1{ lib, stdenv, fetchFromGitHub, autoreconfHook, autogen, pkg-config, python3
2, flac, lame, libmpg123, libogg, libopus, libvorbis
3, alsa-lib, Carbon, AudioToolbox
4
5# for passthru.tests
6, audacity
7, freeswitch
8, gst_all_1
9, libsamplerate
10, moc
11, pipewire
12, pulseaudio
13}:
14
15stdenv.mkDerivation rec {
16 pname = "libsndfile";
17 version = "1.2.2";
18
19 src = fetchFromGitHub {
20 owner = pname;
21 repo = pname;
22 rev = version;
23 hash = "sha256-MOOX/O0UaoeMaQPW9PvvE0izVp+6IoE5VbtTx0RvMkI=";
24 };
25
26 nativeBuildInputs = [ autoreconfHook autogen pkg-config python3 ];
27 buildInputs = [ flac lame libmpg123 libogg libopus libvorbis ]
28 ++ lib.optionals stdenv.isLinux [ alsa-lib ]
29 ++ lib.optionals stdenv.isDarwin [ Carbon AudioToolbox ];
30
31 enableParallelBuilding = true;
32
33 outputs = [ "bin" "dev" "out" "man" "doc" ];
34
35 # need headers from the Carbon.framework in /System/Library/Frameworks to
36 # compile this on darwin -- not sure how to handle
37 preConfigure = lib.optionalString stdenv.isDarwin
38 ''
39 NIX_CFLAGS_COMPILE+=" -I$SDKROOT/System/Library/Frameworks/Carbon.framework/Versions/A/Headers"
40 '';
41
42 # Needed on Darwin.
43 NIX_CFLAGS_LINK = "-logg -lvorbis";
44
45 doCheck = true;
46 preCheck = ''
47 patchShebangs tests/test_wrapper.sh tests/pedantic-header-test.sh
48
49 substituteInPlace tests/test_wrapper.sh \
50 --replace '/usr/bin/env' "$(type -P env)"
51 '';
52
53 passthru.tests = {
54 inherit
55 audacity
56 freeswitch
57 libsamplerate
58 moc
59 pipewire
60 pulseaudio;
61 inherit (python3.pkgs)
62 soundfile
63 wavefile;
64 inherit (gst_all_1) gst-plugins-bad;
65 lame = (lame.override { sndfileFileIOSupport = true; });
66 };
67
68 meta = with lib; {
69 description = "C library for reading and writing files containing sampled sound";
70 homepage = "https://libsndfile.github.io/libsndfile/";
71 changelog = "https://github.com/libsndfile/libsndfile/releases/tag/${version}";
72 license = licenses.lgpl2Plus;
73 maintainers = with maintainers; [ lovek323 ];
74 platforms = platforms.unix;
75
76 longDescription = ''
77 Libsndfile is a C library for reading and writing files containing
78 sampled sound (such as MS Windows WAV and the Apple/SGI AIFF format)
79 through one standard library interface. It is released in source
80 code format under the GNU Lesser General Public License.
81
82 The library was written to compile and run on a Linux system but
83 should compile and run on just about any Unix (including macOS).
84 There are also pre-compiled binaries available for 32 and 64 bit
85 windows.
86
87 It was designed to handle both little-endian (such as WAV) and
88 big-endian (such as AIFF) data, and to compile and run correctly on
89 little-endian (such as Intel and DEC/Compaq Alpha) processor systems
90 as well as big-endian processor systems such as Motorola 68k, Power
91 PC, MIPS and SPARC. Hopefully the design of the library will also
92 make it easy to extend for reading and writing new sound file
93 formats.
94 '';
95 };
96}