autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposed Autoconf patch so that "configure" need not use Awk


From: Paul Eggert
Subject: proposed Autoconf patch so that "configure" need not use Awk
Date: Wed, 31 Oct 2001 04:54:15 -0800 (PST)

We've now established that this issue is not urgent and is irrelevant
to Autoconf 2.53, but I still want to persist in suggesting that we
not use Awk in "configure", for three reasons:

1.  The GNU Coding Standards suggest that we not use Awk.
2.  If we don't use Awk, it's one less program to worry about while porting.
3.  In this case the non-Awk version is simpler and easier to understand.

We've discussed (1) already.

(2) has been a problem with Autoconf before.  Long ago, autoconf used
to use Awk to generate config.h, but Autoconf 1.3 removed the need for
Awk.  This fix was installed on Dec 18 00:21:23 1992 by djm (patch
from Ian Lance Taylor) and was presumably done for a good reason.

As for (3), the comparison is between something like this:

  awk '{print NR; print}'

and something like this:

  sed '='

Both commands work, but the Sed version is shorter and easier to follow,
assuming you know both Awk and Sed.

Here's a proposed patch to use the idea of "sed '='".  It's a slightly
improved version of the most recent patch I submitted on this subject.

Even if you still want to use Awk, despite the above arguments, almost
all of this patch is needed; just replace "sed '='" with "awk '{print
NR; print}'" in the code and replace "Sed" with "Awk+Sed" in the
documentation.

