libtool-patches
[Top][All Lists]
Advanced

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

[PATCH] getopt.m4sh generated libtool option parser, and XSI improvement


From: Gary V. Vaughan
Subject: [PATCH] getopt.m4sh generated libtool option parser, and XSI improvements.
Date: Wed, 23 Jun 2010 03:23:39 +0700

This is the improved (and renamed) `Use getopt.m4sh to generate libtool
option parser.' patch I promised yesterday.  I'm pretty happy with this,
save that even though _LT_PROG_XSI_REPLACE correctly generates sed
scripts in config.status of the form:

  sed -i .tmp -e '/^func_name ()$/,/^} # func_name/c\
func_name ()\
{\
  indented code\
    over several\
  lines\
} # XSI func_name implementation' $cfgfile || ...

which, when run from the command line, retains the indentation of the
function body, but somehow deletes that indentation when run from
config.status.  It doesn't affect the functionality of the patch which
passes the testsuite with and without the XSI replacements in effect.

Other than that, this allows us to put the fallback implementations of
functions in the files which depend on them, and eliminate a fixme in
libtool.m4.

Any ideas why the indentation is lost like this?

And in any case, okay to push?

(Amusingly, I think I've just invented hyper-programming:
_LT_PROG_XSI_REPLACE is an m4 program, that writes a sed program
that is copied by a shell program (configure) into another shell-script
(config.status) which then rewrites yet another shell script (libtool)
so that it can compile and link other programs more effectively!! =)O| )

Cheers,
Gary

* libltdl/m4/libtool.m4 (_LT_PROG_XSI_SHELLFNS): Moved portable
shell versions of various utility functions from here...
* libltdl/config/getopt.m4sh (func_split_long_opt): ...to here...
* libltdl/config/general.m4sh (func_dirname, func_basename)
(func_dirname_and_basename, func_strip_name): ...here...
* libltdl/config/ltmain.m4sh (func_append, func_arith, func_len)
(func_lo2o, func_xform): ...and here.
* libltdl/config/libtool.m4 (_LT_PROG_XSI_REPLACE): New macro that
expands into a sed command for replacing the contents of a
suitably decorated shell function with an alternate XSI
implementation.
(_LT_PROG_XSI_SHELLFNS): Use it to replace the portable shell
versions of the functions above with equivalent XSI
implementations that avoid unnecessary forks if the host shell
supports that.
* libltdl/config/ltmain.m4sh: Replace hand written shell code
with a call to M4SH_GETOPTS. Rename some option variables in
the client code to match the generated option parser settings.
* libltdl/config/general.m4sh (func_echo, func_error)
(func_warning): Use $opt_mode instead of obsoleted $mode in
message leader.

Signed-off-by: Gary V. Vaughan <address@hidden>
---
 ChangeLog                   |   25 +++
 libltdl/config/general.m4sh |   61 ++++++--
 libltdl/config/getopt.m4sh  |   49 ++++--
 libltdl/config/ltmain.m4sh  |  367 ++++++++++++++++++++-----------------------
 libltdl/m4/libtool.m4       |  255 +++++++-----------------------
 5 files changed, 333 insertions(+), 424 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 18e346d..aad234c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2010-06-22  Gary V. Vaughan  <address@hidden>
+
+       getopt.m4sh generated libtool option parser, and XSI improvements.
+       * libltdl/m4/libtool.m4 (_LT_PROG_XSI_SHELLFNS): Moved portable
+       shell versions of various utility functions from here...
+       * libltdl/config/getopt.m4sh (func_split_long_opt): ...to here...
+       * libltdl/config/general.m4sh (func_dirname, func_basename)
+       (func_dirname_and_basename, func_strip_name): ...here...
+       * libltdl/config/ltmain.m4sh (func_append, func_arith, func_len)
+       (func_lo2o, func_xform): ...and here.
+       * libltdl/config/libtool.m4 (_LT_PROG_XSI_REPLACE): New macro that
+       expands into a sed command for replacing the contents of a
+       suitably decorated shell function with an alternate XSI
+       implementation.
+       (_LT_PROG_XSI_SHELLFNS): Use it to replace the portable shell
+       versions of the functions above with equivalent XSI
+       implementations that avoid unnecessary forks if the host shell
+       supports that.
+       * libltdl/config/ltmain.m4sh: Replace hand written shell code
+       with a call to M4SH_GETOPTS. Rename some option variables in
+       the client code to match the generated option parser settings.
+       * libltdl/config/general.m4sh (func_echo, func_error)
+       (func_warning): Use $opt_mode instead of obsoleted $mode in
+       message leader.
+
 2010-06-21  Gary V. Vaughan  <address@hidden>
 
        Ensure getopts.m4sh is compatible with Autoconf-2.61 and newer.
diff --git a/libltdl/config/general.m4sh b/libltdl/config/general.m4sh
index bb254cc..8a6912d 100644
--- a/libltdl/config/general.m4sh
+++ b/libltdl/config/general.m4sh
@@ -73,6 +73,27 @@ IFS="        $lt_nl"
 dirname="s,/[^/]*$,,"
 basename="s,^.*/,,"
 
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+    func_dirname_result=`$ECHO "${1}" | $SED "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+} # func_dirname may be replaced by XSI optimised implementation
+
+
+# func_basename file
+func_basename ()
+{
+    func_basename_result=`$ECHO "${1}" | $SED "$basename"`
+} # func_basename may be replaced by XSI optimised implementation
+
+
 # func_dirname_and_basename file append nondir_replacement
 # perform func_basename and func_dirname in a single function
 # call:
