瀏覽代碼

Add GNU/Hurd as platform

SDL has been building on GNU/Hurd for a long time, using either drivers
based on external libraries (e.g. X11, pulseaudio, sndio, etc) or dummy
drivers. This commit introduces it explicitly as platform, so it can be
recognized, and tweaked as needed. In particular:
- introduce the SDL_PLATFORM_HURD define
- tighten/improve the platform detection in cmake, and use "Hurd" as
  identifier
- return the platform name in SDL_GetPlatform()
- tweak the CFLAGS/LDFLAGS so pthreads can be used properly
- implement SDL_GetExeName(), using /proc/self/exe as provided by the
  basic Linux-like procfs
- enable GLES 2 in tests (mostly for consistency with Linux)
Pino Toscano 1 月之前
父節點
當前提交
171885010d
共有 6 個文件被更改,包括 20 次插入5 次删除
  1. 3 0
      cmake/sdlchecks.cmake
  2. 2 2
      cmake/sdlplatform.cmake
  3. 10 0
      include/SDL3/SDL_platform_defines.h
  4. 2 0
      src/SDL.c
  5. 2 2
      src/core/unix/SDL_appid.c
  6. 1 1
      test/testgles2.c

+ 3 - 0
cmake/sdlchecks.cmake

@@ -884,6 +884,9 @@ macro(CheckPTHREAD)
       set(PTHREAD_LDFLAGS "-pthread")
     elseif(QNX)
       # pthread support is baked in
+    elseif(HURD)
+      set(PTHREAD_CFLAGS "-D_REENTRANT")
+      set(PTHREAD_LDFLAGS "-pthread")
     else()
       set(PTHREAD_CFLAGS "-D_REENTRANT")
       set(PTHREAD_LDFLAGS "-lpthread")

+ 2 - 2
cmake/sdlplatform.cmake

@@ -36,8 +36,8 @@ function(SDL_DetectCMakePlatform)
     set(sdl_cmake_platform NetBSD)
   elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
     set(sdl_cmake_platform OpenBSD)
-  elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
-    set(sdl_cmake_platform GNU)
+  elseif(CMAKE_SYSTEM_NAME STREQUAL "GNU")
+    set(sdl_cmake_platform Hurd)
   elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
     set(sdl_cmake_platform BSDi)
   elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")

+ 10 - 0
include/SDL3/SDL_platform_defines.h

@@ -484,4 +484,14 @@
 #define SDL_PLATFORM_NGAGE 1
 #endif
 
+#ifdef __GNU__
+
+/**
+ * A preprocessor macro that is only defined if compiling for GNU/Hurd.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_PLATFORM_HURD 1
+#endif
+
 #endif /* SDL_platform_defines_h_ */

+ 2 - 0
src/SDL.c

@@ -770,6 +770,8 @@ const char *SDL_GetPlatform(void)
     return "PlayStation Vita";
 #elif defined(SDL_PLATFORM_3DS)
     return "Nintendo 3DS";
+#elif defined(SDL_PLATFORM_HURD)
+    return "GNU/Hurd";
 #elif defined(__managarm__)
     return "Managarm";
 #else

+ 2 - 2
src/core/unix/SDL_appid.c

@@ -30,11 +30,11 @@ const char *SDL_GetExeName(void)
 
     // TODO: Use a fallback if BSD has no mounted procfs (OpenBSD has no procfs at all)
     if (!proc_name) {
-#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD)
+#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD) || defined(SDL_PLATFORM_HURD)
         static char linkfile[1024];
         int linksize;
 
-#if defined(SDL_PLATFORM_LINUX)
+#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_HURD)
         const char *proc_path = "/proc/self/exe";
 #elif defined(SDL_PLATFORM_FREEBSD)
         const char *proc_path = "/proc/curproc/file";

+ 1 - 1
test/testgles2.c

@@ -19,7 +19,7 @@
 
 #include <stdlib.h>
 
-#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_EMSCRIPTEN) || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_LINUX)
+#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_EMSCRIPTEN) || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_HURD)
 #define HAVE_OPENGLES2
 #endif