Try to use (Apple) gcc's __BIG_ENDIAN__ and __LITTLE_ENDIAN__ macros if possible. HEAD
authorTimo Sirainen <tss@iki.fi>
Fri Dec 19 08:49:51 2008 +0200 (2008-12-19)
branchHEAD
changeset 8057fdcb5fc6f2d9
parent 8056 a47ddd8a67a4
child 8058 92921985e4f5
Try to use (Apple) gcc's __BIG_ENDIAN__ and __LITTLE_ENDIAN__ macros if possible.
Based on a patch by Apple.
configure.in
src/lib-index/mail-index-map.c
src/lib-index/mail-index.c
src/lib/sha1.c
     1.1 --- a/configure.in	Fri Dec 19 06:23:18 2008 +0200
     1.2 +++ b/configure.in	Fri Dec 19 08:49:51 2008 +0200
     1.3 @@ -2159,20 +2159,24 @@
     1.4  AC_SUBST(dict_drivers)
     1.5  
     1.6  dnl **
     1.7 -dnl ** Index file compatibility flags
     1.8 +dnl ** Endianess
     1.9  dnl **
    1.10  
    1.11 -dnl * currently just checking for endianess
    1.12 -
    1.13 -AC_C_BIGENDIAN
    1.14 -
    1.15 -if test $ac_cv_c_bigendian = yes; then
    1.16 -	flags=0
    1.17 -else
    1.18 -	flags=1
    1.19 -fi
    1.20 -
    1.21 -AC_DEFINE_UNQUOTED(MAIL_INDEX_COMPAT_FLAGS, $flags, Index file compatibility flags)
    1.22 +dnl At least Apple's gcc supports __BIG_ENDIAN__ and __LITTLE_ENDIAN__
    1.23 +dnl defines. Use them if possible to allow cross-compiling.
    1.24 +AC_MSG_CHECKING([if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined])
    1.25 +AC_TRY_COMPILE([
    1.26 +  #if !(__BIG_ENDIAN__ || __LITTLE_ENDIAN__)
    1.27 +  #error nope
    1.28 +  #endif
    1.29 +], [
    1.30 +], [
    1.31 +  AC_DEFINE(WORDS_BIGENDIAN, __BIG_ENDIAN__, Define if your CPU is big endian)
    1.32 +  AC_MSG_RESULT(yes)
    1.33 +], [
    1.34 +  AC_MSG_RESULT(no)
    1.35 +  AC_C_BIGENDIAN
    1.36 +])
    1.37  
    1.38  dnl **
    1.39  dnl ** IPv6 support
     2.1 --- a/src/lib-index/mail-index-map.c	Fri Dec 19 06:23:18 2008 +0200
     2.2 +++ b/src/lib-index/mail-index-map.c	Fri Dec 19 08:49:51 2008 +0200
     2.3 @@ -367,7 +367,7 @@
     2.4  {
     2.5          enum mail_index_header_compat_flags compat_flags = 0;
     2.6  
     2.7 -#ifndef WORDS_BIGENDIAN
     2.8 +#if !WORDS_BIGENDIAN
     2.9  	compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
    2.10  #endif
    2.11  
    2.12 @@ -784,7 +784,7 @@
    2.13  	hdr->header_size = sizeof(*hdr);
    2.14  	hdr->record_size = sizeof(struct mail_index_record);
    2.15  
    2.16 -#ifndef WORDS_BIGENDIAN
    2.17 +#if !WORDS_BIGENDIAN
    2.18  	hdr->compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
    2.19  #endif
    2.20  
     3.1 --- a/src/lib-index/mail-index.c	Fri Dec 19 06:23:18 2008 +0200
     3.2 +++ b/src/lib-index/mail-index.c	Fri Dec 19 08:49:51 2008 +0200
     3.3 @@ -633,7 +633,7 @@
     3.4          index->index_lock_timeout = FALSE;
     3.5  }
     3.6  
     3.7 -#ifdef WORDS_BIGENDIAN
     3.8 +#if WORDS_BIGENDIAN
     3.9  /* FIXME: Unfortunately these functions were originally written to use
    3.10     endian-specific code and we can't avoid that without breaking backwards
    3.11     compatibility. When we do break it, just select one of these. */
     4.1 --- a/src/lib/sha1.c	Fri Dec 19 06:23:18 2008 +0200
     4.2 +++ b/src/lib/sha1.c	Fri Dec 19 08:49:51 2008 +0200
     4.3 @@ -80,7 +80,7 @@
     4.4  	size_t t, s;
     4.5  	uint32_t	tmp;
     4.6  
     4.7 -#ifndef WORDS_BIGENDIAN
     4.8 +#if !WORDS_BIGENDIAN
     4.9  	struct sha1_ctxt tctxt;
    4.10  	memmove(&tctxt.m.b8[0], &ctxt->m.b8[0], 64);
    4.11  	ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
    4.12 @@ -189,7 +189,7 @@
    4.13  	memset(&ctxt->m.b8[padstart], 0, padlen - 8);
    4.14  	COUNT += (padlen - 8);
    4.15  	COUNT %= 64;
    4.16 -#ifdef WORDS_BIGENDIAN
    4.17 +#if WORDS_BIGENDIAN
    4.18  	PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
    4.19  	PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
    4.20  	PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
    4.21 @@ -235,7 +235,7 @@
    4.22  
    4.23  	digest = (uint8_t *)digest0;
    4.24  	sha1_pad(ctxt);
    4.25 -#ifdef WORDS_BIGENDIAN
    4.26 +#if WORDS_BIGENDIAN
    4.27  	memmove(digest, &ctxt->h.b8[0], 20);
    4.28  #else
    4.29  	digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];