# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=libfabric
pkgver=1.22.0
pkgrel=1
pkgdesc="User-space API for OpenFabrics Interfaces (OFI)"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://ofiwg.github.io/libfabric/"
license=(GPL2)
depends=(glibc gcc-libs numactl)
options=(!lto)
source=(https://github.com/ofiwg/libfabric/releases/download/v${pkgver}/libfabric-${pkgver}.tar.bz2
        ${pkgname}-riscv-page-size.patch::https://github.com/ofiwg/libfabric/pull/10308.diff)
sha512sums=('02fe0713ab96288addef8777b0912f3db200720b42bb6976c8c6796c08de8e1a54bfb7b44d98c334c5184e24ffcf35eab40323e43a605d699630e5eee53548f8'
            'fd5bac99c0125ea048019a1191ed7fad033b026ea34d008b6042f005d655f8a89d2e4b71b359eebf9e40ab9c9a2f15442a927fa966ae3ae5c1a62d42392c052f')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -Np1 -i ${srcdir}/${pkgname}-riscv-page-size.patch
  autoreconf -fvi
}

build() {
  cd ${pkgname}-${pkgver}

  case "${CARCH}" in
    powerpc) CFLAGS+=' -latomic -Wno-incompatible-pointer-types' ;;
  esac

  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd ${pkgname}-${pkgver}
  make test
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install
}
