forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / by-name / sd / SDL1 / package.nix
blobbd793b5885bb344de1e4ba525f62d6959d4bfa70
1 { lib
2 , alsa-lib
3 , audiofile
4 , config
5 , darwin
6 , fetchpatch
7 , fetchurl
8 , libGL
9 , libGLU
10 , libICE
11 , libXext
12 , libXrandr
13 , libcap
14 , libiconv
15 , libpulseaudio
16 , pkg-config
17 , stdenv
18 # Boolean flags
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
27 # SDL2 expression too
29 let
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: {
42   pname = "SDL";
43   version = "1.2.15";
45   src = fetchurl {
46     url = "https://www.libsdl.org/release/SDL-${finalAttrs.version}.tar.gz";
47     hash = "sha256-1tMWp5Pl40gVXw3ZO5eXmJM/uYqh7evMEIgp1kdKrQA=";
48   };
50   outputs = [ "out" "dev" ];
51   outputBin = "dev"; # sdl-config
53   nativeBuildInputs = [ pkg-config ]
54     ++ lib.optional stdenv.hostPlatform.isLinux libcap;
56   propagatedBuildInputs = [ libiconv ] ++ extraPropagatedBuildInputs;
58   buildInputs =
59     [ ]
60     ++ lib.optionals (!stdenv.hostPlatform.isMinGW && alsaSupport) [ audiofile ]
61     ++ lib.optionals stdenv.hostPlatform.isDarwin [ AudioUnit CoreAudio CoreServices Kernel OpenGL ];
63   configureFlags = [
64     "--disable-oss"
65     "--disable-video-x11-xme"
66     "--enable-rpath"
67   # Building without this fails on Darwin with
68   #
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)
71   #
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";
78   patches = [
79     ./find-headers.patch
81     # Fix window resizing issues, e.g. for xmonad
82     # Ticket: http://bugzilla.libsdl.org/show_bug.cgi?id=1430
83     (fetchpatch {
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=";
87     })
88     # Fix drops of keyboard events for SDL_EnableUNICODE
89     (fetchpatch {
90       url = "https://github.com/libsdl-org/SDL-1.2/commit/0332e2bb18dc68d6892c3b653b2547afe323854b.patch";
91       hash = "sha256-5V6K0oTN56RRi48XLPQsjgLzt0a6GsjajDrda3ZEhTw=";
92     })
93     # Ignore insane joystick axis events
94     (fetchpatch {
95       url = "https://github.com/libsdl-org/SDL-1.2/commit/ab99cc82b0a898ad528d46fa128b649a220a94f4.patch";
96       hash = "sha256-8CvKHvkmidm4tFCWYhxE059hN3gwOKz6nKs5rvQ4ZKw=";
97     })
98     # https://bugzilla.libsdl.org/show_bug.cgi?id=1769
99     (fetchpatch {
100       url = "https://github.com/libsdl-org/SDL-1.2/commit/5d79977ec7a6b58afa6e4817035aaaba186f7e9f.patch";
101       hash = "sha256-t+60bC4gLFbslXm1n9nimiFrho2DnxdWdKr4H9Yp/sw=";
102     })
103     # Workaround X11 bug to allow changing gamma
104     # Ticket: https://bugs.freedesktop.org/show_bug.cgi?id=27222
105     (fetchpatch {
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=";
109     })
110     # Fix a build failure on OS X Mavericks
111     # Ticket: https://bugzilla.libsdl.org/show_bug.cgi?id=2085
112     (fetchpatch {
113       url = "https://github.com/libsdl-org/SDL-1.2/commit/19039324be71738d8990e91b9ba341b2ea068445.patch";
114       hash = "sha256-DCWZo0LzHJoWUr/5vL5pKIEmmz3pvr4TO6Ip8WykfDI=";
115     })
116     (fetchpatch {
117       url = "https://github.com/libsdl-org/SDL-1.2/commit/7933032ad4d57c24f2230db29f67eb7d21bb5654.patch";
118       hash = "sha256-Knq+ceL6y/zKcfJayC2gy+DKnoa8DLslBNl3laMzwa8=";
119     })
120     (fetchpatch {
121       name = "CVE-2022-34568.patch";
122       url = "https://github.com/libsdl-org/SDL-1.2/commit/d7e00208738a0bc6af302723fe64908ac35b777b.patch";
123       hash = "sha256-fuxXsqZW94/C8CKu9LakppCU4zHupj66O2MngQ4BO9o=";
124     })
125   ];
127   enableParallelBuilding = true;
129   postInstall = ''
130     moveToOutput share/aclocal "$dev"
131   '';
133   # See the same place in the expression for SDL2
134   postFixup = let
135     rpath = lib.makeLibraryPath extraPropagatedBuildInputs;
136   in ''
137     for lib in $out/lib/*.so* ; do
138       if [[ -L "$lib" ]]; then
139         patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
140       fi
141     done
142   '';
144   setupHook = ./setup-hook.sh;
146   passthru = { inherit openglSupport; };
148   meta = {
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;
155   };