# Template file for 'libucontext'
pkgname=libucontext
version=0.1.3
revision=1
short_desc="Compatibility layer providing ucontext functions"
maintainer="Peter Bui <pbui@github.bx612.space>"
license="ISC"
homepage="https://github.com/kaniini/libucontext"
distfiles="https://distfiles.dereferenced.org/${pkgname}/${pkgname}-${version}.tar.xz"
only_for_archs="aarch64-musl armv5tel-musl armv6l-musl armv7l-musl i686-musl mips-musl mipshf-musl mipsel-musl mipselhf-musl x86_64-musl"
checksum=da530b2f4469f9adcef678b9c1bf07f2a66ea922251d9bcf13b691f09a08883e

case "${XBPS_TARGET_MACHINE}" in
arm*)	export LIBUCONTEXT_ARCH="arm";;
i686*)	export LIBUCONTEXT_ARCH="x86";;
*)	export LIBUCONTEXT_ARCH="${XBPS_TARGET_MACHINE%%-musl}";;
esac

do_build() {
	case "${XBPS_TARGET_MACHINE}" in
	i686*) sed -i arch/x86/startcontext.S -e "s;__i686.get_pc_thunk.bx;i686_get_pc_thunk_bx;g" ;;
	esac
	make ARCH="${LIBUCONTEXT_ARCH}"
}

do_check() {
	make ARCH="${LIBUCONTEXT_ARCH}" check
}

do_install() {
	make ARCH="${LIBUCONTEXT_ARCH}" DESTDIR="${DESTDIR}/usr" install
}

post_install() {
	vlicense LICENSE
}

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