# Template file for 'apr'
pkgname=apr
version=1.7.0
revision=4
build_style=gnu-configure
configure_args="--with-installbuilddir=/usr/share/apr-1/build"
makedepends="expat-devel libuuid-devel"
short_desc="Apache Portable Runtime Library"
maintainer="Orphaned <orphan@voidlinux.org>"
license="Apache-2.0"
homepage="http://apr.apache.org/"
distfiles="http://www.apache.org/dist/apr/apr-${version}.tar.bz2"
checksum=e2e148f0b2e99b8e5c6caa09f6d4fb4dd3e83f744aa72a952f94f5a14436f7ea

# Do not redefine struct iovec in include/apr_want.h
CFLAGS="-DAPR_IOVEC_DEFINED=1"

# Can't run test programs when cross compiling
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=sem_open"
fi

if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then
	makedepends+=" libatomic-devel"
	LDFLAGS="-latomic"
fi

pre_build() {
	if [ "$CROSS_BUILD" ]; then
		vsed -i Makefile \
			-e "/LINK_PROG.*OBJECTS_gen_test_char/s|.*|\t${BUILD_CC} ${BUILD_CFLAGS} tools/gen_test_char.c -o tools/gen_test_char|"
		# Fixup some not detected configure results to match native builds
		vsed -i include/apr.h \
			-e "/#define APR_HAVE_SHMEM_MMAP_ZERO/s;0;1;" \
			-e "/#define APR_HAVE_IOVEC/s;0;1;" \
			-e "/#define APR_HAS_POSIXSEM_SERIALIZE/s;0;1;" \
			-e "/#define APR_HAS_PROC_PTHREAD_SERIALIZE/s;0;1;"
	fi
}

post_install() {
	if [ "$CROSS_BUILD" ]; then
		vsed -i -e "s,$XBPS_CROSS_BASE,,g" \
			"$DESTDIR/usr/bin/apr-1-config" \
			"$DESTDIR/usr/share/apr-1/build/apr_rules.mk"
	fi
}

apr-devel_package() {
	depends="libtool libuuid-devel apr>=${version}_${revision}"
	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/"
	}
}
