Gnu autotools: debug / release targets?

I have been looking for this for a while: I am currently converting a medium-sized program to autotools based on an eclipse-based method (with make files)

I always use the "debug" assembly with all debugging symbols and without optimization, as well as with the "release" assembly without debug symbols and better optimization.

Now I'm trying to reproduce this using autotools, so I can (possibly) do something like:

./configure make debug 

which would have all the debugging symbols and no optimizations, and where:

 ./configure make 

The result will be the release version (default)

PS: I read about the / enable -debug flag / feature flag, but in my current (simple) setup, using this, not recognized configure

+51
c ++ autotools autoconf automake
Dec 29 '10 at 11:37
source share
4 answers

Add the sentence to the configure.in or configure.ac file;

 AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable debugging, default: no]), [case "${enableval}" in yes) debug=true ;; no) debug=false ;; *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; esac], [debug=false]) AM_CONDITIONAL(DEBUG, test x"$debug" = x"true") 

Now in Makefile.in or Makefile.am ;

 if DEBUG AM_CFLAGS = -g3 -O0 AM_CXXFLAGS = -g3 -O0 else AM_CFLAGS = -O2 AM_CXXFLAGS = -O2 endif 

So, when debug on, you can modify your {C/CXX}FLAGS to include debugging information.

+14
Dec 29 2018-10-29
source share

An Ismaili solution is a general approach, but it suffers from some serious problems. If the user tries to get the debug build by running "./configure --enable-debug", the configure script will set CFLAGS to '-g -O2' and the Makefile will use '-g3 -O0 ... -g -O2' when creating any executable files. In this case, gcc will use -O2, and some compilers will be interrupted due to conflicting -O options. Any scenario is not expected behavior.

Creating with debugging symbols or not is not something the project developer should take care of. This is a problem for the user. If you have a project and want to create a debug build or release build, you must use different parameters during setup. For example,

 $ mkdir debug
 $ mkdir release
 $ cd debug && / path / to / configure --prefix = / dbg \
    CPPFLAGS = -DDEBUG CXXFLAGS = "- g -O0" && make && make install
 $ cd ../release && / path / to / configure CPPFLAGS = -DNDEBUG && make && make install

This will install the debug build in / dbg / bin and set the "release" to / usr / local / bin

In addition, you can significantly reduce the boredom of your typing by using the CONFIG_SITE file. For example, you can:

 echo 'CPPFLAGS = -DDEBUG CFLAGS = "- g -O0"' >> /dbg/share/config.site

and then all future calls to 'configure -prefix = / dbg' will automatically inherit the settings for CPPFLAGS and CFLAGS without the need to specify on the command line.

If you want to provide the user with an easy way to create a "debug version", it is quite acceptable to include a script in the distribution package that calls configure script using the appropriate arguments and calls make && make install , but there is absolutely no need to mutate your metafiles with autotrack so cool. He just does not belong. And be careful, many packages have tried adding --enable-debug , which are just wrong. If the user calls configure CFLAGS="-g -O0" but receives an assembly that uses unexpected flags, then you have an error and your package is corrupted. This is too common experience, and if you support a package (currently thinking of tmux and curl ) in which the user does not get what any reasonable person would call a "debug build" after calling configure CFLAGS="-g -O0" , then your package is broken.

An important point to always remember when saving a package using autotools is that the user can use a completely different tool chain than you. It is possible that a custom tool chain will require -DMAKE_IT_A_DEBUG or -DUSE_DEBUG or -I/usr/banana-split/debug/build/with/georges/headers . Perhaps he will need -O145 or -Q passed to the compiler or -debug passed to the linker, or ... whatever. As an maintainer, you simply don’t have the information necessary even for the phrase “debug build” to be meaningful to all users. Therefore, do not try, because you can make the software non-strict for a specific set of users.

+110
Jan 13 2018-11-11T00:
source share

The default Makefile created with autotools creates binary files with debugging symbols. Use make install-strip to create a release target.

+4
Jan 04 '12 at 12:13
source share

Another example of setting CFLAGS / CXXFLAGS without editing Makefile.in or Makefile.am . Add this code to configure.in or configure.ac :

 test -z "$SED" && SED=sed AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [whether to include debug symbols (default is no)])], [enable_debug=$enableval], [enable_debug=no] ) if test "x$enable_debug" = xyes; then dnl Remove all optimization flags from CFLAGS changequote({,}) CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'` CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9s]*//g'` CFLAGS=`echo "$CFLAGS" | $SED -e 's/-g[0-9]*//g'` CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-g[0-9]*//g'` changequote([,]) CFLAGS="$CFLAGS -g -O0" CXXFLAGS="$CXXFLAGS -g -O0" fi echo "CFLAGS=$CFLAGS" 

Check this:

 $ ./configure --enable-debug | grep CFLAGS 
0
Nov 14 '17 at 7:17
source share



All Articles