libtool-patches
[Top][All Lists]
Advanced

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

Re: make libtool faster v3


From: Ralf Wildenhues
Subject: Re: make libtool faster v3
Date: Tue, 7 Dec 2004 18:06:29 +0100
User-agent: Mutt/1.4.1i

> * Peter O'Gorman wrote on Wed, Dec 01, 2004 at 10:19:38AM CET:
> > Ralf Wildenhues wrote:
> > >We provide two implementations of each function, a Bourne shell com-
> > >pliant one and an XSI compliant one (again, the latter without forks).
> > >Since most systems either have a suitable shell already or are not used
> > >primarily for application development anyway, this should benefit the
> > >bulk of libtool users while /not/ compromising portability.
> > 
> > Can the shells capabilities not be checked in configure (in libtool.m4) and 
> > the appropriate basename and dirname functions put in the generated libtool 
> > script from config.status? Even chosing which version of dirname/basename 
> > to call during configure is better than doing it every time libtool is 
> > called.

Yep.

No my m4-fu is rather far from great, but this is what I've come up
with:  Test for the constructs we want in configure, let config.status
copy a set of functions into `libtool' based on this test.

The other scripts (libtoolize, maintenance stuff like mailnotify)
don't make use of the XSI functions.  I don't think this is necessary
as they are not used that often (or at all, by users of Libtool), and
it would unnecessarily complicate their build.

Another optimization I found generally useful: let func_quote_for_eval
only fork when input necessitates this.  Building libltdl is noticeably
faster now.

Side note for patch below: all shell positional parameters are written
like ${1} in libtool.m4 as to prevent the need to m4-escape them.

OK to apply to HEAD (as separate patches)?  Please test, thankyou.

Regards,
Ralf

        * config/general.m4sh (func_quote_for_eval): Only fork if the
        substitution matches.

        * config/ltmain.m4sh: Set marker for insertion of shell functions.

        * m4/libtool.m4 (_LT_CHECK_XSI_SHELL, _LT_PROG_XSI_SHELLFNS): New macros
        to detect at `configure' time whether the shell supports some XSI
        extensions and to copy appropriate versions of new shell functions into
        `libtool' through `config.status'.  Copied functions are Bourne and XSI
        variants of func_basename, func_dirname (a variant of `dirname' suitable
        for libtool).  (_LT_SETUP) Require _LT_CHECK_XSI_SHELL.
        (_LT_CONFIG)  Use _LT_PROG_XSI_SHELLFNS to insert into `libtool' at 
marker.

        * config/ltmain.m4sh (all over the map): Make use of func_basename and
        func_dirname in most occasions.


Index: config/general.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/config/general.m4sh,v
retrieving revision 1.11
diff -u -r1.11 general.m4sh
--- config/general.m4sh 30 Nov 2004 20:46:23 -0000      1.11
+++ config/general.m4sh 7 Dec 2004 18:00:08 -0000
@@ -271,7 +271,12 @@
 # which are still active within double quotes backslashified.
 func_quote_for_eval ()
 {
-    func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e 
"$sed_quote_subst"`
+    case $1 in
+      *[[\`\"\\\$]]*)
+       func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e 
"$sed_quote_subst"` ;;
+      *)
+        func_quote_for_eval_unquoted_result="$1" ;;
+    esac
 
     case $func_quote_for_eval_unquoted_result in
       # Double-quote args containing shell metacharacters to delay
Index: m4/libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/m4/libtool.m4,v
retrieving revision 1.143
diff -u -r1.143 libtool.m4
--- m4/libtool.m4       29 Nov 2004 21:12:41 -0000      1.143
+++ m4/libtool.m4       7 Dec 2004 18:02:09 -0000
@@ -102,6 +102,7 @@
 AC_REQUIRE([AC_EXEEXT])dnl
 _LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
 dnl
+m4_require([_LT_CHECK_XSI_SHELL])dnl
 m4_require([_LT_CMD_RELOAD])dnl
 m4_require([_LT_CHECK_MAGIC_METHOD])dnl
 m4_require([_LT_CMD_OLD_ARCHIVE])dnl
@@ -528,7 +529,13 @@
   # 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 '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1)
+  sed '/^# Generated shell functions inserted here/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" ||
     (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
@@ -5978,3 +5985,70 @@
 AC_MSG_RESULT([$SED])
 ])#AC_PROG_SED
 ])#m4_ifndef
