ltmain.sh 88.7 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
# ltmain.sh - Provide generalized library-building support services.
2 3 4
# NOTE: Changing this file will not affect anything until you rerun ltconfig.
#
# Copyright (C) 1996-1998 Free Software Foundation, Inc.
Elliot Lee's avatar
Elliot Lee committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.

26 27 28 29
# Check that we have a working $echo.
if test "X$1" = X--no-reexec; then
  # Discard the --no-reexec flag, and continue.
  shift
30 31 32 33 34 35 36
elif test "X$1" = X--fallback-echo; then
  # used as fallback echo
  shift
  cat <<EOF
$*
EOF
  exit 0
37 38 39 40 41 42 43 44
elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
  # Yippee, $echo works!
  :
else
  # Restart under the correct shell, and then maybe $echo will work.
  exec $SHELL "$0" --no-reexec ${1+"$@"}
fi

Elliot Lee's avatar
Elliot Lee committed
45 46
# The name of this program.
progname=`$echo "$0" | sed 's%^.*/%%'`
47
modename="$progname"
Elliot Lee's avatar
Elliot Lee committed
48 49 50 51

# Constants.
PROGRAM=ltmain.sh
PACKAGE=libtool
52
VERSION=1.2d
Elliot Lee's avatar
Elliot Lee committed
53 54 55 56 57 58 59 60 61 62

default_mode=
help="Try \`$progname --help' for more information."
magic="%%%MAGIC variable%%%"
mkdir="mkdir"
mv="mv -f"
rm="rm -f"

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
63 64
Xsed='sed -e s/^X//'
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
Elliot Lee's avatar
Elliot Lee committed
65 66 67 68 69

# NLS nuisances.
# Only set LANG and LC_ALL to C if already set.
# These must not be set unconditionally because not all systems understand
# e.g. LANG=C (notably SCO).
70 71 72 73 74 75 76
# We save the old values to restore during execute mode.
if test "${LC_ALL+set}" = set; then
  save_LC_ALL="$LC_ALL"; LC_ALL=C; export LC_ALL
fi
if test "${LANG+set}" = set; then
  save_LANG="$LANG"; LANG=C; export LANG
fi
Elliot Lee's avatar
Elliot Lee committed
77 78

if test "$LTCONFIG_VERSION" != "$VERSION"; then
79 80
  echo "$modename: ltconfig version \`$LTCONFIG_VERSION' does not match $PROGRAM version \`$VERSION'" 1>&2
  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
Elliot Lee's avatar
Elliot Lee committed
81 82 83 84
  exit 1
fi

if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
85 86
  echo "$modename: not configured to build any kind of library" 1>&2
  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
Elliot Lee's avatar
Elliot Lee committed
87 88 89 90 91 92 93 94 95 96 97 98
  exit 1
fi

# Global variables.
mode=$default_mode
nonopt=
prev=
prevopt=
run=
show="$echo"
show_help=
execute_dlfiles=
99 100
lo2o="s/\\.lo\$/.${objext}/"
los2o="s/\\.lo /.${objext} /g"
Elliot Lee's avatar
Elliot Lee committed
101 102 103 104 105 106 107 108

# Parse our command line options once, thoroughly.
while test $# -gt 0
do
  arg="$1"
  shift

  case "$arg" in
109
  -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;;
Elliot Lee's avatar
Elliot Lee committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  *) optarg= ;;
  esac

  # If the previous option needs an argument, assign it.
  if test -n "$prev"; then
    case "$prev" in
    execute_dlfiles)
      eval "$prev=\"\$$prev \$arg\""
      ;;
    *)
      eval "$prev=\$arg"
      ;;
    esac

    prev=
    prevopt=
    continue
  fi

  # Have we seen a non-optional argument yet?
  case "$arg" in
  --help)
    show_help=yes
    ;;

  --version)
136
    echo "$PROGRAM (GNU $PACKAGE) $VERSION"
Elliot Lee's avatar
Elliot Lee committed
137 138 139
    exit 0
    ;;

140 141 142 143 144 145 146 147 148 149
  --config)
    sed -e '1,/^### BEGIN LIBTOOL CONFIG/d' -e '/^### END LIBTOOL CONFIG/,$d' $0
    exit 0
    ;;

  --debug)
    echo "$progname: enabling shell trace mode"
    set -x
    ;;

Elliot Lee's avatar
Elliot Lee committed
150 151 152 153 154
  --dry-run | -n)
    run=:
    ;;

  --features)
155
    echo "host: $host"
Elliot Lee's avatar
Elliot Lee committed
156
    if test "$build_libtool_libs" = yes; then
157
      echo "enable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
158
    else
159
      echo "disable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
160 161
    fi
    if test "$build_old_libs" = yes; then
162
      echo "enable static libraries"
Elliot Lee's avatar
Elliot Lee committed
163
    else
164
      echo "disable static libraries"
Elliot Lee's avatar
Elliot Lee committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    fi
    exit 0
    ;;

  --finish) mode="finish" ;;

  --mode) prevopt="--mode" prev=mode ;;
  --mode=*) mode="$optarg" ;;

  --quiet | --silent)
    show=:
    ;;

  -dlopen)
    prevopt="-dlopen"
    prev=execute_dlfiles
    ;;

  -*)
184
    $echo "$modename: unrecognized option \`$arg'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
185 186 187 188 189 190 191 192 193 194 195 196
    $echo "$help" 1>&2
    exit 1
    ;;

  *)
    nonopt="$arg"
    break
    ;;
  esac
done

if test -n "$prevopt"; then
197
  $echo "$modename: option \`$prevopt' requires an argument" 1>&2
Elliot Lee's avatar
Elliot Lee committed
198 199 200 201 202 203 204 205 206
  $echo "$help" 1>&2
  exit 1
fi

if test -z "$show_help"; then

  # Infer the operation mode.
  if test -z "$mode"; then
    case "$nonopt" in
207
    *cc | *++ | gcc* | *-gcc*)
Elliot Lee's avatar
Elliot Lee committed
208 209 210 211 212 213 214 215 216 217 218
      mode=link
      for arg
      do
        case "$arg" in
        -c)
           mode=compile
           break
           ;;
        esac
      done
      ;;
219
    *db | *dbx | *strace | *truss)
Elliot Lee's avatar
Elliot Lee committed
220 221
      mode=execute
      ;;
222
    *install*|cp|mv)
Elliot Lee's avatar
Elliot Lee committed
223 224 225 226 227 228 229 230 231 232 233 234
      mode=install
      ;;
    *rm)
      mode=uninstall
      ;;
    *)
      # If we have no mode, but dlfiles were specified, then do execute mode.
      test -n "$execute_dlfiles" && mode=execute

      # Just use the default operation mode.
      if test -z "$mode"; then
        if test -n "$nonopt"; then
235
          $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
236
        else
237
          $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2
Elliot Lee's avatar
Elliot Lee committed
238 239 240 241 242 243 244 245
        fi
      fi
      ;;
    esac
  fi

  # Only execute mode is allowed to have -dlopen flags.
  if test -n "$execute_dlfiles" && test "$mode" != execute; then
246
    $echo "$modename: unrecognized option \`-dlopen'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
247 248 249 250 251 252
    $echo "$help" 1>&2
    exit 1
  fi

  # Change the help message to a mode-specific one.
  generic_help="$help"
253
  help="Try \`$modename --help --mode=$mode' for more information."
Elliot Lee's avatar
Elliot Lee committed
254 255 256 257 258

  # These modes are in order of execution frequency so that they run quickly.
  case "$mode" in
  # libtool compile mode
  compile)
