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.