# $Id$
# Maintainer: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Damir Perisa <damir.perisa@bluewin.ch>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - upstream patches to fix ARM signed char FTBFS

pkgbase=openbabel
pkgname=(openbabel python-openbabel)
pkgver=2.4.1
pkgrel=5
pkgdesc="A library designed to interconvert between many file formats used in molecular modeling and computational chemistry"
arch=('x86_64')
url="http://openbabel.org/wiki/Main_Page"
license=('GPL')
makedepends=('cmake' 'eigen' 'wxgtk' 'boost' 'python')
source=("http://downloads.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.gz"
        'https://github.com/openbabel/openbabel/commit/e26491017efefdc6aaf73d4d49f284f4e9436244.patch'
        'https://github.com/openbabel/openbabel/commit/8d707b8ebbe1742b0f626032cd6227eeb62393ac.patch')
md5sums=('d9defcd7830b0592fece4fe54a137b99'
         '2ee91aaa28ba948b363f24558a14820a'
         '247a9b482deb7bfc8722bda5b8a8e092')

prepare() {
  mkdir -p build

  cd openbabel-$pkgver
  patch -p1 -i ../e26491017efefdc6aaf73d4d49f284f4e9436244.patch
  patch -p1 -i ../8d707b8ebbe1742b0f626032cd6227eeb62393ac.patch
}

build() {
  cd build
  #export CXXFLAGS+=' -std=gnu++98'
  cmake ../openbabel-$pkgver \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr -DwxWidgets_CONFIG_EXECUTABLE=/usr/bin/wx-config \
    -DPYTHON_BINDINGS=ON
  make

  # To split python bindings
  sed -i '/scripts.cmake_install.cmake/d' cmake_install.cmake
}

package_openbabel() {
  depends=('libxml2' 'libsm')
  optdepends=('wxgtk: GUI interface')

  cd build
  make DESTDIR="$pkgdir" install
}

package_python-openbabel() {
  depends=('python' 'openbabel')

  cd build/scripts
  make DESTDIR="$pkgdir" install
}