-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (164 loc) · 5.67 KB
/
Copy pathMakefile
File metadata and controls
194 lines (164 loc) · 5.67 KB
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
# Coding the Impossible — Book Examples Build System
# Primary assembler: sjasmplus (full Z80 instruction set, $FF and #FF hex)
# Secondary: mza (MinZ Assembler, used for mze emulation + DZRP)
#
# Usage:
# make # build all chapter examples
# make test # assemble all with sjasmplus, report errors
# make test-mza # assemble all with mza
# make ch01 # build chapter 1 examples
# make demo # build the torus demo
# make clean # remove build artifacts
SJASMPLUS ?= sjasmplus
MZA_PATH := $(HOME)/dev/minz-ts/minzc/mza
BUILD_DIR := build
# sjasmplus flags
SJASM_FLAGS := --nologo
# mza flags
MZA_FLAGS := --target zxspectrum -u
MZA_RAW_FLAGS := --target generic -f bin -u
# Source files
CHAPTERS := $(wildcard chapters/ch*/examples/*.a80)
DEMO_MAIN := demo/src/main.a80
DEMO_TORUS := demo/src/torus.a80
# Book build
PYTHON ?= python3
BUILD_BOOK := $(PYTHON) build_book.py
.PHONY: all clean test test-mza test-compare demo book book-a4 book-a5 book-epub release version-bump verify-listings inject-listings audit-tstates autotag-stats screenshots packbench packbench-budget packbench-timeline packbench-analyze
all: $(patsubst chapters/%.a80,$(BUILD_DIR)/%.bin,$(CHAPTERS))
$(BUILD_DIR)/%.bin: chapters/%.a80
@mkdir -p $(dir $@)
$(SJASMPLUS) $(SJASM_FLAGS) --raw=$@ $<
demo:
@mkdir -p $(BUILD_DIR)
cd demo/src && $(SJASMPLUS) $(SJASM_FLAGS) main.a80
demo-torus:
@mkdir -p $(BUILD_DIR)
cd demo/src && $(SJASMPLUS) $(SJASM_FLAGS) --raw=../../$(BUILD_DIR)/torus.bin torus.a80
# Per-chapter shortcuts
ch%:
@for f in chapters/$@-*/examples/*.a80; do \
[ -f "$$f" ] || continue; \
echo "=== $$f ==="; \
mkdir -p $(BUILD_DIR); \
$(SJASMPLUS) $(SJASM_FLAGS) --raw=$(BUILD_DIR)/$$(basename $$f .a80).bin $$f; \
done
test:
@ok=0; fail=0; \
for f in chapters/ch*/examples/*.a80; do \
[ -f "$$f" ] || continue; \
if $(SJASMPLUS) $(SJASM_FLAGS) $$f >/dev/null 2>&1; then \
echo " OK $$f"; ok=$$((ok+1)); \
else \
echo "FAIL $$f"; fail=$$((fail+1)); \
fi; \
done; \
if [ -f "$(DEMO_TORUS)" ]; then \
if (cd demo/src && $(SJASMPLUS) $(SJASM_FLAGS) torus.a80) >/dev/null 2>&1; then \
echo " OK $(DEMO_TORUS)"; ok=$$((ok+1)); \
else \
echo "FAIL $(DEMO_TORUS)"; fail=$$((fail+1)); \
fi; \
fi; \
if [ -f "$(DEMO_MAIN)" ]; then \
if (cd demo/src && $(SJASMPLUS) $(SJASM_FLAGS) main.a80) >/dev/null 2>&1; then \
echo " OK $(DEMO_MAIN)"; ok=$$((ok+1)); \
else \
echo "FAIL $(DEMO_MAIN)"; fail=$$((fail+1)); \
fi; \
fi; \
echo "---"; echo "$$ok passed, $$fail failed"
test-mza:
@ok=0; fail=0; \
for f in chapters/ch*/examples/*.a80; do \
[ -f "$$f" ] || continue; \
if $(MZA_PATH) $(MZA_FLAGS) -o /dev/null $$f 2>/dev/null; then \
echo " OK $$f"; ok=$$((ok+1)); \
else \
echo "FAIL $$f"; fail=$$((fail+1)); \
fi; \
done; \
if [ -f "$(DEMO_MAIN)" ]; then \
if (cd demo/src && $(MZA_PATH) $(MZA_FLAGS) -o /dev/null torus.a80) 2>/dev/null; then \
echo " OK $(DEMO_MAIN)"; ok=$$((ok+1)); \
else \
echo "FAIL $(DEMO_MAIN)"; fail=$$((fail+1)); \
fi; \
fi; \
echo "---"; echo "$$ok passed, $$fail failed"
test-compare:
@ok=0; fail=0; skip=0; \
mkdir -p $(BUILD_DIR)/cmp-sj $(BUILD_DIR)/cmp-mza; \
for f in chapters/ch*/examples/*.a80; do \
[ -f "$$f" ] || continue; \
base=$$(basename $$f .a80); \
sj=$(BUILD_DIR)/cmp-sj/$$base.bin; \
mz=$(BUILD_DIR)/cmp-mza/$$base.bin; \
if ! $(SJASMPLUS) $(SJASM_FLAGS) --raw=$$sj $$f >/dev/null 2>&1; then \
echo "SKIP $$f (sjasmplus failed)"; skip=$$((skip+1)); continue; \
fi; \
if ! $(MZA_PATH) $(MZA_RAW_FLAGS) -o $$mz $$f 2>/dev/null; then \
echo "SKIP $$f (mza failed)"; skip=$$((skip+1)); continue; \
fi; \
if cmp -s $$sj $$mz; then \
echo " OK $$f"; ok=$$((ok+1)); \
else \
sjsz=$$(wc -c < $$sj | tr -d ' '); \
mzsz=$$(wc -c < $$mz | tr -d ' '); \
echo "DIFF $$f (sjasmplus=$${sjsz}B, mza=$${mzsz}B)"; \
fail=$$((fail+1)); \
fi; \
done; \
if [ -f "$(DEMO_MAIN)" ]; then \
sj=$(BUILD_DIR)/cmp-sj/torus.bin; \
mz=$(BUILD_DIR)/cmp-mza/torus.bin; \
if (cd demo/src && $(SJASMPLUS) $(SJASM_FLAGS) --raw=../../$$sj torus.a80) >/dev/null 2>&1 && \
(cd demo/src && $(MZA_PATH) $(MZA_RAW_FLAGS) -o ../../$$mz torus.a80) 2>/dev/null; then \
if cmp -s $$sj $$mz; then \
echo " OK $(DEMO_MAIN)"; ok=$$((ok+1)); \
else \
sjsz=$$(wc -c < $$sj | tr -d ' '); \
mzsz=$$(wc -c < $$mz | tr -d ' '); \
echo "DIFF $(DEMO_MAIN) (sjasmplus=$${sjsz}B, mza=$${mzsz}B)"; \
fail=$$((fail+1)); \
fi; \
else \
echo "SKIP $(DEMO_MAIN) (assembler failed)"; skip=$$((skip+1)); \
fi; \
fi; \
echo "---"; echo "$$ok match, $$fail differ, $$skip skipped"
# --- Book targets (via build_book.py, auto-increments version) ---
book:
$(BUILD_BOOK) --all
book-a4:
$(BUILD_BOOK) --pdf
book-a5:
$(BUILD_BOOK) --pdf-a5
book-epub:
$(BUILD_BOOK) --epub
release: clean book
@mkdir -p release
cp $(BUILD_DIR)/book-a4-*.pdf $(BUILD_DIR)/book-a5-*.pdf $(BUILD_DIR)/book-*.epub release/
@echo "Release files copied to release/"
version-bump:
$(BUILD_BOOK) --bump
verify-listings:
$(PYTHON) tools/manage_listings.py verify
inject-listings:
$(PYTHON) tools/manage_listings.py inject --lang all
audit-tstates:
$(PYTHON) tools/audit_tstates.py --scan-chapters
autotag-stats:
$(PYTHON) tools/autotag.py --stats
screenshots:
$(PYTHON) tools/screenshots.py --force
packbench:
$(PYTHON) tools/packbench.py bench --list-packers
packbench-budget:
$(PYTHON) tools/packbench.py budget --config demo/packbench.toml
packbench-timeline:
$(PYTHON) tools/packbench.py timeline --config demo/packbench.toml
packbench-analyze:
$(PYTHON) tools/packbench.py analyze build/*.bin
clean:
rm -rf $(BUILD_DIR)