]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/autoconf/programs.m4 (AC_PROG_GREP): New macro to test for a
authorGary V. Vaughan <gary@gnu.org>
Tue, 27 Jan 2004 20:07:12 +0000 (20:07 +0000)
committerGary V. Vaughan <gary@gnu.org>
Tue, 27 Jan 2004 20:07:12 +0000 (20:07 +0000)
grep or ggrep program in PATH that accepts as long lines as
possible.
* lib/autoconf/programs.m4 (_AC_PROG_GREP): Factor out the core of
AC_PROG_GREP.
(AC_PROG_EGREP, AC_PROG_FGREP): Use it to find best available
egrep and fgrep respectively if $GREP -E/-F don't work.
(_AC_PATH_PROG_FEATURE_CHECK): Factor out the common core of
_AC_PROG_GREP, and AC_PROG_SED.
(_AC_FEATURE_CHECK_LENGTH): New helper macro for finding the
longest input length accepted by a command.
(AC_PROG_SED): Use it.
* doc/autoconf.texi (Particular Programs): Document the changes.
* NEWS: Updated.

ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/programs.m4

index 80d1275f12db15d5de205458ea916d25e91a01d9..9dd26c941e18377b3e4c92a44a6abf197cadda49 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2004-01-27  Gary V. Vaugan  <gary@gnu.org>
+           Albert Chin-A-Young <china@thewrittenword.com>
+
+       * lib/autoconf/programs.m4 (AC_PROG_GREP): New macro to test for a
+       grep or ggrep program in PATH that accepts as long lines as
+       possible.
+       * lib/autoconf/programs.m4 (_AC_PROG_GREP): Factor out the core of
+       AC_PROG_GREP.
+       (AC_PROG_EGREP, AC_PROG_FGREP): Use it to find best available
+       egrep and fgrep respectively if $GREP -E/-F don't work.
+       (_AC_PATH_PROG_FEATURE_CHECK): Factor out the common core of
+       _AC_PROG_GREP, and AC_PROG_SED.
+       (_AC_FEATURE_CHECK_LENGTH): New helper macro for finding the
+       longest input length accepted by a command.
+       (AC_PROG_SED): Use it.
+       * doc/autoconf.texi (Particular Programs): Document the changes.
+       * NEWS: Updated.
+
 2004-01-27  Paul Eggert  <eggert@twinsun.com>
 
        * bin/autoconf.as ($version): Update copyright from 2003 to 2004.
diff --git a/NEWS b/NEWS
index 8a5d61f95c9dffabe5989e1aa903c5370675a9dc..2478bb73f5c8e909236c9ddcd50961f3865f1697 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,14 @@
 * Major changes in Autoconf 2.59a
 
+** AC_PROG_GREP
+  New macro that tests for a grep program that accepts as a long a line
+  as possible.
+
+** AC_PROG_EGREP, AC_PROG_FGREP
+  These macros now require AC_PROG_GREP, and try EGREP="$GREP -E" and
+  FGREP="$GREP -F" respectively if possible, or else run a path search for
+  a program that accepts as long a line as possible.
+
 ** AC_PROG_SED
   New macro that tests for a sed program that truncates as few characters
   as possible.
index 6d9b68b7fdcd55d0b7704c7c28d925d1c5f8f654..cede1f43351e2332a9c33fd6cb5fa4581334dca9 100644 (file)
@@ -3235,18 +3235,32 @@ It tries @code{gawk} first because that is reported to be the
 best implementation.
 @end defmac
 
+@defmac AC_PROG_GREP
+@acindex{PROG_GREP}
+@ovindex GREP
+On AIX the default @code{grep} silently truncates long lines on the
+input before matching.  This macro looks for @sc{gnu} Grep or
+else the best available @code{grep} or @code{ggrep} in the user's
+@code{$PATH}, which accepts the longest input lines possible.  Set the
+output variable @code{GREP} to whatever is chosen.
+@end defmac
+
 @defmac AC_PROG_EGREP
 @acindex{PROG_EGREP}
 @ovindex EGREP
-Check for @code{grep -E} and @code{egrep}, in that order, and set
-output variable @code{EGREP} to the first one that is found.
+Check whether @code{$GREP -E} works, or else search the user's
+@code{$PATH} for @code{egrep}, and @code{gegrep}, in that order, and set
+output variable @code{EGREP} to the one which accepts the longest input
+lines.
 @end defmac
 
 @defmac AC_PROG_FGREP
 @acindex{PROG_FGREP}
 @ovindex FGREP
-Check for @code{grep -F} and @code{fgrep}, in that order, and set
-output variable @code{FGREP} to the first one that is found.
+Check whether @code{$GREP -F} works, or else search the user's
+@code{$PATH} for @code{fgrep}, and @code{gfgrep}, in that order, and set
+output variable @code{FGREP} to the one which accepts the longest input
+lines.
 @end defmac
 
 @defmac AC_PROG_INSTALL
