17ec3b29aSmrg#! /bin/sh
27ec3b29aSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
37ec3b29aSmrg##               by inline-source v2014-01-03.01
432001f49Smrg
57ec3b29aSmrg# libtool (GNU libtool) 2.4.6
67ec3b29aSmrg# Provide generalized library-building support services.
732001f49Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
832001f49Smrg
97ec3b29aSmrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
1032001f49Smrg# This is free software; see the source for copying conditions.  There is NO
1132001f49Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1232001f49Smrg
1332001f49Smrg# GNU Libtool is free software; you can redistribute it and/or modify
1432001f49Smrg# it under the terms of the GNU General Public License as published by
1532001f49Smrg# the Free Software Foundation; either version 2 of the License, or
1632001f49Smrg# (at your option) any later version.
1732001f49Smrg#
1832001f49Smrg# As a special exception to the GNU General Public License,
1932001f49Smrg# if you distribute this file as part of a program or library that
2032001f49Smrg# is built using GNU Libtool, you may include this file under the
2132001f49Smrg# same distribution terms that you use for the rest of that program.
2232001f49Smrg#
2332001f49Smrg# GNU Libtool is distributed in the hope that it will be useful, but
2432001f49Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
2532001f49Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2632001f49Smrg# General Public License for more details.
2732001f49Smrg#
2832001f49Smrg# You should have received a copy of the GNU General Public License
297ec3b29aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
3032001f49Smrg
3132001f49Smrg
3232001f49SmrgPROGRAM=libtool
3332001f49SmrgPACKAGE=libtool
347ec3b29aSmrgVERSION="2.4.6 Debian-2.4.6-2"
357ec3b29aSmrgpackage_revision=2.4.6
3632001f49Smrg
377ec3b29aSmrg
387ec3b29aSmrg## ------ ##
397ec3b29aSmrg## Usage. ##
407ec3b29aSmrg## ------ ##
417ec3b29aSmrg
427ec3b29aSmrg# Run './libtool --help' for help with using this script from the
437ec3b29aSmrg# command line.
447ec3b29aSmrg
457ec3b29aSmrg
467ec3b29aSmrg## ------------------------------- ##
477ec3b29aSmrg## User overridable command paths. ##
487ec3b29aSmrg## ------------------------------- ##
497ec3b29aSmrg
507ec3b29aSmrg# After configure completes, it has a better idea of some of the
517ec3b29aSmrg# shell tools we need than the defaults used by the functions shared
527ec3b29aSmrg# with bootstrap, so set those here where they can still be over-
537ec3b29aSmrg# ridden by the user, but otherwise take precedence.
547ec3b29aSmrg
557ec3b29aSmrg: ${AUTOCONF="autoconf"}
567ec3b29aSmrg: ${AUTOMAKE="automake"}
577ec3b29aSmrg
587ec3b29aSmrg
597ec3b29aSmrg## -------------------------- ##
607ec3b29aSmrg## Source external libraries. ##
617ec3b29aSmrg## -------------------------- ##
627ec3b29aSmrg
637ec3b29aSmrg# Much of our low-level functionality needs to be sourced from external
647ec3b29aSmrg# libraries, which are installed to $pkgauxdir.
657ec3b29aSmrg
667ec3b29aSmrg# Set a version string for this script.
677ec3b29aSmrgscriptversion=2015-01-20.17; # UTC
687ec3b29aSmrg
697ec3b29aSmrg# General shell script boiler plate, and helper functions.
707ec3b29aSmrg# Written by Gary V. Vaughan, 2004
717ec3b29aSmrg
727ec3b29aSmrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
737ec3b29aSmrg# This is free software; see the source for copying conditions.  There is NO
747ec3b29aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
757ec3b29aSmrg
767ec3b29aSmrg# This program is free software; you can redistribute it and/or modify
777ec3b29aSmrg# it under the terms of the GNU General Public License as published by
787ec3b29aSmrg# the Free Software Foundation; either version 3 of the License, or
797ec3b29aSmrg# (at your option) any later version.
807ec3b29aSmrg
817ec3b29aSmrg# As a special exception to the GNU General Public License, if you distribute
827ec3b29aSmrg# this file as part of a program or library that is built using GNU Libtool,
837ec3b29aSmrg# you may include this file under the same distribution terms that you use
847ec3b29aSmrg# for the rest of that program.
857ec3b29aSmrg
867ec3b29aSmrg# This program is distributed in the hope that it will be useful,
877ec3b29aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
887ec3b29aSmrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
897ec3b29aSmrg# General Public License for more details.
907ec3b29aSmrg
917ec3b29aSmrg# You should have received a copy of the GNU General Public License
927ec3b29aSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
937ec3b29aSmrg
947ec3b29aSmrg# Please report bugs or propose patches to gary@gnu.org.
957ec3b29aSmrg
967ec3b29aSmrg
977ec3b29aSmrg## ------ ##
987ec3b29aSmrg## Usage. ##
997ec3b29aSmrg## ------ ##
1007ec3b29aSmrg
1017ec3b29aSmrg# Evaluate this file near the top of your script to gain access to
1027ec3b29aSmrg# the functions and variables defined here:
1037ec3b29aSmrg#
1047ec3b29aSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
1057ec3b29aSmrg#
1067ec3b29aSmrg# If you need to override any of the default environment variable
1077ec3b29aSmrg# settings, do that before evaluating this file.
1087ec3b29aSmrg
1097ec3b29aSmrg
1107ec3b29aSmrg## -------------------- ##
1117ec3b29aSmrg## Shell normalisation. ##
1127ec3b29aSmrg## -------------------- ##
1137ec3b29aSmrg
1147ec3b29aSmrg# Some shells need a little help to be as Bourne compatible as possible.
1157ec3b29aSmrg# Before doing anything else, make sure all that help has been provided!
1167ec3b29aSmrg
1177ec3b29aSmrgDUALCASE=1; export DUALCASE # for MKS sh
1187ec3b29aSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
11932001f49Smrg  emulate sh
12032001f49Smrg  NULLCMD=:
1217ec3b29aSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
12232001f49Smrg  # is contrary to our usage.  Disable this feature.
12332001f49Smrg  alias -g '${1+"$@"}'='"$@"'
12432001f49Smrg  setopt NO_GLOB_SUBST
12532001f49Smrgelse
1267ec3b29aSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
12732001f49Smrgfi
12832001f49Smrg
1297ec3b29aSmrg# NLS nuisances: We save the old values in case they are required later.
1307ec3b29aSmrg_G_user_locale=
1317ec3b29aSmrg_G_safe_locale=
1327ec3b29aSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
13332001f49Smrgdo
1347ec3b29aSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1357ec3b29aSmrg          save_$_G_var=\$$_G_var
1367ec3b29aSmrg          $_G_var=C
1377ec3b29aSmrg	  export $_G_var
1387ec3b29aSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1397ec3b29aSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
14032001f49Smrg	fi"
14132001f49Smrgdone
14232001f49Smrg
1437ec3b29aSmrg# CDPATH.
1447ec3b29aSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
14532001f49Smrg
1467ec3b29aSmrg# Make sure IFS has a sensible default
1477ec3b29aSmrgsp=' '
1487ec3b29aSmrgnl='
1497ec3b29aSmrg'
1507ec3b29aSmrgIFS="$sp	$nl"
1517ec3b29aSmrg
1527ec3b29aSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1537ec3b29aSmrgif test "${PATH_SEPARATOR+set}" != set; then
1547ec3b29aSmrg  PATH_SEPARATOR=:
1557ec3b29aSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1567ec3b29aSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1577ec3b29aSmrg      PATH_SEPARATOR=';'
1587ec3b29aSmrg  }
1597ec3b29aSmrgfi
16032001f49Smrg
16132001f49Smrg
16232001f49Smrg
1637ec3b29aSmrg## ------------------------- ##
1647ec3b29aSmrg## Locate command utilities. ##
1657ec3b29aSmrg## ------------------------- ##
1667ec3b29aSmrg
1677ec3b29aSmrg
1687ec3b29aSmrg# func_executable_p FILE
1697ec3b29aSmrg# ----------------------
1707ec3b29aSmrg# Check that FILE is an executable regular file.
1717ec3b29aSmrgfunc_executable_p ()
1727ec3b29aSmrg{
1737ec3b29aSmrg    test -f "$1" && test -x "$1"
1747ec3b29aSmrg}
1757ec3b29aSmrg
1767ec3b29aSmrg
1777ec3b29aSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1787ec3b29aSmrg# --------------------------------------------
1797ec3b29aSmrg# Search for either a program that responds to --version with output
1807ec3b29aSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1817ec3b29aSmrg# trying all the directories in PATH with each of the elements of
1827ec3b29aSmrg# PROGS_LIST.
1837ec3b29aSmrg#
1847ec3b29aSmrg# CHECK_FUNC should accept the path to a candidate program, and
1857ec3b29aSmrg# set $func_check_prog_result if it truncates its output less than
1867ec3b29aSmrg# $_G_path_prog_max characters.
1877ec3b29aSmrgfunc_path_progs ()
1887ec3b29aSmrg{
1897ec3b29aSmrg    _G_progs_list=$1
1907ec3b29aSmrg    _G_check_func=$2
1917ec3b29aSmrg    _G_PATH=${3-"$PATH"}
1927ec3b29aSmrg
1937ec3b29aSmrg    _G_path_prog_max=0
1947ec3b29aSmrg    _G_path_prog_found=false
1957ec3b29aSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
1967ec3b29aSmrg    for _G_dir in $_G_PATH; do
1977ec3b29aSmrg      IFS=$_G_save_IFS
1987ec3b29aSmrg      test -z "$_G_dir" && _G_dir=.
1997ec3b29aSmrg      for _G_prog_name in $_G_progs_list; do
2007ec3b29aSmrg        for _exeext in '' .EXE; do
2017ec3b29aSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2027ec3b29aSmrg          func_executable_p "$_G_path_prog" || continue
2037ec3b29aSmrg          case `"$_G_path_prog" --version 2>&1` in
2047ec3b29aSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2057ec3b29aSmrg            *)     $_G_check_func $_G_path_prog
2067ec3b29aSmrg		   func_path_progs_result=$func_check_prog_result
2077ec3b29aSmrg		   ;;
2087ec3b29aSmrg          esac
2097ec3b29aSmrg          $_G_path_prog_found && break 3
2107ec3b29aSmrg        done
2117ec3b29aSmrg      done
2127ec3b29aSmrg    done
2137ec3b29aSmrg    IFS=$_G_save_IFS
2147ec3b29aSmrg    test -z "$func_path_progs_result" && {
2157ec3b29aSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2167ec3b29aSmrg      exit 1
2177ec3b29aSmrg    }
2187ec3b29aSmrg}
2197ec3b29aSmrg
2207ec3b29aSmrg
2217ec3b29aSmrg# We want to be able to use the functions in this file before configure
2227ec3b29aSmrg# has figured out where the best binaries are kept, which means we have
2237ec3b29aSmrg# to search for them ourselves - except when the results are already set
2247ec3b29aSmrg# where we skip the searches.
2257ec3b29aSmrg
2267ec3b29aSmrg# Unless the user overrides by setting SED, search the path for either GNU
2277ec3b29aSmrg# sed, or the sed that truncates its output the least.
2287ec3b29aSmrgtest -z "$SED" && {
2297ec3b29aSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2307ec3b29aSmrg  for _G_i in 1 2 3 4 5 6 7; do
2317ec3b29aSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2327ec3b29aSmrg  done
2337ec3b29aSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2347ec3b29aSmrg  _G_sed_script=
2357ec3b29aSmrg
2367ec3b29aSmrg  func_check_prog_sed ()
2377ec3b29aSmrg  {
2387ec3b29aSmrg    _G_path_prog=$1
2397ec3b29aSmrg
2407ec3b29aSmrg    _G_count=0
2417ec3b29aSmrg    printf 0123456789 >conftest.in
2427ec3b29aSmrg    while :
2437ec3b29aSmrg    do
2447ec3b29aSmrg      cat conftest.in conftest.in >conftest.tmp
2457ec3b29aSmrg      mv conftest.tmp conftest.in
2467ec3b29aSmrg      cp conftest.in conftest.nl
2477ec3b29aSmrg      echo '' >> conftest.nl
2487ec3b29aSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2497ec3b29aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2507ec3b29aSmrg      _G_count=`expr $_G_count + 1`
2517ec3b29aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2527ec3b29aSmrg        # Best one so far, save it but keep looking for a better one
2537ec3b29aSmrg        func_check_prog_result=$_G_path_prog
2547ec3b29aSmrg        _G_path_prog_max=$_G_count
2557ec3b29aSmrg      fi
2567ec3b29aSmrg      # 10*(2^10) chars as input seems more than enough
2577ec3b29aSmrg      test 10 -lt "$_G_count" && break
2587ec3b29aSmrg    done
2597ec3b29aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2607ec3b29aSmrg  }
2617ec3b29aSmrg
2627ec3b29aSmrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
2637ec3b29aSmrg  rm -f conftest.sed
2647ec3b29aSmrg  SED=$func_path_progs_result
2657ec3b29aSmrg}
2667ec3b29aSmrg
2677ec3b29aSmrg
2687ec3b29aSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2697ec3b29aSmrg# grep, or the grep that truncates its output the least.
2707ec3b29aSmrgtest -z "$GREP" && {
2717ec3b29aSmrg  func_check_prog_grep ()
2727ec3b29aSmrg  {
2737ec3b29aSmrg    _G_path_prog=$1
2747ec3b29aSmrg
2757ec3b29aSmrg    _G_count=0
2767ec3b29aSmrg    _G_path_prog_max=0
2777ec3b29aSmrg    printf 0123456789 >conftest.in
2787ec3b29aSmrg    while :
2797ec3b29aSmrg    do
2807ec3b29aSmrg      cat conftest.in conftest.in >conftest.tmp
2817ec3b29aSmrg      mv conftest.tmp conftest.in
2827ec3b29aSmrg      cp conftest.in conftest.nl
2837ec3b29aSmrg      echo 'GREP' >> conftest.nl
2847ec3b29aSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2857ec3b29aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2867ec3b29aSmrg      _G_count=`expr $_G_count + 1`
2877ec3b29aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2887ec3b29aSmrg        # Best one so far, save it but keep looking for a better one
2897ec3b29aSmrg        func_check_prog_result=$_G_path_prog
2907ec3b29aSmrg        _G_path_prog_max=$_G_count
2917ec3b29aSmrg      fi
2927ec3b29aSmrg      # 10*(2^10) chars as input seems more than enough
2937ec3b29aSmrg      test 10 -lt "$_G_count" && break
2947ec3b29aSmrg    done
2957ec3b29aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2967ec3b29aSmrg  }
2977ec3b29aSmrg
2987ec3b29aSmrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
2997ec3b29aSmrg  GREP=$func_path_progs_result
3007ec3b29aSmrg}
3017ec3b29aSmrg
3027ec3b29aSmrg
3037ec3b29aSmrg## ------------------------------- ##
3047ec3b29aSmrg## User overridable command paths. ##
3057ec3b29aSmrg## ------------------------------- ##
3067ec3b29aSmrg
3077ec3b29aSmrg# All uppercase variable names are used for environment variables.  These
3087ec3b29aSmrg# variables can be overridden by the user before calling a script that
3097ec3b29aSmrg# uses them if a suitable command of that name is not already available
3107ec3b29aSmrg# in the command search PATH.
31132001f49Smrg
31232001f49Smrg: ${CP="cp -f"}
3137ec3b29aSmrg: ${ECHO="printf %s\n"}
3147ec3b29aSmrg: ${EGREP="$GREP -E"}
3157ec3b29aSmrg: ${FGREP="$GREP -F"}
3167ec3b29aSmrg: ${LN_S="ln -s"}
31732001f49Smrg: ${MAKE="make"}
31832001f49Smrg: ${MKDIR="mkdir"}
31932001f49Smrg: ${MV="mv -f"}
32032001f49Smrg: ${RM="rm -f"}
32132001f49Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
32232001f49Smrg
32332001f49Smrg
3247ec3b29aSmrg## -------------------- ##
3257ec3b29aSmrg## Useful sed snippets. ##
3267ec3b29aSmrg## -------------------- ##
32732001f49Smrg
3287ec3b29aSmrgsed_dirname='s|/[^/]*$||'
3297ec3b29aSmrgsed_basename='s|^.*/||'
33032001f49Smrg
3317ec3b29aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3327ec3b29aSmrg# metacharacters that are still active within double-quoted strings.
3337ec3b29aSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
33432001f49Smrg
3357ec3b29aSmrg# Same as above, but do not quote variable references.
3367ec3b29aSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
33732001f49Smrg
3387ec3b29aSmrg# Sed substitution that turns a string into a regex matching for the
3397ec3b29aSmrg# string literally.
3407ec3b29aSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
34132001f49Smrg
3427ec3b29aSmrg# Sed substitution that converts a w32 file name or path
3437ec3b29aSmrg# that contains forward slashes, into one that contains
3447ec3b29aSmrg# (escaped) backslashes.  A very naive implementation.
3457ec3b29aSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3467ec3b29aSmrg
3477ec3b29aSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3487ec3b29aSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3497ec3b29aSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3507ec3b29aSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3517ec3b29aSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3527ec3b29aSmrg_G_bs='\\'
3537ec3b29aSmrg_G_bs2='\\\\'
3547ec3b29aSmrg_G_bs4='\\\\\\\\'
3557ec3b29aSmrg_G_dollar='\$'
3567ec3b29aSmrgsed_double_backslash="\
3577ec3b29aSmrg  s/$_G_bs4/&\\
3587ec3b29aSmrg/g
3597ec3b29aSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3607ec3b29aSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3617ec3b29aSmrg  s/\n//g"
36232001f49Smrg
36332001f49Smrg
3647ec3b29aSmrg## ----------------- ##
3657ec3b29aSmrg## Global variables. ##
3667ec3b29aSmrg## ----------------- ##
36732001f49Smrg
3687ec3b29aSmrg# Except for the global variables explicitly listed below, the following
3697ec3b29aSmrg# functions in the '^func_' namespace, and the '^require_' namespace
3707ec3b29aSmrg# variables initialised in the 'Resource management' section, sourcing
3717ec3b29aSmrg# this file will not pollute your global namespace with anything
3727ec3b29aSmrg# else. There's no portable way to scope variables in Bourne shell
3737ec3b29aSmrg# though, so actually running these functions will sometimes place
3747ec3b29aSmrg# results into a variable named after the function, and often use
3757ec3b29aSmrg# temporary variables in the '^_G_' namespace. If you are careful to
3767ec3b29aSmrg# avoid using those namespaces casually in your sourcing script, things
3777ec3b29aSmrg# should continue to work as you expect. And, of course, you can freely
3787ec3b29aSmrg# overwrite any of the functions or variables defined here before
3797ec3b29aSmrg# calling anything to customize them.
38032001f49Smrg
3817ec3b29aSmrgEXIT_SUCCESS=0
3827ec3b29aSmrgEXIT_FAILURE=1
3837ec3b29aSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
3847ec3b29aSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
38532001f49Smrg
3867ec3b29aSmrg# Allow overriding, eg assuming that you follow the convention of
3877ec3b29aSmrg# putting '$debug_cmd' at the start of all your functions, you can get
3887ec3b29aSmrg# bash to show function call trace with:
3897ec3b29aSmrg#
3907ec3b29aSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
3917ec3b29aSmrgdebug_cmd=${debug_cmd-":"}
3927ec3b29aSmrgexit_cmd=:
39332001f49Smrg
3947ec3b29aSmrg# By convention, finish your script with:
3957ec3b29aSmrg#
3967ec3b29aSmrg#    exit $exit_status
3977ec3b29aSmrg#
3987ec3b29aSmrg# so that you can set exit_status to non-zero if you want to indicate
3997ec3b29aSmrg# something went wrong during execution without actually bailing out at
4007ec3b29aSmrg# the point of failure.
4017ec3b29aSmrgexit_status=$EXIT_SUCCESS
40232001f49Smrg
4037ec3b29aSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4047ec3b29aSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4057ec3b29aSmrg# the _XPG environment variable is not equal to 1 (one), the special
4067ec3b29aSmrg# positional parameter $0, within a function call, is the name of the
4077ec3b29aSmrg# function.
4087ec3b29aSmrgprogpath=$0
40932001f49Smrg
4107ec3b29aSmrg# The name of this program.
4117ec3b29aSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
41232001f49Smrg
4137ec3b29aSmrg# Make sure we have an absolute progpath for reexecution:
41432001f49Smrgcase $progpath in
41532001f49Smrg  [\\/]*|[A-Za-z]:\\*) ;;
41632001f49Smrg  *[\\/]*)
4177ec3b29aSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
41832001f49Smrg     progdir=`cd "$progdir" && pwd`
4197ec3b29aSmrg     progpath=$progdir/$progname
42032001f49Smrg     ;;
42132001f49Smrg  *)
4227ec3b29aSmrg     _G_IFS=$IFS
42332001f49Smrg     IFS=${PATH_SEPARATOR-:}
42432001f49Smrg     for progdir in $PATH; do
4257ec3b29aSmrg       IFS=$_G_IFS
42632001f49Smrg       test -x "$progdir/$progname" && break
42732001f49Smrg     done
4287ec3b29aSmrg     IFS=$_G_IFS
42932001f49Smrg     test -n "$progdir" || progdir=`pwd`
4307ec3b29aSmrg     progpath=$progdir/$progname
43132001f49Smrg     ;;
43232001f49Smrgesac
43332001f49Smrg
43432001f49Smrg
4357ec3b29aSmrg## ----------------- ##
4367ec3b29aSmrg## Standard options. ##
4377ec3b29aSmrg## ----------------- ##
43832001f49Smrg
4397ec3b29aSmrg# The following options affect the operation of the functions defined
4407ec3b29aSmrg# below, and should be set appropriately depending on run-time para-
4417ec3b29aSmrg# meters passed on the command line.
44232001f49Smrg
44332001f49Smrgopt_dry_run=false
44432001f49Smrgopt_quiet=false
44532001f49Smrgopt_verbose=false
44632001f49Smrg
4477ec3b29aSmrg# Categories 'all' and 'none' are always available.  Append any others
4487ec3b29aSmrg# you will pass as the first argument to func_warning from your own
4497ec3b29aSmrg# code.
4507ec3b29aSmrgwarning_categories=
45132001f49Smrg
4527ec3b29aSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4537ec3b29aSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4547ec3b29aSmrg# treat the next displayed warning as a fatal error.
4557ec3b29aSmrgwarning_func=func_warn_and_continue
45632001f49Smrg
4577ec3b29aSmrg# Set to 'all' to display all warnings, 'none' to suppress all
4587ec3b29aSmrg# warnings, or a space delimited list of some subset of
4597ec3b29aSmrg# 'warning_categories' to display only the listed warnings.
4607ec3b29aSmrgopt_warning_types=all
46132001f49Smrg
46232001f49Smrg
4637ec3b29aSmrg## -------------------- ##
4647ec3b29aSmrg## Resource management. ##
4657ec3b29aSmrg## -------------------- ##
46632001f49Smrg
4677ec3b29aSmrg# This section contains definitions for functions that each ensure a
4687ec3b29aSmrg# particular resource (a file, or a non-empty configuration variable for
4697ec3b29aSmrg# example) is available, and if appropriate to extract default values
4707ec3b29aSmrg# from pertinent package files. Call them using their associated
4717ec3b29aSmrg# 'require_*' variable to ensure that they are executed, at most, once.
4727ec3b29aSmrg#
4737ec3b29aSmrg# It's entirely deliberate that calling these functions can set
4747ec3b29aSmrg# variables that don't obey the namespace limitations obeyed by the rest
4757ec3b29aSmrg# of this file, in order that that they be as useful as possible to
4767ec3b29aSmrg# callers.
47732001f49Smrg
47832001f49Smrg
4797ec3b29aSmrg# require_term_colors
4807ec3b29aSmrg# -------------------
4817ec3b29aSmrg# Allow display of bold text on terminals that support it.
4827ec3b29aSmrgrequire_term_colors=func_require_term_colors
4837ec3b29aSmrgfunc_require_term_colors ()
48432001f49Smrg{
4857ec3b29aSmrg    $debug_cmd
4867ec3b29aSmrg
4877ec3b29aSmrg    test -t 1 && {
4887ec3b29aSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
4897ec3b29aSmrg      # precedence, because most terminfo databases neglect to describe
4907ec3b29aSmrg      # whether color sequences are supported.
4917ec3b29aSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
4927ec3b29aSmrg
4937ec3b29aSmrg      if test 1 = "$USE_ANSI_COLORS"; then
4947ec3b29aSmrg        # Standard ANSI escape sequences
4957ec3b29aSmrg        tc_reset='[0m'
4967ec3b29aSmrg        tc_bold='[1m';   tc_standout='[7m'
4977ec3b29aSmrg        tc_red='[31m';   tc_green='[32m'
4987ec3b29aSmrg        tc_blue='[34m';  tc_cyan='[36m'
4997ec3b29aSmrg      else
5007ec3b29aSmrg        # Otherwise trust the terminfo database after all.
5017ec3b29aSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5027ec3b29aSmrg          tc_reset=`tput sgr0`
5037ec3b29aSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5047ec3b29aSmrg          tc_standout=$tc_bold
5057ec3b29aSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5067ec3b29aSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5077ec3b29aSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5087ec3b29aSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5097ec3b29aSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5107ec3b29aSmrg        }
5117ec3b29aSmrg      fi
5127ec3b29aSmrg    }
51332001f49Smrg
5147ec3b29aSmrg    require_term_colors=:
51532001f49Smrg}
51632001f49Smrg
51732001f49Smrg
5187ec3b29aSmrg## ----------------- ##
5197ec3b29aSmrg## Function library. ##
5207ec3b29aSmrg## ----------------- ##
5217ec3b29aSmrg
5227ec3b29aSmrg# This section contains a variety of useful functions to call in your
5237ec3b29aSmrg# scripts. Take note of the portable wrappers for features provided by
5247ec3b29aSmrg# some modern shells, which will fall back to slower equivalents on
5257ec3b29aSmrg# less featureful shells.
5267ec3b29aSmrg
5277ec3b29aSmrg
5287ec3b29aSmrg# func_append VAR VALUE
5297ec3b29aSmrg# ---------------------
5307ec3b29aSmrg# Append VALUE onto the existing contents of VAR.
5317ec3b29aSmrg
5327ec3b29aSmrg  # We should try to minimise forks, especially on Windows where they are
5337ec3b29aSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5347ec3b29aSmrg  # being used:
5357ec3b29aSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5367ec3b29aSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5377ec3b29aSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5387ec3b29aSmrg    # The += operator was introduced in bash 3.1
5397ec3b29aSmrg    case $BASH_VERSION in
5407ec3b29aSmrg      [12].* | 3.0 | 3.0*) ;;
5417ec3b29aSmrg      *)
5427ec3b29aSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5437ec3b29aSmrg        ;;
5447ec3b29aSmrg    esac
5457ec3b29aSmrg  fi
5467ec3b29aSmrg
5477ec3b29aSmrg  # _G_HAVE_PLUSEQ_OP
5487ec3b29aSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5497ec3b29aSmrg  # useable or anything else if it does not work.
5507ec3b29aSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5517ec3b29aSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5527ec3b29aSmrg    && _G_HAVE_PLUSEQ_OP=yes
5537ec3b29aSmrg
5547ec3b29aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5557ec3b29aSmrgthen
5567ec3b29aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
5577ec3b29aSmrg  eval 'func_append ()
5587ec3b29aSmrg  {
5597ec3b29aSmrg    $debug_cmd
5607ec3b29aSmrg
5617ec3b29aSmrg    eval "$1+=\$2"
5627ec3b29aSmrg  }'
5637ec3b29aSmrgelse
5647ec3b29aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
5657ec3b29aSmrg  func_append ()
5667ec3b29aSmrg  {
5677ec3b29aSmrg    $debug_cmd
5687ec3b29aSmrg
5697ec3b29aSmrg    eval "$1=\$$1\$2"
5707ec3b29aSmrg  }
5717ec3b29aSmrgfi
5727ec3b29aSmrg
5737ec3b29aSmrg
5747ec3b29aSmrg# func_append_quoted VAR VALUE
5757ec3b29aSmrg# ----------------------------
5767ec3b29aSmrg# Quote VALUE and append to the end of shell variable VAR, separated
5777ec3b29aSmrg# by a space.
5787ec3b29aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
5797ec3b29aSmrg  eval 'func_append_quoted ()
5807ec3b29aSmrg  {
5817ec3b29aSmrg    $debug_cmd
5827ec3b29aSmrg
5837ec3b29aSmrg    func_quote_for_eval "$2"
5847ec3b29aSmrg    eval "$1+=\\ \$func_quote_for_eval_result"
5857ec3b29aSmrg  }'
5867ec3b29aSmrgelse
5877ec3b29aSmrg  func_append_quoted ()
5887ec3b29aSmrg  {
5897ec3b29aSmrg    $debug_cmd
5907ec3b29aSmrg
5917ec3b29aSmrg    func_quote_for_eval "$2"
5927ec3b29aSmrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
5937ec3b29aSmrg  }
5947ec3b29aSmrgfi
5957ec3b29aSmrg
5967ec3b29aSmrg
5977ec3b29aSmrg# func_append_uniq VAR VALUE
5987ec3b29aSmrg# --------------------------
5997ec3b29aSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6007ec3b29aSmrg# entries are delimited by the first character of VALUE.  For example:
6017ec3b29aSmrg#
6027ec3b29aSmrg#   func_append_uniq options " --another-option option-argument"
6037ec3b29aSmrg#
6047ec3b29aSmrg# will only append to $options if " --another-option option-argument "
6057ec3b29aSmrg# is not already present somewhere in $options already (note spaces at
6067ec3b29aSmrg# each end implied by leading space in second argument).
6077ec3b29aSmrgfunc_append_uniq ()
6087ec3b29aSmrg{
6097ec3b29aSmrg    $debug_cmd
6107ec3b29aSmrg
6117ec3b29aSmrg    eval _G_current_value='`$ECHO $'$1'`'
6127ec3b29aSmrg    _G_delim=`expr "$2" : '\(.\)'`
6137ec3b29aSmrg
6147ec3b29aSmrg    case $_G_delim$_G_current_value$_G_delim in
6157ec3b29aSmrg      *"$2$_G_delim"*) ;;
6167ec3b29aSmrg      *) func_append "$@" ;;
6177ec3b29aSmrg    esac
6187ec3b29aSmrg}
6197ec3b29aSmrg
6207ec3b29aSmrg
6217ec3b29aSmrg# func_arith TERM...
6227ec3b29aSmrg# ------------------
6237ec3b29aSmrg# Set func_arith_result to the result of evaluating TERMs.
6247ec3b29aSmrg  test -z "$_G_HAVE_ARITH_OP" \
6257ec3b29aSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6267ec3b29aSmrg    && _G_HAVE_ARITH_OP=yes
6277ec3b29aSmrg
6287ec3b29aSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6297ec3b29aSmrg  eval 'func_arith ()
6307ec3b29aSmrg  {
6317ec3b29aSmrg    $debug_cmd
6327ec3b29aSmrg
6337ec3b29aSmrg    func_arith_result=$(( $* ))
6347ec3b29aSmrg  }'
6357ec3b29aSmrgelse
6367ec3b29aSmrg  func_arith ()
6377ec3b29aSmrg  {
6387ec3b29aSmrg    $debug_cmd
6397ec3b29aSmrg
6407ec3b29aSmrg    func_arith_result=`expr "$@"`
6417ec3b29aSmrg  }
6427ec3b29aSmrgfi
6437ec3b29aSmrg
6447ec3b29aSmrg
6457ec3b29aSmrg# func_basename FILE
6467ec3b29aSmrg# ------------------
6477ec3b29aSmrg# Set func_basename_result to FILE with everything up to and including
6487ec3b29aSmrg# the last / stripped.
6497ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6507ec3b29aSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6517ec3b29aSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6527ec3b29aSmrg  # on unsupported syntax...
6537ec3b29aSmrg  _b='func_basename_result=${1##*/}'
6547ec3b29aSmrg  _d='case $1 in
6557ec3b29aSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6567ec3b29aSmrg        *  ) func_dirname_result=$3        ;;
6577ec3b29aSmrg      esac'
6587ec3b29aSmrg
6597ec3b29aSmrgelse
6607ec3b29aSmrg  # ...otherwise fall back to using sed.
6617ec3b29aSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
6627ec3b29aSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
6637ec3b29aSmrg      if test "X$func_dirname_result" = "X$1"; then
6647ec3b29aSmrg        func_dirname_result=$3
6657ec3b29aSmrg      else
6667ec3b29aSmrg        func_append func_dirname_result "$2"
6677ec3b29aSmrg      fi'
6687ec3b29aSmrgfi
6697ec3b29aSmrg
6707ec3b29aSmrgeval 'func_basename ()
6717ec3b29aSmrg{
6727ec3b29aSmrg    $debug_cmd
6737ec3b29aSmrg
6747ec3b29aSmrg    '"$_b"'
6757ec3b29aSmrg}'
6767ec3b29aSmrg
6777ec3b29aSmrg
6787ec3b29aSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
6797ec3b29aSmrg# -------------------------------------------
6807ec3b29aSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
6817ec3b29aSmrg# otherwise set result to NONDIR_REPLACEMENT.
6827ec3b29aSmrgeval 'func_dirname ()
6837ec3b29aSmrg{
6847ec3b29aSmrg    $debug_cmd
6857ec3b29aSmrg
6867ec3b29aSmrg    '"$_d"'
6877ec3b29aSmrg}'
6887ec3b29aSmrg
6897ec3b29aSmrg
6907ec3b29aSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
6917ec3b29aSmrg# --------------------------------------------------------
6927ec3b29aSmrg# Perform func_basename and func_dirname in a single function
6937ec3b29aSmrg# call:
6947ec3b29aSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
6957ec3b29aSmrg#             add APPEND to the result, otherwise set result
6967ec3b29aSmrg#             to NONDIR_REPLACEMENT.
6977ec3b29aSmrg#             value returned in "$func_dirname_result"
6987ec3b29aSmrg#   basename: Compute filename of FILE.
6997ec3b29aSmrg#             value retuned in "$func_basename_result"
7007ec3b29aSmrg# For efficiency, we do not delegate to the functions above but instead
7017ec3b29aSmrg# duplicate the functionality here.
7027ec3b29aSmrgeval 'func_dirname_and_basename ()
7037ec3b29aSmrg{
7047ec3b29aSmrg    $debug_cmd
7057ec3b29aSmrg
7067ec3b29aSmrg    '"$_b"'
7077ec3b29aSmrg    '"$_d"'
7087ec3b29aSmrg}'
7097ec3b29aSmrg
7107ec3b29aSmrg
7117ec3b29aSmrg# func_echo ARG...
7127ec3b29aSmrg# ----------------
7137ec3b29aSmrg# Echo program name prefixed message.
7147ec3b29aSmrgfunc_echo ()
7157ec3b29aSmrg{
7167ec3b29aSmrg    $debug_cmd
7177ec3b29aSmrg
7187ec3b29aSmrg    _G_message=$*
7197ec3b29aSmrg
7207ec3b29aSmrg    func_echo_IFS=$IFS
7217ec3b29aSmrg    IFS=$nl
7227ec3b29aSmrg    for _G_line in $_G_message; do
7237ec3b29aSmrg      IFS=$func_echo_IFS
7247ec3b29aSmrg      $ECHO "$progname: $_G_line"
7257ec3b29aSmrg    done
7267ec3b29aSmrg    IFS=$func_echo_IFS
7277ec3b29aSmrg}
7287ec3b29aSmrg
7297ec3b29aSmrg
7307ec3b29aSmrg# func_echo_all ARG...
7317ec3b29aSmrg# --------------------
7327ec3b29aSmrg# Invoke $ECHO with all args, space-separated.
7337ec3b29aSmrgfunc_echo_all ()
7347ec3b29aSmrg{
7357ec3b29aSmrg    $ECHO "$*"
7367ec3b29aSmrg}
7377ec3b29aSmrg
7387ec3b29aSmrg
7397ec3b29aSmrg# func_echo_infix_1 INFIX ARG...
7407ec3b29aSmrg# ------------------------------
7417ec3b29aSmrg# Echo program name, followed by INFIX on the first line, with any
7427ec3b29aSmrg# additional lines not showing INFIX.
7437ec3b29aSmrgfunc_echo_infix_1 ()
7447ec3b29aSmrg{
7457ec3b29aSmrg    $debug_cmd
7467ec3b29aSmrg
7477ec3b29aSmrg    $require_term_colors
7487ec3b29aSmrg
7497ec3b29aSmrg    _G_infix=$1; shift
7507ec3b29aSmrg    _G_indent=$_G_infix
7517ec3b29aSmrg    _G_prefix="$progname: $_G_infix: "
7527ec3b29aSmrg    _G_message=$*
7537ec3b29aSmrg
7547ec3b29aSmrg    # Strip color escape sequences before counting printable length
7557ec3b29aSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7567ec3b29aSmrg    do
7577ec3b29aSmrg      test -n "$_G_tc" && {
7587ec3b29aSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
7597ec3b29aSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
7607ec3b29aSmrg      }
7617ec3b29aSmrg    done
7627ec3b29aSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
7637ec3b29aSmrg
7647ec3b29aSmrg    func_echo_infix_1_IFS=$IFS
7657ec3b29aSmrg    IFS=$nl
7667ec3b29aSmrg    for _G_line in $_G_message; do
7677ec3b29aSmrg      IFS=$func_echo_infix_1_IFS
7687ec3b29aSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
7697ec3b29aSmrg      _G_prefix=$_G_indent
7707ec3b29aSmrg    done
7717ec3b29aSmrg    IFS=$func_echo_infix_1_IFS
7727ec3b29aSmrg}
7737ec3b29aSmrg
7747ec3b29aSmrg
7757ec3b29aSmrg# func_error ARG...
7767ec3b29aSmrg# -----------------
7777ec3b29aSmrg# Echo program name prefixed message to standard error.
7787ec3b29aSmrgfunc_error ()
7797ec3b29aSmrg{
7807ec3b29aSmrg    $debug_cmd
7817ec3b29aSmrg
7827ec3b29aSmrg    $require_term_colors
7837ec3b29aSmrg
7847ec3b29aSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
7857ec3b29aSmrg}
7867ec3b29aSmrg
7877ec3b29aSmrg
7887ec3b29aSmrg# func_fatal_error ARG...
7897ec3b29aSmrg# -----------------------
7907ec3b29aSmrg# Echo program name prefixed message to standard error, and exit.
7917ec3b29aSmrgfunc_fatal_error ()
7927ec3b29aSmrg{
7937ec3b29aSmrg    $debug_cmd
7947ec3b29aSmrg
7957ec3b29aSmrg    func_error "$*"
7967ec3b29aSmrg    exit $EXIT_FAILURE
7977ec3b29aSmrg}
7987ec3b29aSmrg
7997ec3b29aSmrg
8007ec3b29aSmrg# func_grep EXPRESSION FILENAME
8017ec3b29aSmrg# -----------------------------
80232001f49Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
80332001f49Smrgfunc_grep ()
80432001f49Smrg{
8057ec3b29aSmrg    $debug_cmd
8067ec3b29aSmrg
80732001f49Smrg    $GREP "$1" "$2" >/dev/null 2>&1
80832001f49Smrg}
80932001f49Smrg
81032001f49Smrg
8117ec3b29aSmrg# func_len STRING
8127ec3b29aSmrg# ---------------
8137ec3b29aSmrg# Set func_len_result to the length of STRING. STRING may not
8147ec3b29aSmrg# start with a hyphen.
8157ec3b29aSmrg  test -z "$_G_HAVE_XSI_OPS" \
8167ec3b29aSmrg    && (eval 'x=a/b/c;
8177ec3b29aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8187ec3b29aSmrg    && _G_HAVE_XSI_OPS=yes
8197ec3b29aSmrg
8207ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8217ec3b29aSmrg  eval 'func_len ()
8227ec3b29aSmrg  {
8237ec3b29aSmrg    $debug_cmd
8247ec3b29aSmrg
8257ec3b29aSmrg    func_len_result=${#1}
8267ec3b29aSmrg  }'
8277ec3b29aSmrgelse
8287ec3b29aSmrg  func_len ()
8297ec3b29aSmrg  {
8307ec3b29aSmrg    $debug_cmd
8317ec3b29aSmrg
8327ec3b29aSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8337ec3b29aSmrg  }
8347ec3b29aSmrgfi
8357ec3b29aSmrg
8367ec3b29aSmrg
8377ec3b29aSmrg# func_mkdir_p DIRECTORY-PATH
8387ec3b29aSmrg# ---------------------------
83932001f49Smrg# Make sure the entire path to DIRECTORY-PATH is available.
84032001f49Smrgfunc_mkdir_p ()
84132001f49Smrg{
8427ec3b29aSmrg    $debug_cmd
84332001f49Smrg
8447ec3b29aSmrg    _G_directory_path=$1
8457ec3b29aSmrg    _G_dir_list=
84632001f49Smrg
8477ec3b29aSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8487ec3b29aSmrg
8497ec3b29aSmrg      # Protect directory names starting with '-'
8507ec3b29aSmrg      case $_G_directory_path in
8517ec3b29aSmrg        -*) _G_directory_path=./$_G_directory_path ;;
85232001f49Smrg      esac
85332001f49Smrg
85432001f49Smrg      # While some portion of DIR does not yet exist...
8557ec3b29aSmrg      while test ! -d "$_G_directory_path"; do
85632001f49Smrg        # ...make a list in topmost first order.  Use a colon delimited
85732001f49Smrg	# list incase some portion of path contains whitespace.
8587ec3b29aSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
85932001f49Smrg
86032001f49Smrg        # If the last portion added has no slash in it, the list is done
8617ec3b29aSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
86232001f49Smrg
86332001f49Smrg        # ...otherwise throw away the child directory and loop
8647ec3b29aSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
86532001f49Smrg      done
8667ec3b29aSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
86732001f49Smrg
8687ec3b29aSmrg      func_mkdir_p_IFS=$IFS; IFS=:
8697ec3b29aSmrg      for _G_dir in $_G_dir_list; do
8707ec3b29aSmrg	IFS=$func_mkdir_p_IFS
8717ec3b29aSmrg        # mkdir can fail with a 'File exist' error if two processes
87232001f49Smrg        # try to create one of the directories concurrently.  Don't
87332001f49Smrg        # stop in that case!
8747ec3b29aSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
87532001f49Smrg      done
8767ec3b29aSmrg      IFS=$func_mkdir_p_IFS
87732001f49Smrg
87832001f49Smrg      # Bail out if we (or some other process) failed to create a directory.
8797ec3b29aSmrg      test -d "$_G_directory_path" || \
8807ec3b29aSmrg        func_fatal_error "Failed to create '$1'"
88132001f49Smrg    fi
88232001f49Smrg}
88332001f49Smrg
88432001f49Smrg
8857ec3b29aSmrg# func_mktempdir [BASENAME]
8867ec3b29aSmrg# -------------------------
88732001f49Smrg# Make a temporary directory that won't clash with other running
88832001f49Smrg# libtool processes, and avoids race conditions if possible.  If
8897ec3b29aSmrg# given, BASENAME is the basename for that directory.
89032001f49Smrgfunc_mktempdir ()
89132001f49Smrg{
8927ec3b29aSmrg    $debug_cmd
8937ec3b29aSmrg
8947ec3b29aSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
89532001f49Smrg
8967ec3b29aSmrg    if test : = "$opt_dry_run"; then
89732001f49Smrg      # Return a directory name, but don't create it in dry-run mode
8987ec3b29aSmrg      _G_tmpdir=$_G_template-$$
89932001f49Smrg    else
90032001f49Smrg
90132001f49Smrg      # If mktemp works, use that first and foremost
9027ec3b29aSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
90332001f49Smrg
9047ec3b29aSmrg      if test ! -d "$_G_tmpdir"; then
90532001f49Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9067ec3b29aSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
90732001f49Smrg
9087ec3b29aSmrg        func_mktempdir_umask=`umask`
90932001f49Smrg        umask 0077
9107ec3b29aSmrg        $MKDIR "$_G_tmpdir"
9117ec3b29aSmrg        umask $func_mktempdir_umask
91232001f49Smrg      fi
91332001f49Smrg
91432001f49Smrg      # If we're not in dry-run mode, bomb out on failure
9157ec3b29aSmrg      test -d "$_G_tmpdir" || \
9167ec3b29aSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9177ec3b29aSmrg    fi
9187ec3b29aSmrg
9197ec3b29aSmrg    $ECHO "$_G_tmpdir"
9207ec3b29aSmrg}
9217ec3b29aSmrg
9227ec3b29aSmrg
9237ec3b29aSmrg# func_normal_abspath PATH
9247ec3b29aSmrg# ------------------------
9257ec3b29aSmrg# Remove doubled-up and trailing slashes, "." path components,
9267ec3b29aSmrg# and cancel out any ".." path components in PATH after making
9277ec3b29aSmrg# it an absolute path.
9287ec3b29aSmrgfunc_normal_abspath ()
9297ec3b29aSmrg{
9307ec3b29aSmrg    $debug_cmd
9317ec3b29aSmrg
9327ec3b29aSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9337ec3b29aSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9347ec3b29aSmrg    _G_pathcdr='s|^/[^/]*||'
9357ec3b29aSmrg    _G_removedotparts=':dotsl
9367ec3b29aSmrg		s|/\./|/|g
9377ec3b29aSmrg		t dotsl
9387ec3b29aSmrg		s|/\.$|/|'
9397ec3b29aSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9407ec3b29aSmrg    _G_finalslash='s|/*$|/|'
9417ec3b29aSmrg
9427ec3b29aSmrg    # Start from root dir and reassemble the path.
9437ec3b29aSmrg    func_normal_abspath_result=
9447ec3b29aSmrg    func_normal_abspath_tpath=$1
9457ec3b29aSmrg    func_normal_abspath_altnamespace=
9467ec3b29aSmrg    case $func_normal_abspath_tpath in
9477ec3b29aSmrg      "")
9487ec3b29aSmrg        # Empty path, that just means $cwd.
9497ec3b29aSmrg        func_stripname '' '/' "`pwd`"
9507ec3b29aSmrg        func_normal_abspath_result=$func_stripname_result
9517ec3b29aSmrg        return
9527ec3b29aSmrg        ;;
9537ec3b29aSmrg      # The next three entries are used to spot a run of precisely
9547ec3b29aSmrg      # two leading slashes without using negated character classes;
9557ec3b29aSmrg      # we take advantage of case's first-match behaviour.
9567ec3b29aSmrg      ///*)
9577ec3b29aSmrg        # Unusual form of absolute path, do nothing.
9587ec3b29aSmrg        ;;
9597ec3b29aSmrg      //*)
9607ec3b29aSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
9617ec3b29aSmrg        # and for example Cygwin uses it to access remote file shares
9627ec3b29aSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
9637ec3b29aSmrg        func_normal_abspath_altnamespace=/
9647ec3b29aSmrg        ;;
9657ec3b29aSmrg      /*)
9667ec3b29aSmrg        # Absolute path, do nothing.
9677ec3b29aSmrg        ;;
9687ec3b29aSmrg      *)
9697ec3b29aSmrg        # Relative path, prepend $cwd.
9707ec3b29aSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
9717ec3b29aSmrg        ;;
9727ec3b29aSmrg    esac
9737ec3b29aSmrg
9747ec3b29aSmrg    # Cancel out all the simple stuff to save iterations.  We also want
9757ec3b29aSmrg    # the path to end with a slash for ease of parsing, so make sure
9767ec3b29aSmrg    # there is one (and only one) here.
9777ec3b29aSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
9787ec3b29aSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
9797ec3b29aSmrg    while :; do
9807ec3b29aSmrg      # Processed it all yet?
9817ec3b29aSmrg      if test / = "$func_normal_abspath_tpath"; then
9827ec3b29aSmrg        # If we ascended to the root using ".." the result may be empty now.
9837ec3b29aSmrg        if test -z "$func_normal_abspath_result"; then
9847ec3b29aSmrg          func_normal_abspath_result=/
9857ec3b29aSmrg        fi
9867ec3b29aSmrg        break
9877ec3b29aSmrg      fi
9887ec3b29aSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
9897ec3b29aSmrg          -e "$_G_pathcar"`
9907ec3b29aSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
9917ec3b29aSmrg          -e "$_G_pathcdr"`
9927ec3b29aSmrg      # Figure out what to do with it
9937ec3b29aSmrg      case $func_normal_abspath_tcomponent in
9947ec3b29aSmrg        "")
9957ec3b29aSmrg          # Trailing empty path component, ignore it.
9967ec3b29aSmrg          ;;
9977ec3b29aSmrg        ..)
9987ec3b29aSmrg          # Parent dir; strip last assembled component from result.
9997ec3b29aSmrg          func_dirname "$func_normal_abspath_result"
10007ec3b29aSmrg          func_normal_abspath_result=$func_dirname_result
10017ec3b29aSmrg          ;;
10027ec3b29aSmrg        *)
10037ec3b29aSmrg          # Actual path component, append it.
10047ec3b29aSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10057ec3b29aSmrg          ;;
10067ec3b29aSmrg      esac
10077ec3b29aSmrg    done
10087ec3b29aSmrg    # Restore leading double-slash if one was found on entry.
10097ec3b29aSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10107ec3b29aSmrg}
10117ec3b29aSmrg
10127ec3b29aSmrg
10137ec3b29aSmrg# func_notquiet ARG...
10147ec3b29aSmrg# --------------------
10157ec3b29aSmrg# Echo program name prefixed message only when not in quiet mode.
10167ec3b29aSmrgfunc_notquiet ()
10177ec3b29aSmrg{
10187ec3b29aSmrg    $debug_cmd
10197ec3b29aSmrg
10207ec3b29aSmrg    $opt_quiet || func_echo ${1+"$@"}
10217ec3b29aSmrg
10227ec3b29aSmrg    # A bug in bash halts the script if the last line of a function
10237ec3b29aSmrg    # fails when set -e is in force, so we need another command to
10247ec3b29aSmrg    # work around that:
10257ec3b29aSmrg    :
10267ec3b29aSmrg}
10277ec3b29aSmrg
10287ec3b29aSmrg
10297ec3b29aSmrg# func_relative_path SRCDIR DSTDIR
10307ec3b29aSmrg# --------------------------------
10317ec3b29aSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10327ec3b29aSmrgfunc_relative_path ()
10337ec3b29aSmrg{
10347ec3b29aSmrg    $debug_cmd
10357ec3b29aSmrg
10367ec3b29aSmrg    func_relative_path_result=
10377ec3b29aSmrg    func_normal_abspath "$1"
10387ec3b29aSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10397ec3b29aSmrg    func_normal_abspath "$2"
10407ec3b29aSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10417ec3b29aSmrg
10427ec3b29aSmrg    # Ascend the tree starting from libdir
10437ec3b29aSmrg    while :; do
10447ec3b29aSmrg      # check if we have found a prefix of bindir
10457ec3b29aSmrg      case $func_relative_path_tbindir in
10467ec3b29aSmrg        $func_relative_path_tlibdir)
10477ec3b29aSmrg          # found an exact match
10487ec3b29aSmrg          func_relative_path_tcancelled=
10497ec3b29aSmrg          break
10507ec3b29aSmrg          ;;
10517ec3b29aSmrg        $func_relative_path_tlibdir*)
10527ec3b29aSmrg          # found a matching prefix
10537ec3b29aSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10547ec3b29aSmrg          func_relative_path_tcancelled=$func_stripname_result
10557ec3b29aSmrg          if test -z "$func_relative_path_result"; then
10567ec3b29aSmrg            func_relative_path_result=.
10577ec3b29aSmrg          fi
10587ec3b29aSmrg          break
10597ec3b29aSmrg          ;;
10607ec3b29aSmrg        *)
10617ec3b29aSmrg          func_dirname $func_relative_path_tlibdir
10627ec3b29aSmrg          func_relative_path_tlibdir=$func_dirname_result
10637ec3b29aSmrg          if test -z "$func_relative_path_tlibdir"; then
10647ec3b29aSmrg            # Have to descend all the way to the root!
10657ec3b29aSmrg            func_relative_path_result=../$func_relative_path_result
10667ec3b29aSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
10677ec3b29aSmrg            break
10687ec3b29aSmrg          fi
10697ec3b29aSmrg          func_relative_path_result=../$func_relative_path_result
10707ec3b29aSmrg          ;;
10717ec3b29aSmrg      esac
10727ec3b29aSmrg    done
10737ec3b29aSmrg
10747ec3b29aSmrg    # Now calculate path; take care to avoid doubling-up slashes.
10757ec3b29aSmrg    func_stripname '' '/' "$func_relative_path_result"
10767ec3b29aSmrg    func_relative_path_result=$func_stripname_result
10777ec3b29aSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
10787ec3b29aSmrg    if test -n "$func_stripname_result"; then
10797ec3b29aSmrg      func_append func_relative_path_result "/$func_stripname_result"
10807ec3b29aSmrg    fi
10817ec3b29aSmrg
10827ec3b29aSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
10837ec3b29aSmrg    if test -n "$func_relative_path_result"; then
10847ec3b29aSmrg      func_stripname './' '' "$func_relative_path_result"
10857ec3b29aSmrg      func_relative_path_result=$func_stripname_result
108632001f49Smrg    fi
108732001f49Smrg
10887ec3b29aSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
10897ec3b29aSmrg
10907ec3b29aSmrg    :
10917ec3b29aSmrg}
10927ec3b29aSmrg
10937ec3b29aSmrg
10947ec3b29aSmrg# func_quote_for_eval ARG...
10957ec3b29aSmrg# --------------------------
10967ec3b29aSmrg# Aesthetically quote ARGs to be evaled later.
10977ec3b29aSmrg# This function returns two values:
10987ec3b29aSmrg#   i) func_quote_for_eval_result
10997ec3b29aSmrg#      double-quoted, suitable for a subsequent eval
11007ec3b29aSmrg#  ii) func_quote_for_eval_unquoted_result
11017ec3b29aSmrg#      has all characters that are still active within double
11027ec3b29aSmrg#      quotes backslashified.
11037ec3b29aSmrgfunc_quote_for_eval ()
11047ec3b29aSmrg{
11057ec3b29aSmrg    $debug_cmd
11067ec3b29aSmrg
11077ec3b29aSmrg    func_quote_for_eval_unquoted_result=
11087ec3b29aSmrg    func_quote_for_eval_result=
11097ec3b29aSmrg    while test 0 -lt $#; do
11107ec3b29aSmrg      case $1 in
11117ec3b29aSmrg        *[\\\`\"\$]*)
11127ec3b29aSmrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
11137ec3b29aSmrg        *)
11147ec3b29aSmrg          _G_unquoted_arg=$1 ;;
11157ec3b29aSmrg      esac
11167ec3b29aSmrg      if test -n "$func_quote_for_eval_unquoted_result"; then
11177ec3b29aSmrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
11187ec3b29aSmrg      else
11197ec3b29aSmrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
11207ec3b29aSmrg      fi
11217ec3b29aSmrg
11227ec3b29aSmrg      case $_G_unquoted_arg in
11237ec3b29aSmrg        # Double-quote args containing shell metacharacters to delay
11247ec3b29aSmrg        # word splitting, command substitution and variable expansion
11257ec3b29aSmrg        # for a subsequent eval.
11267ec3b29aSmrg        # Many Bourne shells cannot handle close brackets correctly
11277ec3b29aSmrg        # in scan sets, so we specify it separately.
11287ec3b29aSmrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
11297ec3b29aSmrg          _G_quoted_arg=\"$_G_unquoted_arg\"
11307ec3b29aSmrg          ;;
11317ec3b29aSmrg        *)
11327ec3b29aSmrg          _G_quoted_arg=$_G_unquoted_arg
11337ec3b29aSmrg	  ;;
11347ec3b29aSmrg      esac
11357ec3b29aSmrg
11367ec3b29aSmrg      if test -n "$func_quote_for_eval_result"; then
11377ec3b29aSmrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
11387ec3b29aSmrg      else
11397ec3b29aSmrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
11407ec3b29aSmrg      fi
11417ec3b29aSmrg      shift
11427ec3b29aSmrg    done
11437ec3b29aSmrg}
11447ec3b29aSmrg
11457ec3b29aSmrg
11467ec3b29aSmrg# func_quote_for_expand ARG
11477ec3b29aSmrg# -------------------------
11487ec3b29aSmrg# Aesthetically quote ARG to be evaled later; same as above,
11497ec3b29aSmrg# but do not quote variable references.
11507ec3b29aSmrgfunc_quote_for_expand ()
11517ec3b29aSmrg{
11527ec3b29aSmrg    $debug_cmd
11537ec3b29aSmrg
11547ec3b29aSmrg    case $1 in
11557ec3b29aSmrg      *[\\\`\"]*)
11567ec3b29aSmrg	_G_arg=`$ECHO "$1" | $SED \
11577ec3b29aSmrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
11587ec3b29aSmrg      *)
11597ec3b29aSmrg        _G_arg=$1 ;;
11607ec3b29aSmrg    esac
11617ec3b29aSmrg
11627ec3b29aSmrg    case $_G_arg in
11637ec3b29aSmrg      # Double-quote args containing shell metacharacters to delay
11647ec3b29aSmrg      # word splitting and command substitution for a subsequent eval.
11657ec3b29aSmrg      # Many Bourne shells cannot handle close brackets correctly
11667ec3b29aSmrg      # in scan sets, so we specify it separately.
11677ec3b29aSmrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
11687ec3b29aSmrg        _G_arg=\"$_G_arg\"
11697ec3b29aSmrg        ;;
11707ec3b29aSmrg    esac
11717ec3b29aSmrg
11727ec3b29aSmrg    func_quote_for_expand_result=$_G_arg
11737ec3b29aSmrg}
11747ec3b29aSmrg
11757ec3b29aSmrg
11767ec3b29aSmrg# func_stripname PREFIX SUFFIX NAME
11777ec3b29aSmrg# ---------------------------------
11787ec3b29aSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
11797ec3b29aSmrg# PREFIX and SUFFIX must not contain globbing or regex special
11807ec3b29aSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
11817ec3b29aSmrg# dot (in which case that matches only a dot).
11827ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
11837ec3b29aSmrg  eval 'func_stripname ()
11847ec3b29aSmrg  {
11857ec3b29aSmrg    $debug_cmd
11867ec3b29aSmrg
11877ec3b29aSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
11887ec3b29aSmrg    # positional parameters, so assign one to ordinary variable first.
11897ec3b29aSmrg    func_stripname_result=$3
11907ec3b29aSmrg    func_stripname_result=${func_stripname_result#"$1"}
11917ec3b29aSmrg    func_stripname_result=${func_stripname_result%"$2"}
11927ec3b29aSmrg  }'
11937ec3b29aSmrgelse
11947ec3b29aSmrg  func_stripname ()
11957ec3b29aSmrg  {
11967ec3b29aSmrg    $debug_cmd
11977ec3b29aSmrg
11987ec3b29aSmrg    case $2 in
11997ec3b29aSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
12007ec3b29aSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
12017ec3b29aSmrg    esac
12027ec3b29aSmrg  }
12037ec3b29aSmrgfi
12047ec3b29aSmrg
12057ec3b29aSmrg
12067ec3b29aSmrg# func_show_eval CMD [FAIL_EXP]
12077ec3b29aSmrg# -----------------------------
12087ec3b29aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12097ec3b29aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12107ec3b29aSmrg# is given, then evaluate it.
12117ec3b29aSmrgfunc_show_eval ()
12127ec3b29aSmrg{
12137ec3b29aSmrg    $debug_cmd
12147ec3b29aSmrg
12157ec3b29aSmrg    _G_cmd=$1
12167ec3b29aSmrg    _G_fail_exp=${2-':'}
12177ec3b29aSmrg
12187ec3b29aSmrg    func_quote_for_expand "$_G_cmd"
12197ec3b29aSmrg    eval "func_notquiet $func_quote_for_expand_result"
12207ec3b29aSmrg
12217ec3b29aSmrg    $opt_dry_run || {
12227ec3b29aSmrg      eval "$_G_cmd"
12237ec3b29aSmrg      _G_status=$?
12247ec3b29aSmrg      if test 0 -ne "$_G_status"; then
12257ec3b29aSmrg	eval "(exit $_G_status); $_G_fail_exp"
12267ec3b29aSmrg      fi
12277ec3b29aSmrg    }
12287ec3b29aSmrg}
12297ec3b29aSmrg
12307ec3b29aSmrg
12317ec3b29aSmrg# func_show_eval_locale CMD [FAIL_EXP]
12327ec3b29aSmrg# ------------------------------------
12337ec3b29aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12347ec3b29aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12357ec3b29aSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
12367ec3b29aSmrgfunc_show_eval_locale ()
12377ec3b29aSmrg{
12387ec3b29aSmrg    $debug_cmd
12397ec3b29aSmrg
12407ec3b29aSmrg    _G_cmd=$1
12417ec3b29aSmrg    _G_fail_exp=${2-':'}
12427ec3b29aSmrg
12437ec3b29aSmrg    $opt_quiet || {
12447ec3b29aSmrg      func_quote_for_expand "$_G_cmd"
12457ec3b29aSmrg      eval "func_echo $func_quote_for_expand_result"
12467ec3b29aSmrg    }
12477ec3b29aSmrg
12487ec3b29aSmrg    $opt_dry_run || {
12497ec3b29aSmrg      eval "$_G_user_locale
12507ec3b29aSmrg	    $_G_cmd"
12517ec3b29aSmrg      _G_status=$?
12527ec3b29aSmrg      eval "$_G_safe_locale"
12537ec3b29aSmrg      if test 0 -ne "$_G_status"; then
12547ec3b29aSmrg	eval "(exit $_G_status); $_G_fail_exp"
12557ec3b29aSmrg      fi
12567ec3b29aSmrg    }
12577ec3b29aSmrg}
12587ec3b29aSmrg
12597ec3b29aSmrg
12607ec3b29aSmrg# func_tr_sh
12617ec3b29aSmrg# ----------
12627ec3b29aSmrg# Turn $1 into a string suitable for a shell variable name.
12637ec3b29aSmrg# Result is stored in $func_tr_sh_result.  All characters
12647ec3b29aSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
12657ec3b29aSmrg# if $1 begins with a digit, a '_' is prepended as well.
12667ec3b29aSmrgfunc_tr_sh ()
12677ec3b29aSmrg{
12687ec3b29aSmrg    $debug_cmd
12697ec3b29aSmrg
12707ec3b29aSmrg    case $1 in
12717ec3b29aSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
12727ec3b29aSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
12737ec3b29aSmrg      ;;
12747ec3b29aSmrg    * )
12757ec3b29aSmrg      func_tr_sh_result=$1
12767ec3b29aSmrg      ;;
12777ec3b29aSmrg    esac
12787ec3b29aSmrg}
12797ec3b29aSmrg
12807ec3b29aSmrg
12817ec3b29aSmrg# func_verbose ARG...
12827ec3b29aSmrg# -------------------
12837ec3b29aSmrg# Echo program name prefixed message in verbose mode only.
12847ec3b29aSmrgfunc_verbose ()
12857ec3b29aSmrg{
12867ec3b29aSmrg    $debug_cmd
12877ec3b29aSmrg
12887ec3b29aSmrg    $opt_verbose && func_echo "$*"
12897ec3b29aSmrg
12907ec3b29aSmrg    :
12917ec3b29aSmrg}
12927ec3b29aSmrg
12937ec3b29aSmrg
12947ec3b29aSmrg# func_warn_and_continue ARG...
12957ec3b29aSmrg# -----------------------------
12967ec3b29aSmrg# Echo program name prefixed warning message to standard error.
12977ec3b29aSmrgfunc_warn_and_continue ()
12987ec3b29aSmrg{
12997ec3b29aSmrg    $debug_cmd
13007ec3b29aSmrg
13017ec3b29aSmrg    $require_term_colors
13027ec3b29aSmrg
13037ec3b29aSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
13047ec3b29aSmrg}
13057ec3b29aSmrg
13067ec3b29aSmrg
13077ec3b29aSmrg# func_warning CATEGORY ARG...
13087ec3b29aSmrg# ----------------------------
13097ec3b29aSmrg# Echo program name prefixed warning message to standard error. Warning
13107ec3b29aSmrg# messages can be filtered according to CATEGORY, where this function
13117ec3b29aSmrg# elides messages where CATEGORY is not listed in the global variable
13127ec3b29aSmrg# 'opt_warning_types'.
13137ec3b29aSmrgfunc_warning ()
13147ec3b29aSmrg{
13157ec3b29aSmrg    $debug_cmd
13167ec3b29aSmrg
13177ec3b29aSmrg    # CATEGORY must be in the warning_categories list!
13187ec3b29aSmrg    case " $warning_categories " in
13197ec3b29aSmrg      *" $1 "*) ;;
13207ec3b29aSmrg      *) func_internal_error "invalid warning category '$1'" ;;
13217ec3b29aSmrg    esac
13227ec3b29aSmrg
13237ec3b29aSmrg    _G_category=$1
13247ec3b29aSmrg    shift
13257ec3b29aSmrg
13267ec3b29aSmrg    case " $opt_warning_types " in
13277ec3b29aSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
13287ec3b29aSmrg    esac
13297ec3b29aSmrg}
13307ec3b29aSmrg
13317ec3b29aSmrg
13327ec3b29aSmrg# func_sort_ver VER1 VER2
13337ec3b29aSmrg# -----------------------
13347ec3b29aSmrg# 'sort -V' is not generally available.
13357ec3b29aSmrg# Note this deviates from the version comparison in automake
13367ec3b29aSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
13377ec3b29aSmrg# but this should suffice as we won't be specifying old
13387ec3b29aSmrg# version formats or redundant trailing .0 in bootstrap.conf.
13397ec3b29aSmrg# If we did want full compatibility then we should probably
13407ec3b29aSmrg# use m4_version_compare from autoconf.
13417ec3b29aSmrgfunc_sort_ver ()
13427ec3b29aSmrg{
13437ec3b29aSmrg    $debug_cmd
13447ec3b29aSmrg
13457ec3b29aSmrg    printf '%s\n%s\n' "$1" "$2" \
13467ec3b29aSmrg      | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n
13477ec3b29aSmrg}
13487ec3b29aSmrg
13497ec3b29aSmrg# func_lt_ver PREV CURR
13507ec3b29aSmrg# ---------------------
13517ec3b29aSmrg# Return true if PREV and CURR are in the correct order according to
13527ec3b29aSmrg# func_sort_ver, otherwise false.  Use it like this:
13537ec3b29aSmrg#
13547ec3b29aSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
13557ec3b29aSmrgfunc_lt_ver ()
13567ec3b29aSmrg{
13577ec3b29aSmrg    $debug_cmd
13587ec3b29aSmrg
13597ec3b29aSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
13607ec3b29aSmrg}
13617ec3b29aSmrg
13627ec3b29aSmrg
13637ec3b29aSmrg# Local variables:
13647ec3b29aSmrg# mode: shell-script
13657ec3b29aSmrg# sh-indentation: 2
13667ec3b29aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
13677ec3b29aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
13687ec3b29aSmrg# time-stamp-time-zone: "UTC"
13697ec3b29aSmrg# End:
13707ec3b29aSmrg#! /bin/sh
13717ec3b29aSmrg
13727ec3b29aSmrg# Set a version string for this script.
13737ec3b29aSmrgscriptversion=2014-01-07.03; # UTC
13747ec3b29aSmrg
13757ec3b29aSmrg# A portable, pluggable option parser for Bourne shell.
13767ec3b29aSmrg# Written by Gary V. Vaughan, 2010
13777ec3b29aSmrg
13787ec3b29aSmrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
13797ec3b29aSmrg# This is free software; see the source for copying conditions.  There is NO
13807ec3b29aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13817ec3b29aSmrg
13827ec3b29aSmrg# This program is free software: you can redistribute it and/or modify
13837ec3b29aSmrg# it under the terms of the GNU General Public License as published by
13847ec3b29aSmrg# the Free Software Foundation, either version 3 of the License, or
13857ec3b29aSmrg# (at your option) any later version.
13867ec3b29aSmrg
13877ec3b29aSmrg# This program is distributed in the hope that it will be useful,
13887ec3b29aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
13897ec3b29aSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13907ec3b29aSmrg# GNU General Public License for more details.
13917ec3b29aSmrg
13927ec3b29aSmrg# You should have received a copy of the GNU General Public License
13937ec3b29aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13947ec3b29aSmrg
13957ec3b29aSmrg# Please report bugs or propose patches to gary@gnu.org.
13967ec3b29aSmrg
13977ec3b29aSmrg
13987ec3b29aSmrg## ------ ##
13997ec3b29aSmrg## Usage. ##
14007ec3b29aSmrg## ------ ##
14017ec3b29aSmrg
14027ec3b29aSmrg# This file is a library for parsing options in your shell scripts along
14037ec3b29aSmrg# with assorted other useful supporting features that you can make use
14047ec3b29aSmrg# of too.
14057ec3b29aSmrg#
14067ec3b29aSmrg# For the simplest scripts you might need only:
14077ec3b29aSmrg#
14087ec3b29aSmrg#   #!/bin/sh
14097ec3b29aSmrg#   . relative/path/to/funclib.sh
14107ec3b29aSmrg#   . relative/path/to/options-parser
14117ec3b29aSmrg#   scriptversion=1.0
14127ec3b29aSmrg#   func_options ${1+"$@"}
14137ec3b29aSmrg#   eval set dummy "$func_options_result"; shift
14147ec3b29aSmrg#   ...rest of your script...
14157ec3b29aSmrg#
14167ec3b29aSmrg# In order for the '--version' option to work, you will need to have a
14177ec3b29aSmrg# suitably formatted comment like the one at the top of this file
14187ec3b29aSmrg# starting with '# Written by ' and ending with '# warranty; '.
14197ec3b29aSmrg#
14207ec3b29aSmrg# For '-h' and '--help' to work, you will also need a one line
14217ec3b29aSmrg# description of your script's purpose in a comment directly above the
14227ec3b29aSmrg# '# Written by ' line, like the one at the top of this file.
14237ec3b29aSmrg#
14247ec3b29aSmrg# The default options also support '--debug', which will turn on shell
14257ec3b29aSmrg# execution tracing (see the comment above debug_cmd below for another
14267ec3b29aSmrg# use), and '--verbose' and the func_verbose function to allow your script
14277ec3b29aSmrg# to display verbose messages only when your user has specified
14287ec3b29aSmrg# '--verbose'.
14297ec3b29aSmrg#
14307ec3b29aSmrg# After sourcing this file, you can plug processing for additional
14317ec3b29aSmrg# options by amending the variables from the 'Configuration' section
14327ec3b29aSmrg# below, and following the instructions in the 'Option parsing'
14337ec3b29aSmrg# section further down.
14347ec3b29aSmrg
14357ec3b29aSmrg## -------------- ##
14367ec3b29aSmrg## Configuration. ##
14377ec3b29aSmrg## -------------- ##
14387ec3b29aSmrg
14397ec3b29aSmrg# You should override these variables in your script after sourcing this
14407ec3b29aSmrg# file so that they reflect the customisations you have added to the
14417ec3b29aSmrg# option parser.
14427ec3b29aSmrg
14437ec3b29aSmrg# The usage line for option parsing errors and the start of '-h' and
14447ec3b29aSmrg# '--help' output messages. You can embed shell variables for delayed
14457ec3b29aSmrg# expansion at the time the message is displayed, but you will need to
14467ec3b29aSmrg# quote other shell meta-characters carefully to prevent them being
14477ec3b29aSmrg# expanded when the contents are evaled.
14487ec3b29aSmrgusage='$progpath [OPTION]...'
14497ec3b29aSmrg
14507ec3b29aSmrg# Short help message in response to '-h' and '--help'.  Add to this or
14517ec3b29aSmrg# override it after sourcing this library to reflect the full set of
14527ec3b29aSmrg# options your script accepts.
14537ec3b29aSmrgusage_message="\
14547ec3b29aSmrg       --debug        enable verbose shell tracing
14557ec3b29aSmrg   -W, --warnings=CATEGORY
14567ec3b29aSmrg                      report the warnings falling in CATEGORY [all]
14577ec3b29aSmrg   -v, --verbose      verbosely report processing
14587ec3b29aSmrg       --version      print version information and exit
14597ec3b29aSmrg   -h, --help         print short or long help message and exit
14607ec3b29aSmrg"
14617ec3b29aSmrg
14627ec3b29aSmrg# Additional text appended to 'usage_message' in response to '--help'.
14637ec3b29aSmrglong_help_message="
14647ec3b29aSmrgWarning categories include:
14657ec3b29aSmrg       'all'          show all warnings
14667ec3b29aSmrg       'none'         turn off all the warnings
14677ec3b29aSmrg       'error'        warnings are treated as fatal errors"
14687ec3b29aSmrg
14697ec3b29aSmrg# Help message printed before fatal option parsing errors.
14707ec3b29aSmrgfatal_help="Try '\$progname --help' for more information."
14717ec3b29aSmrg
14727ec3b29aSmrg
14737ec3b29aSmrg
14747ec3b29aSmrg## ------------------------- ##
14757ec3b29aSmrg## Hook function management. ##
14767ec3b29aSmrg## ------------------------- ##
14777ec3b29aSmrg
14787ec3b29aSmrg# This section contains functions for adding, removing, and running hooks
14797ec3b29aSmrg# to the main code.  A hook is just a named list of of function, that can
14807ec3b29aSmrg# be run in order later on.
14817ec3b29aSmrg
14827ec3b29aSmrg# func_hookable FUNC_NAME
14837ec3b29aSmrg# -----------------------
14847ec3b29aSmrg# Declare that FUNC_NAME will run hooks added with
14857ec3b29aSmrg# 'func_add_hook FUNC_NAME ...'.
14867ec3b29aSmrgfunc_hookable ()
14877ec3b29aSmrg{
14887ec3b29aSmrg    $debug_cmd
14897ec3b29aSmrg
14907ec3b29aSmrg    func_append hookable_fns " $1"
14917ec3b29aSmrg}
14927ec3b29aSmrg
14937ec3b29aSmrg
14947ec3b29aSmrg# func_add_hook FUNC_NAME HOOK_FUNC
14957ec3b29aSmrg# ---------------------------------
14967ec3b29aSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
14977ec3b29aSmrg# first have been declared "hookable" by a call to 'func_hookable'.
14987ec3b29aSmrgfunc_add_hook ()
14997ec3b29aSmrg{
15007ec3b29aSmrg    $debug_cmd
15017ec3b29aSmrg
15027ec3b29aSmrg    case " $hookable_fns " in
15037ec3b29aSmrg      *" $1 "*) ;;
15047ec3b29aSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
15057ec3b29aSmrg    esac
15067ec3b29aSmrg
15077ec3b29aSmrg    eval func_append ${1}_hooks '" $2"'
15087ec3b29aSmrg}
15097ec3b29aSmrg
15107ec3b29aSmrg
15117ec3b29aSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
15127ec3b29aSmrg# ------------------------------------
15137ec3b29aSmrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
15147ec3b29aSmrgfunc_remove_hook ()
15157ec3b29aSmrg{
15167ec3b29aSmrg    $debug_cmd
15177ec3b29aSmrg
15187ec3b29aSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
15197ec3b29aSmrg}
15207ec3b29aSmrg
15217ec3b29aSmrg
15227ec3b29aSmrg# func_run_hooks FUNC_NAME [ARG]...
15237ec3b29aSmrg# ---------------------------------
15247ec3b29aSmrg# Run all hook functions registered to FUNC_NAME.
15257ec3b29aSmrg# It is assumed that the list of hook functions contains nothing more
15267ec3b29aSmrg# than a whitespace-delimited list of legal shell function names, and
15277ec3b29aSmrg# no effort is wasted trying to catch shell meta-characters or preserve
15287ec3b29aSmrg# whitespace.
15297ec3b29aSmrgfunc_run_hooks ()
15307ec3b29aSmrg{
15317ec3b29aSmrg    $debug_cmd
15327ec3b29aSmrg
15337ec3b29aSmrg    case " $hookable_fns " in
15347ec3b29aSmrg      *" $1 "*) ;;
15357ec3b29aSmrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
15367ec3b29aSmrg    esac
15377ec3b29aSmrg
15387ec3b29aSmrg    eval _G_hook_fns=\$$1_hooks; shift
15397ec3b29aSmrg
15407ec3b29aSmrg    for _G_hook in $_G_hook_fns; do
15417ec3b29aSmrg      eval $_G_hook '"$@"'
15427ec3b29aSmrg
15437ec3b29aSmrg      # store returned options list back into positional
15447ec3b29aSmrg      # parameters for next 'cmd' execution.
15457ec3b29aSmrg      eval _G_hook_result=\$${_G_hook}_result
15467ec3b29aSmrg      eval set dummy "$_G_hook_result"; shift
15477ec3b29aSmrg    done
15487ec3b29aSmrg
15497ec3b29aSmrg    func_quote_for_eval ${1+"$@"}
15507ec3b29aSmrg    func_run_hooks_result=$func_quote_for_eval_result
15517ec3b29aSmrg}
15527ec3b29aSmrg
15537ec3b29aSmrg
15547ec3b29aSmrg
15557ec3b29aSmrg## --------------- ##
15567ec3b29aSmrg## Option parsing. ##
15577ec3b29aSmrg## --------------- ##
15587ec3b29aSmrg
15597ec3b29aSmrg# In order to add your own option parsing hooks, you must accept the
15607ec3b29aSmrg# full positional parameter list in your hook function, remove any
15617ec3b29aSmrg# options that you action, and then pass back the remaining unprocessed
15627ec3b29aSmrg# options in '<hooked_function_name>_result', escaped suitably for
15637ec3b29aSmrg# 'eval'.  Like this:
15647ec3b29aSmrg#
15657ec3b29aSmrg#    my_options_prep ()
15667ec3b29aSmrg#    {
15677ec3b29aSmrg#        $debug_cmd
15687ec3b29aSmrg#
15697ec3b29aSmrg#        # Extend the existing usage message.
15707ec3b29aSmrg#        usage_message=$usage_message'
15717ec3b29aSmrg#      -s, --silent       don'\''t print informational messages
15727ec3b29aSmrg#    '
15737ec3b29aSmrg#
15747ec3b29aSmrg#        func_quote_for_eval ${1+"$@"}
15757ec3b29aSmrg#        my_options_prep_result=$func_quote_for_eval_result
15767ec3b29aSmrg#    }
15777ec3b29aSmrg#    func_add_hook func_options_prep my_options_prep
15787ec3b29aSmrg#
15797ec3b29aSmrg#
15807ec3b29aSmrg#    my_silent_option ()
15817ec3b29aSmrg#    {
15827ec3b29aSmrg#        $debug_cmd
15837ec3b29aSmrg#
15847ec3b29aSmrg#        # Note that for efficiency, we parse as many options as we can
15857ec3b29aSmrg#        # recognise in a loop before passing the remainder back to the
15867ec3b29aSmrg#        # caller on the first unrecognised argument we encounter.
15877ec3b29aSmrg#        while test $# -gt 0; do
15887ec3b29aSmrg#          opt=$1; shift
15897ec3b29aSmrg#          case $opt in
15907ec3b29aSmrg#            --silent|-s) opt_silent=: ;;
15917ec3b29aSmrg#            # Separate non-argument short options:
15927ec3b29aSmrg#            -s*)         func_split_short_opt "$_G_opt"
15937ec3b29aSmrg#                         set dummy "$func_split_short_opt_name" \
15947ec3b29aSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
15957ec3b29aSmrg#                         shift
15967ec3b29aSmrg#                         ;;
15977ec3b29aSmrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
15987ec3b29aSmrg#          esac
15997ec3b29aSmrg#        done
16007ec3b29aSmrg#
16017ec3b29aSmrg#        func_quote_for_eval ${1+"$@"}
16027ec3b29aSmrg#        my_silent_option_result=$func_quote_for_eval_result
16037ec3b29aSmrg#    }
16047ec3b29aSmrg#    func_add_hook func_parse_options my_silent_option
16057ec3b29aSmrg#
16067ec3b29aSmrg#
16077ec3b29aSmrg#    my_option_validation ()
16087ec3b29aSmrg#    {
16097ec3b29aSmrg#        $debug_cmd
16107ec3b29aSmrg#
16117ec3b29aSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
16127ec3b29aSmrg#    '--silent' and '--verbose' options are mutually exclusive."
16137ec3b29aSmrg#
16147ec3b29aSmrg#        func_quote_for_eval ${1+"$@"}
16157ec3b29aSmrg#        my_option_validation_result=$func_quote_for_eval_result
16167ec3b29aSmrg#    }
16177ec3b29aSmrg#    func_add_hook func_validate_options my_option_validation
16187ec3b29aSmrg#
16197ec3b29aSmrg# You'll alse need to manually amend $usage_message to reflect the extra
16207ec3b29aSmrg# options you parse.  It's preferable to append if you can, so that
16217ec3b29aSmrg# multiple option parsing hooks can be added safely.
16227ec3b29aSmrg
16237ec3b29aSmrg
16247ec3b29aSmrg# func_options [ARG]...
16257ec3b29aSmrg# ---------------------
16267ec3b29aSmrg# All the functions called inside func_options are hookable. See the
16277ec3b29aSmrg# individual implementations for details.
16287ec3b29aSmrgfunc_hookable func_options
16297ec3b29aSmrgfunc_options ()
16307ec3b29aSmrg{
16317ec3b29aSmrg    $debug_cmd
16327ec3b29aSmrg
16337ec3b29aSmrg    func_options_prep ${1+"$@"}
16347ec3b29aSmrg    eval func_parse_options \
16357ec3b29aSmrg        ${func_options_prep_result+"$func_options_prep_result"}
16367ec3b29aSmrg    eval func_validate_options \
16377ec3b29aSmrg        ${func_parse_options_result+"$func_parse_options_result"}
16387ec3b29aSmrg
16397ec3b29aSmrg    eval func_run_hooks func_options \
16407ec3b29aSmrg        ${func_validate_options_result+"$func_validate_options_result"}
16417ec3b29aSmrg
16427ec3b29aSmrg    # save modified positional parameters for caller
16437ec3b29aSmrg    func_options_result=$func_run_hooks_result
164432001f49Smrg}
164532001f49Smrg
164632001f49Smrg
16477ec3b29aSmrg# func_options_prep [ARG]...
16487ec3b29aSmrg# --------------------------
16497ec3b29aSmrg# All initialisations required before starting the option parse loop.
16507ec3b29aSmrg# Note that when calling hook functions, we pass through the list of
16517ec3b29aSmrg# positional parameters.  If a hook function modifies that list, and
16527ec3b29aSmrg# needs to propogate that back to rest of this script, then the complete
16537ec3b29aSmrg# modified list must be put in 'func_run_hooks_result' before
16547ec3b29aSmrg# returning.
16557ec3b29aSmrgfunc_hookable func_options_prep
16567ec3b29aSmrgfunc_options_prep ()
165732001f49Smrg{
16587ec3b29aSmrg    $debug_cmd
165932001f49Smrg
16607ec3b29aSmrg    # Option defaults:
16617ec3b29aSmrg    opt_verbose=false
16627ec3b29aSmrg    opt_warning_types=
16637ec3b29aSmrg
16647ec3b29aSmrg    func_run_hooks func_options_prep ${1+"$@"}
16657ec3b29aSmrg
16667ec3b29aSmrg    # save modified positional parameters for caller
16677ec3b29aSmrg    func_options_prep_result=$func_run_hooks_result
166832001f49Smrg}
166932001f49Smrg
167032001f49Smrg
16717ec3b29aSmrg# func_parse_options [ARG]...
16727ec3b29aSmrg# ---------------------------
16737ec3b29aSmrg# The main option parsing loop.
16747ec3b29aSmrgfunc_hookable func_parse_options
16757ec3b29aSmrgfunc_parse_options ()
167632001f49Smrg{
16777ec3b29aSmrg    $debug_cmd
167832001f49Smrg
16797ec3b29aSmrg    func_parse_options_result=
168032001f49Smrg
16817ec3b29aSmrg    # this just eases exit handling
16827ec3b29aSmrg    while test $# -gt 0; do
16837ec3b29aSmrg      # Defer to hook functions for initial option parsing, so they
16847ec3b29aSmrg      # get priority in the event of reusing an option name.
16857ec3b29aSmrg      func_run_hooks func_parse_options ${1+"$@"}
168632001f49Smrg
16877ec3b29aSmrg      # Adjust func_parse_options positional parameters to match
16887ec3b29aSmrg      eval set dummy "$func_run_hooks_result"; shift
168932001f49Smrg
16907ec3b29aSmrg      # Break out of the loop if we already parsed every option.
16917ec3b29aSmrg      test $# -gt 0 || break
169232001f49Smrg
16937ec3b29aSmrg      _G_opt=$1
16947ec3b29aSmrg      shift
16957ec3b29aSmrg      case $_G_opt in
16967ec3b29aSmrg        --debug|-x)   debug_cmd='set -x'
16977ec3b29aSmrg                      func_echo "enabling shell trace mode"
16987ec3b29aSmrg                      $debug_cmd
16997ec3b29aSmrg                      ;;
17007ec3b29aSmrg
17017ec3b29aSmrg        --no-warnings|--no-warning|--no-warn)
17027ec3b29aSmrg                      set dummy --warnings none ${1+"$@"}
17037ec3b29aSmrg                      shift
17047ec3b29aSmrg		      ;;
170532001f49Smrg
17067ec3b29aSmrg        --warnings|--warning|-W)
17077ec3b29aSmrg                      test $# = 0 && func_missing_arg $_G_opt && break
17087ec3b29aSmrg                      case " $warning_categories $1" in
17097ec3b29aSmrg                        *" $1 "*)
17107ec3b29aSmrg                          # trailing space prevents matching last $1 above
17117ec3b29aSmrg                          func_append_uniq opt_warning_types " $1"
17127ec3b29aSmrg                          ;;
17137ec3b29aSmrg                        *all)
17147ec3b29aSmrg                          opt_warning_types=$warning_categories
17157ec3b29aSmrg                          ;;
17167ec3b29aSmrg                        *none)
17177ec3b29aSmrg                          opt_warning_types=none
17187ec3b29aSmrg                          warning_func=:
17197ec3b29aSmrg                          ;;
17207ec3b29aSmrg                        *error)
17217ec3b29aSmrg                          opt_warning_types=$warning_categories
17227ec3b29aSmrg                          warning_func=func_fatal_error
17237ec3b29aSmrg                          ;;
17247ec3b29aSmrg                        *)
17257ec3b29aSmrg                          func_fatal_error \
17267ec3b29aSmrg                             "unsupported warning category: '$1'"
17277ec3b29aSmrg                          ;;
17287ec3b29aSmrg                      esac
17297ec3b29aSmrg                      shift
17307ec3b29aSmrg                      ;;
17317ec3b29aSmrg
17327ec3b29aSmrg        --verbose|-v) opt_verbose=: ;;
17337ec3b29aSmrg        --version)    func_version ;;
17347ec3b29aSmrg        -\?|-h)       func_usage ;;
17357ec3b29aSmrg        --help)       func_help ;;
17367ec3b29aSmrg
17377ec3b29aSmrg	# Separate optargs to long options (plugins may need this):
17387ec3b29aSmrg	--*=*)        func_split_equals "$_G_opt"
17397ec3b29aSmrg	              set dummy "$func_split_equals_lhs" \
17407ec3b29aSmrg                          "$func_split_equals_rhs" ${1+"$@"}
17417ec3b29aSmrg                      shift
17427ec3b29aSmrg                      ;;
17437ec3b29aSmrg
17447ec3b29aSmrg       # Separate optargs to short options:
17457ec3b29aSmrg        -W*)
17467ec3b29aSmrg                      func_split_short_opt "$_G_opt"
17477ec3b29aSmrg                      set dummy "$func_split_short_opt_name" \
17487ec3b29aSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
17497ec3b29aSmrg                      shift
17507ec3b29aSmrg                      ;;
17517ec3b29aSmrg
17527ec3b29aSmrg        # Separate non-argument short options:
17537ec3b29aSmrg        -\?*|-h*|-v*|-x*)
17547ec3b29aSmrg                      func_split_short_opt "$_G_opt"
17557ec3b29aSmrg                      set dummy "$func_split_short_opt_name" \
17567ec3b29aSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
17577ec3b29aSmrg                      shift
17587ec3b29aSmrg                      ;;
17597ec3b29aSmrg
17607ec3b29aSmrg        --)           break ;;
17617ec3b29aSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
17627ec3b29aSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17637ec3b29aSmrg      esac
17647ec3b29aSmrg    done
17657ec3b29aSmrg
17667ec3b29aSmrg    # save modified positional parameters for caller
17677ec3b29aSmrg    func_quote_for_eval ${1+"$@"}
17687ec3b29aSmrg    func_parse_options_result=$func_quote_for_eval_result
176932001f49Smrg}
177032001f49Smrg
177132001f49Smrg
17727ec3b29aSmrg# func_validate_options [ARG]...
17737ec3b29aSmrg# ------------------------------
17747ec3b29aSmrg# Perform any sanity checks on option settings and/or unconsumed
17757ec3b29aSmrg# arguments.
17767ec3b29aSmrgfunc_hookable func_validate_options
17777ec3b29aSmrgfunc_validate_options ()
177832001f49Smrg{
17797ec3b29aSmrg    $debug_cmd
178032001f49Smrg
17817ec3b29aSmrg    # Display all warnings if -W was not given.
17827ec3b29aSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
178332001f49Smrg
17847ec3b29aSmrg    func_run_hooks func_validate_options ${1+"$@"}
178532001f49Smrg
17867ec3b29aSmrg    # Bail if the options were screwed!
17877ec3b29aSmrg    $exit_cmd $EXIT_FAILURE
17887ec3b29aSmrg
17897ec3b29aSmrg    # save modified positional parameters for caller
17907ec3b29aSmrg    func_validate_options_result=$func_run_hooks_result
179132001f49Smrg}
179232001f49Smrg
179332001f49Smrg
179432001f49Smrg
17957ec3b29aSmrg## ----------------- ##
17967ec3b29aSmrg## Helper functions. ##
17977ec3b29aSmrg## ----------------- ##
179832001f49Smrg
17997ec3b29aSmrg# This section contains the helper functions used by the rest of the
18007ec3b29aSmrg# hookable option parser framework in ascii-betical order.
18017ec3b29aSmrg
18027ec3b29aSmrg
18037ec3b29aSmrg# func_fatal_help ARG...
18047ec3b29aSmrg# ----------------------
18057ec3b29aSmrg# Echo program name prefixed message to standard error, followed by
18067ec3b29aSmrg# a help hint, and exit.
18077ec3b29aSmrgfunc_fatal_help ()
180832001f49Smrg{
18097ec3b29aSmrg    $debug_cmd
181032001f49Smrg
18117ec3b29aSmrg    eval \$ECHO \""Usage: $usage"\"
18127ec3b29aSmrg    eval \$ECHO \""$fatal_help"\"
18137ec3b29aSmrg    func_error ${1+"$@"}
18147ec3b29aSmrg    exit $EXIT_FAILURE
181532001f49Smrg}
181632001f49Smrg
18177ec3b29aSmrg
18187ec3b29aSmrg# func_help
18197ec3b29aSmrg# ---------
18207ec3b29aSmrg# Echo long help message to standard output and exit.
182132001f49Smrgfunc_help ()
182232001f49Smrg{
18237ec3b29aSmrg    $debug_cmd
18247ec3b29aSmrg
18257ec3b29aSmrg    func_usage_message
18267ec3b29aSmrg    $ECHO "$long_help_message"
18277ec3b29aSmrg    exit 0
182832001f49Smrg}
182932001f49Smrg
18307ec3b29aSmrg
18317ec3b29aSmrg# func_missing_arg ARGNAME
18327ec3b29aSmrg# ------------------------
183332001f49Smrg# Echo program name prefixed message to standard error and set global
183432001f49Smrg# exit_cmd.
183532001f49Smrgfunc_missing_arg ()
183632001f49Smrg{
18377ec3b29aSmrg    $debug_cmd
183832001f49Smrg
18397ec3b29aSmrg    func_error "Missing argument for '$1'."
184032001f49Smrg    exit_cmd=exit
184132001f49Smrg}
184232001f49Smrg
184332001f49Smrg
18447ec3b29aSmrg# func_split_equals STRING
18457ec3b29aSmrg# ------------------------
18467ec3b29aSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
18477ec3b29aSmrg# splitting STRING at the '=' sign.
18487ec3b29aSmrgtest -z "$_G_HAVE_XSI_OPS" \
18497ec3b29aSmrg    && (eval 'x=a/b/c;
18507ec3b29aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
18517ec3b29aSmrg    && _G_HAVE_XSI_OPS=yes
18527ec3b29aSmrg
18537ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"
18547ec3b29aSmrgthen
18557ec3b29aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
18567ec3b29aSmrg  eval 'func_split_equals ()
18577ec3b29aSmrg  {
18587ec3b29aSmrg      $debug_cmd
18597ec3b29aSmrg
18607ec3b29aSmrg      func_split_equals_lhs=${1%%=*}
18617ec3b29aSmrg      func_split_equals_rhs=${1#*=}
18627ec3b29aSmrg      test "x$func_split_equals_lhs" = "x$1" \
18637ec3b29aSmrg        && func_split_equals_rhs=
18647ec3b29aSmrg  }'
18657ec3b29aSmrgelse
18667ec3b29aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
18677ec3b29aSmrg  func_split_equals ()
18687ec3b29aSmrg  {
18697ec3b29aSmrg      $debug_cmd
18707ec3b29aSmrg
18717ec3b29aSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
18727ec3b29aSmrg      func_split_equals_rhs=
18737ec3b29aSmrg      test "x$func_split_equals_lhs" = "x$1" \
18747ec3b29aSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
18757ec3b29aSmrg  }
18767ec3b29aSmrgfi #func_split_equals
18777ec3b29aSmrg
18787ec3b29aSmrg
18797ec3b29aSmrg# func_split_short_opt SHORTOPT
18807ec3b29aSmrg# -----------------------------
188132001f49Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
188232001f49Smrg# variables after splitting SHORTOPT after the 2nd character.
18837ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"
18847ec3b29aSmrgthen
18857ec3b29aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
18867ec3b29aSmrg  eval 'func_split_short_opt ()
18877ec3b29aSmrg  {
18887ec3b29aSmrg      $debug_cmd
18897ec3b29aSmrg
18907ec3b29aSmrg      func_split_short_opt_arg=${1#??}
18917ec3b29aSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
18927ec3b29aSmrg  }'
18937ec3b29aSmrgelse
18947ec3b29aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
18957ec3b29aSmrg  func_split_short_opt ()
18967ec3b29aSmrg  {
18977ec3b29aSmrg      $debug_cmd
18987ec3b29aSmrg
18997ec3b29aSmrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
19007ec3b29aSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
19017ec3b29aSmrg  }
19027ec3b29aSmrgfi #func_split_short_opt
19037ec3b29aSmrg
19047ec3b29aSmrg
19057ec3b29aSmrg# func_usage
19067ec3b29aSmrg# ----------
19077ec3b29aSmrg# Echo short help message to standard output and exit.
19087ec3b29aSmrgfunc_usage ()
190932001f49Smrg{
19107ec3b29aSmrg    $debug_cmd
191132001f49Smrg
19127ec3b29aSmrg    func_usage_message
19137ec3b29aSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
19147ec3b29aSmrg    exit 0
19157ec3b29aSmrg}
191632001f49Smrg
191732001f49Smrg
19187ec3b29aSmrg# func_usage_message
19197ec3b29aSmrg# ------------------
19207ec3b29aSmrg# Echo short help message to standard output.
19217ec3b29aSmrgfunc_usage_message ()
192232001f49Smrg{
19237ec3b29aSmrg    $debug_cmd
192432001f49Smrg
19257ec3b29aSmrg    eval \$ECHO \""Usage: $usage"\"
19267ec3b29aSmrg    echo
19277ec3b29aSmrg    $SED -n 's|^# ||
19287ec3b29aSmrg        /^Written by/{
19297ec3b29aSmrg          x;p;x
19307ec3b29aSmrg        }
19317ec3b29aSmrg	h
19327ec3b29aSmrg	/^Written by/q' < "$progpath"
19337ec3b29aSmrg    echo
19347ec3b29aSmrg    eval \$ECHO \""$usage_message"\"
19357ec3b29aSmrg}
193632001f49Smrg
193732001f49Smrg
19387ec3b29aSmrg# func_version
19397ec3b29aSmrg# ------------
19407ec3b29aSmrg# Echo version message to standard output and exit.
19417ec3b29aSmrgfunc_version ()
19427ec3b29aSmrg{
19437ec3b29aSmrg    $debug_cmd
194432001f49Smrg
19457ec3b29aSmrg    printf '%s\n' "$progname $scriptversion"
19467ec3b29aSmrg    $SED -n '
19477ec3b29aSmrg        /(C)/!b go
19487ec3b29aSmrg        :more
19497ec3b29aSmrg        /\./!{
19507ec3b29aSmrg          N
19517ec3b29aSmrg          s|\n# | |
19527ec3b29aSmrg          b more
19537ec3b29aSmrg        }
19547ec3b29aSmrg        :go
19557ec3b29aSmrg        /^# Written by /,/# warranty; / {
19567ec3b29aSmrg          s|^# ||
19577ec3b29aSmrg          s|^# *$||
19587ec3b29aSmrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
19597ec3b29aSmrg          p
19607ec3b29aSmrg        }
19617ec3b29aSmrg        /^# Written by / {
19627ec3b29aSmrg          s|^# ||
19637ec3b29aSmrg          p
19647ec3b29aSmrg        }
19657ec3b29aSmrg        /^warranty; /q' < "$progpath"
196632001f49Smrg
19677ec3b29aSmrg    exit $?
19687ec3b29aSmrg}
196932001f49Smrg
197032001f49Smrg
19717ec3b29aSmrg# Local variables:
19727ec3b29aSmrg# mode: shell-script
19737ec3b29aSmrg# sh-indentation: 2
19747ec3b29aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
19757ec3b29aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
19767ec3b29aSmrg# time-stamp-time-zone: "UTC"
19777ec3b29aSmrg# End:
197832001f49Smrg
19797ec3b29aSmrg# Set a version string.
19807ec3b29aSmrgscriptversion='(GNU libtool) 2.4.6'
198132001f49Smrg
198232001f49Smrg
19837ec3b29aSmrg# func_echo ARG...
19847ec3b29aSmrg# ----------------
19857ec3b29aSmrg# Libtool also displays the current mode in messages, so override
19867ec3b29aSmrg# funclib.sh func_echo with this custom definition.
19877ec3b29aSmrgfunc_echo ()
198832001f49Smrg{
19897ec3b29aSmrg    $debug_cmd
199032001f49Smrg
19917ec3b29aSmrg    _G_message=$*
199232001f49Smrg
19937ec3b29aSmrg    func_echo_IFS=$IFS
19947ec3b29aSmrg    IFS=$nl
19957ec3b29aSmrg    for _G_line in $_G_message; do
19967ec3b29aSmrg      IFS=$func_echo_IFS
19977ec3b29aSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
19987ec3b29aSmrg    done
19997ec3b29aSmrg    IFS=$func_echo_IFS
20007ec3b29aSmrg}
200132001f49Smrg
20027ec3b29aSmrg
20037ec3b29aSmrg# func_warning ARG...
20047ec3b29aSmrg# -------------------
20057ec3b29aSmrg# Libtool warnings are not categorized, so override funclib.sh
20067ec3b29aSmrg# func_warning with this simpler definition.
20077ec3b29aSmrgfunc_warning ()
200832001f49Smrg{
20097ec3b29aSmrg    $debug_cmd
201032001f49Smrg
20117ec3b29aSmrg    $warning_func ${1+"$@"}
20127ec3b29aSmrg}
201332001f49Smrg
201432001f49Smrg
20157ec3b29aSmrg## ---------------- ##
20167ec3b29aSmrg## Options parsing. ##
20177ec3b29aSmrg## ---------------- ##
20187ec3b29aSmrg
20197ec3b29aSmrg# Hook in the functions to make sure our own options are parsed during
20207ec3b29aSmrg# the option parsing loop.
20217ec3b29aSmrg
20227ec3b29aSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
20237ec3b29aSmrg
20247ec3b29aSmrg# Short help message in response to '-h'.
20257ec3b29aSmrgusage_message="Options:
20267ec3b29aSmrg       --config             show all configuration variables
20277ec3b29aSmrg       --debug              enable verbose shell tracing
20287ec3b29aSmrg   -n, --dry-run            display commands without modifying any files
20297ec3b29aSmrg       --features           display basic configuration information and exit
20307ec3b29aSmrg       --mode=MODE          use operation mode MODE
20317ec3b29aSmrg       --no-warnings        equivalent to '-Wnone'
20327ec3b29aSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
20337ec3b29aSmrg       --quiet, --silent    don't print informational messages
20347ec3b29aSmrg       --tag=TAG            use configuration variables from tag TAG
20357ec3b29aSmrg   -v, --verbose            print more informational messages than default
20367ec3b29aSmrg       --version            print version information
20377ec3b29aSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
20387ec3b29aSmrg   -h, --help, --help-all   print short, long, or detailed help message
20397ec3b29aSmrg"
204032001f49Smrg
20417ec3b29aSmrg# Additional text appended to 'usage_message' in response to '--help'.
20427ec3b29aSmrgfunc_help ()
204332001f49Smrg{
20447ec3b29aSmrg    $debug_cmd
20457ec3b29aSmrg
20467ec3b29aSmrg    func_usage_message
20477ec3b29aSmrg    $ECHO "$long_help_message
20487ec3b29aSmrg
20497ec3b29aSmrgMODE must be one of the following:
20507ec3b29aSmrg
20517ec3b29aSmrg       clean           remove files from the build directory
20527ec3b29aSmrg       compile         compile a source file into a libtool object
20537ec3b29aSmrg       execute         automatically set library path, then run a program
20547ec3b29aSmrg       finish          complete the installation of libtool libraries
20557ec3b29aSmrg       install         install libraries or executables
20567ec3b29aSmrg       link            create a library or an executable
20577ec3b29aSmrg       uninstall       remove libraries from an installed directory
20587ec3b29aSmrg
20597ec3b29aSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
20607ec3b29aSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
20617ec3b29aSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
20627ec3b29aSmrg
20637ec3b29aSmrgWhen reporting a bug, please describe a test case to reproduce it and
20647ec3b29aSmrginclude the following information:
20657ec3b29aSmrg
20667ec3b29aSmrg       host-triplet:   $host
20677ec3b29aSmrg       shell:          $SHELL
20687ec3b29aSmrg       compiler:       $LTCC
20697ec3b29aSmrg       compiler flags: $LTCFLAGS
20707ec3b29aSmrg       linker:         $LD (gnu? $with_gnu_ld)
20717ec3b29aSmrg       version:        $progname $scriptversion Debian-2.4.6-2
20727ec3b29aSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
20737ec3b29aSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
20747ec3b29aSmrg
20757ec3b29aSmrgReport bugs to <bug-libtool@gnu.org>.
20767ec3b29aSmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
20777ec3b29aSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
20787ec3b29aSmrg    exit 0
20797ec3b29aSmrg}
208032001f49Smrg
208132001f49Smrg
20827ec3b29aSmrg# func_lo2o OBJECT-NAME
20837ec3b29aSmrg# ---------------------
20847ec3b29aSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
20857ec3b29aSmrg# object suffix.
20867ec3b29aSmrg
20877ec3b29aSmrglo2o=s/\\.lo\$/.$objext/
20887ec3b29aSmrgo2lo=s/\\.$objext\$/.lo/
20897ec3b29aSmrg
20907ec3b29aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
20917ec3b29aSmrg  eval 'func_lo2o ()
20927ec3b29aSmrg  {
20937ec3b29aSmrg    case $1 in
20947ec3b29aSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
20957ec3b29aSmrg      *   ) func_lo2o_result=$1               ;;
20967ec3b29aSmrg    esac
20977ec3b29aSmrg  }'
20987ec3b29aSmrg
20997ec3b29aSmrg  # func_xform LIBOBJ-OR-SOURCE
21007ec3b29aSmrg  # ---------------------------
21017ec3b29aSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
21027ec3b29aSmrg  # suffix to a '.lo' libtool-object suffix.
21037ec3b29aSmrg  eval 'func_xform ()
21047ec3b29aSmrg  {
21057ec3b29aSmrg    func_xform_result=${1%.*}.lo
21067ec3b29aSmrg  }'
21077ec3b29aSmrgelse
21087ec3b29aSmrg  # ...otherwise fall back to using sed.
21097ec3b29aSmrg  func_lo2o ()
21107ec3b29aSmrg  {
21117ec3b29aSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
21127ec3b29aSmrg  }
21137ec3b29aSmrg
21147ec3b29aSmrg  func_xform ()
21157ec3b29aSmrg  {
21167ec3b29aSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
21177ec3b29aSmrg  }
21187ec3b29aSmrgfi
211932001f49Smrg
212032001f49Smrg
21217ec3b29aSmrg# func_fatal_configuration ARG...
21227ec3b29aSmrg# -------------------------------
212332001f49Smrg# Echo program name prefixed message to standard error, followed by
212432001f49Smrg# a configuration failure hint, and exit.
212532001f49Smrgfunc_fatal_configuration ()
212632001f49Smrg{
21277ec3b29aSmrg    func__fatal_error ${1+"$@"} \
21287ec3b29aSmrg      "See the $PACKAGE documentation for more information." \
21297ec3b29aSmrg      "Fatal configuration error."
213032001f49Smrg}
213132001f49Smrg
213232001f49Smrg
213332001f49Smrg# func_config
21347ec3b29aSmrg# -----------
213532001f49Smrg# Display the configuration for all the tags in this script.
213632001f49Smrgfunc_config ()
213732001f49Smrg{
213832001f49Smrg    re_begincf='^# ### BEGIN LIBTOOL'
213932001f49Smrg    re_endcf='^# ### END LIBTOOL'
214032001f49Smrg
214132001f49Smrg    # Default configuration.
214232001f49Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
214332001f49Smrg
214432001f49Smrg    # Now print the configurations for the tags.
214532001f49Smrg    for tagname in $taglist; do
214632001f49Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
214732001f49Smrg    done
214832001f49Smrg
214932001f49Smrg    exit $?
215032001f49Smrg}
215132001f49Smrg
21527ec3b29aSmrg
215332001f49Smrg# func_features
21547ec3b29aSmrg# -------------
215532001f49Smrg# Display the features supported by this script.
215632001f49Smrgfunc_features ()
215732001f49Smrg{
215832001f49Smrg    echo "host: $host"
21597ec3b29aSmrg    if test yes = "$build_libtool_libs"; then
216032001f49Smrg      echo "enable shared libraries"
216132001f49Smrg    else
216232001f49Smrg      echo "disable shared libraries"
216332001f49Smrg    fi
21647ec3b29aSmrg    if test yes = "$build_old_libs"; then
216532001f49Smrg      echo "enable static libraries"
216632001f49Smrg    else
216732001f49Smrg      echo "disable static libraries"
216832001f49Smrg    fi
216932001f49Smrg
217032001f49Smrg    exit $?
217132001f49Smrg}
217232001f49Smrg
21737ec3b29aSmrg
21747ec3b29aSmrg# func_enable_tag TAGNAME
21757ec3b29aSmrg# -----------------------
217632001f49Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
217732001f49Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
217832001f49Smrg# variable here.
217932001f49Smrgfunc_enable_tag ()
218032001f49Smrg{
21817ec3b29aSmrg    # Global variable:
21827ec3b29aSmrg    tagname=$1
218332001f49Smrg
21847ec3b29aSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
21857ec3b29aSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
21867ec3b29aSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
218732001f49Smrg
21887ec3b29aSmrg    # Validate tagname.
21897ec3b29aSmrg    case $tagname in
21907ec3b29aSmrg      *[!-_A-Za-z0-9,/]*)
21917ec3b29aSmrg        func_fatal_error "invalid tag name: $tagname"
21927ec3b29aSmrg        ;;
21937ec3b29aSmrg    esac
219432001f49Smrg
21957ec3b29aSmrg    # Don't test for the "default" C tag, as we know it's
21967ec3b29aSmrg    # there but not specially marked.
21977ec3b29aSmrg    case $tagname in
21987ec3b29aSmrg        CC) ;;
219932001f49Smrg    *)
22007ec3b29aSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
22017ec3b29aSmrg	  taglist="$taglist $tagname"
22027ec3b29aSmrg
22037ec3b29aSmrg	  # Evaluate the configuration.  Be careful to quote the path
22047ec3b29aSmrg	  # and the sed script, to avoid splitting on whitespace, but
22057ec3b29aSmrg	  # also don't use non-portable quotes within backquotes within
22067ec3b29aSmrg	  # quotes we have to do it in 2 steps:
22077ec3b29aSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
22087ec3b29aSmrg	  eval "$extractedcf"
22097ec3b29aSmrg        else
22107ec3b29aSmrg	  func_error "ignoring unknown tag $tagname"
22117ec3b29aSmrg        fi
22127ec3b29aSmrg        ;;
22137ec3b29aSmrg    esac
221432001f49Smrg}
221532001f49Smrg
22167ec3b29aSmrg
221732001f49Smrg# func_check_version_match
22187ec3b29aSmrg# ------------------------
221932001f49Smrg# Ensure that we are using m4 macros, and libtool script from the same
222032001f49Smrg# release of libtool.
222132001f49Smrgfunc_check_version_match ()
222232001f49Smrg{
22237ec3b29aSmrg    if test "$package_revision" != "$macro_revision"; then
22247ec3b29aSmrg      if test "$VERSION" != "$macro_version"; then
22257ec3b29aSmrg        if test -z "$macro_version"; then
22267ec3b29aSmrg          cat >&2 <<_LT_EOF
222732001f49Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
222832001f49Smrg$progname: definition of this LT_INIT comes from an older release.
222932001f49Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
223032001f49Smrg$progname: and run autoconf again.
223132001f49Smrg_LT_EOF
22327ec3b29aSmrg        else
22337ec3b29aSmrg          cat >&2 <<_LT_EOF
223432001f49Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
223532001f49Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
223632001f49Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
223732001f49Smrg$progname: and run autoconf again.
223832001f49Smrg_LT_EOF
22397ec3b29aSmrg        fi
22407ec3b29aSmrg      else
22417ec3b29aSmrg        cat >&2 <<_LT_EOF
224232001f49Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
224332001f49Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
224432001f49Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
224532001f49Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
224632001f49Smrg_LT_EOF
22477ec3b29aSmrg      fi
224832001f49Smrg
22497ec3b29aSmrg      exit $EXIT_MISMATCH
22507ec3b29aSmrg    fi
225132001f49Smrg}
225232001f49Smrg
225332001f49Smrg
22547ec3b29aSmrg# libtool_options_prep [ARG]...
22557ec3b29aSmrg# -----------------------------
22567ec3b29aSmrg# Preparation for options parsed by libtool.
22577ec3b29aSmrglibtool_options_prep ()
22587ec3b29aSmrg{
22597ec3b29aSmrg    $debug_mode
226032001f49Smrg
22617ec3b29aSmrg    # Option defaults:
22627ec3b29aSmrg    opt_config=false
22637ec3b29aSmrg    opt_dlopen=
22647ec3b29aSmrg    opt_dry_run=false
22657ec3b29aSmrg    opt_help=false
22667ec3b29aSmrg    opt_mode=
22677ec3b29aSmrg    opt_preserve_dup_deps=false
22687ec3b29aSmrg    opt_quiet=false
226932001f49Smrg
22707ec3b29aSmrg    nonopt=
22717ec3b29aSmrg    preserve_args=
227232001f49Smrg
22737ec3b29aSmrg    # Shorthand for --mode=foo, only valid as the first argument
22747ec3b29aSmrg    case $1 in
22757ec3b29aSmrg    clean|clea|cle|cl)
22767ec3b29aSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
22777ec3b29aSmrg      ;;
22787ec3b29aSmrg    compile|compil|compi|comp|com|co|c)
22797ec3b29aSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
22807ec3b29aSmrg      ;;
22817ec3b29aSmrg    execute|execut|execu|exec|exe|ex|e)
22827ec3b29aSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
22837ec3b29aSmrg      ;;
22847ec3b29aSmrg    finish|finis|fini|fin|fi|f)
22857ec3b29aSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
22867ec3b29aSmrg      ;;
22877ec3b29aSmrg    install|instal|insta|inst|ins|in|i)
22887ec3b29aSmrg      shift; set dummy --mode install ${1+"$@"}; shift
22897ec3b29aSmrg      ;;
22907ec3b29aSmrg    link|lin|li|l)
22917ec3b29aSmrg      shift; set dummy --mode link ${1+"$@"}; shift
22927ec3b29aSmrg      ;;
22937ec3b29aSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
22947ec3b29aSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
22957ec3b29aSmrg      ;;
22967ec3b29aSmrg    esac
22977ec3b29aSmrg
22987ec3b29aSmrg    # Pass back the list of options.
22997ec3b29aSmrg    func_quote_for_eval ${1+"$@"}
23007ec3b29aSmrg    libtool_options_prep_result=$func_quote_for_eval_result
23017ec3b29aSmrg}
23027ec3b29aSmrgfunc_add_hook func_options_prep libtool_options_prep
230332001f49Smrg
230432001f49Smrg
23057ec3b29aSmrg# libtool_parse_options [ARG]...
23067ec3b29aSmrg# ---------------------------------
23077ec3b29aSmrg# Provide handling for libtool specific options.
23087ec3b29aSmrglibtool_parse_options ()
230932001f49Smrg{
23107ec3b29aSmrg    $debug_cmd
231132001f49Smrg
23127ec3b29aSmrg    # Perform our own loop to consume as many options as possible in
23137ec3b29aSmrg    # each iteration.
23147ec3b29aSmrg    while test $# -gt 0; do
23157ec3b29aSmrg      _G_opt=$1
23167ec3b29aSmrg      shift
23177ec3b29aSmrg      case $_G_opt in
23187ec3b29aSmrg        --dry-run|--dryrun|-n)
23197ec3b29aSmrg                        opt_dry_run=:
23207ec3b29aSmrg                        ;;
23217ec3b29aSmrg
23227ec3b29aSmrg        --config)       func_config ;;
23237ec3b29aSmrg
23247ec3b29aSmrg        --dlopen|-dlopen)
23257ec3b29aSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
23267ec3b29aSmrg}$1"
23277ec3b29aSmrg                        shift
23287ec3b29aSmrg                        ;;
23297ec3b29aSmrg
23307ec3b29aSmrg        --preserve-dup-deps)
23317ec3b29aSmrg                        opt_preserve_dup_deps=: ;;
23327ec3b29aSmrg
23337ec3b29aSmrg        --features)     func_features ;;
23347ec3b29aSmrg
23357ec3b29aSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
23367ec3b29aSmrg
23377ec3b29aSmrg        --help)         opt_help=: ;;
23387ec3b29aSmrg
23397ec3b29aSmrg        --help-all)     opt_help=': help-all' ;;
23407ec3b29aSmrg
23417ec3b29aSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
23427ec3b29aSmrg                        opt_mode=$1
23437ec3b29aSmrg                        case $1 in
23447ec3b29aSmrg                          # Valid mode arguments:
23457ec3b29aSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
23467ec3b29aSmrg
23477ec3b29aSmrg                          # Catch anything else as an error
23487ec3b29aSmrg                          *) func_error "invalid argument for $_G_opt"
23497ec3b29aSmrg                             exit_cmd=exit
23507ec3b29aSmrg                             break
23517ec3b29aSmrg                             ;;
23527ec3b29aSmrg                        esac
23537ec3b29aSmrg                        shift
23547ec3b29aSmrg                        ;;
23557ec3b29aSmrg
23567ec3b29aSmrg        --no-silent|--no-quiet)
23577ec3b29aSmrg                        opt_quiet=false
23587ec3b29aSmrg                        func_append preserve_args " $_G_opt"
23597ec3b29aSmrg                        ;;
23607ec3b29aSmrg
23617ec3b29aSmrg        --no-warnings|--no-warning|--no-warn)
23627ec3b29aSmrg                        opt_warning=false
23637ec3b29aSmrg                        func_append preserve_args " $_G_opt"
23647ec3b29aSmrg                        ;;
23657ec3b29aSmrg
23667ec3b29aSmrg        --no-verbose)
23677ec3b29aSmrg                        opt_verbose=false
23687ec3b29aSmrg                        func_append preserve_args " $_G_opt"
23697ec3b29aSmrg                        ;;
23707ec3b29aSmrg
23717ec3b29aSmrg        --silent|--quiet)
23727ec3b29aSmrg                        opt_quiet=:
23737ec3b29aSmrg                        opt_verbose=false
23747ec3b29aSmrg                        func_append preserve_args " $_G_opt"
23757ec3b29aSmrg                        ;;
23767ec3b29aSmrg
23777ec3b29aSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
23787ec3b29aSmrg                        opt_tag=$1
23797ec3b29aSmrg                        func_append preserve_args " $_G_opt $1"
23807ec3b29aSmrg                        func_enable_tag "$1"
23817ec3b29aSmrg                        shift
23827ec3b29aSmrg                        ;;
23837ec3b29aSmrg
23847ec3b29aSmrg        --verbose|-v)   opt_quiet=false
23857ec3b29aSmrg                        opt_verbose=:
23867ec3b29aSmrg                        func_append preserve_args " $_G_opt"
23877ec3b29aSmrg                        ;;
23887ec3b29aSmrg
23897ec3b29aSmrg	# An option not handled by this hook function:
23907ec3b29aSmrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
23917ec3b29aSmrg      esac
23927ec3b29aSmrg    done
239332001f49Smrg
239432001f49Smrg
23957ec3b29aSmrg    # save modified positional parameters for caller
23967ec3b29aSmrg    func_quote_for_eval ${1+"$@"}
23977ec3b29aSmrg    libtool_parse_options_result=$func_quote_for_eval_result
23987ec3b29aSmrg}
23997ec3b29aSmrgfunc_add_hook func_parse_options libtool_parse_options
240032001f49Smrg
240132001f49Smrg
240232001f49Smrg
24037ec3b29aSmrg# libtool_validate_options [ARG]...
24047ec3b29aSmrg# ---------------------------------
24057ec3b29aSmrg# Perform any sanity checks on option settings and/or unconsumed
24067ec3b29aSmrg# arguments.
24077ec3b29aSmrglibtool_validate_options ()
24087ec3b29aSmrg{
24097ec3b29aSmrg    # save first non-option argument
24107ec3b29aSmrg    if test 0 -lt $#; then
24117ec3b29aSmrg      nonopt=$1
24127ec3b29aSmrg      shift
241332001f49Smrg    fi
241432001f49Smrg
24157ec3b29aSmrg    # preserve --debug
24167ec3b29aSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
241732001f49Smrg
24187ec3b29aSmrg    case $host in
24197ec3b29aSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
24207ec3b29aSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
24217ec3b29aSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
24227ec3b29aSmrg        # don't eliminate duplications in $postdeps and $predeps
24237ec3b29aSmrg        opt_duplicate_compiler_generated_deps=:
24247ec3b29aSmrg        ;;
24257ec3b29aSmrg      *)
24267ec3b29aSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
24277ec3b29aSmrg        ;;
24287ec3b29aSmrg    esac
242932001f49Smrg
24307ec3b29aSmrg    $opt_help || {
24317ec3b29aSmrg      # Sanity checks first:
24327ec3b29aSmrg      func_check_version_match
24337ec3b29aSmrg
24347ec3b29aSmrg      test yes != "$build_libtool_libs" \
24357ec3b29aSmrg        && test yes != "$build_old_libs" \
24367ec3b29aSmrg        && func_fatal_configuration "not configured to build any kind of library"
24377ec3b29aSmrg
24387ec3b29aSmrg      # Darwin sucks
24397ec3b29aSmrg      eval std_shrext=\"$shrext_cmds\"
24407ec3b29aSmrg
24417ec3b29aSmrg      # Only execute mode is allowed to have -dlopen flags.
24427ec3b29aSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
24437ec3b29aSmrg        func_error "unrecognized option '-dlopen'"
24447ec3b29aSmrg        $ECHO "$help" 1>&2
24457ec3b29aSmrg        exit $EXIT_FAILURE
24467ec3b29aSmrg      fi
244732001f49Smrg
24487ec3b29aSmrg      # Change the help message to a mode-specific one.
24497ec3b29aSmrg      generic_help=$help
24507ec3b29aSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
24517ec3b29aSmrg    }
245232001f49Smrg
24537ec3b29aSmrg    # Pass back the unparsed argument list
24547ec3b29aSmrg    func_quote_for_eval ${1+"$@"}
24557ec3b29aSmrg    libtool_validate_options_result=$func_quote_for_eval_result
245632001f49Smrg}
24577ec3b29aSmrgfunc_add_hook func_validate_options libtool_validate_options
245832001f49Smrg
245932001f49Smrg
24607ec3b29aSmrg# Process options as early as possible so that --help and --version
24617ec3b29aSmrg# can return quickly.
24627ec3b29aSmrgfunc_options ${1+"$@"}
24637ec3b29aSmrgeval set dummy "$func_options_result"; shift
24647ec3b29aSmrg
246532001f49Smrg
246632001f49Smrg
246732001f49Smrg## ----------- ##
246832001f49Smrg##    Main.    ##
246932001f49Smrg## ----------- ##
247032001f49Smrg
24717ec3b29aSmrgmagic='%%%MAGIC variable%%%'
24727ec3b29aSmrgmagic_exe='%%%MAGIC EXE variable%%%'
24737ec3b29aSmrg
24747ec3b29aSmrg# Global variables.
24757ec3b29aSmrgextracted_archives=
24767ec3b29aSmrgextracted_serial=0
24777ec3b29aSmrg
24787ec3b29aSmrg# If this variable is set in any of the actions, the command in it
24797ec3b29aSmrg# will be execed at the end.  This prevents here-documents from being
24807ec3b29aSmrg# left over by shells.
24817ec3b29aSmrgexec_cmd=
24827ec3b29aSmrg
24837ec3b29aSmrg
24847ec3b29aSmrg# A function that is used when there is no print builtin or printf.
24857ec3b29aSmrgfunc_fallback_echo ()
24867ec3b29aSmrg{
24877ec3b29aSmrg  eval 'cat <<_LTECHO_EOF
24887ec3b29aSmrg$1
24897ec3b29aSmrg_LTECHO_EOF'
24907ec3b29aSmrg}
24917ec3b29aSmrg
24927ec3b29aSmrg# func_generated_by_libtool
24937ec3b29aSmrg# True iff stdin has been generated by Libtool. This function is only
24947ec3b29aSmrg# a basic sanity check; it will hardly flush out determined imposters.
24957ec3b29aSmrgfunc_generated_by_libtool_p ()
24967ec3b29aSmrg{
24977ec3b29aSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
24987ec3b29aSmrg}
24997ec3b29aSmrg
250032001f49Smrg# func_lalib_p file
25017ec3b29aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
250232001f49Smrg# This function is only a basic sanity check; it will hardly flush out
250332001f49Smrg# determined imposters.
250432001f49Smrgfunc_lalib_p ()
250532001f49Smrg{
250632001f49Smrg    test -f "$1" &&
25077ec3b29aSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
250832001f49Smrg}
250932001f49Smrg
251032001f49Smrg# func_lalib_unsafe_p file
25117ec3b29aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
251232001f49Smrg# This function implements the same check as func_lalib_p without
251332001f49Smrg# resorting to external programs.  To this end, it redirects stdin and
251432001f49Smrg# closes it afterwards, without saving the original file descriptor.
251532001f49Smrg# As a safety measure, use it only where a negative result would be
25167ec3b29aSmrg# fatal anyway.  Works if 'file' does not exist.
251732001f49Smrgfunc_lalib_unsafe_p ()
251832001f49Smrg{
251932001f49Smrg    lalib_p=no
252032001f49Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
252132001f49Smrg	for lalib_p_l in 1 2 3 4
252232001f49Smrg	do
252332001f49Smrg	    read lalib_p_line
25247ec3b29aSmrg	    case $lalib_p_line in
252532001f49Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
252632001f49Smrg	    esac
252732001f49Smrg	done
252832001f49Smrg	exec 0<&5 5<&-
252932001f49Smrg    fi
25307ec3b29aSmrg    test yes = "$lalib_p"
253132001f49Smrg}
253232001f49Smrg
253332001f49Smrg# func_ltwrapper_script_p file
253432001f49Smrg# True iff FILE is a libtool wrapper script
253532001f49Smrg# This function is only a basic sanity check; it will hardly flush out
253632001f49Smrg# determined imposters.
253732001f49Smrgfunc_ltwrapper_script_p ()
253832001f49Smrg{
25397ec3b29aSmrg    test -f "$1" &&
25407ec3b29aSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
254132001f49Smrg}
254232001f49Smrg
254332001f49Smrg# func_ltwrapper_executable_p file
254432001f49Smrg# True iff FILE is a libtool wrapper executable
254532001f49Smrg# This function is only a basic sanity check; it will hardly flush out
254632001f49Smrg# determined imposters.
254732001f49Smrgfunc_ltwrapper_executable_p ()
254832001f49Smrg{
254932001f49Smrg    func_ltwrapper_exec_suffix=
255032001f49Smrg    case $1 in
255132001f49Smrg    *.exe) ;;
255232001f49Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
255332001f49Smrg    esac
255432001f49Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
255532001f49Smrg}
255632001f49Smrg
255732001f49Smrg# func_ltwrapper_scriptname file
255832001f49Smrg# Assumes file is an ltwrapper_executable
255932001f49Smrg# uses $file to determine the appropriate filename for a
256032001f49Smrg# temporary ltwrapper_script.
256132001f49Smrgfunc_ltwrapper_scriptname ()
256232001f49Smrg{
256332001f49Smrg    func_dirname_and_basename "$1" "" "."
256432001f49Smrg    func_stripname '' '.exe' "$func_basename_result"
25657ec3b29aSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
256632001f49Smrg}
256732001f49Smrg
256832001f49Smrg# func_ltwrapper_p file
256932001f49Smrg# True iff FILE is a libtool wrapper script or wrapper executable
257032001f49Smrg# This function is only a basic sanity check; it will hardly flush out
257132001f49Smrg# determined imposters.
257232001f49Smrgfunc_ltwrapper_p ()
257332001f49Smrg{
257432001f49Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
257532001f49Smrg}
257632001f49Smrg
257732001f49Smrg
257832001f49Smrg# func_execute_cmds commands fail_cmd
257932001f49Smrg# Execute tilde-delimited COMMANDS.
258032001f49Smrg# If FAIL_CMD is given, eval that upon failure.
258132001f49Smrg# FAIL_CMD may read-access the current command in variable CMD!
258232001f49Smrgfunc_execute_cmds ()
258332001f49Smrg{
25847ec3b29aSmrg    $debug_cmd
25857ec3b29aSmrg
258632001f49Smrg    save_ifs=$IFS; IFS='~'
258732001f49Smrg    for cmd in $1; do
25887ec3b29aSmrg      IFS=$sp$nl
258932001f49Smrg      eval cmd=\"$cmd\"
25907ec3b29aSmrg      IFS=$save_ifs
259132001f49Smrg      func_show_eval "$cmd" "${2-:}"
259232001f49Smrg    done
259332001f49Smrg    IFS=$save_ifs
259432001f49Smrg}
259532001f49Smrg
259632001f49Smrg
259732001f49Smrg# func_source file
259832001f49Smrg# Source FILE, adding directory component if necessary.
259932001f49Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
260032001f49Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
260132001f49Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
26027ec3b29aSmrg# 'FILE.' does not work on cygwin managed mounts.
260332001f49Smrgfunc_source ()
260432001f49Smrg{
26057ec3b29aSmrg    $debug_cmd
26067ec3b29aSmrg
260732001f49Smrg    case $1 in
260832001f49Smrg    */* | *\\*)	. "$1" ;;
260932001f49Smrg    *)		. "./$1" ;;
261032001f49Smrg    esac
261132001f49Smrg}
261232001f49Smrg
261332001f49Smrg
261432001f49Smrg# func_resolve_sysroot PATH
261532001f49Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
261632001f49Smrg# func_resolve_sysroot_result
261732001f49Smrgfunc_resolve_sysroot ()
261832001f49Smrg{
261932001f49Smrg  func_resolve_sysroot_result=$1
262032001f49Smrg  case $func_resolve_sysroot_result in
262132001f49Smrg  =*)
262232001f49Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
262332001f49Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
262432001f49Smrg    ;;
262532001f49Smrg  esac
262632001f49Smrg}
262732001f49Smrg
262832001f49Smrg# func_replace_sysroot PATH
262932001f49Smrg# If PATH begins with the sysroot, replace it with = and
263032001f49Smrg# store the result into func_replace_sysroot_result.
263132001f49Smrgfunc_replace_sysroot ()
263232001f49Smrg{
26337ec3b29aSmrg  case $lt_sysroot:$1 in
263432001f49Smrg  ?*:"$lt_sysroot"*)
263532001f49Smrg    func_stripname "$lt_sysroot" '' "$1"
26367ec3b29aSmrg    func_replace_sysroot_result='='$func_stripname_result
263732001f49Smrg    ;;
263832001f49Smrg  *)
263932001f49Smrg    # Including no sysroot.
264032001f49Smrg    func_replace_sysroot_result=$1
264132001f49Smrg    ;;
264232001f49Smrg  esac
264332001f49Smrg}
264432001f49Smrg
264532001f49Smrg# func_infer_tag arg
264632001f49Smrg# Infer tagged configuration to use if any are available and
264732001f49Smrg# if one wasn't chosen via the "--tag" command line option.
264832001f49Smrg# Only attempt this if the compiler in the base compile
264932001f49Smrg# command doesn't match the default compiler.
265032001f49Smrg# arg is usually of the form 'gcc ...'
265132001f49Smrgfunc_infer_tag ()
265232001f49Smrg{
26537ec3b29aSmrg    $debug_cmd
26547ec3b29aSmrg
265532001f49Smrg    if test -n "$available_tags" && test -z "$tagname"; then
265632001f49Smrg      CC_quoted=
265732001f49Smrg      for arg in $CC; do
265832001f49Smrg	func_append_quoted CC_quoted "$arg"
265932001f49Smrg      done
266032001f49Smrg      CC_expanded=`func_echo_all $CC`
266132001f49Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
266232001f49Smrg      case $@ in
266332001f49Smrg      # Blanks in the command may have been stripped by the calling shell,
266432001f49Smrg      # but not from the CC environment variable when configure was run.
266532001f49Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
266632001f49Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
266732001f49Smrg      # Blanks at the start of $base_compile will cause this to fail
266832001f49Smrg      # if we don't check for them as well.
266932001f49Smrg      *)
267032001f49Smrg	for z in $available_tags; do
267132001f49Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
267232001f49Smrg	    # Evaluate the configuration.
26737ec3b29aSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
267432001f49Smrg	    CC_quoted=
267532001f49Smrg	    for arg in $CC; do
267632001f49Smrg	      # Double-quote args containing other shell metacharacters.
267732001f49Smrg	      func_append_quoted CC_quoted "$arg"
267832001f49Smrg	    done
267932001f49Smrg	    CC_expanded=`func_echo_all $CC`
268032001f49Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
268132001f49Smrg	    case "$@ " in
268232001f49Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
268332001f49Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
268432001f49Smrg	      # The compiler in the base compile command matches
268532001f49Smrg	      # the one in the tagged configuration.
268632001f49Smrg	      # Assume this is the tagged configuration we want.
268732001f49Smrg	      tagname=$z
268832001f49Smrg	      break
268932001f49Smrg	      ;;
269032001f49Smrg	    esac
269132001f49Smrg	  fi
269232001f49Smrg	done
269332001f49Smrg	# If $tagname still isn't set, then no tagged configuration
269432001f49Smrg	# was found and let the user know that the "--tag" command
269532001f49Smrg	# line option must be used.
269632001f49Smrg	if test -z "$tagname"; then
269732001f49Smrg	  func_echo "unable to infer tagged configuration"
26987ec3b29aSmrg	  func_fatal_error "specify a tag with '--tag'"
269932001f49Smrg#	else
270032001f49Smrg#	  func_verbose "using $tagname tagged configuration"
270132001f49Smrg	fi
270232001f49Smrg	;;
270332001f49Smrg      esac
270432001f49Smrg    fi
270532001f49Smrg}
270632001f49Smrg
270732001f49Smrg
270832001f49Smrg
270932001f49Smrg# func_write_libtool_object output_name pic_name nonpic_name
271032001f49Smrg# Create a libtool object file (analogous to a ".la" file),
271132001f49Smrg# but don't create it if we're doing a dry run.
271232001f49Smrgfunc_write_libtool_object ()
271332001f49Smrg{
27147ec3b29aSmrg    write_libobj=$1
27157ec3b29aSmrg    if test yes = "$build_libtool_libs"; then
27167ec3b29aSmrg      write_lobj=\'$2\'
271732001f49Smrg    else
271832001f49Smrg      write_lobj=none
271932001f49Smrg    fi
272032001f49Smrg
27217ec3b29aSmrg    if test yes = "$build_old_libs"; then
27227ec3b29aSmrg      write_oldobj=\'$3\'
272332001f49Smrg    else
272432001f49Smrg      write_oldobj=none
272532001f49Smrg    fi
272632001f49Smrg
272732001f49Smrg    $opt_dry_run || {
272832001f49Smrg      cat >${write_libobj}T <<EOF
272932001f49Smrg# $write_libobj - a libtool object file
27307ec3b29aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
273132001f49Smrg#
273232001f49Smrg# Please DO NOT delete this file!
273332001f49Smrg# It is necessary for linking the library.
273432001f49Smrg
273532001f49Smrg# Name of the PIC object.
273632001f49Smrgpic_object=$write_lobj
273732001f49Smrg
273832001f49Smrg# Name of the non-PIC object
273932001f49Smrgnon_pic_object=$write_oldobj
274032001f49Smrg
274132001f49SmrgEOF
27427ec3b29aSmrg      $MV "${write_libobj}T" "$write_libobj"
274332001f49Smrg    }
274432001f49Smrg}
274532001f49Smrg
274632001f49Smrg
274732001f49Smrg##################################################
274832001f49Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
274932001f49Smrg##################################################
275032001f49Smrg
275132001f49Smrg# func_convert_core_file_wine_to_w32 ARG
275232001f49Smrg# Helper function used by file name conversion functions when $build is *nix,
275332001f49Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
275432001f49Smrg# correctly configured wine environment available, with the winepath program
275532001f49Smrg# in $build's $PATH.
275632001f49Smrg#
275732001f49Smrg# ARG is the $build file name to be converted to w32 format.
275832001f49Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
275932001f49Smrg# be empty on error (or when ARG is empty)
276032001f49Smrgfunc_convert_core_file_wine_to_w32 ()
276132001f49Smrg{
27627ec3b29aSmrg  $debug_cmd
27637ec3b29aSmrg
27647ec3b29aSmrg  func_convert_core_file_wine_to_w32_result=$1
276532001f49Smrg  if test -n "$1"; then
276632001f49Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
276732001f49Smrg    # are forced to check the contents of stdout. On the other hand, if the
276832001f49Smrg    # command is not found, the shell will set an exit code of 127 and print
276932001f49Smrg    # *an error message* to stdout. So we must check for both error code of
277032001f49Smrg    # zero AND non-empty stdout, which explains the odd construction:
277132001f49Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
27727ec3b29aSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
277332001f49Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
27747ec3b29aSmrg        $SED -e "$sed_naive_backslashify"`
277532001f49Smrg    else
277632001f49Smrg      func_convert_core_file_wine_to_w32_result=
277732001f49Smrg    fi
277832001f49Smrg  fi
277932001f49Smrg}
278032001f49Smrg# end: func_convert_core_file_wine_to_w32
278132001f49Smrg
278232001f49Smrg
278332001f49Smrg# func_convert_core_path_wine_to_w32 ARG
278432001f49Smrg# Helper function used by path conversion functions when $build is *nix, and
278532001f49Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
278632001f49Smrg# configured wine environment available, with the winepath program in $build's
278732001f49Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
278832001f49Smrg#
278932001f49Smrg# ARG is path to be converted from $build format to win32.
279032001f49Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
279132001f49Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
279232001f49Smrg# are convertible, then the result may be empty.
279332001f49Smrgfunc_convert_core_path_wine_to_w32 ()
279432001f49Smrg{
27957ec3b29aSmrg  $debug_cmd
27967ec3b29aSmrg
279732001f49Smrg  # unfortunately, winepath doesn't convert paths, only file names
27987ec3b29aSmrg  func_convert_core_path_wine_to_w32_result=
279932001f49Smrg  if test -n "$1"; then
280032001f49Smrg    oldIFS=$IFS
280132001f49Smrg    IFS=:
280232001f49Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
280332001f49Smrg      IFS=$oldIFS
280432001f49Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
28057ec3b29aSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
280632001f49Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
28077ec3b29aSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
280832001f49Smrg        else
280932001f49Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
281032001f49Smrg        fi
281132001f49Smrg      fi
281232001f49Smrg    done
281332001f49Smrg    IFS=$oldIFS
281432001f49Smrg  fi
281532001f49Smrg}
281632001f49Smrg# end: func_convert_core_path_wine_to_w32
281732001f49Smrg
281832001f49Smrg
281932001f49Smrg# func_cygpath ARGS...
282032001f49Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
282132001f49Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
282232001f49Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
282332001f49Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
282432001f49Smrg# file name or path is assumed to be in w32 format, as previously converted
282532001f49Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
282632001f49Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
282732001f49Smrg# Cygwin format). Returns an empty string on error.
282832001f49Smrg#
282932001f49Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
283032001f49Smrg# be converted.
283132001f49Smrg#
283232001f49Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
283332001f49Smrg# environment variable; do not put it in $PATH.
283432001f49Smrgfunc_cygpath ()
283532001f49Smrg{
28367ec3b29aSmrg  $debug_cmd
28377ec3b29aSmrg
283832001f49Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
283932001f49Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
284032001f49Smrg    if test "$?" -ne 0; then
284132001f49Smrg      # on failure, ensure result is empty
284232001f49Smrg      func_cygpath_result=
284332001f49Smrg    fi
284432001f49Smrg  else
284532001f49Smrg    func_cygpath_result=
28467ec3b29aSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
284732001f49Smrg  fi
284832001f49Smrg}
284932001f49Smrg#end: func_cygpath
285032001f49Smrg
285132001f49Smrg
285232001f49Smrg# func_convert_core_msys_to_w32 ARG
285332001f49Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
285432001f49Smrg# result in func_convert_core_msys_to_w32_result.
285532001f49Smrgfunc_convert_core_msys_to_w32 ()
285632001f49Smrg{
28577ec3b29aSmrg  $debug_cmd
28587ec3b29aSmrg
285932001f49Smrg  # awkward: cmd appends spaces to result
286032001f49Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
28617ec3b29aSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
286232001f49Smrg}
286332001f49Smrg#end: func_convert_core_msys_to_w32
286432001f49Smrg
286532001f49Smrg
286632001f49Smrg# func_convert_file_check ARG1 ARG2
286732001f49Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
286832001f49Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
286932001f49Smrg# func_to_host_file_result to ARG1).
287032001f49Smrgfunc_convert_file_check ()
287132001f49Smrg{
28727ec3b29aSmrg  $debug_cmd
28737ec3b29aSmrg
28747ec3b29aSmrg  if test -z "$2" && test -n "$1"; then
287532001f49Smrg    func_error "Could not determine host file name corresponding to"
28767ec3b29aSmrg    func_error "  '$1'"
287732001f49Smrg    func_error "Continuing, but uninstalled executables may not work."
287832001f49Smrg    # Fallback:
28797ec3b29aSmrg    func_to_host_file_result=$1
288032001f49Smrg  fi
288132001f49Smrg}
288232001f49Smrg# end func_convert_file_check
288332001f49Smrg
288432001f49Smrg
288532001f49Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
288632001f49Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
288732001f49Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
288832001f49Smrg# func_to_host_file_result to a simplistic fallback value (see below).
288932001f49Smrgfunc_convert_path_check ()
289032001f49Smrg{
28917ec3b29aSmrg  $debug_cmd
28927ec3b29aSmrg
289332001f49Smrg  if test -z "$4" && test -n "$3"; then
289432001f49Smrg    func_error "Could not determine the host path corresponding to"
28957ec3b29aSmrg    func_error "  '$3'"
289632001f49Smrg    func_error "Continuing, but uninstalled executables may not work."
289732001f49Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
289832001f49Smrg    # should not be "improved".  See libtool.info.
289932001f49Smrg    if test "x$1" != "x$2"; then
290032001f49Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
290132001f49Smrg      func_to_host_path_result=`echo "$3" |
290232001f49Smrg        $SED -e "$lt_replace_pathsep_chars"`
290332001f49Smrg    else
29047ec3b29aSmrg      func_to_host_path_result=$3
290532001f49Smrg    fi
290632001f49Smrg  fi
290732001f49Smrg}
290832001f49Smrg# end func_convert_path_check
290932001f49Smrg
291032001f49Smrg
291132001f49Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
291232001f49Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
291332001f49Smrg# and appending REPL if ORIG matches BACKPAT.
291432001f49Smrgfunc_convert_path_front_back_pathsep ()
291532001f49Smrg{
29167ec3b29aSmrg  $debug_cmd
29177ec3b29aSmrg
291832001f49Smrg  case $4 in
29197ec3b29aSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
292032001f49Smrg    ;;
292132001f49Smrg  esac
292232001f49Smrg  case $4 in
292332001f49Smrg  $2 ) func_append func_to_host_path_result "$3"
292432001f49Smrg    ;;
292532001f49Smrg  esac
292632001f49Smrg}
292732001f49Smrg# end func_convert_path_front_back_pathsep
292832001f49Smrg
292932001f49Smrg
293032001f49Smrg##################################################
293132001f49Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
293232001f49Smrg##################################################
29337ec3b29aSmrg# invoked via '$to_host_file_cmd ARG'
293432001f49Smrg#
293532001f49Smrg# In each case, ARG is the path to be converted from $build to $host format.
293632001f49Smrg# Result will be available in $func_to_host_file_result.
293732001f49Smrg
293832001f49Smrg
293932001f49Smrg# func_to_host_file ARG
294032001f49Smrg# Converts the file name ARG from $build format to $host format. Return result
294132001f49Smrg# in func_to_host_file_result.
294232001f49Smrgfunc_to_host_file ()
294332001f49Smrg{
29447ec3b29aSmrg  $debug_cmd
29457ec3b29aSmrg
294632001f49Smrg  $to_host_file_cmd "$1"
294732001f49Smrg}
294832001f49Smrg# end func_to_host_file
294932001f49Smrg
295032001f49Smrg
295132001f49Smrg# func_to_tool_file ARG LAZY
295232001f49Smrg# converts the file name ARG from $build format to toolchain format. Return
295332001f49Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
295432001f49Smrg# in (the comma separated) LAZY, no conversion takes place.
295532001f49Smrgfunc_to_tool_file ()
295632001f49Smrg{
29577ec3b29aSmrg  $debug_cmd
29587ec3b29aSmrg
295932001f49Smrg  case ,$2, in
296032001f49Smrg    *,"$to_tool_file_cmd",*)
296132001f49Smrg      func_to_tool_file_result=$1
296232001f49Smrg      ;;
296332001f49Smrg    *)
296432001f49Smrg      $to_tool_file_cmd "$1"
296532001f49Smrg      func_to_tool_file_result=$func_to_host_file_result
296632001f49Smrg      ;;
296732001f49Smrg  esac
296832001f49Smrg}
296932001f49Smrg# end func_to_tool_file
297032001f49Smrg
297132001f49Smrg
297232001f49Smrg# func_convert_file_noop ARG
297332001f49Smrg# Copy ARG to func_to_host_file_result.
297432001f49Smrgfunc_convert_file_noop ()
297532001f49Smrg{
29767ec3b29aSmrg  func_to_host_file_result=$1
297732001f49Smrg}
297832001f49Smrg# end func_convert_file_noop
297932001f49Smrg
298032001f49Smrg
298132001f49Smrg# func_convert_file_msys_to_w32 ARG
298232001f49Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
298332001f49Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
298432001f49Smrg# func_to_host_file_result.
298532001f49Smrgfunc_convert_file_msys_to_w32 ()
298632001f49Smrg{
29877ec3b29aSmrg  $debug_cmd
29887ec3b29aSmrg
29897ec3b29aSmrg  func_to_host_file_result=$1
299032001f49Smrg  if test -n "$1"; then
299132001f49Smrg    func_convert_core_msys_to_w32 "$1"
29927ec3b29aSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
299332001f49Smrg  fi
299432001f49Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
299532001f49Smrg}
299632001f49Smrg# end func_convert_file_msys_to_w32
299732001f49Smrg
299832001f49Smrg
299932001f49Smrg# func_convert_file_cygwin_to_w32 ARG
300032001f49Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
300132001f49Smrg# func_to_host_file_result.
300232001f49Smrgfunc_convert_file_cygwin_to_w32 ()
300332001f49Smrg{
30047ec3b29aSmrg  $debug_cmd
30057ec3b29aSmrg
30067ec3b29aSmrg  func_to_host_file_result=$1
300732001f49Smrg  if test -n "$1"; then
300832001f49Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
300932001f49Smrg    # LT_CYGPATH in this case.
301032001f49Smrg    func_to_host_file_result=`cygpath -m "$1"`
301132001f49Smrg  fi
301232001f49Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
301332001f49Smrg}
301432001f49Smrg# end func_convert_file_cygwin_to_w32
301532001f49Smrg
301632001f49Smrg
301732001f49Smrg# func_convert_file_nix_to_w32 ARG
301832001f49Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
301932001f49Smrg# and a working winepath. Returns result in func_to_host_file_result.
302032001f49Smrgfunc_convert_file_nix_to_w32 ()
302132001f49Smrg{
30227ec3b29aSmrg  $debug_cmd
30237ec3b29aSmrg
30247ec3b29aSmrg  func_to_host_file_result=$1
302532001f49Smrg  if test -n "$1"; then
302632001f49Smrg    func_convert_core_file_wine_to_w32 "$1"
30277ec3b29aSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
302832001f49Smrg  fi
302932001f49Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
303032001f49Smrg}
303132001f49Smrg# end func_convert_file_nix_to_w32
303232001f49Smrg
303332001f49Smrg
303432001f49Smrg# func_convert_file_msys_to_cygwin ARG
303532001f49Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
303632001f49Smrg# Returns result in func_to_host_file_result.
303732001f49Smrgfunc_convert_file_msys_to_cygwin ()
303832001f49Smrg{
30397ec3b29aSmrg  $debug_cmd
30407ec3b29aSmrg
30417ec3b29aSmrg  func_to_host_file_result=$1
304232001f49Smrg  if test -n "$1"; then
304332001f49Smrg    func_convert_core_msys_to_w32 "$1"
304432001f49Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
30457ec3b29aSmrg    func_to_host_file_result=$func_cygpath_result
304632001f49Smrg  fi
304732001f49Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
304832001f49Smrg}
304932001f49Smrg# end func_convert_file_msys_to_cygwin
305032001f49Smrg
305132001f49Smrg
305232001f49Smrg# func_convert_file_nix_to_cygwin ARG
305332001f49Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
305432001f49Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
305532001f49Smrg# in func_to_host_file_result.
305632001f49Smrgfunc_convert_file_nix_to_cygwin ()
305732001f49Smrg{
30587ec3b29aSmrg  $debug_cmd
30597ec3b29aSmrg
30607ec3b29aSmrg  func_to_host_file_result=$1
306132001f49Smrg  if test -n "$1"; then
306232001f49Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
306332001f49Smrg    func_convert_core_file_wine_to_w32 "$1"
306432001f49Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
30657ec3b29aSmrg    func_to_host_file_result=$func_cygpath_result
306632001f49Smrg  fi
306732001f49Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
306832001f49Smrg}
306932001f49Smrg# end func_convert_file_nix_to_cygwin
307032001f49Smrg
307132001f49Smrg
307232001f49Smrg#############################################
307332001f49Smrg# $build to $host PATH CONVERSION FUNCTIONS #
307432001f49Smrg#############################################
30757ec3b29aSmrg# invoked via '$to_host_path_cmd ARG'
307632001f49Smrg#
307732001f49Smrg# In each case, ARG is the path to be converted from $build to $host format.
307832001f49Smrg# The result will be available in $func_to_host_path_result.
307932001f49Smrg#
308032001f49Smrg# Path separators are also converted from $build format to $host format.  If
308132001f49Smrg# ARG begins or ends with a path separator character, it is preserved (but
308232001f49Smrg# converted to $host format) on output.
308332001f49Smrg#
308432001f49Smrg# All path conversion functions are named using the following convention:
308532001f49Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
308632001f49Smrg#   path conversion function         : func_convert_path_X_to_Y ()
308732001f49Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
308832001f49Smrg# same.  If conversion functions are added for new $build/$host combinations,
308932001f49Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
309032001f49Smrg# will break.
309132001f49Smrg
309232001f49Smrg
309332001f49Smrg# func_init_to_host_path_cmd
309432001f49Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
309532001f49Smrg# appropriate value, based on the value of $to_host_file_cmd.
309632001f49Smrgto_host_path_cmd=
309732001f49Smrgfunc_init_to_host_path_cmd ()
309832001f49Smrg{
30997ec3b29aSmrg  $debug_cmd
31007ec3b29aSmrg
310132001f49Smrg  if test -z "$to_host_path_cmd"; then
310232001f49Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
31037ec3b29aSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
310432001f49Smrg  fi
310532001f49Smrg}
310632001f49Smrg
310732001f49Smrg
310832001f49Smrg# func_to_host_path ARG
310932001f49Smrg# Converts the path ARG from $build format to $host format. Return result
311032001f49Smrg# in func_to_host_path_result.
311132001f49Smrgfunc_to_host_path ()
311232001f49Smrg{
31137ec3b29aSmrg  $debug_cmd
31147ec3b29aSmrg
311532001f49Smrg  func_init_to_host_path_cmd
311632001f49Smrg  $to_host_path_cmd "$1"
311732001f49Smrg}
311832001f49Smrg# end func_to_host_path
311932001f49Smrg
312032001f49Smrg
312132001f49Smrg# func_convert_path_noop ARG
312232001f49Smrg# Copy ARG to func_to_host_path_result.
312332001f49Smrgfunc_convert_path_noop ()
312432001f49Smrg{
31257ec3b29aSmrg  func_to_host_path_result=$1
312632001f49Smrg}
312732001f49Smrg# end func_convert_path_noop
312832001f49Smrg
312932001f49Smrg
313032001f49Smrg# func_convert_path_msys_to_w32 ARG
313132001f49Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
313232001f49Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
313332001f49Smrg# func_to_host_path_result.
313432001f49Smrgfunc_convert_path_msys_to_w32 ()
313532001f49Smrg{
31367ec3b29aSmrg  $debug_cmd
31377ec3b29aSmrg
31387ec3b29aSmrg  func_to_host_path_result=$1
313932001f49Smrg  if test -n "$1"; then
314032001f49Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
314132001f49Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
314232001f49Smrg    # and winepath ignores them completely.
314332001f49Smrg    func_stripname : : "$1"
314432001f49Smrg    func_to_host_path_tmp1=$func_stripname_result
314532001f49Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
31467ec3b29aSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
314732001f49Smrg    func_convert_path_check : ";" \
314832001f49Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
314932001f49Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
315032001f49Smrg  fi
315132001f49Smrg}
315232001f49Smrg# end func_convert_path_msys_to_w32
315332001f49Smrg
315432001f49Smrg
315532001f49Smrg# func_convert_path_cygwin_to_w32 ARG
315632001f49Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
315732001f49Smrg# func_to_host_file_result.
315832001f49Smrgfunc_convert_path_cygwin_to_w32 ()
315932001f49Smrg{
31607ec3b29aSmrg  $debug_cmd
31617ec3b29aSmrg
31627ec3b29aSmrg  func_to_host_path_result=$1
316332001f49Smrg  if test -n "$1"; then
316432001f49Smrg    # See func_convert_path_msys_to_w32:
316532001f49Smrg    func_stripname : : "$1"
316632001f49Smrg    func_to_host_path_tmp1=$func_stripname_result
316732001f49Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
316832001f49Smrg    func_convert_path_check : ";" \
316932001f49Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
317032001f49Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
317132001f49Smrg  fi
317232001f49Smrg}
317332001f49Smrg# end func_convert_path_cygwin_to_w32
317432001f49Smrg
317532001f49Smrg
317632001f49Smrg# func_convert_path_nix_to_w32 ARG
317732001f49Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
317832001f49Smrg# a working winepath.  Returns result in func_to_host_file_result.
317932001f49Smrgfunc_convert_path_nix_to_w32 ()
318032001f49Smrg{
31817ec3b29aSmrg  $debug_cmd
31827ec3b29aSmrg
31837ec3b29aSmrg  func_to_host_path_result=$1
318432001f49Smrg  if test -n "$1"; then
318532001f49Smrg    # See func_convert_path_msys_to_w32:
318632001f49Smrg    func_stripname : : "$1"
318732001f49Smrg    func_to_host_path_tmp1=$func_stripname_result
318832001f49Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
31897ec3b29aSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
319032001f49Smrg    func_convert_path_check : ";" \
319132001f49Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
319232001f49Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
319332001f49Smrg  fi
319432001f49Smrg}
319532001f49Smrg# end func_convert_path_nix_to_w32
319632001f49Smrg
319732001f49Smrg
319832001f49Smrg# func_convert_path_msys_to_cygwin ARG
319932001f49Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
320032001f49Smrg# Returns result in func_to_host_file_result.
320132001f49Smrgfunc_convert_path_msys_to_cygwin ()
320232001f49Smrg{
32037ec3b29aSmrg  $debug_cmd
32047ec3b29aSmrg
32057ec3b29aSmrg  func_to_host_path_result=$1
320632001f49Smrg  if test -n "$1"; then
320732001f49Smrg    # See func_convert_path_msys_to_w32:
320832001f49Smrg    func_stripname : : "$1"
320932001f49Smrg    func_to_host_path_tmp1=$func_stripname_result
321032001f49Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
321132001f49Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
32127ec3b29aSmrg    func_to_host_path_result=$func_cygpath_result
321332001f49Smrg    func_convert_path_check : : \
321432001f49Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
321532001f49Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
321632001f49Smrg  fi
321732001f49Smrg}
321832001f49Smrg# end func_convert_path_msys_to_cygwin
321932001f49Smrg
322032001f49Smrg
322132001f49Smrg# func_convert_path_nix_to_cygwin ARG
322232001f49Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
322332001f49Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
322432001f49Smrg# func_to_host_file_result.
322532001f49Smrgfunc_convert_path_nix_to_cygwin ()
322632001f49Smrg{
32277ec3b29aSmrg  $debug_cmd
32287ec3b29aSmrg
32297ec3b29aSmrg  func_to_host_path_result=$1
323032001f49Smrg  if test -n "$1"; then
323132001f49Smrg    # Remove leading and trailing path separator characters from
323232001f49Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
323332001f49Smrg    # into '.;' and ';.', and winepath ignores them completely.
323432001f49Smrg    func_stripname : : "$1"
323532001f49Smrg    func_to_host_path_tmp1=$func_stripname_result
323632001f49Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
323732001f49Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
32387ec3b29aSmrg    func_to_host_path_result=$func_cygpath_result
323932001f49Smrg    func_convert_path_check : : \
324032001f49Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
324132001f49Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
324232001f49Smrg  fi
324332001f49Smrg}
324432001f49Smrg# end func_convert_path_nix_to_cygwin
324532001f49Smrg
324632001f49Smrg
32477ec3b29aSmrg# func_dll_def_p FILE
32487ec3b29aSmrg# True iff FILE is a Windows DLL '.def' file.
32497ec3b29aSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
32507ec3b29aSmrgfunc_dll_def_p ()
32517ec3b29aSmrg{
32527ec3b29aSmrg  $debug_cmd
32537ec3b29aSmrg
32547ec3b29aSmrg  func_dll_def_p_tmp=`$SED -n \
32557ec3b29aSmrg    -e 's/^[	 ]*//' \
32567ec3b29aSmrg    -e '/^\(;.*\)*$/d' \
32577ec3b29aSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
32587ec3b29aSmrg    -e q \
32597ec3b29aSmrg    "$1"`
32607ec3b29aSmrg  test DEF = "$func_dll_def_p_tmp"
32617ec3b29aSmrg}
32627ec3b29aSmrg
32637ec3b29aSmrg
326432001f49Smrg# func_mode_compile arg...
326532001f49Smrgfunc_mode_compile ()
326632001f49Smrg{
32677ec3b29aSmrg    $debug_cmd
32687ec3b29aSmrg
326932001f49Smrg    # Get the compilation command and the source file.
327032001f49Smrg    base_compile=
32717ec3b29aSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
327232001f49Smrg    suppress_opt=yes
327332001f49Smrg    suppress_output=
327432001f49Smrg    arg_mode=normal
327532001f49Smrg    libobj=
327632001f49Smrg    later=
327732001f49Smrg    pie_flag=
327832001f49Smrg
327932001f49Smrg    for arg
328032001f49Smrg    do
328132001f49Smrg      case $arg_mode in
328232001f49Smrg      arg  )
328332001f49Smrg	# do not "continue".  Instead, add this to base_compile
32847ec3b29aSmrg	lastarg=$arg
328532001f49Smrg	arg_mode=normal
328632001f49Smrg	;;
328732001f49Smrg
328832001f49Smrg      target )
32897ec3b29aSmrg	libobj=$arg
329032001f49Smrg	arg_mode=normal
329132001f49Smrg	continue
329232001f49Smrg	;;
329332001f49Smrg
329432001f49Smrg      normal )
329532001f49Smrg	# Accept any command-line options.
329632001f49Smrg	case $arg in
329732001f49Smrg	-o)
329832001f49Smrg	  test -n "$libobj" && \
32997ec3b29aSmrg	    func_fatal_error "you cannot specify '-o' more than once"
330032001f49Smrg	  arg_mode=target
330132001f49Smrg	  continue
330232001f49Smrg	  ;;
330332001f49Smrg
330432001f49Smrg	-pie | -fpie | -fPIE)
330532001f49Smrg          func_append pie_flag " $arg"
330632001f49Smrg	  continue
330732001f49Smrg	  ;;
330832001f49Smrg
330932001f49Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
331032001f49Smrg	  func_append later " $arg"
331132001f49Smrg	  continue
331232001f49Smrg	  ;;
331332001f49Smrg
331432001f49Smrg	-no-suppress)
331532001f49Smrg	  suppress_opt=no
331632001f49Smrg	  continue
331732001f49Smrg	  ;;
331832001f49Smrg
331932001f49Smrg	-Xcompiler)
332032001f49Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
332132001f49Smrg	  continue      #  The current "srcfile" will either be retained or
332232001f49Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
332332001f49Smrg
332432001f49Smrg	-Wc,*)
332532001f49Smrg	  func_stripname '-Wc,' '' "$arg"
332632001f49Smrg	  args=$func_stripname_result
332732001f49Smrg	  lastarg=
33287ec3b29aSmrg	  save_ifs=$IFS; IFS=,
332932001f49Smrg	  for arg in $args; do
33307ec3b29aSmrg	    IFS=$save_ifs
333132001f49Smrg	    func_append_quoted lastarg "$arg"
333232001f49Smrg	  done
33337ec3b29aSmrg	  IFS=$save_ifs
333432001f49Smrg	  func_stripname ' ' '' "$lastarg"
333532001f49Smrg	  lastarg=$func_stripname_result
333632001f49Smrg
333732001f49Smrg	  # Add the arguments to base_compile.
333832001f49Smrg	  func_append base_compile " $lastarg"
333932001f49Smrg	  continue
334032001f49Smrg	  ;;
334132001f49Smrg
334232001f49Smrg	*)
334332001f49Smrg	  # Accept the current argument as the source file.
334432001f49Smrg	  # The previous "srcfile" becomes the current argument.
334532001f49Smrg	  #
33467ec3b29aSmrg	  lastarg=$srcfile
33477ec3b29aSmrg	  srcfile=$arg
334832001f49Smrg	  ;;
334932001f49Smrg	esac  #  case $arg
335032001f49Smrg	;;
335132001f49Smrg      esac    #  case $arg_mode
335232001f49Smrg
335332001f49Smrg      # Aesthetically quote the previous argument.
335432001f49Smrg      func_append_quoted base_compile "$lastarg"
335532001f49Smrg    done # for arg
335632001f49Smrg
335732001f49Smrg    case $arg_mode in
335832001f49Smrg    arg)
335932001f49Smrg      func_fatal_error "you must specify an argument for -Xcompile"
336032001f49Smrg      ;;
336132001f49Smrg    target)
33627ec3b29aSmrg      func_fatal_error "you must specify a target with '-o'"
336332001f49Smrg      ;;
336432001f49Smrg    *)
336532001f49Smrg      # Get the name of the library object.
336632001f49Smrg      test -z "$libobj" && {
336732001f49Smrg	func_basename "$srcfile"
33687ec3b29aSmrg	libobj=$func_basename_result
336932001f49Smrg      }
337032001f49Smrg      ;;
337132001f49Smrg    esac
337232001f49Smrg
337332001f49Smrg    # Recognize several different file suffixes.
337432001f49Smrg    # If the user specifies -o file.o, it is replaced with file.lo
337532001f49Smrg    case $libobj in
337632001f49Smrg    *.[cCFSifmso] | \
337732001f49Smrg    *.ada | *.adb | *.ads | *.asm | \
337832001f49Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
337932001f49Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
338032001f49Smrg      func_xform "$libobj"
338132001f49Smrg      libobj=$func_xform_result
338232001f49Smrg      ;;
338332001f49Smrg    esac
338432001f49Smrg
338532001f49Smrg    case $libobj in
338632001f49Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
338732001f49Smrg    *)
33887ec3b29aSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
338932001f49Smrg      ;;
339032001f49Smrg    esac
339132001f49Smrg
339232001f49Smrg    func_infer_tag $base_compile
339332001f49Smrg
339432001f49Smrg    for arg in $later; do
339532001f49Smrg      case $arg in
339632001f49Smrg      -shared)
33977ec3b29aSmrg	test yes = "$build_libtool_libs" \
33987ec3b29aSmrg	  || func_fatal_configuration "cannot build a shared library"
339932001f49Smrg	build_old_libs=no
340032001f49Smrg	continue
340132001f49Smrg	;;
340232001f49Smrg
340332001f49Smrg      -static)
340432001f49Smrg	build_libtool_libs=no
340532001f49Smrg	build_old_libs=yes
340632001f49Smrg	continue
340732001f49Smrg	;;
340832001f49Smrg
340932001f49Smrg      -prefer-pic)
341032001f49Smrg	pic_mode=yes
341132001f49Smrg	continue
341232001f49Smrg	;;
341332001f49Smrg
341432001f49Smrg      -prefer-non-pic)
341532001f49Smrg	pic_mode=no
341632001f49Smrg	continue
341732001f49Smrg	;;
341832001f49Smrg      esac
341932001f49Smrg    done
342032001f49Smrg
342132001f49Smrg    func_quote_for_eval "$libobj"
342232001f49Smrg    test "X$libobj" != "X$func_quote_for_eval_result" \
342332001f49Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
34247ec3b29aSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
342532001f49Smrg    func_dirname_and_basename "$obj" "/" ""
34267ec3b29aSmrg    objname=$func_basename_result
34277ec3b29aSmrg    xdir=$func_dirname_result
34287ec3b29aSmrg    lobj=$xdir$objdir/$objname
342932001f49Smrg
343032001f49Smrg    test -z "$base_compile" && \
343132001f49Smrg      func_fatal_help "you must specify a compilation command"
343232001f49Smrg
343332001f49Smrg    # Delete any leftover library objects.
34347ec3b29aSmrg    if test yes = "$build_old_libs"; then
343532001f49Smrg      removelist="$obj $lobj $libobj ${libobj}T"
343632001f49Smrg    else
343732001f49Smrg      removelist="$lobj $libobj ${libobj}T"
343832001f49Smrg    fi
343932001f49Smrg
344032001f49Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
344132001f49Smrg    case $host_os in
344232001f49Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
344332001f49Smrg      pic_mode=default
344432001f49Smrg      ;;
344532001f49Smrg    esac
34467ec3b29aSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
344732001f49Smrg      # non-PIC code in shared libraries is not supported
344832001f49Smrg      pic_mode=default
344932001f49Smrg    fi
345032001f49Smrg
345132001f49Smrg    # Calculate the filename of the output object if compiler does
345232001f49Smrg    # not support -o with -c
34537ec3b29aSmrg    if test no = "$compiler_c_o"; then
34547ec3b29aSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
34557ec3b29aSmrg      lockfile=$output_obj.lock
345632001f49Smrg    else
345732001f49Smrg      output_obj=
345832001f49Smrg      need_locks=no
345932001f49Smrg      lockfile=
346032001f49Smrg    fi
346132001f49Smrg
346232001f49Smrg    # Lock this critical section if it is needed
346332001f49Smrg    # We use this script file to make the link, it avoids creating a new file
34647ec3b29aSmrg    if test yes = "$need_locks"; then
346532001f49Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
346632001f49Smrg	func_echo "Waiting for $lockfile to be removed"
346732001f49Smrg	sleep 2
346832001f49Smrg      done
34697ec3b29aSmrg    elif test warn = "$need_locks"; then
347032001f49Smrg      if test -f "$lockfile"; then
347132001f49Smrg	$ECHO "\
347232001f49Smrg*** ERROR, $lockfile exists and contains:
347332001f49Smrg`cat $lockfile 2>/dev/null`
347432001f49Smrg
347532001f49SmrgThis indicates that another process is trying to use the same
347632001f49Smrgtemporary object file, and libtool could not work around it because
34777ec3b29aSmrgyour compiler does not support '-c' and '-o' together.  If you
347832001f49Smrgrepeat this compilation, it may succeed, by chance, but you had better
347932001f49Smrgavoid parallel builds (make -j) in this platform, or get a better
348032001f49Smrgcompiler."
348132001f49Smrg
348232001f49Smrg	$opt_dry_run || $RM $removelist
348332001f49Smrg	exit $EXIT_FAILURE
348432001f49Smrg      fi
348532001f49Smrg      func_append removelist " $output_obj"
348632001f49Smrg      $ECHO "$srcfile" > "$lockfile"
348732001f49Smrg    fi
348832001f49Smrg
348932001f49Smrg    $opt_dry_run || $RM $removelist
349032001f49Smrg    func_append removelist " $lockfile"
349132001f49Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
349232001f49Smrg
349332001f49Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
349432001f49Smrg    srcfile=$func_to_tool_file_result
349532001f49Smrg    func_quote_for_eval "$srcfile"
349632001f49Smrg    qsrcfile=$func_quote_for_eval_result
349732001f49Smrg
349832001f49Smrg    # Only build a PIC object if we are building libtool libraries.
34997ec3b29aSmrg    if test yes = "$build_libtool_libs"; then
350032001f49Smrg      # Without this assignment, base_compile gets emptied.
350132001f49Smrg      fbsd_hideous_sh_bug=$base_compile
350232001f49Smrg
35037ec3b29aSmrg      if test no != "$pic_mode"; then
350432001f49Smrg	command="$base_compile $qsrcfile $pic_flag"
350532001f49Smrg      else
350632001f49Smrg	# Don't build PIC code
350732001f49Smrg	command="$base_compile $qsrcfile"
350832001f49Smrg      fi
350932001f49Smrg
351032001f49Smrg      func_mkdir_p "$xdir$objdir"
351132001f49Smrg
351232001f49Smrg      if test -z "$output_obj"; then
351332001f49Smrg	# Place PIC objects in $objdir
351432001f49Smrg	func_append command " -o $lobj"
351532001f49Smrg      fi
351632001f49Smrg
351732001f49Smrg      func_show_eval_locale "$command"	\
351832001f49Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
351932001f49Smrg
35207ec3b29aSmrg      if test warn = "$need_locks" &&
352132001f49Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
352232001f49Smrg	$ECHO "\
352332001f49Smrg*** ERROR, $lockfile contains:
352432001f49Smrg`cat $lockfile 2>/dev/null`
352532001f49Smrg
352632001f49Smrgbut it should contain:
352732001f49Smrg$srcfile
352832001f49Smrg
352932001f49SmrgThis indicates that another process is trying to use the same
353032001f49Smrgtemporary object file, and libtool could not work around it because
35317ec3b29aSmrgyour compiler does not support '-c' and '-o' together.  If you
353232001f49Smrgrepeat this compilation, it may succeed, by chance, but you had better
353332001f49Smrgavoid parallel builds (make -j) in this platform, or get a better
353432001f49Smrgcompiler."
353532001f49Smrg
353632001f49Smrg	$opt_dry_run || $RM $removelist
353732001f49Smrg	exit $EXIT_FAILURE
353832001f49Smrg      fi
353932001f49Smrg
354032001f49Smrg      # Just move the object if needed, then go on to compile the next one
354132001f49Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
354232001f49Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
354332001f49Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
354432001f49Smrg      fi
354532001f49Smrg
354632001f49Smrg      # Allow error messages only from the first compilation.
35477ec3b29aSmrg      if test yes = "$suppress_opt"; then
354832001f49Smrg	suppress_output=' >/dev/null 2>&1'
354932001f49Smrg      fi
355032001f49Smrg    fi
355132001f49Smrg
355232001f49Smrg    # Only build a position-dependent object if we build old libraries.
35537ec3b29aSmrg    if test yes = "$build_old_libs"; then
35547ec3b29aSmrg      if test yes != "$pic_mode"; then
355532001f49Smrg	# Don't build PIC code
355632001f49Smrg	command="$base_compile $qsrcfile$pie_flag"
355732001f49Smrg      else
355832001f49Smrg	command="$base_compile $qsrcfile $pic_flag"
355932001f49Smrg      fi
35607ec3b29aSmrg      if test yes = "$compiler_c_o"; then
356132001f49Smrg	func_append command " -o $obj"
356232001f49Smrg      fi
356332001f49Smrg
356432001f49Smrg      # Suppress compiler output if we already did a PIC compilation.
356532001f49Smrg      func_append command "$suppress_output"
356632001f49Smrg      func_show_eval_locale "$command" \
356732001f49Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
356832001f49Smrg
35697ec3b29aSmrg      if test warn = "$need_locks" &&
357032001f49Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
357132001f49Smrg	$ECHO "\
357232001f49Smrg*** ERROR, $lockfile contains:
357332001f49Smrg`cat $lockfile 2>/dev/null`
357432001f49Smrg
357532001f49Smrgbut it should contain:
357632001f49Smrg$srcfile
357732001f49Smrg
357832001f49SmrgThis indicates that another process is trying to use the same
357932001f49Smrgtemporary object file, and libtool could not work around it because
35807ec3b29aSmrgyour compiler does not support '-c' and '-o' together.  If you
358132001f49Smrgrepeat this compilation, it may succeed, by chance, but you had better
358232001f49Smrgavoid parallel builds (make -j) in this platform, or get a better
358332001f49Smrgcompiler."
358432001f49Smrg
358532001f49Smrg	$opt_dry_run || $RM $removelist
358632001f49Smrg	exit $EXIT_FAILURE
358732001f49Smrg      fi
358832001f49Smrg
358932001f49Smrg      # Just move the object if needed
359032001f49Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
359132001f49Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
359232001f49Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
359332001f49Smrg      fi
359432001f49Smrg    fi
359532001f49Smrg
359632001f49Smrg    $opt_dry_run || {
359732001f49Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
359832001f49Smrg
359932001f49Smrg      # Unlock the critical section if it was locked
36007ec3b29aSmrg      if test no != "$need_locks"; then
360132001f49Smrg	removelist=$lockfile
360232001f49Smrg        $RM "$lockfile"
360332001f49Smrg      fi
360432001f49Smrg    }
360532001f49Smrg
360632001f49Smrg    exit $EXIT_SUCCESS
360732001f49Smrg}
360832001f49Smrg
360932001f49Smrg$opt_help || {
36107ec3b29aSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
361132001f49Smrg}
361232001f49Smrg
361332001f49Smrgfunc_mode_help ()
361432001f49Smrg{
361532001f49Smrg    # We need to display help for each of the modes.
361632001f49Smrg    case $opt_mode in
361732001f49Smrg      "")
361832001f49Smrg        # Generic help is extracted from the usage comments
361932001f49Smrg        # at the start of this file.
362032001f49Smrg        func_help
362132001f49Smrg        ;;
362232001f49Smrg
362332001f49Smrg      clean)
362432001f49Smrg        $ECHO \
362532001f49Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
362632001f49Smrg
362732001f49SmrgRemove files from the build directory.
362832001f49Smrg
362932001f49SmrgRM is the name of the program to use to delete files associated with each FILE
36307ec3b29aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
363132001f49Smrgto RM.
363232001f49Smrg
363332001f49SmrgIf FILE is a libtool library, object or program, all the files associated
363432001f49Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
363532001f49Smrg        ;;
363632001f49Smrg
363732001f49Smrg      compile)
363832001f49Smrg      $ECHO \
363932001f49Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
364032001f49Smrg
364132001f49SmrgCompile a source file into a libtool library object.
364232001f49Smrg
364332001f49SmrgThis mode accepts the following additional options:
364432001f49Smrg
364532001f49Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
364632001f49Smrg  -no-suppress      do not suppress compiler output for multiple passes
364732001f49Smrg  -prefer-pic       try to build PIC objects only
364832001f49Smrg  -prefer-non-pic   try to build non-PIC objects only
36497ec3b29aSmrg  -shared           do not build a '.o' file suitable for static linking
36507ec3b29aSmrg  -static           only build a '.o' file suitable for static linking
365132001f49Smrg  -Wc,FLAG          pass FLAG directly to the compiler
365232001f49Smrg
36537ec3b29aSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
365432001f49Smrgfrom the given SOURCEFILE.
365532001f49Smrg
365632001f49SmrgThe output file name is determined by removing the directory component from
36577ec3b29aSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
36587ec3b29aSmrglibrary object suffix, '.lo'."
365932001f49Smrg        ;;
366032001f49Smrg
366132001f49Smrg      execute)
366232001f49Smrg        $ECHO \
366332001f49Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
366432001f49Smrg
366532001f49SmrgAutomatically set library path, then run a program.
366632001f49Smrg
366732001f49SmrgThis mode accepts the following additional options:
366832001f49Smrg
366932001f49Smrg  -dlopen FILE      add the directory containing FILE to the library path
367032001f49Smrg
36717ec3b29aSmrgThis mode sets the library path environment variable according to '-dlopen'
367232001f49Smrgflags.
367332001f49Smrg
367432001f49SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
367532001f49Smrginto their corresponding uninstalled binary, and any of their required library
367632001f49Smrgdirectories are added to the library path.
367732001f49Smrg
367832001f49SmrgThen, COMMAND is executed, with ARGS as arguments."
367932001f49Smrg        ;;
368032001f49Smrg
368132001f49Smrg      finish)
368232001f49Smrg        $ECHO \
368332001f49Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
368432001f49Smrg
368532001f49SmrgComplete the installation of libtool libraries.
368632001f49Smrg
368732001f49SmrgEach LIBDIR is a directory that contains libtool libraries.
368832001f49Smrg
368932001f49SmrgThe commands that this mode executes may require superuser privileges.  Use
36907ec3b29aSmrgthe '--dry-run' option if you just want to see what would be executed."
369132001f49Smrg        ;;
369232001f49Smrg
369332001f49Smrg      install)
369432001f49Smrg        $ECHO \
369532001f49Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
369632001f49Smrg
369732001f49SmrgInstall executables or libraries.
369832001f49Smrg
369932001f49SmrgINSTALL-COMMAND is the installation command.  The first component should be
37007ec3b29aSmrgeither the 'install' or 'cp' program.
370132001f49Smrg
370232001f49SmrgThe following components of INSTALL-COMMAND are treated specially:
370332001f49Smrg
370432001f49Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
370532001f49Smrg
370632001f49SmrgThe rest of the components are interpreted as arguments to that command (only
370732001f49SmrgBSD-compatible install options are recognized)."
370832001f49Smrg        ;;
370932001f49Smrg
371032001f49Smrg      link)
371132001f49Smrg        $ECHO \
371232001f49Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
371332001f49Smrg
371432001f49SmrgLink object files or libraries together to form another library, or to
371532001f49Smrgcreate an executable program.
371632001f49Smrg
371732001f49SmrgLINK-COMMAND is a command using the C compiler that you would use to create
371832001f49Smrga program from several object files.
371932001f49Smrg
372032001f49SmrgThe following components of LINK-COMMAND are treated specially:
372132001f49Smrg
372232001f49Smrg  -all-static       do not do any dynamic linking at all
372332001f49Smrg  -avoid-version    do not add a version suffix if possible
372432001f49Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
372532001f49Smrg                    libraries must be found in the PATH setting at runtime)
37267ec3b29aSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
372732001f49Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
372832001f49Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
372932001f49Smrg  -export-symbols SYMFILE
373032001f49Smrg                    try to export only the symbols listed in SYMFILE
373132001f49Smrg  -export-symbols-regex REGEX
373232001f49Smrg                    try to export only the symbols matching REGEX
373332001f49Smrg  -LLIBDIR          search LIBDIR for required installed libraries
373432001f49Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
373532001f49Smrg  -module           build a library that can dlopened
373632001f49Smrg  -no-fast-install  disable the fast-install mode
373732001f49Smrg  -no-install       link a not-installable executable
373832001f49Smrg  -no-undefined     declare that a library does not refer to external symbols
373932001f49Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
37407ec3b29aSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
37417ec3b29aSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
374232001f49Smrg  -precious-files-regex REGEX
374332001f49Smrg                    don't remove output files matching REGEX
374432001f49Smrg  -release RELEASE  specify package release information
374532001f49Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
374632001f49Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
374732001f49Smrg  -shared           only do dynamic linking of libtool libraries
374832001f49Smrg  -shrext SUFFIX    override the standard shared library file extension
374932001f49Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
375032001f49Smrg  -static-libtool-libs
375132001f49Smrg                    do not do any dynamic linking of libtool libraries
375232001f49Smrg  -version-info CURRENT[:REVISION[:AGE]]
375332001f49Smrg                    specify library version info [each variable defaults to 0]
375432001f49Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
375532001f49Smrg  -Wc,FLAG
375632001f49Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
375732001f49Smrg  -Wl,FLAG
375832001f49Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
375932001f49Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
376032001f49Smrg
37617ec3b29aSmrgAll other options (arguments beginning with '-') are ignored.
376232001f49Smrg
37637ec3b29aSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
376432001f49Smrgtreated as uninstalled libtool libraries, other files are standard or library
376532001f49Smrgobject files.
376632001f49Smrg
37677ec3b29aSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
37687ec3b29aSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
376932001f49Smrgrequired, except when creating a convenience library.
377032001f49Smrg
37717ec3b29aSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
37727ec3b29aSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
377332001f49Smrg
37747ec3b29aSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
377532001f49Smrgis created, otherwise an executable program is created."
377632001f49Smrg        ;;
377732001f49Smrg
377832001f49Smrg      uninstall)
377932001f49Smrg        $ECHO \
378032001f49Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
378132001f49Smrg
378232001f49SmrgRemove libraries from an installation directory.
378332001f49Smrg
378432001f49SmrgRM is the name of the program to use to delete files associated with each FILE
37857ec3b29aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
378632001f49Smrgto RM.
378732001f49Smrg
378832001f49SmrgIf FILE is a libtool library, all the files associated with it are deleted.
378932001f49SmrgOtherwise, only FILE itself is deleted using RM."
379032001f49Smrg        ;;
379132001f49Smrg
379232001f49Smrg      *)
37937ec3b29aSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
379432001f49Smrg        ;;
379532001f49Smrg    esac
379632001f49Smrg
379732001f49Smrg    echo
37987ec3b29aSmrg    $ECHO "Try '$progname --help' for more information about other modes."
379932001f49Smrg}
380032001f49Smrg
380132001f49Smrg# Now that we've collected a possible --mode arg, show help if necessary
380232001f49Smrgif $opt_help; then
38037ec3b29aSmrg  if test : = "$opt_help"; then
380432001f49Smrg    func_mode_help
380532001f49Smrg  else
380632001f49Smrg    {
380732001f49Smrg      func_help noexit
380832001f49Smrg      for opt_mode in compile link execute install finish uninstall clean; do
380932001f49Smrg	func_mode_help
381032001f49Smrg      done
38117ec3b29aSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
381232001f49Smrg    {
381332001f49Smrg      func_help noexit
381432001f49Smrg      for opt_mode in compile link execute install finish uninstall clean; do
381532001f49Smrg	echo
381632001f49Smrg	func_mode_help
381732001f49Smrg      done
381832001f49Smrg    } |
38197ec3b29aSmrg    $SED '1d
382032001f49Smrg      /^When reporting/,/^Report/{
382132001f49Smrg	H
382232001f49Smrg	d
382332001f49Smrg      }
382432001f49Smrg      $x
382532001f49Smrg      /information about other modes/d
382632001f49Smrg      /more detailed .*MODE/d
382732001f49Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
382832001f49Smrg  fi
382932001f49Smrg  exit $?
383032001f49Smrgfi
383132001f49Smrg
383232001f49Smrg
383332001f49Smrg# func_mode_execute arg...
383432001f49Smrgfunc_mode_execute ()
383532001f49Smrg{
38367ec3b29aSmrg    $debug_cmd
38377ec3b29aSmrg
383832001f49Smrg    # The first argument is the command name.
38397ec3b29aSmrg    cmd=$nonopt
384032001f49Smrg    test -z "$cmd" && \
384132001f49Smrg      func_fatal_help "you must specify a COMMAND"
384232001f49Smrg
384332001f49Smrg    # Handle -dlopen flags immediately.
384432001f49Smrg    for file in $opt_dlopen; do
384532001f49Smrg      test -f "$file" \
38467ec3b29aSmrg	|| func_fatal_help "'$file' is not a file"
384732001f49Smrg
384832001f49Smrg      dir=
384932001f49Smrg      case $file in
385032001f49Smrg      *.la)
385132001f49Smrg	func_resolve_sysroot "$file"
385232001f49Smrg	file=$func_resolve_sysroot_result
385332001f49Smrg
385432001f49Smrg	# Check to see that this really is a libtool archive.
385532001f49Smrg	func_lalib_unsafe_p "$file" \
38567ec3b29aSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
385732001f49Smrg
385832001f49Smrg	# Read the libtool library.
385932001f49Smrg	dlname=
386032001f49Smrg	library_names=
386132001f49Smrg	func_source "$file"
386232001f49Smrg
386332001f49Smrg	# Skip this library if it cannot be dlopened.
386432001f49Smrg	if test -z "$dlname"; then
386532001f49Smrg	  # Warn if it was a shared library.
386632001f49Smrg	  test -n "$library_names" && \
38677ec3b29aSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
386832001f49Smrg	  continue
386932001f49Smrg	fi
387032001f49Smrg
387132001f49Smrg	func_dirname "$file" "" "."
38727ec3b29aSmrg	dir=$func_dirname_result
387332001f49Smrg
387432001f49Smrg	if test -f "$dir/$objdir/$dlname"; then
387532001f49Smrg	  func_append dir "/$objdir"
387632001f49Smrg	else
387732001f49Smrg	  if test ! -f "$dir/$dlname"; then
38787ec3b29aSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
387932001f49Smrg	  fi
388032001f49Smrg	fi
388132001f49Smrg	;;
388232001f49Smrg
388332001f49Smrg      *.lo)
388432001f49Smrg	# Just add the directory containing the .lo file.
388532001f49Smrg	func_dirname "$file" "" "."
38867ec3b29aSmrg	dir=$func_dirname_result
388732001f49Smrg	;;
388832001f49Smrg
388932001f49Smrg      *)
38907ec3b29aSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
389132001f49Smrg	continue
389232001f49Smrg	;;
389332001f49Smrg      esac
389432001f49Smrg
389532001f49Smrg      # Get the absolute pathname.
389632001f49Smrg      absdir=`cd "$dir" && pwd`
38977ec3b29aSmrg      test -n "$absdir" && dir=$absdir
389832001f49Smrg
389932001f49Smrg      # Now add the directory to shlibpath_var.
390032001f49Smrg      if eval "test -z \"\$$shlibpath_var\""; then
390132001f49Smrg	eval "$shlibpath_var=\"\$dir\""
390232001f49Smrg      else
390332001f49Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
390432001f49Smrg      fi
390532001f49Smrg    done
390632001f49Smrg
390732001f49Smrg    # This variable tells wrapper scripts just to set shlibpath_var
390832001f49Smrg    # rather than running their programs.
39097ec3b29aSmrg    libtool_execute_magic=$magic
391032001f49Smrg
391132001f49Smrg    # Check if any of the arguments is a wrapper script.
391232001f49Smrg    args=
391332001f49Smrg    for file
391432001f49Smrg    do
391532001f49Smrg      case $file in
391632001f49Smrg      -* | *.la | *.lo ) ;;
391732001f49Smrg      *)
391832001f49Smrg	# Do a test to see if this is really a libtool program.
391932001f49Smrg	if func_ltwrapper_script_p "$file"; then
392032001f49Smrg	  func_source "$file"
392132001f49Smrg	  # Transform arg to wrapped name.
39227ec3b29aSmrg	  file=$progdir/$program
392332001f49Smrg	elif func_ltwrapper_executable_p "$file"; then
392432001f49Smrg	  func_ltwrapper_scriptname "$file"
392532001f49Smrg	  func_source "$func_ltwrapper_scriptname_result"
392632001f49Smrg	  # Transform arg to wrapped name.
39277ec3b29aSmrg	  file=$progdir/$program
392832001f49Smrg	fi
392932001f49Smrg	;;
393032001f49Smrg      esac
393132001f49Smrg      # Quote arguments (to preserve shell metacharacters).
393232001f49Smrg      func_append_quoted args "$file"
393332001f49Smrg    done
393432001f49Smrg
39357ec3b29aSmrg    if $opt_dry_run; then
39367ec3b29aSmrg      # Display what would be done.
39377ec3b29aSmrg      if test -n "$shlibpath_var"; then
39387ec3b29aSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
39397ec3b29aSmrg	echo "export $shlibpath_var"
39407ec3b29aSmrg      fi
39417ec3b29aSmrg      $ECHO "$cmd$args"
39427ec3b29aSmrg      exit $EXIT_SUCCESS
39437ec3b29aSmrg    else
394432001f49Smrg      if test -n "$shlibpath_var"; then
394532001f49Smrg	# Export the shlibpath_var.
394632001f49Smrg	eval "export $shlibpath_var"
394732001f49Smrg      fi
394832001f49Smrg
394932001f49Smrg      # Restore saved environment variables
395032001f49Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
395132001f49Smrg      do
395232001f49Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
395332001f49Smrg                $lt_var=\$save_$lt_var; export $lt_var
395432001f49Smrg	      else
395532001f49Smrg		$lt_unset $lt_var
395632001f49Smrg	      fi"
395732001f49Smrg      done
395832001f49Smrg
395932001f49Smrg      # Now prepare to actually exec the command.
39607ec3b29aSmrg      exec_cmd=\$cmd$args
396132001f49Smrg    fi
396232001f49Smrg}
396332001f49Smrg
39647ec3b29aSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
396532001f49Smrg
396632001f49Smrg
396732001f49Smrg# func_mode_finish arg...
396832001f49Smrgfunc_mode_finish ()
396932001f49Smrg{
39707ec3b29aSmrg    $debug_cmd
39717ec3b29aSmrg
397232001f49Smrg    libs=
397332001f49Smrg    libdirs=
397432001f49Smrg    admincmds=
397532001f49Smrg
397632001f49Smrg    for opt in "$nonopt" ${1+"$@"}
397732001f49Smrg    do
397832001f49Smrg      if test -d "$opt"; then
397932001f49Smrg	func_append libdirs " $opt"
398032001f49Smrg
398132001f49Smrg      elif test -f "$opt"; then
398232001f49Smrg	if func_lalib_unsafe_p "$opt"; then
398332001f49Smrg	  func_append libs " $opt"
398432001f49Smrg	else
39857ec3b29aSmrg	  func_warning "'$opt' is not a valid libtool archive"
398632001f49Smrg	fi
398732001f49Smrg
398832001f49Smrg      else
39897ec3b29aSmrg	func_fatal_error "invalid argument '$opt'"
399032001f49Smrg      fi
399132001f49Smrg    done
399232001f49Smrg
399332001f49Smrg    if test -n "$libs"; then
399432001f49Smrg      if test -n "$lt_sysroot"; then
399532001f49Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
399632001f49Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
399732001f49Smrg      else
399832001f49Smrg        sysroot_cmd=
399932001f49Smrg      fi
400032001f49Smrg
400132001f49Smrg      # Remove sysroot references
400232001f49Smrg      if $opt_dry_run; then
400332001f49Smrg        for lib in $libs; do
40047ec3b29aSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
400532001f49Smrg        done
400632001f49Smrg      else
400732001f49Smrg        tmpdir=`func_mktempdir`
400832001f49Smrg        for lib in $libs; do
40097ec3b29aSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
401032001f49Smrg	    > $tmpdir/tmp-la
401132001f49Smrg	  mv -f $tmpdir/tmp-la $lib
401232001f49Smrg	done
401332001f49Smrg        ${RM}r "$tmpdir"
401432001f49Smrg      fi
401532001f49Smrg    fi
401632001f49Smrg
401732001f49Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
401832001f49Smrg      for libdir in $libdirs; do
401932001f49Smrg	if test -n "$finish_cmds"; then
402032001f49Smrg	  # Do each command in the finish commands.
402132001f49Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
402232001f49Smrg'"$cmd"'"'
402332001f49Smrg	fi
402432001f49Smrg	if test -n "$finish_eval"; then
402532001f49Smrg	  # Do the single finish_eval.
402632001f49Smrg	  eval cmds=\"$finish_eval\"
402732001f49Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
402832001f49Smrg       $cmds"
402932001f49Smrg	fi
403032001f49Smrg      done
403132001f49Smrg    fi
403232001f49Smrg
403332001f49Smrg    # Exit here if they wanted silent mode.
40347ec3b29aSmrg    $opt_quiet && exit $EXIT_SUCCESS
403532001f49Smrg
403632001f49Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
403732001f49Smrg      echo "----------------------------------------------------------------------"
403832001f49Smrg      echo "Libraries have been installed in:"
403932001f49Smrg      for libdir in $libdirs; do
404032001f49Smrg	$ECHO "   $libdir"
404132001f49Smrg      done
404232001f49Smrg      echo
404332001f49Smrg      echo "If you ever happen to want to link against installed libraries"
404432001f49Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
40457ec3b29aSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
404632001f49Smrg      echo "flag during linking and do at least one of the following:"
404732001f49Smrg      if test -n "$shlibpath_var"; then
40487ec3b29aSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
404932001f49Smrg	echo "     during execution"
405032001f49Smrg      fi
405132001f49Smrg      if test -n "$runpath_var"; then
40527ec3b29aSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
405332001f49Smrg	echo "     during linking"
405432001f49Smrg      fi
405532001f49Smrg      if test -n "$hardcode_libdir_flag_spec"; then
405632001f49Smrg	libdir=LIBDIR
405732001f49Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
405832001f49Smrg
40597ec3b29aSmrg	$ECHO "   - use the '$flag' linker flag"
406032001f49Smrg      fi
406132001f49Smrg      if test -n "$admincmds"; then
406232001f49Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
406332001f49Smrg      fi
406432001f49Smrg      if test -f /etc/ld.so.conf; then
40657ec3b29aSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
406632001f49Smrg      fi
406732001f49Smrg      echo
406832001f49Smrg
406932001f49Smrg      echo "See any operating system documentation about shared libraries for"
407032001f49Smrg      case $host in
407132001f49Smrg	solaris2.[6789]|solaris2.1[0-9])
407232001f49Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
407332001f49Smrg	  echo "pages."
407432001f49Smrg	  ;;
407532001f49Smrg	*)
407632001f49Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
407732001f49Smrg	  ;;
407832001f49Smrg      esac
407932001f49Smrg      echo "----------------------------------------------------------------------"
408032001f49Smrg    fi
408132001f49Smrg    exit $EXIT_SUCCESS
408232001f49Smrg}
408332001f49Smrg
40847ec3b29aSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
408532001f49Smrg
408632001f49Smrg
408732001f49Smrg# func_mode_install arg...
408832001f49Smrgfunc_mode_install ()
408932001f49Smrg{
40907ec3b29aSmrg    $debug_cmd
40917ec3b29aSmrg
409232001f49Smrg    # There may be an optional sh(1) argument at the beginning of
409332001f49Smrg    # install_prog (especially on Windows NT).
40947ec3b29aSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
409532001f49Smrg       # Allow the use of GNU shtool's install command.
40967ec3b29aSmrg       case $nonopt in *shtool*) :;; *) false;; esac
40977ec3b29aSmrg    then
409832001f49Smrg      # Aesthetically quote it.
409932001f49Smrg      func_quote_for_eval "$nonopt"
410032001f49Smrg      install_prog="$func_quote_for_eval_result "
410132001f49Smrg      arg=$1
410232001f49Smrg      shift
410332001f49Smrg    else
410432001f49Smrg      install_prog=
410532001f49Smrg      arg=$nonopt
410632001f49Smrg    fi
410732001f49Smrg
410832001f49Smrg    # The real first argument should be the name of the installation program.
410932001f49Smrg    # Aesthetically quote it.
411032001f49Smrg    func_quote_for_eval "$arg"
411132001f49Smrg    func_append install_prog "$func_quote_for_eval_result"
411232001f49Smrg    install_shared_prog=$install_prog
411332001f49Smrg    case " $install_prog " in
411432001f49Smrg      *[\\\ /]cp\ *) install_cp=: ;;
411532001f49Smrg      *) install_cp=false ;;
411632001f49Smrg    esac
411732001f49Smrg
411832001f49Smrg    # We need to accept at least all the BSD install flags.
411932001f49Smrg    dest=
412032001f49Smrg    files=
412132001f49Smrg    opts=
412232001f49Smrg    prev=
412332001f49Smrg    install_type=
41247ec3b29aSmrg    isdir=false
412532001f49Smrg    stripme=
412632001f49Smrg    no_mode=:
412732001f49Smrg    for arg
412832001f49Smrg    do
412932001f49Smrg      arg2=
413032001f49Smrg      if test -n "$dest"; then
413132001f49Smrg	func_append files " $dest"
413232001f49Smrg	dest=$arg
413332001f49Smrg	continue
413432001f49Smrg      fi
413532001f49Smrg
413632001f49Smrg      case $arg in
41377ec3b29aSmrg      -d) isdir=: ;;
413832001f49Smrg      -f)
413932001f49Smrg	if $install_cp; then :; else
414032001f49Smrg	  prev=$arg
414132001f49Smrg	fi
414232001f49Smrg	;;
414332001f49Smrg      -g | -m | -o)
414432001f49Smrg	prev=$arg
414532001f49Smrg	;;
414632001f49Smrg      -s)
414732001f49Smrg	stripme=" -s"
414832001f49Smrg	continue
414932001f49Smrg	;;
415032001f49Smrg      -*)
415132001f49Smrg	;;
415232001f49Smrg      *)
415332001f49Smrg	# If the previous option needed an argument, then skip it.
415432001f49Smrg	if test -n "$prev"; then
41557ec3b29aSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
415632001f49Smrg	    arg2=$install_override_mode
415732001f49Smrg	    no_mode=false
415832001f49Smrg	  fi
415932001f49Smrg	  prev=
416032001f49Smrg	else
416132001f49Smrg	  dest=$arg
416232001f49Smrg	  continue
416332001f49Smrg	fi
416432001f49Smrg	;;
416532001f49Smrg      esac
416632001f49Smrg
416732001f49Smrg      # Aesthetically quote the argument.
416832001f49Smrg      func_quote_for_eval "$arg"
416932001f49Smrg      func_append install_prog " $func_quote_for_eval_result"
417032001f49Smrg      if test -n "$arg2"; then
417132001f49Smrg	func_quote_for_eval "$arg2"
417232001f49Smrg      fi
417332001f49Smrg      func_append install_shared_prog " $func_quote_for_eval_result"
417432001f49Smrg    done
417532001f49Smrg
417632001f49Smrg    test -z "$install_prog" && \
417732001f49Smrg      func_fatal_help "you must specify an install program"
417832001f49Smrg
417932001f49Smrg    test -n "$prev" && \
41807ec3b29aSmrg      func_fatal_help "the '$prev' option requires an argument"
418132001f49Smrg
418232001f49Smrg    if test -n "$install_override_mode" && $no_mode; then
418332001f49Smrg      if $install_cp; then :; else
418432001f49Smrg	func_quote_for_eval "$install_override_mode"
418532001f49Smrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
418632001f49Smrg      fi
418732001f49Smrg    fi
418832001f49Smrg
418932001f49Smrg    if test -z "$files"; then
419032001f49Smrg      if test -z "$dest"; then
419132001f49Smrg	func_fatal_help "no file or destination specified"
419232001f49Smrg      else
419332001f49Smrg	func_fatal_help "you must specify a destination"
419432001f49Smrg      fi
419532001f49Smrg    fi
419632001f49Smrg
419732001f49Smrg    # Strip any trailing slash from the destination.
419832001f49Smrg    func_stripname '' '/' "$dest"
419932001f49Smrg    dest=$func_stripname_result
420032001f49Smrg
420132001f49Smrg    # Check to see that the destination is a directory.
42027ec3b29aSmrg    test -d "$dest" && isdir=:
42037ec3b29aSmrg    if $isdir; then
42047ec3b29aSmrg      destdir=$dest
420532001f49Smrg      destname=
420632001f49Smrg    else
420732001f49Smrg      func_dirname_and_basename "$dest" "" "."
42087ec3b29aSmrg      destdir=$func_dirname_result
42097ec3b29aSmrg      destname=$func_basename_result
421032001f49Smrg
421132001f49Smrg      # Not a directory, so check to see that there is only one file specified.
421232001f49Smrg      set dummy $files; shift
421332001f49Smrg      test "$#" -gt 1 && \
42147ec3b29aSmrg	func_fatal_help "'$dest' is not a directory"
421532001f49Smrg    fi
421632001f49Smrg    case $destdir in
421732001f49Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
421832001f49Smrg    *)
421932001f49Smrg      for file in $files; do
422032001f49Smrg	case $file in
422132001f49Smrg	*.lo) ;;
422232001f49Smrg	*)
42237ec3b29aSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
422432001f49Smrg	  ;;
422532001f49Smrg	esac
422632001f49Smrg      done
422732001f49Smrg      ;;
422832001f49Smrg    esac
422932001f49Smrg
423032001f49Smrg    # This variable tells wrapper scripts just to set variables rather
423132001f49Smrg    # than running their programs.
42327ec3b29aSmrg    libtool_install_magic=$magic
423332001f49Smrg
423432001f49Smrg    staticlibs=
423532001f49Smrg    future_libdirs=
423632001f49Smrg    current_libdirs=
423732001f49Smrg    for file in $files; do
423832001f49Smrg
423932001f49Smrg      # Do each installation.
424032001f49Smrg      case $file in
424132001f49Smrg      *.$libext)
424232001f49Smrg	# Do the static libraries later.
424332001f49Smrg	func_append staticlibs " $file"
424432001f49Smrg	;;
424532001f49Smrg
424632001f49Smrg      *.la)
424732001f49Smrg	func_resolve_sysroot "$file"
424832001f49Smrg	file=$func_resolve_sysroot_result
424932001f49Smrg
425032001f49Smrg	# Check to see that this really is a libtool archive.
425132001f49Smrg	func_lalib_unsafe_p "$file" \
42527ec3b29aSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
425332001f49Smrg
425432001f49Smrg	library_names=
425532001f49Smrg	old_library=
425632001f49Smrg	relink_command=
425732001f49Smrg	func_source "$file"
425832001f49Smrg
425932001f49Smrg	# Add the libdir to current_libdirs if it is the destination.
426032001f49Smrg	if test "X$destdir" = "X$libdir"; then
426132001f49Smrg	  case "$current_libdirs " in
426232001f49Smrg	  *" $libdir "*) ;;
426332001f49Smrg	  *) func_append current_libdirs " $libdir" ;;
426432001f49Smrg	  esac
426532001f49Smrg	else
426632001f49Smrg	  # Note the libdir as a future libdir.
426732001f49Smrg	  case "$future_libdirs " in
426832001f49Smrg	  *" $libdir "*) ;;
426932001f49Smrg	  *) func_append future_libdirs " $libdir" ;;
427032001f49Smrg	  esac
427132001f49Smrg	fi
427232001f49Smrg
427332001f49Smrg	func_dirname "$file" "/" ""
42747ec3b29aSmrg	dir=$func_dirname_result
427532001f49Smrg	func_append dir "$objdir"
427632001f49Smrg
427732001f49Smrg	if test -n "$relink_command"; then
427832001f49Smrg	  # Determine the prefix the user has applied to our future dir.
427932001f49Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
428032001f49Smrg
428132001f49Smrg	  # Don't allow the user to place us outside of our expected
428232001f49Smrg	  # location b/c this prevents finding dependent libraries that
428332001f49Smrg	  # are installed to the same prefix.
428432001f49Smrg	  # At present, this check doesn't affect windows .dll's that
428532001f49Smrg	  # are installed into $libdir/../bin (currently, that works fine)
428632001f49Smrg	  # but it's something to keep an eye on.
428732001f49Smrg	  test "$inst_prefix_dir" = "$destdir" && \
42887ec3b29aSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
428932001f49Smrg
429032001f49Smrg	  if test -n "$inst_prefix_dir"; then
429132001f49Smrg	    # Stick the inst_prefix_dir data into the link command.
429232001f49Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
429332001f49Smrg	  else
429432001f49Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
429532001f49Smrg	  fi
429632001f49Smrg
42977ec3b29aSmrg	  func_warning "relinking '$file'"
429832001f49Smrg	  func_show_eval "$relink_command" \
42997ec3b29aSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
430032001f49Smrg	fi
430132001f49Smrg
430232001f49Smrg	# See the names of the shared library.
430332001f49Smrg	set dummy $library_names; shift
430432001f49Smrg	if test -n "$1"; then
43057ec3b29aSmrg	  realname=$1
430632001f49Smrg	  shift
430732001f49Smrg
43087ec3b29aSmrg	  srcname=$realname
43097ec3b29aSmrg	  test -n "$relink_command" && srcname=${realname}T
431032001f49Smrg
431132001f49Smrg	  # Install the shared library and build the symlinks.
431232001f49Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
431332001f49Smrg	      'exit $?'
43147ec3b29aSmrg	  tstripme=$stripme
431532001f49Smrg	  case $host_os in
431632001f49Smrg	  cygwin* | mingw* | pw32* | cegcc*)
431732001f49Smrg	    case $realname in
431832001f49Smrg	    *.dll.a)
43197ec3b29aSmrg	      tstripme=
43207ec3b29aSmrg	      ;;
43217ec3b29aSmrg	    esac
43227ec3b29aSmrg	    ;;
43237ec3b29aSmrg	  os2*)
43247ec3b29aSmrg	    case $realname in
43257ec3b29aSmrg	    *_dll.a)
43267ec3b29aSmrg	      tstripme=
432732001f49Smrg	      ;;
432832001f49Smrg	    esac
432932001f49Smrg	    ;;
433032001f49Smrg	  esac
433132001f49Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
433232001f49Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
433332001f49Smrg	  fi
433432001f49Smrg
433532001f49Smrg	  if test "$#" -gt 0; then
433632001f49Smrg	    # Delete the old symlinks, and create new ones.
43377ec3b29aSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
433832001f49Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
433932001f49Smrg	    # so we also need to try rm && ln -s.
434032001f49Smrg	    for linkname
434132001f49Smrg	    do
434232001f49Smrg	      test "$linkname" != "$realname" \
434332001f49Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
434432001f49Smrg	    done
434532001f49Smrg	  fi
434632001f49Smrg
434732001f49Smrg	  # Do each command in the postinstall commands.
43487ec3b29aSmrg	  lib=$destdir/$realname
434932001f49Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
435032001f49Smrg	fi
435132001f49Smrg
435232001f49Smrg	# Install the pseudo-library for information purposes.
435332001f49Smrg	func_basename "$file"
43547ec3b29aSmrg	name=$func_basename_result
43557ec3b29aSmrg	instname=$dir/${name}i
435632001f49Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
435732001f49Smrg
435832001f49Smrg	# Maybe install the static library, too.
435932001f49Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
436032001f49Smrg	;;
436132001f49Smrg
436232001f49Smrg      *.lo)
436332001f49Smrg	# Install (i.e. copy) a libtool object.
436432001f49Smrg
436532001f49Smrg	# Figure out destination file name, if it wasn't already specified.
436632001f49Smrg	if test -n "$destname"; then
43677ec3b29aSmrg	  destfile=$destdir/$destname
436832001f49Smrg	else
436932001f49Smrg	  func_basename "$file"
43707ec3b29aSmrg	  destfile=$func_basename_result
43717ec3b29aSmrg	  destfile=$destdir/$destfile
437232001f49Smrg	fi
437332001f49Smrg
437432001f49Smrg	# Deduce the name of the destination old-style object file.
437532001f49Smrg	case $destfile in
437632001f49Smrg	*.lo)
437732001f49Smrg	  func_lo2o "$destfile"
437832001f49Smrg	  staticdest=$func_lo2o_result
437932001f49Smrg	  ;;
438032001f49Smrg	*.$objext)
43817ec3b29aSmrg	  staticdest=$destfile
438232001f49Smrg	  destfile=
438332001f49Smrg	  ;;
438432001f49Smrg	*)
43857ec3b29aSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
438632001f49Smrg	  ;;
438732001f49Smrg	esac
438832001f49Smrg
438932001f49Smrg	# Install the libtool object if requested.
439032001f49Smrg	test -n "$destfile" && \
439132001f49Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
439232001f49Smrg
439332001f49Smrg	# Install the old object if enabled.
43947ec3b29aSmrg	if test yes = "$build_old_libs"; then
439532001f49Smrg	  # Deduce the name of the old-style object file.
439632001f49Smrg	  func_lo2o "$file"
439732001f49Smrg	  staticobj=$func_lo2o_result
439832001f49Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
439932001f49Smrg	fi
440032001f49Smrg	exit $EXIT_SUCCESS
440132001f49Smrg	;;
440232001f49Smrg
440332001f49Smrg      *)
440432001f49Smrg	# Figure out destination file name, if it wasn't already specified.
440532001f49Smrg	if test -n "$destname"; then
44067ec3b29aSmrg	  destfile=$destdir/$destname
440732001f49Smrg	else
440832001f49Smrg	  func_basename "$file"
44097ec3b29aSmrg	  destfile=$func_basename_result
44107ec3b29aSmrg	  destfile=$destdir/$destfile
441132001f49Smrg	fi
441232001f49Smrg
441332001f49Smrg	# If the file is missing, and there is a .exe on the end, strip it
441432001f49Smrg	# because it is most likely a libtool script we actually want to
441532001f49Smrg	# install
44167ec3b29aSmrg	stripped_ext=
441732001f49Smrg	case $file in
441832001f49Smrg	  *.exe)
441932001f49Smrg	    if test ! -f "$file"; then
442032001f49Smrg	      func_stripname '' '.exe' "$file"
442132001f49Smrg	      file=$func_stripname_result
44227ec3b29aSmrg	      stripped_ext=.exe
442332001f49Smrg	    fi
442432001f49Smrg	    ;;
442532001f49Smrg	esac
442632001f49Smrg
442732001f49Smrg	# Do a test to see if this is really a libtool program.
442832001f49Smrg	case $host in
442932001f49Smrg	*cygwin* | *mingw*)
443032001f49Smrg	    if func_ltwrapper_executable_p "$file"; then
443132001f49Smrg	      func_ltwrapper_scriptname "$file"
443232001f49Smrg	      wrapper=$func_ltwrapper_scriptname_result
443332001f49Smrg	    else
443432001f49Smrg	      func_stripname '' '.exe' "$file"
443532001f49Smrg	      wrapper=$func_stripname_result
443632001f49Smrg	    fi
443732001f49Smrg	    ;;
443832001f49Smrg	*)
443932001f49Smrg	    wrapper=$file
444032001f49Smrg	    ;;
444132001f49Smrg	esac
444232001f49Smrg	if func_ltwrapper_script_p "$wrapper"; then
444332001f49Smrg	  notinst_deplibs=
444432001f49Smrg	  relink_command=
444532001f49Smrg
444632001f49Smrg	  func_source "$wrapper"
444732001f49Smrg
444832001f49Smrg	  # Check the variables that should have been set.
444932001f49Smrg	  test -z "$generated_by_libtool_version" && \
44507ec3b29aSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
445132001f49Smrg
44527ec3b29aSmrg	  finalize=:
445332001f49Smrg	  for lib in $notinst_deplibs; do
445432001f49Smrg	    # Check to see that each library is installed.
445532001f49Smrg	    libdir=
445632001f49Smrg	    if test -f "$lib"; then
445732001f49Smrg	      func_source "$lib"
445832001f49Smrg	    fi
44597ec3b29aSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
446032001f49Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
44617ec3b29aSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
44627ec3b29aSmrg	      finalize=false
446332001f49Smrg	    fi
446432001f49Smrg	  done
446532001f49Smrg
446632001f49Smrg	  relink_command=
446732001f49Smrg	  func_source "$wrapper"
446832001f49Smrg
446932001f49Smrg	  outputname=
44707ec3b29aSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
447132001f49Smrg	    $opt_dry_run || {
44727ec3b29aSmrg	      if $finalize; then
447332001f49Smrg	        tmpdir=`func_mktempdir`
447432001f49Smrg		func_basename "$file$stripped_ext"
44757ec3b29aSmrg		file=$func_basename_result
44767ec3b29aSmrg	        outputname=$tmpdir/$file
447732001f49Smrg	        # Replace the output file specification.
447832001f49Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
447932001f49Smrg
44807ec3b29aSmrg	        $opt_quiet || {
448132001f49Smrg	          func_quote_for_expand "$relink_command"
448232001f49Smrg		  eval "func_echo $func_quote_for_expand_result"
448332001f49Smrg	        }
448432001f49Smrg	        if eval "$relink_command"; then :
448532001f49Smrg	          else
44867ec3b29aSmrg		  func_error "error: relink '$file' with the above command before installing it"
448732001f49Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
448832001f49Smrg		  continue
448932001f49Smrg	        fi
44907ec3b29aSmrg	        file=$outputname
449132001f49Smrg	      else
44927ec3b29aSmrg	        func_warning "cannot relink '$file'"
449332001f49Smrg	      fi
449432001f49Smrg	    }
449532001f49Smrg	  else
449632001f49Smrg	    # Install the binary that we compiled earlier.
449732001f49Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
449832001f49Smrg	  fi
449932001f49Smrg	fi
450032001f49Smrg
450132001f49Smrg	# remove .exe since cygwin /usr/bin/install will append another
450232001f49Smrg	# one anyway
450332001f49Smrg	case $install_prog,$host in
450432001f49Smrg	*/usr/bin/install*,*cygwin*)
450532001f49Smrg	  case $file:$destfile in
450632001f49Smrg	  *.exe:*.exe)
450732001f49Smrg	    # this is ok
450832001f49Smrg	    ;;
450932001f49Smrg	  *.exe:*)
451032001f49Smrg	    destfile=$destfile.exe
451132001f49Smrg	    ;;
451232001f49Smrg	  *:*.exe)
451332001f49Smrg	    func_stripname '' '.exe' "$destfile"
451432001f49Smrg	    destfile=$func_stripname_result
451532001f49Smrg	    ;;
451632001f49Smrg	  esac
451732001f49Smrg	  ;;
451832001f49Smrg	esac
451932001f49Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
452032001f49Smrg	$opt_dry_run || if test -n "$outputname"; then
452132001f49Smrg	  ${RM}r "$tmpdir"
452232001f49Smrg	fi
452332001f49Smrg	;;
452432001f49Smrg      esac
452532001f49Smrg    done
452632001f49Smrg
452732001f49Smrg    for file in $staticlibs; do
452832001f49Smrg      func_basename "$file"
45297ec3b29aSmrg      name=$func_basename_result
453032001f49Smrg
453132001f49Smrg      # Set up the ranlib parameters.
45327ec3b29aSmrg      oldlib=$destdir/$name
453332001f49Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
453432001f49Smrg      tool_oldlib=$func_to_tool_file_result
453532001f49Smrg
453632001f49Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
453732001f49Smrg
453832001f49Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
453932001f49Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
454032001f49Smrg      fi
454132001f49Smrg
454232001f49Smrg      # Do each command in the postinstall commands.
454332001f49Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
454432001f49Smrg    done
454532001f49Smrg
454632001f49Smrg    test -n "$future_libdirs" && \
45477ec3b29aSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
454832001f49Smrg
454932001f49Smrg    if test -n "$current_libdirs"; then
455032001f49Smrg      # Maybe just do a dry run.
455132001f49Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
45527ec3b29aSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
455332001f49Smrg    else
455432001f49Smrg      exit $EXIT_SUCCESS
455532001f49Smrg    fi
455632001f49Smrg}
455732001f49Smrg
45587ec3b29aSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
455932001f49Smrg
456032001f49Smrg
456132001f49Smrg# func_generate_dlsyms outputname originator pic_p
456232001f49Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
456332001f49Smrg# a dlpreopen symbol table.
456432001f49Smrgfunc_generate_dlsyms ()
456532001f49Smrg{
45667ec3b29aSmrg    $debug_cmd
45677ec3b29aSmrg
45687ec3b29aSmrg    my_outputname=$1
45697ec3b29aSmrg    my_originator=$2
45707ec3b29aSmrg    my_pic_p=${3-false}
45717ec3b29aSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
457232001f49Smrg    my_dlsyms=
457332001f49Smrg
45747ec3b29aSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
457532001f49Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
45767ec3b29aSmrg	my_dlsyms=${my_outputname}S.c
457732001f49Smrg      else
457832001f49Smrg	func_error "not configured to extract global symbols from dlpreopened files"
457932001f49Smrg      fi
458032001f49Smrg    fi
458132001f49Smrg
458232001f49Smrg    if test -n "$my_dlsyms"; then
458332001f49Smrg      case $my_dlsyms in
458432001f49Smrg      "") ;;
458532001f49Smrg      *.c)
458632001f49Smrg	# Discover the nlist of each of the dlfiles.
45877ec3b29aSmrg	nlist=$output_objdir/$my_outputname.nm
458832001f49Smrg
458932001f49Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
459032001f49Smrg
459132001f49Smrg	# Parse the name list into a source file.
459232001f49Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
459332001f49Smrg
459432001f49Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
45957ec3b29aSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
45967ec3b29aSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
459732001f49Smrg
459832001f49Smrg#ifdef __cplusplus
459932001f49Smrgextern \"C\" {
460032001f49Smrg#endif
460132001f49Smrg
46027ec3b29aSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
460332001f49Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
460432001f49Smrg#endif
460532001f49Smrg
460632001f49Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
46077ec3b29aSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
46087ec3b29aSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
460932001f49Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
461032001f49Smrg# define LT_DLSYM_CONST
46117ec3b29aSmrg#elif defined __osf__
461232001f49Smrg/* This system does not cope well with relocations in const data.  */
461332001f49Smrg# define LT_DLSYM_CONST
461432001f49Smrg#else
461532001f49Smrg# define LT_DLSYM_CONST const
461632001f49Smrg#endif
461732001f49Smrg
46187ec3b29aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
46197ec3b29aSmrg
462032001f49Smrg/* External symbol declarations for the compiler. */\
462132001f49Smrg"
462232001f49Smrg
46237ec3b29aSmrg	if test yes = "$dlself"; then
46247ec3b29aSmrg	  func_verbose "generating symbol list for '$output'"
462532001f49Smrg
462632001f49Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
462732001f49Smrg
462832001f49Smrg	  # Add our own program objects to the symbol list.
462932001f49Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
463032001f49Smrg	  for progfile in $progfiles; do
463132001f49Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
46327ec3b29aSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
463332001f49Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
463432001f49Smrg	  done
463532001f49Smrg
463632001f49Smrg	  if test -n "$exclude_expsyms"; then
463732001f49Smrg	    $opt_dry_run || {
463832001f49Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
463932001f49Smrg	      eval '$MV "$nlist"T "$nlist"'
464032001f49Smrg	    }
464132001f49Smrg	  fi
464232001f49Smrg
464332001f49Smrg	  if test -n "$export_symbols_regex"; then
464432001f49Smrg	    $opt_dry_run || {
464532001f49Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
464632001f49Smrg	      eval '$MV "$nlist"T "$nlist"'
464732001f49Smrg	    }
464832001f49Smrg	  fi
464932001f49Smrg
465032001f49Smrg	  # Prepare the list of exported symbols
465132001f49Smrg	  if test -z "$export_symbols"; then
46527ec3b29aSmrg	    export_symbols=$output_objdir/$outputname.exp
465332001f49Smrg	    $opt_dry_run || {
465432001f49Smrg	      $RM $export_symbols
46557ec3b29aSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
465632001f49Smrg	      case $host in
465732001f49Smrg	      *cygwin* | *mingw* | *cegcc* )
465832001f49Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
465932001f49Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
466032001f49Smrg	        ;;
466132001f49Smrg	      esac
466232001f49Smrg	    }
466332001f49Smrg	  else
466432001f49Smrg	    $opt_dry_run || {
46657ec3b29aSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
466632001f49Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
466732001f49Smrg	      eval '$MV "$nlist"T "$nlist"'
466832001f49Smrg	      case $host in
466932001f49Smrg	        *cygwin* | *mingw* | *cegcc* )
467032001f49Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
467132001f49Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
467232001f49Smrg	          ;;
467332001f49Smrg	      esac
467432001f49Smrg	    }
467532001f49Smrg	  fi
467632001f49Smrg	fi
467732001f49Smrg
467832001f49Smrg	for dlprefile in $dlprefiles; do
46797ec3b29aSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
468032001f49Smrg	  func_basename "$dlprefile"
46817ec3b29aSmrg	  name=$func_basename_result
468232001f49Smrg          case $host in
468332001f49Smrg	    *cygwin* | *mingw* | *cegcc* )
468432001f49Smrg	      # if an import library, we need to obtain dlname
468532001f49Smrg	      if func_win32_import_lib_p "$dlprefile"; then
468632001f49Smrg	        func_tr_sh "$dlprefile"
468732001f49Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
46887ec3b29aSmrg	        dlprefile_dlbasename=
468932001f49Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
469032001f49Smrg	          # Use subshell, to avoid clobbering current variable values
469132001f49Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
46927ec3b29aSmrg	          if test -n "$dlprefile_dlname"; then
469332001f49Smrg	            func_basename "$dlprefile_dlname"
46947ec3b29aSmrg	            dlprefile_dlbasename=$func_basename_result
469532001f49Smrg	          else
469632001f49Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
469732001f49Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
469832001f49Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
469932001f49Smrg	          fi
470032001f49Smrg	        fi
470132001f49Smrg	        $opt_dry_run || {
47027ec3b29aSmrg	          if test -n "$dlprefile_dlbasename"; then
470332001f49Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
470432001f49Smrg	          else
470532001f49Smrg	            func_warning "Could not compute DLL name from $name"
470632001f49Smrg	            eval '$ECHO ": $name " >> "$nlist"'
470732001f49Smrg	          fi
470832001f49Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
470932001f49Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
471032001f49Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
471132001f49Smrg	        }
471232001f49Smrg	      else # not an import lib
471332001f49Smrg	        $opt_dry_run || {
471432001f49Smrg	          eval '$ECHO ": $name " >> "$nlist"'
471532001f49Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
471632001f49Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
471732001f49Smrg	        }
471832001f49Smrg	      fi
471932001f49Smrg	    ;;
472032001f49Smrg	    *)
472132001f49Smrg	      $opt_dry_run || {
472232001f49Smrg	        eval '$ECHO ": $name " >> "$nlist"'
472332001f49Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
472432001f49Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
472532001f49Smrg	      }
472632001f49Smrg	    ;;
472732001f49Smrg          esac
472832001f49Smrg	done
472932001f49Smrg
473032001f49Smrg	$opt_dry_run || {
473132001f49Smrg	  # Make sure we have at least an empty file.
473232001f49Smrg	  test -f "$nlist" || : > "$nlist"
473332001f49Smrg
473432001f49Smrg	  if test -n "$exclude_expsyms"; then
473532001f49Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
473632001f49Smrg	    $MV "$nlist"T "$nlist"
473732001f49Smrg	  fi
473832001f49Smrg
473932001f49Smrg	  # Try sorting and uniquifying the output.
474032001f49Smrg	  if $GREP -v "^: " < "$nlist" |
474132001f49Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
474232001f49Smrg		sort -k 3
474332001f49Smrg	      else
474432001f49Smrg		sort +2
474532001f49Smrg	      fi |
474632001f49Smrg	      uniq > "$nlist"S; then
474732001f49Smrg	    :
474832001f49Smrg	  else
474932001f49Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
475032001f49Smrg	  fi
475132001f49Smrg
475232001f49Smrg	  if test -f "$nlist"S; then
475332001f49Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
475432001f49Smrg	  else
475532001f49Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
475632001f49Smrg	  fi
475732001f49Smrg
47587ec3b29aSmrg	  func_show_eval '$RM "${nlist}I"'
47597ec3b29aSmrg	  if test -n "$global_symbol_to_import"; then
47607ec3b29aSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
47617ec3b29aSmrg	  fi
47627ec3b29aSmrg
476332001f49Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
476432001f49Smrg
476532001f49Smrg/* The mapping between symbol names and symbols.  */
476632001f49Smrgtypedef struct {
476732001f49Smrg  const char *name;
476832001f49Smrg  void *address;
476932001f49Smrg} lt_dlsymlist;
477032001f49Smrgextern LT_DLSYM_CONST lt_dlsymlist
47717ec3b29aSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
47727ec3b29aSmrg"
47737ec3b29aSmrg
47747ec3b29aSmrg	  if test -s "$nlist"I; then
47757ec3b29aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47767ec3b29aSmrgstatic void lt_syminit(void)
47777ec3b29aSmrg{
47787ec3b29aSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
47797ec3b29aSmrg  for (; symbol->name; ++symbol)
47807ec3b29aSmrg    {"
47817ec3b29aSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
47827ec3b29aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47837ec3b29aSmrg    }
47847ec3b29aSmrg}"
47857ec3b29aSmrg	  fi
47867ec3b29aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
478732001f49SmrgLT_DLSYM_CONST lt_dlsymlist
478832001f49Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
47897ec3b29aSmrg{ {\"$my_originator\", (void *) 0},"
47907ec3b29aSmrg
47917ec3b29aSmrg	  if test -s "$nlist"I; then
47927ec3b29aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47937ec3b29aSmrg  {\"@INIT@\", (void *) &lt_syminit},"
47947ec3b29aSmrg	  fi
479532001f49Smrg
479632001f49Smrg	  case $need_lib_prefix in
479732001f49Smrg	  no)
479832001f49Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
479932001f49Smrg	    ;;
480032001f49Smrg	  *)
480132001f49Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
480232001f49Smrg	    ;;
480332001f49Smrg	  esac
480432001f49Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
480532001f49Smrg  {0, (void *) 0}
480632001f49Smrg};
480732001f49Smrg
480832001f49Smrg/* This works around a problem in FreeBSD linker */
480932001f49Smrg#ifdef FREEBSD_WORKAROUND
481032001f49Smrgstatic const void *lt_preloaded_setup() {
481132001f49Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
481232001f49Smrg}
481332001f49Smrg#endif
481432001f49Smrg
481532001f49Smrg#ifdef __cplusplus
481632001f49Smrg}
481732001f49Smrg#endif\
481832001f49Smrg"
481932001f49Smrg	} # !$opt_dry_run
482032001f49Smrg
482132001f49Smrg	pic_flag_for_symtable=
482232001f49Smrg	case "$compile_command " in
482332001f49Smrg	*" -static "*) ;;
482432001f49Smrg	*)
482532001f49Smrg	  case $host in
482632001f49Smrg	  # compiling the symbol table file with pic_flag works around
482732001f49Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
482832001f49Smrg	  # linked before any other PIC object.  But we must not use
482932001f49Smrg	  # pic_flag when linking with -static.  The problem exists in
483032001f49Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
483132001f49Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
483232001f49Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
483332001f49Smrg	  *-*-hpux*)
483432001f49Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
483532001f49Smrg	  *)
48367ec3b29aSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
483732001f49Smrg	    ;;
483832001f49Smrg	  esac
483932001f49Smrg	  ;;
484032001f49Smrg	esac
484132001f49Smrg	symtab_cflags=
484232001f49Smrg	for arg in $LTCFLAGS; do
484332001f49Smrg	  case $arg in
484432001f49Smrg	  -pie | -fpie | -fPIE) ;;
484532001f49Smrg	  *) func_append symtab_cflags " $arg" ;;
484632001f49Smrg	  esac
484732001f49Smrg	done
484832001f49Smrg
484932001f49Smrg	# Now compile the dynamic symbol file.
485032001f49Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
485132001f49Smrg
485232001f49Smrg	# Clean up the generated files.
48537ec3b29aSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
485432001f49Smrg
485532001f49Smrg	# Transform the symbol file into the correct name.
48567ec3b29aSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
485732001f49Smrg	case $host in
485832001f49Smrg	*cygwin* | *mingw* | *cegcc* )
485932001f49Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
486032001f49Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
486132001f49Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
486232001f49Smrg	  else
486332001f49Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
486432001f49Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
486532001f49Smrg	  fi
486632001f49Smrg	  ;;
486732001f49Smrg	*)
486832001f49Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
486932001f49Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
487032001f49Smrg	  ;;
487132001f49Smrg	esac
487232001f49Smrg	;;
487332001f49Smrg      *)
48747ec3b29aSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
487532001f49Smrg	;;
487632001f49Smrg      esac
487732001f49Smrg    else
487832001f49Smrg      # We keep going just in case the user didn't refer to
487932001f49Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
488032001f49Smrg      # really was required.
488132001f49Smrg
488232001f49Smrg      # Nullify the symbol file.
488332001f49Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
488432001f49Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
488532001f49Smrg    fi
488632001f49Smrg}
488732001f49Smrg
48887ec3b29aSmrg# func_cygming_gnu_implib_p ARG
48897ec3b29aSmrg# This predicate returns with zero status (TRUE) if
48907ec3b29aSmrg# ARG is a GNU/binutils-style import library. Returns
48917ec3b29aSmrg# with nonzero status (FALSE) otherwise.
48927ec3b29aSmrgfunc_cygming_gnu_implib_p ()
48937ec3b29aSmrg{
48947ec3b29aSmrg  $debug_cmd
48957ec3b29aSmrg
48967ec3b29aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
48977ec3b29aSmrg  func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'`
48987ec3b29aSmrg  test -n "$func_cygming_gnu_implib_tmp"
48997ec3b29aSmrg}
49007ec3b29aSmrg
49017ec3b29aSmrg# func_cygming_ms_implib_p ARG
49027ec3b29aSmrg# This predicate returns with zero status (TRUE) if
49037ec3b29aSmrg# ARG is an MS-style import library. Returns
49047ec3b29aSmrg# with nonzero status (FALSE) otherwise.
49057ec3b29aSmrgfunc_cygming_ms_implib_p ()
49067ec3b29aSmrg{
49077ec3b29aSmrg  $debug_cmd
49087ec3b29aSmrg
49097ec3b29aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
49107ec3b29aSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
49117ec3b29aSmrg  test -n "$func_cygming_ms_implib_tmp"
49127ec3b29aSmrg}
49137ec3b29aSmrg
491432001f49Smrg# func_win32_libid arg
491532001f49Smrg# return the library type of file 'arg'
491632001f49Smrg#
491732001f49Smrg# Need a lot of goo to handle *both* DLLs and import libs
491832001f49Smrg# Has to be a shell function in order to 'eat' the argument
491932001f49Smrg# that is supplied when $file_magic_command is called.
492032001f49Smrg# Despite the name, also deal with 64 bit binaries.
492132001f49Smrgfunc_win32_libid ()
492232001f49Smrg{
49237ec3b29aSmrg  $debug_cmd
49247ec3b29aSmrg
49257ec3b29aSmrg  win32_libid_type=unknown
492632001f49Smrg  win32_fileres=`file -L $1 2>/dev/null`
492732001f49Smrg  case $win32_fileres in
492832001f49Smrg  *ar\ archive\ import\ library*) # definitely import
492932001f49Smrg    win32_libid_type="x86 archive import"
493032001f49Smrg    ;;
493132001f49Smrg  *ar\ archive*) # could be an import, or static
493232001f49Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
493332001f49Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
493432001f49Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
49357ec3b29aSmrg      case $nm_interface in
49367ec3b29aSmrg      "MS dumpbin")
49377ec3b29aSmrg	if func_cygming_ms_implib_p "$1" ||
49387ec3b29aSmrg	   func_cygming_gnu_implib_p "$1"
49397ec3b29aSmrg	then
49407ec3b29aSmrg	  win32_nmres=import
49417ec3b29aSmrg	else
49427ec3b29aSmrg	  win32_nmres=
49437ec3b29aSmrg	fi
49447ec3b29aSmrg	;;
49457ec3b29aSmrg      *)
49467ec3b29aSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
49477ec3b29aSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
49487ec3b29aSmrg	  $SED -n -e '
494932001f49Smrg	    1,100{
495032001f49Smrg		/ I /{
49517ec3b29aSmrg		    s|.*|import|
495232001f49Smrg		    p
495332001f49Smrg		    q
495432001f49Smrg		}
495532001f49Smrg	    }'`
49567ec3b29aSmrg	;;
49577ec3b29aSmrg      esac
495832001f49Smrg      case $win32_nmres in
495932001f49Smrg      import*)  win32_libid_type="x86 archive import";;
496032001f49Smrg      *)        win32_libid_type="x86 archive static";;
496132001f49Smrg      esac
496232001f49Smrg    fi
496332001f49Smrg    ;;
496432001f49Smrg  *DLL*)
496532001f49Smrg    win32_libid_type="x86 DLL"
496632001f49Smrg    ;;
496732001f49Smrg  *executable*) # but shell scripts are "executable" too...
496832001f49Smrg    case $win32_fileres in
496932001f49Smrg    *MS\ Windows\ PE\ Intel*)
497032001f49Smrg      win32_libid_type="x86 DLL"
497132001f49Smrg      ;;
497232001f49Smrg    esac
497332001f49Smrg    ;;
497432001f49Smrg  esac
497532001f49Smrg  $ECHO "$win32_libid_type"
497632001f49Smrg}
497732001f49Smrg
497832001f49Smrg# func_cygming_dll_for_implib ARG
497932001f49Smrg#
498032001f49Smrg# Platform-specific function to extract the
498132001f49Smrg# name of the DLL associated with the specified
498232001f49Smrg# import library ARG.
498332001f49Smrg# Invoked by eval'ing the libtool variable
498432001f49Smrg#    $sharedlib_from_linklib_cmd
498532001f49Smrg# Result is available in the variable
498632001f49Smrg#    $sharedlib_from_linklib_result
498732001f49Smrgfunc_cygming_dll_for_implib ()
498832001f49Smrg{
49897ec3b29aSmrg  $debug_cmd
49907ec3b29aSmrg
499132001f49Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
499232001f49Smrg}
499332001f49Smrg
499432001f49Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
499532001f49Smrg#
499632001f49Smrg# The is the core of a fallback implementation of a
499732001f49Smrg# platform-specific function to extract the name of the
499832001f49Smrg# DLL associated with the specified import library LIBNAME.
499932001f49Smrg#
500032001f49Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
500132001f49Smrg# on the platform and compiler that created the implib.
500232001f49Smrg#
500332001f49Smrg# Echos the name of the DLL associated with the
500432001f49Smrg# specified import library.
500532001f49Smrgfunc_cygming_dll_for_implib_fallback_core ()
500632001f49Smrg{
50077ec3b29aSmrg  $debug_cmd
50087ec3b29aSmrg
500932001f49Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
501032001f49Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
501132001f49Smrg    $SED '/^Contents of section '"$match_literal"':/{
501232001f49Smrg      # Place marker at beginning of archive member dllname section
501332001f49Smrg      s/.*/====MARK====/
501432001f49Smrg      p
501532001f49Smrg      d
501632001f49Smrg    }
501732001f49Smrg    # These lines can sometimes be longer than 43 characters, but
501832001f49Smrg    # are always uninteresting
501932001f49Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
502032001f49Smrg    /^In archive [^:]*:/d
502132001f49Smrg    # Ensure marker is printed
502232001f49Smrg    /^====MARK====/p
502332001f49Smrg    # Remove all lines with less than 43 characters
502432001f49Smrg    /^.\{43\}/!d
502532001f49Smrg    # From remaining lines, remove first 43 characters
502632001f49Smrg    s/^.\{43\}//' |
502732001f49Smrg    $SED -n '
502832001f49Smrg      # Join marker and all lines until next marker into a single line
502932001f49Smrg      /^====MARK====/ b para
503032001f49Smrg      H
503132001f49Smrg      $ b para
503232001f49Smrg      b
503332001f49Smrg      :para
503432001f49Smrg      x
503532001f49Smrg      s/\n//g
503632001f49Smrg      # Remove the marker
503732001f49Smrg      s/^====MARK====//
503832001f49Smrg      # Remove trailing dots and whitespace
503932001f49Smrg      s/[\. \t]*$//
504032001f49Smrg      # Print
504132001f49Smrg      /./p' |
504232001f49Smrg    # we now have a list, one entry per line, of the stringified
504332001f49Smrg    # contents of the appropriate section of all members of the
50447ec3b29aSmrg    # archive that possess that section. Heuristic: eliminate
50457ec3b29aSmrg    # all those that have a first or second character that is
504632001f49Smrg    # a '.' (that is, objdump's representation of an unprintable
504732001f49Smrg    # character.) This should work for all archives with less than
504832001f49Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
504932001f49Smrg    # begins with a literal '.' or a single character followed by
505032001f49Smrg    # a '.'.
505132001f49Smrg    #
505232001f49Smrg    # Of those that remain, print the first one.
505332001f49Smrg    $SED -e '/^\./d;/^.\./d;q'
505432001f49Smrg}
505532001f49Smrg
505632001f49Smrg# func_cygming_dll_for_implib_fallback ARG
505732001f49Smrg# Platform-specific function to extract the
505832001f49Smrg# name of the DLL associated with the specified
505932001f49Smrg# import library ARG.
506032001f49Smrg#
506132001f49Smrg# This fallback implementation is for use when $DLLTOOL
506232001f49Smrg# does not support the --identify-strict option.
506332001f49Smrg# Invoked by eval'ing the libtool variable
506432001f49Smrg#    $sharedlib_from_linklib_cmd
506532001f49Smrg# Result is available in the variable
506632001f49Smrg#    $sharedlib_from_linklib_result
506732001f49Smrgfunc_cygming_dll_for_implib_fallback ()
506832001f49Smrg{
50697ec3b29aSmrg  $debug_cmd
50707ec3b29aSmrg
50717ec3b29aSmrg  if func_cygming_gnu_implib_p "$1"; then
507232001f49Smrg    # binutils import library
507332001f49Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
50747ec3b29aSmrg  elif func_cygming_ms_implib_p "$1"; then
507532001f49Smrg    # ms-generated import library
507632001f49Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
507732001f49Smrg  else
507832001f49Smrg    # unknown
50797ec3b29aSmrg    sharedlib_from_linklib_result=
508032001f49Smrg  fi
508132001f49Smrg}
508232001f49Smrg
508332001f49Smrg
508432001f49Smrg# func_extract_an_archive dir oldlib
508532001f49Smrgfunc_extract_an_archive ()
508632001f49Smrg{
50877ec3b29aSmrg    $debug_cmd
50887ec3b29aSmrg
50897ec3b29aSmrg    f_ex_an_ar_dir=$1; shift
50907ec3b29aSmrg    f_ex_an_ar_oldlib=$1
50917ec3b29aSmrg    if test yes = "$lock_old_archive_extraction"; then
509232001f49Smrg      lockfile=$f_ex_an_ar_oldlib.lock
509332001f49Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
509432001f49Smrg	func_echo "Waiting for $lockfile to be removed"
509532001f49Smrg	sleep 2
509632001f49Smrg      done
509732001f49Smrg    fi
509832001f49Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
509932001f49Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
51007ec3b29aSmrg    if test yes = "$lock_old_archive_extraction"; then
510132001f49Smrg      $opt_dry_run || rm -f "$lockfile"
510232001f49Smrg    fi
510332001f49Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
510432001f49Smrg     :
510532001f49Smrg    else
510632001f49Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
510732001f49Smrg    fi
510832001f49Smrg}
510932001f49Smrg
511032001f49Smrg
511132001f49Smrg# func_extract_archives gentop oldlib ...
511232001f49Smrgfunc_extract_archives ()
511332001f49Smrg{
51147ec3b29aSmrg    $debug_cmd
51157ec3b29aSmrg
51167ec3b29aSmrg    my_gentop=$1; shift
511732001f49Smrg    my_oldlibs=${1+"$@"}
51187ec3b29aSmrg    my_oldobjs=
51197ec3b29aSmrg    my_xlib=
51207ec3b29aSmrg    my_xabs=
51217ec3b29aSmrg    my_xdir=
512232001f49Smrg
512332001f49Smrg    for my_xlib in $my_oldlibs; do
512432001f49Smrg      # Extract the objects.
512532001f49Smrg      case $my_xlib in
51267ec3b29aSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
512732001f49Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
512832001f49Smrg      esac
512932001f49Smrg      func_basename "$my_xlib"
51307ec3b29aSmrg      my_xlib=$func_basename_result
513132001f49Smrg      my_xlib_u=$my_xlib
513232001f49Smrg      while :; do
513332001f49Smrg        case " $extracted_archives " in
513432001f49Smrg	*" $my_xlib_u "*)
513532001f49Smrg	  func_arith $extracted_serial + 1
513632001f49Smrg	  extracted_serial=$func_arith_result
513732001f49Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
513832001f49Smrg	*) break ;;
513932001f49Smrg	esac
514032001f49Smrg      done
514132001f49Smrg      extracted_archives="$extracted_archives $my_xlib_u"
51427ec3b29aSmrg      my_xdir=$my_gentop/$my_xlib_u
514332001f49Smrg
514432001f49Smrg      func_mkdir_p "$my_xdir"
514532001f49Smrg
514632001f49Smrg      case $host in
514732001f49Smrg      *-darwin*)
514832001f49Smrg	func_verbose "Extracting $my_xabs"
514932001f49Smrg	# Do not bother doing anything if just a dry run
515032001f49Smrg	$opt_dry_run || {
515132001f49Smrg	  darwin_orig_dir=`pwd`
515232001f49Smrg	  cd $my_xdir || exit $?
515332001f49Smrg	  darwin_archive=$my_xabs
515432001f49Smrg	  darwin_curdir=`pwd`
51557ec3b29aSmrg	  func_basename "$darwin_archive"
51567ec3b29aSmrg	  darwin_base_archive=$func_basename_result
515732001f49Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
515832001f49Smrg	  if test -n "$darwin_arches"; then
515932001f49Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
516032001f49Smrg	    darwin_arch=
516132001f49Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
51627ec3b29aSmrg	    for darwin_arch in  $darwin_arches; do
51637ec3b29aSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
51647ec3b29aSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
51657ec3b29aSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
51667ec3b29aSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
516732001f49Smrg	      cd "$darwin_curdir"
51687ec3b29aSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
516932001f49Smrg	    done # $darwin_arches
517032001f49Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
51717ec3b29aSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
517232001f49Smrg	    darwin_file=
517332001f49Smrg	    darwin_files=
517432001f49Smrg	    for darwin_file in $darwin_filelist; do
517532001f49Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
517632001f49Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
517732001f49Smrg	    done # $darwin_filelist
517832001f49Smrg	    $RM -rf unfat-$$
517932001f49Smrg	    cd "$darwin_orig_dir"
518032001f49Smrg	  else
518132001f49Smrg	    cd $darwin_orig_dir
518232001f49Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
518332001f49Smrg	  fi # $darwin_arches
518432001f49Smrg	} # !$opt_dry_run
518532001f49Smrg	;;
518632001f49Smrg      *)
518732001f49Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
518832001f49Smrg	;;
518932001f49Smrg      esac
519032001f49Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
519132001f49Smrg    done
519232001f49Smrg
51937ec3b29aSmrg    func_extract_archives_result=$my_oldobjs
519432001f49Smrg}
519532001f49Smrg
519632001f49Smrg
519732001f49Smrg# func_emit_wrapper [arg=no]
519832001f49Smrg#
519932001f49Smrg# Emit a libtool wrapper script on stdout.
520032001f49Smrg# Don't directly open a file because we may want to
520132001f49Smrg# incorporate the script contents within a cygwin/mingw
520232001f49Smrg# wrapper executable.  Must ONLY be called from within
520332001f49Smrg# func_mode_link because it depends on a number of variables
520432001f49Smrg# set therein.
520532001f49Smrg#
520632001f49Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
520732001f49Smrg# variable will take.  If 'yes', then the emitted script
52087ec3b29aSmrg# will assume that the directory where it is stored is
520932001f49Smrg# the $objdir directory.  This is a cygwin/mingw-specific
521032001f49Smrg# behavior.
521132001f49Smrgfunc_emit_wrapper ()
521232001f49Smrg{
521332001f49Smrg	func_emit_wrapper_arg1=${1-no}
521432001f49Smrg
521532001f49Smrg	$ECHO "\
521632001f49Smrg#! $SHELL
521732001f49Smrg
521832001f49Smrg# $output - temporary wrapper script for $objdir/$outputname
52197ec3b29aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
522032001f49Smrg#
522132001f49Smrg# The $output program cannot be directly executed until all the libtool
522232001f49Smrg# libraries that it depends on are installed.
522332001f49Smrg#
522432001f49Smrg# This wrapper script should never be moved out of the build directory.
522532001f49Smrg# If it is, it will not operate correctly.
522632001f49Smrg
522732001f49Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
522832001f49Smrg# metacharacters that are still active within double-quoted strings.
522932001f49Smrgsed_quote_subst='$sed_quote_subst'
523032001f49Smrg
523132001f49Smrg# Be Bourne compatible
523232001f49Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
523332001f49Smrg  emulate sh
523432001f49Smrg  NULLCMD=:
523532001f49Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
523632001f49Smrg  # is contrary to our usage.  Disable this feature.
523732001f49Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
523832001f49Smrg  setopt NO_GLOB_SUBST
523932001f49Smrgelse
524032001f49Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
524132001f49Smrgfi
524232001f49SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
524332001f49SmrgDUALCASE=1; export DUALCASE # for MKS sh
524432001f49Smrg
524532001f49Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
524632001f49Smrg# if CDPATH is set.
524732001f49Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
524832001f49Smrg
524932001f49Smrgrelink_command=\"$relink_command\"
525032001f49Smrg
525132001f49Smrg# This environment variable determines our operation mode.
525232001f49Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
525332001f49Smrg  # install mode needs the following variables:
525432001f49Smrg  generated_by_libtool_version='$macro_version'
525532001f49Smrg  notinst_deplibs='$notinst_deplibs'
525632001f49Smrgelse
525732001f49Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
525832001f49Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
525932001f49Smrg    file=\"\$0\""
526032001f49Smrg
526132001f49Smrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
526232001f49Smrg    $ECHO "\
526332001f49Smrg
526432001f49Smrg# A function that is used when there is no print builtin or printf.
526532001f49Smrgfunc_fallback_echo ()
526632001f49Smrg{
526732001f49Smrg  eval 'cat <<_LTECHO_EOF
526832001f49Smrg\$1
526932001f49Smrg_LTECHO_EOF'
527032001f49Smrg}
527132001f49Smrg    ECHO=\"$qECHO\"
527232001f49Smrg  fi
527332001f49Smrg
527432001f49Smrg# Very basic option parsing. These options are (a) specific to
527532001f49Smrg# the libtool wrapper, (b) are identical between the wrapper
52767ec3b29aSmrg# /script/ and the wrapper /executable/ that is used only on
527732001f49Smrg# windows platforms, and (c) all begin with the string "--lt-"
52787ec3b29aSmrg# (application programs are unlikely to have options that match
527932001f49Smrg# this pattern).
528032001f49Smrg#
528132001f49Smrg# There are only two supported options: --lt-debug and
528232001f49Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
528332001f49Smrg#
528432001f49Smrg# The first argument to this parsing function should be the
528532001f49Smrg# script's $0 value, followed by "$@".
528632001f49Smrglt_option_debug=
528732001f49Smrgfunc_parse_lt_options ()
528832001f49Smrg{
528932001f49Smrg  lt_script_arg0=\$0
529032001f49Smrg  shift
529132001f49Smrg  for lt_opt
529232001f49Smrg  do
529332001f49Smrg    case \"\$lt_opt\" in
529432001f49Smrg    --lt-debug) lt_option_debug=1 ;;
529532001f49Smrg    --lt-dump-script)
529632001f49Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
529732001f49Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
529832001f49Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
529932001f49Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
530032001f49Smrg        exit 0
530132001f49Smrg      ;;
530232001f49Smrg    --lt-*)
530332001f49Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
530432001f49Smrg        exit 1
530532001f49Smrg      ;;
530632001f49Smrg    esac
530732001f49Smrg  done
530832001f49Smrg
530932001f49Smrg  # Print the debug banner immediately:
531032001f49Smrg  if test -n \"\$lt_option_debug\"; then
53117ec3b29aSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
531232001f49Smrg  fi
531332001f49Smrg}
531432001f49Smrg
531532001f49Smrg# Used when --lt-debug. Prints its arguments to stdout
531632001f49Smrg# (redirection is the responsibility of the caller)
531732001f49Smrgfunc_lt_dump_args ()
531832001f49Smrg{
531932001f49Smrg  lt_dump_args_N=1;
532032001f49Smrg  for lt_arg
532132001f49Smrg  do
53227ec3b29aSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
532332001f49Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
532432001f49Smrg  done
532532001f49Smrg}
532632001f49Smrg
532732001f49Smrg# Core function for launching the target application
532832001f49Smrgfunc_exec_program_core ()
532932001f49Smrg{
533032001f49Smrg"
533132001f49Smrg  case $host in
533232001f49Smrg  # Backslashes separate directories on plain windows
533332001f49Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
533432001f49Smrg    $ECHO "\
533532001f49Smrg      if test -n \"\$lt_option_debug\"; then
53367ec3b29aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
533732001f49Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
533832001f49Smrg      fi
533932001f49Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
534032001f49Smrg"
534132001f49Smrg    ;;
534232001f49Smrg
534332001f49Smrg  *)
534432001f49Smrg    $ECHO "\
534532001f49Smrg      if test -n \"\$lt_option_debug\"; then
53467ec3b29aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
534732001f49Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
534832001f49Smrg      fi
534932001f49Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
535032001f49Smrg"
535132001f49Smrg    ;;
535232001f49Smrg  esac
535332001f49Smrg  $ECHO "\
535432001f49Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
535532001f49Smrg      exit 1
535632001f49Smrg}
535732001f49Smrg
535832001f49Smrg# A function to encapsulate launching the target application
535932001f49Smrg# Strips options in the --lt-* namespace from \$@ and
536032001f49Smrg# launches target application with the remaining arguments.
536132001f49Smrgfunc_exec_program ()
536232001f49Smrg{
536332001f49Smrg  case \" \$* \" in
536432001f49Smrg  *\\ --lt-*)
536532001f49Smrg    for lt_wr_arg
536632001f49Smrg    do
536732001f49Smrg      case \$lt_wr_arg in
536832001f49Smrg      --lt-*) ;;
536932001f49Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
537032001f49Smrg      esac
537132001f49Smrg      shift
537232001f49Smrg    done ;;
537332001f49Smrg  esac
537432001f49Smrg  func_exec_program_core \${1+\"\$@\"}
537532001f49Smrg}
537632001f49Smrg
537732001f49Smrg  # Parse options
537832001f49Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
537932001f49Smrg
538032001f49Smrg  # Find the directory that this script lives in.
538132001f49Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
538232001f49Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
538332001f49Smrg
538432001f49Smrg  # Follow symbolic links until we get to the real thisdir.
538532001f49Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
538632001f49Smrg  while test -n \"\$file\"; do
538732001f49Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
538832001f49Smrg
538932001f49Smrg    # If there was a directory component, then change thisdir.
539032001f49Smrg    if test \"x\$destdir\" != \"x\$file\"; then
539132001f49Smrg      case \"\$destdir\" in
539232001f49Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
539332001f49Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
539432001f49Smrg      esac
539532001f49Smrg    fi
539632001f49Smrg
539732001f49Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
539832001f49Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
539932001f49Smrg  done
540032001f49Smrg
540132001f49Smrg  # Usually 'no', except on cygwin/mingw when embedded into
540232001f49Smrg  # the cwrapper.
540332001f49Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
540432001f49Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
540532001f49Smrg    # special case for '.'
540632001f49Smrg    if test \"\$thisdir\" = \".\"; then
540732001f49Smrg      thisdir=\`pwd\`
540832001f49Smrg    fi
540932001f49Smrg    # remove .libs from thisdir
541032001f49Smrg    case \"\$thisdir\" in
541132001f49Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
541232001f49Smrg    $objdir )   thisdir=. ;;
541332001f49Smrg    esac
541432001f49Smrg  fi
541532001f49Smrg
541632001f49Smrg  # Try to get the absolute directory name.
541732001f49Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
541832001f49Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
541932001f49Smrg"
542032001f49Smrg
54217ec3b29aSmrg	if test yes = "$fast_install"; then
542232001f49Smrg	  $ECHO "\
542332001f49Smrg  program=lt-'$outputname'$exeext
542432001f49Smrg  progdir=\"\$thisdir/$objdir\"
542532001f49Smrg
542632001f49Smrg  if test ! -f \"\$progdir/\$program\" ||
54277ec3b29aSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
542832001f49Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
542932001f49Smrg
543032001f49Smrg    file=\"\$\$-\$program\"
543132001f49Smrg
543232001f49Smrg    if test ! -d \"\$progdir\"; then
543332001f49Smrg      $MKDIR \"\$progdir\"
543432001f49Smrg    else
543532001f49Smrg      $RM \"\$progdir/\$file\"
543632001f49Smrg    fi"
543732001f49Smrg
543832001f49Smrg	  $ECHO "\
543932001f49Smrg
544032001f49Smrg    # relink executable if necessary
544132001f49Smrg    if test -n \"\$relink_command\"; then
544232001f49Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
544332001f49Smrg      else
54447ec3b29aSmrg	\$ECHO \"\$relink_command_output\" >&2
544532001f49Smrg	$RM \"\$progdir/\$file\"
544632001f49Smrg	exit 1
544732001f49Smrg      fi
544832001f49Smrg    fi
544932001f49Smrg
545032001f49Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
545132001f49Smrg    { $RM \"\$progdir/\$program\";
545232001f49Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
545332001f49Smrg    $RM \"\$progdir/\$file\"
545432001f49Smrg  fi"
545532001f49Smrg	else
545632001f49Smrg	  $ECHO "\
545732001f49Smrg  program='$outputname'
545832001f49Smrg  progdir=\"\$thisdir/$objdir\"
545932001f49Smrg"
546032001f49Smrg	fi
546132001f49Smrg
546232001f49Smrg	$ECHO "\
546332001f49Smrg
546432001f49Smrg  if test -f \"\$progdir/\$program\"; then"
546532001f49Smrg
546632001f49Smrg	# fixup the dll searchpath if we need to.
546732001f49Smrg	#
546832001f49Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
546932001f49Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
547032001f49Smrg	# libraries must come first.
547132001f49Smrg	if test -n "$dllsearchpath"; then
547232001f49Smrg	  $ECHO "\
547332001f49Smrg    # Add the dll search path components to the executable PATH
547432001f49Smrg    PATH=$dllsearchpath:\$PATH
547532001f49Smrg"
547632001f49Smrg	fi
547732001f49Smrg
547832001f49Smrg	# Export our shlibpath_var if we have one.
54797ec3b29aSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
548032001f49Smrg	  $ECHO "\
548132001f49Smrg    # Add our own library path to $shlibpath_var
548232001f49Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
548332001f49Smrg
548432001f49Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
548532001f49Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
548632001f49Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
548732001f49Smrg
548832001f49Smrg    export $shlibpath_var
548932001f49Smrg"
549032001f49Smrg	fi
549132001f49Smrg
549232001f49Smrg	$ECHO "\
549332001f49Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
549432001f49Smrg      # Run the actual program with our arguments.
549532001f49Smrg      func_exec_program \${1+\"\$@\"}
549632001f49Smrg    fi
549732001f49Smrg  else
549832001f49Smrg    # The program doesn't exist.
54997ec3b29aSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
550032001f49Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
550132001f49Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
550232001f49Smrg    exit 1
550332001f49Smrg  fi
550432001f49Smrgfi\
550532001f49Smrg"
550632001f49Smrg}
550732001f49Smrg
550832001f49Smrg
550932001f49Smrg# func_emit_cwrapperexe_src
551032001f49Smrg# emit the source code for a wrapper executable on stdout
551132001f49Smrg# Must ONLY be called from within func_mode_link because
551232001f49Smrg# it depends on a number of variable set therein.
551332001f49Smrgfunc_emit_cwrapperexe_src ()
551432001f49Smrg{
551532001f49Smrg	cat <<EOF
551632001f49Smrg
551732001f49Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
55187ec3b29aSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
551932001f49Smrg
552032001f49Smrg   The $output program cannot be directly executed until all the libtool
552132001f49Smrg   libraries that it depends on are installed.
552232001f49Smrg
552332001f49Smrg   This wrapper executable should never be moved out of the build directory.
552432001f49Smrg   If it is, it will not operate correctly.
552532001f49Smrg*/
552632001f49SmrgEOF
552732001f49Smrg	    cat <<"EOF"
552832001f49Smrg#ifdef _MSC_VER
552932001f49Smrg# define _CRT_SECURE_NO_DEPRECATE 1
553032001f49Smrg#endif
553132001f49Smrg#include <stdio.h>
553232001f49Smrg#include <stdlib.h>
553332001f49Smrg#ifdef _MSC_VER
553432001f49Smrg# include <direct.h>
553532001f49Smrg# include <process.h>
553632001f49Smrg# include <io.h>
553732001f49Smrg#else
553832001f49Smrg# include <unistd.h>
553932001f49Smrg# include <stdint.h>
554032001f49Smrg# ifdef __CYGWIN__
554132001f49Smrg#  include <io.h>
554232001f49Smrg# endif
554332001f49Smrg#endif
554432001f49Smrg#include <malloc.h>
554532001f49Smrg#include <stdarg.h>
554632001f49Smrg#include <assert.h>
554732001f49Smrg#include <string.h>
554832001f49Smrg#include <ctype.h>
554932001f49Smrg#include <errno.h>
555032001f49Smrg#include <fcntl.h>
555132001f49Smrg#include <sys/stat.h>
555232001f49Smrg
55537ec3b29aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
55547ec3b29aSmrg
555532001f49Smrg/* declarations of non-ANSI functions */
55567ec3b29aSmrg#if defined __MINGW32__
555732001f49Smrg# ifdef __STRICT_ANSI__
555832001f49Smrgint _putenv (const char *);
555932001f49Smrg# endif
55607ec3b29aSmrg#elif defined __CYGWIN__
556132001f49Smrg# ifdef __STRICT_ANSI__
556232001f49Smrgchar *realpath (const char *, char *);
556332001f49Smrgint putenv (char *);
556432001f49Smrgint setenv (const char *, const char *, int);
556532001f49Smrg# endif
55667ec3b29aSmrg/* #elif defined other_platform || defined ... */
556732001f49Smrg#endif
556832001f49Smrg
556932001f49Smrg/* portability defines, excluding path handling macros */
55707ec3b29aSmrg#if defined _MSC_VER
557132001f49Smrg# define setmode _setmode
557232001f49Smrg# define stat    _stat
557332001f49Smrg# define chmod   _chmod
557432001f49Smrg# define getcwd  _getcwd
557532001f49Smrg# define putenv  _putenv
557632001f49Smrg# define S_IXUSR _S_IEXEC
55777ec3b29aSmrg#elif defined __MINGW32__
557832001f49Smrg# define setmode _setmode
557932001f49Smrg# define stat    _stat
558032001f49Smrg# define chmod   _chmod
558132001f49Smrg# define getcwd  _getcwd
558232001f49Smrg# define putenv  _putenv
55837ec3b29aSmrg#elif defined __CYGWIN__
558432001f49Smrg# define HAVE_SETENV
558532001f49Smrg# define FOPEN_WB "wb"
55867ec3b29aSmrg/* #elif defined other platforms ... */
558732001f49Smrg#endif
558832001f49Smrg
55897ec3b29aSmrg#if defined PATH_MAX
559032001f49Smrg# define LT_PATHMAX PATH_MAX
55917ec3b29aSmrg#elif defined MAXPATHLEN
559232001f49Smrg# define LT_PATHMAX MAXPATHLEN
559332001f49Smrg#else
559432001f49Smrg# define LT_PATHMAX 1024
559532001f49Smrg#endif
559632001f49Smrg
559732001f49Smrg#ifndef S_IXOTH
559832001f49Smrg# define S_IXOTH 0
559932001f49Smrg#endif
560032001f49Smrg#ifndef S_IXGRP
560132001f49Smrg# define S_IXGRP 0
560232001f49Smrg#endif
560332001f49Smrg
560432001f49Smrg/* path handling portability macros */
560532001f49Smrg#ifndef DIR_SEPARATOR
560632001f49Smrg# define DIR_SEPARATOR '/'
560732001f49Smrg# define PATH_SEPARATOR ':'
560832001f49Smrg#endif
560932001f49Smrg
56107ec3b29aSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
56117ec3b29aSmrg  defined __OS2__
561232001f49Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
561332001f49Smrg# define FOPEN_WB "wb"
561432001f49Smrg# ifndef DIR_SEPARATOR_2
561532001f49Smrg#  define DIR_SEPARATOR_2 '\\'
561632001f49Smrg# endif
561732001f49Smrg# ifndef PATH_SEPARATOR_2
561832001f49Smrg#  define PATH_SEPARATOR_2 ';'
561932001f49Smrg# endif
562032001f49Smrg#endif
562132001f49Smrg
562232001f49Smrg#ifndef DIR_SEPARATOR_2
562332001f49Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
562432001f49Smrg#else /* DIR_SEPARATOR_2 */
562532001f49Smrg# define IS_DIR_SEPARATOR(ch) \
562632001f49Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
562732001f49Smrg#endif /* DIR_SEPARATOR_2 */
562832001f49Smrg
562932001f49Smrg#ifndef PATH_SEPARATOR_2
563032001f49Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
563132001f49Smrg#else /* PATH_SEPARATOR_2 */
563232001f49Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
563332001f49Smrg#endif /* PATH_SEPARATOR_2 */
563432001f49Smrg
563532001f49Smrg#ifndef FOPEN_WB
563632001f49Smrg# define FOPEN_WB "w"
563732001f49Smrg#endif
563832001f49Smrg#ifndef _O_BINARY
563932001f49Smrg# define _O_BINARY 0
564032001f49Smrg#endif
564132001f49Smrg
564232001f49Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
564332001f49Smrg#define XFREE(stale) do { \
56447ec3b29aSmrg  if (stale) { free (stale); stale = 0; } \
564532001f49Smrg} while (0)
564632001f49Smrg
56477ec3b29aSmrg#if defined LT_DEBUGWRAPPER
564832001f49Smrgstatic int lt_debug = 1;
564932001f49Smrg#else
565032001f49Smrgstatic int lt_debug = 0;
565132001f49Smrg#endif
565232001f49Smrg
565332001f49Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
565432001f49Smrg
565532001f49Smrgvoid *xmalloc (size_t num);
565632001f49Smrgchar *xstrdup (const char *string);
565732001f49Smrgconst char *base_name (const char *name);
565832001f49Smrgchar *find_executable (const char *wrapper);
565932001f49Smrgchar *chase_symlinks (const char *pathspec);
566032001f49Smrgint make_executable (const char *path);
566132001f49Smrgint check_executable (const char *path);
566232001f49Smrgchar *strendzap (char *str, const char *pat);
566332001f49Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
566432001f49Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
566532001f49Smrgstatic const char *nonnull (const char *s);
566632001f49Smrgstatic const char *nonempty (const char *s);
566732001f49Smrgvoid lt_setenv (const char *name, const char *value);
566832001f49Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
566932001f49Smrgvoid lt_update_exe_path (const char *name, const char *value);
567032001f49Smrgvoid lt_update_lib_path (const char *name, const char *value);
567132001f49Smrgchar **prepare_spawn (char **argv);
567232001f49Smrgvoid lt_dump_script (FILE *f);
567332001f49SmrgEOF
567432001f49Smrg
567532001f49Smrg	    cat <<EOF
56767ec3b29aSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
56777ec3b29aSmrg# define externally_visible volatile
56787ec3b29aSmrg#else
56797ec3b29aSmrg# define externally_visible __attribute__((externally_visible)) volatile
56807ec3b29aSmrg#endif
56817ec3b29aSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
568232001f49Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
568332001f49SmrgEOF
568432001f49Smrg
56857ec3b29aSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
568632001f49Smrg              func_to_host_path "$temp_rpath"
568732001f49Smrg	      cat <<EOF
568832001f49Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
568932001f49SmrgEOF
569032001f49Smrg	    else
569132001f49Smrg	      cat <<"EOF"
569232001f49Smrgconst char * LIB_PATH_VALUE   = "";
569332001f49SmrgEOF
569432001f49Smrg	    fi
569532001f49Smrg
569632001f49Smrg	    if test -n "$dllsearchpath"; then
569732001f49Smrg              func_to_host_path "$dllsearchpath:"
569832001f49Smrg	      cat <<EOF
569932001f49Smrgconst char * EXE_PATH_VARNAME = "PATH";
570032001f49Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
570132001f49SmrgEOF
570232001f49Smrg	    else
570332001f49Smrg	      cat <<"EOF"
570432001f49Smrgconst char * EXE_PATH_VARNAME = "";
570532001f49Smrgconst char * EXE_PATH_VALUE   = "";
570632001f49SmrgEOF
570732001f49Smrg	    fi
570832001f49Smrg
57097ec3b29aSmrg	    if test yes = "$fast_install"; then
571032001f49Smrg	      cat <<EOF
571132001f49Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
571232001f49SmrgEOF
571332001f49Smrg	    else
571432001f49Smrg	      cat <<EOF
571532001f49Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
571632001f49SmrgEOF
571732001f49Smrg	    fi
571832001f49Smrg
571932001f49Smrg
572032001f49Smrg	    cat <<"EOF"
572132001f49Smrg
572232001f49Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
572332001f49Smrg
572432001f49Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
572532001f49Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
572632001f49Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
572732001f49Smrg
572832001f49Smrgint
572932001f49Smrgmain (int argc, char *argv[])
573032001f49Smrg{
573132001f49Smrg  char **newargz;
573232001f49Smrg  int  newargc;
573332001f49Smrg  char *tmp_pathspec;
573432001f49Smrg  char *actual_cwrapper_path;
573532001f49Smrg  char *actual_cwrapper_name;
573632001f49Smrg  char *target_name;
573732001f49Smrg  char *lt_argv_zero;
57387ec3b29aSmrg  int rval = 127;
573932001f49Smrg
574032001f49Smrg  int i;
574132001f49Smrg
574232001f49Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
57437ec3b29aSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
574432001f49Smrg
574532001f49Smrg  /* very simple arg parsing; don't want to rely on getopt
574632001f49Smrg   * also, copy all non cwrapper options to newargz, except
574732001f49Smrg   * argz[0], which is handled differently
574832001f49Smrg   */
574932001f49Smrg  newargc=0;
575032001f49Smrg  for (i = 1; i < argc; i++)
575132001f49Smrg    {
57527ec3b29aSmrg      if (STREQ (argv[i], dumpscript_opt))
575332001f49Smrg	{
575432001f49SmrgEOF
57557ec3b29aSmrg	    case $host in
575632001f49Smrg	      *mingw* | *cygwin* )
575732001f49Smrg		# make stdout use "unix" line endings
575832001f49Smrg		echo "          setmode(1,_O_BINARY);"
575932001f49Smrg		;;
576032001f49Smrg	      esac
576132001f49Smrg
576232001f49Smrg	    cat <<"EOF"
576332001f49Smrg	  lt_dump_script (stdout);
576432001f49Smrg	  return 0;
576532001f49Smrg	}
57667ec3b29aSmrg      if (STREQ (argv[i], debug_opt))
576732001f49Smrg	{
576832001f49Smrg          lt_debug = 1;
576932001f49Smrg          continue;
577032001f49Smrg	}
57717ec3b29aSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
577232001f49Smrg        {
577332001f49Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
577432001f49Smrg             namespace, but it is not one of the ones we know about and
577532001f49Smrg             have already dealt with, above (inluding dump-script), then
577632001f49Smrg             report an error. Otherwise, targets might begin to believe
577732001f49Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
577832001f49Smrg             namespace. The first time any user complains about this, we'll
577932001f49Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
578032001f49Smrg             or a configure.ac-settable value.
578132001f49Smrg           */
578232001f49Smrg          lt_fatal (__FILE__, __LINE__,
578332001f49Smrg		    "unrecognized %s option: '%s'",
578432001f49Smrg                    ltwrapper_option_prefix, argv[i]);
578532001f49Smrg        }
578632001f49Smrg      /* otherwise ... */
578732001f49Smrg      newargz[++newargc] = xstrdup (argv[i]);
578832001f49Smrg    }
578932001f49Smrg  newargz[++newargc] = NULL;
579032001f49Smrg
579132001f49SmrgEOF
579232001f49Smrg	    cat <<EOF
579332001f49Smrg  /* The GNU banner must be the first non-error debug message */
57947ec3b29aSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
579532001f49SmrgEOF
579632001f49Smrg	    cat <<"EOF"
579732001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
579832001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
579932001f49Smrg
580032001f49Smrg  tmp_pathspec = find_executable (argv[0]);
580132001f49Smrg  if (tmp_pathspec == NULL)
580232001f49Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
580332001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
580432001f49Smrg                  "(main) found exe (before symlink chase) at: %s\n",
580532001f49Smrg		  tmp_pathspec);
580632001f49Smrg
580732001f49Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
580832001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
580932001f49Smrg                  "(main) found exe (after symlink chase) at: %s\n",
581032001f49Smrg		  actual_cwrapper_path);
581132001f49Smrg  XFREE (tmp_pathspec);
581232001f49Smrg
581332001f49Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
581432001f49Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
581532001f49Smrg
581632001f49Smrg  /* wrapper name transforms */
581732001f49Smrg  strendzap (actual_cwrapper_name, ".exe");
581832001f49Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
581932001f49Smrg  XFREE (actual_cwrapper_name);
582032001f49Smrg  actual_cwrapper_name = tmp_pathspec;
582132001f49Smrg  tmp_pathspec = 0;
582232001f49Smrg
582332001f49Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
582432001f49Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
582532001f49Smrg  strendzap (target_name, ".exe");
582632001f49Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
582732001f49Smrg  XFREE (target_name);
582832001f49Smrg  target_name = tmp_pathspec;
582932001f49Smrg  tmp_pathspec = 0;
583032001f49Smrg
583132001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
583232001f49Smrg		  "(main) libtool target name: %s\n",
583332001f49Smrg		  target_name);
583432001f49SmrgEOF
583532001f49Smrg
583632001f49Smrg	    cat <<EOF
583732001f49Smrg  newargz[0] =
583832001f49Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
583932001f49Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
584032001f49Smrg  strcpy (newargz[0], actual_cwrapper_path);
584132001f49Smrg  strcat (newargz[0], "$objdir");
584232001f49Smrg  strcat (newargz[0], "/");
584332001f49SmrgEOF
584432001f49Smrg
584532001f49Smrg	    cat <<"EOF"
584632001f49Smrg  /* stop here, and copy so we don't have to do this twice */
584732001f49Smrg  tmp_pathspec = xstrdup (newargz[0]);
584832001f49Smrg
584932001f49Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
585032001f49Smrg  strcat (newargz[0], actual_cwrapper_name);
585132001f49Smrg
585232001f49Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
585332001f49Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
585432001f49Smrg  XFREE (tmp_pathspec);
585532001f49Smrg  tmp_pathspec = NULL;
585632001f49SmrgEOF
585732001f49Smrg
585832001f49Smrg	    case $host_os in
585932001f49Smrg	      mingw*)
586032001f49Smrg	    cat <<"EOF"
586132001f49Smrg  {
586232001f49Smrg    char* p;
586332001f49Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
586432001f49Smrg      {
586532001f49Smrg	*p = '/';
586632001f49Smrg      }
586732001f49Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
586832001f49Smrg      {
586932001f49Smrg	*p = '/';
587032001f49Smrg      }
587132001f49Smrg  }
587232001f49SmrgEOF
587332001f49Smrg	    ;;
587432001f49Smrg	    esac
587532001f49Smrg
587632001f49Smrg	    cat <<"EOF"
587732001f49Smrg  XFREE (target_name);
587832001f49Smrg  XFREE (actual_cwrapper_path);
587932001f49Smrg  XFREE (actual_cwrapper_name);
588032001f49Smrg
588132001f49Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
588232001f49Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
588332001f49Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
588432001f49Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
588532001f49Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
588632001f49Smrg     libraries must come first. */
588732001f49Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
588832001f49Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
588932001f49Smrg
589032001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
589132001f49Smrg		  nonnull (lt_argv_zero));
589232001f49Smrg  for (i = 0; i < newargc; i++)
589332001f49Smrg    {
589432001f49Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
589532001f49Smrg		      i, nonnull (newargz[i]));
589632001f49Smrg    }
589732001f49Smrg
589832001f49SmrgEOF
589932001f49Smrg
590032001f49Smrg	    case $host_os in
590132001f49Smrg	      mingw*)
590232001f49Smrg		cat <<"EOF"
590332001f49Smrg  /* execv doesn't actually work on mingw as expected on unix */
590432001f49Smrg  newargz = prepare_spawn (newargz);
59057ec3b29aSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
590632001f49Smrg  if (rval == -1)
590732001f49Smrg    {
590832001f49Smrg      /* failed to start process */
590932001f49Smrg      lt_debugprintf (__FILE__, __LINE__,
591032001f49Smrg		      "(main) failed to launch target \"%s\": %s\n",
591132001f49Smrg		      lt_argv_zero, nonnull (strerror (errno)));
591232001f49Smrg      return 127;
591332001f49Smrg    }
591432001f49Smrg  return rval;
591532001f49SmrgEOF
591632001f49Smrg		;;
591732001f49Smrg	      *)
591832001f49Smrg		cat <<"EOF"
591932001f49Smrg  execv (lt_argv_zero, newargz);
592032001f49Smrg  return rval; /* =127, but avoids unused variable warning */
592132001f49SmrgEOF
592232001f49Smrg		;;
592332001f49Smrg	    esac
592432001f49Smrg
592532001f49Smrg	    cat <<"EOF"
592632001f49Smrg}
592732001f49Smrg
592832001f49Smrgvoid *
592932001f49Smrgxmalloc (size_t num)
593032001f49Smrg{
593132001f49Smrg  void *p = (void *) malloc (num);
593232001f49Smrg  if (!p)
593332001f49Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
593432001f49Smrg
593532001f49Smrg  return p;
593632001f49Smrg}
593732001f49Smrg
593832001f49Smrgchar *
593932001f49Smrgxstrdup (const char *string)
594032001f49Smrg{
594132001f49Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
594232001f49Smrg			  string) : NULL;
594332001f49Smrg}
594432001f49Smrg
594532001f49Smrgconst char *
594632001f49Smrgbase_name (const char *name)
594732001f49Smrg{
594832001f49Smrg  const char *base;
594932001f49Smrg
59507ec3b29aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
595132001f49Smrg  /* Skip over the disk name in MSDOS pathnames. */
595232001f49Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
595332001f49Smrg    name += 2;
595432001f49Smrg#endif
595532001f49Smrg
595632001f49Smrg  for (base = name; *name; name++)
595732001f49Smrg    if (IS_DIR_SEPARATOR (*name))
595832001f49Smrg      base = name + 1;
595932001f49Smrg  return base;
596032001f49Smrg}
596132001f49Smrg
596232001f49Smrgint
596332001f49Smrgcheck_executable (const char *path)
596432001f49Smrg{
596532001f49Smrg  struct stat st;
596632001f49Smrg
596732001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
596832001f49Smrg                  nonempty (path));
596932001f49Smrg  if ((!path) || (!*path))
597032001f49Smrg    return 0;
597132001f49Smrg
597232001f49Smrg  if ((stat (path, &st) >= 0)
597332001f49Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
597432001f49Smrg    return 1;
597532001f49Smrg  else
597632001f49Smrg    return 0;
597732001f49Smrg}
597832001f49Smrg
597932001f49Smrgint
598032001f49Smrgmake_executable (const char *path)
598132001f49Smrg{
598232001f49Smrg  int rval = 0;
598332001f49Smrg  struct stat st;
598432001f49Smrg
598532001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
598632001f49Smrg                  nonempty (path));
598732001f49Smrg  if ((!path) || (!*path))
598832001f49Smrg    return 0;
598932001f49Smrg
599032001f49Smrg  if (stat (path, &st) >= 0)
599132001f49Smrg    {
599232001f49Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
599332001f49Smrg    }
599432001f49Smrg  return rval;
599532001f49Smrg}
599632001f49Smrg
599732001f49Smrg/* Searches for the full path of the wrapper.  Returns
599832001f49Smrg   newly allocated full path name if found, NULL otherwise
599932001f49Smrg   Does not chase symlinks, even on platforms that support them.
600032001f49Smrg*/
600132001f49Smrgchar *
600232001f49Smrgfind_executable (const char *wrapper)
600332001f49Smrg{
600432001f49Smrg  int has_slash = 0;
600532001f49Smrg  const char *p;
600632001f49Smrg  const char *p_next;
600732001f49Smrg  /* static buffer for getcwd */
600832001f49Smrg  char tmp[LT_PATHMAX + 1];
60097ec3b29aSmrg  size_t tmp_len;
601032001f49Smrg  char *concat_name;
601132001f49Smrg
601232001f49Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
601332001f49Smrg                  nonempty (wrapper));
601432001f49Smrg
601532001f49Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
601632001f49Smrg    return NULL;
601732001f49Smrg
601832001f49Smrg  /* Absolute path? */
60197ec3b29aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
602032001f49Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
602132001f49Smrg    {
602232001f49Smrg      concat_name = xstrdup (wrapper);
602332001f49Smrg      if (check_executable (concat_name))
602432001f49Smrg	return concat_name;
602532001f49Smrg      XFREE (concat_name);
602632001f49Smrg    }
602732001f49Smrg  else
602832001f49Smrg    {
602932001f49Smrg#endif
603032001f49Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
603132001f49Smrg	{
603232001f49Smrg	  concat_name = xstrdup (wrapper);
603332001f49Smrg	  if (check_executable (concat_name))
603432001f49Smrg	    return concat_name;
603532001f49Smrg	  XFREE (concat_name);
603632001f49Smrg	}
60377ec3b29aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
603832001f49Smrg    }
603932001f49Smrg#endif
604032001f49Smrg
604132001f49Smrg  for (p = wrapper; *p; p++)
604232001f49Smrg    if (*p == '/')
604332001f49Smrg      {
604432001f49Smrg	has_slash = 1;
604532001f49Smrg	break;
604632001f49Smrg      }
604732001f49Smrg  if (!has_slash)
604832001f49Smrg    {
604932001f49Smrg      /* no slashes; search PATH */
605032001f49Smrg      const char *path = getenv ("PATH");
605132001f49Smrg      if (path != NULL)
605232001f49Smrg	{
605332001f49Smrg	  for (p = path; *p; p = p_next)
605432001f49Smrg	    {
605532001f49Smrg	      const char *q;
605632001f49Smrg	      size_t p_len;
605732001f49Smrg	      for (q = p; *q; q++)
605832001f49Smrg		if (IS_PATH_SEPARATOR (*q))
605932001f49Smrg		  break;
60607ec3b29aSmrg	      p_len = (size_t) (q - p);
606132001f49Smrg	      p_next = (*q == '\0' ? q : q + 1);
606232001f49Smrg	      if (p_len == 0)
606332001f49Smrg		{
606432001f49Smrg		  /* empty path: current directory */
606532001f49Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
606632001f49Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
606732001f49Smrg                              nonnull (strerror (errno)));
606832001f49Smrg		  tmp_len = strlen (tmp);
606932001f49Smrg		  concat_name =
607032001f49Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
607132001f49Smrg		  memcpy (concat_name, tmp, tmp_len);
607232001f49Smrg		  concat_name[tmp_len] = '/';
607332001f49Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
607432001f49Smrg		}
607532001f49Smrg	      else
607632001f49Smrg		{
607732001f49Smrg		  concat_name =
607832001f49Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
607932001f49Smrg		  memcpy (concat_name, p, p_len);
608032001f49Smrg		  concat_name[p_len] = '/';
608132001f49Smrg		  strcpy (concat_name + p_len + 1, wrapper);
608232001f49Smrg		}
608332001f49Smrg	      if (check_executable (concat_name))
608432001f49Smrg		return concat_name;
608532001f49Smrg	      XFREE (concat_name);
608632001f49Smrg	    }
608732001f49Smrg	}
608832001f49Smrg      /* not found in PATH; assume curdir */
608932001f49Smrg    }
609032001f49Smrg  /* Relative path | not found in path: prepend cwd */
609132001f49Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
609232001f49Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
609332001f49Smrg              nonnull (strerror (errno)));
609432001f49Smrg  tmp_len = strlen (tmp);
609532001f49Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
609632001f49Smrg  memcpy (concat_name, tmp, tmp_len);
609732001f49Smrg  concat_name[tmp_len] = '/';
609832001f49Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
609932001f49Smrg
610032001f49Smrg  if (check_executable (concat_name))
610132001f49Smrg    return concat_name;
610232001f49Smrg  XFREE (concat_name);
610332001f49Smrg  return NULL;
610432001f49Smrg}
610532001f49Smrg
610632001f49Smrgchar *
610732001f49Smrgchase_symlinks (const char *pathspec)
610832001f49Smrg{
610932001f49Smrg#ifndef S_ISLNK
611032001f49Smrg  return xstrdup (pathspec);
611132001f49Smrg#else
611232001f49Smrg  char buf[LT_PATHMAX];
611332001f49Smrg  struct stat s;
611432001f49Smrg  char *tmp_pathspec = xstrdup (pathspec);
611532001f49Smrg  char *p;
611632001f49Smrg  int has_symlinks = 0;
611732001f49Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
611832001f49Smrg    {
611932001f49Smrg      lt_debugprintf (__FILE__, __LINE__,
612032001f49Smrg		      "checking path component for symlinks: %s\n",
612132001f49Smrg		      tmp_pathspec);
612232001f49Smrg      if (lstat (tmp_pathspec, &s) == 0)
612332001f49Smrg	{
612432001f49Smrg	  if (S_ISLNK (s.st_mode) != 0)
612532001f49Smrg	    {
612632001f49Smrg	      has_symlinks = 1;
612732001f49Smrg	      break;
612832001f49Smrg	    }
612932001f49Smrg
613032001f49Smrg	  /* search backwards for last DIR_SEPARATOR */
613132001f49Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
613232001f49Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
613332001f49Smrg	    p--;
613432001f49Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
613532001f49Smrg	    {
613632001f49Smrg	      /* no more DIR_SEPARATORS left */
613732001f49Smrg	      break;
613832001f49Smrg	    }
613932001f49Smrg	  *p = '\0';
614032001f49Smrg	}
614132001f49Smrg      else
614232001f49Smrg	{
614332001f49Smrg	  lt_fatal (__FILE__, __LINE__,
614432001f49Smrg		    "error accessing file \"%s\": %s",
614532001f49Smrg		    tmp_pathspec, nonnull (strerror (errno)));
614632001f49Smrg	}
614732001f49Smrg    }
614832001f49Smrg  XFREE (tmp_pathspec);
614932001f49Smrg
615032001f49Smrg  if (!has_symlinks)
615132001f49Smrg    {
615232001f49Smrg      return xstrdup (pathspec);
615332001f49Smrg    }
615432001f49Smrg
615532001f49Smrg  tmp_pathspec = realpath (pathspec, buf);
615632001f49Smrg  if (tmp_pathspec == 0)
615732001f49Smrg    {
615832001f49Smrg      lt_fatal (__FILE__, __LINE__,
615932001f49Smrg		"could not follow symlinks for %s", pathspec);
616032001f49Smrg    }
616132001f49Smrg  return xstrdup (tmp_pathspec);
616232001f49Smrg#endif
616332001f49Smrg}
616432001f49Smrg
616532001f49Smrgchar *
616632001f49Smrgstrendzap (char *str, const char *pat)
616732001f49Smrg{
616832001f49Smrg  size_t len, patlen;
616932001f49Smrg
617032001f49Smrg  assert (str != NULL);
617132001f49Smrg  assert (pat != NULL);
617232001f49Smrg
617332001f49Smrg  len = strlen (str);
617432001f49Smrg  patlen = strlen (pat);
617532001f49Smrg
617632001f49Smrg  if (patlen <= len)
617732001f49Smrg    {
617832001f49Smrg      str += len - patlen;
61797ec3b29aSmrg      if (STREQ (str, pat))
618032001f49Smrg	*str = '\0';
618132001f49Smrg    }
618232001f49Smrg  return str;
618332001f49Smrg}
618432001f49Smrg
618532001f49Smrgvoid
618632001f49Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
618732001f49Smrg{
618832001f49Smrg  va_list args;
618932001f49Smrg  if (lt_debug)
619032001f49Smrg    {
619132001f49Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
619232001f49Smrg      va_start (args, fmt);
619332001f49Smrg      (void) vfprintf (stderr, fmt, args);
619432001f49Smrg      va_end (args);
619532001f49Smrg    }
619632001f49Smrg}
619732001f49Smrg
619832001f49Smrgstatic void
619932001f49Smrglt_error_core (int exit_status, const char *file,
620032001f49Smrg	       int line, const char *mode,
620132001f49Smrg	       const char *message, va_list ap)
620232001f49Smrg{
620332001f49Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
620432001f49Smrg  vfprintf (stderr, message, ap);
620532001f49Smrg  fprintf (stderr, ".\n");
620632001f49Smrg
620732001f49Smrg  if (exit_status >= 0)
620832001f49Smrg    exit (exit_status);
620932001f49Smrg}
621032001f49Smrg
621132001f49Smrgvoid
621232001f49Smrglt_fatal (const char *file, int line, const char *message, ...)
621332001f49Smrg{
621432001f49Smrg  va_list ap;
621532001f49Smrg  va_start (ap, message);
621632001f49Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
621732001f49Smrg  va_end (ap);
621832001f49Smrg}
621932001f49Smrg
622032001f49Smrgstatic const char *
622132001f49Smrgnonnull (const char *s)
622232001f49Smrg{
622332001f49Smrg  return s ? s : "(null)";
622432001f49Smrg}
622532001f49Smrg
622632001f49Smrgstatic const char *
622732001f49Smrgnonempty (const char *s)
622832001f49Smrg{
622932001f49Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
623032001f49Smrg}
623132001f49Smrg
623232001f49Smrgvoid
623332001f49Smrglt_setenv (const char *name, const char *value)
623432001f49Smrg{
623532001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
623632001f49Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
623732001f49Smrg                  nonnull (name), nonnull (value));
623832001f49Smrg  {
623932001f49Smrg#ifdef HAVE_SETENV
624032001f49Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
624132001f49Smrg    char *str = xstrdup (value);
624232001f49Smrg    setenv (name, str, 1);
624332001f49Smrg#else
62447ec3b29aSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
624532001f49Smrg    char *str = XMALLOC (char, len);
624632001f49Smrg    sprintf (str, "%s=%s", name, value);
624732001f49Smrg    if (putenv (str) != EXIT_SUCCESS)
624832001f49Smrg      {
624932001f49Smrg        XFREE (str);
625032001f49Smrg      }
625132001f49Smrg#endif
625232001f49Smrg  }
625332001f49Smrg}
625432001f49Smrg
625532001f49Smrgchar *
625632001f49Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
625732001f49Smrg{
625832001f49Smrg  char *new_value;
625932001f49Smrg  if (orig_value && *orig_value)
626032001f49Smrg    {
62617ec3b29aSmrg      size_t orig_value_len = strlen (orig_value);
62627ec3b29aSmrg      size_t add_len = strlen (add);
626332001f49Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
626432001f49Smrg      if (to_end)
626532001f49Smrg        {
626632001f49Smrg          strcpy (new_value, orig_value);
626732001f49Smrg          strcpy (new_value + orig_value_len, add);
626832001f49Smrg        }
626932001f49Smrg      else
627032001f49Smrg        {
627132001f49Smrg          strcpy (new_value, add);
627232001f49Smrg          strcpy (new_value + add_len, orig_value);
627332001f49Smrg        }
627432001f49Smrg    }
627532001f49Smrg  else
627632001f49Smrg    {
627732001f49Smrg      new_value = xstrdup (add);
627832001f49Smrg    }
627932001f49Smrg  return new_value;
628032001f49Smrg}
628132001f49Smrg
628232001f49Smrgvoid
628332001f49Smrglt_update_exe_path (const char *name, const char *value)
628432001f49Smrg{
628532001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
628632001f49Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
628732001f49Smrg                  nonnull (name), nonnull (value));
628832001f49Smrg
628932001f49Smrg  if (name && *name && value && *value)
629032001f49Smrg    {
629132001f49Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
629232001f49Smrg      /* some systems can't cope with a ':'-terminated path #' */
62937ec3b29aSmrg      size_t len = strlen (new_value);
62947ec3b29aSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
629532001f49Smrg        {
62967ec3b29aSmrg          new_value[--len] = '\0';
629732001f49Smrg        }
629832001f49Smrg      lt_setenv (name, new_value);
629932001f49Smrg      XFREE (new_value);
630032001f49Smrg    }
630132001f49Smrg}
630232001f49Smrg
630332001f49Smrgvoid
630432001f49Smrglt_update_lib_path (const char *name, const char *value)
630532001f49Smrg{
630632001f49Smrg  lt_debugprintf (__FILE__, __LINE__,
630732001f49Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
630832001f49Smrg                  nonnull (name), nonnull (value));
630932001f49Smrg
631032001f49Smrg  if (name && *name && value && *value)
631132001f49Smrg    {
631232001f49Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
631332001f49Smrg      lt_setenv (name, new_value);
631432001f49Smrg      XFREE (new_value);
631532001f49Smrg    }
631632001f49Smrg}
631732001f49Smrg
631832001f49SmrgEOF
631932001f49Smrg	    case $host_os in
632032001f49Smrg	      mingw*)
632132001f49Smrg		cat <<"EOF"
632232001f49Smrg
632332001f49Smrg/* Prepares an argument vector before calling spawn().
632432001f49Smrg   Note that spawn() does not by itself call the command interpreter
632532001f49Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
632632001f49Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
632732001f49Smrg         GetVersionEx(&v);
632832001f49Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
632932001f49Smrg      }) ? "cmd.exe" : "command.com").
633032001f49Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
633132001f49Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
633232001f49Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
633332001f49Smrg   special way:
633432001f49Smrg   - Space and tab are interpreted as delimiters. They are not treated as
633532001f49Smrg     delimiters if they are surrounded by double quotes: "...".
633632001f49Smrg   - Unescaped double quotes are removed from the input. Their only effect is
633732001f49Smrg     that within double quotes, space and tab are treated like normal
633832001f49Smrg     characters.
633932001f49Smrg   - Backslashes not followed by double quotes are not special.
634032001f49Smrg   - But 2*n+1 backslashes followed by a double quote become
634132001f49Smrg     n backslashes followed by a double quote (n >= 0):
634232001f49Smrg       \" -> "
634332001f49Smrg       \\\" -> \"
634432001f49Smrg       \\\\\" -> \\"
634532001f49Smrg */
634632001f49Smrg#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
634732001f49Smrg#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
634832001f49Smrgchar **
634932001f49Smrgprepare_spawn (char **argv)
635032001f49Smrg{
635132001f49Smrg  size_t argc;
635232001f49Smrg  char **new_argv;
635332001f49Smrg  size_t i;
635432001f49Smrg
635532001f49Smrg  /* Count number of arguments.  */
635632001f49Smrg  for (argc = 0; argv[argc] != NULL; argc++)
635732001f49Smrg    ;
635832001f49Smrg
635932001f49Smrg  /* Allocate new argument vector.  */
636032001f49Smrg  new_argv = XMALLOC (char *, argc + 1);
636132001f49Smrg
636232001f49Smrg  /* Put quoted arguments into the new argument vector.  */
636332001f49Smrg  for (i = 0; i < argc; i++)
636432001f49Smrg    {
636532001f49Smrg      const char *string = argv[i];
636632001f49Smrg
636732001f49Smrg      if (string[0] == '\0')
636832001f49Smrg	new_argv[i] = xstrdup ("\"\"");
636932001f49Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
637032001f49Smrg	{
637132001f49Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
637232001f49Smrg	  size_t length;
637332001f49Smrg	  unsigned int backslashes;
637432001f49Smrg	  const char *s;
637532001f49Smrg	  char *quoted_string;
637632001f49Smrg	  char *p;
637732001f49Smrg
637832001f49Smrg	  length = 0;
637932001f49Smrg	  backslashes = 0;
638032001f49Smrg	  if (quote_around)
638132001f49Smrg	    length++;
638232001f49Smrg	  for (s = string; *s != '\0'; s++)
638332001f49Smrg	    {
638432001f49Smrg	      char c = *s;
638532001f49Smrg	      if (c == '"')
638632001f49Smrg		length += backslashes + 1;
638732001f49Smrg	      length++;
638832001f49Smrg	      if (c == '\\')
638932001f49Smrg		backslashes++;
639032001f49Smrg	      else
639132001f49Smrg		backslashes = 0;
639232001f49Smrg	    }
639332001f49Smrg	  if (quote_around)
639432001f49Smrg	    length += backslashes + 1;
639532001f49Smrg
639632001f49Smrg	  quoted_string = XMALLOC (char, length + 1);
639732001f49Smrg
639832001f49Smrg	  p = quoted_string;
639932001f49Smrg	  backslashes = 0;
640032001f49Smrg	  if (quote_around)
640132001f49Smrg	    *p++ = '"';
640232001f49Smrg	  for (s = string; *s != '\0'; s++)
640332001f49Smrg	    {
640432001f49Smrg	      char c = *s;
640532001f49Smrg	      if (c == '"')
640632001f49Smrg		{
640732001f49Smrg		  unsigned int j;
640832001f49Smrg		  for (j = backslashes + 1; j > 0; j--)
640932001f49Smrg		    *p++ = '\\';
641032001f49Smrg		}
641132001f49Smrg	      *p++ = c;
641232001f49Smrg	      if (c == '\\')
641332001f49Smrg		backslashes++;
641432001f49Smrg	      else
641532001f49Smrg		backslashes = 0;
641632001f49Smrg	    }
641732001f49Smrg	  if (quote_around)
641832001f49Smrg	    {
641932001f49Smrg	      unsigned int j;
642032001f49Smrg	      for (j = backslashes; j > 0; j--)
642132001f49Smrg		*p++ = '\\';
642232001f49Smrg	      *p++ = '"';
642332001f49Smrg	    }
642432001f49Smrg	  *p = '\0';
642532001f49Smrg
642632001f49Smrg	  new_argv[i] = quoted_string;
642732001f49Smrg	}
642832001f49Smrg      else
642932001f49Smrg	new_argv[i] = (char *) string;
643032001f49Smrg    }
643132001f49Smrg  new_argv[argc] = NULL;
643232001f49Smrg
643332001f49Smrg  return new_argv;
643432001f49Smrg}
643532001f49SmrgEOF
643632001f49Smrg		;;
643732001f49Smrg	    esac
643832001f49Smrg
643932001f49Smrg            cat <<"EOF"
644032001f49Smrgvoid lt_dump_script (FILE* f)
644132001f49Smrg{
644232001f49SmrgEOF
644332001f49Smrg	    func_emit_wrapper yes |
644432001f49Smrg	      $SED -n -e '
644532001f49Smrgs/^\(.\{79\}\)\(..*\)/\1\
644632001f49Smrg\2/
644732001f49Smrgh
644832001f49Smrgs/\([\\"]\)/\\\1/g
644932001f49Smrgs/$/\\n/
645032001f49Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
645132001f49Smrgg
645232001f49SmrgD'
645332001f49Smrg            cat <<"EOF"
645432001f49Smrg}
645532001f49SmrgEOF
645632001f49Smrg}
645732001f49Smrg# end: func_emit_cwrapperexe_src
645832001f49Smrg
645932001f49Smrg# func_win32_import_lib_p ARG
646032001f49Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
646132001f49Smrgfunc_win32_import_lib_p ()
646232001f49Smrg{
64637ec3b29aSmrg    $debug_cmd
64647ec3b29aSmrg
646532001f49Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
646632001f49Smrg    *import*) : ;;
646732001f49Smrg    *) false ;;
646832001f49Smrg    esac
646932001f49Smrg}
647032001f49Smrg
64717ec3b29aSmrg# func_suncc_cstd_abi
64727ec3b29aSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
64737ec3b29aSmrg# Several compiler flags select an ABI that is incompatible with the
64747ec3b29aSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
64757ec3b29aSmrgfunc_suncc_cstd_abi ()
64767ec3b29aSmrg{
64777ec3b29aSmrg    $debug_cmd
64787ec3b29aSmrg
64797ec3b29aSmrg    case " $compile_command " in
64807ec3b29aSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
64817ec3b29aSmrg      suncc_use_cstd_abi=no
64827ec3b29aSmrg      ;;
64837ec3b29aSmrg    *)
64847ec3b29aSmrg      suncc_use_cstd_abi=yes
64857ec3b29aSmrg      ;;
64867ec3b29aSmrg    esac
64877ec3b29aSmrg}
64887ec3b29aSmrg
648932001f49Smrg# func_mode_link arg...
649032001f49Smrgfunc_mode_link ()
649132001f49Smrg{
64927ec3b29aSmrg    $debug_cmd
64937ec3b29aSmrg
649432001f49Smrg    case $host in
649532001f49Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
649632001f49Smrg      # It is impossible to link a dll without this setting, and
649732001f49Smrg      # we shouldn't force the makefile maintainer to figure out
64987ec3b29aSmrg      # what system we are compiling for in order to pass an extra
649932001f49Smrg      # flag for every libtool invocation.
650032001f49Smrg      # allow_undefined=no
650132001f49Smrg
650232001f49Smrg      # FIXME: Unfortunately, there are problems with the above when trying
65037ec3b29aSmrg      # to make a dll that has undefined symbols, in which case not
650432001f49Smrg      # even a static library is built.  For now, we need to specify
650532001f49Smrg      # -no-undefined on the libtool link line when we can be certain
650632001f49Smrg      # that all symbols are satisfied, otherwise we get a static library.
650732001f49Smrg      allow_undefined=yes
650832001f49Smrg      ;;
650932001f49Smrg    *)
651032001f49Smrg      allow_undefined=yes
651132001f49Smrg      ;;
651232001f49Smrg    esac
651332001f49Smrg    libtool_args=$nonopt
651432001f49Smrg    base_compile="$nonopt $@"
651532001f49Smrg    compile_command=$nonopt
651632001f49Smrg    finalize_command=$nonopt
651732001f49Smrg
651832001f49Smrg    compile_rpath=
651932001f49Smrg    finalize_rpath=
652032001f49Smrg    compile_shlibpath=
652132001f49Smrg    finalize_shlibpath=
652232001f49Smrg    convenience=
652332001f49Smrg    old_convenience=
652432001f49Smrg    deplibs=
652532001f49Smrg    old_deplibs=
652632001f49Smrg    compiler_flags=
652732001f49Smrg    linker_flags=
652832001f49Smrg    dllsearchpath=
652932001f49Smrg    lib_search_path=`pwd`
653032001f49Smrg    inst_prefix_dir=
653132001f49Smrg    new_inherited_linker_flags=
653232001f49Smrg
653332001f49Smrg    avoid_version=no
653432001f49Smrg    bindir=
653532001f49Smrg    dlfiles=
653632001f49Smrg    dlprefiles=
653732001f49Smrg    dlself=no
653832001f49Smrg    export_dynamic=no
653932001f49Smrg    export_symbols=
654032001f49Smrg    export_symbols_regex=
654132001f49Smrg    generated=
654232001f49Smrg    libobjs=
654332001f49Smrg    ltlibs=
654432001f49Smrg    module=no
654532001f49Smrg    no_install=no
654632001f49Smrg    objs=
65477ec3b29aSmrg    os2dllname=
654832001f49Smrg    non_pic_objects=
654932001f49Smrg    precious_files_regex=
655032001f49Smrg    prefer_static_libs=no
65517ec3b29aSmrg    preload=false
655232001f49Smrg    prev=
655332001f49Smrg    prevarg=
655432001f49Smrg    release=
655532001f49Smrg    rpath=
655632001f49Smrg    xrpath=
655732001f49Smrg    perm_rpath=
655832001f49Smrg    temp_rpath=
655932001f49Smrg    thread_safe=no
656032001f49Smrg    vinfo=
656132001f49Smrg    vinfo_number=no
656232001f49Smrg    weak_libs=
65637ec3b29aSmrg    single_module=$wl-single_module
656432001f49Smrg    func_infer_tag $base_compile
656532001f49Smrg
656632001f49Smrg    # We need to know -static, to get the right output filenames.
656732001f49Smrg    for arg
656832001f49Smrg    do
656932001f49Smrg      case $arg in
657032001f49Smrg      -shared)
65717ec3b29aSmrg	test yes != "$build_libtool_libs" \
65727ec3b29aSmrg	  && func_fatal_configuration "cannot build a shared library"
657332001f49Smrg	build_old_libs=no
657432001f49Smrg	break
657532001f49Smrg	;;
657632001f49Smrg      -all-static | -static | -static-libtool-libs)
657732001f49Smrg	case $arg in
657832001f49Smrg	-all-static)
65797ec3b29aSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
658032001f49Smrg	    func_warning "complete static linking is impossible in this configuration"
658132001f49Smrg	  fi
658232001f49Smrg	  if test -n "$link_static_flag"; then
658332001f49Smrg	    dlopen_self=$dlopen_self_static
658432001f49Smrg	  fi
658532001f49Smrg	  prefer_static_libs=yes
658632001f49Smrg	  ;;
658732001f49Smrg	-static)
658832001f49Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
658932001f49Smrg	    dlopen_self=$dlopen_self_static
659032001f49Smrg	  fi
659132001f49Smrg	  prefer_static_libs=built
659232001f49Smrg	  ;;
659332001f49Smrg	-static-libtool-libs)
659432001f49Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
659532001f49Smrg	    dlopen_self=$dlopen_self_static
659632001f49Smrg	  fi
659732001f49Smrg	  prefer_static_libs=yes
659832001f49Smrg	  ;;
659932001f49Smrg	esac
660032001f49Smrg	build_libtool_libs=no
660132001f49Smrg	build_old_libs=yes
660232001f49Smrg	break
660332001f49Smrg	;;
660432001f49Smrg      esac
660532001f49Smrg    done
660632001f49Smrg
660732001f49Smrg    # See if our shared archives depend on static archives.
660832001f49Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
660932001f49Smrg
661032001f49Smrg    # Go through the arguments, transforming them on the way.
661132001f49Smrg    while test "$#" -gt 0; do
66127ec3b29aSmrg      arg=$1
661332001f49Smrg      shift
661432001f49Smrg      func_quote_for_eval "$arg"
661532001f49Smrg      qarg=$func_quote_for_eval_unquoted_result
661632001f49Smrg      func_append libtool_args " $func_quote_for_eval_result"
661732001f49Smrg
661832001f49Smrg      # If the previous option needs an argument, assign it.
661932001f49Smrg      if test -n "$prev"; then
662032001f49Smrg	case $prev in
662132001f49Smrg	output)
662232001f49Smrg	  func_append compile_command " @OUTPUT@"
662332001f49Smrg	  func_append finalize_command " @OUTPUT@"
662432001f49Smrg	  ;;
662532001f49Smrg	esac
662632001f49Smrg
662732001f49Smrg	case $prev in
662832001f49Smrg	bindir)
66297ec3b29aSmrg	  bindir=$arg
663032001f49Smrg	  prev=
663132001f49Smrg	  continue
663232001f49Smrg	  ;;
663332001f49Smrg	dlfiles|dlprefiles)
66347ec3b29aSmrg	  $preload || {
663532001f49Smrg	    # Add the symbol object into the linking commands.
663632001f49Smrg	    func_append compile_command " @SYMFILE@"
663732001f49Smrg	    func_append finalize_command " @SYMFILE@"
66387ec3b29aSmrg	    preload=:
66397ec3b29aSmrg	  }
664032001f49Smrg	  case $arg in
664132001f49Smrg	  *.la | *.lo) ;;  # We handle these cases below.
664232001f49Smrg	  force)
66437ec3b29aSmrg	    if test no = "$dlself"; then
664432001f49Smrg	      dlself=needless
664532001f49Smrg	      export_dynamic=yes
664632001f49Smrg	    fi
664732001f49Smrg	    prev=
664832001f49Smrg	    continue
664932001f49Smrg	    ;;
665032001f49Smrg	  self)
66517ec3b29aSmrg	    if test dlprefiles = "$prev"; then
665232001f49Smrg	      dlself=yes
66537ec3b29aSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
665432001f49Smrg	      dlself=yes
665532001f49Smrg	    else
665632001f49Smrg	      dlself=needless
665732001f49Smrg	      export_dynamic=yes
665832001f49Smrg	    fi
665932001f49Smrg	    prev=
666032001f49Smrg	    continue
666132001f49Smrg	    ;;
666232001f49Smrg	  *)
66637ec3b29aSmrg	    if test dlfiles = "$prev"; then
666432001f49Smrg	      func_append dlfiles " $arg"
666532001f49Smrg	    else
666632001f49Smrg	      func_append dlprefiles " $arg"
666732001f49Smrg	    fi
666832001f49Smrg	    prev=
666932001f49Smrg	    continue
667032001f49Smrg	    ;;
667132001f49Smrg	  esac
667232001f49Smrg	  ;;
667332001f49Smrg	expsyms)
66747ec3b29aSmrg	  export_symbols=$arg
667532001f49Smrg	  test -f "$arg" \
66767ec3b29aSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
667732001f49Smrg	  prev=
667832001f49Smrg	  continue
667932001f49Smrg	  ;;
668032001f49Smrg	expsyms_regex)
66817ec3b29aSmrg	  export_symbols_regex=$arg
668232001f49Smrg	  prev=
668332001f49Smrg	  continue
668432001f49Smrg	  ;;
668532001f49Smrg	framework)
668632001f49Smrg	  case $host in
668732001f49Smrg	    *-*-darwin*)
668832001f49Smrg	      case "$deplibs " in
668932001f49Smrg		*" $qarg.ltframework "*) ;;
669032001f49Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
669132001f49Smrg		   ;;
669232001f49Smrg	      esac
669332001f49Smrg	      ;;
669432001f49Smrg	  esac
669532001f49Smrg	  prev=
669632001f49Smrg	  continue
669732001f49Smrg	  ;;
669832001f49Smrg	inst_prefix)
66997ec3b29aSmrg	  inst_prefix_dir=$arg
67007ec3b29aSmrg	  prev=
67017ec3b29aSmrg	  continue
67027ec3b29aSmrg	  ;;
67037ec3b29aSmrg	mllvm)
67047ec3b29aSmrg	  # Clang does not use LLVM to link, so we can simply discard any
67057ec3b29aSmrg	  # '-mllvm $arg' options when doing the link step.
670632001f49Smrg	  prev=
670732001f49Smrg	  continue
670832001f49Smrg	  ;;
670932001f49Smrg	objectlist)
671032001f49Smrg	  if test -f "$arg"; then
671132001f49Smrg	    save_arg=$arg
671232001f49Smrg	    moreargs=
671332001f49Smrg	    for fil in `cat "$save_arg"`
671432001f49Smrg	    do
671532001f49Smrg#	      func_append moreargs " $fil"
671632001f49Smrg	      arg=$fil
671732001f49Smrg	      # A libtool-controlled object.
671832001f49Smrg
671932001f49Smrg	      # Check to see that this really is a libtool object.
672032001f49Smrg	      if func_lalib_unsafe_p "$arg"; then
672132001f49Smrg		pic_object=
672232001f49Smrg		non_pic_object=
672332001f49Smrg
672432001f49Smrg		# Read the .lo file
672532001f49Smrg		func_source "$arg"
672632001f49Smrg
672732001f49Smrg		if test -z "$pic_object" ||
672832001f49Smrg		   test -z "$non_pic_object" ||
67297ec3b29aSmrg		   test none = "$pic_object" &&
67307ec3b29aSmrg		   test none = "$non_pic_object"; then
67317ec3b29aSmrg		  func_fatal_error "cannot find name of object for '$arg'"
673232001f49Smrg		fi
673332001f49Smrg
673432001f49Smrg		# Extract subdirectory from the argument.
673532001f49Smrg		func_dirname "$arg" "/" ""
67367ec3b29aSmrg		xdir=$func_dirname_result
673732001f49Smrg
67387ec3b29aSmrg		if test none != "$pic_object"; then
673932001f49Smrg		  # Prepend the subdirectory the object is found in.
67407ec3b29aSmrg		  pic_object=$xdir$pic_object
674132001f49Smrg
67427ec3b29aSmrg		  if test dlfiles = "$prev"; then
67437ec3b29aSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
674432001f49Smrg		      func_append dlfiles " $pic_object"
674532001f49Smrg		      prev=
674632001f49Smrg		      continue
674732001f49Smrg		    else
674832001f49Smrg		      # If libtool objects are unsupported, then we need to preload.
674932001f49Smrg		      prev=dlprefiles
675032001f49Smrg		    fi
675132001f49Smrg		  fi
675232001f49Smrg
675332001f49Smrg		  # CHECK ME:  I think I busted this.  -Ossama
67547ec3b29aSmrg		  if test dlprefiles = "$prev"; then
675532001f49Smrg		    # Preload the old-style object.
675632001f49Smrg		    func_append dlprefiles " $pic_object"
675732001f49Smrg		    prev=
675832001f49Smrg		  fi
675932001f49Smrg
676032001f49Smrg		  # A PIC object.
676132001f49Smrg		  func_append libobjs " $pic_object"
67627ec3b29aSmrg		  arg=$pic_object
676332001f49Smrg		fi
676432001f49Smrg
676532001f49Smrg		# Non-PIC object.
67667ec3b29aSmrg		if test none != "$non_pic_object"; then
676732001f49Smrg		  # Prepend the subdirectory the object is found in.
67687ec3b29aSmrg		  non_pic_object=$xdir$non_pic_object
676932001f49Smrg
677032001f49Smrg		  # A standard non-PIC object
677132001f49Smrg		  func_append non_pic_objects " $non_pic_object"
67727ec3b29aSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
67737ec3b29aSmrg		    arg=$non_pic_object
677432001f49Smrg		  fi
677532001f49Smrg		else
677632001f49Smrg		  # If the PIC object exists, use it instead.
677732001f49Smrg		  # $xdir was prepended to $pic_object above.
67787ec3b29aSmrg		  non_pic_object=$pic_object
677932001f49Smrg		  func_append non_pic_objects " $non_pic_object"
678032001f49Smrg		fi
678132001f49Smrg	      else
678232001f49Smrg		# Only an error if not doing a dry-run.
678332001f49Smrg		if $opt_dry_run; then
678432001f49Smrg		  # Extract subdirectory from the argument.
678532001f49Smrg		  func_dirname "$arg" "/" ""
67867ec3b29aSmrg		  xdir=$func_dirname_result
678732001f49Smrg
678832001f49Smrg		  func_lo2o "$arg"
678932001f49Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
679032001f49Smrg		  non_pic_object=$xdir$func_lo2o_result
679132001f49Smrg		  func_append libobjs " $pic_object"
679232001f49Smrg		  func_append non_pic_objects " $non_pic_object"
679332001f49Smrg	        else
67947ec3b29aSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
679532001f49Smrg		fi
679632001f49Smrg	      fi
679732001f49Smrg	    done
679832001f49Smrg	  else
67997ec3b29aSmrg	    func_fatal_error "link input file '$arg' does not exist"
680032001f49Smrg	  fi
680132001f49Smrg	  arg=$save_arg
680232001f49Smrg	  prev=
680332001f49Smrg	  continue
680432001f49Smrg	  ;;
68057ec3b29aSmrg	os2dllname)
68067ec3b29aSmrg	  os2dllname=$arg
68077ec3b29aSmrg	  prev=
68087ec3b29aSmrg	  continue
68097ec3b29aSmrg	  ;;
681032001f49Smrg	precious_regex)
68117ec3b29aSmrg	  precious_files_regex=$arg
681232001f49Smrg	  prev=
681332001f49Smrg	  continue
681432001f49Smrg	  ;;
681532001f49Smrg	release)
68167ec3b29aSmrg	  release=-$arg
681732001f49Smrg	  prev=
681832001f49Smrg	  continue
681932001f49Smrg	  ;;
682032001f49Smrg	rpath | xrpath)
682132001f49Smrg	  # We need an absolute path.
682232001f49Smrg	  case $arg in
682332001f49Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
682432001f49Smrg	  *)
682532001f49Smrg	    func_fatal_error "only absolute run-paths are allowed"
682632001f49Smrg	    ;;
682732001f49Smrg	  esac
68287ec3b29aSmrg	  if test rpath = "$prev"; then
682932001f49Smrg	    case "$rpath " in
683032001f49Smrg	    *" $arg "*) ;;
683132001f49Smrg	    *) func_append rpath " $arg" ;;
683232001f49Smrg	    esac
683332001f49Smrg	  else
683432001f49Smrg	    case "$xrpath " in
683532001f49Smrg	    *" $arg "*) ;;
683632001f49Smrg	    *) func_append xrpath " $arg" ;;
683732001f49Smrg	    esac
683832001f49Smrg	  fi
683932001f49Smrg	  prev=
684032001f49Smrg	  continue
684132001f49Smrg	  ;;
684232001f49Smrg	shrext)
68437ec3b29aSmrg	  shrext_cmds=$arg
684432001f49Smrg	  prev=
684532001f49Smrg	  continue
684632001f49Smrg	  ;;
684732001f49Smrg	weak)
684832001f49Smrg	  func_append weak_libs " $arg"
684932001f49Smrg	  prev=
685032001f49Smrg	  continue
685132001f49Smrg	  ;;
685232001f49Smrg	xcclinker)
685332001f49Smrg	  func_append linker_flags " $qarg"
685432001f49Smrg	  func_append compiler_flags " $qarg"
685532001f49Smrg	  prev=
685632001f49Smrg	  func_append compile_command " $qarg"
685732001f49Smrg	  func_append finalize_command " $qarg"
685832001f49Smrg	  continue
685932001f49Smrg	  ;;
686032001f49Smrg	xcompiler)
686132001f49Smrg	  func_append compiler_flags " $qarg"
686232001f49Smrg	  prev=
686332001f49Smrg	  func_append compile_command " $qarg"
686432001f49Smrg	  func_append finalize_command " $qarg"
686532001f49Smrg	  continue
686632001f49Smrg	  ;;
686732001f49Smrg	xlinker)
686832001f49Smrg	  func_append linker_flags " $qarg"
686932001f49Smrg	  func_append compiler_flags " $wl$qarg"
687032001f49Smrg	  prev=
687132001f49Smrg	  func_append compile_command " $wl$qarg"
687232001f49Smrg	  func_append finalize_command " $wl$qarg"
687332001f49Smrg	  continue
687432001f49Smrg	  ;;
687532001f49Smrg	*)
687632001f49Smrg	  eval "$prev=\"\$arg\""
687732001f49Smrg	  prev=
687832001f49Smrg	  continue
687932001f49Smrg	  ;;
688032001f49Smrg	esac
688132001f49Smrg      fi # test -n "$prev"
688232001f49Smrg
68837ec3b29aSmrg      prevarg=$arg
688432001f49Smrg
688532001f49Smrg      case $arg in
688632001f49Smrg      -all-static)
688732001f49Smrg	if test -n "$link_static_flag"; then
688832001f49Smrg	  # See comment for -static flag below, for more details.
688932001f49Smrg	  func_append compile_command " $link_static_flag"
689032001f49Smrg	  func_append finalize_command " $link_static_flag"
689132001f49Smrg	fi
689232001f49Smrg	continue
689332001f49Smrg	;;
689432001f49Smrg
689532001f49Smrg      -allow-undefined)
689632001f49Smrg	# FIXME: remove this flag sometime in the future.
68977ec3b29aSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
689832001f49Smrg	;;
689932001f49Smrg
690032001f49Smrg      -avoid-version)
690132001f49Smrg	avoid_version=yes
690232001f49Smrg	continue
690332001f49Smrg	;;
690432001f49Smrg
690532001f49Smrg      -bindir)
690632001f49Smrg	prev=bindir
690732001f49Smrg	continue
690832001f49Smrg	;;
690932001f49Smrg
691032001f49Smrg      -dlopen)
691132001f49Smrg	prev=dlfiles
691232001f49Smrg	continue
691332001f49Smrg	;;
691432001f49Smrg
691532001f49Smrg      -dlpreopen)
691632001f49Smrg	prev=dlprefiles
691732001f49Smrg	continue
691832001f49Smrg	;;
691932001f49Smrg
692032001f49Smrg      -export-dynamic)
692132001f49Smrg	export_dynamic=yes
692232001f49Smrg	continue
692332001f49Smrg	;;
692432001f49Smrg
692532001f49Smrg      -export-symbols | -export-symbols-regex)
692632001f49Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
692732001f49Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
692832001f49Smrg	fi
69297ec3b29aSmrg	if test X-export-symbols = "X$arg"; then
693032001f49Smrg	  prev=expsyms
693132001f49Smrg	else
693232001f49Smrg	  prev=expsyms_regex
693332001f49Smrg	fi
693432001f49Smrg	continue
693532001f49Smrg	;;
693632001f49Smrg
693732001f49Smrg      -framework)
693832001f49Smrg	prev=framework
693932001f49Smrg	continue
694032001f49Smrg	;;
694132001f49Smrg
694232001f49Smrg      -inst-prefix-dir)
694332001f49Smrg	prev=inst_prefix
694432001f49Smrg	continue
694532001f49Smrg	;;
694632001f49Smrg
694732001f49Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
694832001f49Smrg      # so, if we see these flags be careful not to treat them like -L
694932001f49Smrg      -L[A-Z][A-Z]*:*)
695032001f49Smrg	case $with_gcc/$host in
695132001f49Smrg	no/*-*-irix* | /*-*-irix*)
695232001f49Smrg	  func_append compile_command " $arg"
695332001f49Smrg	  func_append finalize_command " $arg"
695432001f49Smrg	  ;;
695532001f49Smrg	esac
695632001f49Smrg	continue
695732001f49Smrg	;;
695832001f49Smrg
695932001f49Smrg      -L*)
696032001f49Smrg	func_stripname "-L" '' "$arg"
696132001f49Smrg	if test -z "$func_stripname_result"; then
696232001f49Smrg	  if test "$#" -gt 0; then
69637ec3b29aSmrg	    func_fatal_error "require no space between '-L' and '$1'"
696432001f49Smrg	  else
69657ec3b29aSmrg	    func_fatal_error "need path for '-L' option"
696632001f49Smrg	  fi
696732001f49Smrg	fi
696832001f49Smrg	func_resolve_sysroot "$func_stripname_result"
696932001f49Smrg	dir=$func_resolve_sysroot_result
697032001f49Smrg	# We need an absolute path.
697132001f49Smrg	case $dir in
697232001f49Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
697332001f49Smrg	*)
697432001f49Smrg	  absdir=`cd "$dir" && pwd`
697532001f49Smrg	  test -z "$absdir" && \
69767ec3b29aSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
69777ec3b29aSmrg	  dir=$absdir
697832001f49Smrg	  ;;
697932001f49Smrg	esac
698032001f49Smrg	case "$deplibs " in
698132001f49Smrg	*" -L$dir "* | *" $arg "*)
698232001f49Smrg	  # Will only happen for absolute or sysroot arguments
698332001f49Smrg	  ;;
698432001f49Smrg	*)
698532001f49Smrg	  # Preserve sysroot, but never include relative directories
698632001f49Smrg	  case $dir in
698732001f49Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
698832001f49Smrg	    *) func_append deplibs " -L$dir" ;;
698932001f49Smrg	  esac
699032001f49Smrg	  func_append lib_search_path " $dir"
699132001f49Smrg	  ;;
699232001f49Smrg	esac
699332001f49Smrg	case $host in
699432001f49Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
699532001f49Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
699632001f49Smrg	  case :$dllsearchpath: in
699732001f49Smrg	  *":$dir:"*) ;;
699832001f49Smrg	  ::) dllsearchpath=$dir;;
699932001f49Smrg	  *) func_append dllsearchpath ":$dir";;
700032001f49Smrg	  esac
700132001f49Smrg	  case :$dllsearchpath: in
700232001f49Smrg	  *":$testbindir:"*) ;;
700332001f49Smrg	  ::) dllsearchpath=$testbindir;;
700432001f49Smrg	  *) func_append dllsearchpath ":$testbindir";;
700532001f49Smrg	  esac
700632001f49Smrg	  ;;
700732001f49Smrg	esac
700832001f49Smrg	continue
700932001f49Smrg	;;
701032001f49Smrg
701132001f49Smrg      -l*)
70127ec3b29aSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
701332001f49Smrg	  case $host in
701432001f49Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
701532001f49Smrg	    # These systems don't actually have a C or math library (as such)
701632001f49Smrg	    continue
701732001f49Smrg	    ;;
701832001f49Smrg	  *-*-os2*)
701932001f49Smrg	    # These systems don't actually have a C library (as such)
70207ec3b29aSmrg	    test X-lc = "X$arg" && continue
702132001f49Smrg	    ;;
70227ec3b29aSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
702332001f49Smrg	    # Do not include libc due to us having libc/libc_r.
70247ec3b29aSmrg	    test X-lc = "X$arg" && continue
702532001f49Smrg	    ;;
702632001f49Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
702732001f49Smrg	    # Rhapsody C and math libraries are in the System framework
702832001f49Smrg	    func_append deplibs " System.ltframework"
702932001f49Smrg	    continue
703032001f49Smrg	    ;;
703132001f49Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
703232001f49Smrg	    # Causes problems with __ctype
70337ec3b29aSmrg	    test X-lc = "X$arg" && continue
703432001f49Smrg	    ;;
703532001f49Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
703632001f49Smrg	    # Compiler inserts libc in the correct place for threads to work
70377ec3b29aSmrg	    test X-lc = "X$arg" && continue
703832001f49Smrg	    ;;
703932001f49Smrg	  esac
70407ec3b29aSmrg	elif test X-lc_r = "X$arg"; then
704132001f49Smrg	 case $host in
70427ec3b29aSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
704332001f49Smrg	   # Do not include libc_r directly, use -pthread flag.
704432001f49Smrg	   continue
704532001f49Smrg	   ;;
704632001f49Smrg	 esac
704732001f49Smrg	fi
704832001f49Smrg	func_append deplibs " $arg"
704932001f49Smrg	continue
705032001f49Smrg	;;
705132001f49Smrg
70527ec3b29aSmrg      -mllvm)
70537ec3b29aSmrg	prev=mllvm
70547ec3b29aSmrg	continue
70557ec3b29aSmrg	;;
70567ec3b29aSmrg
705732001f49Smrg      -module)
705832001f49Smrg	module=yes
705932001f49Smrg	continue
706032001f49Smrg	;;
706132001f49Smrg
706232001f49Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
706332001f49Smrg      # classes, name mangling, and exception handling.
706432001f49Smrg      # Darwin uses the -arch flag to determine output architecture.
706532001f49Smrg      -model|-arch|-isysroot|--sysroot)
706632001f49Smrg	func_append compiler_flags " $arg"
706732001f49Smrg	func_append compile_command " $arg"
706832001f49Smrg	func_append finalize_command " $arg"
706932001f49Smrg	prev=xcompiler
707032001f49Smrg	continue
707132001f49Smrg	;;
707232001f49Smrg
707332001f49Smrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
707432001f49Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
707532001f49Smrg	func_append compiler_flags " $arg"
707632001f49Smrg	func_append compile_command " $arg"
707732001f49Smrg	func_append finalize_command " $arg"
707832001f49Smrg	case "$new_inherited_linker_flags " in
707932001f49Smrg	    *" $arg "*) ;;
708032001f49Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
708132001f49Smrg	esac
708232001f49Smrg	continue
708332001f49Smrg	;;
708432001f49Smrg
708532001f49Smrg      -multi_module)
70867ec3b29aSmrg	single_module=$wl-multi_module
708732001f49Smrg	continue
708832001f49Smrg	;;
708932001f49Smrg
709032001f49Smrg      -no-fast-install)
709132001f49Smrg	fast_install=no
709232001f49Smrg	continue
709332001f49Smrg	;;
709432001f49Smrg
709532001f49Smrg      -no-install)
709632001f49Smrg	case $host in
709732001f49Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
709832001f49Smrg	  # The PATH hackery in wrapper scripts is required on Windows
709932001f49Smrg	  # and Darwin in order for the loader to find any dlls it needs.
71007ec3b29aSmrg	  func_warning "'-no-install' is ignored for $host"
71017ec3b29aSmrg	  func_warning "assuming '-no-fast-install' instead"
710232001f49Smrg	  fast_install=no
710332001f49Smrg	  ;;
710432001f49Smrg	*) no_install=yes ;;
710532001f49Smrg	esac
710632001f49Smrg	continue
710732001f49Smrg	;;
710832001f49Smrg
710932001f49Smrg      -no-undefined)
711032001f49Smrg	allow_undefined=no
711132001f49Smrg	continue
711232001f49Smrg	;;
711332001f49Smrg
711432001f49Smrg      -objectlist)
711532001f49Smrg	prev=objectlist
711632001f49Smrg	continue
711732001f49Smrg	;;
711832001f49Smrg
71197ec3b29aSmrg      -os2dllname)
71207ec3b29aSmrg	prev=os2dllname
71217ec3b29aSmrg	continue
71227ec3b29aSmrg	;;
71237ec3b29aSmrg
712432001f49Smrg      -o) prev=output ;;
712532001f49Smrg
712632001f49Smrg      -precious-files-regex)
712732001f49Smrg	prev=precious_regex
712832001f49Smrg	continue
712932001f49Smrg	;;
713032001f49Smrg
713132001f49Smrg      -release)
713232001f49Smrg	prev=release
713332001f49Smrg	continue
713432001f49Smrg	;;
713532001f49Smrg
713632001f49Smrg      -rpath)
713732001f49Smrg	prev=rpath
713832001f49Smrg	continue
713932001f49Smrg	;;
714032001f49Smrg
714132001f49Smrg      -R)
714232001f49Smrg	prev=xrpath
714332001f49Smrg	continue
714432001f49Smrg	;;
714532001f49Smrg
714632001f49Smrg      -R*)
714732001f49Smrg	func_stripname '-R' '' "$arg"
714832001f49Smrg	dir=$func_stripname_result
714932001f49Smrg	# We need an absolute path.
715032001f49Smrg	case $dir in
715132001f49Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
715232001f49Smrg	=*)
715332001f49Smrg	  func_stripname '=' '' "$dir"
715432001f49Smrg	  dir=$lt_sysroot$func_stripname_result
715532001f49Smrg	  ;;
715632001f49Smrg	*)
715732001f49Smrg	  func_fatal_error "only absolute run-paths are allowed"
715832001f49Smrg	  ;;
715932001f49Smrg	esac
716032001f49Smrg	case "$xrpath " in
716132001f49Smrg	*" $dir "*) ;;
716232001f49Smrg	*) func_append xrpath " $dir" ;;
716332001f49Smrg	esac
716432001f49Smrg	continue
716532001f49Smrg	;;
716632001f49Smrg
716732001f49Smrg      -shared)
716832001f49Smrg	# The effects of -shared are defined in a previous loop.
716932001f49Smrg	continue
717032001f49Smrg	;;
717132001f49Smrg
717232001f49Smrg      -shrext)
717332001f49Smrg	prev=shrext
717432001f49Smrg	continue
717532001f49Smrg	;;
717632001f49Smrg
717732001f49Smrg      -static | -static-libtool-libs)
717832001f49Smrg	# The effects of -static are defined in a previous loop.
717932001f49Smrg	# We used to do the same as -all-static on platforms that
718032001f49Smrg	# didn't have a PIC flag, but the assumption that the effects
718132001f49Smrg	# would be equivalent was wrong.  It would break on at least
718232001f49Smrg	# Digital Unix and AIX.
718332001f49Smrg	continue
718432001f49Smrg	;;
718532001f49Smrg
718632001f49Smrg      -thread-safe)
718732001f49Smrg	thread_safe=yes
718832001f49Smrg	continue
718932001f49Smrg	;;
719032001f49Smrg
719132001f49Smrg      -version-info)
719232001f49Smrg	prev=vinfo
719332001f49Smrg	continue
719432001f49Smrg	;;
719532001f49Smrg
719632001f49Smrg      -version-number)
719732001f49Smrg	prev=vinfo
719832001f49Smrg	vinfo_number=yes
719932001f49Smrg	continue
720032001f49Smrg	;;
720132001f49Smrg
720232001f49Smrg      -weak)
720332001f49Smrg        prev=weak
720432001f49Smrg	continue
720532001f49Smrg	;;
720632001f49Smrg
720732001f49Smrg      -Wc,*)
720832001f49Smrg	func_stripname '-Wc,' '' "$arg"
720932001f49Smrg	args=$func_stripname_result
721032001f49Smrg	arg=
72117ec3b29aSmrg	save_ifs=$IFS; IFS=,
721232001f49Smrg	for flag in $args; do
72137ec3b29aSmrg	  IFS=$save_ifs
721432001f49Smrg          func_quote_for_eval "$flag"
721532001f49Smrg	  func_append arg " $func_quote_for_eval_result"
721632001f49Smrg	  func_append compiler_flags " $func_quote_for_eval_result"
721732001f49Smrg	done
72187ec3b29aSmrg	IFS=$save_ifs
721932001f49Smrg	func_stripname ' ' '' "$arg"
722032001f49Smrg	arg=$func_stripname_result
722132001f49Smrg	;;
722232001f49Smrg
722332001f49Smrg      -Wl,*)
722432001f49Smrg	func_stripname '-Wl,' '' "$arg"
722532001f49Smrg	args=$func_stripname_result
722632001f49Smrg	arg=
72277ec3b29aSmrg	save_ifs=$IFS; IFS=,
722832001f49Smrg	for flag in $args; do
72297ec3b29aSmrg	  IFS=$save_ifs
723032001f49Smrg          func_quote_for_eval "$flag"
723132001f49Smrg	  func_append arg " $wl$func_quote_for_eval_result"
723232001f49Smrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
723332001f49Smrg	  func_append linker_flags " $func_quote_for_eval_result"
723432001f49Smrg	done
72357ec3b29aSmrg	IFS=$save_ifs
723632001f49Smrg	func_stripname ' ' '' "$arg"
723732001f49Smrg	arg=$func_stripname_result
723832001f49Smrg	;;
723932001f49Smrg
724032001f49Smrg      -Xcompiler)
724132001f49Smrg	prev=xcompiler
724232001f49Smrg	continue
724332001f49Smrg	;;
724432001f49Smrg
724532001f49Smrg      -Xlinker)
724632001f49Smrg	prev=xlinker
724732001f49Smrg	continue
724832001f49Smrg	;;
724932001f49Smrg
725032001f49Smrg      -XCClinker)
725132001f49Smrg	prev=xcclinker
725232001f49Smrg	continue
725332001f49Smrg	;;
725432001f49Smrg
725532001f49Smrg      # -msg_* for osf cc
725632001f49Smrg      -msg_*)
725732001f49Smrg	func_quote_for_eval "$arg"
72587ec3b29aSmrg	arg=$func_quote_for_eval_result
725932001f49Smrg	;;
726032001f49Smrg
726132001f49Smrg      # Flags to be passed through unchanged, with rationale:
726232001f49Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
726332001f49Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
726432001f49Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
726532001f49Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
726632001f49Smrg      # -q*                  compiler args for the IBM compiler
726732001f49Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
726832001f49Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
726932001f49Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
72707ec3b29aSmrg      # -fstack-protector*   stack protector flags for GCC
727132001f49Smrg      # @file                GCC response files
727232001f49Smrg      # -tp=*                Portland pgcc target processor selection
727332001f49Smrg      # --sysroot=*          for sysroot support
72747ec3b29aSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
72757ec3b29aSmrg      # -specs=*             GCC specs files
72767ec3b29aSmrg      # -stdlib=*            select c++ std lib with clang
72777ec3b29aSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
727832001f49Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
727932001f49Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
72807ec3b29aSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
72817ec3b29aSmrg      -specs=*|-fsanitize=*)
728232001f49Smrg        func_quote_for_eval "$arg"
72837ec3b29aSmrg	arg=$func_quote_for_eval_result
728432001f49Smrg        func_append compile_command " $arg"
728532001f49Smrg        func_append finalize_command " $arg"
728632001f49Smrg        func_append compiler_flags " $arg"
728732001f49Smrg        continue
728832001f49Smrg        ;;
728932001f49Smrg
72907ec3b29aSmrg      -Z*)
72917ec3b29aSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
72927ec3b29aSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
72937ec3b29aSmrg	  compiler_flags="$compiler_flags $arg"
72947ec3b29aSmrg	  func_append compile_command " $arg"
72957ec3b29aSmrg	  func_append finalize_command " $arg"
72967ec3b29aSmrg	  case $arg in
72977ec3b29aSmrg	  -Zlinker | -Zstack)
72987ec3b29aSmrg	    prev=xcompiler
72997ec3b29aSmrg	    ;;
73007ec3b29aSmrg	  esac
73017ec3b29aSmrg	  continue
73027ec3b29aSmrg        else
73037ec3b29aSmrg	  # Otherwise treat like 'Some other compiler flag' below
73047ec3b29aSmrg	  func_quote_for_eval "$arg"
73057ec3b29aSmrg	  arg=$func_quote_for_eval_result
73067ec3b29aSmrg        fi
73077ec3b29aSmrg	;;
73087ec3b29aSmrg
730932001f49Smrg      # Some other compiler flag.
731032001f49Smrg      -* | +*)
731132001f49Smrg        func_quote_for_eval "$arg"
73127ec3b29aSmrg	arg=$func_quote_for_eval_result
731332001f49Smrg	;;
731432001f49Smrg
731532001f49Smrg      *.$objext)
731632001f49Smrg	# A standard object.
731732001f49Smrg	func_append objs " $arg"
731832001f49Smrg	;;
731932001f49Smrg
732032001f49Smrg      *.lo)
732132001f49Smrg	# A libtool-controlled object.
732232001f49Smrg
732332001f49Smrg	# Check to see that this really is a libtool object.
732432001f49Smrg	if func_lalib_unsafe_p "$arg"; then
732532001f49Smrg	  pic_object=
732632001f49Smrg	  non_pic_object=
732732001f49Smrg
732832001f49Smrg	  # Read the .lo file
732932001f49Smrg	  func_source "$arg"
733032001f49Smrg
733132001f49Smrg	  if test -z "$pic_object" ||
733232001f49Smrg	     test -z "$non_pic_object" ||
73337ec3b29aSmrg	     test none = "$pic_object" &&
73347ec3b29aSmrg	     test none = "$non_pic_object"; then
73357ec3b29aSmrg	    func_fatal_error "cannot find name of object for '$arg'"
733632001f49Smrg	  fi
733732001f49Smrg
733832001f49Smrg	  # Extract subdirectory from the argument.
733932001f49Smrg	  func_dirname "$arg" "/" ""
73407ec3b29aSmrg	  xdir=$func_dirname_result
734132001f49Smrg
73427ec3b29aSmrg	  test none = "$pic_object" || {
734332001f49Smrg	    # Prepend the subdirectory the object is found in.
73447ec3b29aSmrg	    pic_object=$xdir$pic_object
734532001f49Smrg
73467ec3b29aSmrg	    if test dlfiles = "$prev"; then
73477ec3b29aSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
734832001f49Smrg		func_append dlfiles " $pic_object"
734932001f49Smrg		prev=
735032001f49Smrg		continue
735132001f49Smrg	      else
735232001f49Smrg		# If libtool objects are unsupported, then we need to preload.
735332001f49Smrg		prev=dlprefiles
735432001f49Smrg	      fi
735532001f49Smrg	    fi
735632001f49Smrg
735732001f49Smrg	    # CHECK ME:  I think I busted this.  -Ossama
73587ec3b29aSmrg	    if test dlprefiles = "$prev"; then
735932001f49Smrg	      # Preload the old-style object.
736032001f49Smrg	      func_append dlprefiles " $pic_object"
736132001f49Smrg	      prev=
736232001f49Smrg	    fi
736332001f49Smrg
736432001f49Smrg	    # A PIC object.
736532001f49Smrg	    func_append libobjs " $pic_object"
73667ec3b29aSmrg	    arg=$pic_object
73677ec3b29aSmrg	  }
736832001f49Smrg
736932001f49Smrg	  # Non-PIC object.
73707ec3b29aSmrg	  if test none != "$non_pic_object"; then
737132001f49Smrg	    # Prepend the subdirectory the object is found in.
73727ec3b29aSmrg	    non_pic_object=$xdir$non_pic_object
737332001f49Smrg
737432001f49Smrg	    # A standard non-PIC object
737532001f49Smrg	    func_append non_pic_objects " $non_pic_object"
73767ec3b29aSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
73777ec3b29aSmrg	      arg=$non_pic_object
737832001f49Smrg	    fi
737932001f49Smrg	  else
738032001f49Smrg	    # If the PIC object exists, use it instead.
738132001f49Smrg	    # $xdir was prepended to $pic_object above.
73827ec3b29aSmrg	    non_pic_object=$pic_object
738332001f49Smrg	    func_append non_pic_objects " $non_pic_object"
738432001f49Smrg	  fi
738532001f49Smrg	else
738632001f49Smrg	  # Only an error if not doing a dry-run.
738732001f49Smrg	  if $opt_dry_run; then
738832001f49Smrg	    # Extract subdirectory from the argument.
738932001f49Smrg	    func_dirname "$arg" "/" ""
73907ec3b29aSmrg	    xdir=$func_dirname_result
739132001f49Smrg
739232001f49Smrg	    func_lo2o "$arg"
739332001f49Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
739432001f49Smrg	    non_pic_object=$xdir$func_lo2o_result
739532001f49Smrg	    func_append libobjs " $pic_object"
739632001f49Smrg	    func_append non_pic_objects " $non_pic_object"
739732001f49Smrg	  else
73987ec3b29aSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
739932001f49Smrg	  fi
740032001f49Smrg	fi
740132001f49Smrg	;;
740232001f49Smrg
740332001f49Smrg      *.$libext)
740432001f49Smrg	# An archive.
740532001f49Smrg	func_append deplibs " $arg"
740632001f49Smrg	func_append old_deplibs " $arg"
740732001f49Smrg	continue
740832001f49Smrg	;;
740932001f49Smrg
741032001f49Smrg      *.la)
741132001f49Smrg	# A libtool-controlled library.
741232001f49Smrg
741332001f49Smrg	func_resolve_sysroot "$arg"
74147ec3b29aSmrg	if test dlfiles = "$prev"; then
741532001f49Smrg	  # This library was specified with -dlopen.
741632001f49Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
741732001f49Smrg	  prev=
74187ec3b29aSmrg	elif test dlprefiles = "$prev"; then
741932001f49Smrg	  # The library was specified with -dlpreopen.
742032001f49Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
742132001f49Smrg	  prev=
742232001f49Smrg	else
742332001f49Smrg	  func_append deplibs " $func_resolve_sysroot_result"
742432001f49Smrg	fi
742532001f49Smrg	continue
742632001f49Smrg	;;
742732001f49Smrg
742832001f49Smrg      # Some other compiler argument.
742932001f49Smrg      *)
743032001f49Smrg	# Unknown arguments in both finalize_command and compile_command need
743132001f49Smrg	# to be aesthetically quoted because they are evaled later.
743232001f49Smrg	func_quote_for_eval "$arg"
74337ec3b29aSmrg	arg=$func_quote_for_eval_result
743432001f49Smrg	;;
743532001f49Smrg      esac # arg
743632001f49Smrg
743732001f49Smrg      # Now actually substitute the argument into the commands.
743832001f49Smrg      if test -n "$arg"; then
743932001f49Smrg	func_append compile_command " $arg"
744032001f49Smrg	func_append finalize_command " $arg"
744132001f49Smrg      fi
744232001f49Smrg    done # argument parsing loop
744332001f49Smrg
744432001f49Smrg    test -n "$prev" && \
74457ec3b29aSmrg      func_fatal_help "the '$prevarg' option requires an argument"
744632001f49Smrg
74477ec3b29aSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
744832001f49Smrg      eval arg=\"$export_dynamic_flag_spec\"
744932001f49Smrg      func_append compile_command " $arg"
745032001f49Smrg      func_append finalize_command " $arg"
745132001f49Smrg    fi
745232001f49Smrg
745332001f49Smrg    oldlibs=
745432001f49Smrg    # calculate the name of the file, without its directory
745532001f49Smrg    func_basename "$output"
74567ec3b29aSmrg    outputname=$func_basename_result
74577ec3b29aSmrg    libobjs_save=$libobjs
745832001f49Smrg
745932001f49Smrg    if test -n "$shlibpath_var"; then
746032001f49Smrg      # get the directories listed in $shlibpath_var
74617ec3b29aSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
746232001f49Smrg    else
746332001f49Smrg      shlib_search_path=
746432001f49Smrg    fi
746532001f49Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
746632001f49Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
746732001f49Smrg
74687ec3b29aSmrg    # Definition is injected by LT_CONFIG during libtool generation.
74697ec3b29aSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
74707ec3b29aSmrg
747132001f49Smrg    func_dirname "$output" "/" ""
74727ec3b29aSmrg    output_objdir=$func_dirname_result$objdir
747332001f49Smrg    func_to_tool_file "$output_objdir/"
747432001f49Smrg    tool_output_objdir=$func_to_tool_file_result
747532001f49Smrg    # Create the object directory.
747632001f49Smrg    func_mkdir_p "$output_objdir"
747732001f49Smrg
747832001f49Smrg    # Determine the type of output
747932001f49Smrg    case $output in
748032001f49Smrg    "")
748132001f49Smrg      func_fatal_help "you must specify an output file"
748232001f49Smrg      ;;
748332001f49Smrg    *.$libext) linkmode=oldlib ;;
748432001f49Smrg    *.lo | *.$objext) linkmode=obj ;;
748532001f49Smrg    *.la) linkmode=lib ;;
748632001f49Smrg    *) linkmode=prog ;; # Anything else should be a program.
748732001f49Smrg    esac
748832001f49Smrg
748932001f49Smrg    specialdeplibs=
749032001f49Smrg
749132001f49Smrg    libs=
749232001f49Smrg    # Find all interdependent deplibs by searching for libraries
749332001f49Smrg    # that are linked more than once (e.g. -la -lb -la)
749432001f49Smrg    for deplib in $deplibs; do
74957ec3b29aSmrg      if $opt_preserve_dup_deps; then
749632001f49Smrg	case "$libs " in
749732001f49Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
749832001f49Smrg	esac
749932001f49Smrg      fi
750032001f49Smrg      func_append libs " $deplib"
750132001f49Smrg    done
750232001f49Smrg
75037ec3b29aSmrg    if test lib = "$linkmode"; then
750432001f49Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
750532001f49Smrg
750632001f49Smrg      # Compute libraries that are listed more than once in $predeps
750732001f49Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
750832001f49Smrg      # not to be eliminated).
750932001f49Smrg      pre_post_deps=
751032001f49Smrg      if $opt_duplicate_compiler_generated_deps; then
751132001f49Smrg	for pre_post_dep in $predeps $postdeps; do
751232001f49Smrg	  case "$pre_post_deps " in
751332001f49Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
751432001f49Smrg	  esac
751532001f49Smrg	  func_append pre_post_deps " $pre_post_dep"
751632001f49Smrg	done
751732001f49Smrg      fi
751832001f49Smrg      pre_post_deps=
751932001f49Smrg    fi
752032001f49Smrg
752132001f49Smrg    deplibs=
752232001f49Smrg    newdependency_libs=
752332001f49Smrg    newlib_search_path=
752432001f49Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
752532001f49Smrg    notinst_deplibs= # not-installed libtool libraries
752632001f49Smrg    notinst_path= # paths that contain not-installed libtool libraries
752732001f49Smrg
752832001f49Smrg    case $linkmode in
752932001f49Smrg    lib)
753032001f49Smrg	passes="conv dlpreopen link"
753132001f49Smrg	for file in $dlfiles $dlprefiles; do
753232001f49Smrg	  case $file in
753332001f49Smrg	  *.la) ;;
753432001f49Smrg	  *)
75357ec3b29aSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
753632001f49Smrg	    ;;
753732001f49Smrg	  esac
753832001f49Smrg	done
753932001f49Smrg	;;
754032001f49Smrg    prog)
754132001f49Smrg	compile_deplibs=
754232001f49Smrg	finalize_deplibs=
75437ec3b29aSmrg	alldeplibs=false
754432001f49Smrg	newdlfiles=
754532001f49Smrg	newdlprefiles=
754632001f49Smrg	passes="conv scan dlopen dlpreopen link"
754732001f49Smrg	;;
754832001f49Smrg    *)  passes="conv"
754932001f49Smrg	;;
755032001f49Smrg    esac
755132001f49Smrg
755232001f49Smrg    for pass in $passes; do
755332001f49Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
755432001f49Smrg      # so that -L comes before libs that need it for instance...
75557ec3b29aSmrg      if test lib,link = "$linkmode,$pass"; then
755632001f49Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
755732001f49Smrg	##        order, and fix it there properly
755832001f49Smrg        tmp_deplibs=
755932001f49Smrg	for deplib in $deplibs; do
756032001f49Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
756132001f49Smrg	done
75627ec3b29aSmrg	deplibs=$tmp_deplibs
756332001f49Smrg      fi
756432001f49Smrg
75657ec3b29aSmrg      if test lib,link = "$linkmode,$pass" ||
75667ec3b29aSmrg	 test prog,scan = "$linkmode,$pass"; then
75677ec3b29aSmrg	libs=$deplibs
756832001f49Smrg	deplibs=
756932001f49Smrg      fi
75707ec3b29aSmrg      if test prog = "$linkmode"; then
757132001f49Smrg	case $pass in
75727ec3b29aSmrg	dlopen) libs=$dlfiles ;;
75737ec3b29aSmrg	dlpreopen) libs=$dlprefiles ;;
757432001f49Smrg	link)
757532001f49Smrg	  libs="$deplibs %DEPLIBS%"
757632001f49Smrg	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
757732001f49Smrg	  ;;
757832001f49Smrg	esac
757932001f49Smrg      fi
75807ec3b29aSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
758132001f49Smrg	# Collect and forward deplibs of preopened libtool libs
758232001f49Smrg	for lib in $dlprefiles; do
758332001f49Smrg	  # Ignore non-libtool-libs
758432001f49Smrg	  dependency_libs=
758532001f49Smrg	  func_resolve_sysroot "$lib"
758632001f49Smrg	  case $lib in
758732001f49Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
758832001f49Smrg	  esac
758932001f49Smrg
759032001f49Smrg	  # Collect preopened libtool deplibs, except any this library
759132001f49Smrg	  # has declared as weak libs
759232001f49Smrg	  for deplib in $dependency_libs; do
759332001f49Smrg	    func_basename "$deplib"
759432001f49Smrg            deplib_base=$func_basename_result
759532001f49Smrg	    case " $weak_libs " in
759632001f49Smrg	    *" $deplib_base "*) ;;
759732001f49Smrg	    *) func_append deplibs " $deplib" ;;
759832001f49Smrg	    esac
759932001f49Smrg	  done
760032001f49Smrg	done
76017ec3b29aSmrg	libs=$dlprefiles
760232001f49Smrg      fi
76037ec3b29aSmrg      if test dlopen = "$pass"; then
760432001f49Smrg	# Collect dlpreopened libraries
76057ec3b29aSmrg	save_deplibs=$deplibs
760632001f49Smrg	deplibs=
760732001f49Smrg      fi
760832001f49Smrg
760932001f49Smrg      for deplib in $libs; do
761032001f49Smrg	lib=
76117ec3b29aSmrg	found=false
761232001f49Smrg	case $deplib in
761332001f49Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
761432001f49Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
76157ec3b29aSmrg	  if test prog,link = "$linkmode,$pass"; then
761632001f49Smrg	    compile_deplibs="$deplib $compile_deplibs"
761732001f49Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
761832001f49Smrg	  else
761932001f49Smrg	    func_append compiler_flags " $deplib"
76207ec3b29aSmrg	    if test lib = "$linkmode"; then
762132001f49Smrg		case "$new_inherited_linker_flags " in
762232001f49Smrg		    *" $deplib "*) ;;
762332001f49Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
762432001f49Smrg		esac
762532001f49Smrg	    fi
762632001f49Smrg	  fi
762732001f49Smrg	  continue
762832001f49Smrg	  ;;
762932001f49Smrg	-l*)
76307ec3b29aSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
76317ec3b29aSmrg	    func_warning "'-l' is ignored for archives/objects"
763232001f49Smrg	    continue
763332001f49Smrg	  fi
763432001f49Smrg	  func_stripname '-l' '' "$deplib"
763532001f49Smrg	  name=$func_stripname_result
76367ec3b29aSmrg	  if test lib = "$linkmode"; then
763732001f49Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
763832001f49Smrg	  else
763932001f49Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
764032001f49Smrg	  fi
764132001f49Smrg	  for searchdir in $searchdirs; do
764232001f49Smrg	    for search_ext in .la $std_shrext .so .a; do
764332001f49Smrg	      # Search the libtool library
76447ec3b29aSmrg	      lib=$searchdir/lib$name$search_ext
764532001f49Smrg	      if test -f "$lib"; then
76467ec3b29aSmrg		if test .la = "$search_ext"; then
76477ec3b29aSmrg		  found=:
764832001f49Smrg		else
76497ec3b29aSmrg		  found=false
765032001f49Smrg		fi
765132001f49Smrg		break 2
765232001f49Smrg	      fi
765332001f49Smrg	    done
765432001f49Smrg	  done
76557ec3b29aSmrg	  if $found; then
76567ec3b29aSmrg	    # deplib is a libtool library
765732001f49Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
765832001f49Smrg	    # We need to do some special things here, and not later.
76597ec3b29aSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
766032001f49Smrg	      case " $predeps $postdeps " in
766132001f49Smrg	      *" $deplib "*)
766232001f49Smrg		if func_lalib_p "$lib"; then
766332001f49Smrg		  library_names=
766432001f49Smrg		  old_library=
766532001f49Smrg		  func_source "$lib"
766632001f49Smrg		  for l in $old_library $library_names; do
76677ec3b29aSmrg		    ll=$l
766832001f49Smrg		  done
76697ec3b29aSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
76707ec3b29aSmrg		    found=false
767132001f49Smrg		    func_dirname "$lib" "" "."
76727ec3b29aSmrg		    ladir=$func_dirname_result
767332001f49Smrg		    lib=$ladir/$old_library
76747ec3b29aSmrg		    if test prog,link = "$linkmode,$pass"; then
767532001f49Smrg		      compile_deplibs="$deplib $compile_deplibs"
767632001f49Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
767732001f49Smrg		    else
767832001f49Smrg		      deplibs="$deplib $deplibs"
76797ec3b29aSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
768032001f49Smrg		    fi
768132001f49Smrg		    continue
768232001f49Smrg		  fi
768332001f49Smrg		fi
768432001f49Smrg		;;
768532001f49Smrg	      *) ;;
768632001f49Smrg	      esac
768732001f49Smrg	    fi
76887ec3b29aSmrg	  else
76897ec3b29aSmrg	    # deplib doesn't seem to be a libtool library
76907ec3b29aSmrg	    if test prog,link = "$linkmode,$pass"; then
76917ec3b29aSmrg	      compile_deplibs="$deplib $compile_deplibs"
76927ec3b29aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
76937ec3b29aSmrg	    else
76947ec3b29aSmrg	      deplibs="$deplib $deplibs"
76957ec3b29aSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
76967ec3b29aSmrg	    fi
76977ec3b29aSmrg	    continue
769832001f49Smrg	  fi
769932001f49Smrg	  ;; # -l
770032001f49Smrg	*.ltframework)
77017ec3b29aSmrg	  if test prog,link = "$linkmode,$pass"; then
770232001f49Smrg	    compile_deplibs="$deplib $compile_deplibs"
770332001f49Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
770432001f49Smrg	  else
770532001f49Smrg	    deplibs="$deplib $deplibs"
77067ec3b29aSmrg	    if test lib = "$linkmode"; then
770732001f49Smrg		case "$new_inherited_linker_flags " in
770832001f49Smrg		    *" $deplib "*) ;;
770932001f49Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
771032001f49Smrg		esac
771132001f49Smrg	    fi
771232001f49Smrg	  fi
771332001f49Smrg	  continue
771432001f49Smrg	  ;;
771532001f49Smrg	-L*)
771632001f49Smrg	  case $linkmode in
771732001f49Smrg	  lib)
771832001f49Smrg	    deplibs="$deplib $deplibs"
77197ec3b29aSmrg	    test conv = "$pass" && continue
772032001f49Smrg	    newdependency_libs="$deplib $newdependency_libs"
772132001f49Smrg	    func_stripname '-L' '' "$deplib"
772232001f49Smrg	    func_resolve_sysroot "$func_stripname_result"
772332001f49Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
772432001f49Smrg	    ;;
772532001f49Smrg	  prog)
77267ec3b29aSmrg	    if test conv = "$pass"; then
772732001f49Smrg	      deplibs="$deplib $deplibs"
772832001f49Smrg	      continue
772932001f49Smrg	    fi
77307ec3b29aSmrg	    if test scan = "$pass"; then
773132001f49Smrg	      deplibs="$deplib $deplibs"
773232001f49Smrg	    else
773332001f49Smrg	      compile_deplibs="$deplib $compile_deplibs"
773432001f49Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
773532001f49Smrg	    fi
773632001f49Smrg	    func_stripname '-L' '' "$deplib"
773732001f49Smrg	    func_resolve_sysroot "$func_stripname_result"
773832001f49Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
773932001f49Smrg	    ;;
774032001f49Smrg	  *)
77417ec3b29aSmrg	    func_warning "'-L' is ignored for archives/objects"
774232001f49Smrg	    ;;
774332001f49Smrg	  esac # linkmode
774432001f49Smrg	  continue
774532001f49Smrg	  ;; # -L
774632001f49Smrg	-R*)
77477ec3b29aSmrg	  if test link = "$pass"; then
774832001f49Smrg	    func_stripname '-R' '' "$deplib"
774932001f49Smrg	    func_resolve_sysroot "$func_stripname_result"
775032001f49Smrg	    dir=$func_resolve_sysroot_result
775132001f49Smrg	    # Make sure the xrpath contains only unique directories.
775232001f49Smrg	    case "$xrpath " in
775332001f49Smrg	    *" $dir "*) ;;
775432001f49Smrg	    *) func_append xrpath " $dir" ;;
775532001f49Smrg	    esac
775632001f49Smrg	  fi
775732001f49Smrg	  deplibs="$deplib $deplibs"
775832001f49Smrg	  continue
775932001f49Smrg	  ;;
776032001f49Smrg	*.la)
776132001f49Smrg	  func_resolve_sysroot "$deplib"
776232001f49Smrg	  lib=$func_resolve_sysroot_result
776332001f49Smrg	  ;;
776432001f49Smrg	*.$libext)
77657ec3b29aSmrg	  if test conv = "$pass"; then
776632001f49Smrg	    deplibs="$deplib $deplibs"
776732001f49Smrg	    continue
776832001f49Smrg	  fi
776932001f49Smrg	  case $linkmode in
777032001f49Smrg	  lib)
777132001f49Smrg	    # Linking convenience modules into shared libraries is allowed,
777232001f49Smrg	    # but linking other static libraries is non-portable.
777332001f49Smrg	    case " $dlpreconveniencelibs " in
777432001f49Smrg	    *" $deplib "*) ;;
777532001f49Smrg	    *)
77767ec3b29aSmrg	      valid_a_lib=false
777732001f49Smrg	      case $deplibs_check_method in
777832001f49Smrg		match_pattern*)
777932001f49Smrg		  set dummy $deplibs_check_method; shift
778032001f49Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
778132001f49Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
778232001f49Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
77837ec3b29aSmrg		    valid_a_lib=:
778432001f49Smrg		  fi
778532001f49Smrg		;;
778632001f49Smrg		pass_all)
77877ec3b29aSmrg		  valid_a_lib=:
778832001f49Smrg		;;
778932001f49Smrg	      esac
77907ec3b29aSmrg	      if $valid_a_lib; then
77917ec3b29aSmrg		echo
77927ec3b29aSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
77937ec3b29aSmrg		$ECHO "*** static library $deplib is not portable!"
77947ec3b29aSmrg		deplibs="$deplib $deplibs"
77957ec3b29aSmrg	      else
779632001f49Smrg		echo
779732001f49Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
779832001f49Smrg		echo "*** I have the capability to make that library automatically link in when"
779932001f49Smrg		echo "*** you link to this library.  But I can only do this if you have a"
780032001f49Smrg		echo "*** shared version of the library, which you do not appear to have"
780132001f49Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
780232001f49Smrg		echo "*** that it is just a static archive that I should not use here."
780332001f49Smrg	      fi
780432001f49Smrg	      ;;
780532001f49Smrg	    esac
780632001f49Smrg	    continue
780732001f49Smrg	    ;;
780832001f49Smrg	  prog)
78097ec3b29aSmrg	    if test link != "$pass"; then
781032001f49Smrg	      deplibs="$deplib $deplibs"
781132001f49Smrg	    else
781232001f49Smrg	      compile_deplibs="$deplib $compile_deplibs"
781332001f49Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
781432001f49Smrg	    fi
781532001f49Smrg	    continue
781632001f49Smrg	    ;;
781732001f49Smrg	  esac # linkmode
781832001f49Smrg	  ;; # *.$libext
781932001f49Smrg	*.lo | *.$objext)
78207ec3b29aSmrg	  if test conv = "$pass"; then
782132001f49Smrg	    deplibs="$deplib $deplibs"
78227ec3b29aSmrg	  elif test prog = "$linkmode"; then
78237ec3b29aSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
782432001f49Smrg	      # If there is no dlopen support or we're linking statically,
782532001f49Smrg	      # we need to preload.
782632001f49Smrg	      func_append newdlprefiles " $deplib"
782732001f49Smrg	      compile_deplibs="$deplib $compile_deplibs"
782832001f49Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
782932001f49Smrg	    else
783032001f49Smrg	      func_append newdlfiles " $deplib"
783132001f49Smrg	    fi
783232001f49Smrg	  fi
783332001f49Smrg	  continue
783432001f49Smrg	  ;;
783532001f49Smrg	%DEPLIBS%)
78367ec3b29aSmrg	  alldeplibs=:
783732001f49Smrg	  continue
783832001f49Smrg	  ;;
783932001f49Smrg	esac # case $deplib
784032001f49Smrg
78417ec3b29aSmrg	$found || test -f "$lib" \
78427ec3b29aSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
784332001f49Smrg
784432001f49Smrg	# Check to see that this really is a libtool archive.
784532001f49Smrg	func_lalib_unsafe_p "$lib" \
78467ec3b29aSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
784732001f49Smrg
784832001f49Smrg	func_dirname "$lib" "" "."
78497ec3b29aSmrg	ladir=$func_dirname_result
785032001f49Smrg
785132001f49Smrg	dlname=
785232001f49Smrg	dlopen=
785332001f49Smrg	dlpreopen=
785432001f49Smrg	libdir=
785532001f49Smrg	library_names=
785632001f49Smrg	old_library=
785732001f49Smrg	inherited_linker_flags=
785832001f49Smrg	# If the library was installed with an old release of libtool,
785932001f49Smrg	# it will not redefine variables installed, or shouldnotlink
786032001f49Smrg	installed=yes
786132001f49Smrg	shouldnotlink=no
786232001f49Smrg	avoidtemprpath=
786332001f49Smrg
786432001f49Smrg
786532001f49Smrg	# Read the .la file
786632001f49Smrg	func_source "$lib"
786732001f49Smrg
786832001f49Smrg	# Convert "-framework foo" to "foo.ltframework"
786932001f49Smrg	if test -n "$inherited_linker_flags"; then
787032001f49Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
787132001f49Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
787232001f49Smrg	    case " $new_inherited_linker_flags " in
787332001f49Smrg	      *" $tmp_inherited_linker_flag "*) ;;
787432001f49Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
787532001f49Smrg	    esac
787632001f49Smrg	  done
787732001f49Smrg	fi
787832001f49Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
78797ec3b29aSmrg	if test lib,link = "$linkmode,$pass" ||
78807ec3b29aSmrg	   test prog,scan = "$linkmode,$pass" ||
78817ec3b29aSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
788232001f49Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
788332001f49Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
788432001f49Smrg	fi
788532001f49Smrg
78867ec3b29aSmrg	if test conv = "$pass"; then
788732001f49Smrg	  # Only check for convenience libraries
788832001f49Smrg	  deplibs="$lib $deplibs"
788932001f49Smrg	  if test -z "$libdir"; then
789032001f49Smrg	    if test -z "$old_library"; then
78917ec3b29aSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
789232001f49Smrg	    fi
789332001f49Smrg	    # It is a libtool convenience library, so add in its objects.
789432001f49Smrg	    func_append convenience " $ladir/$objdir/$old_library"
789532001f49Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
789632001f49Smrg	    tmp_libs=
789732001f49Smrg	    for deplib in $dependency_libs; do
789832001f49Smrg	      deplibs="$deplib $deplibs"
78997ec3b29aSmrg	      if $opt_preserve_dup_deps; then
790032001f49Smrg		case "$tmp_libs " in
790132001f49Smrg		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
790232001f49Smrg		esac
790332001f49Smrg	      fi
790432001f49Smrg	      func_append tmp_libs " $deplib"
790532001f49Smrg	    done
79067ec3b29aSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
79077ec3b29aSmrg	    func_fatal_error "'$lib' is not a convenience library"
790832001f49Smrg	  fi
790932001f49Smrg	  continue
791032001f49Smrg	fi # $pass = conv
791132001f49Smrg
791232001f49Smrg
791332001f49Smrg	# Get the name of the library we link against.
791432001f49Smrg	linklib=
791532001f49Smrg	if test -n "$old_library" &&
79167ec3b29aSmrg	   { test yes = "$prefer_static_libs" ||
79177ec3b29aSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
791832001f49Smrg	  linklib=$old_library
791932001f49Smrg	else
792032001f49Smrg	  for l in $old_library $library_names; do
79217ec3b29aSmrg	    linklib=$l
792232001f49Smrg	  done
792332001f49Smrg	fi
792432001f49Smrg	if test -z "$linklib"; then
79257ec3b29aSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
792632001f49Smrg	fi
792732001f49Smrg
792832001f49Smrg	# This library was specified with -dlopen.
79297ec3b29aSmrg	if test dlopen = "$pass"; then
79307ec3b29aSmrg	  test -z "$libdir" \
79317ec3b29aSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
793232001f49Smrg	  if test -z "$dlname" ||
79337ec3b29aSmrg	     test yes != "$dlopen_support" ||
79347ec3b29aSmrg	     test no = "$build_libtool_libs"
79357ec3b29aSmrg	  then
793632001f49Smrg	    # If there is no dlname, no dlopen support or we're linking
793732001f49Smrg	    # statically, we need to preload.  We also need to preload any
793832001f49Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
793932001f49Smrg	    # bomb out in the load deplibs phase.
794032001f49Smrg	    func_append dlprefiles " $lib $dependency_libs"
794132001f49Smrg	  else
794232001f49Smrg	    func_append newdlfiles " $lib"
794332001f49Smrg	  fi
794432001f49Smrg	  continue
794532001f49Smrg	fi # $pass = dlopen
794632001f49Smrg
794732001f49Smrg	# We need an absolute path.
794832001f49Smrg	case $ladir in
79497ec3b29aSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
795032001f49Smrg	*)
795132001f49Smrg	  abs_ladir=`cd "$ladir" && pwd`
795232001f49Smrg	  if test -z "$abs_ladir"; then
79537ec3b29aSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
795432001f49Smrg	    func_warning "passing it literally to the linker, although it might fail"
79557ec3b29aSmrg	    abs_ladir=$ladir
795632001f49Smrg	  fi
795732001f49Smrg	  ;;
795832001f49Smrg	esac
795932001f49Smrg	func_basename "$lib"
79607ec3b29aSmrg	laname=$func_basename_result
796132001f49Smrg
796232001f49Smrg	# Find the relevant object directory and library name.
79637ec3b29aSmrg	if test yes = "$installed"; then
796432001f49Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
79657ec3b29aSmrg	    func_warning "library '$lib' was moved."
79667ec3b29aSmrg	    dir=$ladir
79677ec3b29aSmrg	    absdir=$abs_ladir
79687ec3b29aSmrg	    libdir=$abs_ladir
796932001f49Smrg	  else
79707ec3b29aSmrg	    dir=$lt_sysroot$libdir
79717ec3b29aSmrg	    absdir=$lt_sysroot$libdir
797232001f49Smrg	  fi
79737ec3b29aSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
797432001f49Smrg	else
797532001f49Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
79767ec3b29aSmrg	    dir=$ladir
79777ec3b29aSmrg	    absdir=$abs_ladir
797832001f49Smrg	    # Remove this search path later
797932001f49Smrg	    func_append notinst_path " $abs_ladir"
798032001f49Smrg	  else
79817ec3b29aSmrg	    dir=$ladir/$objdir
79827ec3b29aSmrg	    absdir=$abs_ladir/$objdir
798332001f49Smrg	    # Remove this search path later
798432001f49Smrg	    func_append notinst_path " $abs_ladir"
798532001f49Smrg	  fi
798632001f49Smrg	fi # $installed = yes
798732001f49Smrg	func_stripname 'lib' '.la' "$laname"
798832001f49Smrg	name=$func_stripname_result
798932001f49Smrg
799032001f49Smrg	# This library was specified with -dlpreopen.
79917ec3b29aSmrg	if test dlpreopen = "$pass"; then
79927ec3b29aSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
79937ec3b29aSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
799432001f49Smrg	  fi
79957ec3b29aSmrg	  case $host in
799632001f49Smrg	    # special handling for platforms with PE-DLLs.
799732001f49Smrg	    *cygwin* | *mingw* | *cegcc* )
799832001f49Smrg	      # Linker will automatically link against shared library if both
799932001f49Smrg	      # static and shared are present.  Therefore, ensure we extract
800032001f49Smrg	      # symbols from the import library if a shared library is present
800132001f49Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
800232001f49Smrg	      # this by putting the import library name into $newdlprefiles.
800332001f49Smrg	      # We recover the dlopen module name by 'saving' the la file
800432001f49Smrg	      # name in a special purpose variable, and (later) extracting the
800532001f49Smrg	      # dlname from the la file.
800632001f49Smrg	      if test -n "$dlname"; then
800732001f49Smrg	        func_tr_sh "$dir/$linklib"
800832001f49Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
800932001f49Smrg	        func_append newdlprefiles " $dir/$linklib"
801032001f49Smrg	      else
801132001f49Smrg	        func_append newdlprefiles " $dir/$old_library"
801232001f49Smrg	        # Keep a list of preopened convenience libraries to check
801332001f49Smrg	        # that they are being used correctly in the link pass.
801432001f49Smrg	        test -z "$libdir" && \
801532001f49Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
801632001f49Smrg	      fi
801732001f49Smrg	    ;;
801832001f49Smrg	    * )
801932001f49Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
802032001f49Smrg	      # are required to link).
802132001f49Smrg	      if test -n "$old_library"; then
802232001f49Smrg	        func_append newdlprefiles " $dir/$old_library"
802332001f49Smrg	        # Keep a list of preopened convenience libraries to check
802432001f49Smrg	        # that they are being used correctly in the link pass.
802532001f49Smrg	        test -z "$libdir" && \
802632001f49Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
802732001f49Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
802832001f49Smrg	      elif test -n "$dlname"; then
802932001f49Smrg	        func_append newdlprefiles " $dir/$dlname"
803032001f49Smrg	      else
803132001f49Smrg	        func_append newdlprefiles " $dir/$linklib"
803232001f49Smrg	      fi
803332001f49Smrg	    ;;
803432001f49Smrg	  esac
803532001f49Smrg	fi # $pass = dlpreopen
803632001f49Smrg
803732001f49Smrg	if test -z "$libdir"; then
803832001f49Smrg	  # Link the convenience library
80397ec3b29aSmrg	  if test lib = "$linkmode"; then
804032001f49Smrg	    deplibs="$dir/$old_library $deplibs"
80417ec3b29aSmrg	  elif test prog,link = "$linkmode,$pass"; then
804232001f49Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
804332001f49Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
804432001f49Smrg	  else
804532001f49Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
804632001f49Smrg	  fi
804732001f49Smrg	  continue
804832001f49Smrg	fi
804932001f49Smrg
805032001f49Smrg
80517ec3b29aSmrg	if test prog = "$linkmode" && test link != "$pass"; then
805232001f49Smrg	  func_append newlib_search_path " $ladir"
805332001f49Smrg	  deplibs="$lib $deplibs"
805432001f49Smrg
80557ec3b29aSmrg	  linkalldeplibs=false
80567ec3b29aSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
80577ec3b29aSmrg	     test no = "$build_libtool_libs"; then
80587ec3b29aSmrg	    linkalldeplibs=:
805932001f49Smrg	  fi
806032001f49Smrg
806132001f49Smrg	  tmp_libs=
806232001f49Smrg	  for deplib in $dependency_libs; do
806332001f49Smrg	    case $deplib in
806432001f49Smrg	    -L*) func_stripname '-L' '' "$deplib"
806532001f49Smrg	         func_resolve_sysroot "$func_stripname_result"
806632001f49Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
806732001f49Smrg		 ;;
806832001f49Smrg	    esac
806932001f49Smrg	    # Need to link against all dependency_libs?
80707ec3b29aSmrg	    if $linkalldeplibs; then
807132001f49Smrg	      deplibs="$deplib $deplibs"
807232001f49Smrg	    else
807332001f49Smrg	      # Need to hardcode shared library paths
807432001f49Smrg	      # or/and link against static libraries
807532001f49Smrg	      newdependency_libs="$deplib $newdependency_libs"
807632001f49Smrg	    fi
80777ec3b29aSmrg	    if $opt_preserve_dup_deps; then
807832001f49Smrg	      case "$tmp_libs " in
807932001f49Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
808032001f49Smrg	      esac
808132001f49Smrg	    fi
808232001f49Smrg	    func_append tmp_libs " $deplib"
808332001f49Smrg	  done # for deplib
808432001f49Smrg	  continue
808532001f49Smrg	fi # $linkmode = prog...
808632001f49Smrg
80877ec3b29aSmrg	if test prog,link = "$linkmode,$pass"; then
808832001f49Smrg	  if test -n "$library_names" &&
80897ec3b29aSmrg	     { { test no = "$prefer_static_libs" ||
80907ec3b29aSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
809132001f49Smrg	       test -z "$old_library"; }; then
809232001f49Smrg	    # We need to hardcode the library path
80937ec3b29aSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
809432001f49Smrg	      # Make sure the rpath contains only unique directories.
80957ec3b29aSmrg	      case $temp_rpath: in
809632001f49Smrg	      *"$absdir:"*) ;;
809732001f49Smrg	      *) func_append temp_rpath "$absdir:" ;;
809832001f49Smrg	      esac
809932001f49Smrg	    fi
810032001f49Smrg
810132001f49Smrg	    # Hardcode the library path.
810232001f49Smrg	    # Skip directories that are in the system default run-time
810332001f49Smrg	    # search path.
810432001f49Smrg	    case " $sys_lib_dlsearch_path " in
810532001f49Smrg	    *" $absdir "*) ;;
810632001f49Smrg	    *)
810732001f49Smrg	      case "$compile_rpath " in
810832001f49Smrg	      *" $absdir "*) ;;
810932001f49Smrg	      *) func_append compile_rpath " $absdir" ;;
811032001f49Smrg	      esac
811132001f49Smrg	      ;;
811232001f49Smrg	    esac
811332001f49Smrg	    case " $sys_lib_dlsearch_path " in
811432001f49Smrg	    *" $libdir "*) ;;
811532001f49Smrg	    *)
811632001f49Smrg	      case "$finalize_rpath " in
811732001f49Smrg	      *" $libdir "*) ;;
811832001f49Smrg	      *) func_append finalize_rpath " $libdir" ;;
811932001f49Smrg	      esac
812032001f49Smrg	      ;;
812132001f49Smrg	    esac
812232001f49Smrg	  fi # $linkmode,$pass = prog,link...
812332001f49Smrg
81247ec3b29aSmrg	  if $alldeplibs &&
81257ec3b29aSmrg	     { test pass_all = "$deplibs_check_method" ||
81267ec3b29aSmrg	       { test yes = "$build_libtool_libs" &&
812732001f49Smrg		 test -n "$library_names"; }; }; then
812832001f49Smrg	    # We only need to search for static libraries
812932001f49Smrg	    continue
813032001f49Smrg	  fi
813132001f49Smrg	fi
813232001f49Smrg
813332001f49Smrg	link_static=no # Whether the deplib will be linked statically
813432001f49Smrg	use_static_libs=$prefer_static_libs
81357ec3b29aSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
813632001f49Smrg	  use_static_libs=no
813732001f49Smrg	fi
813832001f49Smrg	if test -n "$library_names" &&
81397ec3b29aSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
814032001f49Smrg	  case $host in
81417ec3b29aSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
814232001f49Smrg	      # No point in relinking DLLs because paths are not encoded
814332001f49Smrg	      func_append notinst_deplibs " $lib"
814432001f49Smrg	      need_relink=no
814532001f49Smrg	    ;;
814632001f49Smrg	  *)
81477ec3b29aSmrg	    if test no = "$installed"; then
814832001f49Smrg	      func_append notinst_deplibs " $lib"
814932001f49Smrg	      need_relink=yes
815032001f49Smrg	    fi
815132001f49Smrg	    ;;
815232001f49Smrg	  esac
815332001f49Smrg	  # This is a shared library
815432001f49Smrg
815532001f49Smrg	  # Warn about portability, can't link against -module's on some
815632001f49Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
81577ec3b29aSmrg	  dlopenmodule=
815832001f49Smrg	  for dlpremoduletest in $dlprefiles; do
815932001f49Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
81607ec3b29aSmrg	      dlopenmodule=$dlpremoduletest
816132001f49Smrg	      break
816232001f49Smrg	    fi
816332001f49Smrg	  done
81647ec3b29aSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
816532001f49Smrg	    echo
81667ec3b29aSmrg	    if test prog = "$linkmode"; then
816732001f49Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
816832001f49Smrg	    else
816932001f49Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
817032001f49Smrg	    fi
817132001f49Smrg	    $ECHO "*** $linklib is not portable!"
817232001f49Smrg	  fi
81737ec3b29aSmrg	  if test lib = "$linkmode" &&
81747ec3b29aSmrg	     test yes = "$hardcode_into_libs"; then
817532001f49Smrg	    # Hardcode the library path.
817632001f49Smrg	    # Skip directories that are in the system default run-time
817732001f49Smrg	    # search path.
817832001f49Smrg	    case " $sys_lib_dlsearch_path " in
817932001f49Smrg	    *" $absdir "*) ;;
818032001f49Smrg	    *)
818132001f49Smrg	      case "$compile_rpath " in
818232001f49Smrg	      *" $absdir "*) ;;
818332001f49Smrg	      *) func_append compile_rpath " $absdir" ;;
818432001f49Smrg	      esac
818532001f49Smrg	      ;;
818632001f49Smrg	    esac
818732001f49Smrg	    case " $sys_lib_dlsearch_path " in
818832001f49Smrg	    *" $libdir "*) ;;
818932001f49Smrg	    *)
819032001f49Smrg	      case "$finalize_rpath " in
819132001f49Smrg	      *" $libdir "*) ;;
819232001f49Smrg	      *) func_append finalize_rpath " $libdir" ;;
819332001f49Smrg	      esac
819432001f49Smrg	      ;;
819532001f49Smrg	    esac
819632001f49Smrg	  fi
819732001f49Smrg
819832001f49Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
819932001f49Smrg	    # figure out the soname
820032001f49Smrg	    set dummy $library_names
820132001f49Smrg	    shift
82027ec3b29aSmrg	    realname=$1
820332001f49Smrg	    shift
820432001f49Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
820532001f49Smrg	    # use dlname if we got it. it's perfectly good, no?
820632001f49Smrg	    if test -n "$dlname"; then
82077ec3b29aSmrg	      soname=$dlname
820832001f49Smrg	    elif test -n "$soname_spec"; then
820932001f49Smrg	      # bleh windows
821032001f49Smrg	      case $host in
82117ec3b29aSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
821232001f49Smrg	        func_arith $current - $age
821332001f49Smrg		major=$func_arith_result
82147ec3b29aSmrg		versuffix=-$major
821532001f49Smrg		;;
821632001f49Smrg	      esac
821732001f49Smrg	      eval soname=\"$soname_spec\"
821832001f49Smrg	    else
82197ec3b29aSmrg	      soname=$realname
822032001f49Smrg	    fi
822132001f49Smrg
822232001f49Smrg	    # Make a new name for the extract_expsyms_cmds to use
82237ec3b29aSmrg	    soroot=$soname
822432001f49Smrg	    func_basename "$soroot"
82257ec3b29aSmrg	    soname=$func_basename_result
822632001f49Smrg	    func_stripname 'lib' '.dll' "$soname"
822732001f49Smrg	    newlib=libimp-$func_stripname_result.a
822832001f49Smrg
822932001f49Smrg	    # If the library has no export list, then create one now
823032001f49Smrg	    if test -f "$output_objdir/$soname-def"; then :
823132001f49Smrg	    else
82327ec3b29aSmrg	      func_verbose "extracting exported symbol list from '$soname'"
823332001f49Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
823432001f49Smrg	    fi
823532001f49Smrg
823632001f49Smrg	    # Create $newlib
823732001f49Smrg	    if test -f "$output_objdir/$newlib"; then :; else
82387ec3b29aSmrg	      func_verbose "generating import library for '$soname'"
823932001f49Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
824032001f49Smrg	    fi
824132001f49Smrg	    # make sure the library variables are pointing to the new library
824232001f49Smrg	    dir=$output_objdir
824332001f49Smrg	    linklib=$newlib
824432001f49Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
824532001f49Smrg
82467ec3b29aSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
824732001f49Smrg	    add_shlibpath=
824832001f49Smrg	    add_dir=
824932001f49Smrg	    add=
825032001f49Smrg	    lib_linked=yes
825132001f49Smrg	    case $hardcode_action in
825232001f49Smrg	    immediate | unsupported)
82537ec3b29aSmrg	      if test no = "$hardcode_direct"; then
82547ec3b29aSmrg		add=$dir/$linklib
825532001f49Smrg		case $host in
82567ec3b29aSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
82577ec3b29aSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
825832001f49Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
82597ec3b29aSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
826032001f49Smrg		  *-*-darwin* )
82617ec3b29aSmrg		    # if the lib is a (non-dlopened) module then we cannot
826232001f49Smrg		    # link against it, someone is ignoring the earlier warnings
826332001f49Smrg		    if /usr/bin/file -L $add 2> /dev/null |
82647ec3b29aSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
826532001f49Smrg		      if test "X$dlopenmodule" != "X$lib"; then
826632001f49Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
82677ec3b29aSmrg			if test -z "$old_library"; then
826832001f49Smrg			  echo
826932001f49Smrg			  echo "*** And there doesn't seem to be a static archive available"
827032001f49Smrg			  echo "*** The link will probably fail, sorry"
827132001f49Smrg			else
82727ec3b29aSmrg			  add=$dir/$old_library
827332001f49Smrg			fi
827432001f49Smrg		      elif test -n "$old_library"; then
82757ec3b29aSmrg			add=$dir/$old_library
827632001f49Smrg		      fi
827732001f49Smrg		    fi
827832001f49Smrg		esac
82797ec3b29aSmrg	      elif test no = "$hardcode_minus_L"; then
828032001f49Smrg		case $host in
82817ec3b29aSmrg		*-*-sunos*) add_shlibpath=$dir ;;
828232001f49Smrg		esac
82837ec3b29aSmrg		add_dir=-L$dir
82847ec3b29aSmrg		add=-l$name
82857ec3b29aSmrg	      elif test no = "$hardcode_shlibpath_var"; then
82867ec3b29aSmrg		add_shlibpath=$dir
82877ec3b29aSmrg		add=-l$name
828832001f49Smrg	      else
828932001f49Smrg		lib_linked=no
829032001f49Smrg	      fi
829132001f49Smrg	      ;;
829232001f49Smrg	    relink)
82937ec3b29aSmrg	      if test yes = "$hardcode_direct" &&
82947ec3b29aSmrg	         test no = "$hardcode_direct_absolute"; then
82957ec3b29aSmrg		add=$dir/$linklib
82967ec3b29aSmrg	      elif test yes = "$hardcode_minus_L"; then
82977ec3b29aSmrg		add_dir=-L$absdir
829832001f49Smrg		# Try looking first in the location we're being installed to.
829932001f49Smrg		if test -n "$inst_prefix_dir"; then
830032001f49Smrg		  case $libdir in
830132001f49Smrg		    [\\/]*)
830232001f49Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
830332001f49Smrg		      ;;
830432001f49Smrg		  esac
830532001f49Smrg		fi
83067ec3b29aSmrg		add=-l$name
83077ec3b29aSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
83087ec3b29aSmrg		add_shlibpath=$dir
83097ec3b29aSmrg		add=-l$name
831032001f49Smrg	      else
831132001f49Smrg		lib_linked=no
831232001f49Smrg	      fi
831332001f49Smrg	      ;;
831432001f49Smrg	    *) lib_linked=no ;;
831532001f49Smrg	    esac
831632001f49Smrg
83177ec3b29aSmrg	    if test yes != "$lib_linked"; then
831832001f49Smrg	      func_fatal_configuration "unsupported hardcode properties"
831932001f49Smrg	    fi
832032001f49Smrg
832132001f49Smrg	    if test -n "$add_shlibpath"; then
832232001f49Smrg	      case :$compile_shlibpath: in
832332001f49Smrg	      *":$add_shlibpath:"*) ;;
832432001f49Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
832532001f49Smrg	      esac
832632001f49Smrg	    fi
83277ec3b29aSmrg	    if test prog = "$linkmode"; then
832832001f49Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
832932001f49Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
833032001f49Smrg	    else
833132001f49Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
833232001f49Smrg	      test -n "$add" && deplibs="$add $deplibs"
83337ec3b29aSmrg	      if test yes != "$hardcode_direct" &&
83347ec3b29aSmrg		 test yes != "$hardcode_minus_L" &&
83357ec3b29aSmrg		 test yes = "$hardcode_shlibpath_var"; then
833632001f49Smrg		case :$finalize_shlibpath: in
833732001f49Smrg		*":$libdir:"*) ;;
833832001f49Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
833932001f49Smrg		esac
834032001f49Smrg	      fi
834132001f49Smrg	    fi
834232001f49Smrg	  fi
834332001f49Smrg
83447ec3b29aSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
834532001f49Smrg	    add_shlibpath=
834632001f49Smrg	    add_dir=
834732001f49Smrg	    add=
834832001f49Smrg	    # Finalize command for both is simple: just hardcode it.
83497ec3b29aSmrg	    if test yes = "$hardcode_direct" &&
83507ec3b29aSmrg	       test no = "$hardcode_direct_absolute"; then
83517ec3b29aSmrg	      add=$libdir/$linklib
83527ec3b29aSmrg	    elif test yes = "$hardcode_minus_L"; then
83537ec3b29aSmrg	      add_dir=-L$libdir
83547ec3b29aSmrg	      add=-l$name
83557ec3b29aSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
835632001f49Smrg	      case :$finalize_shlibpath: in
835732001f49Smrg	      *":$libdir:"*) ;;
835832001f49Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
835932001f49Smrg	      esac
83607ec3b29aSmrg	      add=-l$name
83617ec3b29aSmrg	    elif test yes = "$hardcode_automatic"; then
836232001f49Smrg	      if test -n "$inst_prefix_dir" &&
83637ec3b29aSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
83647ec3b29aSmrg		add=$inst_prefix_dir$libdir/$linklib
836532001f49Smrg	      else
83667ec3b29aSmrg		add=$libdir/$linklib
836732001f49Smrg	      fi
836832001f49Smrg	    else
836932001f49Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
83707ec3b29aSmrg	      add_dir=-L$libdir
837132001f49Smrg	      # Try looking first in the location we're being installed to.
837232001f49Smrg	      if test -n "$inst_prefix_dir"; then
837332001f49Smrg		case $libdir in
837432001f49Smrg		  [\\/]*)
837532001f49Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
837632001f49Smrg		    ;;
837732001f49Smrg		esac
837832001f49Smrg	      fi
83797ec3b29aSmrg	      add=-l$name
838032001f49Smrg	    fi
838132001f49Smrg
83827ec3b29aSmrg	    if test prog = "$linkmode"; then
838332001f49Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
838432001f49Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
838532001f49Smrg	    else
838632001f49Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
838732001f49Smrg	      test -n "$add" && deplibs="$add $deplibs"
838832001f49Smrg	    fi
838932001f49Smrg	  fi
83907ec3b29aSmrg	elif test prog = "$linkmode"; then
839132001f49Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
839232001f49Smrg	  # is not unsupported.  This is valid on all known static and
839332001f49Smrg	  # shared platforms.
83947ec3b29aSmrg	  if test unsupported != "$hardcode_direct"; then
83957ec3b29aSmrg	    test -n "$old_library" && linklib=$old_library
839632001f49Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
839732001f49Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
839832001f49Smrg	  else
839932001f49Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
840032001f49Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
840132001f49Smrg	  fi
84027ec3b29aSmrg	elif test yes = "$build_libtool_libs"; then
840332001f49Smrg	  # Not a shared library
84047ec3b29aSmrg	  if test pass_all != "$deplibs_check_method"; then
840532001f49Smrg	    # We're trying link a shared library against a static one
840632001f49Smrg	    # but the system doesn't support it.
840732001f49Smrg
840832001f49Smrg	    # Just print a warning and add the library to dependency_libs so
840932001f49Smrg	    # that the program can be linked against the static library.
841032001f49Smrg	    echo
84117ec3b29aSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
841232001f49Smrg	    echo "*** I have the capability to make that library automatically link in when"
841332001f49Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
841432001f49Smrg	    echo "*** shared version of the library, which you do not appear to have."
84157ec3b29aSmrg	    if test yes = "$module"; then
841632001f49Smrg	      echo "*** But as you try to build a module library, libtool will still create "
841732001f49Smrg	      echo "*** a static module, that should work as long as the dlopening application"
841832001f49Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
841932001f49Smrg	      if test -z "$global_symbol_pipe"; then
842032001f49Smrg		echo
842132001f49Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
84227ec3b29aSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
842332001f49Smrg		echo "*** not find such a program.  So, this module is probably useless."
84247ec3b29aSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
842532001f49Smrg	      fi
84267ec3b29aSmrg	      if test no = "$build_old_libs"; then
842732001f49Smrg		build_libtool_libs=module
842832001f49Smrg		build_old_libs=yes
842932001f49Smrg	      else
843032001f49Smrg		build_libtool_libs=no
843132001f49Smrg	      fi
843232001f49Smrg	    fi
843332001f49Smrg	  else
843432001f49Smrg	    deplibs="$dir/$old_library $deplibs"
843532001f49Smrg	    link_static=yes
843632001f49Smrg	  fi
843732001f49Smrg	fi # link shared/static library?
843832001f49Smrg
84397ec3b29aSmrg	if test lib = "$linkmode"; then
844032001f49Smrg	  if test -n "$dependency_libs" &&
84417ec3b29aSmrg	     { test yes != "$hardcode_into_libs" ||
84427ec3b29aSmrg	       test yes = "$build_old_libs" ||
84437ec3b29aSmrg	       test yes = "$link_static"; }; then
844432001f49Smrg	    # Extract -R from dependency_libs
844532001f49Smrg	    temp_deplibs=
844632001f49Smrg	    for libdir in $dependency_libs; do
844732001f49Smrg	      case $libdir in
844832001f49Smrg	      -R*) func_stripname '-R' '' "$libdir"
844932001f49Smrg	           temp_xrpath=$func_stripname_result
845032001f49Smrg		   case " $xrpath " in
845132001f49Smrg		   *" $temp_xrpath "*) ;;
845232001f49Smrg		   *) func_append xrpath " $temp_xrpath";;
845332001f49Smrg		   esac;;
845432001f49Smrg	      *) func_append temp_deplibs " $libdir";;
845532001f49Smrg	      esac
845632001f49Smrg	    done
84577ec3b29aSmrg	    dependency_libs=$temp_deplibs
845832001f49Smrg	  fi
845932001f49Smrg
846032001f49Smrg	  func_append newlib_search_path " $absdir"
846132001f49Smrg	  # Link against this library
84627ec3b29aSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
846332001f49Smrg	  # ... and its dependency_libs
846432001f49Smrg	  tmp_libs=
846532001f49Smrg	  for deplib in $dependency_libs; do
846632001f49Smrg	    newdependency_libs="$deplib $newdependency_libs"
846732001f49Smrg	    case $deplib in
846832001f49Smrg              -L*) func_stripname '-L' '' "$deplib"
846932001f49Smrg                   func_resolve_sysroot "$func_stripname_result";;
847032001f49Smrg              *) func_resolve_sysroot "$deplib" ;;
847132001f49Smrg            esac
84727ec3b29aSmrg	    if $opt_preserve_dup_deps; then
847332001f49Smrg	      case "$tmp_libs " in
847432001f49Smrg	      *" $func_resolve_sysroot_result "*)
847532001f49Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
847632001f49Smrg	      esac
847732001f49Smrg	    fi
847832001f49Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
847932001f49Smrg	  done
848032001f49Smrg
84817ec3b29aSmrg	  if test no != "$link_all_deplibs"; then
848232001f49Smrg	    # Add the search paths of all dependency libraries
848332001f49Smrg	    for deplib in $dependency_libs; do
848432001f49Smrg	      path=
848532001f49Smrg	      case $deplib in
84867ec3b29aSmrg	      -L*) path=$deplib ;;
848732001f49Smrg	      *.la)
848832001f49Smrg	        func_resolve_sysroot "$deplib"
848932001f49Smrg	        deplib=$func_resolve_sysroot_result
849032001f49Smrg	        func_dirname "$deplib" "" "."
849132001f49Smrg		dir=$func_dirname_result
849232001f49Smrg		# We need an absolute path.
849332001f49Smrg		case $dir in
84947ec3b29aSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
849532001f49Smrg		*)
849632001f49Smrg		  absdir=`cd "$dir" && pwd`
849732001f49Smrg		  if test -z "$absdir"; then
84987ec3b29aSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
84997ec3b29aSmrg		    absdir=$dir
850032001f49Smrg		  fi
850132001f49Smrg		  ;;
850232001f49Smrg		esac
850332001f49Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
850432001f49Smrg		case $host in
850532001f49Smrg		*-*-darwin*)
850632001f49Smrg		  depdepl=
85077ec3b29aSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
85087ec3b29aSmrg		  if test -n "$deplibrary_names"; then
85097ec3b29aSmrg		    for tmp in $deplibrary_names; do
851032001f49Smrg		      depdepl=$tmp
851132001f49Smrg		    done
85127ec3b29aSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
85137ec3b29aSmrg		      depdepl=$absdir/$objdir/$depdepl
85147ec3b29aSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
851532001f49Smrg                      if test -z "$darwin_install_name"; then
85167ec3b29aSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
851732001f49Smrg                      fi
85187ec3b29aSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
85197ec3b29aSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
852032001f49Smrg		      path=
852132001f49Smrg		    fi
852232001f49Smrg		  fi
852332001f49Smrg		  ;;
852432001f49Smrg		*)
85257ec3b29aSmrg		  path=-L$absdir/$objdir
852632001f49Smrg		  ;;
852732001f49Smrg		esac
852832001f49Smrg		else
85297ec3b29aSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
853032001f49Smrg		  test -z "$libdir" && \
85317ec3b29aSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
853232001f49Smrg		  test "$absdir" != "$libdir" && \
85337ec3b29aSmrg		    func_warning "'$deplib' seems to be moved"
853432001f49Smrg
85357ec3b29aSmrg		  path=-L$absdir
853632001f49Smrg		fi
853732001f49Smrg		;;
853832001f49Smrg	      esac
853932001f49Smrg	      case " $deplibs " in
854032001f49Smrg	      *" $path "*) ;;
854132001f49Smrg	      *) deplibs="$path $deplibs" ;;
854232001f49Smrg	      esac
854332001f49Smrg	    done
854432001f49Smrg	  fi # link_all_deplibs != no
854532001f49Smrg	fi # linkmode = lib
854632001f49Smrg      done # for deplib in $libs
85477ec3b29aSmrg      if test link = "$pass"; then
85487ec3b29aSmrg	if test prog = "$linkmode"; then
854932001f49Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
855032001f49Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
855132001f49Smrg	else
855232001f49Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
855332001f49Smrg	fi
855432001f49Smrg      fi
85557ec3b29aSmrg      dependency_libs=$newdependency_libs
85567ec3b29aSmrg      if test dlpreopen = "$pass"; then
855732001f49Smrg	# Link the dlpreopened libraries before other libraries
855832001f49Smrg	for deplib in $save_deplibs; do
855932001f49Smrg	  deplibs="$deplib $deplibs"
856032001f49Smrg	done
856132001f49Smrg      fi
85627ec3b29aSmrg      if test dlopen != "$pass"; then
85637ec3b29aSmrg	test conv = "$pass" || {
856432001f49Smrg	  # Make sure lib_search_path contains only unique directories.
856532001f49Smrg	  lib_search_path=
856632001f49Smrg	  for dir in $newlib_search_path; do
856732001f49Smrg	    case "$lib_search_path " in
856832001f49Smrg	    *" $dir "*) ;;
856932001f49Smrg	    *) func_append lib_search_path " $dir" ;;
857032001f49Smrg	    esac
857132001f49Smrg	  done
857232001f49Smrg	  newlib_search_path=
85737ec3b29aSmrg	}
857432001f49Smrg
85757ec3b29aSmrg	if test prog,link = "$linkmode,$pass"; then
857632001f49Smrg	  vars="compile_deplibs finalize_deplibs"
85777ec3b29aSmrg	else
85787ec3b29aSmrg	  vars=deplibs
857932001f49Smrg	fi
858032001f49Smrg	for var in $vars dependency_libs; do
858132001f49Smrg	  # Add libraries to $var in reverse order
858232001f49Smrg	  eval tmp_libs=\"\$$var\"
858332001f49Smrg	  new_libs=
858432001f49Smrg	  for deplib in $tmp_libs; do
858532001f49Smrg	    # FIXME: Pedantically, this is the right thing to do, so
858632001f49Smrg	    #        that some nasty dependency loop isn't accidentally
858732001f49Smrg	    #        broken:
858832001f49Smrg	    #new_libs="$deplib $new_libs"
858932001f49Smrg	    # Pragmatically, this seems to cause very few problems in
859032001f49Smrg	    # practice:
859132001f49Smrg	    case $deplib in
859232001f49Smrg	    -L*) new_libs="$deplib $new_libs" ;;
859332001f49Smrg	    -R*) ;;
859432001f49Smrg	    *)
859532001f49Smrg	      # And here is the reason: when a library appears more
859632001f49Smrg	      # than once as an explicit dependence of a library, or
859732001f49Smrg	      # is implicitly linked in more than once by the
859832001f49Smrg	      # compiler, it is considered special, and multiple
859932001f49Smrg	      # occurrences thereof are not removed.  Compare this
860032001f49Smrg	      # with having the same library being listed as a
860132001f49Smrg	      # dependency of multiple other libraries: in this case,
860232001f49Smrg	      # we know (pedantically, we assume) the library does not
860332001f49Smrg	      # need to be listed more than once, so we keep only the
860432001f49Smrg	      # last copy.  This is not always right, but it is rare
860532001f49Smrg	      # enough that we require users that really mean to play
860632001f49Smrg	      # such unportable linking tricks to link the library
860732001f49Smrg	      # using -Wl,-lname, so that libtool does not consider it
860832001f49Smrg	      # for duplicate removal.
860932001f49Smrg	      case " $specialdeplibs " in
861032001f49Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
861132001f49Smrg	      *)
861232001f49Smrg		case " $new_libs " in
861332001f49Smrg		*" $deplib "*) ;;
861432001f49Smrg		*) new_libs="$deplib $new_libs" ;;
861532001f49Smrg		esac
861632001f49Smrg		;;
861732001f49Smrg	      esac
861832001f49Smrg	      ;;
861932001f49Smrg	    esac
862032001f49Smrg	  done
862132001f49Smrg	  tmp_libs=
862232001f49Smrg	  for deplib in $new_libs; do
862332001f49Smrg	    case $deplib in
862432001f49Smrg	    -L*)
862532001f49Smrg	      case " $tmp_libs " in
862632001f49Smrg	      *" $deplib "*) ;;
862732001f49Smrg	      *) func_append tmp_libs " $deplib" ;;
862832001f49Smrg	      esac
862932001f49Smrg	      ;;
863032001f49Smrg	    *) func_append tmp_libs " $deplib" ;;
863132001f49Smrg	    esac
863232001f49Smrg	  done
863332001f49Smrg	  eval $var=\"$tmp_libs\"
863432001f49Smrg	done # for var
863532001f49Smrg      fi
86367ec3b29aSmrg
86377ec3b29aSmrg      # Add Sun CC postdeps if required:
86387ec3b29aSmrg      test CXX = "$tagname" && {
86397ec3b29aSmrg        case $host_os in
86407ec3b29aSmrg        linux*)
86417ec3b29aSmrg          case `$CC -V 2>&1 | sed 5q` in
86427ec3b29aSmrg          *Sun\ C*) # Sun C++ 5.9
86437ec3b29aSmrg            func_suncc_cstd_abi
86447ec3b29aSmrg
86457ec3b29aSmrg            if test no != "$suncc_use_cstd_abi"; then
86467ec3b29aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
86477ec3b29aSmrg            fi
86487ec3b29aSmrg            ;;
86497ec3b29aSmrg          esac
86507ec3b29aSmrg          ;;
86517ec3b29aSmrg
86527ec3b29aSmrg        solaris*)
86537ec3b29aSmrg          func_cc_basename "$CC"
86547ec3b29aSmrg          case $func_cc_basename_result in
86557ec3b29aSmrg          CC* | sunCC*)
86567ec3b29aSmrg            func_suncc_cstd_abi
86577ec3b29aSmrg
86587ec3b29aSmrg            if test no != "$suncc_use_cstd_abi"; then
86597ec3b29aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
86607ec3b29aSmrg            fi
86617ec3b29aSmrg            ;;
86627ec3b29aSmrg          esac
86637ec3b29aSmrg          ;;
86647ec3b29aSmrg        esac
86657ec3b29aSmrg      }
86667ec3b29aSmrg
866732001f49Smrg      # Last step: remove runtime libs from dependency_libs
866832001f49Smrg      # (they stay in deplibs)
866932001f49Smrg      tmp_libs=
86707ec3b29aSmrg      for i in $dependency_libs; do
867132001f49Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
867232001f49Smrg	*" $i "*)
86737ec3b29aSmrg	  i=
867432001f49Smrg	  ;;
867532001f49Smrg	esac
86767ec3b29aSmrg	if test -n "$i"; then
867732001f49Smrg	  func_append tmp_libs " $i"
867832001f49Smrg	fi
867932001f49Smrg      done
868032001f49Smrg      dependency_libs=$tmp_libs
868132001f49Smrg    done # for pass
86827ec3b29aSmrg    if test prog = "$linkmode"; then
86837ec3b29aSmrg      dlfiles=$newdlfiles
868432001f49Smrg    fi
86857ec3b29aSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
86867ec3b29aSmrg      dlprefiles=$newdlprefiles
868732001f49Smrg    fi
868832001f49Smrg
868932001f49Smrg    case $linkmode in
869032001f49Smrg    oldlib)
86917ec3b29aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
86927ec3b29aSmrg	func_warning "'-dlopen' is ignored for archives"
869332001f49Smrg      fi
869432001f49Smrg
869532001f49Smrg      case " $deplibs" in
869632001f49Smrg      *\ -l* | *\ -L*)
86977ec3b29aSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
869832001f49Smrg      esac
869932001f49Smrg
870032001f49Smrg      test -n "$rpath" && \
87017ec3b29aSmrg	func_warning "'-rpath' is ignored for archives"
870232001f49Smrg
870332001f49Smrg      test -n "$xrpath" && \
87047ec3b29aSmrg	func_warning "'-R' is ignored for archives"
870532001f49Smrg
870632001f49Smrg      test -n "$vinfo" && \
87077ec3b29aSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
870832001f49Smrg
870932001f49Smrg      test -n "$release" && \
87107ec3b29aSmrg	func_warning "'-release' is ignored for archives"
871132001f49Smrg
871232001f49Smrg      test -n "$export_symbols$export_symbols_regex" && \
87137ec3b29aSmrg	func_warning "'-export-symbols' is ignored for archives"
871432001f49Smrg
871532001f49Smrg      # Now set the variables for building old libraries.
871632001f49Smrg      build_libtool_libs=no
87177ec3b29aSmrg      oldlibs=$output
871832001f49Smrg      func_append objs "$old_deplibs"
871932001f49Smrg      ;;
872032001f49Smrg
872132001f49Smrg    lib)
87227ec3b29aSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
872332001f49Smrg      case $outputname in
872432001f49Smrg      lib*)
872532001f49Smrg	func_stripname 'lib' '.la' "$outputname"
872632001f49Smrg	name=$func_stripname_result
872732001f49Smrg	eval shared_ext=\"$shrext_cmds\"
872832001f49Smrg	eval libname=\"$libname_spec\"
872932001f49Smrg	;;
873032001f49Smrg      *)
87317ec3b29aSmrg	test no = "$module" \
87327ec3b29aSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
873332001f49Smrg
87347ec3b29aSmrg	if test no != "$need_lib_prefix"; then
873532001f49Smrg	  # Add the "lib" prefix for modules if required
873632001f49Smrg	  func_stripname '' '.la' "$outputname"
873732001f49Smrg	  name=$func_stripname_result
873832001f49Smrg	  eval shared_ext=\"$shrext_cmds\"
873932001f49Smrg	  eval libname=\"$libname_spec\"
874032001f49Smrg	else
874132001f49Smrg	  func_stripname '' '.la' "$outputname"
874232001f49Smrg	  libname=$func_stripname_result
874332001f49Smrg	fi
874432001f49Smrg	;;
874532001f49Smrg      esac
874632001f49Smrg
874732001f49Smrg      if test -n "$objs"; then
87487ec3b29aSmrg	if test pass_all != "$deplibs_check_method"; then
87497ec3b29aSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
875032001f49Smrg	else
875132001f49Smrg	  echo
875232001f49Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
875332001f49Smrg	  $ECHO "*** objects $objs is not portable!"
875432001f49Smrg	  func_append libobjs " $objs"
875532001f49Smrg	fi
875632001f49Smrg      fi
875732001f49Smrg
87587ec3b29aSmrg      test no = "$dlself" \
87597ec3b29aSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
876032001f49Smrg
876132001f49Smrg      set dummy $rpath
876232001f49Smrg      shift
87637ec3b29aSmrg      test 1 -lt "$#" \
87647ec3b29aSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
876532001f49Smrg
87667ec3b29aSmrg      install_libdir=$1
876732001f49Smrg
876832001f49Smrg      oldlibs=
876932001f49Smrg      if test -z "$rpath"; then
87707ec3b29aSmrg	if test yes = "$build_libtool_libs"; then
877132001f49Smrg	  # Building a libtool convenience library.
87727ec3b29aSmrg	  # Some compilers have problems with a '.al' extension so
877332001f49Smrg	  # convenience libraries should have the same extension an
877432001f49Smrg	  # archive normally would.
877532001f49Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
877632001f49Smrg	  build_libtool_libs=convenience
877732001f49Smrg	  build_old_libs=yes
877832001f49Smrg	fi
877932001f49Smrg
878032001f49Smrg	test -n "$vinfo" && \
87817ec3b29aSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
878232001f49Smrg
878332001f49Smrg	test -n "$release" && \
87847ec3b29aSmrg	  func_warning "'-release' is ignored for convenience libraries"
878532001f49Smrg      else
878632001f49Smrg
878732001f49Smrg	# Parse the version information argument.
87887ec3b29aSmrg	save_ifs=$IFS; IFS=:
878932001f49Smrg	set dummy $vinfo 0 0 0
879032001f49Smrg	shift
87917ec3b29aSmrg	IFS=$save_ifs
879232001f49Smrg
879332001f49Smrg	test -n "$7" && \
87947ec3b29aSmrg	  func_fatal_help "too many parameters to '-version-info'"
879532001f49Smrg
879632001f49Smrg	# convert absolute version numbers to libtool ages
879732001f49Smrg	# this retains compatibility with .la files and attempts
879832001f49Smrg	# to make the code below a bit more comprehensible
879932001f49Smrg
880032001f49Smrg	case $vinfo_number in
880132001f49Smrg	yes)
88027ec3b29aSmrg	  number_major=$1
88037ec3b29aSmrg	  number_minor=$2
88047ec3b29aSmrg	  number_revision=$3
880532001f49Smrg	  #
880632001f49Smrg	  # There are really only two kinds -- those that
880732001f49Smrg	  # use the current revision as the major version
880832001f49Smrg	  # and those that subtract age and use age as
880932001f49Smrg	  # a minor version.  But, then there is irix
88107ec3b29aSmrg	  # that has an extra 1 added just for fun
881132001f49Smrg	  #
881232001f49Smrg	  case $version_type in
881332001f49Smrg	  # correct linux to gnu/linux during the next big refactor
88147ec3b29aSmrg	  darwin|freebsd-elf|linux|osf|windows|none)
881532001f49Smrg	    func_arith $number_major + $number_minor
881632001f49Smrg	    current=$func_arith_result
88177ec3b29aSmrg	    age=$number_minor
88187ec3b29aSmrg	    revision=$number_revision
881932001f49Smrg	    ;;
88207ec3b29aSmrg	  freebsd-aout|qnx|sunos)
88217ec3b29aSmrg	    current=$number_major
88227ec3b29aSmrg	    revision=$number_minor
88237ec3b29aSmrg	    age=0
882432001f49Smrg	    ;;
882532001f49Smrg	  irix|nonstopux)
882632001f49Smrg	    func_arith $number_major + $number_minor
882732001f49Smrg	    current=$func_arith_result
88287ec3b29aSmrg	    age=$number_minor
88297ec3b29aSmrg	    revision=$number_minor
883032001f49Smrg	    lt_irix_increment=no
883132001f49Smrg	    ;;
883232001f49Smrg	  *)
88337ec3b29aSmrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
883432001f49Smrg	    ;;
883532001f49Smrg	  esac
883632001f49Smrg	  ;;
883732001f49Smrg	no)
88387ec3b29aSmrg	  current=$1
88397ec3b29aSmrg	  revision=$2
88407ec3b29aSmrg	  age=$3
884132001f49Smrg	  ;;
884232001f49Smrg	esac
884332001f49Smrg
884432001f49Smrg	# Check that each of the things are valid numbers.
884532001f49Smrg	case $current in
884632001f49Smrg	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
884732001f49Smrg	*)
88487ec3b29aSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
88497ec3b29aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
885032001f49Smrg	  ;;
885132001f49Smrg	esac
885232001f49Smrg
885332001f49Smrg	case $revision in
885432001f49Smrg	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
885532001f49Smrg	*)
88567ec3b29aSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
88577ec3b29aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
885832001f49Smrg	  ;;
885932001f49Smrg	esac
886032001f49Smrg
886132001f49Smrg	case $age in
886232001f49Smrg	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
886332001f49Smrg	*)
88647ec3b29aSmrg	  func_error "AGE '$age' must be a nonnegative integer"
88657ec3b29aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
886632001f49Smrg	  ;;
886732001f49Smrg	esac
886832001f49Smrg
886932001f49Smrg	if test "$age" -gt "$current"; then
88707ec3b29aSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
88717ec3b29aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
887232001f49Smrg	fi
887332001f49Smrg
887432001f49Smrg	# Calculate the version variables.
887532001f49Smrg	major=
887632001f49Smrg	versuffix=
887732001f49Smrg	verstring=
887832001f49Smrg	case $version_type in
887932001f49Smrg	none) ;;
888032001f49Smrg
888132001f49Smrg	darwin)
888232001f49Smrg	  # Like Linux, but with the current version available in
888332001f49Smrg	  # verstring for coding it into the library header
888432001f49Smrg	  func_arith $current - $age
888532001f49Smrg	  major=.$func_arith_result
88867ec3b29aSmrg	  versuffix=$major.$age.$revision
888732001f49Smrg	  # Darwin ld doesn't like 0 for these options...
888832001f49Smrg	  func_arith $current + 1
888932001f49Smrg	  minor_current=$func_arith_result
88907ec3b29aSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
889132001f49Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
88927ec3b29aSmrg          # On Darwin other compilers
88937ec3b29aSmrg          case $CC in
88947ec3b29aSmrg              nagfor*)
88957ec3b29aSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
88967ec3b29aSmrg                  ;;
88977ec3b29aSmrg              *)
88987ec3b29aSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
88997ec3b29aSmrg                  ;;
89007ec3b29aSmrg          esac
890132001f49Smrg	  ;;
890232001f49Smrg
890332001f49Smrg	freebsd-aout)
89047ec3b29aSmrg	  major=.$current
89057ec3b29aSmrg	  versuffix=.$current.$revision
890632001f49Smrg	  ;;
890732001f49Smrg
890832001f49Smrg	freebsd-elf)
89097ec3b29aSmrg	  func_arith $current - $age
89107ec3b29aSmrg	  major=.$func_arith_result
89117ec3b29aSmrg	  versuffix=$major.$age.$revision
891232001f49Smrg	  ;;
891332001f49Smrg
891432001f49Smrg	irix | nonstopux)
89157ec3b29aSmrg	  if test no = "$lt_irix_increment"; then
891632001f49Smrg	    func_arith $current - $age
891732001f49Smrg	  else
891832001f49Smrg	    func_arith $current - $age + 1
891932001f49Smrg	  fi
892032001f49Smrg	  major=$func_arith_result
892132001f49Smrg
892232001f49Smrg	  case $version_type in
892332001f49Smrg	    nonstopux) verstring_prefix=nonstopux ;;
892432001f49Smrg	    *)         verstring_prefix=sgi ;;
892532001f49Smrg	  esac
89267ec3b29aSmrg	  verstring=$verstring_prefix$major.$revision
892732001f49Smrg
892832001f49Smrg	  # Add in all the interfaces that we are compatible with.
892932001f49Smrg	  loop=$revision
89307ec3b29aSmrg	  while test 0 -ne "$loop"; do
893132001f49Smrg	    func_arith $revision - $loop
893232001f49Smrg	    iface=$func_arith_result
893332001f49Smrg	    func_arith $loop - 1
893432001f49Smrg	    loop=$func_arith_result
89357ec3b29aSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
893632001f49Smrg	  done
893732001f49Smrg
89387ec3b29aSmrg	  # Before this point, $major must not contain '.'.
893932001f49Smrg	  major=.$major
89407ec3b29aSmrg	  versuffix=$major.$revision
894132001f49Smrg	  ;;
894232001f49Smrg
894332001f49Smrg	linux) # correct to gnu/linux during the next big refactor
894432001f49Smrg	  func_arith $current - $age
894532001f49Smrg	  major=.$func_arith_result
89467ec3b29aSmrg	  versuffix=$major.$age.$revision
894732001f49Smrg	  ;;
894832001f49Smrg
894932001f49Smrg	osf)
895032001f49Smrg	  func_arith $current - $age
895132001f49Smrg	  major=.$func_arith_result
89527ec3b29aSmrg	  versuffix=.$current.$age.$revision
89537ec3b29aSmrg	  verstring=$current.$age.$revision
895432001f49Smrg
895532001f49Smrg	  # Add in all the interfaces that we are compatible with.
895632001f49Smrg	  loop=$age
89577ec3b29aSmrg	  while test 0 -ne "$loop"; do
895832001f49Smrg	    func_arith $current - $loop
895932001f49Smrg	    iface=$func_arith_result
896032001f49Smrg	    func_arith $loop - 1
896132001f49Smrg	    loop=$func_arith_result
89627ec3b29aSmrg	    verstring=$verstring:$iface.0
896332001f49Smrg	  done
896432001f49Smrg
896532001f49Smrg	  # Make executables depend on our current version.
89667ec3b29aSmrg	  func_append verstring ":$current.0"
896732001f49Smrg	  ;;
896832001f49Smrg
896932001f49Smrg	qnx)
89707ec3b29aSmrg	  major=.$current
89717ec3b29aSmrg	  versuffix=.$current
89727ec3b29aSmrg	  ;;
89737ec3b29aSmrg
89747ec3b29aSmrg	sco)
89757ec3b29aSmrg	  major=.$current
89767ec3b29aSmrg	  versuffix=.$current
897732001f49Smrg	  ;;
897832001f49Smrg
897932001f49Smrg	sunos)
89807ec3b29aSmrg	  major=.$current
89817ec3b29aSmrg	  versuffix=.$current.$revision
898232001f49Smrg	  ;;
898332001f49Smrg
898432001f49Smrg	windows)
898532001f49Smrg	  # Use '-' rather than '.', since we only want one
89867ec3b29aSmrg	  # extension on DOS 8.3 file systems.
898732001f49Smrg	  func_arith $current - $age
898832001f49Smrg	  major=$func_arith_result
89897ec3b29aSmrg	  versuffix=-$major
899032001f49Smrg	  ;;
899132001f49Smrg
899232001f49Smrg	*)
89937ec3b29aSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
899432001f49Smrg	  ;;
899532001f49Smrg	esac
899632001f49Smrg
899732001f49Smrg	# Clear the version info if we defaulted, and they specified a release.
899832001f49Smrg	if test -z "$vinfo" && test -n "$release"; then
899932001f49Smrg	  major=
900032001f49Smrg	  case $version_type in
900132001f49Smrg	  darwin)
900232001f49Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
900332001f49Smrg	    # problems, so we reset it completely
900432001f49Smrg	    verstring=
900532001f49Smrg	    ;;
900632001f49Smrg	  *)
90077ec3b29aSmrg	    verstring=0.0
900832001f49Smrg	    ;;
900932001f49Smrg	  esac
90107ec3b29aSmrg	  if test no = "$need_version"; then
901132001f49Smrg	    versuffix=
901232001f49Smrg	  else
90137ec3b29aSmrg	    versuffix=.0.0
901432001f49Smrg	  fi
901532001f49Smrg	fi
901632001f49Smrg
901732001f49Smrg	# Remove version info from name if versioning should be avoided
90187ec3b29aSmrg	if test yes,no = "$avoid_version,$need_version"; then
901932001f49Smrg	  major=
902032001f49Smrg	  versuffix=
90217ec3b29aSmrg	  verstring=
902232001f49Smrg	fi
902332001f49Smrg
902432001f49Smrg	# Check to see if the archive will have undefined symbols.
90257ec3b29aSmrg	if test yes = "$allow_undefined"; then
90267ec3b29aSmrg	  if test unsupported = "$allow_undefined_flag"; then
90277ec3b29aSmrg	    if test yes = "$build_old_libs"; then
90287ec3b29aSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
90297ec3b29aSmrg	      build_libtool_libs=no
90307ec3b29aSmrg	    else
90317ec3b29aSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
90327ec3b29aSmrg	    fi
903332001f49Smrg	  fi
903432001f49Smrg	else
903532001f49Smrg	  # Don't allow undefined symbols.
90367ec3b29aSmrg	  allow_undefined_flag=$no_undefined_flag
903732001f49Smrg	fi
903832001f49Smrg
903932001f49Smrg      fi
904032001f49Smrg
90417ec3b29aSmrg      func_generate_dlsyms "$libname" "$libname" :
904232001f49Smrg      func_append libobjs " $symfileobj"
90437ec3b29aSmrg      test " " = "$libobjs" && libobjs=
904432001f49Smrg
90457ec3b29aSmrg      if test relink != "$opt_mode"; then
904632001f49Smrg	# Remove our outputs, but don't remove object files since they
904732001f49Smrg	# may have been created when compiling PIC objects.
904832001f49Smrg	removelist=
904932001f49Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
905032001f49Smrg	for p in $tempremovelist; do
905132001f49Smrg	  case $p in
905232001f49Smrg	    *.$objext | *.gcno)
905332001f49Smrg	       ;;
90547ec3b29aSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
90557ec3b29aSmrg	       if test -n "$precious_files_regex"; then
905632001f49Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
905732001f49Smrg		 then
905832001f49Smrg		   continue
905932001f49Smrg		 fi
906032001f49Smrg	       fi
906132001f49Smrg	       func_append removelist " $p"
906232001f49Smrg	       ;;
906332001f49Smrg	    *) ;;
906432001f49Smrg	  esac
906532001f49Smrg	done
906632001f49Smrg	test -n "$removelist" && \
906732001f49Smrg	  func_show_eval "${RM}r \$removelist"
906832001f49Smrg      fi
906932001f49Smrg
907032001f49Smrg      # Now set the variables for building old libraries.
90717ec3b29aSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
907232001f49Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
907332001f49Smrg
907432001f49Smrg	# Transform .lo files to .o files.
90757ec3b29aSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
907632001f49Smrg      fi
907732001f49Smrg
907832001f49Smrg      # Eliminate all temporary directories.
907932001f49Smrg      #for path in $notinst_path; do
908032001f49Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
908132001f49Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
908232001f49Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
908332001f49Smrg      #done
908432001f49Smrg
908532001f49Smrg      if test -n "$xrpath"; then
908632001f49Smrg	# If the user specified any rpath flags, then add them.
908732001f49Smrg	temp_xrpath=
908832001f49Smrg	for libdir in $xrpath; do
908932001f49Smrg	  func_replace_sysroot "$libdir"
909032001f49Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
909132001f49Smrg	  case "$finalize_rpath " in
909232001f49Smrg	  *" $libdir "*) ;;
909332001f49Smrg	  *) func_append finalize_rpath " $libdir" ;;
909432001f49Smrg	  esac
909532001f49Smrg	done
90967ec3b29aSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
909732001f49Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
909832001f49Smrg	fi
909932001f49Smrg      fi
910032001f49Smrg
910132001f49Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
91027ec3b29aSmrg      old_dlfiles=$dlfiles
910332001f49Smrg      dlfiles=
910432001f49Smrg      for lib in $old_dlfiles; do
910532001f49Smrg	case " $dlprefiles $dlfiles " in
910632001f49Smrg	*" $lib "*) ;;
910732001f49Smrg	*) func_append dlfiles " $lib" ;;
910832001f49Smrg	esac
910932001f49Smrg      done
911032001f49Smrg
911132001f49Smrg      # Make sure dlprefiles contains only unique files
91127ec3b29aSmrg      old_dlprefiles=$dlprefiles
911332001f49Smrg      dlprefiles=
911432001f49Smrg      for lib in $old_dlprefiles; do
911532001f49Smrg	case "$dlprefiles " in
911632001f49Smrg	*" $lib "*) ;;
911732001f49Smrg	*) func_append dlprefiles " $lib" ;;
911832001f49Smrg	esac
911932001f49Smrg      done
912032001f49Smrg
91217ec3b29aSmrg      if test yes = "$build_libtool_libs"; then
912232001f49Smrg	if test -n "$rpath"; then
912332001f49Smrg	  case $host in
912432001f49Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
912532001f49Smrg	    # these systems don't actually have a c library (as such)!
912632001f49Smrg	    ;;
912732001f49Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
912832001f49Smrg	    # Rhapsody C library is in the System framework
912932001f49Smrg	    func_append deplibs " System.ltframework"
913032001f49Smrg	    ;;
913132001f49Smrg	  *-*-netbsd*)
913232001f49Smrg	    # Don't link with libc until the a.out ld.so is fixed.
913332001f49Smrg	    ;;
913432001f49Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
913532001f49Smrg	    # Do not include libc due to us having libc/libc_r.
913632001f49Smrg	    ;;
913732001f49Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
913832001f49Smrg	    # Causes problems with __ctype
913932001f49Smrg	    ;;
914032001f49Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
914132001f49Smrg	    # Compiler inserts libc in the correct place for threads to work
914232001f49Smrg	    ;;
914332001f49Smrg	  *)
914432001f49Smrg	    # Add libc to deplibs on all other systems if necessary.
91457ec3b29aSmrg	    if test yes = "$build_libtool_need_lc"; then
914632001f49Smrg	      func_append deplibs " -lc"
914732001f49Smrg	    fi
914832001f49Smrg	    ;;
914932001f49Smrg	  esac
915032001f49Smrg	fi
915132001f49Smrg
915232001f49Smrg	# Transform deplibs into only deplibs that can be linked in shared.
915332001f49Smrg	name_save=$name
915432001f49Smrg	libname_save=$libname
915532001f49Smrg	release_save=$release
915632001f49Smrg	versuffix_save=$versuffix
915732001f49Smrg	major_save=$major
915832001f49Smrg	# I'm not sure if I'm treating the release correctly.  I think
915932001f49Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
916032001f49Smrg	# add it in twice.  Is that correct?
91617ec3b29aSmrg	release=
91627ec3b29aSmrg	versuffix=
91637ec3b29aSmrg	major=
916432001f49Smrg	newdeplibs=
916532001f49Smrg	droppeddeps=no
916632001f49Smrg	case $deplibs_check_method in
916732001f49Smrg	pass_all)
916832001f49Smrg	  # Don't check for shared/static.  Everything works.
916932001f49Smrg	  # This might be a little naive.  We might want to check
917032001f49Smrg	  # whether the library exists or not.  But this is on
917132001f49Smrg	  # osf3 & osf4 and I'm not really sure... Just
917232001f49Smrg	  # implementing what was already the behavior.
917332001f49Smrg	  newdeplibs=$deplibs
917432001f49Smrg	  ;;
917532001f49Smrg	test_compile)
917632001f49Smrg	  # This code stresses the "libraries are programs" paradigm to its
917732001f49Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
917832001f49Smrg	  # against the deplibs as a proxy for the library.  Then we can check
917932001f49Smrg	  # whether they linked in statically or dynamically with ldd.
918032001f49Smrg	  $opt_dry_run || $RM conftest.c
918132001f49Smrg	  cat > conftest.c <<EOF
918232001f49Smrg	  int main() { return 0; }
918332001f49SmrgEOF
918432001f49Smrg	  $opt_dry_run || $RM conftest
918532001f49Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
918632001f49Smrg	    ldd_output=`ldd conftest`
918732001f49Smrg	    for i in $deplibs; do
918832001f49Smrg	      case $i in
918932001f49Smrg	      -l*)
919032001f49Smrg		func_stripname -l '' "$i"
919132001f49Smrg		name=$func_stripname_result
91927ec3b29aSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
919332001f49Smrg		  case " $predeps $postdeps " in
919432001f49Smrg		  *" $i "*)
919532001f49Smrg		    func_append newdeplibs " $i"
91967ec3b29aSmrg		    i=
919732001f49Smrg		    ;;
919832001f49Smrg		  esac
919932001f49Smrg		fi
92007ec3b29aSmrg		if test -n "$i"; then
920132001f49Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
920232001f49Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
920332001f49Smrg		  set dummy $deplib_matches; shift
920432001f49Smrg		  deplib_match=$1
92057ec3b29aSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
920632001f49Smrg		    func_append newdeplibs " $i"
920732001f49Smrg		  else
920832001f49Smrg		    droppeddeps=yes
920932001f49Smrg		    echo
921032001f49Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
921132001f49Smrg		    echo "*** I have the capability to make that library automatically link in when"
921232001f49Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
921332001f49Smrg		    echo "*** shared version of the library, which I believe you do not have"
921432001f49Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
921532001f49Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
921632001f49Smrg		  fi
921732001f49Smrg		fi
921832001f49Smrg		;;
921932001f49Smrg	      *)
922032001f49Smrg		func_append newdeplibs " $i"
922132001f49Smrg		;;
922232001f49Smrg	      esac
922332001f49Smrg	    done
922432001f49Smrg	  else
922532001f49Smrg	    # Error occurred in the first compile.  Let's try to salvage
922632001f49Smrg	    # the situation: Compile a separate program for each library.
922732001f49Smrg	    for i in $deplibs; do
922832001f49Smrg	      case $i in
922932001f49Smrg	      -l*)
923032001f49Smrg		func_stripname -l '' "$i"
923132001f49Smrg		name=$func_stripname_result
923232001f49Smrg		$opt_dry_run || $RM conftest
923332001f49Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
923432001f49Smrg		  ldd_output=`ldd conftest`
92357ec3b29aSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
923632001f49Smrg		    case " $predeps $postdeps " in
923732001f49Smrg		    *" $i "*)
923832001f49Smrg		      func_append newdeplibs " $i"
92397ec3b29aSmrg		      i=
924032001f49Smrg		      ;;
924132001f49Smrg		    esac
924232001f49Smrg		  fi
92437ec3b29aSmrg		  if test -n "$i"; then
924432001f49Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
924532001f49Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
924632001f49Smrg		    set dummy $deplib_matches; shift
924732001f49Smrg		    deplib_match=$1
92487ec3b29aSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
924932001f49Smrg		      func_append newdeplibs " $i"
925032001f49Smrg		    else
925132001f49Smrg		      droppeddeps=yes
925232001f49Smrg		      echo
925332001f49Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
925432001f49Smrg		      echo "*** I have the capability to make that library automatically link in when"
925532001f49Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
925632001f49Smrg		      echo "*** shared version of the library, which you do not appear to have"
925732001f49Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
925832001f49Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
925932001f49Smrg		    fi
926032001f49Smrg		  fi
926132001f49Smrg		else
926232001f49Smrg		  droppeddeps=yes
926332001f49Smrg		  echo
926432001f49Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
926532001f49Smrg		  echo "*** make it link in!  You will probably need to install it or some"
926632001f49Smrg		  echo "*** library that it depends on before this library will be fully"
926732001f49Smrg		  echo "*** functional.  Installing it before continuing would be even better."
926832001f49Smrg		fi
926932001f49Smrg		;;
927032001f49Smrg	      *)
927132001f49Smrg		func_append newdeplibs " $i"
927232001f49Smrg		;;
927332001f49Smrg	      esac
927432001f49Smrg	    done
927532001f49Smrg	  fi
927632001f49Smrg	  ;;
927732001f49Smrg	file_magic*)
927832001f49Smrg	  set dummy $deplibs_check_method; shift
927932001f49Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
928032001f49Smrg	  for a_deplib in $deplibs; do
928132001f49Smrg	    case $a_deplib in
928232001f49Smrg	    -l*)
928332001f49Smrg	      func_stripname -l '' "$a_deplib"
928432001f49Smrg	      name=$func_stripname_result
92857ec3b29aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
928632001f49Smrg		case " $predeps $postdeps " in
928732001f49Smrg		*" $a_deplib "*)
928832001f49Smrg		  func_append newdeplibs " $a_deplib"
92897ec3b29aSmrg		  a_deplib=
929032001f49Smrg		  ;;
929132001f49Smrg		esac
929232001f49Smrg	      fi
92937ec3b29aSmrg	      if test -n "$a_deplib"; then
929432001f49Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
929532001f49Smrg		if test -n "$file_magic_glob"; then
929632001f49Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
929732001f49Smrg		else
929832001f49Smrg		  libnameglob=$libname
929932001f49Smrg		fi
93007ec3b29aSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
930132001f49Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
93027ec3b29aSmrg		  if test yes = "$want_nocaseglob"; then
930332001f49Smrg		    shopt -s nocaseglob
930432001f49Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
930532001f49Smrg		    $nocaseglob
930632001f49Smrg		  else
930732001f49Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
930832001f49Smrg		  fi
930932001f49Smrg		  for potent_lib in $potential_libs; do
931032001f49Smrg		      # Follow soft links.
931132001f49Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
931232001f49Smrg			 $GREP " -> " >/dev/null; then
931332001f49Smrg			continue
931432001f49Smrg		      fi
931532001f49Smrg		      # The statement above tries to avoid entering an
931632001f49Smrg		      # endless loop below, in case of cyclic links.
931732001f49Smrg		      # We might still enter an endless loop, since a link
931832001f49Smrg		      # loop can be closed while we follow links,
931932001f49Smrg		      # but so what?
93207ec3b29aSmrg		      potlib=$potent_lib
932132001f49Smrg		      while test -h "$potlib" 2>/dev/null; do
93227ec3b29aSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
932332001f49Smrg			case $potliblink in
93247ec3b29aSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
93257ec3b29aSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
932632001f49Smrg			esac
932732001f49Smrg		      done
932832001f49Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
932932001f49Smrg			 $SED -e 10q |
933032001f49Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
933132001f49Smrg			func_append newdeplibs " $a_deplib"
93327ec3b29aSmrg			a_deplib=
933332001f49Smrg			break 2
933432001f49Smrg		      fi
933532001f49Smrg		  done
933632001f49Smrg		done
933732001f49Smrg	      fi
93387ec3b29aSmrg	      if test -n "$a_deplib"; then
933932001f49Smrg		droppeddeps=yes
934032001f49Smrg		echo
934132001f49Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
934232001f49Smrg		echo "*** I have the capability to make that library automatically link in when"
934332001f49Smrg		echo "*** you link to this library.  But I can only do this if you have a"
934432001f49Smrg		echo "*** shared version of the library, which you do not appear to have"
934532001f49Smrg		echo "*** because I did check the linker path looking for a file starting"
93467ec3b29aSmrg		if test -z "$potlib"; then
934732001f49Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
934832001f49Smrg		else
934932001f49Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
935032001f49Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
935132001f49Smrg		fi
935232001f49Smrg	      fi
935332001f49Smrg	      ;;
935432001f49Smrg	    *)
935532001f49Smrg	      # Add a -L argument.
935632001f49Smrg	      func_append newdeplibs " $a_deplib"
935732001f49Smrg	      ;;
935832001f49Smrg	    esac
935932001f49Smrg	  done # Gone through all deplibs.
936032001f49Smrg	  ;;
936132001f49Smrg	match_pattern*)
936232001f49Smrg	  set dummy $deplibs_check_method; shift
936332001f49Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
936432001f49Smrg	  for a_deplib in $deplibs; do
936532001f49Smrg	    case $a_deplib in
936632001f49Smrg	    -l*)
936732001f49Smrg	      func_stripname -l '' "$a_deplib"
936832001f49Smrg	      name=$func_stripname_result
93697ec3b29aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
937032001f49Smrg		case " $predeps $postdeps " in
937132001f49Smrg		*" $a_deplib "*)
937232001f49Smrg		  func_append newdeplibs " $a_deplib"
93737ec3b29aSmrg		  a_deplib=
937432001f49Smrg		  ;;
937532001f49Smrg		esac
937632001f49Smrg	      fi
93777ec3b29aSmrg	      if test -n "$a_deplib"; then
937832001f49Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
937932001f49Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
938032001f49Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
938132001f49Smrg		  for potent_lib in $potential_libs; do
93827ec3b29aSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
938332001f49Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
938432001f49Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
938532001f49Smrg		      func_append newdeplibs " $a_deplib"
93867ec3b29aSmrg		      a_deplib=
938732001f49Smrg		      break 2
938832001f49Smrg		    fi
938932001f49Smrg		  done
939032001f49Smrg		done
939132001f49Smrg	      fi
93927ec3b29aSmrg	      if test -n "$a_deplib"; then
939332001f49Smrg		droppeddeps=yes
939432001f49Smrg		echo
939532001f49Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
939632001f49Smrg		echo "*** I have the capability to make that library automatically link in when"
939732001f49Smrg		echo "*** you link to this library.  But I can only do this if you have a"
939832001f49Smrg		echo "*** shared version of the library, which you do not appear to have"
939932001f49Smrg		echo "*** because I did check the linker path looking for a file starting"
94007ec3b29aSmrg		if test -z "$potlib"; then
940132001f49Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
940232001f49Smrg		else
940332001f49Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
940432001f49Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
940532001f49Smrg		fi
940632001f49Smrg	      fi
940732001f49Smrg	      ;;
940832001f49Smrg	    *)
940932001f49Smrg	      # Add a -L argument.
941032001f49Smrg	      func_append newdeplibs " $a_deplib"
941132001f49Smrg	      ;;
941232001f49Smrg	    esac
941332001f49Smrg	  done # Gone through all deplibs.
941432001f49Smrg	  ;;
941532001f49Smrg	none | unknown | *)
94167ec3b29aSmrg	  newdeplibs=
941732001f49Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
94187ec3b29aSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94197ec3b29aSmrg	    for i in $predeps $postdeps; do
942032001f49Smrg	      # can't use Xsed below, because $i might contain '/'
94217ec3b29aSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
942232001f49Smrg	    done
942332001f49Smrg	  fi
942432001f49Smrg	  case $tmp_deplibs in
942532001f49Smrg	  *[!\	\ ]*)
942632001f49Smrg	    echo
94277ec3b29aSmrg	    if test none = "$deplibs_check_method"; then
942832001f49Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
942932001f49Smrg	    else
943032001f49Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
943132001f49Smrg	    fi
943232001f49Smrg	    echo "*** All declared inter-library dependencies are being dropped."
943332001f49Smrg	    droppeddeps=yes
943432001f49Smrg	    ;;
943532001f49Smrg	  esac
943632001f49Smrg	  ;;
943732001f49Smrg	esac
943832001f49Smrg	versuffix=$versuffix_save
943932001f49Smrg	major=$major_save
944032001f49Smrg	release=$release_save
944132001f49Smrg	libname=$libname_save
944232001f49Smrg	name=$name_save
944332001f49Smrg
944432001f49Smrg	case $host in
944532001f49Smrg	*-*-rhapsody* | *-*-darwin1.[012])
944632001f49Smrg	  # On Rhapsody replace the C library with the System framework
944732001f49Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
944832001f49Smrg	  ;;
944932001f49Smrg	esac
945032001f49Smrg
94517ec3b29aSmrg	if test yes = "$droppeddeps"; then
94527ec3b29aSmrg	  if test yes = "$module"; then
945332001f49Smrg	    echo
945432001f49Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
945532001f49Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
945632001f49Smrg	    echo "*** a static module, that should work as long as the dlopening"
945732001f49Smrg	    echo "*** application is linked with the -dlopen flag."
945832001f49Smrg	    if test -z "$global_symbol_pipe"; then
945932001f49Smrg	      echo
946032001f49Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
94617ec3b29aSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
946232001f49Smrg	      echo "*** not find such a program.  So, this module is probably useless."
94637ec3b29aSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
946432001f49Smrg	    fi
94657ec3b29aSmrg	    if test no = "$build_old_libs"; then
94667ec3b29aSmrg	      oldlibs=$output_objdir/$libname.$libext
946732001f49Smrg	      build_libtool_libs=module
946832001f49Smrg	      build_old_libs=yes
946932001f49Smrg	    else
947032001f49Smrg	      build_libtool_libs=no
947132001f49Smrg	    fi
947232001f49Smrg	  else
947332001f49Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
947432001f49Smrg	    echo "*** automatically added whenever a program is linked with this library"
947532001f49Smrg	    echo "*** or is declared to -dlopen it."
947632001f49Smrg
94777ec3b29aSmrg	    if test no = "$allow_undefined"; then
947832001f49Smrg	      echo
947932001f49Smrg	      echo "*** Since this library must not contain undefined symbols,"
948032001f49Smrg	      echo "*** because either the platform does not support them or"
948132001f49Smrg	      echo "*** it was explicitly requested with -no-undefined,"
948232001f49Smrg	      echo "*** libtool will only create a static version of it."
94837ec3b29aSmrg	      if test no = "$build_old_libs"; then
94847ec3b29aSmrg		oldlibs=$output_objdir/$libname.$libext
948532001f49Smrg		build_libtool_libs=module
948632001f49Smrg		build_old_libs=yes
948732001f49Smrg	      else
948832001f49Smrg		build_libtool_libs=no
948932001f49Smrg	      fi
949032001f49Smrg	    fi
949132001f49Smrg	  fi
949232001f49Smrg	fi
949332001f49Smrg	# Done checking deplibs!
949432001f49Smrg	deplibs=$newdeplibs
949532001f49Smrg      fi
949632001f49Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
949732001f49Smrg      case $host in
949832001f49Smrg	*-*-darwin*)
949932001f49Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
950032001f49Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
950132001f49Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
950232001f49Smrg	  ;;
950332001f49Smrg      esac
950432001f49Smrg
950532001f49Smrg      # move library search paths that coincide with paths to not yet
950632001f49Smrg      # installed libraries to the beginning of the library search list
950732001f49Smrg      new_libs=
950832001f49Smrg      for path in $notinst_path; do
950932001f49Smrg	case " $new_libs " in
951032001f49Smrg	*" -L$path/$objdir "*) ;;
951132001f49Smrg	*)
951232001f49Smrg	  case " $deplibs " in
951332001f49Smrg	  *" -L$path/$objdir "*)
951432001f49Smrg	    func_append new_libs " -L$path/$objdir" ;;
951532001f49Smrg	  esac
951632001f49Smrg	  ;;
951732001f49Smrg	esac
951832001f49Smrg      done
951932001f49Smrg      for deplib in $deplibs; do
952032001f49Smrg	case $deplib in
952132001f49Smrg	-L*)
952232001f49Smrg	  case " $new_libs " in
952332001f49Smrg	  *" $deplib "*) ;;
952432001f49Smrg	  *) func_append new_libs " $deplib" ;;
952532001f49Smrg	  esac
952632001f49Smrg	  ;;
952732001f49Smrg	*) func_append new_libs " $deplib" ;;
952832001f49Smrg	esac
952932001f49Smrg      done
95307ec3b29aSmrg      deplibs=$new_libs
953132001f49Smrg
953232001f49Smrg      # All the library-specific variables (install_libdir is set above).
953332001f49Smrg      library_names=
953432001f49Smrg      old_library=
953532001f49Smrg      dlname=
953632001f49Smrg
953732001f49Smrg      # Test again, we may have decided not to build it any more
95387ec3b29aSmrg      if test yes = "$build_libtool_libs"; then
95397ec3b29aSmrg	# Remove $wl instances when linking with ld.
954032001f49Smrg	# FIXME: should test the right _cmds variable.
954132001f49Smrg	case $archive_cmds in
954232001f49Smrg	  *\$LD\ *) wl= ;;
954332001f49Smrg        esac
95447ec3b29aSmrg	if test yes = "$hardcode_into_libs"; then
954532001f49Smrg	  # Hardcode the library paths
954632001f49Smrg	  hardcode_libdirs=
954732001f49Smrg	  dep_rpath=
95487ec3b29aSmrg	  rpath=$finalize_rpath
95497ec3b29aSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
955032001f49Smrg	  for libdir in $rpath; do
955132001f49Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
955232001f49Smrg	      if test -n "$hardcode_libdir_separator"; then
955332001f49Smrg		func_replace_sysroot "$libdir"
955432001f49Smrg		libdir=$func_replace_sysroot_result
955532001f49Smrg		if test -z "$hardcode_libdirs"; then
95567ec3b29aSmrg		  hardcode_libdirs=$libdir
955732001f49Smrg		else
955832001f49Smrg		  # Just accumulate the unique libdirs.
955932001f49Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
956032001f49Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
956132001f49Smrg		    ;;
956232001f49Smrg		  *)
956332001f49Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
956432001f49Smrg		    ;;
956532001f49Smrg		  esac
956632001f49Smrg		fi
956732001f49Smrg	      else
956832001f49Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
956932001f49Smrg		func_append dep_rpath " $flag"
957032001f49Smrg	      fi
957132001f49Smrg	    elif test -n "$runpath_var"; then
957232001f49Smrg	      case "$perm_rpath " in
957332001f49Smrg	      *" $libdir "*) ;;
957432001f49Smrg	      *) func_append perm_rpath " $libdir" ;;
957532001f49Smrg	      esac
957632001f49Smrg	    fi
957732001f49Smrg	  done
957832001f49Smrg	  # Substitute the hardcoded libdirs into the rpath.
957932001f49Smrg	  if test -n "$hardcode_libdir_separator" &&
958032001f49Smrg	     test -n "$hardcode_libdirs"; then
95817ec3b29aSmrg	    libdir=$hardcode_libdirs
958232001f49Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
958332001f49Smrg	  fi
958432001f49Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
958532001f49Smrg	    # We should set the runpath_var.
958632001f49Smrg	    rpath=
958732001f49Smrg	    for dir in $perm_rpath; do
958832001f49Smrg	      func_append rpath "$dir:"
958932001f49Smrg	    done
959032001f49Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
959132001f49Smrg	  fi
959232001f49Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
959332001f49Smrg	fi
959432001f49Smrg
95957ec3b29aSmrg	shlibpath=$finalize_shlibpath
95967ec3b29aSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
959732001f49Smrg	if test -n "$shlibpath"; then
959832001f49Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
959932001f49Smrg	fi
960032001f49Smrg
960132001f49Smrg	# Get the real and link names of the library.
960232001f49Smrg	eval shared_ext=\"$shrext_cmds\"
960332001f49Smrg	eval library_names=\"$library_names_spec\"
960432001f49Smrg	set dummy $library_names
960532001f49Smrg	shift
96067ec3b29aSmrg	realname=$1
960732001f49Smrg	shift
960832001f49Smrg
960932001f49Smrg	if test -n "$soname_spec"; then
961032001f49Smrg	  eval soname=\"$soname_spec\"
961132001f49Smrg	else
96127ec3b29aSmrg	  soname=$realname
961332001f49Smrg	fi
961432001f49Smrg	if test -z "$dlname"; then
961532001f49Smrg	  dlname=$soname
961632001f49Smrg	fi
961732001f49Smrg
96187ec3b29aSmrg	lib=$output_objdir/$realname
961932001f49Smrg	linknames=
962032001f49Smrg	for link
962132001f49Smrg	do
962232001f49Smrg	  func_append linknames " $link"
962332001f49Smrg	done
962432001f49Smrg
962532001f49Smrg	# Use standard objects if they are pic
962632001f49Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
962732001f49Smrg	test "X$libobjs" = "X " && libobjs=
962832001f49Smrg
962932001f49Smrg	delfiles=
963032001f49Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
963132001f49Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
96327ec3b29aSmrg	  export_symbols=$output_objdir/$libname.uexp
963332001f49Smrg	  func_append delfiles " $export_symbols"
963432001f49Smrg	fi
963532001f49Smrg
963632001f49Smrg	orig_export_symbols=
963732001f49Smrg	case $host_os in
963832001f49Smrg	cygwin* | mingw* | cegcc*)
963932001f49Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
964032001f49Smrg	    # exporting using user supplied symfile
96417ec3b29aSmrg	    func_dll_def_p "$export_symbols" || {
964232001f49Smrg	      # and it's NOT already a .def file. Must figure out
964332001f49Smrg	      # which of the given symbols are data symbols and tag
964432001f49Smrg	      # them as such. So, trigger use of export_symbols_cmds.
964532001f49Smrg	      # export_symbols gets reassigned inside the "prepare
964632001f49Smrg	      # the list of exported symbols" if statement, so the
964732001f49Smrg	      # include_expsyms logic still works.
96487ec3b29aSmrg	      orig_export_symbols=$export_symbols
964932001f49Smrg	      export_symbols=
965032001f49Smrg	      always_export_symbols=yes
96517ec3b29aSmrg	    }
965232001f49Smrg	  fi
965332001f49Smrg	  ;;
965432001f49Smrg	esac
965532001f49Smrg
965632001f49Smrg	# Prepare the list of exported symbols
965732001f49Smrg	if test -z "$export_symbols"; then
96587ec3b29aSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
96597ec3b29aSmrg	    func_verbose "generating symbol list for '$libname.la'"
96607ec3b29aSmrg	    export_symbols=$output_objdir/$libname.exp
966132001f49Smrg	    $opt_dry_run || $RM $export_symbols
966232001f49Smrg	    cmds=$export_symbols_cmds
96637ec3b29aSmrg	    save_ifs=$IFS; IFS='~'
966432001f49Smrg	    for cmd1 in $cmds; do
96657ec3b29aSmrg	      IFS=$save_ifs
966632001f49Smrg	      # Take the normal branch if the nm_file_list_spec branch
966732001f49Smrg	      # doesn't work or if tool conversion is not needed.
966832001f49Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
966932001f49Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
967032001f49Smrg		  try_normal_branch=yes
967132001f49Smrg		  eval cmd=\"$cmd1\"
967232001f49Smrg		  func_len " $cmd"
967332001f49Smrg		  len=$func_len_result
967432001f49Smrg		  ;;
967532001f49Smrg		*)
967632001f49Smrg		  try_normal_branch=no
967732001f49Smrg		  ;;
967832001f49Smrg	      esac
96797ec3b29aSmrg	      if test yes = "$try_normal_branch" \
968032001f49Smrg		 && { test "$len" -lt "$max_cmd_len" \
968132001f49Smrg		      || test "$max_cmd_len" -le -1; }
968232001f49Smrg	      then
968332001f49Smrg		func_show_eval "$cmd" 'exit $?'
968432001f49Smrg		skipped_export=false
968532001f49Smrg	      elif test -n "$nm_file_list_spec"; then
968632001f49Smrg		func_basename "$output"
968732001f49Smrg		output_la=$func_basename_result
968832001f49Smrg		save_libobjs=$libobjs
968932001f49Smrg		save_output=$output
96907ec3b29aSmrg		output=$output_objdir/$output_la.nm
969132001f49Smrg		func_to_tool_file "$output"
969232001f49Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
969332001f49Smrg		func_append delfiles " $output"
969432001f49Smrg		func_verbose "creating $NM input file list: $output"
969532001f49Smrg		for obj in $save_libobjs; do
969632001f49Smrg		  func_to_tool_file "$obj"
969732001f49Smrg		  $ECHO "$func_to_tool_file_result"
969832001f49Smrg		done > "$output"
969932001f49Smrg		eval cmd=\"$cmd1\"
970032001f49Smrg		func_show_eval "$cmd" 'exit $?'
970132001f49Smrg		output=$save_output
970232001f49Smrg		libobjs=$save_libobjs
970332001f49Smrg		skipped_export=false
970432001f49Smrg	      else
970532001f49Smrg		# The command line is too long to execute in one step.
970632001f49Smrg		func_verbose "using reloadable object file for export list..."
970732001f49Smrg		skipped_export=:
970832001f49Smrg		# Break out early, otherwise skipped_export may be
970932001f49Smrg		# set to false by a later but shorter cmd.
971032001f49Smrg		break
971132001f49Smrg	      fi
971232001f49Smrg	    done
97137ec3b29aSmrg	    IFS=$save_ifs
97147ec3b29aSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
971532001f49Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
971632001f49Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
971732001f49Smrg	    fi
971832001f49Smrg	  fi
971932001f49Smrg	fi
972032001f49Smrg
972132001f49Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
97227ec3b29aSmrg	  tmp_export_symbols=$export_symbols
97237ec3b29aSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
972432001f49Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
972532001f49Smrg	fi
972632001f49Smrg
97277ec3b29aSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
972832001f49Smrg	  # The given exports_symbols file has to be filtered, so filter it.
97297ec3b29aSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
973032001f49Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
97317ec3b29aSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
973232001f49Smrg	  # though. Also, the filter scales superlinearly with the number of
973332001f49Smrg	  # global variables. join(1) would be nice here, but unfortunately
973432001f49Smrg	  # isn't a blessed tool.
973532001f49Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
973632001f49Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
973732001f49Smrg	  export_symbols=$output_objdir/$libname.def
973832001f49Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
973932001f49Smrg	fi
974032001f49Smrg
974132001f49Smrg	tmp_deplibs=
974232001f49Smrg	for test_deplib in $deplibs; do
974332001f49Smrg	  case " $convenience " in
974432001f49Smrg	  *" $test_deplib "*) ;;
974532001f49Smrg	  *)
974632001f49Smrg	    func_append tmp_deplibs " $test_deplib"
974732001f49Smrg	    ;;
974832001f49Smrg	  esac
974932001f49Smrg	done
97507ec3b29aSmrg	deplibs=$tmp_deplibs
975132001f49Smrg
975232001f49Smrg	if test -n "$convenience"; then
975332001f49Smrg	  if test -n "$whole_archive_flag_spec" &&
97547ec3b29aSmrg	    test yes = "$compiler_needs_object" &&
975532001f49Smrg	    test -z "$libobjs"; then
975632001f49Smrg	    # extract the archives, so we have objects to list.
975732001f49Smrg	    # TODO: could optimize this to just extract one archive.
975832001f49Smrg	    whole_archive_flag_spec=
975932001f49Smrg	  fi
976032001f49Smrg	  if test -n "$whole_archive_flag_spec"; then
976132001f49Smrg	    save_libobjs=$libobjs
976232001f49Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
976332001f49Smrg	    test "X$libobjs" = "X " && libobjs=
976432001f49Smrg	  else
97657ec3b29aSmrg	    gentop=$output_objdir/${outputname}x
976632001f49Smrg	    func_append generated " $gentop"
976732001f49Smrg
976832001f49Smrg	    func_extract_archives $gentop $convenience
976932001f49Smrg	    func_append libobjs " $func_extract_archives_result"
977032001f49Smrg	    test "X$libobjs" = "X " && libobjs=
977132001f49Smrg	  fi
977232001f49Smrg	fi
977332001f49Smrg
97747ec3b29aSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
977532001f49Smrg	  eval flag=\"$thread_safe_flag_spec\"
977632001f49Smrg	  func_append linker_flags " $flag"
977732001f49Smrg	fi
977832001f49Smrg
977932001f49Smrg	# Make a backup of the uninstalled library when relinking
97807ec3b29aSmrg	if test relink = "$opt_mode"; then
978132001f49Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
978232001f49Smrg	fi
978332001f49Smrg
978432001f49Smrg	# Do each of the archive commands.
97857ec3b29aSmrg	if test yes = "$module" && test -n "$module_cmds"; then
978632001f49Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
978732001f49Smrg	    eval test_cmds=\"$module_expsym_cmds\"
978832001f49Smrg	    cmds=$module_expsym_cmds
978932001f49Smrg	  else
979032001f49Smrg	    eval test_cmds=\"$module_cmds\"
979132001f49Smrg	    cmds=$module_cmds
979232001f49Smrg	  fi
979332001f49Smrg	else
979432001f49Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
979532001f49Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
979632001f49Smrg	    cmds=$archive_expsym_cmds
979732001f49Smrg	  else
979832001f49Smrg	    eval test_cmds=\"$archive_cmds\"
979932001f49Smrg	    cmds=$archive_cmds
980032001f49Smrg	  fi
980132001f49Smrg	fi
980232001f49Smrg
98037ec3b29aSmrg	if test : != "$skipped_export" &&
980432001f49Smrg	   func_len " $test_cmds" &&
980532001f49Smrg	   len=$func_len_result &&
980632001f49Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
980732001f49Smrg	  :
980832001f49Smrg	else
980932001f49Smrg	  # The command line is too long to link in one step, link piecewise
981032001f49Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
981132001f49Smrg	  # script.
981232001f49Smrg
981332001f49Smrg	  # Save the value of $output and $libobjs because we want to
981432001f49Smrg	  # use them later.  If we have whole_archive_flag_spec, we
981532001f49Smrg	  # want to use save_libobjs as it was before
981632001f49Smrg	  # whole_archive_flag_spec was expanded, because we can't
981732001f49Smrg	  # assume the linker understands whole_archive_flag_spec.
981832001f49Smrg	  # This may have to be revisited, in case too many
981932001f49Smrg	  # convenience libraries get linked in and end up exceeding
982032001f49Smrg	  # the spec.
982132001f49Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
982232001f49Smrg	    save_libobjs=$libobjs
982332001f49Smrg	  fi
982432001f49Smrg	  save_output=$output
982532001f49Smrg	  func_basename "$output"
982632001f49Smrg	  output_la=$func_basename_result
982732001f49Smrg
982832001f49Smrg	  # Clear the reloadable object creation command queue and
982932001f49Smrg	  # initialize k to one.
983032001f49Smrg	  test_cmds=
983132001f49Smrg	  concat_cmds=
983232001f49Smrg	  objlist=
983332001f49Smrg	  last_robj=
983432001f49Smrg	  k=1
983532001f49Smrg
98367ec3b29aSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
98377ec3b29aSmrg	    output=$output_objdir/$output_la.lnkscript
983832001f49Smrg	    func_verbose "creating GNU ld script: $output"
983932001f49Smrg	    echo 'INPUT (' > $output
984032001f49Smrg	    for obj in $save_libobjs
984132001f49Smrg	    do
984232001f49Smrg	      func_to_tool_file "$obj"
984332001f49Smrg	      $ECHO "$func_to_tool_file_result" >> $output
984432001f49Smrg	    done
984532001f49Smrg	    echo ')' >> $output
984632001f49Smrg	    func_append delfiles " $output"
984732001f49Smrg	    func_to_tool_file "$output"
984832001f49Smrg	    output=$func_to_tool_file_result
98497ec3b29aSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
98507ec3b29aSmrg	    output=$output_objdir/$output_la.lnk
985132001f49Smrg	    func_verbose "creating linker input file list: $output"
985232001f49Smrg	    : > $output
985332001f49Smrg	    set x $save_libobjs
985432001f49Smrg	    shift
985532001f49Smrg	    firstobj=
98567ec3b29aSmrg	    if test yes = "$compiler_needs_object"; then
985732001f49Smrg	      firstobj="$1 "
985832001f49Smrg	      shift
985932001f49Smrg	    fi
986032001f49Smrg	    for obj
986132001f49Smrg	    do
986232001f49Smrg	      func_to_tool_file "$obj"
986332001f49Smrg	      $ECHO "$func_to_tool_file_result" >> $output
986432001f49Smrg	    done
986532001f49Smrg	    func_append delfiles " $output"
986632001f49Smrg	    func_to_tool_file "$output"
986732001f49Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
986832001f49Smrg	  else
986932001f49Smrg	    if test -n "$save_libobjs"; then
987032001f49Smrg	      func_verbose "creating reloadable object files..."
98717ec3b29aSmrg	      output=$output_objdir/$output_la-$k.$objext
987232001f49Smrg	      eval test_cmds=\"$reload_cmds\"
987332001f49Smrg	      func_len " $test_cmds"
987432001f49Smrg	      len0=$func_len_result
987532001f49Smrg	      len=$len0
987632001f49Smrg
987732001f49Smrg	      # Loop over the list of objects to be linked.
987832001f49Smrg	      for obj in $save_libobjs
987932001f49Smrg	      do
988032001f49Smrg		func_len " $obj"
988132001f49Smrg		func_arith $len + $func_len_result
988232001f49Smrg		len=$func_arith_result
98837ec3b29aSmrg		if test -z "$objlist" ||
988432001f49Smrg		   test "$len" -lt "$max_cmd_len"; then
988532001f49Smrg		  func_append objlist " $obj"
988632001f49Smrg		else
988732001f49Smrg		  # The command $test_cmds is almost too long, add a
988832001f49Smrg		  # command to the queue.
98897ec3b29aSmrg		  if test 1 -eq "$k"; then
989032001f49Smrg		    # The first file doesn't have a previous command to add.
989132001f49Smrg		    reload_objs=$objlist
989232001f49Smrg		    eval concat_cmds=\"$reload_cmds\"
989332001f49Smrg		  else
989432001f49Smrg		    # All subsequent reloadable object files will link in
989532001f49Smrg		    # the last one created.
989632001f49Smrg		    reload_objs="$objlist $last_robj"
989732001f49Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
989832001f49Smrg		  fi
98997ec3b29aSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
990032001f49Smrg		  func_arith $k + 1
990132001f49Smrg		  k=$func_arith_result
99027ec3b29aSmrg		  output=$output_objdir/$output_la-$k.$objext
990332001f49Smrg		  objlist=" $obj"
990432001f49Smrg		  func_len " $last_robj"
990532001f49Smrg		  func_arith $len0 + $func_len_result
990632001f49Smrg		  len=$func_arith_result
990732001f49Smrg		fi
990832001f49Smrg	      done
990932001f49Smrg	      # Handle the remaining objects by creating one last
991032001f49Smrg	      # reloadable object file.  All subsequent reloadable object
991132001f49Smrg	      # files will link in the last one created.
991232001f49Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
991332001f49Smrg	      reload_objs="$objlist $last_robj"
99147ec3b29aSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
991532001f49Smrg	      if test -n "$last_robj"; then
99167ec3b29aSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
991732001f49Smrg	      fi
991832001f49Smrg	      func_append delfiles " $output"
991932001f49Smrg
992032001f49Smrg	    else
992132001f49Smrg	      output=
992232001f49Smrg	    fi
992332001f49Smrg
99247ec3b29aSmrg	    ${skipped_export-false} && {
99257ec3b29aSmrg	      func_verbose "generating symbol list for '$libname.la'"
99267ec3b29aSmrg	      export_symbols=$output_objdir/$libname.exp
992732001f49Smrg	      $opt_dry_run || $RM $export_symbols
992832001f49Smrg	      libobjs=$output
992932001f49Smrg	      # Append the command to create the export file.
993032001f49Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
993132001f49Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
993232001f49Smrg	      if test -n "$last_robj"; then
993332001f49Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
993432001f49Smrg	      fi
99357ec3b29aSmrg	    }
993632001f49Smrg
993732001f49Smrg	    test -n "$save_libobjs" &&
993832001f49Smrg	      func_verbose "creating a temporary reloadable object file: $output"
993932001f49Smrg
994032001f49Smrg	    # Loop through the commands generated above and execute them.
99417ec3b29aSmrg	    save_ifs=$IFS; IFS='~'
994232001f49Smrg	    for cmd in $concat_cmds; do
99437ec3b29aSmrg	      IFS=$save_ifs
99447ec3b29aSmrg	      $opt_quiet || {
994532001f49Smrg		  func_quote_for_expand "$cmd"
994632001f49Smrg		  eval "func_echo $func_quote_for_expand_result"
994732001f49Smrg	      }
994832001f49Smrg	      $opt_dry_run || eval "$cmd" || {
994932001f49Smrg		lt_exit=$?
995032001f49Smrg
995132001f49Smrg		# Restore the uninstalled library and exit
99527ec3b29aSmrg		if test relink = "$opt_mode"; then
995332001f49Smrg		  ( cd "$output_objdir" && \
995432001f49Smrg		    $RM "${realname}T" && \
995532001f49Smrg		    $MV "${realname}U" "$realname" )
995632001f49Smrg		fi
995732001f49Smrg
995832001f49Smrg		exit $lt_exit
995932001f49Smrg	      }
996032001f49Smrg	    done
99617ec3b29aSmrg	    IFS=$save_ifs
996232001f49Smrg
996332001f49Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
996432001f49Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
996532001f49Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
996632001f49Smrg	    fi
996732001f49Smrg	  fi
996832001f49Smrg
99697ec3b29aSmrg          ${skipped_export-false} && {
997032001f49Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
99717ec3b29aSmrg	      tmp_export_symbols=$export_symbols
99727ec3b29aSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
997332001f49Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
997432001f49Smrg	    fi
997532001f49Smrg
997632001f49Smrg	    if test -n "$orig_export_symbols"; then
997732001f49Smrg	      # The given exports_symbols file has to be filtered, so filter it.
99787ec3b29aSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
997932001f49Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
99807ec3b29aSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
998132001f49Smrg	      # though. Also, the filter scales superlinearly with the number of
998232001f49Smrg	      # global variables. join(1) would be nice here, but unfortunately
998332001f49Smrg	      # isn't a blessed tool.
998432001f49Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
998532001f49Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
998632001f49Smrg	      export_symbols=$output_objdir/$libname.def
998732001f49Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
998832001f49Smrg	    fi
99897ec3b29aSmrg	  }
999032001f49Smrg
999132001f49Smrg	  libobjs=$output
999232001f49Smrg	  # Restore the value of output.
999332001f49Smrg	  output=$save_output
999432001f49Smrg
999532001f49Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
999632001f49Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
999732001f49Smrg	    test "X$libobjs" = "X " && libobjs=
999832001f49Smrg	  fi
999932001f49Smrg	  # Expand the library linking commands again to reset the
1000032001f49Smrg	  # value of $libobjs for piecewise linking.
1000132001f49Smrg
1000232001f49Smrg	  # Do each of the archive commands.
100037ec3b29aSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
1000432001f49Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1000532001f49Smrg	      cmds=$module_expsym_cmds
1000632001f49Smrg	    else
1000732001f49Smrg	      cmds=$module_cmds
1000832001f49Smrg	    fi
1000932001f49Smrg	  else
1001032001f49Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1001132001f49Smrg	      cmds=$archive_expsym_cmds
1001232001f49Smrg	    else
1001332001f49Smrg	      cmds=$archive_cmds
1001432001f49Smrg	    fi
1001532001f49Smrg	  fi
1001632001f49Smrg	fi
1001732001f49Smrg
1001832001f49Smrg	if test -n "$delfiles"; then
1001932001f49Smrg	  # Append the command to remove temporary files to $cmds.
1002032001f49Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1002132001f49Smrg	fi
1002232001f49Smrg
1002332001f49Smrg	# Add any objects from preloaded convenience libraries
1002432001f49Smrg	if test -n "$dlprefiles"; then
100257ec3b29aSmrg	  gentop=$output_objdir/${outputname}x
1002632001f49Smrg	  func_append generated " $gentop"
1002732001f49Smrg
1002832001f49Smrg	  func_extract_archives $gentop $dlprefiles
1002932001f49Smrg	  func_append libobjs " $func_extract_archives_result"
1003032001f49Smrg	  test "X$libobjs" = "X " && libobjs=
1003132001f49Smrg	fi
1003232001f49Smrg
100337ec3b29aSmrg	save_ifs=$IFS; IFS='~'
1003432001f49Smrg	for cmd in $cmds; do
100357ec3b29aSmrg	  IFS=$sp$nl
1003632001f49Smrg	  eval cmd=\"$cmd\"
100377ec3b29aSmrg	  IFS=$save_ifs
100387ec3b29aSmrg	  $opt_quiet || {
1003932001f49Smrg	    func_quote_for_expand "$cmd"
1004032001f49Smrg	    eval "func_echo $func_quote_for_expand_result"
1004132001f49Smrg	  }
1004232001f49Smrg	  $opt_dry_run || eval "$cmd" || {
1004332001f49Smrg	    lt_exit=$?
1004432001f49Smrg
1004532001f49Smrg	    # Restore the uninstalled library and exit
100467ec3b29aSmrg	    if test relink = "$opt_mode"; then
1004732001f49Smrg	      ( cd "$output_objdir" && \
1004832001f49Smrg	        $RM "${realname}T" && \
1004932001f49Smrg		$MV "${realname}U" "$realname" )
1005032001f49Smrg	    fi
1005132001f49Smrg
1005232001f49Smrg	    exit $lt_exit
1005332001f49Smrg	  }
1005432001f49Smrg	done
100557ec3b29aSmrg	IFS=$save_ifs
1005632001f49Smrg
1005732001f49Smrg	# Restore the uninstalled library and exit
100587ec3b29aSmrg	if test relink = "$opt_mode"; then
1005932001f49Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
1006032001f49Smrg
1006132001f49Smrg	  if test -n "$convenience"; then
1006232001f49Smrg	    if test -z "$whole_archive_flag_spec"; then
1006332001f49Smrg	      func_show_eval '${RM}r "$gentop"'
1006432001f49Smrg	    fi
1006532001f49Smrg	  fi
1006632001f49Smrg
1006732001f49Smrg	  exit $EXIT_SUCCESS
1006832001f49Smrg	fi
1006932001f49Smrg
1007032001f49Smrg	# Create links to the real library.
1007132001f49Smrg	for linkname in $linknames; do
1007232001f49Smrg	  if test "$realname" != "$linkname"; then
1007332001f49Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
1007432001f49Smrg	  fi
1007532001f49Smrg	done
1007632001f49Smrg
1007732001f49Smrg	# If -module or -export-dynamic was specified, set the dlname.
100787ec3b29aSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1007932001f49Smrg	  # On all known operating systems, these are identical.
100807ec3b29aSmrg	  dlname=$soname
1008132001f49Smrg	fi
1008232001f49Smrg      fi
1008332001f49Smrg      ;;
1008432001f49Smrg
1008532001f49Smrg    obj)
100867ec3b29aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
100877ec3b29aSmrg	func_warning "'-dlopen' is ignored for objects"
1008832001f49Smrg      fi
1008932001f49Smrg
1009032001f49Smrg      case " $deplibs" in
1009132001f49Smrg      *\ -l* | *\ -L*)
100927ec3b29aSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
1009332001f49Smrg      esac
1009432001f49Smrg
1009532001f49Smrg      test -n "$rpath" && \
100967ec3b29aSmrg	func_warning "'-rpath' is ignored for objects"
1009732001f49Smrg
1009832001f49Smrg      test -n "$xrpath" && \
100997ec3b29aSmrg	func_warning "'-R' is ignored for objects"
1010032001f49Smrg
1010132001f49Smrg      test -n "$vinfo" && \
101027ec3b29aSmrg	func_warning "'-version-info' is ignored for objects"
1010332001f49Smrg
1010432001f49Smrg      test -n "$release" && \
101057ec3b29aSmrg	func_warning "'-release' is ignored for objects"
1010632001f49Smrg
1010732001f49Smrg      case $output in
1010832001f49Smrg      *.lo)
1010932001f49Smrg	test -n "$objs$old_deplibs" && \
101107ec3b29aSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1011132001f49Smrg
1011232001f49Smrg	libobj=$output
1011332001f49Smrg	func_lo2o "$libobj"
1011432001f49Smrg	obj=$func_lo2o_result
1011532001f49Smrg	;;
1011632001f49Smrg      *)
1011732001f49Smrg	libobj=
101187ec3b29aSmrg	obj=$output
1011932001f49Smrg	;;
1012032001f49Smrg      esac
1012132001f49Smrg
1012232001f49Smrg      # Delete the old objects.
1012332001f49Smrg      $opt_dry_run || $RM $obj $libobj
1012432001f49Smrg
1012532001f49Smrg      # Objects from convenience libraries.  This assumes
1012632001f49Smrg      # single-version convenience libraries.  Whenever we create
1012732001f49Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1012832001f49Smrg      # the extraction.
1012932001f49Smrg      reload_conv_objs=
1013032001f49Smrg      gentop=
101317ec3b29aSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
101327ec3b29aSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
101337ec3b29aSmrg      # into space.
101347ec3b29aSmrg      case $reload_cmds in
101357ec3b29aSmrg        *\$LD[\ \$]*) wl= ;;
101367ec3b29aSmrg      esac
1013732001f49Smrg      if test -n "$convenience"; then
1013832001f49Smrg	if test -n "$whole_archive_flag_spec"; then
1013932001f49Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
101407ec3b29aSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
101417ec3b29aSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
1014232001f49Smrg	else
101437ec3b29aSmrg	  gentop=$output_objdir/${obj}x
1014432001f49Smrg	  func_append generated " $gentop"
1014532001f49Smrg
1014632001f49Smrg	  func_extract_archives $gentop $convenience
1014732001f49Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
1014832001f49Smrg	fi
1014932001f49Smrg      fi
1015032001f49Smrg
1015132001f49Smrg      # If we're not building shared, we need to use non_pic_objs
101527ec3b29aSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
1015332001f49Smrg
1015432001f49Smrg      # Create the old-style object.
101557ec3b29aSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
1015632001f49Smrg
101577ec3b29aSmrg      output=$obj
1015832001f49Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
1015932001f49Smrg
1016032001f49Smrg      # Exit if we aren't doing a library object file.
1016132001f49Smrg      if test -z "$libobj"; then
1016232001f49Smrg	if test -n "$gentop"; then
1016332001f49Smrg	  func_show_eval '${RM}r "$gentop"'
1016432001f49Smrg	fi
1016532001f49Smrg
1016632001f49Smrg	exit $EXIT_SUCCESS
1016732001f49Smrg      fi
1016832001f49Smrg
101697ec3b29aSmrg      test yes = "$build_libtool_libs" || {
1017032001f49Smrg	if test -n "$gentop"; then
1017132001f49Smrg	  func_show_eval '${RM}r "$gentop"'
1017232001f49Smrg	fi
1017332001f49Smrg
1017432001f49Smrg	# Create an invalid libtool object if no PIC, so that we don't
1017532001f49Smrg	# accidentally link it into a program.
1017632001f49Smrg	# $show "echo timestamp > $libobj"
1017732001f49Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1017832001f49Smrg	exit $EXIT_SUCCESS
101797ec3b29aSmrg      }
1018032001f49Smrg
101817ec3b29aSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1018232001f49Smrg	# Only do commands if we really have different PIC objects.
1018332001f49Smrg	reload_objs="$libobjs $reload_conv_objs"
101847ec3b29aSmrg	output=$libobj
1018532001f49Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
1018632001f49Smrg      fi
1018732001f49Smrg
1018832001f49Smrg      if test -n "$gentop"; then
1018932001f49Smrg	func_show_eval '${RM}r "$gentop"'
1019032001f49Smrg      fi
1019132001f49Smrg
1019232001f49Smrg      exit $EXIT_SUCCESS
1019332001f49Smrg      ;;
1019432001f49Smrg
1019532001f49Smrg    prog)
1019632001f49Smrg      case $host in
1019732001f49Smrg	*cygwin*) func_stripname '' '.exe' "$output"
1019832001f49Smrg	          output=$func_stripname_result.exe;;
1019932001f49Smrg      esac
1020032001f49Smrg      test -n "$vinfo" && \
102017ec3b29aSmrg	func_warning "'-version-info' is ignored for programs"
1020232001f49Smrg
1020332001f49Smrg      test -n "$release" && \
102047ec3b29aSmrg	func_warning "'-release' is ignored for programs"
1020532001f49Smrg
102067ec3b29aSmrg      $preload \
102077ec3b29aSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
102087ec3b29aSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1020932001f49Smrg
1021032001f49Smrg      case $host in
1021132001f49Smrg      *-*-rhapsody* | *-*-darwin1.[012])
1021232001f49Smrg	# On Rhapsody replace the C library is the System framework
1021332001f49Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1021432001f49Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
1021532001f49Smrg	;;
1021632001f49Smrg      esac
1021732001f49Smrg
1021832001f49Smrg      case $host in
1021932001f49Smrg      *-*-darwin*)
1022032001f49Smrg	# Don't allow lazy linking, it breaks C++ global constructors
1022132001f49Smrg	# But is supposedly fixed on 10.4 or later (yay!).
102227ec3b29aSmrg	if test CXX = "$tagname"; then
1022332001f49Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1022432001f49Smrg	    10.[0123])
102257ec3b29aSmrg	      func_append compile_command " $wl-bind_at_load"
102267ec3b29aSmrg	      func_append finalize_command " $wl-bind_at_load"
1022732001f49Smrg	    ;;
1022832001f49Smrg	  esac
1022932001f49Smrg	fi
1023032001f49Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1023132001f49Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1023232001f49Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1023332001f49Smrg	;;
1023432001f49Smrg      esac
1023532001f49Smrg
1023632001f49Smrg
1023732001f49Smrg      # move library search paths that coincide with paths to not yet
1023832001f49Smrg      # installed libraries to the beginning of the library search list
1023932001f49Smrg      new_libs=
1024032001f49Smrg      for path in $notinst_path; do
1024132001f49Smrg	case " $new_libs " in
1024232001f49Smrg	*" -L$path/$objdir "*) ;;
1024332001f49Smrg	*)
1024432001f49Smrg	  case " $compile_deplibs " in
1024532001f49Smrg	  *" -L$path/$objdir "*)
1024632001f49Smrg	    func_append new_libs " -L$path/$objdir" ;;
1024732001f49Smrg	  esac
1024832001f49Smrg	  ;;
1024932001f49Smrg	esac
1025032001f49Smrg      done
1025132001f49Smrg      for deplib in $compile_deplibs; do
1025232001f49Smrg	case $deplib in
1025332001f49Smrg	-L*)
1025432001f49Smrg	  case " $new_libs " in
1025532001f49Smrg	  *" $deplib "*) ;;
1025632001f49Smrg	  *) func_append new_libs " $deplib" ;;
1025732001f49Smrg	  esac
1025832001f49Smrg	  ;;
1025932001f49Smrg	*) func_append new_libs " $deplib" ;;
1026032001f49Smrg	esac
1026132001f49Smrg      done
102627ec3b29aSmrg      compile_deplibs=$new_libs
1026332001f49Smrg
1026432001f49Smrg
1026532001f49Smrg      func_append compile_command " $compile_deplibs"
1026632001f49Smrg      func_append finalize_command " $finalize_deplibs"
1026732001f49Smrg
1026832001f49Smrg      if test -n "$rpath$xrpath"; then
1026932001f49Smrg	# If the user specified any rpath flags, then add them.
1027032001f49Smrg	for libdir in $rpath $xrpath; do
1027132001f49Smrg	  # This is the magic to use -rpath.
1027232001f49Smrg	  case "$finalize_rpath " in
1027332001f49Smrg	  *" $libdir "*) ;;
1027432001f49Smrg	  *) func_append finalize_rpath " $libdir" ;;
1027532001f49Smrg	  esac
1027632001f49Smrg	done
1027732001f49Smrg      fi
1027832001f49Smrg
1027932001f49Smrg      # Now hardcode the library paths
1028032001f49Smrg      rpath=
1028132001f49Smrg      hardcode_libdirs=
1028232001f49Smrg      for libdir in $compile_rpath $finalize_rpath; do
1028332001f49Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1028432001f49Smrg	  if test -n "$hardcode_libdir_separator"; then
1028532001f49Smrg	    if test -z "$hardcode_libdirs"; then
102867ec3b29aSmrg	      hardcode_libdirs=$libdir
1028732001f49Smrg	    else
1028832001f49Smrg	      # Just accumulate the unique libdirs.
1028932001f49Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1029032001f49Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1029132001f49Smrg		;;
1029232001f49Smrg	      *)
1029332001f49Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1029432001f49Smrg		;;
1029532001f49Smrg	      esac
1029632001f49Smrg	    fi
1029732001f49Smrg	  else
1029832001f49Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1029932001f49Smrg	    func_append rpath " $flag"
1030032001f49Smrg	  fi
1030132001f49Smrg	elif test -n "$runpath_var"; then
1030232001f49Smrg	  case "$perm_rpath " in
1030332001f49Smrg	  *" $libdir "*) ;;
1030432001f49Smrg	  *) func_append perm_rpath " $libdir" ;;
1030532001f49Smrg	  esac
1030632001f49Smrg	fi
1030732001f49Smrg	case $host in
1030832001f49Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
103097ec3b29aSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1031032001f49Smrg	  case :$dllsearchpath: in
1031132001f49Smrg	  *":$libdir:"*) ;;
1031232001f49Smrg	  ::) dllsearchpath=$libdir;;
1031332001f49Smrg	  *) func_append dllsearchpath ":$libdir";;
1031432001f49Smrg	  esac
1031532001f49Smrg	  case :$dllsearchpath: in
1031632001f49Smrg	  *":$testbindir:"*) ;;
1031732001f49Smrg	  ::) dllsearchpath=$testbindir;;
1031832001f49Smrg	  *) func_append dllsearchpath ":$testbindir";;
1031932001f49Smrg	  esac
1032032001f49Smrg	  ;;
1032132001f49Smrg	esac
1032232001f49Smrg      done
1032332001f49Smrg      # Substitute the hardcoded libdirs into the rpath.
1032432001f49Smrg      if test -n "$hardcode_libdir_separator" &&
1032532001f49Smrg	 test -n "$hardcode_libdirs"; then
103267ec3b29aSmrg	libdir=$hardcode_libdirs
1032732001f49Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1032832001f49Smrg      fi
103297ec3b29aSmrg      compile_rpath=$rpath
1033032001f49Smrg
1033132001f49Smrg      rpath=
1033232001f49Smrg      hardcode_libdirs=
1033332001f49Smrg      for libdir in $finalize_rpath; do
1033432001f49Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1033532001f49Smrg	  if test -n "$hardcode_libdir_separator"; then
1033632001f49Smrg	    if test -z "$hardcode_libdirs"; then
103377ec3b29aSmrg	      hardcode_libdirs=$libdir
1033832001f49Smrg	    else
1033932001f49Smrg	      # Just accumulate the unique libdirs.
1034032001f49Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1034132001f49Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1034232001f49Smrg		;;
1034332001f49Smrg	      *)
1034432001f49Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1034532001f49Smrg		;;
1034632001f49Smrg	      esac
1034732001f49Smrg	    fi
1034832001f49Smrg	  else
1034932001f49Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1035032001f49Smrg	    func_append rpath " $flag"
1035132001f49Smrg	  fi
1035232001f49Smrg	elif test -n "$runpath_var"; then
1035332001f49Smrg	  case "$finalize_perm_rpath " in
1035432001f49Smrg	  *" $libdir "*) ;;
1035532001f49Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1035632001f49Smrg	  esac
1035732001f49Smrg	fi
1035832001f49Smrg      done
1035932001f49Smrg      # Substitute the hardcoded libdirs into the rpath.
1036032001f49Smrg      if test -n "$hardcode_libdir_separator" &&
1036132001f49Smrg	 test -n "$hardcode_libdirs"; then
103627ec3b29aSmrg	libdir=$hardcode_libdirs
1036332001f49Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1036432001f49Smrg      fi
103657ec3b29aSmrg      finalize_rpath=$rpath
1036632001f49Smrg
103677ec3b29aSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1036832001f49Smrg	# Transform all the library objects into standard objects.
1036932001f49Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1037032001f49Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1037132001f49Smrg      fi
1037232001f49Smrg
103737ec3b29aSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
1037432001f49Smrg
1037532001f49Smrg      # template prelinking step
1037632001f49Smrg      if test -n "$prelink_cmds"; then
1037732001f49Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1037832001f49Smrg      fi
1037932001f49Smrg
103807ec3b29aSmrg      wrappers_required=:
1038132001f49Smrg      case $host in
1038232001f49Smrg      *cegcc* | *mingw32ce*)
1038332001f49Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
103847ec3b29aSmrg        wrappers_required=false
1038532001f49Smrg        ;;
1038632001f49Smrg      *cygwin* | *mingw* )
103877ec3b29aSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
1038832001f49Smrg        ;;
1038932001f49Smrg      *)
103907ec3b29aSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
103917ec3b29aSmrg          wrappers_required=false
1039232001f49Smrg        fi
1039332001f49Smrg        ;;
1039432001f49Smrg      esac
103957ec3b29aSmrg      $wrappers_required || {
1039632001f49Smrg	# Replace the output file specification.
1039732001f49Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
103987ec3b29aSmrg	link_command=$compile_command$compile_rpath
1039932001f49Smrg
1040032001f49Smrg	# We have no uninstalled library dependencies, so finalize right now.
1040132001f49Smrg	exit_status=0
1040232001f49Smrg	func_show_eval "$link_command" 'exit_status=$?'
1040332001f49Smrg
1040432001f49Smrg	if test -n "$postlink_cmds"; then
1040532001f49Smrg	  func_to_tool_file "$output"
1040632001f49Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1040732001f49Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1040832001f49Smrg	fi
1040932001f49Smrg
1041032001f49Smrg	# Delete the generated files.
104117ec3b29aSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
104127ec3b29aSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
1041332001f49Smrg	fi
1041432001f49Smrg
1041532001f49Smrg	exit $exit_status
104167ec3b29aSmrg      }
1041732001f49Smrg
1041832001f49Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1041932001f49Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1042032001f49Smrg      fi
1042132001f49Smrg      if test -n "$finalize_shlibpath"; then
1042232001f49Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1042332001f49Smrg      fi
1042432001f49Smrg
1042532001f49Smrg      compile_var=
1042632001f49Smrg      finalize_var=
1042732001f49Smrg      if test -n "$runpath_var"; then
1042832001f49Smrg	if test -n "$perm_rpath"; then
1042932001f49Smrg	  # We should set the runpath_var.
1043032001f49Smrg	  rpath=
1043132001f49Smrg	  for dir in $perm_rpath; do
1043232001f49Smrg	    func_append rpath "$dir:"
1043332001f49Smrg	  done
1043432001f49Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
1043532001f49Smrg	fi
1043632001f49Smrg	if test -n "$finalize_perm_rpath"; then
1043732001f49Smrg	  # We should set the runpath_var.
1043832001f49Smrg	  rpath=
1043932001f49Smrg	  for dir in $finalize_perm_rpath; do
1044032001f49Smrg	    func_append rpath "$dir:"
1044132001f49Smrg	  done
1044232001f49Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
1044332001f49Smrg	fi
1044432001f49Smrg      fi
1044532001f49Smrg
104467ec3b29aSmrg      if test yes = "$no_install"; then
1044732001f49Smrg	# We don't need to create a wrapper script.
104487ec3b29aSmrg	link_command=$compile_var$compile_command$compile_rpath
1044932001f49Smrg	# Replace the output file specification.
1045032001f49Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1045132001f49Smrg	# Delete the old output file.
1045232001f49Smrg	$opt_dry_run || $RM $output
1045332001f49Smrg	# Link the executable and exit
1045432001f49Smrg	func_show_eval "$link_command" 'exit $?'
1045532001f49Smrg
1045632001f49Smrg	if test -n "$postlink_cmds"; then
1045732001f49Smrg	  func_to_tool_file "$output"
1045832001f49Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1045932001f49Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1046032001f49Smrg	fi
1046132001f49Smrg
1046232001f49Smrg	exit $EXIT_SUCCESS
1046332001f49Smrg      fi
1046432001f49Smrg
104657ec3b29aSmrg      case $hardcode_action,$fast_install in
104667ec3b29aSmrg        relink,*)
104677ec3b29aSmrg	  # Fast installation is not supported
104687ec3b29aSmrg	  link_command=$compile_var$compile_command$compile_rpath
104697ec3b29aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1047032001f49Smrg
104717ec3b29aSmrg	  func_warning "this platform does not like uninstalled shared libraries"
104727ec3b29aSmrg	  func_warning "'$output' will be relinked during installation"
104737ec3b29aSmrg	  ;;
104747ec3b29aSmrg        *,yes)
104757ec3b29aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
104767ec3b29aSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
104777ec3b29aSmrg          ;;
104787ec3b29aSmrg	*,no)
104797ec3b29aSmrg	  link_command=$compile_var$compile_command$compile_rpath
104807ec3b29aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
104817ec3b29aSmrg          ;;
104827ec3b29aSmrg	*,needless)
104837ec3b29aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
104847ec3b29aSmrg	  relink_command=
104857ec3b29aSmrg          ;;
104867ec3b29aSmrg      esac
1048732001f49Smrg
1048832001f49Smrg      # Replace the output file specification.
1048932001f49Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
1049032001f49Smrg
1049132001f49Smrg      # Delete the old output files.
1049232001f49Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
1049332001f49Smrg
1049432001f49Smrg      func_show_eval "$link_command" 'exit $?'
1049532001f49Smrg
1049632001f49Smrg      if test -n "$postlink_cmds"; then
1049732001f49Smrg	func_to_tool_file "$output_objdir/$outputname"
1049832001f49Smrg	postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1049932001f49Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1050032001f49Smrg      fi
1050132001f49Smrg
1050232001f49Smrg      # Now create the wrapper script.
1050332001f49Smrg      func_verbose "creating $output"
1050432001f49Smrg
1050532001f49Smrg      # Quote the relink command for shipping.
1050632001f49Smrg      if test -n "$relink_command"; then
1050732001f49Smrg	# Preserve any variables that may affect compiler behavior
1050832001f49Smrg	for var in $variables_saved_for_relink; do
1050932001f49Smrg	  if eval test -z \"\${$var+set}\"; then
1051032001f49Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1051132001f49Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1051232001f49Smrg	    relink_command="$var=; export $var; $relink_command"
1051332001f49Smrg	  else
1051432001f49Smrg	    func_quote_for_eval "$var_value"
1051532001f49Smrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
1051632001f49Smrg	  fi
1051732001f49Smrg	done
1051832001f49Smrg	relink_command="(cd `pwd`; $relink_command)"
1051932001f49Smrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
1052032001f49Smrg      fi
1052132001f49Smrg
1052232001f49Smrg      # Only actually do things if not in dry run mode.
1052332001f49Smrg      $opt_dry_run || {
1052432001f49Smrg	# win32 will think the script is a binary if it has
1052532001f49Smrg	# a .exe suffix, so we strip it off here.
1052632001f49Smrg	case $output in
1052732001f49Smrg	  *.exe) func_stripname '' '.exe' "$output"
1052832001f49Smrg	         output=$func_stripname_result ;;
1052932001f49Smrg	esac
1053032001f49Smrg	# test for cygwin because mv fails w/o .exe extensions
1053132001f49Smrg	case $host in
1053232001f49Smrg	  *cygwin*)
1053332001f49Smrg	    exeext=.exe
1053432001f49Smrg	    func_stripname '' '.exe' "$outputname"
1053532001f49Smrg	    outputname=$func_stripname_result ;;
1053632001f49Smrg	  *) exeext= ;;
1053732001f49Smrg	esac
1053832001f49Smrg	case $host in
1053932001f49Smrg	  *cygwin* | *mingw* )
1054032001f49Smrg	    func_dirname_and_basename "$output" "" "."
1054132001f49Smrg	    output_name=$func_basename_result
1054232001f49Smrg	    output_path=$func_dirname_result
105437ec3b29aSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
105447ec3b29aSmrg	    cwrapper=$output_path/$output_name.exe
1054532001f49Smrg	    $RM $cwrappersource $cwrapper
1054632001f49Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1054732001f49Smrg
1054832001f49Smrg	    func_emit_cwrapperexe_src > $cwrappersource
1054932001f49Smrg
1055032001f49Smrg	    # The wrapper executable is built using the $host compiler,
1055132001f49Smrg	    # because it contains $host paths and files. If cross-
1055232001f49Smrg	    # compiling, it, like the target executable, must be
1055332001f49Smrg	    # executed on the $host or under an emulation environment.
1055432001f49Smrg	    $opt_dry_run || {
1055532001f49Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1055632001f49Smrg	      $STRIP $cwrapper
1055732001f49Smrg	    }
1055832001f49Smrg
1055932001f49Smrg	    # Now, create the wrapper script for func_source use:
1056032001f49Smrg	    func_ltwrapper_scriptname $cwrapper
1056132001f49Smrg	    $RM $func_ltwrapper_scriptname_result
1056232001f49Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1056332001f49Smrg	    $opt_dry_run || {
1056432001f49Smrg	      # note: this script will not be executed, so do not chmod.
105657ec3b29aSmrg	      if test "x$build" = "x$host"; then
1056632001f49Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1056732001f49Smrg	      else
1056832001f49Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1056932001f49Smrg	      fi
1057032001f49Smrg	    }
1057132001f49Smrg	  ;;
1057232001f49Smrg	  * )
1057332001f49Smrg	    $RM $output
1057432001f49Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
1057532001f49Smrg
1057632001f49Smrg	    func_emit_wrapper no > $output
1057732001f49Smrg	    chmod +x $output
1057832001f49Smrg	  ;;
1057932001f49Smrg	esac
1058032001f49Smrg      }
1058132001f49Smrg      exit $EXIT_SUCCESS
1058232001f49Smrg      ;;
1058332001f49Smrg    esac
1058432001f49Smrg
1058532001f49Smrg    # See if we need to build an old-fashioned archive.
1058632001f49Smrg    for oldlib in $oldlibs; do
1058732001f49Smrg
105887ec3b29aSmrg      case $build_libtool_libs in
105897ec3b29aSmrg        convenience)
105907ec3b29aSmrg	  oldobjs="$libobjs_save $symfileobj"
105917ec3b29aSmrg	  addlibs=$convenience
1059232001f49Smrg	  build_libtool_libs=no
105937ec3b29aSmrg	  ;;
105947ec3b29aSmrg	module)
105957ec3b29aSmrg	  oldobjs=$libobjs_save
105967ec3b29aSmrg	  addlibs=$old_convenience
105977ec3b29aSmrg	  build_libtool_libs=no
105987ec3b29aSmrg          ;;
105997ec3b29aSmrg	*)
1060032001f49Smrg	  oldobjs="$old_deplibs $non_pic_objects"
106017ec3b29aSmrg	  $preload && test -f "$symfileobj" \
106027ec3b29aSmrg	    && func_append oldobjs " $symfileobj"
106037ec3b29aSmrg	  addlibs=$old_convenience
106047ec3b29aSmrg	  ;;
106057ec3b29aSmrg      esac
1060632001f49Smrg
1060732001f49Smrg      if test -n "$addlibs"; then
106087ec3b29aSmrg	gentop=$output_objdir/${outputname}x
1060932001f49Smrg	func_append generated " $gentop"
1061032001f49Smrg
1061132001f49Smrg	func_extract_archives $gentop $addlibs
1061232001f49Smrg	func_append oldobjs " $func_extract_archives_result"
1061332001f49Smrg      fi
1061432001f49Smrg
1061532001f49Smrg      # Do each command in the archive commands.
106167ec3b29aSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1061732001f49Smrg	cmds=$old_archive_from_new_cmds
1061832001f49Smrg      else
1061932001f49Smrg
1062032001f49Smrg	# Add any objects from preloaded convenience libraries
1062132001f49Smrg	if test -n "$dlprefiles"; then
106227ec3b29aSmrg	  gentop=$output_objdir/${outputname}x
1062332001f49Smrg	  func_append generated " $gentop"
1062432001f49Smrg
1062532001f49Smrg	  func_extract_archives $gentop $dlprefiles
1062632001f49Smrg	  func_append oldobjs " $func_extract_archives_result"
1062732001f49Smrg	fi
1062832001f49Smrg
1062932001f49Smrg	# POSIX demands no paths to be encoded in archives.  We have
1063032001f49Smrg	# to avoid creating archives with duplicate basenames if we
1063132001f49Smrg	# might have to extract them afterwards, e.g., when creating a
1063232001f49Smrg	# static archive out of a convenience library, or when linking
1063332001f49Smrg	# the entirety of a libtool archive into another (currently
1063432001f49Smrg	# not supported by libtool).
1063532001f49Smrg	if (for obj in $oldobjs
1063632001f49Smrg	    do
1063732001f49Smrg	      func_basename "$obj"
1063832001f49Smrg	      $ECHO "$func_basename_result"
1063932001f49Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
1064032001f49Smrg	  :
1064132001f49Smrg	else
1064232001f49Smrg	  echo "copying selected object files to avoid basename conflicts..."
106437ec3b29aSmrg	  gentop=$output_objdir/${outputname}x
1064432001f49Smrg	  func_append generated " $gentop"
1064532001f49Smrg	  func_mkdir_p "$gentop"
1064632001f49Smrg	  save_oldobjs=$oldobjs
1064732001f49Smrg	  oldobjs=
1064832001f49Smrg	  counter=1
1064932001f49Smrg	  for obj in $save_oldobjs
1065032001f49Smrg	  do
1065132001f49Smrg	    func_basename "$obj"
106527ec3b29aSmrg	    objbase=$func_basename_result
1065332001f49Smrg	    case " $oldobjs " in
1065432001f49Smrg	    " ") oldobjs=$obj ;;
1065532001f49Smrg	    *[\ /]"$objbase "*)
1065632001f49Smrg	      while :; do
1065732001f49Smrg		# Make sure we don't pick an alternate name that also
1065832001f49Smrg		# overlaps.
1065932001f49Smrg		newobj=lt$counter-$objbase
1066032001f49Smrg		func_arith $counter + 1
1066132001f49Smrg		counter=$func_arith_result
1066232001f49Smrg		case " $oldobjs " in
1066332001f49Smrg		*[\ /]"$newobj "*) ;;
1066432001f49Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1066532001f49Smrg		esac
1066632001f49Smrg	      done
1066732001f49Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1066832001f49Smrg	      func_append oldobjs " $gentop/$newobj"
1066932001f49Smrg	      ;;
1067032001f49Smrg	    *) func_append oldobjs " $obj" ;;
1067132001f49Smrg	    esac
1067232001f49Smrg	  done
1067332001f49Smrg	fi
1067432001f49Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
1067532001f49Smrg	tool_oldlib=$func_to_tool_file_result
1067632001f49Smrg	eval cmds=\"$old_archive_cmds\"
1067732001f49Smrg
1067832001f49Smrg	func_len " $cmds"
1067932001f49Smrg	len=$func_len_result
1068032001f49Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1068132001f49Smrg	  cmds=$old_archive_cmds
1068232001f49Smrg	elif test -n "$archiver_list_spec"; then
1068332001f49Smrg	  func_verbose "using command file archive linking..."
1068432001f49Smrg	  for obj in $oldobjs
1068532001f49Smrg	  do
1068632001f49Smrg	    func_to_tool_file "$obj"
1068732001f49Smrg	    $ECHO "$func_to_tool_file_result"
1068832001f49Smrg	  done > $output_objdir/$libname.libcmd
1068932001f49Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1069032001f49Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1069132001f49Smrg	  cmds=$old_archive_cmds
1069232001f49Smrg	else
1069332001f49Smrg	  # the command line is too long to link in one step, link in parts
1069432001f49Smrg	  func_verbose "using piecewise archive linking..."
1069532001f49Smrg	  save_RANLIB=$RANLIB
1069632001f49Smrg	  RANLIB=:
1069732001f49Smrg	  objlist=
1069832001f49Smrg	  concat_cmds=
1069932001f49Smrg	  save_oldobjs=$oldobjs
1070032001f49Smrg	  oldobjs=
1070132001f49Smrg	  # Is there a better way of finding the last object in the list?
1070232001f49Smrg	  for obj in $save_oldobjs
1070332001f49Smrg	  do
1070432001f49Smrg	    last_oldobj=$obj
1070532001f49Smrg	  done
1070632001f49Smrg	  eval test_cmds=\"$old_archive_cmds\"
1070732001f49Smrg	  func_len " $test_cmds"
1070832001f49Smrg	  len0=$func_len_result
1070932001f49Smrg	  len=$len0
1071032001f49Smrg	  for obj in $save_oldobjs
1071132001f49Smrg	  do
1071232001f49Smrg	    func_len " $obj"
1071332001f49Smrg	    func_arith $len + $func_len_result
1071432001f49Smrg	    len=$func_arith_result
1071532001f49Smrg	    func_append objlist " $obj"
1071632001f49Smrg	    if test "$len" -lt "$max_cmd_len"; then
1071732001f49Smrg	      :
1071832001f49Smrg	    else
1071932001f49Smrg	      # the above command should be used before it gets too long
1072032001f49Smrg	      oldobjs=$objlist
107217ec3b29aSmrg	      if test "$obj" = "$last_oldobj"; then
1072232001f49Smrg		RANLIB=$save_RANLIB
1072332001f49Smrg	      fi
1072432001f49Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
107257ec3b29aSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1072632001f49Smrg	      objlist=
1072732001f49Smrg	      len=$len0
1072832001f49Smrg	    fi
1072932001f49Smrg	  done
1073032001f49Smrg	  RANLIB=$save_RANLIB
1073132001f49Smrg	  oldobjs=$objlist
107327ec3b29aSmrg	  if test -z "$oldobjs"; then
1073332001f49Smrg	    eval cmds=\"\$concat_cmds\"
1073432001f49Smrg	  else
1073532001f49Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1073632001f49Smrg	  fi
1073732001f49Smrg	fi
1073832001f49Smrg      fi
1073932001f49Smrg      func_execute_cmds "$cmds" 'exit $?'
1074032001f49Smrg    done
1074132001f49Smrg
1074232001f49Smrg    test -n "$generated" && \
1074332001f49Smrg      func_show_eval "${RM}r$generated"
1074432001f49Smrg
1074532001f49Smrg    # Now create the libtool archive.
1074632001f49Smrg    case $output in
1074732001f49Smrg    *.la)
1074832001f49Smrg      old_library=
107497ec3b29aSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1075032001f49Smrg      func_verbose "creating $output"
1075132001f49Smrg
1075232001f49Smrg      # Preserve any variables that may affect compiler behavior
1075332001f49Smrg      for var in $variables_saved_for_relink; do
1075432001f49Smrg	if eval test -z \"\${$var+set}\"; then
1075532001f49Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1075632001f49Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
1075732001f49Smrg	  relink_command="$var=; export $var; $relink_command"
1075832001f49Smrg	else
1075932001f49Smrg	  func_quote_for_eval "$var_value"
1076032001f49Smrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
1076132001f49Smrg	fi
1076232001f49Smrg      done
1076332001f49Smrg      # Quote the link command for shipping.
107647ec3b29aSmrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1076532001f49Smrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
107667ec3b29aSmrg      if test yes = "$hardcode_automatic"; then
1076732001f49Smrg	relink_command=
1076832001f49Smrg      fi
1076932001f49Smrg
1077032001f49Smrg      # Only create the output if not a dry run.
1077132001f49Smrg      $opt_dry_run || {
1077232001f49Smrg	for installed in no yes; do
107737ec3b29aSmrg	  if test yes = "$installed"; then
1077432001f49Smrg	    if test -z "$install_libdir"; then
1077532001f49Smrg	      break
1077632001f49Smrg	    fi
107777ec3b29aSmrg	    output=$output_objdir/${outputname}i
1077832001f49Smrg	    # Replace all uninstalled libtool libraries with the installed ones
1077932001f49Smrg	    newdependency_libs=
1078032001f49Smrg	    for deplib in $dependency_libs; do
1078132001f49Smrg	      case $deplib in
1078232001f49Smrg	      *.la)
1078332001f49Smrg		func_basename "$deplib"
107847ec3b29aSmrg		name=$func_basename_result
1078532001f49Smrg		func_resolve_sysroot "$deplib"
107867ec3b29aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1078732001f49Smrg		test -z "$libdir" && \
107887ec3b29aSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1078932001f49Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1079032001f49Smrg		;;
1079132001f49Smrg	      -L*)
1079232001f49Smrg		func_stripname -L '' "$deplib"
1079332001f49Smrg		func_replace_sysroot "$func_stripname_result"
1079432001f49Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1079532001f49Smrg		;;
1079632001f49Smrg	      -R*)
1079732001f49Smrg		func_stripname -R '' "$deplib"
1079832001f49Smrg		func_replace_sysroot "$func_stripname_result"
1079932001f49Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
1080032001f49Smrg		;;
1080132001f49Smrg	      *) func_append newdependency_libs " $deplib" ;;
1080232001f49Smrg	      esac
1080332001f49Smrg	    done
108047ec3b29aSmrg	    dependency_libs=$newdependency_libs
1080532001f49Smrg	    newdlfiles=
1080632001f49Smrg
1080732001f49Smrg	    for lib in $dlfiles; do
1080832001f49Smrg	      case $lib in
1080932001f49Smrg	      *.la)
1081032001f49Smrg	        func_basename "$lib"
108117ec3b29aSmrg		name=$func_basename_result
108127ec3b29aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1081332001f49Smrg		test -z "$libdir" && \
108147ec3b29aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1081532001f49Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1081632001f49Smrg		;;
1081732001f49Smrg	      *) func_append newdlfiles " $lib" ;;
1081832001f49Smrg	      esac
1081932001f49Smrg	    done
108207ec3b29aSmrg	    dlfiles=$newdlfiles
1082132001f49Smrg	    newdlprefiles=
1082232001f49Smrg	    for lib in $dlprefiles; do
1082332001f49Smrg	      case $lib in
1082432001f49Smrg	      *.la)
1082532001f49Smrg		# Only pass preopened files to the pseudo-archive (for
1082632001f49Smrg		# eventual linking with the app. that links it) if we
1082732001f49Smrg		# didn't already link the preopened objects directly into
1082832001f49Smrg		# the library:
1082932001f49Smrg		func_basename "$lib"
108307ec3b29aSmrg		name=$func_basename_result
108317ec3b29aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1083232001f49Smrg		test -z "$libdir" && \
108337ec3b29aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1083432001f49Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1083532001f49Smrg		;;
1083632001f49Smrg	      esac
1083732001f49Smrg	    done
108387ec3b29aSmrg	    dlprefiles=$newdlprefiles
1083932001f49Smrg	  else
1084032001f49Smrg	    newdlfiles=
1084132001f49Smrg	    for lib in $dlfiles; do
1084232001f49Smrg	      case $lib in
108437ec3b29aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1084432001f49Smrg		*) abs=`pwd`"/$lib" ;;
1084532001f49Smrg	      esac
1084632001f49Smrg	      func_append newdlfiles " $abs"
1084732001f49Smrg	    done
108487ec3b29aSmrg	    dlfiles=$newdlfiles
1084932001f49Smrg	    newdlprefiles=
1085032001f49Smrg	    for lib in $dlprefiles; do
1085132001f49Smrg	      case $lib in
108527ec3b29aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1085332001f49Smrg		*) abs=`pwd`"/$lib" ;;
1085432001f49Smrg	      esac
1085532001f49Smrg	      func_append newdlprefiles " $abs"
1085632001f49Smrg	    done
108577ec3b29aSmrg	    dlprefiles=$newdlprefiles
1085832001f49Smrg	  fi
1085932001f49Smrg	  $RM $output
1086032001f49Smrg	  # place dlname in correct position for cygwin
1086132001f49Smrg	  # In fact, it would be nice if we could use this code for all target
1086232001f49Smrg	  # systems that can't hard-code library paths into their executables
1086332001f49Smrg	  # and that have no shared library path variable independent of PATH,
1086432001f49Smrg	  # but it turns out we can't easily determine that from inspecting
1086532001f49Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1086632001f49Smrg	  # applies here; at the moment, that means platforms that use the PE
1086732001f49Smrg	  # object format with DLL files.  See the long comment at the top of
1086832001f49Smrg	  # tests/bindir.at for full details.
1086932001f49Smrg	  tdlname=$dlname
1087032001f49Smrg	  case $host,$output,$installed,$module,$dlname in
1087132001f49Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1087232001f49Smrg	      # If a -bindir argument was supplied, place the dll there.
108737ec3b29aSmrg	      if test -n "$bindir"; then
1087432001f49Smrg		func_relative_path "$install_libdir" "$bindir"
108757ec3b29aSmrg		tdlname=$func_relative_path_result/$dlname
1087632001f49Smrg	      else
1087732001f49Smrg		# Otherwise fall back on heuristic.
1087832001f49Smrg		tdlname=../bin/$dlname
1087932001f49Smrg	      fi
1088032001f49Smrg	      ;;
1088132001f49Smrg	  esac
1088232001f49Smrg	  $ECHO > $output "\
1088332001f49Smrg# $outputname - a libtool library file
108847ec3b29aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1088532001f49Smrg#
1088632001f49Smrg# Please DO NOT delete this file!
1088732001f49Smrg# It is necessary for linking the library.
1088832001f49Smrg
1088932001f49Smrg# The name that we can dlopen(3).
1089032001f49Smrgdlname='$tdlname'
1089132001f49Smrg
1089232001f49Smrg# Names of this library.
1089332001f49Smrglibrary_names='$library_names'
1089432001f49Smrg
1089532001f49Smrg# The name of the static archive.
1089632001f49Smrgold_library='$old_library'
1089732001f49Smrg
108987ec3b29aSmrg# Linker flags that cannot go in dependency_libs.
1089932001f49Smrginherited_linker_flags='$new_inherited_linker_flags'
1090032001f49Smrg
1090132001f49Smrg# Libraries that this one depends upon.
1090232001f49Smrgdependency_libs='$dependency_libs'
1090332001f49Smrg
1090432001f49Smrg# Names of additional weak libraries provided by this library
1090532001f49Smrgweak_library_names='$weak_libs'
1090632001f49Smrg
1090732001f49Smrg# Version information for $libname.
1090832001f49Smrgcurrent=$current
1090932001f49Smrgage=$age
1091032001f49Smrgrevision=$revision
1091132001f49Smrg
1091232001f49Smrg# Is this an already installed library?
1091332001f49Smrginstalled=$installed
1091432001f49Smrg
1091532001f49Smrg# Should we warn about portability when linking against -modules?
1091632001f49Smrgshouldnotlink=$module
1091732001f49Smrg
1091832001f49Smrg# Files to dlopen/dlpreopen
1091932001f49Smrgdlopen='$dlfiles'
1092032001f49Smrgdlpreopen='$dlprefiles'
1092132001f49Smrg
1092232001f49Smrg# Directory that this library needs to be installed in:
1092332001f49Smrglibdir='$install_libdir'"
109247ec3b29aSmrg	  if test no,yes = "$installed,$need_relink"; then
1092532001f49Smrg	    $ECHO >> $output "\
1092632001f49Smrgrelink_command=\"$relink_command\""
1092732001f49Smrg	  fi
1092832001f49Smrg	done
1092932001f49Smrg      }
1093032001f49Smrg
1093132001f49Smrg      # Do a symbolic link so that the libtool archive can be found in
1093232001f49Smrg      # LD_LIBRARY_PATH before the program is installed.
1093332001f49Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1093432001f49Smrg      ;;
1093532001f49Smrg    esac
1093632001f49Smrg    exit $EXIT_SUCCESS
1093732001f49Smrg}
1093832001f49Smrg
109397ec3b29aSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
109407ec3b29aSmrg  func_mode_link ${1+"$@"}
109417ec3b29aSmrgfi
1094232001f49Smrg
1094332001f49Smrg
1094432001f49Smrg# func_mode_uninstall arg...
1094532001f49Smrgfunc_mode_uninstall ()
1094632001f49Smrg{
109477ec3b29aSmrg    $debug_cmd
109487ec3b29aSmrg
109497ec3b29aSmrg    RM=$nonopt
1095032001f49Smrg    files=
109517ec3b29aSmrg    rmforce=false
1095232001f49Smrg    exit_status=0
1095332001f49Smrg
1095432001f49Smrg    # This variable tells wrapper scripts just to set variables rather
1095532001f49Smrg    # than running their programs.
109567ec3b29aSmrg    libtool_install_magic=$magic
1095732001f49Smrg
1095832001f49Smrg    for arg
1095932001f49Smrg    do
1096032001f49Smrg      case $arg in
109617ec3b29aSmrg      -f) func_append RM " $arg"; rmforce=: ;;
1096232001f49Smrg      -*) func_append RM " $arg" ;;
1096332001f49Smrg      *) func_append files " $arg" ;;
1096432001f49Smrg      esac
1096532001f49Smrg    done
1096632001f49Smrg
1096732001f49Smrg    test -z "$RM" && \
1096832001f49Smrg      func_fatal_help "you must specify an RM program"
1096932001f49Smrg
1097032001f49Smrg    rmdirs=
1097132001f49Smrg
1097232001f49Smrg    for file in $files; do
1097332001f49Smrg      func_dirname "$file" "" "."
109747ec3b29aSmrg      dir=$func_dirname_result
109757ec3b29aSmrg      if test . = "$dir"; then
109767ec3b29aSmrg	odir=$objdir
1097732001f49Smrg      else
109787ec3b29aSmrg	odir=$dir/$objdir
1097932001f49Smrg      fi
1098032001f49Smrg      func_basename "$file"
109817ec3b29aSmrg      name=$func_basename_result
109827ec3b29aSmrg      test uninstall = "$opt_mode" && odir=$dir
1098332001f49Smrg
1098432001f49Smrg      # Remember odir for removal later, being careful to avoid duplicates
109857ec3b29aSmrg      if test clean = "$opt_mode"; then
1098632001f49Smrg	case " $rmdirs " in
1098732001f49Smrg	  *" $odir "*) ;;
1098832001f49Smrg	  *) func_append rmdirs " $odir" ;;
1098932001f49Smrg	esac
1099032001f49Smrg      fi
1099132001f49Smrg
1099232001f49Smrg      # Don't error if the file doesn't exist and rm -f was used.
1099332001f49Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1099432001f49Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1099532001f49Smrg	 test -f "$file"; then
1099632001f49Smrg	:
1099732001f49Smrg      elif test -d "$file"; then
1099832001f49Smrg	exit_status=1
1099932001f49Smrg	continue
110007ec3b29aSmrg      elif $rmforce; then
1100132001f49Smrg	continue
1100232001f49Smrg      fi
1100332001f49Smrg
110047ec3b29aSmrg      rmfiles=$file
1100532001f49Smrg
1100632001f49Smrg      case $name in
1100732001f49Smrg      *.la)
1100832001f49Smrg	# Possibly a libtool archive, so verify it.
1100932001f49Smrg	if func_lalib_p "$file"; then
1101032001f49Smrg	  func_source $dir/$name
1101132001f49Smrg
1101232001f49Smrg	  # Delete the libtool libraries and symlinks.
1101332001f49Smrg	  for n in $library_names; do
1101432001f49Smrg	    func_append rmfiles " $odir/$n"
1101532001f49Smrg	  done
1101632001f49Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
1101732001f49Smrg
110187ec3b29aSmrg	  case $opt_mode in
1101932001f49Smrg	  clean)
1102032001f49Smrg	    case " $library_names " in
1102132001f49Smrg	    *" $dlname "*) ;;
1102232001f49Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
1102332001f49Smrg	    esac
1102432001f49Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
1102532001f49Smrg	    ;;
1102632001f49Smrg	  uninstall)
1102732001f49Smrg	    if test -n "$library_names"; then
1102832001f49Smrg	      # Do each command in the postuninstall commands.
110297ec3b29aSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
1103032001f49Smrg	    fi
1103132001f49Smrg
1103232001f49Smrg	    if test -n "$old_library"; then
1103332001f49Smrg	      # Do each command in the old_postuninstall commands.
110347ec3b29aSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
1103532001f49Smrg	    fi
1103632001f49Smrg	    # FIXME: should reinstall the best remaining shared library.
1103732001f49Smrg	    ;;
1103832001f49Smrg	  esac
1103932001f49Smrg	fi
1104032001f49Smrg	;;
1104132001f49Smrg
1104232001f49Smrg      *.lo)
1104332001f49Smrg	# Possibly a libtool object, so verify it.
1104432001f49Smrg	if func_lalib_p "$file"; then
1104532001f49Smrg
1104632001f49Smrg	  # Read the .lo file
1104732001f49Smrg	  func_source $dir/$name
1104832001f49Smrg
1104932001f49Smrg	  # Add PIC object to the list of files to remove.
110507ec3b29aSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1105132001f49Smrg	    func_append rmfiles " $dir/$pic_object"
1105232001f49Smrg	  fi
1105332001f49Smrg
1105432001f49Smrg	  # Add non-PIC object to the list of files to remove.
110557ec3b29aSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1105632001f49Smrg	    func_append rmfiles " $dir/$non_pic_object"
1105732001f49Smrg	  fi
1105832001f49Smrg	fi
1105932001f49Smrg	;;
1106032001f49Smrg
1106132001f49Smrg      *)
110627ec3b29aSmrg	if test clean = "$opt_mode"; then
1106332001f49Smrg	  noexename=$name
1106432001f49Smrg	  case $file in
1106532001f49Smrg	  *.exe)
1106632001f49Smrg	    func_stripname '' '.exe' "$file"
1106732001f49Smrg	    file=$func_stripname_result
1106832001f49Smrg	    func_stripname '' '.exe' "$name"
1106932001f49Smrg	    noexename=$func_stripname_result
1107032001f49Smrg	    # $file with .exe has already been added to rmfiles,
1107132001f49Smrg	    # add $file without .exe
1107232001f49Smrg	    func_append rmfiles " $file"
1107332001f49Smrg	    ;;
1107432001f49Smrg	  esac
1107532001f49Smrg	  # Do a test to see if this is a libtool program.
1107632001f49Smrg	  if func_ltwrapper_p "$file"; then
1107732001f49Smrg	    if func_ltwrapper_executable_p "$file"; then
1107832001f49Smrg	      func_ltwrapper_scriptname "$file"
1107932001f49Smrg	      relink_command=
1108032001f49Smrg	      func_source $func_ltwrapper_scriptname_result
1108132001f49Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1108232001f49Smrg	    else
1108332001f49Smrg	      relink_command=
1108432001f49Smrg	      func_source $dir/$noexename
1108532001f49Smrg	    fi
1108632001f49Smrg
1108732001f49Smrg	    # note $name still contains .exe if it was in $file originally
1108832001f49Smrg	    # as does the version of $file that was added into $rmfiles
110897ec3b29aSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
110907ec3b29aSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1109132001f49Smrg	      func_append rmfiles " $odir/lt-$name"
1109232001f49Smrg	    fi
110937ec3b29aSmrg	    if test "X$noexename" != "X$name"; then
110947ec3b29aSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
1109532001f49Smrg	    fi
1109632001f49Smrg	  fi
1109732001f49Smrg	fi
1109832001f49Smrg	;;
1109932001f49Smrg      esac
1110032001f49Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
1110132001f49Smrg    done
1110232001f49Smrg
111037ec3b29aSmrg    # Try to remove the $objdir's in the directories where we deleted files
1110432001f49Smrg    for dir in $rmdirs; do
1110532001f49Smrg      if test -d "$dir"; then
1110632001f49Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
1110732001f49Smrg      fi
1110832001f49Smrg    done
1110932001f49Smrg
1111032001f49Smrg    exit $exit_status
1111132001f49Smrg}
1111232001f49Smrg
111137ec3b29aSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
111147ec3b29aSmrg  func_mode_uninstall ${1+"$@"}
111157ec3b29aSmrgfi
1111632001f49Smrg
1111732001f49Smrgtest -z "$opt_mode" && {
111187ec3b29aSmrg  help=$generic_help
1111932001f49Smrg  func_fatal_help "you must specify a MODE"
1112032001f49Smrg}
1112132001f49Smrg
1112232001f49Smrgtest -z "$exec_cmd" && \
111237ec3b29aSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
1112432001f49Smrg
1112532001f49Smrgif test -n "$exec_cmd"; then
1112632001f49Smrg  eval exec "$exec_cmd"
1112732001f49Smrg  exit $EXIT_FAILURE
1112832001f49Smrgfi
1112932001f49Smrg
1113032001f49Smrgexit $exit_status
1113132001f49Smrg
1113232001f49Smrg
1113332001f49Smrg# The TAGs below are defined such that we never get into a situation
111347ec3b29aSmrg# where we disable both kinds of libraries.  Given conflicting
1113532001f49Smrg# choices, we go for a static library, that is the most portable,
1113632001f49Smrg# since we can't tell whether shared libraries were disabled because
1113732001f49Smrg# the user asked for that or because the platform doesn't support
1113832001f49Smrg# them.  This is particularly important on AIX, because we don't
1113932001f49Smrg# support having both static and shared libraries enabled at the same
1114032001f49Smrg# time on that platform, so we default to a shared-only configuration.
1114132001f49Smrg# If a disable-shared tag is given, we'll fallback to a static-only
1114232001f49Smrg# configuration.  But we'll never go from static-only to shared-only.
1114332001f49Smrg
1114432001f49Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1114532001f49Smrgbuild_libtool_libs=no
1114632001f49Smrgbuild_old_libs=yes
1114732001f49Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
1114832001f49Smrg
1114932001f49Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1115032001f49Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
1115132001f49Smrg# ### END LIBTOOL TAG CONFIG: disable-static
1115232001f49Smrg
1115332001f49Smrg# Local Variables:
1115432001f49Smrg# mode:shell-script
1115532001f49Smrg# sh-indentation:2
1115632001f49Smrg# End:
11157