ltmain.sh 105 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
# ltmain.sh - Provide generalized library-building support services.
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.

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
  :
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%^.*/%%'`
52
modename="$progname"
Elliot Lee's avatar
Elliot Lee committed
53 54 55 56

# Constants.
PROGRAM=ltmain.sh
PACKAGE=libtool
Manish Singh's avatar
Manish Singh committed
57 58
VERSION=1.3
TIMESTAMP=" (1.385.2.117 1999/04/29 13:07:13)"
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//'
70
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
71 72
SP2NL='tr \040 \012'
NL2SP='tr \012 \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).
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
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
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
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
    ;;

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)
163
    echo "host: $host"
Elliot Lee's avatar
Elliot Lee committed
164
    if test "$build_libtool_libs" = yes; then
165
      echo "enable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
166
    else
167
      echo "disable shared libraries"
Elliot Lee's avatar
Elliot Lee committed
168 169
    fi
    if test "$build_old_libs" = yes; then
170
      echo "enable static libraries"
Elliot Lee's avatar
Elliot Lee committed
171
    else
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
    ;;

  -*)
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
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
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
      ;;
227
    *db | *dbx | *strace | *truss)
Elliot Lee's avatar
Elliot Lee committed
228 229
      mode=execute
      ;;
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
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"
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)
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
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
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
	;;
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.
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
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

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
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 434 435 436 437
    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.
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
      command="$base_compile $pic_flag -DPIC $srcfile"
      if test "$build_old_libs" = yes; then
	lo_libobj="$libobj"
	dir=`$echo "X$libobj" | $Xsed -e 's%/[^/]*$%%'`
	if test "X$dir" = "X$libobj"; then
	  dir="$objdir"
	else
	  dir="$dir/$objdir"
	fi
	libobj="$dir/"`$echo "X$libobj" | $Xsed -e 's%^.*/%%'`

	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 469 470
      fi

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

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

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

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
      # 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
	if test -f $obj; then
	  $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

	# Now arrange that obj and lo_libobj become the same file
	$show "$LN_S $obj $lo_libobj"
	if $run $LN_S $obj $lo_libobj; then
526 527
	  exit 0
	else
528
	  error=$?
529 530 531 532
	  $run $rm $removelist
	  exit $error
	fi
      fi
Elliot Lee's avatar
Elliot Lee committed
533 534 535 536 537 538 539

      # 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
540 541
      command="$base_compile $srcfile"
      if test "$compiler_c_o" = yes; then
542 543
	command="$command -o $obj"
	output_obj="$obj"
544 545
      fi

Elliot Lee's avatar
Elliot Lee committed
546
      # Suppress compiler output if we already did a PIC compilation.
547 548 549
      command="$command$suppress_output"
      $show "$command"
      if $run eval "$command"; then :
Elliot Lee's avatar
Elliot Lee committed
550
      else
551 552
	$run $rm $removelist
	exit 1
Elliot Lee's avatar
Elliot Lee committed
553
      fi
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

      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
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
      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
	$show "echo timestamp > $libobj"
	$run eval "echo timestamp > \$libobj" || exit $?
      else
	# Move the .lo from within objdir
	$show "$mv $libobj $lo_libobj"
	if $run $mv $libobj $lo_libobj; then :
595 596 597 598 599 600 601 602 603 604 605
	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
606 607 608 609 610 611 612
    fi

    exit 0
    ;;

  # libtool link mode
  link)
613
    modename="$modename: link"
614
    C_compiler="$CC" # save it, to compile generated C sources
Elliot Lee's avatar
Elliot Lee committed
615
    CC="$nonopt"
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    case "$host" in
    *-*-cygwin* | *-*-mingw* | *-*-os2*)
      # 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
