--- /dev/null
+include("util/ncgg/build.lua")
+
+definerule("build_ncg",
+ {
+ arch = { type="string" }
+ },
+ function(e)
+ -- Remember this is executed from the caller's directory; local
+ -- target names will resolve there
+ local headers = clibrary {
+ name = e.name.."/headers",
+ srcs = {},
+ hdrs = {
+ "mach/proto/ncg/*.h",
+ "mach/"..e.arch.."/ncg/mach*"
+ }
+ }
+
+ local tables = ncgg {
+ name = e.name.."/tables",
+ srcs = { "mach/"..e.arch.."/ncg/table" }
+ }
+
+ return cprogram {
+ name = e.name,
+ srcs = {
+ "mach/proto/ncg/*.c",
+ "mach/"..e.arch.."/ncg/mach.h",
+ archlib, -- for .c file
+ tables, -- for .c file
+ },
+ deps = {
+ "h+emheaders",
+ "modules+headers",
+ "modules/src/flt_arith+lib",
+ "modules/src/object+lib",
+ "util/data+em_data",
+ archlib, -- for .h file
+ headers,
+ tables, -- for .h file
+ }
+ }
+ end
+)
+
+include("mach/proto/as/build.lua")
+include("mach/proto/ncg/build.lua")
+
+definerule("build_plat",
+ {
+ arch = { type = "string" },
+ plat = { type = "string" },
+ },
+ function(e)
+ local descr = "plat/"..e.plat.."/descr"
+
+ local as = build_as {
+ name = "as",
+ arch = e.arch
+ }
+
+ local ncg = build_ncg {
+ name = "ncg",
+ 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,
+ }
+ }
+ end
+)
+
--- /dev/null
+include("first/yacc.lua")
+
+local cggparser = yacc {
+ name = "cggparser",
+ srcs = { "./cgg.y" }
+}
+
+flex {
+ name = "cgglexer",
+ srcs = { "./scan.l" }
+}
+
+normalrule {
+ name = "keywords",
+ ins = {
+ "./cvtkeywords",
+ "./keywords",
+ unpack(filenamesof({cggparser}, "%.h$"))
+ },
+ outleaves = { "enterkeyw.c" },
+ commands = {
+ "%{ins[1]} %{ins[2]} %{ins[3]} %{outs[1]}"
+ }
+}
+
+cprogram {
+ name = "ncgg",
+ srcs = {
+ "./*.c",
+ "+cggparser", -- for .c file
+ "+cgglexer", -- for .c file
+ "+keywords",
+ },
+ deps = {
+ "+cggparser", -- for .h file
+ "+cgglexer", -- for .h file
+ "h+emheaders",
+ "util/data+em_data",
+ }
+}
+
+definerule("ncgg",
+ {
+ srcs = { type="targets" }
+ },
+ function(e)
+ -- Remember this is executed from the caller's directory; local
+ -- target names will resolve there
+ if (#e.srcs ~= 1) then
+ error("you must supply exactly one input file")
+ end
+
+ local cpptable = cppfile {
+ name = e.name.."/cpptable",
+ outleaf = "cpptable",
+ srcs = e.srcs
+ }
+
+ return normalrule {
+ name = e.name,
+ cwd = e.cwd,
+ outleaves = {
+ "tables.c",
+ "tables.h",
+ },
+ ins = {
+ "util/ncgg+ncgg",
+ cpptable
+ },
+ commands = {
+ "cd %{dir} && %{ins}",
+ "mv %{dir}/tables.H %{dir}/tables.h"
+ }
+ }
+ end
+)
+
+--[[
+D := util/ncgg
+
+define build-ncgg-impl
+
+$(call reset)
+$(eval cflags += -I$D)
+
+$(call yacc, $(OBJDIR)/$D, $D/cgg.y)
+
+$(call flex, $(OBJDIR)/$D, $D/scan.l)
+$(call dependson, $(OBJDIR)/$D/y.tab.h)
+
+$(call cfile, $D/subr.c)
+$(call cfile, $D/main.c)
+$(call cfile, $D/coerc.c)
+$(call cfile, $D/error.c)
+$(call cfile, $D/emlookup.c)
+$(call cfile, $D/expr.c)
+$(call cfile, $D/instruct.c)
+$(call cfile, $D/iocc.c)
+$(call cfile, $D/lookup.c)
+$(call cfile, $D/output.c)
+$(call cfile, $D/set.c)
+$(call cfile, $D/strlookup.c)
+$(call cfile, $D/var.c)
+$(call cfile, $D/hall.c)
+
+$(eval CLEANABLES += $(OBJDIR)/$D/enterkeyw.c)
+$(OBJDIR)/$D/enterkeyw.c: $D/cvtkeywords $D/keywords $(OBJDIR)/$D/y.tab.h
+ @echo KEYWORDS $$@
+ @mkdir -p $$(dir $$@)
+ $(hide) cd $$(dir $$@) && sh $(abspath $D/cvtkeywords) $(abspath $D/keywords)
+$(call cfile, $(OBJDIR)/$D/enterkeyw.c)
+
+$(eval $q: $(INCDIR)/em_spec.h)
+
+$(call rawfile, $(LIBEM_DATA))
+$(call cprogram, $(BINDIR)/ncgg)
+$(eval NCGG := $o)
+
+endef
+
+$(eval $(build-ncgg-impl))
+--]]