Skip to content

Commit 0bbc304

Browse files
committed
Enough works to build a simple boot.s.
1 parent cf1f432 commit 0bbc304

File tree

18 files changed

+305
-24
lines changed

18 files changed

+305
-24
lines changed

build.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
from build.ab import export
22

33
export(
4-
name="all",
4+
name="common",
55
deps=[
6+
"util/ack+all",
7+
"lang/cem/cemcom-ansi+all",
68
"util/amisc+all",
79
"util/arch+all",
810
"util/led+all",
9-
"util/ncgg",
10-
"util/LLgen",
11-
"lang/cem/cemcom-ansi+all",
11+
],
12+
)
13+
14+
export(
15+
name="all",
16+
deps=[
17+
"plat/pc86+all",
18+
".+common",
1219
],
1320
)

build/ab.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ def simplerule(
557557
def export(self, name=None, items: TargetsMap = {}, deps: Targets = []):
558558
ins = []
559559
outs = []
560+
rules = []
560561
for dest, src in items.items():
561562
dest = self.targetof(dest)
562563
outs += [dest]
@@ -568,23 +569,23 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []):
568569
len(srcs) == 1
569570
), "a dependency of an exported file must have exactly one output file"
570571

571-
subrule = simplerule(
572+
rule = simplerule(
572573
name=f"{self.localname}/{destf}",
573574
cwd=self.cwd,
574575
ins=[srcs[0]],
575576
outs=[destf],
576577
commands=["$(CP) -H %s %s" % (srcs[0], destf)],
577578
label="",
578579
)
579-
subrule.materialise()
580-
581-
simplerule(
582-
replaces=self,
583-
ins=outs + deps,
584-
outs=["=sentinel"],
585-
commands=["touch $[outs[0]]"],
586-
label="EXPORT",
587-
)
580+
rule.materialise()
581+
rules += [rule]
582+
583+
self.ins = []
584+
self.outs = rules + deps
585+
586+
emit("")
587+
emit(".PHONY:", name)
588+
emit(name, ":", *filenamesof(outs), *filenamesof(deps))
588589

589590

590591
def main():

build/ack.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from build.toolchain import Toolchain
2+
from build.c import cfile
3+
4+
5+
class AckToolchain(Toolchain):
6+
PREFIX = "ACK"
7+
CC = ["$(INSDIR)/bin/ack $(ACKCFLAGS) -m$[plat] -c -o $[outs[0]] $[ins[0]]"]
8+
9+
10+
def ackcfile(name, plat=None, **kwargs):
11+
kwargs["deps"] = kwargs.get("deps", []) + [
12+
f"plat/{plat}+tools",
13+
"util/ack+all",
14+
]
15+
kwargs["args"] = kwargs.get("args", {}) | {"plat": plat}
16+
cfile(name=name, toolchain=AckToolchain, **kwargs)

build/c.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323

2424
Toolchain.CC = ["$(CC) -c -o $[outs[0]] $[ins[0]] $(CFLAGS) $[cflags]"]
25+
Toolchain.CPP = ["$(CC) -E -P -o $[outs] $[cflags] -x c $[ins]"]
2526
Toolchain.CXX = ["$(CXX) -c -o $[outs[0]] $[ins[0]] $(CFLAGS) $[cflags]"]
2627
Toolchain.AR = ["$(AR) cqs $[outs[0]] $[ins]"]
2728
Toolchain.ARXX = ["$(AR) cqs $[outs[0]] $[ins]"]
@@ -36,6 +37,7 @@
3637
HostToolchain.CC = [
3738
"$(HOSTCC) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]"
3839
]
40+
HostToolchain.CPP = ["$(HOSTCC) -E -P -o $[outs] $[cflags] -x c $[ins]"]
3941
HostToolchain.CXX = [
4042
"$(HOSTCXX) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]"
4143
]
@@ -519,3 +521,44 @@ def hostcxxprogram(
519521
toolchain.PREFIX + label,
520522
cxxfilerule,
521523
)
524+
525+
526+
def _cppfileimpl(self, name, srcs, deps, cflags, toolchain):
527+
hdr_deps = _indirect(deps, "cheader_deps")
528+
cflags = collectattrs(
529+
targets=hdr_deps, name="caller_cflags", initial=cflags
530+
)
531+
532+
simplerule(
533+
replaces=self,
534+
ins=srcs,
535+
outs=[f"={self.localname}"],
536+
deps=deps,
537+
commands=toolchain.CPP,
538+
args={"cflags": cflags},
539+
label=toolchain.PREFIX + "CPPFILE",
540+
)
541+
542+
543+
@Rule
544+
def cppfile(
545+
self,
546+
name,
547+
srcs: Targets = [],
548+
deps: Targets = [],
549+
cflags=[],
550+
toolchain=Toolchain,
551+
):
552+
_cppfileimpl(self, name, srcs, deps, cflags, toolchain)
553+
554+
555+
@Rule
556+
def hostcppfile(
557+
self,
558+
name,
559+
srcs: Targets = [],
560+
deps: Targets = [],
561+
cflags=[],
562+
toolchain=HostToolchain,
563+
):
564+
_cppfileimpl(self, name, srcs, deps, cflags, toolchain)

h/build.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from build.ab import simplerule
22
from build.c import clibrary
33

4+
simplerule(
5+
name="em_path",
6+
ins=[],
7+
outs=["=em_path.h"],
8+
commands=[
9+
"echo '#define EM_DIR \"$(PREFIX)\"' > $[outs]",
10+
"echo '#define ACK_PATH \"share/ack/descr\"' >> $[outs]",
11+
],
12+
)
13+
414
simplerule(
515
name="local",
616
ins=[],
@@ -27,7 +37,8 @@
2737
"cgg_cg.h",
2838
"em_reg.h",
2939
"stb.h",
40+
"con_float",
3041
]
3142
}
32-
| {"local.h": ".+local"},
43+
| {"local.h": ".+local", "em_path.h": ".+em_path"},
3344
)

