forked from gbdk-2020/gbdk-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
403 lines (346 loc) · 13 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# Top level Makefile for GBDK that combines the builds for sdcc,
# gbdk-lib, and gbdk-support
#
# GBDK-2020
#
TOPDIR = $(shell pwd)
# Package name, used for tarballs
PKG = gbdk
# Version, used for tarballs
VER = 3.00
PORTS=gbz80 z80
PLATFORMS=gb ap duck gg sms
# Prefix to add to the standard tools. Usefull for a standard gcc
# cross-compile.
TOOLSPREFIX =
# TOOLSPREFIX = i686-w64-mingw32-
TARGETCC = $(TOOLSPREFIX)gcc
TARGETRANLIB = $(TOOLSPREFIX)ranlib
TARGETAR = $(TOOLSPREFIX)ar
TARGETSTRIP = $(TOOLSPREFIX)strip
# Directory containing the source to gbdk-lib
GBDKLIBDIR = $(TOPDIR)/gbdk-lib
# Directory containing the source to gbdk-support
GBDKSUPPORTDIR = $(TOPDIR)/gbdk-support
# Directory with docs config and output (via doxygen)
GBDKDOCSDIR = $(TOPDIR)/docs
# Doxygen command and version check info
DOXYGENCMD = doxygen
DOXYGEN_VER_REQ = 1.8.17
DOXYGEN_VER_HAS = $(shell doxygen -v)
# Base setup
# Extension to add to executables
EXEEXTENSION =
ifeq ($(TOOLSPREFIX),i686-w64-mingw32-)
EXEEXTENSION=.exe
endif
# Host operating system identifier.
HOSTOS = $(shell uname -s)
# Target operating system identifier. Used in the output zip name.
TARGETOS ?= $(HOSTOS)
# Directory that gbdk should finally end up in
TARGETDIR = /opt/gbdk
# Directory that gbdk for this target is built into.
BUILDDIR = $(TOPDIR)/build/gbdk
NOISELOG = $(TOPDIR)/noise.log
all: native-build
clean: gbdk-support-clean gbdk-lib-clean
distclean: clean build-dir-clean
dist-examples-rebuild: gbdk-dist-examples-clean gbdk-dist-examples-build
docs: doxygen-generate
docspdf: doxygen-generate-with-pdf
docsclean: doxygen-clean
docsreset: doxygen-reset
docstools: docs-toolchain-generate
# Build rule for michaelh's machine to spin a release
sapphire-full-build: native-build binary cross-clean cross-linux-mingw32-build
# Cross-compilation targets
FIXUPMASKS = *.c *.h .bat *.s ChangeLog README
native-build: gbdk-build gbdk-install
cross-clean: gbdk-support-clean
cross-build: gbdk-build gbdk-install cross-cleanup
cross-cleanup:
ifdef MSDOSLINEENDS
for i in $(FIXUPMASKS); do \
find $(BUILDDIR) -name $$i -exec unix2dos {} \; ; \
done
endif
cross-linux-mingw32-build:
$(MAKE) TARGETOS=i586-mingw32msvc \
TOOLSPREFIX=i586-mingw32msvc- \
EXEEXTENSION=.exe \
CROSSCOMPILING=1 \
MSDOSLINEENDS=1 \
TARGETDIR=/sdcc \
ARCHIVETYPE=zip \
cross-build gbdk-lib-examples-makefile binary
# Source code drop
src: clean
rm -rf gbdk
mkdir -p gbdk
cp -r Makefile sdcc gbdk-lib gbdk-support gbdk
tar czf gbdk-$(VER).tar.gz gbdk
# Base rules
gbdk-build: gbdk-support-build gbdk-lib-build
gbdk-install: $(BUILDDIR)/bin gbdk-support-install gbdk-lib-install sdcc-install
# Directories
$(BUILDDIR)/bin:
@echo Creating dir $(BUILDDIR)/bin
@mkdir -p $@
build-dir-clean:
rm -r $(BUILDDIR)
# Rules for gbdk-support
gbdk-support-build:
@echo Building lcc
ifdef BINDIR
@$(MAKE) -C $(GBDKSUPPORTDIR)/lcc TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ BINDIR=$(BINDIR)/ --no-print-directory
else
@$(MAKE) -C $(GBDKSUPPORTDIR)/lcc TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory
endif
@echo
@echo Building ihxcheck
@$(MAKE) -C $(GBDKSUPPORTDIR)/ihxcheck TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory
@echo Building bankpack
@$(MAKE) -C $(GBDKSUPPORTDIR)/bankpack TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory
@echo Building png2asset
@$(MAKE) -C $(GBDKSUPPORTDIR)/png2asset TOOLSPREFIX=$(TOOLSPREFIX)
@echo Building gbcompress
@$(MAKE) -C $(GBDKSUPPORTDIR)/gbcompress TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory
@echo
gbdk-support-install: gbdk-support-build $(BUILDDIR)/bin
@echo Installing lcc
@cp $(GBDKSUPPORTDIR)/lcc/lcc$(EXEEXTENSION) $(BUILDDIR)/bin/lcc$(EXEEXTENSION)
@$(TARGETSTRIP) $(BUILDDIR)/bin/lcc*
@cp $(GBDKDOCSDIR)/ChangeLog $(BUILDDIR)
@cp $(GBDKDOCSDIR)/README $(BUILDDIR)
@cp $(GBDKDOCSDIR)/gbdk_manual.pdf $(BUILDDIR)
@echo
@echo Installing ihxcheck
@cp $(GBDKSUPPORTDIR)/ihxcheck/ihxcheck$(EXEEXTENSION) $(BUILDDIR)/bin/ihxcheck$(EXEEXTENSION)
@$(TARGETSTRIP) $(BUILDDIR)/bin/ihxcheck*
@echo Installing bankpack
@cp $(GBDKSUPPORTDIR)/bankpack/bankpack$(EXEEXTENSION) $(BUILDDIR)/bin/bankpack$(EXEEXTENSION)
@$(TARGETSTRIP) $(BUILDDIR)/bin/bankpack*
@echo Installing png2asset
@cp $(GBDKSUPPORTDIR)/png2asset/png2asset$(EXEEXTENSION) $(BUILDDIR)/bin/png2asset$(EXEEXTENSION)
@$(TARGETSTRIP) $(BUILDDIR)/bin/png2asset*
@echo Installing gbcompress
@cp $(GBDKSUPPORTDIR)/gbcompress/gbcompress$(EXEEXTENSION) $(BUILDDIR)/bin/gbcompress$(EXEEXTENSION)
@$(TARGETSTRIP) $(BUILDDIR)/bin/gbcompress*
@echo
gbdk-support-clean:
@echo Cleaning lcc
@$(MAKE) -C $(GBDKSUPPORTDIR)/lcc clean --no-print-directory
@echo
@echo Cleaning ihxcheck
@$(MAKE) -C $(GBDKSUPPORTDIR)/ihxcheck clean --no-print-directory
@echo Cleaning bankpack
@$(MAKE) -C $(GBDKSUPPORTDIR)/bankpack clean --no-print-directory
@echo Cleaning png2asset
@$(MAKE) -C $(GBDKSUPPORTDIR)/png2asset clean
@echo Cleaning gbcompress
@$(MAKE) -C $(GBDKSUPPORTDIR)/gbcompress clean --no-print-directory
@echo
# Rules for gbdk-lib
gbdk-lib-build: check-SDCCDIR
ifndef CROSSCOMPILING
@echo Building lib
@$(MAKE) -C $(GBDKLIBDIR)/libc PORTS="$(PORTS)" PLATFORMS="$(PLATFORMS)" --no-print-directory
@echo
endif
gbdk-lib-install: gbdk-lib-build
gbdk-lib-install: gbdk-lib-install-prepare
gbdk-lib-install: gbdk-lib-install-examples
gbdk-lib-install: gbdk-lib-install-ports
gbdk-lib-install: gbdk-lib-install-platforms
gbdk-lib-install-prepare:
@rm -rf $(BUILDDIR)/lib
gbdk-lib-install-ports:
@for port in $(PORTS); do \
echo Installing lib for port: $$port; \
mkdir -p $(BUILDDIR)/lib/small/asxxxx/$$port/; \
cp $(GBDKLIBDIR)/build/small/asxxxx/$$port/$$port.lib $(BUILDDIR)/lib/small/asxxxx/$$port/$$port.lib; \
done
@echo
# The inner loop copies global.s for platforms from relevant port/platform.
# When doing that it expects a given platform to never be present in
# multiple ports since the copy destination is not port specific (lacks /$$port/ )
gbdk-lib-install-platforms:
@for plat in $(PLATFORMS); do \
echo Installing lib for platform: $$plat; \
mkdir -p $(BUILDDIR)/lib/small/asxxxx/$$plat; \
cp $(GBDKLIBDIR)/build/small/asxxxx/$$plat/crt0.o $(BUILDDIR)/lib/small/asxxxx/$$plat/crt0.o; \
cp $(GBDKLIBDIR)/build/small/asxxxx/$$plat/$$plat.lib $(BUILDDIR)/lib/small/asxxxx/$$plat/$$plat.lib; \
for port in $(PORTS); do \
if [ -d "$(GBDKLIBDIR)/libc/targets/$$port/$$plat" ]; then \
cp $(GBDKLIBDIR)/libc/targets/$$port/$$plat/global.s $(BUILDDIR)/lib/small/asxxxx/$$plat/global.s; \
fi \
done \
done
@echo
gbdk-lib-install-examples:
@echo Installing Examples
@cp -r $(GBDKLIBDIR)/include $(GBDKLIBDIR)/examples $(BUILDDIR)
@for plat in $(PLATFORMS); do \
if [ -d "$(BUILDDIR)/examples/$$plat" ]; then \
echo Generating Examples compile.bat for $$plat; \
$(MAKE) -C $(BUILDDIR)/examples/$$plat compile.bat --no-print-directory; \
echo; \
fi \
done
gbdk-lib-clean:
@echo Cleaning lib
@$(MAKE) -C $(GBDKLIBDIR) PORTS="$(PORTS)" PLATFORMS="$(PLATFORMS)" clean
@echo
gbdk-lib-examples-makefile:
$(MAKE) -C $(BUILDDIR)/examples/gb compile.bat
unix2dos $(BUILDDIR)/examples/gb/compile.bat
gbdk-dist-examples-build:
$(MAKE) -C $(BUILDDIR)/examples/gb
gbdk-dist-examples-clean:
$(MAKE) -C $(BUILDDIR)/examples/gb clean
# Copy SDDC executable files
SDCC_BINS = makebin packihx sdar sdasgb sdcc sdcdb sdcpp sdldgb sdnm sdobjcopy sdranlib sz80 sdasz80 sdldz80
ifeq ($(OS),Windows_NT)
MINGW64_RUNTIME = \
libgcc_s_seh-1.dll \
libgcc_s_sjlj-1.dll \
libstdc++-6.dll \
libwinpthread-1.dll \
readline5.dll
SDCC_BINS := $(addsuffix .exe, $(SDCC_BINS)) $(MINGW64_RUNTIME)
endif
sdcc-install: check-SDCCDIR
@echo Installing SDCC
@for i in $(SDCC_BINS); do \
cp $(SDCCDIR)/bin/$$i $(BUILDDIR)/bin/ && echo "-> $$i" ; \
done
# Final binary
binary:
ifeq ($(ARCHIVETYPE),zip)
rm -f $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).zip
cd $(BUILDDIR)/..; zip -9Xrq $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).zip gbdk
else
rm -f $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).tar.gz
cd $(BUILDDIR)/..; tar czf $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).tar.gz gbdk
endif
# Install
install: native-build
mkdir -p $(TARGETDIR)
cp -r $(BUILDDIR)/* $(TARGETDIR)
# Make sure SDCCDIR is populated
# Swap WIN/MSDOS slashes to Unix style for MinGW (prevent some errors with cp)
check-SDCCDIR:
ifndef SDCCDIR
$(error SDCCDIR is undefined)
endif
ifeq ($(OS),Windows_NT)
SDCCDIR := $(subst \,/,$(SDCCDIR))
endif
# First purge doxygen output directory to clear potentially stale output.
# Next change working dir so "include" is the root doxygen works in.
# That prevents it from including the path leading up to there in the
# output, even though it's instructed to only process starting at "include".
doxygen-generate:
ifeq ($(shell expr "$(DOXYGEN_VER_HAS)" \< "$(DOXYGEN_VER_REQ)"), 1)
$(error Doxygen version $(DOXYGEN_VER_HAS) is too old! Minimum version is $(DOXYGEN_VER_REQ))
endif
#Run Doxygen
rm -rf $(GBDKDOCSDIR)/api; \
cd "$(GBDKLIBDIR)/include"; \
GBDKDOCSDIR="$(GBDKDOCSDIR)" GBDKLIBDIR="$(GBDKLIBDIR)" $(DOXYGENCMD) "$(GBDKDOCSDIR)/config/gbdk-2020-doxyfile"
@if [ "$(DOCS_PDF_ON)" = "YES" ]; then\
$(MAKE) -C $(GBDKDOCSDIR)/latex;\
cp $(GBDKDOCSDIR)/latex/refman.pdf $(GBDKDOCSDIR)/gbdk_manual.pdf;\
fi
rm -rf $(GBDKDOCSDIR)/latex
# Turn on Latex -> PDF conversion to run run at end of regular docs build
# (which includes latex output but deletes it at the end).
#
# The conversion process requires a Latex install.
# For Windows there are various Latex packages to choose from.
# For Linux this appears to be the minimum:
# sudo apt install texlive-latex-base
# sudo apt install texlive-latex-recommended
# sudo apt install texlive-latex-extra
#
doxygen-generate-with-pdf: DOCS_PDF_ON=YES
doxygen-generate-with-pdf: doxygen-generate
# Generate toolchain settings markdown file (if possible)
docs-toolchain-generate: TOOLCHAIN_DOCS_FILE=$(GBDKDOCSDIR)/pages/20_toolchain_settings.md
docs-toolchain-generate:
ifneq (,$(wildcard $(BUILDDIR)/bin/))
echo \@page docs_toolchain_settings Toolchain settings > $(TOOLCHAIN_DOCS_FILE)
# lcc
echo \@anchor lcc-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# lcc settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
cd "$(BUILDDIR)/bin/"; \
./lcc >> $(TOOLCHAIN_DOCS_FILE) 2>&1
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# sdcc
echo \@anchor sdcc-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# sdcc settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/sdcc -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# sdasgb
echo \@anchor sdasgb-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# sdasgb settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/sdasgb -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# sdasz80
echo \@anchor sdasz80-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# sdasz80 settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/sdasgb -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# bankpack
echo \@anchor bankpack-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# bankpack settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/bankpack -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# sdldgb
echo \@anchor sdldgb-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# sdldgb settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/sdldgb >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# sdldz80
echo \@anchor sdldz80-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# sdldz80 settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/sdldgb >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# ihxcheck
echo \@anchor ihxcheck-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# ihxcheck settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/ihxcheck -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# makebin
echo \@anchor makebin-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# makebin settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/makebin -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# gbcompress
echo \@anchor gbcompress-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# gbcompress settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/gbcompress -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
# png2asset
echo \@anchor png2asset-settings >> $(TOOLCHAIN_DOCS_FILE);
echo \# png2asset settings >> $(TOOLCHAIN_DOCS_FILE);
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE);
$(BUILDDIR)/bin/png2asset >> $(TOOLCHAIN_DOCS_FILE) 2>&1
echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE)
endif
doxygen-clean:
rm -rf $(GBDKDOCSDIR)/api
doxygen-reset:
rm -rf $(GBDKDOCSDIR)/api
git checkout $(GBDKDOCSDIR)/api