Skip to content

Commit dcbdcac

Browse files
committed
Update ab.
1 parent a71afea commit dcbdcac

File tree

8 files changed

+249
-171
lines changed

8 files changed

+249
-171
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ HOSTCFLAGS = $(CFLAGS)
4747
ACKCFLAGS = -O
4848

4949
LDFLAGS ?= -g
50+
ACKLDFLAGS =
5051

5152
# Various commands.
5253

build/ab.mk

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ HOSTCC ?= gcc
1515
HOSTCXX ?= g++
1616
HOSTAR ?= ar
1717
HOSTCFLAGS ?= -g -Og
18+
HOSTCXXFLAGS ?= $(HOSTCFLAGS)
1819
HOSTLDFLAGS ?= -g
1920

2021
CC ?= $(HOSTCC)
2122
CXX ?= $(HOSTCXX)
2223
AR ?= $(HOSTAR)
2324
CFLAGS ?= $(HOSTCFLAGS)
25+
CXXFLAGS ?= $(CFLAGS)
2426
LDFLAGS ?= $(HOSTLDFLAGS)
2527

26-
export PKG_CONFIG
27-
export HOST_PKG_CONFIG
28+
NINJA ?= ninja
2829

2930
ifdef VERBOSE
3031
hide =
@@ -63,32 +64,33 @@ EXT ?=
6364

6465
CWD=$(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
9496
update-ab:
@@ -103,9 +105,15 @@ clean::
103105
$(hide) rm -rf $(OBJ)
104106

105107
export 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 $@

build/ab.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rule rule
2+
command = $command

0 commit comments

Comments
 (0)