summary refs log tree commit diff
path: root/pkgs/misc/emulators/higan/default.nix
blob: e735bdb38eed470df257aab454556d3faac2a78f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{ stdenv, fetchFromGitHub
, pkgconfig
, libX11, libXv
, udev
, libGLU, libGL, SDL2
, libao, openal, libpulseaudio
, alsaLib
, gtk2, gtksourceview
, runtimeShell
# Darwin dependencies
, libicns, Carbon, Cocoa, OpenGL, OpenAL}:

let
  inherit (stdenv.lib) optionals;
in
stdenv.mkDerivation rec {

  pname = "higan";
  version = "110";

  src = fetchFromGitHub {
    owner = "higan-emu";
    repo = "higan";
    rev = "v${version}";
    sha256 = "11rvm53c3p2f6zk8xbyv2j51xp8zmqnch7zravhj3fk590qrjrr2";
  };

  patches = [ ./0001-change-flags.diff ];
  postPatch = ''
    sed '1i#include <cmath>' -i higan/fc/ppu/ppu.cpp

    for file in icarus/GNUmakefile higan/target-higan/GNUmakefile; do
      substituteInPlace "$file" \
        --replace 'sips -s format icns data/$(name).png --out out/$(name).app/Contents/Resources/$(name).icns' \
                  'png2icns out/$(name).app/Contents/Resources/$(name).icns data/$(name).png'
    done
  '';

  nativeBuildInputs = [ pkgconfig ]
    ++ optionals stdenv.isDarwin [ libicns ];

  buildInputs = [ SDL2 libao ]
                ++ optionals stdenv.isLinux [ alsaLib udev libpulseaudio openal
                                              gtk2 gtksourceview libX11 libXv
                                              libGLU libGL ]
                ++ optionals stdenv.isDarwin [ Carbon Cocoa OpenGL OpenAL ];

  buildPhase = ''
    make compiler=c++ -C higan openmp=true target=higan
    make compiler=c++ -C genius openmp=true
    make compiler=c++ -C icarus openmp=true
  '';

  installPhase = (if stdenv.isDarwin then ''
    mkdir "$out"
    mv higan/out/higan.app "$out"/
    mv icarus/out/icarus.app "$out"/
    mv genius/out/genius.app "$out"/
  '' else ''
    install -dm 755 "$out"/bin "$out"/share/applications "$out"/share/pixmaps

    install -m 755 higan/out/higan -t "$out"/bin/
    install -m 644 higan/target-higan/resource/higan.desktop \
            -t $out/share/applications/
    install -m 644 higan/target-higan/resource/higan.svg \
            $out/share/pixmaps/higan-icon.svg
    install -m 644 higan/target-higan/resource/higan.png \
            $out/share/pixmaps/higan-icon.png

    install -m 755 icarus/out/icarus -t "$out"/bin/
    install -m 644 icarus/data/icarus.desktop -t $out/share/applications/
    install -m 644 icarus/data/icarus.svg $out/share/pixmaps/icarus-icon.svg
    install -m 644 icarus/data/icarus.png $out/share/pixmaps/icarus-icon.png

    install -m 755 genius/out/genius -t "$out"/bin/
    install -m 644 genius/data/genius.desktop -t $out/share/applications/
    install -m 644 genius/data/genius.svg $out/share/pixmaps/genius-icon.svg
    install -m 644 genius/data/genius.png $out/share/pixmaps/genius-icon.png
  '') + ''
    mkdir -p "$out"/share/higan "$out"/share/icarus
    cp --recursive --no-dereference --preserve='links' --no-preserve='ownership' \
      higan/System/ "$out"/share/higan/
    cp --recursive --no-dereference --preserve='links' --no-preserve='ownership' \
      icarus/Database icarus/Firmware $out/share/icarus/
  '';

  fixupPhase = let
    dest = if stdenv.isDarwin
           then "\\$HOME/Library/Application Support/higan"
           else "\\$HOME/higan";
  in ''
    # A dirty workaround, suggested by @cpages:
    # we create a first-run script to populate
    # $HOME with all the stuff needed at runtime

    mkdir -p "$out"/bin
    cat <<EOF > $out/bin/higan-init.sh
    #!${runtimeShell}

    cp --recursive --update $out/share/higan/System/ "${dest}"/

    EOF

    chmod +x $out/bin/higan-init.sh
  '';

  meta = with stdenv.lib; {
    description = "An open-source, cycle-accurate multi-system emulator";
    longDescription = ''
      higan is a multi-system game console emulator. The purpose of higan is to
      serve as hardware documentation in source code form: it is meant to be as
      accurate and complete as possible, with code that is easy to read and
      understand.

      It currently supports the following systems:
      - Famicom + Famicom Disk System
      - Super Famicom + Super Game Boy
      - Game Boy + Game Boy Color
      - Game Boy Advance + Game Boy Player
      - SG-1000 + SC-3000
      - Master System + Game Gear
      - Mega Drive + Mega CD
      - PC Engine + SuperGrafx
      - MSX + MSX2
      - ColecoVision
      - Neo Geo Pocket + Neo Geo Pocket Color
      - WonderSwan + WonderSwan Color + SwanCrystal + Pocket Challenge V2
    '';
    homepage = "https://byuu.org/higan/";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [ AndersonTorres ];
    platforms = platforms.unix;
  };
}
# TODO: Qt and GTK3+ support