# Template file for 'cdogs'
pkgname=cdogs-sdl
version=0.5.8
revision=1
build_style=cmake
_hqxrev=2a8a05854ad2147425d0b55a3c40e81c368c97fd
_tinydirrev=53aab97d6a11d70d669ce9c36d0d90ec6937c33d
hostmakedepends="cmake"
makedepends="physfs-devel SDL-devel SDL_mixer-devel SDL_image-devel SDL_net-devel"
short_desc="A classic overhead run-and-gun game"
maintainer="Enno Boland <eb@s01.de>"
homepage="http://cxong.github.io/cdogs-sdl/"
license="GPL2"
distfiles="https://github.com/cxong/cdogs-sdl/archive/$version.tar.gz
	https://github.com/cxong/tinydir/archive/$_tinydirrev.tar.gz
	https://github.com/cxong/hqx/archive/$_hqxrev.tar.gz"
checksum="08e1f47b43c229ce0d20a32c9e287abc9f47cdc658ac38726a414083256401d3
	2d71972034d570ac506dee5909cfac72c1870734228a61b266e354f2d9acf277
	fca25adefd14af3584dcf0e48c69647aa46a924ddbfcb75ec6053528f1bd80bc"
lib32disabled=yes

post_extract() {
	rmdir ${XBPS_BUILDDIR}/$pkgname-$version/src/cdogs/hqx
	ln -sf ${XBPS_BUILDDIR}/hqx-$_hqxrev \
		${XBPS_BUILDDIR}/$pkgname-$version/src/cdogs/hqx

	rmdir ${XBPS_BUILDDIR}/$pkgname-$version/src/tinydir
	ln -sf ${XBPS_BUILDDIR}/tinydir-$_tinydirrev \
		${XBPS_BUILDDIR}/$pkgname-$version/src/tinydir
}

pre_configure() {
	# disable tests
	sed -i "/add_subdirectory(tests)/d" src/CMakeLists.txt

	# fix the broken build system and build
	sed -i \
		-e "s/add_definitions(-Winline -Werror)/add_definitions(-Winline)/" \
		-e "/PROGRAMS /s#src/#build/\0#g" \
		-e "/FILES /s#build/linux/#build/\0#g" \
		-e "s#\(SET(CMAKE_INSTALL_PREFIX\) .*#\1 /usr/share/cdogs)#" \
		-e "s#\(set(CDOGS_DATA_DIR\) .*#\1 /usr/share/cdogs/)#" \
		CMakeLists.txt

	# workaround bug
	ln -rs build build/build
}

post_install() {
	mv $DESTDIR/usr/share/cdogs/bin $DESTDIR/usr/bin
}