+
+# _LT_CHECK_XSI_SHELL
+# -------------------
+# define func_basename as either Bourne or XSI compatible
+m4_defun([_LT_CHECK_XSI_SHELL],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+])
+fi
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+])# _LT_CHECK_XSI_SHELL
+
+# _LT_PROG_XSI_SHELLFNS
+# ---------------------
+# Bourne and XSI compatible variants of some useful shell functions.
+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##*/}"
+}
+_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 "X${1}" | $Xsed -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 file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+_LT_EOF
+esac
+])
Index: config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/config/ltmain.m4sh,v
retrieving revision 1.30
diff -u -r1.30 ltmain.m4sh
--- config/ltmain.m4sh  2 Dec 2004 16:40:55 -0000       1.30
+++ config/ltmain.m4sh  7 Dec 2004 18:02:08 -0000
@@ -616,6 +616,9 @@
 }
 
 
+# Generated shell functions inserted here.
+
+
 # func_win32_libid arg
 # return the library type of file 'arg'
 #
@@ -811,7 +814,8 @@
 
        for dlprefile in $dlprefiles; do
          func_echo "extracting global C symbols from \`$dlprefile'"
-         name=`$ECHO "X$dlprefile" | $Xsed -e 's%^.*/%%'`
+         func_basename "$dlprefile"
+         name="$func_basename_result"
          $opt_dry_run || {
            eval '$ECHO ": $name " >> "$nlist"'
            eval "$NM $dlprefile | $global_symbol_pipe >> '$nlist'"
@@ -971,7 +975,8 @@
        [[\\/]]* | [[A-Za-z]]:[[\\/]]*) my_xabs="$my_xlib" ;;
        *) my_xabs=`pwd`"/$my_xlib" ;;
       esac
-      my_xlib=`$ECHO "X$my_xlib" | $Xsed -e 's%^.*/%%'`
+      func_basename "$my_xlib"
+      my_xlib="$func_basename_result"
       my_xdir="$my_gentop/$my_xlib"
 
       func_mkdir_p "$my_xdir"
@@ -1149,7 +1154,10 @@
       ;;
     *)
       # Get the name of the library object.
-      test -z "$libobj" && libobj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%'`
+      test -z "$libobj" && {
+       func_basename "$srcfile"
+       libobj="$func_basename_result"
+      }
       ;;
     esac
 
@@ -1210,13 +1218,10 @@
       esac
     done
 
-    objname=`$ECHO "X$obj" | $Xsed -e 's%^.*/%%'`
-    xdir=`$ECHO "X$obj" | $Xsed -e 's%/[[^/]]*$%%'`
-    if test "X$xdir" = "X$obj"; then
-      xdir=
-    else
-      xdir=$xdir/
-    fi
+    func_basename "$obj"
+    objname="$func_basename_result"
+    func_dirname "$obj" "/" ""
+    xdir="$func_dirname_result"
     lobj=${xdir}$objdir/$objname
 
     test -z "$base_compile" && \
@@ -1481,8 +1486,8 @@
          continue
        fi
 
-       dir=`$ECHO "X$file" | $Xsed -e 's%/[[^/]]*$%%'`
-       test "X$dir" = "X$file" && dir=.
+       func_dirname "$file" "" "."
+       dir="$func_dirname_result"
 
        if test -f "$dir/$objdir/$dlname"; then
          dir="$dir/$objdir"
@@ -1493,8 +1498,8 @@
 
       *.lo)
        # Just add the directory containing the .lo file.
-       dir=`$ECHO "X$file" | $Xsed -e 's%/[[^/]]*$%%'`
-       test "X$dir" = "X$file" && dir=.
+       func_dirname "$file" "" "."
+       dir="$func_dirname_result"
        ;;
 
       *)
@@ -1746,9 +1751,10 @@
       destdir="$dest"
       destname=
     else
-      destdir=`$ECHO "X$dest" | $Xsed -e 's%/[[^/]]*$%%'`
-      test "X$destdir" = "X$dest" && destdir=.
-      destname=`$ECHO "X$dest" | $Xsed -e 's%^.*/%%'`
+      func_dirname "$dest" "" "."
+      destdir="$func_dirname_result"
+      func_basename "$dest"
+      destname="$func_basename_result"
 
       # Not a directory, so check to see that there is only one file specified.
       set dummy $files
@@ -1813,8 +1819,8 @@
          esac
        fi
 
-       dir=`$ECHO "X$file" | $Xsed -e 's%/[[^/]]*$%%'`/
-       test "X$dir" = "X$file/" && dir=
+       func_dirname "$file" "/" ""
+       dir="$func_dirname_result"
        dir="$dir$objdir"
 
        if test -n "$relink_command"; then
@@ -1891,7 +1897,8 @@
        fi
 
        # Install the pseudo-library for information purposes.