259
    modename="$modename: compile"
Elliot Lee's avatar
Elliot Lee committed
260 261 262 263 264
    # Get the compilation command and the source file.
    base_compile=
    lastarg=
    srcfile="$nonopt"
    suppress_output=
265
    force_static=no
Elliot Lee's avatar
Elliot Lee committed
266

267
    user_target=no
Elliot Lee's avatar
Elliot Lee committed
268 269
    for arg
    do
270 271 272
      # Accept any command-line options.
      case "$arg" in
      -o)
273 274 275 276 277
        if test "$user_target" != "no"; then
          $echo "$modename: you cannot specify \`-o' more than once" 1>&2
	  exit 1
        fi
        user_target=next
278 279
	;;

280 281 282 283 284
      -force-static)
        force_static=yes
        continue
        ;;
	
285
      -static)
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
        build_old_libs=yes
        continue
        ;;
      esac

      case "$user_target" in
      next)
        # The next one is the -o target name
        user_target=yes
        continue
        ;;
      yes)
        # We got the output file
        user_target=set
        libobj="$arg"
        continue
        ;;
303
      esac
Elliot Lee's avatar
Elliot Lee committed
304 305 306 307 308 309 310 311 312 313

      # Accept the current argument as the source file.
      lastarg="$srcfile"
      srcfile="$arg"

      # Aesthetically quote the previous argument.

      # Backslashify any backslashes, double quotes, and dollar signs.
      # These are the only characters that are still specially
      # interpreted inside of double-quoted scrings.
314
      lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
315 316 317 318 319 320

      # Double-quote args containing other shell metacharacters.
      # Many Bourne shells cannot handle close brackets correctly in scan
      # sets, so we specify it separately.
      case "$lastarg" in
      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
321 322
        lastarg="\"$lastarg\""
        ;;
Elliot Lee's avatar
Elliot Lee committed
323 324 325 326
      esac

      # Add the previous argument to base_compile.
      if test -z "$base_compile"; then
327
        base_compile="$lastarg"
Elliot Lee's avatar
Elliot Lee committed
328
      else
329
        base_compile="$base_compile $lastarg"
Elliot Lee's avatar
Elliot Lee committed
330 331 332
      fi
    done

333 334 335 336 337 338 339 340 341 342 343 344
    case "$user_target" in
    set)
      ;;
    no)
      # Get the name of the library object.
      libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'`
      ;;
    *)
      $echo "$modename: you must specify a target with \`-o'" 1>&2
      exit 1
      ;;
    esac
Elliot Lee's avatar
Elliot Lee committed
345 346

    # Recognize several different file suffixes.
347 348
    # If the user specifies -o file.o, it is replaced with file.lo
    xform='[cCFSfmso]'
Elliot Lee's avatar
Elliot Lee committed
349
    case "$libobj" in
350 351 352 353
    *.ada) xform=ada ;;
    *.adb) xform=adb ;;
    *.ads) xform=ads ;;
    *.asm) xform=asm ;;
Elliot Lee's avatar
Elliot Lee committed
354 355 356 357 358 359 360 361
    *.c++) xform=c++ ;;
    *.cc) xform=cc ;;
    *.cpp) xform=cpp ;;
    *.cxx) xform=cxx ;;
    *.f90) xform=f90 ;;
    *.for) xform=for ;;
    esac

362
    libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
Elliot Lee's avatar
Elliot Lee committed
363 364

    case "$libobj" in
365
    *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;;
Elliot Lee's avatar
Elliot Lee committed
366
    *)
367
      $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
368 369 370 371 372
      exit 1
      ;;
    esac

    if test -z "$base_compile"; then
373
      $echo "$modename: you must specify a compilation command" 1>&2
Elliot Lee's avatar
Elliot Lee committed
374 375 376 377 378 379
      $echo "$help" 1>&2
      exit 1
    fi

    # Delete any leftover library objects.
    if test "$build_old_libs" = yes; then
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
      removelist="$obj $libobj $lockfile"
    else
      removelist="$libobj $lockfile"
    fi

    $run $rm $removelist
    trap "$run $rm $removelist; exit 1" 1 2 15

    # Calculate the filename of the output object if compiler does
    # not support -o with -c
    if test "$compiler_c_o" = no; then
      output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\..*$%%'`.${objext}
      lockfile="$output_obj.lock"
      removelist="$removelist $output_obj $lockfile"
      trap "$run $rm $removelist; exit 1" 1 2 15
Elliot Lee's avatar
Elliot Lee committed
395
    else
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
      need_locks=no
      lockfile=
    fi

    # Lock this critical section if it is needed
    # We use this script file to make the link, it avoids creating a new file
    if test "$need_locks" = yes; then
      until ln "$0" "$lockfile" 2>/dev/null; do
        $show "Waiting for $lockfile to be removed"
        sleep 2
      done
    elif test "$need_locks" = warn; then
      if test -f "$lockfile"; then
	echo "\
*** ERROR, $lockfile exists and contains:
`cat $lockfile 2>/dev/null`