639 640 641
# #ifdef __cplusplus
# extern "C" {
# #endif
642
# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
Manish Singh's avatar
Manish Singh committed
643 644 645
# #ifdef __cplusplus
# }
# #endif
646 647 648 649 650 651 652 653 654 655 656 657 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 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
#
# #include <cygwin/cygwin_dll.h>
# DECLARE_CYGWIN_DLL( DllMain );
# HINSTANCE __hDllInstance_base;
#
# BOOL APIENTRY
# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
# {
#   __hDllInstance_base = hInst;
#   return TRUE;
# }
# /* ltdll.c ends here */
      # 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 */
      ;;
791 792 793
    *-*-beos*)
      allow_undefined=no
      ;;
794 795 796 797
    *)
      allow_undefined=yes
      ;;
    esac
Elliot Lee's avatar
Elliot Lee committed
798 799 800
    compile_command="$CC"
    finalize_command="$CC"

801 802
    compile_rpath=
    finalize_rpath=
Elliot Lee's avatar
Elliot Lee committed
803 804
    compile_shlibpath=
    finalize_shlibpath=
805 806
    convenience=
    old_convenience=
Elliot Lee's avatar
Elliot Lee committed
807
    deplibs=
808 809 810 811 812 813 814 815 816 817 818
    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
      lib_search_path=
    fi
    # now prepend the system-specific ones
    eval lib_search_path=\"$sys_lib_search_path_spec\$lib_search_path\"
    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
819
    
820
    avoid_version=no
Elliot Lee's avatar
Elliot Lee committed
821 822
    dlfiles=
    dlprefiles=
823
    dlself=no
Elliot Lee's avatar
Elliot Lee committed
824
    export_dynamic=no
825
    export_symbols=
826
    export_symbols_regex=
827
    generated=
Elliot Lee's avatar
Elliot Lee committed
828 829 830
    libobjs=
    link_against_libtool_libs=
    ltlibs=
831
    module=no
Elliot Lee's avatar
Elliot Lee committed
832
    objs=
Manish Singh's avatar
Manish Singh committed
833
    prefer_static_libs=no
834
    preload=no
Elliot Lee's avatar
Elliot Lee committed
835 836
    prev=
    prevarg=
837
    release=
Elliot Lee's avatar
Elliot Lee committed
838
    rpath=
839
    xrpath=
Elliot Lee's avatar
Elliot Lee committed
840 841
    perm_rpath=
    temp_rpath=
842
    thread_safe=no
Elliot Lee's avatar
Elliot Lee committed
843 844 845 846 847 848 849
    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
850 851
	if test "X$arg" = "X-all-static"; then
	  if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
852
	    $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2
Manish Singh's avatar
Manish Singh committed
853 854 855 856 857 858 859 860
	  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
861 862
	fi
	build_libtool_libs=no
Elliot Lee's avatar
Elliot Lee committed
863
	build_old_libs=yes
Manish Singh's avatar
Manish Singh committed
864
	prefer_static_libs=yes
865 866
	break
	;;
Elliot Lee's avatar
Elliot Lee committed
867 868 869 870 871 872 873
      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.
874 875 876 877
    while test $# -gt 0; do
      arg="$1"
      shift

Elliot Lee's avatar
Elliot Lee committed
878 879
      # If the previous option needs an argument, assign it.
      if test -n "$prev"; then
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
	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.
	  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
902 903 904
	    else
	      dlself=needless
	      export_dynamic=yes
905 906 907 908 909
	    fi
	    prev=
	    continue
	    ;;
	  *)
Manish Singh's avatar
Manish Singh committed
910 911 912 913 914
	    if test "$prev" = dlfiles; then
	      dlfiles="$dlfiles $arg"
	    else
	      dlprefiles="$dlprefiles $arg"
	    fi
915 916 917 918 919
	    prev=
	    ;;
	  esac
	  ;;
	expsyms)
920
	  export_symbols="$arg"
921 922 923 924 925 926 927 928 929
	  if test ! -f "$arg"; then
	    $echo "$modename: symbol file \`$arg' does not exist"
	    exit 1
	  fi
	  prev=
	  continue
	  ;;
	expsyms_regex)
	  export_symbols_regex="$arg"
930
	  prev=
