【发布时间】:2014-11-17 18:47:57
【问题描述】:
我正试图围绕模式规则以及它们的功能展开思考。我正在使用this文章作为参考,其中说明了
模式规则是为许多文件指定规则的简洁方式 一次。该规则将取决于文件名,但通常取决于 以简单的方式在他们身上。您可以使用 % 指定模式 通配符。当存在于依赖列表中时, % 匹配任何字符串 任何长度;当出现在目标列表中时,% 代表 依赖列表中 % 匹配的字符串。
以下模式规则将获取任何 .c 文件并将其编译为 .o 文件:
%.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -c $(input) -o $(output)(假设您有变量 CC、CFLAGS 和 INCLUDES 定义为合适的东西。 Makepp 会猜测 CC 的值,然后 CFLAGS。)
规则的第一行说它适用于所有可能的情况 匹配模式 %.c 的输入文件。这些 .c 文件可以是 使用指定的转换成对应的 .o 文件 行动。
规则的动作与我们见过的其他动作非常相似 以前,除了它使用自动变量。一个自动 variable 是一个变量,其值由 makepp 自动设置 取决于它出现的规则。一些有用的自动 变量是:
$(input)
The name of the first input file. In this rule, this would be the file that matches the %.c pattern. $(dependency) is a synonymn for $(input). In older makefiles, you will also see the cryptic symbol $< used as well.
$(output)
The name of the first output file. In this rule, this would be the file that matches the %.o pattern. $(target) and $@ are synonymns.
$(inputs)
The name of all explicitly listed input files. In this case, since there is only one, $(inputs) is equivalent to $(input). $(dependencies) and $^ are synonymns.
$(outputs)
The name of all explicitly listed targets. In this case, since there is only one, $(outputs) is equivalent to $(output). $(targets) is a synonymn for $(outputs).
以下是我的问题:
1) 假设我有 2 个文件 FileA.c 和 FileB.c。当我应用上述模式规则时,它将如何应用于上述两个文件。给出的示例仅处理一个文件。
2) 自动变量input和inputs有什么区别
【问题讨论】:
标签: makefile