[libdispatch-dev] autoconf HAVE macro conventions

Ronnie Misra rgmisra at apple.com
Fri Oct 30 13:08:05 PDT 2009


On Oct 30, 2009, at 12:26 PM, Paolo Bonzini wrote:

> On 10/30/2009 08:24 PM, Kevin Van Vechten wrote:
>> I'm not very familiar with autoconf conventions and was wondering why
>> some config.h values are merely defined and some are explicitly
>> defined to 1.
>
> That's a bad decision in configure.ac usually.  Just look for  
> occurrences of AC_DEFINE([FOO],,[Comment]) and add a 1 between the  
> two commas.
>
>> Is there a strong convention to do #ifdef HAVE_FOO instead of #if
>> HAVE_FOO when testing for configure features?  For various reasons,
>> the ability to define a macro to 0 or 1 would be useful for the Mac
>> OS X version of config.h — it would let us define certain features in
>> terms of other features without as much conditional logic.
>
> ... that said, why can't config.h be generated for Mac OS X by  
> running configure every time a change to the autoconf source is  
> checked in? There should be no need for conditional logic.

I think this is the problem Kevin is alluding to:

Mac OS X projects usually use the same set of source files for all of  
the multiple machine architectures that the project is be built for.  
This can cause problems when a configure-time check doesn't match the  
target architecture. An example that has come up in the past is  
configure-time detection of endianness. If configure was run on a  
PowerPC machine, the generated config.h would indicate that the  
machine was big-endian:

	/* Define if the machine architecture is big-endian. */
	#define WORDS_BIGENDIAN 1

whereas if it was run on in an Intel machine, the generated config.h  
would indicate that the machine was little-endian:

	/* Define if the machine architecture is big-endian. */
	/* #undef WORDS_BIGENDIAN */

One possible solution that has been employed in the past is to hand- 
modify the checked in pre-created config.h to use the (Apple-specific)  
compiler built-in:

	/* Define if the machine architecture is big-endian. */
	#define WORDS_BIGENDIAN __BIG_ENDIAN__

If the code that uses this #define is written using "#if  
WORDS_BIGENDIAN", it will work correctly, but if it instead uses  
"#ifdef WORDS_BIGENDIAN", it will incorrectly treat all architectures  
as big-endian.

Ronnie


More information about the libdispatch-dev mailing list