2019-05-28 20:52:34 +02:00
|
|
|
{ stdenv, config, fetchurl, pkgconfig
|
|
|
|
, libGLSupported ? stdenv.lib.elem stdenv.hostPlatform.system stdenv.lib.platforms.mesaPlatforms
|
2018-11-05 12:55:08 +01:00
|
|
|
, openglSupport ? libGLSupported, libGL
|
2019-02-22 16:36:48 +01:00
|
|
|
, alsaSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid, alsaLib
|
|
|
|
, x11Support ? !stdenv.isCygwin && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libX11, xorgproto, libICE, libXi, libXScrnSaver, libXcursor
|
|
|
|
, libXinerama, libXext, libXxf86vm, libXrandr
|
|
|
|
, waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, wayland, wayland-protocols, libxkbcommon
|
|
|
|
, dbusSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid, dbus
|
2016-08-22 05:24:32 +02:00
|
|
|
, udevSupport ? false, udev
|
|
|
|
, ibusSupport ? false, ibus
|
2019-05-06 05:51:09 +02:00
|
|
|
, fcitxSupport ? false, fcitx
|
2019-02-22 16:36:48 +01:00
|
|
|
, pulseaudioSupport ? config.pulseaudio or stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libpulseaudio
|
2015-10-28 20:34:57 +01:00
|
|
|
, AudioUnit, Cocoa, CoreAudio, CoreServices, ForceFeedback, OpenGL
|
2019-06-19 20:30:21 +02:00
|
|
|
, audiofile, libiconv
|
2013-07-02 23:06:05 +02:00
|
|
|
}:
|
|
|
|
|
2018-03-05 18:30:34 +01:00
|
|
|
# NOTE: When editing this expression see if the same change applies to
|
|
|
|
# SDL expression too
|
|
|
|
|
2018-11-05 12:55:08 +01:00
|
|
|
with stdenv.lib;
|
2013-07-02 23:06:05 +02:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "SDL2";
|
2019-08-18 18:13:29 +02:00
|
|
|
version = "2.0.10";
|
2013-07-02 23:06:05 +02:00
|
|
|
|
|
|
|
src = fetchurl {
|
2019-08-15 14:41:18 +02:00
|
|
|
url = "https://www.libsdl.org/release/${pname}-${version}.tar.gz";
|
2019-08-18 18:13:29 +02:00
|
|
|
sha256 = "0mqxp6w5jhbq6y1j690g9r3gpzwjxh4czaglw8x05l7hl49nqrdl";
|
2013-07-02 23:06:05 +02:00
|
|
|
};
|
|
|
|
|
2016-12-25 02:11:07 +01:00
|
|
|
outputs = [ "out" "dev" ];
|
2018-03-05 18:30:34 +01:00
|
|
|
outputBin = "dev"; # sdl-config
|
2016-12-25 02:11:07 +01:00
|
|
|
|
2016-08-22 05:24:32 +02:00
|
|
|
patches = [ ./find-headers.patch ];
|
|
|
|
|
2019-10-09 20:41:59 +02:00
|
|
|
# Fix with mesa 19.2: https://bugzilla.libsdl.org/show_bug.cgi?id=4797
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace include/SDL_opengl_glext.h \
|
|
|
|
--replace "typedef ptrdiff_t GLsizeiptr;" "typedef signed long int khronos_ssize_t; typedef khronos_ssize_t GLsizeiptr;" \
|
|
|
|
--replace "typedef ptrdiff_t GLintptr;" "typedef signed long int khronos_intptr_t; typedef khronos_intptr_t GLintptr;"
|
|
|
|
'';
|
|
|
|
|
2018-12-09 23:55:10 +01:00
|
|
|
nativeBuildInputs = [ pkgconfig ];
|
2016-08-22 05:24:32 +02:00
|
|
|
|
2018-06-11 00:29:24 +02:00
|
|
|
propagatedBuildInputs = dlopenPropagatedBuildInputs;
|
|
|
|
|
|
|
|
dlopenPropagatedBuildInputs = [ ]
|
|
|
|
# Propagated for #include <GLES/gl.h> in SDL_opengles.h.
|
|
|
|
++ optional openglSupport libGL
|
|
|
|
# Propagated for #include <X11/Xlib.h> and <X11/Xatom.h> in SDL_syswm.h.
|
2018-12-31 04:40:47 +01:00
|
|
|
++ optionals x11Support [ libX11 xorgproto ];
|
2018-06-11 00:29:24 +02:00
|
|
|
|
|
|
|
dlopenBuildInputs = [ ]
|
2019-02-22 16:36:48 +01:00
|
|
|
++ optionals alsaSupport [ alsaLib audiofile ]
|
2018-03-05 21:12:44 +01:00
|
|
|
++ optional dbusSupport dbus
|
2018-06-11 00:29:24 +02:00
|
|
|
++ optional pulseaudioSupport libpulseaudio
|
2018-03-05 21:12:44 +01:00
|
|
|
++ optional udevSupport udev
|
2018-03-05 18:30:34 +01:00
|
|
|
++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
|
2018-06-11 00:29:24 +02:00
|
|
|
++ optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ];
|
2013-07-02 23:06:05 +02:00
|
|
|
|
2019-02-22 16:36:48 +01:00
|
|
|
buildInputs = [ libiconv ]
|
2018-06-11 00:29:24 +02:00
|
|
|
++ dlopenBuildInputs
|
2018-03-05 21:12:44 +01:00
|
|
|
++ optional ibusSupport ibus
|
2019-05-06 05:51:09 +02:00
|
|
|
++ optional fcitxSupport fcitx
|
2019-06-19 20:30:21 +02:00
|
|
|
++ optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
|
2013-11-06 23:17:46 +01:00
|
|
|
|
2018-11-13 17:41:39 +01:00
|
|
|
enableParallelBuilding = true;
|
2017-02-16 22:24:40 +01:00
|
|
|
|
2018-05-10 18:31:03 +02:00
|
|
|
configureFlags = [
|
|
|
|
"--disable-oss"
|
|
|
|
] ++ optional (!x11Support) "--without-x"
|
2018-06-07 01:18:00 +02:00
|
|
|
++ optional alsaSupport "--with-alsa-prefix=${alsaLib.out}/lib"
|
|
|
|
++ optional stdenv.isDarwin "--disable-sdltest";
|
2013-07-02 23:06:05 +02:00
|
|
|
|
2019-11-03 18:36:28 +01:00
|
|
|
# We remove libtool .la files when static libs are requested,
|
|
|
|
# because they make the builds of downstream libs like `SDL_tff`
|
|
|
|
# fail with `cannot find -lXext, `-lXcursor` etc. linker errors
|
|
|
|
# because the `.la` files are not pruned if static libs exist
|
|
|
|
# (see https://github.com/NixOS/nixpkgs/commit/fd97db43bcb05e37f6bb77f363f1e1e239d9de53)
|
|
|
|
# and they also don't carry the necessary `-L` paths of their
|
|
|
|
# X11 dependencies.
|
|
|
|
# For static linking, it is better to rely on `pkg-config` `.pc`
|
|
|
|
# files.
|
2013-11-06 23:17:46 +01:00
|
|
|
postInstall = ''
|
2019-11-03 18:36:28 +01:00
|
|
|
if [ "$dontDisableStatic" -eq "1" ]; then
|
|
|
|
rm $out/lib/*.la
|
|
|
|
else
|
|
|
|
rm $out/lib/*.a
|
|
|
|
fi
|
2016-12-25 02:11:07 +01:00
|
|
|
moveToOutput bin/sdl2-config "$dev"
|
2013-11-06 23:17:46 +01:00
|
|
|
'';
|
|
|
|
|
2018-03-05 21:12:44 +01:00
|
|
|
# SDL is weird in that instead of just dynamically linking with
|
|
|
|
# libraries when you `--enable-*` (or when `configure` finds) them
|
|
|
|
# it `dlopen`s them at runtime. In principle, this means it can
|
|
|
|
# ignore any missing optional dependencies like alsa, pulseaudio,
|
|
|
|
# some x11 libs, wayland, etc if they are missing on the system
|
|
|
|
# and/or work with wide array of versions of said libraries. In
|
|
|
|
# nixpkgs, however, we don't need any of that. Moreover, since we
|
|
|
|
# don't have a global ld-cache we have to stuff all the propagated
|
|
|
|
# libraries into rpath by hand or else some applications that use
|
|
|
|
# SDL API that requires said libraries will fail to start.
|
|
|
|
#
|
|
|
|
# You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
|
2018-06-11 00:29:24 +02:00
|
|
|
# list the symbols used in this way.
|
|
|
|
postFixup = let
|
|
|
|
rpath = makeLibraryPath (dlopenPropagatedBuildInputs ++ dlopenBuildInputs);
|
|
|
|
in optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so") ''
|
2018-03-05 21:12:44 +01:00
|
|
|
for lib in $out/lib/*.so* ; do
|
2018-06-11 00:25:33 +02:00
|
|
|
if ! [[ -L "$lib" ]]; then
|
2018-06-11 00:29:24 +02:00
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
|
2018-03-05 21:12:44 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2016-08-22 05:24:32 +02:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
passthru = { inherit openglSupport; };
|
2013-07-02 23:06:05 +02:00
|
|
|
|
2016-08-22 05:24:32 +02:00
|
|
|
meta = with stdenv.lib; {
|
2013-07-02 23:06:05 +02:00
|
|
|
description = "A cross-platform multimedia library";
|
2017-08-01 22:03:30 +02:00
|
|
|
homepage = http://www.libsdl.org/;
|
2016-08-22 05:24:32 +02:00
|
|
|
license = licenses.zlib;
|
|
|
|
platforms = platforms.all;
|
2017-01-20 12:23:57 +01:00
|
|
|
maintainers = with maintainers; [ cpages ];
|
2013-07-02 23:06:05 +02:00
|
|
|
};
|
|
|
|
}
|