2013-04-26 64 views
0

我需要基於某些子系統名稱來計算文件路徑。請參閱下面的MWE。有沒有更簡單的方法來實現同樣的請求?請參閱下面的我的aa,ab,ac和join方法。計算生成文件中的文件路徑

我並不熱衷於$(子系統)的雙重使用,因爲它依賴於以相同順序執行。我試過使用$(patsubst),但它只替換%的第一個實例。請提供任何提示?

# 
## Given some subsystem names 
subsystem := pi_sub_chris \ 
      pi_sub_rob \ 
      pi_sub_greg 

# 
## And an output directory 
dir_export := ../pi_sw/export 

# 
## Calculate a file path in export directory to be made 
## Is there a better way to do this!? 
aa := $(addprefix $(dir_export)/,$(subsystem)) 
ab := $(addsuffix /a2l/, $(aa)) 
ac := $(addsuffix .a2l, $(subsystem)) 
files_to_be_made := $(join $(ab), $(ac)) 

.PHONY : 
go : $(files_to_be_made) 
    @echo Done! 

%.a2l : 
    @echo A perl script is run here to generate file [email protected] 

哪個正確輸出:

A perl script is run here to generate file ../pi_sw/export/pi_sub_chris/a2l/pi_sub_chris.a2l 
A perl script is run here to generate file ../pi_sw/export/pi_sub_rob/a2l/pi_sub_rob.a2l 
A perl script is run here to generate file ../pi_sw/export/pi_sub_greg/a2l/pi_sub_greg.a2l 
Done! 

回答

3

有沒有問題,依靠在這些變量被擴展的順序;即必須爲真或者幾乎每個makefile都會中斷。這絕對有保證。

但是,如果你不喜歡它,你可以使用類似:

files_to_be_made := $(foreach S,$(subsystem),$(dir_export)/$S/a21/$S.a21) 
+0

感謝您提供一個答案。到底是什麼我以後。 – Chris 2013-04-28 19:01:15