# Template file for 'drbd-utils'
pkgname=drbd-utils
version=9.12.1
revision=1
build_style=gnu-configure
build_helper="qemu"
configure_args="
 --sbindir=/usr/bin
 --prefix=/usr
 --exec-prefix=/usr
 --libexecdir=/usr/libexec
 --with-distro=generic
 --with-bashcompletion
 --with-udev
 --without-rgmanager
 --without-pacemaker
 --without-heartbeat
 --without-83support
 --without-xen"
conf_files="
 /etc/drbd.conf
 /etc/drbd.d/global_common.conf"
hostmakedepends="automake libtool flex pkg-config eudev libxslt docbook-xsl po4a"
makedepends="eudev-libudev-devel"
short_desc="Distributed replicated storage"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-2.0-or-later"
homepage="http://www.drbd.org"
distfiles="https://www.linbit.com/downloads/drbd/utils/${pkgname}-${version}.tar.gz"
checksum=1102e2a2001a45685c2f4ce5cb14e5a8a099044f53389d38480b3a88f5db3fd1

# XXX mirror which is reachable from musl builders
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	distfiles="https://distfiles.voidlinux.de/${pkgname}-${version}.tar.gz"
fi

# Workaround a parallelism issue
disable_parallel_build=yes

if [ -n "$CROSS_BUILD" ]; then
	hostmakedepends+=" drbd-utils"
fi

CFLAGS="-fcommon"

pre_configure() {
	sed -i 's#/lib/drbd#/usr/lib/drbd#' drbd.spec.in
	NOCONFIGURE=1 ./autogen.sh
	find -name "*.c" -exec sed -i "{}" -e 's#sys/poll\.h#poll.h#g' \;
	find -name Makefile.in -exec sed -i "{}" -e 's#$(DESTDIR)/lib#$(DESTDIR)/usr/lib#g' \;
	if [ -n "$CROSS_BUILD" ]; then
		# Replace drbdsetup{,-84,9} with the /usr/bin or /usr/libexec counterparts
		find -name "Makefile*" -exec sed -i "{}" \
			-e 's#^\(\s\)$(TOPDIR)/user/v84/drbdsetup-84#\1/usr/libexec/drbdsetup-84#' \
			-e 's#^\(\s\)$(TOPDIR)/user/v9/drbdsetup#\1/usr/bin/drbdsetup#' \
		\;
	fi
}

post_install() {
	mv ${DESTDIR}/usr/lib/drbd $DESTDIR/usr/libexec
	mv ${DESTDIR}/etc/init.d/* $DESTDIR/usr/libexec
	vmkdir usr/share/bash-completion/completions
	mv ${DESTDIR}/etc/bash_completion.d/* $DESTDIR/usr/share/bash-completion/completions
	vsv drbd
}
