Define _GNU_SOURCE when building SDL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 7e92850..e3083fe 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -21,6 +21,15 @@
#ifndef _SDL_internal_h
#define _SDL_internal_h
+/* Many of SDL's features require _GNU_SOURCE on various platforms
+ You can turn this off if necessary by using -D_GNU_SOURCE=0
+ */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#elif !_GNU_SOURCE
+#undef _GNU_SOURCE
+#endif
+
#include "dynapi/SDL_dynapi.h"
#if SDL_DYNAMIC_API
@@ -33,6 +42,6 @@
#include "SDL_config.h"
-#endif
+#endif /* _SDL_internal_h */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index debbeba..3e856b5 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -18,15 +18,10 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
-
-#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#if defined(__clang_analyzer__)
#define SDL_DISABLE_ANALYZE_MACROS 1
#endif
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-
#include "../SDL_internal.h"
/* This file contains portable string manipulation functions for SDL */
diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c
index 1bd8dfa..9ae6536 100644
--- a/src/test/SDL_test_fuzzer.c
+++ b/src/test/SDL_test_fuzzer.c
@@ -34,7 +34,6 @@
#define UINT32_MAX ~(Uint32)0
#define UINT64_MAX ~(Uint64)0
#else
-#define _GNU_SOURCE
#include <stdint.h>
#endif
#include <stdio.h>
diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c
index f24cfda..ee7f583 100644
--- a/src/thread/pthread/SDL_sysmutex.c
+++ b/src/thread/pthread/SDL_sysmutex.c
@@ -20,9 +20,6 @@
*/
#include "../../SDL_internal.h"
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
#include <errno.h>
#include <pthread.h>
diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c
index b7547e6..caadf4e 100644
--- a/src/thread/pthread/SDL_syssem.c
+++ b/src/thread/pthread/SDL_syssem.c
@@ -20,9 +20,6 @@
*/
#include "../../SDL_internal.h"
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index afcec1a..323eff7 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -23,8 +23,6 @@
#if SDL_VIDEO_DRIVER_WAYLAND
-/* _GNU_SOURCE for pipe2 declaration. */
-#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index 8dfc9ee..73b2b58 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -23,10 +23,6 @@
#if SDL_VIDEO_DRIVER_WAYLAND
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index b1e3ff4..29307b3 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -18,10 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_X11