# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=lcalc
pkgver=1.23
pkgrel=18
pkgdesc="C++ L-function class library and command line interface"
arch=(x86_64)
url="http://oto.math.uwaterloo.ca/~mrubinst/L_function_public/L.html"
license=(GPL2)
depends=(pari)
makedepends=(chrpath)
#source=("http://oto.math.uwaterloo.ca/~mrubinst/L_function_public/CODE/L-$pkgver.tar.gz"
source=("https://mirrors.mit.edu/sage/spkg/upstream/lcalc/lcalc-$pkgver.tar.bz2"
        Lcommon.h.patch gcc-4.9.patch pari-2.7.patch gcc-5.patch lcalc-c++11.patch lcalc-system-cflags.patch)
sha256sums=('83d4253ec2f38553b21190d6d0c6b71bab7ea14717f6dde5bd18f60775d3cdb0'
            'cad59ddc93f6fecf238d56e09ab29e59d8b8129d2c8dc10f32b643e86eb1cce1'
            '55c6c9f969593f24c75a85e7a150b876671356aa68ceb8e77c563a645897643e'
            '437e3870342ef4cb5749398ead9381504403e7e1f99efadab95f4a607678b400'
            '66bfa8df3a7cadbe9cfc9f7f05e0dedd0195e68db048e05ce4e1a96d25946aef'
            '89820d96a0106365875246c36d4adf86f4464cba80bf03095c9a21e2fccb8e69'
            '045604ebff18ea126c597f076b7c22f331e5767a8c59f4d726d7e9dd7aef8fc7')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i ../Lcommon.h.patch  
  patch -p1 -i ../gcc-4.9.patch
  patch -p1 -i ../gcc-5.patch
# port to PARI 2.7 API
  patch -p1 -i ../pari-2.7.patch
# Install headers where Sage expects them
  sed -e 's|include/Lfunction|include/libLfunction|g' -i src/Makefile
# make headers C++11 compliant
  patch -p1 -i ../lcalc-c++11.patch
# use system CFLAGS/LDFLAGS
  patch -p1 -i ../lcalc-system-cflags.patch
}

build() {
  cd $pkgname-$pkgver/src
  make PARI_DEFINE="-DINCLUDE_PARI" LOCATION_PARI_H="/usr/include/pari"	LOCATION_PARI_LIBRARY="/usr/lib" all
}

package() {
  cd $pkgname-$pkgver/src
  mkdir -p "$pkgdir"/usr/{bin,include,lib}
  make INSTALL_DIR="$pkgdir"/usr install

# fix wrong permissions
  chmod 644 "$pkgdir"/usr/include/libLfunction/Ldokchitser.h
# fix insecure rpath
  chrpath -d "$pkgdir"/usr/bin/lcalc
}
