@@ -21,14 +21,10 @@ assert openglSupport -> (stdenv.isDarwin || x11Support && libGL != null);
2121
2222let
2323
24− # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
25− # we must arrange to add it to its RPATH; however, `patchelf' seems
26− # to fail at doing this, hence `--disable-pulseaudio-shared'.
2724 configureFlagsFun = attrs: [
28− "--disable-oss" "--disable-x11-shared" "--disable-wayland-shared"
29− "--disable-pulseaudio-shared" "--disable-alsa-shared"
30− ] ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib"
31− ++ optional (!x11Support) "--without-x";
25+ "--disable-oss"
26+ ] ++ optional (!x11Support) "--without-x"
27+ ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib";
3228
3329in
3430
@@ -48,18 +44,17 @@ stdenv.mkDerivation rec {
4844
4945 nativeBuildInputs = [ pkgconfig ];
5046
51− # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
5247 propagatedBuildInputs = [ libiconv ]
48+ ++ optional dbusSupport dbus
49+ ++ optional udevSupport udev
5350 ++ optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ]
5451 ++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
52+ ++ optional alsaSupport alsaLib
5553 ++ optional pulseaudioSupport libpulseaudio;
5654
5755 buildInputs = [ audiofile ]
58− ++ optional openglSupport libGL
59− ++ optional alsaSupport alsaLib
60− ++ optional dbusSupport dbus
61− ++ optional udevSupport udev
62− ++ optional ibusSupport ibus
56+ ++ optional openglSupport libGL
57+ ++ optional ibusSupport ibus
6358 ++ optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
6459
6560 # https://bugzilla.libsdl.org/show_bug.cgi?id=1431
@@ -81,6 +76,28 @@ stdenv.mkDerivation rec {
8176 moveToOutput bin/sdl2-config "$dev"
8277 '';
8378
79+ # SDL is weird in that instead of just dynamically linking with
80+ # libraries when you `--enable-*` (or when `configure` finds) them
81+ # it `dlopen`s them at runtime. In principle, this means it can
82+ # ignore any missing optional dependencies like alsa, pulseaudio,
83+ # some x11 libs, wayland, etc if they are missing on the system
84+ # and/or work with wide array of versions of said libraries. In
85+ # nixpkgs, however, we don't need any of that. Moreover, since we
86+ # don't have a global ld-cache we have to stuff all the propagated
87+ # libraries into rpath by hand or else some applications that use
88+ # SDL API that requires said libraries will fail to start.
89+ #
90+ # You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
91+ # confirm that they actually use most of the `propagatedBuildInputs`
92+ # from above in this way. This is pretty weird.
93+ postFixup = ''
94+ for lib in $out/lib/*.so* ; do
95+ if [[ -L "$lib" ]]; then
96+ patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath propagatedBuildInputs}" "$lib"
97+ fi
98+ done
99+ '';
100+
84101 setupHook = ./setup-hook.sh;
85102
86103 passthru = { inherit openglSupport; };