2014-01-21 21 views
6

我的問題與GNU的問題有關。Makefiles:可以'罐頭食譜'有參數?

如果您有一系列可用作多個目標配方的命令,則可以使用canned recipe。我可能是這樣的:

define run-foo 
# Here comes a 
# sequence of commands that are 
# executed line by line 
endef 

現在你可以使用罐裝配方是這樣的:

file1: input1: 
    $(run-foo) 

$(pattern) : sub/% : %.inp 
    $(run-foo) 

等。我不知道是否有可能定義一個帶參數罐裝配方(或類似的東西),這樣我就可以這樣執行它們:

file2: input2 
    $(run-foo) specific-parameter2 "additional" 

file3: input3 
    $(run-foo) another-parameter3 "text" 

這可能嗎?任何提示歡迎:)

回答

11

您可以通過這樣做:

  • 使用參數$1$2 ...等你define -ed宏觀
  • 調用宏通過$(call ...)

如:

define recipe 
echo $1 
endef 

all: t1 t2 

t1: 
    $(call recipe,"One") 

t2: 
    $(call recipe,"Two") 
+1

The Automatic變量是有效的,所以你的罐頭食譜可能像'$ {opts - $ @}'一樣變得僵硬。當然,你會事先定義'opts-t1'和'opts-t2'。 – bobbogo

+0

行情在這裏沒有必要。 – Frug