-       name=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'`
+       func_basename "$file"
+       name="$func_basename_result"
        instname="$dir/$name"i
        func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
 
@@ -1906,7 +1913,8 @@
        if test -n "$destname"; then
          destfile="$destdir/$destname"
        else
-         destfile=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'`
+         func_basename "$file"
+         destfile="$func_basename_result"
          destfile="$destdir/$destfile"
        fi
 
@@ -1942,7 +1950,8 @@
        if test -n "$destname"; then
          destfile="$destdir/$destname"
        else
-         destfile=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'`
+         func_basename "$file"
+         destfile="$func_basename_result"
          destfile="$destdir/$destfile"
        fi
 
@@ -2026,7 +2035,8 @@
            $opt_dry_run || {
              if test "$finalize" = yes; then
                tmpdir=`func_mktempdir`
-               file=`$ECHO "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'`
+               func_basename "$file$stripped_ext"
+               file="$func_basename_result"
                outputname="$tmpdir/$file"
                # Replace the output file specification.
                relink_command=`$ECHO "X$relink_command" | $Xsed -e 
'address@hidden@%'"$outputname"'%g'`
@@ -2078,7 +2088,8 @@
     done
 
     for file in $staticlibs; do
-      name=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'`
+      func_basename "$file"
+      name="$func_basename_result"
 
       # Set up the ranlib parameters.
       oldlib="$destdir/$name"
@@ -2340,12 +2351,8 @@
                fi
 
                # Extract subdirectory from the argument.
-               xdir=`$ECHO "X$arg" | $Xsed -e 's%/[[^/]]*$%%'`
-               if test "X$xdir" = "X$arg"; then
-                 xdir=
-               else
-                 xdir="$xdir/"
-               fi
+               func_dirname "$arg" "/" ""
+               xdir="$func_dirname_result"
 
                if test "$pic_object" != none; then
                  # Prepend the subdirectory the object is found in.
@@ -2394,12 +2401,8 @@
                # Only an error if not doing a dry-run.
                if $opt_dry_run; then
                  # Extract subdirectory from the argument.
-                 xdir=`$ECHO "X$arg" | $Xsed -e 's%/[[^/]]*$%%'`
-                 if test "X$xdir" = "X$arg"; then
-                   xdir=
-                 else
-                   xdir="$xdir/"
-                 fi
+                 func_dirname "$arg" "/" ""
+                 xdir="$func_dirname_result"
 
                  pic_object=`$ECHO "X${xdir}${objdir}/${arg}" | $Xsed -e 
"$lo2o"`
                  non_pic_object=`$ECHO "X${xdir}${arg}" | $Xsed -e "$lo2o"`
@@ -2833,12 +2836,8 @@
          fi
 
          # Extract subdirectory from the argument.
-         xdir=`$ECHO "X$arg" | $Xsed -e 's%/[[^/]]*$%%'`
-         if test "X$xdir" = "X$arg"; then
-           xdir=
-         else
-           xdir="$xdir/"
-         fi
+         func_dirname "$arg" "/" ""
+         xdir="$func_dirname_result"
 
          if test "$pic_object" != none; then
            # Prepend the subdirectory the object is found in.
@@ -2887,12 +2886,8 @@
          # Only an error if not doing a dry-run.
          if $opt_dry_run; then
            # Extract subdirectory from the argument.
-           xdir=`$ECHO "X$arg" | $Xsed -e 's%/[[^/]]*$%%'`
-           if test "X$xdir" = "X$arg"; then
-             xdir=
-           else
-             xdir="$xdir/"
-           fi
+           func_dirname "$arg" "/" ""
+           xdir="$func_dirname_result"
 
            pic_object=`$ECHO "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
            non_pic_object=`$ECHO "X${xdir}${arg}" | $Xsed -e "$lo2o"`
@@ -2955,7 +2950,8 @@
 
     oldlibs=
     # calculate the name of the file, without its directory
-    outputname=`$ECHO "X$output" | $Xsed -e 's%^.*/%%'`
+    func_basename "$output"
+    outputname="$func_basename_result"
     libobjs_save="$libobjs"
 
     if test -n "$shlibpath_var"; then
@@ -2967,12 +2963,8 @@
     eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
     eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
 
-    output_objdir=`$ECHO "X$output" | $Xsed -e 's%/[[^/]]*$%%'`
-    if test "X$output_objdir" = "X$output"; then
-      output_objdir="$objdir"
-    else
-      output_objdir="$output_objdir/$objdir"
-    fi
+    func_dirname "$output" "/" ""
+    output_objdir="$func_dirname_result$objdir"
     # Create the object directory.
     func_mkdir_p "$output_objdir"
 
@@ -3170,8 +3162,8 @@
                  done
                  if test "X$ll" = "X$old_library" ; then # only static version 
available
                    found=no
-                   ladir=`$ECHO "X$lib" | $Xsed -e 's%/[[^/]]*$%%'`
-                   test "X$ladir" = "X$lib" && ladir="."
+                   func_dirname "$lib" "" "."
+                   ladir="$func_dirname_result"
                    lib=$ladir/$old_library
                    if test "$linkmode,$pass" = "prog,link"; then
                      compile_deplibs="$deplib $compile_deplibs"
@@ -3330,8 +3322,8 @@
        func_lalib_unsafe_p "$lib" \
          || func_fatal_error "\`$lib' is not a valid libtool archive"
 
-       ladir=`$ECHO "X$lib" | $Xsed -e 's%/[[^/]]*$%%'`
-       test "X$ladir" = "X$lib" && ladir="."
+       func_dirname "$lib" "" "."
+       ladir="$func_dirname_result"
 
        dlname=
        dlopen=
@@ -3435,7 +3427,8 @@
          fi
          ;;
        esac
-       laname=`$ECHO "X$lib" | $Xsed -e 's%^.*/%%'`
+       func_basename "$lib"
+       laname="$func_basename_result"
 
        # Find the relevant object directory and library name.
        if test "X$installed" = Xyes; then
@@ -3660,7 +3653,8 @@
 
            # Make a new name for the extract_expsyms_cmds to use
            soroot="$soname"
-           soname=`$ECHO "X$soroot" | $Xsed -e 's/^.*\///'`
+           func_basename "$soroot"
+           soname="$func_basename_result"
            newlib=libimp-`$ECHO "X$soname" | $Xsed -e 's/^lib//;s/\.dll$//'`.a
 
            # If the library has no export list, then create one now
@@ -3925,8 +3919,8 @@
              case $deplib in
              -L*) path="$deplib" ;;
              *.la)
-               dir=`$ECHO "X$deplib" | $Xsed -e 's%/[[^/]]*$%%'`
-               test "X$dir" = "X$deplib" && dir="."
+               func_dirname "$deplib" "" "."
+               dir="$func_dirname_result"
                # We need an absolute path.
                case $dir in
                [[\\/]]* | [[A-Za-z]]:[[\\/]]*) absdir="$dir" ;;
@@ -6223,7 +6217,8 @@
          # names appear in distinct ar calls; check, warn and compensate.
            if (for obj in $save_oldobjs
            do
-             $ECHO "X$obj" | $Xsed -e 's%^.*/%%'
+             func_basename "$obj"
+             $ECHO "$func_basename_result"
            done | sort | sort -uc >/dev/null 2>&1); then
            :
          else
@@ -6314,7 +6309,8 @@
            for deplib in $dependency_libs; do
              case $deplib in
              *.la)
-               name=`$ECHO "X$deplib" | $Xsed -e 's%^.*/%%'`
+               func_basename "$deplib"
+               name="$func_basename_result"
                eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
                test -z "$libdir" && \
                  func_fatal_error "\`$deplib' is not a valid libtool archive"
@@ -6329,7 +6325,8 @@
            for lib in $dlfiles; do
              case $lib in
              *.la)
-               name=`$ECHO "X$lib" | $Xsed -e 's%^.*/%%'`
+               func_basename "$lib"
+               name="$func_basename_result"
                eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
                test -z "$libdir" && \
                  func_fatal_error "\`$lib' is not a valid libtool archive"
@@ -6347,7 +6344,8 @@
                # eventual linking with the app. that links it) if we
                # didn't already link the preopened objects directly into
                # the library:
-               name=`$ECHO "X$lib" | $Xsed -e 's%^.*/%%'`
+               func_basename "$lib"
+               name="$func_basename_result"
                eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
                test -z "$libdir" && \
                  func_fatal_error "\`$lib' is not a valid libtool archive"
@@ -6468,14 +6466,15 @@
 
     origobjdir="$objdir"
     for file in $files; do
-      dir=`$ECHO "X$file" | $Xsed -e 's%/[[^/]]*$%%'`
-      if test "X$dir" = "X$file"; then
-       dir=.
+      func_dirname "$file" "" "."
+      dir="$func_dirname_result"
+      if test "X$dir" = X.; then
        objdir="$origobjdir"
       else
        objdir="$dir/$origobjdir"
       fi
-      name=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'`
+      func_basename "$file"
+      name="$func_basename_result"
       test "$mode" = uninstall && objdir="$dir"
 
       # Remember objdir for removal later, being careful to avoid duplicates




reply via email to

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