Reputation: 4716
I am slowly fighting my way through the gnu make documentation jungle (although it's excellent — just a lot).
I encountered pattern rules:
%.png: file1 file2
run command here
There are also wildcards usable as targets:
FILES = $(wildcard *.png)
Now I could write:
$(FILES): file1 file2
run command here
Is there any difference between the first and the second use case?
Upvotes: 2
Views: 52
Reputation: 13914
In the case of %.png
: If any other rule, in turn, asks for some file, which does not itself have an explicit rule, but ends in .png
, then this rule will be invoked.
So, %.png: %.jpeg
(for example) says, “unless there is a more specific rule, here is how to convert from a JPEG to a PNG image.”
$(FILES)
is enumerating a list of dependencies that you might want to create. It's not really the sort of thing for the target of a rule, but rather, for the dependencies of one.
For example, a phony target like images.zip: $(FILES)
could be used to say that all of the $(FILES)
must be up-to-date before making images.zip
.
Using wildcard sources is, of course, rather “dangerous” as missing files won't be detected by make
, so it's possible to have a “falsely positive” result of a build.
Upvotes: 2