SUMMARY="A player for Adobe Flash"
DESCRIPTION="GNU Gnash is the GNU Flash movie player — Flash is an animation \
file format pioneered by Macromedia which continues to be supported by their \
successor company, Adobe. Flash has been extended to include audio and video \
content, and programs written in ActionScript, an ECMAScript-compatible language."
HOMEPAGE="http://www.gnu.org/software/gnash/"
COPYRIGHT="2005-2019 Free Software Foundation"
LICENSE="GNU GPL v3"
REVISION="1"
srcGitRev="8a11e60585db4ed6bc4eafadfbd9b3123ced45d9"
SOURCE_URI="http://git.savannah.gnu.org/cgit/gnash.git/snapshot/gnash-$srcGitRev.tar.gz"
CHECKSUM_SHA256="c2628665624a5d7b76cf68142f151da7cac61637c55052e048a3e8e958223f99"
SOURCE_DIR="gnash-$srcGitRev"
PATCHES="gnash-$portVersion.patchset"
ADDITIONAL_FILES="gnash.rdef.in"

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

GLOBAL_WRITABLE_FILES="
	settings/gnashpluginrc auto-merge
	settings/gnashrc auto-merge
	"

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

libVersion=${portVersion%~*}dev

PROVIDES="
	gnash$secondaryArchSuffix = $portVersion
	cmd:gnash = $portVersion
	cmd:gprocessor = $portVersion
	cmd:rtmpget = $portVersion
	lib:libgnashbase$secondaryArchSuffix = $portVersion
	lib:libgnashbase_$libVersion$secondaryArchSuffix = $portVersion
	lib:libgnashcore$secondaryArchSuffix = $portVersion
	lib:libgnashcore_$libVersion$secondaryArchSuffix = $portVersion
	lib:libgnashdevice$secondaryArchSuffix = $portVersion
	lib:libgnashdevice_$libVersion$secondaryArchSuffix = $portVersion
	lib:libgnashmedia$secondaryArchSuffix = $portVersion
	lib:libgnashmedia_$libVersion$secondaryArchSuffix = $portVersion
	lib:libgnashrender$secondaryArchSuffix = $portVersion
	lib:libgnashrender_$libVersion$secondaryArchSuffix = $portVersion
	lib:libgnashsound$secondaryArchSuffix = $portVersion
	lib:libgnashsound_$libVersion$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libagg$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libboost_program_options$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	lib:libspeex$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	gnash${secondaryArchSuffix}_devel = $portVersion
	devel:libgnashbase$secondaryArchSuffix = $portVersion
	devel:libgnashcore$secondaryArchSuffix = $portVersion
	devel:libgnashdevice$secondaryArchSuffix = $portVersion
	devel:libgnashmedia$secondaryArchSuffix = $portVersion
	devel:libgnashrender$secondaryArchSuffix = $portVersion
	devel:libgnashsound$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	gnash$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libagg$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix
	devel:libboost_program_options$secondaryArchSuffix >= 1.69.0
	devel:libbz2$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgif$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libspeex$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	cmd:xargs
	"

BUILD()
{
	INCLUDE_DIR=`finddir B_SYSTEM_DIRECTORY`/$relativeIncludeDir
	LIB_DIR=`finddir B_SYSTEM_DIRECTORY`/$relativeDevelopLibDir

	autogen.sh

	runConfigure ./configure \
		--with-boost-incl=$INCLUDE_DIR/boost \
		--with-boost-lib=$LIB_DIR \
		--bindir=$commandBinDir \
		--libdir=$libDir \
		--enable-renderer=agg \
		--enable-media=ffmpeg \
		--enable-gui=haiku \
		--enable-sound=mkit \
		--disable-jemalloc \
		--without-gconf \
		--disable-extensions

	make $jobArgs
}

INSTALL()
{
	make install
	mv $libDir/gnash/*dev.so $libDir
	rm -rf $commandBinDir/gnash \
		$dataDir/{applications,icons} \
		$libDir/gnash	
	mv $commandBinDir/haiku-gnash $commandBinDir/gnash
	strip $binDir/* $libDir/*.so

	for i in $libDir/lib*.so;do
		mv $i ${i%-*}.so
		ln -fs ${i%-*}.so $i
	done

	prepareInstalledDevelLibs \
		libgnashbase libgnashcore \
		libgnashdevice libgnashmedia \
		libgnashrender libgnashsound
	fixPkgconfig

	packageEntries devel \
		$developDir

	local APP_SIGNATURE="application/x-vnd.gnash-player"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3 | cut -d~ -f1`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/gnash.rdef.in > gnash.rdef

	addResourcesToBinaries gnash.rdef $commandBinDir/gnash
}

TEST()
{
	make check
}
