autoconf-patches
[Top][All Lists]
Advanced

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

Re: AS_BASENAME and AS_DIRNAME API change


From: Paul Eggert
Subject: Re: AS_BASENAME and AS_DIRNAME API change
Date: Mon, 24 Apr 2006 12:39:52 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Stepan Kasal <address@hidden> writes:

> But I propose to back out the other changes, including the
> ChangeLog entries for these changes.

Sigh, I suppose you're right, I got overenthusiastic over the weekend.
However, I still think we need to make it clear that
AS_DETECT_REQUIRED, AS_DETECT_SUGGESTED, AS_BASENAME_EXPR,
AS_BASENAME_SED, AS_DIRNAME_EXPR, AS_DIRNAME_SED are not intended to
be exported, by putting a leading _ on these names.

Also, we should check for implementations that mishandle "basename --
file" and "dirname -- file", so that we don't run into unspecified
behavior with files whose name begin with "-".

Also, AS_BASENAME isn't documented and may go away, so autoconf.as
shouldn't use it.

I installed this, which I hope addresses most of the issues you raised.
(It also puts in a log entry for the "runtime" doc patch that I forgot
to put in yesterday.)

Index: ChangeLog
===================================================================
RCS file: /cvsroot/autoconf/autoconf/ChangeLog,v
retrieving revision 1.2847
diff -p -c -r1.2847 ChangeLog
*** ChangeLog   24 Apr 2006 05:54:54 -0000      1.2847
--- ChangeLog   24 Apr 2006 19:34:13 -0000
***************
*** 1,58 ****
  2006-04-23  Paul Eggert  <address@hidden>
  
