$NetBSD: patch-ab,v 1.28 2003/01/21 22:43:42 grant Exp $

--- ltmain.sh.orig	Thu Jun 14 14:06:50 2001
+++ ltmain.sh
@@ -211,6 +211,8 @@ do
   --mode) prevopt="--mode" prev=mode ;;
   --mode=*) mode="$optarg" ;;
 
+  --preserve-dup-deps) duplicate_deps="yes" ;;
+
   --quiet | --silent)
     show=:
     ;;
@@ -256,7 +258,7 @@ if test -z "$show_help"; then
   # Infer the operation mode.
   if test -z "$mode"; then
     case $nonopt in
-    *cc | *++ | gcc* | *-gcc*)
+    *cc | *++ | gcc* | *-gcc* | *CC)
       mode=link
       for arg
       do
@@ -494,11 +496,21 @@ if test -z "$show_help"; then
     # command doesn't match the default compiler.
     if test -n "$available_tags" && test -z "$tagname"; then
       case $base_compile in
-      "$CC "*) ;;
+      "$CC "*) tagname=CC ;;
       # Blanks in the command may have been stripped by the calling shell,
       # but not from the CC environment variable when ltconfig was run.
-      "`$echo $CC` "*) ;;
-      *)
+      "`$echo $CC` "*) tagname=CC ;;
+      *)   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$" < "$0" > /dev/null; then
 	    # Evaluate the configuration.
@@ -528,8 +540,6 @@ if test -z "$show_help"; then
 #        else
 #          echo "$modename: using $tagname tagged configuration"
         fi
-	;;
-      esac
     fi
 
     objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
@@ -1528,11 +1538,21 @@ EOF
     # command doesn't match the default compiler.
     if test -n "$available_tags" && test -z "$tagname"; then
       case $base_compile in
-      "$CC "*) ;;
+      "$CC "*) tagname=CC ;;
       # Blanks in the command may have been stripped by the calling shell,
       # but not from the CC environment variable when ltconfig was run.
-      "`$echo $CC` "*) ;;
-      *)
+      "`$echo $CC` "*) tagname=CC ;;
+      *)   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$" < "$0" > /dev/null; then
 	    # Evaluate the configuration.
@@ -1562,8 +1582,6 @@ EOF
 #       else
 #         echo "$modename: using $tagname tagged configuration"
         fi
-	;;
-      esac
     fi
 
     if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
@@ -1619,9 +1637,11 @@ EOF
     # Find all interdependent deplibs by searching for libraries
     # that are linked more than once (e.g. -la -lb -la)
     for deplib in $deplibs; do
+      if test "X$duplicate_deps" = "Xyes" ; then
       case "$libs " in
       *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
       esac
+      fi
       libs="$libs $deplib"
     done
 
@@ -1632,12 +1652,14 @@ EOF
       # $postdeps and mark them as special (i.e., whose duplicates are
       # not to be eliminated).
       pre_post_deps=
+      if test "X$duplicate_deps" = "Xyes" ; then
       for pre_post_dep in $predeps $postdeps; do
         case "$pre_post_deps " in
 	*" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
 	esac
 	pre_post_deps="$pre_post_deps $pre_post_dep"
       done
+      fi
       pre_post_deps=
     fi
 
@@ -1861,9 +1883,11 @@ EOF
 	    tmp_libs=
 	    for deplib in $dependency_libs; do
 	      deplibs="$deplib $deplibs"
+              if test "X$duplicate_deps" = "Xyes" ; then
 	      case "$tmp_libs " in
 	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
 	      esac
+              fi
 	      tmp_libs="$tmp_libs $deplib"
 	    done
 	  elif test $linkmode != prog && test $linkmode != lib; then
@@ -1986,9 +2010,11 @@ EOF
 	      # or/and link against static libraries
 	      newdependency_libs="$deplib $newdependency_libs"
 	    fi
+	    if test "X$duplicate_deps" = "Xyes" ; then
 	    case "$tmp_libs " in
 	    *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
 	    esac
+	    fi
 	    tmp_libs="$tmp_libs $deplib"
 	  done # for deplib
 	  continue
@@ -2287,9 +2313,11 @@ EOF
 	  tmp_libs=
 	  for deplib in $dependency_libs; do
 	    newdependency_libs="$deplib $newdependency_libs"
+	    if test "X$duplicate_deps" = "Xyes" ; then
 	    case "$tmp_libs " in
 	    *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
 	    esac
+	    fi
 	    tmp_libs="$tmp_libs $deplib"
 	  done
 
@@ -2582,7 +2610,7 @@ EOF
 	  ;;
 
 	irix)
-	  major=`expr $current - $age + 1`
+	  major=`expr $current - $age`
 	  verstring="sgi$major.$revision"
 
 	  # Add in all the interfaces that we are compatible with.
@@ -2642,7 +2670,16 @@ EOF
 	# Clear the version info if we defaulted, and they specified a release.
 	if test -z "$vinfo" && test -n "$release"; then
 	  major=
-	  verstring="0.0"
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring="0.0"
+	    ;;
+	  esac
 	  if test "$need_version" = no; then
 	    versuffix=
 	  else
@@ -5053,7 +5090,7 @@ relink_command=\"$relink_command\""
       fi
 
       # Now prepare to actually exec the command.
-      exec_cmd='"$cmd"$args'
+      exec_cmd="\$cmd$args"
     else
       # Display what would be done.
       if test -n "$shlibpath_var"; then
