# $Id$
# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Daniel Isenmann <daniel@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - pass LIBS="-lm" to configure

pkgname=gegl02
pkgver=0.2.0
pkgrel=7
pkgdesc="Graph based image processing framework (v0.2)"
arch=('i686' 'x86_64')
url="http://www.gegl.org/"
license=('GPL3' 'LGPL3')
depends=('babl' 'libspiro')
makedepends=('intltool' 'ruby' 'lua' 'libopenraw' 'openexr' 'mesa' 'glu' 'ffmpeg' 'librsvg' 'jasper' 'exiv2' 'vala')
optdepends=('libopenraw: openraw plugin'
            'openexr: openexr plugin'
            'ffmpeg: ffmpeg plugin'
            'librsvg: svg plugin'
            'jasper: jasper plugin')
options=(!makeflags)
source=(http://ftp.gimp.org/pub/gegl/${pkgver%.*}/gegl-${pkgver}.tar.bz2
        gegl-0.2.0-ffmpeg-0.11.patch
        gegl-0.2.0-CVE-2012-4433.patch
        gegl-0.2.0-lua-5.2.patch
        gegl-0.2.0-remove-src-over-op.patch)
sha1sums=('764cc66cb3c7b261b8fc18a6268a0e264a91d573'
          'f5e4c0edd32e088f768e303081f1ed2d80588d4c'
          '44d48bd9ad008703de9f8eb683d557bac39a02c8'
          'c78a092b880874ba7784b652bcd9c532e2b9975d'
          'dc9ae21cc5ba0fb47ef05793f0cb169572dfab74')

prepare() {
  cd gegl-${pkgver}
  patch -Np1 -i ../gegl-0.2.0-ffmpeg-0.11.patch
  patch -Np1 -i ../gegl-0.2.0-CVE-2012-4433.patch
  patch -Np1 -i ../gegl-0.2.0-lua-5.2.patch
  patch -Np1 -i ../gegl-0.2.0-remove-src-over-op.patch
  sed -i 's/avcodec_alloc_frame/av_frame_alloc/g' operations/external/ff-*.c

  # Fix build with libopenraw 0.1.0
  sed -i 's/OR_DATA_TYPE_CFA/OR_DATA_TYPE_RAW/' operations/external/openraw.c
  sed -ri 's/(libopenraw(-gnome)?)-1\.0/\1-0.1/' configure.ac
  autoreconf -vi
}

build() {
  cd gegl-${pkgver}
  LIBS="-lm" ./configure  --prefix=/usr  --with-sdl --with-librsvg \
    --with-libavformat --with-jasper --without-umfpack --disable-docs

  # https://bugzilla.gnome.org/show_bug.cgi?id=655517
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd gegl-${pkgver}
  make -k check || :
}

package() {
  cd gegl-${pkgver}
  make DESTDIR="${pkgdir}" install
  rm -r "${pkgdir}/usr/bin"
}