如何在Makefile中使用自动变量获取第二个依赖项文件?

Yu *_*hou 36 makefile gnu-make

我需要从规则中获取第n个依赖文件,类似于bash中的$ n.我需要这个,因为我想将各个依赖项文件作为构建程序的选项提供.

这是一个例子:

dep.o: dep.src config1.cfg config2.cfg
    parse -cfg1 $2 -cfg2 $3 -o $@ $<
Run Code Online (Sandbox Code Playgroud)

可能吗?

Bet*_*eta 53

dep.o: dep.src config1.cfg config2.cfg
    @echo the second preq is $(word 2,$^), the third is $(word 3,$^)
Run Code Online (Sandbox Code Playgroud)

  • (GNU) make 手册中的参考文献:[10.5.3 自动变量](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html) for `$^` (“名称所有先决条件,它们之间有空格”),以及 [8.2 字符串替换和分析函数](https://www.gnu.org/software/make/manual/html_node/Text-Functions.html) `$ (word n,text)`(“返回 *text* 的 *n* 个单词”)。 (4认同)