views:

13

answers:

2

What is the name of the special Makefile variable that contains the match of %, to use in 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 ...

A: 

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 $@
David Jones
oops, I see it now: $*
David Jones