# Template file for 'apr'
pkgname=apr
version=1.7.6
revision=1
build_style=gnu-configure
configure_args="--with-installbuilddir=/usr/share/apr-1/build"
makedepends="expat-devel libuuid-devel"
checkdepends="gdb iana-etc"
short_desc="Apache Portable Runtime Library"
maintainer="Orphaned <orphan@voidlinux.org>"
license="Apache-2.0"
homepage="https://apr.apache.org/"
distfiles="https://archive.apache.org/dist/apr/apr-${version}.tar.bz2"
checksum=49030d92d2575da735791b496dc322f3ce5cff9494779ba8cc28c7f46c5deb32

# Can't run test programs when cross compiling
# NOTE always diff between native and cross build!!!
if [ "$CROSS_BUILD" ]; then
	configure_args+=" apr_cv_pthreads_cflags=-pthread"
	configure_args+=" apr_cv_process_shared_works=yes"
	configure_args+=" apr_cv_mutex_robust_shared=yes"
	configure_args+=" apr_cv_tcp_nodelay_with_cork=yes"
	configure_args+=" ac_cv_func_sem_open=yes"
	configure_args+=" ac_cv_mmap__dev_zero=yes"
	configure_args+=" ac_cv_struct_rlimit=yes"
fi

# The apr package doesn't use crypt_r, however apr-util does,
# and apr-util uses the apr.h generated by apr's ./configure.
if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	makedepends+=" libxcrypt-devel"
fi

do_check() {
	local _args
	cd test
	if [ "$XBPS_BUILD_ENVIRONMENT" = void-packages-ci ]; then
		sed -i 's/if BROKEN_IN_CI/if 0/' testsockets.c
		if [ "$XBPS_LIBC" = musl ]; then
			# unable to resolve back from 127.0.0.1
			_args="-x testsock"
		fi
	fi
	make ${makejobs}
	./testall ${_args}
}

post_install() {
	sed -i -e 's,-ffile-prefix-map=[^[:space:]]*,,' \
		"$DESTDIR/usr/share/apr-1/build/apr_rules.mk"
	if [ "$CROSS_BUILD" ]; then
		sed -i -e 's;cross_compiling=.*;cross_compiling=;' \
			"$DESTDIR/usr/bin/apr-1-config"
		sed -i -e "s,$XBPS_CROSS_BASE,,g" \
			"$DESTDIR/usr/share/apr-1/build/apr_rules.mk"
	fi
}

apr-devel_package() {
	depends="libtool libuuid-devel apr>=${version}_${revision}"
	if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
		depends+=" libxcrypt-devel"
	fi
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/bin
		vmove usr/share
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.exp"
		vmove usr/lib/pkgconfig
		ln -sf ../../../bin/libtool "$PKGDESTDIR/usr/share/apr-1/build/"
	}
}
