automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alternative compiling for debug/optimized code?


From: Andrew Suffield
Subject: Re: Alternative compiling for debug/optimized code?
Date: Fri, 9 Dec 2005 01:48:39 +0000
User-agent: Mutt/1.5.11

On Thu, Dec 08, 2005 at 01:37:26PM +0100, Ralf Wildenhues wrote:
> > but most of th time I don't need debug code, so I want to disable that
> > -g - option.
> 
> So standard way with Automake-using projects would be: you make a debug
> build tree and a normal (optimized) build tree:
> 
> mkdir build-debug build
> cd build-debug
> ../source-tree/configure CFLAGS=-g
> make
> 
> cd ../build
> ../source-tree/configure CFLAGS=-O3
> make

This is really an autoconf thing, but I go one step further and use
the construction at the end of this mail. I have similar (although
less complex) constructs for stuff like -g, -pg, etc. It detects the
default flags to use based on the presence of a file 'development' in
the source tree. This file is present in the revision-controlled tree
where development work happens (and therefore you do a lot of
debugging), but which automake does not put into the 'make dist'
tarballs, so end-users get the optimised version instead.

That said, I almost always put -g in there by default regardless,
because with the exception of huge projects or complex C++ features,
it doesn't cost anything noticable and occasionally it's useful. I'm
assuming here that for production use, the binaries will get packaged
and stripped at that point - which means you've installed the files
stripped, but your build tree has the debugging symbols if you need
them later (and which can be used to decode any core dumps produced by
the stripped binaries).

AC_MSG_CHECKING(for suitable optimisation flags)
AC_ARG_ENABLE(optimise,
[  --enable-optimise       Enable optimisation ],
[if test "$enableval" = "yes"
then
        if test "$GCC" = "yes"
        then
                optimise='-Os '
        else
                optimise='-O '
        fi
else
        if test "$GCC" = "yes"
        then
                optimise='-O0 '
        else
                optimise=''
        fi
fi],[
        if test -f "$srcdir/development"
        then
                if test "$GCC" = "yes"
                then
                        optimise='-O0 '
                else
                        optimise=''
                fi
        else
                if test "$GCC" = "yes"
                then
                        optimise='-O2 '
                else
                        optimise='-O '
                fi
        fi
])
if test -z "${optimise}"
then
        AC_MSG_RESULT(none)
else
        AC_MSG_RESULT(${optimise})
fi

Yes, I'm aware this has duplicated code and should be refactored.

-- 
  .''`.  ** Debian GNU/Linux ** | Andrew Suffield
 : :' :  http://www.debian.org/ |
 `. `'                          |
   `-             -><-          |

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]