1{ stdenv
2, lib
3, fetchFromGitHub
4, unstableGitUpdater
5, cmake
6, libiconv
7, zlib
8, enableShared ? true
9
10, enableAudio ? true
11, withWaveWrite ? true
12, withWinMM ? stdenv.hostPlatform.isWindows
13, withDirectSound ? stdenv.hostPlatform.isWindows
14, withXAudio2 ? stdenv.hostPlatform.isWindows
15, withWASAPI ? stdenv.hostPlatform.isWindows
16, withOSS ? stdenv.hostPlatform.isFreeBSD
17, withSADA ? stdenv.hostPlatform.isSunOS
18, withALSA ? stdenv.hostPlatform.isLinux
19, alsa-lib
20, withPulseAudio ? stdenv.hostPlatform.isLinux
21, libpulseaudio
22, withCoreAudio ? stdenv.hostPlatform.isDarwin
23, CoreAudio
24, AudioToolbox
25, withLibao ? true
26, libao
27
28, enableEmulation ? true
29, withAllEmulators ? true
30, emulators ? [ ]
31
32, enableLibplayer ? true
33
34, enableTools ? false
35}:
36
37assert enableTools -> enableAudio && enableEmulation && enableLibplayer;
38
39let
40 inherit (lib) optional optionals;
41 onOff = val: if val then "ON" else "OFF";
42in
43stdenv.mkDerivation rec {
44 pname = "libvgm";
45 version = "unstable-2023-04-22";
46
47 src = fetchFromGitHub {
48 owner = "ValleyBell";
49 repo = "libvgm";
50 rev = "669a7566a356393d4e5b1030a9f9cdd3486bb41b";
51 sha256 = "U/PO/YtS8bOb2yKk57UQKH4eRNysYC/hrmUR5YZyYlw=";
52 };
53
54 outputs = [
55 "out"
56 "dev"
57 ] ++ optional enableTools "bin";
58
59 nativeBuildInputs = [
60 cmake
61 ];
62
63 propagatedBuildInputs = [
64 libiconv
65 zlib
66 ] ++ optionals withALSA [
67 alsa-lib
68 ] ++ optionals withPulseAudio [
69 libpulseaudio
70 ] ++ optionals withCoreAudio [
71 CoreAudio
72 AudioToolbox
73 ] ++ optionals withLibao [
74 libao
75 ];
76
77 cmakeFlags = [
78 "-DBUILD_LIBAUDIO=${onOff enableAudio}"
79 "-DBUILD_LIBEMU=${onOff enableEmulation}"
80 "-DBUILD_LIBPLAYER=${onOff enableLibplayer}"
81 "-DBUILD_TESTS=${onOff enableTools}"
82 "-DBUILD_PLAYER=${onOff enableTools}"
83 "-DBUILD_VGM2WAV=${onOff enableTools}"
84 "-DLIBRARY_TYPE=${if enableShared then "SHARED" else "STATIC"}"
85 "-DUSE_SANITIZERS=ON"
86 ] ++ optionals enableAudio [
87 "-DAUDIODRV_WAVEWRITE=${onOff withWaveWrite}"
88 "-DAUDIODRV_WINMM=${onOff withWinMM}"
89 "-DAUDIODRV_DSOUND=${onOff withDirectSound}"
90 "-DAUDIODRV_XAUDIO2=${onOff withXAudio2}"
91 "-DAUDIODRV_WASAPI=${onOff withWASAPI}"
92 "-DAUDIODRV_OSS=${onOff withOSS}"
93 "-DAUDIODRV_SADA=${onOff withSADA}"
94 "-DAUDIODRV_ALSA=${onOff withALSA}"
95 "-DAUDIODRV_PULSE=${onOff withPulseAudio}"
96 "-DAUDIODRV_APPLE=${onOff withCoreAudio}"
97 "-DAUDIODRV_LIBAO=${onOff withLibao}"
98 ] ++ optionals enableEmulation ([
99 "-DSNDEMU__ALL=${onOff withAllEmulators}"
100 ] ++ optionals (!withAllEmulators)
101 (lib.lists.forEach emulators (x: "-DSNDEMU_${x}=ON"))
102 ) ++ optionals enableTools [
103 "-DUTIL_CHARCNV_ICONV=ON"
104 "-DUTIL_CHARCNV_WINAPI=${onOff stdenv.hostPlatform.isWindows}"
105 ];
106
107 passthru.updateScript = unstableGitUpdater {
108 url = "https://github.com/ValleyBell/libvgm.git";
109 };
110
111 meta = with lib; {
112 homepage = "https://github.com/ValleyBell/libvgm";
113 description = "More modular rewrite of most components from VGMPlay";
114 license =
115 if (enableEmulation && (withAllEmulators || (lib.lists.any (core: core == "WSWAN_ALL") emulators))) then
116 licenses.unfree # https://github.com/ValleyBell/libvgm/issues/43
117 else
118 licenses.gpl2Only;
119 maintainers = with maintainers; [ OPNA2608 ];
120 platforms = platforms.all;
121 };
122}