From 0d77cb827938776a5f86f0edf55dfb0cce2d21bb Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 7 Aug 2016 21:56:53 +0200 Subject: [PATCH] We can build our first C file. --- build.lua | 3 +- first/ackbuilder.lua | 2 +- lang/build.lua | 0 lang/cem/cemcom.ansi/build.lua | 35 ++++++++++++-- lang/cem/cemcom.ansi/char.tab | 2 - lang/cem/libcc.ansi/build.lua | 29 +++++++++++ mach/i86/libem/build.lua | 8 ++++ mach/i86/libsys/build.lua | 8 ++++ modules/src/assert/build.lua | 7 +++ modules/src/em_mes/build.lua | 11 +++++ modules/src/flt_arith/build.lua | 18 ++++++- modules/src/read_em/build.lua | 59 ++++++++++++----------- plat/build.lua | 11 +++-- plat/pc86/build.lua | 1 + util/misc/build.lua | 17 +++++++ util/opt/build.lua | 85 +++++++++++++++++++++++++++++++++ 16 files changed, 258 insertions(+), 38 deletions(-) create mode 100644 lang/build.lua create mode 100644 lang/cem/libcc.ansi/build.lua create mode 100644 mach/i86/libem/build.lua create mode 100644 mach/i86/libsys/build.lua create mode 100644 modules/src/assert/build.lua create mode 100644 modules/src/em_mes/build.lua create mode 100644 util/opt/build.lua diff --git a/build.lua b/build.lua index 200744a4c..373f195e3 100644 --- a/build.lua +++ b/build.lua @@ -12,11 +12,12 @@ installable { name = "ack", map = { "lang/cem/cemcom.ansi+pkg", + "plat/pc86+pkg", "util/ack+pkg", "util/amisc+pkg", "util/arch+pkg", "util/misc+pkg", - "plat/pc86+pkg", + "util/opt+pkg", } } diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 0f83c4936..7bbf2ee04 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -415,7 +415,7 @@ loadtarget = function(targetname) target = targets[targetname] if not target then - error(string.format("build file '%s' contains no rule '%s'", + error(string.format("build file '%s' contains no target '%s'", filename, targetpart)) end end diff --git a/lang/build.lua b/lang/build.lua new file mode 100644 index 000000000..e69de29bb diff --git a/lang/cem/cemcom.ansi/build.lua b/lang/cem/cemcom.ansi/build.lua index bc3f33b3d..fe0f70d25 100644 --- a/lang/cem/cemcom.ansi/build.lua +++ b/lang/cem/cemcom.ansi/build.lua @@ -1,4 +1,5 @@ include("util/LLgen/build.lua") +include("util/cmisc/build.lua") normalrule { name = "parameters", @@ -50,12 +51,24 @@ clibrary { } normalrule { - name = "tokenname-g", + name = "tokenfile-g", ins = { "./make.tokfile", "./tokenname.c", }, - outleaves = { "tokenname.g" }, + outleaves = { "tokenfile.g" }, + commands = { + "sh %{ins[1]} < %{ins[2]} > %{outs}", + } +} + +normalrule { + name = "symbol2str-c", + ins = { + "./make.tokcase", + "./tokenname.c", + }, + outleaves = { "symbol2str.c" }, commands = { "sh %{ins[1]} < %{ins[2]} > %{outs}", } @@ -64,14 +77,23 @@ normalrule { llgen { name = "llgen", srcs = { - "+tokenname-g", -- must be first + "+tokenfile-g", -- must be first "./*.g", }, } +tabgen { + name = "tabgen", + srcs = { "./char.tab" } +} + cprogram { name = "cemcom", srcs = { + "./LLlex.c", + "./LLmessage.c", + "./arith.c", + "./blocks.c", "./ch3.c", "./ch3bin.c", "./ch3mon.c", @@ -111,17 +133,24 @@ cprogram { "./tokenname.c", "./type.c", "./util.c", + "+symbol2str-c", + "+tabgen", + matching(filenamesof("+llgen"), "%.c$"), }, deps = { + "./*.h", "+parameters", "+nextlib", "+llgen", "h+emheaders", "modules/src/alloc+lib", "modules/src/em_code+lib_k", + "modules/src/em_mes+lib", "modules/src/flt_arith+lib", "modules/src/idf+lib", "modules/src/input+lib", + "modules/src/print+lib", + "modules/src/string+lib", "modules/src/system+lib", "modules+headers", "util/data+em_data", diff --git a/lang/cem/cemcom.ansi/char.tab b/lang/cem/cemcom.ansi/char.tab index 809f1c6ce..329178284 100644 --- a/lang/cem/cemcom.ansi/char.tab +++ b/lang/cem/cemcom.ansi/char.tab @@ -1,6 +1,4 @@ % -hdrs = { "./src/system/system.h" }, -hdrs = { "./src/system/system.h" }, % CHARACTER CLASSES % % some general settings: diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua new file mode 100644 index 000000000..a75526836 --- /dev/null +++ b/lang/cem/libcc.ansi/build.lua @@ -0,0 +1,29 @@ +for _, plat in ipairs(vars.plats) do + acklibrary { + name = "lib_"..plat, + srcs = { + "./assert/*.c", + }, + hdrs = { + }, + vars = { plat = plat } + } + + ackfile { + name = "crt_"..plat, + srcs = { "./head_ac.e" }, + vars = { plat = plat }, + deps = { + "h+emheaders" + } + } + + installable { + name = "pkg_"..plat, + map = { + ["$(PLATIND)/"..plat.."/c-ansi.o"] = "+crt_"..plat, + --["$(PLATIND)/"..plat.."/libc.a"] = "+lib_"..plat, + } + } +end + diff --git a/mach/i86/libem/build.lua b/mach/i86/libem/build.lua new file mode 100644 index 000000000..ca5a13c65 --- /dev/null +++ b/mach/i86/libem/build.lua @@ -0,0 +1,8 @@ +for _, plat in ipairs(vars.plats) do + acklibrary { + name = "lib_"..plat, + srcs = { "./*.s" }, + vars = { plat = plat }, + } +end + diff --git a/mach/i86/libsys/build.lua b/mach/i86/libsys/build.lua new file mode 100644 index 000000000..ca5a13c65 --- /dev/null +++ b/mach/i86/libsys/build.lua @@ -0,0 +1,8 @@ +for _, plat in ipairs(vars.plats) do + acklibrary { + name = "lib_"..plat, + srcs = { "./*.s" }, + vars = { plat = plat }, + } +end + diff --git a/modules/src/assert/build.lua b/modules/src/assert/build.lua new file mode 100644 index 000000000..bd1230bfe --- /dev/null +++ b/modules/src/assert/build.lua @@ -0,0 +1,7 @@ +clibrary { + name = "lib", + srcs = { "./*.c" }, + hdrs = { "./assert.h" }, +} + + diff --git a/modules/src/em_mes/build.lua b/modules/src/em_mes/build.lua new file mode 100644 index 000000000..a3c0173cc --- /dev/null +++ b/modules/src/em_mes/build.lua @@ -0,0 +1,11 @@ +clibrary { + name = "lib", + srcs = { "./*.c" }, + deps = { + "h+emheaders", + "modules+headers", + "modules/src/em_code+em_code_ek_h", + "util/data+em_data", + } +} + diff --git a/modules/src/flt_arith/build.lua b/modules/src/flt_arith/build.lua index 10ce7b8ce..a3da4b801 100644 --- a/modules/src/flt_arith/build.lua +++ b/modules/src/flt_arith/build.lua @@ -1,6 +1,22 @@ clibrary { name = "lib", - srcs = { "./*.c" }, + srcs = { + "./flt_ar2flt.c", + "./flt_div.c", + "./flt_flt2ar.c", + "./flt_modf.c", + "./flt_str2fl.c", + "./flt_cmp.c", + "./flt_add.c", + "./b64_add.c", + "./flt_mul.c", + "./flt_nrm.c", + "./b64_sft.c", + "./flt_umin.c", + "./flt_chk.c", + "./split.c", + "./ucmp.c", + }, hdrs = { "./flt_arith.h" }, deps = { "modules+headers" diff --git a/modules/src/read_em/build.lua b/modules/src/read_em/build.lua index d80d0569c..45794bd91 100644 --- a/modules/src/read_em/build.lua +++ b/modules/src/read_em/build.lua @@ -25,34 +25,39 @@ normalrule { } } -clibrary { - name = "lib_ev", - vars = { - ["+cflags"] = { - "-DPRIVATE=static", - "-DEXPORT=", - "-DNDEBUG", - "-DCHECKING" +local function variant(name, cflags) + clibrary { + name = name, + vars = { + ["+cflags"] = { + "-DPRIVATE=static", + "-DEXPORT=", + "-DNDEBUG", + "-DCHECKING", + unpack(cflags) + }, }, - }, - srcs = { - "./EM_vars.c", - "./read_em.c", - "./mkcalls.c", - }, - hdrs = { - "./em_comp.h", - }, - deps = { - "+c_mnem_h", - "+c_mnem_narg_h", - "h+emheaders", - "modules+headers", - "modules/src/alloc+lib", - "modules/src/em_code+em_code_ek_h", - "modules/src/system+lib", - "util/data+em_data", + srcs = { + "./EM_vars.c", + "./read_em.c", + "./mkcalls.c", + }, + hdrs = { + "./em_comp.h", + }, + deps = { + "+c_mnem_h", + "+c_mnem_narg_h", + "h+emheaders", + "modules+headers", + "modules/src/alloc+lib", + "modules/src/em_code+em_code_ek_h", + "modules/src/system+lib", + "util/data+em_data", + } } -} +end +variant("lib_ev", {}) +variant("lib_kv", { "-DCOMPACT" }) diff --git a/plat/build.lua b/plat/build.lua index 67b8cd1d8..472e9ec3f 100644 --- a/plat/build.lua +++ b/plat/build.lua @@ -13,9 +13,10 @@ definerule("ackfile", name = e.name, srcs = e.srcs, deps = { + "lang/cem/cpp.ansi+pkg", "plat/"..plat.."+tools", "util/ack+pkg", - "lang/cem/cpp.ansi+pkg", + "util/misc+pkg", e.deps }, commands = { @@ -43,7 +44,7 @@ definerule("acklibrary", _cfile = ackfile, commands = { "rm -f %{outs[1]}", - "ACKDIR=$(INSDIR) $(INSDIR)/bin/aal q %{outs[1]} %{ins}" + "ACKDIR=$(INSDIR) $(INSDIR)/bin/aal qc %{outs[1]} %{ins}" } } end @@ -73,6 +74,7 @@ definerule("build_plat_tools", ["$(PLATDEP)/"..e.plat.."/as"] = as, ["$(PLATDEP)/"..e.plat.."/ncg"] = ncg, ["$(PLATIND)/descr/"..e.plat] = descr, + "util/opt+pkg", } } end @@ -87,7 +89,10 @@ definerule("build_plat_libs", return installable { name = e.name, map = { - ["$(PLATIND)/"..e.plat.."/libend.a"] = "mach/"..e.arch.."/libend+lib_"..e.plat + ["$(PLATIND)/"..e.plat.."/libend.a"] = "mach/"..e.arch.."/libend+lib_"..e.plat, + ["$(PLATIND)/"..e.plat.."/libem.a"] = "mach/"..e.arch.."/libem+lib_"..e.plat, + ["$(PLATIND)/"..e.plat.."/libsys.a"] = "mach/"..e.arch.."/libsys+lib_"..e.plat, + "lang/cem/libcc.ansi+pkg_"..e.plat, } } end diff --git a/plat/pc86/build.lua b/plat/pc86/build.lua index c293a4ea6..6f68b1474 100644 --- a/plat/pc86/build.lua +++ b/plat/pc86/build.lua @@ -1,4 +1,5 @@ include("plat/build.lua") +include("lang/build.lua") build_plat_tools { name = "tools", diff --git a/util/misc/build.lua b/util/misc/build.lua index ab0a26d7d..3b11c6018 100644 --- a/util/misc/build.lua +++ b/util/misc/build.lua @@ -19,10 +19,27 @@ cprogram { } } +cprogram { + name = "decode", + srcs = { "./convert.c" }, + deps = { + "h+emheaders", + "modules+headers", + "modules/src/alloc+lib", + "modules/src/em_code+lib_k", + "modules/src/print+lib", + "modules/src/read_em+lib_kv", + "modules/src/string+lib", + "modules/src/system+lib", + "util/data+em_data", + } +} + installable { name = "pkg", map = { ["$(PLATDEP)/em_encode"] = "+encode", + ["$(PLATDEP)/em_decode"] = "+decode", ["$(INSDIR)/bin/esize"] = "+esize", ["$(PLATIND)/man/man1/esize.1"] = "./esize.1", ["$(PLATIND)/man/man6/em_decode.6"] = "./em_decode.6" diff --git a/util/opt/build.lua b/util/opt/build.lua new file mode 100644 index 000000000..8a4dc6688 --- /dev/null +++ b/util/opt/build.lua @@ -0,0 +1,85 @@ +include("first/yacc.lua") + +yacc { + name = "yacc", + srcs = { "./mktab.y" } +} + +flex { + name = "flex", + srcs = { "./scan.l" } +} + +cprogram { + name = "mktab", + srcs = { + matching(filenamesof("+yacc"), "%.c$"), + matching(filenamesof("+flex"), "%.c$"), + }, + deps = { + "+flex", + "+yacc", + "util/data+em_data", + } +} + +normalrule { + name = "pattern_c", + ins = { + "+mktab", + "./patterns", + "lang/cem/cpp.ansi+cpp" + }, + outleaves = { "pattern.c" }, + commands = { + "%{ins[3]} < %{ins[2]} | %{ins[1]} > %{outs}" + } +} + +normalrule { + name = "pop_push_c", + ins = { + "./pop_push.awk", + "h/em_table" + }, + outleaves = { "pop_push.c" }, + commands = { + "awk -f %{ins[1]} < %{ins[2]} > %{outs}" + } +} + +local function variant(name, cflags) + cprogram { + name = name, + srcs = { + "+pattern_c", + "+pop_push_c", + "./*.c", + }, + deps = { + "./*.h", + "h+emheaders", + "modules/src/alloc+lib", + "modules/src/print+lib", + "modules/src/string+lib", + "modules/src/system+lib", + "util/data+em_data", + }, + vars = { + ["+cflags"] = cflags + } + } +end + +variant("em_opt", {}) +variant("em_opt2", {"-DGLOBAL_OPT"}) + +installable { + name = "pkg", + map = { + ["$(PLATDEP)/em_opt"] = "+em_opt", + ["$(PLATDEP)/em_opt2"] = "+em_opt2", + ["$(INSDIR)/share/man/man6/em_opt.6"] = "./em_opt.6", + } +} +