@@ -1,4 +1,4 @@
1−{ stdenv, fetchurl, fetchpatch, pkgconfig, audiofile, libcap, libiconv
1+{ stdenv, lib, fetchurl, fetchpatch, pkgconfig, audiofile, libcap, libiconv
22, openglSupport ? false, libGL, libGLU
33, alsaSupport ? true, alsaLib
44, x11Support ? hostPlatform == buildPlatform, libXext, libICE, libXrandr
@@ -7,13 +7,32 @@
77, hostPlatform, buildPlatform
88}:
99
10−# OSS is no longer supported, for it's much crappier than ALSA and
11−# PulseAudio.
12−assert hostPlatform.isLinux -> alsaSupport || pulseaudioSupport;
10+# NOTE: When editing this expression see if the same change applies to
11+# SDL2 expression too
12+
13+with lib;
14+
15+assert !stdenv.isDarwin -> alsaSupport || pulseaudioSupport;
16+assert openglSupport -> (stdenv.isDarwin || x11Support && libGL != null && libGLU != null);
1317
1418let
15− inherit (stdenv.lib) optional optionals;
19+
20+ configureFlagsFun = attrs: [
21+ "--disable-oss"
22+ "--disable-video-x11-xme"
23+ "--enable-rpath"
24+ # Building without this fails on Darwin with
25+ #
26+ # ./src/video/x11/SDL_x11sym.h:168:17: error: conflicting types for '_XData32'
27+ # SDL_X11_SYM(int,_XData32,(Display *dpy,register long *data,unsigned len),(dpy,data,len),return)
28+ #
29+ # Please try revert the change that introduced this comment when updating SDL.
30+ ] ++ optional stdenv.isDarwin "--disable-x11-shared"
31+ ++ optional (!x11Support) "--without-x"
32+ ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib";
33+
1634in
35+
1736stdenv.mkDerivation rec {
1837 name = "SDL-${version}";
1938 version = "1.2.15";
@@ -28,36 +47,28 @@ stdenv.mkDerivation rec {
2847
2948 nativeBuildInputs = [ pkgconfig ];
3049
31− # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
32− propagatedBuildInputs =
33− optionals x11Support [ libXext libICE libXrandr ] ++
34− optional alsaSupport alsaLib ++
35− optional stdenv.isLinux libcap ++
36− optionals openglSupport [ libGL libGLU ] ++
37− optional pulseaudioSupport libpulseaudio ++
38− optional stdenv.isDarwin Cocoa;
39−
40− buildInputs = let
41− notMingw = !hostPlatform.isMinGW;
42− in optional notMingw audiofile
43− ++ optionals stdenv.isDarwin [ OpenGL CoreAudio CoreServices AudioUnit Kernel ]
44− ++ [ libiconv ];
45−
46− # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
47− # we must arrange to add it to its RPATH; however, `patchelf' seems
48− # to fail at doing this, hence `--disable-pulseaudio-shared'.
49− configureFlags = [
50− "--disable-oss"
51− "--disable-video-x11-xme"
52− "--disable-x11-shared"
53− "--disable-alsa-shared"
54− "--enable-rpath"
55− "--disable-pulseaudio-shared"
56− "--disable-osmesa-shared"
57− ] ++ optional (!x11Support) "--without-x"
58− ++ optional (alsaSupport && hostPlatform != buildPlatform) "--with-alsa-prefix=${alsaLib.out}/lib";
50+ propagatedBuildInputs = [ ]
51+ ++ optionals (x11Support && !stdenv.isDarwin) [ libXext libICE libXrandr ]
52+ ++ optional stdenv.isLinux libcap
53+ ++ optionals openglSupport [ libGL libGLU ]
54+ ++ optional alsaSupport alsaLib
55+ ++ optional pulseaudioSupport libpulseaudio
56+ ++ optional stdenv.isDarwin Cocoa;
57+
58+ buildInputs = [ libiconv ]
59+ ++ optionals (x11Support && stdenv.isDarwin) [ libXext libICE libXrandr ]
60+ ++ optional (!hostPlatform.isMinGW) audiofile
61+ ++ optionals stdenv.isDarwin [ AudioUnit CoreAudio CoreServices Kernel OpenGL ];
62+
63+ configureFlags = configureFlagsFun { inherit alsaLib; };
64+
65+ crossAttrs = {
66+ configureFlags = configureFlagsFun { alsaLib = alsaLib.crossDrv; };
67+ };
5968
6069 patches = [
70+ ./find-headers.patch
71+
6172 # Fix window resizing issues, e.g. for xmonad
6273 # Ticket: http://bugzilla.libsdl.org/show_bug.cgi?id=1430
6374 (fetchpatch {
@@ -75,6 +86,11 @@ stdenv.mkDerivation rec {
7586 url = "http://hg.libsdl.org/SDL/raw-rev/95abff7adcc2";
7687 sha256 = "0i8x0kx0pw12ld5bfxhyzs466y3c0n9dscw1ijhq1b96r72xyhqq";
7788 })
89+ # https://bugzilla.libsdl.org/show_bug.cgi?id=1769
90+ (fetchpatch {
91+ url = "http://hg.libsdl.org/SDL/raw-rev/91ad7b43317a";
92+ sha256 = "15g537vbl2my4mfrjxfkcx9ri6bk2gjvaqj650rjdxwk2nkdkn4b";
93+ })
7894 # Workaround X11 bug to allow changing gamma
7995 # Ticket: https://bugs.freedesktop.org/show_bug.cgi?id=27222
8096 (fetchpatch {
@@ -92,10 +108,20 @@ stdenv.mkDerivation rec {
92108 url = "http://hg.libsdl.org/SDL/raw-rev/bbfb41c13a87";
93109 sha256 = "1336g7waaf1c8yhkz11xbs500h8bmvabh4h437ax8l1xdwcppfxv";
94110 })
95− ./find-headers.patch
96111 ];
97112
98− postFixup = ''moveToOutput share/aclocal "$dev" '';
113+ postInstall = ''
114+ moveToOutput share/aclocal "$dev"
115+ '';
116+
117+ # See the same place in the expression for SDL2
118+ postFixup = ''
119+ for lib in $out/lib/*.so* ; do
120+ if [[ -L "$lib" ]]; then
121+ patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath propagatedBuildInputs}" "$lib"
122+ fi
123+ done
124+ '';
99125
100126 setupHook = ./setup-hook.sh;
101127