# Template file for 'cdogs'
pkgname=cdogs-sdl
version=0.5.5.1
revision=1
build_style=cmake
_hqxrev=994249c8c4d1446afd9c05654bf7eafffd7a11bb;
_tinydirrev=5545eeb7bf5ee2b64f790a276f89aa1856a6269a
hostmakedepends="cmake"
makedepends="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="3013861dc73241b2081b6f41ed3937a7afa9b19a7f8e3cc9470ba1b4f1244f8d
	ebd1c2c64724f5f5e1837e42bae1f5c67a0be4df09b7974c2d6a3d64c8314ea4
	adeef0711099da7e86c2c20b3fc40e63f32ea1e11ef0b9a98dacfc983f38f4ce"
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_configure() {
	cp build/src/cdogs/sys_config.h src/cdogs/sys_config.h
}

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