libltdl/config/ltmain.m4sh: (func_cygpath): New function.
(func_wine_to_win32_path): New function. Refactored from...
(func_msys_to_win32): New function supports converting both
paths and pathlists. Refactored from...
(func_to_host_path): ...here.
[msys->mingw]: Use refactored func_msys_to_win32.
[*nix->mingw]: Use refactored func_wine_to_win32_path.
[cygwin->mingw]: Simplify.
[cygwin->cygwin]: New. Explicit no-op.
[msys->cygwin]: New. Use func_msys_to_win32 + func_cygpath.
[*nix->cygwin]: New. Use func_wine_to_win32_path + func_cygpath.
(func_wine_to_win32_pathlist): New function. Refactored from...
(func_to_host_pathlist): ...here.
[msys->mingw]: Use refactored func_msys_to_win32.
[*nix->mingw]: Use refactored func_wine_to_win32_pathlist.
[cygwin->mingw]: Simplify.
[cygwin->cygwin]: New. Explicit no-op.
[msys->cygwin]: New. Use func_msys_to_win32 + func_cygpath.
[*nix->cygwin]: New. Use func_wine_to_win32_pathlist + func_cygpath.
---
Just as unix -> mingw cross builds need special support when
creating the cwrapper source code in order for the cwrapper
to work properly under the wine environment, so too do unix ->
cygwin cross builds.  However, this led to a lot of duplicated
code, so I refactored a bit.

Now, native cygwin and native mingw both still work ok. What I
can't test is whether I've broken the existing unix -> mingw 
support.  Nor can I actually test the new unix -> cygwin 
support.  I *think* it all should work, but I'd like for 
somebody to verify that for me. Please?

NOTE: At present, to use the unix -> cygwin support, you *MUST*
have the LT_CYGPATH environment variable exported, containing
the *unix* (that is, $build) path to the cygpath.exe you want
to use.  In the final patch, I'll prepare some documentation
to that effect, but right now the implementation is probably
in flux pending feedback.

Here's the comment block in ltmain.m4sh describing this:
# [*] The full *nix path to the cygpath program must be
# specified in the LT_CYGPATH environment variable. This
# is because (a) cygpath shouldn't be in $PATH, because it
# usually lives in cygwin's bin/ directory -- along with
# *cygwin* versions of sed, id, cp. If the unix build
# environment had those programs in its $PATH, many bad
# things could happen. (b) especially in cygwin-1.7, multiple
# installations (with separate "mount tables" in
# <CYGROOT-N>/etc/fstab) can coexist on the same Win32
# instance. The cygpath.exe for cygwin installation #N in
# <CYGROOT-N>/bin automatically deduces the appropriate
# ../etc/fstab file. Therefore, it matters which cygpath.exe
# is used. LT_CYGPATH may be replaced or supplemented by an
# LT_INIT-activated configure option in the future.

In re: LT_INIT, I was thinking maybe LT_INIT([win32-dll cygcross])
where the developers of client packages could enable a configure
option, so that end users could do:
   configure \
     --host=cygwin \
     --cygpath=/opt/cygwin-1.7-unstable/bin/cygpath.exe \
     <other args>
Then, func_cygpath would default to using the specified
cygpath, unless LT_CYGPATH overrides. But I haven't worked
out all the details...eventually I need to set up my own
cygwin-under-wine installation. <g> Anyway, if cygcross did
not appear as an LT_INIT option, then --cygpath wouldn't 
be available (but setting LT_CYGPATH would always work).

Comments? Reviews? *Test Results*?

Oh: one other thing. I know using 'win32' is frowned 
upon by the FSF/RMS. But I somehow need to distinguish
between "cygwin" paths, "msys" paths, and actual win32
paths. I have several functions now named 
func_*_to_win32*().  Got any suggestions? "mingw" is
actually ambiguous, as it could also refer to unix-style
msys paths. "mingw_native" might be okay, but it's rather
wordy.

==
Chuck

 libltdl/config/ltmain.m4sh |  259 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 209 insertions(+), 50 deletions(-)

diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index 20ca07b..7677846 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -2557,6 +2557,73 @@ func_emit_wrapper ()
        func_emit_wrapper_part2 ${1-no}
 }
 
