SUMMARY="Tux4Kids' math tutor for kids"
DESCRIPTION="TuxMath is an educational math tutor for kids starring Tux, \
the Linux penguin. This educational game comes with two different games for \
practicing math, and having a great time doing it."
HOMEPAGE="https://sourceforge.net/projects/tuxmath/"
COPYRIGHT="2000-2009 Sam Hart"
LICENSE="GNU GPL v2"
REVISION="5"
SOURCE_URI="https://downloads.sf.net/tuxmath/tuxmath_w_fonts-$portVersion.tar.gz"
CHECKSUM_SHA256="7a3e39b17b88402a89780ac56368d8d92322c3b91f50ee4f9b747a8e2901b3a4"
SOURCE_DIR="tuxmath_w_fonts-$portVersion"
PATCHES="tuxmath-$portVersion.patchset"
ADDITIONAL_FILES="tuxmath.rdef"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	tuxmath$secondaryArchSuffix
	app:TuxMath$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	lib:libSDL_ttf_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	devel:libSDL_mixer_1.2$secondaryArchSuffix
	devel:libSDL_ttf_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autopoint
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	autoreconf -vfi
	sed -i "s,-lm,," configure

	./configure --prefix=$appsDir/TuxMath --without-sdlpango LDFLAGS="-liconv"

	echo "#define ICONV_CONST const" >> config.h
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/TuxMath
	make install

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/tuxmath.rdef > tuxmath.rdef

	addResourcesToBinaries tuxmath.rdef \
		$appsDir/TuxMath/bin/tuxmath

	mv $appsDir/TuxMath/bin/tuxmath $appsDir/TuxMath/TuxMath
	rm -r $appsDir/TuxMath/bin
	addAppDeskbarSymlink $appsDir/TuxMath/TuxMath
}
