#!/bin/sh
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# TODO: implements options VISUAL, TREMOR

PKGNAME=gst-plugins-base
PKGVERSION=1.16.0
PKGREVISION=1
PKGLICENSE="GPLv2"
PKGSUMMARY="gstreamer base plugins"
PKGDOWNLOAD="https://gstreamer.freedesktop.org/src/gst-plugins-base/$PKGNAME-$PKGVERSION.tar.xz"
PKGDEPENDS="dev/meson:build multimedia/gstreamer"
PKGOPTIONS="ALSA CDPARANOIA PANGO NLS OGG OPUS THEORA VORBIS X"

: ${CC:=clang}
: ${CFLAGS:=-O2}
: ${CXX:=clang++}
: ${CXXFLAGS:=-O2}
: ${LDFLAGS:=}
: ${ALSA:=yes}
: ${CDPARANOIA:=yes}
: ${PANGO:=yes}
: ${OGG:=yes}
: ${OPUS:=yes}
: ${THEORA:=yes}
: ${VORBIS:=yes}
: ${X:=yes}

if [ "$ALSA" = "yes" ]; then
	PKGDEPENDS="audio/alsa-lib $PKGDEPENDS"
	with_alsa="-D alsa=enabled"
else
	with_alsa="-D alsa=disabled"
fi

if [ "$CDPARANOIA" = "yes" ]; then
	PKGDEPENDS="audio/cdparanoia $PKGDEPENDS"
	with_cdparanoia="-D cdparanoia=enabled"
else
	with_cdparanoia="-D cdparanoia=disabled"
fi

if [ "$PANGO" = "yes" ]; then
	PKGDEPENDS="fonts/pango $PKGDEPENDS"
	with_pango="-D pango=enabled"
else
	with_pango="-D pango=disabled"
fi

if [ "$OGG" = "yes" ]; then
	PKGDEPENDS="audio/libogg $PKGDEPENDS"
	with_ogg="-D ogg=enabled"
else
	with_ogg="-D ogg=disabled"
fi

if [ "$OPUS" = "yes" ]; then
	PKGDEPENDS="audio/opus $PKGDEPENDS"
	with_opus="-D opus=enabled"
else
	with_opus="-D opus=disabled"
fi

if [ "$THEORA" = "yes" ]; then
	PKGDEPENDS="multimedia/libtheora $PKGDEPENDS"
	with_theora="-D theora=enabled"
else
	with_theora="-D theora=disabled"
fi

if [ "$VORBIS" = "yes" ]; then
	PKGDEPENDS="audio/libvorbis $PKGDEPENDS"
	with_vorbis="-D vorbis=enabled"
else
	with_vorbis="-D vorbis=disabled"
fi

if [ "$X" = "yes" ]; then
	PKGDEPENDS="x11/libxshmfence $PKGDEPENDS"
	with_x="-D x11=enabled -Dxshm=enabled"
else
	with_x="-D x11=disabled -Dxshm=disabled"
fi

build()
{
	rm -rf $PKGNAME-$PKGVERSION
	tar xvf $PKGNAME-$PKGVERSION.tar.xz
	cd $PKGNAME-$PKGVERSION

	CC="$CC" \
	CFLAGS="$CFLAGS" \
	CXX="$CXX" \
	CXXFLAGS="$CXXFLAGS" \
	LDFLAGS="$LDFLAGS" \
	meson \
		--prefix / \
		--buildtype release \
		--default-library shared \
		. build \
		-D tests=disabled \
		$with_alsa \
		$with_cdparanoia \
		$with_pango \
		$with_ogg \
		$with_opus \
		$with_theora \
		$with_vorbis \
		$with_x
	CC="$CC" ninja -C build
	DESTDIR=$DESTDIR ninja -C build install

	cd ..
	rm -rf $PKGNAME-$PKGVERSION
}