+# func_wine_to_win32_path arg
+# helper function used by func_to_host_path
+# when $build is neither mingw/msys nor cygwin, and
+# arg must be converted to win32 ($host is mingw or
+# cygwin).
+#
+# result is available in $func_wine_to_win32_path_result
+# result is empty on error (or when arg is empty)
+func_wine_to_win32_path ()
+{
+  lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+  func_wine_to_win32_path_result="$1"
+  if test -n "$1"; then
+    # Unfortunately, winepath does not exit with a non-zero
+    # error code, so we are forced to check the contents of
+    # stdout. On the other hand, if the command is not
+    # found, the shell will set an exit code of 127 and print
+    # *an error message* to stdout. So we must check for both
+    # error code of zero AND non-empty stdout, which explains
+    # the odd construction:
+    func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
+    if test "$?" -eq 0 && test -n "${func_wine_to_win32_path_tmp}"; then
+      func_to_host_path_result=`$ECHO "$func_wine_to_win32_path_tmp" |
+        $SED -e "$lt_sed_naive_backslashify"`
+    else
+      func_wine_to_win32_path_result=
+    fi
+  fi
+}
+# end: func_wine_to_win32_path
+
+# func_cygpath ARGS...
+# a wrapper around calling the cygpath program via
+# LT_CYGPATH. See func_to_host_path comments for
+# explanation of that variable. Result is available
+# in func_cygpath_result. May be empty on error.
+#
+# ARGS are the typical arguments and options for
+# the cygpath program. Usually, the last argument
+# is the path or pathlist to be converted.
+func_cygpath ()
+{
+  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
+    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
+    if test $? -ne 0; then
+      # on failure, ensure result is empty
+      func_cygpath_result=
+    fi
+  else
+    func_cygpath_result=
+    func_error "LT_CYGPATH is empty or specifies non-existant file: 
\`$LT_CYGPATH'"
+  fi
+}
+#end: func_cygpath
+
+# func_msys_to_win32 ARG
+# Converts ARG from msys (unix-ish) format to
+# win32 format. Can accomodate both paths and pathlists.
+# Result is available in func_msys_to_win32_result.
+func_msys_to_win32()
+{
+  lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+  # awkward: cmd appends spaces to result
+  func_msys_to_win32_result=`( cmd //c echo "$1" ) 2>/dev/null |
+    $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
+}
+#end: func_msys_to_win32
 
 # func_to_host_path arg
 #
@@ -2568,6 +2635,8 @@ func_emit_wrapper ()
 #    mingw (msys)    mingw  [e.g. native]
 #    cygwin          mingw
 #    *nix + wine     mingw
+#    cygwin          cygwin (no-op)
+#    *nix + wine     cygwin [*]
 # where wine is equipped with the `winepath' executable.
 # In the native mingw case, the (msys) shell automatically
 # converts paths for any non-msys applications it launches,
@@ -2576,6 +2645,21 @@ func_emit_wrapper ()
 # $build cygwin.  Calling this function does no harm for other
 # $host/$build combinations not listed above.
 #
+# [*] The full *nix path to the cygpath program must be
+# specified in the LT_CYGPATH environment variable. This
+# is because (a) cygpath shouldn't be in $PATH, because it
+# usually lives in cygwin's bin/ directory -- along with
+# *cygwin* versions of sed, id, cp. If the unix host
+# environment had those programs in its $PATH, many bad
+# things could happen. (b) especially in cygwin-1.7, multiple
+# installations (with separate "mount tables" in
+# <CYGROOT-N>/etc/fstab) can coexist on the same Win32
+# instance. The cygpath.exe for cygwin installation #N in
+# <CYGROOT-N>/bin automatically deduces the appropriate
+# ../etc/fstab file. Therefore, it matters which cygpath.exe
+# is used. LT_CYGPATH may be replaced or supplemented by an
+# LT_INIT-activated configure option in the future.
+#
 # ARG is the path (on $build) that should be converted to
 # the proper representation for $host. The result is stored
 # in $func_to_host_path_result.
@@ -2585,35 +2669,19 @@ func_to_host_path ()
   if test -n "$1"; then
     case $host in
       *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
         case $build in
           *mingw* ) # actually, msys
