Makefile 自动变量 @F 不会在依赖项中扩展
Makefile automatic variable @F doesn't get expanded in dependencies
在下面的 Makefile 中 $F
没有展开,它只是空的。我想知道使用 @F
而不是显式编写依赖项的优雅解决方案是什么?
nested-cycles.scala first.scala follow.scala : ../$(basename $(@F)).aps ${APS2SCALA}
${APS2SCALA} ${APS2SCALAFLAGS} -S $(basename $(@F))
你是对的。见 GNU make manual:
It’s very important that you recognize the limited scope in which automatic variable values are available: they only have values within the recipe. In particular, you cannot use them anywhere within the target list of a rule; they have no value there and will expand to the empty string. Also, they cannot be accessed directly within the prerequisite list of a rule. A common mistake is attempting to use $@ within the prerequisites list; this will not work.
通常的处理方式是写一个 pattern rule 告诉 make 如何根据使用该模式的先决条件构建匹配给定模式的目标。对于您的示例,它将是这样的:
%.scala : ../%.aps ${APS2SCALA}
${APS2SCALA} ${APS2SCALAFLAGS} -S $*
在下面的 Makefile 中 $F
没有展开,它只是空的。我想知道使用 @F
而不是显式编写依赖项的优雅解决方案是什么?
nested-cycles.scala first.scala follow.scala : ../$(basename $(@F)).aps ${APS2SCALA}
${APS2SCALA} ${APS2SCALAFLAGS} -S $(basename $(@F))
你是对的。见 GNU make manual:
It’s very important that you recognize the limited scope in which automatic variable values are available: they only have values within the recipe. In particular, you cannot use them anywhere within the target list of a rule; they have no value there and will expand to the empty string. Also, they cannot be accessed directly within the prerequisite list of a rule. A common mistake is attempting to use $@ within the prerequisites list; this will not work.
通常的处理方式是写一个 pattern rule 告诉 make 如何根据使用该模式的先决条件构建匹配给定模式的目标。对于您的示例,它将是这样的:
%.scala : ../%.aps ${APS2SCALA}
${APS2SCALA} ${APS2SCALAFLAGS} -S $*