931
	  continue
932
	  ;;
933 934 935 936 937
	release)
	  release="-$arg"
	  prev=
	  continue
	  ;;
Manish Singh's avatar
Manish Singh committed
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
	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
958 959 960 961 962
	  prev=
	  continue
	  ;;
	*)
	  eval "$prev=\"\$arg\""
Elliot Lee's avatar
Elliot Lee committed
963 964 965
	  prev=
	  continue
	  ;;
966
	esac
Elliot Lee's avatar
Elliot Lee committed
967 968 969 970 971 972 973
      fi

      prevarg="$arg"

      case "$arg" in
      -all-static)
	if test -n "$link_static_flag"; then
974
	  compile_command="$compile_command $link_static_flag"
Elliot Lee's avatar
Elliot Lee committed
975
	  finalize_command="$finalize_command $link_static_flag"
976 977
	fi
	continue
Elliot Lee's avatar
Elliot Lee committed
978 979 980
	;;

      -allow-undefined)
981 982
	# 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
983 984 985
	continue
	;;

986 987 988 989 990
      -avoid-version)
	avoid_version=yes
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
991
      -dlopen)
992 993 994
	prev=dlfiles
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
995 996

      -dlpreopen)
997 998 999
	prev=dlprefiles
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1000 1001

      -export-dynamic)
Manish Singh's avatar
Manish Singh committed
1002 1003
	export_dynamic=yes
	continue
1004
	;;
Elliot Lee's avatar
Elliot Lee committed
1005

1006 1007
      -export-symbols | -export-symbols-regex)
	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
Manish Singh's avatar
Manish Singh committed
1008
	  $echo "$modename: not more than one -exported-symbols argument allowed"
1009 1010
	  exit 1
	fi
Manish Singh's avatar
Manish Singh committed
1011
	if test "X$arg" = "X-export-symbols"; then
1012 1013 1014 1015
	  prev=expsyms
	else
	  prev=expsyms_regex
	fi
1016
	continue
1017
	;;
1018

Elliot Lee's avatar
Elliot Lee committed
1019
      -L*)
Manish Singh's avatar
Manish Singh committed
1020 1021
	dir=`$echo "X$arg" | $Xsed -e 's/^-L//'`
	# We need an absolute path.
1022
	case "$dir" in
Manish Singh's avatar
Manish Singh committed
1023
	[\\/]* | [A-Za-z]:[\\/]*) ;;
1024
	*)
Manish Singh's avatar
Manish Singh committed
1025 1026 1027 1028 1029 1030
	  absdir=`cd "$dir" && pwd`
	  if test -z "$absdir"; then
	    $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
	    exit 1
	  fi
	  dir="$absdir"
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
	  ;;
	esac
	case " $deplibs " in
	*" $arg "*) ;;
	*) deplibs="$deplibs $arg";;
	esac
	case " $lib_search_path " in
	*" $dir "*) ;;
	*) lib_search_path="$lib_search_path $dir";;
	esac
	case "$host" in
	*-*-cygwin* | *-*-mingw* | *-*-os2*)
	  dllsearchdir=`cd "$dir" && pwd || echo "$dir"`
	  case ":$dllsearchpath:" in
	  ::) dllsearchpath="$dllsearchdir";;
	  *":$dllsearchdir:"*) ;;
	  *) dllsearchpath="$dllsearchpath:$dllsearchdir";;
	  esac
	  ;;
	esac
	;;

      -l*)
Manish Singh's avatar
Manish Singh committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
	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
1069 1070
	deplibs="$deplibs $arg"
	;;
Elliot Lee's avatar
Elliot Lee committed
1071

1072
      -module)
Manish Singh's avatar
Manish Singh committed
1073 1074
	module=yes
	continue
1075
	;;
Manish Singh's avatar
Manish Singh committed
1076

1077 1078 1079 1080 1081
      -no-undefined)
	allow_undefined=no
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
1082 1083
      -o) prev=output ;;

1084 1085 1086 1087 1088
      -release)
	prev=release
	continue
	;;

Elliot Lee's avatar
Elliot Lee committed
1089
      -rpath)
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
	prev=rpath
	continue
	;;

      -R)
	prev=xrpath
	continue
	;;

      -R*)
Manish Singh's avatar
Manish Singh committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
	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
1113 1114
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1115 1116 1117 1118

      -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
1119
	  compile_command="$compile_command $link_static_flag"
Elliot Lee's avatar
Elliot Lee committed
1120
	  finalize_command="$finalize_command $link_static_flag"
1121 1122 1123 1124 1125 1126
	fi
	continue
	;;

      -thread-safe)
	thread_safe=yes
Elliot Lee's avatar
Elliot Lee committed
1127 1128 1129 1130
	continue
	;;

      -version-info)
1131 1132 1133
	prev=vinfo
	continue
	;;
Elliot Lee's avatar
Elliot Lee committed
1134 1135 1136 1137 1138

      # Some other compiler flag.
      -* | +*)
	# Unknown arguments in both finalize_command and compile_command need
	# to be aesthetically quoted because they are evaled later.
1139
	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
1140 1141 1142 1143 1144
	case "$arg" in
	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
	  arg="\"$arg\""
	  ;;
	esac
1145
	;;
Elliot Lee's avatar
Elliot Lee committed
1146

1147
      *.o | *.obj | *.a | *.lib)
1148 1149 1150
	# A standard object.
	objs="$objs $arg"
	;;
Elliot Lee's avatar
Elliot Lee committed
1151 1152

      *.lo)
1153
	# A library object.
Elliot Lee's avatar
Elliot Lee committed
1154 1155
	if test "$prev" = dlfiles; then
	  dlfiles="$dlfiles $arg"
1156
	  if test "$build_libtool_libs" = yes && test "$dlopen" = yes; then
Elliot Lee's avatar
Elliot Lee committed
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
	    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.
1167
	  dlprefiles="$dlprefiles "`$echo "X$arg" | $Xsed -e "$lo2o"`
Elliot Lee's avatar
Elliot Lee committed
1168 1169 1170
	  prev=
	fi
	libobjs="$libobjs $arg"
1171
	;;
Elliot Lee's avatar
Elliot Lee committed
1172 1173

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

1176 1177 1178 1179
	dlname=
	libdir=
	library_names=
	old_library=
Elliot Lee's avatar
Elliot Lee committed
1180

1181 1182 1183 1184 1185 1186
	# 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
1187

1188 1189 1190 1191
	# 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
1192
	# Read the .la file
1193 1194 1195 1196 1197
	# If there is no directory component, then add one.
	case "$arg" in
	*/* | *\\*) . $arg ;;
	*) . ./$arg ;;
	esac
Elliot Lee's avatar
Elliot Lee committed
1198

1199 1200 1201 1202 1203
	# 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
1204

1205 1206 1207 1208
	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
1209

1210 1211
	# Find the relevant object directory and library name.
	name=`$echo "X$arg" | $Xsed -e 's%^.*/%%' -e 's/\.la$//' -e 's/^lib//'`
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222

	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
1223

1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
	if test -n "$dependency_libs"; then
	  # Extract -R from dependency_libs
	  temp_deplibs=
	  for deplib in $dependency_libs; do
	    case "$deplib" in
	    -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";;
		 esac;;
	    *) temp_deplibs="$temp_deplibs $deplib";;
	    esac
	  done
	  dependency_libs="$temp_deplibs"
	fi

	if test -z "$libdir"; then
1245
	  # It is a libtool convenience library, so add in its objects.
1246
	  convenience="$convenience $dir/$old_library"
1247
	  old_convenience="$old_convenience $dir/$old_library"
1248 1249 1250
	  deplibs="$deplibs$dependency_libs"
	  compile_command="$compile_command $dir/$old_library$dependency_libs"
	  finalize_command="$finalize_command $dir/$old_library$dependency_libs"
