# Template file for 'rocksndiamonds'
pkgname=rocksndiamonds
version=4.1.1.0
revision=1
build_style=gnu-makefile
hostmakedepends="pkg-config"
makedepends="SDL2_image-devel SDL2_mixer-devel SDL2_net-devel"
depends="rocksndiamonds-data"
short_desc="Arcade style game"
maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
license="GPL-2.0-only"
homepage="http://www.artsoft.org/rocksndiamonds"
distfiles="http://www.artsoft.org/RELEASES/unix/${pkgname}/${pkgname}-${version}.tar.gz"
checksum=e24c6d4db9571d02207d1944e46e2d68695c0e7f001bc8794dcd20f40a3515cc

# Package build options
build_options="gles"

case "$XBPS_TARGET_MACHINE" in
	arm*)
		# Enable OpenGL/ES on rpi platforms
		build_options_default="gles"
		;;
esac


if [ "$build_option_gles" ]; then
	case "$XBPS_TARGET_MACHINE" in
	armv[67]*)
		# RaspberryPi, use Videocore IV
		makedepends+=" rpi-userland-devel"
		LDFLAGS="-L${XBPS_CROSS_BASE}/opt/vc/lib -lbcm_host"
		;;
	esac
fi

do_build() {
	CFLAGS+=" -DTARGET_SDL2"
	CFLAGS+=" -DRO_GAME_DIR='\"/usr/share/${pkgname}\"'"
	CFLAGS+=" -DRW_GAME_DIR='\"/var/lib/${pkgname}\"'"
	CFLAGS+=" $(sdl2-config --cflags)"
	LDFLAGS+=" $(sdl2-config --libs) -lSDL2_image -lSDL2_mixer -lSDL2_net -lm"
	make CC="${CC}" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" sdl2
}

do_install() {
	vmkdir usr/share/${pkgname}
	cp -aR graphics levels music sounds ${DESTDIR}/usr/share/${pkgname}
	vbin rocksndiamonds
	# Manual page is no longer supplied (WTF)
	# vman rocksndiamonds.1
	vinstall ${FILESDIR}/${pkgname}.desktop 644 usr/share/applications
	vinstall ${FILESDIR}/${pkgname}.png 644 usr/share/pixmaps
}

rocksndiamonds-data_package() {
	short_desc+=" - data files"
	noarch=yes
	pkg_install() {
		vmove usr/share/rocksndiamonds
	}
}
