# Maintainer (Arch): David Runge <dvzrv@archlinux.org>
# Contributor (Arch): Federico Cinelli <cinelli@aur.archlinux.org>
# Contributor (Arch): Mateusz Herych   <heniekk@gmail.com>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: Jorge Lopez <jorginho@lavabit.com>

pkgname=libquicktime
pkgver=1.2.4
pkgrel=22
pkgrel+=.parabola1
pkgdesc="A library for reading and writing quicktime files"
pkgdesc+=", without nonfree faac support"
arch=('x86_64')
arch+=('i686' 'armv7h')
license=('LGPL2.1')
url="http://libquicktime.sourceforge.net/"
depends=('glib2' 'glibc' 'zlib')
makedepends=('alsa-lib' 'faad2' 'ffmpeg' 'gtk2' 'lame' 'libdv'
'libglvnd' 'libjpeg-turbo' 'libvorbis' 'libx11' 'libxaw' 'libxext' 'libxt'
'libxv' 'schroedinger' 'sndio' 'x264')
optdepends=('alsa-lib: for lqtplay'
            'ffmpeg: for lqt_ffmpeg plugin'
            'gtk2: for libquicktime_config'
            'lame: for lqt_lame plugin'
            'libdv: for lqt_dv plugin'
            'libglvnd: for lqtplay'
            'libjpeg-turbo: for lqt_mjpeg plugin'
            'libpng: for lqt_png plugin'
            'libvorbis: for lqt_lame and lqt_vorbis plugin'
            'libx11: for lqtplay'
            'libxaw: for lqtplay'
            'libxext: for lqtplay'
            'libxt: for lqtplay'
            'libxv: for lqtplay'
            'schroedinger: for lqt_schroedinger plugin'
            'sndio: for lqtplay'
            'x264: for lqt_x264 plugin')
provides=('libquicktime.so')
source=("https://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.gz"
        "${pkgname}-1.2.4-CVE-2016-2399.patch"
        "${pkgname}-1.2.4-CVE-2017-9122_et_al.patch"
        "${pkgname}-1.2.4-faad2.patch"
        "${pkgname}-1.2.4-ffmpeg2.patch"
        "${pkgname}-1.2.4-ffmpeg29.patch"
        "${pkgname}-1.2.4-ffmpeg4.patch"
        "${pkgname}-1.2.4-ffmpeg-codecs.patch"
        "${pkgname}-1.2.4-libavutil.patch")
sha512sums=('6ab6cd62ae2361bb3ad73725e9e8baa2b03361bc23e9e34b24f90c0e2bec4337de950ed7f30a6a1d2e67ab33e8f0c43538369fd07e417f54b84583a3c331f8dd'
            '759fee13bc96db036063efcd8288c0e467ce811b597cf6c0ceed1c8927593963174f4f3324512db0e773e936a4b9fe5c8d8fc9e0f00b2ce59110661175986f9c'
            '93639d3fe12eefddd1b457be702ec0a4a64a73c44fce6b3134e50bb9a4e7e5f25d256d3ace6ec5e774f2db4c0d68725f3e35e901f7d932a4be9cba566eab528e'
            '3e751330ebbc4026363efd45b21c60c313ea169a57a5cdfa46125e126aab34c2dea3629ce92e7b0b5f14693db4f11723177fd28611e2e979cc8fcd506077509e'
            '32ddf394aad4ed80e89ec72a534e0466268ab0061b991815e905b78eae55a7d935117b0915faf6f7f51bd7e2d9fbaa4b0e07bfcef1ef1e2f4a7e2061c489122d'
            '2a7e06c03b0f64f02b923c1a0e7121f4e1ea735f19a6df8ce8daf18177ead132d1ae921c64f3770042db3bbf29f15a7fcceece835d475e052c4c3bb7139c9e2e'
            '1b11a82d694654976a5f79cd8feb27eec3810e09a66dc58ca576eaf1f96e4948abd4dae7955a7da6cf99ae6ffef9e183b39090d96cc6b5fe216b4c4f4faff7a8'
            '20c535444de1f3e9a68c35ee4eb409f150e6340fd43dda4544791454f42c031b24c08f651e0351f5a22dcb59459ac372aa70d82a1d20482b2d997589e19087fd'
            '691110dc18f6646e2e17f40c6a42911a6b8eaa8cea20b5595f20d218d51da11d11923a3001b7ad7c3ad6bd0d90e712b95ccee5526fa1bec176cd27813e4a775e')
 
replaces=("${pkgname}-libre" "${pkgname}-parabola")
conflicts=("${pkgname}-libre" "${pkgname}-parabola")

prepare() {
  cd "$pkgname-$pkgver"
  # boatload of CVEs: http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=libquicktime
  patch -Np1 -i "../${pkgname}-1.2.4-CVE-2016-2399.patch"
  patch -Np1 -i "../${pkgname}-1.2.4-CVE-2017-9122_et_al.patch"
  # checks for faad2 are broken in configure.ac
  patch -Np1 -i "../${pkgname}-1.2.4-faad2.patch"
  # ffmpeg compatibility is very ancient
  patch -Np1 -i "../${pkgname}-1.2.4-ffmpeg2.patch"
  patch -Np1 -i "../${pkgname}-1.2.4-ffmpeg29.patch"
  patch -Np1 -i "../${pkgname}-1.2.4-ffmpeg4.patch"
  patch -Np1 -i "../${pkgname}-1.2.4-libavutil.patch"
  patch -Np1 -i "../${pkgname}-1.2.4-ffmpeg-codecs.patch"
  autoreconf -vfi
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --enable-gpl \
    --with-ffmpeg \
    --with-libdv \
    --with-x264 \
    --without-doxygen \
    --without-faac
  make
}

package() {
  depends+=('libfaad.so')
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -vDm 644 {AUTHORS,ChangeLog,README,TODO} \
    -t "${pkgdir}/usr/share/doc/${pkgname}"
}
