What's the name of the Makefile 'match' special variable?
What is the name of the special Makefile variable that contains the match of %
, to use in开发者_如何学Go the rule body?
As an example, I would like to use it like this:
%.o: %.c
@echo Matched $MATCH
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
where I put $MATCH
there because I can't remember the actual name of that special pattern-match variable.
In other words, if the user says make foo.c
I want to output Matched foo
.
I didn't find it here, but I it exists because I've used it before ...
From the GNU Make software manual, the special variable you are referring to is $*
, the implicit stem match:
The stem with which an implicit rule matches (see How Patterns Match). If the target is
dir/a.foo.b
and the target pattern isa.%.b
then the stem isdir/foo
. The stem is useful for constructing names of related files.
I don't see a specific variable, but here is a solution for you:
%.o: %.c
@echo Matched `basename $@ .o`
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
精彩评论