-
Notifications
You must be signed in to change notification settings - Fork 20
/
rules.mak
325 lines (258 loc) · 12 KB
/
rules.mak
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#
# FastBasic - Fast basic interpreter for the Atari 8-bit computers
# Copyright (C) 2017-2024 Daniel Serpell
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>
#
# Main compilation rules
all: $(ATR) $(COMPILER_COMMON) $(COMPILER_TARGET) $(COMPILER_MANIFESTS)
dist: $(ATR) $(ZIPFILE)
# Make sure that failed targets are deleted
.DELETE_ON_ERROR:
.PHONY: clean
clean:
$(Q)rm -f $(OBJS) $(LSTS) $(FILES) $(ATR) $(ZIPFILE) $(XEXS) $(MAPS) \
$(LBLS) $(SYNTP) $(COMPILER_HOST) $(FASTBASIC_TARGET_OBJ) \
$(FASTBASIC_HOST_DEPS) $(FASTBASIC_TARGET_DEPS) $(SYNTAX_PARSER_DEPS)\
$(SAMPLE_BAS:%.bas=build/gen/%.asm) \
$(FASTBASIC_HOST_OBJ) $(SYNTAX_PARSER_OBJ)
$(Q)rm -f $(TESTS_XEX) $(TESTS_ROM) $(TESTS_ASM) $(TESTS_OBJ) $(TESTS_ATB) $(TESTS_LBL) $(RUNTEST_OBJS) $(RUNTEST) $(TESTS_STAMP) $(RUNTEST_OBJS:.o=.d)
.PHONY: distclean
distclean: clean
$(Q)-rm -f build/gen/int/basic.asm build/gen/fp/basic.asm \
build/gen/int/basic.inc build/gen/fp/basic.inc \
build/gen/int/editor.asm build/gen/fp/editor.asm \
$(CMD_BAS_SRC) \
$(CMD_BAS_SRC:build/gen/%.bas=build/gen/fp/%.asm) \
$(CMD_BAS_SRC:build/gen/%.bas=build/gen/int/%.asm) \
$(COMPILER_HOST) $(COMPILER_TARGET) $(COMPILER_COMMON) \
$(COMPILER_MANIFESTS)
$(Q)printf "%s\n" $(BUILD_FOLDERS) | sort -r | while read folder; do \
test -d $$folder && rmdir $$folder || true ; done
# Build an ATR disk image using "mkatr".
$(ATR): $(DOS:%=$(DOSDIR)/%) $(FILES) | $(MKATR_HOST) build
$(ECHO) "Creating ATR disk image"
$(Q)$(MKATR_HOST) $@ $(DOSDIR) -b $^
# Build compiler ZIP file.
$(ZIPFILE): $(COMPILER_COMMON) $(COMPILER_TARGET) $(COMPILER_MANIFESTS) | build
$(CROSS)strip $(COMPILER_TARGET)
# This rule is complicated because we want to store only the paths
# relative to the compiler directory, not the full path of the build
# directory.
(cd build/compiler ; zip -9v ../../$@ $(COMPILER_COMMON:build/compiler/%=%) $(COMPILER_TARGET:build/compiler/%=%) $(COMPILER_MANIFESTS:build/compiler/%=%) )
# BAS sources also transformed to ATASCII (replace $0A with $9B)
build/disk/%.bas: samples/fp/%.bas | build/disk
$(Q)LC_ALL=C tr '\n' '\233' < $< > $@
build/disk/%.bas: samples/int/%.bas | build/disk
$(Q)LC_ALL=C tr '\n' '\233' < $< > $@
build/disk/%.bas: tests/%.bas | build/disk
$(Q)LC_ALL=C tr '\n' '\233' < $< > $@
# Transform a text file to ATASCII (replace $0A with $9B)
build/disk/%: % version.mk | build/disk
$(Q)$(SED) 's/%VERSION%/$(VERSION)/' < $< | LC_ALL=C tr '\n' '\233' > $@
build/disk/%.txt: %.md version.mk | build/disk
$(Q)$(SED) 's/%VERSION%/$(VERSION)/' < $< | LC_ALL=C awk 'BEGIN{for(n=0;n<127;n++)chg[sprintf("%c",n)]=128+n} {l=length($$0);for(i=1;i<=l;i++){c=substr($$0,i,1);if(c=="`"){x=1-x;if(x)c="\002";else c="\026";}else if(x)c=chg[c];printf "%c",c;}printf "\233";}' > $@
# Copy ".XEX" as ".COM"
build/disk/%.com: build/bin/%.xex | build/disk
$(Q)cp $< $@
# Parser generator for 6502
$(SYNTP): $(SYNTAX_PARSER_OBJ) | build/gen
$(ECHO) "Compile parser generator tool $@"
$(Q)$(CXX) $(HOST_CXXFLAGS) -o $@ $^
# Host compiler build
build/obj/cxx/%.o: src/compiler/%.cc | build/obj/cxx
$(ECHO) "Compile $<"
$(Q)$(CXX) $(HOST_CXXFLAGS) $(FB_CXX) -c -o $@ $<
$(FASTBASIC_HOST): $(FASTBASIC_HOST_OBJ) | build/bin
$(ECHO) "Linking host compiler"
$(Q)$(CXX) $(HOST_CXXFLAGS) $(FB_CXX) -o $@ $^
$(CA65_HOST): $(CA65_SRC) | build/bin
$(ECHO) "Compile CA65"
$(Q)$(CC) $(HOST_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(LD65_HOST): $(LD65_SRC) | build/bin
$(ECHO) "Compile LD65"
$(Q)$(CC) $(HOST_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(AR65_HOST): $(AR65_SRC) | build/bin
$(ECHO) "Compile AR65"
$(Q)$(CC) $(HOST_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(MKATR_HOST): $(MKATR_SRC) | mkatr/src build/bin
$(ECHO) "Compile MKATR"
$(Q)$(CC) $(HOST_CFLAGS) -o $@ $^
$(LSATR_HOST): $(LSATR_SRC) | mkatr/src build/bin
$(ECHO) "Compile LSATR"
$(Q)$(CC) $(HOST_CFLAGS) -o $@ $^
# Update mkatr submodule if not found
$(sort $(MKATR_SRC) $(LSATR_SRC) mkatr/src) &:
$(Q)git submodule update --init mkatr
# Target compiler build
ifeq ($(CROSS),)
# No cross-compilation, just copy host tools to target tools:
$(COMPILER_TARGET): build/compiler/%$(TGT_EXT): build/bin/%$(HOST_EXT) | build/compiler
$(Q)cp -f $< $@
else
# Cross-compilation: compile for target
build/obj/cxx-tgt/%.o: src/compiler/%.cc | build/obj/cxx-tgt
$(ECHO) "Compile target $<"
$(Q)$(CROSS)$(CXX) $(TARGET_CXXFLAGS) $(FB_CXX) -c -o $@ $<
$(FASTBASIC_TARGET): $(FASTBASIC_TARGET_OBJ) | build/compiler
$(ECHO) "Linking target compiler"
$(Q)$(CROSS)$(CXX) $(TARGET_CXXFLAGS) $(FB_CXX) -o $@ $^
$(CA65_TARGET): $(CA65_SRC) | build/compiler
$(ECHO) "Compile target CA65"
$(Q)$(CROSS)$(CC) $(TARGET_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(LD65_TARGET): $(LD65_SRC) | build/compiler
$(ECHO) "Compile target LD65"
$(Q)$(CROSS)$(CC) $(TARGET_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(AR65_TARGET): $(AR65_SRC) | build/compiler
$(ECHO) "Compile target AR65"
$(Q)$(CROSS)$(CC) $(TARGET_CFLAGS) $(CC65_CFLAGS) -o $@ $^
$(MKATR_TARGET): $(MKATR_SRC) | mkatr/src build/compiler
$(ECHO) "Compile target MKATR"
$(Q)$(CROSS)$(CC) $(TARGET_CFLAGS) -o $@ $^
$(LSATR_TARGET): $(LSATR_SRC) | mkatr/src build/compiler
$(ECHO) "Compile target LSATR"
$(Q)$(CROSS)$(CC) $(TARGET_CFLAGS) -o $@ $^
# Copy compatibility binaries
build/compiler/fb$(TGT_EXT): build/compiler/fastbasic$(TGT_EXT)
$(Q)cp -f $< $@
endif
# Windows manifests
build/%.manifest: compiler/utf8.manifest
$(Q)cp -f $< $@
# Generator for syntax file - 6502 version - FLOAT
build/gen/fp/basic.asm: $(SYNTAX_FP) $(SYNTP) | build/gen/fp
$(ECHO) "Creating FP parsing bytecode"
$(Q)$(SYNTP) $(SYNTAX_FP) -o $@
# Generator for syntax file - 6502 version - INTEGER
build/gen/int/basic.asm: $(SYNTAX_INT) $(SYNTP) | build/gen/int
$(ECHO) "Creating INT parsing bytecode"
$(Q)$(SYNTP) $(SYNTAX_INT) -o $@
# Sets the version inside command line compiler source
build/gen/cmdline-vers.bas: src/cmdline.bas version.mk
$(Q)$(SED) 's/%VERSION%/$(VERSION)/' < $< > $@
# Main program file
build/bin/fb.xex: $(IDE_OBJS_FP) $(A800_FP_OBJS) $(IDE_BAS_OBJS_FP) | build/bin $(LD65_HOST)
$(ECHO) "Linking floating point IDE"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
@printf "\e[1;33mFP IDE HEAP START: "
@$(SED) -n -e 's/^[^ ]* 00\([0-9A-F]*\) .*HEAP_RUN.*/\1/p' $(@:.xex=.lbl)
@printf "\e[0m"
build/bin/fbc.xex: $(CMD_OBJS_FP) $(A800_FP_OBJS) $(CMD_BAS_OBJS_FP) | build/bin $(LD65_HOST)
$(ECHO) "Linking command line compiler"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
@printf "\e[1;33mCOMMAND LINE COMPILER HEAP START: "
@$(SED) -n -e 's/^[^ ]* 00\([0-9A-F]*\) .*HEAP_RUN.*/\1/p' $(@:.xex=.lbl)
@printf "\e[0m"
build/bin/fbci.xex: $(CMD_OBJS_INT) $(A800_OBJS) $(CMD_BAS_OBJS_INT) | build/bin $(LD65_HOST)
$(ECHO) "Linking command line integer compiler"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
@printf "\e[1;33mCOMMAND LINE INTEGER COMPILER HEAP START: "
@$(SED) -n -e 's/^[^ ]* 00\([0-9A-F]*\) .*HEAP_RUN.*/\1/p' $(@:.xex=.lbl)
@printf "\e[0m"
build/bin/fbi.xex: $(IDE_OBJS_INT) $(A800_OBJS) $(IDE_BAS_OBJS_INT) | build/bin $(LD65_HOST)
$(ECHO) "Linking integer IDE"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
@printf "\e[1;33mINTEGER IDE HEAP START: "
@$(SED) -n -e 's/^[^ ]* 00\([0-9A-F]*\) .*HEAP_RUN.*/\1/p' $(@:.xex=.lbl)
@printf "\e[0m"
# Compiled program files
build/bin/%.xex: build/obj/fp/%.o $(LIB_FP) | build/bin $(LD65_HOST)
$(ECHO) "Linking floating point $@"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
build/bin/%.xex: build/obj/int/%.o $(LIB_INT) | build/bin $(LD65_HOST)
$(ECHO) "Linking integer $@"
$(Q)$(LD65_HOST) $(LD65_FLAGS) -Ln $(@:.xex=.lbl) -vm -m $(@:.xex=.map) -o $@ $^
# Generates basic bytecode from source file
build/gen/fp/%.asm: build/gen/%.bas $(FASTBASIC_HOST) | build/gen/fp
$(ECHO) "Compiling FP BASIC $<"
$(Q)$(FASTBASIC_HOST) $(FB_FP_FLAGS) -o $@ -c $<
build/gen/int/%.asm: build/gen/%.bas $(FASTBASIC_HOST) | build/gen/int
$(ECHO) "Compiling INT BASIC $<"
$(Q)$(FASTBASIC_HOST) $(FB_INT_FLAGS) -o $@ -c $<
build/gen/fp/%.asm: src/%.bas $(FASTBASIC_HOST) | build/gen/fp
$(ECHO) "Compiling FP BASIC $<"
$(Q)$(FASTBASIC_HOST) $(FB_FP_FLAGS) -o $@ -c $<
build/gen/int/%.asm: src/%.bas $(FASTBASIC_HOST) | build/gen/int
$(ECHO) "Compiling INT BASIC $<"
$(Q)$(FASTBASIC_HOST) $(FB_INT_FLAGS) -o $@ -c $<
build/gen/fp/%.asm: samples/fp/%.bas $(FASTBASIC_HOST) | build/gen/fp
$(ECHO) "Compiling FP BASIC sample $<"
$(Q)$(FASTBASIC_HOST) $(FB_FP_FLAGS) -o $@ -c $<
build/gen/int/%.asm: samples/int/%.bas $(FASTBASIC_HOST) | build/gen/int
$(ECHO) "Compiling INT BASIC sample $<"
$(Q)$(FASTBASIC_HOST) $(FB_INT_FLAGS) -o $@ -c $<
# Object file rules
build/obj/fp/%.o: src/%.asm | $(AS_FOLDERS:src%=build/obj/fp%) $(CA65_HOST)
$(ECHO) "Assembly FP $<"
$(Q)$(CA65_HOST) $(CA65_FP_FLAGS) -l $(@:.o=.lst) -o $@ $<
build/obj/fp/%.o: build/gen/fp/%.asm | build/obj/fp $(CA65_HOST)
$(ECHO) "Assembly FP $<"
$(Q)$(CA65_HOST) $(CA65_FP_FLAGS) -l $(@:.o=.lst) -o $@ $<
build/obj/rom-fp/%.o: src/%.asm | $(AS_FOLDERS:src%=build/obj/rom-fp%) $(CA65_HOST)
$(ECHO) "Assembly Cart FP $<"
$(Q)$(CA65_HOST) $(CA65_FP_FLAGS) $(CA65_ROM) -l $(@:.o=.lst) -o $@ $<
build/obj/int/%.o: src/%.asm | $(AS_FOLDERS:src%=build/obj/int%) $(CA65_HOST)
$(ECHO) "Assembly INT $<"
$(Q)$(CA65_HOST) $(CA65_INT_FLAGS) -l $(@:.o=.lst) -o $@ $<
build/obj/int/%.o: build/gen/int/%.asm | build/obj/int $(CA65_HOST)
$(ECHO) "Assembly INT $<"
$(Q)$(CA65_HOST) $(CA65_INT_FLAGS) -l $(@:.o=.lst) -o $@ $<
build/obj/rom-int/%.o: src/%.asm | $(AS_FOLDERS:src%=build/obj/rom-int%) $(CA65_HOST)
$(ECHO) "Assembly Cart INT $<"
$(Q)$(CA65_HOST) $(CA65_INT_FLAGS) $(CA65_ROM) -l $(@:.o=.lst) -o $@ $<
build/obj/a5200/%.o: src/%.asm | $(AS_FOLDERS:src%=build/obj/a5200%) $(CA65_HOST)
$(ECHO) "Assembly Atari-5200 INT $<"
$(Q)$(CA65_HOST) $(CA65_A5200_FLAGS) -l $(@:.o=.lst) -o $@ $<
# Rule to build all folders
$(BUILD_FOLDERS):
$(Q)mkdir -p $@
# Library files
$(LIB_FP): $(RT_OBJS_FP) $(A800_FP_OBJS) | build/compiler $(AR65_HOST)
$(ECHO) "Creating FP library $@"
$(Q)rm -f $@
$(Q)$(AR65_HOST) a $@ $^
$(LIB_ROM_FP): $(RT_OBJS_ROM_FP) $(A800_FP_ROM_OBJS) | build/compiler $(AR65_HOST)
$(ECHO) "Creating Cart FP library $@"
$(Q)rm -f $@
$(Q)$(AR65_HOST) a $@ $^
$(LIB_INT): $(RT_OBJS_INT) $(A800_OBJS) | build/compiler $(AR65_HOST)
$(ECHO) "Creating INT library $@"
$(Q)rm -f $@
$(Q)$(AR65_HOST) a $@ $^
$(LIB_ROM_INT): $(RT_OBJS_ROM_INT) $(A800_ROM_OBJS) | build/compiler $(AR65_HOST)
$(ECHO) "Creating Cart INT library $@"
$(Q)rm -f $@
$(Q)$(AR65_HOST) a $@ $^
$(LIB_A5200): $(A5200_OBJS) | build/compiler $(AR65_HOST)
$(ECHO) "Creating Atari-5200 INT library $@"
$(Q)rm -f $@
$(Q)$(AR65_HOST) a $@ $^
# Copy manual to compiler changing the version string.
build/compiler/MANUAL.md: manual.md a5200.md | version.mk build/compiler
$(Q)LC_ALL=C sed 's/%VERSION%/$(VERSION)/' $(filter %.md,$^) > $@
# Copy other files to compiler folder
build/compiler/%: compiler/% | build/compiler
$(Q)cp -f $< $@
# Copy compatibility binaries
build/bin/fb$(HOST_EXT): build/bin/fastbasic$(HOST_EXT)
$(Q)cp -f $< $@
# Copy syntax files to compiler folder
build/compiler/syntax/%: src/syntax/% | build/compiler/syntax
$(Q)cp -f $< $@
# Copy other files to compiler folder
build/compiler/%: compiler/% | build/compiler
$(Q)cp -f $< $@
# Copy assembly include files from CC65
build/compiler/asminc/%: cc65/asminc/% | build/compiler/asminc
$(Q)cp -f $< $@