SUMMARY="The popular cross-plattform media player"
DESCRIPTION="VLC is a free and open source cross-platform multimedia player \
and framework that plays most multimedia files as well as DVDs, Audio CDs, \
VCDs, and various streaming protocols."
HOMEPAGE="https://www.videolan.org/vlc/"
COPYRIGHT="1998-2021 VideoLAN"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://download.videolan.org/pub/videolan/vlc/$portVersion/vlc-$portVersion.tar.xz"
SOURCE_DIR="vlc-$portVersion"
CHECKSUM_SHA256="ffae35fc64f625c175571d2346bc5f6207be99762517f15423e74f18399410f6"
PATCHES="vlc-$portVersion.patchset"
ADDITIONAL_FILES="
	vlc.rdef.in
	vlc_launcher.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	vlc$secondaryArchSuffix = $portVersion
	app:VLC$secondaryArchSuffix = $portVersion
	cmd:vlc = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liba52$secondaryArchSuffix
	lib:libass$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libbluray$secondaryArchSuffix
	lib:libcddb$secondaryArchSuffix
	lib:libdca$secondaryArchSuffix
	lib:libdvbpsi$secondaryArchSuffix
	lib:libdvdcss$secondaryArchSuffix
	lib:libdvdnav$secondaryArchSuffix
	lib:libdvdread$secondaryArchSuffix
	lib:libebml$secondaryArchSuffix
	lib:libenca$secondaryArchSuffix
	lib:libfaad$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libgnutls$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libmad$secondaryArchSuffix
	lib:libmatroska$secondaryArchSuffix
	lib:libmodplug$secondaryArchSuffix
	lib:libmpcdec$secondaryArchSuffix
	lib:libmpeg2$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libsamplerate$secondaryArchSuffix
	lib:libschroedinger_1.0$secondaryArchSuffix
	lib:libspeex$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libtheoradec$secondaryArchSuffix
	lib:libtheoraenc$secondaryArchSuffix
	lib:libtwolame$secondaryArchSuffix
#	lib:libupnp$secondaryArchSuffix					# deadlock during upnp devices scan
	lib:libvorbis$secondaryArchSuffix
	lib:libvorbisenc$secondaryArchSuffix
	lib:libvpx$secondaryArchSuffix
	lib:libx264$secondaryArchSuffix
	lib:libx265$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liba52$secondaryArchSuffix
	devel:libass$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libbluray$secondaryArchSuffix
	devel:libcddb$secondaryArchSuffix
	devel:libdca$secondaryArchSuffix
	devel:libdvbpsi$secondaryArchSuffix
	devel:libdvdcss$secondaryArchSuffix
	devel:libdvdnav$secondaryArchSuffix
	devel:libdvdread$secondaryArchSuffix
	devel:libebml$secondaryArchSuffix
	devel:libenca$secondaryArchSuffix
	devel:libfaad$secondaryArchSuffix
	devel:libflac$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libgnutls$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libmad$secondaryArchSuffix
	devel:libmatroska$secondaryArchSuffix
	devel:libmodplug$secondaryArchSuffix
	devel:libmpcdec$secondaryArchSuffix
	devel:libmpeg2$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libsamplerate$secondaryArchSuffix
	devel:libschroedinger_1.0$secondaryArchSuffix
	devel:libspeex$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libtag$secondaryArchSuffix
	devel:libtheora$secondaryArchSuffix
	devel:libtwolame$secondaryArchSuffix
#	devel:libupnp$secondaryArchSuffix				# deadlock during upnp devices scan
	devel:libvorbis$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	devel:libx264$secondaryArchSuffix
	devel:libx265$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:live555$secondaryArchSuffix
	"

BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoreconf
	cmd:gcc$secondaryArchSuffix
	cmd:gettext$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:xargs
	cmd:yacc
	"

BUILD()
{
	unzip -o $portDir/additional-files/haikuicons.zip -d $sourceDir

	autoreconf

	export BUILDCC=gcc
	export CFLAGS="-lgnu -lnetwork"
	export CXXFLAGS="-lgnu -lnetwork"

	runConfigure ./configure \
		--prefix=$appsDir/VLC \
		--bindir=$appsDir/VLC \
		--libdir=$appsDir/VLC/lib \
		--datarootdir=$appsDir/VLC/data \
		--datadir=$appsDir/VLC/data \
		--disable-rpath \
		--with-default-font=`finddir B_SYSTEM_FONTS_DIRECTORY`/ttfonts/NotoMono-Regular.ttf \
		--with-default-font-family=Sans \
		--with-default-monospace-font-family=Monospace \
		--disable-dependency-tracking \
		--enable-run-as-root \
		--disable-update-check \
		--enable-fast-install \
		--disable-lua

	make $jobArgs

	cd haiku
	gcc VLCLauncher.cpp -lbe -o "VLC media player"
}

INSTALL()
{
	make install-strip

	rm -rf $appsDir/VLC/data/{applications,icons,kde4}
	rm -rf $appsDir/VLC/{cvlc,qvlc,rvlc,vlc-wrapper}
	rm -rf $developDir $manDir $docDir $appsDir/VLC/lib/pkgconfig
	find $appsDir/VLC/lib -name '*.a' -delete
	find $appsDir/VLC/lib -name '*.la' -delete

	cp "haiku/VLC media player" $appsDir/VLC
	mv $appsDir/VLC/vlc $appsDir/VLC/VLC
	mkdir -p $prefix/bin
	ln -s $appsDir/VLC/VLC $prefix/bin/vlc

	local APP_SIGNATURE="application/x-vnd.vlc"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	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/vlc.rdef.in > vlc.rdef

	addResourcesToBinaries vlc.rdef $appsDir/VLC/VLC

	local APP_SIGNATURE="application/x-vnd.vlc-launcher"
	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/vlc_launcher.rdef.in > vlc_launcher.rdef

	addResourcesToBinaries vlc_launcher.rdef "$appsDir/VLC/VLC media player"

	addAppDeskbarSymlink $appsDir/VLC/VLC "VLC media player"
}
