From 93d4278f572935eaacd4bd0b0176afc6c9178b14 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Fri, 29 Nov 2024 07:09:49 +0800
Subject: [PATCH] Sort out X11/OpenGL

---
 configure                     | 28 +++++++++++++++-------------
 include/SDL_config_macosx.h   | 14 ++++++++------
 src/video/x11/SDL_x11opengl.c |  9 ++++++++-
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git configure configure
index cbae11e23..60605c44d 100755
--- configure
+++ configure
@@ -23776,10 +23776,10 @@ fi
                 # This isn't necessary for X11, but fixes GLX detection
                 if test "x$x_includes" = xNONE && \
                    test "x$x_libraries" = xNONE && \
-                   test -d /opt/X11/include && \
-                   test -d /opt/X11/lib; then
-                    x_includes="/opt/X11/include"
-                    x_libraries="/opt/X11/lib"
+                   test -d @PREFIX@/include && \
+                   test -d @PREFIX@/lib; then
+                    x_includes="@PREFIX@/include"
+                    x_libraries="@PREFIX@/lib"
                 fi
                 ;;
         esac
@@ -23876,6 +23876,8 @@ fi
   # Standard set of common directories for X headers.
 # Check X11 before X11Rn because it is often a symlink to the current release.
 ac_x_header_dirs='
+@PREFIX@/include
+
 /usr/X11/include
 /usr/X11R7/include
 /usr/X11R6/include
@@ -24518,15 +24520,15 @@ fi
 
             case "$host" in
                 *-*-darwin*)
-                    # Apple now puts this in /opt/X11
-                    x11_lib='/opt/X11/lib/libX11.6.dylib'
-                    x11ext_lib='/opt/X11/lib/libXext.6.dylib'
-                    xcursor_lib='/opt/X11/lib/libXcursor.1.dylib'
-                    xinput_lib='/opt/X11/lib/libXi.6.dylib'
-                    xfixes_lib='/opt/X11/lib/libXfixes.3.dylib'
-                    xrandr_lib='/opt/X11/lib/libXrandr.2.dylib'
-                    xrender_lib='/opt/X11/lib/libXrender.1.dylib'
-                    xss_lib='/opt/X11/lib/libXss.1.dylib'
+                    # MacPorts puts this in @PREFIX@
+                    x11_lib='@PREFIX@/lib/libX11.6.dylib'
+                    x11ext_lib='@PREFIX@/lib/libXext.6.dylib'
+                    xcursor_lib='@PREFIX@/lib/libXcursor.1.dylib'
+                    xinput_lib='@PREFIX@/lib/libXi.6.dylib'
+                    xfixes_lib='@PREFIX@/lib/libXfixes.3.dylib'
+                    xrandr_lib='@PREFIX@/lib/libXrandr.2.dylib'
+                    xrender_lib='@PREFIX@/lib/libXrender.1.dylib'
+                    xss_lib='@PREFIX@/lib/libXss.1.dylib'
                     ;;
                 *-*-openbsd*)
                     x11_lib='libX11.so'
diff --git include/SDL_config_macosx.h include/SDL_config_macosx.h
index 2db760a9f..aea6a0c99 100644
--- include/SDL_config_macosx.h
+++ include/SDL_config_macosx.h
@@ -182,14 +182,16 @@
 #define SDL_TIMER_UNIX  1
 
 /* Enable various video drivers */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040
 #define SDL_VIDEO_DRIVER_COCOA  1
+#endif
 #define SDL_VIDEO_DRIVER_DUMMY  1
-#undef SDL_VIDEO_DRIVER_X11
-#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/opt/X11/lib/libX11.6.dylib"
-#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/opt/X11/lib/libXext.6.dylib"
-#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "/opt/X11/lib/libXi.6.dylib"
-#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/opt/X11/lib/libXrandr.2.dylib"
-#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/opt/X11/lib/libXss.1.dylib"
+#define SDL_VIDEO_DRIVER_X11    1
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC "@PREFIX@/lib/libX11.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "@PREFIX@/lib/libXext.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "@PREFIX@/lib/libXi.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "@PREFIX@/lib/libXrandr.2.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "@PREFIX@/lib/libXss.1.dylib"
 #define SDL_VIDEO_DRIVER_X11_XDBE 1
 #define SDL_VIDEO_DRIVER_X11_XRANDR 1
 #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
diff --git src/video/x11/SDL_x11opengl.c src/video/x11/SDL_x11opengl.c
index da252615f..2255c479f 100644
--- src/video/x11/SDL_x11opengl.c
+++ src/video/x11/SDL_x11opengl.c
@@ -40,7 +44,7 @@
  */
 #define DEFAULT_OPENGL  "libGL.so"
 #elif defined(__MACOSX__)
-#define DEFAULT_OPENGL  "/opt/X11/lib/libGL.1.dylib"
+#define DEFAULT_OPENGL  "@GL_LIB@"
 #elif defined(__QNXNTO__)
 #define DEFAULT_OPENGL  "libGL.so.3"
 #else