1251 1252 1253
	  continue
	fi

1254 1255 1256 1257 1258 1259 1260 1261 1262
	# This library was specified with -dlopen.
	if test "$prev" = dlfiles; then
	  dlfiles="$dlfiles $arg"
	  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,
	    # we need to preload.
	    prev=dlprefiles
	  else
	    # We should not create a dependency on this library, but we
1263 1264 1265
	    # may need any libraries it requires.
	    compile_command="$compile_command$dependency_libs"
	    finalize_command="$finalize_command$dependency_libs"
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
	    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
1283 1284
	if test -n "$library_names" &&
	   { test "$prefer_static_libs" = no || test -z "$old_library"; }; then
1285 1286 1287 1288 1289 1290 1291 1292
	  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
1293

1294 1295
	  # We need an absolute path.
	  case "$dir" in
Manish Singh's avatar
Manish Singh committed
1296
	  [\\/] | [A-Za-z]:[\\/]*) absdir="$dir" ;;
1297 1298 1299
	  *)
	    absdir=`cd "$dir" && pwd`
	    if test -z "$absdir"; then
Manish Singh's avatar
Manish Singh committed
1300
	      $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
1301 1302 1303 1304 1305
	      exit 1
	    fi
	    ;;
	  esac
	  
Elliot Lee's avatar
Elliot Lee committed
1306
	  # This is the magic to use -rpath.
1307 1308 1309
	  # 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
1310
	  *" $absdir "*) ;;
1311 1312 1313 1314 1315 1316
	  *)
	    case "$compile_rpath " in
	    *" $absdir "*) ;;
	    *) compile_rpath="$compile_rpath $absdir" 
	    esac
	    ;;
Manish Singh's avatar
Manish Singh committed
1317
	  esac
Elliot Lee's avatar
Elliot Lee committed
1318

1319
	  case " $sys_lib_dlsearch_path " in
Manish Singh's avatar
Manish Singh committed
1320
	  *" $libdir "*) ;;
1321 1322 1323 1324 1325 1326
	  *)
	    case "$finalize_rpath " in
	    *" $libdir "*) ;;
	    *) finalize_rpath="$finalize_rpath $libdir"
	    esac
	    ;;
Manish Singh's avatar
Manish Singh committed
1327
	  esac
Elliot Lee's avatar
Elliot Lee committed
1328

1329
	  lib_linked=yes
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
	  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
	      *-*-cygwin* | *-*-mingw* | *-*-os2*)
		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
1346 1347
	      case "$host" in
	      *-*-sunos*)
1348
		compile_shlibpath="$compile_shlibpath$dir:"
1349 1350
		;;
	      esac
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
	      case "$compile_command " in
	      *" -L$dir "*) ;;
	      *) compile_command="$compile_command -L$dir";;
	      esac
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -L$dir -l$name"
	    elif test "$hardcode_shlibpath_var" = no; then
	      case ":$compile_shlibpath:" in
	      *":$dir:"*) ;;
	      *) compile_shlibpath="$compile_shlibpath$dir:";;
	      esac
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -l$name"
1364 1365
	    else
	      lib_linked=no
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
	    fi
	    ;;

	  relink)
	    if test "$hardcode_direct" = yes; then
	      compile_command="$compile_command $absdir/$linklib"
	      deplibs="$deplibs $absdir/$linklib"
	    elif test "$hardcode_minus_L" = yes; then
	      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"
	    elif test "$hardcode_shlibpath_var" = yes; then
	      case ":$compile_shlibpath:" in
	      *":$absdir:"*) ;;
	      *) compile_shlibpath="$compile_shlibpath$absdir:";;
	      esac
	      compile_command="$compile_command -l$name"
	      deplibs="$deplibs -l$name"
1387 1388
	    else
	      lib_linked=no
1389 1390
	    fi
	    ;;
Elliot Lee's avatar
Elliot Lee committed
1391

1392 1393 1394
	  *)
	    lib_linked=no
	    ;;
1395
	  esac