@@ -87,17 +108,31 @@ basename="s,^.*/,,"
 # those functions but instead duplicate the functionality here.
 func_dirname_and_basename ()
 {
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "${1}" | $SED -e "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-  func_basename_result=`$ECHO "${1}" | $SED -e "$basename"`
-}
+    # Extract subdirectory from the argument.
+    func_dirname_result=`$ECHO "${1}" | $SED -e "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+    func_basename_result=`$ECHO "${1}" | $SED -e "$basename"`
+} # func_dirname_and_basename may be replaced by XSI optimised implementation
+
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{ 
+    case ${2} in
+      .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; 
s%\\\\${2}\$%%"`;; 
+      *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
+    esac
+} # func_stripname may be replaced by XSI optimised implementation
 
-# Generated shell functions inserted here.
 
 # These SED scripts presuppose an absolute path with a trailing slash.
 pathcar='s,^/\([^/]*\).*$,\1,'
@@ -308,7 +343,7 @@ opt_warning=:
 # name if it has been set yet.
 func_echo ()
 {
-    $ECHO "$progname${mode+: }$mode: $*"
+    $ECHO "$progname: ${opt_mode+$opt_mode: }$*"
 }
 
 # func_verbose arg...
@@ -334,14 +369,14 @@ func_echo_all ()
 # Echo program name prefixed message to standard error.
 func_error ()
 {
-    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
+    $ECHO "$progname: ${opt_mode+$opt_mode: }"${1+"$@"} 1>&2
 }
 
 # func_warning arg...
 # Echo program name prefixed warning message to standard error.
 func_warning ()
 {
-    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
+    $opt_warning && $ECHO "$progname: ${opt_mode+$opt_mode: }warning: 
"${1+"$@"} 1>&2
 
     # bash bug again:
     :
diff --git a/libltdl/config/getopt.m4sh b/libltdl/config/getopt.m4sh
index 031402c..1487755 100644
--- a/libltdl/config/getopt.m4sh
+++ b/libltdl/config/getopt.m4sh
@@ -463,13 +463,7 @@ m4go_defaults
 
 # Parse options once, thoroughly.  This comes as soon as possible in the
 # script to make things like `--version' happen as quickly as we can.
-{M4SH_VERBATIM([[
-  # sed scripts
-  my_sed_single_opt='1s/^\(..\).*$/\1/;q'
-  my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
-  my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
-  my_sed_long_arg='1s/^--[^=]*=//'
-]])
+{
   # this just eases exit handling
   while test [$]# -gt 0; do
     opt="[$]1"
@@ -486,27 +480,24 @@ m4go_branches
 
       # Separate optargs to long options:
       --*=*)
-                       arg=`echo "$opt" | $SED "$my_sed_long_arg"`
-                       opt=`echo "$opt" | $SED "$my_sed_long_opt"`
-                       set dummy "$opt" "$arg" ${1+"[$]@"}
+                       func_split_long_opt "$opt"
+                       set dummy "$func_split_long_opt_name" 
"$func_split_long_opt_arg" ${1+"[$]@"}
                        shift
                        ;;
 
 m4_ifset([m4go_shortargs], dnl (
 [      # Separate optargs to short options:
       ]m4go_shortargs[)
-                       arg=`echo "$opt" |$SED "$my_sed_single_rest"`
-                       opt=`echo "$opt" |$SED "$my_sed_single_opt"`
-                       set dummy "$opt" "$arg" ${1+"[$]@"}
+                       func_split_short_opt "$opt"
+                       set dummy "$func_split_short_opt_name" 
"$func_split_short_opt_arg" ${1+"[$]@"}
                        shift
                        ;;
 
 ])m4_ifset([m4go_shortnoargs], dnl (
 [      # Separate non-argument short options:
       ]m4go_shortnoargs[)
-                       rest=`echo "$opt" |$SED "$my_sed_single_rest"`
-                       opt=`echo "$opt" |$SED "$my_sed_single_opt"`
-                       set dummy "$opt" "-$rest" ${1+"[$]@"}
+                       func_split_short_opt "$opt"
+                       set dummy "$func_split_short_opt_name" 
"$func_split_short_opt_arg" ${1+"[$]@"}
                        shift
                        ;;
 
@@ -619,6 +610,32 @@ func_missing_arg ()
     exit_cmd=exit
 }
 
+
+# func_split_short_opt shortopt
+# Set func_split_short_opt_name and func_split_short_opt_arg shell
+# variables after splitting SHORTOPT at the `=' sign.
+func_split_short_opt ()
+{
+    my_sed_short_opt='1s/^\(..\).*$/\1/;q'
+    my_sed_short_rest='1s/^..\(.*\)$/\1/;q'
+
+    func_split_short_opt_name=`$ECHO "$1" | $SED "$my_sed_short_opt"`
+    func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_arg"`
+} # func_split_short_opt may be replaced by XSI optimised implementation
+
+
+# func_split_long_opt longopt
+# Set func_split_long_opt_name and func_split_long_opt_arg shell
+# variables after splitting LONGOPT at the `=' sign.
+func_split_long_opt ()
+{
+    my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
+    my_sed_long_arg='1s/^--[^=]*=//'
+
+    func_split_long_opt_name=`$ECHO "$1" | $SED "$my_sed_long_opt"`
+    func_split_long_opt_arg=`$ECHO "$1" | $SED "$my_sed_long_arg"`
+} # func_split_long_opt may be replaced by XSI optimised implementation
+
 exit_cmd=:
 ]])
 
diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index a325e27..0262322 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -133,30 +133,60 @@ m4_define([M4SH_IN_HEADER], [$1])dnl
 m4_include([getopt.m4sh])
 
 M4SH_VERBATIM([[
-
 magic="%%%MAGIC variable%%%"
 magic_exe="%%%MAGIC EXE variable%%%"
 
 # Global variables.
 # $mode is unset
 nonopt=
-execute_dlfiles=
 preserve_args=
 lo2o="s/\\.lo\$/.${objext}/"
 o2lo="s/\\.${objext}\$/.lo/"
 extracted_archives=
 extracted_serial=0
 
-opt_dry_run=false
-opt_duplicate_deps=false
-opt_silent=false
-opt_debug=:
-
 # If this variable is set in any of the actions, the command in it
 # will be execed at the end.  This prevents here-documents from being
 # left over by shells.
 exec_cmd=
 
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+    eval "${1}=\$${1}\${2}"
+} # func_append may be replaced by XSI optimised implementation
+
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+    func_arith_result=`expr "address@hidden"`
+} # func_arith may be replaced by XSI optimised implementation
+
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+    func_len_result=`expr "${1}" : ".*" 2>/dev/null || echo $max_cmd_len`
+} # func_len may be replaced by XSI optimised implementation
+
+
+# func_lo2o object
+func_lo2o ()
+{
+    func_lo2o_result=`$ECHO "${1}" | $SED "$lo2o"`
+} # func_lo2o may be replaced by XSI optimised implementation
+
+
+# func_xform libobj-or-source
+func_xform ()
+{
+    func_xform_result=`$ECHO "${1}" | $SED 's/\.[[^.]]*$/.lo/'`
+} # func_xform may be replaced by XSI optimised implementation
+
+
 # func_fatal_configuration arg...
 # Echo program name prefixed message to standard error, followed by
 # a configuration failure hint, and exit.
@@ -246,145 +276,6 @@ func_enable_tag ()
   esac
 }
 
