# Template file for 'libunwind'
pkgname=libunwind
version=1.8.1
revision=1
build_style=gnu-configure
hostmakedepends="libtool automake"
makedepends="liblzma-devel"
short_desc="Library to determine the call-chain of a program"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://www.nongnu.org/libunwind/"
distfiles="https://github.com/libunwind/libunwind/releases/download/v${version}/libunwind-${version}.tar.gz"
checksum=ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157
# many test failures
make_check=no

# Enable C++ exception handling (doesn't work too well on x86)
case "$XBPS_TARGET_MACHINE" in
	x86_64*|i686*) ;;
	*) configure_args+=" --enable-cxx-exceptions" ;;
esac

# LDFLAGS is necessary because libunwind.so itself uses getcontext/setcontext
case "$XBPS_TARGET_MACHINE" in
	i686-musl) LDFLAGS=" -lssp_nonshared" ;;
	ppc64*-musl) makedepends+=" libucontext-devel"; LDFLAGS=" -lucontext" ;;
	ppc*-musl) makedepends+=" libucontext-devel"; LDFLAGS=" -lucontext -lssp_nonshared" ;;
	mips*-musl) CLAGS="-D_MIPS_SIM=_ABI32" ;;
	*) ;;
esac

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	checkdepends+=" libexecinfo-devel"
fi

pre_configure() {
	# unw_getcontext is just getcontext on ppc*, separate lib for musl
	# it needs to be here because it's used directly in a macro in a
	# public header, so things using libunwind need linkage against it
	case "$XBPS_TARGET_MACHINE" in
		i686-musl|ppc*-musl)
			vsed -i src/unwind/libunwind.pc.in -e \
				's/\-lunwind/\-lunwind \-lucontext/'
		;;
	esac

	autoreconf -fi
}

post_install() {
	vlicense COPYING LICENSE
}

libunwind-devel_package() {
	depends="${sourcepkg}>=${version}"

	case "$XBPS_TARGET_MACHINE" in
		i686-musl|ppc*-musl) depends+=" libucontext-devel" ;;
		*) ;;
	esac

	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/share
	}
}
