# Top-level build Makefile for NES disassembly projects # Builds every project under the mapper directories at once. # # Two tiers live in this repo: # // promoted projects - built by "all", "clean" and "" # _wip/// pre-promotion tier - built only by "wip" # Nothing except "wip"/"wipclean" touches the _wip/ tree. MAPPERS := NROM AOROM CNROM MMC1 MMC3 MMC5 UNROM MAPPER8 # The pre-promotion tier lives under _wip/. Only the "wip" and "wipclean" # targets reach it; "all", "clean" and "" never do. WIP := _wip .PHONY: all clean wip wipclean $(MAPPERS) help # Build one project directory. Expects the shell variable "project" to hold # the project path; records the result in status/passed/failed/count. define build_project if [ -f "$$project/Makefile" ]; then \ echo "=== Building $$project ==="; \ count=$$((count + 1)); \ if $(MAKE) -C "$$project"; then \ printf '%b' "$$GREEN"; \ echo ">>> $$project: Passed"; \ printf '%b' "$$RESET"; \ passed="$$passed|$$project"; \ else \ printf '%b' "$$RED"; \ echo ">>> $$project: Failed"; \ printf '%b' "$$RESET"; \ failed="$$failed|$$project"; \ status=1; \ fi; \ else \ echo "=== Skipping $$project (no Makefile) ==="; \ fi; endef # Print the pass/fail summary. Expects the shell variables status/passed/ # failed/count and msg (the success headline) to be set. define summary echo ""; \ echo "=== $1 Summary ==="; \ printf '%b' "$$GREEN"; \ pcount=$$(echo "$$passed" | tr '|' '\n' | grep -c .); \ echo "Passed ($$pcount):"; \ echo "$$passed" | tr '|' '\n' | grep -v '^$$' | sed 's/^/ - /'; \ printf '%b' "$$RESET"; \ if [ -n "$$failed" ]; then \ printf '%b' "$$RED$$BOLD"; \ fcount=$$(echo "$$failed" | tr '|' '\n' | grep -c .); \ echo "Failed ($$fcount):"; \ echo "$$failed" | tr '|' '\n' | grep -v '^$$' | sed 's/^/ - /'; \ printf '%b' "$$RESET"; \ fi; \ if [ $$status -eq 0 ]; then \ printf '%b' "$$GREEN$$BOLD"; \ echo ">>> $$msg"; \ printf '%b' "$$RESET"; \ else \ printf '%b' "$$RED$$BOLD"; \ echo ">>> Some projects Failed"; \ printf '%b' "$$RESET"; \ fi; endef all: @status=0; \ GREEN='\033[32m'; RED='\033[31m'; BOLD='\033[1m'; RESET='\033[0m'; \ passed=""; failed=""; count=0; \ for m in $(MAPPERS); do \ for d in "$$m"/*/; do \ [ -d "$$d" ] || continue; \ project="$${d%/}"; \ $(call build_project) \ done; \ done; \ msg="All $$count Projects Passed"; \ $(call summary,Build) \ exit $$status clean: @status=0; \ for m in $(MAPPERS); do \ for d in "$$m"/*/; do \ [ -d "$$d" ] || continue; \ project="$${d%/}"; \ if [ -f "$$project/Makefile" ]; then \ echo "=== Cleaning $$project ==="; \ $(MAKE) -C "$$project" clean || status=1; \ fi; \ done; \ done; \ exit $$status # Pre-promotion tier (_wip///). Explicitly opt-in: no other # target builds, cleans or otherwise reaches into the _wip/ tree. wip: @status=0; \ GREEN='\033[32m'; RED='\033[31m'; BOLD='\033[1m'; RESET='\033[0m'; \ passed=""; failed=""; count=0; \ for m in $(WIP)/*/; do \ [ -d "$$m" ] || continue; \ for d in "$$m"*/; do \ [ -d "$$d" ] || continue; \ project="$${d%/}"; \ $(call build_project) \ done; \ done; \ msg="All $$count WIP Projects Passed"; \ $(call summary,WIP Build) \ exit $$status # Clean the pre-promotion tier only. wipclean: @status=0; \ for m in $(WIP)/*/; do \ [ -d "$$m" ] || continue; \ for d in "$$m"*/; do \ [ -d "$$d" ] || continue; \ project="$${d%/}"; \ if [ -f "$$project/Makefile" ]; then \ echo "=== Cleaning $$project ==="; \ $(MAKE) -C "$$project" clean || status=1; \ fi; \ done; \ done; \ exit $$status # Per-mapper targets, e.g. "make MMC3" $(MAPPERS): @status=0; \ GREEN='\033[32m'; RED='\033[31m'; BOLD='\033[1m'; RESET='\033[0m'; \ passed=""; failed=""; count=0; \ for d in "$@"/*/; do \ [ -d "$$d" ] || continue; \ project="$${d%/}"; \ $(call build_project) \ done; \ msg="All $$count $@ Projects Passed"; \ $(call summary,$@ Build) \ exit $$status help: @echo "Usage: make [target]" @echo "" @echo "Targets:" @echo " all - Build and verify every promoted project (all mappers)" @echo " clean - Clean build artifacts in every promoted project" @echo " - Build only one mapper: $(MAPPERS)" @echo " wip - Build and verify every project under $(WIP)/ (pre-promotion tier)" @echo " wipclean - Clean build artifacts under $(WIP)/" @echo " help - Show this help"