# Template file for 'libucontext'
pkgname=libucontext
version=1.0
revision=1
archs="*-musl"
wrksrc="${pkgname}-${pkgname}-${version}"
short_desc="Compatibility layer providing ucontext functions"
maintainer="Orphaned <orphan@voidlinux.org>"
license="ISC"
homepage="https://github.com/kaniini/libucontext"
distfiles="https://github.com/kaniini/libucontext/archive/${pkgname}-${version}.tar.gz"
checksum=23714e99a87f6dea82e8a073c526325161dd65462459820b16a6162be91955bb

case "${XBPS_TARGET_MACHINE}" in
	x86_64*)  _luctx_arch="x86_64"  ;;
	i686*)    _luctx_arch="x86"     ;;
	aarch64*) _luctx_arch="aarch64" ;;
	arm*)     _luctx_arch="arm"     ;;
	ppc64*)   _luctx_arch="ppc64"   ;;
	ppc*)     _luctx_arch="ppc"     ;;
	mips*64*) _luctx_arch="mips64"  ;;
	mips*)    _luctx_arch="mips"    ;;
	riscv64*) _luctx_arch="riscv64" ;;
	s390x*)   _luctx_arch="s390x"   ;;
	*) broken="libucontext not available for ${XBPS_TARGET_MACHINE}";;
esac

# we provide our own CFLAGS, which overwrite all of theirs
export CFLAGS=" -DEXPORT_UNPREFIXED"

do_build() {
	make ARCH="${_luctx_arch}" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
}

do_check() {
	make ARCH="${_luctx_arch}" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" check
}

do_install() {
	make ARCH="${_luctx_arch}" DESTDIR="${DESTDIR}" LIBDIR="/usr/lib" install
	# missing from release?
	ln -s libucontext_posix.so.1 ${DESTDIR}/usr/lib/libucontext_posix.so
}

post_install() {
	vlicense LICENSE
}

libucontext-devel_package() {
	depends="libucontext>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.a"
	}
}
