Biggish refactor to break cycles; my build rules were full of them. cpm builds,
authorDavid Given <dg@cowlark.com>
Sat, 13 Aug 2016 23:39:40 +0000 (01:39 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 13 Aug 2016 23:39:40 +0000 (01:39 +0200)
which requires top and topgen.

14 files changed:
build.lua
lang/cem/cpp.ansi/build.lua
mach/i80/libem/build.lua [new file with mode: 0644]
mach/i80/libend/build.lua [new file with mode: 0644]
mach/proto/top/build.lua [new file with mode: 0644]
plat/build.lua
plat/cpm/build-headers.lua [new file with mode: 0644]
plat/cpm/build-pkg.lua [new file with mode: 0644]
plat/cpm/build-tools.lua [new file with mode: 0644]
plat/pc86/build-headers.lua [new file with mode: 0644]
plat/pc86/build-pkg.lua [moved from plat/pc86/build.lua with 54% similarity]
plat/pc86/build-tools.lua [new file with mode: 0644]
util/topgen/build.lua [new file with mode: 0644]
util/topgen/main.c

index 30da3e9..c5a59a1 100644 (file)
--- a/build.lua
+++ b/build.lua
@@ -5,7 +5,8 @@ vars.ackcflags = {
        "-O"
 }
 vars.plats = {
-       "pc86"
+       "pc86",
+       "cpm",
 }
 
 installable {
@@ -15,6 +16,7 @@ installable {
                "lang/cem/cemcom.ansi+pkg",
                "lang/m2/comp+pkg",
                "lang/pc/comp+pkg",
+               "plat/cpm+pkg",
                "plat/pc86+pkg",
                "util/ack+pkg",
                "util/amisc+pkg",
index 1f22fe8..be12453 100644 (file)
@@ -1,4 +1,5 @@
 include("util/cmisc/build.lua")
+include("util/LLgen/build.lua")
 
 local allocd_header = definerule(nil,
        {
diff --git a/mach/i80/libem/build.lua b/mach/i80/libem/build.lua
new file mode 100644 (file)
index 0000000..ca5a13c
--- /dev/null
@@ -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/i80/libend/build.lua b/mach/i80/libend/build.lua
new file mode 100644 (file)
index 0000000..ca5a13c
--- /dev/null
@@ -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/proto/top/build.lua b/mach/proto/top/build.lua
new file mode 100644 (file)
index 0000000..56ee652
--- /dev/null
@@ -0,0 +1,19 @@
+include("util/topgen/build.lua")
+
+definerule("build_top",
+       {
+               arch = { type="string" },
+       },
+       function(e)
+               local t = topgen {
+                       name = e.name.."_topgen",
+                       srcs = { "mach/"..e.arch.."/top/table" }
+               }
+
+               return cprogram {
+                       name = e.name,
+                       srcs = { "mach/proto/top/*.c", },
+                       deps = { t },
+               }
+       end
+)
index 05f746f..deb2e46 100644 (file)
@@ -1,5 +1,6 @@
 include("mach/proto/as/build.lua")
 include("mach/proto/ncg/build.lua")
+include("mach/proto/top/build.lua")
 
 definerule("ackfile",
        {
@@ -53,36 +54,6 @@ definerule("acklibrary",
        end
 )
 
-definerule("build_plat_tools",
-       {
-               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,
-               }
-
-               return installable {
-                       name = e.name,
-                       map = {
-                               ["$(PLATDEP)/"..e.plat.."/as"] = as,
-                               ["$(PLATDEP)/"..e.plat.."/ncg"] = ncg,
-                               ["$(PLATIND)/descr/"..e.plat] = descr,
-                               "util/opt+pkg",
-                       }
-               }
-       end
-)
-
 definerule("build_plat_libs",
        {
                arch = { type="string" },
@@ -93,15 +64,13 @@ definerule("build_plat_libs",
                        name = e.name,
                        map = {
                                "lang/basic/lib+pkg_"..e.plat,
-                               "lang/cem/libcc.ansi+pkg_"..e.plat,
-                               "lang/m2/libm2+pkg_"..e.plat,
-                               "lang/pc/libpc+pkg_"..e.plat,
+                               --"lang/cem/libcc.ansi+pkg_"..e.plat,
+                               --"lang/m2/libm2+pkg_"..e.plat,
+                               --"lang/pc/libpc+pkg_"..e.plat,
                                ["$(PLATIND)/"..e.plat.."/libem.a"] = "mach/"..e.arch.."/libem+lib_"..e.plat,
                                ["$(PLATIND)/"..e.plat.."/libend.a"] = "mach/"..e.arch.."/libend+lib_"..e.plat,
-                               ["$(PLATIND)/"..e.plat.."/libsys.a"] = "mach/"..e.arch.."/libsys+lib_"..e.plat,
                        }
                }
        end
 )
 
-
diff --git a/plat/cpm/build-headers.lua b/plat/cpm/build-headers.lua
new file mode 100644 (file)
index 0000000..eb3cc8f
--- /dev/null
@@ -0,0 +1,11 @@
+include("plat/build.lua")
+
+acklibrary {
+       name = "headers",
+       hdrs = {
+               ["ack/config.h"] = "./include/ack/config.h",
+               ["unistd.h"] = "./include/unistd.h",
+               ["cpm.h"] = "./include/cpm.h",
+       }
+}
+
diff --git a/plat/cpm/build-pkg.lua b/plat/cpm/build-pkg.lua
new file mode 100644 (file)
index 0000000..1dace45
--- /dev/null
@@ -0,0 +1,24 @@
+include("plat/build.lua")
+include("lang/build.lua")
+
+ackfile {
+       name = "boot",
+       srcs = { "./boot.s" },
+       vars = { plat = "cpm" }
+}
+
+build_plat_libs {
+       name = "libs",
+       arch = "i80",
+       plat = "cpm",
+}
+
+installable {
+       name = "pkg",
+       map = {
+               "+tools",
+               "+libs",
+               ["$(PLATIND)/cpm/boot.o"] = "+boot"
+       }
+}
+
diff --git a/plat/cpm/build-tools.lua b/plat/cpm/build-tools.lua
new file mode 100644 (file)
index 0000000..383cf8c
--- /dev/null
@@ -0,0 +1,27 @@
+include("plat/build.lua")
+
+build_as {
+       name = "as",
+       arch = "i80",
+}
+
+build_ncg {
+       name = "ncg",
+       arch = "i80",
+}
+
+build_top {
+       name = "top",
+       arch = "i80",
+}
+
+return installable {
+       name = "tools",
+       map = {
+               ["$(PLATDEP)/cpm/as"] = "+as",
+               ["$(PLATDEP)/cpm/ncg"] = "+ncg",
+               ["$(PLATDEP)/cpm/top"] = "+top",
+               ["$(PLATIND)/descr/cpm"] = "./descr",
+               "util/opt+pkg",
+       }
+}
diff --git a/plat/pc86/build-headers.lua b/plat/pc86/build-headers.lua
new file mode 100644 (file)
index 0000000..8b326df
--- /dev/null
@@ -0,0 +1,10 @@
+include("plat/build.lua")
+
+acklibrary {
+       name = "headers",
+       hdrs = {
+               ["ack/config.h"] = "./include/ack/config.h",
+               ["unistd.h"] = "./include/unistd.h",
+       }
+}
+
similarity index 54%
rename from plat/pc86/build.lua
rename to plat/pc86/build-pkg.lua
index 002f66a..667d62f 100644 (file)
@@ -1,11 +1,4 @@
 include("plat/build.lua")
-include("lang/build.lua")
-
-build_plat_tools {
-       name = "tools",
-       arch = "i86",
-       plat = "pc86",
-}
 
 ackfile {
        name = "boot",
@@ -13,14 +6,6 @@ ackfile {
        vars = { plat = "pc86" }
 }
 
-acklibrary {
-       name = "headers",
-       hdrs = {
-               ["ack/config.h"] = "./include/ack/config.h",
-               ["unistd.h"] = "./include/unistd.h",
-       }
-}
-
 build_plat_libs {
        name = "libs",
        arch = "i86",
diff --git a/plat/pc86/build-tools.lua b/plat/pc86/build-tools.lua
new file mode 100644 (file)
index 0000000..fbb34bd
--- /dev/null
@@ -0,0 +1,21 @@
+include("plat/build.lua")
+
+build_as {
+       name = "as",
+       arch = "i86",
+}
+
+build_ncg {
+       name = "ncg",
+       arch = "i86",
+}
+
+return installable {
+       name = "tools",
+       map = {
+               ["$(PLATDEP)/pc86/as"] = "+as",
+               ["$(PLATDEP)/pc86/ncg"] = "+ncg",
+               ["$(PLATIND)/descr/pc86"] = "./descr",
+               "util/opt+pkg",
+       }
+}
diff --git a/util/topgen/build.lua b/util/topgen/build.lua
new file mode 100644 (file)
index 0000000..7156322
--- /dev/null
@@ -0,0 +1,43 @@
+include("util/LLgen/build.lua")
+
+llgen {
+       name = "llgen",
+       srcs = { "./*.g" }
+}
+
+cprogram {
+       name = "topgen",
+       srcs = {
+               "./*.c",
+               matching(filenamesof("+llgen"), "%.c$"),
+       },
+       deps = {
+               "+llgen",
+       }
+}
+
+definerule("topgen",
+       {
+               srcs = { type="targets" },
+       },
+       function(e)
+               -- Remember this is executed from the caller's directory; local
+               -- target names will resolve there
+
+               return normalrule {
+                       name = e.name,
+                       outleaves = {
+                               "gen.c",
+                               "gen.h",
+                       },
+                       ins = {
+                               "util/topgen+topgen",
+                               e.srcs,
+                       },
+                       commands = {
+                               "%{ins[1]} %{ins[2]} %{dir}"
+                       }
+               }
+       end
+)
+
index dd6c4c8..2f211f8 100644 (file)
@@ -22,13 +22,17 @@ char *inpfile;
 main(argc,argv) char *argv[]; {
 
     newline = 1;
-    if (argc != 2) {
-       fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]);
+    if (argc != 3) {
+       fprintf(stderr,"Usage : %s targetoptimizerdescription outputdir\n",argv[0]);
        exit(1);
     }
     if ((input = fopen(argv[1],"r")) == NULL) {
        fprintf(stderr,"Fatal error : couldn't open %s\n",argv[1]);
        exit(1);
+    }
+       if (chdir(argv[2]) != 0) {
+       fprintf(stderr,"Fatal error : couldn't chdir to %s\n",argv[2]);
+       exit(1);
     }
     if ((genc = fopen("gen.c","w")) == NULL) {
        fputs("Fatal error : couldn't open gen.c\n",stderr);