From 363d13cc2f063568c5a2dd53c5db3ba07055b19c Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 29 Jul 2016 00:22:49 +0200 Subject: [PATCH] C preprocessor; tabgen; now the pc86 boot.s builds using the ack toolchain. --- build.lua | 3 + first/build.lua | 14 ++-- h/build.lua | 2 +- lang/cem/cemcom.ansi/build.lua | 120 --------------------------------- lang/cem/cpp.ansi/build.lua | 110 ++++++++++++++++++++++++++++++ plat/build.lua | 48 +++++++------ plat/pc86/build.lua | 19 +++++- util/cmisc/build.lua | 25 +++++++ 8 files changed, 190 insertions(+), 151 deletions(-) create mode 100644 lang/cem/cpp.ansi/build.lua create mode 100644 util/cmisc/build.lua diff --git a/build.lua b/build.lua index cc483e438..9db83f5cd 100644 --- a/build.lua +++ b/build.lua @@ -1,6 +1,9 @@ vars.cflags = { "-g", "-O" } +vars.ackcflags = { + "-O" +} installable { name = "ack", diff --git a/first/build.lua b/first/build.lua index e514384b9..6a8bc4c93 100644 --- a/first/build.lua +++ b/first/build.lua @@ -48,24 +48,20 @@ definerule("cfile", } }, function (e) - local csrcs = filenamesof(e.srcs, "%.c$") - if (#csrcs ~= 1) then - error("you must have exactly one .c file") - end - - local hsrcs = filenamesof(e.srcs, "%.h$") local hdrpaths = {} for _, t in pairs(e.deps) do - hdrpaths[#hdrpaths+1] = "-I"..t.dir + if t.dir then + hdrpaths[#hdrpaths+1] = "-I"..t.dir + end end hdrpaths = uniquify(hdrpaths) - local outleaf = basename(csrcs[1]):gsub("%.c$", ".o") + local outleaf = basename(e.name)..".o" return normalrule { name = e.name, cwd = e.cwd, - ins = {csrcs[1]}, + ins = e.srcs, deps = e.deps, outleaves = {outleaf}, label = e.label, diff --git a/h/build.lua b/h/build.lua index db9400fdc..4249c1e55 100644 --- a/h/build.lua +++ b/h/build.lua @@ -3,7 +3,7 @@ normalrule { ins = {}, outleaves = { "em_path.h" }, commands = { - "echo '#define TMP_DIR \"$(ACK_TEMP_DIR)\"' > %{outs}", + "echo '#define TMP_DIR \"/tmp\"' > %{outs}", "echo '#define EM_DIR \"$(PREFIX)\"' >> %{outs}", "echo '#define ACK_PATH \"share/ack/descr\"' >> %{outs}", } diff --git a/lang/cem/cemcom.ansi/build.lua b/lang/cem/cemcom.ansi/build.lua index ff07e4b36..f402bd697 100644 --- a/lang/cem/cemcom.ansi/build.lua +++ b/lang/cem/cemcom.ansi/build.lua @@ -135,123 +135,3 @@ installable { ["$(PLATDEP)/em_cemcom.ansi"] = "+cemcom" } } ---[[ - -D := lang/cem/cemcom.ansi - -define build-cemcom-ansi-allocd-header -$(eval g := $(OBJDIR)/$D/$(strip $1).h) -$g: $D/$(strip $1).str $D/make.allocd - @echo ALLOCD $$@ - @mkdir -p $$(dir $$@) - $(hide) $D/make.allocd < $$^ > $$@ - -$(eval CLEANABLES += $g) -$(eval $q: $g) -endef - -define build-cemcom-ansi-next -$(eval CLEANABLES += $(OBJDIR)/$D/next.c) -$(OBJDIR)/$D/next.c: $D/make.next $1 - @echo NEXT $$@ - @mkdir -p $$(dir $$@) - $(hide) $$^ > $$@ -$(call cfile, $(OBJDIR)/$D/next.c) - -$(foreach f, $1, $(call build-cemcom-ansi-allocd-header, \ - $(basename $(notdir $f)))) -endef - -define build-cemcom-ansi-impl - -$(call reset) -$(eval cflags += -I$(OBJDIR)/$D -I$D) - -$(call cfile, $D/arith.c) -$(call dependson, $(INCDIR)/flt_arith.h) - -$(call cfile, $D/blocks.c) -$(call dependson, $(INCDIR)/em_codeEK.h) - -$(call cfile, $D/LLlex.c) -$(call cfile, $D/LLmessage.c) - - -$(call llgen, $(OBJDIR)/$D, \ - $(OBJDIR)/$D/tokenfile.g \ - $D/program.g \ - $D/declar.g \ - $D/expression.g \ - $D/statement.g \ - $D/ival.g) - -$(eval CLEANABLES += $(OBJDIR)/$D/tokenfile.g) -$(OBJDIR)/$D/tokenfile.g: $D/make.tokfile $D/tokenname.c - @echo TOKENFILE $$@ - @mkdir -p $$(dir $$@) - $(hide) sh $D/make.tokfile < $D/tokenname.c > $$@ - -$(call tabgen, $D/char.tab) - -$(eval $q: $(OBJDIR)/$D/parameters.h) - -$(eval CLEANABLES += $(OBJDIR)/$D/parameters.h) -$(OBJDIR)/$D/parameters.h: $D/BigPars - @echo PARAMETERS $$@ - @mkdir -p $$(dir $$@) - $(hide) echo '#ifndef PARAMETERS_H' > $$@ - $(hide) echo '#define PARAMETERS_H' >> $$@ - $(hide) grep -v '^!' < $D/BigPars >> $$@ - $(hide) echo '#endif' >> $$@ - -$(eval CLEANABLES += $(OBJDIR)/$D/symbol2str.c) -$(OBJDIR)/$D/symbol2str.c: $D/make.tokcase $D/tokenname.c - @echo TOKCASE $$@ - @mkdir -p $$(dir $$@) - $(hide) $D/make.tokcase < $D/tokenname.c > $$@ -$(call cfile, $(OBJDIR)/$D/symbol2str.c) - -$(call build-cemcom-ansi-next, \ - $D/code.str \ - $D/declar.str \ - $D/def.str \ - $D/expr.str \ - $D/field.str \ - $D/estack.str \ - $D/util.str \ - $D/proto.str \ - $D/replace.str \ - $D/idf.str \ - $D/macro.str \ - $D/stack.str \ - $D/stmt.str \ - $D/struct.str \ - $D/switch.str \ - $D/type.str \ - $D/l_brace.str \ - $D/l_state.str \ - $D/l_outdef.str) - -$(eval $q: $(OBJDIR)/$D/Lpars.h) - -$(call rawfile, $(LIBEM_MES)) -$(call rawfile, $(LIBEMK)) -$(call rawfile, $(LIBEM_DATA)) -$(call rawfile, $(LIBINPUT)) -$(call rawfile, $(LIBASSERT)) -$(call rawfile, $(LIBALLOC)) -$(call rawfile, $(LIBFLT_ARITH)) -$(call rawfile, $(LIBPRINT)) -$(call rawfile, $(LIBSYSTEM)) -$(call rawfile, $(LIBSTRING)) -$(call cprogram, $(BINDIR)/cemcom.ansi) -$(call installto, $(PLATDEP)/em_cemcom.ansi) -$(eval CEMCOMANSI := $o) - -$(call reset) -$(eval q := $D/cemcom.ansi.1) -$(call installto, $(INSDIR)/share/man/man1/cemcom.6) -endef - -$(eval $(build-cemcom-ansi-impl)) ---]] diff --git a/lang/cem/cpp.ansi/build.lua b/lang/cem/cpp.ansi/build.lua new file mode 100644 index 000000000..ee3275a51 --- /dev/null +++ b/lang/cem/cpp.ansi/build.lua @@ -0,0 +1,110 @@ +include("util/cmisc/build.lua") + +local allocd_header = definerule(null, + { + srcs = { type="targets" } + }, + function (e) + return normalrule { + name = e.name, + ins = { + "./make.allocd", + unpack(e.srcs) + }, + outleaves = replace(basename(e.srcs), "%.str$", ".h"), + commands = { + "%{ins[1]} < %{ins[2]} > %{outs}" + } + } + end +) + +allocd_header { + name = "macro_h", + srcs = { "./macro.str" } +} + +allocd_header { + name = "replace_h", + srcs = { "./replace.str" } +} + +normalrule { + name = "tokenfile_g", + ins = { + "./make.tokfile", + "./tokenname.c", + }, + 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}" + } +} + +normalrule { + name = "next_c", + ins = { + "./make.next", + "./*.str", + }, + outleaves = { "next.c" }, + commands = { + "sh %{ins} > %{outs}" + } +} + +llgen { + name = "llgen", + srcs = { + "+tokenfile_g", + "./expression.g" + } +} + +tabgen { + name = "tabgen_c", + srcs = { "./char.tab" } +} + +cprogram { + name = "cpp", + srcs = { + "./*.c", + "+llgen", + "+next_c", + "+symbol2str_c", + "+tabgen_c", + }, + deps = { + "+llgen", + "+macro_h", + "+replace_h", + "modules+headers", + "modules/src/alloc+lib", + "modules/src/idf+lib", + "modules/src/input+lib", + "modules/src/print+lib", + "modules/src/string+lib", + "modules/src/system+lib", + } +} + +installable { + name = "pkg", + map = { + ["$(PLATDEP)/cpp.ansi"] = "+cpp" + } +} + diff --git a/plat/build.lua b/plat/build.lua index cd220bb9f..b8b457c0d 100644 --- a/plat/build.lua +++ b/plat/build.lua @@ -1,7 +1,32 @@ include("mach/proto/as/build.lua") include("mach/proto/ncg/build.lua") -definerule("build_plat", +definerule("ackfile", + { + srcs = { type="targets" }, + deps = { type="targets", default={} }, + }, + function (e) + local plat = e.vars.plat + + return cfile { + name = e.name, + srcs = e.srcs, + deps = { + "plat/"..plat.."+tools", + "util/ack+pkg", + "lang/cem/cpp.ansi+pkg", + unpack(e.deps) + }, + commands = { + "ACKDIR=$(INSDIR) $(INSDIR)/bin/ack -m%{plat} -c -o %{outs} %{ins} %{hdrpaths} %{ackcflags}" + } + } + end +) + + +definerule("build_plat_tools", { arch = { type = "string" }, plat = { type = "string" }, @@ -19,28 +44,13 @@ definerule("build_plat", arch = e.arch, } - local tools = installable { - name = "tools", - map = { - ["$(PLATDEP)/"..e.arch.."/as"] = as, - ["$(PLATDEP)/"..e.plat.."/ncg"] = ncg, - ["$(PLATIND)/descr/"..e.plat.."/descr"] = descr, - } - } - - local libraries = installable { - name = "libraries", - map = { - } - } - return installable { name = e.name, map = { - tools, - libraries, + ["$(PLATDEP)/"..e.plat.."/as"] = as, + ["$(PLATDEP)/"..e.plat.."/ncg"] = ncg, + ["$(PLATIND)/descr/"..e.plat] = descr, } } end ) - diff --git a/plat/pc86/build.lua b/plat/pc86/build.lua index 5976b8933..baef77e7e 100644 --- a/plat/pc86/build.lua +++ b/plat/pc86/build.lua @@ -1,7 +1,22 @@ include("plat/build.lua") -build_plat { - name = "pkg", +build_plat_tools { + name = "tools", arch = "i86", plat = "pc86", } + +ackfile { + name = "boot", + srcs = { "./boot.s" }, + vars = { plat = "pc86" } +} + +installable { + name = "pkg", + map = { + "+tools", + ["$(PLATIND)/pc86/boot.o"] = "+boot" + } +} + diff --git a/util/cmisc/build.lua b/util/cmisc/build.lua new file mode 100644 index 000000000..8ffe24a36 --- /dev/null +++ b/util/cmisc/build.lua @@ -0,0 +1,25 @@ +cprogram { + name = "tabgen", + srcs = { "./tabgen.c" } +} + +definerule("tabgen", + { + srcs = { type="targets" }, + }, + function(e) + local symname = replace(basename(e.srcs[1]), "%.tab$", "") + + return normalrule { + name = e.name, + ins = { + "util/cmisc+tabgen", + unpack(e.srcs) + }, + outleaves = { symname..".c" }, + commands = { + "%{ins[1]} -f%{ins[2]} > %{outs} || rm %{outs}" + } + } + end +)