简体   繁体   English

GNU是否在文件名中支持'%'?

[英]Does GNU Make support '%' in a filename?

In GNU Make is it possible to have a dependency on a file that includes a % in the filename? 在GNU Make中,是否可以依赖文件名中包含%的文件? 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. 这会失败,但如果文件名没有%那就没关系。

You could try: 你可以尝试:

PERCENT := %
foo: results(10$(PERCENT)).dat
    gnuplot config.plt

(where the spaces before gnuplot are a tab character really). (其中gnuplot之前的空格确实是制表符)。

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. 但似乎没有任何方法可以像第二个例子那样在隐式模式规则中逃避%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM