# Template file for 'bsd-games'.  Based on Arch PKGBUILD by Chris Brannon.
pkgname=bsd-games
version=2.17
revision=2
patch_args="-Np1"
build_style=gnu-configure
make_dirs="
 /var/games/bsdgames/hack 0775 root users
 /var/games/bsdgames/hack/save 0775 root users
 /var/games/bsdgames/phantasia 0775 root users"
hostmakedepends="flex words-en"
makedepends="ncurses-devel"
depends="words-en"
short_desc="A linux port for a collection of BSD command line games"
maintainer="Christian Neukirchen <chneukirchen@gmail.com>"
license="BSD"
homepage="ftp://ftp.ibiblio.org/pub/Linux/games/"
distfiles="ftp://ftp.lip6.fr/pub/linux/sunsite/games/${pkgname}-${version}.tar.gz"
checksum=066f924aef6c1c5ea946f588e36f303021f5dfc093944738f025d8edbc6fff60
nocross=yes

post_extract() {
	cp ${FILESDIR}/config.params .

	echo "bsd_games_cfg_cc='$CC'" >>config.params
	echo "bsd_games_cfg_cxx='$CXX'" >>config.params
	echo "bsd_games_cfg_other_cflags='$CFLAGS'" >>config.params
	echo "bsd_games_cfg_other_ldflags='$LDFLAGS'" >>config.params

	sed -i "s/FISH/GO-FISH/g; s/\.Nm fish/\.Nm go-fish/g" fish/fish.6
	sed -i "s/tenths/tenth/g" tests/number.-0.1
	sed -i "s/Elegy{ Written in a Country Church{-| }Yard:/Elegy{ Written in a Country Church{-| }Yard}:/g" quiz/datfiles/poetry
	sed -i "s/\.tI friend/\.It friend/g" hunt/hunt/hunt.6.in
	sed -i "s/it\'s initial/its initial/g" backgammon/teachgammon/ttext1.c
	sed -i "s/two player\'s/two players/g" backgammon/teachgammon/ttext2.c
	sed -i  "s/\.I range/\.It range/g" arithmetic/arithmetic.6
	sed -i "s/game were the/game where the/g" gomoku/gomoku.6
	sed -i 's|/usr/games|/usr/bin|g' wargames/wargames

	sed -i '1i#include <sys/types.h>' banner/banner.c
	sed -i 's/getdate/get_date/g' hack/*.[ch]
	sed -i '1i#include <fcntl.h>' wump/wump.c
	sed -i 's/-DOTTO//' hunt/Makeconfig
}

do_install() {
	echo >install-score
	sed -i "s|PKGDIR|$DESTDIR|g" hide-game install-man install-score Makeconfig subst.sed
	make install

	# Remove conflict with fish-shell
	mv "${DESTDIR}/usr/bin/fish" "${DESTDIR}/usr/bin/go-fish"
	mv "${DESTDIR}/usr/share/man/man6/fish.6.gz" "${DESTDIR}/usr/share/man/man6/go-fish.6.gz"

	vdoc "${DESTDIR}/usr/share/doc/trek.me"
	rm "${DESTDIR}/usr/share/doc/trek.me"
	vlicense COPYING
}

