SUMMARY="A free, open source, and cross-platform media player"
DESCRIPTION="mpv is a media player based on MPlayer and mplayer2. It supports \
a wide variety of video file formats, audio and video codecs, and subtitle \
types."
HOMEPAGE="https://mpv.io/"
COPYRIGHT="2013-2021 MPV Developers"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/mpv-player/mpv/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f654fb6275e5178f57e055d20918d7d34e19949bc98ebbf4a7371902e88ce309"
SOURCE_FILENAME="mpv-$portVersion.tar.gz"
wafVersion="2.0.20"
SOURCE_URI_2="https://waf.io/waf-$wafVersion#noarchive"
CHECKSUM_SHA256_2="bf971e98edc2414968a262c6aa6b88541a26c3cd248689c89f4c57370955ee7f"
SOURCE_FILENAME_2="waf-$wafVersion"
PATCHES="mpv-$portVersion.patchset"

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

GLOBAL_WRITABLE_FILES="settings/mpv/encoding-profiles.conf keep-old"

PROVIDES="
	mpv$secondaryArchSuffix = $portVersion
	cmd:mpv$secondaryArchSuffix = $portVersion compat >= 0.30
	lib:libmpv$secondaryArchSuffix = 1.106.0 compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libass$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavfilter$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libbluray$secondaryArchSuffix
	lib:libcdio$secondaryArchSuffix
	lib:libcdio_paranoia$secondaryArchSuffix
	lib:libdvdnav$secondaryArchSuffix
	lib:libdvdread$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	lib:librubberband$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libswresample$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libuchardet$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	mpv${secondaryArchSuffix}_devel = $portVersion compat >= 0.30
	devel:libmpv$secondaryArchSuffix = 1.106.0 compat >= 1
	"
REQUIRES_devel="
	haiku$secondaryArchSuffix
	mpv$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libass$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix
	devel:libavfilter$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libbluray$secondaryArchSuffix
	devel:libcdio_paranoia$secondaryArchSuffix
	devel:libdvdcss$secondaryArchSuffix
	devel:libdvdnav$secondaryArchSuffix
	devel:libdvdread$secondaryArchSuffix
	devel:libenca$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libfribidi$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libharfbuzz$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:libmpg123$secondaryArchSuffix
	devel:librubberband$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libswresample$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libuchardet$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	cmd:yasm
	"

BUILD()
{
#	Do not call "python bootstrap.py" as it (only) downloads waf.
#	python bootstrap.py
	# Instead, copy the archive from SOURCE_URI_2.
	cp $sourceDir2/$SOURCE_FILENAME_2 waf
	chmod +x waf

	export LDFLAGS=-lnetwork

	python3 waf configure \
		--enable-dvdnav \
		--disable-libavdevice \
		--disable-openal \
		--disable-libmpv-static \
		--disable-static-build \
		--enable-libmpv-shared \
		--enable-sdl2 \
		--enable-cdda \
		--bindir=$binDir \
		--confdir=$settingsDir/mpv \
		--disable-gl \
		--datadir=$dataDir \
		--libdir=$libDir \
		--includedir=$includeDir

	python3 waf build
}

INSTALL()
{
	python3 waf install
	rm -rf $dataDir/applications
	rm -rf $dataDir/icons

	prepareInstalledDevelLibs libmpv

	fixPkgconfig

	# devel package
	packageEntries devel $developDir
}
