@@ -15,16 +15,17 @@ HOSTCC ?= gcc
1515HOSTCXX ?= g++
1616HOSTAR ?= ar
1717HOSTCFLAGS ?= -g -Og
18+ HOSTCXXFLAGS ?= $(HOSTCFLAGS )
1819HOSTLDFLAGS ?= -g
1920
2021CC ?= $(HOSTCC )
2122CXX ?= $(HOSTCXX )
2223AR ?= $(HOSTAR )
2324CFLAGS ?= $(HOSTCFLAGS )
25+ CXXFLAGS ?= $(CFLAGS )
2426LDFLAGS ?= $(HOSTLDFLAGS )
2527
26- export PKG_CONFIG
27- export HOST_PKG_CONFIG
28+ NINJA ?= ninja
2829
2930ifdef VERBOSE
3031 hide =
@@ -63,32 +64,33 @@ EXT ?=
6364
6465CWD =$(shell pwd)
6566
66- ifeq ($(AB_ENABLE_PROGRESS_INFO ) ,true)
67- ifeq ($(PROGRESSINFO),)
68- # The first make invocation here has to have its output discarded or else it
69- # produces spurious 'Leaving directory' messages... don't know why.
70- rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \
71- && $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l))
72- ruleindex := 1
73- PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1)) "
74- endif
75- else
76- PROGRESSINFO = ""
77- endif
67+ define newline
68+
69+
70+ endef
71+
72+ define check_for_command
73+ $(shell command -v $1 >/dev/null || (echo "Required command '$1' missing" >/dev/stderr && kill $$PPID) )
74+ endef
7875
79- PKG_CONFIG_HASHES = $(OBJ ) /.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG ) --list-all | md5sum) )
80- HOST_PKG_CONFIG_HASHES = $(OBJ ) /.pkg-config-hashes/host-$(word 1, $(shell $(HOST_PKG_CONFIG ) --list-all | md5sum) )
76+ $(call check_for_command,ninja)
77+ $(call check_for_command,cmp)
78+ $(call check_for_command,$(PYTHON))
8179
82- $(OBJ ) /build.mk : $(PKG_CONFIG_HASHES ) $(HOST_PKG_CONFIG_HASHES )
83- $(PKG_CONFIG_HASHES ) $(HOST_PKG_CONFIG_HASHES ) & :
84- $(hide ) rm -rf $(OBJ ) /.pkg-config-hashes
85- $(hide ) mkdir -p $(OBJ ) /.pkg-config-hashes
86- $(hide ) touch $(PKG_CONFIG_HASHES ) $(HOST_PKG_CONFIG_HASHES )
80+ pkg-config-hash = $(shell ($(PKG_CONFIG ) --list-all && $(HOST_PKG_CONFIG ) --list-all) | md5sum)
81+ build-files = $(shell find . -name .obj -prune -o \( -name 'build.py' -a -type f \) -print) $(wildcard build/* .py) $(wildcard config.py)
82+ build-file-timestamps = $(shell ls -l $(build-files ) | md5sum)
8783
88- include $(OBJ ) /build.mk
84+ # Wipe the build file (forcing a regeneration) if the make environment is different.
85+ # (Conveniently, this includes the pkg-config hash calculated above.)
8986
90- MAKEFLAGS += -r -j$(shell nproc)
91- .DELETE_ON_ERROR :
87+ ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS
88+ $(shell mkdir -p $(OBJ))
89+ $(file >$(OBJ)/newvars.txt,$(foreach v,$(filter-out $(ignored-variables),$(.VARIABLES)),$(v)=$($(v))$(newline)))
90+ $(shell touch $(OBJ)/vars.txt)
91+ # $(shell diff -u $(OBJ)/vars.txt $(OBJ)/newvars.txt > /dev/stderr)
92+ $(shell cmp -s $(OBJ)/newvars.txt $(OBJ)/vars.txt || (rm -f $(OBJ)/build.ninja && echo "Environment changed --- regenerating" > /dev/stderr))
93+ $(shell mv $(OBJ)/newvars.txt $(OBJ)/vars.txt)
9294
9395.PHONY : update-ab
9496update-ab :
@@ -103,9 +105,15 @@ clean::
103105 $(hide ) rm -rf $(OBJ )
104106
105107export PYTHONHASHSEED = 1
106- build-files = $(shell find . -name 'build.py') $(wildcard build/* .py) $(wildcard config.py)
107- $(OBJ ) /build.mk : Makefile $(build-files ) build/ab.mk
108+ $(OBJ ) /build.ninja $(OBJ ) /build.targets & :
108109 @echo " AB"
109- @mkdir -p $(OBJ )
110- $(hide ) $(PYTHON ) -X pycache_prefix=$(OBJ ) /__pycache__ build/ab.py -o $@ build.py \
111- || rm -f $@
110+ $(hide ) $(PYTHON ) -X pycache_prefix=$(OBJ ) /__pycache__ build/ab.py \
111+ -o $(OBJ ) build.py \
112+ -v $(OBJ ) /vars.txt \
113+ || (rm -f $@ && false)
114+
115+ include $(OBJ ) /build.targets
116+ .PHONY : $(ninja-targets )
117+ .NOTPARALLEL :
118+ $(ninja-targets ) : $(OBJ ) /build.ninja
119+ +$(hide ) $(NINJA ) -f $(OBJ ) /build.ninja $@
0 commit comments