如何在不编辑makefile的情况下附加到makefile中的cxxflags?

发布于 2025-01-23 09:14:37 字数 461 浏览 3 评论 0原文

我正在为QT应用程序编写构建脚本。脚本首先调用.pro文件上的 qmake ,然后运行make cxxflags = -dswversion = xxxx

问题在于,它覆盖了Makefile中已经定义的CXXFLAG。当前,我知道解决此问题的唯一方法是编辑Makefile并更改此问题:

CXXFLAGS      = <flags>

对此:

CXXFLAGS      += <flags>

我希望有一个更简单的解决方案。有什么办法可以简单地将命令行中的cxxflag附加到而无需重写makefile的情况下?

另外,我的真正问题是在构建时间定义swversion(因为它取决于构建时间戳)。您是否知道在运行时定义此问题而不是将其传递给CXXFLAGS的更好方法?

I'm writing a build script for a Qt application. The script first calls qmake on the .pro file and then runs make CXXFLAGS=-DSWVERSION=xxxx.

The problem with this is that it overwrites the CXXFLAGS already defined in the Makefile. Currently, the only method I know to solve this problem is to edit the Makefile and change this:

CXXFLAGS      = <flags>

To this:

CXXFLAGS      += <flags>

I was hoping there would be a simpler solution. Is there any way I can simply append to CXXFLAGS from the command line WITHOUT rewriting the Makefile?

Alternatively, my real problem is defining SWVERSION at build-time (because it is dependent on the build timestamp). Do you know of a better way to define this at runtime instead of passing it to CXXFLAGS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终难愈 2025-01-30 09:14:37

您建议的更改无论如何都无法正常工作:即使将值附加到+=的情况下,命令行上设置的值也完全覆盖了Makefile中的值。您可以做到这一点,并且可以工作:

override CXXFLAGS += <flags>

但是,它的方式通常是 的方式是,makefile提供了专门保留的变量,这些变量专门为用户覆盖命令行。例如,在自动化生成的makefiles中,保留cxxflagscflags等的常见变量,请保留使用命令行或环境设置的用户,并且内部makefile标志被放入其他变量中,例如am_cflags。 编译对象的配方使用两个变量

然后, 一组类似的保留makefile变量,但您可以检查QT文档或生成的Makefile配方。

The change you suggest won't work anyway: a value set on the command line completely overrides the value set in the makefile, even if the value is appended to with +=. You could do this and it would work:

override CXXFLAGS += <flags>

However, the way it's normally done is that the makefile provides variables which are reserved specifically for users to override on the command line. For example in automake-generated makefiles, the common variables like CXXFLAGS, CFLAGS, etc. are reserved for users to set via the command line or environment, and the internal makefile flags are put into a different variable, like AM_CFLAGS. Then the recipes to compile objects uses both variable, like $(CC) $(AM_CFLAGS) $(CFLAGS) ...

I don't know anything about qt so I can't say whether they have a similar set of reserved makefile variables but you might check the qt docs, or your generated makefile recipes, to see.

末蓝 2025-01-30 09:14:37

对于将来阅读本文的任何人,我发现的解决方案是调用qmake&lt; project file&gt;定义+=“ swversion = xxxx”。希望有人能发现这个有用。

For anyone reading this in the future, the solution I found was to call qmake <project file> DEFINES+="SWVERSION=xxxx". Hope someone finds this helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文