ltmain.sh 108 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
# ltmain.sh - Provide generalized library-building support services.
Manish Singh's avatar
Manish Singh committed
2 3
# NOTE: Changing this file will not affect anything until you rerun ltconfig.
#
4
# Copyright (C) 1996-1999 Free Software Foundation, Inc.
Manish Singh's avatar
Manish Singh committed
5
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# 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.

Manish Singh's avatar
Manish Singh committed
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
elif test "X$1" = X--fallback-echo; then
Manish Singh's avatar
Manish Singh committed
31 32
  # Avoid inline document here, it may be left over
  :
Manish Singh's avatar
Manish Singh committed
33 34 35 36 37 38 39 40
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

Manish Singh's avatar
Manish Singh committed
41 42 43 44 45 46 47 48 49
if test "X$1" = X--fallback-echo; then
  # used as fallback echo
  shift
  cat <<EOF
$*
EOF
  exit 0
fi

Elliot Lee's avatar
Elliot Lee committed
50 51
# The name of this program.
progname=`$echo "$0" | sed 's%^.*/%%'`
Manish Singh's avatar
Manish Singh committed
52
modename="$progname"
Elliot Lee's avatar
Elliot Lee committed
53 54 55 56

# Constants.
PROGRAM=ltmain.sh
PACKAGE=libtool
57 58
VERSION=1.3.4
TIMESTAMP=" (1.385.2.196 1999/12/07 21:47:57)"
Elliot Lee's avatar
Elliot Lee committed
59 60 61 62 63 64 65 66 67 68

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.
69
Xsed='sed -e 1s/^X//'
Manish Singh's avatar
Manish Singh committed
70
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
71
SP2NL='tr \040 \012'
Manish Singh's avatar
Manish Singh committed
72
NL2SP='tr \015\012 \040\040'
Elliot Lee's avatar
Elliot Lee committed
73 74 75 76 77

# 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).
Manish Singh's avatar
Manish Singh committed
78 79 80 81 82 83 84
# 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
85 86

if test "$LTCONFIG_VERSION" != "$VERSION"; then
Manish Singh's avatar
Manish Singh committed
87 88
  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
89 90 91 92
  exit 1
fi

if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
Manish Singh's avatar
Manish Singh committed
93 94
  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
95 96 97 98 99 100 101 102 103 104 105 106
  exit 1
fi

# Global variables.
mode=$default_mode
nonopt=
prev=
prevopt=
run=
show="$echo"
show_help=
execute_dlfiles=
107
lo2o="s/\\.lo\$/.${objext}/"
Manish Singh's avatar
Manish Singh committed
108
o2lo="s/\\.${objext}\$/.lo/"
Elliot Lee's avatar
Elliot Lee committed
109 110 111 112 113 114 115 116

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

  case "$arg" in
Manish Singh's avatar
Manish Singh committed
117
  -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;;
Elliot Lee's avatar
Elliot Lee committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  *) 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)
144
    echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP"
Elliot Lee's avatar
Elliot Lee committed
145 146 147
    exit 0
    ;;

Manish Singh's avatar
Manish Singh committed
148 149 150 151 152 153 154 155 156 157
  --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
158 159 160 161 162
  --dry-run | -n)
    run=:
    ;;

  --features)
Manish Singh's avatar
Manish Singh committed
163
    echo "host: $host"
Elliot Lee's avatar
Elliot Lee committed
164
    if test "$build_libtool_libs" = yes; then
Manish Singh's avatar
Manish Singh committed
165
      echo "enable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
166
    else
Manish Singh's avatar
Manish Singh committed
167
      echo "disable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
168 169
    fi
    if test "$build_old_libs" = yes; then
Manish Singh's avatar
Manish Singh committed
170
      echo "enable static libraries"
Elliot Lee's avatar
Elliot Lee committed
171
    else
Manish Singh's avatar
Manish Singh committed
172
      echo "disable static libraries"
Elliot Lee's avatar
Elliot Lee committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    fi
    exit 0
    ;;

  --finish) mode="finish" ;;

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

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

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

  -*)
Manish Singh's avatar
Manish Singh committed
192
    $echo "$modename: unrecognized option \`$arg'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
193 194 195 196 197 198 199 200 201 202 203 204
    $echo "$help" 1>&2
    exit 1
    ;;

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

if test -n "$prevopt"; then
Manish Singh's avatar
Manish Singh committed
205
  $echo "$modename: option \`$prevopt' requires an argument" 1>&2
Elliot Lee's avatar
Elliot Lee committed
206 207 208 209 210 211 212 213 214
  $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
Manish Singh's avatar
Manish Singh committed
215
    *cc | *++ | gcc* | *-gcc*)
Elliot Lee's avatar
Elliot Lee committed
216 217 218
      mode=link
      for arg
      do
219 220 221 222 223 224
	case "$arg" in
	-c)
	   mode=compile
	   break
	   ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
225 226
      done
      ;;
Manish Singh's avatar
Manish Singh committed
227
    *db | *dbx | *strace | *truss)
Elliot Lee's avatar
Elliot Lee committed
228 229
      mode=execute
      ;;
Manish Singh's avatar
Manish Singh committed
230
    *install*|cp|mv)
Elliot Lee's avatar
Elliot Lee committed
231 232 233 234 235 236 237 238 239 240 241
      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
242 243 244 245 246
	if test -n "$nonopt"; then
	  $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2
	else
	  $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2
	fi
Elliot Lee's avatar
Elliot Lee committed
247 248 249 250 251 252 253
      fi
      ;;
    esac
  fi

  # Only execute mode is allowed to have -dlopen flags.
  if test -n "$execute_dlfiles" && test "$mode" != execute; then