@@ -3369,7 +3383,7 @@ is found, and otherwise to @samp{:} (do nothing).
 @acindex {PROG_SED}
 @ovindex SED
 Set output variable @code{SED} to a @code{sed} on @samp{PATH} that
-truncates as few characters as possible.  If @sc{GNU} Sed is found,
+truncates as few characters as possible.  If @sc{gnu} Sed is found,
 use that instead.
 @end defmac
 
index 7005c0509f1d5f9ef8380fccda8c494796082fe1..9353bbe1a7899b283f6585967928b8f5d3678c74 100644 (file)
@@ -267,12 +267,14 @@ AC_DEFUN([AC_PROG_AWK],
 # AC_PROG_EGREP
 # -------------
 AC_DEFUN([AC_PROG_EGREP],
-[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
-   [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
-    then ac_cv_prog_egrep='grep -E'
-    else ac_cv_prog_egrep='egrep'
-    fi])
- EGREP=$ac_cv_prog_egrep
+[AC_REQUIRE([AC_PROG_GREP])dnl
+AC_CACHE_CHECK([for egrep], ac_cv_path_EGREP,
+   [if echo a | ($GREP -E '(a|b)') >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     _AC_PROG_GREP(EGREP, egrep)
+   fi])
+ EGREP="$ac_cv_path_EGREP"
  AC_SUBST([EGREP])
 ])# AC_PROG_EGREP
 
@@ -280,16 +282,124 @@ AC_DEFUN([AC_PROG_EGREP],
 # AC_PROG_FGREP
 # -------------
 AC_DEFUN([AC_PROG_FGREP],
-[AC_CACHE_CHECK([for fgrep], [ac_cv_prog_fgrep],
-   [if echo 'ab*c' | (grep -F 'ab*c') >/dev/null 2>&1
-    then ac_cv_prog_fgrep='grep -F'
-    else ac_cv_prog_fgrep='fgrep'
-    fi])
- FGREP=$ac_cv_prog_fgrep
+[AC_REQUIRE([AC_PROG_GREP])dnl
+AC_CACHE_CHECK([for fgrep], ac_cv_path_FGREP,
+   [if echo 'ab*c' | ($GREP -F 'ab*c') >/dev/null 2>&1
+   then ac_cv_path_FGREP="$GREP -F"
+   else
+     _AC_PROG_GREP(FGREP, fgrep)
+   fi])
+ FGREP="$ac_cv_path_FGREP"
  AC_SUBST([FGREP])
 ])# AC_PROG_FGREP
 
 
+# AC_PROG_GREP
+# ------------
+# Check for a fully functional grep program that handles
+# the longest lines possible.  Prefer GNU grep if found.
+AC_DEFUN([AC_PROG_GREP],
+[AC_CACHE_CHECK([for grep that handles long lines], oc_cv_path_GREP,
+   [_$0(GREP, [grep ggrep])])
+ GREP="$ac_cv_path_GREP"
+ AC_SUBST([GREP])
+])
+m4_define([_AC_PROG_GREP],
+[_AC_PATH_PROG_FEATURE_CHECK([$1], [$2],
+       [_AC_FEATURE_CHECK_LENGTH([ac_path_$1], [ac_cv_path_$1],
+               ["$ac_path_$1" '$1$'], [$1])])
+])
+
+
+# _AC_PATH_PROG_FEATURE_CHECK(VARIABLE, PROGNAME-LIST, FEATURE-TEST, [PATH])
+# --------------------------------------------------------------------------
+# FEATURE-TEST is called repeatedly with $ac_path_VARIABLE set to the
+# path to a program named in PROGNAME-LIST.  FEATURE-TEST must set
+# $ac_cv_path_VARIABLE to the path of an acceptable program, or else
+# _AC_PATH_PROG_FEATURE_CHECK will report that no acceptable program
+# was found, and abort.  If a suitable $ac_path_VARIABLE is found,
+# `break 2' will accept it without any further checks.
+m4_define([_AC_PATH_PROG_FEATURE_CHECK],
+[# Extract the first word of "$2" to use in msg output
+if test -z "$$1"; then
+set dummy $2; ac_prog_name=$[2]
+AC_CACHE_VAL([ac_cv_path_$1],
+[AS_TMPDIR([$1])
+# Loop through the user's path and test for each of PROGNAME-LIST
+_AS_PATH_WALK([$4],
+[for ac_prog in $2; do
+  for ac_exec_ext in '' $ac_executable_extensions; do
+    ac_path_$1="$as_dir/$ac_prog$ac_exec_ext"
+    test -f "$ac_path_$1" || continue
+    $3
+  done
+done])
+rm -rf "$tmp"
+])
+$1="$ac_cv_path_$1"
+if test -z "$$1"; then
+  AC_MSG_ERROR([no acceptable $ac_prog_name could be found in dnl
+m4_default([$4], [\$PATH])])
+fi
+AC_SUBST([$1])
+fi
+])
+
+
+# _AC_FEATURE_CHECK_LENGTH(PROGPATH, CACHE-VAR, CHECK-CMD, [MATCH-STRING])
+# ------------------------------------------------------------------------
+# For use as the FEATURE-TEST argument to _AC_PATH_PROG_FEATURE_TEST.
+# On each iteration run CHECK-CMD on an input file, storing the value
+# of PROGPATH in CACHE-VAR if the CHECK-CMD succeeds.  The input file
+# is always one line, starting with only 10 characters, and doubling
+# in length at each iteration until approx 10000 characters or the
+# feature check succeeds.  The feature check is called at each
+# iteration by appending (optionally, MATCH-STRING and) a newline
+# to the file, and using the result as input to CHECK-CMD.
+m4_define([_AC_FEATURE_CHECK_LENGTH],
+[if AS_EXECUTABLE_P(["$$1"]); then
+  # Check for GNU $1 and select it if it is found.
+  _AC_PATH_PROG_FLAVOR_GNU([$$1],
+    [$2="$$1"
+    break 2
+  ])
+
+  ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >"$tmp/conftest.in"
+  while :
+  do
+    cat "$tmp/conftest.in" "$tmp/conftest.in" >"$tmp/conftest.tmp"
+    mv "$tmp/conftest.tmp" "$tmp/conftest.in"
+    cp "$tmp/conftest.in" "$tmp/conftest.nl"
+    echo '$4' >> "$tmp/conftest.nl"
+    $3 < "$tmp/conftest.nl" >"$tmp/conftest.out" || break
+   diff "$tmp/conftest.out" "$tmp/conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      $2="$$1"
+      ac_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+fi
+])
+
+
+# _AC_PATH_PROG_FLAVOR_GNU(PROGRAM-PATH, IF-SUCCESS, [IF-FAILURE])
+# ----------------------------------------------------------------
+m4_define([_AC_PATH_PROG_FLAVOR_GNU],
+[# Check for GNU $1
+if "$1" --version 2>&1 < /dev/null | grep 'GNU' >/dev/null; then
+  $2
+m4_ifval([$3],
+[else
+  $3
+])fi
+])# _AC_PATH_PROG_FLAVOR_GNU
+
+
 # AC_PROG_INSTALL
 # ---------------
 AN_MAKEVAR([INSTALL], [AC_PROG_INSTALL])
@@ -506,56 +616,16 @@ Remove this warning when you adjust the code.])])
 # Check for a fully functional sed program that truncates
 # as few characters as possible.  Prefer GNU sed if found.
 AC_DEFUN([AC_PROG_SED],
-[AC_MSG_CHECKING([for a sed that does not truncate output])
-if test -z "$SED"; then
-AC_CACHE_VAL(ac_cv_path_sed,
-[AS_TMPDIR([sed])
-ac_max=0
-# Loop through the user's path and test for sed and gsed.
-# Add /usr/xpg4/bin/sed as it is typically found on Solaris
-# along with a /bin/sed that truncates output.
-_AS_PATH_WALK([$PATH:/usr/xpg4/bin],
-[ac_fini=false
-for ac_prog in sed gsed; do
-  for ac_exec_ext in '' $ac_executable_extensions; do
-    ac_sed="$as_dir/$ac_prog$ac_exec_ext"
-    if test -f "$ac_sed" && AS_EXECUTABLE_P(["$ac_sed"]); then
-      # Check for GNU sed and select it if it is found.
-      if "$ac_sed" --version 2>&1 < /dev/null | grep 'GNU' >/dev/null; then
-        ac_cv_path_sed="$ac_sed"
-       ac_fini=:
-        break
-      fi
-
-      ac_count=0
-      echo $ECHO_N "0123456789$ECHO_C" >conftest.in
-      while :
-      do
-        cat conftest.in conftest.in >conftest.tmp
-        mv conftest.tmp conftest.in
-        cp conftest.in conftest.nl
-        echo '' >> conftest.nl
-        "$ac_sed" -e 's/a$//' < conftest.nl >conftest.out || break
-        diff conftest.out conftest.nl >/dev/null 2>&1 || break
-        ac_count=`expr $ac_count + 1`
-        if test $ac_count -gt $ac_max; then
-          ac_max=$ac_count
-          ac_cv_path_sed="$ac_sed"
-        fi
-        # 10*(2^10) chars as input seems more than enough
-        test $ac_count -gt 10 && break
-      done
-    fi
-  done
-  $ac_fini && break
-done])
-rm -rf "$tmp"
-])
-fi
-SED="$ac_cv_path_sed"
-AC_SUBST([SED])
-AC_MSG_RESULT([$SED])
-])
+[AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
+    [_AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
+       [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
+               ["$ac_path_SED" -e 's/a$//'])],
+       dnl Add /usr/xpg4/bin/sed as it is typically found on Solaris
+       dnl along with a /bin/sed that truncates output.
+       [$PATH:/usr/xpg4/bin])])
+ SED="$ac_cv_path_SED"
+ AC_SUBST([SED])
+])# AC_PROG_SED
 
 
 # AC_PROG_YACC