Skip to content

Commit

Permalink
Merge pull request #195 from davidgiven/ab
Browse files Browse the repository at this point in the history
Update ab.
  • Loading branch information
davidgiven authored Oct 29, 2024
2 parents 342ceb9 + 3b623f1 commit 1ddaa19
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 265 deletions.
42 changes: 38 additions & 4 deletions build/ab.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
ifeq ($(findstring 4.,$(MAKE_VERSION)),)
MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no)
MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no)
MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no)

ifeq ($(MAKENOT3),yes)
$(error You need GNU Make 4.x for this (if you're on OSX, use gmake).)
endif

Expand All @@ -10,9 +14,12 @@ AR ?= ar
CFLAGS ?= -g -Og
LDFLAGS ?= -g
PKG_CONFIG ?= pkg-config
HOST_PKG_CONFIG ?= $(PKG_CONFIG)
ECHO ?= echo
CP ?= cp
TARGETS ?= +all

export PKG_CONFIG
export HOST_PKG_CONFIG

ifdef VERBOSE
hide =
Expand All @@ -24,17 +31,44 @@ else
endif
endif

WINDOWS := no
OSX := no
LINUX := no
ifeq ($(OS),Windows_NT)
WINDOWS := yes
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LINUX := yes
endif
ifeq ($(UNAME_S),Darwin)
OSX := yes
endif
endif

ifeq ($(OS), Windows_NT)
EXT ?= .exe
endif
EXT ?=

ifeq ($(PROGRESSINFO),)
rulecount := $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 && $(MAKE) -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l)
# The first make invocation here has to have its output discarded or else it
# produces spurious 'Leaving directory' messages... don't know why.
rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \
&& $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l))
ruleindex := 1
PROGRESSINFO = "$(shell $(PYTHON) build/_progress.py $(ruleindex) $(rulecount))$(eval ruleindex := $(shell expr $(ruleindex) + 1))"
PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1))"
endif

PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG) --list-all | md5sum))
HOST_PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/host-$(word 1, $(shell $(HOST_PKG_CONFIG) --list-all | md5sum))

$(OBJ)/build.mk : $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)
$(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) &:
$(hide) rm -rf $(OBJ)/.pkg-config-hashes
$(hide) mkdir -p $(OBJ)/.pkg-config-hashes
$(hide) touch $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)

include $(OBJ)/build.mk

MAKEFLAGS += -r -j$(shell nproc)
Expand Down
17 changes: 13 additions & 4 deletions build/ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __init__(self, cwd, name):
self.dir = join("$(OBJ)", name)
self.ins = []
self.outs = []
self.deps = []
self.materialised = False
self.args = {}

Expand Down Expand Up @@ -419,10 +420,18 @@ def emit_rule(name, ins, outs, cmds=[], label=None):
emit(".PHONY:", name, into=lines)
if outs:
emit(name, ":", *fouts, into=lines)
emit(*fouts, "&:" if len(fouts) > 1 else ":", *fins, "\x01", into=lines)
if len(fouts) == 1:
emit(*fouts, ":", *fins, "\x01", into=lines)
else:
emit("ifeq ($(MAKE4.3),yes)", into=lines)
emit(*fouts, "&:", *fins, "\x01", into=lines)
emit("else", into=lines)
emit(*(fouts[1:]), ":", fouts[0], into=lines)
emit(fouts[0], ":", *fins, "\x01", into=lines)
emit("endif", into=lines)

if label:
emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO) ", label, into=lines)
emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO)", label, into=lines)
for c in cmds:
emit("\t$(hide)", c, into=lines)
else:
Expand Down Expand Up @@ -472,7 +481,7 @@ def simplerule(
name=self.name,
ins=ins + deps,
outs=outs,
label=self.templateexpand("{label} {name}"),
label=self.templateexpand("{label} {name}") if label else None,
cmds=cs,
)

Expand All @@ -498,7 +507,7 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []):
ins=[srcs[0]],
outs=[destf],
commands=["$(CP) %s %s" % (srcs[0], destf)],
label="CP",
label="",
)
subrule.materialise()

Expand Down
Loading

0 comments on commit 1ddaa19

Please sign in to comment.