# Template file for 'nfs-utils'
pkgname=nfs-utils
version=1.2.9
revision=4
short_desc="Network File System client utilities"
maintainer="Juan RP <xtraeme@gmail.com>"
license="GPL-2"
homepage="http://nfs.sourceforge.net"
distfiles="${KERNEL_SITE}/utils/${pkgname}/${version}/${pkgname}-${version}.tar.xz"
checksum=b540618847e665aedbab9eb956da910be3302492a6424474fcda537540295b0c

hostmakedepends="pkg-config"
makedepends="libblkid-devel libmount-devel libtirpc-devel
 librpcsecgss-devel>=0.19_3 libnfsidmap-devel>=0.25_3 keyutils-devel
 libevent-devel device-mapper-devel libcap-devel mit-krb5-devel
 libblkid-devel sqlite-devel"
depends="rpcbind"
conf_files="/etc/idmapd.conf"
make_dirs="
	/var/lib/nfs/rpc_pipefs	0755	root	root
	/var/lib/nfs/sm		0750	root	root"

do_configure() {
	configure_args+=" --with-statduser=nobody --enable-gss --enable-nfsv4
		--with-statedir=/var/lib/nfs --enable-libmount-mount
		--with-gssglue --without-tcp-wrappers --enable-ipv6
		--sbindir=/usr/sbin "

	./configure ${configure_args} \
		--with-tirpcinclude=$XBPS_CROSS_BASE/usr/include/tirpc \
		--with-krb5=$XBPS_CROSS_BASE \
		CC_FOR_BUILD="$CC" CFLAGS_FOR_BUILD="$CFLAGS"
}

do_build() {
	make ${makejobs}
}

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

	vmkdir usr/sbin
	mv ${DESTDIR}/sbin/* ${DESTDIR}/usr/sbin
	# conffiles
	vinstall ${FILESDIR}/exports 644 etc
	vinstall ${FILESDIR}/idmapd.conf 644 etc
	# systemd glue
	if [ "$build_option_systemd" ]; then
		vmkdir usr/lib/systemd/system
		install -m644 ${FILESDIR}/*.{service,mount} ${DESTDIR}/usr/lib/systemd/system
	fi

	rm -rf ${DESTDIR}/var/lib/nfs
}

nfs-utils-server_package() {
	short_desc="Network File System utilities - Server utilities"
	depends="rpcbind"
	replaces="nfs-utils<1.2.6_2"
	conf_files="/etc/exports"
	make_dirs="
		/var/lib/nfs/v4recovery 	0755    root    root
		/var/lib/nfs/sm 		0750    root    root
		/etc/exports.d			0750	root	root"
	pkg_install() {
		vmove etc/exports
		for f in exportfs rpc.mountd rpc.nfsd blkmapd rpc.svcgssd; do
			vmove usr/sbin/${f}
			[ "$f" = "blkmapd" ] && continue
			vmove usr/share/man/man8/$(basename ${f}).8
		done
		for f in mountd nfsd svcgssd; do
			vmove usr/share/man/man8/${f}.8
		done
		vmove usr/share/man/man5
		vmove usr/share/man/man7
		if [ "$build_option_systemd" ]; then
			for f in blkmapd nfsd rpc-mountd rpc-svcgssd; do
				vmove usr/lib/systemd/system/${f}.service
			done
			vmove usr/lib/systemd/system/proc-fs-nfsd.mount
		fi
	}
}
