Reputation: 8756
Suppose I have some targets in a Makefile as below:
A-foobar-int:
mvn test -Dtest.env=(@:X-foobar-%=%)
B-foobar-qa:
mvn test -Dtest.env=(@:X-foobar-%=%)
C-foobar-int:
mvn test -Dtest.env=(@:X-foobar-%=%)
Currently, the X as in X-foobar-% is something I am trying to figure out. Basically, what I want to achieve is have a general pattern in all the target actions, instead of A-foobar-%
, B-foobar-%
, or C-foobar-%
. So, what should I do?
Upvotes: 0
Views: 193
Reputation: 151511
If I understood your question correctly, this does what you want:
%-foobar-int:
@echo mvn test -Dtest.env=$(@:$*-foobar-%=%)
%-foobar-qa:
@echo mvn test -Dtest.env=$(@:$*-foobar-%=%)
There's only 2 rules because A-foobar-int
and C-foobar-int
are both handled by the first rule. The rules use $*
to get the value of the stem matched by the target patterns. (And I'm using echo
to check the results because I not set to run the command.)
Upvotes: 1
Reputation: 57203
So, you want to drop the first two tokens of $@ (when -
is used as a tokenizer).
Here we go:
drop-two-tokens-helper = $(subst $(word 1,$3)$2$(word 2,$3)$2,,$1)
drop-two-tokens = $(call drop-two-tokens-helper,$2$2$2$1,$2,$2$2$2$(subst $2, ,$1))
A-foobar-int:
mvn test -Dtest.env=$(call drop-two-tokens,$@,-)
Upvotes: 0