18
votes

I want a pattern rule with dependencies constructed both from the stem and using wildcards, i.e. something like

$(FILES): %.o: %.c $(wildcard %*.c)

This doesn't seem to work: the stem % is not expanded within the wildcard function (see http://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html), while the automatic variable $* seems not to be recognized when listing dependencies.

Is there a (not too kludgy) way of doing something like this?

1

1 Answers

25
votes

As is stated in section 10.5.3 of the GNU make manual, automatic variables (which is what $* is) are not available in prerequisites, but it also refers to a work-around, namely secondary expansion.

If I understand it (and you) correctly, something like this should do what you want:

.SECONDEXPANSION:
$(FILES): %.o: %.c $$(wildcard $$**.c)