# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gc
pkgver=7.6.4
pkgrel=2
pkgdesc="A garbage collector for C and C++"
url="http://hboehm.info/gc/"
arch="all"
license="GPL"
makedepends="libatomic_ops-dev linux-headers"
subpackages="$pkgname-dev $pkgname-doc libgc++:libgccpp"
source="http://hboehm.info/gc/gc_source/gc-$pkgver.tar.gz
	0001-Fix-gctest-with-musl-libc-on-s390x.patch
	fix-boehm-gc.patch
	"
builddir="$srcdir/gc-${pkgver%[a-z]}"

build() {
	cd "$builddir"

	if [ "$CLIBC" = "musl" ]; then
		export CFLAGS="$CFLAGS -D_GNU_SOURCE -DNO_GETCONTEXT -DUSE_MMAP -DHAVE_DL_ITERATE_PHDR"
	fi
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--datadir=/usr/share/doc/gc \
		--enable-cplusplus
	make
}

check() {
	cd "$builddir"

	# two FAILs due to grsecurity
	make check
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
}

libgccpp() {
	install -d "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgccpp.* "$subpkgdir"/usr/lib/
}

sha512sums="2c85be3e24b85732b3dc6f08fe98cf1a82b6fb2a22ec73090f80920721c737ef92cee8f0cd7ea7228d686005d164e7da54ce3907c3a1ba5eefa43355a472085e  gc-7.6.4.tar.gz
829b68d88a48a8e414f9d509d8da87a6a127fc90b871d0c30596fe9cb39e3fe093d671160d86db1affda246e2409b05dd33e1190e36f2c4d0e784fffd404b652  0001-Fix-gctest-with-musl-libc-on-s390x.patch
6439505931f0d023bf27d6ce0af90d09dc23bb9dd49b561566ec54b2cddc20642be9bd7b41203f643cb6efed3db2f54aef410b436f3acc2351fe4bb0a8791ea4  fix-boehm-gc.patch"
