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

pkgbase=gc
pkgname=('libgc' 'libgc-devel')
pkgver=8.0.4
pkgrel=1
pkgdesc="A garbage collector for C and C++"
arch=('i686' 'x86_64')
groups=('libraries')
url="https://www.hboehm.info/gc/"
license=('GPL')
source=("https://github.com/ivmai/bdwgc/releases/download/v${pkgver}/${pkgbase}-${pkgver}.tar.gz"
        gc-8.0-msys2.patch)
makedepends=(libatomic_ops-devel)
options=('!libtool')
sha256sums=('436a0ddc67b1ac0b0405b61a9675bca9e075c8156f4debd1d06f3a56c7cd289d'
            '28d1a532badc3f83ed804727f99b7189106a1be92f98ac452e7a219ba2f115af')

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  patch -p1 -i ${srcdir}/gc-8.0-msys2.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  ../${pkgbase}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-cplusplus \
    --enable-threads=pthreads \
    --with-libatomic-ops=yes

  make
}

check() {
  cd "${srcdir}/build-${CARCH}"

  make check
}

package_libgc() {
  depends=('libatomic_ops' 'gcc-libs')
  cd "${srcdir}/build-${CARCH}"

  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}/usr/{include,lib}
}

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

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

  make DESTDIR=${pkgdir} install

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