[Top][All Lists]

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

Re: Specifying AM_CPPFLAGS from within

From: Matthew Walker
Subject: Re: Specifying AM_CPPFLAGS from within
Date: Fri, 03 Jun 2005 21:32:41 +1200
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

Hi Jirka,

Firstly, thank you very very much for your comments. They were well and truly more thorough than I'd ever hoped for.

Unfortunately, I don't understand much of what you have said.

Jirka Hanika wrote:

On Thu, Jun 02, 2005 at 05:50:14PM +1200, Matthew Walker wrote:

I would like to know how I should go about specifying AM_CPPFLAGS from within my

For such things, it is VERY useful to add something like this:

include $(top_srcdir)/Makefile.common

at the top of every  This basically gives you a whole new
dimension of performing package administration.  I'm almost surprised
this feature is not built into the automake to dismiss the (small) initial
work investment.  Now write your own Makefile.common and put everything
into it as you please.

I understand this suggestion (!) but I did a quick search and found there were 81 Makefiles. If I were to add that text to the top of every makefile, can you confirm that Makefile.common would have only the line:
AM_CPPFLAGS=-Wall -ggdb

From your comments below, I understand that this is not entirely portable and that there is no "easy" solution to this portability problem. Also, AM_CPPFLAGS covers both C and C++ while AM_CFLAGS covers only C. As the library is in C++, I gather AM_CPPFLAGS is the better choice.

Other people use a single  That's not bad, either.  Gives
you much faster builds, at some expense of maintainability.

As the library is not my own, I do not think this option is available to me.

I read Norman Gray and Alexandre Duret-Lutz's discussion from this mailing list on this topic ( but could not understand quite what I was supposed to do.

Put this into your


(or rather, AC_SUBST(AM_CFLAGS) as it is something of a conincidence that the
preprocessor and compilation flags tend to have the same effects.)

I just do not get this at all. Where do I *set* AM_CPPFLAGS? I tried to understand the documentation for AC_SUBST (section 7.2 of the Autoconf manual), but for the life of me, I just don't get it.

AC_SUBST subsitutes something for something else. My imagination tells me that it probably looks through all the's for the something, but really I've got no idea.

Here is the part of that I thought I could alter:

dnl Open BEAGLE optimization mode option.
 [  --enable-optimization    enable optimization mode [default=no]],
 [case $enableval in
 yes) enable_optimization=yes;;
 no) enable_optimization=no;;
 *) enable_optimization=no;; esac],
if test "$enable_optimization" = yes; then
 AC_DEFINE(NDEBUG,,[define if some debug code is disabled])
 CFLAGS=`echo $CFLAGS | sed 's/\(?*\)-g\(?*\)/\1\2/'`         <---- This is 
already in the file. I don't know what it does
CXXFLAGS=`echo $CXXFLAGS | sed 's/\(?*\)-g\(?*\)/\1\2/'` but my guess is that it would be better if it didn't set else CFLAGS or CXXFLAGS.
 CFLAGS=`echo $CFLAGS | sed 's/\(?*\)-O[[0-9]]\(?*\)/\1\2/'`  <----/
 CXXFLAGS=`echo $CXXFLAGS | sed 's/\(?*\)-O[[0-9]]\(?*\)/\1\2/'`

dnl Open BEAGLE full debug mode option.
 [  --enable-full-debug      enable full debug mode [default=no]],
 [case $enableval in
 yes) enable_full_debug=yes;;
 no) enable_full_debug=no;;
 *) enable_full_debug=no;; esac],
if test "$enable_full_debug" = yes; then
 AC_DEFINE(FULL_DEBUG,,[define if full debug mode is active])
 CPPFLAGS=-Wall                                               <---- This is my 
effort. It works but shouldn't set CPPFLAGS either.

Can you show me how I would use AC_SUBST to replace my "CPPFLAGS=-Wall"?

The library that I'm working on has an "--enable--full-debug" mode, and I would like to ensure that the compiler spits out all the warnings it can by specifing CPPFLAGS=-Wall. I have, however, read that setting CPPFLAGS is a bad thing to do because users should be able to alter that variable to their hearts content.

Not every compiler understands -Wall, but newcomers are rarely interested
in hearing that :-)

You are right that CPPFLAGS is not the right tool.

You may wish to stop reading here, and resume reading when you get
automake/autoconf run according to your present wishes :-)
as the rest is less straightforward.

Any help will be very much appreciated. I am _very_ much a newbie to autoconf/automake and I apologize sincerely if this is a stupid question.

No it's a fairly standard question.  But you'll probably learn over time that
often it is significantly better to approach these problems from a different
angle.  For example, you don't need to meddle with the autotools at all
in your example - just specify CFLAGS as every other builder would.  It is
simple and automatizable, unless you do development on a different host each
day.  The benefit?  People with different compilers will not have to
fight the non-portable -Wall which happens to break their
I found this the most interesting/easy idea.  All I need to type is:
make 'CPPFLAGS=-Wall -ggdb'
or better yet:
./configure --enable-full-debug 'CPPFLAGS=-Wall -ggdb'
and everything seems to be lovely. This is great for me, but I still think it might be beneficial, for debug mode, to somehow set all warnings to be on. As I understand it, the code you provided checks for the best warning settings for a user's compiler. (I feel this is cheeky of me seeing I'm just starting, but...) Why isn't such code already part of autoconf?

Thank you again for your fantastic assistance.



reply via email to

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