Makefile:can’罐头食谱’有参数吗?

前端之家收集整理的这篇文章主要介绍了Makefile:can’罐头食谱’有参数吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题涉及GNU的制作.

如果你有一系列命令可用作多个目标的配方,那么canned recipe就派上用场了.我可能看起来像这样:

  1. define run-foo
  2. # Here comes a
  3. # sequence of commands that are
  4. # executed line by line
  5. endef

现在您可以像这样使用罐装配方:

  1. file1: input1:
  2. $(run-foo)
  3.  
  4. $(pattern) : sub/% : %.inp
  5. $(run-foo)

等等.我想知道是否可以定义带参数的罐装食谱(或类似的东西),以便我可以像这样执行它们:

  1. file2: input2
  2. $(run-foo) specific-parameter2 "additional"
  3.  
  4. file3: input3
  5. $(run-foo) another-parameter3 "text"

这可能吗?任何提示欢迎:)

解决方法

你这样做:

>在定义宏中使用参数$1,$2 …等
>通过$调用宏(调用…)

例如:

  1. define recipe
  2. echo $1
  3. endef
  4.  
  5. all: t1 t2
  6.  
  7. t1:
  8. $(call recipe,"One")
  9.  
  10. t2:
  11. $(call recipe,"Two")

猜你在找的C&C++相关文章