From b0832788ecfb4d99fc21f08888da3ee7aa4066b1 Mon Sep 17 00:00:00 2001
From: Christian Krause <chkr@plauener.de>
Date: Sun, 4 Jul 2021 10:45:35 +0200
Subject: [PATCH] SDL: build fix for various non-x86 architectures
- allow certain symbols from unistd.h within SDL backend
- e.g. on armv7, ppc64, aarch and s390, SDL.h would include indirectly
unistd.h after common/forbidden.h and so the preprocessor would
generate broken code even if the symbols are never called by
scummvm
---
backends/platform/sdl/sdl-sys.h | 51 +++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h
index 219aca830a..d33f1453ee 100644
--- a/backends/platform/sdl/sdl-sys.h
+++ b/backends/platform/sdl/sdl-sys.h
@@ -111,6 +111,32 @@
#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
+// Fix compilation on non-x86 architectures
+// It needs various (usually forbidden) symbols from unistd.h
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
+ #undef chdir
+ #define chdir FAKE_chdir
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
+ #undef getcwd
+ #define getcwd FAKE_getcwd
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
+ #undef getwd
+ #define getwd FAKE_getwd
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
+ #undef unlink
+ #define unlink FAKE_unlink
+ #endif
+
+#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
// HACK: SDL might include windows.h which defines its own ARRAYSIZE.
// However, we want to use the version from common/util.h. Thus, we make sure
// that we actually have this definition after including the SDL headers.
@@ -274,4 +300,29 @@
#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
+// re-forbid all those unistd.h symbols again (if they were forbidden)
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
+ #undef chdir
+ #define chdir(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
+ #undef getcwd
+ #define getcwd(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
+ #undef getwd
+ #define getwd(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
+ #undef unlink
+ #define unlink(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
+ #endif
+
+#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
#endif
--
2.26.3