2001-10-31  Paul Eggert  <address@hidden>

        * lib/m4sugar/m4sh.m4 (_AS_LINENO_PREPARE): Fix the sed
        prepass to work even if there are multiple instances of
        $LINENO on the same line.  Do not substitute for other
        variables like $LINENOT.  Do not check file dates;
        such a check is unreliable on sufficiently fast machines,
        and removing the check makes the code simpler and more reliable.
        Check for output and chmod failures.

        (Oh, and by the way, use Sed rather than Awk.  :-)

        * doc/autoconf.texi (Special Shell Variables): Document
        the above.

Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.67
diff -p -u -r1.67 m4sh.m4
--- lib/m4sugar/m4sh.m4 2001/10/26 19:52:43     1.67
+++ lib/m4sugar/m4sh.m4 2001/10/31 12:26:18
@@ -474,15 +474,11 @@ m4_define([_AS_LINENO_WORKS],
 # _AS_LINENO_PREPARE
 # ------------------
 # If LINENO is not supported by the shell, produce a version of this
-# script where LINENO is hard coded.  Rewrite if not up to date only.
+# script where LINENO is hard coded.
 # Comparing LINENO against _oline_ is not a good solution, since in
 # the case of embedded executables (such as config.status within
 # configure) you'd compare LINENO wrt config.status vs. _oline_ vs
-# configure.  Hence a useless rewrite (not to mention the risk of
-# ``infinite'' rewrites.  Merely check that LINENO is incremented
-# between two lines, which is a property guaranteed for _oline_, hence
-# it protects us from repetitive rewrites.  Be sure to have a test
-# that does detect non LINENO support...
+# configure.
 m4_define([_AS_LINENO_PREPARE],
 [_AS_LINENO_WORKS || {
   # Find who we are.  Look in the path if we contain no path at all
@@ -515,19 +511,21 @@ m4_define([_AS_LINENO_PREPARE],
         esac
        done]);;
   esac
-  if test ! -f "$as_me.lineno" ||
-     test x`ls -1dt "$as_me.lineno" "$as_myself" 2>/dev/null | sed 1q` \
-                != x"$as_me.lineno"; then
-     # Be sure to write the pattern so that it doesn't replace itself:
-     # it must not match itself.
-     awk <$as_myself '
-           /[[$]]LINENO/ { printf "%d:", NR }
-                         { print }
-         ' |
-       sed ['/[$]LINENO/s/^\([0-9][0-9]*\):\(.*\)[$]LINENO/\2\1/'] \
-         >$as_me.lineno
-    chmod +x $as_me.lineno
-  fi
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.
+  sed '=' <$as_myself |
+    sed '
+      N
+      s/$/ /
+      : loop
+      s/^\([[0-9]]*\)\(.*\)[[$]]LINENO\([[^a-zA-Z0-9_]]\)/\1\2\1\3/
+      t loop
+      s/ $//
+      s/.*\n//
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    AS_ERROR([cannot create $as_me.lineno; rerun with a POSIX shell])
 
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.555
diff -p -u -r1.555 autoconf.texi
--- doc/autoconf.texi   2001/10/26 19:52:07     1.555
+++ doc/autoconf.texi   2001/10/31 12:26:22
@@ -8190,16 +8190,17 @@ Most modern shells provide the current l
 Its value is the line number of the beginning of the current command.
 Autoconf attempts to execute @command{configure} with a modern shell.
 If no such shell is available, it attempts to implement @code{LINENO}
-with a simple Awk+Sed prepass that replaces the first instance of the
-string @code{$LINENO} in each line with the line's number.
+with a Sed prepass that replaces the each instance of the string
address@hidden (not followed by an alphanumeric character) with the
+line's number.
 
 You should not rely on @code{LINENO} within @command{eval}, as the
-behavior differs in practice.  Also, the possibility of the Awk+Sed
+behavior differs in practice.  Also, the possibility of the Sed
 prepass means that you should not rely on @code{$LINENO} when quoted,
 when in here-documents, or when in long commands that cross line
-boundaries or that have multiple instances of $LINENO.  Subshells
-should be OK, though.  In the following example, lines 1, 6, and 10
-are portable, but the other instances of @code{LINENO} are not:
+boundaries.  Subshells should be OK, though.  In the following
+example, lines 1, 6, and 9 are portable, but the other instances of
address@hidden are not:
 
 @example
 @group
@@ -8211,10 +8212,9 @@ cat <<EOF
 EOF
 ( echo 6. $LINENO )
 eval 'echo 7. $LINENO'
-echo 8. $LINENO $LINENO
-echo 9. '$LINENO'
-echo 10. $LINENO '
-11.' $LINENO
+echo 8. '$LINENO'
+echo 9. $LINENO '
+10.' $LINENO
 @end group
 @group
 $ @kbd{bash-2.05 lineno}
@@ -8223,10 +8223,9 @@ $ @kbd{bash-2.05 lineno}
 4. 2
 6. 6
 7. 1
-8. 8 8
-9. $LINENO
-10. 10 
-11. 10
+8. $LINENO
+9. 9
+10. 9
 @end group
 @group
 $ @kbd{zsh-3.0.6 lineno}
@@ -8235,10 +8234,9 @@ $ @kbd{zsh-3.0.6 lineno}
 4. 2
 6. 6
 7. 7
-8. 8 8
-9. $LINENO
-10. 10 
-11. 10
+8. $LINENO
+9. 9
+10. 9
 @end group
 @group
 $ @kbd{pdksh-5.2.14 lineno}
@@ -8247,14 +8245,20 @@ $ @kbd{pdksh-5.2.14 lineno}
 4. 2
 6. 6
 7. 0
-8. 8 8
-9. $LINENO
-10. 10 
-11. 10
+8. $LINENO
+9. 9
+10. 9
 @end group
 @group
-$ @kbd{awk '/\$LINENO/@{printf "%d:", address@hidden; @address@hidden' lineno 
|}
-> @kbd{sed '/\$LINENO/s/^\([^:]*\):\(.*\)\$LINENO/\2\1/' |}
+$ @kbd{sed '=; s/^/X/' <lineno |}
+> @kbd{  sed '}
+> @kbd{    /^[0-9]/N}
+> @kbd{    : loop}
+> @kbd{      s/^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\)/\1\2\1\3/}
+> @kbd{      s/^\([0-9]*\)\(.*\)[$]LINENO$/\1\2\1/}
+> @kbd{    t loop}
+> @kbd{    s/.*\nX//}
+> @kbd{  ' |}
 > @kbd{sh}
 1. 1
 3. 3
@@ -8264,7 +8268,6 @@ $ @kbd{awk '/\$LINENO/@{printf "%d:", NR
 8. 8
 9. 9
 10. 10 
-11. 11
 @end group
 @end example
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]