【发布时间】:2021-11-17 21:23:18
【问题描述】:
我有一个 makefile 可以从 yaml 文件生成一些头文件和 cpp 文件。
../api/%.h ../api/%.cpp : ../idl/%.yml
$(info Generating api files from $<)
$(IDL_TO_CPP_EXE) --input $< --output $(basename $@)
IDL_HEADERS=$(IDL_INPUTS:../idl/%.yml=../api/%.h)
IDL_CPPS=$(IDL_INPUTS:../idl/%.yml=../api/%.cpp)
all: $(IDL_HEADERS) $(IDL_CPPS)
$(info The dependencies are $(IDL_HEADERS) $(IDL_CPPS))
IDL_INPUTS +=../idl/common_api/CommonTypes.yml
当我运行它时,它会输出以下内容,但不会生成 .h 和 .cpp 文件。我已经检查过它们不存在,所以这不是时间戳问题。
The dependencies are ../api/common_api/CommonTypes.h ../api/common_api/CommonTypes.cpp
make: Nothing to be done for 'all'.
如果我手动将变量扩展为以下,那么它突然开始工作!日志的控制台输出完全一样,我一直小心避免隐藏字符之类的东西。
all: ../api/common_api/CommonTypes.h ../api/common_api/CommonTypes.cpp
$(info The dependencies are $(IDL_HEADERS) $(IDL_CPPS))
为什么这个 makefile 使用显式依赖,而不使用变量?
更新:
all: $(IDL_HEADERS) $(IDL_CPPS)
$(info The dependencies are $^)
$(info The dependencies should be $(IDL_HEADERS) $(IDL_CPPS))
输出:
The dependencies are
The dependencies should be ../api/common_api/CommonTypes.h ../api/common_api/CommonTypes.cpp
make: Nothing to be done for 'all'.
【问题讨论】:
-
首先,在
all的配方中,您应该打印$^而不是实际变量:自动变量$^包含使认为all具有的实际先决条件。其次,您应该运行make -d并检查(非常长的)调试输出,看看为什么 make 认为不需要构建先决条件。 -
@MadScientist 使用
$^很有用。它告诉我它认为先决条件是空的。
标签: c++ makefile code-generation