diff options
| author | Michael Forney <mforney@mforney.org> | 2017-09-17 00:03:34 -0700 |
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2017-09-25 19:23:06 -0700 |
| commit | ba94a8513d9a0aadb3f2c834c74b64aa644c61e8 (patch) | |
| tree | 48ac6c85baa7b9d960b9e1e726a906e61ca60967 /setup.lua | |
| parent | cb362b531d79708a259bbf070dee5104fd63df08 (diff) | |
Rewrite ninja generation scripts in Lua
Diffstat (limited to 'setup.lua')
| -rwxr-xr-x | setup.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/setup.lua b/setup.lua new file mode 100755 index 00000000..6f4e2580 --- /dev/null +++ b/setup.lua @@ -0,0 +1,97 @@ +#!/bin/lua + +if not os.execute('test -f config.lua') then + os.execute('cp config.def.lua config.lua') +end + +dofile 'ninja.lua' +config = dofile 'config.lua' + +local recurse = not arg[1] + +function subgen(dir) + local file = '$dir/'..dir..'/local.ninja' + subninja(file) + table.insert(pkg.inputs.ninja, '$dir/'..dir..'/ninja') + table.insert(pkg.inputs.index, '$outdir/'..dir..'/root.index') + table.insert(pkg.inputs.perms, '$outdir/'..dir..'/root.perms') + local cmd = string.format('test -f %s/%s/local.ninja', pkg.dir, dir) + if recurse or not os.execute(cmd) then + local oldpkg, oldout = pkg, io.output() + if pkg.dir ~= '.' then + dir = pkg.dir..'/'..dir + end + gen(dir) + pkg = oldpkg + io.output(oldout) + end +end + +function gen(dir) + pkg={ + name=dir:match('[^/]*$'), + dir=dir, + inputs={ + perms={}, + index={}, + gen={ + 'setup.lua', + 'ninja.lua', + 'config.lua', + 'sets.lua', + '$dir/gen.lua', + }, + ninja={'$dir/local.ninja'}, + fetch={}, + }, + perms={}, + } + io.output(dir..'/local.ninja.tmp') + set('dir', dir) + set('outdir', '$builddir/$dir') + set('srcdir', '$dir/src') + dofile(dir..'/gen.lua') + + build('gen', '$dir/local.ninja', {'|', pkg.inputs.gen}) + phony('ninja', pkg.inputs.ninja) + + if pkg.hdrs then + phony('headers', pkg.hdrs) + if pkg.hdrs.install then + for hdr in iterstrings(pkg.hdrs) do + if not hdr:hasprefix('$outdir/include/') then + error('header is not in $outdir/include: '..hdr) + end + file(hdr:sub(9), '644', hdr) + end + end + end + if pkg.deps then + phony('deps', pkg.deps) + end + + if next(pkg.perms) then + table.sort(pkg.perms, function(s1, s2) + return s1:sub(8) < s2:sub(8) + end) + local f = io.open(dir..'/local.perms', 'w') + table.insert(pkg.perms, '') + f:write(table.concat(pkg.perms, '\n')) + table.insert(pkg.inputs.perms, '$dir/local.perms') + f:close() + end + if next(pkg.inputs.perms) then + build('mergeperms', '$outdir/root.perms', pkg.inputs.perms) + else + build('empty', '$outdir/root.perms') + end + if next(pkg.inputs.index) then + build('cat', '$outdir/root.index', pkg.inputs.index) + else + build('empty', '$outdir/root.index') + end + io.close() + os.rename(dir..'/local.ninja.tmp', dir..'/local.ninja') +end + +gen(arg[1] or '.') |
