bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #55560] .SECONDEXPANSION and eval in target-specific prerequisite l


From: Quinn Mikelson
Subject: [bug #55560] .SECONDEXPANSION and eval in target-specific prerequisite lists
Date: Sun, 27 Jan 2019 23:49:26 -0500 (EST)
User-agent: Mozilla/5.0 (Linux; Android 9; Pixel 2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Mobile Safari/537.36

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]