Ligio
Ligio

Reputation: 627

Makefile: is it possible to have stem with slash?

I have these files:

 tests/prova.txt
 tests/mydir/prova.txt

In my Makefile I have a target like that for printing file paths (it's just an example):

checkf-%:
    echo tests/${@:checkf-%=%}.txt

If I call

make checkf-prova

it works! But if I call

make checkf-mydir/prova

I get

make: No rule to make target

How can I call the target with a slash in % ?

Upvotes: 4

Views: 3040

Answers (1)

John
John

Reputation: 3520

The stem (% sign) only matches valid filename characters, and thus will not match strings with /'s in them. Having said that, pattern rules will strip directory names before trying to match, and then reinsert them when running the recipes, so:

p%.txt :
    @echo p\%.txt matches $@

will work with:

~/tmp> make tests/prova.txt
p%.txt matches tests/prova.txt

(notice that this is specific to pattern rules. test/prova.txt will not match a prova.txt target, but will match the p%.txt target). See http://www.gnu.org/software/make/manual/html_node/Pattern-Match.html#Pattern-Match for more details.

Upvotes: 7

Related Questions