SUMMARY="A movie player which runs on many systems"
DESCRIPTION="It plays most MPEG/VOB, AVI, Ogg/OGM, VIVO, ASF/WMA/WMV, \
QT/MOV/MP4, RealMedia, Matroska, NUT, NuppelVideo, FLI, YUV4MPEG, FILM, \
RoQ, PVA files, supported by many native, XAnim, and Win32 DLL codecs. \
You can watch VideoCD, SVCD, DVD, 3ivx, DivX 3/4/5, WMV and even H.264 movies.

Another great feature of MPlayer is the wide range of supported output \
drivers. It works with X11, Xv, DGA, OpenGL, SVGAlib, fbdev, AAlib, DirectFB, \
but you can use GGI, SDL (and this way all their drivers), VESA (on every \
VESA compatible card, even without X11!) and some low level card-specific \
drivers (for Matrox, 3Dfx and ATI), too! Most of them support software or \
hardware scaling, so you can enjoy movies in fullscreen. MPlayer supports \
displaying through some hardware MPEG decoder boards, such as the Siemens \
DVB, DXR2 and DXR3/Hollywood+.

MPlayer has an onscreen display (OSD) for status information, nice big \
antialiased shaded subtitles and visual feedback for keyboard controls. \
European/ISO 8859-1,2 (Hungarian, English, Czech, etc), Cyrillic and Korean \
fonts are supported along with 12 subtitle formats (MicroDVD, SubRip, OGM, \
SubViewer, Sami, VPlayer, RT, SSA, AQTitle, JACOsub, PJS and our own: MPsub). \
DVD subtitles (SPU streams, VOBsub and Closed Captions) are supported as well."
HOMEPAGE="http://www.mplayerhq.hu/"
COPYRIGHT="2001-2019 The MPlayer Team"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://anduin.linuxfromscratch.org/BLFS/mplayer/mplayer-export-2021-07-29.tar.bz2"
CHECKSUM_SHA256="fc15102b81440dcd297258f3b2afefe6930ce8791985d0ca8c38555e56bf07b1"
SOURCE_DIR="mplayer-export-2021-07-29"
PATCHES="mplayer-1.4.0_20210729.patchset"
ADDITIONAL_FILES="mplayer.rdef.in"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	mplayer$secondaryArchSuffix = $portVersion
	cmd:mencoder$commandSuffix
	cmd:mplayer$commandSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cdrtools$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:liba52$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcaca$secondaryArchSuffix
	lib:libcdio$secondaryArchSuffix
	lib:libcdio_paranoia$secondaryArchSuffix
	lib:libdca$secondaryArchSuffix
	lib:libdv$secondaryArchSuffix
	lib:libdvdcss$secondaryArchSuffix
	lib:libdvdnav$secondaryArchSuffix
	lib:libdvdread$secondaryArchSuffix
	lib:libenca$secondaryArchSuffix
	lib:libfaac$secondaryArchSuffix
	lib:libfaad$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libfribidi$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libgnutls$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblzo2$secondaryArchSuffix
	lib:libmad$secondaryArchSuffix
	lib:libmng$secondaryArchSuffix
	lib:libmp3lame$secondaryArchSuffix
#	lib:libmpcdec$secondaryArchSuffix
	lib:libmpeg2$secondaryArchSuffix
	lib:libmpg123$secondaryArchSuffix
	lib:libncursesw$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
#	lib:libopenal$secondaryArchSuffix
#	lib:libopenjp2$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
#	lib:libschroedinger_1.0$secondaryArchSuffix
#	lib:libsdl$secondaryArchSuffix
	lib:libsmbclient$secondaryArchSuffix
	lib:libspeex$secondaryArchSuffix
#	lib:libssl$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libswresample$secondaryArchSuffix
	lib:libtheoradec$secondaryArchSuffix
	lib:libtwolame$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libvorbisenc$secondaryArchSuffix
#	lib:libvpx$secondaryArchSuffix
	lib:libx264$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
#	lib:live555$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavcodec$secondaryArchSuffix >= 59
	devel:libavformat$secondaryArchSuffix >= 59
	devel:libavutil$secondaryArchSuffix >= 57
	devel:liba52$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:libcaca$secondaryArchSuffix
	devel:libcddb$secondaryArchSuffix
	devel:libcdio$secondaryArchSuffix >= 19
	devel:libcdio_paranoia$secondaryArchSuffix
	devel:libdca$secondaryArchSuffix
	devel:libdv$secondaryArchSuffix
	devel:libdvdcss$secondaryArchSuffix
	devel:libdvdnav$secondaryArchSuffix
	devel:libdvdread$secondaryArchSuffix
	devel:libenca$secondaryArchSuffix
	devel:libfaac$secondaryArchSuffix
	devel:libfaad$secondaryArchSuffix
	devel:libflac$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libfribidi$secondaryArchSuffix
	devel:libgif$secondaryArchSuffix
	devel:libgnutls$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblzo2$secondaryArchSuffix
	devel:libmad$secondaryArchSuffix
	devel:libmng$secondaryArchSuffix
	devel:libmp3lame$secondaryArchSuffix
#	devel:libmpcdec$secondaryArchSuffix
	devel:libmpeg2$secondaryArchSuffix
	devel:libmpg123$secondaryArchSuffix
	devel:libncursesw$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
#	devel:libopenal$secondaryArchSuffix
#	devel:libopenjp2$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libparanoia$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
#	devel:libschroedinger_1.0$secondaryArchSuffix
#	devel:libsdl$secondaryArchSuffix
	devel:libsmbclient$secondaryArchSuffix
	devel:libspeex$secondaryArchSuffix
#	devel:libssl$secondaryArchSuffix
	devel:libswresample$secondaryArchSuffix >= 4
	devel:libswscale$secondaryArchSuffix >= 6
	devel:libtheoradec$secondaryArchSuffix
	devel:libtwolame$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libvorbisenc$secondaryArchSuffix
#	devel:libvpx$secondaryArchSuffix
	devel:libx264$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
#	devel:live555$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
#	cmd:xslt_config$secondaryArchSuffix
	cmd:yasm
	"

defineDebugInfoPackage mplayer$secondaryArchSuffix \
	"$commandBinDir"/mencoder \
	"$commandBinDir"/mplayer

BUILD()
{
	export CFLAGS="-D_BSD_SOURCE"
	export LDFLAGS="-lnetwork -lbsd"

	libtoolize --force --copy --install
	chmod +x configure help/*.sh *.sh #mplayer doesn't provides configure.ac/in
	configure \
		--prefix=$prefix \
		--bindir=$commandBinDir \
		--datadir=$dataDir \
		--confdir=$settingsDir/mplayer \
		--mandir=$manDir \
		--disable-ffmpeg_a \
		--disable-sdl \
		--enable-dvdread --extra-libs="-ldvdcss -ldvdnav -ldvdread" \
		--enable-haiku \
		--enable-menu \
		--enable-runtime-cpudetection \
		--enable-smb

	make $jobArgs
}

INSTALL()
{
	make install

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

	addResourcesToBinaries mplayer.rdef $commandBinDir/mplayer

	mimeset -f $commandBinDir/mplayer
}