Manish Singh's avatar
Manish Singh committed
254
    $echo "$modename: unrecognized option \`-dlopen'" 1>&2
Elliot Lee's avatar
Elliot Lee committed
255 256 257 258 259 260
    $echo "$help" 1>&2
    exit 1
  fi

  # Change the help message to a mode-specific one.
  generic_help="$help"
Manish Singh's avatar
Manish Singh committed
261
  help="Try \`$modename --help --mode=$mode' for more information."
Elliot Lee's avatar
Elliot Lee committed
262 263 264 265 266

  # These modes are in order of execution frequency so that they run quickly.
  case "$mode" in
  # libtool compile mode
  compile)
Manish Singh's avatar
Manish Singh committed
267
    modename="$modename: compile"
Elliot Lee's avatar
Elliot Lee committed
268 269 270 271 272 273
    # Get the compilation command and the source file.
    base_compile=
    lastarg=
    srcfile="$nonopt"
    suppress_output=

274
    user_target=no
Elliot Lee's avatar
Elliot Lee committed
275 276
    for arg
    do
Manish Singh's avatar
Manish Singh committed
277 278 279
      # Accept any command-line options.
      case "$arg" in
      -o)
280 281
	if test "$user_target" != "no"; then
	  $echo "$modename: you cannot specify \`-o' more than once" 1>&2
282
	  exit 1
283 284
	fi
	user_target=next
Manish Singh's avatar
Manish Singh committed
285 286 287
	;;

      -static)
288 289 290
	build_old_libs=yes
	continue
	;;
291 292 293 294
      esac

      case "$user_target" in
      next)
295 296 297 298
	# The next one is the -o target name
	user_target=yes
	continue
	;;
299
      yes)
300 301 302 303 304
	# We got the output file
	user_target=set
	libobj="$arg"
	continue
	;;
Manish Singh's avatar
Manish Singh committed
305
      esac
Elliot Lee's avatar
Elliot Lee committed
306 307 308 309 310 311 312 313 314 315

      # 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.
Manish Singh's avatar
Manish Singh committed
316
      lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
317 318 319 320 321 322

      # 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
      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
323 324
	lastarg="\"$lastarg\""
	;;
Elliot Lee's avatar
Elliot Lee committed
325 326 327 328
      esac

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

335 336 337 338 339 340 341 342 343 344 345 346
    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
347 348

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

Manish Singh's avatar
Manish Singh committed
364
    libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
Elliot Lee's avatar
Elliot Lee committed
365 366

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

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

    # Delete any leftover library objects.
    if test "$build_old_libs" = yes; then
382
      removelist="$obj $libobj"
383
    else
384
      removelist="$libobj"
385 386 387 388 389 390 391 392 393 394 395 396
    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
397
    else
398 399 400 401 402 403 404 405
      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
406 407
	$show "Waiting for $lockfile to be removed"
	sleep 2
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
      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
430 431 432 433
    fi

    # Only build a PIC object if we are building libtool libraries.
    if test "$build_libtool_libs" = yes; then
Manish Singh's avatar
Manish Singh committed
434 435 436
      # Without this assignment, base_compile gets emptied.
      fbsd_hideous_sh_bug=$base_compile

Elliot Lee's avatar
Elliot Lee committed
437
      # All platforms use -DPIC, to notify preprocessed assembler code.
438
      command="$base_compile $srcfile $pic_flag -DPIC"
439
      if test "$build_old_libs" = yes; then
440
	lo_libobj="$libobj"
441 442 443 444 445 446
	dir=`$echo "X$libobj" | $Xsed -e 's%/[^/]*$%%'`
	if test "X$dir" = "X$libobj"; then
	  dir="$objdir"
	else
	  dir="$dir/$objdir"
	fi
447
	libobj="$dir/"`$echo "X$libobj" | $Xsed -e 's%^.*/%%'`
448 449 450 451 452 453 454 455 456 457 458 459 460

	if test -d "$dir"; then
	  $show "$rm $libobj"
	  $run $rm $libobj
	else
	  $show "$mkdir $dir"
	  $run $mkdir $dir
	  status=$?
	  if test $status -ne 0 && test ! -d $dir; then
	    exit $status
	  fi
	fi
      fi
461
      if test "$compiler_o_lo" = yes; then
462 463
	output_obj="$libobj"
	command="$command -o $output_obj"
464
      elif test "$compiler_c_o" = yes; then
465 466
	output_obj="$obj"
	command="$command -o $output_obj"
467 468
      fi

469
      $run $rm "$output_obj"
470 471
      $show "$command"
      if $run eval "$command"; then :
Elliot Lee's avatar
Elliot Lee committed
472
      else
473 474
	test -n "$output_obj" && $run $rm $removelist
	exit 1
Elliot Lee's avatar
Elliot Lee committed
475 476
      fi

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
      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
495 496
      fi

497
      # Just move the object if needed, then go on to compile the next one
498 499 500
      if test x"$output_obj" != x"$libobj"; then
	$show "$mv $output_obj $libobj"
	if $run $mv $output_obj $libobj; then :
501 502 503 504 505 506 507
	else
	  error=$?
	  $run $rm $removelist
	  exit $error
	fi
      fi

508 509 510
      # If we have no pic_flag, then copy the object into place and finish.
      if test -z "$pic_flag" && test "$build_old_libs" = yes; then
	# Rename the .lo from within objdir to obj
511
	if test -f $obj; then
