Makefile - $< 用于多个规则
Makefile - $< for multiple rules
根据 gnu make 文档 $<
指的是第一个先决条件:
$<
The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Implicit Rules).
但是,如果我有以下情况:
a: b
a: c
@echo first prerequisite is: $<
这将打印 first prerequisite is c
。虽然这是有道理的,(因为如果 b
被认为是第一个先决条件,它会引发许多尖锐的棍子),但我没有看到任何支持这一点的文档,我想知道我是否可以依赖它是一致的在其他 make 系统中(POSIX 标准似乎也没有对此进行扩展)
POSIX 根本不要求 $<
在显式规则中可用,并且有一些 make 版本不使其可用。所以使用它首先是不可移植的。
来自POSIX:
In an inference rule, the $< macro shall evaluate to the filename whose existence allowed the inference rule to be chosen for the target ... The meaning of the $< macro shall be otherwise unspecified.
添加了重点。 “推理规则”与 GNU make 的隐式规则相同(技术上它只是后缀规则,因为 POSIX 没有定义模式规则)。
就 GNU make 而言,$<
始终是规则 中的第一个先决条件 (我的意思是包含配方的规则)。这绝对是有保证的,我认为 GNU make 手册中应该有文字暗示这一点,但我没有去看。
根据 gnu make 文档 $<
指的是第一个先决条件:
$< The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Implicit Rules).
但是,如果我有以下情况:
a: b
a: c
@echo first prerequisite is: $<
这将打印 first prerequisite is c
。虽然这是有道理的,(因为如果 b
被认为是第一个先决条件,它会引发许多尖锐的棍子),但我没有看到任何支持这一点的文档,我想知道我是否可以依赖它是一致的在其他 make 系统中(POSIX 标准似乎也没有对此进行扩展)
POSIX 根本不要求 $<
在显式规则中可用,并且有一些 make 版本不使其可用。所以使用它首先是不可移植的。
来自POSIX:
In an inference rule, the $< macro shall evaluate to the filename whose existence allowed the inference rule to be chosen for the target ... The meaning of the $< macro shall be otherwise unspecified.
添加了重点。 “推理规则”与 GNU make 的隐式规则相同(技术上它只是后缀规则,因为 POSIX 没有定义模式规则)。
就 GNU make 而言,$<
始终是规则 中的第一个先决条件 (我的意思是包含配方的规则)。这绝对是有保证的,我认为 GNU make 手册中应该有文字暗示这一点,但我没有去看。