# Template file for 'lsof'
pkgname=lsof
version=4.96.3
revision=1
build_style=configure
configure_script="./Configure"
configure_args="-n linux"
make_check_target="all"
make_check_args="-C tests"
hostmakedepends="perl groff"
short_desc="LiSt Open Files"
maintainer="Subhaditya Nath <sn03.general@gmail.com>"
license="custom:lsof"
homepage="https://github.com/lsof-org/lsof"
changelog="https://raw.githubusercontent.com/lsof-org/lsof/master/00DIST"
distfiles="https://github.com/lsof-org/lsof/archive/refs/tags/${version}/${version}.tar.gz"
checksum=2753fc01452a3d2ee665e8365afdac0e9683197f3ec06231aa684a48b286d11c

post_extract() {
	# See: https://github.com/lsof-org/lsof/issues/61
	# The TestDB was meant for storing known-good configurations, and
	# skipping tests if the current system configuration exists in the
	# TestDB.   But we don't want that.
	rm tests/CkTestDB
	ln -s /bin/true tests/CkTestDB
}

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

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

	soelim Lsof.8 | grep -vi '^\.lf ' > lsof.8
}

do_install() {
	vbin lsof
	vman lsof.8

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