11MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION ) ) ) ) ,yes,no)
2- MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION ) ) ) ) ,yes,no)
3- MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4 ) _$(MAKE4.3 ) ) ,yes,no)
42
53ifeq ($(MAKENOT4 ) ,yes)
64$(error You need GNU Make 4.x for this (if you're on OSX, use gmake).)
@@ -17,16 +15,17 @@ HOSTCC ?= gcc
1715HOSTCXX ?= g++
1816HOSTAR ?= ar
1917HOSTCFLAGS ?= -g -Og
18+ HOSTCXXFLAGS ?= $(HOSTCFLAGS )
2019HOSTLDFLAGS ?= -g
2120
2221CC ?= $(HOSTCC )
2322CXX ?= $(HOSTCXX )
2423AR ?= $(HOSTAR )
2524CFLAGS ?= $(HOSTCFLAGS )
25+ CXXFLAGS ?= $(CFLAGS )
2626LDFLAGS ?= $(HOSTLDFLAGS )
2727
28- export PKG_CONFIG
29- export HOST_PKG_CONFIG
28+ NINJA ?= ninja
3029
3130ifdef VERBOSE
3231 hide =
@@ -65,32 +64,33 @@ EXT ?=
6564
6665CWD =$(shell pwd)
6766
68- ifeq ($(AB_ENABLE_PROGRESS_INFO ) ,true)
69- ifeq ($(PROGRESSINFO),)
70- # The first make invocation here has to have its output discarded or else it
71- # produces spurious 'Leaving directory' messages... don't know why.
72- rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \
73- && $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l))
74- ruleindex := 1
75- PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1)) "
76- endif
77- else
78- PROGRESSINFO = ""
79- 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" >&2 && kill $$PPID) )
74+ endef
8075
81- PKG_CONFIG_HASHES = $(OBJ ) /.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG ) --list-all | md5sum) )
82- 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))
8379
84- $(OBJ ) /build.mk : $(PKG_CONFIG_HASHES ) $(HOST_PKG_CONFIG_HASHES )
85- $(PKG_CONFIG_HASHES ) $(HOST_PKG_CONFIG_HASHES ) & :
86- $(hide ) rm -rf $(OBJ ) /.pkg-config-hashes
87- $(hide ) mkdir -p $(OBJ ) /.pkg-config-hashes
88- $(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)
8983
90- 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.)
9186
92- MAKEFLAGS += -r -j$(shell nproc)
93- .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 >&2)
92+ $(shell cmp -s $(OBJ)/newvars.txt $(OBJ)/vars.txt || (rm -f $(OBJ)/build.ninja && echo "Environment changed --- regenerating" >&2))
93+ $(shell mv $(OBJ)/newvars.txt $(OBJ)/vars.txt)
9494
9595.PHONY : update-ab
9696update-ab :
@@ -105,9 +105,15 @@ clean::
105105 $(hide ) rm -rf $(OBJ )
106106
107107export PYTHONHASHSEED = 1
108- build-files = $(shell find . -name 'build.py') $(wildcard build/* .py) $(wildcard config.py)
109- $(OBJ ) /build.mk : Makefile $(build-files ) build/ab.mk
108+ $(OBJ ) /build.ninja $(OBJ ) /build.targets & :
110109 @echo " AB"
111- @mkdir -p $(OBJ )
112- $(hide ) $(PYTHON ) -X pycache_prefix=$(OBJ ) /__pycache__ build/ab.py -o $@ build.py \
113- || 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