automake
[Top][All Lists]
Advanced

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

Re: Specifying AM_CPPFLAGS from within configure.ac


From: Jirka Hanika
Subject: Re: Specifying AM_CPPFLAGS from within configure.ac
Date: Fri, 3 Jun 2005 15:41:09 +0200
User-agent: Mutt/1.4.1i

Hi Matthew, Stepan, Ralf,

first let me thank Ralf and Stepan, for your comments about the code
snippet, I've learned a lot.  You are both right.

For example I'll try to upgrade the "unused variable" warning avoidance
code to something like

if (((int)argv) * ((int)argv) < 0 || argc < 0) printf("");

and accept the fact that bannered compilers will simply select no option.
Hope the libtool experience doesn't suggest that the newest gcc will see
through the trick, too.


Now at least briefly:

> 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

Yes.  One line.  In my projects it simply turned out that Makefile.common
changes more often than all Makefile.am's taken together.  It may or may
not in your case, too.

Besides, you can probably do that change automatically, using
find and sed, so 81 is not that bad.  A few minutes.

> From your comments below, I understand that this is not entirely 
> portable and that there is no "easy" solution to this portability 
> problem.  

Except for specifying the flags "from outside" (not manually) at
configure time, yes.

> 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.

I'd choose AM_CXXFLAGS in that case.  That's the one for C++.  CPPFLAGS
is for preprocessor only (-D, -I ...), although it will mostly work the
same.

> >Other people use a single Makefile.am.  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 see.

> 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.

You set it in Makefile.am, or in a file included from there.

The AC_SUBST only says that you want this option propagate down to the
Makefile, as a make variable.  The Makefile will use it in any case (empty
or not), because its reference has been generated by automake/configure
as a part of compilation commands.

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

Almost.  Looks for @AM_CXXFLAGS@ in every Makefile.in and replaces it
with the configure variable of the same name.  But its configure,
not automake, who does this.  Automake only copies the assignment to
Makefile.in.

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

No, it is a good exercise for you, but I'll tell you a simpler
alternative to start with :-)

AC_SUBST also has a two-argument form.  The second argument is the value
you want to assign to the variable.  In a trivial case, like this:

AC_SUBST(AM_CXXFLAGS, [-Wall])

> >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
> >compilation.
> > 
> >
> 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.

Yes, something along these lines.

>   This is great for me, but I still 
> think it might be beneficial, for debug mode, to somehow set all 
> warnings to be on.

Yes.  May happen.

>  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?

As Ralf just taught me, it is probably very hard to get right for every
possible use case.  My needs were pretty modest at the time I needed
this and I snatched the code from somewhere and adapted it without much
scrutiny.  Maybe you can ask at the autoconf list instead of here.

Jirka





reply via email to

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