$NetBSD: patch-ac,v 1.22 2006/08/23 19:49:12 jschauma Exp $

--- ltmain.sh.orig	Sun Dec 18 17:14:54 2005
+++ ltmain.sh	Wed Aug 23 15:40:14 2006
@@ -226,6 +226,31 @@
 # arg is usually of the form 'gcc ...'
 func_infer_tag ()
 {
+    # Set the commonly-used compilers for some tags.
+    tag_compilers_CC="*cc *xlc"
+    tag_compilers_CXX="*++ *CC"
+    tag_compilers_F77="*77 *fort"
+    base_compiler=`set -- "$@"; $echo $1`
+    # If $tagname still isn't set, then try to infer if the default
+    # "CC" tag applies by matching up the base compile command to some
+    # compilers commonly used for the "CC" tag.
+    if test -z "$tagname"; then
+        z=CC
+        eval "tag_compilers=\$tag_compilers_${z}"
+        if test -n "$tag_compilers"; then
+        for zp in $tag_compilers; do
+          case $base_compiler in
+            $zp)
+            # The compiler in the base compile command matches
+            # one of the common compilers for the current tag.
+            # Assume this is the tagged configuration we want.
+            tagname=$z
+            break
+            ;;
+          esac
+        done
+        fi
+    fi
     if test -n "$available_tags" && test -z "$tagname"; then
       CC_quoted=
       for arg in $CC; do
@@ -266,7 +291,28 @@
 	      break
 	      ;;
 	    esac
+	    # If $tagname still isn't set, then try to infer it by
+	    # matching up the base compile command to some compilers
+	    # commonly used for certain tags.
+	    base_compiler=`set -- "$@"; $echo $1`
+	    eval "tag_compilers=\$tag_compilers_${z}"
+	    if test -n "$tag_compilers"; then
+	      for zp in $tag_compilers; do
+		case $base_compiler in 
+		  $zp)
+		  # The compiler in the base compile command matches
+		  # one of the common compilers for the current tag.
+		  # Assume this is the tagged configuration we want.
+		  tagname=$z
+		  break
+		  ;;
+		esac
+	      done
+	      if test -n "$tagname"; then
+		break
+	      fi
 	  fi
+	  fi
 	done
 	# If $tagname still isn't set, then no tagged configuration
 	# was found and let the user know that the "--tag" command
@@ -568,7 +614,7 @@
     $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
@@ -1375,6 +1421,13 @@
 	    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 "*) ;;
@@ -1604,6 +1657,12 @@
 	compiler_flags="$compiler_flags $arg"
 	compile_command="$compile_command $arg"
 	finalize_command="$finalize_command $arg"
+	case $host:$arg in
+	*-*-dragonfly*:-pthread)
+	  # pkgsrc hack to use -pthread in .la file for final linking
+	  deplibs="$deplibs $arg"
+	  ;;
+	esac
 	continue
 	;;
 
@@ -2101,6 +2160,30 @@
 	  else
 	    compiler_flags="$compiler_flags $deplib"
 	  fi
+	  case $host:$deplib in
+	  *-*-dragonfly*:-pthread)
+	    # pkgsrc hack to use -pthread in .la file for final linking
+	    case $linkmode in
+	    lib)
+	      deplibs="$deplib $deplibs"
+	      test "$pass" = conv && continue
+	      newdependency_libs="$deplib $newdependency_libs"
+	      ;;
+	    prog)
+	      if test "$pass" = conv; then
+		deplibs="$deplib $deplibs"
+		continue
+	      fi
+	      if test "$pass" = scan; then
+		deplibs="$deplib $deplibs"
+	      else
+		compile_deplibs="$deplib $compile_deplibs"
+		finalize_deplibs="$deplib $finalize_deplibs"
+	      fi
+	      ;;
+	    esac
+	    ;;
+	  esac
 	  continue
 	  ;;
 	-l*)
@@ -3197,7 +3280,7 @@
 	    age="0"
 	    ;;
 	  irix|nonstopux)
-	    current=`expr $number_major + $number_minor - 1`
+	    current=`expr $number_major + $number_minor`
 	    age="$number_minor"
 	    revision="$number_minor"
 	    ;;
@@ -3247,6 +3330,7 @@
 	# Calculate the version variables.
 	major=
 	versuffix=
+	versuffix2=
 	verstring=
 	case $version_type in
 	none) ;;
@@ -3296,6 +3380,7 @@
 	linux)
 	  major=.`expr $current - $age`
 	  versuffix="$major.$age.$revision"
+	  versuffix2="$major.$age"
 	  ;;
 
 	osf)
@@ -3358,6 +3443,7 @@
 	if test "$avoid_version" = yes && test "$need_version" = no; then
 	  major=
 	  versuffix=
+	  versuffix2=
 	  verstring=""
 	fi
 
@@ -3409,12 +3495,13 @@
 	oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
       fi
 
-      # Eliminate all temporary directories.
-      for path in $notinst_path; do
-	lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"`
-	deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"`
-	dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"`
-      done
+      ### Commented out in pkgsrc, since it is completely broken.
+      ## Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"`
+      #	deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"`
+      #	dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"`
+      #done
 
       if test -n "$xrpath"; then
 	# If the user specified any rpath flags, then add them.
@@ -5820,8 +5907,16 @@
       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