This indicates that another process is trying to use the same
temporary object file, and libtool could not work around it because
your compiler does not support \`-c' and \`-o' together.  If you
repeat this compilation, it may succeed, by chance, but you had better
avoid parallel builds (make -j) in this platform, or get a better
compiler."

	$run $rm $removelist
	exit 1
      fi
      echo $srcfile > "$lockfile"
    fi

    if test -n "$fix_srcfile_path"; then
      eval srcfile=\"$fix_srcfile_path\"
Elliot Lee's avatar
Elliot Lee committed
428 429 430 431 432 433 434 435
    fi

    # Only build a PIC object if we are building libtool libraries.
    if test "$build_libtool_libs" = yes; then
      # Without this assignment, base_compile gets emptied.
      fbsd_hideous_sh_bug=$base_compile

      # All platforms use -DPIC, to notify preprocessed assembler code.
436 437 438 439 440 441 442 443 444 445 446
      command="$base_compile$pic_flag -DPIC $srcfile"
      if test "$compiler_o_lo" = yes; then
        command="$command -o $libobj"
        output_obj="$libobj"
      elif test "$compiler_c_o" = yes; then
        command="$command -o $obj"
        output_obj="$obj"
      fi

      $show "$command"
      if $run eval "$command"; then :
Elliot Lee's avatar
Elliot Lee committed
447
      else
448
        test -n "$output_obj" && $run $rm $removelist
Elliot Lee's avatar
Elliot Lee committed
449 450 451
        exit 1
      fi

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
      if test "$need_locks" = warn &&
	 test x"`cat $lockfile 2>/dev/null`" != x"$srcfile"; then
	echo "\
*** ERROR, $lockfile contains:
`cat $lockfile 2>/dev/null`

but it should contain:
$srcfile

This indicates that another process is trying to use the same
temporary object file, and libtool could not work around it because
your compiler does not support \`-c' and \`-o' together.  If you
repeat this compilation, it may succeed, by chance, but you had better
avoid parallel builds (make -j) in this platform, or get a better
compiler."

	$run $rm $removelist
	exit 1
Elliot Lee's avatar
Elliot Lee committed
470 471
      fi

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
      # Just move the object if needed, then go on to compile the next one
      if test "$compiler_o_lo" = no && test x"$output_obj" != x"$libobj"; then
        $show "$mv $output_obj $libobj"
        if $run $mv $output_obj $libobj; then :
	else
	  error=$?
	  $run $rm $removelist
	  exit $error
	fi
      fi

      # If we have no pic_flag and do not have -force-static, 
      # then copy the object into place and finish.
      if test -z "$pic_flag" && test "$force_static" = no; then
        $show "$LN_S $libobj $obj"
        if $run $LN_S $libobj $obj; then
	  exit 0
	else
          error=$?
	  $run $rm $removelist
	  exit $error
	fi
      fi
Elliot Lee's avatar
Elliot Lee committed
495 496 497 498 499 500 501

      # Allow error messages only from the first compilation.
      suppress_output=' >/dev/null 2>&1'
    fi

    # Only build a position-dependent object if we build old libraries.
    if test "$build_old_libs" = yes; then
502 503 504 505 506 507 508 509 510
      command="$base_compile $srcfile"
      if test "$force_static" = yes; then
        command="$command -DLIBTOOL_STATIC"
      fi
      if test "$compiler_c_o" = yes; then
        command="$command -o $obj"
        output_obj="$obj"
      fi

Elliot Lee's avatar
Elliot Lee committed
511
      # Suppress compiler output if we already did a PIC compilation.
512 513 514
      command="$command$suppress_output"
      $show "$command"
      if $run eval "$command"; then :
Elliot Lee's avatar
Elliot Lee committed
515
      else
516
        $run $rm $removelist
Elliot Lee's avatar
Elliot Lee committed
517 518
        exit 1
      fi
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554

      if test "$need_locks" = warn &&
	 test x"`cat $lockfile 2>/dev/null`" != x"$srcfile"; then
	echo "\
*** ERROR, $lockfile contains:
`cat $lockfile 2>/dev/null`

but it should contain:
$srcfile

This indicates that another process is trying to use the same
temporary object file, and libtool could not work around it because
your compiler does not support \`-c' and \`-o' together.  If you
repeat this compilation, it may succeed, by chance, but you had better
avoid parallel builds (make -j) in this platform, or get a better
compiler."

	$run $rm $removelist
	exit 1
      fi

      # Just move the object if needed
      if test "$compiler_c_o" = no && test x"$output_obj" != x"$obj"; then
        $show "$mv $output_obj $obj"
        if $run $mv $output_obj $obj; then :
	else
	  error=$?
	  $run $rm $removelist
	  exit $error
	fi
      fi
    fi

    # Unlock the critical section if it was locked
    if test "$need_locks" != no; then
      $rm "$lockfile"
Elliot Lee's avatar
Elliot Lee committed
555 556
    fi

557 558
    # Create an invalid libtool object if no PIC, so that we do not
    # accidentally link it into a program.
Elliot Lee's avatar
Elliot Lee committed
559
    if test "$build_libtool_libs" != yes; then
560 561
      $show "echo timestamp > $libobj"
      $run eval "echo timestamp > \$libobj" || exit $?
Elliot Lee's avatar
Elliot Lee committed
562 563 564 565 566 567 568
    fi

    exit 0
    ;;

  # libtool link mode
  link)
569
    modename="$modename: link"
570
    C_compiler="$CC" # save it, to compile generated C sources
Elliot Lee's avatar
Elliot Lee committed
571
    CC="$nonopt"
572
    allow_undefined=yes
Elliot Lee's avatar
Elliot Lee committed
573 574 575 576 577
    compile_command="$CC"
    finalize_command="$CC"

    compile_shlibpath=
    finalize_shlibpath=
578 579
    convenience=
    old_convenience=
Elliot Lee's avatar
Elliot Lee committed
580
    deplibs=
581 582
    eval lib_search_path=\"$sys_lib_search_path\"
    
Elliot Lee's avatar
Elliot Lee committed
583 584 585
    dlfiles=
    dlprefiles=
    export_dynamic=no
586
    export_symbols=
587
    generated=
Elliot Lee's avatar
Elliot Lee committed
588 589 590 591
    hardcode_libdirs=
    libobjs=
    link_against_libtool_libs=
    ltlibs=
592
    module=no
Elliot Lee's avatar
Elliot Lee committed
593 594 595
    objs=
    prev=
    prevarg=
596
    release=
Elliot Lee's avatar
Elliot Lee committed
597 598 599 600 601 602 603 604 605 606 607
    rpath=
    perm_rpath=
    temp_rpath=
    vinfo=

    # We need to know -static, to get the right output filenames.
    for arg
    do
      case "$arg" in
      -all-static | -static)
        if test "X$arg" = "X-all-static" && test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
608
	    $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2
Elliot Lee's avatar
Elliot Lee committed
609 610 611 612 613 614 615 616 617 618 619 620
        fi
        build_libtool_libs=no
	build_old_libs=yes
        break
        ;;
      esac
    done

    # See if our shared archives depend on static archives.
    test -n "$old_archive_from_new_cmds" && build_old_libs=yes

    # Go through the arguments, transforming them on the way.
621 622 623 624
    while test $# -gt 0; do
      arg="$1"
      shift

Elliot Lee's avatar
Elliot Lee committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
      # If the previous option needs an argument, assign it.
      if test -n "$prev"; then
        case "$prev" in
        output)
          compile_command="$compile_command @OUTPUT@"
          finalize_command="$finalize_command @OUTPUT@"
          ;;
        esac

        case "$prev" in
        dlfiles|dlprefiles)
          case "$arg" in
          *.la | *.lo) ;;  # We handle these cases below.
          *)
            dlprefiles="$dlprefiles $arg"
            test "$prev" = dlfiles && dlfiles="$dlfiles $arg"
            prev=
            ;;
          esac
          ;;
645 646 647 648 649 650 651 652
	exportsyms)
	  export_symbols="$arg"
          if test ! -f "$arg"; then
            $echo "$modename: symbol file \`$arg' does not exist"
            exit 1
          fi
	  prev=
	  ;;
653 654 655 656 657
	release)
	  release="-$arg"
	  prev=
	  continue
	  ;;
Elliot Lee's avatar
Elliot Lee committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
        rpath)
          rpath="$rpath $arg"
	  prev=
	  continue
	  ;;
        *)
          eval "$prev=\"\$arg\""
          prev=
          continue
          ;;
        esac
      fi

      prevarg="$arg"

      case "$arg" in
      -all-static)
	if test -n "$link_static_flag"; then
          compile_command="$compile_command $link_static_flag"
	  finalize_command="$finalize_command $link_static_flag"
        fi
        continue
	;;

      -allow-undefined)
683 684
	# FIXME: remove this flag sometime in the future.
	$echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2
Elliot Lee's avatar
Elliot Lee committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	continue
	;;

      -dlopen)
        prev=dlfiles
        continue
        ;;

      -dlpreopen)
        prev=dlprefiles
        continue
        ;;

      -export-dynamic)
        if test "$export_dynamic" != yes; then
          export_dynamic=yes
	  if test -n "$export_dynamic_flag_spec"; then
702
	    eval arg=\"$export_dynamic_flag_spec\"
Elliot Lee's avatar
Elliot Lee committed
703 704 705 706 707 708 709 710 711 712
	  else
	    arg=
	  fi

          # Add the symbol object into the linking commands.
	  compile_command="$compile_command @SYMFILE@"
	  finalize_command="$finalize_command @SYMFILE@"
        fi
        ;;

713 714 715 716 717 718 719 720 721
      -export-symbols)
        if test -n "$export_symbols"; then
          $echo "$modename: cannot have more than one -exported-symbols"
          exit 1
        fi
	prev=exportsyms
	continue
        ;;

Elliot Lee's avatar
Elliot Lee committed
722
      -L*)
723
        dir=`$echo "X$arg" | $Xsed -e 's%^-L\(.*\)$%\1%'`
Elliot Lee's avatar
Elliot Lee committed
724
        case "$dir" in
725
        /* | [A-Za-z]:[/\\]*)
Elliot Lee's avatar
Elliot Lee committed
726 727 728
	  # Add the corresponding hardcode_libdir_flag, if it is not identical.
          ;;
        *)
729
          $echo "$modename: \`-L$dir' cannot specify a relative directory" 1>&2
Elliot Lee's avatar
Elliot Lee committed
730 731 732 733
          exit 1
          ;;
        esac
        deplibs="$deplibs $arg"
734
        lib_search_path="$lib_search_path `expr $arg : '-L\(.*\)'`"
Elliot Lee's avatar
Elliot Lee committed
735 736 737 738
        ;;

      -l*) deplibs="$deplibs $arg" ;;

739 740 741 742 743 744 745 746 747 748 749
      -module)
        if test "$module" != yes; then
          module=yes
	  if test -n "$export_dynamic_flag_spec"; then
	    eval arg=\"$export_dynamic_flag_spec\"
	  else
	    arg=
	  fi
	fi
        ;;
	
750 751 752 753 754
      -no-undefined)
	allow_undefined=no
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
755 756
      -o) prev=output ;;

757 758 759 760 761
      -release)
	prev=release
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
      -rpath)
        prev=rpath
        continue
        ;;

      -static)
	# If we have no pic_flag, then this is the same as -all-static.
	if test -z "$pic_flag" && test -n "$link_static_flag"; then
          compile_command="$compile_command $link_static_flag"
	  finalize_command="$finalize_command $link_static_flag"
        fi
	continue
	;;

      -version-info)
        prev=vinfo
        continue
        ;;

      # Some other compiler flag.
      -* | +*)
	# Unknown arguments in both finalize_command and compile_command need
	# to be aesthetically quoted because they are evaled later.
785
	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
786 787 788 789 790 791 792
	case "$arg" in
	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
	  arg="\"$arg\""
	  ;;
	esac
        ;;

793
      *.o | *.obj | *.a | *.lib)
Elliot Lee's avatar
Elliot Lee committed
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
        # A standard object.
        objs="$objs $arg"
        ;;

      *.lo)
        # A library object.
	if test "$prev" = dlfiles; then
	  dlfiles="$dlfiles $arg"
	  if test "$build_libtool_libs" = yes; then
	    prev=
	    continue
	  else
	    # If libtool objects are unsupported, then we need to preload.
	    prev=dlprefiles
	  fi
	fi

	if test "$prev" = dlprefiles; then
	  # Preload the old-style object.
813
	  dlprefiles="$dlprefiles "`$echo "X$arg" | $Xsed -e "$lo2o"`
Elliot Lee's avatar
Elliot Lee committed
814 815 816 817 818 819 820 821 822 823 824 825 826 827
	  prev=
	fi
	libobjs="$libobjs $arg"
        ;;

      *.la)
        # A libtool-controlled library.

        dlname=
        libdir=
        library_names=
        old_library=

        # Check to see that this really is a libtool archive.
828
        if (sed -e '2q' $arg | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
Elliot Lee's avatar
Elliot Lee committed
829
        else
830
          $echo "$modename: \`$arg' is not a valid libtool archive" 1>&2
Elliot Lee's avatar
Elliot Lee committed
831 832 833
          exit 1
        fi

834 835 836 837
	# If the library was installed with an old release of libtool,
	# it will not redefine variable installed.
	installed=yes

Elliot Lee's avatar
Elliot Lee committed
838 839
        # If there is no directory component, then add one.
        case "$arg" in
840
        */* | *\\*) . $arg ;;
Elliot Lee's avatar
Elliot Lee committed
841 842 843 844 845 846 847 848 849 850
        *) . ./$arg ;;
        esac

        # Get the name of the library we link against.
        linklib=
        for l in $old_library $library_names; do
          linklib="$l"
        done

        if test -z "$linklib"; then
851
          $echo "$modename: cannot find name of link library for \`$arg'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
852 853 854 855
          exit 1
        fi

        # Find the relevant object directory and library name.
856
        name=`$echo "X$arg" | $Xsed -e 's%^.*/%%' -e 's/\.la$//' -e 's/^lib//'`
857 858 859 860 861 862 863 864 865 866 867

	if test "X$installed" = Xyes; then
	  dir="$libdir"
	else
	  dir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
	  if test "X$dir" = "X$arg"; then
	    dir="$objdir"
	  else
	    dir="$dir/$objdir"
	  fi
	fi
Elliot Lee's avatar
Elliot Lee committed
868

869 870
        if test -z "$libdir"; then
	  # It is a libtool convenience library, so add in its objects.
871
	  convenience="$convenience $dir/$old_library"
872
	  old_convenience="$old_convenience $dir/$old_library"
873 874 875
	  deplibs="$deplibs$dependency_libs"
	  compile_command="$compile_command $dir/$old_library$dependency_libs"
	  finalize_command="$finalize_command $dir/$old_library$dependency_libs"
876 877 878
	  continue
	fi

Elliot Lee's avatar
Elliot Lee committed
879 880 881
        # This library was specified with -dlopen.
        if test "$prev" = dlfiles; then
          dlfiles="$dlfiles $arg"
882 883 884
          if test -z "$dlname" || test "$build_libtool_libs" = no; then
            # If there is no dlname or we're linking statically,
            # we need to preload.
Elliot Lee's avatar
Elliot Lee committed
885 886
            prev=dlprefiles
          else
887 888 889 890
            # We should not create a dependency on this library, but we
	    # may need any libraries it requires.
	    compile_command="$compile_command$dependency_libs"
	    finalize_command="$finalize_command$dependency_libs"
Elliot Lee's avatar
Elliot Lee committed
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
            prev=
            continue
          fi
        fi

        # The library was specified with -dlpreopen.
        if test "$prev" = dlprefiles; then
          # Prefer using a static library (so that no silly _DYNAMIC symbols
          # are required to link).
          if test -n "$old_library"; then
            dlprefiles="$dlprefiles $dir/$old_library"
          else
            dlprefiles="$dlprefiles $dir/$linklib"
          fi
          prev=
        fi

        if test "$build_libtool_libs" = yes && test -n "$library_names"; then
          link_against_libtool_libs="$link_against_libtool_libs $arg"
          if test -n "$shlibpath_var"; then
            # Make sure the rpath contains only unique directories.
            case "$temp_rpath " in
            *" $dir "*) ;;
            *) temp_rpath="$temp_rpath $dir" ;;
            esac
          fi

	  # This is the magic to use -rpath.
          if test -n "$hardcode_libdir_flag_spec"; then
            if test -n "$hardcode_libdir_separator"; then
              if test -z "$hardcode_libdirs"; then
                # Put the magic libdir with the hardcode flag.
                hardcode_libdirs="$libdir"
                libdir="@HARDCODE_LIBDIRS@"
              else
                # Just accumulate the unique libdirs.
		case "$hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator" in
		*"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
		  ;;
		*)
		  hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
		  ;;
		esac
                libdir=
              fi
            fi

            if test -n "$libdir"; then
939
              eval flag=\"$hardcode_libdir_flag_spec\"
Elliot Lee's avatar
Elliot Lee committed
940 941 942 943

              compile_command="$compile_command $flag"
              finalize_command="$finalize_command $flag"
            fi
944
          elif test -n "$runpath_var"; then
Elliot Lee's avatar
Elliot Lee committed
945 946 947 948 949 950 951 952
            # Do the same for the permanent run path.
            case "$perm_rpath " in
            *" $libdir "*) ;;
            *) perm_rpath="$perm_rpath $libdir" ;;
            esac
          fi


953
	  lib_linked=yes
Elliot Lee's avatar
Elliot Lee committed
954
          case "$hardcode_action" in
955
          immediate | unsupported)
Elliot Lee's avatar
Elliot Lee committed
956 957 958
            if test "$hardcode_direct" = no; then
              compile_command="$compile_command $dir/$linklib"
            elif test "$hardcode_minus_L" = no; then
959 960 961 962 963
	      case "$host" in
	      *-*-sunos*)
                compile_shlibpath="$compile_shlibpath$dir:"
		;;
	      esac
Elliot Lee's avatar
Elliot Lee committed
964 965 966 967
              compile_command="$compile_command -L$dir -l$name"
            elif test "$hardcode_shlibpath_var" = no; then
              compile_shlibpath="$compile_shlibpath$dir:"
              compile_command="$compile_command -l$name"
968 969
	    else
	      lib_linked=no
Elliot Lee's avatar
Elliot Lee committed
970 971 972 973 974 975
            fi
            ;;

          relink)
            # We need an absolute path.
            case "$dir" in
976
            /* | [A-Za-z]:[/\\]*) ;;
Elliot Lee's avatar
Elliot Lee committed
977 978 979
            *)
              absdir=`cd "$dir" && pwd`
              if test -z "$absdir"; then
980
                $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
981 982 983 984 985 986 987 988 989 990 991 992 993
                exit 1
              fi
              dir="$absdir"
              ;;
            esac

            if test "$hardcode_direct" = yes; then
              compile_command="$compile_command $dir/$linklib"
            elif test "$hardcode_minus_L" = yes; then
              compile_command="$compile_command -L$dir -l$name"
            elif test "$hardcode_shlibpath_var" = yes; then
              compile_shlibpath="$compile_shlibpath$dir:"
              compile_command="$compile_command -l$name"
994 995
	    else
	      lib_linked=no
Elliot Lee's avatar
Elliot Lee committed
996 997 998
            fi
            ;;

999 1000 1001
	  *)
	    lib_linked=no
	    ;;
Elliot Lee's avatar
Elliot Lee committed
1002 1003
          esac

1004 1005 1006 1007 1008
	  if test "$lib_linked" != yes; then
	    $echo "$modename: configuration error: unsupported hardcode properties"
	    exit 1
	  fi

Elliot Lee's avatar
Elliot Lee committed
1009 1010 1011 1012 1013 1014 1015 1016 1017
          # Finalize command for both is simple: just hardcode it.
          if test "$hardcode_direct" = yes; then
            finalize_command="$finalize_command $libdir/$linklib"
          elif test "$hardcode_minus_L" = yes; then
            finalize_command="$finalize_command -L$libdir -l$name"
          elif test "$hardcode_shlibpath_var" = yes; then
            finalize_shlibpath="$finalize_shlibpath$libdir:"
            finalize_command="$finalize_command -l$name"
          else
1018
            # We cannot seem to hardcode it, guess we'll fake it.
Elliot Lee's avatar
Elliot Lee committed
1019 1020 1021 1022 1023
            finalize_command="$finalize_command -L$libdir -l$name"
          fi
        else
          # Transform directly to old archives if we don't build new libraries.
          if test -n "$pic_flag" && test -z "$old_library"; then
1024
            $echo "$modename: cannot find static library for \`$arg'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
            exit 1
          fi

	  # Here we assume that one of hardcode_direct or hardcode_minus_L
	  # is not unsupported.  This is valid on all known static and
	  # shared platforms.
	  if test "$hardcode_direct" != unsupported; then
	    test -n "$old_library" && linklib="$old_library"
	    compile_command="$compile_command $dir/$linklib"
	    finalize_command="$finalize_command $dir/$linklib"
	  else
	    compile_command="$compile_command -L$dir -l$name"
	    finalize_command="$finalize_command -L$dir -l$name"
	  fi
        fi
1040 1041 1042 1043

	# Add in any libraries that this one depends upon.
	compile_command="$compile_command$dependency_libs"
	finalize_command="$finalize_command$dependency_libs"
Elliot Lee's avatar
Elliot Lee committed
1044 1045 1046 1047 1048 1049 1050
	continue
        ;;

      # Some other compiler argument.
      *)
	# Unknown arguments in both finalize_command and compile_command need
	# to be aesthetically quoted because they are evaled later.
1051
	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
1052 1053 1054 1055 1056 1057 1058 1059 1060
	case "$arg" in
	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
	  arg="\"$arg\""
	  ;;
	esac
        ;;
      esac

      # Now actually substitute the argument into the commands.
1061 1062 1063 1064
      if test -n "$arg"; then
	compile_command="$compile_command $arg"
	finalize_command="$finalize_command $arg"
      fi
Elliot Lee's avatar
Elliot Lee committed
1065 1066 1067
    done

    if test -n "$prev"; then
1068 1069 1070 1071 1072
      $echo "$modename: the \`$prevarg' option requires an argument" 1>&2
      $echo "$help" 1>&2
      exit 1
    fi

1073 1074 1075 1076 1077
    if test -n "$export_symbols" && test "$module" = yes; then
      $echo "$modename: \`-export-symbols' is not supported for modules"
      exit 1
    fi
    
1078
    oldlibs=
1079 1080 1081
    # calculate the name of the file, without its directory
    outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'`

