$NetBSD: patch-ac,v 1.12 2004/04/22 14:40:29 tv Exp $

--- ltmain.sh.orig	Sun Apr 11 01:44:45 2004
+++ ltmain.sh
@@ -192,10 +192,26 @@ func_infer_tag () {
       case $@ in
       # Blanks in the command may have been stripped by the calling shell,
       # but not from the CC environment variable when configure was run.
-      " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;;
+      " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*)
+         tagname=CC
+         ;;
       # Blanks at the start of $base_compile will cause this to fail
       # if we don't check for them as well.
       *)
+        base_compiler=`$echo $base_compile | awk '{ print $1 }'`
+        case $base_compiler in
+        *cc)
+          tagname=CC
+          ;;
+        *++)
+          tagname=CXX
+	  eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $0`"
+          ;;
+        esac
+        ;;
+      esac
+    fi
+    if test -n "$available_tags" && test -z "$tagname"; then
 	for z in $available_tags; do
 	  if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
 	    # Evaluate the configuration.
@@ -231,8 +247,6 @@ func_infer_tag () {
 #        else
 #          $echo "$modename: using $tagname tagged configuration"
 	fi
-	;;
-      esac
     fi
 }
 # End of Shell function definitions
@@ -401,7 +415,7 @@ if test -z "$show_help"; then
     $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2
     $echo "*** Future versions of Libtool will require -mode=MODE be specified." 1>&2
     case $nonopt in
-    *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*)
+    *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc* | *CC)
       mode=link
       for arg
       do
@@ -1185,6 +1199,13 @@ EOF
 	    exit $EXIT_FAILURE
 	    ;;
 	  esac
+	  # Canonicalise the pathname
+	  tmp=""
+	  while test "$arg" != "$tmp"
+          do
+            tmp=$arg
+            arg=`$echo "X$arg" | $Xsed -e 's%[^/.][^/.]*/\.\.%%g' -e 's%/\./%/%g' -e 's%//*%/%g' -e 's%/$%%g'`
+          done
 	  if test "$prev" = rpath; then
 	    case "$rpath " in
 	    *" $arg "*) ;;
@@ -2983,8 +3004,8 @@ EOF
 	darwin)
 	  # Like Linux, but with the current version available in
 	  # verstring for coding it into the library header
-	  major=.`expr $current - $age`
-	  versuffix="$major.$age.$revision"
+	  major=".$current"
+	  versuffix=".$current.$revision"
 	  # Darwin ld doesn't like 0 for these options...
 	  minor_current=`expr $current + 1`
 	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
@@ -5384,8 +5405,16 @@ relink_command=\"$relink_command\""
       exit $EXIT_FAILURE
     fi
 
-    # Strip any trailing slash from the destination.
-    dest=`$echo "X$dest" | $Xsed -e 's%/$%%'`
+    # Canonicalise the pathname:
+    #   - remove foo/../
+    #   - replace //
+    #   - remove /./
+    #   - strip any trailing /
+    tmp=""
+    while test "$dest" != "$tmp";  do
+      tmp=$dest
+      dest=`$echo "X$dest" | $Xsed -e 's%[^/.][^/.]*/\.\.%%g' -e 's%/\./%/%g' -e 's%//*%/%g' -e 's%/$%%g'`
+    done
 
     # Check to see that the destination is a directory.
     test -d "$dest" && isdir=yes
