# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=libblastrampoline
pkgver=5.12.0
pkgrel=1
pkgdesc='Using PLT trampolines to provide a BLAS and LAPACK demuxing library'
arch=(x86_64 powerpc64le riscv64)
url='https://github.com/JuliaLinearAlgebra/libblastrampoline'
license=(MIT)
depends=(glibc)
makedepends=(git)
source=(git+https://github.com/JuliaLinearAlgebra/libblastrampoline#tag=v$pkgver)
sha256sums=('ad564955a936a02f7c7f71c4f9337971affb0cbe01669f9398a92b1932b86bee')
options=(!lto)

build() {
  cd $pkgname/src

  case "${CARCH}" in
    powerpc64le) MYARCH="powerpc64le" ;;
    riscv64)     MYARCH="riscv64" ;;
    x86_64)      MYARCH="x86_64" ;;
    *) 
      echo "unsupported architecture"
      return 1
    ;;
  esac

  make\
    COMPLEX_RETSTYLE_AUTODETECTION=0 \
    F2C_AUTODETECTION=0 \
    LBT_CFLAGS="$CFLAGS -fPIC -D_GNU_SOURCE -DARCH_${MYARCH}" \
    LBT_LDFLAGS="-shared $LDFLAGS"
}

package() {
  cd $pkgname/src
  make F2C_AUTODETECTION=0 COMPLEX_RETSTYLE_AUTODETECTION=0 prefix="$pkgdir"/usr install
  install -Dm644 ../LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
}