Elliot Lee's avatar
Elliot Lee committed
1396

1397 1398 1399 1400 1401
	  if test "$lib_linked" != yes; then
	    $echo "$modename: configuration error: unsupported hardcode properties"
	    exit 1
	  fi

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
	  # 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
	    case "$finalize_command " in
	    *" -L$libdir "*) ;;
	    *) finalize_command="$finalize_command -L$libdir";;
	    esac
	    finalize_command="$finalize_command -l$name"
	  elif test "$hardcode_shlibpath_var" = yes; then
	    case ":$finalize_shlibpath:" in
	    *":$libdir:"*) ;;
	    *) finalize_shlibpath="$finalize_shlibpath$libdir:";;
	    esac
	    finalize_command="$finalize_command -l$name"
	  else
	    # We cannot seem to hardcode it, guess we'll fake it.
	    case "$finalize_command " in
	    *" -L$dir "*) ;;
	    *) finalize_command="$finalize_command -L$libdir";;
	    esac
	    finalize_command="$finalize_command -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
	    $echo "$modename: cannot find static library for \`$arg'" 1>&2
	    exit 1
	  fi
Elliot Lee's avatar
Elliot Lee committed
1431 1432 1433 1434 1435 1436 1437 1438 1439

	  # 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
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
	    case "$compile_command " in
	    *" -L$dir "*) ;;
	    *) compile_command="$compile_command -L$dir";;
	    esac
	    compile_command="$compile_command -l$name"
	    case "$finalize_command " in
	    *" -L$dir "*) ;;
	    *) finalize_command="$finalize_command -L$dir";;
	    esac
	    finalize_command="$finalize_command -l$name"
Elliot Lee's avatar
Elliot Lee committed
1450
	  fi
1451
	fi
1452 1453 1454 1455

	# 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
1456
	continue
1457
	;;
Elliot Lee's avatar
Elliot Lee committed
1458 1459 1460 1461 1462

      # Some other compiler argument.
      *)
	# Unknown arguments in both finalize_command and compile_command need
	# to be aesthetically quoted because they are evaled later.
1463
	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
Elliot Lee's avatar
Elliot Lee committed
1464 1465 1466 1467 1468
	case "$arg" in
	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
	  arg="\"$arg\""
	  ;;
	esac
1469
	;;
Elliot Lee's avatar
Elliot Lee committed
1470 1471 1472
      esac

      # Now actually substitute the argument into the commands.
1473 1474 1475 1476
      if test -n "$arg"; then
	compile_command="$compile_command $arg"
	finalize_command="$finalize_command $arg"
      fi
Elliot Lee's avatar
Elliot Lee committed
1477 1478 1479
    done

    if test -n "$prev"; then
1480 1481 1482 1483 1484
      $echo "$modename: the \`$prevarg' option requires an argument" 1>&2
      $echo "$help" 1>&2
      exit 1
    fi

Manish Singh's avatar
Manish Singh committed
1485 1486 1487 1488 1489 1490
    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
      eval arg=\"$export_dynamic_flag_spec\"
      compile_command="$compile_command $arg"
      finalize_command="$finalize_command $arg"
    fi

1491
    oldlibs=
1492 1493
    # calculate the name of the file, without its directory
    outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'`
1494
    libobjs_save="$libobjs"
1495

Elliot Lee's avatar
Elliot Lee committed
1496 1497
    case "$output" in
    "")
1498
      $echo "$modename: you must specify an output file" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1499 1500 1501 1502
      $echo "$help" 1>&2
      exit 1
      ;;

1503
    *.a | *.lib)
1504
      if test -n "$link_against_libtool_libs"; then
1505 1506
	$echo "$modename: error: cannot link libtool libraries into archives" 1>&2
	exit 1
1507 1508 1509
      fi

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

Manish Singh's avatar
Manish Singh committed
1513
      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
1514
	$echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2
1515 1516 1517
      fi

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

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

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

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

Manish Singh's avatar
Manish Singh committed
1533
      if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
