2021-10-29 11:47:45 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, config
|
|
|
|
, fetchurl
|
|
|
|
, pkg-config
|
2021-01-23 17:15:07 +00:00
|
|
|
, libGLSupported ? lib.elem stdenv.hostPlatform.system lib.platforms.mesaPlatforms
|
2021-10-29 11:47:45 +00:00
|
|
|
, openglSupport ? libGLSupported
|
|
|
|
, libGL
|
|
|
|
, alsaSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, alsa-lib
|
2021-04-21 01:31:11 +00:00
|
|
|
, x11Support ? !stdenv.targetPlatform.isWindows && !stdenv.hostPlatform.isAndroid
|
2021-10-29 11:47:45 +00:00
|
|
|
, libX11
|
|
|
|
, xorgproto
|
|
|
|
, libICE
|
|
|
|
, libXi
|
|
|
|
, libXScrnSaver
|
|
|
|
, libXcursor
|
|
|
|
, libXinerama
|
|
|
|
, libXext
|
|
|
|
, libXxf86vm
|
|
|
|
, libXrandr
|
2019-02-22 15:36:48 +00:00
|
|
|
, waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
2021-10-29 11:47:45 +00:00
|
|
|
, wayland
|
|
|
|
, wayland-protocols
|
|
|
|
, libxkbcommon
|
|
|
|
, dbusSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, dbus
|
|
|
|
, udevSupport ? false
|
|
|
|
, udev
|
|
|
|
, ibusSupport ? false
|
|
|
|
, ibus
|
|
|
|
, fcitxSupport ? false
|
|
|
|
, fcitx
|
2021-10-29 12:36:54 +00:00
|
|
|
, libdecorSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libdecor
|
|
|
|
, pipewireSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, pipewire # NOTE: must be built with SDL2 without pipewire support
|
2019-02-22 15:36:48 +00:00
|
|
|
, pulseaudioSupport ? config.pulseaudio or stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libpulseaudio
|
2021-10-29 11:47:45 +00:00
|
|
|
, AudioUnit
|
|
|
|
, Cocoa
|
|
|
|
, CoreAudio
|
|
|
|
, CoreServices
|
|
|
|
, ForceFeedback
|
|
|
|
, OpenGL
|
|
|
|
, audiofile
|
|
|
|
, libiconv
|
2020-05-21 09:33:17 +00:00
|
|
|
, withStatic ? false
|
2013-07-02 21:06:05 +00:00
|
|
|
}:
|
|
|
|
|
2018-03-05 17:30:34 +00:00
|
|
|
# NOTE: When editing this expression see if the same change applies to
|
|
|
|
# SDL expression too
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
with lib;
|
2013-07-02 21:06:05 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 12:41:18 +00:00
|
|
|
pname = "SDL2";
|
2021-10-29 11:47:10 +00:00
|
|
|
version = "2.0.20";
|
2013-07-02 21:06:05 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2019-08-15 12:41:18 +00:00
|
|
|
url = "https://www.libsdl.org/release/${pname}-${version}.tar.gz";
|
2021-10-29 11:47:10 +00:00
|
|
|
sha256 = "sha256-xWq6HXtbDn6Znkp2mMcLY6M5T/lwS19uHFfgwW8E3QY=";
|
2013-07-02 21:06:05 +00:00
|
|
|
};
|
2020-05-21 09:33:17 +00:00
|
|
|
dontDisableStatic = withStatic;
|
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
|
|
|
|
2022-03-12 14:12:25 +00:00
|
|
|
patches = [
|
|
|
|
# `sdl2-config --cflags` from Nixpkgs returns include path to just SDL2.
|
|
|
|
# On a normal distro this is enough for includes from all SDL2* packages to work,
|
|
|
|
# but on NixOS they're spread across different paths.
|
|
|
|
# This patch + the setup-hook will ensure that `sdl2-config --cflags` works correctly.
|
|
|
|
./find-headers.patch
|
|
|
|
];
|
|
|
|
|
2021-01-19 06:50:56 +00:00
|
|
|
depsBuildBuild = [ pkg-config ];
|
2020-06-25 00:40:00 +00:00
|
|
|
|
2021-01-19 06:50:56 +00:00
|
|
|
nativeBuildInputs = [ pkg-config ] ++ optionals waylandSupport [ wayland ];
|
2016-08-22 03:24:32 +00:00
|
|
|
|
2018-06-10 22:29:24 +00: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 03:40:47 +00:00
|
|
|
++ optionals x11Support [ libX11 xorgproto ];
|
2018-06-10 22:29:24 +00:00
|
|
|
|
2021-10-29 11:47:45 +00:00
|
|
|
dlopenBuildInputs = optionals alsaSupport [ alsa-lib audiofile ]
|
|
|
|
++ optional dbusSupport dbus
|
2021-10-29 12:36:54 +00:00
|
|
|
++ optional libdecorSupport libdecor
|
|
|
|
++ optional pipewireSupport pipewire
|
2021-10-29 11:47:45 +00:00
|
|
|
++ optional pulseaudioSupport libpulseaudio
|
|
|
|
++ optional udevSupport udev
|
2018-03-05 17:30:34 +00:00
|
|
|
++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
|
2018-06-10 22:29:24 +00:00
|
|
|
++ optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ];
|
2013-07-02 21:06:05 +00:00
|
|
|
|
2019-02-22 15:36:48 +00:00
|
|
|
buildInputs = [ libiconv ]
|
2018-06-10 22:29:24 +00:00
|
|
|
++ dlopenBuildInputs
|
2021-10-29 11:47:45 +00:00
|
|
|
++ optional ibusSupport ibus
|
|
|
|
++ optional fcitxSupport fcitx
|
2019-06-19 18:30:21 +00:00
|
|
|
++ optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
|
2013-11-06 22:17:46 +00:00
|
|
|
|
2018-11-13 16:41:39 +00:00
|
|
|
enableParallelBuilding = true;
|
2017-02-16 21:24:40 +00:00
|
|
|
|
2018-05-10 16:31:03 +00:00
|
|
|
configureFlags = [
|
|
|
|
"--disable-oss"
|
|
|
|
] ++ optional (!x11Support) "--without-x"
|
2021-10-29 11:47:45 +00:00
|
|
|
++ optional alsaSupport "--with-alsa-prefix=${alsa-lib.out}/lib"
|
|
|
|
++ optional stdenv.targetPlatform.isWindows "--disable-video-opengles"
|
|
|
|
++ optional stdenv.isDarwin "--disable-sdltest";
|
2013-07-02 21:06:05 +00:00
|
|
|
|
2019-11-03 17:36:28 +00: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 22:17:46 +00:00
|
|
|
postInstall = ''
|
2019-11-03 17:36:28 +00:00
|
|
|
if [ "$dontDisableStatic" -eq "1" ]; then
|
|
|
|
rm $out/lib/*.la
|
|
|
|
else
|
|
|
|
rm $out/lib/*.a
|
|
|
|
fi
|
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
|
2018-06-10 22:29:24 +00:00
|
|
|
# list the symbols used in this way.
|
2021-10-29 11:47:45 +00:00
|
|
|
postFixup =
|
|
|
|
let
|
|
|
|
rpath = makeLibraryPath (dlopenPropagatedBuildInputs ++ dlopenBuildInputs);
|
|
|
|
in
|
|
|
|
optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so") ''
|
|
|
|
for lib in $out/lib/*.so* ; do
|
|
|
|
if ! [[ -L "$lib" ]]; then
|
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
2018-03-05 20:12:44 +00:00
|
|
|
|
2016-08-22 03:24:32 +00:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
passthru = { inherit openglSupport; };
|
2013-07-02 21:06:05 +00:00
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
meta = with lib; {
|
2013-07-02 21:06:05 +00:00
|
|
|
description = "A cross-platform multimedia library";
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "http://www.libsdl.org/";
|
2016-08-22 03:24:32 +00:00
|
|
|
license = licenses.zlib;
|
|
|
|
platforms = platforms.all;
|
2017-01-20 11:23:57 +00:00
|
|
|
maintainers = with maintainers; [ cpages ];
|
2013-07-02 21:06:05 +00:00
|
|
|
};
|
|
|
|
}
|