#Maintainer: George Vlahavas (vlahavas~at~gmail~dot~com)

pkgname=prboom
pkgver=2.5.0
_freedoomver=0.8
pkgrel=3gv
source=("http://downloads.sourceforge.net/prboom/prboom-$pkgver.tar.gz" "https://github.com/freedoom/freedoom/releases/download/v${_freedoomver}/freedoom-iwad-v${_freedoomver}.zip" "icons.tar.gz" "prboom.desktop" "libpng-1.4.patch")
docs=("readme*" "install" "copying" "changelog" "authors" "news" "todo" "maintainers" "*.txt")
url=http://prboom.sourceforge.net/index.html

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"prboom (a much enhanced port of Doom)"
"PrBoom is made up of the combined projects DosDoom, Boom, MBF, LxDoom"
"and lSDLDoom. Free maps from the freedoom project are included in the"
"package."
)


build() {
	cd $startdir/src/$pkgname-$pkgver

	patch -p1 < $startdir/src/libpng-1.4.patch || exit 1

	# apparently for some 32bit CPUs, this is needed, or it crashes
	if [ "$arch" == "i486" ] || [ "arch" == "i586" ] || [ "$arch" == "i686" ]; then
		EXTRACONFIGUREOPTS="--disable-i386-asm"
	else
		EXTRACONFIGUREOPTS=""
	fi
	echo "Using extra configure options: $EXTRACONFIGUREOPTS"

	./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --localstatedir=/var --sysconfdir=/etc --with-waddir=/usr/share/prboom --build=$arch-slackware-linux $EXTRACONFIGUREOPTS

	make || return 1
	make install DESTDIR=$startdir/pkg
	mkdir -p $startdir/pkg/usr/bin
	mv $startdir/pkg/usr/games/* $startdir/pkg/usr/bin
	rmdir $startdir/pkg/usr/games

	mv $startdir/src/freedoom-iwad-v${_freedoomver}/*.wad $startdir/pkg/usr/share/prboom/
	mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver/freedoom-iwad-${_freedoomver}
	mv $startdir/src/freedoom-iwad-v${_freedoomver}/* $startdir/pkg/usr/doc/$pkgname-$pkgver/freedoom-iwad-${_freedoomver}

	mkdir -p $startdir/pkg/usr/share/applications
	cp $startdir/src/prboom.desktop $startdir/pkg/usr/share/applications/

	# Copy icons to the right place
	ICONSIZES="64 48 32 24 22 16"
	for i in $ICONSIZES; do
		mkdir -p $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps;
		mv $startdir/src/$pkgname-$i.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/$pkgname.png;
	done;

	# Remove not needed doc dir
	rm -rf $startdir/pkg/usr/share/doc
}