logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

setup.lua (3542B)


  1. #!/bin/lua
  2. -- Lua 5.1 compatibility
  3. do
  4. local os_execute = os.execute
  5. os.execute = function(cmd)
  6. local ret = os_execute(cmd)
  7. return ret == true or ret == 0
  8. end
  9. end
  10. basedir = arg[0]:match('(.*)/') or '.'
  11. if not os.execute('exec test -f config.lua') then
  12. os.execute('exec cp '..basedir..'/config.def.lua config.lua')
  13. end
  14. dofile(basedir..'/ninja.lua')
  15. config = dofile 'config.lua'
  16. if not config.prefix then
  17. config.prefix = ''
  18. end
  19. local recurse = not arg[1]
  20. local function gen(gendir)
  21. local dir = basedir..'/'..gendir
  22. local outdir = config.builddir..'/'..gendir
  23. pkg={
  24. name=gendir:match('[^/]*$'),
  25. dir=dir,
  26. gendir=gendir,
  27. srcdir=dir..'/src',
  28. outdir=outdir,
  29. inputs={
  30. index={},
  31. fspec={},
  32. gen={
  33. '$basedir/ninja.lua',
  34. '$basedir/sets.lua',
  35. '$basedir/setup.lua',
  36. 'config.lua',
  37. },
  38. ninja={'$gendir/local.ninja'},
  39. fetch={},
  40. },
  41. fspec={},
  42. }
  43. assert(os.execute(('exec mkdir -p %s %s'):format(gendir, outdir)))
  44. io.output(gendir..'/local.ninja.tmp')
  45. set('gendir', gendir)
  46. if gendir ~= '.' then
  47. set('dir', '$basedir/$gendir')
  48. set('outdir', '$builddir/$gendir')
  49. set('srcdir', '$dir/src')
  50. end
  51. load('gen.lua')
  52. build('gen', '$gendir/local.ninja', {'|', pkg.inputs.gen})
  53. phony('ninja', pkg.inputs.ninja)
  54. if pkg.hdrs then
  55. phony('headers', pkg.hdrs)
  56. if pkg.hdrs.install then
  57. for hdr in iterstrings(pkg.hdrs) do
  58. if not hdr:hasprefix('$outdir/include/') then
  59. error('header is not in $outdir/include: '..hdr)
  60. end
  61. file(hdr:sub(9), '644', hdr)
  62. end
  63. end
  64. end
  65. if pkg.deps then
  66. phony('deps', pkg.deps)
  67. end
  68. if next(pkg.fspec) then
  69. local out = outdir..'/local.fspec'
  70. local tmp = out..'.tmp'
  71. local f = assert(io.open(tmp, 'w'))
  72. local srcs = {}
  73. for _, path, fspec in sortedpairs(pkg.fspec) do
  74. f:write(('/%s\n'):format(path))
  75. for _, k in ipairs{'type', 'mode', 'source', 'target'} do
  76. local v = fspec[k]
  77. if v then
  78. f:write(('%s=%s\n'):format(k, v))
  79. end
  80. end
  81. f:write('\n')
  82. local src = fspec.source
  83. if src then
  84. srcs[#srcs + 1] = src
  85. end
  86. end
  87. f:close()
  88. if os.execute(('exec cmp -s %s %s'):format(tmp, out)) then
  89. os.remove(tmp)
  90. else
  91. os.rename(tmp, out)
  92. end
  93. build('fspec-hash', '$outdir/local-hashed.fspec', {'$outdir/local.fspec', '|', '$builddir/pkg/fspec-sync/host/fspec-hash', srcs})
  94. table.insert(pkg.inputs.fspec, '$outdir/local-hashed.fspec')
  95. end
  96. if next(pkg.inputs.index) then
  97. build('cat', '$outdir/root.index', pkg.inputs.index, {
  98. description=' INDEX $outdir/root.index',
  99. })
  100. else
  101. build('empty', '$outdir/root.index')
  102. end
  103. if next(pkg.inputs.fspec) then
  104. build('cat', '$outdir/tree.fspec', pkg.inputs.fspec, {
  105. description = ' FSPEC $outdir/tree.fspec',
  106. })
  107. else
  108. build('empty', '$outdir/tree.fspec')
  109. end
  110. build('phony', '$dir/root', pkg.inputs.root)
  111. io.close()
  112. os.rename(gendir..'/local.ninja.tmp', gendir..'/local.ninja')
  113. if gendir == '.' then
  114. os.execute('exec ln -sf local.ninja build.ninja')
  115. end
  116. end
  117. function subgen(dir)
  118. local file = '$gendir/'..dir..'/local.ninja'
  119. subninja(file)
  120. table.insert(pkg.inputs.ninja, '$gendir/'..dir..'/ninja')
  121. table.insert(pkg.inputs.index, '$outdir/'..dir..'/root.index')
  122. table.insert(pkg.inputs.fspec, '$outdir/'..dir..'/tree.fspec')
  123. local cmd = ('exec test -f %s/%s/local.ninja'):format(pkg.gendir, dir)
  124. if recurse or not os.execute(cmd) then
  125. local oldpkg, oldout = pkg, io.output()
  126. if pkg.gendir ~= '.' then
  127. dir = pkg.gendir..'/'..dir
  128. end
  129. gen(dir)
  130. pkg = oldpkg
  131. io.output(oldout)
  132. end
  133. end
  134. gen(arg[1] or '.')