# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=sdl12-compat
# Have the same version as the last upstream release
pkgver=1.2.68
pkgrel=0
pkgdesc="SDL-1.2 compat layer that uses SDL-2.0"
url="https://github.com/libsdl-org/sdl12-compat"
arch="all"
license="BSD-3-Clause"
depends="sdl2"
makedepends="cmake samurai sdl2-dev"
checkdepends="glu-dev mesa-dev"
subpackages="$pkgname-static $pkgname-dbg $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/libsdl-org/sdl12-compat/archive/release-$pkgver.tar.gz"
builddir="$srcdir/$pkgname-release-$pkgver"
options="!check" # these are manual tests, not actual

# Otherwise the package will fail installation if sdl is already present
# NOTE(Leo): remove this before the release of 3.15
replaces="sdl"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -O2 -DNDEBUG -flto=auto -I/usr/include/directfb" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSDL12TESTS="$(want_check && echo ON || echo OFF)" \
		$crossopts
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# Claim the provider 'pc:sdl=$pkgver' by creating a symlink
	# so packages can find it
	ln -s sdl12_compat.pc "$pkgdir"/usr/lib/pkgconfig/sdl.pc
}

dev() {
	# Otherwise the package will fail installation if sdl is already present
	# NOTE(Leo): remove this before the release of 3.15
	replaces="sdl-dev"

	default_dev
}

sha512sums="
d0e71e75f312402bf075f6553d9fd6493a3db9dd42719bb753287a35e6c40ee37c6092b157ff2384f3055400a3113645595d1269590cd50ea1e0c8f247240858  sdl12-compat-1.2.68.tar.gz
"
