1 From 6754b208e7ec3bd1d4265db18fa4c0e7961a77bf Mon Sep 17 00:00:00 2001
2 From: Eric Le Bihan <eric.le.bihan.dev@free.fr>
3 Date: Mon, 20 Mar 2017 20:05:00 +0100
4 Subject: [PATCH] No runtime tests for endianness
6 Replace build and execution of runtime test programs for determining
7 the endianness of the target with compile time test programs.
9 This improves support for cross-compilation.
11 Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr>
13 configure | 15 +++++++++++----
14 src/sysdeps/trybigendian.c | 16 ++++++++++++++++
15 src/sysdeps/trylittleendian.c | 19 +++++++++++++++++++
16 3 files changed, 46 insertions(+), 4 deletions(-)
17 create mode 100644 src/sysdeps/trybigendian.c
18 create mode 100644 src/sysdeps/trylittleendian.c
20 diff --git a/configure b/configure
21 index 1579025..4da9c5e 100755
24 @@ -463,13 +463,20 @@ EOF
28 - echo "Checking system endianness..."
29 - $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO -o tryendianness src/sysdeps/tryendianness.c
30 - endianness=$(./tryendianness) || fail "$0: unable to determine endianness"
31 + echo "Checking system endianness..."
32 + if $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO -o trybigendian src/sysdeps/trybigendian.c 2>/dev/null; then
35 + if $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO -o trylittleendian src/sysdeps/trylittleendian.c 2>/dev/null; then
38 + fail "$0: unable to determine endianness"
41 echo "endianness: $endianness" >> $sysdeps/sysdeps
42 echo "#define ${package_macro_name}_ENDIANNESS \"$endianness\"" >> $sysdeps/sysdeps.h
43 echo " ... $endianness"
45 + rm -f trybigendian trylittleendian
47 trytypesize ushort USHORT "unsigned short"
48 trytypesize uint UINT "unsigned int"
49 diff --git a/src/sysdeps/trybigendian.c b/src/sysdeps/trybigendian.c
51 index 0000000..d857572
53 +++ b/src/sysdeps/trybigendian.c
55 +#if defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN) || \
56 + defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
57 + defined(__BIG_ENDIAN) || \
58 + defined(__ARMEB__) || \
59 + defined(__THUMBEB__) || \
60 + defined(__AARCH64EB__) || \
61 + defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
64 +#error "not big endian"
71 diff --git a/src/sysdeps/trylittleendian.c b/src/sysdeps/trylittleendian.c
73 index 0000000..68b93c1
75 +++ b/src/sysdeps/trylittleendian.c
77 +#if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
78 + defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
79 + defined(__LITTLE_ENDIAN) || \
80 + defined(__ARMEL__) || \
81 + defined(__THUMBEL__) || \
82 + defined(__AARCH64EL__) || \
83 + defined(__i386) || defined(__i386__) || \
84 + defined(__amd64) || defined(__amd64__) || \
85 + defined(__x86_64) || defined(__x86_64__) || \
86 + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
89 +#error "not little endian"