I'm trying to improve our current GNU Make based build system. It is half non-recursive and half-recursive.
Following [1], it is non-recursive on the directory tree. While sources are organized across directories in logical modules, they're ultimately brought in to a single dependency graph.
However, it is also a multi-architecture build similar to what's described in [2] (such as 32-bit vs 64-bit, but also RELEASE vs DEBUG and Internal vs External, resulting in a large number of possible combinations), and that aspect is recursive: the top-level makefile calls itself with a given apps target with different variables (CPU_WIDTH=32 or =64).
This regularly causes problems, as certain targets need to be built only once at the top-level, while most others need to be built with appropriate flags per-architecture in the recursed levels. Regularly we discover that some build-once targets are actually being built multiple times, having been somehow swept into the recursive's dependency tree.
How could I design a Makefile such that it could contain the entire multi-architecture dependency graph in one non-recursive invocation of Make?
I feel like a key feature is using target-specific variables, which crucially propagate down the dependency graph. Unfortunately, a given named target will only be built once, even if it should be built multiple times with different options. A way around this would be to add some arch-specific info in the target name (for example, instead of target foo.o, make it 32/foo.o and 64/foo.o), but in the following naive example this didn't work:
.PHONY: all exe32 exe64 baz-$(ARCH)
all: exe32 exe64
exe32: ARCH = 32
exe32: baz-$(ARCH)
@echo in $@ ARCH is $(ARCH)
exe64: ARCH = 64
exe64: baz-$(ARCH)
@echo in $@ ARCH is $(ARCH)
baz-$(ARCH):
@echo in $@ ARCH is $(ARCH)
This results in the erroneous output:
in baz- ARCH is 32
in exe32 ARCH is 32
in exe64 ARCH is 64
make -C arm64 -f ../src/Makefile && make -C arm32 -f ../src/Makefile(or even some version ofall: $(ARCHES)and%:⤶↦$(MAKE) -C $@in a top-level Makefile). - Toby Speight