about summary refs log tree commit diff
path: root/nixpkgs/pkgs/games/sdlpop
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-04-28 14:39:00 +0000
committerAlyssa Ross <hi@alyssa.is>2021-06-10 08:52:36 +0000
commit693e64ef7421374338ddb1dc12b9573feec75972 (patch)
tree2526ac075d248699c35d63e04499890ee4381f5f /nixpkgs/pkgs/games/sdlpop
parent7014df2256694d97093d6f2bb1db340d346dea88 (diff)
parent8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17 (diff)
downloadnixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.gz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.bz2
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.lz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.xz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.zst
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.zip
Merge commit '8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17'
Diffstat (limited to 'nixpkgs/pkgs/games/sdlpop')
-rw-r--r--nixpkgs/pkgs/games/sdlpop/default.nix68
-rw-r--r--nixpkgs/pkgs/games/sdlpop/prince.sh16
2 files changed, 84 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/games/sdlpop/default.nix b/nixpkgs/pkgs/games/sdlpop/default.nix
new file mode 100644
index 000000000000..cef321fdce4e
--- /dev/null
+++ b/nixpkgs/pkgs/games/sdlpop/default.nix
@@ -0,0 +1,68 @@
+{ lib, stdenv
+, makeWrapper
+, makeDesktopItem, copyDesktopItems
+, fetchFromGitHub
+, pkg-config
+, SDL2, SDL2_image
+}:
+
+stdenv.mkDerivation rec {
+  pname = "sdlpop";
+  version = "1.21";
+
+  src = fetchFromGitHub {
+    owner = "NagyD";
+    repo = "SDLPoP";
+    rev = "v${version}";
+    sha256 = "1q4mnyg8v4420f1bp24v8lgi335vijdv61yi3fan14jgfzl38l7w";
+  };
+
+  nativeBuildInputs = [ pkg-config makeWrapper copyDesktopItems ];
+  buildInputs = [ SDL2 SDL2_image ];
+
+  makeFlags = [ "-C" "src" ];
+
+  preBuild = ''
+    substituteInPlace src/Makefile --replace "CC = gcc" "CC = ${stdenv.cc.targetPrefix}gcc"
+  '';
+
+  # The prince binary expects two things of the working directory it is called from:
+  # (1) There is a subdirectory "data" containing the level data.
+  # (2) The working directory is writable, so save and quicksave files can be created.
+  # Our solution is to ensure that ~/.local/share/sdlpop is the working
+  # directory, symlinking the data files into it. This is the task of the
+  # prince.sh wrapper.
+
+  installPhase = ''
+    runHook preInstall
+
+    install -Dm755 prince $out/bin/.prince-bin
+    substituteAll ${./prince.sh} $out/bin/prince
+    chmod +x $out/bin/prince
+
+    mkdir -p $out/share/sdlpop
+    cp -r data doc mods SDLPoP.ini $out/share/sdlpop
+
+    install -Dm755 data/icon.png $out/share/icons/hicolor/32x32/apps/sdlpop.png
+
+    runHook postInstall
+  '';
+
+  desktopItems = [ (makeDesktopItem {
+    name = "sdlpop";
+    icon = "sdlpop";
+    exec = "prince";
+    desktopName = "SDLPoP";
+    comment = "An open-source port of Prince of Persia";
+    categories = "Game;AdventureGame;";
+  }) ];
+
+  meta = with lib; {
+    description = "Open-source port of Prince of Persia";
+    homepage = "https://github.com/NagyD/SDLPoP";
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ iblech ];
+    platforms = platforms.unix;
+    broken = stdenv.isDarwin;
+  };
+}
diff --git a/nixpkgs/pkgs/games/sdlpop/prince.sh b/nixpkgs/pkgs/games/sdlpop/prince.sh
new file mode 100644
index 000000000000..698c347272a4
--- /dev/null
+++ b/nixpkgs/pkgs/games/sdlpop/prince.sh
@@ -0,0 +1,16 @@
+#! @shell@
+
+set -euo pipefail
+
+mkdir -p ~/.local/share/sdlpop
+cd ~/.local/share/sdlpop
+
+for i in SDLPoP.ini mods; do
+  [ -e $i ] || cp -r @out@/share/sdlpop/$i .
+done
+
+# Create the data symlink or update it (in case it is a symlink, else the user
+# has probably tinkered with it and does not want it to be recreated).
+[ ! -e data -o -L data ] && ln -sf @out@/share/sdlpop/data .
+
+exec -a "prince" @out@/bin/.prince-bin "$@"