# $Id: PKGBUILD 137215 2015-07-21 13:57:45Z alucryd $
# Maintainer: Ray Rashif <schiv@archlinux.org>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>
# Contributor: Jaroslaw Swierczynski <swiergot@aur.archlinux.org>
# Contributor: Alexander Rødseth <rodseth@gmail.com>

pkgname=cinelerra-cv
pkgver=2.2
_gitrel=2.2.0
pkgrel=26
epoch=1
pkgdesc="Professional video editing and compositing environment"
arch=('x86_64' 'i686')
url="http://cinelerra.org/"
license=('GPL')
depends=('e2fsprogs' 'libavc1394' 'libiec61883' 'libxv'
         'libtiff' 'mjpegtools' 'fftw' 'a52dec' 'glu'
         'ffmpeg' 'faad2' 'faac' 'openexr>=2.0.0')
makedepends=('git' 'nasm' 'mesa')
source=("$pkgname::git+git://git.cinelerra-cv.org/CinelerraCV.git#branch=rel$_gitrel"
        'v4l1_removal.patch'
        'ffmpeg_api.patch'
        'ffmpeg2.0.patch'
        'cinelerra-std_and_str_h.patch'
        'gcc5fix.patch')
md5sums=('SKIP'
         'bfa85e20809429d88eba4ab83e569612'
         'b05ec2fb54e7d02f6167525417802111'
         '14dd897084d64cd0b5e9caa8a69818bd'
         '02d8222e596133bbc05eaad15bef242c'
         '7bf8fe04ce242d8aa76dba94897eac4e')

prepare() {
  cd "$srcdir/$pkgname"

  ## Patches (oldest first) ##

  # v4l1 removal patch
  patch -Np1 -i "$srcdir/v4l1_removal.patch"

  # ffmpeg api patch update for 0.11
  patch -Np1 -i "$srcdir/ffmpeg_api.patch"

  # fix some missing headers
  patch -Np0 -i "$srcdir/cinelerra-std_and_str_h.patch"

  # fix avcodec_alloc_context and alloc_open
  patch -Np1 -i "$srcdir/ffmpeg2.0.patch"

  ## Hacks ##

  # if you don't need OpenGL comment out the next line (and no glu/mesa dep)
  # TODO: check if this is still needed (pre-svn commit) --schiv
  #sed -i '/\/X11R6/s///' configure.in

  # TODO: check if this is still needed (old commit; r29539 by ibiru) --schiv
  #sed -i -e '/Debian/d' admin/nasm

  # ffmpeg 2.0 related replacements
  # TODO: super slow on HDDs, but proper patch requires merging with others
  find -type f -exec sed -i 's/AVCODEC_MAX_AUDIO_FRAME_SIZE/192000/' {} \;
  find -type f -exec sed -i 's/CodecID/AVCodecID/' {} \;

  # gcc 5.x fix
  patch -Np1 -i "$srcdir/gcc5fix.patch"
}

build() {
  cd "$srcdir/$pkgname"

  ## More Hacks (must be in existing env) ##

  # gcc 4.6 workaround
  export CFLAGS+=" -Wwrite-strings -D__STDC_CONSTANT_MACROS"
  export CPPFLAGS="$CFLAGS"

  # remove executable stack
  export LDFLAGS+=" -Wl,-z,noexecstack"

  ./autogen.sh

  # disable mmx due to improper use of registers in asm
  # - possibly a new problem since gcc 4.9
  ./configure --prefix=/usr \
              --with-buildinfo=git/recompile \
              --with-external-ffmpeg \
              --enable-opengl \
              --disable-mmx \
              --disable-esd

  make
}

package() {
  cd "$srcdir/$pkgname"

  make DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:
