From bff5c4019c23b617736e9f789b8b22ded86bfb91 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 24 Jul 2016 00:50:02 +0200 Subject: [PATCH] Baby steps towards building a platform --- make the assembler work. Add ackbuilder support for C preprocessor files and yacc. --- build.lua | 1 + first/ackbuilder.lua | 9 ++++- first/build.lua | 44 ++++++++++++++++++++-- first/yacc.lua | 23 ++++++++++++ mach/proto/as/build.lua | 46 +++++++++++++++++++++++ plat/build.lua | 0 plat/pc86/build.lua | 14 +++++++ util/misc/build.lua | 82 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 first/yacc.lua create mode 100644 mach/proto/as/build.lua create mode 100644 plat/build.lua create mode 100644 plat/pc86/build.lua create mode 100644 util/misc/build.lua diff --git a/build.lua b/build.lua index 86641357d..7b28b0d30 100644 --- a/build.lua +++ b/build.lua @@ -6,6 +6,7 @@ installable { "util/amisc+pkg", "util/arch+pkg", "util/misc+pkg", + "plat/pc86+pkg", } } diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 539b34897..c7184bc9f 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -375,6 +375,13 @@ local typeconverters = { return i end, + boolean = function(propname, i) + if (type(i) ~= "boolean") then + error(string.format("property '%s' must be a boolean", propname)) + end + return i + end, + string = function(propname, i) if (type(i) ~= "string") then error(string.format("property '%s' must be a string", propname)) @@ -410,7 +417,7 @@ local function definerule(rulename, types, cb) local args = {} for propname, typespec in pairs(types) do if not e[propname] then - if not typespec.optional and not typespec.default then + if not typespec.optional and (typespec.default == nil) then error(string.format("missing mandatory property '%s'", propname)) end diff --git a/first/build.lua b/first/build.lua index dcddaae90..31c790f13 100644 --- a/first/build.lua +++ b/first/build.lua @@ -62,10 +62,6 @@ definerule("cfile", end hdrpaths = uniquify(hdrpaths) - for _, f in pairs(filenamesof(hdeps)) do - hsrcs[#hsrcs+1] = f - end - local outleaf = basename(csrcs[1]):gsub("%.c$", ".o") return normalrule { @@ -84,6 +80,46 @@ definerule("cfile", end ) +definerule("cppfile", + { + srcs = { type="targets" }, + deps = { type="targets", default={} }, + outleaf = { type="string" }, + cflags = { type="strings", default={} }, + commands = { + type="strings", + default={ + "$(CC) -E -P -o %{outs[1]} %{hdrpaths} %{cflags} -x c %{ins}" + } + }, + }, + function (e) + if (#e.srcs ~= 1) then + error("you must have exactly one input file") + end + + local hdrpaths = {} + for _, t in pairs(e.deps) do + hdrpaths[#hdrpaths+1] = "-I"..t.dir + end + hdrpaths = uniquify(hdrpaths) + + return normalrule { + name = e.name, + cwd = e.cwd, + ins = e.srcs, + deps = e.deps, + outleaves = {e.outleaf}, + label = e.label, + commands = e.commands, + vars = { + hdrpaths = hdrpaths, + cflags = e.cflags, + } + } + end +) + definerule("bundle", { srcs = { type="targets" }, diff --git a/first/yacc.lua b/first/yacc.lua new file mode 100644 index 000000000..bb308003e --- /dev/null +++ b/first/yacc.lua @@ -0,0 +1,23 @@ +definerule("yacc", + { + srcs = { type="targets" }, + commands = { + type="strings", + default={ + "yacc -t -b %{dir}/y -d %{ins}" + } + }, + }, + function (e) + return normalrule { + name = e.name, + cwd = e.cwd, + ins = e.srcs, + outleaves = { "y.tab.c", "y.tab.h" }, + label = e.label, + commands = e.commands, + } + end +) + + diff --git a/mach/proto/as/build.lua b/mach/proto/as/build.lua new file mode 100644 index 000000000..39e491813 --- /dev/null +++ b/mach/proto/as/build.lua @@ -0,0 +1,46 @@ +include("first/yacc.lua") + +definerule("build_as", + { + arch = { type="string" } + }, + function(e) + -- Remember this is executed from the caller's directory; local + -- target names will resolve there + local archlib = clibrary { + name = e.name.."/archlib", + srcs = {}, + hdrs = { "mach/"..e.arch.."/as/mach*.c" } + } + + local preprocessedy = cppfile { + name = e.name.."/yaccinput", + srcs = { "mach/proto/as/comm2.y" }, + outleaf = "comm2.y", + deps = { + "h+emheaders", + archlib, + }, + } + + local yaccfiles = yacc { + name = e.name.."/yacc", + srcs = { preprocessedy } + } + + return cprogram { + name = e.name, + srcs = { + "mach/proto/as/*.c", + yaccfiles, -- for .c file + }, + deps = { + "h+emheaders", + "modules/src/object+lib", + archlib, + yaccfiles, -- for .h file + } + } + end +) + diff --git a/plat/build.lua b/plat/build.lua new file mode 100644 index 000000000..e69de29bb diff --git a/plat/pc86/build.lua b/plat/pc86/build.lua new file mode 100644 index 000000000..c3a70093e --- /dev/null +++ b/plat/pc86/build.lua @@ -0,0 +1,14 @@ +include("mach/proto/as/build.lua") + +build_as { + name = "as", + arch = "i86" +} + +installable { + name = "pkg", + map = { + ["$(PLATDEP)/pc86/as"] = "+as" + } +} + diff --git a/util/misc/build.lua b/util/misc/build.lua new file mode 100644 index 000000000..ab0a26d7d --- /dev/null +++ b/util/misc/build.lua @@ -0,0 +1,82 @@ +cprogram { + name = "esize", + srcs = { "./esize.c" }, +} + +cprogram { + name = "encode", + 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_ev", + "modules/src/string+lib", + "modules/src/system+lib", + "util/data+em_data", + } +} + +installable { + name = "pkg", + map = { + ["$(PLATDEP)/em_encode"] = "+encode", + ["$(INSDIR)/bin/esize"] = "+esize", + ["$(PLATIND)/man/man1/esize.1"] = "./esize.1", + ["$(PLATIND)/man/man6/em_decode.6"] = "./em_decode.6" + } +} + +--[[ +D := util/misc + +define build-misc-impl + $(call reset) + $(call cfile, $D/esize.c) + $(call cprogram, $(BINDIR)/esize) + $(call installto, $(INSDIR)/bin/esize) + + $(call reset) + $(eval q := $D/esize.1) + $(call installto, $(INSDIR)/share/man/man1/esize.1) + + $(call reset) + $(eval objdir := encode) + $(call cfile, $D/convert.c) + $(eval $q: $(INCDIR)/em_comp.h $(INCDIR)/em_codeEK.h) + $(call rawfile, $(LIBREAD_EMEV)) + $(call rawfile, $(LIBEMK)) + $(call rawfile, $(LIBEM_DATA)) + $(call rawfile, $(LIBALLOC)) + $(call rawfile, $(LIBPRINT)) + $(call rawfile, $(LIBSTRING)) + $(call rawfile, $(LIBSYSTEM)) + $(call cprogram, $(BINDIR)/em_encode) + $(call installto, $(PLATDEP)/em_encode) + $(eval EM_ENCODE := $o) + $(eval ACK_CORE_TOOLS += $o) + + $(call reset) + $(eval objdir := decode) + $(call cfile, $D/convert.c) + $(eval $q: $(INCDIR)/em_comp.h $(INCDIR)/em_codeEK.h) + $(call rawfile, $(LIBREAD_EMKV)) + $(call rawfile, $(LIBEME)) + $(call rawfile, $(LIBEM_DATA)) + $(call rawfile, $(LIBALLOC)) + $(call rawfile, $(LIBPRINT)) + $(call rawfile, $(LIBSTRING)) + $(call rawfile, $(LIBSYSTEM)) + $(call cprogram, $(BINDIR)/em_decode) + $(call installto, $(PLATDEP)/em_decode) + $(eval EM_DECODE := $o) + + $(call reset) + $(eval q := $D/em_decode.6) + $(call installto, $(INSDIR)/share/man/man6/em_decode.6) +endef + +$(eval $(build-misc-impl)) +--]] -- 2.34.1