makefile:can';罐装食谱';有参数吗?

makefile:can';罐装食谱';有参数吗?,makefile,dependencies,build-process,gnu-make,Makefile,Dependencies,Build Process,Gnu Make,我的问题涉及GNU的品牌 如果您有一系列命令,这些命令对于多个目标非常有用,那么一个命令就派上了用场。我可能看起来像这样: 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 $(r

我的问题涉及GNU的品牌

如果您有一系列命令,这些命令对于多个目标非常有用,那么一个命令就派上了用场。我可能看起来像这样:

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"
现在,您可以使用如下罐装配方:

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"
等等。我想知道是否有可能定义带参数的罐装食谱(或类似的东西),以便我可以像这样执行它们:

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"
这可能吗?任何提示欢迎:)

您可以通过以下方式完成此操作:

  • 使用参数
    $1
    $2
    。。。在
    定义
    -ed宏中使用etc
  • 通过
    $(调用…)调用宏
e、 g:


自动变量是有效的,因此罐装配方可以像
${opts-$@}
那样展开。当然,您已经在手上定义了
opts-t1
opts-t2
。这里不需要引号。