From d1c35db920eba34a9fefe18f8f5dc27a40aed9f6 Mon Sep 17 00:00:00 2001
From: Christoph Hrdinka <c.github@hrdinka.at>
Date: Sat, 27 Feb 2016 15:40:50 +0100
Subject: [PATCH] retrofe: init at 0.6.169

---
 pkgs/misc/emulators/retrofe/default.nix       | 79 +++++++++++++++++++
 .../emulators/retrofe/include-paths.patch     | 11 +++
 pkgs/top-level/all-packages.nix               |  2 +
 3 files changed, 92 insertions(+)
 create mode 100644 pkgs/misc/emulators/retrofe/default.nix
 create mode 100644 pkgs/misc/emulators/retrofe/include-paths.patch

diff --git a/pkgs/misc/emulators/retrofe/default.nix b/pkgs/misc/emulators/retrofe/default.nix
new file mode 100644
index 000000000000..bf3091d1d706
--- /dev/null
+++ b/pkgs/misc/emulators/retrofe/default.nix
@@ -0,0 +1,79 @@
+{ stdenv, fetchhg, cmake, dos2unix, glib, gst_all_1, makeWrapper, pkgconfig
+, python, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, sqlite, zlib
+}:
+
+let
+  gstPlugins = with gst_all_1; [ gst-libav gst-plugins-base gst-plugins-good ];
+  GST_PLUGIN_PATH = stdenv.lib.makeSearchPath "lib/gstreamer-1.0" gstPlugins;
+
+in stdenv.mkDerivation rec {
+  name = "retrofe-${version}";
+  version = "0.6.169";
+
+  src = fetchhg {
+    url = https://bitbucket.org/teamretro/retrofe;
+    rev = "8793e03";
+    sha256 = "0cvsg07ff0fdqh5zgiv2fs7s6c98hn150kpxmpw5fn6jilaszwkm";
+  };
+
+  nativeBuildInputs = [ cmake makeWrapper pkgconfig python ];
+
+  buildInputs = [
+    glib gst_all_1.gstreamer SDL2 SDL2_image SDL2_mixer SDL2_ttf sqlite zlib
+  ] ++ gstPlugins;
+
+  patches = [ ./include-paths.patch ];
+
+  configurePhase = ''
+    cmake RetroFE/Source -BRetroFE/Build -DCMAKE_BUILD_TYPE=Release \
+      -DVERSION_MAJOR=0 -DVERSION_MINOR=0 -DVERSION_BUILD=0 \
+      -DGSTREAMER_BASE_INCLUDE_DIRS='${gst_all_1.gst-plugins-base}/include/gstreamer-1.0'
+  '';
+
+  buildPhase = ''
+    cmake --build RetroFE/Build
+    python Scripts/Package.py --os=linux --build=full
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mkdir -p $out/share/retrofe
+    cp -r Artifacts/linux/RetroFE $out/share/retrofe/example
+    mv $out/share/retrofe/example/retrofe $out/bin/
+
+    cat > $out/bin/retrofe-init << EOF
+    #!/bin/sh
+
+    echo "This will install retrofe's example files into this directory"
+    echo "Example files location: $out/share/retrofe/example/"
+
+    while true; do
+        read -p "Do you want to proceed? [yn] " yn
+        case \$yn in
+            [Yy]* ) cp -r --no-preserve=all $out/share/retrofe/example/* .; break;;
+            [Nn]* ) exit;;
+            * ) echo "Please answer with yes or no.";;
+        esac
+    done
+    EOF
+
+    chmod +x $out/bin/retrofe-init
+  '';
+
+  # retrofe will look for config files in its install path ($out/bin).
+  # When set it will use $RETROFE_PATH instead. Sadly this behaviour isn't
+  # documented well. To make it behave more like as expected it's set to
+  # $PWD by default here.
+  fixupPhase = ''
+    wrapProgram "$out/bin/retrofe" \
+      --prefix GST_PLUGIN_PATH : '${GST_PLUGIN_PATH}/lib/gstreamer-1.0' \
+      --set    RETROFE_PATH      "\''${RETROFE_PATH:-\$PWD}"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A frontend for arcade cabinets and media PCs";
+    license = licenses.gpl3Plus;
+    homepage = http://retrofe.com;
+    maintainers = with maintainers; [ hrdinka ];
+  };
+}
diff --git a/pkgs/misc/emulators/retrofe/include-paths.patch b/pkgs/misc/emulators/retrofe/include-paths.patch
new file mode 100644
index 000000000000..02eef2594ea6
--- /dev/null
+++ b/pkgs/misc/emulators/retrofe/include-paths.patch
@@ -0,0 +1,11 @@
+diff -ur RetroFE.1/RetroFE/Source/CMakeLists.txt RetroFE.2/RetroFE/Source/CMakeLists.txt
+--- RetroFE.1/RetroFE/Source/CMakeLists.txt	2016-02-21 14:52:36.726070602 +0100
++++ RetroFE.2/RetroFE/Source/CMakeLists.txt	2016-02-21 14:38:43.036249029 +0100
+@@ -59,6 +59,7 @@
+ set(RETROFE_INCLUDE_DIRS
+ 	"${GLIB2_INCLUDE_DIRS}"
+ 	"${GSTREAMER_INCLUDE_DIRS}"
++	"${GSTREAMER_BASE_INCLUDE_DIRS}"
+ 	"${SDL2_INCLUDE_DIRS}"
+ 	"${SDL2_IMAGE_INCLUDE_DIRS}"
+ 	"${SDL2_MIXER_INCLUDE_DIRS}"
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 22dbfc41f438..b25da232aab1 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -15903,6 +15903,8 @@ let
     retroarch = retroarchBare;
   });
 
+  retrofe = callPackage ../misc/emulators/retrofe { };
+
   rss-glx = callPackage ../misc/screensavers/rss-glx { };
 
   runit = callPackage ../tools/system/runit { };