开发者

What's the name of the Makefile 'match' special variable?

开发者 https://www.devze.com 2023-01-21 14:22 出处:网络
What is the name of the special Makefile variable that contains the match of %, to use in开发者_如何学Go the rule body?

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 is a.%.b then the stem is dir/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 $@
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号