2022-03-30 09:31:56 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, config
|
2023-10-09 19:29:22 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, nix-update-script
|
2022-03-30 09:31:56 +00:00
|
|
|
, pkg-config
|
2021-02-05 17:12:51 +00:00
|
|
|
, libGLSupported ? lib.elem stdenv.hostPlatform.system lib.platforms.mesaPlatforms
|
2022-03-30 09:31:56 +00:00
|
|
|
, openglSupport ? libGLSupported
|
|
|
|
, libGL
|
|
|
|
, alsaSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, alsa-lib
|
2021-04-22 02:08:21 +00:00
|
|
|
, x11Support ? !stdenv.targetPlatform.isWindows && !stdenv.hostPlatform.isAndroid
|
2022-03-30 09:31:56 +00:00
|
|
|
, libX11
|
|
|
|
, xorgproto
|
|
|
|
, libICE
|
|
|
|
, libXi
|
|
|
|
, libXScrnSaver
|
|
|
|
, libXcursor
|
|
|
|
, libXinerama
|
|
|
|
, libXext
|
|
|
|
, libXxf86vm
|
|
|
|
, libXrandr
|
2020-04-24 23:36:52 +00:00
|
|
|
, waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
2022-03-30 09:31:56 +00:00
|
|
|
, wayland
|
|
|
|
, wayland-protocols
|
2022-05-18 14:49:53 +00:00
|
|
|
, wayland-scanner
|
2023-04-29 16:46:19 +00:00
|
|
|
, drmSupport ? false
|
2022-04-27 09:35:20 +00:00
|
|
|
, libdrm
|
|
|
|
, mesa
|
2022-03-30 09:31:56 +00:00
|
|
|
, libxkbcommon
|
|
|
|
, dbusSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, dbus
|
2022-08-12 12:06:08 +00:00
|
|
|
, udevSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
2022-03-30 09:31:56 +00:00
|
|
|
, udev
|
|
|
|
, ibusSupport ? false
|
|
|
|
, ibus
|
|
|
|
, libdecorSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libdecor
|
|
|
|
, pipewireSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, pipewire # NOTE: must be built with SDL2 without pipewire support
|
2020-04-24 23:36:52 +00:00
|
|
|
, pulseaudioSupport ? config.pulseaudio or stdenv.isLinux && !stdenv.hostPlatform.isAndroid
|
|
|
|
, libpulseaudio
|
2022-03-30 09:31:56 +00:00
|
|
|
, AudioUnit
|
|
|
|
, Cocoa
|
|
|
|
, CoreAudio
|
|
|
|
, CoreServices
|
|
|
|
, ForceFeedback
|
|
|
|
, OpenGL
|
|
|
|
, audiofile
|
|
|
|
, libiconv
|
2020-06-18 07:06:33 +00:00
|
|
|
, withStatic ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# NOTE: When editing this expression see if the same change applies to
|
|
|
|
# SDL expression too
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "SDL2";
|
2023-10-09 19:29:22 +00:00
|
|
|
version = "2.28.3";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "libsdl-org";
|
|
|
|
repo = "SDL";
|
|
|
|
rev = "release-${version}";
|
|
|
|
hash = "sha256-/kQ2IyvAfmZ+zIUt1WuEIeX0nYPGXDlAQk2qDsQnFFs=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-10-21 18:38:19 +00:00
|
|
|
dontDisableStatic = if withStatic then 1 else 0;
|
2020-04-24 23:36:52 +00:00
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
outputBin = "dev"; # sdl-config
|
|
|
|
|
2022-04-15 01:41:22 +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
|
|
|
|
];
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
postPatch = ''
|
|
|
|
# Fix running wayland-scanner for the build platform when cross-compiling.
|
|
|
|
# See comment here: https://github.com/libsdl-org/SDL/issues/4860#issuecomment-1119003545
|
|
|
|
substituteInPlace configure \
|
|
|
|
--replace '$(WAYLAND_SCANNER)' 'wayland-scanner'
|
|
|
|
'';
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
depsBuildBuild = [ pkg-config ];
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeBuildInputs = [ pkg-config ] ++ lib.optionals waylandSupport [ wayland wayland-scanner ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
dlopenPropagatedBuildInputs = [ ]
|
|
|
|
# Propagated for #include <GLES/gl.h> in SDL_opengles.h.
|
2023-07-15 17:15:38 +00:00
|
|
|
++ lib.optional (openglSupport && !stdenv.isDarwin) libGL
|
2020-04-24 23:36:52 +00:00
|
|
|
# Propagated for #include <X11/Xlib.h> and <X11/Xatom.h> in SDL_syswm.h.
|
2023-04-29 16:46:19 +00:00
|
|
|
++ lib.optionals x11Support [ libX11 ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = lib.optionals x11Support [ xorgproto ]
|
|
|
|
++ dlopenPropagatedBuildInputs;
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
dlopenBuildInputs = lib.optionals alsaSupport [ alsa-lib audiofile ]
|
|
|
|
++ lib.optional dbusSupport dbus
|
|
|
|
++ lib.optional libdecorSupport libdecor
|
|
|
|
++ lib.optional pipewireSupport pipewire
|
|
|
|
++ lib.optional pulseaudioSupport libpulseaudio
|
|
|
|
++ lib.optional udevSupport udev
|
2023-04-29 16:46:19 +00:00
|
|
|
++ lib.optionals waylandSupport [ wayland libxkbcommon ]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ]
|
|
|
|
++ lib.optionals drmSupport [ libdrm mesa ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs = [ libiconv ]
|
|
|
|
++ dlopenBuildInputs
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optional ibusSupport ibus
|
2023-04-29 16:46:19 +00:00
|
|
|
++ lib.optionals waylandSupport [ wayland-protocols ]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
configureFlags = [
|
|
|
|
"--disable-oss"
|
2023-02-02 18:25:31 +00:00
|
|
|
] ++ lib.optional (!x11Support) "--without-x"
|
|
|
|
++ lib.optional alsaSupport "--with-alsa-prefix=${alsa-lib.out}/lib"
|
|
|
|
++ lib.optional stdenv.targetPlatform.isWindows "--disable-video-opengles"
|
|
|
|
++ lib.optional stdenv.isDarwin "--disable-sdltest";
|
2020-04-24 23:36:52 +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.
|
|
|
|
postInstall = ''
|
|
|
|
if [ "$dontDisableStatic" -eq "1" ]; then
|
|
|
|
rm $out/lib/*.la
|
|
|
|
else
|
|
|
|
rm $out/lib/*.a
|
|
|
|
fi
|
|
|
|
moveToOutput bin/sdl2-config "$dev"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# list the symbols used in this way.
|
2022-03-30 09:31:56 +00:00
|
|
|
postFixup =
|
|
|
|
let
|
2023-02-02 18:25:31 +00:00
|
|
|
rpath = lib.makeLibraryPath (dlopenPropagatedBuildInputs ++ dlopenBuildInputs);
|
2022-03-30 09:31:56 +00:00
|
|
|
in
|
2023-02-02 18:25:31 +00:00
|
|
|
lib.optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so") ''
|
2022-03-30 09:31:56 +00:00
|
|
|
for lib in $out/lib/*.so* ; do
|
|
|
|
if ! [[ -L "$lib" ]]; then
|
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
passthru = {
|
|
|
|
inherit openglSupport;
|
|
|
|
updateScript = nix-update-script { extraArgs = ["--version-regex" "release-(.*)"]; };
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "A cross-platform multimedia library";
|
|
|
|
homepage = "http://www.libsdl.org/";
|
2023-05-24 13:37:59 +00:00
|
|
|
changelog = "https://github.com/libsdl-org/SDL/releases/tag/release-${version}";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.zlib;
|
|
|
|
platforms = platforms.all;
|
2023-03-30 22:05:00 +00:00
|
|
|
maintainers = with maintainers; [ cpages ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|