# Description: SDL version 2, Simple DirectMedia Layer
# URL: https://www.libsdl.org
# Maintainer: Juergen Daubert, jue at crux dot nu
# Depends on: mesa
# Optional: alsa-lib ibus jack pipewire pulseaudio wayland-protocols

name=libsdl2
version=2.30.2
release=1
source=(https://www.libsdl.org/release/SDL2-$version.tar.gz)

build() {
	prt-get isinst alsa-lib && PKGMK_SDL2+=' -D SDL_ALSA_SHARED=ON'
	prt-get isinst ibus && PKGMK_SDL2+=' -D SDL_USE_IME=ON'
	prt-get isinst jack && PKGMK_SDL2+=' -D SDL_JACK_SHARED=ON'
	prt-get isinst pipewire && PKGMK_SDL2+=' -D SDL_PIPEWIRE_SHARED=ON'
	prt-get isinst pulseaudio && PKGMK_SDL2+=' -D SDL_PULSEAUDIO_SHARED=ON'
	prt-get isinst wayland-protocols && PKGMK_SDL2+=' -D SDL_WAYLAND_SHARED=ON'

	[[ -z $CCACHE_PREFIX ]] || unset CCACHE_PREFIX

	cmake -S SDL2-$version -B build -G Ninja $PKGMK_SDL2 \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBDIR=lib \
		-D CMAKE_BUILD_TYPE=Release \
		-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
		-D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
		-D SDL_CLOCK_GETTIME=ON \
		-D SDL_RPATH=OFF
	cmake --build build -j ${JOBS:-1}
	DESTDIR=$PKG cmake --install build

	rm -r $PKG/usr/share/licenses
}