512 513 514 515 516 517 518 519 520 521 522 523
	  $show $rm $obj
	  $run $rm $obj
	fi

	$show "$mv $libobj $obj"
	if $run $mv $libobj $obj; then :
	else
	  error=$?
	  $run $rm $removelist
	  exit $error
	fi

524 525 526 527 528 529 530 531
	xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
	if test "X$xdir" = "X$obj"; then
	  xdir="."
	else
	  xdir="$xdir"
	fi
	baseobj=`$echo "X$obj" | $Xsed -e "s%.*/%%"`
	libobj=`$echo "X$baseobj" | $Xsed -e "$o2lo"`
532
	# Now arrange that obj and lo_libobj become the same file
533 534
	$show "(cd $xdir && $LN_S $baseobj $libobj)"
	if $run eval '(cd $xdir && $LN_S $baseobj $libobj)'; then
535 536
	  exit 0
	else
537
	  error=$?
538 539 540 541
	  $run $rm $removelist
	  exit $error
	fi
      fi
Elliot Lee's avatar
Elliot Lee committed
542 543 544 545 546 547 548

      # 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
549 550
      command="$base_compile $srcfile"
      if test "$compiler_c_o" = yes; then
551 552
	command="$command -o $obj"
	output_obj="$obj"
553 554
      fi

Elliot Lee's avatar
Elliot Lee committed
555
      # Suppress compiler output if we already did a PIC compilation.
556
      command="$command$suppress_output"
557
      $run $rm "$output_obj"
558 559
      $show "$command"
      if $run eval "$command"; then :
Elliot Lee's avatar
Elliot Lee committed
560
      else
561 562
	$run $rm $removelist
	exit 1
Elliot Lee's avatar
Elliot Lee committed
563
      fi
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585

      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
586 587 588 589 590 591 592 593 594 595 596 597 598
      if 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

      # Create an invalid libtool object if no PIC, so that we do not
      # accidentally link it into a program.
      if test "$build_libtool_libs" != yes; then
599 600
	$show "echo timestamp > $libobj"
	$run eval "echo timestamp > \$libobj" || exit $?
601 602 603 604
      else
	# Move the .lo from within objdir
	$show "$mv $libobj $lo_libobj"
	if $run $mv $libobj $lo_libobj; then :
605 606 607 608 609 610 611 612 613 614 615
	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
616 617 618 619 620 621 622
    fi

    exit 0
    ;;

  # libtool link mode
  link)
Manish Singh's avatar
Manish Singh committed
623
    modename="$modename: link"
624
    case "$host" in
625
    *-*-cygwin* | *-*-mingw* | *-*-os2*)
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
      # It is impossible to link a dll without this setting, and
      # we shouldn't force the makefile maintainer to figure out
      # which system we are compiling for in order to pass an extra
      # flag for every libtool invokation.
      # allow_undefined=no

      # FIXME: Unfortunately, there are problems with the above when trying
      # to make a dll which has undefined symbols, in which case not
      # even a static library is built.  For now, we need to specify
      # -no-undefined on the libtool link line when we can be certain
      # that all symbols are satisfied, otherwise we get a static library.
      allow_undefined=yes

      # This is a source program that is used to create dlls on Windows
      # Don't remove nor modify the starting and closing comments
# /* ltdll.c starts here */
# #define WIN32_LEAN_AND_MEAN
# #include <windows.h>
# #undef WIN32_LEAN_AND_MEAN
# #include <stdio.h>
#
Manish Singh's avatar
Manish Singh committed
647 648 649 650 651 652
# #ifndef __CYGWIN__
# #  ifdef __CYGWIN32__
# #    define __CYGWIN__ __CYGWIN32__
# #  endif
# #endif
#
Manish Singh's avatar
Manish Singh committed
653 654 655
# #ifdef __cplusplus
# extern "C" {
# #endif
656
# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
Manish Singh's avatar
Manish Singh committed
657 658 659
# #ifdef __cplusplus
# }
# #endif
660
#
Manish Singh's avatar
Manish Singh committed
661
# #ifdef __CYGWIN__
662 663
# #include <cygwin/cygwin_dll.h>
# DECLARE_CYGWIN_DLL( DllMain );
Manish Singh's avatar
Manish Singh committed
664
# #endif
665 666 667 668 669 670 671 672 673
# HINSTANCE __hDllInstance_base;
#
# BOOL APIENTRY
# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
# {
#   __hDllInstance_base = hInst;
#   return TRUE;
# }
# /* ltdll.c ends here */
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
      # This is a source program that is used to create import libraries
      # on Windows for dlls which lack them. Don't remove nor modify the
      # starting and closing comments
