~kaction/config

ref: a53ab2c19d3ef10d552da75d2f83741badf44269 config/Tupfile.lua -rw-r--r-- 4.2 KiB
a53ab2c1 — Dmitry Bogatov Fix typo in "solemn-email-session" 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
uri  = {}
rule = {}
directory = {}
function uri.github(arg)
  local fmt = 'https://raw.githubusercontent.com/%s/%s/%s'
  return string.format(fmt, arg.repo, arg.ref or 'master', arg.path)
end

do
  files = {}
  files.relatives = {}
  files.inputs = {}

  function outfile(relative)
    local input = string.format('out/dest/%s', relative)
    table.insert(files.relatives, relative)
    table.insert(files.inputs, input)
    return input
  end

  function rule.archive()
    local tgz = 'out/config.tar.gz'
    local cmd = [[
^ TAR config.tar.gz^ cd out/dest; tar -czf ../config.tar.gz %s ]]
    local argument = tostring(files.relatives)

    tup.rule(files.inputs, cmd:format(argument), tgz)
  end
end

function rule.copy(relative)
  local relative = string.sub(relative, 3)
  local source = string.format('src/copy/%s', relative)
  local destination = outfile(relative)
  local command = string.format('^ CP %s^ cp -d %%f %%o', relative)
  tup.rule(source, command, destination)
end

function rule.vimspell(input)
  local lang = tup.file(input)
  local path = string.format('.vim/spell/%s.utf-8.spl', lang)
  local command = string.format([[^ SPELL %s^
  printf "mkspell! %%o %%f\nexit" | vim -e ]], base)
  tup.rule(input, command, outfile(path))
end

function rule.deploy()
  local command = '^ DEPLOY^ cp -f %f ~/ && cd ~ && tar xf %b'
  tup.rule('out/config.tar.gz', command, {})
end

function rule.man(input)
  local ext  = tup.ext(input)
  local base = tup.base(input)
  local dest = string.format('.local/share/man/man%s/%s.%s.gz', ext, base, ext)
  tup.rule(input, '^ MAN %f^ gzip %f -c > %o', outfile(dest))
end

function rule.dircolors(dest, input)
  local cmd = '^ DIRCOLORS ^ TERM=linux dircolors --sh %s > %%o'
  tup.rule(input or {}, cmd:format(input or ""), outfile(dest))
end

function rule.ftplugin(input)
  local relative = input:gsub('^src/copy/', '')
  local output = outfile(relative)
  tup.rule(input, '^ FTPLUGIN %B^ ./aux/fix-ftplugin %f > %o', output)
end

function rule.m4(dest, input)
  local cmd = '^ M4 %b^ m4 -P %f > %o'
  tup.rule(string.format('src/m4/%s', input), cmd, outfile(dest))
end

function rule.snippet_txt(source)
  local base = tup.base(source)
  local src_c = string.format('out/snippet_txt/%s.c', base)
  local cmd_m4 = '^ SNIP %B^ m4 -P -DTHE_SOURCE=%f aux/mk-template.c.m4> %o'
  tup.rule(source, cmd_m4, src_c)
  tup.rule(src_c, '^ CC %B^ c99 -O3 %f -o %o', outfile('.vim/bin/' .. base))
end

function directory.within(list, callback)
  for dir in list do
    local pattern = string.format('src/copy/%s/*', dir)
    for _, path in ipairs(tup.glob(pattern)) do
      local relative = string.format('%s/%s', dir, tup.file(path))
      callback(relative)
    end
  end
end

tup.creategitignore()
directory.within(io.lines('src/copy.dirs'), rule.copy)

for _, input in ipairs(tup.glob('src/spell/*')) do
  rule.vimspell(input)
end

for _, input in ipairs(tup.glob('src/man/*')) do
  rule.man(input)
end

for _, input in ipairs(tup.glob('src/prog/*')) do
  local file = tup.file(input)
  local dest = string.format('.local/bin/%s', file)
  tup.rule(input, '^ INSTALL %B^ cp -f %f %o', outfile(dest))
end

do
  local names = {}
  for _, input in ipairs(tup.glob('src/snippet-txt/*.txt')) do
    rule.snippet_txt(input)
    table.insert(names, tup.base(input))
  end
  local command = '^ SNIPCMD^ ./aux/vim-snipcmd %s > %%o'
  local output = outfile('.vim/autogen/snippets.vim')
  tup.rule({}, command:format(tostring(names)), output)
end


do
  local pattern = 'src/copy/.vim/after/ftplugin/*.vim'
  for _, input in ipairs(tup.glob(pattern)) do
    rule.ftplugin(input)
  end
end

do
  local filename = 'volatile/dircolors.256dark'
  rule.dircolors('.local/share/posix/dircolors-256.sh', filename)
  rule.dircolors('.local/share/posix/dircolors-16.sh')
  rule.m4('.local/share/posix/color-list.sh', 'colorlist.m4')
end

do
  local input  = 'volatile/gitolite.conf'
  local output = outfile('.config/myrepos/iu-guest.conf')
  local command = './aux/myrepos.iu-guest < %f > %o'
  tup.rule(input, command, output)
end

tup.rule({}, './aux/myrepos.salsa < volatile/salsa.list > %o',
                 outfile('.config/myrepos/salsa.conf'))

rule.archive()

if tup.getconfig('DEPLOY') == 'y' then
  rule.deploy()
end