From a70007dbdfa4a6b85bac31f8de139b1b02f0ffc3 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 12 Feb 2020 23:42:50 +0800 Subject: [PATCH] [build] auto detect big endian (#4551) --- configure.ac | 2 ++ src/core/common/encoding.hpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index d9f51b89d..9122f469c 100644 --- a/configure.ac +++ b/configure.ac @@ -202,6 +202,8 @@ AC_PROG_CXX_C_O AM_PROG_AS +AC_C_BIGENDIAN + # Check for other compiler toolchain tools. AC_CHECK_TOOL(AR, ar) diff --git a/src/core/common/encoding.hpp b/src/core/common/encoding.hpp index 0d4ba72cb..8f2858406 100644 --- a/src/core/common/encoding.hpp +++ b/src/core/common/encoding.hpp @@ -37,8 +37,13 @@ #include "openthread-core-config.h" #ifndef BYTE_ORDER_BIG_ENDIAN +#if defined(WORDS_BIGENDIAN) || \ + defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define BYTE_ORDER_BIG_ENDIAN 1 +#else #define BYTE_ORDER_BIG_ENDIAN 0 #endif +#endif #include #include