diff options
author | jlam <jlam@pkgsrc.org> | 2002-04-22 02:30:51 +0000 |
---|---|---|
committer | jlam <jlam@pkgsrc.org> | 2002-04-22 02:30:51 +0000 |
commit | ff13344585b79284e6e57567174d5f61dbf5d62d (patch) | |
tree | 2f34d9b2b7b112b3695f8abf4f3d97f755b266c4 /mk/endian.mk | |
parent | 9fd26d8b885908b4e7b315d940f99c3613e12317 (diff) | |
download | pkgsrc-ff13344585b79284e6e57567174d5f61dbf5d62d.tar.gz |
Makefile fragment to determine the endianness of the platform by checking
header files. It defines MACHINE_ENDIAN which is one of three values:
little, big, or unknown.
This file is used in package Makefiles as follows:
.include "../../mk/endian.mk"
.if ${MACHINE_ENDIAN} == "big"
# ...big endian stuff...
.elif ${MACHINE_ENDIAN} == "little"
# ...little endian stuff...
.else
BROKEN= "Unknown endianness"
.endif
Diffstat (limited to 'mk/endian.mk')
-rw-r--r-- | mk/endian.mk | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/mk/endian.mk b/mk/endian.mk new file mode 100644 index 00000000000..61113dee7d5 --- /dev/null +++ b/mk/endian.mk @@ -0,0 +1,51 @@ +# $NetBSD: endian.mk,v 1.1 2002/04/22 02:30:51 jlam Exp $ +# +# Determine the endianness of the platform by checking header files. +# +# This file is used as follows: +# +# .include "../../mk/endian.mk" +# +# .if ${MACHINE_ENDIAN} == "big" +# # ...big endian stuff... +# .elif ${MACHINE_ENDIAN} == "little" +# # ...little endian stuff... +# .else +# BROKEN= "Unknown endianness" +# .endif + +.include "../../mk/bsd.prefs.mk" +.if !defined(MACHINE_ENDIAN) +_ENDIAN_H_FILES= /usr/include/endian.h # Linux +_ENDIAN_H_FILES+= /usr/include/sys/endian.h # NetBSD=>1.5 +_ENDIAN_H_FILES+= /usr/include/machine/endian.h # NetBSD<1.5 +_ENDIAN_H_FILES+= /usr/include/sys/byteorder.h # Solaris +_ENDIAN_H_FILES+= /dev/null +. for FILE in ${_ENDIAN_H_FILES} +. if !defined(_ENDIAN_H) +. if exists(${FILE}) +_ENDIAN_H?= ${FILE:S/\/usr\/include\///} +. endif +. endif +. endfor +MACHINE_ENDIAN!= \ + byte_order=` \ + ( \ + ${ECHO} "\#include <${_ENDIAN_H}>"; \ + ${ECHO} "\#ifndef BYTE_ORDER"; \ + ${ECHO} "\#ifdef _BIG_ENDIAN"; \ + ${ECHO} "\#define BYTE_ORDER 4321"; \ + ${ECHO} "\#else"; \ + ${ECHO} "\#define BYTE_ORDER 1234"; \ + ${ECHO} "\#endif"; \ + ${ECHO} "\#endif"; \ + ${ECHO} "BYTE_ORDER"; \ + ) | ${CC} -E - | ${GREP} "^\\(1234\\|4321\\)" \ + `; \ + case `${ECHO} $${byte_order}` in \ + 1234) ${ECHO} little ;; \ + 4321) ${ECHO} big ;; \ + *) ${ECHO} unknown ;; \ + esac +MAKEFLAGS+= MACHINE_ENDIAN="${MACHINE_ENDIAN}" +.endif |