Elliot Lee's avatar
Elliot Lee committed
1082 1083
    case "$output" in
    "")
1084
      $echo "$modename: you must specify an output file" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1085 1086 1087 1088
      $echo "$help" 1>&2
      exit 1
      ;;

1089
    *.a | *.lib)
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
      if test -n "$link_against_libtool_libs"; then
        $echo "$modename: error: cannot link libtool libraries into archives" 1>&2
        exit 1
      fi

      if test -n "$deplibs"; then
        $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2
      fi

      if test -n "$dlfiles$dlprefiles"; then
        $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2
      fi

      if test -n "$rpath"; then
        $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2
      fi

      if test -n "$vinfo"; then
        $echo "$modename: warning: \`-version-info' is ignored for archives" 1>&2
      fi

      if test -n "$release"; then
        $echo "$modename: warning: \`-release' is ignored for archives" 1>&2
      fi

1115 1116 1117 1118
      if test -n "$export_symbols"; then
        $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2
      fi

1119 1120
      # Now set the variables for building old libraries.
      build_libtool_libs=no
1121
      oldlibs="$output"
1122 1123
      ;;

Elliot Lee's avatar
Elliot Lee committed
1124 1125
    *.la)
      # Make sure we only generate libraries of the form `libNAME.la'.
1126
      case "$outputname" in
