Makefile: move endian test into Makefile.d

flashrom-stable:
Somewhat restored the original solution using pre-defined macros.

Change-Id: I0c2420fd60d7d6a23c94c9962b06bfd7f3c86ad8
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/58270
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72243
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/Makefile b/Makefile
index d34c289..da092ce 100644
--- a/Makefile
+++ b/Makefile
@@ -166,8 +166,7 @@
 # the lines below use CC itself.
 override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h)
 override ARCH      := $(call c_macro_test, Makefile.d/arch_test.h)
-override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null \
-    | tail -1))
+override ENDIAN    := $(call c_macro_test, Makefile.d/endian_test.h)
 
 ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD))
 override CPPFLAGS += -I/usr/local/include
@@ -844,6 +843,8 @@
 	@if [ $(ARCH) = unknown ]; then echo Aborting.; exit 1; fi
 	@echo Target OS is $(TARGET_OS)
 	@if [ $(TARGET_OS) = unknown ]; then echo Aborting.; exit 1; fi
+	@echo Target endian is $(ENDIAN)
+	@if [ $(ENDIAN) = unknown ]; then echo Aborting.; exit 1; fi
 ifeq ($(TARGET_OS), libpayload)
 	@$(CC) --version 2>&1 | grep -q coreboot || \
 		( echo "Warning: It seems you are not using coreboot's reference compiler."; \
diff --git a/Makefile.d/endian_test.h b/Makefile.d/endian_test.h
new file mode 100644
index 0000000..e600e14
--- /dev/null
+++ b/Makefile.d/endian_test.h
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2011 Carl-Daniel Hailfinger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/*
+ * This file determines the target endian. It should only be used by the Makefile
+ */
+
+/*
+ * This works since gcc 4.6 and with clang
+ * https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+ */
+#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+"big"
+#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+"little"
+#else
+"unknown"
+#endif
diff --git a/endiantest.c b/endiantest.c
deleted file mode 100644
index a73b908..0000000
--- a/endiantest.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "platform.h"
-#if defined(__FLASHROM_LITTLE_ENDIAN__)
-little
-#else
-big
-#endif