(_AC_INIT_PREPARE_ENVIRONMENT): Use AC_SHELL_UNSETENV.
Set CDPATH. Fixes Autoconf/96.
* doc/autoconf.texi (Special Shell Variables): New node.
Document `status', `CDPATH', `LANG', `LC_ALL', `LC_MESSAGES' and
`LC_CTYPE'.
+2000-05-19 Akim Demaille <akim@epita.fr>
+
+ * acgeneral.m4 (AC_SHELL_UNSET, AC_SHELL_UNSETENV): New macro.
+ (_AC_INIT_PREPARE_ENVIRONMENT): Use AC_SHELL_UNSETENV.
+ Set CDPATH. Fixes Autoconf/96.
+
+ * doc/autoconf.texi (Special Shell Variables): New node.
+ Document `status', `CDPATH', `LANG', `LC_ALL', `LC_MESSAGES' and
+ `LC_CTYPE'.
+
2000-05-12 Akim Demaille <akim@epita.fr>
* acgeneral.m4 (sinclude): Define, some packages (binutils) need
])# _AC_SHELL_TMPDIR
+# AC_SHELL_UNSET(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
+# --------------------------------------------------------
+# Try to unset the env VAR, otherwise set it to
+# VALUE-IF-UNSET-NOT-SUPPORTED. `ac_unset' must have been computed.
+define([AC_SHELL_UNSET],
+[$ac_unset $1 || test ${$1+set} != set || $1=$2])
+
+
+# AC_SHELL_UNSETENV(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
+# --------------------------------------------------------
+# Try to unset the env VAR, otherwise set it to
+# VALUE-IF-UNSET-NOT-SUPPORTED. `ac_unset' must have been computed.
+define([AC_SHELL_UNSETENV],
+[$ac_unset $1 || test ${$1+set} != set || $1=$2 && export $1])
+
+
## --------------------------------------------------- ##
## Common m4/sh handling of variables (indirections). ##
## --------------------------------------------------- ##
])# _AC_INIT_VERSION
-
# _AC_INIT_PREPARE_ENVIRONMENT
# ----------------------------
# Tune the envvar we depend upon: IFS, NLS.
-# FIXME: CDPATH.
define([_AC_INIT_PREPARE_ENVIRONMENT],
-[# NLS nuisances.
-# Only set these to C if already set. These must not be set unconditionally
-# because not all systems understand e.g. LANG=C (notably SCO).
-# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
-# Non-C LC_CTYPE values break the ctype check.
-if test "${LANG+set}" = set; then LANG=C; export LANG; fi
-if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
-if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
-if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+[if (unset FOO) >/dev/null 2>&1; then
+ ac_unset=unset
+else
+ ac_unset=false
+fi
+
+# NLS nuisances.
+AC_SHELL_UNSETENV([LANG], [C])
+AC_SHELL_UNSETENV([LC_ALL], [C])
+AC_SHELL_UNSETENV([LC_CTYPE], [C])
+AC_SHELL_UNSETENV([LC_MESSAGES], [C])
# IFS
# We need space, tab and new line, in precisely that order.
ac_nl='
'
-IFS=" $ac_nl"dnl
+IFS=" $ac_nl"
+
+# CDPATH.
+AC_SHELL_UNSETENV([CDPATH], [:])
])
+
# _AC_INIT_PREPARE
# ----------------
# Called by AC_INIT to build the preamble of the `configure' scripts.
Portable Shell Programming
+* Special Shell Variables::
* Testing Values and Files:: Checking strings and files
* Shell Substitutions:: Test and assign
* Limitations of Usual Tools:: Portable use of portable tools
@code{cat} having any options.
@menu
+* Special Shell Variables:: Variables you should not change
* Testing Values and Files:: Checking strings and files
* Shell Substitutions:: Test and assign
* Limitations of Usual Tools:: Portable use of portable tools
* Exiting from Shell Scripts:: How to exit from an autoconf shell script
@end menu
-@node Testing Values and Files, Shell Substitutions, Portable Shell, Portable Shell
+@node Special Shell Variables, Testing Values and Files, Portable Shell, Portable Shell
+@subsection Special Shell Variables
+
+Some shell variables shall not be used. Since currently Autoconf does
+not use @code{unset}, there are some variables which need some specific
+values to disable the features they control.
+
+@c Alphabetical order, case insensitive, `A' before `a'.
+@table @code
+@item CDPATH
+@evindex CDPATH
+Because when this variable is set @code{cd} is verbose, idioms such as
+@samp{abs=`cd $rel && pwd`} break, since @code{abs} receives twice the
+path.
+
+@c FIXME: Which shells? How do they behave?
+Setting @code{CDPATH} to the empty value is not enough for most shells.
+A simple colon is enough but for @code{zsh}, which prefers a leading dot:
+
+@example
+~ % mkdir foo && CDPATH=: cd foo
+~/foo
+~ % CDPATH=:. cd foo
+~/foo
+~ % CDPATH=.: cd foo
+~ %
+@end example
+
+@noindent
+(of course we could just @code{unset} @code{CDPATH}, it also behaves
+properly if set to the empty string).
+
+Therefore a portable solution to neutralize @samp{CDPATH} is
+@samp{CDPATH=$@{ZSH_VERSION+.@}:}.
+
+@item LANG
+@itemx LC_ALL
+@itemx LC_MESSAGES
+@itemx LC_CTYPE
+@evindex LANG
+@evindex LC_ALL
+@evindex LC_MESSAGES
+@evindex LC_CTYPE
+
+These must not be set unconditionally because not all systems understand
+e.g. @strong{LANG=C} (notably SCO). Fixing @code{LC_MESSAGES} prevents
+Solaris @command{sh} from translating var values in @code{set}! Non-C
+@code{LC_CTYPE} values break the ctype check. Therefore, run:
+
+@example
+test "$@{LANG+set@}" = set && LANG=C && export LANG
+test "$@{LC_ALL+set@}" = set && LC_ALL=C && export LC_ALL
+test "$@{LC_CTYPE+set@}" = set && LC_CTYPE=C && export LC_CTYPE
+test "$@{LC_MESSAGES+set@}" = set && LC_MESSAGES=C && export LC_MESSAGES
+@end example
+
+@item status
+@evindex status
+This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
+hence read-only. Do not use it.
+@end table
+
+
+@node Testing Values and Files, Shell Substitutions, Special Shell Variables, Portable Shell
@subsection Testing Values and Files
@code{configure} scripts need to test properties of many files and
])# _AC_SHELL_TMPDIR
+# AC_SHELL_UNSET(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
+# --------------------------------------------------------
+# Try to unset the env VAR, otherwise set it to
+# VALUE-IF-UNSET-NOT-SUPPORTED. `ac_unset' must have been computed.
+define([AC_SHELL_UNSET],
+[$ac_unset $1 || test ${$1+set} != set || $1=$2])
+
+
+# AC_SHELL_UNSETENV(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
+# --------------------------------------------------------
+# Try to unset the env VAR, otherwise set it to
+# VALUE-IF-UNSET-NOT-SUPPORTED. `ac_unset' must have been computed.
+define([AC_SHELL_UNSETENV],
+[$ac_unset $1 || test ${$1+set} != set || $1=$2 && export $1])
+
+
## --------------------------------------------------- ##
## Common m4/sh handling of variables (indirections). ##
## --------------------------------------------------- ##
])# _AC_INIT_VERSION
-
# _AC_INIT_PREPARE_ENVIRONMENT
# ----------------------------
# Tune the envvar we depend upon: IFS, NLS.
-# FIXME: CDPATH.
define([_AC_INIT_PREPARE_ENVIRONMENT],
-[# NLS nuisances.
-# Only set these to C if already set. These must not be set unconditionally
-# because not all systems understand e.g. LANG=C (notably SCO).
-# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
-# Non-C LC_CTYPE values break the ctype check.
-if test "${LANG+set}" = set; then LANG=C; export LANG; fi
-if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
-if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
-if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+[if (unset FOO) >/dev/null 2>&1; then
+ ac_unset=unset
+else
+ ac_unset=false
+fi
+
+# NLS nuisances.
+AC_SHELL_UNSETENV([LANG], [C])
+AC_SHELL_UNSETENV([LC_ALL], [C])
+AC_SHELL_UNSETENV([LC_CTYPE], [C])
+AC_SHELL_UNSETENV([LC_MESSAGES], [C])
# IFS
# We need space, tab and new line, in precisely that order.
ac_nl='
'
-IFS=" $ac_nl"dnl
+IFS=" $ac_nl"
+
+# CDPATH.
+AC_SHELL_UNSETENV([CDPATH], [:])
])
+
# _AC_INIT_PREPARE
# ----------------
# Called by AC_INIT to build the preamble of the `configure' scripts.