Elliot Lee's avatar
Elliot Lee committed
1127 1128
      lib*) ;;
      *)
1129
	$echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1130 1131 1132 1133 1134
	$echo "$help" 1>&2
	exit 1
	;;
      esac

1135
      name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
1136
      eval libname=\"$libname_spec\"
Elliot Lee's avatar
Elliot Lee committed
1137

1138 1139 1140 1141 1142 1143 1144
      output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'`
      if test "X$output_objdir" = "X$output"; then
        output_objdir="$objdir"
      else
        output_objdir="$output_objdir/$objdir"
      fi

Elliot Lee's avatar
Elliot Lee committed
1145 1146 1147 1148 1149 1150
      # All the library-specific variables (install_libdir is set above).
      library_names=
      old_library=
      dlname=

      if test -n "$objs"; then
1151
        $echo "$modename: cannot build libtool library \`$output' from non-libtool objects:$objs" 2>&1
Elliot Lee's avatar
Elliot Lee committed
1152 1153 1154 1155 1156
        exit 1
      fi

      # How the heck are we supposed to write a wrapper for a shared library?
      if test -n "$link_against_libtool_libs"; then
1157
        $echo "$modename: error: cannot link shared libraries into libtool libraries" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1158 1159 1160 1161
        exit 1
      fi

      if test -n "$dlfiles$dlprefiles"; then
