# Maintainer: Markus M. May <triplem@tu.archserver.org>
# Contributor: Paul Mattal <paul@archlinux.org>
# Contributor: Jason Chu <jason@archlinux.org>

pkgname=subversion
pkgver=1.6.16
pkgrel=1
pkgdesc="Replacement for CVS, another versioning system (SVN)"
arch=('i686' 'x86_64')
license=('apache' 'bsd')
depends=('apr-util' 'neon')
makedepends=('heimdal' 'apache' 'python' 'perl' 'swig' 'ruby' 'java-environment' 
             'autoconf' 'sqlite3' 'db' 'e2fsprogs')
source=(http://subversion.tigris.org/downloads/$pkgname-$pkgver.tar.bz2
        svnserve 
        svn 
        svnserve.conf 
        svnmerge.py
        subversion.rpath.fix.patch
        subversion.suppress.deprecation.warnings.patch)
backup=('etc/xinetd.d/svn' 'etc/conf.d/svnserve')
url="http://subversion.apache.org/"
provides=('svn')
options=('!makeflags' '!libtool')
optdepends=('bash-completion: for svn bash completion')
md5sums=('32f25a6724559fe8691d1f57a63f636e'
         'a2b029e8385007ffb99b437b30521c90'
         'bd95f605976cb80f0eb773cda04e3e3d'
         'c459e299192552f61578f3438abf0664'
         '21bf3aa5b797ce98eba8307f30e9c070'
         '6b4340ba9d8845cd8497e013ae01be3f'
         'b1b02eb6ea8ea5cfa9168661f770cae9')
         
build() {
   cd ${srcdir}/${pkgname}-${pkgver}

   # apply patches
   patch -p0 < $srcdir/subversion.rpath.fix.patch
   patch -p1 -i $srcdir/subversion.suppress.deprecation.warnings.patch

   export PYTHON=/usr/bin/python
   
   # configure
   # we are using a static library, therefor this is not automatically found
   # by ld, we provide it with LDFLAGS
   autoreconf
   ./configure --prefix=/usr --with-apr=/usr --with-apr-util=/usr \
               --with-zlib=/usr --with-neon=/usr --with-apxs \
               --with-sqlite=/usr --with-berkeley-db=:/usr/include/:/usr/lib:db-4.8 \
               --enable-javahl --without-gnome-keyring --without-kwallet \
               LDFLAGS="-L/opt/ruby-enterprise/lib"

   # build
   (make external-all && make LT_LDFLAGS="-L$Fdestdir/usr/lib" local-all )
}

package() {
   cd ${srcdir}/${pkgname}-${pkgver}

   # install
   export LD_LIBRARY_PATH=${pkgdir}/usr/lib:$LD_LIBRARY_PATH
   make DESTDIR=${pkgdir} install

   make DESTDIR=${pkgdir} swig-py
   make install-swig-py DESTDIR=${pkgdir}

   install -d ${pkgdir}/usr/lib/python2.7
   mv ${pkgdir}/usr/lib/svn-python/ ${pkgdir}/usr/lib/python2.7/site-packages

   install -d ${pkgdir}/usr/share/subversion
   install -d -m 755 tools/hook-scripts ${pkgdir}/usr/share/subversion/
   rm -f ${pkgdir}/usr/share/subversion/hook-scripts/*.in

   make DESTDIR=${pkgdir} swig-pl
   make install-swig-pl DESTDIR=${pkgdir} INSTALLDIRS=vendor
   rm -f ${pkgdir}/usr/lib/perl5/vendor_perl/auto/SVN/_Core/.packlist
   rm -rf ${pkgdir}/usr/lib/perl5/core_perl

   make DESTDIR=${pkgdir} swig-rb
   make install-swig-rb DESTDIR=${pkgdir}

   make DESTDIR=${pkgdir} javahl
   make DESTDIR=${pkgdir} install-javahl

   install -d ${pkgdir}/etc/{rc.d,xinetd.d,conf.d}

   install -m 755 ${srcdir}/svnserve ${pkgdir}/etc/rc.d
   install -m 644 ${srcdir}/svn ${pkgdir}/etc/xinetd.d
   install -m 644 ${srcdir}/svnserve.conf ${pkgdir}/etc/conf.d/svnserve
   install -m 755 ${srcdir}/svnmerge.py ${pkgdir}/usr/bin/svnmerge
   install -D -m 644 ${srcdir}/subversion-$pkgver/COPYING \
               ${pkgdir}/usr/share/licenses/$pkgname/LICENSE

   # bash completion
   install -Dm 644 ${srcdir}/${pkgname}-${pkgver}/tools/client-side/bash_completion \
               ${pkgdir}/etc/bash_completion.d/subversion
}