-            # awkward: cmd appends spaces to result
-            func_to_host_path_result=`( cmd //c echo "$1" ) 2>/dev/null |
-              $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
+            func_msys_to_win32 "$1"
+            func_to_host_path_result="$func_msys_to_win32_result"
             ;;
           *cygwin* )
-            func_to_host_path_result=`cygpath -w "$1" |
-             $SED -e "$lt_sed_naive_backslashify"`
+            func_to_host_path_result=`cygpath -m "$1"`
             ;;
           * )
-            # Unfortunately, winepath does not exit with a non-zero
-            # error code, so we are forced to check the contents of
-            # stdout. On the other hand, if the command is not
-            # found, the shell will set an exit code of 127 and print
-            # *an error message* to stdout. So we must check for both
-            # error code of zero AND non-empty stdout, which explains
-            # the odd construction:
-            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
-            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
-              func_to_host_path_result=`$ECHO "$func_to_host_path_tmp1" |
-                $SED -e "$lt_sed_naive_backslashify"`
-            else
-              # Allow warning below.
-              func_to_host_path_result=
-            fi
+            func_wine_to_win32_path "$1"
+            func_to_host_path_result="$func_wine_to_win32_path_result"
             ;;
-        esac
+        esac # $build
         if test -z "$func_to_host_path_result" ; then
           func_error "Could not determine host path corresponding to"
           func_error "  \`$1'"
@@ -2621,12 +2689,77 @@ func_to_host_path ()
           # Fallback:
           func_to_host_path_result="$1"
         fi
-        ;;
+        ;; # $host is mingw
+      *cygwin* )
+        case $build in
+          *cygwin* ) func_to_host_path_result="$1" ;; # no-op
+          *mingw*  ) # unsupported
+            # This implies running a cross build from msys to
+            # cygwin -- but msys has notorious problems executing
+            # cygwin apps, because of conflicts between cygwin1.dll
+            # and msys-1.0.dll. However, we'll try it. First, convert
+            # from msys to win32, then use cygpath to convert from
+            # win32 to cygwin.
+            func_msys_to_win32 "$1"
+            func_cygpath -u "$func_msys_to_win32_result"
+            func_to_host_path_result="$func_cygpath_result"
+            ;;
+          * )
+            # convert from *nix to win32, then use cygpath to
+            # convert from win32 to cygwin.
+            func_wine_to_win32_path "$1"
+            func_cygpath -u "$func_wine_to_win32_path_result"
+            func_to_host_path_result="$func_cygpath_result"
+            ;;
+        esac # $build
+        if test -z "$func_to_host_path_result" ; then
+          func_error "Could not determine host path corresponding to"
+          func_error "  \`$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback:
+          func_to_host_path_result="$1"
+        fi
+        ;; # $host is cygwin
     esac
   fi
 }
 # end: func_to_host_path
 
+# func_wine_to_win32_pathlist arg
+# helper function used by func_to_host_pathlist
+# when $build is neither mingw/msys nor cygwin, and
+# arg must be converted to win32 ($host is mingw or
+# cygwin). Assumes arg has no leading or trailing
+# path separator characters.
+#
+# result is available in $func_wine_to_win32_pathlist_result
+# unconvertible paths in pathlist are skipped; if no paths
+# are convertible, result may be empty.
+func_wine_to_win32_pathlist ()
+{
+  # unfortunately, winepath doesn't convert pathlists
+  func_wine_to_win32_pathlist_result=""
+  if test -n "$1"; then
+    func_wine_to_win32_pathlist_oldIFS=$IFS
+    IFS=:
+    for func_wine_to_win32_pathlist_f in $1; do
+      IFS=$func_wine_to_win32_pathlist_oldIFS
+      if test -n "$func_wine_to_win32_pathlist_f" ; then
+        func_wine_to_win32_path "$func_wine_to_win32_pathlist_f"
+        if test -n "$func_wine_to_win32_path_result" ; then
+          if test -z "$func_wine_to_win32_pathlist_result"; then
+            
func_wine_to_win32_pathlist_result="$func_wine_to_win32_path_result"
+          else
+            func_append func_wine_to_win32_pathlist_result 
";$func_wine_to_win32_path_result"
+          fi
+        fi
+      fi
+    done
+    IFS=$func_wine_to_win32_pathlist_oldIFS
+  fi
+}
+# end: func_wine_to_win32_pathlist
+
 # func_to_host_pathlist arg
 #
 # Convert pathlists to host format when used with build tools.
@@ -2637,6 +2770,8 @@ func_to_host_path ()
 #    mingw (msys)    mingw  [e.g. native]
 #    cygwin          mingw
 #    *nix + wine     mingw
+#    cygwin          cygwin (no-op)
+#    *nix + wine     cygwin [* see LT_CYGPATH, in func_to_host_path()]
 #
 # Path separators are also converted from $build format to
 # $host format. If ARG begins or ends with a path separator
@@ -2652,7 +2787,6 @@ func_to_host_pathlist ()
   if test -n "$1"; then
     case $host in
       *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
         # Remove leading and trailing path separator characters from
         # ARG. msys behavior is inconsistent here, cygpath turns them
         # into '.;' and ';.', and winepath ignores them completely.
@@ -2660,36 +2794,17 @@ func_to_host_pathlist ()
         func_to_host_pathlist_tmp1=$func_stripname_result
         case $build in
           *mingw* ) # Actually, msys.
-            # Awkward: cmd appends spaces to result.
-            func_to_host_pathlist_result=`
-             ( cmd //c echo "$func_to_host_pathlist_tmp1" ) 2>/dev/null |
-             $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
+            func_msys_to_win32 "$func_to_host_pathlist_tmp1"
+            func_to_host_pathlist_result="$func_msys_to_win32_result"
             ;;
           *cygwin* )
