autoconf
[Top][All Lists]
Advanced

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

Re: Problem with symlinks and VPATH Builds


From: Paul Eggert
Subject: Re: Problem with symlinks and VPATH Builds
Date: Fri, 30 Aug 2002 23:40:12 -0700 (PDT)

> From: Alexandre Duret-Lutz <address@hidden>
> Date: Fri, 02 Aug 2002 15:12:33 +0200

> :( :( :(
> 
> Why replace an illustrated discussion of the isse with `Autoconf
> will get it right for you.'?  Why not showing people the
> commands they should use outside Autoconf?

In the long run I'm not sure the Autoconf manual is the right place
for a "portable shell programming HOWTO".  If Autoconf can solve a
problem without the user needing to worry about it, then that's a good
thing.  Documenting the worrisome feature in the user manual (as
opposed to an implementation manual) undoes some of the advantages of
automating the problem away, since it complicates the job of Autoconf
users and may cause them to worry unnecessarily.

However, in the short term the manual does seem to be the current
repository for this info, so I installed the revised patch shown
below.  This patch uses a simpler suggestion for working around the
problem.  As far as I can tell, this patch retains all the information
from the previous documentation, though in a somewhat terser and more
general form.

2002-08-30  Paul Eggert  <address@hidden>

        * lib/autoconf/general.m4 (_AC_INIT_SRCDIR): Reject FOO if "cd
        FOO" and "ls FOO" talk about different directories; this catches
        problems when POSIX 1003.1-2001 "cd" fails due to symlink
        spaghetti.

        * lib/m4sugar/m4sh.m4 (AS_SHELL_SANITIZE): Use AS_UNSET instead
        of rolling our own unset.
        (_AS_PREPARE): $as_unset CDPATH instead of AS_UNSETting it, since
        in practice we needn't worry about CDPATH if unset doesn't work.

        * doc/autoconf.texi (Special Shell Variables): Mention POSIX
        1003.1-2001's requirements for CDPATH.  Give a simpler workaround
        for the CDPATH problem.  Document PWD.
        (Limitations of Builtins): Document the problem that "cd $foo" and
        "ls $foo" may refer to different directories in shells conforming
        to POSIX 1003.1-2001.  Use PS1 rather than CDPATH for "unset"
        example, since the old example is now out of date.

Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.801
retrieving revision 1.802
diff -p -u -r1.801 -r1.802
--- lib/autoconf/general.m4     18 Jul 2002 11:57:32 -0000      1.801
+++ lib/autoconfgeneral.m4      31 Aug 2002 05:47:02 -0000      1.802
@@ -537,6 +537,8 @@ if test ! -r $srcdir/$ac_unique_file; th
     AC_MSG_ERROR([cannot find sources ($ac_unique_file) in $srcdir])
   fi
 fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+  AC_MSG_ERROR([sources are in $srcdir, but `cd $srcdir' does not work])
 dnl Double slashes in pathnames in object file debugging info
 dnl mess up M-x gdb in Emacs.
 srcdir=`echo "$srcdir" | sed 's%\([[^\\/]]\)[[\\/]]*$%\1%'`
Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.85
retrieving revision 1.86
diff -p -u -r1.85 -r1.86
--- lib/m4sugar/m4sh.m4 23 Jul 2002 22:17:19 -0000      1.85
+++ lib/m4sugar/m4sh.m4 31 Aug 2002 05:48:04 -0000      1.86
@@ -159,8 +159,7 @@ m4_foreach([_AS_var],
   [LANG, LC_ALL, LC_TIME, LC_CTYPE, LANGUAGE,
    LC_COLLATE, LC_NUMERIC, LC_MESSAGES],
   [(set +x; test -n "`(_AS_var=C; export _AS_var) 2>&1`") &&
-    { $as_unset _AS_var || test "${_AS_var+set}" != set; } ||
-      { _AS_var=C; export _AS_var; }
+    { AS_UNSET(_AS_var, C); }
 ])
 
 # Required to use basename.
@@ -206,7 +205,7 @@ as_nl='
 IFS="  $as_nl"
 
 # CDPATH.
-AS_UNSET([CDPATH], [$PATH_SEPARATOR])
+$as_unset CDPATH
 ])
 
 
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.655
retrieving revision 1.656
diff -p -u -r1.655 -r1.656
--- doc/autoconf.texi   30 Aug 2002 01:15:49 -0000      1.655
+++ doc/autoconf.texi   31 Aug 2002 05:46:05 -0000      1.656
@@ -8961,50 +8961,25 @@ fallback value is needed.  We list these
 @table @code
 @item CDPATH
 @evindex CDPATH
-When this variable is set @code{cd} is verbose, so idioms such as
address@hidden $rel && pwd`} break because @code{abs} receives the path
-twice.
-
address@hidden FIXME: Which shells?  How do they behave?
-Setting @code{CDPATH} to the empty value is not enough for most shells.
-A simple path separator is enough except for @code{zsh}, which prefers a
-leading dot:
-
address@hidden
-zsh-3.1.6$ @kbd{mkdir foo && (CDPATH=: cd foo)}
-/tmp/foo
-zsh-3.1.6$ @kbd{(CDPATH=:. cd foo)}
-/tmp/foo
-zsh-3.1.6$ @kbd{(CDPATH=.: cd foo)}
-zsh-3.1.6$
address@hidden example
-
address@hidden
-(of course we could just @command{unset} @code{CDPATH}, since it also
-behaves properly if set to the empty string).
+When this variable is set it specifies a list of directories to search
+when invoking @code{cd} with a relative filename.  @acronym{POSIX}
+1003.1-2001 says that if a nonempty directory name from @code{CDPATH}
+is used successfully, @code{cd} prints the resulting absolute
+filename.  Unfortunately this output can break idioms like
address@hidden src && pwd`} because @code{abs} receives the path twice.
+Also, many shells do not conform to this part of @acronym{POSIX}; for
+example, @command{zsh} prints the result only if a directory name
+other than @file{.} was chosen from @code{CDPATH}.
 
