makefile - 无法覆盖特定于目标的变量

标签 makefile gnu-make

我有这样的Makefile:

print: var1=inside

print:
    @echo $(var1)

当我运行var1=outside make -e print时。我期望看到:

outside

Because of :

Variables provided on the command line (and in the environment if the ‘-e’ option is in force) will take precedence.

但我得到:

inside

输出正确吗?

最佳答案

这是预期的;我想这是否正确取决于你问的是谁。

-e 选项对 makefile 中的“全局”变量有效,但特定于目标的变量优先于全局范围的变量。

我个人认为 -e 是一个错误,根本不应该存在。但是,你知道,POSIX 等等。尽管它存在,我还是建议避免它。以令人困惑和令人惊讶的方式完全搞乱您的构建实在是太容易了。

预计到达时间 好吧,也许这不是预期的。也许这是一个错误。您从哪里获得您提供的报价?仅凭 225 页文档中的这句话很难说...一个链接或至少一个部分名称会有所帮助。

关于makefile - 无法覆盖特定于目标的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62095861/

相关文章:

c++ - 如果使用 Makefile 编译,代码可以正常工作,如果使用 XCode 编译,代码会崩溃

bash - 如何在 Makefile 中使用 eval

Makefile:防止无限模式递归

linux - Solaris 是否有 popen 问题?

ubuntu - Alfa awus036h 驱动程序安装上的 Make & Make 安装错误

c - make如何自动创建.o文件

makefile - 为什么要在先决条件之前运行配方?

macos - 如何运行 "gmake install"?

makefile - 如何强制Make始终执行配方

build-process - 用makefile和静态模式规则进行树外构建