-# Parse options once, thoroughly.  This comes as soon as possible in
-# the script to make things like `libtool --version' happen quickly.
-{
-
-  # Shorthand for --mode=foo, only valid as the first argument
-  case $1 in
-  clean|clea|cle|cl)
-    shift; set dummy --mode clean ${1+"$@"}; shift
-    ;;
-  compile|compil|compi|comp|com|co|c)
-    shift; set dummy --mode compile ${1+"$@"}; shift
-    ;;
-  execute|execut|execu|exec|exe|ex|e)
-    shift; set dummy --mode execute ${1+"$@"}; shift
-    ;;
-  finish|finis|fini|fin|fi|f)
-    shift; set dummy --mode finish ${1+"$@"}; shift
-    ;;
-  install|instal|insta|inst|ins|in|i)
-    shift; set dummy --mode install ${1+"$@"}; shift
-    ;;
-  link|lin|li|l)
-    shift; set dummy --mode link ${1+"$@"}; shift
-    ;;
-  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
-    shift; set dummy --mode uninstall ${1+"$@"}; shift
-    ;;
-  esac
-
-  # Parse non-mode specific arguments:
-  while test "$#" -gt 0; do
-    opt="$1"
-    shift
-
-    case $opt in
-      --config)                func_config                                     
;;
-
-      --debug)         preserve_args="$preserve_args $opt"
-                       func_echo "enabling shell trace mode"
-                       opt_debug='set -x'
-                       $opt_debug
-                       ;;
-
-      -dlopen)         test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       execute_dlfiles="$execute_dlfiles $1"
-                       shift
-                       ;;
-
-      --dry-run | -n)  opt_dry_run=:                                   ;;
-      --features)       func_features                                  ;;
-      --finish)                mode="finish"                                   
;;
-
-      --mode)          test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       case $1 in
-                         # Valid mode arguments:
-                         clean)        ;;
-                         compile)      ;;
-                         execute)      ;;
-                         finish)       ;;
-                         install)      ;;
-                         link)         ;;
-                         relink)       ;;
-                         uninstall)    ;;
-
-                         # Catch anything else as an error
-                         *) func_error "invalid argument for $opt"
-                            exit_cmd=exit
-                            break
-                            ;;
-                       esac
-
-                       mode="$1"
-                       shift
-                       ;;
-
-      --preserve-dup-deps)
-                       opt_duplicate_deps=:                            ;;
-
-      --quiet|--silent)        preserve_args="$preserve_args $opt"
-                       opt_silent=:
-                       opt_verbose=false
-                       ;;
-
-      --no-quiet|--no-silent)
-                       preserve_args="$preserve_args $opt"
-                       opt_silent=false
-                       ;;
-
-      --verbose| -v)   preserve_args="$preserve_args $opt"
-                       opt_silent=false
-                       opt_verbose=:
-                       ;;
-
-      --no-verbose)    preserve_args="$preserve_args $opt"
-                       opt_verbose=false
-                       ;;
-
-      --tag)           test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       preserve_args="$preserve_args $opt $1"
-                       func_enable_tag "$1"    # tagname is set here
-                       shift
-                       ;;
-
-      # Separate optargs to long options:
-      -dlopen=*|--mode=*|--tag=*)
-                       func_opt_split "$opt"
-                       set dummy "$func_opt_split_opt" "$func_opt_split_arg" 
${1+"$@"}
-                       shift
-                       ;;
-
-      -\?|-h)          func_usage                                      ;;
-      --help)          opt_help=:                                      ;;
-      --help-all)      opt_help=': help-all'                           ;;
-      --version)       func_version                                    ;;
-
-      -*)              func_fatal_help "unrecognized option \`$opt'"   ;;
-
-      *)               nonopt="$opt"
-                       break
-                       ;;
-    esac
-  done
-
-
-  case $host in
-    *cygwin* | *mingw* | *pw32* | *cegcc*)
-      # don't eliminate duplications in $postdeps and $predeps
-      opt_duplicate_compiler_generated_deps=:
-      ;;
-    *)
-      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
-      ;;
-  esac
-
-  # Having warned about all mis-specified options, bail out if
-  # anything was wrong.
-  $exit_cmd $EXIT_FAILURE
-}
-
 # func_check_version_match
 # Ensure that we are using m4 macros, and libtool script from the same
 # release of libtool.
@@ -421,37 +312,119 @@ _LT_EOF
 }
 
 
-## ----------- ##
-##    Main.    ##
-## ----------- ##
+# Shorthand for --mode=foo, only valid as the first argument
+case $1 in
+clean|clea|cle|cl)
+  shift; set dummy --mode clean ${1+"$@"}; shift
+  ;;
+compile|compil|compi|comp|com|co|c)
+  shift; set dummy --mode compile ${1+"$@"}; shift
+  ;;
+execute|execut|execu|exec|exe|ex|e)
+  shift; set dummy --mode execute ${1+"$@"}; shift
+  ;;
+finish|finis|fini|fin|fi|f)
+  shift; set dummy --mode finish ${1+"$@"}; shift
+  ;;
+install|instal|insta|inst|ins|in|i)
+  shift; set dummy --mode install ${1+"$@"}; shift
+  ;;
+link|lin|li|l)
+  shift; set dummy --mode link ${1+"$@"}; shift
+  ;;
+uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+  shift; set dummy --mode uninstall ${1+"$@"}; shift
+  ;;
+esac
+]])
 