-            func_to_host_pathlist_result=`cygpath -w -p 
"$func_to_host_pathlist_tmp1" |
-              $SED -e "$lt_sed_naive_backslashify"`
+            func_to_host_pathlist_result=`cygpath -m -p 
"$func_to_host_pathlist_tmp1"`
             ;;
           * )
-            # unfortunately, winepath doesn't convert pathlists
-            func_to_host_pathlist_result=""
-            func_to_host_pathlist_oldIFS=$IFS
-            IFS=:
-            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
-              IFS=$func_to_host_pathlist_oldIFS
-              if test -n "$func_to_host_pathlist_f" ; then
-                func_to_host_path "$func_to_host_pathlist_f"
-                if test -n "$func_to_host_path_result" ; then
-                  if test -z "$func_to_host_pathlist_result" ; then
-                    func_to_host_pathlist_result="$func_to_host_path_result"
-                  else
-                    func_append func_to_host_pathlist_result 
";$func_to_host_path_result"
-                  fi
-                fi
-              fi
-            done
-            IFS=$func_to_host_pathlist_oldIFS
+            func_wine_to_win32_pathlist "$func_to_host_pathlist_tmp1"
+            func_to_host_pathlist_result="$func_wine_to_win32_pathlist_result"
             ;;
-        esac
+        esac # $build
         if test -z "$func_to_host_pathlist_result"; then
           func_error "Could not determine the host path(s) corresponding to"
           func_error "  \`$1'"
@@ -2712,7 +2827,51 @@ func_to_host_pathlist ()
           *: ) func_append func_to_host_pathlist_result ";"
             ;;
         esac
-        ;;
+        ;; # $host is mingw
+      *cygwin* )
+        # Remove leading and trailing path separator characters from
+        # ARG. msys behavior is inconsistent here, cygpath turns them
+        # into '.;' and ';.', and winepath ignores them completely.
+       func_stripname : : "$1"
+        func_to_host_pathlist_tmp1=$func_stripname_result
+        case $build in
+          *cygwin* ) 
func_to_host_pathlist_result="$func_to_host_pathlist_tmp1" ;;
+          *mingw*  ) # unsupported
+            # This implies running a cross build from msys to
+            # cygwin -- but msys has notorious problems executing
+            # cygwin apps, because of conflicts between cygwin1.dll
+            # and msys-1.0.dll. However, we'll try it. First, convert
+            # from msys to win32, then use cygpath to convert from
+            # win32 to cygwin.
+            func_msys_to_win32 "$func_to_host_pathlist_tmp1"
+            func_cygpath -u -p "$func_msys_to_win32_result"
+            func_to_host_pathlist_result="$func_cygpath_result"
+            ;;
+          * )
+            # convert from *nix to win32, then use cygpath to
+            # convert from win32 to cygwin.
+            func_wine_to_win32_pathlist "$func_to_host_pathlist_tmp1"
+            func_cygpath -u -p "$func_wine_to_win32_pathlist_result"
+            func_to_host_pathlist_result="$func_cygpath_result"
+            ;;
+        esac # $build
+        if test -z "$func_to_host_pathlist_result"; then
+          func_error "Could not determine the host path(s) corresponding to"
+          func_error "  \`$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback.
+          func_to_host_pathlist_result="$func_to_host_pathlist_tmp1"
+        fi
+        # Now, add the leading and trailing path separators back
+        case "$1" in
+          :* ) func_to_host_pathlist_result=":$func_to_host_pathlist_result"
+            ;;
+        esac
+        case "$1" in
+          *: ) func_append func_to_host_pathlist_result ":"
+            ;;
+        esac
+        ;; # $host is cygwin
     esac
   fi
 }
-- 
1.6.0.4



Reply via email to