From 74342149b52ff715c66d25216e32b7689490cbdb Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:41:39 +0000 Subject: [PATCH 01/40] Create new branch named "ab22" From 68fd6b48893714903068c9c81bac9664cf6a8eb5 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:38 +0000 Subject: [PATCH 02/40] First very prototype version of ab2. --- Makefile | 16 ++-- build.py | 19 ++++ build/ab2.py | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 285 insertions(+), 7 deletions(-) create mode 100644 build.py create mode 100644 build/ab2.py diff --git a/Makefile b/Makefile index 3b604023..de561ab8 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,19 @@ export CFLAGS = -g -O0 export LDFLAGS = -g export NINJAFLAGS = -all: $(OBJ)/build.ninja - @ninja -f $(OBJ)/build.ninja $(NINJAFLAGS) +all: $(OBJ)/build.mk + @make -f $(OBJ)/build.mk hide= y clean: @echo CLEAN @rm -rf $(OBJ) bin -lua-files = $(shell find . -name 'build*.lua') $(wildcard build/*.lua) toolchains.lua -$(OBJ)/build.ninja: mkninja.lua Makefile $(lua-files) - @echo MKNINJA +build-files = $(shell find . -name 'build.py') +$(OBJ)/build.mk: build/ab2.py Makefile $(build-files) + @echo ACKBUILDER @mkdir -p $(OBJ) - @$(LUA) \ - mkninja.lua \ + @python3 \ + build/ab2.py \ + -m make \ + build.py \ > $@ diff --git a/build.py b/build.py new file mode 100644 index 00000000..75e5b532 --- /dev/null +++ b/build.py @@ -0,0 +1,19 @@ +simplerule( + name="main", + ins=["README.md"], + outs=["x"], + commands=[ + "cp {ins} {outs}" + ] +) + +simplerule( + name="y", + ins=["+main"], + outs=["y"], + commands=[ + "cp {ins} {outs}" + ], + label="Y" +) + diff --git a/build/ab2.py b/build/ab2.py new file mode 100644 index 00000000..d01d5b41 --- /dev/null +++ b/build/ab2.py @@ -0,0 +1,257 @@ +from collections.abc import Iterable +import argparse +import functools +import inspect +import os.path +import re +import sys + +defaultGlobals = {} +targets = {} +cwd = "." +unmaterialisedTargets = set() +emitter = None + + +class ABException(BaseException): + pass + + +class Invocation: + name = None + callback = None + types = None + ins = [] + outs = [] + rawArgs = {} + + def materialise(self): + if self in unmaterialisedTargets: + self.args = {} + for k, v in self.rawArgs.items(): + t = self.types.get(k, None) + if t: + v = t.convert(v) + self.args[k] = v + + self.callback.__globals__["self"] = self + self.callback(**self.args) + unmaterialisedTargets.remove(self) + + +class Type: + pass + + +class String(Type): + def convert(self, value): + if type(value) != "string": + raise ABException("rule wanted a String, but got a "+type(value)) + return value + + +class Strings(Type): + def convert(self, value): + if type(value) == "string": + value = [value] + return value + + +class Targets(Type): + def convert(self, value): + if type(value) is str: + value = [value] + if type(value) is list: + value = [targetof(v) for v in value] + return value + + +def debug(*s): + print(*s, file=sys.stderr) + + +def flatten(*xs): + def recurse(xs): + for x in xs: + if isinstance(x, Iterable) and not isinstance(x, (str, bytes)): + yield from recurse(x) + else: + yield x + + return list(recurse(xs)) + + +def targetof(s): + if isinstance(s, Invocation): + return s + + if s.startswith("+"): + s = cwd + s + if s.startswith("./"): + s = cwd + "/" + s + + if s in targets: + t = targets[s] + t.materialise() + return t + + if "+" in s: + raise ABException("target reference %s not supported yet" % s) + else: + i = Invocation() + i.outs = [s] + targets[s] = i + return i + + +def targetsof(*xs): + return flatten([targetof(x) for x in flatten(xs)]) + + +def filenamesof(*xs): + xs = targetsof(xs) + + f = [] + for t in xs: + f += t.outs + return f + + +def emit(*args): + print(*flatten(args)) + + +def unmake(ss): + return ss + + +def templateexpand(s, invocation): + class Converter: + def __getitem__(self, key): + f = filenamesof(invocation.args[key]) + if type(f) is list: + return " ".join(f) + return f + + return eval("f%r" % s, invocation.callback.__globals__, Converter()) + + +class MakeEmitter: + def begin(self): + emit("hide = @") + + def end(self): + pass + + def var(self, name, value): + # Don't let emit insert spaces. + emit(name+"="+value) + + def rule(self, name, ins, outs): + if outs: + emit(".PHONY:", name) + emit(name, ":", outs) + emit(outs, "&:", ins) + else: + emit(name, ":", ins) + + def exec(self, command): + emit("\t$(hide)", command) + + +class NinjaEmitter: + def begin(self): + emit("rule build\n") + emit(" command = $command\n") + emit("\n") + + def var(self, name, value): + # Don't let emit insert spaces. + emit(name+"="+unmake(value)) + + def rule(self, name, ins, outs): + if outs: + emit("build", name, ": phony", unmake(outs)) + emit("build", unmake(outs), ": build", unmake(ins)) + else: + emit("build", name, ": phony", unmake(ins)) + + +def Rule(func): + name = func.__name__ + sig = inspect.signature(func) + + @functools.wraps(func) + def wrapper(*, name, **kwargs): + bound = sig.bind(name=name, **kwargs) + bound.apply_defaults() + + i = Invocation() + i.fullname = cwd + "+" + name + i.name = name + i.rawArgs = bound.arguments + i.types = func.__annotations__ + i.callback = func + + targets[i.fullname] = i + unmaterialisedTargets.add(i) + + defaultGlobals[name] = wrapper + return wrapper + + +@Rule +def simplerule( + name=None, + ins: Targets() = [], + outs: Strings() = [], + deps: Targets() = [], + commands: Strings() = [], + label="RULE"): + + self.ins = ins + self.outs = outs + emitter.rule(self.fullname, filenamesof(ins, deps), outs) + emitter.exec(templateexpand("@echo {label} {ins}", self)) + for c in commands: + emitter.exec(templateexpand(c, self)) + + +def loadbuildfile(filename): + with open(filename, "r") as fp: + global cwd + code = compile(fp.read(), filename, + mode="exec") + oldCwd = cwd + cwd = os.path.dirname(filename) + if cwd == "": + cwd = "." + exec(code, dict(defaultGlobals, CWD=cwd)) + cwd = oldCwd + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "-m", "--mode", choices=["make", "ninja"], default="make") + parser.add_argument("files", nargs="+") + args = parser.parse_args() + + global emitter + if args.mode == "make": + emitter = MakeEmitter() + else: + emitter = NinjaEmitter() + emitter.begin() + + for f in args.files: + loadbuildfile(f) + + while unmaterialisedTargets: + debug(len(unmaterialisedTargets)) + next(iter(unmaterialisedTargets)).materialise() + + emitter.end() + + +main() From 73a210794127e86156556eb1e5ba3336e87c7019 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:39 +0000 Subject: [PATCH 03/40] Most of the rule engine seems to work, including inherited variables. --- Makefile | 2 +- build.py | 30 +++---- build/ab2.py | 179 ++++++++++++++++++++++++++++++++++++----- build/c.py | 22 +++++ tools/tubeemu/build.py | 0 5 files changed, 193 insertions(+), 40 deletions(-) create mode 100644 build/c.py create mode 100644 tools/tubeemu/build.py diff --git a/Makefile b/Makefile index de561ab8..e1148c41 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ export LDFLAGS = -g export NINJAFLAGS = all: $(OBJ)/build.mk - @make -f $(OBJ)/build.mk hide= y + @make -f $(OBJ)/build.mk hide= +cfile clean: @echo CLEAN diff --git a/build.py b/build.py index 75e5b532..6d3a84b0 100644 --- a/build.py +++ b/build.py @@ -1,19 +1,15 @@ -simplerule( - name="main", - ins=["README.md"], - outs=["x"], - commands=[ - "cp {ins} {outs}" - ] -) +from os.path import * -simplerule( - name="y", - ins=["+main"], - outs=["y"], - commands=[ - "cp {ins} {outs}" - ], - label="Y" -) +installable( + name="all", + items={ + "bbctube.o": "tools/tubeemu+bbctube", + }) +cfile( + name="cfile", + srcs=["tools/tubeemu/bbctube.c"], + vars={ + "+cflags": ["-Ithird_party/lib6502"] + } +) diff --git a/build/ab2.py b/build/ab2.py index d01d5b41..3dd4cd02 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -1,22 +1,67 @@ -from collections.abc import Iterable +from collections.abc import Iterable, Sequence +from os.path import * import argparse import functools import inspect -import os.path import re import sys +import copy defaultGlobals = {} targets = {} -cwd = "." +cwd = "" unmaterialisedTargets = set() emitter = None +currentVars = None class ABException(BaseException): pass +class ParameterList(Sequence): + def __init__(self, parent=[]): + self.data = parent + + def __getitem__(self, i): + return self.data[i] + + def __len__(self): + return len(self.data) + + def __str__(self): + return " ".join(self.data) + + def __add__(self, other): + newdata = self.data.copy() + other + return ParameterList(newdata) + + def __repr__(self): + return f"" + + +def Vars(parent=None): + data = {} + + class VarsImpl: + def __setattr__(self, k, v): + data[k] = v + + def __getattr__(self, k): + if k in data: + return data[k] + if parent: + return getattr(parent, k) + return ParameterList() + + def __repr__(self): + return f" {parent}>" + + __setitem__ = __setattr__ + __getitem__ = __getattr__ + + return VarsImpl() + class Invocation: name = None callback = None @@ -24,6 +69,8 @@ class Invocation: ins = [] outs = [] rawArgs = {} + vars = None + varsettings = None def materialise(self): if self in unmaterialisedTargets: @@ -34,10 +81,34 @@ def materialise(self): v = t.convert(v) self.args[k] = v + global currentVars + self.vars = Vars(self.callerVars) + oldVars = currentVars + currentVars = self.vars + + if self.varsettings: + for k, v in self.varsettings.items(): + if k.startswith("+"): + k = k[1:] + self.vars[k] = self.vars[k] + flatten(v) + else: + self.vars[k] = ParameterList(v) + self.callback.__globals__["self"] = self - self.callback(**self.args) + newInvocation = self.callback(**self.args) + newInvocation = newInvocation or self + if newInvocation != self: + for k in dir(newInvocation): + if not k.startswith("_"): + setattr(self, k, getattr(newInvocation, k)) + self.materialise() + + currentVars = oldVars unmaterialisedTargets.remove(self) + def __str__(self): + return "" % self.fullname + class Type: pass @@ -128,9 +199,11 @@ def unmake(ss): def templateexpand(s, invocation): class Converter: def __getitem__(self, key): + if key == "vars": + return invocation.vars f = filenamesof(invocation.args[key]) - if type(f) is list: - return " ".join(f) + if isinstance(f, Sequence): + f = ParameterList(f) return f return eval("f%r" % s, invocation.callback.__globals__, Converter()) @@ -145,18 +218,18 @@ def end(self): def var(self, name, value): # Don't let emit insert spaces. - emit(name+"="+value) + emit(name+"="+unmake(value)) def rule(self, name, ins, outs): if outs: emit(".PHONY:", name) - emit(name, ":", outs) - emit(outs, "&:", ins) + emit(name, ":", unmake(outs)) + emit(outs, "&:", unmake(ins)) else: - emit(name, ":", ins) + emit(name, ":", unmake(ins)) def exec(self, command): - emit("\t$(hide)", command) + emit("\t$(hide)", unmake(command)) class NinjaEmitter: @@ -180,21 +253,29 @@ def rule(self, name, ins, outs): def Rule(func): name = func.__name__ sig = inspect.signature(func) + if "self" in func.__globals__: + os.exit() @functools.wraps(func) def wrapper(*, name, **kwargs): - bound = sig.bind(name=name, **kwargs) - bound.apply_defaults() - i = Invocation() + i.cwd = cwd i.fullname = cwd + "+" + name i.name = name - i.rawArgs = bound.arguments i.types = func.__annotations__ i.callback = func + i.callerVars = currentVars + i.varsettings = kwargs.get("vars", None) + if i.varsettings: + kwargs.pop("vars") + + bound = sig.bind(name=name, **kwargs) + bound.apply_defaults() + i.rawArgs = bound.arguments targets[i.fullname] = i unmaterialisedTargets.add(i) + return i defaultGlobals[name] = wrapper return wrapper @@ -204,28 +285,72 @@ def wrapper(*, name, **kwargs): def simplerule( name=None, ins: Targets() = [], - outs: Strings() = [], + outs=[], deps: Targets() = [], commands: Strings() = [], label="RULE"): - self.ins = ins self.outs = outs emitter.rule(self.fullname, filenamesof(ins, deps), outs) - emitter.exec(templateexpand("@echo {label} {ins}", self)) + emitter.exec(templateexpand("echo {label} {ins}", self)) + + for out in filenamesof(outs): + dir = dirname(out) + if dir: + emitter.exec("mkdir -p "+dir) + for c in commands: emitter.exec(templateexpand(c, self)) +@Rule +def normalrule( + name=None, + ins: Targets() = [], + deps: Targets() = [], + outleaves=[], + label="RULE", + objdir=None, + commands=[]): + objdir = objdir or join("$(OBJ)", self.cwd, name) + + return simplerule( + name=name, + ins=ins, + deps=deps, + outs=[join(objdir, f) for f in outleaves], + label=label, + commands=commands) + + +@Rule +def installable( + name=None, + items={}): + + emitter.rule(self.fullname, filenamesof(items.values()), items.keys()) + emitter.exec(templateexpand("echo EXPORT {name}", self)) + + for dest, src in items.items(): + dir = dirname(dest) + if dir: + emitter.exec("mkdir -p "+dir) + + srcs = filenamesof(src) + if len(srcs) != 1: + raise ABException( + "a dependency of an installable must have exactly one output file") + + emitter.exec("cp %s %s" % (srcs[0], dest)) + + def loadbuildfile(filename): with open(filename, "r") as fp: global cwd code = compile(fp.read(), filename, mode="exec") oldCwd = cwd - cwd = os.path.dirname(filename) - if cwd == "": - cwd = "." + cwd = dirname(filename) exec(code, dict(defaultGlobals, CWD=cwd)) cwd = oldCwd @@ -244,12 +369,22 @@ def main(): emitter = NinjaEmitter() emitter.begin() + global currentVars + currentVars = Vars() + + for k in ("Rule", "Targets"): + defaultGlobals[k] = globals()[k] + defaultGlobals["print"] = debug + for f in args.files: loadbuildfile(f) while unmaterialisedTargets: - debug(len(unmaterialisedTargets)) + total = len(targets) + finished = total - len(unmaterialisedTargets) + sys.stderr.write("%d/%d\r" % (finished, total)) next(iter(unmaterialisedTargets)).materialise() + sys.stderr.write("%d/%d\n" % (total, total)) emitter.end() diff --git a/build/c.py b/build/c.py new file mode 100644 index 00000000..07d71fcf --- /dev/null +++ b/build/c.py @@ -0,0 +1,22 @@ +@Rule +def cfile(name, + srcs: Targets() = [], + deps: Targets() = [], + suffix=".o", + commands=[ + "$(CC) -c -o {outs[0]} {ins[0]} {deps} {vars.cflags}" + ], + label="CC"): + if not name: + name = filenamesof(srcs)[1] + + outleaf = basename(name) + suffix + + return normalrule( + name=name, + ins=srcs, + deps=deps, + outleaves=[outleaf], + label=label, + commands=commands) + diff --git a/tools/tubeemu/build.py b/tools/tubeemu/build.py new file mode 100644 index 00000000..e69de29b From f845fadc3d3c65b0b87c14c96266cd6142201459 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:39 +0000 Subject: [PATCH 04/40] I think the new build system may actually be working! --- Makefile | 6 +- build.py | 11 +- build/ab2.py | 259 ++++++++++++++++++++++++++--------- build/c.py | 83 ++++++++++- third_party/lib6502/build.py | 7 + tools/tubeemu/build.py | 9 ++ 6 files changed, 291 insertions(+), 84 deletions(-) create mode 100644 third_party/lib6502/build.py diff --git a/Makefile b/Makefile index e1148c41..2bf97b45 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,14 @@ export LDFLAGS = -g export NINJAFLAGS = all: $(OBJ)/build.mk - @make -f $(OBJ)/build.mk hide= +cfile + @make -f $(OBJ)/build.mk +all clean: @echo CLEAN @rm -rf $(OBJ) bin -build-files = $(shell find . -name 'build.py') -$(OBJ)/build.mk: build/ab2.py Makefile $(build-files) +build-files = $(shell find . -name 'build.py') build/*.py +$(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) @python3 \ diff --git a/build.py b/build.py index 6d3a84b0..96713e25 100644 --- a/build.py +++ b/build.py @@ -1,15 +1,8 @@ +from build.ab2 import Rule, installable from os.path import * installable( name="all", items={ - "bbctube.o": "tools/tubeemu+bbctube", + "bbctube": "tools/tubeemu+bbctube", }) - -cfile( - name="cfile", - srcs=["tools/tubeemu/bbctube.c"], - vars={ - "+cflags": ["-Ithird_party/lib6502"] - } -) diff --git a/build/ab2.py b/build/ab2.py index 3dd4cd02..88f6e410 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -1,19 +1,48 @@ from collections.abc import Iterable, Sequence from os.path import * +from types import SimpleNamespace import argparse +import copy import functools +import importlib +import importlib.abc +import importlib.util import inspect import re import sys -import copy +import types +import pathlib +import builtins defaultGlobals = {} targets = {} -cwd = "" +currentInvocation = None unmaterialisedTargets = set() emitter = None currentVars = None +sys.path += ["."] +old_import = builtins.__import__ + + +def new_import(name, *args, **kwargs): + if name not in sys.modules: + path = name.replace(".", "/")+".py" + if isfile(path): + sys.stderr.write(f"loading {path}\n") + loader = importlib.machinery.SourceFileLoader(name, path) + + spec = importlib.util.spec_from_loader( + name, loader, origin="built-in") + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + + return old_import(name, *args, **kwargs) + + +builtins.__import__ = new_import + class ABException(BaseException): pass @@ -62,25 +91,36 @@ def __repr__(self): return VarsImpl() + class Invocation: name = None callback = None types = None - ins = [] - outs = [] - rawArgs = {} + ins = None + outs = None + rawArgs = None vars = None varsettings = None def materialise(self): if self in unmaterialisedTargets: + # Create a new invocation frame. + + global currentInvocation + oldInvocation = currentInvocation + currentInvocation = self + + # Perform type conversion to the declared rule parameter types. + self.args = {} for k, v in self.rawArgs.items(): t = self.types.get(k, None) if t: - v = t.convert(v) + v = t.convert(v, self) self.args[k] = v + # Create a new variable frame and set any variables. + global currentVars self.vars = Vars(self.callerVars) oldVars = currentVars @@ -94,20 +134,32 @@ def materialise(self): else: self.vars[k] = ParameterList(v) - self.callback.__globals__["self"] = self - newInvocation = self.callback(**self.args) - newInvocation = newInvocation or self - if newInvocation != self: - for k in dir(newInvocation): - if not k.startswith("_"): - setattr(self, k, getattr(newInvocation, k)) - self.materialise() + # Actually call the callback. If it returns another invocation, + # then replace the current one with it. + + proxy = self.callback(**self.args) + currentInvocation = oldInvocation + + if proxy: + if self.ins or self.outs: + raise ABException( + f"{self.name} is a proxy, but sets self.ins or self.outs") + proxy.materialise() + self.ins = [proxy] + self.outs = proxy.outs + else: + if not self.outs: + raise ABException( + f"{self.name} is not a proxy, but didn't set self.outs") + + # Destack the variable and invocation frame. currentVars = oldVars unmaterialisedTargets.remove(self) + currentInvocation = oldInvocation - def __str__(self): - return "" % self.fullname + def __repr__(self): + return "" % self.name class Type: @@ -115,28 +167,36 @@ class Type: class String(Type): - def convert(self, value): + def convert(self, value, invocation): if type(value) != "string": raise ABException("rule wanted a String, but got a "+type(value)) return value class Strings(Type): - def convert(self, value): + def convert(self, value, invocation): if type(value) == "string": value = [value] return value class Targets(Type): - def convert(self, value): + def convert(self, value, invocation): if type(value) is str: value = [value] if type(value) is list: - value = [targetof(v) for v in value] + value = targetsof(value, cwd=invocation.cwd) return value +class TargetsMap(Type): + def convert(self, value, invocation): + if type(value) is dict: + return { + targetof(k, cwd=invocation.cwd): targetof(v, cwd=invocation.cwd) for k, v in value.items()} + raise ABException(f"wanted a dict of targets, got a {type(value)}") + + def debug(*s): print(*s, file=sys.stderr) @@ -152,40 +212,78 @@ def recurse(xs): return list(recurse(xs)) -def targetof(s): +def massagefilename(s): + callername = inspect.stack()[1][0].f_globals["__name__"] + cwd = dirname(callername.replace(".", "/")) + + if ("+" in name) and not name.startswith("+"): + (cwd, target) = name.split("+", 1) + + i = Invocation() + if name.startswith("./"): + name = join(cwd, name) + elif "+" not in name: + name = cwd + "+" + name + + +def targetof(s, cwd): if isinstance(s, Invocation): + s.materialise() return s - if s.startswith("+"): - s = cwd + s - if s.startswith("./"): - s = cwd + "/" + s - if s in targets: t = targets[s] t.materialise() return t - if "+" in s: - raise ABException("target reference %s not supported yet" % s) - else: - i = Invocation() - i.outs = [s] - targets[s] = i - return i + if s.startswith("+"): + s = cwd + s + if s.startswith("./"): + s = join(cwd, s) + + if "+" not in s: + if isdir(s): + s = s + "+" + basename(s) + else: + i = Invocation() + i.name = "(anonymous)" + i.outs = [s] + targets[s] = i + return i + (path, target) = s.split("+", 2) + loadbuildfile(join(path, "build.py")) + if not s in targets: + raise ABException( + f"build file at {path} doesn't contain +{target}") + i = targets[s] + i.materialise() + return i -def targetsof(*xs): - return flatten([targetof(x) for x in flatten(xs)]) + +def targetsof(*xs, cwd): + return flatten([targetof(x, cwd) for x in flatten(xs)]) def filenamesof(*xs): - xs = targetsof(xs) + fs = [] + for t in flatten(xs): + if type(t) == str: + fs += [t] + else: + fs += [normpath(f) for f in t.outs] + return fs + - f = [] - for t in xs: - f += t.outs - return f +def filenameof(x): + xs = filenamesof(x) + if len(xs) != 1: + raise ABException("expected a single item") + return xs[0] + + +def stripext(path): + return splitext(path)[0] def emit(*args): @@ -251,39 +349,51 @@ def rule(self, name, ins, outs): def Rule(func): - name = func.__name__ sig = inspect.signature(func) - if "self" in func.__globals__: - os.exit() @functools.wraps(func) def wrapper(*, name, **kwargs): + callername = inspect.stack()[1][0].f_globals["__name__"] + cwd = dirname(callername.replace(".", "/")) + + if ("+" in name) and not name.startswith("+"): + (cwd, target) = name.split("+", 1) + i = Invocation() - i.cwd = cwd - i.fullname = cwd + "+" + name + if name.startswith("./"): + name = join(cwd, name) + elif "+" not in name: + name = cwd + "+" + name + i.name = name + i.cwd = cwd i.types = func.__annotations__ i.callback = func i.callerVars = currentVars i.varsettings = kwargs.get("vars", None) - if i.varsettings: - kwargs.pop("vars") + setattr(i, func.__name__, SimpleNamespace()) - bound = sig.bind(name=name, **kwargs) + kwargs.pop("vars", None) + + bound = sig.bind(name=name, self=i, **kwargs) bound.apply_defaults() i.rawArgs = bound.arguments - targets[i.fullname] = i + if name in targets: + raise ABException(f"target {i.name} has already been defined") + + targets[name] = i unmaterialisedTargets.add(i) return i - defaultGlobals[name] = wrapper + defaultGlobals[func.__name__] = wrapper return wrapper @Rule def simplerule( - name=None, + self, + name, ins: Targets() = [], outs=[], deps: Targets() = [], @@ -291,7 +401,7 @@ def simplerule( label="RULE"): self.ins = ins self.outs = outs - emitter.rule(self.fullname, filenamesof(ins, deps), outs) + emitter.rule(self.name, filenamesof(ins, deps), outs) emitter.exec(templateexpand("echo {label} {ins}", self)) for out in filenamesof(outs): @@ -305,6 +415,7 @@ def simplerule( @Rule def normalrule( + self, name=None, ins: Targets() = [], deps: Targets() = [], @@ -312,10 +423,10 @@ def normalrule( label="RULE", objdir=None, commands=[]): - objdir = objdir or join("$(OBJ)", self.cwd, name) + objdir = objdir or join("$(OBJ)", name) return simplerule( - name=name, + name=name+"/simplerule", ins=ins, deps=deps, outs=[join(objdir, f) for f in outleaves], @@ -325,14 +436,19 @@ def normalrule( @Rule def installable( + self, name=None, - items={}): + items: TargetsMap() = {}): - emitter.rule(self.fullname, filenamesof(items.values()), items.keys()) - emitter.exec(templateexpand("echo EXPORT {name}", self)) + emitter.rule(self.name, filenamesof( + items.values()), filenamesof(items.keys())) + emitter.exec(f"echo EXPORT {self.name}") + self.ins = items.values() + self.outs = [] for dest, src in items.items(): - dir = dirname(dest) + destf = filenameof(dest) + dir = dirname(destf) if dir: emitter.exec("mkdir -p "+dir) @@ -341,18 +457,20 @@ def installable( raise ABException( "a dependency of an installable must have exactly one output file") - emitter.exec("cp %s %s" % (srcs[0], dest)) + emitter.exec("cp %s %s" % (srcs[0], destf)) + self.outs += destf def loadbuildfile(filename): - with open(filename, "r") as fp: - global cwd - code = compile(fp.read(), filename, - mode="exec") - oldCwd = cwd - cwd = dirname(filename) - exec(code, dict(defaultGlobals, CWD=cwd)) - cwd = oldCwd + filename = filename.replace("/", ".").removesuffix(".py") + builtins.__import__(filename) + + +def load(filename): + loadbuildfile(filename) + callerglobals = inspect.stack()[1][0].f_globals + for k, v in defaultGlobals.items(): + callerglobals[k] = v def main(): @@ -372,13 +490,18 @@ def main(): global currentVars currentVars = Vars() - for k in ("Rule", "Targets"): + for k in ("Rule", "Targets", "load", "filenamesof", "stripext"): defaultGlobals[k] = globals()[k] defaultGlobals["print"] = debug + global __name__ + sys.modules["build.ab2"] = sys.modules[__name__] + __name__ = "build.ab2" + for f in args.files: loadbuildfile(f) + total = 0 while unmaterialisedTargets: total = len(targets) finished = total - len(unmaterialisedTargets) diff --git a/build/c.py b/build/c.py index 07d71fcf..c5f87c4b 100644 --- a/build/c.py +++ b/build/c.py @@ -1,22 +1,97 @@ +from build.ab2 import Rule, Targets, normalrule, filenamesof, stripext, debug, flatten +from os.path import * + + @Rule -def cfile(name, +def cfile(self, + name, srcs: Targets() = [], deps: Targets() = [], suffix=".o", commands=[ - "$(CC) -c -o {outs[0]} {ins[0]} {deps} {vars.cflags}" + "$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}" ], label="CC"): if not name: name = filenamesof(srcs)[1] - outleaf = basename(name) + suffix + headers = [filenamesof(d.clibrary.hdrs) for d in deps if d.clibrary] + headers = set(["-I"+dirname(f) for f in flatten(headers)]) + + outleaf = stripext(basename(name)) + suffix return normalrule( - name=name, + name=name + "/cfile", ins=srcs, deps=deps, outleaves=[outleaf], label=label, + commands=commands, + vars={ + "+cflags": flatten(headers) + } + ) + + +@Rule +def clibrary(self, + name, + srcs: Targets() = [], + deps: Targets() = [], + hdrs: Targets() = [], + commands=[ + "$(AR) cqs {outs[0]} {ins}" + ], + label="AR"): + + ins = [ + cfile( + name=name+"/"+basename(filenamesof(f)[0]), + srcs=[f], + deps=deps + ) + for f in srcs + ] + + r = normalrule( + name=name+"/clibrary", + ins=ins, + outleaves=[basename(name) + ".a"], + label=label, commands=commands) + r.materialise() + + self.ins = [r] + self.outs = r.outs + self.clibrary.hdrs = hdrs + + +@Rule +def cprogram(self, + name, + srcs: Targets() = [], + deps: Targets() = [], + commands=[ + "$(CC) -o {outs[0]} {ins} {vars.libraries}" + ], + label="CLINK"): + libraries = [d.outs for d in deps if d.clibrary] + + ins = [ + cfile( + name=name+"/"+basename(filenamesof(f)[0]), + srcs=[f], + deps=deps, + ) + for f in srcs + ] + return normalrule( + name=name+"/cprogram", + ins=ins, + outleaves=[basename(name)], + label=label, + commands=commands, + vars={ + "+libraries": libraries + }) diff --git a/third_party/lib6502/build.py b/third_party/lib6502/build.py new file mode 100644 index 00000000..1b39e44d --- /dev/null +++ b/third_party/lib6502/build.py @@ -0,0 +1,7 @@ +from build.c import clibrary + +clibrary( + name="lib6502", + srcs=["./lib6502.c"], + hdrs=["./lib6502.h"], +) diff --git a/tools/tubeemu/build.py b/tools/tubeemu/build.py index e69de29b..ca7130f3 100644 --- a/tools/tubeemu/build.py +++ b/tools/tubeemu/build.py @@ -0,0 +1,9 @@ +from build.c import cprogram + +cprogram( + name="bbctube", + srcs=["./bbctube.c"], + deps=[ + "third_party/lib6502" + ] +) From 411da4823bb4aa9135c7a14dc2b0791285759190 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:40 +0000 Subject: [PATCH 05/40] Actually start building some programs. --- Makefile | 8 +-- build.py | 11 +++- build/ab2.py | 9 +-- build/c.py | 120 ++++++++++++++++++++++-------------- third_party/apout/build.py | 30 +++++++++ third_party/djlink/build.py | 51 +++++++++++++++ tools/build.py | 11 ++++ tools/obpemu/build.py | 12 ++++ 8 files changed, 195 insertions(+), 57 deletions(-) create mode 100644 third_party/apout/build.py create mode 100644 third_party/djlink/build.py create mode 100644 tools/build.py create mode 100644 tools/obpemu/build.py diff --git a/Makefile b/Makefile index 2bf97b45..d3f703bc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ export LDFLAGS = -g export NINJAFLAGS = all: $(OBJ)/build.mk - @make -f $(OBJ)/build.mk +all + @+make -f $(OBJ)/build.mk +all clean: @echo CLEAN @@ -15,8 +15,4 @@ build-files = $(shell find . -name 'build.py') build/*.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) - @python3 \ - build/ab2.py \ - -m make \ - build.py \ - > $@ + @python3 build/ab2.py -m make build.py > $@ diff --git a/build.py b/build.py index 96713e25..fcfecc63 100644 --- a/build.py +++ b/build.py @@ -4,5 +4,12 @@ installable( name="all", items={ - "bbctube": "tools/tubeemu+bbctube", - }) + "bin/bbctube": "tools/tubeemu+bbctube", + "bin/obpemu": "tools/obpemu", + "bin/mkadfs": "tools+mkadfs", + "bin/mkdfs": "tools+mkdfs", + "bin/apout": "third_party/apout", + }, + deps=[ + "third_party/djlink+djlink-programs" + ]) diff --git a/build/ab2.py b/build/ab2.py index 88f6e410..71453a44 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -402,7 +402,7 @@ def simplerule( self.ins = ins self.outs = outs emitter.rule(self.name, filenamesof(ins, deps), outs) - emitter.exec(templateexpand("echo {label} {ins}", self)) + emitter.exec(templateexpand("echo {label} {name}", self)) for out in filenamesof(outs): dir = dirname(out) @@ -438,10 +438,11 @@ def normalrule( def installable( self, name=None, - items: TargetsMap() = {}): + items: TargetsMap() = {}, + deps: Targets() = []): emitter.rule(self.name, filenamesof( - items.values()), filenamesof(items.keys())) + items.values(), deps), filenamesof(items.keys())) emitter.exec(f"echo EXPORT {self.name}") self.ins = items.values() @@ -458,7 +459,7 @@ def installable( "a dependency of an installable must have exactly one output file") emitter.exec("cp %s %s" % (srcs[0], destf)) - self.outs += destf + self.outs += [destf] def loadbuildfile(filename): diff --git a/build/c.py b/build/c.py index c5f87c4b..a624cc98 100644 --- a/build/c.py +++ b/build/c.py @@ -1,17 +1,8 @@ -from build.ab2 import Rule, Targets, normalrule, filenamesof, stripext, debug, flatten +from build.ab2 import Rule, Targets, normalrule, filenamesof, filenameof, stripext, debug, flatten from os.path import * -@Rule -def cfile(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - suffix=".o", - commands=[ - "$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}" - ], - label="CC"): +def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): if not name: name = filenamesof(srcs)[1] @@ -21,18 +12,59 @@ def cfile(self, outleaf = stripext(basename(name)) + suffix return normalrule( - name=name + "/cfile", + name=name + "/" + kind, ins=srcs, deps=deps, outleaves=[outleaf], label=label, commands=commands, - vars={ - "+cflags": flatten(headers) - } - ) + vars={ + "+"+flags: flatten(headers) + } + ) + + +@Rule +def cfile(self, + name, + srcs: Targets() = [], + deps: Targets() = [], + suffix=".o", + commands=[ + "$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}" + ], + label="CC"): + return cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", "cflags") +@Rule +def cxxfile(self, + name, + srcs: Targets() = [], + deps: Targets() = [], + suffix=".o", + commands=[ + "$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}" + ], + label="CXX"): + return cfileimpl(self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags") + + +def findsources(name, srcs, deps): + ins = [] + for i in srcs: + f = filenameof(i) + if f.endswith(".c") or f.endswith(".cc"): + ins += [ + cfile( + name=name+"/"+basename(filenamesof(f)[0]), + srcs=[f], + deps=deps + ) + ] + return ins + + @Rule def clibrary(self, name, @@ -44,18 +76,9 @@ def clibrary(self, ], label="AR"): - ins = [ - cfile( - name=name+"/"+basename(filenamesof(f)[0]), - srcs=[f], - deps=deps - ) - for f in srcs - ] - r = normalrule( name=name+"/clibrary", - ins=ins, + ins=findsources(name, srcs, deps), outleaves=[basename(name) + ".a"], label=label, commands=commands) @@ -66,32 +89,39 @@ def clibrary(self, self.clibrary.hdrs = hdrs +def programimpl(self, name, srcs, deps, commands, label, filerule, kind): + libraries = [d.outs for d in deps if d.clibrary] + + return normalrule( + name=name+"/"+kind, + ins=findsources(name, srcs, deps), + outleaves=[basename(name)], + label=label, + commands=commands, + vars={ + "+ldflags": libraries + }) + + @Rule def cprogram(self, name, srcs: Targets() = [], deps: Targets() = [], commands=[ - "$(CC) -o {outs[0]} {ins} {vars.libraries}" + "$(CC) -o {outs[0]} {ins} {vars.ldflags}" ], label="CLINK"): - libraries = [d.outs for d in deps if d.clibrary] + return programimpl(self, name, srcs, deps, commands, label, cfile, "cprogram") - ins = [ - cfile( - name=name+"/"+basename(filenamesof(f)[0]), - srcs=[f], - deps=deps, - ) - for f in srcs - ] - return normalrule( - name=name+"/cprogram", - ins=ins, - outleaves=[basename(name)], - label=label, - commands=commands, - vars={ - "+libraries": libraries - }) +@Rule +def cxxprogram(self, + name, + srcs: Targets() = [], + deps: Targets() = [], + commands=[ + "$(CXX) -o {outs[0]} {ins} {vars.ldflags}" + ], + label="CXXLINK"): + return programimpl(self, name, srcs, deps, commands, label, cxxfile, "cxxprogram") diff --git a/third_party/apout/build.py b/third_party/apout/build.py new file mode 100644 index 00000000..a9249623 --- /dev/null +++ b/third_party/apout/build.py @@ -0,0 +1,30 @@ +from build.c import cprogram + +cprogram( + name="apout", + srcs=[ + "./aout.c", + "./branch.c", + "./bsd_ioctl.c", + "./bsd_signal.c", + "./bsdtrap.c", + "./cpu.c", + "./debug.c", + "./double.c", + "./ea.c", + "./fp.c", + "./itab.c", + "./ke11a.c", + "./magic.c", + "./main.c", + "./single.c", + "./v1trap.c", + "./v7trap.c", + ], + vars={ + "+ldflags": ["-lm"], + "+cflags": [ + "-DEMUV1", + "-DNATIVES", "-DRUN_V1_RAW", "-DDEBUG", "-DZERO_MEMORY", "-DWRITEBASE", "-DHEX", + ]} +) diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py new file mode 100644 index 00000000..72e50585 --- /dev/null +++ b/third_party/djlink/build.py @@ -0,0 +1,51 @@ +from build.c import cxxprogram +from build.ab2 import installable + +cxxprogram( + name="objdump", + srcs=["./objdump.cc"], +) + +cxxprogram( + name="bindiff", + srcs=["./bindiff.cc"], +) + +cxxprogram( + name="djlink", + srcs=[ + "./djlink.cc", + "./fixups.cc", + "./libs.cc", + "./list.cc", + "./map.cc", + "./objs.cc", + "./out.cc", + "./quark.cc", + "./segments.cc", + "./stricmp.cc", + "./symbols.cc", + "./fixups.h", + "./libs.h", + "./link.h", + "./list.h", + "./map.h", + "./objs.h", + "./omf.h", + "./out.h", + "./quark.h", + "./segments.h", + "./stricmp.h", + "./symbols.h", + "./vars.h", + ], +) + +installable( + name="djlink-programs", + items={ + "bin/objdump": "+objdump", + "bin/bindiff": "+bindiff", + "bin/djlink": "+djlink", + } +) diff --git a/tools/build.py b/tools/build.py new file mode 100644 index 00000000..0ff9dc39 --- /dev/null +++ b/tools/build.py @@ -0,0 +1,11 @@ +from build.c import cprogram + +cprogram( + name="mkadfs", + srcs=["./mkadfs.c"], +) + +cprogram( + name="mkdfs", + srcs=["./mkdfs.c"], +) diff --git a/tools/obpemu/build.py b/tools/obpemu/build.py new file mode 100644 index 00000000..11581875 --- /dev/null +++ b/tools/obpemu/build.py @@ -0,0 +1,12 @@ +from build.c import cprogram + +cprogram( + name="obpemu", + srcs=[ + "./emulator.c", + "./main.c" + ], + vars={ + "+ldflags": "-lreadline" + } +) From 9fce893af2003d7f1bb938402ff178ad9597ba96 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:40 +0000 Subject: [PATCH 06/40] Build more things. --- Makefile | 2 +- build.py | 2 ++ build/ab2.py | 16 +++++++++++----- build/c.py | 16 +++++++++------- build/yacc.py | 15 +++++++++++++++ third_party/emu2/build.py | 22 ++++++++++++++++++++++ third_party/lemon/build.py | 12 ++++++++++++ third_party/zmac/build.py | 20 ++++++++++++++++++++ tools/cpmemu/build.py | 14 ++++++++++++++ 9 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 build/yacc.py create mode 100644 third_party/emu2/build.py create mode 100644 third_party/lemon/build.py create mode 100644 third_party/zmac/build.py create mode 100644 tools/cpmemu/build.py diff --git a/Makefile b/Makefile index d3f703bc..503e001e 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ build-files = $(shell find . -name 'build.py') build/*.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) - @python3 build/ab2.py -m make build.py > $@ + @python3 -B build/ab2.py -m make build.py > $@ diff --git a/build.py b/build.py index fcfecc63..0a5682eb 100644 --- a/build.py +++ b/build.py @@ -9,6 +9,8 @@ "bin/mkadfs": "tools+mkadfs", "bin/mkdfs": "tools+mkdfs", "bin/apout": "third_party/apout", + "bin/emu2": "third_party/emu2", + "bin/zmac": "third_party/zmac", }, deps=[ "third_party/djlink+djlink-programs" diff --git a/build/ab2.py b/build/ab2.py index 71453a44..bea217cd 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -226,6 +226,14 @@ def massagefilename(s): name = cwd + "+" + name +def fileinvocation(s): + i = Invocation() + i.name = "(anonymous)" + i.outs = [s] + targets[s] = i + return i + + def targetof(s, cwd): if isinstance(s, Invocation): s.materialise() @@ -240,16 +248,14 @@ def targetof(s, cwd): s = cwd + s if s.startswith("./"): s = join(cwd, s) + if s.startswith("$"): + return fileinvocation(s) if "+" not in s: if isdir(s): s = s + "+" + basename(s) else: - i = Invocation() - i.name = "(anonymous)" - i.outs = [s] - targets[s] = i - return i + return fileinvocation(s) (path, target) = s.split("+", 2) loadbuildfile(join(path, "build.py")) diff --git a/build/c.py b/build/c.py index a624cc98..5656b9ed 100644 --- a/build/c.py +++ b/build/c.py @@ -6,8 +6,8 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): if not name: name = filenamesof(srcs)[1] - headers = [filenamesof(d.clibrary.hdrs) for d in deps if d.clibrary] - headers = set(["-I"+dirname(f) for f in flatten(headers)]) + dirs = [d.clibrary.dirs for d in deps if hasattr(d, "clibrary")] + dirs = set(["-I"+f for f in filenamesof(dirs)]) outleaf = stripext(basename(name)) + suffix @@ -19,7 +19,7 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): label=label, commands=commands, vars={ - "+"+flags: flatten(headers) + "+"+flags: flatten(dirs) } ) @@ -52,9 +52,8 @@ def cxxfile(self, def findsources(name, srcs, deps): ins = [] - for i in srcs: - f = filenameof(i) - if f.endswith(".c") or f.endswith(".cc"): + for f in filenamesof(srcs): + if f.endswith(".c") or f.endswith(".cc") or f.endswith(".cpp"): ins += [ cfile( name=name+"/"+basename(filenamesof(f)[0]), @@ -64,7 +63,7 @@ def findsources(name, srcs, deps): ] return ins - + @Rule def clibrary(self, name, @@ -84,9 +83,12 @@ def clibrary(self, commands=commands) r.materialise() + dirs = set([dirname(f) for f in filenamesof(hdrs)]) + self.ins = [r] self.outs = r.outs self.clibrary.hdrs = hdrs + self.clibrary.dirs = dirs def programimpl(self, name, srcs, deps, commands, label, filerule, kind): diff --git a/build/yacc.py b/build/yacc.py new file mode 100644 index 00000000..398b1231 --- /dev/null +++ b/build/yacc.py @@ -0,0 +1,15 @@ +from build.ab2 import normalrule, Rule, Targets + + +@Rule +def yacc(self, + name, + srcs: Targets() = []): + return normalrule( + name=name+"/yacc", + ins=srcs, + outleaves=["y.tab.c", "y.tab.h"], + commands=[ + "bison -y -t -o {outs[0]} --defines={outs[1]} {ins}" + ] + ) diff --git a/third_party/emu2/build.py b/third_party/emu2/build.py new file mode 100644 index 00000000..11fbff7c --- /dev/null +++ b/third_party/emu2/build.py @@ -0,0 +1,22 @@ +from build.c import cprogram + +cprogram( + name="emu2", + srcs=[ + "./src/cpu.c", + "./src/loader.c", + "./src/main.c", + "./src/codepage.c", + "./src/dosnames.c", + "./src/dis.c", + "./src/dos.c", + "./src/keyb.c", + "./src/dbg.c", + "./src/timer.c", + "./src/utils.c", + "./src/video.c", + ], + vars={ + "+ldflags": ["-lm"] + } +) diff --git a/third_party/lemon/build.py b/third_party/lemon/build.py new file mode 100644 index 00000000..46604695 --- /dev/null +++ b/third_party/lemon/build.py @@ -0,0 +1,12 @@ +from build.ab2 import Rule +from build.c import cprogram + +cprogram( + name="lemon", + srcs=["./lemon.c"], +) + +cprogram( + name="lemon-cowgol", + srcs=["./lemon-cowgol.c"], +) diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py new file mode 100644 index 00000000..679ce051 --- /dev/null +++ b/third_party/zmac/build.py @@ -0,0 +1,20 @@ +from build.yacc import yacc +from build.c import cprogram + +yacc( + name="parser", + srcs=["third_party/zmac/zmac.y"], +) + +cprogram( + name="zmac", + srcs=[ + "+parser", + "./mio.c", + "./zi80dis.cpp", + "./zi80dis.h" + ], + vars={ + "+cflags": ["-Ithird_party/zmac"], + } +) diff --git a/tools/cpmemu/build.py b/tools/cpmemu/build.py new file mode 100644 index 00000000..f479529f --- /dev/null +++ b/tools/cpmemu/build.py @@ -0,0 +1,14 @@ +from build.c import cprogram + +cprogram( + name="cpmemu" + srcs=[ + "./main.c", + "./emulator.c", + "./fileio.c", + "./biosbdos.c", + ], + vars={ + "+ldflags": ["-lz80ex", "-lz80ex_dasm", "-lreadline"] + } +) From f33b2697cde0d31950a51a9b4b0f575089a7e044 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:40 +0000 Subject: [PATCH 07/40] Build even more things. Better proxies, don't write to stdout. --- Makefile | 2 +- build.py | 8 +- build/ab2.py | 107 ++++++++++++++------------ build/c.py | 142 ++++++++++++++++++++--------------- build/yacc.py | 11 +-- third_party/apout/build.py | 10 ++- third_party/djlink/build.py | 2 +- third_party/emu2/build.py | 4 +- third_party/musashi/build.py | 30 ++++++++ third_party/zmac/build.py | 25 ++++-- tools/ataritosemu/build.py | 18 +++++ tools/build.py | 12 +++ tools/cpmemu/build.py | 13 +++- tools/lx68kemu/build.py | 17 +++++ tools/obpemu/build.py | 9 +-- tools/tubeemu/build.py | 8 +- 16 files changed, 266 insertions(+), 152 deletions(-) create mode 100644 third_party/musashi/build.py create mode 100644 tools/ataritosemu/build.py create mode 100644 tools/lx68kemu/build.py diff --git a/Makefile b/Makefile index 503e001e..9ff89745 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ build-files = $(shell find . -name 'build.py') build/*.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) - @python3 -B build/ab2.py -m make build.py > $@ + @python3 -B build/ab2.py -m make -o $@ build.py diff --git a/build.py b/build.py index 0a5682eb..0a78e3c8 100644 --- a/build.py +++ b/build.py @@ -11,7 +11,9 @@ "bin/apout": "third_party/apout", "bin/emu2": "third_party/emu2", "bin/zmac": "third_party/zmac", + "bin/cpmemu": "tools/cpmemu", + "bin/ataritosemu": "tools/ataritosemu", + "bin/lx68kemu": "tools/lx68kemu", }, - deps=[ - "third_party/djlink+djlink-programs" - ]) + deps=["third_party/djlink+djlink-programs"], +) diff --git a/build/ab2.py b/build/ab2.py index bea217cd..40b082c3 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -18,6 +18,7 @@ targets = {} currentInvocation = None unmaterialisedTargets = set() +outputFp = None emitter = None currentVars = None @@ -27,13 +28,12 @@ def new_import(name, *args, **kwargs): if name not in sys.modules: - path = name.replace(".", "/")+".py" + path = name.replace(".", "/") + ".py" if isfile(path): sys.stderr.write(f"loading {path}\n") loader = importlib.machinery.SourceFileLoader(name, path) - spec = importlib.util.spec_from_loader( - name, loader, origin="built-in") + spec = importlib.util.spec_from_loader(name, loader, origin="built-in") module = importlib.util.module_from_spec(spec) sys.modules[name] = module spec.loader.exec_module(module) @@ -143,14 +143,17 @@ def materialise(self): if proxy: if self.ins or self.outs: raise ABException( - f"{self.name} is a proxy, but sets self.ins or self.outs") + f"{self.name} is a proxy, but sets self.ins or self.outs" + ) proxy.materialise() - self.ins = [proxy] - self.outs = proxy.outs + for k in dir(proxy): + if not k.startswith("_"): + setattr(self, k, getattr(proxy, k)) else: if not self.outs: raise ABException( - f"{self.name} is not a proxy, but didn't set self.outs") + f"{self.name} is not a proxy, but didn't set self.outs" + ) # Destack the variable and invocation frame. @@ -169,7 +172,7 @@ class Type: class String(Type): def convert(self, value, invocation): if type(value) != "string": - raise ABException("rule wanted a String, but got a "+type(value)) + raise ABException("rule wanted a String, but got a " + type(value)) return value @@ -189,18 +192,21 @@ def convert(self, value, invocation): return value +class Target(Type): + def convert(self, value, invocation): + return targetof(value, cwd=invocation.cwd) + + class TargetsMap(Type): def convert(self, value, invocation): if type(value) is dict: return { - targetof(k, cwd=invocation.cwd): targetof(v, cwd=invocation.cwd) for k, v in value.items()} + targetof(k, cwd=invocation.cwd): targetof(v, cwd=invocation.cwd) + for k, v in value.items() + } raise ABException(f"wanted a dict of targets, got a {type(value)}") -def debug(*s): - print(*s, file=sys.stderr) - - def flatten(*xs): def recurse(xs): for x in xs: @@ -260,8 +266,7 @@ def targetof(s, cwd): (path, target) = s.split("+", 2) loadbuildfile(join(path, "build.py")) if not s in targets: - raise ABException( - f"build file at {path} doesn't contain +{target}") + raise ABException(f"build file at {path} doesn't contain +{target}") i = targets[s] i.materialise() return i @@ -293,7 +298,8 @@ def stripext(path): def emit(*args): - print(*flatten(args)) + outputFp.write(" ".join(flatten(args))) + outputFp.write("\n") def unmake(ss): @@ -322,7 +328,7 @@ def end(self): def var(self, name, value): # Don't let emit insert spaces. - emit(name+"="+unmake(value)) + emit(name + "=" + unmake(value)) def rule(self, name, ins, outs): if outs: @@ -344,7 +350,7 @@ def begin(self): def var(self, name, value): # Don't let emit insert spaces. - emit(name+"="+unmake(value)) + emit(name + "=" + unmake(value)) def rule(self, name, ins, outs): if outs: @@ -372,6 +378,7 @@ def wrapper(*, name, **kwargs): name = cwd + "+" + name i.name = name + i.localname = name.split("+")[-1] i.cwd = cwd i.types = func.__annotations__ i.callback = func @@ -398,13 +405,14 @@ def wrapper(*, name, **kwargs): @Rule def simplerule( - self, - name, - ins: Targets() = [], - outs=[], - deps: Targets() = [], - commands: Strings() = [], - label="RULE"): + self, + name, + ins: Targets() = [], + outs=[], + deps: Targets() = [], + commands: Strings() = [], + label="RULE", +): self.ins = ins self.outs = outs emitter.rule(self.name, filenamesof(ins, deps), outs) @@ -413,7 +421,7 @@ def simplerule( for out in filenamesof(outs): dir = dirname(out) if dir: - emitter.exec("mkdir -p "+dir) + emitter.exec("mkdir -p " + dir) for c in commands: emitter.exec(templateexpand(c, self)) @@ -421,34 +429,32 @@ def simplerule( @Rule def normalrule( - self, - name=None, - ins: Targets() = [], - deps: Targets() = [], - outleaves=[], - label="RULE", - objdir=None, - commands=[]): + self, + name=None, + ins: Targets() = [], + deps: Targets() = [], + outleaves=[], + label="RULE", + objdir=None, + commands=[], +): objdir = objdir or join("$(OBJ)", name) return simplerule( - name=name+"/simplerule", + name=name + "/simplerule", ins=ins, deps=deps, outs=[join(objdir, f) for f in outleaves], label=label, - commands=commands) + commands=commands, + ) @Rule -def installable( - self, - name=None, - items: TargetsMap() = {}, - deps: Targets() = []): - - emitter.rule(self.name, filenamesof( - items.values(), deps), filenamesof(items.keys())) +def installable(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): + emitter.rule( + self.name, filenamesof(items.values(), deps), filenamesof(items.keys()) + ) emitter.exec(f"echo EXPORT {self.name}") self.ins = items.values() @@ -457,12 +463,13 @@ def installable( destf = filenameof(dest) dir = dirname(destf) if dir: - emitter.exec("mkdir -p "+dir) + emitter.exec("mkdir -p " + dir) srcs = filenamesof(src) if len(srcs) != 1: raise ABException( - "a dependency of an installable must have exactly one output file") + "a dependency of an installable must have exactly one output file" + ) emitter.exec("cp %s %s" % (srcs[0], destf)) self.outs += [destf] @@ -482,11 +489,14 @@ def load(filename): def main(): parser = argparse.ArgumentParser() - parser.add_argument( - "-m", "--mode", choices=["make", "ninja"], default="make") + parser.add_argument("-m", "--mode", choices=["make", "ninja"], default="make") + parser.add_argument("-o", "--output") parser.add_argument("files", nargs="+") args = parser.parse_args() + global outputFp + outputFp = open(args.output, "wt") + global emitter if args.mode == "make": emitter = MakeEmitter() @@ -499,7 +509,6 @@ def main(): for k in ("Rule", "Targets", "load", "filenamesof", "stripext"): defaultGlobals[k] = globals()[k] - defaultGlobals["print"] = debug global __name__ sys.modules["build.ab2"] = sys.modules[__name__] diff --git a/build/c.py b/build/c.py index 5656b9ed..957a49e5 100644 --- a/build/c.py +++ b/build/c.py @@ -1,4 +1,12 @@ -from build.ab2 import Rule, Targets, normalrule, filenamesof, filenameof, stripext, debug, flatten +from build.ab2 import ( + Rule, + Targets, + normalrule, + filenamesof, + filenameof, + stripext, + flatten, +) from os.path import * @@ -6,8 +14,17 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): if not name: name = filenamesof(srcs)[1] - dirs = [d.clibrary.dirs for d in deps if hasattr(d, "clibrary")] - dirs = set(["-I"+f for f in filenamesof(dirs)]) + dirs = [] + for d in deps: + for f in filenamesof(d): + if f.endswith(".h"): + dirs += [dirname(f)] + try: + dirs += d.clibrary.dirs + except: + pass + + includeflags = set(["-I" + f for f in filenamesof(dirs)]) outleaf = stripext(basename(name)) + suffix @@ -18,36 +35,36 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): outleaves=[outleaf], label=label, commands=commands, - vars={ - "+"+flags: flatten(dirs) - } + vars={"+" + flags: flatten(includeflags)}, ) @Rule -def cfile(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - suffix=".o", - commands=[ - "$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}" - ], - label="CC"): +def cfile( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + suffix=".o", + commands=["$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}"], + label="CC", +): return cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", "cflags") @Rule -def cxxfile(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - suffix=".o", - commands=[ - "$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}" - ], - label="CXX"): - return cfileimpl(self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags") +def cxxfile( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + suffix=".o", + commands=["$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}"], + label="CXX", +): + return cfileimpl( + self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags" + ) def findsources(name, srcs, deps): @@ -56,31 +73,33 @@ def findsources(name, srcs, deps): if f.endswith(".c") or f.endswith(".cc") or f.endswith(".cpp"): ins += [ cfile( - name=name+"/"+basename(filenamesof(f)[0]), - srcs=[f], - deps=deps + name=name + "/" + basename(filenamesof(f)[0]), srcs=[f], deps=deps ) ] return ins @Rule -def clibrary(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - hdrs: Targets() = [], - commands=[ - "$(AR) cqs {outs[0]} {ins}" - ], - label="AR"): +def clibrary( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + hdrs: Targets() = [], + commands=["$(AR) cqs {outs[0]} {ins}"], + label="AR", +): + for f in filenamesof(srcs): + if f.endswith(".h"): + deps += [f] r = normalrule( - name=name+"/clibrary", + name=name + "/clibrary", ins=findsources(name, srcs, deps), outleaves=[basename(name) + ".a"], label=label, - commands=commands) + commands=commands, + ) r.materialise() dirs = set([dirname(f) for f in filenamesof(hdrs)]) @@ -92,38 +111,41 @@ def clibrary(self, def programimpl(self, name, srcs, deps, commands, label, filerule, kind): - libraries = [d.outs for d in deps if d.clibrary] + libraries = [d.outs for d in deps if hasattr(d, "clibrary")] + + for f in filenamesof(srcs): + if f.endswith(".h"): + deps += [f] return normalrule( - name=name+"/"+kind, + name=name + "/" + kind, ins=findsources(name, srcs, deps), outleaves=[basename(name)], label=label, commands=commands, - vars={ - "+ldflags": libraries - }) + vars={"+ldflags": libraries}, + ) @Rule -def cprogram(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - commands=[ - "$(CC) -o {outs[0]} {ins} {vars.ldflags}" - ], - label="CLINK"): +def cprogram( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + commands=["$(CC) -o {outs[0]} {ins} {vars.ldflags}"], + label="CLINK", +): return programimpl(self, name, srcs, deps, commands, label, cfile, "cprogram") @Rule -def cxxprogram(self, - name, - srcs: Targets() = [], - deps: Targets() = [], - commands=[ - "$(CXX) -o {outs[0]} {ins} {vars.ldflags}" - ], - label="CXXLINK"): +def cxxprogram( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + commands=["$(CXX) -o {outs[0]} {ins} {vars.ldflags}"], + label="CXXLINK", +): return programimpl(self, name, srcs, deps, commands, label, cxxfile, "cxxprogram") diff --git a/build/yacc.py b/build/yacc.py index 398b1231..12840473 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -2,14 +2,11 @@ @Rule -def yacc(self, - name, - srcs: Targets() = []): +def yacc(self, name, srcs: Targets() = []): return normalrule( - name=name+"/yacc", + name=name + "/yacc", ins=srcs, outleaves=["y.tab.c", "y.tab.h"], - commands=[ - "bison -y -t -o {outs[0]} --defines={outs[1]} {ins}" - ] + commands=["bison -y -t -o {outs[0]} --defines={outs[1]} {ins}"], + label="YACC", ) diff --git a/third_party/apout/build.py b/third_party/apout/build.py index a9249623..a94b3480 100644 --- a/third_party/apout/build.py +++ b/third_party/apout/build.py @@ -25,6 +25,12 @@ "+ldflags": ["-lm"], "+cflags": [ "-DEMUV1", - "-DNATIVES", "-DRUN_V1_RAW", "-DDEBUG", "-DZERO_MEMORY", "-DWRITEBASE", "-DHEX", - ]} + "-DNATIVES", + "-DRUN_V1_RAW", + "-DDEBUG", + "-DZERO_MEMORY", + "-DWRITEBASE", + "-DHEX", + ], + }, ) diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py index 72e50585..95885909 100644 --- a/third_party/djlink/build.py +++ b/third_party/djlink/build.py @@ -47,5 +47,5 @@ "bin/objdump": "+objdump", "bin/bindiff": "+bindiff", "bin/djlink": "+djlink", - } + }, ) diff --git a/third_party/emu2/build.py b/third_party/emu2/build.py index 11fbff7c..b731d236 100644 --- a/third_party/emu2/build.py +++ b/third_party/emu2/build.py @@ -16,7 +16,5 @@ "./src/utils.c", "./src/video.c", ], - vars={ - "+ldflags": ["-lm"] - } + vars={"+ldflags": ["-lm"]}, ) diff --git a/third_party/musashi/build.py b/third_party/musashi/build.py new file mode 100644 index 00000000..3ab430a1 --- /dev/null +++ b/third_party/musashi/build.py @@ -0,0 +1,30 @@ +from build.ab2 import Rule, Target, normalrule +from build.c import clibrary, cprogram + +cprogram(name="m68kmake", srcs=["./m68kmake.c"]) + +normalrule( + name="m68kops", + ins=["+m68kmake", "./m68k_in.c"], + outleaves=["m68kops.c", "m68kops.h"], + commands=["{ins[0]} {dirname(outs[0])} {ins[1]} > /dev/null"], + label="MUSASHILIB", +) + + +@Rule +def musashilib(self, name, m68kconf: Target() = None): + return clibrary( + name=name + "/musashilib", + srcs=[ + m68kconf, + "third_party/musashi/m68kcpu.c", + "third_party/musashi/m68kcpu.h", + "third_party/musashi/m68kdasm.c", + "third_party/musashi/m68k.h", + "third_party/musashi/m68kmmu.h", + "third_party/musashi/softfloat/softfloat.c", + "third_party/musashi/softfloat/softfloat.h", + "third_party/musashi+m68kops", + ], + ) diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py index 679ce051..308f6f2e 100644 --- a/third_party/zmac/build.py +++ b/third_party/zmac/build.py @@ -1,5 +1,7 @@ from build.yacc import yacc from build.c import cprogram +from build.ab2 import Rule, Targets, normalrule, filenameof +from os.path import * yacc( name="parser", @@ -8,13 +10,22 @@ cprogram( name="zmac", - srcs=[ - "+parser", - "./mio.c", - "./zi80dis.cpp", - "./zi80dis.h" - ], + srcs=["+parser", "./mio.c", "./zi80dis.cpp", "./zi80dis.h"], vars={ "+cflags": ["-Ithird_party/zmac"], - } + }, ) + + +@Rule +def zmac(self, name, srcs: Targets() = []): + filename, ext = splitext(filenameof(srcs)) + archflag = "-z" if (ext == "z80") else "-8" + + return normalrule( + name=name + "/zmac", + ins=["third_party/zmac", srcs[0]], + outleaves=[self.localname + ".cim", self.localname + ".lst"], + commands=["{ins[0]} -j -m " + archflag + " -o {outs[0]} -o {outs[1]} {ins[1]}"], + label="ZMAC", + ) diff --git a/tools/ataritosemu/build.py b/tools/ataritosemu/build.py new file mode 100644 index 00000000..78c29574 --- /dev/null +++ b/tools/ataritosemu/build.py @@ -0,0 +1,18 @@ +from build.c import cprogram +from third_party.musashi.build import musashilib + +musashilib( + name="musashi", + m68kconf="tools/ataritosemu/m68kconf.h", +) + +cprogram( + name="ataritosemu", + srcs=[ + "./gemdos.c", + "./sim.c", + "./sim.h", + "third_party/musashi/m68k.h", + ], + deps=["+musashi"], +) diff --git a/tools/build.py b/tools/build.py index 0ff9dc39..deeddfde 100644 --- a/tools/build.py +++ b/tools/build.py @@ -1,4 +1,5 @@ from build.c import cprogram +from build.ab2 import Rule, Target, normalrule cprogram( name="mkadfs", @@ -9,3 +10,14 @@ name="mkdfs", srcs=["./mkdfs.c"], ) + + +@Rule +def objectify(self, name, src: Target() = None, symbol=None): + return normalrule( + name=name + "/objectify", + ins=["tools/objectify", src], + outleaves=[symbol + ".c"], + commands=["lua {ins[0]} " + symbol + " < {ins[1]} > {outs}"], + label="OBJECTIFY", + ) diff --git a/tools/cpmemu/build.py b/tools/cpmemu/build.py index f479529f..0fcb8888 100644 --- a/tools/cpmemu/build.py +++ b/tools/cpmemu/build.py @@ -1,14 +1,19 @@ from build.c import cprogram +from third_party.zmac.build import zmac +from tools.build import objectify + +zmac(name="biosbdos", srcs=["./biosbdos.z80"]) + +objectify(name="biosbdosdata", src="+biosbdos", symbol="biosbdosdata") cprogram( - name="cpmemu" + name="cpmemu", srcs=[ "./main.c", "./emulator.c", "./fileio.c", "./biosbdos.c", + "+biosbdosdata", ], - vars={ - "+ldflags": ["-lz80ex", "-lz80ex_dasm", "-lreadline"] - } + vars={"+ldflags": ["-lz80ex", "-lz80ex_dasm", "-lreadline"]}, ) diff --git a/tools/lx68kemu/build.py b/tools/lx68kemu/build.py new file mode 100644 index 00000000..85db496d --- /dev/null +++ b/tools/lx68kemu/build.py @@ -0,0 +1,17 @@ +from build.c import cprogram +from third_party.musashi.build import musashilib + +musashilib( + name="musashi", + m68kconf="tools/lx68kemu/m68kconf.h", +) + +cprogram( + name="lx68kemu", + srcs=[ + "./sim.c", + "./sim.h", + "third_party/musashi/m68k.h", + ], + deps=["+musashi"], +) diff --git a/tools/obpemu/build.py b/tools/obpemu/build.py index 11581875..c9975306 100644 --- a/tools/obpemu/build.py +++ b/tools/obpemu/build.py @@ -1,12 +1,5 @@ from build.c import cprogram cprogram( - name="obpemu", - srcs=[ - "./emulator.c", - "./main.c" - ], - vars={ - "+ldflags": "-lreadline" - } + name="obpemu", srcs=["./emulator.c", "./main.c"], vars={"+ldflags": "-lreadline"} ) diff --git a/tools/tubeemu/build.py b/tools/tubeemu/build.py index ca7130f3..c81391ae 100644 --- a/tools/tubeemu/build.py +++ b/tools/tubeemu/build.py @@ -1,9 +1,3 @@ from build.c import cprogram -cprogram( - name="bbctube", - srcs=["./bbctube.c"], - deps=[ - "third_party/lib6502" - ] -) +cprogram(name="bbctube", srcs=["./bbctube.c"], deps=["third_party/lib6502"]) From d4b88df4a731f53a4aa15e24bffa1fd8771f0b0f Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:40 +0000 Subject: [PATCH 08/40] Replace proxies with replacement. --- build/ab2.py | 81 ++++++++++++++++-------------------- build/c.py | 23 +++++----- build/yacc.py | 4 +- third_party/musashi/build.py | 4 +- third_party/zmac/build.py | 4 +- tools/build.py | 4 +- 6 files changed, 53 insertions(+), 67 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index 40b082c3..2a1717f1 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -16,7 +16,6 @@ defaultGlobals = {} targets = {} -currentInvocation = None unmaterialisedTargets = set() outputFp = None emitter = None @@ -104,12 +103,6 @@ class Invocation: def materialise(self): if self in unmaterialisedTargets: - # Create a new invocation frame. - - global currentInvocation - oldInvocation = currentInvocation - currentInvocation = self - # Perform type conversion to the declared rule parameter types. self.args = {} @@ -134,32 +127,19 @@ def materialise(self): else: self.vars[k] = ParameterList(v) - # Actually call the callback. If it returns another invocation, - # then replace the current one with it. - - proxy = self.callback(**self.args) - currentInvocation = oldInvocation - - if proxy: - if self.ins or self.outs: - raise ABException( - f"{self.name} is a proxy, but sets self.ins or self.outs" - ) - proxy.materialise() - for k in dir(proxy): - if not k.startswith("_"): - setattr(self, k, getattr(proxy, k)) - else: - if not self.outs: - raise ABException( - f"{self.name} is not a proxy, but didn't set self.outs" - ) + # Actually call the callback. + + self.callback(**self.args) + if not self.outs: + raise ABException( + f"{self.name} didn't set self.outs" + ) # Destack the variable and invocation frame. currentVars = oldVars - unmaterialisedTargets.remove(self) - currentInvocation = oldInvocation + if self in unmaterialisedTargets: + unmaterialisedTargets.remove(self) def __repr__(self): return "" % self.name @@ -364,21 +344,32 @@ def Rule(func): sig = inspect.signature(func) @functools.wraps(func) - def wrapper(*, name, **kwargs): + def wrapper(*, name=None, replaces=None, **kwargs): callername = inspect.stack()[1][0].f_globals["__name__"] cwd = dirname(callername.replace(".", "/")) - if ("+" in name) and not name.startswith("+"): - (cwd, target) = name.split("+", 1) - - i = Invocation() - if name.startswith("./"): - name = join(cwd, name) - elif "+" not in name: - name = cwd + "+" + name + if name: + if ("+" in name) and not name.startswith("+"): + (cwd, target) = name.split("+", 1) + + i = Invocation() + if name.startswith("./"): + name = join(cwd, name) + elif "+" not in name: + name = cwd + "+" + name + + i.name = name + i.localname = name.split("+")[-1] + + if name in targets: + raise ABException(f"target {i.name} has already been defined") + targets[name] = i + elif replaces: + i = replaces + name = i.name + else: + raise ABException("you must supply either name or replaces") - i.name = name - i.localname = name.split("+")[-1] i.cwd = cwd i.types = func.__annotations__ i.callback = func @@ -392,11 +383,9 @@ def wrapper(*, name, **kwargs): bound.apply_defaults() i.rawArgs = bound.arguments - if name in targets: - raise ABException(f"target {i.name} has already been defined") - - targets[name] = i unmaterialisedTargets.add(i) + if replaces: + i.materialise() return i defaultGlobals[func.__name__] = wrapper @@ -440,8 +429,8 @@ def normalrule( ): objdir = objdir or join("$(OBJ)", name) - return simplerule( - name=name + "/simplerule", + simplerule( + replaces=self, ins=ins, deps=deps, outs=[join(objdir, f) for f in outleaves], diff --git a/build/c.py b/build/c.py index 957a49e5..edaec26e 100644 --- a/build/c.py +++ b/build/c.py @@ -28,8 +28,8 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): outleaf = stripext(basename(name)) + suffix - return normalrule( - name=name + "/" + kind, + normalrule( + replaces=self, ins=srcs, deps=deps, outleaves=[outleaf], @@ -49,7 +49,7 @@ def cfile( commands=["$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}"], label="CC", ): - return cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", "cflags") + cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", "cflags") @Rule @@ -62,7 +62,7 @@ def cxxfile( commands=["$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}"], label="CXX", ): - return cfileimpl( + cfileimpl( self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags" ) @@ -93,19 +93,16 @@ def clibrary( if f.endswith(".h"): deps += [f] - r = normalrule( - name=name + "/clibrary", + normalrule( + replaces=self, ins=findsources(name, srcs, deps), outleaves=[basename(name) + ".a"], label=label, commands=commands, ) - r.materialise() dirs = set([dirname(f) for f in filenamesof(hdrs)]) - self.ins = [r] - self.outs = r.outs self.clibrary.hdrs = hdrs self.clibrary.dirs = dirs @@ -117,8 +114,8 @@ def programimpl(self, name, srcs, deps, commands, label, filerule, kind): if f.endswith(".h"): deps += [f] - return normalrule( - name=name + "/" + kind, + normalrule( + replaces=self, ins=findsources(name, srcs, deps), outleaves=[basename(name)], label=label, @@ -136,7 +133,7 @@ def cprogram( commands=["$(CC) -o {outs[0]} {ins} {vars.ldflags}"], label="CLINK", ): - return programimpl(self, name, srcs, deps, commands, label, cfile, "cprogram") + programimpl(self, name, srcs, deps, commands, label, cfile, "cprogram") @Rule @@ -148,4 +145,4 @@ def cxxprogram( commands=["$(CXX) -o {outs[0]} {ins} {vars.ldflags}"], label="CXXLINK", ): - return programimpl(self, name, srcs, deps, commands, label, cxxfile, "cxxprogram") + programimpl(self, name, srcs, deps, commands, label, cxxfile, "cxxprogram") diff --git a/build/yacc.py b/build/yacc.py index 12840473..d55230bc 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -3,8 +3,8 @@ @Rule def yacc(self, name, srcs: Targets() = []): - return normalrule( - name=name + "/yacc", + normalrule( + replaces=self, ins=srcs, outleaves=["y.tab.c", "y.tab.h"], commands=["bison -y -t -o {outs[0]} --defines={outs[1]} {ins}"], diff --git a/third_party/musashi/build.py b/third_party/musashi/build.py index 3ab430a1..09694c53 100644 --- a/third_party/musashi/build.py +++ b/third_party/musashi/build.py @@ -14,8 +14,8 @@ @Rule def musashilib(self, name, m68kconf: Target() = None): - return clibrary( - name=name + "/musashilib", + clibrary( + replaces=self, srcs=[ m68kconf, "third_party/musashi/m68kcpu.c", diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py index 308f6f2e..50f13eae 100644 --- a/third_party/zmac/build.py +++ b/third_party/zmac/build.py @@ -22,8 +22,8 @@ def zmac(self, name, srcs: Targets() = []): filename, ext = splitext(filenameof(srcs)) archflag = "-z" if (ext == "z80") else "-8" - return normalrule( - name=name + "/zmac", + normalrule( + replaces=self, ins=["third_party/zmac", srcs[0]], outleaves=[self.localname + ".cim", self.localname + ".lst"], commands=["{ins[0]} -j -m " + archflag + " -o {outs[0]} -o {outs[1]} {ins[1]}"], diff --git a/tools/build.py b/tools/build.py index deeddfde..edd564db 100644 --- a/tools/build.py +++ b/tools/build.py @@ -14,8 +14,8 @@ @Rule def objectify(self, name, src: Target() = None, symbol=None): - return normalrule( - name=name + "/objectify", + normalrule( + replaces=self, ins=["tools/objectify", src], outleaves=[symbol + ".c"], commands=["lua {ins[0]} " + symbol + " < {ins[1]} > {outs}"], From f683d43a7e969d857554aeacf57546a9ba85f721 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:41 +0000 Subject: [PATCH 09/40] Build more things. --- build.py | 1 + build/ab2.py | 4 +--- build/c.py | 4 +--- third_party/rc2014emu/build.py | 3 +++ tools/fuzix6303emu/build.py | 12 ++++++++++++ 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 third_party/rc2014emu/build.py create mode 100644 tools/fuzix6303emu/build.py diff --git a/build.py b/build.py index 0a78e3c8..f13f21e6 100644 --- a/build.py +++ b/build.py @@ -14,6 +14,7 @@ "bin/cpmemu": "tools/cpmemu", "bin/ataritosemu": "tools/ataritosemu", "bin/lx68kemu": "tools/lx68kemu", + "bin/fuzix6303emu": "tools/fuzix6303emu", }, deps=["third_party/djlink+djlink-programs"], ) diff --git a/build/ab2.py b/build/ab2.py index 2a1717f1..e8f5828c 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -131,9 +131,7 @@ def materialise(self): self.callback(**self.args) if not self.outs: - raise ABException( - f"{self.name} didn't set self.outs" - ) + raise ABException(f"{self.name} didn't set self.outs") # Destack the variable and invocation frame. diff --git a/build/c.py b/build/c.py index edaec26e..066e3c90 100644 --- a/build/c.py +++ b/build/c.py @@ -62,9 +62,7 @@ def cxxfile( commands=["$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}"], label="CXX", ): - cfileimpl( - self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags" - ) + cfileimpl(self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags") def findsources(name, srcs, deps): diff --git a/third_party/rc2014emu/build.py b/third_party/rc2014emu/build.py new file mode 100644 index 00000000..e1bae79d --- /dev/null +++ b/third_party/rc2014emu/build.py @@ -0,0 +1,3 @@ +from build.c import clibrary + +clibrary(name="rc2014emu", srcs=["./6800.c"], hdrs=["./6800.h"]) diff --git a/tools/fuzix6303emu/build.py b/tools/fuzix6303emu/build.py new file mode 100644 index 00000000..ec38bc68 --- /dev/null +++ b/tools/fuzix6303emu/build.py @@ -0,0 +1,12 @@ +from build.c import cprogram + +cprogram( + name="fuzix6303emu", + srcs=[ + "./main.c", + "./disasm.c", + "./globals.h", + ], + deps=["third_party/rc2014emu"], + vars={"+ldflags": ["-lreadline"]}, +) From 7f86e0a5ff09dbeddce9c17ecbeed53866c53eb8 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:41 +0000 Subject: [PATCH 10/40] Start thinking about toolchains. --- bootstrap/build.py | 6 ++++++ build.py | 22 +++++++++++++++++++++- src/build.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 bootstrap/build.py create mode 100644 src/build.py diff --git a/bootstrap/build.py b/bootstrap/build.py new file mode 100644 index 00000000..7951ef97 --- /dev/null +++ b/bootstrap/build.py @@ -0,0 +1,6 @@ +from src.build import cgen + +cgen(name="cowfe", srcs=["./cowfe-cgen.bootstrap.c"]) +cgen(name="cowbe", srcs=["./cowbe-cgen.bootstrap.c"]) +cgen(name="cowlink", srcs=["./cowlink-cgen.bootstrap.c"]) +cgen(name="cowwrap", srcs=["./cowwrap.bootstrap.c"]) diff --git a/build.py b/build.py index f13f21e6..8c9b9279 100644 --- a/build.py +++ b/build.py @@ -1,5 +1,25 @@ from build.ab2 import Rule, installable from os.path import * +from src.build import toolchain + +toolchains = [ + toolchain( + name="ncgen", + id="ncgen", + cowfe="bootstrap+cowfe", + cowbe="bootstrap+cowbe", + cowlink="bootstrap+cowlink", + cowwrap="bootstrap+cowwrap", + ), + toolchain( + name="nncgen", + id="nncgen", + cowfe="bootstrap+cowfe", + cowbe="bootstrap+cowbe", + cowlink="bootstrap+cowlink", + cowwrap="bootstrap+cowwrap", + ), +] installable( name="all", @@ -16,5 +36,5 @@ "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", }, - deps=["third_party/djlink+djlink-programs"], + deps=["third_party/djlink+djlink-programs"] + toolchains, ) diff --git a/src/build.py b/src/build.py new file mode 100644 index 00000000..af9504cb --- /dev/null +++ b/src/build.py @@ -0,0 +1,33 @@ +from build.ab2 import Rule, Target, Targets, installable +from build.c import cprogram + + +@Rule +def cgen(self, name, srcs: Targets() = []): + cprogram(replaces=self, srcs=srcs + ["rt/cgen/cowgol.h"]) + + +@Rule +def toolchain( + self, + name, + id, + cowfe: Target() = None, + cowbe: Target() = None, + cowlink: Target() = None, + cowwrap: Target() = None, +): + self.toolchain.cowfe = cowfe + self.toolchain.cowbe = cowbe + self.toolchain.cowlink = cowlink + self.toolchain.cowwrap = cowwrap + + installable( + replaces=self, + items={ + "bin/cowfe-" + id: cowfe, + "bin/cowbe-" + id: cowbe, + "bin/cowlink-" + id: cowlink, + "bin/cowwrap-" + id: cowwrap, + }, + ) From fa0a26548c4346a90e78d1d51a21d5bf6b224083 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:41 +0000 Subject: [PATCH 11/40] Finally update to emit .coh files. --- third_party/lemon/lemon-cowgol.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/third_party/lemon/lemon-cowgol.c b/third_party/lemon/lemon-cowgol.c index 760d7031..4c2f3242 100644 --- a/third_party/lemon/lemon-cowgol.c +++ b/third_party/lemon/lemon-cowgol.c @@ -4104,7 +4104,7 @@ void ReportTable( in = tplt_open(lemp); if( in==0 ) return; - out = file_open(lemp,".c","wb"); + out = file_open(lemp,".coh","wb"); if( out==0 ){ fclose(in); return; @@ -4115,7 +4115,7 @@ void ReportTable( /* Generate the include code, if any */ tplt_print(out,lemp,lemp->include,&lineno); if( mhflag ){ - char *incName = file_makename(lemp, ".h"); + char *incName = file_makename(lemp, ".tokens.coh"); fprintf(out,"#include \"%s\"\n", incName); lineno++; free(incName); } @@ -4625,22 +4625,7 @@ void ReportHeader(struct lemon *lemp) if( lemp->tokenprefix ) prefix = lemp->tokenprefix; else prefix = ""; - in = file_open(lemp,".h","rb"); - if( in ){ - int nextChar; - for(i=1; interminal && fgets(line,LINESIZE,in); i++){ - lemon_sprintf(pattern,"const %s%s := %d;\n", - prefix,lemp->symbols[i]->name,i); - if( strcmp(line,pattern) ) break; - } - nextChar = fgetc(in); - fclose(in); - if( i==lemp->nterminal && nextChar==EOF ){ - /* No change in the file. Don't rewrite it. */ - return; - } - } - out = file_open(lemp,".h","wb"); + out = file_open(lemp,".tokens.coh","wb"); if( out ){ for(i=1; interminal; i++){ fprintf(out,"const %s%s := %d;\n",prefix,lemp->symbols[i]->name,i); From e4b28acf9828a6a0a7a6ef453b25afcb2a684baa Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:42 +0000 Subject: [PATCH 12/40] Most of cowfe and cowbe build. --- build.py | 22 +----- build/ab2.py | 6 +- build/gpp.py | 18 +++++ build/yacc.py | 11 +++ src/build.py | 151 +++++++++++++++++++++++++++++++++---- src/cowbe/build.py | 55 ++++++++++++++ src/cowfe/build.py | 51 +++++++++++++ third_party/lemon/build.py | 24 +++++- tools/newgen/build.py | 35 +++++++++ 9 files changed, 335 insertions(+), 38 deletions(-) create mode 100644 build/gpp.py create mode 100644 src/cowbe/build.py create mode 100644 src/cowfe/build.py create mode 100644 tools/newgen/build.py diff --git a/build.py b/build.py index 8c9b9279..2d9fe478 100644 --- a/build.py +++ b/build.py @@ -1,25 +1,5 @@ from build.ab2 import Rule, installable from os.path import * -from src.build import toolchain - -toolchains = [ - toolchain( - name="ncgen", - id="ncgen", - cowfe="bootstrap+cowfe", - cowbe="bootstrap+cowbe", - cowlink="bootstrap+cowlink", - cowwrap="bootstrap+cowwrap", - ), - toolchain( - name="nncgen", - id="nncgen", - cowfe="bootstrap+cowfe", - cowbe="bootstrap+cowbe", - cowlink="bootstrap+cowlink", - cowwrap="bootstrap+cowwrap", - ), -] installable( name="all", @@ -36,5 +16,5 @@ "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", }, - deps=["third_party/djlink+djlink-programs"] + toolchains, + deps=["third_party/djlink+djlink-programs", "src+toolchains"], ) diff --git a/build/ab2.py b/build/ab2.py index e8f5828c..c321e704 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -172,6 +172,8 @@ def convert(self, value, invocation): class Target(Type): def convert(self, value, invocation): + if not value: + return None return targetof(value, cwd=invocation.cwd) @@ -300,6 +302,8 @@ def __getitem__(self, key): class MakeEmitter: def begin(self): emit("hide = @") + emit(".DELETE_ON_ERROR:") + emit(".SECONDARY:") def end(self): pass @@ -445,7 +449,7 @@ def installable(self, name=None, items: TargetsMap() = {}, deps: Targets() = []) emitter.exec(f"echo EXPORT {self.name}") self.ins = items.values() - self.outs = [] + self.outs = filenamesof(deps) for dest, src in items.items(): destf = filenameof(dest) dir = dirname(destf) diff --git a/build/gpp.py b/build/gpp.py new file mode 100644 index 00000000..3bc57ee3 --- /dev/null +++ b/build/gpp.py @@ -0,0 +1,18 @@ +from build.ab2 import Rule, normalrule, Targets, filenamesof +from os.path import * + + +@Rule +def gpp(self, name, srcs: Targets() = []): + hdrs = set(["-I" + dirname(f) for f in filenamesof(srcs)]) + + normalrule( + replaces=self, + ins=srcs, + outleaves=[self.localname + ".i"], + commands=[ + "gpp --nostdinc -U '' '' '(' ',' ')' '(' ')' '$$' '' -M '$$' '\\n' ' ' ' ' '\\n' '(' ')' " + + (" ".join(hdrs)) + + " -o {outs} {ins[0]}" + ], + ) diff --git a/build/yacc.py b/build/yacc.py index d55230bc..5a25c710 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -10,3 +10,14 @@ def yacc(self, name, srcs: Targets() = []): commands=["bison -y -t -o {outs[0]} --defines={outs[1]} {ins}"], label="YACC", ) + + +@Rule +def flex(self, name, srcs: Targets() = []): + normalrule( + replaces=self, + ins=srcs, + outleaves=["lexer.c"], + commands=["flex -8 -Cem -s -t {ins[0]} > {outs[0]}"], + label="FLEX", + ) diff --git a/src/build.py b/src/build.py index af9504cb..136493de 100644 --- a/src/build.py +++ b/src/build.py @@ -1,5 +1,6 @@ -from build.ab2 import Rule, Target, Targets, installable +from build.ab2 import Rule, Target, Targets, installable, normalrule, filenamesof from build.c import cprogram +from os.path import * @Rule @@ -11,23 +12,143 @@ def cgen(self, name, srcs: Targets() = []): def toolchain( self, name, - id, cowfe: Target() = None, cowbe: Target() = None, cowlink: Target() = None, cowwrap: Target() = None, + runtime=None, + asmext=None, + assembler=None, ): - self.toolchain.cowfe = cowfe - self.toolchain.cowbe = cowbe - self.toolchain.cowlink = cowlink - self.toolchain.cowwrap = cowwrap - - installable( - replaces=self, - items={ - "bin/cowfe-" + id: cowfe, - "bin/cowbe-" + id: cowbe, - "bin/cowlink-" + id: cowlink, - "bin/cowwrap-" + id: cowwrap, - }, + id = self.localname + + for k, v in self.args.items(): + setattr(self, k, v) + + items = {} + if cowfe: + items["bin/cowfe-" + id] = cowfe + if cowbe: + items["bin/cowbe-" + id] = cowbe + if cowlink: + items["bin/cowlink-" + id] = cowlink + if cowwrap: + items["bin/cowwrap-" + id] = cowwrap + + installable(replaces=self, items=items) + + +@Rule +def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): + srcs += [ + "rt/common-file.coh", + "rt/common.coh", + "rt/fileio.coh", + "rt/malloc.coh", + "rt/strings.coh", + toolchain.runtime + "/cowgol.coh", + toolchain.runtime + "/file.coh", + toolchain.runtime + "/argv.coh", + ] + + cow = [f for f in filenamesof(srcs) if f.endswith(".cow")] + dirs = set([dirname(f) for f in filenamesof(srcs)]) + flags = [f"-I{dir}/" for dir in dirs] + + cob = normalrule( + name=name + "/cowfe", + ins=[toolchain.cowfe, cow] + srcs, + outleaves=[self.localname + ".cob"], + commands=[ + "scripts/quiet {ins[0]} " + (" ".join(flags)) + " {ins[1]} {outs[0]}" + ], + label="COWFE-" + toolchain.localname.upper(), ) + + coo = normalrule( + name=name + "/cowbe", + ins=[toolchain.cowbe, cob], + outleaves=[self.localname + ".coo"], + commands=["scripts/quiet {ins[0]} {ins[1]} {outs}"], + label="COWBE-" + toolchain.localname.upper(), + ) + + asm = normalrule( + name=name + "/cowlink", + ins=[toolchain.cowlink, coo], + outleaves=[self.localname + toolchain.asmext], + commands=["scripts/quiet {ins[0]} -o {outs} {' '.join(ins[1:])}"], + label="COWLINK-" + toolchain.localname.upper(), + ) + + toolchain.assembler(replaces=self, srcs=[asm]) + + +TOOLCHAINS = [ + toolchain( + name="ncgen", + cowfe="bootstrap+cowfe", + cowbe="bootstrap+cowbe", + cowlink="bootstrap+cowlink", + cowwrap="bootstrap+cowwrap", + runtime="rt/cgen", + asmext=".c", + assembler=cgen, + ), + toolchain( + name="nncgen", + cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", + cowbe="src/cowbe+cowbe-for-cgen-with-ncgen", + cowlink="bootstrap+cowlink", + cowwrap="bootstrap+cowwrap", + runtime="rt/cgen", + asmext=".c", + assembler=cgen, + ), + #toolchain( + # name="ncpm", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", runtime="rt/cpm", + # asmext=".asm", + #), +] + +installable(name="toolchains", deps=TOOLCHAINS) + +normalrule( + name="midcodesfecoh", + ins=["scripts/mkmidcodescoh.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + outleaves=["midcodesfe.coh"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]} fe"], + label="MKMIDCODESFE", +) + +normalrule( + name="midcodesbecoh", + ins=["scripts/mkmidcodescoh.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + outleaves=["midcodesbe.coh"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]} be"], + label="MKMIDCODESBE", +) + +normalrule( + name="coboutcoh", + ins=["scripts/mkcobout.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + outleaves=["cobout.coh"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], + label="MKCOBOUT", +) + +normalrule( + name="iburgcodes", + ins=["scripts/mkiburgcodes.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + outleaves=["iburgcodes-coh.h"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], + label="MKIBURGCODES", +) + +normalrule( + name="cobincoh", + ins=["scripts/mkcobin.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + outleaves=["cobin.coh"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], + label="MKCOBIN", +) diff --git a/src/cowbe/build.py b/src/cowbe/build.py new file mode 100644 index 00000000..b77abf20 --- /dev/null +++ b/src/cowbe/build.py @@ -0,0 +1,55 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol +from tools.newgen.build import newgencowgol + +ARCHS = [ + "6303", + "6502", + "65c02", + "65c02-tiny", + "68000", + "80386", + "8080", + "8086", + "basic", + "cgen", + "pdp11", + "powerpc", + "thumb2", + "z80", +] + +extras = { + "65c02": ["src/cowbe/arch6502.cow.ng"], + "65c02-tiny": ["src/cowbe/arch6502.cow.ng"], +} + +for arch in ARCHS: + newgencowgol( + name="gen-" + arch, + srcs=["src/cowbe/arch" + arch + ".cow.ng"] + extras.get(arch, []), + ) + +for toolchain in TOOLCHAINS: + for arch in ARCHS: + cowgol( + name="cowbe-for-" + arch + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "+gen-" + arch, + "include/coodecls.coh", + "src+midcodesbecoh", + "src+cobincoh", + "./main.cow", + "./allocator.coh", + "./codegen.coh", + "./emitter.coh", + "./inputter.coh", + "./midcodec.coh", + "./processor.coh", + "./regcache.coh", + "./treewalker.coh", + "./types.coh", + "./utils.coh", + ], + ) diff --git a/src/cowfe/build.py b/src/cowfe/build.py new file mode 100644 index 00000000..4c6d0df1 --- /dev/null +++ b/src/cowfe/build.py @@ -0,0 +1,51 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol +from third_party.lemon.build import lemoncowgol + +ARCHS = [ + "6502", + "80386", + "basic", + "cgen", + "pdp11", + "16bit", + "32bita2", + "32bita", +] + +lemoncowgol(name="parser", src="src/cowfe/parser.y") + +for arch in ARCHS: + normalrule( + name="arch-" + arch, + ins=["./arch" + arch + ".coh"], + outleaves=["arch.coh"], + commands=["cp {ins} {outs}"], + label="COPY", + ) + +for toolchain in TOOLCHAINS: + for arch in ARCHS: + cowgol( + name="cowfe-for-" + arch + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "+arch-" + arch, + "+parser", + "./allocator.coh", + "./codegen.coh", + "./emitter.coh", + "./expressions.coh", + "./lexer.coh", + "./main.cow", + "./midcodec.coh", + "./namespace.coh", + "./regcache.coh", + "./symbols.coh", + "./treewalker.coh", + "./types.coh", + "include/coodecls.coh", + "src+coboutcoh", + "src+midcodesfecoh", + ], + ) diff --git a/third_party/lemon/build.py b/third_party/lemon/build.py index 46604695..f5c0e5eb 100644 --- a/third_party/lemon/build.py +++ b/third_party/lemon/build.py @@ -1,4 +1,4 @@ -from build.ab2 import Rule +from build.ab2 import Rule, Target, normalrule from build.c import cprogram cprogram( @@ -10,3 +10,25 @@ name="lemon-cowgol", srcs=["./lemon-cowgol.c"], ) + + +@Rule +def lemon(self, name, src: Target() = None): + normalrule( + replaces=self, + ins=["+lemon", "./lempar.c", src], + outleaves=[self.localname + ".c", self.localname + ".h"], + commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], + label="LEMON", + ) + + +@Rule +def lemoncowgol(self, name, src: Target() = None): + normalrule( + replaces=self, + ins=["+lemon-cowgol", "src/cowfe/lempar.coh", src], + outleaves=[self.localname + ".coh", self.localname + ".tokens.coh"], + commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], + label="LEMON-COWGOL", + ) diff --git a/tools/newgen/build.py b/tools/newgen/build.py new file mode 100644 index 00000000..481f38e2 --- /dev/null +++ b/tools/newgen/build.py @@ -0,0 +1,35 @@ +from build.ab2 import Rule, Targets, normalrule +from build.c import cprogram +from build.yacc import flex +from build.gpp import gpp +from third_party.lemon.build import lemon + +lemon(name="parser", src="./parser.y") + +flex(name="lexer", srcs=["./lexer.l"]) + +cprogram( + name="newgen", + srcs=[ + "./main.c", + "./utils.c", + "./globals.h", + "+parser", + "+lexer", + "src+iburgcodes", + ], + vars={"+cflags": ["-DCOWGOL"], "+ldflags": ["-lfl"]}, +) + + +@Rule +def newgencowgol(self, name, srcs: Targets() = []): + preprocessed = gpp(name=name + "/preprocessed", srcs=srcs) + + normalrule( + replaces=self, + ins=["+newgen", preprocessed], + outleaves=["inssel.coh", "inssel.decl.coh"], + commands=["{ins[0]} {ins[1]} {outs[0]} {outs[1]}"], + label="NEWGEN", + ) From b38092e10c901e73503978e3e812d77e801c681d Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:42 +0000 Subject: [PATCH 13/40] Rename installable -> export. --- build.py | 4 ++-- build/ab2.py | 4 ++-- src/build.py | 6 +++--- third_party/djlink/build.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.py b/build.py index 2d9fe478..06e2c330 100644 --- a/build.py +++ b/build.py @@ -1,7 +1,7 @@ -from build.ab2 import Rule, installable +from build.ab2 import Rule, export from os.path import * -installable( +export( name="all", items={ "bin/bbctube": "tools/tubeemu+bbctube", diff --git a/build/ab2.py b/build/ab2.py index c321e704..40925cdc 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -442,7 +442,7 @@ def normalrule( @Rule -def installable(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): +def export(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): emitter.rule( self.name, filenamesof(items.values(), deps), filenamesof(items.keys()) ) @@ -459,7 +459,7 @@ def installable(self, name=None, items: TargetsMap() = {}, deps: Targets() = []) srcs = filenamesof(src) if len(srcs) != 1: raise ABException( - "a dependency of an installable must have exactly one output file" + "a dependency of an export must have exactly one output file" ) emitter.exec("cp %s %s" % (srcs[0], destf)) diff --git a/src/build.py b/src/build.py index 136493de..3c3fbfee 100644 --- a/src/build.py +++ b/src/build.py @@ -1,4 +1,4 @@ -from build.ab2 import Rule, Target, Targets, installable, normalrule, filenamesof +from build.ab2 import Rule, Target, Targets, export, normalrule, filenamesof from build.c import cprogram from os.path import * @@ -35,7 +35,7 @@ def toolchain( if cowwrap: items["bin/cowwrap-" + id] = cowwrap - installable(replaces=self, items=items) + export(replaces=self, items=items) @Rule @@ -111,7 +111,7 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): #), ] -installable(name="toolchains", deps=TOOLCHAINS) +export(name="toolchains", deps=TOOLCHAINS) normalrule( name="midcodesfecoh", diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py index 95885909..f42df92a 100644 --- a/third_party/djlink/build.py +++ b/third_party/djlink/build.py @@ -1,5 +1,5 @@ from build.c import cxxprogram -from build.ab2 import installable +from build.ab2 import export cxxprogram( name="objdump", @@ -41,7 +41,7 @@ ], ) -installable( +export( name="djlink-programs", items={ "bin/objdump": "+objdump", From 5aca409e1ebff4cc8ad682c49e6ddc0a44cdc144 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:42 +0000 Subject: [PATCH 14/40] Build cowlink. --- src/build.py | 2 +- src/cowlink/build.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/cowlink/build.py diff --git a/src/build.py b/src/build.py index 3c3fbfee..6465957e 100644 --- a/src/build.py +++ b/src/build.py @@ -99,7 +99,7 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): name="nncgen", cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", cowbe="src/cowbe+cowbe-for-cgen-with-ncgen", - cowlink="bootstrap+cowlink", + cowlink="src/cowlink+cowlink-for-cgen-with-ncgen", cowwrap="bootstrap+cowwrap", runtime="rt/cgen", asmext=".c", diff --git a/src/cowlink/build.py b/src/cowlink/build.py new file mode 100644 index 00000000..301c33cb --- /dev/null +++ b/src/cowlink/build.py @@ -0,0 +1,47 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol + +ARCHS = [ + "8080", + "ataritos", + "basic", + "bbct", + "bbctn", + "cgen", + "fuzix6303", + "lx386", + "lx68k", + "lxppc", + "lxthumb2", + "msdos", + "rt11", + "v7unix", +] + +for arch in ARCHS: + normalrule( + name="arch-" + arch, + ins=["./arch" + arch + ".coh"], + outleaves=["archlink.coh"], + commands=["cp {ins} {outs}"], + label="COPY", + ) + +for toolchain in TOOLCHAINS: + for arch in ARCHS: + cowgol( + name="cowlink-for-" + arch + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "include/coodecls.coh", + "+arch-"+arch, + "./main.cow", + "./asmwrite.coh", + "./cooread.coh", + "./emitter.coh", + "./graph.coh", + "./streams.coh", + "./types.coh", + "./utils.coh", + ], + ) From ba1aa0657c23e3cbf6fb25b83a2fa13e6536c438 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:43 +0000 Subject: [PATCH 15/40] Build cowwrap. --- src/build.py | 6 +++--- src/cowlink/build.py | 48 ++++++++++++++++++++++---------------------- src/cowwrap/build.py | 13 ++++++++++++ 3 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 src/cowwrap/build.py diff --git a/src/build.py b/src/build.py index 6465957e..a1c126cb 100644 --- a/src/build.py +++ b/src/build.py @@ -100,15 +100,15 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", cowbe="src/cowbe+cowbe-for-cgen-with-ncgen", cowlink="src/cowlink+cowlink-for-cgen-with-ncgen", - cowwrap="bootstrap+cowwrap", + cowwrap="src/cowwrap+cowwrap-with-ncgen", runtime="rt/cgen", asmext=".c", assembler=cgen, ), - #toolchain( + # toolchain( # name="ncpm", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", runtime="rt/cpm", # asmext=".asm", - #), + # ), ] export(name="toolchains", deps=TOOLCHAINS) diff --git a/src/cowlink/build.py b/src/cowlink/build.py index 301c33cb..940f5811 100644 --- a/src/cowlink/build.py +++ b/src/cowlink/build.py @@ -2,20 +2,20 @@ from src.build import TOOLCHAINS, cowgol ARCHS = [ - "8080", - "ataritos", - "basic", - "bbct", - "bbctn", - "cgen", - "fuzix6303", - "lx386", - "lx68k", - "lxppc", - "lxthumb2", - "msdos", - "rt11", - "v7unix", + "8080", + "ataritos", + "basic", + "bbct", + "bbctn", + "cgen", + "fuzix6303", + "lx386", + "lx68k", + "lxppc", + "lxthumb2", + "msdos", + "rt11", + "v7unix", ] for arch in ARCHS: @@ -33,15 +33,15 @@ name="cowlink-for-" + arch + "-with-" + toolchain.localname, toolchain=toolchain, srcs=[ - "include/coodecls.coh", - "+arch-"+arch, - "./main.cow", - "./asmwrite.coh", - "./cooread.coh", - "./emitter.coh", - "./graph.coh", - "./streams.coh", - "./types.coh", - "./utils.coh", + "include/coodecls.coh", + "+arch-" + arch, + "./main.cow", + "./asmwrite.coh", + "./cooread.coh", + "./emitter.coh", + "./graph.coh", + "./streams.coh", + "./types.coh", + "./utils.coh", ], ) diff --git a/src/cowwrap/build.py b/src/cowwrap/build.py new file mode 100644 index 00000000..a55e1df4 --- /dev/null +++ b/src/cowwrap/build.py @@ -0,0 +1,13 @@ +from src.build import TOOLCHAINS, cowgol + +for toolchain in TOOLCHAINS: + cowgol( + name="cowwrap-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "include/coodecls.coh", + "./main.cow", + "./emitter.coh", + "./reader.coh", + ], + ) From a10f9c62fc965e7341197434b0b0bcc79849c842 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:43 +0000 Subject: [PATCH 16/40] Finally build our first programs! --- build.py | 2 +- build/ab2.py | 8 ++- build/c.py | 12 +++- examples/build.py | 27 +++++++ rt/cgen/build.py | 3 + rt/cpm/build.py | 3 + rt/cpmz/build.py | 3 + rt/lxthumb2/build.py | 3 + src/build.py | 146 ++++++++++++++++++++++++++++++++++---- third_party/zmac/build.py | 10 ++- tools/obpemu/build.py | 4 +- 11 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 examples/build.py create mode 100644 rt/cgen/build.py create mode 100644 rt/cpm/build.py create mode 100644 rt/cpmz/build.py create mode 100644 rt/lxthumb2/build.py diff --git a/build.py b/build.py index 06e2c330..cca144aa 100644 --- a/build.py +++ b/build.py @@ -16,5 +16,5 @@ "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", }, - deps=["third_party/djlink+djlink-programs", "src+toolchains"], + deps=["third_party/djlink+djlink-programs", "src+toolchains", "examples"], ) diff --git a/build/ab2.py b/build/ab2.py index 40925cdc..12863875 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -32,7 +32,9 @@ def new_import(name, *args, **kwargs): sys.stderr.write(f"loading {path}\n") loader = importlib.machinery.SourceFileLoader(name, path) - spec = importlib.util.spec_from_loader(name, loader, origin="built-in") + spec = importlib.util.spec_from_loader( + name, loader, origin="built-in" + ) module = importlib.util.module_from_spec(spec) sys.modules[name] = module spec.loader.exec_module(module) @@ -480,7 +482,9 @@ def load(filename): def main(): parser = argparse.ArgumentParser() - parser.add_argument("-m", "--mode", choices=["make", "ninja"], default="make") + parser.add_argument( + "-m", "--mode", choices=["make", "ninja"], default="make" + ) parser.add_argument("-o", "--output") parser.add_argument("files", nargs="+") args = parser.parse_args() diff --git a/build/c.py b/build/c.py index 066e3c90..d04a4f13 100644 --- a/build/c.py +++ b/build/c.py @@ -49,7 +49,9 @@ def cfile( commands=["$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}"], label="CC", ): - cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", "cflags") + cfileimpl( + self, name, srcs, deps, suffix, commands, label, "cfile", "cflags" + ) @Rule @@ -62,7 +64,9 @@ def cxxfile( commands=["$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}"], label="CXX", ): - cfileimpl(self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags") + cfileimpl( + self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags" + ) def findsources(name, srcs, deps): @@ -71,7 +75,9 @@ def findsources(name, srcs, deps): if f.endswith(".c") or f.endswith(".cc") or f.endswith(".cpp"): ins += [ cfile( - name=name + "/" + basename(filenamesof(f)[0]), srcs=[f], deps=deps + name=name + "/" + basename(filenamesof(f)[0]), + srcs=[f], + deps=deps, ) ] return ins diff --git a/examples/build.py b/examples/build.py new file mode 100644 index 00000000..14d648cc --- /dev/null +++ b/examples/build.py @@ -0,0 +1,27 @@ +from src.build import TOOLCHAINS, cowgol +from build.ab2 import export + +PROGRAMS = [ + "argv", + "cowcalc", + "file", + "filetester", + "helloworld", + "icando", + "mandel", +] + +items = {} +for toolchain in TOOLCHAINS: + for prog in PROGRAMS: + t = cowgol( + name=prog + "-for-" + toolchain.localname, + srcs="./" + prog + ".cow", + toolchain=toolchain, + ) + + items[ + f"bin/examples/{prog}-for-{toolchain.localname}{toolchain.binext}" + ] = t + +export(name="examples", items=items) diff --git a/rt/cgen/build.py b/rt/cgen/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/cgen/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/cpm/build.py b/rt/cpm/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/cpm/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/cpmz/build.py b/rt/cpmz/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/cpmz/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/lxthumb2/build.py b/rt/lxthumb2/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/lxthumb2/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/src/build.py b/src/build.py index a1c126cb..9fd65064 100644 --- a/src/build.py +++ b/src/build.py @@ -1,6 +1,8 @@ from build.ab2 import Rule, Target, Targets, export, normalrule, filenamesof from build.c import cprogram from os.path import * +from third_party.zmac.build import zmac +from types import SimpleNamespace @Rule @@ -8,6 +10,24 @@ def cgen(self, name, srcs: Targets() = []): cprogram(replaces=self, srcs=srcs + ["rt/cgen/cowgol.h"]) +def buildgasimpl(self, prefix): + normalrule( + replaces=self, + ins=self.args["srcs"], + outleaves=[self.localname + ".elf"], + commands=[ + prefix + "-as -g {ins} -o {outs[0]}.s", + prefix + "-ld -g {outs[0]}.s -o {outs[0]}", + ], + label="ASM-" + prefix.upper(), + ) + + +@Rule +def buildgasarm(self, name, srcs: Targets() = None): + buildgasimpl(self, "arm-linux-gnueabihf") + + @Rule def toolchain( self, @@ -18,6 +38,7 @@ def toolchain( cowwrap: Target() = None, runtime=None, asmext=None, + binext=None, assembler=None, ): id = self.localname @@ -39,7 +60,13 @@ def toolchain( @Rule -def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): +def cowlib( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + toolchain: Target() = None, +): srcs += [ "rt/common-file.coh", "rt/common.coh", @@ -60,22 +87,32 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): ins=[toolchain.cowfe, cow] + srcs, outleaves=[self.localname + ".cob"], commands=[ - "scripts/quiet {ins[0]} " + (" ".join(flags)) + " {ins[1]} {outs[0]}" + "scripts/quiet {ins[0]} " + + (" ".join(flags)) + + " {ins[1]} {outs[0]}" ], label="COWFE-" + toolchain.localname.upper(), ) - coo = normalrule( - name=name + "/cowbe", + normalrule( + replaces=self, ins=[toolchain.cowbe, cob], outleaves=[self.localname + ".coo"], commands=["scripts/quiet {ins[0]} {ins[1]} {outs}"], label="COWBE-" + toolchain.localname.upper(), ) + +@Rule +def cowlink(self, name, deps: Targets() = [], toolchain: Target() = None): + coos = [] + for d in deps: + if hasattr(d, "cowlib"): + coos += filenamesof(d) + asm = normalrule( name=name + "/cowlink", - ins=[toolchain.cowlink, coo], + ins=[toolchain.cowlink] + [coos], outleaves=[self.localname + toolchain.asmext], commands=["scripts/quiet {ins[0]} -o {outs} {' '.join(ins[1:])}"], label="COWLINK-" + toolchain.localname.upper(), @@ -84,6 +121,36 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): toolchain.assembler(replaces=self, srcs=[asm]) +@Rule +def cowgol( + self, + name, + srcs: Targets() = [], + deps: Targets() = [], + toolchain: Target() = None, +): + coo = cowlib(name=name + "/main", srcs=srcs, toolchain=toolchain) + + cowlink( + replaces=self, + deps=[coo, toolchain.runtime + "+cowgolcoo"] + deps, + toolchain=toolchain, + ) + + +@Rule +def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): + self.cowlib = SimpleNamespace() + normalrule( + replaces=self, + ins=["bootstrap+cowwrap", src], + outleaves=["cowgol.coo"], + label="COWWRAP-"+toolchain.localname.upper(), + commands=[ + "{ins[0]} {ins[1]} {outs}" + ]) + + TOOLCHAINS = [ toolchain( name="ncgen", @@ -93,6 +160,7 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): cowwrap="bootstrap+cowwrap", runtime="rt/cgen", asmext=".c", + binext=".exe", assembler=cgen, ), toolchain( @@ -103,19 +171,53 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): cowwrap="src/cowwrap+cowwrap-with-ncgen", runtime="rt/cgen", asmext=".c", + binext=".exe", assembler=cgen, ), - # toolchain( - # name="ncpm", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", runtime="rt/cpm", - # asmext=".asm", - # ), + toolchain( + name="ncpm", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-8080-with-ncgen", + cowlink="src/cowlink+cowlink-for-8080-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/cpm", + asmext=".asm", + binext=".com", + assembler=zmac, + ), + toolchain( + name="ncpmz", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-z80-with-ncgen", + cowlink="src/cowlink+cowlink-for-8080-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/cpmz", + asmext=".z80", + binext=".com", + assembler=zmac, + ), + toolchain( + name="lxthumb2", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-thumb2-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxthumb2-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxthumb2", + asmext=".s", + binext=".exe", + assembler=buildgasarm, + ), ] export(name="toolchains", deps=TOOLCHAINS) normalrule( name="midcodesfecoh", - ins=["scripts/mkmidcodescoh.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + ins=[ + "scripts/mkmidcodescoh.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], outleaves=["midcodesfe.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]} fe"], label="MKMIDCODESFE", @@ -123,7 +225,11 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): normalrule( name="midcodesbecoh", - ins=["scripts/mkmidcodescoh.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + ins=[ + "scripts/mkmidcodescoh.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], outleaves=["midcodesbe.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]} be"], label="MKMIDCODESBE", @@ -131,7 +237,11 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): normalrule( name="coboutcoh", - ins=["scripts/mkcobout.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + ins=[ + "scripts/mkcobout.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], outleaves=["cobout.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKCOBOUT", @@ -139,7 +249,11 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): normalrule( name="iburgcodes", - ins=["scripts/mkiburgcodes.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + ins=[ + "scripts/mkiburgcodes.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], outleaves=["iburgcodes-coh.h"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKIBURGCODES", @@ -147,7 +261,11 @@ def cowgol(self, name, srcs: Targets() = [], toolchain: Target() = None): normalrule( name="cobincoh", - ins=["scripts/mkcobin.lua", "scripts/libcowgol.lua", "src/midcodes.coh.tab"], + ins=[ + "scripts/mkcobin.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], outleaves=["cobin.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKCOBIN", diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py index 50f13eae..aaddc68a 100644 --- a/third_party/zmac/build.py +++ b/third_party/zmac/build.py @@ -20,12 +20,16 @@ @Rule def zmac(self, name, srcs: Targets() = []): filename, ext = splitext(filenameof(srcs)) - archflag = "-z" if (ext == "z80") else "-8" + archflag = "-z" if (ext == ".z80") else "-8" normalrule( replaces=self, ins=["third_party/zmac", srcs[0]], - outleaves=[self.localname + ".cim", self.localname + ".lst"], - commands=["{ins[0]} -j -m " + archflag + " -o {outs[0]} -o {outs[1]} {ins[1]}"], + outleaves=[self.localname + ".cim"], + commands=[ + "{ins[0]} -j -m " + + archflag + + " -o {outs[0]} -o {outs[0]}.lst {ins[1]}" + ], label="ZMAC", ) diff --git a/tools/obpemu/build.py b/tools/obpemu/build.py index c9975306..78c9d0c9 100644 --- a/tools/obpemu/build.py +++ b/tools/obpemu/build.py @@ -1,5 +1,7 @@ from build.c import cprogram cprogram( - name="obpemu", srcs=["./emulator.c", "./main.c"], vars={"+ldflags": "-lreadline"} + name="obpemu", + srcs=["./emulator.c", "./main.c"], + vars={"+ldflags": "-lreadline"}, ) From 409897e6dea18e0194a108dbf42dca70c74c1b7c Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:43 +0000 Subject: [PATCH 17/40] Rename outleaves -> outs. --- build/ab2.py | 4 ++-- build/c.py | 6 +++--- build/gpp.py | 2 +- build/yacc.py | 4 ++-- src/build.py | 20 ++++++++++---------- src/cowfe/build.py | 2 +- src/cowlink/build.py | 2 +- third_party/lemon/build.py | 4 ++-- third_party/musashi/build.py | 2 +- third_party/zmac/build.py | 2 +- tools/build.py | 2 +- tools/newgen/build.py | 2 +- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index 12863875..7e1041a4 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -426,7 +426,7 @@ def normalrule( name=None, ins: Targets() = [], deps: Targets() = [], - outleaves=[], + outs=[], label="RULE", objdir=None, commands=[], @@ -437,7 +437,7 @@ def normalrule( replaces=self, ins=ins, deps=deps, - outs=[join(objdir, f) for f in outleaves], + outs=[join(objdir, f) for f in outs], label=label, commands=commands, ) diff --git a/build/c.py b/build/c.py index d04a4f13..9eae78f2 100644 --- a/build/c.py +++ b/build/c.py @@ -32,7 +32,7 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): replaces=self, ins=srcs, deps=deps, - outleaves=[outleaf], + outs=[outleaf], label=label, commands=commands, vars={"+" + flags: flatten(includeflags)}, @@ -100,7 +100,7 @@ def clibrary( normalrule( replaces=self, ins=findsources(name, srcs, deps), - outleaves=[basename(name) + ".a"], + outs=[basename(name) + ".a"], label=label, commands=commands, ) @@ -121,7 +121,7 @@ def programimpl(self, name, srcs, deps, commands, label, filerule, kind): normalrule( replaces=self, ins=findsources(name, srcs, deps), - outleaves=[basename(name)], + outs=[basename(name)], label=label, commands=commands, vars={"+ldflags": libraries}, diff --git a/build/gpp.py b/build/gpp.py index 3bc57ee3..ff95f0b2 100644 --- a/build/gpp.py +++ b/build/gpp.py @@ -9,7 +9,7 @@ def gpp(self, name, srcs: Targets() = []): normalrule( replaces=self, ins=srcs, - outleaves=[self.localname + ".i"], + outs=[self.localname + ".i"], commands=[ "gpp --nostdinc -U '' '' '(' ',' ')' '(' ')' '$$' '' -M '$$' '\\n' ' ' ' ' '\\n' '(' ')' " + (" ".join(hdrs)) diff --git a/build/yacc.py b/build/yacc.py index 5a25c710..e14f09ce 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -6,7 +6,7 @@ def yacc(self, name, srcs: Targets() = []): normalrule( replaces=self, ins=srcs, - outleaves=["y.tab.c", "y.tab.h"], + outs=["y.tab.c", "y.tab.h"], commands=["bison -y -t -o {outs[0]} --defines={outs[1]} {ins}"], label="YACC", ) @@ -17,7 +17,7 @@ def flex(self, name, srcs: Targets() = []): normalrule( replaces=self, ins=srcs, - outleaves=["lexer.c"], + outs=["lexer.c"], commands=["flex -8 -Cem -s -t {ins[0]} > {outs[0]}"], label="FLEX", ) diff --git a/src/build.py b/src/build.py index 9fd65064..46387968 100644 --- a/src/build.py +++ b/src/build.py @@ -14,7 +14,7 @@ def buildgasimpl(self, prefix): normalrule( replaces=self, ins=self.args["srcs"], - outleaves=[self.localname + ".elf"], + outs=[self.localname + ".elf"], commands=[ prefix + "-as -g {ins} -o {outs[0]}.s", prefix + "-ld -g {outs[0]}.s -o {outs[0]}", @@ -85,7 +85,7 @@ def cowlib( cob = normalrule( name=name + "/cowfe", ins=[toolchain.cowfe, cow] + srcs, - outleaves=[self.localname + ".cob"], + outs=[self.localname + ".cob"], commands=[ "scripts/quiet {ins[0]} " + (" ".join(flags)) @@ -97,7 +97,7 @@ def cowlib( normalrule( replaces=self, ins=[toolchain.cowbe, cob], - outleaves=[self.localname + ".coo"], + outs=[self.localname + ".coo"], commands=["scripts/quiet {ins[0]} {ins[1]} {outs}"], label="COWBE-" + toolchain.localname.upper(), ) @@ -113,7 +113,7 @@ def cowlink(self, name, deps: Targets() = [], toolchain: Target() = None): asm = normalrule( name=name + "/cowlink", ins=[toolchain.cowlink] + [coos], - outleaves=[self.localname + toolchain.asmext], + outs=[self.localname + toolchain.asmext], commands=["scripts/quiet {ins[0]} -o {outs} {' '.join(ins[1:])}"], label="COWLINK-" + toolchain.localname.upper(), ) @@ -144,7 +144,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): normalrule( replaces=self, ins=["bootstrap+cowwrap", src], - outleaves=["cowgol.coo"], + outs=["cowgol.coo"], label="COWWRAP-"+toolchain.localname.upper(), commands=[ "{ins[0]} {ins[1]} {outs}" @@ -218,7 +218,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): "scripts/libcowgol.lua", "src/midcodes.coh.tab", ], - outleaves=["midcodesfe.coh"], + outs=["midcodesfe.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]} fe"], label="MKMIDCODESFE", ) @@ -230,7 +230,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): "scripts/libcowgol.lua", "src/midcodes.coh.tab", ], - outleaves=["midcodesbe.coh"], + outs=["midcodesbe.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]} be"], label="MKMIDCODESBE", ) @@ -242,7 +242,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): "scripts/libcowgol.lua", "src/midcodes.coh.tab", ], - outleaves=["cobout.coh"], + outs=["cobout.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKCOBOUT", ) @@ -254,7 +254,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): "scripts/libcowgol.lua", "src/midcodes.coh.tab", ], - outleaves=["iburgcodes-coh.h"], + outs=["iburgcodes-coh.h"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKIBURGCODES", ) @@ -266,7 +266,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): "scripts/libcowgol.lua", "src/midcodes.coh.tab", ], - outleaves=["cobin.coh"], + outs=["cobin.coh"], commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], label="MKCOBIN", ) diff --git a/src/cowfe/build.py b/src/cowfe/build.py index 4c6d0df1..0bf00436 100644 --- a/src/cowfe/build.py +++ b/src/cowfe/build.py @@ -19,7 +19,7 @@ normalrule( name="arch-" + arch, ins=["./arch" + arch + ".coh"], - outleaves=["arch.coh"], + outs=["arch.coh"], commands=["cp {ins} {outs}"], label="COPY", ) diff --git a/src/cowlink/build.py b/src/cowlink/build.py index 940f5811..efbd366a 100644 --- a/src/cowlink/build.py +++ b/src/cowlink/build.py @@ -22,7 +22,7 @@ normalrule( name="arch-" + arch, ins=["./arch" + arch + ".coh"], - outleaves=["archlink.coh"], + outs=["archlink.coh"], commands=["cp {ins} {outs}"], label="COPY", ) diff --git a/third_party/lemon/build.py b/third_party/lemon/build.py index f5c0e5eb..5d865059 100644 --- a/third_party/lemon/build.py +++ b/third_party/lemon/build.py @@ -17,7 +17,7 @@ def lemon(self, name, src: Target() = None): normalrule( replaces=self, ins=["+lemon", "./lempar.c", src], - outleaves=[self.localname + ".c", self.localname + ".h"], + outs=[self.localname + ".c", self.localname + ".h"], commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], label="LEMON", ) @@ -28,7 +28,7 @@ def lemoncowgol(self, name, src: Target() = None): normalrule( replaces=self, ins=["+lemon-cowgol", "src/cowfe/lempar.coh", src], - outleaves=[self.localname + ".coh", self.localname + ".tokens.coh"], + outs=[self.localname + ".coh", self.localname + ".tokens.coh"], commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], label="LEMON-COWGOL", ) diff --git a/third_party/musashi/build.py b/third_party/musashi/build.py index 09694c53..cbb01345 100644 --- a/third_party/musashi/build.py +++ b/third_party/musashi/build.py @@ -6,7 +6,7 @@ normalrule( name="m68kops", ins=["+m68kmake", "./m68k_in.c"], - outleaves=["m68kops.c", "m68kops.h"], + outs=["m68kops.c", "m68kops.h"], commands=["{ins[0]} {dirname(outs[0])} {ins[1]} > /dev/null"], label="MUSASHILIB", ) diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py index aaddc68a..a2df8554 100644 --- a/third_party/zmac/build.py +++ b/third_party/zmac/build.py @@ -25,7 +25,7 @@ def zmac(self, name, srcs: Targets() = []): normalrule( replaces=self, ins=["third_party/zmac", srcs[0]], - outleaves=[self.localname + ".cim"], + outs=[self.localname + ".cim"], commands=[ "{ins[0]} -j -m " + archflag diff --git a/tools/build.py b/tools/build.py index edd564db..bcb4882f 100644 --- a/tools/build.py +++ b/tools/build.py @@ -17,7 +17,7 @@ def objectify(self, name, src: Target() = None, symbol=None): normalrule( replaces=self, ins=["tools/objectify", src], - outleaves=[symbol + ".c"], + outs=[symbol + ".c"], commands=["lua {ins[0]} " + symbol + " < {ins[1]} > {outs}"], label="OBJECTIFY", ) diff --git a/tools/newgen/build.py b/tools/newgen/build.py index 481f38e2..10311d26 100644 --- a/tools/newgen/build.py +++ b/tools/newgen/build.py @@ -29,7 +29,7 @@ def newgencowgol(self, name, srcs: Targets() = []): normalrule( replaces=self, ins=["+newgen", preprocessed], - outleaves=["inssel.coh", "inssel.decl.coh"], + outs=["inssel.coh", "inssel.decl.coh"], commands=["{ins[0]} {ins[1]} {outs[0]} {outs[1]}"], label="NEWGEN", ) From b5aa4e1c6bd9cccaea23015f3eadef7c870fdb47 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:43 +0000 Subject: [PATCH 18/40] More toolchains. --- rt/lx386/build.py | 3 +++ src/build.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 rt/lx386/build.py diff --git a/rt/lx386/build.py b/rt/lx386/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/lx386/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/src/build.py b/src/build.py index 46387968..af1a5c0f 100644 --- a/src/build.py +++ b/src/build.py @@ -28,6 +28,19 @@ def buildgasarm(self, name, srcs: Targets() = None): buildgasimpl(self, "arm-linux-gnueabihf") +@Rule +def buildgas386(self, name, srcs: Targets() = None): + buildgasimpl(self, "i686-linux-gnu") + +@Rule +def buildgas68k(self, name, srcs: Targets() = None): + buildgasimpl(self, "m68k-linux-gnu") + +@Rule +def buildgasppc(self, name, srcs: Targets() = None): + buildgasimpl(self, "powerpc-linux-gnu") + + @Rule def toolchain( self, @@ -143,7 +156,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): self.cowlib = SimpleNamespace() normalrule( replaces=self, - ins=["bootstrap+cowwrap", src], + ins=[toolchain.cowwrap, src], outs=["cowgol.coo"], label="COWWRAP-"+toolchain.localname.upper(), commands=[ @@ -207,6 +220,39 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): binext=".exe", assembler=buildgasarm, ), + toolchain( + name="lx386", + cowfe="src/cowfe+cowfe-for-80386-with-nncgen", + cowbe="src/cowbe+cowbe-for-80386-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx386-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx386", + asmext=".s", + binext=".exe", + assembler=buildgas386, + ), + toolchain( + name="lx68k", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx68k-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx68k", + asmext=".s", + binext=".exe", + assembler=buildgas68k, + ), + toolchain( + name="lxppc", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-powerpc-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxppc-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxppc", + asmext=".s", + binext=".exe", + assembler=buildgasppc, + ), ] export(name="toolchains", deps=TOOLCHAINS) From e76ac50e170f8a92de3930ddac9f1c8d60cc0a17 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:44 +0000 Subject: [PATCH 19/40] Fix export dependencies. --- Makefile | 2 +- build/ab2.py | 19 ++++++++++--------- src/build.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 9ff89745..0f1b7bda 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ build-files = $(shell find . -name 'build.py') build/*.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) - @python3 -B build/ab2.py -m make -o $@ build.py + @python3 -B build/ab2.py -m make -t +all -o $@ build.py diff --git a/build/ab2.py b/build/ab2.py index 7e1041a4..1911c760 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -268,6 +268,10 @@ def filenamesof(*xs): return fs +def targetnamesof(*xs): + return [x.name for x in flatten(xs)] + + def filenameof(x): xs = filenamesof(x) if len(xs) != 1: @@ -315,7 +319,9 @@ def var(self, name, value): emit(name + "=" + unmake(value)) def rule(self, name, ins, outs): + ins = filenamesof(ins) if outs: + outs = filenamesof(outs) emit(".PHONY:", name) emit(name, ":", unmake(outs)) emit(outs, "&:", unmake(ins)) @@ -446,7 +452,7 @@ def normalrule( @Rule def export(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): emitter.rule( - self.name, filenamesof(items.values(), deps), filenamesof(items.keys()) + self.name, flatten(items.values(), deps), filenamesof(items.keys()) ) emitter.exec(f"echo EXPORT {self.name}") @@ -487,6 +493,7 @@ def main(): ) parser.add_argument("-o", "--output") parser.add_argument("files", nargs="+") + parser.add_argument("-t", "--targets", nargs="+") args = parser.parse_args() global outputFp @@ -512,14 +519,8 @@ def main(): for f in args.files: loadbuildfile(f) - total = 0 - while unmaterialisedTargets: - total = len(targets) - finished = total - len(unmaterialisedTargets) - sys.stderr.write("%d/%d\r" % (finished, total)) - next(iter(unmaterialisedTargets)).materialise() - sys.stderr.write("%d/%d\n" % (total, total)) - + for t in args.targets: + targets[t].materialise() emitter.end() diff --git a/src/build.py b/src/build.py index af1a5c0f..3a512431 100644 --- a/src/build.py +++ b/src/build.py @@ -160,7 +160,7 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): outs=["cowgol.coo"], label="COWWRAP-"+toolchain.localname.upper(), commands=[ - "{ins[0]} {ins[1]} {outs}" + "scripts/quiet {ins[0]} {ins[1]} {outs}" ]) From 66f4dd1f434343485d51284eed9c07c764db3d01 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:44 +0000 Subject: [PATCH 20/40] Fix export dependencies... again. --- build/ab2.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index 1911c760..6bfd0553 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -318,15 +318,15 @@ def var(self, name, value): # Don't let emit insert spaces. emit(name + "=" + unmake(value)) - def rule(self, name, ins, outs): + def rule(self, name, ins, outs, deps=[]): ins = filenamesof(ins) if outs: outs = filenamesof(outs) emit(".PHONY:", name) - emit(name, ":", unmake(outs)) - emit(outs, "&:", unmake(ins)) + emit(name, ":", unmake(outs), unmake(deps)) + emit(outs, "&:", unmake(ins), unmake(deps)) else: - emit(name, ":", unmake(ins)) + emit(name, ":", unmake(ins), unmake(deps)) def exec(self, command): emit("\t$(hide)", unmake(command)) @@ -452,7 +452,10 @@ def normalrule( @Rule def export(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): emitter.rule( - self.name, flatten(items.values(), deps), filenamesof(items.keys()) + self.name, + flatten(items.values()), + filenamesof(items.keys()), + filenamesof(deps), ) emitter.exec(f"echo EXPORT {self.name}") From 1f90e99a06c819e91037b371929c5dd18541d184 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:44 +0000 Subject: [PATCH 21/40] More toolchains. Add missing files. --- build.py | 2 +- build/tass64.py | 14 ++++++++++++ examples/build.py | 1 + rt/bbct/build.py | 3 +++ rt/lx68k/build.py | 3 +++ rt/lxppc/build.py | 3 +++ src/build.py | 54 +++++++++++++++++++++++++++++++++++++++++------ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 build/tass64.py create mode 100644 rt/bbct/build.py create mode 100644 rt/lx68k/build.py create mode 100644 rt/lxppc/build.py diff --git a/build.py b/build.py index cca144aa..c1adfa54 100644 --- a/build.py +++ b/build.py @@ -16,5 +16,5 @@ "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", }, - deps=["third_party/djlink+djlink-programs", "src+toolchains", "examples"], + deps=["third_party/djlink+djlink-programs", "examples"], ) diff --git a/build/tass64.py b/build/tass64.py new file mode 100644 index 00000000..f0a31283 --- /dev/null +++ b/build/tass64.py @@ -0,0 +1,14 @@ +from build.ab2 import normalrule, Rule, Targets, filenameof + + +@Rule +def tass64(self, name, srcs: Targets() = []): + normalrule( + replaces=self, + ins=srcs, + outs=[self.localname + ".bin"], + commands=[ + "64tass --quiet --long-branch --ascii --case-sensitive --nostart -o {outs} {ins}" + ], + label="TASS64", + ) diff --git a/examples/build.py b/examples/build.py index 14d648cc..7aeb5c8f 100644 --- a/examples/build.py +++ b/examples/build.py @@ -13,6 +13,7 @@ items = {} for toolchain in TOOLCHAINS: + toolchain.materialise() for prog in PROGRAMS: t = cowgol( name=prog + "-for-" + toolchain.localname, diff --git a/rt/bbct/build.py b/rt/bbct/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/bbct/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/lx68k/build.py b/rt/lx68k/build.py new file mode 100644 index 00000000..1bedc025 --- /dev/null +++ b/rt/lx68k/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="rt/common-68000/cowgol.cos") diff --git a/rt/lxppc/build.py b/rt/lxppc/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/lxppc/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/src/build.py b/src/build.py index 3a512431..32f1ec63 100644 --- a/src/build.py +++ b/src/build.py @@ -3,6 +3,7 @@ from os.path import * from third_party.zmac.build import zmac from types import SimpleNamespace +from build.tass64 import tass64 @Rule @@ -32,15 +33,22 @@ def buildgasarm(self, name, srcs: Targets() = None): def buildgas386(self, name, srcs: Targets() = None): buildgasimpl(self, "i686-linux-gnu") + @Rule def buildgas68k(self, name, srcs: Targets() = None): buildgasimpl(self, "m68k-linux-gnu") + @Rule def buildgasppc(self, name, srcs: Targets() = None): buildgasimpl(self, "powerpc-linux-gnu") +@Rule +def buildtass64(self, name, srcs: Targets() = None): + tass64(replaces=self, srcs=srcs) + + @Rule def toolchain( self, @@ -152,16 +160,17 @@ def cowgol( @Rule -def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): +def cowwrap( + self, name, src: Target() = None, toolchain: Target() = "src+ncgen" +): self.cowlib = SimpleNamespace() normalrule( replaces=self, ins=[toolchain.cowwrap, src], outs=["cowgol.coo"], - label="COWWRAP-"+toolchain.localname.upper(), - commands=[ - "scripts/quiet {ins[0]} {ins[1]} {outs}" - ]) + label="COWWRAP-" + toolchain.localname.upper(), + commands=["scripts/quiet {ins[0]} {ins[1]} {outs}"], + ) TOOLCHAINS = [ @@ -253,10 +262,41 @@ def cowwrap(self, name, src: Target() = None, toolchain:Target()="src+ncgen"): binext=".exe", assembler=buildgasppc, ), + toolchain( + name="bbct", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ), + toolchain( + name="bbctiny", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-tiny-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ), + toolchain( + name="bbct6502", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-6502-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ), ] -export(name="toolchains", deps=TOOLCHAINS) - normalrule( name="midcodesfecoh", ins=[ From fb119d5d458bc0a075a1259fe9c4179566abfc02 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:45 +0000 Subject: [PATCH 22/40] Add the rest of the toolchains. --- Makefile | 2 +- build/nasm.py | 12 ++++++ rt/ataritos/build.py | 3 ++ rt/fuzix6303/build.py | 3 ++ rt/msdos/build.py | 3 ++ rt/unixv7/build.py | 3 ++ src/build.py | 77 +++++++++++++++++++++++++++++++++++++ src/cowasm/build.py | 18 +++++++++ third_party/djlink/build.py | 13 ++++++- 9 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 build/nasm.py create mode 100644 rt/ataritos/build.py create mode 100644 rt/fuzix6303/build.py create mode 100644 rt/msdos/build.py create mode 100644 rt/unixv7/build.py create mode 100644 src/cowasm/build.py diff --git a/Makefile b/Makefile index 0f1b7bda..54c815f5 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ build-files = $(shell find . -name 'build.py') build/*.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) - @python3 -B build/ab2.py -m make -t +all -o $@ build.py + @python3 -X pycache_prefix=$(OBJ) build/ab2.py -m make -t +all -o $@ build.py diff --git a/build/nasm.py b/build/nasm.py new file mode 100644 index 00000000..8e38a04c --- /dev/null +++ b/build/nasm.py @@ -0,0 +1,12 @@ +from build.ab2 import normalrule, Rule, Targets, filenameof + + +@Rule +def nasm(self, name, srcs: Targets() = []): + normalrule( + replaces=self, + ins=srcs, + outs=[self.localname + ".obj"], + commands=["nasm -f obj -o {outs} {ins}"], + label="NASM", + ) diff --git a/rt/ataritos/build.py b/rt/ataritos/build.py new file mode 100644 index 00000000..1bedc025 --- /dev/null +++ b/rt/ataritos/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="rt/common-68000/cowgol.cos") diff --git a/rt/fuzix6303/build.py b/rt/fuzix6303/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/fuzix6303/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/msdos/build.py b/rt/msdos/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/msdos/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/rt/unixv7/build.py b/rt/unixv7/build.py new file mode 100644 index 00000000..b7594b3b --- /dev/null +++ b/rt/unixv7/build.py @@ -0,0 +1,3 @@ +from src.build import cowwrap + +cowwrap(name="cowgolcoo", src="./cowgol.cos") diff --git a/src/build.py b/src/build.py index 32f1ec63..f1dabb67 100644 --- a/src/build.py +++ b/src/build.py @@ -4,6 +4,8 @@ from third_party.zmac.build import zmac from types import SimpleNamespace from build.tass64 import tass64 +from build.nasm import nasm +from third_party.djlink.build import djlink @Rule @@ -44,11 +46,42 @@ def buildgasppc(self, name, srcs: Targets() = None): buildgasimpl(self, "powerpc-linux-gnu") +@Rule +def buildgasataritos(self, name, srcs: Targets() = None): + buildgasimpl(self, "m68k-atari-mint") + + @Rule def buildtass64(self, name, srcs: Targets() = None): tass64(replaces=self, srcs=srcs) +def buildcowasmimpl(self, asm): + normalrule( + replaces=self, + ins=[asm] + self.args["srcs"], + outs=[self.localname + ".bin"], + commands=["scripts/quiet {ins[0]} -o {outs[0]} {ins[1]}"], + label="ASM", + ) + + +@Rule +def buildcowasmpdp11(self, name, srcs: Targets() = None): + buildcowasmimpl(self, "src/cowasm+cowasm-for-pdp11-with-ncgen") + + +@Rule +def buildcowasm6303(self, name, srcs: Targets() = None): + buildcowasmimpl(self, "src/cowasm+cowasm-for-6303-with-ncgen") + + +@Rule +def buildnasm(self, name, srcs: Targets() = None): + o = nasm(name=name + "/obj", srcs=srcs) + djlink(replaces=self, srcs=[o]) + + @Rule def toolchain( self, @@ -295,6 +328,50 @@ def cowwrap( binext=".bin", assembler=buildtass64, ), + toolchain( + name="unixv7", + cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", + cowbe="src/cowbe+cowbe-for-pdp11-with-ncgen", + cowlink="src/cowlink+cowlink-for-v7unix-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/unixv7", + asmext=".asm", + binext=".exe", + assembler=buildcowasmpdp11, + ), + toolchain( + name="fuzix6303", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-6303-with-ncgen", + cowlink="src/cowlink+cowlink-for-fuzix6303-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/fuzix6303", + asmext=".asm", + binext=".exe", + assembler=buildcowasm6303, + ), + toolchain( + name="msdos", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-8086-with-ncgen", + cowlink="src/cowlink+cowlink-for-msdos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/msdos", + asmext=".asm", + binext=".exe", + assembler=buildnasm, + ), + toolchain( + name="ataritos", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-ataritos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/ataritos", + asmext=".asm", + binext=".tos", + assembler=buildgasataritos, + ), ] normalrule( diff --git a/src/cowasm/build.py b/src/cowasm/build.py new file mode 100644 index 00000000..b9a1eee4 --- /dev/null +++ b/src/cowasm/build.py @@ -0,0 +1,18 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol +from tools.newgen.build import newgencowgol + +ARCHS = ["8080", "pdp11", "6303", "tlcs90", "obp"] + +for toolchain in TOOLCHAINS: + toolchain.materialise() + for arch in ARCHS: + cowgol( + name="cowasm-for-" + arch + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "./arch" + arch + ".cow", + "./cowasm.coh", + "./stdsyms.coh", + ], + ) diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py index f42df92a..0208fe71 100644 --- a/third_party/djlink/build.py +++ b/third_party/djlink/build.py @@ -1,5 +1,5 @@ from build.c import cxxprogram -from build.ab2 import export +from build.ab2 import export, Rule, Targets, normalrule cxxprogram( name="objdump", @@ -49,3 +49,14 @@ "bin/djlink": "+djlink", }, ) + + +@Rule +def djlink(self, name, srcs: Targets() = []): + normalrule( + replaces=self, + ins=["+djlink"] + srcs, + outs=[self.localname + ".bin"], + commands=["{ins[0]} -o {outs} {ins[1]} > /dev/null"], + label="DJLINK", + ) From bb4f0374b52d3b9be98fb94e1917679fe5e7b812 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:45 +0000 Subject: [PATCH 23/40] Avoid a build cycle. Add tools to detect build cycles. --- build/ab2.py | 128 +++++++++++++++++++++++++-------------------- src/cowbe/build.py | 10 ++-- src/cowfe/build.py | 8 ++- 3 files changed, 85 insertions(+), 61 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index 6bfd0553..e12a41e9 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -17,6 +17,7 @@ defaultGlobals = {} targets = {} unmaterialisedTargets = set() +materialisingStack = [] outputFp = None emitter = None currentVars = None @@ -99,16 +100,25 @@ class Invocation: types = None ins = None outs = None - rawArgs = None + binding = None vars = None varsettings = None - def materialise(self): + def materialise(self, replacing=False): if self in unmaterialisedTargets: + if not replacing and (self in materialisingStack): + print("Found dependency cycle:") + for i in materialisingStack: + print(f" {i.name}") + print(f" {self.name}") + sys.exit(1) + + materialisingStack.append(self) + # Perform type conversion to the declared rule parameter types. self.args = {} - for k, v in self.rawArgs.items(): + for k, v in self.binding.arguments.items(): t = self.types.get(k, None) if t: v = t.convert(v, self) @@ -131,7 +141,12 @@ def materialise(self): # Actually call the callback. - self.callback(**self.args) + try: + self.callback(**self.args) + except BaseException as e: + print(f"Error materialising {self} ({id(self)}): {self.callback}") + print(f"Arguments: {self.args}") + raise e if not self.outs: raise ABException(f"{self.name} didn't set self.outs") @@ -141,10 +156,63 @@ def materialise(self): if self in unmaterialisedTargets: unmaterialisedTargets.remove(self) + materialisingStack.pop() + def __repr__(self): return "" % self.name +def Rule(func): + sig = inspect.signature(func) + + @functools.wraps(func) + def wrapper(*, name=None, replaces=None, **kwargs): + callername = inspect.stack()[1][0].f_globals["__name__"] + cwd = dirname(callername.replace(".", "/")) + + if name: + if ("+" in name) and not name.startswith("+"): + (cwd, target) = name.split("+", 1) + + i = Invocation() + if name.startswith("./"): + name = join(cwd, name) + elif "+" not in name: + name = cwd + "+" + name + + i.name = name + i.localname = name.split("+")[-1] + + if name in targets: + raise ABException(f"target {i.name} has already been defined") + targets[name] = i + elif replaces: + i = replaces + name = i.name + else: + raise ABException("you must supply either name or replaces") + + i.cwd = cwd + i.types = func.__annotations__ + i.callback = func + i.callerVars = currentVars + i.varsettings = kwargs.get("vars", None) + setattr(i, func.__name__, SimpleNamespace()) + + kwargs.pop("vars", None) + + i.binding = sig.bind(name=name, self=i, **kwargs) + i.binding.apply_defaults() + + unmaterialisedTargets.add(i) + if replaces: + i.materialise(replacing=True) + return i + + defaultGlobals[func.__name__] = wrapper + return wrapper + + class Type: pass @@ -350,58 +418,6 @@ def rule(self, name, ins, outs): emit("build", name, ": phony", unmake(ins)) -def Rule(func): - sig = inspect.signature(func) - - @functools.wraps(func) - def wrapper(*, name=None, replaces=None, **kwargs): - callername = inspect.stack()[1][0].f_globals["__name__"] - cwd = dirname(callername.replace(".", "/")) - - if name: - if ("+" in name) and not name.startswith("+"): - (cwd, target) = name.split("+", 1) - - i = Invocation() - if name.startswith("./"): - name = join(cwd, name) - elif "+" not in name: - name = cwd + "+" + name - - i.name = name - i.localname = name.split("+")[-1] - - if name in targets: - raise ABException(f"target {i.name} has already been defined") - targets[name] = i - elif replaces: - i = replaces - name = i.name - else: - raise ABException("you must supply either name or replaces") - - i.cwd = cwd - i.types = func.__annotations__ - i.callback = func - i.callerVars = currentVars - i.varsettings = kwargs.get("vars", None) - setattr(i, func.__name__, SimpleNamespace()) - - kwargs.pop("vars", None) - - bound = sig.bind(name=name, self=i, **kwargs) - bound.apply_defaults() - i.rawArgs = bound.arguments - - unmaterialisedTargets.add(i) - if replaces: - i.materialise() - return i - - defaultGlobals[func.__name__] = wrapper - return wrapper - - @Rule def simplerule( self, diff --git a/src/cowbe/build.py b/src/cowbe/build.py index b77abf20..56c634bb 100644 --- a/src/cowbe/build.py +++ b/src/cowbe/build.py @@ -1,4 +1,4 @@ -from build.ab2 import normalrule +from build.ab2 import normalrule, export from src.build import TOOLCHAINS, cowgol from tools.newgen.build import newgencowgol @@ -30,10 +30,12 @@ srcs=["src/cowbe/arch" + arch + ".cow.ng"] + extras.get(arch, []), ) +items = {} for toolchain in TOOLCHAINS: for arch in ARCHS: - cowgol( - name="cowbe-for-" + arch + "-with-" + toolchain.localname, + name = "cowbe-for-" + arch + "-with-" + toolchain.localname + items["bin/" + name] = cowgol( + name=name, toolchain=toolchain, srcs=[ "+gen-" + arch, @@ -53,3 +55,5 @@ "./utils.coh", ], ) + +export(name="cowbe", items=items) diff --git a/src/cowfe/build.py b/src/cowfe/build.py index 0bf00436..6468693e 100644 --- a/src/cowfe/build.py +++ b/src/cowfe/build.py @@ -1,4 +1,4 @@ -from build.ab2 import normalrule +from build.ab2 import normalrule, export from src.build import TOOLCHAINS, cowgol from third_party.lemon.build import lemoncowgol @@ -24,9 +24,11 @@ label="COPY", ) +items = {} for toolchain in TOOLCHAINS: for arch in ARCHS: - cowgol( + name="cowfe-for-" + arch + "-with-" + toolchain.localname + items[name] = cowgol( name="cowfe-for-" + arch + "-with-" + toolchain.localname, toolchain=toolchain, srcs=[ @@ -49,3 +51,5 @@ "src+midcodesfecoh", ], ) + + From b109e9655b5f510f85b2c169cd4acfc1e74a1c5f Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:45 +0000 Subject: [PATCH 24/40] Detect whether tools are available. --- Makefile | 6 +- build/ab2.py | 4 +- config.py | 14 +++ src/build.py | 264 +++++++++++++++++++++++++++------------------ src/cowfe/build.py | 4 +- 5 files changed, 180 insertions(+), 112 deletions(-) create mode 100644 config.py diff --git a/Makefile b/Makefile index 54c815f5..eb90513d 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,12 @@ clean: @echo CLEAN @rm -rf $(OBJ) bin -build-files = $(shell find . -name 'build.py') build/*.py +build-files = $(shell find . -name 'build.py') build/*.py config.py $(OBJ)/build.mk: Makefile $(build-files) @echo ACKBUILDER @mkdir -p $(OBJ) @python3 -X pycache_prefix=$(OBJ) build/ab2.py -m make -t +all -o $@ build.py + +.DELETE_ON_ERROR: +.SECONDARY: + diff --git a/build/ab2.py b/build/ab2.py index e12a41e9..ae1520e0 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -144,7 +144,9 @@ def materialise(self, replacing=False): try: self.callback(**self.args) except BaseException as e: - print(f"Error materialising {self} ({id(self)}): {self.callback}") + print( + f"Error materialising {self} ({id(self)}): {self.callback}" + ) print(f"Arguments: {self.args}") raise e if not self.outs: diff --git a/config.py b/config.py new file mode 100644 index 00000000..9020f2bd --- /dev/null +++ b/config.py @@ -0,0 +1,14 @@ +import os + + +def enable_if(command): + return os.system(f"command -v {command} > /dev/null") == 0 + + +has_gccataritos = enable_if("m68k-atari-mint-as") +has_nasm = enable_if("nasm") +has_gcc386 = enable_if("i686-linux-gnu-as") +has_gcc68k = enable_if("m68k-linux-gnu-as") +has_gccthumb2 = enable_if("arm-linux-gnueabihf-as") +has_gccpowerpc = enable_if("powerpc-linux-gnu-as") +has_tass64 = enable_if("64tass") diff --git a/src/build.py b/src/build.py index f1dabb67..089395f2 100644 --- a/src/build.py +++ b/src/build.py @@ -6,6 +6,7 @@ from build.tass64 import tass64 from build.nasm import nasm from third_party.djlink.build import djlink +import config @Rule @@ -206,7 +207,9 @@ def cowwrap( ) -TOOLCHAINS = [ +TOOLCHAINS = [] + +TOOLCHAINS.append( toolchain( name="ncgen", cowfe="bootstrap+cowfe", @@ -217,7 +220,10 @@ def cowwrap( asmext=".c", binext=".exe", assembler=cgen, - ), + ) +) + +TOOLCHAINS.append( toolchain( name="nncgen", cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", @@ -228,7 +234,10 @@ def cowwrap( asmext=".c", binext=".exe", assembler=cgen, - ), + ) +) + +TOOLCHAINS.append( toolchain( name="ncpm", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", @@ -239,7 +248,10 @@ def cowwrap( asmext=".asm", binext=".com", assembler=zmac, - ), + ) +) + +TOOLCHAINS.append( toolchain( name="ncpmz", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", @@ -250,84 +262,111 @@ def cowwrap( asmext=".z80", binext=".com", assembler=zmac, - ), - toolchain( - name="lxthumb2", - cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", - cowbe="src/cowbe+cowbe-for-thumb2-with-ncgen", - cowlink="src/cowlink+cowlink-for-lxthumb2-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lxthumb2", - asmext=".s", - binext=".exe", - assembler=buildgasarm, - ), - toolchain( - name="lx386", - cowfe="src/cowfe+cowfe-for-80386-with-nncgen", - cowbe="src/cowbe+cowbe-for-80386-with-ncgen", - cowlink="src/cowlink+cowlink-for-lx386-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lx386", - asmext=".s", - binext=".exe", - assembler=buildgas386, - ), - toolchain( - name="lx68k", - cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", - cowbe="src/cowbe+cowbe-for-68000-with-ncgen", - cowlink="src/cowlink+cowlink-for-lx68k-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lx68k", - asmext=".s", - binext=".exe", - assembler=buildgas68k, - ), - toolchain( - name="lxppc", - cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", - cowbe="src/cowbe+cowbe-for-powerpc-with-ncgen", - cowlink="src/cowlink+cowlink-for-lxppc-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lxppc", - asmext=".s", - binext=".exe", - assembler=buildgasppc, - ), - toolchain( - name="bbct", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-65c02-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - ), - toolchain( - name="bbctiny", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-65c02-tiny-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - ), - toolchain( - name="bbct6502", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-6502-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - ), + ) +) + +if config.has_gccthumb2: + TOOLCHAINS.append( + toolchain( + name="lxthumb2", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-thumb2-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxthumb2-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxthumb2", + asmext=".s", + binext=".exe", + assembler=buildgasarm, + ) + ) + +if config.has_gcc386: + TOOLCHAINS.append( + toolchain( + name="lx386", + cowfe="src/cowfe+cowfe-for-80386-with-nncgen", + cowbe="src/cowbe+cowbe-for-80386-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx386-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx386", + asmext=".s", + binext=".exe", + assembler=buildgas386, + ) + ) + +if config.has_gcc68k: + TOOLCHAINS.append( + toolchain( + name="lx68k", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx68k-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx68k", + asmext=".s", + binext=".exe", + assembler=buildgas68k, + ) + ) + +if config.has_gccpowerpc: + TOOLCHAINS.append( + toolchain( + name="lxppc", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-powerpc-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxppc-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxppc", + asmext=".s", + binext=".exe", + assembler=buildgasppc, + ) + ) + +if config.has_tass64: + TOOLCHAINS.append( + toolchain( + name="bbct", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ) + ) + TOOLCHAINS.append( + toolchain( + name="bbctiny", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-tiny-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ) + ) + TOOLCHAINS.append( + toolchain( + name="bbct6502", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-6502-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + ) + ) + +TOOLCHAINS.append( toolchain( name="unixv7", cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", @@ -338,7 +377,10 @@ def cowwrap( asmext=".asm", binext=".exe", assembler=buildcowasmpdp11, - ), + ) +) + +TOOLCHAINS.append( toolchain( name="fuzix6303", cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", @@ -349,30 +391,38 @@ def cowwrap( asmext=".asm", binext=".exe", assembler=buildcowasm6303, - ), - toolchain( - name="msdos", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-8086-with-ncgen", - cowlink="src/cowlink+cowlink-for-msdos-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/msdos", - asmext=".asm", - binext=".exe", - assembler=buildnasm, - ), - toolchain( - name="ataritos", - cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", - cowbe="src/cowbe+cowbe-for-68000-with-ncgen", - cowlink="src/cowlink+cowlink-for-ataritos-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/ataritos", - asmext=".asm", - binext=".tos", - assembler=buildgasataritos, - ), -] + ) +) + +if config.has_nasm: + TOOLCHAINS.append( + toolchain( + name="msdos", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-8086-with-ncgen", + cowlink="src/cowlink+cowlink-for-msdos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/msdos", + asmext=".asm", + binext=".exe", + assembler=buildnasm, + ) + ) + +if config.has_gccataritos: + TOOLCHAINS.append( + toolchain( + name="ataritos", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-ataritos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/ataritos", + asmext=".asm", + binext=".tos", + assembler=buildgasataritos, + ) + ) normalrule( name="midcodesfecoh", diff --git a/src/cowfe/build.py b/src/cowfe/build.py index 6468693e..88004c42 100644 --- a/src/cowfe/build.py +++ b/src/cowfe/build.py @@ -27,7 +27,7 @@ items = {} for toolchain in TOOLCHAINS: for arch in ARCHS: - name="cowfe-for-" + arch + "-with-" + toolchain.localname + name = "cowfe-for-" + arch + "-with-" + toolchain.localname items[name] = cowgol( name="cowfe-for-" + arch + "-with-" + toolchain.localname, toolchain=toolchain, @@ -51,5 +51,3 @@ "src+midcodesfecoh", ], ) - - From ee02d1ffbbb2c64517609f25e86b92b0ed27e7f3 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:46 +0000 Subject: [PATCH 25/40] Update build script --- .github/workflows/ccpp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 7c5811d0..d8af975a 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -4,7 +4,7 @@ on: [push] jobs: build-linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: apt update @@ -12,7 +12,7 @@ jobs: - name: add-apt-repository run: sudo add-apt-repository ppa:vriviere/ppa -y - name: apt - run: sudo apt install ninja-build lua5.1 pasmo libz80ex-dev flex libbsd-dev libreadline-dev bison binutils-arm-linux-gnueabihf binutils-i686-linux-gnu binutils-powerpc-linux-gnu binutils-m68k-atari-mint binutils-m68k-linux-gnu qemu-user gpp 64tass libfl-dev nasm + run: sudo apt install ninja-build lua5.1 libz80ex-dev flex libbsd-dev libreadline-dev bison binutils-arm-linux-gnueabihf binutils-i686-linux-gnu binutils-powerpc-linux-gnu binutils-m68k-atari-mint binutils-m68k-linux-gnu qemu-user gpp 64tass libfl-dev nasm - name: make run: make NINJAFLAGS=-k1 From bb23c082c30a7a96e9ffcf13f79856eb9f59af02 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:46 +0000 Subject: [PATCH 26/40] Actually run some tests. --- build.py | 4 +- src/build.py | 48 ++++++++++++++++++++++- tests/build.py | 87 ++++++++++++++++++++++++++++++++++++++++++ tools/tubeemu/build.py | 2 +- 4 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 tests/build.py diff --git a/build.py b/build.py index c1adfa54..adf90293 100644 --- a/build.py +++ b/build.py @@ -4,7 +4,7 @@ export( name="all", items={ - "bin/bbctube": "tools/tubeemu+bbctube", + "bin/tubeemu": "tools/tubeemu", "bin/obpemu": "tools/obpemu", "bin/mkadfs": "tools+mkadfs", "bin/mkdfs": "tools+mkdfs", @@ -16,5 +16,5 @@ "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", }, - deps=["third_party/djlink+djlink-programs", "examples"], + deps=["third_party/djlink+djlink-programs", "examples", "tests"], ) diff --git a/src/build.py b/src/build.py index 089395f2..3130bb5c 100644 --- a/src/build.py +++ b/src/build.py @@ -1,4 +1,12 @@ -from build.ab2 import Rule, Target, Targets, export, normalrule, filenamesof +from build.ab2 import ( + Rule, + Target, + Targets, + export, + normalrule, + filenamesof, + filenameof, +) from build.c import cprogram from os.path import * from third_party.zmac.build import zmac @@ -83,6 +91,39 @@ def buildnasm(self, name, srcs: Targets() = None): djlink(replaces=self, srcs=[o]) +def testimpl(self, runner): + goodfile = self.args["goodfile"] + normalrule( + replaces=self, + ins=[self.args["exe"]], + outs=[self.localname + ".bad"], + commands=[ + "timeout 5s " + runner + " {ins} > {outs}; true", + "diff -u -w {outs[0]} " + filenameof(goodfile), + ], + label="TEST", + ) + + +@Rule +def nativetest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, "") + + +@Rule +def tubeemutest(self, name, goodfile: Target() = None, exe: Target() = None): + normalrule( + replaces=self, + ins=["tools/tubeemu", self.args["exe"], goodfile], + outs=[self.localname + ".bad"], + commands=[ + "timeout 5s {ins[0]} -l 0x400 -e 0x400 -f {ins[1]} > {outs}; true", + "diff -u -w {outs[0]} " + filenameof(goodfile), + ], + label="TEST", + ) + + @Rule def toolchain( self, @@ -95,6 +136,7 @@ def toolchain( asmext=None, binext=None, assembler=None, + tester=None, ): id = self.localname @@ -234,6 +276,7 @@ def cowwrap( asmext=".c", binext=".exe", assembler=cgen, + tester=nativetest, ) ) @@ -337,6 +380,7 @@ def cowwrap( asmext=".asm", binext=".bin", assembler=buildtass64, + tester=tubeemutest, ) ) TOOLCHAINS.append( @@ -350,6 +394,7 @@ def cowwrap( asmext=".asm", binext=".bin", assembler=buildtass64, + tester=tubeemutest, ) ) TOOLCHAINS.append( @@ -363,6 +408,7 @@ def cowwrap( asmext=".asm", binext=".bin", assembler=buildtass64, + tester=tubeemutest, ) ) diff --git a/tests/build.py b/tests/build.py new file mode 100644 index 00000000..1bfd7312 --- /dev/null +++ b/tests/build.py @@ -0,0 +1,87 @@ +from build.ab2 import normalrule, Rule, Target, export +from src.build import TOOLCHAINS, cowgol + +TESTS = [ + "addsub-16bit", + "addsub-32bit", + "addsub-8bit", + "atoi", + "arrayinitialisers", + "case", + "casts", + "conditionals", + "divrem-16bit-s", + "divrem-16bit-u", + "divrem-32bit-s", + "divrem-32bit-u", + "divrem-8bit-s", + "divrem-8bit-u", + # "empty", # causes qemu to crash, but works on real hardware + "fileio", + "folding", + "forwards", + "inputparams", + "interfaces", + "itoa", + "logic-16bit", + "logic-32bit", + "logic-8bit", + "loops", + "lvalues", + "malloc", + "mul-16bit-s", + "mul-16bit-u", + "mul-32bit-s", + "mul-32bit-u", + "mul-8bit-s", + "mul-8bit-u", + "nested-calls", + "outputparams", + "passto", + "pointers", + "rangetypes", + "recordinitialisers", + "records", + "regalloc", + "shifts-16bit", + "shifts-32bit", + "shifts-8bit", + "unions", +] + + +@Rule +def testsuite(self, name, toolchain: Target() = None): + tests = [] + if toolchain.tester: + for test in TESTS: + bin = cowgol( + name=name + "/" + test + "/bin", + srcs=["./" + test + ".test.cow"], + toolchain=toolchain, + ) + + tests.append( + toolchain.tester( + name=name + "/" + test, + goodfile="./" + test + ".good", + exe=bin, + ) + ) + + normalrule( + replaces=self, + ins=tests, + outs=["stamp"], + commands=["touch {outs}"], + label="TESTSUITE", + ) + + +export( + name="tests", + deps=[ + testsuite(name="tests-" + toolchain.localname, toolchain=toolchain) + for toolchain in TOOLCHAINS + ], +) diff --git a/tools/tubeemu/build.py b/tools/tubeemu/build.py index c81391ae..fee3995f 100644 --- a/tools/tubeemu/build.py +++ b/tools/tubeemu/build.py @@ -1,3 +1,3 @@ from build.c import cprogram -cprogram(name="bbctube", srcs=["./bbctube.c"], deps=["third_party/lib6502"]) +cprogram(name="tubeemu", srcs=["./bbctube.c"], deps=["third_party/lib6502"]) From 37683683fbd3acbbba9a60ac9e31c481dc9ae392 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:46 +0000 Subject: [PATCH 27/40] Don't use inspect in the critical path; massive performance boosts. This does change the semantics very slightly but I can live with that. --- build/ab2.py | 30 ++++++++++++------------------ third_party/djlink/build.py | 2 +- third_party/lemon/build.py | 4 ++-- tools/newgen/build.py | 2 +- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index ae1520e0..fdae4622 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -13,6 +13,7 @@ import types import pathlib import builtins +import cProfile defaultGlobals = {} targets = {} @@ -21,6 +22,7 @@ outputFp = None emitter = None currentVars = None +cwdStack = [""] sys.path += ["."] old_import = builtins.__import__ @@ -38,7 +40,9 @@ def new_import(name, *args, **kwargs): ) module = importlib.util.module_from_spec(spec) sys.modules[name] = module + cwdStack.append(dirname(path)) spec.loader.exec_module(module) + cwdStack.pop() return old_import(name, *args, **kwargs) @@ -142,7 +146,9 @@ def materialise(self, replacing=False): # Actually call the callback. try: + cwdStack.append(self.cwd) self.callback(**self.args) + cwdStack.pop() except BaseException as e: print( f"Error materialising {self} ({id(self)}): {self.callback}" @@ -169,13 +175,14 @@ def Rule(func): @functools.wraps(func) def wrapper(*, name=None, replaces=None, **kwargs): - callername = inspect.stack()[1][0].f_globals["__name__"] - cwd = dirname(callername.replace(".", "/")) - + cwd = None if name: if ("+" in name) and not name.startswith("+"): - (cwd, target) = name.split("+", 1) + (cwd, _) = name.split("+", 1) + if not cwd: + cwd = cwdStack[-1] + if name: i = Invocation() if name.startswith("./"): name = join(cwd, name) @@ -270,20 +277,6 @@ def recurse(xs): return list(recurse(xs)) -def massagefilename(s): - callername = inspect.stack()[1][0].f_globals["__name__"] - cwd = dirname(callername.replace(".", "/")) - - if ("+" in name) and not name.startswith("+"): - (cwd, target) = name.split("+", 1) - - i = Invocation() - if name.startswith("./"): - name = join(cwd, name) - elif "+" not in name: - name = cwd + "+" + name - - def fileinvocation(s): i = Invocation() i.name = "(anonymous)" @@ -546,3 +539,4 @@ def main(): main() +#cProfile.run("main()", sort="tottime") diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py index 0208fe71..a41d68b3 100644 --- a/third_party/djlink/build.py +++ b/third_party/djlink/build.py @@ -55,7 +55,7 @@ def djlink(self, name, srcs: Targets() = []): normalrule( replaces=self, - ins=["+djlink"] + srcs, + ins=["third_party/djlink"] + srcs, outs=[self.localname + ".bin"], commands=["{ins[0]} -o {outs} {ins[1]} > /dev/null"], label="DJLINK", diff --git a/third_party/lemon/build.py b/third_party/lemon/build.py index 5d865059..43bae3f2 100644 --- a/third_party/lemon/build.py +++ b/third_party/lemon/build.py @@ -16,7 +16,7 @@ def lemon(self, name, src: Target() = None): normalrule( replaces=self, - ins=["+lemon", "./lempar.c", src], + ins=["third_party/lemon+lemon", "third_party/lemon/lempar.c", src], outs=[self.localname + ".c", self.localname + ".h"], commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], label="LEMON", @@ -27,7 +27,7 @@ def lemon(self, name, src: Target() = None): def lemoncowgol(self, name, src: Target() = None): normalrule( replaces=self, - ins=["+lemon-cowgol", "src/cowfe/lempar.coh", src], + ins=["third_party/lemon+lemon-cowgol", "src/cowfe/lempar.coh", src], outs=[self.localname + ".coh", self.localname + ".tokens.coh"], commands=["{ins[0]} -T{ins[1]} -d{dirname(outs[0])} {ins[2]}"], label="LEMON-COWGOL", diff --git a/tools/newgen/build.py b/tools/newgen/build.py index 10311d26..f3c5541a 100644 --- a/tools/newgen/build.py +++ b/tools/newgen/build.py @@ -28,7 +28,7 @@ def newgencowgol(self, name, srcs: Targets() = []): normalrule( replaces=self, - ins=["+newgen", preprocessed], + ins=["tools/newgen", preprocessed], outs=["inssel.coh", "inssel.decl.coh"], commands=["{ins[0]} {ins[1]} {outs[0]} {outs[1]}"], label="NEWGEN", From 6a405b17cef744353252576043bbaafbe9021bee Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:46 +0000 Subject: [PATCH 28/40] Lots more test suites work. --- src/build.py | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/build.py b/src/build.py index 3130bb5c..cb1ad7f3 100644 --- a/src/build.py +++ b/src/build.py @@ -91,14 +91,14 @@ def buildnasm(self, name, srcs: Targets() = None): djlink(replaces=self, srcs=[o]) -def testimpl(self, runner): +def testimpl(self, dep, command): goodfile = self.args["goodfile"] normalrule( replaces=self, - ins=[self.args["exe"]], + ins=dep + [self.args["exe"]], outs=[self.localname + ".bad"], commands=[ - "timeout 5s " + runner + " {ins} > {outs}; true", + "timeout 5s " + command + " > {outs}; true", "diff -u -w {outs[0]} " + filenameof(goodfile), ], label="TEST", @@ -107,21 +107,32 @@ def testimpl(self, runner): @Rule def nativetest(self, name, goodfile: Target() = None, exe: Target() = None): - testimpl(self, "") + testimpl(self, [], "{ins[0]}") @Rule def tubeemutest(self, name, goodfile: Target() = None, exe: Target() = None): - normalrule( - replaces=self, - ins=["tools/tubeemu", self.args["exe"], goodfile], - outs=[self.localname + ".bad"], - commands=[ - "timeout 5s {ins[0]} -l 0x400 -e 0x400 -f {ins[1]} > {outs}; true", - "diff -u -w {outs[0]} " + filenameof(goodfile), - ], - label="TEST", - ) + testimpl(self, ["tools/tubeemu"], "{ins[0]} -l 0x400 -e 0x400 -f {ins[1]}") + + +@Rule +def cpmtest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, ["tools/cpmemu"], "{ins[0]} {ins[1]}") + + +@Rule +def apouttest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, ["third_party/apout"], "{ins[0]} {ins[1]}") + + +@Rule +def fuzix6303test(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, ["tools/fuzix6303emu"], "{ins[0]} -f {ins[1]}") + + +@Rule +def ataritostest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, ["tools/ataritosemu"], "{ins[0]} {ins[1]}") @Rule @@ -291,6 +302,7 @@ def cowwrap( asmext=".asm", binext=".com", assembler=zmac, + tester=cpmtest, ) ) @@ -305,6 +317,7 @@ def cowwrap( asmext=".z80", binext=".com", assembler=zmac, + tester=cpmtest, ) ) @@ -423,6 +436,7 @@ def cowwrap( asmext=".asm", binext=".exe", assembler=buildcowasmpdp11, + tester=apouttest, ) ) @@ -437,6 +451,7 @@ def cowwrap( asmext=".asm", binext=".exe", assembler=buildcowasm6303, + tester=fuzix6303test, ) ) @@ -467,6 +482,7 @@ def cowwrap( asmext=".asm", binext=".tos", assembler=buildgasataritos, + tester=ataritostest ) ) From d1acd90009881c9b04b6160769e996008e4c5987 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:47 +0000 Subject: [PATCH 29/40] Add the rest of the tests. Is it all done now? --- build/ab2.py | 2 +- config.py | 4 ++++ src/build.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/build/ab2.py b/build/ab2.py index fdae4622..e104418f 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -539,4 +539,4 @@ def main(): main() -#cProfile.run("main()", sort="tottime") +# cProfile.run("main()", sort="tottime") diff --git a/config.py b/config.py index 9020f2bd..c3642d97 100644 --- a/config.py +++ b/config.py @@ -12,3 +12,7 @@ def enable_if(command): has_gccthumb2 = enable_if("arm-linux-gnueabihf-as") has_gccpowerpc = enable_if("powerpc-linux-gnu-as") has_tass64 = enable_if("64tass") +has_qemuarm = enable_if("qemu-arm") +has_qemu386 = enable_if("qemu-i386") +has_qemuppc = enable_if("qemu-ppc") +has_qemu68k = enable_if("qemu-m68k") diff --git a/src/build.py b/src/build.py index cb1ad7f3..a9710df7 100644 --- a/src/build.py +++ b/src/build.py @@ -135,6 +135,31 @@ def ataritostest(self, name, goodfile: Target() = None, exe: Target() = None): testimpl(self, ["tools/ataritosemu"], "{ins[0]} {ins[1]}") +@Rule +def qemuarmtest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, [], "qemu-arm {ins[0]}") + + +@Rule +def qemu386test(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, [], "qemu-i386 {ins[0]}") + + +@Rule +def qemu68ktest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, [], "qemu-m68k {ins[0]}") + + +@Rule +def qemuppctest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, [], "qemu-ppc {ins[0]}") + + +@Rule +def msdostest(self, name, goodfile: Target() = None, exe: Target() = None): + testimpl(self, ["third_party/emu2"], "{ins[0]} {ins[1]}") + + @Rule def toolchain( self, @@ -333,6 +358,7 @@ def cowwrap( asmext=".s", binext=".exe", assembler=buildgasarm, + tester=qemuarmtest if config.has_qemuarm else None, ) ) @@ -348,6 +374,7 @@ def cowwrap( asmext=".s", binext=".exe", assembler=buildgas386, + tester=qemu386test if config.has_qemu386 else None, ) ) @@ -363,6 +390,7 @@ def cowwrap( asmext=".s", binext=".exe", assembler=buildgas68k, + tester=qemu68ktest if config.has_qemu68k else None, ) ) @@ -378,6 +406,7 @@ def cowwrap( asmext=".s", binext=".exe", assembler=buildgasppc, + tester=qemuppctest if config.has_qemuppc else None, ) ) @@ -467,6 +496,7 @@ def cowwrap( asmext=".asm", binext=".exe", assembler=buildnasm, + tester=msdostest, ) ) @@ -482,7 +512,7 @@ def cowwrap( asmext=".asm", binext=".tos", assembler=buildgasataritos, - tester=ataritostest + tester=ataritostest, ) ) From da6c308e3d9581ec141bfab98c040a0a4067efc1 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:47 +0000 Subject: [PATCH 30/40] Build some more small things. --- build.py | 3 +++ src/cowbdmp/build.py | 14 ++++++++++++++ src/cowdis/build.py | 14 ++++++++++++++ src/misc/build.py | 14 ++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/cowbdmp/build.py create mode 100644 src/cowdis/build.py create mode 100644 src/misc/build.py diff --git a/build.py b/build.py index adf90293..ef8b4c63 100644 --- a/build.py +++ b/build.py @@ -15,6 +15,9 @@ "bin/ataritosemu": "tools/ataritosemu", "bin/lx68kemu": "tools/lx68kemu", "bin/fuzix6303emu": "tools/fuzix6303emu", + "bin/cowdis-tlcs90": "src/cowdis+cowdis-for-tlcs90-with-nncgen", + "bin/cowbdmp": "src/cowbdmp+cowbdmp-with-nncgen", + "bin/basicify": "src/misc+basicify-with-nncgen", }, deps=["third_party/djlink+djlink-programs", "examples", "tests"], ) diff --git a/src/cowbdmp/build.py b/src/cowbdmp/build.py new file mode 100644 index 00000000..81b97c7a --- /dev/null +++ b/src/cowbdmp/build.py @@ -0,0 +1,14 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol + +for toolchain in TOOLCHAINS: + cowgol( + name="cowbdmp-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "./main.cow", + "./types.coh", + "src+midcodesbecoh", + "src+cobincoh", + ], + ) diff --git a/src/cowdis/build.py b/src/cowdis/build.py new file mode 100644 index 00000000..09b7240f --- /dev/null +++ b/src/cowdis/build.py @@ -0,0 +1,14 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol + +ARCHS = ["tlcs90"] + +for toolchain in TOOLCHAINS: + for arch in ARCHS: + cowgol( + name="cowdis-for-" + arch + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "./arch" + arch + ".cow", + ], + ) diff --git a/src/misc/build.py b/src/misc/build.py new file mode 100644 index 00000000..7b8b84de --- /dev/null +++ b/src/misc/build.py @@ -0,0 +1,14 @@ +from build.ab2 import normalrule +from src.build import TOOLCHAINS, cowgol + +PROGRAMS = ["basicify"] + +for toolchain in TOOLCHAINS: + for program in PROGRAMS: + cowgol( + name=program + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "./" + program + ".cow", + ], + ) From d43a5074860a79dc03a207e9763392231e1d38b2 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:47 +0000 Subject: [PATCH 31/40] Build a bunch of distributions. --- build.py | 12 ++++++++++-- dist/ataritos/build.py | 17 +++++++++++++++++ dist/cpm/build.py | 18 ++++++++++++++++++ dist/cpmz/build.py | 18 ++++++++++++++++++ dist/cpmz/tocpm.lua | 5 ----- dist/msdos/build.py | 15 +++++++++++++++ tools/build.py | 11 +++++++++++ {dist/cpm => tools}/tocpm.lua | 0 8 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 dist/ataritos/build.py create mode 100644 dist/cpm/build.py create mode 100644 dist/cpmz/build.py delete mode 100644 dist/cpmz/tocpm.lua create mode 100644 dist/msdos/build.py rename {dist/cpm => tools}/tocpm.lua (100%) diff --git a/build.py b/build.py index ef8b4c63..8a82b75c 100644 --- a/build.py +++ b/build.py @@ -1,5 +1,6 @@ from build.ab2 import Rule, export from os.path import * +import config export( name="all", @@ -19,5 +20,12 @@ "bin/cowbdmp": "src/cowbdmp+cowbdmp-with-nncgen", "bin/basicify": "src/misc+basicify-with-nncgen", }, - deps=["third_party/djlink+djlink-programs", "examples", "tests"], -) + deps=[ + "third_party/djlink+djlink-programs", + "examples", + "tests", + "dist/cpmz", + "dist/cpm", + ] + + (["dist/msdos"] if config.has_nasm else []) + + (["dist/ataritos"] if config.has_gcc68k else [])) diff --git a/dist/ataritos/build.py b/dist/ataritos/build.py new file mode 100644 index 00000000..8f5edcb6 --- /dev/null +++ b/dist/ataritos/build.py @@ -0,0 +1,17 @@ +from build.ab2 import export +from tools.build import tocpm + +tocpm(name="demosub", src="./demo.sub") + +export( + name="ataritos", + items={ + "bin/dist/ataritos/mandel.cow": "examples/mandel.cow", + "bin/dist/ataritos/cowgol.coh": "rt/ataritos/cowgol.coh", + "bin/dist/ataritos/common.coh": "rt/common.coh", + "bin/dist/ataritos/cowgol.coo": "rt/ataritos+cowgolcoo", + "bin/dist/ataritos/cowfe.com": "src/cowfe+cowfe-for-32bita2-with-ataritos", + "bin/dist/ataritos/cowbe.com": "src/cowbe+cowbe-for-68000-with-ataritos", + "bin/dist/ataritos/cowlink.com": "src/cowlink+cowlink-for-ataritos-with-ataritos", + }, +) diff --git a/dist/cpm/build.py b/dist/cpm/build.py new file mode 100644 index 00000000..4112cfdf --- /dev/null +++ b/dist/cpm/build.py @@ -0,0 +1,18 @@ +from build.ab2 import export +from tools.build import tocpm + +tocpm(name="demosub", src="./demo.sub") + +export( + name="cpm", + items={ + "bin/dist/cpm/demo.sub": "+demosub", + "bin/dist/cpm/mandel.cow": "examples/mandel.cow", + "bin/dist/cpm/cowgol.coh": "rt/cpm/cowgol.coh", + "bin/dist/cpm/common.coh": "rt/common.coh", + "bin/dist/cpm/cowgol.coo": "rt/cpm+cowgolcoo", + "bin/dist/cpm/cowfe.com": "src/cowfe+cowfe-for-16bit-with-ncpm", + "bin/dist/cpm/cowbe.com": "src/cowbe+cowbe-for-8080-with-ncpm", + "bin/dist/cpm/cowlink.com": "src/cowlink+cowlink-for-8080-with-ncpm", + }, +) diff --git a/dist/cpmz/build.py b/dist/cpmz/build.py new file mode 100644 index 00000000..d03a1a24 --- /dev/null +++ b/dist/cpmz/build.py @@ -0,0 +1,18 @@ +from build.ab2 import export +from tools.build import tocpm + +tocpm(name="demosub", src="./demo.sub") + +export( + name="cpmz", + items={ + "bin/dist/cpmz/demo.sub": "+demosub", + "bin/dist/cpmz/mandel.cow": "examples/mandel.cow", + "bin/dist/cpmz/cowgol.coh": "rt/cpmz/cowgol.coh", + "bin/dist/cpmz/common.coh": "rt/common.coh", + "bin/dist/cpmz/cowgol.coo": "rt/cpmz+cowgolcoo", + "bin/dist/cpmz/cowfe.com": "src/cowfe+cowfe-for-16bit-with-ncpmz", + "bin/dist/cpmz/cowbe.com": "src/cowbe+cowbe-for-z80-with-ncpmz", + "bin/dist/cpmz/cowlink.com": "src/cowlink+cowlink-for-8080-with-ncpmz", + }, +) diff --git a/dist/cpmz/tocpm.lua b/dist/cpmz/tocpm.lua deleted file mode 100644 index 1176c6f2..00000000 --- a/dist/cpmz/tocpm.lua +++ /dev/null @@ -1,5 +0,0 @@ -for l in io.stdin:lines() do - io.write(l, "\r\n") -end -io.write(string.char(26)) - diff --git a/dist/msdos/build.py b/dist/msdos/build.py new file mode 100644 index 00000000..f0ba8c9d --- /dev/null +++ b/dist/msdos/build.py @@ -0,0 +1,15 @@ +from build.ab2 import export + +export( + name="msdos", + items={ + "bin/dist/msdos/demo.bat": "./demo.bat", + "bin/dist/msdos/mandel.cow": "examples/mandel.cow", + "bin/dist/msdos/cowgol.coh": "rt/msdos/cowgol.coh", + "bin/dist/msdos/common.coh": "rt/common.coh", + "bin/dist/msdos/cowgol.coo": "rt/msdos+cowgolcoo", + "bin/dist/msdos/cowfe.exe": "src/cowfe+cowfe-for-16bit-with-msdos", + "bin/dist/msdos/cowbe.exe": "src/cowbe+cowbe-for-8086-with-msdos", + "bin/dist/msdos/cowlink.exe": "src/cowlink+cowlink-for-msdos-with-msdos", + }, +) diff --git a/tools/build.py b/tools/build.py index bcb4882f..c69bf232 100644 --- a/tools/build.py +++ b/tools/build.py @@ -21,3 +21,14 @@ def objectify(self, name, src: Target() = None, symbol=None): commands=["lua {ins[0]} " + symbol + " < {ins[1]} > {outs}"], label="OBJECTIFY", ) + + +@Rule +def tocpm(self, name, src: Target() = None): + normalrule( + replaces=self, + ins=["tools/tocpm.lua", src], + outs=[self.localname + ".txt"], + commands=["lua {ins[0]} < {ins[1]} > {outs}"], + label="TOCPM", + ) diff --git a/dist/cpm/tocpm.lua b/tools/tocpm.lua similarity index 100% rename from dist/cpm/tocpm.lua rename to tools/tocpm.lua From 45afd0cd012659bcde6585c1f38883d7659673cb Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:48 +0000 Subject: [PATCH 32/40] Rework types. Built the bbct distribution. --- build.py | 4 ++- build/ab2.py | 42 ++++++++-------------- build/c.py | 22 ++++++------ build/gpp.py | 2 +- build/nasm.py | 2 +- build/tass64.py | 2 +- build/yacc.py | 4 +-- dist/bbct/build.py | 68 ++++++++++++++++++++++++++++++++++++ src/build.py | 68 +++++++++++++++++------------------- tests/build.py | 2 +- third_party/djlink/build.py | 2 +- third_party/lemon/build.py | 4 +-- third_party/musashi/build.py | 2 +- third_party/zmac/build.py | 2 +- tools/build.py | 26 ++++++++++++-- tools/newgen/build.py | 2 +- 16 files changed, 165 insertions(+), 89 deletions(-) create mode 100644 dist/bbct/build.py diff --git a/build.py b/build.py index 8a82b75c..d29da7ed 100644 --- a/build.py +++ b/build.py @@ -28,4 +28,6 @@ "dist/cpm", ] + (["dist/msdos"] if config.has_nasm else []) - + (["dist/ataritos"] if config.has_gcc68k else [])) + + (["dist/ataritos"] if config.has_gcc68k else []) + + (["dist/bbct"] if config.has_tass64 else []), +) diff --git a/build/ab2.py b/build/ab2.py index e104418f..45b25e12 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -13,7 +13,6 @@ import types import pathlib import builtins -import cProfile defaultGlobals = {} targets = {} @@ -125,7 +124,7 @@ def materialise(self, replacing=False): for k, v in self.binding.arguments.items(): t = self.types.get(k, None) if t: - v = t.convert(v, self) + v = t(v).convert(self) self.args[k] = v # Create a new variable frame and set any variables. @@ -223,25 +222,13 @@ def wrapper(*, name=None, replaces=None, **kwargs): class Type: - pass - - -class String(Type): - def convert(self, value, invocation): - if type(value) != "string": - raise ABException("rule wanted a String, but got a " + type(value)) - return value - - -class Strings(Type): - def convert(self, value, invocation): - if type(value) == "string": - value = [value] - return value + def __init__(self, value): + self.value = value class Targets(Type): - def convert(self, value, invocation): + def convert(self, invocation): + value = self.value if type(value) is str: value = [value] if type(value) is list: @@ -250,14 +237,16 @@ def convert(self, value, invocation): class Target(Type): - def convert(self, value, invocation): + def convert(self, invocation): + value = self.value if not value: return None return targetof(value, cwd=invocation.cwd) class TargetsMap(Type): - def convert(self, value, invocation): + def convert(self, invocation): + value = self.value if type(value) is dict: return { targetof(k, cwd=invocation.cwd): targetof(v, cwd=invocation.cwd) @@ -417,10 +406,10 @@ def rule(self, name, ins, outs): def simplerule( self, name, - ins: Targets() = [], + ins: Targets = [], outs=[], - deps: Targets() = [], - commands: Strings() = [], + deps: Targets = [], + commands=[], label="RULE", ): self.ins = ins @@ -441,8 +430,8 @@ def simplerule( def normalrule( self, name=None, - ins: Targets() = [], - deps: Targets() = [], + ins: Targets = [], + deps: Targets = [], outs=[], label="RULE", objdir=None, @@ -461,7 +450,7 @@ def normalrule( @Rule -def export(self, name=None, items: TargetsMap() = {}, deps: Targets() = []): +def export(self, name=None, items: TargetsMap = {}, deps: Targets = []): emitter.rule( self.name, flatten(items.values()), @@ -539,4 +528,3 @@ def main(): main() -# cProfile.run("main()", sort="tottime") diff --git a/build/c.py b/build/c.py index 9eae78f2..6ce13890 100644 --- a/build/c.py +++ b/build/c.py @@ -43,8 +43,8 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): def cfile( self, name, - srcs: Targets() = [], - deps: Targets() = [], + srcs: Targets = [], + deps: Targets = [], suffix=".o", commands=["$(CC) -c -o {outs[0]} {ins[0]} {vars.cflags}"], label="CC", @@ -58,8 +58,8 @@ def cfile( def cxxfile( self, name, - srcs: Targets() = [], - deps: Targets() = [], + srcs: Targets = [], + deps: Targets = [], suffix=".o", commands=["$(CXX) -c -o {outs[0]} {ins[0]} {vars.cxxflags}"], label="CXX", @@ -87,9 +87,9 @@ def findsources(name, srcs, deps): def clibrary( self, name, - srcs: Targets() = [], - deps: Targets() = [], - hdrs: Targets() = [], + srcs: Targets = [], + deps: Targets = [], + hdrs: Targets = [], commands=["$(AR) cqs {outs[0]} {ins}"], label="AR", ): @@ -132,8 +132,8 @@ def programimpl(self, name, srcs, deps, commands, label, filerule, kind): def cprogram( self, name, - srcs: Targets() = [], - deps: Targets() = [], + srcs: Targets = [], + deps: Targets = [], commands=["$(CC) -o {outs[0]} {ins} {vars.ldflags}"], label="CLINK", ): @@ -144,8 +144,8 @@ def cprogram( def cxxprogram( self, name, - srcs: Targets() = [], - deps: Targets() = [], + srcs: Targets = [], + deps: Targets = [], commands=["$(CXX) -o {outs[0]} {ins} {vars.ldflags}"], label="CXXLINK", ): diff --git a/build/gpp.py b/build/gpp.py index ff95f0b2..4c87b5eb 100644 --- a/build/gpp.py +++ b/build/gpp.py @@ -3,7 +3,7 @@ @Rule -def gpp(self, name, srcs: Targets() = []): +def gpp(self, name, srcs: Targets = []): hdrs = set(["-I" + dirname(f) for f in filenamesof(srcs)]) normalrule( diff --git a/build/nasm.py b/build/nasm.py index 8e38a04c..74174ed1 100644 --- a/build/nasm.py +++ b/build/nasm.py @@ -2,7 +2,7 @@ @Rule -def nasm(self, name, srcs: Targets() = []): +def nasm(self, name, srcs: Targets = []): normalrule( replaces=self, ins=srcs, diff --git a/build/tass64.py b/build/tass64.py index f0a31283..28ae843f 100644 --- a/build/tass64.py +++ b/build/tass64.py @@ -2,7 +2,7 @@ @Rule -def tass64(self, name, srcs: Targets() = []): +def tass64(self, name, srcs: Targets = []): normalrule( replaces=self, ins=srcs, diff --git a/build/yacc.py b/build/yacc.py index e14f09ce..39481c54 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -2,7 +2,7 @@ @Rule -def yacc(self, name, srcs: Targets() = []): +def yacc(self, name, srcs: Targets = []): normalrule( replaces=self, ins=srcs, @@ -13,7 +13,7 @@ def yacc(self, name, srcs: Targets() = []): @Rule -def flex(self, name, srcs: Targets() = []): +def flex(self, name, srcs: Targets = []): normalrule( replaces=self, ins=srcs, diff --git a/dist/bbct/build.py b/dist/bbct/build.py new file mode 100644 index 00000000..a650bed3 --- /dev/null +++ b/dist/bbct/build.py @@ -0,0 +1,68 @@ +from build.ab2 import export, Rule, Target, normalrule +from tools.build import tocpm, mkdfs + + +@Rule +def bbcify(self, name, src: Target = None): + normalrule( + replaces=self, + ins=[src], + outs=[self.localname + ".txt"], + commands=[ + r"""sed -e 's/include "\(.*\)\.coh"/include "h.\1"/' < {ins} | expand -t4 | tr '\n' '\r' > {outs}""" + ], + label="BBCIFY", + ) + + +bbcify(name="mandelcow", src="examples/mandel.cow") +bbcify(name="cowgolcoh", src="rt/bbct/cowgol.coh") +bbcify(name="commoncoh", src="rt/common.coh") + +mkdfs( + name="ssd", + flags=[ + ["-f", Target("./!boot")], + [ + "-f", + Target("src/cowfe+cowfe-for-16bit-with-bbct"), + "-e0x400", + "-l0x400", + "-ncowfe", + ], + [ + "-f", + Target("src/cowbe+cowbe-for-6502-with-bbct"), + "-e0x400", + "-l0x400", + "-ncowbe", + ], + [ + "-f", + Target("src/cowlink+cowlink-for-bbct-with-bbct"), + "-e0x400", + "-l0x400", + "-ncowlink", + ], + ["-f", Target("rt/bbct+cowgolcoo"), "-no.cowgol"], + ["-f", Target("+cowgolcoh"), "-nh.cowgol"], + ["-f", Target("+commoncoh"), "-nh.common"], + ["-f", Target("+mandelcow"), "-nw.source"], + "-B3", + ], +) + +export( + name="bbct", + items={ + "bin/dist/bbct/!boot": "./!boot", + "bin/dist/bbct/mandel.cow": "+mandelcow", + "bin/dist/bbct/cowgol.coh": "+cowgolcoh", + "bin/dist/bbct/common.coh": "+commoncoh", + "bin/dist/bbct/cowgol.coo": "rt/bbct+cowgolcoo", + "bin/dist/bbct/cowfe.com": "src/cowfe+cowfe-for-16bit-with-bbct", + "bin/dist/bbct/cowbe.com": "src/cowbe+cowbe-for-6502-with-bbct", + "bin/dist/bbct/cowlink.com": "src/cowlink+cowlink-for-bbct-with-bbct", + "bin/dist/bbct.ssd": "+ssd", + }, +) diff --git a/src/build.py b/src/build.py index a9710df7..977e5501 100644 --- a/src/build.py +++ b/src/build.py @@ -18,7 +18,7 @@ @Rule -def cgen(self, name, srcs: Targets() = []): +def cgen(self, name, srcs: Targets = []): cprogram(replaces=self, srcs=srcs + ["rt/cgen/cowgol.h"]) @@ -36,32 +36,32 @@ def buildgasimpl(self, prefix): @Rule -def buildgasarm(self, name, srcs: Targets() = None): +def buildgasarm(self, name, srcs: Targets = None): buildgasimpl(self, "arm-linux-gnueabihf") @Rule -def buildgas386(self, name, srcs: Targets() = None): +def buildgas386(self, name, srcs: Targets = None): buildgasimpl(self, "i686-linux-gnu") @Rule -def buildgas68k(self, name, srcs: Targets() = None): +def buildgas68k(self, name, srcs: Targets = None): buildgasimpl(self, "m68k-linux-gnu") @Rule -def buildgasppc(self, name, srcs: Targets() = None): +def buildgasppc(self, name, srcs: Targets = None): buildgasimpl(self, "powerpc-linux-gnu") @Rule -def buildgasataritos(self, name, srcs: Targets() = None): +def buildgasataritos(self, name, srcs: Targets = None): buildgasimpl(self, "m68k-atari-mint") @Rule -def buildtass64(self, name, srcs: Targets() = None): +def buildtass64(self, name, srcs: Targets = None): tass64(replaces=self, srcs=srcs) @@ -76,17 +76,17 @@ def buildcowasmimpl(self, asm): @Rule -def buildcowasmpdp11(self, name, srcs: Targets() = None): +def buildcowasmpdp11(self, name, srcs: Targets = None): buildcowasmimpl(self, "src/cowasm+cowasm-for-pdp11-with-ncgen") @Rule -def buildcowasm6303(self, name, srcs: Targets() = None): +def buildcowasm6303(self, name, srcs: Targets = None): buildcowasmimpl(self, "src/cowasm+cowasm-for-6303-with-ncgen") @Rule -def buildnasm(self, name, srcs: Targets() = None): +def buildnasm(self, name, srcs: Targets = None): o = nasm(name=name + "/obj", srcs=srcs) djlink(replaces=self, srcs=[o]) @@ -106,57 +106,57 @@ def testimpl(self, dep, command): @Rule -def nativetest(self, name, goodfile: Target() = None, exe: Target() = None): +def nativetest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, [], "{ins[0]}") @Rule -def tubeemutest(self, name, goodfile: Target() = None, exe: Target() = None): +def tubeemutest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["tools/tubeemu"], "{ins[0]} -l 0x400 -e 0x400 -f {ins[1]}") @Rule -def cpmtest(self, name, goodfile: Target() = None, exe: Target() = None): +def cpmtest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["tools/cpmemu"], "{ins[0]} {ins[1]}") @Rule -def apouttest(self, name, goodfile: Target() = None, exe: Target() = None): +def apouttest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["third_party/apout"], "{ins[0]} {ins[1]}") @Rule -def fuzix6303test(self, name, goodfile: Target() = None, exe: Target() = None): +def fuzix6303test(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["tools/fuzix6303emu"], "{ins[0]} -f {ins[1]}") @Rule -def ataritostest(self, name, goodfile: Target() = None, exe: Target() = None): +def ataritostest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["tools/ataritosemu"], "{ins[0]} {ins[1]}") @Rule -def qemuarmtest(self, name, goodfile: Target() = None, exe: Target() = None): +def qemuarmtest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, [], "qemu-arm {ins[0]}") @Rule -def qemu386test(self, name, goodfile: Target() = None, exe: Target() = None): +def qemu386test(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, [], "qemu-i386 {ins[0]}") @Rule -def qemu68ktest(self, name, goodfile: Target() = None, exe: Target() = None): +def qemu68ktest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, [], "qemu-m68k {ins[0]}") @Rule -def qemuppctest(self, name, goodfile: Target() = None, exe: Target() = None): +def qemuppctest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, [], "qemu-ppc {ins[0]}") @Rule -def msdostest(self, name, goodfile: Target() = None, exe: Target() = None): +def msdostest(self, name, goodfile: Target = None, exe: Target = None): testimpl(self, ["third_party/emu2"], "{ins[0]} {ins[1]}") @@ -164,10 +164,10 @@ def msdostest(self, name, goodfile: Target() = None, exe: Target() = None): def toolchain( self, name, - cowfe: Target() = None, - cowbe: Target() = None, - cowlink: Target() = None, - cowwrap: Target() = None, + cowfe: Target = None, + cowbe: Target = None, + cowlink: Target = None, + cowwrap: Target = None, runtime=None, asmext=None, binext=None, @@ -196,9 +196,9 @@ def toolchain( def cowlib( self, name, - srcs: Targets() = [], - deps: Targets() = [], - toolchain: Target() = None, + srcs: Targets = [], + deps: Targets = [], + toolchain: Target = None, ): srcs += [ "rt/common-file.coh", @@ -237,7 +237,7 @@ def cowlib( @Rule -def cowlink(self, name, deps: Targets() = [], toolchain: Target() = None): +def cowlink(self, name, deps: Targets = [], toolchain: Target = None): coos = [] for d in deps: if hasattr(d, "cowlib"): @@ -258,9 +258,9 @@ def cowlink(self, name, deps: Targets() = [], toolchain: Target() = None): def cowgol( self, name, - srcs: Targets() = [], - deps: Targets() = [], - toolchain: Target() = None, + srcs: Targets = [], + deps: Targets = [], + toolchain: Target = None, ): coo = cowlib(name=name + "/main", srcs=srcs, toolchain=toolchain) @@ -272,9 +272,7 @@ def cowgol( @Rule -def cowwrap( - self, name, src: Target() = None, toolchain: Target() = "src+ncgen" -): +def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): self.cowlib = SimpleNamespace() normalrule( replaces=self, diff --git a/tests/build.py b/tests/build.py index 1bfd7312..a610b48e 100644 --- a/tests/build.py +++ b/tests/build.py @@ -51,7 +51,7 @@ @Rule -def testsuite(self, name, toolchain: Target() = None): +def testsuite(self, name, toolchain: Target = None): tests = [] if toolchain.tester: for test in TESTS: diff --git a/third_party/djlink/build.py b/third_party/djlink/build.py index a41d68b3..cb16c0a4 100644 --- a/third_party/djlink/build.py +++ b/third_party/djlink/build.py @@ -52,7 +52,7 @@ @Rule -def djlink(self, name, srcs: Targets() = []): +def djlink(self, name, srcs: Targets = []): normalrule( replaces=self, ins=["third_party/djlink"] + srcs, diff --git a/third_party/lemon/build.py b/third_party/lemon/build.py index 43bae3f2..ad348e1c 100644 --- a/third_party/lemon/build.py +++ b/third_party/lemon/build.py @@ -13,7 +13,7 @@ @Rule -def lemon(self, name, src: Target() = None): +def lemon(self, name, src: Target = None): normalrule( replaces=self, ins=["third_party/lemon+lemon", "third_party/lemon/lempar.c", src], @@ -24,7 +24,7 @@ def lemon(self, name, src: Target() = None): @Rule -def lemoncowgol(self, name, src: Target() = None): +def lemoncowgol(self, name, src: Target = None): normalrule( replaces=self, ins=["third_party/lemon+lemon-cowgol", "src/cowfe/lempar.coh", src], diff --git a/third_party/musashi/build.py b/third_party/musashi/build.py index cbb01345..ae8db58a 100644 --- a/third_party/musashi/build.py +++ b/third_party/musashi/build.py @@ -13,7 +13,7 @@ @Rule -def musashilib(self, name, m68kconf: Target() = None): +def musashilib(self, name, m68kconf: Target = None): clibrary( replaces=self, srcs=[ diff --git a/third_party/zmac/build.py b/third_party/zmac/build.py index a2df8554..911ca726 100644 --- a/third_party/zmac/build.py +++ b/third_party/zmac/build.py @@ -18,7 +18,7 @@ @Rule -def zmac(self, name, srcs: Targets() = []): +def zmac(self, name, srcs: Targets = []): filename, ext = splitext(filenameof(srcs)) archflag = "-z" if (ext == ".z80") else "-8" diff --git a/tools/build.py b/tools/build.py index c69bf232..ed05a9ac 100644 --- a/tools/build.py +++ b/tools/build.py @@ -1,5 +1,5 @@ from build.c import cprogram -from build.ab2 import Rule, Target, normalrule +from build.ab2 import Rule, Target, Targets, normalrule, flatten, filenamesof cprogram( name="mkadfs", @@ -13,7 +13,7 @@ @Rule -def objectify(self, name, src: Target() = None, symbol=None): +def objectify(self, name, src: Target = None, symbol=None): normalrule( replaces=self, ins=["tools/objectify", src], @@ -24,7 +24,7 @@ def objectify(self, name, src: Target() = None, symbol=None): @Rule -def tocpm(self, name, src: Target() = None): +def tocpm(self, name, src: Target = None): normalrule( replaces=self, ins=["tools/tocpm.lua", src], @@ -32,3 +32,23 @@ def tocpm(self, name, src: Target() = None): commands=["lua {ins[0]} < {ins[1]} > {outs}"], label="TOCPM", ) + + +@Rule +def mkdfs(self, name, flags=[]): + srcs = [] + cmdline = ["{ins[0]}", "-O", "{outs}"] + for f in flatten(flags): + if isinstance(f, Target): + srcs += [f.convert(self)] + cmdline += filenamesof(f.convert(self)) + else: + cmdline += [f] + + normalrule( + replaces=self, + ins=["tools+mkdfs"] + srcs, + outs=[self.localname + ".ssd"], + commands=[" ".join(cmdline)], + label="MKDFS", + ) diff --git a/tools/newgen/build.py b/tools/newgen/build.py index f3c5541a..0ef8c248 100644 --- a/tools/newgen/build.py +++ b/tools/newgen/build.py @@ -23,7 +23,7 @@ @Rule -def newgencowgol(self, name, srcs: Targets() = []): +def newgencowgol(self, name, srcs: Targets = []): preprocessed = gpp(name=name + "/preprocessed", srcs=srcs) normalrule( From 9a2b27de0bf64cf8a74f793539294db9e2b1586d Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:48 +0000 Subject: [PATCH 33/40] Clean up the config stuff a bit. --- build.py | 6 ++-- config.py | 11 ++++++++ src/build.py | 78 +++++++++++++++++++++++++++------------------------- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/build.py b/build.py index d29da7ed..b0876e46 100644 --- a/build.py +++ b/build.py @@ -27,7 +27,7 @@ "dist/cpmz", "dist/cpm", ] - + (["dist/msdos"] if config.has_nasm else []) - + (["dist/ataritos"] if config.has_gcc68k else []) - + (["dist/bbct"] if config.has_tass64 else []), + + (["dist/msdos"] if config.has_msdos else []) + + (["dist/ataritos"] if config.has_ataritos else []) + + (["dist/bbct"] if config.has_bbct else []), ) diff --git a/config.py b/config.py index c3642d97..3b2f6e10 100644 --- a/config.py +++ b/config.py @@ -16,3 +16,14 @@ def enable_if(command): has_qemu386 = enable_if("qemu-i386") has_qemuppc = enable_if("qemu-ppc") has_qemu68k = enable_if("qemu-m68k") + +has_ataritos = has_gccataritos +has_msdos = has_nasm +has_lx386 = has_gcc386 +has_lxthumb2 = has_gccthumb2 +has_lx68k = has_gcc68k +has_lxppc = has_gccpowerpc +has_bbct = has_tass64 +has_bbctiny = has_tass64 +has_bbct6502 = has_tass64 + diff --git a/src/build.py b/src/build.py index 977e5501..983a0b56 100644 --- a/src/build.py +++ b/src/build.py @@ -344,7 +344,37 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_gccthumb2: +TOOLCHAINS.append( + toolchain( + name="unixv7", + cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", + cowbe="src/cowbe+cowbe-for-pdp11-with-ncgen", + cowlink="src/cowlink+cowlink-for-v7unix-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/unixv7", + asmext=".asm", + binext=".exe", + assembler=buildcowasmpdp11, + tester=apouttest, + ) +) + +TOOLCHAINS.append( + toolchain( + name="fuzix6303", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-6303-with-ncgen", + cowlink="src/cowlink+cowlink-for-fuzix6303-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/fuzix6303", + asmext=".asm", + binext=".exe", + assembler=buildcowasm6303, + tester=fuzix6303test, + ) +) + +if config.has_lxthumb2: TOOLCHAINS.append( toolchain( name="lxthumb2", @@ -360,7 +390,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_gcc386: +if config.has_lx386: TOOLCHAINS.append( toolchain( name="lx386", @@ -376,7 +406,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_gcc68k: +if config.has_lx68k: TOOLCHAINS.append( toolchain( name="lx68k", @@ -392,7 +422,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_gccpowerpc: +if config.has_lxppc: TOOLCHAINS.append( toolchain( name="lxppc", @@ -408,7 +438,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_tass64: +if config.has_bbct: TOOLCHAINS.append( toolchain( name="bbct", @@ -423,6 +453,8 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): tester=tubeemutest, ) ) + +if config.has_bbctiny: TOOLCHAINS.append( toolchain( name="bbctiny", @@ -437,6 +469,8 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): tester=tubeemutest, ) ) + +if config.has_bbct6502: TOOLCHAINS.append( toolchain( name="bbct6502", @@ -452,37 +486,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -TOOLCHAINS.append( - toolchain( - name="unixv7", - cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", - cowbe="src/cowbe+cowbe-for-pdp11-with-ncgen", - cowlink="src/cowlink+cowlink-for-v7unix-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/unixv7", - asmext=".asm", - binext=".exe", - assembler=buildcowasmpdp11, - tester=apouttest, - ) -) - -TOOLCHAINS.append( - toolchain( - name="fuzix6303", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-6303-with-ncgen", - cowlink="src/cowlink+cowlink-for-fuzix6303-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/fuzix6303", - asmext=".asm", - binext=".exe", - assembler=buildcowasm6303, - tester=fuzix6303test, - ) -) - -if config.has_nasm: +if config.has_msdos: TOOLCHAINS.append( toolchain( name="msdos", @@ -498,7 +502,7 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) ) -if config.has_gccataritos: +if config.has_ataritos: TOOLCHAINS.append( toolchain( name="ataritos", From 685d1ec0c06ce3c0a0217cdc9c642faca249a1f3 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:48 +0000 Subject: [PATCH 34/40] Generate ninjafiles instead of makefiles. --- Makefile | 17 ++++++++++-- build/ab2.py | 76 +++++++++++++++++++++++++++++++++++----------------- config.py | 1 - 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index eb90513d..9d442d1b 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,18 @@ export OBJ = .obj export LUA = lua +export CC = gcc +export CXX = g++ +export AR = ar export CFLAGS = -g -O0 export LDFLAGS = -g export NINJAFLAGS = -all: $(OBJ)/build.mk - @+make -f $(OBJ)/build.mk +all +#all: $(OBJ)/build.mk +# @+make -f $(OBJ)/build.mk +all +all: $(OBJ)/build.ninja + @ninja -f $< +all + clean: @echo CLEAN @rm -rf $(OBJ) bin @@ -17,6 +23,13 @@ $(OBJ)/build.mk: Makefile $(build-files) @mkdir -p $(OBJ) @python3 -X pycache_prefix=$(OBJ) build/ab2.py -m make -t +all -o $@ build.py +$(OBJ)/build.ninja: Makefile $(build-files) + @echo ACKBUILDER + @mkdir -p $(OBJ) + @python3 -X pycache_prefix=$(OBJ) build/ab2.py -m ninja -t +all -o $@ \ + -v OBJ,CC,CXX,AR \ + build.py + .DELETE_ON_ERROR: .SECONDARY: diff --git a/build/ab2.py b/build/ab2.py index 45b25e12..ab164ee4 100644 --- a/build/ab2.py +++ b/build/ab2.py @@ -13,6 +13,7 @@ import types import pathlib import builtins +import os defaultGlobals = {} targets = {} @@ -340,10 +341,6 @@ def emit(*args): outputFp.write("\n") -def unmake(ss): - return ss - - def templateexpand(s, invocation): class Converter: def __getitem__(self, key): @@ -368,38 +365,56 @@ def end(self): def var(self, name, value): # Don't let emit insert spaces. - emit(name + "=" + unmake(value)) + emit(name + "=" + value) def rule(self, name, ins, outs, deps=[]): ins = filenamesof(ins) if outs: outs = filenamesof(outs) emit(".PHONY:", name) - emit(name, ":", unmake(outs), unmake(deps)) - emit(outs, "&:", unmake(ins), unmake(deps)) + emit(name, ":", outs, deps) + emit(outs, "&:", ins, deps) else: - emit(name, ":", unmake(ins), unmake(deps)) + emit(name, ":", ins, deps) + + def label(self, s): + emit("\t$(hide)echo", s) + + def exec(self, cs): + for c in cs: + emit("\t$(hide)", c) - def exec(self, command): - emit("\t$(hide)", unmake(command)) + +def unmake(*ss): + return [ + re.sub(r"\$\(([^)]*)\)", r"$\1", s) for s in flatten(filenamesof(ss)) + ] class NinjaEmitter: def begin(self): - emit("rule build\n") - emit(" command = $command\n") - emit("\n") + emit("rule build") + emit(" command = $command") + + def end(self): + pass def var(self, name, value): # Don't let emit insert spaces. - emit(name + "=" + unmake(value)) + emit(name + "=" + unmake(value)[0]) - def rule(self, name, ins, outs): + def rule(self, name, ins, outs, deps=[]): if outs: - emit("build", name, ": phony", unmake(outs)) + emit("build", name, ": phony", unmake(outs, deps)) emit("build", unmake(outs), ": build", unmake(ins)) else: - emit("build", name, ": phony", unmake(ins)) + emit("build", name, ": phony", unmake(ins, deps)) + + def label(self, s): + emit(" description=", s) + + def exec(self, cs): + emit(" command=", " && ".join(unmake(cs))) @Rule @@ -415,15 +430,17 @@ def simplerule( self.ins = ins self.outs = outs emitter.rule(self.name, filenamesof(ins, deps), outs) - emitter.exec(templateexpand("echo {label} {name}", self)) + emitter.label(templateexpand("{label} {name}", self)) + cs = [] for out in filenamesof(outs): dir = dirname(out) if dir: - emitter.exec("mkdir -p " + dir) + cs += ["mkdir -p " + dir] for c in commands: - emitter.exec(templateexpand(c, self)) + cs += [templateexpand(c, self)] + emitter.exec(cs) @Rule @@ -457,15 +474,16 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []): filenamesof(items.keys()), filenamesof(deps), ) - emitter.exec(f"echo EXPORT {self.name}") + emitter.label(f"EXPORT {self.name}") + cs = [] self.ins = items.values() self.outs = filenamesof(deps) for dest, src in items.items(): destf = filenameof(dest) dir = dirname(destf) if dir: - emitter.exec("mkdir -p " + dir) + cs += ["mkdir -p " + dir] srcs = filenamesof(src) if len(srcs) != 1: @@ -473,9 +491,11 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []): "a dependency of an export must have exactly one output file" ) - emitter.exec("cp %s %s" % (srcs[0], destf)) + cs += ["cp %s %s" % (srcs[0], destf)] self.outs += [destf] + emitter.exec(cs) + def loadbuildfile(filename): filename = filename.replace("/", ".").removesuffix(".py") @@ -496,7 +516,8 @@ def main(): ) parser.add_argument("-o", "--output") parser.add_argument("files", nargs="+") - parser.add_argument("-t", "--targets", nargs="+") + parser.add_argument("-t", "--targets", action="append") + parser.add_argument("-v", "--vars", action="append") args = parser.parse_args() global outputFp @@ -509,6 +530,11 @@ def main(): emitter = NinjaEmitter() emitter.begin() + for v in flatten([a.split(",") for a in args.vars]): + e = os.getenv(v) + if e: + emitter.var(v, e) + global currentVars currentVars = Vars() @@ -522,7 +548,7 @@ def main(): for f in args.files: loadbuildfile(f) - for t in args.targets: + for t in flatten([a.split(",") for a in args.targets]): targets[t].materialise() emitter.end() diff --git a/config.py b/config.py index 3b2f6e10..e3ed5441 100644 --- a/config.py +++ b/config.py @@ -26,4 +26,3 @@ def enable_if(command): has_bbct = has_tass64 has_bbctiny = has_tass64 has_bbct6502 = has_tass64 - From e6e62c79b106090a7aa6c57bacc72240a2926705 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:49 +0000 Subject: [PATCH 35/40] Remove the obsolete lua files. --- bootstrap/build.lua | 20 -- build/c.lua | 138 ------------- build/gpp.lua | 20 -- build/tass64.lua | 20 -- build/utils.lua | 9 - build/yacc.lua | 16 -- dist/ataritos/build.lua | 37 ---- dist/bbct/build.lua | 43 ----- dist/cpm/build.lua | 64 ------ dist/cpmbasic/build.lua | 54 ------ dist/cpmbasic/tocpm.lua | 5 - dist/cpmz/build.lua | 59 ------ dist/msdos/build.lua | 42 ---- examples/build.lua | 20 -- mkninja.lua | 184 ------------------ rt/ataritos/build.lua | 6 - rt/bbct/build.lua | 5 - rt/bbcti/build.lua | 5 - rt/cgen/build.lua | 5 - rt/cpm/build.lua | 5 - rt/cpmz/build.lua | 5 - rt/fuzix6303/build.lua | 5 - rt/lx386/build.lua | 5 - rt/lx68k/build.lua | 5 - rt/lxppc/build.lua | 5 - rt/lxthumb2/build.lua | 5 - rt/msdos/build.lua | 5 - rt/unixv7/build.lua | 5 - src/build.lua | 331 -------------------------------- src/cowasm/build.lua | 16 -- src/cowasm2/build.lua | 30 --- src/cowbdmp/build.lua | 16 -- src/cowbe/build.lua | 61 ------ src/cowdis/build.lua | 14 -- src/cowfe/build.lua | 56 ------ src/cowlink/build.lua | 46 ----- src/cowwrap/build.lua | 13 -- src/misc/build.lua | 11 -- tests/build.lua | 72 ------- third_party/apout/build.lua | 25 --- third_party/djlink/build.lua | 54 ------ third_party/emu2/build.lua | 19 -- third_party/lemon/build.lua | 41 ---- third_party/musashi/build.lua | 40 ---- third_party/rc2014emu/build.lua | 0 third_party/zmac/build.lua | 44 ----- toolchains.lua | 202 ------------------- tools/ataritosemu/build.lua | 17 -- tools/build.lua | 39 ---- tools/cpmemu/build.lua | 24 --- tools/fuzix6303emu/build.lua | 15 -- tools/lx68kemu/build.lua | 16 -- tools/newgen/build.lua | 48 ----- tools/obpemu/build.lua | 12 -- tools/tubeemu/build.lua | 11 -- 55 files changed, 2070 deletions(-) delete mode 100644 bootstrap/build.lua delete mode 100644 build/c.lua delete mode 100644 build/gpp.lua delete mode 100644 build/tass64.lua delete mode 100644 build/utils.lua delete mode 100644 build/yacc.lua delete mode 100644 dist/ataritos/build.lua delete mode 100644 dist/bbct/build.lua delete mode 100644 dist/cpm/build.lua delete mode 100644 dist/cpmbasic/build.lua delete mode 100644 dist/cpmbasic/tocpm.lua delete mode 100644 dist/cpmz/build.lua delete mode 100644 dist/msdos/build.lua delete mode 100644 examples/build.lua delete mode 100644 mkninja.lua delete mode 100644 rt/ataritos/build.lua delete mode 100644 rt/bbct/build.lua delete mode 100644 rt/bbcti/build.lua delete mode 100644 rt/cgen/build.lua delete mode 100644 rt/cpm/build.lua delete mode 100644 rt/cpmz/build.lua delete mode 100644 rt/fuzix6303/build.lua delete mode 100644 rt/lx386/build.lua delete mode 100644 rt/lx68k/build.lua delete mode 100644 rt/lxppc/build.lua delete mode 100644 rt/lxthumb2/build.lua delete mode 100644 rt/msdos/build.lua delete mode 100644 rt/unixv7/build.lua delete mode 100644 src/build.lua delete mode 100644 src/cowasm/build.lua delete mode 100644 src/cowasm2/build.lua delete mode 100644 src/cowbdmp/build.lua delete mode 100644 src/cowbe/build.lua delete mode 100644 src/cowdis/build.lua delete mode 100644 src/cowfe/build.lua delete mode 100644 src/cowlink/build.lua delete mode 100644 src/cowwrap/build.lua delete mode 100644 src/misc/build.lua delete mode 100644 tests/build.lua delete mode 100644 third_party/apout/build.lua delete mode 100644 third_party/djlink/build.lua delete mode 100644 third_party/emu2/build.lua delete mode 100644 third_party/lemon/build.lua delete mode 100644 third_party/musashi/build.lua delete mode 100644 third_party/rc2014emu/build.lua delete mode 100644 third_party/zmac/build.lua delete mode 100644 toolchains.lua delete mode 100644 tools/ataritosemu/build.lua delete mode 100644 tools/build.lua delete mode 100644 tools/cpmemu/build.lua delete mode 100644 tools/fuzix6303emu/build.lua delete mode 100644 tools/lx68kemu/build.lua delete mode 100644 tools/newgen/build.lua delete mode 100644 tools/obpemu/build.lua delete mode 100644 tools/tubeemu/build.lua diff --git a/bootstrap/build.lua b/bootstrap/build.lua deleted file mode 100644 index 76a60550..00000000 --- a/bootstrap/build.lua +++ /dev/null @@ -1,20 +0,0 @@ -buildcgen { - ins = { "bootstrap/cowfe-cgen.bootstrap.c" }, - outs = { "bin/cowfe-cgen.bootstrap.exe" } -} - -buildcgen { - ins = { "bootstrap/cowbe-cgen.bootstrap.c" }, - outs = { "bin/cowbe-cgen.bootstrap.exe" } -} - -buildcgen { - ins = { "bootstrap/cowlink-cgen.bootstrap.c" }, - outs = { "bin/cowlink-cgen.bootstrap.exe" } -} - -buildcgen { - ins = { "bootstrap/cowwrap.bootstrap.c" }, - outs = { "bin/cowwrap.bootstrap.exe" } -} - diff --git a/build/c.lua b/build/c.lua deleted file mode 100644 index 77d63569..00000000 --- a/build/c.lua +++ /dev/null @@ -1,138 +0,0 @@ -function cfile(e) - local hdrs = {} - for _, src in ipairs(e.ins) do - local f = src:gsub("[^/]*$", "") - if f == "" then - f = "." - end - hdrs[#hdrs+1] = "-I"..f - end - - local cflags = e.cflags or "" - rule { - ins = e.ins, - outs = e.outs, - cmd = "$CC $CFLAGS "..cflags.." "..joined(hdrs).." -c -o &1 @1" - } -end - -function cprogram(e) - local objdir = e.objdir or "$OBJ" - local objs = {} - local hdrs = {} - local libs = {} - for _, src in ipairs(e.ins) do - if src:find("%.h$") then - hdrs[#hdrs+1] = src - end - end - - for _, src in ipairs(e.ins) do - if src:find("%.a$") then - libs[#libs+1] = src - elseif not src:find("%.h$") then - local o = objdir.."/"..src:gsub("%.c$", ".o"):gsub("%.cpp$", ".o") - objs[#objs+1] = o - cfile { - ins = concat { - src, - hdrs - }, - outs = { o }, - cflags = e.cflags, - } - end - end - - local ldflags = e.ldflags or "" - rule { - ins = concat { objs, libs }, - outs = e.outs, - cmd = "$CC -o &1 @@ "..joined(libs).." $LDFLAGS "..ldflags - } -end - -function clibrary(e) - local objdir = e.objdir or "$OBJ" - local objs = {} - local hdrs = {} - for _, src in ipairs(e.ins) do - if src:find("%.h$") then - hdrs[#hdrs+1] = src - end - end - - for _, src in ipairs(e.ins) do - if not src:find("%.h$") then - local o = objdir.."/"..src:gsub("%.c$", ".o"):gsub("%.cpp$", ".o") - objs[#objs+1] = o - cfile { - ins = concat { - src, - hdrs - }, - outs = { o }, - cflags = e.cflags, - } - end - end - - rule { - ins = objs, - outs = e.outs, - cmd = "rm -f &1 && $AR qcs &1 @@" - } -end - -function cxxfile(e) - local hdrs = {} - for _, src in ipairs(e.ins) do - local f = src:gsub("[^/]*$", "") - if f == "" then - f = "." - end - hdrs[#hdrs+1] = "-I"..f - end - - local cxxflags = e.cxxflags or "" - rule { - ins = e.ins, - outs = e.outs, - cmd = "$CXX $CXXFLAGS "..cxxflags.." "..joined(hdrs).." -c -o &1 @1" - } -end - -function cxxprogram(e) - local objdir = e.objdir or "$OBJ" - local objs = {} - local hdrs = {} - for _, src in ipairs(e.ins) do - if src:find("%.h$") then - hdrs[#hdrs+1] = src - end - end - - for _, src in ipairs(e.ins) do - if not src:find("%.h$") then - local o = objdir.."/"..src:gsub("%.cc$", ".o"):gsub("%.cpp$", ".o") - objs[#objs+1] = o - cxxfile { - ins = concat { - src, - hdrs - }, - outs = { o }, - cxxflags = e.cxxflags, - } - end - end - - local ldflags = e.ldflags or "" - rule { - ins = objs, - outs = e.outs, - cmd = "$CXX -o &1 @@ $LDFLAGS "..ldflags - } -end - - diff --git a/build/gpp.lua b/build/gpp.lua deleted file mode 100644 index e74ca2f3..00000000 --- a/build/gpp.lua +++ /dev/null @@ -1,20 +0,0 @@ -function gpp(e) - local hdrs = {} - for _, src in ipairs(e.ins) do - local f = src:gsub("[^/]*$", "") - if f == "" then - f = "." - end - hdrs[#hdrs+1] = "-I"..f - end - - local cflags = e.cflags or "" - rule { - ins = e.ins, - outs = e.outs, - cmd = "gpp --nostdinc -U '' '' '(' ',' ')' '(' ')' '$$' '' -M '$$' '\\n' ' ' ' ' '\\n' '(' ')' ".. - cflags.." "..joined(hdrs).." -o &1 @1" - } -end - - diff --git a/build/tass64.lua b/build/tass64.lua deleted file mode 100644 index 4a18f328..00000000 --- a/build/tass64.lua +++ /dev/null @@ -1,20 +0,0 @@ -function tass64(e) - local hdrs = {} - for _, src in ipairs(e.ins) do - local f = src:gsub("[^/]*$", "") - if f == "" then - f = "." - end - hdrs[#hdrs+1] = "-I"..f - end - - local cflags = e.cflags or "" - rule { - ins = e.ins, - outs = e.outs, - cmd = "64tass --quiet --long-branch --ascii --case-sensitive --nostart -o &1 @1" - } -end - - - diff --git a/build/utils.lua b/build/utils.lua deleted file mode 100644 index 7667f059..00000000 --- a/build/utils.lua +++ /dev/null @@ -1,9 +0,0 @@ -function copy(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "cp @1 &1" - } -end - - diff --git a/build/yacc.lua b/build/yacc.lua deleted file mode 100644 index d1e18f38..00000000 --- a/build/yacc.lua +++ /dev/null @@ -1,16 +0,0 @@ -function yacc(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "bison -y -t -o &1 --defines=&2 @1" - } -end - -function flex(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "flex -8 -Cem -s -t @1 > &1" - } -end - diff --git a/dist/ataritos/build.lua b/dist/ataritos/build.lua deleted file mode 100644 index 81ed918d..00000000 --- a/dist/ataritos/build.lua +++ /dev/null @@ -1,37 +0,0 @@ -if WITH_ATARITOS then - copy { - ins = { "examples/mandel.cow" }, - outs = { "$OBJ/dist/ataritos/mandel.cow" }, - } - - copy { - ins = { "rt/ataritos/cowgol.coh" }, - outs = { "$OBJ/dist/ataritos/cowgol.coh" }, - } - - copy { - ins = { "rt/common.coh" }, - outs = { "$OBJ/dist/ataritos/common.coh" }, - } - - copy { - ins = { "$OBJ/rt/ataritos/cowgol.coo" }, - outs = { "$OBJ/dist/ataritos/cowgol.coo" } - } - - copy { - ins = { "bin/cowfe-32bita2.ataritos.ataritos.tos" }, - outs = { "$OBJ/dist/ataritos/cowfe.tos" } - } - - copy { - ins = { "bin/cowbe-68000.ataritos.ataritos.tos" }, - outs = { "$OBJ/dist/ataritos/cowbe.tos" } - } - - copy { - ins = { "bin/cowlink-ataritos.ataritos.ataritos.tos" }, - outs = { "$OBJ/dist/ataritos/cowlink.tos" } - } -end - diff --git a/dist/bbct/build.lua b/dist/bbct/build.lua deleted file mode 100644 index f7b5cb5c..00000000 --- a/dist/bbct/build.lua +++ /dev/null @@ -1,43 +0,0 @@ -function bbcify(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = [[sed -e 's/include "\(.*\)\.coh"/include "h.\1"/' < @1 | expand -t4 | tr '\n' '\r' > &1]] - } -end - -bbcify { - ins = { "examples/mandel.cow" }, - outs = { "$OBJ/dist/bbct/mandel.cow" }, -} - -bbcify { - ins = { "rt/bbct/cowgol.coh" }, - outs = { "$OBJ/dist/bbct/cowgol.coh" }, -} - -bbcify { - ins = { "rt/common.coh" }, - outs = { "$OBJ/dist/bbct/common.coh" }, -} - -mkdfs { - ins = { - "-f", "dist/bbct/!boot", - "-f", "bin/cowfe-6502.bbct.bbct", "-e0x400", "-l0x400", "-ncowfe", - "-f", "bin/cowbe-65c02.bbct.bbct", "-e0x400", "-l0x400", "-ncowbe", - "-f", "bin/cowlink-bbctn.bbct.bbct", "-e0x400", "-l0x400", "-ncowlink", - "-f", "$OBJ/rt/bbct/cowgol.coo", "-no.cowgol", - "-f", "$OBJ/dist/bbct/cowgol.coh", "-nh.cowgol", - "-f", "$OBJ/dist/bbct/common.coh", "-nh.common", - "-f", "$OBJ/dist/bbct/mandel.cow", "-nw.source", - "-B3" - }, - outs = { "bbct.ssd" } -} - -mkdfs { - ins = {}, - outs = { "bbctwork.ssd" } -} - diff --git a/dist/cpm/build.lua b/dist/cpm/build.lua deleted file mode 100644 index e8cc8c79..00000000 --- a/dist/cpm/build.lua +++ /dev/null @@ -1,64 +0,0 @@ -function cpmify(e) - rule { - ins = concat { - "dist/cpm/tocpm.lua", - e.ins, - }, - outs = e.outs, - cmd = "$LUA @1 < @2 > &1", - } -end - -function copy(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "cp @1 &1" - } -end - -cpmify { - ins = { "examples/mandel.cow" }, - outs = { "$OBJ/dist/cpm/mandel.cow" }, -} - -cpmify { - ins = { "rt/cpm/cowgol.coh" }, - outs = { "$OBJ/dist/cpm/cowgol.coh" }, -} - -cpmify { - ins = { "rt/common.coh" }, - outs = { "$OBJ/dist/cpm/common.coh" }, -} - -cpmify { - ins = { "dist/cpm/demo.sub" }, - outs = { "$OBJ/dist/cpm/demo.sub" }, -} - -copy { - ins = { "$OBJ/rt/cpm/cowgol.coo" }, - outs = { "$OBJ/dist/cpm/cowgol.coo" } -} - -copy { - ins = { "bin/cowfe-16bit.ncpm.8080.com" }, - outs = { "$OBJ/dist/cpm/cowfe.com" } -} - -copy { - ins = { "bin/cowbe-8080.ncpm.8080.com" }, - outs = { "$OBJ/dist/cpm/cowbe.com" } -} - -copy { - ins = { "bin/cowlink-8080.ncpm.8080.com" }, - outs = { "$OBJ/dist/cpm/cowlink.com" } -} - -copy { - ins = { "bin/cowasm-8080.ncpm.8080.com" }, - outs = { "$OBJ/dist/cpm/cowasm.com" } -} - diff --git a/dist/cpmbasic/build.lua b/dist/cpmbasic/build.lua deleted file mode 100644 index 301b8d21..00000000 --- a/dist/cpmbasic/build.lua +++ /dev/null @@ -1,54 +0,0 @@ -function cpmify(e) - rule { - ins = concat { - "dist/cpmbasic/tocpm.lua", - e.ins, - }, - outs = e.outs, - cmd = "$LUA @1 < @2 > &1", - } -end - -function copy(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "cp @1 &1" - } -end - -cpmify { - ins = { "dist/cpmbasic/demo.sub" }, - outs = { "$OBJ/dist/cpmbasic/demo.sub" }, -} - -cpmify { - ins = { "examples/music.dat" }, - outs = { "$OBJ/dist/cpmbasic/music.dat" }, -} - -cpmify { - ins = { "examples/crisps.cow" }, - outs = { "$OBJ/dist/cpmbasic/crisps.cow" }, -} - -copy { - ins = { "bin/cowfe-basic.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmbasic/cowfe.com" } -} - -copy { - ins = { "bin/cowbe-basic.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmbasic/cowbe.com" } -} - -copy { - ins = { "bin/cowlink-basic.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmbasic/cowlink.com" } -} - -copy { - ins = { "bin/basicify.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmbasic/basicify.com" } -} - diff --git a/dist/cpmbasic/tocpm.lua b/dist/cpmbasic/tocpm.lua deleted file mode 100644 index 1176c6f2..00000000 --- a/dist/cpmbasic/tocpm.lua +++ /dev/null @@ -1,5 +0,0 @@ -for l in io.stdin:lines() do - io.write(l, "\r\n") -end -io.write(string.char(26)) - diff --git a/dist/cpmz/build.lua b/dist/cpmz/build.lua deleted file mode 100644 index 48bdf0e8..00000000 --- a/dist/cpmz/build.lua +++ /dev/null @@ -1,59 +0,0 @@ -function cpmify(e) - rule { - ins = concat { - "dist/cpmz/tocpm.lua", - e.ins, - }, - outs = e.outs, - cmd = "$LUA @1 < @2 > &1", - } -end - -function copy(e) - rule { - ins = e.ins, - outs = e.outs, - cmd = "cp @1 &1" - } -end - -cpmify { - ins = { "examples/mandel.cow" }, - outs = { "$OBJ/dist/cpmz/mandel.cow" }, -} - -cpmify { - ins = { "rt/cpmz/cowgol.coh" }, - outs = { "$OBJ/dist/cpmz/cowgol.coh" }, -} - -cpmify { - ins = { "rt/common.coh" }, - outs = { "$OBJ/dist/cpmz/common.coh" }, -} - -cpmify { - ins = { "dist/cpmz/demo.sub" }, - outs = { "$OBJ/dist/cpmz/demo.sub" }, -} - -copy { - ins = { "$OBJ/rt/cpmz/cowgol.coo" }, - outs = { "$OBJ/dist/cpmz/cowgol.coo" } -} - -copy { - ins = { "bin/cowfe-16bit.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmz/cowfe.com" } -} - -copy { - ins = { "bin/cowbe-z80.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmz/cowbe.com" } -} - -copy { - ins = { "bin/cowlink-8080.ncpmz.z80.com" }, - outs = { "$OBJ/dist/cpmz/cowlink.com" } -} - diff --git a/dist/msdos/build.lua b/dist/msdos/build.lua deleted file mode 100644 index ba48d407..00000000 --- a/dist/msdos/build.lua +++ /dev/null @@ -1,42 +0,0 @@ -if WITH_MSDOS then - copy { - ins = { "examples/mandel.cow" }, - outs = { "$OBJ/dist/msdos/mandel.cow" }, - } - - cpmify { - ins = { "rt/msdos/cowgol.coh" }, - outs = { "$OBJ/dist/msdos/cowgol.coh" }, - } - - cpmify { - ins = { "rt/common.coh" }, - outs = { "$OBJ/dist/msdos/common.coh" }, - } - - cpmify { - ins = { "dist/msdos/demo.bat" }, - outs = { "$OBJ/dist/msdos/demo.bat" }, - } - - copy { - ins = { "$OBJ/rt/msdos/cowgol.coo" }, - outs = { "$OBJ/dist/msdos/cowgol.coo" } - } - - copy { - ins = { "bin/cowfe-16bit.msdos.msdos.exe" }, - outs = { "$OBJ/dist/msdos/cowfe.exe" } - } - - copy { - ins = { "bin/cowbe-8086.msdos.msdos.exe" }, - outs = { "$OBJ/dist/msdos/cowbe.exe" } - } - - copy { - ins = { "bin/cowlink-msdos.msdos.msdos.exe" }, - outs = { "$OBJ/dist/msdos/cowlink.exe" } - } -end - diff --git a/examples/build.lua b/examples/build.lua deleted file mode 100644 index 76d48d91..00000000 --- a/examples/build.lua +++ /dev/null @@ -1,20 +0,0 @@ -local PROGRAMS = { - "argv", - "file", - "filetester", - "helloworld", - "icando", - "mandel", -} - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, prog in ipairs(PROGRAMS) do - cowgol { - toolchain = toolchain, - ins = { - "examples/"..prog..".cow" - }, - outs = { "bin/examples/"..prog } - } - end -end diff --git a/mkninja.lua b/mkninja.lua deleted file mode 100644 index b61a1b06..00000000 --- a/mkninja.lua +++ /dev/null @@ -1,184 +0,0 @@ -local function env(var, default) - return os.getenv(var) or default -end - -print("OBJ = "..env("OBJ", ".obj")) -print("LUA = "..env("LUA", "lua5.1")) -print("CC = "..env("CC", "cc")) -print("CXX = "..env("CC", "c++")) -print("CPP = "..env("CC", "cpp")) -print("AR = "..env("AR", "ar")) -print("CFLAGS = "..env("CFLAGS", "")) -print("CXXFLAGS = "..env("CXXFLAGS", "$CFLAGS")) -print("LDFLAGS = "..env("LDFLAGS", "")) -print("rule build"); -print(" command = $command"); -print("") - -function include(filename) - io.stderr:write("loading ", filename, "\n") - local fp, e = io.open(filename) - if not e then - local data - data, e = fp:read("*a") - fp:close(); - if not e then - local chunk - chunk, e = loadstring(data, "@"..filename) - if not e then - chunk() - end - end - end - if e then - error(string.format("coudn't load %s: %s", filename, e)) - end -end - -function string:obj() - if not self:find("^%$") then - return "$OBJ/"..self - end - return self -end - -function string:ext(newext) - return self:gsub("%.[^.]*$", newext) -end - -function string:dir() - return self:gsub("[^/]*$", "") -end - -function string:leaf() - return self:gsub("^.*/", "") -end - -function concat(...) - local result = {} - - local function recurse(t) - for _, i in ipairs(t) do - if type(i) == "table" then - recurse(i) - else - result[#result+1] = i - end - end - end - recurse({...}) - return result -end - -function joined(t) - local m = {} - for _, i in ipairs(t) do - m[i] = true - end - t = {} - for i in pairs(m) do - t[#t+1] = i - end - table.sort(t) - return table.concat(t, " ") -end - -function set(t) - local s = {} - for _, k in ipairs(t) do - s[k] = true - end - return s -end - -function command_present(name) - return os.execute("command -v "..name.." >/dev/null") ~= false -end - - -function rule(e) - print(string.format("build %s: build %s", - table.concat(e.outs, " "), - table.concat(e.ins, " "))) - local cmd = e.cmd - :gsub("@(%d+)", function (n) return e.ins[tonumber(n)] end) - :gsub("@@", table.concat(e.ins, " ")) - :gsub("&(%d+)", function (n) return e.outs[tonumber(n)] end) - - print(" command = "..cmd) - print("") -end - -function addto(t, v) - t[#t+1] = v -end - -function enable_if(name, command) - local v = command_present(command) - if not v then - io.stderr:write(name.." is 0 as "..command.." is not present\n") - end - _G[name] = v -end - -enable_if("WITH_ATARITOS", "m68k-atari-mint-as") -enable_if("WITH_MSDOS", "nasm") -enable_if("WITH_LX386", "i686-linux-gnu-as") -enable_if("WITH_LX68K", "m68k-linux-gnu-as") -enable_if("WITH_LXTHUMB2", "arm-linux-gnueabihf-as") -enable_if("WITH_LXPPC", "powerpc-linux-gnu-as") - -include "build/c.lua" -include "build/yacc.lua" -include "build/gpp.lua" -include "build/tass64.lua" -include "build/utils.lua" -include "tools/build.lua" -include "third_party/emu2/build.lua" -include "third_party/apout/build.lua" -include "third_party/zmac/build.lua" -include "third_party/djlink/build.lua" -include "third_party/musashi/build.lua" -include "tools/cpmemu/build.lua" -include "tools/tubeemu/build.lua" -include "tools/fuzix6303emu/build.lua" -include "tools/lx68kemu/build.lua" -include "tools/ataritosemu/build.lua" -include "tools/obpemu/build.lua" -include "third_party/lemon/build.lua" -include "tools/newgen/build.lua" -include "src/build.lua" -include "bootstrap/build.lua" -include "toolchains.lua" -include "src/cowlink/build.lua" -include "src/cowfe/build.lua" -include "src/cowbe/build.lua" -include "src/cowwrap/build.lua" -include "src/cowbdmp/build.lua" -include "src/cowasm/build.lua" -include "src/cowasm2/build.lua" -include "src/cowdis/build.lua" -include "src/misc/build.lua" -include "rt/ataritos/build.lua" -include "rt/cpm/build.lua" -include "rt/cpmz/build.lua" -include "rt/cgen/build.lua" -include "rt/lx386/build.lua" -include "rt/lx68k/build.lua" -include "rt/lxthumb2/build.lua" -include "rt/lxppc/build.lua" -include "rt/bbct/build.lua" -include "rt/bbcti/build.lua" -include "rt/unixv7/build.lua" -include "rt/fuzix6303/build.lua" -include "rt/msdos/build.lua" -include "examples/build.lua" -include "tests/build.lua" -include "dist/bbct/build.lua" -include "dist/cpm/build.lua" -include "dist/cpmz/build.lua" -include "dist/cpmbasic/build.lua" -include "dist/msdos/build.lua" -include "dist/ataritos/build.lua" - - diff --git a/rt/ataritos/build.lua b/rt/ataritos/build.lua deleted file mode 100644 index 7bcc6414..00000000 --- a/rt/ataritos/build.lua +++ /dev/null @@ -1,6 +0,0 @@ -cowwrap { - ins = { "rt/common-68000/cowgol.cos" }, - outs = { "$OBJ/rt/ataritos/cowgol.coo" } -} - - diff --git a/rt/bbct/build.lua b/rt/bbct/build.lua deleted file mode 100644 index 90a8a6bc..00000000 --- a/rt/bbct/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/bbct/cowgol.cos" }, - outs = { "$OBJ/rt/bbct/cowgol.coo" } -} - diff --git a/rt/bbcti/build.lua b/rt/bbcti/build.lua deleted file mode 100644 index a391a768..00000000 --- a/rt/bbcti/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/bbcti/cowgol.cos" }, - outs = { "$OBJ/rt/bbcti/cowgol.coo" } -} - diff --git a/rt/cgen/build.lua b/rt/cgen/build.lua deleted file mode 100644 index 192c139a..00000000 --- a/rt/cgen/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/cgen/cowgol.cos" }, - outs = { "$OBJ/rt/cgen/cowgol.coo" } -} - diff --git a/rt/cpm/build.lua b/rt/cpm/build.lua deleted file mode 100644 index c7fdffe0..00000000 --- a/rt/cpm/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/cpm/cowgol.cos" }, - outs = { "$OBJ/rt/cpm/cowgol.coo" } -} - diff --git a/rt/cpmz/build.lua b/rt/cpmz/build.lua deleted file mode 100644 index be847a05..00000000 --- a/rt/cpmz/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/cpmz/cowgol.cos" }, - outs = { "$OBJ/rt/cpmz/cowgol.coo" } -} - diff --git a/rt/fuzix6303/build.lua b/rt/fuzix6303/build.lua deleted file mode 100644 index b6b4fdfd..00000000 --- a/rt/fuzix6303/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/fuzix6303/cowgol.cos" }, - outs = { "$OBJ/rt/fuzix6303/cowgol.coo" } -} - diff --git a/rt/lx386/build.lua b/rt/lx386/build.lua deleted file mode 100644 index 2d7c0dd2..00000000 --- a/rt/lx386/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/lx386/cowgol.cos" }, - outs = { "$OBJ/rt/lx386/cowgol.coo" } -} - diff --git a/rt/lx68k/build.lua b/rt/lx68k/build.lua deleted file mode 100644 index c8ba38a5..00000000 --- a/rt/lx68k/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/common-68000/cowgol.cos" }, - outs = { "$OBJ/rt/lx68k/cowgol.coo" } -} - diff --git a/rt/lxppc/build.lua b/rt/lxppc/build.lua deleted file mode 100644 index ed69d955..00000000 --- a/rt/lxppc/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/lxppc/cowgol.cos" }, - outs = { "$OBJ/rt/lxppc/cowgol.coo" } -} - diff --git a/rt/lxthumb2/build.lua b/rt/lxthumb2/build.lua deleted file mode 100644 index 9642e816..00000000 --- a/rt/lxthumb2/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/lxthumb2/cowgol.cos" }, - outs = { "$OBJ/rt/lxthumb2/cowgol.coo" } -} - diff --git a/rt/msdos/build.lua b/rt/msdos/build.lua deleted file mode 100644 index 9099e7e6..00000000 --- a/rt/msdos/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/msdos/cowgol.cos" }, - outs = { "$OBJ/rt/msdos/cowgol.coo" } -} - diff --git a/rt/unixv7/build.lua b/rt/unixv7/build.lua deleted file mode 100644 index 7e616888..00000000 --- a/rt/unixv7/build.lua +++ /dev/null @@ -1,5 +0,0 @@ -cowwrap { - ins = { "rt/unixv7/cowgol.cos" }, - outs = { "$OBJ/rt/unixv7/cowgol.coo" } -} - diff --git a/src/build.lua b/src/build.lua deleted file mode 100644 index 1a4a8c38..00000000 --- a/src/build.lua +++ /dev/null @@ -1,331 +0,0 @@ -rule { - ins = { - "scripts/mkiburgcodes.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/iburgcodes-coh.h" }, - cmd = "$LUA @1 -- @3 &1" -} - -rule { - ins = { - "scripts/mkmidcodescoh.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/midcodes.coh" }, - cmd = "$LUA @1 -- @3 &1 combined" -} - -rule { - ins = { - "scripts/mkcobin.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/cobin.coh" }, - cmd = "$LUA @1 -- @3 &1" -} - -rule { - ins = { - "scripts/mkcobout.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/cobout.coh" }, - cmd = "$LUA @1 -- @3 &1" -} - -rule { - ins = { - "scripts/mkmidcodescoh.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/midcodesfe.coh" }, - cmd = "$LUA @1 -- @3 &1 fe" -} - -rule { - ins = { - "scripts/mkmidcodescoh.lua", - "scripts/libcowgol.lua", - "src/midcodes.coh.tab", - }, - outs = { "$OBJ/midcodesbe.coh" }, - cmd = "$LUA @1 -- @3 &1 be" -} - -function uncoo(e) - rule { - ins = concat { - "scripts/uncoo.lua", - e.ins - }, - outs = e.outs, - cmd = "$LUA @1 @2 &1" - } -end - -function buildcgen(e) - cprogram { - ins = concat { - e.ins, - "rt/cgen/cowgol.h", - }, - outs = e.outs - } -end - -function buildgas(arch, e) - local obj = e.outs[1]:ext(".o"):obj() - rule { - ins = e.ins, - outs = { obj }, - cmd = arch.."-as -g @1 -o &1" - } - - rule { - ins = { obj }, - outs = e.outs, - cmd = arch.."-ld -g @1 -o &1" - } -end - -function buildgas386(e) - return buildgas("i686-linux-gnu", e) -end - -function buildgas68k(e) - return buildgas("m68k-linux-gnu", e) -end - -function buildgasarm(e) - return buildgas("arm-linux-gnueabihf", e) -end - -function buildgasppc(e) - return buildgas("powerpc-linux-gnu", e) -end - -function buildgasataritos(e) - return buildgas("m68k-atari-mint", e) -end - -function buildzmac(e) - local cim = e.outs[1]:ext(".cim"):obj() - zmac { - ins = e.ins, - outs = { cim } - } - - rule { - ins = { cim }, - outs = e.outs, - cmd = "cp @1 &1" - } -end - -function buildcowasm(e, asm) - local lst = e.outs[1]:ext(".lst"):obj() - rule { - ins = concat { - "scripts/quiet", - "bin/cowasm-"..asm..".nncgen.exe", - e.ins - }, - outs = { e.outs[1], lst }, - cmd = "@1 @2 @3 -o &1 -l &2" - } -end - -function buildcowasm8080(e) - buildcowasm(e, "8080") -end - -function buildcowasmpdp11(e) - buildcowasm(e, "pdp11") -end - -function buildcowasm6303(e) - buildcowasm(e, "6303") -end - -function buildtass64(e) - local img = e.outs[1]:ext(".img"):obj() - tass64 { - ins = e.ins, - outs = e.outs, - } -end - -function buildnasm(e) - local lst = e.outs[1]:ext(".lst"):obj() - local obj = e.outs[1]:ext(".obj"):obj() - rule { - ins = e.ins, - outs = { obj, lst }, - cmd = "nasm -f obj -o &1 -l &2 @1", - } - - djlink { - ins = { obj }, - outs = { e.outs[1] } - } -end - -function simpletest(interpreter, e) - local badfile = e.ins[1]:ext(".bad") - rule { - ins = e.ins, - outs = { badfile }, - cmd = "timeout 5s "..interpreter.." @1 > &1.tmp && mv &1.tmp &1 && diff -u -w &1 "..e.goodfile, - } -end - -function nativetest(e) - return simpletest("", e) -end - -function qemu386test(e) - return simpletest("qemu-i386", e) -end - -function qemu68ktest(e) - return simpletest("qemu-m68k", e) -end - -function qemuarmtest(e) - return simpletest("qemu-arm", e) -end - -function qemuppctest(e) - return simpletest("qemu-ppc", e) -end - -function cpmtest(e) - e.ins = concat { e.ins, "bin/cpmemu" } - return simpletest("bin/cpmemu", e) -end - -function tubeemutest(e) - e.ins = concat { e.ins, "bin/tubeemu" } - return simpletest("bin/tubeemu -l 0x400 -e 0x400 -f", e) -end - -function apouttest(e) - e.ins = concat { e.ins, "bin/apout" } - return simpletest("bin/apout ", e) -end - -function fuzix6303test(e) - e.ins = concat { e.ins, "bin/fuzix6303emu" } - return simpletest("bin/fuzix6303emu -f", e) -end - -function emu2test(e) - e.ins = concat { e.ins, "bin/emu2" } - return simpletest("bin/emu2", e) -end - -function ataritosemutest(e) - e.ins = concat { e.ins, "bin/ataritosemu" } - return simpletest("bin/ataritosemu", e) -end - -function cowgol(e) - local out = e.outs[1].."."..e.toolchain.name..e.toolchain.binext - local coo = out:ext(".coo"):obj() - local asm = out:ext(e.toolchain.asmext):obj() - - local hdrs = {} - for _, src in ipairs(e.ins) do - local f = src:gsub("[^/]*$", "") - if f == "" then - f = "." - end - hdrs[#hdrs+1] = "-I"..f - end - - if e.toolchain.compiler then - rule { - ins = concat { - e.toolchain.compiler, - e.ins, - "scripts/quiet", - "rt/common-file.coh", - "rt/common.coh", - "rt/fileio.coh", - "rt/malloc.coh", - "rt/strings.coh", - (e.toolchain.runtime.."/cowgol.coh"), - (e.toolchain.runtime.."/file.coh"), - (e.toolchain.runtime.."/argv.coh"), - }, - outs = { coo }, - cmd = "scripts/quiet @1 -Irt/ -I"..e.toolchain.runtime.."/ "..joined(hdrs).." @2 &1" - } - else - local cob = out:ext(".cob"):obj() - rule { - ins = concat { - e.toolchain.cowfe, - e.ins, - "scripts/quiet", - "rt/common-file.coh", - "rt/common.coh", - "rt/fileio.coh", - "rt/malloc.coh", - "rt/strings.coh", - (e.toolchain.runtime.."/cowgol.coh"), - (e.toolchain.runtime.."/file.coh"), - (e.toolchain.runtime.."/argv.coh"), - }, - outs = { cob }, - cmd = "scripts/quiet @1 -Irt/ -I"..e.toolchain.runtime.."/ "..joined(hdrs).." @2 &1" - } - - rule { - ins = concat { - e.toolchain.cowbe, - "scripts/quiet", - cob, - }, - outs = { coo }, - cmd = "scripts/quiet @1 @3 &1" - } - end - - rule { - ins = concat { - "scripts/quiet", - e.toolchain.linker, - (e.toolchain.runtime.."/cowgol.coo"):obj(), - coo - }, - outs = { asm }, - cmd = "@1 @2 -o &1 @3 @4" - } - - e.toolchain.assembler { - ins = { asm }, - outs = { out } - } - - return out -end - -function cowwrap(e) - rule { - ins = concat { - "scripts/quiet", - "bin/cowwrap.bootstrap.exe", - e.ins - }, - outs = e.outs, - cmd = "@1 @2 @3 &1" - } -end - diff --git a/src/cowasm/build.lua b/src/cowasm/build.lua deleted file mode 100644 index f718424a..00000000 --- a/src/cowasm/build.lua +++ /dev/null @@ -1,16 +0,0 @@ -local ARCHS = { "8080", "pdp11", "6303", "tlcs90", "obp" } - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, arch in ipairs(ARCHS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowasm/arch"..arch..".cow", - "src/cowasm/cowasm.coh", - "src/cowasm/stdsyms.coh", - }, - outs = { "bin/cowasm-"..arch } - } - end -end - diff --git a/src/cowasm2/build.lua b/src/cowasm2/build.lua deleted file mode 100644 index 1ab65fe7..00000000 --- a/src/cowasm2/build.lua +++ /dev/null @@ -1,30 +0,0 @@ -local ARCHS = { "ac1082" } - -for _, arch in ipairs(ARCHS) do - lemoncowgol { - ins = { "src/cowasm2/arch"..arch..".y" }, - outs = { - "$OBJ/src/cowasm2/arch"..arch..".parser.coh", - "$OBJ/src/cowasm2/arch"..arch..".tokens.coh", - } - } - - for _, toolchain in ipairs(ALL_TOOLCHAINS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowasm2/arch"..arch..".cow", - "src/cowasm2/types.coh", - "src/cowasm2/lexer.coh", - "src/cowasm2/symbols.coh", - "src/cowasm2/emitter.coh", - "src/cowasm2/cowasm2.coh", - "$OBJ/src/cowasm2/arch"..arch..".parser.coh", - "$OBJ/src/cowasm2/arch"..arch..".tokens.coh", - }, - outs = { "bin/cowasm-"..arch } - } - end -end - - diff --git a/src/cowbdmp/build.lua b/src/cowbdmp/build.lua deleted file mode 100644 index 023fa89d..00000000 --- a/src/cowbdmp/build.lua +++ /dev/null @@ -1,16 +0,0 @@ -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowbdmp/main.cow", - "src/cowbdmp/types.coh", - "src/cowbe/inputter.coh", - "src/cowbe/utils.coh", - "src/cowbe/treewalker.coh", - "$OBJ/cobin.coh", - "$OBJ/midcodesbe.coh", - }, - outs = { "bin/cowbdmp" } - } -end - diff --git a/src/cowbe/build.lua b/src/cowbe/build.lua deleted file mode 100644 index 484c1bc9..00000000 --- a/src/cowbe/build.lua +++ /dev/null @@ -1,61 +0,0 @@ -local ARCHS = { - "6303", - "6502", - "65c02", - "65c02-tiny", - "68000", - "80386", - "8080", - "8086", - "basic", - "cgen", - "pdp11", - "powerpc", - "thumb2", - "z80", -} - -local extras = { - ["65c02"] = "src/cowbe/arch6502.cow.ng", - ["65c02-tiny"] = "src/cowbe/arch6502.cow.ng" -} - -for _, arch in ipairs(ARCHS) do - newgencowgol { - ins = { - "src/cowbe/arch"..arch..".cow.ng", - extras[arch] - }, - outs = { - "$OBJ/cowbe-"..arch.."/inssel.coh", - "$OBJ/cowbe-"..arch.."/inssel.decl.coh", - } - } -end - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, arch in ipairs(ARCHS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowbe/main.cow", - "include/coodecls.coh", - "src/cowbe/allocator.coh", - "src/cowbe/codegen.coh", - "src/cowbe/emitter.coh", - "src/cowbe/inputter.coh", - "src/cowbe/midcodec.coh", - "src/cowbe/processor.coh", - "src/cowbe/regcache.coh", - "src/cowbe/treewalker.coh", - "src/cowbe/types.coh", - "src/cowbe/utils.coh", - "$OBJ/cowbe-"..arch.."/inssel.coh", - "$OBJ/cowbe-"..arch.."/inssel.decl.coh", - "$OBJ/midcodesbe.coh", - }, - outs = { "bin/cowbe-"..arch } - } - end -end - diff --git a/src/cowdis/build.lua b/src/cowdis/build.lua deleted file mode 100644 index 803c048b..00000000 --- a/src/cowdis/build.lua +++ /dev/null @@ -1,14 +0,0 @@ -local ARCHS = { "tlcs90" } - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, arch in ipairs(ARCHS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowdis/arch"..arch..".cow", - }, - outs = { "bin/cowdis-"..arch } - } - end -end - diff --git a/src/cowfe/build.lua b/src/cowfe/build.lua deleted file mode 100644 index d30f7810..00000000 --- a/src/cowfe/build.lua +++ /dev/null @@ -1,56 +0,0 @@ -local ARCHS = { - "6502", - "80386", - "basic", - "cgen", - "pdp11", - "16bit", - "32bita2", - "32bita", -} - -lemoncowgol { - ins = { "src/cowfe/parser.y" }, - outs = { - "$OBJ/src/cowfe/parser.coh", - "$OBJ/src/cowfe/parser.tokens.coh", - } -} - -for _, arch in ipairs(ARCHS) do - rule { - ins = { "src/cowfe/arch"..arch..".coh" }, - outs = { "$OBJ/cowfe-"..arch.."/arch.coh" }, - cmd = "cp @1 &1", - } -end - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, arch in ipairs(ARCHS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowfe/main.cow", - "include/coodecls.coh", - "src/cowfe/allocator.coh", - "src/cowfe/codegen.coh", - "src/cowfe/emitter.coh", - "src/cowfe/expressions.coh", - "src/cowfe/lexer.coh", - "src/cowfe/midcodec.coh", - "src/cowfe/namespace.coh", - "src/cowfe/regcache.coh", - "src/cowfe/symbols.coh", - "src/cowfe/treewalker.coh", - "src/cowfe/types.coh", - "$OBJ/src/cowfe/parser.coh", - "$OBJ/src/cowfe/parser.tokens.coh", - "$OBJ/cowfe-"..arch.."/arch.coh", - "$OBJ/midcodesfe.coh", - "$OBJ/cobout.coh", - }, - outs = { "bin/cowfe-"..arch } - } - end -end - diff --git a/src/cowlink/build.lua b/src/cowlink/build.lua deleted file mode 100644 index 567d7fea..00000000 --- a/src/cowlink/build.lua +++ /dev/null @@ -1,46 +0,0 @@ -local ARCHS = { - "8080", - "ataritos", - "basic", - "bbct", - "bbctn", - "cgen", - "fuzix6303", - "lx386", - "lx68k", - "lxppc", - "lxthumb2", - "msdos", - "rt11", - "v7unix", -} - -for _, arch in ipairs(ARCHS) do - rule { - ins = { "src/cowlink/arch"..arch..".coh" }, - outs = { "$OBJ/cowlink-"..arch.."/archlink.coh" }, - cmd = "cp @1 &1", - } -end - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - for _, arch in ipairs(ARCHS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowlink/main.cow", - "include/coodecls.coh", - "$OBJ/cowlink-"..arch.."/archlink.coh", - "src/cowlink/asmwrite.coh", - "src/cowlink/cooread.coh", - "src/cowlink/emitter.coh", - "src/cowlink/graph.coh", - "src/cowlink/streams.coh", - "src/cowlink/types.coh", - "src/cowlink/utils.coh", - }, - outs = { "bin/cowlink-"..arch } - } - end -end - diff --git a/src/cowwrap/build.lua b/src/cowwrap/build.lua deleted file mode 100644 index efaadfee..00000000 --- a/src/cowwrap/build.lua +++ /dev/null @@ -1,13 +0,0 @@ -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - cowgol { - toolchain = toolchain, - ins = { - "src/cowwrap/main.cow", - "include/coodecls.coh", - "src/cowwrap/emitter.coh", - "src/cowwrap/reader.coh", - }, - outs = { "bin/cowwrap" }, - } -end - diff --git a/src/misc/build.lua b/src/misc/build.lua deleted file mode 100644 index d0887c48..00000000 --- a/src/misc/build.lua +++ /dev/null @@ -1,11 +0,0 @@ -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - cowgol { - toolchain = toolchain, - ins = { - "src/misc/basicify.cow" - }, - outs = { "bin/basicify" } - } -end - - diff --git a/tests/build.lua b/tests/build.lua deleted file mode 100644 index 894a807f..00000000 --- a/tests/build.lua +++ /dev/null @@ -1,72 +0,0 @@ -ALL_TESTS = { - "addsub-16bit", - "addsub-32bit", - "addsub-8bit", - "atoi", - "arrayinitialisers", - "case", - "casts", - "conditionals", - "divrem-16bit-s", - "divrem-16bit-u", - "divrem-32bit-s", - "divrem-32bit-u", - "divrem-8bit-s", - "divrem-8bit-u", - --"empty", # causes qemu to crash, but works on real hardware - "fileio", - "folding", - "forwards", - "inputparams", - "interfaces", - "itoa", - "logic-16bit", - "logic-32bit", - "logic-8bit", - "loops", - "lvalues", - "malloc", - "mul-16bit-s", - "mul-16bit-u", - "mul-32bit-s", - "mul-32bit-u", - "mul-8bit-s", - "mul-8bit-u", - "nested-calls", - "outputparams", - "pointers", - "rangetypes", - "recordinitialisers", - "records", - "regalloc", - "shifts-16bit", - "shifts-32bit", - "shifts-8bit", - "unions", -} - -for _, toolchain in ipairs(ALL_TOOLCHAINS) do - -- ncgen uses the bootstrap compiler, which should be tested and also - -- doesn't support the current language features. So, we don't need to - -- run the tests for it and they likely won't work anyway. - if toolchain.name ~= "ncgen" then - for _, test in ipairs(ALL_TESTS) do - if toolchain.tester then - local exe = cowgol { - toolchain = toolchain, - ins = { - "tests/"..test..".test.cow", - "tests/_framework.coh", - }, - outs = { "$OBJ/tests/"..test } - } - - toolchain.tester { - ins = { exe }, - goodfile = "tests/"..test..".good" - } - end - end - end -end - diff --git a/third_party/apout/build.lua b/third_party/apout/build.lua deleted file mode 100644 index 22335627..00000000 --- a/third_party/apout/build.lua +++ /dev/null @@ -1,25 +0,0 @@ -cprogram { - ins = { - "third_party/apout/aout.c", - "third_party/apout/branch.c", - "third_party/apout/bsd_ioctl.c", - "third_party/apout/bsd_signal.c", - "third_party/apout/bsdtrap.c", - "third_party/apout/cpu.c", - "third_party/apout/debug.c", - "third_party/apout/double.c", - "third_party/apout/ea.c", - "third_party/apout/fp.c", - "third_party/apout/itab.c", - "third_party/apout/ke11a.c", - "third_party/apout/magic.c", - "third_party/apout/main.c", - "third_party/apout/single.c", - "third_party/apout/v1trap.c", - "third_party/apout/v7trap.c", - }, - ldflags = "-lm", - cflags = "-DEMUV1 -DNATIVES -DRUN_V1_RAW -DDEBUG -DZERO_MEMORY -DWRITEBASE -DHEX", - outs = { "bin/apout" } -} - diff --git a/third_party/djlink/build.lua b/third_party/djlink/build.lua deleted file mode 100644 index 552b5288..00000000 --- a/third_party/djlink/build.lua +++ /dev/null @@ -1,54 +0,0 @@ -cxxprogram { - ins = { "third_party/djlink/objdump.cc" }, - outs = { "bin/objdump" } -} - -cxxprogram { - ins = { "third_party/djlink/bindiff.cc" }, - outs = { "bin/bindiff" } -} - -cxxprogram { - ins = { - "third_party/djlink/djlink.cc", - "third_party/djlink/fixups.cc", - "third_party/djlink/libs.cc", - "third_party/djlink/list.cc", - "third_party/djlink/map.cc", - "third_party/djlink/objs.cc", - "third_party/djlink/out.cc", - "third_party/djlink/quark.cc", - "third_party/djlink/segments.cc", - "third_party/djlink/stricmp.cc", - "third_party/djlink/symbols.cc", - "third_party/djlink/fixups.h", - "third_party/djlink/libs.h", - "third_party/djlink/link.h", - "third_party/djlink/list.h", - "third_party/djlink/map.h", - "third_party/djlink/objs.h", - "third_party/djlink/omf.h", - "third_party/djlink/out.h", - "third_party/djlink/quark.h", - "third_party/djlink/segments.h", - "third_party/djlink/stricmp.h", - "third_party/djlink/symbols.h", - "third_party/djlink/vars.h", - }, - outs = { "bin/djlink" } -} - -function djlink(e) - local map = e.outs[1]:ext(".map") - rule { - ins = concat { - "bin/djlink", - e.ins, - }, - outs = concat { - e.outs, - map - }, - cmd = "@1 -o &1 -m &2 @2 > /dev/null" - } -end diff --git a/third_party/emu2/build.lua b/third_party/emu2/build.lua deleted file mode 100644 index 65b6a29e..00000000 --- a/third_party/emu2/build.lua +++ /dev/null @@ -1,19 +0,0 @@ -cprogram { - ins = { - "third_party/emu2/src/cpu.c", - "third_party/emu2/src/loader.c", - "third_party/emu2/src/main.c", - "third_party/emu2/src/codepage.c", - "third_party/emu2/src/dosnames.c", - "third_party/emu2/src/dis.c", - "third_party/emu2/src/dos.c", - "third_party/emu2/src/keyb.c", - "third_party/emu2/src/dbg.c", - "third_party/emu2/src/timer.c", - "third_party/emu2/src/utils.c", - "third_party/emu2/src/video.c", - }, - ldflags = "-lm", - outs = { "bin/emu2" } -} - diff --git a/third_party/lemon/build.lua b/third_party/lemon/build.lua deleted file mode 100644 index eef67b95..00000000 --- a/third_party/lemon/build.lua +++ /dev/null @@ -1,41 +0,0 @@ -cprogram { - ins = { "third_party/lemon/lemon.c" }, - outs = { "bin/lemon" } -} - -cprogram { - ins = { "third_party/lemon/lemon-cowgol.c" }, - outs = { "bin/lemon-cowgol" } -} - -function lemon(e) - local dir = e.outs[1]:gsub("/[^/]*$", "").."/tmp" - rule { - ins = concat { - "bin/lemon", - "third_party/lemon/lempar.c", - e.ins, - }, - outs = e.outs, - cmd = "mkdir -p "..dir.." && @1 -T@2 -d"..dir.." @3" - .." && mv "..dir.."/parser.c &1" - .." && mv "..dir.."/parser.h &2" - } -end - -function lemoncowgol(e) - local dir = e.outs[1]:gsub("/[^/]*$", "").."/tmp" - local leaf = e.ins[1]:leaf():ext("") - rule { - ins = concat { - "bin/lemon-cowgol", - "src/cowfe/lempar.coh", - e.ins, - }, - outs = e.outs, - cmd = "mkdir -p "..dir.." && @1 -T@2 -d"..dir.." @3" - .." && mv "..dir.."/"..leaf..".c &1" - .." && mv "..dir.."/"..leaf..".h &2" - } -end - diff --git a/third_party/musashi/build.lua b/third_party/musashi/build.lua deleted file mode 100644 index af53f7fa..00000000 --- a/third_party/musashi/build.lua +++ /dev/null @@ -1,40 +0,0 @@ -cprogram { - ins = { - "third_party/musashi/m68kmake.c" - }, - outs = { - "$OBJ/third_party/musashi/m68kmake" - } -} - -rule { - ins = { - "$OBJ/third_party/musashi/m68kmake", - "third_party/musashi/m68k_in.c" - }, - outs = { - "$OBJ/third_party/musashi/m68kops.c", - "$OBJ/third_party/musashi/m68kops.h" - }, - cmd = "@1 $OBJ/third_party/musashi @2 > /dev/null" -} - -function musashilib(e) - clibrary { - ins = { - e.m68kconf, - "third_party/musashi/m68kcpu.c", - "third_party/musashi/m68kcpu.h", - "third_party/musashi/m68kdasm.c", - "third_party/musashi/m68k.h", - "third_party/musashi/m68kmmu.h", - "third_party/musashi/softfloat/softfloat.c", - "third_party/musashi/softfloat/softfloat.h", - "$OBJ/third_party/musashi/m68kops.c", - "$OBJ/third_party/musashi/m68kops.h" - }, - objdir = e.outs[1]:dir().."musashi", - outs = e.outs - } -end - diff --git a/third_party/rc2014emu/build.lua b/third_party/rc2014emu/build.lua deleted file mode 100644 index e69de29b..00000000 diff --git a/third_party/zmac/build.lua b/third_party/zmac/build.lua deleted file mode 100644 index 06614293..00000000 --- a/third_party/zmac/build.lua +++ /dev/null @@ -1,44 +0,0 @@ -yacc { - ins = { "third_party/zmac/zmac.y" }, - outs = { - "$OBJ/third_party/zmac/y.tab.c", - "$OBJ/third_party/zmac/y.tab.h", - } -} - -cprogram { - ins = { - "$OBJ/third_party/zmac/y.tab.c", - "third_party/zmac/mio.c", - "third_party/zmac/zi80dis.cpp" - }, - outs = { - "bin/zmac" - }, - cflags = "-I$OBJ/third_party/zmac -Ithird_party/zmac" -} - -function zmac(e) - local f = e.ins[1] - local _, _, ext = f:find("%.(%w+)$") - local archflag = (ext == "z80") and "-z" or "-8" - local lstfile = e.outs[1]:ext(".lst") - - local hdrpaths = {} - for _, t in ipairs(e.ins) do - hdrpaths[#hdrpaths+1] = "-I"..t - end - - rule { - ins = concat( - "bin/zmac", - e.ins - ), - outs = { - e.outs[1], - lstfile - }, - cmd = "@1 -j -m "..archflag.." -o &1 -o &2 "..table.concat(hdrpaths, " ").." @2" - } -end - diff --git a/toolchains.lua b/toolchains.lua deleted file mode 100644 index 7ea33425..00000000 --- a/toolchains.lua +++ /dev/null @@ -1,202 +0,0 @@ -toolchain_ataritos = { - name = "ataritos", - cowfe = "bin/cowfe-32bita2.nncgen.exe", - cowbe = "bin/cowbe-68000.nncgen.exe", - linker = "bin/cowlink-ataritos.nncgen.exe", - assembler = buildgasataritos, - runtime = "rt/ataritos", - asmext = ".s", - binext = ".ataritos.tos", - tester = ataritosemutest, -} - -toolchain_ncgen = { - name = "ncgen", - cowfe = "bin/cowfe-cgen.bootstrap.exe", - cowbe = "bin/cowbe-cgen.bootstrap.exe", - linker = "bin/cowlink-cgen.bootstrap.exe", - assembler = buildcgen, - runtime = "rt/cgen", - asmext = ".c", - binext = ".exe", - tester = nativetest -} - -toolchain_nncgen = { - name = "nncgen", - cowbe = "bin/cowbe-cgen.ncgen.exe", - cowfe = "bin/cowfe-cgen.ncgen.exe", - linker = "bin/cowlink-cgen.ncgen.exe", - assembler = buildcgen, - runtime = "rt/cgen", - asmext = ".c", - binext = ".exe", - tester = nativetest -} - -toolchain_ncpm = { - name = "ncpm", - cowfe = "bin/cowfe-16bit.nncgen.exe", - cowbe = "bin/cowbe-8080.nncgen.exe", - linker = "bin/cowlink-8080.nncgen.exe", - assembler = buildcowasm8080, - runtime = "rt/cpm", - asmext = ".asm", - binext = ".8080.com", - tester = cpmtest, -} - -toolchain_ncpmz = { - name = "ncpmz", - cowfe = "bin/cowfe-16bit.nncgen.exe", - cowbe = "bin/cowbe-z80.nncgen.exe", - linker = "bin/cowlink-8080.nncgen.exe", - assembler = buildzmac, - runtime = "rt/cpmz", - asmext = ".z80", - binext = ".z80.com", - tester = cpmtest, -} - -toolchain_lxthumb2 = { - name = "lxthumb2", - cowfe = "bin/cowfe-32bita.nncgen.exe", - cowbe = "bin/cowbe-thumb2.nncgen.exe", - linker = "bin/cowlink-lxthumb2.nncgen.exe", - assembler = buildgasarm, - runtime = "rt/lxthumb2", - asmext = ".s", - binext = ".lxthumb2.exe", - tester = qemuarmtest -} - -toolchain_lx386 = { - name = "lx386", - cowfe = "bin/cowfe-80386.nncgen.exe", - cowbe = "bin/cowbe-80386.nncgen.exe", - linker = "bin/cowlink-lx386.nncgen.exe", - assembler = buildgas386, - runtime = "rt/lx386", - asmext = ".s", - binext = ".lx386.exe", - tester = qemu386test -} - -toolchain_lx68k = { - name = "lx68k", - cowfe = "bin/cowfe-32bita2.nncgen.exe", - cowbe = "bin/cowbe-68000.nncgen.exe", - linker = "bin/cowlink-lx68k.nncgen.exe", - assembler = buildgas68k, - runtime = "rt/lx68k", - asmext = ".s", - binext = ".lx68k.exe", - tester = qemu68ktest -} - -toolchain_lxppc = { - name = "lxppc", - cowfe = "bin/cowfe-32bita.nncgen.exe", - cowbe = "bin/cowbe-powerpc.nncgen.exe", - linker = "bin/cowlink-lxppc.nncgen.exe", - assembler = buildgasppc, - runtime = "rt/lxppc", - asmext = ".s", - binext = ".lxppc.exe", - tester = qemuppctest -} - -toolchain_bbct = { - name = "bbct", - cowfe = "bin/cowfe-6502.nncgen.exe", - cowbe = "bin/cowbe-65c02.nncgen.exe", - linker = "bin/cowlink-bbct.nncgen.exe", - assembler = buildtass64, - runtime = "rt/bbct", - asmext = ".asm", - binext = ".bbct", - tester = tubeemutest, - archs = { "8080" } -} - -toolchain_bbctiny = { - name = "bbctiny", - cowfe = "bin/cowfe-6502.nncgen.exe", - cowbe = "bin/cowbe-65c02-tiny.nncgen.exe", - linker = "bin/cowlink-bbct.nncgen.exe", - assembler = buildtass64, - runtime = "rt/bbct", - asmext = ".asm", - binext = ".bbctiny", - tester = tubeemutest, -} - -toolchain_bbct6502 = { - name = "bbct6502", - cowfe = "bin/cowfe-6502.nncgen.exe", - cowbe = "bin/cowbe-6502.nncgen.exe", - linker = "bin/cowlink-bbct.nncgen.exe", - assembler = buildtass64, - runtime = "rt/bbct", - asmext = ".asm", - binext = ".bbct6502", - tester = tubeemutest, - archs = { "8080" }, -} - -toolchain_unixv7 = { - name = "unixv7", - cowfe = "bin/cowfe-pdp11.nncgen.exe", - cowbe = "bin/cowbe-pdp11.nncgen.exe", - linker = "bin/cowlink-v7unix.nncgen.exe", - assembler = buildcowasmpdp11, - runtime = "rt/unixv7", - asmext = ".asm", - binext = ".exe", - tester = apouttest -} - -toolchain_fuzix6303 = { - name = "fuzix6303", - cowfe = "bin/cowfe-16bit.nncgen.exe", - cowbe = "bin/cowbe-6303.nncgen.exe", - linker = "bin/cowlink-fuzix6303.nncgen.exe", - assembler = buildcowasm6303, - runtime = "rt/fuzix6303", - asmext = ".asm", - binext = ".6303.exe", - tester = fuzix6303test, -} - -toolchain_msdos = { - name = "msdos", - cowfe = "bin/cowfe-16bit.nncgen.exe", - cowbe = "bin/cowbe-8086.nncgen.exe", - linker = "bin/cowlink-msdos.nncgen.exe", - assembler = buildnasm, - runtime = "rt/msdos", - asmext = ".asm", - binext = ".msdos.exe", - tester = emu2test, -} - -ALL_TOOLCHAINS = {} -addto(ALL_TOOLCHAINS, toolchain_nncgen) -addto(ALL_TOOLCHAINS, toolchain_ncgen) - -addto(ALL_TOOLCHAINS, toolchain_bbct) -addto(ALL_TOOLCHAINS, toolchain_bbct6502) -addto(ALL_TOOLCHAINS, toolchain_bbcti) -addto(ALL_TOOLCHAINS, toolchain_bbctiny) -addto(ALL_TOOLCHAINS, toolchain_fuzix6303) -addto(ALL_TOOLCHAINS, toolchain_ncpm) -addto(ALL_TOOLCHAINS, toolchain_ncpmz) -addto(ALL_TOOLCHAINS, toolchain_unixv7) - -if WITH_ATARITOS then addto(ALL_TOOLCHAINS, toolchain_ataritos) end -if WITH_LX386 then addto(ALL_TOOLCHAINS, toolchain_lx386) end -if WITH_LX68K then addto(ALL_TOOLCHAINS, toolchain_lx68k) end -if WITH_LXPPC then addto(ALL_TOOLCHAINS, toolchain_lxppc) end -if WITH_LXTHUMB2 then addto(ALL_TOOLCHAINS, toolchain_lxthumb2) end -if WITH_MSDOS then addto(ALL_TOOLCHAINS, toolchain_msdos) end - diff --git a/tools/ataritosemu/build.lua b/tools/ataritosemu/build.lua deleted file mode 100644 index d4e94e68..00000000 --- a/tools/ataritosemu/build.lua +++ /dev/null @@ -1,17 +0,0 @@ -musashilib { - m68kconf = "tools/ataritosemu/m68kconf.h", - outs = { "$OBJ/tools/ataritosemu/libmusashi.a" } -} - -cprogram { - ins = { - "tools/ataritosemu/gemdos.c", - "tools/ataritosemu/sim.c", - "tools/ataritosemu/sim.h", - "third_party/musashi/m68k.h", - "$OBJ/tools/ataritosemu/libmusashi.a", - }, - outs = { "bin/ataritosemu" }, -} - - diff --git a/tools/build.lua b/tools/build.lua deleted file mode 100644 index 04c2e0fd..00000000 --- a/tools/build.lua +++ /dev/null @@ -1,39 +0,0 @@ -function objectify(e) - rule { - ins = concat { - "tools/objectify", - e.ins - }, - outs = e.outs, - cmd = "$LUA @1 "..e.symbol.." < @2 > &1" - } -end - -cprogram { - ins = { "tools/mkadfs.c" }, - outs = { "bin/mkadfs" }, -} - -cprogram { - ins = { "tools/mkdfs.c" }, - outs = { "bin/mkdfs" }, -} - -function mkdfs(e) - local ins = {} - for _, f in ipairs(e.ins) do - if not f:find("^-") then - ins[#ins+1] = f - end - end - - rule { - ins = concat { - "bin/mkdfs", - ins, - }, - outs = e.outs, - cmd = "@1 -O &1 "..table.concat(e.ins, " ") - } -end - diff --git a/tools/cpmemu/build.lua b/tools/cpmemu/build.lua deleted file mode 100644 index 574b584d..00000000 --- a/tools/cpmemu/build.lua +++ /dev/null @@ -1,24 +0,0 @@ -zmac { - ins = { "tools/cpmemu/biosbdos.z80" }, - outs = { "$OBJ/tools/cpmemu/biosbdos.cim" } -} - -objectify { - ins = { "$OBJ/tools/cpmemu/biosbdos.cim" }, - outs = { "$OBJ/tools/cpmemu/biosbdosdata.c" }, - symbol = "biosbdosdata" -} - -cprogram { - ins = { - "tools/cpmemu/main.c", - "tools/cpmemu/emulator.c", - "tools/cpmemu/fileio.c", - "tools/cpmemu/biosbdos.c", - "$OBJ/tools/cpmemu/biosbdosdata.c", - }, - ldflags = "-lz80ex -lz80ex_dasm -lreadline", - outs = { "bin/cpmemu" } -} - - diff --git a/tools/fuzix6303emu/build.lua b/tools/fuzix6303emu/build.lua deleted file mode 100644 index 407a7005..00000000 --- a/tools/fuzix6303emu/build.lua +++ /dev/null @@ -1,15 +0,0 @@ -cprogram { - ins = { - "tools/fuzix6303emu/main.c", - "tools/fuzix6303emu/disasm.c", - "tools/fuzix6303emu/globals.h", - "third_party/rc2014emu/6800.c", - "third_party/rc2014emu/6800.h", - }, - outs = { "bin/fuzix6303emu" }, - ldflags = "-lreadline", -} - - - - diff --git a/tools/lx68kemu/build.lua b/tools/lx68kemu/build.lua deleted file mode 100644 index cc6ed12b..00000000 --- a/tools/lx68kemu/build.lua +++ /dev/null @@ -1,16 +0,0 @@ -musashilib { - m68kconf = "tools/lx68kemu/m68kconf.h", - outs = { "$OBJ/tools/lx68kemu/libmusashi.a" } -} - -cprogram { - ins = { - "tools/lx68kemu/sim.c", - "tools/lx68kemu/sim.h", - "third_party/musashi/m68k.h", - "$OBJ/tools/lx68kemu/libmusashi.a", - }, - outs = { "bin/lx68kemu" }, -} - - diff --git a/tools/newgen/build.lua b/tools/newgen/build.lua deleted file mode 100644 index 6af30971..00000000 --- a/tools/newgen/build.lua +++ /dev/null @@ -1,48 +0,0 @@ -lemon { - ins = { "tools/newgen/parser.y" }, - outs = { - "$OBJ/tools/newgen/parser.c", - "$OBJ/tools/newgen/parser.h", - } -} - -flex { - ins = { "tools/newgen/lexer.l" }, - outs = { "$OBJ/tools/newgen/lexer.c" }, -} - -cprogram { - ins = { - "tools/newgen/main.c", - "tools/newgen/utils.c", - "tools/newgen/globals.h", - "$OBJ/iburgcodes-coh.h", - "$OBJ/tools/newgen/parser.c", - "$OBJ/tools/newgen/parser.h", - "$OBJ/tools/newgen/lexer.c", - }, - objdir = "$OBJ/newgen-cowgol", - cflags = "-DCOWGOL", - ldflags = "-lfl", - outs = { "bin/newgen-cowgol" } -} - -function newgencowgol(e) - local infile = e.ins[1] - local cppfile = infile:ext(".i"):obj(); - - gpp { - ins = e.ins, - outs = { cppfile } - } - - rule { - ins = concat { - "bin/newgen-cowgol", - cppfile - }, - outs = e.outs, - cmd = "@1 @2 &1 &2" - } -end - diff --git a/tools/obpemu/build.lua b/tools/obpemu/build.lua deleted file mode 100644 index 4f53f951..00000000 --- a/tools/obpemu/build.lua +++ /dev/null @@ -1,12 +0,0 @@ -cprogram { - ins = { - "tools/obpemu/main.c", - "tools/obpemu/emulator.c", - }, - outs = { "bin/obpemu" }, - ldflags = "-lreadline", -} - - - - diff --git a/tools/tubeemu/build.lua b/tools/tubeemu/build.lua deleted file mode 100644 index 0789c66a..00000000 --- a/tools/tubeemu/build.lua +++ /dev/null @@ -1,11 +0,0 @@ -cprogram { - ins = { - "tools/tubeemu/bbctube.c", - "third_party/lib6502/lib6502.c", - "third_party/lib6502/lib6502.h", - }, - outs = { "bin/tubeemu" } -} - - - From 5b4d5a3890d269b0b894bfd475f6980ebd0175ad Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:49 +0000 Subject: [PATCH 36/40] Generate consistent ninja files. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 9d442d1b..8df12cec 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ export CFLAGS = -g -O0 export LDFLAGS = -g export NINJAFLAGS = +export PYTHONHASHSEED = 1 + #all: $(OBJ)/build.mk # @+make -f $(OBJ)/build.mk +all From b896b0e1cda29e80a843138c33598dc4575eeb72 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:49 +0000 Subject: [PATCH 37/40] Update documentation. --- doc/building.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/building.md b/doc/building.md index f986970a..e282a3fa 100644 --- a/doc/building.md +++ b/doc/building.md @@ -9,7 +9,7 @@ dependencies. - the Ninja build tool - - Lua 5.1 (needed for the build) + - Python 3 and Lua 5.1 (needed for the build) - the Pasmo Z80 assembler (needed to build part of the CP/M emulator) @@ -37,7 +37,7 @@ dependencies. If you're on a Debianish platform, you should be able to install them (after adding any custom package sources as above) with: - apt install ninja-build lua5.1 pasmo libz80ex-dev flex libbsd-dev libreadline-dev bison binutils-arm-linux-gnueabihf binutils-i686-linux-gnu binutils-powerpc-linux-gnu binutils-m68k-linux-gnu binutils-m68k-atari-mint qemu-user gpp 64tass nasm + apt install ninja-build lua5.1 libz80ex-dev flex libbsd-dev libreadline-dev bison binutils-arm-linux-gnueabihf binutils-i686-linux-gnu binutils-powerpc-linux-gnu binutils-m68k-linux-gnu binutils-m68k-atari-mint qemu-user gpp 64tass nasm python3 Once done you can build the compiler itself with: @@ -47,10 +47,10 @@ make ``` You'll be left with a lot of stuff in the `bin` directory. The tools are all -labeled as (name).(toolchain).(extension); however, several extensions also -contain a dot. So, `cowfe-65c02.ncpmz.z80.com` is cowfe, the main front-end -compiler, targeting the 65c02, built with the `ncpmz` toolchain, which produced -a `z80.com` executable. +labeled as (name)-for-(toolchain)-with-(toolchain). So, +`cowfe-for-65c02-with-ncpmz.com` is cowfe, the main front-end compiler, +targeting the 65c02, built with the `ncpmz` toolchain, which produced a `.com` +executable. From a9c2679286863445b876dd59d580cc49859d13c1 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:49 +0000 Subject: [PATCH 38/40] Fix out-of-range jump preventing some large PowerPC programs being assembled. --- rt/lxppc/file.coh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rt/lxppc/file.coh b/rt/lxppc/file.coh index 73838f5b..0094bca6 100644 --- a/rt/lxppc/file.coh +++ b/rt/lxppc/file.coh @@ -29,7 +29,8 @@ include "fileio.coh"; @asm "lwz 8, ", pos, "@l(8)"; @asm "li 0, 0xb3"; # pread64 @asm "sc"; - @asm "bsol ", _fix_errno; + @asm "bns . + 4"; + @asm "bl ", _fix_errno; @asm "lis 4, ", i, "@ha"; @asm "stw 3, ", i, "@l(4)"; @@ -58,7 +59,8 @@ end sub; @asm "lwz 8, ", pos, "@l(8)"; @asm "li 0, 0xb4"; # pwrite64 @asm "sc"; - @asm "bsol ", _fix_errno; + @asm "bns . + 4"; + @asm "bl ", _fix_errno; @asm "lis 4, ", i, "@ha"; @asm "stw 3, ", i, "@l(4)"; @@ -78,7 +80,8 @@ sub fcb_i_open(fcb: [FCB], filename: [uint8], flags: uint32): (errno: uint8) is @asm "li 5, ", 0o666; # umask @asm "li 0, 0x05"; # open @asm "sc"; - @asm "bsol ", _fix_errno; + @asm "bns . + 4"; + @asm "bl ", _fix_errno; @asm "lis 4, ", fd, "@ha"; @asm "stw 3, ", fd, "@l(4)"; if fd < 0 then From e7f61dde112c73ebbc497c1f83bac5c3047d301b Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:46:50 +0000 Subject: [PATCH 39/40] Cross-build most of the tools. --- bootstrap/build.py | 2 +- build.py | 11 +- examples/build.py | 3 +- src/build.py | 414 ----------------------------------------- src/cowasm/build.py | 13 +- src/cowbdmp/build.py | 3 +- src/cowbe/build.py | 3 +- src/cowdis/build.py | 3 +- src/cowfe/build.py | 5 +- src/cowlink/build.py | 10 +- src/cowwrap/build.py | 11 +- src/misc/build.py | 3 +- src/toolchains.py | 428 +++++++++++++++++++++++++++++++++++++++++++ tests/build.py | 3 +- 14 files changed, 477 insertions(+), 435 deletions(-) create mode 100644 src/toolchains.py diff --git a/bootstrap/build.py b/bootstrap/build.py index 7951ef97..4a6ddf6e 100644 --- a/bootstrap/build.py +++ b/bootstrap/build.py @@ -1,4 +1,4 @@ -from src.build import cgen +from src.toolchains import cgen cgen(name="cowfe", srcs=["./cowfe-cgen.bootstrap.c"]) cgen(name="cowbe", srcs=["./cowbe-cgen.bootstrap.c"]) diff --git a/build.py b/build.py index b0876e46..97c21ea4 100644 --- a/build.py +++ b/build.py @@ -21,11 +21,16 @@ "bin/basicify": "src/misc+basicify-with-nncgen", }, deps=[ - "third_party/djlink+djlink-programs", + "dist/cpm", + "dist/cpmz", "examples", + "src/cowasm", + "src/cowbe", + "src/cowfe", + "src/cowlink", + "src/cowwrap", "tests", - "dist/cpmz", - "dist/cpm", + "third_party/djlink+djlink-programs", ] + (["dist/msdos"] if config.has_msdos else []) + (["dist/ataritos"] if config.has_ataritos else []) diff --git a/examples/build.py b/examples/build.py index 7aeb5c8f..fb869ff9 100644 --- a/examples/build.py +++ b/examples/build.py @@ -1,4 +1,5 @@ -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS from build.ab2 import export PROGRAMS = [ diff --git a/src/build.py b/src/build.py index 983a0b56..00cc4bad 100644 --- a/src/build.py +++ b/src/build.py @@ -9,189 +9,10 @@ ) from build.c import cprogram from os.path import * -from third_party.zmac.build import zmac from types import SimpleNamespace -from build.tass64 import tass64 -from build.nasm import nasm -from third_party.djlink.build import djlink import config -@Rule -def cgen(self, name, srcs: Targets = []): - cprogram(replaces=self, srcs=srcs + ["rt/cgen/cowgol.h"]) - - -def buildgasimpl(self, prefix): - normalrule( - replaces=self, - ins=self.args["srcs"], - outs=[self.localname + ".elf"], - commands=[ - prefix + "-as -g {ins} -o {outs[0]}.s", - prefix + "-ld -g {outs[0]}.s -o {outs[0]}", - ], - label="ASM-" + prefix.upper(), - ) - - -@Rule -def buildgasarm(self, name, srcs: Targets = None): - buildgasimpl(self, "arm-linux-gnueabihf") - - -@Rule -def buildgas386(self, name, srcs: Targets = None): - buildgasimpl(self, "i686-linux-gnu") - - -@Rule -def buildgas68k(self, name, srcs: Targets = None): - buildgasimpl(self, "m68k-linux-gnu") - - -@Rule -def buildgasppc(self, name, srcs: Targets = None): - buildgasimpl(self, "powerpc-linux-gnu") - - -@Rule -def buildgasataritos(self, name, srcs: Targets = None): - buildgasimpl(self, "m68k-atari-mint") - - -@Rule -def buildtass64(self, name, srcs: Targets = None): - tass64(replaces=self, srcs=srcs) - - -def buildcowasmimpl(self, asm): - normalrule( - replaces=self, - ins=[asm] + self.args["srcs"], - outs=[self.localname + ".bin"], - commands=["scripts/quiet {ins[0]} -o {outs[0]} {ins[1]}"], - label="ASM", - ) - - -@Rule -def buildcowasmpdp11(self, name, srcs: Targets = None): - buildcowasmimpl(self, "src/cowasm+cowasm-for-pdp11-with-ncgen") - - -@Rule -def buildcowasm6303(self, name, srcs: Targets = None): - buildcowasmimpl(self, "src/cowasm+cowasm-for-6303-with-ncgen") - - -@Rule -def buildnasm(self, name, srcs: Targets = None): - o = nasm(name=name + "/obj", srcs=srcs) - djlink(replaces=self, srcs=[o]) - - -def testimpl(self, dep, command): - goodfile = self.args["goodfile"] - normalrule( - replaces=self, - ins=dep + [self.args["exe"]], - outs=[self.localname + ".bad"], - commands=[ - "timeout 5s " + command + " > {outs}; true", - "diff -u -w {outs[0]} " + filenameof(goodfile), - ], - label="TEST", - ) - - -@Rule -def nativetest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, [], "{ins[0]}") - - -@Rule -def tubeemutest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["tools/tubeemu"], "{ins[0]} -l 0x400 -e 0x400 -f {ins[1]}") - - -@Rule -def cpmtest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["tools/cpmemu"], "{ins[0]} {ins[1]}") - - -@Rule -def apouttest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["third_party/apout"], "{ins[0]} {ins[1]}") - - -@Rule -def fuzix6303test(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["tools/fuzix6303emu"], "{ins[0]} -f {ins[1]}") - - -@Rule -def ataritostest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["tools/ataritosemu"], "{ins[0]} {ins[1]}") - - -@Rule -def qemuarmtest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, [], "qemu-arm {ins[0]}") - - -@Rule -def qemu386test(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, [], "qemu-i386 {ins[0]}") - - -@Rule -def qemu68ktest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, [], "qemu-m68k {ins[0]}") - - -@Rule -def qemuppctest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, [], "qemu-ppc {ins[0]}") - - -@Rule -def msdostest(self, name, goodfile: Target = None, exe: Target = None): - testimpl(self, ["third_party/emu2"], "{ins[0]} {ins[1]}") - - -@Rule -def toolchain( - self, - name, - cowfe: Target = None, - cowbe: Target = None, - cowlink: Target = None, - cowwrap: Target = None, - runtime=None, - asmext=None, - binext=None, - assembler=None, - tester=None, -): - id = self.localname - - for k, v in self.args.items(): - setattr(self, k, v) - - items = {} - if cowfe: - items["bin/cowfe-" + id] = cowfe - if cowbe: - items["bin/cowbe-" + id] = cowbe - if cowlink: - items["bin/cowlink-" + id] = cowlink - if cowwrap: - items["bin/cowwrap-" + id] = cowwrap - - export(replaces=self, items=items) - - @Rule def cowlib( self, @@ -283,241 +104,6 @@ def cowwrap(self, name, src: Target = None, toolchain: Target = "src+ncgen"): ) -TOOLCHAINS = [] - -TOOLCHAINS.append( - toolchain( - name="ncgen", - cowfe="bootstrap+cowfe", - cowbe="bootstrap+cowbe", - cowlink="bootstrap+cowlink", - cowwrap="bootstrap+cowwrap", - runtime="rt/cgen", - asmext=".c", - binext=".exe", - assembler=cgen, - ) -) - -TOOLCHAINS.append( - toolchain( - name="nncgen", - cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", - cowbe="src/cowbe+cowbe-for-cgen-with-ncgen", - cowlink="src/cowlink+cowlink-for-cgen-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/cgen", - asmext=".c", - binext=".exe", - assembler=cgen, - tester=nativetest, - ) -) - -TOOLCHAINS.append( - toolchain( - name="ncpm", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-8080-with-ncgen", - cowlink="src/cowlink+cowlink-for-8080-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/cpm", - asmext=".asm", - binext=".com", - assembler=zmac, - tester=cpmtest, - ) -) - -TOOLCHAINS.append( - toolchain( - name="ncpmz", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-z80-with-ncgen", - cowlink="src/cowlink+cowlink-for-8080-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/cpmz", - asmext=".z80", - binext=".com", - assembler=zmac, - tester=cpmtest, - ) -) - -TOOLCHAINS.append( - toolchain( - name="unixv7", - cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", - cowbe="src/cowbe+cowbe-for-pdp11-with-ncgen", - cowlink="src/cowlink+cowlink-for-v7unix-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/unixv7", - asmext=".asm", - binext=".exe", - assembler=buildcowasmpdp11, - tester=apouttest, - ) -) - -TOOLCHAINS.append( - toolchain( - name="fuzix6303", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-6303-with-ncgen", - cowlink="src/cowlink+cowlink-for-fuzix6303-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/fuzix6303", - asmext=".asm", - binext=".exe", - assembler=buildcowasm6303, - tester=fuzix6303test, - ) -) - -if config.has_lxthumb2: - TOOLCHAINS.append( - toolchain( - name="lxthumb2", - cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", - cowbe="src/cowbe+cowbe-for-thumb2-with-ncgen", - cowlink="src/cowlink+cowlink-for-lxthumb2-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lxthumb2", - asmext=".s", - binext=".exe", - assembler=buildgasarm, - tester=qemuarmtest if config.has_qemuarm else None, - ) - ) - -if config.has_lx386: - TOOLCHAINS.append( - toolchain( - name="lx386", - cowfe="src/cowfe+cowfe-for-80386-with-nncgen", - cowbe="src/cowbe+cowbe-for-80386-with-ncgen", - cowlink="src/cowlink+cowlink-for-lx386-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lx386", - asmext=".s", - binext=".exe", - assembler=buildgas386, - tester=qemu386test if config.has_qemu386 else None, - ) - ) - -if config.has_lx68k: - TOOLCHAINS.append( - toolchain( - name="lx68k", - cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", - cowbe="src/cowbe+cowbe-for-68000-with-ncgen", - cowlink="src/cowlink+cowlink-for-lx68k-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lx68k", - asmext=".s", - binext=".exe", - assembler=buildgas68k, - tester=qemu68ktest if config.has_qemu68k else None, - ) - ) - -if config.has_lxppc: - TOOLCHAINS.append( - toolchain( - name="lxppc", - cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", - cowbe="src/cowbe+cowbe-for-powerpc-with-ncgen", - cowlink="src/cowlink+cowlink-for-lxppc-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/lxppc", - asmext=".s", - binext=".exe", - assembler=buildgasppc, - tester=qemuppctest if config.has_qemuppc else None, - ) - ) - -if config.has_bbct: - TOOLCHAINS.append( - toolchain( - name="bbct", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-65c02-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - tester=tubeemutest, - ) - ) - -if config.has_bbctiny: - TOOLCHAINS.append( - toolchain( - name="bbctiny", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-65c02-tiny-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - tester=tubeemutest, - ) - ) - -if config.has_bbct6502: - TOOLCHAINS.append( - toolchain( - name="bbct6502", - cowfe="src/cowfe+cowfe-for-6502-with-nncgen", - cowbe="src/cowbe+cowbe-for-6502-with-ncgen", - cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/bbct", - asmext=".asm", - binext=".bin", - assembler=buildtass64, - tester=tubeemutest, - ) - ) - -if config.has_msdos: - TOOLCHAINS.append( - toolchain( - name="msdos", - cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", - cowbe="src/cowbe+cowbe-for-8086-with-ncgen", - cowlink="src/cowlink+cowlink-for-msdos-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/msdos", - asmext=".asm", - binext=".exe", - assembler=buildnasm, - tester=msdostest, - ) - ) - -if config.has_ataritos: - TOOLCHAINS.append( - toolchain( - name="ataritos", - cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", - cowbe="src/cowbe+cowbe-for-68000-with-ncgen", - cowlink="src/cowlink+cowlink-for-ataritos-with-ncgen", - cowwrap="src/cowwrap+cowwrap-with-ncgen", - runtime="rt/ataritos", - asmext=".asm", - binext=".tos", - assembler=buildgasataritos, - tester=ataritostest, - ) - ) - normalrule( name="midcodesfecoh", ins=[ diff --git a/src/cowasm/build.py b/src/cowasm/build.py index b9a1eee4..c99bb15d 100644 --- a/src/cowasm/build.py +++ b/src/cowasm/build.py @@ -1,14 +1,17 @@ -from build.ab2 import normalrule -from src.build import TOOLCHAINS, cowgol +from build.ab2 import normalrule, export +from src.build import cowgol from tools.newgen.build import newgencowgol +from src.toolchains import TOOLCHAINS ARCHS = ["8080", "pdp11", "6303", "tlcs90", "obp"] +items = {} for toolchain in TOOLCHAINS: toolchain.materialise() for arch in ARCHS: - cowgol( - name="cowasm-for-" + arch + "-with-" + toolchain.localname, + name = "cowasm-for-" + arch + "-with-" + toolchain.localname + items[name] = cowgol( + name=name, toolchain=toolchain, srcs=[ "./arch" + arch + ".cow", @@ -16,3 +19,5 @@ "./stdsyms.coh", ], ) + +export(name="cowasm", items=items) diff --git a/src/cowbdmp/build.py b/src/cowbdmp/build.py index 81b97c7a..85bcace0 100644 --- a/src/cowbdmp/build.py +++ b/src/cowbdmp/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS for toolchain in TOOLCHAINS: cowgol( diff --git a/src/cowbe/build.py b/src/cowbe/build.py index 56c634bb..9e25119c 100644 --- a/src/cowbe/build.py +++ b/src/cowbe/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule, export -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS from tools.newgen.build import newgencowgol ARCHS = [ diff --git a/src/cowdis/build.py b/src/cowdis/build.py index 09b7240f..b4b4017a 100644 --- a/src/cowdis/build.py +++ b/src/cowdis/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS ARCHS = ["tlcs90"] diff --git a/src/cowfe/build.py b/src/cowfe/build.py index 88004c42..711984e4 100644 --- a/src/cowfe/build.py +++ b/src/cowfe/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule, export -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS from third_party.lemon.build import lemoncowgol ARCHS = [ @@ -51,3 +52,5 @@ "src+midcodesfecoh", ], ) + +export(name="cowfe", items=items) diff --git a/src/cowlink/build.py b/src/cowlink/build.py index efbd366a..31c9d738 100644 --- a/src/cowlink/build.py +++ b/src/cowlink/build.py @@ -1,5 +1,6 @@ -from build.ab2 import normalrule -from src.build import TOOLCHAINS, cowgol +from build.ab2 import normalrule, export +from src.build import cowgol +from src.toolchains import TOOLCHAINS ARCHS = [ "8080", @@ -27,9 +28,11 @@ label="COPY", ) +items = {} for toolchain in TOOLCHAINS: for arch in ARCHS: - cowgol( + name = "cowlink-for-" + arch + "-with-" + toolchain.localname + items[name] = cowgol( name="cowlink-for-" + arch + "-with-" + toolchain.localname, toolchain=toolchain, srcs=[ @@ -45,3 +48,4 @@ "./utils.coh", ], ) +export(name="cowlink", items=items) diff --git a/src/cowwrap/build.py b/src/cowwrap/build.py index a55e1df4..13f9a5ce 100644 --- a/src/cowwrap/build.py +++ b/src/cowwrap/build.py @@ -1,8 +1,11 @@ -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol, export +from src.toolchains import TOOLCHAINS +items = {} for toolchain in TOOLCHAINS: - cowgol( - name="cowwrap-with-" + toolchain.localname, + name = "cowwrap-with-" + toolchain.localname + items[name] = cowgol( + name=name, toolchain=toolchain, srcs=[ "include/coodecls.coh", @@ -11,3 +14,5 @@ "./reader.coh", ], ) + +export(name="cowwrap", items=items) diff --git a/src/misc/build.py b/src/misc/build.py index 7b8b84de..4359b20a 100644 --- a/src/misc/build.py +++ b/src/misc/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS PROGRAMS = ["basicify"] diff --git a/src/toolchains.py b/src/toolchains.py new file mode 100644 index 00000000..e8e72cac --- /dev/null +++ b/src/toolchains.py @@ -0,0 +1,428 @@ +from build.ab2 import ( + Rule, + Target, + Targets, + export, + normalrule, + filenamesof, + filenameof, +) +from build.c import cprogram +from os.path import * +from third_party.zmac.build import zmac +from types import SimpleNamespace +from build.tass64 import tass64 +from build.nasm import nasm +from third_party.djlink.build import djlink +import config + + +@Rule +def cgen(self, name, srcs: Targets = []): + cprogram(replaces=self, srcs=srcs + ["rt/cgen/cowgol.h"]) + + +def buildgasimpl(self, prefix, flags=""): + normalrule( + replaces=self, + ins=self.args["srcs"], + outs=[self.localname + ".elf"], + commands=[ + prefix + "-as " + flags + " -g {ins} -o {outs[0]}.s", + prefix + "-ld -g {outs[0]}.s -o {outs[0]}", + ], + label="ASM-" + prefix.upper(), + ) + + +@Rule +def buildgasarm(self, name, srcs: Targets = None): + buildgasimpl(self, "arm-linux-gnueabihf") + + +@Rule +def buildgas386(self, name, srcs: Targets = None): + buildgasimpl(self, "i686-linux-gnu") + + +@Rule +def buildgas68k(self, name, srcs: Targets = None): + buildgasimpl(self, "m68k-linux-gnu") + + +@Rule +def buildgasppc(self, name, srcs: Targets = None): + buildgasimpl(self, "powerpc-linux-gnu") + + +@Rule +def buildgasataritos(self, name, srcs: Targets = None): + buildgasimpl(self, "m68k-atari-mint") + + +@Rule +def buildtass64(self, name, srcs: Targets = None): + tass64(replaces=self, srcs=srcs) + + +def buildcowasmimpl(self, asm): + normalrule( + replaces=self, + ins=[asm] + self.args["srcs"], + outs=[self.localname + ".bin"], + commands=["scripts/quiet {ins[0]} -o {outs[0]} {ins[1]}"], + label="ASM", + ) + + +@Rule +def buildcowasmpdp11(self, name, srcs: Targets = None): + buildcowasmimpl(self, "src/cowasm+cowasm-for-pdp11-with-ncgen") + + +@Rule +def buildcowasm6303(self, name, srcs: Targets = None): + buildcowasmimpl(self, "src/cowasm+cowasm-for-6303-with-ncgen") + + +@Rule +def buildnasm(self, name, srcs: Targets = None): + o = nasm(name=name + "/obj", srcs=srcs) + djlink(replaces=self, srcs=[o]) + + +def testimpl(self, dep, command): + goodfile = self.args["goodfile"] + normalrule( + replaces=self, + ins=dep + [self.args["exe"]], + outs=[self.localname + ".bad"], + commands=[ + "timeout 5s " + command + " > {outs}; true", + "diff -u -w {outs[0]} " + filenameof(goodfile), + ], + label="TEST", + ) + + +@Rule +def nativetest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, [], "{ins[0]}") + + +@Rule +def tubeemutest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["tools/tubeemu"], "{ins[0]} -l 0x400 -e 0x400 -f {ins[1]}") + + +@Rule +def cpmtest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["tools/cpmemu"], "{ins[0]} {ins[1]}") + + +@Rule +def apouttest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["third_party/apout"], "{ins[0]} {ins[1]}") + + +@Rule +def fuzix6303test(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["tools/fuzix6303emu"], "{ins[0]} -f {ins[1]}") + + +@Rule +def ataritostest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["tools/ataritosemu"], "{ins[0]} {ins[1]}") + + +@Rule +def qemuarmtest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, [], "qemu-arm {ins[0]}") + + +@Rule +def qemu386test(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, [], "qemu-i386 {ins[0]}") + + +@Rule +def qemu68ktest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, [], "qemu-m68k {ins[0]}") + + +@Rule +def qemuppctest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, [], "qemu-ppc {ins[0]}") + + +@Rule +def msdostest(self, name, goodfile: Target = None, exe: Target = None): + testimpl(self, ["third_party/emu2"], "{ins[0]} {ins[1]}") + + +@Rule +def toolchain( + self, + name, + cowfe: Target = None, + cowbe: Target = None, + cowlink: Target = None, + cowwrap: Target = None, + runtime=None, + asmext=None, + binext=None, + assembler=None, + tester=None, +): + id = self.localname + + for k, v in self.args.items(): + setattr(self, k, v) + + items = {} + if cowfe: + items["bin/cowfe-" + id] = cowfe + if cowbe: + items["bin/cowbe-" + id] = cowbe + if cowlink: + items["bin/cowlink-" + id] = cowlink + if cowwrap: + items["bin/cowwrap-" + id] = cowwrap + + export(replaces=self, items=items) + + +TOOLCHAINS = [] + +TOOLCHAINS.append( + toolchain( + name="ncgen", + cowfe="bootstrap+cowfe", + cowbe="bootstrap+cowbe", + cowlink="bootstrap+cowlink", + cowwrap="bootstrap+cowwrap", + runtime="rt/cgen", + asmext=".c", + binext=".exe", + assembler=cgen, + ) +) + +TOOLCHAINS.append( + toolchain( + name="nncgen", + cowfe="src/cowfe+cowfe-for-cgen-with-ncgen", + cowbe="src/cowbe+cowbe-for-cgen-with-ncgen", + cowlink="src/cowlink+cowlink-for-cgen-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/cgen", + asmext=".c", + binext=".exe", + assembler=cgen, + tester=nativetest, + ) +) + +TOOLCHAINS.append( + toolchain( + name="ncpm", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-8080-with-ncgen", + cowlink="src/cowlink+cowlink-for-8080-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/cpm", + asmext=".asm", + binext=".com", + assembler=zmac, + tester=cpmtest, + ) +) + +TOOLCHAINS.append( + toolchain( + name="ncpmz", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-z80-with-ncgen", + cowlink="src/cowlink+cowlink-for-8080-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/cpmz", + asmext=".z80", + binext=".com", + assembler=zmac, + tester=cpmtest, + ) +) + +TOOLCHAINS.append( + toolchain( + name="unixv7", + cowfe="src/cowfe+cowfe-for-pdp11-with-nncgen", + cowbe="src/cowbe+cowbe-for-pdp11-with-ncgen", + cowlink="src/cowlink+cowlink-for-v7unix-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/unixv7", + asmext=".asm", + binext=".exe", + assembler=buildcowasmpdp11, + tester=apouttest, + ) +) + +TOOLCHAINS.append( + toolchain( + name="fuzix6303", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-6303-with-ncgen", + cowlink="src/cowlink+cowlink-for-fuzix6303-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/fuzix6303", + asmext=".asm", + binext=".exe", + assembler=buildcowasm6303, + tester=fuzix6303test, + ) +) + +if config.has_lxthumb2: + TOOLCHAINS.append( + toolchain( + name="lxthumb2", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-thumb2-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxthumb2-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxthumb2", + asmext=".s", + binext=".exe", + assembler=buildgasarm, + tester=qemuarmtest if config.has_qemuarm else None, + ) + ) + +if config.has_lx386: + TOOLCHAINS.append( + toolchain( + name="lx386", + cowfe="src/cowfe+cowfe-for-80386-with-nncgen", + cowbe="src/cowbe+cowbe-for-80386-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx386-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx386", + asmext=".s", + binext=".exe", + assembler=buildgas386, + tester=qemu386test if config.has_qemu386 else None, + ) + ) + +if config.has_lx68k: + TOOLCHAINS.append( + toolchain( + name="lx68k", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-lx68k-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lx68k", + asmext=".s", + binext=".exe", + assembler=buildgas68k, + tester=qemu68ktest if config.has_qemu68k else None, + ) + ) + +if config.has_lxppc: + TOOLCHAINS.append( + toolchain( + name="lxppc", + cowfe="src/cowfe+cowfe-for-32bita-with-nncgen", + cowbe="src/cowbe+cowbe-for-powerpc-with-ncgen", + cowlink="src/cowlink+cowlink-for-lxppc-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/lxppc", + asmext=".s", + binext=".exe", + assembler=buildgasppc, + tester=qemuppctest if config.has_qemuppc else None, + ) + ) + +if config.has_bbct: + TOOLCHAINS.append( + toolchain( + name="bbct", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + tester=tubeemutest, + ) + ) + +if config.has_bbctiny: + TOOLCHAINS.append( + toolchain( + name="bbctiny", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-65c02-tiny-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + tester=tubeemutest, + ) + ) + +if config.has_bbct6502: + TOOLCHAINS.append( + toolchain( + name="bbct6502", + cowfe="src/cowfe+cowfe-for-6502-with-nncgen", + cowbe="src/cowbe+cowbe-for-6502-with-ncgen", + cowlink="src/cowlink+cowlink-for-bbct-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/bbct", + asmext=".asm", + binext=".bin", + assembler=buildtass64, + tester=tubeemutest, + ) + ) + +if config.has_msdos: + TOOLCHAINS.append( + toolchain( + name="msdos", + cowfe="src/cowfe+cowfe-for-16bit-with-nncgen", + cowbe="src/cowbe+cowbe-for-8086-with-ncgen", + cowlink="src/cowlink+cowlink-for-msdos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/msdos", + asmext=".asm", + binext=".exe", + assembler=buildnasm, + tester=msdostest, + ) + ) + +if config.has_ataritos: + TOOLCHAINS.append( + toolchain( + name="ataritos", + cowfe="src/cowfe+cowfe-for-32bita2-with-nncgen", + cowbe="src/cowbe+cowbe-for-68000-with-ncgen", + cowlink="src/cowlink+cowlink-for-ataritos-with-ncgen", + cowwrap="src/cowwrap+cowwrap-with-ncgen", + runtime="rt/ataritos", + asmext=".asm", + binext=".tos", + assembler=buildgasataritos, + tester=ataritostest, + ) + ) diff --git a/tests/build.py b/tests/build.py index a610b48e..f123282c 100644 --- a/tests/build.py +++ b/tests/build.py @@ -1,5 +1,6 @@ from build.ab2 import normalrule, Rule, Target, export -from src.build import TOOLCHAINS, cowgol +from src.build import cowgol +from src.toolchains import TOOLCHAINS TESTS = [ "addsub-16bit", From 86b9650be8baeca99b81331c426eac5e109479b3 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 5 Mar 2023 18:49:16 +0000 Subject: [PATCH 40/40] Typo fixes. --- examples/build.py | 1 - tests/build.py | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/build.py b/examples/build.py index fb869ff9..6b6fd288 100644 --- a/examples/build.py +++ b/examples/build.py @@ -4,7 +4,6 @@ PROGRAMS = [ "argv", - "cowcalc", "file", "filetester", "helloworld", diff --git a/tests/build.py b/tests/build.py index f123282c..672cbfed 100644 --- a/tests/build.py +++ b/tests/build.py @@ -38,7 +38,6 @@ "mul-8bit-u", "nested-calls", "outputparams", - "passto", "pointers", "rangetypes", "recordinitialisers",