1162
        $echo "$modename: warning: \`-dlopen' is ignored for libtool libraries" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1163 1164 1165 1166
      fi

      set dummy $rpath
      if test $# -gt 2; then
1167
	$echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1168 1169 1170
      fi
      install_libdir="$2"

1171
      oldlibs=
1172 1173
      if test -z "$rpath"; then
	# Building a libtool convenience library.
1174 1175
        libext=al
	oldlibs="$output_objdir/$libname.$libext $oldlibs"
1176
	build_libtool_libs=convenience
1177
	dependency_libs="$deplibs"
Elliot Lee's avatar
Elliot Lee committed
1178

1179 1180 1181
	if test -n "$vinfo"; then
	  $echo "$modename: warning: \`-version-info' is ignored for convenience libraries" 1>&2
	fi
Elliot Lee's avatar
Elliot Lee committed
1182

1183 1184 1185 1186
	if test -n "$release"; then
	  $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2
	fi
      else
Elliot Lee's avatar
Elliot Lee committed
1187

1188 1189 1190 1191
	# Parse the version information argument.
	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=':'
	set dummy $vinfo 0 0 0
	IFS="$save_ifs"
Elliot Lee's avatar
Elliot Lee committed
1192

1193 1194 1195 1196 1197
	if test -n "$8"; then
	  $echo "$modename: too many parameters to \`-version-info'" 1>&2
	  $echo "$help" 1>&2
	  exit 1
	fi
Elliot Lee's avatar
Elliot Lee committed
1198

1199 1200 1201
	current="$2"
	revision="$3"
	age="$4"
Elliot Lee's avatar
Elliot Lee committed
1202

1203 1204 1205 1206 1207 1208 1209 1210 1211
	# Check that each of the things are valid numbers.
	case "$current" in
	0 | [1-9] | [1-9][0-9]*) ;;
	*)
	  $echo "$modename: CURRENT \`$current' is not a nonnegative integer" 1>&2
	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
	  exit 1
	  ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
1212

1213 1214 1215 1216 1217 1218 1219 1220
	case "$revision" in
	0 | [1-9] | [1-9][0-9]*) ;;
	*)
	  $echo "$modename: REVISION \`$revision' is not a nonnegative integer" 1>&2
	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
	  exit 1
	  ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
1221

1222 1223 1224 1225 1226 1227 1228 1229
	case "$age" in
	0 | [1-9] | [1-9][0-9]*) ;;
	*)
	  $echo "$modename: AGE \`$age' is not a nonnegative integer" 1>&2
	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
	  exit 1
	  ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
1230

1231 1232 1233 1234 1235
	if test $age -gt $current; then
	  $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2
	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
	  exit 1
	fi
Elliot Lee's avatar
Elliot Lee committed
1236

1237 1238 1239 1240 1241 1242
	# Calculate the version variables.
	major=
	versuffix=
	verstring=
	case "$version_type" in
	none) ;;
Elliot Lee's avatar
Elliot Lee committed
1243

1244 1245 1246 1247
	linux)
	  major=.`expr $current - $age`
	  versuffix="$major.$age.$revision"
	  ;;
Elliot Lee's avatar
Elliot Lee committed
1248

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
	osf)
	  major=`expr $current - $age`
	  versuffix=".$current.$age.$revision"
	  verstring="$current.$age.$revision"

	  # Add in all the interfaces that we are compatible with.
	  loop=$age
	  while test $loop != 0; do
	    iface=`expr $current - $loop`
	    loop=`expr $loop - 1`
	    verstring="$verstring:${iface}.0"
	  done

	  # Make executables depend on our current version.
	  verstring="$verstring:${current}.0"
	  ;;

	sunos)
	  major=".$current"
	  versuffix=".$current.$revision"
	  ;;

1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
	freebsd-aout)
	  major=".$current"
	  versuffix=".$current.$revision";
	  ;;

	freebsd-elf)
	  major=".$current"
	  versuffix=".$current";
	  ;;

	windows)
	  # Like Linux, but with '-' rather than '.', since we only
	  # want one extension on Windows 95.
	  major=`expr $current - $age`
	  versuffix="-$major-$age-$revision"
	  ;;

1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
	*)
	  $echo "$modename: unknown library version type \`$version_type'" 1>&2
	  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
	  exit 1
	  ;;
	esac

	# Clear the version info if we defaulted, and they specified a release.
	if test -z "$vinfo" && test -n "$release"; then
	  major=
	  versuffix=
	  verstring="0.0"
1300 1301 1302 1303 1304
	  case "$host" in
	  *-*-sunos*)
	    versuffix=".0.0"
	    ;;
	  esac
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
	fi

	# Check to see if the archive will have undefined symbols.
	if test "$allow_undefined" = yes; then
	  if test "$allow_undefined_flag" = unsupported; then
	    $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2
	    build_libtool_libs=no
	    build_old_libs=yes
	  fi
	else
	  # Don't allow undefined symbols.
	  allow_undefined_flag="$no_undefined_flag"
	fi

	# Add libc to deplibs on all systems.
	dependency_libs="$deplibs"
	deplibs="$deplibs -lc"
      fi
Elliot Lee's avatar
Elliot Lee committed
1323 1324

      # Create the output directory, or remove our outputs if we need to.
1325 1326 1327
      if test -d $output_objdir; then
        $show "${rm}r $output_objdir/$outputname $output_objdir/$libname.* $output_objdir/${libname}${release}.*"
	$run ${rm}r $output_objdir/$outputname $output_objdir/$libname.* $output_objdir/${libname}${release}.*
Elliot Lee's avatar
Elliot Lee committed
1328
      else
1329 1330
        $show "$mkdir $output_objdir"
        $run $mkdir $output_objdir
1331
        status=$?
1332
        if test $status -ne 0 && test ! -d $output_objdir; then
1333
          exit $status
Elliot Lee's avatar
Elliot Lee committed
1334 1335 1336
        fi
      fi

1337 1338
      # Now set the variables for building old libraries.
      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
1339
	oldlibs="$oldlibs $output_objdir/$libname.$libext"
1340 1341

	# Transform .lo files to .o files.
1342
	oldobjs="$objs"`$echo "X$libobjs " | $Xsed -e 's/[^   ]*\.'${libext}' //g' -e "$los2o" -e 's/ $//g'`
1343 1344
      fi

Elliot Lee's avatar
Elliot Lee committed
1345
      if test "$build_libtool_libs" = yes; then
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
        # Transform deplibs into only deplibs that can be linked in shared.
        ## Gordon: Do you check for the existence of the libraries in deplibs
        ## on the system?  That should maybe be merged in here someplace....
        ## Actually: I think test_compile and file_magic do this... file_regex
        ## sorta does this. Only pas_all needs to be changed.  -Toshio
        name_save=$name
        libname_save=$libname
        release_save=$release
        versuffix_save=$versuffix
        major_save=$major
        # I'm not sure if I'm treating the release correctly.  I think
        # release should show up in the -l (ie -lgmp5) so we don't want to
        # add it in twice.  Is that correct?
        release=""
        versuffix=""
        major=""
        newdeplibs=
        case "$check_shared_deplibs_method" in
        pass_all)  
          newdeplibs=$deplibs 
                    ;; # Don't check for shared/static.  Everything works.
                       # This might be a little naive.  We might want to check
                       # whether the library exists or not.  But this is on
                       # osf3 & osf4 and I'm not really sure... Just
                       # implementing what was already the behaviour.
        test_compile)
          # This code stresses the "libraries are programs" paradigm to its
          # limits. Maybe even breaks it.  We compile a program, linking it
          # against the deplibs as a proxy for the library.  Then we can check
          # whether they linked in statically or dynamically with ldd.
          $rm conftest.c
          cat > conftest.c <<EOF
          int main() { return 0; }