-$opt_help || {
-  # Sanity checks first:
-  func_check_version_match
+dnl SHORT      LONG                           DEFAULT                INIT
+dnl ----------------------------------------------------------------------
+M4SH_GETOPTS(
+  [n],         [--dry-run|--dryrun],           [],                     [],
+  [],          [--config],                     [],                     [
+       func_config],
+  [;],         [--dlopen|-dlopen],             [],                     [],
+  [],          [--preserve-dup-deps],          [],                     [],
+  [],          [--features],                   [],                     [
+       func_features],
+  [],          [--finish],                     [],                     [
+       set dummy --mode finish ${1+"[$]@"}; shift],
+  [],          [--help],                       [],                     [],
+  [],          [--help-all],                   [],                     [
+       opt_help=': help-all'],
+  [!],         [--mode],                       [],                     [
+       case $optarg in
+         # Valid mode arguments:
+         clean|compile|execute|finish|install|link|relink|uninstall) ;;
+
+         # Catch anything else as an error
+         *) func_error "invalid argument for $opt"
+            exit_cmd=exit
+            break
+            ;;
+       esac],
+  [],          [--no-silent|--no-quiet],       [false],                [
+       preserve_args="$preserve_args $opt"],
+  [],          [--no-verbose],                 [false],                [
+       preserve_args="$preserve_args $opt"],
+  [],          [--silent|--quiet],             [],                     [
+       preserve_args="$preserve_args $opt"
+        opt_verbose=false],
+  [],          [--verbose],                    [],                     [
+       preserve_args="$preserve_args $opt"
+       opt_silent=false],
+  [!],         [--tag],                        [],                     [
+       preserve_args="$preserve_args $opt $optarg"
+       func_enable_tag "$optarg"],
+[
+  # save first non-option argument
+  nonopt="$opt"; shift
+
+  # preserve --debug
+  $opt_debug && preserve_args="$preserve_args --debug"
 
-  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
-    func_fatal_configuration "not configured to build any kind of library"
-  fi
+  case $host in
+    *cygwin* | *mingw* | *pw32* | *cegcc*)
+      # don't eliminate duplications in $postdeps and $predeps
+      opt_duplicate_compiler_generated_deps=:
+      ;;
+    *)
+      opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
+      ;;
+  esac
 
-  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
+  $opt_help || {
+    # Sanity checks first:
+    func_check_version_match
 
+    if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+      func_fatal_configuration "not configured to build any kind of library"
+    fi
 
-  # Darwin sucks
-  eval std_shrext=\"$shrext_cmds\"
+    test -z "$opt_mode" && func_fatal_error "error: you must specify a MODE."
 
+    # Darwin sucks
+    eval std_shrext=\"$shrext_cmds\"
 
-  # Only execute mode is allowed to have -dlopen flags.
-  if test -n "$execute_dlfiles" && test "$mode" != execute; then
-    func_error "unrecognized option \`-dlopen'"
-    $ECHO "$help" 1>&2
-    exit $EXIT_FAILURE
-  fi
+    # Only execute mode is allowed to have -dlopen flags.
+    if test -n "$opt_dlopen" && test "$opt_mode" != execute; then
+      func_error "unrecognized option \`-dlopen'"
+      $ECHO "$help" 1>&2
+      exit $EXIT_FAILURE
+    fi
+
+    # Change the help message to a mode-specific one.
+    generic_help="$help"
+    help="Try \`$progname --help --mode=$opt_mode' for more information."
+  }
+])
 
-  # Change the help message to a mode-specific one.
-  generic_help="$help"
-  help="Try \`$progname --help --mode=$mode' for more information."
-}
 
+M4SH_VERBATIM([[
+## ----------- ##
+##    Main.    ##
+## ----------- ##
 
 # func_lalib_p file
 # True iff FILE is a libtool `.la' library or `.lo' object file.
@@ -1014,13 +987,13 @@ compiler."
 }
 
 $opt_help || {
-  test "$mode" = compile && func_mode_compile ${1+"$@"}
+  test "$opt_mode" = compile && func_mode_compile ${1+"$@"}
 }
 
 func_mode_help ()
 {
     # We need to display help for each of the modes.
-    case $mode in
+    case $opt_mode in
       "")
         # Generic help is extracted from the usage comments
         # at the start of this file.
@@ -1196,7 +1169,7 @@ Otherwise, only FILE itself is deleted using RM."
         ;;
 
       *)
-        func_fatal_help "invalid operation mode \`$mode'"
+        func_fatal_help "invalid operation mode \`$opt_mode'"
         ;;
     esac
 
@@ -1211,13 +1184,13 @@ if $opt_help; then
   else
     {
       func_help noexit
-      for mode in compile link execute install finish uninstall clean; do
+      for opt_mode in compile link execute install finish uninstall clean; do
        func_mode_help
       done
     } | sed -n '1p; 2,$s/^Usage:/  or: /p'
     {
       func_help noexit
-      for mode in compile link execute install finish uninstall clean; do
+      for opt_mode in compile link execute install finish uninstall clean; do
        echo
        func_mode_help
       done
@@ -1246,7 +1219,7 @@ func_mode_execute ()
       func_fatal_help "you must specify a COMMAND"
 
     # Handle -dlopen flags immediately.
-    for file in $execute_dlfiles; do
+    for file in $opt_dlopen; do
       test -f "$file" \
        || func_fatal_help "\`$file' is not a file"
 
@@ -1364,7 +1337,7 @@ func_mode_execute ()
     fi
 }
 
-test "$mode" = execute && func_mode_execute ${1+"$@"}
+test "$opt_mode" = execute && func_mode_execute ${1+"$@"}
 
 
 # func_mode_finish arg...
@@ -1444,7 +1417,7 @@ func_mode_finish ()
     exit $EXIT_SUCCESS
 }
 
