Unverified Commit cb1697b9 authored by Peder Bergebakken Sundt's avatar Peder Bergebakken Sundt Committed by GitHub
Browse files

SDL_compat: set rpath during installation; add tests (#405305)

parents b3645c4a 69948e36
Loading
Loading
Loading
Loading
+46 −18
Original line number Diff line number Diff line
@@ -11,6 +11,12 @@
  pkg-config,
  pkg-config-unwrapped,
  stdenv,
  testers,
  dosbox,
  SDL_image,
  SDL_ttf,
  SDL_mixer,
  SDL_sound,
  # Boolean flags
  libGLSupported ? lib.elem stdenv.hostPlatform.system mesa.meta.platforms,
  openglSupport ? libGLSupported,
@@ -52,8 +58,33 @@ stdenv.mkDerivation (finalAttrs: {
    ]
    ++ lib.optionals openglSupport [ libGLU ];

  postPatch = ''
    substituteInPlace CMakeLists.txt \
      --replace-fail 'set(CMAKE_SKIP_RPATH TRUE)' 'set(CMAKE_SKIP_RPATH FALSE)'
  '';

  dontPatchELF = true; # don't strip rpath

  cmakeFlags =
    let
      rpath = lib.makeLibraryPath [ sdl2-compat ];
    in
    [
      (lib.cmakeFeature "CMAKE_INSTALL_RPATH" rpath)
      (lib.cmakeFeature "CMAKE_BUILD_RPATH" rpath)
      (lib.cmakeBool "SDL12TESTS" finalAttrs.finalPackage.doCheck)
    ];

  enableParallelBuilding = true;

  # Darwin fails with "Critical error: required built-in appearance SystemAppearance not found"
  doCheck = !stdenv.hostPlatform.isDarwin;
  checkPhase = ''
    runHook preCheck
    ./testver
    runHook postCheck
  '';

  postInstall = ''
    # allow as a drop in replacement for SDL
    # Can be removed after treewide switch from pkg-config to pkgconf
@@ -66,24 +97,17 @@ stdenv.mkDerivation (finalAttrs: {
  patches = [ ./find-headers.patch ];
  setupHook = ./setup-hook.sh;

  postFixup = ''
    for lib in $out/lib/*${stdenv.hostPlatform.extensions.sharedLibrary}* ; do
      if [[ -L "$lib" ]]; then
        ${
          if stdenv.hostPlatform.isDarwin then
            ''
              install_name_tool ${
                lib.strings.concatMapStrings (x: " -add_rpath ${lib.makeLibraryPath [ x ]} ") finalAttrs.buildInputs
              } "$lib"
            ''
          else
            ''
              patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath finalAttrs.buildInputs}" "$lib"
            ''
        }
      fi
    done
  '';
  passthru.tests = {
    pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;

    inherit
      SDL_image
      SDL_ttf
      SDL_mixer
      SDL_sound
      dosbox
      ;
  };

  meta = {
    homepage = "https://www.libsdl.org/";
@@ -93,5 +117,9 @@ stdenv.mkDerivation (finalAttrs: {
    maintainers = with lib.maintainers; [ peterhoeg ];
    teams = [ lib.teams.sdl ];
    platforms = lib.platforms.all;
    pkgConfigModules = [
      "sdl"
      "sdl12_compat"
    ];
  };
})