help-make
[Top][All Lists]
Advanced

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

Secondary expansion and pattern rules


From: Mike Haboustak
Subject: Secondary expansion and pattern rules
Date: Fri, 8 Feb 2019 14:32:53 -0500

I've been trying to make use of secondary expansion and I ran into some
confusion that I couldn't reconcile with manual. Specifically, The value
of the automatic variable $< is not what I'd expect during the second
expansion of an implicit rule prerequisite.

In the makefile below, foo.o is built via the %.o: %.c pattern rule, and
the value of $< printed by $(info) is foo.o, not foo.c.

If I use an explicit rule, as used for bar.o, the value of $< is bar.c,
as I expect.

It seems that the value of $< is getting defaulted for implicit rules
during second expansion. However, the value of $< is correct in the
recipe.

If this is the expected behavior, is there a way I can use secondary
expansion with implicit rules and get the correct value of $< for foo.o
(foo.c)?

---
--- Example Makefile
MAKEFLAGS += -rR
.SECONDEXPANSION:

.PHONY: all
all: test

test: foo.o bar.o

%.o: %.c
        @echo Turning $< into $@
        @touch $@

foo.o: baz.c
bar.o: bar.c baz.c
        @echo Turning $< into $@
        @touch bar.o

foo.o: $$(info in foo.o\: $$$$< = $$< and $$$$^ = $$^)
bar.o: $$(info in bar.o\: $$$$< = $$< and $$$$^ = $$^)

baz.c:
        @touch baz.c
foo.c:
        @touch foo.c
bar.c:
        @touch bar.c


---
--- Make output
in foo.o: $< = foo.o and $^ = baz.c
in bar.o: $< = bar.c and $^ = bar.c baz.c
Turning foo.c into foo.o
Turning bar.c into bar.o

---
--- foo.o rule from make -p
foo.o: foo.c baz.c
#  Implicit rule search has been done.
#  Implicit/static pattern stem: 'foo'
#  Last modified 2019-02-08 18:57:12.169408599
#  File has been updated.
#  Successfully updated.
# automatic
# @ := foo.o
# automatic
# % :=
# automatic
# * :=
# automatic
# + := baz.c
# automatic
# | :=
# automatic
# < := foo.o
# automatic
# ^ := baz.c
# automatic
# ? :=
# variable set hash-table stats:
# Load=8/32=25%, Rehash=0, Collisions=1/10=10%
#  recipe to execute (from 'Makefile', line 11):
        @echo Turning $< into $@
        @touch $@


- Mike



reply via email to

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