Subject: Re: endian.mk proposal
To: Alan Barrett <apb@cequrux.com>
From: Johnny C. Lam <jlam@netbsd.org>
List: tech-pkg
Date: 04/15/2002 06:46:57
On Mon, Apr 15, 2002 at 09:54:02AM +0200, Alan Barrett wrote:
> 
> I'd prefer it to have at least three output states: big/little/unknown.
> At present, error cases are reported as "little".  You could do all the
> work in the C preprocessor, and avoid the grep.

I agree with having a tri-state MACHINE_ENDIAN.  I'll make some changes
to my endian.mk.  It'll be slower, but these are all one-time costs, and
will only be used by packages that actually require the endianness of the
platform, so this will be fine.

> 
> MACHINE_ENDIAN!=							\
> 	(								\
> 		${ECHO} "\#include <${_ENDIAN_H}>";			\
> 		${ECHO} "\#if defined(BYTE_ORDER) && (BYTE_ORDER==4321)";\
> 		${ECHO} "big";						\
> 		${ECHO} "\#elif defined(BYTE_ORDER) && (BYTE_ORDER==1234)";\
> 		${ECHO} "little";					\
> 		${ECHO} "\#elif defined(_BIG_ENDIAN)";			\
> 		${ECHO} "big";						\
> 		${ECHO} "\#elif defined(_LITTLE_ENDIAN)";		\
> 		${ECHO} "little";					\
> 		${ECHO} "\#else";					\
> 		${ECHO} "unknown";					\
> 		${ECHO} "\#endif";					\
> 	) | ${CC} -E -

Have you tried this?  The preprocessor outputs a lot of garbage along with
what we're looking for.  I don't know how to suppress this extra output,
which is why I decided on grepping for a string that isn't likely to appear
in the preprocessor output by accident.

	Cheers,

	-- Johnny Lam <jlam@netbsd.org>