# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ivan Maidanski <ivmai@mail.ru>

pkgbase=gc
pkgname=('libgc' 'libgc-devel')
pkgver=8.2.8
pkgrel=1
pkgdesc="A garbage collector for C and C++"
arch=('i686' 'x86_64')
groups=('libraries')
url="https://www.hboehm.info/gc/"
msys2_repository_url="https://github.com/ivmai/bdwgc"
msys2_references=(
  "cpe: cpe:/a:boehm-demers-weiser:garbage_collector"
  "cpe: cpe:/a:bdwgc_project:bdwgc"
)
license=('MIT')
makedepends=('autotools' 'gcc')
source=("https://github.com/ivmai/bdwgc/releases/download/v${pkgver}/${pkgbase}-${pkgver}.tar.gz")
options=('!libtool')
sha256sums=('7649020621cb26325e1fb5c8742590d92fb48ce5c259b502faf7d9fb5dabb160')

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  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=none

  make
}

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

  make check
}

package_libgc() {
  depends=('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}")

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

  make DESTDIR=${pkgdir} install

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