summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--meson.build7
-rw-r--r--platform.h89
3 files changed, 14 insertions, 89 deletions
diff --git a/Makefile b/Makefile
index cea5c69b0..6de8f557d 100644
--- a/Makefile
+++ b/Makefile
@@ -248,6 +248,13 @@ ifneq ($(ARCH)-little, $(filter $(ARCH),x86 mips)-$(ENDIAN))
$(call mark_unsupported,CONFIG_INTERNAL)
endif
+ifeq ($(ENDIAN), little)
+FEATURE_CFLAGS += -D'__FLASHROM_LITTLE_ENDIAN__=1'
+endif
+ifeq ($(ENDIAN), big)
+FEATURE_CFLAGS += -D'__FLASHROM_BIG_ENDIAN__=1'
+endif
+
# PCI port I/O support is unimplemented on PPC/MIPS/SPARC and unavailable on ARM.
# Right now this means the drivers below only work on x86.
ifneq ($(ARCH), x86)
diff --git a/meson.build b/meson.build
index 1a36df887..02dedfcf9 100644
--- a/meson.build
+++ b/meson.build
@@ -29,6 +29,13 @@ add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required fo
add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
+if host_machine.endian() == 'little'
+ add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
+endif
+if host_machine.endian() == 'big'
+ add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
+endif
+
# get defaults from configure
config_atahpt = get_option('config_atahpt')
config_atapromise = get_option('config_atapromise')
diff --git a/platform.h b/platform.h
index cd8e54b06..9bbde549d 100644
--- a/platform.h
+++ b/platform.h
@@ -71,93 +71,4 @@
#error Unknown architecture
#endif
-/* The next big hunk tries to guess endianness from various preprocessor macros */
-/* First some error checking in case some weird header has defined both.
- * NB: OpenBSD always defines _BIG_ENDIAN and _LITTLE_ENDIAN. */
-#if defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
-#error Conflicting endianness #define
-#endif
-
-#if IS_X86
-
-/* All x86 is little-endian. */
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-
-#elif IS_MIPS
-
-/* MIPS can be either endian. */
-#if defined (__MIPSEL) || defined (__MIPSEL__) || defined (_MIPSEL) || defined (MIPSEL)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#elif defined (__MIPSEB) || defined (__MIPSEB__) || defined (_MIPSEB) || defined (MIPSEB)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#endif
-
-#elif IS_PPC
-
-/* PowerPC can be either endian. */
-#if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#elif defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#elif IS_ARM
-
-/* ARM can be either endian. */
-#if defined (__ARMEB__) || defined (__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#elif defined (__ARMEL__) || defined (__LITTLE_ENDIAN__)
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#elif IS_SPARC
-/* SPARC is big endian in general (but allows to access data in little endian too). */
-#define __FLASHROM_BIG_ENDIAN__ 1
-
-#elif IS_ARC
-#if defined(__BIG_ENDIAN__)
-#define __FLASHROM_BIG_ENDIAN__ 1
-#else
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#endif
-
-#endif /* IS_? */
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-
-/* If architecture-specific approaches fail try generic variants. First: BSD (works about everywhere). */
-#if !IS_WINDOWS
-#include <sys/param.h>
-
-#if defined (__BYTE_ORDER)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define __FLASHROM_LITTLE_ENDIAN__
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define __FLASHROM_BIG_ENDIAN__
-#else
-#error Unknown byte order!
-#endif
-#endif /* defined __BYTE_ORDER */
-#endif /* !IS_WINDOWS */
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-
-/* Nonstandard libc-specific macros for determining endianness. */
-/* musl provides an endian.h as well... but it can not be detected from within C. */
-#if defined(__GLIBC__)
-#include <endian.h>
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define __FLASHROM_LITTLE_ENDIAN__ 1
-#elif BYTE_ORDER == BIG_ENDIAN
-#define __FLASHROM_BIG_ENDIAN__ 1
-#endif
-#endif
-#endif
-
-#endif
-
-#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-#error Unable to determine endianness.
-#endif
-
#endif /* !__PLATFORM_H__ */