| Chris@40 | 1 dnl @synopsis MN_C_FIND_ENDIAN | 
| Chris@40 | 2 dnl | 
| Chris@40 | 3 dnl Determine endian-ness of target processor. | 
| Chris@40 | 4 dnl @version 1.1	Mar 03 2002 | 
| Chris@40 | 5 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com> | 
| Chris@40 | 6 dnl | 
| Chris@40 | 7 dnl Majority written from scratch to replace the standard autoconf macro | 
| Chris@40 | 8 dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation | 
| Chris@40 | 9 dnl of the AC_TRY_RUN macro. | 
| Chris@40 | 10 dnl | 
| Chris@40 | 11 dnl Permission to use, copy, modify, distribute, and sell this file for any | 
| Chris@40 | 12 dnl purpose is hereby granted without fee, provided that the above copyright | 
| Chris@40 | 13 dnl and this permission notice appear in all copies.  No representations are | 
| Chris@40 | 14 dnl made about the suitability of this software for any purpose.  It is | 
| Chris@40 | 15 dnl provided "as is" without express or implied warranty. | 
| Chris@40 | 16 | 
| Chris@40 | 17 dnl Find endian-ness in the following way: | 
| Chris@40 | 18 dnl    1) Look in <endian.h>. | 
| Chris@40 | 19 dnl    2) If 1) fails, look in <sys/types.h> and <sys/param.h>. | 
| Chris@40 | 20 dnl    3) If 1) and 2) fails and not cross compiling run a test program. | 
| Chris@40 | 21 dnl    4) If 1) and 2) fails and cross compiling then guess based on target. | 
| Chris@40 | 22 | 
| Chris@40 | 23 AC_DEFUN([MN_C_FIND_ENDIAN], | 
| Chris@40 | 24 [AC_CACHE_CHECK(processor byte ordering, | 
| Chris@40 | 25 	ac_cv_c_byte_order, | 
| Chris@40 | 26 | 
| Chris@40 | 27 # Initialize to unknown | 
| Chris@40 | 28 ac_cv_c_byte_order=unknown | 
| Chris@40 | 29 | 
| Chris@40 | 30 if test x$ac_cv_header_endian_h = xyes ; then | 
| Chris@40 | 31 | 
| Chris@40 | 32 	# First try <endian.h> which should set BYTE_ORDER. | 
| Chris@40 | 33 | 
| Chris@40 | 34 	[AC_TRY_LINK([ | 
| Chris@40 | 35 		#include <endian.h> | 
| Chris@40 | 36 		#if BYTE_ORDER != LITTLE_ENDIAN | 
| Chris@40 | 37 			not big endian | 
| Chris@40 | 38 		#endif | 
| Chris@40 | 39 		], return 0 ;, | 
| Chris@40 | 40 			ac_cv_c_byte_order=little | 
| Chris@40 | 41 		)] | 
| Chris@40 | 42 | 
| Chris@40 | 43 	[AC_TRY_LINK([ | 
| Chris@40 | 44 		#include <endian.h> | 
| Chris@40 | 45 		#if BYTE_ORDER != BIG_ENDIAN | 
| Chris@40 | 46 			not big endian | 
| Chris@40 | 47 		#endif | 
| Chris@40 | 48 		], return 0 ;, | 
| Chris@40 | 49 			ac_cv_c_byte_order=big | 
| Chris@40 | 50 		)] | 
| Chris@40 | 51 | 
| Chris@40 | 52 	fi | 
| Chris@40 | 53 | 
| Chris@40 | 54 if test $ac_cv_c_byte_order = unknown ; then | 
| Chris@40 | 55 | 
| Chris@40 | 56 	[AC_TRY_LINK([ | 
| Chris@40 | 57 		#include <sys/types.h> | 
| Chris@40 | 58 		#include <sys/param.h> | 
| Chris@40 | 59 		#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN | 
| Chris@40 | 60 			bogus endian macros | 
| Chris@40 | 61 		#endif | 
| Chris@40 | 62 		], return 0 ;, | 
| Chris@40 | 63 | 
| Chris@40 | 64 		[AC_TRY_LINK([ | 
| Chris@40 | 65 			#include <sys/types.h> | 
| Chris@40 | 66 			#include <sys/param.h> | 
| Chris@40 | 67 			#if BYTE_ORDER != LITTLE_ENDIAN | 
| Chris@40 | 68 				not big endian | 
| Chris@40 | 69 			#endif | 
| Chris@40 | 70 			], return 0 ;, | 
| Chris@40 | 71 				ac_cv_c_byte_order=little | 
| Chris@40 | 72 			)] | 
| Chris@40 | 73 | 
| Chris@40 | 74 		[AC_TRY_LINK([ | 
| Chris@40 | 75 			#include <sys/types.h> | 
| Chris@40 | 76 			#include <sys/param.h> | 
| Chris@40 | 77 			#if BYTE_ORDER != LITTLE_ENDIAN | 
| Chris@40 | 78 				not big endian | 
| Chris@40 | 79 			#endif | 
| Chris@40 | 80 			], return 0 ;, | 
| Chris@40 | 81 				ac_cv_c_byte_order=little | 
| Chris@40 | 82 			)] | 
| Chris@40 | 83 | 
| Chris@40 | 84 		)] | 
| Chris@40 | 85 | 
| Chris@40 | 86  	fi | 
| Chris@40 | 87 | 
| Chris@40 | 88 if test $ac_cv_c_byte_order = unknown ; then | 
| Chris@40 | 89 	if test $cross_compiling = yes ; then | 
| Chris@40 | 90 		# This is the last resort. Try to guess the target processor endian-ness | 
| Chris@40 | 91 		# by looking at the target CPU type. | 
| Chris@40 | 92 		[ | 
| Chris@40 | 93 		case "$target_cpu" in | 
| Chris@40 | 94 			alpha* | i?86* | mipsel* | ia64*) | 
| Chris@40 | 95 				ac_cv_c_byte_order=little | 
| Chris@40 | 96 				;; | 
| Chris@40 | 97 | 
| Chris@40 | 98 			m68* | mips* | powerpc* | hppa* | sparc*) | 
| Chris@40 | 99 				ac_cv_c_byte_order=big | 
| Chris@40 | 100 				;; | 
| Chris@40 | 101 | 
| Chris@40 | 102 			esac | 
| Chris@40 | 103 		] | 
| Chris@40 | 104 	else | 
| Chris@40 | 105 		AC_TRY_RUN( | 
| Chris@40 | 106 		[[ | 
| Chris@40 | 107 		int main (void) | 
| Chris@40 | 108 		{	/* Are we little or big endian?  From Harbison&Steele.  */ | 
| Chris@40 | 109 			union | 
| Chris@40 | 110 			{	long l ; | 
| Chris@40 | 111 				char c [sizeof (long)] ; | 
| Chris@40 | 112 			} u ; | 
| Chris@40 | 113 			u.l = 1 ; | 
| Chris@40 | 114 			return (u.c [sizeof (long) - 1] == 1); | 
| Chris@40 | 115 			} | 
| Chris@40 | 116 			]], , ac_cv_c_byte_order=big, | 
| Chris@40 | 117 			) | 
| Chris@40 | 118 | 
| Chris@40 | 119 		AC_TRY_RUN( | 
| Chris@40 | 120 		[[int main (void) | 
| Chris@40 | 121 		{	/* Are we little or big endian?  From Harbison&Steele.  */ | 
| Chris@40 | 122 			union | 
| Chris@40 | 123 			{	long l ; | 
| Chris@40 | 124 				char c [sizeof (long)] ; | 
| Chris@40 | 125 			} u ; | 
| Chris@40 | 126 			u.l = 1 ; | 
| Chris@40 | 127 			return (u.c [0] == 1); | 
| Chris@40 | 128 			}]], , ac_cv_c_byte_order=little, | 
| Chris@40 | 129 			) | 
| Chris@40 | 130 		fi | 
| Chris@40 | 131 	fi | 
| Chris@40 | 132 | 
| Chris@40 | 133 ) | 
| Chris@40 | 134 | 
| Chris@40 | 135 if test $ac_cv_c_byte_order = big ; then | 
| Chris@40 | 136 	ac_cv_c_big_endian=1 | 
| Chris@40 | 137 	ac_cv_c_little_endian=0 | 
| Chris@40 | 138 elif test $ac_cv_c_byte_order = little ; then | 
| Chris@40 | 139 	ac_cv_c_big_endian=0 | 
| Chris@40 | 140 	ac_cv_c_little_endian=1 | 
| Chris@40 | 141 else | 
| Chris@40 | 142 	ac_cv_c_big_endian=0 | 
| Chris@40 | 143 	ac_cv_c_little_endian=0 | 
| Chris@40 | 144 | 
| Chris@40 | 145 	AC_MSG_WARN([[*****************************************************************]]) | 
| Chris@40 | 146 	AC_MSG_WARN([[*** Not able to determine endian-ness of target processor.       ]]) | 
| Chris@40 | 147 	AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in  ]]) | 
| Chris@40 | 148 	AC_MSG_WARN([[*** src/config.h may need to be hand editied.                    ]]) | 
| Chris@40 | 149 	AC_MSG_WARN([[*****************************************************************]]) | 
| Chris@40 | 150 	fi | 
| Chris@40 | 151 | 
| Chris@40 | 152 ] | 
| Chris@40 | 153 )# MN_C_FIND_ENDIAN | 
| Chris@40 | 154 | 
| Chris@40 | 155 |