autoconf
[Top][All Lists]
Advanced

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

Re: configure sets CFLAGS or how to disable default CFLAGS='-g -O2' for


From: Chris Pickett
Subject: Re: configure sets CFLAGS or how to disable default CFLAGS='-g -O2' for gcc?
Date: Sun, 2 Apr 2006 13:06:30 -0400 (EDT)
User-agent: SquirrelMail/1.5.1 [CVS]

On Sun, April 2, 2006 7:35 am, Peter Volkov wrote:
> I'm using autoconf / automake to build my program. I'd like to set some
> default CFLAGS for my project with the following variable in my
> src/Makefile.am:
>
>
> AM_CFLAGS = $(GLIB_CFLAGS) -O3 -Wall -ffast-math

I wouldn't worry about -O3 and -ffast-math unless you are sure they will
make a difference.

> Does anybody see what is the problem here? I do not want to set CFLAGS
> environment variable forever... Any suggestions are welcome.

Save CFLAGS before you call AC_PROG_CC, and restore it after, if you don't
want "-g -O2".  Search the Autoconf list for AC_PROG_CC, there was a
fairly clean way of doing it suggested in the last couple of years.  I
know this because I recently had a similar problem: I wanted -O0 as the
default.  AC_PROG_CC has been doing this since 1996.

> Another related question is what if I want to have different CFLAGS for
> release and for debugging. How should I do this? I thought about different
> AM_CFLAGS in Makefile.am and chose between them with
> AM_CONDITIONAL, but now I don't know what to do.

I use AC_SUBST in configure.ac to define STRICT_CFLAGS, BROKEN_CFLAGS,
DEBUG_CFLAGS and OPT_CFLAGS.  Strict flags give as many gcc warnings as
possible, broken flags are those that don't play well for whatever reason
and can't be used everywhere (e.g. I link against a library with variadic
macros and so I have to put -Wno-variadic-macros in there, since I am
using -ansi -pedantic -Werror).  Then to use these in a Makefile.am I do
AM_CFLAGS += @STRICT_CFLAGS@, for example; you could also have them
associated per-program.

You can use AC_ARG_ENABLE to get debugging and optimizing configure
options, which can then be used inside Makefiles, just look at some
examples of how this macro is used.  The one thing you should avoid is
clobbering the environment CFLAGS in a configuration file, the end user
should always be able to override (at least the important bits of) what
you specified.

Cheers,
Chris





reply via email to

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