# Template file for 'ufoai'
pkgname=ufoai
version=2.5
revision=1
create_wrksrc=yes
build_style=gnu-makefile
hostmakedepends="pkg-config"
makedepends="MesaLib-devel glu-devel libjpeg-turbo-devel
 libvorbis-devel libopenal-devel xvidcore-devel libtheora-devel
 SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel libcurl-devel
 gtkglext-devel gtksourceview2-devel"
depends="ufoai-data>=${version} ca-certificates"
short_desc="UFO Alien Invasion"
maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
license="GPL-2"
homepage="http://ufoai.org/"
distfiles="
 ${SOURCEFORGE_SITE}/${pkgname}/UFO_AI%202.x/${version}/${pkgname}-${version}-source.tar.bz2
 ${SOURCEFORGE_SITE}/${pkgname}/UFO_AI%202.x/${version}/${pkgname}-${version}-data.tar"
checksum="
 0c7cc3bc9efeb276f71cbe6ee8ff7c76f98d183de79f1a069fa63059cf182a8f
 0d12041cba3aaaba1ce114650c36586d286dcce51c721844c06fdace06e307b8"

# suppress a lot of warnings
CXXFLAGS="-Wno-cast-align -Wno-cast-qual -Wno-inline"

post_extract() {
	cd ${wrksrc}
	mv ufoai-${version}-source/* .
}
do_configure() {
	# Further reduce amount of warnings
	sed -i build/platforms/linux.mk \
		-e"s;_BSD_SOURCE;_DEFAULT_SOURCE;g"

	# Disable building of maps and models
	sed -i Makefile \
		-e "s;include build/maps.mk;#&;" \
		-e "s;include build/models.mk;#&;"

	./configure --prefix=/usr \
		--bindir=/usr/bin \
		--datadir=/usr/share/ufoai \
		--localedir=/usr/share/ufoai/base/i18n \
		--enable-uforadiant \
		--enable-release
}
do_build() {
	make ${makejobs}
	make ${makejobs} lang
	make ${makejobs} uforadiant
}
post_install() {
	local f
	for f in ufo ufoai ufoai-safe ufoded uforadiant; do
		if [ -f debian/$f.desktop ]; then
			vinstall debian/$f.desktop 644 usr/share/applications
		fi
		if [ -f debian/$f.xpm ]; then
			vinstall debian/$f.xpm 644 usr/share/pixmaps
		fi
		if [ -f debian/$f.6 ]; then
			vman debian/$f.6
		fi
	done
	# adjust desktop files
	sed -i ${DESTDIR}/usr/share/applications/* -e "s;/usr/games/;;"
}

ufoai-data_package() {
	short_desc+=" - data files"
	noarch=yes
	pkg_install() {
		vmove usr/share/ufoai/base/*.pk3
		vmove usr/share/ufoai/base/i18n
	}
}

ufoai-radiant_package() {
	short_desc+=" - map editor"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/bin/uforadiant
		vmove usr/share/ufoai/radiant
		vmove usr/share/applications/uforadiant.desktop
		vmove usr/share/man/man6/uforadiant.6
		vmove usr/share/pixmaps/uforadiant.xpm
	}
}