-Life wouldn't be so much fun if @command{bash} and @command{zsh} had the
-same behavior:
+In practice the shells that have this problem also support
address@hidden, so you can work around the problem as follows:
 
 @example
-bash-2.02$ @kbd{mkdir foo && (CDPATH=: cd foo)}
-bash-2.02$ @kbd{(CDPATH=:. cd foo)}
-bash-2.02$ @kbd{(CDPATH=.: cd foo)}
-/tmp/foo
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 @end example
 
-Of course, even better style would be to use @code{PATH_SEPARATOR} instead
-of a @samp{:}.
-Therefore, a portable solution to neutralize @code{CDPATH} is
-
address@hidden
address@hidden@}$PATH_SEPARATOR
address@hidden example
-
address@hidden
-Note that since @command{zsh} supports @command{unset}, you may unset
address@hidden using @code{PATH_SEPARATOR} as a fallback, see
address@hidden of Builtins}.
+Autoconf-generated scripts automatically unset @code{CDPATH} if
+possible, so you need not worry about this problem in those scripts.
 
 @item IFS
 @evindex IFS
@@ -9145,6 +9120,16 @@ When executing the command @samp{>foo}, 
 sets @code{NULLCMD} to @samp{cat}.  If you forgot to set @code{NULLCMD},
 your script might be suspended waiting for data on its standard input.
 
address@hidden PWD
address@hidden 1003.1-2001 requires that @command{cd} and
address@hidden must update the @env{PWD} environment variable to point
+to the logical path to the current directory, but traditional shells
+do not support this.  This can cause confusion if one shell instance
+maintains @env{PWD} but a subsidiary and different shell does not know
+about @env{PWD} and executes @command{cd}; in this case @env{PWD} will
+point to the wrong directory.  Use @samp{`pwd`} rather than
address@hidden
+
 @item status
 @evindex status
 This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
@@ -9206,6 +9191,27 @@ You can't use @command{!}, you'll have t
 The use of @samp{break 2}, etcetera, is safe.
 
 
address@hidden @command{cd} and @command{pwd}
address@hidden ---------------------------------
address@hidden @command{cd}
address@hidden @command{pwd}
address@hidden 1003.1-2001 requires that @command{cd} and
address@hidden must support the @option{-L} and @option{-P} options,
+with @option{-L} being the default.  However, traditional shells do
+not support these options, and their @command{cd} and @command{pwd}
+commands have the @option{-P} behavior.
+
+Portable scripts should assume neither option is supported, and should
+assume neither behavior is the default.  This can be a bit tricky,
+since the @acronym{POSIX} default behavior means that, for example,
address@hidden ..} and @samp{cd ..} may refer to different directories.  It
+is safe to use @command{cd @var{dir}} if @var{dir} contains no
address@hidden components.  Also, Autoconf-generated scripts check for this
+problem when computing variables like @code{ac_top_srcdir}
+(@pxref{Configuration Actions}), so it is safe to @command{cd} to
+these variables.
+
+
 @item @command{case}
 @c -----------------
 @prindex @command{case}
@@ -9431,6 +9437,10 @@ fi
 @end example
 
 
address@hidden @command{pwd}
address@hidden ----------------
+See @command{cd} above.
+
 @item @command{set}
 @c ----------------
 @prindex @command{set}
@@ -9644,7 +9654,7 @@ for @command{true}.
 @prindex @command{unset}
 You cannot assume the support of @command{unset}, nevertheless, because
 it is extremely useful to disable embarrassing variables such as
address@hidden, you can test for its existence and use
address@hidden, you can test for its existence and use
 it @emph{provided} you give a neutralizing value when @command{unset} is
 not supported:
 
@@ -9654,7 +9664,7 @@ if (unset FOO) >/dev/null 2>&1; then
 else
   unset=false
 fi
-$unset CDPATH || CDPATH=:
+$unset PS1 || PS1='$ '
 @end example
 
 @xref{Special Shell Variables}, for some neutralizing values. Also, see




reply via email to

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