From 2d198a1cc54ba0e05b2b61415f48dff91c109fc7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 19 May 2000 11:54:04 +0000 Subject: [PATCH] * 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'. --- ChangeLog | 10 ++++++ acgeneral.m4 | 44 +++++++++++++++++++-------- doc/autoconf.texi | 67 ++++++++++++++++++++++++++++++++++++++++- lib/autoconf/general.m4 | 44 +++++++++++++++++++-------- 4 files changed, 140 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff54358d..541a4d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-05-19 Akim Demaille + + * 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 * acgeneral.m4 (sinclude): Define, some packages (binutils) need diff --git a/acgeneral.m4 b/acgeneral.m4 index b8efdd38..b37d9a30 100644 --- a/acgeneral.m4 +++ b/acgeneral.m4 @@ -473,6 +473,22 @@ $debug || ])# _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). ## ## --------------------------------------------------- ## @@ -1436,29 +1452,33 @@ fi])dnl ])# _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. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index d82ab093..1e0c667b 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -252,6 +252,7 @@ Checking Run Time Behavior 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 @@ -4515,13 +4516,77 @@ well; for example, don't rely on @code{ln} having a @samp{-f} option or @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 diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index b8efdd38..b37d9a30 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -473,6 +473,22 @@ $debug || ])# _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). ## ## --------------------------------------------------- ## @@ -1436,29 +1452,33 @@ fi])dnl ])# _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.