NAME=grep
VERSION=2.5.1a
SOURCE=$MIRROR_GNU/grep/grep-$VERSION.tar.gz
# A bunch of patches from Red Hat (grep-2.5.1-32.2.src.rpm). The development
# of GNU grep seems to be active but with lack of resources. :-(
# See http://www.gnu.org/software/grep/devel.html section "5 Roadmap".
# The Red Hat's patches are on their way to official grep.
PATCH=(	grep-2.5.1-fgrep.patch
	grep-2.5.1-bracket.patch
	grep-2.5-i18n.patch
	grep-2.5.1-oi.patch
	grep-2.5.1-manpage.patch
	grep-2.5.1-egf-speedup.patch
	grep-2.5.1-dfa-optional.patch
	grep-2.5.1-w.patch
	grep-P.patch )
BUILD=1
OPTIMIZE=${OPTIMIZE:-"-O2"}

build() {
	_explode 0
	cd grep-$VERSION

	for I in "${PATCH[@]}"; do
		_patch $I -p1
	done

	$CONFIGURE
	
	# Links statically against libpcre:
	sed -i "s|^LIBS.*\$|LIBS = $LIBDIR/libpcre.a|" src/Makefile
	
	make
	make DESTDIR=$PKG install
	_doc 0 grep-$VERSION  AUTHORS COPYING README README-alpha THANKS TODO

	# Replace scripts with symlinks:
	rm -f $PKG$BINDIR/{e,f}grep
	ln -s grep $PKG$BINDIR/egrep
	ln -s grep $PKG$BINDIR/fgrep

	# grep is needed before we have /usr.
	if [ "$PREFIX" = "/usr" ]; then
		mkdir -p $PKG/bin
		mv $PKG$BINDIR/* $PKG/bin
		ln -s ../../bin/grep $PKG$BINDIR/grep
		ln -s ../../bin/egrep $PKG$BINDIR/egrep
		ln -s ../../bin/fgrep $PKG$BINDIR/fgrep
	fi

	_chfix
	_chgrp_bin
}
