On 11/14/2010 03:09 PM, Jim Meyering wrote: >> It is possible to disable the body of these two expansions by >> assigning values to GREP and EGREP inside the configure script. > > But with no grep program already installed, that will always fail.
You can implement a basic grep that is "good enough for configure" using while/read and case. You will use the newly-built grep after it's, well, built. But nobody uses grep in "make all", so it can be substituted unconditionally in Makefiles, and a shell function can replace the dummygrep binary. This is the patch: 2010-11-14 Paolo Bonzini <bonz...@gnu.org> * configure.ac (fn_grep): New. Set GREP and EGREP to it, replace with newly-built grep before AC_OUTPUT. diff --git a/configure.ac b/configure.ac index 481ce86..87a38cc 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,36 @@ AC_INIT([GNU grep], m4_esyscmd([build-aux/git-version-gen .tarball-version]), [bug-g...@gnu.org]) +# Override grep during configure. +fn_grep () { + test $1 = -E && shift + case $...@%:@:$1 in + 0:*) AC_MSG_ERROR([fn_grep: expected pattern]) ;; + 1:-*) AC_MSG_ERROR([fn_grep: invalid command line]) ;; + 1:*) pattern=$1 ;; + 2:--|2:-e|2:-Ee) pattern=$2 ;; + *) AC_MSG_ERROR([fn_grep: invalid command line]) ;; + esac + + case $pattern in + *[].^$\\*[]*) AC_MSG_ERROR([fn_grep: regular expressions not supported]) ;; + esac + + rc=1 + while read line; do + case $line in + *$pattern*) + rc=0 + AS_ECHO([$line]) ;; + esac + done + return $rc +} + +test -n "$GREP" || GREP=fn_grep +test -n "$EGREP" || EGREP=fn_grep +ac_cv_path_EGREP=$EGREP + AC_CONFIG_AUX_DIR(build-aux) AC_CONFIG_SRCDIR(src/grep.c) AC_DEFINE([GREP], 1, [We are building grep]) @@ -167,4 +197,6 @@ AC_CONFIG_FILES([ doc/Makefile gnulib-tests/Makefile ]) +GREP="$ac_abs_top_builddir/src/grep" +EGREP="$ac_abs_top_builddir/src/egrep" AC_OUTPUT