| 1 |
From: Simon McVittie <[email protected]> |
| 2 |
Date: Sat, 24 Jun 2017 19:09:26 +0100 |
| 3 |
Subject: build: define ARCH_STRING in Makefile on Linux and other GNU |
| 4 |
platforms |
| 5 |
|
| 6 |
GNU platforms (Linux, kFreeBSD, Hurd) have endian.h to determine |
| 7 |
endianness, so all architectures except x86_64 are in fact treated |
| 8 |
identically, except that their ARCH_STRING is different. For the engine, |
| 9 |
the ARCH_STRING must always be identical to the ARCH from the Makefile, |
| 10 |
otherwise the engine will not find its cgame, game and ui plugins |
| 11 |
under their expected names and startup will fail. If we pass it in |
| 12 |
from the Makefile, then an identical value is guaranteed, and we can |
| 13 |
get rid of an increasingly long list of defined(__some_cpu__) tests. |
| 14 |
|
| 15 |
The game-code does not actually use ARCH_STRING, but I've kept it |
| 16 |
in order to be consistent with the ioquake3 engine. |
| 17 |
|
| 18 |
On non-Linux platforms we only support a few architectures anyway, |
| 19 |
so keeping the list up to date is less of a burden; *BSD porters |
| 20 |
could probably use the same technique to get support for lots of |
| 21 |
architectures with little effort, but I have not done that here, |
| 22 |
because I cannot test it. |
| 23 |
|
| 24 |
Windows must continue to support preprocessor-based architecture tests |
| 25 |
in any case, so that the MSVC solutions (which do not use the Makefile) |
| 26 |
can continue to work. However, Windows only runs on a few CPU families, |
| 27 |
so this shouldn't be a significant burden in practice. |
| 28 |
|
| 29 |
When cross-compiling, the tools are compiled for the build architecture |
| 30 |
(COMPILE_PLATFORM, COMPILE_ARCH) rather than the host architecture |
| 31 |
(PLATFORM, ARCH), so define ARCH_STRING to COMPILE_ARCH on a GNU |
| 32 |
COMPILE_PLATFORM. |
| 33 |
|
| 34 |
(cherry-picked from ioquake3 commit 2a71948f21fe588dbce9b29409283e9c912ef8e7) |
| 35 |
|
| 36 |
Forwarded: https://github.com/OpenArena/gamecode/pull/17 |
| 37 |
Applied-upstream: https://github.com/OpenArena/gamecode/commit/732d32079b6675f8595471af7d252e190c80f006 |
| 38 |
--- |
| 39 |
Makefile | 6 +++++- |
| 40 |
code/qcommon/q_platform.h | 30 ++---------------------------- |
| 41 |
2 files changed, 7 insertions(+), 29 deletions(-) |
| 42 |
|
| 43 |
diff --git a/Makefile b/Makefile |
| 44 |
index 11a9efc..6eeba4f 100644 |
| 45 |
--- a/Makefile |
| 46 |
+++ b/Makefile |
| 47 |
@@ -211,6 +211,10 @@ endif |
| 48 |
INSTALL=install |
| 49 |
MKDIR=mkdir |
| 50 |
|
| 51 |
+ifneq (,$(findstring "$(COMPILE_PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu" "gnu")) |
| 52 |
+ TOOLS_CFLAGS += -DARCH_STRING=\"$(COMPILE_ARCH)\" |
| 53 |
+endif |
| 54 |
+ |
| 55 |
ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu" "gnu")) |
| 56 |
|
| 57 |
ifeq ($(ARCH),alpha) |
| 58 |
@@ -218,7 +222,7 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu" "gnu") |
| 59 |
endif |
| 60 |
|
| 61 |
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes \ |
| 62 |
- -pipe -DUSE_ICON $(SDL_CFLAGS) |
| 63 |
+ -pipe -DUSE_ICON $(SDL_CFLAGS) -DARCH_STRING=\\\"$(ARCH)\\\" |
| 64 |
|
| 65 |
ifeq ($(USE_OPENAL),1) |
| 66 |
BASE_CFLAGS += -DUSE_OPENAL |
| 67 |
diff --git a/code/qcommon/q_platform.h b/code/qcommon/q_platform.h |
| 68 |
index cfa44b7..fc8d40d 100644 |
| 69 |
--- a/code/qcommon/q_platform.h |
| 70 |
+++ b/code/qcommon/q_platform.h |
| 71 |
@@ -162,34 +162,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 72 |
#define ID_INLINE inline |
| 73 |
#define PATH_SEP '/' |
| 74 |
|
| 75 |
-#if defined __i386__ |
| 76 |
-#define ARCH_STRING "i386" |
| 77 |
-#elif defined __x86_64__ |
| 78 |
-#define ARCH_STRING "x86_64" |
| 79 |
-#elif defined __powerpc64__ |
| 80 |
-#define ARCH_STRING "ppc64" |
| 81 |
-#elif defined __powerpc__ |
| 82 |
-#define ARCH_STRING "ppc" |
| 83 |
-#elif defined __s390__ |
| 84 |
-#define ARCH_STRING "s390" |
| 85 |
-#elif defined __s390x__ |
| 86 |
-#define ARCH_STRING "s390x" |
| 87 |
-#elif defined __ia64__ |
| 88 |
-#define ARCH_STRING "ia64" |
| 89 |
-#elif defined __alpha__ |
| 90 |
-#define ARCH_STRING "alpha" |
| 91 |
-#elif defined __sparc__ |
| 92 |
-#define ARCH_STRING "sparc" |
| 93 |
-#elif defined __arm__ |
| 94 |
-#define ARCH_STRING "arm" |
| 95 |
-#elif defined __cris__ |
| 96 |
-#define ARCH_STRING "cris" |
| 97 |
-#elif defined __hppa__ |
| 98 |
-#define ARCH_STRING "hppa" |
| 99 |
-#elif defined __mips__ |
| 100 |
-#define ARCH_STRING "mips" |
| 101 |
-#elif defined __sh__ |
| 102 |
-#define ARCH_STRING "sh" |
| 103 |
+#if !defined(ARCH_STRING) |
| 104 |
+# error ARCH_STRING should be defined by the Makefile |
| 105 |
#endif |
| 106 |
|
| 107 |
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN |