SUMMARY="GNU regular expression matcher"
DESCRIPTION="The grep command searches one or more input files for lines \
containing a match to a specified pattern. By default, grep prints the \
matching lines."
HOMEPAGE="https://www.gnu.org/software/grep/"
COPYRIGHT="1992-2016 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="http://ftp.gnu.org/gnu/grep/grep-$portVersion.tar.xz"
CHECKSUM_SHA256="5c10da312460aec721984d5d83246d24520ec438dd48d7ab5a05dbc0d6d6823c"
PATCHES="grep-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?arm"
SECONDARY_ARCHITECTURES="x86"

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	grep$secondaryArchSuffix = $portVersion compat >= 3
	cmd:egrep$commandSuffix = $portVersion compat >= 2
	cmd:fgrep$commandSuffix = $portVersion compat >= 2
	cmd:grep$commandSuffix = $portVersion compat >= 2
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	"

if [ "$targetArchitecture" = x86_gcc2 ]; then
	REPLACES="
		grep
		"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:makeinfo
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage grep$secondaryArchSuffix \
	$commandBinDir/grep

BUILD()
{
	autoreconf -f -I m4
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir \
		--without-included-regex --disable-gcc-warnings
	make $jobArgs
}

INSTALL()
{
	make install
}

TEST()
{
	# SKIPPED:	big-hole, big-match, fmbtest, long-line-vs-2GiB-read, \
	#			long-pattern-perf, mb-non-UTF8-performance, pcre*, proc \
	#			turkish-eyes, write-error-msg, many-regex-performance
	#
	# TOTAL: 116
	# PASS:  91
	# SKIP:  23
	# XFAIL: 2
	# FAIL:  0
	# XPASS: 0
	# ERROR: 0

	make check
}