-test "$mode" = finish && func_mode_finish ${1+"$@"}
+test "$opt_mode" = finish && func_mode_finish ${1+"$@"}
 
 
 # func_mode_install arg...
@@ -1904,7 +1877,7 @@ func_mode_install ()
     fi
 }
 
-test "$mode" = install && func_mode_install ${1+"$@"}
+test "$opt_mode" = install && func_mode_install ${1+"$@"}
 
 
 # func_generate_dlsyms outputname originator pic_p
@@ -4683,7 +4656,7 @@ func_mode_link ()
     # Find all interdependent deplibs by searching for libraries
     # that are linked more than once (e.g. -la -lb -la)
     for deplib in $deplibs; do
-      if $opt_duplicate_deps ; then
+      if $opt_preserve_dup_deps ; then
        case "$libs " in
        *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
        esac
@@ -5080,7 +5053,7 @@ func_mode_link ()
          tmp_libs=
          for deplib in $dependency_libs; do
            deplibs="$deplib $deplibs"
-           if $opt_duplicate_deps ; then
+           if $opt_preserve_dup_deps ; then
              case "$tmp_libs " in
              *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
              esac
@@ -5222,7 +5195,7 @@ func_mode_link ()
              # or/and link against static libraries
              newdependency_libs="$deplib $newdependency_libs"
            fi
-           if $opt_duplicate_deps ; then
+           if $opt_preserve_dup_deps ; then
              case "$tmp_libs " in
              *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
              esac
@@ -5489,7 +5462,7 @@ func_mode_link ()
            fi
          fi
 
-         if test "$linkmode" = prog || test "$mode" = relink; then
+         if test "$linkmode" = prog || test "$opt_mode" = relink; then
            add_shlibpath=
            add_dir=
            add=
@@ -5612,7 +5585,7 @@ func_mode_link ()
          tmp_libs=
          for deplib in $dependency_libs; do
            newdependency_libs="$deplib $newdependency_libs"
-           if $opt_duplicate_deps ; then
+           if $opt_preserve_dup_deps ; then
              case "$tmp_libs " in
              *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
              esac
@@ -6129,7 +6102,7 @@ func_mode_link ()
       libobjs="$libobjs $symfileobj"
       test "X$libobjs" = "X " && libobjs=
 
-      if test "$mode" != relink; then
+      if test "$opt_mode" != relink; then
        # Remove our outputs, but don't remove object files since they
        # may have been created when compiling PIC objects.
        removelist=
@@ -6627,7 +6600,7 @@ EOF
          hardcode_libdirs=
          dep_rpath=
          rpath="$finalize_rpath"
-         test "$mode" != relink && rpath="$compile_rpath$rpath"
+         test "$opt_mode" != relink && rpath="$compile_rpath$rpath"
          for libdir in $rpath; do
            if test -n "$hardcode_libdir_flag_spec"; then
              if test -n "$hardcode_libdir_separator"; then
@@ -6676,7 +6649,7 @@ EOF
        fi
 
        shlibpath="$finalize_shlibpath"
-       test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+       test "$opt_mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
        if test -n "$shlibpath"; then
          eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export 
$shlibpath_var"
        fi
@@ -6828,7 +6801,7 @@ EOF
        fi
 
        # Make a backup of the uninstalled library when relinking
-       if test "$mode" = relink; then
+       if test "$opt_mode" = relink; then
          $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV 
$realname ${realname}U)' || exit $?
        fi
 
@@ -6995,7 +6968,7 @@ EOF
                lt_exit=$?
 
                # Restore the uninstalled library and exit
