2016-01-23 58 views
0

比方說,我有這樣的GNU生成文件:

SOURCE = source1/a source2/b source3/c 
BUILD = build/a build/b build/c 
BASE = build/ 

$(BUILD): $(BASE)%: % 
    install $< [email protected] 

所以基本上我在目錄來源1源2source3,文件,這我想無論如何放進建立目錄。

我想用一個靜態模式規則來實現這一點。我天真的做法是:

$(BUILD): $(BASE)%: $(filter *%, $(SOURCE)) 
    install $< [email protected] 

這是行不通的。我知道過濾器也用百分號表示。

$(BUILD): $(BASE)%: $(wildcard */$(notdir %)) 
    install $< [email protected] 

這也行不通。但即使如此,這仍然是不令人滿意的,因爲我可能想touch一個新的文件source1/b,這會弄亂一切。

如何在GNU makefile靜態模式規則中使用$(filter)函數?還是有另一種方法來做到這一點?

層次結構現在看起來是這樣的:

source1/ 
     a 
source2/ 
     b 
source3/ 
     c 
build/ 

我希望它看起來像這樣:

source1/ 
     a 
source2/ 
     b 
source3/ 
     c 
build/ 
     a 
     b 
     c 
+0

如果你有'源1/B'和'源2/B',你要投入'然後呢建/'? – Beta

+0

我想把'a','b'和'c'放入'build'中。 – hgiesel

+0

*您想將哪個''b'放入'build /'中?你說你可能希望在'source2/b'之外引入'source/b',但是你沒有說你想在這種情況下做什麼。 – Beta

回答

2

你可以用the VPATH variable做到這一點:

SOURCE = source1/a source2/b source3/c 
BUILD = build/a build/b build/c 
BASE = build/ 

VPATH = source1 source2 source3 

$(BUILD): $(BASE)%: % 
    install $< [email protected] 

或者:

SOURCE = source1/a source2/b source3/c 
BASE = build/ 
BUILD = $(addprefix $(BASE), $(notdir $(SOURCE))) 

VPATH = $(dir $(SOURCE)) 

$(BUILD): $(BASE)%: % 
    install $< [email protected] 
1

讀一千#1的問題和GNU做教程了幾個小時後,我終於得到它的工作:

SOURCE = source1/a source2/b source3/c 
TEST = a b c 
BUILD = build/a build/b build/c 
BASE = build/ 
PERCENT = % 

.SECONDEXPANSION: 
$(BUILD): $(BASE)%: $$(filter $$(PERCENT)/$$*,$$(SOURCE)) 
    install $< [email protected] 

這是有點hacky,但我很高興它。如果有人有任何更好的想法,請讓我知道。