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 diff --git a/Makefile b/Makefile index 3b604023..8df12cec 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,37 @@ 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.ninja - @ninja -f $(OBJ)/build.ninja $(NINJAFLAGS) +export PYTHONHASHSEED = 1 + +#all: $(OBJ)/build.mk +# @+make -f $(OBJ)/build.mk +all +all: $(OBJ)/build.ninja + @ninja -f $< +all + 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') build/*.py config.py +$(OBJ)/build.mk: Makefile $(build-files) + @echo ACKBUILDER @mkdir -p $(OBJ) - @$(LUA) \ - mkninja.lua \ - > $@ + @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/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/bootstrap/build.py b/bootstrap/build.py new file mode 100644 index 00000000..4a6ddf6e --- /dev/null +++ b/bootstrap/build.py @@ -0,0 +1,6 @@ +from src.toolchains 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 new file mode 100644 index 00000000..97c21ea4 --- /dev/null +++ b/build.py @@ -0,0 +1,38 @@ +from build.ab2 import Rule, export +from os.path import * +import config + +export( + name="all", + items={ + "bin/tubeemu": "tools/tubeemu", + "bin/obpemu": "tools/obpemu", + "bin/mkadfs": "tools+mkadfs", + "bin/mkdfs": "tools+mkdfs", + "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", + "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=[ + "dist/cpm", + "dist/cpmz", + "examples", + "src/cowasm", + "src/cowbe", + "src/cowfe", + "src/cowlink", + "src/cowwrap", + "tests", + "third_party/djlink+djlink-programs", + ] + + (["dist/msdos"] if config.has_msdos else []) + + (["dist/ataritos"] if config.has_ataritos else []) + + (["dist/bbct"] if config.has_bbct else []), +) diff --git a/build/ab2.py b/build/ab2.py new file mode 100644 index 00000000..ab164ee4 --- /dev/null +++ b/build/ab2.py @@ -0,0 +1,556 @@ +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 types +import pathlib +import builtins +import os + +defaultGlobals = {} +targets = {} +unmaterialisedTargets = set() +materialisingStack = [] +outputFp = None +emitter = None +currentVars = None +cwdStack = [""] + +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 + cwdStack.append(dirname(path)) + spec.loader.exec_module(module) + cwdStack.pop() + + return old_import(name, *args, **kwargs) + + +builtins.__import__ = new_import + + +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 + types = None + ins = None + outs = None + binding = None + vars = None + varsettings = None + + 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.binding.arguments.items(): + t = self.types.get(k, None) + if t: + v = t(v).convert(self) + self.args[k] = v + + # Create a new variable frame and set any variables. + + 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) + + # 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}" + ) + print(f"Arguments: {self.args}") + raise e + if not self.outs: + raise ABException(f"{self.name} didn't set self.outs") + + # Destack the variable and invocation frame. + + currentVars = oldVars + 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): + cwd = None + if name: + if ("+" in name) and not name.startswith("+"): + (cwd, _) = name.split("+", 1) + if not cwd: + cwd = cwdStack[-1] + + if name: + 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: + def __init__(self, value): + self.value = value + + +class Targets(Type): + def convert(self, invocation): + value = self.value + if type(value) is str: + value = [value] + if type(value) is list: + value = targetsof(value, cwd=invocation.cwd) + return value + + +class Target(Type): + def convert(self, invocation): + value = self.value + if not value: + return None + return targetof(value, cwd=invocation.cwd) + + +class TargetsMap(Type): + def convert(self, invocation): + value = self.value + 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 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 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() + return s + + if s in targets: + t = targets[s] + t.materialise() + return t + + if s.startswith("+"): + 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: + return fileinvocation(s) + + (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, cwd): + return flatten([targetof(x, cwd) for x in flatten(xs)]) + + +def filenamesof(*xs): + fs = [] + for t in flatten(xs): + if type(t) == str: + fs += [t] + else: + fs += [normpath(f) for f in t.outs] + return fs + + +def targetnamesof(*xs): + return [x.name for x in flatten(xs)] + + +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): + outputFp.write(" ".join(flatten(args))) + outputFp.write("\n") + + +def templateexpand(s, invocation): + class Converter: + def __getitem__(self, key): + if key == "vars": + return invocation.vars + f = filenamesof(invocation.args[key]) + if isinstance(f, Sequence): + f = ParameterList(f) + return f + + return eval("f%r" % s, invocation.callback.__globals__, Converter()) + + +class MakeEmitter: + def begin(self): + emit("hide = @") + emit(".DELETE_ON_ERROR:") + emit(".SECONDARY:") + + def end(self): + pass + + def var(self, name, value): + # Don't let emit insert spaces. + emit(name + "=" + value) + + def rule(self, name, ins, outs, deps=[]): + ins = filenamesof(ins) + if outs: + outs = filenamesof(outs) + emit(".PHONY:", name) + emit(name, ":", outs, deps) + emit(outs, "&:", ins, deps) + else: + 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 unmake(*ss): + return [ + re.sub(r"\$\(([^)]*)\)", r"$\1", s) for s in flatten(filenamesof(ss)) + ] + + +class NinjaEmitter: + def begin(self): + 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)[0]) + + def rule(self, name, ins, outs, deps=[]): + if outs: + emit("build", name, ": phony", unmake(outs, deps)) + emit("build", unmake(outs), ": build", unmake(ins)) + else: + emit("build", name, ": phony", unmake(ins, deps)) + + def label(self, s): + emit(" description=", s) + + def exec(self, cs): + emit(" command=", " && ".join(unmake(cs))) + + +@Rule +def simplerule( + self, + name, + ins: Targets = [], + outs=[], + deps: Targets = [], + commands=[], + label="RULE", +): + self.ins = ins + self.outs = outs + emitter.rule(self.name, filenamesof(ins, deps), outs) + emitter.label(templateexpand("{label} {name}", self)) + cs = [] + + for out in filenamesof(outs): + dir = dirname(out) + if dir: + cs += ["mkdir -p " + dir] + + for c in commands: + cs += [templateexpand(c, self)] + emitter.exec(cs) + + +@Rule +def normalrule( + self, + name=None, + ins: Targets = [], + deps: Targets = [], + outs=[], + label="RULE", + objdir=None, + commands=[], +): + objdir = objdir or join("$(OBJ)", name) + + simplerule( + replaces=self, + ins=ins, + deps=deps, + outs=[join(objdir, f) for f in outs], + label=label, + commands=commands, + ) + + +@Rule +def export(self, name=None, items: TargetsMap = {}, deps: Targets = []): + emitter.rule( + self.name, + flatten(items.values()), + filenamesof(items.keys()), + filenamesof(deps), + ) + 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: + cs += ["mkdir -p " + dir] + + srcs = filenamesof(src) + if len(srcs) != 1: + raise ABException( + "a dependency of an export must have exactly one output file" + ) + + cs += ["cp %s %s" % (srcs[0], destf)] + self.outs += [destf] + + emitter.exec(cs) + + +def loadbuildfile(filename): + 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(): + parser = argparse.ArgumentParser() + parser.add_argument( + "-m", "--mode", choices=["make", "ninja"], default="make" + ) + parser.add_argument("-o", "--output") + parser.add_argument("files", nargs="+") + parser.add_argument("-t", "--targets", action="append") + parser.add_argument("-v", "--vars", action="append") + args = parser.parse_args() + + global outputFp + outputFp = open(args.output, "wt") + + global emitter + if args.mode == "make": + emitter = MakeEmitter() + else: + 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() + + for k in ("Rule", "Targets", "load", "filenamesof", "stripext"): + defaultGlobals[k] = globals()[k] + + global __name__ + sys.modules["build.ab2"] = sys.modules[__name__] + __name__ = "build.ab2" + + for f in args.files: + loadbuildfile(f) + + for t in flatten([a.split(",") for a in args.targets]): + targets[t].materialise() + emitter.end() + + +main() 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/c.py b/build/c.py new file mode 100644 index 00000000..6ce13890 --- /dev/null +++ b/build/c.py @@ -0,0 +1,152 @@ +from build.ab2 import ( + Rule, + Targets, + normalrule, + filenamesof, + filenameof, + stripext, + flatten, +) +from os.path import * + + +def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, flags): + if not name: + name = filenamesof(srcs)[1] + + 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 + + normalrule( + replaces=self, + ins=srcs, + deps=deps, + outs=[outleaf], + label=label, + commands=commands, + 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", +): + 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", +): + cfileimpl( + self, name, srcs, deps, suffix, commands, label, "cxxfile", "cxxflags" + ) + + +def findsources(name, srcs, deps): + ins = [] + 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]), + 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", +): + for f in filenamesof(srcs): + if f.endswith(".h"): + deps += [f] + + normalrule( + replaces=self, + ins=findsources(name, srcs, deps), + outs=[basename(name) + ".a"], + label=label, + commands=commands, + ) + + dirs = set([dirname(f) for f in filenamesof(hdrs)]) + + self.clibrary.hdrs = hdrs + self.clibrary.dirs = dirs + + +def programimpl(self, name, srcs, deps, commands, label, filerule, kind): + libraries = [d.outs for d in deps if hasattr(d, "clibrary")] + + for f in filenamesof(srcs): + if f.endswith(".h"): + deps += [f] + + normalrule( + replaces=self, + ins=findsources(name, srcs, deps), + outs=[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.ldflags}"], + label="CLINK", +): + 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", +): + programimpl(self, name, srcs, deps, commands, label, cxxfile, "cxxprogram") 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/gpp.py b/build/gpp.py new file mode 100644 index 00000000..4c87b5eb --- /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, + outs=[self.localname + ".i"], + commands=[ + "gpp --nostdinc -U '' '' '(' ',' ')' '(' ')' '$$' '' -M '$$' '\\n' ' ' ' ' '\\n' '(' ')' " + + (" ".join(hdrs)) + + " -o {outs} {ins[0]}" + ], + ) diff --git a/build/nasm.py b/build/nasm.py new file mode 100644 index 00000000..74174ed1 --- /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/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/tass64.py b/build/tass64.py new file mode 100644 index 00000000..28ae843f --- /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/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/build/yacc.py b/build/yacc.py new file mode 100644 index 00000000..39481c54 --- /dev/null +++ b/build/yacc.py @@ -0,0 +1,23 @@ +from build.ab2 import normalrule, Rule, Targets + + +@Rule +def yacc(self, name, srcs: Targets = []): + normalrule( + replaces=self, + ins=srcs, + outs=["y.tab.c", "y.tab.h"], + 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, + outs=["lexer.c"], + commands=["flex -8 -Cem -s -t {ins[0]} > {outs[0]}"], + label="FLEX", + ) diff --git a/config.py b/config.py new file mode 100644 index 00000000..e3ed5441 --- /dev/null +++ b/config.py @@ -0,0 +1,28 @@ +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") +has_qemuarm = enable_if("qemu-arm") +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/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/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/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/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/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/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/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/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.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/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/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. 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/examples/build.py b/examples/build.py new file mode 100644 index 00000000..6b6fd288 --- /dev/null +++ b/examples/build.py @@ -0,0 +1,28 @@ +from src.build import cowgol +from src.toolchains import TOOLCHAINS +from build.ab2 import export + +PROGRAMS = [ + "argv", + "file", + "filetester", + "helloworld", + "icando", + "mandel", +] + +items = {} +for toolchain in TOOLCHAINS: + toolchain.materialise() + 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/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/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/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/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/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/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.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/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.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/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/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/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/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/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/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/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.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/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/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 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/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/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/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.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/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.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/build.py b/src/build.py new file mode 100644 index 00000000..00cc4bad --- /dev/null +++ b/src/build.py @@ -0,0 +1,165 @@ +from build.ab2 import ( + Rule, + Target, + Targets, + export, + normalrule, + filenamesof, + filenameof, +) +from build.c import cprogram +from os.path import * +from types import SimpleNamespace +import config + + +@Rule +def cowlib( + self, + name, + srcs: Targets = [], + deps: 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, + outs=[self.localname + ".cob"], + commands=[ + "scripts/quiet {ins[0]} " + + (" ".join(flags)) + + " {ins[1]} {outs[0]}" + ], + label="COWFE-" + toolchain.localname.upper(), + ) + + normalrule( + replaces=self, + ins=[toolchain.cowbe, cob], + outs=[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] + [coos], + outs=[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]) + + +@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=[toolchain.cowwrap, src], + outs=["cowgol.coo"], + label="COWWRAP-" + toolchain.localname.upper(), + commands=["scripts/quiet {ins[0]} {ins[1]} {outs}"], + ) + + +normalrule( + name="midcodesfecoh", + ins=[ + "scripts/mkmidcodescoh.lua", + "scripts/libcowgol.lua", + "src/midcodes.coh.tab", + ], + outs=["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", + ], + outs=["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", + ], + outs=["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", + ], + outs=["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", + ], + outs=["cobin.coh"], + commands=["lua {ins[0]} -- {ins[2]} {outs[0]}"], + label="MKCOBIN", +) 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/cowasm/build.py b/src/cowasm/build.py new file mode 100644 index 00000000..c99bb15d --- /dev/null +++ b/src/cowasm/build.py @@ -0,0 +1,23 @@ +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: + name = "cowasm-for-" + arch + "-with-" + toolchain.localname + items[name] = cowgol( + name=name, + toolchain=toolchain, + srcs=[ + "./arch" + arch + ".cow", + "./cowasm.coh", + "./stdsyms.coh", + ], + ) + +export(name="cowasm", items=items) 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/cowbdmp/build.py b/src/cowbdmp/build.py new file mode 100644 index 00000000..85bcace0 --- /dev/null +++ b/src/cowbdmp/build.py @@ -0,0 +1,15 @@ +from build.ab2 import normalrule +from src.build import cowgol +from src.toolchains import TOOLCHAINS + +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/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/cowbe/build.py b/src/cowbe/build.py new file mode 100644 index 00000000..9e25119c --- /dev/null +++ b/src/cowbe/build.py @@ -0,0 +1,60 @@ +from build.ab2 import normalrule, export +from src.build import cowgol +from src.toolchains import TOOLCHAINS +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, []), + ) + +items = {} +for toolchain in TOOLCHAINS: + for arch in ARCHS: + name = "cowbe-for-" + arch + "-with-" + toolchain.localname + items["bin/" + name] = cowgol( + name=name, + 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", + ], + ) + +export(name="cowbe", items=items) 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/cowdis/build.py b/src/cowdis/build.py new file mode 100644 index 00000000..b4b4017a --- /dev/null +++ b/src/cowdis/build.py @@ -0,0 +1,15 @@ +from build.ab2 import normalrule +from src.build import cowgol +from src.toolchains import TOOLCHAINS + +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/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/cowfe/build.py b/src/cowfe/build.py new file mode 100644 index 00000000..711984e4 --- /dev/null +++ b/src/cowfe/build.py @@ -0,0 +1,56 @@ +from build.ab2 import normalrule, export +from src.build import cowgol +from src.toolchains import TOOLCHAINS +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"], + outs=["arch.coh"], + commands=["cp {ins} {outs}"], + label="COPY", + ) + +items = {} +for toolchain in TOOLCHAINS: + for arch in ARCHS: + name = "cowfe-for-" + arch + "-with-" + toolchain.localname + items[name] = 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", + ], + ) + +export(name="cowfe", items=items) 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/cowlink/build.py b/src/cowlink/build.py new file mode 100644 index 00000000..31c9d738 --- /dev/null +++ b/src/cowlink/build.py @@ -0,0 +1,51 @@ +from build.ab2 import normalrule, export +from src.build import cowgol +from src.toolchains import TOOLCHAINS + +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"], + outs=["archlink.coh"], + commands=["cp {ins} {outs}"], + label="COPY", + ) + +items = {} +for toolchain in TOOLCHAINS: + for arch in ARCHS: + name = "cowlink-for-" + arch + "-with-" + toolchain.localname + items[name] = 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", + ], + ) +export(name="cowlink", items=items) 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/cowwrap/build.py b/src/cowwrap/build.py new file mode 100644 index 00000000..13f9a5ce --- /dev/null +++ b/src/cowwrap/build.py @@ -0,0 +1,18 @@ +from src.build import cowgol, export +from src.toolchains import TOOLCHAINS + +items = {} +for toolchain in TOOLCHAINS: + name = "cowwrap-with-" + toolchain.localname + items[name] = cowgol( + name=name, + toolchain=toolchain, + srcs=[ + "include/coodecls.coh", + "./main.cow", + "./emitter.coh", + "./reader.coh", + ], + ) + +export(name="cowwrap", items=items) 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/src/misc/build.py b/src/misc/build.py new file mode 100644 index 00000000..4359b20a --- /dev/null +++ b/src/misc/build.py @@ -0,0 +1,15 @@ +from build.ab2 import normalrule +from src.build import cowgol +from src.toolchains import TOOLCHAINS + +PROGRAMS = ["basicify"] + +for toolchain in TOOLCHAINS: + for program in PROGRAMS: + cowgol( + name=program + "-with-" + toolchain.localname, + toolchain=toolchain, + srcs=[ + "./" + program + ".cow", + ], + ) 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.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/tests/build.py b/tests/build.py new file mode 100644 index 00000000..672cbfed --- /dev/null +++ b/tests/build.py @@ -0,0 +1,87 @@ +from build.ab2 import normalrule, Rule, Target, export +from src.build import cowgol +from src.toolchains import TOOLCHAINS + +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", +] + + +@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/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/apout/build.py b/third_party/apout/build.py new file mode 100644 index 00000000..a94b3480 --- /dev/null +++ b/third_party/apout/build.py @@ -0,0 +1,36 @@ +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.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/djlink/build.py b/third_party/djlink/build.py new file mode 100644 index 00000000..cb16c0a4 --- /dev/null +++ b/third_party/djlink/build.py @@ -0,0 +1,62 @@ +from build.c import cxxprogram +from build.ab2 import export, Rule, Targets, normalrule + +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", + ], +) + +export( + name="djlink-programs", + items={ + "bin/objdump": "+objdump", + "bin/bindiff": "+bindiff", + "bin/djlink": "+djlink", + }, +) + + +@Rule +def djlink(self, name, srcs: Targets = []): + normalrule( + replaces=self, + 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/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/emu2/build.py b/third_party/emu2/build.py new file mode 100644 index 00000000..b731d236 --- /dev/null +++ b/third_party/emu2/build.py @@ -0,0 +1,20 @@ +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.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/lemon/build.py b/third_party/lemon/build.py new file mode 100644 index 00000000..ad348e1c --- /dev/null +++ b/third_party/lemon/build.py @@ -0,0 +1,34 @@ +from build.ab2 import Rule, Target, normalrule +from build.c import cprogram + +cprogram( + name="lemon", + srcs=["./lemon.c"], +) + +cprogram( + name="lemon-cowgol", + srcs=["./lemon-cowgol.c"], +) + + +@Rule +def lemon(self, name, src: Target = None): + normalrule( + replaces=self, + 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", + ) + + +@Rule +def lemoncowgol(self, name, src: Target = None): + normalrule( + replaces=self, + 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/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); 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/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/musashi/build.py b/third_party/musashi/build.py new file mode 100644 index 00000000..ae8db58a --- /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"], + outs=["m68kops.c", "m68kops.h"], + commands=["{ins[0]} {dirname(outs[0])} {ins[1]} > /dev/null"], + label="MUSASHILIB", +) + + +@Rule +def musashilib(self, name, m68kconf: Target = None): + clibrary( + replaces=self, + 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/rc2014emu/build.lua b/third_party/rc2014emu/build.lua deleted file mode 100644 index e69de29b..00000000 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/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/third_party/zmac/build.py b/third_party/zmac/build.py new file mode 100644 index 00000000..911ca726 --- /dev/null +++ b/third_party/zmac/build.py @@ -0,0 +1,35 @@ +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", + srcs=["third_party/zmac/zmac.y"], +) + +cprogram( + name="zmac", + 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" + + normalrule( + replaces=self, + ins=["third_party/zmac", srcs[0]], + outs=[self.localname + ".cim"], + commands=[ + "{ins[0]} -j -m " + + archflag + + " -o {outs[0]} -o {outs[0]}.lst {ins[1]}" + ], + label="ZMAC", + ) 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/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.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/build.py b/tools/build.py new file mode 100644 index 00000000..ed05a9ac --- /dev/null +++ b/tools/build.py @@ -0,0 +1,54 @@ +from build.c import cprogram +from build.ab2 import Rule, Target, Targets, normalrule, flatten, filenamesof + +cprogram( + name="mkadfs", + srcs=["./mkadfs.c"], +) + +cprogram( + name="mkdfs", + srcs=["./mkdfs.c"], +) + + +@Rule +def objectify(self, name, src: Target = None, symbol=None): + normalrule( + replaces=self, + ins=["tools/objectify", src], + outs=[symbol + ".c"], + 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", + ) + + +@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/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/cpmemu/build.py b/tools/cpmemu/build.py new file mode 100644 index 00000000..0fcb8888 --- /dev/null +++ b/tools/cpmemu/build.py @@ -0,0 +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", + srcs=[ + "./main.c", + "./emulator.c", + "./fileio.c", + "./biosbdos.c", + "+biosbdosdata", + ], + vars={"+ldflags": ["-lz80ex", "-lz80ex_dasm", "-lreadline"]}, +) 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/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"]}, +) 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/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/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/newgen/build.py b/tools/newgen/build.py new file mode 100644 index 00000000..0ef8c248 --- /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=["tools/newgen", preprocessed], + outs=["inssel.coh", "inssel.decl.coh"], + commands=["{ins[0]} {ins[1]} {outs[0]} {outs[1]}"], + label="NEWGEN", + ) 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/obpemu/build.py b/tools/obpemu/build.py new file mode 100644 index 00000000..78c9d0c9 --- /dev/null +++ b/tools/obpemu/build.py @@ -0,0 +1,7 @@ +from build.c import cprogram + +cprogram( + name="obpemu", + srcs=["./emulator.c", "./main.c"], + vars={"+ldflags": "-lreadline"}, +) 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 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" } -} - - - diff --git a/tools/tubeemu/build.py b/tools/tubeemu/build.py new file mode 100644 index 00000000..fee3995f --- /dev/null +++ b/tools/tubeemu/build.py @@ -0,0 +1,3 @@ +from build.c import cprogram + +cprogram(name="tubeemu", srcs=["./bbctube.c"], deps=["third_party/lib6502"])