1534
	$echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2
1535 1536
      fi

1537 1538
      # Now set the variables for building old libraries.
      build_libtool_libs=no
1539
      oldlibs="$output"
1540 1541
      ;;

Elliot Lee's avatar
Elliot Lee committed
1542 1543
    *.la)
      # Make sure we only generate libraries of the form `libNAME.la'.
1544
      case "$outputname" in
1545 1546 1547 1548
      lib*)
	name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
	eval libname=\"$libname_spec\"
	;;
Elliot Lee's avatar
Elliot Lee committed
1549
      *)
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
	if test "$module" = no; then
	  $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2
	  $echo "$help" 1>&2
	  exit 1
	fi
	if test "$need_lib_prefix" != no; then
	  # Add the "lib" prefix for modules if required
	  name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
	  eval libname=\"$libname_spec\"
	else
	  libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
	fi
Elliot Lee's avatar
Elliot Lee committed
1562 1563 1564
	;;
      esac

1565 1566
      output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'`
      if test "X$output_objdir" = "X$output"; then
1567
	output_objdir="$objdir"
1568
      else
1569
	output_objdir="$output_objdir/$objdir"
1570 1571
      fi

Elliot Lee's avatar
Elliot Lee committed
1572
      if test -n "$objs"; then
1573 1574
	$echo "$modename: cannot build libtool library \`$output' from non-libtool objects:$objs" 2>&1
	exit 1
Elliot Lee's avatar
Elliot Lee committed
1575 1576 1577 1578
      fi

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

Manish Singh's avatar
Manish Singh committed
1583
      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
1584
	$echo "$modename: warning: \`-dlopen' is ignored for libtool libraries" 1>&2
Elliot Lee's avatar
Elliot Lee committed
1585 1586 1587 1588
      fi

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

1593
      oldlibs=
1594
      if test -z "$rpath"; then
1595 1596 1597 1598 1599 1600 1601
	if test "$build_libtool_libs" = yes; then
	  # Building a libtool convenience library.
	  libext=al
	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
	  build_libtool_libs=convenience
	  build_old_libs=yes
	fi
1602
	dependency_libs="$deplibs"
Elliot Lee's avatar
Elliot Lee committed
1603

1604 1605 1606
	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
1607

1608 1609 1610 1611
	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
1612

1613 1614 1615 1616
	# 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
1617

1618 1619 1620 1621 1622
	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
1623

1624 1625 1626
	current="$2"
	revision="$3"
	age="$4"
Elliot Lee's avatar
Elliot Lee committed
1627

1628 1629 1630 1631 1632 1633 1634 1635 1636
	# 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
1637

1638 1639 1640 1641 1642 1643 1644 1645
	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
1646

1647 1648 1649 1650 1651 1652 1653 1654
	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
1655

1656 1657 1658 1659 1660
	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
1661

1662 1663 1664 1665 1666 1667
	# Calculate the version variables.
	major=
	versuffix=
	verstring=
	case "$version_type" in
	none) ;;
Elliot Lee's avatar
Elliot Lee committed
1668

1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
	irix)
	  major=`expr $current - $age + 1`
	  versuffix="$major.$revision"
	  verstring="sgi$major.$revision"

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

1683 1684 1685 1686
	linux)
	  major=.`expr $current - $age`
	  versuffix="$major.$age.$revision"
	  ;;
Elliot Lee's avatar
Elliot Lee committed
1687

1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
	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"
	  ;;

1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726
	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"
	  ;;

1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
	*)
	  $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=
	  verstring="0.0"
1738 1739 1740
	  if test "$need_version" = no; then
	    versuffix=
	  else
1741
	    versuffix=".0.0"
1742
	  fi
1743 1744
	fi

1745 1746 1747 1748 1749 1750 1751
	# Remove version info from name if versioning should be avoided
	if test "$avoid_version" = yes && test "$need_version" = no; then
	  major=
	  versuffix=
	  verstring=""
	fi
	
1752