-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
262 lines (224 loc) · 6.45 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# T3X/0 Makefile
# Nils M Holm, 2022, 2023, 2024
# Public domain / 0BSD license
# Fixes for Linux, Darwin by Rogerio Senna
V=17
# Detect OS
#
ifeq ($(OS),Windows_NT) # works for Windows XP, 2000, 7, Vista, 10, 11...
detected_OS := Windows_NT
else
detected_OS := $(shell uname 2> /dev/null)
endif
$(info Detected OS: $(or $(detected_OS),(unknown)))
# If OS == Linux, check if cc has 32-bit support
# TODO: assuming installed Linux is always 64-bit, might not work on plain 32-bit Linux
#
ifeq ($(detected_OS),Linux)
ifeq (,$(wildcard /usr/lib32/libc.a))
$(warning No x86 support, please install gcc-multilib)
endif
endif
# TCVM Options
#
# CONSOLE will include console I/O functions in the TCVM.
# Requires the curses library. Not needed for bootstrapping,
# but only for running programs that use the CONSOLE module
# on the TCVM. If -DCONSOLE causes trouble, just remove its
# OPTS and LIBS lines.
#
OPTS=
LIBS=
OPTS+= -DCONSOLE
LIBS+= library/console.c -lcurses
# Flags for compiling T3X/0 assembly output
#
CFLAGS=-std=c89 # force C89 rules
ifneq ($(detected_OS),Darwin)
CFLAGS+=-m32 # force 32-bit compilation (but not on macOS)
endif
# CFLAGS+=-fPIC # get rid of stupid linker errors
# CFLAGS+=-Wl,-z,notext # get rid of stupid linker errors
# Where to keep the T3X libraries
#
T3XDIR= /usr/local/t3x/0
# Where the binaries go
#
BINDIR= /usr/local/bin
# Host platform. Just keep "unix".
#
HOST= unix
########## nothing to configure past this line ##########
all: tcvm txtrn.tc
all-tcode: tcvm txtrn.tc tx-dos.tc tx-cpm.tc
all-native: tcvm txtrn.tc tx-$(HOST) tx-dos tx-cpm tx-tcvm
# When something goes wrong during cross-compilation, this
# target will reset the code generator and runtime links.
#
reset:
ln -fs cgtcvm.t cg.t
ln -fs txtcvm.t t3x.t
ln -fs txemtbin.t txemit.t
# Regular bootstrap using a pre-compiled Tcode/0 image
#
txtrn.tc: txtrn.t cg.t txemit.t tcvm bin/txtrn0.tc
./tcvm bin/txtrn0.tc txtrn
# Alternative bootstrap using an existing T3Xr7 compiler
#
alt: txtrn.t cg.t txemit.t txtrn0
txx txtrn0 txtrn
txtrn0: txtrn0.t
tx txtrn0.t
# The Tcode/0 VM
#
tcvm: tcvm.c
cc $(CFLAGS) -O2 -g $(OPTS) -o tcvm tcvm.c $(LIBS)
# Triple test of the Tcode/0 compiler
#
triple: txtrn.tc
./tcvm txtrn.tc txtrn txtrn1
./tcvm txtrn1.tc txtrn txtrn2
cmp txtrn1.tc txtrn2.tc
rm -f txtrn1.tc txtrn2.tc
# Run the test suite under the Tcode/0 VM
#
test: programs/test.t tcvm txtrn.tc
./tcvm txtrn.tc programs/test test
./tcvm test.tc
# Native CP/M-Z80 compiler
#
tx-cpm.com:
bin/build.sh cpm cpm
# Native DOS-8086 compiler
#
tx-dos.com:
bin/build.sh dos dos
# HOST -> DOS-8086 cross compiler
#
tx-dos:
bin/build.sh $(HOST) dos
# HOST -> CP/M-Z80 cross compiler
#
tx-cpm:
bin/build.sh $(HOST) cpm
# HOST -> TCVM cross compiler
#
tx-tcvm:
bin/build.sh $(HOST) tcvm
# Native HOST compiler
#
tx-$(HOST):
bin/build.sh $(HOST) $(HOST)
# TCVM -> DOS compiler
#
tx-dos.tc:
bin/build.sh tcvm dos
# TCVM -> CP/M compiler
#
tx-cpm.tc:
bin/build.sh tcvm cpm
# Triple test of the Unix-386 compiler
#
unix-triple: tx-unix
ln -fs txemtsrc.t txemit.t
ln -fs targets/cgunx386.t cg.t
ln -fs targets/txunx386.t t3x.t
./tx-unix txtrn tx-unix2
cc $(CFLAGS) -s -o tx-unix2 tx-unix2.s targets/ux386lib.c && \
rm tx-unix2.s
./tx-unix2 txtrn tx-unix3
cc $(CFLAGS) -s -o tx-unix3 tx-unix3.s targets/ux386lib.c && \
rm tx-unix3.s
make reset
cmp tx-unix2 tx-unix3 && rm tx-unix2 tx-unix3
# Triple test of the FreeBSD-386 compiler
#
fbsd-triple:
bin/build.sh fbsd fbsd
ln -fs txemtsrc.t txemit.t
ln -fs targets/cgfbd386.t cg.t
ln -fs targets/txfbd386.t t3x.t
./tx-fbsd txtrn tx-fbsd2
as -32 -o tx-fbsd2.o tx-fbsd2.s
ld -o tx-fbsd2 tx-fbsd2.o
rm -f tx-fbsd2.[so]
./tx-fbsd2 txtrn tx-fbsd3
as -32 -o tx-fbsd3.o tx-fbsd3.s
ld -o tx-fbsd3 tx-fbsd3.o
rm -f tx-fbsd3.[so]
make reset
cmp tx-fbsd2 tx-fbsd3 && rm tx-fbsd2 tx-fbsd3
# System-wide installation
# Use this with HOST=unix or HOST=fbsd
#
install-native: all-native tx-dos.tc tx-cpm.tc
install -d $(T3XDIR)
install -d $(T3XDIR)/cpmz80
install -d $(T3XDIR)/dos86c
install -d $(T3XDIR)/fbd386
install -d $(T3XDIR)/unx386
install -c -m 0644 txtrn.tc $(T3XDIR)
install -c -m 0644 txtcvm.t $(T3XDIR)/t3x.t
install -c -m 0644 targets/txunx386.t $(T3XDIR)/unx386/t3x.t
install -c -m 0644 targets/ux386lib.c $(T3XDIR)/unx386
install -c -m 0644 targets/txfbd386.t $(T3XDIR)/fbd386/t3x.t
install -c -m 0644 targets/txcpmz80.t $(T3XDIR)/cpmz80/t3x.t
install -c -m 0644 targets/txdos86c.t $(T3XDIR)/dos86c/t3x.t
install -c -m 0644 library/*.t $(T3XDIR)
install -c -m 0644 library/console.tvm $(T3XDIR)/console.t
install -c -m 0644 library/console.cpm $(T3XDIR)/cpmz80/console.t
install -c -m 0644 library/console.dos $(T3XDIR)/dos86c/console.t
install -c -m 0644 library/console.unx $(T3XDIR)/unx386/console.t
install -c -m 0644 library/console.c $(T3XDIR)/unx386/console.c
install -c tx-$(HOST) $(T3XDIR)
install -c tx-dos $(T3XDIR)
install -c tx-cpm $(T3XDIR)
install -c tx-tcvm $(T3XDIR)
install -c tx-dos.tc $(T3XDIR)
install -c tx-cpm.tc $(T3XDIR)
install -c tcvm $(BINDIR)
install -c bin/tx0.sh $(BINDIR)/tx0
# System-wide installation
# Use this with HOST=unix to also install the fbsd backend
#
install-fbsd-native: install-native
bin/build.sh fbsd fbsd
install -d $(T3XDIR)
install -d $(T3XDIR)/fbd386
install -c -m 0644 targets/txfbd386.t $(T3XDIR)/fbd386/t3x.t
install -c tx-fbsd $(T3XDIR)
# System-wide minimum (bytecode) installation
# Use this if there is no native code support for your system
#
install-tcode: all-tcode
install -d $(T3XDIR)
install -d $(T3XDIR)/cpmz80
install -d $(T3XDIR)/dos86c
install -c -m 0644 txtrn.tc $(T3XDIR)
install -c -m 0644 txtcvm.t $(T3XDIR)/t3x.t
install -c -m 0644 targets/txcpmz80.t $(T3XDIR)/cpmz80/t3x.t
install -c -m 0644 targets/txdos86c.t $(T3XDIR)/dos86c/t3x.t
install -c -m 0644 library/* $(T3XDIR)
install -c tx-dos.tc $(T3XDIR)
install -c tx-cpm.tc $(T3XDIR)
install -c tcvm $(BINDIR)
install -c bin/tx0.sh $(BINDIR)/tx0
csums:
txsum -u <_checksums >_checksums.new
mv -f _checksums.new _checksums
mksums: clean
find . -type f | grep -v t3x0-$V.zip | grep -v _checksums \
| txsum -m >_checksums
arc: clean
(cd ..; zip -9r t3x0-$V.zip t3x0)
mv ../t3x0-$V.zip .
clean:
rm -f txtrn0 txtrn1.tc txtrn.tc \
tx-tcvm.tc tx-tcvm.com tx-tcvm \
tx-cpm.tc tx-cpm.com tx-cpm \
tx-dos.tc tx-dos.com tx-dos \
tx-dos.tc tx-cpm.tc \
tx-fbsd.tc tx-fbsd \
tx-unix.tc tx-unix \
cpmfile.tc dosfile.tc \
tcvm test.tc *.core core t3x0-$V.zip