automake
[Top][All Lists]
Advanced

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

Re: Best means to override CXXFLAGS locally


From: Sander Niemeijer
Subject: Re: Best means to override CXXFLAGS locally
Date: Mon, 23 Oct 2006 13:56:45 +0200

Hi Ralf,

I have been struggling with the 'single file disable optimization issue' for a while and used to have a somewhat ugly solution up to this point. The recent fixes in automake that ensure that target_??FLAGS always overrides AM_??FLAGS make your suggestion a valid solution now.

In our project we have a single file (part of a libtool library target) that is too big to be compiled with optimization turned on.
Based on your suggestion I now use the following approach:

In configure.ac I have the following (at the bottom of the file!, just before AC_OUTPUT):
----
# here are some rules that set the value for DISOPT_FLAG for certain compilers. For gcc this is -O0
# ...
AC_SUBST(DISOPT_FLAG)

# store CFLAGS in CFG_CFLAGS and clear CFLAGS so we can override the flags (e.g. DISOPT_FLAG) in our Makefile(s)
CFG_CFLAGS=$CFLAGS
CFLAGS=
AC_SUBST(CFG_CFLAGS)
----

Then in each Makefile.am I have at the top:
---
CFG_CFLAGS = @CFG_CFLAGS@
AM_CFLAGS = $(CFG_CFLAGS)
---
and for each target_CFLAGS setting in a Makefile.am I add '$ (CFG_CFLAGS)'

The single file that has to be build with optimization turned off is now build as a libtool 'convenience library':
---
noinst_LTLIBRARIES = bigfile.la

bigfile_la_sources = bigfile.c
bigfile_la_CFLAGS = $(CFG_CFLAGS) $(DISOPT_FLAG)
---
and this convenience library is added to the original library by adding 'libbigfile.la' to the _la_LIBADD setting of the original library.

The catch with this approach is that running a 'make CFLAGS=<some other flags>' (if you ever do such a thing) will no longer replace the initial CFLAGS settings that were provided to the configure script (or set by AC_PROG_CC). It will just add them at the end (and also override the DISOPT_FLAG!). With the way I have set up the CFG_CFLAGS setting in Makefile.am you can now still replace the original CFLAGS by using 'make CFG_CFLAGS=<some other flags>'.

Best regards,
Sander

On 22-okt-2006, at 13:46, Ralf Wildenhues wrote:

Hello Akim,

* Akim Demaille wrote on Sun, Oct 22, 2006 at 01:10:02PM CEST:
What would be the cleanest means to handle this exception?

Here is what I did:

I think it's much better to do the munging in configure.ac.  Store the
CFLAGS set by the user and/or AC_PROG_CC in AM_CFLAGS, and override
CFLAGS. Depending upon whether the changed flags settings apply to only
a few, non-portability-problematic files in your project, the rest of
the configure tests should run with the flags set by the user, and you
should only override at the end, or the converse.

Much cleaner, involves much less changes.  If you have something that
works nicely and is reasonably generally useful, post a summary, or
even better, a FAQ addition to the manual.  ;-)

Cheers,
Ralf







reply via email to

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