Follow-up Comment #2, bug #55560 (project make): I noticed that running my library builds in parallel seemed to break things more often that running them serially. Looking at the previous examples there is indeed some ambiguity in the prerequisites parsing order. I found some old email threads discussing static patterns with patterned subdirectories to accesse similarly patterned variables and I'm fairly certain I've come up with a solution:
=== Makefile === TARGET := libfoo all: SOURCES := foo.cc bar.cc tests: SOURCES := foo.cc bar.cc test.cc include library.mk === library.mk === WORKDIR := $(CURDIR)/.work LIBRARY := $(LIBDIR)/$(TARGET).so # This macro uses the stem of a pattern to export target-specific variables OBJECT_PATTERN = $(eval $*-OBJECTS := $(SOURCES:%.cc=%.o)) LIBRARY_TARGETS := all tests PHONY: $(LIBRARY_TARGETS) .SECONDEXPANSION: $(LIBRARY_TARGETS) # Static pattern forces the preprocessor to evaluate LIBRARY_TARGETS first, then LIBRARY $(LIBRARY_TARGETS): %: $$(OBJECT_PATTERN) $(WORKDIR)/%/$(LIBRARY) ; # We have to write the LIBRARY as a pattern to get our preprocessor trick to work correctly. ## Here we nest it in a subdirectory and have it access the variable we exported earlier. $(WORKDIR)/%/$(LIBRARY): $$(%-OBJECTS) $(LD) $^ -o $@ Writing the phony library targets as static pattern rules and modifying the Library target to contain a pattern-specific variable seems to work. Is my understanding of "forcing" the pattern parsing order correct here? Anyway, I've tested this on a number of different source trees and all of my usage tests have been working. Coincidentally I have noticed builds are marginally slower, so this technique may imply a performance penalty. If there's anyone out there that can chime in, I'd be very grateful. _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?55560> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/ _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make