!       * doc/autoconf.texi (Run Time): Document the exit status situation
!       with more accuracy and detail.
! 
!       * NEWS: Remove mention of AS_VAR_SET_BASENAME and AS_VAR_SET_DIRNAME.
!       * doc/autoconf.texi (Programming in M4sh): Remove mention of
!       AS_VAR_SET_BASENAME, AS_VAR_SET_DIRNAME, and AS_BASENAME.
!       We have to keep AS_DIRNAME since it was part of a stable Autoconf,
!       but AS_BASENAME doesn't have to be supported.
! 
!       * lib/m4sugar/m4sh.m4 (AS_BASENAME, AS_DIRNAME): Bring these back.
! 
! 2006-04-23  Ralf Wildenhues  <address@hidden>
! 
!       * doc/autoconf.texi (Introduction): The GNU Autoconf Macro
!       Archive is not officially `GNU' any more.  Update URL.
!       (Defining Directories): Likewise
!       * lib/autoconf/c.m4 (AC_C_RESTRICT): Update URL.
! 
! 2006-04-22  Paul Eggert  <address@hidden>
  
!       * NEWS: Remove AS_DIRNAME and AS_BASENAME, replacing them with
!       AS_VAR_SET_DIRNAME and AS_VAR_SET_BASENAME.
!       * doc/autoconf.texi (Programming in M4sh): Document this.  All uses
!       changed.  The newer interfaces are more reliable, as they allow
!       implementations that handle trailing newline correctly.  For now,
!       we're in a freeze, so I did not include the more-reliable
!       implementations, but I wanted to correct the interface before 2.60
!       goes out.
        * lib/m4sugar/m4sh.m4 (_AS_DETECT_REQUIRED): Renamed from
        AS_DETECT_REQUIRED.  All uses changed.
        (_AS_DETECT_SUGGESTED): Renamed from AS_DETECT_SUGGESTED.
        All uses changed.
        (_AS_DETECT_BETTER_SHELL): Put ;; at the end of a case.
!       (_AS_BASENAME): Renamed from AS_BASENAME.  All uses changed.
!       Use "basename --" to protect against leading "-".
        (_AS_BASENAME_EXPR): Renamed from AS_BASENAME_EXPR.  All uses changed.
        (_AS_BASENAME_SED): Renamed from AS_BASENAME_SED.  All uses changed.
        (_AS_BASENAME_PREPARE): Reject implementations that cannot handle "--".
        (_AS_DIRNAME_PREPARE): Likewise.
-       (_AS_DIRNAME): Renamed from AS_DIRNAME.  All uses changed.
        (_AS_DIRNAME_EXPR): Renamed from AS_DIRNAME_EXPR.  All uses changed.
        (_AS_DIRNAME_SED): Renamed from AS_DIRNAME_SED.  All uses changed.
!       Use "dirname --".
!       (AS_VAR_SET_BASENAME, AS_VAR_SET_DIRNAME): New macros.
!       * tests/m4sh.at (AS_VAR_SET_DIRNAME): Renamed from AS_DIRNAME.
!       Test the new API.  Don't test internals, since they're probably
!       going to change anyway.
!       (AS_VAR_SET_BASENAME): Likewise, renamed from AS_BASENAME.
! 
!       * bin/autoconf.as: Don't use AS_BASENAME or AS_DIRNAME.  This
!       removes a bootstrapping problem with the changes described above.
!       The AS_DIRNAME part wasn't used, anyway, and the AS_BASENAME
!       part can be done portably without all the deep Autoconf magic.
  
  2006-04-19  Ralf Wildenhues  <address@hidden>
  
--- 1,47 ----
  2006-04-23  Paul Eggert  <address@hidden>
  
!       Prepare for deprecation of AS_BASENAME and AS_DIRNAME, and fix
!       a few minor bugs in this area.
  
!       * doc/autoconf.texi (Programming in M4sh): Comment out the
!       documentation of AS_BASENAME, for now.
!       (Shell Substitutions): Do not use AS_DIRNAME in an example.
!       (Limitations of Builtins) <basename>: Do not refer to
!       AS_BASENAME.
!       * bin/autoconf.as (me): Don't use AS_BASENAME.
!       (dir): Remove the unused variable.
        * lib/m4sugar/m4sh.m4 (_AS_DETECT_REQUIRED): Renamed from
        AS_DETECT_REQUIRED.  All uses changed.
        (_AS_DETECT_SUGGESTED): Renamed from AS_DETECT_SUGGESTED.
        All uses changed.
        (_AS_DETECT_BETTER_SHELL): Put ;; at the end of a case.
!       (AS_BASENAME): Use "basename --" to protect against leading "-".
        (_AS_BASENAME_EXPR): Renamed from AS_BASENAME_EXPR.  All uses changed.
        (_AS_BASENAME_SED): Renamed from AS_BASENAME_SED.  All uses changed.
        (_AS_BASENAME_PREPARE): Reject implementations that cannot handle "--".
        (_AS_DIRNAME_PREPARE): Likewise.
        (_AS_DIRNAME_EXPR): Renamed from AS_DIRNAME_EXPR.  All uses changed.
        (_AS_DIRNAME_SED): Renamed from AS_DIRNAME_SED.  All uses changed.
!       (AS_DIRNAME): Use "dirname --".
! 
! 2006-04-23  Paul Eggert  <address@hidden>
! 
!       * doc/autoconf.texi (Runtime): Renamed from "Run Time".  All uses
!       of "run time" and "run-time" changed to "runtime", for consistency.
!       * lib/autoconf/fortran.m4: Likewise (in comment).
!       * lib/autoconf/functions.m4: Likewise.
!       * lib/autoconf/general.m4: Likewise.
!       * lib/autoconf/headers.m4: Likewise.
! 
!       * doc/autoconf.texi (Run Time): Document the exit status situation
!       with more accuracy and detail.
! 
! 2006-04-23  Ralf Wildenhues  <address@hidden>
! 
!       * doc/autoconf.texi (Introduction): The GNU Autoconf Macro
!       Archive is not officially `GNU' any more.  Update URL.
!       (Defining Directories): Likewise
!       * lib/autoconf/c.m4 (AC_C_RESTRICT): Update URL.
  
  2006-04-19  Ralf Wildenhues  <address@hidden>
  
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.999
diff -p -c -r1.999 autoconf.texi
*** doc/autoconf.texi   24 Apr 2006 06:51:53 -0000      1.999
--- doc/autoconf.texi   24 Apr 2006 19:34:14 -0000
*************** For the time being, it is not mature eno
*** 9666,9671 ****
--- 9666,9681 ----
  M4sh provides portable alternatives for some common shell constructs
  that unfortunately are not portable in practice.
  
+ @c Deprecated, to be replaced by a better API
+ @ignore
+ @defmac AS_BASENAME (@var{file-name})
+ @asindex{BASENAME}
+ Output the non-directory portion of @var{file-name}.  For example,
+ if @code{$file} is @samp{/one/two/three}, the command
+ @code{base=`AS_BASENAME(["$file"])`} sets @code{base} to @samp{three}.
+ @end defmac
+ @end ignore
+ 
  @defmac AS_BOURNE_COMPATIBLE
  @asindex{BOURNE_COMPATIBLE}
  Set up the shell to be more compatible with the Bourne shell as
