logo

oasis

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

gen.lua (10151B)


  1. local version = setmetatable({2, 39}, {__index=function() return 0 end})
  2. local defvec = 'x86_64_elf64_vec'
  3. local selvecs = {[defvec]=true, i386_elf32_vec=true}
  4. local selarchs = {i386=true}
  5. local emuls = {
  6. 'elf_x86_64',
  7. 'elf_i386',
  8. }
  9. cflags{
  10. '-std=c99', '-Wall', '-Wno-return-local-addr', '-Wno-stringop-truncation',
  11. '-D _POSIX_C_SOURCE=200809L',
  12. '-D HAVE_CONFIG_H',
  13. '-I $srcdir/include',
  14. '-I $outdir/bfd',
  15. '-I $srcdir/bfd',
  16. '-isystem $builddir/pkg/zlib/include',
  17. }
  18. pkg.deps = {
  19. 'pkg/zlib/headers',
  20. '$outdir/bfd/bfd.h',
  21. '$outdir/bfd/bfdver.h',
  22. '$outdir/bfd/bfd_stdint.h',
  23. }
  24. sub('libiberty.ninja', function()
  25. cflags{'-I $dir/libiberty'}
  26. -- src/libiberty/Makefile.in:/^REQUIRED_OFILES
  27. lib('libiberty.a', [[libiberty/(
  28. regex.c cplus-dem.c cp-demangle.c
  29. md5.c sha1.c alloca.c
  30. argv.c
  31. choose-temp.c concat.c
  32. cp-demint.c crc32.c d-demangle.c
  33. dwarfnames.c dyn-string.c
  34. fdmatch.c fibheap.c
  35. filedescriptor.c
  36. filename_cmp.c floatformat.c
  37. fnmatch.c fopen_unlocked.c
  38. getopt.c getopt1.c getpwd.c
  39. getruntime.c hashtab.c hex.c
  40. lbasename.c lrealpath.c
  41. make-relative-prefix.c make-temp-file.c
  42. objalloc.c
  43. obstack.c
  44. partition.c pexecute.c physmem.c
  45. pex-common.c pex-one.c
  46. pex-unix.c vprintf-support.c
  47. rust-demangle.c
  48. safe-ctype.c
  49. simple-object.c simple-object-coff.c
  50. simple-object-elf.c simple-object-mach-o.c
  51. simple-object-xcoff.c
  52. sort.c spaces.c
  53. splay-tree.c stack-limit.c
  54. strerror.c strsignal.c
  55. timeval-utils.c unlink-if-ordinary.c
  56. xasprintf.c xatexit.c xexit.c
  57. xmalloc.c xmemdup.c xstrdup.c
  58. xstrerror.c xstrndup.c
  59. xvasprintf.c
  60. )]])
  61. end)
  62. sub('bfd.ninja', function()
  63. cflags{'-I $dir/bfd'}
  64. build('sed', '$outdir/bfd/bfd.h', '$srcdir/bfd/bfd-in2.h', {expr={
  65. '-e s,@supports_plugins@,0,',
  66. '-e s,@wordsize@,64,',
  67. '-e s,@bfd_default_target_size@,64,',
  68. [[-e 's,@BFD_INT64_FMT@,__PRI64,']],
  69. '-e s,@bfd_file_ptr@,int64_t,',
  70. '-e s,@bfd_ufile_ptr@,uint64_t,',
  71. }})
  72. build('sed', '$outdir/bfd/bfdver.h', '$srcdir/bfd/version.h', {expr={
  73. string.format('-e s,@bfd_version@,%d%02d%02d%02d%02d,', version[1], version[2], version[3], version[4], version[5]),
  74. string.format([[-e 's,@bfd_version_string@,"%s",']], table.concat(version, '.')),
  75. [[-e 's,@bfd_version_package@,"(GNU Binutils) ",']],
  76. [[-e 's,@report_bugs_to@,"<http://www.sourceware.org/bugzilla/>",']],
  77. }})
  78. build('printf', '$outdir/bfd/bfd_stdint.h', nil, {args=[['#include <stdint.h>\n']]})
  79. build('sed', '$outdir/bfd/targmatch.h', {'$srcdir/bfd/config.bfd', '|', '$srcdir/bfd/targmatch.sed'}, {
  80. expr='-f $srcdir/bfd/targmatch.sed',
  81. })
  82. build('sed', '$outdir/bfd/elf32-target.h', '$srcdir/bfd/elfxx-target.h', {expr='-e s,NN,32,g'})
  83. build('sed', '$outdir/bfd/elf64-target.h', '$srcdir/bfd/elfxx-target.h', {expr='-e s,NN,64,g'})
  84. build('sed', '$outdir/bfd/pex64igen.c', '$srcdir/bfd/peXXigen.c', {expr='-e s,XX,pex64,g'})
  85. build('sed', '$outdir/bfd/peigen.c', '$srcdir/bfd/peXXigen.c', {expr='-e s,XX,pe,g'})
  86. -- src/bfd/config.bfd
  87. for _, vec in ipairs(table.keys(selvecs)) do
  88. if vec:find('elf64') or vec:find('mips_elf32_n') then
  89. selvecs.elf64_le_vec = true
  90. selvecs.elf64_be_vec = true
  91. end
  92. if vec:find('elf32') or vec:find('elf64') or vec:find('mips_elf32_n') then
  93. selvecs.elf32_le_vec = true
  94. selvecs.elf32_be_vec = true
  95. end
  96. if vec:find('iamcu_elf32') then
  97. selarchs.iamcu = true
  98. end
  99. end
  100. local srcs = {}
  101. local special = {
  102. ['dwarf2.c']='bfd/dwarf2.c.o',
  103. ['peigen.c']='$outdir/bfd/peigen.c',
  104. ['pex64igen.c']='$outdir/bfd/pex64igen.c',
  105. }
  106. for vec, vecsrcs in pairs(load 'vec.lua') do
  107. if selvecs[vec] then
  108. for src in iterstrings(vecsrcs) do
  109. srcs[special[src] or 'bfd/'..src] = true
  110. end
  111. end
  112. end
  113. for arch in pairs(selarchs) do
  114. srcs['bfd/cpu-'..arch..'.c'] = true
  115. end
  116. local deps = {
  117. '$gendir/deps',
  118. '$outdir/bfd/targmatch.h',
  119. '$outdir/bfd/elf32-target.h',
  120. '$outdir/bfd/elf64-target.h',
  121. }
  122. local selvecnames = table.keys(selvecs)
  123. cc('bfd/targets.c', nil, {cflags={
  124. '$cflags',
  125. '-D DEFAULT_VECTOR='..defvec,
  126. '-D HAVE_'..table.concat(selvecnames, ' -D HAVE_'),
  127. string.format([[-D 'SELECT_VECS=&%s']], table.concat(selvecnames, ',&')),
  128. }})
  129. cc('bfd/archures.c', nil, {cflags={
  130. '$cflags',
  131. string.format([[-D 'SELECT_ARCHITECTURES=&bfd_%s_arch']], table.concat(table.keys(selarchs), '_arch,&bfd_')),
  132. }})
  133. cc('bfd/dwarf2.c', nil, {cflags={'$cflags', string.format([[-D 'DEBUGDIR="%s/lib/debug"']], config.prefix)}})
  134. lib('libbfd.a', {
  135. -- src/bfd/Makefile.am:/^BFD32_LIBS_CFILES
  136. -- src/bfd/Makefile.am:/^BFD64_LIBS_CFILES
  137. paths[[bfd/(
  138. archive.c archures.c.o bfd.c bfdio.c bfdwin.c cache.c coff-bfd.c
  139. compress.c corefile.c elf-properties.c format.c hash.c
  140. init.c libbfd.c linker.c merge.c opncls.c reloc.c
  141. section.c simple.c stab-syms.c stabs.c syms.c targets.c.o
  142. binary.c ihex.c srec.c tekhex.c verilog.c
  143. archive64.c
  144. )]],
  145. table.keys(srcs),
  146. 'libiberty.a',
  147. '$builddir/pkg/zlib/libz.a',
  148. }, deps)
  149. end)
  150. sub('opcodes.ninja', function()
  151. cflags{'-I $dir/opcodes'}
  152. local srcs = {}
  153. for arch, archsrcs in pairs(load 'arch.lua') do
  154. if selarchs[arch] then
  155. for src in iterstrings(archsrcs) do
  156. srcs['opcodes/'..src] = true
  157. end
  158. end
  159. end
  160. cc('opcodes/disassemble.c', nil, {cflags={
  161. '$cflags', '-D ARCH_'..table.concat(table.keys(selarchs), ' -D ARCH_'),
  162. }})
  163. lib('libopcodes.a', {
  164. paths[[opcodes/(dis-buf.c disassemble.c.o dis-init.c)]],
  165. table.keys(srcs),
  166. })
  167. end)
  168. sub('binutils.ninja', function()
  169. cflags{
  170. string.format([[-D 'LOCALEDIR="%s/share/locale"']], config.prefix),
  171. '-D bin_dummy_emulation=bin_vanilla_emulation',
  172. '-I $dir/binutils',
  173. '-I $srcdir/binutils',
  174. }
  175. lib('libcommon.a', [[
  176. binutils/(
  177. bucomm.c version.c filemode.c rename.c
  178. elfcomm.c
  179. rddbg.c debug.c stabs.c rdcoff.c wrstabs.c
  180. dwarf.c demanguse.c
  181. )
  182. libbfd.a.d
  183. libiberty.a
  184. ]])
  185. cc('binutils/objdump.c', nil, {cflags='$cflags -D OBJDUMP_PRIVATE_VECTORS='})
  186. exe('bin/size', [[binutils/size.c libcommon.a.d]])
  187. exe('bin/objcopy', [[binutils/(objcopy.c not-strip.c) libcommon.a.d]])
  188. exe('bin/readelf', [[binutils/(readelf.c unwind-ia64.c) libcommon.a.d]])
  189. exe('bin/elfedit', [[binutils/elfedit.c libcommon.a.d]])
  190. exe('bin/strip', [[binutils/(objcopy.c.o is-strip.c) libcommon.a.d]])
  191. exe('bin/nm', [[binutils/nm.c libcommon.a.d]])
  192. exe('bin/objdump', [[binutils/(objdump.c.o prdbg.c) libcommon.a.d libopcodes.a]])
  193. exe('bin/addr2line', [[binutils/addr2line.c libcommon.a.d]])
  194. local arobjs = objects[[
  195. binutils/(
  196. arparse.c arlex.c ar.c arsup.c binemul.c
  197. emul_vanilla.c
  198. )
  199. libcommon.a.d
  200. ]]
  201. exe('bin/ar', {arobjs, 'binutils/not-ranlib.c'})
  202. exe('bin/ranlib', {arobjs, 'binutils/is-ranlib.c'})
  203. for _, tool in ipairs{'size', 'objcopy', 'readelf', 'elfedit', 'strip', 'nm', 'objdump', 'addr2line', 'ar', 'ranlib'} do
  204. file('bin/'..tool, '755', '$outdir/bin/'..tool)
  205. man{'binutils/doc/'..tool..'.1'}
  206. sym(string.format('bin/%s-%s', config.target.platform, tool), tool)
  207. end
  208. end)
  209. sub('gas.ninja', function()
  210. cflags{
  211. '-I $dir/gas',
  212. '-I $outdir/gas',
  213. '-I $srcdir/gas',
  214. '-I $srcdir/gas/config',
  215. '-I $srcdir',
  216. }
  217. build('copy', '$outdir/gas/targ-cpu.h', '$srcdir/gas/config/tc-i386.h')
  218. build('copy', '$outdir/gas/targ-env.h', '$srcdir/gas/config/te-linux.h')
  219. build('copy', '$outdir/gas/obj-format.h', '$srcdir/gas/config/obj-elf.h')
  220. local deps = {
  221. '$gendir/deps',
  222. '$outdir/gas/targ-cpu.h',
  223. '$outdir/gas/targ-env.h',
  224. '$outdir/gas/obj-format.h',
  225. }
  226. -- src/gas/Makefile.am:/^GAS_CFILES
  227. exe('bin/as', [[
  228. gas/(
  229. app.c
  230. as.c
  231. atof-generic.c
  232. compress-debug.c
  233. cond.c
  234. depend.c
  235. dwarf2dbg.c
  236. dw2gencfi.c
  237. ecoff.c
  238. ehopt.c
  239. expr.c
  240. flonum-copy.c
  241. flonum-konst.c
  242. flonum-mult.c
  243. frags.c
  244. hash.c
  245. input-file.c
  246. input-scrub.c
  247. listing.c
  248. literal.c
  249. macro.c
  250. messages.c
  251. output-file.c
  252. read.c
  253. remap.c
  254. sb.c
  255. stabs.c
  256. subsegs.c
  257. symbols.c
  258. write.c
  259. config/(tc-i386.c obj-elf.c atof-ieee.c)
  260. )
  261. libopcodes.a
  262. libbfd.a.d
  263. ]], deps)
  264. file('bin/as', '755', '$outdir/bin/as')
  265. sym(string.format('bin/%s-as', config.target.platform), 'as')
  266. man{'gas/doc/as.1'}
  267. end)
  268. sub('ld.ninja', function()
  269. cflags{
  270. '-D ELF_LIST_OPTIONS=true',
  271. '-D ELF_SHLIB_LIST_OPTIONS=true',
  272. '-D ELF_PLT_UNWIND_LIST_OPTIONS=true',
  273. string.format([[-D 'BINDIR="%s/bin"']], config.prefix),
  274. string.format([[-D 'SCRIPTDIR="%s/%s/lib"']], config.prefix, config.target.platform),
  275. string.format([[-D 'TOOLBINDIR="%s/%s/bin"']], config.prefix, config.target.platform),
  276. '-I $dir/ld',
  277. '-I $outdir/ld',
  278. '-I $srcdir/ld',
  279. }
  280. local deps = {
  281. '$gendir/deps',
  282. '$outdir/ld/ldemul-list.h',
  283. }
  284. rule('ldemul', 'sh $dir/ldemul.sh $emuls >$out')
  285. build('ldemul', '$outdir/ld/ldemul-list.h', {'|', '$dir/ldemul.sh'}, {emuls=emuls})
  286. build('copy', '$outdir/ld/stringify.sed', '$srcdir/ld/emultempl/astring.sed')
  287. rule('genscripts', string.format([[cd $outdir/ld && LIB_PATH= sh $$OLDPWD/$srcdir/ld/genscripts.sh $$OLDPWD/$srcdir/ld /lib '' '' %s %s %s '' /lib '%s' /lib no yes $emul %s]], config.target.platform, config.target.platform, config.target.platform, table.concat(emuls, ' '), config.target.platform))
  288. local srcs = {}
  289. for _, emul in ipairs(emuls) do
  290. local out = string.format('$outdir/ld/e%s.c', emul)
  291. table.insert(srcs, out)
  292. build('genscripts', string.format('$outdir/ld/e%s.c', emul), {'|', '$srcdir/ld/genscripts.sh', '$outdir/ld/stringify.sed'}, {
  293. emul=emul,
  294. })
  295. end
  296. cc('ld/ldmain.c', nil, {cflags={
  297. '$cflags',
  298. string.format([[-D 'DEFAULT_EMULATION="%s"']], emuls[1]),
  299. string.format([[-D 'TARGET="%s"']], 'x86_64-pc-linux-musl'),
  300. }})
  301. exe('bin/ld', {
  302. -- src/ld/Makefile.am:/^ld_new_SOURCES
  303. -- src/ld/configure.tgt:/^targ_extra_ofiles
  304. paths[[
  305. ld/(
  306. ldgram.c ldlex-wrapper.c lexsup.c ldlang.c mri.c ldctor.c ldmain.c.o
  307. ldwrite.c ldexp.c ldemul.c ldver.c ldmisc.c ldfile.c ldcref.c plugin.c
  308. ldbuildid.c
  309. ldelf.c ldelfgen.c
  310. )
  311. libbfd.a.d
  312. ]],
  313. srcs,
  314. }, deps)
  315. file('bin/ld', '755', '$outdir/bin/ld')
  316. sym(string.format('bin/%s-ld', config.target.platform), 'ld')
  317. man{'ld/ld.1'}
  318. end)
  319. fetch 'curl'