19 , alsaSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid
20 , libGLSupported ? lib.meta.availableOn stdenv.hostPlatform libGL
21 , openglSupport ? libGLSupported
22 , pulseaudioSupport ? config.pulseaudio or stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid && lib.meta.availableOn stdenv.hostPlatform libpulseaudio
23 , x11Support ? !stdenv.hostPlatform.isCygwin && !stdenv.hostPlatform.isAndroid
26 # NOTE: When editing this expression see if the same change applies to
30 inherit (darwin.apple_sdk.frameworks) OpenGL CoreAudio CoreServices AudioUnit Kernel Cocoa GLUT;
31 extraPropagatedBuildInputs = [ ]
32 ++ lib.optionals x11Support [ libXext libICE libXrandr ]
33 ++ lib.optionals (openglSupport && stdenv.hostPlatform.isLinux) [ libGL ]
34 # libGLU doesn’t work with Android's SDL
35 ++ lib.optionals (openglSupport && stdenv.hostPlatform.isLinux && (!stdenv.hostPlatform.isAndroid)) [ libGLU ]
36 ++ lib.optionals (openglSupport && stdenv.hostPlatform.isDarwin) [ OpenGL GLUT ]
37 ++ lib.optional alsaSupport alsa-lib
38 ++ lib.optional pulseaudioSupport libpulseaudio
39 ++ lib.optional stdenv.hostPlatform.isDarwin Cocoa;
41 stdenv.mkDerivation (finalAttrs: {
46 url = "https://www.libsdl.org/release/SDL-${finalAttrs.version}.tar.gz";
47 hash = "sha256-1tMWp5Pl40gVXw3ZO5eXmJM/uYqh7evMEIgp1kdKrQA=";
50 outputs = [ "out" "dev" ];
51 outputBin = "dev"; # sdl-config
53 nativeBuildInputs = [ pkg-config ]
54 ++ lib.optional stdenv.hostPlatform.isLinux libcap;
56 propagatedBuildInputs = [ libiconv ] ++ extraPropagatedBuildInputs;
60 ++ lib.optionals (!stdenv.hostPlatform.isMinGW && alsaSupport) [ audiofile ]
61 ++ lib.optionals stdenv.hostPlatform.isDarwin [ AudioUnit CoreAudio CoreServices Kernel OpenGL ];
65 "--disable-video-x11-xme"
67 # Building without this fails on Darwin with
69 # ./src/video/x11/SDL_x11sym.h:168:17: error: conflicting types for '_XData32'
70 # SDL_X11_SYM(int,_XData32,(Display *dpy,register long *data,unsigned len),(dpy,data,len),return)
72 # Please try revert the change that introduced this comment when updating SDL.
73 ] ++ lib.optional stdenv.hostPlatform.isDarwin "--disable-x11-shared"
74 ++ lib.optional (!x11Support) "--without-x"
75 ++ lib.optional alsaSupport "--with-alsa-prefix=${alsa-lib.out}/lib"
76 ++ lib.optional stdenv.hostPlatform.isMusl "CFLAGS=-DICONV_INBUF_NONCONST";
81 # Fix window resizing issues, e.g. for xmonad
82 # Ticket: http://bugzilla.libsdl.org/show_bug.cgi?id=1430
84 name = "fix_window_resizing.diff";
85 url = "https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=10;filename=fix_window_resizing.diff;att=2;bug=665779";
86 hash = "sha256-hj3ykyOKeDh6uPDlvwNHSowQxmR+mfhvCnHvcdhXZfw=";
88 # Fix drops of keyboard events for SDL_EnableUNICODE
90 url = "https://github.com/libsdl-org/SDL-1.2/commit/0332e2bb18dc68d6892c3b653b2547afe323854b.patch";
91 hash = "sha256-5V6K0oTN56RRi48XLPQsjgLzt0a6GsjajDrda3ZEhTw=";
93 # Ignore insane joystick axis events
95 url = "https://github.com/libsdl-org/SDL-1.2/commit/ab99cc82b0a898ad528d46fa128b649a220a94f4.patch";
96 hash = "sha256-8CvKHvkmidm4tFCWYhxE059hN3gwOKz6nKs5rvQ4ZKw=";
98 # https://bugzilla.libsdl.org/show_bug.cgi?id=1769
100 url = "https://github.com/libsdl-org/SDL-1.2/commit/5d79977ec7a6b58afa6e4817035aaaba186f7e9f.patch";
101 hash = "sha256-t+60bC4gLFbslXm1n9nimiFrho2DnxdWdKr4H9Yp/sw=";
103 # Workaround X11 bug to allow changing gamma
104 # Ticket: https://bugs.freedesktop.org/show_bug.cgi?id=27222
106 name = "SDL_SetGamma.patch";
107 url = "https://src.fedoraproject.org/rpms/SDL/raw/7a07323e5cec08bea6f390526f86a1ce5341596d/f/SDL-1.2.15-x11-Bypass-SetGammaRamp-when-changing-gamma.patch";
108 hash = "sha256-m7ZQ5GnfGlMkKJkrBSB3GrLz8MT6njgI9jROJAbRonQ=";
110 # Fix a build failure on OS X Mavericks
111 # Ticket: https://bugzilla.libsdl.org/show_bug.cgi?id=2085
113 url = "https://github.com/libsdl-org/SDL-1.2/commit/19039324be71738d8990e91b9ba341b2ea068445.patch";
114 hash = "sha256-DCWZo0LzHJoWUr/5vL5pKIEmmz3pvr4TO6Ip8WykfDI=";
117 url = "https://github.com/libsdl-org/SDL-1.2/commit/7933032ad4d57c24f2230db29f67eb7d21bb5654.patch";
118 hash = "sha256-Knq+ceL6y/zKcfJayC2gy+DKnoa8DLslBNl3laMzwa8=";
121 name = "CVE-2022-34568.patch";
122 url = "https://github.com/libsdl-org/SDL-1.2/commit/d7e00208738a0bc6af302723fe64908ac35b777b.patch";
123 hash = "sha256-fuxXsqZW94/C8CKu9LakppCU4zHupj66O2MngQ4BO9o=";
127 enableParallelBuilding = true;
130 moveToOutput share/aclocal "$dev"
133 # See the same place in the expression for SDL2
135 rpath = lib.makeLibraryPath extraPropagatedBuildInputs;
137 for lib in $out/lib/*.so* ; do
138 if [[ -L "$lib" ]]; then
139 patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
144 setupHook = ./setup-hook.sh;
146 passthru = { inherit openglSupport; };
149 homepage = "http://www.libsdl.org/";
150 description = "Cross-platform multimedia library";
151 license = lib.licenses.lgpl21;
152 mainProgram = "sdl-config";
153 maintainers = lib.teams.sdl.members ++ (with lib.maintainers; [ lovek323 ]);
154 platforms = lib.platforms.unix;