EOF
          $rm a.out
          $C_compiler conftest.c $deplibs
          if test $? -eq 0 ; then
            ldd_output=`ldd a.out`
            for i in $deplibs; do
              name="`expr $i : '-l\(.*\)'`"
              # If $name is empty we are operating on a -L argument.
              if test "$name" != "" ; then
                libname=`eval \\$echo \"$libname_spec\"`
                deplib_matches=`eval \\$echo \"$library_names_spec\"`
                set dummy $deplib_matches
                deplib_match=$2
                if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
                  newdeplibs="$newdeplibs $i"
                else
                  echo
                  echo "*** Warning: This library needs some functionality provided by $i."
                  echo "*** I have the capability to make that library automatically link in when"
                  echo "*** you link to this library.  But I can only do this if you have a"
                  echo "*** shared version of the library, which you do not appear to have."
                fi
              else
                newdeplibs="$newdeplibs $i"
              fi
            done
          else
            # Error occured in the first compile.  Let's try to salvage the situation:
            # Compile a seperate program for each library.
            for i in $deplibs; do
              name="`expr $i : '-l\(.*\)'`"
             # If $name is empty we are operating on a -L argument.
              if test "$name" != "" ; then
                $rm a.out
                $C_compiler conftest.c $i
                # Did it work?
                if test $? -eq 0 ; then
                  ldd_output=`ldd a.out`
                    libname=`eval \\$echo \"$libname_spec\"`
                    deplib_matches=`eval \\$echo \"$library_names_spec\"`
                    set dummy $deplib_matches
                    deplib_match=$2
                    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
                      newdeplibs="$newdeplibs $i"
                    else
                      echo
                      echo "*** Warning: This library needs some functionality provided by $i."
                      echo "*** I have the capability to make that library automatically link in when"
                      echo "*** you link to this library.  But I can only do this if you have a"
                      echo "*** shared version of the library, which you do not appear to have."
                    fi
                else
                  echo
                  echo "*** Warning!  Library $i is needed by this library but I was not able to"
                  echo "***  make it link in!  You will probably need to install it or some"
                  echo "*** library that it depends on before this library will be fully"
                  echo "*** functional.  Installing it before continuing would be even better."
                fi
              else
                newdeplibs="$newdeplibs $i"
              fi
            done
          fi
          deplibs=$newdeplibs
          ;;
        file_magic* | file_regex)
          set dummy $check_shared_deplibs_method
          file_magic_regex="`expr \"$check_shared_deplibs_method\" : \"$2\(.*\)\"`"
          for a_deplib in $deplibs; do
            name="`expr $a_deplib : '-l\(.*\)'`"
            # If $name is empty we are operating on a -L argument.
            if test "$name" != "" ; then
              libname=`eval \\$echo \"$libname_spec\"`
              case "$check_shared_deplibs_method" in
                file_magic*)
                  for i in $lib_search_path; do
                   # This needs to be more general than file_regex in order to
                   # catch things like glibc on linux.  Maybe file_regex
                   # should be more general as well, but maybe not.  Since
                   # library names are supposed to conform to
                   # library_name_spec, I think file_regex should remain
                   # strict.  What do you think Gordon?
                    potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
                    for potent_lib in $potential_libs; do
                      file_output=`file $potent_lib`
                      if test `expr "$file_output" : ".*$file_magic_regex"` -ne 0 ; then
                        newdeplibs="$newdeplibs $a_deplib"
                        a_deplib=""
                        break 2
                      fi
                    done
                  done
                  ;;
                file_regex)
                  deplib_matches=`eval \\$echo \"$library_names_spec\"`
                  set dummy $deplib_matches
                  deplib_match=$2
                  for i in $lib_search_path; do
                    potential_libs=`ls $i/$deplib_match* 2>/dev/null`
                    if test "$potential_libs" != "" ; then
                      newdeplibs="$newdeplibs $a_deplib"
                      a_deplib=""
                      break
                    fi
                  done
                  ;;
              esac
              if test "$a_deplib" != "" ; then
                echo
                echo "*** Warning: This library needs some functionality provided by $a_deplib."
                echo "*** I have the capability to make that library automatically link in when"
                echo "*** you link to this library.  But I can only do this if you have a"
                echo "*** shared version of the library, which you do not appear to have."
              fi
            else
              # Add a -L argument.
              newdeplibs="$newdeplibs $a_deplib"
            fi
          done # Gone through all deplibs.
          ;;
        none | *)  deplibs="" ;;
        esac
        versuffix=$versuffix_save
        major=$major_save
        release=$release_save
        libname=$libname_save
        name=$name_save
        deplibs=$newdeplibs
        # Done checking deplibs!
 
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
	# Get the real and link names of the library.
	eval library_names=\"$library_names_spec\"
	set dummy $library_names
	realname="$2"
	shift; shift

	if test -n "$soname_spec"; then
	  eval soname=\"$soname_spec\"
	else
	  soname="$realname"
	fi
Elliot Lee's avatar
Elliot Lee committed
1520

1521
	lib="$output_objdir/$realname"
Elliot Lee's avatar
Elliot Lee committed
1522 1523 1524 1525 1526
	for link
	do
	  linknames="$linknames $link"
	done

1527
	# Use standard objects if they are PIC.
1528
	test -z "$pic_flag" && libobjs=`$echo "X$libobjs " | $Xsed -e "$los2o" -e 's/ $//g'`
Elliot Lee's avatar
Elliot Lee committed
1529

1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
	if test -n "$whole_archive_flag_spec"; then
	  if test -n "$convenience"; then
	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
	  fi
	else
	  for xlib in $convenience; do
	    # Extract the objects.
	    xdir="$xlib"x
	    generated="$generated $xdir"
	    xlib=`echo "$xlib" | $Xsed -e 's%^.*/%%'`

	    $show "${rm}r $xdir"
	    $run ${rm}r "$xdir"
	    $show "mkdir $xdir"
	    $run mkdir "$xdir"
	    status=$?
	    if test $status -ne 0 && test ! -d "$xdir"; then
	      exit $status
	    fi
	    $show "(cd $xdir && $AR x ../$xlib)"
	    $run eval "(cd \$xdir && $AR x ../\$xlib)" || exit $?
Elliot Lee's avatar
Elliot Lee committed
1551

1552 1553 1554
	    libobjs="$libobjs `echo $xdir/*`"
	  done
	fi
1555

1556
	# Do each of the archive commands.
1557 1558 1559 1560 1561 1562
	if test -n "$export_symbols" && test -n "$archive_sym_cmds"; then
	  eval cmds=\"$archive_sym_cmds\"
	else
	  eval cmds=\"$archive_cmds\"
	fi
	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
	for cmd in $cmds; do
	  IFS="$save_ifs"
	  $show "$cmd"
	  $run eval "$cmd" || exit $?
	done
	IFS="$save_ifs"

	# Create links to the real library.
	for linkname in $linknames; do
	  if test "$realname" != "$linkname"; then
1573 1574
	    $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)"
	    $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $?
1575 1576 1577
	  fi
	done

