summaryrefslogtreecommitdiff
path: root/pkgs/by-name/fu/furnace/package.nix
blob: 1ca6761b33c28436141db596c4823972c511e053 (about) (plain)
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
136
137
138
139
140
141
{
  stdenv,
  lib,
  testers,
  furnace,
  fetchFromGitHub,
  cmake,
  pkg-config,
  makeWrapper,
  fftw,
  fmt,
  freetype,
  libsndfile,
  libX11,
  libGL,
  rtmidi,
  SDL2,
  zlib,
  withJACK ? stdenv.hostPlatform.isUnix,
  libjack2,
  withGUI ? true,
  darwin,
  portaudio,
  alsa-lib,
  # Enable GL/GLES rendering
  withGL ? !stdenv.hostPlatform.isDarwin,
  # Use GLES instead of GL, some platforms have better support for one than the other
  preferGLES ? stdenv.hostPlatform.isAarch,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "furnace";
  version = "0.6.8.1";

  src = fetchFromGitHub {
    owner = "tildearrow";
    repo = "furnace";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-R4yQqTPVNx5i9AeY06T0QdNN22ImLvD0bH96r5ojPLo=";
  };

  postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
    # To offer scaling detection on X11, furnace checks if libX11.so is available via dlopen and uses some of its functions
    # But it's being linked against a versioned libX11.so.VERSION via SDL, so the unversioned one is not on the rpath
    substituteInPlace src/gui/scaling.cpp \
      --replace-fail 'libX11.so' '${lib.getLib libX11}/lib/libX11.so'
  '';

  nativeBuildInputs =
    [
      cmake
      pkg-config
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      makeWrapper
    ];

  buildInputs =
    [
      fftw
      fmt
      freetype
      libsndfile
      rtmidi
      SDL2
      zlib
      portaudio
    ]
    ++ lib.optionals withGL [
      libGL
    ]
    ++ lib.optionals withJACK [
      libjack2
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      # portaudio pkg-config is pulling this in as a link dependency, not set in propagatedBuildInputs
      alsa-lib
      libX11
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin (
      with darwin.apple_sdk.frameworks;
      [
        Cocoa
      ]
    );

  cmakeFlags = [
    (lib.cmakeBool "BUILD_GUI" withGUI)
    (lib.cmakeBool "SYSTEM_FFTW" true)
    (lib.cmakeBool "SYSTEM_FMT" true)
    (lib.cmakeBool "SYSTEM_LIBSNDFILE" true)
    (lib.cmakeBool "SYSTEM_RTMIDI" true)
    (lib.cmakeBool "SYSTEM_SDL2" true)
    (lib.cmakeBool "SYSTEM_ZLIB" true)
    (lib.cmakeBool "USE_FREETYPE" true)
    (lib.cmakeBool "SYSTEM_FREETYPE" true)
    (lib.cmakeBool "WITH_JACK" withJACK)
    (lib.cmakeBool "WITH_PORTAUDIO" true)
    (lib.cmakeBool "SYSTEM_PORTAUDIO" true)
    (lib.cmakeBool "WITH_RENDER_SDL" true)
    (lib.cmakeBool "WITH_RENDER_OPENGL" withGL)
    (lib.cmakeBool "USE_GLES" (withGL && preferGLES))
    (lib.cmakeBool "WITH_RENDER_METAL" false) # fails to build
    (lib.cmakeBool "WITH_RENDER_OPENGL1" (withGL && !preferGLES))
    (lib.cmakeBool "FORCE_APPLE_BIN" true)
  ];

  postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    # Normal CMake install phase on Darwin only installs the binary, the user is expected to use CPack to build a
    # bundle. That adds alot of overhead for not much benefit (CPack is currently abit broken, and needs impure access
    # to /usr/bin/hdiutil). So we'll manually assemble & install everything instead.

    mkdir -p $out/{Applications/Furnace.app/Contents/{MacOS,Resources},share/{,doc,licenses}/furnace}
    mv $out/{bin,Applications/Furnace.app/Contents/MacOS}/furnace
    makeWrapper $out/{Applications/Furnace.app/Contents/MacOS,bin}/furnace

    install -m644 {../res,$out/Applications/Furnace.app/Contents}/Info.plist
    install -m644 ../res/icon.icns $out/Applications/Furnace.app/Contents/Resources/Furnace.icns
    install -m644 {..,$out/share/licenses/furnace}/LICENSE
    cp -r ../papers $out/share/doc/furnace/
    cp -r ../demos $out/share/furnace/
  '';

  passthru = {
    updateScript = ./update.sh;
    tests.version = testers.testVersion {
      package = furnace;
    };
  };

  meta = {
    description = "Multi-system chiptune tracker compatible with DefleMask modules";
    homepage = "https://github.com/tildearrow/furnace";
    changelog = "https://github.com/tildearrow/furnace/releases/tag/v${finalAttrs.version}";
    license = with lib.licenses; [ gpl2Plus ];
    maintainers = with lib.maintainers; [ OPNA2608 ];
    platforms = lib.platforms.all;
    mainProgram = "furnace";
  };
})