125420f97Smrg#! /usr/bin/env sh
28292847cSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
325420f97Smrg##               by inline-source v2019-02-19.15
4c2939121Smrg
525420f97Smrg# libtool (GNU libtool) 2.4.7
68292847cSmrg# Provide generalized library-building support services.
7c2939121Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8c2939121Smrg
925420f97Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10c2939121Smrg# This is free software; see the source for copying conditions.  There is NO
11c2939121Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12c2939121Smrg
13c2939121Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14c76ae52dSmrg# it under the terms of the GNU General Public License as published by
15c76ae52dSmrg# the Free Software Foundation; either version 2 of the License, or
16c76ae52dSmrg# (at your option) any later version.
17c76ae52dSmrg#
18c2939121Smrg# As a special exception to the GNU General Public License,
19c2939121Smrg# if you distribute this file as part of a program or library that
20c2939121Smrg# is built using GNU Libtool, you may include this file under the
21c2939121Smrg# same distribution terms that you use for the rest of that program.
22c2939121Smrg#
23c2939121Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24c76ae52dSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25c76ae52dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26c76ae52dSmrg# General Public License for more details.
27c76ae52dSmrg#
28c76ae52dSmrg# You should have received a copy of the GNU General Public License
298292847cSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30c76ae52dSmrg
31c76ae52dSmrg
32c2939121SmrgPROGRAM=libtool
33c76ae52dSmrgPACKAGE=libtool
34de301c82SmrgVERSION="2.4.7 Debian-2.4.7-7~deb12u1"
3525420f97Smrgpackage_revision=2.4.7
360d590c07Smrg
378292847cSmrg
388292847cSmrg## ------ ##
398292847cSmrg## Usage. ##
408292847cSmrg## ------ ##
418292847cSmrg
428292847cSmrg# Run './libtool --help' for help with using this script from the
438292847cSmrg# command line.
448292847cSmrg
458292847cSmrg
468292847cSmrg## ------------------------------- ##
478292847cSmrg## User overridable command paths. ##
488292847cSmrg## ------------------------------- ##
498292847cSmrg
508292847cSmrg# After configure completes, it has a better idea of some of the
518292847cSmrg# shell tools we need than the defaults used by the functions shared
528292847cSmrg# with bootstrap, so set those here where they can still be over-
538292847cSmrg# ridden by the user, but otherwise take precedence.
548292847cSmrg
558292847cSmrg: ${AUTOCONF="autoconf"}
568292847cSmrg: ${AUTOMAKE="automake"}
578292847cSmrg
588292847cSmrg
598292847cSmrg## -------------------------- ##
608292847cSmrg## Source external libraries. ##
618292847cSmrg## -------------------------- ##
628292847cSmrg
638292847cSmrg# Much of our low-level functionality needs to be sourced from external
648292847cSmrg# libraries, which are installed to $pkgauxdir.
658292847cSmrg
668292847cSmrg# Set a version string for this script.
6725420f97Smrgscriptversion=2019-02-19.15; # UTC
688292847cSmrg
698292847cSmrg# General shell script boiler plate, and helper functions.
708292847cSmrg# Written by Gary V. Vaughan, 2004
718292847cSmrg
7225420f97Smrg# This is free software.  There is NO warranty; not even for
7325420f97Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7425420f97Smrg#
7525420f97Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
7625420f97Smrg#
7725420f97Smrg# This file is dual licensed under the terms of the MIT license
7825420f97Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
7925420f97Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
8025420f97Smrg# these licenses when using or redistributing this software or any of
8125420f97Smrg# the files within it.  See the URLs above, or the file `LICENSE`
8225420f97Smrg# included in the Bootstrap distribution for the full license texts.
838292847cSmrg
8425420f97Smrg# Please report bugs or propose patches to:
8525420f97Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
868292847cSmrg
878292847cSmrg
888292847cSmrg## ------ ##
898292847cSmrg## Usage. ##
908292847cSmrg## ------ ##
918292847cSmrg
928292847cSmrg# Evaluate this file near the top of your script to gain access to
938292847cSmrg# the functions and variables defined here:
948292847cSmrg#
958292847cSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
968292847cSmrg#
978292847cSmrg# If you need to override any of the default environment variable
988292847cSmrg# settings, do that before evaluating this file.
998292847cSmrg
1008292847cSmrg
1018292847cSmrg## -------------------- ##
1028292847cSmrg## Shell normalisation. ##
1038292847cSmrg## -------------------- ##
1048292847cSmrg
1058292847cSmrg# Some shells need a little help to be as Bourne compatible as possible.
1068292847cSmrg# Before doing anything else, make sure all that help has been provided!
1078292847cSmrg
1088292847cSmrgDUALCASE=1; export DUALCASE # for MKS sh
1098292847cSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1100d590c07Smrg  emulate sh
1110d590c07Smrg  NULLCMD=:
1128292847cSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1130d590c07Smrg  # is contrary to our usage.  Disable this feature.
1140d590c07Smrg  alias -g '${1+"$@"}'='"$@"'
115c76ae52dSmrg  setopt NO_GLOB_SUBST
1160d590c07Smrgelse
1178292847cSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118c76ae52dSmrgfi
119c76ae52dSmrg
1208292847cSmrg# NLS nuisances: We save the old values in case they are required later.
1218292847cSmrg_G_user_locale=
1228292847cSmrg_G_safe_locale=
1238292847cSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1240d590c07Smrgdo
1258292847cSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1268292847cSmrg          save_$_G_var=\$$_G_var
1278292847cSmrg          $_G_var=C
1288292847cSmrg	  export $_G_var
1298292847cSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1308292847cSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1310d590c07Smrg	fi"
1320d590c07Smrgdone
13325420f97Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
13425420f97Smrg# in case the environment reset is needed later and the $save_* variant is not
13525420f97Smrg# defined (see the code above).
13625420f97SmrgLC_ALL=C
13725420f97SmrgLANGUAGE=C
13825420f97Smrgexport LANGUAGE LC_ALL
139c2939121Smrg
1408292847cSmrg# Make sure IFS has a sensible default
1418292847cSmrgsp=' '
1428292847cSmrgnl='
1438292847cSmrg'
1448292847cSmrgIFS="$sp	$nl"
1458292847cSmrg
1468292847cSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1478292847cSmrgif test "${PATH_SEPARATOR+set}" != set; then
1488292847cSmrg  PATH_SEPARATOR=:
1498292847cSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1508292847cSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1518292847cSmrg      PATH_SEPARATOR=';'
1528292847cSmrg  }
1538292847cSmrgfi
154c2939121Smrg
155c2939121Smrg
15625420f97Smrg# func_unset VAR
15725420f97Smrg# --------------
15825420f97Smrg# Portably unset VAR.
15925420f97Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
16025420f97Smrg# status if VAR is already unset, which might be problematic if the
16125420f97Smrg# statement is used at the end of a function (thus poisoning its return
16225420f97Smrg# value) or when 'set -e' is active (causing even a spurious abort of
16325420f97Smrg# the script in this case).
16425420f97Smrgfunc_unset ()
16525420f97Smrg{
16625420f97Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
16725420f97Smrg}
16825420f97Smrg
16925420f97Smrg
17025420f97Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
17125420f97Smrgfunc_unset CDPATH
17225420f97Smrg
17325420f97Smrg# Make sure ${,E,F}GREP behave sanely.
17425420f97Smrgfunc_unset GREP_OPTIONS
17525420f97Smrg
176c2939121Smrg
1778292847cSmrg## ------------------------- ##
1788292847cSmrg## Locate command utilities. ##
1798292847cSmrg## ------------------------- ##
1808292847cSmrg
1818292847cSmrg
1828292847cSmrg# func_executable_p FILE
1838292847cSmrg# ----------------------
1848292847cSmrg# Check that FILE is an executable regular file.
1858292847cSmrgfunc_executable_p ()
1868292847cSmrg{
1878292847cSmrg    test -f "$1" && test -x "$1"
1888292847cSmrg}
1898292847cSmrg
1908292847cSmrg
1918292847cSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1928292847cSmrg# --------------------------------------------
1938292847cSmrg# Search for either a program that responds to --version with output
1948292847cSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1958292847cSmrg# trying all the directories in PATH with each of the elements of
1968292847cSmrg# PROGS_LIST.
1978292847cSmrg#
1988292847cSmrg# CHECK_FUNC should accept the path to a candidate program, and
1998292847cSmrg# set $func_check_prog_result if it truncates its output less than
2008292847cSmrg# $_G_path_prog_max characters.
2018292847cSmrgfunc_path_progs ()
2028292847cSmrg{
2038292847cSmrg    _G_progs_list=$1
2048292847cSmrg    _G_check_func=$2
2058292847cSmrg    _G_PATH=${3-"$PATH"}
2068292847cSmrg
2078292847cSmrg    _G_path_prog_max=0
2088292847cSmrg    _G_path_prog_found=false
2098292847cSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
2108292847cSmrg    for _G_dir in $_G_PATH; do
2118292847cSmrg      IFS=$_G_save_IFS
2128292847cSmrg      test -z "$_G_dir" && _G_dir=.
2138292847cSmrg      for _G_prog_name in $_G_progs_list; do
2148292847cSmrg        for _exeext in '' .EXE; do
2158292847cSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2168292847cSmrg          func_executable_p "$_G_path_prog" || continue
2178292847cSmrg          case `"$_G_path_prog" --version 2>&1` in
2188292847cSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2198292847cSmrg            *)     $_G_check_func $_G_path_prog
2208292847cSmrg		   func_path_progs_result=$func_check_prog_result
2218292847cSmrg		   ;;
2228292847cSmrg          esac
2238292847cSmrg          $_G_path_prog_found && break 3
2248292847cSmrg        done
2258292847cSmrg      done
2268292847cSmrg    done
2278292847cSmrg    IFS=$_G_save_IFS
2288292847cSmrg    test -z "$func_path_progs_result" && {
2298292847cSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2308292847cSmrg      exit 1
2318292847cSmrg    }
2328292847cSmrg}
2338292847cSmrg
2348292847cSmrg
2358292847cSmrg# We want to be able to use the functions in this file before configure
2368292847cSmrg# has figured out where the best binaries are kept, which means we have
2378292847cSmrg# to search for them ourselves - except when the results are already set
2388292847cSmrg# where we skip the searches.
2398292847cSmrg
2408292847cSmrg# Unless the user overrides by setting SED, search the path for either GNU
2418292847cSmrg# sed, or the sed that truncates its output the least.
2428292847cSmrgtest -z "$SED" && {
2438292847cSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2448292847cSmrg  for _G_i in 1 2 3 4 5 6 7; do
2458292847cSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2468292847cSmrg  done
2478292847cSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2488292847cSmrg  _G_sed_script=
2498292847cSmrg
2508292847cSmrg  func_check_prog_sed ()
2518292847cSmrg  {
2528292847cSmrg    _G_path_prog=$1
2538292847cSmrg
2548292847cSmrg    _G_count=0
2558292847cSmrg    printf 0123456789 >conftest.in
2568292847cSmrg    while :
2578292847cSmrg    do
2588292847cSmrg      cat conftest.in conftest.in >conftest.tmp
2598292847cSmrg      mv conftest.tmp conftest.in
2608292847cSmrg      cp conftest.in conftest.nl
2618292847cSmrg      echo '' >> conftest.nl
2628292847cSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2638292847cSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2648292847cSmrg      _G_count=`expr $_G_count + 1`
2658292847cSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2668292847cSmrg        # Best one so far, save it but keep looking for a better one
2678292847cSmrg        func_check_prog_result=$_G_path_prog
2688292847cSmrg        _G_path_prog_max=$_G_count
2698292847cSmrg      fi
2708292847cSmrg      # 10*(2^10) chars as input seems more than enough
2718292847cSmrg      test 10 -lt "$_G_count" && break
2728292847cSmrg    done
2738292847cSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2748292847cSmrg  }
2758292847cSmrg
27625420f97Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
2778292847cSmrg  rm -f conftest.sed
2788292847cSmrg  SED=$func_path_progs_result
2798292847cSmrg}
2808292847cSmrg
2818292847cSmrg
2828292847cSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2838292847cSmrg# grep, or the grep that truncates its output the least.
2848292847cSmrgtest -z "$GREP" && {
2858292847cSmrg  func_check_prog_grep ()
2868292847cSmrg  {
2878292847cSmrg    _G_path_prog=$1
2888292847cSmrg
2898292847cSmrg    _G_count=0
2908292847cSmrg    _G_path_prog_max=0
2918292847cSmrg    printf 0123456789 >conftest.in
2928292847cSmrg    while :
2938292847cSmrg    do
2948292847cSmrg      cat conftest.in conftest.in >conftest.tmp
2958292847cSmrg      mv conftest.tmp conftest.in
2968292847cSmrg      cp conftest.in conftest.nl
2978292847cSmrg      echo 'GREP' >> conftest.nl
2988292847cSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2998292847cSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
3008292847cSmrg      _G_count=`expr $_G_count + 1`
3018292847cSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
3028292847cSmrg        # Best one so far, save it but keep looking for a better one
3038292847cSmrg        func_check_prog_result=$_G_path_prog
3048292847cSmrg        _G_path_prog_max=$_G_count
3058292847cSmrg      fi
3068292847cSmrg      # 10*(2^10) chars as input seems more than enough
3078292847cSmrg      test 10 -lt "$_G_count" && break
3088292847cSmrg    done
3098292847cSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
3108292847cSmrg  }
3118292847cSmrg
31225420f97Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
3138292847cSmrg  GREP=$func_path_progs_result
3148292847cSmrg}
3158292847cSmrg
3168292847cSmrg
3178292847cSmrg## ------------------------------- ##
3188292847cSmrg## User overridable command paths. ##
3198292847cSmrg## ------------------------------- ##
3208292847cSmrg
3218292847cSmrg# All uppercase variable names are used for environment variables.  These
3228292847cSmrg# variables can be overridden by the user before calling a script that
3238292847cSmrg# uses them if a suitable command of that name is not already available
3248292847cSmrg# in the command search PATH.
325c2939121Smrg
326c2939121Smrg: ${CP="cp -f"}
3278292847cSmrg: ${ECHO="printf %s\n"}
3288292847cSmrg: ${EGREP="$GREP -E"}
3298292847cSmrg: ${FGREP="$GREP -F"}
3308292847cSmrg: ${LN_S="ln -s"}
331c2939121Smrg: ${MAKE="make"}
332c2939121Smrg: ${MKDIR="mkdir"}
333c2939121Smrg: ${MV="mv -f"}
334c2939121Smrg: ${RM="rm -f"}
335c2939121Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336c76ae52dSmrg
337c2939121Smrg
3388292847cSmrg## -------------------- ##
3398292847cSmrg## Useful sed snippets. ##
3408292847cSmrg## -------------------- ##
3412836776bSmrg
3428292847cSmrgsed_dirname='s|/[^/]*$||'
3438292847cSmrgsed_basename='s|^.*/||'
3442836776bSmrg
3458292847cSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3468292847cSmrg# metacharacters that are still active within double-quoted strings.
3478292847cSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3482836776bSmrg
3498292847cSmrg# Same as above, but do not quote variable references.
3508292847cSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3512836776bSmrg
3528292847cSmrg# Sed substitution that turns a string into a regex matching for the
3538292847cSmrg# string literally.
3548292847cSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3552836776bSmrg
3568292847cSmrg# Sed substitution that converts a w32 file name or path
3578292847cSmrg# that contains forward slashes, into one that contains
3588292847cSmrg# (escaped) backslashes.  A very naive implementation.
3598292847cSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3608292847cSmrg
3618292847cSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3628292847cSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3638292847cSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3648292847cSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3658292847cSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3668292847cSmrg_G_bs='\\'
3678292847cSmrg_G_bs2='\\\\'
3688292847cSmrg_G_bs4='\\\\\\\\'
3698292847cSmrg_G_dollar='\$'
3708292847cSmrgsed_double_backslash="\
3718292847cSmrg  s/$_G_bs4/&\\
3728292847cSmrg/g
3738292847cSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3748292847cSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3758292847cSmrg  s/\n//g"
3762836776bSmrg
37725420f97Smrg# require_check_ifs_backslash
37825420f97Smrg# ---------------------------
37925420f97Smrg# Check if we can use backslash as IFS='\' separator, and set
38025420f97Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
38125420f97Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
38225420f97Smrgfunc_require_check_ifs_backslash ()
38325420f97Smrg{
38425420f97Smrg  _G_save_IFS=$IFS
38525420f97Smrg  IFS='\'
38625420f97Smrg  _G_check_ifs_backshlash='a\\b'
38725420f97Smrg  for _G_i in $_G_check_ifs_backshlash
38825420f97Smrg  do
38925420f97Smrg  case $_G_i in
39025420f97Smrg  a)
39125420f97Smrg    check_ifs_backshlash_broken=false
39225420f97Smrg    ;;
39325420f97Smrg  '')
39425420f97Smrg    break
39525420f97Smrg    ;;
39625420f97Smrg  *)
39725420f97Smrg    check_ifs_backshlash_broken=:
39825420f97Smrg    break
39925420f97Smrg    ;;
40025420f97Smrg  esac
40125420f97Smrg  done
40225420f97Smrg  IFS=$_G_save_IFS
40325420f97Smrg  require_check_ifs_backslash=:
40425420f97Smrg}
40525420f97Smrg
406c76ae52dSmrg
4078292847cSmrg## ----------------- ##
4088292847cSmrg## Global variables. ##
4098292847cSmrg## ----------------- ##
410c2939121Smrg
4118292847cSmrg# Except for the global variables explicitly listed below, the following
4128292847cSmrg# functions in the '^func_' namespace, and the '^require_' namespace
4138292847cSmrg# variables initialised in the 'Resource management' section, sourcing
4148292847cSmrg# this file will not pollute your global namespace with anything
4158292847cSmrg# else. There's no portable way to scope variables in Bourne shell
4168292847cSmrg# though, so actually running these functions will sometimes place
4178292847cSmrg# results into a variable named after the function, and often use
4188292847cSmrg# temporary variables in the '^_G_' namespace. If you are careful to
4198292847cSmrg# avoid using those namespaces casually in your sourcing script, things
4208292847cSmrg# should continue to work as you expect. And, of course, you can freely
4218292847cSmrg# overwrite any of the functions or variables defined here before
4228292847cSmrg# calling anything to customize them.
423c2939121Smrg
4248292847cSmrgEXIT_SUCCESS=0
4258292847cSmrgEXIT_FAILURE=1
4268292847cSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
4278292847cSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428c2939121Smrg
4298292847cSmrg# Allow overriding, eg assuming that you follow the convention of
4308292847cSmrg# putting '$debug_cmd' at the start of all your functions, you can get
4318292847cSmrg# bash to show function call trace with:
4328292847cSmrg#
433de301c82Smrg#    debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
4348292847cSmrgdebug_cmd=${debug_cmd-":"}
4358292847cSmrgexit_cmd=:
436c2939121Smrg
4378292847cSmrg# By convention, finish your script with:
4388292847cSmrg#
4398292847cSmrg#    exit $exit_status
4408292847cSmrg#
4418292847cSmrg# so that you can set exit_status to non-zero if you want to indicate
4428292847cSmrg# something went wrong during execution without actually bailing out at
4438292847cSmrg# the point of failure.
4448292847cSmrgexit_status=$EXIT_SUCCESS
445c2939121Smrg
4468292847cSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4478292847cSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4488292847cSmrg# the _XPG environment variable is not equal to 1 (one), the special
4498292847cSmrg# positional parameter $0, within a function call, is the name of the
4508292847cSmrg# function.
4518292847cSmrgprogpath=$0
452c2939121Smrg
4538292847cSmrg# The name of this program.
4548292847cSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455c2939121Smrg
4568292847cSmrg# Make sure we have an absolute progpath for reexecution:
457c2939121Smrgcase $progpath in
458c2939121Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459c2939121Smrg  *[\\/]*)
4608292847cSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461c2939121Smrg     progdir=`cd "$progdir" && pwd`
4628292847cSmrg     progpath=$progdir/$progname
463c2939121Smrg     ;;
464c2939121Smrg  *)
4658292847cSmrg     _G_IFS=$IFS
4662836776bSmrg     IFS=${PATH_SEPARATOR-:}
467c2939121Smrg     for progdir in $PATH; do
4688292847cSmrg       IFS=$_G_IFS
469c2939121Smrg       test -x "$progdir/$progname" && break
470c2939121Smrg     done
4718292847cSmrg     IFS=$_G_IFS
472c2939121Smrg     test -n "$progdir" || progdir=`pwd`
4738292847cSmrg     progpath=$progdir/$progname
474c2939121Smrg     ;;
475c2939121Smrgesac
476c2939121Smrg
477c2939121Smrg
4788292847cSmrg## ----------------- ##
4798292847cSmrg## Standard options. ##
4808292847cSmrg## ----------------- ##
4812836776bSmrg
4828292847cSmrg# The following options affect the operation of the functions defined
4838292847cSmrg# below, and should be set appropriately depending on run-time para-
4848292847cSmrg# meters passed on the command line.
485c2939121Smrg
486c2939121Smrgopt_dry_run=false
487c2939121Smrgopt_quiet=false
488c2939121Smrgopt_verbose=false
489c2939121Smrg
4908292847cSmrg# Categories 'all' and 'none' are always available.  Append any others
4918292847cSmrg# you will pass as the first argument to func_warning from your own
4928292847cSmrg# code.
4938292847cSmrgwarning_categories=
494c2939121Smrg
4958292847cSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4968292847cSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4978292847cSmrg# treat the next displayed warning as a fatal error.
4988292847cSmrgwarning_func=func_warn_and_continue
499c2939121Smrg
5008292847cSmrg# Set to 'all' to display all warnings, 'none' to suppress all
5018292847cSmrg# warnings, or a space delimited list of some subset of
5028292847cSmrg# 'warning_categories' to display only the listed warnings.
5038292847cSmrgopt_warning_types=all
504c2939121Smrg
505c2939121Smrg
5068292847cSmrg## -------------------- ##
5078292847cSmrg## Resource management. ##
5088292847cSmrg## -------------------- ##
509c2939121Smrg
5108292847cSmrg# This section contains definitions for functions that each ensure a
5118292847cSmrg# particular resource (a file, or a non-empty configuration variable for
5128292847cSmrg# example) is available, and if appropriate to extract default values
5138292847cSmrg# from pertinent package files. Call them using their associated
5148292847cSmrg# 'require_*' variable to ensure that they are executed, at most, once.
5158292847cSmrg#
5168292847cSmrg# It's entirely deliberate that calling these functions can set
5178292847cSmrg# variables that don't obey the namespace limitations obeyed by the rest
5188292847cSmrg# of this file, in order that that they be as useful as possible to
5198292847cSmrg# callers.
520c2939121Smrg
521c2939121Smrg
5228292847cSmrg# require_term_colors
5238292847cSmrg# -------------------
5248292847cSmrg# Allow display of bold text on terminals that support it.
5258292847cSmrgrequire_term_colors=func_require_term_colors
5268292847cSmrgfunc_require_term_colors ()
527c2939121Smrg{
5288292847cSmrg    $debug_cmd
5298292847cSmrg
5308292847cSmrg    test -t 1 && {
5318292847cSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
5328292847cSmrg      # precedence, because most terminfo databases neglect to describe
5338292847cSmrg      # whether color sequences are supported.
5348292847cSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
5358292847cSmrg
5368292847cSmrg      if test 1 = "$USE_ANSI_COLORS"; then
5378292847cSmrg        # Standard ANSI escape sequences
5388292847cSmrg        tc_reset='[0m'
5398292847cSmrg        tc_bold='[1m';   tc_standout='[7m'
5408292847cSmrg        tc_red='[31m';   tc_green='[32m'
5418292847cSmrg        tc_blue='[34m';  tc_cyan='[36m'
5428292847cSmrg      else
5438292847cSmrg        # Otherwise trust the terminfo database after all.
5448292847cSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5458292847cSmrg          tc_reset=`tput sgr0`
5468292847cSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5478292847cSmrg          tc_standout=$tc_bold
5488292847cSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5498292847cSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5508292847cSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5518292847cSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5528292847cSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5538292847cSmrg        }
5548292847cSmrg      fi
5558292847cSmrg    }
556c2939121Smrg
5578292847cSmrg    require_term_colors=:
558c2939121Smrg}
559c2939121Smrg
560c2939121Smrg
5618292847cSmrg## ----------------- ##
5628292847cSmrg## Function library. ##
5638292847cSmrg## ----------------- ##
5648292847cSmrg
5658292847cSmrg# This section contains a variety of useful functions to call in your
5668292847cSmrg# scripts. Take note of the portable wrappers for features provided by
5678292847cSmrg# some modern shells, which will fall back to slower equivalents on
5688292847cSmrg# less featureful shells.
5698292847cSmrg
5708292847cSmrg
5718292847cSmrg# func_append VAR VALUE
5728292847cSmrg# ---------------------
5738292847cSmrg# Append VALUE onto the existing contents of VAR.
5748292847cSmrg
5758292847cSmrg  # _G_HAVE_PLUSEQ_OP
5768292847cSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5778292847cSmrg  # useable or anything else if it does not work.
578de301c82Smrg  if test -z "$_G_HAVE_PLUSEQ_OP" &&  \
579de301c82Smrg      __PLUSEQ_TEST="a" &&  \
580de301c82Smrg      __PLUSEQ_TEST+=" b" 2>/dev/null &&  \
581de301c82Smrg      test "a b" = "$__PLUSEQ_TEST"; then
582de301c82Smrg    _G_HAVE_PLUSEQ_OP=yes
583de301c82Smrg  fi
5848292847cSmrg
5858292847cSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5868292847cSmrgthen
5878292847cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
5888292847cSmrg  eval 'func_append ()
5898292847cSmrg  {
5908292847cSmrg    $debug_cmd
5918292847cSmrg
5928292847cSmrg    eval "$1+=\$2"
5938292847cSmrg  }'
5948292847cSmrgelse
5958292847cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
5968292847cSmrg  func_append ()
5978292847cSmrg  {
5988292847cSmrg    $debug_cmd
5998292847cSmrg
6008292847cSmrg    eval "$1=\$$1\$2"
6018292847cSmrg  }
6028292847cSmrgfi
6038292847cSmrg
6048292847cSmrg
6058292847cSmrg# func_append_quoted VAR VALUE
6068292847cSmrg# ----------------------------
6078292847cSmrg# Quote VALUE and append to the end of shell variable VAR, separated
6088292847cSmrg# by a space.
6098292847cSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
6108292847cSmrg  eval 'func_append_quoted ()
6118292847cSmrg  {
6128292847cSmrg    $debug_cmd
6138292847cSmrg
61425420f97Smrg    func_quote_arg pretty "$2"
61525420f97Smrg    eval "$1+=\\ \$func_quote_arg_result"
6168292847cSmrg  }'
6178292847cSmrgelse
6188292847cSmrg  func_append_quoted ()
6198292847cSmrg  {
6208292847cSmrg    $debug_cmd
6218292847cSmrg
62225420f97Smrg    func_quote_arg pretty "$2"
62325420f97Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
6248292847cSmrg  }
6258292847cSmrgfi
6268292847cSmrg
6278292847cSmrg
6288292847cSmrg# func_append_uniq VAR VALUE
6298292847cSmrg# --------------------------
6308292847cSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6318292847cSmrg# entries are delimited by the first character of VALUE.  For example:
6328292847cSmrg#
6338292847cSmrg#   func_append_uniq options " --another-option option-argument"
6348292847cSmrg#
6358292847cSmrg# will only append to $options if " --another-option option-argument "
6368292847cSmrg# is not already present somewhere in $options already (note spaces at
6378292847cSmrg# each end implied by leading space in second argument).
6388292847cSmrgfunc_append_uniq ()
6398292847cSmrg{
6408292847cSmrg    $debug_cmd
6418292847cSmrg
6428292847cSmrg    eval _G_current_value='`$ECHO $'$1'`'
6438292847cSmrg    _G_delim=`expr "$2" : '\(.\)'`
6448292847cSmrg
6458292847cSmrg    case $_G_delim$_G_current_value$_G_delim in
6468292847cSmrg      *"$2$_G_delim"*) ;;
6478292847cSmrg      *) func_append "$@" ;;
6488292847cSmrg    esac
6498292847cSmrg}
6508292847cSmrg
6518292847cSmrg
6528292847cSmrg# func_arith TERM...
6538292847cSmrg# ------------------
6548292847cSmrg# Set func_arith_result to the result of evaluating TERMs.
6558292847cSmrg  test -z "$_G_HAVE_ARITH_OP" \
6568292847cSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6578292847cSmrg    && _G_HAVE_ARITH_OP=yes
6588292847cSmrg
6598292847cSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6608292847cSmrg  eval 'func_arith ()
6618292847cSmrg  {
6628292847cSmrg    $debug_cmd
6638292847cSmrg
6648292847cSmrg    func_arith_result=$(( $* ))
6658292847cSmrg  }'
6668292847cSmrgelse
6678292847cSmrg  func_arith ()
6688292847cSmrg  {
6698292847cSmrg    $debug_cmd
6708292847cSmrg
6718292847cSmrg    func_arith_result=`expr "$@"`
6728292847cSmrg  }
6738292847cSmrgfi
6748292847cSmrg
6758292847cSmrg
6768292847cSmrg# func_basename FILE
6778292847cSmrg# ------------------
6788292847cSmrg# Set func_basename_result to FILE with everything up to and including
6798292847cSmrg# the last / stripped.
6808292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6818292847cSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6828292847cSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6838292847cSmrg  # on unsupported syntax...
6848292847cSmrg  _b='func_basename_result=${1##*/}'
6858292847cSmrg  _d='case $1 in
6868292847cSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6878292847cSmrg        *  ) func_dirname_result=$3        ;;
6888292847cSmrg      esac'
6898292847cSmrg
6908292847cSmrgelse
6918292847cSmrg  # ...otherwise fall back to using sed.
6928292847cSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
6938292847cSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
6948292847cSmrg      if test "X$func_dirname_result" = "X$1"; then
6958292847cSmrg        func_dirname_result=$3
6968292847cSmrg      else
6978292847cSmrg        func_append func_dirname_result "$2"
6988292847cSmrg      fi'
6998292847cSmrgfi
7008292847cSmrg
7018292847cSmrgeval 'func_basename ()
7028292847cSmrg{
7038292847cSmrg    $debug_cmd
7048292847cSmrg
7058292847cSmrg    '"$_b"'
7068292847cSmrg}'
7078292847cSmrg
7088292847cSmrg
7098292847cSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
7108292847cSmrg# -------------------------------------------
7118292847cSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
7128292847cSmrg# otherwise set result to NONDIR_REPLACEMENT.
7138292847cSmrgeval 'func_dirname ()
7148292847cSmrg{
7158292847cSmrg    $debug_cmd
7168292847cSmrg
7178292847cSmrg    '"$_d"'
7188292847cSmrg}'
7198292847cSmrg
7208292847cSmrg
7218292847cSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
7228292847cSmrg# --------------------------------------------------------
7238292847cSmrg# Perform func_basename and func_dirname in a single function
7248292847cSmrg# call:
7258292847cSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
7268292847cSmrg#             add APPEND to the result, otherwise set result
7278292847cSmrg#             to NONDIR_REPLACEMENT.
7288292847cSmrg#             value returned in "$func_dirname_result"
7298292847cSmrg#   basename: Compute filename of FILE.
7308292847cSmrg#             value retuned in "$func_basename_result"
7318292847cSmrg# For efficiency, we do not delegate to the functions above but instead
7328292847cSmrg# duplicate the functionality here.
7338292847cSmrgeval 'func_dirname_and_basename ()
7348292847cSmrg{
7358292847cSmrg    $debug_cmd
7368292847cSmrg
7378292847cSmrg    '"$_b"'
7388292847cSmrg    '"$_d"'
7398292847cSmrg}'
7408292847cSmrg
7418292847cSmrg
7428292847cSmrg# func_echo ARG...
7438292847cSmrg# ----------------
7448292847cSmrg# Echo program name prefixed message.
7458292847cSmrgfunc_echo ()
7468292847cSmrg{
7478292847cSmrg    $debug_cmd
7488292847cSmrg
7498292847cSmrg    _G_message=$*
7508292847cSmrg
7518292847cSmrg    func_echo_IFS=$IFS
7528292847cSmrg    IFS=$nl
7538292847cSmrg    for _G_line in $_G_message; do
7548292847cSmrg      IFS=$func_echo_IFS
7558292847cSmrg      $ECHO "$progname: $_G_line"
7568292847cSmrg    done
7578292847cSmrg    IFS=$func_echo_IFS
7588292847cSmrg}
7598292847cSmrg
7608292847cSmrg
7618292847cSmrg# func_echo_all ARG...
7628292847cSmrg# --------------------
7638292847cSmrg# Invoke $ECHO with all args, space-separated.
7648292847cSmrgfunc_echo_all ()
7658292847cSmrg{
7668292847cSmrg    $ECHO "$*"
7678292847cSmrg}
7688292847cSmrg
7698292847cSmrg
7708292847cSmrg# func_echo_infix_1 INFIX ARG...
7718292847cSmrg# ------------------------------
7728292847cSmrg# Echo program name, followed by INFIX on the first line, with any
7738292847cSmrg# additional lines not showing INFIX.
7748292847cSmrgfunc_echo_infix_1 ()
7758292847cSmrg{
7768292847cSmrg    $debug_cmd
7778292847cSmrg
7788292847cSmrg    $require_term_colors
7798292847cSmrg
7808292847cSmrg    _G_infix=$1; shift
7818292847cSmrg    _G_indent=$_G_infix
7828292847cSmrg    _G_prefix="$progname: $_G_infix: "
7838292847cSmrg    _G_message=$*
7848292847cSmrg
7858292847cSmrg    # Strip color escape sequences before counting printable length
7868292847cSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7878292847cSmrg    do
7888292847cSmrg      test -n "$_G_tc" && {
7898292847cSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
7908292847cSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
7918292847cSmrg      }
7928292847cSmrg    done
7938292847cSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
7948292847cSmrg
7958292847cSmrg    func_echo_infix_1_IFS=$IFS
7968292847cSmrg    IFS=$nl
7978292847cSmrg    for _G_line in $_G_message; do
7988292847cSmrg      IFS=$func_echo_infix_1_IFS
7998292847cSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
8008292847cSmrg      _G_prefix=$_G_indent
8018292847cSmrg    done
8028292847cSmrg    IFS=$func_echo_infix_1_IFS
8038292847cSmrg}
8048292847cSmrg
8058292847cSmrg
8068292847cSmrg# func_error ARG...
8078292847cSmrg# -----------------
8088292847cSmrg# Echo program name prefixed message to standard error.
8098292847cSmrgfunc_error ()
8108292847cSmrg{
8118292847cSmrg    $debug_cmd
8128292847cSmrg
8138292847cSmrg    $require_term_colors
8148292847cSmrg
8158292847cSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
8168292847cSmrg}
8178292847cSmrg
8188292847cSmrg
8198292847cSmrg# func_fatal_error ARG...
8208292847cSmrg# -----------------------
8218292847cSmrg# Echo program name prefixed message to standard error, and exit.
8228292847cSmrgfunc_fatal_error ()
8238292847cSmrg{
8248292847cSmrg    $debug_cmd
8258292847cSmrg
8268292847cSmrg    func_error "$*"
8278292847cSmrg    exit $EXIT_FAILURE
8288292847cSmrg}
8298292847cSmrg
8308292847cSmrg
8318292847cSmrg# func_grep EXPRESSION FILENAME
8328292847cSmrg# -----------------------------
833c2939121Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
834c2939121Smrgfunc_grep ()
835c2939121Smrg{
8368292847cSmrg    $debug_cmd
8378292847cSmrg
838c2939121Smrg    $GREP "$1" "$2" >/dev/null 2>&1
839c2939121Smrg}
840c2939121Smrg
841c2939121Smrg
8428292847cSmrg# func_len STRING
8438292847cSmrg# ---------------
8448292847cSmrg# Set func_len_result to the length of STRING. STRING may not
8458292847cSmrg# start with a hyphen.
8468292847cSmrg  test -z "$_G_HAVE_XSI_OPS" \
8478292847cSmrg    && (eval 'x=a/b/c;
8488292847cSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8498292847cSmrg    && _G_HAVE_XSI_OPS=yes
8508292847cSmrg
8518292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8528292847cSmrg  eval 'func_len ()
8538292847cSmrg  {
8548292847cSmrg    $debug_cmd
8558292847cSmrg
8568292847cSmrg    func_len_result=${#1}
8578292847cSmrg  }'
8588292847cSmrgelse
8598292847cSmrg  func_len ()
8608292847cSmrg  {
8618292847cSmrg    $debug_cmd
8628292847cSmrg
8638292847cSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8648292847cSmrg  }
8658292847cSmrgfi
8668292847cSmrg
8678292847cSmrg
8688292847cSmrg# func_mkdir_p DIRECTORY-PATH
8698292847cSmrg# ---------------------------
870c2939121Smrg# Make sure the entire path to DIRECTORY-PATH is available.
871c2939121Smrgfunc_mkdir_p ()
872c2939121Smrg{
8738292847cSmrg    $debug_cmd
874c2939121Smrg
8758292847cSmrg    _G_directory_path=$1
8768292847cSmrg    _G_dir_list=
877c2939121Smrg
8788292847cSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8798292847cSmrg
8808292847cSmrg      # Protect directory names starting with '-'
8818292847cSmrg      case $_G_directory_path in
8828292847cSmrg        -*) _G_directory_path=./$_G_directory_path ;;
883c2939121Smrg      esac
884c2939121Smrg
885c2939121Smrg      # While some portion of DIR does not yet exist...
8868292847cSmrg      while test ! -d "$_G_directory_path"; do
887c2939121Smrg        # ...make a list in topmost first order.  Use a colon delimited
888c2939121Smrg	# list incase some portion of path contains whitespace.
8898292847cSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
890c2939121Smrg
891c2939121Smrg        # If the last portion added has no slash in it, the list is done
8928292847cSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
893c2939121Smrg
894c2939121Smrg        # ...otherwise throw away the child directory and loop
8958292847cSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
896c2939121Smrg      done
8978292847cSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
898c2939121Smrg
8998292847cSmrg      func_mkdir_p_IFS=$IFS; IFS=:
9008292847cSmrg      for _G_dir in $_G_dir_list; do
9018292847cSmrg	IFS=$func_mkdir_p_IFS
9028292847cSmrg        # mkdir can fail with a 'File exist' error if two processes
903c2939121Smrg        # try to create one of the directories concurrently.  Don't
904c2939121Smrg        # stop in that case!
9058292847cSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
906c2939121Smrg      done
9078292847cSmrg      IFS=$func_mkdir_p_IFS
908c2939121Smrg
909c2939121Smrg      # Bail out if we (or some other process) failed to create a directory.
9108292847cSmrg      test -d "$_G_directory_path" || \
9118292847cSmrg        func_fatal_error "Failed to create '$1'"
912c2939121Smrg    fi
913c2939121Smrg}
914c76ae52dSmrg
915c76ae52dSmrg
9168292847cSmrg# func_mktempdir [BASENAME]
9178292847cSmrg# -------------------------
918c76ae52dSmrg# Make a temporary directory that won't clash with other running
919c76ae52dSmrg# libtool processes, and avoids race conditions if possible.  If
9208292847cSmrg# given, BASENAME is the basename for that directory.
921c76ae52dSmrgfunc_mktempdir ()
922c76ae52dSmrg{
9238292847cSmrg    $debug_cmd
9248292847cSmrg
9258292847cSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
926c76ae52dSmrg
9278292847cSmrg    if test : = "$opt_dry_run"; then
928c76ae52dSmrg      # Return a directory name, but don't create it in dry-run mode
9298292847cSmrg      _G_tmpdir=$_G_template-$$
930c76ae52dSmrg    else
931c76ae52dSmrg
932c76ae52dSmrg      # If mktemp works, use that first and foremost
9338292847cSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
934c76ae52dSmrg
9358292847cSmrg      if test ! -d "$_G_tmpdir"; then
936c2939121Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9378292847cSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
938c76ae52dSmrg
9398292847cSmrg        func_mktempdir_umask=`umask`
940c2939121Smrg        umask 0077
9418292847cSmrg        $MKDIR "$_G_tmpdir"
9428292847cSmrg        umask $func_mktempdir_umask
943c76ae52dSmrg      fi
944c76ae52dSmrg
945c76ae52dSmrg      # If we're not in dry-run mode, bomb out on failure
9468292847cSmrg      test -d "$_G_tmpdir" || \
9478292847cSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9488292847cSmrg    fi
9498292847cSmrg
9508292847cSmrg    $ECHO "$_G_tmpdir"
9518292847cSmrg}
9528292847cSmrg
9538292847cSmrg
9548292847cSmrg# func_normal_abspath PATH
9558292847cSmrg# ------------------------
9568292847cSmrg# Remove doubled-up and trailing slashes, "." path components,
9578292847cSmrg# and cancel out any ".." path components in PATH after making
9588292847cSmrg# it an absolute path.
9598292847cSmrgfunc_normal_abspath ()
9608292847cSmrg{
9618292847cSmrg    $debug_cmd
9628292847cSmrg
9638292847cSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9648292847cSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9658292847cSmrg    _G_pathcdr='s|^/[^/]*||'
9668292847cSmrg    _G_removedotparts=':dotsl
9678292847cSmrg		s|/\./|/|g
9688292847cSmrg		t dotsl
9698292847cSmrg		s|/\.$|/|'
9708292847cSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9718292847cSmrg    _G_finalslash='s|/*$|/|'
9728292847cSmrg
9738292847cSmrg    # Start from root dir and reassemble the path.
9748292847cSmrg    func_normal_abspath_result=
9758292847cSmrg    func_normal_abspath_tpath=$1
9768292847cSmrg    func_normal_abspath_altnamespace=
9778292847cSmrg    case $func_normal_abspath_tpath in
9788292847cSmrg      "")
9798292847cSmrg        # Empty path, that just means $cwd.
9808292847cSmrg        func_stripname '' '/' "`pwd`"
9818292847cSmrg        func_normal_abspath_result=$func_stripname_result
9828292847cSmrg        return
9838292847cSmrg        ;;
9848292847cSmrg      # The next three entries are used to spot a run of precisely
9858292847cSmrg      # two leading slashes without using negated character classes;
9868292847cSmrg      # we take advantage of case's first-match behaviour.
9878292847cSmrg      ///*)
9888292847cSmrg        # Unusual form of absolute path, do nothing.
9898292847cSmrg        ;;
9908292847cSmrg      //*)
9918292847cSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
9928292847cSmrg        # and for example Cygwin uses it to access remote file shares
9938292847cSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
9948292847cSmrg        func_normal_abspath_altnamespace=/
9958292847cSmrg        ;;
9968292847cSmrg      /*)
9978292847cSmrg        # Absolute path, do nothing.
9988292847cSmrg        ;;
9998292847cSmrg      *)
10008292847cSmrg        # Relative path, prepend $cwd.
10018292847cSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
10028292847cSmrg        ;;
10038292847cSmrg    esac
10048292847cSmrg
10058292847cSmrg    # Cancel out all the simple stuff to save iterations.  We also want
10068292847cSmrg    # the path to end with a slash for ease of parsing, so make sure
10078292847cSmrg    # there is one (and only one) here.
10088292847cSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10098292847cSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
10108292847cSmrg    while :; do
10118292847cSmrg      # Processed it all yet?
10128292847cSmrg      if test / = "$func_normal_abspath_tpath"; then
10138292847cSmrg        # If we ascended to the root using ".." the result may be empty now.
10148292847cSmrg        if test -z "$func_normal_abspath_result"; then
10158292847cSmrg          func_normal_abspath_result=/
10168292847cSmrg        fi
10178292847cSmrg        break
10188292847cSmrg      fi
10198292847cSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
10208292847cSmrg          -e "$_G_pathcar"`
10218292847cSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10228292847cSmrg          -e "$_G_pathcdr"`
10238292847cSmrg      # Figure out what to do with it
10248292847cSmrg      case $func_normal_abspath_tcomponent in
10258292847cSmrg        "")
10268292847cSmrg          # Trailing empty path component, ignore it.
10278292847cSmrg          ;;
10288292847cSmrg        ..)
10298292847cSmrg          # Parent dir; strip last assembled component from result.
10308292847cSmrg          func_dirname "$func_normal_abspath_result"
10318292847cSmrg          func_normal_abspath_result=$func_dirname_result
10328292847cSmrg          ;;
10338292847cSmrg        *)
10348292847cSmrg          # Actual path component, append it.
10358292847cSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10368292847cSmrg          ;;
10378292847cSmrg      esac
10388292847cSmrg    done
10398292847cSmrg    # Restore leading double-slash if one was found on entry.
10408292847cSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10418292847cSmrg}
10428292847cSmrg
10438292847cSmrg
10448292847cSmrg# func_notquiet ARG...
10458292847cSmrg# --------------------
10468292847cSmrg# Echo program name prefixed message only when not in quiet mode.
10478292847cSmrgfunc_notquiet ()
10488292847cSmrg{
10498292847cSmrg    $debug_cmd
10508292847cSmrg
10518292847cSmrg    $opt_quiet || func_echo ${1+"$@"}
10528292847cSmrg
10538292847cSmrg    # A bug in bash halts the script if the last line of a function
10548292847cSmrg    # fails when set -e is in force, so we need another command to
10558292847cSmrg    # work around that:
10568292847cSmrg    :
10578292847cSmrg}
10588292847cSmrg
10598292847cSmrg
10608292847cSmrg# func_relative_path SRCDIR DSTDIR
10618292847cSmrg# --------------------------------
10628292847cSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10638292847cSmrgfunc_relative_path ()
10648292847cSmrg{
10658292847cSmrg    $debug_cmd
10668292847cSmrg
10678292847cSmrg    func_relative_path_result=
10688292847cSmrg    func_normal_abspath "$1"
10698292847cSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10708292847cSmrg    func_normal_abspath "$2"
10718292847cSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10728292847cSmrg
10738292847cSmrg    # Ascend the tree starting from libdir
10748292847cSmrg    while :; do
10758292847cSmrg      # check if we have found a prefix of bindir
10768292847cSmrg      case $func_relative_path_tbindir in
10778292847cSmrg        $func_relative_path_tlibdir)
10788292847cSmrg          # found an exact match
10798292847cSmrg          func_relative_path_tcancelled=
10808292847cSmrg          break
10818292847cSmrg          ;;
10828292847cSmrg        $func_relative_path_tlibdir*)
10838292847cSmrg          # found a matching prefix
10848292847cSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10858292847cSmrg          func_relative_path_tcancelled=$func_stripname_result
10868292847cSmrg          if test -z "$func_relative_path_result"; then
10878292847cSmrg            func_relative_path_result=.
10888292847cSmrg          fi
10898292847cSmrg          break
10908292847cSmrg          ;;
10918292847cSmrg        *)
10928292847cSmrg          func_dirname $func_relative_path_tlibdir
10938292847cSmrg          func_relative_path_tlibdir=$func_dirname_result
10948292847cSmrg          if test -z "$func_relative_path_tlibdir"; then
10958292847cSmrg            # Have to descend all the way to the root!
10968292847cSmrg            func_relative_path_result=../$func_relative_path_result
10978292847cSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
10988292847cSmrg            break
10998292847cSmrg          fi
11008292847cSmrg          func_relative_path_result=../$func_relative_path_result
11018292847cSmrg          ;;
11028292847cSmrg      esac
11038292847cSmrg    done
11048292847cSmrg
11058292847cSmrg    # Now calculate path; take care to avoid doubling-up slashes.
11068292847cSmrg    func_stripname '' '/' "$func_relative_path_result"
11078292847cSmrg    func_relative_path_result=$func_stripname_result
11088292847cSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
11098292847cSmrg    if test -n "$func_stripname_result"; then
11108292847cSmrg      func_append func_relative_path_result "/$func_stripname_result"
11118292847cSmrg    fi
11128292847cSmrg
11138292847cSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
11148292847cSmrg    if test -n "$func_relative_path_result"; then
11158292847cSmrg      func_stripname './' '' "$func_relative_path_result"
11168292847cSmrg      func_relative_path_result=$func_stripname_result
1117c76ae52dSmrg    fi
1118c76ae52dSmrg
11198292847cSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
11208292847cSmrg
11218292847cSmrg    :
11228292847cSmrg}
11238292847cSmrg
11248292847cSmrg
112525420f97Smrg# func_quote_portable EVAL ARG
112625420f97Smrg# ----------------------------
112725420f97Smrg# Internal function to portably implement func_quote_arg.  Note that we still
112825420f97Smrg# keep attention to performance here so we as much as possible try to avoid
112925420f97Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
113025420f97Smrgfunc_quote_portable ()
11318292847cSmrg{
11328292847cSmrg    $debug_cmd
11338292847cSmrg
113425420f97Smrg    $require_check_ifs_backslash
113525420f97Smrg
113625420f97Smrg    func_quote_portable_result=$2
113725420f97Smrg
113825420f97Smrg    # one-time-loop (easy break)
113925420f97Smrg    while true
114025420f97Smrg    do
114125420f97Smrg      if $1; then
114225420f97Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
114325420f97Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
114425420f97Smrg        break
11458292847cSmrg      fi
11468292847cSmrg
114725420f97Smrg      # Quote for eval.
114825420f97Smrg      case $func_quote_portable_result in
114925420f97Smrg        *[\\\`\"\$]*)
115025420f97Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
115125420f97Smrg          # contains the shell wildcard characters.
115225420f97Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
115325420f97Smrg            :*|*[\[\*\?]*)
115425420f97Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
115525420f97Smrg                  | $SED "$sed_quote_subst"`
115625420f97Smrg              break
115725420f97Smrg              ;;
115825420f97Smrg          esac
115925420f97Smrg
116025420f97Smrg          func_quote_portable_old_IFS=$IFS
116125420f97Smrg          for _G_char in '\' '`' '"' '$'
116225420f97Smrg          do
116325420f97Smrg            # STATE($1) PREV($2) SEPARATOR($3)
116425420f97Smrg            set start "" ""
116525420f97Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
116625420f97Smrg            IFS=$_G_char
116725420f97Smrg            for _G_part in $func_quote_portable_result
116825420f97Smrg            do
116925420f97Smrg              case $1 in
117025420f97Smrg              quote)
117125420f97Smrg                func_append func_quote_portable_result "$3$2"
117225420f97Smrg                set quote "$_G_part" "\\$_G_char"
117325420f97Smrg                ;;
117425420f97Smrg              start)
117525420f97Smrg                set first "" ""
117625420f97Smrg                func_quote_portable_result=
117725420f97Smrg                ;;
117825420f97Smrg              first)
117925420f97Smrg                set quote "$_G_part" ""
118025420f97Smrg                ;;
118125420f97Smrg              esac
118225420f97Smrg            done
118325420f97Smrg          done
118425420f97Smrg          IFS=$func_quote_portable_old_IFS
11858292847cSmrg          ;;
118625420f97Smrg        *) ;;
11878292847cSmrg      esac
118825420f97Smrg      break
11898292847cSmrg    done
119025420f97Smrg
119125420f97Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
119225420f97Smrg    case $func_quote_portable_result in
119325420f97Smrg      # double-quote args containing shell metacharacters to delay
119425420f97Smrg      # word splitting, command substitution and variable expansion
119525420f97Smrg      # for a subsequent eval.
119625420f97Smrg      # many bourne shells cannot handle close brackets correctly
119725420f97Smrg      # in scan sets, so we specify it separately.
119825420f97Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
119925420f97Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
120025420f97Smrg        ;;
120125420f97Smrg    esac
12028292847cSmrg}
12038292847cSmrg
12048292847cSmrg
120525420f97Smrg# func_quotefast_eval ARG
120625420f97Smrg# -----------------------
120725420f97Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
120825420f97Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
120925420f97Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
121025420f97Smrg  printf -v _GL_test_printf_tilde %q '~'
121125420f97Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
121225420f97Smrg    func_quotefast_eval ()
121325420f97Smrg    {
121425420f97Smrg      printf -v func_quotefast_eval_result %q "$1"
121525420f97Smrg    }
121625420f97Smrg  else
121725420f97Smrg    # Broken older Bash implementations.  Make those faster too if possible.
121825420f97Smrg    func_quotefast_eval ()
121925420f97Smrg    {
122025420f97Smrg      case $1 in
122125420f97Smrg        '~'*)
122225420f97Smrg          func_quote_portable false "$1"
122325420f97Smrg          func_quotefast_eval_result=$func_quote_portable_result
122425420f97Smrg          ;;
122525420f97Smrg        *)
122625420f97Smrg          printf -v func_quotefast_eval_result %q "$1"
122725420f97Smrg          ;;
122825420f97Smrg      esac
122925420f97Smrg    }
123025420f97Smrg  fi
123125420f97Smrgelse
123225420f97Smrg  func_quotefast_eval ()
123325420f97Smrg  {
123425420f97Smrg    func_quote_portable false "$1"
123525420f97Smrg    func_quotefast_eval_result=$func_quote_portable_result
123625420f97Smrg  }
123725420f97Smrgfi
12388292847cSmrg
123925420f97Smrg
124025420f97Smrg# func_quote_arg MODEs ARG
124125420f97Smrg# ------------------------
124225420f97Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
124325420f97Smrg# specifiers listed below separated by ',' character.  This function returns two
124425420f97Smrg# values:
124525420f97Smrg#   i) func_quote_arg_result
124625420f97Smrg#      double-quoted (when needed), suitable for a subsequent eval
124725420f97Smrg#  ii) func_quote_arg_unquoted_result
124825420f97Smrg#      has all characters that are still active within double
124925420f97Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
125025420f97Smrg#
125125420f97Smrg# Available modes:
125225420f97Smrg# ----------------
125325420f97Smrg# 'eval' (default)
125425420f97Smrg#       - escape shell special characters
125525420f97Smrg# 'expand'
125625420f97Smrg#       - the same as 'eval';  but do not quote variable references
125725420f97Smrg# 'pretty'
125825420f97Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
125925420f97Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
126025420f97Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
126125420f97Smrg# 'unquoted'
126225420f97Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
126325420f97Smrg#         wrapping double-quotes.
126425420f97Smrg#
126525420f97Smrg# Examples for 'func_quote_arg pretty,unquoted string':
126625420f97Smrg#
126725420f97Smrg#   string      | *_result              | *_unquoted_result
126825420f97Smrg#   ------------+-----------------------+-------------------
126925420f97Smrg#   "           | \"                    | \"
127025420f97Smrg#   a b         | "a b"                 | a b
127125420f97Smrg#   "a b"       | "\"a b\""             | \"a b\"
127225420f97Smrg#   *           | "*"                   | *
127325420f97Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
127425420f97Smrg#
127525420f97Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
127625420f97Smrg#
127725420f97Smrg#   string        |   *_result          |  *_unquoted_result
127825420f97Smrg#   --------------+---------------------+--------------------
127925420f97Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
128025420f97Smrgfunc_quote_arg ()
128125420f97Smrg{
128225420f97Smrg    _G_quote_expand=false
128325420f97Smrg    case ,$1, in
128425420f97Smrg      *,expand,*)
128525420f97Smrg        _G_quote_expand=:
128625420f97Smrg        ;;
12878292847cSmrg    esac
12888292847cSmrg
128925420f97Smrg    case ,$1, in
129025420f97Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
129125420f97Smrg        func_quote_portable $_G_quote_expand "$2"
129225420f97Smrg        func_quote_arg_result=$func_quote_portable_result
129325420f97Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
129425420f97Smrg        ;;
129525420f97Smrg      *)
129625420f97Smrg        # Faster quote-for-eval for some shells.
129725420f97Smrg        func_quotefast_eval "$2"
129825420f97Smrg        func_quote_arg_result=$func_quotefast_eval_result
12998292847cSmrg        ;;
13008292847cSmrg    esac
130125420f97Smrg}
130225420f97Smrg
13038292847cSmrg
130425420f97Smrg# func_quote MODEs ARGs...
130525420f97Smrg# ------------------------
130625420f97Smrg# Quote all ARGs to be evaled later and join them into single command.  See
130725420f97Smrg# func_quote_arg's description for more info.
130825420f97Smrgfunc_quote ()
130925420f97Smrg{
131025420f97Smrg    $debug_cmd
131125420f97Smrg    _G_func_quote_mode=$1 ; shift
131225420f97Smrg    func_quote_result=
131325420f97Smrg    while test 0 -lt $#; do
131425420f97Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
131525420f97Smrg      if test -n "$func_quote_result"; then
131625420f97Smrg        func_append func_quote_result " $func_quote_arg_result"
131725420f97Smrg      else
131825420f97Smrg        func_append func_quote_result "$func_quote_arg_result"
131925420f97Smrg      fi
132025420f97Smrg      shift
132125420f97Smrg    done
13228292847cSmrg}
13238292847cSmrg
13248292847cSmrg
13258292847cSmrg# func_stripname PREFIX SUFFIX NAME
13268292847cSmrg# ---------------------------------
13278292847cSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
13288292847cSmrg# PREFIX and SUFFIX must not contain globbing or regex special
13298292847cSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
13308292847cSmrg# dot (in which case that matches only a dot).
13318292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
13328292847cSmrg  eval 'func_stripname ()
13338292847cSmrg  {
13348292847cSmrg    $debug_cmd
13358292847cSmrg
13368292847cSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
13378292847cSmrg    # positional parameters, so assign one to ordinary variable first.
13388292847cSmrg    func_stripname_result=$3
13398292847cSmrg    func_stripname_result=${func_stripname_result#"$1"}
13408292847cSmrg    func_stripname_result=${func_stripname_result%"$2"}
13418292847cSmrg  }'
13428292847cSmrgelse
13438292847cSmrg  func_stripname ()
13448292847cSmrg  {
13458292847cSmrg    $debug_cmd
13468292847cSmrg
13478292847cSmrg    case $2 in
13488292847cSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
13498292847cSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
13508292847cSmrg    esac
13518292847cSmrg  }
13528292847cSmrgfi
13538292847cSmrg
13548292847cSmrg
13558292847cSmrg# func_show_eval CMD [FAIL_EXP]
13568292847cSmrg# -----------------------------
13578292847cSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13588292847cSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13598292847cSmrg# is given, then evaluate it.
13608292847cSmrgfunc_show_eval ()
13618292847cSmrg{
13628292847cSmrg    $debug_cmd
13638292847cSmrg
13648292847cSmrg    _G_cmd=$1
13658292847cSmrg    _G_fail_exp=${2-':'}
13668292847cSmrg
136725420f97Smrg    func_quote_arg pretty,expand "$_G_cmd"
136825420f97Smrg    eval "func_notquiet $func_quote_arg_result"
13698292847cSmrg
13708292847cSmrg    $opt_dry_run || {
13718292847cSmrg      eval "$_G_cmd"
13728292847cSmrg      _G_status=$?
13738292847cSmrg      if test 0 -ne "$_G_status"; then
13748292847cSmrg	eval "(exit $_G_status); $_G_fail_exp"
13758292847cSmrg      fi
13768292847cSmrg    }
13778292847cSmrg}
13788292847cSmrg
13798292847cSmrg
13808292847cSmrg# func_show_eval_locale CMD [FAIL_EXP]
13818292847cSmrg# ------------------------------------
13828292847cSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13838292847cSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13848292847cSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
13858292847cSmrgfunc_show_eval_locale ()
13868292847cSmrg{
13878292847cSmrg    $debug_cmd
13888292847cSmrg
13898292847cSmrg    _G_cmd=$1
13908292847cSmrg    _G_fail_exp=${2-':'}
13918292847cSmrg
13928292847cSmrg    $opt_quiet || {
139325420f97Smrg      func_quote_arg expand,pretty "$_G_cmd"
139425420f97Smrg      eval "func_echo $func_quote_arg_result"
13958292847cSmrg    }
13968292847cSmrg
13978292847cSmrg    $opt_dry_run || {
13988292847cSmrg      eval "$_G_user_locale
13998292847cSmrg	    $_G_cmd"
14008292847cSmrg      _G_status=$?
14018292847cSmrg      eval "$_G_safe_locale"
14028292847cSmrg      if test 0 -ne "$_G_status"; then
14038292847cSmrg	eval "(exit $_G_status); $_G_fail_exp"
14048292847cSmrg      fi
14058292847cSmrg    }
14068292847cSmrg}
14078292847cSmrg
14088292847cSmrg
14098292847cSmrg# func_tr_sh
14108292847cSmrg# ----------
14118292847cSmrg# Turn $1 into a string suitable for a shell variable name.
14128292847cSmrg# Result is stored in $func_tr_sh_result.  All characters
14138292847cSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
14148292847cSmrg# if $1 begins with a digit, a '_' is prepended as well.
14158292847cSmrgfunc_tr_sh ()
14168292847cSmrg{
14178292847cSmrg    $debug_cmd
14188292847cSmrg
14198292847cSmrg    case $1 in
14208292847cSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
14218292847cSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
14228292847cSmrg      ;;
14238292847cSmrg    * )
14248292847cSmrg      func_tr_sh_result=$1
14258292847cSmrg      ;;
14268292847cSmrg    esac
14278292847cSmrg}
14288292847cSmrg
14298292847cSmrg
14308292847cSmrg# func_verbose ARG...
14318292847cSmrg# -------------------
14328292847cSmrg# Echo program name prefixed message in verbose mode only.
14338292847cSmrgfunc_verbose ()
14348292847cSmrg{
14358292847cSmrg    $debug_cmd
14368292847cSmrg
14378292847cSmrg    $opt_verbose && func_echo "$*"
14388292847cSmrg
14398292847cSmrg    :
14408292847cSmrg}
14418292847cSmrg
14428292847cSmrg
14438292847cSmrg# func_warn_and_continue ARG...
14448292847cSmrg# -----------------------------
14458292847cSmrg# Echo program name prefixed warning message to standard error.
14468292847cSmrgfunc_warn_and_continue ()
14478292847cSmrg{
14488292847cSmrg    $debug_cmd
14498292847cSmrg
14508292847cSmrg    $require_term_colors
14518292847cSmrg
14528292847cSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
14538292847cSmrg}
14548292847cSmrg
14558292847cSmrg
14568292847cSmrg# func_warning CATEGORY ARG...
14578292847cSmrg# ----------------------------
14588292847cSmrg# Echo program name prefixed warning message to standard error. Warning
14598292847cSmrg# messages can be filtered according to CATEGORY, where this function
14608292847cSmrg# elides messages where CATEGORY is not listed in the global variable
14618292847cSmrg# 'opt_warning_types'.
14628292847cSmrgfunc_warning ()
14638292847cSmrg{
14648292847cSmrg    $debug_cmd
14658292847cSmrg
14668292847cSmrg    # CATEGORY must be in the warning_categories list!
14678292847cSmrg    case " $warning_categories " in
14688292847cSmrg      *" $1 "*) ;;
14698292847cSmrg      *) func_internal_error "invalid warning category '$1'" ;;
14708292847cSmrg    esac
14718292847cSmrg
14728292847cSmrg    _G_category=$1
14738292847cSmrg    shift
14748292847cSmrg
14758292847cSmrg    case " $opt_warning_types " in
14768292847cSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
14778292847cSmrg    esac
14788292847cSmrg}
14798292847cSmrg
14808292847cSmrg
14818292847cSmrg# func_sort_ver VER1 VER2
14828292847cSmrg# -----------------------
14838292847cSmrg# 'sort -V' is not generally available.
14848292847cSmrg# Note this deviates from the version comparison in automake
14858292847cSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
14868292847cSmrg# but this should suffice as we won't be specifying old
14878292847cSmrg# version formats or redundant trailing .0 in bootstrap.conf.
14888292847cSmrg# If we did want full compatibility then we should probably
14898292847cSmrg# use m4_version_compare from autoconf.
14908292847cSmrgfunc_sort_ver ()
14918292847cSmrg{
14928292847cSmrg    $debug_cmd
14938292847cSmrg
14948292847cSmrg    printf '%s\n%s\n' "$1" "$2" \
14958292847cSmrg      | 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
14968292847cSmrg}
14978292847cSmrg
14988292847cSmrg# func_lt_ver PREV CURR
14998292847cSmrg# ---------------------
15008292847cSmrg# Return true if PREV and CURR are in the correct order according to
15018292847cSmrg# func_sort_ver, otherwise false.  Use it like this:
15028292847cSmrg#
15038292847cSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
15048292847cSmrgfunc_lt_ver ()
15058292847cSmrg{
15068292847cSmrg    $debug_cmd
15078292847cSmrg
15088292847cSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
15098292847cSmrg}
15108292847cSmrg
15118292847cSmrg
15128292847cSmrg# Local variables:
15138292847cSmrg# mode: shell-script
15148292847cSmrg# sh-indentation: 2
15158292847cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
15168292847cSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
15178292847cSmrg# time-stamp-time-zone: "UTC"
15188292847cSmrg# End:
15198292847cSmrg#! /bin/sh
15208292847cSmrg
15218292847cSmrg# A portable, pluggable option parser for Bourne shell.
15228292847cSmrg# Written by Gary V. Vaughan, 2010
15238292847cSmrg
152425420f97Smrg# This is free software.  There is NO warranty; not even for
152525420f97Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
152625420f97Smrg#
152725420f97Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
152825420f97Smrg#
152925420f97Smrg# This file is dual licensed under the terms of the MIT license
153025420f97Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
153125420f97Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
153225420f97Smrg# these licenses when using or redistributing this software or any of
153325420f97Smrg# the files within it.  See the URLs above, or the file `LICENSE`
153425420f97Smrg# included in the Bootstrap distribution for the full license texts.
15358292847cSmrg
153625420f97Smrg# Please report bugs or propose patches to:
153725420f97Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
15388292847cSmrg
153925420f97Smrg# Set a version string for this script.
154025420f97Smrgscriptversion=2019-02-19.15; # UTC
15418292847cSmrg
15428292847cSmrg
15438292847cSmrg## ------ ##
15448292847cSmrg## Usage. ##
15458292847cSmrg## ------ ##
15468292847cSmrg
15478292847cSmrg# This file is a library for parsing options in your shell scripts along
15488292847cSmrg# with assorted other useful supporting features that you can make use
15498292847cSmrg# of too.
15508292847cSmrg#
15518292847cSmrg# For the simplest scripts you might need only:
15528292847cSmrg#
15538292847cSmrg#   #!/bin/sh
15548292847cSmrg#   . relative/path/to/funclib.sh
15558292847cSmrg#   . relative/path/to/options-parser
15568292847cSmrg#   scriptversion=1.0
15578292847cSmrg#   func_options ${1+"$@"}
15588292847cSmrg#   eval set dummy "$func_options_result"; shift
15598292847cSmrg#   ...rest of your script...
15608292847cSmrg#
15618292847cSmrg# In order for the '--version' option to work, you will need to have a
15628292847cSmrg# suitably formatted comment like the one at the top of this file
156325420f97Smrg# starting with '# Written by ' and ending with '# Copyright'.
15648292847cSmrg#
15658292847cSmrg# For '-h' and '--help' to work, you will also need a one line
15668292847cSmrg# description of your script's purpose in a comment directly above the
15678292847cSmrg# '# Written by ' line, like the one at the top of this file.
15688292847cSmrg#
15698292847cSmrg# The default options also support '--debug', which will turn on shell
15708292847cSmrg# execution tracing (see the comment above debug_cmd below for another
15718292847cSmrg# use), and '--verbose' and the func_verbose function to allow your script
15728292847cSmrg# to display verbose messages only when your user has specified
15738292847cSmrg# '--verbose'.
15748292847cSmrg#
157525420f97Smrg# After sourcing this file, you can plug in processing for additional
15768292847cSmrg# options by amending the variables from the 'Configuration' section
15778292847cSmrg# below, and following the instructions in the 'Option parsing'
15788292847cSmrg# section further down.
15798292847cSmrg
15808292847cSmrg## -------------- ##
15818292847cSmrg## Configuration. ##
15828292847cSmrg## -------------- ##
15838292847cSmrg
15848292847cSmrg# You should override these variables in your script after sourcing this
15858292847cSmrg# file so that they reflect the customisations you have added to the
15868292847cSmrg# option parser.
15878292847cSmrg
15888292847cSmrg# The usage line for option parsing errors and the start of '-h' and
15898292847cSmrg# '--help' output messages. You can embed shell variables for delayed
15908292847cSmrg# expansion at the time the message is displayed, but you will need to
15918292847cSmrg# quote other shell meta-characters carefully to prevent them being
15928292847cSmrg# expanded when the contents are evaled.
15938292847cSmrgusage='$progpath [OPTION]...'
15948292847cSmrg
15958292847cSmrg# Short help message in response to '-h' and '--help'.  Add to this or
15968292847cSmrg# override it after sourcing this library to reflect the full set of
15978292847cSmrg# options your script accepts.
15988292847cSmrgusage_message="\
15998292847cSmrg       --debug        enable verbose shell tracing
16008292847cSmrg   -W, --warnings=CATEGORY
16018292847cSmrg                      report the warnings falling in CATEGORY [all]
16028292847cSmrg   -v, --verbose      verbosely report processing
16038292847cSmrg       --version      print version information and exit
16048292847cSmrg   -h, --help         print short or long help message and exit
16058292847cSmrg"
16068292847cSmrg
16078292847cSmrg# Additional text appended to 'usage_message' in response to '--help'.
16088292847cSmrglong_help_message="
16098292847cSmrgWarning categories include:
16108292847cSmrg       'all'          show all warnings
16118292847cSmrg       'none'         turn off all the warnings
16128292847cSmrg       'error'        warnings are treated as fatal errors"
16138292847cSmrg
16148292847cSmrg# Help message printed before fatal option parsing errors.
16158292847cSmrgfatal_help="Try '\$progname --help' for more information."
16168292847cSmrg
16178292847cSmrg
16188292847cSmrg
16198292847cSmrg## ------------------------- ##
16208292847cSmrg## Hook function management. ##
16218292847cSmrg## ------------------------- ##
16228292847cSmrg
16238292847cSmrg# This section contains functions for adding, removing, and running hooks
162425420f97Smrg# in the main code.  A hook is just a list of function names that can be
162525420f97Smrg# run in order later on.
16268292847cSmrg
16278292847cSmrg# func_hookable FUNC_NAME
16288292847cSmrg# -----------------------
16298292847cSmrg# Declare that FUNC_NAME will run hooks added with
16308292847cSmrg# 'func_add_hook FUNC_NAME ...'.
16318292847cSmrgfunc_hookable ()
16328292847cSmrg{
16338292847cSmrg    $debug_cmd
16348292847cSmrg
16358292847cSmrg    func_append hookable_fns " $1"
16368292847cSmrg}
16378292847cSmrg
16388292847cSmrg
16398292847cSmrg# func_add_hook FUNC_NAME HOOK_FUNC
16408292847cSmrg# ---------------------------------
16418292847cSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
16428292847cSmrg# first have been declared "hookable" by a call to 'func_hookable'.
16438292847cSmrgfunc_add_hook ()
16448292847cSmrg{
16458292847cSmrg    $debug_cmd
16468292847cSmrg
16478292847cSmrg    case " $hookable_fns " in
16488292847cSmrg      *" $1 "*) ;;
16498292847cSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
16508292847cSmrg    esac
16518292847cSmrg
16528292847cSmrg    eval func_append ${1}_hooks '" $2"'
16538292847cSmrg}
16548292847cSmrg
16558292847cSmrg
16568292847cSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
16578292847cSmrg# ------------------------------------
165825420f97Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
165925420f97Smrg# FUNC_NAME.
16608292847cSmrgfunc_remove_hook ()
16618292847cSmrg{
16628292847cSmrg    $debug_cmd
16638292847cSmrg
16648292847cSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
16658292847cSmrg}
16668292847cSmrg
16678292847cSmrg
166825420f97Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
166925420f97Smrg# ---------------------------------------------
167025420f97Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
167125420f97Smrg# *_result variable of FUNC_NAME_B.
167225420f97Smrgfunc_propagate_result ()
167325420f97Smrg{
167425420f97Smrg    $debug_cmd
167525420f97Smrg
167625420f97Smrg    func_propagate_result_result=:
167725420f97Smrg    if eval "test \"\${${1}_result+set}\" = set"
167825420f97Smrg    then
167925420f97Smrg      eval "${2}_result=\$${1}_result"
168025420f97Smrg    else
168125420f97Smrg      func_propagate_result_result=false
168225420f97Smrg    fi
168325420f97Smrg}
168425420f97Smrg
168525420f97Smrg
16868292847cSmrg# func_run_hooks FUNC_NAME [ARG]...
16878292847cSmrg# ---------------------------------
16888292847cSmrg# Run all hook functions registered to FUNC_NAME.
168925420f97Smrg# It's assumed that the list of hook functions contains nothing more
16908292847cSmrg# than a whitespace-delimited list of legal shell function names, and
16918292847cSmrg# no effort is wasted trying to catch shell meta-characters or preserve
16928292847cSmrg# whitespace.
16938292847cSmrgfunc_run_hooks ()
16948292847cSmrg{
16958292847cSmrg    $debug_cmd
16968292847cSmrg
1697de301c82Smrg    _G_rc_run_hooks=false
1698de301c82Smrg
16998292847cSmrg    case " $hookable_fns " in
17008292847cSmrg      *" $1 "*) ;;
170125420f97Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17028292847cSmrg    esac
17038292847cSmrg
17048292847cSmrg    eval _G_hook_fns=\$$1_hooks; shift
17058292847cSmrg
17068292847cSmrg    for _G_hook in $_G_hook_fns; do
170725420f97Smrg      func_unset "${_G_hook}_result"
170825420f97Smrg      eval $_G_hook '${1+"$@"}'
170925420f97Smrg      func_propagate_result $_G_hook func_run_hooks
171025420f97Smrg      if $func_propagate_result_result; then
171125420f97Smrg        eval set dummy "$func_run_hooks_result"; shift
1712de3c0529Smrg      fi
17138292847cSmrg    done
17148292847cSmrg}
17158292847cSmrg
17168292847cSmrg
17178292847cSmrg
17188292847cSmrg## --------------- ##
17198292847cSmrg## Option parsing. ##
17208292847cSmrg## --------------- ##
17218292847cSmrg
17228292847cSmrg# In order to add your own option parsing hooks, you must accept the
172325420f97Smrg# full positional parameter list from your hook function.  You may remove
172425420f97Smrg# or edit any options that you action, and then pass back the remaining
172525420f97Smrg# unprocessed options in '<hooked_function_name>_result', escaped
172625420f97Smrg# suitably for 'eval'.
172725420f97Smrg#
172825420f97Smrg# The '<hooked_function_name>_result' variable is automatically unset
172925420f97Smrg# before your hook gets called; for best performance, only set the
173025420f97Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
173125420f97Smrg# function unnecessarily because it can be an expensive operation on some
173225420f97Smrg# machines).
1733de3c0529Smrg#
1734de3c0529Smrg# Like this:
17358292847cSmrg#
17368292847cSmrg#    my_options_prep ()
17378292847cSmrg#    {
17388292847cSmrg#        $debug_cmd
17398292847cSmrg#
17408292847cSmrg#        # Extend the existing usage message.
17418292847cSmrg#        usage_message=$usage_message'
17428292847cSmrg#      -s, --silent       don'\''t print informational messages
17438292847cSmrg#    '
174425420f97Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
174525420f97Smrg#        # my_options_prep_result variable intact.
17468292847cSmrg#    }
17478292847cSmrg#    func_add_hook func_options_prep my_options_prep
17488292847cSmrg#
17498292847cSmrg#
17508292847cSmrg#    my_silent_option ()
17518292847cSmrg#    {
17528292847cSmrg#        $debug_cmd
17538292847cSmrg#
1754de3c0529Smrg#        args_changed=false
1755de3c0529Smrg#
175625420f97Smrg#        # Note that, for efficiency, we parse as many options as we can
17578292847cSmrg#        # recognise in a loop before passing the remainder back to the
17588292847cSmrg#        # caller on the first unrecognised argument we encounter.
17598292847cSmrg#        while test $# -gt 0; do
17608292847cSmrg#          opt=$1; shift
17618292847cSmrg#          case $opt in
1762de3c0529Smrg#            --silent|-s) opt_silent=:
1763de3c0529Smrg#                         args_changed=:
1764de3c0529Smrg#                         ;;
17658292847cSmrg#            # Separate non-argument short options:
17668292847cSmrg#            -s*)         func_split_short_opt "$_G_opt"
17678292847cSmrg#                         set dummy "$func_split_short_opt_name" \
17688292847cSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
17698292847cSmrg#                         shift
1770de3c0529Smrg#                         args_changed=:
17718292847cSmrg#                         ;;
1772de3c0529Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
177325420f97Smrg#                         # is added back to "$@" in case we need it later,
177425420f97Smrg#                         # if $args_changed was set to 'true'.
1775de3c0529Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17768292847cSmrg#          esac
17778292847cSmrg#        done
17788292847cSmrg#
177925420f97Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1780de3c0529Smrg#        if $args_changed; then
178125420f97Smrg#          func_quote eval ${1+"$@"}
178225420f97Smrg#          my_silent_option_result=$func_quote_result
1783de3c0529Smrg#        fi
17848292847cSmrg#    }
17858292847cSmrg#    func_add_hook func_parse_options my_silent_option
17868292847cSmrg#
17878292847cSmrg#
17888292847cSmrg#    my_option_validation ()
17898292847cSmrg#    {
17908292847cSmrg#        $debug_cmd
17918292847cSmrg#
17928292847cSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
17938292847cSmrg#    '--silent' and '--verbose' options are mutually exclusive."
17948292847cSmrg#    }
17958292847cSmrg#    func_add_hook func_validate_options my_option_validation
17968292847cSmrg#
1797de3c0529Smrg# You'll also need to manually amend $usage_message to reflect the extra
17988292847cSmrg# options you parse.  It's preferable to append if you can, so that
17998292847cSmrg# multiple option parsing hooks can be added safely.
18008292847cSmrg
18018292847cSmrg
1802de3c0529Smrg# func_options_finish [ARG]...
1803de3c0529Smrg# ----------------------------
1804de3c0529Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1805de3c0529Smrgfunc_options_finish ()
1806de3c0529Smrg{
1807de3c0529Smrg    $debug_cmd
1808de3c0529Smrg
180925420f97Smrg    func_run_hooks func_options ${1+"$@"}
181025420f97Smrg    func_propagate_result func_run_hooks func_options_finish
1811de3c0529Smrg}
1812de3c0529Smrg
1813de3c0529Smrg
18148292847cSmrg# func_options [ARG]...
18158292847cSmrg# ---------------------
18168292847cSmrg# All the functions called inside func_options are hookable. See the
18178292847cSmrg# individual implementations for details.
18188292847cSmrgfunc_hookable func_options
18198292847cSmrgfunc_options ()
18208292847cSmrg{
18218292847cSmrg    $debug_cmd
18228292847cSmrg
182325420f97Smrg    _G_options_quoted=false
1824de3c0529Smrg
1825de3c0529Smrg    for my_func in options_prep parse_options validate_options options_finish
1826de3c0529Smrg    do
182725420f97Smrg      func_unset func_${my_func}_result
182825420f97Smrg      func_unset func_run_hooks_result
182925420f97Smrg      eval func_$my_func '${1+"$@"}'
183025420f97Smrg      func_propagate_result func_$my_func func_options
183125420f97Smrg      if $func_propagate_result_result; then
183225420f97Smrg        eval set dummy "$func_options_result"; shift
183325420f97Smrg        _G_options_quoted=:
1834de3c0529Smrg      fi
1835de3c0529Smrg    done
18368292847cSmrg
183725420f97Smrg    $_G_options_quoted || {
183825420f97Smrg      # As we (func_options) are top-level options-parser function and
183925420f97Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
184025420f97Smrg      # caller.
184125420f97Smrg      func_quote eval ${1+"$@"}
184225420f97Smrg      func_options_result=$func_quote_result
184325420f97Smrg    }
1844c76ae52dSmrg}
1845c76ae52dSmrg
1846c76ae52dSmrg
18478292847cSmrg# func_options_prep [ARG]...
18488292847cSmrg# --------------------------
18498292847cSmrg# All initialisations required before starting the option parse loop.
18508292847cSmrg# Note that when calling hook functions, we pass through the list of
18518292847cSmrg# positional parameters.  If a hook function modifies that list, and
1852de3c0529Smrg# needs to propagate that back to rest of this script, then the complete
185325420f97Smrg# modified list must be put in 'func_run_hooks_result' before returning.
18548292847cSmrgfunc_hookable func_options_prep
18558292847cSmrgfunc_options_prep ()
1856c76ae52dSmrg{
18578292847cSmrg    $debug_cmd
1858c2939121Smrg
18598292847cSmrg    # Option defaults:
18608292847cSmrg    opt_verbose=false
18618292847cSmrg    opt_warning_types=
18628292847cSmrg
186325420f97Smrg    func_run_hooks func_options_prep ${1+"$@"}
186425420f97Smrg    func_propagate_result func_run_hooks func_options_prep
1865c76ae52dSmrg}
1866c76ae52dSmrg
1867c76ae52dSmrg
18688292847cSmrg# func_parse_options [ARG]...
18698292847cSmrg# ---------------------------
18708292847cSmrg# The main option parsing loop.
18718292847cSmrgfunc_hookable func_parse_options
18728292847cSmrgfunc_parse_options ()
1873c76ae52dSmrg{
18748292847cSmrg    $debug_cmd
1875c2939121Smrg
187625420f97Smrg    _G_parse_options_requote=false
18778292847cSmrg    # this just eases exit handling
18788292847cSmrg    while test $# -gt 0; do
18798292847cSmrg      # Defer to hook functions for initial option parsing, so they
18808292847cSmrg      # get priority in the event of reusing an option name.
188125420f97Smrg      func_run_hooks func_parse_options ${1+"$@"}
188225420f97Smrg      func_propagate_result func_run_hooks func_parse_options
188325420f97Smrg      if $func_propagate_result_result; then
188425420f97Smrg        eval set dummy "$func_parse_options_result"; shift
188525420f97Smrg        # Even though we may have changed "$@", we passed the "$@" array
188625420f97Smrg        # down into the hook and it quoted it for us (because we are in
188725420f97Smrg        # this if-branch).  No need to quote it again.
188825420f97Smrg        _G_parse_options_requote=false
1889de3c0529Smrg      fi
1890c76ae52dSmrg
18918292847cSmrg      # Break out of the loop if we already parsed every option.
18928292847cSmrg      test $# -gt 0 || break
1893c76ae52dSmrg
189425420f97Smrg      # We expect that one of the options parsed in this function matches
189525420f97Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1896de3c0529Smrg      _G_match_parse_options=:
18978292847cSmrg      _G_opt=$1
18988292847cSmrg      shift
18998292847cSmrg      case $_G_opt in
19008292847cSmrg        --debug|-x)   debug_cmd='set -x'
190125420f97Smrg                      func_echo "enabling shell trace mode" >&2
19028292847cSmrg                      $debug_cmd
19038292847cSmrg                      ;;
19048292847cSmrg
19058292847cSmrg        --no-warnings|--no-warning|--no-warn)
19068292847cSmrg                      set dummy --warnings none ${1+"$@"}
19078292847cSmrg                      shift
19088292847cSmrg		      ;;
1909c2939121Smrg
19108292847cSmrg        --warnings|--warning|-W)
1911de3c0529Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
191225420f97Smrg                        _G_parse_options_requote=:
1913de3c0529Smrg                        break
1914de3c0529Smrg                      fi
19158292847cSmrg                      case " $warning_categories $1" in
19168292847cSmrg                        *" $1 "*)
19178292847cSmrg                          # trailing space prevents matching last $1 above
19188292847cSmrg                          func_append_uniq opt_warning_types " $1"
19198292847cSmrg                          ;;
19208292847cSmrg                        *all)
19218292847cSmrg                          opt_warning_types=$warning_categories
19228292847cSmrg                          ;;
19238292847cSmrg                        *none)
19248292847cSmrg                          opt_warning_types=none
19258292847cSmrg                          warning_func=:
19268292847cSmrg                          ;;
19278292847cSmrg                        *error)
19288292847cSmrg                          opt_warning_types=$warning_categories
19298292847cSmrg                          warning_func=func_fatal_error
19308292847cSmrg                          ;;
19318292847cSmrg                        *)
19328292847cSmrg                          func_fatal_error \
19338292847cSmrg                             "unsupported warning category: '$1'"
19348292847cSmrg                          ;;
19358292847cSmrg                      esac
19368292847cSmrg                      shift
19378292847cSmrg                      ;;
19388292847cSmrg
19398292847cSmrg        --verbose|-v) opt_verbose=: ;;
19408292847cSmrg        --version)    func_version ;;
19418292847cSmrg        -\?|-h)       func_usage ;;
19428292847cSmrg        --help)       func_help ;;
19438292847cSmrg
19448292847cSmrg	# Separate optargs to long options (plugins may need this):
19458292847cSmrg	--*=*)        func_split_equals "$_G_opt"
19468292847cSmrg	              set dummy "$func_split_equals_lhs" \
19478292847cSmrg                          "$func_split_equals_rhs" ${1+"$@"}
19488292847cSmrg                      shift
19498292847cSmrg                      ;;
19508292847cSmrg
19518292847cSmrg       # Separate optargs to short options:
19528292847cSmrg        -W*)
19538292847cSmrg                      func_split_short_opt "$_G_opt"
19548292847cSmrg                      set dummy "$func_split_short_opt_name" \
19558292847cSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
19568292847cSmrg                      shift
19578292847cSmrg                      ;;
19588292847cSmrg
19598292847cSmrg        # Separate non-argument short options:
19608292847cSmrg        -\?*|-h*|-v*|-x*)
19618292847cSmrg                      func_split_short_opt "$_G_opt"
19628292847cSmrg                      set dummy "$func_split_short_opt_name" \
19638292847cSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
19648292847cSmrg                      shift
19658292847cSmrg                      ;;
19668292847cSmrg
196725420f97Smrg        --)           _G_parse_options_requote=: ; break ;;
19688292847cSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1969de3c0529Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1970de3c0529Smrg                      _G_match_parse_options=false
1971de3c0529Smrg                      break
1972de3c0529Smrg                      ;;
19738292847cSmrg      esac
1974de3c0529Smrg
197525420f97Smrg      if $_G_match_parse_options; then
197625420f97Smrg        _G_parse_options_requote=:
197725420f97Smrg      fi
19788292847cSmrg    done
19798292847cSmrg
198025420f97Smrg    if $_G_parse_options_requote; then
1981de3c0529Smrg      # save modified positional parameters for caller
198225420f97Smrg      func_quote eval ${1+"$@"}
198325420f97Smrg      func_parse_options_result=$func_quote_result
1984de3c0529Smrg    fi
1985c76ae52dSmrg}
1986c76ae52dSmrg
1987c2939121Smrg
19888292847cSmrg# func_validate_options [ARG]...
19898292847cSmrg# ------------------------------
19908292847cSmrg# Perform any sanity checks on option settings and/or unconsumed
19918292847cSmrg# arguments.
19928292847cSmrgfunc_hookable func_validate_options
19938292847cSmrgfunc_validate_options ()
1994c76ae52dSmrg{
19958292847cSmrg    $debug_cmd
1996c76ae52dSmrg
19978292847cSmrg    # Display all warnings if -W was not given.
19988292847cSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1999c76ae52dSmrg
200025420f97Smrg    func_run_hooks func_validate_options ${1+"$@"}
200125420f97Smrg    func_propagate_result func_run_hooks func_validate_options
2002c76ae52dSmrg
20038292847cSmrg    # Bail if the options were screwed!
20048292847cSmrg    $exit_cmd $EXIT_FAILURE
20052836776bSmrg}
20062836776bSmrg
2007c76ae52dSmrg
20082836776bSmrg
20098292847cSmrg## ----------------- ##
20108292847cSmrg## Helper functions. ##
20118292847cSmrg## ----------------- ##
2012c76ae52dSmrg
20138292847cSmrg# This section contains the helper functions used by the rest of the
20148292847cSmrg# hookable option parser framework in ascii-betical order.
20158292847cSmrg
20168292847cSmrg
20178292847cSmrg# func_fatal_help ARG...
20188292847cSmrg# ----------------------
20198292847cSmrg# Echo program name prefixed message to standard error, followed by
20208292847cSmrg# a help hint, and exit.
20218292847cSmrgfunc_fatal_help ()
2022c2939121Smrg{
20238292847cSmrg    $debug_cmd
20242836776bSmrg
20258292847cSmrg    eval \$ECHO \""Usage: $usage"\"
20268292847cSmrg    eval \$ECHO \""$fatal_help"\"
20278292847cSmrg    func_error ${1+"$@"}
20288292847cSmrg    exit $EXIT_FAILURE
2029c2939121Smrg}
2030c76ae52dSmrg
20318292847cSmrg
20328292847cSmrg# func_help
20338292847cSmrg# ---------
20348292847cSmrg# Echo long help message to standard output and exit.
2035c2939121Smrgfunc_help ()
2036c2939121Smrg{
20378292847cSmrg    $debug_cmd
20388292847cSmrg
20398292847cSmrg    func_usage_message
20408292847cSmrg    $ECHO "$long_help_message"
20418292847cSmrg    exit 0
2042c2939121Smrg}
2043c76ae52dSmrg
20448292847cSmrg
20458292847cSmrg# func_missing_arg ARGNAME
20468292847cSmrg# ------------------------
2047c2939121Smrg# Echo program name prefixed message to standard error and set global
2048c2939121Smrg# exit_cmd.
2049c2939121Smrgfunc_missing_arg ()
2050c2939121Smrg{
20518292847cSmrg    $debug_cmd
20522836776bSmrg
20538292847cSmrg    func_error "Missing argument for '$1'."
2054c2939121Smrg    exit_cmd=exit
2055c2939121Smrg}
2056c76ae52dSmrg
2057c76ae52dSmrg
20588292847cSmrg# func_split_equals STRING
20598292847cSmrg# ------------------------
206025420f97Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
206125420f97Smrg# after splitting STRING at the '=' sign.
20628292847cSmrgtest -z "$_G_HAVE_XSI_OPS" \
20638292847cSmrg    && (eval 'x=a/b/c;
20648292847cSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
20658292847cSmrg    && _G_HAVE_XSI_OPS=yes
20668292847cSmrg
20678292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"
20688292847cSmrgthen
20698292847cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
20708292847cSmrg  eval 'func_split_equals ()
20718292847cSmrg  {
20728292847cSmrg      $debug_cmd
20738292847cSmrg
20748292847cSmrg      func_split_equals_lhs=${1%%=*}
20758292847cSmrg      func_split_equals_rhs=${1#*=}
207625420f97Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
207725420f97Smrg        func_split_equals_rhs=
207825420f97Smrg      fi
20798292847cSmrg  }'
20808292847cSmrgelse
20818292847cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
20828292847cSmrg  func_split_equals ()
20838292847cSmrg  {
20848292847cSmrg      $debug_cmd
20858292847cSmrg
20868292847cSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
20878292847cSmrg      func_split_equals_rhs=
208825420f97Smrg      test "x$func_split_equals_lhs=" = "x$1" \
20898292847cSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
20908292847cSmrg  }
20918292847cSmrgfi #func_split_equals
20928292847cSmrg
20938292847cSmrg
20948292847cSmrg# func_split_short_opt SHORTOPT
20958292847cSmrg# -----------------------------
20962836776bSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
20972836776bSmrg# variables after splitting SHORTOPT after the 2nd character.
20988292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"
20998292847cSmrgthen
21008292847cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
21018292847cSmrg  eval 'func_split_short_opt ()
21028292847cSmrg  {
21038292847cSmrg      $debug_cmd
21048292847cSmrg
21058292847cSmrg      func_split_short_opt_arg=${1#??}
21068292847cSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
21078292847cSmrg  }'
21088292847cSmrgelse
21098292847cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
21108292847cSmrg  func_split_short_opt ()
21118292847cSmrg  {
21128292847cSmrg      $debug_cmd
21138292847cSmrg
211425420f97Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
21158292847cSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
21168292847cSmrg  }
21178292847cSmrgfi #func_split_short_opt
21188292847cSmrg
21198292847cSmrg
21208292847cSmrg# func_usage
21218292847cSmrg# ----------
21228292847cSmrg# Echo short help message to standard output and exit.
21238292847cSmrgfunc_usage ()
21242836776bSmrg{
21258292847cSmrg    $debug_cmd
21262836776bSmrg
21278292847cSmrg    func_usage_message
21288292847cSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
21298292847cSmrg    exit 0
21308292847cSmrg}
21312836776bSmrg
21322836776bSmrg
21338292847cSmrg# func_usage_message
21348292847cSmrg# ------------------
21358292847cSmrg# Echo short help message to standard output.
21368292847cSmrgfunc_usage_message ()
21372836776bSmrg{
21388292847cSmrg    $debug_cmd
21392836776bSmrg
21408292847cSmrg    eval \$ECHO \""Usage: $usage"\"
21418292847cSmrg    echo
21428292847cSmrg    $SED -n 's|^# ||
21438292847cSmrg        /^Written by/{
21448292847cSmrg          x;p;x
21458292847cSmrg        }
21468292847cSmrg	h
21478292847cSmrg	/^Written by/q' < "$progpath"
21488292847cSmrg    echo
21498292847cSmrg    eval \$ECHO \""$usage_message"\"
21508292847cSmrg}
21512836776bSmrg
2152c76ae52dSmrg
21538292847cSmrg# func_version
21548292847cSmrg# ------------
21558292847cSmrg# Echo version message to standard output and exit.
215625420f97Smrg# The version message is extracted from the calling file's header
215725420f97Smrg# comments, with leading '# ' stripped:
215825420f97Smrg#   1. First display the progname and version
215925420f97Smrg#   2. Followed by the header comment line matching  /^# Written by /
216025420f97Smrg#   3. Then a blank line followed by the first following line matching
216125420f97Smrg#      /^# Copyright /
216225420f97Smrg#   4. Immediately followed by any lines between the previous matches,
216325420f97Smrg#      except lines preceding the intervening completely blank line.
216425420f97Smrg# For example, see the header comments of this file.
21658292847cSmrgfunc_version ()
21668292847cSmrg{
21678292847cSmrg    $debug_cmd
2168c76ae52dSmrg
21698292847cSmrg    printf '%s\n' "$progname $scriptversion"
21708292847cSmrg    $SED -n '
217125420f97Smrg        /^# Written by /!b
217225420f97Smrg        s|^# ||; p; n
217325420f97Smrg
217425420f97Smrg        :fwd2blnk
217525420f97Smrg        /./ {
217625420f97Smrg          n
217725420f97Smrg          b fwd2blnk
21788292847cSmrg        }
217925420f97Smrg        p; n
218025420f97Smrg
218125420f97Smrg        :holdwrnt
218225420f97Smrg        s|^# ||
218325420f97Smrg        s|^# *$||
218425420f97Smrg        /^Copyright /!{
218525420f97Smrg          /./H
218625420f97Smrg          n
218725420f97Smrg          b holdwrnt
21888292847cSmrg        }
218925420f97Smrg
219025420f97Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
219125420f97Smrg        G
219225420f97Smrg        s|\(\n\)\n*|\1|g
219325420f97Smrg        p; q' < "$progpath"
21940d590c07Smrg
21958292847cSmrg    exit $?
21968292847cSmrg}
2197c76ae52dSmrg
2198c2939121Smrg
21998292847cSmrg# Local variables:
22008292847cSmrg# mode: shell-script
22018292847cSmrg# sh-indentation: 2
22028292847cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
220325420f97Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
22048292847cSmrg# time-stamp-time-zone: "UTC"
22058292847cSmrg# End:
2206c2939121Smrg
22078292847cSmrg# Set a version string.
220825420f97Smrgscriptversion='(GNU libtool) 2.4.7'
2209c2939121Smrg
2210c2939121Smrg
22118292847cSmrg# func_echo ARG...
22128292847cSmrg# ----------------
22138292847cSmrg# Libtool also displays the current mode in messages, so override
22148292847cSmrg# funclib.sh func_echo with this custom definition.
22158292847cSmrgfunc_echo ()
22162836776bSmrg{
22178292847cSmrg    $debug_cmd
22182836776bSmrg
22198292847cSmrg    _G_message=$*
22202836776bSmrg
22218292847cSmrg    func_echo_IFS=$IFS
22228292847cSmrg    IFS=$nl
22238292847cSmrg    for _G_line in $_G_message; do
22248292847cSmrg      IFS=$func_echo_IFS
22258292847cSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
22268292847cSmrg    done
22278292847cSmrg    IFS=$func_echo_IFS
22288292847cSmrg}
22292836776bSmrg
22308292847cSmrg
22318292847cSmrg# func_warning ARG...
22328292847cSmrg# -------------------
22338292847cSmrg# Libtool warnings are not categorized, so override funclib.sh
22348292847cSmrg# func_warning with this simpler definition.
22358292847cSmrgfunc_warning ()
22362836776bSmrg{
22378292847cSmrg    $debug_cmd
22382836776bSmrg
22398292847cSmrg    $warning_func ${1+"$@"}
22408292847cSmrg}
22412836776bSmrg
22422836776bSmrg
22438292847cSmrg## ---------------- ##
22448292847cSmrg## Options parsing. ##
22458292847cSmrg## ---------------- ##
22468292847cSmrg
22478292847cSmrg# Hook in the functions to make sure our own options are parsed during
22488292847cSmrg# the option parsing loop.
22498292847cSmrg
22508292847cSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
22518292847cSmrg
22528292847cSmrg# Short help message in response to '-h'.
22538292847cSmrgusage_message="Options:
22548292847cSmrg       --config             show all configuration variables
22558292847cSmrg       --debug              enable verbose shell tracing
22568292847cSmrg   -n, --dry-run            display commands without modifying any files
22578292847cSmrg       --features           display basic configuration information and exit
22588292847cSmrg       --mode=MODE          use operation mode MODE
22598292847cSmrg       --no-warnings        equivalent to '-Wnone'
22608292847cSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
22618292847cSmrg       --quiet, --silent    don't print informational messages
22628292847cSmrg       --tag=TAG            use configuration variables from tag TAG
22638292847cSmrg   -v, --verbose            print more informational messages than default
22648292847cSmrg       --version            print version information
22658292847cSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
22668292847cSmrg   -h, --help, --help-all   print short, long, or detailed help message
22678292847cSmrg"
22682836776bSmrg
22698292847cSmrg# Additional text appended to 'usage_message' in response to '--help'.
22708292847cSmrgfunc_help ()
22712836776bSmrg{
22728292847cSmrg    $debug_cmd
22738292847cSmrg
22748292847cSmrg    func_usage_message
22758292847cSmrg    $ECHO "$long_help_message
22768292847cSmrg
22778292847cSmrgMODE must be one of the following:
22788292847cSmrg
22798292847cSmrg       clean           remove files from the build directory
22808292847cSmrg       compile         compile a source file into a libtool object
22818292847cSmrg       execute         automatically set library path, then run a program
22828292847cSmrg       finish          complete the installation of libtool libraries
22838292847cSmrg       install         install libraries or executables
22848292847cSmrg       link            create a library or an executable
22858292847cSmrg       uninstall       remove libraries from an installed directory
22868292847cSmrg
22878292847cSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
22888292847cSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
22898292847cSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
22908292847cSmrg
22918292847cSmrgWhen reporting a bug, please describe a test case to reproduce it and
22928292847cSmrginclude the following information:
22938292847cSmrg
22948292847cSmrg       host-triplet:   $host
22958292847cSmrg       shell:          $SHELL
22968292847cSmrg       compiler:       $LTCC
22978292847cSmrg       compiler flags: $LTCFLAGS
22988292847cSmrg       linker:         $LD (gnu? $with_gnu_ld)
2299de301c82Smrg       version:        $progname $scriptversion Debian-2.4.7-7~deb12u1
23008292847cSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
23018292847cSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
23028292847cSmrg
23038292847cSmrgReport bugs to <bug-libtool@gnu.org>.
2304de301c82SmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
23058292847cSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
23068292847cSmrg    exit 0
23078292847cSmrg}
23082836776bSmrg
23092836776bSmrg
23108292847cSmrg# func_lo2o OBJECT-NAME
23118292847cSmrg# ---------------------
23128292847cSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
23138292847cSmrg# object suffix.
23148292847cSmrg
23158292847cSmrglo2o=s/\\.lo\$/.$objext/
23168292847cSmrgo2lo=s/\\.$objext\$/.lo/
23178292847cSmrg
23188292847cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
23198292847cSmrg  eval 'func_lo2o ()
23208292847cSmrg  {
23218292847cSmrg    case $1 in
23228292847cSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
23238292847cSmrg      *   ) func_lo2o_result=$1               ;;
23248292847cSmrg    esac
23258292847cSmrg  }'
23268292847cSmrg
23278292847cSmrg  # func_xform LIBOBJ-OR-SOURCE
23288292847cSmrg  # ---------------------------
23298292847cSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
23308292847cSmrg  # suffix to a '.lo' libtool-object suffix.
23318292847cSmrg  eval 'func_xform ()
23328292847cSmrg  {
23338292847cSmrg    func_xform_result=${1%.*}.lo
23348292847cSmrg  }'
23358292847cSmrgelse
23368292847cSmrg  # ...otherwise fall back to using sed.
23378292847cSmrg  func_lo2o ()
23388292847cSmrg  {
23398292847cSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
23408292847cSmrg  }
23418292847cSmrg
23428292847cSmrg  func_xform ()
23438292847cSmrg  {
23448292847cSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
23458292847cSmrg  }
23468292847cSmrgfi
23472836776bSmrg
23482836776bSmrg
23498292847cSmrg# func_fatal_configuration ARG...
23508292847cSmrg# -------------------------------
2351c2939121Smrg# Echo program name prefixed message to standard error, followed by
2352c2939121Smrg# a configuration failure hint, and exit.
2353c2939121Smrgfunc_fatal_configuration ()
2354c2939121Smrg{
235525420f97Smrg    func_fatal_error ${1+"$@"} \
23568292847cSmrg      "See the $PACKAGE documentation for more information." \
23578292847cSmrg      "Fatal configuration error."
2358c2939121Smrg}
2359c2939121Smrg
2360c2939121Smrg
2361c2939121Smrg# func_config
23628292847cSmrg# -----------
2363c2939121Smrg# Display the configuration for all the tags in this script.
2364c2939121Smrgfunc_config ()
2365c2939121Smrg{
2366c2939121Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2367c2939121Smrg    re_endcf='^# ### END LIBTOOL'
2368c2939121Smrg
2369c2939121Smrg    # Default configuration.
2370c2939121Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2371c2939121Smrg
2372c76ae52dSmrg    # Now print the configurations for the tags.
2373c76ae52dSmrg    for tagname in $taglist; do
2374c2939121Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2375c76ae52dSmrg    done
2376c76ae52dSmrg
2377c2939121Smrg    exit $?
2378c2939121Smrg}
2379c76ae52dSmrg
23808292847cSmrg
2381c2939121Smrg# func_features
23828292847cSmrg# -------------
2383c2939121Smrg# Display the features supported by this script.
2384c2939121Smrgfunc_features ()
2385c2939121Smrg{
2386c2939121Smrg    echo "host: $host"
23878292847cSmrg    if test yes = "$build_libtool_libs"; then
2388c2939121Smrg      echo "enable shared libraries"
2389c76ae52dSmrg    else
2390c2939121Smrg      echo "disable shared libraries"
2391c76ae52dSmrg    fi
23928292847cSmrg    if test yes = "$build_old_libs"; then
2393c2939121Smrg      echo "enable static libraries"
2394c76ae52dSmrg    else
2395c2939121Smrg      echo "disable static libraries"
2396c76ae52dSmrg    fi
2397c2939121Smrg
2398c76ae52dSmrg    exit $?
2399c2939121Smrg}
2400c76ae52dSmrg
24018292847cSmrg
24028292847cSmrg# func_enable_tag TAGNAME
24038292847cSmrg# -----------------------
2404c2939121Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2405c2939121Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2406c2939121Smrg# variable here.
2407c2939121Smrgfunc_enable_tag ()
2408c2939121Smrg{
24098292847cSmrg    # Global variable:
24108292847cSmrg    tagname=$1
2411c76ae52dSmrg
24128292847cSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
24138292847cSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
24148292847cSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2415c76ae52dSmrg
24168292847cSmrg    # Validate tagname.
24178292847cSmrg    case $tagname in
24188292847cSmrg      *[!-_A-Za-z0-9,/]*)
24198292847cSmrg        func_fatal_error "invalid tag name: $tagname"
24208292847cSmrg        ;;
24218292847cSmrg    esac
2422c76ae52dSmrg
24238292847cSmrg    # Don't test for the "default" C tag, as we know it's
24248292847cSmrg    # there but not specially marked.
24258292847cSmrg    case $tagname in
24268292847cSmrg        CC) ;;
2427c2939121Smrg    *)
24288292847cSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
24298292847cSmrg	  taglist="$taglist $tagname"
24308292847cSmrg
24318292847cSmrg	  # Evaluate the configuration.  Be careful to quote the path
24328292847cSmrg	  # and the sed script, to avoid splitting on whitespace, but
24338292847cSmrg	  # also don't use non-portable quotes within backquotes within
24348292847cSmrg	  # quotes we have to do it in 2 steps:
24358292847cSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
24368292847cSmrg	  eval "$extractedcf"
24378292847cSmrg        else
24388292847cSmrg	  func_error "ignoring unknown tag $tagname"
24398292847cSmrg        fi
24408292847cSmrg        ;;
24418292847cSmrg    esac
2442c2939121Smrg}
2443c2939121Smrg
24448292847cSmrg
24452836776bSmrg# func_check_version_match
24468292847cSmrg# ------------------------
24472836776bSmrg# Ensure that we are using m4 macros, and libtool script from the same
24482836776bSmrg# release of libtool.
24492836776bSmrgfunc_check_version_match ()
2450c2939121Smrg{
24518292847cSmrg    if test "$package_revision" != "$macro_revision"; then
24528292847cSmrg      if test "$VERSION" != "$macro_version"; then
24538292847cSmrg        if test -z "$macro_version"; then
24548292847cSmrg          cat >&2 <<_LT_EOF
24552836776bSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24562836776bSmrg$progname: definition of this LT_INIT comes from an older release.
24572836776bSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24582836776bSmrg$progname: and run autoconf again.
24592836776bSmrg_LT_EOF
24608292847cSmrg        else
24618292847cSmrg          cat >&2 <<_LT_EOF
24622836776bSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24632836776bSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
24642836776bSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24652836776bSmrg$progname: and run autoconf again.
24662836776bSmrg_LT_EOF
24678292847cSmrg        fi
24688292847cSmrg      else
24698292847cSmrg        cat >&2 <<_LT_EOF
24702836776bSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
24712836776bSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
24722836776bSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
24732836776bSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
24742836776bSmrg_LT_EOF
24758292847cSmrg      fi
24762836776bSmrg
24778292847cSmrg      exit $EXIT_MISMATCH
24788292847cSmrg    fi
24792836776bSmrg}
24802836776bSmrg
24812836776bSmrg
24828292847cSmrg# libtool_options_prep [ARG]...
24838292847cSmrg# -----------------------------
24848292847cSmrg# Preparation for options parsed by libtool.
24858292847cSmrglibtool_options_prep ()
24868292847cSmrg{
24878292847cSmrg    $debug_mode
24882836776bSmrg
24898292847cSmrg    # Option defaults:
24908292847cSmrg    opt_config=false
24918292847cSmrg    opt_dlopen=
24928292847cSmrg    opt_dry_run=false
24938292847cSmrg    opt_help=false
24948292847cSmrg    opt_mode=
24958292847cSmrg    opt_preserve_dup_deps=false
24968292847cSmrg    opt_quiet=false
24972836776bSmrg
24988292847cSmrg    nonopt=
24998292847cSmrg    preserve_args=
25002836776bSmrg
2501de3c0529Smrg    _G_rc_lt_options_prep=:
2502de3c0529Smrg
2503de301c82Smrg    _G_rc_lt_options_prep=:
2504de301c82Smrg
25058292847cSmrg    # Shorthand for --mode=foo, only valid as the first argument
25068292847cSmrg    case $1 in
25078292847cSmrg    clean|clea|cle|cl)
25088292847cSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
25098292847cSmrg      ;;
25108292847cSmrg    compile|compil|compi|comp|com|co|c)
25118292847cSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
25128292847cSmrg      ;;
25138292847cSmrg    execute|execut|execu|exec|exe|ex|e)
25148292847cSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
25158292847cSmrg      ;;
25168292847cSmrg    finish|finis|fini|fin|fi|f)
25178292847cSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
25188292847cSmrg      ;;
25198292847cSmrg    install|instal|insta|inst|ins|in|i)
25208292847cSmrg      shift; set dummy --mode install ${1+"$@"}; shift
25218292847cSmrg      ;;
25228292847cSmrg    link|lin|li|l)
25238292847cSmrg      shift; set dummy --mode link ${1+"$@"}; shift
25248292847cSmrg      ;;
25258292847cSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
25268292847cSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
25278292847cSmrg      ;;
2528de3c0529Smrg    *)
2529de3c0529Smrg      _G_rc_lt_options_prep=false
2530de3c0529Smrg      ;;
25318292847cSmrg    esac
25328292847cSmrg
2533de3c0529Smrg    if $_G_rc_lt_options_prep; then
2534de3c0529Smrg      # Pass back the list of options.
253525420f97Smrg      func_quote eval ${1+"$@"}
253625420f97Smrg      libtool_options_prep_result=$func_quote_result
2537de3c0529Smrg    fi
25388292847cSmrg}
25398292847cSmrgfunc_add_hook func_options_prep libtool_options_prep
2540c76ae52dSmrg
2541c76ae52dSmrg
25428292847cSmrg# libtool_parse_options [ARG]...
25438292847cSmrg# ---------------------------------
25448292847cSmrg# Provide handling for libtool specific options.
25458292847cSmrglibtool_parse_options ()
25462836776bSmrg{
25478292847cSmrg    $debug_cmd
2548c2939121Smrg
2549de3c0529Smrg    _G_rc_lt_parse_options=false
2550de3c0529Smrg
25518292847cSmrg    # Perform our own loop to consume as many options as possible in
25528292847cSmrg    # each iteration.
25538292847cSmrg    while test $# -gt 0; do
2554de3c0529Smrg      _G_match_lt_parse_options=:
25558292847cSmrg      _G_opt=$1
25568292847cSmrg      shift
25578292847cSmrg      case $_G_opt in
25588292847cSmrg        --dry-run|--dryrun|-n)
25598292847cSmrg                        opt_dry_run=:
25608292847cSmrg                        ;;
25618292847cSmrg
25628292847cSmrg        --config)       func_config ;;
25638292847cSmrg
25648292847cSmrg        --dlopen|-dlopen)
25658292847cSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
25668292847cSmrg}$1"
25678292847cSmrg                        shift
25688292847cSmrg                        ;;
25698292847cSmrg
25708292847cSmrg        --preserve-dup-deps)
25718292847cSmrg                        opt_preserve_dup_deps=: ;;
25728292847cSmrg
25738292847cSmrg        --features)     func_features ;;
25748292847cSmrg
25758292847cSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
25768292847cSmrg
25778292847cSmrg        --help)         opt_help=: ;;
25788292847cSmrg
25798292847cSmrg        --help-all)     opt_help=': help-all' ;;
25808292847cSmrg
25818292847cSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
25828292847cSmrg                        opt_mode=$1
25838292847cSmrg                        case $1 in
25848292847cSmrg                          # Valid mode arguments:
25858292847cSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
25868292847cSmrg
25878292847cSmrg                          # Catch anything else as an error
25888292847cSmrg                          *) func_error "invalid argument for $_G_opt"
25898292847cSmrg                             exit_cmd=exit
25908292847cSmrg                             break
25918292847cSmrg                             ;;
25928292847cSmrg                        esac
25938292847cSmrg                        shift
25948292847cSmrg                        ;;
25958292847cSmrg
25968292847cSmrg        --no-silent|--no-quiet)
25978292847cSmrg                        opt_quiet=false
25988292847cSmrg                        func_append preserve_args " $_G_opt"
25998292847cSmrg                        ;;
26008292847cSmrg
26018292847cSmrg        --no-warnings|--no-warning|--no-warn)
26028292847cSmrg                        opt_warning=false
26038292847cSmrg                        func_append preserve_args " $_G_opt"
26048292847cSmrg                        ;;
26058292847cSmrg
26068292847cSmrg        --no-verbose)
26078292847cSmrg                        opt_verbose=false
26088292847cSmrg                        func_append preserve_args " $_G_opt"
26098292847cSmrg                        ;;
26108292847cSmrg
26118292847cSmrg        --silent|--quiet)
26128292847cSmrg                        opt_quiet=:
26138292847cSmrg                        opt_verbose=false
26148292847cSmrg                        func_append preserve_args " $_G_opt"
26158292847cSmrg                        ;;
26168292847cSmrg
26178292847cSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
26188292847cSmrg                        opt_tag=$1
26198292847cSmrg                        func_append preserve_args " $_G_opt $1"
26208292847cSmrg                        func_enable_tag "$1"
26218292847cSmrg                        shift
26228292847cSmrg                        ;;
26238292847cSmrg
26248292847cSmrg        --verbose|-v)   opt_quiet=false
26258292847cSmrg                        opt_verbose=:
26268292847cSmrg                        func_append preserve_args " $_G_opt"
26278292847cSmrg                        ;;
26288292847cSmrg
2629de3c0529Smrg        # An option not handled by this hook function:
2630de3c0529Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2631de3c0529Smrg                        _G_match_lt_parse_options=false
2632de3c0529Smrg                        break
2633de3c0529Smrg                        ;;
26348292847cSmrg      esac
2635de3c0529Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
26368292847cSmrg    done
26372836776bSmrg
2638de3c0529Smrg    if $_G_rc_lt_parse_options; then
2639de3c0529Smrg      # save modified positional parameters for caller
264025420f97Smrg      func_quote eval ${1+"$@"}
264125420f97Smrg      libtool_parse_options_result=$func_quote_result
2642de3c0529Smrg    fi
26438292847cSmrg}
26448292847cSmrgfunc_add_hook func_parse_options libtool_parse_options
2645c2939121Smrg
2646c76ae52dSmrg
2647c2939121Smrg
26488292847cSmrg# libtool_validate_options [ARG]...
26498292847cSmrg# ---------------------------------
26508292847cSmrg# Perform any sanity checks on option settings and/or unconsumed
26518292847cSmrg# arguments.
26528292847cSmrglibtool_validate_options ()
26538292847cSmrg{
26548292847cSmrg    # save first non-option argument
26558292847cSmrg    if test 0 -lt $#; then
26568292847cSmrg      nonopt=$1
26578292847cSmrg      shift
2658c2939121Smrg    fi
2659c2939121Smrg
26608292847cSmrg    # preserve --debug
26618292847cSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2662c2939121Smrg
26638292847cSmrg    case $host in
26648292847cSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
26658292847cSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
26668292847cSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
26678292847cSmrg        # don't eliminate duplications in $postdeps and $predeps
26688292847cSmrg        opt_duplicate_compiler_generated_deps=:
26698292847cSmrg        ;;
26708292847cSmrg      *)
26718292847cSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
26728292847cSmrg        ;;
26738292847cSmrg    esac
2674c2939121Smrg
26758292847cSmrg    $opt_help || {
26768292847cSmrg      # Sanity checks first:
26778292847cSmrg      func_check_version_match
26788292847cSmrg
26798292847cSmrg      test yes != "$build_libtool_libs" \
26808292847cSmrg        && test yes != "$build_old_libs" \
26818292847cSmrg        && func_fatal_configuration "not configured to build any kind of library"
26828292847cSmrg
26838292847cSmrg      # Darwin sucks
26848292847cSmrg      eval std_shrext=\"$shrext_cmds\"
26858292847cSmrg
26868292847cSmrg      # Only execute mode is allowed to have -dlopen flags.
26878292847cSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
26888292847cSmrg        func_error "unrecognized option '-dlopen'"
26898292847cSmrg        $ECHO "$help" 1>&2
26908292847cSmrg        exit $EXIT_FAILURE
26918292847cSmrg      fi
2692c2939121Smrg
26938292847cSmrg      # Change the help message to a mode-specific one.
26948292847cSmrg      generic_help=$help
26958292847cSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
26968292847cSmrg    }
2697c2939121Smrg
26988292847cSmrg    # Pass back the unparsed argument list
269925420f97Smrg    func_quote eval ${1+"$@"}
270025420f97Smrg    libtool_validate_options_result=$func_quote_result
27012836776bSmrg}
27028292847cSmrgfunc_add_hook func_validate_options libtool_validate_options
2703c2939121Smrg
2704c2939121Smrg
27058292847cSmrg# Process options as early as possible so that --help and --version
27068292847cSmrg# can return quickly.
27078292847cSmrgfunc_options ${1+"$@"}
27088292847cSmrgeval set dummy "$func_options_result"; shift
27098292847cSmrg
2710c76ae52dSmrg
2711c76ae52dSmrg
27122836776bSmrg## ----------- ##
27132836776bSmrg##    Main.    ##
27142836776bSmrg## ----------- ##
2715c76ae52dSmrg
27168292847cSmrgmagic='%%%MAGIC variable%%%'
27178292847cSmrgmagic_exe='%%%MAGIC EXE variable%%%'
27188292847cSmrg
27198292847cSmrg# Global variables.
27208292847cSmrgextracted_archives=
27218292847cSmrgextracted_serial=0
27228292847cSmrg
27238292847cSmrg# If this variable is set in any of the actions, the command in it
27248292847cSmrg# will be execed at the end.  This prevents here-documents from being
27258292847cSmrg# left over by shells.
27268292847cSmrgexec_cmd=
27278292847cSmrg
27288292847cSmrg
27298292847cSmrg# A function that is used when there is no print builtin or printf.
27308292847cSmrgfunc_fallback_echo ()
27318292847cSmrg{
27328292847cSmrg  eval 'cat <<_LTECHO_EOF
27338292847cSmrg$1
27348292847cSmrg_LTECHO_EOF'
27358292847cSmrg}
27368292847cSmrg
27378292847cSmrg# func_generated_by_libtool
27388292847cSmrg# True iff stdin has been generated by Libtool. This function is only
27398292847cSmrg# a basic sanity check; it will hardly flush out determined imposters.
27408292847cSmrgfunc_generated_by_libtool_p ()
27418292847cSmrg{
27428292847cSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
27438292847cSmrg}
27448292847cSmrg
2745c2939121Smrg# func_lalib_p file
27468292847cSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2747c2939121Smrg# This function is only a basic sanity check; it will hardly flush out
2748c2939121Smrg# determined imposters.
2749c2939121Smrgfunc_lalib_p ()
2750c2939121Smrg{
2751c2939121Smrg    test -f "$1" &&
27528292847cSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2753c2939121Smrg}
2754c76ae52dSmrg
2755c2939121Smrg# func_lalib_unsafe_p file
27568292847cSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2757c2939121Smrg# This function implements the same check as func_lalib_p without
2758c2939121Smrg# resorting to external programs.  To this end, it redirects stdin and
2759c2939121Smrg# closes it afterwards, without saving the original file descriptor.
2760c2939121Smrg# As a safety measure, use it only where a negative result would be
27618292847cSmrg# fatal anyway.  Works if 'file' does not exist.
2762c2939121Smrgfunc_lalib_unsafe_p ()
2763c2939121Smrg{
2764c2939121Smrg    lalib_p=no
2765c2939121Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2766c2939121Smrg	for lalib_p_l in 1 2 3 4
2767c2939121Smrg	do
2768c2939121Smrg	    read lalib_p_line
27698292847cSmrg	    case $lalib_p_line in
2770c2939121Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2771c2939121Smrg	    esac
2772c2939121Smrg	done
2773c2939121Smrg	exec 0<&5 5<&-
2774c2939121Smrg    fi
27758292847cSmrg    test yes = "$lalib_p"
2776c2939121Smrg}
2777c76ae52dSmrg
2778c2939121Smrg# func_ltwrapper_script_p file
2779c2939121Smrg# True iff FILE is a libtool wrapper script
2780c2939121Smrg# This function is only a basic sanity check; it will hardly flush out
2781c2939121Smrg# determined imposters.
2782c2939121Smrgfunc_ltwrapper_script_p ()
2783c2939121Smrg{
27848292847cSmrg    test -f "$1" &&
27858292847cSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2786c2939121Smrg}
2787c76ae52dSmrg
2788c2939121Smrg# func_ltwrapper_executable_p file
2789c2939121Smrg# True iff FILE is a libtool wrapper executable
2790c2939121Smrg# This function is only a basic sanity check; it will hardly flush out
2791c2939121Smrg# determined imposters.
2792c2939121Smrgfunc_ltwrapper_executable_p ()
2793c2939121Smrg{
2794c2939121Smrg    func_ltwrapper_exec_suffix=
2795c2939121Smrg    case $1 in
2796c2939121Smrg    *.exe) ;;
2797c2939121Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2798c2939121Smrg    esac
2799c2939121Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2800c2939121Smrg}
2801c2939121Smrg
2802c2939121Smrg# func_ltwrapper_scriptname file
2803c2939121Smrg# Assumes file is an ltwrapper_executable
2804c2939121Smrg# uses $file to determine the appropriate filename for a
2805c2939121Smrg# temporary ltwrapper_script.
2806c2939121Smrgfunc_ltwrapper_scriptname ()
2807c2939121Smrg{
28082836776bSmrg    func_dirname_and_basename "$1" "" "."
28092836776bSmrg    func_stripname '' '.exe' "$func_basename_result"
28108292847cSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2811c2939121Smrg}
2812c2939121Smrg
2813c2939121Smrg# func_ltwrapper_p file
2814c2939121Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2815c2939121Smrg# This function is only a basic sanity check; it will hardly flush out
2816c2939121Smrg# determined imposters.
2817c2939121Smrgfunc_ltwrapper_p ()
2818c2939121Smrg{
2819c2939121Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2820c2939121Smrg}
2821c2939121Smrg
2822c2939121Smrg
2823c2939121Smrg# func_execute_cmds commands fail_cmd
2824c2939121Smrg# Execute tilde-delimited COMMANDS.
2825c2939121Smrg# If FAIL_CMD is given, eval that upon failure.
2826c2939121Smrg# FAIL_CMD may read-access the current command in variable CMD!
2827c2939121Smrgfunc_execute_cmds ()
2828c2939121Smrg{
28298292847cSmrg    $debug_cmd
28308292847cSmrg
2831c2939121Smrg    save_ifs=$IFS; IFS='~'
2832c2939121Smrg    for cmd in $1; do
28338292847cSmrg      IFS=$sp$nl
2834c2939121Smrg      eval cmd=\"$cmd\"
28358292847cSmrg      IFS=$save_ifs
2836c2939121Smrg      func_show_eval "$cmd" "${2-:}"
2837c2939121Smrg    done
2838c2939121Smrg    IFS=$save_ifs
2839c2939121Smrg}
2840c2939121Smrg
2841c2939121Smrg
2842c2939121Smrg# func_source file
2843c2939121Smrg# Source FILE, adding directory component if necessary.
2844c2939121Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2845c2939121Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2846c2939121Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
28478292847cSmrg# 'FILE.' does not work on cygwin managed mounts.
2848c2939121Smrgfunc_source ()
2849c2939121Smrg{
28508292847cSmrg    $debug_cmd
28518292847cSmrg
2852c2939121Smrg    case $1 in
2853c2939121Smrg    */* | *\\*)	. "$1" ;;
2854c2939121Smrg    *)		. "./$1" ;;
2855c2939121Smrg    esac
2856c2939121Smrg}
2857c2939121Smrg
2858c2939121Smrg
28592836776bSmrg# func_resolve_sysroot PATH
28602836776bSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
28612836776bSmrg# func_resolve_sysroot_result
28622836776bSmrgfunc_resolve_sysroot ()
28632836776bSmrg{
28642836776bSmrg  func_resolve_sysroot_result=$1
28652836776bSmrg  case $func_resolve_sysroot_result in
28662836776bSmrg  =*)
28672836776bSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
28682836776bSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
28692836776bSmrg    ;;
28702836776bSmrg  esac
28712836776bSmrg}
28722836776bSmrg
28732836776bSmrg# func_replace_sysroot PATH
28742836776bSmrg# If PATH begins with the sysroot, replace it with = and
28752836776bSmrg# store the result into func_replace_sysroot_result.
28762836776bSmrgfunc_replace_sysroot ()
28772836776bSmrg{
28788292847cSmrg  case $lt_sysroot:$1 in
28792836776bSmrg  ?*:"$lt_sysroot"*)
28802836776bSmrg    func_stripname "$lt_sysroot" '' "$1"
28818292847cSmrg    func_replace_sysroot_result='='$func_stripname_result
28822836776bSmrg    ;;
28832836776bSmrg  *)
28842836776bSmrg    # Including no sysroot.
28852836776bSmrg    func_replace_sysroot_result=$1
28862836776bSmrg    ;;
28872836776bSmrg  esac
28882836776bSmrg}
28892836776bSmrg
2890c2939121Smrg# func_infer_tag arg
2891c2939121Smrg# Infer tagged configuration to use if any are available and
2892c2939121Smrg# if one wasn't chosen via the "--tag" command line option.
2893c2939121Smrg# Only attempt this if the compiler in the base compile
2894c2939121Smrg# command doesn't match the default compiler.
2895c2939121Smrg# arg is usually of the form 'gcc ...'
2896c2939121Smrgfunc_infer_tag ()
2897c2939121Smrg{
28988292847cSmrg    $debug_cmd
28998292847cSmrg
2900c2939121Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2901c2939121Smrg      CC_quoted=
2902c2939121Smrg      for arg in $CC; do
29032836776bSmrg	func_append_quoted CC_quoted "$arg"
2904c2939121Smrg      done
2905c2939121Smrg      CC_expanded=`func_echo_all $CC`
2906c2939121Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2907c2939121Smrg      case $@ in
2908c2939121Smrg      # Blanks in the command may have been stripped by the calling shell,
2909c2939121Smrg      # but not from the CC environment variable when configure was run.
2910c2939121Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2911c2939121Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2912c2939121Smrg      # Blanks at the start of $base_compile will cause this to fail
2913c2939121Smrg      # if we don't check for them as well.
2914c2939121Smrg      *)
2915c2939121Smrg	for z in $available_tags; do
2916c2939121Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2917c2939121Smrg	    # Evaluate the configuration.
29188292847cSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2919c2939121Smrg	    CC_quoted=
2920c2939121Smrg	    for arg in $CC; do
2921c2939121Smrg	      # Double-quote args containing other shell metacharacters.
29222836776bSmrg	      func_append_quoted CC_quoted "$arg"
2923c2939121Smrg	    done
2924c2939121Smrg	    CC_expanded=`func_echo_all $CC`
2925c2939121Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2926c2939121Smrg	    case "$@ " in
2927c2939121Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2928c2939121Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2929c2939121Smrg	      # The compiler in the base compile command matches
2930c2939121Smrg	      # the one in the tagged configuration.
2931c2939121Smrg	      # Assume this is the tagged configuration we want.
2932c2939121Smrg	      tagname=$z
2933c2939121Smrg	      break
2934c2939121Smrg	      ;;
2935c2939121Smrg	    esac
2936c2939121Smrg	  fi
2937c2939121Smrg	done
2938c2939121Smrg	# If $tagname still isn't set, then no tagged configuration
2939c2939121Smrg	# was found and let the user know that the "--tag" command
2940c2939121Smrg	# line option must be used.
2941c2939121Smrg	if test -z "$tagname"; then
2942c2939121Smrg	  func_echo "unable to infer tagged configuration"
29438292847cSmrg	  func_fatal_error "specify a tag with '--tag'"
2944c2939121Smrg#	else
2945c2939121Smrg#	  func_verbose "using $tagname tagged configuration"
2946c2939121Smrg	fi
2947c2939121Smrg	;;
2948c2939121Smrg      esac
2949c2939121Smrg    fi
2950c2939121Smrg}
2951c2939121Smrg
2952c2939121Smrg
29532836776bSmrg
29542836776bSmrg# func_write_libtool_object output_name pic_name nonpic_name
29552836776bSmrg# Create a libtool object file (analogous to a ".la" file),
29562836776bSmrg# but don't create it if we're doing a dry run.
29572836776bSmrgfunc_write_libtool_object ()
29582836776bSmrg{
29598292847cSmrg    write_libobj=$1
29608292847cSmrg    if test yes = "$build_libtool_libs"; then
29618292847cSmrg      write_lobj=\'$2\'
29622836776bSmrg    else
29632836776bSmrg      write_lobj=none
29642836776bSmrg    fi
29652836776bSmrg
29668292847cSmrg    if test yes = "$build_old_libs"; then
29678292847cSmrg      write_oldobj=\'$3\'
29682836776bSmrg    else
29692836776bSmrg      write_oldobj=none
29702836776bSmrg    fi
29712836776bSmrg
29722836776bSmrg    $opt_dry_run || {
29732836776bSmrg      cat >${write_libobj}T <<EOF
29742836776bSmrg# $write_libobj - a libtool object file
29758292847cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
29762836776bSmrg#
29772836776bSmrg# Please DO NOT delete this file!
29782836776bSmrg# It is necessary for linking the library.
29792836776bSmrg
29802836776bSmrg# Name of the PIC object.
29812836776bSmrgpic_object=$write_lobj
29822836776bSmrg
29832836776bSmrg# Name of the non-PIC object
29842836776bSmrgnon_pic_object=$write_oldobj
29852836776bSmrg
29862836776bSmrgEOF
29878292847cSmrg      $MV "${write_libobj}T" "$write_libobj"
29882836776bSmrg    }
29892836776bSmrg}
29902836776bSmrg
29912836776bSmrg
29922836776bSmrg##################################################
29932836776bSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
29942836776bSmrg##################################################
29952836776bSmrg
29962836776bSmrg# func_convert_core_file_wine_to_w32 ARG
29972836776bSmrg# Helper function used by file name conversion functions when $build is *nix,
29982836776bSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
29992836776bSmrg# correctly configured wine environment available, with the winepath program
30002836776bSmrg# in $build's $PATH.
30012836776bSmrg#
30022836776bSmrg# ARG is the $build file name to be converted to w32 format.
30032836776bSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
30042836776bSmrg# be empty on error (or when ARG is empty)
30052836776bSmrgfunc_convert_core_file_wine_to_w32 ()
30062836776bSmrg{
30078292847cSmrg  $debug_cmd
30088292847cSmrg
30098292847cSmrg  func_convert_core_file_wine_to_w32_result=$1
30102836776bSmrg  if test -n "$1"; then
30112836776bSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
30122836776bSmrg    # are forced to check the contents of stdout. On the other hand, if the
30132836776bSmrg    # command is not found, the shell will set an exit code of 127 and print
30142836776bSmrg    # *an error message* to stdout. So we must check for both error code of
30152836776bSmrg    # zero AND non-empty stdout, which explains the odd construction:
30162836776bSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
30178292847cSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
30182836776bSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
30198292847cSmrg        $SED -e "$sed_naive_backslashify"`
30202836776bSmrg    else
30212836776bSmrg      func_convert_core_file_wine_to_w32_result=
30222836776bSmrg    fi
30232836776bSmrg  fi
30242836776bSmrg}
30252836776bSmrg# end: func_convert_core_file_wine_to_w32
30262836776bSmrg
30272836776bSmrg
30282836776bSmrg# func_convert_core_path_wine_to_w32 ARG
30292836776bSmrg# Helper function used by path conversion functions when $build is *nix, and
30302836776bSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
30312836776bSmrg# configured wine environment available, with the winepath program in $build's
30322836776bSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
30332836776bSmrg#
30342836776bSmrg# ARG is path to be converted from $build format to win32.
30352836776bSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
30362836776bSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
30372836776bSmrg# are convertible, then the result may be empty.
30382836776bSmrgfunc_convert_core_path_wine_to_w32 ()
30392836776bSmrg{
30408292847cSmrg  $debug_cmd
30418292847cSmrg
30422836776bSmrg  # unfortunately, winepath doesn't convert paths, only file names
30438292847cSmrg  func_convert_core_path_wine_to_w32_result=
30442836776bSmrg  if test -n "$1"; then
30452836776bSmrg    oldIFS=$IFS
30462836776bSmrg    IFS=:
30472836776bSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
30482836776bSmrg      IFS=$oldIFS
30492836776bSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
30508292847cSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
30512836776bSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
30528292847cSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
30532836776bSmrg        else
30542836776bSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
30552836776bSmrg        fi
30562836776bSmrg      fi
30572836776bSmrg    done
30582836776bSmrg    IFS=$oldIFS
30592836776bSmrg  fi
30602836776bSmrg}
30612836776bSmrg# end: func_convert_core_path_wine_to_w32
30622836776bSmrg
30632836776bSmrg
30642836776bSmrg# func_cygpath ARGS...
30652836776bSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
30662836776bSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
30672836776bSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
30682836776bSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
30692836776bSmrg# file name or path is assumed to be in w32 format, as previously converted
30702836776bSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
30712836776bSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
30722836776bSmrg# Cygwin format). Returns an empty string on error.
30732836776bSmrg#
30742836776bSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
30752836776bSmrg# be converted.
30762836776bSmrg#
30772836776bSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
30782836776bSmrg# environment variable; do not put it in $PATH.
30792836776bSmrgfunc_cygpath ()
30802836776bSmrg{
30818292847cSmrg  $debug_cmd
30828292847cSmrg
30832836776bSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
30842836776bSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
30852836776bSmrg    if test "$?" -ne 0; then
30862836776bSmrg      # on failure, ensure result is empty
30872836776bSmrg      func_cygpath_result=
30882836776bSmrg    fi
30892836776bSmrg  else
30902836776bSmrg    func_cygpath_result=
30918292847cSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
30922836776bSmrg  fi
30932836776bSmrg}
30942836776bSmrg#end: func_cygpath
30952836776bSmrg
30962836776bSmrg
30972836776bSmrg# func_convert_core_msys_to_w32 ARG
30982836776bSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
30992836776bSmrg# result in func_convert_core_msys_to_w32_result.
31002836776bSmrgfunc_convert_core_msys_to_w32 ()
31012836776bSmrg{
31028292847cSmrg  $debug_cmd
31038292847cSmrg
31042836776bSmrg  # awkward: cmd appends spaces to result
31052836776bSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
31068292847cSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
31072836776bSmrg}
31082836776bSmrg#end: func_convert_core_msys_to_w32
31092836776bSmrg
31102836776bSmrg
31112836776bSmrg# func_convert_file_check ARG1 ARG2
31122836776bSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
31132836776bSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
31142836776bSmrg# func_to_host_file_result to ARG1).
31152836776bSmrgfunc_convert_file_check ()
31162836776bSmrg{
31178292847cSmrg  $debug_cmd
31188292847cSmrg
31198292847cSmrg  if test -z "$2" && test -n "$1"; then
31202836776bSmrg    func_error "Could not determine host file name corresponding to"
31218292847cSmrg    func_error "  '$1'"
31222836776bSmrg    func_error "Continuing, but uninstalled executables may not work."
31232836776bSmrg    # Fallback:
31248292847cSmrg    func_to_host_file_result=$1
31252836776bSmrg  fi
31262836776bSmrg}
31272836776bSmrg# end func_convert_file_check
31282836776bSmrg
31292836776bSmrg
31302836776bSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
31312836776bSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
31322836776bSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
31332836776bSmrg# func_to_host_file_result to a simplistic fallback value (see below).
31342836776bSmrgfunc_convert_path_check ()
31352836776bSmrg{
31368292847cSmrg  $debug_cmd
31378292847cSmrg
31382836776bSmrg  if test -z "$4" && test -n "$3"; then
31392836776bSmrg    func_error "Could not determine the host path corresponding to"
31408292847cSmrg    func_error "  '$3'"
31412836776bSmrg    func_error "Continuing, but uninstalled executables may not work."
31422836776bSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
31432836776bSmrg    # should not be "improved".  See libtool.info.
31442836776bSmrg    if test "x$1" != "x$2"; then
31452836776bSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
31462836776bSmrg      func_to_host_path_result=`echo "$3" |
31472836776bSmrg        $SED -e "$lt_replace_pathsep_chars"`
31482836776bSmrg    else
31498292847cSmrg      func_to_host_path_result=$3
31502836776bSmrg    fi
31512836776bSmrg  fi
31522836776bSmrg}
31532836776bSmrg# end func_convert_path_check
31542836776bSmrg
31552836776bSmrg
31562836776bSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
31572836776bSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
31582836776bSmrg# and appending REPL if ORIG matches BACKPAT.
31592836776bSmrgfunc_convert_path_front_back_pathsep ()
31602836776bSmrg{
31618292847cSmrg  $debug_cmd
31628292847cSmrg
31632836776bSmrg  case $4 in
31648292847cSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
31652836776bSmrg    ;;
31662836776bSmrg  esac
31672836776bSmrg  case $4 in
31682836776bSmrg  $2 ) func_append func_to_host_path_result "$3"
31692836776bSmrg    ;;
31702836776bSmrg  esac
31712836776bSmrg}
31722836776bSmrg# end func_convert_path_front_back_pathsep
31732836776bSmrg
31742836776bSmrg
31752836776bSmrg##################################################
31762836776bSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
31772836776bSmrg##################################################
31788292847cSmrg# invoked via '$to_host_file_cmd ARG'
31792836776bSmrg#
31802836776bSmrg# In each case, ARG is the path to be converted from $build to $host format.
31812836776bSmrg# Result will be available in $func_to_host_file_result.
31822836776bSmrg
31832836776bSmrg
31842836776bSmrg# func_to_host_file ARG
31852836776bSmrg# Converts the file name ARG from $build format to $host format. Return result
31862836776bSmrg# in func_to_host_file_result.
31872836776bSmrgfunc_to_host_file ()
31882836776bSmrg{
31898292847cSmrg  $debug_cmd
31908292847cSmrg
31912836776bSmrg  $to_host_file_cmd "$1"
31922836776bSmrg}
31932836776bSmrg# end func_to_host_file
31942836776bSmrg
31952836776bSmrg
31962836776bSmrg# func_to_tool_file ARG LAZY
31972836776bSmrg# converts the file name ARG from $build format to toolchain format. Return
31982836776bSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
31992836776bSmrg# in (the comma separated) LAZY, no conversion takes place.
32002836776bSmrgfunc_to_tool_file ()
32012836776bSmrg{
32028292847cSmrg  $debug_cmd
32038292847cSmrg
32042836776bSmrg  case ,$2, in
32052836776bSmrg    *,"$to_tool_file_cmd",*)
32062836776bSmrg      func_to_tool_file_result=$1
32072836776bSmrg      ;;
32082836776bSmrg    *)
32092836776bSmrg      $to_tool_file_cmd "$1"
32102836776bSmrg      func_to_tool_file_result=$func_to_host_file_result
32112836776bSmrg      ;;
32122836776bSmrg  esac
32132836776bSmrg}
32142836776bSmrg# end func_to_tool_file
32152836776bSmrg
32162836776bSmrg
32172836776bSmrg# func_convert_file_noop ARG
32182836776bSmrg# Copy ARG to func_to_host_file_result.
32192836776bSmrgfunc_convert_file_noop ()
32202836776bSmrg{
32218292847cSmrg  func_to_host_file_result=$1
32222836776bSmrg}
32232836776bSmrg# end func_convert_file_noop
32242836776bSmrg
32252836776bSmrg
32262836776bSmrg# func_convert_file_msys_to_w32 ARG
32272836776bSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
32282836776bSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
32292836776bSmrg# func_to_host_file_result.
32302836776bSmrgfunc_convert_file_msys_to_w32 ()
32312836776bSmrg{
32328292847cSmrg  $debug_cmd
32338292847cSmrg
32348292847cSmrg  func_to_host_file_result=$1
32352836776bSmrg  if test -n "$1"; then
32362836776bSmrg    func_convert_core_msys_to_w32 "$1"
32378292847cSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
32382836776bSmrg  fi
32392836776bSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
32402836776bSmrg}
32412836776bSmrg# end func_convert_file_msys_to_w32
32422836776bSmrg
32432836776bSmrg
32442836776bSmrg# func_convert_file_cygwin_to_w32 ARG
32452836776bSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
32462836776bSmrg# func_to_host_file_result.
32472836776bSmrgfunc_convert_file_cygwin_to_w32 ()
32482836776bSmrg{
32498292847cSmrg  $debug_cmd
32508292847cSmrg
32518292847cSmrg  func_to_host_file_result=$1
32522836776bSmrg  if test -n "$1"; then
32532836776bSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
32542836776bSmrg    # LT_CYGPATH in this case.
32552836776bSmrg    func_to_host_file_result=`cygpath -m "$1"`
32562836776bSmrg  fi
32572836776bSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
32582836776bSmrg}
32592836776bSmrg# end func_convert_file_cygwin_to_w32
32602836776bSmrg
32612836776bSmrg
32622836776bSmrg# func_convert_file_nix_to_w32 ARG
32632836776bSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
32642836776bSmrg# and a working winepath. Returns result in func_to_host_file_result.
32652836776bSmrgfunc_convert_file_nix_to_w32 ()
32662836776bSmrg{
32678292847cSmrg  $debug_cmd
32688292847cSmrg
32698292847cSmrg  func_to_host_file_result=$1
32702836776bSmrg  if test -n "$1"; then
32712836776bSmrg    func_convert_core_file_wine_to_w32 "$1"
32728292847cSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
32732836776bSmrg  fi
32742836776bSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
32752836776bSmrg}
32762836776bSmrg# end func_convert_file_nix_to_w32
32772836776bSmrg
32782836776bSmrg
32792836776bSmrg# func_convert_file_msys_to_cygwin ARG
32802836776bSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32812836776bSmrg# Returns result in func_to_host_file_result.
32822836776bSmrgfunc_convert_file_msys_to_cygwin ()
32832836776bSmrg{
32848292847cSmrg  $debug_cmd
32858292847cSmrg
32868292847cSmrg  func_to_host_file_result=$1
32872836776bSmrg  if test -n "$1"; then
32882836776bSmrg    func_convert_core_msys_to_w32 "$1"
32892836776bSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
32908292847cSmrg    func_to_host_file_result=$func_cygpath_result
32912836776bSmrg  fi
32922836776bSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
32932836776bSmrg}
32942836776bSmrg# end func_convert_file_msys_to_cygwin
32952836776bSmrg
32962836776bSmrg
32972836776bSmrg# func_convert_file_nix_to_cygwin ARG
32982836776bSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
32992836776bSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
33002836776bSmrg# in func_to_host_file_result.
33012836776bSmrgfunc_convert_file_nix_to_cygwin ()
33022836776bSmrg{
33038292847cSmrg  $debug_cmd
33048292847cSmrg
33058292847cSmrg  func_to_host_file_result=$1
33062836776bSmrg  if test -n "$1"; then
33072836776bSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
33082836776bSmrg    func_convert_core_file_wine_to_w32 "$1"
33092836776bSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
33108292847cSmrg    func_to_host_file_result=$func_cygpath_result
33112836776bSmrg  fi
33122836776bSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
33132836776bSmrg}
33142836776bSmrg# end func_convert_file_nix_to_cygwin
33152836776bSmrg
33162836776bSmrg
33172836776bSmrg#############################################
33182836776bSmrg# $build to $host PATH CONVERSION FUNCTIONS #
33192836776bSmrg#############################################
33208292847cSmrg# invoked via '$to_host_path_cmd ARG'
33212836776bSmrg#
33222836776bSmrg# In each case, ARG is the path to be converted from $build to $host format.
33232836776bSmrg# The result will be available in $func_to_host_path_result.
33242836776bSmrg#
33252836776bSmrg# Path separators are also converted from $build format to $host format.  If
33262836776bSmrg# ARG begins or ends with a path separator character, it is preserved (but
33272836776bSmrg# converted to $host format) on output.
33282836776bSmrg#
33292836776bSmrg# All path conversion functions are named using the following convention:
33302836776bSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
33312836776bSmrg#   path conversion function         : func_convert_path_X_to_Y ()
33322836776bSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
33332836776bSmrg# same.  If conversion functions are added for new $build/$host combinations,
33342836776bSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
33352836776bSmrg# will break.
33362836776bSmrg
33372836776bSmrg
33382836776bSmrg# func_init_to_host_path_cmd
33392836776bSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
33402836776bSmrg# appropriate value, based on the value of $to_host_file_cmd.
33412836776bSmrgto_host_path_cmd=
33422836776bSmrgfunc_init_to_host_path_cmd ()
33432836776bSmrg{
33448292847cSmrg  $debug_cmd
33458292847cSmrg
33462836776bSmrg  if test -z "$to_host_path_cmd"; then
33472836776bSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
33488292847cSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
33492836776bSmrg  fi
33502836776bSmrg}
33512836776bSmrg
33522836776bSmrg
33532836776bSmrg# func_to_host_path ARG
33542836776bSmrg# Converts the path ARG from $build format to $host format. Return result
33552836776bSmrg# in func_to_host_path_result.
33562836776bSmrgfunc_to_host_path ()
33572836776bSmrg{
33588292847cSmrg  $debug_cmd
33598292847cSmrg
33602836776bSmrg  func_init_to_host_path_cmd
33612836776bSmrg  $to_host_path_cmd "$1"
33622836776bSmrg}
33632836776bSmrg# end func_to_host_path
33642836776bSmrg
33652836776bSmrg
33662836776bSmrg# func_convert_path_noop ARG
33672836776bSmrg# Copy ARG to func_to_host_path_result.
33682836776bSmrgfunc_convert_path_noop ()
33692836776bSmrg{
33708292847cSmrg  func_to_host_path_result=$1
33712836776bSmrg}
33722836776bSmrg# end func_convert_path_noop
33732836776bSmrg
33742836776bSmrg
33752836776bSmrg# func_convert_path_msys_to_w32 ARG
33762836776bSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
33772836776bSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
33782836776bSmrg# func_to_host_path_result.
33792836776bSmrgfunc_convert_path_msys_to_w32 ()
33802836776bSmrg{
33818292847cSmrg  $debug_cmd
33828292847cSmrg
33838292847cSmrg  func_to_host_path_result=$1
33842836776bSmrg  if test -n "$1"; then
33852836776bSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
33862836776bSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
33872836776bSmrg    # and winepath ignores them completely.
33882836776bSmrg    func_stripname : : "$1"
33892836776bSmrg    func_to_host_path_tmp1=$func_stripname_result
33902836776bSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
33918292847cSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
33922836776bSmrg    func_convert_path_check : ";" \
33932836776bSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
33942836776bSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
33952836776bSmrg  fi
33962836776bSmrg}
33972836776bSmrg# end func_convert_path_msys_to_w32
33982836776bSmrg
33992836776bSmrg
34002836776bSmrg# func_convert_path_cygwin_to_w32 ARG
34012836776bSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
34022836776bSmrg# func_to_host_file_result.
34032836776bSmrgfunc_convert_path_cygwin_to_w32 ()
34042836776bSmrg{
34058292847cSmrg  $debug_cmd
34068292847cSmrg
34078292847cSmrg  func_to_host_path_result=$1
34082836776bSmrg  if test -n "$1"; then
34092836776bSmrg    # See func_convert_path_msys_to_w32:
34102836776bSmrg    func_stripname : : "$1"
34112836776bSmrg    func_to_host_path_tmp1=$func_stripname_result
34122836776bSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
34132836776bSmrg    func_convert_path_check : ";" \
34142836776bSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34152836776bSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34162836776bSmrg  fi
34172836776bSmrg}
34182836776bSmrg# end func_convert_path_cygwin_to_w32
34192836776bSmrg
34202836776bSmrg
34212836776bSmrg# func_convert_path_nix_to_w32 ARG
34222836776bSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
34232836776bSmrg# a working winepath.  Returns result in func_to_host_file_result.
34242836776bSmrgfunc_convert_path_nix_to_w32 ()
3425c2939121Smrg{
34268292847cSmrg  $debug_cmd
34278292847cSmrg
34288292847cSmrg  func_to_host_path_result=$1
34292836776bSmrg  if test -n "$1"; then
34302836776bSmrg    # See func_convert_path_msys_to_w32:
34312836776bSmrg    func_stripname : : "$1"
34322836776bSmrg    func_to_host_path_tmp1=$func_stripname_result
34332836776bSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34348292847cSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
34352836776bSmrg    func_convert_path_check : ";" \
34362836776bSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34372836776bSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34382836776bSmrg  fi
34392836776bSmrg}
34402836776bSmrg# end func_convert_path_nix_to_w32
3441c2939121Smrg
3442c2939121Smrg
34432836776bSmrg# func_convert_path_msys_to_cygwin ARG
34442836776bSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
34452836776bSmrg# Returns result in func_to_host_file_result.
34462836776bSmrgfunc_convert_path_msys_to_cygwin ()
34472836776bSmrg{
34488292847cSmrg  $debug_cmd
34498292847cSmrg
34508292847cSmrg  func_to_host_path_result=$1
34512836776bSmrg  if test -n "$1"; then
34522836776bSmrg    # See func_convert_path_msys_to_w32:
34532836776bSmrg    func_stripname : : "$1"
34542836776bSmrg    func_to_host_path_tmp1=$func_stripname_result
34552836776bSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
34562836776bSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
34578292847cSmrg    func_to_host_path_result=$func_cygpath_result
34582836776bSmrg    func_convert_path_check : : \
34592836776bSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34602836776bSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34612836776bSmrg  fi
34622836776bSmrg}
34632836776bSmrg# end func_convert_path_msys_to_cygwin
3464c2939121Smrg
3465c2939121Smrg
34662836776bSmrg# func_convert_path_nix_to_cygwin ARG
34672836776bSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
34682836776bSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
34692836776bSmrg# func_to_host_file_result.
34702836776bSmrgfunc_convert_path_nix_to_cygwin ()
34712836776bSmrg{
34728292847cSmrg  $debug_cmd
34738292847cSmrg
34748292847cSmrg  func_to_host_path_result=$1
34752836776bSmrg  if test -n "$1"; then
34762836776bSmrg    # Remove leading and trailing path separator characters from
34772836776bSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
34782836776bSmrg    # into '.;' and ';.', and winepath ignores them completely.
34792836776bSmrg    func_stripname : : "$1"
34802836776bSmrg    func_to_host_path_tmp1=$func_stripname_result
34812836776bSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34822836776bSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
34838292847cSmrg    func_to_host_path_result=$func_cygpath_result
34842836776bSmrg    func_convert_path_check : : \
34852836776bSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34862836776bSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34872836776bSmrg  fi
3488c2939121Smrg}
34892836776bSmrg# end func_convert_path_nix_to_cygwin
34902836776bSmrg
3491c2939121Smrg
34928292847cSmrg# func_dll_def_p FILE
34938292847cSmrg# True iff FILE is a Windows DLL '.def' file.
34948292847cSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
34958292847cSmrgfunc_dll_def_p ()
34968292847cSmrg{
34978292847cSmrg  $debug_cmd
34988292847cSmrg
34998292847cSmrg  func_dll_def_p_tmp=`$SED -n \
35008292847cSmrg    -e 's/^[	 ]*//' \
35018292847cSmrg    -e '/^\(;.*\)*$/d' \
35028292847cSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
35038292847cSmrg    -e q \
35048292847cSmrg    "$1"`
35058292847cSmrg  test DEF = "$func_dll_def_p_tmp"
35068292847cSmrg}
35078292847cSmrg
35088292847cSmrg
3509c2939121Smrg# func_mode_compile arg...
3510c2939121Smrgfunc_mode_compile ()
3511c2939121Smrg{
35128292847cSmrg    $debug_cmd
35138292847cSmrg
3514c2939121Smrg    # Get the compilation command and the source file.
3515c2939121Smrg    base_compile=
35168292847cSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3517c2939121Smrg    suppress_opt=yes
3518c2939121Smrg    suppress_output=
3519c2939121Smrg    arg_mode=normal
3520c2939121Smrg    libobj=
3521c2939121Smrg    later=
3522c2939121Smrg    pie_flag=
3523c2939121Smrg
3524c2939121Smrg    for arg
3525c2939121Smrg    do
3526c2939121Smrg      case $arg_mode in
3527c2939121Smrg      arg  )
3528c2939121Smrg	# do not "continue".  Instead, add this to base_compile
35298292847cSmrg	lastarg=$arg
3530c2939121Smrg	arg_mode=normal
3531c2939121Smrg	;;
3532c2939121Smrg
3533c2939121Smrg      target )
35348292847cSmrg	libobj=$arg
3535c2939121Smrg	arg_mode=normal
3536c2939121Smrg	continue
3537c2939121Smrg	;;
3538c2939121Smrg
3539c2939121Smrg      normal )
3540c2939121Smrg	# Accept any command-line options.
3541c2939121Smrg	case $arg in
3542c2939121Smrg	-o)
3543c2939121Smrg	  test -n "$libobj" && \
35448292847cSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3545c2939121Smrg	  arg_mode=target
3546c2939121Smrg	  continue
3547c2939121Smrg	  ;;
3548c2939121Smrg
3549c2939121Smrg	-pie | -fpie | -fPIE)
35502836776bSmrg          func_append pie_flag " $arg"
3551c2939121Smrg	  continue
3552c2939121Smrg	  ;;
3553c2939121Smrg
3554c2939121Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
35552836776bSmrg	  func_append later " $arg"
3556c2939121Smrg	  continue
3557c2939121Smrg	  ;;
3558c76ae52dSmrg
3559c76ae52dSmrg	-no-suppress)
3560c76ae52dSmrg	  suppress_opt=no
3561c76ae52dSmrg	  continue
3562c76ae52dSmrg	  ;;
3563c76ae52dSmrg
3564c76ae52dSmrg	-Xcompiler)
3565c76ae52dSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3566c76ae52dSmrg	  continue      #  The current "srcfile" will either be retained or
3567c76ae52dSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3568c76ae52dSmrg
3569c76ae52dSmrg	-Wc,*)
3570c2939121Smrg	  func_stripname '-Wc,' '' "$arg"
3571c2939121Smrg	  args=$func_stripname_result
3572c76ae52dSmrg	  lastarg=
35738292847cSmrg	  save_ifs=$IFS; IFS=,
3574c2939121Smrg	  for arg in $args; do
35758292847cSmrg	    IFS=$save_ifs
35762836776bSmrg	    func_append_quoted lastarg "$arg"
3577c76ae52dSmrg	  done
35788292847cSmrg	  IFS=$save_ifs
3579c2939121Smrg	  func_stripname ' ' '' "$lastarg"
3580c2939121Smrg	  lastarg=$func_stripname_result
3581c76ae52dSmrg
3582c76ae52dSmrg	  # Add the arguments to base_compile.
35832836776bSmrg	  func_append base_compile " $lastarg"
3584c76ae52dSmrg	  continue
3585c76ae52dSmrg	  ;;
3586c76ae52dSmrg
3587c2939121Smrg	*)
3588c76ae52dSmrg	  # Accept the current argument as the source file.
3589c76ae52dSmrg	  # The previous "srcfile" becomes the current argument.
3590c76ae52dSmrg	  #
35918292847cSmrg	  lastarg=$srcfile
35928292847cSmrg	  srcfile=$arg
3593c76ae52dSmrg	  ;;
3594c76ae52dSmrg	esac  #  case $arg
3595c76ae52dSmrg	;;
3596c76ae52dSmrg      esac    #  case $arg_mode
3597c76ae52dSmrg
3598c76ae52dSmrg      # Aesthetically quote the previous argument.
35992836776bSmrg      func_append_quoted base_compile "$lastarg"
3600c76ae52dSmrg    done # for arg
3601c76ae52dSmrg
3602c76ae52dSmrg    case $arg_mode in
3603c76ae52dSmrg    arg)
3604c2939121Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3605c76ae52dSmrg      ;;
3606c76ae52dSmrg    target)
36078292847cSmrg      func_fatal_error "you must specify a target with '-o'"
3608c76ae52dSmrg      ;;
3609c76ae52dSmrg    *)
3610c76ae52dSmrg      # Get the name of the library object.
3611c2939121Smrg      test -z "$libobj" && {
3612c2939121Smrg	func_basename "$srcfile"
36138292847cSmrg	libobj=$func_basename_result
3614c2939121Smrg      }
3615c76ae52dSmrg      ;;
3616c76ae52dSmrg    esac
3617c76ae52dSmrg
3618c76ae52dSmrg    # Recognize several different file suffixes.
3619c76ae52dSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3620c76ae52dSmrg    case $libobj in
3621c2939121Smrg    *.[cCFSifmso] | \
3622c2939121Smrg    *.ada | *.adb | *.ads | *.asm | \
3623c2939121Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
36242836776bSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3625c2939121Smrg      func_xform "$libobj"
3626c2939121Smrg      libobj=$func_xform_result
3627c2939121Smrg      ;;
3628c76ae52dSmrg    esac
3629c76ae52dSmrg
3630c76ae52dSmrg    case $libobj in
3631c2939121Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3632c76ae52dSmrg    *)
36338292847cSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3634c76ae52dSmrg      ;;
3635c76ae52dSmrg    esac
3636c76ae52dSmrg
3637c76ae52dSmrg    func_infer_tag $base_compile
3638c76ae52dSmrg
3639c76ae52dSmrg    for arg in $later; do
3640c76ae52dSmrg      case $arg in
3641c2939121Smrg      -shared)
36428292847cSmrg	test yes = "$build_libtool_libs" \
36438292847cSmrg	  || func_fatal_configuration "cannot build a shared library"
3644c2939121Smrg	build_old_libs=no
3645c2939121Smrg	continue
3646c2939121Smrg	;;
3647c2939121Smrg
3648c76ae52dSmrg      -static)
3649c2939121Smrg	build_libtool_libs=no
3650c76ae52dSmrg	build_old_libs=yes
3651c76ae52dSmrg	continue
3652c76ae52dSmrg	;;
3653c76ae52dSmrg
3654c76ae52dSmrg      -prefer-pic)
3655c76ae52dSmrg	pic_mode=yes
3656c76ae52dSmrg	continue
3657c76ae52dSmrg	;;
3658c76ae52dSmrg
3659c76ae52dSmrg      -prefer-non-pic)
3660c76ae52dSmrg	pic_mode=no
3661c76ae52dSmrg	continue
3662c76ae52dSmrg	;;
3663c76ae52dSmrg      esac
3664c76ae52dSmrg    done
3665c76ae52dSmrg
366625420f97Smrg    func_quote_arg pretty "$libobj"
366725420f97Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3668c2939121Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
36698292847cSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3670c2939121Smrg    func_dirname_and_basename "$obj" "/" ""
36718292847cSmrg    objname=$func_basename_result
36728292847cSmrg    xdir=$func_dirname_result
36738292847cSmrg    lobj=$xdir$objdir/$objname
3674c76ae52dSmrg
3675c2939121Smrg    test -z "$base_compile" && \
3676c2939121Smrg      func_fatal_help "you must specify a compilation command"
3677c76ae52dSmrg
3678c76ae52dSmrg    # Delete any leftover library objects.
36798292847cSmrg    if test yes = "$build_old_libs"; then
3680c76ae52dSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3681c76ae52dSmrg    else
3682c76ae52dSmrg      removelist="$lobj $libobj ${libobj}T"
3683c76ae52dSmrg    fi
3684c76ae52dSmrg
3685c76ae52dSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3686c76ae52dSmrg    case $host_os in
3687c2939121Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3688c76ae52dSmrg      pic_mode=default
3689c76ae52dSmrg      ;;
3690c76ae52dSmrg    esac
36918292847cSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3692c76ae52dSmrg      # non-PIC code in shared libraries is not supported
3693c76ae52dSmrg      pic_mode=default
3694c76ae52dSmrg    fi
3695c76ae52dSmrg
3696c76ae52dSmrg    # Calculate the filename of the output object if compiler does
3697c76ae52dSmrg    # not support -o with -c
36988292847cSmrg    if test no = "$compiler_c_o"; then
36998292847cSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
37008292847cSmrg      lockfile=$output_obj.lock
3701c76ae52dSmrg    else
3702c76ae52dSmrg      output_obj=
3703c76ae52dSmrg      need_locks=no
3704c76ae52dSmrg      lockfile=
3705c76ae52dSmrg    fi
3706c76ae52dSmrg
3707c76ae52dSmrg    # Lock this critical section if it is needed
3708c76ae52dSmrg    # We use this script file to make the link, it avoids creating a new file
37098292847cSmrg    if test yes = "$need_locks"; then
3710c2939121Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3711c2939121Smrg	func_echo "Waiting for $lockfile to be removed"
3712c76ae52dSmrg	sleep 2
3713c76ae52dSmrg      done
37148292847cSmrg    elif test warn = "$need_locks"; then
3715c76ae52dSmrg      if test -f "$lockfile"; then
3716c2939121Smrg	$ECHO "\
3717c76ae52dSmrg*** ERROR, $lockfile exists and contains:
3718c76ae52dSmrg`cat $lockfile 2>/dev/null`
3719c76ae52dSmrg
3720c76ae52dSmrgThis indicates that another process is trying to use the same
3721c76ae52dSmrgtemporary object file, and libtool could not work around it because
37228292847cSmrgyour compiler does not support '-c' and '-o' together.  If you
3723c76ae52dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3724c76ae52dSmrgavoid parallel builds (make -j) in this platform, or get a better
3725c76ae52dSmrgcompiler."
3726c76ae52dSmrg
3727c2939121Smrg	$opt_dry_run || $RM $removelist
3728c76ae52dSmrg	exit $EXIT_FAILURE
3729c76ae52dSmrg      fi
37302836776bSmrg      func_append removelist " $output_obj"
3731c2939121Smrg      $ECHO "$srcfile" > "$lockfile"
3732c76ae52dSmrg    fi
3733c76ae52dSmrg
3734c2939121Smrg    $opt_dry_run || $RM $removelist
37352836776bSmrg    func_append removelist " $lockfile"
3736c2939121Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3737c2939121Smrg
37382836776bSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
37392836776bSmrg    srcfile=$func_to_tool_file_result
374025420f97Smrg    func_quote_arg pretty "$srcfile"
374125420f97Smrg    qsrcfile=$func_quote_arg_result
3742c76ae52dSmrg
3743c76ae52dSmrg    # Only build a PIC object if we are building libtool libraries.
37448292847cSmrg    if test yes = "$build_libtool_libs"; then
3745c76ae52dSmrg      # Without this assignment, base_compile gets emptied.
3746c76ae52dSmrg      fbsd_hideous_sh_bug=$base_compile
3747c76ae52dSmrg
37488292847cSmrg      if test no != "$pic_mode"; then
3749c76ae52dSmrg	command="$base_compile $qsrcfile $pic_flag"
3750c76ae52dSmrg      else
3751c76ae52dSmrg	# Don't build PIC code
3752c76ae52dSmrg	command="$base_compile $qsrcfile"
3753c76ae52dSmrg      fi
3754c76ae52dSmrg
3755c2939121Smrg      func_mkdir_p "$xdir$objdir"
3756c76ae52dSmrg
3757c76ae52dSmrg      if test -z "$output_obj"; then
3758c76ae52dSmrg	# Place PIC objects in $objdir
37592836776bSmrg	func_append command " -o $lobj"
3760c76ae52dSmrg      fi
3761c76ae52dSmrg
3762c2939121Smrg      func_show_eval_locale "$command"	\
3763c2939121Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3764c76ae52dSmrg
37658292847cSmrg      if test warn = "$need_locks" &&
3766c76ae52dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3767c2939121Smrg	$ECHO "\
3768c76ae52dSmrg*** ERROR, $lockfile contains:
3769c76ae52dSmrg`cat $lockfile 2>/dev/null`
3770c76ae52dSmrg
3771c76ae52dSmrgbut it should contain:
3772c76ae52dSmrg$srcfile
3773c76ae52dSmrg
3774c76ae52dSmrgThis indicates that another process is trying to use the same
3775c76ae52dSmrgtemporary object file, and libtool could not work around it because
37768292847cSmrgyour compiler does not support '-c' and '-o' together.  If you
3777c76ae52dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3778c76ae52dSmrgavoid parallel builds (make -j) in this platform, or get a better
3779c76ae52dSmrgcompiler."
3780c76ae52dSmrg
3781c2939121Smrg	$opt_dry_run || $RM $removelist
3782c76ae52dSmrg	exit $EXIT_FAILURE
3783c76ae52dSmrg      fi
3784c76ae52dSmrg
3785c76ae52dSmrg      # Just move the object if needed, then go on to compile the next one
3786c76ae52dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3787c2939121Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3788c2939121Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3789c76ae52dSmrg      fi
3790c76ae52dSmrg
3791c76ae52dSmrg      # Allow error messages only from the first compilation.
37928292847cSmrg      if test yes = "$suppress_opt"; then
3793c2939121Smrg	suppress_output=' >/dev/null 2>&1'
3794c76ae52dSmrg      fi
3795c76ae52dSmrg    fi
3796c76ae52dSmrg
3797c76ae52dSmrg    # Only build a position-dependent object if we build old libraries.
37988292847cSmrg    if test yes = "$build_old_libs"; then
37998292847cSmrg      if test yes != "$pic_mode"; then
3800c76ae52dSmrg	# Don't build PIC code
3801c2939121Smrg	command="$base_compile $qsrcfile$pie_flag"
3802c76ae52dSmrg      else
3803c76ae52dSmrg	command="$base_compile $qsrcfile $pic_flag"
3804c76ae52dSmrg      fi
38058292847cSmrg      if test yes = "$compiler_c_o"; then
38062836776bSmrg	func_append command " -o $obj"
3807c76ae52dSmrg      fi
3808c76ae52dSmrg
3809c76ae52dSmrg      # Suppress compiler output if we already did a PIC compilation.
38102836776bSmrg      func_append command "$suppress_output"
3811c2939121Smrg      func_show_eval_locale "$command" \
3812c2939121Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3813c76ae52dSmrg
38148292847cSmrg      if test warn = "$need_locks" &&
3815c76ae52dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3816c2939121Smrg	$ECHO "\
3817c76ae52dSmrg*** ERROR, $lockfile contains:
3818c76ae52dSmrg`cat $lockfile 2>/dev/null`
3819c76ae52dSmrg
3820c76ae52dSmrgbut it should contain:
3821c76ae52dSmrg$srcfile
3822c76ae52dSmrg
3823c76ae52dSmrgThis indicates that another process is trying to use the same
3824c76ae52dSmrgtemporary object file, and libtool could not work around it because
38258292847cSmrgyour compiler does not support '-c' and '-o' together.  If you
3826c76ae52dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3827c76ae52dSmrgavoid parallel builds (make -j) in this platform, or get a better
3828c76ae52dSmrgcompiler."
3829c76ae52dSmrg
3830c2939121Smrg	$opt_dry_run || $RM $removelist
3831c76ae52dSmrg	exit $EXIT_FAILURE
3832c76ae52dSmrg      fi
3833c76ae52dSmrg
3834c76ae52dSmrg      # Just move the object if needed
3835c76ae52dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3836c2939121Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3837c2939121Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3838c76ae52dSmrg      fi
3839c76ae52dSmrg    fi
3840c76ae52dSmrg
3841c2939121Smrg    $opt_dry_run || {
3842c2939121Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3843c76ae52dSmrg
3844c2939121Smrg      # Unlock the critical section if it was locked
38458292847cSmrg      if test no != "$need_locks"; then
3846c2939121Smrg	removelist=$lockfile
3847c2939121Smrg        $RM "$lockfile"
3848c2939121Smrg      fi
3849c2939121Smrg    }
3850c76ae52dSmrg
3851c76ae52dSmrg    exit $EXIT_SUCCESS
3852c2939121Smrg}
3853c76ae52dSmrg
3854c2939121Smrg$opt_help || {
38558292847cSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3856c2939121Smrg}
3857c76ae52dSmrg
3858c2939121Smrgfunc_mode_help ()
3859c2939121Smrg{
3860c2939121Smrg    # We need to display help for each of the modes.
38612836776bSmrg    case $opt_mode in
3862c2939121Smrg      "")
3863c2939121Smrg        # Generic help is extracted from the usage comments
3864c2939121Smrg        # at the start of this file.
3865c2939121Smrg        func_help
3866c2939121Smrg        ;;
3867c76ae52dSmrg
3868c2939121Smrg      clean)
3869c2939121Smrg        $ECHO \
3870c2939121Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3871c76ae52dSmrg
3872c2939121SmrgRemove files from the build directory.
3873c76ae52dSmrg
3874c2939121SmrgRM is the name of the program to use to delete files associated with each FILE
38758292847cSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3876c2939121Smrgto RM.
3877c76ae52dSmrg
3878c2939121SmrgIf FILE is a libtool library, object or program, all the files associated
3879c2939121Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3880c2939121Smrg        ;;
3881c76ae52dSmrg
3882c2939121Smrg      compile)
3883c2939121Smrg      $ECHO \
3884c2939121Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3885c76ae52dSmrg
3886c2939121SmrgCompile a source file into a libtool library object.
3887c76ae52dSmrg
3888c2939121SmrgThis mode accepts the following additional options:
3889c76ae52dSmrg
3890c2939121Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3891c2939121Smrg  -no-suppress      do not suppress compiler output for multiple passes
3892c2939121Smrg  -prefer-pic       try to build PIC objects only
3893c2939121Smrg  -prefer-non-pic   try to build non-PIC objects only
38948292847cSmrg  -shared           do not build a '.o' file suitable for static linking
38958292847cSmrg  -static           only build a '.o' file suitable for static linking
389625420f97Smrg  -Wc,FLAG
389725420f97Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3898c76ae52dSmrg
38998292847cSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3900c2939121Smrgfrom the given SOURCEFILE.
3901c76ae52dSmrg
3902c2939121SmrgThe output file name is determined by removing the directory component from
39038292847cSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
39048292847cSmrglibrary object suffix, '.lo'."
3905c2939121Smrg        ;;
3906c76ae52dSmrg
3907c2939121Smrg      execute)
3908c2939121Smrg        $ECHO \
3909c2939121Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3910c76ae52dSmrg
3911c2939121SmrgAutomatically set library path, then run a program.
3912c76ae52dSmrg
3913c2939121SmrgThis mode accepts the following additional options:
3914c76ae52dSmrg
3915c2939121Smrg  -dlopen FILE      add the directory containing FILE to the library path
3916c76ae52dSmrg
39178292847cSmrgThis mode sets the library path environment variable according to '-dlopen'
3918c2939121Smrgflags.
3919c76ae52dSmrg
3920c2939121SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3921c2939121Smrginto their corresponding uninstalled binary, and any of their required library
3922c2939121Smrgdirectories are added to the library path.
3923c76ae52dSmrg
3924c2939121SmrgThen, COMMAND is executed, with ARGS as arguments."
3925c2939121Smrg        ;;
3926c76ae52dSmrg
3927c2939121Smrg      finish)
3928c2939121Smrg        $ECHO \
3929c2939121Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3930c76ae52dSmrg
3931c2939121SmrgComplete the installation of libtool libraries.
3932c76ae52dSmrg
3933c2939121SmrgEach LIBDIR is a directory that contains libtool libraries.
3934c76ae52dSmrg
3935c2939121SmrgThe commands that this mode executes may require superuser privileges.  Use
39368292847cSmrgthe '--dry-run' option if you just want to see what would be executed."
3937c2939121Smrg        ;;
3938c76ae52dSmrg
3939c2939121Smrg      install)
3940c2939121Smrg        $ECHO \
3941c2939121Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3942c76ae52dSmrg
3943c2939121SmrgInstall executables or libraries.
3944c76ae52dSmrg
3945c2939121SmrgINSTALL-COMMAND is the installation command.  The first component should be
39468292847cSmrgeither the 'install' or 'cp' program.
3947c76ae52dSmrg
3948c2939121SmrgThe following components of INSTALL-COMMAND are treated specially:
3949c76ae52dSmrg
3950c2939121Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3951c76ae52dSmrg
3952c2939121SmrgThe rest of the components are interpreted as arguments to that command (only
3953c2939121SmrgBSD-compatible install options are recognized)."
3954c2939121Smrg        ;;
3955c76ae52dSmrg
3956c2939121Smrg      link)
3957c2939121Smrg        $ECHO \
3958c2939121Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3959c76ae52dSmrg
3960c2939121SmrgLink object files or libraries together to form another library, or to
3961c2939121Smrgcreate an executable program.
3962c76ae52dSmrg
3963c2939121SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3964c2939121Smrga program from several object files.
3965c76ae52dSmrg
3966c2939121SmrgThe following components of LINK-COMMAND are treated specially:
3967c76ae52dSmrg
3968c2939121Smrg  -all-static       do not do any dynamic linking at all
3969c2939121Smrg  -avoid-version    do not add a version suffix if possible
3970c2939121Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
3971c2939121Smrg                    libraries must be found in the PATH setting at runtime)
39728292847cSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3973c2939121Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3974c2939121Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3975c2939121Smrg  -export-symbols SYMFILE
3976c2939121Smrg                    try to export only the symbols listed in SYMFILE
3977c2939121Smrg  -export-symbols-regex REGEX
3978c2939121Smrg                    try to export only the symbols matching REGEX
3979c2939121Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3980c2939121Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3981c2939121Smrg  -module           build a library that can dlopened
3982c2939121Smrg  -no-fast-install  disable the fast-install mode
3983c2939121Smrg  -no-install       link a not-installable executable
3984c2939121Smrg  -no-undefined     declare that a library does not refer to external symbols
3985c2939121Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
39868292847cSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
39878292847cSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3988c2939121Smrg  -precious-files-regex REGEX
3989c2939121Smrg                    don't remove output files matching REGEX
3990c2939121Smrg  -release RELEASE  specify package release information
3991c2939121Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3992c2939121Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3993c2939121Smrg  -shared           only do dynamic linking of libtool libraries
3994c2939121Smrg  -shrext SUFFIX    override the standard shared library file extension
3995c2939121Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
3996c2939121Smrg  -static-libtool-libs
3997c2939121Smrg                    do not do any dynamic linking of libtool libraries
3998c2939121Smrg  -version-info CURRENT[:REVISION[:AGE]]
3999c2939121Smrg                    specify library version info [each variable defaults to 0]
4000c2939121Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4001c2939121Smrg  -Wc,FLAG
4002c2939121Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
400325420f97Smrg  -Wa,FLAG
400425420f97Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4005c2939121Smrg  -Wl,FLAG
4006c2939121Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4007c2939121Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4008c76ae52dSmrg
40098292847cSmrgAll other options (arguments beginning with '-') are ignored.
4010c76ae52dSmrg
40118292847cSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4012c2939121Smrgtreated as uninstalled libtool libraries, other files are standard or library
4013c2939121Smrgobject files.
4014c76ae52dSmrg
40158292847cSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
40168292847cSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4017c2939121Smrgrequired, except when creating a convenience library.
4018c76ae52dSmrg
40198292847cSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
40208292847cSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40210d590c07Smrg
40228292847cSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4023c2939121Smrgis created, otherwise an executable program is created."
4024c2939121Smrg        ;;
4025c76ae52dSmrg
4026c2939121Smrg      uninstall)
4027c2939121Smrg        $ECHO \
4028c2939121Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4029c76ae52dSmrg
4030c2939121SmrgRemove libraries from an installation directory.
4031c76ae52dSmrg
4032c2939121SmrgRM is the name of the program to use to delete files associated with each FILE
40338292847cSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4034c2939121Smrgto RM.
4035c76ae52dSmrg
4036c2939121SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4037c2939121SmrgOtherwise, only FILE itself is deleted using RM."
4038c2939121Smrg        ;;
4039c76ae52dSmrg
4040c2939121Smrg      *)
40418292847cSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4042c2939121Smrg        ;;
4043c2939121Smrg    esac
4044c76ae52dSmrg
4045c2939121Smrg    echo
40468292847cSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4047c2939121Smrg}
4048c76ae52dSmrg
4049c2939121Smrg# Now that we've collected a possible --mode arg, show help if necessary
4050c2939121Smrgif $opt_help; then
40518292847cSmrg  if test : = "$opt_help"; then
4052c2939121Smrg    func_mode_help
4053c2939121Smrg  else
4054c2939121Smrg    {
4055c2939121Smrg      func_help noexit
40562836776bSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4057c2939121Smrg	func_mode_help
4058c2939121Smrg      done
40598292847cSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4060c2939121Smrg    {
4061c2939121Smrg      func_help noexit
40622836776bSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4063c2939121Smrg	echo
4064c2939121Smrg	func_mode_help
4065c2939121Smrg      done
4066c2939121Smrg    } |
40678292847cSmrg    $SED '1d
4068c2939121Smrg      /^When reporting/,/^Report/{
4069c2939121Smrg	H
4070c2939121Smrg	d
4071c2939121Smrg      }
4072c2939121Smrg      $x
4073c2939121Smrg      /information about other modes/d
4074c2939121Smrg      /more detailed .*MODE/d
4075c2939121Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4076c2939121Smrg  fi
4077c2939121Smrg  exit $?
4078c2939121Smrgfi
4079c76ae52dSmrg
4080c76ae52dSmrg
4081c2939121Smrg# func_mode_execute arg...
4082c2939121Smrgfunc_mode_execute ()
4083c2939121Smrg{
40848292847cSmrg    $debug_cmd
40858292847cSmrg
4086c2939121Smrg    # The first argument is the command name.
40878292847cSmrg    cmd=$nonopt
4088c2939121Smrg    test -z "$cmd" && \
4089c2939121Smrg      func_fatal_help "you must specify a COMMAND"
4090c76ae52dSmrg
4091c2939121Smrg    # Handle -dlopen flags immediately.
40922836776bSmrg    for file in $opt_dlopen; do
4093c2939121Smrg      test -f "$file" \
40948292847cSmrg	|| func_fatal_help "'$file' is not a file"
4095c76ae52dSmrg
4096c2939121Smrg      dir=
4097c2939121Smrg      case $file in
4098c2939121Smrg      *.la)
40992836776bSmrg	func_resolve_sysroot "$file"
41002836776bSmrg	file=$func_resolve_sysroot_result
41012836776bSmrg
4102c2939121Smrg	# Check to see that this really is a libtool archive.
4103c2939121Smrg	func_lalib_unsafe_p "$file" \
41048292847cSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4105c76ae52dSmrg
4106c2939121Smrg	# Read the libtool library.
4107c2939121Smrg	dlname=
4108c2939121Smrg	library_names=
4109c2939121Smrg	func_source "$file"
4110c76ae52dSmrg
4111c2939121Smrg	# Skip this library if it cannot be dlopened.
4112c2939121Smrg	if test -z "$dlname"; then
4113c2939121Smrg	  # Warn if it was a shared library.
4114c2939121Smrg	  test -n "$library_names" && \
41158292847cSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4116c2939121Smrg	  continue
4117c2939121Smrg	fi
4118c76ae52dSmrg
4119c2939121Smrg	func_dirname "$file" "" "."
41208292847cSmrg	dir=$func_dirname_result
4121c76ae52dSmrg
4122c2939121Smrg	if test -f "$dir/$objdir/$dlname"; then
41232836776bSmrg	  func_append dir "/$objdir"
4124c2939121Smrg	else
4125c2939121Smrg	  if test ! -f "$dir/$dlname"; then
41268292847cSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4127c2939121Smrg	  fi
4128c2939121Smrg	fi
4129c76ae52dSmrg	;;
4130c76ae52dSmrg
4131c2939121Smrg      *.lo)
4132c2939121Smrg	# Just add the directory containing the .lo file.
4133c2939121Smrg	func_dirname "$file" "" "."
41348292847cSmrg	dir=$func_dirname_result
4135c76ae52dSmrg	;;
4136c2939121Smrg
4137c2939121Smrg      *)
41388292847cSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4139c76ae52dSmrg	continue
4140c76ae52dSmrg	;;
4141c2939121Smrg      esac
4142c76ae52dSmrg
4143c2939121Smrg      # Get the absolute pathname.
4144c2939121Smrg      absdir=`cd "$dir" && pwd`
41458292847cSmrg      test -n "$absdir" && dir=$absdir
4146c76ae52dSmrg
4147c2939121Smrg      # Now add the directory to shlibpath_var.
4148c2939121Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4149c2939121Smrg	eval "$shlibpath_var=\"\$dir\""
4150c2939121Smrg      else
4151c2939121Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4152c2939121Smrg      fi
4153c2939121Smrg    done
4154c76ae52dSmrg
4155c2939121Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4156c2939121Smrg    # rather than running their programs.
41578292847cSmrg    libtool_execute_magic=$magic
4158c76ae52dSmrg
4159c2939121Smrg    # Check if any of the arguments is a wrapper script.
4160c2939121Smrg    args=
4161c2939121Smrg    for file
4162c2939121Smrg    do
4163c2939121Smrg      case $file in
4164c2939121Smrg      -* | *.la | *.lo ) ;;
4165c2939121Smrg      *)
4166c2939121Smrg	# Do a test to see if this is really a libtool program.
4167c2939121Smrg	if func_ltwrapper_script_p "$file"; then
4168c2939121Smrg	  func_source "$file"
4169c2939121Smrg	  # Transform arg to wrapped name.
41708292847cSmrg	  file=$progdir/$program
4171c2939121Smrg	elif func_ltwrapper_executable_p "$file"; then
4172c2939121Smrg	  func_ltwrapper_scriptname "$file"
4173c2939121Smrg	  func_source "$func_ltwrapper_scriptname_result"
4174c2939121Smrg	  # Transform arg to wrapped name.
41758292847cSmrg	  file=$progdir/$program
4176c2939121Smrg	fi
4177c76ae52dSmrg	;;
4178c2939121Smrg      esac
4179c2939121Smrg      # Quote arguments (to preserve shell metacharacters).
41802836776bSmrg      func_append_quoted args "$file"
4181c2939121Smrg    done
4182c76ae52dSmrg
41838292847cSmrg    if $opt_dry_run; then
41848292847cSmrg      # Display what would be done.
41858292847cSmrg      if test -n "$shlibpath_var"; then
41868292847cSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
41878292847cSmrg	echo "export $shlibpath_var"
41888292847cSmrg      fi
41898292847cSmrg      $ECHO "$cmd$args"
41908292847cSmrg      exit $EXIT_SUCCESS
41918292847cSmrg    else
4192c2939121Smrg      if test -n "$shlibpath_var"; then
4193c2939121Smrg	# Export the shlibpath_var.
4194c2939121Smrg	eval "export $shlibpath_var"
4195c2939121Smrg      fi
4196c76ae52dSmrg
4197c2939121Smrg      # Restore saved environment variables
4198c2939121Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4199c2939121Smrg      do
4200c2939121Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4201c2939121Smrg                $lt_var=\$save_$lt_var; export $lt_var
4202c2939121Smrg	      else
4203c2939121Smrg		$lt_unset $lt_var
4204c2939121Smrg	      fi"
4205c2939121Smrg      done
4206c76ae52dSmrg
4207c2939121Smrg      # Now prepare to actually exec the command.
42088292847cSmrg      exec_cmd=\$cmd$args
4209c2939121Smrg    fi
4210c2939121Smrg}
4211c76ae52dSmrg
42128292847cSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4213c76ae52dSmrg
4214c76ae52dSmrg
4215c2939121Smrg# func_mode_finish arg...
4216c2939121Smrgfunc_mode_finish ()
4217c2939121Smrg{
42188292847cSmrg    $debug_cmd
42198292847cSmrg
42202836776bSmrg    libs=
42212836776bSmrg    libdirs=
4222c2939121Smrg    admincmds=
4223c76ae52dSmrg
42242836776bSmrg    for opt in "$nonopt" ${1+"$@"}
42252836776bSmrg    do
42262836776bSmrg      if test -d "$opt"; then
42272836776bSmrg	func_append libdirs " $opt"
42282836776bSmrg
42292836776bSmrg      elif test -f "$opt"; then
42302836776bSmrg	if func_lalib_unsafe_p "$opt"; then
42312836776bSmrg	  func_append libs " $opt"
42322836776bSmrg	else
42338292847cSmrg	  func_warning "'$opt' is not a valid libtool archive"
42342836776bSmrg	fi
42352836776bSmrg
42362836776bSmrg      else
42378292847cSmrg	func_fatal_error "invalid argument '$opt'"
42382836776bSmrg      fi
42392836776bSmrg    done
42402836776bSmrg
42412836776bSmrg    if test -n "$libs"; then
42422836776bSmrg      if test -n "$lt_sysroot"; then
42432836776bSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
42442836776bSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
42452836776bSmrg      else
42462836776bSmrg        sysroot_cmd=
42472836776bSmrg      fi
42482836776bSmrg
42492836776bSmrg      # Remove sysroot references
42502836776bSmrg      if $opt_dry_run; then
42512836776bSmrg        for lib in $libs; do
42528292847cSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
42532836776bSmrg        done
42542836776bSmrg      else
42552836776bSmrg        tmpdir=`func_mktempdir`
42562836776bSmrg        for lib in $libs; do
42578292847cSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
42582836776bSmrg	    > $tmpdir/tmp-la
42592836776bSmrg	  mv -f $tmpdir/tmp-la $lib
42602836776bSmrg	done
42612836776bSmrg        ${RM}r "$tmpdir"
42622836776bSmrg      fi
42632836776bSmrg    fi
4264c76ae52dSmrg
42652836776bSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4266c2939121Smrg      for libdir in $libdirs; do
4267c2939121Smrg	if test -n "$finish_cmds"; then
4268c2939121Smrg	  # Do each command in the finish commands.
4269c2939121Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4270c2939121Smrg'"$cmd"'"'
4271c2939121Smrg	fi
4272c2939121Smrg	if test -n "$finish_eval"; then
4273c2939121Smrg	  # Do the single finish_eval.
4274c2939121Smrg	  eval cmds=\"$finish_eval\"
42752836776bSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4276c2939121Smrg       $cmds"
4277c2939121Smrg	fi
4278c2939121Smrg      done
4279c2939121Smrg    fi
4280c76ae52dSmrg
4281c2939121Smrg    # Exit here if they wanted silent mode.
42828292847cSmrg    $opt_quiet && exit $EXIT_SUCCESS
4283c76ae52dSmrg
42842836776bSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42852836776bSmrg      echo "----------------------------------------------------------------------"
42862836776bSmrg      echo "Libraries have been installed in:"
42872836776bSmrg      for libdir in $libdirs; do
42882836776bSmrg	$ECHO "   $libdir"
42892836776bSmrg      done
42902836776bSmrg      echo
42912836776bSmrg      echo "If you ever happen to want to link against installed libraries"
42922836776bSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
42938292847cSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
42942836776bSmrg      echo "flag during linking and do at least one of the following:"
42952836776bSmrg      if test -n "$shlibpath_var"; then
42968292847cSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
42972836776bSmrg	echo "     during execution"
42982836776bSmrg      fi
42992836776bSmrg      if test -n "$runpath_var"; then
43008292847cSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
43012836776bSmrg	echo "     during linking"
43022836776bSmrg      fi
43032836776bSmrg      if test -n "$hardcode_libdir_flag_spec"; then
43042836776bSmrg	libdir=LIBDIR
43052836776bSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4306c76ae52dSmrg
43078292847cSmrg	$ECHO "   - use the '$flag' linker flag"
43082836776bSmrg      fi
43092836776bSmrg      if test -n "$admincmds"; then
43102836776bSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
43112836776bSmrg      fi
43122836776bSmrg      if test -f /etc/ld.so.conf; then
43138292847cSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
43142836776bSmrg      fi
43152836776bSmrg      echo
4316c76ae52dSmrg
43172836776bSmrg      echo "See any operating system documentation about shared libraries for"
43182836776bSmrg      case $host in
43192836776bSmrg	solaris2.[6789]|solaris2.1[0-9])
43202836776bSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
43212836776bSmrg	  echo "pages."
43222836776bSmrg	  ;;
43232836776bSmrg	*)
43242836776bSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
43252836776bSmrg	  ;;
43262836776bSmrg      esac
43272836776bSmrg      echo "----------------------------------------------------------------------"
43282836776bSmrg    fi
4329c2939121Smrg    exit $EXIT_SUCCESS
4330c2939121Smrg}
4331c76ae52dSmrg
43328292847cSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4333c76ae52dSmrg
4334c76ae52dSmrg
4335c2939121Smrg# func_mode_install arg...
4336c2939121Smrgfunc_mode_install ()
4337c2939121Smrg{
43388292847cSmrg    $debug_cmd
43398292847cSmrg
4340c2939121Smrg    # There may be an optional sh(1) argument at the beginning of
4341c2939121Smrg    # install_prog (especially on Windows NT).
43428292847cSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4343c2939121Smrg       # Allow the use of GNU shtool's install command.
43448292847cSmrg       case $nonopt in *shtool*) :;; *) false;; esac
43458292847cSmrg    then
4346c2939121Smrg      # Aesthetically quote it.
434725420f97Smrg      func_quote_arg pretty "$nonopt"
434825420f97Smrg      install_prog="$func_quote_arg_result "
4349c2939121Smrg      arg=$1
4350c2939121Smrg      shift
4351c2939121Smrg    else
4352c2939121Smrg      install_prog=
4353c2939121Smrg      arg=$nonopt
4354c2939121Smrg    fi
4355c76ae52dSmrg
4356c2939121Smrg    # The real first argument should be the name of the installation program.
4357c2939121Smrg    # Aesthetically quote it.
435825420f97Smrg    func_quote_arg pretty "$arg"
435925420f97Smrg    func_append install_prog "$func_quote_arg_result"
4360c2939121Smrg    install_shared_prog=$install_prog
4361c2939121Smrg    case " $install_prog " in
4362c2939121Smrg      *[\\\ /]cp\ *) install_cp=: ;;
4363c2939121Smrg      *) install_cp=false ;;
4364c2939121Smrg    esac
4365c76ae52dSmrg
4366c2939121Smrg    # We need to accept at least all the BSD install flags.
4367c2939121Smrg    dest=
4368c2939121Smrg    files=
4369c2939121Smrg    opts=
4370c2939121Smrg    prev=
4371c2939121Smrg    install_type=
43728292847cSmrg    isdir=false
4373c2939121Smrg    stripme=
4374c2939121Smrg    no_mode=:
4375c2939121Smrg    for arg
4376c2939121Smrg    do
4377c2939121Smrg      arg2=
4378c2939121Smrg      if test -n "$dest"; then
43792836776bSmrg	func_append files " $dest"
4380c2939121Smrg	dest=$arg
4381c76ae52dSmrg	continue
4382c2939121Smrg      fi
4383c76ae52dSmrg
4384c2939121Smrg      case $arg in
43858292847cSmrg      -d) isdir=: ;;
4386c2939121Smrg      -f)
4387c2939121Smrg	if $install_cp; then :; else
4388c2939121Smrg	  prev=$arg
4389c76ae52dSmrg	fi
4390c2939121Smrg	;;
4391c2939121Smrg      -g | -m | -o)
4392c2939121Smrg	prev=$arg
4393c2939121Smrg	;;
4394c2939121Smrg      -s)
4395c2939121Smrg	stripme=" -s"
4396c76ae52dSmrg	continue
4397c76ae52dSmrg	;;
4398c2939121Smrg      -*)
4399c2939121Smrg	;;
4400c76ae52dSmrg      *)
4401c2939121Smrg	# If the previous option needed an argument, then skip it.
4402c2939121Smrg	if test -n "$prev"; then
44038292847cSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4404c2939121Smrg	    arg2=$install_override_mode
4405c2939121Smrg	    no_mode=false
4406c2939121Smrg	  fi
4407c2939121Smrg	  prev=
4408c2939121Smrg	else
4409c2939121Smrg	  dest=$arg
4410c2939121Smrg	  continue
4411c2939121Smrg	fi
4412c76ae52dSmrg	;;
4413c2939121Smrg      esac
4414c76ae52dSmrg
4415c2939121Smrg      # Aesthetically quote the argument.
441625420f97Smrg      func_quote_arg pretty "$arg"
441725420f97Smrg      func_append install_prog " $func_quote_arg_result"
4418c2939121Smrg      if test -n "$arg2"; then
441925420f97Smrg	func_quote_arg pretty "$arg2"
4420c76ae52dSmrg      fi
442125420f97Smrg      func_append install_shared_prog " $func_quote_arg_result"
4422c2939121Smrg    done
4423c76ae52dSmrg
4424c2939121Smrg    test -z "$install_prog" && \
4425c2939121Smrg      func_fatal_help "you must specify an install program"
4426c76ae52dSmrg
4427c2939121Smrg    test -n "$prev" && \
44288292847cSmrg      func_fatal_help "the '$prev' option requires an argument"
4429c76ae52dSmrg
4430c2939121Smrg    if test -n "$install_override_mode" && $no_mode; then
4431c2939121Smrg      if $install_cp; then :; else
443225420f97Smrg	func_quote_arg pretty "$install_override_mode"
443325420f97Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4434c2939121Smrg      fi
4435c76ae52dSmrg    fi
4436c76ae52dSmrg
4437c2939121Smrg    if test -z "$files"; then
4438c2939121Smrg      if test -z "$dest"; then
4439c2939121Smrg	func_fatal_help "no file or destination specified"
4440c2939121Smrg      else
4441c2939121Smrg	func_fatal_help "you must specify a destination"
4442c76ae52dSmrg      fi
4443c76ae52dSmrg    fi
4444c76ae52dSmrg
4445c2939121Smrg    # Strip any trailing slash from the destination.
4446c2939121Smrg    func_stripname '' '/' "$dest"
4447c2939121Smrg    dest=$func_stripname_result
4448c76ae52dSmrg
4449c2939121Smrg    # Check to see that the destination is a directory.
44508292847cSmrg    test -d "$dest" && isdir=:
44518292847cSmrg    if $isdir; then
44528292847cSmrg      destdir=$dest
4453c2939121Smrg      destname=
4454c2939121Smrg    else
4455c2939121Smrg      func_dirname_and_basename "$dest" "" "."
44568292847cSmrg      destdir=$func_dirname_result
44578292847cSmrg      destname=$func_basename_result
4458c2939121Smrg
4459c2939121Smrg      # Not a directory, so check to see that there is only one file specified.
4460c2939121Smrg      set dummy $files; shift
4461c2939121Smrg      test "$#" -gt 1 && \
44628292847cSmrg	func_fatal_help "'$dest' is not a directory"
4463c2939121Smrg    fi
4464c2939121Smrg    case $destdir in
4465c2939121Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4466c76ae52dSmrg    *)
4467c2939121Smrg      for file in $files; do
4468c2939121Smrg	case $file in
4469c2939121Smrg	*.lo) ;;
4470c2939121Smrg	*)
44718292847cSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4472c2939121Smrg	  ;;
4473c2939121Smrg	esac
4474c2939121Smrg      done
4475c76ae52dSmrg      ;;
4476c76ae52dSmrg    esac
4477c76ae52dSmrg
4478c2939121Smrg    # This variable tells wrapper scripts just to set variables rather
4479c2939121Smrg    # than running their programs.
44808292847cSmrg    libtool_install_magic=$magic
4481c76ae52dSmrg
4482c2939121Smrg    staticlibs=
4483c2939121Smrg    future_libdirs=
4484c2939121Smrg    current_libdirs=
4485c2939121Smrg    for file in $files; do
4486c76ae52dSmrg
4487c2939121Smrg      # Do each installation.
4488c2939121Smrg      case $file in
4489c2939121Smrg      *.$libext)
4490c2939121Smrg	# Do the static libraries later.
44912836776bSmrg	func_append staticlibs " $file"
4492c2939121Smrg	;;
4493c2939121Smrg
4494c2939121Smrg      *.la)
44952836776bSmrg	func_resolve_sysroot "$file"
44962836776bSmrg	file=$func_resolve_sysroot_result
44972836776bSmrg
4498c2939121Smrg	# Check to see that this really is a libtool archive.
4499c2939121Smrg	func_lalib_unsafe_p "$file" \
45008292847cSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4501c2939121Smrg
4502c2939121Smrg	library_names=
4503c2939121Smrg	old_library=
4504c2939121Smrg	relink_command=
4505c2939121Smrg	func_source "$file"
4506c2939121Smrg
4507c2939121Smrg	# Add the libdir to current_libdirs if it is the destination.
4508c2939121Smrg	if test "X$destdir" = "X$libdir"; then
4509c2939121Smrg	  case "$current_libdirs " in
4510c2939121Smrg	  *" $libdir "*) ;;
45112836776bSmrg	  *) func_append current_libdirs " $libdir" ;;
4512c76ae52dSmrg	  esac
4513c2939121Smrg	else
4514c2939121Smrg	  # Note the libdir as a future libdir.
4515c2939121Smrg	  case "$future_libdirs " in
4516c2939121Smrg	  *" $libdir "*) ;;
45172836776bSmrg	  *) func_append future_libdirs " $libdir" ;;
4518c2939121Smrg	  esac
4519c2939121Smrg	fi
4520c76ae52dSmrg
4521c2939121Smrg	func_dirname "$file" "/" ""
45228292847cSmrg	dir=$func_dirname_result
45232836776bSmrg	func_append dir "$objdir"
4524c2939121Smrg
4525c2939121Smrg	if test -n "$relink_command"; then
4526c2939121Smrg	  # Determine the prefix the user has applied to our future dir.
4527c2939121Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4528c2939121Smrg
4529c2939121Smrg	  # Don't allow the user to place us outside of our expected
4530c2939121Smrg	  # location b/c this prevents finding dependent libraries that
4531c2939121Smrg	  # are installed to the same prefix.
4532c2939121Smrg	  # At present, this check doesn't affect windows .dll's that
4533c2939121Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4534c2939121Smrg	  # but it's something to keep an eye on.
4535c2939121Smrg	  test "$inst_prefix_dir" = "$destdir" && \
45368292847cSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4537c2939121Smrg
4538c2939121Smrg	  if test -n "$inst_prefix_dir"; then
4539c2939121Smrg	    # Stick the inst_prefix_dir data into the link command.
4540c2939121Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4541c2939121Smrg	  else
4542c2939121Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4543c2939121Smrg	  fi
4544c2939121Smrg
45458292847cSmrg	  func_warning "relinking '$file'"
4546c2939121Smrg	  func_show_eval "$relink_command" \
45478292847cSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4548c2939121Smrg	fi
4549c2939121Smrg
4550c2939121Smrg	# See the names of the shared library.
4551c2939121Smrg	set dummy $library_names; shift
4552c2939121Smrg	if test -n "$1"; then
45538292847cSmrg	  realname=$1
4554c2939121Smrg	  shift
4555c2939121Smrg
45568292847cSmrg	  srcname=$realname
45578292847cSmrg	  test -n "$relink_command" && srcname=${realname}T
4558c2939121Smrg
4559c2939121Smrg	  # Install the shared library and build the symlinks.
4560c2939121Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4561c2939121Smrg	      'exit $?'
45628292847cSmrg	  tstripme=$stripme
4563c2939121Smrg	  case $host_os in
4564c2939121Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4565c2939121Smrg	    case $realname in
4566c2939121Smrg	    *.dll.a)
45678292847cSmrg	      tstripme=
45688292847cSmrg	      ;;
45698292847cSmrg	    esac
45708292847cSmrg	    ;;
45718292847cSmrg	  os2*)
45728292847cSmrg	    case $realname in
45738292847cSmrg	    *_dll.a)
45748292847cSmrg	      tstripme=
4575c2939121Smrg	      ;;
4576c2939121Smrg	    esac
4577c76ae52dSmrg	    ;;
4578c76ae52dSmrg	  esac
4579c2939121Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4580c2939121Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4581c2939121Smrg	  fi
4582c2939121Smrg
4583c2939121Smrg	  if test "$#" -gt 0; then
4584c2939121Smrg	    # Delete the old symlinks, and create new ones.
45858292847cSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4586c2939121Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4587c2939121Smrg	    # so we also need to try rm && ln -s.
4588c2939121Smrg	    for linkname
4589c2939121Smrg	    do
4590c2939121Smrg	      test "$linkname" != "$realname" \
4591c2939121Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4592c2939121Smrg	    done
4593c2939121Smrg	  fi
4594c2939121Smrg
4595c2939121Smrg	  # Do each command in the postinstall commands.
45968292847cSmrg	  lib=$destdir/$realname
4597c2939121Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4598c2939121Smrg	fi
4599c2939121Smrg
4600c2939121Smrg	# Install the pseudo-library for information purposes.
4601c2939121Smrg	func_basename "$file"
46028292847cSmrg	name=$func_basename_result
46038292847cSmrg	instname=$dir/${name}i
4604c2939121Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4605c2939121Smrg
4606c2939121Smrg	# Maybe install the static library, too.
46072836776bSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4608c76ae52dSmrg	;;
4609c2939121Smrg
4610c2939121Smrg      *.lo)
4611c2939121Smrg	# Install (i.e. copy) a libtool object.
4612c2939121Smrg
4613c2939121Smrg	# Figure out destination file name, if it wasn't already specified.
4614c2939121Smrg	if test -n "$destname"; then
46158292847cSmrg	  destfile=$destdir/$destname
4616c2939121Smrg	else
4617c2939121Smrg	  func_basename "$file"
46188292847cSmrg	  destfile=$func_basename_result
46198292847cSmrg	  destfile=$destdir/$destfile
4620c2939121Smrg	fi
4621c2939121Smrg
4622c2939121Smrg	# Deduce the name of the destination old-style object file.
4623c2939121Smrg	case $destfile in
4624c2939121Smrg	*.lo)
4625c2939121Smrg	  func_lo2o "$destfile"
4626c2939121Smrg	  staticdest=$func_lo2o_result
4627c76ae52dSmrg	  ;;
4628c2939121Smrg	*.$objext)
46298292847cSmrg	  staticdest=$destfile
4630c2939121Smrg	  destfile=
4631c76ae52dSmrg	  ;;
4632c2939121Smrg	*)
46338292847cSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4634c76ae52dSmrg	  ;;
4635c2939121Smrg	esac
4636c2939121Smrg
4637c2939121Smrg	# Install the libtool object if requested.
4638c2939121Smrg	test -n "$destfile" && \
4639c2939121Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4640c2939121Smrg
4641c2939121Smrg	# Install the old object if enabled.
46428292847cSmrg	if test yes = "$build_old_libs"; then
4643c2939121Smrg	  # Deduce the name of the old-style object file.
4644c2939121Smrg	  func_lo2o "$file"
4645c2939121Smrg	  staticobj=$func_lo2o_result
4646c2939121Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4647c76ae52dSmrg	fi
4648c2939121Smrg	exit $EXIT_SUCCESS
4649c2939121Smrg	;;
4650c76ae52dSmrg
4651c2939121Smrg      *)
4652c2939121Smrg	# Figure out destination file name, if it wasn't already specified.
4653c2939121Smrg	if test -n "$destname"; then
46548292847cSmrg	  destfile=$destdir/$destname
4655c76ae52dSmrg	else
4656c2939121Smrg	  func_basename "$file"
46578292847cSmrg	  destfile=$func_basename_result
46588292847cSmrg	  destfile=$destdir/$destfile
4659c76ae52dSmrg	fi
4660c76ae52dSmrg
4661c2939121Smrg	# If the file is missing, and there is a .exe on the end, strip it
4662c2939121Smrg	# because it is most likely a libtool script we actually want to
4663c2939121Smrg	# install
46648292847cSmrg	stripped_ext=
4665c2939121Smrg	case $file in
4666c2939121Smrg	  *.exe)
4667c2939121Smrg	    if test ! -f "$file"; then
4668c2939121Smrg	      func_stripname '' '.exe' "$file"
4669c2939121Smrg	      file=$func_stripname_result
46708292847cSmrg	      stripped_ext=.exe
4671c2939121Smrg	    fi
4672c2939121Smrg	    ;;
4673c2939121Smrg	esac
4674c76ae52dSmrg
4675c2939121Smrg	# Do a test to see if this is really a libtool program.
4676c2939121Smrg	case $host in
4677c2939121Smrg	*cygwin* | *mingw*)
4678c2939121Smrg	    if func_ltwrapper_executable_p "$file"; then
4679c2939121Smrg	      func_ltwrapper_scriptname "$file"
4680c2939121Smrg	      wrapper=$func_ltwrapper_scriptname_result
4681c2939121Smrg	    else
4682c2939121Smrg	      func_stripname '' '.exe' "$file"
4683c2939121Smrg	      wrapper=$func_stripname_result
4684c2939121Smrg	    fi
4685c2939121Smrg	    ;;
4686c2939121Smrg	*)
4687c2939121Smrg	    wrapper=$file
4688c2939121Smrg	    ;;
4689c2939121Smrg	esac
4690c2939121Smrg	if func_ltwrapper_script_p "$wrapper"; then
4691c2939121Smrg	  notinst_deplibs=
4692c2939121Smrg	  relink_command=
4693c76ae52dSmrg
4694c2939121Smrg	  func_source "$wrapper"
4695c76ae52dSmrg
4696c2939121Smrg	  # Check the variables that should have been set.
4697c2939121Smrg	  test -z "$generated_by_libtool_version" && \
46988292847cSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4699c76ae52dSmrg
47008292847cSmrg	  finalize=:
4701c2939121Smrg	  for lib in $notinst_deplibs; do
4702c2939121Smrg	    # Check to see that each library is installed.
4703c2939121Smrg	    libdir=
4704c2939121Smrg	    if test -f "$lib"; then
4705c2939121Smrg	      func_source "$lib"
4706c76ae52dSmrg	    fi
47078292847cSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4708c2939121Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
47098292847cSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
47108292847cSmrg	      finalize=false
4711c2939121Smrg	    fi
4712c2939121Smrg	  done
4713c76ae52dSmrg
4714c2939121Smrg	  relink_command=
4715c2939121Smrg	  func_source "$wrapper"
4716c76ae52dSmrg
4717c2939121Smrg	  outputname=
47188292847cSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4719c2939121Smrg	    $opt_dry_run || {
47208292847cSmrg	      if $finalize; then
4721c2939121Smrg	        tmpdir=`func_mktempdir`
4722c2939121Smrg		func_basename "$file$stripped_ext"
47238292847cSmrg		file=$func_basename_result
47248292847cSmrg	        outputname=$tmpdir/$file
4725c2939121Smrg	        # Replace the output file specification.
4726c2939121Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4727c2939121Smrg
47288292847cSmrg	        $opt_quiet || {
472925420f97Smrg	          func_quote_arg expand,pretty "$relink_command"
473025420f97Smrg		  eval "func_echo $func_quote_arg_result"
4731c2939121Smrg	        }
4732c2939121Smrg	        if eval "$relink_command"; then :
4733c2939121Smrg	          else
47348292847cSmrg		  func_error "error: relink '$file' with the above command before installing it"
4735c2939121Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4736c2939121Smrg		  continue
4737c2939121Smrg	        fi
47388292847cSmrg	        file=$outputname
4739c2939121Smrg	      else
47408292847cSmrg	        func_warning "cannot relink '$file'"
4741c2939121Smrg	      fi
4742c2939121Smrg	    }
4743c76ae52dSmrg	  else
4744c2939121Smrg	    # Install the binary that we compiled earlier.
4745c2939121Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4746c76ae52dSmrg	  fi
4747c2939121Smrg	fi
4748c76ae52dSmrg
4749c2939121Smrg	# remove .exe since cygwin /usr/bin/install will append another
4750c2939121Smrg	# one anyway
4751c2939121Smrg	case $install_prog,$host in
4752c2939121Smrg	*/usr/bin/install*,*cygwin*)
4753c2939121Smrg	  case $file:$destfile in
4754c2939121Smrg	  *.exe:*.exe)
4755c2939121Smrg	    # this is ok
4756c2939121Smrg	    ;;
4757c2939121Smrg	  *.exe:*)
4758c2939121Smrg	    destfile=$destfile.exe
4759c2939121Smrg	    ;;
4760c2939121Smrg	  *:*.exe)
4761c2939121Smrg	    func_stripname '' '.exe' "$destfile"
4762c2939121Smrg	    destfile=$func_stripname_result
4763c2939121Smrg	    ;;
4764c2939121Smrg	  esac
4765c76ae52dSmrg	  ;;
4766c76ae52dSmrg	esac
4767c2939121Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4768c2939121Smrg	$opt_dry_run || if test -n "$outputname"; then
4769c2939121Smrg	  ${RM}r "$tmpdir"
4770c2939121Smrg	fi
4771c2939121Smrg	;;
4772c2939121Smrg      esac
4773c2939121Smrg    done
4774c76ae52dSmrg
4775c2939121Smrg    for file in $staticlibs; do
4776c2939121Smrg      func_basename "$file"
47778292847cSmrg      name=$func_basename_result
4778c2939121Smrg
4779c2939121Smrg      # Set up the ranlib parameters.
47808292847cSmrg      oldlib=$destdir/$name
47812836776bSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
47822836776bSmrg      tool_oldlib=$func_to_tool_file_result
4783c2939121Smrg
4784c2939121Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4785c2939121Smrg
4786c2939121Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
47872836776bSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4788c2939121Smrg      fi
4789c2939121Smrg
4790c2939121Smrg      # Do each command in the postinstall commands.
4791c2939121Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4792c2939121Smrg    done
4793c2939121Smrg
4794c2939121Smrg    test -n "$future_libdirs" && \
47958292847cSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4796c2939121Smrg
4797c2939121Smrg    if test -n "$current_libdirs"; then
4798c2939121Smrg      # Maybe just do a dry run.
4799c2939121Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
48008292847cSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4801c2939121Smrg    else
4802c2939121Smrg      exit $EXIT_SUCCESS
4803c2939121Smrg    fi
4804c2939121Smrg}
4805c2939121Smrg
48068292847cSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4807c2939121Smrg
4808c2939121Smrg
4809c2939121Smrg# func_generate_dlsyms outputname originator pic_p
4810c2939121Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4811c2939121Smrg# a dlpreopen symbol table.
4812c2939121Smrgfunc_generate_dlsyms ()
4813c2939121Smrg{
48148292847cSmrg    $debug_cmd
48158292847cSmrg
48168292847cSmrg    my_outputname=$1
48178292847cSmrg    my_originator=$2
48188292847cSmrg    my_pic_p=${3-false}
48198292847cSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4820c2939121Smrg    my_dlsyms=
4821c2939121Smrg
48228292847cSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4823c2939121Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
48248292847cSmrg	my_dlsyms=${my_outputname}S.c
4825c2939121Smrg      else
4826c2939121Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4827c2939121Smrg      fi
4828c2939121Smrg    fi
4829c2939121Smrg
4830c2939121Smrg    if test -n "$my_dlsyms"; then
4831c2939121Smrg      case $my_dlsyms in
4832c2939121Smrg      "") ;;
4833c2939121Smrg      *.c)
4834c2939121Smrg	# Discover the nlist of each of the dlfiles.
48358292847cSmrg	nlist=$output_objdir/$my_outputname.nm
4836c2939121Smrg
4837c2939121Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4838c2939121Smrg
4839c2939121Smrg	# Parse the name list into a source file.
4840c2939121Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4841c2939121Smrg
4842c2939121Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
48438292847cSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
48448292847cSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4845c2939121Smrg
4846c2939121Smrg#ifdef __cplusplus
4847c2939121Smrgextern \"C\" {
4848c2939121Smrg#endif
4849c2939121Smrg
48508292847cSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4851c2939121Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4852c2939121Smrg#endif
4853c2939121Smrg
48542836776bSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
48558292847cSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
48568292847cSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
48572836776bSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
48582836776bSmrg# define LT_DLSYM_CONST
48598292847cSmrg#elif defined __osf__
48602836776bSmrg/* This system does not cope well with relocations in const data.  */
48612836776bSmrg# define LT_DLSYM_CONST
48622836776bSmrg#else
48632836776bSmrg# define LT_DLSYM_CONST const
48642836776bSmrg#endif
48652836776bSmrg
48668292847cSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
48678292847cSmrg
4868c2939121Smrg/* External symbol declarations for the compiler. */\
4869c2939121Smrg"
4870c2939121Smrg
48718292847cSmrg	if test yes = "$dlself"; then
48728292847cSmrg	  func_verbose "generating symbol list for '$output'"
4873c2939121Smrg
4874c2939121Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4875c2939121Smrg
4876c2939121Smrg	  # Add our own program objects to the symbol list.
4877c2939121Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4878c2939121Smrg	  for progfile in $progfiles; do
48792836776bSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
48808292847cSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
48812836776bSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4882c2939121Smrg	  done
4883c2939121Smrg
4884c2939121Smrg	  if test -n "$exclude_expsyms"; then
4885c2939121Smrg	    $opt_dry_run || {
4886c2939121Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4887c2939121Smrg	      eval '$MV "$nlist"T "$nlist"'
4888c2939121Smrg	    }
4889c76ae52dSmrg	  fi
4890c2939121Smrg
4891c2939121Smrg	  if test -n "$export_symbols_regex"; then
4892c2939121Smrg	    $opt_dry_run || {
4893c2939121Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4894c2939121Smrg	      eval '$MV "$nlist"T "$nlist"'
4895c2939121Smrg	    }
4896c2939121Smrg	  fi
4897c2939121Smrg
4898c2939121Smrg	  # Prepare the list of exported symbols
4899c2939121Smrg	  if test -z "$export_symbols"; then
49008292847cSmrg	    export_symbols=$output_objdir/$outputname.exp
4901c2939121Smrg	    $opt_dry_run || {
4902c2939121Smrg	      $RM $export_symbols
49038292847cSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4904c2939121Smrg	      case $host in
4905c2939121Smrg	      *cygwin* | *mingw* | *cegcc* )
4906c2939121Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4907c2939121Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4908c2939121Smrg	        ;;
4909c2939121Smrg	      esac
4910c2939121Smrg	    }
4911c76ae52dSmrg	  else
4912c2939121Smrg	    $opt_dry_run || {
49138292847cSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4914c2939121Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4915c2939121Smrg	      eval '$MV "$nlist"T "$nlist"'
4916c2939121Smrg	      case $host in
4917c2939121Smrg	        *cygwin* | *mingw* | *cegcc* )
4918c2939121Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4919c2939121Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4920c2939121Smrg	          ;;
4921c2939121Smrg	      esac
4922c2939121Smrg	    }
4923c76ae52dSmrg	  fi
4924c2939121Smrg	fi
4925c76ae52dSmrg
4926c2939121Smrg	for dlprefile in $dlprefiles; do
49278292847cSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4928c2939121Smrg	  func_basename "$dlprefile"
49298292847cSmrg	  name=$func_basename_result
49302836776bSmrg          case $host in
49312836776bSmrg	    *cygwin* | *mingw* | *cegcc* )
49322836776bSmrg	      # if an import library, we need to obtain dlname
49332836776bSmrg	      if func_win32_import_lib_p "$dlprefile"; then
49342836776bSmrg	        func_tr_sh "$dlprefile"
49352836776bSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
49368292847cSmrg	        dlprefile_dlbasename=
49372836776bSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
49382836776bSmrg	          # Use subshell, to avoid clobbering current variable values
49392836776bSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
49408292847cSmrg	          if test -n "$dlprefile_dlname"; then
49412836776bSmrg	            func_basename "$dlprefile_dlname"
49428292847cSmrg	            dlprefile_dlbasename=$func_basename_result
49432836776bSmrg	          else
49442836776bSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
49452836776bSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
49462836776bSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
49472836776bSmrg	          fi
49482836776bSmrg	        fi
49492836776bSmrg	        $opt_dry_run || {
49508292847cSmrg	          if test -n "$dlprefile_dlbasename"; then
49512836776bSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
49522836776bSmrg	          else
49532836776bSmrg	            func_warning "Could not compute DLL name from $name"
49542836776bSmrg	            eval '$ECHO ": $name " >> "$nlist"'
49552836776bSmrg	          fi
49562836776bSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49572836776bSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
49582836776bSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
49592836776bSmrg	        }
49602836776bSmrg	      else # not an import lib
49612836776bSmrg	        $opt_dry_run || {
49622836776bSmrg	          eval '$ECHO ": $name " >> "$nlist"'
49632836776bSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49642836776bSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49652836776bSmrg	        }
49662836776bSmrg	      fi
49672836776bSmrg	    ;;
49682836776bSmrg	    *)
49692836776bSmrg	      $opt_dry_run || {
49702836776bSmrg	        eval '$ECHO ": $name " >> "$nlist"'
49712836776bSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49722836776bSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49732836776bSmrg	      }
49742836776bSmrg	    ;;
49752836776bSmrg          esac
4976c2939121Smrg	done
4977c2939121Smrg
4978c2939121Smrg	$opt_dry_run || {
4979c2939121Smrg	  # Make sure we have at least an empty file.
4980c2939121Smrg	  test -f "$nlist" || : > "$nlist"
4981c2939121Smrg
4982c2939121Smrg	  if test -n "$exclude_expsyms"; then
4983c2939121Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4984c2939121Smrg	    $MV "$nlist"T "$nlist"
4985c76ae52dSmrg	  fi
4986c2939121Smrg
4987c2939121Smrg	  # Try sorting and uniquifying the output.
4988c2939121Smrg	  if $GREP -v "^: " < "$nlist" |
4989c2939121Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4990c2939121Smrg		sort -k 3
4991c2939121Smrg	      else
4992c2939121Smrg		sort +2
4993c2939121Smrg	      fi |
4994c2939121Smrg	      uniq > "$nlist"S; then
4995c2939121Smrg	    :
4996c76ae52dSmrg	  else
4997c2939121Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4998c76ae52dSmrg	  fi
4999c76ae52dSmrg
5000c2939121Smrg	  if test -f "$nlist"S; then
5001c2939121Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5002c76ae52dSmrg	  else
5003c2939121Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5004c76ae52dSmrg	  fi
5005c76ae52dSmrg
50068292847cSmrg	  func_show_eval '$RM "${nlist}I"'
50078292847cSmrg	  if test -n "$global_symbol_to_import"; then
50088292847cSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
50098292847cSmrg	  fi
50108292847cSmrg
5011c2939121Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5012c76ae52dSmrg
5013c2939121Smrg/* The mapping between symbol names and symbols.  */
5014c2939121Smrgtypedef struct {
5015c2939121Smrg  const char *name;
5016c2939121Smrg  void *address;
5017c2939121Smrg} lt_dlsymlist;
50182836776bSmrgextern LT_DLSYM_CONST lt_dlsymlist
50198292847cSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
50208292847cSmrg"
50218292847cSmrg
50228292847cSmrg	  if test -s "$nlist"I; then
50238292847cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50248292847cSmrgstatic void lt_syminit(void)
50258292847cSmrg{
50268292847cSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
50278292847cSmrg  for (; symbol->name; ++symbol)
50288292847cSmrg    {"
50298292847cSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
50308292847cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50318292847cSmrg    }
50328292847cSmrg}"
50338292847cSmrg	  fi
50348292847cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
50352836776bSmrgLT_DLSYM_CONST lt_dlsymlist
5036c2939121Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
50378292847cSmrg{ {\"$my_originator\", (void *) 0},"
50388292847cSmrg
50398292847cSmrg	  if test -s "$nlist"I; then
50408292847cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50418292847cSmrg  {\"@INIT@\", (void *) &lt_syminit},"
50428292847cSmrg	  fi
5043c76ae52dSmrg
5044c2939121Smrg	  case $need_lib_prefix in
5045c2939121Smrg	  no)
5046c2939121Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5047c2939121Smrg	    ;;
5048c2939121Smrg	  *)
5049c2939121Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5050c2939121Smrg	    ;;
5051c2939121Smrg	  esac
5052c2939121Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5053c2939121Smrg  {0, (void *) 0}
5054c2939121Smrg};
5055c76ae52dSmrg
5056c2939121Smrg/* This works around a problem in FreeBSD linker */
5057c2939121Smrg#ifdef FREEBSD_WORKAROUND
5058c2939121Smrgstatic const void *lt_preloaded_setup() {
5059c2939121Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5060c2939121Smrg}
5061c2939121Smrg#endif
5062c76ae52dSmrg
5063c2939121Smrg#ifdef __cplusplus
5064c2939121Smrg}
5065c2939121Smrg#endif\
5066c2939121Smrg"
5067c2939121Smrg	} # !$opt_dry_run
5068c76ae52dSmrg
5069c2939121Smrg	pic_flag_for_symtable=
5070c2939121Smrg	case "$compile_command " in
5071c2939121Smrg	*" -static "*) ;;
5072c2939121Smrg	*)
5073c2939121Smrg	  case $host in
5074c2939121Smrg	  # compiling the symbol table file with pic_flag works around
5075c2939121Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5076c2939121Smrg	  # linked before any other PIC object.  But we must not use
5077c2939121Smrg	  # pic_flag when linking with -static.  The problem exists in
5078c2939121Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
50792836776bSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5080c2939121Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5081c2939121Smrg	  *-*-hpux*)
5082c2939121Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5083c2939121Smrg	  *)
50848292847cSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5085c2939121Smrg	    ;;
5086c2939121Smrg	  esac
5087c2939121Smrg	  ;;
5088c2939121Smrg	esac
5089c2939121Smrg	symtab_cflags=
5090c2939121Smrg	for arg in $LTCFLAGS; do
5091c2939121Smrg	  case $arg in
5092c2939121Smrg	  -pie | -fpie | -fPIE) ;;
50932836776bSmrg	  *) func_append symtab_cflags " $arg" ;;
5094c2939121Smrg	  esac
5095c2939121Smrg	done
5096c76ae52dSmrg
5097c2939121Smrg	# Now compile the dynamic symbol file.
5098c2939121Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5099c76ae52dSmrg
5100c2939121Smrg	# Clean up the generated files.
51018292847cSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5102c76ae52dSmrg
5103c2939121Smrg	# Transform the symbol file into the correct name.
51048292847cSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5105c2939121Smrg	case $host in
5106c2939121Smrg	*cygwin* | *mingw* | *cegcc* )
5107c2939121Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5108c2939121Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5109c2939121Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5110c2939121Smrg	  else
5111c2939121Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5112c2939121Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5113c2939121Smrg	  fi
5114c2939121Smrg	  ;;
5115c2939121Smrg	*)
5116c2939121Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5117c2939121Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5118c2939121Smrg	  ;;
5119c2939121Smrg	esac
5120c2939121Smrg	;;
5121c2939121Smrg      *)
51228292847cSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5123c2939121Smrg	;;
5124c2939121Smrg      esac
5125c2939121Smrg    else
5126c2939121Smrg      # We keep going just in case the user didn't refer to
5127c2939121Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5128c2939121Smrg      # really was required.
5129c76ae52dSmrg
5130c2939121Smrg      # Nullify the symbol file.
5131c2939121Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5132c2939121Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5133c2939121Smrg    fi
5134c2939121Smrg}
5135c76ae52dSmrg
51368292847cSmrg# func_cygming_gnu_implib_p ARG
51378292847cSmrg# This predicate returns with zero status (TRUE) if
51388292847cSmrg# ARG is a GNU/binutils-style import library. Returns
51398292847cSmrg# with nonzero status (FALSE) otherwise.
51408292847cSmrgfunc_cygming_gnu_implib_p ()
51418292847cSmrg{
51428292847cSmrg  $debug_cmd
51438292847cSmrg
51448292847cSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51458292847cSmrg  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)$'`
51468292847cSmrg  test -n "$func_cygming_gnu_implib_tmp"
51478292847cSmrg}
51488292847cSmrg
51498292847cSmrg# func_cygming_ms_implib_p ARG
51508292847cSmrg# This predicate returns with zero status (TRUE) if
51518292847cSmrg# ARG is an MS-style import library. Returns
51528292847cSmrg# with nonzero status (FALSE) otherwise.
51538292847cSmrgfunc_cygming_ms_implib_p ()
51548292847cSmrg{
51558292847cSmrg  $debug_cmd
51568292847cSmrg
51578292847cSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51588292847cSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
51598292847cSmrg  test -n "$func_cygming_ms_implib_tmp"
51608292847cSmrg}
51618292847cSmrg
5162c2939121Smrg# func_win32_libid arg
5163c2939121Smrg# return the library type of file 'arg'
5164c2939121Smrg#
5165c2939121Smrg# Need a lot of goo to handle *both* DLLs and import libs
5166c2939121Smrg# Has to be a shell function in order to 'eat' the argument
5167c2939121Smrg# that is supplied when $file_magic_command is called.
5168c2939121Smrg# Despite the name, also deal with 64 bit binaries.
5169c2939121Smrgfunc_win32_libid ()
5170c2939121Smrg{
51718292847cSmrg  $debug_cmd
51728292847cSmrg
51738292847cSmrg  win32_libid_type=unknown
5174c2939121Smrg  win32_fileres=`file -L $1 2>/dev/null`
5175c2939121Smrg  case $win32_fileres in
5176c2939121Smrg  *ar\ archive\ import\ library*) # definitely import
5177c2939121Smrg    win32_libid_type="x86 archive import"
5178c2939121Smrg    ;;
5179c2939121Smrg  *ar\ archive*) # could be an import, or static
5180c2939121Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5181c2939121Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5182c2939121Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
51838292847cSmrg      case $nm_interface in
51848292847cSmrg      "MS dumpbin")
51858292847cSmrg	if func_cygming_ms_implib_p "$1" ||
51868292847cSmrg	   func_cygming_gnu_implib_p "$1"
51878292847cSmrg	then
51888292847cSmrg	  win32_nmres=import
51898292847cSmrg	else
51908292847cSmrg	  win32_nmres=
51918292847cSmrg	fi
51928292847cSmrg	;;
51938292847cSmrg      *)
51948292847cSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
51958292847cSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
51968292847cSmrg	  $SED -n -e '
5197c2939121Smrg	    1,100{
5198c2939121Smrg		/ I /{
51998292847cSmrg		    s|.*|import|
5200c2939121Smrg		    p
5201c2939121Smrg		    q
5202c2939121Smrg		}
5203c2939121Smrg	    }'`
52048292847cSmrg	;;
52058292847cSmrg      esac
5206c2939121Smrg      case $win32_nmres in
5207c2939121Smrg      import*)  win32_libid_type="x86 archive import";;
5208c2939121Smrg      *)        win32_libid_type="x86 archive static";;
5209c2939121Smrg      esac
5210c2939121Smrg    fi
5211c2939121Smrg    ;;
5212c2939121Smrg  *DLL*)
5213c2939121Smrg    win32_libid_type="x86 DLL"
5214c2939121Smrg    ;;
5215c2939121Smrg  *executable*) # but shell scripts are "executable" too...
5216c2939121Smrg    case $win32_fileres in
5217c2939121Smrg    *MS\ Windows\ PE\ Intel*)
5218c2939121Smrg      win32_libid_type="x86 DLL"
5219c2939121Smrg      ;;
5220c2939121Smrg    esac
5221c2939121Smrg    ;;
5222c2939121Smrg  esac
5223c2939121Smrg  $ECHO "$win32_libid_type"
5224c2939121Smrg}
5225c76ae52dSmrg
52262836776bSmrg# func_cygming_dll_for_implib ARG
52272836776bSmrg#
52282836776bSmrg# Platform-specific function to extract the
52292836776bSmrg# name of the DLL associated with the specified
52302836776bSmrg# import library ARG.
52312836776bSmrg# Invoked by eval'ing the libtool variable
52322836776bSmrg#    $sharedlib_from_linklib_cmd
52332836776bSmrg# Result is available in the variable
52342836776bSmrg#    $sharedlib_from_linklib_result
52352836776bSmrgfunc_cygming_dll_for_implib ()
52362836776bSmrg{
52378292847cSmrg  $debug_cmd
52388292847cSmrg
52392836776bSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
52402836776bSmrg}
52412836776bSmrg
52422836776bSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
52432836776bSmrg#
52442836776bSmrg# The is the core of a fallback implementation of a
52452836776bSmrg# platform-specific function to extract the name of the
52462836776bSmrg# DLL associated with the specified import library LIBNAME.
52472836776bSmrg#
52482836776bSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
52492836776bSmrg# on the platform and compiler that created the implib.
52502836776bSmrg#
52512836776bSmrg# Echos the name of the DLL associated with the
52522836776bSmrg# specified import library.
52532836776bSmrgfunc_cygming_dll_for_implib_fallback_core ()
52542836776bSmrg{
52558292847cSmrg  $debug_cmd
52568292847cSmrg
52572836776bSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
52582836776bSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
52592836776bSmrg    $SED '/^Contents of section '"$match_literal"':/{
52602836776bSmrg      # Place marker at beginning of archive member dllname section
52612836776bSmrg      s/.*/====MARK====/
52622836776bSmrg      p
52632836776bSmrg      d
52642836776bSmrg    }
52652836776bSmrg    # These lines can sometimes be longer than 43 characters, but
52662836776bSmrg    # are always uninteresting
52672836776bSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
52682836776bSmrg    /^In archive [^:]*:/d
52692836776bSmrg    # Ensure marker is printed
52702836776bSmrg    /^====MARK====/p
52712836776bSmrg    # Remove all lines with less than 43 characters
52722836776bSmrg    /^.\{43\}/!d
52732836776bSmrg    # From remaining lines, remove first 43 characters
52742836776bSmrg    s/^.\{43\}//' |
52752836776bSmrg    $SED -n '
52762836776bSmrg      # Join marker and all lines until next marker into a single line
52772836776bSmrg      /^====MARK====/ b para
52782836776bSmrg      H
52792836776bSmrg      $ b para
52802836776bSmrg      b
52812836776bSmrg      :para
52822836776bSmrg      x
52832836776bSmrg      s/\n//g
52842836776bSmrg      # Remove the marker
52852836776bSmrg      s/^====MARK====//
52862836776bSmrg      # Remove trailing dots and whitespace
52872836776bSmrg      s/[\. \t]*$//
52882836776bSmrg      # Print
52892836776bSmrg      /./p' |
52902836776bSmrg    # we now have a list, one entry per line, of the stringified
52912836776bSmrg    # contents of the appropriate section of all members of the
52928292847cSmrg    # archive that possess that section. Heuristic: eliminate
52938292847cSmrg    # all those that have a first or second character that is
52942836776bSmrg    # a '.' (that is, objdump's representation of an unprintable
52952836776bSmrg    # character.) This should work for all archives with less than
52962836776bSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
52972836776bSmrg    # begins with a literal '.' or a single character followed by
52982836776bSmrg    # a '.'.
52992836776bSmrg    #
53002836776bSmrg    # Of those that remain, print the first one.
53012836776bSmrg    $SED -e '/^\./d;/^.\./d;q'
53022836776bSmrg}
53032836776bSmrg
53042836776bSmrg# func_cygming_dll_for_implib_fallback ARG
53052836776bSmrg# Platform-specific function to extract the
53062836776bSmrg# name of the DLL associated with the specified
53072836776bSmrg# import library ARG.
53082836776bSmrg#
53092836776bSmrg# This fallback implementation is for use when $DLLTOOL
53102836776bSmrg# does not support the --identify-strict option.
53112836776bSmrg# Invoked by eval'ing the libtool variable
53122836776bSmrg#    $sharedlib_from_linklib_cmd
53132836776bSmrg# Result is available in the variable
53142836776bSmrg#    $sharedlib_from_linklib_result
53152836776bSmrgfunc_cygming_dll_for_implib_fallback ()
53162836776bSmrg{
53178292847cSmrg  $debug_cmd
53188292847cSmrg
53198292847cSmrg  if func_cygming_gnu_implib_p "$1"; then
53202836776bSmrg    # binutils import library
53212836776bSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
53228292847cSmrg  elif func_cygming_ms_implib_p "$1"; then
53232836776bSmrg    # ms-generated import library
53242836776bSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
53252836776bSmrg  else
53262836776bSmrg    # unknown
53278292847cSmrg    sharedlib_from_linklib_result=
53282836776bSmrg  fi
53292836776bSmrg}
5330c76ae52dSmrg
5331c76ae52dSmrg
5332c2939121Smrg# func_extract_an_archive dir oldlib
5333c2939121Smrgfunc_extract_an_archive ()
5334c2939121Smrg{
53358292847cSmrg    $debug_cmd
53368292847cSmrg
53378292847cSmrg    f_ex_an_ar_dir=$1; shift
53388292847cSmrg    f_ex_an_ar_oldlib=$1
53398292847cSmrg    if test yes = "$lock_old_archive_extraction"; then
5340c2939121Smrg      lockfile=$f_ex_an_ar_oldlib.lock
5341c2939121Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5342c2939121Smrg	func_echo "Waiting for $lockfile to be removed"
5343c2939121Smrg	sleep 2
5344c2939121Smrg      done
5345c2939121Smrg    fi
5346c2939121Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5347c2939121Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
53488292847cSmrg    if test yes = "$lock_old_archive_extraction"; then
5349c2939121Smrg      $opt_dry_run || rm -f "$lockfile"
5350c2939121Smrg    fi
5351c2939121Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5352c2939121Smrg     :
5353c2939121Smrg    else
5354c2939121Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5355c2939121Smrg    fi
5356c2939121Smrg}
5357c76ae52dSmrg
5358c76ae52dSmrg
5359c2939121Smrg# func_extract_archives gentop oldlib ...
5360c2939121Smrgfunc_extract_archives ()
5361c2939121Smrg{
53628292847cSmrg    $debug_cmd
53638292847cSmrg
53648292847cSmrg    my_gentop=$1; shift
5365c2939121Smrg    my_oldlibs=${1+"$@"}
53668292847cSmrg    my_oldobjs=
53678292847cSmrg    my_xlib=
53688292847cSmrg    my_xabs=
53698292847cSmrg    my_xdir=
5370c76ae52dSmrg
5371c2939121Smrg    for my_xlib in $my_oldlibs; do
5372c2939121Smrg      # Extract the objects.
5373c2939121Smrg      case $my_xlib in
53748292847cSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5375c2939121Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5376c2939121Smrg      esac
5377c2939121Smrg      func_basename "$my_xlib"
53788292847cSmrg      my_xlib=$func_basename_result
5379c2939121Smrg      my_xlib_u=$my_xlib
5380c2939121Smrg      while :; do
5381c2939121Smrg        case " $extracted_archives " in
5382c2939121Smrg	*" $my_xlib_u "*)
5383c2939121Smrg	  func_arith $extracted_serial + 1
5384c2939121Smrg	  extracted_serial=$func_arith_result
5385c2939121Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5386c2939121Smrg	*) break ;;
5387c2939121Smrg	esac
5388c2939121Smrg      done
5389c2939121Smrg      extracted_archives="$extracted_archives $my_xlib_u"
53908292847cSmrg      my_xdir=$my_gentop/$my_xlib_u
5391c76ae52dSmrg
5392c2939121Smrg      func_mkdir_p "$my_xdir"
5393c2939121Smrg
5394c2939121Smrg      case $host in
5395c2939121Smrg      *-darwin*)
5396c2939121Smrg	func_verbose "Extracting $my_xabs"
5397c2939121Smrg	# Do not bother doing anything if just a dry run
5398c2939121Smrg	$opt_dry_run || {
5399c2939121Smrg	  darwin_orig_dir=`pwd`
5400c2939121Smrg	  cd $my_xdir || exit $?
5401c2939121Smrg	  darwin_archive=$my_xabs
5402c2939121Smrg	  darwin_curdir=`pwd`
54038292847cSmrg	  func_basename "$darwin_archive"
54048292847cSmrg	  darwin_base_archive=$func_basename_result
5405c2939121Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5406c2939121Smrg	  if test -n "$darwin_arches"; then
5407c2939121Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5408c2939121Smrg	    darwin_arch=
5409c2939121Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
54108292847cSmrg	    for darwin_arch in  $darwin_arches; do
54118292847cSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
54128292847cSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
54138292847cSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
54148292847cSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5415c2939121Smrg	      cd "$darwin_curdir"
54168292847cSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5417c2939121Smrg	    done # $darwin_arches
5418c2939121Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
54198292847cSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5420c2939121Smrg	    darwin_file=
5421c2939121Smrg	    darwin_files=
5422c2939121Smrg	    for darwin_file in $darwin_filelist; do
5423c2939121Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5424c2939121Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5425c2939121Smrg	    done # $darwin_filelist
5426c2939121Smrg	    $RM -rf unfat-$$
5427c2939121Smrg	    cd "$darwin_orig_dir"
5428c76ae52dSmrg	  else
5429c2939121Smrg	    cd $darwin_orig_dir
5430c2939121Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5431c2939121Smrg	  fi # $darwin_arches
5432c2939121Smrg	} # !$opt_dry_run
5433c2939121Smrg	;;
5434c2939121Smrg      *)
5435c2939121Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5436c2939121Smrg	;;
5437c2939121Smrg      esac
5438c2939121Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5439c2939121Smrg    done
5440c76ae52dSmrg
54418292847cSmrg    func_extract_archives_result=$my_oldobjs
5442c2939121Smrg}
5443c76ae52dSmrg
5444c76ae52dSmrg
5445c2939121Smrg# func_emit_wrapper [arg=no]
5446c2939121Smrg#
5447c2939121Smrg# Emit a libtool wrapper script on stdout.
5448c2939121Smrg# Don't directly open a file because we may want to
5449c2939121Smrg# incorporate the script contents within a cygwin/mingw
5450c2939121Smrg# wrapper executable.  Must ONLY be called from within
5451c2939121Smrg# func_mode_link because it depends on a number of variables
5452c2939121Smrg# set therein.
5453c2939121Smrg#
5454c2939121Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5455c2939121Smrg# variable will take.  If 'yes', then the emitted script
54568292847cSmrg# will assume that the directory where it is stored is
5457c2939121Smrg# the $objdir directory.  This is a cygwin/mingw-specific
5458c2939121Smrg# behavior.
5459c2939121Smrgfunc_emit_wrapper ()
5460c2939121Smrg{
5461c2939121Smrg	func_emit_wrapper_arg1=${1-no}
5462c76ae52dSmrg
5463c2939121Smrg	$ECHO "\
5464c2939121Smrg#! $SHELL
5465c76ae52dSmrg
5466c2939121Smrg# $output - temporary wrapper script for $objdir/$outputname
54678292847cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5468c2939121Smrg#
5469c2939121Smrg# The $output program cannot be directly executed until all the libtool
5470c2939121Smrg# libraries that it depends on are installed.
5471c2939121Smrg#
5472c2939121Smrg# This wrapper script should never be moved out of the build directory.
5473c2939121Smrg# If it is, it will not operate correctly.
5474c76ae52dSmrg
5475c2939121Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5476c2939121Smrg# metacharacters that are still active within double-quoted strings.
5477c2939121Smrgsed_quote_subst='$sed_quote_subst'
5478c76ae52dSmrg
5479c2939121Smrg# Be Bourne compatible
5480c2939121Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5481c2939121Smrg  emulate sh
5482c2939121Smrg  NULLCMD=:
5483c2939121Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5484c2939121Smrg  # is contrary to our usage.  Disable this feature.
5485c2939121Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5486c2939121Smrg  setopt NO_GLOB_SUBST
5487c2939121Smrgelse
5488c2939121Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5489c2939121Smrgfi
5490c2939121SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5491c2939121SmrgDUALCASE=1; export DUALCASE # for MKS sh
5492c76ae52dSmrg
5493c2939121Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5494c2939121Smrg# if CDPATH is set.
5495c2939121Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5496c76ae52dSmrg
5497c2939121Smrgrelink_command=\"$relink_command\"
5498c76ae52dSmrg
5499c2939121Smrg# This environment variable determines our operation mode.
5500c2939121Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5501c2939121Smrg  # install mode needs the following variables:
5502c2939121Smrg  generated_by_libtool_version='$macro_version'
5503c2939121Smrg  notinst_deplibs='$notinst_deplibs'
5504c2939121Smrgelse
5505c2939121Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5506c2939121Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5507c2939121Smrg    file=\"\$0\""
5508c76ae52dSmrg
550925420f97Smrg    func_quote_arg pretty "$ECHO"
551025420f97Smrg    qECHO=$func_quote_arg_result
5511c2939121Smrg    $ECHO "\
5512c76ae52dSmrg
5513c2939121Smrg# A function that is used when there is no print builtin or printf.
5514c2939121Smrgfunc_fallback_echo ()
5515c2939121Smrg{
5516c2939121Smrg  eval 'cat <<_LTECHO_EOF
5517c2939121Smrg\$1
5518c2939121Smrg_LTECHO_EOF'
5519c2939121Smrg}
552025420f97Smrg    ECHO=$qECHO
5521c2939121Smrg  fi
5522c2939121Smrg
5523c2939121Smrg# Very basic option parsing. These options are (a) specific to
5524c2939121Smrg# the libtool wrapper, (b) are identical between the wrapper
55258292847cSmrg# /script/ and the wrapper /executable/ that is used only on
5526c2939121Smrg# windows platforms, and (c) all begin with the string "--lt-"
55278292847cSmrg# (application programs are unlikely to have options that match
5528c2939121Smrg# this pattern).
5529c2939121Smrg#
5530c2939121Smrg# There are only two supported options: --lt-debug and
5531c2939121Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
5532c2939121Smrg#
5533c2939121Smrg# The first argument to this parsing function should be the
5534c2939121Smrg# script's $0 value, followed by "$@".
5535c2939121Smrglt_option_debug=
5536c2939121Smrgfunc_parse_lt_options ()
5537c2939121Smrg{
5538c2939121Smrg  lt_script_arg0=\$0
5539c2939121Smrg  shift
5540c2939121Smrg  for lt_opt
5541c2939121Smrg  do
5542c2939121Smrg    case \"\$lt_opt\" in
5543c2939121Smrg    --lt-debug) lt_option_debug=1 ;;
5544c2939121Smrg    --lt-dump-script)
5545c2939121Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5546c2939121Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5547c2939121Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5548c2939121Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5549c2939121Smrg        exit 0
5550c2939121Smrg      ;;
5551c2939121Smrg    --lt-*)
5552c2939121Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5553c2939121Smrg        exit 1
5554c76ae52dSmrg      ;;
5555c2939121Smrg    esac
5556c2939121Smrg  done
5557c76ae52dSmrg
5558c2939121Smrg  # Print the debug banner immediately:
5559c2939121Smrg  if test -n \"\$lt_option_debug\"; then
55608292847cSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5561c2939121Smrg  fi
5562c2939121Smrg}
5563c76ae52dSmrg
5564c2939121Smrg# Used when --lt-debug. Prints its arguments to stdout
5565c2939121Smrg# (redirection is the responsibility of the caller)
5566c2939121Smrgfunc_lt_dump_args ()
5567c2939121Smrg{
5568c2939121Smrg  lt_dump_args_N=1;
5569c2939121Smrg  for lt_arg
5570c2939121Smrg  do
55718292847cSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5572c2939121Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5573c2939121Smrg  done
5574c2939121Smrg}
5575c76ae52dSmrg
5576c2939121Smrg# Core function for launching the target application
5577c2939121Smrgfunc_exec_program_core ()
5578c2939121Smrg{
5579c2939121Smrg"
5580c2939121Smrg  case $host in
5581c2939121Smrg  # Backslashes separate directories on plain windows
5582c2939121Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
5583c2939121Smrg    $ECHO "\
5584c2939121Smrg      if test -n \"\$lt_option_debug\"; then
55858292847cSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5586c2939121Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5587c76ae52dSmrg      fi
5588c2939121Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5589c2939121Smrg"
5590c2939121Smrg    ;;
5591c76ae52dSmrg
5592c2939121Smrg  *)
5593c2939121Smrg    $ECHO "\
5594c2939121Smrg      if test -n \"\$lt_option_debug\"; then
55958292847cSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5596c2939121Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5597c76ae52dSmrg      fi
5598c2939121Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5599c2939121Smrg"
5600c2939121Smrg    ;;
5601c2939121Smrg  esac
5602c2939121Smrg  $ECHO "\
5603c2939121Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5604c2939121Smrg      exit 1
5605c2939121Smrg}
5606c76ae52dSmrg
5607c2939121Smrg# A function to encapsulate launching the target application
5608c2939121Smrg# Strips options in the --lt-* namespace from \$@ and
5609c2939121Smrg# launches target application with the remaining arguments.
5610c2939121Smrgfunc_exec_program ()
5611c2939121Smrg{
56122836776bSmrg  case \" \$* \" in
56132836776bSmrg  *\\ --lt-*)
56142836776bSmrg    for lt_wr_arg
56152836776bSmrg    do
56162836776bSmrg      case \$lt_wr_arg in
56172836776bSmrg      --lt-*) ;;
56182836776bSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
56192836776bSmrg      esac
56202836776bSmrg      shift
56212836776bSmrg    done ;;
56222836776bSmrg  esac
5623c2939121Smrg  func_exec_program_core \${1+\"\$@\"}
5624c2939121Smrg}
5625c76ae52dSmrg
5626c2939121Smrg  # Parse options
5627c2939121Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5628c76ae52dSmrg
5629c2939121Smrg  # Find the directory that this script lives in.
5630c2939121Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5631c2939121Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5632c76ae52dSmrg
5633c2939121Smrg  # Follow symbolic links until we get to the real thisdir.
5634c2939121Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5635c2939121Smrg  while test -n \"\$file\"; do
5636c2939121Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5637c76ae52dSmrg
5638c2939121Smrg    # If there was a directory component, then change thisdir.
5639c2939121Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5640c2939121Smrg      case \"\$destdir\" in
5641c2939121Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5642c2939121Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5643c2939121Smrg      esac
5644c2939121Smrg    fi
5645c76ae52dSmrg
5646c2939121Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5647c2939121Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5648c2939121Smrg  done
5649c76ae52dSmrg
5650c2939121Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5651c2939121Smrg  # the cwrapper.
5652c2939121Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5653c2939121Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5654c2939121Smrg    # special case for '.'
5655c2939121Smrg    if test \"\$thisdir\" = \".\"; then
5656c2939121Smrg      thisdir=\`pwd\`
5657c2939121Smrg    fi
5658c2939121Smrg    # remove .libs from thisdir
5659c2939121Smrg    case \"\$thisdir\" in
5660c2939121Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5661c2939121Smrg    $objdir )   thisdir=. ;;
5662c2939121Smrg    esac
5663c2939121Smrg  fi
5664c76ae52dSmrg
5665c2939121Smrg  # Try to get the absolute directory name.
5666c2939121Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5667c2939121Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5668c2939121Smrg"
5669c76ae52dSmrg
56708292847cSmrg	if test yes = "$fast_install"; then
5671c2939121Smrg	  $ECHO "\
5672c2939121Smrg  program=lt-'$outputname'$exeext
5673c2939121Smrg  progdir=\"\$thisdir/$objdir\"
5674c76ae52dSmrg
5675c2939121Smrg  if test ! -f \"\$progdir/\$program\" ||
56768292847cSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5677c2939121Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5678c76ae52dSmrg
5679c2939121Smrg    file=\"\$\$-\$program\"
5680c76ae52dSmrg
5681c2939121Smrg    if test ! -d \"\$progdir\"; then
5682c2939121Smrg      $MKDIR \"\$progdir\"
5683c2939121Smrg    else
5684c2939121Smrg      $RM \"\$progdir/\$file\"
5685c2939121Smrg    fi"
5686c76ae52dSmrg
5687c2939121Smrg	  $ECHO "\
5688c76ae52dSmrg
5689c2939121Smrg    # relink executable if necessary
5690c2939121Smrg    if test -n \"\$relink_command\"; then
5691c2939121Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5692c2939121Smrg      else
56938292847cSmrg	\$ECHO \"\$relink_command_output\" >&2
5694c2939121Smrg	$RM \"\$progdir/\$file\"
5695c2939121Smrg	exit 1
5696c2939121Smrg      fi
5697c2939121Smrg    fi
5698c76ae52dSmrg
5699c2939121Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5700c2939121Smrg    { $RM \"\$progdir/\$program\";
5701c2939121Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5702c2939121Smrg    $RM \"\$progdir/\$file\"
5703c2939121Smrg  fi"
5704c2939121Smrg	else
5705c2939121Smrg	  $ECHO "\
5706c2939121Smrg  program='$outputname'
5707c2939121Smrg  progdir=\"\$thisdir/$objdir\"
5708c2939121Smrg"
5709c2939121Smrg	fi
5710c76ae52dSmrg
5711c2939121Smrg	$ECHO "\
5712c76ae52dSmrg
5713c2939121Smrg  if test -f \"\$progdir/\$program\"; then"
5714c76ae52dSmrg
57152836776bSmrg	# fixup the dll searchpath if we need to.
57162836776bSmrg	#
57172836776bSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
57182836776bSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
57192836776bSmrg	# libraries must come first.
57202836776bSmrg	if test -n "$dllsearchpath"; then
57212836776bSmrg	  $ECHO "\
57222836776bSmrg    # Add the dll search path components to the executable PATH
57232836776bSmrg    PATH=$dllsearchpath:\$PATH
57242836776bSmrg"
57252836776bSmrg	fi
57262836776bSmrg
5727c2939121Smrg	# Export our shlibpath_var if we have one.
57288292847cSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5729c2939121Smrg	  $ECHO "\
5730c2939121Smrg    # Add our own library path to $shlibpath_var
5731c2939121Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5732c76ae52dSmrg
5733c2939121Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5734c2939121Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5735c2939121Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5736c76ae52dSmrg
5737c2939121Smrg    export $shlibpath_var
5738c2939121Smrg"
5739c2939121Smrg	fi
5740c76ae52dSmrg
5741c2939121Smrg	$ECHO "\
5742c2939121Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5743c2939121Smrg      # Run the actual program with our arguments.
5744c2939121Smrg      func_exec_program \${1+\"\$@\"}
5745c2939121Smrg    fi
5746c2939121Smrg  else
5747c2939121Smrg    # The program doesn't exist.
57488292847cSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5749c2939121Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5750c2939121Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5751c2939121Smrg    exit 1
5752c2939121Smrg  fi
5753c2939121Smrgfi\
5754c2939121Smrg"
5755c2939121Smrg}
5756c76ae52dSmrg
5757c76ae52dSmrg
5758c2939121Smrg# func_emit_cwrapperexe_src
5759c2939121Smrg# emit the source code for a wrapper executable on stdout
5760c2939121Smrg# Must ONLY be called from within func_mode_link because
5761c2939121Smrg# it depends on a number of variable set therein.
5762c2939121Smrgfunc_emit_cwrapperexe_src ()
5763c2939121Smrg{
5764c2939121Smrg	cat <<EOF
5765c76ae52dSmrg
5766c2939121Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
57678292847cSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5768c76ae52dSmrg
5769c2939121Smrg   The $output program cannot be directly executed until all the libtool
5770c2939121Smrg   libraries that it depends on are installed.
5771c76ae52dSmrg
5772c2939121Smrg   This wrapper executable should never be moved out of the build directory.
5773c2939121Smrg   If it is, it will not operate correctly.
5774c2939121Smrg*/
5775c2939121SmrgEOF
5776c2939121Smrg	    cat <<"EOF"
5777c2939121Smrg#ifdef _MSC_VER
5778c2939121Smrg# define _CRT_SECURE_NO_DEPRECATE 1
5779c2939121Smrg#endif
5780c2939121Smrg#include <stdio.h>
5781c2939121Smrg#include <stdlib.h>
5782c2939121Smrg#ifdef _MSC_VER
5783c2939121Smrg# include <direct.h>
5784c2939121Smrg# include <process.h>
5785c2939121Smrg# include <io.h>
5786c2939121Smrg#else
5787c2939121Smrg# include <unistd.h>
5788c2939121Smrg# include <stdint.h>
5789c2939121Smrg# ifdef __CYGWIN__
5790c2939121Smrg#  include <io.h>
5791c2939121Smrg# endif
5792c2939121Smrg#endif
5793c2939121Smrg#include <malloc.h>
5794c2939121Smrg#include <stdarg.h>
5795c2939121Smrg#include <assert.h>
5796c2939121Smrg#include <string.h>
5797c2939121Smrg#include <ctype.h>
5798c2939121Smrg#include <errno.h>
5799c2939121Smrg#include <fcntl.h>
5800c2939121Smrg#include <sys/stat.h>
5801c76ae52dSmrg
58028292847cSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
58038292847cSmrg
5804c2939121Smrg/* declarations of non-ANSI functions */
58058292847cSmrg#if defined __MINGW32__
5806c2939121Smrg# ifdef __STRICT_ANSI__
5807c2939121Smrgint _putenv (const char *);
5808c2939121Smrg# endif
58098292847cSmrg#elif defined __CYGWIN__
5810c2939121Smrg# ifdef __STRICT_ANSI__
5811c2939121Smrgchar *realpath (const char *, char *);
5812c2939121Smrgint putenv (char *);
5813c2939121Smrgint setenv (const char *, const char *, int);
5814c2939121Smrg# endif
58158292847cSmrg/* #elif defined other_platform || defined ... */
5816c2939121Smrg#endif
5817c76ae52dSmrg
5818c2939121Smrg/* portability defines, excluding path handling macros */
58198292847cSmrg#if defined _MSC_VER
5820c2939121Smrg# define setmode _setmode
5821c2939121Smrg# define stat    _stat
5822c2939121Smrg# define chmod   _chmod
5823c2939121Smrg# define getcwd  _getcwd
5824c2939121Smrg# define putenv  _putenv
5825c2939121Smrg# define S_IXUSR _S_IEXEC
58268292847cSmrg#elif defined __MINGW32__
5827c2939121Smrg# define setmode _setmode
5828c2939121Smrg# define stat    _stat
5829c2939121Smrg# define chmod   _chmod
5830c2939121Smrg# define getcwd  _getcwd
5831c2939121Smrg# define putenv  _putenv
58328292847cSmrg#elif defined __CYGWIN__
5833c2939121Smrg# define HAVE_SETENV
5834c2939121Smrg# define FOPEN_WB "wb"
58358292847cSmrg/* #elif defined other platforms ... */
5836c2939121Smrg#endif
5837c76ae52dSmrg
58388292847cSmrg#if defined PATH_MAX
5839c2939121Smrg# define LT_PATHMAX PATH_MAX
58408292847cSmrg#elif defined MAXPATHLEN
5841c2939121Smrg# define LT_PATHMAX MAXPATHLEN
5842c2939121Smrg#else
5843c2939121Smrg# define LT_PATHMAX 1024
5844c2939121Smrg#endif
5845c76ae52dSmrg
5846c2939121Smrg#ifndef S_IXOTH
5847c2939121Smrg# define S_IXOTH 0
5848c2939121Smrg#endif
5849c2939121Smrg#ifndef S_IXGRP
5850c2939121Smrg# define S_IXGRP 0
5851c2939121Smrg#endif
5852c76ae52dSmrg
5853c2939121Smrg/* path handling portability macros */
5854c2939121Smrg#ifndef DIR_SEPARATOR
5855c2939121Smrg# define DIR_SEPARATOR '/'
5856c2939121Smrg# define PATH_SEPARATOR ':'
5857c2939121Smrg#endif
5858c76ae52dSmrg
58598292847cSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
58608292847cSmrg  defined __OS2__
5861c2939121Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5862c2939121Smrg# define FOPEN_WB "wb"
5863c2939121Smrg# ifndef DIR_SEPARATOR_2
5864c2939121Smrg#  define DIR_SEPARATOR_2 '\\'
5865c2939121Smrg# endif
5866c2939121Smrg# ifndef PATH_SEPARATOR_2
5867c2939121Smrg#  define PATH_SEPARATOR_2 ';'
5868c2939121Smrg# endif
5869c2939121Smrg#endif
5870c76ae52dSmrg
5871c2939121Smrg#ifndef DIR_SEPARATOR_2
5872c2939121Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5873c2939121Smrg#else /* DIR_SEPARATOR_2 */
5874c2939121Smrg# define IS_DIR_SEPARATOR(ch) \
5875c2939121Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5876c2939121Smrg#endif /* DIR_SEPARATOR_2 */
5877c76ae52dSmrg
5878c2939121Smrg#ifndef PATH_SEPARATOR_2
5879c2939121Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5880c2939121Smrg#else /* PATH_SEPARATOR_2 */
5881c2939121Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5882c2939121Smrg#endif /* PATH_SEPARATOR_2 */
5883c2939121Smrg
5884c2939121Smrg#ifndef FOPEN_WB
5885c2939121Smrg# define FOPEN_WB "w"
5886c2939121Smrg#endif
5887c2939121Smrg#ifndef _O_BINARY
5888c2939121Smrg# define _O_BINARY 0
5889c2939121Smrg#endif
5890c2939121Smrg
5891c2939121Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5892c2939121Smrg#define XFREE(stale) do { \
58938292847cSmrg  if (stale) { free (stale); stale = 0; } \
5894c2939121Smrg} while (0)
5895c2939121Smrg
58968292847cSmrg#if defined LT_DEBUGWRAPPER
5897c2939121Smrgstatic int lt_debug = 1;
5898c2939121Smrg#else
5899c2939121Smrgstatic int lt_debug = 0;
5900c2939121Smrg#endif
5901c2939121Smrg
5902c2939121Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5903c2939121Smrg
5904c2939121Smrgvoid *xmalloc (size_t num);
5905c2939121Smrgchar *xstrdup (const char *string);
5906c2939121Smrgconst char *base_name (const char *name);
5907c2939121Smrgchar *find_executable (const char *wrapper);
5908c2939121Smrgchar *chase_symlinks (const char *pathspec);
5909c2939121Smrgint make_executable (const char *path);
5910c2939121Smrgint check_executable (const char *path);
5911c2939121Smrgchar *strendzap (char *str, const char *pat);
5912c2939121Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5913c2939121Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5914c2939121Smrgstatic const char *nonnull (const char *s);
5915c2939121Smrgstatic const char *nonempty (const char *s);
5916c2939121Smrgvoid lt_setenv (const char *name, const char *value);
5917c2939121Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5918c2939121Smrgvoid lt_update_exe_path (const char *name, const char *value);
5919c2939121Smrgvoid lt_update_lib_path (const char *name, const char *value);
5920c2939121Smrgchar **prepare_spawn (char **argv);
5921c2939121Smrgvoid lt_dump_script (FILE *f);
5922c2939121SmrgEOF
5923c2939121Smrg
5924c2939121Smrg	    cat <<EOF
59258292847cSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
59268292847cSmrg# define externally_visible volatile
59278292847cSmrg#else
59288292847cSmrg# define externally_visible __attribute__((externally_visible)) volatile
59298292847cSmrg#endif
59308292847cSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5931c2939121Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5932c2939121SmrgEOF
5933c2939121Smrg
59348292847cSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
59352836776bSmrg              func_to_host_path "$temp_rpath"
5936c2939121Smrg	      cat <<EOF
59372836776bSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5938c76ae52dSmrgEOF
5939c76ae52dSmrg	    else
5940c2939121Smrg	      cat <<"EOF"
5941c2939121Smrgconst char * LIB_PATH_VALUE   = "";
5942c2939121SmrgEOF
5943c76ae52dSmrg	    fi
5944c2939121Smrg
5945c2939121Smrg	    if test -n "$dllsearchpath"; then
59462836776bSmrg              func_to_host_path "$dllsearchpath:"
5947c2939121Smrg	      cat <<EOF
5948c2939121Smrgconst char * EXE_PATH_VARNAME = "PATH";
59492836776bSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5950c2939121SmrgEOF
5951c76ae52dSmrg	    else
5952c2939121Smrg	      cat <<"EOF"
5953c2939121Smrgconst char * EXE_PATH_VARNAME = "";
5954c2939121Smrgconst char * EXE_PATH_VALUE   = "";
5955c2939121SmrgEOF
5956c76ae52dSmrg	    fi
5957c2939121Smrg
59588292847cSmrg	    if test yes = "$fast_install"; then
5959c2939121Smrg	      cat <<EOF
5960c2939121Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5961c2939121SmrgEOF
5962c76ae52dSmrg	    else
5963c2939121Smrg	      cat <<EOF
5964c2939121Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5965c2939121SmrgEOF
5966c76ae52dSmrg	    fi
5967c76ae52dSmrg
5968c76ae52dSmrg
5969c2939121Smrg	    cat <<"EOF"
5970c76ae52dSmrg
5971c2939121Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5972c76ae52dSmrg
5973c2939121Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5974c2939121Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5975c2939121Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5976c76ae52dSmrg
5977c2939121Smrgint
5978c2939121Smrgmain (int argc, char *argv[])
5979c2939121Smrg{
5980c2939121Smrg  char **newargz;
5981c2939121Smrg  int  newargc;
5982c2939121Smrg  char *tmp_pathspec;
5983c2939121Smrg  char *actual_cwrapper_path;
5984c2939121Smrg  char *actual_cwrapper_name;
5985c2939121Smrg  char *target_name;
5986c2939121Smrg  char *lt_argv_zero;
59878292847cSmrg  int rval = 127;
5988c76ae52dSmrg
5989c2939121Smrg  int i;
5990c76ae52dSmrg
5991c2939121Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
59928292847cSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5993c76ae52dSmrg
5994c2939121Smrg  /* very simple arg parsing; don't want to rely on getopt
5995c2939121Smrg   * also, copy all non cwrapper options to newargz, except
5996c2939121Smrg   * argz[0], which is handled differently
5997c2939121Smrg   */
5998c2939121Smrg  newargc=0;
5999c2939121Smrg  for (i = 1; i < argc; i++)
6000c2939121Smrg    {
60018292847cSmrg      if (STREQ (argv[i], dumpscript_opt))
6002c2939121Smrg	{
6003c2939121SmrgEOF
60048292847cSmrg	    case $host in
6005c2939121Smrg	      *mingw* | *cygwin* )
6006c2939121Smrg		# make stdout use "unix" line endings
6007c2939121Smrg		echo "          setmode(1,_O_BINARY);"
6008c2939121Smrg		;;
60090d590c07Smrg	      esac
6010c76ae52dSmrg
6011c2939121Smrg	    cat <<"EOF"
6012c2939121Smrg	  lt_dump_script (stdout);
6013c2939121Smrg	  return 0;
6014c2939121Smrg	}
60158292847cSmrg      if (STREQ (argv[i], debug_opt))
6016c2939121Smrg	{
6017c2939121Smrg          lt_debug = 1;
6018c2939121Smrg          continue;
6019c2939121Smrg	}
60208292847cSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6021c2939121Smrg        {
6022c2939121Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6023c2939121Smrg             namespace, but it is not one of the ones we know about and
6024c2939121Smrg             have already dealt with, above (inluding dump-script), then
6025c2939121Smrg             report an error. Otherwise, targets might begin to believe
6026c2939121Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6027c2939121Smrg             namespace. The first time any user complains about this, we'll
6028c2939121Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6029c2939121Smrg             or a configure.ac-settable value.
6030c2939121Smrg           */
6031c2939121Smrg          lt_fatal (__FILE__, __LINE__,
6032c2939121Smrg		    "unrecognized %s option: '%s'",
6033c2939121Smrg                    ltwrapper_option_prefix, argv[i]);
6034c2939121Smrg        }
6035c2939121Smrg      /* otherwise ... */
6036c2939121Smrg      newargz[++newargc] = xstrdup (argv[i]);
6037c2939121Smrg    }
6038c2939121Smrg  newargz[++newargc] = NULL;
6039c76ae52dSmrg
6040c2939121SmrgEOF
6041c2939121Smrg	    cat <<EOF
6042c2939121Smrg  /* The GNU banner must be the first non-error debug message */
60438292847cSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6044c2939121SmrgEOF
6045c2939121Smrg	    cat <<"EOF"
6046c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6047c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6048c2939121Smrg
6049c2939121Smrg  tmp_pathspec = find_executable (argv[0]);
6050c2939121Smrg  if (tmp_pathspec == NULL)
6051c2939121Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6052c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6053c2939121Smrg                  "(main) found exe (before symlink chase) at: %s\n",
6054c2939121Smrg		  tmp_pathspec);
6055c2939121Smrg
6056c2939121Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6057c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6058c2939121Smrg                  "(main) found exe (after symlink chase) at: %s\n",
6059c2939121Smrg		  actual_cwrapper_path);
6060c2939121Smrg  XFREE (tmp_pathspec);
6061c2939121Smrg
6062c2939121Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6063c2939121Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6064c2939121Smrg
6065c2939121Smrg  /* wrapper name transforms */
6066c2939121Smrg  strendzap (actual_cwrapper_name, ".exe");
6067c2939121Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6068c2939121Smrg  XFREE (actual_cwrapper_name);
6069c2939121Smrg  actual_cwrapper_name = tmp_pathspec;
6070c2939121Smrg  tmp_pathspec = 0;
6071c2939121Smrg
6072c2939121Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6073c2939121Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6074c2939121Smrg  strendzap (target_name, ".exe");
6075c2939121Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6076c2939121Smrg  XFREE (target_name);
6077c2939121Smrg  target_name = tmp_pathspec;
6078c2939121Smrg  tmp_pathspec = 0;
6079c2939121Smrg
6080c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6081c2939121Smrg		  "(main) libtool target name: %s\n",
6082c2939121Smrg		  target_name);
6083c2939121SmrgEOF
6084c76ae52dSmrg
6085c2939121Smrg	    cat <<EOF
6086c2939121Smrg  newargz[0] =
6087c2939121Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6088c2939121Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6089c2939121Smrg  strcpy (newargz[0], actual_cwrapper_path);
6090c2939121Smrg  strcat (newargz[0], "$objdir");
6091c2939121Smrg  strcat (newargz[0], "/");
6092c2939121SmrgEOF
6093c76ae52dSmrg
6094c2939121Smrg	    cat <<"EOF"
6095c2939121Smrg  /* stop here, and copy so we don't have to do this twice */
6096c2939121Smrg  tmp_pathspec = xstrdup (newargz[0]);
6097c76ae52dSmrg
6098c2939121Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6099c2939121Smrg  strcat (newargz[0], actual_cwrapper_name);
6100c76ae52dSmrg
6101c2939121Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6102c2939121Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6103c2939121Smrg  XFREE (tmp_pathspec);
6104c2939121Smrg  tmp_pathspec = NULL;
6105c2939121SmrgEOF
6106c76ae52dSmrg
6107c2939121Smrg	    case $host_os in
6108c2939121Smrg	      mingw*)
6109c2939121Smrg	    cat <<"EOF"
6110c2939121Smrg  {
6111c2939121Smrg    char* p;
6112c2939121Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6113c2939121Smrg      {
6114c2939121Smrg	*p = '/';
6115c2939121Smrg      }
6116c2939121Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6117c2939121Smrg      {
6118c2939121Smrg	*p = '/';
6119c2939121Smrg      }
6120c2939121Smrg  }
6121c2939121SmrgEOF
6122c2939121Smrg	    ;;
6123c2939121Smrg	    esac
6124c76ae52dSmrg
6125c2939121Smrg	    cat <<"EOF"
6126c2939121Smrg  XFREE (target_name);
6127c2939121Smrg  XFREE (actual_cwrapper_path);
6128c2939121Smrg  XFREE (actual_cwrapper_name);
6129c76ae52dSmrg
6130c2939121Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6131c2939121Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
61322836776bSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
61332836776bSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
61342836776bSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
61352836776bSmrg     libraries must come first. */
6136c2939121Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
61372836776bSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6138c76ae52dSmrg
6139c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6140c2939121Smrg		  nonnull (lt_argv_zero));
6141c2939121Smrg  for (i = 0; i < newargc; i++)
6142c2939121Smrg    {
6143c2939121Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6144c2939121Smrg		      i, nonnull (newargz[i]));
6145c2939121Smrg    }
6146c76ae52dSmrg
6147c2939121SmrgEOF
6148c76ae52dSmrg
6149c2939121Smrg	    case $host_os in
6150c2939121Smrg	      mingw*)
6151c2939121Smrg		cat <<"EOF"
6152c2939121Smrg  /* execv doesn't actually work on mingw as expected on unix */
6153c2939121Smrg  newargz = prepare_spawn (newargz);
61548292847cSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6155c2939121Smrg  if (rval == -1)
6156c2939121Smrg    {
6157c2939121Smrg      /* failed to start process */
6158c2939121Smrg      lt_debugprintf (__FILE__, __LINE__,
6159c2939121Smrg		      "(main) failed to launch target \"%s\": %s\n",
6160c2939121Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6161c2939121Smrg      return 127;
6162c2939121Smrg    }
6163c2939121Smrg  return rval;
6164c2939121SmrgEOF
6165c2939121Smrg		;;
6166c2939121Smrg	      *)
6167c2939121Smrg		cat <<"EOF"
6168c2939121Smrg  execv (lt_argv_zero, newargz);
6169c2939121Smrg  return rval; /* =127, but avoids unused variable warning */
6170c2939121SmrgEOF
6171c2939121Smrg		;;
6172c2939121Smrg	    esac
6173c76ae52dSmrg
6174c2939121Smrg	    cat <<"EOF"
6175c2939121Smrg}
6176c76ae52dSmrg
6177c2939121Smrgvoid *
6178c2939121Smrgxmalloc (size_t num)
6179c2939121Smrg{
6180c2939121Smrg  void *p = (void *) malloc (num);
6181c2939121Smrg  if (!p)
6182c2939121Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6183c76ae52dSmrg
6184c2939121Smrg  return p;
6185c2939121Smrg}
6186c76ae52dSmrg
6187c2939121Smrgchar *
6188c2939121Smrgxstrdup (const char *string)
6189c2939121Smrg{
6190c2939121Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6191c2939121Smrg			  string) : NULL;
6192c2939121Smrg}
6193c76ae52dSmrg
6194c2939121Smrgconst char *
6195c2939121Smrgbase_name (const char *name)
6196c2939121Smrg{
6197c2939121Smrg  const char *base;
6198c76ae52dSmrg
61998292847cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6200c2939121Smrg  /* Skip over the disk name in MSDOS pathnames. */
6201c2939121Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6202c2939121Smrg    name += 2;
6203c2939121Smrg#endif
6204c76ae52dSmrg
6205c2939121Smrg  for (base = name; *name; name++)
6206c2939121Smrg    if (IS_DIR_SEPARATOR (*name))
6207c2939121Smrg      base = name + 1;
6208c2939121Smrg  return base;
6209c2939121Smrg}
6210c76ae52dSmrg
6211c2939121Smrgint
6212c2939121Smrgcheck_executable (const char *path)
6213c2939121Smrg{
6214c2939121Smrg  struct stat st;
6215c76ae52dSmrg
6216c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6217c2939121Smrg                  nonempty (path));
6218c2939121Smrg  if ((!path) || (!*path))
6219c2939121Smrg    return 0;
6220c76ae52dSmrg
6221c2939121Smrg  if ((stat (path, &st) >= 0)
6222c2939121Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6223c2939121Smrg    return 1;
6224c2939121Smrg  else
6225c2939121Smrg    return 0;
6226c2939121Smrg}
6227c76ae52dSmrg
6228c2939121Smrgint
6229c2939121Smrgmake_executable (const char *path)
6230c2939121Smrg{
6231c2939121Smrg  int rval = 0;
6232c2939121Smrg  struct stat st;
6233c76ae52dSmrg
6234c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6235c2939121Smrg                  nonempty (path));
6236c2939121Smrg  if ((!path) || (!*path))
6237c2939121Smrg    return 0;
6238c76ae52dSmrg
6239c2939121Smrg  if (stat (path, &st) >= 0)
6240c2939121Smrg    {
6241c2939121Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6242c2939121Smrg    }
6243c2939121Smrg  return rval;
6244c2939121Smrg}
6245c76ae52dSmrg
6246c2939121Smrg/* Searches for the full path of the wrapper.  Returns
6247c2939121Smrg   newly allocated full path name if found, NULL otherwise
6248c2939121Smrg   Does not chase symlinks, even on platforms that support them.
6249c2939121Smrg*/
6250c2939121Smrgchar *
6251c2939121Smrgfind_executable (const char *wrapper)
6252c2939121Smrg{
6253c2939121Smrg  int has_slash = 0;
6254c2939121Smrg  const char *p;
6255c2939121Smrg  const char *p_next;
6256c2939121Smrg  /* static buffer for getcwd */
6257c2939121Smrg  char tmp[LT_PATHMAX + 1];
62588292847cSmrg  size_t tmp_len;
6259c2939121Smrg  char *concat_name;
6260c76ae52dSmrg
6261c2939121Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6262c2939121Smrg                  nonempty (wrapper));
6263c76ae52dSmrg
6264c2939121Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6265c2939121Smrg    return NULL;
6266c76ae52dSmrg
6267c2939121Smrg  /* Absolute path? */
62688292847cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6269c2939121Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6270c2939121Smrg    {
6271c2939121Smrg      concat_name = xstrdup (wrapper);
6272c2939121Smrg      if (check_executable (concat_name))
6273c2939121Smrg	return concat_name;
6274c2939121Smrg      XFREE (concat_name);
6275c2939121Smrg    }
6276c2939121Smrg  else
6277c2939121Smrg    {
6278c2939121Smrg#endif
6279c2939121Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6280c2939121Smrg	{
6281c2939121Smrg	  concat_name = xstrdup (wrapper);
6282c2939121Smrg	  if (check_executable (concat_name))
6283c2939121Smrg	    return concat_name;
6284c2939121Smrg	  XFREE (concat_name);
6285c2939121Smrg	}
62868292847cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6287c2939121Smrg    }
6288c2939121Smrg#endif
6289c76ae52dSmrg
6290c2939121Smrg  for (p = wrapper; *p; p++)
6291c2939121Smrg    if (*p == '/')
6292c2939121Smrg      {
6293c2939121Smrg	has_slash = 1;
6294c2939121Smrg	break;
6295c2939121Smrg      }
6296c2939121Smrg  if (!has_slash)
6297c2939121Smrg    {
6298c2939121Smrg      /* no slashes; search PATH */
6299c2939121Smrg      const char *path = getenv ("PATH");
6300c2939121Smrg      if (path != NULL)
6301c2939121Smrg	{
6302c2939121Smrg	  for (p = path; *p; p = p_next)
6303c2939121Smrg	    {
6304c2939121Smrg	      const char *q;
6305c2939121Smrg	      size_t p_len;
6306c2939121Smrg	      for (q = p; *q; q++)
6307c2939121Smrg		if (IS_PATH_SEPARATOR (*q))
6308c2939121Smrg		  break;
63098292847cSmrg	      p_len = (size_t) (q - p);
6310c2939121Smrg	      p_next = (*q == '\0' ? q : q + 1);
6311c2939121Smrg	      if (p_len == 0)
6312c2939121Smrg		{
6313c2939121Smrg		  /* empty path: current directory */
6314c2939121Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6315c2939121Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6316c2939121Smrg                              nonnull (strerror (errno)));
6317c2939121Smrg		  tmp_len = strlen (tmp);
6318c2939121Smrg		  concat_name =
6319c2939121Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6320c2939121Smrg		  memcpy (concat_name, tmp, tmp_len);
6321c2939121Smrg		  concat_name[tmp_len] = '/';
6322c2939121Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6323c2939121Smrg		}
6324c2939121Smrg	      else
6325c2939121Smrg		{
6326c2939121Smrg		  concat_name =
6327c2939121Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6328c2939121Smrg		  memcpy (concat_name, p, p_len);
6329c2939121Smrg		  concat_name[p_len] = '/';
6330c2939121Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6331c2939121Smrg		}
6332c2939121Smrg	      if (check_executable (concat_name))
6333c2939121Smrg		return concat_name;
6334c2939121Smrg	      XFREE (concat_name);
6335c2939121Smrg	    }
6336c2939121Smrg	}
6337c2939121Smrg      /* not found in PATH; assume curdir */
6338c2939121Smrg    }
6339c2939121Smrg  /* Relative path | not found in path: prepend cwd */
6340c2939121Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6341c2939121Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6342c2939121Smrg              nonnull (strerror (errno)));
6343c2939121Smrg  tmp_len = strlen (tmp);
6344c2939121Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6345c2939121Smrg  memcpy (concat_name, tmp, tmp_len);
6346c2939121Smrg  concat_name[tmp_len] = '/';
6347c2939121Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6348c76ae52dSmrg
6349c2939121Smrg  if (check_executable (concat_name))
6350c2939121Smrg    return concat_name;
6351c2939121Smrg  XFREE (concat_name);
6352c2939121Smrg  return NULL;
6353c2939121Smrg}
6354c76ae52dSmrg
6355c2939121Smrgchar *
6356c2939121Smrgchase_symlinks (const char *pathspec)
6357c2939121Smrg{
6358c2939121Smrg#ifndef S_ISLNK
6359c2939121Smrg  return xstrdup (pathspec);
6360c2939121Smrg#else
6361c2939121Smrg  char buf[LT_PATHMAX];
6362c2939121Smrg  struct stat s;
6363c2939121Smrg  char *tmp_pathspec = xstrdup (pathspec);
6364c2939121Smrg  char *p;
6365c2939121Smrg  int has_symlinks = 0;
6366c2939121Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6367c2939121Smrg    {
6368c2939121Smrg      lt_debugprintf (__FILE__, __LINE__,
6369c2939121Smrg		      "checking path component for symlinks: %s\n",
6370c2939121Smrg		      tmp_pathspec);
6371c2939121Smrg      if (lstat (tmp_pathspec, &s) == 0)
6372c2939121Smrg	{
6373c2939121Smrg	  if (S_ISLNK (s.st_mode) != 0)
6374c2939121Smrg	    {
6375c2939121Smrg	      has_symlinks = 1;
6376c2939121Smrg	      break;
6377c2939121Smrg	    }
6378c76ae52dSmrg
6379c2939121Smrg	  /* search backwards for last DIR_SEPARATOR */
6380c2939121Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6381c2939121Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6382c2939121Smrg	    p--;
6383c2939121Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6384c2939121Smrg	    {
6385c2939121Smrg	      /* no more DIR_SEPARATORS left */
6386c2939121Smrg	      break;
6387c2939121Smrg	    }
6388c2939121Smrg	  *p = '\0';
6389c2939121Smrg	}
6390c2939121Smrg      else
6391c2939121Smrg	{
6392c2939121Smrg	  lt_fatal (__FILE__, __LINE__,
6393c2939121Smrg		    "error accessing file \"%s\": %s",
6394c2939121Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6395c2939121Smrg	}
6396c2939121Smrg    }
6397c2939121Smrg  XFREE (tmp_pathspec);
6398c76ae52dSmrg
6399c2939121Smrg  if (!has_symlinks)
6400c2939121Smrg    {
6401c2939121Smrg      return xstrdup (pathspec);
6402c2939121Smrg    }
6403c76ae52dSmrg
6404c2939121Smrg  tmp_pathspec = realpath (pathspec, buf);
6405c2939121Smrg  if (tmp_pathspec == 0)
6406c2939121Smrg    {
6407c2939121Smrg      lt_fatal (__FILE__, __LINE__,
6408c2939121Smrg		"could not follow symlinks for %s", pathspec);
6409c2939121Smrg    }
6410c2939121Smrg  return xstrdup (tmp_pathspec);
6411c2939121Smrg#endif
6412c2939121Smrg}
6413c76ae52dSmrg
6414c2939121Smrgchar *
6415c2939121Smrgstrendzap (char *str, const char *pat)
6416c2939121Smrg{
6417c2939121Smrg  size_t len, patlen;
6418c76ae52dSmrg
6419c2939121Smrg  assert (str != NULL);
6420c2939121Smrg  assert (pat != NULL);
6421c76ae52dSmrg
6422c2939121Smrg  len = strlen (str);
6423c2939121Smrg  patlen = strlen (pat);
6424c76ae52dSmrg
6425c2939121Smrg  if (patlen <= len)
6426c2939121Smrg    {
6427c2939121Smrg      str += len - patlen;
64288292847cSmrg      if (STREQ (str, pat))
6429c2939121Smrg	*str = '\0';
6430c2939121Smrg    }
6431c2939121Smrg  return str;
6432c2939121Smrg}
6433c76ae52dSmrg
6434c2939121Smrgvoid
6435c2939121Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6436c2939121Smrg{
6437c2939121Smrg  va_list args;
6438c2939121Smrg  if (lt_debug)
6439c2939121Smrg    {
6440c2939121Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6441c2939121Smrg      va_start (args, fmt);
6442c2939121Smrg      (void) vfprintf (stderr, fmt, args);
6443c2939121Smrg      va_end (args);
6444c2939121Smrg    }
6445c2939121Smrg}
6446c76ae52dSmrg
6447c2939121Smrgstatic void
6448c2939121Smrglt_error_core (int exit_status, const char *file,
6449c2939121Smrg	       int line, const char *mode,
6450c2939121Smrg	       const char *message, va_list ap)
6451c2939121Smrg{
6452c2939121Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6453c2939121Smrg  vfprintf (stderr, message, ap);
6454c2939121Smrg  fprintf (stderr, ".\n");
6455c76ae52dSmrg
6456c2939121Smrg  if (exit_status >= 0)
6457c2939121Smrg    exit (exit_status);
6458c2939121Smrg}
6459c76ae52dSmrg
6460c2939121Smrgvoid
6461c2939121Smrglt_fatal (const char *file, int line, const char *message, ...)
6462c2939121Smrg{
6463c2939121Smrg  va_list ap;
6464c2939121Smrg  va_start (ap, message);
6465c2939121Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6466c2939121Smrg  va_end (ap);
6467c2939121Smrg}
6468c76ae52dSmrg
6469c2939121Smrgstatic const char *
6470c2939121Smrgnonnull (const char *s)
6471c2939121Smrg{
6472c2939121Smrg  return s ? s : "(null)";
6473c2939121Smrg}
6474c76ae52dSmrg
6475c2939121Smrgstatic const char *
6476c2939121Smrgnonempty (const char *s)
6477c2939121Smrg{
6478c2939121Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
6479c2939121Smrg}
6480c76ae52dSmrg
6481c2939121Smrgvoid
6482c2939121Smrglt_setenv (const char *name, const char *value)
6483c2939121Smrg{
6484c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6485c2939121Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
6486c2939121Smrg                  nonnull (name), nonnull (value));
6487c2939121Smrg  {
6488c2939121Smrg#ifdef HAVE_SETENV
6489c2939121Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6490c2939121Smrg    char *str = xstrdup (value);
6491c2939121Smrg    setenv (name, str, 1);
6492c2939121Smrg#else
64938292847cSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6494c2939121Smrg    char *str = XMALLOC (char, len);
6495c2939121Smrg    sprintf (str, "%s=%s", name, value);
6496c2939121Smrg    if (putenv (str) != EXIT_SUCCESS)
6497c2939121Smrg      {
6498c2939121Smrg        XFREE (str);
6499c2939121Smrg      }
6500c2939121Smrg#endif
6501c2939121Smrg  }
6502c2939121Smrg}
6503c76ae52dSmrg
6504c2939121Smrgchar *
6505c2939121Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6506c2939121Smrg{
6507c2939121Smrg  char *new_value;
6508c2939121Smrg  if (orig_value && *orig_value)
6509c2939121Smrg    {
65108292847cSmrg      size_t orig_value_len = strlen (orig_value);
65118292847cSmrg      size_t add_len = strlen (add);
6512c2939121Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6513c2939121Smrg      if (to_end)
6514c2939121Smrg        {
6515c2939121Smrg          strcpy (new_value, orig_value);
6516c2939121Smrg          strcpy (new_value + orig_value_len, add);
6517c2939121Smrg        }
6518c2939121Smrg      else
6519c2939121Smrg        {
6520c2939121Smrg          strcpy (new_value, add);
6521c2939121Smrg          strcpy (new_value + add_len, orig_value);
6522c2939121Smrg        }
6523c2939121Smrg    }
6524c2939121Smrg  else
6525c2939121Smrg    {
6526c2939121Smrg      new_value = xstrdup (add);
6527c2939121Smrg    }
6528c2939121Smrg  return new_value;
6529c2939121Smrg}
6530c76ae52dSmrg
6531c2939121Smrgvoid
6532c2939121Smrglt_update_exe_path (const char *name, const char *value)
6533c2939121Smrg{
6534c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6535c2939121Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6536c2939121Smrg                  nonnull (name), nonnull (value));
6537c76ae52dSmrg
6538c2939121Smrg  if (name && *name && value && *value)
6539c2939121Smrg    {
6540c2939121Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6541c2939121Smrg      /* some systems can't cope with a ':'-terminated path #' */
65428292847cSmrg      size_t len = strlen (new_value);
65438292847cSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6544c2939121Smrg        {
65458292847cSmrg          new_value[--len] = '\0';
6546c2939121Smrg        }
6547c2939121Smrg      lt_setenv (name, new_value);
6548c2939121Smrg      XFREE (new_value);
6549c2939121Smrg    }
6550c2939121Smrg}
6551c76ae52dSmrg
6552c2939121Smrgvoid
6553c2939121Smrglt_update_lib_path (const char *name, const char *value)
6554c2939121Smrg{
6555c2939121Smrg  lt_debugprintf (__FILE__, __LINE__,
6556c2939121Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6557c2939121Smrg                  nonnull (name), nonnull (value));
6558c76ae52dSmrg
6559c2939121Smrg  if (name && *name && value && *value)
6560c2939121Smrg    {
6561c2939121Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6562c2939121Smrg      lt_setenv (name, new_value);
6563c2939121Smrg      XFREE (new_value);
6564c2939121Smrg    }
6565c2939121Smrg}
6566c76ae52dSmrg
6567c2939121SmrgEOF
6568c2939121Smrg	    case $host_os in
6569c2939121Smrg	      mingw*)
6570c2939121Smrg		cat <<"EOF"
6571c2939121Smrg
6572c2939121Smrg/* Prepares an argument vector before calling spawn().
6573c2939121Smrg   Note that spawn() does not by itself call the command interpreter
6574c2939121Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6575c2939121Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6576c2939121Smrg         GetVersionEx(&v);
6577c2939121Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6578c2939121Smrg      }) ? "cmd.exe" : "command.com").
6579c2939121Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6580c2939121Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6581c2939121Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6582c2939121Smrg   special way:
6583c2939121Smrg   - Space and tab are interpreted as delimiters. They are not treated as
6584c2939121Smrg     delimiters if they are surrounded by double quotes: "...".
6585c2939121Smrg   - Unescaped double quotes are removed from the input. Their only effect is
6586c2939121Smrg     that within double quotes, space and tab are treated like normal
6587c2939121Smrg     characters.
6588c2939121Smrg   - Backslashes not followed by double quotes are not special.
6589c2939121Smrg   - But 2*n+1 backslashes followed by a double quote become
6590c2939121Smrg     n backslashes followed by a double quote (n >= 0):
6591c2939121Smrg       \" -> "
6592c2939121Smrg       \\\" -> \"
6593c2939121Smrg       \\\\\" -> \\"
6594c2939121Smrg */
6595c2939121Smrg#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"
6596c2939121Smrg#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"
6597c2939121Smrgchar **
6598c2939121Smrgprepare_spawn (char **argv)
6599c2939121Smrg{
6600c2939121Smrg  size_t argc;
6601c2939121Smrg  char **new_argv;
6602c2939121Smrg  size_t i;
6603c76ae52dSmrg
6604c2939121Smrg  /* Count number of arguments.  */
6605c2939121Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6606c2939121Smrg    ;
6607c76ae52dSmrg
6608c2939121Smrg  /* Allocate new argument vector.  */
6609c2939121Smrg  new_argv = XMALLOC (char *, argc + 1);
6610c76ae52dSmrg
6611c2939121Smrg  /* Put quoted arguments into the new argument vector.  */
6612c2939121Smrg  for (i = 0; i < argc; i++)
6613c2939121Smrg    {
6614c2939121Smrg      const char *string = argv[i];
6615c2939121Smrg
6616c2939121Smrg      if (string[0] == '\0')
6617c2939121Smrg	new_argv[i] = xstrdup ("\"\"");
6618c2939121Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6619c2939121Smrg	{
6620c2939121Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6621c2939121Smrg	  size_t length;
6622c2939121Smrg	  unsigned int backslashes;
6623c2939121Smrg	  const char *s;
6624c2939121Smrg	  char *quoted_string;
6625c2939121Smrg	  char *p;
6626c2939121Smrg
6627c2939121Smrg	  length = 0;
6628c2939121Smrg	  backslashes = 0;
6629c2939121Smrg	  if (quote_around)
6630c2939121Smrg	    length++;
6631c2939121Smrg	  for (s = string; *s != '\0'; s++)
6632c2939121Smrg	    {
6633c2939121Smrg	      char c = *s;
6634c2939121Smrg	      if (c == '"')
6635c2939121Smrg		length += backslashes + 1;
6636c2939121Smrg	      length++;
6637c2939121Smrg	      if (c == '\\')
6638c2939121Smrg		backslashes++;
6639c2939121Smrg	      else
6640c2939121Smrg		backslashes = 0;
6641c2939121Smrg	    }
6642c2939121Smrg	  if (quote_around)
6643c2939121Smrg	    length += backslashes + 1;
6644c2939121Smrg
6645c2939121Smrg	  quoted_string = XMALLOC (char, length + 1);
6646c2939121Smrg
6647c2939121Smrg	  p = quoted_string;
6648c2939121Smrg	  backslashes = 0;
6649c2939121Smrg	  if (quote_around)
6650c2939121Smrg	    *p++ = '"';
6651c2939121Smrg	  for (s = string; *s != '\0'; s++)
6652c2939121Smrg	    {
6653c2939121Smrg	      char c = *s;
6654c2939121Smrg	      if (c == '"')
6655c2939121Smrg		{
6656c2939121Smrg		  unsigned int j;
6657c2939121Smrg		  for (j = backslashes + 1; j > 0; j--)
6658c2939121Smrg		    *p++ = '\\';
6659c2939121Smrg		}
6660c2939121Smrg	      *p++ = c;
6661c2939121Smrg	      if (c == '\\')
6662c2939121Smrg		backslashes++;
6663c2939121Smrg	      else
6664c2939121Smrg		backslashes = 0;
6665c2939121Smrg	    }
6666c2939121Smrg	  if (quote_around)
6667c2939121Smrg	    {
6668c2939121Smrg	      unsigned int j;
6669c2939121Smrg	      for (j = backslashes; j > 0; j--)
6670c2939121Smrg		*p++ = '\\';
6671c2939121Smrg	      *p++ = '"';
6672c2939121Smrg	    }
6673c2939121Smrg	  *p = '\0';
6674c76ae52dSmrg
6675c2939121Smrg	  new_argv[i] = quoted_string;
6676c2939121Smrg	}
6677c2939121Smrg      else
6678c2939121Smrg	new_argv[i] = (char *) string;
6679c2939121Smrg    }
6680c2939121Smrg  new_argv[argc] = NULL;
6681c76ae52dSmrg
6682c2939121Smrg  return new_argv;
6683c2939121Smrg}
6684c2939121SmrgEOF
6685c76ae52dSmrg		;;
6686c2939121Smrg	    esac
6687c76ae52dSmrg
6688c2939121Smrg            cat <<"EOF"
6689c2939121Smrgvoid lt_dump_script (FILE* f)
6690c2939121Smrg{
6691c2939121SmrgEOF
6692c2939121Smrg	    func_emit_wrapper yes |
66932836776bSmrg	      $SED -n -e '
66942836776bSmrgs/^\(.\{79\}\)\(..*\)/\1\
66952836776bSmrg\2/
66962836776bSmrgh
66972836776bSmrgs/\([\\"]\)/\\\1/g
66982836776bSmrgs/$/\\n/
66992836776bSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
67002836776bSmrgg
67012836776bSmrgD'
6702c2939121Smrg            cat <<"EOF"
6703c2939121Smrg}
6704c2939121SmrgEOF
6705c2939121Smrg}
6706c2939121Smrg# end: func_emit_cwrapperexe_src
6707c76ae52dSmrg
6708c2939121Smrg# func_win32_import_lib_p ARG
6709c2939121Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6710c2939121Smrgfunc_win32_import_lib_p ()
6711c2939121Smrg{
67128292847cSmrg    $debug_cmd
67138292847cSmrg
6714c2939121Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6715c2939121Smrg    *import*) : ;;
6716c2939121Smrg    *) false ;;
6717c2939121Smrg    esac
6718c2939121Smrg}
6719c76ae52dSmrg
67208292847cSmrg# func_suncc_cstd_abi
67218292847cSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
67228292847cSmrg# Several compiler flags select an ABI that is incompatible with the
67238292847cSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
67248292847cSmrgfunc_suncc_cstd_abi ()
67258292847cSmrg{
67268292847cSmrg    $debug_cmd
67278292847cSmrg
67288292847cSmrg    case " $compile_command " in
67298292847cSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
67308292847cSmrg      suncc_use_cstd_abi=no
67318292847cSmrg      ;;
67328292847cSmrg    *)
67338292847cSmrg      suncc_use_cstd_abi=yes
67348292847cSmrg      ;;
67358292847cSmrg    esac
67368292847cSmrg}
67378292847cSmrg
6738c2939121Smrg# func_mode_link arg...
6739c2939121Smrgfunc_mode_link ()
6740c2939121Smrg{
67418292847cSmrg    $debug_cmd
67428292847cSmrg
6743c2939121Smrg    case $host in
6744c2939121Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6745c2939121Smrg      # It is impossible to link a dll without this setting, and
6746c2939121Smrg      # we shouldn't force the makefile maintainer to figure out
67478292847cSmrg      # what system we are compiling for in order to pass an extra
6748c2939121Smrg      # flag for every libtool invocation.
6749c2939121Smrg      # allow_undefined=no
6750c76ae52dSmrg
6751c2939121Smrg      # FIXME: Unfortunately, there are problems with the above when trying
67528292847cSmrg      # to make a dll that has undefined symbols, in which case not
6753c2939121Smrg      # even a static library is built.  For now, we need to specify
6754c2939121Smrg      # -no-undefined on the libtool link line when we can be certain
6755c2939121Smrg      # that all symbols are satisfied, otherwise we get a static library.
6756c2939121Smrg      allow_undefined=yes
6757c2939121Smrg      ;;
6758c2939121Smrg    *)
6759c2939121Smrg      allow_undefined=yes
6760c2939121Smrg      ;;
6761c2939121Smrg    esac
6762c2939121Smrg    libtool_args=$nonopt
6763c2939121Smrg    base_compile="$nonopt $@"
6764c2939121Smrg    compile_command=$nonopt
6765c2939121Smrg    finalize_command=$nonopt
6766c76ae52dSmrg
6767c2939121Smrg    compile_rpath=
6768c2939121Smrg    finalize_rpath=
6769c2939121Smrg    compile_shlibpath=
6770c2939121Smrg    finalize_shlibpath=
6771c2939121Smrg    convenience=
6772c2939121Smrg    old_convenience=
6773c2939121Smrg    deplibs=
6774c2939121Smrg    old_deplibs=
6775c2939121Smrg    compiler_flags=
6776c2939121Smrg    linker_flags=
6777c2939121Smrg    dllsearchpath=
6778c2939121Smrg    lib_search_path=`pwd`
6779c2939121Smrg    inst_prefix_dir=
6780c2939121Smrg    new_inherited_linker_flags=
6781c76ae52dSmrg
6782c2939121Smrg    avoid_version=no
6783c2939121Smrg    bindir=
6784c2939121Smrg    dlfiles=
6785c2939121Smrg    dlprefiles=
6786c2939121Smrg    dlself=no
6787c2939121Smrg    export_dynamic=no
6788c2939121Smrg    export_symbols=
6789c2939121Smrg    export_symbols_regex=
6790c2939121Smrg    generated=
6791c2939121Smrg    libobjs=
6792c2939121Smrg    ltlibs=
6793c2939121Smrg    module=no
6794c2939121Smrg    no_install=no
6795c2939121Smrg    objs=
67968292847cSmrg    os2dllname=
6797c2939121Smrg    non_pic_objects=
6798c2939121Smrg    precious_files_regex=
6799c2939121Smrg    prefer_static_libs=no
68008292847cSmrg    preload=false
6801c2939121Smrg    prev=
6802c2939121Smrg    prevarg=
6803c2939121Smrg    release=
6804c2939121Smrg    rpath=
6805c2939121Smrg    xrpath=
6806c2939121Smrg    perm_rpath=
6807c2939121Smrg    temp_rpath=
6808c2939121Smrg    thread_safe=no
6809c2939121Smrg    vinfo=
6810c2939121Smrg    vinfo_number=no
6811c2939121Smrg    weak_libs=
68128292847cSmrg    single_module=$wl-single_module
6813c2939121Smrg    func_infer_tag $base_compile
6814c76ae52dSmrg
6815c2939121Smrg    # We need to know -static, to get the right output filenames.
6816c2939121Smrg    for arg
6817c2939121Smrg    do
6818c2939121Smrg      case $arg in
6819c2939121Smrg      -shared)
68208292847cSmrg	test yes != "$build_libtool_libs" \
68218292847cSmrg	  && func_fatal_configuration "cannot build a shared library"
6822c2939121Smrg	build_old_libs=no
6823c2939121Smrg	break
6824c2939121Smrg	;;
6825c2939121Smrg      -all-static | -static | -static-libtool-libs)
6826c2939121Smrg	case $arg in
6827c2939121Smrg	-all-static)
68288292847cSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6829c2939121Smrg	    func_warning "complete static linking is impossible in this configuration"
6830c2939121Smrg	  fi
6831c2939121Smrg	  if test -n "$link_static_flag"; then
6832c2939121Smrg	    dlopen_self=$dlopen_self_static
6833c2939121Smrg	  fi
6834c2939121Smrg	  prefer_static_libs=yes
6835c2939121Smrg	  ;;
6836c2939121Smrg	-static)
6837c2939121Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6838c2939121Smrg	    dlopen_self=$dlopen_self_static
6839c2939121Smrg	  fi
6840c2939121Smrg	  prefer_static_libs=built
6841c2939121Smrg	  ;;
6842c2939121Smrg	-static-libtool-libs)
6843c2939121Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6844c2939121Smrg	    dlopen_self=$dlopen_self_static
6845c2939121Smrg	  fi
6846c2939121Smrg	  prefer_static_libs=yes
6847c2939121Smrg	  ;;
6848c2939121Smrg	esac
6849c2939121Smrg	build_libtool_libs=no
6850c2939121Smrg	build_old_libs=yes
6851c2939121Smrg	break
6852c2939121Smrg	;;
6853c2939121Smrg      esac
6854c2939121Smrg    done
6855c76ae52dSmrg
6856c2939121Smrg    # See if our shared archives depend on static archives.
6857c2939121Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6858c76ae52dSmrg
6859c2939121Smrg    # Go through the arguments, transforming them on the way.
6860c2939121Smrg    while test "$#" -gt 0; do
68618292847cSmrg      arg=$1
6862c2939121Smrg      shift
686325420f97Smrg      func_quote_arg pretty,unquoted "$arg"
686425420f97Smrg      qarg=$func_quote_arg_unquoted_result
686525420f97Smrg      func_append libtool_args " $func_quote_arg_result"
6866c76ae52dSmrg
6867c2939121Smrg      # If the previous option needs an argument, assign it.
6868c2939121Smrg      if test -n "$prev"; then
6869c2939121Smrg	case $prev in
6870c2939121Smrg	output)
6871c2939121Smrg	  func_append compile_command " @OUTPUT@"
6872c2939121Smrg	  func_append finalize_command " @OUTPUT@"
6873c2939121Smrg	  ;;
6874c2939121Smrg	esac
6875c76ae52dSmrg
6876c2939121Smrg	case $prev in
6877c2939121Smrg	bindir)
68788292847cSmrg	  bindir=$arg
6879c2939121Smrg	  prev=
6880c2939121Smrg	  continue
6881c2939121Smrg	  ;;
6882c2939121Smrg	dlfiles|dlprefiles)
68838292847cSmrg	  $preload || {
6884c2939121Smrg	    # Add the symbol object into the linking commands.
6885c2939121Smrg	    func_append compile_command " @SYMFILE@"
6886c2939121Smrg	    func_append finalize_command " @SYMFILE@"
68878292847cSmrg	    preload=:
68888292847cSmrg	  }
6889c2939121Smrg	  case $arg in
6890c2939121Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6891c2939121Smrg	  force)
68928292847cSmrg	    if test no = "$dlself"; then
6893c2939121Smrg	      dlself=needless
6894c2939121Smrg	      export_dynamic=yes
6895c76ae52dSmrg	    fi
6896c2939121Smrg	    prev=
6897c2939121Smrg	    continue
6898c2939121Smrg	    ;;
6899c2939121Smrg	  self)
69008292847cSmrg	    if test dlprefiles = "$prev"; then
6901c2939121Smrg	      dlself=yes
69028292847cSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6903c2939121Smrg	      dlself=yes
6904c76ae52dSmrg	    else
6905c2939121Smrg	      dlself=needless
6906c2939121Smrg	      export_dynamic=yes
6907c76ae52dSmrg	    fi
6908c2939121Smrg	    prev=
6909c2939121Smrg	    continue
6910c2939121Smrg	    ;;
6911c2939121Smrg	  *)
69128292847cSmrg	    if test dlfiles = "$prev"; then
69132836776bSmrg	      func_append dlfiles " $arg"
6914c76ae52dSmrg	    else
69152836776bSmrg	      func_append dlprefiles " $arg"
6916c76ae52dSmrg	    fi
6917c2939121Smrg	    prev=
6918c2939121Smrg	    continue
6919c2939121Smrg	    ;;
6920c2939121Smrg	  esac
6921c2939121Smrg	  ;;
6922c2939121Smrg	expsyms)
69238292847cSmrg	  export_symbols=$arg
6924c2939121Smrg	  test -f "$arg" \
69258292847cSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6926c2939121Smrg	  prev=
6927c2939121Smrg	  continue
6928c2939121Smrg	  ;;
6929c2939121Smrg	expsyms_regex)
69308292847cSmrg	  export_symbols_regex=$arg
6931c2939121Smrg	  prev=
6932c2939121Smrg	  continue
6933c2939121Smrg	  ;;
6934c2939121Smrg	framework)
6935c76ae52dSmrg	  case $host in
6936c2939121Smrg	    *-*-darwin*)
6937c2939121Smrg	      case "$deplibs " in
6938c2939121Smrg		*" $qarg.ltframework "*) ;;
69392836776bSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6940c2939121Smrg		   ;;
6941c2939121Smrg	      esac
6942c2939121Smrg	      ;;
6943c76ae52dSmrg	  esac
6944c2939121Smrg	  prev=
6945c2939121Smrg	  continue
6946c76ae52dSmrg	  ;;
6947c2939121Smrg	inst_prefix)
69488292847cSmrg	  inst_prefix_dir=$arg
69498292847cSmrg	  prev=
69508292847cSmrg	  continue
69518292847cSmrg	  ;;
69528292847cSmrg	mllvm)
69538292847cSmrg	  # Clang does not use LLVM to link, so we can simply discard any
69548292847cSmrg	  # '-mllvm $arg' options when doing the link step.
6955c2939121Smrg	  prev=
6956c2939121Smrg	  continue
6957c76ae52dSmrg	  ;;
6958c2939121Smrg	objectlist)
6959c2939121Smrg	  if test -f "$arg"; then
6960c2939121Smrg	    save_arg=$arg
6961c2939121Smrg	    moreargs=
6962c2939121Smrg	    for fil in `cat "$save_arg"`
6963c2939121Smrg	    do
69642836776bSmrg#	      func_append moreargs " $fil"
6965c2939121Smrg	      arg=$fil
6966c2939121Smrg	      # A libtool-controlled object.
6967c76ae52dSmrg
6968c2939121Smrg	      # Check to see that this really is a libtool object.
6969c2939121Smrg	      if func_lalib_unsafe_p "$arg"; then
6970c2939121Smrg		pic_object=
6971c2939121Smrg		non_pic_object=
6972c76ae52dSmrg
6973c2939121Smrg		# Read the .lo file
6974c2939121Smrg		func_source "$arg"
6975c76ae52dSmrg
6976c2939121Smrg		if test -z "$pic_object" ||
6977c2939121Smrg		   test -z "$non_pic_object" ||
69788292847cSmrg		   test none = "$pic_object" &&
69798292847cSmrg		   test none = "$non_pic_object"; then
69808292847cSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6981c2939121Smrg		fi
6982c76ae52dSmrg
6983c2939121Smrg		# Extract subdirectory from the argument.
6984c2939121Smrg		func_dirname "$arg" "/" ""
69858292847cSmrg		xdir=$func_dirname_result
6986c76ae52dSmrg
69878292847cSmrg		if test none != "$pic_object"; then
6988c2939121Smrg		  # Prepend the subdirectory the object is found in.
69898292847cSmrg		  pic_object=$xdir$pic_object
6990c76ae52dSmrg
69918292847cSmrg		  if test dlfiles = "$prev"; then
69928292847cSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
69932836776bSmrg		      func_append dlfiles " $pic_object"
6994c2939121Smrg		      prev=
6995c2939121Smrg		      continue
6996c2939121Smrg		    else
6997c2939121Smrg		      # If libtool objects are unsupported, then we need to preload.
6998c2939121Smrg		      prev=dlprefiles
6999c2939121Smrg		    fi
7000c2939121Smrg		  fi
7001c76ae52dSmrg
7002c2939121Smrg		  # CHECK ME:  I think I busted this.  -Ossama
70038292847cSmrg		  if test dlprefiles = "$prev"; then
7004c2939121Smrg		    # Preload the old-style object.
70052836776bSmrg		    func_append dlprefiles " $pic_object"
7006c2939121Smrg		    prev=
7007c2939121Smrg		  fi
7008c76ae52dSmrg
7009c2939121Smrg		  # A PIC object.
7010c2939121Smrg		  func_append libobjs " $pic_object"
70118292847cSmrg		  arg=$pic_object
7012c2939121Smrg		fi
7013c76ae52dSmrg
7014c2939121Smrg		# Non-PIC object.
70158292847cSmrg		if test none != "$non_pic_object"; then
7016c2939121Smrg		  # Prepend the subdirectory the object is found in.
70178292847cSmrg		  non_pic_object=$xdir$non_pic_object
7018c76ae52dSmrg
7019c2939121Smrg		  # A standard non-PIC object
7020c2939121Smrg		  func_append non_pic_objects " $non_pic_object"
70218292847cSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
70228292847cSmrg		    arg=$non_pic_object
7023c2939121Smrg		  fi
7024c2939121Smrg		else
7025c2939121Smrg		  # If the PIC object exists, use it instead.
7026c2939121Smrg		  # $xdir was prepended to $pic_object above.
70278292847cSmrg		  non_pic_object=$pic_object
7028c2939121Smrg		  func_append non_pic_objects " $non_pic_object"
7029c2939121Smrg		fi
7030c2939121Smrg	      else
7031c2939121Smrg		# Only an error if not doing a dry-run.
7032c2939121Smrg		if $opt_dry_run; then
7033c2939121Smrg		  # Extract subdirectory from the argument.
7034c2939121Smrg		  func_dirname "$arg" "/" ""
70358292847cSmrg		  xdir=$func_dirname_result
7036c2939121Smrg
7037c2939121Smrg		  func_lo2o "$arg"
7038c2939121Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7039c2939121Smrg		  non_pic_object=$xdir$func_lo2o_result
7040c2939121Smrg		  func_append libobjs " $pic_object"
7041c2939121Smrg		  func_append non_pic_objects " $non_pic_object"
7042c2939121Smrg	        else
70438292847cSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7044c2939121Smrg		fi
7045c2939121Smrg	      fi
7046c2939121Smrg	    done
7047c76ae52dSmrg	  else
70488292847cSmrg	    func_fatal_error "link input file '$arg' does not exist"
7049c76ae52dSmrg	  fi
7050c2939121Smrg	  arg=$save_arg
7051c2939121Smrg	  prev=
7052c2939121Smrg	  continue
7053c2939121Smrg	  ;;
70548292847cSmrg	os2dllname)
70558292847cSmrg	  os2dllname=$arg
70568292847cSmrg	  prev=
70578292847cSmrg	  continue
70588292847cSmrg	  ;;
7059c2939121Smrg	precious_regex)
70608292847cSmrg	  precious_files_regex=$arg
7061c2939121Smrg	  prev=
7062c2939121Smrg	  continue
7063c2939121Smrg	  ;;
7064c2939121Smrg	release)
70658292847cSmrg	  release=-$arg
7066c2939121Smrg	  prev=
7067c2939121Smrg	  continue
7068c2939121Smrg	  ;;
7069c2939121Smrg	rpath | xrpath)
7070c2939121Smrg	  # We need an absolute path.
7071c2939121Smrg	  case $arg in
7072c2939121Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7073c2939121Smrg	  *)
7074c2939121Smrg	    func_fatal_error "only absolute run-paths are allowed"
7075c2939121Smrg	    ;;
7076c2939121Smrg	  esac
70778292847cSmrg	  if test rpath = "$prev"; then
7078c2939121Smrg	    case "$rpath " in
7079c2939121Smrg	    *" $arg "*) ;;
70802836776bSmrg	    *) func_append rpath " $arg" ;;
7081c2939121Smrg	    esac
7082c76ae52dSmrg	  else
7083c2939121Smrg	    case "$xrpath " in
7084c2939121Smrg	    *" $arg "*) ;;
70852836776bSmrg	    *) func_append xrpath " $arg" ;;
7086c2939121Smrg	    esac
7087c76ae52dSmrg	  fi
7088c2939121Smrg	  prev=
7089c2939121Smrg	  continue
7090c2939121Smrg	  ;;
7091c2939121Smrg	shrext)
70928292847cSmrg	  shrext_cmds=$arg
7093c2939121Smrg	  prev=
7094c2939121Smrg	  continue
7095c2939121Smrg	  ;;
7096c2939121Smrg	weak)
70972836776bSmrg	  func_append weak_libs " $arg"
7098c2939121Smrg	  prev=
7099c2939121Smrg	  continue
7100c2939121Smrg	  ;;
710125420f97Smrg	xassembler)
710225420f97Smrg	  func_append compiler_flags " -Xassembler $qarg"
710325420f97Smrg	  prev=
710425420f97Smrg	  func_append compile_command " -Xassembler $qarg"
710525420f97Smrg	  func_append finalize_command " -Xassembler $qarg"
710625420f97Smrg	  continue
710725420f97Smrg	  ;;
7108c2939121Smrg	xcclinker)
71092836776bSmrg	  func_append linker_flags " $qarg"
71102836776bSmrg	  func_append compiler_flags " $qarg"
7111c2939121Smrg	  prev=
7112c2939121Smrg	  func_append compile_command " $qarg"
7113c2939121Smrg	  func_append finalize_command " $qarg"
7114c2939121Smrg	  continue
7115c2939121Smrg	  ;;
7116c2939121Smrg	xcompiler)
71172836776bSmrg	  func_append compiler_flags " $qarg"
7118c2939121Smrg	  prev=
7119c2939121Smrg	  func_append compile_command " $qarg"
7120c2939121Smrg	  func_append finalize_command " $qarg"
7121c2939121Smrg	  continue
7122c2939121Smrg	  ;;
7123c2939121Smrg	xlinker)
71242836776bSmrg	  func_append linker_flags " $qarg"
71252836776bSmrg	  func_append compiler_flags " $wl$qarg"
7126c2939121Smrg	  prev=
7127c2939121Smrg	  func_append compile_command " $wl$qarg"
7128c2939121Smrg	  func_append finalize_command " $wl$qarg"
7129c2939121Smrg	  continue
7130c2939121Smrg	  ;;
7131c2939121Smrg	*)
7132c2939121Smrg	  eval "$prev=\"\$arg\""
7133c2939121Smrg	  prev=
7134c2939121Smrg	  continue
7135c2939121Smrg	  ;;
7136c76ae52dSmrg	esac
7137c2939121Smrg      fi # test -n "$prev"
7138c76ae52dSmrg
71398292847cSmrg      prevarg=$arg
7140c76ae52dSmrg
7141c2939121Smrg      case $arg in
7142c2939121Smrg      -all-static)
7143c2939121Smrg	if test -n "$link_static_flag"; then
7144c2939121Smrg	  # See comment for -static flag below, for more details.
7145c2939121Smrg	  func_append compile_command " $link_static_flag"
7146c2939121Smrg	  func_append finalize_command " $link_static_flag"
7147c2939121Smrg	fi
7148c2939121Smrg	continue
7149c2939121Smrg	;;
7150c76ae52dSmrg
7151c2939121Smrg      -allow-undefined)
7152c2939121Smrg	# FIXME: remove this flag sometime in the future.
71538292847cSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7154c2939121Smrg	;;
7155c76ae52dSmrg
7156c2939121Smrg      -avoid-version)
7157c2939121Smrg	avoid_version=yes
7158c2939121Smrg	continue
7159c2939121Smrg	;;
7160c76ae52dSmrg
7161c2939121Smrg      -bindir)
7162c2939121Smrg	prev=bindir
7163c2939121Smrg	continue
7164c2939121Smrg	;;
7165c76ae52dSmrg
7166c2939121Smrg      -dlopen)
7167c2939121Smrg	prev=dlfiles
7168c2939121Smrg	continue
7169c2939121Smrg	;;
7170c76ae52dSmrg
7171c2939121Smrg      -dlpreopen)
7172c2939121Smrg	prev=dlprefiles
7173c2939121Smrg	continue
7174c2939121Smrg	;;
7175c76ae52dSmrg
7176c2939121Smrg      -export-dynamic)
7177c2939121Smrg	export_dynamic=yes
7178c2939121Smrg	continue
7179c2939121Smrg	;;
7180c76ae52dSmrg
7181c2939121Smrg      -export-symbols | -export-symbols-regex)
7182c2939121Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7183c2939121Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7184c2939121Smrg	fi
71858292847cSmrg	if test X-export-symbols = "X$arg"; then
7186c2939121Smrg	  prev=expsyms
7187c2939121Smrg	else
7188c2939121Smrg	  prev=expsyms_regex
7189c2939121Smrg	fi
7190c2939121Smrg	continue
7191c2939121Smrg	;;
7192c76ae52dSmrg
7193c2939121Smrg      -framework)
7194c2939121Smrg	prev=framework
7195c2939121Smrg	continue
7196c2939121Smrg	;;
7197c76ae52dSmrg
7198c2939121Smrg      -inst-prefix-dir)
7199c2939121Smrg	prev=inst_prefix
7200c2939121Smrg	continue
7201c2939121Smrg	;;
7202c76ae52dSmrg
7203c2939121Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7204c2939121Smrg      # so, if we see these flags be careful not to treat them like -L
7205c2939121Smrg      -L[A-Z][A-Z]*:*)
7206c2939121Smrg	case $with_gcc/$host in
7207c2939121Smrg	no/*-*-irix* | /*-*-irix*)
7208c2939121Smrg	  func_append compile_command " $arg"
7209c2939121Smrg	  func_append finalize_command " $arg"
7210c2939121Smrg	  ;;
7211c2939121Smrg	esac
7212c2939121Smrg	continue
7213c2939121Smrg	;;
7214c76ae52dSmrg
7215c2939121Smrg      -L*)
72162836776bSmrg	func_stripname "-L" '' "$arg"
72172836776bSmrg	if test -z "$func_stripname_result"; then
7218c2939121Smrg	  if test "$#" -gt 0; then
72198292847cSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7220c2939121Smrg	  else
72218292847cSmrg	    func_fatal_error "need path for '-L' option"
7222c2939121Smrg	  fi
7223c2939121Smrg	fi
72242836776bSmrg	func_resolve_sysroot "$func_stripname_result"
72252836776bSmrg	dir=$func_resolve_sysroot_result
7226c2939121Smrg	# We need an absolute path.
7227c2939121Smrg	case $dir in
7228c2939121Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7229c2939121Smrg	*)
7230c2939121Smrg	  absdir=`cd "$dir" && pwd`
7231c2939121Smrg	  test -z "$absdir" && \
72328292847cSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
72338292847cSmrg	  dir=$absdir
7234c2939121Smrg	  ;;
7235c2939121Smrg	esac
7236c2939121Smrg	case "$deplibs " in
72372836776bSmrg	*" -L$dir "* | *" $arg "*)
72382836776bSmrg	  # Will only happen for absolute or sysroot arguments
72392836776bSmrg	  ;;
7240c2939121Smrg	*)
72412836776bSmrg	  # Preserve sysroot, but never include relative directories
72422836776bSmrg	  case $dir in
72432836776bSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
72442836776bSmrg	    *) func_append deplibs " -L$dir" ;;
72452836776bSmrg	  esac
72462836776bSmrg	  func_append lib_search_path " $dir"
7247c2939121Smrg	  ;;
7248c2939121Smrg	esac
7249c2939121Smrg	case $host in
7250c2939121Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7251c2939121Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7252c2939121Smrg	  case :$dllsearchpath: in
7253c2939121Smrg	  *":$dir:"*) ;;
7254c2939121Smrg	  ::) dllsearchpath=$dir;;
72552836776bSmrg	  *) func_append dllsearchpath ":$dir";;
7256c2939121Smrg	  esac
7257c2939121Smrg	  case :$dllsearchpath: in
7258c2939121Smrg	  *":$testbindir:"*) ;;
7259c2939121Smrg	  ::) dllsearchpath=$testbindir;;
72602836776bSmrg	  *) func_append dllsearchpath ":$testbindir";;
7261c2939121Smrg	  esac
7262c2939121Smrg	  ;;
7263c2939121Smrg	esac
7264c2939121Smrg	continue
7265c2939121Smrg	;;
7266c76ae52dSmrg
7267c2939121Smrg      -l*)
72688292847cSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7269c2939121Smrg	  case $host in
7270c2939121Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7271c2939121Smrg	    # These systems don't actually have a C or math library (as such)
7272c2939121Smrg	    continue
7273c2939121Smrg	    ;;
7274c2939121Smrg	  *-*-os2*)
7275c2939121Smrg	    # These systems don't actually have a C library (as such)
72768292847cSmrg	    test X-lc = "X$arg" && continue
7277c2939121Smrg	    ;;
727825420f97Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7279c2939121Smrg	    # Do not include libc due to us having libc/libc_r.
72808292847cSmrg	    test X-lc = "X$arg" && continue
7281c2939121Smrg	    ;;
7282c2939121Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7283c2939121Smrg	    # Rhapsody C and math libraries are in the System framework
72842836776bSmrg	    func_append deplibs " System.ltframework"
7285c2939121Smrg	    continue
7286c2939121Smrg	    ;;
7287c2939121Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7288c2939121Smrg	    # Causes problems with __ctype
72898292847cSmrg	    test X-lc = "X$arg" && continue
7290c2939121Smrg	    ;;
7291c2939121Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7292c2939121Smrg	    # Compiler inserts libc in the correct place for threads to work
72938292847cSmrg	    test X-lc = "X$arg" && continue
7294c2939121Smrg	    ;;
7295c2939121Smrg	  esac
72968292847cSmrg	elif test X-lc_r = "X$arg"; then
7297c2939121Smrg	 case $host in
729825420f97Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7299c2939121Smrg	   # Do not include libc_r directly, use -pthread flag.
7300c2939121Smrg	   continue
7301c2939121Smrg	   ;;
7302c2939121Smrg	 esac
7303c2939121Smrg	fi
73042836776bSmrg	func_append deplibs " $arg"
7305c2939121Smrg	continue
7306c2939121Smrg	;;
7307c76ae52dSmrg
73088292847cSmrg      -mllvm)
73098292847cSmrg	prev=mllvm
73108292847cSmrg	continue
73118292847cSmrg	;;
73128292847cSmrg
7313c2939121Smrg      -module)
7314c2939121Smrg	module=yes
7315c2939121Smrg	continue
7316c2939121Smrg	;;
7317c76ae52dSmrg
7318c2939121Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7319c2939121Smrg      # classes, name mangling, and exception handling.
7320c2939121Smrg      # Darwin uses the -arch flag to determine output architecture.
73212836776bSmrg      -model|-arch|-isysroot|--sysroot)
73222836776bSmrg	func_append compiler_flags " $arg"
7323c2939121Smrg	func_append compile_command " $arg"
7324c2939121Smrg	func_append finalize_command " $arg"
7325c2939121Smrg	prev=xcompiler
7326c2939121Smrg	continue
7327c2939121Smrg	;;
732825420f97Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
732925420f97Smrg     -pthread)
733025420f97Smrg	case $host in
733125420f97Smrg	  *solaris2*) ;;
733225420f97Smrg	  *)
733325420f97Smrg	    case "$new_inherited_linker_flags " in
733425420f97Smrg	        *" $arg "*) ;;
733525420f97Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
733625420f97Smrg	    esac
733725420f97Smrg	  ;;
733825420f97Smrg	esac
733925420f97Smrg	continue
734025420f97Smrg	;;
734125420f97Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
73422836776bSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
73432836776bSmrg	func_append compiler_flags " $arg"
7344c2939121Smrg	func_append compile_command " $arg"
7345c2939121Smrg	func_append finalize_command " $arg"
7346c2939121Smrg	case "$new_inherited_linker_flags " in
7347c2939121Smrg	    *" $arg "*) ;;
73482836776bSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7349c2939121Smrg	esac
7350c2939121Smrg	continue
7351c2939121Smrg	;;
7352c76ae52dSmrg
7353c2939121Smrg      -multi_module)
73548292847cSmrg	single_module=$wl-multi_module
7355c2939121Smrg	continue
7356c2939121Smrg	;;
7357c76ae52dSmrg
7358c2939121Smrg      -no-fast-install)
7359c2939121Smrg	fast_install=no
7360c2939121Smrg	continue
7361c2939121Smrg	;;
7362c76ae52dSmrg
7363c2939121Smrg      -no-install)
7364c2939121Smrg	case $host in
7365c2939121Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7366c2939121Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7367c2939121Smrg	  # and Darwin in order for the loader to find any dlls it needs.
73688292847cSmrg	  func_warning "'-no-install' is ignored for $host"
73698292847cSmrg	  func_warning "assuming '-no-fast-install' instead"
7370c2939121Smrg	  fast_install=no
7371c2939121Smrg	  ;;
7372c2939121Smrg	*) no_install=yes ;;
7373c2939121Smrg	esac
7374c2939121Smrg	continue
7375c2939121Smrg	;;
7376c76ae52dSmrg
7377c2939121Smrg      -no-undefined)
7378c2939121Smrg	allow_undefined=no
7379c2939121Smrg	continue
7380c2939121Smrg	;;
7381c76ae52dSmrg
7382c2939121Smrg      -objectlist)
7383c2939121Smrg	prev=objectlist
7384c2939121Smrg	continue
7385c2939121Smrg	;;
7386c76ae52dSmrg
73878292847cSmrg      -os2dllname)
73888292847cSmrg	prev=os2dllname
73898292847cSmrg	continue
73908292847cSmrg	;;
73918292847cSmrg
7392c2939121Smrg      -o) prev=output ;;
7393c76ae52dSmrg
7394c2939121Smrg      -precious-files-regex)
7395c2939121Smrg	prev=precious_regex
7396c2939121Smrg	continue
7397c2939121Smrg	;;
7398c76ae52dSmrg
7399c2939121Smrg      -release)
7400c2939121Smrg	prev=release
7401c2939121Smrg	continue
7402c2939121Smrg	;;
7403c76ae52dSmrg
7404c2939121Smrg      -rpath)
7405c2939121Smrg	prev=rpath
7406c2939121Smrg	continue
7407c2939121Smrg	;;
7408c76ae52dSmrg
7409c2939121Smrg      -R)
7410c2939121Smrg	prev=xrpath
7411c2939121Smrg	continue
7412c2939121Smrg	;;
7413c76ae52dSmrg
7414c2939121Smrg      -R*)
7415c2939121Smrg	func_stripname '-R' '' "$arg"
7416c2939121Smrg	dir=$func_stripname_result
7417c2939121Smrg	# We need an absolute path.
7418c2939121Smrg	case $dir in
7419c2939121Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
74202836776bSmrg	=*)
74212836776bSmrg	  func_stripname '=' '' "$dir"
74222836776bSmrg	  dir=$lt_sysroot$func_stripname_result
74232836776bSmrg	  ;;
7424c2939121Smrg	*)
7425c2939121Smrg	  func_fatal_error "only absolute run-paths are allowed"
7426c2939121Smrg	  ;;
7427c2939121Smrg	esac
7428c2939121Smrg	case "$xrpath " in
7429c2939121Smrg	*" $dir "*) ;;
74302836776bSmrg	*) func_append xrpath " $dir" ;;
7431c2939121Smrg	esac
7432c2939121Smrg	continue
7433c2939121Smrg	;;
7434c76ae52dSmrg
7435c2939121Smrg      -shared)
7436c2939121Smrg	# The effects of -shared are defined in a previous loop.
7437c2939121Smrg	continue
7438c2939121Smrg	;;
7439c76ae52dSmrg
7440c2939121Smrg      -shrext)
7441c2939121Smrg	prev=shrext
7442c2939121Smrg	continue
7443c2939121Smrg	;;
7444c76ae52dSmrg
7445c2939121Smrg      -static | -static-libtool-libs)
7446c2939121Smrg	# The effects of -static are defined in a previous loop.
7447c2939121Smrg	# We used to do the same as -all-static on platforms that
7448c2939121Smrg	# didn't have a PIC flag, but the assumption that the effects
7449c2939121Smrg	# would be equivalent was wrong.  It would break on at least
7450c2939121Smrg	# Digital Unix and AIX.
7451c2939121Smrg	continue
7452c2939121Smrg	;;
7453c76ae52dSmrg
7454c2939121Smrg      -thread-safe)
7455c2939121Smrg	thread_safe=yes
7456c2939121Smrg	continue
7457c2939121Smrg	;;
7458c76ae52dSmrg
7459c2939121Smrg      -version-info)
7460c2939121Smrg	prev=vinfo
7461c2939121Smrg	continue
7462c2939121Smrg	;;
7463c76ae52dSmrg
7464c2939121Smrg      -version-number)
7465c2939121Smrg	prev=vinfo
7466c2939121Smrg	vinfo_number=yes
7467c2939121Smrg	continue
7468c2939121Smrg	;;
7469c76ae52dSmrg
7470c2939121Smrg      -weak)
7471c2939121Smrg        prev=weak
7472c2939121Smrg	continue
7473c2939121Smrg	;;
7474c76ae52dSmrg
7475c2939121Smrg      -Wc,*)
7476c2939121Smrg	func_stripname '-Wc,' '' "$arg"
7477c2939121Smrg	args=$func_stripname_result
7478c2939121Smrg	arg=
74798292847cSmrg	save_ifs=$IFS; IFS=,
7480c2939121Smrg	for flag in $args; do
74818292847cSmrg	  IFS=$save_ifs
748225420f97Smrg          func_quote_arg pretty "$flag"
748325420f97Smrg	  func_append arg " $func_quote_arg_result"
748425420f97Smrg	  func_append compiler_flags " $func_quote_arg_result"
7485c2939121Smrg	done
74868292847cSmrg	IFS=$save_ifs
7487c2939121Smrg	func_stripname ' ' '' "$arg"
7488c2939121Smrg	arg=$func_stripname_result
7489c2939121Smrg	;;
7490c76ae52dSmrg
7491c2939121Smrg      -Wl,*)
7492c2939121Smrg	func_stripname '-Wl,' '' "$arg"
7493c2939121Smrg	args=$func_stripname_result
7494c2939121Smrg	arg=
74958292847cSmrg	save_ifs=$IFS; IFS=,
7496c2939121Smrg	for flag in $args; do
74978292847cSmrg	  IFS=$save_ifs
749825420f97Smrg          func_quote_arg pretty "$flag"
749925420f97Smrg	  func_append arg " $wl$func_quote_arg_result"
750025420f97Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
750125420f97Smrg	  func_append linker_flags " $func_quote_arg_result"
7502c2939121Smrg	done
75038292847cSmrg	IFS=$save_ifs
7504c2939121Smrg	func_stripname ' ' '' "$arg"
7505c2939121Smrg	arg=$func_stripname_result
7506c2939121Smrg	;;
7507c76ae52dSmrg
750825420f97Smrg      -Xassembler)
750925420f97Smrg        prev=xassembler
751025420f97Smrg        continue
751125420f97Smrg        ;;
751225420f97Smrg
7513c2939121Smrg      -Xcompiler)
7514c2939121Smrg	prev=xcompiler
7515c2939121Smrg	continue
7516c2939121Smrg	;;
7517c76ae52dSmrg
7518c2939121Smrg      -Xlinker)
7519c2939121Smrg	prev=xlinker
7520c2939121Smrg	continue
7521c2939121Smrg	;;
7522c76ae52dSmrg
7523c2939121Smrg      -XCClinker)
7524c2939121Smrg	prev=xcclinker
7525c2939121Smrg	continue
7526c2939121Smrg	;;
7527c76ae52dSmrg
7528c2939121Smrg      # -msg_* for osf cc
7529c2939121Smrg      -msg_*)
753025420f97Smrg	func_quote_arg pretty "$arg"
753125420f97Smrg	arg=$func_quote_arg_result
7532c2939121Smrg	;;
7533c76ae52dSmrg
7534c2939121Smrg      # Flags to be passed through unchanged, with rationale:
7535c2939121Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7536c2939121Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7537c2939121Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7538c2939121Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7539c2939121Smrg      # -q*                  compiler args for the IBM compiler
7540c2939121Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7541c2939121Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7542c2939121Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
75438292847cSmrg      # -fstack-protector*   stack protector flags for GCC
7544c2939121Smrg      # @file                GCC response files
7545c2939121Smrg      # -tp=*                Portland pgcc target processor selection
75462836776bSmrg      # --sysroot=*          for sysroot support
75478292847cSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7548de3c0529Smrg      # -specs=*             GCC specs files
75498292847cSmrg      # -stdlib=*            select c++ std lib with clang
7550de3c0529Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7551de3c0529Smrg      # -fuse-ld=*           Linker select flags for GCC
7552de301c82Smrg      # -static-*            direct GCC to link specific libraries statically
7553de301c82Smrg      # -fcilkplus           Cilk Plus language extension features for C/C++
755425420f97Smrg      # -Wa,*                Pass flags directly to the assembler
7555c2939121Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
75562836776bSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7557de3c0529Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7558de301c82Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus|-Wa,*)
755925420f97Smrg        func_quote_arg pretty "$arg"
756025420f97Smrg	arg=$func_quote_arg_result
7561c2939121Smrg        func_append compile_command " $arg"
7562c2939121Smrg        func_append finalize_command " $arg"
75632836776bSmrg        func_append compiler_flags " $arg"
7564c2939121Smrg        continue
7565c2939121Smrg        ;;
7566c76ae52dSmrg
75678292847cSmrg      -Z*)
75688292847cSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
75698292847cSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
75708292847cSmrg	  compiler_flags="$compiler_flags $arg"
75718292847cSmrg	  func_append compile_command " $arg"
75728292847cSmrg	  func_append finalize_command " $arg"
75738292847cSmrg	  case $arg in
75748292847cSmrg	  -Zlinker | -Zstack)
75758292847cSmrg	    prev=xcompiler
75768292847cSmrg	    ;;
75778292847cSmrg	  esac
75788292847cSmrg	  continue
75798292847cSmrg        else
75808292847cSmrg	  # Otherwise treat like 'Some other compiler flag' below
758125420f97Smrg	  func_quote_arg pretty "$arg"
758225420f97Smrg	  arg=$func_quote_arg_result
75838292847cSmrg        fi
75848292847cSmrg	;;
75858292847cSmrg
7586c2939121Smrg      # Some other compiler flag.
7587c2939121Smrg      -* | +*)
758825420f97Smrg        func_quote_arg pretty "$arg"
758925420f97Smrg	arg=$func_quote_arg_result
7590c2939121Smrg	;;
7591c76ae52dSmrg
7592c2939121Smrg      *.$objext)
7593c2939121Smrg	# A standard object.
75942836776bSmrg	func_append objs " $arg"
7595c2939121Smrg	;;
7596c76ae52dSmrg
7597c2939121Smrg      *.lo)
7598c2939121Smrg	# A libtool-controlled object.
7599c76ae52dSmrg
7600c2939121Smrg	# Check to see that this really is a libtool object.
7601c2939121Smrg	if func_lalib_unsafe_p "$arg"; then
7602c2939121Smrg	  pic_object=
7603c2939121Smrg	  non_pic_object=
7604c76ae52dSmrg
7605c2939121Smrg	  # Read the .lo file
7606c2939121Smrg	  func_source "$arg"
7607c76ae52dSmrg
7608c2939121Smrg	  if test -z "$pic_object" ||
7609c2939121Smrg	     test -z "$non_pic_object" ||
76108292847cSmrg	     test none = "$pic_object" &&
76118292847cSmrg	     test none = "$non_pic_object"; then
76128292847cSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7613c2939121Smrg	  fi
76140d590c07Smrg
7615c2939121Smrg	  # Extract subdirectory from the argument.
7616c2939121Smrg	  func_dirname "$arg" "/" ""
76178292847cSmrg	  xdir=$func_dirname_result
7618c76ae52dSmrg
76198292847cSmrg	  test none = "$pic_object" || {
7620c2939121Smrg	    # Prepend the subdirectory the object is found in.
76218292847cSmrg	    pic_object=$xdir$pic_object
7622c76ae52dSmrg
76238292847cSmrg	    if test dlfiles = "$prev"; then
76248292847cSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
76252836776bSmrg		func_append dlfiles " $pic_object"
7626c2939121Smrg		prev=
7627c2939121Smrg		continue
7628c2939121Smrg	      else
7629c2939121Smrg		# If libtool objects are unsupported, then we need to preload.
7630c2939121Smrg		prev=dlprefiles
7631c2939121Smrg	      fi
7632c2939121Smrg	    fi
7633c2939121Smrg
7634c2939121Smrg	    # CHECK ME:  I think I busted this.  -Ossama
76358292847cSmrg	    if test dlprefiles = "$prev"; then
7636c2939121Smrg	      # Preload the old-style object.
76372836776bSmrg	      func_append dlprefiles " $pic_object"
7638c2939121Smrg	      prev=
7639c2939121Smrg	    fi
7640c2939121Smrg
7641c2939121Smrg	    # A PIC object.
7642c2939121Smrg	    func_append libobjs " $pic_object"
76438292847cSmrg	    arg=$pic_object
76448292847cSmrg	  }
7645c2939121Smrg
7646c2939121Smrg	  # Non-PIC object.
76478292847cSmrg	  if test none != "$non_pic_object"; then
7648c2939121Smrg	    # Prepend the subdirectory the object is found in.
76498292847cSmrg	    non_pic_object=$xdir$non_pic_object
7650c2939121Smrg
7651c2939121Smrg	    # A standard non-PIC object
7652c2939121Smrg	    func_append non_pic_objects " $non_pic_object"
76538292847cSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
76548292847cSmrg	      arg=$non_pic_object
7655c2939121Smrg	    fi
7656c2939121Smrg	  else
7657c2939121Smrg	    # If the PIC object exists, use it instead.
7658c2939121Smrg	    # $xdir was prepended to $pic_object above.
76598292847cSmrg	    non_pic_object=$pic_object
7660c2939121Smrg	    func_append non_pic_objects " $non_pic_object"
7661c2939121Smrg	  fi
7662c2939121Smrg	else
7663c2939121Smrg	  # Only an error if not doing a dry-run.
7664c2939121Smrg	  if $opt_dry_run; then
7665c2939121Smrg	    # Extract subdirectory from the argument.
7666c2939121Smrg	    func_dirname "$arg" "/" ""
76678292847cSmrg	    xdir=$func_dirname_result
7668c2939121Smrg
7669c2939121Smrg	    func_lo2o "$arg"
7670c2939121Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7671c2939121Smrg	    non_pic_object=$xdir$func_lo2o_result
7672c2939121Smrg	    func_append libobjs " $pic_object"
7673c2939121Smrg	    func_append non_pic_objects " $non_pic_object"
7674c2939121Smrg	  else
76758292847cSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7676c2939121Smrg	  fi
7677c2939121Smrg	fi
7678c2939121Smrg	;;
7679c2939121Smrg
7680c2939121Smrg      *.$libext)
7681c2939121Smrg	# An archive.
76822836776bSmrg	func_append deplibs " $arg"
76832836776bSmrg	func_append old_deplibs " $arg"
7684c2939121Smrg	continue
7685c2939121Smrg	;;
7686c2939121Smrg
7687c2939121Smrg      *.la)
7688c2939121Smrg	# A libtool-controlled library.
7689c2939121Smrg
76902836776bSmrg	func_resolve_sysroot "$arg"
76918292847cSmrg	if test dlfiles = "$prev"; then
7692c2939121Smrg	  # This library was specified with -dlopen.
76932836776bSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7694c2939121Smrg	  prev=
76958292847cSmrg	elif test dlprefiles = "$prev"; then
7696c2939121Smrg	  # The library was specified with -dlpreopen.
76972836776bSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7698c2939121Smrg	  prev=
7699c2939121Smrg	else
77002836776bSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7701c2939121Smrg	fi
7702c2939121Smrg	continue
7703c2939121Smrg	;;
7704c2939121Smrg
7705c2939121Smrg      # Some other compiler argument.
7706c2939121Smrg      *)
7707c2939121Smrg	# Unknown arguments in both finalize_command and compile_command need
7708c2939121Smrg	# to be aesthetically quoted because they are evaled later.
770925420f97Smrg	func_quote_arg pretty "$arg"
771025420f97Smrg	arg=$func_quote_arg_result
7711c2939121Smrg	;;
7712c2939121Smrg      esac # arg
7713c2939121Smrg
7714c2939121Smrg      # Now actually substitute the argument into the commands.
7715c2939121Smrg      if test -n "$arg"; then
7716c2939121Smrg	func_append compile_command " $arg"
7717c2939121Smrg	func_append finalize_command " $arg"
7718c2939121Smrg      fi
7719c2939121Smrg    done # argument parsing loop
7720c2939121Smrg
7721c2939121Smrg    test -n "$prev" && \
77228292847cSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7723c2939121Smrg
77248292847cSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7725c2939121Smrg      eval arg=\"$export_dynamic_flag_spec\"
7726c2939121Smrg      func_append compile_command " $arg"
7727c2939121Smrg      func_append finalize_command " $arg"
7728c2939121Smrg    fi
7729c2939121Smrg
7730c2939121Smrg    oldlibs=
7731c2939121Smrg    # calculate the name of the file, without its directory
7732c2939121Smrg    func_basename "$output"
77338292847cSmrg    outputname=$func_basename_result
77348292847cSmrg    libobjs_save=$libobjs
7735c2939121Smrg
7736c2939121Smrg    if test -n "$shlibpath_var"; then
7737c2939121Smrg      # get the directories listed in $shlibpath_var
77388292847cSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7739c76ae52dSmrg    else
7740c2939121Smrg      shlib_search_path=
7741c76ae52dSmrg    fi
7742c2939121Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7743c2939121Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7744c76ae52dSmrg
77458292847cSmrg    # Definition is injected by LT_CONFIG during libtool generation.
77468292847cSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
77478292847cSmrg
7748c2939121Smrg    func_dirname "$output" "/" ""
77498292847cSmrg    output_objdir=$func_dirname_result$objdir
77502836776bSmrg    func_to_tool_file "$output_objdir/"
77512836776bSmrg    tool_output_objdir=$func_to_tool_file_result
7752c2939121Smrg    # Create the object directory.
7753c2939121Smrg    func_mkdir_p "$output_objdir"
7754c76ae52dSmrg
7755c2939121Smrg    # Determine the type of output
7756c2939121Smrg    case $output in
7757c2939121Smrg    "")
7758c2939121Smrg      func_fatal_help "you must specify an output file"
7759c2939121Smrg      ;;
7760c2939121Smrg    *.$libext) linkmode=oldlib ;;
7761c2939121Smrg    *.lo | *.$objext) linkmode=obj ;;
7762c2939121Smrg    *.la) linkmode=lib ;;
7763c2939121Smrg    *) linkmode=prog ;; # Anything else should be a program.
7764c2939121Smrg    esac
7765c2939121Smrg
7766c2939121Smrg    specialdeplibs=
7767c2939121Smrg
7768c2939121Smrg    libs=
7769c2939121Smrg    # Find all interdependent deplibs by searching for libraries
7770c2939121Smrg    # that are linked more than once (e.g. -la -lb -la)
7771c2939121Smrg    for deplib in $deplibs; do
77728292847cSmrg      if $opt_preserve_dup_deps; then
7773c2939121Smrg	case "$libs " in
77742836776bSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7775c2939121Smrg	esac
7776c2939121Smrg      fi
77772836776bSmrg      func_append libs " $deplib"
7778c2939121Smrg    done
7779c2939121Smrg
77808292847cSmrg    if test lib = "$linkmode"; then
7781c2939121Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7782c2939121Smrg
7783c2939121Smrg      # Compute libraries that are listed more than once in $predeps
7784c2939121Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7785c2939121Smrg      # not to be eliminated).
7786c2939121Smrg      pre_post_deps=
7787c2939121Smrg      if $opt_duplicate_compiler_generated_deps; then
7788c2939121Smrg	for pre_post_dep in $predeps $postdeps; do
7789c2939121Smrg	  case "$pre_post_deps " in
77902836776bSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7791c2939121Smrg	  esac
77922836776bSmrg	  func_append pre_post_deps " $pre_post_dep"
7793c2939121Smrg	done
7794c2939121Smrg      fi
7795c2939121Smrg      pre_post_deps=
7796c2939121Smrg    fi
7797c2939121Smrg
7798c2939121Smrg    deplibs=
7799c2939121Smrg    newdependency_libs=
7800c2939121Smrg    newlib_search_path=
7801c2939121Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7802c2939121Smrg    notinst_deplibs= # not-installed libtool libraries
7803c2939121Smrg    notinst_path= # paths that contain not-installed libtool libraries
7804c2939121Smrg
7805c2939121Smrg    case $linkmode in
7806c2939121Smrg    lib)
7807c2939121Smrg	passes="conv dlpreopen link"
7808c2939121Smrg	for file in $dlfiles $dlprefiles; do
7809c2939121Smrg	  case $file in
7810c2939121Smrg	  *.la) ;;
7811c2939121Smrg	  *)
78128292847cSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7813c2939121Smrg	    ;;
7814c2939121Smrg	  esac
7815c2939121Smrg	done
7816c2939121Smrg	;;
7817c2939121Smrg    prog)
7818c2939121Smrg	compile_deplibs=
7819c2939121Smrg	finalize_deplibs=
78208292847cSmrg	alldeplibs=false
7821c2939121Smrg	newdlfiles=
7822c2939121Smrg	newdlprefiles=
7823c2939121Smrg	passes="conv scan dlopen dlpreopen link"
7824c2939121Smrg	;;
7825c2939121Smrg    *)  passes="conv"
7826c2939121Smrg	;;
7827c2939121Smrg    esac
7828c2939121Smrg
7829c2939121Smrg    for pass in $passes; do
7830c2939121Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7831c2939121Smrg      # so that -L comes before libs that need it for instance...
78328292847cSmrg      if test lib,link = "$linkmode,$pass"; then
7833c2939121Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7834c2939121Smrg	##        order, and fix it there properly
7835c2939121Smrg        tmp_deplibs=
7836c2939121Smrg	for deplib in $deplibs; do
7837c2939121Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7838c2939121Smrg	done
78398292847cSmrg	deplibs=$tmp_deplibs
7840c2939121Smrg      fi
7841c2939121Smrg
78428292847cSmrg      if test lib,link = "$linkmode,$pass" ||
78438292847cSmrg	 test prog,scan = "$linkmode,$pass"; then
78448292847cSmrg	libs=$deplibs
7845c2939121Smrg	deplibs=
7846c2939121Smrg      fi
78478292847cSmrg      if test prog = "$linkmode"; then
7848c2939121Smrg	case $pass in
78498292847cSmrg	dlopen) libs=$dlfiles ;;
78508292847cSmrg	dlpreopen) libs=$dlprefiles ;;
7851de301c82Smrg	link)
7852de301c82Smrg	  libs="$deplibs %DEPLIBS%"
7853de301c82Smrg	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
7854de301c82Smrg	  ;;
7855c2939121Smrg	esac
7856c2939121Smrg      fi
78578292847cSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7858c2939121Smrg	# Collect and forward deplibs of preopened libtool libs
7859c2939121Smrg	for lib in $dlprefiles; do
7860c2939121Smrg	  # Ignore non-libtool-libs
7861c2939121Smrg	  dependency_libs=
78622836776bSmrg	  func_resolve_sysroot "$lib"
7863c2939121Smrg	  case $lib in
78642836776bSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7865c2939121Smrg	  esac
7866c2939121Smrg
7867c2939121Smrg	  # Collect preopened libtool deplibs, except any this library
7868c2939121Smrg	  # has declared as weak libs
7869c2939121Smrg	  for deplib in $dependency_libs; do
7870c2939121Smrg	    func_basename "$deplib"
7871c2939121Smrg            deplib_base=$func_basename_result
7872c2939121Smrg	    case " $weak_libs " in
7873c2939121Smrg	    *" $deplib_base "*) ;;
78742836776bSmrg	    *) func_append deplibs " $deplib" ;;
7875c2939121Smrg	    esac
7876c2939121Smrg	  done
7877c2939121Smrg	done
78788292847cSmrg	libs=$dlprefiles
7879c2939121Smrg      fi
78808292847cSmrg      if test dlopen = "$pass"; then
7881c2939121Smrg	# Collect dlpreopened libraries
78828292847cSmrg	save_deplibs=$deplibs
7883c2939121Smrg	deplibs=
7884c2939121Smrg      fi
7885c2939121Smrg
7886c2939121Smrg      for deplib in $libs; do
7887c2939121Smrg	lib=
78888292847cSmrg	found=false
7889c2939121Smrg	case $deplib in
78902836776bSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
78912836776bSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
78928292847cSmrg	  if test prog,link = "$linkmode,$pass"; then
7893c2939121Smrg	    compile_deplibs="$deplib $compile_deplibs"
7894c2939121Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7895c2939121Smrg	  else
78962836776bSmrg	    func_append compiler_flags " $deplib"
78978292847cSmrg	    if test lib = "$linkmode"; then
7898c2939121Smrg		case "$new_inherited_linker_flags " in
7899c2939121Smrg		    *" $deplib "*) ;;
79002836776bSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7901c2939121Smrg		esac
7902c2939121Smrg	    fi
7903c2939121Smrg	  fi
7904c2939121Smrg	  continue
7905c2939121Smrg	  ;;
7906c2939121Smrg	-l*)
79078292847cSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
79088292847cSmrg	    func_warning "'-l' is ignored for archives/objects"
7909c2939121Smrg	    continue
7910c2939121Smrg	  fi
7911c2939121Smrg	  func_stripname '-l' '' "$deplib"
7912c2939121Smrg	  name=$func_stripname_result
79138292847cSmrg	  if test lib = "$linkmode"; then
7914c2939121Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7915c2939121Smrg	  else
7916c2939121Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7917c2939121Smrg	  fi
7918c2939121Smrg	  for searchdir in $searchdirs; do
7919c2939121Smrg	    for search_ext in .la $std_shrext .so .a; do
7920c2939121Smrg	      # Search the libtool library
79218292847cSmrg	      lib=$searchdir/lib$name$search_ext
7922c2939121Smrg	      if test -f "$lib"; then
79238292847cSmrg		if test .la = "$search_ext"; then
79248292847cSmrg		  found=:
7925c2939121Smrg		else
79268292847cSmrg		  found=false
7927c2939121Smrg		fi
7928c2939121Smrg		break 2
7929c2939121Smrg	      fi
7930c2939121Smrg	    done
7931c2939121Smrg	  done
79328292847cSmrg	  if $found; then
79338292847cSmrg	    # deplib is a libtool library
7934c2939121Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7935c2939121Smrg	    # We need to do some special things here, and not later.
79368292847cSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7937c2939121Smrg	      case " $predeps $postdeps " in
7938c2939121Smrg	      *" $deplib "*)
7939c2939121Smrg		if func_lalib_p "$lib"; then
7940c2939121Smrg		  library_names=
7941c2939121Smrg		  old_library=
7942c2939121Smrg		  func_source "$lib"
7943c2939121Smrg		  for l in $old_library $library_names; do
79448292847cSmrg		    ll=$l
7945c2939121Smrg		  done
79468292847cSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
79478292847cSmrg		    found=false
7948c2939121Smrg		    func_dirname "$lib" "" "."
79498292847cSmrg		    ladir=$func_dirname_result
7950c2939121Smrg		    lib=$ladir/$old_library
79518292847cSmrg		    if test prog,link = "$linkmode,$pass"; then
7952c2939121Smrg		      compile_deplibs="$deplib $compile_deplibs"
7953c2939121Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7954c2939121Smrg		    else
7955c2939121Smrg		      deplibs="$deplib $deplibs"
79568292847cSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7957c2939121Smrg		    fi
7958c2939121Smrg		    continue
7959c2939121Smrg		  fi
7960c2939121Smrg		fi
7961c2939121Smrg		;;
7962c2939121Smrg	      *) ;;
7963c2939121Smrg	      esac
7964c2939121Smrg	    fi
79658292847cSmrg	  else
79668292847cSmrg	    # deplib doesn't seem to be a libtool library
79678292847cSmrg	    if test prog,link = "$linkmode,$pass"; then
79688292847cSmrg	      compile_deplibs="$deplib $compile_deplibs"
79698292847cSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
79708292847cSmrg	    else
79718292847cSmrg	      deplibs="$deplib $deplibs"
79728292847cSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79738292847cSmrg	    fi
79748292847cSmrg	    continue
7975c2939121Smrg	  fi
7976c2939121Smrg	  ;; # -l
7977c2939121Smrg	*.ltframework)
79788292847cSmrg	  if test prog,link = "$linkmode,$pass"; then
7979c2939121Smrg	    compile_deplibs="$deplib $compile_deplibs"
7980c2939121Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7981c2939121Smrg	  else
7982c2939121Smrg	    deplibs="$deplib $deplibs"
79838292847cSmrg	    if test lib = "$linkmode"; then
7984c2939121Smrg		case "$new_inherited_linker_flags " in
7985c2939121Smrg		    *" $deplib "*) ;;
79862836776bSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7987c2939121Smrg		esac
7988c2939121Smrg	    fi
7989c2939121Smrg	  fi
7990c2939121Smrg	  continue
7991c2939121Smrg	  ;;
7992c2939121Smrg	-L*)
7993c2939121Smrg	  case $linkmode in
7994c2939121Smrg	  lib)
7995c2939121Smrg	    deplibs="$deplib $deplibs"
79968292847cSmrg	    test conv = "$pass" && continue
7997c2939121Smrg	    newdependency_libs="$deplib $newdependency_libs"
7998c2939121Smrg	    func_stripname '-L' '' "$deplib"
79992836776bSmrg	    func_resolve_sysroot "$func_stripname_result"
80002836776bSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8001c2939121Smrg	    ;;
8002c2939121Smrg	  prog)
80038292847cSmrg	    if test conv = "$pass"; then
8004c2939121Smrg	      deplibs="$deplib $deplibs"
8005c2939121Smrg	      continue
8006c2939121Smrg	    fi
80078292847cSmrg	    if test scan = "$pass"; then
8008c2939121Smrg	      deplibs="$deplib $deplibs"
8009c2939121Smrg	    else
8010c2939121Smrg	      compile_deplibs="$deplib $compile_deplibs"
8011c2939121Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8012c2939121Smrg	    fi
8013c2939121Smrg	    func_stripname '-L' '' "$deplib"
80142836776bSmrg	    func_resolve_sysroot "$func_stripname_result"
80152836776bSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8016c2939121Smrg	    ;;
8017c2939121Smrg	  *)
80188292847cSmrg	    func_warning "'-L' is ignored for archives/objects"
8019c2939121Smrg	    ;;
8020c2939121Smrg	  esac # linkmode
8021c2939121Smrg	  continue
8022c2939121Smrg	  ;; # -L
8023c2939121Smrg	-R*)
80248292847cSmrg	  if test link = "$pass"; then
8025c2939121Smrg	    func_stripname '-R' '' "$deplib"
80262836776bSmrg	    func_resolve_sysroot "$func_stripname_result"
80272836776bSmrg	    dir=$func_resolve_sysroot_result
8028c2939121Smrg	    # Make sure the xrpath contains only unique directories.
8029c2939121Smrg	    case "$xrpath " in
8030c2939121Smrg	    *" $dir "*) ;;
80312836776bSmrg	    *) func_append xrpath " $dir" ;;
8032c2939121Smrg	    esac
8033c2939121Smrg	  fi
8034c2939121Smrg	  deplibs="$deplib $deplibs"
8035c2939121Smrg	  continue
8036c2939121Smrg	  ;;
80372836776bSmrg	*.la)
80382836776bSmrg	  func_resolve_sysroot "$deplib"
80392836776bSmrg	  lib=$func_resolve_sysroot_result
80402836776bSmrg	  ;;
8041c2939121Smrg	*.$libext)
80428292847cSmrg	  if test conv = "$pass"; then
8043c2939121Smrg	    deplibs="$deplib $deplibs"
8044c2939121Smrg	    continue
8045c2939121Smrg	  fi
8046c2939121Smrg	  case $linkmode in
8047c2939121Smrg	  lib)
8048c2939121Smrg	    # Linking convenience modules into shared libraries is allowed,
8049c2939121Smrg	    # but linking other static libraries is non-portable.
8050c2939121Smrg	    case " $dlpreconveniencelibs " in
8051c2939121Smrg	    *" $deplib "*) ;;
8052c2939121Smrg	    *)
80538292847cSmrg	      valid_a_lib=false
8054c2939121Smrg	      case $deplibs_check_method in
8055c2939121Smrg		match_pattern*)
8056c2939121Smrg		  set dummy $deplibs_check_method; shift
8057c2939121Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8058c2939121Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8059c2939121Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
80608292847cSmrg		    valid_a_lib=:
8061c2939121Smrg		  fi
8062c2939121Smrg		;;
8063c2939121Smrg		pass_all)
80648292847cSmrg		  valid_a_lib=:
8065c2939121Smrg		;;
8066c2939121Smrg	      esac
80678292847cSmrg	      if $valid_a_lib; then
80688292847cSmrg		echo
80698292847cSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
80708292847cSmrg		$ECHO "*** static library $deplib is not portable!"
80718292847cSmrg		deplibs="$deplib $deplibs"
80728292847cSmrg	      else
8073c2939121Smrg		echo
8074c2939121Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8075c2939121Smrg		echo "*** I have the capability to make that library automatically link in when"
8076c2939121Smrg		echo "*** you link to this library.  But I can only do this if you have a"
8077c2939121Smrg		echo "*** shared version of the library, which you do not appear to have"
8078c2939121Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8079c2939121Smrg		echo "*** that it is just a static archive that I should not use here."
8080c2939121Smrg	      fi
8081c2939121Smrg	      ;;
8082c2939121Smrg	    esac
8083c2939121Smrg	    continue
8084c2939121Smrg	    ;;
8085c2939121Smrg	  prog)
80868292847cSmrg	    if test link != "$pass"; then
8087c2939121Smrg	      deplibs="$deplib $deplibs"
8088c2939121Smrg	    else
8089c2939121Smrg	      compile_deplibs="$deplib $compile_deplibs"
8090c2939121Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8091c2939121Smrg	    fi
8092c2939121Smrg	    continue
8093c2939121Smrg	    ;;
8094c2939121Smrg	  esac # linkmode
8095c2939121Smrg	  ;; # *.$libext
8096c2939121Smrg	*.lo | *.$objext)
80978292847cSmrg	  if test conv = "$pass"; then
8098c2939121Smrg	    deplibs="$deplib $deplibs"
80998292847cSmrg	  elif test prog = "$linkmode"; then
81008292847cSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8101c2939121Smrg	      # If there is no dlopen support or we're linking statically,
8102c2939121Smrg	      # we need to preload.
81032836776bSmrg	      func_append newdlprefiles " $deplib"
8104c2939121Smrg	      compile_deplibs="$deplib $compile_deplibs"
8105c2939121Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8106c2939121Smrg	    else
81072836776bSmrg	      func_append newdlfiles " $deplib"
8108c2939121Smrg	    fi
8109c2939121Smrg	  fi
8110c2939121Smrg	  continue
8111c2939121Smrg	  ;;
8112c2939121Smrg	%DEPLIBS%)
81138292847cSmrg	  alldeplibs=:
8114c2939121Smrg	  continue
8115c2939121Smrg	  ;;
8116c2939121Smrg	esac # case $deplib
8117c2939121Smrg
81188292847cSmrg	$found || test -f "$lib" \
81198292847cSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8120c2939121Smrg
8121c2939121Smrg	# Check to see that this really is a libtool archive.
8122c2939121Smrg	func_lalib_unsafe_p "$lib" \
81238292847cSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8124c2939121Smrg
8125c2939121Smrg	func_dirname "$lib" "" "."
81268292847cSmrg	ladir=$func_dirname_result
8127c2939121Smrg
8128c2939121Smrg	dlname=
8129c2939121Smrg	dlopen=
8130c2939121Smrg	dlpreopen=
8131c2939121Smrg	libdir=
8132c2939121Smrg	library_names=
8133c2939121Smrg	old_library=
8134c2939121Smrg	inherited_linker_flags=
8135c2939121Smrg	# If the library was installed with an old release of libtool,
8136c2939121Smrg	# it will not redefine variables installed, or shouldnotlink
8137c2939121Smrg	installed=yes
8138c2939121Smrg	shouldnotlink=no
8139c2939121Smrg	avoidtemprpath=
8140c2939121Smrg
8141c2939121Smrg
8142c2939121Smrg	# Read the .la file
8143c2939121Smrg	func_source "$lib"
8144c2939121Smrg
8145c2939121Smrg	# Convert "-framework foo" to "foo.ltframework"
8146c2939121Smrg	if test -n "$inherited_linker_flags"; then
8147c2939121Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8148c2939121Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8149c2939121Smrg	    case " $new_inherited_linker_flags " in
8150c2939121Smrg	      *" $tmp_inherited_linker_flag "*) ;;
81512836776bSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8152c2939121Smrg	    esac
8153c2939121Smrg	  done
8154c2939121Smrg	fi
8155c2939121Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
81568292847cSmrg	if test lib,link = "$linkmode,$pass" ||
81578292847cSmrg	   test prog,scan = "$linkmode,$pass" ||
81588292847cSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
81592836776bSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
81602836776bSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8161c2939121Smrg	fi
8162c2939121Smrg
81638292847cSmrg	if test conv = "$pass"; then
8164c2939121Smrg	  # Only check for convenience libraries
8165c2939121Smrg	  deplibs="$lib $deplibs"
8166c2939121Smrg	  if test -z "$libdir"; then
8167c2939121Smrg	    if test -z "$old_library"; then
81688292847cSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8169c2939121Smrg	    fi
8170c2939121Smrg	    # It is a libtool convenience library, so add in its objects.
81712836776bSmrg	    func_append convenience " $ladir/$objdir/$old_library"
81722836776bSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8173de301c82Smrg	    tmp_libs=
8174de301c82Smrg	    for deplib in $dependency_libs; do
8175de301c82Smrg	      deplibs="$deplib $deplibs"
8176de301c82Smrg	      if $opt_preserve_dup_deps; then
8177de301c82Smrg		case "$tmp_libs " in
8178de301c82Smrg		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
8179de301c82Smrg		esac
8180de301c82Smrg	      fi
8181de301c82Smrg	      func_append tmp_libs " $deplib"
8182de301c82Smrg	    done
81838292847cSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
81848292847cSmrg	    func_fatal_error "'$lib' is not a convenience library"
8185c2939121Smrg	  fi
8186c2939121Smrg	  continue
8187c2939121Smrg	fi # $pass = conv
8188c2939121Smrg
8189c2939121Smrg
8190c2939121Smrg	# Get the name of the library we link against.
8191c2939121Smrg	linklib=
81922836776bSmrg	if test -n "$old_library" &&
81938292847cSmrg	   { test yes = "$prefer_static_libs" ||
81948292847cSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
81952836776bSmrg	  linklib=$old_library
81962836776bSmrg	else
81972836776bSmrg	  for l in $old_library $library_names; do
81988292847cSmrg	    linklib=$l
81992836776bSmrg	  done
82002836776bSmrg	fi
8201c2939121Smrg	if test -z "$linklib"; then
82028292847cSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8203c2939121Smrg	fi
8204c2939121Smrg
8205c2939121Smrg	# This library was specified with -dlopen.
82068292847cSmrg	if test dlopen = "$pass"; then
82078292847cSmrg	  test -z "$libdir" \
82088292847cSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8209c2939121Smrg	  if test -z "$dlname" ||
82108292847cSmrg	     test yes != "$dlopen_support" ||
82118292847cSmrg	     test no = "$build_libtool_libs"
82128292847cSmrg	  then
8213c2939121Smrg	    # If there is no dlname, no dlopen support or we're linking
8214c2939121Smrg	    # statically, we need to preload.  We also need to preload any
8215c2939121Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8216c2939121Smrg	    # bomb out in the load deplibs phase.
82172836776bSmrg	    func_append dlprefiles " $lib $dependency_libs"
8218c2939121Smrg	  else
82192836776bSmrg	    func_append newdlfiles " $lib"
8220c2939121Smrg	  fi
8221c2939121Smrg	  continue
8222c2939121Smrg	fi # $pass = dlopen
8223c2939121Smrg
8224c2939121Smrg	# We need an absolute path.
8225c2939121Smrg	case $ladir in
82268292847cSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8227c2939121Smrg	*)
8228c2939121Smrg	  abs_ladir=`cd "$ladir" && pwd`
8229c2939121Smrg	  if test -z "$abs_ladir"; then
82308292847cSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8231c2939121Smrg	    func_warning "passing it literally to the linker, although it might fail"
82328292847cSmrg	    abs_ladir=$ladir
8233c2939121Smrg	  fi
8234c2939121Smrg	  ;;
8235c2939121Smrg	esac
8236c2939121Smrg	func_basename "$lib"
82378292847cSmrg	laname=$func_basename_result
8238c2939121Smrg
8239c2939121Smrg	# Find the relevant object directory and library name.
82408292847cSmrg	if test yes = "$installed"; then
82412836776bSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82428292847cSmrg	    func_warning "library '$lib' was moved."
82438292847cSmrg	    dir=$ladir
82448292847cSmrg	    absdir=$abs_ladir
82458292847cSmrg	    libdir=$abs_ladir
8246c2939121Smrg	  else
82478292847cSmrg	    dir=$lt_sysroot$libdir
82488292847cSmrg	    absdir=$lt_sysroot$libdir
8249c2939121Smrg	  fi
82508292847cSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8251c2939121Smrg	else
8252c2939121Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82538292847cSmrg	    dir=$ladir
82548292847cSmrg	    absdir=$abs_ladir
8255c2939121Smrg	    # Remove this search path later
82562836776bSmrg	    func_append notinst_path " $abs_ladir"
8257c2939121Smrg	  else
82588292847cSmrg	    dir=$ladir/$objdir
82598292847cSmrg	    absdir=$abs_ladir/$objdir
8260c2939121Smrg	    # Remove this search path later
82612836776bSmrg	    func_append notinst_path " $abs_ladir"
8262c2939121Smrg	  fi
8263c2939121Smrg	fi # $installed = yes
8264c2939121Smrg	func_stripname 'lib' '.la' "$laname"
8265c2939121Smrg	name=$func_stripname_result
8266c2939121Smrg
8267c2939121Smrg	# This library was specified with -dlpreopen.
82688292847cSmrg	if test dlpreopen = "$pass"; then
82698292847cSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
82708292847cSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8271c2939121Smrg	  fi
82728292847cSmrg	  case $host in
82732836776bSmrg	    # special handling for platforms with PE-DLLs.
82742836776bSmrg	    *cygwin* | *mingw* | *cegcc* )
82752836776bSmrg	      # Linker will automatically link against shared library if both
82762836776bSmrg	      # static and shared are present.  Therefore, ensure we extract
82772836776bSmrg	      # symbols from the import library if a shared library is present
82782836776bSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
82792836776bSmrg	      # this by putting the import library name into $newdlprefiles.
82802836776bSmrg	      # We recover the dlopen module name by 'saving' the la file
82812836776bSmrg	      # name in a special purpose variable, and (later) extracting the
82822836776bSmrg	      # dlname from the la file.
82832836776bSmrg	      if test -n "$dlname"; then
82842836776bSmrg	        func_tr_sh "$dir/$linklib"
82852836776bSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
82862836776bSmrg	        func_append newdlprefiles " $dir/$linklib"
82872836776bSmrg	      else
82882836776bSmrg	        func_append newdlprefiles " $dir/$old_library"
82892836776bSmrg	        # Keep a list of preopened convenience libraries to check
82902836776bSmrg	        # that they are being used correctly in the link pass.
82912836776bSmrg	        test -z "$libdir" && \
82922836776bSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
82932836776bSmrg	      fi
82942836776bSmrg	    ;;
82952836776bSmrg	    * )
82962836776bSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
82972836776bSmrg	      # are required to link).
82982836776bSmrg	      if test -n "$old_library"; then
82992836776bSmrg	        func_append newdlprefiles " $dir/$old_library"
83002836776bSmrg	        # Keep a list of preopened convenience libraries to check
83012836776bSmrg	        # that they are being used correctly in the link pass.
83022836776bSmrg	        test -z "$libdir" && \
83032836776bSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
83042836776bSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
83052836776bSmrg	      elif test -n "$dlname"; then
83062836776bSmrg	        func_append newdlprefiles " $dir/$dlname"
83072836776bSmrg	      else
83082836776bSmrg	        func_append newdlprefiles " $dir/$linklib"
83092836776bSmrg	      fi
83102836776bSmrg	    ;;
83112836776bSmrg	  esac
8312c2939121Smrg	fi # $pass = dlpreopen
8313c2939121Smrg
8314c2939121Smrg	if test -z "$libdir"; then
8315c2939121Smrg	  # Link the convenience library
83168292847cSmrg	  if test lib = "$linkmode"; then
8317c2939121Smrg	    deplibs="$dir/$old_library $deplibs"
83188292847cSmrg	  elif test prog,link = "$linkmode,$pass"; then
8319c2939121Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8320c2939121Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8321c2939121Smrg	  else
8322c2939121Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8323c2939121Smrg	  fi
8324c2939121Smrg	  continue
8325c2939121Smrg	fi
8326c2939121Smrg
8327c2939121Smrg
83288292847cSmrg	if test prog = "$linkmode" && test link != "$pass"; then
83292836776bSmrg	  func_append newlib_search_path " $ladir"
8330c2939121Smrg	  deplibs="$lib $deplibs"
8331c2939121Smrg
83328292847cSmrg	  linkalldeplibs=false
83338292847cSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
83348292847cSmrg	     test no = "$build_libtool_libs"; then
83358292847cSmrg	    linkalldeplibs=:
8336c2939121Smrg	  fi
8337c2939121Smrg
8338c2939121Smrg	  tmp_libs=
8339c2939121Smrg	  for deplib in $dependency_libs; do
8340c2939121Smrg	    case $deplib in
8341c2939121Smrg	    -L*) func_stripname '-L' '' "$deplib"
83422836776bSmrg	         func_resolve_sysroot "$func_stripname_result"
83432836776bSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8344c2939121Smrg		 ;;
8345c2939121Smrg	    esac
8346c2939121Smrg	    # Need to link against all dependency_libs?
83478292847cSmrg	    if $linkalldeplibs; then
8348c2939121Smrg	      deplibs="$deplib $deplibs"
8349c2939121Smrg	    else
8350c2939121Smrg	      # Need to hardcode shared library paths
8351c2939121Smrg	      # or/and link against static libraries
8352c2939121Smrg	      newdependency_libs="$deplib $newdependency_libs"
8353c2939121Smrg	    fi
83548292847cSmrg	    if $opt_preserve_dup_deps; then
8355c2939121Smrg	      case "$tmp_libs " in
83562836776bSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8357c2939121Smrg	      esac
8358c2939121Smrg	    fi
83592836776bSmrg	    func_append tmp_libs " $deplib"
8360c2939121Smrg	  done # for deplib
8361c2939121Smrg	  continue
8362c2939121Smrg	fi # $linkmode = prog...
8363c2939121Smrg
83648292847cSmrg	if test prog,link = "$linkmode,$pass"; then
8365c2939121Smrg	  if test -n "$library_names" &&
83668292847cSmrg	     { { test no = "$prefer_static_libs" ||
83678292847cSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8368c2939121Smrg	       test -z "$old_library"; }; then
8369c2939121Smrg	    # We need to hardcode the library path
83708292847cSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8371c2939121Smrg	      # Make sure the rpath contains only unique directories.
83728292847cSmrg	      case $temp_rpath: in
8373c2939121Smrg	      *"$absdir:"*) ;;
83742836776bSmrg	      *) func_append temp_rpath "$absdir:" ;;
8375c2939121Smrg	      esac
8376c2939121Smrg	    fi
8377c2939121Smrg
8378c2939121Smrg	    # Hardcode the library path.
8379c2939121Smrg	    # Skip directories that are in the system default run-time
8380c2939121Smrg	    # search path.
8381c2939121Smrg	    case " $sys_lib_dlsearch_path " in
8382c2939121Smrg	    *" $absdir "*) ;;
8383c2939121Smrg	    *)
8384c2939121Smrg	      case "$compile_rpath " in
8385c2939121Smrg	      *" $absdir "*) ;;
83862836776bSmrg	      *) func_append compile_rpath " $absdir" ;;
8387c2939121Smrg	      esac
8388c2939121Smrg	      ;;
8389c2939121Smrg	    esac
8390c2939121Smrg	    case " $sys_lib_dlsearch_path " in
8391c2939121Smrg	    *" $libdir "*) ;;
8392c2939121Smrg	    *)
8393c2939121Smrg	      case "$finalize_rpath " in
8394c2939121Smrg	      *" $libdir "*) ;;
83952836776bSmrg	      *) func_append finalize_rpath " $libdir" ;;
8396c2939121Smrg	      esac
8397c2939121Smrg	      ;;
8398c2939121Smrg	    esac
8399c2939121Smrg	  fi # $linkmode,$pass = prog,link...
8400c2939121Smrg
84018292847cSmrg	  if $alldeplibs &&
84028292847cSmrg	     { test pass_all = "$deplibs_check_method" ||
84038292847cSmrg	       { test yes = "$build_libtool_libs" &&
8404c2939121Smrg		 test -n "$library_names"; }; }; then
8405c2939121Smrg	    # We only need to search for static libraries
8406c2939121Smrg	    continue
8407c2939121Smrg	  fi
8408c2939121Smrg	fi
8409c2939121Smrg
8410c2939121Smrg	link_static=no # Whether the deplib will be linked statically
8411c2939121Smrg	use_static_libs=$prefer_static_libs
84128292847cSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8413c2939121Smrg	  use_static_libs=no
8414c2939121Smrg	fi
8415c2939121Smrg	if test -n "$library_names" &&
84168292847cSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8417c2939121Smrg	  case $host in
84188292847cSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8419c2939121Smrg	      # No point in relinking DLLs because paths are not encoded
84202836776bSmrg	      func_append notinst_deplibs " $lib"
8421c2939121Smrg	      need_relink=no
8422c2939121Smrg	    ;;
8423c2939121Smrg	  *)
84248292847cSmrg	    if test no = "$installed"; then
84252836776bSmrg	      func_append notinst_deplibs " $lib"
8426c2939121Smrg	      need_relink=yes
8427c2939121Smrg	    fi
8428c2939121Smrg	    ;;
8429c2939121Smrg	  esac
8430c2939121Smrg	  # This is a shared library
8431c2939121Smrg
8432c2939121Smrg	  # Warn about portability, can't link against -module's on some
8433c2939121Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
84348292847cSmrg	  dlopenmodule=
8435c2939121Smrg	  for dlpremoduletest in $dlprefiles; do
8436c2939121Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
84378292847cSmrg	      dlopenmodule=$dlpremoduletest
8438c2939121Smrg	      break
8439c2939121Smrg	    fi
8440c2939121Smrg	  done
84418292847cSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8442c2939121Smrg	    echo
84438292847cSmrg	    if test prog = "$linkmode"; then
8444c2939121Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8445c2939121Smrg	    else
8446c2939121Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8447c2939121Smrg	    fi
8448c2939121Smrg	    $ECHO "*** $linklib is not portable!"
8449c2939121Smrg	  fi
84508292847cSmrg	  if test lib = "$linkmode" &&
84518292847cSmrg	     test yes = "$hardcode_into_libs"; then
8452c2939121Smrg	    # Hardcode the library path.
8453c2939121Smrg	    # Skip directories that are in the system default run-time
8454c2939121Smrg	    # search path.
8455c2939121Smrg	    case " $sys_lib_dlsearch_path " in
8456c2939121Smrg	    *" $absdir "*) ;;
8457c2939121Smrg	    *)
8458c2939121Smrg	      case "$compile_rpath " in
8459c2939121Smrg	      *" $absdir "*) ;;
84602836776bSmrg	      *) func_append compile_rpath " $absdir" ;;
8461c2939121Smrg	      esac
8462c2939121Smrg	      ;;
8463c2939121Smrg	    esac
8464c2939121Smrg	    case " $sys_lib_dlsearch_path " in
8465c2939121Smrg	    *" $libdir "*) ;;
8466c2939121Smrg	    *)
8467c2939121Smrg	      case "$finalize_rpath " in
8468c2939121Smrg	      *" $libdir "*) ;;
84692836776bSmrg	      *) func_append finalize_rpath " $libdir" ;;
8470c2939121Smrg	      esac
8471c2939121Smrg	      ;;
8472c2939121Smrg	    esac
8473c2939121Smrg	  fi
8474c2939121Smrg
8475c2939121Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8476c2939121Smrg	    # figure out the soname
8477c2939121Smrg	    set dummy $library_names
8478c2939121Smrg	    shift
84798292847cSmrg	    realname=$1
8480c2939121Smrg	    shift
8481c2939121Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8482c2939121Smrg	    # use dlname if we got it. it's perfectly good, no?
8483c2939121Smrg	    if test -n "$dlname"; then
84848292847cSmrg	      soname=$dlname
8485c2939121Smrg	    elif test -n "$soname_spec"; then
8486c2939121Smrg	      # bleh windows
8487c2939121Smrg	      case $host in
84888292847cSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8489c2939121Smrg	        func_arith $current - $age
8490c2939121Smrg		major=$func_arith_result
84918292847cSmrg		versuffix=-$major
8492c2939121Smrg		;;
8493c2939121Smrg	      esac
8494c2939121Smrg	      eval soname=\"$soname_spec\"
8495c2939121Smrg	    else
84968292847cSmrg	      soname=$realname
8497c2939121Smrg	    fi
8498c2939121Smrg
8499c2939121Smrg	    # Make a new name for the extract_expsyms_cmds to use
85008292847cSmrg	    soroot=$soname
8501c2939121Smrg	    func_basename "$soroot"
85028292847cSmrg	    soname=$func_basename_result
8503c2939121Smrg	    func_stripname 'lib' '.dll' "$soname"
8504c2939121Smrg	    newlib=libimp-$func_stripname_result.a
8505c2939121Smrg
8506c2939121Smrg	    # If the library has no export list, then create one now
8507c2939121Smrg	    if test -f "$output_objdir/$soname-def"; then :
8508c2939121Smrg	    else
85098292847cSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8510c2939121Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8511c2939121Smrg	    fi
8512c2939121Smrg
8513c2939121Smrg	    # Create $newlib
8514c2939121Smrg	    if test -f "$output_objdir/$newlib"; then :; else
85158292847cSmrg	      func_verbose "generating import library for '$soname'"
8516c2939121Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8517c2939121Smrg	    fi
8518c2939121Smrg	    # make sure the library variables are pointing to the new library
8519c2939121Smrg	    dir=$output_objdir
8520c2939121Smrg	    linklib=$newlib
8521c2939121Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8522c2939121Smrg
85238292847cSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8524c2939121Smrg	    add_shlibpath=
8525c2939121Smrg	    add_dir=
8526c2939121Smrg	    add=
8527c2939121Smrg	    lib_linked=yes
8528c2939121Smrg	    case $hardcode_action in
8529c2939121Smrg	    immediate | unsupported)
85308292847cSmrg	      if test no = "$hardcode_direct"; then
85318292847cSmrg		add=$dir/$linklib
8532c2939121Smrg		case $host in
85338292847cSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
85348292847cSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8535c2939121Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
85368292847cSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8537c2939121Smrg		  *-*-darwin* )
85388292847cSmrg		    # if the lib is a (non-dlopened) module then we cannot
8539c2939121Smrg		    # link against it, someone is ignoring the earlier warnings
8540c2939121Smrg		    if /usr/bin/file -L $add 2> /dev/null |
85418292847cSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8542c2939121Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8543c2939121Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
85448292847cSmrg			if test -z "$old_library"; then
8545c2939121Smrg			  echo
8546c2939121Smrg			  echo "*** And there doesn't seem to be a static archive available"
8547c2939121Smrg			  echo "*** The link will probably fail, sorry"
8548c2939121Smrg			else
85498292847cSmrg			  add=$dir/$old_library
8550c2939121Smrg			fi
8551c2939121Smrg		      elif test -n "$old_library"; then
85528292847cSmrg			add=$dir/$old_library
8553c2939121Smrg		      fi
8554c2939121Smrg		    fi
8555c2939121Smrg		esac
85568292847cSmrg	      elif test no = "$hardcode_minus_L"; then
8557c2939121Smrg		case $host in
85588292847cSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8559c2939121Smrg		esac
85608292847cSmrg		add_dir=-L$dir
85618292847cSmrg		add=-l$name
85628292847cSmrg	      elif test no = "$hardcode_shlibpath_var"; then
85638292847cSmrg		add_shlibpath=$dir
85648292847cSmrg		add=-l$name
8565c2939121Smrg	      else
8566c2939121Smrg		lib_linked=no
8567c2939121Smrg	      fi
8568c2939121Smrg	      ;;
8569c2939121Smrg	    relink)
85708292847cSmrg	      if test yes = "$hardcode_direct" &&
85718292847cSmrg	         test no = "$hardcode_direct_absolute"; then
85728292847cSmrg		add=$dir/$linklib
85738292847cSmrg	      elif test yes = "$hardcode_minus_L"; then
85748292847cSmrg		add_dir=-L$absdir
8575c2939121Smrg		# Try looking first in the location we're being installed to.
8576c2939121Smrg		if test -n "$inst_prefix_dir"; then
8577c2939121Smrg		  case $libdir in
8578c2939121Smrg		    [\\/]*)
85792836776bSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8580c2939121Smrg		      ;;
8581c2939121Smrg		  esac
8582c2939121Smrg		fi
85838292847cSmrg		add=-l$name
85848292847cSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
85858292847cSmrg		add_shlibpath=$dir
85868292847cSmrg		add=-l$name
8587c2939121Smrg	      else
8588c2939121Smrg		lib_linked=no
8589c2939121Smrg	      fi
8590c2939121Smrg	      ;;
8591c2939121Smrg	    *) lib_linked=no ;;
8592c2939121Smrg	    esac
8593c2939121Smrg
85948292847cSmrg	    if test yes != "$lib_linked"; then
8595c2939121Smrg	      func_fatal_configuration "unsupported hardcode properties"
8596c2939121Smrg	    fi
8597c2939121Smrg
8598c2939121Smrg	    if test -n "$add_shlibpath"; then
8599c2939121Smrg	      case :$compile_shlibpath: in
8600c2939121Smrg	      *":$add_shlibpath:"*) ;;
86012836776bSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8602c2939121Smrg	      esac
8603c2939121Smrg	    fi
86048292847cSmrg	    if test prog = "$linkmode"; then
8605c2939121Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8606c2939121Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8607c2939121Smrg	    else
8608c2939121Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8609c2939121Smrg	      test -n "$add" && deplibs="$add $deplibs"
86108292847cSmrg	      if test yes != "$hardcode_direct" &&
86118292847cSmrg		 test yes != "$hardcode_minus_L" &&
86128292847cSmrg		 test yes = "$hardcode_shlibpath_var"; then
8613c2939121Smrg		case :$finalize_shlibpath: in
8614c2939121Smrg		*":$libdir:"*) ;;
86152836776bSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8616c2939121Smrg		esac
8617c2939121Smrg	      fi
8618c2939121Smrg	    fi
8619c2939121Smrg	  fi
8620c2939121Smrg
86218292847cSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8622c2939121Smrg	    add_shlibpath=
8623c2939121Smrg	    add_dir=
8624c2939121Smrg	    add=
8625c2939121Smrg	    # Finalize command for both is simple: just hardcode it.
86268292847cSmrg	    if test yes = "$hardcode_direct" &&
86278292847cSmrg	       test no = "$hardcode_direct_absolute"; then
86288292847cSmrg	      add=$libdir/$linklib
86298292847cSmrg	    elif test yes = "$hardcode_minus_L"; then
86308292847cSmrg	      add_dir=-L$libdir
86318292847cSmrg	      add=-l$name
86328292847cSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8633c2939121Smrg	      case :$finalize_shlibpath: in
8634c2939121Smrg	      *":$libdir:"*) ;;
86352836776bSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8636c2939121Smrg	      esac
86378292847cSmrg	      add=-l$name
86388292847cSmrg	    elif test yes = "$hardcode_automatic"; then
8639c2939121Smrg	      if test -n "$inst_prefix_dir" &&
86408292847cSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
86418292847cSmrg		add=$inst_prefix_dir$libdir/$linklib
8642c2939121Smrg	      else
86438292847cSmrg		add=$libdir/$linklib
8644c2939121Smrg	      fi
8645c2939121Smrg	    else
8646c2939121Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
86478292847cSmrg	      add_dir=-L$libdir
8648c2939121Smrg	      # Try looking first in the location we're being installed to.
8649c2939121Smrg	      if test -n "$inst_prefix_dir"; then
8650c2939121Smrg		case $libdir in
8651c2939121Smrg		  [\\/]*)
86522836776bSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8653c2939121Smrg		    ;;
8654c2939121Smrg		esac
8655c2939121Smrg	      fi
86568292847cSmrg	      add=-l$name
8657c2939121Smrg	    fi
8658c2939121Smrg
86598292847cSmrg	    if test prog = "$linkmode"; then
8660c2939121Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8661c2939121Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8662c2939121Smrg	    else
8663c2939121Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8664c2939121Smrg	      test -n "$add" && deplibs="$add $deplibs"
8665c2939121Smrg	    fi
8666c2939121Smrg	  fi
86678292847cSmrg	elif test prog = "$linkmode"; then
8668c2939121Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8669c2939121Smrg	  # is not unsupported.  This is valid on all known static and
8670c2939121Smrg	  # shared platforms.
86718292847cSmrg	  if test unsupported != "$hardcode_direct"; then
86728292847cSmrg	    test -n "$old_library" && linklib=$old_library
8673c2939121Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8674c2939121Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8675c2939121Smrg	  else
8676c2939121Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8677c2939121Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8678c2939121Smrg	  fi
86798292847cSmrg	elif test yes = "$build_libtool_libs"; then
8680c2939121Smrg	  # Not a shared library
86818292847cSmrg	  if test pass_all != "$deplibs_check_method"; then
8682c2939121Smrg	    # We're trying link a shared library against a static one
8683c2939121Smrg	    # but the system doesn't support it.
8684c2939121Smrg
8685c2939121Smrg	    # Just print a warning and add the library to dependency_libs so
8686c2939121Smrg	    # that the program can be linked against the static library.
8687c2939121Smrg	    echo
86888292847cSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8689c2939121Smrg	    echo "*** I have the capability to make that library automatically link in when"
8690c2939121Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
8691c2939121Smrg	    echo "*** shared version of the library, which you do not appear to have."
86928292847cSmrg	    if test yes = "$module"; then
8693c2939121Smrg	      echo "*** But as you try to build a module library, libtool will still create "
8694c2939121Smrg	      echo "*** a static module, that should work as long as the dlopening application"
8695c2939121Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8696c2939121Smrg	      if test -z "$global_symbol_pipe"; then
8697c2939121Smrg		echo
8698c2939121Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
86998292847cSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8700c2939121Smrg		echo "*** not find such a program.  So, this module is probably useless."
87018292847cSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8702c2939121Smrg	      fi
87038292847cSmrg	      if test no = "$build_old_libs"; then
8704c2939121Smrg		build_libtool_libs=module
8705c2939121Smrg		build_old_libs=yes
8706c2939121Smrg	      else
8707c2939121Smrg		build_libtool_libs=no
8708c2939121Smrg	      fi
8709c2939121Smrg	    fi
8710c2939121Smrg	  else
8711c2939121Smrg	    deplibs="$dir/$old_library $deplibs"
8712c2939121Smrg	    link_static=yes
8713c2939121Smrg	  fi
8714c2939121Smrg	fi # link shared/static library?
8715c2939121Smrg
87168292847cSmrg	if test lib = "$linkmode"; then
8717c2939121Smrg	  if test -n "$dependency_libs" &&
87188292847cSmrg	     { test yes != "$hardcode_into_libs" ||
87198292847cSmrg	       test yes = "$build_old_libs" ||
87208292847cSmrg	       test yes = "$link_static"; }; then
8721c2939121Smrg	    # Extract -R from dependency_libs
8722c2939121Smrg	    temp_deplibs=
8723c2939121Smrg	    for libdir in $dependency_libs; do
8724c2939121Smrg	      case $libdir in
8725c2939121Smrg	      -R*) func_stripname '-R' '' "$libdir"
8726c2939121Smrg	           temp_xrpath=$func_stripname_result
8727c2939121Smrg		   case " $xrpath " in
8728c2939121Smrg		   *" $temp_xrpath "*) ;;
87292836776bSmrg		   *) func_append xrpath " $temp_xrpath";;
8730c2939121Smrg		   esac;;
87312836776bSmrg	      *) func_append temp_deplibs " $libdir";;
8732c2939121Smrg	      esac
8733c2939121Smrg	    done
87348292847cSmrg	    dependency_libs=$temp_deplibs
8735c2939121Smrg	  fi
8736c2939121Smrg
87372836776bSmrg	  func_append newlib_search_path " $absdir"
8738c2939121Smrg	  # Link against this library
87398292847cSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8740c2939121Smrg	  # ... and its dependency_libs
8741c2939121Smrg	  tmp_libs=
8742c2939121Smrg	  for deplib in $dependency_libs; do
8743c2939121Smrg	    newdependency_libs="$deplib $newdependency_libs"
87442836776bSmrg	    case $deplib in
87452836776bSmrg              -L*) func_stripname '-L' '' "$deplib"
87462836776bSmrg                   func_resolve_sysroot "$func_stripname_result";;
87472836776bSmrg              *) func_resolve_sysroot "$deplib" ;;
87482836776bSmrg            esac
87498292847cSmrg	    if $opt_preserve_dup_deps; then
8750c2939121Smrg	      case "$tmp_libs " in
87512836776bSmrg	      *" $func_resolve_sysroot_result "*)
87522836776bSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8753c2939121Smrg	      esac
8754c2939121Smrg	    fi
87552836776bSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8756c2939121Smrg	  done
8757c2939121Smrg
87588292847cSmrg	  if test no != "$link_all_deplibs"; then
8759c2939121Smrg	    # Add the search paths of all dependency libraries
8760c2939121Smrg	    for deplib in $dependency_libs; do
8761c2939121Smrg	      path=
8762c2939121Smrg	      case $deplib in
87638292847cSmrg	      -L*) path=$deplib ;;
8764c2939121Smrg	      *.la)
87652836776bSmrg	        func_resolve_sysroot "$deplib"
87662836776bSmrg	        deplib=$func_resolve_sysroot_result
8767c2939121Smrg	        func_dirname "$deplib" "" "."
87682836776bSmrg		dir=$func_dirname_result
8769c2939121Smrg		# We need an absolute path.
8770c2939121Smrg		case $dir in
87718292847cSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8772c2939121Smrg		*)
8773c2939121Smrg		  absdir=`cd "$dir" && pwd`
8774c2939121Smrg		  if test -z "$absdir"; then
87758292847cSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
87768292847cSmrg		    absdir=$dir
8777c2939121Smrg		  fi
8778c2939121Smrg		  ;;
8779c2939121Smrg		esac
8780c2939121Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8781c2939121Smrg		case $host in
8782c2939121Smrg		*-*-darwin*)
8783c2939121Smrg		  depdepl=
87848292847cSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
87858292847cSmrg		  if test -n "$deplibrary_names"; then
87868292847cSmrg		    for tmp in $deplibrary_names; do
8787c2939121Smrg		      depdepl=$tmp
8788c2939121Smrg		    done
87898292847cSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
87908292847cSmrg		      depdepl=$absdir/$objdir/$depdepl
87918292847cSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8792c2939121Smrg                      if test -z "$darwin_install_name"; then
87938292847cSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8794c2939121Smrg                      fi
87958292847cSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
87968292847cSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8797c2939121Smrg		      path=
8798c2939121Smrg		    fi
8799c2939121Smrg		  fi
8800c2939121Smrg		  ;;
8801c2939121Smrg		*)
88028292847cSmrg		  path=-L$absdir/$objdir
8803c2939121Smrg		  ;;
8804c2939121Smrg		esac
8805c2939121Smrg		else
88068292847cSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8807c2939121Smrg		  test -z "$libdir" && \
88088292847cSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8809c2939121Smrg		  test "$absdir" != "$libdir" && \
88108292847cSmrg		    func_warning "'$deplib' seems to be moved"
8811c2939121Smrg
88128292847cSmrg		  path=-L$absdir
8813c2939121Smrg		fi
8814c2939121Smrg		;;
8815c2939121Smrg	      esac
8816c2939121Smrg	      case " $deplibs " in
8817c2939121Smrg	      *" $path "*) ;;
8818c2939121Smrg	      *) deplibs="$path $deplibs" ;;
8819c2939121Smrg	      esac
8820c2939121Smrg	    done
8821c2939121Smrg	  fi # link_all_deplibs != no
8822c2939121Smrg	fi # linkmode = lib
8823c2939121Smrg      done # for deplib in $libs
88248292847cSmrg      if test link = "$pass"; then
88258292847cSmrg	if test prog = "$linkmode"; then
8826c2939121Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8827c2939121Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8828c2939121Smrg	else
8829c2939121Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8830c2939121Smrg	fi
8831c2939121Smrg      fi
88328292847cSmrg      dependency_libs=$newdependency_libs
88338292847cSmrg      if test dlpreopen = "$pass"; then
8834c2939121Smrg	# Link the dlpreopened libraries before other libraries
8835c2939121Smrg	for deplib in $save_deplibs; do
8836c2939121Smrg	  deplibs="$deplib $deplibs"
8837c2939121Smrg	done
8838c2939121Smrg      fi
88398292847cSmrg      if test dlopen != "$pass"; then
88408292847cSmrg	test conv = "$pass" || {
8841c2939121Smrg	  # Make sure lib_search_path contains only unique directories.
8842c2939121Smrg	  lib_search_path=
8843c2939121Smrg	  for dir in $newlib_search_path; do
8844c2939121Smrg	    case "$lib_search_path " in
8845c2939121Smrg	    *" $dir "*) ;;
88462836776bSmrg	    *) func_append lib_search_path " $dir" ;;
8847c2939121Smrg	    esac
8848c2939121Smrg	  done
8849c2939121Smrg	  newlib_search_path=
88508292847cSmrg	}
8851c2939121Smrg
88528292847cSmrg	if test prog,link = "$linkmode,$pass"; then
8853c2939121Smrg	  vars="compile_deplibs finalize_deplibs"
88548292847cSmrg	else
88558292847cSmrg	  vars=deplibs
8856c2939121Smrg	fi
8857c2939121Smrg	for var in $vars dependency_libs; do
8858c2939121Smrg	  # Add libraries to $var in reverse order
8859c2939121Smrg	  eval tmp_libs=\"\$$var\"
8860c2939121Smrg	  new_libs=
8861c2939121Smrg	  for deplib in $tmp_libs; do
8862c2939121Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8863c2939121Smrg	    #        that some nasty dependency loop isn't accidentally
8864c2939121Smrg	    #        broken:
8865c2939121Smrg	    #new_libs="$deplib $new_libs"
8866c2939121Smrg	    # Pragmatically, this seems to cause very few problems in
8867c2939121Smrg	    # practice:
8868c2939121Smrg	    case $deplib in
8869c2939121Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8870c2939121Smrg	    -R*) ;;
8871c2939121Smrg	    *)
8872c2939121Smrg	      # And here is the reason: when a library appears more
8873c2939121Smrg	      # than once as an explicit dependence of a library, or
8874c2939121Smrg	      # is implicitly linked in more than once by the
8875c2939121Smrg	      # compiler, it is considered special, and multiple
8876c2939121Smrg	      # occurrences thereof are not removed.  Compare this
8877c2939121Smrg	      # with having the same library being listed as a
8878c2939121Smrg	      # dependency of multiple other libraries: in this case,
8879c2939121Smrg	      # we know (pedantically, we assume) the library does not
8880c2939121Smrg	      # need to be listed more than once, so we keep only the
8881c2939121Smrg	      # last copy.  This is not always right, but it is rare
8882c2939121Smrg	      # enough that we require users that really mean to play
8883c2939121Smrg	      # such unportable linking tricks to link the library
8884c2939121Smrg	      # using -Wl,-lname, so that libtool does not consider it
8885c2939121Smrg	      # for duplicate removal.
8886c2939121Smrg	      case " $specialdeplibs " in
8887c2939121Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8888c2939121Smrg	      *)
8889c2939121Smrg		case " $new_libs " in
8890c2939121Smrg		*" $deplib "*) ;;
8891c2939121Smrg		*) new_libs="$deplib $new_libs" ;;
8892c2939121Smrg		esac
8893c2939121Smrg		;;
8894c2939121Smrg	      esac
8895c2939121Smrg	      ;;
8896c2939121Smrg	    esac
8897c2939121Smrg	  done
8898c2939121Smrg	  tmp_libs=
8899c2939121Smrg	  for deplib in $new_libs; do
8900c2939121Smrg	    case $deplib in
8901c2939121Smrg	    -L*)
8902c2939121Smrg	      case " $tmp_libs " in
8903c2939121Smrg	      *" $deplib "*) ;;
89042836776bSmrg	      *) func_append tmp_libs " $deplib" ;;
8905c2939121Smrg	      esac
8906c2939121Smrg	      ;;
89072836776bSmrg	    *) func_append tmp_libs " $deplib" ;;
8908c2939121Smrg	    esac
8909c2939121Smrg	  done
8910c2939121Smrg	  eval $var=\"$tmp_libs\"
8911c2939121Smrg	done # for var
8912c2939121Smrg      fi
89138292847cSmrg
89148292847cSmrg      # Add Sun CC postdeps if required:
89158292847cSmrg      test CXX = "$tagname" && {
89168292847cSmrg        case $host_os in
89178292847cSmrg        linux*)
891825420f97Smrg          case `$CC -V 2>&1 | $SED 5q` in
89198292847cSmrg          *Sun\ C*) # Sun C++ 5.9
89208292847cSmrg            func_suncc_cstd_abi
89218292847cSmrg
89228292847cSmrg            if test no != "$suncc_use_cstd_abi"; then
89238292847cSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89248292847cSmrg            fi
89258292847cSmrg            ;;
89268292847cSmrg          esac
89278292847cSmrg          ;;
89288292847cSmrg
89298292847cSmrg        solaris*)
89308292847cSmrg          func_cc_basename "$CC"
89318292847cSmrg          case $func_cc_basename_result in
89328292847cSmrg          CC* | sunCC*)
89338292847cSmrg            func_suncc_cstd_abi
89348292847cSmrg
89358292847cSmrg            if test no != "$suncc_use_cstd_abi"; then
89368292847cSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89378292847cSmrg            fi
89388292847cSmrg            ;;
89398292847cSmrg          esac
89408292847cSmrg          ;;
89418292847cSmrg        esac
89428292847cSmrg      }
89438292847cSmrg
8944c2939121Smrg      # Last step: remove runtime libs from dependency_libs
8945c2939121Smrg      # (they stay in deplibs)
8946c2939121Smrg      tmp_libs=
89478292847cSmrg      for i in $dependency_libs; do
8948c2939121Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8949c2939121Smrg	*" $i "*)
89508292847cSmrg	  i=
8951c2939121Smrg	  ;;
8952c2939121Smrg	esac
89538292847cSmrg	if test -n "$i"; then
89542836776bSmrg	  func_append tmp_libs " $i"
8955c2939121Smrg	fi
8956c2939121Smrg      done
8957c2939121Smrg      dependency_libs=$tmp_libs
8958c2939121Smrg    done # for pass
89598292847cSmrg    if test prog = "$linkmode"; then
89608292847cSmrg      dlfiles=$newdlfiles
8961c2939121Smrg    fi
89628292847cSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
89638292847cSmrg      dlprefiles=$newdlprefiles
8964c2939121Smrg    fi
8965c2939121Smrg
8966c2939121Smrg    case $linkmode in
8967c2939121Smrg    oldlib)
89688292847cSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
89698292847cSmrg	func_warning "'-dlopen' is ignored for archives"
8970c2939121Smrg      fi
8971c2939121Smrg
8972c2939121Smrg      case " $deplibs" in
8973c2939121Smrg      *\ -l* | *\ -L*)
89748292847cSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8975c2939121Smrg      esac
8976c2939121Smrg
8977c2939121Smrg      test -n "$rpath" && \
89788292847cSmrg	func_warning "'-rpath' is ignored for archives"
8979c2939121Smrg
8980c2939121Smrg      test -n "$xrpath" && \
89818292847cSmrg	func_warning "'-R' is ignored for archives"
8982c2939121Smrg
8983c2939121Smrg      test -n "$vinfo" && \
89848292847cSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8985c2939121Smrg
8986c2939121Smrg      test -n "$release" && \
89878292847cSmrg	func_warning "'-release' is ignored for archives"
8988c2939121Smrg
8989c2939121Smrg      test -n "$export_symbols$export_symbols_regex" && \
89908292847cSmrg	func_warning "'-export-symbols' is ignored for archives"
8991c2939121Smrg
8992c2939121Smrg      # Now set the variables for building old libraries.
8993c2939121Smrg      build_libtool_libs=no
89948292847cSmrg      oldlibs=$output
89952836776bSmrg      func_append objs "$old_deplibs"
8996c2939121Smrg      ;;
8997c2939121Smrg
8998c2939121Smrg    lib)
89998292847cSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9000c2939121Smrg      case $outputname in
9001c2939121Smrg      lib*)
9002c2939121Smrg	func_stripname 'lib' '.la' "$outputname"
9003c2939121Smrg	name=$func_stripname_result
9004c2939121Smrg	eval shared_ext=\"$shrext_cmds\"
9005c2939121Smrg	eval libname=\"$libname_spec\"
9006c2939121Smrg	;;
9007c2939121Smrg      *)
90088292847cSmrg	test no = "$module" \
90098292847cSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9010c2939121Smrg
90118292847cSmrg	if test no != "$need_lib_prefix"; then
9012c2939121Smrg	  # Add the "lib" prefix for modules if required
9013c2939121Smrg	  func_stripname '' '.la' "$outputname"
9014c2939121Smrg	  name=$func_stripname_result
9015c2939121Smrg	  eval shared_ext=\"$shrext_cmds\"
9016c2939121Smrg	  eval libname=\"$libname_spec\"
9017c2939121Smrg	else
9018c2939121Smrg	  func_stripname '' '.la' "$outputname"
9019c2939121Smrg	  libname=$func_stripname_result
9020c2939121Smrg	fi
9021c2939121Smrg	;;
9022c2939121Smrg      esac
9023c2939121Smrg
9024c2939121Smrg      if test -n "$objs"; then
90258292847cSmrg	if test pass_all != "$deplibs_check_method"; then
90268292847cSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9027c2939121Smrg	else
9028c2939121Smrg	  echo
9029c2939121Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9030c2939121Smrg	  $ECHO "*** objects $objs is not portable!"
90312836776bSmrg	  func_append libobjs " $objs"
9032c2939121Smrg	fi
9033c2939121Smrg      fi
9034c2939121Smrg
90358292847cSmrg      test no = "$dlself" \
90368292847cSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9037c2939121Smrg
9038c2939121Smrg      set dummy $rpath
9039c2939121Smrg      shift
90408292847cSmrg      test 1 -lt "$#" \
90418292847cSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9042c2939121Smrg
90438292847cSmrg      install_libdir=$1
9044c2939121Smrg
9045c2939121Smrg      oldlibs=
9046c2939121Smrg      if test -z "$rpath"; then
90478292847cSmrg	if test yes = "$build_libtool_libs"; then
9048c2939121Smrg	  # Building a libtool convenience library.
90498292847cSmrg	  # Some compilers have problems with a '.al' extension so
9050c2939121Smrg	  # convenience libraries should have the same extension an
9051c2939121Smrg	  # archive normally would.
9052c2939121Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9053c2939121Smrg	  build_libtool_libs=convenience
9054c2939121Smrg	  build_old_libs=yes
9055c2939121Smrg	fi
9056c2939121Smrg
9057c2939121Smrg	test -n "$vinfo" && \
90588292847cSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9059c2939121Smrg
9060c2939121Smrg	test -n "$release" && \
90618292847cSmrg	  func_warning "'-release' is ignored for convenience libraries"
9062c2939121Smrg      else
9063c2939121Smrg
9064c2939121Smrg	# Parse the version information argument.
90658292847cSmrg	save_ifs=$IFS; IFS=:
9066c2939121Smrg	set dummy $vinfo 0 0 0
9067c2939121Smrg	shift
90688292847cSmrg	IFS=$save_ifs
9069c2939121Smrg
9070c2939121Smrg	test -n "$7" && \
90718292847cSmrg	  func_fatal_help "too many parameters to '-version-info'"
9072c2939121Smrg
9073c2939121Smrg	# convert absolute version numbers to libtool ages
9074c2939121Smrg	# this retains compatibility with .la files and attempts
9075c2939121Smrg	# to make the code below a bit more comprehensible
9076c2939121Smrg
9077c2939121Smrg	case $vinfo_number in
9078c2939121Smrg	yes)
90798292847cSmrg	  number_major=$1
90808292847cSmrg	  number_minor=$2
90818292847cSmrg	  number_revision=$3
9082c2939121Smrg	  #
9083c2939121Smrg	  # There are really only two kinds -- those that
9084c2939121Smrg	  # use the current revision as the major version
9085c2939121Smrg	  # and those that subtract age and use age as
9086c2939121Smrg	  # a minor version.  But, then there is irix
90878292847cSmrg	  # that has an extra 1 added just for fun
9088c2939121Smrg	  #
9089c2939121Smrg	  case $version_type in
90902836776bSmrg	  # correct linux to gnu/linux during the next big refactor
909125420f97Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9092c2939121Smrg	    func_arith $number_major + $number_minor
9093c2939121Smrg	    current=$func_arith_result
90948292847cSmrg	    age=$number_minor
90958292847cSmrg	    revision=$number_revision
9096c2939121Smrg	    ;;
90978292847cSmrg	  freebsd-aout|qnx|sunos)
90988292847cSmrg	    current=$number_major
90998292847cSmrg	    revision=$number_minor
91008292847cSmrg	    age=0
9101c2939121Smrg	    ;;
9102c2939121Smrg	  irix|nonstopux)
9103c2939121Smrg	    func_arith $number_major + $number_minor
9104c2939121Smrg	    current=$func_arith_result
91058292847cSmrg	    age=$number_minor
91068292847cSmrg	    revision=$number_minor
9107c2939121Smrg	    lt_irix_increment=no
9108c2939121Smrg	    ;;
9109de301c82Smrg	  *)
9110de301c82Smrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
9111de301c82Smrg	    ;;
9112c2939121Smrg	  esac
9113c2939121Smrg	  ;;
9114c2939121Smrg	no)
91158292847cSmrg	  current=$1
91168292847cSmrg	  revision=$2
91178292847cSmrg	  age=$3
9118c2939121Smrg	  ;;
9119c2939121Smrg	esac
9120c2939121Smrg
9121c2939121Smrg	# Check that each of the things are valid numbers.
9122c2939121Smrg	case $current in
9123c2939121Smrg	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]) ;;
9124c2939121Smrg	*)
91258292847cSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
91268292847cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9127c2939121Smrg	  ;;
9128c2939121Smrg	esac
9129c2939121Smrg
9130c2939121Smrg	case $revision in
9131c2939121Smrg	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]) ;;
9132c2939121Smrg	*)
91338292847cSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
91348292847cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9135c2939121Smrg	  ;;
9136c2939121Smrg	esac
9137c2939121Smrg
9138c2939121Smrg	case $age in
9139c2939121Smrg	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]) ;;
9140c2939121Smrg	*)
91418292847cSmrg	  func_error "AGE '$age' must be a nonnegative integer"
91428292847cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9143c2939121Smrg	  ;;
9144c2939121Smrg	esac
9145c2939121Smrg
9146c2939121Smrg	if test "$age" -gt "$current"; then
91478292847cSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
91488292847cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9149c2939121Smrg	fi
9150c2939121Smrg
9151c2939121Smrg	# Calculate the version variables.
9152c2939121Smrg	major=
9153c2939121Smrg	versuffix=
9154c2939121Smrg	verstring=
9155c2939121Smrg	case $version_type in
9156c2939121Smrg	none) ;;
9157c2939121Smrg
9158c2939121Smrg	darwin)
9159c2939121Smrg	  # Like Linux, but with the current version available in
9160c2939121Smrg	  # verstring for coding it into the library header
9161c2939121Smrg	  func_arith $current - $age
9162c2939121Smrg	  major=.$func_arith_result
91638292847cSmrg	  versuffix=$major.$age.$revision
9164c2939121Smrg	  # Darwin ld doesn't like 0 for these options...
9165c2939121Smrg	  func_arith $current + 1
9166c2939121Smrg	  minor_current=$func_arith_result
91678292847cSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168c2939121Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91698292847cSmrg          # On Darwin other compilers
91708292847cSmrg          case $CC in
91718292847cSmrg              nagfor*)
91728292847cSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91738292847cSmrg                  ;;
91748292847cSmrg              *)
91758292847cSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91768292847cSmrg                  ;;
91778292847cSmrg          esac
9178c2939121Smrg	  ;;
9179c2939121Smrg
9180c2939121Smrg	freebsd-aout)
91818292847cSmrg	  major=.$current
91828292847cSmrg	  versuffix=.$current.$revision
9183c2939121Smrg	  ;;
9184c2939121Smrg
918525420f97Smrg	freebsd-elf | midnightbsd-elf)
91868292847cSmrg	  func_arith $current - $age
91878292847cSmrg	  major=.$func_arith_result
91888292847cSmrg	  versuffix=$major.$age.$revision
9189c2939121Smrg	  ;;
9190c2939121Smrg
9191c2939121Smrg	irix | nonstopux)
91928292847cSmrg	  if test no = "$lt_irix_increment"; then
9193c2939121Smrg	    func_arith $current - $age
9194c2939121Smrg	  else
9195c2939121Smrg	    func_arith $current - $age + 1
9196c2939121Smrg	  fi
9197c2939121Smrg	  major=$func_arith_result
9198c2939121Smrg
9199c2939121Smrg	  case $version_type in
9200c2939121Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9201c2939121Smrg	    *)         verstring_prefix=sgi ;;
9202c2939121Smrg	  esac
92038292847cSmrg	  verstring=$verstring_prefix$major.$revision
9204c2939121Smrg
9205c2939121Smrg	  # Add in all the interfaces that we are compatible with.
9206c2939121Smrg	  loop=$revision
92078292847cSmrg	  while test 0 -ne "$loop"; do
9208c2939121Smrg	    func_arith $revision - $loop
9209c2939121Smrg	    iface=$func_arith_result
9210c2939121Smrg	    func_arith $loop - 1
9211c2939121Smrg	    loop=$func_arith_result
92128292847cSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213c2939121Smrg	  done
9214c2939121Smrg
92158292847cSmrg	  # Before this point, $major must not contain '.'.
9216c2939121Smrg	  major=.$major
92178292847cSmrg	  versuffix=$major.$revision
9218c2939121Smrg	  ;;
9219c2939121Smrg
92202836776bSmrg	linux) # correct to gnu/linux during the next big refactor
9221c2939121Smrg	  func_arith $current - $age
9222c2939121Smrg	  major=.$func_arith_result
92238292847cSmrg	  versuffix=$major.$age.$revision
9224c2939121Smrg	  ;;
9225c2939121Smrg
9226c2939121Smrg	osf)
9227c2939121Smrg	  func_arith $current - $age
9228c2939121Smrg	  major=.$func_arith_result
92298292847cSmrg	  versuffix=.$current.$age.$revision
92308292847cSmrg	  verstring=$current.$age.$revision
9231c2939121Smrg
9232c2939121Smrg	  # Add in all the interfaces that we are compatible with.
9233c2939121Smrg	  loop=$age
92348292847cSmrg	  while test 0 -ne "$loop"; do
9235c2939121Smrg	    func_arith $current - $loop
9236c2939121Smrg	    iface=$func_arith_result
9237c2939121Smrg	    func_arith $loop - 1
9238c2939121Smrg	    loop=$func_arith_result
92398292847cSmrg	    verstring=$verstring:$iface.0
9240c2939121Smrg	  done
9241c2939121Smrg
9242c2939121Smrg	  # Make executables depend on our current version.
92438292847cSmrg	  func_append verstring ":$current.0"
9244c2939121Smrg	  ;;
9245c2939121Smrg
9246c2939121Smrg	qnx)
92478292847cSmrg	  major=.$current
92488292847cSmrg	  versuffix=.$current
92498292847cSmrg	  ;;
92508292847cSmrg
92518292847cSmrg	sco)
92528292847cSmrg	  major=.$current
92538292847cSmrg	  versuffix=.$current
9254c2939121Smrg	  ;;
9255c2939121Smrg
9256c2939121Smrg	sunos)
92578292847cSmrg	  major=.$current
92588292847cSmrg	  versuffix=.$current.$revision
9259c2939121Smrg	  ;;
9260c2939121Smrg
9261c2939121Smrg	windows)
9262c2939121Smrg	  # Use '-' rather than '.', since we only want one
92638292847cSmrg	  # extension on DOS 8.3 file systems.
9264c2939121Smrg	  func_arith $current - $age
9265c2939121Smrg	  major=$func_arith_result
92668292847cSmrg	  versuffix=-$major
9267c2939121Smrg	  ;;
9268c2939121Smrg
9269c2939121Smrg	*)
92708292847cSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271c2939121Smrg	  ;;
9272c2939121Smrg	esac
9273c2939121Smrg
9274c2939121Smrg	# Clear the version info if we defaulted, and they specified a release.
9275c2939121Smrg	if test -z "$vinfo" && test -n "$release"; then
9276c2939121Smrg	  major=
9277c2939121Smrg	  case $version_type in
9278c2939121Smrg	  darwin)
9279c2939121Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280c2939121Smrg	    # problems, so we reset it completely
9281c2939121Smrg	    verstring=
9282c2939121Smrg	    ;;
9283c2939121Smrg	  *)
92848292847cSmrg	    verstring=0.0
9285c2939121Smrg	    ;;
9286c2939121Smrg	  esac
92878292847cSmrg	  if test no = "$need_version"; then
9288c2939121Smrg	    versuffix=
9289c2939121Smrg	  else
92908292847cSmrg	    versuffix=.0.0
9291c2939121Smrg	  fi
9292c2939121Smrg	fi
9293c2939121Smrg
9294c2939121Smrg	# Remove version info from name if versioning should be avoided
92958292847cSmrg	if test yes,no = "$avoid_version,$need_version"; then
9296c2939121Smrg	  major=
9297c2939121Smrg	  versuffix=
92988292847cSmrg	  verstring=
9299c2939121Smrg	fi
9300c2939121Smrg
9301c2939121Smrg	# Check to see if the archive will have undefined symbols.
93028292847cSmrg	if test yes = "$allow_undefined"; then
93038292847cSmrg	  if test unsupported = "$allow_undefined_flag"; then
93048292847cSmrg	    if test yes = "$build_old_libs"; then
93058292847cSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
93068292847cSmrg	      build_libtool_libs=no
93078292847cSmrg	    else
93088292847cSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
93098292847cSmrg	    fi
9310c2939121Smrg	  fi
9311c2939121Smrg	else
9312c2939121Smrg	  # Don't allow undefined symbols.
93138292847cSmrg	  allow_undefined_flag=$no_undefined_flag
9314c2939121Smrg	fi
9315c2939121Smrg
9316c2939121Smrg      fi
9317c2939121Smrg
93188292847cSmrg      func_generate_dlsyms "$libname" "$libname" :
93192836776bSmrg      func_append libobjs " $symfileobj"
93208292847cSmrg      test " " = "$libobjs" && libobjs=
9321c2939121Smrg
93228292847cSmrg      if test relink != "$opt_mode"; then
9323c2939121Smrg	# Remove our outputs, but don't remove object files since they
9324c2939121Smrg	# may have been created when compiling PIC objects.
9325c2939121Smrg	removelist=
9326c2939121Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327c2939121Smrg	for p in $tempremovelist; do
9328c2939121Smrg	  case $p in
9329c2939121Smrg	    *.$objext | *.gcno)
9330c2939121Smrg	       ;;
93318292847cSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
93328292847cSmrg	       if test -n "$precious_files_regex"; then
9333c2939121Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334c2939121Smrg		 then
9335c2939121Smrg		   continue
9336c2939121Smrg		 fi
9337c2939121Smrg	       fi
93382836776bSmrg	       func_append removelist " $p"
9339c2939121Smrg	       ;;
9340c2939121Smrg	    *) ;;
9341c2939121Smrg	  esac
9342c2939121Smrg	done
9343c2939121Smrg	test -n "$removelist" && \
9344c2939121Smrg	  func_show_eval "${RM}r \$removelist"
9345c2939121Smrg      fi
9346c2939121Smrg
9347c2939121Smrg      # Now set the variables for building old libraries.
93488292847cSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
93492836776bSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350c2939121Smrg
9351c2939121Smrg	# Transform .lo files to .o files.
93528292847cSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353c2939121Smrg      fi
9354c2939121Smrg
9355c2939121Smrg      # Eliminate all temporary directories.
9356c2939121Smrg      #for path in $notinst_path; do
9357c2939121Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358c2939121Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359c2939121Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360c2939121Smrg      #done
9361c2939121Smrg
9362c2939121Smrg      if test -n "$xrpath"; then
9363c2939121Smrg	# If the user specified any rpath flags, then add them.
9364c2939121Smrg	temp_xrpath=
9365c2939121Smrg	for libdir in $xrpath; do
93662836776bSmrg	  func_replace_sysroot "$libdir"
93672836776bSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368c2939121Smrg	  case "$finalize_rpath " in
9369c2939121Smrg	  *" $libdir "*) ;;
93702836776bSmrg	  *) func_append finalize_rpath " $libdir" ;;
9371c2939121Smrg	  esac
9372c2939121Smrg	done
93738292847cSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374c2939121Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375c2939121Smrg	fi
9376c2939121Smrg      fi
9377c2939121Smrg
9378c2939121Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
93798292847cSmrg      old_dlfiles=$dlfiles
9380c2939121Smrg      dlfiles=
9381c2939121Smrg      for lib in $old_dlfiles; do
9382c2939121Smrg	case " $dlprefiles $dlfiles " in
9383c2939121Smrg	*" $lib "*) ;;
93842836776bSmrg	*) func_append dlfiles " $lib" ;;
9385c2939121Smrg	esac
9386c2939121Smrg      done
9387c2939121Smrg
9388c2939121Smrg      # Make sure dlprefiles contains only unique files
93898292847cSmrg      old_dlprefiles=$dlprefiles
9390c2939121Smrg      dlprefiles=
9391c2939121Smrg      for lib in $old_dlprefiles; do
9392c2939121Smrg	case "$dlprefiles " in
9393c2939121Smrg	*" $lib "*) ;;
93942836776bSmrg	*) func_append dlprefiles " $lib" ;;
9395c2939121Smrg	esac
9396c2939121Smrg      done
9397c2939121Smrg
93988292847cSmrg      if test yes = "$build_libtool_libs"; then
9399c2939121Smrg	if test -n "$rpath"; then
9400c2939121Smrg	  case $host in
9401c2939121Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402c2939121Smrg	    # these systems don't actually have a c library (as such)!
9403c2939121Smrg	    ;;
9404c2939121Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405c2939121Smrg	    # Rhapsody C library is in the System framework
94062836776bSmrg	    func_append deplibs " System.ltframework"
9407c2939121Smrg	    ;;
9408c2939121Smrg	  *-*-netbsd*)
9409c2939121Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9410c2939121Smrg	    ;;
941125420f97Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412c2939121Smrg	    # Do not include libc due to us having libc/libc_r.
9413c2939121Smrg	    ;;
9414c2939121Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415c2939121Smrg	    # Causes problems with __ctype
9416c2939121Smrg	    ;;
9417c2939121Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418c2939121Smrg	    # Compiler inserts libc in the correct place for threads to work
9419c2939121Smrg	    ;;
9420c2939121Smrg	  *)
9421c2939121Smrg	    # Add libc to deplibs on all other systems if necessary.
94228292847cSmrg	    if test yes = "$build_libtool_need_lc"; then
94232836776bSmrg	      func_append deplibs " -lc"
9424c2939121Smrg	    fi
9425c2939121Smrg	    ;;
9426c2939121Smrg	  esac
9427c2939121Smrg	fi
9428c2939121Smrg
9429c2939121Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9430c2939121Smrg	name_save=$name
9431c2939121Smrg	libname_save=$libname
9432c2939121Smrg	release_save=$release
9433c2939121Smrg	versuffix_save=$versuffix
9434c2939121Smrg	major_save=$major
9435c2939121Smrg	# I'm not sure if I'm treating the release correctly.  I think
9436c2939121Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437c2939121Smrg	# add it in twice.  Is that correct?
94388292847cSmrg	release=
94398292847cSmrg	versuffix=
94408292847cSmrg	major=
9441c2939121Smrg	newdeplibs=
9442c2939121Smrg	droppeddeps=no
9443c2939121Smrg	case $deplibs_check_method in
9444c2939121Smrg	pass_all)
9445c2939121Smrg	  # Don't check for shared/static.  Everything works.
9446c2939121Smrg	  # This might be a little naive.  We might want to check
9447c2939121Smrg	  # whether the library exists or not.  But this is on
9448c2939121Smrg	  # osf3 & osf4 and I'm not really sure... Just
9449c2939121Smrg	  # implementing what was already the behavior.
9450c2939121Smrg	  newdeplibs=$deplibs
9451c2939121Smrg	  ;;
9452c2939121Smrg	test_compile)
9453c2939121Smrg	  # This code stresses the "libraries are programs" paradigm to its
9454c2939121Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455c2939121Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9456c2939121Smrg	  # whether they linked in statically or dynamically with ldd.
9457c2939121Smrg	  $opt_dry_run || $RM conftest.c
9458c2939121Smrg	  cat > conftest.c <<EOF
9459c2939121Smrg	  int main() { return 0; }
9460c2939121SmrgEOF
9461c2939121Smrg	  $opt_dry_run || $RM conftest
9462c2939121Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463c2939121Smrg	    ldd_output=`ldd conftest`
9464c2939121Smrg	    for i in $deplibs; do
9465c2939121Smrg	      case $i in
9466c2939121Smrg	      -l*)
9467c2939121Smrg		func_stripname -l '' "$i"
9468c2939121Smrg		name=$func_stripname_result
94698292847cSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470c2939121Smrg		  case " $predeps $postdeps " in
9471c2939121Smrg		  *" $i "*)
94722836776bSmrg		    func_append newdeplibs " $i"
94738292847cSmrg		    i=
9474c2939121Smrg		    ;;
9475c2939121Smrg		  esac
9476c2939121Smrg		fi
94778292847cSmrg		if test -n "$i"; then
9478c2939121Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479c2939121Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480c2939121Smrg		  set dummy $deplib_matches; shift
9481c2939121Smrg		  deplib_match=$1
94828292847cSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
94832836776bSmrg		    func_append newdeplibs " $i"
9484c2939121Smrg		  else
9485c2939121Smrg		    droppeddeps=yes
9486c2939121Smrg		    echo
9487c2939121Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488c2939121Smrg		    echo "*** I have the capability to make that library automatically link in when"
9489c2939121Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490c2939121Smrg		    echo "*** shared version of the library, which I believe you do not have"
9491c2939121Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492c2939121Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493c2939121Smrg		  fi
9494c2939121Smrg		fi
9495c2939121Smrg		;;
9496c2939121Smrg	      *)
94972836776bSmrg		func_append newdeplibs " $i"
9498c2939121Smrg		;;
9499c2939121Smrg	      esac
9500c2939121Smrg	    done
9501c2939121Smrg	  else
9502c2939121Smrg	    # Error occurred in the first compile.  Let's try to salvage
9503c2939121Smrg	    # the situation: Compile a separate program for each library.
9504c2939121Smrg	    for i in $deplibs; do
9505c2939121Smrg	      case $i in
9506c2939121Smrg	      -l*)
9507c2939121Smrg		func_stripname -l '' "$i"
9508c2939121Smrg		name=$func_stripname_result
9509c2939121Smrg		$opt_dry_run || $RM conftest
9510c2939121Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511c2939121Smrg		  ldd_output=`ldd conftest`
95128292847cSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513c2939121Smrg		    case " $predeps $postdeps " in
9514c2939121Smrg		    *" $i "*)
95152836776bSmrg		      func_append newdeplibs " $i"
95168292847cSmrg		      i=
9517c2939121Smrg		      ;;
9518c2939121Smrg		    esac
9519c2939121Smrg		  fi
95208292847cSmrg		  if test -n "$i"; then
9521c2939121Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522c2939121Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523c2939121Smrg		    set dummy $deplib_matches; shift
9524c2939121Smrg		    deplib_match=$1
95258292847cSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
95262836776bSmrg		      func_append newdeplibs " $i"
9527c2939121Smrg		    else
9528c2939121Smrg		      droppeddeps=yes
9529c2939121Smrg		      echo
9530c2939121Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531c2939121Smrg		      echo "*** I have the capability to make that library automatically link in when"
9532c2939121Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533c2939121Smrg		      echo "*** shared version of the library, which you do not appear to have"
9534c2939121Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535c2939121Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536c2939121Smrg		    fi
9537c2939121Smrg		  fi
9538c2939121Smrg		else
9539c2939121Smrg		  droppeddeps=yes
9540c2939121Smrg		  echo
9541c2939121Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542c2939121Smrg		  echo "*** make it link in!  You will probably need to install it or some"
9543c2939121Smrg		  echo "*** library that it depends on before this library will be fully"
9544c2939121Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9545c2939121Smrg		fi
9546c2939121Smrg		;;
9547c2939121Smrg	      *)
95482836776bSmrg		func_append newdeplibs " $i"
9549c2939121Smrg		;;
9550c2939121Smrg	      esac
9551c2939121Smrg	    done
9552c2939121Smrg	  fi
9553c2939121Smrg	  ;;
9554c2939121Smrg	file_magic*)
9555c2939121Smrg	  set dummy $deplibs_check_method; shift
9556c2939121Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557c2939121Smrg	  for a_deplib in $deplibs; do
9558c2939121Smrg	    case $a_deplib in
9559c2939121Smrg	    -l*)
9560c2939121Smrg	      func_stripname -l '' "$a_deplib"
9561c2939121Smrg	      name=$func_stripname_result
95628292847cSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563c2939121Smrg		case " $predeps $postdeps " in
9564c2939121Smrg		*" $a_deplib "*)
95652836776bSmrg		  func_append newdeplibs " $a_deplib"
95668292847cSmrg		  a_deplib=
9567c2939121Smrg		  ;;
9568c2939121Smrg		esac
9569c2939121Smrg	      fi
95708292847cSmrg	      if test -n "$a_deplib"; then
9571c2939121Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
95722836776bSmrg		if test -n "$file_magic_glob"; then
95732836776bSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
95742836776bSmrg		else
95752836776bSmrg		  libnameglob=$libname
95762836776bSmrg		fi
95778292847cSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578c2939121Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
95798292847cSmrg		  if test yes = "$want_nocaseglob"; then
95802836776bSmrg		    shopt -s nocaseglob
95812836776bSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95822836776bSmrg		    $nocaseglob
95832836776bSmrg		  else
95842836776bSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95852836776bSmrg		  fi
9586c2939121Smrg		  for potent_lib in $potential_libs; do
9587c2939121Smrg		      # Follow soft links.
9588c2939121Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589c2939121Smrg			 $GREP " -> " >/dev/null; then
9590c2939121Smrg			continue
9591c2939121Smrg		      fi
9592c2939121Smrg		      # The statement above tries to avoid entering an
9593c2939121Smrg		      # endless loop below, in case of cyclic links.
9594c2939121Smrg		      # We might still enter an endless loop, since a link
9595c2939121Smrg		      # loop can be closed while we follow links,
9596c2939121Smrg		      # but so what?
95978292847cSmrg		      potlib=$potent_lib
9598c2939121Smrg		      while test -h "$potlib" 2>/dev/null; do
95998292847cSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600c2939121Smrg			case $potliblink in
96018292847cSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
96028292847cSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603c2939121Smrg			esac
9604c2939121Smrg		      done
9605c2939121Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606c2939121Smrg			 $SED -e 10q |
9607c2939121Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
96082836776bSmrg			func_append newdeplibs " $a_deplib"
96098292847cSmrg			a_deplib=
9610c2939121Smrg			break 2
9611c2939121Smrg		      fi
9612c2939121Smrg		  done
9613c2939121Smrg		done
9614c2939121Smrg	      fi
96158292847cSmrg	      if test -n "$a_deplib"; then
9616c2939121Smrg		droppeddeps=yes
9617c2939121Smrg		echo
9618c2939121Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619c2939121Smrg		echo "*** I have the capability to make that library automatically link in when"
9620c2939121Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9621c2939121Smrg		echo "*** shared version of the library, which you do not appear to have"
9622c2939121Smrg		echo "*** because I did check the linker path looking for a file starting"
96238292847cSmrg		if test -z "$potlib"; then
9624c2939121Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625c2939121Smrg		else
9626c2939121Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627c2939121Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628c2939121Smrg		fi
9629c2939121Smrg	      fi
9630c2939121Smrg	      ;;
9631c2939121Smrg	    *)
9632c2939121Smrg	      # Add a -L argument.
96332836776bSmrg	      func_append newdeplibs " $a_deplib"
9634c2939121Smrg	      ;;
9635c2939121Smrg	    esac
9636c2939121Smrg	  done # Gone through all deplibs.
9637c2939121Smrg	  ;;
9638c2939121Smrg	match_pattern*)
9639c2939121Smrg	  set dummy $deplibs_check_method; shift
9640c2939121Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641c2939121Smrg	  for a_deplib in $deplibs; do
9642c2939121Smrg	    case $a_deplib in
9643c2939121Smrg	    -l*)
9644c2939121Smrg	      func_stripname -l '' "$a_deplib"
9645c2939121Smrg	      name=$func_stripname_result
96468292847cSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647c2939121Smrg		case " $predeps $postdeps " in
9648c2939121Smrg		*" $a_deplib "*)
96492836776bSmrg		  func_append newdeplibs " $a_deplib"
96508292847cSmrg		  a_deplib=
9651c2939121Smrg		  ;;
9652c2939121Smrg		esac
9653c2939121Smrg	      fi
96548292847cSmrg	      if test -n "$a_deplib"; then
9655c2939121Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656c2939121Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657c2939121Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658c2939121Smrg		  for potent_lib in $potential_libs; do
96598292847cSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660c2939121Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661c2939121Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
96622836776bSmrg		      func_append newdeplibs " $a_deplib"
96638292847cSmrg		      a_deplib=
9664c2939121Smrg		      break 2
9665c2939121Smrg		    fi
9666c2939121Smrg		  done
9667c2939121Smrg		done
9668c2939121Smrg	      fi
96698292847cSmrg	      if test -n "$a_deplib"; then
9670c2939121Smrg		droppeddeps=yes
9671c2939121Smrg		echo
9672c2939121Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673c2939121Smrg		echo "*** I have the capability to make that library automatically link in when"
9674c2939121Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9675c2939121Smrg		echo "*** shared version of the library, which you do not appear to have"
9676c2939121Smrg		echo "*** because I did check the linker path looking for a file starting"
96778292847cSmrg		if test -z "$potlib"; then
9678c2939121Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679c2939121Smrg		else
9680c2939121Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681c2939121Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682c2939121Smrg		fi
9683c2939121Smrg	      fi
9684c2939121Smrg	      ;;
9685c2939121Smrg	    *)
9686c2939121Smrg	      # Add a -L argument.
96872836776bSmrg	      func_append newdeplibs " $a_deplib"
9688c2939121Smrg	      ;;
9689c2939121Smrg	    esac
9690c2939121Smrg	  done # Gone through all deplibs.
9691c2939121Smrg	  ;;
9692c2939121Smrg	none | unknown | *)
96938292847cSmrg	  newdeplibs=
9694c2939121Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
96958292847cSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96968292847cSmrg	    for i in $predeps $postdeps; do
9697c2939121Smrg	      # can't use Xsed below, because $i might contain '/'
96988292847cSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699c2939121Smrg	    done
9700c2939121Smrg	  fi
9701c2939121Smrg	  case $tmp_deplibs in
9702c2939121Smrg	  *[!\	\ ]*)
9703c2939121Smrg	    echo
97048292847cSmrg	    if test none = "$deplibs_check_method"; then
9705c2939121Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706c2939121Smrg	    else
9707c2939121Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708c2939121Smrg	    fi
9709c2939121Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9710c2939121Smrg	    droppeddeps=yes
9711c2939121Smrg	    ;;
9712c2939121Smrg	  esac
9713c2939121Smrg	  ;;
9714c2939121Smrg	esac
9715c2939121Smrg	versuffix=$versuffix_save
9716c2939121Smrg	major=$major_save
9717c2939121Smrg	release=$release_save
9718c2939121Smrg	libname=$libname_save
9719c2939121Smrg	name=$name_save
9720c2939121Smrg
9721c2939121Smrg	case $host in
9722c2939121Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9723c2939121Smrg	  # On Rhapsody replace the C library with the System framework
9724c2939121Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725c2939121Smrg	  ;;
9726c2939121Smrg	esac
9727c2939121Smrg
97288292847cSmrg	if test yes = "$droppeddeps"; then
97298292847cSmrg	  if test yes = "$module"; then
9730c2939121Smrg	    echo
9731c2939121Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732c2939121Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733c2939121Smrg	    echo "*** a static module, that should work as long as the dlopening"
9734c2939121Smrg	    echo "*** application is linked with the -dlopen flag."
9735c2939121Smrg	    if test -z "$global_symbol_pipe"; then
9736c2939121Smrg	      echo
9737c2939121Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
97388292847cSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739c2939121Smrg	      echo "*** not find such a program.  So, this module is probably useless."
97408292847cSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741c2939121Smrg	    fi
97428292847cSmrg	    if test no = "$build_old_libs"; then
97438292847cSmrg	      oldlibs=$output_objdir/$libname.$libext
9744c2939121Smrg	      build_libtool_libs=module
9745c2939121Smrg	      build_old_libs=yes
9746c2939121Smrg	    else
9747c2939121Smrg	      build_libtool_libs=no
9748c2939121Smrg	    fi
9749c2939121Smrg	  else
9750c2939121Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751c2939121Smrg	    echo "*** automatically added whenever a program is linked with this library"
9752c2939121Smrg	    echo "*** or is declared to -dlopen it."
9753c2939121Smrg
97548292847cSmrg	    if test no = "$allow_undefined"; then
9755c2939121Smrg	      echo
9756c2939121Smrg	      echo "*** Since this library must not contain undefined symbols,"
9757c2939121Smrg	      echo "*** because either the platform does not support them or"
9758c2939121Smrg	      echo "*** it was explicitly requested with -no-undefined,"
9759c2939121Smrg	      echo "*** libtool will only create a static version of it."
97608292847cSmrg	      if test no = "$build_old_libs"; then
97618292847cSmrg		oldlibs=$output_objdir/$libname.$libext
9762c2939121Smrg		build_libtool_libs=module
9763c2939121Smrg		build_old_libs=yes
9764c2939121Smrg	      else
9765c2939121Smrg		build_libtool_libs=no
9766c2939121Smrg	      fi
9767c2939121Smrg	    fi
9768c2939121Smrg	  fi
9769c2939121Smrg	fi
9770c2939121Smrg	# Done checking deplibs!
9771c2939121Smrg	deplibs=$newdeplibs
9772c2939121Smrg      fi
9773c2939121Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774c2939121Smrg      case $host in
9775c2939121Smrg	*-*-darwin*)
9776c2939121Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777c2939121Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778c2939121Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779c2939121Smrg	  ;;
9780c2939121Smrg      esac
9781c2939121Smrg
9782c2939121Smrg      # move library search paths that coincide with paths to not yet
9783c2939121Smrg      # installed libraries to the beginning of the library search list
9784c2939121Smrg      new_libs=
9785c2939121Smrg      for path in $notinst_path; do
9786c2939121Smrg	case " $new_libs " in
9787c2939121Smrg	*" -L$path/$objdir "*) ;;
9788c2939121Smrg	*)
9789c2939121Smrg	  case " $deplibs " in
9790c2939121Smrg	  *" -L$path/$objdir "*)
97912836776bSmrg	    func_append new_libs " -L$path/$objdir" ;;
9792c2939121Smrg	  esac
9793c2939121Smrg	  ;;
9794c2939121Smrg	esac
9795c2939121Smrg      done
9796c2939121Smrg      for deplib in $deplibs; do
9797c2939121Smrg	case $deplib in
9798c2939121Smrg	-L*)
9799c2939121Smrg	  case " $new_libs " in
9800c2939121Smrg	  *" $deplib "*) ;;
98012836776bSmrg	  *) func_append new_libs " $deplib" ;;
9802c2939121Smrg	  esac
9803c2939121Smrg	  ;;
98042836776bSmrg	*) func_append new_libs " $deplib" ;;
9805c2939121Smrg	esac
9806c2939121Smrg      done
98078292847cSmrg      deplibs=$new_libs
9808c2939121Smrg
9809c2939121Smrg      # All the library-specific variables (install_libdir is set above).
9810c2939121Smrg      library_names=
9811c2939121Smrg      old_library=
9812c2939121Smrg      dlname=
9813c2939121Smrg
9814c2939121Smrg      # Test again, we may have decided not to build it any more
98158292847cSmrg      if test yes = "$build_libtool_libs"; then
98168292847cSmrg	# Remove $wl instances when linking with ld.
98172836776bSmrg	# FIXME: should test the right _cmds variable.
98182836776bSmrg	case $archive_cmds in
98192836776bSmrg	  *\$LD\ *) wl= ;;
98202836776bSmrg        esac
98218292847cSmrg	if test yes = "$hardcode_into_libs"; then
9822c2939121Smrg	  # Hardcode the library paths
9823c2939121Smrg	  hardcode_libdirs=
9824c2939121Smrg	  dep_rpath=
98258292847cSmrg	  rpath=$finalize_rpath
98268292847cSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827c2939121Smrg	  for libdir in $rpath; do
9828c2939121Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829c2939121Smrg	      if test -n "$hardcode_libdir_separator"; then
98302836776bSmrg		func_replace_sysroot "$libdir"
98312836776bSmrg		libdir=$func_replace_sysroot_result
9832c2939121Smrg		if test -z "$hardcode_libdirs"; then
98338292847cSmrg		  hardcode_libdirs=$libdir
9834c2939121Smrg		else
9835c2939121Smrg		  # Just accumulate the unique libdirs.
9836c2939121Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837c2939121Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838c2939121Smrg		    ;;
9839c2939121Smrg		  *)
98402836776bSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841c2939121Smrg		    ;;
9842c2939121Smrg		  esac
9843c2939121Smrg		fi
9844c2939121Smrg	      else
9845c2939121Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
98462836776bSmrg		func_append dep_rpath " $flag"
9847c2939121Smrg	      fi
9848c2939121Smrg	    elif test -n "$runpath_var"; then
9849c2939121Smrg	      case "$perm_rpath " in
9850c2939121Smrg	      *" $libdir "*) ;;
98512836776bSmrg	      *) func_append perm_rpath " $libdir" ;;
9852c2939121Smrg	      esac
9853c2939121Smrg	    fi
9854c2939121Smrg	  done
9855c2939121Smrg	  # Substitute the hardcoded libdirs into the rpath.
9856c2939121Smrg	  if test -n "$hardcode_libdir_separator" &&
9857c2939121Smrg	     test -n "$hardcode_libdirs"; then
98588292847cSmrg	    libdir=$hardcode_libdirs
98592836776bSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860c2939121Smrg	  fi
9861c2939121Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862c2939121Smrg	    # We should set the runpath_var.
9863c2939121Smrg	    rpath=
9864c2939121Smrg	    for dir in $perm_rpath; do
98652836776bSmrg	      func_append rpath "$dir:"
9866c2939121Smrg	    done
9867c2939121Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868c2939121Smrg	  fi
9869c2939121Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870c2939121Smrg	fi
9871c76ae52dSmrg
98728292847cSmrg	shlibpath=$finalize_shlibpath
98738292847cSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874c2939121Smrg	if test -n "$shlibpath"; then
9875c2939121Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876c2939121Smrg	fi
9877c76ae52dSmrg
9878c2939121Smrg	# Get the real and link names of the library.
9879c2939121Smrg	eval shared_ext=\"$shrext_cmds\"
9880c2939121Smrg	eval library_names=\"$library_names_spec\"
9881c2939121Smrg	set dummy $library_names
9882c2939121Smrg	shift
98838292847cSmrg	realname=$1
9884c2939121Smrg	shift
9885c76ae52dSmrg
9886c2939121Smrg	if test -n "$soname_spec"; then
9887c2939121Smrg	  eval soname=\"$soname_spec\"
9888c2939121Smrg	else
98898292847cSmrg	  soname=$realname
9890c2939121Smrg	fi
9891c2939121Smrg	if test -z "$dlname"; then
9892c2939121Smrg	  dlname=$soname
9893c2939121Smrg	fi
9894c76ae52dSmrg
98958292847cSmrg	lib=$output_objdir/$realname
9896c2939121Smrg	linknames=
9897c2939121Smrg	for link
9898c2939121Smrg	do
98992836776bSmrg	  func_append linknames " $link"
9900c2939121Smrg	done
9901c76ae52dSmrg
9902c2939121Smrg	# Use standard objects if they are pic
9903c2939121Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904c2939121Smrg	test "X$libobjs" = "X " && libobjs=
9905c76ae52dSmrg
9906c2939121Smrg	delfiles=
9907c2939121Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908c2939121Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
99098292847cSmrg	  export_symbols=$output_objdir/$libname.uexp
99102836776bSmrg	  func_append delfiles " $export_symbols"
9911c2939121Smrg	fi
9912c76ae52dSmrg
9913c2939121Smrg	orig_export_symbols=
9914c2939121Smrg	case $host_os in
9915c2939121Smrg	cygwin* | mingw* | cegcc*)
9916c2939121Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917c2939121Smrg	    # exporting using user supplied symfile
99188292847cSmrg	    func_dll_def_p "$export_symbols" || {
9919c2939121Smrg	      # and it's NOT already a .def file. Must figure out
9920c2939121Smrg	      # which of the given symbols are data symbols and tag
9921c2939121Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9922c2939121Smrg	      # export_symbols gets reassigned inside the "prepare
9923c2939121Smrg	      # the list of exported symbols" if statement, so the
9924c2939121Smrg	      # include_expsyms logic still works.
99258292847cSmrg	      orig_export_symbols=$export_symbols
9926c2939121Smrg	      export_symbols=
9927c2939121Smrg	      always_export_symbols=yes
99288292847cSmrg	    }
9929c2939121Smrg	  fi
9930c2939121Smrg	  ;;
9931c2939121Smrg	esac
9932c76ae52dSmrg
9933c2939121Smrg	# Prepare the list of exported symbols
9934c2939121Smrg	if test -z "$export_symbols"; then
99358292847cSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
99368292847cSmrg	    func_verbose "generating symbol list for '$libname.la'"
99378292847cSmrg	    export_symbols=$output_objdir/$libname.exp
9938c2939121Smrg	    $opt_dry_run || $RM $export_symbols
9939c2939121Smrg	    cmds=$export_symbols_cmds
99408292847cSmrg	    save_ifs=$IFS; IFS='~'
99412836776bSmrg	    for cmd1 in $cmds; do
99428292847cSmrg	      IFS=$save_ifs
99432836776bSmrg	      # Take the normal branch if the nm_file_list_spec branch
99442836776bSmrg	      # doesn't work or if tool conversion is not needed.
99452836776bSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
99462836776bSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
99472836776bSmrg		  try_normal_branch=yes
99482836776bSmrg		  eval cmd=\"$cmd1\"
99492836776bSmrg		  func_len " $cmd"
99502836776bSmrg		  len=$func_len_result
99512836776bSmrg		  ;;
99522836776bSmrg		*)
99532836776bSmrg		  try_normal_branch=no
99542836776bSmrg		  ;;
99552836776bSmrg	      esac
99568292847cSmrg	      if test yes = "$try_normal_branch" \
99572836776bSmrg		 && { test "$len" -lt "$max_cmd_len" \
99582836776bSmrg		      || test "$max_cmd_len" -le -1; }
99592836776bSmrg	      then
99602836776bSmrg		func_show_eval "$cmd" 'exit $?'
99612836776bSmrg		skipped_export=false
99622836776bSmrg	      elif test -n "$nm_file_list_spec"; then
99632836776bSmrg		func_basename "$output"
99642836776bSmrg		output_la=$func_basename_result
99652836776bSmrg		save_libobjs=$libobjs
99662836776bSmrg		save_output=$output
99678292847cSmrg		output=$output_objdir/$output_la.nm
99682836776bSmrg		func_to_tool_file "$output"
99692836776bSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
99702836776bSmrg		func_append delfiles " $output"
99712836776bSmrg		func_verbose "creating $NM input file list: $output"
99722836776bSmrg		for obj in $save_libobjs; do
99732836776bSmrg		  func_to_tool_file "$obj"
99742836776bSmrg		  $ECHO "$func_to_tool_file_result"
99752836776bSmrg		done > "$output"
99762836776bSmrg		eval cmd=\"$cmd1\"
9977c2939121Smrg		func_show_eval "$cmd" 'exit $?'
99782836776bSmrg		output=$save_output
99792836776bSmrg		libobjs=$save_libobjs
9980c2939121Smrg		skipped_export=false
9981c2939121Smrg	      else
9982c2939121Smrg		# The command line is too long to execute in one step.
9983c2939121Smrg		func_verbose "using reloadable object file for export list..."
9984c2939121Smrg		skipped_export=:
9985c2939121Smrg		# Break out early, otherwise skipped_export may be
9986c2939121Smrg		# set to false by a later but shorter cmd.
9987c2939121Smrg		break
9988c2939121Smrg	      fi
9989c2939121Smrg	    done
99908292847cSmrg	    IFS=$save_ifs
99918292847cSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992c2939121Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993c2939121Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994c2939121Smrg	    fi
9995c2939121Smrg	  fi
9996c2939121Smrg	fi
9997c76ae52dSmrg
9998c2939121Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99998292847cSmrg	  tmp_export_symbols=$export_symbols
100008292847cSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001c2939121Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002c2939121Smrg	fi
10003c76ae52dSmrg
100048292847cSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005c2939121Smrg	  # The given exports_symbols file has to be filtered, so filter it.
100068292847cSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007c2939121Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
100088292847cSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009c2939121Smrg	  # though. Also, the filter scales superlinearly with the number of
10010c2939121Smrg	  # global variables. join(1) would be nice here, but unfortunately
10011c2939121Smrg	  # isn't a blessed tool.
10012c2939121Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
100132836776bSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014c2939121Smrg	  export_symbols=$output_objdir/$libname.def
10015c2939121Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016c76ae52dSmrg	fi
10017c76ae52dSmrg
10018c2939121Smrg	tmp_deplibs=
10019c2939121Smrg	for test_deplib in $deplibs; do
10020c2939121Smrg	  case " $convenience " in
10021c2939121Smrg	  *" $test_deplib "*) ;;
10022c2939121Smrg	  *)
100232836776bSmrg	    func_append tmp_deplibs " $test_deplib"
10024c2939121Smrg	    ;;
10025c2939121Smrg	  esac
10026c2939121Smrg	done
100278292847cSmrg	deplibs=$tmp_deplibs
10028c76ae52dSmrg
10029c2939121Smrg	if test -n "$convenience"; then
10030c2939121Smrg	  if test -n "$whole_archive_flag_spec" &&
100318292847cSmrg	    test yes = "$compiler_needs_object" &&
10032c2939121Smrg	    test -z "$libobjs"; then
10033c2939121Smrg	    # extract the archives, so we have objects to list.
10034c2939121Smrg	    # TODO: could optimize this to just extract one archive.
10035c2939121Smrg	    whole_archive_flag_spec=
10036c2939121Smrg	  fi
10037c2939121Smrg	  if test -n "$whole_archive_flag_spec"; then
10038c2939121Smrg	    save_libobjs=$libobjs
10039c2939121Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040c2939121Smrg	    test "X$libobjs" = "X " && libobjs=
10041c2939121Smrg	  else
100428292847cSmrg	    gentop=$output_objdir/${outputname}x
100432836776bSmrg	    func_append generated " $gentop"
10044c76ae52dSmrg
10045c2939121Smrg	    func_extract_archives $gentop $convenience
100462836776bSmrg	    func_append libobjs " $func_extract_archives_result"
10047c2939121Smrg	    test "X$libobjs" = "X " && libobjs=
10048c2939121Smrg	  fi
10049c2939121Smrg	fi
10050c76ae52dSmrg
100518292847cSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052c2939121Smrg	  eval flag=\"$thread_safe_flag_spec\"
100532836776bSmrg	  func_append linker_flags " $flag"
10054c2939121Smrg	fi
10055c76ae52dSmrg
10056c2939121Smrg	# Make a backup of the uninstalled library when relinking
100578292847cSmrg	if test relink = "$opt_mode"; then
10058c2939121Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059c76ae52dSmrg	fi
10060c76ae52dSmrg
10061c2939121Smrg	# Do each of the archive commands.
100628292847cSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10063c2939121Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064c2939121Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10065c2939121Smrg	    cmds=$module_expsym_cmds
10066c2939121Smrg	  else
10067c2939121Smrg	    eval test_cmds=\"$module_cmds\"
10068c2939121Smrg	    cmds=$module_cmds
10069c2939121Smrg	  fi
10070c2939121Smrg	else
10071c2939121Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072c2939121Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073c2939121Smrg	    cmds=$archive_expsym_cmds
10074c2939121Smrg	  else
10075c2939121Smrg	    eval test_cmds=\"$archive_cmds\"
10076c2939121Smrg	    cmds=$archive_cmds
10077c2939121Smrg	  fi
10078c76ae52dSmrg	fi
10079c76ae52dSmrg
100808292847cSmrg	if test : != "$skipped_export" &&
10081c2939121Smrg	   func_len " $test_cmds" &&
10082c2939121Smrg	   len=$func_len_result &&
10083c2939121Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084c2939121Smrg	  :
10085c2939121Smrg	else
10086c2939121Smrg	  # The command line is too long to link in one step, link piecewise
10087c2939121Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088c2939121Smrg	  # script.
10089c76ae52dSmrg
10090c2939121Smrg	  # Save the value of $output and $libobjs because we want to
10091c2939121Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10092c2939121Smrg	  # want to use save_libobjs as it was before
10093c2939121Smrg	  # whole_archive_flag_spec was expanded, because we can't
10094c2939121Smrg	  # assume the linker understands whole_archive_flag_spec.
10095c2939121Smrg	  # This may have to be revisited, in case too many
10096c2939121Smrg	  # convenience libraries get linked in and end up exceeding
10097c2939121Smrg	  # the spec.
10098c2939121Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099c2939121Smrg	    save_libobjs=$libobjs
10100c2939121Smrg	  fi
10101c2939121Smrg	  save_output=$output
10102c2939121Smrg	  func_basename "$output"
10103c2939121Smrg	  output_la=$func_basename_result
10104c76ae52dSmrg
10105c2939121Smrg	  # Clear the reloadable object creation command queue and
10106c2939121Smrg	  # initialize k to one.
10107c2939121Smrg	  test_cmds=
10108c2939121Smrg	  concat_cmds=
10109c2939121Smrg	  objlist=
10110c2939121Smrg	  last_robj=
10111c2939121Smrg	  k=1
10112c76ae52dSmrg
101138292847cSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
101148292847cSmrg	    output=$output_objdir/$output_la.lnkscript
10115c2939121Smrg	    func_verbose "creating GNU ld script: $output"
10116c2939121Smrg	    echo 'INPUT (' > $output
10117c2939121Smrg	    for obj in $save_libobjs
10118c2939121Smrg	    do
101192836776bSmrg	      func_to_tool_file "$obj"
101202836776bSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10121c2939121Smrg	    done
10122c2939121Smrg	    echo ')' >> $output
101232836776bSmrg	    func_append delfiles " $output"
101242836776bSmrg	    func_to_tool_file "$output"
101252836776bSmrg	    output=$func_to_tool_file_result
101268292847cSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
101278292847cSmrg	    output=$output_objdir/$output_la.lnk
10128c2939121Smrg	    func_verbose "creating linker input file list: $output"
10129c2939121Smrg	    : > $output
10130c2939121Smrg	    set x $save_libobjs
10131c2939121Smrg	    shift
10132c2939121Smrg	    firstobj=
101338292847cSmrg	    if test yes = "$compiler_needs_object"; then
10134c2939121Smrg	      firstobj="$1 "
10135c2939121Smrg	      shift
10136c2939121Smrg	    fi
10137c2939121Smrg	    for obj
10138c2939121Smrg	    do
101392836776bSmrg	      func_to_tool_file "$obj"
101402836776bSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10141c2939121Smrg	    done
101422836776bSmrg	    func_append delfiles " $output"
101432836776bSmrg	    func_to_tool_file "$output"
101442836776bSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145c2939121Smrg	  else
10146c2939121Smrg	    if test -n "$save_libobjs"; then
10147c2939121Smrg	      func_verbose "creating reloadable object files..."
101488292847cSmrg	      output=$output_objdir/$output_la-$k.$objext
10149c2939121Smrg	      eval test_cmds=\"$reload_cmds\"
10150c2939121Smrg	      func_len " $test_cmds"
10151c2939121Smrg	      len0=$func_len_result
10152c2939121Smrg	      len=$len0
10153c2939121Smrg
10154c2939121Smrg	      # Loop over the list of objects to be linked.
10155c2939121Smrg	      for obj in $save_libobjs
10156c2939121Smrg	      do
10157c2939121Smrg		func_len " $obj"
10158c2939121Smrg		func_arith $len + $func_len_result
10159c2939121Smrg		len=$func_arith_result
101608292847cSmrg		if test -z "$objlist" ||
10161c2939121Smrg		   test "$len" -lt "$max_cmd_len"; then
10162c2939121Smrg		  func_append objlist " $obj"
10163c2939121Smrg		else
10164c2939121Smrg		  # The command $test_cmds is almost too long, add a
10165c2939121Smrg		  # command to the queue.
101668292847cSmrg		  if test 1 -eq "$k"; then
10167c2939121Smrg		    # The first file doesn't have a previous command to add.
10168c2939121Smrg		    reload_objs=$objlist
10169c2939121Smrg		    eval concat_cmds=\"$reload_cmds\"
10170c2939121Smrg		  else
10171c2939121Smrg		    # All subsequent reloadable object files will link in
10172c2939121Smrg		    # the last one created.
10173c2939121Smrg		    reload_objs="$objlist $last_robj"
10174c2939121Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175c2939121Smrg		  fi
101768292847cSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177c2939121Smrg		  func_arith $k + 1
10178c2939121Smrg		  k=$func_arith_result
101798292847cSmrg		  output=$output_objdir/$output_la-$k.$objext
10180c2939121Smrg		  objlist=" $obj"
10181c2939121Smrg		  func_len " $last_robj"
10182c2939121Smrg		  func_arith $len0 + $func_len_result
10183c2939121Smrg		  len=$func_arith_result
10184c2939121Smrg		fi
10185c2939121Smrg	      done
10186c2939121Smrg	      # Handle the remaining objects by creating one last
10187c2939121Smrg	      # reloadable object file.  All subsequent reloadable object
10188c2939121Smrg	      # files will link in the last one created.
10189c2939121Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190c2939121Smrg	      reload_objs="$objlist $last_robj"
101918292847cSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192c2939121Smrg	      if test -n "$last_robj"; then
101938292847cSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194c2939121Smrg	      fi
101952836776bSmrg	      func_append delfiles " $output"
10196c2939121Smrg
10197c2939121Smrg	    else
10198c2939121Smrg	      output=
10199c2939121Smrg	    fi
10200c76ae52dSmrg
102018292847cSmrg	    ${skipped_export-false} && {
102028292847cSmrg	      func_verbose "generating symbol list for '$libname.la'"
102038292847cSmrg	      export_symbols=$output_objdir/$libname.exp
10204c2939121Smrg	      $opt_dry_run || $RM $export_symbols
10205c2939121Smrg	      libobjs=$output
10206c2939121Smrg	      # Append the command to create the export file.
10207c2939121Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208c2939121Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209c2939121Smrg	      if test -n "$last_robj"; then
10210c2939121Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211c2939121Smrg	      fi
102128292847cSmrg	    }
10213c76ae52dSmrg
10214c2939121Smrg	    test -n "$save_libobjs" &&
10215c2939121Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216c76ae52dSmrg
10217c2939121Smrg	    # Loop through the commands generated above and execute them.
102188292847cSmrg	    save_ifs=$IFS; IFS='~'
10219c2939121Smrg	    for cmd in $concat_cmds; do
102208292847cSmrg	      IFS=$save_ifs
102218292847cSmrg	      $opt_quiet || {
1022225420f97Smrg		  func_quote_arg expand,pretty "$cmd"
1022325420f97Smrg		  eval "func_echo $func_quote_arg_result"
10224c2939121Smrg	      }
10225c2939121Smrg	      $opt_dry_run || eval "$cmd" || {
10226c2939121Smrg		lt_exit=$?
10227c2939121Smrg
10228c2939121Smrg		# Restore the uninstalled library and exit
102298292847cSmrg		if test relink = "$opt_mode"; then
10230c2939121Smrg		  ( cd "$output_objdir" && \
10231c2939121Smrg		    $RM "${realname}T" && \
10232c2939121Smrg		    $MV "${realname}U" "$realname" )
10233c2939121Smrg		fi
10234c76ae52dSmrg
10235c2939121Smrg		exit $lt_exit
10236c2939121Smrg	      }
10237c2939121Smrg	    done
102388292847cSmrg	    IFS=$save_ifs
10239c76ae52dSmrg
10240c2939121Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241c2939121Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242c2939121Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243c76ae52dSmrg	    fi
10244c76ae52dSmrg	  fi
10245c76ae52dSmrg
102468292847cSmrg          ${skipped_export-false} && {
10247c2939121Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
102488292847cSmrg	      tmp_export_symbols=$export_symbols
102498292847cSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250c2939121Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251c2939121Smrg	    fi
10252c76ae52dSmrg
10253c2939121Smrg	    if test -n "$orig_export_symbols"; then
10254c2939121Smrg	      # The given exports_symbols file has to be filtered, so filter it.
102558292847cSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256c2939121Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
102578292847cSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258c2939121Smrg	      # though. Also, the filter scales superlinearly with the number of
10259c2939121Smrg	      # global variables. join(1) would be nice here, but unfortunately
10260c2939121Smrg	      # isn't a blessed tool.
10261c2939121Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
102622836776bSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263c2939121Smrg	      export_symbols=$output_objdir/$libname.def
10264c2939121Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265c2939121Smrg	    fi
102668292847cSmrg	  }
10267c76ae52dSmrg
10268c2939121Smrg	  libobjs=$output
10269c2939121Smrg	  # Restore the value of output.
10270c2939121Smrg	  output=$save_output
10271c76ae52dSmrg
10272c2939121Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273c2939121Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274c2939121Smrg	    test "X$libobjs" = "X " && libobjs=
10275c2939121Smrg	  fi
10276c2939121Smrg	  # Expand the library linking commands again to reset the
10277c2939121Smrg	  # value of $libobjs for piecewise linking.
10278c2939121Smrg
10279c2939121Smrg	  # Do each of the archive commands.
102808292847cSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281c2939121Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282c2939121Smrg	      cmds=$module_expsym_cmds
10283c76ae52dSmrg	    else
10284c2939121Smrg	      cmds=$module_cmds
10285c76ae52dSmrg	    fi
10286c76ae52dSmrg	  else
10287c2939121Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288c2939121Smrg	      cmds=$archive_expsym_cmds
10289c2939121Smrg	    else
10290c2939121Smrg	      cmds=$archive_cmds
10291c2939121Smrg	    fi
10292c76ae52dSmrg	  fi
10293c76ae52dSmrg	fi
10294c76ae52dSmrg
10295c2939121Smrg	if test -n "$delfiles"; then
10296c2939121Smrg	  # Append the command to remove temporary files to $cmds.
10297c2939121Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298c2939121Smrg	fi
10299c76ae52dSmrg
10300c2939121Smrg	# Add any objects from preloaded convenience libraries
10301c2939121Smrg	if test -n "$dlprefiles"; then
103028292847cSmrg	  gentop=$output_objdir/${outputname}x
103032836776bSmrg	  func_append generated " $gentop"
10304c76ae52dSmrg
10305c2939121Smrg	  func_extract_archives $gentop $dlprefiles
103062836776bSmrg	  func_append libobjs " $func_extract_archives_result"
10307c2939121Smrg	  test "X$libobjs" = "X " && libobjs=
10308c76ae52dSmrg	fi
10309c76ae52dSmrg
103108292847cSmrg	save_ifs=$IFS; IFS='~'
10311c2939121Smrg	for cmd in $cmds; do
103128292847cSmrg	  IFS=$sp$nl
10313c2939121Smrg	  eval cmd=\"$cmd\"
103148292847cSmrg	  IFS=$save_ifs
103158292847cSmrg	  $opt_quiet || {
1031625420f97Smrg	    func_quote_arg expand,pretty "$cmd"
1031725420f97Smrg	    eval "func_echo $func_quote_arg_result"
10318c2939121Smrg	  }
10319c2939121Smrg	  $opt_dry_run || eval "$cmd" || {
10320c2939121Smrg	    lt_exit=$?
10321c76ae52dSmrg
10322c2939121Smrg	    # Restore the uninstalled library and exit
103238292847cSmrg	    if test relink = "$opt_mode"; then
10324c2939121Smrg	      ( cd "$output_objdir" && \
10325c2939121Smrg	        $RM "${realname}T" && \
10326c2939121Smrg		$MV "${realname}U" "$realname" )
10327c76ae52dSmrg	    fi
10328c76ae52dSmrg
10329c2939121Smrg	    exit $lt_exit
10330c2939121Smrg	  }
10331c2939121Smrg	done
103328292847cSmrg	IFS=$save_ifs
10333c76ae52dSmrg
10334c2939121Smrg	# Restore the uninstalled library and exit
103358292847cSmrg	if test relink = "$opt_mode"; then
10336c2939121Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337c76ae52dSmrg
10338c2939121Smrg	  if test -n "$convenience"; then
10339c2939121Smrg	    if test -z "$whole_archive_flag_spec"; then
10340c2939121Smrg	      func_show_eval '${RM}r "$gentop"'
10341c2939121Smrg	    fi
10342c2939121Smrg	  fi
10343c76ae52dSmrg
10344c2939121Smrg	  exit $EXIT_SUCCESS
10345c2939121Smrg	fi
10346c76ae52dSmrg
10347c2939121Smrg	# Create links to the real library.
10348c2939121Smrg	for linkname in $linknames; do
10349c2939121Smrg	  if test "$realname" != "$linkname"; then
10350c2939121Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351c2939121Smrg	  fi
10352c2939121Smrg	done
10353c76ae52dSmrg
10354c2939121Smrg	# If -module or -export-dynamic was specified, set the dlname.
103558292847cSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356c2939121Smrg	  # On all known operating systems, these are identical.
103578292847cSmrg	  dlname=$soname
10358c2939121Smrg	fi
10359c2939121Smrg      fi
10360c2939121Smrg      ;;
10361c76ae52dSmrg
10362c2939121Smrg    obj)
103638292847cSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
103648292847cSmrg	func_warning "'-dlopen' is ignored for objects"
10365c2939121Smrg      fi
10366c76ae52dSmrg
10367c2939121Smrg      case " $deplibs" in
10368c2939121Smrg      *\ -l* | *\ -L*)
103698292847cSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370c2939121Smrg      esac
10371c76ae52dSmrg
10372c2939121Smrg      test -n "$rpath" && \
103738292847cSmrg	func_warning "'-rpath' is ignored for objects"
10374c76ae52dSmrg
10375c2939121Smrg      test -n "$xrpath" && \
103768292847cSmrg	func_warning "'-R' is ignored for objects"
10377c2939121Smrg
10378c2939121Smrg      test -n "$vinfo" && \
103798292847cSmrg	func_warning "'-version-info' is ignored for objects"
10380c76ae52dSmrg
10381c2939121Smrg      test -n "$release" && \
103828292847cSmrg	func_warning "'-release' is ignored for objects"
10383c76ae52dSmrg
10384c2939121Smrg      case $output in
10385c2939121Smrg      *.lo)
10386c2939121Smrg	test -n "$objs$old_deplibs" && \
103878292847cSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388c2939121Smrg
10389c2939121Smrg	libobj=$output
10390c2939121Smrg	func_lo2o "$libobj"
10391c2939121Smrg	obj=$func_lo2o_result
10392c2939121Smrg	;;
10393c2939121Smrg      *)
10394c2939121Smrg	libobj=
103958292847cSmrg	obj=$output
10396c76ae52dSmrg	;;
10397c76ae52dSmrg      esac
10398c76ae52dSmrg
10399c2939121Smrg      # Delete the old objects.
10400c2939121Smrg      $opt_dry_run || $RM $obj $libobj
10401c76ae52dSmrg
10402c2939121Smrg      # Objects from convenience libraries.  This assumes
10403c2939121Smrg      # single-version convenience libraries.  Whenever we create
10404c2939121Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405c2939121Smrg      # the extraction.
10406c2939121Smrg      reload_conv_objs=
10407c2939121Smrg      gentop=
104088292847cSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
104098292847cSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
104108292847cSmrg      # into space.
104118292847cSmrg      case $reload_cmds in
104128292847cSmrg        *\$LD[\ \$]*) wl= ;;
104138292847cSmrg      esac
10414c2939121Smrg      if test -n "$convenience"; then
10415c2939121Smrg	if test -n "$whole_archive_flag_spec"; then
10416c2939121Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
104178292847cSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
104188292847cSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419c76ae52dSmrg	else
104208292847cSmrg	  gentop=$output_objdir/${obj}x
104212836776bSmrg	  func_append generated " $gentop"
10422c2939121Smrg
10423c2939121Smrg	  func_extract_archives $gentop $convenience
10424c2939121Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425c76ae52dSmrg	fi
10426c2939121Smrg      fi
10427c76ae52dSmrg
104282836776bSmrg      # If we're not building shared, we need to use non_pic_objs
104298292847cSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
104302836776bSmrg
10431c2939121Smrg      # Create the old-style object.
104328292847cSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433c76ae52dSmrg
104348292847cSmrg      output=$obj
10435c2939121Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436c76ae52dSmrg
10437c2939121Smrg      # Exit if we aren't doing a library object file.
10438c2939121Smrg      if test -z "$libobj"; then
10439c2939121Smrg	if test -n "$gentop"; then
10440c2939121Smrg	  func_show_eval '${RM}r "$gentop"'
10441c2939121Smrg	fi
10442c76ae52dSmrg
10443c2939121Smrg	exit $EXIT_SUCCESS
10444c76ae52dSmrg      fi
10445c76ae52dSmrg
104468292847cSmrg      test yes = "$build_libtool_libs" || {
10447c2939121Smrg	if test -n "$gentop"; then
10448c2939121Smrg	  func_show_eval '${RM}r "$gentop"'
10449c2939121Smrg	fi
10450c76ae52dSmrg
10451c2939121Smrg	# Create an invalid libtool object if no PIC, so that we don't
10452c2939121Smrg	# accidentally link it into a program.
10453c2939121Smrg	# $show "echo timestamp > $libobj"
10454c2939121Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455c2939121Smrg	exit $EXIT_SUCCESS
104568292847cSmrg      }
10457c76ae52dSmrg
104588292847cSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459c2939121Smrg	# Only do commands if we really have different PIC objects.
10460c2939121Smrg	reload_objs="$libobjs $reload_conv_objs"
104618292847cSmrg	output=$libobj
10462c2939121Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463c76ae52dSmrg      fi
10464c2939121Smrg
10465c2939121Smrg      if test -n "$gentop"; then
10466c2939121Smrg	func_show_eval '${RM}r "$gentop"'
10467c2939121Smrg      fi
10468c2939121Smrg
10469c2939121Smrg      exit $EXIT_SUCCESS
10470c76ae52dSmrg      ;;
10471c76ae52dSmrg
10472c2939121Smrg    prog)
10473c2939121Smrg      case $host in
10474c2939121Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10475c2939121Smrg	          output=$func_stripname_result.exe;;
10476c2939121Smrg      esac
10477c2939121Smrg      test -n "$vinfo" && \
104788292847cSmrg	func_warning "'-version-info' is ignored for programs"
10479c76ae52dSmrg
10480c2939121Smrg      test -n "$release" && \
104818292847cSmrg	func_warning "'-release' is ignored for programs"
10482c76ae52dSmrg
104838292847cSmrg      $preload \
104848292847cSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
104858292847cSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10486c2939121Smrg
10487c2939121Smrg      case $host in
10488c2939121Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10489c2939121Smrg	# On Rhapsody replace the C library is the System framework
10490c2939121Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491c2939121Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492c76ae52dSmrg	;;
10493c2939121Smrg      esac
10494c76ae52dSmrg
10495c2939121Smrg      case $host in
10496c2939121Smrg      *-*-darwin*)
10497c2939121Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10498c2939121Smrg	# But is supposedly fixed on 10.4 or later (yay!).
104998292847cSmrg	if test CXX = "$tagname"; then
10500c2939121Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501c2939121Smrg	    10.[0123])
105028292847cSmrg	      func_append compile_command " $wl-bind_at_load"
105038292847cSmrg	      func_append finalize_command " $wl-bind_at_load"
10504c2939121Smrg	    ;;
10505c2939121Smrg	  esac
10506c76ae52dSmrg	fi
10507c2939121Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508c2939121Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509c2939121Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10510c2939121Smrg	;;
10511c2939121Smrg      esac
10512c76ae52dSmrg
10513c76ae52dSmrg
10514c2939121Smrg      # move library search paths that coincide with paths to not yet
10515c2939121Smrg      # installed libraries to the beginning of the library search list
10516c2939121Smrg      new_libs=
10517c2939121Smrg      for path in $notinst_path; do
10518c2939121Smrg	case " $new_libs " in
10519c2939121Smrg	*" -L$path/$objdir "*) ;;
10520c2939121Smrg	*)
10521c2939121Smrg	  case " $compile_deplibs " in
10522c2939121Smrg	  *" -L$path/$objdir "*)
105232836776bSmrg	    func_append new_libs " -L$path/$objdir" ;;
10524c76ae52dSmrg	  esac
10525c2939121Smrg	  ;;
10526c2939121Smrg	esac
10527c2939121Smrg      done
10528c2939121Smrg      for deplib in $compile_deplibs; do
10529c2939121Smrg	case $deplib in
10530c2939121Smrg	-L*)
10531c2939121Smrg	  case " $new_libs " in
10532c2939121Smrg	  *" $deplib "*) ;;
105332836776bSmrg	  *) func_append new_libs " $deplib" ;;
10534c76ae52dSmrg	  esac
10535c2939121Smrg	  ;;
105362836776bSmrg	*) func_append new_libs " $deplib" ;;
10537c2939121Smrg	esac
10538c2939121Smrg      done
105398292847cSmrg      compile_deplibs=$new_libs
10540c76ae52dSmrg
10541c76ae52dSmrg
105422836776bSmrg      func_append compile_command " $compile_deplibs"
105432836776bSmrg      func_append finalize_command " $finalize_deplibs"
10544c76ae52dSmrg
10545c2939121Smrg      if test -n "$rpath$xrpath"; then
10546c2939121Smrg	# If the user specified any rpath flags, then add them.
10547c2939121Smrg	for libdir in $rpath $xrpath; do
10548c2939121Smrg	  # This is the magic to use -rpath.
10549c2939121Smrg	  case "$finalize_rpath " in
10550c2939121Smrg	  *" $libdir "*) ;;
105512836776bSmrg	  *) func_append finalize_rpath " $libdir" ;;
10552c2939121Smrg	  esac
10553c2939121Smrg	done
10554c2939121Smrg      fi
10555c76ae52dSmrg
10556c2939121Smrg      # Now hardcode the library paths
10557c2939121Smrg      rpath=
10558c2939121Smrg      hardcode_libdirs=
10559c2939121Smrg      for libdir in $compile_rpath $finalize_rpath; do
10560c2939121Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10561c2939121Smrg	  if test -n "$hardcode_libdir_separator"; then
10562c2939121Smrg	    if test -z "$hardcode_libdirs"; then
105638292847cSmrg	      hardcode_libdirs=$libdir
10564c2939121Smrg	    else
10565c2939121Smrg	      # Just accumulate the unique libdirs.
10566c2939121Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567c2939121Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568c2939121Smrg		;;
10569c2939121Smrg	      *)
105702836776bSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571c2939121Smrg		;;
10572c2939121Smrg	      esac
10573c2939121Smrg	    fi
10574c76ae52dSmrg	  else
10575c2939121Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
105762836776bSmrg	    func_append rpath " $flag"
10577c76ae52dSmrg	  fi
10578c2939121Smrg	elif test -n "$runpath_var"; then
10579c2939121Smrg	  case "$perm_rpath " in
10580c2939121Smrg	  *" $libdir "*) ;;
105812836776bSmrg	  *) func_append perm_rpath " $libdir" ;;
10582c2939121Smrg	  esac
10583c2939121Smrg	fi
10584c2939121Smrg	case $host in
10585c2939121Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
105868292847cSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587c2939121Smrg	  case :$dllsearchpath: in
10588c2939121Smrg	  *":$libdir:"*) ;;
10589c2939121Smrg	  ::) dllsearchpath=$libdir;;
105902836776bSmrg	  *) func_append dllsearchpath ":$libdir";;
10591c2939121Smrg	  esac
10592c2939121Smrg	  case :$dllsearchpath: in
10593c2939121Smrg	  *":$testbindir:"*) ;;
10594c2939121Smrg	  ::) dllsearchpath=$testbindir;;
105952836776bSmrg	  *) func_append dllsearchpath ":$testbindir";;
10596c2939121Smrg	  esac
10597c2939121Smrg	  ;;
10598c2939121Smrg	esac
10599c2939121Smrg      done
10600c2939121Smrg      # Substitute the hardcoded libdirs into the rpath.
10601c2939121Smrg      if test -n "$hardcode_libdir_separator" &&
10602c2939121Smrg	 test -n "$hardcode_libdirs"; then
106038292847cSmrg	libdir=$hardcode_libdirs
10604c2939121Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605c2939121Smrg      fi
106068292847cSmrg      compile_rpath=$rpath
10607c76ae52dSmrg
10608c2939121Smrg      rpath=
10609c2939121Smrg      hardcode_libdirs=
10610c2939121Smrg      for libdir in $finalize_rpath; do
10611c2939121Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10612c2939121Smrg	  if test -n "$hardcode_libdir_separator"; then
10613c2939121Smrg	    if test -z "$hardcode_libdirs"; then
106148292847cSmrg	      hardcode_libdirs=$libdir
10615c2939121Smrg	    else
10616c2939121Smrg	      # Just accumulate the unique libdirs.
10617c2939121Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618c2939121Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619c2939121Smrg		;;
10620c2939121Smrg	      *)
106212836776bSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622c2939121Smrg		;;
10623c2939121Smrg	      esac
10624c2939121Smrg	    fi
10625c76ae52dSmrg	  else
10626c2939121Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
106272836776bSmrg	    func_append rpath " $flag"
10628c76ae52dSmrg	  fi
10629c2939121Smrg	elif test -n "$runpath_var"; then
10630c2939121Smrg	  case "$finalize_perm_rpath " in
10631c2939121Smrg	  *" $libdir "*) ;;
106322836776bSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10633c2939121Smrg	  esac
10634c76ae52dSmrg	fi
10635c2939121Smrg      done
10636c2939121Smrg      # Substitute the hardcoded libdirs into the rpath.
10637c2939121Smrg      if test -n "$hardcode_libdir_separator" &&
10638c2939121Smrg	 test -n "$hardcode_libdirs"; then
106398292847cSmrg	libdir=$hardcode_libdirs
10640c2939121Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641c2939121Smrg      fi
106428292847cSmrg      finalize_rpath=$rpath
10643c76ae52dSmrg
106448292847cSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645c2939121Smrg	# Transform all the library objects into standard objects.
10646c2939121Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647c2939121Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648c2939121Smrg      fi
10649c76ae52dSmrg
106508292847cSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651c76ae52dSmrg
10652c2939121Smrg      # template prelinking step
10653c2939121Smrg      if test -n "$prelink_cmds"; then
10654c2939121Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655c2939121Smrg      fi
10656c76ae52dSmrg
106578292847cSmrg      wrappers_required=:
10658c2939121Smrg      case $host in
10659c2939121Smrg      *cegcc* | *mingw32ce*)
10660c2939121Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
106618292847cSmrg        wrappers_required=false
10662c2939121Smrg        ;;
10663c2939121Smrg      *cygwin* | *mingw* )
106648292847cSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665c2939121Smrg        ;;
10666c2939121Smrg      *)
106678292847cSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
106688292847cSmrg          wrappers_required=false
10669c2939121Smrg        fi
10670c2939121Smrg        ;;
10671c2939121Smrg      esac
106728292847cSmrg      $wrappers_required || {
10673c2939121Smrg	# Replace the output file specification.
10674c2939121Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
106758292847cSmrg	link_command=$compile_command$compile_rpath
10676c76ae52dSmrg
10677c2939121Smrg	# We have no uninstalled library dependencies, so finalize right now.
10678c2939121Smrg	exit_status=0
10679c2939121Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680c76ae52dSmrg
106812836776bSmrg	if test -n "$postlink_cmds"; then
106822836776bSmrg	  func_to_tool_file "$output"
106832836776bSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
106842836776bSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
106852836776bSmrg	fi
106862836776bSmrg
10687c2939121Smrg	# Delete the generated files.
106888292847cSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
106898292847cSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690c76ae52dSmrg	fi
10691c76ae52dSmrg
10692c2939121Smrg	exit $exit_status
106938292847cSmrg      }
10694c76ae52dSmrg
10695c2939121Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696c2939121Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697c2939121Smrg      fi
10698c2939121Smrg      if test -n "$finalize_shlibpath"; then
10699c2939121Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700c2939121Smrg      fi
10701c76ae52dSmrg
10702c2939121Smrg      compile_var=
10703c2939121Smrg      finalize_var=
10704c2939121Smrg      if test -n "$runpath_var"; then
10705c2939121Smrg	if test -n "$perm_rpath"; then
10706c2939121Smrg	  # We should set the runpath_var.
10707c2939121Smrg	  rpath=
10708c2939121Smrg	  for dir in $perm_rpath; do
107092836776bSmrg	    func_append rpath "$dir:"
10710c2939121Smrg	  done
10711c2939121Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712c76ae52dSmrg	fi
10713c2939121Smrg	if test -n "$finalize_perm_rpath"; then
10714c2939121Smrg	  # We should set the runpath_var.
10715c2939121Smrg	  rpath=
10716c2939121Smrg	  for dir in $finalize_perm_rpath; do
107172836776bSmrg	    func_append rpath "$dir:"
10718c2939121Smrg	  done
10719c2939121Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720c76ae52dSmrg	fi
10721c2939121Smrg      fi
10722c76ae52dSmrg
107238292847cSmrg      if test yes = "$no_install"; then
10724c2939121Smrg	# We don't need to create a wrapper script.
107258292847cSmrg	link_command=$compile_var$compile_command$compile_rpath
10726c2939121Smrg	# Replace the output file specification.
10727c2939121Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728c2939121Smrg	# Delete the old output file.
10729c2939121Smrg	$opt_dry_run || $RM $output
10730c2939121Smrg	# Link the executable and exit
10731c2939121Smrg	func_show_eval "$link_command" 'exit $?'
107322836776bSmrg
107332836776bSmrg	if test -n "$postlink_cmds"; then
107342836776bSmrg	  func_to_tool_file "$output"
107352836776bSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
107362836776bSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
107372836776bSmrg	fi
107382836776bSmrg
10739c76ae52dSmrg	exit $EXIT_SUCCESS
10740c2939121Smrg      fi
10741c76ae52dSmrg
107428292847cSmrg      case $hardcode_action,$fast_install in
107438292847cSmrg        relink,*)
107448292847cSmrg	  # Fast installation is not supported
107458292847cSmrg	  link_command=$compile_var$compile_command$compile_rpath
107468292847cSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10747c2939121Smrg
107488292847cSmrg	  func_warning "this platform does not like uninstalled shared libraries"
107498292847cSmrg	  func_warning "'$output' will be relinked during installation"
107508292847cSmrg	  ;;
107518292847cSmrg        *,yes)
107528292847cSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107538292847cSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
107548292847cSmrg          ;;
107558292847cSmrg	*,no)
107568292847cSmrg	  link_command=$compile_var$compile_command$compile_rpath
107578292847cSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107588292847cSmrg          ;;
107598292847cSmrg	*,needless)
107608292847cSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107618292847cSmrg	  relink_command=
107628292847cSmrg          ;;
107638292847cSmrg      esac
10764c76ae52dSmrg
10765c2939121Smrg      # Replace the output file specification.
10766c2939121Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767c76ae52dSmrg
10768c2939121Smrg      # Delete the old output files.
10769c2939121Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770c76ae52dSmrg
10771c2939121Smrg      func_show_eval "$link_command" 'exit $?'
10772c76ae52dSmrg
107732836776bSmrg      if test -n "$postlink_cmds"; then
107742836776bSmrg	func_to_tool_file "$output_objdir/$outputname"
107752836776bSmrg	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'`
107762836776bSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
107772836776bSmrg      fi
107782836776bSmrg
10779c2939121Smrg      # Now create the wrapper script.
10780c2939121Smrg      func_verbose "creating $output"
10781c76ae52dSmrg
10782c2939121Smrg      # Quote the relink command for shipping.
10783c2939121Smrg      if test -n "$relink_command"; then
10784c2939121Smrg	# Preserve any variables that may affect compiler behavior
10785c2939121Smrg	for var in $variables_saved_for_relink; do
10786c2939121Smrg	  if eval test -z \"\${$var+set}\"; then
10787c2939121Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788c2939121Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789c2939121Smrg	    relink_command="$var=; export $var; $relink_command"
10790c76ae52dSmrg	  else
1079125420f97Smrg	    func_quote_arg pretty "$var_value"
1079225420f97Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793c76ae52dSmrg	  fi
10794c2939121Smrg	done
1079525420f97Smrg	func_quote eval cd "`pwd`"
1079625420f97Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
1079725420f97Smrg	relink_command=$func_quote_arg_unquoted_result
10798c2939121Smrg      fi
10799c76ae52dSmrg
10800c2939121Smrg      # Only actually do things if not in dry run mode.
10801c2939121Smrg      $opt_dry_run || {
10802c2939121Smrg	# win32 will think the script is a binary if it has
10803c2939121Smrg	# a .exe suffix, so we strip it off here.
10804c2939121Smrg	case $output in
10805c2939121Smrg	  *.exe) func_stripname '' '.exe' "$output"
10806c2939121Smrg	         output=$func_stripname_result ;;
10807c2939121Smrg	esac
10808c2939121Smrg	# test for cygwin because mv fails w/o .exe extensions
10809c2939121Smrg	case $host in
10810c2939121Smrg	  *cygwin*)
10811c2939121Smrg	    exeext=.exe
10812c2939121Smrg	    func_stripname '' '.exe' "$outputname"
10813c2939121Smrg	    outputname=$func_stripname_result ;;
10814c2939121Smrg	  *) exeext= ;;
10815c76ae52dSmrg	esac
10816c2939121Smrg	case $host in
10817c2939121Smrg	  *cygwin* | *mingw* )
10818c2939121Smrg	    func_dirname_and_basename "$output" "" "."
10819c2939121Smrg	    output_name=$func_basename_result
10820c2939121Smrg	    output_path=$func_dirname_result
108218292847cSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
108228292847cSmrg	    cwrapper=$output_path/$output_name.exe
10823c2939121Smrg	    $RM $cwrappersource $cwrapper
10824c2939121Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825c2939121Smrg
10826c2939121Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10827c2939121Smrg
10828c2939121Smrg	    # The wrapper executable is built using the $host compiler,
10829c2939121Smrg	    # because it contains $host paths and files. If cross-
10830c2939121Smrg	    # compiling, it, like the target executable, must be
10831c2939121Smrg	    # executed on the $host or under an emulation environment.
10832c2939121Smrg	    $opt_dry_run || {
10833c2939121Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834c2939121Smrg	      $STRIP $cwrapper
10835c2939121Smrg	    }
10836c76ae52dSmrg
10837c2939121Smrg	    # Now, create the wrapper script for func_source use:
10838c2939121Smrg	    func_ltwrapper_scriptname $cwrapper
10839c2939121Smrg	    $RM $func_ltwrapper_scriptname_result
10840c2939121Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841c2939121Smrg	    $opt_dry_run || {
10842c2939121Smrg	      # note: this script will not be executed, so do not chmod.
108438292847cSmrg	      if test "x$build" = "x$host"; then
10844c2939121Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10845c2939121Smrg	      else
10846c2939121Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10847c2939121Smrg	      fi
10848c2939121Smrg	    }
10849c2939121Smrg	  ;;
10850c2939121Smrg	  * )
10851c2939121Smrg	    $RM $output
10852c2939121Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853c76ae52dSmrg
10854c2939121Smrg	    func_emit_wrapper no > $output
10855c2939121Smrg	    chmod +x $output
10856c2939121Smrg	  ;;
10857c2939121Smrg	esac
10858c2939121Smrg      }
10859c2939121Smrg      exit $EXIT_SUCCESS
10860c2939121Smrg      ;;
10861c2939121Smrg    esac
10862c76ae52dSmrg
10863c2939121Smrg    # See if we need to build an old-fashioned archive.
10864c2939121Smrg    for oldlib in $oldlibs; do
10865c76ae52dSmrg
108668292847cSmrg      case $build_libtool_libs in
108678292847cSmrg        convenience)
108688292847cSmrg	  oldobjs="$libobjs_save $symfileobj"
108698292847cSmrg	  addlibs=$convenience
10870c2939121Smrg	  build_libtool_libs=no
108718292847cSmrg	  ;;
108728292847cSmrg	module)
108738292847cSmrg	  oldobjs=$libobjs_save
108748292847cSmrg	  addlibs=$old_convenience
108758292847cSmrg	  build_libtool_libs=no
108768292847cSmrg          ;;
108778292847cSmrg	*)
10878c2939121Smrg	  oldobjs="$old_deplibs $non_pic_objects"
108798292847cSmrg	  $preload && test -f "$symfileobj" \
108808292847cSmrg	    && func_append oldobjs " $symfileobj"
108818292847cSmrg	  addlibs=$old_convenience
108828292847cSmrg	  ;;
108838292847cSmrg      esac
10884c76ae52dSmrg
10885c2939121Smrg      if test -n "$addlibs"; then
108868292847cSmrg	gentop=$output_objdir/${outputname}x
108872836776bSmrg	func_append generated " $gentop"
10888c76ae52dSmrg
10889c2939121Smrg	func_extract_archives $gentop $addlibs
108902836776bSmrg	func_append oldobjs " $func_extract_archives_result"
10891c2939121Smrg      fi
10892c76ae52dSmrg
10893c2939121Smrg      # Do each command in the archive commands.
108948292847cSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895c2939121Smrg	cmds=$old_archive_from_new_cmds
10896c2939121Smrg      else
10897c76ae52dSmrg
10898c2939121Smrg	# Add any objects from preloaded convenience libraries
10899c2939121Smrg	if test -n "$dlprefiles"; then
109008292847cSmrg	  gentop=$output_objdir/${outputname}x
109012836776bSmrg	  func_append generated " $gentop"
10902c76ae52dSmrg
10903c2939121Smrg	  func_extract_archives $gentop $dlprefiles
109042836776bSmrg	  func_append oldobjs " $func_extract_archives_result"
10905c2939121Smrg	fi
10906c76ae52dSmrg
10907c2939121Smrg	# POSIX demands no paths to be encoded in archives.  We have
10908c2939121Smrg	# to avoid creating archives with duplicate basenames if we
10909c2939121Smrg	# might have to extract them afterwards, e.g., when creating a
10910c2939121Smrg	# static archive out of a convenience library, or when linking
10911c2939121Smrg	# the entirety of a libtool archive into another (currently
10912c2939121Smrg	# not supported by libtool).
10913c2939121Smrg	if (for obj in $oldobjs
10914c2939121Smrg	    do
10915c2939121Smrg	      func_basename "$obj"
10916c2939121Smrg	      $ECHO "$func_basename_result"
10917c2939121Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918c2939121Smrg	  :
10919c2939121Smrg	else
10920c2939121Smrg	  echo "copying selected object files to avoid basename conflicts..."
109218292847cSmrg	  gentop=$output_objdir/${outputname}x
109222836776bSmrg	  func_append generated " $gentop"
10923c2939121Smrg	  func_mkdir_p "$gentop"
10924c2939121Smrg	  save_oldobjs=$oldobjs
10925c2939121Smrg	  oldobjs=
10926c2939121Smrg	  counter=1
10927c2939121Smrg	  for obj in $save_oldobjs
10928c2939121Smrg	  do
10929c2939121Smrg	    func_basename "$obj"
109308292847cSmrg	    objbase=$func_basename_result
10931c2939121Smrg	    case " $oldobjs " in
10932c2939121Smrg	    " ") oldobjs=$obj ;;
10933c2939121Smrg	    *[\ /]"$objbase "*)
10934c2939121Smrg	      while :; do
10935c2939121Smrg		# Make sure we don't pick an alternate name that also
10936c2939121Smrg		# overlaps.
10937c2939121Smrg		newobj=lt$counter-$objbase
10938c2939121Smrg		func_arith $counter + 1
10939c2939121Smrg		counter=$func_arith_result
10940c2939121Smrg		case " $oldobjs " in
10941c2939121Smrg		*[\ /]"$newobj "*) ;;
10942c2939121Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943c2939121Smrg		esac
10944c2939121Smrg	      done
10945c2939121Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
109462836776bSmrg	      func_append oldobjs " $gentop/$newobj"
10947c2939121Smrg	      ;;
109482836776bSmrg	    *) func_append oldobjs " $obj" ;;
10949c2939121Smrg	    esac
10950c76ae52dSmrg	  done
10951c76ae52dSmrg	fi
109522836776bSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
109532836776bSmrg	tool_oldlib=$func_to_tool_file_result
10954c2939121Smrg	eval cmds=\"$old_archive_cmds\"
10955c76ae52dSmrg
10956c2939121Smrg	func_len " $cmds"
10957c2939121Smrg	len=$func_len_result
10958c2939121Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959c2939121Smrg	  cmds=$old_archive_cmds
109602836776bSmrg	elif test -n "$archiver_list_spec"; then
109612836776bSmrg	  func_verbose "using command file archive linking..."
109622836776bSmrg	  for obj in $oldobjs
109632836776bSmrg	  do
109642836776bSmrg	    func_to_tool_file "$obj"
109652836776bSmrg	    $ECHO "$func_to_tool_file_result"
109662836776bSmrg	  done > $output_objdir/$libname.libcmd
109672836776bSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
109682836776bSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
109692836776bSmrg	  cmds=$old_archive_cmds
10970c2939121Smrg	else
10971c2939121Smrg	  # the command line is too long to link in one step, link in parts
10972c2939121Smrg	  func_verbose "using piecewise archive linking..."
10973c2939121Smrg	  save_RANLIB=$RANLIB
10974c2939121Smrg	  RANLIB=:
10975c2939121Smrg	  objlist=
10976c2939121Smrg	  concat_cmds=
10977c2939121Smrg	  save_oldobjs=$oldobjs
10978c2939121Smrg	  oldobjs=
10979c2939121Smrg	  # Is there a better way of finding the last object in the list?
10980c2939121Smrg	  for obj in $save_oldobjs
10981c2939121Smrg	  do
10982c2939121Smrg	    last_oldobj=$obj
10983c2939121Smrg	  done
10984c2939121Smrg	  eval test_cmds=\"$old_archive_cmds\"
10985c2939121Smrg	  func_len " $test_cmds"
10986c2939121Smrg	  len0=$func_len_result
10987c2939121Smrg	  len=$len0
10988c2939121Smrg	  for obj in $save_oldobjs
10989c2939121Smrg	  do
10990c2939121Smrg	    func_len " $obj"
10991c2939121Smrg	    func_arith $len + $func_len_result
10992c2939121Smrg	    len=$func_arith_result
10993c2939121Smrg	    func_append objlist " $obj"
10994c2939121Smrg	    if test "$len" -lt "$max_cmd_len"; then
10995c2939121Smrg	      :
10996c2939121Smrg	    else
10997c2939121Smrg	      # the above command should be used before it gets too long
10998c2939121Smrg	      oldobjs=$objlist
109998292847cSmrg	      if test "$obj" = "$last_oldobj"; then
11000c2939121Smrg		RANLIB=$save_RANLIB
11001c2939121Smrg	      fi
11002c2939121Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
110038292847cSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004c2939121Smrg	      objlist=
11005c2939121Smrg	      len=$len0
11006c2939121Smrg	    fi
11007c2939121Smrg	  done
11008c2939121Smrg	  RANLIB=$save_RANLIB
11009c2939121Smrg	  oldobjs=$objlist
110108292847cSmrg	  if test -z "$oldobjs"; then
11011c2939121Smrg	    eval cmds=\"\$concat_cmds\"
11012c2939121Smrg	  else
11013c2939121Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014c2939121Smrg	  fi
11015c2939121Smrg	fi
11016c2939121Smrg      fi
11017c2939121Smrg      func_execute_cmds "$cmds" 'exit $?'
11018c76ae52dSmrg    done
11019c76ae52dSmrg
11020c2939121Smrg    test -n "$generated" && \
11021c2939121Smrg      func_show_eval "${RM}r$generated"
11022c76ae52dSmrg
11023c2939121Smrg    # Now create the libtool archive.
11024c2939121Smrg    case $output in
11025c2939121Smrg    *.la)
11026c2939121Smrg      old_library=
110278292847cSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028c2939121Smrg      func_verbose "creating $output"
11029c76ae52dSmrg
11030c2939121Smrg      # Preserve any variables that may affect compiler behavior
11031c2939121Smrg      for var in $variables_saved_for_relink; do
11032c2939121Smrg	if eval test -z \"\${$var+set}\"; then
11033c2939121Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034c2939121Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035c2939121Smrg	  relink_command="$var=; export $var; $relink_command"
11036c76ae52dSmrg	else
1103725420f97Smrg	  func_quote_arg pretty,unquoted "$var_value"
1103825420f97Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039c76ae52dSmrg	fi
11040c2939121Smrg      done
11041c2939121Smrg      # Quote the link command for shipping.
1104225420f97Smrg      func_quote eval cd "`pwd`"
1104325420f97Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1104425420f97Smrg      func_quote_arg pretty,unquoted "$relink_command"
1104525420f97Smrg      relink_command=$func_quote_arg_unquoted_result
110468292847cSmrg      if test yes = "$hardcode_automatic"; then
11047c2939121Smrg	relink_command=
11048c2939121Smrg      fi
11049c76ae52dSmrg
11050c2939121Smrg      # Only create the output if not a dry run.
11051c2939121Smrg      $opt_dry_run || {
11052c2939121Smrg	for installed in no yes; do
110538292847cSmrg	  if test yes = "$installed"; then
11054c2939121Smrg	    if test -z "$install_libdir"; then
11055c2939121Smrg	      break
11056c2939121Smrg	    fi
110578292847cSmrg	    output=$output_objdir/${outputname}i
11058c2939121Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11059c2939121Smrg	    newdependency_libs=
11060c2939121Smrg	    for deplib in $dependency_libs; do
11061c2939121Smrg	      case $deplib in
11062c2939121Smrg	      *.la)
11063c2939121Smrg		func_basename "$deplib"
110648292847cSmrg		name=$func_basename_result
110652836776bSmrg		func_resolve_sysroot "$deplib"
110668292847cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067c2939121Smrg		test -z "$libdir" && \
110688292847cSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
110692836776bSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
110702836776bSmrg		;;
110712836776bSmrg	      -L*)
110722836776bSmrg		func_stripname -L '' "$deplib"
110732836776bSmrg		func_replace_sysroot "$func_stripname_result"
110742836776bSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
110752836776bSmrg		;;
110762836776bSmrg	      -R*)
110772836776bSmrg		func_stripname -R '' "$deplib"
110782836776bSmrg		func_replace_sysroot "$func_stripname_result"
110792836776bSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080c2939121Smrg		;;
110812836776bSmrg	      *) func_append newdependency_libs " $deplib" ;;
11082c2939121Smrg	      esac
11083c2939121Smrg	    done
110848292847cSmrg	    dependency_libs=$newdependency_libs
11085c2939121Smrg	    newdlfiles=
11086c2939121Smrg
11087c2939121Smrg	    for lib in $dlfiles; do
11088c2939121Smrg	      case $lib in
11089c2939121Smrg	      *.la)
11090c2939121Smrg	        func_basename "$lib"
110918292847cSmrg		name=$func_basename_result
110928292847cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093c2939121Smrg		test -z "$libdir" && \
110948292847cSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
110952836776bSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096c2939121Smrg		;;
110972836776bSmrg	      *) func_append newdlfiles " $lib" ;;
11098c2939121Smrg	      esac
11099c2939121Smrg	    done
111008292847cSmrg	    dlfiles=$newdlfiles
11101c2939121Smrg	    newdlprefiles=
11102c2939121Smrg	    for lib in $dlprefiles; do
11103c2939121Smrg	      case $lib in
11104c2939121Smrg	      *.la)
11105c2939121Smrg		# Only pass preopened files to the pseudo-archive (for
11106c2939121Smrg		# eventual linking with the app. that links it) if we
11107c2939121Smrg		# didn't already link the preopened objects directly into
11108c2939121Smrg		# the library:
11109c2939121Smrg		func_basename "$lib"
111108292847cSmrg		name=$func_basename_result
111118292847cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112c2939121Smrg		test -z "$libdir" && \
111138292847cSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
111142836776bSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115c2939121Smrg		;;
11116c2939121Smrg	      esac
11117c2939121Smrg	    done
111188292847cSmrg	    dlprefiles=$newdlprefiles
11119c2939121Smrg	  else
11120c2939121Smrg	    newdlfiles=
11121c2939121Smrg	    for lib in $dlfiles; do
11122c2939121Smrg	      case $lib in
111238292847cSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124c2939121Smrg		*) abs=`pwd`"/$lib" ;;
11125c2939121Smrg	      esac
111262836776bSmrg	      func_append newdlfiles " $abs"
11127c2939121Smrg	    done
111288292847cSmrg	    dlfiles=$newdlfiles
11129c2939121Smrg	    newdlprefiles=
11130c2939121Smrg	    for lib in $dlprefiles; do
11131c2939121Smrg	      case $lib in
111328292847cSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133c2939121Smrg		*) abs=`pwd`"/$lib" ;;
11134c2939121Smrg	      esac
111352836776bSmrg	      func_append newdlprefiles " $abs"
11136c2939121Smrg	    done
111378292847cSmrg	    dlprefiles=$newdlprefiles
11138c2939121Smrg	  fi
11139c2939121Smrg	  $RM $output
11140c2939121Smrg	  # place dlname in correct position for cygwin
11141c2939121Smrg	  # In fact, it would be nice if we could use this code for all target
11142c2939121Smrg	  # systems that can't hard-code library paths into their executables
11143c2939121Smrg	  # and that have no shared library path variable independent of PATH,
11144c2939121Smrg	  # but it turns out we can't easily determine that from inspecting
11145c2939121Smrg	  # libtool variables, so we have to hard-code the OSs to which it
11146c2939121Smrg	  # applies here; at the moment, that means platforms that use the PE
11147c2939121Smrg	  # object format with DLL files.  See the long comment at the top of
11148c2939121Smrg	  # tests/bindir.at for full details.
11149c2939121Smrg	  tdlname=$dlname
11150c2939121Smrg	  case $host,$output,$installed,$module,$dlname in
11151c2939121Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152c2939121Smrg	      # If a -bindir argument was supplied, place the dll there.
111538292847cSmrg	      if test -n "$bindir"; then
11154c2939121Smrg		func_relative_path "$install_libdir" "$bindir"
111558292847cSmrg		tdlname=$func_relative_path_result/$dlname
11156c2939121Smrg	      else
11157c2939121Smrg		# Otherwise fall back on heuristic.
11158c2939121Smrg		tdlname=../bin/$dlname
11159c2939121Smrg	      fi
11160c2939121Smrg	      ;;
11161c2939121Smrg	  esac
11162c2939121Smrg	  $ECHO > $output "\
11163c2939121Smrg# $outputname - a libtool library file
111648292847cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165c2939121Smrg#
11166c2939121Smrg# Please DO NOT delete this file!
11167c2939121Smrg# It is necessary for linking the library.
11168c76ae52dSmrg
11169c2939121Smrg# The name that we can dlopen(3).
11170c2939121Smrgdlname='$tdlname'
11171c76ae52dSmrg
11172c2939121Smrg# Names of this library.
11173c2939121Smrglibrary_names='$library_names'
11174c76ae52dSmrg
11175c2939121Smrg# The name of the static archive.
11176c2939121Smrgold_library='$old_library'
11177c76ae52dSmrg
111788292847cSmrg# Linker flags that cannot go in dependency_libs.
11179c2939121Smrginherited_linker_flags='$new_inherited_linker_flags'
11180c76ae52dSmrg
11181c2939121Smrg# Libraries that this one depends upon.
11182c2939121Smrgdependency_libs='$dependency_libs'
11183c76ae52dSmrg
11184c2939121Smrg# Names of additional weak libraries provided by this library
11185c2939121Smrgweak_library_names='$weak_libs'
11186c76ae52dSmrg
11187c2939121Smrg# Version information for $libname.
11188c2939121Smrgcurrent=$current
11189c2939121Smrgage=$age
11190c2939121Smrgrevision=$revision
11191c76ae52dSmrg
11192c2939121Smrg# Is this an already installed library?
11193c2939121Smrginstalled=$installed
11194c76ae52dSmrg
11195c2939121Smrg# Should we warn about portability when linking against -modules?
11196c2939121Smrgshouldnotlink=$module
11197c76ae52dSmrg
11198c2939121Smrg# Files to dlopen/dlpreopen
11199c2939121Smrgdlopen='$dlfiles'
11200c2939121Smrgdlpreopen='$dlprefiles'
11201c76ae52dSmrg
11202c2939121Smrg# Directory that this library needs to be installed in:
11203c2939121Smrglibdir='$install_libdir'"
112048292847cSmrg	  if test no,yes = "$installed,$need_relink"; then
11205c2939121Smrg	    $ECHO >> $output "\
11206c2939121Smrgrelink_command=\"$relink_command\""
11207c2939121Smrg	  fi
11208c2939121Smrg	done
11209c2939121Smrg      }
11210c76ae52dSmrg
11211c2939121Smrg      # Do a symbolic link so that the libtool archive can be found in
11212c2939121Smrg      # LD_LIBRARY_PATH before the program is installed.
11213c2939121Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214c2939121Smrg      ;;
11215c2939121Smrg    esac
11216c2939121Smrg    exit $EXIT_SUCCESS
11217c2939121Smrg}
11218c76ae52dSmrg
112198292847cSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
112208292847cSmrg  func_mode_link ${1+"$@"}
112218292847cSmrgfi
11222c76ae52dSmrg
11223c76ae52dSmrg
11224c2939121Smrg# func_mode_uninstall arg...
11225c2939121Smrgfunc_mode_uninstall ()
11226c2939121Smrg{
112278292847cSmrg    $debug_cmd
112288292847cSmrg
112298292847cSmrg    RM=$nonopt
11230c76ae52dSmrg    files=
112318292847cSmrg    rmforce=false
11232c76ae52dSmrg    exit_status=0
11233c76ae52dSmrg
11234c76ae52dSmrg    # This variable tells wrapper scripts just to set variables rather
11235c76ae52dSmrg    # than running their programs.
112368292847cSmrg    libtool_install_magic=$magic
11237c76ae52dSmrg
11238c76ae52dSmrg    for arg
11239c76ae52dSmrg    do
11240c76ae52dSmrg      case $arg in
112418292847cSmrg      -f) func_append RM " $arg"; rmforce=: ;;
112422836776bSmrg      -*) func_append RM " $arg" ;;
112432836776bSmrg      *) func_append files " $arg" ;;
11244c76ae52dSmrg      esac
11245c76ae52dSmrg    done
11246c76ae52dSmrg
11247c2939121Smrg    test -z "$RM" && \
11248c2939121Smrg      func_fatal_help "you must specify an RM program"
11249c76ae52dSmrg
11250c76ae52dSmrg    rmdirs=
11251c76ae52dSmrg
11252c76ae52dSmrg    for file in $files; do
11253c2939121Smrg      func_dirname "$file" "" "."
112548292847cSmrg      dir=$func_dirname_result
112558292847cSmrg      if test . = "$dir"; then
112568292847cSmrg	odir=$objdir
11257c76ae52dSmrg      else
112588292847cSmrg	odir=$dir/$objdir
11259c76ae52dSmrg      fi
11260c2939121Smrg      func_basename "$file"
112618292847cSmrg      name=$func_basename_result
112628292847cSmrg      test uninstall = "$opt_mode" && odir=$dir
11263c76ae52dSmrg
112642836776bSmrg      # Remember odir for removal later, being careful to avoid duplicates
112658292847cSmrg      if test clean = "$opt_mode"; then
11266c76ae52dSmrg	case " $rmdirs " in
112672836776bSmrg	  *" $odir "*) ;;
112682836776bSmrg	  *) func_append rmdirs " $odir" ;;
11269c76ae52dSmrg	esac
11270c76ae52dSmrg      fi
11271c76ae52dSmrg
11272c76ae52dSmrg      # Don't error if the file doesn't exist and rm -f was used.
11273c2939121Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274c2939121Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275c2939121Smrg	 test -f "$file"; then
11276c76ae52dSmrg	:
11277c76ae52dSmrg      elif test -d "$file"; then
11278c76ae52dSmrg	exit_status=1
11279c76ae52dSmrg	continue
112808292847cSmrg      elif $rmforce; then
11281c76ae52dSmrg	continue
11282c76ae52dSmrg      fi
11283c76ae52dSmrg
112848292847cSmrg      rmfiles=$file
11285c76ae52dSmrg
11286c76ae52dSmrg      case $name in
11287c76ae52dSmrg      *.la)
11288c76ae52dSmrg	# Possibly a libtool archive, so verify it.
11289c2939121Smrg	if func_lalib_p "$file"; then
11290c2939121Smrg	  func_source $dir/$name
11291c76ae52dSmrg
11292c76ae52dSmrg	  # Delete the libtool libraries and symlinks.
11293c76ae52dSmrg	  for n in $library_names; do
112942836776bSmrg	    func_append rmfiles " $odir/$n"
11295c76ae52dSmrg	  done
112962836776bSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297c76ae52dSmrg
112988292847cSmrg	  case $opt_mode in
11299c76ae52dSmrg	  clean)
113002836776bSmrg	    case " $library_names " in
11301c76ae52dSmrg	    *" $dlname "*) ;;
113022836776bSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303c76ae52dSmrg	    esac
113042836776bSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305c76ae52dSmrg	    ;;
11306c76ae52dSmrg	  uninstall)
11307c76ae52dSmrg	    if test -n "$library_names"; then
11308c76ae52dSmrg	      # Do each command in the postuninstall commands.
113098292847cSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310c76ae52dSmrg	    fi
11311c76ae52dSmrg
11312c76ae52dSmrg	    if test -n "$old_library"; then
11313c76ae52dSmrg	      # Do each command in the old_postuninstall commands.
113148292847cSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315c76ae52dSmrg	    fi
11316c76ae52dSmrg	    # FIXME: should reinstall the best remaining shared library.
11317c76ae52dSmrg	    ;;
11318c76ae52dSmrg	  esac
11319c76ae52dSmrg	fi
11320c76ae52dSmrg	;;
11321c76ae52dSmrg
11322c76ae52dSmrg      *.lo)
11323c76ae52dSmrg	# Possibly a libtool object, so verify it.
11324c2939121Smrg	if func_lalib_p "$file"; then
11325c76ae52dSmrg
11326c76ae52dSmrg	  # Read the .lo file
11327c2939121Smrg	  func_source $dir/$name
11328c76ae52dSmrg
11329c76ae52dSmrg	  # Add PIC object to the list of files to remove.
113308292847cSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
113312836776bSmrg	    func_append rmfiles " $dir/$pic_object"
11332c76ae52dSmrg	  fi
11333c76ae52dSmrg
11334c76ae52dSmrg	  # Add non-PIC object to the list of files to remove.
113358292847cSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
113362836776bSmrg	    func_append rmfiles " $dir/$non_pic_object"
11337c76ae52dSmrg	  fi
11338c76ae52dSmrg	fi
11339c76ae52dSmrg	;;
11340c76ae52dSmrg
11341c76ae52dSmrg      *)
113428292847cSmrg	if test clean = "$opt_mode"; then
11343c76ae52dSmrg	  noexename=$name
11344c76ae52dSmrg	  case $file in
11345c76ae52dSmrg	  *.exe)
11346c2939121Smrg	    func_stripname '' '.exe' "$file"
11347c2939121Smrg	    file=$func_stripname_result
11348c2939121Smrg	    func_stripname '' '.exe' "$name"
11349c2939121Smrg	    noexename=$func_stripname_result
11350c76ae52dSmrg	    # $file with .exe has already been added to rmfiles,
11351c76ae52dSmrg	    # add $file without .exe
113522836776bSmrg	    func_append rmfiles " $file"
11353c76ae52dSmrg	    ;;
11354c76ae52dSmrg	  esac
11355c76ae52dSmrg	  # Do a test to see if this is a libtool program.
11356c2939121Smrg	  if func_ltwrapper_p "$file"; then
11357c2939121Smrg	    if func_ltwrapper_executable_p "$file"; then
11358c2939121Smrg	      func_ltwrapper_scriptname "$file"
11359c2939121Smrg	      relink_command=
11360c2939121Smrg	      func_source $func_ltwrapper_scriptname_result
113612836776bSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362c2939121Smrg	    else
11363c2939121Smrg	      relink_command=
11364c2939121Smrg	      func_source $dir/$noexename
11365c2939121Smrg	    fi
11366c76ae52dSmrg
11367c76ae52dSmrg	    # note $name still contains .exe if it was in $file originally
11368c76ae52dSmrg	    # as does the version of $file that was added into $rmfiles
113698292847cSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
113708292847cSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
113712836776bSmrg	      func_append rmfiles " $odir/lt-$name"
11372c76ae52dSmrg	    fi
113738292847cSmrg	    if test "X$noexename" != "X$name"; then
113748292847cSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375c76ae52dSmrg	    fi
11376c76ae52dSmrg	  fi
11377c76ae52dSmrg	fi
11378c76ae52dSmrg	;;
11379c76ae52dSmrg      esac
11380c2939121Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381c76ae52dSmrg    done
11382c76ae52dSmrg
113838292847cSmrg    # Try to remove the $objdir's in the directories where we deleted files
11384c76ae52dSmrg    for dir in $rmdirs; do
11385c76ae52dSmrg      if test -d "$dir"; then
11386c2939121Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387c76ae52dSmrg      fi
11388c76ae52dSmrg    done
11389c76ae52dSmrg
11390c76ae52dSmrg    exit $exit_status
11391c2939121Smrg}
11392c76ae52dSmrg
113938292847cSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
113948292847cSmrg  func_mode_uninstall ${1+"$@"}
113958292847cSmrgfi
11396c76ae52dSmrg
113972836776bSmrgtest -z "$opt_mode" && {
113988292847cSmrg  help=$generic_help
11399c2939121Smrg  func_fatal_help "you must specify a MODE"
11400c2939121Smrg}
11401c2939121Smrg
11402c2939121Smrgtest -z "$exec_cmd" && \
114038292847cSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404c76ae52dSmrg
11405c76ae52dSmrgif test -n "$exec_cmd"; then
11406c2939121Smrg  eval exec "$exec_cmd"
11407c76ae52dSmrg  exit $EXIT_FAILURE
11408c76ae52dSmrgfi
11409c76ae52dSmrg
11410c2939121Smrgexit $exit_status
11411c76ae52dSmrg
11412c76ae52dSmrg
11413c76ae52dSmrg# The TAGs below are defined such that we never get into a situation
114148292847cSmrg# where we disable both kinds of libraries.  Given conflicting
11415c76ae52dSmrg# choices, we go for a static library, that is the most portable,
11416c76ae52dSmrg# since we can't tell whether shared libraries were disabled because
11417c76ae52dSmrg# the user asked for that or because the platform doesn't support
11418c76ae52dSmrg# them.  This is particularly important on AIX, because we don't
11419c76ae52dSmrg# support having both static and shared libraries enabled at the same
11420c76ae52dSmrg# time on that platform, so we default to a shared-only configuration.
11421c76ae52dSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422c76ae52dSmrg# configuration.  But we'll never go from static-only to shared-only.
11423c76ae52dSmrg
11424c76ae52dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425c2939121Smrgbuild_libtool_libs=no
11426c2939121Smrgbuild_old_libs=yes
11427c76ae52dSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428c76ae52dSmrg
11429c76ae52dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430c2939121Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431c76ae52dSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432c76ae52dSmrg
11433c76ae52dSmrg# Local Variables:
11434c76ae52dSmrg# mode:shell-script
11435c76ae52dSmrg# sh-indentation:2
11436c76ae52dSmrg# End:
11437