# $Id: PKGBUILD 150832 2012-02-23 12:01:17Z juergen $
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Ronald van Haren <ronald.archlinux.org>
# Contributor: Damir Perisa <damir@archlinux.org>
# Modified to compile against ecl by: maribu

pkgname=maxima-ecl
_pkgname=maxima
pkgver=5.37.2
_eclver=16.0.0
pkgrel=2
pkgdesc="A sophisticated computer algebra system (compiled against ecl)"
arch=(i686 x86_64)
license=(GPL)
url="http://maxima.sourceforge.net"
depends=(ecl=$_eclver texinfo)
makedepends=(python2 emacs patch)
optdepends=('gnuplot: plotting capabilities' 'rlwrap: readline support via /usr/bin/rmaxima' 'tk: graphical xmaxima interface')
conflicts=(maxima)
provides=(maxima)
options=(!zipman) # don't zip info pages or they won't work inside maxima
install=maxima.install
source=("http://downloads.sourceforge.net/sourceforge/${_pkgname}/${_pkgname}-${pkgver}.tar.gz"
        "${_pkgname}.desktop" 'build-fasl.patch' 'matrixexp.patch')
md5sums=('1038d68116a9b516e046a76f68ba5115'
         '24aa81126fbb8b726854e5a80d4c2415'
         'eb33481ea06afb97743af06ff52c099b'
         '0a1fb7bb0cfdede965252b75decc2c0d')

prepare() {
  cd $_pkgname-$pkgver

# set correct python executable to create docs
  sed -i "s|${PYTHONBIN:-python}|python2|" doc/info/extract_categories.sh

# build maxima ecl library
  patch -p1 -i ../build-fasl.patch
# fix matrix exponentiation
  patch -p1 -i ../matrixexp.patch
}

build() {
  cd $_pkgname-$pkgver

  # set correct python executable to create docs
  sed -i "s|${PYTHONBIN:-python}|python2|" doc/info/extract_categories.sh

  ./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info \
	--libexecdir=/usr/lib --enable-ecl --with-default-lisp=ecl
  make -j1
}

package() {
  cd $_pkgname-$pkgver
  make DESTDIR="$pkgdir" emacsdir=/usr/share/emacs/site-lisp/maxima install

  # install some freedesktop.org compatibility
  install -Dm644 ${srcdir}/${_pkgname}.desktop \
  	$pkgdir/usr/share/applications/${_pkgname}.desktop

  # make sure, we have a nice icon for the desktop file at the right place
  install -d $pkgdir/usr/share/pixmaps/
  ln -s /usr/share/maxima/${pkgver}/xmaxima/maxima-new.png \
	$pkgdir/usr/share/pixmaps/${_pkgname}.png

  _ecldir="/usr/lib/ecl-$_eclver"
  mkdir -p "$pkgdir/$_ecldir"
  install src/binary-ecl/maxima.fas "$pkgdir/$_ecldir"
}