-               if test "$mode" = relink; then
+               if test "$opt_mode" = relink; then
                  ( cd "$output_objdir" && \
                    $RM "${realname}T" && \
                    $MV "${realname}U" "$realname" )
@@ -7088,7 +7061,7 @@ EOF
            lt_exit=$?
 
            # Restore the uninstalled library and exit
-           if test "$mode" = relink; then
+           if test "$opt_mode" = relink; then
              ( cd "$output_objdir" && \
                $RM "${realname}T" && \
                $MV "${realname}U" "$realname" )
@@ -7100,7 +7073,7 @@ EOF
        IFS="$save_ifs"
 
        # Restore the uninstalled library and exit
-       if test "$mode" = relink; then
+       if test "$opt_mode" = relink; then
          $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV 
$realname ${realname}T && $MV ${realname}U $realname)' || exit $?
 
          if test -n "$convenience"; then
@@ -7939,7 +7912,7 @@ relink_command=\"$relink_command\""
     exit $EXIT_SUCCESS
 }
 
-{ test "$mode" = link || test "$mode" = relink; } &&
+{ test "$opt_mode" = link || test "$opt_mode" = relink; } &&
     func_mode_link ${1+"$@"}
 
 
@@ -7980,10 +7953,10 @@ func_mode_uninstall ()
       fi
       func_basename "$file"
       name="$func_basename_result"
-      test "$mode" = uninstall && odir="$dir"
+      test "$opt_mode" = uninstall && odir="$dir"
 
       # Remember odir for removal later, being careful to avoid duplicates
-      if test "$mode" = clean; then
+      if test "$opt_mode" = clean; then
        case " $rmdirs " in
          *" $odir "*) ;;
          *) rmdirs="$rmdirs $odir" ;;
@@ -8016,7 +7989,7 @@ func_mode_uninstall ()
          done
          test -n "$old_library" && rmfiles="$rmfiles $odir/$old_library"
 
-         case "$mode" in
+         case "$opt_mode" in
          clean)
            case " $library_names " in
            *" $dlname "*) ;;
@@ -8062,7 +8035,7 @@ func_mode_uninstall ()
        ;;
 
       *)
-       if test "$mode" = clean ; then
+       if test "$opt_mode" = clean ; then
          noexename=$name
          case $file in
          *.exe)
@@ -8113,16 +8086,16 @@ func_mode_uninstall ()
     exit $exit_status
 }
 
-{ test "$mode" = uninstall || test "$mode" = clean; } &&
+{ test "$opt_mode" = uninstall || test "$opt_mode" = clean; } &&
     func_mode_uninstall ${1+"$@"}
 
-test -z "$mode" && {
+test -z "$opt_mode" && {
   help="$generic_help"
   func_fatal_help "you must specify a MODE"
 }
 
 test -z "$exec_cmd" && \
-  func_fatal_help "invalid operation mode \`$mode'"
+  func_fatal_help "invalid operation mode \`$opt_mode'"
 
 if test -n "$exec_cmd"; then
   eval exec "$exec_cmd"
diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4
index b93dd0c..0b8a00e 100644
--- a/libltdl/m4/libtool.m4
+++ b/libltdl/m4/libtool.m4
@@ -748,15 +748,12 @@ _LT_EOF
   # if finds mixed CR/LF and LF-only lines.  Since sed operates in
   # text mode, it properly converts lines to CR/LF.  This bash problem
   # is reportedly fixed, but why not run on old versions too?
-  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
+  sed '$q' "$ltmain" >> "$cfgfile" \
+     || (rm -f "$cfgfile"; exit 1)
 
   _LT_PROG_XSI_SHELLFNS
 
-  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> 
"$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
-
-  mv -f "$cfgfile" "$ofile" ||
+   mv -f "$cfgfile" "$ofile" ||
     (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
   chmod +x "$ofile"
 ],
@@ -7254,206 +7251,68 @@ _LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into 
spaces])dnl
 ])# _LT_CHECK_SHELL_FEATURES
 
 
+# _LT_PROG_XSI_REPLACE (FUNCNAME, REPLACEMENT-BODY)
+# -------------------------------------------------
+# In `$cfgfile', look for function FUNCNAME delimited by `^FUNCNAME ()$' and
+# '^} FUNCNAME ', and replace its body with REPLACEMENT-BODY.
+m4_defun([_LT_PROG_XSI_REPLACE],
+[dnl {
+sed -i .tmp -e '/^$1 ()$/,/^} # $1 /c\
+$1 ()\
+{\
+m4_bpatsubst([$2], [$], [\\])
+} # XSI $1 implementation' "$cfgfile" \
+  || (mv -f "$cfgfile.tmp" "$cfgfile"; exit 1)
+rm -f "$cfgfile.tmp"])
+
+
 # _LT_PROG_XSI_SHELLFNS
 # ---------------------
