1{ stdenv, lib, fetchurl, pkgconfig, audiofile
2, openglSupport ? false, libGL
3, alsaSupport ? true, alsaLib
4, x11Support ? true, libICE, libXi, libXScrnSaver, libXcursor, libXinerama, libXext, libXxf86vm, libXrandr
5, waylandSupport ? true, wayland, wayland-protocols, libxkbcommon
6, dbusSupport ? false, dbus
7, udevSupport ? false, udev
8, ibusSupport ? false, ibus
9, pulseaudioSupport ? true, libpulseaudio
10, AudioUnit, Cocoa, CoreAudio, CoreServices, ForceFeedback, OpenGL
11, libiconv
12}:
13
14# OSS is no longer supported, for it's much crappier than ALSA and
15# PulseAudio.
16assert !stdenv.isDarwin -> alsaSupport || pulseaudioSupport;
17
18assert openglSupport -> (stdenv.isDarwin || libGL != null && x11Support);
19
20let
21 configureFlagsFun = attrs: [
22 "--disable-oss" "--disable-x11-shared" "--disable-wayland-shared"
23 "--disable-pulseaudio-shared" "--disable-alsa-shared"
24 ] ++ lib.optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib"
25 ++ lib.optional (!x11Support) "--without-x";
26in
27stdenv.mkDerivation rec {
28 name = "SDL2-${version}";
29 version = "2.0.7";
30
31 src = fetchurl {
32 url = "http://www.libsdl.org/release/${name}.tar.gz";
33 sha256 = "0pjdpxla5kh1w1b0shxrx97a116vyy31njxi0jhyvqhk8d6cfdgf";
34 };
35
36 outputs = [ "out" "dev" ];
37
38 patches = [ ./find-headers.patch ];
39
40 nativeBuildInputs = [ pkgconfig ];
41
42 # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
43 propagatedBuildInputs = lib.optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ] ++
44 lib.optionals waylandSupport [ wayland wayland-protocols libxkbcommon ] ++
45 lib.optional pulseaudioSupport libpulseaudio
46 ++ [ libiconv ];
47
48 buildInputs = [ audiofile ] ++
49 lib.optional openglSupport libGL ++
50 lib.optional alsaSupport alsaLib ++
51 lib.optional dbusSupport dbus ++
52 lib.optional udevSupport udev ++
53 lib.optional ibusSupport ibus ++
54 lib.optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
55
56 # https://bugzilla.libsdl.org/show_bug.cgi?id=1431
57 dontDisableStatic = true;
58
59 # /build/SDL2-2.0.7/src/video/wayland/SDL_waylandevents.c:41:10: fatal error:
60 # pointer-constraints-unstable-v1-client-protocol.h: No such file or directory
61 enableParallelBuilding = false;
62
63 # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
64 # we must arrange to add it to its RPATH; however, `patchelf' seems
65 # to fail at doing this, hence `--disable-pulseaudio-shared'.
66 configureFlags = configureFlagsFun { inherit alsaLib; };
67
68 crossAttrs = {
69 configureFlags = configureFlagsFun { alsaLib = alsaLib.crossDrv; };
70 };
71
72 postInstall = ''
73 moveToOutput lib/libSDL2main.a "$dev"
74 rm $out/lib/*.a
75 moveToOutput bin/sdl2-config "$dev"
76 '';
77
78 setupHook = ./setup-hook.sh;
79
80 passthru = { inherit openglSupport; };
81
82 meta = with stdenv.lib; {
83 description = "A cross-platform multimedia library";
84 homepage = http://www.libsdl.org/;
85 license = licenses.zlib;
86 platforms = platforms.all;
87 maintainers = with maintainers; [ cpages ];
88 };
89}