Subject: Re: proposal
To: None <>
From: Alan Barrett <>
List: tech-pkg
Date: 04/15/2002 09:54:02
On Fri, 12 Apr 2002, Johnny Lam wrote:
> I'd like to add the following file as /usr/pkgsrc/mk/ to assist
> in the creation of some packages that need to determine the endianness of
> the CPU.

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.

	(								\
		${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 -

--apb (Alan Barrett)