about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/zx/zxtune/package.nix
blob: 436a241533662e4f9e716efe8294af01c7a4be2b (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
136
137
138
139
140
141
142
143
144
145
146
147
148
{ lib
, stdenv
, fetchFromBitbucket
, nix-update-script
, boost
, zlib
# File backends (for decoding and encoding)
, withMp3 ? true
, lame
, withOgg ? true
, libvorbis
, withFlac ? true
, flac
# Audio backends (for playback)
, withOpenal ? false
, openal
, withSDL ? false
, SDL
, withOss ? false
, withAlsa ? stdenv.hostPlatform.isLinux
, alsa-lib
, withPulse ? stdenv.hostPlatform.isLinux
, libpulseaudio
# GUI audio player
, withQt ? true
, qt5
, zip
}:
let
  dlopenBuildInputs = []
    ++ lib.optional withMp3 lame
    ++ lib.optional withOgg libvorbis
    ++ lib.optional withFlac flac
    ++ lib.optional withOpenal openal
    ++ lib.optional withSDL SDL
    ++ lib.optional withAlsa alsa-lib
    ++ lib.optional withPulse libpulseaudio;
  supportWayland = (!stdenv.hostPlatform.isDarwin);
  platformName = "linux";
  staticBuildInputs = [ boost zlib ]
    ++ lib.optional withQt (if (supportWayland) then qt5.qtwayland else qt5.qtbase);
in stdenv.mkDerivation rec {
  pname = "zxtune";
  version = "5056";

  outputs = [ "out" ];

  src = fetchFromBitbucket {
    owner = "zxtune";
    repo = "zxtune";
    rev = "r${version}";
    hash = "sha256-zvLbgS8AFW4kkvTccGXcr1KEw3EH47XcHwzq6CKzusQ=";
  };

  passthru.updateScript = nix-update-script {
    extraArgs = [ "--version-regex" "r([0-9]+)" ];
  };

  strictDeps = true;

  nativeBuildInputs = lib.optionals withQt [ zip qt5.wrapQtAppsHook ];

  buildInputs = staticBuildInputs ++ dlopenBuildInputs;

  patches = [
    ./disable_updates.patch
  ];

  # Fix use of old OpenAL header path
  postPatch = ''
    substituteInPlace src/sound/backends/gates/openal_api.h \
      --replace "#include <OpenAL/" "#include <AL/"
  '';

  buildPhase = let
    setOptionalSupport = name: var:
      "support_${name}=" + (if (var) then "1" else "");
    makeOptsCommon = [
      ''-j$NIX_BUILD_CORES''
      ''root.version=${src.rev}''
      ''system.zlib=1''
      ''platform=${platformName}''
      ''includes.dirs.${platformName}="${lib.makeSearchPathOutput "dev" "include" buildInputs}"''
      ''libraries.dirs.${platformName}="${lib.makeLibraryPath staticBuildInputs}"''
      ''ld_flags="-Wl,-rpath=\"${lib.makeLibraryPath dlopenBuildInputs}\""''
      (setOptionalSupport "mp3" withMp3)
      (setOptionalSupport "ogg" withOgg)
      (setOptionalSupport "flac" withFlac)
      (setOptionalSupport "openal" withOpenal)
      (setOptionalSupport "sdl" withSDL)
      (setOptionalSupport "oss" withOss)
      (setOptionalSupport "alsa" withAlsa)
      (setOptionalSupport "pulseaudio" withPulse)
    ];
    makeOptsQt = [
      ''tools.uic=${qt5.qtbase.dev}/bin/uic''
      ''tools.moc=${qt5.qtbase.dev}/bin/moc''
      ''tools.rcc=${qt5.qtbase.dev}/bin/rcc''
    ];
  in ''
    runHook preBuild
    make ${builtins.toString makeOptsCommon} -C apps/xtractor
    make ${builtins.toString makeOptsCommon} -C apps/zxtune123
  '' + lib.optionalString withQt ''
    make ${builtins.toString (makeOptsCommon ++ makeOptsQt)} -C apps/zxtune-qt
  '' + ''
    runHook postBuild
  '';

  # Libs from dlopenBuildInputs are found with dlopen. Do not shrink rpath. Can
  # check output of 'out/bin/zxtune123 --list-backends' to verify all plugins
  # load ("Status: Available" or "Status: Failed to load dynamic library...").
  dontPatchELF = true;

  installPhase = ''
    runHook preInstall
    install -Dm755 bin/linux/release/xtractor -t $out/bin
    install -Dm755 bin/linux/release/zxtune123 -t $out/bin
  '' + lib.optionalString withQt ''
    install -Dm755 bin/linux/release/zxtune-qt -t $out/bin
  '' + ''
    runHook postInstall
  '';

  # Only wrap the gui
  dontWrapQtApps = true;
  preFixup = lib.optionalString withQt ''
    wrapQtApp "$out/bin/zxtune-qt"
  '';

  meta = with lib; {
    description = "Crossplatform chiptunes player";
    longDescription = ''
      Chiptune music player with truly extensive format support. Supported
      formats/chips include AY/YM, ZX Spectrum, PC, Amiga, Atari, Acorn, Philips
      SAA1099, MOS6581 (Commodore 64), NES, SNES, GameBoy, Atari, TurboGrafX,
      Nintendo DS, Sega Master System, and more. Powered by vgmstream, OpenMPT,
      sidplay, and many other libraries.
    '';
    homepage = "https://zxtune.bitbucket.io/";
    license = licenses.gpl3;
    # zxtune supports mac and windows, but more work will be needed to
    # integrate with the custom make system (see platformName above)
    platforms = platforms.linux;
    maintainers = with maintainers; [ EBADBEEF ];
    mainProgram = if withQt then "zxtune-qt" else "zxtune123";
  };
}