# Template file for 'findutils'
pkgname=findutils
version=4.4.2
revision=15
bootstrap=yes
build_style=gnu-configure
configure_args="--program-prefix=g --localstatedir=/var/lib/locate"
short_desc="The GNU Find Utilities"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="GPL-3"
homepage="http://www.gnu.org/software/findutils"
distfiles="${GNU_SITE}/$pkgname/$pkgname-$version.tar.gz"
checksum=434f32d171cbc0a5e72cfc5372c6fc4cb0e681f8dce566a0de5b6fccd702b62a

make_dirs="/var/lib/locate 0755 root root"
conf_files="/etc/updatedb.conf"
conflicts="chroot-findutils>=0"

alternatives="
 locate:locate:/usr/bin/glocate
 locate:locate.1:/usr/share/man/man1/glocate
 locate:locatedb.5:/usr/share/man/man5/glocatedb
 locate:updatedb:/usr/bin/gupdatedb
 locate:updatedb.1:/usr/share/man/man1/gupdatedb
 xargs:xargs:/usr/bin/gxargs
 xargs:xargs.1:/usr/share/man/man1/gxargs.1
 find:find:/usr/bin/gfind
 find:find.1:/usr/share/man/man1/gfind.1
"

pre_configure() {
	case "$XBPS_TARGET_MACHINE" in
	*-musl)
		# Special case for musl libc; "fix" issues with gnulib.
		: > gnulib/lib/freadahead.c
		: > gnulib/lib/fseeko.c
		echo "void close_stdin(void) {}" > gnulib/lib/closein.c
		;;
	esac
}
post_install() {
	# Install the cron daily job.
	vinstall ${FILESDIR}/updatedb.cron-daily 744 etc/cron.daily updatedb
	# Install the updatedb conf file.
	vinstall ${FILESDIR}/updatedb.conf 640 etc

	# remove 'g' prefix.
	for f in gbigram gcode gfrcode; do
		mv ${DESTDIR}/usr/libexec/${f} ${DESTDIR}/usr/libexec/${f#g}
		sed -i "s/${f}/${f#g}/" ${DESTDIR}/usr/bin/gupdatedb
	done
}