# /* impgen.c starts here */
# /*   Copyright (C) 1999 Free Software Foundation, Inc.
# 
#  This file is part of GNU libtool.
# 
#  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.
#  */
# 
#  #include <stdio.h>		/* for printf() */
#  #include <unistd.h>		/* for open(), lseek(), read() */
#  #include <fcntl.h>		/* for O_RDONLY, O_BINARY */
#  #include <string.h>		/* for strdup() */
# 
#  static unsigned int
#  pe_get16 (fd, offset)
#       int fd;
#       int offset;
#  {
#    unsigned char b[2];
#    lseek (fd, offset, SEEK_SET);
#    read (fd, b, 2);
#    return b[0] + (b[1]<<8);
#  }
# 
#  static unsigned int
#  pe_get32 (fd, offset)
#      int fd;
#      int offset;
#  {
#    unsigned char b[4];
#    lseek (fd, offset, SEEK_SET);
#    read (fd, b, 4);
#    return b[0] + (b[1]<<8) + (b[2]<<16) + (b[3]<<24);
#  }
# 
#  static unsigned int
#  pe_as32 (ptr)
#       void *ptr;
#  {
#    unsigned char *b = ptr;
#    return b[0] + (b[1]<<8) + (b[2]<<16) + (b[3]<<24);
#  }
# 
#  int
#  main (argc, argv)
#      int argc;
#      char *argv[];
#  {
#      int dll;
#      unsigned long pe_header_offset, opthdr_ofs, num_entries, i;
#      unsigned long export_rva, export_size, nsections, secptr, expptr;
#      unsigned long name_rvas, nexp;
#      unsigned char *expdata, *erva;
#      char *filename, *dll_name;
# 
#      filename = argv[1];
# 
#      dll = open(filename, O_RDONLY|O_BINARY);
#      if (!dll)
#  	return 1;
# 
#      dll_name = filename;
#    
#      for (i=0; filename[i]; i++)
#  	if (filename[i] == '/' || filename[i] == '\\'  || filename[i] == ':')
#  	    dll_name = filename + i +1;
# 
#      pe_header_offset = pe_get32 (dll, 0x3c);
#      opthdr_ofs = pe_header_offset + 4 + 20;
#      num_entries = pe_get32 (dll, opthdr_ofs + 92);
# 
#      if (num_entries < 1) /* no exports */
#  	return 1;
# 
#      export_rva = pe_get32 (dll, opthdr_ofs + 96);
#      export_size = pe_get32 (dll, opthdr_ofs + 100);
#      nsections = pe_get16 (dll, pe_header_offset + 4 +2);
#      secptr = (pe_header_offset + 4 + 20 +
#  	      pe_get16 (dll, pe_header_offset + 4 + 16));
# 
#      expptr = 0;
#      for (i = 0; i < nsections; i++)
#      {
#  	char sname[8];
#  	unsigned long secptr1 = secptr + 40 * i;
#  	unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
#  	unsigned long vsize = pe_get32 (dll, secptr1 + 16);
#  	unsigned long fptr = pe_get32 (dll, secptr1 + 20);
#  	lseek(dll, secptr1, SEEK_SET);
#  	read(dll, sname, 8);
#  	if (vaddr <= export_rva && vaddr+vsize > export_rva)
#  	{
#  	    expptr = fptr + (export_rva - vaddr);
#  	    if (export_rva + export_size > vaddr + vsize)
#  		export_size = vsize - (export_rva - vaddr);
#  	    break;
#  	}
#      }
# 
#      expdata = (unsigned char*)malloc(export_size);
#      lseek (dll, expptr, SEEK_SET);
#      read (dll, expdata, export_size);
#      erva = expdata - export_rva;
# 
#      nexp = pe_as32 (expdata+24);
#      name_rvas = pe_as32 (expdata+32);
# 
#      printf ("EXPORTS\n");
#      for (i = 0; i<nexp; i++)
#      {
#  	unsigned long name_rva = pe_as32 (erva+name_rvas+i*4);
#  	printf ("\t%s @ %ld ;\n", erva+name_rva, 1+ i);
#      }
# 
#      return 0;
#  }
# /* impgen.c ends here */
806 807 808 809 810
      ;;
    *)
      allow_undefined=yes
      ;;
    esac
811 812
    compile_command="$nonopt"
    finalize_command="$nonopt"
Elliot Lee's avatar
Elliot Lee committed
813

814 815
    compile_rpath=
    finalize_rpath=
Elliot Lee's avatar
Elliot Lee committed
816 817
    compile_shlibpath=
    finalize_shlibpath=
Manish Singh's avatar
Manish Singh committed
818 819
    convenience=
    old_convenience=
Elliot Lee's avatar
Elliot Lee committed
820
    deplibs=
