btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / hi / higan / package.nix
blob3eb9a9a310ecf1d288bc90faf58496ceade4d122
1 { lib
2 , SDL2
3 , alsa-lib
4 , darwin
5 , fetchFromGitHub
6 , gtk3
7 , gtksourceview3
8 , libGL
9 , libGLU
10 , libX11
11 , libXv
12 , libao
13 , libicns
14 , libpulseaudio
15 , openal
16 , pkg-config
17 , runtimeShell
18 , stdenv
19 , udev
20 , unstableGitUpdater
23 stdenv.mkDerivation (finalAttrs: {
24   pname = "higan";
25   version = "115-unstable-2024-02-17";
27   src = fetchFromGitHub {
28     owner = "higan-emu";
29     repo = "higan";
30     rev = "ba4b918c0bbcc302e0d5d2ed70f2c56214d62681";
31     hash = "sha256-M8WaPrOPSRKxhYcf6ffNkDzITkCltNF9c/zl0GmfJrI=";
32   };
34   nativeBuildInputs = [
35     pkg-config
36   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
37     libicns
38   ];
40   buildInputs = [
41     SDL2
42     libao
43   ] ++ lib.optionals stdenv.hostPlatform.isLinux [
44     alsa-lib
45     gtk3
46     gtksourceview3
47     libGL
48     libGLU
49     libX11
50     libXv
51     libpulseaudio
52     openal
53     udev
54   ]
55   ++ lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
56     Carbon
57     Cocoa
58     OpenAL
59     OpenGL
60   ]);
62   patches = [
63     # Includes cmath header
64     ./001-include-cmath.patch
65     # Uses png2icns instead of sips
66     ./002-sips-to-png2icns.patch
67   ];
69   dontConfigure = true;
71   enableParallelBuilding = true;
73   buildPhase = let
74     platform =
75       if stdenv.hostPlatform.isLinux
76       then "linux"
77       else if stdenv.hostPlatform.isDarwin
78       then "macos"
79       else if stdenv.hostPlatform.isBSD
80       then "bsd"
81       else if stdenv.hostPlatform.isWindows
82       then "windows"
83       else throw "Unknown platform for higan: ${stdenv.hostPlatform.system}";
84   in ''
85     runHook preBuild
87     make -C higan-ui -j$NIX_BUILD_CORES \
88       compiler=${stdenv.cc.targetPrefix}c++ \
89       platform=${platform} \
90       openmp=true \
91       hiro=gtk3 \
92       build=accuracy \
93       local=false \
94       cores="cv fc gb gba md ms msx ngp pce sfc sg ws"
96     make -C icarus -j$NIX_BUILD_CORES \
97       compiler=${stdenv.cc.targetPrefix}c++ \
98       platform=${platform} \
99       openmp=true \
100       hiro=gtk3
102     runHook postBuild
103   '';
105   installPhase = ''
106     runHook preInstall
108   '' + (if stdenv.hostPlatform.isDarwin then ''
109     mkdir ${placeholder "out"}
110     mv higan/out/higan.app ${placeholder "out"}/
111     mv icarus/out/icarus.app ${placeholder "out"}/
112   '' else ''
113     install -d ${placeholder "out"}/bin
114     install higan-ui/out/higan -t ${placeholder "out"}/bin/
115     install icarus/out/icarus -t ${placeholder "out"}/bin/
117     install -d ${placeholder "out"}/share/applications
118     install higan-ui/resource/higan.desktop -t ${placeholder "out"}/share/applications/
119     install icarus/resource/icarus.desktop -t ${placeholder "out"}/share/applications/
121     install -d ${placeholder "out"}/share/pixmaps
122     install higan/higan/resource/higan.svg ${placeholder "out"}/share/pixmaps/higan-icon.svg
123     install higan/higan/resource/logo.png ${placeholder "out"}/share/pixmaps/higan-icon.png
124     install icarus/resource/icarus.svg ${placeholder "out"}/share/pixmaps/icarus-icon.svg
125     install icarus/resource/icarus.png ${placeholder "out"}/share/pixmaps/icarus-icon.png
126   '') + ''
127     install -d ${placeholder "out"}/share/higan
128     cp -rd extras/ higan/System/ ${placeholder "out"}/share/higan/
130     install -d ${placeholder "out"}/share/icarus
131     cp -rd icarus/Database icarus/Firmware ${placeholder "out"}/share/icarus/
132   '' + (
133     # A dirty workaround, suggested by @cpages:
134     # we create a first-run script to populate
135     # $HOME with all the stuff needed at runtime
136     let
137       dest = if stdenv.hostPlatform.isDarwin
138            then "\\$HOME/Library/Application Support/higan"
139            else "\\$HOME/higan";
140     in ''
141     mkdir -p ${placeholder "out"}/bin
142     cat <<EOF > ${placeholder "out"}/bin/higan-init.sh
143     #!${runtimeShell}
145     cp --recursive --update ${placeholder "out"}/share/higan/System/ "${dest}"/
147     EOF
149     chmod +x ${placeholder "out"}/bin/higan-init.sh
150   '') + ''
152     runHook postInstall
153   '';
155   passthru.updateScript = unstableGitUpdater {};
157   meta = with lib; {
158     homepage = "https://github.com/higan-emu/higan";
159     description = "Open-source, cycle-accurate multi-system emulator";
160     longDescription = ''
161       higan is a multi-system emulator, originally developed by Near, with an
162       uncompromising focus on accuracy and code readability.
164       It currently emulates the following systems: Famicom, Famicom Disk System,
165       Super Famicom, Super Game Boy, Game Boy, Game Boy Color, Game Boy Advance,
166       Game Boy Player, SG-1000, SC-3000, Master System, Game Gear, Mega Drive,
167       Mega CD, PC Engine, SuperGrafx, MSX, MSX2, ColecoVision, Neo Geo Pocket,
168       Neo Geo Pocket Color, WonderSwan, WonderSwan Color, SwanCrystal, Pocket
169       Challenge V2.
170     '';
171     license = licenses.gpl3Plus;
172     maintainers = with maintainers; [ AndersonTorres ];
173     platforms = platforms.unix;
174     broken = stdenv.hostPlatform.isDarwin;
175   };
177 # TODO: select between Qt and GTK3