Commit bd0def06ee47bee34a296da70cc0e4edd2dbd862

Guillermo A. Amaral 2018-02-07T14:12:26

Set rpath instead of changing environment for RPi Credit goes to Adrian Perez de Castro for the improvement. Signed-off-by: Guillermo A. Amaral <g@maral.me>

diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 4093594..b210105 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -1132,6 +1132,7 @@ macro(CheckRPI)
       set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
       set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
       set(VIDEO_RPI_LIBRARIES bcm_host )
+      set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
     endif()
     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
@@ -1152,6 +1153,7 @@ macro(CheckRPI)
       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
+      list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
   endif(VIDEO_RPI)
 endmacro(CheckRPI)
diff --git a/configure b/configure
index bc79df9..7fd57c5 100755
--- a/configure
+++ b/configure
@@ -19551,7 +19551,7 @@ fi
             RPI_LDFLAGS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host"
         else
             RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux"
-            RPI_LDFLAGS="-L/opt/vc/lib -lbcm_host"
+            RPI_LDFLAGS="-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib -lbcm_host"
         fi
 
         # Save the original compiler flags and libraries
diff --git a/configure.in b/configure.in
index 56dd7a7..2a9b464 100644
--- a/configure.in
+++ b/configure.in
@@ -1580,7 +1580,7 @@ AC_HELP_STRING([--enable-video-rpi], [use Raspberry Pi video driver [[default=ye
             RPI_LDFLAGS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host"
         else
             RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux"
-            RPI_LDFLAGS="-L/opt/vc/lib -lbcm_host"
+            RPI_LDFLAGS="-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib -lbcm_host"
         fi
 
         # Save the original compiler flags and libraries
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 3926d5b..d40285e 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -44,7 +44,6 @@
 
 #if SDL_VIDEO_DRIVER_RPI
 /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
-static const char g_rpi_opt_path[] = "/opt/vc/lib";
 #define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
 #define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
 #define ALT_EGL "libEGL.so"
@@ -266,20 +265,6 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
 #endif
 #if SDL_VIDEO_DRIVER_RPI
     SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
-
-    path = SDL_getenv("LD_LIBRARY_PATH");
-    if (path) {
-        const int path_size = SDL_strlen(path) + 1 + sizeof(g_rpi_opt_path);
-        char *new_path = SDL_calloc(1, path_size);
-        strcat(new_path, path);
-        strcat(new_path, ":");
-        strcat(new_path, g_rpi_opt_path);
-        SDL_setenv("LD_LIBRARY_PATH", new_path, 1);
-        SDL_free(new_path);
-    } else {
-        SDL_setenv("LD_LIBRARY_PATH", g_rpi_opt_path, 1);
-    }
-    path = NULL;
 #endif
 
     if (_this->egl_data) {