14e8f48c7Smrg#! /usr/bin/env sh
248e5ce07Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
34e8f48c7Smrg##               by inline-source v2019-02-19.15
4c27c18e8Smrg
54e8f48c7Smrg# libtool (GNU libtool) 2.4.7
648e5ce07Smrg# Provide generalized library-building support services.
7c27c18e8Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8c27c18e8Smrg
94e8f48c7Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10c27c18e8Smrg# This is free software; see the source for copying conditions.  There is NO
11c27c18e8Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12c27c18e8Smrg
13c27c18e8Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14c43cc173Smrg# it under the terms of the GNU General Public License as published by
15c43cc173Smrg# the Free Software Foundation; either version 2 of the License, or
16c43cc173Smrg# (at your option) any later version.
17c43cc173Smrg#
18c27c18e8Smrg# As a special exception to the GNU General Public License,
19c27c18e8Smrg# if you distribute this file as part of a program or library that
20c27c18e8Smrg# is built using GNU Libtool, you may include this file under the
21c27c18e8Smrg# same distribution terms that you use for the rest of that program.
22c27c18e8Smrg#
23c27c18e8Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24c43cc173Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25c43cc173Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26c43cc173Smrg# General Public License for more details.
27c43cc173Smrg#
28c43cc173Smrg# You should have received a copy of the GNU General Public License
2948e5ce07Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
3044584a44Smrg
3144584a44Smrg
320eb1301bSmrgPROGRAM=libtool
330eb1301bSmrgPACKAGE=libtool
344e8f48c7SmrgVERSION=2.4.7
354e8f48c7Smrgpackage_revision=2.4.7
3644584a44Smrg
3748e5ce07Smrg
3848e5ce07Smrg## ------ ##
3948e5ce07Smrg## Usage. ##
4048e5ce07Smrg## ------ ##
4148e5ce07Smrg
4248e5ce07Smrg# Run './libtool --help' for help with using this script from the
4348e5ce07Smrg# command line.
4448e5ce07Smrg
4548e5ce07Smrg
4648e5ce07Smrg## ------------------------------- ##
4748e5ce07Smrg## User overridable command paths. ##
4848e5ce07Smrg## ------------------------------- ##
4948e5ce07Smrg
5048e5ce07Smrg# After configure completes, it has a better idea of some of the
5148e5ce07Smrg# shell tools we need than the defaults used by the functions shared
5248e5ce07Smrg# with bootstrap, so set those here where they can still be over-
5348e5ce07Smrg# ridden by the user, but otherwise take precedence.
5448e5ce07Smrg
5548e5ce07Smrg: ${AUTOCONF="autoconf"}
5648e5ce07Smrg: ${AUTOMAKE="automake"}
5748e5ce07Smrg
5848e5ce07Smrg
5948e5ce07Smrg## -------------------------- ##
6048e5ce07Smrg## Source external libraries. ##
6148e5ce07Smrg## -------------------------- ##
6248e5ce07Smrg
6348e5ce07Smrg# Much of our low-level functionality needs to be sourced from external
6448e5ce07Smrg# libraries, which are installed to $pkgauxdir.
6548e5ce07Smrg
6648e5ce07Smrg# Set a version string for this script.
674e8f48c7Smrgscriptversion=2019-02-19.15; # UTC
6848e5ce07Smrg
6948e5ce07Smrg# General shell script boiler plate, and helper functions.
7048e5ce07Smrg# Written by Gary V. Vaughan, 2004
7148e5ce07Smrg
724e8f48c7Smrg# This is free software.  There is NO warranty; not even for
734e8f48c7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
744e8f48c7Smrg#
754e8f48c7Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
764e8f48c7Smrg#
774e8f48c7Smrg# This file is dual licensed under the terms of the MIT license
784e8f48c7Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
794e8f48c7Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
804e8f48c7Smrg# these licenses when using or redistributing this software or any of
814e8f48c7Smrg# the files within it.  See the URLs above, or the file `LICENSE`
824e8f48c7Smrg# included in the Bootstrap distribution for the full license texts.
8348e5ce07Smrg
844e8f48c7Smrg# Please report bugs or propose patches to:
854e8f48c7Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
8648e5ce07Smrg
8748e5ce07Smrg
8848e5ce07Smrg## ------ ##
8948e5ce07Smrg## Usage. ##
9048e5ce07Smrg## ------ ##
9148e5ce07Smrg
9248e5ce07Smrg# Evaluate this file near the top of your script to gain access to
9348e5ce07Smrg# the functions and variables defined here:
9448e5ce07Smrg#
9548e5ce07Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
9648e5ce07Smrg#
9748e5ce07Smrg# If you need to override any of the default environment variable
9848e5ce07Smrg# settings, do that before evaluating this file.
9948e5ce07Smrg
10048e5ce07Smrg
10148e5ce07Smrg## -------------------- ##
10248e5ce07Smrg## Shell normalisation. ##
10348e5ce07Smrg## -------------------- ##
10448e5ce07Smrg
10548e5ce07Smrg# Some shells need a little help to be as Bourne compatible as possible.
10648e5ce07Smrg# Before doing anything else, make sure all that help has been provided!
10748e5ce07Smrg
10848e5ce07SmrgDUALCASE=1; export DUALCASE # for MKS sh
10948e5ce07Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
11021e67964Smrg  emulate sh
11121e67964Smrg  NULLCMD=:
11248e5ce07Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
11321e67964Smrg  # is contrary to our usage.  Disable this feature.
11421e67964Smrg  alias -g '${1+"$@"}'='"$@"'
115c43cc173Smrg  setopt NO_GLOB_SUBST
11621e67964Smrgelse
11748e5ce07Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
11844584a44Smrgfi
11944584a44Smrg
12048e5ce07Smrg# NLS nuisances: We save the old values in case they are required later.
12148e5ce07Smrg_G_user_locale=
12248e5ce07Smrg_G_safe_locale=
12348e5ce07Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1240eb1301bSmrgdo
12548e5ce07Smrg  eval "if test set = \"\${$_G_var+set}\"; then
12648e5ce07Smrg          save_$_G_var=\$$_G_var
12748e5ce07Smrg          $_G_var=C
12848e5ce07Smrg	  export $_G_var
12948e5ce07Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
13048e5ce07Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1310eb1301bSmrg	fi"
1320eb1301bSmrgdone
1334e8f48c7Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1344e8f48c7Smrg# in case the environment reset is needed later and the $save_* variant is not
1354e8f48c7Smrg# defined (see the code above).
1364e8f48c7SmrgLC_ALL=C
1374e8f48c7SmrgLANGUAGE=C
1384e8f48c7Smrgexport LANGUAGE LC_ALL
13944584a44Smrg
14048e5ce07Smrg# Make sure IFS has a sensible default
14148e5ce07Smrgsp=' '
14248e5ce07Smrgnl='
14348e5ce07Smrg'
14448e5ce07SmrgIFS="$sp	$nl"
14548e5ce07Smrg
14648e5ce07Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
14748e5ce07Smrgif test "${PATH_SEPARATOR+set}" != set; then
14848e5ce07Smrg  PATH_SEPARATOR=:
14948e5ce07Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
15048e5ce07Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
15148e5ce07Smrg      PATH_SEPARATOR=';'
15248e5ce07Smrg  }
15348e5ce07Smrgfi
15444584a44Smrg
15544584a44Smrg
1564e8f48c7Smrg# func_unset VAR
1574e8f48c7Smrg# --------------
1584e8f48c7Smrg# Portably unset VAR.
1594e8f48c7Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1604e8f48c7Smrg# status if VAR is already unset, which might be problematic if the
1614e8f48c7Smrg# statement is used at the end of a function (thus poisoning its return
1624e8f48c7Smrg# value) or when 'set -e' is active (causing even a spurious abort of
1634e8f48c7Smrg# the script in this case).
1644e8f48c7Smrgfunc_unset ()
1654e8f48c7Smrg{
1664e8f48c7Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1674e8f48c7Smrg}
1684e8f48c7Smrg
1694e8f48c7Smrg
1704e8f48c7Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1714e8f48c7Smrgfunc_unset CDPATH
1724e8f48c7Smrg
1734e8f48c7Smrg# Make sure ${,E,F}GREP behave sanely.
1744e8f48c7Smrgfunc_unset GREP_OPTIONS
1754e8f48c7Smrg
17644584a44Smrg
17748e5ce07Smrg## ------------------------- ##
17848e5ce07Smrg## Locate command utilities. ##
17948e5ce07Smrg## ------------------------- ##
18048e5ce07Smrg
18148e5ce07Smrg
18248e5ce07Smrg# func_executable_p FILE
18348e5ce07Smrg# ----------------------
18448e5ce07Smrg# Check that FILE is an executable regular file.
18548e5ce07Smrgfunc_executable_p ()
18648e5ce07Smrg{
18748e5ce07Smrg    test -f "$1" && test -x "$1"
18848e5ce07Smrg}
18948e5ce07Smrg
19048e5ce07Smrg
19148e5ce07Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
19248e5ce07Smrg# --------------------------------------------
19348e5ce07Smrg# Search for either a program that responds to --version with output
19448e5ce07Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
19548e5ce07Smrg# trying all the directories in PATH with each of the elements of
19648e5ce07Smrg# PROGS_LIST.
19748e5ce07Smrg#
19848e5ce07Smrg# CHECK_FUNC should accept the path to a candidate program, and
19948e5ce07Smrg# set $func_check_prog_result if it truncates its output less than
20048e5ce07Smrg# $_G_path_prog_max characters.
20148e5ce07Smrgfunc_path_progs ()
20248e5ce07Smrg{
20348e5ce07Smrg    _G_progs_list=$1
20448e5ce07Smrg    _G_check_func=$2
20548e5ce07Smrg    _G_PATH=${3-"$PATH"}
20648e5ce07Smrg
20748e5ce07Smrg    _G_path_prog_max=0
20848e5ce07Smrg    _G_path_prog_found=false
20948e5ce07Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
21048e5ce07Smrg    for _G_dir in $_G_PATH; do
21148e5ce07Smrg      IFS=$_G_save_IFS
21248e5ce07Smrg      test -z "$_G_dir" && _G_dir=.
21348e5ce07Smrg      for _G_prog_name in $_G_progs_list; do
21448e5ce07Smrg        for _exeext in '' .EXE; do
21548e5ce07Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
21648e5ce07Smrg          func_executable_p "$_G_path_prog" || continue
21748e5ce07Smrg          case `"$_G_path_prog" --version 2>&1` in
21848e5ce07Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
21948e5ce07Smrg            *)     $_G_check_func $_G_path_prog
22048e5ce07Smrg		   func_path_progs_result=$func_check_prog_result
22148e5ce07Smrg		   ;;
22248e5ce07Smrg          esac
22348e5ce07Smrg          $_G_path_prog_found && break 3
22448e5ce07Smrg        done
22548e5ce07Smrg      done
22648e5ce07Smrg    done
22748e5ce07Smrg    IFS=$_G_save_IFS
22848e5ce07Smrg    test -z "$func_path_progs_result" && {
22948e5ce07Smrg      echo "no acceptable sed could be found in \$PATH" >&2
23048e5ce07Smrg      exit 1
23148e5ce07Smrg    }
23248e5ce07Smrg}
23348e5ce07Smrg
23448e5ce07Smrg
23548e5ce07Smrg# We want to be able to use the functions in this file before configure
23648e5ce07Smrg# has figured out where the best binaries are kept, which means we have
23748e5ce07Smrg# to search for them ourselves - except when the results are already set
23848e5ce07Smrg# where we skip the searches.
23948e5ce07Smrg
24048e5ce07Smrg# Unless the user overrides by setting SED, search the path for either GNU
24148e5ce07Smrg# sed, or the sed that truncates its output the least.
24248e5ce07Smrgtest -z "$SED" && {
24348e5ce07Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
24448e5ce07Smrg  for _G_i in 1 2 3 4 5 6 7; do
24548e5ce07Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
24648e5ce07Smrg  done
24748e5ce07Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
24848e5ce07Smrg  _G_sed_script=
24948e5ce07Smrg
25048e5ce07Smrg  func_check_prog_sed ()
25148e5ce07Smrg  {
25248e5ce07Smrg    _G_path_prog=$1
25348e5ce07Smrg
25448e5ce07Smrg    _G_count=0
25548e5ce07Smrg    printf 0123456789 >conftest.in
25648e5ce07Smrg    while :
25748e5ce07Smrg    do
25848e5ce07Smrg      cat conftest.in conftest.in >conftest.tmp
25948e5ce07Smrg      mv conftest.tmp conftest.in
26048e5ce07Smrg      cp conftest.in conftest.nl
26148e5ce07Smrg      echo '' >> conftest.nl
26248e5ce07Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
26348e5ce07Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
26448e5ce07Smrg      _G_count=`expr $_G_count + 1`
26548e5ce07Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
26648e5ce07Smrg        # Best one so far, save it but keep looking for a better one
26748e5ce07Smrg        func_check_prog_result=$_G_path_prog
26848e5ce07Smrg        _G_path_prog_max=$_G_count
26948e5ce07Smrg      fi
27048e5ce07Smrg      # 10*(2^10) chars as input seems more than enough
27148e5ce07Smrg      test 10 -lt "$_G_count" && break
27248e5ce07Smrg    done
27348e5ce07Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
27448e5ce07Smrg  }
27548e5ce07Smrg
2764e8f48c7Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
27748e5ce07Smrg  rm -f conftest.sed
27848e5ce07Smrg  SED=$func_path_progs_result
27948e5ce07Smrg}
28048e5ce07Smrg
28148e5ce07Smrg
28248e5ce07Smrg# Unless the user overrides by setting GREP, search the path for either GNU
28348e5ce07Smrg# grep, or the grep that truncates its output the least.
28448e5ce07Smrgtest -z "$GREP" && {
28548e5ce07Smrg  func_check_prog_grep ()
28648e5ce07Smrg  {
28748e5ce07Smrg    _G_path_prog=$1
28848e5ce07Smrg
28948e5ce07Smrg    _G_count=0
29048e5ce07Smrg    _G_path_prog_max=0
29148e5ce07Smrg    printf 0123456789 >conftest.in
29248e5ce07Smrg    while :
29348e5ce07Smrg    do
29448e5ce07Smrg      cat conftest.in conftest.in >conftest.tmp
29548e5ce07Smrg      mv conftest.tmp conftest.in
29648e5ce07Smrg      cp conftest.in conftest.nl
29748e5ce07Smrg      echo 'GREP' >> conftest.nl
29848e5ce07Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
29948e5ce07Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
30048e5ce07Smrg      _G_count=`expr $_G_count + 1`
30148e5ce07Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
30248e5ce07Smrg        # Best one so far, save it but keep looking for a better one
30348e5ce07Smrg        func_check_prog_result=$_G_path_prog
30448e5ce07Smrg        _G_path_prog_max=$_G_count
30548e5ce07Smrg      fi
30648e5ce07Smrg      # 10*(2^10) chars as input seems more than enough
30748e5ce07Smrg      test 10 -lt "$_G_count" && break
30848e5ce07Smrg    done
30948e5ce07Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
31048e5ce07Smrg  }
31148e5ce07Smrg
3124e8f48c7Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
31348e5ce07Smrg  GREP=$func_path_progs_result
31448e5ce07Smrg}
31548e5ce07Smrg
31648e5ce07Smrg
31748e5ce07Smrg## ------------------------------- ##
31848e5ce07Smrg## User overridable command paths. ##
31948e5ce07Smrg## ------------------------------- ##
32048e5ce07Smrg
32148e5ce07Smrg# All uppercase variable names are used for environment variables.  These
32248e5ce07Smrg# variables can be overridden by the user before calling a script that
32348e5ce07Smrg# uses them if a suitable command of that name is not already available
32448e5ce07Smrg# in the command search PATH.
325c27c18e8Smrg
326c27c18e8Smrg: ${CP="cp -f"}
32748e5ce07Smrg: ${ECHO="printf %s\n"}
32848e5ce07Smrg: ${EGREP="$GREP -E"}
32948e5ce07Smrg: ${FGREP="$GREP -F"}
33048e5ce07Smrg: ${LN_S="ln -s"}
331c27c18e8Smrg: ${MAKE="make"}
332c27c18e8Smrg: ${MKDIR="mkdir"}
333c27c18e8Smrg: ${MV="mv -f"}
334c27c18e8Smrg: ${RM="rm -f"}
335c27c18e8Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336b789ec8aSmrg
337b789ec8aSmrg
33848e5ce07Smrg## -------------------- ##
33948e5ce07Smrg## Useful sed snippets. ##
34048e5ce07Smrg## -------------------- ##
341b789ec8aSmrg
34248e5ce07Smrgsed_dirname='s|/[^/]*$||'
34348e5ce07Smrgsed_basename='s|^.*/||'
344b789ec8aSmrg
34548e5ce07Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
34648e5ce07Smrg# metacharacters that are still active within double-quoted strings.
34748e5ce07Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348b789ec8aSmrg
34948e5ce07Smrg# Same as above, but do not quote variable references.
35048e5ce07Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351c43cc173Smrg
35248e5ce07Smrg# Sed substitution that turns a string into a regex matching for the
35348e5ce07Smrg# string literally.
35448e5ce07Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355c27c18e8Smrg
35648e5ce07Smrg# Sed substitution that converts a w32 file name or path
35748e5ce07Smrg# that contains forward slashes, into one that contains
35848e5ce07Smrg# (escaped) backslashes.  A very naive implementation.
35948e5ce07Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
36048e5ce07Smrg
36148e5ce07Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
36248e5ce07Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
36348e5ce07Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
36448e5ce07Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
36548e5ce07Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
36648e5ce07Smrg_G_bs='\\'
36748e5ce07Smrg_G_bs2='\\\\'
36848e5ce07Smrg_G_bs4='\\\\\\\\'
36948e5ce07Smrg_G_dollar='\$'
37048e5ce07Smrgsed_double_backslash="\
37148e5ce07Smrg  s/$_G_bs4/&\\
37248e5ce07Smrg/g
37348e5ce07Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
37448e5ce07Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
37548e5ce07Smrg  s/\n//g"
37637eb1ca1Smrg
3774e8f48c7Smrg# require_check_ifs_backslash
3784e8f48c7Smrg# ---------------------------
3794e8f48c7Smrg# Check if we can use backslash as IFS='\' separator, and set
3804e8f48c7Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
3814e8f48c7Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3824e8f48c7Smrgfunc_require_check_ifs_backslash ()
3834e8f48c7Smrg{
3844e8f48c7Smrg  _G_save_IFS=$IFS
3854e8f48c7Smrg  IFS='\'
3864e8f48c7Smrg  _G_check_ifs_backshlash='a\\b'
3874e8f48c7Smrg  for _G_i in $_G_check_ifs_backshlash
3884e8f48c7Smrg  do
3894e8f48c7Smrg  case $_G_i in
3904e8f48c7Smrg  a)
3914e8f48c7Smrg    check_ifs_backshlash_broken=false
3924e8f48c7Smrg    ;;
3934e8f48c7Smrg  '')
3944e8f48c7Smrg    break
3954e8f48c7Smrg    ;;
3964e8f48c7Smrg  *)
3974e8f48c7Smrg    check_ifs_backshlash_broken=:
3984e8f48c7Smrg    break
3994e8f48c7Smrg    ;;
4004e8f48c7Smrg  esac
4014e8f48c7Smrg  done
4024e8f48c7Smrg  IFS=$_G_save_IFS
4034e8f48c7Smrg  require_check_ifs_backslash=:
4044e8f48c7Smrg}
4054e8f48c7Smrg
40637eb1ca1Smrg
40748e5ce07Smrg## ----------------- ##
40848e5ce07Smrg## Global variables. ##
40948e5ce07Smrg## ----------------- ##
41037eb1ca1Smrg
41148e5ce07Smrg# Except for the global variables explicitly listed below, the following
41248e5ce07Smrg# functions in the '^func_' namespace, and the '^require_' namespace
41348e5ce07Smrg# variables initialised in the 'Resource management' section, sourcing
41448e5ce07Smrg# this file will not pollute your global namespace with anything
41548e5ce07Smrg# else. There's no portable way to scope variables in Bourne shell
41648e5ce07Smrg# though, so actually running these functions will sometimes place
41748e5ce07Smrg# results into a variable named after the function, and often use
41848e5ce07Smrg# temporary variables in the '^_G_' namespace. If you are careful to
41948e5ce07Smrg# avoid using those namespaces casually in your sourcing script, things
42048e5ce07Smrg# should continue to work as you expect. And, of course, you can freely
42148e5ce07Smrg# overwrite any of the functions or variables defined here before
42248e5ce07Smrg# calling anything to customize them.
42337eb1ca1Smrg
42448e5ce07SmrgEXIT_SUCCESS=0
42548e5ce07SmrgEXIT_FAILURE=1
42648e5ce07SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
42748e5ce07SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4280eb1301bSmrg
42948e5ce07Smrg# Allow overriding, eg assuming that you follow the convention of
43048e5ce07Smrg# putting '$debug_cmd' at the start of all your functions, you can get
43148e5ce07Smrg# bash to show function call trace with:
43248e5ce07Smrg#
4334e8f48c7Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
43448e5ce07Smrgdebug_cmd=${debug_cmd-":"}
43548e5ce07Smrgexit_cmd=:
4360eb1301bSmrg
43748e5ce07Smrg# By convention, finish your script with:
43848e5ce07Smrg#
43948e5ce07Smrg#    exit $exit_status
44048e5ce07Smrg#
44148e5ce07Smrg# so that you can set exit_status to non-zero if you want to indicate
44248e5ce07Smrg# something went wrong during execution without actually bailing out at
44348e5ce07Smrg# the point of failure.
44448e5ce07Smrgexit_status=$EXIT_SUCCESS
4450eb1301bSmrg
44648e5ce07Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
44748e5ce07Smrg# is ksh but when the shell is invoked as "sh" and the current value of
44848e5ce07Smrg# the _XPG environment variable is not equal to 1 (one), the special
44948e5ce07Smrg# positional parameter $0, within a function call, is the name of the
45048e5ce07Smrg# function.
45148e5ce07Smrgprogpath=$0
452c27c18e8Smrg
45348e5ce07Smrg# The name of this program.
45448e5ce07Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455c27c18e8Smrg
45648e5ce07Smrg# Make sure we have an absolute progpath for reexecution:
457c27c18e8Smrgcase $progpath in
458c27c18e8Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459c27c18e8Smrg  *[\\/]*)
46048e5ce07Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461c27c18e8Smrg     progdir=`cd "$progdir" && pwd`
46248e5ce07Smrg     progpath=$progdir/$progname
463c27c18e8Smrg     ;;
464c27c18e8Smrg  *)
46548e5ce07Smrg     _G_IFS=$IFS
466f1ee322dSmrg     IFS=${PATH_SEPARATOR-:}
467c27c18e8Smrg     for progdir in $PATH; do
46848e5ce07Smrg       IFS=$_G_IFS
469c27c18e8Smrg       test -x "$progdir/$progname" && break
470c27c18e8Smrg     done
47148e5ce07Smrg     IFS=$_G_IFS
472c27c18e8Smrg     test -n "$progdir" || progdir=`pwd`
47348e5ce07Smrg     progpath=$progdir/$progname
474c27c18e8Smrg     ;;
475c27c18e8Smrgesac
476c27c18e8Smrg
477c27c18e8Smrg
47848e5ce07Smrg## ----------------- ##
47948e5ce07Smrg## Standard options. ##
48048e5ce07Smrg## ----------------- ##
481b789ec8aSmrg
48248e5ce07Smrg# The following options affect the operation of the functions defined
48348e5ce07Smrg# below, and should be set appropriately depending on run-time para-
48448e5ce07Smrg# meters passed on the command line.
485c27c18e8Smrg
486c27c18e8Smrgopt_dry_run=false
487c27c18e8Smrgopt_quiet=false
488c27c18e8Smrgopt_verbose=false
489c27c18e8Smrg
49048e5ce07Smrg# Categories 'all' and 'none' are always available.  Append any others
49148e5ce07Smrg# you will pass as the first argument to func_warning from your own
49248e5ce07Smrg# code.
49348e5ce07Smrgwarning_categories=
494c27c18e8Smrg
49548e5ce07Smrg# By default, display warnings according to 'opt_warning_types'.  Set
49648e5ce07Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
49748e5ce07Smrg# treat the next displayed warning as a fatal error.
49848e5ce07Smrgwarning_func=func_warn_and_continue
499c27c18e8Smrg
50048e5ce07Smrg# Set to 'all' to display all warnings, 'none' to suppress all
50148e5ce07Smrg# warnings, or a space delimited list of some subset of
50248e5ce07Smrg# 'warning_categories' to display only the listed warnings.
50348e5ce07Smrgopt_warning_types=all
504c27c18e8Smrg
50537eb1ca1Smrg
50648e5ce07Smrg## -------------------- ##
50748e5ce07Smrg## Resource management. ##
50848e5ce07Smrg## -------------------- ##
509c27c18e8Smrg
51048e5ce07Smrg# This section contains definitions for functions that each ensure a
51148e5ce07Smrg# particular resource (a file, or a non-empty configuration variable for
51248e5ce07Smrg# example) is available, and if appropriate to extract default values
51348e5ce07Smrg# from pertinent package files. Call them using their associated
51448e5ce07Smrg# 'require_*' variable to ensure that they are executed, at most, once.
51548e5ce07Smrg#
51648e5ce07Smrg# It's entirely deliberate that calling these functions can set
51748e5ce07Smrg# variables that don't obey the namespace limitations obeyed by the rest
51848e5ce07Smrg# of this file, in order that that they be as useful as possible to
51948e5ce07Smrg# callers.
520c27c18e8Smrg
521c27c18e8Smrg
52248e5ce07Smrg# require_term_colors
52348e5ce07Smrg# -------------------
52448e5ce07Smrg# Allow display of bold text on terminals that support it.
52548e5ce07Smrgrequire_term_colors=func_require_term_colors
52648e5ce07Smrgfunc_require_term_colors ()
527c27c18e8Smrg{
52848e5ce07Smrg    $debug_cmd
52948e5ce07Smrg
53048e5ce07Smrg    test -t 1 && {
53148e5ce07Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
53248e5ce07Smrg      # precedence, because most terminfo databases neglect to describe
53348e5ce07Smrg      # whether color sequences are supported.
53448e5ce07Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
53548e5ce07Smrg
53648e5ce07Smrg      if test 1 = "$USE_ANSI_COLORS"; then
53748e5ce07Smrg        # Standard ANSI escape sequences
53848e5ce07Smrg        tc_reset='[0m'
53948e5ce07Smrg        tc_bold='[1m';   tc_standout='[7m'
54048e5ce07Smrg        tc_red='[31m';   tc_green='[32m'
54148e5ce07Smrg        tc_blue='[34m';  tc_cyan='[36m'
54248e5ce07Smrg      else
54348e5ce07Smrg        # Otherwise trust the terminfo database after all.
54448e5ce07Smrg        test -n "`tput sgr0 2>/dev/null`" && {
54548e5ce07Smrg          tc_reset=`tput sgr0`
54648e5ce07Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
54748e5ce07Smrg          tc_standout=$tc_bold
54848e5ce07Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
54948e5ce07Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
55048e5ce07Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
55148e5ce07Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
55248e5ce07Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
55348e5ce07Smrg        }
55448e5ce07Smrg      fi
55548e5ce07Smrg    }
556c27c18e8Smrg
55748e5ce07Smrg    require_term_colors=:
558c27c18e8Smrg}
559c27c18e8Smrg
560c27c18e8Smrg
56148e5ce07Smrg## ----------------- ##
56248e5ce07Smrg## Function library. ##
56348e5ce07Smrg## ----------------- ##
56448e5ce07Smrg
56548e5ce07Smrg# This section contains a variety of useful functions to call in your
56648e5ce07Smrg# scripts. Take note of the portable wrappers for features provided by
56748e5ce07Smrg# some modern shells, which will fall back to slower equivalents on
56848e5ce07Smrg# less featureful shells.
56948e5ce07Smrg
57048e5ce07Smrg
57148e5ce07Smrg# func_append VAR VALUE
57248e5ce07Smrg# ---------------------
57348e5ce07Smrg# Append VALUE onto the existing contents of VAR.
57448e5ce07Smrg
57548e5ce07Smrg  # We should try to minimise forks, especially on Windows where they are
57648e5ce07Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
57748e5ce07Smrg  # being used:
57848e5ce07Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
57948e5ce07Smrg    : ${_G_HAVE_ARITH_OP="yes"}
58048e5ce07Smrg    : ${_G_HAVE_XSI_OPS="yes"}
58148e5ce07Smrg    # The += operator was introduced in bash 3.1
58248e5ce07Smrg    case $BASH_VERSION in
58348e5ce07Smrg      [12].* | 3.0 | 3.0*) ;;
58448e5ce07Smrg      *)
58548e5ce07Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
58648e5ce07Smrg        ;;
58748e5ce07Smrg    esac
58848e5ce07Smrg  fi
58948e5ce07Smrg
59048e5ce07Smrg  # _G_HAVE_PLUSEQ_OP
59148e5ce07Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
59248e5ce07Smrg  # useable or anything else if it does not work.
59348e5ce07Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
59448e5ce07Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
59548e5ce07Smrg    && _G_HAVE_PLUSEQ_OP=yes
59648e5ce07Smrg
59748e5ce07Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
59848e5ce07Smrgthen
59948e5ce07Smrg  # This is an XSI compatible shell, allowing a faster implementation...
60048e5ce07Smrg  eval 'func_append ()
60148e5ce07Smrg  {
60248e5ce07Smrg    $debug_cmd
60348e5ce07Smrg
60448e5ce07Smrg    eval "$1+=\$2"
60548e5ce07Smrg  }'
60648e5ce07Smrgelse
60748e5ce07Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
60848e5ce07Smrg  func_append ()
60948e5ce07Smrg  {
61048e5ce07Smrg    $debug_cmd
61148e5ce07Smrg
61248e5ce07Smrg    eval "$1=\$$1\$2"
61348e5ce07Smrg  }
61448e5ce07Smrgfi
61548e5ce07Smrg
61648e5ce07Smrg
61748e5ce07Smrg# func_append_quoted VAR VALUE
61848e5ce07Smrg# ----------------------------
61948e5ce07Smrg# Quote VALUE and append to the end of shell variable VAR, separated
62048e5ce07Smrg# by a space.
62148e5ce07Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
62248e5ce07Smrg  eval 'func_append_quoted ()
62348e5ce07Smrg  {
62448e5ce07Smrg    $debug_cmd
62548e5ce07Smrg
6264e8f48c7Smrg    func_quote_arg pretty "$2"
6274e8f48c7Smrg    eval "$1+=\\ \$func_quote_arg_result"
62848e5ce07Smrg  }'
62948e5ce07Smrgelse
63048e5ce07Smrg  func_append_quoted ()
63148e5ce07Smrg  {
63248e5ce07Smrg    $debug_cmd
63348e5ce07Smrg
6344e8f48c7Smrg    func_quote_arg pretty "$2"
6354e8f48c7Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
63648e5ce07Smrg  }
63748e5ce07Smrgfi
63848e5ce07Smrg
63948e5ce07Smrg
64048e5ce07Smrg# func_append_uniq VAR VALUE
64148e5ce07Smrg# --------------------------
64248e5ce07Smrg# Append unique VALUE onto the existing contents of VAR, assuming
64348e5ce07Smrg# entries are delimited by the first character of VALUE.  For example:
64448e5ce07Smrg#
64548e5ce07Smrg#   func_append_uniq options " --another-option option-argument"
64648e5ce07Smrg#
64748e5ce07Smrg# will only append to $options if " --another-option option-argument "
64848e5ce07Smrg# is not already present somewhere in $options already (note spaces at
64948e5ce07Smrg# each end implied by leading space in second argument).
65048e5ce07Smrgfunc_append_uniq ()
65148e5ce07Smrg{
65248e5ce07Smrg    $debug_cmd
65348e5ce07Smrg
65448e5ce07Smrg    eval _G_current_value='`$ECHO $'$1'`'
65548e5ce07Smrg    _G_delim=`expr "$2" : '\(.\)'`
65648e5ce07Smrg
65748e5ce07Smrg    case $_G_delim$_G_current_value$_G_delim in
65848e5ce07Smrg      *"$2$_G_delim"*) ;;
65948e5ce07Smrg      *) func_append "$@" ;;
66048e5ce07Smrg    esac
66148e5ce07Smrg}
66248e5ce07Smrg
66348e5ce07Smrg
66448e5ce07Smrg# func_arith TERM...
66548e5ce07Smrg# ------------------
66648e5ce07Smrg# Set func_arith_result to the result of evaluating TERMs.
66748e5ce07Smrg  test -z "$_G_HAVE_ARITH_OP" \
66848e5ce07Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
66948e5ce07Smrg    && _G_HAVE_ARITH_OP=yes
67048e5ce07Smrg
67148e5ce07Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
67248e5ce07Smrg  eval 'func_arith ()
67348e5ce07Smrg  {
67448e5ce07Smrg    $debug_cmd
67548e5ce07Smrg
67648e5ce07Smrg    func_arith_result=$(( $* ))
67748e5ce07Smrg  }'
67848e5ce07Smrgelse
67948e5ce07Smrg  func_arith ()
68048e5ce07Smrg  {
68148e5ce07Smrg    $debug_cmd
68248e5ce07Smrg
68348e5ce07Smrg    func_arith_result=`expr "$@"`
68448e5ce07Smrg  }
68548e5ce07Smrgfi
68648e5ce07Smrg
68748e5ce07Smrg
68848e5ce07Smrg# func_basename FILE
68948e5ce07Smrg# ------------------
69048e5ce07Smrg# Set func_basename_result to FILE with everything up to and including
69148e5ce07Smrg# the last / stripped.
69248e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
69348e5ce07Smrg  # If this shell supports suffix pattern removal, then use it to avoid
69448e5ce07Smrg  # forking. Hide the definitions single quotes in case the shell chokes
69548e5ce07Smrg  # on unsupported syntax...
69648e5ce07Smrg  _b='func_basename_result=${1##*/}'
69748e5ce07Smrg  _d='case $1 in
69848e5ce07Smrg        */*) func_dirname_result=${1%/*}$2 ;;
69948e5ce07Smrg        *  ) func_dirname_result=$3        ;;
70048e5ce07Smrg      esac'
70148e5ce07Smrg
70248e5ce07Smrgelse
70348e5ce07Smrg  # ...otherwise fall back to using sed.
70448e5ce07Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
70548e5ce07Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
70648e5ce07Smrg      if test "X$func_dirname_result" = "X$1"; then
70748e5ce07Smrg        func_dirname_result=$3
70848e5ce07Smrg      else
70948e5ce07Smrg        func_append func_dirname_result "$2"
71048e5ce07Smrg      fi'
71148e5ce07Smrgfi
71248e5ce07Smrg
71348e5ce07Smrgeval 'func_basename ()
71448e5ce07Smrg{
71548e5ce07Smrg    $debug_cmd
71648e5ce07Smrg
71748e5ce07Smrg    '"$_b"'
71848e5ce07Smrg}'
71948e5ce07Smrg
72048e5ce07Smrg
72148e5ce07Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
72248e5ce07Smrg# -------------------------------------------
72348e5ce07Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
72448e5ce07Smrg# otherwise set result to NONDIR_REPLACEMENT.
72548e5ce07Smrgeval 'func_dirname ()
72648e5ce07Smrg{
72748e5ce07Smrg    $debug_cmd
72848e5ce07Smrg
72948e5ce07Smrg    '"$_d"'
73048e5ce07Smrg}'
73148e5ce07Smrg
73248e5ce07Smrg
73348e5ce07Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
73448e5ce07Smrg# --------------------------------------------------------
73548e5ce07Smrg# Perform func_basename and func_dirname in a single function
73648e5ce07Smrg# call:
73748e5ce07Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
73848e5ce07Smrg#             add APPEND to the result, otherwise set result
73948e5ce07Smrg#             to NONDIR_REPLACEMENT.
74048e5ce07Smrg#             value returned in "$func_dirname_result"
74148e5ce07Smrg#   basename: Compute filename of FILE.
74248e5ce07Smrg#             value retuned in "$func_basename_result"
74348e5ce07Smrg# For efficiency, we do not delegate to the functions above but instead
74448e5ce07Smrg# duplicate the functionality here.
74548e5ce07Smrgeval 'func_dirname_and_basename ()
74648e5ce07Smrg{
74748e5ce07Smrg    $debug_cmd
74848e5ce07Smrg
74948e5ce07Smrg    '"$_b"'
75048e5ce07Smrg    '"$_d"'
75148e5ce07Smrg}'
75248e5ce07Smrg
75348e5ce07Smrg
75448e5ce07Smrg# func_echo ARG...
75548e5ce07Smrg# ----------------
75648e5ce07Smrg# Echo program name prefixed message.
75748e5ce07Smrgfunc_echo ()
75848e5ce07Smrg{
75948e5ce07Smrg    $debug_cmd
76048e5ce07Smrg
76148e5ce07Smrg    _G_message=$*
76248e5ce07Smrg
76348e5ce07Smrg    func_echo_IFS=$IFS
76448e5ce07Smrg    IFS=$nl
76548e5ce07Smrg    for _G_line in $_G_message; do
76648e5ce07Smrg      IFS=$func_echo_IFS
76748e5ce07Smrg      $ECHO "$progname: $_G_line"
76848e5ce07Smrg    done
76948e5ce07Smrg    IFS=$func_echo_IFS
77048e5ce07Smrg}
77148e5ce07Smrg
77248e5ce07Smrg
77348e5ce07Smrg# func_echo_all ARG...
77448e5ce07Smrg# --------------------
77548e5ce07Smrg# Invoke $ECHO with all args, space-separated.
77648e5ce07Smrgfunc_echo_all ()
77748e5ce07Smrg{
77848e5ce07Smrg    $ECHO "$*"
77948e5ce07Smrg}
78048e5ce07Smrg
78148e5ce07Smrg
78248e5ce07Smrg# func_echo_infix_1 INFIX ARG...
78348e5ce07Smrg# ------------------------------
78448e5ce07Smrg# Echo program name, followed by INFIX on the first line, with any
78548e5ce07Smrg# additional lines not showing INFIX.
78648e5ce07Smrgfunc_echo_infix_1 ()
78748e5ce07Smrg{
78848e5ce07Smrg    $debug_cmd
78948e5ce07Smrg
79048e5ce07Smrg    $require_term_colors
79148e5ce07Smrg
79248e5ce07Smrg    _G_infix=$1; shift
79348e5ce07Smrg    _G_indent=$_G_infix
79448e5ce07Smrg    _G_prefix="$progname: $_G_infix: "
79548e5ce07Smrg    _G_message=$*
79648e5ce07Smrg
79748e5ce07Smrg    # Strip color escape sequences before counting printable length
79848e5ce07Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
79948e5ce07Smrg    do
80048e5ce07Smrg      test -n "$_G_tc" && {
80148e5ce07Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
80248e5ce07Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
80348e5ce07Smrg      }
80448e5ce07Smrg    done
80548e5ce07Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
80648e5ce07Smrg
80748e5ce07Smrg    func_echo_infix_1_IFS=$IFS
80848e5ce07Smrg    IFS=$nl
80948e5ce07Smrg    for _G_line in $_G_message; do
81048e5ce07Smrg      IFS=$func_echo_infix_1_IFS
81148e5ce07Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
81248e5ce07Smrg      _G_prefix=$_G_indent
81348e5ce07Smrg    done
81448e5ce07Smrg    IFS=$func_echo_infix_1_IFS
81548e5ce07Smrg}
81648e5ce07Smrg
81748e5ce07Smrg
81848e5ce07Smrg# func_error ARG...
81948e5ce07Smrg# -----------------
82048e5ce07Smrg# Echo program name prefixed message to standard error.
82148e5ce07Smrgfunc_error ()
82248e5ce07Smrg{
82348e5ce07Smrg    $debug_cmd
82448e5ce07Smrg
82548e5ce07Smrg    $require_term_colors
82648e5ce07Smrg
82748e5ce07Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
82848e5ce07Smrg}
82948e5ce07Smrg
83048e5ce07Smrg
83148e5ce07Smrg# func_fatal_error ARG...
83248e5ce07Smrg# -----------------------
83348e5ce07Smrg# Echo program name prefixed message to standard error, and exit.
83448e5ce07Smrgfunc_fatal_error ()
83548e5ce07Smrg{
83648e5ce07Smrg    $debug_cmd
83748e5ce07Smrg
83848e5ce07Smrg    func_error "$*"
83948e5ce07Smrg    exit $EXIT_FAILURE
84048e5ce07Smrg}
84148e5ce07Smrg
84248e5ce07Smrg
84348e5ce07Smrg# func_grep EXPRESSION FILENAME
84448e5ce07Smrg# -----------------------------
845c27c18e8Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846c27c18e8Smrgfunc_grep ()
847c27c18e8Smrg{
84848e5ce07Smrg    $debug_cmd
84948e5ce07Smrg
850c27c18e8Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851c27c18e8Smrg}
852c27c18e8Smrg
853c27c18e8Smrg
85448e5ce07Smrg# func_len STRING
85548e5ce07Smrg# ---------------
85648e5ce07Smrg# Set func_len_result to the length of STRING. STRING may not
85748e5ce07Smrg# start with a hyphen.
85848e5ce07Smrg  test -z "$_G_HAVE_XSI_OPS" \
85948e5ce07Smrg    && (eval 'x=a/b/c;
86048e5ce07Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
86148e5ce07Smrg    && _G_HAVE_XSI_OPS=yes
86248e5ce07Smrg
86348e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
86448e5ce07Smrg  eval 'func_len ()
86548e5ce07Smrg  {
86648e5ce07Smrg    $debug_cmd
86748e5ce07Smrg
86848e5ce07Smrg    func_len_result=${#1}
86948e5ce07Smrg  }'
87048e5ce07Smrgelse
87148e5ce07Smrg  func_len ()
87248e5ce07Smrg  {
87348e5ce07Smrg    $debug_cmd
87448e5ce07Smrg
87548e5ce07Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
87648e5ce07Smrg  }
87748e5ce07Smrgfi
87848e5ce07Smrg
87948e5ce07Smrg
88048e5ce07Smrg# func_mkdir_p DIRECTORY-PATH
88148e5ce07Smrg# ---------------------------
882c27c18e8Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883c27c18e8Smrgfunc_mkdir_p ()
884c27c18e8Smrg{
88548e5ce07Smrg    $debug_cmd
88648e5ce07Smrg
88748e5ce07Smrg    _G_directory_path=$1
88848e5ce07Smrg    _G_dir_list=
889c27c18e8Smrg
89048e5ce07Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
89144584a44Smrg
89248e5ce07Smrg      # Protect directory names starting with '-'
89348e5ce07Smrg      case $_G_directory_path in
89448e5ce07Smrg        -*) _G_directory_path=./$_G_directory_path ;;
895c27c18e8Smrg      esac
896c27c18e8Smrg
897c27c18e8Smrg      # While some portion of DIR does not yet exist...
89848e5ce07Smrg      while test ! -d "$_G_directory_path"; do
899c27c18e8Smrg        # ...make a list in topmost first order.  Use a colon delimited
900c27c18e8Smrg	# list incase some portion of path contains whitespace.
90148e5ce07Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902c27c18e8Smrg
903c27c18e8Smrg        # If the last portion added has no slash in it, the list is done
90448e5ce07Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
905c27c18e8Smrg
906c27c18e8Smrg        # ...otherwise throw away the child directory and loop
90748e5ce07Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908c27c18e8Smrg      done
90948e5ce07Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910c27c18e8Smrg
91148e5ce07Smrg      func_mkdir_p_IFS=$IFS; IFS=:
91248e5ce07Smrg      for _G_dir in $_G_dir_list; do
91348e5ce07Smrg	IFS=$func_mkdir_p_IFS
91448e5ce07Smrg        # mkdir can fail with a 'File exist' error if two processes
915c27c18e8Smrg        # try to create one of the directories concurrently.  Don't
916c27c18e8Smrg        # stop in that case!
91748e5ce07Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
918c27c18e8Smrg      done
91948e5ce07Smrg      IFS=$func_mkdir_p_IFS
920c27c18e8Smrg
921c27c18e8Smrg      # Bail out if we (or some other process) failed to create a directory.
92248e5ce07Smrg      test -d "$_G_directory_path" || \
92348e5ce07Smrg        func_fatal_error "Failed to create '$1'"
924c27c18e8Smrg    fi
925c27c18e8Smrg}
926c43cc173Smrg
927c43cc173Smrg
92848e5ce07Smrg# func_mktempdir [BASENAME]
92948e5ce07Smrg# -------------------------
930c43cc173Smrg# Make a temporary directory that won't clash with other running
931c43cc173Smrg# libtool processes, and avoids race conditions if possible.  If
93248e5ce07Smrg# given, BASENAME is the basename for that directory.
933c43cc173Smrgfunc_mktempdir ()
934c43cc173Smrg{
93548e5ce07Smrg    $debug_cmd
93648e5ce07Smrg
93748e5ce07Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
93844584a44Smrg
93948e5ce07Smrg    if test : = "$opt_dry_run"; then
940c43cc173Smrg      # Return a directory name, but don't create it in dry-run mode
94148e5ce07Smrg      _G_tmpdir=$_G_template-$$
942c43cc173Smrg    else
943c43cc173Smrg
944c43cc173Smrg      # If mktemp works, use that first and foremost
94548e5ce07Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946c43cc173Smrg
94748e5ce07Smrg      if test ! -d "$_G_tmpdir"; then
948c27c18e8Smrg        # Failing that, at least try and use $RANDOM to avoid a race
94948e5ce07Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950c43cc173Smrg
95148e5ce07Smrg        func_mktempdir_umask=`umask`
952c27c18e8Smrg        umask 0077
95348e5ce07Smrg        $MKDIR "$_G_tmpdir"
95448e5ce07Smrg        umask $func_mktempdir_umask
955c43cc173Smrg      fi
956c43cc173Smrg
957c43cc173Smrg      # If we're not in dry-run mode, bomb out on failure
95848e5ce07Smrg      test -d "$_G_tmpdir" || \
95948e5ce07Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960c43cc173Smrg    fi
961c43cc173Smrg
96248e5ce07Smrg    $ECHO "$_G_tmpdir"
96344584a44Smrg}
96444584a44Smrg
96544584a44Smrg
96648e5ce07Smrg# func_normal_abspath PATH
96748e5ce07Smrg# ------------------------
96848e5ce07Smrg# Remove doubled-up and trailing slashes, "." path components,
96948e5ce07Smrg# and cancel out any ".." path components in PATH after making
97048e5ce07Smrg# it an absolute path.
97148e5ce07Smrgfunc_normal_abspath ()
97244584a44Smrg{
97348e5ce07Smrg    $debug_cmd
97444584a44Smrg
97548e5ce07Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
97648e5ce07Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
97748e5ce07Smrg    _G_pathcdr='s|^/[^/]*||'
97848e5ce07Smrg    _G_removedotparts=':dotsl
97948e5ce07Smrg		s|/\./|/|g
98048e5ce07Smrg		t dotsl
98148e5ce07Smrg		s|/\.$|/|'
98248e5ce07Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
98348e5ce07Smrg    _G_finalslash='s|/*$|/|'
98448e5ce07Smrg
98548e5ce07Smrg    # Start from root dir and reassemble the path.
98648e5ce07Smrg    func_normal_abspath_result=
98748e5ce07Smrg    func_normal_abspath_tpath=$1
98848e5ce07Smrg    func_normal_abspath_altnamespace=
98948e5ce07Smrg    case $func_normal_abspath_tpath in
99048e5ce07Smrg      "")
99148e5ce07Smrg        # Empty path, that just means $cwd.
99248e5ce07Smrg        func_stripname '' '/' "`pwd`"
99348e5ce07Smrg        func_normal_abspath_result=$func_stripname_result
99448e5ce07Smrg        return
99548e5ce07Smrg        ;;
99648e5ce07Smrg      # The next three entries are used to spot a run of precisely
99748e5ce07Smrg      # two leading slashes without using negated character classes;
99848e5ce07Smrg      # we take advantage of case's first-match behaviour.
99948e5ce07Smrg      ///*)
100048e5ce07Smrg        # Unusual form of absolute path, do nothing.
100148e5ce07Smrg        ;;
100248e5ce07Smrg      //*)
100348e5ce07Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
100448e5ce07Smrg        # and for example Cygwin uses it to access remote file shares
100548e5ce07Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
100648e5ce07Smrg        func_normal_abspath_altnamespace=/
100748e5ce07Smrg        ;;
100848e5ce07Smrg      /*)
100948e5ce07Smrg        # Absolute path, do nothing.
101044584a44Smrg        ;;
10110eb1301bSmrg      *)
101248e5ce07Smrg        # Relative path, prepend $cwd.
101348e5ce07Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
101448e5ce07Smrg        ;;
101544584a44Smrg    esac
101648e5ce07Smrg
101748e5ce07Smrg    # Cancel out all the simple stuff to save iterations.  We also want
101848e5ce07Smrg    # the path to end with a slash for ease of parsing, so make sure
101948e5ce07Smrg    # there is one (and only one) here.
102048e5ce07Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
102148e5ce07Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
102248e5ce07Smrg    while :; do
102348e5ce07Smrg      # Processed it all yet?
102448e5ce07Smrg      if test / = "$func_normal_abspath_tpath"; then
102548e5ce07Smrg        # If we ascended to the root using ".." the result may be empty now.
102648e5ce07Smrg        if test -z "$func_normal_abspath_result"; then
102748e5ce07Smrg          func_normal_abspath_result=/
102848e5ce07Smrg        fi
102948e5ce07Smrg        break
103048e5ce07Smrg      fi
103148e5ce07Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
103248e5ce07Smrg          -e "$_G_pathcar"`
103348e5ce07Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
103448e5ce07Smrg          -e "$_G_pathcdr"`
103548e5ce07Smrg      # Figure out what to do with it
103648e5ce07Smrg      case $func_normal_abspath_tcomponent in
103748e5ce07Smrg        "")
103848e5ce07Smrg          # Trailing empty path component, ignore it.
103948e5ce07Smrg          ;;
104048e5ce07Smrg        ..)
104148e5ce07Smrg          # Parent dir; strip last assembled component from result.
104248e5ce07Smrg          func_dirname "$func_normal_abspath_result"
104348e5ce07Smrg          func_normal_abspath_result=$func_dirname_result
104448e5ce07Smrg          ;;
104548e5ce07Smrg        *)
104648e5ce07Smrg          # Actual path component, append it.
104748e5ce07Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
104848e5ce07Smrg          ;;
104948e5ce07Smrg      esac
105048e5ce07Smrg    done
105148e5ce07Smrg    # Restore leading double-slash if one was found on entry.
105248e5ce07Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
105348e5ce07Smrg}
105448e5ce07Smrg
105548e5ce07Smrg
105648e5ce07Smrg# func_notquiet ARG...
105748e5ce07Smrg# --------------------
105848e5ce07Smrg# Echo program name prefixed message only when not in quiet mode.
105948e5ce07Smrgfunc_notquiet ()
106048e5ce07Smrg{
106148e5ce07Smrg    $debug_cmd
106248e5ce07Smrg
106348e5ce07Smrg    $opt_quiet || func_echo ${1+"$@"}
106448e5ce07Smrg
106548e5ce07Smrg    # A bug in bash halts the script if the last line of a function
106648e5ce07Smrg    # fails when set -e is in force, so we need another command to
106748e5ce07Smrg    # work around that:
106848e5ce07Smrg    :
106948e5ce07Smrg}
107048e5ce07Smrg
107148e5ce07Smrg
107248e5ce07Smrg# func_relative_path SRCDIR DSTDIR
107348e5ce07Smrg# --------------------------------
107448e5ce07Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
107548e5ce07Smrgfunc_relative_path ()
107648e5ce07Smrg{
107748e5ce07Smrg    $debug_cmd
107848e5ce07Smrg
107948e5ce07Smrg    func_relative_path_result=
108048e5ce07Smrg    func_normal_abspath "$1"
108148e5ce07Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
108248e5ce07Smrg    func_normal_abspath "$2"
108348e5ce07Smrg    func_relative_path_tbindir=$func_normal_abspath_result
108448e5ce07Smrg
108548e5ce07Smrg    # Ascend the tree starting from libdir
108648e5ce07Smrg    while :; do
108748e5ce07Smrg      # check if we have found a prefix of bindir
108848e5ce07Smrg      case $func_relative_path_tbindir in
108948e5ce07Smrg        $func_relative_path_tlibdir)
109048e5ce07Smrg          # found an exact match
109148e5ce07Smrg          func_relative_path_tcancelled=
109248e5ce07Smrg          break
109348e5ce07Smrg          ;;
109448e5ce07Smrg        $func_relative_path_tlibdir*)
109548e5ce07Smrg          # found a matching prefix
109648e5ce07Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
109748e5ce07Smrg          func_relative_path_tcancelled=$func_stripname_result
109848e5ce07Smrg          if test -z "$func_relative_path_result"; then
109948e5ce07Smrg            func_relative_path_result=.
110048e5ce07Smrg          fi
110148e5ce07Smrg          break
110248e5ce07Smrg          ;;
110348e5ce07Smrg        *)
110448e5ce07Smrg          func_dirname $func_relative_path_tlibdir
110548e5ce07Smrg          func_relative_path_tlibdir=$func_dirname_result
110648e5ce07Smrg          if test -z "$func_relative_path_tlibdir"; then
110748e5ce07Smrg            # Have to descend all the way to the root!
110848e5ce07Smrg            func_relative_path_result=../$func_relative_path_result
110948e5ce07Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
111048e5ce07Smrg            break
111148e5ce07Smrg          fi
111248e5ce07Smrg          func_relative_path_result=../$func_relative_path_result
111348e5ce07Smrg          ;;
111448e5ce07Smrg      esac
111548e5ce07Smrg    done
111648e5ce07Smrg
111748e5ce07Smrg    # Now calculate path; take care to avoid doubling-up slashes.
111848e5ce07Smrg    func_stripname '' '/' "$func_relative_path_result"
111948e5ce07Smrg    func_relative_path_result=$func_stripname_result
112048e5ce07Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
112148e5ce07Smrg    if test -n "$func_stripname_result"; then
112248e5ce07Smrg      func_append func_relative_path_result "/$func_stripname_result"
112348e5ce07Smrg    fi
112448e5ce07Smrg
112548e5ce07Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
112648e5ce07Smrg    if test -n "$func_relative_path_result"; then
112748e5ce07Smrg      func_stripname './' '' "$func_relative_path_result"
112848e5ce07Smrg      func_relative_path_result=$func_stripname_result
112948e5ce07Smrg    fi
113048e5ce07Smrg
113148e5ce07Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
113248e5ce07Smrg
113348e5ce07Smrg    :
113444584a44Smrg}
113544584a44Smrg
113644584a44Smrg
11374e8f48c7Smrg# func_quote_portable EVAL ARG
11384e8f48c7Smrg# ----------------------------
11394e8f48c7Smrg# Internal function to portably implement func_quote_arg.  Note that we still
11404e8f48c7Smrg# keep attention to performance here so we as much as possible try to avoid
11414e8f48c7Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11424e8f48c7Smrgfunc_quote_portable ()
114348e5ce07Smrg{
114448e5ce07Smrg    $debug_cmd
114548e5ce07Smrg
11464e8f48c7Smrg    $require_check_ifs_backslash
11474e8f48c7Smrg
11484e8f48c7Smrg    func_quote_portable_result=$2
11494e8f48c7Smrg
11504e8f48c7Smrg    # one-time-loop (easy break)
11514e8f48c7Smrg    while true
11524e8f48c7Smrg    do
11534e8f48c7Smrg      if $1; then
11544e8f48c7Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11554e8f48c7Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11564e8f48c7Smrg        break
115748e5ce07Smrg      fi
115848e5ce07Smrg
11594e8f48c7Smrg      # Quote for eval.
11604e8f48c7Smrg      case $func_quote_portable_result in
11614e8f48c7Smrg        *[\\\`\"\$]*)
11624e8f48c7Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11634e8f48c7Smrg          # contains the shell wildcard characters.
11644e8f48c7Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11654e8f48c7Smrg            :*|*[\[\*\?]*)
11664e8f48c7Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11674e8f48c7Smrg                  | $SED "$sed_quote_subst"`
11684e8f48c7Smrg              break
11694e8f48c7Smrg              ;;
11704e8f48c7Smrg          esac
11714e8f48c7Smrg
11724e8f48c7Smrg          func_quote_portable_old_IFS=$IFS
11734e8f48c7Smrg          for _G_char in '\' '`' '"' '$'
11744e8f48c7Smrg          do
11754e8f48c7Smrg            # STATE($1) PREV($2) SEPARATOR($3)
11764e8f48c7Smrg            set start "" ""
11774e8f48c7Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11784e8f48c7Smrg            IFS=$_G_char
11794e8f48c7Smrg            for _G_part in $func_quote_portable_result
11804e8f48c7Smrg            do
11814e8f48c7Smrg              case $1 in
11824e8f48c7Smrg              quote)
11834e8f48c7Smrg                func_append func_quote_portable_result "$3$2"
11844e8f48c7Smrg                set quote "$_G_part" "\\$_G_char"
11854e8f48c7Smrg                ;;
11864e8f48c7Smrg              start)
11874e8f48c7Smrg                set first "" ""
11884e8f48c7Smrg                func_quote_portable_result=
11894e8f48c7Smrg                ;;
11904e8f48c7Smrg              first)
11914e8f48c7Smrg                set quote "$_G_part" ""
11924e8f48c7Smrg                ;;
11934e8f48c7Smrg              esac
11944e8f48c7Smrg            done
11954e8f48c7Smrg          done
11964e8f48c7Smrg          IFS=$func_quote_portable_old_IFS
119748e5ce07Smrg          ;;
11984e8f48c7Smrg        *) ;;
119948e5ce07Smrg      esac
12004e8f48c7Smrg      break
120148e5ce07Smrg    done
12024e8f48c7Smrg
12034e8f48c7Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12044e8f48c7Smrg    case $func_quote_portable_result in
12054e8f48c7Smrg      # double-quote args containing shell metacharacters to delay
12064e8f48c7Smrg      # word splitting, command substitution and variable expansion
12074e8f48c7Smrg      # for a subsequent eval.
12084e8f48c7Smrg      # many bourne shells cannot handle close brackets correctly
12094e8f48c7Smrg      # in scan sets, so we specify it separately.
12104e8f48c7Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12114e8f48c7Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
12124e8f48c7Smrg        ;;
12134e8f48c7Smrg    esac
121448e5ce07Smrg}
121548e5ce07Smrg
121648e5ce07Smrg
12174e8f48c7Smrg# func_quotefast_eval ARG
12184e8f48c7Smrg# -----------------------
12194e8f48c7Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12204e8f48c7Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12214e8f48c7Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12224e8f48c7Smrg  printf -v _GL_test_printf_tilde %q '~'
12234e8f48c7Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
12244e8f48c7Smrg    func_quotefast_eval ()
12254e8f48c7Smrg    {
12264e8f48c7Smrg      printf -v func_quotefast_eval_result %q "$1"
12274e8f48c7Smrg    }
12284e8f48c7Smrg  else
12294e8f48c7Smrg    # Broken older Bash implementations.  Make those faster too if possible.
12304e8f48c7Smrg    func_quotefast_eval ()
12314e8f48c7Smrg    {
12324e8f48c7Smrg      case $1 in
12334e8f48c7Smrg        '~'*)
12344e8f48c7Smrg          func_quote_portable false "$1"
12354e8f48c7Smrg          func_quotefast_eval_result=$func_quote_portable_result
12364e8f48c7Smrg          ;;
12374e8f48c7Smrg        *)
12384e8f48c7Smrg          printf -v func_quotefast_eval_result %q "$1"
12394e8f48c7Smrg          ;;
12404e8f48c7Smrg      esac
12414e8f48c7Smrg    }
12424e8f48c7Smrg  fi
12434e8f48c7Smrgelse
12444e8f48c7Smrg  func_quotefast_eval ()
12454e8f48c7Smrg  {
12464e8f48c7Smrg    func_quote_portable false "$1"
12474e8f48c7Smrg    func_quotefast_eval_result=$func_quote_portable_result
12484e8f48c7Smrg  }
12494e8f48c7Smrgfi
125048e5ce07Smrg
12514e8f48c7Smrg
12524e8f48c7Smrg# func_quote_arg MODEs ARG
12534e8f48c7Smrg# ------------------------
12544e8f48c7Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12554e8f48c7Smrg# specifiers listed below separated by ',' character.  This function returns two
12564e8f48c7Smrg# values:
12574e8f48c7Smrg#   i) func_quote_arg_result
12584e8f48c7Smrg#      double-quoted (when needed), suitable for a subsequent eval
12594e8f48c7Smrg#  ii) func_quote_arg_unquoted_result
12604e8f48c7Smrg#      has all characters that are still active within double
12614e8f48c7Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12624e8f48c7Smrg#
12634e8f48c7Smrg# Available modes:
12644e8f48c7Smrg# ----------------
12654e8f48c7Smrg# 'eval' (default)
12664e8f48c7Smrg#       - escape shell special characters
12674e8f48c7Smrg# 'expand'
12684e8f48c7Smrg#       - the same as 'eval';  but do not quote variable references
12694e8f48c7Smrg# 'pretty'
12704e8f48c7Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12714e8f48c7Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12724e8f48c7Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
12734e8f48c7Smrg# 'unquoted'
12744e8f48c7Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12754e8f48c7Smrg#         wrapping double-quotes.
12764e8f48c7Smrg#
12774e8f48c7Smrg# Examples for 'func_quote_arg pretty,unquoted string':
12784e8f48c7Smrg#
12794e8f48c7Smrg#   string      | *_result              | *_unquoted_result
12804e8f48c7Smrg#   ------------+-----------------------+-------------------
12814e8f48c7Smrg#   "           | \"                    | \"
12824e8f48c7Smrg#   a b         | "a b"                 | a b
12834e8f48c7Smrg#   "a b"       | "\"a b\""             | \"a b\"
12844e8f48c7Smrg#   *           | "*"                   | *
12854e8f48c7Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12864e8f48c7Smrg#
12874e8f48c7Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12884e8f48c7Smrg#
12894e8f48c7Smrg#   string        |   *_result          |  *_unquoted_result
12904e8f48c7Smrg#   --------------+---------------------+--------------------
12914e8f48c7Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12924e8f48c7Smrgfunc_quote_arg ()
12934e8f48c7Smrg{
12944e8f48c7Smrg    _G_quote_expand=false
12954e8f48c7Smrg    case ,$1, in
12964e8f48c7Smrg      *,expand,*)
12974e8f48c7Smrg        _G_quote_expand=:
12984e8f48c7Smrg        ;;
129944584a44Smrg    esac
130044584a44Smrg
13014e8f48c7Smrg    case ,$1, in
13024e8f48c7Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
13034e8f48c7Smrg        func_quote_portable $_G_quote_expand "$2"
13044e8f48c7Smrg        func_quote_arg_result=$func_quote_portable_result
13054e8f48c7Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13064e8f48c7Smrg        ;;
13074e8f48c7Smrg      *)
13084e8f48c7Smrg        # Faster quote-for-eval for some shells.
13094e8f48c7Smrg        func_quotefast_eval "$2"
13104e8f48c7Smrg        func_quote_arg_result=$func_quotefast_eval_result
13110eb1301bSmrg        ;;
13120eb1301bSmrg    esac
13134e8f48c7Smrg}
131444584a44Smrg
13154e8f48c7Smrg
13164e8f48c7Smrg# func_quote MODEs ARGs...
13174e8f48c7Smrg# ------------------------
13184e8f48c7Smrg# Quote all ARGs to be evaled later and join them into single command.  See
13194e8f48c7Smrg# func_quote_arg's description for more info.
13204e8f48c7Smrgfunc_quote ()
13214e8f48c7Smrg{
13224e8f48c7Smrg    $debug_cmd
13234e8f48c7Smrg    _G_func_quote_mode=$1 ; shift
13244e8f48c7Smrg    func_quote_result=
13254e8f48c7Smrg    while test 0 -lt $#; do
13264e8f48c7Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
13274e8f48c7Smrg      if test -n "$func_quote_result"; then
13284e8f48c7Smrg        func_append func_quote_result " $func_quote_arg_result"
13294e8f48c7Smrg      else
13304e8f48c7Smrg        func_append func_quote_result "$func_quote_arg_result"
13314e8f48c7Smrg      fi
13324e8f48c7Smrg      shift
13334e8f48c7Smrg    done
133448e5ce07Smrg}
133548e5ce07Smrg
133648e5ce07Smrg
133748e5ce07Smrg# func_stripname PREFIX SUFFIX NAME
133848e5ce07Smrg# ---------------------------------
133948e5ce07Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
134048e5ce07Smrg# PREFIX and SUFFIX must not contain globbing or regex special
134148e5ce07Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
134248e5ce07Smrg# dot (in which case that matches only a dot).
134348e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
134448e5ce07Smrg  eval 'func_stripname ()
134548e5ce07Smrg  {
134648e5ce07Smrg    $debug_cmd
134748e5ce07Smrg
134848e5ce07Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
134948e5ce07Smrg    # positional parameters, so assign one to ordinary variable first.
135048e5ce07Smrg    func_stripname_result=$3
135148e5ce07Smrg    func_stripname_result=${func_stripname_result#"$1"}
135248e5ce07Smrg    func_stripname_result=${func_stripname_result%"$2"}
135348e5ce07Smrg  }'
135448e5ce07Smrgelse
135548e5ce07Smrg  func_stripname ()
135648e5ce07Smrg  {
135748e5ce07Smrg    $debug_cmd
135848e5ce07Smrg
135948e5ce07Smrg    case $2 in
136048e5ce07Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
136148e5ce07Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
136248e5ce07Smrg    esac
136348e5ce07Smrg  }
136448e5ce07Smrgfi
136548e5ce07Smrg
136648e5ce07Smrg
136748e5ce07Smrg# func_show_eval CMD [FAIL_EXP]
136848e5ce07Smrg# -----------------------------
136948e5ce07Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
137048e5ce07Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
137148e5ce07Smrg# is given, then evaluate it.
137248e5ce07Smrgfunc_show_eval ()
137348e5ce07Smrg{
137448e5ce07Smrg    $debug_cmd
137548e5ce07Smrg
137648e5ce07Smrg    _G_cmd=$1
137748e5ce07Smrg    _G_fail_exp=${2-':'}
137848e5ce07Smrg
13794e8f48c7Smrg    func_quote_arg pretty,expand "$_G_cmd"
13804e8f48c7Smrg    eval "func_notquiet $func_quote_arg_result"
138148e5ce07Smrg
138248e5ce07Smrg    $opt_dry_run || {
138348e5ce07Smrg      eval "$_G_cmd"
138448e5ce07Smrg      _G_status=$?
138548e5ce07Smrg      if test 0 -ne "$_G_status"; then
138648e5ce07Smrg	eval "(exit $_G_status); $_G_fail_exp"
138748e5ce07Smrg      fi
138848e5ce07Smrg    }
138948e5ce07Smrg}
139048e5ce07Smrg
139148e5ce07Smrg
139248e5ce07Smrg# func_show_eval_locale CMD [FAIL_EXP]
139348e5ce07Smrg# ------------------------------------
139448e5ce07Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
139548e5ce07Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
139648e5ce07Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
139748e5ce07Smrgfunc_show_eval_locale ()
139848e5ce07Smrg{
139948e5ce07Smrg    $debug_cmd
140048e5ce07Smrg
140148e5ce07Smrg    _G_cmd=$1
140248e5ce07Smrg    _G_fail_exp=${2-':'}
140348e5ce07Smrg
140448e5ce07Smrg    $opt_quiet || {
14054e8f48c7Smrg      func_quote_arg expand,pretty "$_G_cmd"
14064e8f48c7Smrg      eval "func_echo $func_quote_arg_result"
140748e5ce07Smrg    }
140848e5ce07Smrg
140948e5ce07Smrg    $opt_dry_run || {
141048e5ce07Smrg      eval "$_G_user_locale
141148e5ce07Smrg	    $_G_cmd"
141248e5ce07Smrg      _G_status=$?
141348e5ce07Smrg      eval "$_G_safe_locale"
141448e5ce07Smrg      if test 0 -ne "$_G_status"; then
141548e5ce07Smrg	eval "(exit $_G_status); $_G_fail_exp"
141648e5ce07Smrg      fi
141748e5ce07Smrg    }
141848e5ce07Smrg}
141948e5ce07Smrg
142048e5ce07Smrg
142148e5ce07Smrg# func_tr_sh
142248e5ce07Smrg# ----------
142348e5ce07Smrg# Turn $1 into a string suitable for a shell variable name.
142448e5ce07Smrg# Result is stored in $func_tr_sh_result.  All characters
142548e5ce07Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
142648e5ce07Smrg# if $1 begins with a digit, a '_' is prepended as well.
142748e5ce07Smrgfunc_tr_sh ()
142848e5ce07Smrg{
142948e5ce07Smrg    $debug_cmd
143048e5ce07Smrg
143148e5ce07Smrg    case $1 in
143248e5ce07Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
143348e5ce07Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
143448e5ce07Smrg      ;;
143548e5ce07Smrg    * )
143648e5ce07Smrg      func_tr_sh_result=$1
143748e5ce07Smrg      ;;
143848e5ce07Smrg    esac
143948e5ce07Smrg}
144048e5ce07Smrg
144148e5ce07Smrg
144248e5ce07Smrg# func_verbose ARG...
144348e5ce07Smrg# -------------------
144448e5ce07Smrg# Echo program name prefixed message in verbose mode only.
144548e5ce07Smrgfunc_verbose ()
144648e5ce07Smrg{
144748e5ce07Smrg    $debug_cmd
144848e5ce07Smrg
144948e5ce07Smrg    $opt_verbose && func_echo "$*"
145048e5ce07Smrg
145148e5ce07Smrg    :
145248e5ce07Smrg}
145348e5ce07Smrg
145448e5ce07Smrg
145548e5ce07Smrg# func_warn_and_continue ARG...
145648e5ce07Smrg# -----------------------------
145748e5ce07Smrg# Echo program name prefixed warning message to standard error.
145848e5ce07Smrgfunc_warn_and_continue ()
145948e5ce07Smrg{
146048e5ce07Smrg    $debug_cmd
146148e5ce07Smrg
146248e5ce07Smrg    $require_term_colors
146348e5ce07Smrg
146448e5ce07Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
146548e5ce07Smrg}
146648e5ce07Smrg
146748e5ce07Smrg
146848e5ce07Smrg# func_warning CATEGORY ARG...
146948e5ce07Smrg# ----------------------------
147048e5ce07Smrg# Echo program name prefixed warning message to standard error. Warning
147148e5ce07Smrg# messages can be filtered according to CATEGORY, where this function
147248e5ce07Smrg# elides messages where CATEGORY is not listed in the global variable
147348e5ce07Smrg# 'opt_warning_types'.
147448e5ce07Smrgfunc_warning ()
147548e5ce07Smrg{
147648e5ce07Smrg    $debug_cmd
147748e5ce07Smrg
147848e5ce07Smrg    # CATEGORY must be in the warning_categories list!
147948e5ce07Smrg    case " $warning_categories " in
148048e5ce07Smrg      *" $1 "*) ;;
148148e5ce07Smrg      *) func_internal_error "invalid warning category '$1'" ;;
148248e5ce07Smrg    esac
148348e5ce07Smrg
148448e5ce07Smrg    _G_category=$1
148548e5ce07Smrg    shift
148648e5ce07Smrg
148748e5ce07Smrg    case " $opt_warning_types " in
148848e5ce07Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
148948e5ce07Smrg    esac
1490c43cc173Smrg}
1491c43cc173Smrg
1492c43cc173Smrg
149348e5ce07Smrg# func_sort_ver VER1 VER2
149448e5ce07Smrg# -----------------------
149548e5ce07Smrg# 'sort -V' is not generally available.
149648e5ce07Smrg# Note this deviates from the version comparison in automake
149748e5ce07Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
149848e5ce07Smrg# but this should suffice as we won't be specifying old
149948e5ce07Smrg# version formats or redundant trailing .0 in bootstrap.conf.
150048e5ce07Smrg# If we did want full compatibility then we should probably
150148e5ce07Smrg# use m4_version_compare from autoconf.
150248e5ce07Smrgfunc_sort_ver ()
150348e5ce07Smrg{
150448e5ce07Smrg    $debug_cmd
150548e5ce07Smrg
150648e5ce07Smrg    printf '%s\n%s\n' "$1" "$2" \
150748e5ce07Smrg      | 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
150848e5ce07Smrg}
150948e5ce07Smrg
151048e5ce07Smrg# func_lt_ver PREV CURR
151148e5ce07Smrg# ---------------------
151248e5ce07Smrg# Return true if PREV and CURR are in the correct order according to
151348e5ce07Smrg# func_sort_ver, otherwise false.  Use it like this:
151448e5ce07Smrg#
151548e5ce07Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
151648e5ce07Smrgfunc_lt_ver ()
151748e5ce07Smrg{
151848e5ce07Smrg    $debug_cmd
151948e5ce07Smrg
152048e5ce07Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
152148e5ce07Smrg}
152248e5ce07Smrg
152348e5ce07Smrg
152448e5ce07Smrg# Local variables:
152548e5ce07Smrg# mode: shell-script
152648e5ce07Smrg# sh-indentation: 2
152748e5ce07Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
152848e5ce07Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
152948e5ce07Smrg# time-stamp-time-zone: "UTC"
153048e5ce07Smrg# End:
153148e5ce07Smrg#! /bin/sh
153248e5ce07Smrg
153348e5ce07Smrg# A portable, pluggable option parser for Bourne shell.
153448e5ce07Smrg# Written by Gary V. Vaughan, 2010
153548e5ce07Smrg
15364e8f48c7Smrg# This is free software.  There is NO warranty; not even for
15374e8f48c7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15384e8f48c7Smrg#
15394e8f48c7Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
15404e8f48c7Smrg#
15414e8f48c7Smrg# This file is dual licensed under the terms of the MIT license
15424e8f48c7Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
15434e8f48c7Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15444e8f48c7Smrg# these licenses when using or redistributing this software or any of
15454e8f48c7Smrg# the files within it.  See the URLs above, or the file `LICENSE`
15464e8f48c7Smrg# included in the Bootstrap distribution for the full license texts.
154748e5ce07Smrg
15484e8f48c7Smrg# Please report bugs or propose patches to:
15494e8f48c7Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
155048e5ce07Smrg
15514e8f48c7Smrg# Set a version string for this script.
15524e8f48c7Smrgscriptversion=2019-02-19.15; # UTC
155348e5ce07Smrg
155448e5ce07Smrg
155548e5ce07Smrg## ------ ##
155648e5ce07Smrg## Usage. ##
155748e5ce07Smrg## ------ ##
155848e5ce07Smrg
155948e5ce07Smrg# This file is a library for parsing options in your shell scripts along
156048e5ce07Smrg# with assorted other useful supporting features that you can make use
156148e5ce07Smrg# of too.
156248e5ce07Smrg#
156348e5ce07Smrg# For the simplest scripts you might need only:
156448e5ce07Smrg#
156548e5ce07Smrg#   #!/bin/sh
156648e5ce07Smrg#   . relative/path/to/funclib.sh
156748e5ce07Smrg#   . relative/path/to/options-parser
156848e5ce07Smrg#   scriptversion=1.0
156948e5ce07Smrg#   func_options ${1+"$@"}
157048e5ce07Smrg#   eval set dummy "$func_options_result"; shift
157148e5ce07Smrg#   ...rest of your script...
157248e5ce07Smrg#
157348e5ce07Smrg# In order for the '--version' option to work, you will need to have a
157448e5ce07Smrg# suitably formatted comment like the one at the top of this file
15754e8f48c7Smrg# starting with '# Written by ' and ending with '# Copyright'.
157648e5ce07Smrg#
157748e5ce07Smrg# For '-h' and '--help' to work, you will also need a one line
157848e5ce07Smrg# description of your script's purpose in a comment directly above the
157948e5ce07Smrg# '# Written by ' line, like the one at the top of this file.
158048e5ce07Smrg#
158148e5ce07Smrg# The default options also support '--debug', which will turn on shell
158248e5ce07Smrg# execution tracing (see the comment above debug_cmd below for another
158348e5ce07Smrg# use), and '--verbose' and the func_verbose function to allow your script
158448e5ce07Smrg# to display verbose messages only when your user has specified
158548e5ce07Smrg# '--verbose'.
158648e5ce07Smrg#
15874e8f48c7Smrg# After sourcing this file, you can plug in processing for additional
158848e5ce07Smrg# options by amending the variables from the 'Configuration' section
158948e5ce07Smrg# below, and following the instructions in the 'Option parsing'
159048e5ce07Smrg# section further down.
159148e5ce07Smrg
159248e5ce07Smrg## -------------- ##
159348e5ce07Smrg## Configuration. ##
159448e5ce07Smrg## -------------- ##
159548e5ce07Smrg
159648e5ce07Smrg# You should override these variables in your script after sourcing this
159748e5ce07Smrg# file so that they reflect the customisations you have added to the
159848e5ce07Smrg# option parser.
159948e5ce07Smrg
160048e5ce07Smrg# The usage line for option parsing errors and the start of '-h' and
160148e5ce07Smrg# '--help' output messages. You can embed shell variables for delayed
160248e5ce07Smrg# expansion at the time the message is displayed, but you will need to
160348e5ce07Smrg# quote other shell meta-characters carefully to prevent them being
160448e5ce07Smrg# expanded when the contents are evaled.
160548e5ce07Smrgusage='$progpath [OPTION]...'
160648e5ce07Smrg
160748e5ce07Smrg# Short help message in response to '-h' and '--help'.  Add to this or
160848e5ce07Smrg# override it after sourcing this library to reflect the full set of
160948e5ce07Smrg# options your script accepts.
161048e5ce07Smrgusage_message="\
161148e5ce07Smrg       --debug        enable verbose shell tracing
161248e5ce07Smrg   -W, --warnings=CATEGORY
161348e5ce07Smrg                      report the warnings falling in CATEGORY [all]
161448e5ce07Smrg   -v, --verbose      verbosely report processing
161548e5ce07Smrg       --version      print version information and exit
161648e5ce07Smrg   -h, --help         print short or long help message and exit
161748e5ce07Smrg"
161848e5ce07Smrg
161948e5ce07Smrg# Additional text appended to 'usage_message' in response to '--help'.
162048e5ce07Smrglong_help_message="
162148e5ce07SmrgWarning categories include:
162248e5ce07Smrg       'all'          show all warnings
162348e5ce07Smrg       'none'         turn off all the warnings
162448e5ce07Smrg       'error'        warnings are treated as fatal errors"
162548e5ce07Smrg
162648e5ce07Smrg# Help message printed before fatal option parsing errors.
162748e5ce07Smrgfatal_help="Try '\$progname --help' for more information."
162848e5ce07Smrg
162948e5ce07Smrg
163048e5ce07Smrg
163148e5ce07Smrg## ------------------------- ##
163248e5ce07Smrg## Hook function management. ##
163348e5ce07Smrg## ------------------------- ##
163448e5ce07Smrg
163548e5ce07Smrg# This section contains functions for adding, removing, and running hooks
16364e8f48c7Smrg# in the main code.  A hook is just a list of function names that can be
16374e8f48c7Smrg# run in order later on.
163848e5ce07Smrg
163948e5ce07Smrg# func_hookable FUNC_NAME
164048e5ce07Smrg# -----------------------
164148e5ce07Smrg# Declare that FUNC_NAME will run hooks added with
164248e5ce07Smrg# 'func_add_hook FUNC_NAME ...'.
164348e5ce07Smrgfunc_hookable ()
164448e5ce07Smrg{
164548e5ce07Smrg    $debug_cmd
164648e5ce07Smrg
164748e5ce07Smrg    func_append hookable_fns " $1"
164848e5ce07Smrg}
164948e5ce07Smrg
165048e5ce07Smrg
165148e5ce07Smrg# func_add_hook FUNC_NAME HOOK_FUNC
165248e5ce07Smrg# ---------------------------------
165348e5ce07Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
165448e5ce07Smrg# first have been declared "hookable" by a call to 'func_hookable'.
165548e5ce07Smrgfunc_add_hook ()
165648e5ce07Smrg{
165748e5ce07Smrg    $debug_cmd
165848e5ce07Smrg
165948e5ce07Smrg    case " $hookable_fns " in
166048e5ce07Smrg      *" $1 "*) ;;
166148e5ce07Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
166248e5ce07Smrg    esac
166348e5ce07Smrg
166448e5ce07Smrg    eval func_append ${1}_hooks '" $2"'
166548e5ce07Smrg}
166648e5ce07Smrg
166748e5ce07Smrg
166848e5ce07Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
166948e5ce07Smrg# ------------------------------------
16704e8f48c7Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
16714e8f48c7Smrg# FUNC_NAME.
167248e5ce07Smrgfunc_remove_hook ()
167348e5ce07Smrg{
167448e5ce07Smrg    $debug_cmd
167548e5ce07Smrg
167648e5ce07Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
167748e5ce07Smrg}
167848e5ce07Smrg
167948e5ce07Smrg
16804e8f48c7Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16814e8f48c7Smrg# ---------------------------------------------
16824e8f48c7Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16834e8f48c7Smrg# *_result variable of FUNC_NAME_B.
16844e8f48c7Smrgfunc_propagate_result ()
16854e8f48c7Smrg{
16864e8f48c7Smrg    $debug_cmd
16874e8f48c7Smrg
16884e8f48c7Smrg    func_propagate_result_result=:
16894e8f48c7Smrg    if eval "test \"\${${1}_result+set}\" = set"
16904e8f48c7Smrg    then
16914e8f48c7Smrg      eval "${2}_result=\$${1}_result"
16924e8f48c7Smrg    else
16934e8f48c7Smrg      func_propagate_result_result=false
16944e8f48c7Smrg    fi
16954e8f48c7Smrg}
16964e8f48c7Smrg
16974e8f48c7Smrg
169848e5ce07Smrg# func_run_hooks FUNC_NAME [ARG]...
169948e5ce07Smrg# ---------------------------------
170048e5ce07Smrg# Run all hook functions registered to FUNC_NAME.
17014e8f48c7Smrg# It's assumed that the list of hook functions contains nothing more
170248e5ce07Smrg# than a whitespace-delimited list of legal shell function names, and
170348e5ce07Smrg# no effort is wasted trying to catch shell meta-characters or preserve
170448e5ce07Smrg# whitespace.
170548e5ce07Smrgfunc_run_hooks ()
170648e5ce07Smrg{
170748e5ce07Smrg    $debug_cmd
170848e5ce07Smrg
170948e5ce07Smrg    case " $hookable_fns " in
171048e5ce07Smrg      *" $1 "*) ;;
17114e8f48c7Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
171248e5ce07Smrg    esac
171348e5ce07Smrg
171448e5ce07Smrg    eval _G_hook_fns=\$$1_hooks; shift
171548e5ce07Smrg
171648e5ce07Smrg    for _G_hook in $_G_hook_fns; do
17174e8f48c7Smrg      func_unset "${_G_hook}_result"
17184e8f48c7Smrg      eval $_G_hook '${1+"$@"}'
17194e8f48c7Smrg      func_propagate_result $_G_hook func_run_hooks
17204e8f48c7Smrg      if $func_propagate_result_result; then
17214e8f48c7Smrg        eval set dummy "$func_run_hooks_result"; shift
172287404ef7Smrg      fi
172348e5ce07Smrg    done
172448e5ce07Smrg}
172548e5ce07Smrg
172648e5ce07Smrg
172748e5ce07Smrg
172848e5ce07Smrg## --------------- ##
172948e5ce07Smrg## Option parsing. ##
173048e5ce07Smrg## --------------- ##
173148e5ce07Smrg
173248e5ce07Smrg# In order to add your own option parsing hooks, you must accept the
17334e8f48c7Smrg# full positional parameter list from your hook function.  You may remove
17344e8f48c7Smrg# or edit any options that you action, and then pass back the remaining
17354e8f48c7Smrg# unprocessed options in '<hooked_function_name>_result', escaped
17364e8f48c7Smrg# suitably for 'eval'.
17374e8f48c7Smrg#
17384e8f48c7Smrg# The '<hooked_function_name>_result' variable is automatically unset
17394e8f48c7Smrg# before your hook gets called; for best performance, only set the
17404e8f48c7Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17414e8f48c7Smrg# function unnecessarily because it can be an expensive operation on some
17424e8f48c7Smrg# machines).
174387404ef7Smrg#
174487404ef7Smrg# Like this:
174548e5ce07Smrg#
174648e5ce07Smrg#    my_options_prep ()
174748e5ce07Smrg#    {
174848e5ce07Smrg#        $debug_cmd
174948e5ce07Smrg#
175048e5ce07Smrg#        # Extend the existing usage message.
175148e5ce07Smrg#        usage_message=$usage_message'
175248e5ce07Smrg#      -s, --silent       don'\''t print informational messages
175348e5ce07Smrg#    '
17544e8f48c7Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
17554e8f48c7Smrg#        # my_options_prep_result variable intact.
175648e5ce07Smrg#    }
175748e5ce07Smrg#    func_add_hook func_options_prep my_options_prep
175848e5ce07Smrg#
175948e5ce07Smrg#
176048e5ce07Smrg#    my_silent_option ()
176148e5ce07Smrg#    {
176248e5ce07Smrg#        $debug_cmd
176348e5ce07Smrg#
176487404ef7Smrg#        args_changed=false
176587404ef7Smrg#
17664e8f48c7Smrg#        # Note that, for efficiency, we parse as many options as we can
176748e5ce07Smrg#        # recognise in a loop before passing the remainder back to the
176848e5ce07Smrg#        # caller on the first unrecognised argument we encounter.
176948e5ce07Smrg#        while test $# -gt 0; do
177048e5ce07Smrg#          opt=$1; shift
177148e5ce07Smrg#          case $opt in
177287404ef7Smrg#            --silent|-s) opt_silent=:
177387404ef7Smrg#                         args_changed=:
177487404ef7Smrg#                         ;;
177548e5ce07Smrg#            # Separate non-argument short options:
177648e5ce07Smrg#            -s*)         func_split_short_opt "$_G_opt"
177748e5ce07Smrg#                         set dummy "$func_split_short_opt_name" \
177848e5ce07Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
177948e5ce07Smrg#                         shift
178087404ef7Smrg#                         args_changed=:
178148e5ce07Smrg#                         ;;
178287404ef7Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17834e8f48c7Smrg#                         # is added back to "$@" in case we need it later,
17844e8f48c7Smrg#                         # if $args_changed was set to 'true'.
178587404ef7Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
178648e5ce07Smrg#          esac
178748e5ce07Smrg#        done
178848e5ce07Smrg#
17894e8f48c7Smrg#        # Only call 'func_quote' here if we processed at least one argument.
179087404ef7Smrg#        if $args_changed; then
17914e8f48c7Smrg#          func_quote eval ${1+"$@"}
17924e8f48c7Smrg#          my_silent_option_result=$func_quote_result
179387404ef7Smrg#        fi
179448e5ce07Smrg#    }
179548e5ce07Smrg#    func_add_hook func_parse_options my_silent_option
179648e5ce07Smrg#
179748e5ce07Smrg#
179848e5ce07Smrg#    my_option_validation ()
179948e5ce07Smrg#    {
180048e5ce07Smrg#        $debug_cmd
180148e5ce07Smrg#
180248e5ce07Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
180348e5ce07Smrg#    '--silent' and '--verbose' options are mutually exclusive."
180448e5ce07Smrg#    }
180548e5ce07Smrg#    func_add_hook func_validate_options my_option_validation
180648e5ce07Smrg#
180787404ef7Smrg# You'll also need to manually amend $usage_message to reflect the extra
180848e5ce07Smrg# options you parse.  It's preferable to append if you can, so that
180948e5ce07Smrg# multiple option parsing hooks can be added safely.
181048e5ce07Smrg
181148e5ce07Smrg
181287404ef7Smrg# func_options_finish [ARG]...
181387404ef7Smrg# ----------------------------
181487404ef7Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
181587404ef7Smrgfunc_options_finish ()
181687404ef7Smrg{
181787404ef7Smrg    $debug_cmd
181887404ef7Smrg
18194e8f48c7Smrg    func_run_hooks func_options ${1+"$@"}
18204e8f48c7Smrg    func_propagate_result func_run_hooks func_options_finish
182187404ef7Smrg}
182287404ef7Smrg
182387404ef7Smrg
182448e5ce07Smrg# func_options [ARG]...
182548e5ce07Smrg# ---------------------
182648e5ce07Smrg# All the functions called inside func_options are hookable. See the
182748e5ce07Smrg# individual implementations for details.
182848e5ce07Smrgfunc_hookable func_options
182948e5ce07Smrgfunc_options ()
1830c43cc173Smrg{
183148e5ce07Smrg    $debug_cmd
183244584a44Smrg
18334e8f48c7Smrg    _G_options_quoted=false
183487404ef7Smrg
183587404ef7Smrg    for my_func in options_prep parse_options validate_options options_finish
183687404ef7Smrg    do
18374e8f48c7Smrg      func_unset func_${my_func}_result
18384e8f48c7Smrg      func_unset func_run_hooks_result
18394e8f48c7Smrg      eval func_$my_func '${1+"$@"}'
18404e8f48c7Smrg      func_propagate_result func_$my_func func_options
18414e8f48c7Smrg      if $func_propagate_result_result; then
18424e8f48c7Smrg        eval set dummy "$func_options_result"; shift
18434e8f48c7Smrg        _G_options_quoted=:
184487404ef7Smrg      fi
184587404ef7Smrg    done
184644584a44Smrg
18474e8f48c7Smrg    $_G_options_quoted || {
18484e8f48c7Smrg      # As we (func_options) are top-level options-parser function and
18494e8f48c7Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18504e8f48c7Smrg      # caller.
18514e8f48c7Smrg      func_quote eval ${1+"$@"}
18524e8f48c7Smrg      func_options_result=$func_quote_result
18534e8f48c7Smrg    }
1854c43cc173Smrg}
1855c43cc173Smrg
1856c43cc173Smrg
185748e5ce07Smrg# func_options_prep [ARG]...
185848e5ce07Smrg# --------------------------
185948e5ce07Smrg# All initialisations required before starting the option parse loop.
186048e5ce07Smrg# Note that when calling hook functions, we pass through the list of
186148e5ce07Smrg# positional parameters.  If a hook function modifies that list, and
186287404ef7Smrg# needs to propagate that back to rest of this script, then the complete
18634e8f48c7Smrg# modified list must be put in 'func_run_hooks_result' before returning.
186448e5ce07Smrgfunc_hookable func_options_prep
186548e5ce07Smrgfunc_options_prep ()
1866c43cc173Smrg{
186748e5ce07Smrg    $debug_cmd
1868c27c18e8Smrg
186948e5ce07Smrg    # Option defaults:
187048e5ce07Smrg    opt_verbose=false
187148e5ce07Smrg    opt_warning_types=
187244584a44Smrg
18734e8f48c7Smrg    func_run_hooks func_options_prep ${1+"$@"}
18744e8f48c7Smrg    func_propagate_result func_run_hooks func_options_prep
1875c43cc173Smrg}
1876c43cc173Smrg
187748e5ce07Smrg
187848e5ce07Smrg# func_parse_options [ARG]...
187948e5ce07Smrg# ---------------------------
188048e5ce07Smrg# The main option parsing loop.
188148e5ce07Smrgfunc_hookable func_parse_options
188248e5ce07Smrgfunc_parse_options ()
1883c43cc173Smrg{
188448e5ce07Smrg    $debug_cmd
188548e5ce07Smrg
18864e8f48c7Smrg    _G_parse_options_requote=false
188748e5ce07Smrg    # this just eases exit handling
188848e5ce07Smrg    while test $# -gt 0; do
188948e5ce07Smrg      # Defer to hook functions for initial option parsing, so they
189048e5ce07Smrg      # get priority in the event of reusing an option name.
18914e8f48c7Smrg      func_run_hooks func_parse_options ${1+"$@"}
18924e8f48c7Smrg      func_propagate_result func_run_hooks func_parse_options
18934e8f48c7Smrg      if $func_propagate_result_result; then
18944e8f48c7Smrg        eval set dummy "$func_parse_options_result"; shift
18954e8f48c7Smrg        # Even though we may have changed "$@", we passed the "$@" array
18964e8f48c7Smrg        # down into the hook and it quoted it for us (because we are in
18974e8f48c7Smrg        # this if-branch).  No need to quote it again.
18984e8f48c7Smrg        _G_parse_options_requote=false
189987404ef7Smrg      fi
190048e5ce07Smrg
190148e5ce07Smrg      # Break out of the loop if we already parsed every option.
190248e5ce07Smrg      test $# -gt 0 || break
190348e5ce07Smrg
19044e8f48c7Smrg      # We expect that one of the options parsed in this function matches
19054e8f48c7Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
190687404ef7Smrg      _G_match_parse_options=:
190748e5ce07Smrg      _G_opt=$1
190848e5ce07Smrg      shift
190948e5ce07Smrg      case $_G_opt in
191048e5ce07Smrg        --debug|-x)   debug_cmd='set -x'
19114e8f48c7Smrg                      func_echo "enabling shell trace mode" >&2
191248e5ce07Smrg                      $debug_cmd
191348e5ce07Smrg                      ;;
191448e5ce07Smrg
191548e5ce07Smrg        --no-warnings|--no-warning|--no-warn)
191648e5ce07Smrg                      set dummy --warnings none ${1+"$@"}
191748e5ce07Smrg                      shift
191848e5ce07Smrg		      ;;
191948e5ce07Smrg
192048e5ce07Smrg        --warnings|--warning|-W)
192187404ef7Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19224e8f48c7Smrg                        _G_parse_options_requote=:
192387404ef7Smrg                        break
192487404ef7Smrg                      fi
192548e5ce07Smrg                      case " $warning_categories $1" in
192648e5ce07Smrg                        *" $1 "*)
192748e5ce07Smrg                          # trailing space prevents matching last $1 above
192848e5ce07Smrg                          func_append_uniq opt_warning_types " $1"
192948e5ce07Smrg                          ;;
193048e5ce07Smrg                        *all)
193148e5ce07Smrg                          opt_warning_types=$warning_categories
193248e5ce07Smrg                          ;;
193348e5ce07Smrg                        *none)
193448e5ce07Smrg                          opt_warning_types=none
193548e5ce07Smrg                          warning_func=:
193648e5ce07Smrg                          ;;
193748e5ce07Smrg                        *error)
193848e5ce07Smrg                          opt_warning_types=$warning_categories
193948e5ce07Smrg                          warning_func=func_fatal_error
194048e5ce07Smrg                          ;;
194148e5ce07Smrg                        *)
194248e5ce07Smrg                          func_fatal_error \
194348e5ce07Smrg                             "unsupported warning category: '$1'"
194448e5ce07Smrg                          ;;
194548e5ce07Smrg                      esac
194648e5ce07Smrg                      shift
194748e5ce07Smrg                      ;;
194848e5ce07Smrg
194948e5ce07Smrg        --verbose|-v) opt_verbose=: ;;
195048e5ce07Smrg        --version)    func_version ;;
195148e5ce07Smrg        -\?|-h)       func_usage ;;
195248e5ce07Smrg        --help)       func_help ;;
195348e5ce07Smrg
195448e5ce07Smrg	# Separate optargs to long options (plugins may need this):
195548e5ce07Smrg	--*=*)        func_split_equals "$_G_opt"
195648e5ce07Smrg	              set dummy "$func_split_equals_lhs" \
195748e5ce07Smrg                          "$func_split_equals_rhs" ${1+"$@"}
195848e5ce07Smrg                      shift
195948e5ce07Smrg                      ;;
196048e5ce07Smrg
196148e5ce07Smrg       # Separate optargs to short options:
196248e5ce07Smrg        -W*)
196348e5ce07Smrg                      func_split_short_opt "$_G_opt"
196448e5ce07Smrg                      set dummy "$func_split_short_opt_name" \
196548e5ce07Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
196648e5ce07Smrg                      shift
196748e5ce07Smrg                      ;;
196848e5ce07Smrg
196948e5ce07Smrg        # Separate non-argument short options:
197048e5ce07Smrg        -\?*|-h*|-v*|-x*)
197148e5ce07Smrg                      func_split_short_opt "$_G_opt"
197248e5ce07Smrg                      set dummy "$func_split_short_opt_name" \
197348e5ce07Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
197448e5ce07Smrg                      shift
197548e5ce07Smrg                      ;;
197648e5ce07Smrg
19774e8f48c7Smrg        --)           _G_parse_options_requote=: ; break ;;
197848e5ce07Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
197987404ef7Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
198087404ef7Smrg                      _G_match_parse_options=false
198187404ef7Smrg                      break
198287404ef7Smrg                      ;;
198348e5ce07Smrg      esac
198487404ef7Smrg
19854e8f48c7Smrg      if $_G_match_parse_options; then
19864e8f48c7Smrg        _G_parse_options_requote=:
19874e8f48c7Smrg      fi
198848e5ce07Smrg    done
198948e5ce07Smrg
19904e8f48c7Smrg    if $_G_parse_options_requote; then
199187404ef7Smrg      # save modified positional parameters for caller
19924e8f48c7Smrg      func_quote eval ${1+"$@"}
19934e8f48c7Smrg      func_parse_options_result=$func_quote_result
199487404ef7Smrg    fi
1995b789ec8aSmrg}
1996b789ec8aSmrg
1997c43cc173Smrg
199848e5ce07Smrg# func_validate_options [ARG]...
199948e5ce07Smrg# ------------------------------
200048e5ce07Smrg# Perform any sanity checks on option settings and/or unconsumed
200148e5ce07Smrg# arguments.
200248e5ce07Smrgfunc_hookable func_validate_options
200348e5ce07Smrgfunc_validate_options ()
20040eb1301bSmrg{
200548e5ce07Smrg    $debug_cmd
2006b789ec8aSmrg
200748e5ce07Smrg    # Display all warnings if -W was not given.
200848e5ce07Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
200948e5ce07Smrg
20104e8f48c7Smrg    func_run_hooks func_validate_options ${1+"$@"}
20114e8f48c7Smrg    func_propagate_result func_run_hooks func_validate_options
201248e5ce07Smrg
201348e5ce07Smrg    # Bail if the options were screwed!
201448e5ce07Smrg    $exit_cmd $EXIT_FAILURE
20150eb1301bSmrg}
201644584a44Smrg
201748e5ce07Smrg
201848e5ce07Smrg
201948e5ce07Smrg## ----------------- ##
202048e5ce07Smrg## Helper functions. ##
202148e5ce07Smrg## ----------------- ##
202248e5ce07Smrg
202348e5ce07Smrg# This section contains the helper functions used by the rest of the
202448e5ce07Smrg# hookable option parser framework in ascii-betical order.
202548e5ce07Smrg
202648e5ce07Smrg
202748e5ce07Smrg# func_fatal_help ARG...
202848e5ce07Smrg# ----------------------
202948e5ce07Smrg# Echo program name prefixed message to standard error, followed by
203048e5ce07Smrg# a help hint, and exit.
203148e5ce07Smrgfunc_fatal_help ()
2032c27c18e8Smrg{
203348e5ce07Smrg    $debug_cmd
2034b789ec8aSmrg
203548e5ce07Smrg    eval \$ECHO \""Usage: $usage"\"
203648e5ce07Smrg    eval \$ECHO \""$fatal_help"\"
203748e5ce07Smrg    func_error ${1+"$@"}
203848e5ce07Smrg    exit $EXIT_FAILURE
2039c27c18e8Smrg}
2040c27c18e8Smrg
204148e5ce07Smrg
204248e5ce07Smrg# func_help
204348e5ce07Smrg# ---------
204448e5ce07Smrg# Echo long help message to standard output and exit.
2045c27c18e8Smrgfunc_help ()
2046c27c18e8Smrg{
204748e5ce07Smrg    $debug_cmd
204848e5ce07Smrg
204948e5ce07Smrg    func_usage_message
205048e5ce07Smrg    $ECHO "$long_help_message"
205148e5ce07Smrg    exit 0
2052c27c18e8Smrg}
2053c27c18e8Smrg
205448e5ce07Smrg
205548e5ce07Smrg# func_missing_arg ARGNAME
205648e5ce07Smrg# ------------------------
2057c27c18e8Smrg# Echo program name prefixed message to standard error and set global
2058c27c18e8Smrg# exit_cmd.
2059c27c18e8Smrgfunc_missing_arg ()
2060c27c18e8Smrg{
206148e5ce07Smrg    $debug_cmd
2062b789ec8aSmrg
206348e5ce07Smrg    func_error "Missing argument for '$1'."
2064c27c18e8Smrg    exit_cmd=exit
2065c43cc173Smrg}
2066c43cc173Smrg
2067c43cc173Smrg
206848e5ce07Smrg# func_split_equals STRING
206948e5ce07Smrg# ------------------------
20704e8f48c7Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20714e8f48c7Smrg# after splitting STRING at the '=' sign.
207248e5ce07Smrgtest -z "$_G_HAVE_XSI_OPS" \
207348e5ce07Smrg    && (eval 'x=a/b/c;
207448e5ce07Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
207548e5ce07Smrg    && _G_HAVE_XSI_OPS=yes
207648e5ce07Smrg
207748e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"
207848e5ce07Smrgthen
207948e5ce07Smrg  # This is an XSI compatible shell, allowing a faster implementation...
208048e5ce07Smrg  eval 'func_split_equals ()
208148e5ce07Smrg  {
208248e5ce07Smrg      $debug_cmd
208348e5ce07Smrg
208448e5ce07Smrg      func_split_equals_lhs=${1%%=*}
208548e5ce07Smrg      func_split_equals_rhs=${1#*=}
20864e8f48c7Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
20874e8f48c7Smrg        func_split_equals_rhs=
20884e8f48c7Smrg      fi
208948e5ce07Smrg  }'
209048e5ce07Smrgelse
209148e5ce07Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
209248e5ce07Smrg  func_split_equals ()
209348e5ce07Smrg  {
209448e5ce07Smrg      $debug_cmd
209548e5ce07Smrg
209648e5ce07Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
209748e5ce07Smrg      func_split_equals_rhs=
20984e8f48c7Smrg      test "x$func_split_equals_lhs=" = "x$1" \
209948e5ce07Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
210048e5ce07Smrg  }
210148e5ce07Smrgfi #func_split_equals
210248e5ce07Smrg
210348e5ce07Smrg
210448e5ce07Smrg# func_split_short_opt SHORTOPT
210548e5ce07Smrg# -----------------------------
2106b789ec8aSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107b789ec8aSmrg# variables after splitting SHORTOPT after the 2nd character.
210848e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"
210948e5ce07Smrgthen
211048e5ce07Smrg  # This is an XSI compatible shell, allowing a faster implementation...
211148e5ce07Smrg  eval 'func_split_short_opt ()
211248e5ce07Smrg  {
211348e5ce07Smrg      $debug_cmd
211448e5ce07Smrg
211548e5ce07Smrg      func_split_short_opt_arg=${1#??}
211648e5ce07Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
211748e5ce07Smrg  }'
211848e5ce07Smrgelse
211948e5ce07Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
212048e5ce07Smrg  func_split_short_opt ()
212148e5ce07Smrg  {
212248e5ce07Smrg      $debug_cmd
212348e5ce07Smrg
21244e8f48c7Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
212548e5ce07Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
212648e5ce07Smrg  }
212748e5ce07Smrgfi #func_split_short_opt
212848e5ce07Smrg
212948e5ce07Smrg
213048e5ce07Smrg# func_usage
213148e5ce07Smrg# ----------
213248e5ce07Smrg# Echo short help message to standard output and exit.
213348e5ce07Smrgfunc_usage ()
2134b789ec8aSmrg{
213548e5ce07Smrg    $debug_cmd
2136b789ec8aSmrg
213748e5ce07Smrg    func_usage_message
213848e5ce07Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
213948e5ce07Smrg    exit 0
214048e5ce07Smrg}
2141b789ec8aSmrg
2142b789ec8aSmrg
214348e5ce07Smrg# func_usage_message
214448e5ce07Smrg# ------------------
214548e5ce07Smrg# Echo short help message to standard output.
214648e5ce07Smrgfunc_usage_message ()
2147b789ec8aSmrg{
214848e5ce07Smrg    $debug_cmd
2149b789ec8aSmrg
215048e5ce07Smrg    eval \$ECHO \""Usage: $usage"\"
215148e5ce07Smrg    echo
215248e5ce07Smrg    $SED -n 's|^# ||
215348e5ce07Smrg        /^Written by/{
215448e5ce07Smrg          x;p;x
215548e5ce07Smrg        }
215648e5ce07Smrg	h
215748e5ce07Smrg	/^Written by/q' < "$progpath"
215848e5ce07Smrg    echo
215948e5ce07Smrg    eval \$ECHO \""$usage_message"\"
216048e5ce07Smrg}
2161b789ec8aSmrg
2162c43cc173Smrg
216348e5ce07Smrg# func_version
216448e5ce07Smrg# ------------
216548e5ce07Smrg# Echo version message to standard output and exit.
21664e8f48c7Smrg# The version message is extracted from the calling file's header
21674e8f48c7Smrg# comments, with leading '# ' stripped:
21684e8f48c7Smrg#   1. First display the progname and version
21694e8f48c7Smrg#   2. Followed by the header comment line matching  /^# Written by /
21704e8f48c7Smrg#   3. Then a blank line followed by the first following line matching
21714e8f48c7Smrg#      /^# Copyright /
21724e8f48c7Smrg#   4. Immediately followed by any lines between the previous matches,
21734e8f48c7Smrg#      except lines preceding the intervening completely blank line.
21744e8f48c7Smrg# For example, see the header comments of this file.
217548e5ce07Smrgfunc_version ()
217648e5ce07Smrg{
217748e5ce07Smrg    $debug_cmd
2178c27c18e8Smrg
217948e5ce07Smrg    printf '%s\n' "$progname $scriptversion"
218048e5ce07Smrg    $SED -n '
21814e8f48c7Smrg        /^# Written by /!b
21824e8f48c7Smrg        s|^# ||; p; n
21834e8f48c7Smrg
21844e8f48c7Smrg        :fwd2blnk
21854e8f48c7Smrg        /./ {
21864e8f48c7Smrg          n
21874e8f48c7Smrg          b fwd2blnk
218848e5ce07Smrg        }
21894e8f48c7Smrg        p; n
21904e8f48c7Smrg
21914e8f48c7Smrg        :holdwrnt
21924e8f48c7Smrg        s|^# ||
21934e8f48c7Smrg        s|^# *$||
21944e8f48c7Smrg        /^Copyright /!{
21954e8f48c7Smrg          /./H
21964e8f48c7Smrg          n
21974e8f48c7Smrg          b holdwrnt
219848e5ce07Smrg        }
21994e8f48c7Smrg
22004e8f48c7Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22014e8f48c7Smrg        G
22024e8f48c7Smrg        s|\(\n\)\n*|\1|g
22034e8f48c7Smrg        p; q' < "$progpath"
2204c27c18e8Smrg
220548e5ce07Smrg    exit $?
220648e5ce07Smrg}
2207c27c18e8Smrg
2208c43cc173Smrg
220948e5ce07Smrg# Local variables:
221048e5ce07Smrg# mode: shell-script
221148e5ce07Smrg# sh-indentation: 2
221248e5ce07Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
22134e8f48c7Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
221448e5ce07Smrg# time-stamp-time-zone: "UTC"
221548e5ce07Smrg# End:
2216c43cc173Smrg
221748e5ce07Smrg# Set a version string.
22184e8f48c7Smrgscriptversion='(GNU libtool) 2.4.7'
2219c43cc173Smrg
2220c27c18e8Smrg
222148e5ce07Smrg# func_echo ARG...
222248e5ce07Smrg# ----------------
222348e5ce07Smrg# Libtool also displays the current mode in messages, so override
222448e5ce07Smrg# funclib.sh func_echo with this custom definition.
222548e5ce07Smrgfunc_echo ()
2226b789ec8aSmrg{
222748e5ce07Smrg    $debug_cmd
2228b789ec8aSmrg
222948e5ce07Smrg    _G_message=$*
223048e5ce07Smrg
223148e5ce07Smrg    func_echo_IFS=$IFS
223248e5ce07Smrg    IFS=$nl
223348e5ce07Smrg    for _G_line in $_G_message; do
223448e5ce07Smrg      IFS=$func_echo_IFS
223548e5ce07Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
223648e5ce07Smrg    done
223748e5ce07Smrg    IFS=$func_echo_IFS
223848e5ce07Smrg}
2239b789ec8aSmrg
2240b789ec8aSmrg
224148e5ce07Smrg# func_warning ARG...
224248e5ce07Smrg# -------------------
224348e5ce07Smrg# Libtool warnings are not categorized, so override funclib.sh
224448e5ce07Smrg# func_warning with this simpler definition.
224548e5ce07Smrgfunc_warning ()
2246b789ec8aSmrg{
224748e5ce07Smrg    $debug_cmd
224848e5ce07Smrg
224948e5ce07Smrg    $warning_func ${1+"$@"}
225048e5ce07Smrg}
225148e5ce07Smrg
2252b789ec8aSmrg
225348e5ce07Smrg## ---------------- ##
225448e5ce07Smrg## Options parsing. ##
225548e5ce07Smrg## ---------------- ##
225648e5ce07Smrg
225748e5ce07Smrg# Hook in the functions to make sure our own options are parsed during
225848e5ce07Smrg# the option parsing loop.
225948e5ce07Smrg
226048e5ce07Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
226148e5ce07Smrg
226248e5ce07Smrg# Short help message in response to '-h'.
226348e5ce07Smrgusage_message="Options:
226448e5ce07Smrg       --config             show all configuration variables
226548e5ce07Smrg       --debug              enable verbose shell tracing
226648e5ce07Smrg   -n, --dry-run            display commands without modifying any files
226748e5ce07Smrg       --features           display basic configuration information and exit
226848e5ce07Smrg       --mode=MODE          use operation mode MODE
226948e5ce07Smrg       --no-warnings        equivalent to '-Wnone'
227048e5ce07Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
227148e5ce07Smrg       --quiet, --silent    don't print informational messages
227248e5ce07Smrg       --tag=TAG            use configuration variables from tag TAG
227348e5ce07Smrg   -v, --verbose            print more informational messages than default
227448e5ce07Smrg       --version            print version information
227548e5ce07Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
227648e5ce07Smrg   -h, --help, --help-all   print short, long, or detailed help message
227748e5ce07Smrg"
2278b789ec8aSmrg
227948e5ce07Smrg# Additional text appended to 'usage_message' in response to '--help'.
228048e5ce07Smrgfunc_help ()
22810eb1301bSmrg{
228248e5ce07Smrg    $debug_cmd
228348e5ce07Smrg
228448e5ce07Smrg    func_usage_message
228548e5ce07Smrg    $ECHO "$long_help_message
228648e5ce07Smrg
228748e5ce07SmrgMODE must be one of the following:
228848e5ce07Smrg
228948e5ce07Smrg       clean           remove files from the build directory
229048e5ce07Smrg       compile         compile a source file into a libtool object
229148e5ce07Smrg       execute         automatically set library path, then run a program
229248e5ce07Smrg       finish          complete the installation of libtool libraries
229348e5ce07Smrg       install         install libraries or executables
229448e5ce07Smrg       link            create a library or an executable
229548e5ce07Smrg       uninstall       remove libraries from an installed directory
229648e5ce07Smrg
229748e5ce07SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
229848e5ce07Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
229948e5ce07SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
230048e5ce07Smrg
230148e5ce07SmrgWhen reporting a bug, please describe a test case to reproduce it and
230248e5ce07Smrginclude the following information:
230348e5ce07Smrg
230448e5ce07Smrg       host-triplet:   $host
230548e5ce07Smrg       shell:          $SHELL
230648e5ce07Smrg       compiler:       $LTCC
230748e5ce07Smrg       compiler flags: $LTCFLAGS
230848e5ce07Smrg       linker:         $LD (gnu? $with_gnu_ld)
23094e8f48c7Smrg       version:        $progname (GNU libtool) 2.4.7
231048e5ce07Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
231148e5ce07Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
231248e5ce07Smrg
231348e5ce07SmrgReport bugs to <bug-libtool@gnu.org>.
23144e8f48c7SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
231548e5ce07SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
231648e5ce07Smrg    exit 0
231748e5ce07Smrg}
231844584a44Smrg
231944584a44Smrg
232048e5ce07Smrg# func_lo2o OBJECT-NAME
232148e5ce07Smrg# ---------------------
232248e5ce07Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
232348e5ce07Smrg# object suffix.
232444584a44Smrg
232548e5ce07Smrglo2o=s/\\.lo\$/.$objext/
232648e5ce07Smrgo2lo=s/\\.$objext\$/.lo/
232744584a44Smrg
232848e5ce07Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
232948e5ce07Smrg  eval 'func_lo2o ()
233048e5ce07Smrg  {
233148e5ce07Smrg    case $1 in
233248e5ce07Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
233348e5ce07Smrg      *   ) func_lo2o_result=$1               ;;
233448e5ce07Smrg    esac
233548e5ce07Smrg  }'
233648e5ce07Smrg
233748e5ce07Smrg  # func_xform LIBOBJ-OR-SOURCE
233848e5ce07Smrg  # ---------------------------
233948e5ce07Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
234048e5ce07Smrg  # suffix to a '.lo' libtool-object suffix.
234148e5ce07Smrg  eval 'func_xform ()
234248e5ce07Smrg  {
234348e5ce07Smrg    func_xform_result=${1%.*}.lo
234448e5ce07Smrg  }'
234548e5ce07Smrgelse
234648e5ce07Smrg  # ...otherwise fall back to using sed.
234748e5ce07Smrg  func_lo2o ()
234848e5ce07Smrg  {
234948e5ce07Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
235048e5ce07Smrg  }
235148e5ce07Smrg
235248e5ce07Smrg  func_xform ()
235348e5ce07Smrg  {
235448e5ce07Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
235548e5ce07Smrg  }
235648e5ce07Smrgfi
2357b789ec8aSmrg
2358b789ec8aSmrg
235948e5ce07Smrg# func_fatal_configuration ARG...
236048e5ce07Smrg# -------------------------------
2361c27c18e8Smrg# Echo program name prefixed message to standard error, followed by
2362c27c18e8Smrg# a configuration failure hint, and exit.
2363c27c18e8Smrgfunc_fatal_configuration ()
2364c27c18e8Smrg{
23654e8f48c7Smrg    func_fatal_error ${1+"$@"} \
236648e5ce07Smrg      "See the $PACKAGE documentation for more information." \
236748e5ce07Smrg      "Fatal configuration error."
2368c27c18e8Smrg}
2369c43cc173Smrg
237021e67964Smrg
2371c27c18e8Smrg# func_config
237248e5ce07Smrg# -----------
2373c27c18e8Smrg# Display the configuration for all the tags in this script.
2374c27c18e8Smrgfunc_config ()
2375c27c18e8Smrg{
2376c27c18e8Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377c27c18e8Smrg    re_endcf='^# ### END LIBTOOL'
2378c27c18e8Smrg
2379c27c18e8Smrg    # Default configuration.
2380c27c18e8Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2381c43cc173Smrg
2382c43cc173Smrg    # Now print the configurations for the tags.
2383c43cc173Smrg    for tagname in $taglist; do
2384c27c18e8Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385c43cc173Smrg    done
2386c43cc173Smrg
2387c27c18e8Smrg    exit $?
2388c27c18e8Smrg}
2389c43cc173Smrg
239048e5ce07Smrg
2391c27c18e8Smrg# func_features
239248e5ce07Smrg# -------------
2393c27c18e8Smrg# Display the features supported by this script.
2394c27c18e8Smrgfunc_features ()
2395c27c18e8Smrg{
239637eb1ca1Smrg    echo "host: $host"
239748e5ce07Smrg    if test yes = "$build_libtool_libs"; then
239837eb1ca1Smrg      echo "enable shared libraries"
2399c43cc173Smrg    else
240037eb1ca1Smrg      echo "disable shared libraries"
2401c43cc173Smrg    fi
240248e5ce07Smrg    if test yes = "$build_old_libs"; then
240337eb1ca1Smrg      echo "enable static libraries"
2404c43cc173Smrg    else
240537eb1ca1Smrg      echo "disable static libraries"
2406c43cc173Smrg    fi
2407c27c18e8Smrg
2408c43cc173Smrg    exit $?
2409c27c18e8Smrg}
2410c43cc173Smrg
241148e5ce07Smrg
241248e5ce07Smrg# func_enable_tag TAGNAME
241348e5ce07Smrg# -----------------------
2414c27c18e8Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415c27c18e8Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416c27c18e8Smrg# variable here.
2417c27c18e8Smrgfunc_enable_tag ()
2418c27c18e8Smrg{
241948e5ce07Smrg    # Global variable:
242048e5ce07Smrg    tagname=$1
2421c43cc173Smrg
242248e5ce07Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
242348e5ce07Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
242448e5ce07Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425c43cc173Smrg
242648e5ce07Smrg    # Validate tagname.
242748e5ce07Smrg    case $tagname in
242848e5ce07Smrg      *[!-_A-Za-z0-9,/]*)
242948e5ce07Smrg        func_fatal_error "invalid tag name: $tagname"
243048e5ce07Smrg        ;;
243148e5ce07Smrg    esac
2432c43cc173Smrg
243348e5ce07Smrg    # Don't test for the "default" C tag, as we know it's
243448e5ce07Smrg    # there but not specially marked.
243548e5ce07Smrg    case $tagname in
243648e5ce07Smrg        CC) ;;
2437c27c18e8Smrg    *)
243848e5ce07Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
243948e5ce07Smrg	  taglist="$taglist $tagname"
244048e5ce07Smrg
244148e5ce07Smrg	  # Evaluate the configuration.  Be careful to quote the path
244248e5ce07Smrg	  # and the sed script, to avoid splitting on whitespace, but
244348e5ce07Smrg	  # also don't use non-portable quotes within backquotes within
244448e5ce07Smrg	  # quotes we have to do it in 2 steps:
244548e5ce07Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
244648e5ce07Smrg	  eval "$extractedcf"
244748e5ce07Smrg        else
244848e5ce07Smrg	  func_error "ignoring unknown tag $tagname"
244948e5ce07Smrg        fi
245048e5ce07Smrg        ;;
245148e5ce07Smrg    esac
2452c27c18e8Smrg}
2453c27c18e8Smrg
245448e5ce07Smrg
2455b789ec8aSmrg# func_check_version_match
245648e5ce07Smrg# ------------------------
2457b789ec8aSmrg# Ensure that we are using m4 macros, and libtool script from the same
2458b789ec8aSmrg# release of libtool.
2459b789ec8aSmrgfunc_check_version_match ()
2460c27c18e8Smrg{
246148e5ce07Smrg    if test "$package_revision" != "$macro_revision"; then
246248e5ce07Smrg      if test "$VERSION" != "$macro_version"; then
246348e5ce07Smrg        if test -z "$macro_version"; then
246448e5ce07Smrg          cat >&2 <<_LT_EOF
2465b789ec8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466b789ec8aSmrg$progname: definition of this LT_INIT comes from an older release.
2467b789ec8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468b789ec8aSmrg$progname: and run autoconf again.
2469b789ec8aSmrg_LT_EOF
247048e5ce07Smrg        else
247148e5ce07Smrg          cat >&2 <<_LT_EOF
2472b789ec8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473b789ec8aSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474b789ec8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475b789ec8aSmrg$progname: and run autoconf again.
2476b789ec8aSmrg_LT_EOF
247748e5ce07Smrg        fi
247848e5ce07Smrg      else
247948e5ce07Smrg        cat >&2 <<_LT_EOF
2480b789ec8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481b789ec8aSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482b789ec8aSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483b789ec8aSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484b789ec8aSmrg_LT_EOF
248548e5ce07Smrg      fi
2486b789ec8aSmrg
248748e5ce07Smrg      exit $EXIT_MISMATCH
248848e5ce07Smrg    fi
24890eb1301bSmrg}
2490b789ec8aSmrg
2491c43cc173Smrg
249248e5ce07Smrg# libtool_options_prep [ARG]...
249348e5ce07Smrg# -----------------------------
249448e5ce07Smrg# Preparation for options parsed by libtool.
249548e5ce07Smrglibtool_options_prep ()
249648e5ce07Smrg{
249748e5ce07Smrg    $debug_mode
2498b789ec8aSmrg
249948e5ce07Smrg    # Option defaults:
250048e5ce07Smrg    opt_config=false
250148e5ce07Smrg    opt_dlopen=
250248e5ce07Smrg    opt_dry_run=false
250348e5ce07Smrg    opt_help=false
250448e5ce07Smrg    opt_mode=
250548e5ce07Smrg    opt_preserve_dup_deps=false
250648e5ce07Smrg    opt_quiet=false
2507b789ec8aSmrg
250848e5ce07Smrg    nonopt=
250948e5ce07Smrg    preserve_args=
251044584a44Smrg
251187404ef7Smrg    _G_rc_lt_options_prep=:
251287404ef7Smrg
251348e5ce07Smrg    # Shorthand for --mode=foo, only valid as the first argument
251448e5ce07Smrg    case $1 in
251548e5ce07Smrg    clean|clea|cle|cl)
251648e5ce07Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
251748e5ce07Smrg      ;;
251848e5ce07Smrg    compile|compil|compi|comp|com|co|c)
251948e5ce07Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
252048e5ce07Smrg      ;;
252148e5ce07Smrg    execute|execut|execu|exec|exe|ex|e)
252248e5ce07Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
252348e5ce07Smrg      ;;
252448e5ce07Smrg    finish|finis|fini|fin|fi|f)
252548e5ce07Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
252648e5ce07Smrg      ;;
252748e5ce07Smrg    install|instal|insta|inst|ins|in|i)
252848e5ce07Smrg      shift; set dummy --mode install ${1+"$@"}; shift
252948e5ce07Smrg      ;;
253048e5ce07Smrg    link|lin|li|l)
253148e5ce07Smrg      shift; set dummy --mode link ${1+"$@"}; shift
253248e5ce07Smrg      ;;
253348e5ce07Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
253448e5ce07Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
253548e5ce07Smrg      ;;
253687404ef7Smrg    *)
253787404ef7Smrg      _G_rc_lt_options_prep=false
253887404ef7Smrg      ;;
253948e5ce07Smrg    esac
254048e5ce07Smrg
254187404ef7Smrg    if $_G_rc_lt_options_prep; then
254287404ef7Smrg      # Pass back the list of options.
25434e8f48c7Smrg      func_quote eval ${1+"$@"}
25444e8f48c7Smrg      libtool_options_prep_result=$func_quote_result
254587404ef7Smrg    fi
254648e5ce07Smrg}
254748e5ce07Smrgfunc_add_hook func_options_prep libtool_options_prep
2548b789ec8aSmrg
2549b789ec8aSmrg
255048e5ce07Smrg# libtool_parse_options [ARG]...
255148e5ce07Smrg# ---------------------------------
255248e5ce07Smrg# Provide handling for libtool specific options.
255348e5ce07Smrglibtool_parse_options ()
2554b789ec8aSmrg{
255548e5ce07Smrg    $debug_cmd
2556c27c18e8Smrg
255787404ef7Smrg    _G_rc_lt_parse_options=false
255887404ef7Smrg
255948e5ce07Smrg    # Perform our own loop to consume as many options as possible in
256048e5ce07Smrg    # each iteration.
256148e5ce07Smrg    while test $# -gt 0; do
256287404ef7Smrg      _G_match_lt_parse_options=:
256348e5ce07Smrg      _G_opt=$1
256448e5ce07Smrg      shift
256548e5ce07Smrg      case $_G_opt in
256648e5ce07Smrg        --dry-run|--dryrun|-n)
256748e5ce07Smrg                        opt_dry_run=:
256848e5ce07Smrg                        ;;
256948e5ce07Smrg
257048e5ce07Smrg        --config)       func_config ;;
257148e5ce07Smrg
257248e5ce07Smrg        --dlopen|-dlopen)
257348e5ce07Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
257448e5ce07Smrg}$1"
257548e5ce07Smrg                        shift
257648e5ce07Smrg                        ;;
257748e5ce07Smrg
257848e5ce07Smrg        --preserve-dup-deps)
257948e5ce07Smrg                        opt_preserve_dup_deps=: ;;
258048e5ce07Smrg
258148e5ce07Smrg        --features)     func_features ;;
258248e5ce07Smrg
258348e5ce07Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
258448e5ce07Smrg
258548e5ce07Smrg        --help)         opt_help=: ;;
258648e5ce07Smrg
258748e5ce07Smrg        --help-all)     opt_help=': help-all' ;;
258848e5ce07Smrg
258948e5ce07Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
259048e5ce07Smrg                        opt_mode=$1
259148e5ce07Smrg                        case $1 in
259248e5ce07Smrg                          # Valid mode arguments:
259348e5ce07Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
259448e5ce07Smrg
259548e5ce07Smrg                          # Catch anything else as an error
259648e5ce07Smrg                          *) func_error "invalid argument for $_G_opt"
259748e5ce07Smrg                             exit_cmd=exit
259848e5ce07Smrg                             break
259948e5ce07Smrg                             ;;
260048e5ce07Smrg                        esac
260148e5ce07Smrg                        shift
260248e5ce07Smrg                        ;;
260348e5ce07Smrg
260448e5ce07Smrg        --no-silent|--no-quiet)
260548e5ce07Smrg                        opt_quiet=false
260648e5ce07Smrg                        func_append preserve_args " $_G_opt"
260748e5ce07Smrg                        ;;
260848e5ce07Smrg
260948e5ce07Smrg        --no-warnings|--no-warning|--no-warn)
261048e5ce07Smrg                        opt_warning=false
261148e5ce07Smrg                        func_append preserve_args " $_G_opt"
261248e5ce07Smrg                        ;;
261348e5ce07Smrg
261448e5ce07Smrg        --no-verbose)
261548e5ce07Smrg                        opt_verbose=false
261648e5ce07Smrg                        func_append preserve_args " $_G_opt"
261748e5ce07Smrg                        ;;
261848e5ce07Smrg
261948e5ce07Smrg        --silent|--quiet)
262048e5ce07Smrg                        opt_quiet=:
262148e5ce07Smrg                        opt_verbose=false
262248e5ce07Smrg                        func_append preserve_args " $_G_opt"
262348e5ce07Smrg                        ;;
262448e5ce07Smrg
262548e5ce07Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
262648e5ce07Smrg                        opt_tag=$1
262748e5ce07Smrg                        func_append preserve_args " $_G_opt $1"
262848e5ce07Smrg                        func_enable_tag "$1"
262948e5ce07Smrg                        shift
263048e5ce07Smrg                        ;;
263148e5ce07Smrg
263248e5ce07Smrg        --verbose|-v)   opt_quiet=false
263348e5ce07Smrg                        opt_verbose=:
263448e5ce07Smrg                        func_append preserve_args " $_G_opt"
263548e5ce07Smrg                        ;;
263648e5ce07Smrg
263787404ef7Smrg        # An option not handled by this hook function:
263887404ef7Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
263987404ef7Smrg                        _G_match_lt_parse_options=false
264087404ef7Smrg                        break
264187404ef7Smrg                        ;;
264248e5ce07Smrg      esac
264387404ef7Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
264448e5ce07Smrg    done
2645b789ec8aSmrg
264687404ef7Smrg    if $_G_rc_lt_parse_options; then
264787404ef7Smrg      # save modified positional parameters for caller
26484e8f48c7Smrg      func_quote eval ${1+"$@"}
26494e8f48c7Smrg      libtool_parse_options_result=$func_quote_result
265087404ef7Smrg    fi
265148e5ce07Smrg}
265248e5ce07Smrgfunc_add_hook func_parse_options libtool_parse_options
2653c27c18e8Smrg
2654c43cc173Smrg
2655c27c18e8Smrg
265648e5ce07Smrg# libtool_validate_options [ARG]...
265748e5ce07Smrg# ---------------------------------
265848e5ce07Smrg# Perform any sanity checks on option settings and/or unconsumed
265948e5ce07Smrg# arguments.
266048e5ce07Smrglibtool_validate_options ()
266148e5ce07Smrg{
266248e5ce07Smrg    # save first non-option argument
266348e5ce07Smrg    if test 0 -lt $#; then
266448e5ce07Smrg      nonopt=$1
266548e5ce07Smrg      shift
2666c27c18e8Smrg    fi
2667c27c18e8Smrg
266848e5ce07Smrg    # preserve --debug
266948e5ce07Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
267044584a44Smrg
26714e8f48c7Smrg    # Keeping compiler generated duplicates in $postdeps and $predeps is not
26724e8f48c7Smrg    # harmful, and is necessary in a majority of systems that use it to satisfy
26734e8f48c7Smrg    # symbol dependencies.
26744e8f48c7Smrg    opt_duplicate_compiler_generated_deps=:
267544584a44Smrg
267648e5ce07Smrg    $opt_help || {
267748e5ce07Smrg      # Sanity checks first:
267848e5ce07Smrg      func_check_version_match
2679c27c18e8Smrg
268048e5ce07Smrg      test yes != "$build_libtool_libs" \
268148e5ce07Smrg        && test yes != "$build_old_libs" \
268248e5ce07Smrg        && func_fatal_configuration "not configured to build any kind of library"
2683c27c18e8Smrg
268448e5ce07Smrg      # Darwin sucks
268548e5ce07Smrg      eval std_shrext=\"$shrext_cmds\"
268648e5ce07Smrg
268748e5ce07Smrg      # Only execute mode is allowed to have -dlopen flags.
268848e5ce07Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
268948e5ce07Smrg        func_error "unrecognized option '-dlopen'"
269048e5ce07Smrg        $ECHO "$help" 1>&2
269148e5ce07Smrg        exit $EXIT_FAILURE
269248e5ce07Smrg      fi
269348e5ce07Smrg
269448e5ce07Smrg      # Change the help message to a mode-specific one.
269548e5ce07Smrg      generic_help=$help
269648e5ce07Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
269748e5ce07Smrg    }
269848e5ce07Smrg
269948e5ce07Smrg    # Pass back the unparsed argument list
27004e8f48c7Smrg    func_quote eval ${1+"$@"}
27014e8f48c7Smrg    libtool_validate_options_result=$func_quote_result
2702b789ec8aSmrg}
270348e5ce07Smrgfunc_add_hook func_validate_options libtool_validate_options
270448e5ce07Smrg
2705c27c18e8Smrg
270648e5ce07Smrg# Process options as early as possible so that --help and --version
270748e5ce07Smrg# can return quickly.
270848e5ce07Smrgfunc_options ${1+"$@"}
270948e5ce07Smrgeval set dummy "$func_options_result"; shift
271044584a44Smrg
2711c43cc173Smrg
2712c43cc173Smrg
2713b789ec8aSmrg## ----------- ##
2714b789ec8aSmrg##    Main.    ##
2715b789ec8aSmrg## ----------- ##
2716c43cc173Smrg
271748e5ce07Smrgmagic='%%%MAGIC variable%%%'
271848e5ce07Smrgmagic_exe='%%%MAGIC EXE variable%%%'
271948e5ce07Smrg
272048e5ce07Smrg# Global variables.
272148e5ce07Smrgextracted_archives=
272248e5ce07Smrgextracted_serial=0
272348e5ce07Smrg
272448e5ce07Smrg# If this variable is set in any of the actions, the command in it
272548e5ce07Smrg# will be execed at the end.  This prevents here-documents from being
272648e5ce07Smrg# left over by shells.
272748e5ce07Smrgexec_cmd=
272848e5ce07Smrg
272948e5ce07Smrg
273048e5ce07Smrg# A function that is used when there is no print builtin or printf.
273148e5ce07Smrgfunc_fallback_echo ()
273248e5ce07Smrg{
273348e5ce07Smrg  eval 'cat <<_LTECHO_EOF
273448e5ce07Smrg$1
273548e5ce07Smrg_LTECHO_EOF'
273648e5ce07Smrg}
273748e5ce07Smrg
273848e5ce07Smrg# func_generated_by_libtool
273948e5ce07Smrg# True iff stdin has been generated by Libtool. This function is only
274048e5ce07Smrg# a basic sanity check; it will hardly flush out determined imposters.
274148e5ce07Smrgfunc_generated_by_libtool_p ()
274248e5ce07Smrg{
274348e5ce07Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
274448e5ce07Smrg}
274548e5ce07Smrg
2746c27c18e8Smrg# func_lalib_p file
274748e5ce07Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2748c27c18e8Smrg# This function is only a basic sanity check; it will hardly flush out
2749c27c18e8Smrg# determined imposters.
2750c27c18e8Smrgfunc_lalib_p ()
2751c27c18e8Smrg{
2752c27c18e8Smrg    test -f "$1" &&
275348e5ce07Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2754c27c18e8Smrg}
2755c43cc173Smrg
2756c27c18e8Smrg# func_lalib_unsafe_p file
275748e5ce07Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2758c27c18e8Smrg# This function implements the same check as func_lalib_p without
2759c27c18e8Smrg# resorting to external programs.  To this end, it redirects stdin and
2760c27c18e8Smrg# closes it afterwards, without saving the original file descriptor.
2761c27c18e8Smrg# As a safety measure, use it only where a negative result would be
276248e5ce07Smrg# fatal anyway.  Works if 'file' does not exist.
2763c27c18e8Smrgfunc_lalib_unsafe_p ()
2764c27c18e8Smrg{
2765c27c18e8Smrg    lalib_p=no
2766c27c18e8Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2767c27c18e8Smrg	for lalib_p_l in 1 2 3 4
2768c27c18e8Smrg	do
2769c27c18e8Smrg	    read lalib_p_line
277048e5ce07Smrg	    case $lalib_p_line in
2771c27c18e8Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2772c27c18e8Smrg	    esac
2773c27c18e8Smrg	done
2774c27c18e8Smrg	exec 0<&5 5<&-
2775c27c18e8Smrg    fi
277648e5ce07Smrg    test yes = "$lalib_p"
2777c27c18e8Smrg}
2778c43cc173Smrg
2779c27c18e8Smrg# func_ltwrapper_script_p file
2780c27c18e8Smrg# True iff FILE is a libtool wrapper script
2781c27c18e8Smrg# This function is only a basic sanity check; it will hardly flush out
2782c27c18e8Smrg# determined imposters.
2783c27c18e8Smrgfunc_ltwrapper_script_p ()
2784c27c18e8Smrg{
278548e5ce07Smrg    test -f "$1" &&
278648e5ce07Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2787c27c18e8Smrg}
2788c43cc173Smrg
2789c27c18e8Smrg# func_ltwrapper_executable_p file
2790c27c18e8Smrg# True iff FILE is a libtool wrapper executable
2791c27c18e8Smrg# This function is only a basic sanity check; it will hardly flush out
2792c27c18e8Smrg# determined imposters.
2793c27c18e8Smrgfunc_ltwrapper_executable_p ()
2794c27c18e8Smrg{
2795c27c18e8Smrg    func_ltwrapper_exec_suffix=
2796c27c18e8Smrg    case $1 in
2797c27c18e8Smrg    *.exe) ;;
2798c27c18e8Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2799c27c18e8Smrg    esac
2800c27c18e8Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2801c27c18e8Smrg}
2802c43cc173Smrg
2803c27c18e8Smrg# func_ltwrapper_scriptname file
2804c27c18e8Smrg# Assumes file is an ltwrapper_executable
2805c27c18e8Smrg# uses $file to determine the appropriate filename for a
2806c27c18e8Smrg# temporary ltwrapper_script.
2807c27c18e8Smrgfunc_ltwrapper_scriptname ()
2808c27c18e8Smrg{
2809b789ec8aSmrg    func_dirname_and_basename "$1" "" "."
2810b789ec8aSmrg    func_stripname '' '.exe' "$func_basename_result"
281148e5ce07Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2812c27c18e8Smrg}
2813c27c18e8Smrg
2814c27c18e8Smrg# func_ltwrapper_p file
2815c27c18e8Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2816c27c18e8Smrg# This function is only a basic sanity check; it will hardly flush out
2817c27c18e8Smrg# determined imposters.
2818c27c18e8Smrgfunc_ltwrapper_p ()
2819c27c18e8Smrg{
2820c27c18e8Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2821c27c18e8Smrg}
2822c27c18e8Smrg
2823c27c18e8Smrg
2824c27c18e8Smrg# func_execute_cmds commands fail_cmd
2825c27c18e8Smrg# Execute tilde-delimited COMMANDS.
2826c27c18e8Smrg# If FAIL_CMD is given, eval that upon failure.
2827c27c18e8Smrg# FAIL_CMD may read-access the current command in variable CMD!
2828c27c18e8Smrgfunc_execute_cmds ()
2829c27c18e8Smrg{
283048e5ce07Smrg    $debug_cmd
283148e5ce07Smrg
2832c27c18e8Smrg    save_ifs=$IFS; IFS='~'
2833c27c18e8Smrg    for cmd in $1; do
283448e5ce07Smrg      IFS=$sp$nl
28350eb1301bSmrg      eval cmd=\"$cmd\"
283648e5ce07Smrg      IFS=$save_ifs
2837c27c18e8Smrg      func_show_eval "$cmd" "${2-:}"
2838c27c18e8Smrg    done
2839c27c18e8Smrg    IFS=$save_ifs
2840c27c18e8Smrg}
2841c27c18e8Smrg
2842c27c18e8Smrg
2843c27c18e8Smrg# func_source file
2844c27c18e8Smrg# Source FILE, adding directory component if necessary.
2845c27c18e8Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2846c27c18e8Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2847c27c18e8Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
284848e5ce07Smrg# 'FILE.' does not work on cygwin managed mounts.
2849c27c18e8Smrgfunc_source ()
2850c27c18e8Smrg{
285148e5ce07Smrg    $debug_cmd
285248e5ce07Smrg
2853c27c18e8Smrg    case $1 in
2854c27c18e8Smrg    */* | *\\*)	. "$1" ;;
2855c27c18e8Smrg    *)		. "./$1" ;;
2856c27c18e8Smrg    esac
2857c27c18e8Smrg}
2858c27c18e8Smrg
2859c27c18e8Smrg
2860b789ec8aSmrg# func_resolve_sysroot PATH
2861b789ec8aSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2862b789ec8aSmrg# func_resolve_sysroot_result
2863b789ec8aSmrgfunc_resolve_sysroot ()
2864b789ec8aSmrg{
2865b789ec8aSmrg  func_resolve_sysroot_result=$1
2866b789ec8aSmrg  case $func_resolve_sysroot_result in
2867b789ec8aSmrg  =*)
2868b789ec8aSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2869b789ec8aSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2870b789ec8aSmrg    ;;
2871b789ec8aSmrg  esac
2872b789ec8aSmrg}
2873b789ec8aSmrg
2874b789ec8aSmrg# func_replace_sysroot PATH
2875b789ec8aSmrg# If PATH begins with the sysroot, replace it with = and
2876b789ec8aSmrg# store the result into func_replace_sysroot_result.
2877b789ec8aSmrgfunc_replace_sysroot ()
2878b789ec8aSmrg{
287948e5ce07Smrg  case $lt_sysroot:$1 in
2880b789ec8aSmrg  ?*:"$lt_sysroot"*)
2881b789ec8aSmrg    func_stripname "$lt_sysroot" '' "$1"
288248e5ce07Smrg    func_replace_sysroot_result='='$func_stripname_result
2883b789ec8aSmrg    ;;
2884b789ec8aSmrg  *)
2885b789ec8aSmrg    # Including no sysroot.
2886b789ec8aSmrg    func_replace_sysroot_result=$1
2887b789ec8aSmrg    ;;
2888b789ec8aSmrg  esac
2889b789ec8aSmrg}
2890b789ec8aSmrg
2891c27c18e8Smrg# func_infer_tag arg
2892c27c18e8Smrg# Infer tagged configuration to use if any are available and
2893c27c18e8Smrg# if one wasn't chosen via the "--tag" command line option.
2894c27c18e8Smrg# Only attempt this if the compiler in the base compile
2895c27c18e8Smrg# command doesn't match the default compiler.
2896c27c18e8Smrg# arg is usually of the form 'gcc ...'
2897c27c18e8Smrgfunc_infer_tag ()
2898c27c18e8Smrg{
289948e5ce07Smrg    $debug_cmd
290048e5ce07Smrg
2901c27c18e8Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2902c27c18e8Smrg      CC_quoted=
2903c27c18e8Smrg      for arg in $CC; do
2904b789ec8aSmrg	func_append_quoted CC_quoted "$arg"
2905c27c18e8Smrg      done
290637eb1ca1Smrg      CC_expanded=`func_echo_all $CC`
290737eb1ca1Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2908c27c18e8Smrg      case $@ in
2909c27c18e8Smrg      # Blanks in the command may have been stripped by the calling shell,
2910c27c18e8Smrg      # but not from the CC environment variable when configure was run.
291137eb1ca1Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291237eb1ca1Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2913c27c18e8Smrg      # Blanks at the start of $base_compile will cause this to fail
2914c27c18e8Smrg      # if we don't check for them as well.
2915c27c18e8Smrg      *)
2916c27c18e8Smrg	for z in $available_tags; do
2917c27c18e8Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2918c27c18e8Smrg	    # Evaluate the configuration.
291948e5ce07Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2920c27c18e8Smrg	    CC_quoted=
2921c27c18e8Smrg	    for arg in $CC; do
2922c27c18e8Smrg	      # Double-quote args containing other shell metacharacters.
2923b789ec8aSmrg	      func_append_quoted CC_quoted "$arg"
2924c27c18e8Smrg	    done
292537eb1ca1Smrg	    CC_expanded=`func_echo_all $CC`
292637eb1ca1Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2927c27c18e8Smrg	    case "$@ " in
292837eb1ca1Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
292937eb1ca1Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2930c27c18e8Smrg	      # The compiler in the base compile command matches
2931c27c18e8Smrg	      # the one in the tagged configuration.
2932c27c18e8Smrg	      # Assume this is the tagged configuration we want.
2933c27c18e8Smrg	      tagname=$z
2934c27c18e8Smrg	      break
2935c27c18e8Smrg	      ;;
2936c27c18e8Smrg	    esac
2937c27c18e8Smrg	  fi
2938c27c18e8Smrg	done
2939c27c18e8Smrg	# If $tagname still isn't set, then no tagged configuration
2940c27c18e8Smrg	# was found and let the user know that the "--tag" command
2941c27c18e8Smrg	# line option must be used.
2942c27c18e8Smrg	if test -z "$tagname"; then
2943c27c18e8Smrg	  func_echo "unable to infer tagged configuration"
294448e5ce07Smrg	  func_fatal_error "specify a tag with '--tag'"
2945c27c18e8Smrg#	else
2946c27c18e8Smrg#	  func_verbose "using $tagname tagged configuration"
2947c27c18e8Smrg	fi
2948c27c18e8Smrg	;;
2949c27c18e8Smrg      esac
2950c27c18e8Smrg    fi
2951c27c18e8Smrg}
2952c27c18e8Smrg
2953c27c18e8Smrg
2954c27c18e8Smrg
2955b789ec8aSmrg# func_write_libtool_object output_name pic_name nonpic_name
2956b789ec8aSmrg# Create a libtool object file (analogous to a ".la" file),
2957b789ec8aSmrg# but don't create it if we're doing a dry run.
2958b789ec8aSmrgfunc_write_libtool_object ()
2959b789ec8aSmrg{
296048e5ce07Smrg    write_libobj=$1
296148e5ce07Smrg    if test yes = "$build_libtool_libs"; then
296248e5ce07Smrg      write_lobj=\'$2\'
2963b789ec8aSmrg    else
2964b789ec8aSmrg      write_lobj=none
2965b789ec8aSmrg    fi
2966b789ec8aSmrg
296748e5ce07Smrg    if test yes = "$build_old_libs"; then
296848e5ce07Smrg      write_oldobj=\'$3\'
2969b789ec8aSmrg    else
2970b789ec8aSmrg      write_oldobj=none
2971b789ec8aSmrg    fi
2972b789ec8aSmrg
2973b789ec8aSmrg    $opt_dry_run || {
2974b789ec8aSmrg      cat >${write_libobj}T <<EOF
2975b789ec8aSmrg# $write_libobj - a libtool object file
297648e5ce07Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2977b789ec8aSmrg#
2978b789ec8aSmrg# Please DO NOT delete this file!
2979b789ec8aSmrg# It is necessary for linking the library.
2980b789ec8aSmrg
2981b789ec8aSmrg# Name of the PIC object.
2982b789ec8aSmrgpic_object=$write_lobj
2983b789ec8aSmrg
2984b789ec8aSmrg# Name of the non-PIC object
2985b789ec8aSmrgnon_pic_object=$write_oldobj
2986b789ec8aSmrg
2987b789ec8aSmrgEOF
298848e5ce07Smrg      $MV "${write_libobj}T" "$write_libobj"
2989b789ec8aSmrg    }
2990b789ec8aSmrg}
2991b789ec8aSmrg
2992b789ec8aSmrg
2993b789ec8aSmrg##################################################
2994b789ec8aSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
2995b789ec8aSmrg##################################################
2996b789ec8aSmrg
2997b789ec8aSmrg# func_convert_core_file_wine_to_w32 ARG
2998b789ec8aSmrg# Helper function used by file name conversion functions when $build is *nix,
2999b789ec8aSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3000b789ec8aSmrg# correctly configured wine environment available, with the winepath program
3001b789ec8aSmrg# in $build's $PATH.
3002b789ec8aSmrg#
3003b789ec8aSmrg# ARG is the $build file name to be converted to w32 format.
3004b789ec8aSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3005b789ec8aSmrg# be empty on error (or when ARG is empty)
3006b789ec8aSmrgfunc_convert_core_file_wine_to_w32 ()
3007b789ec8aSmrg{
300848e5ce07Smrg  $debug_cmd
300948e5ce07Smrg
301048e5ce07Smrg  func_convert_core_file_wine_to_w32_result=$1
3011b789ec8aSmrg  if test -n "$1"; then
3012b789ec8aSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3013b789ec8aSmrg    # are forced to check the contents of stdout. On the other hand, if the
3014b789ec8aSmrg    # command is not found, the shell will set an exit code of 127 and print
3015b789ec8aSmrg    # *an error message* to stdout. So we must check for both error code of
3016b789ec8aSmrg    # zero AND non-empty stdout, which explains the odd construction:
3017b789ec8aSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
301848e5ce07Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3019b789ec8aSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
302048e5ce07Smrg        $SED -e "$sed_naive_backslashify"`
3021b789ec8aSmrg    else
3022b789ec8aSmrg      func_convert_core_file_wine_to_w32_result=
3023b789ec8aSmrg    fi
3024b789ec8aSmrg  fi
3025b789ec8aSmrg}
3026b789ec8aSmrg# end: func_convert_core_file_wine_to_w32
3027b789ec8aSmrg
3028b789ec8aSmrg
3029b789ec8aSmrg# func_convert_core_path_wine_to_w32 ARG
3030b789ec8aSmrg# Helper function used by path conversion functions when $build is *nix, and
3031b789ec8aSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3032b789ec8aSmrg# configured wine environment available, with the winepath program in $build's
3033b789ec8aSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3034b789ec8aSmrg#
3035b789ec8aSmrg# ARG is path to be converted from $build format to win32.
3036b789ec8aSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3037b789ec8aSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3038b789ec8aSmrg# are convertible, then the result may be empty.
3039b789ec8aSmrgfunc_convert_core_path_wine_to_w32 ()
3040b789ec8aSmrg{
304148e5ce07Smrg  $debug_cmd
304248e5ce07Smrg
3043b789ec8aSmrg  # unfortunately, winepath doesn't convert paths, only file names
304448e5ce07Smrg  func_convert_core_path_wine_to_w32_result=
3045b789ec8aSmrg  if test -n "$1"; then
3046b789ec8aSmrg    oldIFS=$IFS
3047b789ec8aSmrg    IFS=:
3048b789ec8aSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3049b789ec8aSmrg      IFS=$oldIFS
3050b789ec8aSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
305148e5ce07Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3052b789ec8aSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
305348e5ce07Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3054b789ec8aSmrg        else
3055b789ec8aSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3056b789ec8aSmrg        fi
3057b789ec8aSmrg      fi
3058b789ec8aSmrg    done
3059b789ec8aSmrg    IFS=$oldIFS
3060b789ec8aSmrg  fi
3061b789ec8aSmrg}
3062b789ec8aSmrg# end: func_convert_core_path_wine_to_w32
3063b789ec8aSmrg
3064b789ec8aSmrg
3065b789ec8aSmrg# func_cygpath ARGS...
3066b789ec8aSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3067b789ec8aSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3068b789ec8aSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3069b789ec8aSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3070b789ec8aSmrg# file name or path is assumed to be in w32 format, as previously converted
3071b789ec8aSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3072b789ec8aSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3073b789ec8aSmrg# Cygwin format). Returns an empty string on error.
3074b789ec8aSmrg#
3075b789ec8aSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3076b789ec8aSmrg# be converted.
3077b789ec8aSmrg#
3078b789ec8aSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3079b789ec8aSmrg# environment variable; do not put it in $PATH.
3080b789ec8aSmrgfunc_cygpath ()
3081b789ec8aSmrg{
308248e5ce07Smrg  $debug_cmd
308348e5ce07Smrg
3084b789ec8aSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3085b789ec8aSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3086b789ec8aSmrg    if test "$?" -ne 0; then
3087b789ec8aSmrg      # on failure, ensure result is empty
3088b789ec8aSmrg      func_cygpath_result=
3089b789ec8aSmrg    fi
3090b789ec8aSmrg  else
3091b789ec8aSmrg    func_cygpath_result=
309248e5ce07Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3093b789ec8aSmrg  fi
3094b789ec8aSmrg}
3095b789ec8aSmrg#end: func_cygpath
3096b789ec8aSmrg
3097b789ec8aSmrg
3098b789ec8aSmrg# func_convert_core_msys_to_w32 ARG
3099b789ec8aSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3100b789ec8aSmrg# result in func_convert_core_msys_to_w32_result.
3101b789ec8aSmrgfunc_convert_core_msys_to_w32 ()
3102b789ec8aSmrg{
310348e5ce07Smrg  $debug_cmd
310448e5ce07Smrg
3105b789ec8aSmrg  # awkward: cmd appends spaces to result
3106b789ec8aSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
310748e5ce07Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3108b789ec8aSmrg}
3109b789ec8aSmrg#end: func_convert_core_msys_to_w32
3110b789ec8aSmrg
3111b789ec8aSmrg
3112b789ec8aSmrg# func_convert_file_check ARG1 ARG2
3113b789ec8aSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3114b789ec8aSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3115b789ec8aSmrg# func_to_host_file_result to ARG1).
3116b789ec8aSmrgfunc_convert_file_check ()
3117b789ec8aSmrg{
311848e5ce07Smrg  $debug_cmd
311948e5ce07Smrg
312048e5ce07Smrg  if test -z "$2" && test -n "$1"; then
3121b789ec8aSmrg    func_error "Could not determine host file name corresponding to"
312248e5ce07Smrg    func_error "  '$1'"
3123b789ec8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3124b789ec8aSmrg    # Fallback:
312548e5ce07Smrg    func_to_host_file_result=$1
3126b789ec8aSmrg  fi
3127b789ec8aSmrg}
3128b789ec8aSmrg# end func_convert_file_check
3129b789ec8aSmrg
3130b789ec8aSmrg
3131b789ec8aSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3132b789ec8aSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3133b789ec8aSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3134b789ec8aSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3135b789ec8aSmrgfunc_convert_path_check ()
3136b789ec8aSmrg{
313748e5ce07Smrg  $debug_cmd
313848e5ce07Smrg
3139b789ec8aSmrg  if test -z "$4" && test -n "$3"; then
3140b789ec8aSmrg    func_error "Could not determine the host path corresponding to"
314148e5ce07Smrg    func_error "  '$3'"
3142b789ec8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3143b789ec8aSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3144b789ec8aSmrg    # should not be "improved".  See libtool.info.
3145b789ec8aSmrg    if test "x$1" != "x$2"; then
3146b789ec8aSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3147b789ec8aSmrg      func_to_host_path_result=`echo "$3" |
3148b789ec8aSmrg        $SED -e "$lt_replace_pathsep_chars"`
3149b789ec8aSmrg    else
315048e5ce07Smrg      func_to_host_path_result=$3
3151b789ec8aSmrg    fi
3152b789ec8aSmrg  fi
3153b789ec8aSmrg}
3154b789ec8aSmrg# end func_convert_path_check
3155b789ec8aSmrg
3156b789ec8aSmrg
3157b789ec8aSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3158b789ec8aSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3159b789ec8aSmrg# and appending REPL if ORIG matches BACKPAT.
3160b789ec8aSmrgfunc_convert_path_front_back_pathsep ()
3161b789ec8aSmrg{
316248e5ce07Smrg  $debug_cmd
316348e5ce07Smrg
3164b789ec8aSmrg  case $4 in
316548e5ce07Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3166b789ec8aSmrg    ;;
3167b789ec8aSmrg  esac
3168b789ec8aSmrg  case $4 in
3169b789ec8aSmrg  $2 ) func_append func_to_host_path_result "$3"
3170b789ec8aSmrg    ;;
3171b789ec8aSmrg  esac
3172b789ec8aSmrg}
3173b789ec8aSmrg# end func_convert_path_front_back_pathsep
3174b789ec8aSmrg
3175b789ec8aSmrg
3176b789ec8aSmrg##################################################
3177b789ec8aSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3178b789ec8aSmrg##################################################
317948e5ce07Smrg# invoked via '$to_host_file_cmd ARG'
3180b789ec8aSmrg#
3181b789ec8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3182b789ec8aSmrg# Result will be available in $func_to_host_file_result.
3183b789ec8aSmrg
3184b789ec8aSmrg
3185b789ec8aSmrg# func_to_host_file ARG
3186b789ec8aSmrg# Converts the file name ARG from $build format to $host format. Return result
3187b789ec8aSmrg# in func_to_host_file_result.
3188b789ec8aSmrgfunc_to_host_file ()
3189b789ec8aSmrg{
319048e5ce07Smrg  $debug_cmd
319148e5ce07Smrg
3192b789ec8aSmrg  $to_host_file_cmd "$1"
3193b789ec8aSmrg}
3194b789ec8aSmrg# end func_to_host_file
3195b789ec8aSmrg
3196b789ec8aSmrg
3197b789ec8aSmrg# func_to_tool_file ARG LAZY
3198b789ec8aSmrg# converts the file name ARG from $build format to toolchain format. Return
3199b789ec8aSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3200b789ec8aSmrg# in (the comma separated) LAZY, no conversion takes place.
3201b789ec8aSmrgfunc_to_tool_file ()
3202b789ec8aSmrg{
320348e5ce07Smrg  $debug_cmd
320448e5ce07Smrg
3205b789ec8aSmrg  case ,$2, in
3206b789ec8aSmrg    *,"$to_tool_file_cmd",*)
3207b789ec8aSmrg      func_to_tool_file_result=$1
3208b789ec8aSmrg      ;;
3209b789ec8aSmrg    *)
3210b789ec8aSmrg      $to_tool_file_cmd "$1"
3211b789ec8aSmrg      func_to_tool_file_result=$func_to_host_file_result
3212b789ec8aSmrg      ;;
3213b789ec8aSmrg  esac
3214b789ec8aSmrg}
3215b789ec8aSmrg# end func_to_tool_file
3216b789ec8aSmrg
3217b789ec8aSmrg
3218b789ec8aSmrg# func_convert_file_noop ARG
3219b789ec8aSmrg# Copy ARG to func_to_host_file_result.
3220b789ec8aSmrgfunc_convert_file_noop ()
3221b789ec8aSmrg{
322248e5ce07Smrg  func_to_host_file_result=$1
3223b789ec8aSmrg}
3224b789ec8aSmrg# end func_convert_file_noop
3225b789ec8aSmrg
3226b789ec8aSmrg
3227b789ec8aSmrg# func_convert_file_msys_to_w32 ARG
3228b789ec8aSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3229b789ec8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3230b789ec8aSmrg# func_to_host_file_result.
3231b789ec8aSmrgfunc_convert_file_msys_to_w32 ()
3232b789ec8aSmrg{
323348e5ce07Smrg  $debug_cmd
323448e5ce07Smrg
323548e5ce07Smrg  func_to_host_file_result=$1
3236b789ec8aSmrg  if test -n "$1"; then
3237b789ec8aSmrg    func_convert_core_msys_to_w32 "$1"
323848e5ce07Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3239b789ec8aSmrg  fi
3240b789ec8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3241b789ec8aSmrg}
3242b789ec8aSmrg# end func_convert_file_msys_to_w32
3243b789ec8aSmrg
3244b789ec8aSmrg
3245b789ec8aSmrg# func_convert_file_cygwin_to_w32 ARG
3246b789ec8aSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3247b789ec8aSmrg# func_to_host_file_result.
3248b789ec8aSmrgfunc_convert_file_cygwin_to_w32 ()
3249b789ec8aSmrg{
325048e5ce07Smrg  $debug_cmd
325148e5ce07Smrg
325248e5ce07Smrg  func_to_host_file_result=$1
3253b789ec8aSmrg  if test -n "$1"; then
3254b789ec8aSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3255b789ec8aSmrg    # LT_CYGPATH in this case.
3256b789ec8aSmrg    func_to_host_file_result=`cygpath -m "$1"`
3257b789ec8aSmrg  fi
3258b789ec8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3259b789ec8aSmrg}
3260b789ec8aSmrg# end func_convert_file_cygwin_to_w32
3261b789ec8aSmrg
3262b789ec8aSmrg
3263b789ec8aSmrg# func_convert_file_nix_to_w32 ARG
3264b789ec8aSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3265b789ec8aSmrg# and a working winepath. Returns result in func_to_host_file_result.
3266b789ec8aSmrgfunc_convert_file_nix_to_w32 ()
3267b789ec8aSmrg{
326848e5ce07Smrg  $debug_cmd
326948e5ce07Smrg
327048e5ce07Smrg  func_to_host_file_result=$1
3271b789ec8aSmrg  if test -n "$1"; then
3272b789ec8aSmrg    func_convert_core_file_wine_to_w32 "$1"
327348e5ce07Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3274b789ec8aSmrg  fi
3275b789ec8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3276b789ec8aSmrg}
3277b789ec8aSmrg# end func_convert_file_nix_to_w32
3278b789ec8aSmrg
3279b789ec8aSmrg
3280b789ec8aSmrg# func_convert_file_msys_to_cygwin ARG
3281b789ec8aSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3282b789ec8aSmrg# Returns result in func_to_host_file_result.
3283b789ec8aSmrgfunc_convert_file_msys_to_cygwin ()
3284b789ec8aSmrg{
328548e5ce07Smrg  $debug_cmd
328648e5ce07Smrg
328748e5ce07Smrg  func_to_host_file_result=$1
3288b789ec8aSmrg  if test -n "$1"; then
3289b789ec8aSmrg    func_convert_core_msys_to_w32 "$1"
3290b789ec8aSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
329148e5ce07Smrg    func_to_host_file_result=$func_cygpath_result
3292b789ec8aSmrg  fi
3293b789ec8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3294b789ec8aSmrg}
3295b789ec8aSmrg# end func_convert_file_msys_to_cygwin
3296b789ec8aSmrg
3297b789ec8aSmrg
3298b789ec8aSmrg# func_convert_file_nix_to_cygwin ARG
3299b789ec8aSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3300b789ec8aSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3301b789ec8aSmrg# in func_to_host_file_result.
3302b789ec8aSmrgfunc_convert_file_nix_to_cygwin ()
3303b789ec8aSmrg{
330448e5ce07Smrg  $debug_cmd
330548e5ce07Smrg
330648e5ce07Smrg  func_to_host_file_result=$1
3307b789ec8aSmrg  if test -n "$1"; then
3308b789ec8aSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3309b789ec8aSmrg    func_convert_core_file_wine_to_w32 "$1"
3310b789ec8aSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
331148e5ce07Smrg    func_to_host_file_result=$func_cygpath_result
3312b789ec8aSmrg  fi
3313b789ec8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3314b789ec8aSmrg}
3315b789ec8aSmrg# end func_convert_file_nix_to_cygwin
3316b789ec8aSmrg
3317b789ec8aSmrg
3318b789ec8aSmrg#############################################
3319b789ec8aSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3320b789ec8aSmrg#############################################
332148e5ce07Smrg# invoked via '$to_host_path_cmd ARG'
3322b789ec8aSmrg#
3323b789ec8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3324b789ec8aSmrg# The result will be available in $func_to_host_path_result.
3325b789ec8aSmrg#
3326b789ec8aSmrg# Path separators are also converted from $build format to $host format.  If
3327b789ec8aSmrg# ARG begins or ends with a path separator character, it is preserved (but
3328b789ec8aSmrg# converted to $host format) on output.
3329b789ec8aSmrg#
3330b789ec8aSmrg# All path conversion functions are named using the following convention:
3331b789ec8aSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3332b789ec8aSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3333b789ec8aSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3334b789ec8aSmrg# same.  If conversion functions are added for new $build/$host combinations,
3335b789ec8aSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3336b789ec8aSmrg# will break.
3337b789ec8aSmrg
3338b789ec8aSmrg
3339b789ec8aSmrg# func_init_to_host_path_cmd
3340b789ec8aSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3341b789ec8aSmrg# appropriate value, based on the value of $to_host_file_cmd.
3342b789ec8aSmrgto_host_path_cmd=
3343b789ec8aSmrgfunc_init_to_host_path_cmd ()
3344b789ec8aSmrg{
334548e5ce07Smrg  $debug_cmd
334648e5ce07Smrg
3347b789ec8aSmrg  if test -z "$to_host_path_cmd"; then
3348b789ec8aSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
334948e5ce07Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3350b789ec8aSmrg  fi
3351b789ec8aSmrg}
3352b789ec8aSmrg
3353b789ec8aSmrg
3354b789ec8aSmrg# func_to_host_path ARG
3355b789ec8aSmrg# Converts the path ARG from $build format to $host format. Return result
3356b789ec8aSmrg# in func_to_host_path_result.
3357b789ec8aSmrgfunc_to_host_path ()
3358b789ec8aSmrg{
335948e5ce07Smrg  $debug_cmd
336048e5ce07Smrg
3361b789ec8aSmrg  func_init_to_host_path_cmd
3362b789ec8aSmrg  $to_host_path_cmd "$1"
3363b789ec8aSmrg}
3364b789ec8aSmrg# end func_to_host_path
3365b789ec8aSmrg
3366b789ec8aSmrg
3367b789ec8aSmrg# func_convert_path_noop ARG
3368b789ec8aSmrg# Copy ARG to func_to_host_path_result.
3369b789ec8aSmrgfunc_convert_path_noop ()
3370b789ec8aSmrg{
337148e5ce07Smrg  func_to_host_path_result=$1
3372b789ec8aSmrg}
3373b789ec8aSmrg# end func_convert_path_noop
3374b789ec8aSmrg
3375b789ec8aSmrg
3376b789ec8aSmrg# func_convert_path_msys_to_w32 ARG
3377b789ec8aSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3378b789ec8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3379b789ec8aSmrg# func_to_host_path_result.
3380b789ec8aSmrgfunc_convert_path_msys_to_w32 ()
3381c27c18e8Smrg{
338248e5ce07Smrg  $debug_cmd
338348e5ce07Smrg
338448e5ce07Smrg  func_to_host_path_result=$1
3385b789ec8aSmrg  if test -n "$1"; then
3386b789ec8aSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3387b789ec8aSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3388b789ec8aSmrg    # and winepath ignores them completely.
3389b789ec8aSmrg    func_stripname : : "$1"
3390b789ec8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3391b789ec8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
339248e5ce07Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3393b789ec8aSmrg    func_convert_path_check : ";" \
3394b789ec8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3395b789ec8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3396b789ec8aSmrg  fi
3397b789ec8aSmrg}
3398b789ec8aSmrg# end func_convert_path_msys_to_w32
3399c27c18e8Smrg
3400c27c18e8Smrg
3401b789ec8aSmrg# func_convert_path_cygwin_to_w32 ARG
3402b789ec8aSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3403b789ec8aSmrg# func_to_host_file_result.
3404b789ec8aSmrgfunc_convert_path_cygwin_to_w32 ()
3405b789ec8aSmrg{
340648e5ce07Smrg  $debug_cmd
340748e5ce07Smrg
340848e5ce07Smrg  func_to_host_path_result=$1
3409b789ec8aSmrg  if test -n "$1"; then
3410b789ec8aSmrg    # See func_convert_path_msys_to_w32:
3411b789ec8aSmrg    func_stripname : : "$1"
3412b789ec8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3413b789ec8aSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3414b789ec8aSmrg    func_convert_path_check : ";" \
3415b789ec8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3416b789ec8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3417b789ec8aSmrg  fi
3418b789ec8aSmrg}
3419b789ec8aSmrg# end func_convert_path_cygwin_to_w32
3420c27c18e8Smrg
3421c27c18e8Smrg
3422b789ec8aSmrg# func_convert_path_nix_to_w32 ARG
3423b789ec8aSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3424b789ec8aSmrg# a working winepath.  Returns result in func_to_host_file_result.
3425b789ec8aSmrgfunc_convert_path_nix_to_w32 ()
3426b789ec8aSmrg{
342748e5ce07Smrg  $debug_cmd
342848e5ce07Smrg
342948e5ce07Smrg  func_to_host_path_result=$1
3430b789ec8aSmrg  if test -n "$1"; then
3431b789ec8aSmrg    # See func_convert_path_msys_to_w32:
3432b789ec8aSmrg    func_stripname : : "$1"
3433b789ec8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3434b789ec8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
343548e5ce07Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3436b789ec8aSmrg    func_convert_path_check : ";" \
3437b789ec8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3438b789ec8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3439b789ec8aSmrg  fi
3440b789ec8aSmrg}
3441b789ec8aSmrg# end func_convert_path_nix_to_w32
3442c27c18e8Smrg
3443b789ec8aSmrg
3444b789ec8aSmrg# func_convert_path_msys_to_cygwin ARG
3445b789ec8aSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3446b789ec8aSmrg# Returns result in func_to_host_file_result.
3447b789ec8aSmrgfunc_convert_path_msys_to_cygwin ()
3448b789ec8aSmrg{
344948e5ce07Smrg  $debug_cmd
345048e5ce07Smrg
345148e5ce07Smrg  func_to_host_path_result=$1
3452b789ec8aSmrg  if test -n "$1"; then
3453b789ec8aSmrg    # See func_convert_path_msys_to_w32:
3454b789ec8aSmrg    func_stripname : : "$1"
3455b789ec8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3456b789ec8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3457b789ec8aSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
345848e5ce07Smrg    func_to_host_path_result=$func_cygpath_result
3459b789ec8aSmrg    func_convert_path_check : : \
3460b789ec8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3461b789ec8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3462b789ec8aSmrg  fi
3463b789ec8aSmrg}
3464b789ec8aSmrg# end func_convert_path_msys_to_cygwin
3465b789ec8aSmrg
3466b789ec8aSmrg
3467b789ec8aSmrg# func_convert_path_nix_to_cygwin ARG
3468b789ec8aSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3469b789ec8aSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3470b789ec8aSmrg# func_to_host_file_result.
3471b789ec8aSmrgfunc_convert_path_nix_to_cygwin ()
3472b789ec8aSmrg{
347348e5ce07Smrg  $debug_cmd
347448e5ce07Smrg
347548e5ce07Smrg  func_to_host_path_result=$1
3476b789ec8aSmrg  if test -n "$1"; then
3477b789ec8aSmrg    # Remove leading and trailing path separator characters from
3478b789ec8aSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3479b789ec8aSmrg    # into '.;' and ';.', and winepath ignores them completely.
3480b789ec8aSmrg    func_stripname : : "$1"
3481b789ec8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3482b789ec8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3483b789ec8aSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
348448e5ce07Smrg    func_to_host_path_result=$func_cygpath_result
3485b789ec8aSmrg    func_convert_path_check : : \
3486b789ec8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3487b789ec8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3488b789ec8aSmrg  fi
3489c27c18e8Smrg}
3490b789ec8aSmrg# end func_convert_path_nix_to_cygwin
3491b789ec8aSmrg
3492c27c18e8Smrg
349348e5ce07Smrg# func_dll_def_p FILE
349448e5ce07Smrg# True iff FILE is a Windows DLL '.def' file.
349548e5ce07Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
349648e5ce07Smrgfunc_dll_def_p ()
349748e5ce07Smrg{
349848e5ce07Smrg  $debug_cmd
349948e5ce07Smrg
350048e5ce07Smrg  func_dll_def_p_tmp=`$SED -n \
350148e5ce07Smrg    -e 's/^[	 ]*//' \
350248e5ce07Smrg    -e '/^\(;.*\)*$/d' \
350348e5ce07Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
350448e5ce07Smrg    -e q \
350548e5ce07Smrg    "$1"`
350648e5ce07Smrg  test DEF = "$func_dll_def_p_tmp"
350748e5ce07Smrg}
350848e5ce07Smrg
350948e5ce07Smrg
3510c27c18e8Smrg# func_mode_compile arg...
3511c27c18e8Smrgfunc_mode_compile ()
3512c27c18e8Smrg{
351348e5ce07Smrg    $debug_cmd
351448e5ce07Smrg
3515c27c18e8Smrg    # Get the compilation command and the source file.
3516c27c18e8Smrg    base_compile=
351748e5ce07Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3518c27c18e8Smrg    suppress_opt=yes
3519c27c18e8Smrg    suppress_output=
3520c27c18e8Smrg    arg_mode=normal
3521c27c18e8Smrg    libobj=
3522c27c18e8Smrg    later=
3523c27c18e8Smrg    pie_flag=
3524c27c18e8Smrg
3525c27c18e8Smrg    for arg
3526c27c18e8Smrg    do
3527c27c18e8Smrg      case $arg_mode in
3528c27c18e8Smrg      arg  )
3529c27c18e8Smrg	# do not "continue".  Instead, add this to base_compile
353048e5ce07Smrg	lastarg=$arg
3531c27c18e8Smrg	arg_mode=normal
3532c27c18e8Smrg	;;
3533c27c18e8Smrg
3534c27c18e8Smrg      target )
353548e5ce07Smrg	libobj=$arg
3536c27c18e8Smrg	arg_mode=normal
3537c27c18e8Smrg	continue
3538c27c18e8Smrg	;;
3539c27c18e8Smrg
3540c27c18e8Smrg      normal )
3541c27c18e8Smrg	# Accept any command-line options.
3542c27c18e8Smrg	case $arg in
3543c27c18e8Smrg	-o)
3544c27c18e8Smrg	  test -n "$libobj" && \
354548e5ce07Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3546c27c18e8Smrg	  arg_mode=target
3547c27c18e8Smrg	  continue
3548c27c18e8Smrg	  ;;
3549c27c18e8Smrg
3550c27c18e8Smrg	-pie | -fpie | -fPIE)
3551b789ec8aSmrg          func_append pie_flag " $arg"
3552c27c18e8Smrg	  continue
3553c27c18e8Smrg	  ;;
3554c27c18e8Smrg
3555c27c18e8Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3556b789ec8aSmrg	  func_append later " $arg"
3557c27c18e8Smrg	  continue
3558c27c18e8Smrg	  ;;
3559c27c18e8Smrg
3560c27c18e8Smrg	-no-suppress)
3561c43cc173Smrg	  suppress_opt=no
3562c43cc173Smrg	  continue
3563c43cc173Smrg	  ;;
3564c43cc173Smrg
3565c43cc173Smrg	-Xcompiler)
3566c43cc173Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3567c43cc173Smrg	  continue      #  The current "srcfile" will either be retained or
3568c43cc173Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3569c43cc173Smrg
3570c43cc173Smrg	-Wc,*)
3571c27c18e8Smrg	  func_stripname '-Wc,' '' "$arg"
3572c27c18e8Smrg	  args=$func_stripname_result
3573c43cc173Smrg	  lastarg=
357448e5ce07Smrg	  save_ifs=$IFS; IFS=,
3575c27c18e8Smrg	  for arg in $args; do
357648e5ce07Smrg	    IFS=$save_ifs
3577b789ec8aSmrg	    func_append_quoted lastarg "$arg"
3578c43cc173Smrg	  done
357948e5ce07Smrg	  IFS=$save_ifs
3580c27c18e8Smrg	  func_stripname ' ' '' "$lastarg"
3581c27c18e8Smrg	  lastarg=$func_stripname_result
3582c43cc173Smrg
3583c43cc173Smrg	  # Add the arguments to base_compile.
3584b789ec8aSmrg	  func_append base_compile " $lastarg"
3585c43cc173Smrg	  continue
3586c43cc173Smrg	  ;;
3587c43cc173Smrg
3588c27c18e8Smrg	*)
3589c43cc173Smrg	  # Accept the current argument as the source file.
3590c43cc173Smrg	  # The previous "srcfile" becomes the current argument.
3591c43cc173Smrg	  #
359248e5ce07Smrg	  lastarg=$srcfile
359348e5ce07Smrg	  srcfile=$arg
3594c43cc173Smrg	  ;;
3595c43cc173Smrg	esac  #  case $arg
3596c43cc173Smrg	;;
3597c43cc173Smrg      esac    #  case $arg_mode
3598c43cc173Smrg
3599c43cc173Smrg      # Aesthetically quote the previous argument.
3600b789ec8aSmrg      func_append_quoted base_compile "$lastarg"
3601c43cc173Smrg    done # for arg
3602c43cc173Smrg
3603c43cc173Smrg    case $arg_mode in
3604c43cc173Smrg    arg)
3605c27c18e8Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3606c43cc173Smrg      ;;
3607c43cc173Smrg    target)
360848e5ce07Smrg      func_fatal_error "you must specify a target with '-o'"
3609c43cc173Smrg      ;;
3610c43cc173Smrg    *)
3611c43cc173Smrg      # Get the name of the library object.
3612c27c18e8Smrg      test -z "$libobj" && {
3613c27c18e8Smrg	func_basename "$srcfile"
361448e5ce07Smrg	libobj=$func_basename_result
3615c27c18e8Smrg      }
3616c43cc173Smrg      ;;
3617c43cc173Smrg    esac
3618c43cc173Smrg
3619c43cc173Smrg    # Recognize several different file suffixes.
3620c43cc173Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3621c43cc173Smrg    case $libobj in
3622c27c18e8Smrg    *.[cCFSifmso] | \
3623c27c18e8Smrg    *.ada | *.adb | *.ads | *.asm | \
3624c27c18e8Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3625f1ee322dSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3626c27c18e8Smrg      func_xform "$libobj"
3627c27c18e8Smrg      libobj=$func_xform_result
3628c27c18e8Smrg      ;;
3629c43cc173Smrg    esac
3630c43cc173Smrg
3631c43cc173Smrg    case $libobj in
3632c27c18e8Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3633c43cc173Smrg    *)
363448e5ce07Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3635c43cc173Smrg      ;;
3636c43cc173Smrg    esac
3637c43cc173Smrg
3638c43cc173Smrg    func_infer_tag $base_compile
3639c43cc173Smrg
3640c43cc173Smrg    for arg in $later; do
3641c43cc173Smrg      case $arg in
3642c27c18e8Smrg      -shared)
364348e5ce07Smrg	test yes = "$build_libtool_libs" \
364448e5ce07Smrg	  || func_fatal_configuration "cannot build a shared library"
3645c27c18e8Smrg	build_old_libs=no
3646c27c18e8Smrg	continue
3647c27c18e8Smrg	;;
3648c27c18e8Smrg
3649c43cc173Smrg      -static)
3650c27c18e8Smrg	build_libtool_libs=no
3651c43cc173Smrg	build_old_libs=yes
3652c43cc173Smrg	continue
3653c43cc173Smrg	;;
3654c43cc173Smrg
3655c43cc173Smrg      -prefer-pic)
3656c43cc173Smrg	pic_mode=yes
3657c43cc173Smrg	continue
3658c43cc173Smrg	;;
3659c43cc173Smrg
3660c43cc173Smrg      -prefer-non-pic)
3661c43cc173Smrg	pic_mode=no
3662c43cc173Smrg	continue
3663c43cc173Smrg	;;
3664c43cc173Smrg      esac
3665c43cc173Smrg    done
3666c43cc173Smrg
36674e8f48c7Smrg    func_quote_arg pretty "$libobj"
36684e8f48c7Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3669c27c18e8Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
367048e5ce07Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3671c27c18e8Smrg    func_dirname_and_basename "$obj" "/" ""
367248e5ce07Smrg    objname=$func_basename_result
367348e5ce07Smrg    xdir=$func_dirname_result
367448e5ce07Smrg    lobj=$xdir$objdir/$objname
3675c43cc173Smrg
3676c27c18e8Smrg    test -z "$base_compile" && \
3677c27c18e8Smrg      func_fatal_help "you must specify a compilation command"
3678c43cc173Smrg
3679c43cc173Smrg    # Delete any leftover library objects.
368048e5ce07Smrg    if test yes = "$build_old_libs"; then
3681c43cc173Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3682c43cc173Smrg    else
3683c43cc173Smrg      removelist="$lobj $libobj ${libobj}T"
3684c43cc173Smrg    fi
3685c43cc173Smrg
3686c43cc173Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3687c43cc173Smrg    case $host_os in
3688c27c18e8Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3689c43cc173Smrg      pic_mode=default
3690c43cc173Smrg      ;;
3691c43cc173Smrg    esac
369248e5ce07Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3693c43cc173Smrg      # non-PIC code in shared libraries is not supported
3694c43cc173Smrg      pic_mode=default
3695c43cc173Smrg    fi
3696c43cc173Smrg
3697c43cc173Smrg    # Calculate the filename of the output object if compiler does
3698c43cc173Smrg    # not support -o with -c
369948e5ce07Smrg    if test no = "$compiler_c_o"; then
370048e5ce07Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
370148e5ce07Smrg      lockfile=$output_obj.lock
3702c43cc173Smrg    else
3703c43cc173Smrg      output_obj=
3704c43cc173Smrg      need_locks=no
3705c43cc173Smrg      lockfile=
3706c43cc173Smrg    fi
3707c43cc173Smrg
3708c43cc173Smrg    # Lock this critical section if it is needed
3709c43cc173Smrg    # We use this script file to make the link, it avoids creating a new file
371048e5ce07Smrg    if test yes = "$need_locks"; then
3711c27c18e8Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3712c27c18e8Smrg	func_echo "Waiting for $lockfile to be removed"
3713c43cc173Smrg	sleep 2
3714c43cc173Smrg      done
371548e5ce07Smrg    elif test warn = "$need_locks"; then
3716c43cc173Smrg      if test -f "$lockfile"; then
3717c27c18e8Smrg	$ECHO "\
3718c43cc173Smrg*** ERROR, $lockfile exists and contains:
3719c43cc173Smrg`cat $lockfile 2>/dev/null`
3720c43cc173Smrg
3721c43cc173SmrgThis indicates that another process is trying to use the same
3722c43cc173Smrgtemporary object file, and libtool could not work around it because
372348e5ce07Smrgyour compiler does not support '-c' and '-o' together.  If you
3724c43cc173Smrgrepeat this compilation, it may succeed, by chance, but you had better
3725c43cc173Smrgavoid parallel builds (make -j) in this platform, or get a better
3726c43cc173Smrgcompiler."
3727c43cc173Smrg
3728c27c18e8Smrg	$opt_dry_run || $RM $removelist
3729c43cc173Smrg	exit $EXIT_FAILURE
3730c43cc173Smrg      fi
3731b789ec8aSmrg      func_append removelist " $output_obj"
3732c27c18e8Smrg      $ECHO "$srcfile" > "$lockfile"
3733c43cc173Smrg    fi
3734c43cc173Smrg
3735c27c18e8Smrg    $opt_dry_run || $RM $removelist
3736b789ec8aSmrg    func_append removelist " $lockfile"
3737c27c18e8Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3738c27c18e8Smrg
3739b789ec8aSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3740b789ec8aSmrg    srcfile=$func_to_tool_file_result
37414e8f48c7Smrg    func_quote_arg pretty "$srcfile"
37424e8f48c7Smrg    qsrcfile=$func_quote_arg_result
3743c43cc173Smrg
3744c43cc173Smrg    # Only build a PIC object if we are building libtool libraries.
374548e5ce07Smrg    if test yes = "$build_libtool_libs"; then
3746c43cc173Smrg      # Without this assignment, base_compile gets emptied.
3747c43cc173Smrg      fbsd_hideous_sh_bug=$base_compile
3748c43cc173Smrg
374948e5ce07Smrg      if test no != "$pic_mode"; then
3750c43cc173Smrg	command="$base_compile $qsrcfile $pic_flag"
3751c43cc173Smrg      else
3752c43cc173Smrg	# Don't build PIC code
3753c43cc173Smrg	command="$base_compile $qsrcfile"
3754c43cc173Smrg      fi
3755c43cc173Smrg
3756c27c18e8Smrg      func_mkdir_p "$xdir$objdir"
3757c43cc173Smrg
3758c43cc173Smrg      if test -z "$output_obj"; then
3759c43cc173Smrg	# Place PIC objects in $objdir
3760b789ec8aSmrg	func_append command " -o $lobj"
3761c43cc173Smrg      fi
3762c43cc173Smrg
3763c27c18e8Smrg      func_show_eval_locale "$command"	\
3764c27c18e8Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3765c43cc173Smrg
376648e5ce07Smrg      if test warn = "$need_locks" &&
3767c43cc173Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3768c27c18e8Smrg	$ECHO "\
3769c43cc173Smrg*** ERROR, $lockfile contains:
3770c43cc173Smrg`cat $lockfile 2>/dev/null`
3771c43cc173Smrg
3772c43cc173Smrgbut it should contain:
3773c43cc173Smrg$srcfile
3774c43cc173Smrg
3775c43cc173SmrgThis indicates that another process is trying to use the same
3776c43cc173Smrgtemporary object file, and libtool could not work around it because
377748e5ce07Smrgyour compiler does not support '-c' and '-o' together.  If you
3778c43cc173Smrgrepeat this compilation, it may succeed, by chance, but you had better
3779c43cc173Smrgavoid parallel builds (make -j) in this platform, or get a better
3780c43cc173Smrgcompiler."
3781c43cc173Smrg
3782c27c18e8Smrg	$opt_dry_run || $RM $removelist
3783c43cc173Smrg	exit $EXIT_FAILURE
3784c43cc173Smrg      fi
3785c43cc173Smrg
3786c43cc173Smrg      # Just move the object if needed, then go on to compile the next one
3787c43cc173Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3788c27c18e8Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3789c27c18e8Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3790c43cc173Smrg      fi
3791c43cc173Smrg
3792c43cc173Smrg      # Allow error messages only from the first compilation.
379348e5ce07Smrg      if test yes = "$suppress_opt"; then
3794c27c18e8Smrg	suppress_output=' >/dev/null 2>&1'
3795c43cc173Smrg      fi
3796c43cc173Smrg    fi
3797c43cc173Smrg
3798c43cc173Smrg    # Only build a position-dependent object if we build old libraries.
379948e5ce07Smrg    if test yes = "$build_old_libs"; then
380048e5ce07Smrg      if test yes != "$pic_mode"; then
3801c43cc173Smrg	# Don't build PIC code
3802c27c18e8Smrg	command="$base_compile $qsrcfile$pie_flag"
3803c43cc173Smrg      else
3804c43cc173Smrg	command="$base_compile $qsrcfile $pic_flag"
3805c43cc173Smrg      fi
380648e5ce07Smrg      if test yes = "$compiler_c_o"; then
3807b789ec8aSmrg	func_append command " -o $obj"
3808c43cc173Smrg      fi
3809c43cc173Smrg
3810c43cc173Smrg      # Suppress compiler output if we already did a PIC compilation.
3811b789ec8aSmrg      func_append command "$suppress_output"
3812c27c18e8Smrg      func_show_eval_locale "$command" \
3813c27c18e8Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3814c43cc173Smrg
381548e5ce07Smrg      if test warn = "$need_locks" &&
3816c43cc173Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3817c27c18e8Smrg	$ECHO "\
3818c43cc173Smrg*** ERROR, $lockfile contains:
3819c43cc173Smrg`cat $lockfile 2>/dev/null`
3820c43cc173Smrg
3821c43cc173Smrgbut it should contain:
3822c43cc173Smrg$srcfile
3823c43cc173Smrg
3824c43cc173SmrgThis indicates that another process is trying to use the same
3825c43cc173Smrgtemporary object file, and libtool could not work around it because
382648e5ce07Smrgyour compiler does not support '-c' and '-o' together.  If you
3827c43cc173Smrgrepeat this compilation, it may succeed, by chance, but you had better
3828c43cc173Smrgavoid parallel builds (make -j) in this platform, or get a better
3829c43cc173Smrgcompiler."
3830c43cc173Smrg
3831c27c18e8Smrg	$opt_dry_run || $RM $removelist
3832c43cc173Smrg	exit $EXIT_FAILURE
3833c43cc173Smrg      fi
3834c43cc173Smrg
3835c43cc173Smrg      # Just move the object if needed
3836c43cc173Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3837c27c18e8Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3838c27c18e8Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3839c43cc173Smrg      fi
3840c43cc173Smrg    fi
3841c43cc173Smrg
3842c27c18e8Smrg    $opt_dry_run || {
3843c27c18e8Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3844c43cc173Smrg
3845c27c18e8Smrg      # Unlock the critical section if it was locked
384648e5ce07Smrg      if test no != "$need_locks"; then
3847c27c18e8Smrg	removelist=$lockfile
3848c27c18e8Smrg        $RM "$lockfile"
3849c27c18e8Smrg      fi
3850c27c18e8Smrg    }
3851c43cc173Smrg
3852c43cc173Smrg    exit $EXIT_SUCCESS
3853c27c18e8Smrg}
3854c43cc173Smrg
3855c27c18e8Smrg$opt_help || {
385648e5ce07Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3857c27c18e8Smrg}
3858c43cc173Smrg
3859c27c18e8Smrgfunc_mode_help ()
3860c27c18e8Smrg{
3861c27c18e8Smrg    # We need to display help for each of the modes.
3862b789ec8aSmrg    case $opt_mode in
3863c27c18e8Smrg      "")
3864c27c18e8Smrg        # Generic help is extracted from the usage comments
3865c27c18e8Smrg        # at the start of this file.
3866c27c18e8Smrg        func_help
3867c27c18e8Smrg        ;;
3868c43cc173Smrg
3869c27c18e8Smrg      clean)
3870c27c18e8Smrg        $ECHO \
3871c27c18e8Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3872c43cc173Smrg
3873c27c18e8SmrgRemove files from the build directory.
3874c43cc173Smrg
3875c27c18e8SmrgRM is the name of the program to use to delete files associated with each FILE
387648e5ce07Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3877c27c18e8Smrgto RM.
3878c43cc173Smrg
3879c27c18e8SmrgIf FILE is a libtool library, object or program, all the files associated
3880c27c18e8Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3881c27c18e8Smrg        ;;
3882c43cc173Smrg
3883c27c18e8Smrg      compile)
3884c27c18e8Smrg      $ECHO \
3885c27c18e8Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3886c43cc173Smrg
3887c27c18e8SmrgCompile a source file into a libtool library object.
3888c43cc173Smrg
3889c27c18e8SmrgThis mode accepts the following additional options:
3890c43cc173Smrg
3891c27c18e8Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3892c27c18e8Smrg  -no-suppress      do not suppress compiler output for multiple passes
389337eb1ca1Smrg  -prefer-pic       try to build PIC objects only
389437eb1ca1Smrg  -prefer-non-pic   try to build non-PIC objects only
389548e5ce07Smrg  -shared           do not build a '.o' file suitable for static linking
389648e5ce07Smrg  -static           only build a '.o' file suitable for static linking
38974e8f48c7Smrg  -Wc,FLAG
38984e8f48c7Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3899c43cc173Smrg
390048e5ce07SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3901c27c18e8Smrgfrom the given SOURCEFILE.
3902c43cc173Smrg
3903c27c18e8SmrgThe output file name is determined by removing the directory component from
390448e5ce07SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
390548e5ce07Smrglibrary object suffix, '.lo'."
3906c27c18e8Smrg        ;;
3907c43cc173Smrg
3908c27c18e8Smrg      execute)
3909c27c18e8Smrg        $ECHO \
3910c27c18e8Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3911c43cc173Smrg
3912c27c18e8SmrgAutomatically set library path, then run a program.
3913c43cc173Smrg
3914c27c18e8SmrgThis mode accepts the following additional options:
3915c43cc173Smrg
3916c27c18e8Smrg  -dlopen FILE      add the directory containing FILE to the library path
3917c43cc173Smrg
391848e5ce07SmrgThis mode sets the library path environment variable according to '-dlopen'
3919c27c18e8Smrgflags.
3920c43cc173Smrg
3921c27c18e8SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3922c27c18e8Smrginto their corresponding uninstalled binary, and any of their required library
3923c27c18e8Smrgdirectories are added to the library path.
3924c43cc173Smrg
3925c27c18e8SmrgThen, COMMAND is executed, with ARGS as arguments."
3926c27c18e8Smrg        ;;
3927c43cc173Smrg
3928c27c18e8Smrg      finish)
3929c27c18e8Smrg        $ECHO \
3930c27c18e8Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3931c43cc173Smrg
3932c27c18e8SmrgComplete the installation of libtool libraries.
3933c43cc173Smrg
3934c27c18e8SmrgEach LIBDIR is a directory that contains libtool libraries.
3935c43cc173Smrg
3936c27c18e8SmrgThe commands that this mode executes may require superuser privileges.  Use
393748e5ce07Smrgthe '--dry-run' option if you just want to see what would be executed."
3938c27c18e8Smrg        ;;
3939c43cc173Smrg
3940c27c18e8Smrg      install)
3941c27c18e8Smrg        $ECHO \
3942c27c18e8Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3943c43cc173Smrg
3944c27c18e8SmrgInstall executables or libraries.
3945c43cc173Smrg
3946c27c18e8SmrgINSTALL-COMMAND is the installation command.  The first component should be
394748e5ce07Smrgeither the 'install' or 'cp' program.
3948c43cc173Smrg
3949c27c18e8SmrgThe following components of INSTALL-COMMAND are treated specially:
3950c43cc173Smrg
395137eb1ca1Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3952c43cc173Smrg
3953c27c18e8SmrgThe rest of the components are interpreted as arguments to that command (only
3954c27c18e8SmrgBSD-compatible install options are recognized)."
3955c27c18e8Smrg        ;;
3956c43cc173Smrg
3957c27c18e8Smrg      link)
3958c27c18e8Smrg        $ECHO \
3959c27c18e8Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3960c43cc173Smrg
3961c27c18e8SmrgLink object files or libraries together to form another library, or to
3962c27c18e8Smrgcreate an executable program.
3963c43cc173Smrg
3964c27c18e8SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3965c27c18e8Smrga program from several object files.
3966c43cc173Smrg
3967c27c18e8SmrgThe following components of LINK-COMMAND are treated specially:
3968c43cc173Smrg
3969c27c18e8Smrg  -all-static       do not do any dynamic linking at all
3970c27c18e8Smrg  -avoid-version    do not add a version suffix if possible
397137eb1ca1Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397237eb1ca1Smrg                    libraries must be found in the PATH setting at runtime)
397348e5ce07Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3974c27c18e8Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3975c27c18e8Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3976c27c18e8Smrg  -export-symbols SYMFILE
3977c27c18e8Smrg                    try to export only the symbols listed in SYMFILE
3978c27c18e8Smrg  -export-symbols-regex REGEX
3979c27c18e8Smrg                    try to export only the symbols matching REGEX
3980c27c18e8Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3981c27c18e8Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3982c27c18e8Smrg  -module           build a library that can dlopened
3983c27c18e8Smrg  -no-fast-install  disable the fast-install mode
3984c27c18e8Smrg  -no-install       link a not-installable executable
3985c27c18e8Smrg  -no-undefined     declare that a library does not refer to external symbols
3986c27c18e8Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
398748e5ce07Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
398848e5ce07Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3989c27c18e8Smrg  -precious-files-regex REGEX
3990c27c18e8Smrg                    don't remove output files matching REGEX
3991c27c18e8Smrg  -release RELEASE  specify package release information
3992c27c18e8Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3993c27c18e8Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3994c27c18e8Smrg  -shared           only do dynamic linking of libtool libraries
3995c27c18e8Smrg  -shrext SUFFIX    override the standard shared library file extension
3996c27c18e8Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
3997c27c18e8Smrg  -static-libtool-libs
3998c27c18e8Smrg                    do not do any dynamic linking of libtool libraries
3999c27c18e8Smrg  -version-info CURRENT[:REVISION[:AGE]]
4000c27c18e8Smrg                    specify library version info [each variable defaults to 0]
4001c27c18e8Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400237eb1ca1Smrg  -Wc,FLAG
400337eb1ca1Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
40044e8f48c7Smrg  -Wa,FLAG
40054e8f48c7Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
400637eb1ca1Smrg  -Wl,FLAG
400737eb1ca1Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
400837eb1ca1Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4009c43cc173Smrg
401048e5ce07SmrgAll other options (arguments beginning with '-') are ignored.
4011c43cc173Smrg
401248e5ce07SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4013c27c18e8Smrgtreated as uninstalled libtool libraries, other files are standard or library
4014c27c18e8Smrgobject files.
4015c43cc173Smrg
401648e5ce07SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
401748e5ce07Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4018c27c18e8Smrgrequired, except when creating a convenience library.
4019c43cc173Smrg
402048e5ce07SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
402148e5ce07Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4022c43cc173Smrg
402348e5ce07SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4024c27c18e8Smrgis created, otherwise an executable program is created."
4025c43cc173Smrg        ;;
4026c43cc173Smrg
4027c27c18e8Smrg      uninstall)
4028c27c18e8Smrg        $ECHO \
4029c27c18e8Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4030c43cc173Smrg
4031c27c18e8SmrgRemove libraries from an installation directory.
4032c43cc173Smrg
4033c27c18e8SmrgRM is the name of the program to use to delete files associated with each FILE
403448e5ce07Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4035c27c18e8Smrgto RM.
4036c43cc173Smrg
4037c27c18e8SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4038c27c18e8SmrgOtherwise, only FILE itself is deleted using RM."
4039c27c18e8Smrg        ;;
4040c43cc173Smrg
4041c27c18e8Smrg      *)
404248e5ce07Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
4043c27c18e8Smrg        ;;
4044c27c18e8Smrg    esac
4045c43cc173Smrg
404637eb1ca1Smrg    echo
404748e5ce07Smrg    $ECHO "Try '$progname --help' for more information about other modes."
4048c27c18e8Smrg}
4049c43cc173Smrg
405037eb1ca1Smrg# Now that we've collected a possible --mode arg, show help if necessary
405137eb1ca1Smrgif $opt_help; then
405248e5ce07Smrg  if test : = "$opt_help"; then
405337eb1ca1Smrg    func_mode_help
405437eb1ca1Smrg  else
405537eb1ca1Smrg    {
405637eb1ca1Smrg      func_help noexit
4057b789ec8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
405837eb1ca1Smrg	func_mode_help
405937eb1ca1Smrg      done
406048e5ce07Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406137eb1ca1Smrg    {
406237eb1ca1Smrg      func_help noexit
4063b789ec8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
406437eb1ca1Smrg	echo
406537eb1ca1Smrg	func_mode_help
406637eb1ca1Smrg      done
406737eb1ca1Smrg    } |
406848e5ce07Smrg    $SED '1d
406937eb1ca1Smrg      /^When reporting/,/^Report/{
407037eb1ca1Smrg	H
407137eb1ca1Smrg	d
407237eb1ca1Smrg      }
407337eb1ca1Smrg      $x
407437eb1ca1Smrg      /information about other modes/d
407537eb1ca1Smrg      /more detailed .*MODE/d
407637eb1ca1Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
407737eb1ca1Smrg  fi
407837eb1ca1Smrg  exit $?
407937eb1ca1Smrgfi
4080c43cc173Smrg
4081c43cc173Smrg
4082c27c18e8Smrg# func_mode_execute arg...
4083c27c18e8Smrgfunc_mode_execute ()
4084c27c18e8Smrg{
408548e5ce07Smrg    $debug_cmd
408648e5ce07Smrg
4087c27c18e8Smrg    # The first argument is the command name.
408848e5ce07Smrg    cmd=$nonopt
4089c27c18e8Smrg    test -z "$cmd" && \
4090c27c18e8Smrg      func_fatal_help "you must specify a COMMAND"
4091c43cc173Smrg
4092c27c18e8Smrg    # Handle -dlopen flags immediately.
4093b789ec8aSmrg    for file in $opt_dlopen; do
4094c27c18e8Smrg      test -f "$file" \
409548e5ce07Smrg	|| func_fatal_help "'$file' is not a file"
4096c43cc173Smrg
4097c27c18e8Smrg      dir=
4098c27c18e8Smrg      case $file in
4099c27c18e8Smrg      *.la)
4100b789ec8aSmrg	func_resolve_sysroot "$file"
4101b789ec8aSmrg	file=$func_resolve_sysroot_result
4102b789ec8aSmrg
4103c27c18e8Smrg	# Check to see that this really is a libtool archive.
4104c27c18e8Smrg	func_lalib_unsafe_p "$file" \
410548e5ce07Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4106c43cc173Smrg
4107c27c18e8Smrg	# Read the libtool library.
4108c27c18e8Smrg	dlname=
4109c27c18e8Smrg	library_names=
4110c27c18e8Smrg	func_source "$file"
4111c43cc173Smrg
4112c27c18e8Smrg	# Skip this library if it cannot be dlopened.
4113c27c18e8Smrg	if test -z "$dlname"; then
4114c27c18e8Smrg	  # Warn if it was a shared library.
4115c27c18e8Smrg	  test -n "$library_names" && \
411648e5ce07Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4117c27c18e8Smrg	  continue
4118c27c18e8Smrg	fi
4119c43cc173Smrg
4120c27c18e8Smrg	func_dirname "$file" "" "."
412148e5ce07Smrg	dir=$func_dirname_result
4122c43cc173Smrg
4123c27c18e8Smrg	if test -f "$dir/$objdir/$dlname"; then
4124b789ec8aSmrg	  func_append dir "/$objdir"
4125c27c18e8Smrg	else
4126c27c18e8Smrg	  if test ! -f "$dir/$dlname"; then
412748e5ce07Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4128c27c18e8Smrg	  fi
4129c27c18e8Smrg	fi
4130c43cc173Smrg	;;
4131c43cc173Smrg
4132c27c18e8Smrg      *.lo)
4133c27c18e8Smrg	# Just add the directory containing the .lo file.
4134c27c18e8Smrg	func_dirname "$file" "" "."
413548e5ce07Smrg	dir=$func_dirname_result
4136c43cc173Smrg	;;
4137c43cc173Smrg
4138c27c18e8Smrg      *)
413948e5ce07Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4140c43cc173Smrg	continue
4141c43cc173Smrg	;;
4142c27c18e8Smrg      esac
4143c43cc173Smrg
4144c27c18e8Smrg      # Get the absolute pathname.
4145c27c18e8Smrg      absdir=`cd "$dir" && pwd`
414648e5ce07Smrg      test -n "$absdir" && dir=$absdir
4147c43cc173Smrg
4148c27c18e8Smrg      # Now add the directory to shlibpath_var.
4149c27c18e8Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4150c27c18e8Smrg	eval "$shlibpath_var=\"\$dir\""
4151c27c18e8Smrg      else
4152c27c18e8Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4153c27c18e8Smrg      fi
4154c27c18e8Smrg    done
4155c43cc173Smrg
4156c27c18e8Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4157c27c18e8Smrg    # rather than running their programs.
415848e5ce07Smrg    libtool_execute_magic=$magic
4159c43cc173Smrg
4160c27c18e8Smrg    # Check if any of the arguments is a wrapper script.
4161c27c18e8Smrg    args=
4162c27c18e8Smrg    for file
4163c27c18e8Smrg    do
4164c27c18e8Smrg      case $file in
416537eb1ca1Smrg      -* | *.la | *.lo ) ;;
4166c27c18e8Smrg      *)
4167c27c18e8Smrg	# Do a test to see if this is really a libtool program.
4168c27c18e8Smrg	if func_ltwrapper_script_p "$file"; then
4169c27c18e8Smrg	  func_source "$file"
4170c27c18e8Smrg	  # Transform arg to wrapped name.
417148e5ce07Smrg	  file=$progdir/$program
4172c27c18e8Smrg	elif func_ltwrapper_executable_p "$file"; then
4173c27c18e8Smrg	  func_ltwrapper_scriptname "$file"
4174c27c18e8Smrg	  func_source "$func_ltwrapper_scriptname_result"
4175c27c18e8Smrg	  # Transform arg to wrapped name.
417648e5ce07Smrg	  file=$progdir/$program
4177c27c18e8Smrg	fi
4178c27c18e8Smrg	;;
4179c27c18e8Smrg      esac
4180c27c18e8Smrg      # Quote arguments (to preserve shell metacharacters).
4181b789ec8aSmrg      func_append_quoted args "$file"
4182c27c18e8Smrg    done
4183c43cc173Smrg
418448e5ce07Smrg    if $opt_dry_run; then
418548e5ce07Smrg      # Display what would be done.
418648e5ce07Smrg      if test -n "$shlibpath_var"; then
418748e5ce07Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
418848e5ce07Smrg	echo "export $shlibpath_var"
418948e5ce07Smrg      fi
419048e5ce07Smrg      $ECHO "$cmd$args"
419148e5ce07Smrg      exit $EXIT_SUCCESS
419248e5ce07Smrg    else
4193c27c18e8Smrg      if test -n "$shlibpath_var"; then
4194c27c18e8Smrg	# Export the shlibpath_var.
4195c27c18e8Smrg	eval "export $shlibpath_var"
4196c27c18e8Smrg      fi
4197c43cc173Smrg
4198c27c18e8Smrg      # Restore saved environment variables
4199c27c18e8Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4200c27c18e8Smrg      do
4201c27c18e8Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4202c27c18e8Smrg                $lt_var=\$save_$lt_var; export $lt_var
4203c43cc173Smrg	      else
4204c27c18e8Smrg		$lt_unset $lt_var
4205c27c18e8Smrg	      fi"
4206c27c18e8Smrg      done
4207c43cc173Smrg
4208c27c18e8Smrg      # Now prepare to actually exec the command.
420948e5ce07Smrg      exec_cmd=\$cmd$args
4210c27c18e8Smrg    fi
4211c27c18e8Smrg}
4212c43cc173Smrg
421348e5ce07Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4214c43cc173Smrg
4215c43cc173Smrg
4216c27c18e8Smrg# func_mode_finish arg...
4217c27c18e8Smrgfunc_mode_finish ()
4218c27c18e8Smrg{
421948e5ce07Smrg    $debug_cmd
422048e5ce07Smrg
4221b789ec8aSmrg    libs=
4222b789ec8aSmrg    libdirs=
4223c27c18e8Smrg    admincmds=
4224c43cc173Smrg
4225b789ec8aSmrg    for opt in "$nonopt" ${1+"$@"}
4226b789ec8aSmrg    do
4227b789ec8aSmrg      if test -d "$opt"; then
4228b789ec8aSmrg	func_append libdirs " $opt"
4229b789ec8aSmrg
4230b789ec8aSmrg      elif test -f "$opt"; then
4231b789ec8aSmrg	if func_lalib_unsafe_p "$opt"; then
4232b789ec8aSmrg	  func_append libs " $opt"
4233b789ec8aSmrg	else
423448e5ce07Smrg	  func_warning "'$opt' is not a valid libtool archive"
4235b789ec8aSmrg	fi
4236b789ec8aSmrg
4237b789ec8aSmrg      else
423848e5ce07Smrg	func_fatal_error "invalid argument '$opt'"
4239b789ec8aSmrg      fi
4240b789ec8aSmrg    done
4241b789ec8aSmrg
4242b789ec8aSmrg    if test -n "$libs"; then
4243b789ec8aSmrg      if test -n "$lt_sysroot"; then
4244b789ec8aSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4245b789ec8aSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4246b789ec8aSmrg      else
4247b789ec8aSmrg        sysroot_cmd=
4248b789ec8aSmrg      fi
4249b789ec8aSmrg
4250b789ec8aSmrg      # Remove sysroot references
4251b789ec8aSmrg      if $opt_dry_run; then
4252b789ec8aSmrg        for lib in $libs; do
425348e5ce07Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4254b789ec8aSmrg        done
4255b789ec8aSmrg      else
4256b789ec8aSmrg        tmpdir=`func_mktempdir`
4257b789ec8aSmrg        for lib in $libs; do
425848e5ce07Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4259b789ec8aSmrg	    > $tmpdir/tmp-la
4260b789ec8aSmrg	  mv -f $tmpdir/tmp-la $lib
4261b789ec8aSmrg	done
4262b789ec8aSmrg        ${RM}r "$tmpdir"
4263b789ec8aSmrg      fi
4264b789ec8aSmrg    fi
4265c43cc173Smrg
4266b789ec8aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4267c27c18e8Smrg      for libdir in $libdirs; do
4268c27c18e8Smrg	if test -n "$finish_cmds"; then
4269c27c18e8Smrg	  # Do each command in the finish commands.
4270c27c18e8Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4271c27c18e8Smrg'"$cmd"'"'
4272c43cc173Smrg	fi
4273c27c18e8Smrg	if test -n "$finish_eval"; then
4274c27c18e8Smrg	  # Do the single finish_eval.
4275c27c18e8Smrg	  eval cmds=\"$finish_eval\"
4276b789ec8aSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4277c27c18e8Smrg       $cmds"
4278c27c18e8Smrg	fi
4279c27c18e8Smrg      done
4280c27c18e8Smrg    fi
4281c43cc173Smrg
4282c27c18e8Smrg    # Exit here if they wanted silent mode.
428348e5ce07Smrg    $opt_quiet && exit $EXIT_SUCCESS
4284c43cc173Smrg
4285b789ec8aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4286b789ec8aSmrg      echo "----------------------------------------------------------------------"
4287b789ec8aSmrg      echo "Libraries have been installed in:"
4288b789ec8aSmrg      for libdir in $libdirs; do
4289b789ec8aSmrg	$ECHO "   $libdir"
4290b789ec8aSmrg      done
4291b789ec8aSmrg      echo
4292b789ec8aSmrg      echo "If you ever happen to want to link against installed libraries"
4293b789ec8aSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
429448e5ce07Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4295b789ec8aSmrg      echo "flag during linking and do at least one of the following:"
4296b789ec8aSmrg      if test -n "$shlibpath_var"; then
429748e5ce07Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4298b789ec8aSmrg	echo "     during execution"
4299b789ec8aSmrg      fi
4300b789ec8aSmrg      if test -n "$runpath_var"; then
430148e5ce07Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4302b789ec8aSmrg	echo "     during linking"
4303b789ec8aSmrg      fi
4304b789ec8aSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4305b789ec8aSmrg	libdir=LIBDIR
4306b789ec8aSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4307c43cc173Smrg
430848e5ce07Smrg	$ECHO "   - use the '$flag' linker flag"
4309b789ec8aSmrg      fi
4310b789ec8aSmrg      if test -n "$admincmds"; then
4311b789ec8aSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4312b789ec8aSmrg      fi
4313b789ec8aSmrg      if test -f /etc/ld.so.conf; then
431448e5ce07Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4315b789ec8aSmrg      fi
4316b789ec8aSmrg      echo
4317c27c18e8Smrg
4318b789ec8aSmrg      echo "See any operating system documentation about shared libraries for"
4319b789ec8aSmrg      case $host in
4320b789ec8aSmrg	solaris2.[6789]|solaris2.1[0-9])
4321b789ec8aSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4322b789ec8aSmrg	  echo "pages."
4323b789ec8aSmrg	  ;;
4324b789ec8aSmrg	*)
4325b789ec8aSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4326b789ec8aSmrg	  ;;
4327b789ec8aSmrg      esac
4328b789ec8aSmrg      echo "----------------------------------------------------------------------"
4329b789ec8aSmrg    fi
4330c27c18e8Smrg    exit $EXIT_SUCCESS
4331c27c18e8Smrg}
4332c27c18e8Smrg
433348e5ce07Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4334c27c18e8Smrg
4335c27c18e8Smrg
4336c27c18e8Smrg# func_mode_install arg...
4337c27c18e8Smrgfunc_mode_install ()
4338c27c18e8Smrg{
433948e5ce07Smrg    $debug_cmd
434048e5ce07Smrg
4341c27c18e8Smrg    # There may be an optional sh(1) argument at the beginning of
4342c27c18e8Smrg    # install_prog (especially on Windows NT).
434348e5ce07Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4344c27c18e8Smrg       # Allow the use of GNU shtool's install command.
434548e5ce07Smrg       case $nonopt in *shtool*) :;; *) false;; esac
434648e5ce07Smrg    then
4347c27c18e8Smrg      # Aesthetically quote it.
43484e8f48c7Smrg      func_quote_arg pretty "$nonopt"
43494e8f48c7Smrg      install_prog="$func_quote_arg_result "
4350c27c18e8Smrg      arg=$1
4351c27c18e8Smrg      shift
4352c27c18e8Smrg    else
4353c27c18e8Smrg      install_prog=
4354c27c18e8Smrg      arg=$nonopt
4355c27c18e8Smrg    fi
4356c27c18e8Smrg
4357c27c18e8Smrg    # The real first argument should be the name of the installation program.
4358c27c18e8Smrg    # Aesthetically quote it.
43594e8f48c7Smrg    func_quote_arg pretty "$arg"
43604e8f48c7Smrg    func_append install_prog "$func_quote_arg_result"
436137eb1ca1Smrg    install_shared_prog=$install_prog
436237eb1ca1Smrg    case " $install_prog " in
436337eb1ca1Smrg      *[\\\ /]cp\ *) install_cp=: ;;
436437eb1ca1Smrg      *) install_cp=false ;;
436537eb1ca1Smrg    esac
4366c27c18e8Smrg
4367c27c18e8Smrg    # We need to accept at least all the BSD install flags.
4368c27c18e8Smrg    dest=
4369c27c18e8Smrg    files=
4370c27c18e8Smrg    opts=
4371c27c18e8Smrg    prev=
4372c27c18e8Smrg    install_type=
437348e5ce07Smrg    isdir=false
4374c27c18e8Smrg    stripme=
437537eb1ca1Smrg    no_mode=:
4376c27c18e8Smrg    for arg
4377c27c18e8Smrg    do
437837eb1ca1Smrg      arg2=
4379c27c18e8Smrg      if test -n "$dest"; then
4380b789ec8aSmrg	func_append files " $dest"
4381c27c18e8Smrg	dest=$arg
4382c27c18e8Smrg	continue
4383c27c18e8Smrg      fi
4384c27c18e8Smrg
4385c27c18e8Smrg      case $arg in
438648e5ce07Smrg      -d) isdir=: ;;
4387c27c18e8Smrg      -f)
438837eb1ca1Smrg	if $install_cp; then :; else
438937eb1ca1Smrg	  prev=$arg
439037eb1ca1Smrg	fi
4391c27c18e8Smrg	;;
4392c27c18e8Smrg      -g | -m | -o)
4393c27c18e8Smrg	prev=$arg
4394c27c18e8Smrg	;;
4395c27c18e8Smrg      -s)
4396c27c18e8Smrg	stripme=" -s"
4397c27c18e8Smrg	continue
4398c27c18e8Smrg	;;
4399c27c18e8Smrg      -*)
4400c27c18e8Smrg	;;
4401c27c18e8Smrg      *)
4402c27c18e8Smrg	# If the previous option needed an argument, then skip it.
4403c27c18e8Smrg	if test -n "$prev"; then
440448e5ce07Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
440537eb1ca1Smrg	    arg2=$install_override_mode
440637eb1ca1Smrg	    no_mode=false
440737eb1ca1Smrg	  fi
4408c43cc173Smrg	  prev=
4409c43cc173Smrg	else
4410c27c18e8Smrg	  dest=$arg
4411c27c18e8Smrg	  continue
4412c43cc173Smrg	fi
4413c43cc173Smrg	;;
4414c27c18e8Smrg      esac
4415c43cc173Smrg
4416c27c18e8Smrg      # Aesthetically quote the argument.
44174e8f48c7Smrg      func_quote_arg pretty "$arg"
44184e8f48c7Smrg      func_append install_prog " $func_quote_arg_result"
441937eb1ca1Smrg      if test -n "$arg2"; then
44204e8f48c7Smrg	func_quote_arg pretty "$arg2"
442137eb1ca1Smrg      fi
44224e8f48c7Smrg      func_append install_shared_prog " $func_quote_arg_result"
4423c27c18e8Smrg    done
4424c43cc173Smrg
4425c27c18e8Smrg    test -z "$install_prog" && \
4426c27c18e8Smrg      func_fatal_help "you must specify an install program"
4427c43cc173Smrg
4428c27c18e8Smrg    test -n "$prev" && \
442948e5ce07Smrg      func_fatal_help "the '$prev' option requires an argument"
4430c43cc173Smrg
443137eb1ca1Smrg    if test -n "$install_override_mode" && $no_mode; then
443237eb1ca1Smrg      if $install_cp; then :; else
44334e8f48c7Smrg	func_quote_arg pretty "$install_override_mode"
44344e8f48c7Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
443537eb1ca1Smrg      fi
443637eb1ca1Smrg    fi
443737eb1ca1Smrg
4438c27c18e8Smrg    if test -z "$files"; then
4439c27c18e8Smrg      if test -z "$dest"; then
4440c27c18e8Smrg	func_fatal_help "no file or destination specified"
4441c27c18e8Smrg      else
4442c27c18e8Smrg	func_fatal_help "you must specify a destination"
4443c27c18e8Smrg      fi
4444c43cc173Smrg    fi
4445c43cc173Smrg
4446c27c18e8Smrg    # Strip any trailing slash from the destination.
4447c27c18e8Smrg    func_stripname '' '/' "$dest"
4448c27c18e8Smrg    dest=$func_stripname_result
4449c43cc173Smrg
4450c27c18e8Smrg    # Check to see that the destination is a directory.
445148e5ce07Smrg    test -d "$dest" && isdir=:
445248e5ce07Smrg    if $isdir; then
445348e5ce07Smrg      destdir=$dest
4454c27c18e8Smrg      destname=
4455c43cc173Smrg    else
4456c27c18e8Smrg      func_dirname_and_basename "$dest" "" "."
445748e5ce07Smrg      destdir=$func_dirname_result
445848e5ce07Smrg      destname=$func_basename_result
4459c43cc173Smrg
4460c27c18e8Smrg      # Not a directory, so check to see that there is only one file specified.
4461c27c18e8Smrg      set dummy $files; shift
4462c27c18e8Smrg      test "$#" -gt 1 && \
446348e5ce07Smrg	func_fatal_help "'$dest' is not a directory"
4464c43cc173Smrg    fi
4465c27c18e8Smrg    case $destdir in
4466c27c18e8Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4467c43cc173Smrg    *)
4468c27c18e8Smrg      for file in $files; do
4469c27c18e8Smrg	case $file in
4470c27c18e8Smrg	*.lo) ;;
4471c27c18e8Smrg	*)
447248e5ce07Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4473c27c18e8Smrg	  ;;
4474c27c18e8Smrg	esac
4475c27c18e8Smrg      done
4476c43cc173Smrg      ;;
4477c43cc173Smrg    esac
4478c43cc173Smrg
4479c27c18e8Smrg    # This variable tells wrapper scripts just to set variables rather
4480c27c18e8Smrg    # than running their programs.
448148e5ce07Smrg    libtool_install_magic=$magic
4482c43cc173Smrg
4483c27c18e8Smrg    staticlibs=
4484c27c18e8Smrg    future_libdirs=
4485c27c18e8Smrg    current_libdirs=
4486c27c18e8Smrg    for file in $files; do
4487c43cc173Smrg
4488c27c18e8Smrg      # Do each installation.
4489c27c18e8Smrg      case $file in
4490c27c18e8Smrg      *.$libext)
4491c27c18e8Smrg	# Do the static libraries later.
4492b789ec8aSmrg	func_append staticlibs " $file"
4493c27c18e8Smrg	;;
4494c27c18e8Smrg
4495c27c18e8Smrg      *.la)
4496b789ec8aSmrg	func_resolve_sysroot "$file"
4497b789ec8aSmrg	file=$func_resolve_sysroot_result
4498b789ec8aSmrg
4499c27c18e8Smrg	# Check to see that this really is a libtool archive.
4500c27c18e8Smrg	func_lalib_unsafe_p "$file" \
450148e5ce07Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4502c27c18e8Smrg
4503c27c18e8Smrg	library_names=
4504c27c18e8Smrg	old_library=
4505c27c18e8Smrg	relink_command=
4506c27c18e8Smrg	func_source "$file"
4507c27c18e8Smrg
4508c27c18e8Smrg	# Add the libdir to current_libdirs if it is the destination.
4509c27c18e8Smrg	if test "X$destdir" = "X$libdir"; then
4510c27c18e8Smrg	  case "$current_libdirs " in
4511c27c18e8Smrg	  *" $libdir "*) ;;
4512b789ec8aSmrg	  *) func_append current_libdirs " $libdir" ;;
4513c43cc173Smrg	  esac
4514c27c18e8Smrg	else
4515c27c18e8Smrg	  # Note the libdir as a future libdir.
4516c27c18e8Smrg	  case "$future_libdirs " in
4517c27c18e8Smrg	  *" $libdir "*) ;;
4518b789ec8aSmrg	  *) func_append future_libdirs " $libdir" ;;
4519c27c18e8Smrg	  esac
4520c27c18e8Smrg	fi
4521c43cc173Smrg
4522c27c18e8Smrg	func_dirname "$file" "/" ""
452348e5ce07Smrg	dir=$func_dirname_result
4524b789ec8aSmrg	func_append dir "$objdir"
4525c27c18e8Smrg
4526c27c18e8Smrg	if test -n "$relink_command"; then
4527c27c18e8Smrg	  # Determine the prefix the user has applied to our future dir.
452837eb1ca1Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4529c27c18e8Smrg
4530c27c18e8Smrg	  # Don't allow the user to place us outside of our expected
4531c27c18e8Smrg	  # location b/c this prevents finding dependent libraries that
4532c27c18e8Smrg	  # are installed to the same prefix.
4533c27c18e8Smrg	  # At present, this check doesn't affect windows .dll's that
4534c27c18e8Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4535c27c18e8Smrg	  # but it's something to keep an eye on.
4536c27c18e8Smrg	  test "$inst_prefix_dir" = "$destdir" && \
453748e5ce07Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4538c27c18e8Smrg
4539c27c18e8Smrg	  if test -n "$inst_prefix_dir"; then
4540c27c18e8Smrg	    # Stick the inst_prefix_dir data into the link command.
454137eb1ca1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4542c27c18e8Smrg	  else
454337eb1ca1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4544c27c18e8Smrg	  fi
4545c27c18e8Smrg
454648e5ce07Smrg	  func_warning "relinking '$file'"
4547c27c18e8Smrg	  func_show_eval "$relink_command" \
454848e5ce07Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4549c27c18e8Smrg	fi
4550c27c18e8Smrg
4551c27c18e8Smrg	# See the names of the shared library.
4552c27c18e8Smrg	set dummy $library_names; shift
4553c27c18e8Smrg	if test -n "$1"; then
455448e5ce07Smrg	  realname=$1
4555c27c18e8Smrg	  shift
4556c27c18e8Smrg
455748e5ce07Smrg	  srcname=$realname
455848e5ce07Smrg	  test -n "$relink_command" && srcname=${realname}T
4559c27c18e8Smrg
4560c27c18e8Smrg	  # Install the shared library and build the symlinks.
456137eb1ca1Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4562c27c18e8Smrg	      'exit $?'
456348e5ce07Smrg	  tstripme=$stripme
4564c27c18e8Smrg	  case $host_os in
4565c27c18e8Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4566c27c18e8Smrg	    case $realname in
4567c27c18e8Smrg	    *.dll.a)
456848e5ce07Smrg	      tstripme=
456948e5ce07Smrg	      ;;
457048e5ce07Smrg	    esac
457148e5ce07Smrg	    ;;
457248e5ce07Smrg	  os2*)
457348e5ce07Smrg	    case $realname in
457448e5ce07Smrg	    *_dll.a)
457548e5ce07Smrg	      tstripme=
4576c27c18e8Smrg	      ;;
4577c27c18e8Smrg	    esac
4578c43cc173Smrg	    ;;
4579c43cc173Smrg	  esac
4580c27c18e8Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4581c27c18e8Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4582c43cc173Smrg	  fi
4583c27c18e8Smrg
4584c27c18e8Smrg	  if test "$#" -gt 0; then
4585c27c18e8Smrg	    # Delete the old symlinks, and create new ones.
458648e5ce07Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4587c27c18e8Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4588c27c18e8Smrg	    # so we also need to try rm && ln -s.
4589c27c18e8Smrg	    for linkname
4590c27c18e8Smrg	    do
4591c27c18e8Smrg	      test "$linkname" != "$realname" \
4592c27c18e8Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4593c43cc173Smrg	    done
4594c43cc173Smrg	  fi
4595c43cc173Smrg
4596c27c18e8Smrg	  # Do each command in the postinstall commands.
459748e5ce07Smrg	  lib=$destdir/$realname
4598c27c18e8Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4599c43cc173Smrg	fi
4600c43cc173Smrg
4601c27c18e8Smrg	# Install the pseudo-library for information purposes.
4602c27c18e8Smrg	func_basename "$file"
460348e5ce07Smrg	name=$func_basename_result
460448e5ce07Smrg	instname=$dir/${name}i
4605c27c18e8Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4606c43cc173Smrg
4607c27c18e8Smrg	# Maybe install the static library, too.
4608b789ec8aSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4609c27c18e8Smrg	;;
4610c43cc173Smrg
4611c27c18e8Smrg      *.lo)
4612c27c18e8Smrg	# Install (i.e. copy) a libtool object.
4613c43cc173Smrg
4614c27c18e8Smrg	# Figure out destination file name, if it wasn't already specified.
4615c27c18e8Smrg	if test -n "$destname"; then
461648e5ce07Smrg	  destfile=$destdir/$destname
4617c27c18e8Smrg	else
4618c27c18e8Smrg	  func_basename "$file"
461948e5ce07Smrg	  destfile=$func_basename_result
462048e5ce07Smrg	  destfile=$destdir/$destfile
4621c43cc173Smrg	fi
4622c43cc173Smrg
4623c27c18e8Smrg	# Deduce the name of the destination old-style object file.
4624c27c18e8Smrg	case $destfile in
4625c27c18e8Smrg	*.lo)
4626c27c18e8Smrg	  func_lo2o "$destfile"
4627c27c18e8Smrg	  staticdest=$func_lo2o_result
4628c27c18e8Smrg	  ;;
4629c27c18e8Smrg	*.$objext)
463048e5ce07Smrg	  staticdest=$destfile
4631c27c18e8Smrg	  destfile=
4632c27c18e8Smrg	  ;;
4633c27c18e8Smrg	*)
463448e5ce07Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4635c27c18e8Smrg	  ;;
4636c27c18e8Smrg	esac
4637c43cc173Smrg
4638c27c18e8Smrg	# Install the libtool object if requested.
4639c27c18e8Smrg	test -n "$destfile" && \
4640c27c18e8Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4641c43cc173Smrg
4642c27c18e8Smrg	# Install the old object if enabled.
464348e5ce07Smrg	if test yes = "$build_old_libs"; then
4644c27c18e8Smrg	  # Deduce the name of the old-style object file.
4645c27c18e8Smrg	  func_lo2o "$file"
4646c27c18e8Smrg	  staticobj=$func_lo2o_result
4647c27c18e8Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4648c43cc173Smrg	fi
4649c27c18e8Smrg	exit $EXIT_SUCCESS
4650c27c18e8Smrg	;;
4651c43cc173Smrg
4652c27c18e8Smrg      *)
4653c27c18e8Smrg	# Figure out destination file name, if it wasn't already specified.
4654c27c18e8Smrg	if test -n "$destname"; then
465548e5ce07Smrg	  destfile=$destdir/$destname
4656c27c18e8Smrg	else
4657c27c18e8Smrg	  func_basename "$file"
465848e5ce07Smrg	  destfile=$func_basename_result
465948e5ce07Smrg	  destfile=$destdir/$destfile
4660c27c18e8Smrg	fi
4661c43cc173Smrg
4662c27c18e8Smrg	# If the file is missing, and there is a .exe on the end, strip it
4663c27c18e8Smrg	# because it is most likely a libtool script we actually want to
4664c27c18e8Smrg	# install
466548e5ce07Smrg	stripped_ext=
4666c27c18e8Smrg	case $file in
4667c27c18e8Smrg	  *.exe)
4668c27c18e8Smrg	    if test ! -f "$file"; then
4669c27c18e8Smrg	      func_stripname '' '.exe' "$file"
4670c27c18e8Smrg	      file=$func_stripname_result
467148e5ce07Smrg	      stripped_ext=.exe
4672c27c18e8Smrg	    fi
4673c27c18e8Smrg	    ;;
4674c27c18e8Smrg	esac
4675c27c18e8Smrg
4676c27c18e8Smrg	# Do a test to see if this is really a libtool program.
4677c27c18e8Smrg	case $host in
4678c27c18e8Smrg	*cygwin* | *mingw*)
4679c27c18e8Smrg	    if func_ltwrapper_executable_p "$file"; then
4680c27c18e8Smrg	      func_ltwrapper_scriptname "$file"
4681c27c18e8Smrg	      wrapper=$func_ltwrapper_scriptname_result
4682c27c18e8Smrg	    else
4683c27c18e8Smrg	      func_stripname '' '.exe' "$file"
4684c27c18e8Smrg	      wrapper=$func_stripname_result
4685c27c18e8Smrg	    fi
4686c27c18e8Smrg	    ;;
4687c43cc173Smrg	*)
4688c27c18e8Smrg	    wrapper=$file
4689c27c18e8Smrg	    ;;
4690c27c18e8Smrg	esac
4691c27c18e8Smrg	if func_ltwrapper_script_p "$wrapper"; then
4692c27c18e8Smrg	  notinst_deplibs=
4693c27c18e8Smrg	  relink_command=
4694c27c18e8Smrg
4695c27c18e8Smrg	  func_source "$wrapper"
4696c27c18e8Smrg
4697c27c18e8Smrg	  # Check the variables that should have been set.
4698c27c18e8Smrg	  test -z "$generated_by_libtool_version" && \
469948e5ce07Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4700c27c18e8Smrg
470148e5ce07Smrg	  finalize=:
4702c27c18e8Smrg	  for lib in $notinst_deplibs; do
4703c27c18e8Smrg	    # Check to see that each library is installed.
4704c27c18e8Smrg	    libdir=
4705c27c18e8Smrg	    if test -f "$lib"; then
4706c27c18e8Smrg	      func_source "$lib"
4707c27c18e8Smrg	    fi
470848e5ce07Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4709c27c18e8Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
471048e5ce07Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
471148e5ce07Smrg	      finalize=false
4712c27c18e8Smrg	    fi
4713c27c18e8Smrg	  done
4714c27c18e8Smrg
4715c27c18e8Smrg	  relink_command=
4716c27c18e8Smrg	  func_source "$wrapper"
4717c27c18e8Smrg
4718c27c18e8Smrg	  outputname=
471948e5ce07Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4720c27c18e8Smrg	    $opt_dry_run || {
472148e5ce07Smrg	      if $finalize; then
4722c27c18e8Smrg	        tmpdir=`func_mktempdir`
4723c27c18e8Smrg		func_basename "$file$stripped_ext"
472448e5ce07Smrg		file=$func_basename_result
472548e5ce07Smrg	        outputname=$tmpdir/$file
4726c27c18e8Smrg	        # Replace the output file specification.
472737eb1ca1Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4728c27c18e8Smrg
472948e5ce07Smrg	        $opt_quiet || {
47304e8f48c7Smrg	          func_quote_arg expand,pretty "$relink_command"
47314e8f48c7Smrg		  eval "func_echo $func_quote_arg_result"
4732c27c18e8Smrg	        }
4733c27c18e8Smrg	        if eval "$relink_command"; then :
4734c27c18e8Smrg	          else
473548e5ce07Smrg		  func_error "error: relink '$file' with the above command before installing it"
4736c27c18e8Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4737c27c18e8Smrg		  continue
4738c27c18e8Smrg	        fi
473948e5ce07Smrg	        file=$outputname
4740c27c18e8Smrg	      else
474148e5ce07Smrg	        func_warning "cannot relink '$file'"
4742c27c18e8Smrg	      fi
4743c27c18e8Smrg	    }
4744c27c18e8Smrg	  else
4745c27c18e8Smrg	    # Install the binary that we compiled earlier.
474637eb1ca1Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4747c43cc173Smrg	  fi
4748c27c18e8Smrg	fi
4749c27c18e8Smrg
4750c27c18e8Smrg	# remove .exe since cygwin /usr/bin/install will append another
4751c27c18e8Smrg	# one anyway
4752c27c18e8Smrg	case $install_prog,$host in
4753c27c18e8Smrg	*/usr/bin/install*,*cygwin*)
4754c27c18e8Smrg	  case $file:$destfile in
4755c27c18e8Smrg	  *.exe:*.exe)
4756c27c18e8Smrg	    # this is ok
4757c27c18e8Smrg	    ;;
4758c27c18e8Smrg	  *.exe:*)
4759c27c18e8Smrg	    destfile=$destfile.exe
4760c27c18e8Smrg	    ;;
4761c27c18e8Smrg	  *:*.exe)
4762c27c18e8Smrg	    func_stripname '' '.exe' "$destfile"
4763c27c18e8Smrg	    destfile=$func_stripname_result
4764c27c18e8Smrg	    ;;
4765c27c18e8Smrg	  esac
4766c43cc173Smrg	  ;;
4767c43cc173Smrg	esac
4768c27c18e8Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4769c27c18e8Smrg	$opt_dry_run || if test -n "$outputname"; then
4770c27c18e8Smrg	  ${RM}r "$tmpdir"
4771c27c18e8Smrg	fi
4772c27c18e8Smrg	;;
4773c27c18e8Smrg      esac
4774c27c18e8Smrg    done
4775c43cc173Smrg
4776c27c18e8Smrg    for file in $staticlibs; do
4777c27c18e8Smrg      func_basename "$file"
477848e5ce07Smrg      name=$func_basename_result
4779c27c18e8Smrg
4780c27c18e8Smrg      # Set up the ranlib parameters.
478148e5ce07Smrg      oldlib=$destdir/$name
4782f1ee322dSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4783f1ee322dSmrg      tool_oldlib=$func_to_tool_file_result
4784c27c18e8Smrg
4785c27c18e8Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4786c27c18e8Smrg
4787c27c18e8Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4788f1ee322dSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4789c27c18e8Smrg      fi
4790c27c18e8Smrg
4791c27c18e8Smrg      # Do each command in the postinstall commands.
4792c27c18e8Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4793c27c18e8Smrg    done
4794c27c18e8Smrg
4795c27c18e8Smrg    test -n "$future_libdirs" && \
479648e5ce07Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4797c27c18e8Smrg
4798c27c18e8Smrg    if test -n "$current_libdirs"; then
4799c27c18e8Smrg      # Maybe just do a dry run.
4800c27c18e8Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
480148e5ce07Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4802c27c18e8Smrg    else
4803c27c18e8Smrg      exit $EXIT_SUCCESS
4804c27c18e8Smrg    fi
4805c27c18e8Smrg}
4806c27c18e8Smrg
480748e5ce07Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4808c27c18e8Smrg
4809c27c18e8Smrg
4810c27c18e8Smrg# func_generate_dlsyms outputname originator pic_p
4811c27c18e8Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4812c27c18e8Smrg# a dlpreopen symbol table.
4813c27c18e8Smrgfunc_generate_dlsyms ()
4814c27c18e8Smrg{
481548e5ce07Smrg    $debug_cmd
481648e5ce07Smrg
481748e5ce07Smrg    my_outputname=$1
481848e5ce07Smrg    my_originator=$2
481948e5ce07Smrg    my_pic_p=${3-false}
482048e5ce07Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4821c27c18e8Smrg    my_dlsyms=
4822c27c18e8Smrg
482348e5ce07Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4824c27c18e8Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
482548e5ce07Smrg	my_dlsyms=${my_outputname}S.c
4826c27c18e8Smrg      else
4827c27c18e8Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4828c27c18e8Smrg      fi
4829c27c18e8Smrg    fi
4830c27c18e8Smrg
4831c27c18e8Smrg    if test -n "$my_dlsyms"; then
4832c27c18e8Smrg      case $my_dlsyms in
4833c27c18e8Smrg      "") ;;
4834c27c18e8Smrg      *.c)
4835c27c18e8Smrg	# Discover the nlist of each of the dlfiles.
483648e5ce07Smrg	nlist=$output_objdir/$my_outputname.nm
4837c27c18e8Smrg
4838c27c18e8Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4839c27c18e8Smrg
4840c27c18e8Smrg	# Parse the name list into a source file.
4841c27c18e8Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4842c27c18e8Smrg
4843c27c18e8Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
484448e5ce07Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
484548e5ce07Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4846c27c18e8Smrg
4847c27c18e8Smrg#ifdef __cplusplus
4848c27c18e8Smrgextern \"C\" {
4849c27c18e8Smrg#endif
4850c27c18e8Smrg
485148e5ce07Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485237eb1ca1Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
485337eb1ca1Smrg#endif
485437eb1ca1Smrg
4855b789ec8aSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
485648e5ce07Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
485748e5ce07Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4858b789ec8aSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4859b789ec8aSmrg# define LT_DLSYM_CONST
486048e5ce07Smrg#elif defined __osf__
4861b789ec8aSmrg/* This system does not cope well with relocations in const data.  */
4862b789ec8aSmrg# define LT_DLSYM_CONST
4863b789ec8aSmrg#else
4864b789ec8aSmrg# define LT_DLSYM_CONST const
4865b789ec8aSmrg#endif
4866b789ec8aSmrg
486748e5ce07Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
486848e5ce07Smrg
4869c27c18e8Smrg/* External symbol declarations for the compiler. */\
4870c27c18e8Smrg"
4871c27c18e8Smrg
487248e5ce07Smrg	if test yes = "$dlself"; then
487348e5ce07Smrg	  func_verbose "generating symbol list for '$output'"
4874c27c18e8Smrg
4875c27c18e8Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4876c27c18e8Smrg
4877c27c18e8Smrg	  # Add our own program objects to the symbol list.
487837eb1ca1Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4879c27c18e8Smrg	  for progfile in $progfiles; do
4880b789ec8aSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
488148e5ce07Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4882b789ec8aSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4883c27c18e8Smrg	  done
4884c27c18e8Smrg
4885c27c18e8Smrg	  if test -n "$exclude_expsyms"; then
4886c27c18e8Smrg	    $opt_dry_run || {
4887c27c18e8Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4888c27c18e8Smrg	      eval '$MV "$nlist"T "$nlist"'
4889c27c18e8Smrg	    }
4890c43cc173Smrg	  fi
4891c27c18e8Smrg
4892c27c18e8Smrg	  if test -n "$export_symbols_regex"; then
4893c27c18e8Smrg	    $opt_dry_run || {
4894c27c18e8Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4895c27c18e8Smrg	      eval '$MV "$nlist"T "$nlist"'
4896c27c18e8Smrg	    }
4897c27c18e8Smrg	  fi
4898c27c18e8Smrg
4899c27c18e8Smrg	  # Prepare the list of exported symbols
4900c27c18e8Smrg	  if test -z "$export_symbols"; then
490148e5ce07Smrg	    export_symbols=$output_objdir/$outputname.exp
4902c27c18e8Smrg	    $opt_dry_run || {
4903c27c18e8Smrg	      $RM $export_symbols
490448e5ce07Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4905c27c18e8Smrg	      case $host in
4906c27c18e8Smrg	      *cygwin* | *mingw* | *cegcc* )
4907c27c18e8Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4908c27c18e8Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4909c27c18e8Smrg	        ;;
4910c27c18e8Smrg	      esac
4911c27c18e8Smrg	    }
4912c43cc173Smrg	  else
4913c27c18e8Smrg	    $opt_dry_run || {
491448e5ce07Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4915c27c18e8Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4916c27c18e8Smrg	      eval '$MV "$nlist"T "$nlist"'
4917c27c18e8Smrg	      case $host in
491837eb1ca1Smrg	        *cygwin* | *mingw* | *cegcc* )
4919c27c18e8Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4920c27c18e8Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4921c27c18e8Smrg	          ;;
4922c27c18e8Smrg	      esac
4923c27c18e8Smrg	    }
4924c43cc173Smrg	  fi
4925c27c18e8Smrg	fi
4926c43cc173Smrg
4927c27c18e8Smrg	for dlprefile in $dlprefiles; do
492848e5ce07Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4929c27c18e8Smrg	  func_basename "$dlprefile"
493048e5ce07Smrg	  name=$func_basename_result
4931b789ec8aSmrg          case $host in
4932b789ec8aSmrg	    *cygwin* | *mingw* | *cegcc* )
4933b789ec8aSmrg	      # if an import library, we need to obtain dlname
4934b789ec8aSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4935b789ec8aSmrg	        func_tr_sh "$dlprefile"
4936b789ec8aSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
493748e5ce07Smrg	        dlprefile_dlbasename=
4938b789ec8aSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4939b789ec8aSmrg	          # Use subshell, to avoid clobbering current variable values
4940b789ec8aSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
494148e5ce07Smrg	          if test -n "$dlprefile_dlname"; then
4942b789ec8aSmrg	            func_basename "$dlprefile_dlname"
494348e5ce07Smrg	            dlprefile_dlbasename=$func_basename_result
4944b789ec8aSmrg	          else
4945b789ec8aSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4946b789ec8aSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4947b789ec8aSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4948b789ec8aSmrg	          fi
4949b789ec8aSmrg	        fi
4950b789ec8aSmrg	        $opt_dry_run || {
495148e5ce07Smrg	          if test -n "$dlprefile_dlbasename"; then
4952b789ec8aSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4953b789ec8aSmrg	          else
4954b789ec8aSmrg	            func_warning "Could not compute DLL name from $name"
4955b789ec8aSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4956b789ec8aSmrg	          fi
4957b789ec8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4958b789ec8aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4959b789ec8aSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4960b789ec8aSmrg	        }
4961b789ec8aSmrg	      else # not an import lib
4962b789ec8aSmrg	        $opt_dry_run || {
4963b789ec8aSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4964b789ec8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965b789ec8aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4966b789ec8aSmrg	        }
4967b789ec8aSmrg	      fi
4968b789ec8aSmrg	    ;;
4969b789ec8aSmrg	    *)
4970b789ec8aSmrg	      $opt_dry_run || {
4971b789ec8aSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4972b789ec8aSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4973b789ec8aSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4974b789ec8aSmrg	      }
4975b789ec8aSmrg	    ;;
4976b789ec8aSmrg          esac
4977c27c18e8Smrg	done
4978c27c18e8Smrg
4979c27c18e8Smrg	$opt_dry_run || {
4980c27c18e8Smrg	  # Make sure we have at least an empty file.
4981c27c18e8Smrg	  test -f "$nlist" || : > "$nlist"
4982c27c18e8Smrg
4983c27c18e8Smrg	  if test -n "$exclude_expsyms"; then
4984c27c18e8Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4985c27c18e8Smrg	    $MV "$nlist"T "$nlist"
4986c43cc173Smrg	  fi
4987c27c18e8Smrg
4988c27c18e8Smrg	  # Try sorting and uniquifying the output.
4989c27c18e8Smrg	  if $GREP -v "^: " < "$nlist" |
4990c27c18e8Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4991c27c18e8Smrg		sort -k 3
4992c27c18e8Smrg	      else
4993c27c18e8Smrg		sort +2
4994c27c18e8Smrg	      fi |
4995c27c18e8Smrg	      uniq > "$nlist"S; then
4996c27c18e8Smrg	    :
4997c43cc173Smrg	  else
4998c27c18e8Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4999c43cc173Smrg	  fi
5000c43cc173Smrg
5001c27c18e8Smrg	  if test -f "$nlist"S; then
5002c27c18e8Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5003c43cc173Smrg	  else
500437eb1ca1Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5005c43cc173Smrg	  fi
5006c43cc173Smrg
500748e5ce07Smrg	  func_show_eval '$RM "${nlist}I"'
500848e5ce07Smrg	  if test -n "$global_symbol_to_import"; then
500948e5ce07Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
501048e5ce07Smrg	  fi
501148e5ce07Smrg
501237eb1ca1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5013c43cc173Smrg
5014c27c18e8Smrg/* The mapping between symbol names and symbols.  */
5015c27c18e8Smrgtypedef struct {
5016c27c18e8Smrg  const char *name;
5017c27c18e8Smrg  void *address;
5018c27c18e8Smrg} lt_dlsymlist;
5019b789ec8aSmrgextern LT_DLSYM_CONST lt_dlsymlist
502048e5ce07Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
502148e5ce07Smrg"
502248e5ce07Smrg
502348e5ce07Smrg	  if test -s "$nlist"I; then
502448e5ce07Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
502548e5ce07Smrgstatic void lt_syminit(void)
502648e5ce07Smrg{
502748e5ce07Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
502848e5ce07Smrg  for (; symbol->name; ++symbol)
502948e5ce07Smrg    {"
503048e5ce07Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
503148e5ce07Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
503248e5ce07Smrg    }
503348e5ce07Smrg}"
503448e5ce07Smrg	  fi
503548e5ce07Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5036b789ec8aSmrgLT_DLSYM_CONST lt_dlsymlist
5037c27c18e8Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
503848e5ce07Smrg{ {\"$my_originator\", (void *) 0},"
503948e5ce07Smrg
504048e5ce07Smrg	  if test -s "$nlist"I; then
504148e5ce07Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
504248e5ce07Smrg  {\"@INIT@\", (void *) &lt_syminit},"
504348e5ce07Smrg	  fi
5044c43cc173Smrg
5045c27c18e8Smrg	  case $need_lib_prefix in
5046c27c18e8Smrg	  no)
5047c27c18e8Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5048c27c18e8Smrg	    ;;
5049c27c18e8Smrg	  *)
5050c27c18e8Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5051c27c18e8Smrg	    ;;
5052c27c18e8Smrg	  esac
505337eb1ca1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5054c27c18e8Smrg  {0, (void *) 0}
5055c27c18e8Smrg};
5056c43cc173Smrg
5057c27c18e8Smrg/* This works around a problem in FreeBSD linker */
5058c27c18e8Smrg#ifdef FREEBSD_WORKAROUND
5059c27c18e8Smrgstatic const void *lt_preloaded_setup() {
5060c27c18e8Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5061c27c18e8Smrg}
5062c27c18e8Smrg#endif
5063c43cc173Smrg
5064c27c18e8Smrg#ifdef __cplusplus
5065c27c18e8Smrg}
5066c27c18e8Smrg#endif\
5067c27c18e8Smrg"
5068c27c18e8Smrg	} # !$opt_dry_run
5069c43cc173Smrg
5070c27c18e8Smrg	pic_flag_for_symtable=
5071c27c18e8Smrg	case "$compile_command " in
5072c27c18e8Smrg	*" -static "*) ;;
5073c27c18e8Smrg	*)
5074c27c18e8Smrg	  case $host in
5075c27c18e8Smrg	  # compiling the symbol table file with pic_flag works around
5076c27c18e8Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5077c27c18e8Smrg	  # linked before any other PIC object.  But we must not use
5078c27c18e8Smrg	  # pic_flag when linking with -static.  The problem exists in
5079c27c18e8Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5080f1ee322dSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5081c27c18e8Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5082c27c18e8Smrg	  *-*-hpux*)
5083c27c18e8Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5084c27c18e8Smrg	  *)
508548e5ce07Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5086c27c18e8Smrg	    ;;
5087c27c18e8Smrg	  esac
5088c27c18e8Smrg	  ;;
5089c27c18e8Smrg	esac
5090c27c18e8Smrg	symtab_cflags=
5091c27c18e8Smrg	for arg in $LTCFLAGS; do
5092c27c18e8Smrg	  case $arg in
5093c27c18e8Smrg	  -pie | -fpie | -fPIE) ;;
5094b789ec8aSmrg	  *) func_append symtab_cflags " $arg" ;;
5095c27c18e8Smrg	  esac
5096c27c18e8Smrg	done
5097c43cc173Smrg
5098c27c18e8Smrg	# Now compile the dynamic symbol file.
5099c27c18e8Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5100c43cc173Smrg
5101c27c18e8Smrg	# Clean up the generated files.
510248e5ce07Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5103c43cc173Smrg
5104c27c18e8Smrg	# Transform the symbol file into the correct name.
510548e5ce07Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5106c27c18e8Smrg	case $host in
5107c27c18e8Smrg	*cygwin* | *mingw* | *cegcc* )
5108c27c18e8Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
510937eb1ca1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511037eb1ca1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5111c27c18e8Smrg	  else
511237eb1ca1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
511337eb1ca1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5114c27c18e8Smrg	  fi
5115c27c18e8Smrg	  ;;
5116c27c18e8Smrg	*)
511737eb1ca1Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
511837eb1ca1Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5119c27c18e8Smrg	  ;;
5120c27c18e8Smrg	esac
5121c27c18e8Smrg	;;
5122c27c18e8Smrg      *)
512348e5ce07Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5124c27c18e8Smrg	;;
5125c27c18e8Smrg      esac
5126c27c18e8Smrg    else
5127c27c18e8Smrg      # We keep going just in case the user didn't refer to
5128c27c18e8Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5129c27c18e8Smrg      # really was required.
5130c43cc173Smrg
5131c27c18e8Smrg      # Nullify the symbol file.
513237eb1ca1Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
513337eb1ca1Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5134c27c18e8Smrg    fi
5135c27c18e8Smrg}
5136c43cc173Smrg
513748e5ce07Smrg# func_cygming_gnu_implib_p ARG
513848e5ce07Smrg# This predicate returns with zero status (TRUE) if
513948e5ce07Smrg# ARG is a GNU/binutils-style import library. Returns
514048e5ce07Smrg# with nonzero status (FALSE) otherwise.
514148e5ce07Smrgfunc_cygming_gnu_implib_p ()
514248e5ce07Smrg{
514348e5ce07Smrg  $debug_cmd
514448e5ce07Smrg
514548e5ce07Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
514648e5ce07Smrg  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)$'`
514748e5ce07Smrg  test -n "$func_cygming_gnu_implib_tmp"
514848e5ce07Smrg}
514948e5ce07Smrg
515048e5ce07Smrg# func_cygming_ms_implib_p ARG
515148e5ce07Smrg# This predicate returns with zero status (TRUE) if
515248e5ce07Smrg# ARG is an MS-style import library. Returns
515348e5ce07Smrg# with nonzero status (FALSE) otherwise.
515448e5ce07Smrgfunc_cygming_ms_implib_p ()
515548e5ce07Smrg{
515648e5ce07Smrg  $debug_cmd
515748e5ce07Smrg
515848e5ce07Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
515948e5ce07Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
516048e5ce07Smrg  test -n "$func_cygming_ms_implib_tmp"
516148e5ce07Smrg}
516248e5ce07Smrg
5163c27c18e8Smrg# func_win32_libid arg
5164c27c18e8Smrg# return the library type of file 'arg'
5165c27c18e8Smrg#
5166c27c18e8Smrg# Need a lot of goo to handle *both* DLLs and import libs
5167c27c18e8Smrg# Has to be a shell function in order to 'eat' the argument
5168c27c18e8Smrg# that is supplied when $file_magic_command is called.
516937eb1ca1Smrg# Despite the name, also deal with 64 bit binaries.
5170c27c18e8Smrgfunc_win32_libid ()
5171c27c18e8Smrg{
517248e5ce07Smrg  $debug_cmd
517348e5ce07Smrg
517448e5ce07Smrg  win32_libid_type=unknown
5175c27c18e8Smrg  win32_fileres=`file -L $1 2>/dev/null`
5176c27c18e8Smrg  case $win32_fileres in
5177c27c18e8Smrg  *ar\ archive\ import\ library*) # definitely import
5178c27c18e8Smrg    win32_libid_type="x86 archive import"
5179c27c18e8Smrg    ;;
5180c27c18e8Smrg  *ar\ archive*) # could be an import, or static
518137eb1ca1Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5182c27c18e8Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
518337eb1ca1Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
518448e5ce07Smrg      case $nm_interface in
518548e5ce07Smrg      "MS dumpbin")
518648e5ce07Smrg	if func_cygming_ms_implib_p "$1" ||
518748e5ce07Smrg	   func_cygming_gnu_implib_p "$1"
518848e5ce07Smrg	then
518948e5ce07Smrg	  win32_nmres=import
519048e5ce07Smrg	else
519148e5ce07Smrg	  win32_nmres=
519248e5ce07Smrg	fi
519348e5ce07Smrg	;;
519448e5ce07Smrg      *)
519548e5ce07Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
519648e5ce07Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
519748e5ce07Smrg	  $SED -n -e '
5198c27c18e8Smrg	    1,100{
5199c27c18e8Smrg		/ I /{
520048e5ce07Smrg		    s|.*|import|
5201c27c18e8Smrg		    p
5202c27c18e8Smrg		    q
5203c27c18e8Smrg		}
5204c27c18e8Smrg	    }'`
520548e5ce07Smrg	;;
520648e5ce07Smrg      esac
5207c27c18e8Smrg      case $win32_nmres in
5208c27c18e8Smrg      import*)  win32_libid_type="x86 archive import";;
5209c27c18e8Smrg      *)        win32_libid_type="x86 archive static";;
5210c27c18e8Smrg      esac
5211c27c18e8Smrg    fi
5212c27c18e8Smrg    ;;
5213c27c18e8Smrg  *DLL*)
5214c27c18e8Smrg    win32_libid_type="x86 DLL"
5215c27c18e8Smrg    ;;
5216c27c18e8Smrg  *executable*) # but shell scripts are "executable" too...
5217c27c18e8Smrg    case $win32_fileres in
5218c27c18e8Smrg    *MS\ Windows\ PE\ Intel*)
5219c27c18e8Smrg      win32_libid_type="x86 DLL"
5220c27c18e8Smrg      ;;
5221c27c18e8Smrg    esac
5222c27c18e8Smrg    ;;
5223c27c18e8Smrg  esac
5224c27c18e8Smrg  $ECHO "$win32_libid_type"
5225c27c18e8Smrg}
5226c43cc173Smrg
5227b789ec8aSmrg# func_cygming_dll_for_implib ARG
5228b789ec8aSmrg#
5229b789ec8aSmrg# Platform-specific function to extract the
5230b789ec8aSmrg# name of the DLL associated with the specified
5231b789ec8aSmrg# import library ARG.
5232b789ec8aSmrg# Invoked by eval'ing the libtool variable
5233b789ec8aSmrg#    $sharedlib_from_linklib_cmd
5234b789ec8aSmrg# Result is available in the variable
5235b789ec8aSmrg#    $sharedlib_from_linklib_result
5236b789ec8aSmrgfunc_cygming_dll_for_implib ()
5237b789ec8aSmrg{
523848e5ce07Smrg  $debug_cmd
523948e5ce07Smrg
5240b789ec8aSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5241b789ec8aSmrg}
5242b789ec8aSmrg
5243b789ec8aSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5244b789ec8aSmrg#
5245b789ec8aSmrg# The is the core of a fallback implementation of a
5246b789ec8aSmrg# platform-specific function to extract the name of the
5247b789ec8aSmrg# DLL associated with the specified import library LIBNAME.
5248b789ec8aSmrg#
5249b789ec8aSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5250b789ec8aSmrg# on the platform and compiler that created the implib.
5251b789ec8aSmrg#
5252b789ec8aSmrg# Echos the name of the DLL associated with the
5253b789ec8aSmrg# specified import library.
5254b789ec8aSmrgfunc_cygming_dll_for_implib_fallback_core ()
5255b789ec8aSmrg{
525648e5ce07Smrg  $debug_cmd
525748e5ce07Smrg
5258b789ec8aSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5259b789ec8aSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5260b789ec8aSmrg    $SED '/^Contents of section '"$match_literal"':/{
5261b789ec8aSmrg      # Place marker at beginning of archive member dllname section
5262b789ec8aSmrg      s/.*/====MARK====/
5263b789ec8aSmrg      p
5264b789ec8aSmrg      d
5265b789ec8aSmrg    }
5266b789ec8aSmrg    # These lines can sometimes be longer than 43 characters, but
5267b789ec8aSmrg    # are always uninteresting
5268b789ec8aSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5269b789ec8aSmrg    /^In archive [^:]*:/d
5270b789ec8aSmrg    # Ensure marker is printed
5271b789ec8aSmrg    /^====MARK====/p
5272b789ec8aSmrg    # Remove all lines with less than 43 characters
5273b789ec8aSmrg    /^.\{43\}/!d
5274b789ec8aSmrg    # From remaining lines, remove first 43 characters
5275b789ec8aSmrg    s/^.\{43\}//' |
5276b789ec8aSmrg    $SED -n '
5277b789ec8aSmrg      # Join marker and all lines until next marker into a single line
5278b789ec8aSmrg      /^====MARK====/ b para
5279b789ec8aSmrg      H
5280b789ec8aSmrg      $ b para
5281b789ec8aSmrg      b
5282b789ec8aSmrg      :para
5283b789ec8aSmrg      x
5284b789ec8aSmrg      s/\n//g
5285b789ec8aSmrg      # Remove the marker
5286b789ec8aSmrg      s/^====MARK====//
5287b789ec8aSmrg      # Remove trailing dots and whitespace
5288b789ec8aSmrg      s/[\. \t]*$//
5289b789ec8aSmrg      # Print
5290b789ec8aSmrg      /./p' |
5291b789ec8aSmrg    # we now have a list, one entry per line, of the stringified
5292b789ec8aSmrg    # contents of the appropriate section of all members of the
529348e5ce07Smrg    # archive that possess that section. Heuristic: eliminate
529448e5ce07Smrg    # all those that have a first or second character that is
5295b789ec8aSmrg    # a '.' (that is, objdump's representation of an unprintable
5296b789ec8aSmrg    # character.) This should work for all archives with less than
5297b789ec8aSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5298b789ec8aSmrg    # begins with a literal '.' or a single character followed by
5299b789ec8aSmrg    # a '.'.
5300b789ec8aSmrg    #
5301b789ec8aSmrg    # Of those that remain, print the first one.
5302b789ec8aSmrg    $SED -e '/^\./d;/^.\./d;q'
5303b789ec8aSmrg}
5304b789ec8aSmrg
5305b789ec8aSmrg# func_cygming_dll_for_implib_fallback ARG
5306b789ec8aSmrg# Platform-specific function to extract the
5307b789ec8aSmrg# name of the DLL associated with the specified
5308b789ec8aSmrg# import library ARG.
5309b789ec8aSmrg#
5310b789ec8aSmrg# This fallback implementation is for use when $DLLTOOL
5311b789ec8aSmrg# does not support the --identify-strict option.
5312b789ec8aSmrg# Invoked by eval'ing the libtool variable
5313b789ec8aSmrg#    $sharedlib_from_linklib_cmd
5314b789ec8aSmrg# Result is available in the variable
5315b789ec8aSmrg#    $sharedlib_from_linklib_result
5316b789ec8aSmrgfunc_cygming_dll_for_implib_fallback ()
5317b789ec8aSmrg{
531848e5ce07Smrg  $debug_cmd
531948e5ce07Smrg
532048e5ce07Smrg  if func_cygming_gnu_implib_p "$1"; then
5321b789ec8aSmrg    # binutils import library
5322b789ec8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
532348e5ce07Smrg  elif func_cygming_ms_implib_p "$1"; then
5324b789ec8aSmrg    # ms-generated import library
5325b789ec8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5326b789ec8aSmrg  else
5327b789ec8aSmrg    # unknown
532848e5ce07Smrg    sharedlib_from_linklib_result=
5329b789ec8aSmrg  fi
5330b789ec8aSmrg}
5331c43cc173Smrg
5332c43cc173Smrg
5333c27c18e8Smrg# func_extract_an_archive dir oldlib
5334c27c18e8Smrgfunc_extract_an_archive ()
5335c27c18e8Smrg{
533648e5ce07Smrg    $debug_cmd
533748e5ce07Smrg
533848e5ce07Smrg    f_ex_an_ar_dir=$1; shift
533948e5ce07Smrg    f_ex_an_ar_oldlib=$1
534048e5ce07Smrg    if test yes = "$lock_old_archive_extraction"; then
534137eb1ca1Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534237eb1ca1Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
534337eb1ca1Smrg	func_echo "Waiting for $lockfile to be removed"
534437eb1ca1Smrg	sleep 2
534537eb1ca1Smrg      done
534637eb1ca1Smrg    fi
534737eb1ca1Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
534837eb1ca1Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
534948e5ce07Smrg    if test yes = "$lock_old_archive_extraction"; then
535037eb1ca1Smrg      $opt_dry_run || rm -f "$lockfile"
535137eb1ca1Smrg    fi
5352c27c18e8Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5353c27c18e8Smrg     :
5354c27c18e8Smrg    else
5355c27c18e8Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5356c27c18e8Smrg    fi
5357c27c18e8Smrg}
5358c43cc173Smrg
5359c43cc173Smrg
5360c27c18e8Smrg# func_extract_archives gentop oldlib ...
5361c27c18e8Smrgfunc_extract_archives ()
5362c27c18e8Smrg{
536348e5ce07Smrg    $debug_cmd
536448e5ce07Smrg
536548e5ce07Smrg    my_gentop=$1; shift
5366c27c18e8Smrg    my_oldlibs=${1+"$@"}
536748e5ce07Smrg    my_oldobjs=
536848e5ce07Smrg    my_xlib=
536948e5ce07Smrg    my_xabs=
537048e5ce07Smrg    my_xdir=
5371c43cc173Smrg
5372c27c18e8Smrg    for my_xlib in $my_oldlibs; do
5373c27c18e8Smrg      # Extract the objects.
5374c27c18e8Smrg      case $my_xlib in
537548e5ce07Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5376c27c18e8Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5377c27c18e8Smrg      esac
5378c27c18e8Smrg      func_basename "$my_xlib"
537948e5ce07Smrg      my_xlib=$func_basename_result
5380c27c18e8Smrg      my_xlib_u=$my_xlib
5381c27c18e8Smrg      while :; do
5382c27c18e8Smrg        case " $extracted_archives " in
5383c27c18e8Smrg	*" $my_xlib_u "*)
5384c27c18e8Smrg	  func_arith $extracted_serial + 1
5385c27c18e8Smrg	  extracted_serial=$func_arith_result
5386c27c18e8Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5387c27c18e8Smrg	*) break ;;
5388c27c18e8Smrg	esac
5389c27c18e8Smrg      done
5390c27c18e8Smrg      extracted_archives="$extracted_archives $my_xlib_u"
539148e5ce07Smrg      my_xdir=$my_gentop/$my_xlib_u
5392c43cc173Smrg
5393c27c18e8Smrg      func_mkdir_p "$my_xdir"
5394c27c18e8Smrg
5395c27c18e8Smrg      case $host in
5396c27c18e8Smrg      *-darwin*)
5397c27c18e8Smrg	func_verbose "Extracting $my_xabs"
5398c27c18e8Smrg	# Do not bother doing anything if just a dry run
5399c27c18e8Smrg	$opt_dry_run || {
5400c27c18e8Smrg	  darwin_orig_dir=`pwd`
5401c27c18e8Smrg	  cd $my_xdir || exit $?
5402c27c18e8Smrg	  darwin_archive=$my_xabs
5403c27c18e8Smrg	  darwin_curdir=`pwd`
540448e5ce07Smrg	  func_basename "$darwin_archive"
540548e5ce07Smrg	  darwin_base_archive=$func_basename_result
5406c27c18e8Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5407c27c18e8Smrg	  if test -n "$darwin_arches"; then
5408c27c18e8Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5409c27c18e8Smrg	    darwin_arch=
5410c27c18e8Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
541148e5ce07Smrg	    for darwin_arch in  $darwin_arches; do
541248e5ce07Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
541348e5ce07Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
541448e5ce07Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
541548e5ce07Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5416c27c18e8Smrg	      cd "$darwin_curdir"
541748e5ce07Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5418c27c18e8Smrg	    done # $darwin_arches
5419c27c18e8Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
542048e5ce07Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5421c27c18e8Smrg	    darwin_file=
5422c27c18e8Smrg	    darwin_files=
5423c27c18e8Smrg	    for darwin_file in $darwin_filelist; do
542437eb1ca1Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5425c27c18e8Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5426c27c18e8Smrg	    done # $darwin_filelist
5427c27c18e8Smrg	    $RM -rf unfat-$$
5428c27c18e8Smrg	    cd "$darwin_orig_dir"
5429c43cc173Smrg	  else
5430c27c18e8Smrg	    cd $darwin_orig_dir
5431c27c18e8Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5432c27c18e8Smrg	  fi # $darwin_arches
5433c27c18e8Smrg	} # !$opt_dry_run
5434c27c18e8Smrg	;;
5435c27c18e8Smrg      *)
5436c27c18e8Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5437c27c18e8Smrg	;;
5438c27c18e8Smrg      esac
543937eb1ca1Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5440c27c18e8Smrg    done
5441c43cc173Smrg
544248e5ce07Smrg    func_extract_archives_result=$my_oldobjs
5443c27c18e8Smrg}
5444c43cc173Smrg
5445c43cc173Smrg
544637eb1ca1Smrg# func_emit_wrapper [arg=no]
544737eb1ca1Smrg#
544837eb1ca1Smrg# Emit a libtool wrapper script on stdout.
544937eb1ca1Smrg# Don't directly open a file because we may want to
545037eb1ca1Smrg# incorporate the script contents within a cygwin/mingw
545137eb1ca1Smrg# wrapper executable.  Must ONLY be called from within
545237eb1ca1Smrg# func_mode_link because it depends on a number of variables
545337eb1ca1Smrg# set therein.
5454c27c18e8Smrg#
545537eb1ca1Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
545637eb1ca1Smrg# variable will take.  If 'yes', then the emitted script
545748e5ce07Smrg# will assume that the directory where it is stored is
545837eb1ca1Smrg# the $objdir directory.  This is a cygwin/mingw-specific
545937eb1ca1Smrg# behavior.
546037eb1ca1Smrgfunc_emit_wrapper ()
5461c27c18e8Smrg{
546237eb1ca1Smrg	func_emit_wrapper_arg1=${1-no}
5463c43cc173Smrg
5464c27c18e8Smrg	$ECHO "\
5465c27c18e8Smrg#! $SHELL
5466c43cc173Smrg
5467c27c18e8Smrg# $output - temporary wrapper script for $objdir/$outputname
546848e5ce07Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5469c27c18e8Smrg#
5470c27c18e8Smrg# The $output program cannot be directly executed until all the libtool
5471c27c18e8Smrg# libraries that it depends on are installed.
5472c27c18e8Smrg#
5473c27c18e8Smrg# This wrapper script should never be moved out of the build directory.
5474c27c18e8Smrg# If it is, it will not operate correctly.
5475c43cc173Smrg
5476c27c18e8Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5477c27c18e8Smrg# metacharacters that are still active within double-quoted strings.
5478c27c18e8Smrgsed_quote_subst='$sed_quote_subst'
5479c43cc173Smrg
5480c27c18e8Smrg# Be Bourne compatible
5481c27c18e8Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5482c27c18e8Smrg  emulate sh
5483c27c18e8Smrg  NULLCMD=:
5484c27c18e8Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5485c27c18e8Smrg  # is contrary to our usage.  Disable this feature.
5486c27c18e8Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5487c27c18e8Smrg  setopt NO_GLOB_SUBST
5488c27c18e8Smrgelse
5489c27c18e8Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5490c27c18e8Smrgfi
5491c27c18e8SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5492c27c18e8SmrgDUALCASE=1; export DUALCASE # for MKS sh
5493c43cc173Smrg
5494c27c18e8Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5495c27c18e8Smrg# if CDPATH is set.
5496c27c18e8Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5497c43cc173Smrg
5498c27c18e8Smrgrelink_command=\"$relink_command\"
5499c43cc173Smrg
5500c27c18e8Smrg# This environment variable determines our operation mode.
5501c27c18e8Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5502c27c18e8Smrg  # install mode needs the following variables:
5503c27c18e8Smrg  generated_by_libtool_version='$macro_version'
5504c27c18e8Smrg  notinst_deplibs='$notinst_deplibs'
5505c27c18e8Smrgelse
5506c27c18e8Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5507c27c18e8Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
550837eb1ca1Smrg    file=\"\$0\""
550937eb1ca1Smrg
55104e8f48c7Smrg    func_quote_arg pretty "$ECHO"
55114e8f48c7Smrg    qECHO=$func_quote_arg_result
551237eb1ca1Smrg    $ECHO "\
551337eb1ca1Smrg
551437eb1ca1Smrg# A function that is used when there is no print builtin or printf.
551537eb1ca1Smrgfunc_fallback_echo ()
551637eb1ca1Smrg{
551737eb1ca1Smrg  eval 'cat <<_LTECHO_EOF
551837eb1ca1Smrg\$1
551937eb1ca1Smrg_LTECHO_EOF'
552037eb1ca1Smrg}
55214e8f48c7Smrg    ECHO=$qECHO
552237eb1ca1Smrg  fi
552337eb1ca1Smrg
552437eb1ca1Smrg# Very basic option parsing. These options are (a) specific to
552537eb1ca1Smrg# the libtool wrapper, (b) are identical between the wrapper
552648e5ce07Smrg# /script/ and the wrapper /executable/ that is used only on
552737eb1ca1Smrg# windows platforms, and (c) all begin with the string "--lt-"
552848e5ce07Smrg# (application programs are unlikely to have options that match
552937eb1ca1Smrg# this pattern).
553037eb1ca1Smrg#
553137eb1ca1Smrg# There are only two supported options: --lt-debug and
553237eb1ca1Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
553337eb1ca1Smrg#
553437eb1ca1Smrg# The first argument to this parsing function should be the
553537eb1ca1Smrg# script's $0 value, followed by "$@".
553637eb1ca1Smrglt_option_debug=
553737eb1ca1Smrgfunc_parse_lt_options ()
553837eb1ca1Smrg{
553937eb1ca1Smrg  lt_script_arg0=\$0
554037eb1ca1Smrg  shift
554137eb1ca1Smrg  for lt_opt
554237eb1ca1Smrg  do
554337eb1ca1Smrg    case \"\$lt_opt\" in
554437eb1ca1Smrg    --lt-debug) lt_option_debug=1 ;;
554537eb1ca1Smrg    --lt-dump-script)
554637eb1ca1Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
554737eb1ca1Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
554837eb1ca1Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
554937eb1ca1Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555037eb1ca1Smrg        exit 0
555137eb1ca1Smrg      ;;
555237eb1ca1Smrg    --lt-*)
555337eb1ca1Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
555437eb1ca1Smrg        exit 1
555537eb1ca1Smrg      ;;
555637eb1ca1Smrg    esac
555737eb1ca1Smrg  done
555837eb1ca1Smrg
555937eb1ca1Smrg  # Print the debug banner immediately:
556037eb1ca1Smrg  if test -n \"\$lt_option_debug\"; then
556148e5ce07Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556237eb1ca1Smrg  fi
556337eb1ca1Smrg}
556437eb1ca1Smrg
556537eb1ca1Smrg# Used when --lt-debug. Prints its arguments to stdout
556637eb1ca1Smrg# (redirection is the responsibility of the caller)
556737eb1ca1Smrgfunc_lt_dump_args ()
556837eb1ca1Smrg{
556937eb1ca1Smrg  lt_dump_args_N=1;
557037eb1ca1Smrg  for lt_arg
557137eb1ca1Smrg  do
557248e5ce07Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
557337eb1ca1Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
557437eb1ca1Smrg  done
557537eb1ca1Smrg}
557637eb1ca1Smrg
557737eb1ca1Smrg# Core function for launching the target application
557837eb1ca1Smrgfunc_exec_program_core ()
557937eb1ca1Smrg{
5580c27c18e8Smrg"
558137eb1ca1Smrg  case $host in
558237eb1ca1Smrg  # Backslashes separate directories on plain windows
558337eb1ca1Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
558437eb1ca1Smrg    $ECHO "\
558537eb1ca1Smrg      if test -n \"\$lt_option_debug\"; then
558648e5ce07Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
558737eb1ca1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
558837eb1ca1Smrg      fi
558937eb1ca1Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559037eb1ca1Smrg"
559137eb1ca1Smrg    ;;
559237eb1ca1Smrg
559337eb1ca1Smrg  *)
559437eb1ca1Smrg    $ECHO "\
559537eb1ca1Smrg      if test -n \"\$lt_option_debug\"; then
559648e5ce07Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
559737eb1ca1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
559837eb1ca1Smrg      fi
559937eb1ca1Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560037eb1ca1Smrg"
560137eb1ca1Smrg    ;;
560237eb1ca1Smrg  esac
560337eb1ca1Smrg  $ECHO "\
560437eb1ca1Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
560537eb1ca1Smrg      exit 1
560637eb1ca1Smrg}
560737eb1ca1Smrg
560837eb1ca1Smrg# A function to encapsulate launching the target application
560937eb1ca1Smrg# Strips options in the --lt-* namespace from \$@ and
561037eb1ca1Smrg# launches target application with the remaining arguments.
561137eb1ca1Smrgfunc_exec_program ()
561237eb1ca1Smrg{
5613f1ee322dSmrg  case \" \$* \" in
5614f1ee322dSmrg  *\\ --lt-*)
5615f1ee322dSmrg    for lt_wr_arg
5616f1ee322dSmrg    do
5617f1ee322dSmrg      case \$lt_wr_arg in
5618f1ee322dSmrg      --lt-*) ;;
5619f1ee322dSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5620f1ee322dSmrg      esac
5621f1ee322dSmrg      shift
5622f1ee322dSmrg    done ;;
5623f1ee322dSmrg  esac
562437eb1ca1Smrg  func_exec_program_core \${1+\"\$@\"}
562537eb1ca1Smrg}
562637eb1ca1Smrg
562737eb1ca1Smrg  # Parse options
562837eb1ca1Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5629c43cc173Smrg
5630c27c18e8Smrg  # Find the directory that this script lives in.
563137eb1ca1Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5632c27c18e8Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5633c43cc173Smrg
5634c27c18e8Smrg  # Follow symbolic links until we get to the real thisdir.
563537eb1ca1Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5636c27c18e8Smrg  while test -n \"\$file\"; do
563737eb1ca1Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5638c27c18e8Smrg
5639c27c18e8Smrg    # If there was a directory component, then change thisdir.
5640c27c18e8Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5641c27c18e8Smrg      case \"\$destdir\" in
5642c27c18e8Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5643c27c18e8Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5644c43cc173Smrg      esac
5645c27c18e8Smrg    fi
5646c43cc173Smrg
564737eb1ca1Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
564837eb1ca1Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5649c27c18e8Smrg  done
5650c43cc173Smrg
5651c27c18e8Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5652c27c18e8Smrg  # the cwrapper.
565337eb1ca1Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5654c27c18e8Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5655c27c18e8Smrg    # special case for '.'
5656c27c18e8Smrg    if test \"\$thisdir\" = \".\"; then
5657c27c18e8Smrg      thisdir=\`pwd\`
5658c27c18e8Smrg    fi
5659c27c18e8Smrg    # remove .libs from thisdir
5660c27c18e8Smrg    case \"\$thisdir\" in
566137eb1ca1Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5662c27c18e8Smrg    $objdir )   thisdir=. ;;
5663c27c18e8Smrg    esac
5664c27c18e8Smrg  fi
5665c27c18e8Smrg
5666c27c18e8Smrg  # Try to get the absolute directory name.
5667c27c18e8Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5668c27c18e8Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5669c27c18e8Smrg"
5670c27c18e8Smrg
567148e5ce07Smrg	if test yes = "$fast_install"; then
5672c27c18e8Smrg	  $ECHO "\
5673c27c18e8Smrg  program=lt-'$outputname'$exeext
5674c27c18e8Smrg  progdir=\"\$thisdir/$objdir\"
5675c27c18e8Smrg
5676c27c18e8Smrg  if test ! -f \"\$progdir/\$program\" ||
567748e5ce07Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5678c27c18e8Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5679c27c18e8Smrg
5680c27c18e8Smrg    file=\"\$\$-\$program\"
5681c27c18e8Smrg
5682c27c18e8Smrg    if test ! -d \"\$progdir\"; then
5683c27c18e8Smrg      $MKDIR \"\$progdir\"
5684c27c18e8Smrg    else
5685c27c18e8Smrg      $RM \"\$progdir/\$file\"
5686c27c18e8Smrg    fi"
5687c27c18e8Smrg
5688c27c18e8Smrg	  $ECHO "\
5689c27c18e8Smrg
5690c27c18e8Smrg    # relink executable if necessary
5691c27c18e8Smrg    if test -n \"\$relink_command\"; then
5692c27c18e8Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5693c27c18e8Smrg      else
569448e5ce07Smrg	\$ECHO \"\$relink_command_output\" >&2
5695c27c18e8Smrg	$RM \"\$progdir/\$file\"
5696c27c18e8Smrg	exit 1
5697c43cc173Smrg      fi
5698c27c18e8Smrg    fi
5699c43cc173Smrg
5700c27c18e8Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5701c27c18e8Smrg    { $RM \"\$progdir/\$program\";
5702c27c18e8Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5703c27c18e8Smrg    $RM \"\$progdir/\$file\"
5704c27c18e8Smrg  fi"
5705c27c18e8Smrg	else
5706c27c18e8Smrg	  $ECHO "\
5707c27c18e8Smrg  program='$outputname'
5708c27c18e8Smrg  progdir=\"\$thisdir/$objdir\"
5709c27c18e8Smrg"
5710c43cc173Smrg	fi
5711c43cc173Smrg
5712c27c18e8Smrg	$ECHO "\
5713c27c18e8Smrg
5714c27c18e8Smrg  if test -f \"\$progdir/\$program\"; then"
5715c27c18e8Smrg
5716b789ec8aSmrg	# fixup the dll searchpath if we need to.
5717b789ec8aSmrg	#
5718b789ec8aSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5719b789ec8aSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5720b789ec8aSmrg	# libraries must come first.
5721b789ec8aSmrg	if test -n "$dllsearchpath"; then
5722b789ec8aSmrg	  $ECHO "\
5723b789ec8aSmrg    # Add the dll search path components to the executable PATH
5724b789ec8aSmrg    PATH=$dllsearchpath:\$PATH
5725b789ec8aSmrg"
5726b789ec8aSmrg	fi
5727b789ec8aSmrg
5728c27c18e8Smrg	# Export our shlibpath_var if we have one.
572948e5ce07Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5730c27c18e8Smrg	  $ECHO "\
5731c27c18e8Smrg    # Add our own library path to $shlibpath_var
5732c27c18e8Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5733c27c18e8Smrg
5734c27c18e8Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5735c27c18e8Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
573637eb1ca1Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5737c27c18e8Smrg
5738c27c18e8Smrg    export $shlibpath_var
5739c27c18e8Smrg"
5740c43cc173Smrg	fi
5741c43cc173Smrg
5742c27c18e8Smrg	$ECHO "\
5743c27c18e8Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5744c27c18e8Smrg      # Run the actual program with our arguments.
574537eb1ca1Smrg      func_exec_program \${1+\"\$@\"}
5746c27c18e8Smrg    fi
5747c27c18e8Smrg  else
5748c27c18e8Smrg    # The program doesn't exist.
574948e5ce07Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5750c27c18e8Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575137eb1ca1Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5752c27c18e8Smrg    exit 1
5753c27c18e8Smrg  fi
5754c27c18e8Smrgfi\
5755c27c18e8Smrg"
5756c27c18e8Smrg}
5757c43cc173Smrg
5758c43cc173Smrg
5759c27c18e8Smrg# func_emit_cwrapperexe_src
5760c27c18e8Smrg# emit the source code for a wrapper executable on stdout
5761c27c18e8Smrg# Must ONLY be called from within func_mode_link because
5762c27c18e8Smrg# it depends on a number of variable set therein.
5763c27c18e8Smrgfunc_emit_cwrapperexe_src ()
5764c27c18e8Smrg{
5765c27c18e8Smrg	cat <<EOF
5766c43cc173Smrg
5767c27c18e8Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
576848e5ce07Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5769c43cc173Smrg
5770c27c18e8Smrg   The $output program cannot be directly executed until all the libtool
5771c27c18e8Smrg   libraries that it depends on are installed.
5772c43cc173Smrg
5773c27c18e8Smrg   This wrapper executable should never be moved out of the build directory.
5774c27c18e8Smrg   If it is, it will not operate correctly.
5775c27c18e8Smrg*/
5776c27c18e8SmrgEOF
5777c27c18e8Smrg	    cat <<"EOF"
577837eb1ca1Smrg#ifdef _MSC_VER
577937eb1ca1Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578037eb1ca1Smrg#endif
5781c27c18e8Smrg#include <stdio.h>
5782c27c18e8Smrg#include <stdlib.h>
5783c27c18e8Smrg#ifdef _MSC_VER
5784c27c18e8Smrg# include <direct.h>
5785c27c18e8Smrg# include <process.h>
5786c27c18e8Smrg# include <io.h>
5787c27c18e8Smrg#else
5788c27c18e8Smrg# include <unistd.h>
5789c27c18e8Smrg# include <stdint.h>
5790c27c18e8Smrg# ifdef __CYGWIN__
5791c27c18e8Smrg#  include <io.h>
5792c27c18e8Smrg# endif
5793c27c18e8Smrg#endif
5794c27c18e8Smrg#include <malloc.h>
5795c27c18e8Smrg#include <stdarg.h>
5796c27c18e8Smrg#include <assert.h>
5797c27c18e8Smrg#include <string.h>
5798c27c18e8Smrg#include <ctype.h>
5799c27c18e8Smrg#include <errno.h>
5800c27c18e8Smrg#include <fcntl.h>
5801c27c18e8Smrg#include <sys/stat.h>
5802c43cc173Smrg
580348e5ce07Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
580448e5ce07Smrg
580537eb1ca1Smrg/* declarations of non-ANSI functions */
580648e5ce07Smrg#if defined __MINGW32__
580737eb1ca1Smrg# ifdef __STRICT_ANSI__
580837eb1ca1Smrgint _putenv (const char *);
580937eb1ca1Smrg# endif
581048e5ce07Smrg#elif defined __CYGWIN__
581137eb1ca1Smrg# ifdef __STRICT_ANSI__
581237eb1ca1Smrgchar *realpath (const char *, char *);
581337eb1ca1Smrgint putenv (char *);
581437eb1ca1Smrgint setenv (const char *, const char *, int);
581537eb1ca1Smrg# endif
581648e5ce07Smrg/* #elif defined other_platform || defined ... */
581737eb1ca1Smrg#endif
581837eb1ca1Smrg
581937eb1ca1Smrg/* portability defines, excluding path handling macros */
582048e5ce07Smrg#if defined _MSC_VER
582137eb1ca1Smrg# define setmode _setmode
582237eb1ca1Smrg# define stat    _stat
582337eb1ca1Smrg# define chmod   _chmod
582437eb1ca1Smrg# define getcwd  _getcwd
582537eb1ca1Smrg# define putenv  _putenv
582637eb1ca1Smrg# define S_IXUSR _S_IEXEC
582748e5ce07Smrg#elif defined __MINGW32__
582837eb1ca1Smrg# define setmode _setmode
582937eb1ca1Smrg# define stat    _stat
583037eb1ca1Smrg# define chmod   _chmod
583137eb1ca1Smrg# define getcwd  _getcwd
583237eb1ca1Smrg# define putenv  _putenv
583348e5ce07Smrg#elif defined __CYGWIN__
583437eb1ca1Smrg# define HAVE_SETENV
583537eb1ca1Smrg# define FOPEN_WB "wb"
583648e5ce07Smrg/* #elif defined other platforms ... */
583737eb1ca1Smrg#endif
583837eb1ca1Smrg
583948e5ce07Smrg#if defined PATH_MAX
5840c27c18e8Smrg# define LT_PATHMAX PATH_MAX
584148e5ce07Smrg#elif defined MAXPATHLEN
5842c27c18e8Smrg# define LT_PATHMAX MAXPATHLEN
5843c27c18e8Smrg#else
5844c27c18e8Smrg# define LT_PATHMAX 1024
5845c27c18e8Smrg#endif
5846c43cc173Smrg
5847c27c18e8Smrg#ifndef S_IXOTH
5848c27c18e8Smrg# define S_IXOTH 0
5849c27c18e8Smrg#endif
5850c27c18e8Smrg#ifndef S_IXGRP
5851c27c18e8Smrg# define S_IXGRP 0
5852c27c18e8Smrg#endif
5853c43cc173Smrg
585437eb1ca1Smrg/* path handling portability macros */
5855c27c18e8Smrg#ifndef DIR_SEPARATOR
5856c27c18e8Smrg# define DIR_SEPARATOR '/'
5857c27c18e8Smrg# define PATH_SEPARATOR ':'
5858c27c18e8Smrg#endif
5859c43cc173Smrg
586048e5ce07Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
586148e5ce07Smrg  defined __OS2__
5862c27c18e8Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5863c27c18e8Smrg# define FOPEN_WB "wb"
5864c27c18e8Smrg# ifndef DIR_SEPARATOR_2
5865c27c18e8Smrg#  define DIR_SEPARATOR_2 '\\'
5866c27c18e8Smrg# endif
5867c27c18e8Smrg# ifndef PATH_SEPARATOR_2
5868c27c18e8Smrg#  define PATH_SEPARATOR_2 ';'
5869c27c18e8Smrg# endif
5870c27c18e8Smrg#endif
5871c43cc173Smrg
5872c27c18e8Smrg#ifndef DIR_SEPARATOR_2
5873c27c18e8Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5874c27c18e8Smrg#else /* DIR_SEPARATOR_2 */
5875c27c18e8Smrg# define IS_DIR_SEPARATOR(ch) \
5876c27c18e8Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5877c27c18e8Smrg#endif /* DIR_SEPARATOR_2 */
5878c43cc173Smrg
5879c27c18e8Smrg#ifndef PATH_SEPARATOR_2
5880c27c18e8Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5881c27c18e8Smrg#else /* PATH_SEPARATOR_2 */
5882c27c18e8Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5883c27c18e8Smrg#endif /* PATH_SEPARATOR_2 */
5884c43cc173Smrg
5885c27c18e8Smrg#ifndef FOPEN_WB
5886c27c18e8Smrg# define FOPEN_WB "w"
5887c27c18e8Smrg#endif
5888c27c18e8Smrg#ifndef _O_BINARY
5889c27c18e8Smrg# define _O_BINARY 0
5890c27c18e8Smrg#endif
5891c43cc173Smrg
5892c27c18e8Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5893c27c18e8Smrg#define XFREE(stale) do { \
589448e5ce07Smrg  if (stale) { free (stale); stale = 0; } \
5895c27c18e8Smrg} while (0)
5896c43cc173Smrg
589748e5ce07Smrg#if defined LT_DEBUGWRAPPER
589837eb1ca1Smrgstatic int lt_debug = 1;
5899c27c18e8Smrg#else
590037eb1ca1Smrgstatic int lt_debug = 0;
5901c27c18e8Smrg#endif
5902c43cc173Smrg
590337eb1ca1Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5904c43cc173Smrg
5905c27c18e8Smrgvoid *xmalloc (size_t num);
5906c27c18e8Smrgchar *xstrdup (const char *string);
5907c27c18e8Smrgconst char *base_name (const char *name);
5908c27c18e8Smrgchar *find_executable (const char *wrapper);
5909c27c18e8Smrgchar *chase_symlinks (const char *pathspec);
5910c27c18e8Smrgint make_executable (const char *path);
5911c27c18e8Smrgint check_executable (const char *path);
5912c27c18e8Smrgchar *strendzap (char *str, const char *pat);
591337eb1ca1Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
591437eb1ca1Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
591537eb1ca1Smrgstatic const char *nonnull (const char *s);
591637eb1ca1Smrgstatic const char *nonempty (const char *s);
5917c27c18e8Smrgvoid lt_setenv (const char *name, const char *value);
5918c27c18e8Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5919c27c18e8Smrgvoid lt_update_exe_path (const char *name, const char *value);
5920c27c18e8Smrgvoid lt_update_lib_path (const char *name, const char *value);
592137eb1ca1Smrgchar **prepare_spawn (char **argv);
592237eb1ca1Smrgvoid lt_dump_script (FILE *f);
5923c27c18e8SmrgEOF
5924c27c18e8Smrg
5925c27c18e8Smrg	    cat <<EOF
592648e5ce07Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
592748e5ce07Smrg# define externally_visible volatile
592848e5ce07Smrg#else
592948e5ce07Smrg# define externally_visible __attribute__((externally_visible)) volatile
593048e5ce07Smrg#endif
593148e5ce07Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5932c27c18e8Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5933c27c18e8SmrgEOF
5934c43cc173Smrg
593548e5ce07Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5936b789ec8aSmrg              func_to_host_path "$temp_rpath"
5937c27c18e8Smrg	      cat <<EOF
5938b789ec8aSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5939c27c18e8SmrgEOF
5940c27c18e8Smrg	    else
5941c27c18e8Smrg	      cat <<"EOF"
5942c27c18e8Smrgconst char * LIB_PATH_VALUE   = "";
5943c27c18e8SmrgEOF
5944c27c18e8Smrg	    fi
5945c43cc173Smrg
5946c27c18e8Smrg	    if test -n "$dllsearchpath"; then
5947b789ec8aSmrg              func_to_host_path "$dllsearchpath:"
5948c27c18e8Smrg	      cat <<EOF
5949c27c18e8Smrgconst char * EXE_PATH_VARNAME = "PATH";
5950b789ec8aSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5951c27c18e8SmrgEOF
5952c27c18e8Smrg	    else
5953c27c18e8Smrg	      cat <<"EOF"
5954c27c18e8Smrgconst char * EXE_PATH_VARNAME = "";
5955c27c18e8Smrgconst char * EXE_PATH_VALUE   = "";
5956c27c18e8SmrgEOF
5957c27c18e8Smrg	    fi
5958c43cc173Smrg
595948e5ce07Smrg	    if test yes = "$fast_install"; then
5960c27c18e8Smrg	      cat <<EOF
5961c27c18e8Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5962c27c18e8SmrgEOF
5963c27c18e8Smrg	    else
5964c27c18e8Smrg	      cat <<EOF
5965c27c18e8Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5966c27c18e8SmrgEOF
5967c27c18e8Smrg	    fi
5968c43cc173Smrg
5969c43cc173Smrg
5970c27c18e8Smrg	    cat <<"EOF"
5971c43cc173Smrg
5972c27c18e8Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5973c43cc173Smrg
5974c27c18e8Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5975c27c18e8Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
597637eb1ca1Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5977c27c18e8Smrg
5978c27c18e8Smrgint
5979c27c18e8Smrgmain (int argc, char *argv[])
5980c27c18e8Smrg{
5981c27c18e8Smrg  char **newargz;
5982c27c18e8Smrg  int  newargc;
5983c27c18e8Smrg  char *tmp_pathspec;
5984c27c18e8Smrg  char *actual_cwrapper_path;
5985c27c18e8Smrg  char *actual_cwrapper_name;
5986c27c18e8Smrg  char *target_name;
5987c27c18e8Smrg  char *lt_argv_zero;
598848e5ce07Smrg  int rval = 127;
5989c27c18e8Smrg
5990c27c18e8Smrg  int i;
5991c27c18e8Smrg
5992c27c18e8Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
599348e5ce07Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5994c27c18e8Smrg
599537eb1ca1Smrg  /* very simple arg parsing; don't want to rely on getopt
599637eb1ca1Smrg   * also, copy all non cwrapper options to newargz, except
599737eb1ca1Smrg   * argz[0], which is handled differently
599837eb1ca1Smrg   */
599937eb1ca1Smrg  newargc=0;
6000c27c18e8Smrg  for (i = 1; i < argc; i++)
6001c27c18e8Smrg    {
600248e5ce07Smrg      if (STREQ (argv[i], dumpscript_opt))
6003c27c18e8Smrg	{
6004c27c18e8SmrgEOF
600548e5ce07Smrg	    case $host in
6006c27c18e8Smrg	      *mingw* | *cygwin* )
6007c27c18e8Smrg		# make stdout use "unix" line endings
6008c27c18e8Smrg		echo "          setmode(1,_O_BINARY);"
6009c27c18e8Smrg		;;
6010c27c18e8Smrg	      esac
6011c27c18e8Smrg
6012c27c18e8Smrg	    cat <<"EOF"
601337eb1ca1Smrg	  lt_dump_script (stdout);
6014c27c18e8Smrg	  return 0;
6015c27c18e8Smrg	}
601648e5ce07Smrg      if (STREQ (argv[i], debug_opt))
601737eb1ca1Smrg	{
601837eb1ca1Smrg          lt_debug = 1;
601937eb1ca1Smrg          continue;
602037eb1ca1Smrg	}
602148e5ce07Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602237eb1ca1Smrg        {
602337eb1ca1Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
602437eb1ca1Smrg             namespace, but it is not one of the ones we know about and
602537eb1ca1Smrg             have already dealt with, above (inluding dump-script), then
602637eb1ca1Smrg             report an error. Otherwise, targets might begin to believe
602737eb1ca1Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
602837eb1ca1Smrg             namespace. The first time any user complains about this, we'll
602937eb1ca1Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603037eb1ca1Smrg             or a configure.ac-settable value.
603137eb1ca1Smrg           */
603237eb1ca1Smrg          lt_fatal (__FILE__, __LINE__,
603337eb1ca1Smrg		    "unrecognized %s option: '%s'",
603437eb1ca1Smrg                    ltwrapper_option_prefix, argv[i]);
603537eb1ca1Smrg        }
603637eb1ca1Smrg      /* otherwise ... */
603737eb1ca1Smrg      newargz[++newargc] = xstrdup (argv[i]);
6038c27c18e8Smrg    }
603937eb1ca1Smrg  newargz[++newargc] = NULL;
604037eb1ca1Smrg
604137eb1ca1SmrgEOF
604237eb1ca1Smrg	    cat <<EOF
604337eb1ca1Smrg  /* The GNU banner must be the first non-error debug message */
604448e5ce07Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
604537eb1ca1SmrgEOF
604637eb1ca1Smrg	    cat <<"EOF"
604737eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
604837eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6049c27c18e8Smrg
6050c27c18e8Smrg  tmp_pathspec = find_executable (argv[0]);
6051c27c18e8Smrg  if (tmp_pathspec == NULL)
605237eb1ca1Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
605337eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
605437eb1ca1Smrg                  "(main) found exe (before symlink chase) at: %s\n",
605537eb1ca1Smrg		  tmp_pathspec);
6056c27c18e8Smrg
6057c27c18e8Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
605837eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
605937eb1ca1Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606037eb1ca1Smrg		  actual_cwrapper_path);
6061c27c18e8Smrg  XFREE (tmp_pathspec);
6062c27c18e8Smrg
606337eb1ca1Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6064c27c18e8Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6065c27c18e8Smrg
6066c27c18e8Smrg  /* wrapper name transforms */
6067c27c18e8Smrg  strendzap (actual_cwrapper_name, ".exe");
6068c27c18e8Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6069c27c18e8Smrg  XFREE (actual_cwrapper_name);
6070c27c18e8Smrg  actual_cwrapper_name = tmp_pathspec;
6071c27c18e8Smrg  tmp_pathspec = 0;
6072c27c18e8Smrg
6073c27c18e8Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6074c27c18e8Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6075c27c18e8Smrg  strendzap (target_name, ".exe");
6076c27c18e8Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6077c27c18e8Smrg  XFREE (target_name);
6078c27c18e8Smrg  target_name = tmp_pathspec;
6079c27c18e8Smrg  tmp_pathspec = 0;
6080c27c18e8Smrg
608137eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
608237eb1ca1Smrg		  "(main) libtool target name: %s\n",
608337eb1ca1Smrg		  target_name);
6084c27c18e8SmrgEOF
6085c27c18e8Smrg
6086c27c18e8Smrg	    cat <<EOF
6087c27c18e8Smrg  newargz[0] =
6088c27c18e8Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6089c27c18e8Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6090c27c18e8Smrg  strcpy (newargz[0], actual_cwrapper_path);
6091c27c18e8Smrg  strcat (newargz[0], "$objdir");
6092c27c18e8Smrg  strcat (newargz[0], "/");
6093c27c18e8SmrgEOF
6094c27c18e8Smrg
6095c27c18e8Smrg	    cat <<"EOF"
6096c27c18e8Smrg  /* stop here, and copy so we don't have to do this twice */
6097c27c18e8Smrg  tmp_pathspec = xstrdup (newargz[0]);
6098c27c18e8Smrg
6099c27c18e8Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6100c27c18e8Smrg  strcat (newargz[0], actual_cwrapper_name);
6101c27c18e8Smrg
6102c27c18e8Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6103c27c18e8Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6104c27c18e8Smrg  XFREE (tmp_pathspec);
6105c27c18e8Smrg  tmp_pathspec = NULL;
6106c27c18e8SmrgEOF
6107c27c18e8Smrg
6108c27c18e8Smrg	    case $host_os in
6109c27c18e8Smrg	      mingw*)
6110c27c18e8Smrg	    cat <<"EOF"
6111c27c18e8Smrg  {
6112c27c18e8Smrg    char* p;
6113c27c18e8Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6114c27c18e8Smrg      {
6115c27c18e8Smrg	*p = '/';
6116c27c18e8Smrg      }
6117c27c18e8Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6118c27c18e8Smrg      {
6119c27c18e8Smrg	*p = '/';
6120c27c18e8Smrg      }
6121c27c18e8Smrg  }
6122c27c18e8SmrgEOF
6123c43cc173Smrg	    ;;
6124c27c18e8Smrg	    esac
6125c27c18e8Smrg
6126c27c18e8Smrg	    cat <<"EOF"
6127c27c18e8Smrg  XFREE (target_name);
6128c27c18e8Smrg  XFREE (actual_cwrapper_path);
6129c27c18e8Smrg  XFREE (actual_cwrapper_name);
6130c27c18e8Smrg
6131c27c18e8Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6132c27c18e8Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6133b789ec8aSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6134b789ec8aSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6135b789ec8aSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6136b789ec8aSmrg     libraries must come first. */
6137c27c18e8Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6138b789ec8aSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6139c27c18e8Smrg
614037eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614137eb1ca1Smrg		  nonnull (lt_argv_zero));
6142c27c18e8Smrg  for (i = 0; i < newargc; i++)
6143c27c18e8Smrg    {
614437eb1ca1Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
614537eb1ca1Smrg		      i, nonnull (newargz[i]));
6146c27c18e8Smrg    }
6147c43cc173Smrg
6148c43cc173SmrgEOF
6149c43cc173Smrg
6150c27c18e8Smrg	    case $host_os in
6151c27c18e8Smrg	      mingw*)
6152c27c18e8Smrg		cat <<"EOF"
6153c27c18e8Smrg  /* execv doesn't actually work on mingw as expected on unix */
615437eb1ca1Smrg  newargz = prepare_spawn (newargz);
615548e5ce07Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6156c27c18e8Smrg  if (rval == -1)
6157c27c18e8Smrg    {
6158c27c18e8Smrg      /* failed to start process */
615937eb1ca1Smrg      lt_debugprintf (__FILE__, __LINE__,
616037eb1ca1Smrg		      "(main) failed to launch target \"%s\": %s\n",
616137eb1ca1Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6162c27c18e8Smrg      return 127;
6163c27c18e8Smrg    }
6164c27c18e8Smrg  return rval;
6165c27c18e8SmrgEOF
6166c27c18e8Smrg		;;
6167c27c18e8Smrg	      *)
6168c27c18e8Smrg		cat <<"EOF"
6169c27c18e8Smrg  execv (lt_argv_zero, newargz);
6170c27c18e8Smrg  return rval; /* =127, but avoids unused variable warning */
6171c27c18e8SmrgEOF
6172c27c18e8Smrg		;;
6173c27c18e8Smrg	    esac
6174c43cc173Smrg
6175c27c18e8Smrg	    cat <<"EOF"
6176c27c18e8Smrg}
6177c43cc173Smrg
6178c27c18e8Smrgvoid *
6179c27c18e8Smrgxmalloc (size_t num)
6180c27c18e8Smrg{
6181c27c18e8Smrg  void *p = (void *) malloc (num);
6182c27c18e8Smrg  if (!p)
618337eb1ca1Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6184c43cc173Smrg
6185c27c18e8Smrg  return p;
6186c27c18e8Smrg}
6187c43cc173Smrg
6188c27c18e8Smrgchar *
6189c27c18e8Smrgxstrdup (const char *string)
6190c27c18e8Smrg{
6191c27c18e8Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6192c27c18e8Smrg			  string) : NULL;
6193c27c18e8Smrg}
6194c43cc173Smrg
6195c27c18e8Smrgconst char *
6196c27c18e8Smrgbase_name (const char *name)
6197c27c18e8Smrg{
6198c27c18e8Smrg  const char *base;
6199c43cc173Smrg
620048e5ce07Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6201c27c18e8Smrg  /* Skip over the disk name in MSDOS pathnames. */
6202c27c18e8Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6203c27c18e8Smrg    name += 2;
6204c27c18e8Smrg#endif
6205c43cc173Smrg
6206c27c18e8Smrg  for (base = name; *name; name++)
6207c27c18e8Smrg    if (IS_DIR_SEPARATOR (*name))
6208c27c18e8Smrg      base = name + 1;
6209c27c18e8Smrg  return base;
6210c27c18e8Smrg}
6211c43cc173Smrg
6212c27c18e8Smrgint
6213c27c18e8Smrgcheck_executable (const char *path)
6214c27c18e8Smrg{
6215c27c18e8Smrg  struct stat st;
6216c43cc173Smrg
621737eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
621837eb1ca1Smrg                  nonempty (path));
6219c27c18e8Smrg  if ((!path) || (!*path))
6220c27c18e8Smrg    return 0;
6221c43cc173Smrg
6222c27c18e8Smrg  if ((stat (path, &st) >= 0)
6223c27c18e8Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6224c27c18e8Smrg    return 1;
6225c27c18e8Smrg  else
6226c27c18e8Smrg    return 0;
6227c27c18e8Smrg}
6228c43cc173Smrg
6229c27c18e8Smrgint
6230c27c18e8Smrgmake_executable (const char *path)
6231c27c18e8Smrg{
6232c27c18e8Smrg  int rval = 0;
6233c27c18e8Smrg  struct stat st;
6234c43cc173Smrg
623537eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
623637eb1ca1Smrg                  nonempty (path));
6237c27c18e8Smrg  if ((!path) || (!*path))
6238c27c18e8Smrg    return 0;
6239c43cc173Smrg
6240c27c18e8Smrg  if (stat (path, &st) >= 0)
6241c27c18e8Smrg    {
6242c27c18e8Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6243c27c18e8Smrg    }
6244c27c18e8Smrg  return rval;
6245c27c18e8Smrg}
6246c43cc173Smrg
6247c27c18e8Smrg/* Searches for the full path of the wrapper.  Returns
6248c27c18e8Smrg   newly allocated full path name if found, NULL otherwise
6249c27c18e8Smrg   Does not chase symlinks, even on platforms that support them.
6250c27c18e8Smrg*/
6251c27c18e8Smrgchar *
6252c27c18e8Smrgfind_executable (const char *wrapper)
6253c27c18e8Smrg{
6254c27c18e8Smrg  int has_slash = 0;
6255c27c18e8Smrg  const char *p;
6256c27c18e8Smrg  const char *p_next;
6257c27c18e8Smrg  /* static buffer for getcwd */
6258c27c18e8Smrg  char tmp[LT_PATHMAX + 1];
625948e5ce07Smrg  size_t tmp_len;
6260c27c18e8Smrg  char *concat_name;
6261c43cc173Smrg
626237eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
626337eb1ca1Smrg                  nonempty (wrapper));
6264c43cc173Smrg
6265c27c18e8Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6266c27c18e8Smrg    return NULL;
6267c43cc173Smrg
6268c27c18e8Smrg  /* Absolute path? */
626948e5ce07Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6270c27c18e8Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6271c27c18e8Smrg    {
6272c27c18e8Smrg      concat_name = xstrdup (wrapper);
6273c27c18e8Smrg      if (check_executable (concat_name))
6274c27c18e8Smrg	return concat_name;
6275c27c18e8Smrg      XFREE (concat_name);
6276c27c18e8Smrg    }
6277c27c18e8Smrg  else
6278c27c18e8Smrg    {
6279c27c18e8Smrg#endif
6280c27c18e8Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6281c27c18e8Smrg	{
6282c27c18e8Smrg	  concat_name = xstrdup (wrapper);
6283c27c18e8Smrg	  if (check_executable (concat_name))
6284c27c18e8Smrg	    return concat_name;
6285c27c18e8Smrg	  XFREE (concat_name);
6286c27c18e8Smrg	}
628748e5ce07Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6288c27c18e8Smrg    }
6289c27c18e8Smrg#endif
6290c43cc173Smrg
6291c27c18e8Smrg  for (p = wrapper; *p; p++)
6292c27c18e8Smrg    if (*p == '/')
6293c27c18e8Smrg      {
6294c27c18e8Smrg	has_slash = 1;
6295c27c18e8Smrg	break;
6296c27c18e8Smrg      }
6297c27c18e8Smrg  if (!has_slash)
6298c27c18e8Smrg    {
6299c27c18e8Smrg      /* no slashes; search PATH */
6300c27c18e8Smrg      const char *path = getenv ("PATH");
6301c27c18e8Smrg      if (path != NULL)
6302c27c18e8Smrg	{
6303c27c18e8Smrg	  for (p = path; *p; p = p_next)
6304c27c18e8Smrg	    {
6305c27c18e8Smrg	      const char *q;
6306c27c18e8Smrg	      size_t p_len;
6307c27c18e8Smrg	      for (q = p; *q; q++)
6308c27c18e8Smrg		if (IS_PATH_SEPARATOR (*q))
6309c27c18e8Smrg		  break;
631048e5ce07Smrg	      p_len = (size_t) (q - p);
6311c27c18e8Smrg	      p_next = (*q == '\0' ? q : q + 1);
6312c27c18e8Smrg	      if (p_len == 0)
6313c27c18e8Smrg		{
6314c27c18e8Smrg		  /* empty path: current directory */
6315c27c18e8Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
631637eb1ca1Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
631737eb1ca1Smrg                              nonnull (strerror (errno)));
6318c27c18e8Smrg		  tmp_len = strlen (tmp);
6319c27c18e8Smrg		  concat_name =
6320c27c18e8Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6321c27c18e8Smrg		  memcpy (concat_name, tmp, tmp_len);
6322c27c18e8Smrg		  concat_name[tmp_len] = '/';
6323c27c18e8Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6324c27c18e8Smrg		}
6325c27c18e8Smrg	      else
6326c27c18e8Smrg		{
6327c27c18e8Smrg		  concat_name =
6328c27c18e8Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6329c27c18e8Smrg		  memcpy (concat_name, p, p_len);
6330c27c18e8Smrg		  concat_name[p_len] = '/';
6331c27c18e8Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6332c27c18e8Smrg		}
6333c27c18e8Smrg	      if (check_executable (concat_name))
6334c27c18e8Smrg		return concat_name;
6335c27c18e8Smrg	      XFREE (concat_name);
6336c27c18e8Smrg	    }
6337c27c18e8Smrg	}
6338c27c18e8Smrg      /* not found in PATH; assume curdir */
6339c27c18e8Smrg    }
6340c27c18e8Smrg  /* Relative path | not found in path: prepend cwd */
6341c27c18e8Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634237eb1ca1Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
634337eb1ca1Smrg              nonnull (strerror (errno)));
6344c27c18e8Smrg  tmp_len = strlen (tmp);
6345c27c18e8Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6346c27c18e8Smrg  memcpy (concat_name, tmp, tmp_len);
6347c27c18e8Smrg  concat_name[tmp_len] = '/';
6348c27c18e8Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6349c43cc173Smrg
6350c27c18e8Smrg  if (check_executable (concat_name))
6351c27c18e8Smrg    return concat_name;
6352c27c18e8Smrg  XFREE (concat_name);
6353c27c18e8Smrg  return NULL;
6354c27c18e8Smrg}
6355c43cc173Smrg
6356c27c18e8Smrgchar *
6357c27c18e8Smrgchase_symlinks (const char *pathspec)
6358c27c18e8Smrg{
6359c27c18e8Smrg#ifndef S_ISLNK
6360c27c18e8Smrg  return xstrdup (pathspec);
6361c27c18e8Smrg#else
6362c27c18e8Smrg  char buf[LT_PATHMAX];
6363c27c18e8Smrg  struct stat s;
6364c27c18e8Smrg  char *tmp_pathspec = xstrdup (pathspec);
6365c27c18e8Smrg  char *p;
6366c27c18e8Smrg  int has_symlinks = 0;
6367c27c18e8Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6368c27c18e8Smrg    {
636937eb1ca1Smrg      lt_debugprintf (__FILE__, __LINE__,
637037eb1ca1Smrg		      "checking path component for symlinks: %s\n",
637137eb1ca1Smrg		      tmp_pathspec);
6372c27c18e8Smrg      if (lstat (tmp_pathspec, &s) == 0)
6373c27c18e8Smrg	{
6374c27c18e8Smrg	  if (S_ISLNK (s.st_mode) != 0)
6375c27c18e8Smrg	    {
6376c27c18e8Smrg	      has_symlinks = 1;
6377c27c18e8Smrg	      break;
6378c27c18e8Smrg	    }
6379c43cc173Smrg
6380c27c18e8Smrg	  /* search backwards for last DIR_SEPARATOR */
6381c27c18e8Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6382c27c18e8Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6383c27c18e8Smrg	    p--;
6384c27c18e8Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6385c27c18e8Smrg	    {
6386c27c18e8Smrg	      /* no more DIR_SEPARATORS left */
6387c27c18e8Smrg	      break;
6388c27c18e8Smrg	    }
6389c27c18e8Smrg	  *p = '\0';
6390c27c18e8Smrg	}
6391c27c18e8Smrg      else
6392c27c18e8Smrg	{
639337eb1ca1Smrg	  lt_fatal (__FILE__, __LINE__,
639437eb1ca1Smrg		    "error accessing file \"%s\": %s",
639537eb1ca1Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6396c27c18e8Smrg	}
6397c27c18e8Smrg    }
6398c27c18e8Smrg  XFREE (tmp_pathspec);
6399c43cc173Smrg
6400c27c18e8Smrg  if (!has_symlinks)
6401c27c18e8Smrg    {
6402c27c18e8Smrg      return xstrdup (pathspec);
6403c27c18e8Smrg    }
6404c43cc173Smrg
6405c27c18e8Smrg  tmp_pathspec = realpath (pathspec, buf);
6406c27c18e8Smrg  if (tmp_pathspec == 0)
6407c27c18e8Smrg    {
640837eb1ca1Smrg      lt_fatal (__FILE__, __LINE__,
640937eb1ca1Smrg		"could not follow symlinks for %s", pathspec);
6410c27c18e8Smrg    }
6411c27c18e8Smrg  return xstrdup (tmp_pathspec);
6412c27c18e8Smrg#endif
6413c27c18e8Smrg}
6414c43cc173Smrg
6415c27c18e8Smrgchar *
6416c27c18e8Smrgstrendzap (char *str, const char *pat)
6417c27c18e8Smrg{
6418c27c18e8Smrg  size_t len, patlen;
6419c43cc173Smrg
6420c27c18e8Smrg  assert (str != NULL);
6421c27c18e8Smrg  assert (pat != NULL);
6422c43cc173Smrg
6423c27c18e8Smrg  len = strlen (str);
6424c27c18e8Smrg  patlen = strlen (pat);
6425c43cc173Smrg
6426c27c18e8Smrg  if (patlen <= len)
6427c27c18e8Smrg    {
6428c27c18e8Smrg      str += len - patlen;
642948e5ce07Smrg      if (STREQ (str, pat))
6430c27c18e8Smrg	*str = '\0';
6431c27c18e8Smrg    }
6432c27c18e8Smrg  return str;
6433c27c18e8Smrg}
6434c43cc173Smrg
643537eb1ca1Smrgvoid
643637eb1ca1Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
643737eb1ca1Smrg{
643837eb1ca1Smrg  va_list args;
643937eb1ca1Smrg  if (lt_debug)
644037eb1ca1Smrg    {
644137eb1ca1Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644237eb1ca1Smrg      va_start (args, fmt);
644337eb1ca1Smrg      (void) vfprintf (stderr, fmt, args);
644437eb1ca1Smrg      va_end (args);
644537eb1ca1Smrg    }
644637eb1ca1Smrg}
644737eb1ca1Smrg
6448c27c18e8Smrgstatic void
644937eb1ca1Smrglt_error_core (int exit_status, const char *file,
645037eb1ca1Smrg	       int line, const char *mode,
6451c27c18e8Smrg	       const char *message, va_list ap)
6452c27c18e8Smrg{
645337eb1ca1Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6454c27c18e8Smrg  vfprintf (stderr, message, ap);
6455c27c18e8Smrg  fprintf (stderr, ".\n");
6456c43cc173Smrg
6457c27c18e8Smrg  if (exit_status >= 0)
6458c27c18e8Smrg    exit (exit_status);
6459c27c18e8Smrg}
6460c43cc173Smrg
6461c27c18e8Smrgvoid
646237eb1ca1Smrglt_fatal (const char *file, int line, const char *message, ...)
6463c27c18e8Smrg{
6464c27c18e8Smrg  va_list ap;
6465c27c18e8Smrg  va_start (ap, message);
646637eb1ca1Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6467c27c18e8Smrg  va_end (ap);
6468c27c18e8Smrg}
6469c43cc173Smrg
647037eb1ca1Smrgstatic const char *
647137eb1ca1Smrgnonnull (const char *s)
647237eb1ca1Smrg{
647337eb1ca1Smrg  return s ? s : "(null)";
647437eb1ca1Smrg}
647537eb1ca1Smrg
647637eb1ca1Smrgstatic const char *
647737eb1ca1Smrgnonempty (const char *s)
647837eb1ca1Smrg{
647937eb1ca1Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648037eb1ca1Smrg}
648137eb1ca1Smrg
6482c27c18e8Smrgvoid
6483c27c18e8Smrglt_setenv (const char *name, const char *value)
6484c27c18e8Smrg{
648537eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
648637eb1ca1Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
648737eb1ca1Smrg                  nonnull (name), nonnull (value));
6488c27c18e8Smrg  {
6489c27c18e8Smrg#ifdef HAVE_SETENV
6490c27c18e8Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6491c27c18e8Smrg    char *str = xstrdup (value);
6492c27c18e8Smrg    setenv (name, str, 1);
6493c27c18e8Smrg#else
649448e5ce07Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6495c27c18e8Smrg    char *str = XMALLOC (char, len);
6496c27c18e8Smrg    sprintf (str, "%s=%s", name, value);
6497c27c18e8Smrg    if (putenv (str) != EXIT_SUCCESS)
6498c27c18e8Smrg      {
6499c27c18e8Smrg        XFREE (str);
6500c27c18e8Smrg      }
6501c27c18e8Smrg#endif
6502c27c18e8Smrg  }
6503c27c18e8Smrg}
6504c43cc173Smrg
6505c27c18e8Smrgchar *
6506c27c18e8Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6507c27c18e8Smrg{
6508c27c18e8Smrg  char *new_value;
6509c27c18e8Smrg  if (orig_value && *orig_value)
6510c27c18e8Smrg    {
651148e5ce07Smrg      size_t orig_value_len = strlen (orig_value);
651248e5ce07Smrg      size_t add_len = strlen (add);
6513c27c18e8Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6514c27c18e8Smrg      if (to_end)
6515c27c18e8Smrg        {
6516c27c18e8Smrg          strcpy (new_value, orig_value);
6517c27c18e8Smrg          strcpy (new_value + orig_value_len, add);
6518c27c18e8Smrg        }
6519c27c18e8Smrg      else
6520c27c18e8Smrg        {
6521c27c18e8Smrg          strcpy (new_value, add);
6522c27c18e8Smrg          strcpy (new_value + add_len, orig_value);
6523c27c18e8Smrg        }
6524c27c18e8Smrg    }
6525c27c18e8Smrg  else
6526c27c18e8Smrg    {
6527c27c18e8Smrg      new_value = xstrdup (add);
6528c27c18e8Smrg    }
6529c27c18e8Smrg  return new_value;
6530c27c18e8Smrg}
6531c43cc173Smrg
6532c27c18e8Smrgvoid
6533c27c18e8Smrglt_update_exe_path (const char *name, const char *value)
6534c27c18e8Smrg{
653537eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
653637eb1ca1Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
653737eb1ca1Smrg                  nonnull (name), nonnull (value));
6538c43cc173Smrg
6539c27c18e8Smrg  if (name && *name && value && *value)
6540c27c18e8Smrg    {
6541c27c18e8Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6542c27c18e8Smrg      /* some systems can't cope with a ':'-terminated path #' */
654348e5ce07Smrg      size_t len = strlen (new_value);
654448e5ce07Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6545c27c18e8Smrg        {
654648e5ce07Smrg          new_value[--len] = '\0';
6547c27c18e8Smrg        }
6548c27c18e8Smrg      lt_setenv (name, new_value);
6549c27c18e8Smrg      XFREE (new_value);
6550c27c18e8Smrg    }
6551c27c18e8Smrg}
6552c43cc173Smrg
6553c27c18e8Smrgvoid
6554c27c18e8Smrglt_update_lib_path (const char *name, const char *value)
6555c27c18e8Smrg{
655637eb1ca1Smrg  lt_debugprintf (__FILE__, __LINE__,
655737eb1ca1Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
655837eb1ca1Smrg                  nonnull (name), nonnull (value));
6559c43cc173Smrg
6560c27c18e8Smrg  if (name && *name && value && *value)
6561c27c18e8Smrg    {
6562c27c18e8Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6563c27c18e8Smrg      lt_setenv (name, new_value);
6564c27c18e8Smrg      XFREE (new_value);
6565c27c18e8Smrg    }
6566c27c18e8Smrg}
6567c43cc173Smrg
656837eb1ca1SmrgEOF
656937eb1ca1Smrg	    case $host_os in
657037eb1ca1Smrg	      mingw*)
657137eb1ca1Smrg		cat <<"EOF"
657237eb1ca1Smrg
657337eb1ca1Smrg/* Prepares an argument vector before calling spawn().
657437eb1ca1Smrg   Note that spawn() does not by itself call the command interpreter
657537eb1ca1Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
657637eb1ca1Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
657737eb1ca1Smrg         GetVersionEx(&v);
657837eb1ca1Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
657937eb1ca1Smrg      }) ? "cmd.exe" : "command.com").
658037eb1ca1Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658137eb1ca1Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658237eb1ca1Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
658337eb1ca1Smrg   special way:
658437eb1ca1Smrg   - Space and tab are interpreted as delimiters. They are not treated as
658537eb1ca1Smrg     delimiters if they are surrounded by double quotes: "...".
658637eb1ca1Smrg   - Unescaped double quotes are removed from the input. Their only effect is
658737eb1ca1Smrg     that within double quotes, space and tab are treated like normal
658837eb1ca1Smrg     characters.
658937eb1ca1Smrg   - Backslashes not followed by double quotes are not special.
659037eb1ca1Smrg   - But 2*n+1 backslashes followed by a double quote become
659137eb1ca1Smrg     n backslashes followed by a double quote (n >= 0):
659237eb1ca1Smrg       \" -> "
659337eb1ca1Smrg       \\\" -> \"
659437eb1ca1Smrg       \\\\\" -> \\"
659537eb1ca1Smrg */
659637eb1ca1Smrg#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"
659737eb1ca1Smrg#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"
659837eb1ca1Smrgchar **
659937eb1ca1Smrgprepare_spawn (char **argv)
660037eb1ca1Smrg{
660137eb1ca1Smrg  size_t argc;
660237eb1ca1Smrg  char **new_argv;
660337eb1ca1Smrg  size_t i;
660437eb1ca1Smrg
660537eb1ca1Smrg  /* Count number of arguments.  */
660637eb1ca1Smrg  for (argc = 0; argv[argc] != NULL; argc++)
660737eb1ca1Smrg    ;
660837eb1ca1Smrg
660937eb1ca1Smrg  /* Allocate new argument vector.  */
661037eb1ca1Smrg  new_argv = XMALLOC (char *, argc + 1);
661137eb1ca1Smrg
661237eb1ca1Smrg  /* Put quoted arguments into the new argument vector.  */
661337eb1ca1Smrg  for (i = 0; i < argc; i++)
661437eb1ca1Smrg    {
661537eb1ca1Smrg      const char *string = argv[i];
661637eb1ca1Smrg
661737eb1ca1Smrg      if (string[0] == '\0')
661837eb1ca1Smrg	new_argv[i] = xstrdup ("\"\"");
661937eb1ca1Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662037eb1ca1Smrg	{
662137eb1ca1Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662237eb1ca1Smrg	  size_t length;
662337eb1ca1Smrg	  unsigned int backslashes;
662437eb1ca1Smrg	  const char *s;
662537eb1ca1Smrg	  char *quoted_string;
662637eb1ca1Smrg	  char *p;
662737eb1ca1Smrg
662837eb1ca1Smrg	  length = 0;
662937eb1ca1Smrg	  backslashes = 0;
663037eb1ca1Smrg	  if (quote_around)
663137eb1ca1Smrg	    length++;
663237eb1ca1Smrg	  for (s = string; *s != '\0'; s++)
663337eb1ca1Smrg	    {
663437eb1ca1Smrg	      char c = *s;
663537eb1ca1Smrg	      if (c == '"')
663637eb1ca1Smrg		length += backslashes + 1;
663737eb1ca1Smrg	      length++;
663837eb1ca1Smrg	      if (c == '\\')
663937eb1ca1Smrg		backslashes++;
664037eb1ca1Smrg	      else
664137eb1ca1Smrg		backslashes = 0;
664237eb1ca1Smrg	    }
664337eb1ca1Smrg	  if (quote_around)
664437eb1ca1Smrg	    length += backslashes + 1;
664537eb1ca1Smrg
664637eb1ca1Smrg	  quoted_string = XMALLOC (char, length + 1);
664737eb1ca1Smrg
664837eb1ca1Smrg	  p = quoted_string;
664937eb1ca1Smrg	  backslashes = 0;
665037eb1ca1Smrg	  if (quote_around)
665137eb1ca1Smrg	    *p++ = '"';
665237eb1ca1Smrg	  for (s = string; *s != '\0'; s++)
665337eb1ca1Smrg	    {
665437eb1ca1Smrg	      char c = *s;
665537eb1ca1Smrg	      if (c == '"')
665637eb1ca1Smrg		{
665737eb1ca1Smrg		  unsigned int j;
665837eb1ca1Smrg		  for (j = backslashes + 1; j > 0; j--)
665937eb1ca1Smrg		    *p++ = '\\';
666037eb1ca1Smrg		}
666137eb1ca1Smrg	      *p++ = c;
666237eb1ca1Smrg	      if (c == '\\')
666337eb1ca1Smrg		backslashes++;
666437eb1ca1Smrg	      else
666537eb1ca1Smrg		backslashes = 0;
666637eb1ca1Smrg	    }
666737eb1ca1Smrg	  if (quote_around)
666837eb1ca1Smrg	    {
666937eb1ca1Smrg	      unsigned int j;
667037eb1ca1Smrg	      for (j = backslashes; j > 0; j--)
667137eb1ca1Smrg		*p++ = '\\';
667237eb1ca1Smrg	      *p++ = '"';
667337eb1ca1Smrg	    }
667437eb1ca1Smrg	  *p = '\0';
667537eb1ca1Smrg
667637eb1ca1Smrg	  new_argv[i] = quoted_string;
667737eb1ca1Smrg	}
667837eb1ca1Smrg      else
667937eb1ca1Smrg	new_argv[i] = (char *) string;
668037eb1ca1Smrg    }
668137eb1ca1Smrg  new_argv[argc] = NULL;
668237eb1ca1Smrg
668337eb1ca1Smrg  return new_argv;
668437eb1ca1Smrg}
668537eb1ca1SmrgEOF
668637eb1ca1Smrg		;;
668737eb1ca1Smrg	    esac
668837eb1ca1Smrg
668937eb1ca1Smrg            cat <<"EOF"
669037eb1ca1Smrgvoid lt_dump_script (FILE* f)
669137eb1ca1Smrg{
669237eb1ca1SmrgEOF
669337eb1ca1Smrg	    func_emit_wrapper yes |
6694f1ee322dSmrg	      $SED -n -e '
6695f1ee322dSmrgs/^\(.\{79\}\)\(..*\)/\1\
6696f1ee322dSmrg\2/
6697f1ee322dSmrgh
6698f1ee322dSmrgs/\([\\"]\)/\\\1/g
6699f1ee322dSmrgs/$/\\n/
6700f1ee322dSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6701f1ee322dSmrgg
6702f1ee322dSmrgD'
670337eb1ca1Smrg            cat <<"EOF"
670437eb1ca1Smrg}
6705c27c18e8SmrgEOF
6706c27c18e8Smrg}
6707c27c18e8Smrg# end: func_emit_cwrapperexe_src
6708c43cc173Smrg
670937eb1ca1Smrg# func_win32_import_lib_p ARG
671037eb1ca1Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671137eb1ca1Smrgfunc_win32_import_lib_p ()
671237eb1ca1Smrg{
671348e5ce07Smrg    $debug_cmd
671448e5ce07Smrg
671537eb1ca1Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
671637eb1ca1Smrg    *import*) : ;;
671737eb1ca1Smrg    *) false ;;
671837eb1ca1Smrg    esac
671937eb1ca1Smrg}
672037eb1ca1Smrg
672148e5ce07Smrg# func_suncc_cstd_abi
672248e5ce07Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
672348e5ce07Smrg# Several compiler flags select an ABI that is incompatible with the
672448e5ce07Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
672548e5ce07Smrgfunc_suncc_cstd_abi ()
672648e5ce07Smrg{
672748e5ce07Smrg    $debug_cmd
672848e5ce07Smrg
672948e5ce07Smrg    case " $compile_command " in
673048e5ce07Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
673148e5ce07Smrg      suncc_use_cstd_abi=no
673248e5ce07Smrg      ;;
673348e5ce07Smrg    *)
673448e5ce07Smrg      suncc_use_cstd_abi=yes
673548e5ce07Smrg      ;;
673648e5ce07Smrg    esac
673748e5ce07Smrg}
673848e5ce07Smrg
6739c27c18e8Smrg# func_mode_link arg...
6740c27c18e8Smrgfunc_mode_link ()
6741c27c18e8Smrg{
674248e5ce07Smrg    $debug_cmd
674348e5ce07Smrg
6744c27c18e8Smrg    case $host in
6745c27c18e8Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6746c27c18e8Smrg      # It is impossible to link a dll without this setting, and
6747c27c18e8Smrg      # we shouldn't force the makefile maintainer to figure out
674848e5ce07Smrg      # what system we are compiling for in order to pass an extra
6749c27c18e8Smrg      # flag for every libtool invocation.
6750c27c18e8Smrg      # allow_undefined=no
6751c43cc173Smrg
6752c27c18e8Smrg      # FIXME: Unfortunately, there are problems with the above when trying
675348e5ce07Smrg      # to make a dll that has undefined symbols, in which case not
6754c27c18e8Smrg      # even a static library is built.  For now, we need to specify
6755c27c18e8Smrg      # -no-undefined on the libtool link line when we can be certain
6756c27c18e8Smrg      # that all symbols are satisfied, otherwise we get a static library.
6757c27c18e8Smrg      allow_undefined=yes
6758c27c18e8Smrg      ;;
6759c27c18e8Smrg    *)
6760c27c18e8Smrg      allow_undefined=yes
6761c27c18e8Smrg      ;;
6762c27c18e8Smrg    esac
6763c27c18e8Smrg    libtool_args=$nonopt
6764c27c18e8Smrg    base_compile="$nonopt $@"
6765c27c18e8Smrg    compile_command=$nonopt
6766c27c18e8Smrg    finalize_command=$nonopt
6767c43cc173Smrg
6768c27c18e8Smrg    compile_rpath=
6769c27c18e8Smrg    finalize_rpath=
6770c27c18e8Smrg    compile_shlibpath=
6771c27c18e8Smrg    finalize_shlibpath=
6772c27c18e8Smrg    convenience=
6773c27c18e8Smrg    old_convenience=
6774c27c18e8Smrg    deplibs=
6775c27c18e8Smrg    old_deplibs=
6776c27c18e8Smrg    compiler_flags=
6777c27c18e8Smrg    linker_flags=
6778c27c18e8Smrg    dllsearchpath=
6779c27c18e8Smrg    lib_search_path=`pwd`
6780c27c18e8Smrg    inst_prefix_dir=
6781c27c18e8Smrg    new_inherited_linker_flags=
6782c43cc173Smrg
6783c27c18e8Smrg    avoid_version=no
678437eb1ca1Smrg    bindir=
6785c27c18e8Smrg    dlfiles=
6786c27c18e8Smrg    dlprefiles=
6787c27c18e8Smrg    dlself=no
6788c27c18e8Smrg    export_dynamic=no
6789c27c18e8Smrg    export_symbols=
6790c27c18e8Smrg    export_symbols_regex=
6791c27c18e8Smrg    generated=
6792c27c18e8Smrg    libobjs=
6793c27c18e8Smrg    ltlibs=
6794c27c18e8Smrg    module=no
6795c27c18e8Smrg    no_install=no
6796c27c18e8Smrg    objs=
679748e5ce07Smrg    os2dllname=
6798c27c18e8Smrg    non_pic_objects=
6799c27c18e8Smrg    precious_files_regex=
6800c27c18e8Smrg    prefer_static_libs=no
680148e5ce07Smrg    preload=false
6802c27c18e8Smrg    prev=
6803c27c18e8Smrg    prevarg=
6804c27c18e8Smrg    release=
6805c27c18e8Smrg    rpath=
6806c27c18e8Smrg    xrpath=
6807c27c18e8Smrg    perm_rpath=
6808c27c18e8Smrg    temp_rpath=
6809c27c18e8Smrg    thread_safe=no
6810c27c18e8Smrg    vinfo=
6811c27c18e8Smrg    vinfo_number=no
6812c27c18e8Smrg    weak_libs=
681348e5ce07Smrg    single_module=$wl-single_module
6814c27c18e8Smrg    func_infer_tag $base_compile
6815c43cc173Smrg
6816c27c18e8Smrg    # We need to know -static, to get the right output filenames.
6817c27c18e8Smrg    for arg
6818c27c18e8Smrg    do
6819c27c18e8Smrg      case $arg in
6820c27c18e8Smrg      -shared)
682148e5ce07Smrg	test yes != "$build_libtool_libs" \
682248e5ce07Smrg	  && func_fatal_configuration "cannot build a shared library"
6823c27c18e8Smrg	build_old_libs=no
6824c27c18e8Smrg	break
6825c27c18e8Smrg	;;
6826c27c18e8Smrg      -all-static | -static | -static-libtool-libs)
6827c27c18e8Smrg	case $arg in
6828c27c18e8Smrg	-all-static)
682948e5ce07Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6830c27c18e8Smrg	    func_warning "complete static linking is impossible in this configuration"
6831c27c18e8Smrg	  fi
6832c27c18e8Smrg	  if test -n "$link_static_flag"; then
6833c27c18e8Smrg	    dlopen_self=$dlopen_self_static
6834c27c18e8Smrg	  fi
6835c27c18e8Smrg	  prefer_static_libs=yes
6836c27c18e8Smrg	  ;;
6837c27c18e8Smrg	-static)
6838c27c18e8Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6839c27c18e8Smrg	    dlopen_self=$dlopen_self_static
6840c27c18e8Smrg	  fi
6841c27c18e8Smrg	  prefer_static_libs=built
6842c27c18e8Smrg	  ;;
6843c27c18e8Smrg	-static-libtool-libs)
6844c27c18e8Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6845c27c18e8Smrg	    dlopen_self=$dlopen_self_static
6846c27c18e8Smrg	  fi
6847c27c18e8Smrg	  prefer_static_libs=yes
6848c27c18e8Smrg	  ;;
6849c27c18e8Smrg	esac
6850c27c18e8Smrg	build_libtool_libs=no
6851c27c18e8Smrg	build_old_libs=yes
6852c27c18e8Smrg	break
6853c43cc173Smrg	;;
6854c43cc173Smrg      esac
6855c27c18e8Smrg    done
6856c43cc173Smrg
6857c27c18e8Smrg    # See if our shared archives depend on static archives.
6858c27c18e8Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6859c43cc173Smrg
6860c27c18e8Smrg    # Go through the arguments, transforming them on the way.
6861c27c18e8Smrg    while test "$#" -gt 0; do
686248e5ce07Smrg      arg=$1
6863c27c18e8Smrg      shift
68644e8f48c7Smrg      func_quote_arg pretty,unquoted "$arg"
68654e8f48c7Smrg      qarg=$func_quote_arg_unquoted_result
68664e8f48c7Smrg      func_append libtool_args " $func_quote_arg_result"
6867c43cc173Smrg
6868c27c18e8Smrg      # If the previous option needs an argument, assign it.
6869c27c18e8Smrg      if test -n "$prev"; then
6870c27c18e8Smrg	case $prev in
6871c27c18e8Smrg	output)
6872c27c18e8Smrg	  func_append compile_command " @OUTPUT@"
6873c27c18e8Smrg	  func_append finalize_command " @OUTPUT@"
6874c43cc173Smrg	  ;;
6875c43cc173Smrg	esac
6876c43cc173Smrg
6877c27c18e8Smrg	case $prev in
687837eb1ca1Smrg	bindir)
687948e5ce07Smrg	  bindir=$arg
688037eb1ca1Smrg	  prev=
688137eb1ca1Smrg	  continue
688237eb1ca1Smrg	  ;;
6883c27c18e8Smrg	dlfiles|dlprefiles)
688448e5ce07Smrg	  $preload || {
6885c27c18e8Smrg	    # Add the symbol object into the linking commands.
6886c27c18e8Smrg	    func_append compile_command " @SYMFILE@"
6887c27c18e8Smrg	    func_append finalize_command " @SYMFILE@"
688848e5ce07Smrg	    preload=:
688948e5ce07Smrg	  }
6890c27c18e8Smrg	  case $arg in
6891c27c18e8Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6892c27c18e8Smrg	  force)
689348e5ce07Smrg	    if test no = "$dlself"; then
6894c27c18e8Smrg	      dlself=needless
6895c27c18e8Smrg	      export_dynamic=yes
6896c27c18e8Smrg	    fi
6897c27c18e8Smrg	    prev=
6898c27c18e8Smrg	    continue
6899c27c18e8Smrg	    ;;
6900c27c18e8Smrg	  self)
690148e5ce07Smrg	    if test dlprefiles = "$prev"; then
6902c27c18e8Smrg	      dlself=yes
690348e5ce07Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6904c27c18e8Smrg	      dlself=yes
6905c43cc173Smrg	    else
6906c27c18e8Smrg	      dlself=needless
6907c27c18e8Smrg	      export_dynamic=yes
6908c43cc173Smrg	    fi
6909c27c18e8Smrg	    prev=
6910c27c18e8Smrg	    continue
6911c27c18e8Smrg	    ;;
6912c27c18e8Smrg	  *)
691348e5ce07Smrg	    if test dlfiles = "$prev"; then
6914b789ec8aSmrg	      func_append dlfiles " $arg"
6915c27c18e8Smrg	    else
6916b789ec8aSmrg	      func_append dlprefiles " $arg"
6917c27c18e8Smrg	    fi
6918c27c18e8Smrg	    prev=
6919c27c18e8Smrg	    continue
6920c27c18e8Smrg	    ;;
6921c43cc173Smrg	  esac
6922c43cc173Smrg	  ;;
6923c27c18e8Smrg	expsyms)
692448e5ce07Smrg	  export_symbols=$arg
6925c27c18e8Smrg	  test -f "$arg" \
692648e5ce07Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
6927c27c18e8Smrg	  prev=
6928c27c18e8Smrg	  continue
6929c27c18e8Smrg	  ;;
6930c27c18e8Smrg	expsyms_regex)
693148e5ce07Smrg	  export_symbols_regex=$arg
6932c27c18e8Smrg	  prev=
6933c27c18e8Smrg	  continue
6934c27c18e8Smrg	  ;;
6935c27c18e8Smrg	framework)
6936c27c18e8Smrg	  case $host in
6937c27c18e8Smrg	    *-*-darwin*)
6938c27c18e8Smrg	      case "$deplibs " in
6939c27c18e8Smrg		*" $qarg.ltframework "*) ;;
6940b789ec8aSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6941c27c18e8Smrg		   ;;
6942c43cc173Smrg	      esac
6943c27c18e8Smrg	      ;;
6944c43cc173Smrg	  esac
6945c27c18e8Smrg	  prev=
6946c27c18e8Smrg	  continue
6947c27c18e8Smrg	  ;;
6948c27c18e8Smrg	inst_prefix)
694948e5ce07Smrg	  inst_prefix_dir=$arg
695048e5ce07Smrg	  prev=
695148e5ce07Smrg	  continue
695248e5ce07Smrg	  ;;
695348e5ce07Smrg	mllvm)
695448e5ce07Smrg	  # Clang does not use LLVM to link, so we can simply discard any
695548e5ce07Smrg	  # '-mllvm $arg' options when doing the link step.
6956c27c18e8Smrg	  prev=
6957c27c18e8Smrg	  continue
6958c27c18e8Smrg	  ;;
6959c27c18e8Smrg	objectlist)
6960c27c18e8Smrg	  if test -f "$arg"; then
6961c27c18e8Smrg	    save_arg=$arg
6962c27c18e8Smrg	    moreargs=
6963c27c18e8Smrg	    for fil in `cat "$save_arg"`
6964c27c18e8Smrg	    do
6965b789ec8aSmrg#	      func_append moreargs " $fil"
6966c27c18e8Smrg	      arg=$fil
6967c27c18e8Smrg	      # A libtool-controlled object.
6968c43cc173Smrg
6969c27c18e8Smrg	      # Check to see that this really is a libtool object.
6970c27c18e8Smrg	      if func_lalib_unsafe_p "$arg"; then
6971c27c18e8Smrg		pic_object=
6972c27c18e8Smrg		non_pic_object=
6973c43cc173Smrg
6974c27c18e8Smrg		# Read the .lo file
6975c27c18e8Smrg		func_source "$arg"
6976c43cc173Smrg
6977c27c18e8Smrg		if test -z "$pic_object" ||
6978c27c18e8Smrg		   test -z "$non_pic_object" ||
697948e5ce07Smrg		   test none = "$pic_object" &&
698048e5ce07Smrg		   test none = "$non_pic_object"; then
698148e5ce07Smrg		  func_fatal_error "cannot find name of object for '$arg'"
6982c27c18e8Smrg		fi
6983c43cc173Smrg
6984c27c18e8Smrg		# Extract subdirectory from the argument.
6985c27c18e8Smrg		func_dirname "$arg" "/" ""
698648e5ce07Smrg		xdir=$func_dirname_result
6987c43cc173Smrg
698848e5ce07Smrg		if test none != "$pic_object"; then
6989c27c18e8Smrg		  # Prepend the subdirectory the object is found in.
699048e5ce07Smrg		  pic_object=$xdir$pic_object
6991c43cc173Smrg
699248e5ce07Smrg		  if test dlfiles = "$prev"; then
699348e5ce07Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
6994b789ec8aSmrg		      func_append dlfiles " $pic_object"
6995c27c18e8Smrg		      prev=
6996c27c18e8Smrg		      continue
6997c27c18e8Smrg		    else
6998c27c18e8Smrg		      # If libtool objects are unsupported, then we need to preload.
6999c27c18e8Smrg		      prev=dlprefiles
7000c27c18e8Smrg		    fi
7001c27c18e8Smrg		  fi
7002c43cc173Smrg
7003c27c18e8Smrg		  # CHECK ME:  I think I busted this.  -Ossama
700448e5ce07Smrg		  if test dlprefiles = "$prev"; then
7005c27c18e8Smrg		    # Preload the old-style object.
7006b789ec8aSmrg		    func_append dlprefiles " $pic_object"
7007c27c18e8Smrg		    prev=
7008c27c18e8Smrg		  fi
7009c43cc173Smrg
7010c27c18e8Smrg		  # A PIC object.
7011c27c18e8Smrg		  func_append libobjs " $pic_object"
701248e5ce07Smrg		  arg=$pic_object
7013c27c18e8Smrg		fi
7014c43cc173Smrg
7015c27c18e8Smrg		# Non-PIC object.
701648e5ce07Smrg		if test none != "$non_pic_object"; then
7017c27c18e8Smrg		  # Prepend the subdirectory the object is found in.
701848e5ce07Smrg		  non_pic_object=$xdir$non_pic_object
7019c43cc173Smrg
7020c27c18e8Smrg		  # A standard non-PIC object
7021c27c18e8Smrg		  func_append non_pic_objects " $non_pic_object"
702248e5ce07Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
702348e5ce07Smrg		    arg=$non_pic_object
7024c27c18e8Smrg		  fi
7025c27c18e8Smrg		else
7026c27c18e8Smrg		  # If the PIC object exists, use it instead.
7027c27c18e8Smrg		  # $xdir was prepended to $pic_object above.
702848e5ce07Smrg		  non_pic_object=$pic_object
7029c27c18e8Smrg		  func_append non_pic_objects " $non_pic_object"
7030c27c18e8Smrg		fi
7031c27c18e8Smrg	      else
7032c27c18e8Smrg		# Only an error if not doing a dry-run.
7033c27c18e8Smrg		if $opt_dry_run; then
7034c27c18e8Smrg		  # Extract subdirectory from the argument.
7035c27c18e8Smrg		  func_dirname "$arg" "/" ""
703648e5ce07Smrg		  xdir=$func_dirname_result
7037c27c18e8Smrg
7038c27c18e8Smrg		  func_lo2o "$arg"
7039c27c18e8Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7040c27c18e8Smrg		  non_pic_object=$xdir$func_lo2o_result
7041c27c18e8Smrg		  func_append libobjs " $pic_object"
7042c27c18e8Smrg		  func_append non_pic_objects " $non_pic_object"
7043c27c18e8Smrg	        else
704448e5ce07Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
7045c27c18e8Smrg		fi
7046c27c18e8Smrg	      fi
7047c43cc173Smrg	    done
7048c27c18e8Smrg	  else
704948e5ce07Smrg	    func_fatal_error "link input file '$arg' does not exist"
7050c43cc173Smrg	  fi
7051c27c18e8Smrg	  arg=$save_arg
7052c27c18e8Smrg	  prev=
7053c27c18e8Smrg	  continue
7054c27c18e8Smrg	  ;;
705548e5ce07Smrg	os2dllname)
705648e5ce07Smrg	  os2dllname=$arg
705748e5ce07Smrg	  prev=
705848e5ce07Smrg	  continue
705948e5ce07Smrg	  ;;
7060c27c18e8Smrg	precious_regex)
706148e5ce07Smrg	  precious_files_regex=$arg
7062c27c18e8Smrg	  prev=
7063c27c18e8Smrg	  continue
7064c27c18e8Smrg	  ;;
7065c27c18e8Smrg	release)
706648e5ce07Smrg	  release=-$arg
7067c27c18e8Smrg	  prev=
7068c27c18e8Smrg	  continue
7069c27c18e8Smrg	  ;;
7070c27c18e8Smrg	rpath | xrpath)
7071c27c18e8Smrg	  # We need an absolute path.
7072c27c18e8Smrg	  case $arg in
7073c27c18e8Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7074c27c18e8Smrg	  *)
7075c27c18e8Smrg	    func_fatal_error "only absolute run-paths are allowed"
7076c27c18e8Smrg	    ;;
7077c43cc173Smrg	  esac
707848e5ce07Smrg	  if test rpath = "$prev"; then
7079c27c18e8Smrg	    case "$rpath " in
7080c27c18e8Smrg	    *" $arg "*) ;;
7081b789ec8aSmrg	    *) func_append rpath " $arg" ;;
7082c27c18e8Smrg	    esac
7083c27c18e8Smrg	  else
7084c27c18e8Smrg	    case "$xrpath " in
7085c27c18e8Smrg	    *" $arg "*) ;;
7086b789ec8aSmrg	    *) func_append xrpath " $arg" ;;
7087c27c18e8Smrg	    esac
7088c27c18e8Smrg	  fi
7089c27c18e8Smrg	  prev=
7090c27c18e8Smrg	  continue
7091c27c18e8Smrg	  ;;
7092c27c18e8Smrg	shrext)
709348e5ce07Smrg	  shrext_cmds=$arg
7094c27c18e8Smrg	  prev=
7095c27c18e8Smrg	  continue
7096c27c18e8Smrg	  ;;
7097c27c18e8Smrg	weak)
7098b789ec8aSmrg	  func_append weak_libs " $arg"
7099c27c18e8Smrg	  prev=
7100c27c18e8Smrg	  continue
7101c27c18e8Smrg	  ;;
71024e8f48c7Smrg	xassembler)
71034e8f48c7Smrg	  func_append compiler_flags " -Xassembler $qarg"
71044e8f48c7Smrg	  prev=
71054e8f48c7Smrg	  func_append compile_command " -Xassembler $qarg"
71064e8f48c7Smrg	  func_append finalize_command " -Xassembler $qarg"
71074e8f48c7Smrg	  continue
71084e8f48c7Smrg	  ;;
7109c27c18e8Smrg	xcclinker)
7110b789ec8aSmrg	  func_append linker_flags " $qarg"
7111b789ec8aSmrg	  func_append compiler_flags " $qarg"
7112c27c18e8Smrg	  prev=
7113c27c18e8Smrg	  func_append compile_command " $qarg"
7114c27c18e8Smrg	  func_append finalize_command " $qarg"
7115c27c18e8Smrg	  continue
7116c27c18e8Smrg	  ;;
7117c27c18e8Smrg	xcompiler)
7118b789ec8aSmrg	  func_append compiler_flags " $qarg"
7119c27c18e8Smrg	  prev=
7120c27c18e8Smrg	  func_append compile_command " $qarg"
7121c27c18e8Smrg	  func_append finalize_command " $qarg"
7122c27c18e8Smrg	  continue
7123c27c18e8Smrg	  ;;
7124c27c18e8Smrg	xlinker)
7125b789ec8aSmrg	  func_append linker_flags " $qarg"
7126b789ec8aSmrg	  func_append compiler_flags " $wl$qarg"
7127c27c18e8Smrg	  prev=
7128c27c18e8Smrg	  func_append compile_command " $wl$qarg"
7129c27c18e8Smrg	  func_append finalize_command " $wl$qarg"
7130c27c18e8Smrg	  continue
7131c43cc173Smrg	  ;;
7132c43cc173Smrg	*)
7133c27c18e8Smrg	  eval "$prev=\"\$arg\""
7134c27c18e8Smrg	  prev=
7135c27c18e8Smrg	  continue
7136c43cc173Smrg	  ;;
7137c43cc173Smrg	esac
7138c27c18e8Smrg      fi # test -n "$prev"
7139c43cc173Smrg
714048e5ce07Smrg      prevarg=$arg
7141c43cc173Smrg
7142c27c18e8Smrg      case $arg in
7143c27c18e8Smrg      -all-static)
7144c27c18e8Smrg	if test -n "$link_static_flag"; then
7145c27c18e8Smrg	  # See comment for -static flag below, for more details.
7146c27c18e8Smrg	  func_append compile_command " $link_static_flag"
7147c27c18e8Smrg	  func_append finalize_command " $link_static_flag"
7148c43cc173Smrg	fi
7149c27c18e8Smrg	continue
7150c27c18e8Smrg	;;
7151c43cc173Smrg
7152c27c18e8Smrg      -allow-undefined)
7153c27c18e8Smrg	# FIXME: remove this flag sometime in the future.
715448e5ce07Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7155c27c18e8Smrg	;;
7156c43cc173Smrg
7157c27c18e8Smrg      -avoid-version)
7158c27c18e8Smrg	avoid_version=yes
7159c27c18e8Smrg	continue
7160c27c18e8Smrg	;;
7161c43cc173Smrg
716237eb1ca1Smrg      -bindir)
716337eb1ca1Smrg	prev=bindir
716437eb1ca1Smrg	continue
716537eb1ca1Smrg	;;
716637eb1ca1Smrg
7167c27c18e8Smrg      -dlopen)
7168c27c18e8Smrg	prev=dlfiles
7169c27c18e8Smrg	continue
7170c27c18e8Smrg	;;
7171c43cc173Smrg
7172c27c18e8Smrg      -dlpreopen)
7173c27c18e8Smrg	prev=dlprefiles
7174c27c18e8Smrg	continue
7175c27c18e8Smrg	;;
7176c43cc173Smrg
7177c27c18e8Smrg      -export-dynamic)
7178c27c18e8Smrg	export_dynamic=yes
7179c27c18e8Smrg	continue
7180c27c18e8Smrg	;;
7181c43cc173Smrg
7182c27c18e8Smrg      -export-symbols | -export-symbols-regex)
7183c27c18e8Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7184c27c18e8Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7185c27c18e8Smrg	fi
718648e5ce07Smrg	if test X-export-symbols = "X$arg"; then
7187c27c18e8Smrg	  prev=expsyms
7188c43cc173Smrg	else
7189c27c18e8Smrg	  prev=expsyms_regex
7190c43cc173Smrg	fi
7191c27c18e8Smrg	continue
7192c27c18e8Smrg	;;
7193c43cc173Smrg
7194c27c18e8Smrg      -framework)
7195c27c18e8Smrg	prev=framework
7196c27c18e8Smrg	continue
7197c27c18e8Smrg	;;
7198c43cc173Smrg
7199c27c18e8Smrg      -inst-prefix-dir)
7200c27c18e8Smrg	prev=inst_prefix
7201c27c18e8Smrg	continue
7202c27c18e8Smrg	;;
7203c43cc173Smrg
7204c27c18e8Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7205c27c18e8Smrg      # so, if we see these flags be careful not to treat them like -L
7206c27c18e8Smrg      -L[A-Z][A-Z]*:*)
7207c27c18e8Smrg	case $with_gcc/$host in
7208c27c18e8Smrg	no/*-*-irix* | /*-*-irix*)
7209c27c18e8Smrg	  func_append compile_command " $arg"
7210c27c18e8Smrg	  func_append finalize_command " $arg"
7211c27c18e8Smrg	  ;;
7212c27c18e8Smrg	esac
7213c27c18e8Smrg	continue
7214c27c18e8Smrg	;;
7215c43cc173Smrg
7216c27c18e8Smrg      -L*)
7217b789ec8aSmrg	func_stripname "-L" '' "$arg"
7218b789ec8aSmrg	if test -z "$func_stripname_result"; then
7219c27c18e8Smrg	  if test "$#" -gt 0; then
722048e5ce07Smrg	    func_fatal_error "require no space between '-L' and '$1'"
7221c43cc173Smrg	  else
722248e5ce07Smrg	    func_fatal_error "need path for '-L' option"
7223c43cc173Smrg	  fi
7224c27c18e8Smrg	fi
7225b789ec8aSmrg	func_resolve_sysroot "$func_stripname_result"
7226b789ec8aSmrg	dir=$func_resolve_sysroot_result
7227c27c18e8Smrg	# We need an absolute path.
7228c27c18e8Smrg	case $dir in
7229c27c18e8Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7230c27c18e8Smrg	*)
7231c27c18e8Smrg	  absdir=`cd "$dir" && pwd`
7232c27c18e8Smrg	  test -z "$absdir" && \
723348e5ce07Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
723448e5ce07Smrg	  dir=$absdir
7235c27c18e8Smrg	  ;;
7236c43cc173Smrg	esac
7237c27c18e8Smrg	case "$deplibs " in
7238b789ec8aSmrg	*" -L$dir "* | *" $arg "*)
7239b789ec8aSmrg	  # Will only happen for absolute or sysroot arguments
7240b789ec8aSmrg	  ;;
7241c27c18e8Smrg	*)
7242b789ec8aSmrg	  # Preserve sysroot, but never include relative directories
7243b789ec8aSmrg	  case $dir in
7244b789ec8aSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7245b789ec8aSmrg	    *) func_append deplibs " -L$dir" ;;
7246b789ec8aSmrg	  esac
7247b789ec8aSmrg	  func_append lib_search_path " $dir"
7248c27c18e8Smrg	  ;;
7249c43cc173Smrg	esac
7250c43cc173Smrg	case $host in
7251c27c18e8Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725237eb1ca1Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7253c27c18e8Smrg	  case :$dllsearchpath: in
7254c27c18e8Smrg	  *":$dir:"*) ;;
7255c27c18e8Smrg	  ::) dllsearchpath=$dir;;
7256b789ec8aSmrg	  *) func_append dllsearchpath ":$dir";;
7257c27c18e8Smrg	  esac
7258c27c18e8Smrg	  case :$dllsearchpath: in
7259c27c18e8Smrg	  *":$testbindir:"*) ;;
7260c27c18e8Smrg	  ::) dllsearchpath=$testbindir;;
7261b789ec8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
7262c27c18e8Smrg	  esac
7263c27c18e8Smrg	  ;;
7264c43cc173Smrg	esac
7265c27c18e8Smrg	continue
7266c27c18e8Smrg	;;
7267c43cc173Smrg
7268c27c18e8Smrg      -l*)
726948e5ce07Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7270c27c18e8Smrg	  case $host in
727137eb1ca1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7272c27c18e8Smrg	    # These systems don't actually have a C or math library (as such)
7273c27c18e8Smrg	    continue
7274c27c18e8Smrg	    ;;
7275c27c18e8Smrg	  *-*-os2*)
7276c27c18e8Smrg	    # These systems don't actually have a C library (as such)
727748e5ce07Smrg	    test X-lc = "X$arg" && continue
7278c27c18e8Smrg	    ;;
72794e8f48c7Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7280c27c18e8Smrg	    # Do not include libc due to us having libc/libc_r.
728148e5ce07Smrg	    test X-lc = "X$arg" && continue
7282c27c18e8Smrg	    ;;
7283c27c18e8Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7284c27c18e8Smrg	    # Rhapsody C and math libraries are in the System framework
7285b789ec8aSmrg	    func_append deplibs " System.ltframework"
7286c27c18e8Smrg	    continue
7287c27c18e8Smrg	    ;;
7288c27c18e8Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7289c27c18e8Smrg	    # Causes problems with __ctype
729048e5ce07Smrg	    test X-lc = "X$arg" && continue
7291c27c18e8Smrg	    ;;
7292c27c18e8Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7293c27c18e8Smrg	    # Compiler inserts libc in the correct place for threads to work
729448e5ce07Smrg	    test X-lc = "X$arg" && continue
7295c27c18e8Smrg	    ;;
7296c27c18e8Smrg	  esac
729748e5ce07Smrg	elif test X-lc_r = "X$arg"; then
7298c27c18e8Smrg	 case $host in
72994e8f48c7Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7300c27c18e8Smrg	   # Do not include libc_r directly, use -pthread flag.
7301c27c18e8Smrg	   continue
7302c27c18e8Smrg	   ;;
7303c27c18e8Smrg	 esac
7304c27c18e8Smrg	fi
7305b789ec8aSmrg	func_append deplibs " $arg"
7306c27c18e8Smrg	continue
7307c27c18e8Smrg	;;
7308c43cc173Smrg
730948e5ce07Smrg      -mllvm)
731048e5ce07Smrg	prev=mllvm
731148e5ce07Smrg	continue
731248e5ce07Smrg	;;
731348e5ce07Smrg
7314c27c18e8Smrg      -module)
7315c27c18e8Smrg	module=yes
7316c27c18e8Smrg	continue
7317c27c18e8Smrg	;;
7318c43cc173Smrg
7319c27c18e8Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7320c27c18e8Smrg      # classes, name mangling, and exception handling.
7321c27c18e8Smrg      # Darwin uses the -arch flag to determine output architecture.
7322b789ec8aSmrg      -model|-arch|-isysroot|--sysroot)
7323b789ec8aSmrg	func_append compiler_flags " $arg"
7324c27c18e8Smrg	func_append compile_command " $arg"
7325c27c18e8Smrg	func_append finalize_command " $arg"
7326c27c18e8Smrg	prev=xcompiler
7327c27c18e8Smrg	continue
7328c27c18e8Smrg	;;
73294e8f48c7Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
73304e8f48c7Smrg     -pthread)
73314e8f48c7Smrg	case $host in
73324e8f48c7Smrg	  *solaris2*) ;;
73334e8f48c7Smrg	  *)
73344e8f48c7Smrg	    case "$new_inherited_linker_flags " in
73354e8f48c7Smrg	        *" $arg "*) ;;
73364e8f48c7Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
73374e8f48c7Smrg	    esac
73384e8f48c7Smrg	  ;;
73394e8f48c7Smrg	esac
73404e8f48c7Smrg	continue
73414e8f48c7Smrg	;;
73424e8f48c7Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7343f1ee322dSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7344b789ec8aSmrg	func_append compiler_flags " $arg"
7345c27c18e8Smrg	func_append compile_command " $arg"
7346c27c18e8Smrg	func_append finalize_command " $arg"
7347c27c18e8Smrg	case "$new_inherited_linker_flags " in
7348c27c18e8Smrg	    *" $arg "*) ;;
7349b789ec8aSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7350c27c18e8Smrg	esac
7351c27c18e8Smrg	continue
7352c27c18e8Smrg	;;
7353c43cc173Smrg
7354c27c18e8Smrg      -multi_module)
735548e5ce07Smrg	single_module=$wl-multi_module
7356c27c18e8Smrg	continue
7357c27c18e8Smrg	;;
7358c43cc173Smrg
7359c27c18e8Smrg      -no-fast-install)
7360c27c18e8Smrg	fast_install=no
7361c27c18e8Smrg	continue
7362c27c18e8Smrg	;;
7363c43cc173Smrg
7364c27c18e8Smrg      -no-install)
7365c27c18e8Smrg	case $host in
7366c27c18e8Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7367c27c18e8Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7368c27c18e8Smrg	  # and Darwin in order for the loader to find any dlls it needs.
736948e5ce07Smrg	  func_warning "'-no-install' is ignored for $host"
737048e5ce07Smrg	  func_warning "assuming '-no-fast-install' instead"
7371c27c18e8Smrg	  fast_install=no
7372c27c18e8Smrg	  ;;
7373c27c18e8Smrg	*) no_install=yes ;;
7374c27c18e8Smrg	esac
7375c27c18e8Smrg	continue
7376c27c18e8Smrg	;;
7377c43cc173Smrg
7378c27c18e8Smrg      -no-undefined)
7379c27c18e8Smrg	allow_undefined=no
7380c27c18e8Smrg	continue
7381c27c18e8Smrg	;;
7382c43cc173Smrg
7383c27c18e8Smrg      -objectlist)
7384c27c18e8Smrg	prev=objectlist
7385c27c18e8Smrg	continue
7386c27c18e8Smrg	;;
7387c43cc173Smrg
738848e5ce07Smrg      -os2dllname)
738948e5ce07Smrg	prev=os2dllname
739048e5ce07Smrg	continue
739148e5ce07Smrg	;;
739248e5ce07Smrg
7393c27c18e8Smrg      -o) prev=output ;;
7394c43cc173Smrg
7395c27c18e8Smrg      -precious-files-regex)
7396c27c18e8Smrg	prev=precious_regex
7397c27c18e8Smrg	continue
7398c27c18e8Smrg	;;
7399c43cc173Smrg
7400c27c18e8Smrg      -release)
7401c27c18e8Smrg	prev=release
7402c27c18e8Smrg	continue
7403c27c18e8Smrg	;;
7404c43cc173Smrg
7405c27c18e8Smrg      -rpath)
7406c27c18e8Smrg	prev=rpath
7407c27c18e8Smrg	continue
7408c27c18e8Smrg	;;
7409c43cc173Smrg
7410c27c18e8Smrg      -R)
7411c27c18e8Smrg	prev=xrpath
7412c27c18e8Smrg	continue
7413c27c18e8Smrg	;;
7414c43cc173Smrg
7415c27c18e8Smrg      -R*)
7416c27c18e8Smrg	func_stripname '-R' '' "$arg"
7417c27c18e8Smrg	dir=$func_stripname_result
7418c27c18e8Smrg	# We need an absolute path.
7419c27c18e8Smrg	case $dir in
7420c27c18e8Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7421b789ec8aSmrg	=*)
7422b789ec8aSmrg	  func_stripname '=' '' "$dir"
7423b789ec8aSmrg	  dir=$lt_sysroot$func_stripname_result
7424b789ec8aSmrg	  ;;
7425c27c18e8Smrg	*)
7426c27c18e8Smrg	  func_fatal_error "only absolute run-paths are allowed"
7427c27c18e8Smrg	  ;;
7428c27c18e8Smrg	esac
7429c27c18e8Smrg	case "$xrpath " in
7430c27c18e8Smrg	*" $dir "*) ;;
7431b789ec8aSmrg	*) func_append xrpath " $dir" ;;
7432c27c18e8Smrg	esac
7433c27c18e8Smrg	continue
7434c27c18e8Smrg	;;
7435c43cc173Smrg
7436c27c18e8Smrg      -shared)
7437c27c18e8Smrg	# The effects of -shared are defined in a previous loop.
7438c27c18e8Smrg	continue
7439c27c18e8Smrg	;;
7440c43cc173Smrg
7441c27c18e8Smrg      -shrext)
7442c27c18e8Smrg	prev=shrext
7443c27c18e8Smrg	continue
7444c27c18e8Smrg	;;
7445c43cc173Smrg
7446c27c18e8Smrg      -static | -static-libtool-libs)
7447c27c18e8Smrg	# The effects of -static are defined in a previous loop.
7448c27c18e8Smrg	# We used to do the same as -all-static on platforms that
7449c27c18e8Smrg	# didn't have a PIC flag, but the assumption that the effects
7450c27c18e8Smrg	# would be equivalent was wrong.  It would break on at least
7451c27c18e8Smrg	# Digital Unix and AIX.
7452c27c18e8Smrg	continue
7453c27c18e8Smrg	;;
7454c43cc173Smrg
7455c27c18e8Smrg      -thread-safe)
7456c27c18e8Smrg	thread_safe=yes
7457c27c18e8Smrg	continue
7458c27c18e8Smrg	;;
7459c43cc173Smrg
7460c27c18e8Smrg      -version-info)
7461c27c18e8Smrg	prev=vinfo
7462c27c18e8Smrg	continue
7463c27c18e8Smrg	;;
7464c43cc173Smrg
7465c27c18e8Smrg      -version-number)
7466c27c18e8Smrg	prev=vinfo
7467c27c18e8Smrg	vinfo_number=yes
7468c27c18e8Smrg	continue
7469c27c18e8Smrg	;;
7470c43cc173Smrg
7471c27c18e8Smrg      -weak)
7472c27c18e8Smrg        prev=weak
7473c27c18e8Smrg	continue
7474c27c18e8Smrg	;;
7475c43cc173Smrg
7476c27c18e8Smrg      -Wc,*)
7477c27c18e8Smrg	func_stripname '-Wc,' '' "$arg"
7478c27c18e8Smrg	args=$func_stripname_result
7479c27c18e8Smrg	arg=
748048e5ce07Smrg	save_ifs=$IFS; IFS=,
7481c27c18e8Smrg	for flag in $args; do
748248e5ce07Smrg	  IFS=$save_ifs
74834e8f48c7Smrg          func_quote_arg pretty "$flag"
74844e8f48c7Smrg	  func_append arg " $func_quote_arg_result"
74854e8f48c7Smrg	  func_append compiler_flags " $func_quote_arg_result"
7486c27c18e8Smrg	done
748748e5ce07Smrg	IFS=$save_ifs
7488c27c18e8Smrg	func_stripname ' ' '' "$arg"
7489c27c18e8Smrg	arg=$func_stripname_result
7490c27c18e8Smrg	;;
7491c43cc173Smrg
7492c27c18e8Smrg      -Wl,*)
7493c27c18e8Smrg	func_stripname '-Wl,' '' "$arg"
7494c27c18e8Smrg	args=$func_stripname_result
7495c27c18e8Smrg	arg=
749648e5ce07Smrg	save_ifs=$IFS; IFS=,
7497c27c18e8Smrg	for flag in $args; do
749848e5ce07Smrg	  IFS=$save_ifs
74994e8f48c7Smrg          func_quote_arg pretty "$flag"
75004e8f48c7Smrg	  func_append arg " $wl$func_quote_arg_result"
75014e8f48c7Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
75024e8f48c7Smrg	  func_append linker_flags " $func_quote_arg_result"
7503c27c18e8Smrg	done
750448e5ce07Smrg	IFS=$save_ifs
7505c27c18e8Smrg	func_stripname ' ' '' "$arg"
7506c27c18e8Smrg	arg=$func_stripname_result
7507c27c18e8Smrg	;;
7508c43cc173Smrg
75094e8f48c7Smrg      -Xassembler)
75104e8f48c7Smrg        prev=xassembler
75114e8f48c7Smrg        continue
75124e8f48c7Smrg        ;;
75134e8f48c7Smrg
7514c27c18e8Smrg      -Xcompiler)
7515c27c18e8Smrg	prev=xcompiler
7516c27c18e8Smrg	continue
7517c27c18e8Smrg	;;
7518c43cc173Smrg
7519c27c18e8Smrg      -Xlinker)
7520c27c18e8Smrg	prev=xlinker
7521c27c18e8Smrg	continue
7522c27c18e8Smrg	;;
7523c43cc173Smrg
7524c27c18e8Smrg      -XCClinker)
7525c27c18e8Smrg	prev=xcclinker
7526c27c18e8Smrg	continue
7527c27c18e8Smrg	;;
7528c43cc173Smrg
7529c27c18e8Smrg      # -msg_* for osf cc
7530c27c18e8Smrg      -msg_*)
75314e8f48c7Smrg	func_quote_arg pretty "$arg"
75324e8f48c7Smrg	arg=$func_quote_arg_result
7533c27c18e8Smrg	;;
7534c43cc173Smrg
753537eb1ca1Smrg      # Flags to be passed through unchanged, with rationale:
753637eb1ca1Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
753737eb1ca1Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
753837eb1ca1Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
753937eb1ca1Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754037eb1ca1Smrg      # -q*                  compiler args for the IBM compiler
754137eb1ca1Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754237eb1ca1Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
754337eb1ca1Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
754448e5ce07Smrg      # -fstack-protector*   stack protector flags for GCC
754537eb1ca1Smrg      # @file                GCC response files
754637eb1ca1Smrg      # -tp=*                Portland pgcc target processor selection
7547b789ec8aSmrg      # --sysroot=*          for sysroot support
754848e5ce07Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75494940c694Smrg      # -specs=*             GCC specs files
755048e5ce07Smrg      # -stdlib=*            select c++ std lib with clang
75514940c694Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75524940c694Smrg      # -fuse-ld=*           Linker select flags for GCC
75534e8f48c7Smrg      # -Wa,*                Pass flags directly to the assembler
7554c27c18e8Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7555b789ec8aSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75564940c694Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
75574e8f48c7Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
75584e8f48c7Smrg        func_quote_arg pretty "$arg"
75594e8f48c7Smrg	arg=$func_quote_arg_result
7560c27c18e8Smrg        func_append compile_command " $arg"
7561c27c18e8Smrg        func_append finalize_command " $arg"
7562b789ec8aSmrg        func_append compiler_flags " $arg"
7563c27c18e8Smrg        continue
7564c27c18e8Smrg        ;;
7565c43cc173Smrg
756648e5ce07Smrg      -Z*)
756748e5ce07Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
756848e5ce07Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
756948e5ce07Smrg	  compiler_flags="$compiler_flags $arg"
757048e5ce07Smrg	  func_append compile_command " $arg"
757148e5ce07Smrg	  func_append finalize_command " $arg"
757248e5ce07Smrg	  case $arg in
757348e5ce07Smrg	  -Zlinker | -Zstack)
757448e5ce07Smrg	    prev=xcompiler
757548e5ce07Smrg	    ;;
757648e5ce07Smrg	  esac
757748e5ce07Smrg	  continue
757848e5ce07Smrg        else
757948e5ce07Smrg	  # Otherwise treat like 'Some other compiler flag' below
75804e8f48c7Smrg	  func_quote_arg pretty "$arg"
75814e8f48c7Smrg	  arg=$func_quote_arg_result
758248e5ce07Smrg        fi
758348e5ce07Smrg	;;
758448e5ce07Smrg
7585c27c18e8Smrg      # Some other compiler flag.
7586c27c18e8Smrg      -* | +*)
75874e8f48c7Smrg        func_quote_arg pretty "$arg"
75884e8f48c7Smrg	arg=$func_quote_arg_result
7589c27c18e8Smrg	;;
7590c43cc173Smrg
7591c27c18e8Smrg      *.$objext)
7592c27c18e8Smrg	# A standard object.
7593b789ec8aSmrg	func_append objs " $arg"
7594c27c18e8Smrg	;;
7595c43cc173Smrg
7596c27c18e8Smrg      *.lo)
7597c27c18e8Smrg	# A libtool-controlled object.
7598c43cc173Smrg
7599c27c18e8Smrg	# Check to see that this really is a libtool object.
7600c27c18e8Smrg	if func_lalib_unsafe_p "$arg"; then
7601c27c18e8Smrg	  pic_object=
7602c27c18e8Smrg	  non_pic_object=
7603c43cc173Smrg
7604c27c18e8Smrg	  # Read the .lo file
7605c27c18e8Smrg	  func_source "$arg"
7606c43cc173Smrg
7607c27c18e8Smrg	  if test -z "$pic_object" ||
7608c27c18e8Smrg	     test -z "$non_pic_object" ||
760948e5ce07Smrg	     test none = "$pic_object" &&
761048e5ce07Smrg	     test none = "$non_pic_object"; then
761148e5ce07Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7612c27c18e8Smrg	  fi
7613c43cc173Smrg
7614c27c18e8Smrg	  # Extract subdirectory from the argument.
7615c27c18e8Smrg	  func_dirname "$arg" "/" ""
761648e5ce07Smrg	  xdir=$func_dirname_result
7617c43cc173Smrg
761848e5ce07Smrg	  test none = "$pic_object" || {
7619c27c18e8Smrg	    # Prepend the subdirectory the object is found in.
762048e5ce07Smrg	    pic_object=$xdir$pic_object
7621c43cc173Smrg
762248e5ce07Smrg	    if test dlfiles = "$prev"; then
762348e5ce07Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7624b789ec8aSmrg		func_append dlfiles " $pic_object"
7625c27c18e8Smrg		prev=
7626c27c18e8Smrg		continue
7627c27c18e8Smrg	      else
7628c27c18e8Smrg		# If libtool objects are unsupported, then we need to preload.
7629c27c18e8Smrg		prev=dlprefiles
7630c27c18e8Smrg	      fi
7631c27c18e8Smrg	    fi
7632c43cc173Smrg
7633c27c18e8Smrg	    # CHECK ME:  I think I busted this.  -Ossama
763448e5ce07Smrg	    if test dlprefiles = "$prev"; then
7635c27c18e8Smrg	      # Preload the old-style object.
7636b789ec8aSmrg	      func_append dlprefiles " $pic_object"
7637c27c18e8Smrg	      prev=
7638c27c18e8Smrg	    fi
7639c43cc173Smrg
7640c27c18e8Smrg	    # A PIC object.
7641c27c18e8Smrg	    func_append libobjs " $pic_object"
764248e5ce07Smrg	    arg=$pic_object
764348e5ce07Smrg	  }
7644c43cc173Smrg
7645c27c18e8Smrg	  # Non-PIC object.
764648e5ce07Smrg	  if test none != "$non_pic_object"; then
7647c27c18e8Smrg	    # Prepend the subdirectory the object is found in.
764848e5ce07Smrg	    non_pic_object=$xdir$non_pic_object
7649c43cc173Smrg
7650c27c18e8Smrg	    # A standard non-PIC object
7651c27c18e8Smrg	    func_append non_pic_objects " $non_pic_object"
765248e5ce07Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
765348e5ce07Smrg	      arg=$non_pic_object
7654c27c18e8Smrg	    fi
7655c27c18e8Smrg	  else
7656c27c18e8Smrg	    # If the PIC object exists, use it instead.
7657c27c18e8Smrg	    # $xdir was prepended to $pic_object above.
765848e5ce07Smrg	    non_pic_object=$pic_object
7659c27c18e8Smrg	    func_append non_pic_objects " $non_pic_object"
7660c27c18e8Smrg	  fi
7661c27c18e8Smrg	else
7662c27c18e8Smrg	  # Only an error if not doing a dry-run.
7663c27c18e8Smrg	  if $opt_dry_run; then
7664c27c18e8Smrg	    # Extract subdirectory from the argument.
7665c27c18e8Smrg	    func_dirname "$arg" "/" ""
766648e5ce07Smrg	    xdir=$func_dirname_result
7667c27c18e8Smrg
7668c27c18e8Smrg	    func_lo2o "$arg"
7669c27c18e8Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7670c27c18e8Smrg	    non_pic_object=$xdir$func_lo2o_result
7671c27c18e8Smrg	    func_append libobjs " $pic_object"
7672c27c18e8Smrg	    func_append non_pic_objects " $non_pic_object"
7673c27c18e8Smrg	  else
767448e5ce07Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7675c27c18e8Smrg	  fi
7676c27c18e8Smrg	fi
7677c27c18e8Smrg	;;
7678c43cc173Smrg
7679c27c18e8Smrg      *.$libext)
7680c27c18e8Smrg	# An archive.
7681b789ec8aSmrg	func_append deplibs " $arg"
7682b789ec8aSmrg	func_append old_deplibs " $arg"
7683c27c18e8Smrg	continue
7684c27c18e8Smrg	;;
7685c43cc173Smrg
7686c27c18e8Smrg      *.la)
7687c27c18e8Smrg	# A libtool-controlled library.
7688c43cc173Smrg
7689b789ec8aSmrg	func_resolve_sysroot "$arg"
769048e5ce07Smrg	if test dlfiles = "$prev"; then
7691c27c18e8Smrg	  # This library was specified with -dlopen.
7692b789ec8aSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7693c27c18e8Smrg	  prev=
769448e5ce07Smrg	elif test dlprefiles = "$prev"; then
7695c27c18e8Smrg	  # The library was specified with -dlpreopen.
7696b789ec8aSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7697c27c18e8Smrg	  prev=
7698c27c18e8Smrg	else
7699b789ec8aSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7700c27c18e8Smrg	fi
7701c27c18e8Smrg	continue
7702c27c18e8Smrg	;;
7703c43cc173Smrg
7704c27c18e8Smrg      # Some other compiler argument.
7705c27c18e8Smrg      *)
7706c27c18e8Smrg	# Unknown arguments in both finalize_command and compile_command need
7707c27c18e8Smrg	# to be aesthetically quoted because they are evaled later.
77084e8f48c7Smrg	func_quote_arg pretty "$arg"
77094e8f48c7Smrg	arg=$func_quote_arg_result
7710c27c18e8Smrg	;;
7711c27c18e8Smrg      esac # arg
7712c43cc173Smrg
7713c27c18e8Smrg      # Now actually substitute the argument into the commands.
7714c27c18e8Smrg      if test -n "$arg"; then
7715c27c18e8Smrg	func_append compile_command " $arg"
7716c27c18e8Smrg	func_append finalize_command " $arg"
7717c27c18e8Smrg      fi
7718c27c18e8Smrg    done # argument parsing loop
771921e67964Smrg
7720c27c18e8Smrg    test -n "$prev" && \
772148e5ce07Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7722c43cc173Smrg
772348e5ce07Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7724c27c18e8Smrg      eval arg=\"$export_dynamic_flag_spec\"
7725c27c18e8Smrg      func_append compile_command " $arg"
7726c27c18e8Smrg      func_append finalize_command " $arg"
7727c27c18e8Smrg    fi
7728c43cc173Smrg
7729c27c18e8Smrg    oldlibs=
7730c27c18e8Smrg    # calculate the name of the file, without its directory
7731c27c18e8Smrg    func_basename "$output"
773248e5ce07Smrg    outputname=$func_basename_result
773348e5ce07Smrg    libobjs_save=$libobjs
7734c27c18e8Smrg
7735c27c18e8Smrg    if test -n "$shlibpath_var"; then
7736c27c18e8Smrg      # get the directories listed in $shlibpath_var
773748e5ce07Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7738c43cc173Smrg    else
7739c27c18e8Smrg      shlib_search_path=
7740c43cc173Smrg    fi
7741c27c18e8Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7742c27c18e8Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7743c43cc173Smrg
774448e5ce07Smrg    # Definition is injected by LT_CONFIG during libtool generation.
774548e5ce07Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
774648e5ce07Smrg
7747c27c18e8Smrg    func_dirname "$output" "/" ""
774848e5ce07Smrg    output_objdir=$func_dirname_result$objdir
7749b789ec8aSmrg    func_to_tool_file "$output_objdir/"
7750b789ec8aSmrg    tool_output_objdir=$func_to_tool_file_result
7751c27c18e8Smrg    # Create the object directory.
7752c27c18e8Smrg    func_mkdir_p "$output_objdir"
7753c43cc173Smrg
7754c27c18e8Smrg    # Determine the type of output
7755c27c18e8Smrg    case $output in
7756c27c18e8Smrg    "")
7757c27c18e8Smrg      func_fatal_help "you must specify an output file"
7758c27c18e8Smrg      ;;
7759c27c18e8Smrg    *.$libext) linkmode=oldlib ;;
7760c27c18e8Smrg    *.lo | *.$objext) linkmode=obj ;;
7761c27c18e8Smrg    *.la) linkmode=lib ;;
7762c27c18e8Smrg    *) linkmode=prog ;; # Anything else should be a program.
7763c27c18e8Smrg    esac
7764c27c18e8Smrg
7765c27c18e8Smrg    specialdeplibs=
7766c27c18e8Smrg
7767c27c18e8Smrg    libs=
7768c27c18e8Smrg    # Find all interdependent deplibs by searching for libraries
7769c27c18e8Smrg    # that are linked more than once (e.g. -la -lb -la)
7770c27c18e8Smrg    for deplib in $deplibs; do
777148e5ce07Smrg      if $opt_preserve_dup_deps; then
7772c27c18e8Smrg	case "$libs " in
7773b789ec8aSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7774c27c18e8Smrg	esac
7775c27c18e8Smrg      fi
7776b789ec8aSmrg      func_append libs " $deplib"
7777c27c18e8Smrg    done
7778c27c18e8Smrg
777948e5ce07Smrg    if test lib = "$linkmode"; then
7780c27c18e8Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7781c27c18e8Smrg
7782c27c18e8Smrg      # Compute libraries that are listed more than once in $predeps
7783c27c18e8Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7784c27c18e8Smrg      # not to be eliminated).
7785c27c18e8Smrg      pre_post_deps=
7786c27c18e8Smrg      if $opt_duplicate_compiler_generated_deps; then
7787c27c18e8Smrg	for pre_post_dep in $predeps $postdeps; do
7788c27c18e8Smrg	  case "$pre_post_deps " in
7789b789ec8aSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7790c27c18e8Smrg	  esac
7791b789ec8aSmrg	  func_append pre_post_deps " $pre_post_dep"
7792c27c18e8Smrg	done
7793c27c18e8Smrg      fi
7794c27c18e8Smrg      pre_post_deps=
7795c27c18e8Smrg    fi
7796c27c18e8Smrg
7797c27c18e8Smrg    deplibs=
7798c27c18e8Smrg    newdependency_libs=
7799c27c18e8Smrg    newlib_search_path=
7800c27c18e8Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7801c27c18e8Smrg    notinst_deplibs= # not-installed libtool libraries
7802c27c18e8Smrg    notinst_path= # paths that contain not-installed libtool libraries
7803c27c18e8Smrg
7804c27c18e8Smrg    case $linkmode in
7805c27c18e8Smrg    lib)
7806c27c18e8Smrg	passes="conv dlpreopen link"
7807c27c18e8Smrg	for file in $dlfiles $dlprefiles; do
7808c27c18e8Smrg	  case $file in
7809c27c18e8Smrg	  *.la) ;;
7810c27c18e8Smrg	  *)
781148e5ce07Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7812c27c18e8Smrg	    ;;
7813c27c18e8Smrg	  esac
7814c27c18e8Smrg	done
7815c27c18e8Smrg	;;
7816c27c18e8Smrg    prog)
7817c27c18e8Smrg	compile_deplibs=
7818c27c18e8Smrg	finalize_deplibs=
781948e5ce07Smrg	alldeplibs=false
7820c27c18e8Smrg	newdlfiles=
7821c27c18e8Smrg	newdlprefiles=
7822c27c18e8Smrg	passes="conv scan dlopen dlpreopen link"
7823c27c18e8Smrg	;;
7824c27c18e8Smrg    *)  passes="conv"
7825c27c18e8Smrg	;;
7826c27c18e8Smrg    esac
7827c27c18e8Smrg
7828c27c18e8Smrg    for pass in $passes; do
7829c27c18e8Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7830c27c18e8Smrg      # so that -L comes before libs that need it for instance...
783148e5ce07Smrg      if test lib,link = "$linkmode,$pass"; then
7832c27c18e8Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7833c27c18e8Smrg	##        order, and fix it there properly
7834c27c18e8Smrg        tmp_deplibs=
7835c27c18e8Smrg	for deplib in $deplibs; do
7836c27c18e8Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7837c27c18e8Smrg	done
783848e5ce07Smrg	deplibs=$tmp_deplibs
7839c27c18e8Smrg      fi
7840c27c18e8Smrg
784148e5ce07Smrg      if test lib,link = "$linkmode,$pass" ||
784248e5ce07Smrg	 test prog,scan = "$linkmode,$pass"; then
784348e5ce07Smrg	libs=$deplibs
7844c27c18e8Smrg	deplibs=
7845c27c18e8Smrg      fi
784648e5ce07Smrg      if test prog = "$linkmode"; then
7847c27c18e8Smrg	case $pass in
784848e5ce07Smrg	dlopen) libs=$dlfiles ;;
784948e5ce07Smrg	dlpreopen) libs=$dlprefiles ;;
78504e8f48c7Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7851c27c18e8Smrg	esac
7852c27c18e8Smrg      fi
785348e5ce07Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7854c27c18e8Smrg	# Collect and forward deplibs of preopened libtool libs
7855c27c18e8Smrg	for lib in $dlprefiles; do
7856c27c18e8Smrg	  # Ignore non-libtool-libs
7857c27c18e8Smrg	  dependency_libs=
7858b789ec8aSmrg	  func_resolve_sysroot "$lib"
7859c27c18e8Smrg	  case $lib in
7860b789ec8aSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7861c27c18e8Smrg	  esac
7862c27c18e8Smrg
7863c27c18e8Smrg	  # Collect preopened libtool deplibs, except any this library
7864c27c18e8Smrg	  # has declared as weak libs
7865c27c18e8Smrg	  for deplib in $dependency_libs; do
786637eb1ca1Smrg	    func_basename "$deplib"
786737eb1ca1Smrg            deplib_base=$func_basename_result
7868c27c18e8Smrg	    case " $weak_libs " in
7869c27c18e8Smrg	    *" $deplib_base "*) ;;
7870b789ec8aSmrg	    *) func_append deplibs " $deplib" ;;
7871c27c18e8Smrg	    esac
7872c27c18e8Smrg	  done
7873c27c18e8Smrg	done
787448e5ce07Smrg	libs=$dlprefiles
7875c27c18e8Smrg      fi
787648e5ce07Smrg      if test dlopen = "$pass"; then
7877c27c18e8Smrg	# Collect dlpreopened libraries
787848e5ce07Smrg	save_deplibs=$deplibs
7879c27c18e8Smrg	deplibs=
7880c27c18e8Smrg      fi
7881c27c18e8Smrg
7882c27c18e8Smrg      for deplib in $libs; do
7883c27c18e8Smrg	lib=
788448e5ce07Smrg	found=false
7885c27c18e8Smrg	case $deplib in
7886f1ee322dSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7887f1ee322dSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
788848e5ce07Smrg	  if test prog,link = "$linkmode,$pass"; then
7889c27c18e8Smrg	    compile_deplibs="$deplib $compile_deplibs"
7890c27c18e8Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7891c27c18e8Smrg	  else
7892b789ec8aSmrg	    func_append compiler_flags " $deplib"
789348e5ce07Smrg	    if test lib = "$linkmode"; then
7894c27c18e8Smrg		case "$new_inherited_linker_flags " in
7895c27c18e8Smrg		    *" $deplib "*) ;;
7896b789ec8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7897c27c18e8Smrg		esac
7898c27c18e8Smrg	    fi
7899c27c18e8Smrg	  fi
7900c27c18e8Smrg	  continue
7901c27c18e8Smrg	  ;;
7902c27c18e8Smrg	-l*)
790348e5ce07Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
790448e5ce07Smrg	    func_warning "'-l' is ignored for archives/objects"
7905c27c18e8Smrg	    continue
7906c27c18e8Smrg	  fi
7907c27c18e8Smrg	  func_stripname '-l' '' "$deplib"
7908c27c18e8Smrg	  name=$func_stripname_result
790948e5ce07Smrg	  if test lib = "$linkmode"; then
7910c27c18e8Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7911c27c18e8Smrg	  else
7912c27c18e8Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7913c27c18e8Smrg	  fi
7914c27c18e8Smrg	  for searchdir in $searchdirs; do
7915c27c18e8Smrg	    for search_ext in .la $std_shrext .so .a; do
7916c27c18e8Smrg	      # Search the libtool library
791748e5ce07Smrg	      lib=$searchdir/lib$name$search_ext
7918c27c18e8Smrg	      if test -f "$lib"; then
791948e5ce07Smrg		if test .la = "$search_ext"; then
792048e5ce07Smrg		  found=:
7921c27c18e8Smrg		else
792248e5ce07Smrg		  found=false
7923c27c18e8Smrg		fi
7924c27c18e8Smrg		break 2
7925c27c18e8Smrg	      fi
7926c27c18e8Smrg	    done
7927c27c18e8Smrg	  done
792848e5ce07Smrg	  if $found; then
792948e5ce07Smrg	    # deplib is a libtool library
7930c27c18e8Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7931c27c18e8Smrg	    # We need to do some special things here, and not later.
793248e5ce07Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7933c27c18e8Smrg	      case " $predeps $postdeps " in
7934c27c18e8Smrg	      *" $deplib "*)
7935c27c18e8Smrg		if func_lalib_p "$lib"; then
7936c27c18e8Smrg		  library_names=
7937c27c18e8Smrg		  old_library=
7938c27c18e8Smrg		  func_source "$lib"
7939c27c18e8Smrg		  for l in $old_library $library_names; do
794048e5ce07Smrg		    ll=$l
7941c27c18e8Smrg		  done
794248e5ce07Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
794348e5ce07Smrg		    found=false
7944c27c18e8Smrg		    func_dirname "$lib" "" "."
794548e5ce07Smrg		    ladir=$func_dirname_result
7946c27c18e8Smrg		    lib=$ladir/$old_library
794748e5ce07Smrg		    if test prog,link = "$linkmode,$pass"; then
7948c27c18e8Smrg		      compile_deplibs="$deplib $compile_deplibs"
7949c27c18e8Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7950c27c18e8Smrg		    else
7951c27c18e8Smrg		      deplibs="$deplib $deplibs"
795248e5ce07Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7953c27c18e8Smrg		    fi
7954c27c18e8Smrg		    continue
7955c27c18e8Smrg		  fi
7956c27c18e8Smrg		fi
7957c27c18e8Smrg		;;
7958c27c18e8Smrg	      *) ;;
7959c27c18e8Smrg	      esac
7960c27c18e8Smrg	    fi
796148e5ce07Smrg	  else
796248e5ce07Smrg	    # deplib doesn't seem to be a libtool library
796348e5ce07Smrg	    if test prog,link = "$linkmode,$pass"; then
796448e5ce07Smrg	      compile_deplibs="$deplib $compile_deplibs"
796548e5ce07Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
796648e5ce07Smrg	    else
796748e5ce07Smrg	      deplibs="$deplib $deplibs"
796848e5ce07Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
796948e5ce07Smrg	    fi
797048e5ce07Smrg	    continue
7971c27c18e8Smrg	  fi
7972c27c18e8Smrg	  ;; # -l
7973c27c18e8Smrg	*.ltframework)
797448e5ce07Smrg	  if test prog,link = "$linkmode,$pass"; then
7975c27c18e8Smrg	    compile_deplibs="$deplib $compile_deplibs"
7976c27c18e8Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7977c27c18e8Smrg	  else
7978c27c18e8Smrg	    deplibs="$deplib $deplibs"
797948e5ce07Smrg	    if test lib = "$linkmode"; then
7980c27c18e8Smrg		case "$new_inherited_linker_flags " in
7981c27c18e8Smrg		    *" $deplib "*) ;;
7982b789ec8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7983c27c18e8Smrg		esac
7984c27c18e8Smrg	    fi
7985c27c18e8Smrg	  fi
7986c27c18e8Smrg	  continue
7987c27c18e8Smrg	  ;;
7988c27c18e8Smrg	-L*)
7989c27c18e8Smrg	  case $linkmode in
7990c27c18e8Smrg	  lib)
7991c27c18e8Smrg	    deplibs="$deplib $deplibs"
799248e5ce07Smrg	    test conv = "$pass" && continue
7993c27c18e8Smrg	    newdependency_libs="$deplib $newdependency_libs"
7994c27c18e8Smrg	    func_stripname '-L' '' "$deplib"
7995b789ec8aSmrg	    func_resolve_sysroot "$func_stripname_result"
7996b789ec8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7997c27c18e8Smrg	    ;;
7998c27c18e8Smrg	  prog)
799948e5ce07Smrg	    if test conv = "$pass"; then
8000c27c18e8Smrg	      deplibs="$deplib $deplibs"
8001c27c18e8Smrg	      continue
8002c27c18e8Smrg	    fi
800348e5ce07Smrg	    if test scan = "$pass"; then
8004c27c18e8Smrg	      deplibs="$deplib $deplibs"
8005c27c18e8Smrg	    else
8006c27c18e8Smrg	      compile_deplibs="$deplib $compile_deplibs"
8007c27c18e8Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8008c27c18e8Smrg	    fi
8009c27c18e8Smrg	    func_stripname '-L' '' "$deplib"
8010b789ec8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8011b789ec8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8012c27c18e8Smrg	    ;;
8013c27c18e8Smrg	  *)
801448e5ce07Smrg	    func_warning "'-L' is ignored for archives/objects"
8015c27c18e8Smrg	    ;;
8016c27c18e8Smrg	  esac # linkmode
8017c27c18e8Smrg	  continue
8018c27c18e8Smrg	  ;; # -L
8019c27c18e8Smrg	-R*)
802048e5ce07Smrg	  if test link = "$pass"; then
8021c27c18e8Smrg	    func_stripname '-R' '' "$deplib"
8022b789ec8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8023b789ec8aSmrg	    dir=$func_resolve_sysroot_result
8024c27c18e8Smrg	    # Make sure the xrpath contains only unique directories.
8025c27c18e8Smrg	    case "$xrpath " in
8026c27c18e8Smrg	    *" $dir "*) ;;
8027b789ec8aSmrg	    *) func_append xrpath " $dir" ;;
8028c27c18e8Smrg	    esac
8029c27c18e8Smrg	  fi
8030c27c18e8Smrg	  deplibs="$deplib $deplibs"
8031c27c18e8Smrg	  continue
8032c27c18e8Smrg	  ;;
8033b789ec8aSmrg	*.la)
8034b789ec8aSmrg	  func_resolve_sysroot "$deplib"
8035b789ec8aSmrg	  lib=$func_resolve_sysroot_result
8036b789ec8aSmrg	  ;;
8037c27c18e8Smrg	*.$libext)
803848e5ce07Smrg	  if test conv = "$pass"; then
8039c27c18e8Smrg	    deplibs="$deplib $deplibs"
8040c27c18e8Smrg	    continue
8041c27c18e8Smrg	  fi
8042c27c18e8Smrg	  case $linkmode in
8043c27c18e8Smrg	  lib)
8044c27c18e8Smrg	    # Linking convenience modules into shared libraries is allowed,
8045c27c18e8Smrg	    # but linking other static libraries is non-portable.
8046c27c18e8Smrg	    case " $dlpreconveniencelibs " in
8047c27c18e8Smrg	    *" $deplib "*) ;;
8048c27c18e8Smrg	    *)
804948e5ce07Smrg	      valid_a_lib=false
8050c27c18e8Smrg	      case $deplibs_check_method in
8051c27c18e8Smrg		match_pattern*)
8052c27c18e8Smrg		  set dummy $deplibs_check_method; shift
8053c27c18e8Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
805437eb1ca1Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8055c27c18e8Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
805648e5ce07Smrg		    valid_a_lib=:
8057c27c18e8Smrg		  fi
8058c27c18e8Smrg		;;
8059c27c18e8Smrg		pass_all)
806048e5ce07Smrg		  valid_a_lib=:
8061c27c18e8Smrg		;;
8062c27c18e8Smrg	      esac
806348e5ce07Smrg	      if $valid_a_lib; then
806448e5ce07Smrg		echo
806548e5ce07Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
806648e5ce07Smrg		$ECHO "*** static library $deplib is not portable!"
806748e5ce07Smrg		deplibs="$deplib $deplibs"
806848e5ce07Smrg	      else
806937eb1ca1Smrg		echo
8070c27c18e8Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807137eb1ca1Smrg		echo "*** I have the capability to make that library automatically link in when"
807237eb1ca1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
807337eb1ca1Smrg		echo "*** shared version of the library, which you do not appear to have"
807437eb1ca1Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
807537eb1ca1Smrg		echo "*** that it is just a static archive that I should not use here."
8076c27c18e8Smrg	      fi
8077c27c18e8Smrg	      ;;
8078c27c18e8Smrg	    esac
8079c27c18e8Smrg	    continue
8080c27c18e8Smrg	    ;;
8081c27c18e8Smrg	  prog)
808248e5ce07Smrg	    if test link != "$pass"; then
8083c27c18e8Smrg	      deplibs="$deplib $deplibs"
8084c27c18e8Smrg	    else
8085c27c18e8Smrg	      compile_deplibs="$deplib $compile_deplibs"
8086c27c18e8Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8087c27c18e8Smrg	    fi
8088c27c18e8Smrg	    continue
8089c27c18e8Smrg	    ;;
8090c27c18e8Smrg	  esac # linkmode
8091c27c18e8Smrg	  ;; # *.$libext
8092c27c18e8Smrg	*.lo | *.$objext)
809348e5ce07Smrg	  if test conv = "$pass"; then
8094c27c18e8Smrg	    deplibs="$deplib $deplibs"
809548e5ce07Smrg	  elif test prog = "$linkmode"; then
809648e5ce07Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8097c27c18e8Smrg	      # If there is no dlopen support or we're linking statically,
8098c27c18e8Smrg	      # we need to preload.
8099b789ec8aSmrg	      func_append newdlprefiles " $deplib"
8100c27c18e8Smrg	      compile_deplibs="$deplib $compile_deplibs"
8101c27c18e8Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8102c27c18e8Smrg	    else
8103b789ec8aSmrg	      func_append newdlfiles " $deplib"
8104c27c18e8Smrg	    fi
8105c27c18e8Smrg	  fi
8106c27c18e8Smrg	  continue
8107c27c18e8Smrg	  ;;
8108c27c18e8Smrg	%DEPLIBS%)
810948e5ce07Smrg	  alldeplibs=:
8110c27c18e8Smrg	  continue
8111c27c18e8Smrg	  ;;
8112c27c18e8Smrg	esac # case $deplib
8113c27c18e8Smrg
811448e5ce07Smrg	$found || test -f "$lib" \
811548e5ce07Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8116c27c18e8Smrg
8117c27c18e8Smrg	# Check to see that this really is a libtool archive.
8118c27c18e8Smrg	func_lalib_unsafe_p "$lib" \
811948e5ce07Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8120c27c18e8Smrg
8121c27c18e8Smrg	func_dirname "$lib" "" "."
812248e5ce07Smrg	ladir=$func_dirname_result
8123c27c18e8Smrg
8124c27c18e8Smrg	dlname=
8125c27c18e8Smrg	dlopen=
8126c27c18e8Smrg	dlpreopen=
8127c27c18e8Smrg	libdir=
8128c27c18e8Smrg	library_names=
8129c27c18e8Smrg	old_library=
8130c27c18e8Smrg	inherited_linker_flags=
8131c27c18e8Smrg	# If the library was installed with an old release of libtool,
8132c27c18e8Smrg	# it will not redefine variables installed, or shouldnotlink
8133c27c18e8Smrg	installed=yes
8134c27c18e8Smrg	shouldnotlink=no
8135c27c18e8Smrg	avoidtemprpath=
8136c27c18e8Smrg
8137c27c18e8Smrg
8138c27c18e8Smrg	# Read the .la file
8139c27c18e8Smrg	func_source "$lib"
8140c27c18e8Smrg
8141c27c18e8Smrg	# Convert "-framework foo" to "foo.ltframework"
8142c27c18e8Smrg	if test -n "$inherited_linker_flags"; then
814337eb1ca1Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8144c27c18e8Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8145c27c18e8Smrg	    case " $new_inherited_linker_flags " in
8146c27c18e8Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8147b789ec8aSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8148c27c18e8Smrg	    esac
8149c27c18e8Smrg	  done
8150c27c18e8Smrg	fi
815137eb1ca1Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
815248e5ce07Smrg	if test lib,link = "$linkmode,$pass" ||
815348e5ce07Smrg	   test prog,scan = "$linkmode,$pass" ||
815448e5ce07Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8155b789ec8aSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8156b789ec8aSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8157c27c18e8Smrg	fi
8158c27c18e8Smrg
815948e5ce07Smrg	if test conv = "$pass"; then
8160c27c18e8Smrg	  # Only check for convenience libraries
8161c27c18e8Smrg	  deplibs="$lib $deplibs"
8162c27c18e8Smrg	  if test -z "$libdir"; then
8163c27c18e8Smrg	    if test -z "$old_library"; then
816448e5ce07Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
8165c27c18e8Smrg	    fi
8166c27c18e8Smrg	    # It is a libtool convenience library, so add in its objects.
8167b789ec8aSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8168b789ec8aSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
816948e5ce07Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
817048e5ce07Smrg	    func_fatal_error "'$lib' is not a convenience library"
8171c27c18e8Smrg	  fi
81724e8f48c7Smrg	  tmp_libs=
81734e8f48c7Smrg	  for deplib in $dependency_libs; do
81744e8f48c7Smrg	    deplibs="$deplib $deplibs"
81754e8f48c7Smrg	    if $opt_preserve_dup_deps; then
81764e8f48c7Smrg	      case "$tmp_libs " in
81774e8f48c7Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
81784e8f48c7Smrg	      esac
81794e8f48c7Smrg	    fi
81804e8f48c7Smrg	    func_append tmp_libs " $deplib"
81814e8f48c7Smrg	  done
8182c27c18e8Smrg	  continue
8183c27c18e8Smrg	fi # $pass = conv
8184c27c18e8Smrg
8185c27c18e8Smrg
8186c27c18e8Smrg	# Get the name of the library we link against.
8187c27c18e8Smrg	linklib=
8188b789ec8aSmrg	if test -n "$old_library" &&
818948e5ce07Smrg	   { test yes = "$prefer_static_libs" ||
819048e5ce07Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8191b789ec8aSmrg	  linklib=$old_library
8192b789ec8aSmrg	else
8193b789ec8aSmrg	  for l in $old_library $library_names; do
819448e5ce07Smrg	    linklib=$l
8195b789ec8aSmrg	  done
8196b789ec8aSmrg	fi
8197c27c18e8Smrg	if test -z "$linklib"; then
819848e5ce07Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
8199c27c18e8Smrg	fi
8200c27c18e8Smrg
8201c27c18e8Smrg	# This library was specified with -dlopen.
820248e5ce07Smrg	if test dlopen = "$pass"; then
820348e5ce07Smrg	  test -z "$libdir" \
820448e5ce07Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8205c27c18e8Smrg	  if test -z "$dlname" ||
820648e5ce07Smrg	     test yes != "$dlopen_support" ||
820748e5ce07Smrg	     test no = "$build_libtool_libs"
820848e5ce07Smrg	  then
8209c27c18e8Smrg	    # If there is no dlname, no dlopen support or we're linking
8210c27c18e8Smrg	    # statically, we need to preload.  We also need to preload any
8211c27c18e8Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8212c27c18e8Smrg	    # bomb out in the load deplibs phase.
8213b789ec8aSmrg	    func_append dlprefiles " $lib $dependency_libs"
8214c27c18e8Smrg	  else
8215b789ec8aSmrg	    func_append newdlfiles " $lib"
8216c27c18e8Smrg	  fi
8217c27c18e8Smrg	  continue
8218c27c18e8Smrg	fi # $pass = dlopen
8219c27c18e8Smrg
8220c27c18e8Smrg	# We need an absolute path.
8221c27c18e8Smrg	case $ladir in
822248e5ce07Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8223c27c18e8Smrg	*)
8224c27c18e8Smrg	  abs_ladir=`cd "$ladir" && pwd`
8225c27c18e8Smrg	  if test -z "$abs_ladir"; then
822648e5ce07Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8227c27c18e8Smrg	    func_warning "passing it literally to the linker, although it might fail"
822848e5ce07Smrg	    abs_ladir=$ladir
8229c27c18e8Smrg	  fi
8230c27c18e8Smrg	  ;;
8231c27c18e8Smrg	esac
8232c27c18e8Smrg	func_basename "$lib"
823348e5ce07Smrg	laname=$func_basename_result
8234c27c18e8Smrg
8235c27c18e8Smrg	# Find the relevant object directory and library name.
823648e5ce07Smrg	if test yes = "$installed"; then
8237b789ec8aSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
823848e5ce07Smrg	    func_warning "library '$lib' was moved."
823948e5ce07Smrg	    dir=$ladir
824048e5ce07Smrg	    absdir=$abs_ladir
824148e5ce07Smrg	    libdir=$abs_ladir
8242c27c18e8Smrg	  else
824348e5ce07Smrg	    dir=$lt_sysroot$libdir
824448e5ce07Smrg	    absdir=$lt_sysroot$libdir
8245c27c18e8Smrg	  fi
824648e5ce07Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8247c27c18e8Smrg	else
8248c27c18e8Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
824948e5ce07Smrg	    dir=$ladir
825048e5ce07Smrg	    absdir=$abs_ladir
8251c27c18e8Smrg	    # Remove this search path later
8252b789ec8aSmrg	    func_append notinst_path " $abs_ladir"
8253c27c18e8Smrg	  else
825448e5ce07Smrg	    dir=$ladir/$objdir
825548e5ce07Smrg	    absdir=$abs_ladir/$objdir
8256c27c18e8Smrg	    # Remove this search path later
8257b789ec8aSmrg	    func_append notinst_path " $abs_ladir"
8258c27c18e8Smrg	  fi
8259c27c18e8Smrg	fi # $installed = yes
8260c27c18e8Smrg	func_stripname 'lib' '.la' "$laname"
8261c27c18e8Smrg	name=$func_stripname_result
8262c27c18e8Smrg
8263c27c18e8Smrg	# This library was specified with -dlpreopen.
826448e5ce07Smrg	if test dlpreopen = "$pass"; then
826548e5ce07Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
826648e5ce07Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8267c27c18e8Smrg	  fi
826848e5ce07Smrg	  case $host in
8269b789ec8aSmrg	    # special handling for platforms with PE-DLLs.
8270b789ec8aSmrg	    *cygwin* | *mingw* | *cegcc* )
8271b789ec8aSmrg	      # Linker will automatically link against shared library if both
8272b789ec8aSmrg	      # static and shared are present.  Therefore, ensure we extract
8273b789ec8aSmrg	      # symbols from the import library if a shared library is present
8274b789ec8aSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8275b789ec8aSmrg	      # this by putting the import library name into $newdlprefiles.
8276b789ec8aSmrg	      # We recover the dlopen module name by 'saving' the la file
8277b789ec8aSmrg	      # name in a special purpose variable, and (later) extracting the
8278b789ec8aSmrg	      # dlname from the la file.
8279b789ec8aSmrg	      if test -n "$dlname"; then
8280b789ec8aSmrg	        func_tr_sh "$dir/$linklib"
8281b789ec8aSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8282b789ec8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8283b789ec8aSmrg	      else
8284b789ec8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8285b789ec8aSmrg	        # Keep a list of preopened convenience libraries to check
8286b789ec8aSmrg	        # that they are being used correctly in the link pass.
8287b789ec8aSmrg	        test -z "$libdir" && \
8288b789ec8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8289b789ec8aSmrg	      fi
8290b789ec8aSmrg	    ;;
8291b789ec8aSmrg	    * )
8292b789ec8aSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8293b789ec8aSmrg	      # are required to link).
8294b789ec8aSmrg	      if test -n "$old_library"; then
8295b789ec8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8296b789ec8aSmrg	        # Keep a list of preopened convenience libraries to check
8297b789ec8aSmrg	        # that they are being used correctly in the link pass.
8298b789ec8aSmrg	        test -z "$libdir" && \
8299b789ec8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8300b789ec8aSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8301b789ec8aSmrg	      elif test -n "$dlname"; then
8302b789ec8aSmrg	        func_append newdlprefiles " $dir/$dlname"
8303b789ec8aSmrg	      else
8304b789ec8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8305b789ec8aSmrg	      fi
8306b789ec8aSmrg	    ;;
8307b789ec8aSmrg	  esac
8308c27c18e8Smrg	fi # $pass = dlpreopen
8309c27c18e8Smrg
8310c27c18e8Smrg	if test -z "$libdir"; then
8311c27c18e8Smrg	  # Link the convenience library
831248e5ce07Smrg	  if test lib = "$linkmode"; then
8313c27c18e8Smrg	    deplibs="$dir/$old_library $deplibs"
831448e5ce07Smrg	  elif test prog,link = "$linkmode,$pass"; then
8315c27c18e8Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8316c27c18e8Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8317c27c18e8Smrg	  else
8318c27c18e8Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8319c27c18e8Smrg	  fi
8320c27c18e8Smrg	  continue
8321c27c18e8Smrg	fi
8322c27c18e8Smrg
8323c27c18e8Smrg
832448e5ce07Smrg	if test prog = "$linkmode" && test link != "$pass"; then
8325b789ec8aSmrg	  func_append newlib_search_path " $ladir"
8326c27c18e8Smrg	  deplibs="$lib $deplibs"
8327c27c18e8Smrg
832848e5ce07Smrg	  linkalldeplibs=false
832948e5ce07Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
833048e5ce07Smrg	     test no = "$build_libtool_libs"; then
833148e5ce07Smrg	    linkalldeplibs=:
8332c27c18e8Smrg	  fi
8333c27c18e8Smrg
8334c27c18e8Smrg	  tmp_libs=
8335c27c18e8Smrg	  for deplib in $dependency_libs; do
8336c27c18e8Smrg	    case $deplib in
8337c27c18e8Smrg	    -L*) func_stripname '-L' '' "$deplib"
8338b789ec8aSmrg	         func_resolve_sysroot "$func_stripname_result"
8339b789ec8aSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8340c27c18e8Smrg		 ;;
8341c27c18e8Smrg	    esac
8342c27c18e8Smrg	    # Need to link against all dependency_libs?
834348e5ce07Smrg	    if $linkalldeplibs; then
8344c27c18e8Smrg	      deplibs="$deplib $deplibs"
8345c27c18e8Smrg	    else
8346c27c18e8Smrg	      # Need to hardcode shared library paths
8347c27c18e8Smrg	      # or/and link against static libraries
8348c27c18e8Smrg	      newdependency_libs="$deplib $newdependency_libs"
8349c27c18e8Smrg	    fi
835048e5ce07Smrg	    if $opt_preserve_dup_deps; then
8351c27c18e8Smrg	      case "$tmp_libs " in
8352b789ec8aSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8353c27c18e8Smrg	      esac
8354c27c18e8Smrg	    fi
8355b789ec8aSmrg	    func_append tmp_libs " $deplib"
8356c27c18e8Smrg	  done # for deplib
8357c27c18e8Smrg	  continue
8358c27c18e8Smrg	fi # $linkmode = prog...
8359c27c18e8Smrg
836048e5ce07Smrg	if test prog,link = "$linkmode,$pass"; then
8361c27c18e8Smrg	  if test -n "$library_names" &&
836248e5ce07Smrg	     { { test no = "$prefer_static_libs" ||
836348e5ce07Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8364c27c18e8Smrg	       test -z "$old_library"; }; then
8365c27c18e8Smrg	    # We need to hardcode the library path
836648e5ce07Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8367c27c18e8Smrg	      # Make sure the rpath contains only unique directories.
836848e5ce07Smrg	      case $temp_rpath: in
8369c27c18e8Smrg	      *"$absdir:"*) ;;
8370b789ec8aSmrg	      *) func_append temp_rpath "$absdir:" ;;
8371c27c18e8Smrg	      esac
8372c27c18e8Smrg	    fi
8373c27c18e8Smrg
8374c27c18e8Smrg	    # Hardcode the library path.
8375c27c18e8Smrg	    # Skip directories that are in the system default run-time
8376c27c18e8Smrg	    # search path.
8377c27c18e8Smrg	    case " $sys_lib_dlsearch_path " in
8378c27c18e8Smrg	    *" $absdir "*) ;;
8379c27c18e8Smrg	    *)
8380c27c18e8Smrg	      case "$compile_rpath " in
8381c27c18e8Smrg	      *" $absdir "*) ;;
8382b789ec8aSmrg	      *) func_append compile_rpath " $absdir" ;;
8383c27c18e8Smrg	      esac
8384c27c18e8Smrg	      ;;
8385c27c18e8Smrg	    esac
8386c27c18e8Smrg	    case " $sys_lib_dlsearch_path " in
8387c27c18e8Smrg	    *" $libdir "*) ;;
8388c27c18e8Smrg	    *)
8389c27c18e8Smrg	      case "$finalize_rpath " in
8390c27c18e8Smrg	      *" $libdir "*) ;;
8391b789ec8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
8392c27c18e8Smrg	      esac
8393c27c18e8Smrg	      ;;
8394c27c18e8Smrg	    esac
8395c27c18e8Smrg	  fi # $linkmode,$pass = prog,link...
8396c27c18e8Smrg
839748e5ce07Smrg	  if $alldeplibs &&
839848e5ce07Smrg	     { test pass_all = "$deplibs_check_method" ||
839948e5ce07Smrg	       { test yes = "$build_libtool_libs" &&
8400c27c18e8Smrg		 test -n "$library_names"; }; }; then
8401c27c18e8Smrg	    # We only need to search for static libraries
8402c27c18e8Smrg	    continue
8403c27c18e8Smrg	  fi
8404c27c18e8Smrg	fi
8405c27c18e8Smrg
8406c27c18e8Smrg	link_static=no # Whether the deplib will be linked statically
8407c27c18e8Smrg	use_static_libs=$prefer_static_libs
840848e5ce07Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8409c27c18e8Smrg	  use_static_libs=no
8410c27c18e8Smrg	fi
8411c27c18e8Smrg	if test -n "$library_names" &&
841248e5ce07Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8413c27c18e8Smrg	  case $host in
841448e5ce07Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8415c27c18e8Smrg	      # No point in relinking DLLs because paths are not encoded
8416b789ec8aSmrg	      func_append notinst_deplibs " $lib"
8417c27c18e8Smrg	      need_relink=no
8418c27c18e8Smrg	    ;;
8419c27c18e8Smrg	  *)
842048e5ce07Smrg	    if test no = "$installed"; then
8421b789ec8aSmrg	      func_append notinst_deplibs " $lib"
8422c27c18e8Smrg	      need_relink=yes
8423c27c18e8Smrg	    fi
8424c27c18e8Smrg	    ;;
8425c27c18e8Smrg	  esac
8426c27c18e8Smrg	  # This is a shared library
8427c27c18e8Smrg
8428c27c18e8Smrg	  # Warn about portability, can't link against -module's on some
8429c27c18e8Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
843048e5ce07Smrg	  dlopenmodule=
8431c27c18e8Smrg	  for dlpremoduletest in $dlprefiles; do
8432c27c18e8Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
843348e5ce07Smrg	      dlopenmodule=$dlpremoduletest
8434c27c18e8Smrg	      break
8435c27c18e8Smrg	    fi
8436c27c18e8Smrg	  done
843748e5ce07Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
843837eb1ca1Smrg	    echo
843948e5ce07Smrg	    if test prog = "$linkmode"; then
8440c27c18e8Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8441c27c18e8Smrg	    else
8442c27c18e8Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8443c27c18e8Smrg	    fi
8444c27c18e8Smrg	    $ECHO "*** $linklib is not portable!"
8445c27c18e8Smrg	  fi
844648e5ce07Smrg	  if test lib = "$linkmode" &&
844748e5ce07Smrg	     test yes = "$hardcode_into_libs"; then
8448c27c18e8Smrg	    # Hardcode the library path.
8449c27c18e8Smrg	    # Skip directories that are in the system default run-time
8450c27c18e8Smrg	    # search path.
8451c27c18e8Smrg	    case " $sys_lib_dlsearch_path " in
8452c27c18e8Smrg	    *" $absdir "*) ;;
8453c27c18e8Smrg	    *)
8454c27c18e8Smrg	      case "$compile_rpath " in
8455c27c18e8Smrg	      *" $absdir "*) ;;
8456b789ec8aSmrg	      *) func_append compile_rpath " $absdir" ;;
8457c27c18e8Smrg	      esac
8458c27c18e8Smrg	      ;;
8459c27c18e8Smrg	    esac
8460c27c18e8Smrg	    case " $sys_lib_dlsearch_path " in
8461c27c18e8Smrg	    *" $libdir "*) ;;
8462c27c18e8Smrg	    *)
8463c27c18e8Smrg	      case "$finalize_rpath " in
8464c27c18e8Smrg	      *" $libdir "*) ;;
8465b789ec8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
8466c27c18e8Smrg	      esac
8467c27c18e8Smrg	      ;;
8468c27c18e8Smrg	    esac
8469c27c18e8Smrg	  fi
8470c27c18e8Smrg
8471c27c18e8Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8472c27c18e8Smrg	    # figure out the soname
8473c27c18e8Smrg	    set dummy $library_names
8474c27c18e8Smrg	    shift
847548e5ce07Smrg	    realname=$1
8476c27c18e8Smrg	    shift
8477c27c18e8Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8478c27c18e8Smrg	    # use dlname if we got it. it's perfectly good, no?
8479c27c18e8Smrg	    if test -n "$dlname"; then
848048e5ce07Smrg	      soname=$dlname
8481c27c18e8Smrg	    elif test -n "$soname_spec"; then
8482c27c18e8Smrg	      # bleh windows
8483c27c18e8Smrg	      case $host in
848448e5ce07Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8485c27c18e8Smrg	        func_arith $current - $age
8486c27c18e8Smrg		major=$func_arith_result
848748e5ce07Smrg		versuffix=-$major
8488c27c18e8Smrg		;;
8489c27c18e8Smrg	      esac
8490c27c18e8Smrg	      eval soname=\"$soname_spec\"
8491c27c18e8Smrg	    else
849248e5ce07Smrg	      soname=$realname
8493c27c18e8Smrg	    fi
8494c27c18e8Smrg
8495c27c18e8Smrg	    # Make a new name for the extract_expsyms_cmds to use
849648e5ce07Smrg	    soroot=$soname
8497c27c18e8Smrg	    func_basename "$soroot"
849848e5ce07Smrg	    soname=$func_basename_result
8499c27c18e8Smrg	    func_stripname 'lib' '.dll' "$soname"
8500c27c18e8Smrg	    newlib=libimp-$func_stripname_result.a
8501c27c18e8Smrg
8502c27c18e8Smrg	    # If the library has no export list, then create one now
8503c27c18e8Smrg	    if test -f "$output_objdir/$soname-def"; then :
8504c27c18e8Smrg	    else
850548e5ce07Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8506c27c18e8Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8507c27c18e8Smrg	    fi
8508c27c18e8Smrg
8509c27c18e8Smrg	    # Create $newlib
8510c27c18e8Smrg	    if test -f "$output_objdir/$newlib"; then :; else
851148e5ce07Smrg	      func_verbose "generating import library for '$soname'"
8512c27c18e8Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8513c27c18e8Smrg	    fi
8514c27c18e8Smrg	    # make sure the library variables are pointing to the new library
8515c27c18e8Smrg	    dir=$output_objdir
8516c27c18e8Smrg	    linklib=$newlib
8517c27c18e8Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8518c27c18e8Smrg
851948e5ce07Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8520c27c18e8Smrg	    add_shlibpath=
8521c27c18e8Smrg	    add_dir=
8522c27c18e8Smrg	    add=
8523c27c18e8Smrg	    lib_linked=yes
8524c27c18e8Smrg	    case $hardcode_action in
8525c27c18e8Smrg	    immediate | unsupported)
852648e5ce07Smrg	      if test no = "$hardcode_direct"; then
852748e5ce07Smrg		add=$dir/$linklib
8528c27c18e8Smrg		case $host in
852948e5ce07Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
853048e5ce07Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8531c27c18e8Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
853248e5ce07Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8533c27c18e8Smrg		  *-*-darwin* )
853448e5ce07Smrg		    # if the lib is a (non-dlopened) module then we cannot
8535c27c18e8Smrg		    # link against it, someone is ignoring the earlier warnings
8536c27c18e8Smrg		    if /usr/bin/file -L $add 2> /dev/null |
853748e5ce07Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8538c27c18e8Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8539c27c18e8Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
854048e5ce07Smrg			if test -z "$old_library"; then
854137eb1ca1Smrg			  echo
854237eb1ca1Smrg			  echo "*** And there doesn't seem to be a static archive available"
854337eb1ca1Smrg			  echo "*** The link will probably fail, sorry"
8544c27c18e8Smrg			else
854548e5ce07Smrg			  add=$dir/$old_library
8546c27c18e8Smrg			fi
8547c27c18e8Smrg		      elif test -n "$old_library"; then
854848e5ce07Smrg			add=$dir/$old_library
8549c27c18e8Smrg		      fi
8550c27c18e8Smrg		    fi
8551c27c18e8Smrg		esac
855248e5ce07Smrg	      elif test no = "$hardcode_minus_L"; then
8553c27c18e8Smrg		case $host in
855448e5ce07Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8555c27c18e8Smrg		esac
855648e5ce07Smrg		add_dir=-L$dir
855748e5ce07Smrg		add=-l$name
855848e5ce07Smrg	      elif test no = "$hardcode_shlibpath_var"; then
855948e5ce07Smrg		add_shlibpath=$dir
856048e5ce07Smrg		add=-l$name
8561c27c18e8Smrg	      else
8562c27c18e8Smrg		lib_linked=no
8563c27c18e8Smrg	      fi
8564c27c18e8Smrg	      ;;
8565c27c18e8Smrg	    relink)
856648e5ce07Smrg	      if test yes = "$hardcode_direct" &&
856748e5ce07Smrg	         test no = "$hardcode_direct_absolute"; then
856848e5ce07Smrg		add=$dir/$linklib
856948e5ce07Smrg	      elif test yes = "$hardcode_minus_L"; then
857048e5ce07Smrg		add_dir=-L$absdir
8571c27c18e8Smrg		# Try looking first in the location we're being installed to.
8572c27c18e8Smrg		if test -n "$inst_prefix_dir"; then
8573c27c18e8Smrg		  case $libdir in
8574c27c18e8Smrg		    [\\/]*)
8575b789ec8aSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8576c27c18e8Smrg		      ;;
8577c27c18e8Smrg		  esac
8578c27c18e8Smrg		fi
857948e5ce07Smrg		add=-l$name
858048e5ce07Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
858148e5ce07Smrg		add_shlibpath=$dir
858248e5ce07Smrg		add=-l$name
8583c27c18e8Smrg	      else
8584c27c18e8Smrg		lib_linked=no
8585c27c18e8Smrg	      fi
8586c27c18e8Smrg	      ;;
8587c27c18e8Smrg	    *) lib_linked=no ;;
8588c27c18e8Smrg	    esac
8589c27c18e8Smrg
859048e5ce07Smrg	    if test yes != "$lib_linked"; then
8591c27c18e8Smrg	      func_fatal_configuration "unsupported hardcode properties"
8592c27c18e8Smrg	    fi
8593c27c18e8Smrg
8594c27c18e8Smrg	    if test -n "$add_shlibpath"; then
8595c27c18e8Smrg	      case :$compile_shlibpath: in
8596c27c18e8Smrg	      *":$add_shlibpath:"*) ;;
8597b789ec8aSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8598c27c18e8Smrg	      esac
8599c27c18e8Smrg	    fi
860048e5ce07Smrg	    if test prog = "$linkmode"; then
8601c27c18e8Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8602c27c18e8Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8603c27c18e8Smrg	    else
8604c27c18e8Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8605c27c18e8Smrg	      test -n "$add" && deplibs="$add $deplibs"
860648e5ce07Smrg	      if test yes != "$hardcode_direct" &&
860748e5ce07Smrg		 test yes != "$hardcode_minus_L" &&
860848e5ce07Smrg		 test yes = "$hardcode_shlibpath_var"; then
8609c27c18e8Smrg		case :$finalize_shlibpath: in
8610c27c18e8Smrg		*":$libdir:"*) ;;
8611b789ec8aSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8612c27c18e8Smrg		esac
8613c27c18e8Smrg	      fi
8614c27c18e8Smrg	    fi
8615c27c18e8Smrg	  fi
8616c27c18e8Smrg
861748e5ce07Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8618c27c18e8Smrg	    add_shlibpath=
8619c27c18e8Smrg	    add_dir=
8620c27c18e8Smrg	    add=
8621c27c18e8Smrg	    # Finalize command for both is simple: just hardcode it.
862248e5ce07Smrg	    if test yes = "$hardcode_direct" &&
862348e5ce07Smrg	       test no = "$hardcode_direct_absolute"; then
862448e5ce07Smrg	      add=$libdir/$linklib
862548e5ce07Smrg	    elif test yes = "$hardcode_minus_L"; then
862648e5ce07Smrg	      add_dir=-L$libdir
862748e5ce07Smrg	      add=-l$name
862848e5ce07Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8629c27c18e8Smrg	      case :$finalize_shlibpath: in
8630c27c18e8Smrg	      *":$libdir:"*) ;;
8631b789ec8aSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8632c27c18e8Smrg	      esac
863348e5ce07Smrg	      add=-l$name
863448e5ce07Smrg	    elif test yes = "$hardcode_automatic"; then
8635c27c18e8Smrg	      if test -n "$inst_prefix_dir" &&
863648e5ce07Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
863748e5ce07Smrg		add=$inst_prefix_dir$libdir/$linklib
8638c27c18e8Smrg	      else
863948e5ce07Smrg		add=$libdir/$linklib
8640c27c18e8Smrg	      fi
8641c27c18e8Smrg	    else
8642c27c18e8Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
864348e5ce07Smrg	      add_dir=-L$libdir
8644c27c18e8Smrg	      # Try looking first in the location we're being installed to.
8645c27c18e8Smrg	      if test -n "$inst_prefix_dir"; then
8646c27c18e8Smrg		case $libdir in
8647c27c18e8Smrg		  [\\/]*)
8648b789ec8aSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8649c27c18e8Smrg		    ;;
8650c27c18e8Smrg		esac
8651c27c18e8Smrg	      fi
865248e5ce07Smrg	      add=-l$name
8653c27c18e8Smrg	    fi
8654c27c18e8Smrg
865548e5ce07Smrg	    if test prog = "$linkmode"; then
8656c27c18e8Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8657c27c18e8Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8658c27c18e8Smrg	    else
8659c27c18e8Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8660c27c18e8Smrg	      test -n "$add" && deplibs="$add $deplibs"
8661c27c18e8Smrg	    fi
8662c27c18e8Smrg	  fi
866348e5ce07Smrg	elif test prog = "$linkmode"; then
8664c27c18e8Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8665c27c18e8Smrg	  # is not unsupported.  This is valid on all known static and
8666c27c18e8Smrg	  # shared platforms.
866748e5ce07Smrg	  if test unsupported != "$hardcode_direct"; then
866848e5ce07Smrg	    test -n "$old_library" && linklib=$old_library
8669c27c18e8Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8670c27c18e8Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8671c27c18e8Smrg	  else
8672c27c18e8Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8673c27c18e8Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8674c27c18e8Smrg	  fi
867548e5ce07Smrg	elif test yes = "$build_libtool_libs"; then
8676c27c18e8Smrg	  # Not a shared library
867748e5ce07Smrg	  if test pass_all != "$deplibs_check_method"; then
8678c27c18e8Smrg	    # We're trying link a shared library against a static one
8679c27c18e8Smrg	    # but the system doesn't support it.
8680c27c18e8Smrg
8681c27c18e8Smrg	    # Just print a warning and add the library to dependency_libs so
8682c27c18e8Smrg	    # that the program can be linked against the static library.
868337eb1ca1Smrg	    echo
868448e5ce07Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
868537eb1ca1Smrg	    echo "*** I have the capability to make that library automatically link in when"
868637eb1ca1Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
868737eb1ca1Smrg	    echo "*** shared version of the library, which you do not appear to have."
868848e5ce07Smrg	    if test yes = "$module"; then
868937eb1ca1Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869037eb1ca1Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869137eb1ca1Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8692c27c18e8Smrg	      if test -z "$global_symbol_pipe"; then
869337eb1ca1Smrg		echo
869437eb1ca1Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
869548e5ce07Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
869637eb1ca1Smrg		echo "*** not find such a program.  So, this module is probably useless."
869748e5ce07Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8698c27c18e8Smrg	      fi
869948e5ce07Smrg	      if test no = "$build_old_libs"; then
8700c27c18e8Smrg		build_libtool_libs=module
8701c27c18e8Smrg		build_old_libs=yes
8702c27c18e8Smrg	      else
8703c27c18e8Smrg		build_libtool_libs=no
8704c27c18e8Smrg	      fi
8705c27c18e8Smrg	    fi
8706c27c18e8Smrg	  else
8707c27c18e8Smrg	    deplibs="$dir/$old_library $deplibs"
8708c27c18e8Smrg	    link_static=yes
8709c27c18e8Smrg	  fi
8710c27c18e8Smrg	fi # link shared/static library?
8711c27c18e8Smrg
871248e5ce07Smrg	if test lib = "$linkmode"; then
8713c27c18e8Smrg	  if test -n "$dependency_libs" &&
871448e5ce07Smrg	     { test yes != "$hardcode_into_libs" ||
871548e5ce07Smrg	       test yes = "$build_old_libs" ||
871648e5ce07Smrg	       test yes = "$link_static"; }; then
8717c27c18e8Smrg	    # Extract -R from dependency_libs
8718c27c18e8Smrg	    temp_deplibs=
8719c27c18e8Smrg	    for libdir in $dependency_libs; do
8720c27c18e8Smrg	      case $libdir in
8721c27c18e8Smrg	      -R*) func_stripname '-R' '' "$libdir"
8722c27c18e8Smrg	           temp_xrpath=$func_stripname_result
8723c27c18e8Smrg		   case " $xrpath " in
8724c27c18e8Smrg		   *" $temp_xrpath "*) ;;
8725b789ec8aSmrg		   *) func_append xrpath " $temp_xrpath";;
8726c27c18e8Smrg		   esac;;
8727b789ec8aSmrg	      *) func_append temp_deplibs " $libdir";;
8728c27c18e8Smrg	      esac
8729c27c18e8Smrg	    done
873048e5ce07Smrg	    dependency_libs=$temp_deplibs
8731c27c18e8Smrg	  fi
8732c27c18e8Smrg
8733b789ec8aSmrg	  func_append newlib_search_path " $absdir"
8734c27c18e8Smrg	  # Link against this library
873548e5ce07Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8736c27c18e8Smrg	  # ... and its dependency_libs
8737c27c18e8Smrg	  tmp_libs=
8738c27c18e8Smrg	  for deplib in $dependency_libs; do
8739c27c18e8Smrg	    newdependency_libs="$deplib $newdependency_libs"
8740b789ec8aSmrg	    case $deplib in
8741b789ec8aSmrg              -L*) func_stripname '-L' '' "$deplib"
8742b789ec8aSmrg                   func_resolve_sysroot "$func_stripname_result";;
8743b789ec8aSmrg              *) func_resolve_sysroot "$deplib" ;;
8744b789ec8aSmrg            esac
874548e5ce07Smrg	    if $opt_preserve_dup_deps; then
8746c27c18e8Smrg	      case "$tmp_libs " in
8747b789ec8aSmrg	      *" $func_resolve_sysroot_result "*)
8748b789ec8aSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8749c27c18e8Smrg	      esac
8750c27c18e8Smrg	    fi
8751b789ec8aSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8752c27c18e8Smrg	  done
8753c27c18e8Smrg
875448e5ce07Smrg	  if test no != "$link_all_deplibs"; then
8755c27c18e8Smrg	    # Add the search paths of all dependency libraries
8756c27c18e8Smrg	    for deplib in $dependency_libs; do
875737eb1ca1Smrg	      path=
8758c27c18e8Smrg	      case $deplib in
875948e5ce07Smrg	      -L*) path=$deplib ;;
8760c27c18e8Smrg	      *.la)
8761b789ec8aSmrg	        func_resolve_sysroot "$deplib"
8762b789ec8aSmrg	        deplib=$func_resolve_sysroot_result
8763c27c18e8Smrg	        func_dirname "$deplib" "" "."
8764b789ec8aSmrg		dir=$func_dirname_result
8765c27c18e8Smrg		# We need an absolute path.
8766c27c18e8Smrg		case $dir in
876748e5ce07Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8768c27c18e8Smrg		*)
8769c27c18e8Smrg		  absdir=`cd "$dir" && pwd`
8770c27c18e8Smrg		  if test -z "$absdir"; then
877148e5ce07Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
877248e5ce07Smrg		    absdir=$dir
8773c27c18e8Smrg		  fi
8774c27c18e8Smrg		  ;;
8775c27c18e8Smrg		esac
8776c27c18e8Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8777c27c18e8Smrg		case $host in
8778c27c18e8Smrg		*-*-darwin*)
8779c27c18e8Smrg		  depdepl=
878048e5ce07Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
878148e5ce07Smrg		  if test -n "$deplibrary_names"; then
878248e5ce07Smrg		    for tmp in $deplibrary_names; do
8783c27c18e8Smrg		      depdepl=$tmp
8784c27c18e8Smrg		    done
878548e5ce07Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
878648e5ce07Smrg		      depdepl=$absdir/$objdir/$depdepl
878748e5ce07Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8788c27c18e8Smrg                      if test -z "$darwin_install_name"; then
878948e5ce07Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8790c27c18e8Smrg                      fi
879148e5ce07Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
879248e5ce07Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8793c27c18e8Smrg		      path=
8794c27c18e8Smrg		    fi
8795c27c18e8Smrg		  fi
8796c27c18e8Smrg		  ;;
8797c27c18e8Smrg		*)
879848e5ce07Smrg		  path=-L$absdir/$objdir
8799c27c18e8Smrg		  ;;
8800c27c18e8Smrg		esac
8801c27c18e8Smrg		else
880248e5ce07Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8803c27c18e8Smrg		  test -z "$libdir" && \
880448e5ce07Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8805c27c18e8Smrg		  test "$absdir" != "$libdir" && \
880648e5ce07Smrg		    func_warning "'$deplib' seems to be moved"
8807c27c18e8Smrg
880848e5ce07Smrg		  path=-L$absdir
8809c27c18e8Smrg		fi
8810c27c18e8Smrg		;;
8811c27c18e8Smrg	      esac
8812c27c18e8Smrg	      case " $deplibs " in
8813c27c18e8Smrg	      *" $path "*) ;;
8814c27c18e8Smrg	      *) deplibs="$path $deplibs" ;;
8815c27c18e8Smrg	      esac
8816c27c18e8Smrg	    done
8817c27c18e8Smrg	  fi # link_all_deplibs != no
8818c27c18e8Smrg	fi # linkmode = lib
8819c27c18e8Smrg      done # for deplib in $libs
882048e5ce07Smrg      if test link = "$pass"; then
882148e5ce07Smrg	if test prog = "$linkmode"; then
8822c27c18e8Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8823c27c18e8Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8824c27c18e8Smrg	else
882537eb1ca1Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8826c27c18e8Smrg	fi
8827c27c18e8Smrg      fi
882848e5ce07Smrg      dependency_libs=$newdependency_libs
882948e5ce07Smrg      if test dlpreopen = "$pass"; then
8830c27c18e8Smrg	# Link the dlpreopened libraries before other libraries
8831c27c18e8Smrg	for deplib in $save_deplibs; do
8832c27c18e8Smrg	  deplibs="$deplib $deplibs"
8833c27c18e8Smrg	done
8834c27c18e8Smrg      fi
883548e5ce07Smrg      if test dlopen != "$pass"; then
883648e5ce07Smrg	test conv = "$pass" || {
8837c27c18e8Smrg	  # Make sure lib_search_path contains only unique directories.
8838c27c18e8Smrg	  lib_search_path=
8839c27c18e8Smrg	  for dir in $newlib_search_path; do
8840c27c18e8Smrg	    case "$lib_search_path " in
8841c27c18e8Smrg	    *" $dir "*) ;;
8842b789ec8aSmrg	    *) func_append lib_search_path " $dir" ;;
8843c27c18e8Smrg	    esac
8844c27c18e8Smrg	  done
8845c27c18e8Smrg	  newlib_search_path=
884648e5ce07Smrg	}
8847c27c18e8Smrg
884848e5ce07Smrg	if test prog,link = "$linkmode,$pass"; then
88490eb1301bSmrg	  vars="compile_deplibs finalize_deplibs"
885048e5ce07Smrg	else
885148e5ce07Smrg	  vars=deplibs
8852c27c18e8Smrg	fi
8853c27c18e8Smrg	for var in $vars dependency_libs; do
8854c27c18e8Smrg	  # Add libraries to $var in reverse order
8855c27c18e8Smrg	  eval tmp_libs=\"\$$var\"
8856c27c18e8Smrg	  new_libs=
8857c27c18e8Smrg	  for deplib in $tmp_libs; do
8858c27c18e8Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8859c27c18e8Smrg	    #        that some nasty dependency loop isn't accidentally
8860c27c18e8Smrg	    #        broken:
8861c27c18e8Smrg	    #new_libs="$deplib $new_libs"
8862c27c18e8Smrg	    # Pragmatically, this seems to cause very few problems in
8863c27c18e8Smrg	    # practice:
8864c27c18e8Smrg	    case $deplib in
8865c27c18e8Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8866c27c18e8Smrg	    -R*) ;;
8867c27c18e8Smrg	    *)
8868c27c18e8Smrg	      # And here is the reason: when a library appears more
8869c27c18e8Smrg	      # than once as an explicit dependence of a library, or
8870c27c18e8Smrg	      # is implicitly linked in more than once by the
8871c27c18e8Smrg	      # compiler, it is considered special, and multiple
8872c27c18e8Smrg	      # occurrences thereof are not removed.  Compare this
8873c27c18e8Smrg	      # with having the same library being listed as a
8874c27c18e8Smrg	      # dependency of multiple other libraries: in this case,
8875c27c18e8Smrg	      # we know (pedantically, we assume) the library does not
8876c27c18e8Smrg	      # need to be listed more than once, so we keep only the
8877c27c18e8Smrg	      # last copy.  This is not always right, but it is rare
8878c27c18e8Smrg	      # enough that we require users that really mean to play
8879c27c18e8Smrg	      # such unportable linking tricks to link the library
8880c27c18e8Smrg	      # using -Wl,-lname, so that libtool does not consider it
8881c27c18e8Smrg	      # for duplicate removal.
8882c27c18e8Smrg	      case " $specialdeplibs " in
8883c27c18e8Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8884c27c18e8Smrg	      *)
8885c27c18e8Smrg		case " $new_libs " in
8886c27c18e8Smrg		*" $deplib "*) ;;
8887c27c18e8Smrg		*) new_libs="$deplib $new_libs" ;;
8888c27c18e8Smrg		esac
8889c27c18e8Smrg		;;
8890c27c18e8Smrg	      esac
8891c27c18e8Smrg	      ;;
8892c27c18e8Smrg	    esac
8893c27c18e8Smrg	  done
8894c27c18e8Smrg	  tmp_libs=
8895c27c18e8Smrg	  for deplib in $new_libs; do
8896c27c18e8Smrg	    case $deplib in
8897c27c18e8Smrg	    -L*)
8898c27c18e8Smrg	      case " $tmp_libs " in
8899c27c18e8Smrg	      *" $deplib "*) ;;
8900b789ec8aSmrg	      *) func_append tmp_libs " $deplib" ;;
8901c27c18e8Smrg	      esac
8902c27c18e8Smrg	      ;;
8903b789ec8aSmrg	    *) func_append tmp_libs " $deplib" ;;
8904c27c18e8Smrg	    esac
8905c27c18e8Smrg	  done
8906c27c18e8Smrg	  eval $var=\"$tmp_libs\"
8907c27c18e8Smrg	done # for var
8908c27c18e8Smrg      fi
890948e5ce07Smrg
891048e5ce07Smrg      # Add Sun CC postdeps if required:
891148e5ce07Smrg      test CXX = "$tagname" && {
891248e5ce07Smrg        case $host_os in
891348e5ce07Smrg        linux*)
89144e8f48c7Smrg          case `$CC -V 2>&1 | $SED 5q` in
891548e5ce07Smrg          *Sun\ C*) # Sun C++ 5.9
891648e5ce07Smrg            func_suncc_cstd_abi
891748e5ce07Smrg
891848e5ce07Smrg            if test no != "$suncc_use_cstd_abi"; then
891948e5ce07Smrg              func_append postdeps ' -library=Cstd -library=Crun'
892048e5ce07Smrg            fi
892148e5ce07Smrg            ;;
892248e5ce07Smrg          esac
892348e5ce07Smrg          ;;
892448e5ce07Smrg
892548e5ce07Smrg        solaris*)
892648e5ce07Smrg          func_cc_basename "$CC"
892748e5ce07Smrg          case $func_cc_basename_result in
892848e5ce07Smrg          CC* | sunCC*)
892948e5ce07Smrg            func_suncc_cstd_abi
893048e5ce07Smrg
893148e5ce07Smrg            if test no != "$suncc_use_cstd_abi"; then
893248e5ce07Smrg              func_append postdeps ' -library=Cstd -library=Crun'
893348e5ce07Smrg            fi
893448e5ce07Smrg            ;;
893548e5ce07Smrg          esac
893648e5ce07Smrg          ;;
893748e5ce07Smrg        esac
893848e5ce07Smrg      }
893948e5ce07Smrg
8940c27c18e8Smrg      # Last step: remove runtime libs from dependency_libs
8941c27c18e8Smrg      # (they stay in deplibs)
8942c27c18e8Smrg      tmp_libs=
894348e5ce07Smrg      for i in $dependency_libs; do
8944c27c18e8Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8945c27c18e8Smrg	*" $i "*)
894648e5ce07Smrg	  i=
8947c27c18e8Smrg	  ;;
8948c27c18e8Smrg	esac
894948e5ce07Smrg	if test -n "$i"; then
8950b789ec8aSmrg	  func_append tmp_libs " $i"
8951c27c18e8Smrg	fi
8952c27c18e8Smrg      done
8953c27c18e8Smrg      dependency_libs=$tmp_libs
8954c27c18e8Smrg    done # for pass
895548e5ce07Smrg    if test prog = "$linkmode"; then
895648e5ce07Smrg      dlfiles=$newdlfiles
8957c27c18e8Smrg    fi
895848e5ce07Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
895948e5ce07Smrg      dlprefiles=$newdlprefiles
8960c27c18e8Smrg    fi
8961c27c18e8Smrg
8962c27c18e8Smrg    case $linkmode in
8963c27c18e8Smrg    oldlib)
896448e5ce07Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
896548e5ce07Smrg	func_warning "'-dlopen' is ignored for archives"
8966c27c18e8Smrg      fi
8967c27c18e8Smrg
8968c27c18e8Smrg      case " $deplibs" in
8969c27c18e8Smrg      *\ -l* | *\ -L*)
897048e5ce07Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8971c27c18e8Smrg      esac
8972c27c18e8Smrg
8973c27c18e8Smrg      test -n "$rpath" && \
897448e5ce07Smrg	func_warning "'-rpath' is ignored for archives"
8975c27c18e8Smrg
8976c27c18e8Smrg      test -n "$xrpath" && \
897748e5ce07Smrg	func_warning "'-R' is ignored for archives"
8978c27c18e8Smrg
8979c27c18e8Smrg      test -n "$vinfo" && \
898048e5ce07Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
8981c27c18e8Smrg
8982c27c18e8Smrg      test -n "$release" && \
898348e5ce07Smrg	func_warning "'-release' is ignored for archives"
8984c27c18e8Smrg
8985c27c18e8Smrg      test -n "$export_symbols$export_symbols_regex" && \
898648e5ce07Smrg	func_warning "'-export-symbols' is ignored for archives"
8987c27c18e8Smrg
8988c27c18e8Smrg      # Now set the variables for building old libraries.
8989c27c18e8Smrg      build_libtool_libs=no
899048e5ce07Smrg      oldlibs=$output
8991b789ec8aSmrg      func_append objs "$old_deplibs"
8992c27c18e8Smrg      ;;
8993c27c18e8Smrg
8994c27c18e8Smrg    lib)
899548e5ce07Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
8996c27c18e8Smrg      case $outputname in
8997c27c18e8Smrg      lib*)
8998c27c18e8Smrg	func_stripname 'lib' '.la' "$outputname"
8999c27c18e8Smrg	name=$func_stripname_result
9000c27c18e8Smrg	eval shared_ext=\"$shrext_cmds\"
9001c27c18e8Smrg	eval libname=\"$libname_spec\"
9002c27c18e8Smrg	;;
9003c27c18e8Smrg      *)
900448e5ce07Smrg	test no = "$module" \
900548e5ce07Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9006c27c18e8Smrg
900748e5ce07Smrg	if test no != "$need_lib_prefix"; then
9008c27c18e8Smrg	  # Add the "lib" prefix for modules if required
9009c27c18e8Smrg	  func_stripname '' '.la' "$outputname"
9010c27c18e8Smrg	  name=$func_stripname_result
9011c27c18e8Smrg	  eval shared_ext=\"$shrext_cmds\"
9012c27c18e8Smrg	  eval libname=\"$libname_spec\"
9013c27c18e8Smrg	else
9014c27c18e8Smrg	  func_stripname '' '.la' "$outputname"
9015c27c18e8Smrg	  libname=$func_stripname_result
9016c27c18e8Smrg	fi
9017c27c18e8Smrg	;;
9018c27c18e8Smrg      esac
9019c27c18e8Smrg
9020c27c18e8Smrg      if test -n "$objs"; then
902148e5ce07Smrg	if test pass_all != "$deplibs_check_method"; then
902248e5ce07Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9023c27c18e8Smrg	else
902437eb1ca1Smrg	  echo
9025c27c18e8Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9026c27c18e8Smrg	  $ECHO "*** objects $objs is not portable!"
9027b789ec8aSmrg	  func_append libobjs " $objs"
9028c27c18e8Smrg	fi
9029c27c18e8Smrg      fi
9030c27c18e8Smrg
903148e5ce07Smrg      test no = "$dlself" \
903248e5ce07Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9033c27c18e8Smrg
9034c27c18e8Smrg      set dummy $rpath
9035c27c18e8Smrg      shift
903648e5ce07Smrg      test 1 -lt "$#" \
903748e5ce07Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9038c27c18e8Smrg
903948e5ce07Smrg      install_libdir=$1
9040c27c18e8Smrg
9041c27c18e8Smrg      oldlibs=
9042c27c18e8Smrg      if test -z "$rpath"; then
904348e5ce07Smrg	if test yes = "$build_libtool_libs"; then
9044c27c18e8Smrg	  # Building a libtool convenience library.
904548e5ce07Smrg	  # Some compilers have problems with a '.al' extension so
9046c27c18e8Smrg	  # convenience libraries should have the same extension an
9047c27c18e8Smrg	  # archive normally would.
9048c27c18e8Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9049c27c18e8Smrg	  build_libtool_libs=convenience
9050c27c18e8Smrg	  build_old_libs=yes
9051c27c18e8Smrg	fi
9052c27c18e8Smrg
9053c27c18e8Smrg	test -n "$vinfo" && \
905448e5ce07Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9055c27c18e8Smrg
9056c27c18e8Smrg	test -n "$release" && \
905748e5ce07Smrg	  func_warning "'-release' is ignored for convenience libraries"
9058c27c18e8Smrg      else
9059c27c18e8Smrg
9060c27c18e8Smrg	# Parse the version information argument.
906148e5ce07Smrg	save_ifs=$IFS; IFS=:
9062c27c18e8Smrg	set dummy $vinfo 0 0 0
9063c27c18e8Smrg	shift
906448e5ce07Smrg	IFS=$save_ifs
9065c27c18e8Smrg
9066c27c18e8Smrg	test -n "$7" && \
906748e5ce07Smrg	  func_fatal_help "too many parameters to '-version-info'"
9068c27c18e8Smrg
9069c27c18e8Smrg	# convert absolute version numbers to libtool ages
9070c27c18e8Smrg	# this retains compatibility with .la files and attempts
9071c27c18e8Smrg	# to make the code below a bit more comprehensible
9072c27c18e8Smrg
9073c27c18e8Smrg	case $vinfo_number in
9074c27c18e8Smrg	yes)
907548e5ce07Smrg	  number_major=$1
907648e5ce07Smrg	  number_minor=$2
907748e5ce07Smrg	  number_revision=$3
9078c27c18e8Smrg	  #
9079c27c18e8Smrg	  # There are really only two kinds -- those that
9080c27c18e8Smrg	  # use the current revision as the major version
9081c27c18e8Smrg	  # and those that subtract age and use age as
9082c27c18e8Smrg	  # a minor version.  But, then there is irix
908348e5ce07Smrg	  # that has an extra 1 added just for fun
9084c27c18e8Smrg	  #
9085c27c18e8Smrg	  case $version_type in
9086f1ee322dSmrg	  # correct linux to gnu/linux during the next big refactor
90874e8f48c7Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9088c27c18e8Smrg	    func_arith $number_major + $number_minor
9089c27c18e8Smrg	    current=$func_arith_result
909048e5ce07Smrg	    age=$number_minor
909148e5ce07Smrg	    revision=$number_revision
9092c27c18e8Smrg	    ;;
909348e5ce07Smrg	  freebsd-aout|qnx|sunos)
909448e5ce07Smrg	    current=$number_major
909548e5ce07Smrg	    revision=$number_minor
909648e5ce07Smrg	    age=0
9097c27c18e8Smrg	    ;;
9098c27c18e8Smrg	  irix|nonstopux)
9099c27c18e8Smrg	    func_arith $number_major + $number_minor
9100c27c18e8Smrg	    current=$func_arith_result
910148e5ce07Smrg	    age=$number_minor
910248e5ce07Smrg	    revision=$number_minor
9103c27c18e8Smrg	    lt_irix_increment=no
9104c27c18e8Smrg	    ;;
9105c27c18e8Smrg	  esac
9106c27c18e8Smrg	  ;;
9107c27c18e8Smrg	no)
910848e5ce07Smrg	  current=$1
910948e5ce07Smrg	  revision=$2
911048e5ce07Smrg	  age=$3
9111c27c18e8Smrg	  ;;
9112c27c18e8Smrg	esac
9113c27c18e8Smrg
9114c27c18e8Smrg	# Check that each of the things are valid numbers.
9115c27c18e8Smrg	case $current in
9116c27c18e8Smrg	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]) ;;
9117c27c18e8Smrg	*)
911848e5ce07Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
911948e5ce07Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9120c27c18e8Smrg	  ;;
9121c27c18e8Smrg	esac
9122c27c18e8Smrg
9123c27c18e8Smrg	case $revision in
9124c27c18e8Smrg	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]) ;;
9125c27c18e8Smrg	*)
912648e5ce07Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
912748e5ce07Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9128c27c18e8Smrg	  ;;
9129c27c18e8Smrg	esac
9130c27c18e8Smrg
9131c27c18e8Smrg	case $age in
9132c27c18e8Smrg	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]) ;;
9133c27c18e8Smrg	*)
913448e5ce07Smrg	  func_error "AGE '$age' must be a nonnegative integer"
913548e5ce07Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9136c27c18e8Smrg	  ;;
9137c27c18e8Smrg	esac
9138c27c18e8Smrg
9139c27c18e8Smrg	if test "$age" -gt "$current"; then
914048e5ce07Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
914148e5ce07Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9142c27c18e8Smrg	fi
9143c27c18e8Smrg
9144c27c18e8Smrg	# Calculate the version variables.
9145c27c18e8Smrg	major=
9146c27c18e8Smrg	versuffix=
9147c27c18e8Smrg	verstring=
9148c27c18e8Smrg	case $version_type in
9149c27c18e8Smrg	none) ;;
9150c27c18e8Smrg
9151c27c18e8Smrg	darwin)
9152c27c18e8Smrg	  # Like Linux, but with the current version available in
9153c27c18e8Smrg	  # verstring for coding it into the library header
9154c27c18e8Smrg	  func_arith $current - $age
9155c27c18e8Smrg	  major=.$func_arith_result
915648e5ce07Smrg	  versuffix=$major.$age.$revision
9157c27c18e8Smrg	  # Darwin ld doesn't like 0 for these options...
9158c27c18e8Smrg	  func_arith $current + 1
9159c27c18e8Smrg	  minor_current=$func_arith_result
916048e5ce07Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9161c27c18e8Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
916248e5ce07Smrg          # On Darwin other compilers
916348e5ce07Smrg          case $CC in
916448e5ce07Smrg              nagfor*)
916548e5ce07Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
916648e5ce07Smrg                  ;;
916748e5ce07Smrg              *)
916848e5ce07Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
916948e5ce07Smrg                  ;;
917048e5ce07Smrg          esac
9171c27c18e8Smrg	  ;;
9172c27c18e8Smrg
9173c27c18e8Smrg	freebsd-aout)
917448e5ce07Smrg	  major=.$current
917548e5ce07Smrg	  versuffix=.$current.$revision
9176c27c18e8Smrg	  ;;
9177c27c18e8Smrg
91784e8f48c7Smrg	freebsd-elf | midnightbsd-elf)
917948e5ce07Smrg	  func_arith $current - $age
918048e5ce07Smrg	  major=.$func_arith_result
918148e5ce07Smrg	  versuffix=$major.$age.$revision
9182c27c18e8Smrg	  ;;
9183c27c18e8Smrg
9184c27c18e8Smrg	irix | nonstopux)
918548e5ce07Smrg	  if test no = "$lt_irix_increment"; then
9186c27c18e8Smrg	    func_arith $current - $age
9187c27c18e8Smrg	  else
9188c27c18e8Smrg	    func_arith $current - $age + 1
9189c27c18e8Smrg	  fi
9190c27c18e8Smrg	  major=$func_arith_result
9191c27c18e8Smrg
9192c27c18e8Smrg	  case $version_type in
9193c27c18e8Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9194c27c18e8Smrg	    *)         verstring_prefix=sgi ;;
9195c27c18e8Smrg	  esac
919648e5ce07Smrg	  verstring=$verstring_prefix$major.$revision
9197c27c18e8Smrg
9198c27c18e8Smrg	  # Add in all the interfaces that we are compatible with.
9199c27c18e8Smrg	  loop=$revision
920048e5ce07Smrg	  while test 0 -ne "$loop"; do
9201c27c18e8Smrg	    func_arith $revision - $loop
9202c27c18e8Smrg	    iface=$func_arith_result
9203c27c18e8Smrg	    func_arith $loop - 1
9204c27c18e8Smrg	    loop=$func_arith_result
920548e5ce07Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
9206c27c18e8Smrg	  done
9207c27c18e8Smrg
920848e5ce07Smrg	  # Before this point, $major must not contain '.'.
9209c27c18e8Smrg	  major=.$major
921048e5ce07Smrg	  versuffix=$major.$revision
9211c27c18e8Smrg	  ;;
9212c27c18e8Smrg
9213f1ee322dSmrg	linux) # correct to gnu/linux during the next big refactor
9214c27c18e8Smrg	  func_arith $current - $age
9215c27c18e8Smrg	  major=.$func_arith_result
921648e5ce07Smrg	  versuffix=$major.$age.$revision
9217c27c18e8Smrg	  ;;
9218c27c18e8Smrg
9219c27c18e8Smrg	osf)
9220c27c18e8Smrg	  func_arith $current - $age
9221c27c18e8Smrg	  major=.$func_arith_result
922248e5ce07Smrg	  versuffix=.$current.$age.$revision
922348e5ce07Smrg	  verstring=$current.$age.$revision
9224c27c18e8Smrg
9225c27c18e8Smrg	  # Add in all the interfaces that we are compatible with.
9226c27c18e8Smrg	  loop=$age
922748e5ce07Smrg	  while test 0 -ne "$loop"; do
9228c27c18e8Smrg	    func_arith $current - $loop
9229c27c18e8Smrg	    iface=$func_arith_result
9230c27c18e8Smrg	    func_arith $loop - 1
9231c27c18e8Smrg	    loop=$func_arith_result
923248e5ce07Smrg	    verstring=$verstring:$iface.0
9233c27c18e8Smrg	  done
9234c27c18e8Smrg
9235c27c18e8Smrg	  # Make executables depend on our current version.
923648e5ce07Smrg	  func_append verstring ":$current.0"
9237c27c18e8Smrg	  ;;
9238c27c18e8Smrg
9239c27c18e8Smrg	qnx)
924048e5ce07Smrg	  major=.$current
924148e5ce07Smrg	  versuffix=.$current
924248e5ce07Smrg	  ;;
924348e5ce07Smrg
924448e5ce07Smrg	sco)
924548e5ce07Smrg	  major=.$current
924648e5ce07Smrg	  versuffix=.$current
9247c27c18e8Smrg	  ;;
9248c27c18e8Smrg
9249c27c18e8Smrg	sunos)
925048e5ce07Smrg	  major=.$current
925148e5ce07Smrg	  versuffix=.$current.$revision
9252c27c18e8Smrg	  ;;
9253c27c18e8Smrg
9254c27c18e8Smrg	windows)
9255c27c18e8Smrg	  # Use '-' rather than '.', since we only want one
925648e5ce07Smrg	  # extension on DOS 8.3 file systems.
9257c27c18e8Smrg	  func_arith $current - $age
9258c27c18e8Smrg	  major=$func_arith_result
925948e5ce07Smrg	  versuffix=-$major
9260c27c18e8Smrg	  ;;
9261c27c18e8Smrg
9262c27c18e8Smrg	*)
926348e5ce07Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
9264c27c18e8Smrg	  ;;
9265c27c18e8Smrg	esac
9266c27c18e8Smrg
9267c27c18e8Smrg	# Clear the version info if we defaulted, and they specified a release.
9268c27c18e8Smrg	if test -z "$vinfo" && test -n "$release"; then
9269c27c18e8Smrg	  major=
9270c27c18e8Smrg	  case $version_type in
9271c27c18e8Smrg	  darwin)
9272c27c18e8Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9273c27c18e8Smrg	    # problems, so we reset it completely
9274c27c18e8Smrg	    verstring=
9275c27c18e8Smrg	    ;;
9276c27c18e8Smrg	  *)
927748e5ce07Smrg	    verstring=0.0
9278c27c18e8Smrg	    ;;
9279c27c18e8Smrg	  esac
928048e5ce07Smrg	  if test no = "$need_version"; then
9281c27c18e8Smrg	    versuffix=
9282c27c18e8Smrg	  else
928348e5ce07Smrg	    versuffix=.0.0
9284c27c18e8Smrg	  fi
9285c27c18e8Smrg	fi
9286c27c18e8Smrg
9287c27c18e8Smrg	# Remove version info from name if versioning should be avoided
928848e5ce07Smrg	if test yes,no = "$avoid_version,$need_version"; then
9289c27c18e8Smrg	  major=
9290c27c18e8Smrg	  versuffix=
929148e5ce07Smrg	  verstring=
9292c27c18e8Smrg	fi
9293c27c18e8Smrg
9294c27c18e8Smrg	# Check to see if the archive will have undefined symbols.
929548e5ce07Smrg	if test yes = "$allow_undefined"; then
929648e5ce07Smrg	  if test unsupported = "$allow_undefined_flag"; then
929748e5ce07Smrg	    if test yes = "$build_old_libs"; then
929848e5ce07Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
929948e5ce07Smrg	      build_libtool_libs=no
930048e5ce07Smrg	    else
930148e5ce07Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
930248e5ce07Smrg	    fi
9303c27c18e8Smrg	  fi
9304c27c18e8Smrg	else
9305c27c18e8Smrg	  # Don't allow undefined symbols.
930648e5ce07Smrg	  allow_undefined_flag=$no_undefined_flag
9307c27c18e8Smrg	fi
9308c27c18e8Smrg
9309c27c18e8Smrg      fi
9310c27c18e8Smrg
931148e5ce07Smrg      func_generate_dlsyms "$libname" "$libname" :
9312b789ec8aSmrg      func_append libobjs " $symfileobj"
931348e5ce07Smrg      test " " = "$libobjs" && libobjs=
9314c27c18e8Smrg
931548e5ce07Smrg      if test relink != "$opt_mode"; then
9316c27c18e8Smrg	# Remove our outputs, but don't remove object files since they
9317c27c18e8Smrg	# may have been created when compiling PIC objects.
9318c27c18e8Smrg	removelist=
9319c27c18e8Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9320c27c18e8Smrg	for p in $tempremovelist; do
9321c27c18e8Smrg	  case $p in
9322c27c18e8Smrg	    *.$objext | *.gcno)
9323c27c18e8Smrg	       ;;
932448e5ce07Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
932548e5ce07Smrg	       if test -n "$precious_files_regex"; then
9326c27c18e8Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9327c27c18e8Smrg		 then
9328c27c18e8Smrg		   continue
9329c27c18e8Smrg		 fi
9330c27c18e8Smrg	       fi
9331b789ec8aSmrg	       func_append removelist " $p"
9332c27c18e8Smrg	       ;;
9333c27c18e8Smrg	    *) ;;
9334c27c18e8Smrg	  esac
9335c27c18e8Smrg	done
9336c27c18e8Smrg	test -n "$removelist" && \
9337c27c18e8Smrg	  func_show_eval "${RM}r \$removelist"
9338c27c18e8Smrg      fi
9339c27c18e8Smrg
9340c27c18e8Smrg      # Now set the variables for building old libraries.
934148e5ce07Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9342b789ec8aSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9343c27c18e8Smrg
9344c27c18e8Smrg	# Transform .lo files to .o files.
934548e5ce07Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9346c27c18e8Smrg      fi
9347c27c18e8Smrg
9348c27c18e8Smrg      # Eliminate all temporary directories.
9349c27c18e8Smrg      #for path in $notinst_path; do
935037eb1ca1Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935137eb1ca1Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935237eb1ca1Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9353c27c18e8Smrg      #done
9354c27c18e8Smrg
9355c27c18e8Smrg      if test -n "$xrpath"; then
9356c27c18e8Smrg	# If the user specified any rpath flags, then add them.
9357c27c18e8Smrg	temp_xrpath=
9358c27c18e8Smrg	for libdir in $xrpath; do
9359b789ec8aSmrg	  func_replace_sysroot "$libdir"
9360b789ec8aSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9361c27c18e8Smrg	  case "$finalize_rpath " in
9362c27c18e8Smrg	  *" $libdir "*) ;;
9363b789ec8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
9364c27c18e8Smrg	  esac
9365c27c18e8Smrg	done
936648e5ce07Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9367c27c18e8Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9368c27c18e8Smrg	fi
9369c27c18e8Smrg      fi
9370c27c18e8Smrg
9371c27c18e8Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
937248e5ce07Smrg      old_dlfiles=$dlfiles
9373c27c18e8Smrg      dlfiles=
9374c27c18e8Smrg      for lib in $old_dlfiles; do
9375c27c18e8Smrg	case " $dlprefiles $dlfiles " in
9376c27c18e8Smrg	*" $lib "*) ;;
9377b789ec8aSmrg	*) func_append dlfiles " $lib" ;;
9378c27c18e8Smrg	esac
9379c27c18e8Smrg      done
9380c27c18e8Smrg
9381c27c18e8Smrg      # Make sure dlprefiles contains only unique files
938248e5ce07Smrg      old_dlprefiles=$dlprefiles
9383c27c18e8Smrg      dlprefiles=
9384c27c18e8Smrg      for lib in $old_dlprefiles; do
9385c27c18e8Smrg	case "$dlprefiles " in
9386c27c18e8Smrg	*" $lib "*) ;;
9387b789ec8aSmrg	*) func_append dlprefiles " $lib" ;;
9388c27c18e8Smrg	esac
9389c27c18e8Smrg      done
9390c27c18e8Smrg
939148e5ce07Smrg      if test yes = "$build_libtool_libs"; then
9392c27c18e8Smrg	if test -n "$rpath"; then
9393c27c18e8Smrg	  case $host in
939437eb1ca1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9395c27c18e8Smrg	    # these systems don't actually have a c library (as such)!
9396c27c18e8Smrg	    ;;
9397c27c18e8Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9398c27c18e8Smrg	    # Rhapsody C library is in the System framework
9399b789ec8aSmrg	    func_append deplibs " System.ltframework"
9400c27c18e8Smrg	    ;;
9401c27c18e8Smrg	  *-*-netbsd*)
9402c27c18e8Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9403c27c18e8Smrg	    ;;
94044e8f48c7Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9405c27c18e8Smrg	    # Do not include libc due to us having libc/libc_r.
9406c27c18e8Smrg	    ;;
9407c27c18e8Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9408c27c18e8Smrg	    # Causes problems with __ctype
9409c27c18e8Smrg	    ;;
9410c27c18e8Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9411c27c18e8Smrg	    # Compiler inserts libc in the correct place for threads to work
9412c27c18e8Smrg	    ;;
9413c27c18e8Smrg	  *)
9414c27c18e8Smrg	    # Add libc to deplibs on all other systems if necessary.
941548e5ce07Smrg	    if test yes = "$build_libtool_need_lc"; then
9416b789ec8aSmrg	      func_append deplibs " -lc"
9417c27c18e8Smrg	    fi
9418c27c18e8Smrg	    ;;
9419c27c18e8Smrg	  esac
9420c27c18e8Smrg	fi
9421c27c18e8Smrg
9422c27c18e8Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9423c27c18e8Smrg	name_save=$name
9424c27c18e8Smrg	libname_save=$libname
9425c27c18e8Smrg	release_save=$release
9426c27c18e8Smrg	versuffix_save=$versuffix
9427c27c18e8Smrg	major_save=$major
9428c27c18e8Smrg	# I'm not sure if I'm treating the release correctly.  I think
9429c27c18e8Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9430c27c18e8Smrg	# add it in twice.  Is that correct?
943148e5ce07Smrg	release=
943248e5ce07Smrg	versuffix=
943348e5ce07Smrg	major=
9434c27c18e8Smrg	newdeplibs=
9435c27c18e8Smrg	droppeddeps=no
9436c27c18e8Smrg	case $deplibs_check_method in
9437c27c18e8Smrg	pass_all)
9438c27c18e8Smrg	  # Don't check for shared/static.  Everything works.
9439c27c18e8Smrg	  # This might be a little naive.  We might want to check
9440c27c18e8Smrg	  # whether the library exists or not.  But this is on
9441c27c18e8Smrg	  # osf3 & osf4 and I'm not really sure... Just
9442c27c18e8Smrg	  # implementing what was already the behavior.
9443c27c18e8Smrg	  newdeplibs=$deplibs
9444c27c18e8Smrg	  ;;
9445c27c18e8Smrg	test_compile)
9446c27c18e8Smrg	  # This code stresses the "libraries are programs" paradigm to its
9447c27c18e8Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9448c27c18e8Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9449c27c18e8Smrg	  # whether they linked in statically or dynamically with ldd.
9450c27c18e8Smrg	  $opt_dry_run || $RM conftest.c
9451c27c18e8Smrg	  cat > conftest.c <<EOF
9452c27c18e8Smrg	  int main() { return 0; }
9453c27c18e8SmrgEOF
9454c27c18e8Smrg	  $opt_dry_run || $RM conftest
9455c27c18e8Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9456c27c18e8Smrg	    ldd_output=`ldd conftest`
9457c27c18e8Smrg	    for i in $deplibs; do
9458c27c18e8Smrg	      case $i in
9459c27c18e8Smrg	      -l*)
9460c27c18e8Smrg		func_stripname -l '' "$i"
9461c27c18e8Smrg		name=$func_stripname_result
946248e5ce07Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9463c27c18e8Smrg		  case " $predeps $postdeps " in
9464c27c18e8Smrg		  *" $i "*)
9465b789ec8aSmrg		    func_append newdeplibs " $i"
946648e5ce07Smrg		    i=
9467c27c18e8Smrg		    ;;
9468c27c18e8Smrg		  esac
9469c27c18e8Smrg		fi
947048e5ce07Smrg		if test -n "$i"; then
9471c27c18e8Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9472c27c18e8Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9473c27c18e8Smrg		  set dummy $deplib_matches; shift
9474c27c18e8Smrg		  deplib_match=$1
947548e5ce07Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9476b789ec8aSmrg		    func_append newdeplibs " $i"
9477c27c18e8Smrg		  else
9478c27c18e8Smrg		    droppeddeps=yes
947937eb1ca1Smrg		    echo
9480c27c18e8Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948137eb1ca1Smrg		    echo "*** I have the capability to make that library automatically link in when"
948237eb1ca1Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
948337eb1ca1Smrg		    echo "*** shared version of the library, which I believe you do not have"
948437eb1ca1Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
948537eb1ca1Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9486c27c18e8Smrg		  fi
9487c27c18e8Smrg		fi
9488c27c18e8Smrg		;;
9489c27c18e8Smrg	      *)
9490b789ec8aSmrg		func_append newdeplibs " $i"
9491c27c18e8Smrg		;;
9492c27c18e8Smrg	      esac
9493c27c18e8Smrg	    done
9494c27c18e8Smrg	  else
9495c27c18e8Smrg	    # Error occurred in the first compile.  Let's try to salvage
9496c27c18e8Smrg	    # the situation: Compile a separate program for each library.
9497c27c18e8Smrg	    for i in $deplibs; do
9498c27c18e8Smrg	      case $i in
9499c27c18e8Smrg	      -l*)
9500c27c18e8Smrg		func_stripname -l '' "$i"
9501c27c18e8Smrg		name=$func_stripname_result
9502c27c18e8Smrg		$opt_dry_run || $RM conftest
9503c27c18e8Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9504c27c18e8Smrg		  ldd_output=`ldd conftest`
950548e5ce07Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9506c27c18e8Smrg		    case " $predeps $postdeps " in
9507c27c18e8Smrg		    *" $i "*)
9508b789ec8aSmrg		      func_append newdeplibs " $i"
950948e5ce07Smrg		      i=
9510c27c18e8Smrg		      ;;
9511c27c18e8Smrg		    esac
9512c27c18e8Smrg		  fi
951348e5ce07Smrg		  if test -n "$i"; then
9514c27c18e8Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9515c27c18e8Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9516c27c18e8Smrg		    set dummy $deplib_matches; shift
9517c27c18e8Smrg		    deplib_match=$1
951848e5ce07Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9519b789ec8aSmrg		      func_append newdeplibs " $i"
9520c27c18e8Smrg		    else
9521c27c18e8Smrg		      droppeddeps=yes
952237eb1ca1Smrg		      echo
9523c27c18e8Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
952437eb1ca1Smrg		      echo "*** I have the capability to make that library automatically link in when"
952537eb1ca1Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
952637eb1ca1Smrg		      echo "*** shared version of the library, which you do not appear to have"
952737eb1ca1Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
952837eb1ca1Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9529c27c18e8Smrg		    fi
9530c27c18e8Smrg		  fi
9531c27c18e8Smrg		else
9532c27c18e8Smrg		  droppeddeps=yes
953337eb1ca1Smrg		  echo
9534c27c18e8Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
953537eb1ca1Smrg		  echo "*** make it link in!  You will probably need to install it or some"
953637eb1ca1Smrg		  echo "*** library that it depends on before this library will be fully"
953737eb1ca1Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9538c27c18e8Smrg		fi
9539c27c18e8Smrg		;;
9540c27c18e8Smrg	      *)
9541b789ec8aSmrg		func_append newdeplibs " $i"
9542c27c18e8Smrg		;;
9543c27c18e8Smrg	      esac
9544c27c18e8Smrg	    done
9545c27c18e8Smrg	  fi
9546c27c18e8Smrg	  ;;
9547c27c18e8Smrg	file_magic*)
9548c27c18e8Smrg	  set dummy $deplibs_check_method; shift
9549c27c18e8Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9550c27c18e8Smrg	  for a_deplib in $deplibs; do
9551c27c18e8Smrg	    case $a_deplib in
9552c27c18e8Smrg	    -l*)
9553c27c18e8Smrg	      func_stripname -l '' "$a_deplib"
9554c27c18e8Smrg	      name=$func_stripname_result
955548e5ce07Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9556c27c18e8Smrg		case " $predeps $postdeps " in
9557c27c18e8Smrg		*" $a_deplib "*)
9558b789ec8aSmrg		  func_append newdeplibs " $a_deplib"
955948e5ce07Smrg		  a_deplib=
9560c27c18e8Smrg		  ;;
9561c27c18e8Smrg		esac
9562c27c18e8Smrg	      fi
956348e5ce07Smrg	      if test -n "$a_deplib"; then
9564c27c18e8Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9565b789ec8aSmrg		if test -n "$file_magic_glob"; then
9566b789ec8aSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9567b789ec8aSmrg		else
9568b789ec8aSmrg		  libnameglob=$libname
9569b789ec8aSmrg		fi
957048e5ce07Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9571c27c18e8Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
957248e5ce07Smrg		  if test yes = "$want_nocaseglob"; then
9573b789ec8aSmrg		    shopt -s nocaseglob
9574b789ec8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9575b789ec8aSmrg		    $nocaseglob
9576b789ec8aSmrg		  else
9577b789ec8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9578b789ec8aSmrg		  fi
9579c27c18e8Smrg		  for potent_lib in $potential_libs; do
9580c27c18e8Smrg		      # Follow soft links.
9581c27c18e8Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9582c27c18e8Smrg			 $GREP " -> " >/dev/null; then
9583c27c18e8Smrg			continue
9584c27c18e8Smrg		      fi
9585c27c18e8Smrg		      # The statement above tries to avoid entering an
9586c27c18e8Smrg		      # endless loop below, in case of cyclic links.
9587c27c18e8Smrg		      # We might still enter an endless loop, since a link
9588c27c18e8Smrg		      # loop can be closed while we follow links,
9589c27c18e8Smrg		      # but so what?
959048e5ce07Smrg		      potlib=$potent_lib
9591c27c18e8Smrg		      while test -h "$potlib" 2>/dev/null; do
959248e5ce07Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9593c27c18e8Smrg			case $potliblink in
959448e5ce07Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
959548e5ce07Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9596c27c18e8Smrg			esac
9597c27c18e8Smrg		      done
9598c27c18e8Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9599c27c18e8Smrg			 $SED -e 10q |
9600c27c18e8Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9601b789ec8aSmrg			func_append newdeplibs " $a_deplib"
960248e5ce07Smrg			a_deplib=
9603c27c18e8Smrg			break 2
9604c27c18e8Smrg		      fi
9605c27c18e8Smrg		  done
9606c27c18e8Smrg		done
9607c27c18e8Smrg	      fi
960848e5ce07Smrg	      if test -n "$a_deplib"; then
9609c27c18e8Smrg		droppeddeps=yes
961037eb1ca1Smrg		echo
9611c27c18e8Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961237eb1ca1Smrg		echo "*** I have the capability to make that library automatically link in when"
961337eb1ca1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
961437eb1ca1Smrg		echo "*** shared version of the library, which you do not appear to have"
961537eb1ca1Smrg		echo "*** because I did check the linker path looking for a file starting"
961648e5ce07Smrg		if test -z "$potlib"; then
9617c27c18e8Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9618c27c18e8Smrg		else
9619c27c18e8Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9620c27c18e8Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9621c27c18e8Smrg		fi
9622c27c18e8Smrg	      fi
9623c27c18e8Smrg	      ;;
9624c27c18e8Smrg	    *)
9625c27c18e8Smrg	      # Add a -L argument.
9626b789ec8aSmrg	      func_append newdeplibs " $a_deplib"
9627c27c18e8Smrg	      ;;
9628c27c18e8Smrg	    esac
9629c27c18e8Smrg	  done # Gone through all deplibs.
9630c27c18e8Smrg	  ;;
9631c27c18e8Smrg	match_pattern*)
9632c27c18e8Smrg	  set dummy $deplibs_check_method; shift
9633c27c18e8Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9634c27c18e8Smrg	  for a_deplib in $deplibs; do
9635c27c18e8Smrg	    case $a_deplib in
9636c27c18e8Smrg	    -l*)
9637c27c18e8Smrg	      func_stripname -l '' "$a_deplib"
9638c27c18e8Smrg	      name=$func_stripname_result
963948e5ce07Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9640c27c18e8Smrg		case " $predeps $postdeps " in
9641c27c18e8Smrg		*" $a_deplib "*)
9642b789ec8aSmrg		  func_append newdeplibs " $a_deplib"
964348e5ce07Smrg		  a_deplib=
9644c27c18e8Smrg		  ;;
9645c27c18e8Smrg		esac
9646c27c18e8Smrg	      fi
964748e5ce07Smrg	      if test -n "$a_deplib"; then
9648c27c18e8Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9649c27c18e8Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9650c27c18e8Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9651c27c18e8Smrg		  for potent_lib in $potential_libs; do
965248e5ce07Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
965337eb1ca1Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9654c27c18e8Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9655b789ec8aSmrg		      func_append newdeplibs " $a_deplib"
965648e5ce07Smrg		      a_deplib=
9657c27c18e8Smrg		      break 2
9658c27c18e8Smrg		    fi
9659c27c18e8Smrg		  done
9660c27c18e8Smrg		done
9661c27c18e8Smrg	      fi
966248e5ce07Smrg	      if test -n "$a_deplib"; then
9663c27c18e8Smrg		droppeddeps=yes
966437eb1ca1Smrg		echo
9665c27c18e8Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
966637eb1ca1Smrg		echo "*** I have the capability to make that library automatically link in when"
966737eb1ca1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
966837eb1ca1Smrg		echo "*** shared version of the library, which you do not appear to have"
966937eb1ca1Smrg		echo "*** because I did check the linker path looking for a file starting"
967048e5ce07Smrg		if test -z "$potlib"; then
9671c27c18e8Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9672c27c18e8Smrg		else
9673c27c18e8Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9674c27c18e8Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9675c27c18e8Smrg		fi
9676c27c18e8Smrg	      fi
9677c27c18e8Smrg	      ;;
9678c27c18e8Smrg	    *)
9679c27c18e8Smrg	      # Add a -L argument.
9680b789ec8aSmrg	      func_append newdeplibs " $a_deplib"
9681c27c18e8Smrg	      ;;
9682c27c18e8Smrg	    esac
9683c27c18e8Smrg	  done # Gone through all deplibs.
9684c27c18e8Smrg	  ;;
9685c27c18e8Smrg	none | unknown | *)
968648e5ce07Smrg	  newdeplibs=
968737eb1ca1Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
968848e5ce07Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
968948e5ce07Smrg	    for i in $predeps $postdeps; do
9690c27c18e8Smrg	      # can't use Xsed below, because $i might contain '/'
969148e5ce07Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9692c27c18e8Smrg	    done
9693c27c18e8Smrg	  fi
969437eb1ca1Smrg	  case $tmp_deplibs in
969537eb1ca1Smrg	  *[!\	\ ]*)
969637eb1ca1Smrg	    echo
969748e5ce07Smrg	    if test none = "$deplibs_check_method"; then
969837eb1ca1Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9699c27c18e8Smrg	    else
970037eb1ca1Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9701c27c18e8Smrg	    fi
970237eb1ca1Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9703c27c18e8Smrg	    droppeddeps=yes
970437eb1ca1Smrg	    ;;
970537eb1ca1Smrg	  esac
9706c27c18e8Smrg	  ;;
9707c27c18e8Smrg	esac
9708c27c18e8Smrg	versuffix=$versuffix_save
9709c27c18e8Smrg	major=$major_save
9710c27c18e8Smrg	release=$release_save
9711c27c18e8Smrg	libname=$libname_save
9712c27c18e8Smrg	name=$name_save
9713c27c18e8Smrg
9714c27c18e8Smrg	case $host in
9715c27c18e8Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9716c27c18e8Smrg	  # On Rhapsody replace the C library with the System framework
971737eb1ca1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9718c27c18e8Smrg	  ;;
9719c27c18e8Smrg	esac
9720c27c18e8Smrg
972148e5ce07Smrg	if test yes = "$droppeddeps"; then
972248e5ce07Smrg	  if test yes = "$module"; then
972337eb1ca1Smrg	    echo
972437eb1ca1Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9725c27c18e8Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
972637eb1ca1Smrg	    echo "*** a static module, that should work as long as the dlopening"
972737eb1ca1Smrg	    echo "*** application is linked with the -dlopen flag."
9728c27c18e8Smrg	    if test -z "$global_symbol_pipe"; then
972937eb1ca1Smrg	      echo
973037eb1ca1Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
973148e5ce07Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973237eb1ca1Smrg	      echo "*** not find such a program.  So, this module is probably useless."
973348e5ce07Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9734c27c18e8Smrg	    fi
973548e5ce07Smrg	    if test no = "$build_old_libs"; then
973648e5ce07Smrg	      oldlibs=$output_objdir/$libname.$libext
9737c27c18e8Smrg	      build_libtool_libs=module
9738c27c18e8Smrg	      build_old_libs=yes
9739c27c18e8Smrg	    else
9740c27c18e8Smrg	      build_libtool_libs=no
9741c27c18e8Smrg	    fi
9742c27c18e8Smrg	  else
974337eb1ca1Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
974437eb1ca1Smrg	    echo "*** automatically added whenever a program is linked with this library"
974537eb1ca1Smrg	    echo "*** or is declared to -dlopen it."
9746c27c18e8Smrg
974748e5ce07Smrg	    if test no = "$allow_undefined"; then
974837eb1ca1Smrg	      echo
974937eb1ca1Smrg	      echo "*** Since this library must not contain undefined symbols,"
975037eb1ca1Smrg	      echo "*** because either the platform does not support them or"
975137eb1ca1Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975237eb1ca1Smrg	      echo "*** libtool will only create a static version of it."
975348e5ce07Smrg	      if test no = "$build_old_libs"; then
975448e5ce07Smrg		oldlibs=$output_objdir/$libname.$libext
9755c27c18e8Smrg		build_libtool_libs=module
9756c27c18e8Smrg		build_old_libs=yes
9757c27c18e8Smrg	      else
9758c27c18e8Smrg		build_libtool_libs=no
9759c27c18e8Smrg	      fi
9760c27c18e8Smrg	    fi
9761c27c18e8Smrg	  fi
9762c27c18e8Smrg	fi
9763c27c18e8Smrg	# Done checking deplibs!
9764c27c18e8Smrg	deplibs=$newdeplibs
9765c27c18e8Smrg      fi
9766c27c18e8Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9767c27c18e8Smrg      case $host in
9768c27c18e8Smrg	*-*-darwin*)
976937eb1ca1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977037eb1ca1Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977137eb1ca1Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9772c27c18e8Smrg	  ;;
9773c27c18e8Smrg      esac
9774c27c18e8Smrg
9775c27c18e8Smrg      # move library search paths that coincide with paths to not yet
9776c27c18e8Smrg      # installed libraries to the beginning of the library search list
9777c27c18e8Smrg      new_libs=
9778c27c18e8Smrg      for path in $notinst_path; do
9779c27c18e8Smrg	case " $new_libs " in
9780c27c18e8Smrg	*" -L$path/$objdir "*) ;;
9781c27c18e8Smrg	*)
9782c27c18e8Smrg	  case " $deplibs " in
9783c27c18e8Smrg	  *" -L$path/$objdir "*)
9784b789ec8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
9785c27c18e8Smrg	  esac
9786c27c18e8Smrg	  ;;
9787c27c18e8Smrg	esac
9788c27c18e8Smrg      done
9789c27c18e8Smrg      for deplib in $deplibs; do
9790c27c18e8Smrg	case $deplib in
9791c27c18e8Smrg	-L*)
9792c27c18e8Smrg	  case " $new_libs " in
9793c27c18e8Smrg	  *" $deplib "*) ;;
9794b789ec8aSmrg	  *) func_append new_libs " $deplib" ;;
9795c27c18e8Smrg	  esac
9796c27c18e8Smrg	  ;;
9797b789ec8aSmrg	*) func_append new_libs " $deplib" ;;
9798c27c18e8Smrg	esac
9799c27c18e8Smrg      done
980048e5ce07Smrg      deplibs=$new_libs
9801c27c18e8Smrg
9802c27c18e8Smrg      # All the library-specific variables (install_libdir is set above).
9803c27c18e8Smrg      library_names=
9804c27c18e8Smrg      old_library=
9805c27c18e8Smrg      dlname=
9806c27c18e8Smrg
9807c27c18e8Smrg      # Test again, we may have decided not to build it any more
980848e5ce07Smrg      if test yes = "$build_libtool_libs"; then
980948e5ce07Smrg	# Remove $wl instances when linking with ld.
9810f1ee322dSmrg	# FIXME: should test the right _cmds variable.
9811f1ee322dSmrg	case $archive_cmds in
9812f1ee322dSmrg	  *\$LD\ *) wl= ;;
9813f1ee322dSmrg        esac
981448e5ce07Smrg	if test yes = "$hardcode_into_libs"; then
9815c27c18e8Smrg	  # Hardcode the library paths
9816c27c18e8Smrg	  hardcode_libdirs=
9817c27c18e8Smrg	  dep_rpath=
981848e5ce07Smrg	  rpath=$finalize_rpath
981948e5ce07Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9820c27c18e8Smrg	  for libdir in $rpath; do
9821c27c18e8Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9822c27c18e8Smrg	      if test -n "$hardcode_libdir_separator"; then
9823b789ec8aSmrg		func_replace_sysroot "$libdir"
9824b789ec8aSmrg		libdir=$func_replace_sysroot_result
9825c27c18e8Smrg		if test -z "$hardcode_libdirs"; then
982648e5ce07Smrg		  hardcode_libdirs=$libdir
9827c27c18e8Smrg		else
9828c27c18e8Smrg		  # Just accumulate the unique libdirs.
9829c27c18e8Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9830c27c18e8Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9831c27c18e8Smrg		    ;;
9832c27c18e8Smrg		  *)
9833b789ec8aSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9834c27c18e8Smrg		    ;;
9835c27c18e8Smrg		  esac
9836c27c18e8Smrg		fi
9837c27c18e8Smrg	      else
9838c27c18e8Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9839b789ec8aSmrg		func_append dep_rpath " $flag"
9840c27c18e8Smrg	      fi
9841c27c18e8Smrg	    elif test -n "$runpath_var"; then
9842c27c18e8Smrg	      case "$perm_rpath " in
9843c27c18e8Smrg	      *" $libdir "*) ;;
9844f1ee322dSmrg	      *) func_append perm_rpath " $libdir" ;;
9845c27c18e8Smrg	      esac
9846c27c18e8Smrg	    fi
9847c27c18e8Smrg	  done
9848c27c18e8Smrg	  # Substitute the hardcoded libdirs into the rpath.
9849c27c18e8Smrg	  if test -n "$hardcode_libdir_separator" &&
9850c27c18e8Smrg	     test -n "$hardcode_libdirs"; then
985148e5ce07Smrg	    libdir=$hardcode_libdirs
9852f1ee322dSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9853c27c18e8Smrg	  fi
9854c27c18e8Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9855c27c18e8Smrg	    # We should set the runpath_var.
9856c27c18e8Smrg	    rpath=
9857c27c18e8Smrg	    for dir in $perm_rpath; do
9858b789ec8aSmrg	      func_append rpath "$dir:"
9859c27c18e8Smrg	    done
9860c27c18e8Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9861c27c18e8Smrg	  fi
9862c27c18e8Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9863c27c18e8Smrg	fi
9864c43cc173Smrg
986548e5ce07Smrg	shlibpath=$finalize_shlibpath
986648e5ce07Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9867c27c18e8Smrg	if test -n "$shlibpath"; then
9868c27c18e8Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9869c27c18e8Smrg	fi
9870c43cc173Smrg
9871c27c18e8Smrg	# Get the real and link names of the library.
9872c27c18e8Smrg	eval shared_ext=\"$shrext_cmds\"
9873c27c18e8Smrg	eval library_names=\"$library_names_spec\"
9874c27c18e8Smrg	set dummy $library_names
9875c27c18e8Smrg	shift
987648e5ce07Smrg	realname=$1
9877c27c18e8Smrg	shift
9878c43cc173Smrg
9879c27c18e8Smrg	if test -n "$soname_spec"; then
9880c27c18e8Smrg	  eval soname=\"$soname_spec\"
9881c27c18e8Smrg	else
988248e5ce07Smrg	  soname=$realname
9883c27c18e8Smrg	fi
9884c27c18e8Smrg	if test -z "$dlname"; then
9885c27c18e8Smrg	  dlname=$soname
9886c27c18e8Smrg	fi
9887c43cc173Smrg
988848e5ce07Smrg	lib=$output_objdir/$realname
9889c27c18e8Smrg	linknames=
9890c27c18e8Smrg	for link
9891c27c18e8Smrg	do
9892b789ec8aSmrg	  func_append linknames " $link"
9893c27c18e8Smrg	done
9894c43cc173Smrg
9895c27c18e8Smrg	# Use standard objects if they are pic
989637eb1ca1Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9897c27c18e8Smrg	test "X$libobjs" = "X " && libobjs=
9898c43cc173Smrg
9899c27c18e8Smrg	delfiles=
9900c27c18e8Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9901c27c18e8Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
990248e5ce07Smrg	  export_symbols=$output_objdir/$libname.uexp
9903b789ec8aSmrg	  func_append delfiles " $export_symbols"
9904c27c18e8Smrg	fi
9905c43cc173Smrg
9906c27c18e8Smrg	orig_export_symbols=
9907c27c18e8Smrg	case $host_os in
9908c27c18e8Smrg	cygwin* | mingw* | cegcc*)
9909c27c18e8Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9910c27c18e8Smrg	    # exporting using user supplied symfile
991148e5ce07Smrg	    func_dll_def_p "$export_symbols" || {
9912c27c18e8Smrg	      # and it's NOT already a .def file. Must figure out
9913c27c18e8Smrg	      # which of the given symbols are data symbols and tag
9914c27c18e8Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9915c27c18e8Smrg	      # export_symbols gets reassigned inside the "prepare
9916c27c18e8Smrg	      # the list of exported symbols" if statement, so the
9917c27c18e8Smrg	      # include_expsyms logic still works.
991848e5ce07Smrg	      orig_export_symbols=$export_symbols
9919c27c18e8Smrg	      export_symbols=
9920c27c18e8Smrg	      always_export_symbols=yes
992148e5ce07Smrg	    }
9922c27c18e8Smrg	  fi
9923c27c18e8Smrg	  ;;
9924c27c18e8Smrg	esac
9925c43cc173Smrg
9926c27c18e8Smrg	# Prepare the list of exported symbols
9927c27c18e8Smrg	if test -z "$export_symbols"; then
992848e5ce07Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
992948e5ce07Smrg	    func_verbose "generating symbol list for '$libname.la'"
993048e5ce07Smrg	    export_symbols=$output_objdir/$libname.exp
9931c27c18e8Smrg	    $opt_dry_run || $RM $export_symbols
9932c27c18e8Smrg	    cmds=$export_symbols_cmds
993348e5ce07Smrg	    save_ifs=$IFS; IFS='~'
9934b789ec8aSmrg	    for cmd1 in $cmds; do
993548e5ce07Smrg	      IFS=$save_ifs
9936b789ec8aSmrg	      # Take the normal branch if the nm_file_list_spec branch
9937b789ec8aSmrg	      # doesn't work or if tool conversion is not needed.
9938b789ec8aSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9939b789ec8aSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9940b789ec8aSmrg		  try_normal_branch=yes
9941b789ec8aSmrg		  eval cmd=\"$cmd1\"
9942b789ec8aSmrg		  func_len " $cmd"
9943b789ec8aSmrg		  len=$func_len_result
9944b789ec8aSmrg		  ;;
9945b789ec8aSmrg		*)
9946b789ec8aSmrg		  try_normal_branch=no
9947b789ec8aSmrg		  ;;
9948b789ec8aSmrg	      esac
994948e5ce07Smrg	      if test yes = "$try_normal_branch" \
9950b789ec8aSmrg		 && { test "$len" -lt "$max_cmd_len" \
9951b789ec8aSmrg		      || test "$max_cmd_len" -le -1; }
9952b789ec8aSmrg	      then
9953b789ec8aSmrg		func_show_eval "$cmd" 'exit $?'
9954b789ec8aSmrg		skipped_export=false
9955b789ec8aSmrg	      elif test -n "$nm_file_list_spec"; then
9956b789ec8aSmrg		func_basename "$output"
9957b789ec8aSmrg		output_la=$func_basename_result
9958b789ec8aSmrg		save_libobjs=$libobjs
9959b789ec8aSmrg		save_output=$output
996048e5ce07Smrg		output=$output_objdir/$output_la.nm
9961b789ec8aSmrg		func_to_tool_file "$output"
9962b789ec8aSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9963b789ec8aSmrg		func_append delfiles " $output"
9964b789ec8aSmrg		func_verbose "creating $NM input file list: $output"
9965b789ec8aSmrg		for obj in $save_libobjs; do
9966b789ec8aSmrg		  func_to_tool_file "$obj"
9967b789ec8aSmrg		  $ECHO "$func_to_tool_file_result"
9968b789ec8aSmrg		done > "$output"
9969b789ec8aSmrg		eval cmd=\"$cmd1\"
9970c27c18e8Smrg		func_show_eval "$cmd" 'exit $?'
9971b789ec8aSmrg		output=$save_output
9972b789ec8aSmrg		libobjs=$save_libobjs
9973c27c18e8Smrg		skipped_export=false
9974c27c18e8Smrg	      else
9975c27c18e8Smrg		# The command line is too long to execute in one step.
9976c27c18e8Smrg		func_verbose "using reloadable object file for export list..."
9977c27c18e8Smrg		skipped_export=:
9978c27c18e8Smrg		# Break out early, otherwise skipped_export may be
9979c27c18e8Smrg		# set to false by a later but shorter cmd.
9980c27c18e8Smrg		break
9981c27c18e8Smrg	      fi
9982c27c18e8Smrg	    done
998348e5ce07Smrg	    IFS=$save_ifs
998448e5ce07Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9985c27c18e8Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9986c27c18e8Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9987c27c18e8Smrg	    fi
9988c27c18e8Smrg	  fi
9989c27c18e8Smrg	fi
9990c43cc173Smrg
9991c27c18e8Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
999248e5ce07Smrg	  tmp_export_symbols=$export_symbols
999348e5ce07Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
999437eb1ca1Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9995c27c18e8Smrg	fi
9996c43cc173Smrg
999748e5ce07Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
9998c27c18e8Smrg	  # The given exports_symbols file has to be filtered, so filter it.
999948e5ce07Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10000c27c18e8Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
1000148e5ce07Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10002c27c18e8Smrg	  # though. Also, the filter scales superlinearly with the number of
10003c27c18e8Smrg	  # global variables. join(1) would be nice here, but unfortunately
10004c27c18e8Smrg	  # isn't a blessed tool.
10005c27c18e8Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10006b789ec8aSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10007c27c18e8Smrg	  export_symbols=$output_objdir/$libname.def
10008c27c18e8Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10009c43cc173Smrg	fi
10010c43cc173Smrg
10011c27c18e8Smrg	tmp_deplibs=
10012c27c18e8Smrg	for test_deplib in $deplibs; do
10013c27c18e8Smrg	  case " $convenience " in
10014c27c18e8Smrg	  *" $test_deplib "*) ;;
10015c27c18e8Smrg	  *)
10016b789ec8aSmrg	    func_append tmp_deplibs " $test_deplib"
10017c27c18e8Smrg	    ;;
10018c27c18e8Smrg	  esac
10019c27c18e8Smrg	done
1002048e5ce07Smrg	deplibs=$tmp_deplibs
10021c43cc173Smrg
10022c27c18e8Smrg	if test -n "$convenience"; then
10023c27c18e8Smrg	  if test -n "$whole_archive_flag_spec" &&
1002448e5ce07Smrg	    test yes = "$compiler_needs_object" &&
10025c27c18e8Smrg	    test -z "$libobjs"; then
10026c27c18e8Smrg	    # extract the archives, so we have objects to list.
10027c27c18e8Smrg	    # TODO: could optimize this to just extract one archive.
10028c27c18e8Smrg	    whole_archive_flag_spec=
10029c27c18e8Smrg	  fi
10030c27c18e8Smrg	  if test -n "$whole_archive_flag_spec"; then
10031c27c18e8Smrg	    save_libobjs=$libobjs
10032c27c18e8Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10033c27c18e8Smrg	    test "X$libobjs" = "X " && libobjs=
10034c27c18e8Smrg	  else
1003548e5ce07Smrg	    gentop=$output_objdir/${outputname}x
10036b789ec8aSmrg	    func_append generated " $gentop"
10037c43cc173Smrg
10038c27c18e8Smrg	    func_extract_archives $gentop $convenience
10039b789ec8aSmrg	    func_append libobjs " $func_extract_archives_result"
10040c27c18e8Smrg	    test "X$libobjs" = "X " && libobjs=
10041c27c18e8Smrg	  fi
10042c27c18e8Smrg	fi
10043c43cc173Smrg
1004448e5ce07Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10045c27c18e8Smrg	  eval flag=\"$thread_safe_flag_spec\"
10046b789ec8aSmrg	  func_append linker_flags " $flag"
10047c27c18e8Smrg	fi
10048c43cc173Smrg
10049c27c18e8Smrg	# Make a backup of the uninstalled library when relinking
1005048e5ce07Smrg	if test relink = "$opt_mode"; then
10051c27c18e8Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10052c43cc173Smrg	fi
10053c43cc173Smrg
10054c27c18e8Smrg	# Do each of the archive commands.
1005548e5ce07Smrg	if test yes = "$module" && test -n "$module_cmds"; then
10056c27c18e8Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10057c27c18e8Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10058c27c18e8Smrg	    cmds=$module_expsym_cmds
10059c27c18e8Smrg	  else
10060c27c18e8Smrg	    eval test_cmds=\"$module_cmds\"
10061c27c18e8Smrg	    cmds=$module_cmds
10062c27c18e8Smrg	  fi
10063c27c18e8Smrg	else
10064c27c18e8Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10065c27c18e8Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10066c27c18e8Smrg	    cmds=$archive_expsym_cmds
10067c27c18e8Smrg	  else
10068c27c18e8Smrg	    eval test_cmds=\"$archive_cmds\"
10069c27c18e8Smrg	    cmds=$archive_cmds
10070c27c18e8Smrg	  fi
10071c43cc173Smrg	fi
10072c43cc173Smrg
1007348e5ce07Smrg	if test : != "$skipped_export" &&
10074c27c18e8Smrg	   func_len " $test_cmds" &&
10075c27c18e8Smrg	   len=$func_len_result &&
10076c27c18e8Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10077c27c18e8Smrg	  :
10078c27c18e8Smrg	else
10079c27c18e8Smrg	  # The command line is too long to link in one step, link piecewise
10080c27c18e8Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10081c27c18e8Smrg	  # script.
10082c43cc173Smrg
10083c27c18e8Smrg	  # Save the value of $output and $libobjs because we want to
10084c27c18e8Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10085c27c18e8Smrg	  # want to use save_libobjs as it was before
10086c27c18e8Smrg	  # whole_archive_flag_spec was expanded, because we can't
10087c27c18e8Smrg	  # assume the linker understands whole_archive_flag_spec.
10088c27c18e8Smrg	  # This may have to be revisited, in case too many
10089c27c18e8Smrg	  # convenience libraries get linked in and end up exceeding
10090c27c18e8Smrg	  # the spec.
10091c27c18e8Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10092c27c18e8Smrg	    save_libobjs=$libobjs
10093c27c18e8Smrg	  fi
10094c27c18e8Smrg	  save_output=$output
1009537eb1ca1Smrg	  func_basename "$output"
1009637eb1ca1Smrg	  output_la=$func_basename_result
10097c43cc173Smrg
10098c27c18e8Smrg	  # Clear the reloadable object creation command queue and
10099c27c18e8Smrg	  # initialize k to one.
10100c27c18e8Smrg	  test_cmds=
10101c27c18e8Smrg	  concat_cmds=
10102c27c18e8Smrg	  objlist=
10103c27c18e8Smrg	  last_robj=
10104c27c18e8Smrg	  k=1
10105c43cc173Smrg
1010648e5ce07Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
1010748e5ce07Smrg	    output=$output_objdir/$output_la.lnkscript
10108c27c18e8Smrg	    func_verbose "creating GNU ld script: $output"
1010937eb1ca1Smrg	    echo 'INPUT (' > $output
10110c27c18e8Smrg	    for obj in $save_libobjs
10111c27c18e8Smrg	    do
10112b789ec8aSmrg	      func_to_tool_file "$obj"
10113b789ec8aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10114c27c18e8Smrg	    done
1011537eb1ca1Smrg	    echo ')' >> $output
10116b789ec8aSmrg	    func_append delfiles " $output"
10117b789ec8aSmrg	    func_to_tool_file "$output"
10118b789ec8aSmrg	    output=$func_to_tool_file_result
1011948e5ce07Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
1012048e5ce07Smrg	    output=$output_objdir/$output_la.lnk
10121c27c18e8Smrg	    func_verbose "creating linker input file list: $output"
10122c27c18e8Smrg	    : > $output
10123c27c18e8Smrg	    set x $save_libobjs
10124c27c18e8Smrg	    shift
10125c27c18e8Smrg	    firstobj=
1012648e5ce07Smrg	    if test yes = "$compiler_needs_object"; then
10127c27c18e8Smrg	      firstobj="$1 "
10128c27c18e8Smrg	      shift
10129c27c18e8Smrg	    fi
10130c27c18e8Smrg	    for obj
10131c27c18e8Smrg	    do
10132b789ec8aSmrg	      func_to_tool_file "$obj"
10133b789ec8aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10134c27c18e8Smrg	    done
10135b789ec8aSmrg	    func_append delfiles " $output"
10136b789ec8aSmrg	    func_to_tool_file "$output"
10137b789ec8aSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10138c27c18e8Smrg	  else
10139c27c18e8Smrg	    if test -n "$save_libobjs"; then
10140c27c18e8Smrg	      func_verbose "creating reloadable object files..."
1014148e5ce07Smrg	      output=$output_objdir/$output_la-$k.$objext
10142c27c18e8Smrg	      eval test_cmds=\"$reload_cmds\"
10143c27c18e8Smrg	      func_len " $test_cmds"
10144c27c18e8Smrg	      len0=$func_len_result
10145c27c18e8Smrg	      len=$len0
10146c27c18e8Smrg
10147c27c18e8Smrg	      # Loop over the list of objects to be linked.
10148c27c18e8Smrg	      for obj in $save_libobjs
10149c27c18e8Smrg	      do
10150c27c18e8Smrg		func_len " $obj"
10151c27c18e8Smrg		func_arith $len + $func_len_result
10152c27c18e8Smrg		len=$func_arith_result
1015348e5ce07Smrg		if test -z "$objlist" ||
10154c27c18e8Smrg		   test "$len" -lt "$max_cmd_len"; then
10155c27c18e8Smrg		  func_append objlist " $obj"
10156c27c18e8Smrg		else
10157c27c18e8Smrg		  # The command $test_cmds is almost too long, add a
10158c27c18e8Smrg		  # command to the queue.
1015948e5ce07Smrg		  if test 1 -eq "$k"; then
10160c27c18e8Smrg		    # The first file doesn't have a previous command to add.
1016137eb1ca1Smrg		    reload_objs=$objlist
1016237eb1ca1Smrg		    eval concat_cmds=\"$reload_cmds\"
10163c27c18e8Smrg		  else
10164c27c18e8Smrg		    # All subsequent reloadable object files will link in
10165c27c18e8Smrg		    # the last one created.
1016637eb1ca1Smrg		    reload_objs="$objlist $last_robj"
1016737eb1ca1Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10168c27c18e8Smrg		  fi
1016948e5ce07Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
10170c27c18e8Smrg		  func_arith $k + 1
10171c27c18e8Smrg		  k=$func_arith_result
1017248e5ce07Smrg		  output=$output_objdir/$output_la-$k.$objext
1017337eb1ca1Smrg		  objlist=" $obj"
10174c27c18e8Smrg		  func_len " $last_robj"
10175c27c18e8Smrg		  func_arith $len0 + $func_len_result
10176c27c18e8Smrg		  len=$func_arith_result
10177c27c18e8Smrg		fi
10178c27c18e8Smrg	      done
10179c27c18e8Smrg	      # Handle the remaining objects by creating one last
10180c27c18e8Smrg	      # reloadable object file.  All subsequent reloadable object
10181c27c18e8Smrg	      # files will link in the last one created.
10182c27c18e8Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1018337eb1ca1Smrg	      reload_objs="$objlist $last_robj"
1018448e5ce07Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10185c27c18e8Smrg	      if test -n "$last_robj"; then
1018648e5ce07Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10187c27c18e8Smrg	      fi
10188b789ec8aSmrg	      func_append delfiles " $output"
10189c43cc173Smrg
10190c27c18e8Smrg	    else
10191c27c18e8Smrg	      output=
10192c27c18e8Smrg	    fi
10193c27c18e8Smrg
1019448e5ce07Smrg	    ${skipped_export-false} && {
1019548e5ce07Smrg	      func_verbose "generating symbol list for '$libname.la'"
1019648e5ce07Smrg	      export_symbols=$output_objdir/$libname.exp
10197c27c18e8Smrg	      $opt_dry_run || $RM $export_symbols
10198c27c18e8Smrg	      libobjs=$output
10199c27c18e8Smrg	      # Append the command to create the export file.
10200c27c18e8Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10201c27c18e8Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10202c27c18e8Smrg	      if test -n "$last_robj"; then
10203c27c18e8Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10204c27c18e8Smrg	      fi
1020548e5ce07Smrg	    }
10206c43cc173Smrg
10207c27c18e8Smrg	    test -n "$save_libobjs" &&
10208c27c18e8Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10209c43cc173Smrg
10210c27c18e8Smrg	    # Loop through the commands generated above and execute them.
1021148e5ce07Smrg	    save_ifs=$IFS; IFS='~'
10212c27c18e8Smrg	    for cmd in $concat_cmds; do
1021348e5ce07Smrg	      IFS=$save_ifs
1021448e5ce07Smrg	      $opt_quiet || {
102154e8f48c7Smrg		  func_quote_arg expand,pretty "$cmd"
102164e8f48c7Smrg		  eval "func_echo $func_quote_arg_result"
10217c27c18e8Smrg	      }
10218c27c18e8Smrg	      $opt_dry_run || eval "$cmd" || {
10219c27c18e8Smrg		lt_exit=$?
10220c27c18e8Smrg
10221c27c18e8Smrg		# Restore the uninstalled library and exit
1022248e5ce07Smrg		if test relink = "$opt_mode"; then
10223c27c18e8Smrg		  ( cd "$output_objdir" && \
10224c27c18e8Smrg		    $RM "${realname}T" && \
10225c27c18e8Smrg		    $MV "${realname}U" "$realname" )
10226c27c18e8Smrg		fi
10227c43cc173Smrg
10228c27c18e8Smrg		exit $lt_exit
10229c27c18e8Smrg	      }
10230c27c18e8Smrg	    done
1023148e5ce07Smrg	    IFS=$save_ifs
10232c43cc173Smrg
10233c27c18e8Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10234c27c18e8Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10235c27c18e8Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10236c43cc173Smrg	    fi
10237c43cc173Smrg	  fi
10238c43cc173Smrg
1023948e5ce07Smrg          ${skipped_export-false} && {
10240c27c18e8Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
1024148e5ce07Smrg	      tmp_export_symbols=$export_symbols
1024248e5ce07Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1024337eb1ca1Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10244c27c18e8Smrg	    fi
10245c43cc173Smrg
10246c27c18e8Smrg	    if test -n "$orig_export_symbols"; then
10247c27c18e8Smrg	      # The given exports_symbols file has to be filtered, so filter it.
1024848e5ce07Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10249c27c18e8Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
1025048e5ce07Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10251c27c18e8Smrg	      # though. Also, the filter scales superlinearly with the number of
10252c27c18e8Smrg	      # global variables. join(1) would be nice here, but unfortunately
10253c27c18e8Smrg	      # isn't a blessed tool.
10254c27c18e8Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10255b789ec8aSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10256c27c18e8Smrg	      export_symbols=$output_objdir/$libname.def
10257c27c18e8Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10258c27c18e8Smrg	    fi
1025948e5ce07Smrg	  }
10260c43cc173Smrg
10261c27c18e8Smrg	  libobjs=$output
10262c27c18e8Smrg	  # Restore the value of output.
10263c27c18e8Smrg	  output=$save_output
10264c43cc173Smrg
10265c27c18e8Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10266c27c18e8Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10267c27c18e8Smrg	    test "X$libobjs" = "X " && libobjs=
10268c27c18e8Smrg	  fi
10269c27c18e8Smrg	  # Expand the library linking commands again to reset the
10270c27c18e8Smrg	  # value of $libobjs for piecewise linking.
10271c27c18e8Smrg
10272c27c18e8Smrg	  # Do each of the archive commands.
1027348e5ce07Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
10274c27c18e8Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10275c27c18e8Smrg	      cmds=$module_expsym_cmds
10276c43cc173Smrg	    else
10277c27c18e8Smrg	      cmds=$module_cmds
10278c43cc173Smrg	    fi
10279c43cc173Smrg	  else
10280c27c18e8Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10281c27c18e8Smrg	      cmds=$archive_expsym_cmds
10282c27c18e8Smrg	    else
10283c27c18e8Smrg	      cmds=$archive_cmds
10284c27c18e8Smrg	    fi
10285c43cc173Smrg	  fi
10286c43cc173Smrg	fi
10287c43cc173Smrg
10288c27c18e8Smrg	if test -n "$delfiles"; then
10289c27c18e8Smrg	  # Append the command to remove temporary files to $cmds.
10290c27c18e8Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10291c27c18e8Smrg	fi
10292c43cc173Smrg
10293c27c18e8Smrg	# Add any objects from preloaded convenience libraries
10294c27c18e8Smrg	if test -n "$dlprefiles"; then
1029548e5ce07Smrg	  gentop=$output_objdir/${outputname}x
10296b789ec8aSmrg	  func_append generated " $gentop"
10297c43cc173Smrg
10298c27c18e8Smrg	  func_extract_archives $gentop $dlprefiles
10299b789ec8aSmrg	  func_append libobjs " $func_extract_archives_result"
10300c27c18e8Smrg	  test "X$libobjs" = "X " && libobjs=
10301c43cc173Smrg	fi
10302c43cc173Smrg
1030348e5ce07Smrg	save_ifs=$IFS; IFS='~'
10304c27c18e8Smrg	for cmd in $cmds; do
1030548e5ce07Smrg	  IFS=$sp$nl
10306c27c18e8Smrg	  eval cmd=\"$cmd\"
1030748e5ce07Smrg	  IFS=$save_ifs
1030848e5ce07Smrg	  $opt_quiet || {
103094e8f48c7Smrg	    func_quote_arg expand,pretty "$cmd"
103104e8f48c7Smrg	    eval "func_echo $func_quote_arg_result"
10311c27c18e8Smrg	  }
10312c27c18e8Smrg	  $opt_dry_run || eval "$cmd" || {
10313c27c18e8Smrg	    lt_exit=$?
10314c43cc173Smrg
10315c27c18e8Smrg	    # Restore the uninstalled library and exit
1031648e5ce07Smrg	    if test relink = "$opt_mode"; then
10317c27c18e8Smrg	      ( cd "$output_objdir" && \
10318c27c18e8Smrg	        $RM "${realname}T" && \
10319c27c18e8Smrg		$MV "${realname}U" "$realname" )
10320c43cc173Smrg	    fi
10321c43cc173Smrg
10322c27c18e8Smrg	    exit $lt_exit
10323c27c18e8Smrg	  }
10324c27c18e8Smrg	done
1032548e5ce07Smrg	IFS=$save_ifs
10326c43cc173Smrg
10327c27c18e8Smrg	# Restore the uninstalled library and exit
1032848e5ce07Smrg	if test relink = "$opt_mode"; then
10329c27c18e8Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10330c43cc173Smrg
10331c27c18e8Smrg	  if test -n "$convenience"; then
10332c27c18e8Smrg	    if test -z "$whole_archive_flag_spec"; then
10333c27c18e8Smrg	      func_show_eval '${RM}r "$gentop"'
10334c27c18e8Smrg	    fi
10335c27c18e8Smrg	  fi
10336c43cc173Smrg
10337c27c18e8Smrg	  exit $EXIT_SUCCESS
10338c27c18e8Smrg	fi
10339c43cc173Smrg
10340c27c18e8Smrg	# Create links to the real library.
10341c27c18e8Smrg	for linkname in $linknames; do
10342c27c18e8Smrg	  if test "$realname" != "$linkname"; then
10343c27c18e8Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10344c43cc173Smrg	  fi
10345c43cc173Smrg	done
10346c43cc173Smrg
10347c27c18e8Smrg	# If -module or -export-dynamic was specified, set the dlname.
1034848e5ce07Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10349c27c18e8Smrg	  # On all known operating systems, these are identical.
1035048e5ce07Smrg	  dlname=$soname
10351c27c18e8Smrg	fi
10352c27c18e8Smrg      fi
10353c43cc173Smrg      ;;
10354c43cc173Smrg
10355c27c18e8Smrg    obj)
1035648e5ce07Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
1035748e5ce07Smrg	func_warning "'-dlopen' is ignored for objects"
10358c27c18e8Smrg      fi
10359c43cc173Smrg
10360c27c18e8Smrg      case " $deplibs" in
10361c27c18e8Smrg      *\ -l* | *\ -L*)
1036248e5ce07Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10363c43cc173Smrg      esac
10364c43cc173Smrg
10365c27c18e8Smrg      test -n "$rpath" && \
1036648e5ce07Smrg	func_warning "'-rpath' is ignored for objects"
10367c43cc173Smrg
10368c27c18e8Smrg      test -n "$xrpath" && \
1036948e5ce07Smrg	func_warning "'-R' is ignored for objects"
10370c43cc173Smrg
10371c27c18e8Smrg      test -n "$vinfo" && \
1037248e5ce07Smrg	func_warning "'-version-info' is ignored for objects"
10373c27c18e8Smrg
10374c27c18e8Smrg      test -n "$release" && \
1037548e5ce07Smrg	func_warning "'-release' is ignored for objects"
10376c27c18e8Smrg
10377c27c18e8Smrg      case $output in
10378c27c18e8Smrg      *.lo)
10379c27c18e8Smrg	test -n "$objs$old_deplibs" && \
1038048e5ce07Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10381c27c18e8Smrg
10382c27c18e8Smrg	libobj=$output
10383c27c18e8Smrg	func_lo2o "$libobj"
10384c27c18e8Smrg	obj=$func_lo2o_result
10385c43cc173Smrg	;;
10386c43cc173Smrg      *)
10387c27c18e8Smrg	libobj=
1038848e5ce07Smrg	obj=$output
10389c43cc173Smrg	;;
10390c43cc173Smrg      esac
10391c43cc173Smrg
10392c27c18e8Smrg      # Delete the old objects.
10393c27c18e8Smrg      $opt_dry_run || $RM $obj $libobj
10394c43cc173Smrg
10395c27c18e8Smrg      # Objects from convenience libraries.  This assumes
10396c27c18e8Smrg      # single-version convenience libraries.  Whenever we create
10397c27c18e8Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10398c27c18e8Smrg      # the extraction.
10399c27c18e8Smrg      reload_conv_objs=
10400c27c18e8Smrg      gentop=
1040148e5ce07Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
1040248e5ce07Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
1040348e5ce07Smrg      # into space.
1040448e5ce07Smrg      case $reload_cmds in
1040548e5ce07Smrg        *\$LD[\ \$]*) wl= ;;
1040648e5ce07Smrg      esac
10407c27c18e8Smrg      if test -n "$convenience"; then
10408c27c18e8Smrg	if test -n "$whole_archive_flag_spec"; then
10409c27c18e8Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
1041048e5ce07Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
1041148e5ce07Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10412c27c18e8Smrg	else
1041348e5ce07Smrg	  gentop=$output_objdir/${obj}x
10414b789ec8aSmrg	  func_append generated " $gentop"
10415c43cc173Smrg
10416c27c18e8Smrg	  func_extract_archives $gentop $convenience
10417c27c18e8Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10418c27c18e8Smrg	fi
10419c43cc173Smrg      fi
10420c43cc173Smrg
10421b789ec8aSmrg      # If we're not building shared, we need to use non_pic_objs
1042248e5ce07Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10423b789ec8aSmrg
10424c27c18e8Smrg      # Create the old-style object.
1042548e5ce07Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10426c43cc173Smrg
1042748e5ce07Smrg      output=$obj
10428c27c18e8Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10429c43cc173Smrg
10430c27c18e8Smrg      # Exit if we aren't doing a library object file.
10431c27c18e8Smrg      if test -z "$libobj"; then
10432c27c18e8Smrg	if test -n "$gentop"; then
10433c27c18e8Smrg	  func_show_eval '${RM}r "$gentop"'
10434c27c18e8Smrg	fi
10435c27c18e8Smrg
10436c27c18e8Smrg	exit $EXIT_SUCCESS
10437c43cc173Smrg      fi
10438c27c18e8Smrg
1043948e5ce07Smrg      test yes = "$build_libtool_libs" || {
10440c27c18e8Smrg	if test -n "$gentop"; then
10441c27c18e8Smrg	  func_show_eval '${RM}r "$gentop"'
10442c27c18e8Smrg	fi
10443c27c18e8Smrg
10444c27c18e8Smrg	# Create an invalid libtool object if no PIC, so that we don't
10445c27c18e8Smrg	# accidentally link it into a program.
10446c27c18e8Smrg	# $show "echo timestamp > $libobj"
10447c27c18e8Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10448c27c18e8Smrg	exit $EXIT_SUCCESS
1044948e5ce07Smrg      }
10450c27c18e8Smrg
1045148e5ce07Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10452c27c18e8Smrg	# Only do commands if we really have different PIC objects.
10453c27c18e8Smrg	reload_objs="$libobjs $reload_conv_objs"
1045448e5ce07Smrg	output=$libobj
10455c27c18e8Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10456c27c18e8Smrg      fi
10457c27c18e8Smrg
10458c27c18e8Smrg      if test -n "$gentop"; then
10459c27c18e8Smrg	func_show_eval '${RM}r "$gentop"'
10460c27c18e8Smrg      fi
10461c27c18e8Smrg
10462c27c18e8Smrg      exit $EXIT_SUCCESS
10463c43cc173Smrg      ;;
10464c43cc173Smrg
10465c27c18e8Smrg    prog)
10466c27c18e8Smrg      case $host in
10467c27c18e8Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10468c27c18e8Smrg	          output=$func_stripname_result.exe;;
10469c27c18e8Smrg      esac
10470c27c18e8Smrg      test -n "$vinfo" && \
1047148e5ce07Smrg	func_warning "'-version-info' is ignored for programs"
10472c43cc173Smrg
10473c27c18e8Smrg      test -n "$release" && \
1047448e5ce07Smrg	func_warning "'-release' is ignored for programs"
10475c43cc173Smrg
1047648e5ce07Smrg      $preload \
1047748e5ce07Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
1047848e5ce07Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10479c27c18e8Smrg
10480c27c18e8Smrg      case $host in
10481c27c18e8Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10482c27c18e8Smrg	# On Rhapsody replace the C library is the System framework
1048337eb1ca1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1048437eb1ca1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10485c43cc173Smrg	;;
10486c27c18e8Smrg      esac
10487c43cc173Smrg
10488c27c18e8Smrg      case $host in
10489c27c18e8Smrg      *-*-darwin*)
10490c27c18e8Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10491c27c18e8Smrg	# But is supposedly fixed on 10.4 or later (yay!).
1049248e5ce07Smrg	if test CXX = "$tagname"; then
10493c27c18e8Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10494c27c18e8Smrg	    10.[0123])
1049548e5ce07Smrg	      func_append compile_command " $wl-bind_at_load"
1049648e5ce07Smrg	      func_append finalize_command " $wl-bind_at_load"
10497c27c18e8Smrg	    ;;
10498c27c18e8Smrg	  esac
10499c43cc173Smrg	fi
10500c27c18e8Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050137eb1ca1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050237eb1ca1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10503c27c18e8Smrg	;;
10504c27c18e8Smrg      esac
10505c43cc173Smrg
10506c43cc173Smrg
10507c27c18e8Smrg      # move library search paths that coincide with paths to not yet
10508c27c18e8Smrg      # installed libraries to the beginning of the library search list
10509c27c18e8Smrg      new_libs=
10510c27c18e8Smrg      for path in $notinst_path; do
10511c27c18e8Smrg	case " $new_libs " in
10512c27c18e8Smrg	*" -L$path/$objdir "*) ;;
10513c27c18e8Smrg	*)
10514c27c18e8Smrg	  case " $compile_deplibs " in
10515c27c18e8Smrg	  *" -L$path/$objdir "*)
10516b789ec8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
10517c43cc173Smrg	  esac
10518c27c18e8Smrg	  ;;
10519c27c18e8Smrg	esac
10520c27c18e8Smrg      done
10521c27c18e8Smrg      for deplib in $compile_deplibs; do
10522c27c18e8Smrg	case $deplib in
10523c27c18e8Smrg	-L*)
10524c27c18e8Smrg	  case " $new_libs " in
10525c27c18e8Smrg	  *" $deplib "*) ;;
10526b789ec8aSmrg	  *) func_append new_libs " $deplib" ;;
10527c43cc173Smrg	  esac
10528c27c18e8Smrg	  ;;
10529b789ec8aSmrg	*) func_append new_libs " $deplib" ;;
10530c27c18e8Smrg	esac
10531c27c18e8Smrg      done
1053248e5ce07Smrg      compile_deplibs=$new_libs
10533c43cc173Smrg
10534c43cc173Smrg
10535b789ec8aSmrg      func_append compile_command " $compile_deplibs"
10536b789ec8aSmrg      func_append finalize_command " $finalize_deplibs"
10537c43cc173Smrg
10538c27c18e8Smrg      if test -n "$rpath$xrpath"; then
10539c27c18e8Smrg	# If the user specified any rpath flags, then add them.
10540c27c18e8Smrg	for libdir in $rpath $xrpath; do
10541c27c18e8Smrg	  # This is the magic to use -rpath.
10542c27c18e8Smrg	  case "$finalize_rpath " in
10543c27c18e8Smrg	  *" $libdir "*) ;;
10544b789ec8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
10545c27c18e8Smrg	  esac
10546c27c18e8Smrg	done
10547c27c18e8Smrg      fi
10548c43cc173Smrg
10549c27c18e8Smrg      # Now hardcode the library paths
10550c27c18e8Smrg      rpath=
10551c27c18e8Smrg      hardcode_libdirs=
10552c27c18e8Smrg      for libdir in $compile_rpath $finalize_rpath; do
10553c27c18e8Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10554c27c18e8Smrg	  if test -n "$hardcode_libdir_separator"; then
10555c27c18e8Smrg	    if test -z "$hardcode_libdirs"; then
1055648e5ce07Smrg	      hardcode_libdirs=$libdir
10557c27c18e8Smrg	    else
10558c27c18e8Smrg	      # Just accumulate the unique libdirs.
10559c27c18e8Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10560c27c18e8Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10561c27c18e8Smrg		;;
10562c27c18e8Smrg	      *)
10563b789ec8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10564c27c18e8Smrg		;;
10565c27c18e8Smrg	      esac
10566c27c18e8Smrg	    fi
10567c43cc173Smrg	  else
10568c27c18e8Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10569b789ec8aSmrg	    func_append rpath " $flag"
10570c43cc173Smrg	  fi
10571c27c18e8Smrg	elif test -n "$runpath_var"; then
10572c27c18e8Smrg	  case "$perm_rpath " in
10573c27c18e8Smrg	  *" $libdir "*) ;;
10574b789ec8aSmrg	  *) func_append perm_rpath " $libdir" ;;
10575c27c18e8Smrg	  esac
10576c27c18e8Smrg	fi
10577c27c18e8Smrg	case $host in
10578c27c18e8Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
1057948e5ce07Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10580c27c18e8Smrg	  case :$dllsearchpath: in
10581c27c18e8Smrg	  *":$libdir:"*) ;;
10582c27c18e8Smrg	  ::) dllsearchpath=$libdir;;
10583b789ec8aSmrg	  *) func_append dllsearchpath ":$libdir";;
10584c27c18e8Smrg	  esac
10585c27c18e8Smrg	  case :$dllsearchpath: in
10586c27c18e8Smrg	  *":$testbindir:"*) ;;
10587c27c18e8Smrg	  ::) dllsearchpath=$testbindir;;
10588b789ec8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
10589c27c18e8Smrg	  esac
10590c27c18e8Smrg	  ;;
10591c27c18e8Smrg	esac
10592c27c18e8Smrg      done
10593c27c18e8Smrg      # Substitute the hardcoded libdirs into the rpath.
10594c27c18e8Smrg      if test -n "$hardcode_libdir_separator" &&
10595c27c18e8Smrg	 test -n "$hardcode_libdirs"; then
1059648e5ce07Smrg	libdir=$hardcode_libdirs
10597c27c18e8Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10598c27c18e8Smrg      fi
1059948e5ce07Smrg      compile_rpath=$rpath
10600c43cc173Smrg
10601c27c18e8Smrg      rpath=
10602c27c18e8Smrg      hardcode_libdirs=
10603c27c18e8Smrg      for libdir in $finalize_rpath; do
10604c27c18e8Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10605c27c18e8Smrg	  if test -n "$hardcode_libdir_separator"; then
10606c27c18e8Smrg	    if test -z "$hardcode_libdirs"; then
1060748e5ce07Smrg	      hardcode_libdirs=$libdir
10608c27c18e8Smrg	    else
10609c27c18e8Smrg	      # Just accumulate the unique libdirs.
10610c27c18e8Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10611c27c18e8Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10612c27c18e8Smrg		;;
10613c27c18e8Smrg	      *)
10614b789ec8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10615c27c18e8Smrg		;;
10616c27c18e8Smrg	      esac
10617c27c18e8Smrg	    fi
10618c43cc173Smrg	  else
10619c27c18e8Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10620b789ec8aSmrg	    func_append rpath " $flag"
10621c43cc173Smrg	  fi
10622c27c18e8Smrg	elif test -n "$runpath_var"; then
10623c27c18e8Smrg	  case "$finalize_perm_rpath " in
10624c27c18e8Smrg	  *" $libdir "*) ;;
10625b789ec8aSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10626c27c18e8Smrg	  esac
10627c43cc173Smrg	fi
10628c27c18e8Smrg      done
10629c27c18e8Smrg      # Substitute the hardcoded libdirs into the rpath.
10630c27c18e8Smrg      if test -n "$hardcode_libdir_separator" &&
10631c27c18e8Smrg	 test -n "$hardcode_libdirs"; then
1063248e5ce07Smrg	libdir=$hardcode_libdirs
10633c27c18e8Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10634c27c18e8Smrg      fi
1063548e5ce07Smrg      finalize_rpath=$rpath
10636c43cc173Smrg
1063748e5ce07Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10638c27c18e8Smrg	# Transform all the library objects into standard objects.
1063937eb1ca1Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064037eb1ca1Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10641c27c18e8Smrg      fi
10642c43cc173Smrg
1064348e5ce07Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10644c43cc173Smrg
10645c27c18e8Smrg      # template prelinking step
10646c27c18e8Smrg      if test -n "$prelink_cmds"; then
10647c27c18e8Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10648c27c18e8Smrg      fi
10649c43cc173Smrg
1065048e5ce07Smrg      wrappers_required=:
10651c27c18e8Smrg      case $host in
1065237eb1ca1Smrg      *cegcc* | *mingw32ce*)
1065337eb1ca1Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
1065448e5ce07Smrg        wrappers_required=false
1065537eb1ca1Smrg        ;;
10656c27c18e8Smrg      *cygwin* | *mingw* )
1065748e5ce07Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10658c27c18e8Smrg        ;;
10659c27c18e8Smrg      *)
1066048e5ce07Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
1066148e5ce07Smrg          wrappers_required=false
10662c27c18e8Smrg        fi
10663c27c18e8Smrg        ;;
10664c27c18e8Smrg      esac
1066548e5ce07Smrg      $wrappers_required || {
10666c27c18e8Smrg	# Replace the output file specification.
1066737eb1ca1Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1066848e5ce07Smrg	link_command=$compile_command$compile_rpath
10669c43cc173Smrg
10670c27c18e8Smrg	# We have no uninstalled library dependencies, so finalize right now.
10671c27c18e8Smrg	exit_status=0
10672c27c18e8Smrg	func_show_eval "$link_command" 'exit_status=$?'
10673c43cc173Smrg
10674b789ec8aSmrg	if test -n "$postlink_cmds"; then
10675b789ec8aSmrg	  func_to_tool_file "$output"
10676b789ec8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10677b789ec8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10678b789ec8aSmrg	fi
10679b789ec8aSmrg
10680c27c18e8Smrg	# Delete the generated files.
1068148e5ce07Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
1068248e5ce07Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10683c43cc173Smrg	fi
10684c43cc173Smrg
10685c27c18e8Smrg	exit $exit_status
1068648e5ce07Smrg      }
10687c43cc173Smrg
10688c27c18e8Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10689c27c18e8Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10690c27c18e8Smrg      fi
10691c27c18e8Smrg      if test -n "$finalize_shlibpath"; then
10692c27c18e8Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10693c27c18e8Smrg      fi
10694c43cc173Smrg
10695c27c18e8Smrg      compile_var=
10696c27c18e8Smrg      finalize_var=
10697c27c18e8Smrg      if test -n "$runpath_var"; then
10698c27c18e8Smrg	if test -n "$perm_rpath"; then
10699c27c18e8Smrg	  # We should set the runpath_var.
10700c27c18e8Smrg	  rpath=
10701c27c18e8Smrg	  for dir in $perm_rpath; do
10702b789ec8aSmrg	    func_append rpath "$dir:"
10703c27c18e8Smrg	  done
10704c27c18e8Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10705c43cc173Smrg	fi
10706c27c18e8Smrg	if test -n "$finalize_perm_rpath"; then
10707c27c18e8Smrg	  # We should set the runpath_var.
10708c27c18e8Smrg	  rpath=
10709c27c18e8Smrg	  for dir in $finalize_perm_rpath; do
10710b789ec8aSmrg	    func_append rpath "$dir:"
10711c27c18e8Smrg	  done
10712c27c18e8Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10713c43cc173Smrg	fi
10714c27c18e8Smrg      fi
10715c43cc173Smrg
1071648e5ce07Smrg      if test yes = "$no_install"; then
10717c27c18e8Smrg	# We don't need to create a wrapper script.
1071848e5ce07Smrg	link_command=$compile_var$compile_command$compile_rpath
10719c27c18e8Smrg	# Replace the output file specification.
1072037eb1ca1Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10721c27c18e8Smrg	# Delete the old output file.
10722c27c18e8Smrg	$opt_dry_run || $RM $output
10723c27c18e8Smrg	# Link the executable and exit
10724c27c18e8Smrg	func_show_eval "$link_command" 'exit $?'
10725b789ec8aSmrg
10726b789ec8aSmrg	if test -n "$postlink_cmds"; then
10727b789ec8aSmrg	  func_to_tool_file "$output"
10728b789ec8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10729b789ec8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10730b789ec8aSmrg	fi
10731b789ec8aSmrg
10732c43cc173Smrg	exit $EXIT_SUCCESS
10733c27c18e8Smrg      fi
10734c43cc173Smrg
1073548e5ce07Smrg      case $hardcode_action,$fast_install in
1073648e5ce07Smrg        relink,*)
1073748e5ce07Smrg	  # Fast installation is not supported
1073848e5ce07Smrg	  link_command=$compile_var$compile_command$compile_rpath
1073948e5ce07Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10740c27c18e8Smrg
1074148e5ce07Smrg	  func_warning "this platform does not like uninstalled shared libraries"
1074248e5ce07Smrg	  func_warning "'$output' will be relinked during installation"
1074348e5ce07Smrg	  ;;
1074448e5ce07Smrg        *,yes)
1074548e5ce07Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1074648e5ce07Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
1074748e5ce07Smrg          ;;
1074848e5ce07Smrg	*,no)
1074948e5ce07Smrg	  link_command=$compile_var$compile_command$compile_rpath
1075048e5ce07Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1075148e5ce07Smrg          ;;
1075248e5ce07Smrg	*,needless)
1075348e5ce07Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1075448e5ce07Smrg	  relink_command=
1075548e5ce07Smrg          ;;
1075648e5ce07Smrg      esac
10757c43cc173Smrg
10758c27c18e8Smrg      # Replace the output file specification.
1075937eb1ca1Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10760c43cc173Smrg
10761c27c18e8Smrg      # Delete the old output files.
10762c27c18e8Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10763c43cc173Smrg
10764c27c18e8Smrg      func_show_eval "$link_command" 'exit $?'
10765c43cc173Smrg
10766b789ec8aSmrg      if test -n "$postlink_cmds"; then
10767b789ec8aSmrg	func_to_tool_file "$output_objdir/$outputname"
10768b789ec8aSmrg	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'`
10769b789ec8aSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10770b789ec8aSmrg      fi
10771b789ec8aSmrg
10772c27c18e8Smrg      # Now create the wrapper script.
10773c27c18e8Smrg      func_verbose "creating $output"
10774c43cc173Smrg
10775c27c18e8Smrg      # Quote the relink command for shipping.
10776c27c18e8Smrg      if test -n "$relink_command"; then
10777c27c18e8Smrg	# Preserve any variables that may affect compiler behavior
10778c27c18e8Smrg	for var in $variables_saved_for_relink; do
10779c27c18e8Smrg	  if eval test -z \"\${$var+set}\"; then
10780c27c18e8Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10781c27c18e8Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10782c27c18e8Smrg	    relink_command="$var=; export $var; $relink_command"
10783c43cc173Smrg	  else
107844e8f48c7Smrg	    func_quote_arg pretty "$var_value"
107854e8f48c7Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10786c43cc173Smrg	  fi
10787c27c18e8Smrg	done
107884e8f48c7Smrg	func_quote eval cd "`pwd`"
107894e8f48c7Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
107904e8f48c7Smrg	relink_command=$func_quote_arg_unquoted_result
10791c27c18e8Smrg      fi
10792c27c18e8Smrg
10793c27c18e8Smrg      # Only actually do things if not in dry run mode.
10794c27c18e8Smrg      $opt_dry_run || {
10795c27c18e8Smrg	# win32 will think the script is a binary if it has
10796c27c18e8Smrg	# a .exe suffix, so we strip it off here.
10797c27c18e8Smrg	case $output in
10798c27c18e8Smrg	  *.exe) func_stripname '' '.exe' "$output"
10799c27c18e8Smrg	         output=$func_stripname_result ;;
10800c27c18e8Smrg	esac
10801c27c18e8Smrg	# test for cygwin because mv fails w/o .exe extensions
10802c27c18e8Smrg	case $host in
10803c27c18e8Smrg	  *cygwin*)
10804c27c18e8Smrg	    exeext=.exe
10805c27c18e8Smrg	    func_stripname '' '.exe' "$outputname"
10806c27c18e8Smrg	    outputname=$func_stripname_result ;;
10807c27c18e8Smrg	  *) exeext= ;;
10808c43cc173Smrg	esac
10809c27c18e8Smrg	case $host in
10810c27c18e8Smrg	  *cygwin* | *mingw* )
10811c27c18e8Smrg	    func_dirname_and_basename "$output" "" "."
10812c27c18e8Smrg	    output_name=$func_basename_result
10813c27c18e8Smrg	    output_path=$func_dirname_result
1081448e5ce07Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
1081548e5ce07Smrg	    cwrapper=$output_path/$output_name.exe
10816c27c18e8Smrg	    $RM $cwrappersource $cwrapper
10817c27c18e8Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10818c27c18e8Smrg
10819c27c18e8Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10820c27c18e8Smrg
10821c27c18e8Smrg	    # The wrapper executable is built using the $host compiler,
10822c27c18e8Smrg	    # because it contains $host paths and files. If cross-
10823c27c18e8Smrg	    # compiling, it, like the target executable, must be
10824c27c18e8Smrg	    # executed on the $host or under an emulation environment.
10825c27c18e8Smrg	    $opt_dry_run || {
10826c27c18e8Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10827c27c18e8Smrg	      $STRIP $cwrapper
10828c27c18e8Smrg	    }
10829c43cc173Smrg
10830c27c18e8Smrg	    # Now, create the wrapper script for func_source use:
10831c27c18e8Smrg	    func_ltwrapper_scriptname $cwrapper
10832c27c18e8Smrg	    $RM $func_ltwrapper_scriptname_result
10833c27c18e8Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10834c27c18e8Smrg	    $opt_dry_run || {
10835c27c18e8Smrg	      # note: this script will not be executed, so do not chmod.
1083648e5ce07Smrg	      if test "x$build" = "x$host"; then
10837c27c18e8Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10838c27c18e8Smrg	      else
10839c27c18e8Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10840c27c18e8Smrg	      fi
10841c27c18e8Smrg	    }
10842c27c18e8Smrg	  ;;
10843c27c18e8Smrg	  * )
10844c27c18e8Smrg	    $RM $output
10845c27c18e8Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10846c43cc173Smrg
10847c27c18e8Smrg	    func_emit_wrapper no > $output
10848c27c18e8Smrg	    chmod +x $output
10849c27c18e8Smrg	  ;;
10850c27c18e8Smrg	esac
10851c27c18e8Smrg      }
10852c27c18e8Smrg      exit $EXIT_SUCCESS
10853c27c18e8Smrg      ;;
10854c27c18e8Smrg    esac
10855c43cc173Smrg
10856c27c18e8Smrg    # See if we need to build an old-fashioned archive.
10857c27c18e8Smrg    for oldlib in $oldlibs; do
10858c43cc173Smrg
1085948e5ce07Smrg      case $build_libtool_libs in
1086048e5ce07Smrg        convenience)
1086148e5ce07Smrg	  oldobjs="$libobjs_save $symfileobj"
1086248e5ce07Smrg	  addlibs=$convenience
1086344584a44Smrg	  build_libtool_libs=no
1086448e5ce07Smrg	  ;;
1086548e5ce07Smrg	module)
1086648e5ce07Smrg	  oldobjs=$libobjs_save
1086748e5ce07Smrg	  addlibs=$old_convenience
1086848e5ce07Smrg	  build_libtool_libs=no
1086948e5ce07Smrg          ;;
1087048e5ce07Smrg	*)
10871c27c18e8Smrg	  oldobjs="$old_deplibs $non_pic_objects"
1087248e5ce07Smrg	  $preload && test -f "$symfileobj" \
1087348e5ce07Smrg	    && func_append oldobjs " $symfileobj"
1087448e5ce07Smrg	  addlibs=$old_convenience
1087548e5ce07Smrg	  ;;
1087648e5ce07Smrg      esac
10877c43cc173Smrg
10878c27c18e8Smrg      if test -n "$addlibs"; then
1087948e5ce07Smrg	gentop=$output_objdir/${outputname}x
10880b789ec8aSmrg	func_append generated " $gentop"
10881c43cc173Smrg
10882c27c18e8Smrg	func_extract_archives $gentop $addlibs
10883b789ec8aSmrg	func_append oldobjs " $func_extract_archives_result"
10884c27c18e8Smrg      fi
10885c43cc173Smrg
10886c27c18e8Smrg      # Do each command in the archive commands.
1088748e5ce07Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10888c27c18e8Smrg	cmds=$old_archive_from_new_cmds
10889c27c18e8Smrg      else
10890c43cc173Smrg
10891c27c18e8Smrg	# Add any objects from preloaded convenience libraries
10892c27c18e8Smrg	if test -n "$dlprefiles"; then
1089348e5ce07Smrg	  gentop=$output_objdir/${outputname}x
10894b789ec8aSmrg	  func_append generated " $gentop"
10895c43cc173Smrg
10896c27c18e8Smrg	  func_extract_archives $gentop $dlprefiles
10897b789ec8aSmrg	  func_append oldobjs " $func_extract_archives_result"
10898c27c18e8Smrg	fi
10899c43cc173Smrg
10900c27c18e8Smrg	# POSIX demands no paths to be encoded in archives.  We have
10901c27c18e8Smrg	# to avoid creating archives with duplicate basenames if we
10902c27c18e8Smrg	# might have to extract them afterwards, e.g., when creating a
10903c27c18e8Smrg	# static archive out of a convenience library, or when linking
10904c27c18e8Smrg	# the entirety of a libtool archive into another (currently
10905c27c18e8Smrg	# not supported by libtool).
10906c27c18e8Smrg	if (for obj in $oldobjs
10907c27c18e8Smrg	    do
10908c27c18e8Smrg	      func_basename "$obj"
10909c27c18e8Smrg	      $ECHO "$func_basename_result"
10910c27c18e8Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10911c27c18e8Smrg	  :
10912c27c18e8Smrg	else
1091337eb1ca1Smrg	  echo "copying selected object files to avoid basename conflicts..."
1091448e5ce07Smrg	  gentop=$output_objdir/${outputname}x
10915b789ec8aSmrg	  func_append generated " $gentop"
10916c27c18e8Smrg	  func_mkdir_p "$gentop"
10917c27c18e8Smrg	  save_oldobjs=$oldobjs
10918c27c18e8Smrg	  oldobjs=
10919c27c18e8Smrg	  counter=1
10920c27c18e8Smrg	  for obj in $save_oldobjs
10921c27c18e8Smrg	  do
10922c27c18e8Smrg	    func_basename "$obj"
1092348e5ce07Smrg	    objbase=$func_basename_result
10924c27c18e8Smrg	    case " $oldobjs " in
10925c27c18e8Smrg	    " ") oldobjs=$obj ;;
10926c27c18e8Smrg	    *[\ /]"$objbase "*)
10927c27c18e8Smrg	      while :; do
10928c27c18e8Smrg		# Make sure we don't pick an alternate name that also
10929c27c18e8Smrg		# overlaps.
10930c27c18e8Smrg		newobj=lt$counter-$objbase
10931c27c18e8Smrg		func_arith $counter + 1
10932c27c18e8Smrg		counter=$func_arith_result
10933c27c18e8Smrg		case " $oldobjs " in
10934c27c18e8Smrg		*[\ /]"$newobj "*) ;;
10935c27c18e8Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10936c27c18e8Smrg		esac
10937c27c18e8Smrg	      done
10938c27c18e8Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10939b789ec8aSmrg	      func_append oldobjs " $gentop/$newobj"
10940c27c18e8Smrg	      ;;
10941b789ec8aSmrg	    *) func_append oldobjs " $obj" ;;
10942c27c18e8Smrg	    esac
10943c43cc173Smrg	  done
10944c43cc173Smrg	fi
10945f1ee322dSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10946f1ee322dSmrg	tool_oldlib=$func_to_tool_file_result
10947c27c18e8Smrg	eval cmds=\"$old_archive_cmds\"
10948c43cc173Smrg
10949c27c18e8Smrg	func_len " $cmds"
10950c27c18e8Smrg	len=$func_len_result
10951c27c18e8Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10952c27c18e8Smrg	  cmds=$old_archive_cmds
10953b789ec8aSmrg	elif test -n "$archiver_list_spec"; then
10954b789ec8aSmrg	  func_verbose "using command file archive linking..."
10955b789ec8aSmrg	  for obj in $oldobjs
10956b789ec8aSmrg	  do
10957b789ec8aSmrg	    func_to_tool_file "$obj"
10958b789ec8aSmrg	    $ECHO "$func_to_tool_file_result"
10959b789ec8aSmrg	  done > $output_objdir/$libname.libcmd
10960b789ec8aSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10961b789ec8aSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10962b789ec8aSmrg	  cmds=$old_archive_cmds
10963c27c18e8Smrg	else
10964c27c18e8Smrg	  # the command line is too long to link in one step, link in parts
10965c27c18e8Smrg	  func_verbose "using piecewise archive linking..."
10966c27c18e8Smrg	  save_RANLIB=$RANLIB
10967c27c18e8Smrg	  RANLIB=:
10968c27c18e8Smrg	  objlist=
10969c27c18e8Smrg	  concat_cmds=
10970c27c18e8Smrg	  save_oldobjs=$oldobjs
10971c27c18e8Smrg	  oldobjs=
10972c27c18e8Smrg	  # Is there a better way of finding the last object in the list?
10973c27c18e8Smrg	  for obj in $save_oldobjs
10974c27c18e8Smrg	  do
10975c27c18e8Smrg	    last_oldobj=$obj
10976c27c18e8Smrg	  done
10977c27c18e8Smrg	  eval test_cmds=\"$old_archive_cmds\"
10978c27c18e8Smrg	  func_len " $test_cmds"
10979c27c18e8Smrg	  len0=$func_len_result
10980c27c18e8Smrg	  len=$len0
10981c27c18e8Smrg	  for obj in $save_oldobjs
10982c27c18e8Smrg	  do
10983c27c18e8Smrg	    func_len " $obj"
10984c27c18e8Smrg	    func_arith $len + $func_len_result
10985c27c18e8Smrg	    len=$func_arith_result
10986c27c18e8Smrg	    func_append objlist " $obj"
10987c27c18e8Smrg	    if test "$len" -lt "$max_cmd_len"; then
10988c27c18e8Smrg	      :
10989c27c18e8Smrg	    else
10990c27c18e8Smrg	      # the above command should be used before it gets too long
10991c27c18e8Smrg	      oldobjs=$objlist
1099248e5ce07Smrg	      if test "$obj" = "$last_oldobj"; then
10993c27c18e8Smrg		RANLIB=$save_RANLIB
10994c27c18e8Smrg	      fi
10995c27c18e8Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1099648e5ce07Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
10997c27c18e8Smrg	      objlist=
10998c27c18e8Smrg	      len=$len0
10999c27c18e8Smrg	    fi
11000c27c18e8Smrg	  done
11001c27c18e8Smrg	  RANLIB=$save_RANLIB
11002c27c18e8Smrg	  oldobjs=$objlist
1100348e5ce07Smrg	  if test -z "$oldobjs"; then
11004c27c18e8Smrg	    eval cmds=\"\$concat_cmds\"
11005c27c18e8Smrg	  else
11006c27c18e8Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11007c27c18e8Smrg	  fi
11008c27c18e8Smrg	fi
11009c27c18e8Smrg      fi
11010c27c18e8Smrg      func_execute_cmds "$cmds" 'exit $?'
11011c43cc173Smrg    done
11012c43cc173Smrg
11013c27c18e8Smrg    test -n "$generated" && \
11014c27c18e8Smrg      func_show_eval "${RM}r$generated"
11015c43cc173Smrg
11016c27c18e8Smrg    # Now create the libtool archive.
11017c27c18e8Smrg    case $output in
11018c27c18e8Smrg    *.la)
11019c27c18e8Smrg      old_library=
1102048e5ce07Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11021c27c18e8Smrg      func_verbose "creating $output"
11022c43cc173Smrg
11023c27c18e8Smrg      # Preserve any variables that may affect compiler behavior
11024c27c18e8Smrg      for var in $variables_saved_for_relink; do
11025c27c18e8Smrg	if eval test -z \"\${$var+set}\"; then
11026c27c18e8Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11027c27c18e8Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11028c27c18e8Smrg	  relink_command="$var=; export $var; $relink_command"
11029c43cc173Smrg	else
110304e8f48c7Smrg	  func_quote_arg pretty,unquoted "$var_value"
110314e8f48c7Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11032c43cc173Smrg	fi
11033c27c18e8Smrg      done
11034c27c18e8Smrg      # Quote the link command for shipping.
110354e8f48c7Smrg      func_quote eval cd "`pwd`"
110364e8f48c7Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
110374e8f48c7Smrg      func_quote_arg pretty,unquoted "$relink_command"
110384e8f48c7Smrg      relink_command=$func_quote_arg_unquoted_result
1103948e5ce07Smrg      if test yes = "$hardcode_automatic"; then
11040c27c18e8Smrg	relink_command=
11041c27c18e8Smrg      fi
11042c43cc173Smrg
11043c27c18e8Smrg      # Only create the output if not a dry run.
11044c27c18e8Smrg      $opt_dry_run || {
11045c27c18e8Smrg	for installed in no yes; do
1104648e5ce07Smrg	  if test yes = "$installed"; then
11047c27c18e8Smrg	    if test -z "$install_libdir"; then
11048c27c18e8Smrg	      break
11049c27c18e8Smrg	    fi
1105048e5ce07Smrg	    output=$output_objdir/${outputname}i
11051c27c18e8Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11052c27c18e8Smrg	    newdependency_libs=
11053c27c18e8Smrg	    for deplib in $dependency_libs; do
11054c27c18e8Smrg	      case $deplib in
11055c27c18e8Smrg	      *.la)
11056c27c18e8Smrg		func_basename "$deplib"
1105748e5ce07Smrg		name=$func_basename_result
11058f1ee322dSmrg		func_resolve_sysroot "$deplib"
1105948e5ce07Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11060c27c18e8Smrg		test -z "$libdir" && \
1106148e5ce07Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11062b789ec8aSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11063b789ec8aSmrg		;;
11064b789ec8aSmrg	      -L*)
11065b789ec8aSmrg		func_stripname -L '' "$deplib"
11066b789ec8aSmrg		func_replace_sysroot "$func_stripname_result"
11067b789ec8aSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11068b789ec8aSmrg		;;
11069b789ec8aSmrg	      -R*)
11070b789ec8aSmrg		func_stripname -R '' "$deplib"
11071b789ec8aSmrg		func_replace_sysroot "$func_stripname_result"
11072b789ec8aSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11073c27c18e8Smrg		;;
11074b789ec8aSmrg	      *) func_append newdependency_libs " $deplib" ;;
11075c27c18e8Smrg	      esac
11076c27c18e8Smrg	    done
1107748e5ce07Smrg	    dependency_libs=$newdependency_libs
11078c27c18e8Smrg	    newdlfiles=
11079c27c18e8Smrg
11080c27c18e8Smrg	    for lib in $dlfiles; do
11081c27c18e8Smrg	      case $lib in
11082c27c18e8Smrg	      *.la)
11083c27c18e8Smrg	        func_basename "$lib"
1108448e5ce07Smrg		name=$func_basename_result
1108548e5ce07Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11086c27c18e8Smrg		test -z "$libdir" && \
1108748e5ce07Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11088b789ec8aSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11089c27c18e8Smrg		;;
11090b789ec8aSmrg	      *) func_append newdlfiles " $lib" ;;
11091c27c18e8Smrg	      esac
11092c27c18e8Smrg	    done
1109348e5ce07Smrg	    dlfiles=$newdlfiles
11094c27c18e8Smrg	    newdlprefiles=
11095c27c18e8Smrg	    for lib in $dlprefiles; do
11096c27c18e8Smrg	      case $lib in
11097c27c18e8Smrg	      *.la)
11098c27c18e8Smrg		# Only pass preopened files to the pseudo-archive (for
11099c27c18e8Smrg		# eventual linking with the app. that links it) if we
11100c27c18e8Smrg		# didn't already link the preopened objects directly into
11101c27c18e8Smrg		# the library:
11102c27c18e8Smrg		func_basename "$lib"
1110348e5ce07Smrg		name=$func_basename_result
1110448e5ce07Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11105c27c18e8Smrg		test -z "$libdir" && \
1110648e5ce07Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11107b789ec8aSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11108c27c18e8Smrg		;;
11109c27c18e8Smrg	      esac
11110c27c18e8Smrg	    done
1111148e5ce07Smrg	    dlprefiles=$newdlprefiles
11112c27c18e8Smrg	  else
11113c27c18e8Smrg	    newdlfiles=
11114c27c18e8Smrg	    for lib in $dlfiles; do
11115c27c18e8Smrg	      case $lib in
1111648e5ce07Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11117c27c18e8Smrg		*) abs=`pwd`"/$lib" ;;
11118c27c18e8Smrg	      esac
11119b789ec8aSmrg	      func_append newdlfiles " $abs"
11120c27c18e8Smrg	    done
1112148e5ce07Smrg	    dlfiles=$newdlfiles
11122c27c18e8Smrg	    newdlprefiles=
11123c27c18e8Smrg	    for lib in $dlprefiles; do
11124c27c18e8Smrg	      case $lib in
1112548e5ce07Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11126c27c18e8Smrg		*) abs=`pwd`"/$lib" ;;
11127c27c18e8Smrg	      esac
11128b789ec8aSmrg	      func_append newdlprefiles " $abs"
11129c27c18e8Smrg	    done
1113048e5ce07Smrg	    dlprefiles=$newdlprefiles
11131c27c18e8Smrg	  fi
11132c27c18e8Smrg	  $RM $output
11133c27c18e8Smrg	  # place dlname in correct position for cygwin
1113437eb1ca1Smrg	  # In fact, it would be nice if we could use this code for all target
1113537eb1ca1Smrg	  # systems that can't hard-code library paths into their executables
1113637eb1ca1Smrg	  # and that have no shared library path variable independent of PATH,
1113737eb1ca1Smrg	  # but it turns out we can't easily determine that from inspecting
1113837eb1ca1Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1113937eb1ca1Smrg	  # applies here; at the moment, that means platforms that use the PE
1114037eb1ca1Smrg	  # object format with DLL files.  See the long comment at the top of
1114137eb1ca1Smrg	  # tests/bindir.at for full details.
11142c27c18e8Smrg	  tdlname=$dlname
11143c27c18e8Smrg	  case $host,$output,$installed,$module,$dlname in
1114437eb1ca1Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1114537eb1ca1Smrg	      # If a -bindir argument was supplied, place the dll there.
1114648e5ce07Smrg	      if test -n "$bindir"; then
1114737eb1ca1Smrg		func_relative_path "$install_libdir" "$bindir"
1114848e5ce07Smrg		tdlname=$func_relative_path_result/$dlname
1114937eb1ca1Smrg	      else
1115037eb1ca1Smrg		# Otherwise fall back on heuristic.
1115137eb1ca1Smrg		tdlname=../bin/$dlname
1115237eb1ca1Smrg	      fi
1115337eb1ca1Smrg	      ;;
11154c27c18e8Smrg	  esac
11155c27c18e8Smrg	  $ECHO > $output "\
11156c27c18e8Smrg# $outputname - a libtool library file
1115748e5ce07Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11158c27c18e8Smrg#
11159c27c18e8Smrg# Please DO NOT delete this file!
11160c27c18e8Smrg# It is necessary for linking the library.
11161c43cc173Smrg
11162c27c18e8Smrg# The name that we can dlopen(3).
11163c27c18e8Smrgdlname='$tdlname'
11164c43cc173Smrg
11165c27c18e8Smrg# Names of this library.
11166c27c18e8Smrglibrary_names='$library_names'
11167c43cc173Smrg
11168c27c18e8Smrg# The name of the static archive.
11169c27c18e8Smrgold_library='$old_library'
11170c43cc173Smrg
1117148e5ce07Smrg# Linker flags that cannot go in dependency_libs.
11172c27c18e8Smrginherited_linker_flags='$new_inherited_linker_flags'
11173c43cc173Smrg
11174c27c18e8Smrg# Libraries that this one depends upon.
11175c27c18e8Smrgdependency_libs='$dependency_libs'
11176c43cc173Smrg
11177c27c18e8Smrg# Names of additional weak libraries provided by this library
11178c27c18e8Smrgweak_library_names='$weak_libs'
11179c43cc173Smrg
11180c27c18e8Smrg# Version information for $libname.
11181c27c18e8Smrgcurrent=$current
11182c27c18e8Smrgage=$age
11183c27c18e8Smrgrevision=$revision
11184c43cc173Smrg
11185c27c18e8Smrg# Is this an already installed library?
11186c27c18e8Smrginstalled=$installed
11187c43cc173Smrg
11188c27c18e8Smrg# Should we warn about portability when linking against -modules?
11189c27c18e8Smrgshouldnotlink=$module
11190c43cc173Smrg
11191c27c18e8Smrg# Files to dlopen/dlpreopen
11192c27c18e8Smrgdlopen='$dlfiles'
11193c27c18e8Smrgdlpreopen='$dlprefiles'
11194c43cc173Smrg
11195c27c18e8Smrg# Directory that this library needs to be installed in:
11196c27c18e8Smrglibdir='$install_libdir'"
1119748e5ce07Smrg	  if test no,yes = "$installed,$need_relink"; then
11198c27c18e8Smrg	    $ECHO >> $output "\
11199c27c18e8Smrgrelink_command=\"$relink_command\""
11200c27c18e8Smrg	  fi
11201c27c18e8Smrg	done
11202c27c18e8Smrg      }
11203c43cc173Smrg
11204c27c18e8Smrg      # Do a symbolic link so that the libtool archive can be found in
11205c27c18e8Smrg      # LD_LIBRARY_PATH before the program is installed.
11206c27c18e8Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11207c27c18e8Smrg      ;;
11208c27c18e8Smrg    esac
11209c27c18e8Smrg    exit $EXIT_SUCCESS
11210c27c18e8Smrg}
11211c43cc173Smrg
1121248e5ce07Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
1121348e5ce07Smrg  func_mode_link ${1+"$@"}
1121448e5ce07Smrgfi
11215c43cc173Smrg
11216c43cc173Smrg
11217c27c18e8Smrg# func_mode_uninstall arg...
11218c27c18e8Smrgfunc_mode_uninstall ()
11219c27c18e8Smrg{
1122048e5ce07Smrg    $debug_cmd
1122148e5ce07Smrg
1122248e5ce07Smrg    RM=$nonopt
11223c43cc173Smrg    files=
1122448e5ce07Smrg    rmforce=false
11225c43cc173Smrg    exit_status=0
11226c43cc173Smrg
11227c43cc173Smrg    # This variable tells wrapper scripts just to set variables rather
11228c43cc173Smrg    # than running their programs.
1122948e5ce07Smrg    libtool_install_magic=$magic
11230c43cc173Smrg
11231c43cc173Smrg    for arg
11232c43cc173Smrg    do
11233c43cc173Smrg      case $arg in
1123448e5ce07Smrg      -f) func_append RM " $arg"; rmforce=: ;;
11235b789ec8aSmrg      -*) func_append RM " $arg" ;;
11236b789ec8aSmrg      *) func_append files " $arg" ;;
11237c43cc173Smrg      esac
11238c43cc173Smrg    done
11239c43cc173Smrg
11240c27c18e8Smrg    test -z "$RM" && \
11241c27c18e8Smrg      func_fatal_help "you must specify an RM program"
11242c43cc173Smrg
11243c43cc173Smrg    rmdirs=
11244c43cc173Smrg
11245c43cc173Smrg    for file in $files; do
11246c27c18e8Smrg      func_dirname "$file" "" "."
1124748e5ce07Smrg      dir=$func_dirname_result
1124848e5ce07Smrg      if test . = "$dir"; then
1124948e5ce07Smrg	odir=$objdir
11250c43cc173Smrg      else
1125148e5ce07Smrg	odir=$dir/$objdir
11252c43cc173Smrg      fi
11253c27c18e8Smrg      func_basename "$file"
1125448e5ce07Smrg      name=$func_basename_result
1125548e5ce07Smrg      test uninstall = "$opt_mode" && odir=$dir
11256c43cc173Smrg
11257b789ec8aSmrg      # Remember odir for removal later, being careful to avoid duplicates
1125848e5ce07Smrg      if test clean = "$opt_mode"; then
11259c43cc173Smrg	case " $rmdirs " in
11260b789ec8aSmrg	  *" $odir "*) ;;
11261b789ec8aSmrg	  *) func_append rmdirs " $odir" ;;
11262c43cc173Smrg	esac
11263c43cc173Smrg      fi
11264c43cc173Smrg
11265c43cc173Smrg      # Don't error if the file doesn't exist and rm -f was used.
11266c27c18e8Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11267c27c18e8Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11268c27c18e8Smrg	 test -f "$file"; then
11269c43cc173Smrg	:
11270c43cc173Smrg      elif test -d "$file"; then
11271c43cc173Smrg	exit_status=1
11272c43cc173Smrg	continue
1127348e5ce07Smrg      elif $rmforce; then
11274c43cc173Smrg	continue
11275c43cc173Smrg      fi
11276c43cc173Smrg
1127748e5ce07Smrg      rmfiles=$file
11278c43cc173Smrg
11279c43cc173Smrg      case $name in
11280c43cc173Smrg      *.la)
11281c43cc173Smrg	# Possibly a libtool archive, so verify it.
11282c27c18e8Smrg	if func_lalib_p "$file"; then
11283c27c18e8Smrg	  func_source $dir/$name
11284c43cc173Smrg
11285c43cc173Smrg	  # Delete the libtool libraries and symlinks.
11286c43cc173Smrg	  for n in $library_names; do
11287b789ec8aSmrg	    func_append rmfiles " $odir/$n"
11288c43cc173Smrg	  done
11289b789ec8aSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11290c43cc173Smrg
1129148e5ce07Smrg	  case $opt_mode in
11292c43cc173Smrg	  clean)
11293b789ec8aSmrg	    case " $library_names " in
11294c43cc173Smrg	    *" $dlname "*) ;;
11295b789ec8aSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11296c43cc173Smrg	    esac
11297b789ec8aSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11298c43cc173Smrg	    ;;
11299c43cc173Smrg	  uninstall)
11300c43cc173Smrg	    if test -n "$library_names"; then
11301c43cc173Smrg	      # Do each command in the postuninstall commands.
1130248e5ce07Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11303c43cc173Smrg	    fi
11304c43cc173Smrg
11305c43cc173Smrg	    if test -n "$old_library"; then
11306c43cc173Smrg	      # Do each command in the old_postuninstall commands.
1130748e5ce07Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11308c43cc173Smrg	    fi
11309c43cc173Smrg	    # FIXME: should reinstall the best remaining shared library.
11310c43cc173Smrg	    ;;
11311c43cc173Smrg	  esac
11312c43cc173Smrg	fi
11313c43cc173Smrg	;;
11314c43cc173Smrg
11315c43cc173Smrg      *.lo)
11316c43cc173Smrg	# Possibly a libtool object, so verify it.
11317c27c18e8Smrg	if func_lalib_p "$file"; then
11318c43cc173Smrg
11319c43cc173Smrg	  # Read the .lo file
11320c27c18e8Smrg	  func_source $dir/$name
11321c43cc173Smrg
11322c43cc173Smrg	  # Add PIC object to the list of files to remove.
1132348e5ce07Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11324b789ec8aSmrg	    func_append rmfiles " $dir/$pic_object"
11325c43cc173Smrg	  fi
11326c43cc173Smrg
11327c43cc173Smrg	  # Add non-PIC object to the list of files to remove.
1132848e5ce07Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11329b789ec8aSmrg	    func_append rmfiles " $dir/$non_pic_object"
11330c43cc173Smrg	  fi
11331c43cc173Smrg	fi
11332c43cc173Smrg	;;
11333c43cc173Smrg
11334c43cc173Smrg      *)
1133548e5ce07Smrg	if test clean = "$opt_mode"; then
11336c43cc173Smrg	  noexename=$name
11337c43cc173Smrg	  case $file in
11338c43cc173Smrg	  *.exe)
11339c27c18e8Smrg	    func_stripname '' '.exe' "$file"
11340c27c18e8Smrg	    file=$func_stripname_result
11341c27c18e8Smrg	    func_stripname '' '.exe' "$name"
11342c27c18e8Smrg	    noexename=$func_stripname_result
11343c43cc173Smrg	    # $file with .exe has already been added to rmfiles,
11344c43cc173Smrg	    # add $file without .exe
11345b789ec8aSmrg	    func_append rmfiles " $file"
11346c43cc173Smrg	    ;;
11347c43cc173Smrg	  esac
11348c43cc173Smrg	  # Do a test to see if this is a libtool program.
11349c27c18e8Smrg	  if func_ltwrapper_p "$file"; then
11350c27c18e8Smrg	    if func_ltwrapper_executable_p "$file"; then
11351c27c18e8Smrg	      func_ltwrapper_scriptname "$file"
11352c27c18e8Smrg	      relink_command=
11353c27c18e8Smrg	      func_source $func_ltwrapper_scriptname_result
11354b789ec8aSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11355c27c18e8Smrg	    else
11356c27c18e8Smrg	      relink_command=
11357c27c18e8Smrg	      func_source $dir/$noexename
11358c27c18e8Smrg	    fi
11359c43cc173Smrg
11360c43cc173Smrg	    # note $name still contains .exe if it was in $file originally
11361c43cc173Smrg	    # as does the version of $file that was added into $rmfiles
1136248e5ce07Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
1136348e5ce07Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11364b789ec8aSmrg	      func_append rmfiles " $odir/lt-$name"
11365c43cc173Smrg	    fi
1136648e5ce07Smrg	    if test "X$noexename" != "X$name"; then
1136748e5ce07Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11368c43cc173Smrg	    fi
11369c43cc173Smrg	  fi
11370c43cc173Smrg	fi
11371c43cc173Smrg	;;
11372c43cc173Smrg      esac
11373c27c18e8Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11374c43cc173Smrg    done
11375c43cc173Smrg
1137648e5ce07Smrg    # Try to remove the $objdir's in the directories where we deleted files
11377c43cc173Smrg    for dir in $rmdirs; do
11378c43cc173Smrg      if test -d "$dir"; then
11379c27c18e8Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11380c43cc173Smrg      fi
11381c43cc173Smrg    done
11382c43cc173Smrg
11383c43cc173Smrg    exit $exit_status
11384c27c18e8Smrg}
11385c43cc173Smrg
1138648e5ce07Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
1138748e5ce07Smrg  func_mode_uninstall ${1+"$@"}
1138848e5ce07Smrgfi
11389c43cc173Smrg
11390b789ec8aSmrgtest -z "$opt_mode" && {
1139148e5ce07Smrg  help=$generic_help
11392c27c18e8Smrg  func_fatal_help "you must specify a MODE"
11393c27c18e8Smrg}
11394c27c18e8Smrg
11395c27c18e8Smrgtest -z "$exec_cmd" && \
1139648e5ce07Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11397c43cc173Smrg
11398c43cc173Smrgif test -n "$exec_cmd"; then
11399c27c18e8Smrg  eval exec "$exec_cmd"
11400c43cc173Smrg  exit $EXIT_FAILURE
11401c43cc173Smrgfi
11402c43cc173Smrg
11403c27c18e8Smrgexit $exit_status
11404c43cc173Smrg
11405c43cc173Smrg
11406c43cc173Smrg# The TAGs below are defined such that we never get into a situation
1140748e5ce07Smrg# where we disable both kinds of libraries.  Given conflicting
11408c43cc173Smrg# choices, we go for a static library, that is the most portable,
11409c43cc173Smrg# since we can't tell whether shared libraries were disabled because
11410c43cc173Smrg# the user asked for that or because the platform doesn't support
11411c43cc173Smrg# them.  This is particularly important on AIX, because we don't
11412c43cc173Smrg# support having both static and shared libraries enabled at the same
11413c43cc173Smrg# time on that platform, so we default to a shared-only configuration.
11414c43cc173Smrg# If a disable-shared tag is given, we'll fallback to a static-only
11415c43cc173Smrg# configuration.  But we'll never go from static-only to shared-only.
11416c43cc173Smrg
11417c43cc173Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11418c27c18e8Smrgbuild_libtool_libs=no
11419c27c18e8Smrgbuild_old_libs=yes
11420c43cc173Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
11421c43cc173Smrg
11422c43cc173Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11423c27c18e8Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11424c43cc173Smrg# ### END LIBTOOL TAG CONFIG: disable-static
11425c43cc173Smrg
11426c43cc173Smrg# Local Variables:
11427c43cc173Smrg# mode:shell-script
11428c43cc173Smrg# sh-indentation:2
11429c43cc173Smrg# End:
11430