-# Bourne and XSI compatible variants of some useful shell functions.
+# Replace existing portable implementations of several shell functions with
+# equivalent XSI compatible implementations.
 m4_defun([_LT_PROG_XSI_SHELLFNS],
-[case $xsi_shell in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result="${1##*/}"
-}
-
-# func_dirname_and_basename file append nondir_replacement
-# perform func_basename and func_dirname in a single function
-# call:
-#   dirname:  Compute the dirname of FILE.  If nonempty,
-#             add APPEND to the result, otherwise set result
-#             to NONDIR_REPLACEMENT.
-#             value returned in "$func_dirname_result"
-#   basename: Compute filename of FILE.
-#             value retuned in "$func_basename_result"
-# Implementation must be kept synchronized with func_dirname
-# and func_basename. For efficiency, we do not delegate to
-# those functions but instead duplicate the functionality here.
-func_dirname_and_basename ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-  func_basename_result="${1##*/}"
-}
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-func_stripname ()
-{
-  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
-  # positional parameters, so assign one to ordinary parameter first.
-  func_stripname_result=${3}
-  func_stripname_result=${func_stripname_result#"${1}"}
-  func_stripname_result=${func_stripname_result%"${2}"}
-}
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=${1%%=*}
-  func_opt_split_arg=${1#*=}
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  case ${1} in
-    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
-    *)    func_lo2o_result=${1} ;;
-  esac
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=${1%.*}.lo
-}
-
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=$(( $[*] ))
-}
-
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=${#1}
-}
-
-_LT_EOF
-    ;;
-  *) # Bourne compatible functions.
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "${1}" | $SED "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result=`$ECHO "${1}" | $SED "$basename"`
-}
-
-dnl func_dirname_and_basename
-dnl A portable version of this function is already defined in general.m4sh
-dnl so there is no need for it here.
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-# func_strip_suffix prefix name
-func_stripname ()
-{
-  case ${2} in
-    .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; 
s%\\\\${2}\$%%"`;;
-    *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
-  esac
-}
-
-# sed scripts:
-my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q'
-my_sed_long_arg='1s/^-[[^=]]*=//'
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=`$ECHO "${1}" | $SED "$my_sed_long_opt"`
-  func_opt_split_arg=`$ECHO "${1}" | $SED "$my_sed_long_arg"`
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  func_lo2o_result=`$ECHO "${1}" | $SED "$lo2o"`
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=`$ECHO "${1}" | $SED 's/\.[[^.]]*$/.lo/'`
-}
+[if test x"$xsi_shell" = xyes; then
+  _LT_PROG_XSI_REPLACE([func_dirname], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac])
+
+  _LT_PROG_XSI_REPLACE([func_basename], [dnl
+    func_basename_result="${1##*/}"])
+
+  _LT_PROG_XSI_REPLACE([func_dirname_and_basename], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac
+    func_basename_result="${1##*/}"])
 
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=`expr "address@hidden"`
-}
+  _LT_PROG_XSI_REPLACE([func_stripname], [dnl
+    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+    # positional parameters, so assign one to ordinary parameter first.
+    func_stripname_result=${3}
+    func_stripname_result=${func_stripname_result#"${1}"}
+    func_stripname_result=${func_stripname_result%"${2}"}])
 
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len`
-}
+  _LT_PROG_XSI_REPLACE([func_split_long_opt], [dnl
+    func_split_long_opt_name=${1%%=*}
+    func_split_long_opt_arg=${1#*=}])
 
-_LT_EOF
-esac
+  _LT_PROG_XSI_REPLACE([func_lo2o], [dnl
+    case ${1} in
+      *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+      *)    func_lo2o_result=${1} ;;
+    esac])
 
-case $lt_shell_append in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
+  _LT_PROG_XSI_REPLACE([func_xform], [    func_xform_result=${1%.*}.lo])
 
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$[1]+=\$[2]"
-}
-_LT_EOF
-    ;;
-  *)
-    cat << \_LT_EOF >> "$cfgfile"
+  _LT_PROG_XSI_REPLACE([func_arith], [    func_arith_result=$(( $[*] ))])
 
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$[1]=\$$[1]\$[2]"
-}
+  _LT_PROG_XSI_REPLACE([func_len], [    func_len_result=${#1}])
+fi
 
-_LT_EOF
-    ;;
-  esac
+if test x"$lt_shell_append" = xyes; then
+  _LT_PROG_XSI_REPLACE([func_append], [    eval "${1}+=\\${2}"])
+fi
 ])
-- 
1.7.1




reply via email to

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