Subject: Re: endian.mk proposal
To: None <tech-pkg@netbsd.org>
From: Alan Barrett <apb@cequrux.com>
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/endian.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.

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 -

--apb (Alan Barrett)