# Template file for 'lsof'
pkgname=lsof
version=4.95.0
revision=1
wrksrc="${pkgname}_${version}.linux"
build_style=configure
configure_script="./Configure"
configure_args="-n linux"
make_check_target="all"
make_check_args="-C tests"
hostmakedepends="perl"
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/releases/download/${version}/lsof_${version}.linux.tar.bz2"
checksum=e9faa0fbcc48638c1d1f143e93573ac43b65e76646150f83e24bd8c18786303c

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
}

do_install() {
	vbin lsof
	vman lsof.8

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