···11+{ lib, stdenv
22+, makeWrapper
33+, makeDesktopItem, copyDesktopItems
44+, fetchFromGitHub
55+, pkg-config
66+, SDL2, SDL2_image
77+}:
88+99+stdenv.mkDerivation rec {
1010+ pname = "sdlpop";
1111+ version = "1.21";
1212+1313+ src = fetchFromGitHub {
1414+ owner = "NagyD";
1515+ repo = "SDLPoP";
1616+ rev = "v${version}";
1717+ sha256 = "1q4mnyg8v4420f1bp24v8lgi335vijdv61yi3fan14jgfzl38l7w";
1818+ };
1919+2020+ nativeBuildInputs = [ pkg-config makeWrapper copyDesktopItems ];
2121+ buildInputs = [ SDL2 SDL2_image ];
2222+2323+ makeFlags = [ "-C" "src" ];
2424+2525+ preBuild = ''
2626+ substituteInPlace src/Makefile --replace "CC = gcc" "CC = ${stdenv.cc.targetPrefix}gcc"
2727+ '';
2828+2929+ # The prince binary expects two things of the working directory it is called from:
3030+ # (1) There is a subdirectory "data" containing the level data.
3131+ # (2) The working directory is writable, so save and quicksave files can be created.
3232+ # Our solution is to ensure that ~/.local/share/sdlpop is the working
3333+ # directory, symlinking the data files into it. This is the task of the
3434+ # prince.sh wrapper.
3535+3636+ installPhase = ''
3737+ runHook preInstall
3838+3939+ install -Dm755 prince $out/bin/.prince-bin
4040+ substituteAll ${./prince.sh} $out/bin/prince
4141+ chmod +x $out/bin/prince
4242+4343+ mkdir -p $out/share/sdlpop
4444+ cp -r data doc mods SDLPoP.ini $out/share/sdlpop
4545+4646+ install -Dm755 data/icon.png $out/share/icons/hicolor/32x32/apps/sdlpop.png
4747+4848+ runHook postInstall
4949+ '';
5050+5151+ desktopItems = [ (makeDesktopItem {
5252+ name = "sdlpop";
5353+ icon = "sdlpop";
5454+ exec = "prince";
5555+ desktopName = "SDLPoP";
5656+ comment = "An open-source port of Prince of Persia";
5757+ categories = "Game;AdventureGame;";
5858+ }) ];
5959+6060+ meta = with lib; {
6161+ description = "Open-source port of Prince of Persia";
6262+ homepage = "https://github.com/NagyD/SDLPoP";
6363+ license = licenses.gpl3Plus;
6464+ maintainers = with maintainers; [ iblech ];
6565+ platforms = platforms.unix;
6666+ broken = stdenv.isDarwin;
6767+ };
6868+}
+16
pkgs/games/sdlpop/prince.sh
···11+#! @shell@
22+33+set -euo pipefail
44+55+mkdir -p ~/.local/share/sdlpop
66+cd ~/.local/share/sdlpop
77+88+for i in SDLPoP.ini mods; do
99+ [ -e $i ] || cp -r @out@/share/sdlpop/$i .
1010+done
1111+1212+# Create the data symlink or update it (in case it is a symlink, else the user
1313+# has probably tinkered with it and does not want it to be recreated).
1414+[ ! -e data -o -L data ] && ln -sf @out@/share/sdlpop/data .
1515+1616+exec -a "prince" @out@/bin/.prince-bin "$@"