GNU 自动工具:调试/发布目标?
我一直在寻找这个有一段时间了:我目前正在将一个中型程序转换为自动工具,来自基于 Eclipse 的方法(带有 makefile)
我总是习惯于进行“调试”构建,所有调试符号且无优化,以及“发布”版本,无调试符号和最佳优化。
现在我尝试使用自动工具以某种方式复制此内容,因此我(也许)可以执行以下操作:
./configure
make debug
其中将具有所有调试符号且没有优化,并且其中:
./configure
make
将导致“发布”版本(默认)
PS:我已经阅读过有关 --enable-debug 标志/功能的信息,但在我当前的(简单)设置中,configure
无法识别使用它
I've been looking for this for a while: I'm currently converting a medium-size program to autotools, coming from an Eclipse-based method (with makefiles)
I'm always used to having a "debug" build, with all debug symbols and no optimizations, and a "release" build, without debug symbols and best optimizations.
Now I'm trying to replicate this in some way with autotools, so I can (perhaps) do something like:
./configure
make debug
Which would have all debug symbols and no optimizations, and where:
./configure
make
Would result in the "release" version (default)
PS: I've read about the --enable-debug flag/feature, but in my current (simple) setup, using that is unrecognized by configure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ismail 的解决方案是一种常见的方法,但它存在一些严重的问题。如果用户尝试通过执行“./configure --enable-debug”来获取调试版本,则配置脚本会将 CFLAGS 设置为“-g -O2”,并且 Makefile 将使用“-g3 -O0 ... -g” -O2' 构建任何可执行文件时。在这种情况下,gcc 将使用 -O2,并且某些编译器将由于 -O 选项冲突而中止。这两种情况都不是预期的行为。
项目维护者根本不应该担心是否使用调试符号进行构建。这对于用户来说是一个问题。如果您正在构建项目并且想要进行调试构建或发布构建,则应该在配置时使用不同的选项。例如,
这将在 /dbg/bin 中安装带有“-DDEBUG”和“-g -O0”的构建(“调试构建”),并在 /usr/local/bin 中安装“release”,
您可以减少繁琐的工作使用 CONFIG_SITE 文件进行必要的键入。例如,您可以执行以下操作:
然后所有将来的“configure --prefix=/dbg”调用将自动继承 CPPFLAGS 和 CFLAGS 的设置,而无需在命令行上指定。
如果作为包维护者,您希望为用户提供一种构建“调试版本”的简单方法,那么在发行版中包含一个脚本是完全可以接受的,该脚本使用适当的参数调用配置脚本并调用
制作&& make install
,但是绝对没有必要在你的自动工具图元文件中添加这样的垃圾。它根本不属于那里。请注意,许多软件包都尝试添加--enable-debug
这完全是错误的。如果用户调用configure CFLAGS="-g -O0"
,但得到的构建应用了意外标志,那么您就会遇到错误,并且您的软件包已损坏。这是一种非常常见的经历,如果您维护一个包(当前正在考虑 tmux 和 curl),其中用户无法获得任何合理的人会称之为调用configure CFLAGS="-g -O0"
后“调试构建”,那么您的包就会损坏。使用自动工具维护包时必须始终记住的重要一点是,用户可能使用与您完全不同的工具链。用户的工具链完全有可能需要
-DMAKE_IT_A_DEBUG
或-DUSE_DEBUG
或-I/non/standard/path/to/headers
。也许它需要将-O145
或-Q
传递给编译器,或者将-debug
传递给链接器,或者......任何东西。作为维护者,您根本没有必要的信息,甚至无法使“调试构建”一词对所有用户都有意义。因此,不要尝试,因为您可能会导致某些用户无法构建该软件。ismail's solution is a common approach, but it suffers from some serious problems. If the user tries to get a debug build by doing './configure --enable-debug', the configure script will set CFLAGS to '-g -O2' and the Makefile will use '-g3 -O0 ... -g -O2' when building any executables. In that case, gcc will use -O2, and some compilers will abort because of the conflicting -O options. Either scenario is not the expected behavior.
Building with debug symbols or not is NOT something the project maintainer should worry about at all. This is an issue for the user. If you are building a project and you want to make a debug build or a release build, you should use different options at configure time. For example,
This will install a build with `-DDEBUG' and '-g -O0' (a "debug build") in /dbg/bin and a 'release' install in /usr/local/bin
You can reduce the tedium of the necessary typing by using a CONFIG_SITE file. For example, you can do:
and then all future invocations of 'configure --prefix=/dbg' will automatically inherit the settings to CPPFLAGS and CFLAGS without needing to be specified on the command line.
If, as the package maintainer, you want to provide the user with an easy way to build a "debug release", it is perfectly acceptable to include a script in the distribution that invokes the configure script with the appropriate arguments and invokes
make && make install
, but there is absolutely no need to litter your autotool metafiles with such cruft. It simply does not belong there. And be warned, many packages have made attempts to add--enable-debug
which are simply wrong. If the user invokesconfigure CFLAGS="-g -O0"
but gets a build that applies unexpected flags then you have a bug and your package is broken. This is an all too common experience, and if you maintain a package (currently thinking abouttmux
andcurl
) in which the user does not get what any reasonable person would call a "debug build" after invokingconfigure CFLAGS="-g -O0"
, then your package is broken.An important point that must always be remembered when maintaining a package with the autotools is that the user may be using a completely different tool chain than you are. It is entirely possible that the user's tool chain will require
-DMAKE_IT_A_DEBUG
or-DUSE_DEBUG
or-I/non/standard/path/to/headers
. Perhaps it will need-O145
or-Q
passed to the compiler or-debug
passed to the linker, or ... anything. As the maintainer, you simply do not have the information necessary to even make the phrase "debug build" meaningful for all users. So don't try, because you might make the software unbuildable for a certain set of users.在您的
configure.in
或configure.ac
文件中添加一个子句;现在在您的
Makefile.in
或Makefile.am
中;因此,当启用
调试
时,您可以修改{C/CXX}FLAGS
以启用调试信息。Add a clause to your
configure.in
orconfigure.ac
file;Now in your
Makefile.in
orMakefile.am
;So when
debug
is enabled you can modify your{C/CXX}FLAGS
to enable debug information.使用 autotools 创建的默认 Makefile 会生成带有调试符号的二进制文件。使用
make install-strip
生成发布目标。The default Makefile created with autotools produces binaries with debug symbos. Use
make install-strip
to produce a release target.另一个在不编辑
Makefile.in
或Makefile.am
的情况下配置CFLAGS
/CXXFLAGS
的示例。将此代码添加到您的configure.in
或configure.ac
文件中:测试一下:
Another example to configure
CFLAGS
/CXXFLAGS
without editingMakefile.in
orMakefile.am
. Add this code to yourconfigure.in
orconfigure.ac
file:Test it: