Unverified Commit e0ff218a authored by Elian Doran's avatar Elian Doran
Browse files

ut1999: Enable darwin support

parent 15e0d551
Loading
Loading
Loading
Loading
+25 −16
Original line number Diff line number Diff line
{ lib, stdenv, requireFile, autoPatchelfHook, fetchurl, makeDesktopItem, copyDesktopItems, imagemagick
{ lib, stdenv, requireFile, autoPatchelfHook, undmg, fetchurl, makeDesktopItem, copyDesktopItems, imagemagick
, runCommand, libgcc, wxGTK32, innoextract, libGL, SDL2, openal, libmpg123, libxmp }:

let
@@ -12,6 +12,10 @@ let
      url = "https://github.com/OldUnreal/UnrealTournamentPatches/releases/download/v${version}/OldUnreal-UTPatch${version}-Linux-x86.tar.bz2";
      hash = "sha256-1JsFKuAAj/LtYvOUPFu0Hn+zvY3riW0YlJbLd4UnaKU=";
    };
    x86_64-darwin = fetchurl {
      url = "https://github.com/OldUnreal/UnrealTournamentPatches/releases/download/v${version}/OldUnreal-UTPatch${version}-macOS-Sonoma.dmg";
      hash = "sha256-TbhJbOH4E5WOb6XR9dmqLkXziK3/CzhNjd1ypBkkmvw=";
    };
  };
  unpackGog = runCommand "ut1999-gog" {
    src = requireFile rec {
@@ -35,6 +39,7 @@ let
  systemDir = {
    x86_64-linux = "System64";
    i686-linux = "System";
    x86_64-darwin = "System";
  }.${stdenv.hostPlatform.system} or (throw "unsupported system: ${stdenv.hostPlatform.system}");
in stdenv.mkDerivation {
  name = "ut1999";
@@ -53,38 +58,42 @@ in stdenv.mkDerivation {
    stdenv.cc.cc
  ];

  nativeBuildInputs = [
  nativeBuildInputs = lib.optionals stdenv.isLinux [
    copyDesktopItems
    autoPatchelfHook
    imagemagick
  ] ++ lib.optionals stdenv.isDarwin [
    undmg
  ];

  installPhase = ''
  installPhase = let
    outPrefix = if stdenv.isDarwin then "$out/UnrealTournament.app/Contents/MacOS" else "$out";
  in ''
    runHook preInstall

    mkdir -p $out/bin
    cp -r ./* $out

    # Remove bundled libraries to use native versions instead
    rm $out/${systemDir}/libmpg123.so* \
      $out/${systemDir}/libopenal.so* \
      $out/${systemDir}/libSDL2* \
      $out/${systemDir}/libxmp.so*

    cp -r ${if stdenv.isDarwin then "UnrealTournament.app" else "./*"} $out
    chmod -R 755 $out
    cd ${outPrefix}

    ln -s ${unpackGog}/Music $out
    ln -s ${unpackGog}/Sounds $out
    cp -n ${unpackGog}/Textures/* $out/Textures || true
    ln -s ${unpackGog}/Maps $out
    cp -n ${unpackGog}/System/*.{u,int} $out/System || true
    rm -rf ./{Music,Sounds,Maps}
    ln -s ${unpackGog}/{Music,Sounds,Maps} .

    cp -n ${unpackGog}/Textures/* ./Textures || true
    cp -n ${unpackGog}/System/*.{u,int} ./System || true
  '' + lib.optionalString (stdenv.isLinux) ''
    ln -s "$out/${systemDir}/ut-bin" "$out/bin/ut1999"
    ln -s "$out/${systemDir}/ucc-bin" "$out/bin/ut1999-ucc"

    convert "${unpackGog}/gfw_high.ico" "ut1999.png"
    install -D ut1999-5.png "$out/share/icons/hicolor/256x256/apps/ut1999.png"

    # Remove bundled libraries to use native versions instead
    rm $out/${systemDir}/libmpg123.so* \
      $out/${systemDir}/libopenal.so* \
      $out/${systemDir}/libSDL2* \
      $out/${systemDir}/libxmp.so*
  '' + ''
    runHook postInstall
  '';