Skip to content

Commit 1718850

Browse files
pinotreeslouken
authored andcommitted
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)
1 parent b63c32e commit 1718850

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

cmake/sdlchecks.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ macro(CheckPTHREAD)
884884
set(PTHREAD_LDFLAGS "-pthread")
885885
elseif(QNX)
886886
# pthread support is baked in
887+
elseif(HURD)
888+
set(PTHREAD_CFLAGS "-D_REENTRANT")
889+
set(PTHREAD_LDFLAGS "-pthread")
887890
else()
888891
set(PTHREAD_CFLAGS "-D_REENTRANT")
889892
set(PTHREAD_LDFLAGS "-lpthread")

cmake/sdlplatform.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function(SDL_DetectCMakePlatform)
3636
set(sdl_cmake_platform NetBSD)
3737
elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
3838
set(sdl_cmake_platform OpenBSD)
39-
elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
40-
set(sdl_cmake_platform GNU)
39+
elseif(CMAKE_SYSTEM_NAME STREQUAL "GNU")
40+
set(sdl_cmake_platform Hurd)
4141
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
4242
set(sdl_cmake_platform BSDi)
4343
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")

include/SDL3/SDL_platform_defines.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,14 @@
484484
#define SDL_PLATFORM_NGAGE 1
485485
#endif
486486

487+
#ifdef __GNU__
488+
489+
/**
490+
* A preprocessor macro that is only defined if compiling for GNU/Hurd.
491+
*
492+
* \since This macro is available since SDL 3.4.0.
493+
*/
494+
#define SDL_PLATFORM_HURD 1
495+
#endif
496+
487497
#endif /* SDL_platform_defines_h_ */

src/SDL.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ const char *SDL_GetPlatform(void)
770770
return "PlayStation Vita";
771771
#elif defined(SDL_PLATFORM_3DS)
772772
return "Nintendo 3DS";
773+
#elif defined(SDL_PLATFORM_HURD)
774+
return "GNU/Hurd";
773775
#elif defined(__managarm__)
774776
return "Managarm";
775777
#else

src/core/unix/SDL_appid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const char *SDL_GetExeName(void)
3030

3131
// TODO: Use a fallback if BSD has no mounted procfs (OpenBSD has no procfs at all)
3232
if (!proc_name) {
33-
#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD)
33+
#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD) || defined(SDL_PLATFORM_HURD)
3434
static char linkfile[1024];
3535
int linksize;
3636

37-
#if defined(SDL_PLATFORM_LINUX)
37+
#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_HURD)
3838
const char *proc_path = "/proc/self/exe";
3939
#elif defined(SDL_PLATFORM_FREEBSD)
4040
const char *proc_path = "/proc/curproc/file";

test/testgles2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <stdlib.h>
2121

22-
#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_EMSCRIPTEN) || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_LINUX)
22+
#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)
2323
#define HAVE_OPENGLES2
2424
#endif
2525

0 commit comments

Comments
 (0)