Skip to content

Instantly share code, notes, and snippets.

@akanyuk
Last active November 18, 2020 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akanyuk/7d98ffeeac1316b42d10917f208b85e2 to your computer and use it in GitHub Desktop.
Save akanyuk/7d98ffeeac1316b42d10917f208b85e2 to your computer and use it in GitHub Desktop.
ZX Spectrum demo build makefile example
PROJECT_NAME = my_first_mega_demo
PARTS=intro rotozoomer twister 3dcubes cooper_bars greetings3d moving_shit outro
VER = $(shell git log --format="%h" -n 1)
ifeq ($(COPY_SNAPSHOT_TO),)
COPY_SNAPSHOT_TO = C:\Temp
endif
.PHONY: all clean build help
all: build
build: $(PARTS:%=build/%.bin.zx7) ## Default: build project
@printf "\033[32mBuilding '$(PROJECT_NAME)'\033[0m\n"
sjasmplus --fullpath --inc=src/. \
-DSNA_FILENAME=\"build/$(PROJECT_NAME)-$(VER).sna\" \
-DTRD_FILENAME=\"build/$(PROJECT_NAME).trd\" \
src/main.asm
mktap -b "$(PROJECT_NAME)" 1 <src/loader.bas >build/loader.tap
bintap "build/page0.c" build/0.tap "0" 24576 > build/.bintap-out
bintap "build/page1.c" build/1.tap "1" 49152 > build/.bintap-out
bintap "build/page3.c" build/3.tap "3" 49152 > build/.bintap-out
bintap "build/page4.c" build/4.tap "4" 49152 > build/.bintap-out
cat build/loader.tap build/1.tap build/3.tap build/4.tap build/0.tap >> build/$(PROJECT_NAME).tap
cp --force build/$(PROJECT_NAME)-$(VER).sna $(COPY_SNAPSHOT_TO)
@printf "\033[32mDone\033[0m\n"
build/%.bin.zx7: build/%.bin
@printf "\033[32mBuilding '$@'\033[0m\n"
rm -f $@
zx7 $(subst .zx7,,$@)
@printf "\033[32mdone\033[0m\n\n"
build/%.bin:
@printf "\033[32mCompiling part '$(patsubst build/%.bin,%,$@)'\033[0m\n"
mkdir -p build
sjasmplus --fullpath --inc=src/$(subst part.,,$@)/. --inc=res/$(patsubst build/%.bin,%,$@)/. \
-DSNA_FILENAME=\"$(patsubst %.bin,%,$@)-$(VER).sna\" \
-DBIN_FILENAME=\"$@\" \
src/$(patsubst build/%.bin,%,$@)/main.asm
cp --force $(patsubst %.bin,%,$@)-$(VER).sna $(COPY_SNAPSHOT_TO)
@printf "\033[32mdone\033[0m\n\n"
clean: ## Remove artifacts
rm -f build/*
help: ## Display available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-8s\033[0m %s\n", $$1, $$2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment