# Maintainer: Jakub Klinkovský <lahwaacz at archlinux dot org>

_project=ucx
pkgname=openucx
pkgver=1.15.0
pkgrel=2
pkgdesc="Communication framework for data-centric and high-performance applications"
arch=(x86_64 aarch64)
url="http://www.openucx.org"
license=('BSD')
depends=(
  binutils
  glibc
  zlib
  zstd
)
makedepends=(
  rdma-core
  cuda
  rocm-language-runtime
)
optdepends=(
  'rdma-core: for InfiniBand and RDMA support'
  'cuda: for CUDA support'
  'rocm-language-runtime: for ROCm support'
)
provides=(
  libucm.so
  libucp.so
  libucs.so
  libucs_signal.so
  libuct.so
)
source=("$pkgname-$pkgver.tar.gz::https://github.com/openucx/$_project/archive/refs/tags/v$pkgver.tar.gz"
        "aarch64.patch")
sha256sums=('e3082101dd61b2482390e7917b390f0fe9ecf399a839d97ee025ee559e6cb12d'
            '9f3dbd35673f6eb8cf5eb0723b70fbb43fcf0c4ae265e4381fa22f9461a35dba')

prepare() {
  cd $_project-$pkgver
  patch -Np1 < ../aarch64.patch
}

build() {
  cd $_project-$pkgver
  ./autogen.sh
  # NOTE: upstream suggests running ./contrib/configure-release instead of
  # ./configure for maximal performance, but it contains options that would
  # make debugging much harder
  ./configure \
      --prefix=/usr \
      --with-cuda=/opt/cuda \
      --with-rocm=/opt/rocm \
      --with-verbs \
      --with-rc \
      --with-ud \
      --with-dc \
      --with-mlx5-dv
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make V=1
}

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

  # install the license
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
