Does GNU Make support '%' in a filename?

﹥>﹥吖頭↗ 提交于 2019-12-10 16:20:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!