2016-08-22 04:24:32 +01:00
|
|
|
{ stdenv, lib, fetchurl, pkgconfig, audiofile
|
2018-02-24 12:06:44 +00:00
|
|
|
, openglSupport ? false, libGL
|
2016-08-22 04:24:32 +01:00
|
|
|
, alsaSupport ? true, alsaLib
|
|
|
|
, x11Support ? true, libICE, libXi, libXScrnSaver, libXcursor, libXinerama, libXext, libXxf86vm, libXrandr
|
2017-11-01 06:36:56 +00:00
|
|
|
, waylandSupport ? true, wayland, wayland-protocols, libxkbcommon
|
2016-08-22 04:24:32 +01:00
|
|
|
, dbusSupport ? false, dbus
|
|
|
|
, udevSupport ? false, udev
|
|
|
|
, ibusSupport ? false, ibus
|
|
|
|
, pulseaudioSupport ? true, libpulseaudio
|
2015-10-28 19:34:57 +00:00
|
|
|
, AudioUnit, Cocoa, CoreAudio, CoreServices, ForceFeedback, OpenGL
|
2017-05-28 19:52:30 +01:00
|
|
|
, libiconv
|
2013-07-02 22:06:05 +01:00
|
|
|
}:
|
|
|
|
|
2018-03-05 17:30:34 +00:00
|
|
|
# NOTE: When editing this expression see if the same change applies to
|
|
|
|
# SDL expression too
|
|
|
|
|
|
|
|
with lib;
|
2013-07-02 22:06:05 +01:00
|
|
|
|
2018-03-05 17:30:34 +00:00
|
|
|
assert !stdenv.isDarwin -> alsaSupport || pulseaudioSupport;
|
|
|
|
assert openglSupport -> (stdenv.isDarwin || x11Support && libGL != null);
|
2013-07-02 22:06:05 +01:00
|
|
|
|
|
|
|
let
|
2018-03-05 17:30:34 +00:00
|
|
|
|
2016-08-22 04:24:32 +01:00
|
|
|
configureFlagsFun = attrs: [
|
2018-03-05 20:12:44 +00:00
|
|
|
"--disable-oss"
|
|
|
|
] ++ optional (!x11Support) "--without-x"
|
|
|
|
++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib";
|
2018-03-05 17:30:34 +00:00
|
|
|
|
2013-07-02 22:06:05 +01:00
|
|
|
in
|
2018-03-05 17:30:34 +00:00
|
|
|
|
2013-07-02 22:06:05 +01:00
|
|
|
stdenv.mkDerivation rec {
|
2016-08-22 04:24:32 +01:00
|
|
|
name = "SDL2-${version}";
|
2018-03-06 10:23:29 +00:00
|
|
|
version = "2.0.8";
|
2013-07-02 22:06:05 +01:00
|
|
|
|
|
|
|
src = fetchurl {
|
2013-08-27 22:34:49 +01:00
|
|
|
url = "http://www.libsdl.org/release/${name}.tar.gz";
|
2018-03-06 10:23:29 +00:00
|
|
|
sha256 = "1v4js1gkr75hzbxzhwzzif0sf9g07234sd23x1vdaqc661bprizd";
|
2013-07-02 22:06:05 +01:00
|
|
|
};
|
|
|
|
|
2016-12-25 01:11:07 +00:00
|
|
|
outputs = [ "out" "dev" ];
|
2018-03-05 17:30:34 +00:00
|
|
|
outputBin = "dev"; # sdl-config
|
2016-12-25 01:11:07 +00:00
|
|
|
|
2016-08-22 04:24:32 +01:00
|
|
|
patches = [ ./find-headers.patch ];
|
|
|
|
|
|
|
|
nativeBuildInputs = [ pkgconfig ];
|
|
|
|
|
2018-03-05 17:30:34 +00:00
|
|
|
propagatedBuildInputs = [ libiconv ]
|
2018-03-05 20:12:44 +00:00
|
|
|
++ optional dbusSupport dbus
|
|
|
|
++ optional udevSupport udev
|
2018-03-05 17:30:34 +00:00
|
|
|
++ optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ]
|
|
|
|
++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
|
2018-03-05 20:12:44 +00:00
|
|
|
++ optional alsaSupport alsaLib
|
2018-03-05 17:30:34 +00:00
|
|
|
++ optional pulseaudioSupport libpulseaudio;
|
2013-07-02 22:06:05 +01:00
|
|
|
|
2018-03-05 17:30:34 +00:00
|
|
|
buildInputs = [ audiofile ]
|
2018-03-05 20:12:44 +00:00
|
|
|
++ optional openglSupport libGL
|
|
|
|
++ optional ibusSupport ibus
|
2018-03-05 17:30:34 +00:00
|
|
|
++ optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
|
2013-11-06 22:17:46 +00:00
|
|
|
|
2017-11-12 08:47:30 +00:00
|
|
|
# /build/SDL2-2.0.7/src/video/wayland/SDL_waylandevents.c:41:10: fatal error:
|
|
|
|
# pointer-constraints-unstable-v1-client-protocol.h: No such file or directory
|
|
|
|
enableParallelBuilding = false;
|
2017-02-16 21:24:40 +00:00
|
|
|
|
2013-07-02 22:06:05 +01:00
|
|
|
configureFlags = configureFlagsFun { inherit alsaLib; };
|
|
|
|
|
|
|
|
crossAttrs = {
|
2016-08-22 04:24:32 +01:00
|
|
|
configureFlags = configureFlagsFun { alsaLib = alsaLib.crossDrv; };
|
2013-07-02 22:06:05 +01:00
|
|
|
};
|
|
|
|
|
2013-11-06 22:17:46 +00:00
|
|
|
postInstall = ''
|
2017-02-16 21:24:40 +00:00
|
|
|
moveToOutput lib/libSDL2main.a "$dev"
|
2013-11-06 22:17:46 +00:00
|
|
|
rm $out/lib/*.a
|
2016-12-25 01:11:07 +00:00
|
|
|
moveToOutput bin/sdl2-config "$dev"
|
2013-11-06 22:17:46 +00:00
|
|
|
'';
|
|
|
|
|
2018-03-05 20:12:44 +00: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
|
|
|
|
# confirm that they actually use most of the `propagatedBuildInputs`
|
|
|
|
# from above in this way. This is pretty weird.
|
|
|
|
postFixup = ''
|
|
|
|
for lib in $out/lib/*.so* ; do
|
|
|
|
if [[ -L "$lib" ]]; then
|
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath propagatedBuildInputs}" "$lib"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2016-08-22 04:24:32 +01:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
passthru = { inherit openglSupport; };
|
2013-07-02 22:06:05 +01:00
|
|
|
|
2016-08-22 04:24:32 +01:00
|
|
|
meta = with stdenv.lib; {
|
2013-07-02 22:06:05 +01:00
|
|
|
description = "A cross-platform multimedia library";
|
2017-08-01 21:03:30 +01:00
|
|
|
homepage = http://www.libsdl.org/;
|
2016-08-22 04:24:32 +01:00
|
|
|
license = licenses.zlib;
|
|
|
|
platforms = platforms.all;
|
2017-01-20 11:23:57 +00:00
|
|
|
maintainers = with maintainers; [ cpages ];
|
2013-07-02 22:06:05 +01:00
|
|
|
};
|
|
|
|
}
|