/
Makefile
305 lines (223 loc) · 6.25 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# C compiler options
CFLAGS += -Wall -Werror -std=c89 -ansi -Wpedantic -Wextra
# global defaults
INFO := printf '* \033[1;33m%s\033[0;0m\n'
WARN := printf '* \033[1;35m%s\033[0;0m\n'
CHECKMEMORY := $(INFO) 'Checking memory limits' ; sh scripts/check-memory.sh
DR0 = forth/library.img
DR1 = forth/data.img
COMPLETEDR1FILE = mv $@.io $@ ; $(INFO) 'Done'
EMPTYDR1FILE := $(INFO) 'Clearing DR1' ; printf '' >
MAMEOPTS := -rompath roms -video opengl -resolution 1024x768 -skip_gameinfo -nomax -window
PROMPT := sh scripts/prompt.sh
SERIALBAUD := 9600
START := sh scripts/start.sh /dev/stdin /dev/stdout
STARTMAME := $(INFO) 'Starting MAME' ; $(START) mame.pid mame
STARTDISCMSG := $(INFO) 'Starting disc'
STOPDISC := $(INFO) 'Stopping disc' ; sh scripts/stop.sh disc.pid
STOPMAME := $(INFO) 'Stopping MAME' ; sh scripts/stop.sh mame.pid
WAITUNTILSAVED := $(INFO) 'Waiting until saved' ; sh scripts/wait-until-saved.sh
# local OS
UNAME_S := $(shell uname -s)
ifneq ($(filter CYGWIN%,$(UNAME_S)),)
LDFLAGS += -t gcc.ld
OPER := cygwin
SERIALPORT := /dev/ttyS2
STAT := stat -c %s
endif
ifeq ($(UNAME_S),Darwin)
OPER := darwin
PLAY := afplay
SERIALPORT := /dev/cu.usbserial-FT2XIBOF
STAT := stat -f%z
endif
ifeq ($(UNAME_S),Linux)
LDFLAGS += -t gcc.ld
OPER := linux
PLAY := aplay
SERIALPORT := /dev/ttyUSB0
STAT := stat -c %s
endif
ifneq ($(filter MINGW%,$(UNAME_S)),)
CC := gcc
OPER := mingw
endif
# local processor architecture
UNAME_M := $(shell uname -m)
PROC := $(UNAME_M)
# 32 bit kernel on 64 bit host (e.g., container)
ifeq (${OPER},linux)
ifeq (${PROC},x86_64)
ifeq ($(shell getconf LONG_BIT),32)
PROC := i686
endif
endif
# Raspberry Pi 2 onwards
ifeq (${PROC},armv7l)
PROC := armv6l
endif
endif
# local system
SYSTEM := $(OPER)-$(PROC)
# default build is local system platform
TARGET := $(SYSTEM)
# local system target executables
DISC := $(SYSTEM)/disc
ORTER := $(SYSTEM)/orter
ORTERFORTH := $(SYSTEM)/orterforth
# scripts for disc
STARTDISC := $(STARTDISCMSG) && $(START) disc.pid $(DISC)
STARTDISCTCP := $(STARTDISC) tcp 5705
# local system object files
SYSTEMDEPS := \
$(SYSTEM)/inst.o \
$(SYSTEM)/io.o \
$(SYSTEM)/main.o \
$(SYSTEM)/persci.o \
$(SYSTEM)/system.o
# default target
.PHONY : default
default : build
# local system disc server executable
$(DISC) : \
$(SYSTEM)/orter_io.o \
$(SYSTEM)/orter_pty.o \
$(SYSTEM)/orter_serial.o \
$(SYSTEM)/orter_tcp.o \
$(SYSTEM)/persci.o \
disc.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ -lutil
# === LOCAL SYSTEM ===
# SYSTEMOPTION := assembly
SYSTEMOPTION := default
ifeq ($(TARGET),$(SYSTEM))
ifneq ($(OPTION),)
SYSTEMOPTION := $(OPTION)
endif
endif
# assembly option config:
ifeq ($(SYSTEMOPTION),assembly)
# add the assembly code to deps
SYSTEMDEPS += $(SYSTEM)/rf_$(PROC).o
# tell C code it is there
CPPFLAGS += -DRF_ASSEMBLY
endif
# default option config:
ifeq ($(SYSTEMOPTION),default)
# add C code to deps
SYSTEMDEPS += $(SYSTEM)/rf.o
endif
# local system executable
$(ORTERFORTH) : $(SYSTEMDEPS)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
# local system build dir
$(SYSTEM) :
mkdir $@
# build all local system executables
.PHONY : $(SYSTEM)-build
$(SYSTEM)-build : \
$(DISC) \
$(ORTER) \
$(ORTERFORTH)
# clean
.PHONY : $(TARGET)-clean
$(TARGET)-clean :
rm -rf $(TARGET)/*
rm -f model.img
rm -f model.inc
# build and run
.PHONY : $(SYSTEM)-run
$(SYSTEM)-run : $(ORTERFORTH) $(DR0) $(DR1)
@$^
$(SYSTEM)/inst.o : inst.c rf.h system.inc | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/io.o : io.c rf.h system.inc | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/main.o : main.c model.inc persci.h rf.h system.inc | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/persci.o : persci.c persci.h | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/rf.o : rf.c rf.h system.inc | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/rf_$(PROC).o : rf_$(PROC).s | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(SYSTEM)/system.o : system.c rf.h system.inc persci.h | $(SYSTEM)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
# audio for tape load
.PHONY : audio
audio : $(TARGET)/orterforth.wav
# help
.PHONY : $(TARGET)-help
$(TARGET)-help :
@if [ "$(TARGET)" = "$(SYSTEM)" ] ; then more help.txt ; else more target/$(TARGET)/help.txt ; fi
# Forth source file to disc image
%.img : %.fs | $(DISC)
$(DISC) create < $< > $@.io
mv $@.io $@
# build
.PHONY : build
build : $(TARGET)-build
# clean
.PHONY : clean
clean : $(TARGET)-clean
# empty disc image to use as default DR1
forth/data.img :
touch $@
# run disc on physical serial port
.PHONY : disc
disc : $(DISC) $(DR0) $(DR1)
@$(DISC) serial $(SERIALPORT) $(SERIALBAUD) $(DR0) $(DR1)
# help
.PHONY : help
help : $(TARGET)-help
include orter/orter.mk
include target/amiga/amiga.mk
include target/apple2/apple2.mk
include target/bbc/bbc.mk
include target/c64/c64.mk
include target/cpm/cpm.mk
include target/dragon/dragon.mk
#include target/esp32c3/esp32c3.mk
include target/m100/m100.mk
include target/pico/pico.mk
include target/ql/ql.mk
include target/rc2014/rc2014.mk
include target/spectrum/spectrum.mk
include target/z88/z88.mk
include target/zx81/zx81.mk
# symlink to local
.PHONY : link
link : $(ORTER) $(ORTERFORTH)
ln -fs "$$(pwd)/$(ORTER)" /usr/local/bin/orter
ln -fs "$$(pwd)/$(ORTERFORTH)" /usr/local/bin/orterforth
# install to local
.PHONY : install
install : $(ORTER) $(ORTERFORTH)
cp "$(ORTER)" /usr/local/bin/orter
cp "$(ORTERFORTH)" /usr/local/bin/orterforth
# disc image to C include
model.inc : model.img | $(ORTER)
# xxd -i $< > $@.io
$(ORTER) hex include model_img < $< > $@.io
mv $@.io $@
# general rule for missing ROM files
roms/% :
@[ -f $@ ] || (echo "ROM file required: $@" && exit 1)
# run
.PHONY : run
run : $(TARGET)-run
# run working script
.PHONY : script
script : scripts/script.sh
@[ -f $< ] && sh $<
scripts/script.sh :
@echo "Create the file $@ for your working script and run it using: make script"
# basic test
.PHONY : test
test : $(ORTERFORTH) forth/test.img
@echo 'EMPTY-BUFFERS 1 LOAD MON' | $(ORTERFORTH) forth/test.img
# uninstall from local
.PHONY : uninstall
uninstall :
rm -f /usr/local/bin/orter
rm -f /usr/local/bin/orterforth