1578 1579
	# If -module or -export-dynamic was specified, set the dlname.
	if test "$module" = yes || test "$export_dynamic" = yes; then
1580 1581 1582 1583
	  # On all known operating systems, these are identical.
	  dlname="$soname"
	fi
      fi
Elliot Lee's avatar
Elliot Lee committed
1584 1585
      ;;

1586
    *.lo | *.o | *.obj)
Elliot Lee's avatar
Elliot Lee committed
1587
      if test -n "$link_against_libtool_libs"; then
1588
        $echo "$modename: error: cannot link libtool libraries into objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1589 1590 1591 1592
        exit 1
      fi

      if test -n "$deplibs"; then
1593
        $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1594 1595 1596
      fi

      if test -n "$dlfiles$dlprefiles"; then
1597
        $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1598 1599 1600
      fi

      if test -n "$rpath"; then
1601
        $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1602 1603 1604
      fi

      if test -n "$vinfo"; then
1605
        $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2
1606 1607 1608
      fi

      if test -n "$release"; then
1609
        $echo "$modename: warning: \`-release' is ignored for objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1610 1611 1612 1613 1614
      fi

      case "$output" in
      *.lo)
        if test -n "$objs"; then
1615
          $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1616 1617 1618
          exit 1
        fi
        libobj="$output"
1619
        obj=`$echo "X$output" | $Xsed -e "$lo2o"`
Elliot Lee's avatar
Elliot Lee committed
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
        ;;
      *)
        libobj=
        obj="$output"
        ;;
      esac

      # Delete the old objects.
      $run $rm $obj $libobj

      # Create the old-style object.
1631
      reload_objs="$objs"`$echo "X$libobjs " | $Xsed -e 's/[^       ]*\.'${libext}' //g' -e 's/[^       ]*\.lib //g' -e "$los2o" -e 's/ $//g'`
Elliot Lee's avatar
Elliot Lee committed
1632 1633

      output="$obj"
1634
      eval cmds=\"$reload_cmds\"
1635
      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
Elliot Lee's avatar
Elliot Lee committed
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
      for cmd in $cmds; do
        IFS="$save_ifs"
        $show "$cmd"
        $run eval "$cmd" || exit $?
      done
      IFS="$save_ifs"

      # Exit if we aren't doing a library object file.
      test -z "$libobj" && exit 0

      if test "$build_libtool_libs" != yes; then
        # Create an invalid libtool object if no PIC, so that we don't
        # accidentally link it into a program.
1649 1650
        $show "echo timestamp > $libobj"
        $run eval "echo timestamp > $libobj" || exit $?
Elliot Lee's avatar
Elliot Lee committed
1651 1652 1653 1654 1655 1656 1657
        exit 0
      fi

      if test -n "$pic_flag"; then
        # Only do commands if we really have different PIC objects.
        reload_objs="$libobjs"
        output="$libobj"
1658
        eval cmds=\"$reload_cmds\"
1659
        IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
Elliot Lee's avatar
Elliot Lee committed
1660 1661 1662 1663 1664 1665 1666 1667 1668
        for cmd in $cmds; do
          IFS="$save_ifs"
          $show "$cmd"
          $run eval "$cmd" || exit $?
        done
        IFS="$save_ifs"
      else
        # Just create a symlink.
        $show "$LN_S $obj $libobj"
1669
        $run $LN_S $obj $libobj || exit $?
Elliot Lee's avatar
Elliot Lee committed
1670 1671 1672 1673 1674
      fi

      exit 0
      ;;

1675
    # Anything else should be a program.
Elliot Lee's avatar
Elliot Lee committed
1676 1677
    *)
      if test -n "$vinfo"; then
1678
        $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2
1679 1680 1681
      fi

      if test -n "$release"; then
1682
        $echo "$modename: warning: \`-release' is ignored for programs" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
      fi

      if test -n "$rpath"; then
	# If the user specified any rpath flags, then add them.
	for libdir in $rpath; do
          if test -n "$hardcode_libdir_flag_spec"; then
            if test -n "$hardcode_libdir_separator"; then
              if test -z "$hardcode_libdirs"; then
                # Put the magic libdir with the hardcode flag.
                hardcode_libdirs="$libdir"
                libdir="@HARDCODE_LIBDIRS@"
              else
                # Just accumulate the unique libdirs.
		case "$hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator" in
		*"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
		  ;;
		*)
		  hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
		  ;;
		esac
                libdir=
              fi
            fi

            if test -n "$libdir"; then
1708
              eval flag=\"$hardcode_libdir_flag_spec\"
Elliot Lee's avatar
Elliot Lee committed
1709 1710 1711 1712

              compile_command="$compile_command $flag"
              finalize_command="$finalize_command $flag"
            fi
1713
          elif test -n "$runpath_var"; then
Elliot Lee's avatar
Elliot Lee committed
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
            case "$perm_rpath " in
            *" $libdir "*) ;;
            *) perm_rpath="$perm_rpath $libdir" ;;
            esac
          fi
	done
      fi

      # Substitute the hardcoded libdirs into the compile commands.
      if test -n "$hardcode_libdir_separator"; then
1724 1725
	compile_command=`$echo "X$compile_command" | $Xsed -e "s%@HARDCODE_LIBDIRS@%$hardcode_libdirs%g"`
	finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@HARDCODE_LIBDIRS@%$hardcode_libdirs%g"`
Elliot Lee's avatar
Elliot Lee committed
1726 1727
      fi

1728 1729 1730 1731 1732 1733 1734
      output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'`
      if test "X$output_objdir" = "X$output"; then
        output_objdir="$objdir"
      else
        output_objdir="$output_objdir/$objdir"
      fi

Elliot Lee's avatar
Elliot Lee committed
1735 1736
      if test -n "$libobjs" && test "$build_old_libs" = yes; then
        # Transform all the library objects into standard objects.
1737 1738
        compile_command=`$echo "X$compile_command " | $Xsed -e "$los2o" -e 's/ $//'`
        finalize_command=`$echo "X$finalize_command " | $Xsed -e "$los2o" -e 's/ $//'`
Elliot Lee's avatar
Elliot Lee committed
1739 1740 1741
      fi

      if test "$export_dynamic" = yes && test -n "$NM" && test -n "$global_symbol_pipe"; then
1742
        dlsyms="${outputname}S.c"
Elliot Lee's avatar
Elliot Lee committed
1743 1744 1745 1746 1747
      else
        dlsyms=
      fi

      if test -n "$dlsyms"; then
1748 1749 1750 1751 1752 1753 1754
        case "$dlsyms" in
        "") ;;
        *.c)
          if test -z "$export_symbols"; then
            # Add our own program objects to the preloaded list.
            dlprefiles=`$echo "X$objs$dlprefiles " | $Xsed -e "$los2o" -e 's/ $//'`
          fi
Elliot Lee's avatar
Elliot Lee committed
1755

1756 1757
          # Discover the nlist of each of the dlfiles.
          nlist="$objdir/${output}.nm"
Elliot Lee's avatar
Elliot Lee committed
1758

1759 1760 1761
	  if test -d $objdir; then
	    $show "$rm $nlist ${nlist}T"
	    $run $rm "$nlist" "${nlist}T"
Elliot Lee's avatar
Elliot Lee committed
1762
	  else
1763 1764 1765 1766 1767 1768
	    $show "$mkdir $objdir"
	    $run $mkdir $objdir
	    status=$?
	    if test $status -ne 0 && test ! -d $objdir; then
	      exit $status
	    fi
Elliot Lee's avatar
Elliot Lee committed
1769 1770
	  fi