Why conditionally include config.h?

2012-09-13 Thread Kip Warner
Hey list,

Why do many autoconfiscated projects bracket inclusion of the generated
config.h with #if HAVE_CONFIG_H / #endif. Assuming the build
environment was configured, why shouldn't the source just always
unconditionally include config.h? I mean if it isn't there, typically
that means the user didn't configure first which ought to be an error
anyways, no?

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf


Re: Why conditionally include config.h?

2012-09-13 Thread Eric Blake
On 09/13/2012 05:22 PM, Kip Warner wrote:
 Hey list,
 
 Why do many autoconfiscated projects bracket inclusion of the generated
 config.h with #if HAVE_CONFIG_H / #endif.

Bad copy-and-paste habits.  Probably because historically, libtool
prided itself on being usable even without autoconf, and therefore
libtool headers have to use HAVE_CONFIG_H.  Projects that use libtool
would then copy libtool's habits, even when they use autoconf, and the
practice has spread to projects that don't even use libtool.

 Assuming the build
 environment was configured, why shouldn't the source just always
 unconditionally include config.h? I mean if it isn't there, typically
 that means the user didn't configure first which ought to be an error
 anyways, no?

Yep, you are exactly right, which is why gnulib doesn't use
HAVE_CONFIG_H, and even provides a syntax check rule that you can copy
into your project to also avoid it yourself.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
___
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf


Re: Why conditionally include config.h?

2012-09-13 Thread Marko Lindqvist
On 14 September 2012 02:43, Eric Blake ebl...@redhat.com wrote:
 On 09/13/2012 05:22 PM, Kip Warner wrote:
 Hey list,

 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.

 For example, in our freeciv project, this would need cleanup. It used
to be possible to build without autotools and fc_config.h (for systems
lacking autotools support those ancient times), and thus #ifdefs are
used. However, if one would try to build without HAVE_CONFIG_H defined
today, it would go horribly wrong.


 - ML

___
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf


Re: Why conditionally include config.h?

2012-09-13 Thread Bob Friesenhahn

On Thu, 13 Sep 2012, Kip Warner wrote:



Why do many autoconfiscated projects bracket inclusion of the generated
config.h with #if HAVE_CONFIG_H / #endif. Assuming the build
environment was configured, why shouldn't the source just always
unconditionally include config.h? I mean if it isn't there, typically
that means the user didn't configure first which ought to be an error
anyways, no?


Since subsequent responses are not yet adequate ...

It is not necessary to have a configuration header when Autoconf is 
used.   If a configuration header is not used, then all definitions 
appear on the compiler command line and HAVE_CONFIG_H is not defined.


However, it is a bug for #if HAVE_CONFIG_H to be used in any installed 
header file because it might apply to any package, including some 
other package.


Bob
--
Bob Friesenhahn
bfrie...@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,http://www.GraphicsMagick.org/

___
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf


Re: Why conditionally include config.h?

2012-09-13 Thread Russ Allbery
Marko Lindqvist cazf...@gmail.com writes:
 On 14 September 2012 02:43, Eric Blake ebl...@redhat.com 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 (r...@stanford.edu) http://www.eyrie.org/~eagle/

___
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf