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

pkgname=brial
pkgver=1.2.5
pkgrel=4
pkgdesc="Library for polynomials over boolean rings"
arch=(x86_64)
url="https://github.com/BRiAl/BRiAl"
license=(GPL)
depends=(m4ri)
makedepends=(boost python python2)
optdepends=('python: Python 3 bindings' 'python2: Python 2 bindings')
source=("https://github.com/BRiAl/BRiAl/releases/download/$pkgver/brial-$pkgver.tar.bz2"
        brial-imp.patch)
sha256sums=('c4921d5008ac9122452e6f93abb696ef21ceac8e7170008ea7c7b05508da8d34'
            '2f16ac32f905980ea49e2a4cdc7d44a3eec4d794e4cbde24a583a8d1045df2f8')

prepare() {
  cp -r $pkgname-$pkgver/sage-brial{,-py2}

  cd $pkgname-$pkgver/sage-brial
  patch -p1 -i "$srcdir"/brial-imp.patch # For away from deprecated imp module
}

build() {
  cd $pkgname-$pkgver 

  export PYTHON=python2
  ./configure --prefix=/usr --enable-shared
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool # https://bugzilla.gnome.org/show_bug.cgi?id=655517

  make

  cd sage-brial
  python setup.py build
  cd ../sage-brial-py2
  python2 setup.py build
}

package() {
  cd $pkgname-$pkgver

  make DESTDIR="$pkgdir" install

  cd sage-brial
  python setup.py install --skip-build --root="$pkgdir" --optimize=1
  cd ../sage-brial-py2
  python2 setup.py install --skip-build --root="$pkgdir" --optimize=1
}