*************** fields in a record.  You may be able to 
*** 12483,12488 ****
--- 12493,12519 ----
  Not all hosts have a working @command{basename}.
  You can use @command{expr} instead.
  
+ @c AS_BASENAME is to be replaced by a better API.
+ @ignore
+ Not all hosts have a working @command{basename}, and you should instead
+ use @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by
+ @command{expr} if you need to strip a suffix.  For example:
+ 
+ @example
+ a=`basename "$aname"`       # This is not portable.
+ a=`AS_BASENAME(["$aname"])` # This is more portable.
+ 
+ # This is not portable.
+ c=`basename "$cname" .c`
+ 
+ # This is more portable.
+ c=`AS_BASENAME(["$cname"])`
+ case $c in
+ ?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;
+ esac
+ @end example
+ @end ignore
+ 
  
  @item @command{cat}
  @c ----------------
Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.911
diff -p -c -r1.911 general.m4
*** lib/autoconf/general.m4     24 Apr 2006 06:51:53 -0000      1.911
--- lib/autoconf/general.m4     24 Apr 2006 19:34:15 -0000
*************** dnl We reimplement AC_MSG_CHECKING (most
*** 440,447 ****
    _AS_ECHO_N([checking for prefix by ])
    AC_PATH_PROG(ac_prefix_program, [$1])
    if test -n "$ac_prefix_program"; then
!     AS_VAR_SET_DIRNAME([prefix], ["$ac_prefix_program"])
!     AS_VAR_SET_DIRNAME([prefix], ["$prefix"])
    fi
  fi
  ])# AC_PREFIX_PROGRAM
--- 440,447 ----
    _AS_ECHO_N([checking for prefix by ])
    AC_PATH_PROG(ac_prefix_program, [$1])
    if test -n "$ac_prefix_program"; then
!     prefix=`AS_DIRNAME(["$ac_prefix_program"])`
!     prefix=`AS_DIRNAME(["$prefix"])`
    fi
  fi
  ])# AC_PREFIX_PROGRAM
*************** m4_divert_push([PARSE_ARGS])dnl
*** 489,495 ****
  if test -z "$srcdir"; then
    ac_srcdir_defaulted=yes
    # Try the directory containing this script, then the parent directory.
!   AS_VAR_SET_DIRNAME([ac_confdir], ["$[0]"])
    srcdir=$ac_confdir
    if test ! -r "$srcdir/$ac_unique_file"; then
      srcdir=..
--- 489,495 ----
  if test -z "$srcdir"; then
    ac_srcdir_defaulted=yes
    # Try the directory containing this script, then the parent directory.
!   ac_confdir=`AS_DIRNAME(["$[0]"])`
    srcdir=$ac_confdir
    if test ! -r "$srcdir/$ac_unique_file"; then
      srcdir=..
Index: lib/autoconf/status.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v
retrieving revision 1.97
diff -p -c -r1.97 status.m4
*** lib/autoconf/status.m4      23 Apr 2006 06:49:53 -0000      1.97
--- lib/autoconf/status.m4      24 Apr 2006 19:34:15 -0000
*************** do
*** 1427,1433 ****
      ;;
    esac
  
!   AS_VAR_SET_DIRNAME([ac_dir], ["$ac_file"])
    AS_MKDIR_P(["$ac_dir"])
    _AC_SRCDIRS(["$ac_dir"])
  
--- 1427,1433 ----
      ;;
    esac
  
!   ac_dir=`AS_DIRNAME(["$ac_file"])`
    AS_MKDIR_P(["$ac_dir"])
    _AC_SRCDIRS(["$ac_dir"])
  
Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.182
diff -p -c -r1.182 m4sh.m4
*** lib/m4sugar/m4sh.m4 23 Apr 2006 08:13:43 -0000      1.182
--- lib/m4sugar/m4sh.m4 24 Apr 2006 19:34:15 -0000
*************** _AS_EXPR_PREPARE
*** 382,388 ****
  _AS_BASENAME_PREPARE
  
  # Name of the executable.
! AS_VAR_SET_BASENAME([as_me], [$[0]])
  
  # CDPATH.
  $as_unset CDPATH
--- 382,388 ----
  _AS_BASENAME_PREPARE
  
  # Name of the executable.
! as_me=`AS_BASENAME("$[0]")`
  
  # CDPATH.
  $as_unset CDPATH
