# Contributor: Sergei Lukin <sergej.lukin@gmail.com>
# Contributor: Ɓukasz Jendrysik <scadu@yandex.com>
# Contributor: Jakub Skrzypnik <j.skrzypnik@openmailbox.org>
# Maintainer: A. Wilcox <awilfox@adelielinux.org>
pkgname=ffmpeg
pkgver=4.0.2
pkgrel=1
pkgdesc="Record, convert, and stream audio and video"
url="https://ffmpeg.org/"
arch="all"
license="GPL-2.0-only"
options="!check textrels"  # Test suite requires proper licensing headers on all files,
			   # which upstream does not provide.
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs"
makedepends="gnutls-dev lame-dev libvorbis-dev xvidcore-dev zlib-dev libvdpau-dev
	imlib2-dev libtheora-dev coreutils bzip2-dev perl-dev x264-dev
	pulseaudio-dev sdl2-dev libxfixes-dev libva-dev alsa-lib-dev rtmpdump-dev
	v4l-utils-dev yasm opus-dev x265-dev xz-dev freetype-dev speex-dev
	ladspa-dev libcdio-dev libcdio-paranoia-dev wavpack-dev libwebp-dev"
source="https://ffmpeg.org/releases/ffmpeg-$pkgver.tar.xz
	0001-libavutil-clean-up-unused-FF_SYMVER-macro.patch
	altivec-fix.patch
	"

# secfixes:
#   3.3.4-r0:
#     - CVE-2017-14054
#     - CVE-2017-14055
#     - CVE-2017-14056
#     - CVE-2017-14057
#     - CVE-2017-14058
#     - CVE-2017-14059
#     - CVE-2017-14169
#     - CVE-2017-14170
#     - CVE-2017-14171
#     - CVE-2017-14222
#     - CVE-2017-14223
#     - CVE-2017-14225

build() {
	local _dbg="--disable-debug"
	local _asm=""
	[ -n "$DEBUG" ] && _dbg="--enable-debug"

	case "$CARCH" in
	ppc64) _asm="--cpu=G5" ;;
	pmmx) _asm="--disable-asm" ;;
	esac

	cd "$builddir"
	./configure \
		--prefix=/usr \
		--enable-avresample \
		--enable-avfilter \
		--enable-gnutls \
		--enable-gpl \
		--enable-libmp3lame \
		--enable-librtmp \
		--enable-libvorbis \
		--disable-libvpx \
		--enable-libxvid \
		--enable-libx264 \
		--enable-libx265 \
		--enable-libtheora \
		--enable-libv4l2 \
		--enable-postproc \
		--enable-pic \
		--enable-pthreads \
		--enable-shared \
		--enable-libxcb \
		--disable-stripping \
		--disable-static \
		--enable-vaapi \
		--enable-vdpau \
		--enable-libopus \
		--enable-libcdio \
		--enable-ladspa \
		--enable-lzma \
		--enable-libspeex \
		--enable-libfreetype \
		--enable-libwavpack \
		--enable-libwebp \
		--enable-libpulse \
		--optflags="$CFLAGS" \
		$_asm $_dbg
	make
	${CC:-gcc} -o tools/qt-faststart $CFLAGS tools/qt-faststart.c
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install install-man
	install -D -m755 tools/qt-faststart "$pkgdir/usr/bin/qt-faststart"
}

libs() {
	pkgdesc="Libraries for ffmpeg"
	replaces="ffmpeg"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/
}

sha512sums="2dc2b8c66d9c31b6d06da5da336ef45415e3c24fac8c9063cd47f7d4cf688ec4846f88cdd9e841b956cea81e56bb3c6b7655aef503400c7367c32910c28990ac  ffmpeg-4.0.2.tar.xz
32652e18d4eb231a2e32ad1cacffdf33264aac9d459e0e2e6dd91484fced4e1ca5a62886057b1f0b4b1589c014bbe793d17c78adbaffec195f9a75733b5b18cb  0001-libavutil-clean-up-unused-FF_SYMVER-macro.patch
225a87ad4b5564e2cbf35e669cc54adddf7f8ca05fbcfc27ed92f4406d0fd3b27558477afaf4c3c13079b19035d0761d8b2f8af9bc25fcfd727183faa606e4f6  altivec-fix.patch"