Makefile (14244B)
1# Top level Makefile for GBDK that combines the builds for sdcc, 2# gbdk-lib, and gbdk-support 3# 4# GBDK-2020 5# 6TOPDIR = $(shell pwd) 7 8# Package name, used for tarballs 9PKG = gbdk 10# Version, used for tarballs & docs 11VER = 4.0.6 12 13PORTS=sm83 z80 14PLATFORMS=gb ap duck gg sms msxdos 15 16# Prefix to add to the standard tools. Usefull for a standard gcc 17# cross-compile. 18TOOLSPREFIX = 19ifeq ($(OS_TARGET),Win_x32) 20 TOOLSPREFIX = i686-w64-mingw32- 21endif 22ifeq ($(OS_TARGET),Win_x64) 23 TOOLSPREFIX = x86_64-w64-mingw32- 24endif 25 26TARGETCC = $(TOOLSPREFIX)gcc 27TARGETRANLIB = $(TOOLSPREFIX)ranlib 28TARGETAR = $(TOOLSPREFIX)ar 29TARGETSTRIP = $(TOOLSPREFIX)strip 30 31# Directory containing the source to gbdk-lib 32GBDKLIBDIR = $(TOPDIR)/gbdk-lib 33# Directory containing the source to gbdk-support 34GBDKSUPPORTDIR = $(TOPDIR)/gbdk-support 35 36# Directory with docs config and output (via doxygen) 37GBDKDOCSDIR = $(TOPDIR)/docs 38 39# Doxygen command and version check info 40DOXYGENCMD = doxygen 41DOXYGEN_VER_REQ = 1.8.17 42DOXYGEN_VER_HAS = $(shell doxygen -v) 43 44 45# Base setup 46# Extension to add to executables 47EXEEXTENSION = 48ifeq ($(TOOLSPREFIX),i686-w64-mingw32-) 49 EXEEXTENSION=.exe 50endif 51ifeq ($(TOOLSPREFIX),x86_64-w64-mingw32-) 52 EXEEXTENSION=.exe 53endif 54ifeq ($(OS),Windows_NT) 55 EXEEXTENSION=.exe 56endif 57# Host operating system identifier. 58HOSTOS = $(shell uname -s) 59# Target operating system identifier. Used in the output zip name. 60TARGETOS ?= $(HOSTOS) 61 62# Directory that gbdk should finally end up in 63TARGETDIR = /opt/gbdk 64# Directory that gbdk for this target is built into. 65BUILDDIR = $(TOPDIR)/build/gbdk 66 67NOISELOG = $(TOPDIR)/noise.log 68 69all: native-build 70 71clean: gbdk-support-clean gbdk-lib-clean 72 73distclean: clean build-dir-clean 74dist-examples-rebuild: gbdk-dist-examples-clean gbdk-dist-examples-build 75 76docs: doxygen-generate 77docspdf: doxygen-generate-with-pdf 78docsclean: doxygen-clean 79docsreset: doxygen-reset 80docstools: docs-toolchain-generate 81 82# Build rule for michaelh's machine to spin a release 83sapphire-full-build: native-build binary cross-clean cross-linux-mingw32-build 84 85# Cross-compilation targets 86FIXUPMASKS = *.c *.h .bat *.s ChangeLog README 87 88native-build: gbdk-build gbdk-install 89 90cross-clean: gbdk-support-clean 91 92cross-build: gbdk-build gbdk-install cross-cleanup 93 94cross-cleanup: 95ifdef MSDOSLINEENDS 96 for i in $(FIXUPMASKS); do \ 97 find $(BUILDDIR) -name $$i -exec unix2dos {} \; ; \ 98 done 99endif 100 101cross-linux-mingw32-build: 102 $(MAKE) TARGETOS=i586-mingw32msvc \ 103 TOOLSPREFIX=i586-mingw32msvc- \ 104 EXEEXTENSION=.exe \ 105 CROSSCOMPILING=1 \ 106 MSDOSLINEENDS=1 \ 107 TARGETDIR=/sdcc \ 108 ARCHIVETYPE=zip \ 109 cross-build gbdk-lib-examples-makefile binary 110 111# Source code drop 112src: clean 113 rm -rf gbdk 114 mkdir -p gbdk 115 cp -r Makefile sdcc gbdk-lib gbdk-support gbdk 116 tar czf gbdk-$(VER).tar.gz gbdk 117 118# Base rules 119gbdk-build: gbdk-support-build gbdk-lib-build 120 121gbdk-install: $(BUILDDIR)/bin gbdk-support-install gbdk-lib-install sdcc-install 122 123# Directories 124$(BUILDDIR)/bin: 125 @echo Creating dir $(BUILDDIR)/bin 126 @mkdir -p $@ 127 128build-dir-clean: 129 rm -r $(BUILDDIR) 130 131# Rules for gbdk-support 132gbdk-support-build: 133 @echo Building lcc 134ifdef BINDIR 135 @$(MAKE) -C $(GBDKSUPPORTDIR)/lcc TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ BINDIR=$(BINDIR)/ --no-print-directory 136else 137 @$(MAKE) -C $(GBDKSUPPORTDIR)/lcc TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory 138endif 139 @echo 140 @echo Building ihxcheck 141 @$(MAKE) -C $(GBDKSUPPORTDIR)/ihxcheck TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory 142 @echo Building bankpack 143 @$(MAKE) -C $(GBDKSUPPORTDIR)/bankpack TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory 144 @echo Building png2asset 145 @$(MAKE) -C $(GBDKSUPPORTDIR)/png2asset TOOLSPREFIX=$(TOOLSPREFIX) 146 @echo Building gbcompress 147 @$(MAKE) -C $(GBDKSUPPORTDIR)/gbcompress TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory 148 @echo Building makecom 149 @$(MAKE) -C $(GBDKSUPPORTDIR)/makecom TOOLSPREFIX=$(TOOLSPREFIX) TARGETDIR=$(TARGETDIR)/ --no-print-directory 150 @echo 151 152gbdk-support-install: gbdk-support-build $(BUILDDIR)/bin 153 @echo Installing lcc 154 @cp $(GBDKSUPPORTDIR)/lcc/lcc$(EXEEXTENSION) $(BUILDDIR)/bin/lcc$(EXEEXTENSION) 155 @$(TARGETSTRIP) $(BUILDDIR)/bin/lcc$(EXEEXTENSION) 156 @cp $(GBDKDOCSDIR)/ChangeLog $(BUILDDIR) 157 @cp $(GBDKDOCSDIR)/README $(BUILDDIR) 158 @cp $(GBDKDOCSDIR)/gbdk_manual.pdf $(BUILDDIR) 159 @echo 160 @echo Installing ihxcheck 161 @cp $(GBDKSUPPORTDIR)/ihxcheck/ihxcheck$(EXEEXTENSION) $(BUILDDIR)/bin/ihxcheck$(EXEEXTENSION) 162 @$(TARGETSTRIP) $(BUILDDIR)/bin/ihxcheck$(EXEEXTENSION) 163 @echo Installing bankpack 164 @cp $(GBDKSUPPORTDIR)/bankpack/bankpack$(EXEEXTENSION) $(BUILDDIR)/bin/bankpack$(EXEEXTENSION) 165 @$(TARGETSTRIP) $(BUILDDIR)/bin/bankpack$(EXEEXTENSION) 166 @echo Installing png2asset 167 @cp $(GBDKSUPPORTDIR)/png2asset/png2asset$(EXEEXTENSION) $(BUILDDIR)/bin/png2asset$(EXEEXTENSION) 168 @$(TARGETSTRIP) $(BUILDDIR)/bin/png2asset$(EXEEXTENSION) 169 @echo Installing gbcompress 170 @cp $(GBDKSUPPORTDIR)/gbcompress/gbcompress$(EXEEXTENSION) $(BUILDDIR)/bin/gbcompress$(EXEEXTENSION) 171 @$(TARGETSTRIP) $(BUILDDIR)/bin/gbcompress$(EXEEXTENSION) 172 @echo Installing makecom 173 @cp $(GBDKSUPPORTDIR)/makecom/makecom$(EXEEXTENSION) $(BUILDDIR)/bin/makecom$(EXEEXTENSION) 174 @$(TARGETSTRIP) $(BUILDDIR)/bin/makecom$(EXEEXTENSION) 175 @echo 176 177gbdk-support-clean: 178 @echo Cleaning lcc 179 @$(MAKE) -C $(GBDKSUPPORTDIR)/lcc clean --no-print-directory 180 @echo 181 @echo Cleaning ihxcheck 182 @$(MAKE) -C $(GBDKSUPPORTDIR)/ihxcheck clean --no-print-directory 183 @echo Cleaning bankpack 184 @$(MAKE) -C $(GBDKSUPPORTDIR)/bankpack clean --no-print-directory 185 @echo Cleaning png2asset 186 @$(MAKE) -C $(GBDKSUPPORTDIR)/png2asset clean 187 @echo Cleaning gbcompress 188 @$(MAKE) -C $(GBDKSUPPORTDIR)/gbcompress clean --no-print-directory 189 @echo 190 191# Rules for gbdk-lib 192gbdk-lib-build: check-SDCCDIR 193ifndef CROSSCOMPILING 194 @echo Building lib 195 @$(MAKE) -C $(GBDKLIBDIR)/libc PORTS="$(PORTS)" PLATFORMS="$(PLATFORMS)" --no-print-directory 196 @echo 197endif 198 199 200gbdk-lib-install: gbdk-lib-build 201gbdk-lib-install: gbdk-lib-install-prepare 202gbdk-lib-install: gbdk-lib-install-examples 203gbdk-lib-install: gbdk-lib-install-ports 204gbdk-lib-install: gbdk-lib-install-platforms 205 206gbdk-lib-install-prepare: 207 @rm -rf $(BUILDDIR)/lib 208 209gbdk-lib-install-ports: 210 @for port in $(PORTS); do \ 211 echo Installing lib for port: $$port; \ 212 mkdir -p $(BUILDDIR)/lib/small/asxxxx/$$port/; \ 213 cp $(GBDKLIBDIR)/build/small/asxxxx/$$port/$$port.lib $(BUILDDIR)/lib/small/asxxxx/$$port/$$port.lib; \ 214 done 215 @echo 216 217# The inner loop copies global.s for platforms from relevant port/platform. 218# When doing that it expects a given platform to never be present in 219# multiple ports since the copy destination is not port specific (lacks /$$port/ ) 220gbdk-lib-install-platforms: 221 @for plat in $(PLATFORMS); do \ 222 echo Installing lib for platform: $$plat; \ 223 mkdir -p $(BUILDDIR)/lib/small/asxxxx/$$plat; \ 224 cp $(GBDKLIBDIR)/build/small/asxxxx/$$plat/crt0.o $(BUILDDIR)/lib/small/asxxxx/$$plat/crt0.o; \ 225 cp $(GBDKLIBDIR)/build/small/asxxxx/$$plat/$$plat.lib $(BUILDDIR)/lib/small/asxxxx/$$plat/$$plat.lib; \ 226 for port in $(PORTS); do \ 227 if [ -d "$(GBDKLIBDIR)/libc/targets/$$port/$$plat" ]; then \ 228 cp $(GBDKLIBDIR)/libc/targets/$$port/$$plat/global.s $(BUILDDIR)/lib/small/asxxxx/$$plat/global.s; \ 229 fi \ 230 done \ 231 done 232 @echo 233 234 235gbdk-lib-install-examples: 236 @echo Installing Examples 237 @cp -r $(GBDKLIBDIR)/include $(GBDKLIBDIR)/examples $(BUILDDIR) 238 @for plat in $(PLATFORMS); do \ 239 if [ -d "$(BUILDDIR)/examples/$$plat" ]; then \ 240 echo Generating Examples compile.bat for $$plat; \ 241 $(MAKE) -C $(BUILDDIR)/examples/$$plat compile.bat --no-print-directory; \ 242 echo; \ 243 fi \ 244 done 245 246 247gbdk-lib-clean: 248 @echo Cleaning lib 249 @$(MAKE) -C $(GBDKLIBDIR) PORTS="$(PORTS)" PLATFORMS="$(PLATFORMS)" clean 250 @echo 251 252gbdk-lib-examples-makefile: 253 $(MAKE) -C $(BUILDDIR)/examples/gb compile.bat 254 unix2dos $(BUILDDIR)/examples/gb/compile.bat 255 256gbdk-dist-examples-build: 257 $(MAKE) -C $(BUILDDIR)/examples/gb 258 259gbdk-dist-examples-clean: 260 $(MAKE) -C $(BUILDDIR)/examples/gb clean 261 262 263# Copy SDDC executable files 264SDCC_BINS = makebin packihx sdar sdasgb sdcc sdcdb sdcpp sdldgb sdnm sdobjcopy sdranlib sz80 sdasz80 sdldz80 265ifeq ($(OS),Windows_NT) 266MINGW64_RUNTIME = \ 267 libgcc_s_seh-1.dll \ 268 libgcc_s_sjlj-1.dll \ 269 libstdc++-6.dll \ 270 libwinpthread-1.dll \ 271 readline5.dll 272SDCC_BINS := $(addsuffix .exe, $(SDCC_BINS)) $(MINGW64_RUNTIME) 273endif 274 275sdcc-install: check-SDCCDIR 276 @echo Installing SDCC 277 @for i in $(SDCC_BINS); do \ 278 cp $(SDCCDIR)/bin/$$i $(BUILDDIR)/bin/ && echo "-> $$i" ; \ 279 done 280 281# Final binary 282binary: 283ifeq ($(ARCHIVETYPE),zip) 284 rm -f $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).zip 285 cd $(BUILDDIR)/..; zip -9Xrq $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).zip gbdk 286else 287 rm -f $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).tar.gz 288 cd $(BUILDDIR)/..; tar czf $(TOPDIR)/gbdk-$(VER)-$(TARGETOS).tar.gz gbdk 289endif 290 291# Install 292install: native-build 293 mkdir -p $(TARGETDIR) 294 cp -r $(BUILDDIR)/* $(TARGETDIR) 295 296# Make sure SDCCDIR is populated 297# Swap WIN/MSDOS slashes to Unix style for MinGW (prevent some errors with cp) 298check-SDCCDIR: 299ifndef SDCCDIR 300 $(error SDCCDIR is undefined) 301endif 302ifeq ($(OS),Windows_NT) 303SDCCDIR := $(subst \,/,$(SDCCDIR)) 304endif 305 306# First purge doxygen output directory to clear potentially stale output. 307# Next change working dir so "include" is the root doxygen works in. 308# That prevents it from including the path leading up to there in the 309# output, even though it's instructed to only process starting at "include". 310doxygen-generate: 311ifeq ($(shell expr "$(DOXYGEN_VER_HAS)" \< "$(DOXYGEN_VER_REQ)"), 1) 312 $(error Doxygen version $(DOXYGEN_VER_HAS) is too old! Minimum version is $(DOXYGEN_VER_REQ)) 313endif 314#Run Doxygen 315 rm -rf $(GBDKDOCSDIR)/api; \ 316 cd "$(GBDKLIBDIR)/include"; \ 317 GBDKDOCSDIR="$(GBDKDOCSDIR)" GBDKVERSION=$(VER) GBDKLIBDIR="$(GBDKLIBDIR)" $(DOXYGENCMD) "$(GBDKDOCSDIR)/config/gbdk-2020-doxyfile" 318 @if [ "$(DOCS_PDF_ON)" = "YES" ]; then\ 319 $(MAKE) -C $(GBDKDOCSDIR)/latex;\ 320 cp $(GBDKDOCSDIR)/latex/refman.pdf $(GBDKDOCSDIR)/gbdk_manual.pdf;\ 321 fi 322 rm -rf $(GBDKDOCSDIR)/latex 323 324# Turn on Latex -> PDF conversion to run run at end of regular docs build 325# (which includes latex output but deletes it at the end). 326# 327# The conversion process requires a Latex install. 328# For Windows there are various Latex packages to choose from. 329# For Linux this appears to be the minimum: 330# sudo apt install texlive-latex-base 331# sudo apt install texlive-latex-recommended 332# sudo apt install texlive-latex-extra 333# 334doxygen-generate-with-pdf: DOCS_PDF_ON=YES 335doxygen-generate-with-pdf: doxygen-generate 336 337 338# Generate toolchain settings markdown file (if possible) 339docs-toolchain-generate: TOOLCHAIN_DOCS_FILE=$(GBDKDOCSDIR)/pages/20_toolchain_settings.md 340docs-toolchain-generate: 341ifneq (,$(wildcard $(BUILDDIR)/bin/)) 342 echo \@page docs_toolchain_settings Toolchain settings > $(TOOLCHAIN_DOCS_FILE) 343# lcc 344 echo \@anchor lcc-settings >> $(TOOLCHAIN_DOCS_FILE); 345 echo \# lcc settings >> $(TOOLCHAIN_DOCS_FILE); 346 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 347 cd "$(BUILDDIR)/bin/"; \ 348 ./lcc >> $(TOOLCHAIN_DOCS_FILE) 2>&1 349 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 350# sdcc 351 echo \@anchor sdcc-settings >> $(TOOLCHAIN_DOCS_FILE); 352 echo \# sdcc settings >> $(TOOLCHAIN_DOCS_FILE); 353 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 354 $(BUILDDIR)/bin/sdcc -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 355 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 356# sdasgb 357 echo \@anchor sdasgb-settings >> $(TOOLCHAIN_DOCS_FILE); 358 echo \# sdasgb settings >> $(TOOLCHAIN_DOCS_FILE); 359 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 360 $(BUILDDIR)/bin/sdasgb -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 361 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 362# sdasz80 363 echo \@anchor sdasz80-settings >> $(TOOLCHAIN_DOCS_FILE); 364 echo \# sdasz80 settings >> $(TOOLCHAIN_DOCS_FILE); 365 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 366 $(BUILDDIR)/bin/sdasgb -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 367 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 368# bankpack 369 echo \@anchor bankpack-settings >> $(TOOLCHAIN_DOCS_FILE); 370 echo \# bankpack settings >> $(TOOLCHAIN_DOCS_FILE); 371 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 372 $(BUILDDIR)/bin/bankpack -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 373 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 374# sdldgb 375 echo \@anchor sdldgb-settings >> $(TOOLCHAIN_DOCS_FILE); 376 echo \# sdldgb settings >> $(TOOLCHAIN_DOCS_FILE); 377 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 378 $(BUILDDIR)/bin/sdldgb >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 379 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 380# sdldz80 381 echo \@anchor sdldz80-settings >> $(TOOLCHAIN_DOCS_FILE); 382 echo \# sdldz80 settings >> $(TOOLCHAIN_DOCS_FILE); 383 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 384 $(BUILDDIR)/bin/sdldgb >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 385 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 386# ihxcheck 387 echo \@anchor ihxcheck-settings >> $(TOOLCHAIN_DOCS_FILE); 388 echo \# ihxcheck settings >> $(TOOLCHAIN_DOCS_FILE); 389 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 390 $(BUILDDIR)/bin/ihxcheck -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 391 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 392# makebin 393 echo \@anchor makebin-settings >> $(TOOLCHAIN_DOCS_FILE); 394 echo \# makebin settings >> $(TOOLCHAIN_DOCS_FILE); 395 echo Also see \@ref setting_mbc_and_rom_ram_banks >> $(TOOLCHAIN_DOCS_FILE); 396 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 397 $(BUILDDIR)/bin/makebin -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 398 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 399# makecom 400 echo \@anchor makecom-settings >> $(TOOLCHAIN_DOCS_FILE); 401 echo \# makecom settings >> $(TOOLCHAIN_DOCS_FILE); 402 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 403 $(BUILDDIR)/bin/makecom -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 404 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 405# gbcompress 406 echo \@anchor gbcompress-settings >> $(TOOLCHAIN_DOCS_FILE); 407 echo \# gbcompress settings >> $(TOOLCHAIN_DOCS_FILE); 408 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 409 $(BUILDDIR)/bin/gbcompress -h >> $(TOOLCHAIN_DOCS_FILE) 2>&1 || true 410 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 411# png2asset 412 echo \@anchor png2asset-settings >> $(TOOLCHAIN_DOCS_FILE); 413 echo \# png2asset settings >> $(TOOLCHAIN_DOCS_FILE); 414 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE); 415 $(BUILDDIR)/bin/png2asset >> $(TOOLCHAIN_DOCS_FILE) 2>&1 416 echo \`\`\` >> $(TOOLCHAIN_DOCS_FILE) 417endif 418 419 420doxygen-clean: 421 rm -rf $(GBDKDOCSDIR)/api 422 423doxygen-reset: 424 rm -rf $(GBDKDOCSDIR)/api 425 git checkout $(GBDKDOCSDIR)/api 426