是否可以“取消设置” Makefile 中的环境变量?
我正在使用 GNU make,并在一个项目中包含一个第三方库,该项目具有一个构建系统,如果在调用它时在环境中定义了 CFLAGS
,该构建系统就会变得疯狂。由于其他原因,我喜欢在我的环境中定义 CFLAGS
。该库的构建是从另一个 makefile 调用的,因此我说例如:
3rdparty: $(MAKE) -f Makefile.3rdparty
但我想确保当我在第 3 方 Makefile 上调用 make 时未设置 CFLAGS
。我能找到的最接近的内容是:
CFLAGS:=
但这仍然在环境中设置了 CFLAGS
,它只是一个空字符串。公寓 从做一些可怕的事情,比如说:
3rdparty: bash -c "unset CFLAGS; $(MAKE) -f Makefile.3rdparty"
有没有一种简单的方法可以从我的主 makefile 中“取消设置”CFLAGS
变量,所以当调用第三方库时它根本不存在于环境中?
I'm using GNU make, and including a 3rd party library in a project that has a build system that goes berserk if CFLAGS
is defined in the environment when it is called. I like to have CFLAGS
defined in my environment for other reasons. The library's build is being invoked from another makefile, so that I say e.g.:
3rdparty:$(MAKE) -f Makefile.3rdparty
But I would like to be sure that CFLAGS
is unset when I invoke make on the 3rd party Makefile. The nearest thing I can find is to say:
CFLAGS:=
But this still leaves CFLAGS
set in the environment, it's just an empty string. Apart
from doing something hideous like saying:
3rdparty:bash -c "unset CFLAGS; $(MAKE) -f Makefile.3rdparty"
Is there an easy way to "unset" the CFLAGS
variable from within my primary makefile, so that it isn't present at all in the environment when the third party library is invoked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下内容不适合您吗?
Doesn't the following work for you?
从版本 3.82 开始,make 有一个“undefine”指示:
As of version 3.82 make has an "undefine" directive:
如果您需要为配方中的其他命令定义变量而不希望在子制作中定义它,这可能会出现问题。另一个解决方案是使用 env - 调用 submake 并显式设置您需要在 submake 中设置的任何环境变量,例如:
This can be problematic if you need the variable to be defined for other commands in the recipe and only don't want it defined in the submake. Another solution is to use env - to invoke the submake and explicitly set any environment variables you need set in the submake, eg:
取消设置 Linux 中的环境变量。
使用:
To unset an Environment variable in linux.
Use: