autoconf
[Top][All Lists]
Advanced

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

Re: Why conditionally include config.h?


From: Russ Allbery
Subject: Re: Why conditionally include config.h?
Date: Thu, 13 Sep 2012 17:17:31 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Marko Lindqvist <address@hidden> writes:
> On 14 September 2012 02:43, Eric Blake <address@hidden> wrote:
>> On 09/13/2012 05:22 PM, Kip Warner wrote:

>>> Why do many autoconfiscated projects bracket inclusion of the
>>> generated config.h with #if HAVE_CONFIG_H / #endif.
>>
>> Bad copy-and-paste habits.

>  I've seen some packages where same sources are used with multiple build
> systems (typically autotools in more unixy systems and visual studio
> project files on Windows) and it's actually needed to weed out
> "config.h" include when building with system that does not provide it.
> But more often "#ifdef HAVE_CONFIG_H" is just idiom copied from some
> other project.

I believe the #ifdef wrapper used to be recommended by the Autoconf manual
way back, many moons ago (2.13 days at the latest), because it was how the
transition from defining things via -D on the command line to using a
header was handled.  It goes along with the definition of @DEFS@, which
previously (and by previously I mean a long time ago) used to contain all
the results of configure as -D flags to the compiler, but which was
replaced by just "-DHAVE_CONFIG_H" if you used the AC_CONFIG_HEADERS (or
its earlier versions) macro.

So, in other words, you could transition your package that was assuming -D
flags on the compiler command line to using a config.h header by adding
that #ifdef code to the source files, and then it would work with either
Autoconf method: either a config.h file or direct -D flags on the compiler
command line.

I suspect the above is what's happening when you see this in really old
projects, and in newer projects it's copy and paste from older projects.

-- 
Russ Allbery (address@hidden)             <http://www.eyrie.org/~eagle/>



reply via email to

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