# Template file for 'lsof'
pkgname=lsof
version=4.94.0
revision=1
build_style=configure
configure_script="./Configure"
configure_args="-n linux"
hostmakedepends="perl which"
short_desc="LiSt Open Files"
maintainer="Orphaned <orphan@voidlinux.org>"
license="custom:lsof"
homepage="https://people.freebsd.org/~abe/"
distfiles="https://fossies.org/linux/misc/lsof-${version}.tar.gz"
checksum=a9865eeb581c3abaac7426962ddb112ecfd86a5ae93086eb4581ce100f8fa8f4

pre_configure() {
	export LSOF_CC="$CC"
	export LSOF_CFGF="$CFLAGS"
	export LSOF_CFGL="$LDFLAGS"
	export LSOF_INCLUDE="${XBPS_CROSS_BASE}/usr/include"

	vsed "s|/\* #define\tHASSECURITY\t1 \*/|#define\tHASSECURITY\t1|" \
		-i dialects/linux/machine.h
}

pre_check() {
	# test resolves hostname
	cp /etc/hosts ./hosts
	printf '# +++ xbps-src +++ required for lsof tests\n127.0.0.100 %s\n' "$(hostname)" >> /etc/hosts
	# write current config to test db
	cd tests && ./Add2TestDB
}
do_check() {
	make -C tests
}
post_check() {
	# cleanup polluted hosts file
	mv ./hosts /etc/hosts
}

do_install() {
	vbin lsof
	vman Lsof.8 lsof.8

	# extract license from readme
	sed -n 00README -e '/^License/,/\*\/$/p' > License
	vlicense License
}
