有沒有辦法讓GNU make與包含冒號的文件名一起正確工作?在Makefile中轉義文件名冒號
我遇到的具體問題恰好涉及模式規則。下面是一個不依賴於剪切和粘貼製表符的簡化版本:
% make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
% cat Makefile
COLON := \:
all: ; true
%.bar: ; cp $< [email protected]
x.bar: x.foo
%.foo: ; touch [email protected]
a$(COLON)b.bar: a$(COLON)b.foo
all: x.bar a$(COLON)b.bar
clean: ; rm -f *.foo *.bar
% make clean
rm -f *.foo *.bar
% make
touch x.foo
cp x.foo x.bar
cp a\:b.bar
cp: missing destination file operand after `a:b.bar'
Try `cp --help' for more information.
make: *** [a\:b.bar] Error 1
用文字代替$(冒號):產生完全相同的結果。如果沒有反斜槓,它這樣做:
Makefile:6: *** target pattern contains no `%'. Stop.
相當不錯的破解!我用$(shell)很好,我的問題是GNU make特有的。我想這應該是另一個答案中提到的「討厭的臨時文件安排」的例子。我確實擔心在「ls」是佔位符的情況下失敗並且$(POST)因此無法運行的情況下會發生什麼情況。我的意思是我猜這可能大多是好的,因爲$(PRE)是冪等的,對嗎?如果您的文件名中可能包含真正的@ COLON @ s,那麼您只需使用更長,更荒謬的佔位符,可能會嵌入一長串隨機字符串.... – zaphod 2014-07-11 22:37:40