mach/i86/ncg/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from build.c import clibrary
2+
3+
clibrary(name="ncg", hdrs={"mach.h": "./mach.h", "mach.c": "./mach.c"})

mach/proto/as/build.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include("first/bison.lua")
22

3-
definerule("build_as",
3+
44
{
55
arch = { type="string" },
66
deps = { type="targets", default={} },

mach/proto/as/build.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from build.ab import Rule, Targets, simplerule
2+
from build.utils import collectattrs
3+
from build.c import cprogram, clibrary, cppfile
4+
from build.yacc import bison
5+
6+
7+
@Rule
8+
def build_as(self, name, arch):
9+
archlib = clibrary(
10+
name=f"{self.localname}/arch",
11+
hdrs={
12+
k: f"mach/{arch}/as/{k}"
13+
for k in [
14+
"mach0.c",
15+
"mach1.c",
16+
"mach2.c",
17+
"mach3.c",
18+
"mach4.c",
19+
"mach5.c",
20+
]
21+
},
22+
)
23+
24+
preprocessedy = cppfile(
25+
name=f"{self.localname}/bisoninput",
26+
srcs=["mach/proto/as/comm2.y"],
27+
deps=["mach/proto/as/comm0.h", "mach/proto/as/comm1.h", "h", archlib],
28+
)
29+
30+
bisonfiles = bison(name=f"{self.localname}/bison", src=preprocessedy)
31+
32+
cprogram(
33+
replaces=self,
34+
srcs=[
35+
"mach/proto/as/comm0.h",
36+
"mach/proto/as/comm1.h",
37+
"mach/proto/as/comm3.c",
38+
"mach/proto/as/comm4.c",
39+
"mach/proto/as/comm5.c",
40+
"mach/proto/as/comm6.c",
41+
"mach/proto/as/comm7.c",
42+
"mach/proto/as/comm8.c",
43+
bisonfiles,
44+
],
45+
deps=["h", "modules/src/object", "modules/src/flt_arith", archlib],
46+
)

mach/proto/as/comm3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct outhead outhead = {
2020
O_MAGIC, O_STAMP, 0
2121
};
2222

23-
#include "y.tab.h"
23+
#include "bison.h"
2424

2525
item_t keytab[] = {
2626
{0, EXTERN, 0, ".define"},

mach/proto/as/comm4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "comm0.h"
1616
#include "comm1.h"
17-
#include "y.tab.h"
17+
#include "bison.h"
1818
#include "object.h"
1919
#include <errno.h>
2020

0 commit comments

Comments
 (0)