问题
In GNU Make is it possible to have a dependency on a file that includes a % in the filename? I have something like this:
foo: results(10%).dat
gnuplot config.plt
While I can of course choose a different filename it would be nice to know if % should always be avoided or if there is a simple way to escape it (I've tried \, \\, and %% with no luck).
Edit: My problems seems to be more subtle. It seems to not work because of a combination of matching and a percent filename:
all: foo.txt bar.txt
PERCENT := %
foo%txt bar%txt: results(10$(PERCENT)).dat
touch foo$*txt bar$*txt
This fails but if the filename doesn't have a % it's fine.
回答1:
You could try:
PERCENT := %
foo: results(10$(PERCENT)).dat
gnuplot config.plt
(where the spaces before gnuplot are a tab character really).
回答2:
Percent characters are fine in normal rules like the first rule you posted, it should work as-is.
As for the second example, there doesn't seem to be any reason why you would want a pattern rule:
targets := foo.txt bar.txt
.PHONY: all
all: $(targets)
$(targets): results(10%).dat
touch $(targets)
% can be escaped in static pattern rules
$(targets): %.txt: \%%.txt #dependencies will be %foo.txt and %bar.txt respectively
But there doesn't seem to be any way to escape % in an implicit pattern rule like your second example.
来源:https://stackoverflow.com/questions/37419859/does-gnu-make-support-in-a-filename