# Template file for 'xbps'
pkgname=xbps
version=0.37
revision=4
bootstrap=yes
short_desc="The XBPS package system utilities"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://www.voidlinux.eu/xbps"
license="Simplified BSD"

makedepends="zlib-devel openssl-devel libarchive-devel>=3.1.2"
depends="xbps-triggers>=0.75"
conf_files="/etc/xbps/xbps.conf"
replaces="xbps>=0"

if [ -z "$CHROOT_READY" ]; then
	CFLAGS+=" -idirafter ${XBPS_MASTERDIR}/usr/include"
	LDFLAGS+=" -L${XBPS_MASTERDIR}/usr/lib"
else
	hostmakedepends="which pkg-config"
	makedepends+=" atf-devel"

	xbps-tests_package() {
		short_desc+=" - Kyua testsuite"
		replaces="xbps<0.16.3_2 xbps-tests>=0"
		pkg_install() {
			vmove usr/tests
		}
	}

fi

if [ "$XBPS_TARGET_MACHINE" = "i686-musl" ]; then
	# XXX disable SSP until the issue is found.
	CFLAGS+=" -fno-stack-protector"
fi

do_fetch() {
	git clone -b${version} git://github.com/voidlinux/xbps.git xbps-${version}
}

do_configure() {
	if [ "$CHROOT_READY" ]; then
		_args="--enable-tests"
	fi
	HAVE_VASPRINTF=1 ./configure --prefix=/usr --sysconfdir=/etc --enable-debug ${_args}
}

do_build() {
	make ${makejobs}
}

do_install() {
	make DESTDIR=${DESTDIR} install
}

libxbps_package() {
	short_desc+=" - runtime library"
	replaces="xbps<0.16.3_2 libxbps>=0"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}

libxbps-devel_package() {
	short_desc+=" - runtime library (development files)"
	depends="zlib-devel libarchive-devel libxbps>=${version}"
	replaces="xbps-static<0.16.3_2 libxbps-devel>=0"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
	}
}