821 822 823 824 825 826
    linkopts=

    if test -n "$shlibpath_var"; then
      # get the directories listed in $shlibpath_var
      eval lib_search_path=\`\$echo \"X \${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
    else
827
      lib_search_path=
828 829 830
    fi
    # now prepend the system-specific ones
    eval lib_search_path=\"$sys_lib_search_path_spec\$lib_search_path\"
831
    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
832
    
833
    avoid_version=no
Elliot Lee's avatar
Elliot Lee committed
834 835
    dlfiles=
    dlprefiles=
836
    dlself=no
Elliot Lee's avatar
Elliot Lee committed
837
    export_dynamic=no
838
    export_symbols=
839
    export_symbols_regex=
Manish Singh's avatar
Manish Singh committed
840
    generated=
Elliot Lee's avatar
Elliot Lee committed
841 842 843
    libobjs=
    link_against_libtool_libs=
    ltlibs=
844
    module=no
Elliot Lee's avatar
Elliot Lee committed
845
    objs=
Manish Singh's avatar
Manish Singh committed
846
    prefer_static_libs=no
847
    preload=no
Elliot Lee's avatar
Elliot Lee committed
848 849
    prev=
    prevarg=
Manish Singh's avatar
Manish Singh committed
850
    release=
Elliot Lee's avatar
Elliot Lee committed
851
    rpath=
852
    xrpath=
Elliot Lee's avatar
Elliot Lee committed
853 854
    perm_rpath=
    temp_rpath=
855
    thread_safe=no
Elliot Lee's avatar
Elliot Lee committed
856 857 858 859 860 861 862
    vinfo=

    # We need to know -static, to get the right output filenames.
    for arg
    do
      case "$arg" in
      -all-static | -static)
Manish Singh's avatar
Manish Singh committed
863 864
	if test "X$arg" = "X-all-static"; then
	  if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
Manish Singh's avatar
Manish Singh committed
865
	    $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2
Manish Singh's avatar
Manish Singh committed
866 867 868 869 870 871 872 873
	  fi
	  if test -n "$link_static_flag"; then
	    dlopen_self=$dlopen_self_static
	  fi
	else
	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
	    dlopen_self=$dlopen_self_static
	  fi
874 875
	fi
	build_libtool_libs=no
Elliot Lee's avatar
Elliot Lee committed
876
	build_old_libs=yes
Manish Singh's avatar
Manish Singh committed
877
	prefer_static_libs=yes
878 879
	break
	;;
Elliot Lee's avatar
Elliot Lee committed
880 881 882
      esac
    done

Manish Singh's avatar
Manish Singh committed
883 884 885
    # See if our shared archives depend on static archives.
    test -n "$old_archive_from_new_cmds" && build_old_libs=yes

Elliot Lee's avatar
Elliot Lee committed
886
    # Go through the arguments, transforming them on the way.
Manish Singh's avatar
Manish Singh committed
887 888 889 890
    while test $# -gt 0; do
      arg="$1"
      shift

Elliot Lee's avatar
Elliot Lee committed
891 892
      # If the previous option needs an argument, assign it.
      if test -n "$prev"; then
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
	case "$prev" in
	output)
	  compile_command="$compile_command @OUTPUT@"
	  finalize_command="$finalize_command @OUTPUT@"
	  ;;
	esac

	case "$prev" in
	dlfiles|dlprefiles)
	  if test "$preload" = no; then
	    # Add the symbol object into the linking commands.
	    compile_command="$compile_command @SYMFILE@"
	    finalize_command="$finalize_command @SYMFILE@"
	    preload=yes
	  fi
	  case "$arg" in
	  *.la | *.lo) ;;  # We handle these cases below.
Manish Singh's avatar
Manish Singh committed
910 911 912 913 914 915 916 917
	  force)
	    if test "$dlself" = no; then
	      dlself=needless
	      export_dynamic=yes
	    fi
	    prev=
	    continue
	    ;;
918 919 920 921 922
	  self)
	    if test "$prev" = dlprefiles; then
	      dlself=yes
	    elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
	      dlself=yes
Manish Singh's avatar
Manish Singh committed
923 924 925
	    else
	      dlself=needless
	      export_dynamic=yes
926 927 928 929
	    fi
	    prev=
	    continue
	    ;;
930
	  *)
Manish Singh's avatar
Manish Singh committed
931 932 933 934 935
	    if test "$prev" = dlfiles; then
	      dlfiles="$dlfiles $arg"
	    else
	      dlprefiles="$dlprefiles $arg"
	    fi
936 937 938 939
	    prev=
	    ;;
	  esac
	  ;;
940
	expsyms)
941
	  export_symbols="$arg"
942 943 944 945
	  if test ! -f "$arg"; then
	    $echo "$modename: symbol file \`$arg' does not exist"
	    exit 1
	  fi
946
	  prev=
947 948 949 950 951 952
	  continue
	  ;;
	expsyms_regex)
	  export_symbols_regex="$arg"
	  prev=
	  continue
953
	  ;;
Manish Singh's avatar
Manish Singh committed
954 955 956 957 958
	release)
	  release="-$arg"
	  prev=
	  continue
	  ;;
Manish Singh's avatar
Manish Singh committed
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
	rpath | xrpath)
	  # We need an absolute path.
	  case "$arg" in
	  [\\/]* | [A-Za-z]:[\\/]*) ;;
	  *)
	    $echo "$modename: only absolute run-paths are allowed" 1>&2
	    exit 1
	    ;;
	  esac
	  if test "$prev" = rpath; then
	    case "$rpath " in
	    *" $arg "*) ;;
	    *) rpath="$rpath $arg" ;;
	    esac
	  else
	    case "$xrpath " in
	    *" $arg "*) ;;
	    *) xrpath="$xrpath $arg" ;;
	    esac
	  fi
979 980 981 982 983
	  prev=
	  continue
	  ;;
	*)
	  eval "$prev=\"\$arg\""
Elliot Lee's avatar
Elliot Lee committed
984 985 986
	  prev=
	  continue
	  ;;
987
	esac
Elliot Lee's avatar
Elliot Lee committed
988 989 990 991 992 993 994
      fi

      prevarg="$arg"

      case "$arg" in
      -all-static)
	if test -n "$link_static_flag"; then
995
	  compile_command="$compile_command $link_static_flag"
Elliot Lee's avatar
Elliot Lee committed
996
	  finalize_command="$finalize_command $link_static_flag"
997 998
	fi
	continue
Elliot Lee's avatar
Elliot Lee committed
999 1000 1001
	;;

      -allow-undefined)
Manish Singh's avatar
Manish Singh committed
1002 1003
	# 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
1004 1005 1006
	continue
	;;

1007 1008 1009 1010 1011
      -avoid-version)
	avoid_version=yes
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
1012
      -dlopen)
1013 1014 1015
	prev=dlfiles
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1016 1017

      -dlpreopen)
1018 1019 1020
	prev=dlprefiles
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1021 1022

      -export-dynamic)
Manish Singh's avatar
Manish Singh committed
1023 1024
	export_dynamic=yes
	continue
1025
	;;
Elliot Lee's avatar
Elliot Lee committed
1026

1027 1028
      -export-symbols | -export-symbols-regex)
	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
Manish Singh's avatar
Manish Singh committed
1029
	  $echo "$modename: not more than one -exported-symbols argument allowed"
1030 1031
	  exit 1
	fi
Manish Singh's avatar
Manish Singh committed
1032
	if test "X$arg" = "X-export-symbols"; then
1033 1034 1035 1036
	  prev=expsyms
	else
	  prev=expsyms_regex
	fi
1037
	continue
1038
	;;
1039

Elliot Lee's avatar
Elliot Lee committed
1040
      -L*)
Manish Singh's avatar
Manish Singh committed
1041 1042
	dir=`$echo "X$arg" | $Xsed -e 's/^-L//'`
	# We need an absolute path.
1043
	case "$dir" in
Manish Singh's avatar
Manish Singh committed
1044
	[\\/]* | [A-Za-z]:[\\/]*) ;;
1045
	*)
Manish Singh's avatar
Manish Singh committed
1046 1047
	  absdir=`cd "$dir" && pwd`
	  if test -z "$absdir"; then
1048 1049 1050
	    $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2
	    $echo "$modename: passing it literally to the linker, although it might fail" 1>&2
	    absdir="$dir"
Manish Singh's avatar
Manish Singh committed
1051 1052
	  fi
	  dir="$absdir"
1053 1054
	  ;;
	esac
1055 1056 1057 1058 1059 1060 1061 1062
	case " $deplibs " in
	*" $arg "*) ;;
	*) deplibs="$deplibs $arg";;
	esac
	case " $lib_search_path " in
	*" $dir "*) ;;
	*) lib_search_path="$lib_search_path $dir";;
	esac
1063
	case "$host" in
1064 1065 1066 1067 1068 1069 1070
	*-*-cygwin* | *-*-mingw* | *-*-os2*)
	  dllsearchdir=`cd "$dir" && pwd || echo "$dir"`
	  case ":$dllsearchpath:" in
	  ::) dllsearchpath="$dllsearchdir";;
	  *":$dllsearchdir:"*) ;;
	  *) dllsearchpath="$dllsearchpath:$dllsearchdir";;
	  esac
1071 1072 1073 1074 1075
	  ;;
	esac
	;;

      -l*)
Manish Singh's avatar
Manish Singh committed
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	if test "$arg" = "-lc"; then
	  case "$host" in
	  *-*-cygwin* | *-*-mingw* | *-*-os2* | *-*-beos*)
	    # These systems don't actually have c library (as such)
	    continue
	    ;;
	  esac
	elif test "$arg" = "-lm"; then
	  case "$host" in
	  *-*-cygwin* | *-*-beos*)
	    # These systems don't actually have math library (as such)
	    continue
	    ;;
	  esac
	fi
1091 1092
	deplibs="$deplibs $arg"
	;;
Elliot Lee's avatar
Elliot Lee committed
1093

1094
      -module)
Manish Singh's avatar
Manish Singh committed
1095 1096
	module=yes
	continue
1097
	;;
Manish Singh's avatar
Manish Singh committed
1098

Manish Singh's avatar
Manish Singh committed
1099 1100 1101 1102 1103
      -no-undefined)
	allow_undefined=no
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
1104 1105
      -o) prev=output ;;

Manish Singh's avatar
Manish Singh committed
1106 1107 1108 1109 1110
      -release)
	prev=release
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
1111
      -rpath)
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
	prev=rpath
	continue
	;;

      -R)
	prev=xrpath
	continue
	;;

      -R*)
Manish Singh's avatar
Manish Singh committed
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
	dir=`$echo "X$arg" | $Xsed -e 's/^-R//'`
	# We need an absolute path.
	case "$dir" in
	[\\/]* | [A-Za-z]:[\\/]*) ;;
	*)
	  $echo "$modename: only absolute run-paths are allowed" 1>&2
	  exit 1
	  ;;
	esac
	case "$xrpath " in
	*" $dir "*) ;;
	*) xrpath="$xrpath $dir" ;;
	esac
1135 1136
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1137 1138

      -static)
Manish Singh's avatar
Manish Singh committed
1139 1140
	# 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
1141
	  compile_command="$compile_command $link_static_flag"
Manish Singh's avatar
Manish Singh committed
1142
	  finalize_command="$finalize_command $link_static_flag"
1143 1144 1145 1146 1147 1148
	fi
	continue
	;;

      -thread-safe)
	thread_safe=yes
Elliot Lee's avatar
Elliot Lee committed
1149 1150 1151 1152
	continue
	;;

      -version-info)
1153 1154 1155
	prev=vinfo
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1156 1157

      # Some other compiler flag.
Manish Singh's avatar
Manish Singh committed
1158
      -* | +*)
Elliot Lee's avatar
Elliot Lee committed
1159 1160
	# Unknown arguments in both finalize_command and compile_command need
	# to be aesthetically quoted because they are evaled later.
Manish Singh's avatar
Manish Singh committed
1161
	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
1162 1163 1164 1165 1166
	case "$arg" in
	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
	  arg="\"$arg\""
	  ;;
	esac
1167
	;;
Elliot Lee's avatar
Elliot Lee committed
1168

1169
      *.o | *.obj | *.a | *.lib)
1170 1171 1172
	# A standard object.
	objs="$objs $arg"
	;;
Elliot Lee's avatar
Elliot Lee committed
1173 1174

      *.lo)
1175
	# A library object.
Elliot Lee's avatar
Elliot Lee committed
1176 1177
	if test "$prev" = dlfiles; then
	  dlfiles="$dlfiles $arg"
1178
	  if test "$build_libtool_libs" = yes && test "$dlopen" = yes; then
Elliot Lee's avatar
Elliot Lee committed
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
	    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.
1189
	  dlprefiles="$dlprefiles "`$echo "X$arg" | $Xsed -e "$lo2o"`
Elliot Lee's avatar
Elliot Lee committed
1190 1191 1192
	  prev=
	fi
	libobjs="$libobjs $arg"
1193
	;;
Elliot Lee's avatar
Elliot Lee committed
1194 1195

      *.la)
1196
	# A libtool-controlled library.
Elliot Lee's avatar
Elliot Lee committed
1197

1198 1199 1200 1201
	dlname=
	libdir=
	library_names=
	old_library=
Elliot Lee's avatar
Elliot Lee committed
1202

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

1210 1211 1212 1213
	# If the library was installed with an old release of libtool,
	# it will not redefine variable installed.
	installed=yes

Manish Singh's avatar
Manish Singh committed
1214
	# Read the .la file
1215 1216 1217 1218 1219
	# If there is no directory component, then add one.
	case "$arg" in
	*/* | *\\*) . $arg ;;
	*) . ./$arg ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
1220

1221 1222 1223 1224 1225
	# Get the name of the library we link against.
	linklib=
	for l in $old_library $library_names; do
	  linklib="$l"
	done
Elliot Lee's avatar
Elliot Lee committed
1226

1227 1228 1229 1230
	if test -z "$linklib"; then
	  $echo "$modename: cannot find name of link library for \`$arg'" 1>&2
	  exit 1
	fi
Elliot Lee's avatar
Elliot Lee committed
1231

1232 1233
	# Find the relevant object directory and library name.
	name=`$echo "X$arg" | $Xsed -e 's%^.*/%%' -e 's/\.la$//' -e 's/^lib//'`
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244

	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
1245

1246
	if test -n "$dependency_libs"; then
Manish Singh's avatar
Manish Singh committed
1247
	  # Extract -R and -L from dependency_libs
1248 1249 1250
	  temp_deplibs=
	  for deplib in $dependency_libs; do
	    case "$deplib" in
1251 1252 1253 1254 1255 1256 1257 1258
	    -R*) temp_xrpath=`$echo "X$deplib" | $Xsed -e 's/^-R//'`
		 case " $rpath $xrpath " in
		 *" $temp_xrpath "*) ;;
		 *) xrpath="$xrpath $temp_xrpath";;
		 esac;;
	    -L*) case "$compile_command $temp_deplibs " in
		 *" $deplib "*) ;;
		 *) temp_deplibs="$temp_deplibs $deplib";;
Manish Singh's avatar
Manish Singh committed
1259 1260 1261 1262 1263 1264 1265
		 esac
		 temp_dir=`$echo "X$deplib" | $Xsed -e 's/^-L//'`
		 case " $lib_search_path " in
		 *" $temp_dir "*) ;;
		 *) lib_search_path="$lib_search_path $temp_dir";;
		 esac
		 ;;
1266 1267 1268 1269 1270 1271 1272
	    *) temp_deplibs="$temp_deplibs $deplib";;
	    esac
	  done
	  dependency_libs="$temp_deplibs"
	fi

	if test -z "$libdir"; then
Manish Singh's avatar
Manish Singh committed
1273
	  # It is a libtool convenience library, so add in its objects.
1274
	  convenience="$convenience $dir/$old_library"
Manish Singh's avatar
Manish Singh committed
1275
	  old_convenience="$old_convenience $dir/$old_library"
1276 1277 1278
	  deplibs="$deplibs$dependency_libs"
	  compile_command="$compile_command $dir/$old_library$dependency_libs"
	  finalize_command="$finalize_command $dir/$old_library$dependency_libs"
Manish Singh's avatar
Manish Singh committed
1279 1280 1281
	  continue
	fi

1282 1283 1284
	# This library was specified with -dlopen.
	if test "$prev" = dlfiles; then
	  dlfiles="$dlfiles $arg"
1285 1286
	  if test -z "$dlname" || test "$dlopen" != yes || test "$build_libtool_libs" = no; then
	    # If there is no dlname, no dlopen support or we're linking statically,
1287 1288 1289 1290
	    # we need to preload.
	    prev=dlprefiles
	  else
	    # We should not create a dependency on this library, but we
Manish Singh's avatar
Manish Singh committed
1291 1292 1293
	    # may need any libraries it requires.
	    compile_command="$compile_command$dependency_libs"
	    finalize_command="$finalize_command$dependency_libs"
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
	    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

Manish Singh's avatar
Manish Singh committed
1311 1312
	if test -n "$library_names" &&
	   { test "$prefer_static_libs" = no || test -z "$old_library"; }; then
1313 1314 1315 1316 1317 1318 1319 1320
	  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
Elliot Lee's avatar
Elliot Lee committed
1321

1322 1323
	  # We need an absolute path.
	  case "$dir" in
Manish Singh's avatar
Manish Singh committed
1324
	  [\\/] | [A-Za-z]:[\\/]*) absdir="$dir" ;;
1325 1326 1327
	  *)
	    absdir=`cd "$dir" && pwd`
	    if test -z "$absdir"; then
1328 1329 1330
	      $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2
	      $echo "$modename: passing it literally to the linker, although it might fail" 1>&2
	      absdir="$dir"
1331
	    fi
1332 1333 1334 1335 1336 1337 1338
	    ;;
	  esac
	  
	  # This is the magic to use -rpath.
	  # Skip directories that are in the system default run-time
	  # search path, unless they have been requested with -R.
	  case " $sys_lib_dlsearch_path " in
Manish Singh's avatar
Manish Singh committed
1339
	  *" $absdir "*) ;;
1340 1341
	  *)
	    case "$compile_rpath " in
1342
	    *" $absdir "*) ;;
1343
	    *) compile_rpath="$compile_rpath $absdir" 
1344
	    esac
1345
	    ;;
Manish Singh's avatar
Manish Singh committed
1346
	  esac
1347 1348

	  case " $sys_lib_dlsearch_path " in
Manish Singh's avatar
Manish Singh committed
1349
	  *" $libdir "*) ;;
1350 1351
	  *)
	    case "$finalize_rpath " in
1352
	    *" $libdir "*) ;;
1353
	    *) finalize_rpath="$finalize_rpath $libdir"
1354
	    esac
1355
	    ;;
Manish Singh's avatar
Manish Singh committed
1356
	  esac
Elliot Lee's avatar
Elliot Lee committed
1357

Manish Singh's avatar
Manish Singh committed
1358
	  lib_linked=yes
1359 1360 1361 1362 1363 1364
	  case "$hardcode_action" in
	  immediate | unsupported)
	    if test "$hardcode_direct" = no; then
	      compile_command="$compile_command $dir/$linklib"
	      deplibs="$deplibs $dir/$linklib"
	      case "$host" in
1365
	      *-*-cygwin* | *-*-mingw* | *-*-os2*)
1366 1367 1368 1369 1370 1371 1372 1373 1374
		dllsearchdir=`cd "$dir" && pwd || echo "$dir"`
		if test -n "$dllsearchpath"; then
		  dllsearchpath="$dllsearchpath:$dllsearchdir"
		else
		  dllsearchpath="$dllsearchdir"
		fi
		;;
	      esac
	    elif test "$hardcode_minus_L" = no; then
1375 1376
	      case "$host" in
	      *-*-sunos*)
1377
		compile_shlibpath="$compile_shlibpath$dir:"
1378 1379
		;;
	      esac
1380 1381 1382 1383 1384
	      case "$compile_command " in
	      *" -L$dir "*) ;;
	      *) compile_command="$compile_command -L$dir";;
	      esac
	      compile_command="$compile_command -l$name"
1385 1386
	      deplibs="$deplibs -L$dir -l$name"
	    elif test "$hardcode_shlibpath_var" = no; then
1387 1388 1389 1390
	      case ":$compile_shlibpath:" in
	      *":$dir:"*) ;;
	      *) compile_shlibpath="$compile_shlibpath$dir:";;
	      esac
1391 1392
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -l$name"
Manish Singh's avatar
Manish Singh committed
1393 1394
	    else
	      lib_linked=no
1395 1396 1397 1398 1399
	    fi
	    ;;

	  relink)
	    if test "$hardcode_direct" = yes; then
1400 1401
	      compile_command="$compile_command $absdir/$linklib"
	      deplibs="$deplibs $absdir/$linklib"
1402
	    elif test "$hardcode_minus_L" = yes; then
1403 1404 1405 1406 1407 1408
	      case "$compile_command " in
	      *" -L$absdir "*) ;;
	      *) compile_command="$compile_command -L$absdir";;
	      esac
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -L$absdir -l$name"
1409
	    elif test "$hardcode_shlibpath_var" = yes; then
1410 1411 1412 1413
	      case ":$compile_shlibpath:" in
	      *":$absdir:"*) ;;
	      *) compile_shlibpath="$compile_shlibpath$absdir:";;
	      esac
1414 1415
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -l$name"
Manish Singh's avatar
Manish Singh committed
1416 1417
	    else
	      lib_linked=no
1418 1419
	    fi
	    ;;
Elliot Lee's avatar
Elliot Lee committed
1420

Manish Singh's avatar
Manish Singh committed
1421 1422 1423
	  *)
	    lib_linked=no
	    ;;
1424
	  esac
Elliot Lee's avatar
Elliot Lee committed
1425

Manish Singh's avatar
Manish Singh committed
1426 1427 1428 1429 1430
	  if test "$lib_linked" != yes; then
	    $echo "$modename: configuration error: unsupported hardcode properties"
	    exit 1
	  fi

1431 1432 1433 1434
	  # 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
1435 1436 1437 1438 1439
	    case "$finalize_command " in
	    *" -L$libdir "*) ;;
	    *) finalize_command="$finalize_command -L$libdir";;
	    esac
	    finalize_command="$finalize_command -l$name"
1440
	  elif test "$hardcode_shlibpath_var" = yes; then
1441 1442 1443 1444
	    case ":$finalize_shlibpath:" in
	    *":$libdir:"*) ;;
	    *) finalize_shlibpath="$finalize_shlibpath$libdir:";;
	    esac
1445 1446 1447
	    finalize_command="$finalize_command -l$name"
	  else
	    # We cannot seem to hardcode it, guess we'll fake it.
1448 1449 1450 1451 1452
	    case "$finalize_command " in
	    *" -L$dir "*) ;;
	    *) finalize_command="$finalize_command -L$libdir";;
	    esac
	    finalize_command="$finalize_command -l$name"
1453 1454 1455 1456 1457 1458 1459
	  fi
	else
	  # Transform directly to old archives if we don't build new libraries.
	  if test -n "$pic_flag" && test -z "$old_library"; then
	    $echo "$modename: cannot find static library for \`$arg'" 1>&2
	    exit 1
	  fi
Elliot Lee's avatar
Elliot Lee committed
1460

Manish Singh's avatar
Manish Singh committed
1461 1462 1463
	  # 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.
Elliot Lee's avatar
Elliot Lee committed
1464 1465 1466 1467 1468
	  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
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478