*************** m4_define([AS_ERROR],
*** 659,666 ****
  # This section is lexicographically sorted.
  
  
! # _AS_BASENAME(FILE-NAME)
! # -----------------------
  # Simulate the command 'basename FILE-NAME'.  Not all systems have basename.
  # Also see the comments for AS_DIRNAME.
  
--- 659,666 ----
  # This section is lexicographically sorted.
  
  
! # AS_BASENAME(FILE-NAME)
! # ----------------------
  # Simulate the command 'basename FILE-NAME'.  Not all systems have basename.
  # Also see the comments for AS_DIRNAME.
  
*************** m4_defun([_AS_BASENAME_SED],
*** 686,709 ****
          }
          s/.*/./; q']])
  
! m4_defun([_AS_BASENAME],
! [AS_REQUIRE([$0_PREPARE])dnl
  $as_basename -- $1 ||
  _AS_BASENAME_EXPR([$1]) 2>/dev/null ||
  _AS_BASENAME_SED([$1])])
  
- # Some programs rely on _AS_BASENAME being called AS_BASENAME.
- # They should be rewritten to use AS_VAR_SET_BASENAME, but in
- # the meantime we'll leave AS_BASENAME in as an undocumented macro.
- m4_defun([AS_BASENAME], [_AS_BASENAME([$1])])
- 
  
  # _AS_BASENAME_PREPARE
  # --------------------
  # Avoid Solaris 9 /usr/ucb/basename, as `basename /' outputs an empty line.
  # Also, traditional basename mishandles --.
  m4_defun([_AS_BASENAME_PREPARE],
! [if as_basename=`(basename -- /) 2>&1` && test "X$as_basename" = "X/"; then
    as_basename=basename
  else
    as_basename=false
--- 686,704 ----
          }
          s/.*/./; q']])
  
! m4_defun([AS_BASENAME],
! [AS_REQUIRE([_$0_PREPARE])dnl
  $as_basename -- $1 ||
  _AS_BASENAME_EXPR([$1]) 2>/dev/null ||
  _AS_BASENAME_SED([$1])])
  
  
  # _AS_BASENAME_PREPARE
  # --------------------
  # Avoid Solaris 9 /usr/ucb/basename, as `basename /' outputs an empty line.
  # Also, traditional basename mishandles --.
  m4_defun([_AS_BASENAME_PREPARE],
! [if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; 
then
    as_basename=basename
  else
    as_basename=false
*************** fi
*** 711,718 ****
  ])# _AS_BASENAME_PREPARE
  
  
! # _AS_DIRNAME(FILE-NAME)
! # ----------------------
  # Simulate the command 'dirname FILE-NAME'.  Not all systems have dirname.
  # This macro must be usable from inside ` `.
  #
--- 706,713 ----
  ])# _AS_BASENAME_PREPARE
  
  
! # AS_DIRNAME(FILE-NAME)
! # ---------------------
  # Simulate the command 'dirname FILE-NAME'.  Not all systems have dirname.
  # This macro must be usable from inside ` `.
  #
*************** m4_defun([_AS_DIRNAME_SED],
*** 749,765 ****
          }
          s/.*/./; q']])
  
! m4_defun([_AS_DIRNAME],
! [AS_REQUIRE([$0_PREPARE])dnl
  $as_dirname -- $1 ||
  _AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
  _AS_DIRNAME_SED([$1])])
  
- # Some programs rely on _AS_DIRNAME being called AS_DIRNAME.
- # They should be rewritten to use AS_VAR_SET_DIRNAME, but in
- # the meantime we'll leave AS_DIRNAME in as an undocumented macro.
- m4_defun([AS_DIRNAME], [_AS_DIRNAME([$1])])
- 
  
  # _AS_DIRNAME_PREPARE
  # --------------------
--- 744,755 ----
          }
          s/.*/./; q']])
  
! m4_defun([AS_DIRNAME],
! [AS_REQUIRE([_$0_PREPARE])dnl
  $as_dirname -- $1 ||
  _AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
  _AS_DIRNAME_SED([$1])])
  
  
  # _AS_DIRNAME_PREPARE
  # --------------------
*************** m4_define([AS_MKDIR_P],
*** 917,923 ****
      as_dirs=
      while test ! -d "$as_dir"; do
        as_dirs="$as_dir $as_dirs"
!       AS_VAR_SET_DIRNAME([as_dir], ["$as_dir"])
      done
      test ! -n "$as_dirs" || mkdir $as_dirs
    fi || AS_ERROR([cannot create directory $1]); }dnl
--- 907,913 ----
      as_dirs=
      while test ! -d "$as_dir"; do
        as_dirs="$as_dir $as_dirs"
