Reputation: 315
I used to think that '%' in Makefiles was the equivalent to '*' in bash, therefore something like this would make sense:
%.o: %.c
gcc $< -o $@
However, it doesn't work when trying to retrieve files starting with something, which in bash can be done like ls test*
, for example:
#retrieve all files starting with test
test%: %.c
gcc $< -o $@
Can anyone explain how this could be done?
Upvotes: 0
Views: 108
Reputation: 100856
It does work exactly like *
in shell globbing, except that %
must match at least one character while *
can match zero characters.
If you have problems please be sure to use a real example, and show the command you typed and the output you got, and explain why that output is not what you wanted, else we can only guess.
First, you don't add a colon to the end of your pattern rule; since that's a syntax error I'll assume that your real makefile just has one colon:
test%: %.c
...
You haven't given us an actual example so we can't say for sure, but most likely the problem you are having is forgetting that the value of %
must be identical in the target and prerequisite for the rule to match.
So if you have a pattern rule with test% : %.c
and you want to build a target testfoo
, the pattern matches foo
, which means you have to have a file foo.c
.
If your source file is testfoo.c
instead, you have to write test% : test%.c
You can use make -d
to understand why make is not using your pattern rule.
Upvotes: 1