SUMMARY="A UPnP Media Server"
DESCRIPTION="Gerbera is a UPnP media server which allows you to stream \
your digital media through your home network and consume it on a variety of \
UPnP compatible devices."
HOMEPAGE="https://docs.gerbera.io"
COPYRIGHT="2005-2010 Gena Batyan, Sergey 'Jin' Bostandzhyan, Leonhard Wimmer
	2020-2021 Gerbera Contributors"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/gerbera/gerbera/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="dee562cc5d22e8442e2fe1620b073bda612c80f9c4a8333311c647db06c1c4cd"
SOURCE_FILENAME="gerbera-$portVersion.tar.gz"
PATCHES="gerbera-$portVersion.patchset"
ADDITIONAL_FILES="config.xml
	install_config.sh
	"

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

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

GLOBAL_WRITABLE_FILES="
	settings/gerbera/config.xml keep-old
	"
POST_INSTALL_SCRIPTS="
	$relativePostInstallDir/install_config.sh
	"

PROVIDES="
	gerbera$secondaryArchSuffix = $portVersion
	cmd:gerbera$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libatomic$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libduktape$secondaryArchSuffix
	lib:libebml$secondaryArchSuffix
	lib:libexif$secondaryArchSuffix
#	lib:libffmpegthumbnailer$secondaryArchSuffix
	lib:libfmt$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libmagic$secondaryArchSuffix
	lib:libmatroska$secondaryArchSuffix
	lib:libnpupnp$secondaryArchSuffix
	lib:libpugixml$secondaryArchSuffix
	lib:libspdlog$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libatomic$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libduktape$secondaryArchSuffix
	devel:libebml$secondaryArchSuffix
	devel:libexif$secondaryArchSuffix
#	devel:libffmpegthumbnailer$secondaryArchSuffix
	devel:libfmt$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libmagic$secondaryArchSuffix
	devel:libmatroska$secondaryArchSuffix
	devel:libnpupnp$secondaryArchSuffix >= 4.2.0
	devel:libpugixml$secondaryArchSuffix
	devel:libspdlog$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libtag$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix
	devel:libgtest$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cmake -B build -S . \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir \
		-DCMAKE_INSTALL_DATADIR=$dataDir/gerbera \
		-DCMAKE_INSTALL_MANDIR=$manDir/man1 \
		-DCMAKE_EXE_LINKER_FLAGS="-lnetwork" \
		-DCMAKE_CXX_FLAGS="-D_DEFAULT_SOURCE" \
		-DWITH_INOTIFY=NO \
		-DWITH_SYSTEMD=NO \
		-DWITH_NPUPNP=YES \
		-DWITH_AVCODEC=YES \
		-DWITH_TESTS=OFF #\
#		-DWITH_FFMPEGTHUMBNAILER=YES # doesn't produce thumbnails

	make $jobArgs -C build
}

INSTALL()
{
	make -C build install

	mkdir -p $settingsDir/gerbera
	cp $portDir/additional-files/config.xml $settingsDir/gerbera

	mkdir -p $postInstallDir
	cp $portDir/additional-files/install_config.sh $postInstallDir
}

TEST()
{
	make -C build test
}