!       as_dir=`AS_DIRNAME("$as_dir")`
      done
      test ! -n "$as_dirs" || mkdir $as_dirs
    fi || AS_ERROR([cannot create directory $1]); }dnl
*************** rm -f conf$$.file
*** 1020,1041 ****
  ])# _AS_TEST_PREPARE
  
  
- # AS_VAR_SET_BASENAME(VARIABLE, FILE-NAME)
- # ----------------------------------------
- # Simulate VARIABLE=`basename FILE-NAME`.
- m4_defun([AS_VAR_SET_BASENAME],
- [$1=$2
- $1=`_AS_BASENAME(["$$1"])`])
- 
- 
- # AS_VAR_SET_DIRNAME(VARIABLE, FILE-NAME)
- # ---------------------------------------
- # Simulate the command VARIABLE=`dirname FILE-NAME`.
- m4_defun([AS_VAR_SET_DIRNAME],
- [$1=$2
- $1=`_AS_DIRNAME(["$$1"])`])
- 
- 
  
  
  ## ------------------ ##
--- 1010,1015 ----
Index: tests/m4sh.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/m4sh.at,v
retrieving revision 1.46
diff -p -c -r1.46 m4sh.at
*** tests/m4sh.at       23 Apr 2006 06:49:53 -0000      1.46
--- tests/m4sh.at       24 Apr 2006 19:34:15 -0000
*************** AT_CLEANUP
*** 95,114 ****
  
  
  
! ## -------------------- ##
! ## AS_VAR_SET_DIRNAME.  ##
! ## -------------------- ##
  
  # Build nested dirs.
! AT_SETUP([AS@&address@hidden)
  
  AT_DATA_M4SH([script.as],
  [[AS_INIT
  
  m4_define([DIRNAME_TEST],
! [AS_VAR_SET_DIRNAME([dir], [$1])
  test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
!   echo "dirname($1) = $dir instead of $2" >&2])
  
  DIRNAME_TEST([/],             [/])
  DIRNAME_TEST([//],            [//],   [/])
--- 95,126 ----
  
  
  
! ## ------------ ##
! ## AS_DIRNAME.  ##
! ## ------------ ##
  
  # Build nested dirs.
! AT_SETUP([AS@&address@hidden)
  
  AT_DATA_M4SH([script.as],
  [[AS_INIT
  
+ # The EXPR variant is allowed to fail if `expr' was considered as too
+ # weak for us, in which case `as_expr=false'.
  m4_define([DIRNAME_TEST],
! [dir=`AS_DIRNAME([$1])`
! test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
!   echo "dirname($1) = $dir instead of $2" >&2
! 
! if test "$as_expr" != false; then
!   dir=`_AS_DIRNAME_EXPR([$1])`
!   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
!     echo "dirname_expr($1) = $dir instead of $2" >&2
! fi
! 
! dir=`_AS_DIRNAME_SED([$1])`
  test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
!   echo "dirname_sed($1) = $dir instead of $2" >&2])
  
  DIRNAME_TEST([/],             [/])
  DIRNAME_TEST([//],            [//],   [/])
*************** AT_CLEANUP
*** 143,162 ****
  
  
  
! ## --------------------- ##
! ## AS_VAR_SET_BASENAME.  ##
! ## --------------------- ##
  
  # Build nested dirs.
! AT_SETUP([AS@&address@hidden)
  
  AT_DATA_M4SH([script.as],
  [[AS_INIT
  
  m4_define([BASENAME_TEST],
! [AS_VAR_SET_BASENAME([base], [$1])
  test "$base" = "$2" ||
!   echo "basename($1) = $base instead of $2" >&2])
  
  BASENAME_TEST([//1],             [1])
  BASENAME_TEST([/1],              [1])
--- 155,178 ----
  
  
  
! ## ------------- ##
! ## AS_BASENAME.  ##
! ## ------------- ##
  
  # Build nested dirs.
! AT_SETUP([AS@&address@hidden)
  
  AT_DATA_M4SH([script.as],
  [[AS_INIT
  
  m4_define([BASENAME_TEST],
! [base=`AS_BASENAME([$1])`
! test "$base" = "$2" ||
!   echo "basename($1) = $base instead of $2" >&2
! 
! base=`_AS_BASENAME_SED([$1])`
  test "$base" = "$2" ||
!   echo "basename_sed($1) = $base instead of $2" >&2])
  
  BASENAME_TEST([//1],             [1])
  BASENAME_TEST([/1],              [1])




reply via email to

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