# forked from Alpine Linux
pkgname=sdl2
pkgver=2.0.15_hg20210201
pkgrel=0
_snapshot_ver=14845
_pkgver=${pkgver%_hg*}
pkgdesc="development library designed to provide low level access to audio, keyboard, mouse, joystick and graphics"
url="https://www.libsdl.org"
arch="all"
license="Zlib"
depends_dev="directfb-dev mesa-dev samurai"
makedepends="
	alsa-lib-dev
	cmake
	eudev-dev
	jack-dev
	libx11-dev
	libxcursor-dev
	libxext-dev
	libxi-dev
	libxkbcommon-dev
	libxrandr-dev
	libxrender-dev
	libxscrnsaver-dev
	libusb-dev
	pulseaudio-dev
	wayland-dev
	wayland-protocols
	$depends_dev
	"
subpackages="$pkgname-dev"
source="https://www.libsdl.org/tmp/SDL-$_pkgver-$_snapshot_ver.tar.gz
	directfb-cflags.patch
	khronos.patch
	0001-cmake-reset-SDL_INTERFACE_AGE-to-0.patch
	"
options="!check !strip" # No good way to run the available tests
builddir="$srcdir/SDL-$_pkgver-$_snapshot_ver"

# secfixes:
#   2.0.10-r0:
#     - CVE-2019-7572
#     - CVE-2019-7573
#     - CVE-2019-7574
#     - CVE-2019-7575
#     - CVE-2019-7576
#     - CVE-2019-7578
#     - CVE-2019-7635
#     - CVE-2019-7636
#     - CVE-2019-7637
#     - CVE-2019-7638

build() {
	# NOTE: Please do not remove the -DVIDEO_DIRECTFB=ON flag.
	# Some apps, used for booting Alpine derivatives, require this to function!
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=True \
		-DSDL_TEST=OFF \
		-DALSA=ON \
		-DJACK=ON \
		-DCLOCK_GETTIME=ON \
		-DARTS=OFF \
		-DESD=OFF \
		-DNAS=OFF \
		-DRPATH=OFF \
		-DVIDEO_X11=ON \
		-DVIDEO_DIRECTFB=ON \
		-DVIDEO_WAYLAND=ON \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DSDL_STATIC=ON \
		-DSDL_SHARED=ON \
		-DPULSEAUDIO_SHARED=ON \
		"$CMAKE_CROSSOPTS"
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install
}

sha512sums="ff3c7eca4f7ca652c48cff44e33d59894e220796b4982375bcb09c9fa7936c77c1c1a73759ee1b6ceed5b532b52f7e08e3d771c64524c34d22e42bfaedd4f350  SDL-2.0.15-14845.tar.gz
8efdd02e0e71908b913f4c05b1f02aa94315c2bbffff87d1a46db94723dd7f0ea177e1e00de6c212ad31a00a22aa0fd87f63c3865c4dff2dc98f302046084caf  directfb-cflags.patch
76c93659a122def05f341ba30507b546b201c84823236ca731ac801f092e769574e8f051770a76050a77ac846ed851abab604e0a6d578b382f4792ab47aa60ed  khronos.patch
af3cd40185178cb3ce879e823d4c623155a6d969caff083345f7d77b0899be509f66deddd27557fc6bdc8d94d2f71988e3d38b407a2cd4d8c0c3becb34d3cd14  0001-cmake-reset-SDL_INTERFACE_AGE-to-0.patch"
