Use % (percent wildcard) in the recipe part of a rule

Viewed 498

I'd like to do something like this:

PHONY += bar
bar:
    $(MAKE) foo_$@

PHONY += foo_%
foo_%:
    cp somedir/%.a someotherdir/

.PHONY: $(PHONY)

But the % isn't evaluated in the recipe (the cp part).

My workaround has been to create a phony target with the same name of the file I want to use, but I would prefer a better solution:

PHONY += bar
bar:
    $(MAKE) foo_$@

PHONY += foo_%
foo_%: %.a
    @:

PHONY += %.a
%.a:
    cp somedir/$@ someotherdir/

.PHONY: $(PHONY)

Is there any way to pass the expansion of % to the shell command?

0 Answers
Related