Unverified Commit 3954326c authored by 7c6f434c's avatar 7c6f434c Committed by GitHub
Browse files

speed-dreams: add darwin support (#481532)

parents 733406c0 0f3b9676
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
diff --git a/src/ssg/ssgLoadFLT.cxx b/src/ssg/ssgLoadFLT.cxx
--- a/src/ssg/ssgLoadFLT.cxx
+++ b/src/ssg/ssgLoadFLT.cxx
@@ -112,6 +112,10 @@
 # include <sys/stat.h>
 # include <sys/mman.h>
 #endif
+#if defined(__APPLE__)
+typedef unsigned int uint;
+typedef unsigned short ushort;
+#endif
 #ifdef UL_MSVC
 # include <io.h>
 #endif
+8 −2
Original line number Diff line number Diff line
@@ -37,9 +37,15 @@ stdenv.mkDerivation rec {
      url = "https://sources.debian.org/data/main/p/plib/1.8.5-13/debian/patches/08_CVE-2021-38714.patch";
      sha256 = "sha256-3f1wZn0QqK/hPWCg1KEzbB95IGoxBjLZoCOFlW98t5w=";
    })
    ./darwin-ssgloadflt-uint.patch
  ];

  propagatedBuildInputs = [
  configureFlags = lib.optionals stdenv.hostPlatform.isDarwin [
    "--disable-sl"
    "--disable-pw"
  ];

  propagatedBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
    libGLU
    libGL
    libglut
@@ -70,6 +76,6 @@ stdenv.mkDerivation rec {
    license = lib.licenses.lgpl2Plus;

    homepage = "https://plib.sourceforge.net/";
    platforms = lib.platforms.linux;
    platforms = lib.platforms.unix;
  };
}
+16 −0
Original line number Diff line number Diff line
diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp
--- a/src/libs/tgfclient/guiscreen.cpp
+++ b/src/libs/tgfclient/guiscreen.cpp
@@ -426,9 +426,9 @@ bool GfScrInitSDL2(int nWinWidth, int nWinHeight, int nFullScreen)
 
 #ifdef __APPLE__
     // Version d'OpenGL
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
 #else
     // Version d'OpenGL
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+66 −55
Original line number Diff line number Diff line
@@ -29,37 +29,22 @@
  cmake,
  pkg-config,
  libvorbis,
  runtimeShell,
  curl,
  fetchgit,
  cjson,
  minizip,
  rhash,
  copyDesktopItems,
  makeWrapper,
}:

stdenv.mkDerivation rec {
  version = "2.4.2";
  pname = "speed-dreams";

  src = fetchgit {
    url = "https://forge.a-lec.org/speed-dreams/speed-dreams-code.git";
    rev = "v${version}";
    sha256 = "sha256-ZY/0tf0wFbepEUNqpaBA4qgkWDij/joqPtbiF/48oN4=";
    fetchSubmodules = true;
  };
  NIX_CFLAGS_COMPILE = "-I${src}/src/libs/tgf -I${src}/src/libs/tgfdata -I${src}/src/interfaces -I${src}/src/libs/math -I${src}/src/libs/portability";

  postInstall = ''
    mkdir -p "$out/bin"
    # Wrapper for main executable
    cat > "$out/bin/speed-dreams" <<EOF
    #!${runtimeShell}
    export LD_LIBRARY_PATH="$out/lib/games/speed-dreams-2/lib:$out/lib:${
      lib.makeLibraryPath [
let
  glLibs = lib.optionals stdenv.isLinux [
    libGL
    libGLU
    libglut
  ];
  runtimeLibs = glLibs ++ [
    libX11
    plib
    openal
@@ -86,22 +71,45 @@ stdenv.mkDerivation rec {
    minizip
    rhash
    stdenv.cc.cc.lib
      ]
    }"
    if [ -e "${libGL}/lib/libGL.so.1" ]; then
      export LD_PRELOAD="${libGL}/lib/libGL.so.1''${LD_PRELOAD:+:$LD_PRELOAD}"
    fi
    export SDL_VIDEODRIVER="x11"
    exec "$out/games/speed-dreams-2" "$@"
    EOF
    chmod a+x "$out/bin/speed-dreams"
  ];
  runtimeLibPath = lib.makeLibraryPath runtimeLibs;
  libPathVar = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
in
stdenv.mkDerivation rec {
  version = "2.4.2";
  pname = "speed-dreams";

  src = fetchgit {
    url = "https://forge.a-lec.org/speed-dreams/speed-dreams-code.git";
    rev = "v${version}";
    sha256 = "sha256-ZY/0tf0wFbepEUNqpaBA4qgkWDij/joqPtbiF/48oN4=";
    fetchSubmodules = true;
  };
  NIX_CFLAGS_COMPILE = "-I${src}/src/libs/tgf -I${src}/src/libs/tgfdata -I${src}/src/interfaces -I${src}/src/libs/math -I${src}/src/libs/portability";

  patches = [
    ./darwin-gl-compat.patch
  ];

  postInstall = ''
    substituteInPlace "$out/share/applications/speed-dreams.desktop" \
      --replace-fail "Exec=$out/games/speed-dreams-2" "Exec=$out/bin/speed-dreams"
    ${lib.optionalString stdenv.isLinux ''
      # Symlink for desktop icon
      mkdir -p $out/share/pixmaps/
      ln -s "$out/share/games/speed-dreams-2/data/icons/icon.png" "$out/share/pixmaps/speed-dreams-2.png"
      substituteInPlace "$out/share/applications/speed-dreams.desktop" \
      --replace-fail "Exec=$out/games/speed-dreams-2" "Exec=$out/bin/speed-dreams" \
        --replace-fail "Icon=/build/speed-dreams-code/speed-dreams-data/data/data/icons/icon.png" "Icon=$out/share/pixmaps/speed-dreams-2.png"
    ''}
  '';

  postFixup = ''
    mkdir -p "$out/bin"
    makeWrapperArgs=(
      --prefix ${libPathVar} : "$out/lib/games/speed-dreams-2/lib:$out/lib:${runtimeLibPath}"
    )
    ${lib.optionalString stdenv.isLinux "makeWrapperArgs+=(--set SDL_VIDEODRIVER x11)"}
    makeWrapper "$out/games/speed-dreams-2" "$out/bin/speed-dreams" "''${makeWrapperArgs[@]}"
  '';

  # RPATH of binary /nix/store/.../lib64/games/speed-dreams-2/drivers/shadow_sc/shadow_sc.so contains a forbidden reference to /build/
@@ -113,13 +121,11 @@ stdenv.mkDerivation rec {
    pkg-config
    cmake
    copyDesktopItems
    makeWrapper
  ];

  buildInputs = [
    libpng12
    libGLU
    libGL
    libglut
    libX11
    plib
    openal
@@ -146,6 +152,11 @@ stdenv.mkDerivation rec {
    cjson
    minizip
    rhash
  ]
  ++ lib.optionals stdenv.isLinux [
    libGL
    libGLU
    libglut
  ];

  meta = {
@@ -156,7 +167,7 @@ stdenv.mkDerivation rec {
      raskin
      mio
    ];
    platforms = lib.platforms.linux;
    platforms = lib.platforms.linux ++ lib.platforms.darwin;
    mainProgram = "speed-dreams";
  };
}