libtool-patches
[Top][All Lists]
Advanced

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

Re: Followup patch: compute dirname and basename at once, when both are


From: Charles Wilson
Subject: Re: Followup patch: compute dirname and basename at once, when both are needed
Date: Thu, 12 Jul 2007 03:48:30 -0400
User-agent: Thunderbird 1.5.0.12 (Windows/20070509)

Ralf Wildenhues wrote:
The libtool.m4 part of this patch also needs an instance of the function
in case the shell does not support XSI extensions.

Oh, I missed that. Didn't realize we had two implementations of everything.

Inside that
function, you could make use of the other ones (func_dirname and
func_basename) if it helps.

No, if I did that then using the combo function would actually be *worse*, from an execution-time standpoint, than calling the separate functions explicitly. Just like the XSI versions, I think cut-n-paste with an explicit comment about "keep this in sync" is the way to go, here.

Testing on Solaris with /bin/sh should
expose this.

Err...I don't have access to a solaris box at present. Here's the updated patch <untested>. I'll kick off a test (cygwin) and report back later.

2007-07-12  Charles Wilson  <...>

        * libltdl/m4/libtool.m4 (func_dirname_and_basename) <XSI>:
        New function
        (func_dirname_and_basename) <!XSI>: New function.
        * libltdl/config/ltmain.m4sh (func_ltwrapper_scriptname):
        Call it.  Also, take advantage of missed optimization using
        func_dirname's additional arguments.
        (func_mode_compile): Call it.
        (func_mode_install): Call it.
        (func_mode_link): Call it.

--
Chuck
Index: libltdl/config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/config/ltmain.m4sh,v
retrieving revision 1.83
diff -u -r1.83 ltmain.m4sh
--- libltdl/config/ltmain.m4sh  7 Jul 2007 05:09:10 -0000       1.83
+++ libltdl/config/ltmain.m4sh  12 Jul 2007 03:04:20 -0000
@@ -692,14 +692,9 @@
 {
     func_ltwrapper_scriptname_result=""
     if func_ltwrapper_executable_p "$1"; then
-       func_dirname "$1"
-       func_basename "$1"
+       func_dirname_and_basename "$1" "" "."
        func_stripname '' '.exe' "$func_basename_result"
-       if test -z "$func_dirname_result"; then
-           
func_ltwrapper_scriptname_result="./$objdir/${func_stripname_result}_ltshwrapper"
-       else
-           
func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
-       fi
+       
func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
     fi
 }
 
@@ -1422,9 +1417,8 @@
     test "X$libobj" != "X$func_quote_for_eval_result" \
       && $ECHO "X$libobj" | $GREP '[@:>@~#^*{};<>?"'"'"'       &()|`$@<:@]' \
       && func_warning "libobj name \`$libobj' may not contain shell special 
characters."
-    func_basename "$obj"
+    func_dirname_and_basename "$obj" "/" ""
     objname="$func_basename_result"
-    func_dirname "$obj" "/" ""
     xdir="$func_dirname_result"
     lobj=${xdir}$objdir/$objname
 
@@ -1921,9 +1915,8 @@
       destdir="$dest"
       destname=
     else
-      func_dirname "$dest" "" "."
+      func_dirname_and_basename "$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.
@@ -6785,13 +6778,9 @@
        esac
        case $host in
          *cygwin* | *mingw* )
-           func_basename "$output"
+           func_dirname_and_basename "$output" "" "."
            output_name=$func_basename_result
-           func_dirname "$output"
            output_path=$func_dirname_result
-           if test -z "$output_path"; then
-             output_path=.
-           fi
            cwrappersource="$output_path/$objdir/lt-$output_name.c"
            cwrapper="$output_path/$output_name.exe"
            $RM $cwrappersource $cwrapper
Index: libltdl/m4/libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/m4/libtool.m4,v
retrieving revision 1.111
diff -u -r1.111 libtool.m4
--- libltdl/m4/libtool.m4       3 Jul 2007 05:09:40 -0000       1.111
+++ libltdl/m4/libtool.m4       12 Jul 2007 07:46:56 -0000
@@ -7056,6 +7056,27 @@
   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
@@ -7109,6 +7130,30 @@
   func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
 }
 
+# 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 ()
+{
+  # 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_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
 # func_stripname prefix suffix name
 # strip PREFIX and SUFFIX off of NAME.
 # PREFIX and SUFFIX must not contain globbing or regex special

reply via email to

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