# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=libatomic_ops
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=7.8.2
pkgrel=1
pkgdesc="Provides semi-portable access to hardware provided atomic memory operations"
arch=('any')
url="https://github.com/ivmai/libatomic_ops"
msys2_references=(
  "anitya: 1561"
  "cpe: cpe:2.3:a:libatomic_ops_project:libatomic_ops"
)
makedepends=('autotools' 'gcc')
license=('spdx:GPL-2.0-or-later AND MIT')
source=("https://github.com/ivmai/${pkgbase}/releases/download/v${pkgver}/${pkgbase}-${pkgver}.tar.gz")
sha256sums=('d305207fe207f2b3fb5cb4c019da12b44ce3fcbc593dfd5080d867b1a2419b51')

prepare(){
  cd ${srcdir}/${pkgbase}-${pkgver}

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${CHOST} ]] && rm -rf ${srcdir}/build-${CHOST}
  mkdir -p ${srcdir}/build-${CHOST} && cd ${srcdir}/build-${CHOST}

  export MSYSTEM=CYGWIN
  ../${pkgbase}-${pkgver}/configure \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static
  make
}

check() {
  cd ${srcdir}/build-${CHOST}
  PATH="${srcdir}/build-${CHOST}/src/.libs:$PATH" make check
}

package_libatomic_ops() {
  cd "${srcdir}/build-${CHOST}"
  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}/usr/{include,lib,share}
  install -Dm644 ${srcdir}/${pkgbase}-${pkgver}/LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libatomic_ops-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("libatomic_ops=${pkgver}")

  cd "${srcdir}/build-${CHOST}"

  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}/usr/bin
}
