ltmain.sh revision 25dbecb6
125dbecb6Smrg#! /usr/bin/env sh
225dbecb6Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
325dbecb6Smrg##               by inline-source v2019-02-19.15
4b68e1f86Smrg
525dbecb6Smrg# libtool (GNU libtool) 2.4.7
625dbecb6Smrg# Provide generalized library-building support services.
7b68e1f86Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8b68e1f86Smrg
925dbecb6Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10b68e1f86Smrg# This is free software; see the source for copying conditions.  There is NO
11b68e1f86Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12b68e1f86Smrg
13b68e1f86Smrg# GNU Libtool is free software; you can redistribute it and/or modify
146df26cacSmrg# it under the terms of the GNU General Public License as published by
156df26cacSmrg# the Free Software Foundation; either version 2 of the License, or
166df26cacSmrg# (at your option) any later version.
176df26cacSmrg#
18b68e1f86Smrg# As a special exception to the GNU General Public License,
19b68e1f86Smrg# if you distribute this file as part of a program or library that
20b68e1f86Smrg# is built using GNU Libtool, you may include this file under the
21b68e1f86Smrg# same distribution terms that you use for the rest of that program.
22b68e1f86Smrg#
23b68e1f86Smrg# GNU Libtool is distributed in the hope that it will be useful, but
246df26cacSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
256df26cacSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
266df26cacSmrg# General Public License for more details.
276df26cacSmrg#
286df26cacSmrg# You should have received a copy of the GNU General Public License
2925dbecb6Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
306df26cacSmrg
3125dbecb6Smrg
3225dbecb6SmrgPROGRAM=libtool
3325dbecb6SmrgPACKAGE=libtool
3425dbecb6SmrgVERSION=2.4.7
3525dbecb6Smrgpackage_revision=2.4.7
3625dbecb6Smrg
3725dbecb6Smrg
3825dbecb6Smrg## ------ ##
3925dbecb6Smrg## Usage. ##
4025dbecb6Smrg## ------ ##
4125dbecb6Smrg
4225dbecb6Smrg# Run './libtool --help' for help with using this script from the
4325dbecb6Smrg# command line.
4425dbecb6Smrg
4525dbecb6Smrg
4625dbecb6Smrg## ------------------------------- ##
4725dbecb6Smrg## User overridable command paths. ##
4825dbecb6Smrg## ------------------------------- ##
4925dbecb6Smrg
5025dbecb6Smrg# After configure completes, it has a better idea of some of the
5125dbecb6Smrg# shell tools we need than the defaults used by the functions shared
5225dbecb6Smrg# with bootstrap, so set those here where they can still be over-
5325dbecb6Smrg# ridden by the user, but otherwise take precedence.
5425dbecb6Smrg
5525dbecb6Smrg: ${AUTOCONF="autoconf"}
5625dbecb6Smrg: ${AUTOMAKE="automake"}
5725dbecb6Smrg
5825dbecb6Smrg
5925dbecb6Smrg## -------------------------- ##
6025dbecb6Smrg## Source external libraries. ##
6125dbecb6Smrg## -------------------------- ##
6225dbecb6Smrg
6325dbecb6Smrg# Much of our low-level functionality needs to be sourced from external
6425dbecb6Smrg# libraries, which are installed to $pkgauxdir.
6525dbecb6Smrg
6625dbecb6Smrg# Set a version string for this script.
6725dbecb6Smrgscriptversion=2019-02-19.15; # UTC
6825dbecb6Smrg
6925dbecb6Smrg# General shell script boiler plate, and helper functions.
7025dbecb6Smrg# Written by Gary V. Vaughan, 2004
7125dbecb6Smrg
7225dbecb6Smrg# This is free software.  There is NO warranty; not even for
7325dbecb6Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74b68e1f86Smrg#
7525dbecb6Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76b68e1f86Smrg#
7725dbecb6Smrg# This file is dual licensed under the terms of the MIT license
7825dbecb6Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
7925dbecb6Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
8025dbecb6Smrg# these licenses when using or redistributing this software or any of
8125dbecb6Smrg# the files within it.  See the URLs above, or the file `LICENSE`
8225dbecb6Smrg# included in the Bootstrap distribution for the full license texts.
8325dbecb6Smrg
8425dbecb6Smrg# Please report bugs or propose patches to:
8525dbecb6Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
8625dbecb6Smrg
8725dbecb6Smrg
8825dbecb6Smrg## ------ ##
8925dbecb6Smrg## Usage. ##
9025dbecb6Smrg## ------ ##
9125dbecb6Smrg
9225dbecb6Smrg# Evaluate this file near the top of your script to gain access to
9325dbecb6Smrg# the functions and variables defined here:
94b68e1f86Smrg#
9525dbecb6Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96b68e1f86Smrg#
9725dbecb6Smrg# If you need to override any of the default environment variable
9825dbecb6Smrg# settings, do that before evaluating this file.
996df26cacSmrg
10016fd1166Smrg
10125dbecb6Smrg## -------------------- ##
10225dbecb6Smrg## Shell normalisation. ##
10325dbecb6Smrg## -------------------- ##
10425dbecb6Smrg
10525dbecb6Smrg# Some shells need a little help to be as Bourne compatible as possible.
10625dbecb6Smrg# Before doing anything else, make sure all that help has been provided!
10725dbecb6Smrg
10825dbecb6SmrgDUALCASE=1; export DUALCASE # for MKS sh
10925dbecb6Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
11016fd1166Smrg  emulate sh
11116fd1166Smrg  NULLCMD=:
11225dbecb6Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
11316fd1166Smrg  # is contrary to our usage.  Disable this feature.
11416fd1166Smrg  alias -g '${1+"$@"}'='"$@"'
1156df26cacSmrg  setopt NO_GLOB_SUBST
11616fd1166Smrgelse
11725dbecb6Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1186df26cacSmrgfi
1193bfa90b6Smrg
12025dbecb6Smrg# NLS nuisances: We save the old values in case they are required later.
12125dbecb6Smrg_G_user_locale=
12225dbecb6Smrg_G_safe_locale=
12325dbecb6Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
12416fd1166Smrgdo
12525dbecb6Smrg  eval "if test set = \"\${$_G_var+set}\"; then
12625dbecb6Smrg          save_$_G_var=\$$_G_var
12725dbecb6Smrg          $_G_var=C
12825dbecb6Smrg	  export $_G_var
12925dbecb6Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
13025dbecb6Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
13116fd1166Smrg	fi"
13216fd1166Smrgdone
13325dbecb6Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
13425dbecb6Smrg# in case the environment reset is needed later and the $save_* variant is not
13525dbecb6Smrg# defined (see the code above).
1363bfa90b6SmrgLC_ALL=C
1373bfa90b6SmrgLANGUAGE=C
1383bfa90b6Smrgexport LANGUAGE LC_ALL
1396df26cacSmrg
14025dbecb6Smrg# Make sure IFS has a sensible default
14125dbecb6Smrgsp=' '
14225dbecb6Smrgnl='
14325dbecb6Smrg'
14425dbecb6SmrgIFS="$sp	$nl"
14525dbecb6Smrg
14625dbecb6Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
14725dbecb6Smrgif test "${PATH_SEPARATOR+set}" != set; then
14825dbecb6Smrg  PATH_SEPARATOR=:
14925dbecb6Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
15025dbecb6Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
15125dbecb6Smrg      PATH_SEPARATOR=';'
15225dbecb6Smrg  }
15325dbecb6Smrgfi
154b68e1f86Smrg
155b68e1f86Smrg
15625dbecb6Smrg# func_unset VAR
15725dbecb6Smrg# --------------
15825dbecb6Smrg# Portably unset VAR.
15925dbecb6Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
16025dbecb6Smrg# status if VAR is already unset, which might be problematic if the
16125dbecb6Smrg# statement is used at the end of a function (thus poisoning its return
16225dbecb6Smrg# value) or when 'set -e' is active (causing even a spurious abort of
16325dbecb6Smrg# the script in this case).
16425dbecb6Smrgfunc_unset ()
16525dbecb6Smrg{
16625dbecb6Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
16725dbecb6Smrg}
168b68e1f86Smrg
169b68e1f86Smrg
17025dbecb6Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
17125dbecb6Smrgfunc_unset CDPATH
172b68e1f86Smrg
17325dbecb6Smrg# Make sure ${,E,F}GREP behave sanely.
17425dbecb6Smrgfunc_unset GREP_OPTIONS
175b68e1f86Smrg
176b68e1f86Smrg
17725dbecb6Smrg## ------------------------- ##
17825dbecb6Smrg## Locate command utilities. ##
17925dbecb6Smrg## ------------------------- ##
1806df26cacSmrg
181b68e1f86Smrg
18225dbecb6Smrg# func_executable_p FILE
18325dbecb6Smrg# ----------------------
18425dbecb6Smrg# Check that FILE is an executable regular file.
18525dbecb6Smrgfunc_executable_p ()
1863bfa90b6Smrg{
18725dbecb6Smrg    test -f "$1" && test -x "$1"
18825dbecb6Smrg}
1893bfa90b6Smrg
1903bfa90b6Smrg
19125dbecb6Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
19225dbecb6Smrg# --------------------------------------------
19325dbecb6Smrg# Search for either a program that responds to --version with output
19425dbecb6Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
19525dbecb6Smrg# trying all the directories in PATH with each of the elements of
19625dbecb6Smrg# PROGS_LIST.
19725dbecb6Smrg#
19825dbecb6Smrg# CHECK_FUNC should accept the path to a candidate program, and
19925dbecb6Smrg# set $func_check_prog_result if it truncates its output less than
20025dbecb6Smrg# $_G_path_prog_max characters.
20125dbecb6Smrgfunc_path_progs ()
2023bfa90b6Smrg{
20325dbecb6Smrg    _G_progs_list=$1
20425dbecb6Smrg    _G_check_func=$2
20525dbecb6Smrg    _G_PATH=${3-"$PATH"}
20625dbecb6Smrg
20725dbecb6Smrg    _G_path_prog_max=0
20825dbecb6Smrg    _G_path_prog_found=false
20925dbecb6Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
21025dbecb6Smrg    for _G_dir in $_G_PATH; do
21125dbecb6Smrg      IFS=$_G_save_IFS
21225dbecb6Smrg      test -z "$_G_dir" && _G_dir=.
21325dbecb6Smrg      for _G_prog_name in $_G_progs_list; do
21425dbecb6Smrg        for _exeext in '' .EXE; do
21525dbecb6Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
21625dbecb6Smrg          func_executable_p "$_G_path_prog" || continue
21725dbecb6Smrg          case `"$_G_path_prog" --version 2>&1` in
21825dbecb6Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
21925dbecb6Smrg            *)     $_G_check_func $_G_path_prog
22025dbecb6Smrg		   func_path_progs_result=$func_check_prog_result
22125dbecb6Smrg		   ;;
22225dbecb6Smrg          esac
22325dbecb6Smrg          $_G_path_prog_found && break 3
22425dbecb6Smrg        done
22525dbecb6Smrg      done
22625dbecb6Smrg    done
22725dbecb6Smrg    IFS=$_G_save_IFS
22825dbecb6Smrg    test -z "$func_path_progs_result" && {
22925dbecb6Smrg      echo "no acceptable sed could be found in \$PATH" >&2
23025dbecb6Smrg      exit 1
23125dbecb6Smrg    }
23225dbecb6Smrg}
2333bfa90b6Smrg
2343bfa90b6Smrg
23525dbecb6Smrg# We want to be able to use the functions in this file before configure
23625dbecb6Smrg# has figured out where the best binaries are kept, which means we have
23725dbecb6Smrg# to search for them ourselves - except when the results are already set
23825dbecb6Smrg# where we skip the searches.
2393bfa90b6Smrg
24025dbecb6Smrg# Unless the user overrides by setting SED, search the path for either GNU
24125dbecb6Smrg# sed, or the sed that truncates its output the least.
24225dbecb6Smrgtest -z "$SED" && {
24325dbecb6Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
24425dbecb6Smrg  for _G_i in 1 2 3 4 5 6 7; do
24525dbecb6Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
24625dbecb6Smrg  done
24725dbecb6Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
24825dbecb6Smrg  _G_sed_script=
2493bfa90b6Smrg
25025dbecb6Smrg  func_check_prog_sed ()
25125dbecb6Smrg  {
25225dbecb6Smrg    _G_path_prog=$1
2533bfa90b6Smrg
25425dbecb6Smrg    _G_count=0
25525dbecb6Smrg    printf 0123456789 >conftest.in
25625dbecb6Smrg    while :
25725dbecb6Smrg    do
25825dbecb6Smrg      cat conftest.in conftest.in >conftest.tmp
25925dbecb6Smrg      mv conftest.tmp conftest.in
26025dbecb6Smrg      cp conftest.in conftest.nl
26125dbecb6Smrg      echo '' >> conftest.nl
26225dbecb6Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
26325dbecb6Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
26425dbecb6Smrg      _G_count=`expr $_G_count + 1`
26525dbecb6Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
26625dbecb6Smrg        # Best one so far, save it but keep looking for a better one
26725dbecb6Smrg        func_check_prog_result=$_G_path_prog
26825dbecb6Smrg        _G_path_prog_max=$_G_count
26925dbecb6Smrg      fi
27025dbecb6Smrg      # 10*(2^10) chars as input seems more than enough
27125dbecb6Smrg      test 10 -lt "$_G_count" && break
27225dbecb6Smrg    done
27325dbecb6Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
27425dbecb6Smrg  }
2753bfa90b6Smrg
27625dbecb6Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
27725dbecb6Smrg  rm -f conftest.sed
27825dbecb6Smrg  SED=$func_path_progs_result
27925dbecb6Smrg}
2803bfa90b6Smrg
28125dbecb6Smrg
28225dbecb6Smrg# Unless the user overrides by setting GREP, search the path for either GNU
28325dbecb6Smrg# grep, or the grep that truncates its output the least.
28425dbecb6Smrgtest -z "$GREP" && {
28525dbecb6Smrg  func_check_prog_grep ()
28625dbecb6Smrg  {
28725dbecb6Smrg    _G_path_prog=$1
28825dbecb6Smrg
28925dbecb6Smrg    _G_count=0
29025dbecb6Smrg    _G_path_prog_max=0
29125dbecb6Smrg    printf 0123456789 >conftest.in
29225dbecb6Smrg    while :
29325dbecb6Smrg    do
29425dbecb6Smrg      cat conftest.in conftest.in >conftest.tmp
29525dbecb6Smrg      mv conftest.tmp conftest.in
29625dbecb6Smrg      cp conftest.in conftest.nl
29725dbecb6Smrg      echo 'GREP' >> conftest.nl
29825dbecb6Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
29925dbecb6Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
30025dbecb6Smrg      _G_count=`expr $_G_count + 1`
30125dbecb6Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
30225dbecb6Smrg        # Best one so far, save it but keep looking for a better one
30325dbecb6Smrg        func_check_prog_result=$_G_path_prog
30425dbecb6Smrg        _G_path_prog_max=$_G_count
30525dbecb6Smrg      fi
30625dbecb6Smrg      # 10*(2^10) chars as input seems more than enough
30725dbecb6Smrg      test 10 -lt "$_G_count" && break
30825dbecb6Smrg    done
30925dbecb6Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
31025dbecb6Smrg  }
31125dbecb6Smrg
31225dbecb6Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
31325dbecb6Smrg  GREP=$func_path_progs_result
31425dbecb6Smrg}
31525dbecb6Smrg
31625dbecb6Smrg
31725dbecb6Smrg## ------------------------------- ##
31825dbecb6Smrg## User overridable command paths. ##
31925dbecb6Smrg## ------------------------------- ##
32025dbecb6Smrg
32125dbecb6Smrg# All uppercase variable names are used for environment variables.  These
32225dbecb6Smrg# variables can be overridden by the user before calling a script that
32325dbecb6Smrg# uses them if a suitable command of that name is not already available
32425dbecb6Smrg# in the command search PATH.
32525dbecb6Smrg
32625dbecb6Smrg: ${CP="cp -f"}
32725dbecb6Smrg: ${ECHO="printf %s\n"}
32825dbecb6Smrg: ${EGREP="$GREP -E"}
32925dbecb6Smrg: ${FGREP="$GREP -F"}
33025dbecb6Smrg: ${LN_S="ln -s"}
33125dbecb6Smrg: ${MAKE="make"}
33225dbecb6Smrg: ${MKDIR="mkdir"}
33325dbecb6Smrg: ${MV="mv -f"}
33425dbecb6Smrg: ${RM="rm -f"}
33525dbecb6Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
33625dbecb6Smrg
33725dbecb6Smrg
33825dbecb6Smrg## -------------------- ##
33925dbecb6Smrg## Useful sed snippets. ##
34025dbecb6Smrg## -------------------- ##
34125dbecb6Smrg
34225dbecb6Smrgsed_dirname='s|/[^/]*$||'
34325dbecb6Smrgsed_basename='s|^.*/||'
34425dbecb6Smrg
34525dbecb6Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
34625dbecb6Smrg# metacharacters that are still active within double-quoted strings.
34725dbecb6Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
34825dbecb6Smrg
34925dbecb6Smrg# Same as above, but do not quote variable references.
35025dbecb6Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
35125dbecb6Smrg
35225dbecb6Smrg# Sed substitution that turns a string into a regex matching for the
35325dbecb6Smrg# string literally.
35425dbecb6Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
35525dbecb6Smrg
35625dbecb6Smrg# Sed substitution that converts a w32 file name or path
35725dbecb6Smrg# that contains forward slashes, into one that contains
35825dbecb6Smrg# (escaped) backslashes.  A very naive implementation.
35925dbecb6Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
36025dbecb6Smrg
36125dbecb6Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
36225dbecb6Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
36325dbecb6Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
36425dbecb6Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
36525dbecb6Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
36625dbecb6Smrg_G_bs='\\'
36725dbecb6Smrg_G_bs2='\\\\'
36825dbecb6Smrg_G_bs4='\\\\\\\\'
36925dbecb6Smrg_G_dollar='\$'
37025dbecb6Smrgsed_double_backslash="\
37125dbecb6Smrg  s/$_G_bs4/&\\
37225dbecb6Smrg/g
37325dbecb6Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
37425dbecb6Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
37525dbecb6Smrg  s/\n//g"
37625dbecb6Smrg
37725dbecb6Smrg# require_check_ifs_backslash
37825dbecb6Smrg# ---------------------------
37925dbecb6Smrg# Check if we can use backslash as IFS='\' separator, and set
38025dbecb6Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
38125dbecb6Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
38225dbecb6Smrgfunc_require_check_ifs_backslash ()
3833bfa90b6Smrg{
38425dbecb6Smrg  _G_save_IFS=$IFS
38525dbecb6Smrg  IFS='\'
38625dbecb6Smrg  _G_check_ifs_backshlash='a\\b'
38725dbecb6Smrg  for _G_i in $_G_check_ifs_backshlash
38825dbecb6Smrg  do
38925dbecb6Smrg  case $_G_i in
39025dbecb6Smrg  a)
39125dbecb6Smrg    check_ifs_backshlash_broken=false
3923bfa90b6Smrg    ;;
39325dbecb6Smrg  '')
39425dbecb6Smrg    break
3953bfa90b6Smrg    ;;
39625dbecb6Smrg  *)
39725dbecb6Smrg    check_ifs_backshlash_broken=:
39825dbecb6Smrg    break
3993bfa90b6Smrg    ;;
4003bfa90b6Smrg  esac
4013bfa90b6Smrg  done
40225dbecb6Smrg  IFS=$_G_save_IFS
40325dbecb6Smrg  require_check_ifs_backslash=:
404b68e1f86Smrg}
4056df26cacSmrg
4063bfa90b6Smrg
40725dbecb6Smrg## ----------------- ##
40825dbecb6Smrg## Global variables. ##
40925dbecb6Smrg## ----------------- ##
410b68e1f86Smrg
41125dbecb6Smrg# Except for the global variables explicitly listed below, the following
41225dbecb6Smrg# functions in the '^func_' namespace, and the '^require_' namespace
41325dbecb6Smrg# variables initialised in the 'Resource management' section, sourcing
41425dbecb6Smrg# this file will not pollute your global namespace with anything
41525dbecb6Smrg# else. There's no portable way to scope variables in Bourne shell
41625dbecb6Smrg# though, so actually running these functions will sometimes place
41725dbecb6Smrg# results into a variable named after the function, and often use
41825dbecb6Smrg# temporary variables in the '^_G_' namespace. If you are careful to
41925dbecb6Smrg# avoid using those namespaces casually in your sourcing script, things
42025dbecb6Smrg# should continue to work as you expect. And, of course, you can freely
42125dbecb6Smrg# overwrite any of the functions or variables defined here before
42225dbecb6Smrg# calling anything to customize them.
42325dbecb6Smrg
42425dbecb6SmrgEXIT_SUCCESS=0
42525dbecb6SmrgEXIT_FAILURE=1
42625dbecb6SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
42725dbecb6SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
42825dbecb6Smrg
42925dbecb6Smrg# Allow overriding, eg assuming that you follow the convention of
43025dbecb6Smrg# putting '$debug_cmd' at the start of all your functions, you can get
43125dbecb6Smrg# bash to show function call trace with:
43225dbecb6Smrg#
43325dbecb6Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
43425dbecb6Smrgdebug_cmd=${debug_cmd-":"}
43525dbecb6Smrgexit_cmd=:
43625dbecb6Smrg
43725dbecb6Smrg# By convention, finish your script with:
43825dbecb6Smrg#
43925dbecb6Smrg#    exit $exit_status
44025dbecb6Smrg#
44125dbecb6Smrg# so that you can set exit_status to non-zero if you want to indicate
44225dbecb6Smrg# something went wrong during execution without actually bailing out at
44325dbecb6Smrg# the point of failure.
44425dbecb6Smrgexit_status=$EXIT_SUCCESS
445b68e1f86Smrg
44625dbecb6Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
44725dbecb6Smrg# is ksh but when the shell is invoked as "sh" and the current value of
44825dbecb6Smrg# the _XPG environment variable is not equal to 1 (one), the special
44925dbecb6Smrg# positional parameter $0, within a function call, is the name of the
45025dbecb6Smrg# function.
45125dbecb6Smrgprogpath=$0
45225dbecb6Smrg
45325dbecb6Smrg# The name of this program.
45425dbecb6Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455b68e1f86Smrg
45625dbecb6Smrg# Make sure we have an absolute progpath for reexecution:
457b68e1f86Smrgcase $progpath in
458b68e1f86Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459b68e1f86Smrg  *[\\/]*)
46025dbecb6Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461b68e1f86Smrg     progdir=`cd "$progdir" && pwd`
46225dbecb6Smrg     progpath=$progdir/$progname
463b68e1f86Smrg     ;;
464b68e1f86Smrg  *)
46525dbecb6Smrg     _G_IFS=$IFS
4663bfa90b6Smrg     IFS=${PATH_SEPARATOR-:}
467b68e1f86Smrg     for progdir in $PATH; do
46825dbecb6Smrg       IFS=$_G_IFS
469b68e1f86Smrg       test -x "$progdir/$progname" && break
470b68e1f86Smrg     done
47125dbecb6Smrg     IFS=$_G_IFS
472b68e1f86Smrg     test -n "$progdir" || progdir=`pwd`
47325dbecb6Smrg     progpath=$progdir/$progname
474b68e1f86Smrg     ;;
475b68e1f86Smrgesac
476b68e1f86Smrg
477b68e1f86Smrg
47825dbecb6Smrg## ----------------- ##
47925dbecb6Smrg## Standard options. ##
48025dbecb6Smrg## ----------------- ##
4813bfa90b6Smrg
48225dbecb6Smrg# The following options affect the operation of the functions defined
48325dbecb6Smrg# below, and should be set appropriately depending on run-time para-
48425dbecb6Smrg# meters passed on the command line.
485b68e1f86Smrg
486b68e1f86Smrgopt_dry_run=false
487b68e1f86Smrgopt_quiet=false
488b68e1f86Smrgopt_verbose=false
489b68e1f86Smrg
49025dbecb6Smrg# Categories 'all' and 'none' are always available.  Append any others
49125dbecb6Smrg# you will pass as the first argument to func_warning from your own
49225dbecb6Smrg# code.
49325dbecb6Smrgwarning_categories=
494b68e1f86Smrg
49525dbecb6Smrg# By default, display warnings according to 'opt_warning_types'.  Set
49625dbecb6Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
49725dbecb6Smrg# treat the next displayed warning as a fatal error.
49825dbecb6Smrgwarning_func=func_warn_and_continue
499b68e1f86Smrg
50025dbecb6Smrg# Set to 'all' to display all warnings, 'none' to suppress all
50125dbecb6Smrg# warnings, or a space delimited list of some subset of
50225dbecb6Smrg# 'warning_categories' to display only the listed warnings.
50325dbecb6Smrgopt_warning_types=all
504b68e1f86Smrg
5053bfa90b6Smrg
50625dbecb6Smrg## -------------------- ##
50725dbecb6Smrg## Resource management. ##
50825dbecb6Smrg## -------------------- ##
509b68e1f86Smrg
51025dbecb6Smrg# This section contains definitions for functions that each ensure a
51125dbecb6Smrg# particular resource (a file, or a non-empty configuration variable for
51225dbecb6Smrg# example) is available, and if appropriate to extract default values
51325dbecb6Smrg# from pertinent package files. Call them using their associated
51425dbecb6Smrg# 'require_*' variable to ensure that they are executed, at most, once.
51525dbecb6Smrg#
51625dbecb6Smrg# It's entirely deliberate that calling these functions can set
51725dbecb6Smrg# variables that don't obey the namespace limitations obeyed by the rest
51825dbecb6Smrg# of this file, in order that that they be as useful as possible to
51925dbecb6Smrg# callers.
520b68e1f86Smrg
521b68e1f86Smrg
52225dbecb6Smrg# require_term_colors
52325dbecb6Smrg# -------------------
52425dbecb6Smrg# Allow display of bold text on terminals that support it.
52525dbecb6Smrgrequire_term_colors=func_require_term_colors
52625dbecb6Smrgfunc_require_term_colors ()
527b68e1f86Smrg{
52825dbecb6Smrg    $debug_cmd
52925dbecb6Smrg
53025dbecb6Smrg    test -t 1 && {
53125dbecb6Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
53225dbecb6Smrg      # precedence, because most terminfo databases neglect to describe
53325dbecb6Smrg      # whether color sequences are supported.
53425dbecb6Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
53525dbecb6Smrg
53625dbecb6Smrg      if test 1 = "$USE_ANSI_COLORS"; then
53725dbecb6Smrg        # Standard ANSI escape sequences
53825dbecb6Smrg        tc_reset='[0m'
53925dbecb6Smrg        tc_bold='[1m';   tc_standout='[7m'
54025dbecb6Smrg        tc_red='[31m';   tc_green='[32m'
54125dbecb6Smrg        tc_blue='[34m';  tc_cyan='[36m'
54225dbecb6Smrg      else
54325dbecb6Smrg        # Otherwise trust the terminfo database after all.
54425dbecb6Smrg        test -n "`tput sgr0 2>/dev/null`" && {
54525dbecb6Smrg          tc_reset=`tput sgr0`
54625dbecb6Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
54725dbecb6Smrg          tc_standout=$tc_bold
54825dbecb6Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
54925dbecb6Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
55025dbecb6Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
55125dbecb6Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
55225dbecb6Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
55325dbecb6Smrg        }
55425dbecb6Smrg      fi
55525dbecb6Smrg    }
556b68e1f86Smrg
55725dbecb6Smrg    require_term_colors=:
558b68e1f86Smrg}
559b68e1f86Smrg
560b68e1f86Smrg
56125dbecb6Smrg## ----------------- ##
56225dbecb6Smrg## Function library. ##
56325dbecb6Smrg## ----------------- ##
564b68e1f86Smrg
56525dbecb6Smrg# This section contains a variety of useful functions to call in your
56625dbecb6Smrg# scripts. Take note of the portable wrappers for features provided by
56725dbecb6Smrg# some modern shells, which will fall back to slower equivalents on
56825dbecb6Smrg# less featureful shells.
569b68e1f86Smrg
57025dbecb6Smrg
57125dbecb6Smrg# func_append VAR VALUE
57225dbecb6Smrg# ---------------------
57325dbecb6Smrg# Append VALUE onto the existing contents of VAR.
57425dbecb6Smrg
57525dbecb6Smrg  # We should try to minimise forks, especially on Windows where they are
57625dbecb6Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
57725dbecb6Smrg  # being used:
57825dbecb6Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
57925dbecb6Smrg    : ${_G_HAVE_ARITH_OP="yes"}
58025dbecb6Smrg    : ${_G_HAVE_XSI_OPS="yes"}
58125dbecb6Smrg    # The += operator was introduced in bash 3.1
58225dbecb6Smrg    case $BASH_VERSION in
58325dbecb6Smrg      [12].* | 3.0 | 3.0*) ;;
58425dbecb6Smrg      *)
58525dbecb6Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
58625dbecb6Smrg        ;;
58725dbecb6Smrg    esac
58825dbecb6Smrg  fi
58925dbecb6Smrg
59025dbecb6Smrg  # _G_HAVE_PLUSEQ_OP
59125dbecb6Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
59225dbecb6Smrg  # useable or anything else if it does not work.
59325dbecb6Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
59425dbecb6Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
59525dbecb6Smrg    && _G_HAVE_PLUSEQ_OP=yes
59625dbecb6Smrg
59725dbecb6Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
59825dbecb6Smrgthen
59925dbecb6Smrg  # This is an XSI compatible shell, allowing a faster implementation...
60025dbecb6Smrg  eval 'func_append ()
60125dbecb6Smrg  {
60225dbecb6Smrg    $debug_cmd
60325dbecb6Smrg
60425dbecb6Smrg    eval "$1+=\$2"
60525dbecb6Smrg  }'
60625dbecb6Smrgelse
60725dbecb6Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
60825dbecb6Smrg  func_append ()
60925dbecb6Smrg  {
61025dbecb6Smrg    $debug_cmd
61125dbecb6Smrg
61225dbecb6Smrg    eval "$1=\$$1\$2"
61325dbecb6Smrg  }
61425dbecb6Smrgfi
61525dbecb6Smrg
61625dbecb6Smrg
61725dbecb6Smrg# func_append_quoted VAR VALUE
61825dbecb6Smrg# ----------------------------
61925dbecb6Smrg# Quote VALUE and append to the end of shell variable VAR, separated
62025dbecb6Smrg# by a space.
62125dbecb6Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
62225dbecb6Smrg  eval 'func_append_quoted ()
62325dbecb6Smrg  {
62425dbecb6Smrg    $debug_cmd
62525dbecb6Smrg
62625dbecb6Smrg    func_quote_arg pretty "$2"
62725dbecb6Smrg    eval "$1+=\\ \$func_quote_arg_result"
62825dbecb6Smrg  }'
62925dbecb6Smrgelse
63025dbecb6Smrg  func_append_quoted ()
63125dbecb6Smrg  {
63225dbecb6Smrg    $debug_cmd
63325dbecb6Smrg
63425dbecb6Smrg    func_quote_arg pretty "$2"
63525dbecb6Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
63625dbecb6Smrg  }
63725dbecb6Smrgfi
63825dbecb6Smrg
63925dbecb6Smrg
64025dbecb6Smrg# func_append_uniq VAR VALUE
64125dbecb6Smrg# --------------------------
64225dbecb6Smrg# Append unique VALUE onto the existing contents of VAR, assuming
64325dbecb6Smrg# entries are delimited by the first character of VALUE.  For example:
64425dbecb6Smrg#
64525dbecb6Smrg#   func_append_uniq options " --another-option option-argument"
64625dbecb6Smrg#
64725dbecb6Smrg# will only append to $options if " --another-option option-argument "
64825dbecb6Smrg# is not already present somewhere in $options already (note spaces at
64925dbecb6Smrg# each end implied by leading space in second argument).
65025dbecb6Smrgfunc_append_uniq ()
65125dbecb6Smrg{
65225dbecb6Smrg    $debug_cmd
65325dbecb6Smrg
65425dbecb6Smrg    eval _G_current_value='`$ECHO $'$1'`'
65525dbecb6Smrg    _G_delim=`expr "$2" : '\(.\)'`
65625dbecb6Smrg
65725dbecb6Smrg    case $_G_delim$_G_current_value$_G_delim in
65825dbecb6Smrg      *"$2$_G_delim"*) ;;
65925dbecb6Smrg      *) func_append "$@" ;;
66025dbecb6Smrg    esac
66125dbecb6Smrg}
66225dbecb6Smrg
66325dbecb6Smrg
66425dbecb6Smrg# func_arith TERM...
66525dbecb6Smrg# ------------------
66625dbecb6Smrg# Set func_arith_result to the result of evaluating TERMs.
66725dbecb6Smrg  test -z "$_G_HAVE_ARITH_OP" \
66825dbecb6Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
66925dbecb6Smrg    && _G_HAVE_ARITH_OP=yes
67025dbecb6Smrg
67125dbecb6Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
67225dbecb6Smrg  eval 'func_arith ()
67325dbecb6Smrg  {
67425dbecb6Smrg    $debug_cmd
67525dbecb6Smrg
67625dbecb6Smrg    func_arith_result=$(( $* ))
67725dbecb6Smrg  }'
67825dbecb6Smrgelse
67925dbecb6Smrg  func_arith ()
68025dbecb6Smrg  {
68125dbecb6Smrg    $debug_cmd
68225dbecb6Smrg
68325dbecb6Smrg    func_arith_result=`expr "$@"`
68425dbecb6Smrg  }
68525dbecb6Smrgfi
68625dbecb6Smrg
68725dbecb6Smrg
68825dbecb6Smrg# func_basename FILE
68925dbecb6Smrg# ------------------
69025dbecb6Smrg# Set func_basename_result to FILE with everything up to and including
69125dbecb6Smrg# the last / stripped.
69225dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
69325dbecb6Smrg  # If this shell supports suffix pattern removal, then use it to avoid
69425dbecb6Smrg  # forking. Hide the definitions single quotes in case the shell chokes
69525dbecb6Smrg  # on unsupported syntax...
69625dbecb6Smrg  _b='func_basename_result=${1##*/}'
69725dbecb6Smrg  _d='case $1 in
69825dbecb6Smrg        */*) func_dirname_result=${1%/*}$2 ;;
69925dbecb6Smrg        *  ) func_dirname_result=$3        ;;
70025dbecb6Smrg      esac'
70125dbecb6Smrg
70225dbecb6Smrgelse
70325dbecb6Smrg  # ...otherwise fall back to using sed.
70425dbecb6Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
70525dbecb6Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
70625dbecb6Smrg      if test "X$func_dirname_result" = "X$1"; then
70725dbecb6Smrg        func_dirname_result=$3
70825dbecb6Smrg      else
70925dbecb6Smrg        func_append func_dirname_result "$2"
71025dbecb6Smrg      fi'
71125dbecb6Smrgfi
71225dbecb6Smrg
71325dbecb6Smrgeval 'func_basename ()
71425dbecb6Smrg{
71525dbecb6Smrg    $debug_cmd
71625dbecb6Smrg
71725dbecb6Smrg    '"$_b"'
71825dbecb6Smrg}'
71925dbecb6Smrg
72025dbecb6Smrg
72125dbecb6Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
72225dbecb6Smrg# -------------------------------------------
72325dbecb6Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
72425dbecb6Smrg# otherwise set result to NONDIR_REPLACEMENT.
72525dbecb6Smrgeval 'func_dirname ()
72625dbecb6Smrg{
72725dbecb6Smrg    $debug_cmd
72825dbecb6Smrg
72925dbecb6Smrg    '"$_d"'
73025dbecb6Smrg}'
73125dbecb6Smrg
73225dbecb6Smrg
73325dbecb6Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
73425dbecb6Smrg# --------------------------------------------------------
73525dbecb6Smrg# Perform func_basename and func_dirname in a single function
73625dbecb6Smrg# call:
73725dbecb6Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
73825dbecb6Smrg#             add APPEND to the result, otherwise set result
73925dbecb6Smrg#             to NONDIR_REPLACEMENT.
74025dbecb6Smrg#             value returned in "$func_dirname_result"
74125dbecb6Smrg#   basename: Compute filename of FILE.
74225dbecb6Smrg#             value retuned in "$func_basename_result"
74325dbecb6Smrg# For efficiency, we do not delegate to the functions above but instead
74425dbecb6Smrg# duplicate the functionality here.
74525dbecb6Smrgeval 'func_dirname_and_basename ()
74625dbecb6Smrg{
74725dbecb6Smrg    $debug_cmd
74825dbecb6Smrg
74925dbecb6Smrg    '"$_b"'
75025dbecb6Smrg    '"$_d"'
75125dbecb6Smrg}'
75225dbecb6Smrg
75325dbecb6Smrg
75425dbecb6Smrg# func_echo ARG...
75525dbecb6Smrg# ----------------
75625dbecb6Smrg# Echo program name prefixed message.
75725dbecb6Smrgfunc_echo ()
75825dbecb6Smrg{
75925dbecb6Smrg    $debug_cmd
76025dbecb6Smrg
76125dbecb6Smrg    _G_message=$*
76225dbecb6Smrg
76325dbecb6Smrg    func_echo_IFS=$IFS
76425dbecb6Smrg    IFS=$nl
76525dbecb6Smrg    for _G_line in $_G_message; do
76625dbecb6Smrg      IFS=$func_echo_IFS
76725dbecb6Smrg      $ECHO "$progname: $_G_line"
76825dbecb6Smrg    done
76925dbecb6Smrg    IFS=$func_echo_IFS
77025dbecb6Smrg}
77125dbecb6Smrg
77225dbecb6Smrg
77325dbecb6Smrg# func_echo_all ARG...
77425dbecb6Smrg# --------------------
77525dbecb6Smrg# Invoke $ECHO with all args, space-separated.
77625dbecb6Smrgfunc_echo_all ()
77725dbecb6Smrg{
77825dbecb6Smrg    $ECHO "$*"
77925dbecb6Smrg}
78025dbecb6Smrg
78125dbecb6Smrg
78225dbecb6Smrg# func_echo_infix_1 INFIX ARG...
78325dbecb6Smrg# ------------------------------
78425dbecb6Smrg# Echo program name, followed by INFIX on the first line, with any
78525dbecb6Smrg# additional lines not showing INFIX.
78625dbecb6Smrgfunc_echo_infix_1 ()
78725dbecb6Smrg{
78825dbecb6Smrg    $debug_cmd
78925dbecb6Smrg
79025dbecb6Smrg    $require_term_colors
79125dbecb6Smrg
79225dbecb6Smrg    _G_infix=$1; shift
79325dbecb6Smrg    _G_indent=$_G_infix
79425dbecb6Smrg    _G_prefix="$progname: $_G_infix: "
79525dbecb6Smrg    _G_message=$*
79625dbecb6Smrg
79725dbecb6Smrg    # Strip color escape sequences before counting printable length
79825dbecb6Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
79925dbecb6Smrg    do
80025dbecb6Smrg      test -n "$_G_tc" && {
80125dbecb6Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
80225dbecb6Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
80325dbecb6Smrg      }
80425dbecb6Smrg    done
80525dbecb6Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
80625dbecb6Smrg
80725dbecb6Smrg    func_echo_infix_1_IFS=$IFS
80825dbecb6Smrg    IFS=$nl
80925dbecb6Smrg    for _G_line in $_G_message; do
81025dbecb6Smrg      IFS=$func_echo_infix_1_IFS
81125dbecb6Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
81225dbecb6Smrg      _G_prefix=$_G_indent
81325dbecb6Smrg    done
81425dbecb6Smrg    IFS=$func_echo_infix_1_IFS
81525dbecb6Smrg}
81625dbecb6Smrg
81725dbecb6Smrg
81825dbecb6Smrg# func_error ARG...
81925dbecb6Smrg# -----------------
82025dbecb6Smrg# Echo program name prefixed message to standard error.
82125dbecb6Smrgfunc_error ()
82225dbecb6Smrg{
82325dbecb6Smrg    $debug_cmd
82425dbecb6Smrg
82525dbecb6Smrg    $require_term_colors
82625dbecb6Smrg
82725dbecb6Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
82825dbecb6Smrg}
82925dbecb6Smrg
83025dbecb6Smrg
83125dbecb6Smrg# func_fatal_error ARG...
83225dbecb6Smrg# -----------------------
83325dbecb6Smrg# Echo program name prefixed message to standard error, and exit.
83425dbecb6Smrgfunc_fatal_error ()
83525dbecb6Smrg{
83625dbecb6Smrg    $debug_cmd
83725dbecb6Smrg
83825dbecb6Smrg    func_error "$*"
83925dbecb6Smrg    exit $EXIT_FAILURE
84025dbecb6Smrg}
84125dbecb6Smrg
84225dbecb6Smrg
84325dbecb6Smrg# func_grep EXPRESSION FILENAME
84425dbecb6Smrg# -----------------------------
84525dbecb6Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
84625dbecb6Smrgfunc_grep ()
847b68e1f86Smrg{
84825dbecb6Smrg    $debug_cmd
84925dbecb6Smrg
85025dbecb6Smrg    $GREP "$1" "$2" >/dev/null 2>&1
85125dbecb6Smrg}
852b68e1f86Smrg
853b68e1f86Smrg
85425dbecb6Smrg# func_len STRING
85525dbecb6Smrg# ---------------
85625dbecb6Smrg# Set func_len_result to the length of STRING. STRING may not
85725dbecb6Smrg# start with a hyphen.
85825dbecb6Smrg  test -z "$_G_HAVE_XSI_OPS" \
85925dbecb6Smrg    && (eval 'x=a/b/c;
86025dbecb6Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
86125dbecb6Smrg    && _G_HAVE_XSI_OPS=yes
86225dbecb6Smrg
86325dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
86425dbecb6Smrg  eval 'func_len ()
86525dbecb6Smrg  {
86625dbecb6Smrg    $debug_cmd
86725dbecb6Smrg
86825dbecb6Smrg    func_len_result=${#1}
86925dbecb6Smrg  }'
87025dbecb6Smrgelse
87125dbecb6Smrg  func_len ()
87225dbecb6Smrg  {
87325dbecb6Smrg    $debug_cmd
87425dbecb6Smrg
87525dbecb6Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
87625dbecb6Smrg  }
87725dbecb6Smrgfi
87825dbecb6Smrg
87925dbecb6Smrg
88025dbecb6Smrg# func_mkdir_p DIRECTORY-PATH
88125dbecb6Smrg# ---------------------------
88225dbecb6Smrg# Make sure the entire path to DIRECTORY-PATH is available.
88325dbecb6Smrgfunc_mkdir_p ()
88425dbecb6Smrg{
88525dbecb6Smrg    $debug_cmd
88625dbecb6Smrg
88725dbecb6Smrg    _G_directory_path=$1
88825dbecb6Smrg    _G_dir_list=
88925dbecb6Smrg
89025dbecb6Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
89125dbecb6Smrg
89225dbecb6Smrg      # Protect directory names starting with '-'
89325dbecb6Smrg      case $_G_directory_path in
89425dbecb6Smrg        -*) _G_directory_path=./$_G_directory_path ;;
895b68e1f86Smrg      esac
896b68e1f86Smrg
897b68e1f86Smrg      # While some portion of DIR does not yet exist...
89825dbecb6Smrg      while test ! -d "$_G_directory_path"; do
899b68e1f86Smrg        # ...make a list in topmost first order.  Use a colon delimited
900b68e1f86Smrg	# list incase some portion of path contains whitespace.
90125dbecb6Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902b68e1f86Smrg
903b68e1f86Smrg        # If the last portion added has no slash in it, the list is done
90425dbecb6Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
905b68e1f86Smrg
906b68e1f86Smrg        # ...otherwise throw away the child directory and loop
90725dbecb6Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908b68e1f86Smrg      done
90925dbecb6Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910b68e1f86Smrg
91125dbecb6Smrg      func_mkdir_p_IFS=$IFS; IFS=:
91225dbecb6Smrg      for _G_dir in $_G_dir_list; do
91325dbecb6Smrg	IFS=$func_mkdir_p_IFS
91425dbecb6Smrg        # mkdir can fail with a 'File exist' error if two processes
915b68e1f86Smrg        # try to create one of the directories concurrently.  Don't
916b68e1f86Smrg        # stop in that case!
91725dbecb6Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
918b68e1f86Smrg      done
91925dbecb6Smrg      IFS=$func_mkdir_p_IFS
920b68e1f86Smrg
921b68e1f86Smrg      # Bail out if we (or some other process) failed to create a directory.
92225dbecb6Smrg      test -d "$_G_directory_path" || \
92325dbecb6Smrg        func_fatal_error "Failed to create '$1'"
924b68e1f86Smrg    fi
925b68e1f86Smrg}
9266df26cacSmrg
9276df26cacSmrg
92825dbecb6Smrg# func_mktempdir [BASENAME]
92925dbecb6Smrg# -------------------------
9306df26cacSmrg# Make a temporary directory that won't clash with other running
9316df26cacSmrg# libtool processes, and avoids race conditions if possible.  If
93225dbecb6Smrg# given, BASENAME is the basename for that directory.
9336df26cacSmrgfunc_mktempdir ()
9346df26cacSmrg{
93525dbecb6Smrg    $debug_cmd
9366df26cacSmrg
93725dbecb6Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
93825dbecb6Smrg
93925dbecb6Smrg    if test : = "$opt_dry_run"; then
9406df26cacSmrg      # Return a directory name, but don't create it in dry-run mode
94125dbecb6Smrg      _G_tmpdir=$_G_template-$$
9426df26cacSmrg    else
9436df26cacSmrg
9446df26cacSmrg      # If mktemp works, use that first and foremost
94525dbecb6Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9466df26cacSmrg
94725dbecb6Smrg      if test ! -d "$_G_tmpdir"; then
948b68e1f86Smrg        # Failing that, at least try and use $RANDOM to avoid a race
94925dbecb6Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9506df26cacSmrg
95125dbecb6Smrg        func_mktempdir_umask=`umask`
952b68e1f86Smrg        umask 0077
95325dbecb6Smrg        $MKDIR "$_G_tmpdir"
95425dbecb6Smrg        umask $func_mktempdir_umask
9556df26cacSmrg      fi
9566df26cacSmrg
9576df26cacSmrg      # If we're not in dry-run mode, bomb out on failure
95825dbecb6Smrg      test -d "$_G_tmpdir" || \
95925dbecb6Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9606df26cacSmrg    fi
9616df26cacSmrg
96225dbecb6Smrg    $ECHO "$_G_tmpdir"
9636df26cacSmrg}
9646df26cacSmrg
9656df26cacSmrg
96625dbecb6Smrg# func_normal_abspath PATH
96725dbecb6Smrg# ------------------------
96825dbecb6Smrg# Remove doubled-up and trailing slashes, "." path components,
96925dbecb6Smrg# and cancel out any ".." path components in PATH after making
97025dbecb6Smrg# it an absolute path.
97125dbecb6Smrgfunc_normal_abspath ()
9726df26cacSmrg{
97325dbecb6Smrg    $debug_cmd
97425dbecb6Smrg
97525dbecb6Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
97625dbecb6Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
97725dbecb6Smrg    _G_pathcdr='s|^/[^/]*||'
97825dbecb6Smrg    _G_removedotparts=':dotsl
97925dbecb6Smrg		s|/\./|/|g
98025dbecb6Smrg		t dotsl
98125dbecb6Smrg		s|/\.$|/|'
98225dbecb6Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
98325dbecb6Smrg    _G_finalslash='s|/*$|/|'
98425dbecb6Smrg
98525dbecb6Smrg    # Start from root dir and reassemble the path.
98625dbecb6Smrg    func_normal_abspath_result=
98725dbecb6Smrg    func_normal_abspath_tpath=$1
98825dbecb6Smrg    func_normal_abspath_altnamespace=
98925dbecb6Smrg    case $func_normal_abspath_tpath in
99025dbecb6Smrg      "")
99125dbecb6Smrg        # Empty path, that just means $cwd.
99225dbecb6Smrg        func_stripname '' '/' "`pwd`"
99325dbecb6Smrg        func_normal_abspath_result=$func_stripname_result
99425dbecb6Smrg        return
99525dbecb6Smrg        ;;
99625dbecb6Smrg      # The next three entries are used to spot a run of precisely
99725dbecb6Smrg      # two leading slashes without using negated character classes;
99825dbecb6Smrg      # we take advantage of case's first-match behaviour.
99925dbecb6Smrg      ///*)
100025dbecb6Smrg        # Unusual form of absolute path, do nothing.
100125dbecb6Smrg        ;;
100225dbecb6Smrg      //*)
100325dbecb6Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
100425dbecb6Smrg        # and for example Cygwin uses it to access remote file shares
100525dbecb6Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
100625dbecb6Smrg        func_normal_abspath_altnamespace=/
100725dbecb6Smrg        ;;
100825dbecb6Smrg      /*)
100925dbecb6Smrg        # Absolute path, do nothing.
101025dbecb6Smrg        ;;
1011b68e1f86Smrg      *)
101225dbecb6Smrg        # Relative path, prepend $cwd.
101325dbecb6Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
101425dbecb6Smrg        ;;
1015b68e1f86Smrg    esac
1016b68e1f86Smrg
101725dbecb6Smrg    # Cancel out all the simple stuff to save iterations.  We also want
101825dbecb6Smrg    # the path to end with a slash for ease of parsing, so make sure
101925dbecb6Smrg    # there is one (and only one) here.
102025dbecb6Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
102125dbecb6Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
102225dbecb6Smrg    while :; do
102325dbecb6Smrg      # Processed it all yet?
102425dbecb6Smrg      if test / = "$func_normal_abspath_tpath"; then
102525dbecb6Smrg        # If we ascended to the root using ".." the result may be empty now.
102625dbecb6Smrg        if test -z "$func_normal_abspath_result"; then
102725dbecb6Smrg          func_normal_abspath_result=/
102825dbecb6Smrg        fi
102925dbecb6Smrg        break
103025dbecb6Smrg      fi
103125dbecb6Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
103225dbecb6Smrg          -e "$_G_pathcar"`
103325dbecb6Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
103425dbecb6Smrg          -e "$_G_pathcdr"`
103525dbecb6Smrg      # Figure out what to do with it
103625dbecb6Smrg      case $func_normal_abspath_tcomponent in
103725dbecb6Smrg        "")
103825dbecb6Smrg          # Trailing empty path component, ignore it.
103925dbecb6Smrg          ;;
104025dbecb6Smrg        ..)
104125dbecb6Smrg          # Parent dir; strip last assembled component from result.
104225dbecb6Smrg          func_dirname "$func_normal_abspath_result"
104325dbecb6Smrg          func_normal_abspath_result=$func_dirname_result
104425dbecb6Smrg          ;;
104525dbecb6Smrg        *)
104625dbecb6Smrg          # Actual path component, append it.
104725dbecb6Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
104825dbecb6Smrg          ;;
104925dbecb6Smrg      esac
105025dbecb6Smrg    done
105125dbecb6Smrg    # Restore leading double-slash if one was found on entry.
105225dbecb6Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
105325dbecb6Smrg}
105425dbecb6Smrg
105525dbecb6Smrg
105625dbecb6Smrg# func_notquiet ARG...
105725dbecb6Smrg# --------------------
105825dbecb6Smrg# Echo program name prefixed message only when not in quiet mode.
105925dbecb6Smrgfunc_notquiet ()
106025dbecb6Smrg{
106125dbecb6Smrg    $debug_cmd
106225dbecb6Smrg
106325dbecb6Smrg    $opt_quiet || func_echo ${1+"$@"}
106425dbecb6Smrg
106525dbecb6Smrg    # A bug in bash halts the script if the last line of a function
106625dbecb6Smrg    # fails when set -e is in force, so we need another command to
106725dbecb6Smrg    # work around that:
106825dbecb6Smrg    :
106925dbecb6Smrg}
107025dbecb6Smrg
107125dbecb6Smrg
107225dbecb6Smrg# func_relative_path SRCDIR DSTDIR
107325dbecb6Smrg# --------------------------------
107425dbecb6Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
107525dbecb6Smrgfunc_relative_path ()
107625dbecb6Smrg{
107725dbecb6Smrg    $debug_cmd
107825dbecb6Smrg
107925dbecb6Smrg    func_relative_path_result=
108025dbecb6Smrg    func_normal_abspath "$1"
108125dbecb6Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
108225dbecb6Smrg    func_normal_abspath "$2"
108325dbecb6Smrg    func_relative_path_tbindir=$func_normal_abspath_result
108425dbecb6Smrg
108525dbecb6Smrg    # Ascend the tree starting from libdir
108625dbecb6Smrg    while :; do
108725dbecb6Smrg      # check if we have found a prefix of bindir
108825dbecb6Smrg      case $func_relative_path_tbindir in
108925dbecb6Smrg        $func_relative_path_tlibdir)
109025dbecb6Smrg          # found an exact match
109125dbecb6Smrg          func_relative_path_tcancelled=
109225dbecb6Smrg          break
109325dbecb6Smrg          ;;
109425dbecb6Smrg        $func_relative_path_tlibdir*)
109525dbecb6Smrg          # found a matching prefix
109625dbecb6Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
109725dbecb6Smrg          func_relative_path_tcancelled=$func_stripname_result
109825dbecb6Smrg          if test -z "$func_relative_path_result"; then
109925dbecb6Smrg            func_relative_path_result=.
110025dbecb6Smrg          fi
110125dbecb6Smrg          break
110225dbecb6Smrg          ;;
110325dbecb6Smrg        *)
110425dbecb6Smrg          func_dirname $func_relative_path_tlibdir
110525dbecb6Smrg          func_relative_path_tlibdir=$func_dirname_result
110625dbecb6Smrg          if test -z "$func_relative_path_tlibdir"; then
110725dbecb6Smrg            # Have to descend all the way to the root!
110825dbecb6Smrg            func_relative_path_result=../$func_relative_path_result
110925dbecb6Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
111025dbecb6Smrg            break
111125dbecb6Smrg          fi
111225dbecb6Smrg          func_relative_path_result=../$func_relative_path_result
111325dbecb6Smrg          ;;
111425dbecb6Smrg      esac
111525dbecb6Smrg    done
111625dbecb6Smrg
111725dbecb6Smrg    # Now calculate path; take care to avoid doubling-up slashes.
111825dbecb6Smrg    func_stripname '' '/' "$func_relative_path_result"
111925dbecb6Smrg    func_relative_path_result=$func_stripname_result
112025dbecb6Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
112125dbecb6Smrg    if test -n "$func_stripname_result"; then
112225dbecb6Smrg      func_append func_relative_path_result "/$func_stripname_result"
112325dbecb6Smrg    fi
112425dbecb6Smrg
112525dbecb6Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
112625dbecb6Smrg    if test -n "$func_relative_path_result"; then
112725dbecb6Smrg      func_stripname './' '' "$func_relative_path_result"
112825dbecb6Smrg      func_relative_path_result=$func_stripname_result
112925dbecb6Smrg    fi
113025dbecb6Smrg
113125dbecb6Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
113225dbecb6Smrg
113325dbecb6Smrg    :
113425dbecb6Smrg}
113525dbecb6Smrg
113625dbecb6Smrg
113725dbecb6Smrg# func_quote_portable EVAL ARG
113825dbecb6Smrg# ----------------------------
113925dbecb6Smrg# Internal function to portably implement func_quote_arg.  Note that we still
114025dbecb6Smrg# keep attention to performance here so we as much as possible try to avoid
114125dbecb6Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
114225dbecb6Smrgfunc_quote_portable ()
114325dbecb6Smrg{
114425dbecb6Smrg    $debug_cmd
114525dbecb6Smrg
114625dbecb6Smrg    $require_check_ifs_backslash
114725dbecb6Smrg
114825dbecb6Smrg    func_quote_portable_result=$2
114925dbecb6Smrg
115025dbecb6Smrg    # one-time-loop (easy break)
115125dbecb6Smrg    while true
115225dbecb6Smrg    do
115325dbecb6Smrg      if $1; then
115425dbecb6Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
115525dbecb6Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
115625dbecb6Smrg        break
115725dbecb6Smrg      fi
115825dbecb6Smrg
115925dbecb6Smrg      # Quote for eval.
116025dbecb6Smrg      case $func_quote_portable_result in
116125dbecb6Smrg        *[\\\`\"\$]*)
116225dbecb6Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
116325dbecb6Smrg          # contains the shell wildcard characters.
116425dbecb6Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
116525dbecb6Smrg            :*|*[\[\*\?]*)
116625dbecb6Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
116725dbecb6Smrg                  | $SED "$sed_quote_subst"`
116825dbecb6Smrg              break
116925dbecb6Smrg              ;;
117025dbecb6Smrg          esac
117125dbecb6Smrg
117225dbecb6Smrg          func_quote_portable_old_IFS=$IFS
117325dbecb6Smrg          for _G_char in '\' '`' '"' '$'
117425dbecb6Smrg          do
117525dbecb6Smrg            # STATE($1) PREV($2) SEPARATOR($3)
117625dbecb6Smrg            set start "" ""
117725dbecb6Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
117825dbecb6Smrg            IFS=$_G_char
117925dbecb6Smrg            for _G_part in $func_quote_portable_result
118025dbecb6Smrg            do
118125dbecb6Smrg              case $1 in
118225dbecb6Smrg              quote)
118325dbecb6Smrg                func_append func_quote_portable_result "$3$2"
118425dbecb6Smrg                set quote "$_G_part" "\\$_G_char"
118525dbecb6Smrg                ;;
118625dbecb6Smrg              start)
118725dbecb6Smrg                set first "" ""
118825dbecb6Smrg                func_quote_portable_result=
118925dbecb6Smrg                ;;
119025dbecb6Smrg              first)
119125dbecb6Smrg                set quote "$_G_part" ""
119225dbecb6Smrg                ;;
119325dbecb6Smrg              esac
119425dbecb6Smrg            done
119525dbecb6Smrg          done
119625dbecb6Smrg          IFS=$func_quote_portable_old_IFS
119725dbecb6Smrg          ;;
119825dbecb6Smrg        *) ;;
119925dbecb6Smrg      esac
120025dbecb6Smrg      break
120125dbecb6Smrg    done
120225dbecb6Smrg
120325dbecb6Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
120425dbecb6Smrg    case $func_quote_portable_result in
120525dbecb6Smrg      # double-quote args containing shell metacharacters to delay
120625dbecb6Smrg      # word splitting, command substitution and variable expansion
120725dbecb6Smrg      # for a subsequent eval.
120825dbecb6Smrg      # many bourne shells cannot handle close brackets correctly
1209b68e1f86Smrg      # in scan sets, so we specify it separately.
1210b68e1f86Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
121125dbecb6Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
121225dbecb6Smrg        ;;
121325dbecb6Smrg    esac
121425dbecb6Smrg}
121525dbecb6Smrg
121625dbecb6Smrg
121725dbecb6Smrg# func_quotefast_eval ARG
121825dbecb6Smrg# -----------------------
121925dbecb6Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
122025dbecb6Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
122125dbecb6Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
122225dbecb6Smrg  printf -v _GL_test_printf_tilde %q '~'
122325dbecb6Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
122425dbecb6Smrg    func_quotefast_eval ()
122525dbecb6Smrg    {
122625dbecb6Smrg      printf -v func_quotefast_eval_result %q "$1"
122725dbecb6Smrg    }
122825dbecb6Smrg  else
122925dbecb6Smrg    # Broken older Bash implementations.  Make those faster too if possible.
123025dbecb6Smrg    func_quotefast_eval ()
123125dbecb6Smrg    {
123225dbecb6Smrg      case $1 in
123325dbecb6Smrg        '~'*)
123425dbecb6Smrg          func_quote_portable false "$1"
123525dbecb6Smrg          func_quotefast_eval_result=$func_quote_portable_result
123625dbecb6Smrg          ;;
123725dbecb6Smrg        *)
123825dbecb6Smrg          printf -v func_quotefast_eval_result %q "$1"
123925dbecb6Smrg          ;;
124025dbecb6Smrg      esac
124125dbecb6Smrg    }
124225dbecb6Smrg  fi
124325dbecb6Smrgelse
124425dbecb6Smrg  func_quotefast_eval ()
124525dbecb6Smrg  {
124625dbecb6Smrg    func_quote_portable false "$1"
124725dbecb6Smrg    func_quotefast_eval_result=$func_quote_portable_result
124825dbecb6Smrg  }
124925dbecb6Smrgfi
125025dbecb6Smrg
125125dbecb6Smrg
125225dbecb6Smrg# func_quote_arg MODEs ARG
125325dbecb6Smrg# ------------------------
125425dbecb6Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
125525dbecb6Smrg# specifiers listed below separated by ',' character.  This function returns two
125625dbecb6Smrg# values:
125725dbecb6Smrg#   i) func_quote_arg_result
125825dbecb6Smrg#      double-quoted (when needed), suitable for a subsequent eval
125925dbecb6Smrg#  ii) func_quote_arg_unquoted_result
126025dbecb6Smrg#      has all characters that are still active within double
126125dbecb6Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
126225dbecb6Smrg#
126325dbecb6Smrg# Available modes:
126425dbecb6Smrg# ----------------
126525dbecb6Smrg# 'eval' (default)
126625dbecb6Smrg#       - escape shell special characters
126725dbecb6Smrg# 'expand'
126825dbecb6Smrg#       - the same as 'eval';  but do not quote variable references
126925dbecb6Smrg# 'pretty'
127025dbecb6Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
127125dbecb6Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
127225dbecb6Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
127325dbecb6Smrg# 'unquoted'
127425dbecb6Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
127525dbecb6Smrg#         wrapping double-quotes.
127625dbecb6Smrg#
127725dbecb6Smrg# Examples for 'func_quote_arg pretty,unquoted string':
127825dbecb6Smrg#
127925dbecb6Smrg#   string      | *_result              | *_unquoted_result
128025dbecb6Smrg#   ------------+-----------------------+-------------------
128125dbecb6Smrg#   "           | \"                    | \"
128225dbecb6Smrg#   a b         | "a b"                 | a b
128325dbecb6Smrg#   "a b"       | "\"a b\""             | \"a b\"
128425dbecb6Smrg#   *           | "*"                   | *
128525dbecb6Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
128625dbecb6Smrg#
128725dbecb6Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
128825dbecb6Smrg#
128925dbecb6Smrg#   string        |   *_result          |  *_unquoted_result
129025dbecb6Smrg#   --------------+---------------------+--------------------
129125dbecb6Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
129225dbecb6Smrgfunc_quote_arg ()
129325dbecb6Smrg{
129425dbecb6Smrg    _G_quote_expand=false
129525dbecb6Smrg    case ,$1, in
129625dbecb6Smrg      *,expand,*)
129725dbecb6Smrg        _G_quote_expand=:
129825dbecb6Smrg        ;;
129925dbecb6Smrg    esac
130025dbecb6Smrg
130125dbecb6Smrg    case ,$1, in
130225dbecb6Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
130325dbecb6Smrg        func_quote_portable $_G_quote_expand "$2"
130425dbecb6Smrg        func_quote_arg_result=$func_quote_portable_result
130525dbecb6Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306b68e1f86Smrg        ;;
1307b68e1f86Smrg      *)
130825dbecb6Smrg        # Faster quote-for-eval for some shells.
130925dbecb6Smrg        func_quotefast_eval "$2"
131025dbecb6Smrg        func_quote_arg_result=$func_quotefast_eval_result
131125dbecb6Smrg        ;;
131225dbecb6Smrg    esac
131325dbecb6Smrg}
131425dbecb6Smrg
131525dbecb6Smrg
131625dbecb6Smrg# func_quote MODEs ARGs...
131725dbecb6Smrg# ------------------------
131825dbecb6Smrg# Quote all ARGs to be evaled later and join them into single command.  See
131925dbecb6Smrg# func_quote_arg's description for more info.
132025dbecb6Smrgfunc_quote ()
132125dbecb6Smrg{
132225dbecb6Smrg    $debug_cmd
132325dbecb6Smrg    _G_func_quote_mode=$1 ; shift
132425dbecb6Smrg    func_quote_result=
132525dbecb6Smrg    while test 0 -lt $#; do
132625dbecb6Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
132725dbecb6Smrg      if test -n "$func_quote_result"; then
132825dbecb6Smrg        func_append func_quote_result " $func_quote_arg_result"
132925dbecb6Smrg      else
133025dbecb6Smrg        func_append func_quote_result "$func_quote_arg_result"
133125dbecb6Smrg      fi
133225dbecb6Smrg      shift
133325dbecb6Smrg    done
133425dbecb6Smrg}
133525dbecb6Smrg
133625dbecb6Smrg
133725dbecb6Smrg# func_stripname PREFIX SUFFIX NAME
133825dbecb6Smrg# ---------------------------------
133925dbecb6Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
134025dbecb6Smrg# PREFIX and SUFFIX must not contain globbing or regex special
134125dbecb6Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
134225dbecb6Smrg# dot (in which case that matches only a dot).
134325dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
134425dbecb6Smrg  eval 'func_stripname ()
134525dbecb6Smrg  {
134625dbecb6Smrg    $debug_cmd
134725dbecb6Smrg
134825dbecb6Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
134925dbecb6Smrg    # positional parameters, so assign one to ordinary variable first.
135025dbecb6Smrg    func_stripname_result=$3
135125dbecb6Smrg    func_stripname_result=${func_stripname_result#"$1"}
135225dbecb6Smrg    func_stripname_result=${func_stripname_result%"$2"}
135325dbecb6Smrg  }'
135425dbecb6Smrgelse
135525dbecb6Smrg  func_stripname ()
135625dbecb6Smrg  {
135725dbecb6Smrg    $debug_cmd
135825dbecb6Smrg
135925dbecb6Smrg    case $2 in
136025dbecb6Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
136125dbecb6Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
136225dbecb6Smrg    esac
136325dbecb6Smrg  }
136425dbecb6Smrgfi
136525dbecb6Smrg
136625dbecb6Smrg
136725dbecb6Smrg# func_show_eval CMD [FAIL_EXP]
136825dbecb6Smrg# -----------------------------
136925dbecb6Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
137025dbecb6Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
137125dbecb6Smrg# is given, then evaluate it.
137225dbecb6Smrgfunc_show_eval ()
137325dbecb6Smrg{
137425dbecb6Smrg    $debug_cmd
137525dbecb6Smrg
137625dbecb6Smrg    _G_cmd=$1
137725dbecb6Smrg    _G_fail_exp=${2-':'}
137825dbecb6Smrg
137925dbecb6Smrg    func_quote_arg pretty,expand "$_G_cmd"
138025dbecb6Smrg    eval "func_notquiet $func_quote_arg_result"
138125dbecb6Smrg
138225dbecb6Smrg    $opt_dry_run || {
138325dbecb6Smrg      eval "$_G_cmd"
138425dbecb6Smrg      _G_status=$?
138525dbecb6Smrg      if test 0 -ne "$_G_status"; then
138625dbecb6Smrg	eval "(exit $_G_status); $_G_fail_exp"
138725dbecb6Smrg      fi
138825dbecb6Smrg    }
138925dbecb6Smrg}
139025dbecb6Smrg
139125dbecb6Smrg
139225dbecb6Smrg# func_show_eval_locale CMD [FAIL_EXP]
139325dbecb6Smrg# ------------------------------------
139425dbecb6Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
139525dbecb6Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
139625dbecb6Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
139725dbecb6Smrgfunc_show_eval_locale ()
139825dbecb6Smrg{
139925dbecb6Smrg    $debug_cmd
140025dbecb6Smrg
140125dbecb6Smrg    _G_cmd=$1
140225dbecb6Smrg    _G_fail_exp=${2-':'}
140325dbecb6Smrg
140425dbecb6Smrg    $opt_quiet || {
140525dbecb6Smrg      func_quote_arg expand,pretty "$_G_cmd"
140625dbecb6Smrg      eval "func_echo $func_quote_arg_result"
140725dbecb6Smrg    }
140825dbecb6Smrg
140925dbecb6Smrg    $opt_dry_run || {
141025dbecb6Smrg      eval "$_G_user_locale
141125dbecb6Smrg	    $_G_cmd"
141225dbecb6Smrg      _G_status=$?
141325dbecb6Smrg      eval "$_G_safe_locale"
141425dbecb6Smrg      if test 0 -ne "$_G_status"; then
141525dbecb6Smrg	eval "(exit $_G_status); $_G_fail_exp"
141625dbecb6Smrg      fi
141725dbecb6Smrg    }
141825dbecb6Smrg}
141925dbecb6Smrg
142025dbecb6Smrg
142125dbecb6Smrg# func_tr_sh
142225dbecb6Smrg# ----------
142325dbecb6Smrg# Turn $1 into a string suitable for a shell variable name.
142425dbecb6Smrg# Result is stored in $func_tr_sh_result.  All characters
142525dbecb6Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
142625dbecb6Smrg# if $1 begins with a digit, a '_' is prepended as well.
142725dbecb6Smrgfunc_tr_sh ()
142825dbecb6Smrg{
142925dbecb6Smrg    $debug_cmd
143025dbecb6Smrg
143125dbecb6Smrg    case $1 in
143225dbecb6Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
143325dbecb6Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
143425dbecb6Smrg      ;;
143525dbecb6Smrg    * )
143625dbecb6Smrg      func_tr_sh_result=$1
143725dbecb6Smrg      ;;
143825dbecb6Smrg    esac
143925dbecb6Smrg}
144025dbecb6Smrg
144125dbecb6Smrg
144225dbecb6Smrg# func_verbose ARG...
144325dbecb6Smrg# -------------------
144425dbecb6Smrg# Echo program name prefixed message in verbose mode only.
144525dbecb6Smrgfunc_verbose ()
144625dbecb6Smrg{
144725dbecb6Smrg    $debug_cmd
144825dbecb6Smrg
144925dbecb6Smrg    $opt_verbose && func_echo "$*"
145025dbecb6Smrg
145125dbecb6Smrg    :
145225dbecb6Smrg}
145325dbecb6Smrg
145425dbecb6Smrg
145525dbecb6Smrg# func_warn_and_continue ARG...
145625dbecb6Smrg# -----------------------------
145725dbecb6Smrg# Echo program name prefixed warning message to standard error.
145825dbecb6Smrgfunc_warn_and_continue ()
145925dbecb6Smrg{
146025dbecb6Smrg    $debug_cmd
146125dbecb6Smrg
146225dbecb6Smrg    $require_term_colors
146325dbecb6Smrg
146425dbecb6Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
146525dbecb6Smrg}
146625dbecb6Smrg
146725dbecb6Smrg
146825dbecb6Smrg# func_warning CATEGORY ARG...
146925dbecb6Smrg# ----------------------------
147025dbecb6Smrg# Echo program name prefixed warning message to standard error. Warning
147125dbecb6Smrg# messages can be filtered according to CATEGORY, where this function
147225dbecb6Smrg# elides messages where CATEGORY is not listed in the global variable
147325dbecb6Smrg# 'opt_warning_types'.
147425dbecb6Smrgfunc_warning ()
147525dbecb6Smrg{
147625dbecb6Smrg    $debug_cmd
147725dbecb6Smrg
147825dbecb6Smrg    # CATEGORY must be in the warning_categories list!
147925dbecb6Smrg    case " $warning_categories " in
148025dbecb6Smrg      *" $1 "*) ;;
148125dbecb6Smrg      *) func_internal_error "invalid warning category '$1'" ;;
148225dbecb6Smrg    esac
148325dbecb6Smrg
148425dbecb6Smrg    _G_category=$1
148525dbecb6Smrg    shift
148625dbecb6Smrg
148725dbecb6Smrg    case " $opt_warning_types " in
148825dbecb6Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
148925dbecb6Smrg    esac
149025dbecb6Smrg}
149125dbecb6Smrg
149225dbecb6Smrg
149325dbecb6Smrg# func_sort_ver VER1 VER2
149425dbecb6Smrg# -----------------------
149525dbecb6Smrg# 'sort -V' is not generally available.
149625dbecb6Smrg# Note this deviates from the version comparison in automake
149725dbecb6Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
149825dbecb6Smrg# but this should suffice as we won't be specifying old
149925dbecb6Smrg# version formats or redundant trailing .0 in bootstrap.conf.
150025dbecb6Smrg# If we did want full compatibility then we should probably
150125dbecb6Smrg# use m4_version_compare from autoconf.
150225dbecb6Smrgfunc_sort_ver ()
150325dbecb6Smrg{
150425dbecb6Smrg    $debug_cmd
150525dbecb6Smrg
150625dbecb6Smrg    printf '%s\n%s\n' "$1" "$2" \
150725dbecb6Smrg      | 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
150825dbecb6Smrg}
150925dbecb6Smrg
151025dbecb6Smrg# func_lt_ver PREV CURR
151125dbecb6Smrg# ---------------------
151225dbecb6Smrg# Return true if PREV and CURR are in the correct order according to
151325dbecb6Smrg# func_sort_ver, otherwise false.  Use it like this:
151425dbecb6Smrg#
151525dbecb6Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
151625dbecb6Smrgfunc_lt_ver ()
151725dbecb6Smrg{
151825dbecb6Smrg    $debug_cmd
151925dbecb6Smrg
152025dbecb6Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
152125dbecb6Smrg}
152225dbecb6Smrg
152325dbecb6Smrg
152425dbecb6Smrg# Local variables:
152525dbecb6Smrg# mode: shell-script
152625dbecb6Smrg# sh-indentation: 2
152725dbecb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
152825dbecb6Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
152925dbecb6Smrg# time-stamp-time-zone: "UTC"
153025dbecb6Smrg# End:
153125dbecb6Smrg#! /bin/sh
153225dbecb6Smrg
153325dbecb6Smrg# A portable, pluggable option parser for Bourne shell.
153425dbecb6Smrg# Written by Gary V. Vaughan, 2010
153525dbecb6Smrg
153625dbecb6Smrg# This is free software.  There is NO warranty; not even for
153725dbecb6Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153825dbecb6Smrg#
153925dbecb6Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
154025dbecb6Smrg#
154125dbecb6Smrg# This file is dual licensed under the terms of the MIT license
154225dbecb6Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
154325dbecb6Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
154425dbecb6Smrg# these licenses when using or redistributing this software or any of
154525dbecb6Smrg# the files within it.  See the URLs above, or the file `LICENSE`
154625dbecb6Smrg# included in the Bootstrap distribution for the full license texts.
154725dbecb6Smrg
154825dbecb6Smrg# Please report bugs or propose patches to:
154925dbecb6Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
155025dbecb6Smrg
155125dbecb6Smrg# Set a version string for this script.
155225dbecb6Smrgscriptversion=2019-02-19.15; # UTC
155325dbecb6Smrg
155425dbecb6Smrg
155525dbecb6Smrg## ------ ##
155625dbecb6Smrg## Usage. ##
155725dbecb6Smrg## ------ ##
155825dbecb6Smrg
155925dbecb6Smrg# This file is a library for parsing options in your shell scripts along
156025dbecb6Smrg# with assorted other useful supporting features that you can make use
156125dbecb6Smrg# of too.
156225dbecb6Smrg#
156325dbecb6Smrg# For the simplest scripts you might need only:
156425dbecb6Smrg#
156525dbecb6Smrg#   #!/bin/sh
156625dbecb6Smrg#   . relative/path/to/funclib.sh
156725dbecb6Smrg#   . relative/path/to/options-parser
156825dbecb6Smrg#   scriptversion=1.0
156925dbecb6Smrg#   func_options ${1+"$@"}
157025dbecb6Smrg#   eval set dummy "$func_options_result"; shift
157125dbecb6Smrg#   ...rest of your script...
157225dbecb6Smrg#
157325dbecb6Smrg# In order for the '--version' option to work, you will need to have a
157425dbecb6Smrg# suitably formatted comment like the one at the top of this file
157525dbecb6Smrg# starting with '# Written by ' and ending with '# Copyright'.
157625dbecb6Smrg#
157725dbecb6Smrg# For '-h' and '--help' to work, you will also need a one line
157825dbecb6Smrg# description of your script's purpose in a comment directly above the
157925dbecb6Smrg# '# Written by ' line, like the one at the top of this file.
158025dbecb6Smrg#
158125dbecb6Smrg# The default options also support '--debug', which will turn on shell
158225dbecb6Smrg# execution tracing (see the comment above debug_cmd below for another
158325dbecb6Smrg# use), and '--verbose' and the func_verbose function to allow your script
158425dbecb6Smrg# to display verbose messages only when your user has specified
158525dbecb6Smrg# '--verbose'.
158625dbecb6Smrg#
158725dbecb6Smrg# After sourcing this file, you can plug in processing for additional
158825dbecb6Smrg# options by amending the variables from the 'Configuration' section
158925dbecb6Smrg# below, and following the instructions in the 'Option parsing'
159025dbecb6Smrg# section further down.
159125dbecb6Smrg
159225dbecb6Smrg## -------------- ##
159325dbecb6Smrg## Configuration. ##
159425dbecb6Smrg## -------------- ##
159525dbecb6Smrg
159625dbecb6Smrg# You should override these variables in your script after sourcing this
159725dbecb6Smrg# file so that they reflect the customisations you have added to the
159825dbecb6Smrg# option parser.
159925dbecb6Smrg
160025dbecb6Smrg# The usage line for option parsing errors and the start of '-h' and
160125dbecb6Smrg# '--help' output messages. You can embed shell variables for delayed
160225dbecb6Smrg# expansion at the time the message is displayed, but you will need to
160325dbecb6Smrg# quote other shell meta-characters carefully to prevent them being
160425dbecb6Smrg# expanded when the contents are evaled.
160525dbecb6Smrgusage='$progpath [OPTION]...'
160625dbecb6Smrg
160725dbecb6Smrg# Short help message in response to '-h' and '--help'.  Add to this or
160825dbecb6Smrg# override it after sourcing this library to reflect the full set of
160925dbecb6Smrg# options your script accepts.
161025dbecb6Smrgusage_message="\
161125dbecb6Smrg       --debug        enable verbose shell tracing
161225dbecb6Smrg   -W, --warnings=CATEGORY
161325dbecb6Smrg                      report the warnings falling in CATEGORY [all]
161425dbecb6Smrg   -v, --verbose      verbosely report processing
161525dbecb6Smrg       --version      print version information and exit
161625dbecb6Smrg   -h, --help         print short or long help message and exit
161725dbecb6Smrg"
161825dbecb6Smrg
161925dbecb6Smrg# Additional text appended to 'usage_message' in response to '--help'.
162025dbecb6Smrglong_help_message="
162125dbecb6SmrgWarning categories include:
162225dbecb6Smrg       'all'          show all warnings
162325dbecb6Smrg       'none'         turn off all the warnings
162425dbecb6Smrg       'error'        warnings are treated as fatal errors"
162525dbecb6Smrg
162625dbecb6Smrg# Help message printed before fatal option parsing errors.
162725dbecb6Smrgfatal_help="Try '\$progname --help' for more information."
162825dbecb6Smrg
162925dbecb6Smrg
163025dbecb6Smrg
163125dbecb6Smrg## ------------------------- ##
163225dbecb6Smrg## Hook function management. ##
163325dbecb6Smrg## ------------------------- ##
163425dbecb6Smrg
163525dbecb6Smrg# This section contains functions for adding, removing, and running hooks
163625dbecb6Smrg# in the main code.  A hook is just a list of function names that can be
163725dbecb6Smrg# run in order later on.
163825dbecb6Smrg
163925dbecb6Smrg# func_hookable FUNC_NAME
164025dbecb6Smrg# -----------------------
164125dbecb6Smrg# Declare that FUNC_NAME will run hooks added with
164225dbecb6Smrg# 'func_add_hook FUNC_NAME ...'.
164325dbecb6Smrgfunc_hookable ()
164425dbecb6Smrg{
164525dbecb6Smrg    $debug_cmd
164625dbecb6Smrg
164725dbecb6Smrg    func_append hookable_fns " $1"
164825dbecb6Smrg}
164925dbecb6Smrg
165025dbecb6Smrg
165125dbecb6Smrg# func_add_hook FUNC_NAME HOOK_FUNC
165225dbecb6Smrg# ---------------------------------
165325dbecb6Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
165425dbecb6Smrg# first have been declared "hookable" by a call to 'func_hookable'.
165525dbecb6Smrgfunc_add_hook ()
165625dbecb6Smrg{
165725dbecb6Smrg    $debug_cmd
165825dbecb6Smrg
165925dbecb6Smrg    case " $hookable_fns " in
166025dbecb6Smrg      *" $1 "*) ;;
166125dbecb6Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
166225dbecb6Smrg    esac
166325dbecb6Smrg
166425dbecb6Smrg    eval func_append ${1}_hooks '" $2"'
166525dbecb6Smrg}
166625dbecb6Smrg
166725dbecb6Smrg
166825dbecb6Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
166925dbecb6Smrg# ------------------------------------
167025dbecb6Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
167125dbecb6Smrg# FUNC_NAME.
167225dbecb6Smrgfunc_remove_hook ()
167325dbecb6Smrg{
167425dbecb6Smrg    $debug_cmd
167525dbecb6Smrg
167625dbecb6Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
167725dbecb6Smrg}
167825dbecb6Smrg
167925dbecb6Smrg
168025dbecb6Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
168125dbecb6Smrg# ---------------------------------------------
168225dbecb6Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
168325dbecb6Smrg# *_result variable of FUNC_NAME_B.
168425dbecb6Smrgfunc_propagate_result ()
168525dbecb6Smrg{
168625dbecb6Smrg    $debug_cmd
168725dbecb6Smrg
168825dbecb6Smrg    func_propagate_result_result=:
168925dbecb6Smrg    if eval "test \"\${${1}_result+set}\" = set"
169025dbecb6Smrg    then
169125dbecb6Smrg      eval "${2}_result=\$${1}_result"
169225dbecb6Smrg    else
169325dbecb6Smrg      func_propagate_result_result=false
169425dbecb6Smrg    fi
169525dbecb6Smrg}
169625dbecb6Smrg
169725dbecb6Smrg
169825dbecb6Smrg# func_run_hooks FUNC_NAME [ARG]...
169925dbecb6Smrg# ---------------------------------
170025dbecb6Smrg# Run all hook functions registered to FUNC_NAME.
170125dbecb6Smrg# It's assumed that the list of hook functions contains nothing more
170225dbecb6Smrg# than a whitespace-delimited list of legal shell function names, and
170325dbecb6Smrg# no effort is wasted trying to catch shell meta-characters or preserve
170425dbecb6Smrg# whitespace.
170525dbecb6Smrgfunc_run_hooks ()
170625dbecb6Smrg{
170725dbecb6Smrg    $debug_cmd
170825dbecb6Smrg
170925dbecb6Smrg    case " $hookable_fns " in
171025dbecb6Smrg      *" $1 "*) ;;
171125dbecb6Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17126df26cacSmrg    esac
171325dbecb6Smrg
171425dbecb6Smrg    eval _G_hook_fns=\$$1_hooks; shift
171525dbecb6Smrg
171625dbecb6Smrg    for _G_hook in $_G_hook_fns; do
171725dbecb6Smrg      func_unset "${_G_hook}_result"
171825dbecb6Smrg      eval $_G_hook '${1+"$@"}'
171925dbecb6Smrg      func_propagate_result $_G_hook func_run_hooks
172025dbecb6Smrg      if $func_propagate_result_result; then
172125dbecb6Smrg        eval set dummy "$func_run_hooks_result"; shift
172225dbecb6Smrg      fi
172325dbecb6Smrg    done
172425dbecb6Smrg}
172525dbecb6Smrg
172625dbecb6Smrg
172725dbecb6Smrg
172825dbecb6Smrg## --------------- ##
172925dbecb6Smrg## Option parsing. ##
173025dbecb6Smrg## --------------- ##
173125dbecb6Smrg
173225dbecb6Smrg# In order to add your own option parsing hooks, you must accept the
173325dbecb6Smrg# full positional parameter list from your hook function.  You may remove
173425dbecb6Smrg# or edit any options that you action, and then pass back the remaining
173525dbecb6Smrg# unprocessed options in '<hooked_function_name>_result', escaped
173625dbecb6Smrg# suitably for 'eval'.
173725dbecb6Smrg#
173825dbecb6Smrg# The '<hooked_function_name>_result' variable is automatically unset
173925dbecb6Smrg# before your hook gets called; for best performance, only set the
174025dbecb6Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
174125dbecb6Smrg# function unnecessarily because it can be an expensive operation on some
174225dbecb6Smrg# machines).
174325dbecb6Smrg#
174425dbecb6Smrg# Like this:
174525dbecb6Smrg#
174625dbecb6Smrg#    my_options_prep ()
174725dbecb6Smrg#    {
174825dbecb6Smrg#        $debug_cmd
174925dbecb6Smrg#
175025dbecb6Smrg#        # Extend the existing usage message.
175125dbecb6Smrg#        usage_message=$usage_message'
175225dbecb6Smrg#      -s, --silent       don'\''t print informational messages
175325dbecb6Smrg#    '
175425dbecb6Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
175525dbecb6Smrg#        # my_options_prep_result variable intact.
175625dbecb6Smrg#    }
175725dbecb6Smrg#    func_add_hook func_options_prep my_options_prep
175825dbecb6Smrg#
175925dbecb6Smrg#
176025dbecb6Smrg#    my_silent_option ()
176125dbecb6Smrg#    {
176225dbecb6Smrg#        $debug_cmd
176325dbecb6Smrg#
176425dbecb6Smrg#        args_changed=false
176525dbecb6Smrg#
176625dbecb6Smrg#        # Note that, for efficiency, we parse as many options as we can
176725dbecb6Smrg#        # recognise in a loop before passing the remainder back to the
176825dbecb6Smrg#        # caller on the first unrecognised argument we encounter.
176925dbecb6Smrg#        while test $# -gt 0; do
177025dbecb6Smrg#          opt=$1; shift
177125dbecb6Smrg#          case $opt in
177225dbecb6Smrg#            --silent|-s) opt_silent=:
177325dbecb6Smrg#                         args_changed=:
177425dbecb6Smrg#                         ;;
177525dbecb6Smrg#            # Separate non-argument short options:
177625dbecb6Smrg#            -s*)         func_split_short_opt "$_G_opt"
177725dbecb6Smrg#                         set dummy "$func_split_short_opt_name" \
177825dbecb6Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
177925dbecb6Smrg#                         shift
178025dbecb6Smrg#                         args_changed=:
178125dbecb6Smrg#                         ;;
178225dbecb6Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
178325dbecb6Smrg#                         # is added back to "$@" in case we need it later,
178425dbecb6Smrg#                         # if $args_changed was set to 'true'.
178525dbecb6Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
178625dbecb6Smrg#          esac
178725dbecb6Smrg#        done
178825dbecb6Smrg#
178925dbecb6Smrg#        # Only call 'func_quote' here if we processed at least one argument.
179025dbecb6Smrg#        if $args_changed; then
179125dbecb6Smrg#          func_quote eval ${1+"$@"}
179225dbecb6Smrg#          my_silent_option_result=$func_quote_result
179325dbecb6Smrg#        fi
179425dbecb6Smrg#    }
179525dbecb6Smrg#    func_add_hook func_parse_options my_silent_option
179625dbecb6Smrg#
179725dbecb6Smrg#
179825dbecb6Smrg#    my_option_validation ()
179925dbecb6Smrg#    {
180025dbecb6Smrg#        $debug_cmd
180125dbecb6Smrg#
180225dbecb6Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
180325dbecb6Smrg#    '--silent' and '--verbose' options are mutually exclusive."
180425dbecb6Smrg#    }
180525dbecb6Smrg#    func_add_hook func_validate_options my_option_validation
180625dbecb6Smrg#
180725dbecb6Smrg# You'll also need to manually amend $usage_message to reflect the extra
180825dbecb6Smrg# options you parse.  It's preferable to append if you can, so that
180925dbecb6Smrg# multiple option parsing hooks can be added safely.
181025dbecb6Smrg
181125dbecb6Smrg
181225dbecb6Smrg# func_options_finish [ARG]...
181325dbecb6Smrg# ----------------------------
181425dbecb6Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
181525dbecb6Smrgfunc_options_finish ()
181625dbecb6Smrg{
181725dbecb6Smrg    $debug_cmd
181825dbecb6Smrg
181925dbecb6Smrg    func_run_hooks func_options ${1+"$@"}
182025dbecb6Smrg    func_propagate_result func_run_hooks func_options_finish
18216df26cacSmrg}
18226df26cacSmrg
18236df26cacSmrg
182425dbecb6Smrg# func_options [ARG]...
182525dbecb6Smrg# ---------------------
182625dbecb6Smrg# All the functions called inside func_options are hookable. See the
182725dbecb6Smrg# individual implementations for details.
182825dbecb6Smrgfunc_hookable func_options
182925dbecb6Smrgfunc_options ()
18306df26cacSmrg{
183125dbecb6Smrg    $debug_cmd
1832b68e1f86Smrg
183325dbecb6Smrg    _G_options_quoted=false
1834b68e1f86Smrg
183525dbecb6Smrg    for my_func in options_prep parse_options validate_options options_finish
183625dbecb6Smrg    do
183725dbecb6Smrg      func_unset func_${my_func}_result
183825dbecb6Smrg      func_unset func_run_hooks_result
183925dbecb6Smrg      eval func_$my_func '${1+"$@"}'
184025dbecb6Smrg      func_propagate_result func_$my_func func_options
184125dbecb6Smrg      if $func_propagate_result_result; then
184225dbecb6Smrg        eval set dummy "$func_options_result"; shift
184325dbecb6Smrg        _G_options_quoted=:
184425dbecb6Smrg      fi
184525dbecb6Smrg    done
184625dbecb6Smrg
184725dbecb6Smrg    $_G_options_quoted || {
184825dbecb6Smrg      # As we (func_options) are top-level options-parser function and
184925dbecb6Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
185025dbecb6Smrg      # caller.
185125dbecb6Smrg      func_quote eval ${1+"$@"}
185225dbecb6Smrg      func_options_result=$func_quote_result
185325dbecb6Smrg    }
18546df26cacSmrg}
18556df26cacSmrg
18566df26cacSmrg
185725dbecb6Smrg# func_options_prep [ARG]...
185825dbecb6Smrg# --------------------------
185925dbecb6Smrg# All initialisations required before starting the option parse loop.
186025dbecb6Smrg# Note that when calling hook functions, we pass through the list of
186125dbecb6Smrg# positional parameters.  If a hook function modifies that list, and
186225dbecb6Smrg# needs to propagate that back to rest of this script, then the complete
186325dbecb6Smrg# modified list must be put in 'func_run_hooks_result' before returning.
186425dbecb6Smrgfunc_hookable func_options_prep
186525dbecb6Smrgfunc_options_prep ()
18666df26cacSmrg{
186725dbecb6Smrg    $debug_cmd
18686df26cacSmrg
186925dbecb6Smrg    # Option defaults:
187025dbecb6Smrg    opt_verbose=false
187125dbecb6Smrg    opt_warning_types=
1872b68e1f86Smrg
187325dbecb6Smrg    func_run_hooks func_options_prep ${1+"$@"}
187425dbecb6Smrg    func_propagate_result func_run_hooks func_options_prep
18756df26cacSmrg}
18766df26cacSmrg
1877b68e1f86Smrg
187825dbecb6Smrg# func_parse_options [ARG]...
187925dbecb6Smrg# ---------------------------
188025dbecb6Smrg# The main option parsing loop.
188125dbecb6Smrgfunc_hookable func_parse_options
188225dbecb6Smrgfunc_parse_options ()
18836df26cacSmrg{
188425dbecb6Smrg    $debug_cmd
188525dbecb6Smrg
188625dbecb6Smrg    _G_parse_options_requote=false
188725dbecb6Smrg    # this just eases exit handling
188825dbecb6Smrg    while test $# -gt 0; do
188925dbecb6Smrg      # Defer to hook functions for initial option parsing, so they
189025dbecb6Smrg      # get priority in the event of reusing an option name.
189125dbecb6Smrg      func_run_hooks func_parse_options ${1+"$@"}
189225dbecb6Smrg      func_propagate_result func_run_hooks func_parse_options
189325dbecb6Smrg      if $func_propagate_result_result; then
189425dbecb6Smrg        eval set dummy "$func_parse_options_result"; shift
189525dbecb6Smrg        # Even though we may have changed "$@", we passed the "$@" array
189625dbecb6Smrg        # down into the hook and it quoted it for us (because we are in
189725dbecb6Smrg        # this if-branch).  No need to quote it again.
189825dbecb6Smrg        _G_parse_options_requote=false
189925dbecb6Smrg      fi
1900b68e1f86Smrg
190125dbecb6Smrg      # Break out of the loop if we already parsed every option.
190225dbecb6Smrg      test $# -gt 0 || break
1903b68e1f86Smrg
190425dbecb6Smrg      # We expect that one of the options parsed in this function matches
190525dbecb6Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
190625dbecb6Smrg      _G_match_parse_options=:
190725dbecb6Smrg      _G_opt=$1
190825dbecb6Smrg      shift
190925dbecb6Smrg      case $_G_opt in
191025dbecb6Smrg        --debug|-x)   debug_cmd='set -x'
191125dbecb6Smrg                      func_echo "enabling shell trace mode" >&2
191225dbecb6Smrg                      $debug_cmd
191325dbecb6Smrg                      ;;
191425dbecb6Smrg
191525dbecb6Smrg        --no-warnings|--no-warning|--no-warn)
191625dbecb6Smrg                      set dummy --warnings none ${1+"$@"}
191725dbecb6Smrg                      shift
191825dbecb6Smrg		      ;;
191925dbecb6Smrg
192025dbecb6Smrg        --warnings|--warning|-W)
192125dbecb6Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
192225dbecb6Smrg                        _G_parse_options_requote=:
192325dbecb6Smrg                        break
192425dbecb6Smrg                      fi
192525dbecb6Smrg                      case " $warning_categories $1" in
192625dbecb6Smrg                        *" $1 "*)
192725dbecb6Smrg                          # trailing space prevents matching last $1 above
192825dbecb6Smrg                          func_append_uniq opt_warning_types " $1"
192925dbecb6Smrg                          ;;
193025dbecb6Smrg                        *all)
193125dbecb6Smrg                          opt_warning_types=$warning_categories
193225dbecb6Smrg                          ;;
193325dbecb6Smrg                        *none)
193425dbecb6Smrg                          opt_warning_types=none
193525dbecb6Smrg                          warning_func=:
193625dbecb6Smrg                          ;;
193725dbecb6Smrg                        *error)
193825dbecb6Smrg                          opt_warning_types=$warning_categories
193925dbecb6Smrg                          warning_func=func_fatal_error
194025dbecb6Smrg                          ;;
194125dbecb6Smrg                        *)
194225dbecb6Smrg                          func_fatal_error \
194325dbecb6Smrg                             "unsupported warning category: '$1'"
194425dbecb6Smrg                          ;;
194525dbecb6Smrg                      esac
194625dbecb6Smrg                      shift
194725dbecb6Smrg                      ;;
194825dbecb6Smrg
194925dbecb6Smrg        --verbose|-v) opt_verbose=: ;;
195025dbecb6Smrg        --version)    func_version ;;
195125dbecb6Smrg        -\?|-h)       func_usage ;;
195225dbecb6Smrg        --help)       func_help ;;
195325dbecb6Smrg
195425dbecb6Smrg	# Separate optargs to long options (plugins may need this):
195525dbecb6Smrg	--*=*)        func_split_equals "$_G_opt"
195625dbecb6Smrg	              set dummy "$func_split_equals_lhs" \
195725dbecb6Smrg                          "$func_split_equals_rhs" ${1+"$@"}
195825dbecb6Smrg                      shift
195925dbecb6Smrg                      ;;
196025dbecb6Smrg
196125dbecb6Smrg       # Separate optargs to short options:
196225dbecb6Smrg        -W*)
196325dbecb6Smrg                      func_split_short_opt "$_G_opt"
196425dbecb6Smrg                      set dummy "$func_split_short_opt_name" \
196525dbecb6Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
196625dbecb6Smrg                      shift
196725dbecb6Smrg                      ;;
196825dbecb6Smrg
196925dbecb6Smrg        # Separate non-argument short options:
197025dbecb6Smrg        -\?*|-h*|-v*|-x*)
197125dbecb6Smrg                      func_split_short_opt "$_G_opt"
197225dbecb6Smrg                      set dummy "$func_split_short_opt_name" \
197325dbecb6Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
197425dbecb6Smrg                      shift
197525dbecb6Smrg                      ;;
197625dbecb6Smrg
197725dbecb6Smrg        --)           _G_parse_options_requote=: ; break ;;
197825dbecb6Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
197925dbecb6Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
198025dbecb6Smrg                      _G_match_parse_options=false
198125dbecb6Smrg                      break
198225dbecb6Smrg                      ;;
198325dbecb6Smrg      esac
198425dbecb6Smrg
198525dbecb6Smrg      if $_G_match_parse_options; then
198625dbecb6Smrg        _G_parse_options_requote=:
1987b68e1f86Smrg      fi
198825dbecb6Smrg    done
198925dbecb6Smrg
199025dbecb6Smrg    if $_G_parse_options_requote; then
199125dbecb6Smrg      # save modified positional parameters for caller
199225dbecb6Smrg      func_quote eval ${1+"$@"}
199325dbecb6Smrg      func_parse_options_result=$func_quote_result
19946df26cacSmrg    fi
1995b68e1f86Smrg}
19966df26cacSmrg
199725dbecb6Smrg
199825dbecb6Smrg# func_validate_options [ARG]...
199925dbecb6Smrg# ------------------------------
200025dbecb6Smrg# Perform any sanity checks on option settings and/or unconsumed
200125dbecb6Smrg# arguments.
200225dbecb6Smrgfunc_hookable func_validate_options
200325dbecb6Smrgfunc_validate_options ()
20043bfa90b6Smrg{
200525dbecb6Smrg    $debug_cmd
2006b68e1f86Smrg
200725dbecb6Smrg    # Display all warnings if -W was not given.
200825dbecb6Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009b68e1f86Smrg
201025dbecb6Smrg    func_run_hooks func_validate_options ${1+"$@"}
201125dbecb6Smrg    func_propagate_result func_run_hooks func_validate_options
20123bfa90b6Smrg
201325dbecb6Smrg    # Bail if the options were screwed!
201425dbecb6Smrg    $exit_cmd $EXIT_FAILURE
2015b68e1f86Smrg}
2016b68e1f86Smrg
201725dbecb6Smrg
201825dbecb6Smrg
201925dbecb6Smrg## ----------------- ##
202025dbecb6Smrg## Helper functions. ##
202125dbecb6Smrg## ----------------- ##
202225dbecb6Smrg
202325dbecb6Smrg# This section contains the helper functions used by the rest of the
202425dbecb6Smrg# hookable option parser framework in ascii-betical order.
202525dbecb6Smrg
202625dbecb6Smrg
202725dbecb6Smrg# func_fatal_help ARG...
202825dbecb6Smrg# ----------------------
202925dbecb6Smrg# Echo program name prefixed message to standard error, followed by
203025dbecb6Smrg# a help hint, and exit.
203125dbecb6Smrgfunc_fatal_help ()
2032b68e1f86Smrg{
203325dbecb6Smrg    $debug_cmd
20343bfa90b6Smrg
203525dbecb6Smrg    eval \$ECHO \""Usage: $usage"\"
203625dbecb6Smrg    eval \$ECHO \""$fatal_help"\"
203725dbecb6Smrg    func_error ${1+"$@"}
203825dbecb6Smrg    exit $EXIT_FAILURE
2039b68e1f86Smrg}
2040b68e1f86Smrg
204125dbecb6Smrg
204225dbecb6Smrg# func_help
204325dbecb6Smrg# ---------
204425dbecb6Smrg# Echo long help message to standard output and exit.
2045b68e1f86Smrgfunc_help ()
2046b68e1f86Smrg{
204725dbecb6Smrg    $debug_cmd
204825dbecb6Smrg
204925dbecb6Smrg    func_usage_message
205025dbecb6Smrg    $ECHO "$long_help_message"
205125dbecb6Smrg    exit 0
2052b68e1f86Smrg}
2053b68e1f86Smrg
205425dbecb6Smrg
205525dbecb6Smrg# func_missing_arg ARGNAME
205625dbecb6Smrg# ------------------------
2057b68e1f86Smrg# Echo program name prefixed message to standard error and set global
2058b68e1f86Smrg# exit_cmd.
2059b68e1f86Smrgfunc_missing_arg ()
2060b68e1f86Smrg{
206125dbecb6Smrg    $debug_cmd
20623bfa90b6Smrg
206325dbecb6Smrg    func_error "Missing argument for '$1'."
2064b68e1f86Smrg    exit_cmd=exit
20656df26cacSmrg}
20666df26cacSmrg
20676df26cacSmrg
206825dbecb6Smrg# func_split_equals STRING
206925dbecb6Smrg# ------------------------
207025dbecb6Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
207125dbecb6Smrg# after splitting STRING at the '=' sign.
207225dbecb6Smrgtest -z "$_G_HAVE_XSI_OPS" \
207325dbecb6Smrg    && (eval 'x=a/b/c;
207425dbecb6Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
207525dbecb6Smrg    && _G_HAVE_XSI_OPS=yes
207625dbecb6Smrg
207725dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"
207825dbecb6Smrgthen
207925dbecb6Smrg  # This is an XSI compatible shell, allowing a faster implementation...
208025dbecb6Smrg  eval 'func_split_equals ()
208125dbecb6Smrg  {
208225dbecb6Smrg      $debug_cmd
208325dbecb6Smrg
208425dbecb6Smrg      func_split_equals_lhs=${1%%=*}
208525dbecb6Smrg      func_split_equals_rhs=${1#*=}
208625dbecb6Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
208725dbecb6Smrg        func_split_equals_rhs=
208825dbecb6Smrg      fi
208925dbecb6Smrg  }'
209025dbecb6Smrgelse
209125dbecb6Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
209225dbecb6Smrg  func_split_equals ()
209325dbecb6Smrg  {
209425dbecb6Smrg      $debug_cmd
209525dbecb6Smrg
209625dbecb6Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
209725dbecb6Smrg      func_split_equals_rhs=
209825dbecb6Smrg      test "x$func_split_equals_lhs=" = "x$1" \
209925dbecb6Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
210025dbecb6Smrg  }
210125dbecb6Smrgfi #func_split_equals
210225dbecb6Smrg
210325dbecb6Smrg
210425dbecb6Smrg# func_split_short_opt SHORTOPT
210525dbecb6Smrg# -----------------------------
21063bfa90b6Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
21073bfa90b6Smrg# variables after splitting SHORTOPT after the 2nd character.
210825dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"
210925dbecb6Smrgthen
211025dbecb6Smrg  # This is an XSI compatible shell, allowing a faster implementation...
211125dbecb6Smrg  eval 'func_split_short_opt ()
211225dbecb6Smrg  {
211325dbecb6Smrg      $debug_cmd
211425dbecb6Smrg
211525dbecb6Smrg      func_split_short_opt_arg=${1#??}
211625dbecb6Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
211725dbecb6Smrg  }'
211825dbecb6Smrgelse
211925dbecb6Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
212025dbecb6Smrg  func_split_short_opt ()
212125dbecb6Smrg  {
212225dbecb6Smrg      $debug_cmd
212325dbecb6Smrg
212425dbecb6Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
212525dbecb6Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
212625dbecb6Smrg  }
212725dbecb6Smrgfi #func_split_short_opt
212825dbecb6Smrg
212925dbecb6Smrg
213025dbecb6Smrg# func_usage
213125dbecb6Smrg# ----------
213225dbecb6Smrg# Echo short help message to standard output and exit.
213325dbecb6Smrgfunc_usage ()
21343bfa90b6Smrg{
213525dbecb6Smrg    $debug_cmd
21366df26cacSmrg
213725dbecb6Smrg    func_usage_message
213825dbecb6Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
213925dbecb6Smrg    exit 0
214025dbecb6Smrg}
21413bfa90b6Smrg
21423bfa90b6Smrg
214325dbecb6Smrg# func_usage_message
214425dbecb6Smrg# ------------------
214525dbecb6Smrg# Echo short help message to standard output.
214625dbecb6Smrgfunc_usage_message ()
21473bfa90b6Smrg{
214825dbecb6Smrg    $debug_cmd
214925dbecb6Smrg
215025dbecb6Smrg    eval \$ECHO \""Usage: $usage"\"
215125dbecb6Smrg    echo
215225dbecb6Smrg    $SED -n 's|^# ||
215325dbecb6Smrg        /^Written by/{
215425dbecb6Smrg          x;p;x
215525dbecb6Smrg        }
215625dbecb6Smrg	h
215725dbecb6Smrg	/^Written by/q' < "$progpath"
215825dbecb6Smrg    echo
215925dbecb6Smrg    eval \$ECHO \""$usage_message"\"
216025dbecb6Smrg}
21613bfa90b6Smrg
21623bfa90b6Smrg
216325dbecb6Smrg# func_version
216425dbecb6Smrg# ------------
216525dbecb6Smrg# Echo version message to standard output and exit.
216625dbecb6Smrg# The version message is extracted from the calling file's header
216725dbecb6Smrg# comments, with leading '# ' stripped:
216825dbecb6Smrg#   1. First display the progname and version
216925dbecb6Smrg#   2. Followed by the header comment line matching  /^# Written by /
217025dbecb6Smrg#   3. Then a blank line followed by the first following line matching
217125dbecb6Smrg#      /^# Copyright /
217225dbecb6Smrg#   4. Immediately followed by any lines between the previous matches,
217325dbecb6Smrg#      except lines preceding the intervening completely blank line.
217425dbecb6Smrg# For example, see the header comments of this file.
217525dbecb6Smrgfunc_version ()
217625dbecb6Smrg{
217725dbecb6Smrg    $debug_cmd
2178b68e1f86Smrg
217925dbecb6Smrg    printf '%s\n' "$progname $scriptversion"
218025dbecb6Smrg    $SED -n '
218125dbecb6Smrg        /^# Written by /!b
218225dbecb6Smrg        s|^# ||; p; n
2183b68e1f86Smrg
218425dbecb6Smrg        :fwd2blnk
218525dbecb6Smrg        /./ {
218625dbecb6Smrg          n
218725dbecb6Smrg          b fwd2blnk
218825dbecb6Smrg        }
218925dbecb6Smrg        p; n
219025dbecb6Smrg
219125dbecb6Smrg        :holdwrnt
219225dbecb6Smrg        s|^# ||
219325dbecb6Smrg        s|^# *$||
219425dbecb6Smrg        /^Copyright /!{
219525dbecb6Smrg          /./H
219625dbecb6Smrg          n
219725dbecb6Smrg          b holdwrnt
219825dbecb6Smrg        }
2199b68e1f86Smrg
220025dbecb6Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
220125dbecb6Smrg        G
220225dbecb6Smrg        s|\(\n\)\n*|\1|g
220325dbecb6Smrg        p; q' < "$progpath"
22046df26cacSmrg
220525dbecb6Smrg    exit $?
220625dbecb6Smrg}
22076df26cacSmrg
22086df26cacSmrg
220925dbecb6Smrg# Local variables:
221025dbecb6Smrg# mode: shell-script
221125dbecb6Smrg# sh-indentation: 2
221225dbecb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
221325dbecb6Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
221425dbecb6Smrg# time-stamp-time-zone: "UTC"
221525dbecb6Smrg# End:
22166df26cacSmrg
221725dbecb6Smrg# Set a version string.
221825dbecb6Smrgscriptversion='(GNU libtool) 2.4.7'
2219b68e1f86Smrg
22203bfa90b6Smrg
222125dbecb6Smrg# func_echo ARG...
222225dbecb6Smrg# ----------------
222325dbecb6Smrg# Libtool also displays the current mode in messages, so override
222425dbecb6Smrg# funclib.sh func_echo with this custom definition.
222525dbecb6Smrgfunc_echo ()
22263bfa90b6Smrg{
222725dbecb6Smrg    $debug_cmd
22283bfa90b6Smrg
222925dbecb6Smrg    _G_message=$*
22303bfa90b6Smrg
223125dbecb6Smrg    func_echo_IFS=$IFS
223225dbecb6Smrg    IFS=$nl
223325dbecb6Smrg    for _G_line in $_G_message; do
223425dbecb6Smrg      IFS=$func_echo_IFS
223525dbecb6Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
223625dbecb6Smrg    done
223725dbecb6Smrg    IFS=$func_echo_IFS
223825dbecb6Smrg}
22393bfa90b6Smrg
22403bfa90b6Smrg
224125dbecb6Smrg# func_warning ARG...
224225dbecb6Smrg# -------------------
224325dbecb6Smrg# Libtool warnings are not categorized, so override funclib.sh
224425dbecb6Smrg# func_warning with this simpler definition.
224525dbecb6Smrgfunc_warning ()
22463bfa90b6Smrg{
224725dbecb6Smrg    $debug_cmd
22483bfa90b6Smrg
224925dbecb6Smrg    $warning_func ${1+"$@"}
225025dbecb6Smrg}
22513bfa90b6Smrg
22523bfa90b6Smrg
225325dbecb6Smrg## ---------------- ##
225425dbecb6Smrg## Options parsing. ##
225525dbecb6Smrg## ---------------- ##
225625dbecb6Smrg
225725dbecb6Smrg# Hook in the functions to make sure our own options are parsed during
225825dbecb6Smrg# the option parsing loop.
225925dbecb6Smrg
226025dbecb6Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
226125dbecb6Smrg
226225dbecb6Smrg# Short help message in response to '-h'.
226325dbecb6Smrgusage_message="Options:
226425dbecb6Smrg       --config             show all configuration variables
226525dbecb6Smrg       --debug              enable verbose shell tracing
226625dbecb6Smrg   -n, --dry-run            display commands without modifying any files
226725dbecb6Smrg       --features           display basic configuration information and exit
226825dbecb6Smrg       --mode=MODE          use operation mode MODE
226925dbecb6Smrg       --no-warnings        equivalent to '-Wnone'
227025dbecb6Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
227125dbecb6Smrg       --quiet, --silent    don't print informational messages
227225dbecb6Smrg       --tag=TAG            use configuration variables from tag TAG
227325dbecb6Smrg   -v, --verbose            print more informational messages than default
227425dbecb6Smrg       --version            print version information
227525dbecb6Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
227625dbecb6Smrg   -h, --help, --help-all   print short, long, or detailed help message
227725dbecb6Smrg"
22783bfa90b6Smrg
227925dbecb6Smrg# Additional text appended to 'usage_message' in response to '--help'.
228025dbecb6Smrgfunc_help ()
22813bfa90b6Smrg{
228225dbecb6Smrg    $debug_cmd
228325dbecb6Smrg
228425dbecb6Smrg    func_usage_message
228525dbecb6Smrg    $ECHO "$long_help_message
228625dbecb6Smrg
228725dbecb6SmrgMODE must be one of the following:
228825dbecb6Smrg
228925dbecb6Smrg       clean           remove files from the build directory
229025dbecb6Smrg       compile         compile a source file into a libtool object
229125dbecb6Smrg       execute         automatically set library path, then run a program
229225dbecb6Smrg       finish          complete the installation of libtool libraries
229325dbecb6Smrg       install         install libraries or executables
229425dbecb6Smrg       link            create a library or an executable
229525dbecb6Smrg       uninstall       remove libraries from an installed directory
229625dbecb6Smrg
229725dbecb6SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
229825dbecb6Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
229925dbecb6SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
230025dbecb6Smrg
230125dbecb6SmrgWhen reporting a bug, please describe a test case to reproduce it and
230225dbecb6Smrginclude the following information:
230325dbecb6Smrg
230425dbecb6Smrg       host-triplet:   $host
230525dbecb6Smrg       shell:          $SHELL
230625dbecb6Smrg       compiler:       $LTCC
230725dbecb6Smrg       compiler flags: $LTCFLAGS
230825dbecb6Smrg       linker:         $LD (gnu? $with_gnu_ld)
230925dbecb6Smrg       version:        $progname (GNU libtool) 2.4.7
231025dbecb6Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
231125dbecb6Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
231225dbecb6Smrg
231325dbecb6SmrgReport bugs to <bug-libtool@gnu.org>.
231425dbecb6SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
231525dbecb6SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
231625dbecb6Smrg    exit 0
231725dbecb6Smrg}
231825dbecb6Smrg
231925dbecb6Smrg
232025dbecb6Smrg# func_lo2o OBJECT-NAME
232125dbecb6Smrg# ---------------------
232225dbecb6Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
232325dbecb6Smrg# object suffix.
23243bfa90b6Smrg
232525dbecb6Smrglo2o=s/\\.lo\$/.$objext/
232625dbecb6Smrgo2lo=s/\\.$objext\$/.lo/
23273bfa90b6Smrg
232825dbecb6Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
232925dbecb6Smrg  eval 'func_lo2o ()
233025dbecb6Smrg  {
233125dbecb6Smrg    case $1 in
233225dbecb6Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
233325dbecb6Smrg      *   ) func_lo2o_result=$1               ;;
233425dbecb6Smrg    esac
233525dbecb6Smrg  }'
233625dbecb6Smrg
233725dbecb6Smrg  # func_xform LIBOBJ-OR-SOURCE
233825dbecb6Smrg  # ---------------------------
233925dbecb6Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
234025dbecb6Smrg  # suffix to a '.lo' libtool-object suffix.
234125dbecb6Smrg  eval 'func_xform ()
234225dbecb6Smrg  {
234325dbecb6Smrg    func_xform_result=${1%.*}.lo
234425dbecb6Smrg  }'
234525dbecb6Smrgelse
234625dbecb6Smrg  # ...otherwise fall back to using sed.
234725dbecb6Smrg  func_lo2o ()
234825dbecb6Smrg  {
234925dbecb6Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
235025dbecb6Smrg  }
235125dbecb6Smrg
235225dbecb6Smrg  func_xform ()
235325dbecb6Smrg  {
235425dbecb6Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
235525dbecb6Smrg  }
235625dbecb6Smrgfi
235725dbecb6Smrg
235825dbecb6Smrg
235925dbecb6Smrg# func_fatal_configuration ARG...
236025dbecb6Smrg# -------------------------------
2361b68e1f86Smrg# Echo program name prefixed message to standard error, followed by
2362b68e1f86Smrg# a configuration failure hint, and exit.
2363b68e1f86Smrgfunc_fatal_configuration ()
2364b68e1f86Smrg{
236525dbecb6Smrg    func_fatal_error ${1+"$@"} \
236625dbecb6Smrg      "See the $PACKAGE documentation for more information." \
236725dbecb6Smrg      "Fatal configuration error."
2368b68e1f86Smrg}
23696df26cacSmrg
237016fd1166Smrg
2371b68e1f86Smrg# func_config
237225dbecb6Smrg# -----------
2373b68e1f86Smrg# Display the configuration for all the tags in this script.
2374b68e1f86Smrgfunc_config ()
2375b68e1f86Smrg{
2376b68e1f86Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377b68e1f86Smrg    re_endcf='^# ### END LIBTOOL'
2378b68e1f86Smrg
2379b68e1f86Smrg    # Default configuration.
2380b68e1f86Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23816df26cacSmrg
23826df26cacSmrg    # Now print the configurations for the tags.
23836df26cacSmrg    for tagname in $taglist; do
2384b68e1f86Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
23856df26cacSmrg    done
23866df26cacSmrg
2387b68e1f86Smrg    exit $?
2388b68e1f86Smrg}
23896df26cacSmrg
239025dbecb6Smrg
2391b68e1f86Smrg# func_features
239225dbecb6Smrg# -------------
2393b68e1f86Smrg# Display the features supported by this script.
2394b68e1f86Smrgfunc_features ()
2395b68e1f86Smrg{
23963bfa90b6Smrg    echo "host: $host"
239725dbecb6Smrg    if test yes = "$build_libtool_libs"; then
23983bfa90b6Smrg      echo "enable shared libraries"
23996df26cacSmrg    else
24003bfa90b6Smrg      echo "disable shared libraries"
24016df26cacSmrg    fi
240225dbecb6Smrg    if test yes = "$build_old_libs"; then
24033bfa90b6Smrg      echo "enable static libraries"
24046df26cacSmrg    else
24053bfa90b6Smrg      echo "disable static libraries"
24066df26cacSmrg    fi
2407b68e1f86Smrg
24086df26cacSmrg    exit $?
2409b68e1f86Smrg}
24106df26cacSmrg
241125dbecb6Smrg
241225dbecb6Smrg# func_enable_tag TAGNAME
241325dbecb6Smrg# -----------------------
2414b68e1f86Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415b68e1f86Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416b68e1f86Smrg# variable here.
2417b68e1f86Smrgfunc_enable_tag ()
2418b68e1f86Smrg{
241925dbecb6Smrg    # Global variable:
242025dbecb6Smrg    tagname=$1
24216df26cacSmrg
242225dbecb6Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
242325dbecb6Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
242425dbecb6Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24256df26cacSmrg
242625dbecb6Smrg    # Validate tagname.
242725dbecb6Smrg    case $tagname in
242825dbecb6Smrg      *[!-_A-Za-z0-9,/]*)
242925dbecb6Smrg        func_fatal_error "invalid tag name: $tagname"
243025dbecb6Smrg        ;;
243125dbecb6Smrg    esac
24326df26cacSmrg
243325dbecb6Smrg    # Don't test for the "default" C tag, as we know it's
243425dbecb6Smrg    # there but not specially marked.
243525dbecb6Smrg    case $tagname in
243625dbecb6Smrg        CC) ;;
2437b68e1f86Smrg    *)
243825dbecb6Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
243925dbecb6Smrg	  taglist="$taglist $tagname"
244025dbecb6Smrg
244125dbecb6Smrg	  # Evaluate the configuration.  Be careful to quote the path
244225dbecb6Smrg	  # and the sed script, to avoid splitting on whitespace, but
244325dbecb6Smrg	  # also don't use non-portable quotes within backquotes within
244425dbecb6Smrg	  # quotes we have to do it in 2 steps:
244525dbecb6Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
244625dbecb6Smrg	  eval "$extractedcf"
244725dbecb6Smrg        else
244825dbecb6Smrg	  func_error "ignoring unknown tag $tagname"
244925dbecb6Smrg        fi
245025dbecb6Smrg        ;;
245125dbecb6Smrg    esac
2452b68e1f86Smrg}
2453b68e1f86Smrg
245425dbecb6Smrg
24553bfa90b6Smrg# func_check_version_match
245625dbecb6Smrg# ------------------------
24573bfa90b6Smrg# Ensure that we are using m4 macros, and libtool script from the same
24583bfa90b6Smrg# release of libtool.
24593bfa90b6Smrgfunc_check_version_match ()
2460b68e1f86Smrg{
246125dbecb6Smrg    if test "$package_revision" != "$macro_revision"; then
246225dbecb6Smrg      if test "$VERSION" != "$macro_version"; then
246325dbecb6Smrg        if test -z "$macro_version"; then
246425dbecb6Smrg          cat >&2 <<_LT_EOF
24653bfa90b6Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24663bfa90b6Smrg$progname: definition of this LT_INIT comes from an older release.
24673bfa90b6Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24683bfa90b6Smrg$progname: and run autoconf again.
24693bfa90b6Smrg_LT_EOF
247025dbecb6Smrg        else
247125dbecb6Smrg          cat >&2 <<_LT_EOF
24723bfa90b6Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24733bfa90b6Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
24743bfa90b6Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24753bfa90b6Smrg$progname: and run autoconf again.
24763bfa90b6Smrg_LT_EOF
247725dbecb6Smrg        fi
247825dbecb6Smrg      else
247925dbecb6Smrg        cat >&2 <<_LT_EOF
24803bfa90b6Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
24813bfa90b6Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
24823bfa90b6Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
24833bfa90b6Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
24843bfa90b6Smrg_LT_EOF
248525dbecb6Smrg      fi
24866df26cacSmrg
248725dbecb6Smrg      exit $EXIT_MISMATCH
248825dbecb6Smrg    fi
24893bfa90b6Smrg}
24903bfa90b6Smrg
24913bfa90b6Smrg
249225dbecb6Smrg# libtool_options_prep [ARG]...
249325dbecb6Smrg# -----------------------------
249425dbecb6Smrg# Preparation for options parsed by libtool.
249525dbecb6Smrglibtool_options_prep ()
249625dbecb6Smrg{
249725dbecb6Smrg    $debug_mode
24983bfa90b6Smrg
249925dbecb6Smrg    # Option defaults:
250025dbecb6Smrg    opt_config=false
250125dbecb6Smrg    opt_dlopen=
250225dbecb6Smrg    opt_dry_run=false
250325dbecb6Smrg    opt_help=false
250425dbecb6Smrg    opt_mode=
250525dbecb6Smrg    opt_preserve_dup_deps=false
250625dbecb6Smrg    opt_quiet=false
25073bfa90b6Smrg
250825dbecb6Smrg    nonopt=
250925dbecb6Smrg    preserve_args=
25103bfa90b6Smrg
251125dbecb6Smrg    _G_rc_lt_options_prep=:
25123bfa90b6Smrg
251325dbecb6Smrg    # Shorthand for --mode=foo, only valid as the first argument
251425dbecb6Smrg    case $1 in
251525dbecb6Smrg    clean|clea|cle|cl)
251625dbecb6Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
251725dbecb6Smrg      ;;
251825dbecb6Smrg    compile|compil|compi|comp|com|co|c)
251925dbecb6Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
252025dbecb6Smrg      ;;
252125dbecb6Smrg    execute|execut|execu|exec|exe|ex|e)
252225dbecb6Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
252325dbecb6Smrg      ;;
252425dbecb6Smrg    finish|finis|fini|fin|fi|f)
252525dbecb6Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
252625dbecb6Smrg      ;;
252725dbecb6Smrg    install|instal|insta|inst|ins|in|i)
252825dbecb6Smrg      shift; set dummy --mode install ${1+"$@"}; shift
252925dbecb6Smrg      ;;
253025dbecb6Smrg    link|lin|li|l)
253125dbecb6Smrg      shift; set dummy --mode link ${1+"$@"}; shift
253225dbecb6Smrg      ;;
253325dbecb6Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
253425dbecb6Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
253525dbecb6Smrg      ;;
253625dbecb6Smrg    *)
253725dbecb6Smrg      _G_rc_lt_options_prep=false
253825dbecb6Smrg      ;;
2539b68e1f86Smrg    esac
2540b68e1f86Smrg
254125dbecb6Smrg    if $_G_rc_lt_options_prep; then
254225dbecb6Smrg      # Pass back the list of options.
254325dbecb6Smrg      func_quote eval ${1+"$@"}
254425dbecb6Smrg      libtool_options_prep_result=$func_quote_result
254525dbecb6Smrg    fi
254625dbecb6Smrg}
254725dbecb6Smrgfunc_add_hook func_options_prep libtool_options_prep
25483bfa90b6Smrg
25493bfa90b6Smrg
255025dbecb6Smrg# libtool_parse_options [ARG]...
255125dbecb6Smrg# ---------------------------------
255225dbecb6Smrg# Provide handling for libtool specific options.
255325dbecb6Smrglibtool_parse_options ()
255425dbecb6Smrg{
255525dbecb6Smrg    $debug_cmd
2556b68e1f86Smrg
255725dbecb6Smrg    _G_rc_lt_parse_options=false
25586df26cacSmrg
255925dbecb6Smrg    # Perform our own loop to consume as many options as possible in
256025dbecb6Smrg    # each iteration.
256125dbecb6Smrg    while test $# -gt 0; do
256225dbecb6Smrg      _G_match_lt_parse_options=:
256325dbecb6Smrg      _G_opt=$1
256425dbecb6Smrg      shift
256525dbecb6Smrg      case $_G_opt in
256625dbecb6Smrg        --dry-run|--dryrun|-n)
256725dbecb6Smrg                        opt_dry_run=:
256825dbecb6Smrg                        ;;
256925dbecb6Smrg
257025dbecb6Smrg        --config)       func_config ;;
257125dbecb6Smrg
257225dbecb6Smrg        --dlopen|-dlopen)
257325dbecb6Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
257425dbecb6Smrg}$1"
257525dbecb6Smrg                        shift
257625dbecb6Smrg                        ;;
257725dbecb6Smrg
257825dbecb6Smrg        --preserve-dup-deps)
257925dbecb6Smrg                        opt_preserve_dup_deps=: ;;
258025dbecb6Smrg
258125dbecb6Smrg        --features)     func_features ;;
258225dbecb6Smrg
258325dbecb6Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
258425dbecb6Smrg
258525dbecb6Smrg        --help)         opt_help=: ;;
258625dbecb6Smrg
258725dbecb6Smrg        --help-all)     opt_help=': help-all' ;;
258825dbecb6Smrg
258925dbecb6Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
259025dbecb6Smrg                        opt_mode=$1
259125dbecb6Smrg                        case $1 in
259225dbecb6Smrg                          # Valid mode arguments:
259325dbecb6Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
259425dbecb6Smrg
259525dbecb6Smrg                          # Catch anything else as an error
259625dbecb6Smrg                          *) func_error "invalid argument for $_G_opt"
259725dbecb6Smrg                             exit_cmd=exit
259825dbecb6Smrg                             break
259925dbecb6Smrg                             ;;
260025dbecb6Smrg                        esac
260125dbecb6Smrg                        shift
260225dbecb6Smrg                        ;;
260325dbecb6Smrg
260425dbecb6Smrg        --no-silent|--no-quiet)
260525dbecb6Smrg                        opt_quiet=false
260625dbecb6Smrg                        func_append preserve_args " $_G_opt"
260725dbecb6Smrg                        ;;
260825dbecb6Smrg
260925dbecb6Smrg        --no-warnings|--no-warning|--no-warn)
261025dbecb6Smrg                        opt_warning=false
261125dbecb6Smrg                        func_append preserve_args " $_G_opt"
261225dbecb6Smrg                        ;;
261325dbecb6Smrg
261425dbecb6Smrg        --no-verbose)
261525dbecb6Smrg                        opt_verbose=false
261625dbecb6Smrg                        func_append preserve_args " $_G_opt"
261725dbecb6Smrg                        ;;
261825dbecb6Smrg
261925dbecb6Smrg        --silent|--quiet)
262025dbecb6Smrg                        opt_quiet=:
262125dbecb6Smrg                        opt_verbose=false
262225dbecb6Smrg                        func_append preserve_args " $_G_opt"
262325dbecb6Smrg                        ;;
262425dbecb6Smrg
262525dbecb6Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
262625dbecb6Smrg                        opt_tag=$1
262725dbecb6Smrg                        func_append preserve_args " $_G_opt $1"
262825dbecb6Smrg                        func_enable_tag "$1"
262925dbecb6Smrg                        shift
263025dbecb6Smrg                        ;;
263125dbecb6Smrg
263225dbecb6Smrg        --verbose|-v)   opt_quiet=false
263325dbecb6Smrg                        opt_verbose=:
263425dbecb6Smrg                        func_append preserve_args " $_G_opt"
263525dbecb6Smrg                        ;;
263625dbecb6Smrg
263725dbecb6Smrg        # An option not handled by this hook function:
263825dbecb6Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
263925dbecb6Smrg                        _G_match_lt_parse_options=false
264025dbecb6Smrg                        break
264125dbecb6Smrg                        ;;
264225dbecb6Smrg      esac
264325dbecb6Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
264425dbecb6Smrg    done
2645b68e1f86Smrg
264625dbecb6Smrg    if $_G_rc_lt_parse_options; then
264725dbecb6Smrg      # save modified positional parameters for caller
264825dbecb6Smrg      func_quote eval ${1+"$@"}
264925dbecb6Smrg      libtool_parse_options_result=$func_quote_result
2650b68e1f86Smrg    fi
265125dbecb6Smrg}
265225dbecb6Smrgfunc_add_hook func_parse_options libtool_parse_options
265325dbecb6Smrg
2654b68e1f86Smrg
2655b68e1f86Smrg
265625dbecb6Smrg# libtool_validate_options [ARG]...
265725dbecb6Smrg# ---------------------------------
265825dbecb6Smrg# Perform any sanity checks on option settings and/or unconsumed
265925dbecb6Smrg# arguments.
266025dbecb6Smrglibtool_validate_options ()
266125dbecb6Smrg{
266225dbecb6Smrg    # save first non-option argument
266325dbecb6Smrg    if test 0 -lt $#; then
266425dbecb6Smrg      nonopt=$1
266525dbecb6Smrg      shift
26663bfa90b6Smrg    fi
2667b68e1f86Smrg
266825dbecb6Smrg    # preserve --debug
266925dbecb6Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
267025dbecb6Smrg
267125dbecb6Smrg    # Keeping compiler generated duplicates in $postdeps and $predeps is not
267225dbecb6Smrg    # harmful, and is necessary in a majority of systems that use it to satisfy
267325dbecb6Smrg    # symbol dependencies.
267425dbecb6Smrg    opt_duplicate_compiler_generated_deps=:
267525dbecb6Smrg
267625dbecb6Smrg    $opt_help || {
267725dbecb6Smrg      # Sanity checks first:
267825dbecb6Smrg      func_check_version_match
267925dbecb6Smrg
268025dbecb6Smrg      test yes != "$build_libtool_libs" \
268125dbecb6Smrg        && test yes != "$build_old_libs" \
268225dbecb6Smrg        && func_fatal_configuration "not configured to build any kind of library"
2683b68e1f86Smrg
268425dbecb6Smrg      # Darwin sucks
268525dbecb6Smrg      eval std_shrext=\"$shrext_cmds\"
268625dbecb6Smrg
268725dbecb6Smrg      # Only execute mode is allowed to have -dlopen flags.
268825dbecb6Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
268925dbecb6Smrg        func_error "unrecognized option '-dlopen'"
269025dbecb6Smrg        $ECHO "$help" 1>&2
269125dbecb6Smrg        exit $EXIT_FAILURE
269225dbecb6Smrg      fi
269325dbecb6Smrg
269425dbecb6Smrg      # Change the help message to a mode-specific one.
269525dbecb6Smrg      generic_help=$help
269625dbecb6Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
269725dbecb6Smrg    }
26986df26cacSmrg
269925dbecb6Smrg    # Pass back the unparsed argument list
270025dbecb6Smrg    func_quote eval ${1+"$@"}
270125dbecb6Smrg    libtool_validate_options_result=$func_quote_result
27023bfa90b6Smrg}
270325dbecb6Smrgfunc_add_hook func_validate_options libtool_validate_options
2704b68e1f86Smrg
2705b68e1f86Smrg
270625dbecb6Smrg# Process options as early as possible so that --help and --version
270725dbecb6Smrg# can return quickly.
270825dbecb6Smrgfunc_options ${1+"$@"}
270925dbecb6Smrgeval set dummy "$func_options_result"; shift
271025dbecb6Smrg
2711b68e1f86Smrg
2712b68e1f86Smrg
27133bfa90b6Smrg## ----------- ##
27143bfa90b6Smrg##    Main.    ##
27153bfa90b6Smrg## ----------- ##
27166df26cacSmrg
271725dbecb6Smrgmagic='%%%MAGIC variable%%%'
271825dbecb6Smrgmagic_exe='%%%MAGIC EXE variable%%%'
271925dbecb6Smrg
272025dbecb6Smrg# Global variables.
272125dbecb6Smrgextracted_archives=
272225dbecb6Smrgextracted_serial=0
272325dbecb6Smrg
272425dbecb6Smrg# If this variable is set in any of the actions, the command in it
272525dbecb6Smrg# will be execed at the end.  This prevents here-documents from being
272625dbecb6Smrg# left over by shells.
272725dbecb6Smrgexec_cmd=
272825dbecb6Smrg
272925dbecb6Smrg
273025dbecb6Smrg# A function that is used when there is no print builtin or printf.
273125dbecb6Smrgfunc_fallback_echo ()
273225dbecb6Smrg{
273325dbecb6Smrg  eval 'cat <<_LTECHO_EOF
273425dbecb6Smrg$1
273525dbecb6Smrg_LTECHO_EOF'
273625dbecb6Smrg}
273725dbecb6Smrg
273825dbecb6Smrg# func_generated_by_libtool
273925dbecb6Smrg# True iff stdin has been generated by Libtool. This function is only
274025dbecb6Smrg# a basic sanity check; it will hardly flush out determined imposters.
274125dbecb6Smrgfunc_generated_by_libtool_p ()
274225dbecb6Smrg{
274325dbecb6Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
274425dbecb6Smrg}
274525dbecb6Smrg
2746b68e1f86Smrg# func_lalib_p file
274725dbecb6Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2748b68e1f86Smrg# This function is only a basic sanity check; it will hardly flush out
2749b68e1f86Smrg# determined imposters.
2750b68e1f86Smrgfunc_lalib_p ()
2751b68e1f86Smrg{
2752b68e1f86Smrg    test -f "$1" &&
275325dbecb6Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2754b68e1f86Smrg}
27556df26cacSmrg
2756b68e1f86Smrg# func_lalib_unsafe_p file
275725dbecb6Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2758b68e1f86Smrg# This function implements the same check as func_lalib_p without
2759b68e1f86Smrg# resorting to external programs.  To this end, it redirects stdin and
2760b68e1f86Smrg# closes it afterwards, without saving the original file descriptor.
2761b68e1f86Smrg# As a safety measure, use it only where a negative result would be
276225dbecb6Smrg# fatal anyway.  Works if 'file' does not exist.
2763b68e1f86Smrgfunc_lalib_unsafe_p ()
2764b68e1f86Smrg{
2765b68e1f86Smrg    lalib_p=no
2766b68e1f86Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2767b68e1f86Smrg	for lalib_p_l in 1 2 3 4
2768b68e1f86Smrg	do
2769b68e1f86Smrg	    read lalib_p_line
277025dbecb6Smrg	    case $lalib_p_line in
2771b68e1f86Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2772b68e1f86Smrg	    esac
2773b68e1f86Smrg	done
2774b68e1f86Smrg	exec 0<&5 5<&-
2775b68e1f86Smrg    fi
277625dbecb6Smrg    test yes = "$lalib_p"
2777b68e1f86Smrg}
27786df26cacSmrg
2779b68e1f86Smrg# func_ltwrapper_script_p file
2780b68e1f86Smrg# True iff FILE is a libtool wrapper script
2781b68e1f86Smrg# This function is only a basic sanity check; it will hardly flush out
2782b68e1f86Smrg# determined imposters.
2783b68e1f86Smrgfunc_ltwrapper_script_p ()
2784b68e1f86Smrg{
278525dbecb6Smrg    test -f "$1" &&
278625dbecb6Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2787b68e1f86Smrg}
27886df26cacSmrg
2789b68e1f86Smrg# func_ltwrapper_executable_p file
2790b68e1f86Smrg# True iff FILE is a libtool wrapper executable
2791b68e1f86Smrg# This function is only a basic sanity check; it will hardly flush out
2792b68e1f86Smrg# determined imposters.
2793b68e1f86Smrgfunc_ltwrapper_executable_p ()
2794b68e1f86Smrg{
2795b68e1f86Smrg    func_ltwrapper_exec_suffix=
2796b68e1f86Smrg    case $1 in
2797b68e1f86Smrg    *.exe) ;;
2798b68e1f86Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2799b68e1f86Smrg    esac
2800b68e1f86Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2801b68e1f86Smrg}
28026df26cacSmrg
2803b68e1f86Smrg# func_ltwrapper_scriptname file
2804b68e1f86Smrg# Assumes file is an ltwrapper_executable
2805b68e1f86Smrg# uses $file to determine the appropriate filename for a
2806b68e1f86Smrg# temporary ltwrapper_script.
2807b68e1f86Smrgfunc_ltwrapper_scriptname ()
2808b68e1f86Smrg{
28093bfa90b6Smrg    func_dirname_and_basename "$1" "" "."
28103bfa90b6Smrg    func_stripname '' '.exe' "$func_basename_result"
281125dbecb6Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2812b68e1f86Smrg}
2813b68e1f86Smrg
2814b68e1f86Smrg# func_ltwrapper_p file
2815b68e1f86Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2816b68e1f86Smrg# This function is only a basic sanity check; it will hardly flush out
2817b68e1f86Smrg# determined imposters.
2818b68e1f86Smrgfunc_ltwrapper_p ()
2819b68e1f86Smrg{
2820b68e1f86Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2821b68e1f86Smrg}
2822b68e1f86Smrg
2823b68e1f86Smrg
2824b68e1f86Smrg# func_execute_cmds commands fail_cmd
2825b68e1f86Smrg# Execute tilde-delimited COMMANDS.
2826b68e1f86Smrg# If FAIL_CMD is given, eval that upon failure.
2827b68e1f86Smrg# FAIL_CMD may read-access the current command in variable CMD!
2828b68e1f86Smrgfunc_execute_cmds ()
2829b68e1f86Smrg{
283025dbecb6Smrg    $debug_cmd
283125dbecb6Smrg
2832b68e1f86Smrg    save_ifs=$IFS; IFS='~'
2833b68e1f86Smrg    for cmd in $1; do
283425dbecb6Smrg      IFS=$sp$nl
2835b68e1f86Smrg      eval cmd=\"$cmd\"
283625dbecb6Smrg      IFS=$save_ifs
2837b68e1f86Smrg      func_show_eval "$cmd" "${2-:}"
2838b68e1f86Smrg    done
2839b68e1f86Smrg    IFS=$save_ifs
2840b68e1f86Smrg}
2841b68e1f86Smrg
2842b68e1f86Smrg
2843b68e1f86Smrg# func_source file
2844b68e1f86Smrg# Source FILE, adding directory component if necessary.
2845b68e1f86Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2846b68e1f86Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2847b68e1f86Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
284825dbecb6Smrg# 'FILE.' does not work on cygwin managed mounts.
2849b68e1f86Smrgfunc_source ()
2850b68e1f86Smrg{
285125dbecb6Smrg    $debug_cmd
285225dbecb6Smrg
2853b68e1f86Smrg    case $1 in
2854b68e1f86Smrg    */* | *\\*)	. "$1" ;;
2855b68e1f86Smrg    *)		. "./$1" ;;
2856b68e1f86Smrg    esac
2857b68e1f86Smrg}
2858b68e1f86Smrg
2859b68e1f86Smrg
28603bfa90b6Smrg# func_resolve_sysroot PATH
28613bfa90b6Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
28623bfa90b6Smrg# func_resolve_sysroot_result
28633bfa90b6Smrgfunc_resolve_sysroot ()
28643bfa90b6Smrg{
28653bfa90b6Smrg  func_resolve_sysroot_result=$1
28663bfa90b6Smrg  case $func_resolve_sysroot_result in
28673bfa90b6Smrg  =*)
28683bfa90b6Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
28693bfa90b6Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
28703bfa90b6Smrg    ;;
28713bfa90b6Smrg  esac
28723bfa90b6Smrg}
28733bfa90b6Smrg
28743bfa90b6Smrg# func_replace_sysroot PATH
28753bfa90b6Smrg# If PATH begins with the sysroot, replace it with = and
28763bfa90b6Smrg# store the result into func_replace_sysroot_result.
28773bfa90b6Smrgfunc_replace_sysroot ()
28783bfa90b6Smrg{
287925dbecb6Smrg  case $lt_sysroot:$1 in
28803bfa90b6Smrg  ?*:"$lt_sysroot"*)
28813bfa90b6Smrg    func_stripname "$lt_sysroot" '' "$1"
288225dbecb6Smrg    func_replace_sysroot_result='='$func_stripname_result
28833bfa90b6Smrg    ;;
28843bfa90b6Smrg  *)
28853bfa90b6Smrg    # Including no sysroot.
28863bfa90b6Smrg    func_replace_sysroot_result=$1
28873bfa90b6Smrg    ;;
28883bfa90b6Smrg  esac
28893bfa90b6Smrg}
28903bfa90b6Smrg
2891b68e1f86Smrg# func_infer_tag arg
2892b68e1f86Smrg# Infer tagged configuration to use if any are available and
2893b68e1f86Smrg# if one wasn't chosen via the "--tag" command line option.
2894b68e1f86Smrg# Only attempt this if the compiler in the base compile
2895b68e1f86Smrg# command doesn't match the default compiler.
2896b68e1f86Smrg# arg is usually of the form 'gcc ...'
2897b68e1f86Smrgfunc_infer_tag ()
2898b68e1f86Smrg{
289925dbecb6Smrg    $debug_cmd
290025dbecb6Smrg
2901b68e1f86Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2902b68e1f86Smrg      CC_quoted=
2903b68e1f86Smrg      for arg in $CC; do
29043bfa90b6Smrg	func_append_quoted CC_quoted "$arg"
2905b68e1f86Smrg      done
29063bfa90b6Smrg      CC_expanded=`func_echo_all $CC`
29073bfa90b6Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2908b68e1f86Smrg      case $@ in
2909b68e1f86Smrg      # Blanks in the command may have been stripped by the calling shell,
2910b68e1f86Smrg      # but not from the CC environment variable when configure was run.
29113bfa90b6Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29123bfa90b6Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2913b68e1f86Smrg      # Blanks at the start of $base_compile will cause this to fail
2914b68e1f86Smrg      # if we don't check for them as well.
2915b68e1f86Smrg      *)
2916b68e1f86Smrg	for z in $available_tags; do
2917b68e1f86Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2918b68e1f86Smrg	    # Evaluate the configuration.
291925dbecb6Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2920b68e1f86Smrg	    CC_quoted=
2921b68e1f86Smrg	    for arg in $CC; do
2922b68e1f86Smrg	      # Double-quote args containing other shell metacharacters.
29233bfa90b6Smrg	      func_append_quoted CC_quoted "$arg"
2924b68e1f86Smrg	    done
29253bfa90b6Smrg	    CC_expanded=`func_echo_all $CC`
29263bfa90b6Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2927b68e1f86Smrg	    case "$@ " in
29283bfa90b6Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29293bfa90b6Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2930b68e1f86Smrg	      # The compiler in the base compile command matches
2931b68e1f86Smrg	      # the one in the tagged configuration.
2932b68e1f86Smrg	      # Assume this is the tagged configuration we want.
2933b68e1f86Smrg	      tagname=$z
2934b68e1f86Smrg	      break
2935b68e1f86Smrg	      ;;
2936b68e1f86Smrg	    esac
2937b68e1f86Smrg	  fi
2938b68e1f86Smrg	done
2939b68e1f86Smrg	# If $tagname still isn't set, then no tagged configuration
2940b68e1f86Smrg	# was found and let the user know that the "--tag" command
2941b68e1f86Smrg	# line option must be used.
2942b68e1f86Smrg	if test -z "$tagname"; then
2943b68e1f86Smrg	  func_echo "unable to infer tagged configuration"
294425dbecb6Smrg	  func_fatal_error "specify a tag with '--tag'"
2945b68e1f86Smrg#	else
2946b68e1f86Smrg#	  func_verbose "using $tagname tagged configuration"
2947b68e1f86Smrg	fi
2948b68e1f86Smrg	;;
2949b68e1f86Smrg      esac
2950b68e1f86Smrg    fi
2951b68e1f86Smrg}
2952b68e1f86Smrg
2953b68e1f86Smrg
2954b68e1f86Smrg
2955b68e1f86Smrg# func_write_libtool_object output_name pic_name nonpic_name
2956b68e1f86Smrg# Create a libtool object file (analogous to a ".la" file),
2957b68e1f86Smrg# but don't create it if we're doing a dry run.
2958b68e1f86Smrgfunc_write_libtool_object ()
2959b68e1f86Smrg{
296025dbecb6Smrg    write_libobj=$1
296125dbecb6Smrg    if test yes = "$build_libtool_libs"; then
296225dbecb6Smrg      write_lobj=\'$2\'
2963b68e1f86Smrg    else
2964b68e1f86Smrg      write_lobj=none
2965b68e1f86Smrg    fi
2966b68e1f86Smrg
296725dbecb6Smrg    if test yes = "$build_old_libs"; then
296825dbecb6Smrg      write_oldobj=\'$3\'
2969b68e1f86Smrg    else
2970b68e1f86Smrg      write_oldobj=none
2971b68e1f86Smrg    fi
2972b68e1f86Smrg
2973b68e1f86Smrg    $opt_dry_run || {
2974b68e1f86Smrg      cat >${write_libobj}T <<EOF
2975b68e1f86Smrg# $write_libobj - a libtool object file
297625dbecb6Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2977b68e1f86Smrg#
2978b68e1f86Smrg# Please DO NOT delete this file!
2979b68e1f86Smrg# It is necessary for linking the library.
2980b68e1f86Smrg
2981b68e1f86Smrg# Name of the PIC object.
2982b68e1f86Smrgpic_object=$write_lobj
2983b68e1f86Smrg
2984b68e1f86Smrg# Name of the non-PIC object
2985b68e1f86Smrgnon_pic_object=$write_oldobj
2986b68e1f86Smrg
2987b68e1f86SmrgEOF
298825dbecb6Smrg      $MV "${write_libobj}T" "$write_libobj"
2989b68e1f86Smrg    }
2990b68e1f86Smrg}
2991b68e1f86Smrg
29923bfa90b6Smrg
29933bfa90b6Smrg##################################################
29943bfa90b6Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
29953bfa90b6Smrg##################################################
29963bfa90b6Smrg
29973bfa90b6Smrg# func_convert_core_file_wine_to_w32 ARG
29983bfa90b6Smrg# Helper function used by file name conversion functions when $build is *nix,
29993bfa90b6Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
30003bfa90b6Smrg# correctly configured wine environment available, with the winepath program
30013bfa90b6Smrg# in $build's $PATH.
30023bfa90b6Smrg#
30033bfa90b6Smrg# ARG is the $build file name to be converted to w32 format.
30043bfa90b6Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
30053bfa90b6Smrg# be empty on error (or when ARG is empty)
30063bfa90b6Smrgfunc_convert_core_file_wine_to_w32 ()
30073bfa90b6Smrg{
300825dbecb6Smrg  $debug_cmd
300925dbecb6Smrg
301025dbecb6Smrg  func_convert_core_file_wine_to_w32_result=$1
30113bfa90b6Smrg  if test -n "$1"; then
30123bfa90b6Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
30133bfa90b6Smrg    # are forced to check the contents of stdout. On the other hand, if the
30143bfa90b6Smrg    # command is not found, the shell will set an exit code of 127 and print
30153bfa90b6Smrg    # *an error message* to stdout. So we must check for both error code of
30163bfa90b6Smrg    # zero AND non-empty stdout, which explains the odd construction:
30173bfa90b6Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
301825dbecb6Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
30193bfa90b6Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
302025dbecb6Smrg        $SED -e "$sed_naive_backslashify"`
30213bfa90b6Smrg    else
30223bfa90b6Smrg      func_convert_core_file_wine_to_w32_result=
30233bfa90b6Smrg    fi
30243bfa90b6Smrg  fi
30253bfa90b6Smrg}
30263bfa90b6Smrg# end: func_convert_core_file_wine_to_w32
30273bfa90b6Smrg
30283bfa90b6Smrg
30293bfa90b6Smrg# func_convert_core_path_wine_to_w32 ARG
30303bfa90b6Smrg# Helper function used by path conversion functions when $build is *nix, and
30313bfa90b6Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
30323bfa90b6Smrg# configured wine environment available, with the winepath program in $build's
30333bfa90b6Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
30343bfa90b6Smrg#
30353bfa90b6Smrg# ARG is path to be converted from $build format to win32.
30363bfa90b6Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
30373bfa90b6Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
30383bfa90b6Smrg# are convertible, then the result may be empty.
30393bfa90b6Smrgfunc_convert_core_path_wine_to_w32 ()
30403bfa90b6Smrg{
304125dbecb6Smrg  $debug_cmd
304225dbecb6Smrg
30433bfa90b6Smrg  # unfortunately, winepath doesn't convert paths, only file names
304425dbecb6Smrg  func_convert_core_path_wine_to_w32_result=
30453bfa90b6Smrg  if test -n "$1"; then
30463bfa90b6Smrg    oldIFS=$IFS
30473bfa90b6Smrg    IFS=:
30483bfa90b6Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
30493bfa90b6Smrg      IFS=$oldIFS
30503bfa90b6Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
305125dbecb6Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
30523bfa90b6Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
305325dbecb6Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
30543bfa90b6Smrg        else
30553bfa90b6Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
30563bfa90b6Smrg        fi
30573bfa90b6Smrg      fi
30583bfa90b6Smrg    done
30593bfa90b6Smrg    IFS=$oldIFS
30603bfa90b6Smrg  fi
30613bfa90b6Smrg}
30623bfa90b6Smrg# end: func_convert_core_path_wine_to_w32
30633bfa90b6Smrg
30643bfa90b6Smrg
30653bfa90b6Smrg# func_cygpath ARGS...
30663bfa90b6Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
30673bfa90b6Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
30683bfa90b6Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
30693bfa90b6Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
30703bfa90b6Smrg# file name or path is assumed to be in w32 format, as previously converted
30713bfa90b6Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
30723bfa90b6Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
30733bfa90b6Smrg# Cygwin format). Returns an empty string on error.
30743bfa90b6Smrg#
30753bfa90b6Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
30763bfa90b6Smrg# be converted.
30773bfa90b6Smrg#
30783bfa90b6Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
30793bfa90b6Smrg# environment variable; do not put it in $PATH.
30803bfa90b6Smrgfunc_cygpath ()
30813bfa90b6Smrg{
308225dbecb6Smrg  $debug_cmd
308325dbecb6Smrg
30843bfa90b6Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
30853bfa90b6Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
30863bfa90b6Smrg    if test "$?" -ne 0; then
30873bfa90b6Smrg      # on failure, ensure result is empty
30883bfa90b6Smrg      func_cygpath_result=
30893bfa90b6Smrg    fi
30903bfa90b6Smrg  else
30913bfa90b6Smrg    func_cygpath_result=
309225dbecb6Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
30933bfa90b6Smrg  fi
30943bfa90b6Smrg}
30953bfa90b6Smrg#end: func_cygpath
30963bfa90b6Smrg
30973bfa90b6Smrg
30983bfa90b6Smrg# func_convert_core_msys_to_w32 ARG
30993bfa90b6Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
31003bfa90b6Smrg# result in func_convert_core_msys_to_w32_result.
31013bfa90b6Smrgfunc_convert_core_msys_to_w32 ()
31023bfa90b6Smrg{
310325dbecb6Smrg  $debug_cmd
310425dbecb6Smrg
31053bfa90b6Smrg  # awkward: cmd appends spaces to result
31063bfa90b6Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
310725dbecb6Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
31083bfa90b6Smrg}
31093bfa90b6Smrg#end: func_convert_core_msys_to_w32
31103bfa90b6Smrg
31113bfa90b6Smrg
31123bfa90b6Smrg# func_convert_file_check ARG1 ARG2
31133bfa90b6Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
31143bfa90b6Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
31153bfa90b6Smrg# func_to_host_file_result to ARG1).
31163bfa90b6Smrgfunc_convert_file_check ()
31173bfa90b6Smrg{
311825dbecb6Smrg  $debug_cmd
311925dbecb6Smrg
312025dbecb6Smrg  if test -z "$2" && test -n "$1"; then
31213bfa90b6Smrg    func_error "Could not determine host file name corresponding to"
312225dbecb6Smrg    func_error "  '$1'"
31233bfa90b6Smrg    func_error "Continuing, but uninstalled executables may not work."
31243bfa90b6Smrg    # Fallback:
312525dbecb6Smrg    func_to_host_file_result=$1
31263bfa90b6Smrg  fi
31273bfa90b6Smrg}
31283bfa90b6Smrg# end func_convert_file_check
31293bfa90b6Smrg
31303bfa90b6Smrg
31313bfa90b6Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
31323bfa90b6Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
31333bfa90b6Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
31343bfa90b6Smrg# func_to_host_file_result to a simplistic fallback value (see below).
31353bfa90b6Smrgfunc_convert_path_check ()
31363bfa90b6Smrg{
313725dbecb6Smrg  $debug_cmd
313825dbecb6Smrg
31393bfa90b6Smrg  if test -z "$4" && test -n "$3"; then
31403bfa90b6Smrg    func_error "Could not determine the host path corresponding to"
314125dbecb6Smrg    func_error "  '$3'"
31423bfa90b6Smrg    func_error "Continuing, but uninstalled executables may not work."
31433bfa90b6Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
31443bfa90b6Smrg    # should not be "improved".  See libtool.info.
31453bfa90b6Smrg    if test "x$1" != "x$2"; then
31463bfa90b6Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
31473bfa90b6Smrg      func_to_host_path_result=`echo "$3" |
31483bfa90b6Smrg        $SED -e "$lt_replace_pathsep_chars"`
31493bfa90b6Smrg    else
315025dbecb6Smrg      func_to_host_path_result=$3
31513bfa90b6Smrg    fi
31523bfa90b6Smrg  fi
31533bfa90b6Smrg}
31543bfa90b6Smrg# end func_convert_path_check
31553bfa90b6Smrg
31563bfa90b6Smrg
31573bfa90b6Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
31583bfa90b6Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
31593bfa90b6Smrg# and appending REPL if ORIG matches BACKPAT.
31603bfa90b6Smrgfunc_convert_path_front_back_pathsep ()
31613bfa90b6Smrg{
316225dbecb6Smrg  $debug_cmd
316325dbecb6Smrg
31643bfa90b6Smrg  case $4 in
316525dbecb6Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
31663bfa90b6Smrg    ;;
31673bfa90b6Smrg  esac
31683bfa90b6Smrg  case $4 in
31693bfa90b6Smrg  $2 ) func_append func_to_host_path_result "$3"
31703bfa90b6Smrg    ;;
31713bfa90b6Smrg  esac
31723bfa90b6Smrg}
31733bfa90b6Smrg# end func_convert_path_front_back_pathsep
31743bfa90b6Smrg
31753bfa90b6Smrg
31763bfa90b6Smrg##################################################
31773bfa90b6Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
31783bfa90b6Smrg##################################################
317925dbecb6Smrg# invoked via '$to_host_file_cmd ARG'
31803bfa90b6Smrg#
31813bfa90b6Smrg# In each case, ARG is the path to be converted from $build to $host format.
31823bfa90b6Smrg# Result will be available in $func_to_host_file_result.
31833bfa90b6Smrg
31843bfa90b6Smrg
31853bfa90b6Smrg# func_to_host_file ARG
31863bfa90b6Smrg# Converts the file name ARG from $build format to $host format. Return result
31873bfa90b6Smrg# in func_to_host_file_result.
31883bfa90b6Smrgfunc_to_host_file ()
31893bfa90b6Smrg{
319025dbecb6Smrg  $debug_cmd
319125dbecb6Smrg
31923bfa90b6Smrg  $to_host_file_cmd "$1"
31933bfa90b6Smrg}
31943bfa90b6Smrg# end func_to_host_file
31953bfa90b6Smrg
31963bfa90b6Smrg
31973bfa90b6Smrg# func_to_tool_file ARG LAZY
31983bfa90b6Smrg# converts the file name ARG from $build format to toolchain format. Return
31993bfa90b6Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
32003bfa90b6Smrg# in (the comma separated) LAZY, no conversion takes place.
32013bfa90b6Smrgfunc_to_tool_file ()
32023bfa90b6Smrg{
320325dbecb6Smrg  $debug_cmd
320425dbecb6Smrg
32053bfa90b6Smrg  case ,$2, in
32063bfa90b6Smrg    *,"$to_tool_file_cmd",*)
32073bfa90b6Smrg      func_to_tool_file_result=$1
32083bfa90b6Smrg      ;;
32093bfa90b6Smrg    *)
32103bfa90b6Smrg      $to_tool_file_cmd "$1"
32113bfa90b6Smrg      func_to_tool_file_result=$func_to_host_file_result
32123bfa90b6Smrg      ;;
32133bfa90b6Smrg  esac
32143bfa90b6Smrg}
32153bfa90b6Smrg# end func_to_tool_file
32163bfa90b6Smrg
32173bfa90b6Smrg
32183bfa90b6Smrg# func_convert_file_noop ARG
32193bfa90b6Smrg# Copy ARG to func_to_host_file_result.
32203bfa90b6Smrgfunc_convert_file_noop ()
32213bfa90b6Smrg{
322225dbecb6Smrg  func_to_host_file_result=$1
32233bfa90b6Smrg}
32243bfa90b6Smrg# end func_convert_file_noop
32253bfa90b6Smrg
32263bfa90b6Smrg
32273bfa90b6Smrg# func_convert_file_msys_to_w32 ARG
32283bfa90b6Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
32293bfa90b6Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
32303bfa90b6Smrg# func_to_host_file_result.
32313bfa90b6Smrgfunc_convert_file_msys_to_w32 ()
32323bfa90b6Smrg{
323325dbecb6Smrg  $debug_cmd
323425dbecb6Smrg
323525dbecb6Smrg  func_to_host_file_result=$1
32363bfa90b6Smrg  if test -n "$1"; then
32373bfa90b6Smrg    func_convert_core_msys_to_w32 "$1"
323825dbecb6Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
32393bfa90b6Smrg  fi
32403bfa90b6Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32413bfa90b6Smrg}
32423bfa90b6Smrg# end func_convert_file_msys_to_w32
32433bfa90b6Smrg
32443bfa90b6Smrg
32453bfa90b6Smrg# func_convert_file_cygwin_to_w32 ARG
32463bfa90b6Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
32473bfa90b6Smrg# func_to_host_file_result.
32483bfa90b6Smrgfunc_convert_file_cygwin_to_w32 ()
32493bfa90b6Smrg{
325025dbecb6Smrg  $debug_cmd
325125dbecb6Smrg
325225dbecb6Smrg  func_to_host_file_result=$1
32533bfa90b6Smrg  if test -n "$1"; then
32543bfa90b6Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
32553bfa90b6Smrg    # LT_CYGPATH in this case.
32563bfa90b6Smrg    func_to_host_file_result=`cygpath -m "$1"`
32573bfa90b6Smrg  fi
32583bfa90b6Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32593bfa90b6Smrg}
32603bfa90b6Smrg# end func_convert_file_cygwin_to_w32
32613bfa90b6Smrg
32623bfa90b6Smrg
32633bfa90b6Smrg# func_convert_file_nix_to_w32 ARG
32643bfa90b6Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
32653bfa90b6Smrg# and a working winepath. Returns result in func_to_host_file_result.
32663bfa90b6Smrgfunc_convert_file_nix_to_w32 ()
32673bfa90b6Smrg{
326825dbecb6Smrg  $debug_cmd
326925dbecb6Smrg
327025dbecb6Smrg  func_to_host_file_result=$1
32713bfa90b6Smrg  if test -n "$1"; then
32723bfa90b6Smrg    func_convert_core_file_wine_to_w32 "$1"
327325dbecb6Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
32743bfa90b6Smrg  fi
32753bfa90b6Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32763bfa90b6Smrg}
32773bfa90b6Smrg# end func_convert_file_nix_to_w32
32783bfa90b6Smrg
32793bfa90b6Smrg
32803bfa90b6Smrg# func_convert_file_msys_to_cygwin ARG
32813bfa90b6Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32823bfa90b6Smrg# Returns result in func_to_host_file_result.
32833bfa90b6Smrgfunc_convert_file_msys_to_cygwin ()
32843bfa90b6Smrg{
328525dbecb6Smrg  $debug_cmd
328625dbecb6Smrg
328725dbecb6Smrg  func_to_host_file_result=$1
32883bfa90b6Smrg  if test -n "$1"; then
32893bfa90b6Smrg    func_convert_core_msys_to_w32 "$1"
32903bfa90b6Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
329125dbecb6Smrg    func_to_host_file_result=$func_cygpath_result
32923bfa90b6Smrg  fi
32933bfa90b6Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32943bfa90b6Smrg}
32953bfa90b6Smrg# end func_convert_file_msys_to_cygwin
32963bfa90b6Smrg
32973bfa90b6Smrg
32983bfa90b6Smrg# func_convert_file_nix_to_cygwin ARG
32993bfa90b6Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
33003bfa90b6Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
33013bfa90b6Smrg# in func_to_host_file_result.
33023bfa90b6Smrgfunc_convert_file_nix_to_cygwin ()
33033bfa90b6Smrg{
330425dbecb6Smrg  $debug_cmd
330525dbecb6Smrg
330625dbecb6Smrg  func_to_host_file_result=$1
33073bfa90b6Smrg  if test -n "$1"; then
33083bfa90b6Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
33093bfa90b6Smrg    func_convert_core_file_wine_to_w32 "$1"
33103bfa90b6Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
331125dbecb6Smrg    func_to_host_file_result=$func_cygpath_result
33123bfa90b6Smrg  fi
33133bfa90b6Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33143bfa90b6Smrg}
33153bfa90b6Smrg# end func_convert_file_nix_to_cygwin
33163bfa90b6Smrg
33173bfa90b6Smrg
33183bfa90b6Smrg#############################################
33193bfa90b6Smrg# $build to $host PATH CONVERSION FUNCTIONS #
33203bfa90b6Smrg#############################################
332125dbecb6Smrg# invoked via '$to_host_path_cmd ARG'
33223bfa90b6Smrg#
33233bfa90b6Smrg# In each case, ARG is the path to be converted from $build to $host format.
33243bfa90b6Smrg# The result will be available in $func_to_host_path_result.
33253bfa90b6Smrg#
33263bfa90b6Smrg# Path separators are also converted from $build format to $host format.  If
33273bfa90b6Smrg# ARG begins or ends with a path separator character, it is preserved (but
33283bfa90b6Smrg# converted to $host format) on output.
33293bfa90b6Smrg#
33303bfa90b6Smrg# All path conversion functions are named using the following convention:
33313bfa90b6Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
33323bfa90b6Smrg#   path conversion function         : func_convert_path_X_to_Y ()
33333bfa90b6Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
33343bfa90b6Smrg# same.  If conversion functions are added for new $build/$host combinations,
33353bfa90b6Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
33363bfa90b6Smrg# will break.
33373bfa90b6Smrg
33383bfa90b6Smrg
33393bfa90b6Smrg# func_init_to_host_path_cmd
33403bfa90b6Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
33413bfa90b6Smrg# appropriate value, based on the value of $to_host_file_cmd.
33423bfa90b6Smrgto_host_path_cmd=
33433bfa90b6Smrgfunc_init_to_host_path_cmd ()
33443bfa90b6Smrg{
334525dbecb6Smrg  $debug_cmd
334625dbecb6Smrg
33473bfa90b6Smrg  if test -z "$to_host_path_cmd"; then
33483bfa90b6Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
334925dbecb6Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
33503bfa90b6Smrg  fi
33513bfa90b6Smrg}
33523bfa90b6Smrg
33533bfa90b6Smrg
33543bfa90b6Smrg# func_to_host_path ARG
33553bfa90b6Smrg# Converts the path ARG from $build format to $host format. Return result
33563bfa90b6Smrg# in func_to_host_path_result.
33573bfa90b6Smrgfunc_to_host_path ()
33583bfa90b6Smrg{
335925dbecb6Smrg  $debug_cmd
336025dbecb6Smrg
33613bfa90b6Smrg  func_init_to_host_path_cmd
33623bfa90b6Smrg  $to_host_path_cmd "$1"
33633bfa90b6Smrg}
33643bfa90b6Smrg# end func_to_host_path
33653bfa90b6Smrg
33663bfa90b6Smrg
33673bfa90b6Smrg# func_convert_path_noop ARG
33683bfa90b6Smrg# Copy ARG to func_to_host_path_result.
33693bfa90b6Smrgfunc_convert_path_noop ()
33703bfa90b6Smrg{
337125dbecb6Smrg  func_to_host_path_result=$1
33723bfa90b6Smrg}
33733bfa90b6Smrg# end func_convert_path_noop
33743bfa90b6Smrg
33753bfa90b6Smrg
33763bfa90b6Smrg# func_convert_path_msys_to_w32 ARG
33773bfa90b6Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
33783bfa90b6Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
33793bfa90b6Smrg# func_to_host_path_result.
33803bfa90b6Smrgfunc_convert_path_msys_to_w32 ()
33813bfa90b6Smrg{
338225dbecb6Smrg  $debug_cmd
338325dbecb6Smrg
338425dbecb6Smrg  func_to_host_path_result=$1
33853bfa90b6Smrg  if test -n "$1"; then
33863bfa90b6Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
33873bfa90b6Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
33883bfa90b6Smrg    # and winepath ignores them completely.
33893bfa90b6Smrg    func_stripname : : "$1"
33903bfa90b6Smrg    func_to_host_path_tmp1=$func_stripname_result
33913bfa90b6Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
339225dbecb6Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
33933bfa90b6Smrg    func_convert_path_check : ";" \
33943bfa90b6Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
33953bfa90b6Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
33963bfa90b6Smrg  fi
33973bfa90b6Smrg}
33983bfa90b6Smrg# end func_convert_path_msys_to_w32
33993bfa90b6Smrg
34003bfa90b6Smrg
34013bfa90b6Smrg# func_convert_path_cygwin_to_w32 ARG
34023bfa90b6Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
34033bfa90b6Smrg# func_to_host_file_result.
34043bfa90b6Smrgfunc_convert_path_cygwin_to_w32 ()
34053bfa90b6Smrg{
340625dbecb6Smrg  $debug_cmd
340725dbecb6Smrg
340825dbecb6Smrg  func_to_host_path_result=$1
34093bfa90b6Smrg  if test -n "$1"; then
34103bfa90b6Smrg    # See func_convert_path_msys_to_w32:
34113bfa90b6Smrg    func_stripname : : "$1"
34123bfa90b6Smrg    func_to_host_path_tmp1=$func_stripname_result
34133bfa90b6Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
34143bfa90b6Smrg    func_convert_path_check : ";" \
34153bfa90b6Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34163bfa90b6Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34173bfa90b6Smrg  fi
34183bfa90b6Smrg}
34193bfa90b6Smrg# end func_convert_path_cygwin_to_w32
34203bfa90b6Smrg
34213bfa90b6Smrg
34223bfa90b6Smrg# func_convert_path_nix_to_w32 ARG
34233bfa90b6Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
34243bfa90b6Smrg# a working winepath.  Returns result in func_to_host_file_result.
34253bfa90b6Smrgfunc_convert_path_nix_to_w32 ()
34263bfa90b6Smrg{
342725dbecb6Smrg  $debug_cmd
342825dbecb6Smrg
342925dbecb6Smrg  func_to_host_path_result=$1
34303bfa90b6Smrg  if test -n "$1"; then
34313bfa90b6Smrg    # See func_convert_path_msys_to_w32:
34323bfa90b6Smrg    func_stripname : : "$1"
34333bfa90b6Smrg    func_to_host_path_tmp1=$func_stripname_result
34343bfa90b6Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
343525dbecb6Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
34363bfa90b6Smrg    func_convert_path_check : ";" \
34373bfa90b6Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34383bfa90b6Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34393bfa90b6Smrg  fi
34403bfa90b6Smrg}
34413bfa90b6Smrg# end func_convert_path_nix_to_w32
34423bfa90b6Smrg
34433bfa90b6Smrg
34443bfa90b6Smrg# func_convert_path_msys_to_cygwin ARG
34453bfa90b6Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
34463bfa90b6Smrg# Returns result in func_to_host_file_result.
34473bfa90b6Smrgfunc_convert_path_msys_to_cygwin ()
34483bfa90b6Smrg{
344925dbecb6Smrg  $debug_cmd
345025dbecb6Smrg
345125dbecb6Smrg  func_to_host_path_result=$1
34523bfa90b6Smrg  if test -n "$1"; then
34533bfa90b6Smrg    # See func_convert_path_msys_to_w32:
34543bfa90b6Smrg    func_stripname : : "$1"
34553bfa90b6Smrg    func_to_host_path_tmp1=$func_stripname_result
34563bfa90b6Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
34573bfa90b6Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
345825dbecb6Smrg    func_to_host_path_result=$func_cygpath_result
34593bfa90b6Smrg    func_convert_path_check : : \
34603bfa90b6Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34613bfa90b6Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34623bfa90b6Smrg  fi
34633bfa90b6Smrg}
34643bfa90b6Smrg# end func_convert_path_msys_to_cygwin
34653bfa90b6Smrg
34663bfa90b6Smrg
34673bfa90b6Smrg# func_convert_path_nix_to_cygwin ARG
34683bfa90b6Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
34693bfa90b6Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
34703bfa90b6Smrg# func_to_host_file_result.
34713bfa90b6Smrgfunc_convert_path_nix_to_cygwin ()
34723bfa90b6Smrg{
347325dbecb6Smrg  $debug_cmd
347425dbecb6Smrg
347525dbecb6Smrg  func_to_host_path_result=$1
34763bfa90b6Smrg  if test -n "$1"; then
34773bfa90b6Smrg    # Remove leading and trailing path separator characters from
34783bfa90b6Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
34793bfa90b6Smrg    # into '.;' and ';.', and winepath ignores them completely.
34803bfa90b6Smrg    func_stripname : : "$1"
34813bfa90b6Smrg    func_to_host_path_tmp1=$func_stripname_result
34823bfa90b6Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34833bfa90b6Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
348425dbecb6Smrg    func_to_host_path_result=$func_cygpath_result
34853bfa90b6Smrg    func_convert_path_check : : \
34863bfa90b6Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34873bfa90b6Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34883bfa90b6Smrg  fi
34893bfa90b6Smrg}
34903bfa90b6Smrg# end func_convert_path_nix_to_cygwin
34913bfa90b6Smrg
34923bfa90b6Smrg
349325dbecb6Smrg# func_dll_def_p FILE
349425dbecb6Smrg# True iff FILE is a Windows DLL '.def' file.
349525dbecb6Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
349625dbecb6Smrgfunc_dll_def_p ()
349725dbecb6Smrg{
349825dbecb6Smrg  $debug_cmd
349925dbecb6Smrg
350025dbecb6Smrg  func_dll_def_p_tmp=`$SED -n \
350125dbecb6Smrg    -e 's/^[	 ]*//' \
350225dbecb6Smrg    -e '/^\(;.*\)*$/d' \
350325dbecb6Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
350425dbecb6Smrg    -e q \
350525dbecb6Smrg    "$1"`
350625dbecb6Smrg  test DEF = "$func_dll_def_p_tmp"
350725dbecb6Smrg}
350825dbecb6Smrg
350925dbecb6Smrg
3510b68e1f86Smrg# func_mode_compile arg...
3511b68e1f86Smrgfunc_mode_compile ()
3512b68e1f86Smrg{
351325dbecb6Smrg    $debug_cmd
351425dbecb6Smrg
3515b68e1f86Smrg    # Get the compilation command and the source file.
3516b68e1f86Smrg    base_compile=
351725dbecb6Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3518b68e1f86Smrg    suppress_opt=yes
3519b68e1f86Smrg    suppress_output=
3520b68e1f86Smrg    arg_mode=normal
3521b68e1f86Smrg    libobj=
3522b68e1f86Smrg    later=
3523b68e1f86Smrg    pie_flag=
3524b68e1f86Smrg
3525b68e1f86Smrg    for arg
3526b68e1f86Smrg    do
3527b68e1f86Smrg      case $arg_mode in
3528b68e1f86Smrg      arg  )
3529b68e1f86Smrg	# do not "continue".  Instead, add this to base_compile
353025dbecb6Smrg	lastarg=$arg
3531b68e1f86Smrg	arg_mode=normal
3532b68e1f86Smrg	;;
3533b68e1f86Smrg
3534b68e1f86Smrg      target )
353525dbecb6Smrg	libobj=$arg
3536b68e1f86Smrg	arg_mode=normal
3537b68e1f86Smrg	continue
3538b68e1f86Smrg	;;
3539b68e1f86Smrg
3540b68e1f86Smrg      normal )
3541b68e1f86Smrg	# Accept any command-line options.
3542b68e1f86Smrg	case $arg in
3543b68e1f86Smrg	-o)
3544b68e1f86Smrg	  test -n "$libobj" && \
354525dbecb6Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3546b68e1f86Smrg	  arg_mode=target
3547b68e1f86Smrg	  continue
3548b68e1f86Smrg	  ;;
3549b68e1f86Smrg
3550b68e1f86Smrg	-pie | -fpie | -fPIE)
35513bfa90b6Smrg          func_append pie_flag " $arg"
3552b68e1f86Smrg	  continue
3553b68e1f86Smrg	  ;;
3554b68e1f86Smrg
3555b68e1f86Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
35563bfa90b6Smrg	  func_append later " $arg"
3557b68e1f86Smrg	  continue
3558b68e1f86Smrg	  ;;
3559b68e1f86Smrg
3560b68e1f86Smrg	-no-suppress)
35616df26cacSmrg	  suppress_opt=no
35626df26cacSmrg	  continue
35636df26cacSmrg	  ;;
35646df26cacSmrg
35656df26cacSmrg	-Xcompiler)
35666df26cacSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
35676df26cacSmrg	  continue      #  The current "srcfile" will either be retained or
35686df26cacSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
35696df26cacSmrg
35706df26cacSmrg	-Wc,*)
3571b68e1f86Smrg	  func_stripname '-Wc,' '' "$arg"
3572b68e1f86Smrg	  args=$func_stripname_result
35736df26cacSmrg	  lastarg=
357425dbecb6Smrg	  save_ifs=$IFS; IFS=,
3575b68e1f86Smrg	  for arg in $args; do
357625dbecb6Smrg	    IFS=$save_ifs
35773bfa90b6Smrg	    func_append_quoted lastarg "$arg"
35786df26cacSmrg	  done
357925dbecb6Smrg	  IFS=$save_ifs
3580b68e1f86Smrg	  func_stripname ' ' '' "$lastarg"
3581b68e1f86Smrg	  lastarg=$func_stripname_result
35826df26cacSmrg
35836df26cacSmrg	  # Add the arguments to base_compile.
35843bfa90b6Smrg	  func_append base_compile " $lastarg"
35856df26cacSmrg	  continue
35866df26cacSmrg	  ;;
35876df26cacSmrg
3588b68e1f86Smrg	*)
35896df26cacSmrg	  # Accept the current argument as the source file.
35906df26cacSmrg	  # The previous "srcfile" becomes the current argument.
35916df26cacSmrg	  #
359225dbecb6Smrg	  lastarg=$srcfile
359325dbecb6Smrg	  srcfile=$arg
35946df26cacSmrg	  ;;
35956df26cacSmrg	esac  #  case $arg
35966df26cacSmrg	;;
35976df26cacSmrg      esac    #  case $arg_mode
35986df26cacSmrg
35996df26cacSmrg      # Aesthetically quote the previous argument.
36003bfa90b6Smrg      func_append_quoted base_compile "$lastarg"
36016df26cacSmrg    done # for arg
36026df26cacSmrg
36036df26cacSmrg    case $arg_mode in
36046df26cacSmrg    arg)
3605b68e1f86Smrg      func_fatal_error "you must specify an argument for -Xcompile"
36066df26cacSmrg      ;;
36076df26cacSmrg    target)
360825dbecb6Smrg      func_fatal_error "you must specify a target with '-o'"
36096df26cacSmrg      ;;
36106df26cacSmrg    *)
36116df26cacSmrg      # Get the name of the library object.
3612b68e1f86Smrg      test -z "$libobj" && {
3613b68e1f86Smrg	func_basename "$srcfile"
361425dbecb6Smrg	libobj=$func_basename_result
3615b68e1f86Smrg      }
36166df26cacSmrg      ;;
36176df26cacSmrg    esac
36186df26cacSmrg
36196df26cacSmrg    # Recognize several different file suffixes.
36206df26cacSmrg    # If the user specifies -o file.o, it is replaced with file.lo
36216df26cacSmrg    case $libobj in
3622b68e1f86Smrg    *.[cCFSifmso] | \
3623b68e1f86Smrg    *.ada | *.adb | *.ads | *.asm | \
3624b68e1f86Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
36253bfa90b6Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3626b68e1f86Smrg      func_xform "$libobj"
3627b68e1f86Smrg      libobj=$func_xform_result
3628b68e1f86Smrg      ;;
36296df26cacSmrg    esac
36306df26cacSmrg
36316df26cacSmrg    case $libobj in
3632b68e1f86Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
36336df26cacSmrg    *)
363425dbecb6Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
36356df26cacSmrg      ;;
36366df26cacSmrg    esac
36376df26cacSmrg
36386df26cacSmrg    func_infer_tag $base_compile
36396df26cacSmrg
36406df26cacSmrg    for arg in $later; do
36416df26cacSmrg      case $arg in
3642b68e1f86Smrg      -shared)
364325dbecb6Smrg	test yes = "$build_libtool_libs" \
364425dbecb6Smrg	  || func_fatal_configuration "cannot build a shared library"
3645b68e1f86Smrg	build_old_libs=no
3646b68e1f86Smrg	continue
3647b68e1f86Smrg	;;
3648b68e1f86Smrg
36496df26cacSmrg      -static)
3650b68e1f86Smrg	build_libtool_libs=no
36516df26cacSmrg	build_old_libs=yes
36526df26cacSmrg	continue
36536df26cacSmrg	;;
36546df26cacSmrg
36556df26cacSmrg      -prefer-pic)
36566df26cacSmrg	pic_mode=yes
36576df26cacSmrg	continue
36586df26cacSmrg	;;
36596df26cacSmrg
36606df26cacSmrg      -prefer-non-pic)
36616df26cacSmrg	pic_mode=no
36626df26cacSmrg	continue
36636df26cacSmrg	;;
36646df26cacSmrg      esac
36656df26cacSmrg    done
36666df26cacSmrg
366725dbecb6Smrg    func_quote_arg pretty "$libobj"
366825dbecb6Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3669b68e1f86Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
367025dbecb6Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3671b68e1f86Smrg    func_dirname_and_basename "$obj" "/" ""
367225dbecb6Smrg    objname=$func_basename_result
367325dbecb6Smrg    xdir=$func_dirname_result
367425dbecb6Smrg    lobj=$xdir$objdir/$objname
36756df26cacSmrg
3676b68e1f86Smrg    test -z "$base_compile" && \
3677b68e1f86Smrg      func_fatal_help "you must specify a compilation command"
36786df26cacSmrg
36796df26cacSmrg    # Delete any leftover library objects.
368025dbecb6Smrg    if test yes = "$build_old_libs"; then
36816df26cacSmrg      removelist="$obj $lobj $libobj ${libobj}T"
36826df26cacSmrg    else
36836df26cacSmrg      removelist="$lobj $libobj ${libobj}T"
36846df26cacSmrg    fi
36856df26cacSmrg
36866df26cacSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
36876df26cacSmrg    case $host_os in
3688b68e1f86Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
36896df26cacSmrg      pic_mode=default
36906df26cacSmrg      ;;
36916df26cacSmrg    esac
369225dbecb6Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
36936df26cacSmrg      # non-PIC code in shared libraries is not supported
36946df26cacSmrg      pic_mode=default
36956df26cacSmrg    fi
36966df26cacSmrg
36976df26cacSmrg    # Calculate the filename of the output object if compiler does
36986df26cacSmrg    # not support -o with -c
369925dbecb6Smrg    if test no = "$compiler_c_o"; then
370025dbecb6Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
370125dbecb6Smrg      lockfile=$output_obj.lock
37026df26cacSmrg    else
37036df26cacSmrg      output_obj=
37046df26cacSmrg      need_locks=no
37056df26cacSmrg      lockfile=
37066df26cacSmrg    fi
37076df26cacSmrg
37086df26cacSmrg    # Lock this critical section if it is needed
37096df26cacSmrg    # We use this script file to make the link, it avoids creating a new file
371025dbecb6Smrg    if test yes = "$need_locks"; then
3711b68e1f86Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3712b68e1f86Smrg	func_echo "Waiting for $lockfile to be removed"
37136df26cacSmrg	sleep 2
37146df26cacSmrg      done
371525dbecb6Smrg    elif test warn = "$need_locks"; then
37166df26cacSmrg      if test -f "$lockfile"; then
3717b68e1f86Smrg	$ECHO "\
37186df26cacSmrg*** ERROR, $lockfile exists and contains:
37196df26cacSmrg`cat $lockfile 2>/dev/null`
37206df26cacSmrg
37216df26cacSmrgThis indicates that another process is trying to use the same
37226df26cacSmrgtemporary object file, and libtool could not work around it because
372325dbecb6Smrgyour compiler does not support '-c' and '-o' together.  If you
37246df26cacSmrgrepeat this compilation, it may succeed, by chance, but you had better
37256df26cacSmrgavoid parallel builds (make -j) in this platform, or get a better
37266df26cacSmrgcompiler."
37276df26cacSmrg
3728b68e1f86Smrg	$opt_dry_run || $RM $removelist
37296df26cacSmrg	exit $EXIT_FAILURE
37306df26cacSmrg      fi
37313bfa90b6Smrg      func_append removelist " $output_obj"
3732b68e1f86Smrg      $ECHO "$srcfile" > "$lockfile"
37336df26cacSmrg    fi
37346df26cacSmrg
3735b68e1f86Smrg    $opt_dry_run || $RM $removelist
37363bfa90b6Smrg    func_append removelist " $lockfile"
3737b68e1f86Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3738b68e1f86Smrg
37393bfa90b6Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
37403bfa90b6Smrg    srcfile=$func_to_tool_file_result
374125dbecb6Smrg    func_quote_arg pretty "$srcfile"
374225dbecb6Smrg    qsrcfile=$func_quote_arg_result
37436df26cacSmrg
37446df26cacSmrg    # Only build a PIC object if we are building libtool libraries.
374525dbecb6Smrg    if test yes = "$build_libtool_libs"; then
37466df26cacSmrg      # Without this assignment, base_compile gets emptied.
37476df26cacSmrg      fbsd_hideous_sh_bug=$base_compile
37486df26cacSmrg
374925dbecb6Smrg      if test no != "$pic_mode"; then
37506df26cacSmrg	command="$base_compile $qsrcfile $pic_flag"
37516df26cacSmrg      else
37526df26cacSmrg	# Don't build PIC code
37536df26cacSmrg	command="$base_compile $qsrcfile"
37546df26cacSmrg      fi
37556df26cacSmrg
3756b68e1f86Smrg      func_mkdir_p "$xdir$objdir"
37576df26cacSmrg
37586df26cacSmrg      if test -z "$output_obj"; then
37596df26cacSmrg	# Place PIC objects in $objdir
37603bfa90b6Smrg	func_append command " -o $lobj"
37616df26cacSmrg      fi
37626df26cacSmrg
3763b68e1f86Smrg      func_show_eval_locale "$command"	\
3764b68e1f86Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
37656df26cacSmrg
376625dbecb6Smrg      if test warn = "$need_locks" &&
37676df26cacSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3768b68e1f86Smrg	$ECHO "\
37696df26cacSmrg*** ERROR, $lockfile contains:
37706df26cacSmrg`cat $lockfile 2>/dev/null`
37716df26cacSmrg
37726df26cacSmrgbut it should contain:
37736df26cacSmrg$srcfile
37746df26cacSmrg
37756df26cacSmrgThis indicates that another process is trying to use the same
37766df26cacSmrgtemporary object file, and libtool could not work around it because
377725dbecb6Smrgyour compiler does not support '-c' and '-o' together.  If you
37786df26cacSmrgrepeat this compilation, it may succeed, by chance, but you had better
37796df26cacSmrgavoid parallel builds (make -j) in this platform, or get a better
37806df26cacSmrgcompiler."
37816df26cacSmrg
3782b68e1f86Smrg	$opt_dry_run || $RM $removelist
37836df26cacSmrg	exit $EXIT_FAILURE
37846df26cacSmrg      fi
37856df26cacSmrg
37866df26cacSmrg      # Just move the object if needed, then go on to compile the next one
37876df26cacSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3788b68e1f86Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3789b68e1f86Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
37906df26cacSmrg      fi
37916df26cacSmrg
37926df26cacSmrg      # Allow error messages only from the first compilation.
379325dbecb6Smrg      if test yes = "$suppress_opt"; then
3794b68e1f86Smrg	suppress_output=' >/dev/null 2>&1'
37956df26cacSmrg      fi
37966df26cacSmrg    fi
37976df26cacSmrg
37986df26cacSmrg    # Only build a position-dependent object if we build old libraries.
379925dbecb6Smrg    if test yes = "$build_old_libs"; then
380025dbecb6Smrg      if test yes != "$pic_mode"; then
38016df26cacSmrg	# Don't build PIC code
3802b68e1f86Smrg	command="$base_compile $qsrcfile$pie_flag"
38036df26cacSmrg      else
38046df26cacSmrg	command="$base_compile $qsrcfile $pic_flag"
38056df26cacSmrg      fi
380625dbecb6Smrg      if test yes = "$compiler_c_o"; then
38073bfa90b6Smrg	func_append command " -o $obj"
38086df26cacSmrg      fi
38096df26cacSmrg
38106df26cacSmrg      # Suppress compiler output if we already did a PIC compilation.
38113bfa90b6Smrg      func_append command "$suppress_output"
3812b68e1f86Smrg      func_show_eval_locale "$command" \
3813b68e1f86Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
38146df26cacSmrg
381525dbecb6Smrg      if test warn = "$need_locks" &&
38166df26cacSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3817b68e1f86Smrg	$ECHO "\
38186df26cacSmrg*** ERROR, $lockfile contains:
38196df26cacSmrg`cat $lockfile 2>/dev/null`
38206df26cacSmrg
38216df26cacSmrgbut it should contain:
38226df26cacSmrg$srcfile
38236df26cacSmrg
38246df26cacSmrgThis indicates that another process is trying to use the same
38256df26cacSmrgtemporary object file, and libtool could not work around it because
382625dbecb6Smrgyour compiler does not support '-c' and '-o' together.  If you
38276df26cacSmrgrepeat this compilation, it may succeed, by chance, but you had better
38286df26cacSmrgavoid parallel builds (make -j) in this platform, or get a better
38296df26cacSmrgcompiler."
38306df26cacSmrg
3831b68e1f86Smrg	$opt_dry_run || $RM $removelist
38326df26cacSmrg	exit $EXIT_FAILURE
38336df26cacSmrg      fi
38346df26cacSmrg
38356df26cacSmrg      # Just move the object if needed
38366df26cacSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3837b68e1f86Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3838b68e1f86Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38396df26cacSmrg      fi
38406df26cacSmrg    fi
38416df26cacSmrg
3842b68e1f86Smrg    $opt_dry_run || {
3843b68e1f86Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
38446df26cacSmrg
3845b68e1f86Smrg      # Unlock the critical section if it was locked
384625dbecb6Smrg      if test no != "$need_locks"; then
3847b68e1f86Smrg	removelist=$lockfile
3848b68e1f86Smrg        $RM "$lockfile"
3849b68e1f86Smrg      fi
3850b68e1f86Smrg    }
38516df26cacSmrg
38526df26cacSmrg    exit $EXIT_SUCCESS
3853b68e1f86Smrg}
38546df26cacSmrg
3855b68e1f86Smrg$opt_help || {
385625dbecb6Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3857b68e1f86Smrg}
38586df26cacSmrg
3859b68e1f86Smrgfunc_mode_help ()
3860b68e1f86Smrg{
3861b68e1f86Smrg    # We need to display help for each of the modes.
38623bfa90b6Smrg    case $opt_mode in
3863b68e1f86Smrg      "")
3864b68e1f86Smrg        # Generic help is extracted from the usage comments
3865b68e1f86Smrg        # at the start of this file.
3866b68e1f86Smrg        func_help
3867b68e1f86Smrg        ;;
38686df26cacSmrg
3869b68e1f86Smrg      clean)
3870b68e1f86Smrg        $ECHO \
3871b68e1f86Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
38726df26cacSmrg
3873b68e1f86SmrgRemove files from the build directory.
38746df26cacSmrg
3875b68e1f86SmrgRM is the name of the program to use to delete files associated with each FILE
387625dbecb6Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3877b68e1f86Smrgto RM.
38786df26cacSmrg
3879b68e1f86SmrgIf FILE is a libtool library, object or program, all the files associated
3880b68e1f86Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3881b68e1f86Smrg        ;;
38826df26cacSmrg
3883b68e1f86Smrg      compile)
3884b68e1f86Smrg      $ECHO \
3885b68e1f86Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
38866df26cacSmrg
3887b68e1f86SmrgCompile a source file into a libtool library object.
38886df26cacSmrg
3889b68e1f86SmrgThis mode accepts the following additional options:
38906df26cacSmrg
3891b68e1f86Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3892b68e1f86Smrg  -no-suppress      do not suppress compiler output for multiple passes
38933bfa90b6Smrg  -prefer-pic       try to build PIC objects only
38943bfa90b6Smrg  -prefer-non-pic   try to build non-PIC objects only
389525dbecb6Smrg  -shared           do not build a '.o' file suitable for static linking
389625dbecb6Smrg  -static           only build a '.o' file suitable for static linking
389725dbecb6Smrg  -Wc,FLAG
389825dbecb6Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
38996df26cacSmrg
390025dbecb6SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3901b68e1f86Smrgfrom the given SOURCEFILE.
39026df26cacSmrg
3903b68e1f86SmrgThe output file name is determined by removing the directory component from
390425dbecb6SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
390525dbecb6Smrglibrary object suffix, '.lo'."
3906b68e1f86Smrg        ;;
39076df26cacSmrg
3908b68e1f86Smrg      execute)
3909b68e1f86Smrg        $ECHO \
3910b68e1f86Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
39116df26cacSmrg
3912b68e1f86SmrgAutomatically set library path, then run a program.
39136df26cacSmrg
3914b68e1f86SmrgThis mode accepts the following additional options:
39156df26cacSmrg
3916b68e1f86Smrg  -dlopen FILE      add the directory containing FILE to the library path
39176df26cacSmrg
391825dbecb6SmrgThis mode sets the library path environment variable according to '-dlopen'
3919b68e1f86Smrgflags.
39206df26cacSmrg
3921b68e1f86SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3922b68e1f86Smrginto their corresponding uninstalled binary, and any of their required library
3923b68e1f86Smrgdirectories are added to the library path.
39246df26cacSmrg
3925b68e1f86SmrgThen, COMMAND is executed, with ARGS as arguments."
3926b68e1f86Smrg        ;;
39276df26cacSmrg
3928b68e1f86Smrg      finish)
3929b68e1f86Smrg        $ECHO \
3930b68e1f86Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
39316df26cacSmrg
3932b68e1f86SmrgComplete the installation of libtool libraries.
39336df26cacSmrg
3934b68e1f86SmrgEach LIBDIR is a directory that contains libtool libraries.
39356df26cacSmrg
3936b68e1f86SmrgThe commands that this mode executes may require superuser privileges.  Use
393725dbecb6Smrgthe '--dry-run' option if you just want to see what would be executed."
3938b68e1f86Smrg        ;;
39396df26cacSmrg
3940b68e1f86Smrg      install)
3941b68e1f86Smrg        $ECHO \
3942b68e1f86Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
39436df26cacSmrg
3944b68e1f86SmrgInstall executables or libraries.
39456df26cacSmrg
3946b68e1f86SmrgINSTALL-COMMAND is the installation command.  The first component should be
394725dbecb6Smrgeither the 'install' or 'cp' program.
39486df26cacSmrg
3949b68e1f86SmrgThe following components of INSTALL-COMMAND are treated specially:
39506df26cacSmrg
39513bfa90b6Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
39526df26cacSmrg
3953b68e1f86SmrgThe rest of the components are interpreted as arguments to that command (only
3954b68e1f86SmrgBSD-compatible install options are recognized)."
3955b68e1f86Smrg        ;;
39566df26cacSmrg
3957b68e1f86Smrg      link)
3958b68e1f86Smrg        $ECHO \
3959b68e1f86Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
39606df26cacSmrg
3961b68e1f86SmrgLink object files or libraries together to form another library, or to
3962b68e1f86Smrgcreate an executable program.
39636df26cacSmrg
3964b68e1f86SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3965b68e1f86Smrga program from several object files.
39666df26cacSmrg
3967b68e1f86SmrgThe following components of LINK-COMMAND are treated specially:
39686df26cacSmrg
3969b68e1f86Smrg  -all-static       do not do any dynamic linking at all
3970b68e1f86Smrg  -avoid-version    do not add a version suffix if possible
39713bfa90b6Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
39723bfa90b6Smrg                    libraries must be found in the PATH setting at runtime)
397325dbecb6Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3974b68e1f86Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3975b68e1f86Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3976b68e1f86Smrg  -export-symbols SYMFILE
3977b68e1f86Smrg                    try to export only the symbols listed in SYMFILE
3978b68e1f86Smrg  -export-symbols-regex REGEX
3979b68e1f86Smrg                    try to export only the symbols matching REGEX
3980b68e1f86Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3981b68e1f86Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3982b68e1f86Smrg  -module           build a library that can dlopened
3983b68e1f86Smrg  -no-fast-install  disable the fast-install mode
3984b68e1f86Smrg  -no-install       link a not-installable executable
3985b68e1f86Smrg  -no-undefined     declare that a library does not refer to external symbols
3986b68e1f86Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
398725dbecb6Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
398825dbecb6Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3989b68e1f86Smrg  -precious-files-regex REGEX
3990b68e1f86Smrg                    don't remove output files matching REGEX
3991b68e1f86Smrg  -release RELEASE  specify package release information
3992b68e1f86Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3993b68e1f86Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3994b68e1f86Smrg  -shared           only do dynamic linking of libtool libraries
3995b68e1f86Smrg  -shrext SUFFIX    override the standard shared library file extension
3996b68e1f86Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
3997b68e1f86Smrg  -static-libtool-libs
3998b68e1f86Smrg                    do not do any dynamic linking of libtool libraries
3999b68e1f86Smrg  -version-info CURRENT[:REVISION[:AGE]]
4000b68e1f86Smrg                    specify library version info [each variable defaults to 0]
4001b68e1f86Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
40023bfa90b6Smrg  -Wc,FLAG
40033bfa90b6Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
400425dbecb6Smrg  -Wa,FLAG
400525dbecb6Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
40063bfa90b6Smrg  -Wl,FLAG
40073bfa90b6Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
40083bfa90b6Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
40096df26cacSmrg
401025dbecb6SmrgAll other options (arguments beginning with '-') are ignored.
40116df26cacSmrg
401225dbecb6SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4013b68e1f86Smrgtreated as uninstalled libtool libraries, other files are standard or library
4014b68e1f86Smrgobject files.
40156df26cacSmrg
401625dbecb6SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
401725dbecb6Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4018b68e1f86Smrgrequired, except when creating a convenience library.
40196df26cacSmrg
402025dbecb6SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
402125dbecb6Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40226df26cacSmrg
402325dbecb6SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4024b68e1f86Smrgis created, otherwise an executable program is created."
40256df26cacSmrg        ;;
40266df26cacSmrg
4027b68e1f86Smrg      uninstall)
4028b68e1f86Smrg        $ECHO \
4029b68e1f86Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
40306df26cacSmrg
4031b68e1f86SmrgRemove libraries from an installation directory.
40326df26cacSmrg
4033b68e1f86SmrgRM is the name of the program to use to delete files associated with each FILE
403425dbecb6Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4035b68e1f86Smrgto RM.
40366df26cacSmrg
4037b68e1f86SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4038b68e1f86SmrgOtherwise, only FILE itself is deleted using RM."
4039b68e1f86Smrg        ;;
40406df26cacSmrg
4041b68e1f86Smrg      *)
404225dbecb6Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
4043b68e1f86Smrg        ;;
4044b68e1f86Smrg    esac
40456df26cacSmrg
40463bfa90b6Smrg    echo
404725dbecb6Smrg    $ECHO "Try '$progname --help' for more information about other modes."
4048b68e1f86Smrg}
40496df26cacSmrg
40503bfa90b6Smrg# Now that we've collected a possible --mode arg, show help if necessary
40513bfa90b6Smrgif $opt_help; then
405225dbecb6Smrg  if test : = "$opt_help"; then
40533bfa90b6Smrg    func_mode_help
40543bfa90b6Smrg  else
40553bfa90b6Smrg    {
40563bfa90b6Smrg      func_help noexit
40573bfa90b6Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40583bfa90b6Smrg	func_mode_help
40593bfa90b6Smrg      done
406025dbecb6Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
40613bfa90b6Smrg    {
40623bfa90b6Smrg      func_help noexit
40633bfa90b6Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40643bfa90b6Smrg	echo
40653bfa90b6Smrg	func_mode_help
40663bfa90b6Smrg      done
40673bfa90b6Smrg    } |
406825dbecb6Smrg    $SED '1d
40693bfa90b6Smrg      /^When reporting/,/^Report/{
40703bfa90b6Smrg	H
40713bfa90b6Smrg	d
40723bfa90b6Smrg      }
40733bfa90b6Smrg      $x
40743bfa90b6Smrg      /information about other modes/d
40753bfa90b6Smrg      /more detailed .*MODE/d
40763bfa90b6Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
40773bfa90b6Smrg  fi
40783bfa90b6Smrg  exit $?
40793bfa90b6Smrgfi
40806df26cacSmrg
40816df26cacSmrg
4082b68e1f86Smrg# func_mode_execute arg...
4083b68e1f86Smrgfunc_mode_execute ()
4084b68e1f86Smrg{
408525dbecb6Smrg    $debug_cmd
408625dbecb6Smrg
4087b68e1f86Smrg    # The first argument is the command name.
408825dbecb6Smrg    cmd=$nonopt
4089b68e1f86Smrg    test -z "$cmd" && \
4090b68e1f86Smrg      func_fatal_help "you must specify a COMMAND"
40916df26cacSmrg
4092b68e1f86Smrg    # Handle -dlopen flags immediately.
40933bfa90b6Smrg    for file in $opt_dlopen; do
4094b68e1f86Smrg      test -f "$file" \
409525dbecb6Smrg	|| func_fatal_help "'$file' is not a file"
40966df26cacSmrg
4097b68e1f86Smrg      dir=
4098b68e1f86Smrg      case $file in
4099b68e1f86Smrg      *.la)
41003bfa90b6Smrg	func_resolve_sysroot "$file"
41013bfa90b6Smrg	file=$func_resolve_sysroot_result
41023bfa90b6Smrg
4103b68e1f86Smrg	# Check to see that this really is a libtool archive.
4104b68e1f86Smrg	func_lalib_unsafe_p "$file" \
410525dbecb6Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
41066df26cacSmrg
4107b68e1f86Smrg	# Read the libtool library.
4108b68e1f86Smrg	dlname=
4109b68e1f86Smrg	library_names=
4110b68e1f86Smrg	func_source "$file"
41116df26cacSmrg
4112b68e1f86Smrg	# Skip this library if it cannot be dlopened.
4113b68e1f86Smrg	if test -z "$dlname"; then
4114b68e1f86Smrg	  # Warn if it was a shared library.
4115b68e1f86Smrg	  test -n "$library_names" && \
411625dbecb6Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4117b68e1f86Smrg	  continue
4118b68e1f86Smrg	fi
41196df26cacSmrg
4120b68e1f86Smrg	func_dirname "$file" "" "."
412125dbecb6Smrg	dir=$func_dirname_result
41226df26cacSmrg
4123b68e1f86Smrg	if test -f "$dir/$objdir/$dlname"; then
41243bfa90b6Smrg	  func_append dir "/$objdir"
4125b68e1f86Smrg	else
4126b68e1f86Smrg	  if test ! -f "$dir/$dlname"; then
412725dbecb6Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4128b68e1f86Smrg	  fi
4129b68e1f86Smrg	fi
41306df26cacSmrg	;;
41316df26cacSmrg
4132b68e1f86Smrg      *.lo)
4133b68e1f86Smrg	# Just add the directory containing the .lo file.
4134b68e1f86Smrg	func_dirname "$file" "" "."
413525dbecb6Smrg	dir=$func_dirname_result
41366df26cacSmrg	;;
41376df26cacSmrg
4138b68e1f86Smrg      *)
413925dbecb6Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
41406df26cacSmrg	continue
41416df26cacSmrg	;;
4142b68e1f86Smrg      esac
41436df26cacSmrg
4144b68e1f86Smrg      # Get the absolute pathname.
4145b68e1f86Smrg      absdir=`cd "$dir" && pwd`
414625dbecb6Smrg      test -n "$absdir" && dir=$absdir
41476df26cacSmrg
4148b68e1f86Smrg      # Now add the directory to shlibpath_var.
4149b68e1f86Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4150b68e1f86Smrg	eval "$shlibpath_var=\"\$dir\""
4151b68e1f86Smrg      else
4152b68e1f86Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4153b68e1f86Smrg      fi
4154b68e1f86Smrg    done
41556df26cacSmrg
4156b68e1f86Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4157b68e1f86Smrg    # rather than running their programs.
415825dbecb6Smrg    libtool_execute_magic=$magic
41596df26cacSmrg
4160b68e1f86Smrg    # Check if any of the arguments is a wrapper script.
4161b68e1f86Smrg    args=
4162b68e1f86Smrg    for file
4163b68e1f86Smrg    do
4164b68e1f86Smrg      case $file in
41653bfa90b6Smrg      -* | *.la | *.lo ) ;;
4166b68e1f86Smrg      *)
4167b68e1f86Smrg	# Do a test to see if this is really a libtool program.
4168b68e1f86Smrg	if func_ltwrapper_script_p "$file"; then
4169b68e1f86Smrg	  func_source "$file"
4170b68e1f86Smrg	  # Transform arg to wrapped name.
417125dbecb6Smrg	  file=$progdir/$program
4172b68e1f86Smrg	elif func_ltwrapper_executable_p "$file"; then
4173b68e1f86Smrg	  func_ltwrapper_scriptname "$file"
4174b68e1f86Smrg	  func_source "$func_ltwrapper_scriptname_result"
4175b68e1f86Smrg	  # Transform arg to wrapped name.
417625dbecb6Smrg	  file=$progdir/$program
4177b68e1f86Smrg	fi
4178b68e1f86Smrg	;;
4179b68e1f86Smrg      esac
4180b68e1f86Smrg      # Quote arguments (to preserve shell metacharacters).
41813bfa90b6Smrg      func_append_quoted args "$file"
4182b68e1f86Smrg    done
41836df26cacSmrg
418425dbecb6Smrg    if $opt_dry_run; then
418525dbecb6Smrg      # Display what would be done.
418625dbecb6Smrg      if test -n "$shlibpath_var"; then
418725dbecb6Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
418825dbecb6Smrg	echo "export $shlibpath_var"
418925dbecb6Smrg      fi
419025dbecb6Smrg      $ECHO "$cmd$args"
419125dbecb6Smrg      exit $EXIT_SUCCESS
419225dbecb6Smrg    else
4193b68e1f86Smrg      if test -n "$shlibpath_var"; then
4194b68e1f86Smrg	# Export the shlibpath_var.
4195b68e1f86Smrg	eval "export $shlibpath_var"
4196b68e1f86Smrg      fi
41976df26cacSmrg
4198b68e1f86Smrg      # Restore saved environment variables
4199b68e1f86Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4200b68e1f86Smrg      do
4201b68e1f86Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4202b68e1f86Smrg                $lt_var=\$save_$lt_var; export $lt_var
42036df26cacSmrg	      else
4204b68e1f86Smrg		$lt_unset $lt_var
4205b68e1f86Smrg	      fi"
4206b68e1f86Smrg      done
42076df26cacSmrg
4208b68e1f86Smrg      # Now prepare to actually exec the command.
420925dbecb6Smrg      exec_cmd=\$cmd$args
4210b68e1f86Smrg    fi
4211b68e1f86Smrg}
42126df26cacSmrg
421325dbecb6Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
42146df26cacSmrg
42156df26cacSmrg
4216b68e1f86Smrg# func_mode_finish arg...
4217b68e1f86Smrgfunc_mode_finish ()
4218b68e1f86Smrg{
421925dbecb6Smrg    $debug_cmd
422025dbecb6Smrg
42213bfa90b6Smrg    libs=
42223bfa90b6Smrg    libdirs=
4223b68e1f86Smrg    admincmds=
42246df26cacSmrg
42253bfa90b6Smrg    for opt in "$nonopt" ${1+"$@"}
42263bfa90b6Smrg    do
42273bfa90b6Smrg      if test -d "$opt"; then
42283bfa90b6Smrg	func_append libdirs " $opt"
42293bfa90b6Smrg
42303bfa90b6Smrg      elif test -f "$opt"; then
42313bfa90b6Smrg	if func_lalib_unsafe_p "$opt"; then
42323bfa90b6Smrg	  func_append libs " $opt"
42333bfa90b6Smrg	else
423425dbecb6Smrg	  func_warning "'$opt' is not a valid libtool archive"
42353bfa90b6Smrg	fi
42363bfa90b6Smrg
42373bfa90b6Smrg      else
423825dbecb6Smrg	func_fatal_error "invalid argument '$opt'"
42393bfa90b6Smrg      fi
42403bfa90b6Smrg    done
42413bfa90b6Smrg
42423bfa90b6Smrg    if test -n "$libs"; then
42433bfa90b6Smrg      if test -n "$lt_sysroot"; then
42443bfa90b6Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
42453bfa90b6Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
42463bfa90b6Smrg      else
42473bfa90b6Smrg        sysroot_cmd=
42483bfa90b6Smrg      fi
42493bfa90b6Smrg
42503bfa90b6Smrg      # Remove sysroot references
42513bfa90b6Smrg      if $opt_dry_run; then
42523bfa90b6Smrg        for lib in $libs; do
425325dbecb6Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
42543bfa90b6Smrg        done
42553bfa90b6Smrg      else
42563bfa90b6Smrg        tmpdir=`func_mktempdir`
42573bfa90b6Smrg        for lib in $libs; do
425825dbecb6Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
42593bfa90b6Smrg	    > $tmpdir/tmp-la
42603bfa90b6Smrg	  mv -f $tmpdir/tmp-la $lib
42613bfa90b6Smrg	done
42623bfa90b6Smrg        ${RM}r "$tmpdir"
42633bfa90b6Smrg      fi
42643bfa90b6Smrg    fi
42656df26cacSmrg
42663bfa90b6Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4267b68e1f86Smrg      for libdir in $libdirs; do
4268b68e1f86Smrg	if test -n "$finish_cmds"; then
4269b68e1f86Smrg	  # Do each command in the finish commands.
4270b68e1f86Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4271b68e1f86Smrg'"$cmd"'"'
42726df26cacSmrg	fi
4273b68e1f86Smrg	if test -n "$finish_eval"; then
4274b68e1f86Smrg	  # Do the single finish_eval.
4275b68e1f86Smrg	  eval cmds=\"$finish_eval\"
42763bfa90b6Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4277b68e1f86Smrg       $cmds"
4278b68e1f86Smrg	fi
4279b68e1f86Smrg      done
4280b68e1f86Smrg    fi
42816df26cacSmrg
4282b68e1f86Smrg    # Exit here if they wanted silent mode.
428325dbecb6Smrg    $opt_quiet && exit $EXIT_SUCCESS
42846df26cacSmrg
42853bfa90b6Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42863bfa90b6Smrg      echo "----------------------------------------------------------------------"
42873bfa90b6Smrg      echo "Libraries have been installed in:"
42883bfa90b6Smrg      for libdir in $libdirs; do
42893bfa90b6Smrg	$ECHO "   $libdir"
42903bfa90b6Smrg      done
42913bfa90b6Smrg      echo
42923bfa90b6Smrg      echo "If you ever happen to want to link against installed libraries"
42933bfa90b6Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
429425dbecb6Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
42953bfa90b6Smrg      echo "flag during linking and do at least one of the following:"
42963bfa90b6Smrg      if test -n "$shlibpath_var"; then
429725dbecb6Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
42983bfa90b6Smrg	echo "     during execution"
42993bfa90b6Smrg      fi
43003bfa90b6Smrg      if test -n "$runpath_var"; then
430125dbecb6Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
43023bfa90b6Smrg	echo "     during linking"
43033bfa90b6Smrg      fi
43043bfa90b6Smrg      if test -n "$hardcode_libdir_flag_spec"; then
43053bfa90b6Smrg	libdir=LIBDIR
43063bfa90b6Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
43076df26cacSmrg
430825dbecb6Smrg	$ECHO "   - use the '$flag' linker flag"
43093bfa90b6Smrg      fi
43103bfa90b6Smrg      if test -n "$admincmds"; then
43113bfa90b6Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
43123bfa90b6Smrg      fi
43133bfa90b6Smrg      if test -f /etc/ld.so.conf; then
431425dbecb6Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
43153bfa90b6Smrg      fi
43163bfa90b6Smrg      echo
4317b68e1f86Smrg
43183bfa90b6Smrg      echo "See any operating system documentation about shared libraries for"
43193bfa90b6Smrg      case $host in
43203bfa90b6Smrg	solaris2.[6789]|solaris2.1[0-9])
43213bfa90b6Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
43223bfa90b6Smrg	  echo "pages."
43233bfa90b6Smrg	  ;;
43243bfa90b6Smrg	*)
43253bfa90b6Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
43263bfa90b6Smrg	  ;;
43273bfa90b6Smrg      esac
43283bfa90b6Smrg      echo "----------------------------------------------------------------------"
43293bfa90b6Smrg    fi
4330b68e1f86Smrg    exit $EXIT_SUCCESS
4331b68e1f86Smrg}
4332b68e1f86Smrg
433325dbecb6Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4334b68e1f86Smrg
4335b68e1f86Smrg
4336b68e1f86Smrg# func_mode_install arg...
4337b68e1f86Smrgfunc_mode_install ()
4338b68e1f86Smrg{
433925dbecb6Smrg    $debug_cmd
434025dbecb6Smrg
4341b68e1f86Smrg    # There may be an optional sh(1) argument at the beginning of
4342b68e1f86Smrg    # install_prog (especially on Windows NT).
434325dbecb6Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4344b68e1f86Smrg       # Allow the use of GNU shtool's install command.
434525dbecb6Smrg       case $nonopt in *shtool*) :;; *) false;; esac
434625dbecb6Smrg    then
4347b68e1f86Smrg      # Aesthetically quote it.
434825dbecb6Smrg      func_quote_arg pretty "$nonopt"
434925dbecb6Smrg      install_prog="$func_quote_arg_result "
4350b68e1f86Smrg      arg=$1
4351b68e1f86Smrg      shift
4352b68e1f86Smrg    else
4353b68e1f86Smrg      install_prog=
4354b68e1f86Smrg      arg=$nonopt
4355b68e1f86Smrg    fi
4356b68e1f86Smrg
4357b68e1f86Smrg    # The real first argument should be the name of the installation program.
4358b68e1f86Smrg    # Aesthetically quote it.
435925dbecb6Smrg    func_quote_arg pretty "$arg"
436025dbecb6Smrg    func_append install_prog "$func_quote_arg_result"
43613bfa90b6Smrg    install_shared_prog=$install_prog
43623bfa90b6Smrg    case " $install_prog " in
43633bfa90b6Smrg      *[\\\ /]cp\ *) install_cp=: ;;
43643bfa90b6Smrg      *) install_cp=false ;;
43653bfa90b6Smrg    esac
4366b68e1f86Smrg
4367b68e1f86Smrg    # We need to accept at least all the BSD install flags.
4368b68e1f86Smrg    dest=
4369b68e1f86Smrg    files=
4370b68e1f86Smrg    opts=
4371b68e1f86Smrg    prev=
4372b68e1f86Smrg    install_type=
437325dbecb6Smrg    isdir=false
4374b68e1f86Smrg    stripme=
43753bfa90b6Smrg    no_mode=:
4376b68e1f86Smrg    for arg
4377b68e1f86Smrg    do
43783bfa90b6Smrg      arg2=
4379b68e1f86Smrg      if test -n "$dest"; then
43803bfa90b6Smrg	func_append files " $dest"
4381b68e1f86Smrg	dest=$arg
4382b68e1f86Smrg	continue
4383b68e1f86Smrg      fi
4384b68e1f86Smrg
4385b68e1f86Smrg      case $arg in
438625dbecb6Smrg      -d) isdir=: ;;
4387b68e1f86Smrg      -f)
43883bfa90b6Smrg	if $install_cp; then :; else
43893bfa90b6Smrg	  prev=$arg
43903bfa90b6Smrg	fi
4391b68e1f86Smrg	;;
4392b68e1f86Smrg      -g | -m | -o)
4393b68e1f86Smrg	prev=$arg
4394b68e1f86Smrg	;;
4395b68e1f86Smrg      -s)
4396b68e1f86Smrg	stripme=" -s"
4397b68e1f86Smrg	continue
4398b68e1f86Smrg	;;
4399b68e1f86Smrg      -*)
4400b68e1f86Smrg	;;
4401b68e1f86Smrg      *)
4402b68e1f86Smrg	# If the previous option needed an argument, then skip it.
4403b68e1f86Smrg	if test -n "$prev"; then
440425dbecb6Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
44053bfa90b6Smrg	    arg2=$install_override_mode
44063bfa90b6Smrg	    no_mode=false
44073bfa90b6Smrg	  fi
44086df26cacSmrg	  prev=
44096df26cacSmrg	else
4410b68e1f86Smrg	  dest=$arg
4411b68e1f86Smrg	  continue
44126df26cacSmrg	fi
44136df26cacSmrg	;;
4414b68e1f86Smrg      esac
44156df26cacSmrg
4416b68e1f86Smrg      # Aesthetically quote the argument.
441725dbecb6Smrg      func_quote_arg pretty "$arg"
441825dbecb6Smrg      func_append install_prog " $func_quote_arg_result"
44193bfa90b6Smrg      if test -n "$arg2"; then
442025dbecb6Smrg	func_quote_arg pretty "$arg2"
44213bfa90b6Smrg      fi
442225dbecb6Smrg      func_append install_shared_prog " $func_quote_arg_result"
4423b68e1f86Smrg    done
44246df26cacSmrg
4425b68e1f86Smrg    test -z "$install_prog" && \
4426b68e1f86Smrg      func_fatal_help "you must specify an install program"
44276df26cacSmrg
4428b68e1f86Smrg    test -n "$prev" && \
442925dbecb6Smrg      func_fatal_help "the '$prev' option requires an argument"
44306df26cacSmrg
44313bfa90b6Smrg    if test -n "$install_override_mode" && $no_mode; then
44323bfa90b6Smrg      if $install_cp; then :; else
443325dbecb6Smrg	func_quote_arg pretty "$install_override_mode"
443425dbecb6Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
44353bfa90b6Smrg      fi
44363bfa90b6Smrg    fi
44373bfa90b6Smrg
4438b68e1f86Smrg    if test -z "$files"; then
4439b68e1f86Smrg      if test -z "$dest"; then
4440b68e1f86Smrg	func_fatal_help "no file or destination specified"
4441b68e1f86Smrg      else
4442b68e1f86Smrg	func_fatal_help "you must specify a destination"
4443b68e1f86Smrg      fi
44446df26cacSmrg    fi
44456df26cacSmrg
4446b68e1f86Smrg    # Strip any trailing slash from the destination.
4447b68e1f86Smrg    func_stripname '' '/' "$dest"
4448b68e1f86Smrg    dest=$func_stripname_result
44496df26cacSmrg
4450b68e1f86Smrg    # Check to see that the destination is a directory.
445125dbecb6Smrg    test -d "$dest" && isdir=:
445225dbecb6Smrg    if $isdir; then
445325dbecb6Smrg      destdir=$dest
4454b68e1f86Smrg      destname=
44556df26cacSmrg    else
4456b68e1f86Smrg      func_dirname_and_basename "$dest" "" "."
445725dbecb6Smrg      destdir=$func_dirname_result
445825dbecb6Smrg      destname=$func_basename_result
44596df26cacSmrg
4460b68e1f86Smrg      # Not a directory, so check to see that there is only one file specified.
4461b68e1f86Smrg      set dummy $files; shift
4462b68e1f86Smrg      test "$#" -gt 1 && \
446325dbecb6Smrg	func_fatal_help "'$dest' is not a directory"
44646df26cacSmrg    fi
4465b68e1f86Smrg    case $destdir in
4466b68e1f86Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
44676df26cacSmrg    *)
4468b68e1f86Smrg      for file in $files; do
4469b68e1f86Smrg	case $file in
4470b68e1f86Smrg	*.lo) ;;
4471b68e1f86Smrg	*)
447225dbecb6Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4473b68e1f86Smrg	  ;;
4474b68e1f86Smrg	esac
4475b68e1f86Smrg      done
44766df26cacSmrg      ;;
44776df26cacSmrg    esac
44786df26cacSmrg
4479b68e1f86Smrg    # This variable tells wrapper scripts just to set variables rather
4480b68e1f86Smrg    # than running their programs.
448125dbecb6Smrg    libtool_install_magic=$magic
44826df26cacSmrg
4483b68e1f86Smrg    staticlibs=
4484b68e1f86Smrg    future_libdirs=
4485b68e1f86Smrg    current_libdirs=
4486b68e1f86Smrg    for file in $files; do
44876df26cacSmrg
4488b68e1f86Smrg      # Do each installation.
4489b68e1f86Smrg      case $file in
4490b68e1f86Smrg      *.$libext)
4491b68e1f86Smrg	# Do the static libraries later.
44923bfa90b6Smrg	func_append staticlibs " $file"
4493b68e1f86Smrg	;;
4494b68e1f86Smrg
4495b68e1f86Smrg      *.la)
44963bfa90b6Smrg	func_resolve_sysroot "$file"
44973bfa90b6Smrg	file=$func_resolve_sysroot_result
44983bfa90b6Smrg
4499b68e1f86Smrg	# Check to see that this really is a libtool archive.
4500b68e1f86Smrg	func_lalib_unsafe_p "$file" \
450125dbecb6Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4502b68e1f86Smrg
4503b68e1f86Smrg	library_names=
4504b68e1f86Smrg	old_library=
4505b68e1f86Smrg	relink_command=
4506b68e1f86Smrg	func_source "$file"
4507b68e1f86Smrg
4508b68e1f86Smrg	# Add the libdir to current_libdirs if it is the destination.
4509b68e1f86Smrg	if test "X$destdir" = "X$libdir"; then
4510b68e1f86Smrg	  case "$current_libdirs " in
4511b68e1f86Smrg	  *" $libdir "*) ;;
45123bfa90b6Smrg	  *) func_append current_libdirs " $libdir" ;;
45136df26cacSmrg	  esac
4514b68e1f86Smrg	else
4515b68e1f86Smrg	  # Note the libdir as a future libdir.
4516b68e1f86Smrg	  case "$future_libdirs " in
4517b68e1f86Smrg	  *" $libdir "*) ;;
45183bfa90b6Smrg	  *) func_append future_libdirs " $libdir" ;;
4519b68e1f86Smrg	  esac
4520b68e1f86Smrg	fi
45216df26cacSmrg
4522b68e1f86Smrg	func_dirname "$file" "/" ""
452325dbecb6Smrg	dir=$func_dirname_result
45243bfa90b6Smrg	func_append dir "$objdir"
4525b68e1f86Smrg
4526b68e1f86Smrg	if test -n "$relink_command"; then
4527b68e1f86Smrg	  # Determine the prefix the user has applied to our future dir.
45283bfa90b6Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4529b68e1f86Smrg
4530b68e1f86Smrg	  # Don't allow the user to place us outside of our expected
4531b68e1f86Smrg	  # location b/c this prevents finding dependent libraries that
4532b68e1f86Smrg	  # are installed to the same prefix.
4533b68e1f86Smrg	  # At present, this check doesn't affect windows .dll's that
4534b68e1f86Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4535b68e1f86Smrg	  # but it's something to keep an eye on.
4536b68e1f86Smrg	  test "$inst_prefix_dir" = "$destdir" && \
453725dbecb6Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4538b68e1f86Smrg
4539b68e1f86Smrg	  if test -n "$inst_prefix_dir"; then
4540b68e1f86Smrg	    # Stick the inst_prefix_dir data into the link command.
45413bfa90b6Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4542b68e1f86Smrg	  else
45433bfa90b6Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4544b68e1f86Smrg	  fi
4545b68e1f86Smrg
454625dbecb6Smrg	  func_warning "relinking '$file'"
4547b68e1f86Smrg	  func_show_eval "$relink_command" \
454825dbecb6Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4549b68e1f86Smrg	fi
4550b68e1f86Smrg
4551b68e1f86Smrg	# See the names of the shared library.
4552b68e1f86Smrg	set dummy $library_names; shift
4553b68e1f86Smrg	if test -n "$1"; then
455425dbecb6Smrg	  realname=$1
4555b68e1f86Smrg	  shift
4556b68e1f86Smrg
455725dbecb6Smrg	  srcname=$realname
455825dbecb6Smrg	  test -n "$relink_command" && srcname=${realname}T
4559b68e1f86Smrg
4560b68e1f86Smrg	  # Install the shared library and build the symlinks.
45613bfa90b6Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4562b68e1f86Smrg	      'exit $?'
456325dbecb6Smrg	  tstripme=$stripme
4564b68e1f86Smrg	  case $host_os in
4565b68e1f86Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4566b68e1f86Smrg	    case $realname in
4567b68e1f86Smrg	    *.dll.a)
456825dbecb6Smrg	      tstripme=
456925dbecb6Smrg	      ;;
457025dbecb6Smrg	    esac
457125dbecb6Smrg	    ;;
457225dbecb6Smrg	  os2*)
457325dbecb6Smrg	    case $realname in
457425dbecb6Smrg	    *_dll.a)
457525dbecb6Smrg	      tstripme=
4576b68e1f86Smrg	      ;;
4577b68e1f86Smrg	    esac
45786df26cacSmrg	    ;;
45796df26cacSmrg	  esac
4580b68e1f86Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4581b68e1f86Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
45826df26cacSmrg	  fi
4583b68e1f86Smrg
4584b68e1f86Smrg	  if test "$#" -gt 0; then
4585b68e1f86Smrg	    # Delete the old symlinks, and create new ones.
458625dbecb6Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4587b68e1f86Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4588b68e1f86Smrg	    # so we also need to try rm && ln -s.
4589b68e1f86Smrg	    for linkname
4590b68e1f86Smrg	    do
4591b68e1f86Smrg	      test "$linkname" != "$realname" \
4592b68e1f86Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
45936df26cacSmrg	    done
45946df26cacSmrg	  fi
45956df26cacSmrg
4596b68e1f86Smrg	  # Do each command in the postinstall commands.
459725dbecb6Smrg	  lib=$destdir/$realname
4598b68e1f86Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
45996df26cacSmrg	fi
46006df26cacSmrg
4601b68e1f86Smrg	# Install the pseudo-library for information purposes.
4602b68e1f86Smrg	func_basename "$file"
460325dbecb6Smrg	name=$func_basename_result
460425dbecb6Smrg	instname=$dir/${name}i
4605b68e1f86Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
46066df26cacSmrg
4607b68e1f86Smrg	# Maybe install the static library, too.
46083bfa90b6Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4609b68e1f86Smrg	;;
46106df26cacSmrg
4611b68e1f86Smrg      *.lo)
4612b68e1f86Smrg	# Install (i.e. copy) a libtool object.
46136df26cacSmrg
4614b68e1f86Smrg	# Figure out destination file name, if it wasn't already specified.
4615b68e1f86Smrg	if test -n "$destname"; then
461625dbecb6Smrg	  destfile=$destdir/$destname
4617b68e1f86Smrg	else
4618b68e1f86Smrg	  func_basename "$file"
461925dbecb6Smrg	  destfile=$func_basename_result
462025dbecb6Smrg	  destfile=$destdir/$destfile
46216df26cacSmrg	fi
46226df26cacSmrg
4623b68e1f86Smrg	# Deduce the name of the destination old-style object file.
4624b68e1f86Smrg	case $destfile in
4625b68e1f86Smrg	*.lo)
4626b68e1f86Smrg	  func_lo2o "$destfile"
4627b68e1f86Smrg	  staticdest=$func_lo2o_result
4628b68e1f86Smrg	  ;;
4629b68e1f86Smrg	*.$objext)
463025dbecb6Smrg	  staticdest=$destfile
4631b68e1f86Smrg	  destfile=
4632b68e1f86Smrg	  ;;
4633b68e1f86Smrg	*)
463425dbecb6Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4635b68e1f86Smrg	  ;;
4636b68e1f86Smrg	esac
46376df26cacSmrg
4638b68e1f86Smrg	# Install the libtool object if requested.
4639b68e1f86Smrg	test -n "$destfile" && \
4640b68e1f86Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46416df26cacSmrg
4642b68e1f86Smrg	# Install the old object if enabled.
464325dbecb6Smrg	if test yes = "$build_old_libs"; then
4644b68e1f86Smrg	  # Deduce the name of the old-style object file.
4645b68e1f86Smrg	  func_lo2o "$file"
4646b68e1f86Smrg	  staticobj=$func_lo2o_result
4647b68e1f86Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
46486df26cacSmrg	fi
4649b68e1f86Smrg	exit $EXIT_SUCCESS
4650b68e1f86Smrg	;;
46516df26cacSmrg
4652b68e1f86Smrg      *)
4653b68e1f86Smrg	# Figure out destination file name, if it wasn't already specified.
4654b68e1f86Smrg	if test -n "$destname"; then
465525dbecb6Smrg	  destfile=$destdir/$destname
4656b68e1f86Smrg	else
4657b68e1f86Smrg	  func_basename "$file"
465825dbecb6Smrg	  destfile=$func_basename_result
465925dbecb6Smrg	  destfile=$destdir/$destfile
4660b68e1f86Smrg	fi
46616df26cacSmrg
4662b68e1f86Smrg	# If the file is missing, and there is a .exe on the end, strip it
4663b68e1f86Smrg	# because it is most likely a libtool script we actually want to
4664b68e1f86Smrg	# install
466525dbecb6Smrg	stripped_ext=
4666b68e1f86Smrg	case $file in
4667b68e1f86Smrg	  *.exe)
4668b68e1f86Smrg	    if test ! -f "$file"; then
4669b68e1f86Smrg	      func_stripname '' '.exe' "$file"
4670b68e1f86Smrg	      file=$func_stripname_result
467125dbecb6Smrg	      stripped_ext=.exe
4672b68e1f86Smrg	    fi
4673b68e1f86Smrg	    ;;
4674b68e1f86Smrg	esac
4675b68e1f86Smrg
4676b68e1f86Smrg	# Do a test to see if this is really a libtool program.
4677b68e1f86Smrg	case $host in
4678b68e1f86Smrg	*cygwin* | *mingw*)
4679b68e1f86Smrg	    if func_ltwrapper_executable_p "$file"; then
4680b68e1f86Smrg	      func_ltwrapper_scriptname "$file"
4681b68e1f86Smrg	      wrapper=$func_ltwrapper_scriptname_result
4682b68e1f86Smrg	    else
4683b68e1f86Smrg	      func_stripname '' '.exe' "$file"
4684b68e1f86Smrg	      wrapper=$func_stripname_result
4685b68e1f86Smrg	    fi
4686b68e1f86Smrg	    ;;
46876df26cacSmrg	*)
4688b68e1f86Smrg	    wrapper=$file
4689b68e1f86Smrg	    ;;
4690b68e1f86Smrg	esac
4691b68e1f86Smrg	if func_ltwrapper_script_p "$wrapper"; then
4692b68e1f86Smrg	  notinst_deplibs=
4693b68e1f86Smrg	  relink_command=
4694b68e1f86Smrg
4695b68e1f86Smrg	  func_source "$wrapper"
4696b68e1f86Smrg
4697b68e1f86Smrg	  # Check the variables that should have been set.
4698b68e1f86Smrg	  test -z "$generated_by_libtool_version" && \
469925dbecb6Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4700b68e1f86Smrg
470125dbecb6Smrg	  finalize=:
4702b68e1f86Smrg	  for lib in $notinst_deplibs; do
4703b68e1f86Smrg	    # Check to see that each library is installed.
4704b68e1f86Smrg	    libdir=
4705b68e1f86Smrg	    if test -f "$lib"; then
4706b68e1f86Smrg	      func_source "$lib"
4707b68e1f86Smrg	    fi
470825dbecb6Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4709b68e1f86Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
471025dbecb6Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
471125dbecb6Smrg	      finalize=false
4712b68e1f86Smrg	    fi
4713b68e1f86Smrg	  done
4714b68e1f86Smrg
4715b68e1f86Smrg	  relink_command=
4716b68e1f86Smrg	  func_source "$wrapper"
4717b68e1f86Smrg
4718b68e1f86Smrg	  outputname=
471925dbecb6Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4720b68e1f86Smrg	    $opt_dry_run || {
472125dbecb6Smrg	      if $finalize; then
4722b68e1f86Smrg	        tmpdir=`func_mktempdir`
4723b68e1f86Smrg		func_basename "$file$stripped_ext"
472425dbecb6Smrg		file=$func_basename_result
472525dbecb6Smrg	        outputname=$tmpdir/$file
4726b68e1f86Smrg	        # Replace the output file specification.
47273bfa90b6Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4728b68e1f86Smrg
472925dbecb6Smrg	        $opt_quiet || {
473025dbecb6Smrg	          func_quote_arg expand,pretty "$relink_command"
473125dbecb6Smrg		  eval "func_echo $func_quote_arg_result"
4732b68e1f86Smrg	        }
4733b68e1f86Smrg	        if eval "$relink_command"; then :
4734b68e1f86Smrg	          else
473525dbecb6Smrg		  func_error "error: relink '$file' with the above command before installing it"
4736b68e1f86Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4737b68e1f86Smrg		  continue
4738b68e1f86Smrg	        fi
473925dbecb6Smrg	        file=$outputname
4740b68e1f86Smrg	      else
474125dbecb6Smrg	        func_warning "cannot relink '$file'"
4742b68e1f86Smrg	      fi
4743b68e1f86Smrg	    }
4744b68e1f86Smrg	  else
4745b68e1f86Smrg	    # Install the binary that we compiled earlier.
47463bfa90b6Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
47476df26cacSmrg	  fi
4748b68e1f86Smrg	fi
4749b68e1f86Smrg
4750b68e1f86Smrg	# remove .exe since cygwin /usr/bin/install will append another
4751b68e1f86Smrg	# one anyway
4752b68e1f86Smrg	case $install_prog,$host in
4753b68e1f86Smrg	*/usr/bin/install*,*cygwin*)
4754b68e1f86Smrg	  case $file:$destfile in
4755b68e1f86Smrg	  *.exe:*.exe)
4756b68e1f86Smrg	    # this is ok
4757b68e1f86Smrg	    ;;
4758b68e1f86Smrg	  *.exe:*)
4759b68e1f86Smrg	    destfile=$destfile.exe
4760b68e1f86Smrg	    ;;
4761b68e1f86Smrg	  *:*.exe)
4762b68e1f86Smrg	    func_stripname '' '.exe' "$destfile"
4763b68e1f86Smrg	    destfile=$func_stripname_result
4764b68e1f86Smrg	    ;;
4765b68e1f86Smrg	  esac
47666df26cacSmrg	  ;;
47676df26cacSmrg	esac
4768b68e1f86Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4769b68e1f86Smrg	$opt_dry_run || if test -n "$outputname"; then
4770b68e1f86Smrg	  ${RM}r "$tmpdir"
4771b68e1f86Smrg	fi
4772b68e1f86Smrg	;;
4773b68e1f86Smrg      esac
4774b68e1f86Smrg    done
47756df26cacSmrg
4776b68e1f86Smrg    for file in $staticlibs; do
4777b68e1f86Smrg      func_basename "$file"
477825dbecb6Smrg      name=$func_basename_result
4779b68e1f86Smrg
4780b68e1f86Smrg      # Set up the ranlib parameters.
478125dbecb6Smrg      oldlib=$destdir/$name
47823bfa90b6Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
47833bfa90b6Smrg      tool_oldlib=$func_to_tool_file_result
4784b68e1f86Smrg
4785b68e1f86Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4786b68e1f86Smrg
4787b68e1f86Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
47883bfa90b6Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4789b68e1f86Smrg      fi
4790b68e1f86Smrg
4791b68e1f86Smrg      # Do each command in the postinstall commands.
4792b68e1f86Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4793b68e1f86Smrg    done
4794b68e1f86Smrg
4795b68e1f86Smrg    test -n "$future_libdirs" && \
479625dbecb6Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4797b68e1f86Smrg
4798b68e1f86Smrg    if test -n "$current_libdirs"; then
4799b68e1f86Smrg      # Maybe just do a dry run.
4800b68e1f86Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
480125dbecb6Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4802b68e1f86Smrg    else
4803b68e1f86Smrg      exit $EXIT_SUCCESS
4804b68e1f86Smrg    fi
4805b68e1f86Smrg}
4806b68e1f86Smrg
480725dbecb6Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4808b68e1f86Smrg
4809b68e1f86Smrg
4810b68e1f86Smrg# func_generate_dlsyms outputname originator pic_p
4811b68e1f86Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4812b68e1f86Smrg# a dlpreopen symbol table.
4813b68e1f86Smrgfunc_generate_dlsyms ()
4814b68e1f86Smrg{
481525dbecb6Smrg    $debug_cmd
481625dbecb6Smrg
481725dbecb6Smrg    my_outputname=$1
481825dbecb6Smrg    my_originator=$2
481925dbecb6Smrg    my_pic_p=${3-false}
482025dbecb6Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4821b68e1f86Smrg    my_dlsyms=
4822b68e1f86Smrg
482325dbecb6Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4824b68e1f86Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
482525dbecb6Smrg	my_dlsyms=${my_outputname}S.c
4826b68e1f86Smrg      else
4827b68e1f86Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4828b68e1f86Smrg      fi
4829b68e1f86Smrg    fi
4830b68e1f86Smrg
4831b68e1f86Smrg    if test -n "$my_dlsyms"; then
4832b68e1f86Smrg      case $my_dlsyms in
4833b68e1f86Smrg      "") ;;
4834b68e1f86Smrg      *.c)
4835b68e1f86Smrg	# Discover the nlist of each of the dlfiles.
483625dbecb6Smrg	nlist=$output_objdir/$my_outputname.nm
4837b68e1f86Smrg
4838b68e1f86Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4839b68e1f86Smrg
4840b68e1f86Smrg	# Parse the name list into a source file.
4841b68e1f86Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4842b68e1f86Smrg
4843b68e1f86Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
484425dbecb6Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
484525dbecb6Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4846b68e1f86Smrg
4847b68e1f86Smrg#ifdef __cplusplus
4848b68e1f86Smrgextern \"C\" {
4849b68e1f86Smrg#endif
4850b68e1f86Smrg
485125dbecb6Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
48523bfa90b6Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
48533bfa90b6Smrg#endif
48543bfa90b6Smrg
48553bfa90b6Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
485625dbecb6Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
485725dbecb6Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
48583bfa90b6Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
48593bfa90b6Smrg# define LT_DLSYM_CONST
486025dbecb6Smrg#elif defined __osf__
48613bfa90b6Smrg/* This system does not cope well with relocations in const data.  */
48623bfa90b6Smrg# define LT_DLSYM_CONST
48633bfa90b6Smrg#else
48643bfa90b6Smrg# define LT_DLSYM_CONST const
48653bfa90b6Smrg#endif
48663bfa90b6Smrg
486725dbecb6Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
486825dbecb6Smrg
4869b68e1f86Smrg/* External symbol declarations for the compiler. */\
4870b68e1f86Smrg"
4871b68e1f86Smrg
487225dbecb6Smrg	if test yes = "$dlself"; then
487325dbecb6Smrg	  func_verbose "generating symbol list for '$output'"
4874b68e1f86Smrg
4875b68e1f86Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4876b68e1f86Smrg
4877b68e1f86Smrg	  # Add our own program objects to the symbol list.
48783bfa90b6Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4879b68e1f86Smrg	  for progfile in $progfiles; do
48803bfa90b6Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
488125dbecb6Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
48823bfa90b6Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4883b68e1f86Smrg	  done
4884b68e1f86Smrg
4885b68e1f86Smrg	  if test -n "$exclude_expsyms"; then
4886b68e1f86Smrg	    $opt_dry_run || {
4887b68e1f86Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4888b68e1f86Smrg	      eval '$MV "$nlist"T "$nlist"'
4889b68e1f86Smrg	    }
48906df26cacSmrg	  fi
4891b68e1f86Smrg
4892b68e1f86Smrg	  if test -n "$export_symbols_regex"; then
4893b68e1f86Smrg	    $opt_dry_run || {
4894b68e1f86Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4895b68e1f86Smrg	      eval '$MV "$nlist"T "$nlist"'
4896b68e1f86Smrg	    }
4897b68e1f86Smrg	  fi
4898b68e1f86Smrg
4899b68e1f86Smrg	  # Prepare the list of exported symbols
4900b68e1f86Smrg	  if test -z "$export_symbols"; then
490125dbecb6Smrg	    export_symbols=$output_objdir/$outputname.exp
4902b68e1f86Smrg	    $opt_dry_run || {
4903b68e1f86Smrg	      $RM $export_symbols
490425dbecb6Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4905b68e1f86Smrg	      case $host in
4906b68e1f86Smrg	      *cygwin* | *mingw* | *cegcc* )
4907b68e1f86Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4908b68e1f86Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4909b68e1f86Smrg	        ;;
4910b68e1f86Smrg	      esac
4911b68e1f86Smrg	    }
49126df26cacSmrg	  else
4913b68e1f86Smrg	    $opt_dry_run || {
491425dbecb6Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4915b68e1f86Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4916b68e1f86Smrg	      eval '$MV "$nlist"T "$nlist"'
4917b68e1f86Smrg	      case $host in
49183bfa90b6Smrg	        *cygwin* | *mingw* | *cegcc* )
4919b68e1f86Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4920b68e1f86Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4921b68e1f86Smrg	          ;;
4922b68e1f86Smrg	      esac
4923b68e1f86Smrg	    }
49246df26cacSmrg	  fi
4925b68e1f86Smrg	fi
49266df26cacSmrg
4927b68e1f86Smrg	for dlprefile in $dlprefiles; do
492825dbecb6Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4929b68e1f86Smrg	  func_basename "$dlprefile"
493025dbecb6Smrg	  name=$func_basename_result
49313bfa90b6Smrg          case $host in
49323bfa90b6Smrg	    *cygwin* | *mingw* | *cegcc* )
49333bfa90b6Smrg	      # if an import library, we need to obtain dlname
49343bfa90b6Smrg	      if func_win32_import_lib_p "$dlprefile"; then
49353bfa90b6Smrg	        func_tr_sh "$dlprefile"
49363bfa90b6Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
493725dbecb6Smrg	        dlprefile_dlbasename=
49383bfa90b6Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
49393bfa90b6Smrg	          # Use subshell, to avoid clobbering current variable values
49403bfa90b6Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
494125dbecb6Smrg	          if test -n "$dlprefile_dlname"; then
49423bfa90b6Smrg	            func_basename "$dlprefile_dlname"
494325dbecb6Smrg	            dlprefile_dlbasename=$func_basename_result
49443bfa90b6Smrg	          else
49453bfa90b6Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
49463bfa90b6Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
49473bfa90b6Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
49483bfa90b6Smrg	          fi
49493bfa90b6Smrg	        fi
49503bfa90b6Smrg	        $opt_dry_run || {
495125dbecb6Smrg	          if test -n "$dlprefile_dlbasename"; then
49523bfa90b6Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
49533bfa90b6Smrg	          else
49543bfa90b6Smrg	            func_warning "Could not compute DLL name from $name"
49553bfa90b6Smrg	            eval '$ECHO ": $name " >> "$nlist"'
49563bfa90b6Smrg	          fi
49573bfa90b6Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49583bfa90b6Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
49593bfa90b6Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
49603bfa90b6Smrg	        }
49613bfa90b6Smrg	      else # not an import lib
49623bfa90b6Smrg	        $opt_dry_run || {
49633bfa90b6Smrg	          eval '$ECHO ": $name " >> "$nlist"'
49643bfa90b6Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49653bfa90b6Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49663bfa90b6Smrg	        }
49673bfa90b6Smrg	      fi
49683bfa90b6Smrg	    ;;
49693bfa90b6Smrg	    *)
49703bfa90b6Smrg	      $opt_dry_run || {
49713bfa90b6Smrg	        eval '$ECHO ": $name " >> "$nlist"'
49723bfa90b6Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49733bfa90b6Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49743bfa90b6Smrg	      }
49753bfa90b6Smrg	    ;;
49763bfa90b6Smrg          esac
4977b68e1f86Smrg	done
4978b68e1f86Smrg
4979b68e1f86Smrg	$opt_dry_run || {
4980b68e1f86Smrg	  # Make sure we have at least an empty file.
4981b68e1f86Smrg	  test -f "$nlist" || : > "$nlist"
4982b68e1f86Smrg
4983b68e1f86Smrg	  if test -n "$exclude_expsyms"; then
4984b68e1f86Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4985b68e1f86Smrg	    $MV "$nlist"T "$nlist"
49866df26cacSmrg	  fi
4987b68e1f86Smrg
4988b68e1f86Smrg	  # Try sorting and uniquifying the output.
4989b68e1f86Smrg	  if $GREP -v "^: " < "$nlist" |
4990b68e1f86Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4991b68e1f86Smrg		sort -k 3
4992b68e1f86Smrg	      else
4993b68e1f86Smrg		sort +2
4994b68e1f86Smrg	      fi |
4995b68e1f86Smrg	      uniq > "$nlist"S; then
4996b68e1f86Smrg	    :
49976df26cacSmrg	  else
4998b68e1f86Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
49996df26cacSmrg	  fi
50006df26cacSmrg
5001b68e1f86Smrg	  if test -f "$nlist"S; then
5002b68e1f86Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
50036df26cacSmrg	  else
50043bfa90b6Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
50056df26cacSmrg	  fi
50066df26cacSmrg
500725dbecb6Smrg	  func_show_eval '$RM "${nlist}I"'
500825dbecb6Smrg	  if test -n "$global_symbol_to_import"; then
500925dbecb6Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
501025dbecb6Smrg	  fi
501125dbecb6Smrg
50123bfa90b6Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50136df26cacSmrg
5014b68e1f86Smrg/* The mapping between symbol names and symbols.  */
5015b68e1f86Smrgtypedef struct {
5016b68e1f86Smrg  const char *name;
5017b68e1f86Smrg  void *address;
5018b68e1f86Smrg} lt_dlsymlist;
50193bfa90b6Smrgextern LT_DLSYM_CONST lt_dlsymlist
502025dbecb6Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
502125dbecb6Smrg"
502225dbecb6Smrg
502325dbecb6Smrg	  if test -s "$nlist"I; then
502425dbecb6Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
502525dbecb6Smrgstatic void lt_syminit(void)
502625dbecb6Smrg{
502725dbecb6Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
502825dbecb6Smrg  for (; symbol->name; ++symbol)
502925dbecb6Smrg    {"
503025dbecb6Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
503125dbecb6Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
503225dbecb6Smrg    }
503325dbecb6Smrg}"
503425dbecb6Smrg	  fi
503525dbecb6Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50363bfa90b6SmrgLT_DLSYM_CONST lt_dlsymlist
5037b68e1f86Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
503825dbecb6Smrg{ {\"$my_originator\", (void *) 0},"
503925dbecb6Smrg
504025dbecb6Smrg	  if test -s "$nlist"I; then
504125dbecb6Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
504225dbecb6Smrg  {\"@INIT@\", (void *) &lt_syminit},"
504325dbecb6Smrg	  fi
50446df26cacSmrg
5045b68e1f86Smrg	  case $need_lib_prefix in
5046b68e1f86Smrg	  no)
5047b68e1f86Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5048b68e1f86Smrg	    ;;
5049b68e1f86Smrg	  *)
5050b68e1f86Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5051b68e1f86Smrg	    ;;
5052b68e1f86Smrg	  esac
50533bfa90b6Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5054b68e1f86Smrg  {0, (void *) 0}
5055b68e1f86Smrg};
50566df26cacSmrg
5057b68e1f86Smrg/* This works around a problem in FreeBSD linker */
5058b68e1f86Smrg#ifdef FREEBSD_WORKAROUND
5059b68e1f86Smrgstatic const void *lt_preloaded_setup() {
5060b68e1f86Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5061b68e1f86Smrg}
5062b68e1f86Smrg#endif
50636df26cacSmrg
5064b68e1f86Smrg#ifdef __cplusplus
5065b68e1f86Smrg}
5066b68e1f86Smrg#endif\
5067b68e1f86Smrg"
5068b68e1f86Smrg	} # !$opt_dry_run
50696df26cacSmrg
5070b68e1f86Smrg	pic_flag_for_symtable=
5071b68e1f86Smrg	case "$compile_command " in
5072b68e1f86Smrg	*" -static "*) ;;
5073b68e1f86Smrg	*)
5074b68e1f86Smrg	  case $host in
5075b68e1f86Smrg	  # compiling the symbol table file with pic_flag works around
5076b68e1f86Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5077b68e1f86Smrg	  # linked before any other PIC object.  But we must not use
5078b68e1f86Smrg	  # pic_flag when linking with -static.  The problem exists in
5079b68e1f86Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
50803bfa90b6Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5081b68e1f86Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5082b68e1f86Smrg	  *-*-hpux*)
5083b68e1f86Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5084b68e1f86Smrg	  *)
508525dbecb6Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5086b68e1f86Smrg	    ;;
5087b68e1f86Smrg	  esac
5088b68e1f86Smrg	  ;;
5089b68e1f86Smrg	esac
5090b68e1f86Smrg	symtab_cflags=
5091b68e1f86Smrg	for arg in $LTCFLAGS; do
5092b68e1f86Smrg	  case $arg in
5093b68e1f86Smrg	  -pie | -fpie | -fPIE) ;;
50943bfa90b6Smrg	  *) func_append symtab_cflags " $arg" ;;
5095b68e1f86Smrg	  esac
5096b68e1f86Smrg	done
50976df26cacSmrg
5098b68e1f86Smrg	# Now compile the dynamic symbol file.
5099b68e1f86Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51006df26cacSmrg
5101b68e1f86Smrg	# Clean up the generated files.
510225dbecb6Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
51036df26cacSmrg
5104b68e1f86Smrg	# Transform the symbol file into the correct name.
510525dbecb6Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5106b68e1f86Smrg	case $host in
5107b68e1f86Smrg	*cygwin* | *mingw* | *cegcc* )
5108b68e1f86Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
51093bfa90b6Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51103bfa90b6Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5111b68e1f86Smrg	  else
51123bfa90b6Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51133bfa90b6Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5114b68e1f86Smrg	  fi
5115b68e1f86Smrg	  ;;
5116b68e1f86Smrg	*)
51173bfa90b6Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51183bfa90b6Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5119b68e1f86Smrg	  ;;
5120b68e1f86Smrg	esac
5121b68e1f86Smrg	;;
5122b68e1f86Smrg      *)
512325dbecb6Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5124b68e1f86Smrg	;;
5125b68e1f86Smrg      esac
5126b68e1f86Smrg    else
5127b68e1f86Smrg      # We keep going just in case the user didn't refer to
5128b68e1f86Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5129b68e1f86Smrg      # really was required.
51306df26cacSmrg
5131b68e1f86Smrg      # Nullify the symbol file.
51323bfa90b6Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
51333bfa90b6Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5134b68e1f86Smrg    fi
5135b68e1f86Smrg}
51366df26cacSmrg
513725dbecb6Smrg# func_cygming_gnu_implib_p ARG
513825dbecb6Smrg# This predicate returns with zero status (TRUE) if
513925dbecb6Smrg# ARG is a GNU/binutils-style import library. Returns
514025dbecb6Smrg# with nonzero status (FALSE) otherwise.
514125dbecb6Smrgfunc_cygming_gnu_implib_p ()
514225dbecb6Smrg{
514325dbecb6Smrg  $debug_cmd
514425dbecb6Smrg
514525dbecb6Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
514625dbecb6Smrg  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)$'`
514725dbecb6Smrg  test -n "$func_cygming_gnu_implib_tmp"
514825dbecb6Smrg}
514925dbecb6Smrg
515025dbecb6Smrg# func_cygming_ms_implib_p ARG
515125dbecb6Smrg# This predicate returns with zero status (TRUE) if
515225dbecb6Smrg# ARG is an MS-style import library. Returns
515325dbecb6Smrg# with nonzero status (FALSE) otherwise.
515425dbecb6Smrgfunc_cygming_ms_implib_p ()
515525dbecb6Smrg{
515625dbecb6Smrg  $debug_cmd
515725dbecb6Smrg
515825dbecb6Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
515925dbecb6Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
516025dbecb6Smrg  test -n "$func_cygming_ms_implib_tmp"
516125dbecb6Smrg}
516225dbecb6Smrg
5163b68e1f86Smrg# func_win32_libid arg
5164b68e1f86Smrg# return the library type of file 'arg'
5165b68e1f86Smrg#
5166b68e1f86Smrg# Need a lot of goo to handle *both* DLLs and import libs
5167b68e1f86Smrg# Has to be a shell function in order to 'eat' the argument
5168b68e1f86Smrg# that is supplied when $file_magic_command is called.
51693bfa90b6Smrg# Despite the name, also deal with 64 bit binaries.
5170b68e1f86Smrgfunc_win32_libid ()
5171b68e1f86Smrg{
517225dbecb6Smrg  $debug_cmd
517325dbecb6Smrg
517425dbecb6Smrg  win32_libid_type=unknown
5175b68e1f86Smrg  win32_fileres=`file -L $1 2>/dev/null`
5176b68e1f86Smrg  case $win32_fileres in
5177b68e1f86Smrg  *ar\ archive\ import\ library*) # definitely import
5178b68e1f86Smrg    win32_libid_type="x86 archive import"
5179b68e1f86Smrg    ;;
5180b68e1f86Smrg  *ar\ archive*) # could be an import, or static
51813bfa90b6Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5182b68e1f86Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
51833bfa90b6Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
518425dbecb6Smrg      case $nm_interface in
518525dbecb6Smrg      "MS dumpbin")
518625dbecb6Smrg	if func_cygming_ms_implib_p "$1" ||
518725dbecb6Smrg	   func_cygming_gnu_implib_p "$1"
518825dbecb6Smrg	then
518925dbecb6Smrg	  win32_nmres=import
519025dbecb6Smrg	else
519125dbecb6Smrg	  win32_nmres=
519225dbecb6Smrg	fi
519325dbecb6Smrg	;;
519425dbecb6Smrg      *)
519525dbecb6Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
519625dbecb6Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
519725dbecb6Smrg	  $SED -n -e '
5198b68e1f86Smrg	    1,100{
5199b68e1f86Smrg		/ I /{
520025dbecb6Smrg		    s|.*|import|
5201b68e1f86Smrg		    p
5202b68e1f86Smrg		    q
5203b68e1f86Smrg		}
5204b68e1f86Smrg	    }'`
520525dbecb6Smrg	;;
520625dbecb6Smrg      esac
5207b68e1f86Smrg      case $win32_nmres in
5208b68e1f86Smrg      import*)  win32_libid_type="x86 archive import";;
5209b68e1f86Smrg      *)        win32_libid_type="x86 archive static";;
5210b68e1f86Smrg      esac
5211b68e1f86Smrg    fi
5212b68e1f86Smrg    ;;
5213b68e1f86Smrg  *DLL*)
5214b68e1f86Smrg    win32_libid_type="x86 DLL"
5215b68e1f86Smrg    ;;
5216b68e1f86Smrg  *executable*) # but shell scripts are "executable" too...
5217b68e1f86Smrg    case $win32_fileres in
5218b68e1f86Smrg    *MS\ Windows\ PE\ Intel*)
5219b68e1f86Smrg      win32_libid_type="x86 DLL"
5220b68e1f86Smrg      ;;
5221b68e1f86Smrg    esac
5222b68e1f86Smrg    ;;
5223b68e1f86Smrg  esac
5224b68e1f86Smrg  $ECHO "$win32_libid_type"
5225b68e1f86Smrg}
52266df26cacSmrg
52273bfa90b6Smrg# func_cygming_dll_for_implib ARG
52283bfa90b6Smrg#
52293bfa90b6Smrg# Platform-specific function to extract the
52303bfa90b6Smrg# name of the DLL associated with the specified
52313bfa90b6Smrg# import library ARG.
52323bfa90b6Smrg# Invoked by eval'ing the libtool variable
52333bfa90b6Smrg#    $sharedlib_from_linklib_cmd
52343bfa90b6Smrg# Result is available in the variable
52353bfa90b6Smrg#    $sharedlib_from_linklib_result
52363bfa90b6Smrgfunc_cygming_dll_for_implib ()
52373bfa90b6Smrg{
523825dbecb6Smrg  $debug_cmd
523925dbecb6Smrg
52403bfa90b6Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
52413bfa90b6Smrg}
52423bfa90b6Smrg
52433bfa90b6Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
52443bfa90b6Smrg#
52453bfa90b6Smrg# The is the core of a fallback implementation of a
52463bfa90b6Smrg# platform-specific function to extract the name of the
52473bfa90b6Smrg# DLL associated with the specified import library LIBNAME.
52483bfa90b6Smrg#
52493bfa90b6Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
52503bfa90b6Smrg# on the platform and compiler that created the implib.
52513bfa90b6Smrg#
52523bfa90b6Smrg# Echos the name of the DLL associated with the
52533bfa90b6Smrg# specified import library.
52543bfa90b6Smrgfunc_cygming_dll_for_implib_fallback_core ()
52553bfa90b6Smrg{
525625dbecb6Smrg  $debug_cmd
525725dbecb6Smrg
52583bfa90b6Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
52593bfa90b6Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
52603bfa90b6Smrg    $SED '/^Contents of section '"$match_literal"':/{
52613bfa90b6Smrg      # Place marker at beginning of archive member dllname section
52623bfa90b6Smrg      s/.*/====MARK====/
52633bfa90b6Smrg      p
52643bfa90b6Smrg      d
52653bfa90b6Smrg    }
52663bfa90b6Smrg    # These lines can sometimes be longer than 43 characters, but
52673bfa90b6Smrg    # are always uninteresting
52683bfa90b6Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
52693bfa90b6Smrg    /^In archive [^:]*:/d
52703bfa90b6Smrg    # Ensure marker is printed
52713bfa90b6Smrg    /^====MARK====/p
52723bfa90b6Smrg    # Remove all lines with less than 43 characters
52733bfa90b6Smrg    /^.\{43\}/!d
52743bfa90b6Smrg    # From remaining lines, remove first 43 characters
52753bfa90b6Smrg    s/^.\{43\}//' |
52763bfa90b6Smrg    $SED -n '
52773bfa90b6Smrg      # Join marker and all lines until next marker into a single line
52783bfa90b6Smrg      /^====MARK====/ b para
52793bfa90b6Smrg      H
52803bfa90b6Smrg      $ b para
52813bfa90b6Smrg      b
52823bfa90b6Smrg      :para
52833bfa90b6Smrg      x
52843bfa90b6Smrg      s/\n//g
52853bfa90b6Smrg      # Remove the marker
52863bfa90b6Smrg      s/^====MARK====//
52873bfa90b6Smrg      # Remove trailing dots and whitespace
52883bfa90b6Smrg      s/[\. \t]*$//
52893bfa90b6Smrg      # Print
52903bfa90b6Smrg      /./p' |
52913bfa90b6Smrg    # we now have a list, one entry per line, of the stringified
52923bfa90b6Smrg    # contents of the appropriate section of all members of the
529325dbecb6Smrg    # archive that possess that section. Heuristic: eliminate
529425dbecb6Smrg    # all those that have a first or second character that is
52953bfa90b6Smrg    # a '.' (that is, objdump's representation of an unprintable
52963bfa90b6Smrg    # character.) This should work for all archives with less than
52973bfa90b6Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
52983bfa90b6Smrg    # begins with a literal '.' or a single character followed by
52993bfa90b6Smrg    # a '.'.
53003bfa90b6Smrg    #
53013bfa90b6Smrg    # Of those that remain, print the first one.
53023bfa90b6Smrg    $SED -e '/^\./d;/^.\./d;q'
53033bfa90b6Smrg}
53043bfa90b6Smrg
53053bfa90b6Smrg# func_cygming_dll_for_implib_fallback ARG
53063bfa90b6Smrg# Platform-specific function to extract the
53073bfa90b6Smrg# name of the DLL associated with the specified
53083bfa90b6Smrg# import library ARG.
53093bfa90b6Smrg#
53103bfa90b6Smrg# This fallback implementation is for use when $DLLTOOL
53113bfa90b6Smrg# does not support the --identify-strict option.
53123bfa90b6Smrg# Invoked by eval'ing the libtool variable
53133bfa90b6Smrg#    $sharedlib_from_linklib_cmd
53143bfa90b6Smrg# Result is available in the variable
53153bfa90b6Smrg#    $sharedlib_from_linklib_result
53163bfa90b6Smrgfunc_cygming_dll_for_implib_fallback ()
53173bfa90b6Smrg{
531825dbecb6Smrg  $debug_cmd
531925dbecb6Smrg
532025dbecb6Smrg  if func_cygming_gnu_implib_p "$1"; then
53213bfa90b6Smrg    # binutils import library
53223bfa90b6Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
532325dbecb6Smrg  elif func_cygming_ms_implib_p "$1"; then
53243bfa90b6Smrg    # ms-generated import library
53253bfa90b6Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
53263bfa90b6Smrg  else
53273bfa90b6Smrg    # unknown
532825dbecb6Smrg    sharedlib_from_linklib_result=
53293bfa90b6Smrg  fi
53303bfa90b6Smrg}
53316df26cacSmrg
53326df26cacSmrg
5333b68e1f86Smrg# func_extract_an_archive dir oldlib
5334b68e1f86Smrgfunc_extract_an_archive ()
5335b68e1f86Smrg{
533625dbecb6Smrg    $debug_cmd
533725dbecb6Smrg
533825dbecb6Smrg    f_ex_an_ar_dir=$1; shift
533925dbecb6Smrg    f_ex_an_ar_oldlib=$1
534025dbecb6Smrg    if test yes = "$lock_old_archive_extraction"; then
53413bfa90b6Smrg      lockfile=$f_ex_an_ar_oldlib.lock
53423bfa90b6Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
53433bfa90b6Smrg	func_echo "Waiting for $lockfile to be removed"
53443bfa90b6Smrg	sleep 2
53453bfa90b6Smrg      done
53463bfa90b6Smrg    fi
53473bfa90b6Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
53483bfa90b6Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
534925dbecb6Smrg    if test yes = "$lock_old_archive_extraction"; then
53503bfa90b6Smrg      $opt_dry_run || rm -f "$lockfile"
53513bfa90b6Smrg    fi
5352b68e1f86Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5353b68e1f86Smrg     :
5354b68e1f86Smrg    else
5355b68e1f86Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5356b68e1f86Smrg    fi
5357b68e1f86Smrg}
53586df26cacSmrg
53596df26cacSmrg
5360b68e1f86Smrg# func_extract_archives gentop oldlib ...
5361b68e1f86Smrgfunc_extract_archives ()
5362b68e1f86Smrg{
536325dbecb6Smrg    $debug_cmd
536425dbecb6Smrg
536525dbecb6Smrg    my_gentop=$1; shift
5366b68e1f86Smrg    my_oldlibs=${1+"$@"}
536725dbecb6Smrg    my_oldobjs=
536825dbecb6Smrg    my_xlib=
536925dbecb6Smrg    my_xabs=
537025dbecb6Smrg    my_xdir=
53716df26cacSmrg
5372b68e1f86Smrg    for my_xlib in $my_oldlibs; do
5373b68e1f86Smrg      # Extract the objects.
5374b68e1f86Smrg      case $my_xlib in
537525dbecb6Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5376b68e1f86Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5377b68e1f86Smrg      esac
5378b68e1f86Smrg      func_basename "$my_xlib"
537925dbecb6Smrg      my_xlib=$func_basename_result
5380b68e1f86Smrg      my_xlib_u=$my_xlib
5381b68e1f86Smrg      while :; do
5382b68e1f86Smrg        case " $extracted_archives " in
5383b68e1f86Smrg	*" $my_xlib_u "*)
5384b68e1f86Smrg	  func_arith $extracted_serial + 1
5385b68e1f86Smrg	  extracted_serial=$func_arith_result
5386b68e1f86Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5387b68e1f86Smrg	*) break ;;
5388b68e1f86Smrg	esac
5389b68e1f86Smrg      done
5390b68e1f86Smrg      extracted_archives="$extracted_archives $my_xlib_u"
539125dbecb6Smrg      my_xdir=$my_gentop/$my_xlib_u
53926df26cacSmrg
5393b68e1f86Smrg      func_mkdir_p "$my_xdir"
5394b68e1f86Smrg
5395b68e1f86Smrg      case $host in
5396b68e1f86Smrg      *-darwin*)
5397b68e1f86Smrg	func_verbose "Extracting $my_xabs"
5398b68e1f86Smrg	# Do not bother doing anything if just a dry run
5399b68e1f86Smrg	$opt_dry_run || {
5400b68e1f86Smrg	  darwin_orig_dir=`pwd`
5401b68e1f86Smrg	  cd $my_xdir || exit $?
5402b68e1f86Smrg	  darwin_archive=$my_xabs
5403b68e1f86Smrg	  darwin_curdir=`pwd`
540425dbecb6Smrg	  func_basename "$darwin_archive"
540525dbecb6Smrg	  darwin_base_archive=$func_basename_result
5406b68e1f86Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5407b68e1f86Smrg	  if test -n "$darwin_arches"; then
5408b68e1f86Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5409b68e1f86Smrg	    darwin_arch=
5410b68e1f86Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
541125dbecb6Smrg	    for darwin_arch in  $darwin_arches; do
541225dbecb6Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
541325dbecb6Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
541425dbecb6Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
541525dbecb6Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5416b68e1f86Smrg	      cd "$darwin_curdir"
541725dbecb6Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5418b68e1f86Smrg	    done # $darwin_arches
5419b68e1f86Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
542025dbecb6Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5421b68e1f86Smrg	    darwin_file=
5422b68e1f86Smrg	    darwin_files=
5423b68e1f86Smrg	    for darwin_file in $darwin_filelist; do
54243bfa90b6Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5425b68e1f86Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5426b68e1f86Smrg	    done # $darwin_filelist
5427b68e1f86Smrg	    $RM -rf unfat-$$
5428b68e1f86Smrg	    cd "$darwin_orig_dir"
54296df26cacSmrg	  else
5430b68e1f86Smrg	    cd $darwin_orig_dir
5431b68e1f86Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5432b68e1f86Smrg	  fi # $darwin_arches
5433b68e1f86Smrg	} # !$opt_dry_run
5434b68e1f86Smrg	;;
5435b68e1f86Smrg      *)
5436b68e1f86Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5437b68e1f86Smrg	;;
5438b68e1f86Smrg      esac
54393bfa90b6Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5440b68e1f86Smrg    done
54416df26cacSmrg
544225dbecb6Smrg    func_extract_archives_result=$my_oldobjs
5443b68e1f86Smrg}
54446df26cacSmrg
54456df26cacSmrg
54463bfa90b6Smrg# func_emit_wrapper [arg=no]
54473bfa90b6Smrg#
54483bfa90b6Smrg# Emit a libtool wrapper script on stdout.
54493bfa90b6Smrg# Don't directly open a file because we may want to
54503bfa90b6Smrg# incorporate the script contents within a cygwin/mingw
54513bfa90b6Smrg# wrapper executable.  Must ONLY be called from within
54523bfa90b6Smrg# func_mode_link because it depends on a number of variables
54533bfa90b6Smrg# set therein.
5454b68e1f86Smrg#
54553bfa90b6Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
54563bfa90b6Smrg# variable will take.  If 'yes', then the emitted script
545725dbecb6Smrg# will assume that the directory where it is stored is
54583bfa90b6Smrg# the $objdir directory.  This is a cygwin/mingw-specific
54593bfa90b6Smrg# behavior.
54603bfa90b6Smrgfunc_emit_wrapper ()
5461b68e1f86Smrg{
54623bfa90b6Smrg	func_emit_wrapper_arg1=${1-no}
54636df26cacSmrg
5464b68e1f86Smrg	$ECHO "\
5465b68e1f86Smrg#! $SHELL
54666df26cacSmrg
5467b68e1f86Smrg# $output - temporary wrapper script for $objdir/$outputname
546825dbecb6Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5469b68e1f86Smrg#
5470b68e1f86Smrg# The $output program cannot be directly executed until all the libtool
5471b68e1f86Smrg# libraries that it depends on are installed.
5472b68e1f86Smrg#
5473b68e1f86Smrg# This wrapper script should never be moved out of the build directory.
5474b68e1f86Smrg# If it is, it will not operate correctly.
54756df26cacSmrg
5476b68e1f86Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5477b68e1f86Smrg# metacharacters that are still active within double-quoted strings.
5478b68e1f86Smrgsed_quote_subst='$sed_quote_subst'
54796df26cacSmrg
5480b68e1f86Smrg# Be Bourne compatible
5481b68e1f86Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5482b68e1f86Smrg  emulate sh
5483b68e1f86Smrg  NULLCMD=:
5484b68e1f86Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5485b68e1f86Smrg  # is contrary to our usage.  Disable this feature.
5486b68e1f86Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5487b68e1f86Smrg  setopt NO_GLOB_SUBST
5488b68e1f86Smrgelse
5489b68e1f86Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5490b68e1f86Smrgfi
5491b68e1f86SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5492b68e1f86SmrgDUALCASE=1; export DUALCASE # for MKS sh
54936df26cacSmrg
5494b68e1f86Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5495b68e1f86Smrg# if CDPATH is set.
5496b68e1f86Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
54976df26cacSmrg
5498b68e1f86Smrgrelink_command=\"$relink_command\"
54996df26cacSmrg
5500b68e1f86Smrg# This environment variable determines our operation mode.
5501b68e1f86Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5502b68e1f86Smrg  # install mode needs the following variables:
5503b68e1f86Smrg  generated_by_libtool_version='$macro_version'
5504b68e1f86Smrg  notinst_deplibs='$notinst_deplibs'
5505b68e1f86Smrgelse
5506b68e1f86Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5507b68e1f86Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
55083bfa90b6Smrg    file=\"\$0\""
55093bfa90b6Smrg
551025dbecb6Smrg    func_quote_arg pretty "$ECHO"
551125dbecb6Smrg    qECHO=$func_quote_arg_result
55123bfa90b6Smrg    $ECHO "\
55133bfa90b6Smrg
55143bfa90b6Smrg# A function that is used when there is no print builtin or printf.
55153bfa90b6Smrgfunc_fallback_echo ()
55163bfa90b6Smrg{
55173bfa90b6Smrg  eval 'cat <<_LTECHO_EOF
55183bfa90b6Smrg\$1
55193bfa90b6Smrg_LTECHO_EOF'
55203bfa90b6Smrg}
552125dbecb6Smrg    ECHO=$qECHO
55223bfa90b6Smrg  fi
55233bfa90b6Smrg
55243bfa90b6Smrg# Very basic option parsing. These options are (a) specific to
55253bfa90b6Smrg# the libtool wrapper, (b) are identical between the wrapper
552625dbecb6Smrg# /script/ and the wrapper /executable/ that is used only on
55273bfa90b6Smrg# windows platforms, and (c) all begin with the string "--lt-"
552825dbecb6Smrg# (application programs are unlikely to have options that match
55293bfa90b6Smrg# this pattern).
55303bfa90b6Smrg#
55313bfa90b6Smrg# There are only two supported options: --lt-debug and
55323bfa90b6Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
55333bfa90b6Smrg#
55343bfa90b6Smrg# The first argument to this parsing function should be the
55353bfa90b6Smrg# script's $0 value, followed by "$@".
55363bfa90b6Smrglt_option_debug=
55373bfa90b6Smrgfunc_parse_lt_options ()
55383bfa90b6Smrg{
55393bfa90b6Smrg  lt_script_arg0=\$0
55403bfa90b6Smrg  shift
55413bfa90b6Smrg  for lt_opt
55423bfa90b6Smrg  do
55433bfa90b6Smrg    case \"\$lt_opt\" in
55443bfa90b6Smrg    --lt-debug) lt_option_debug=1 ;;
55453bfa90b6Smrg    --lt-dump-script)
55463bfa90b6Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
55473bfa90b6Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
55483bfa90b6Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
55493bfa90b6Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
55503bfa90b6Smrg        exit 0
55513bfa90b6Smrg      ;;
55523bfa90b6Smrg    --lt-*)
55533bfa90b6Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
55543bfa90b6Smrg        exit 1
55553bfa90b6Smrg      ;;
55563bfa90b6Smrg    esac
55573bfa90b6Smrg  done
55583bfa90b6Smrg
55593bfa90b6Smrg  # Print the debug banner immediately:
55603bfa90b6Smrg  if test -n \"\$lt_option_debug\"; then
556125dbecb6Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
55623bfa90b6Smrg  fi
55633bfa90b6Smrg}
55643bfa90b6Smrg
55653bfa90b6Smrg# Used when --lt-debug. Prints its arguments to stdout
55663bfa90b6Smrg# (redirection is the responsibility of the caller)
55673bfa90b6Smrgfunc_lt_dump_args ()
55683bfa90b6Smrg{
55693bfa90b6Smrg  lt_dump_args_N=1;
55703bfa90b6Smrg  for lt_arg
55713bfa90b6Smrg  do
557225dbecb6Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
55733bfa90b6Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
55743bfa90b6Smrg  done
55753bfa90b6Smrg}
55763bfa90b6Smrg
55773bfa90b6Smrg# Core function for launching the target application
55783bfa90b6Smrgfunc_exec_program_core ()
55793bfa90b6Smrg{
5580b68e1f86Smrg"
55813bfa90b6Smrg  case $host in
55823bfa90b6Smrg  # Backslashes separate directories on plain windows
55833bfa90b6Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
55843bfa90b6Smrg    $ECHO "\
55853bfa90b6Smrg      if test -n \"\$lt_option_debug\"; then
558625dbecb6Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
55873bfa90b6Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
55883bfa90b6Smrg      fi
55893bfa90b6Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
55903bfa90b6Smrg"
55913bfa90b6Smrg    ;;
55923bfa90b6Smrg
55933bfa90b6Smrg  *)
55943bfa90b6Smrg    $ECHO "\
55953bfa90b6Smrg      if test -n \"\$lt_option_debug\"; then
559625dbecb6Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
55973bfa90b6Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
55983bfa90b6Smrg      fi
55993bfa90b6Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
56003bfa90b6Smrg"
56013bfa90b6Smrg    ;;
56023bfa90b6Smrg  esac
56033bfa90b6Smrg  $ECHO "\
56043bfa90b6Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
56053bfa90b6Smrg      exit 1
56063bfa90b6Smrg}
56073bfa90b6Smrg
56083bfa90b6Smrg# A function to encapsulate launching the target application
56093bfa90b6Smrg# Strips options in the --lt-* namespace from \$@ and
56103bfa90b6Smrg# launches target application with the remaining arguments.
56113bfa90b6Smrgfunc_exec_program ()
56123bfa90b6Smrg{
56133bfa90b6Smrg  case \" \$* \" in
56143bfa90b6Smrg  *\\ --lt-*)
56153bfa90b6Smrg    for lt_wr_arg
56163bfa90b6Smrg    do
56173bfa90b6Smrg      case \$lt_wr_arg in
56183bfa90b6Smrg      --lt-*) ;;
56193bfa90b6Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
56203bfa90b6Smrg      esac
56213bfa90b6Smrg      shift
56223bfa90b6Smrg    done ;;
56233bfa90b6Smrg  esac
56243bfa90b6Smrg  func_exec_program_core \${1+\"\$@\"}
56253bfa90b6Smrg}
56263bfa90b6Smrg
56273bfa90b6Smrg  # Parse options
56283bfa90b6Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
56296df26cacSmrg
5630b68e1f86Smrg  # Find the directory that this script lives in.
56313bfa90b6Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5632b68e1f86Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
56336df26cacSmrg
5634b68e1f86Smrg  # Follow symbolic links until we get to the real thisdir.
56353bfa90b6Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5636b68e1f86Smrg  while test -n \"\$file\"; do
56373bfa90b6Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5638b68e1f86Smrg
5639b68e1f86Smrg    # If there was a directory component, then change thisdir.
5640b68e1f86Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5641b68e1f86Smrg      case \"\$destdir\" in
5642b68e1f86Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5643b68e1f86Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
56446df26cacSmrg      esac
5645b68e1f86Smrg    fi
56466df26cacSmrg
56473bfa90b6Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
56483bfa90b6Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5649b68e1f86Smrg  done
56506df26cacSmrg
5651b68e1f86Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5652b68e1f86Smrg  # the cwrapper.
56533bfa90b6Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5654b68e1f86Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5655b68e1f86Smrg    # special case for '.'
5656b68e1f86Smrg    if test \"\$thisdir\" = \".\"; then
5657b68e1f86Smrg      thisdir=\`pwd\`
5658b68e1f86Smrg    fi
5659b68e1f86Smrg    # remove .libs from thisdir
5660b68e1f86Smrg    case \"\$thisdir\" in
56613bfa90b6Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5662b68e1f86Smrg    $objdir )   thisdir=. ;;
5663b68e1f86Smrg    esac
5664b68e1f86Smrg  fi
5665b68e1f86Smrg
5666b68e1f86Smrg  # Try to get the absolute directory name.
5667b68e1f86Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5668b68e1f86Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5669b68e1f86Smrg"
5670b68e1f86Smrg
567125dbecb6Smrg	if test yes = "$fast_install"; then
5672b68e1f86Smrg	  $ECHO "\
5673b68e1f86Smrg  program=lt-'$outputname'$exeext
5674b68e1f86Smrg  progdir=\"\$thisdir/$objdir\"
5675b68e1f86Smrg
5676b68e1f86Smrg  if test ! -f \"\$progdir/\$program\" ||
567725dbecb6Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5678b68e1f86Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5679b68e1f86Smrg
5680b68e1f86Smrg    file=\"\$\$-\$program\"
5681b68e1f86Smrg
5682b68e1f86Smrg    if test ! -d \"\$progdir\"; then
5683b68e1f86Smrg      $MKDIR \"\$progdir\"
5684b68e1f86Smrg    else
5685b68e1f86Smrg      $RM \"\$progdir/\$file\"
5686b68e1f86Smrg    fi"
5687b68e1f86Smrg
5688b68e1f86Smrg	  $ECHO "\
5689b68e1f86Smrg
5690b68e1f86Smrg    # relink executable if necessary
5691b68e1f86Smrg    if test -n \"\$relink_command\"; then
5692b68e1f86Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5693b68e1f86Smrg      else
569425dbecb6Smrg	\$ECHO \"\$relink_command_output\" >&2
5695b68e1f86Smrg	$RM \"\$progdir/\$file\"
5696b68e1f86Smrg	exit 1
56976df26cacSmrg      fi
5698b68e1f86Smrg    fi
56996df26cacSmrg
5700b68e1f86Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5701b68e1f86Smrg    { $RM \"\$progdir/\$program\";
5702b68e1f86Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5703b68e1f86Smrg    $RM \"\$progdir/\$file\"
5704b68e1f86Smrg  fi"
5705b68e1f86Smrg	else
5706b68e1f86Smrg	  $ECHO "\
5707b68e1f86Smrg  program='$outputname'
5708b68e1f86Smrg  progdir=\"\$thisdir/$objdir\"
5709b68e1f86Smrg"
57106df26cacSmrg	fi
57116df26cacSmrg
5712b68e1f86Smrg	$ECHO "\
5713b68e1f86Smrg
5714b68e1f86Smrg  if test -f \"\$progdir/\$program\"; then"
5715b68e1f86Smrg
57163bfa90b6Smrg	# fixup the dll searchpath if we need to.
57173bfa90b6Smrg	#
57183bfa90b6Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
57193bfa90b6Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
57203bfa90b6Smrg	# libraries must come first.
57213bfa90b6Smrg	if test -n "$dllsearchpath"; then
57223bfa90b6Smrg	  $ECHO "\
57233bfa90b6Smrg    # Add the dll search path components to the executable PATH
57243bfa90b6Smrg    PATH=$dllsearchpath:\$PATH
57253bfa90b6Smrg"
57263bfa90b6Smrg	fi
57273bfa90b6Smrg
5728b68e1f86Smrg	# Export our shlibpath_var if we have one.
572925dbecb6Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5730b68e1f86Smrg	  $ECHO "\
5731b68e1f86Smrg    # Add our own library path to $shlibpath_var
5732b68e1f86Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5733b68e1f86Smrg
5734b68e1f86Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5735b68e1f86Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
57363bfa90b6Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5737b68e1f86Smrg
5738b68e1f86Smrg    export $shlibpath_var
5739b68e1f86Smrg"
57406df26cacSmrg	fi
57416df26cacSmrg
5742b68e1f86Smrg	$ECHO "\
5743b68e1f86Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5744b68e1f86Smrg      # Run the actual program with our arguments.
57453bfa90b6Smrg      func_exec_program \${1+\"\$@\"}
5746b68e1f86Smrg    fi
5747b68e1f86Smrg  else
5748b68e1f86Smrg    # The program doesn't exist.
574925dbecb6Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5750b68e1f86Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
57513bfa90b6Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5752b68e1f86Smrg    exit 1
5753b68e1f86Smrg  fi
5754b68e1f86Smrgfi\
5755b68e1f86Smrg"
5756b68e1f86Smrg}
57576df26cacSmrg
57586df26cacSmrg
5759b68e1f86Smrg# func_emit_cwrapperexe_src
5760b68e1f86Smrg# emit the source code for a wrapper executable on stdout
5761b68e1f86Smrg# Must ONLY be called from within func_mode_link because
5762b68e1f86Smrg# it depends on a number of variable set therein.
5763b68e1f86Smrgfunc_emit_cwrapperexe_src ()
5764b68e1f86Smrg{
5765b68e1f86Smrg	cat <<EOF
57666df26cacSmrg
5767b68e1f86Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
576825dbecb6Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
57696df26cacSmrg
5770b68e1f86Smrg   The $output program cannot be directly executed until all the libtool
5771b68e1f86Smrg   libraries that it depends on are installed.
57726df26cacSmrg
5773b68e1f86Smrg   This wrapper executable should never be moved out of the build directory.
5774b68e1f86Smrg   If it is, it will not operate correctly.
5775b68e1f86Smrg*/
5776b68e1f86SmrgEOF
5777b68e1f86Smrg	    cat <<"EOF"
57783bfa90b6Smrg#ifdef _MSC_VER
57793bfa90b6Smrg# define _CRT_SECURE_NO_DEPRECATE 1
57803bfa90b6Smrg#endif
5781b68e1f86Smrg#include <stdio.h>
5782b68e1f86Smrg#include <stdlib.h>
5783b68e1f86Smrg#ifdef _MSC_VER
5784b68e1f86Smrg# include <direct.h>
5785b68e1f86Smrg# include <process.h>
5786b68e1f86Smrg# include <io.h>
5787b68e1f86Smrg#else
5788b68e1f86Smrg# include <unistd.h>
5789b68e1f86Smrg# include <stdint.h>
5790b68e1f86Smrg# ifdef __CYGWIN__
5791b68e1f86Smrg#  include <io.h>
5792b68e1f86Smrg# endif
5793b68e1f86Smrg#endif
5794b68e1f86Smrg#include <malloc.h>
5795b68e1f86Smrg#include <stdarg.h>
5796b68e1f86Smrg#include <assert.h>
5797b68e1f86Smrg#include <string.h>
5798b68e1f86Smrg#include <ctype.h>
5799b68e1f86Smrg#include <errno.h>
5800b68e1f86Smrg#include <fcntl.h>
5801b68e1f86Smrg#include <sys/stat.h>
58026df26cacSmrg
580325dbecb6Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
580425dbecb6Smrg
58053bfa90b6Smrg/* declarations of non-ANSI functions */
580625dbecb6Smrg#if defined __MINGW32__
58073bfa90b6Smrg# ifdef __STRICT_ANSI__
58083bfa90b6Smrgint _putenv (const char *);
58093bfa90b6Smrg# endif
581025dbecb6Smrg#elif defined __CYGWIN__
58113bfa90b6Smrg# ifdef __STRICT_ANSI__
58123bfa90b6Smrgchar *realpath (const char *, char *);
58133bfa90b6Smrgint putenv (char *);
58143bfa90b6Smrgint setenv (const char *, const char *, int);
58153bfa90b6Smrg# endif
581625dbecb6Smrg/* #elif defined other_platform || defined ... */
58173bfa90b6Smrg#endif
58183bfa90b6Smrg
58193bfa90b6Smrg/* portability defines, excluding path handling macros */
582025dbecb6Smrg#if defined _MSC_VER
58213bfa90b6Smrg# define setmode _setmode
58223bfa90b6Smrg# define stat    _stat
58233bfa90b6Smrg# define chmod   _chmod
58243bfa90b6Smrg# define getcwd  _getcwd
58253bfa90b6Smrg# define putenv  _putenv
58263bfa90b6Smrg# define S_IXUSR _S_IEXEC
582725dbecb6Smrg#elif defined __MINGW32__
58283bfa90b6Smrg# define setmode _setmode
58293bfa90b6Smrg# define stat    _stat
58303bfa90b6Smrg# define chmod   _chmod
58313bfa90b6Smrg# define getcwd  _getcwd
58323bfa90b6Smrg# define putenv  _putenv
583325dbecb6Smrg#elif defined __CYGWIN__
58343bfa90b6Smrg# define HAVE_SETENV
58353bfa90b6Smrg# define FOPEN_WB "wb"
583625dbecb6Smrg/* #elif defined other platforms ... */
58373bfa90b6Smrg#endif
58383bfa90b6Smrg
583925dbecb6Smrg#if defined PATH_MAX
5840b68e1f86Smrg# define LT_PATHMAX PATH_MAX
584125dbecb6Smrg#elif defined MAXPATHLEN
5842b68e1f86Smrg# define LT_PATHMAX MAXPATHLEN
5843b68e1f86Smrg#else
5844b68e1f86Smrg# define LT_PATHMAX 1024
5845b68e1f86Smrg#endif
58466df26cacSmrg
5847b68e1f86Smrg#ifndef S_IXOTH
5848b68e1f86Smrg# define S_IXOTH 0
5849b68e1f86Smrg#endif
5850b68e1f86Smrg#ifndef S_IXGRP
5851b68e1f86Smrg# define S_IXGRP 0
5852b68e1f86Smrg#endif
58536df26cacSmrg
58543bfa90b6Smrg/* path handling portability macros */
5855b68e1f86Smrg#ifndef DIR_SEPARATOR
5856b68e1f86Smrg# define DIR_SEPARATOR '/'
5857b68e1f86Smrg# define PATH_SEPARATOR ':'
5858b68e1f86Smrg#endif
58596df26cacSmrg
586025dbecb6Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
586125dbecb6Smrg  defined __OS2__
5862b68e1f86Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5863b68e1f86Smrg# define FOPEN_WB "wb"
5864b68e1f86Smrg# ifndef DIR_SEPARATOR_2
5865b68e1f86Smrg#  define DIR_SEPARATOR_2 '\\'
5866b68e1f86Smrg# endif
5867b68e1f86Smrg# ifndef PATH_SEPARATOR_2
5868b68e1f86Smrg#  define PATH_SEPARATOR_2 ';'
5869b68e1f86Smrg# endif
5870b68e1f86Smrg#endif
58716df26cacSmrg
5872b68e1f86Smrg#ifndef DIR_SEPARATOR_2
5873b68e1f86Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5874b68e1f86Smrg#else /* DIR_SEPARATOR_2 */
5875b68e1f86Smrg# define IS_DIR_SEPARATOR(ch) \
5876b68e1f86Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5877b68e1f86Smrg#endif /* DIR_SEPARATOR_2 */
58786df26cacSmrg
5879b68e1f86Smrg#ifndef PATH_SEPARATOR_2
5880b68e1f86Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5881b68e1f86Smrg#else /* PATH_SEPARATOR_2 */
5882b68e1f86Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5883b68e1f86Smrg#endif /* PATH_SEPARATOR_2 */
58846df26cacSmrg
5885b68e1f86Smrg#ifndef FOPEN_WB
5886b68e1f86Smrg# define FOPEN_WB "w"
5887b68e1f86Smrg#endif
5888b68e1f86Smrg#ifndef _O_BINARY
5889b68e1f86Smrg# define _O_BINARY 0
5890b68e1f86Smrg#endif
58916df26cacSmrg
5892b68e1f86Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5893b68e1f86Smrg#define XFREE(stale) do { \
589425dbecb6Smrg  if (stale) { free (stale); stale = 0; } \
5895b68e1f86Smrg} while (0)
58966df26cacSmrg
589725dbecb6Smrg#if defined LT_DEBUGWRAPPER
58983bfa90b6Smrgstatic int lt_debug = 1;
5899b68e1f86Smrg#else
59003bfa90b6Smrgstatic int lt_debug = 0;
5901b68e1f86Smrg#endif
59026df26cacSmrg
59033bfa90b6Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59046df26cacSmrg
5905b68e1f86Smrgvoid *xmalloc (size_t num);
5906b68e1f86Smrgchar *xstrdup (const char *string);
5907b68e1f86Smrgconst char *base_name (const char *name);
5908b68e1f86Smrgchar *find_executable (const char *wrapper);
5909b68e1f86Smrgchar *chase_symlinks (const char *pathspec);
5910b68e1f86Smrgint make_executable (const char *path);
5911b68e1f86Smrgint check_executable (const char *path);
5912b68e1f86Smrgchar *strendzap (char *str, const char *pat);
59133bfa90b6Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
59143bfa90b6Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
59153bfa90b6Smrgstatic const char *nonnull (const char *s);
59163bfa90b6Smrgstatic const char *nonempty (const char *s);
5917b68e1f86Smrgvoid lt_setenv (const char *name, const char *value);
5918b68e1f86Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5919b68e1f86Smrgvoid lt_update_exe_path (const char *name, const char *value);
5920b68e1f86Smrgvoid lt_update_lib_path (const char *name, const char *value);
59213bfa90b6Smrgchar **prepare_spawn (char **argv);
59223bfa90b6Smrgvoid lt_dump_script (FILE *f);
5923b68e1f86SmrgEOF
5924b68e1f86Smrg
5925b68e1f86Smrg	    cat <<EOF
592625dbecb6Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
592725dbecb6Smrg# define externally_visible volatile
592825dbecb6Smrg#else
592925dbecb6Smrg# define externally_visible __attribute__((externally_visible)) volatile
593025dbecb6Smrg#endif
593125dbecb6Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5932b68e1f86Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5933b68e1f86SmrgEOF
59346df26cacSmrg
593525dbecb6Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
59363bfa90b6Smrg              func_to_host_path "$temp_rpath"
5937b68e1f86Smrg	      cat <<EOF
59383bfa90b6Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5939b68e1f86SmrgEOF
5940b68e1f86Smrg	    else
5941b68e1f86Smrg	      cat <<"EOF"
5942b68e1f86Smrgconst char * LIB_PATH_VALUE   = "";
5943b68e1f86SmrgEOF
5944b68e1f86Smrg	    fi
59456df26cacSmrg
5946b68e1f86Smrg	    if test -n "$dllsearchpath"; then
59473bfa90b6Smrg              func_to_host_path "$dllsearchpath:"
5948b68e1f86Smrg	      cat <<EOF
5949b68e1f86Smrgconst char * EXE_PATH_VARNAME = "PATH";
59503bfa90b6Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5951b68e1f86SmrgEOF
5952b68e1f86Smrg	    else
5953b68e1f86Smrg	      cat <<"EOF"
5954b68e1f86Smrgconst char * EXE_PATH_VARNAME = "";
5955b68e1f86Smrgconst char * EXE_PATH_VALUE   = "";
5956b68e1f86SmrgEOF
5957b68e1f86Smrg	    fi
59586df26cacSmrg
595925dbecb6Smrg	    if test yes = "$fast_install"; then
5960b68e1f86Smrg	      cat <<EOF
5961b68e1f86Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5962b68e1f86SmrgEOF
5963b68e1f86Smrg	    else
5964b68e1f86Smrg	      cat <<EOF
5965b68e1f86Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5966b68e1f86SmrgEOF
5967b68e1f86Smrg	    fi
59686df26cacSmrg
59696df26cacSmrg
5970b68e1f86Smrg	    cat <<"EOF"
59716df26cacSmrg
5972b68e1f86Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
59736df26cacSmrg
5974b68e1f86Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5975b68e1f86Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
59763bfa90b6Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5977b68e1f86Smrg
5978b68e1f86Smrgint
5979b68e1f86Smrgmain (int argc, char *argv[])
5980b68e1f86Smrg{
5981b68e1f86Smrg  char **newargz;
5982b68e1f86Smrg  int  newargc;
5983b68e1f86Smrg  char *tmp_pathspec;
5984b68e1f86Smrg  char *actual_cwrapper_path;
5985b68e1f86Smrg  char *actual_cwrapper_name;
5986b68e1f86Smrg  char *target_name;
5987b68e1f86Smrg  char *lt_argv_zero;
598825dbecb6Smrg  int rval = 127;
5989b68e1f86Smrg
5990b68e1f86Smrg  int i;
5991b68e1f86Smrg
5992b68e1f86Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
599325dbecb6Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5994b68e1f86Smrg
59953bfa90b6Smrg  /* very simple arg parsing; don't want to rely on getopt
59963bfa90b6Smrg   * also, copy all non cwrapper options to newargz, except
59973bfa90b6Smrg   * argz[0], which is handled differently
59983bfa90b6Smrg   */
59993bfa90b6Smrg  newargc=0;
6000b68e1f86Smrg  for (i = 1; i < argc; i++)
6001b68e1f86Smrg    {
600225dbecb6Smrg      if (STREQ (argv[i], dumpscript_opt))
6003b68e1f86Smrg	{
6004b68e1f86SmrgEOF
600525dbecb6Smrg	    case $host in
6006b68e1f86Smrg	      *mingw* | *cygwin* )
6007b68e1f86Smrg		# make stdout use "unix" line endings
6008b68e1f86Smrg		echo "          setmode(1,_O_BINARY);"
6009b68e1f86Smrg		;;
6010b68e1f86Smrg	      esac
6011b68e1f86Smrg
6012b68e1f86Smrg	    cat <<"EOF"
60133bfa90b6Smrg	  lt_dump_script (stdout);
6014b68e1f86Smrg	  return 0;
6015b68e1f86Smrg	}
601625dbecb6Smrg      if (STREQ (argv[i], debug_opt))
60173bfa90b6Smrg	{
60183bfa90b6Smrg          lt_debug = 1;
60193bfa90b6Smrg          continue;
60203bfa90b6Smrg	}
602125dbecb6Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
60223bfa90b6Smrg        {
60233bfa90b6Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
60243bfa90b6Smrg             namespace, but it is not one of the ones we know about and
60253bfa90b6Smrg             have already dealt with, above (inluding dump-script), then
60263bfa90b6Smrg             report an error. Otherwise, targets might begin to believe
60273bfa90b6Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
60283bfa90b6Smrg             namespace. The first time any user complains about this, we'll
60293bfa90b6Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
60303bfa90b6Smrg             or a configure.ac-settable value.
60313bfa90b6Smrg           */
60323bfa90b6Smrg          lt_fatal (__FILE__, __LINE__,
60333bfa90b6Smrg		    "unrecognized %s option: '%s'",
60343bfa90b6Smrg                    ltwrapper_option_prefix, argv[i]);
60353bfa90b6Smrg        }
60363bfa90b6Smrg      /* otherwise ... */
60373bfa90b6Smrg      newargz[++newargc] = xstrdup (argv[i]);
6038b68e1f86Smrg    }
60393bfa90b6Smrg  newargz[++newargc] = NULL;
60403bfa90b6Smrg
60413bfa90b6SmrgEOF
60423bfa90b6Smrg	    cat <<EOF
60433bfa90b6Smrg  /* The GNU banner must be the first non-error debug message */
604425dbecb6Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
60453bfa90b6SmrgEOF
60463bfa90b6Smrg	    cat <<"EOF"
60473bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
60483bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6049b68e1f86Smrg
6050b68e1f86Smrg  tmp_pathspec = find_executable (argv[0]);
6051b68e1f86Smrg  if (tmp_pathspec == NULL)
60523bfa90b6Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
60533bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
60543bfa90b6Smrg                  "(main) found exe (before symlink chase) at: %s\n",
60553bfa90b6Smrg		  tmp_pathspec);
6056b68e1f86Smrg
6057b68e1f86Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
60583bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
60593bfa90b6Smrg                  "(main) found exe (after symlink chase) at: %s\n",
60603bfa90b6Smrg		  actual_cwrapper_path);
6061b68e1f86Smrg  XFREE (tmp_pathspec);
6062b68e1f86Smrg
60633bfa90b6Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6064b68e1f86Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6065b68e1f86Smrg
6066b68e1f86Smrg  /* wrapper name transforms */
6067b68e1f86Smrg  strendzap (actual_cwrapper_name, ".exe");
6068b68e1f86Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6069b68e1f86Smrg  XFREE (actual_cwrapper_name);
6070b68e1f86Smrg  actual_cwrapper_name = tmp_pathspec;
6071b68e1f86Smrg  tmp_pathspec = 0;
6072b68e1f86Smrg
6073b68e1f86Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6074b68e1f86Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6075b68e1f86Smrg  strendzap (target_name, ".exe");
6076b68e1f86Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6077b68e1f86Smrg  XFREE (target_name);
6078b68e1f86Smrg  target_name = tmp_pathspec;
6079b68e1f86Smrg  tmp_pathspec = 0;
6080b68e1f86Smrg
60813bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
60823bfa90b6Smrg		  "(main) libtool target name: %s\n",
60833bfa90b6Smrg		  target_name);
6084b68e1f86SmrgEOF
6085b68e1f86Smrg
6086b68e1f86Smrg	    cat <<EOF
6087b68e1f86Smrg  newargz[0] =
6088b68e1f86Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6089b68e1f86Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6090b68e1f86Smrg  strcpy (newargz[0], actual_cwrapper_path);
6091b68e1f86Smrg  strcat (newargz[0], "$objdir");
6092b68e1f86Smrg  strcat (newargz[0], "/");
6093b68e1f86SmrgEOF
6094b68e1f86Smrg
6095b68e1f86Smrg	    cat <<"EOF"
6096b68e1f86Smrg  /* stop here, and copy so we don't have to do this twice */
6097b68e1f86Smrg  tmp_pathspec = xstrdup (newargz[0]);
6098b68e1f86Smrg
6099b68e1f86Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6100b68e1f86Smrg  strcat (newargz[0], actual_cwrapper_name);
6101b68e1f86Smrg
6102b68e1f86Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6103b68e1f86Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6104b68e1f86Smrg  XFREE (tmp_pathspec);
6105b68e1f86Smrg  tmp_pathspec = NULL;
6106b68e1f86SmrgEOF
6107b68e1f86Smrg
6108b68e1f86Smrg	    case $host_os in
6109b68e1f86Smrg	      mingw*)
6110b68e1f86Smrg	    cat <<"EOF"
6111b68e1f86Smrg  {
6112b68e1f86Smrg    char* p;
6113b68e1f86Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6114b68e1f86Smrg      {
6115b68e1f86Smrg	*p = '/';
6116b68e1f86Smrg      }
6117b68e1f86Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6118b68e1f86Smrg      {
6119b68e1f86Smrg	*p = '/';
6120b68e1f86Smrg      }
6121b68e1f86Smrg  }
6122b68e1f86SmrgEOF
61236df26cacSmrg	    ;;
6124b68e1f86Smrg	    esac
6125b68e1f86Smrg
6126b68e1f86Smrg	    cat <<"EOF"
6127b68e1f86Smrg  XFREE (target_name);
6128b68e1f86Smrg  XFREE (actual_cwrapper_path);
6129b68e1f86Smrg  XFREE (actual_cwrapper_name);
6130b68e1f86Smrg
6131b68e1f86Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6132b68e1f86Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
61333bfa90b6Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
61343bfa90b6Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
61353bfa90b6Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
61363bfa90b6Smrg     libraries must come first. */
6137b68e1f86Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
61383bfa90b6Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6139b68e1f86Smrg
61403bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
61413bfa90b6Smrg		  nonnull (lt_argv_zero));
6142b68e1f86Smrg  for (i = 0; i < newargc; i++)
6143b68e1f86Smrg    {
61443bfa90b6Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
61453bfa90b6Smrg		      i, nonnull (newargz[i]));
6146b68e1f86Smrg    }
61476df26cacSmrg
61486df26cacSmrgEOF
61496df26cacSmrg
6150b68e1f86Smrg	    case $host_os in
6151b68e1f86Smrg	      mingw*)
6152b68e1f86Smrg		cat <<"EOF"
6153b68e1f86Smrg  /* execv doesn't actually work on mingw as expected on unix */
61543bfa90b6Smrg  newargz = prepare_spawn (newargz);
615525dbecb6Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6156b68e1f86Smrg  if (rval == -1)
6157b68e1f86Smrg    {
6158b68e1f86Smrg      /* failed to start process */
61593bfa90b6Smrg      lt_debugprintf (__FILE__, __LINE__,
61603bfa90b6Smrg		      "(main) failed to launch target \"%s\": %s\n",
61613bfa90b6Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6162b68e1f86Smrg      return 127;
6163b68e1f86Smrg    }
6164b68e1f86Smrg  return rval;
6165b68e1f86SmrgEOF
6166b68e1f86Smrg		;;
6167b68e1f86Smrg	      *)
6168b68e1f86Smrg		cat <<"EOF"
6169b68e1f86Smrg  execv (lt_argv_zero, newargz);
6170b68e1f86Smrg  return rval; /* =127, but avoids unused variable warning */
6171b68e1f86SmrgEOF
6172b68e1f86Smrg		;;
6173b68e1f86Smrg	    esac
61746df26cacSmrg
6175b68e1f86Smrg	    cat <<"EOF"
6176b68e1f86Smrg}
61776df26cacSmrg
6178b68e1f86Smrgvoid *
6179b68e1f86Smrgxmalloc (size_t num)
6180b68e1f86Smrg{
6181b68e1f86Smrg  void *p = (void *) malloc (num);
6182b68e1f86Smrg  if (!p)
61833bfa90b6Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
61846df26cacSmrg
6185b68e1f86Smrg  return p;
6186b68e1f86Smrg}
61876df26cacSmrg
6188b68e1f86Smrgchar *
6189b68e1f86Smrgxstrdup (const char *string)
6190b68e1f86Smrg{
6191b68e1f86Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6192b68e1f86Smrg			  string) : NULL;
6193b68e1f86Smrg}
61946df26cacSmrg
6195b68e1f86Smrgconst char *
6196b68e1f86Smrgbase_name (const char *name)
6197b68e1f86Smrg{
6198b68e1f86Smrg  const char *base;
61996df26cacSmrg
620025dbecb6Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6201b68e1f86Smrg  /* Skip over the disk name in MSDOS pathnames. */
6202b68e1f86Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6203b68e1f86Smrg    name += 2;
6204b68e1f86Smrg#endif
62056df26cacSmrg
6206b68e1f86Smrg  for (base = name; *name; name++)
6207b68e1f86Smrg    if (IS_DIR_SEPARATOR (*name))
6208b68e1f86Smrg      base = name + 1;
6209b68e1f86Smrg  return base;
6210b68e1f86Smrg}
62116df26cacSmrg
6212b68e1f86Smrgint
6213b68e1f86Smrgcheck_executable (const char *path)
6214b68e1f86Smrg{
6215b68e1f86Smrg  struct stat st;
62166df26cacSmrg
62173bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
62183bfa90b6Smrg                  nonempty (path));
6219b68e1f86Smrg  if ((!path) || (!*path))
6220b68e1f86Smrg    return 0;
62216df26cacSmrg
6222b68e1f86Smrg  if ((stat (path, &st) >= 0)
6223b68e1f86Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6224b68e1f86Smrg    return 1;
6225b68e1f86Smrg  else
6226b68e1f86Smrg    return 0;
6227b68e1f86Smrg}
62286df26cacSmrg
6229b68e1f86Smrgint
6230b68e1f86Smrgmake_executable (const char *path)
6231b68e1f86Smrg{
6232b68e1f86Smrg  int rval = 0;
6233b68e1f86Smrg  struct stat st;
62346df26cacSmrg
62353bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
62363bfa90b6Smrg                  nonempty (path));
6237b68e1f86Smrg  if ((!path) || (!*path))
6238b68e1f86Smrg    return 0;
62396df26cacSmrg
6240b68e1f86Smrg  if (stat (path, &st) >= 0)
6241b68e1f86Smrg    {
6242b68e1f86Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6243b68e1f86Smrg    }
6244b68e1f86Smrg  return rval;
6245b68e1f86Smrg}
62466df26cacSmrg
6247b68e1f86Smrg/* Searches for the full path of the wrapper.  Returns
6248b68e1f86Smrg   newly allocated full path name if found, NULL otherwise
6249b68e1f86Smrg   Does not chase symlinks, even on platforms that support them.
6250b68e1f86Smrg*/
6251b68e1f86Smrgchar *
6252b68e1f86Smrgfind_executable (const char *wrapper)
6253b68e1f86Smrg{
6254b68e1f86Smrg  int has_slash = 0;
6255b68e1f86Smrg  const char *p;
6256b68e1f86Smrg  const char *p_next;
6257b68e1f86Smrg  /* static buffer for getcwd */
6258b68e1f86Smrg  char tmp[LT_PATHMAX + 1];
625925dbecb6Smrg  size_t tmp_len;
6260b68e1f86Smrg  char *concat_name;
62616df26cacSmrg
62623bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
62633bfa90b6Smrg                  nonempty (wrapper));
62646df26cacSmrg
6265b68e1f86Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6266b68e1f86Smrg    return NULL;
62676df26cacSmrg
6268b68e1f86Smrg  /* Absolute path? */
626925dbecb6Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6270b68e1f86Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6271b68e1f86Smrg    {
6272b68e1f86Smrg      concat_name = xstrdup (wrapper);
6273b68e1f86Smrg      if (check_executable (concat_name))
6274b68e1f86Smrg	return concat_name;
6275b68e1f86Smrg      XFREE (concat_name);
6276b68e1f86Smrg    }
6277b68e1f86Smrg  else
6278b68e1f86Smrg    {
6279b68e1f86Smrg#endif
6280b68e1f86Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6281b68e1f86Smrg	{
6282b68e1f86Smrg	  concat_name = xstrdup (wrapper);
6283b68e1f86Smrg	  if (check_executable (concat_name))
6284b68e1f86Smrg	    return concat_name;
6285b68e1f86Smrg	  XFREE (concat_name);
6286b68e1f86Smrg	}
628725dbecb6Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6288b68e1f86Smrg    }
6289b68e1f86Smrg#endif
62906df26cacSmrg
6291b68e1f86Smrg  for (p = wrapper; *p; p++)
6292b68e1f86Smrg    if (*p == '/')
6293b68e1f86Smrg      {
6294b68e1f86Smrg	has_slash = 1;
6295b68e1f86Smrg	break;
6296b68e1f86Smrg      }
6297b68e1f86Smrg  if (!has_slash)
6298b68e1f86Smrg    {
6299b68e1f86Smrg      /* no slashes; search PATH */
6300b68e1f86Smrg      const char *path = getenv ("PATH");
6301b68e1f86Smrg      if (path != NULL)
6302b68e1f86Smrg	{
6303b68e1f86Smrg	  for (p = path; *p; p = p_next)
6304b68e1f86Smrg	    {
6305b68e1f86Smrg	      const char *q;
6306b68e1f86Smrg	      size_t p_len;
6307b68e1f86Smrg	      for (q = p; *q; q++)
6308b68e1f86Smrg		if (IS_PATH_SEPARATOR (*q))
6309b68e1f86Smrg		  break;
631025dbecb6Smrg	      p_len = (size_t) (q - p);
6311b68e1f86Smrg	      p_next = (*q == '\0' ? q : q + 1);
6312b68e1f86Smrg	      if (p_len == 0)
6313b68e1f86Smrg		{
6314b68e1f86Smrg		  /* empty path: current directory */
6315b68e1f86Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
63163bfa90b6Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63173bfa90b6Smrg                              nonnull (strerror (errno)));
6318b68e1f86Smrg		  tmp_len = strlen (tmp);
6319b68e1f86Smrg		  concat_name =
6320b68e1f86Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6321b68e1f86Smrg		  memcpy (concat_name, tmp, tmp_len);
6322b68e1f86Smrg		  concat_name[tmp_len] = '/';
6323b68e1f86Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6324b68e1f86Smrg		}
6325b68e1f86Smrg	      else
6326b68e1f86Smrg		{
6327b68e1f86Smrg		  concat_name =
6328b68e1f86Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6329b68e1f86Smrg		  memcpy (concat_name, p, p_len);
6330b68e1f86Smrg		  concat_name[p_len] = '/';
6331b68e1f86Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6332b68e1f86Smrg		}
6333b68e1f86Smrg	      if (check_executable (concat_name))
6334b68e1f86Smrg		return concat_name;
6335b68e1f86Smrg	      XFREE (concat_name);
6336b68e1f86Smrg	    }
6337b68e1f86Smrg	}
6338b68e1f86Smrg      /* not found in PATH; assume curdir */
6339b68e1f86Smrg    }
6340b68e1f86Smrg  /* Relative path | not found in path: prepend cwd */
6341b68e1f86Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
63423bfa90b6Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63433bfa90b6Smrg              nonnull (strerror (errno)));
6344b68e1f86Smrg  tmp_len = strlen (tmp);
6345b68e1f86Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6346b68e1f86Smrg  memcpy (concat_name, tmp, tmp_len);
6347b68e1f86Smrg  concat_name[tmp_len] = '/';
6348b68e1f86Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
63496df26cacSmrg
6350b68e1f86Smrg  if (check_executable (concat_name))
6351b68e1f86Smrg    return concat_name;
6352b68e1f86Smrg  XFREE (concat_name);
6353b68e1f86Smrg  return NULL;
6354b68e1f86Smrg}
63556df26cacSmrg
6356b68e1f86Smrgchar *
6357b68e1f86Smrgchase_symlinks (const char *pathspec)
6358b68e1f86Smrg{
6359b68e1f86Smrg#ifndef S_ISLNK
6360b68e1f86Smrg  return xstrdup (pathspec);
6361b68e1f86Smrg#else
6362b68e1f86Smrg  char buf[LT_PATHMAX];
6363b68e1f86Smrg  struct stat s;
6364b68e1f86Smrg  char *tmp_pathspec = xstrdup (pathspec);
6365b68e1f86Smrg  char *p;
6366b68e1f86Smrg  int has_symlinks = 0;
6367b68e1f86Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6368b68e1f86Smrg    {
63693bfa90b6Smrg      lt_debugprintf (__FILE__, __LINE__,
63703bfa90b6Smrg		      "checking path component for symlinks: %s\n",
63713bfa90b6Smrg		      tmp_pathspec);
6372b68e1f86Smrg      if (lstat (tmp_pathspec, &s) == 0)
6373b68e1f86Smrg	{
6374b68e1f86Smrg	  if (S_ISLNK (s.st_mode) != 0)
6375b68e1f86Smrg	    {
6376b68e1f86Smrg	      has_symlinks = 1;
6377b68e1f86Smrg	      break;
6378b68e1f86Smrg	    }
63796df26cacSmrg
6380b68e1f86Smrg	  /* search backwards for last DIR_SEPARATOR */
6381b68e1f86Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6382b68e1f86Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6383b68e1f86Smrg	    p--;
6384b68e1f86Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6385b68e1f86Smrg	    {
6386b68e1f86Smrg	      /* no more DIR_SEPARATORS left */
6387b68e1f86Smrg	      break;
6388b68e1f86Smrg	    }
6389b68e1f86Smrg	  *p = '\0';
6390b68e1f86Smrg	}
6391b68e1f86Smrg      else
6392b68e1f86Smrg	{
63933bfa90b6Smrg	  lt_fatal (__FILE__, __LINE__,
63943bfa90b6Smrg		    "error accessing file \"%s\": %s",
63953bfa90b6Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6396b68e1f86Smrg	}
6397b68e1f86Smrg    }
6398b68e1f86Smrg  XFREE (tmp_pathspec);
63996df26cacSmrg
6400b68e1f86Smrg  if (!has_symlinks)
6401b68e1f86Smrg    {
6402b68e1f86Smrg      return xstrdup (pathspec);
6403b68e1f86Smrg    }
64046df26cacSmrg
6405b68e1f86Smrg  tmp_pathspec = realpath (pathspec, buf);
6406b68e1f86Smrg  if (tmp_pathspec == 0)
6407b68e1f86Smrg    {
64083bfa90b6Smrg      lt_fatal (__FILE__, __LINE__,
64093bfa90b6Smrg		"could not follow symlinks for %s", pathspec);
6410b68e1f86Smrg    }
6411b68e1f86Smrg  return xstrdup (tmp_pathspec);
6412b68e1f86Smrg#endif
6413b68e1f86Smrg}
64146df26cacSmrg
6415b68e1f86Smrgchar *
6416b68e1f86Smrgstrendzap (char *str, const char *pat)
6417b68e1f86Smrg{
6418b68e1f86Smrg  size_t len, patlen;
64196df26cacSmrg
6420b68e1f86Smrg  assert (str != NULL);
6421b68e1f86Smrg  assert (pat != NULL);
64226df26cacSmrg
6423b68e1f86Smrg  len = strlen (str);
6424b68e1f86Smrg  patlen = strlen (pat);
64256df26cacSmrg
6426b68e1f86Smrg  if (patlen <= len)
6427b68e1f86Smrg    {
6428b68e1f86Smrg      str += len - patlen;
642925dbecb6Smrg      if (STREQ (str, pat))
6430b68e1f86Smrg	*str = '\0';
6431b68e1f86Smrg    }
6432b68e1f86Smrg  return str;
6433b68e1f86Smrg}
64346df26cacSmrg
64353bfa90b6Smrgvoid
64363bfa90b6Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
64373bfa90b6Smrg{
64383bfa90b6Smrg  va_list args;
64393bfa90b6Smrg  if (lt_debug)
64403bfa90b6Smrg    {
64413bfa90b6Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
64423bfa90b6Smrg      va_start (args, fmt);
64433bfa90b6Smrg      (void) vfprintf (stderr, fmt, args);
64443bfa90b6Smrg      va_end (args);
64453bfa90b6Smrg    }
64463bfa90b6Smrg}
64473bfa90b6Smrg
6448b68e1f86Smrgstatic void
64493bfa90b6Smrglt_error_core (int exit_status, const char *file,
64503bfa90b6Smrg	       int line, const char *mode,
6451b68e1f86Smrg	       const char *message, va_list ap)
6452b68e1f86Smrg{
64533bfa90b6Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6454b68e1f86Smrg  vfprintf (stderr, message, ap);
6455b68e1f86Smrg  fprintf (stderr, ".\n");
64566df26cacSmrg
6457b68e1f86Smrg  if (exit_status >= 0)
6458b68e1f86Smrg    exit (exit_status);
6459b68e1f86Smrg}
64606df26cacSmrg
6461b68e1f86Smrgvoid
64623bfa90b6Smrglt_fatal (const char *file, int line, const char *message, ...)
6463b68e1f86Smrg{
6464b68e1f86Smrg  va_list ap;
6465b68e1f86Smrg  va_start (ap, message);
64663bfa90b6Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6467b68e1f86Smrg  va_end (ap);
6468b68e1f86Smrg}
64696df26cacSmrg
64703bfa90b6Smrgstatic const char *
64713bfa90b6Smrgnonnull (const char *s)
64723bfa90b6Smrg{
64733bfa90b6Smrg  return s ? s : "(null)";
64743bfa90b6Smrg}
64753bfa90b6Smrg
64763bfa90b6Smrgstatic const char *
64773bfa90b6Smrgnonempty (const char *s)
64783bfa90b6Smrg{
64793bfa90b6Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
64803bfa90b6Smrg}
64813bfa90b6Smrg
6482b68e1f86Smrgvoid
6483b68e1f86Smrglt_setenv (const char *name, const char *value)
6484b68e1f86Smrg{
64853bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
64863bfa90b6Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
64873bfa90b6Smrg                  nonnull (name), nonnull (value));
6488b68e1f86Smrg  {
6489b68e1f86Smrg#ifdef HAVE_SETENV
6490b68e1f86Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6491b68e1f86Smrg    char *str = xstrdup (value);
6492b68e1f86Smrg    setenv (name, str, 1);
6493b68e1f86Smrg#else
649425dbecb6Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6495b68e1f86Smrg    char *str = XMALLOC (char, len);
6496b68e1f86Smrg    sprintf (str, "%s=%s", name, value);
6497b68e1f86Smrg    if (putenv (str) != EXIT_SUCCESS)
6498b68e1f86Smrg      {
6499b68e1f86Smrg        XFREE (str);
6500b68e1f86Smrg      }
6501b68e1f86Smrg#endif
6502b68e1f86Smrg  }
6503b68e1f86Smrg}
65046df26cacSmrg
6505b68e1f86Smrgchar *
6506b68e1f86Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6507b68e1f86Smrg{
6508b68e1f86Smrg  char *new_value;
6509b68e1f86Smrg  if (orig_value && *orig_value)
6510b68e1f86Smrg    {
651125dbecb6Smrg      size_t orig_value_len = strlen (orig_value);
651225dbecb6Smrg      size_t add_len = strlen (add);
6513b68e1f86Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6514b68e1f86Smrg      if (to_end)
6515b68e1f86Smrg        {
6516b68e1f86Smrg          strcpy (new_value, orig_value);
6517b68e1f86Smrg          strcpy (new_value + orig_value_len, add);
6518b68e1f86Smrg        }
6519b68e1f86Smrg      else
6520b68e1f86Smrg        {
6521b68e1f86Smrg          strcpy (new_value, add);
6522b68e1f86Smrg          strcpy (new_value + add_len, orig_value);
6523b68e1f86Smrg        }
6524b68e1f86Smrg    }
6525b68e1f86Smrg  else
6526b68e1f86Smrg    {
6527b68e1f86Smrg      new_value = xstrdup (add);
6528b68e1f86Smrg    }
6529b68e1f86Smrg  return new_value;
6530b68e1f86Smrg}
65316df26cacSmrg
6532b68e1f86Smrgvoid
6533b68e1f86Smrglt_update_exe_path (const char *name, const char *value)
6534b68e1f86Smrg{
65353bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
65363bfa90b6Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
65373bfa90b6Smrg                  nonnull (name), nonnull (value));
65386df26cacSmrg
6539b68e1f86Smrg  if (name && *name && value && *value)
6540b68e1f86Smrg    {
6541b68e1f86Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6542b68e1f86Smrg      /* some systems can't cope with a ':'-terminated path #' */
654325dbecb6Smrg      size_t len = strlen (new_value);
654425dbecb6Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6545b68e1f86Smrg        {
654625dbecb6Smrg          new_value[--len] = '\0';
6547b68e1f86Smrg        }
6548b68e1f86Smrg      lt_setenv (name, new_value);
6549b68e1f86Smrg      XFREE (new_value);
6550b68e1f86Smrg    }
6551b68e1f86Smrg}
65526df26cacSmrg
6553b68e1f86Smrgvoid
6554b68e1f86Smrglt_update_lib_path (const char *name, const char *value)
6555b68e1f86Smrg{
65563bfa90b6Smrg  lt_debugprintf (__FILE__, __LINE__,
65573bfa90b6Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
65583bfa90b6Smrg                  nonnull (name), nonnull (value));
65596df26cacSmrg
6560b68e1f86Smrg  if (name && *name && value && *value)
6561b68e1f86Smrg    {
6562b68e1f86Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6563b68e1f86Smrg      lt_setenv (name, new_value);
6564b68e1f86Smrg      XFREE (new_value);
6565b68e1f86Smrg    }
6566b68e1f86Smrg}
65676df26cacSmrg
65683bfa90b6SmrgEOF
65693bfa90b6Smrg	    case $host_os in
65703bfa90b6Smrg	      mingw*)
65713bfa90b6Smrg		cat <<"EOF"
65723bfa90b6Smrg
65733bfa90b6Smrg/* Prepares an argument vector before calling spawn().
65743bfa90b6Smrg   Note that spawn() does not by itself call the command interpreter
65753bfa90b6Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
65763bfa90b6Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
65773bfa90b6Smrg         GetVersionEx(&v);
65783bfa90b6Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
65793bfa90b6Smrg      }) ? "cmd.exe" : "command.com").
65803bfa90b6Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
65813bfa90b6Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
65823bfa90b6Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
65833bfa90b6Smrg   special way:
65843bfa90b6Smrg   - Space and tab are interpreted as delimiters. They are not treated as
65853bfa90b6Smrg     delimiters if they are surrounded by double quotes: "...".
65863bfa90b6Smrg   - Unescaped double quotes are removed from the input. Their only effect is
65873bfa90b6Smrg     that within double quotes, space and tab are treated like normal
65883bfa90b6Smrg     characters.
65893bfa90b6Smrg   - Backslashes not followed by double quotes are not special.
65903bfa90b6Smrg   - But 2*n+1 backslashes followed by a double quote become
65913bfa90b6Smrg     n backslashes followed by a double quote (n >= 0):
65923bfa90b6Smrg       \" -> "
65933bfa90b6Smrg       \\\" -> \"
65943bfa90b6Smrg       \\\\\" -> \\"
65953bfa90b6Smrg */
65963bfa90b6Smrg#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"
65973bfa90b6Smrg#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"
65983bfa90b6Smrgchar **
65993bfa90b6Smrgprepare_spawn (char **argv)
66003bfa90b6Smrg{
66013bfa90b6Smrg  size_t argc;
66023bfa90b6Smrg  char **new_argv;
66033bfa90b6Smrg  size_t i;
66043bfa90b6Smrg
66053bfa90b6Smrg  /* Count number of arguments.  */
66063bfa90b6Smrg  for (argc = 0; argv[argc] != NULL; argc++)
66073bfa90b6Smrg    ;
66083bfa90b6Smrg
66093bfa90b6Smrg  /* Allocate new argument vector.  */
66103bfa90b6Smrg  new_argv = XMALLOC (char *, argc + 1);
66113bfa90b6Smrg
66123bfa90b6Smrg  /* Put quoted arguments into the new argument vector.  */
66133bfa90b6Smrg  for (i = 0; i < argc; i++)
66143bfa90b6Smrg    {
66153bfa90b6Smrg      const char *string = argv[i];
66163bfa90b6Smrg
66173bfa90b6Smrg      if (string[0] == '\0')
66183bfa90b6Smrg	new_argv[i] = xstrdup ("\"\"");
66193bfa90b6Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
66203bfa90b6Smrg	{
66213bfa90b6Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
66223bfa90b6Smrg	  size_t length;
66233bfa90b6Smrg	  unsigned int backslashes;
66243bfa90b6Smrg	  const char *s;
66253bfa90b6Smrg	  char *quoted_string;
66263bfa90b6Smrg	  char *p;
66273bfa90b6Smrg
66283bfa90b6Smrg	  length = 0;
66293bfa90b6Smrg	  backslashes = 0;
66303bfa90b6Smrg	  if (quote_around)
66313bfa90b6Smrg	    length++;
66323bfa90b6Smrg	  for (s = string; *s != '\0'; s++)
66333bfa90b6Smrg	    {
66343bfa90b6Smrg	      char c = *s;
66353bfa90b6Smrg	      if (c == '"')
66363bfa90b6Smrg		length += backslashes + 1;
66373bfa90b6Smrg	      length++;
66383bfa90b6Smrg	      if (c == '\\')
66393bfa90b6Smrg		backslashes++;
66403bfa90b6Smrg	      else
66413bfa90b6Smrg		backslashes = 0;
66423bfa90b6Smrg	    }
66433bfa90b6Smrg	  if (quote_around)
66443bfa90b6Smrg	    length += backslashes + 1;
66453bfa90b6Smrg
66463bfa90b6Smrg	  quoted_string = XMALLOC (char, length + 1);
66473bfa90b6Smrg
66483bfa90b6Smrg	  p = quoted_string;
66493bfa90b6Smrg	  backslashes = 0;
66503bfa90b6Smrg	  if (quote_around)
66513bfa90b6Smrg	    *p++ = '"';
66523bfa90b6Smrg	  for (s = string; *s != '\0'; s++)
66533bfa90b6Smrg	    {
66543bfa90b6Smrg	      char c = *s;
66553bfa90b6Smrg	      if (c == '"')
66563bfa90b6Smrg		{
66573bfa90b6Smrg		  unsigned int j;
66583bfa90b6Smrg		  for (j = backslashes + 1; j > 0; j--)
66593bfa90b6Smrg		    *p++ = '\\';
66603bfa90b6Smrg		}
66613bfa90b6Smrg	      *p++ = c;
66623bfa90b6Smrg	      if (c == '\\')
66633bfa90b6Smrg		backslashes++;
66643bfa90b6Smrg	      else
66653bfa90b6Smrg		backslashes = 0;
66663bfa90b6Smrg	    }
66673bfa90b6Smrg	  if (quote_around)
66683bfa90b6Smrg	    {
66693bfa90b6Smrg	      unsigned int j;
66703bfa90b6Smrg	      for (j = backslashes; j > 0; j--)
66713bfa90b6Smrg		*p++ = '\\';
66723bfa90b6Smrg	      *p++ = '"';
66733bfa90b6Smrg	    }
66743bfa90b6Smrg	  *p = '\0';
66753bfa90b6Smrg
66763bfa90b6Smrg	  new_argv[i] = quoted_string;
66773bfa90b6Smrg	}
66783bfa90b6Smrg      else
66793bfa90b6Smrg	new_argv[i] = (char *) string;
66803bfa90b6Smrg    }
66813bfa90b6Smrg  new_argv[argc] = NULL;
66823bfa90b6Smrg
66833bfa90b6Smrg  return new_argv;
66843bfa90b6Smrg}
66853bfa90b6SmrgEOF
66863bfa90b6Smrg		;;
66873bfa90b6Smrg	    esac
66886df26cacSmrg
66893bfa90b6Smrg            cat <<"EOF"
66903bfa90b6Smrgvoid lt_dump_script (FILE* f)
66913bfa90b6Smrg{
66923bfa90b6SmrgEOF
66933bfa90b6Smrg	    func_emit_wrapper yes |
66943bfa90b6Smrg	      $SED -n -e '
66953bfa90b6Smrgs/^\(.\{79\}\)\(..*\)/\1\
66963bfa90b6Smrg\2/
66973bfa90b6Smrgh
66983bfa90b6Smrgs/\([\\"]\)/\\\1/g
66993bfa90b6Smrgs/$/\\n/
67003bfa90b6Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
67013bfa90b6Smrgg
67023bfa90b6SmrgD'
67033bfa90b6Smrg            cat <<"EOF"
67043bfa90b6Smrg}
6705b68e1f86SmrgEOF
6706b68e1f86Smrg}
6707b68e1f86Smrg# end: func_emit_cwrapperexe_src
67086df26cacSmrg
67093bfa90b6Smrg# func_win32_import_lib_p ARG
67103bfa90b6Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
67113bfa90b6Smrgfunc_win32_import_lib_p ()
67123bfa90b6Smrg{
671325dbecb6Smrg    $debug_cmd
671425dbecb6Smrg
67153bfa90b6Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
67163bfa90b6Smrg    *import*) : ;;
67173bfa90b6Smrg    *) false ;;
67183bfa90b6Smrg    esac
67193bfa90b6Smrg}
67203bfa90b6Smrg
672125dbecb6Smrg# func_suncc_cstd_abi
672225dbecb6Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
672325dbecb6Smrg# Several compiler flags select an ABI that is incompatible with the
672425dbecb6Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
672525dbecb6Smrgfunc_suncc_cstd_abi ()
672625dbecb6Smrg{
672725dbecb6Smrg    $debug_cmd
672825dbecb6Smrg
672925dbecb6Smrg    case " $compile_command " in
673025dbecb6Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
673125dbecb6Smrg      suncc_use_cstd_abi=no
673225dbecb6Smrg      ;;
673325dbecb6Smrg    *)
673425dbecb6Smrg      suncc_use_cstd_abi=yes
673525dbecb6Smrg      ;;
673625dbecb6Smrg    esac
673725dbecb6Smrg}
673825dbecb6Smrg
6739b68e1f86Smrg# func_mode_link arg...
6740b68e1f86Smrgfunc_mode_link ()
6741b68e1f86Smrg{
674225dbecb6Smrg    $debug_cmd
674325dbecb6Smrg
6744b68e1f86Smrg    case $host in
6745b68e1f86Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6746b68e1f86Smrg      # It is impossible to link a dll without this setting, and
6747b68e1f86Smrg      # we shouldn't force the makefile maintainer to figure out
674825dbecb6Smrg      # what system we are compiling for in order to pass an extra
6749b68e1f86Smrg      # flag for every libtool invocation.
6750b68e1f86Smrg      # allow_undefined=no
67516df26cacSmrg
6752b68e1f86Smrg      # FIXME: Unfortunately, there are problems with the above when trying
675325dbecb6Smrg      # to make a dll that has undefined symbols, in which case not
6754b68e1f86Smrg      # even a static library is built.  For now, we need to specify
6755b68e1f86Smrg      # -no-undefined on the libtool link line when we can be certain
6756b68e1f86Smrg      # that all symbols are satisfied, otherwise we get a static library.
6757b68e1f86Smrg      allow_undefined=yes
67586df26cacSmrg      ;;
6759b68e1f86Smrg    *)
6760b68e1f86Smrg      allow_undefined=yes
6761b68e1f86Smrg      ;;
6762b68e1f86Smrg    esac
6763b68e1f86Smrg    libtool_args=$nonopt
6764b68e1f86Smrg    base_compile="$nonopt $@"
6765b68e1f86Smrg    compile_command=$nonopt
6766b68e1f86Smrg    finalize_command=$nonopt
67676df26cacSmrg
6768b68e1f86Smrg    compile_rpath=
6769b68e1f86Smrg    finalize_rpath=
6770b68e1f86Smrg    compile_shlibpath=
6771b68e1f86Smrg    finalize_shlibpath=
6772b68e1f86Smrg    convenience=
6773b68e1f86Smrg    old_convenience=
6774b68e1f86Smrg    deplibs=
6775b68e1f86Smrg    old_deplibs=
6776b68e1f86Smrg    compiler_flags=
6777b68e1f86Smrg    linker_flags=
6778b68e1f86Smrg    dllsearchpath=
6779b68e1f86Smrg    lib_search_path=`pwd`
6780b68e1f86Smrg    inst_prefix_dir=
6781b68e1f86Smrg    new_inherited_linker_flags=
67826df26cacSmrg
6783b68e1f86Smrg    avoid_version=no
67843bfa90b6Smrg    bindir=
6785b68e1f86Smrg    dlfiles=
6786b68e1f86Smrg    dlprefiles=
6787b68e1f86Smrg    dlself=no
6788b68e1f86Smrg    export_dynamic=no
6789b68e1f86Smrg    export_symbols=
6790b68e1f86Smrg    export_symbols_regex=
6791b68e1f86Smrg    generated=
6792b68e1f86Smrg    libobjs=
6793b68e1f86Smrg    ltlibs=
6794b68e1f86Smrg    module=no
6795b68e1f86Smrg    no_install=no
6796b68e1f86Smrg    objs=
679725dbecb6Smrg    os2dllname=
6798b68e1f86Smrg    non_pic_objects=
6799b68e1f86Smrg    precious_files_regex=
6800b68e1f86Smrg    prefer_static_libs=no
680125dbecb6Smrg    preload=false
6802b68e1f86Smrg    prev=
6803b68e1f86Smrg    prevarg=
6804b68e1f86Smrg    release=
6805b68e1f86Smrg    rpath=
6806b68e1f86Smrg    xrpath=
6807b68e1f86Smrg    perm_rpath=
6808b68e1f86Smrg    temp_rpath=
6809b68e1f86Smrg    thread_safe=no
6810b68e1f86Smrg    vinfo=
6811b68e1f86Smrg    vinfo_number=no
6812b68e1f86Smrg    weak_libs=
681325dbecb6Smrg    single_module=$wl-single_module
6814b68e1f86Smrg    func_infer_tag $base_compile
68156df26cacSmrg
6816b68e1f86Smrg    # We need to know -static, to get the right output filenames.
6817b68e1f86Smrg    for arg
6818b68e1f86Smrg    do
6819b68e1f86Smrg      case $arg in
6820b68e1f86Smrg      -shared)
682125dbecb6Smrg	test yes != "$build_libtool_libs" \
682225dbecb6Smrg	  && func_fatal_configuration "cannot build a shared library"
6823b68e1f86Smrg	build_old_libs=no
6824b68e1f86Smrg	break
6825b68e1f86Smrg	;;
6826b68e1f86Smrg      -all-static | -static | -static-libtool-libs)
6827b68e1f86Smrg	case $arg in
6828b68e1f86Smrg	-all-static)
682925dbecb6Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6830b68e1f86Smrg	    func_warning "complete static linking is impossible in this configuration"
6831b68e1f86Smrg	  fi
6832b68e1f86Smrg	  if test -n "$link_static_flag"; then
6833b68e1f86Smrg	    dlopen_self=$dlopen_self_static
6834b68e1f86Smrg	  fi
6835b68e1f86Smrg	  prefer_static_libs=yes
6836b68e1f86Smrg	  ;;
6837b68e1f86Smrg	-static)
6838b68e1f86Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6839b68e1f86Smrg	    dlopen_self=$dlopen_self_static
6840b68e1f86Smrg	  fi
6841b68e1f86Smrg	  prefer_static_libs=built
6842b68e1f86Smrg	  ;;
6843b68e1f86Smrg	-static-libtool-libs)
6844b68e1f86Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6845b68e1f86Smrg	    dlopen_self=$dlopen_self_static
6846b68e1f86Smrg	  fi
6847b68e1f86Smrg	  prefer_static_libs=yes
6848b68e1f86Smrg	  ;;
6849b68e1f86Smrg	esac
6850b68e1f86Smrg	build_libtool_libs=no
6851b68e1f86Smrg	build_old_libs=yes
6852b68e1f86Smrg	break
68536df26cacSmrg	;;
68546df26cacSmrg      esac
6855b68e1f86Smrg    done
68566df26cacSmrg
6857b68e1f86Smrg    # See if our shared archives depend on static archives.
6858b68e1f86Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
68596df26cacSmrg
6860b68e1f86Smrg    # Go through the arguments, transforming them on the way.
6861b68e1f86Smrg    while test "$#" -gt 0; do
686225dbecb6Smrg      arg=$1
6863b68e1f86Smrg      shift
686425dbecb6Smrg      func_quote_arg pretty,unquoted "$arg"
686525dbecb6Smrg      qarg=$func_quote_arg_unquoted_result
686625dbecb6Smrg      func_append libtool_args " $func_quote_arg_result"
68676df26cacSmrg
6868b68e1f86Smrg      # If the previous option needs an argument, assign it.
6869b68e1f86Smrg      if test -n "$prev"; then
6870b68e1f86Smrg	case $prev in
6871b68e1f86Smrg	output)
6872b68e1f86Smrg	  func_append compile_command " @OUTPUT@"
6873b68e1f86Smrg	  func_append finalize_command " @OUTPUT@"
68746df26cacSmrg	  ;;
68756df26cacSmrg	esac
68766df26cacSmrg
6877b68e1f86Smrg	case $prev in
68783bfa90b6Smrg	bindir)
687925dbecb6Smrg	  bindir=$arg
68803bfa90b6Smrg	  prev=
68813bfa90b6Smrg	  continue
68823bfa90b6Smrg	  ;;
6883b68e1f86Smrg	dlfiles|dlprefiles)
688425dbecb6Smrg	  $preload || {
6885b68e1f86Smrg	    # Add the symbol object into the linking commands.
6886b68e1f86Smrg	    func_append compile_command " @SYMFILE@"
6887b68e1f86Smrg	    func_append finalize_command " @SYMFILE@"
688825dbecb6Smrg	    preload=:
688925dbecb6Smrg	  }
6890b68e1f86Smrg	  case $arg in
6891b68e1f86Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6892b68e1f86Smrg	  force)
689325dbecb6Smrg	    if test no = "$dlself"; then
6894b68e1f86Smrg	      dlself=needless
6895b68e1f86Smrg	      export_dynamic=yes
6896b68e1f86Smrg	    fi
6897b68e1f86Smrg	    prev=
6898b68e1f86Smrg	    continue
6899b68e1f86Smrg	    ;;
6900b68e1f86Smrg	  self)
690125dbecb6Smrg	    if test dlprefiles = "$prev"; then
6902b68e1f86Smrg	      dlself=yes
690325dbecb6Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6904b68e1f86Smrg	      dlself=yes
69056df26cacSmrg	    else
6906b68e1f86Smrg	      dlself=needless
6907b68e1f86Smrg	      export_dynamic=yes
69086df26cacSmrg	    fi
6909b68e1f86Smrg	    prev=
6910b68e1f86Smrg	    continue
6911b68e1f86Smrg	    ;;
6912b68e1f86Smrg	  *)
691325dbecb6Smrg	    if test dlfiles = "$prev"; then
69143bfa90b6Smrg	      func_append dlfiles " $arg"
6915b68e1f86Smrg	    else
69163bfa90b6Smrg	      func_append dlprefiles " $arg"
6917b68e1f86Smrg	    fi
6918b68e1f86Smrg	    prev=
6919b68e1f86Smrg	    continue
6920b68e1f86Smrg	    ;;
69216df26cacSmrg	  esac
69226df26cacSmrg	  ;;
6923b68e1f86Smrg	expsyms)
692425dbecb6Smrg	  export_symbols=$arg
6925b68e1f86Smrg	  test -f "$arg" \
692625dbecb6Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
6927b68e1f86Smrg	  prev=
6928b68e1f86Smrg	  continue
6929b68e1f86Smrg	  ;;
6930b68e1f86Smrg	expsyms_regex)
693125dbecb6Smrg	  export_symbols_regex=$arg
6932b68e1f86Smrg	  prev=
6933b68e1f86Smrg	  continue
6934b68e1f86Smrg	  ;;
6935b68e1f86Smrg	framework)
6936b68e1f86Smrg	  case $host in
6937b68e1f86Smrg	    *-*-darwin*)
6938b68e1f86Smrg	      case "$deplibs " in
6939b68e1f86Smrg		*" $qarg.ltframework "*) ;;
69403bfa90b6Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6941b68e1f86Smrg		   ;;
69426df26cacSmrg	      esac
6943b68e1f86Smrg	      ;;
69446df26cacSmrg	  esac
6945b68e1f86Smrg	  prev=
6946b68e1f86Smrg	  continue
6947b68e1f86Smrg	  ;;
6948b68e1f86Smrg	inst_prefix)
694925dbecb6Smrg	  inst_prefix_dir=$arg
695025dbecb6Smrg	  prev=
695125dbecb6Smrg	  continue
695225dbecb6Smrg	  ;;
695325dbecb6Smrg	mllvm)
695425dbecb6Smrg	  # Clang does not use LLVM to link, so we can simply discard any
695525dbecb6Smrg	  # '-mllvm $arg' options when doing the link step.
6956b68e1f86Smrg	  prev=
6957b68e1f86Smrg	  continue
6958b68e1f86Smrg	  ;;
6959b68e1f86Smrg	objectlist)
6960b68e1f86Smrg	  if test -f "$arg"; then
6961b68e1f86Smrg	    save_arg=$arg
6962b68e1f86Smrg	    moreargs=
6963b68e1f86Smrg	    for fil in `cat "$save_arg"`
6964b68e1f86Smrg	    do
69653bfa90b6Smrg#	      func_append moreargs " $fil"
6966b68e1f86Smrg	      arg=$fil
6967b68e1f86Smrg	      # A libtool-controlled object.
69686df26cacSmrg
6969b68e1f86Smrg	      # Check to see that this really is a libtool object.
6970b68e1f86Smrg	      if func_lalib_unsafe_p "$arg"; then
6971b68e1f86Smrg		pic_object=
6972b68e1f86Smrg		non_pic_object=
69736df26cacSmrg
6974b68e1f86Smrg		# Read the .lo file
6975b68e1f86Smrg		func_source "$arg"
69766df26cacSmrg
6977b68e1f86Smrg		if test -z "$pic_object" ||
6978b68e1f86Smrg		   test -z "$non_pic_object" ||
697925dbecb6Smrg		   test none = "$pic_object" &&
698025dbecb6Smrg		   test none = "$non_pic_object"; then
698125dbecb6Smrg		  func_fatal_error "cannot find name of object for '$arg'"
6982b68e1f86Smrg		fi
69836df26cacSmrg
6984b68e1f86Smrg		# Extract subdirectory from the argument.
6985b68e1f86Smrg		func_dirname "$arg" "/" ""
698625dbecb6Smrg		xdir=$func_dirname_result
69876df26cacSmrg
698825dbecb6Smrg		if test none != "$pic_object"; then
6989b68e1f86Smrg		  # Prepend the subdirectory the object is found in.
699025dbecb6Smrg		  pic_object=$xdir$pic_object
69916df26cacSmrg
699225dbecb6Smrg		  if test dlfiles = "$prev"; then
699325dbecb6Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
69943bfa90b6Smrg		      func_append dlfiles " $pic_object"
6995b68e1f86Smrg		      prev=
6996b68e1f86Smrg		      continue
6997b68e1f86Smrg		    else
6998b68e1f86Smrg		      # If libtool objects are unsupported, then we need to preload.
6999b68e1f86Smrg		      prev=dlprefiles
7000b68e1f86Smrg		    fi
7001b68e1f86Smrg		  fi
70026df26cacSmrg
7003b68e1f86Smrg		  # CHECK ME:  I think I busted this.  -Ossama
700425dbecb6Smrg		  if test dlprefiles = "$prev"; then
7005b68e1f86Smrg		    # Preload the old-style object.
70063bfa90b6Smrg		    func_append dlprefiles " $pic_object"
7007b68e1f86Smrg		    prev=
7008b68e1f86Smrg		  fi
70096df26cacSmrg
7010b68e1f86Smrg		  # A PIC object.
7011b68e1f86Smrg		  func_append libobjs " $pic_object"
701225dbecb6Smrg		  arg=$pic_object
7013b68e1f86Smrg		fi
70146df26cacSmrg
7015b68e1f86Smrg		# Non-PIC object.
701625dbecb6Smrg		if test none != "$non_pic_object"; then
7017b68e1f86Smrg		  # Prepend the subdirectory the object is found in.
701825dbecb6Smrg		  non_pic_object=$xdir$non_pic_object
70196df26cacSmrg
7020b68e1f86Smrg		  # A standard non-PIC object
7021b68e1f86Smrg		  func_append non_pic_objects " $non_pic_object"
702225dbecb6Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
702325dbecb6Smrg		    arg=$non_pic_object
7024b68e1f86Smrg		  fi
7025b68e1f86Smrg		else
7026b68e1f86Smrg		  # If the PIC object exists, use it instead.
7027b68e1f86Smrg		  # $xdir was prepended to $pic_object above.
702825dbecb6Smrg		  non_pic_object=$pic_object
7029b68e1f86Smrg		  func_append non_pic_objects " $non_pic_object"
7030b68e1f86Smrg		fi
7031b68e1f86Smrg	      else
7032b68e1f86Smrg		# Only an error if not doing a dry-run.
7033b68e1f86Smrg		if $opt_dry_run; then
7034b68e1f86Smrg		  # Extract subdirectory from the argument.
7035b68e1f86Smrg		  func_dirname "$arg" "/" ""
703625dbecb6Smrg		  xdir=$func_dirname_result
7037b68e1f86Smrg
7038b68e1f86Smrg		  func_lo2o "$arg"
7039b68e1f86Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7040b68e1f86Smrg		  non_pic_object=$xdir$func_lo2o_result
7041b68e1f86Smrg		  func_append libobjs " $pic_object"
7042b68e1f86Smrg		  func_append non_pic_objects " $non_pic_object"
7043b68e1f86Smrg	        else
704425dbecb6Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
7045b68e1f86Smrg		fi
7046b68e1f86Smrg	      fi
70476df26cacSmrg	    done
7048b68e1f86Smrg	  else
704925dbecb6Smrg	    func_fatal_error "link input file '$arg' does not exist"
70506df26cacSmrg	  fi
7051b68e1f86Smrg	  arg=$save_arg
7052b68e1f86Smrg	  prev=
7053b68e1f86Smrg	  continue
7054b68e1f86Smrg	  ;;
705525dbecb6Smrg	os2dllname)
705625dbecb6Smrg	  os2dllname=$arg
705725dbecb6Smrg	  prev=
705825dbecb6Smrg	  continue
705925dbecb6Smrg	  ;;
7060b68e1f86Smrg	precious_regex)
706125dbecb6Smrg	  precious_files_regex=$arg
7062b68e1f86Smrg	  prev=
7063b68e1f86Smrg	  continue
7064b68e1f86Smrg	  ;;
7065b68e1f86Smrg	release)
706625dbecb6Smrg	  release=-$arg
7067b68e1f86Smrg	  prev=
7068b68e1f86Smrg	  continue
7069b68e1f86Smrg	  ;;
7070b68e1f86Smrg	rpath | xrpath)
7071b68e1f86Smrg	  # We need an absolute path.
7072b68e1f86Smrg	  case $arg in
7073b68e1f86Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7074b68e1f86Smrg	  *)
7075b68e1f86Smrg	    func_fatal_error "only absolute run-paths are allowed"
7076b68e1f86Smrg	    ;;
70776df26cacSmrg	  esac
707825dbecb6Smrg	  if test rpath = "$prev"; then
7079b68e1f86Smrg	    case "$rpath " in
7080b68e1f86Smrg	    *" $arg "*) ;;
70813bfa90b6Smrg	    *) func_append rpath " $arg" ;;
7082b68e1f86Smrg	    esac
7083b68e1f86Smrg	  else
7084b68e1f86Smrg	    case "$xrpath " in
7085b68e1f86Smrg	    *" $arg "*) ;;
70863bfa90b6Smrg	    *) func_append xrpath " $arg" ;;
7087b68e1f86Smrg	    esac
7088b68e1f86Smrg	  fi
7089b68e1f86Smrg	  prev=
7090b68e1f86Smrg	  continue
7091b68e1f86Smrg	  ;;
7092b68e1f86Smrg	shrext)
709325dbecb6Smrg	  shrext_cmds=$arg
7094b68e1f86Smrg	  prev=
7095b68e1f86Smrg	  continue
7096b68e1f86Smrg	  ;;
7097b68e1f86Smrg	weak)
70983bfa90b6Smrg	  func_append weak_libs " $arg"
7099b68e1f86Smrg	  prev=
7100b68e1f86Smrg	  continue
7101b68e1f86Smrg	  ;;
710225dbecb6Smrg	xassembler)
710325dbecb6Smrg	  func_append compiler_flags " -Xassembler $qarg"
710425dbecb6Smrg	  prev=
710525dbecb6Smrg	  func_append compile_command " -Xassembler $qarg"
710625dbecb6Smrg	  func_append finalize_command " -Xassembler $qarg"
710725dbecb6Smrg	  continue
710825dbecb6Smrg	  ;;
7109b68e1f86Smrg	xcclinker)
71103bfa90b6Smrg	  func_append linker_flags " $qarg"
71113bfa90b6Smrg	  func_append compiler_flags " $qarg"
7112b68e1f86Smrg	  prev=
7113b68e1f86Smrg	  func_append compile_command " $qarg"
7114b68e1f86Smrg	  func_append finalize_command " $qarg"
7115b68e1f86Smrg	  continue
7116b68e1f86Smrg	  ;;
7117b68e1f86Smrg	xcompiler)
71183bfa90b6Smrg	  func_append compiler_flags " $qarg"
7119b68e1f86Smrg	  prev=
7120b68e1f86Smrg	  func_append compile_command " $qarg"
7121b68e1f86Smrg	  func_append finalize_command " $qarg"
7122b68e1f86Smrg	  continue
7123b68e1f86Smrg	  ;;
7124b68e1f86Smrg	xlinker)
71253bfa90b6Smrg	  func_append linker_flags " $qarg"
71263bfa90b6Smrg	  func_append compiler_flags " $wl$qarg"
7127b68e1f86Smrg	  prev=
7128b68e1f86Smrg	  func_append compile_command " $wl$qarg"
7129b68e1f86Smrg	  func_append finalize_command " $wl$qarg"
7130b68e1f86Smrg	  continue
71316df26cacSmrg	  ;;
71326df26cacSmrg	*)
7133b68e1f86Smrg	  eval "$prev=\"\$arg\""
7134b68e1f86Smrg	  prev=
7135b68e1f86Smrg	  continue
71366df26cacSmrg	  ;;
71376df26cacSmrg	esac
7138b68e1f86Smrg      fi # test -n "$prev"
71396df26cacSmrg
714025dbecb6Smrg      prevarg=$arg
71416df26cacSmrg
7142b68e1f86Smrg      case $arg in
7143b68e1f86Smrg      -all-static)
7144b68e1f86Smrg	if test -n "$link_static_flag"; then
7145b68e1f86Smrg	  # See comment for -static flag below, for more details.
7146b68e1f86Smrg	  func_append compile_command " $link_static_flag"
7147b68e1f86Smrg	  func_append finalize_command " $link_static_flag"
71486df26cacSmrg	fi
7149b68e1f86Smrg	continue
7150b68e1f86Smrg	;;
71516df26cacSmrg
7152b68e1f86Smrg      -allow-undefined)
7153b68e1f86Smrg	# FIXME: remove this flag sometime in the future.
715425dbecb6Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7155b68e1f86Smrg	;;
71566df26cacSmrg
7157b68e1f86Smrg      -avoid-version)
7158b68e1f86Smrg	avoid_version=yes
7159b68e1f86Smrg	continue
7160b68e1f86Smrg	;;
71616df26cacSmrg
71623bfa90b6Smrg      -bindir)
71633bfa90b6Smrg	prev=bindir
71643bfa90b6Smrg	continue
71653bfa90b6Smrg	;;
71663bfa90b6Smrg
7167b68e1f86Smrg      -dlopen)
7168b68e1f86Smrg	prev=dlfiles
7169b68e1f86Smrg	continue
7170b68e1f86Smrg	;;
71716df26cacSmrg
7172b68e1f86Smrg      -dlpreopen)
7173b68e1f86Smrg	prev=dlprefiles
7174b68e1f86Smrg	continue
7175b68e1f86Smrg	;;
71766df26cacSmrg
7177b68e1f86Smrg      -export-dynamic)
7178b68e1f86Smrg	export_dynamic=yes
7179b68e1f86Smrg	continue
7180b68e1f86Smrg	;;
71816df26cacSmrg
7182b68e1f86Smrg      -export-symbols | -export-symbols-regex)
7183b68e1f86Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7184b68e1f86Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7185b68e1f86Smrg	fi
718625dbecb6Smrg	if test X-export-symbols = "X$arg"; then
7187b68e1f86Smrg	  prev=expsyms
71886df26cacSmrg	else
7189b68e1f86Smrg	  prev=expsyms_regex
71906df26cacSmrg	fi
7191b68e1f86Smrg	continue
7192b68e1f86Smrg	;;
71936df26cacSmrg
7194b68e1f86Smrg      -framework)
7195b68e1f86Smrg	prev=framework
7196b68e1f86Smrg	continue
7197b68e1f86Smrg	;;
71986df26cacSmrg
7199b68e1f86Smrg      -inst-prefix-dir)
7200b68e1f86Smrg	prev=inst_prefix
7201b68e1f86Smrg	continue
7202b68e1f86Smrg	;;
72036df26cacSmrg
7204b68e1f86Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7205b68e1f86Smrg      # so, if we see these flags be careful not to treat them like -L
7206b68e1f86Smrg      -L[A-Z][A-Z]*:*)
7207b68e1f86Smrg	case $with_gcc/$host in
7208b68e1f86Smrg	no/*-*-irix* | /*-*-irix*)
7209b68e1f86Smrg	  func_append compile_command " $arg"
7210b68e1f86Smrg	  func_append finalize_command " $arg"
7211b68e1f86Smrg	  ;;
7212b68e1f86Smrg	esac
7213b68e1f86Smrg	continue
7214b68e1f86Smrg	;;
72156df26cacSmrg
7216b68e1f86Smrg      -L*)
72173bfa90b6Smrg	func_stripname "-L" '' "$arg"
72183bfa90b6Smrg	if test -z "$func_stripname_result"; then
7219b68e1f86Smrg	  if test "$#" -gt 0; then
722025dbecb6Smrg	    func_fatal_error "require no space between '-L' and '$1'"
72216df26cacSmrg	  else
722225dbecb6Smrg	    func_fatal_error "need path for '-L' option"
72236df26cacSmrg	  fi
7224b68e1f86Smrg	fi
72253bfa90b6Smrg	func_resolve_sysroot "$func_stripname_result"
72263bfa90b6Smrg	dir=$func_resolve_sysroot_result
7227b68e1f86Smrg	# We need an absolute path.
7228b68e1f86Smrg	case $dir in
7229b68e1f86Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7230b68e1f86Smrg	*)
7231b68e1f86Smrg	  absdir=`cd "$dir" && pwd`
7232b68e1f86Smrg	  test -z "$absdir" && \
723325dbecb6Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
723425dbecb6Smrg	  dir=$absdir
7235b68e1f86Smrg	  ;;
72366df26cacSmrg	esac
7237b68e1f86Smrg	case "$deplibs " in
72383bfa90b6Smrg	*" -L$dir "* | *" $arg "*)
72393bfa90b6Smrg	  # Will only happen for absolute or sysroot arguments
72403bfa90b6Smrg	  ;;
7241b68e1f86Smrg	*)
72423bfa90b6Smrg	  # Preserve sysroot, but never include relative directories
72433bfa90b6Smrg	  case $dir in
72443bfa90b6Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
72453bfa90b6Smrg	    *) func_append deplibs " -L$dir" ;;
72463bfa90b6Smrg	  esac
72473bfa90b6Smrg	  func_append lib_search_path " $dir"
7248b68e1f86Smrg	  ;;
72496df26cacSmrg	esac
72506df26cacSmrg	case $host in
7251b68e1f86Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
72523bfa90b6Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7253b68e1f86Smrg	  case :$dllsearchpath: in
7254b68e1f86Smrg	  *":$dir:"*) ;;
7255b68e1f86Smrg	  ::) dllsearchpath=$dir;;
72563bfa90b6Smrg	  *) func_append dllsearchpath ":$dir";;
7257b68e1f86Smrg	  esac
7258b68e1f86Smrg	  case :$dllsearchpath: in
7259b68e1f86Smrg	  *":$testbindir:"*) ;;
7260b68e1f86Smrg	  ::) dllsearchpath=$testbindir;;
72613bfa90b6Smrg	  *) func_append dllsearchpath ":$testbindir";;
7262b68e1f86Smrg	  esac
7263b68e1f86Smrg	  ;;
72646df26cacSmrg	esac
7265b68e1f86Smrg	continue
7266b68e1f86Smrg	;;
72676df26cacSmrg
7268b68e1f86Smrg      -l*)
726925dbecb6Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7270b68e1f86Smrg	  case $host in
72713bfa90b6Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7272b68e1f86Smrg	    # These systems don't actually have a C or math library (as such)
7273b68e1f86Smrg	    continue
7274b68e1f86Smrg	    ;;
7275b68e1f86Smrg	  *-*-os2*)
7276b68e1f86Smrg	    # These systems don't actually have a C library (as such)
727725dbecb6Smrg	    test X-lc = "X$arg" && continue
7278b68e1f86Smrg	    ;;
727925dbecb6Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7280b68e1f86Smrg	    # Do not include libc due to us having libc/libc_r.
728125dbecb6Smrg	    test X-lc = "X$arg" && continue
7282b68e1f86Smrg	    ;;
7283b68e1f86Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7284b68e1f86Smrg	    # Rhapsody C and math libraries are in the System framework
72853bfa90b6Smrg	    func_append deplibs " System.ltframework"
7286b68e1f86Smrg	    continue
7287b68e1f86Smrg	    ;;
7288b68e1f86Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7289b68e1f86Smrg	    # Causes problems with __ctype
729025dbecb6Smrg	    test X-lc = "X$arg" && continue
7291b68e1f86Smrg	    ;;
7292b68e1f86Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7293b68e1f86Smrg	    # Compiler inserts libc in the correct place for threads to work
729425dbecb6Smrg	    test X-lc = "X$arg" && continue
7295b68e1f86Smrg	    ;;
7296b68e1f86Smrg	  esac
729725dbecb6Smrg	elif test X-lc_r = "X$arg"; then
7298b68e1f86Smrg	 case $host in
729925dbecb6Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7300b68e1f86Smrg	   # Do not include libc_r directly, use -pthread flag.
7301b68e1f86Smrg	   continue
7302b68e1f86Smrg	   ;;
7303b68e1f86Smrg	 esac
7304b68e1f86Smrg	fi
73053bfa90b6Smrg	func_append deplibs " $arg"
7306b68e1f86Smrg	continue
7307b68e1f86Smrg	;;
73086df26cacSmrg
730925dbecb6Smrg      -mllvm)
731025dbecb6Smrg	prev=mllvm
731125dbecb6Smrg	continue
731225dbecb6Smrg	;;
731325dbecb6Smrg
7314b68e1f86Smrg      -module)
7315b68e1f86Smrg	module=yes
7316b68e1f86Smrg	continue
7317b68e1f86Smrg	;;
73186df26cacSmrg
7319b68e1f86Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7320b68e1f86Smrg      # classes, name mangling, and exception handling.
7321b68e1f86Smrg      # Darwin uses the -arch flag to determine output architecture.
73223bfa90b6Smrg      -model|-arch|-isysroot|--sysroot)
73233bfa90b6Smrg	func_append compiler_flags " $arg"
7324b68e1f86Smrg	func_append compile_command " $arg"
7325b68e1f86Smrg	func_append finalize_command " $arg"
7326b68e1f86Smrg	prev=xcompiler
7327b68e1f86Smrg	continue
7328b68e1f86Smrg	;;
732925dbecb6Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
733025dbecb6Smrg     -pthread)
733125dbecb6Smrg	case $host in
733225dbecb6Smrg	  *solaris2*) ;;
733325dbecb6Smrg	  *)
733425dbecb6Smrg	    case "$new_inherited_linker_flags " in
733525dbecb6Smrg	        *" $arg "*) ;;
733625dbecb6Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
733725dbecb6Smrg	    esac
733825dbecb6Smrg	  ;;
733925dbecb6Smrg	esac
734025dbecb6Smrg	continue
734125dbecb6Smrg	;;
734225dbecb6Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
73433bfa90b6Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
73443bfa90b6Smrg	func_append compiler_flags " $arg"
7345b68e1f86Smrg	func_append compile_command " $arg"
7346b68e1f86Smrg	func_append finalize_command " $arg"
7347b68e1f86Smrg	case "$new_inherited_linker_flags " in
7348b68e1f86Smrg	    *" $arg "*) ;;
73493bfa90b6Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7350b68e1f86Smrg	esac
7351b68e1f86Smrg	continue
7352b68e1f86Smrg	;;
73536df26cacSmrg
7354b68e1f86Smrg      -multi_module)
735525dbecb6Smrg	single_module=$wl-multi_module
7356b68e1f86Smrg	continue
7357b68e1f86Smrg	;;
73586df26cacSmrg
7359b68e1f86Smrg      -no-fast-install)
7360b68e1f86Smrg	fast_install=no
7361b68e1f86Smrg	continue
7362b68e1f86Smrg	;;
73636df26cacSmrg
7364b68e1f86Smrg      -no-install)
7365b68e1f86Smrg	case $host in
7366b68e1f86Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7367b68e1f86Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7368b68e1f86Smrg	  # and Darwin in order for the loader to find any dlls it needs.
736925dbecb6Smrg	  func_warning "'-no-install' is ignored for $host"
737025dbecb6Smrg	  func_warning "assuming '-no-fast-install' instead"
7371b68e1f86Smrg	  fast_install=no
7372b68e1f86Smrg	  ;;
7373b68e1f86Smrg	*) no_install=yes ;;
7374b68e1f86Smrg	esac
7375b68e1f86Smrg	continue
7376b68e1f86Smrg	;;
73776df26cacSmrg
7378b68e1f86Smrg      -no-undefined)
7379b68e1f86Smrg	allow_undefined=no
7380b68e1f86Smrg	continue
7381b68e1f86Smrg	;;
73826df26cacSmrg
7383b68e1f86Smrg      -objectlist)
7384b68e1f86Smrg	prev=objectlist
7385b68e1f86Smrg	continue
7386b68e1f86Smrg	;;
73876df26cacSmrg
738825dbecb6Smrg      -os2dllname)
738925dbecb6Smrg	prev=os2dllname
739025dbecb6Smrg	continue
739125dbecb6Smrg	;;
739225dbecb6Smrg
7393b68e1f86Smrg      -o) prev=output ;;
73946df26cacSmrg
7395b68e1f86Smrg      -precious-files-regex)
7396b68e1f86Smrg	prev=precious_regex
7397b68e1f86Smrg	continue
7398b68e1f86Smrg	;;
73996df26cacSmrg
7400b68e1f86Smrg      -release)
7401b68e1f86Smrg	prev=release
7402b68e1f86Smrg	continue
7403b68e1f86Smrg	;;
74046df26cacSmrg
7405b68e1f86Smrg      -rpath)
7406b68e1f86Smrg	prev=rpath
7407b68e1f86Smrg	continue
7408b68e1f86Smrg	;;
74096df26cacSmrg
7410b68e1f86Smrg      -R)
7411b68e1f86Smrg	prev=xrpath
7412b68e1f86Smrg	continue
7413b68e1f86Smrg	;;
74146df26cacSmrg
7415b68e1f86Smrg      -R*)
7416b68e1f86Smrg	func_stripname '-R' '' "$arg"
7417b68e1f86Smrg	dir=$func_stripname_result
7418b68e1f86Smrg	# We need an absolute path.
7419b68e1f86Smrg	case $dir in
7420b68e1f86Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
74213bfa90b6Smrg	=*)
74223bfa90b6Smrg	  func_stripname '=' '' "$dir"
74233bfa90b6Smrg	  dir=$lt_sysroot$func_stripname_result
74243bfa90b6Smrg	  ;;
7425b68e1f86Smrg	*)
7426b68e1f86Smrg	  func_fatal_error "only absolute run-paths are allowed"
7427b68e1f86Smrg	  ;;
7428b68e1f86Smrg	esac
7429b68e1f86Smrg	case "$xrpath " in
7430b68e1f86Smrg	*" $dir "*) ;;
74313bfa90b6Smrg	*) func_append xrpath " $dir" ;;
7432b68e1f86Smrg	esac
7433b68e1f86Smrg	continue
7434b68e1f86Smrg	;;
74356df26cacSmrg
7436b68e1f86Smrg      -shared)
7437b68e1f86Smrg	# The effects of -shared are defined in a previous loop.
7438b68e1f86Smrg	continue
7439b68e1f86Smrg	;;
74406df26cacSmrg
7441b68e1f86Smrg      -shrext)
7442b68e1f86Smrg	prev=shrext
7443b68e1f86Smrg	continue
7444b68e1f86Smrg	;;
74456df26cacSmrg
7446b68e1f86Smrg      -static | -static-libtool-libs)
7447b68e1f86Smrg	# The effects of -static are defined in a previous loop.
7448b68e1f86Smrg	# We used to do the same as -all-static on platforms that
7449b68e1f86Smrg	# didn't have a PIC flag, but the assumption that the effects
7450b68e1f86Smrg	# would be equivalent was wrong.  It would break on at least
7451b68e1f86Smrg	# Digital Unix and AIX.
7452b68e1f86Smrg	continue
7453b68e1f86Smrg	;;
74546df26cacSmrg
7455b68e1f86Smrg      -thread-safe)
7456b68e1f86Smrg	thread_safe=yes
7457b68e1f86Smrg	continue
7458b68e1f86Smrg	;;
74596df26cacSmrg
7460b68e1f86Smrg      -version-info)
7461b68e1f86Smrg	prev=vinfo
7462b68e1f86Smrg	continue
7463b68e1f86Smrg	;;
74646df26cacSmrg
7465b68e1f86Smrg      -version-number)
7466b68e1f86Smrg	prev=vinfo
7467b68e1f86Smrg	vinfo_number=yes
7468b68e1f86Smrg	continue
7469b68e1f86Smrg	;;
74706df26cacSmrg
7471b68e1f86Smrg      -weak)
7472b68e1f86Smrg        prev=weak
7473b68e1f86Smrg	continue
7474b68e1f86Smrg	;;
74756df26cacSmrg
7476b68e1f86Smrg      -Wc,*)
7477b68e1f86Smrg	func_stripname '-Wc,' '' "$arg"
7478b68e1f86Smrg	args=$func_stripname_result
7479b68e1f86Smrg	arg=
748025dbecb6Smrg	save_ifs=$IFS; IFS=,
7481b68e1f86Smrg	for flag in $args; do
748225dbecb6Smrg	  IFS=$save_ifs
748325dbecb6Smrg          func_quote_arg pretty "$flag"
748425dbecb6Smrg	  func_append arg " $func_quote_arg_result"
748525dbecb6Smrg	  func_append compiler_flags " $func_quote_arg_result"
7486b68e1f86Smrg	done
748725dbecb6Smrg	IFS=$save_ifs
7488b68e1f86Smrg	func_stripname ' ' '' "$arg"
7489b68e1f86Smrg	arg=$func_stripname_result
7490b68e1f86Smrg	;;
74916df26cacSmrg
7492b68e1f86Smrg      -Wl,*)
7493b68e1f86Smrg	func_stripname '-Wl,' '' "$arg"
7494b68e1f86Smrg	args=$func_stripname_result
7495b68e1f86Smrg	arg=
749625dbecb6Smrg	save_ifs=$IFS; IFS=,
7497b68e1f86Smrg	for flag in $args; do
749825dbecb6Smrg	  IFS=$save_ifs
749925dbecb6Smrg          func_quote_arg pretty "$flag"
750025dbecb6Smrg	  func_append arg " $wl$func_quote_arg_result"
750125dbecb6Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
750225dbecb6Smrg	  func_append linker_flags " $func_quote_arg_result"
7503b68e1f86Smrg	done
750425dbecb6Smrg	IFS=$save_ifs
7505b68e1f86Smrg	func_stripname ' ' '' "$arg"
7506b68e1f86Smrg	arg=$func_stripname_result
7507b68e1f86Smrg	;;
75086df26cacSmrg
750925dbecb6Smrg      -Xassembler)
751025dbecb6Smrg        prev=xassembler
751125dbecb6Smrg        continue
751225dbecb6Smrg        ;;
751325dbecb6Smrg
7514b68e1f86Smrg      -Xcompiler)
7515b68e1f86Smrg	prev=xcompiler
7516b68e1f86Smrg	continue
7517b68e1f86Smrg	;;
75186df26cacSmrg
7519b68e1f86Smrg      -Xlinker)
7520b68e1f86Smrg	prev=xlinker
7521b68e1f86Smrg	continue
7522b68e1f86Smrg	;;
75236df26cacSmrg
7524b68e1f86Smrg      -XCClinker)
7525b68e1f86Smrg	prev=xcclinker
7526b68e1f86Smrg	continue
7527b68e1f86Smrg	;;
75286df26cacSmrg
7529b68e1f86Smrg      # -msg_* for osf cc
7530b68e1f86Smrg      -msg_*)
753125dbecb6Smrg	func_quote_arg pretty "$arg"
753225dbecb6Smrg	arg=$func_quote_arg_result
7533b68e1f86Smrg	;;
75346df26cacSmrg
75353bfa90b6Smrg      # Flags to be passed through unchanged, with rationale:
75363bfa90b6Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
75373bfa90b6Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
75383bfa90b6Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
75393bfa90b6Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
75403bfa90b6Smrg      # -q*                  compiler args for the IBM compiler
75413bfa90b6Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
75423bfa90b6Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
75433bfa90b6Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
754425dbecb6Smrg      # -fstack-protector*   stack protector flags for GCC
75453bfa90b6Smrg      # @file                GCC response files
75463bfa90b6Smrg      # -tp=*                Portland pgcc target processor selection
75473bfa90b6Smrg      # --sysroot=*          for sysroot support
754825dbecb6Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
754925dbecb6Smrg      # -specs=*             GCC specs files
755025dbecb6Smrg      # -stdlib=*            select c++ std lib with clang
755125dbecb6Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
755225dbecb6Smrg      # -fuse-ld=*           Linker select flags for GCC
755325dbecb6Smrg      # -Wa,*                Pass flags directly to the assembler
7554b68e1f86Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
75553bfa90b6Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
755625dbecb6Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
755725dbecb6Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
755825dbecb6Smrg        func_quote_arg pretty "$arg"
755925dbecb6Smrg	arg=$func_quote_arg_result
7560b68e1f86Smrg        func_append compile_command " $arg"
7561b68e1f86Smrg        func_append finalize_command " $arg"
75623bfa90b6Smrg        func_append compiler_flags " $arg"
7563b68e1f86Smrg        continue
7564b68e1f86Smrg        ;;
75656df26cacSmrg
756625dbecb6Smrg      -Z*)
756725dbecb6Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
756825dbecb6Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
756925dbecb6Smrg	  compiler_flags="$compiler_flags $arg"
757025dbecb6Smrg	  func_append compile_command " $arg"
757125dbecb6Smrg	  func_append finalize_command " $arg"
757225dbecb6Smrg	  case $arg in
757325dbecb6Smrg	  -Zlinker | -Zstack)
757425dbecb6Smrg	    prev=xcompiler
757525dbecb6Smrg	    ;;
757625dbecb6Smrg	  esac
757725dbecb6Smrg	  continue
757825dbecb6Smrg        else
757925dbecb6Smrg	  # Otherwise treat like 'Some other compiler flag' below
758025dbecb6Smrg	  func_quote_arg pretty "$arg"
758125dbecb6Smrg	  arg=$func_quote_arg_result
758225dbecb6Smrg        fi
758325dbecb6Smrg	;;
758425dbecb6Smrg
7585b68e1f86Smrg      # Some other compiler flag.
7586b68e1f86Smrg      -* | +*)
758725dbecb6Smrg        func_quote_arg pretty "$arg"
758825dbecb6Smrg	arg=$func_quote_arg_result
7589b68e1f86Smrg	;;
75906df26cacSmrg
7591b68e1f86Smrg      *.$objext)
7592b68e1f86Smrg	# A standard object.
75933bfa90b6Smrg	func_append objs " $arg"
7594b68e1f86Smrg	;;
75956df26cacSmrg
7596b68e1f86Smrg      *.lo)
7597b68e1f86Smrg	# A libtool-controlled object.
75986df26cacSmrg
7599b68e1f86Smrg	# Check to see that this really is a libtool object.
7600b68e1f86Smrg	if func_lalib_unsafe_p "$arg"; then
7601b68e1f86Smrg	  pic_object=
7602b68e1f86Smrg	  non_pic_object=
76036df26cacSmrg
7604b68e1f86Smrg	  # Read the .lo file
7605b68e1f86Smrg	  func_source "$arg"
76066df26cacSmrg
7607b68e1f86Smrg	  if test -z "$pic_object" ||
7608b68e1f86Smrg	     test -z "$non_pic_object" ||
760925dbecb6Smrg	     test none = "$pic_object" &&
761025dbecb6Smrg	     test none = "$non_pic_object"; then
761125dbecb6Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7612b68e1f86Smrg	  fi
76136df26cacSmrg
7614b68e1f86Smrg	  # Extract subdirectory from the argument.
7615b68e1f86Smrg	  func_dirname "$arg" "/" ""
761625dbecb6Smrg	  xdir=$func_dirname_result
76176df26cacSmrg
761825dbecb6Smrg	  test none = "$pic_object" || {
7619b68e1f86Smrg	    # Prepend the subdirectory the object is found in.
762025dbecb6Smrg	    pic_object=$xdir$pic_object
76216df26cacSmrg
762225dbecb6Smrg	    if test dlfiles = "$prev"; then
762325dbecb6Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
76243bfa90b6Smrg		func_append dlfiles " $pic_object"
7625b68e1f86Smrg		prev=
7626b68e1f86Smrg		continue
7627b68e1f86Smrg	      else
7628b68e1f86Smrg		# If libtool objects are unsupported, then we need to preload.
7629b68e1f86Smrg		prev=dlprefiles
7630b68e1f86Smrg	      fi
7631b68e1f86Smrg	    fi
76326df26cacSmrg
7633b68e1f86Smrg	    # CHECK ME:  I think I busted this.  -Ossama
763425dbecb6Smrg	    if test dlprefiles = "$prev"; then
7635b68e1f86Smrg	      # Preload the old-style object.
76363bfa90b6Smrg	      func_append dlprefiles " $pic_object"
7637b68e1f86Smrg	      prev=
7638b68e1f86Smrg	    fi
76396df26cacSmrg
7640b68e1f86Smrg	    # A PIC object.
7641b68e1f86Smrg	    func_append libobjs " $pic_object"
764225dbecb6Smrg	    arg=$pic_object
764325dbecb6Smrg	  }
76446df26cacSmrg
7645b68e1f86Smrg	  # Non-PIC object.
764625dbecb6Smrg	  if test none != "$non_pic_object"; then
7647b68e1f86Smrg	    # Prepend the subdirectory the object is found in.
764825dbecb6Smrg	    non_pic_object=$xdir$non_pic_object
76496df26cacSmrg
7650b68e1f86Smrg	    # A standard non-PIC object
7651b68e1f86Smrg	    func_append non_pic_objects " $non_pic_object"
765225dbecb6Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
765325dbecb6Smrg	      arg=$non_pic_object
7654b68e1f86Smrg	    fi
7655b68e1f86Smrg	  else
7656b68e1f86Smrg	    # If the PIC object exists, use it instead.
7657b68e1f86Smrg	    # $xdir was prepended to $pic_object above.
765825dbecb6Smrg	    non_pic_object=$pic_object
7659b68e1f86Smrg	    func_append non_pic_objects " $non_pic_object"
7660b68e1f86Smrg	  fi
7661b68e1f86Smrg	else
7662b68e1f86Smrg	  # Only an error if not doing a dry-run.
7663b68e1f86Smrg	  if $opt_dry_run; then
7664b68e1f86Smrg	    # Extract subdirectory from the argument.
7665b68e1f86Smrg	    func_dirname "$arg" "/" ""
766625dbecb6Smrg	    xdir=$func_dirname_result
7667b68e1f86Smrg
7668b68e1f86Smrg	    func_lo2o "$arg"
7669b68e1f86Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7670b68e1f86Smrg	    non_pic_object=$xdir$func_lo2o_result
7671b68e1f86Smrg	    func_append libobjs " $pic_object"
7672b68e1f86Smrg	    func_append non_pic_objects " $non_pic_object"
7673b68e1f86Smrg	  else
767425dbecb6Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7675b68e1f86Smrg	  fi
7676b68e1f86Smrg	fi
7677b68e1f86Smrg	;;
76786df26cacSmrg
7679b68e1f86Smrg      *.$libext)
7680b68e1f86Smrg	# An archive.
76813bfa90b6Smrg	func_append deplibs " $arg"
76823bfa90b6Smrg	func_append old_deplibs " $arg"
7683b68e1f86Smrg	continue
7684b68e1f86Smrg	;;
76856df26cacSmrg
7686b68e1f86Smrg      *.la)
7687b68e1f86Smrg	# A libtool-controlled library.
76886df26cacSmrg
76893bfa90b6Smrg	func_resolve_sysroot "$arg"
769025dbecb6Smrg	if test dlfiles = "$prev"; then
7691b68e1f86Smrg	  # This library was specified with -dlopen.
76923bfa90b6Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7693b68e1f86Smrg	  prev=
769425dbecb6Smrg	elif test dlprefiles = "$prev"; then
7695b68e1f86Smrg	  # The library was specified with -dlpreopen.
76963bfa90b6Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7697b68e1f86Smrg	  prev=
7698b68e1f86Smrg	else
76993bfa90b6Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7700b68e1f86Smrg	fi
7701b68e1f86Smrg	continue
7702b68e1f86Smrg	;;
77036df26cacSmrg
7704b68e1f86Smrg      # Some other compiler argument.
7705b68e1f86Smrg      *)
7706b68e1f86Smrg	# Unknown arguments in both finalize_command and compile_command need
7707b68e1f86Smrg	# to be aesthetically quoted because they are evaled later.
770825dbecb6Smrg	func_quote_arg pretty "$arg"
770925dbecb6Smrg	arg=$func_quote_arg_result
7710b68e1f86Smrg	;;
7711b68e1f86Smrg      esac # arg
77126df26cacSmrg
7713b68e1f86Smrg      # Now actually substitute the argument into the commands.
7714b68e1f86Smrg      if test -n "$arg"; then
7715b68e1f86Smrg	func_append compile_command " $arg"
7716b68e1f86Smrg	func_append finalize_command " $arg"
7717b68e1f86Smrg      fi
7718b68e1f86Smrg    done # argument parsing loop
77196df26cacSmrg
7720b68e1f86Smrg    test -n "$prev" && \
772125dbecb6Smrg      func_fatal_help "the '$prevarg' option requires an argument"
772216fd1166Smrg
772325dbecb6Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7724b68e1f86Smrg      eval arg=\"$export_dynamic_flag_spec\"
7725b68e1f86Smrg      func_append compile_command " $arg"
7726b68e1f86Smrg      func_append finalize_command " $arg"
7727b68e1f86Smrg    fi
77286df26cacSmrg
7729b68e1f86Smrg    oldlibs=
7730b68e1f86Smrg    # calculate the name of the file, without its directory
7731b68e1f86Smrg    func_basename "$output"
773225dbecb6Smrg    outputname=$func_basename_result
773325dbecb6Smrg    libobjs_save=$libobjs
77346df26cacSmrg
7735b68e1f86Smrg    if test -n "$shlibpath_var"; then
7736b68e1f86Smrg      # get the directories listed in $shlibpath_var
773725dbecb6Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
77386df26cacSmrg    else
7739b68e1f86Smrg      shlib_search_path=
77406df26cacSmrg    fi
7741b68e1f86Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7742b68e1f86Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
77436df26cacSmrg
774425dbecb6Smrg    # Definition is injected by LT_CONFIG during libtool generation.
774525dbecb6Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
774625dbecb6Smrg
7747b68e1f86Smrg    func_dirname "$output" "/" ""
774825dbecb6Smrg    output_objdir=$func_dirname_result$objdir
77493bfa90b6Smrg    func_to_tool_file "$output_objdir/"
77503bfa90b6Smrg    tool_output_objdir=$func_to_tool_file_result
7751b68e1f86Smrg    # Create the object directory.
7752b68e1f86Smrg    func_mkdir_p "$output_objdir"
77536df26cacSmrg
7754b68e1f86Smrg    # Determine the type of output
7755b68e1f86Smrg    case $output in
7756b68e1f86Smrg    "")
7757b68e1f86Smrg      func_fatal_help "you must specify an output file"
7758b68e1f86Smrg      ;;
7759b68e1f86Smrg    *.$libext) linkmode=oldlib ;;
7760b68e1f86Smrg    *.lo | *.$objext) linkmode=obj ;;
7761b68e1f86Smrg    *.la) linkmode=lib ;;
7762b68e1f86Smrg    *) linkmode=prog ;; # Anything else should be a program.
7763b68e1f86Smrg    esac
7764b68e1f86Smrg
7765b68e1f86Smrg    specialdeplibs=
7766b68e1f86Smrg
7767b68e1f86Smrg    libs=
7768b68e1f86Smrg    # Find all interdependent deplibs by searching for libraries
7769b68e1f86Smrg    # that are linked more than once (e.g. -la -lb -la)
7770b68e1f86Smrg    for deplib in $deplibs; do
777125dbecb6Smrg      if $opt_preserve_dup_deps; then
7772b68e1f86Smrg	case "$libs " in
77733bfa90b6Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7774b68e1f86Smrg	esac
7775b68e1f86Smrg      fi
77763bfa90b6Smrg      func_append libs " $deplib"
7777b68e1f86Smrg    done
7778b68e1f86Smrg
777925dbecb6Smrg    if test lib = "$linkmode"; then
7780b68e1f86Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7781b68e1f86Smrg
7782b68e1f86Smrg      # Compute libraries that are listed more than once in $predeps
7783b68e1f86Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7784b68e1f86Smrg      # not to be eliminated).
7785b68e1f86Smrg      pre_post_deps=
7786b68e1f86Smrg      if $opt_duplicate_compiler_generated_deps; then
7787b68e1f86Smrg	for pre_post_dep in $predeps $postdeps; do
7788b68e1f86Smrg	  case "$pre_post_deps " in
77893bfa90b6Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7790b68e1f86Smrg	  esac
77913bfa90b6Smrg	  func_append pre_post_deps " $pre_post_dep"
7792b68e1f86Smrg	done
7793b68e1f86Smrg      fi
7794b68e1f86Smrg      pre_post_deps=
7795b68e1f86Smrg    fi
7796b68e1f86Smrg
7797b68e1f86Smrg    deplibs=
7798b68e1f86Smrg    newdependency_libs=
7799b68e1f86Smrg    newlib_search_path=
7800b68e1f86Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7801b68e1f86Smrg    notinst_deplibs= # not-installed libtool libraries
7802b68e1f86Smrg    notinst_path= # paths that contain not-installed libtool libraries
7803b68e1f86Smrg
7804b68e1f86Smrg    case $linkmode in
7805b68e1f86Smrg    lib)
7806b68e1f86Smrg	passes="conv dlpreopen link"
7807b68e1f86Smrg	for file in $dlfiles $dlprefiles; do
7808b68e1f86Smrg	  case $file in
7809b68e1f86Smrg	  *.la) ;;
7810b68e1f86Smrg	  *)
781125dbecb6Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7812b68e1f86Smrg	    ;;
7813b68e1f86Smrg	  esac
7814b68e1f86Smrg	done
7815b68e1f86Smrg	;;
7816b68e1f86Smrg    prog)
7817b68e1f86Smrg	compile_deplibs=
7818b68e1f86Smrg	finalize_deplibs=
781925dbecb6Smrg	alldeplibs=false
7820b68e1f86Smrg	newdlfiles=
7821b68e1f86Smrg	newdlprefiles=
7822b68e1f86Smrg	passes="conv scan dlopen dlpreopen link"
7823b68e1f86Smrg	;;
7824b68e1f86Smrg    *)  passes="conv"
7825b68e1f86Smrg	;;
7826b68e1f86Smrg    esac
7827b68e1f86Smrg
7828b68e1f86Smrg    for pass in $passes; do
7829b68e1f86Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7830b68e1f86Smrg      # so that -L comes before libs that need it for instance...
783125dbecb6Smrg      if test lib,link = "$linkmode,$pass"; then
7832b68e1f86Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7833b68e1f86Smrg	##        order, and fix it there properly
7834b68e1f86Smrg        tmp_deplibs=
7835b68e1f86Smrg	for deplib in $deplibs; do
7836b68e1f86Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7837b68e1f86Smrg	done
783825dbecb6Smrg	deplibs=$tmp_deplibs
7839b68e1f86Smrg      fi
7840b68e1f86Smrg
784125dbecb6Smrg      if test lib,link = "$linkmode,$pass" ||
784225dbecb6Smrg	 test prog,scan = "$linkmode,$pass"; then
784325dbecb6Smrg	libs=$deplibs
7844b68e1f86Smrg	deplibs=
7845b68e1f86Smrg      fi
784625dbecb6Smrg      if test prog = "$linkmode"; then
7847b68e1f86Smrg	case $pass in
784825dbecb6Smrg	dlopen) libs=$dlfiles ;;
784925dbecb6Smrg	dlpreopen) libs=$dlprefiles ;;
7850591e32d7Ssnj	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7851b68e1f86Smrg	esac
7852b68e1f86Smrg      fi
785325dbecb6Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7854b68e1f86Smrg	# Collect and forward deplibs of preopened libtool libs
7855b68e1f86Smrg	for lib in $dlprefiles; do
7856b68e1f86Smrg	  # Ignore non-libtool-libs
7857b68e1f86Smrg	  dependency_libs=
78583bfa90b6Smrg	  func_resolve_sysroot "$lib"
7859b68e1f86Smrg	  case $lib in
78603bfa90b6Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7861b68e1f86Smrg	  esac
7862b68e1f86Smrg
7863b68e1f86Smrg	  # Collect preopened libtool deplibs, except any this library
7864b68e1f86Smrg	  # has declared as weak libs
7865b68e1f86Smrg	  for deplib in $dependency_libs; do
78663bfa90b6Smrg	    func_basename "$deplib"
78673bfa90b6Smrg            deplib_base=$func_basename_result
7868b68e1f86Smrg	    case " $weak_libs " in
7869b68e1f86Smrg	    *" $deplib_base "*) ;;
78703bfa90b6Smrg	    *) func_append deplibs " $deplib" ;;
7871b68e1f86Smrg	    esac
7872b68e1f86Smrg	  done
7873b68e1f86Smrg	done
787425dbecb6Smrg	libs=$dlprefiles
7875b68e1f86Smrg      fi
787625dbecb6Smrg      if test dlopen = "$pass"; then
7877b68e1f86Smrg	# Collect dlpreopened libraries
787825dbecb6Smrg	save_deplibs=$deplibs
7879b68e1f86Smrg	deplibs=
7880b68e1f86Smrg      fi
7881b68e1f86Smrg
7882b68e1f86Smrg      for deplib in $libs; do
7883b68e1f86Smrg	lib=
788425dbecb6Smrg	found=false
7885b68e1f86Smrg	case $deplib in
78863bfa90b6Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
78873bfa90b6Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
788825dbecb6Smrg	  if test prog,link = "$linkmode,$pass"; then
7889b68e1f86Smrg	    compile_deplibs="$deplib $compile_deplibs"
7890b68e1f86Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7891b68e1f86Smrg	  else
78923bfa90b6Smrg	    func_append compiler_flags " $deplib"
789325dbecb6Smrg	    if test lib = "$linkmode"; then
7894b68e1f86Smrg		case "$new_inherited_linker_flags " in
7895b68e1f86Smrg		    *" $deplib "*) ;;
78963bfa90b6Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7897b68e1f86Smrg		esac
7898b68e1f86Smrg	    fi
7899b68e1f86Smrg	  fi
7900b68e1f86Smrg	  continue
7901b68e1f86Smrg	  ;;
7902b68e1f86Smrg	-l*)
790325dbecb6Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
790425dbecb6Smrg	    func_warning "'-l' is ignored for archives/objects"
7905b68e1f86Smrg	    continue
7906b68e1f86Smrg	  fi
7907b68e1f86Smrg	  func_stripname '-l' '' "$deplib"
7908b68e1f86Smrg	  name=$func_stripname_result
790925dbecb6Smrg	  if test lib = "$linkmode"; then
7910b68e1f86Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7911b68e1f86Smrg	  else
7912b68e1f86Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7913b68e1f86Smrg	  fi
7914b68e1f86Smrg	  for searchdir in $searchdirs; do
7915b68e1f86Smrg	    for search_ext in .la $std_shrext .so .a; do
7916b68e1f86Smrg	      # Search the libtool library
791725dbecb6Smrg	      lib=$searchdir/lib$name$search_ext
7918b68e1f86Smrg	      if test -f "$lib"; then
791925dbecb6Smrg		if test .la = "$search_ext"; then
792025dbecb6Smrg		  found=:
7921b68e1f86Smrg		else
792225dbecb6Smrg		  found=false
7923b68e1f86Smrg		fi
7924b68e1f86Smrg		break 2
7925b68e1f86Smrg	      fi
7926b68e1f86Smrg	    done
7927b68e1f86Smrg	  done
792825dbecb6Smrg	  if $found; then
792925dbecb6Smrg	    # deplib is a libtool library
7930b68e1f86Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7931b68e1f86Smrg	    # We need to do some special things here, and not later.
793225dbecb6Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7933b68e1f86Smrg	      case " $predeps $postdeps " in
7934b68e1f86Smrg	      *" $deplib "*)
7935b68e1f86Smrg		if func_lalib_p "$lib"; then
7936b68e1f86Smrg		  library_names=
7937b68e1f86Smrg		  old_library=
7938b68e1f86Smrg		  func_source "$lib"
7939b68e1f86Smrg		  for l in $old_library $library_names; do
794025dbecb6Smrg		    ll=$l
7941b68e1f86Smrg		  done
794225dbecb6Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
794325dbecb6Smrg		    found=false
7944b68e1f86Smrg		    func_dirname "$lib" "" "."
794525dbecb6Smrg		    ladir=$func_dirname_result
7946b68e1f86Smrg		    lib=$ladir/$old_library
794725dbecb6Smrg		    if test prog,link = "$linkmode,$pass"; then
7948b68e1f86Smrg		      compile_deplibs="$deplib $compile_deplibs"
7949b68e1f86Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7950b68e1f86Smrg		    else
7951b68e1f86Smrg		      deplibs="$deplib $deplibs"
795225dbecb6Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7953b68e1f86Smrg		    fi
7954b68e1f86Smrg		    continue
7955b68e1f86Smrg		  fi
7956b68e1f86Smrg		fi
7957b68e1f86Smrg		;;
7958b68e1f86Smrg	      *) ;;
7959b68e1f86Smrg	      esac
7960b68e1f86Smrg	    fi
796125dbecb6Smrg	  else
796225dbecb6Smrg	    # deplib doesn't seem to be a libtool library
796325dbecb6Smrg	    if test prog,link = "$linkmode,$pass"; then
796425dbecb6Smrg	      compile_deplibs="$deplib $compile_deplibs"
796525dbecb6Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
796625dbecb6Smrg	    else
796725dbecb6Smrg	      deplibs="$deplib $deplibs"
796825dbecb6Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
796925dbecb6Smrg	    fi
797025dbecb6Smrg	    continue
7971b68e1f86Smrg	  fi
7972b68e1f86Smrg	  ;; # -l
7973b68e1f86Smrg	*.ltframework)
797425dbecb6Smrg	  if test prog,link = "$linkmode,$pass"; then
7975b68e1f86Smrg	    compile_deplibs="$deplib $compile_deplibs"
7976b68e1f86Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7977b68e1f86Smrg	  else
7978b68e1f86Smrg	    deplibs="$deplib $deplibs"
797925dbecb6Smrg	    if test lib = "$linkmode"; then
7980b68e1f86Smrg		case "$new_inherited_linker_flags " in
7981b68e1f86Smrg		    *" $deplib "*) ;;
79823bfa90b6Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7983b68e1f86Smrg		esac
7984b68e1f86Smrg	    fi
7985b68e1f86Smrg	  fi
7986b68e1f86Smrg	  continue
7987b68e1f86Smrg	  ;;
7988b68e1f86Smrg	-L*)
7989b68e1f86Smrg	  case $linkmode in
7990b68e1f86Smrg	  lib)
7991b68e1f86Smrg	    deplibs="$deplib $deplibs"
799225dbecb6Smrg	    test conv = "$pass" && continue
7993b68e1f86Smrg	    newdependency_libs="$deplib $newdependency_libs"
7994b68e1f86Smrg	    func_stripname '-L' '' "$deplib"
79953bfa90b6Smrg	    func_resolve_sysroot "$func_stripname_result"
79963bfa90b6Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7997b68e1f86Smrg	    ;;
7998b68e1f86Smrg	  prog)
799925dbecb6Smrg	    if test conv = "$pass"; then
8000b68e1f86Smrg	      deplibs="$deplib $deplibs"
8001b68e1f86Smrg	      continue
8002b68e1f86Smrg	    fi
800325dbecb6Smrg	    if test scan = "$pass"; then
8004b68e1f86Smrg	      deplibs="$deplib $deplibs"
8005b68e1f86Smrg	    else
8006b68e1f86Smrg	      compile_deplibs="$deplib $compile_deplibs"
8007b68e1f86Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8008b68e1f86Smrg	    fi
8009b68e1f86Smrg	    func_stripname '-L' '' "$deplib"
80103bfa90b6Smrg	    func_resolve_sysroot "$func_stripname_result"
80113bfa90b6Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8012b68e1f86Smrg	    ;;
8013b68e1f86Smrg	  *)
801425dbecb6Smrg	    func_warning "'-L' is ignored for archives/objects"
8015b68e1f86Smrg	    ;;
8016b68e1f86Smrg	  esac # linkmode
8017b68e1f86Smrg	  continue
8018b68e1f86Smrg	  ;; # -L
8019b68e1f86Smrg	-R*)
802025dbecb6Smrg	  if test link = "$pass"; then
8021b68e1f86Smrg	    func_stripname '-R' '' "$deplib"
80223bfa90b6Smrg	    func_resolve_sysroot "$func_stripname_result"
80233bfa90b6Smrg	    dir=$func_resolve_sysroot_result
8024b68e1f86Smrg	    # Make sure the xrpath contains only unique directories.
8025b68e1f86Smrg	    case "$xrpath " in
8026b68e1f86Smrg	    *" $dir "*) ;;
80273bfa90b6Smrg	    *) func_append xrpath " $dir" ;;
8028b68e1f86Smrg	    esac
8029b68e1f86Smrg	  fi
8030b68e1f86Smrg	  deplibs="$deplib $deplibs"
8031b68e1f86Smrg	  continue
8032b68e1f86Smrg	  ;;
80333bfa90b6Smrg	*.la)
80343bfa90b6Smrg	  func_resolve_sysroot "$deplib"
80353bfa90b6Smrg	  lib=$func_resolve_sysroot_result
80363bfa90b6Smrg	  ;;
8037b68e1f86Smrg	*.$libext)
803825dbecb6Smrg	  if test conv = "$pass"; then
8039b68e1f86Smrg	    deplibs="$deplib $deplibs"
8040b68e1f86Smrg	    continue
8041b68e1f86Smrg	  fi
8042b68e1f86Smrg	  case $linkmode in
8043b68e1f86Smrg	  lib)
8044b68e1f86Smrg	    # Linking convenience modules into shared libraries is allowed,
8045b68e1f86Smrg	    # but linking other static libraries is non-portable.
8046b68e1f86Smrg	    case " $dlpreconveniencelibs " in
8047b68e1f86Smrg	    *" $deplib "*) ;;
8048b68e1f86Smrg	    *)
804925dbecb6Smrg	      valid_a_lib=false
8050b68e1f86Smrg	      case $deplibs_check_method in
8051b68e1f86Smrg		match_pattern*)
8052b68e1f86Smrg		  set dummy $deplibs_check_method; shift
8053b68e1f86Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
80543bfa90b6Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8055b68e1f86Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
805625dbecb6Smrg		    valid_a_lib=:
8057b68e1f86Smrg		  fi
8058b68e1f86Smrg		;;
8059b68e1f86Smrg		pass_all)
806025dbecb6Smrg		  valid_a_lib=:
8061b68e1f86Smrg		;;
8062b68e1f86Smrg	      esac
806325dbecb6Smrg	      if $valid_a_lib; then
806425dbecb6Smrg		echo
806525dbecb6Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
806625dbecb6Smrg		$ECHO "*** static library $deplib is not portable!"
806725dbecb6Smrg		deplibs="$deplib $deplibs"
806825dbecb6Smrg	      else
80693bfa90b6Smrg		echo
8070b68e1f86Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
80713bfa90b6Smrg		echo "*** I have the capability to make that library automatically link in when"
80723bfa90b6Smrg		echo "*** you link to this library.  But I can only do this if you have a"
80733bfa90b6Smrg		echo "*** shared version of the library, which you do not appear to have"
80743bfa90b6Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
80753bfa90b6Smrg		echo "*** that it is just a static archive that I should not use here."
8076b68e1f86Smrg	      fi
8077b68e1f86Smrg	      ;;
8078b68e1f86Smrg	    esac
8079b68e1f86Smrg	    continue
8080b68e1f86Smrg	    ;;
8081b68e1f86Smrg	  prog)
808225dbecb6Smrg	    if test link != "$pass"; then
8083b68e1f86Smrg	      deplibs="$deplib $deplibs"
8084b68e1f86Smrg	    else
8085b68e1f86Smrg	      compile_deplibs="$deplib $compile_deplibs"
8086b68e1f86Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8087b68e1f86Smrg	    fi
8088b68e1f86Smrg	    continue
8089b68e1f86Smrg	    ;;
8090b68e1f86Smrg	  esac # linkmode
8091b68e1f86Smrg	  ;; # *.$libext
8092b68e1f86Smrg	*.lo | *.$objext)
809325dbecb6Smrg	  if test conv = "$pass"; then
8094b68e1f86Smrg	    deplibs="$deplib $deplibs"
809525dbecb6Smrg	  elif test prog = "$linkmode"; then
809625dbecb6Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8097b68e1f86Smrg	      # If there is no dlopen support or we're linking statically,
8098b68e1f86Smrg	      # we need to preload.
80993bfa90b6Smrg	      func_append newdlprefiles " $deplib"
8100b68e1f86Smrg	      compile_deplibs="$deplib $compile_deplibs"
8101b68e1f86Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8102b68e1f86Smrg	    else
81033bfa90b6Smrg	      func_append newdlfiles " $deplib"
8104b68e1f86Smrg	    fi
8105b68e1f86Smrg	  fi
8106b68e1f86Smrg	  continue
8107b68e1f86Smrg	  ;;
8108b68e1f86Smrg	%DEPLIBS%)
810925dbecb6Smrg	  alldeplibs=:
8110b68e1f86Smrg	  continue
8111b68e1f86Smrg	  ;;
8112b68e1f86Smrg	esac # case $deplib
8113b68e1f86Smrg
811425dbecb6Smrg	$found || test -f "$lib" \
811525dbecb6Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8116b68e1f86Smrg
8117b68e1f86Smrg	# Check to see that this really is a libtool archive.
8118b68e1f86Smrg	func_lalib_unsafe_p "$lib" \
811925dbecb6Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8120b68e1f86Smrg
8121b68e1f86Smrg	func_dirname "$lib" "" "."
812225dbecb6Smrg	ladir=$func_dirname_result
8123b68e1f86Smrg
8124b68e1f86Smrg	dlname=
8125b68e1f86Smrg	dlopen=
8126b68e1f86Smrg	dlpreopen=
8127b68e1f86Smrg	libdir=
8128b68e1f86Smrg	library_names=
8129b68e1f86Smrg	old_library=
8130b68e1f86Smrg	inherited_linker_flags=
8131b68e1f86Smrg	# If the library was installed with an old release of libtool,
8132b68e1f86Smrg	# it will not redefine variables installed, or shouldnotlink
8133b68e1f86Smrg	installed=yes
8134b68e1f86Smrg	shouldnotlink=no
8135b68e1f86Smrg	avoidtemprpath=
8136b68e1f86Smrg
8137b68e1f86Smrg
8138b68e1f86Smrg	# Read the .la file
8139b68e1f86Smrg	func_source "$lib"
8140b68e1f86Smrg
8141b68e1f86Smrg	# Convert "-framework foo" to "foo.ltframework"
8142b68e1f86Smrg	if test -n "$inherited_linker_flags"; then
81433bfa90b6Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8144b68e1f86Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8145b68e1f86Smrg	    case " $new_inherited_linker_flags " in
8146b68e1f86Smrg	      *" $tmp_inherited_linker_flag "*) ;;
81473bfa90b6Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8148b68e1f86Smrg	    esac
8149b68e1f86Smrg	  done
8150b68e1f86Smrg	fi
81513bfa90b6Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
815225dbecb6Smrg	if test lib,link = "$linkmode,$pass" ||
815325dbecb6Smrg	   test prog,scan = "$linkmode,$pass" ||
815425dbecb6Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
81553bfa90b6Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
81563bfa90b6Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8157b68e1f86Smrg	fi
8158b68e1f86Smrg
815925dbecb6Smrg	if test conv = "$pass"; then
8160b68e1f86Smrg	  # Only check for convenience libraries
8161b68e1f86Smrg	  deplibs="$lib $deplibs"
8162b68e1f86Smrg	  if test -z "$libdir"; then
8163b68e1f86Smrg	    if test -z "$old_library"; then
816425dbecb6Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
8165b68e1f86Smrg	    fi
8166b68e1f86Smrg	    # It is a libtool convenience library, so add in its objects.
81673bfa90b6Smrg	    func_append convenience " $ladir/$objdir/$old_library"
81683bfa90b6Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
816925dbecb6Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
817025dbecb6Smrg	    func_fatal_error "'$lib' is not a convenience library"
8171b68e1f86Smrg	  fi
8172591e32d7Ssnj	  tmp_libs=
8173591e32d7Ssnj	  for deplib in $dependency_libs; do
8174591e32d7Ssnj	    deplibs="$deplib $deplibs"
817525dbecb6Smrg	    if $opt_preserve_dup_deps; then
8176591e32d7Ssnj	      case "$tmp_libs " in
8177591e32d7Ssnj	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8178591e32d7Ssnj	      esac
8179591e32d7Ssnj	    fi
8180591e32d7Ssnj	    func_append tmp_libs " $deplib"
8181591e32d7Ssnj	  done
8182b68e1f86Smrg	  continue
8183b68e1f86Smrg	fi # $pass = conv
8184b68e1f86Smrg
8185b68e1f86Smrg
8186b68e1f86Smrg	# Get the name of the library we link against.
8187b68e1f86Smrg	linklib=
81883bfa90b6Smrg	if test -n "$old_library" &&
818925dbecb6Smrg	   { test yes = "$prefer_static_libs" ||
819025dbecb6Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
81913bfa90b6Smrg	  linklib=$old_library
81923bfa90b6Smrg	else
81933bfa90b6Smrg	  for l in $old_library $library_names; do
819425dbecb6Smrg	    linklib=$l
81953bfa90b6Smrg	  done
81963bfa90b6Smrg	fi
8197b68e1f86Smrg	if test -z "$linklib"; then
819825dbecb6Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
8199b68e1f86Smrg	fi
8200b68e1f86Smrg
8201b68e1f86Smrg	# This library was specified with -dlopen.
820225dbecb6Smrg	if test dlopen = "$pass"; then
820325dbecb6Smrg	  test -z "$libdir" \
820425dbecb6Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8205b68e1f86Smrg	  if test -z "$dlname" ||
820625dbecb6Smrg	     test yes != "$dlopen_support" ||
820725dbecb6Smrg	     test no = "$build_libtool_libs"
820825dbecb6Smrg	  then
8209b68e1f86Smrg	    # If there is no dlname, no dlopen support or we're linking
8210b68e1f86Smrg	    # statically, we need to preload.  We also need to preload any
8211b68e1f86Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8212b68e1f86Smrg	    # bomb out in the load deplibs phase.
82133bfa90b6Smrg	    func_append dlprefiles " $lib $dependency_libs"
8214b68e1f86Smrg	  else
82153bfa90b6Smrg	    func_append newdlfiles " $lib"
8216b68e1f86Smrg	  fi
8217b68e1f86Smrg	  continue
8218b68e1f86Smrg	fi # $pass = dlopen
8219b68e1f86Smrg
8220b68e1f86Smrg	# We need an absolute path.
8221b68e1f86Smrg	case $ladir in
822225dbecb6Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8223b68e1f86Smrg	*)
8224b68e1f86Smrg	  abs_ladir=`cd "$ladir" && pwd`
8225b68e1f86Smrg	  if test -z "$abs_ladir"; then
822625dbecb6Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8227b68e1f86Smrg	    func_warning "passing it literally to the linker, although it might fail"
822825dbecb6Smrg	    abs_ladir=$ladir
8229b68e1f86Smrg	  fi
8230b68e1f86Smrg	  ;;
8231b68e1f86Smrg	esac
8232b68e1f86Smrg	func_basename "$lib"
823325dbecb6Smrg	laname=$func_basename_result
8234b68e1f86Smrg
8235b68e1f86Smrg	# Find the relevant object directory and library name.
823625dbecb6Smrg	if test yes = "$installed"; then
82373bfa90b6Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
823825dbecb6Smrg	    func_warning "library '$lib' was moved."
823925dbecb6Smrg	    dir=$ladir
824025dbecb6Smrg	    absdir=$abs_ladir
824125dbecb6Smrg	    libdir=$abs_ladir
8242b68e1f86Smrg	  else
824325dbecb6Smrg	    dir=$lt_sysroot$libdir
824425dbecb6Smrg	    absdir=$lt_sysroot$libdir
8245b68e1f86Smrg	  fi
824625dbecb6Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8247b68e1f86Smrg	else
8248b68e1f86Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
824925dbecb6Smrg	    dir=$ladir
825025dbecb6Smrg	    absdir=$abs_ladir
8251b68e1f86Smrg	    # Remove this search path later
82523bfa90b6Smrg	    func_append notinst_path " $abs_ladir"
8253b68e1f86Smrg	  else
825425dbecb6Smrg	    dir=$ladir/$objdir
825525dbecb6Smrg	    absdir=$abs_ladir/$objdir
8256b68e1f86Smrg	    # Remove this search path later
82573bfa90b6Smrg	    func_append notinst_path " $abs_ladir"
8258b68e1f86Smrg	  fi
8259b68e1f86Smrg	fi # $installed = yes
8260b68e1f86Smrg	func_stripname 'lib' '.la' "$laname"
8261b68e1f86Smrg	name=$func_stripname_result
8262b68e1f86Smrg
8263b68e1f86Smrg	# This library was specified with -dlpreopen.
826425dbecb6Smrg	if test dlpreopen = "$pass"; then
826525dbecb6Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
826625dbecb6Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8267b68e1f86Smrg	  fi
826825dbecb6Smrg	  case $host in
82693bfa90b6Smrg	    # special handling for platforms with PE-DLLs.
82703bfa90b6Smrg	    *cygwin* | *mingw* | *cegcc* )
82713bfa90b6Smrg	      # Linker will automatically link against shared library if both
82723bfa90b6Smrg	      # static and shared are present.  Therefore, ensure we extract
82733bfa90b6Smrg	      # symbols from the import library if a shared library is present
82743bfa90b6Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
82753bfa90b6Smrg	      # this by putting the import library name into $newdlprefiles.
82763bfa90b6Smrg	      # We recover the dlopen module name by 'saving' the la file
82773bfa90b6Smrg	      # name in a special purpose variable, and (later) extracting the
82783bfa90b6Smrg	      # dlname from the la file.
82793bfa90b6Smrg	      if test -n "$dlname"; then
82803bfa90b6Smrg	        func_tr_sh "$dir/$linklib"
82813bfa90b6Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
82823bfa90b6Smrg	        func_append newdlprefiles " $dir/$linklib"
82833bfa90b6Smrg	      else
82843bfa90b6Smrg	        func_append newdlprefiles " $dir/$old_library"
82853bfa90b6Smrg	        # Keep a list of preopened convenience libraries to check
82863bfa90b6Smrg	        # that they are being used correctly in the link pass.
82873bfa90b6Smrg	        test -z "$libdir" && \
82883bfa90b6Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
82893bfa90b6Smrg	      fi
82903bfa90b6Smrg	    ;;
82913bfa90b6Smrg	    * )
82923bfa90b6Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
82933bfa90b6Smrg	      # are required to link).
82943bfa90b6Smrg	      if test -n "$old_library"; then
82953bfa90b6Smrg	        func_append newdlprefiles " $dir/$old_library"
82963bfa90b6Smrg	        # Keep a list of preopened convenience libraries to check
82973bfa90b6Smrg	        # that they are being used correctly in the link pass.
82983bfa90b6Smrg	        test -z "$libdir" && \
82993bfa90b6Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
83003bfa90b6Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
83013bfa90b6Smrg	      elif test -n "$dlname"; then
83023bfa90b6Smrg	        func_append newdlprefiles " $dir/$dlname"
83033bfa90b6Smrg	      else
83043bfa90b6Smrg	        func_append newdlprefiles " $dir/$linklib"
83053bfa90b6Smrg	      fi
83063bfa90b6Smrg	    ;;
83073bfa90b6Smrg	  esac
8308b68e1f86Smrg	fi # $pass = dlpreopen
8309b68e1f86Smrg
8310b68e1f86Smrg	if test -z "$libdir"; then
8311b68e1f86Smrg	  # Link the convenience library
831225dbecb6Smrg	  if test lib = "$linkmode"; then
8313b68e1f86Smrg	    deplibs="$dir/$old_library $deplibs"
831425dbecb6Smrg	  elif test prog,link = "$linkmode,$pass"; then
8315b68e1f86Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8316b68e1f86Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8317b68e1f86Smrg	  else
8318b68e1f86Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8319b68e1f86Smrg	  fi
8320b68e1f86Smrg	  continue
8321b68e1f86Smrg	fi
8322b68e1f86Smrg
8323b68e1f86Smrg
832425dbecb6Smrg	if test prog = "$linkmode" && test link != "$pass"; then
83253bfa90b6Smrg	  func_append newlib_search_path " $ladir"
8326b68e1f86Smrg	  deplibs="$lib $deplibs"
8327b68e1f86Smrg
832825dbecb6Smrg	  linkalldeplibs=false
832925dbecb6Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
833025dbecb6Smrg	     test no = "$build_libtool_libs"; then
833125dbecb6Smrg	    linkalldeplibs=:
8332b68e1f86Smrg	  fi
8333b68e1f86Smrg
8334b68e1f86Smrg	  tmp_libs=
8335b68e1f86Smrg	  for deplib in $dependency_libs; do
8336b68e1f86Smrg	    case $deplib in
8337b68e1f86Smrg	    -L*) func_stripname '-L' '' "$deplib"
83383bfa90b6Smrg	         func_resolve_sysroot "$func_stripname_result"
83393bfa90b6Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8340b68e1f86Smrg		 ;;
8341b68e1f86Smrg	    esac
8342b68e1f86Smrg	    # Need to link against all dependency_libs?
834325dbecb6Smrg	    if $linkalldeplibs; then
8344b68e1f86Smrg	      deplibs="$deplib $deplibs"
8345b68e1f86Smrg	    else
8346b68e1f86Smrg	      # Need to hardcode shared library paths
8347b68e1f86Smrg	      # or/and link against static libraries
8348b68e1f86Smrg	      newdependency_libs="$deplib $newdependency_libs"
8349b68e1f86Smrg	    fi
835025dbecb6Smrg	    if $opt_preserve_dup_deps; then
8351b68e1f86Smrg	      case "$tmp_libs " in
83523bfa90b6Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8353b68e1f86Smrg	      esac
8354b68e1f86Smrg	    fi
83553bfa90b6Smrg	    func_append tmp_libs " $deplib"
8356b68e1f86Smrg	  done # for deplib
8357b68e1f86Smrg	  continue
8358b68e1f86Smrg	fi # $linkmode = prog...
8359b68e1f86Smrg
836025dbecb6Smrg	if test prog,link = "$linkmode,$pass"; then
8361b68e1f86Smrg	  if test -n "$library_names" &&
836225dbecb6Smrg	     { { test no = "$prefer_static_libs" ||
836325dbecb6Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8364b68e1f86Smrg	       test -z "$old_library"; }; then
8365b68e1f86Smrg	    # We need to hardcode the library path
836625dbecb6Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8367b68e1f86Smrg	      # Make sure the rpath contains only unique directories.
836825dbecb6Smrg	      case $temp_rpath: in
8369b68e1f86Smrg	      *"$absdir:"*) ;;
83703bfa90b6Smrg	      *) func_append temp_rpath "$absdir:" ;;
8371b68e1f86Smrg	      esac
8372b68e1f86Smrg	    fi
8373b68e1f86Smrg
8374b68e1f86Smrg	    # Hardcode the library path.
8375b68e1f86Smrg	    # Skip directories that are in the system default run-time
8376b68e1f86Smrg	    # search path.
8377b68e1f86Smrg	    case " $sys_lib_dlsearch_path " in
8378b68e1f86Smrg	    *" $absdir "*) ;;
8379b68e1f86Smrg	    *)
8380b68e1f86Smrg	      case "$compile_rpath " in
8381b68e1f86Smrg	      *" $absdir "*) ;;
83823bfa90b6Smrg	      *) func_append compile_rpath " $absdir" ;;
8383b68e1f86Smrg	      esac
8384b68e1f86Smrg	      ;;
8385b68e1f86Smrg	    esac
8386b68e1f86Smrg	    case " $sys_lib_dlsearch_path " in
8387b68e1f86Smrg	    *" $libdir "*) ;;
8388b68e1f86Smrg	    *)
8389b68e1f86Smrg	      case "$finalize_rpath " in
8390b68e1f86Smrg	      *" $libdir "*) ;;
83913bfa90b6Smrg	      *) func_append finalize_rpath " $libdir" ;;
8392b68e1f86Smrg	      esac
8393b68e1f86Smrg	      ;;
8394b68e1f86Smrg	    esac
8395b68e1f86Smrg	  fi # $linkmode,$pass = prog,link...
8396b68e1f86Smrg
839725dbecb6Smrg	  if $alldeplibs &&
839825dbecb6Smrg	     { test pass_all = "$deplibs_check_method" ||
839925dbecb6Smrg	       { test yes = "$build_libtool_libs" &&
8400b68e1f86Smrg		 test -n "$library_names"; }; }; then
8401b68e1f86Smrg	    # We only need to search for static libraries
8402b68e1f86Smrg	    continue
8403b68e1f86Smrg	  fi
8404b68e1f86Smrg	fi
8405b68e1f86Smrg
8406b68e1f86Smrg	link_static=no # Whether the deplib will be linked statically
8407b68e1f86Smrg	use_static_libs=$prefer_static_libs
840825dbecb6Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8409b68e1f86Smrg	  use_static_libs=no
8410b68e1f86Smrg	fi
8411b68e1f86Smrg	if test -n "$library_names" &&
841225dbecb6Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8413b68e1f86Smrg	  case $host in
841425dbecb6Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8415b68e1f86Smrg	      # No point in relinking DLLs because paths are not encoded
84163bfa90b6Smrg	      func_append notinst_deplibs " $lib"
8417b68e1f86Smrg	      need_relink=no
8418b68e1f86Smrg	    ;;
8419b68e1f86Smrg	  *)
842025dbecb6Smrg	    if test no = "$installed"; then
84213bfa90b6Smrg	      func_append notinst_deplibs " $lib"
8422b68e1f86Smrg	      need_relink=yes
8423b68e1f86Smrg	    fi
8424b68e1f86Smrg	    ;;
8425b68e1f86Smrg	  esac
8426b68e1f86Smrg	  # This is a shared library
8427b68e1f86Smrg
8428b68e1f86Smrg	  # Warn about portability, can't link against -module's on some
8429b68e1f86Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
843025dbecb6Smrg	  dlopenmodule=
8431b68e1f86Smrg	  for dlpremoduletest in $dlprefiles; do
8432b68e1f86Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
843325dbecb6Smrg	      dlopenmodule=$dlpremoduletest
8434b68e1f86Smrg	      break
8435b68e1f86Smrg	    fi
8436b68e1f86Smrg	  done
843725dbecb6Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
84383bfa90b6Smrg	    echo
843925dbecb6Smrg	    if test prog = "$linkmode"; then
8440b68e1f86Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8441b68e1f86Smrg	    else
8442b68e1f86Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8443b68e1f86Smrg	    fi
8444b68e1f86Smrg	    $ECHO "*** $linklib is not portable!"
8445b68e1f86Smrg	  fi
844625dbecb6Smrg	  if test lib = "$linkmode" &&
844725dbecb6Smrg	     test yes = "$hardcode_into_libs"; then
8448b68e1f86Smrg	    # Hardcode the library path.
8449b68e1f86Smrg	    # Skip directories that are in the system default run-time
8450b68e1f86Smrg	    # search path.
8451b68e1f86Smrg	    case " $sys_lib_dlsearch_path " in
8452b68e1f86Smrg	    *" $absdir "*) ;;
8453b68e1f86Smrg	    *)
8454b68e1f86Smrg	      case "$compile_rpath " in
8455b68e1f86Smrg	      *" $absdir "*) ;;
84563bfa90b6Smrg	      *) func_append compile_rpath " $absdir" ;;
8457b68e1f86Smrg	      esac
8458b68e1f86Smrg	      ;;
8459b68e1f86Smrg	    esac
8460b68e1f86Smrg	    case " $sys_lib_dlsearch_path " in
8461b68e1f86Smrg	    *" $libdir "*) ;;
8462b68e1f86Smrg	    *)
8463b68e1f86Smrg	      case "$finalize_rpath " in
8464b68e1f86Smrg	      *" $libdir "*) ;;
84653bfa90b6Smrg	      *) func_append finalize_rpath " $libdir" ;;
8466b68e1f86Smrg	      esac
8467b68e1f86Smrg	      ;;
8468b68e1f86Smrg	    esac
8469b68e1f86Smrg	  fi
8470b68e1f86Smrg
8471b68e1f86Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8472b68e1f86Smrg	    # figure out the soname
8473b68e1f86Smrg	    set dummy $library_names
8474b68e1f86Smrg	    shift
847525dbecb6Smrg	    realname=$1
8476b68e1f86Smrg	    shift
8477b68e1f86Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8478b68e1f86Smrg	    # use dlname if we got it. it's perfectly good, no?
8479b68e1f86Smrg	    if test -n "$dlname"; then
848025dbecb6Smrg	      soname=$dlname
8481b68e1f86Smrg	    elif test -n "$soname_spec"; then
8482b68e1f86Smrg	      # bleh windows
8483b68e1f86Smrg	      case $host in
848425dbecb6Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8485b68e1f86Smrg	        func_arith $current - $age
8486b68e1f86Smrg		major=$func_arith_result
848725dbecb6Smrg		versuffix=-$major
8488b68e1f86Smrg		;;
8489b68e1f86Smrg	      esac
8490b68e1f86Smrg	      eval soname=\"$soname_spec\"
8491b68e1f86Smrg	    else
849225dbecb6Smrg	      soname=$realname
8493b68e1f86Smrg	    fi
8494b68e1f86Smrg
8495b68e1f86Smrg	    # Make a new name for the extract_expsyms_cmds to use
849625dbecb6Smrg	    soroot=$soname
8497b68e1f86Smrg	    func_basename "$soroot"
849825dbecb6Smrg	    soname=$func_basename_result
8499b68e1f86Smrg	    func_stripname 'lib' '.dll' "$soname"
8500b68e1f86Smrg	    newlib=libimp-$func_stripname_result.a
8501b68e1f86Smrg
8502b68e1f86Smrg	    # If the library has no export list, then create one now
8503b68e1f86Smrg	    if test -f "$output_objdir/$soname-def"; then :
8504b68e1f86Smrg	    else
850525dbecb6Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8506b68e1f86Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8507b68e1f86Smrg	    fi
8508b68e1f86Smrg
8509b68e1f86Smrg	    # Create $newlib
8510b68e1f86Smrg	    if test -f "$output_objdir/$newlib"; then :; else
851125dbecb6Smrg	      func_verbose "generating import library for '$soname'"
8512b68e1f86Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8513b68e1f86Smrg	    fi
8514b68e1f86Smrg	    # make sure the library variables are pointing to the new library
8515b68e1f86Smrg	    dir=$output_objdir
8516b68e1f86Smrg	    linklib=$newlib
8517b68e1f86Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8518b68e1f86Smrg
851925dbecb6Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8520b68e1f86Smrg	    add_shlibpath=
8521b68e1f86Smrg	    add_dir=
8522b68e1f86Smrg	    add=
8523b68e1f86Smrg	    lib_linked=yes
8524b68e1f86Smrg	    case $hardcode_action in
8525b68e1f86Smrg	    immediate | unsupported)
852625dbecb6Smrg	      if test no = "$hardcode_direct"; then
852725dbecb6Smrg		add=$dir/$linklib
8528b68e1f86Smrg		case $host in
852925dbecb6Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
853025dbecb6Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8531b68e1f86Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
853225dbecb6Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8533b68e1f86Smrg		  *-*-darwin* )
853425dbecb6Smrg		    # if the lib is a (non-dlopened) module then we cannot
8535b68e1f86Smrg		    # link against it, someone is ignoring the earlier warnings
8536b68e1f86Smrg		    if /usr/bin/file -L $add 2> /dev/null |
853725dbecb6Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8538b68e1f86Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8539b68e1f86Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
854025dbecb6Smrg			if test -z "$old_library"; then
85413bfa90b6Smrg			  echo
85423bfa90b6Smrg			  echo "*** And there doesn't seem to be a static archive available"
85433bfa90b6Smrg			  echo "*** The link will probably fail, sorry"
8544b68e1f86Smrg			else
854525dbecb6Smrg			  add=$dir/$old_library
8546b68e1f86Smrg			fi
8547b68e1f86Smrg		      elif test -n "$old_library"; then
854825dbecb6Smrg			add=$dir/$old_library
8549b68e1f86Smrg		      fi
8550b68e1f86Smrg		    fi
8551b68e1f86Smrg		esac
855225dbecb6Smrg	      elif test no = "$hardcode_minus_L"; then
8553b68e1f86Smrg		case $host in
855425dbecb6Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8555b68e1f86Smrg		esac
855625dbecb6Smrg		add_dir=-L$dir
855725dbecb6Smrg		add=-l$name
855825dbecb6Smrg	      elif test no = "$hardcode_shlibpath_var"; then
855925dbecb6Smrg		add_shlibpath=$dir
856025dbecb6Smrg		add=-l$name
8561b68e1f86Smrg	      else
8562b68e1f86Smrg		lib_linked=no
8563b68e1f86Smrg	      fi
8564b68e1f86Smrg	      ;;
8565b68e1f86Smrg	    relink)
856625dbecb6Smrg	      if test yes = "$hardcode_direct" &&
856725dbecb6Smrg	         test no = "$hardcode_direct_absolute"; then
856825dbecb6Smrg		add=$dir/$linklib
856925dbecb6Smrg	      elif test yes = "$hardcode_minus_L"; then
857025dbecb6Smrg		add_dir=-L$absdir
8571b68e1f86Smrg		# Try looking first in the location we're being installed to.
8572b68e1f86Smrg		if test -n "$inst_prefix_dir"; then
8573b68e1f86Smrg		  case $libdir in
8574b68e1f86Smrg		    [\\/]*)
85753bfa90b6Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8576b68e1f86Smrg		      ;;
8577b68e1f86Smrg		  esac
8578b68e1f86Smrg		fi
857925dbecb6Smrg		add=-l$name
858025dbecb6Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
858125dbecb6Smrg		add_shlibpath=$dir
858225dbecb6Smrg		add=-l$name
8583b68e1f86Smrg	      else
8584b68e1f86Smrg		lib_linked=no
8585b68e1f86Smrg	      fi
8586b68e1f86Smrg	      ;;
8587b68e1f86Smrg	    *) lib_linked=no ;;
8588b68e1f86Smrg	    esac
8589b68e1f86Smrg
859025dbecb6Smrg	    if test yes != "$lib_linked"; then
8591b68e1f86Smrg	      func_fatal_configuration "unsupported hardcode properties"
8592b68e1f86Smrg	    fi
8593b68e1f86Smrg
8594b68e1f86Smrg	    if test -n "$add_shlibpath"; then
8595b68e1f86Smrg	      case :$compile_shlibpath: in
8596b68e1f86Smrg	      *":$add_shlibpath:"*) ;;
85973bfa90b6Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8598b68e1f86Smrg	      esac
8599b68e1f86Smrg	    fi
860025dbecb6Smrg	    if test prog = "$linkmode"; then
8601b68e1f86Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8602b68e1f86Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8603b68e1f86Smrg	    else
8604b68e1f86Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8605b68e1f86Smrg	      test -n "$add" && deplibs="$add $deplibs"
860625dbecb6Smrg	      if test yes != "$hardcode_direct" &&
860725dbecb6Smrg		 test yes != "$hardcode_minus_L" &&
860825dbecb6Smrg		 test yes = "$hardcode_shlibpath_var"; then
8609b68e1f86Smrg		case :$finalize_shlibpath: in
8610b68e1f86Smrg		*":$libdir:"*) ;;
86113bfa90b6Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8612b68e1f86Smrg		esac
8613b68e1f86Smrg	      fi
8614b68e1f86Smrg	    fi
8615b68e1f86Smrg	  fi
8616b68e1f86Smrg
861725dbecb6Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8618b68e1f86Smrg	    add_shlibpath=
8619b68e1f86Smrg	    add_dir=
8620b68e1f86Smrg	    add=
8621b68e1f86Smrg	    # Finalize command for both is simple: just hardcode it.
862225dbecb6Smrg	    if test yes = "$hardcode_direct" &&
862325dbecb6Smrg	       test no = "$hardcode_direct_absolute"; then
862425dbecb6Smrg	      add=$libdir/$linklib
862525dbecb6Smrg	    elif test yes = "$hardcode_minus_L"; then
862625dbecb6Smrg	      add_dir=-L$libdir
862725dbecb6Smrg	      add=-l$name
862825dbecb6Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8629b68e1f86Smrg	      case :$finalize_shlibpath: in
8630b68e1f86Smrg	      *":$libdir:"*) ;;
86313bfa90b6Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8632b68e1f86Smrg	      esac
863325dbecb6Smrg	      add=-l$name
863425dbecb6Smrg	    elif test yes = "$hardcode_automatic"; then
8635b68e1f86Smrg	      if test -n "$inst_prefix_dir" &&
863625dbecb6Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
863725dbecb6Smrg		add=$inst_prefix_dir$libdir/$linklib
8638b68e1f86Smrg	      else
863925dbecb6Smrg		add=$libdir/$linklib
8640b68e1f86Smrg	      fi
8641b68e1f86Smrg	    else
8642b68e1f86Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
864325dbecb6Smrg	      add_dir=-L$libdir
8644b68e1f86Smrg	      # Try looking first in the location we're being installed to.
8645b68e1f86Smrg	      if test -n "$inst_prefix_dir"; then
8646b68e1f86Smrg		case $libdir in
8647b68e1f86Smrg		  [\\/]*)
86483bfa90b6Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8649b68e1f86Smrg		    ;;
8650b68e1f86Smrg		esac
8651b68e1f86Smrg	      fi
865225dbecb6Smrg	      add=-l$name
8653b68e1f86Smrg	    fi
8654b68e1f86Smrg
865525dbecb6Smrg	    if test prog = "$linkmode"; then
8656b68e1f86Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8657b68e1f86Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8658b68e1f86Smrg	    else
8659b68e1f86Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8660b68e1f86Smrg	      test -n "$add" && deplibs="$add $deplibs"
8661b68e1f86Smrg	    fi
8662b68e1f86Smrg	  fi
866325dbecb6Smrg	elif test prog = "$linkmode"; then
8664b68e1f86Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8665b68e1f86Smrg	  # is not unsupported.  This is valid on all known static and
8666b68e1f86Smrg	  # shared platforms.
866725dbecb6Smrg	  if test unsupported != "$hardcode_direct"; then
866825dbecb6Smrg	    test -n "$old_library" && linklib=$old_library
8669b68e1f86Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8670b68e1f86Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8671b68e1f86Smrg	  else
8672b68e1f86Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8673b68e1f86Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8674b68e1f86Smrg	  fi
867525dbecb6Smrg	elif test yes = "$build_libtool_libs"; then
8676b68e1f86Smrg	  # Not a shared library
867725dbecb6Smrg	  if test pass_all != "$deplibs_check_method"; then
8678b68e1f86Smrg	    # We're trying link a shared library against a static one
8679b68e1f86Smrg	    # but the system doesn't support it.
8680b68e1f86Smrg
8681b68e1f86Smrg	    # Just print a warning and add the library to dependency_libs so
8682b68e1f86Smrg	    # that the program can be linked against the static library.
86833bfa90b6Smrg	    echo
868425dbecb6Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
86853bfa90b6Smrg	    echo "*** I have the capability to make that library automatically link in when"
86863bfa90b6Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
86873bfa90b6Smrg	    echo "*** shared version of the library, which you do not appear to have."
868825dbecb6Smrg	    if test yes = "$module"; then
86893bfa90b6Smrg	      echo "*** But as you try to build a module library, libtool will still create "
86903bfa90b6Smrg	      echo "*** a static module, that should work as long as the dlopening application"
86913bfa90b6Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8692b68e1f86Smrg	      if test -z "$global_symbol_pipe"; then
86933bfa90b6Smrg		echo
86943bfa90b6Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
869525dbecb6Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
86963bfa90b6Smrg		echo "*** not find such a program.  So, this module is probably useless."
869725dbecb6Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8698b68e1f86Smrg	      fi
869925dbecb6Smrg	      if test no = "$build_old_libs"; then
8700b68e1f86Smrg		build_libtool_libs=module
8701b68e1f86Smrg		build_old_libs=yes
8702b68e1f86Smrg	      else
8703b68e1f86Smrg		build_libtool_libs=no
8704b68e1f86Smrg	      fi
8705b68e1f86Smrg	    fi
8706b68e1f86Smrg	  else
8707b68e1f86Smrg	    deplibs="$dir/$old_library $deplibs"
8708b68e1f86Smrg	    link_static=yes
8709b68e1f86Smrg	  fi
8710b68e1f86Smrg	fi # link shared/static library?
8711b68e1f86Smrg
871225dbecb6Smrg	if test lib = "$linkmode"; then
8713b68e1f86Smrg	  if test -n "$dependency_libs" &&
871425dbecb6Smrg	     { test yes != "$hardcode_into_libs" ||
871525dbecb6Smrg	       test yes = "$build_old_libs" ||
871625dbecb6Smrg	       test yes = "$link_static"; }; then
8717b68e1f86Smrg	    # Extract -R from dependency_libs
8718b68e1f86Smrg	    temp_deplibs=
8719b68e1f86Smrg	    for libdir in $dependency_libs; do
8720b68e1f86Smrg	      case $libdir in
8721b68e1f86Smrg	      -R*) func_stripname '-R' '' "$libdir"
8722b68e1f86Smrg	           temp_xrpath=$func_stripname_result
8723b68e1f86Smrg		   case " $xrpath " in
8724b68e1f86Smrg		   *" $temp_xrpath "*) ;;
87253bfa90b6Smrg		   *) func_append xrpath " $temp_xrpath";;
8726b68e1f86Smrg		   esac;;
87273bfa90b6Smrg	      *) func_append temp_deplibs " $libdir";;
8728b68e1f86Smrg	      esac
8729b68e1f86Smrg	    done
873025dbecb6Smrg	    dependency_libs=$temp_deplibs
8731b68e1f86Smrg	  fi
8732b68e1f86Smrg
87333bfa90b6Smrg	  func_append newlib_search_path " $absdir"
8734b68e1f86Smrg	  # Link against this library
873525dbecb6Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8736b68e1f86Smrg	  # ... and its dependency_libs
8737b68e1f86Smrg	  tmp_libs=
8738b68e1f86Smrg	  for deplib in $dependency_libs; do
8739b68e1f86Smrg	    newdependency_libs="$deplib $newdependency_libs"
87403bfa90b6Smrg	    case $deplib in
87413bfa90b6Smrg              -L*) func_stripname '-L' '' "$deplib"
87423bfa90b6Smrg                   func_resolve_sysroot "$func_stripname_result";;
87433bfa90b6Smrg              *) func_resolve_sysroot "$deplib" ;;
87443bfa90b6Smrg            esac
874525dbecb6Smrg	    if $opt_preserve_dup_deps; then
8746b68e1f86Smrg	      case "$tmp_libs " in
87473bfa90b6Smrg	      *" $func_resolve_sysroot_result "*)
87483bfa90b6Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8749b68e1f86Smrg	      esac
8750b68e1f86Smrg	    fi
87513bfa90b6Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8752b68e1f86Smrg	  done
8753b68e1f86Smrg
875425dbecb6Smrg	  if test no != "$link_all_deplibs"; then
8755b68e1f86Smrg	    # Add the search paths of all dependency libraries
8756b68e1f86Smrg	    for deplib in $dependency_libs; do
87573bfa90b6Smrg	      path=
8758b68e1f86Smrg	      case $deplib in
875925dbecb6Smrg	      -L*) path=$deplib ;;
8760b68e1f86Smrg	      *.la)
87613bfa90b6Smrg	        func_resolve_sysroot "$deplib"
87623bfa90b6Smrg	        deplib=$func_resolve_sysroot_result
8763b68e1f86Smrg	        func_dirname "$deplib" "" "."
87643bfa90b6Smrg		dir=$func_dirname_result
8765b68e1f86Smrg		# We need an absolute path.
8766b68e1f86Smrg		case $dir in
876725dbecb6Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8768b68e1f86Smrg		*)
8769b68e1f86Smrg		  absdir=`cd "$dir" && pwd`
8770b68e1f86Smrg		  if test -z "$absdir"; then
877125dbecb6Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
877225dbecb6Smrg		    absdir=$dir
8773b68e1f86Smrg		  fi
8774b68e1f86Smrg		  ;;
8775b68e1f86Smrg		esac
8776b68e1f86Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8777b68e1f86Smrg		case $host in
8778b68e1f86Smrg		*-*-darwin*)
8779b68e1f86Smrg		  depdepl=
878025dbecb6Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
878125dbecb6Smrg		  if test -n "$deplibrary_names"; then
878225dbecb6Smrg		    for tmp in $deplibrary_names; do
8783b68e1f86Smrg		      depdepl=$tmp
8784b68e1f86Smrg		    done
878525dbecb6Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
878625dbecb6Smrg		      depdepl=$absdir/$objdir/$depdepl
878725dbecb6Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8788b68e1f86Smrg                      if test -z "$darwin_install_name"; then
878925dbecb6Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8790b68e1f86Smrg                      fi
879125dbecb6Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
879225dbecb6Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8793b68e1f86Smrg		      path=
8794b68e1f86Smrg		    fi
8795b68e1f86Smrg		  fi
8796b68e1f86Smrg		  ;;
8797b68e1f86Smrg		*)
879825dbecb6Smrg		  path=-L$absdir/$objdir
8799b68e1f86Smrg		  ;;
8800b68e1f86Smrg		esac
8801b68e1f86Smrg		else
880225dbecb6Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8803b68e1f86Smrg		  test -z "$libdir" && \
880425dbecb6Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8805b68e1f86Smrg		  test "$absdir" != "$libdir" && \
880625dbecb6Smrg		    func_warning "'$deplib' seems to be moved"
8807b68e1f86Smrg
880825dbecb6Smrg		  path=-L$absdir
8809b68e1f86Smrg		fi
8810b68e1f86Smrg		;;
8811b68e1f86Smrg	      esac
8812b68e1f86Smrg	      case " $deplibs " in
8813b68e1f86Smrg	      *" $path "*) ;;
8814b68e1f86Smrg	      *) deplibs="$path $deplibs" ;;
8815b68e1f86Smrg	      esac
8816b68e1f86Smrg	    done
8817b68e1f86Smrg	  fi # link_all_deplibs != no
8818b68e1f86Smrg	fi # linkmode = lib
8819b68e1f86Smrg      done # for deplib in $libs
882025dbecb6Smrg      if test link = "$pass"; then
882125dbecb6Smrg	if test prog = "$linkmode"; then
8822b68e1f86Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8823b68e1f86Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8824b68e1f86Smrg	else
88253bfa90b6Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8826b68e1f86Smrg	fi
8827b68e1f86Smrg      fi
882825dbecb6Smrg      dependency_libs=$newdependency_libs
882925dbecb6Smrg      if test dlpreopen = "$pass"; then
8830b68e1f86Smrg	# Link the dlpreopened libraries before other libraries
8831b68e1f86Smrg	for deplib in $save_deplibs; do
8832b68e1f86Smrg	  deplibs="$deplib $deplibs"
8833b68e1f86Smrg	done
8834b68e1f86Smrg      fi
883525dbecb6Smrg      if test dlopen != "$pass"; then
883625dbecb6Smrg	test conv = "$pass" || {
8837b68e1f86Smrg	  # Make sure lib_search_path contains only unique directories.
8838b68e1f86Smrg	  lib_search_path=
8839b68e1f86Smrg	  for dir in $newlib_search_path; do
8840b68e1f86Smrg	    case "$lib_search_path " in
8841b68e1f86Smrg	    *" $dir "*) ;;
88423bfa90b6Smrg	    *) func_append lib_search_path " $dir" ;;
8843b68e1f86Smrg	    esac
8844b68e1f86Smrg	  done
8845b68e1f86Smrg	  newlib_search_path=
884625dbecb6Smrg	}
8847b68e1f86Smrg
884825dbecb6Smrg	if test prog,link = "$linkmode,$pass"; then
8849b68e1f86Smrg	  vars="compile_deplibs finalize_deplibs"
885025dbecb6Smrg	else
885125dbecb6Smrg	  vars=deplibs
8852b68e1f86Smrg	fi
8853b68e1f86Smrg	for var in $vars dependency_libs; do
8854b68e1f86Smrg	  # Add libraries to $var in reverse order
8855b68e1f86Smrg	  eval tmp_libs=\"\$$var\"
8856b68e1f86Smrg	  new_libs=
8857b68e1f86Smrg	  for deplib in $tmp_libs; do
8858b68e1f86Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8859b68e1f86Smrg	    #        that some nasty dependency loop isn't accidentally
8860b68e1f86Smrg	    #        broken:
8861b68e1f86Smrg	    #new_libs="$deplib $new_libs"
8862b68e1f86Smrg	    # Pragmatically, this seems to cause very few problems in
8863b68e1f86Smrg	    # practice:
8864b68e1f86Smrg	    case $deplib in
8865b68e1f86Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8866b68e1f86Smrg	    -R*) ;;
8867b68e1f86Smrg	    *)
8868b68e1f86Smrg	      # And here is the reason: when a library appears more
8869b68e1f86Smrg	      # than once as an explicit dependence of a library, or
8870b68e1f86Smrg	      # is implicitly linked in more than once by the
8871b68e1f86Smrg	      # compiler, it is considered special, and multiple
8872b68e1f86Smrg	      # occurrences thereof are not removed.  Compare this
8873b68e1f86Smrg	      # with having the same library being listed as a
8874b68e1f86Smrg	      # dependency of multiple other libraries: in this case,
8875b68e1f86Smrg	      # we know (pedantically, we assume) the library does not
8876b68e1f86Smrg	      # need to be listed more than once, so we keep only the
8877b68e1f86Smrg	      # last copy.  This is not always right, but it is rare
8878b68e1f86Smrg	      # enough that we require users that really mean to play
8879b68e1f86Smrg	      # such unportable linking tricks to link the library
8880b68e1f86Smrg	      # using -Wl,-lname, so that libtool does not consider it
8881b68e1f86Smrg	      # for duplicate removal.
8882b68e1f86Smrg	      case " $specialdeplibs " in
8883b68e1f86Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8884b68e1f86Smrg	      *)
8885b68e1f86Smrg		case " $new_libs " in
8886b68e1f86Smrg		*" $deplib "*) ;;
8887b68e1f86Smrg		*) new_libs="$deplib $new_libs" ;;
8888b68e1f86Smrg		esac
8889b68e1f86Smrg		;;
8890b68e1f86Smrg	      esac
8891b68e1f86Smrg	      ;;
8892b68e1f86Smrg	    esac
8893b68e1f86Smrg	  done
8894b68e1f86Smrg	  tmp_libs=
8895b68e1f86Smrg	  for deplib in $new_libs; do
8896b68e1f86Smrg	    case $deplib in
8897b68e1f86Smrg	    -L*)
8898b68e1f86Smrg	      case " $tmp_libs " in
8899b68e1f86Smrg	      *" $deplib "*) ;;
89003bfa90b6Smrg	      *) func_append tmp_libs " $deplib" ;;
8901b68e1f86Smrg	      esac
8902b68e1f86Smrg	      ;;
89033bfa90b6Smrg	    *) func_append tmp_libs " $deplib" ;;
8904b68e1f86Smrg	    esac
8905b68e1f86Smrg	  done
8906b68e1f86Smrg	  eval $var=\"$tmp_libs\"
8907b68e1f86Smrg	done # for var
8908b68e1f86Smrg      fi
890925dbecb6Smrg
891025dbecb6Smrg      # Add Sun CC postdeps if required:
891125dbecb6Smrg      test CXX = "$tagname" && {
891225dbecb6Smrg        case $host_os in
891325dbecb6Smrg        linux*)
891425dbecb6Smrg          case `$CC -V 2>&1 | $SED 5q` in
891525dbecb6Smrg          *Sun\ C*) # Sun C++ 5.9
891625dbecb6Smrg            func_suncc_cstd_abi
891725dbecb6Smrg
891825dbecb6Smrg            if test no != "$suncc_use_cstd_abi"; then
891925dbecb6Smrg              func_append postdeps ' -library=Cstd -library=Crun'
892025dbecb6Smrg            fi
892125dbecb6Smrg            ;;
892225dbecb6Smrg          esac
892325dbecb6Smrg          ;;
892425dbecb6Smrg
892525dbecb6Smrg        solaris*)
892625dbecb6Smrg          func_cc_basename "$CC"
892725dbecb6Smrg          case $func_cc_basename_result in
892825dbecb6Smrg          CC* | sunCC*)
892925dbecb6Smrg            func_suncc_cstd_abi
893025dbecb6Smrg
893125dbecb6Smrg            if test no != "$suncc_use_cstd_abi"; then
893225dbecb6Smrg              func_append postdeps ' -library=Cstd -library=Crun'
893325dbecb6Smrg            fi
893425dbecb6Smrg            ;;
893525dbecb6Smrg          esac
893625dbecb6Smrg          ;;
893725dbecb6Smrg        esac
893825dbecb6Smrg      }
893925dbecb6Smrg
8940b68e1f86Smrg      # Last step: remove runtime libs from dependency_libs
8941b68e1f86Smrg      # (they stay in deplibs)
8942b68e1f86Smrg      tmp_libs=
894325dbecb6Smrg      for i in $dependency_libs; do
8944b68e1f86Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8945b68e1f86Smrg	*" $i "*)
894625dbecb6Smrg	  i=
8947b68e1f86Smrg	  ;;
8948b68e1f86Smrg	esac
894925dbecb6Smrg	if test -n "$i"; then
89503bfa90b6Smrg	  func_append tmp_libs " $i"
8951b68e1f86Smrg	fi
8952b68e1f86Smrg      done
8953b68e1f86Smrg      dependency_libs=$tmp_libs
8954b68e1f86Smrg    done # for pass
895525dbecb6Smrg    if test prog = "$linkmode"; then
895625dbecb6Smrg      dlfiles=$newdlfiles
8957b68e1f86Smrg    fi
895825dbecb6Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
895925dbecb6Smrg      dlprefiles=$newdlprefiles
8960b68e1f86Smrg    fi
8961b68e1f86Smrg
8962b68e1f86Smrg    case $linkmode in
8963b68e1f86Smrg    oldlib)
896425dbecb6Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
896525dbecb6Smrg	func_warning "'-dlopen' is ignored for archives"
8966b68e1f86Smrg      fi
8967b68e1f86Smrg
8968b68e1f86Smrg      case " $deplibs" in
8969b68e1f86Smrg      *\ -l* | *\ -L*)
897025dbecb6Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8971b68e1f86Smrg      esac
8972b68e1f86Smrg
8973b68e1f86Smrg      test -n "$rpath" && \
897425dbecb6Smrg	func_warning "'-rpath' is ignored for archives"
8975b68e1f86Smrg
8976b68e1f86Smrg      test -n "$xrpath" && \
897725dbecb6Smrg	func_warning "'-R' is ignored for archives"
8978b68e1f86Smrg
8979b68e1f86Smrg      test -n "$vinfo" && \
898025dbecb6Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
8981b68e1f86Smrg
8982b68e1f86Smrg      test -n "$release" && \
898325dbecb6Smrg	func_warning "'-release' is ignored for archives"
8984b68e1f86Smrg
8985b68e1f86Smrg      test -n "$export_symbols$export_symbols_regex" && \
898625dbecb6Smrg	func_warning "'-export-symbols' is ignored for archives"
8987b68e1f86Smrg
8988b68e1f86Smrg      # Now set the variables for building old libraries.
8989b68e1f86Smrg      build_libtool_libs=no
899025dbecb6Smrg      oldlibs=$output
89913bfa90b6Smrg      func_append objs "$old_deplibs"
8992b68e1f86Smrg      ;;
8993b68e1f86Smrg
8994b68e1f86Smrg    lib)
899525dbecb6Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
8996b68e1f86Smrg      case $outputname in
8997b68e1f86Smrg      lib*)
8998b68e1f86Smrg	func_stripname 'lib' '.la' "$outputname"
8999b68e1f86Smrg	name=$func_stripname_result
9000b68e1f86Smrg	eval shared_ext=\"$shrext_cmds\"
9001b68e1f86Smrg	eval libname=\"$libname_spec\"
9002b68e1f86Smrg	;;
9003b68e1f86Smrg      *)
900425dbecb6Smrg	test no = "$module" \
900525dbecb6Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9006b68e1f86Smrg
900725dbecb6Smrg	if test no != "$need_lib_prefix"; then
9008b68e1f86Smrg	  # Add the "lib" prefix for modules if required
9009b68e1f86Smrg	  func_stripname '' '.la' "$outputname"
9010b68e1f86Smrg	  name=$func_stripname_result
9011b68e1f86Smrg	  eval shared_ext=\"$shrext_cmds\"
9012b68e1f86Smrg	  eval libname=\"$libname_spec\"
9013b68e1f86Smrg	else
9014b68e1f86Smrg	  func_stripname '' '.la' "$outputname"
9015b68e1f86Smrg	  libname=$func_stripname_result
9016b68e1f86Smrg	fi
9017b68e1f86Smrg	;;
9018b68e1f86Smrg      esac
9019b68e1f86Smrg
9020b68e1f86Smrg      if test -n "$objs"; then
902125dbecb6Smrg	if test pass_all != "$deplibs_check_method"; then
902225dbecb6Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9023b68e1f86Smrg	else
90243bfa90b6Smrg	  echo
9025b68e1f86Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9026b68e1f86Smrg	  $ECHO "*** objects $objs is not portable!"
90273bfa90b6Smrg	  func_append libobjs " $objs"
9028b68e1f86Smrg	fi
9029b68e1f86Smrg      fi
9030b68e1f86Smrg
903125dbecb6Smrg      test no = "$dlself" \
903225dbecb6Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9033b68e1f86Smrg
9034b68e1f86Smrg      set dummy $rpath
9035b68e1f86Smrg      shift
903625dbecb6Smrg      test 1 -lt "$#" \
903725dbecb6Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9038b68e1f86Smrg
903925dbecb6Smrg      install_libdir=$1
9040b68e1f86Smrg
9041b68e1f86Smrg      oldlibs=
9042b68e1f86Smrg      if test -z "$rpath"; then
904325dbecb6Smrg	if test yes = "$build_libtool_libs"; then
9044b68e1f86Smrg	  # Building a libtool convenience library.
904525dbecb6Smrg	  # Some compilers have problems with a '.al' extension so
9046b68e1f86Smrg	  # convenience libraries should have the same extension an
9047b68e1f86Smrg	  # archive normally would.
9048b68e1f86Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9049b68e1f86Smrg	  build_libtool_libs=convenience
9050b68e1f86Smrg	  build_old_libs=yes
9051b68e1f86Smrg	fi
9052b68e1f86Smrg
9053b68e1f86Smrg	test -n "$vinfo" && \
905425dbecb6Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9055b68e1f86Smrg
9056b68e1f86Smrg	test -n "$release" && \
905725dbecb6Smrg	  func_warning "'-release' is ignored for convenience libraries"
9058b68e1f86Smrg      else
9059b68e1f86Smrg
9060b68e1f86Smrg	# Parse the version information argument.
906125dbecb6Smrg	save_ifs=$IFS; IFS=:
9062b68e1f86Smrg	set dummy $vinfo 0 0 0
9063b68e1f86Smrg	shift
906425dbecb6Smrg	IFS=$save_ifs
9065b68e1f86Smrg
9066b68e1f86Smrg	test -n "$7" && \
906725dbecb6Smrg	  func_fatal_help "too many parameters to '-version-info'"
9068b68e1f86Smrg
9069b68e1f86Smrg	# convert absolute version numbers to libtool ages
9070b68e1f86Smrg	# this retains compatibility with .la files and attempts
9071b68e1f86Smrg	# to make the code below a bit more comprehensible
9072b68e1f86Smrg
9073b68e1f86Smrg	case $vinfo_number in
9074b68e1f86Smrg	yes)
907525dbecb6Smrg	  number_major=$1
907625dbecb6Smrg	  number_minor=$2
907725dbecb6Smrg	  number_revision=$3
9078b68e1f86Smrg	  #
9079b68e1f86Smrg	  # There are really only two kinds -- those that
9080b68e1f86Smrg	  # use the current revision as the major version
9081b68e1f86Smrg	  # and those that subtract age and use age as
9082b68e1f86Smrg	  # a minor version.  But, then there is irix
908325dbecb6Smrg	  # that has an extra 1 added just for fun
9084b68e1f86Smrg	  #
9085b68e1f86Smrg	  case $version_type in
90863bfa90b6Smrg	  # correct linux to gnu/linux during the next big refactor
908725dbecb6Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9088b68e1f86Smrg	    func_arith $number_major + $number_minor
9089b68e1f86Smrg	    current=$func_arith_result
909025dbecb6Smrg	    age=$number_minor
909125dbecb6Smrg	    revision=$number_revision
9092b68e1f86Smrg	    ;;
909325dbecb6Smrg	  freebsd-aout|qnx|sunos)
909425dbecb6Smrg	    current=$number_major
909525dbecb6Smrg	    revision=$number_minor
909625dbecb6Smrg	    age=0
9097b68e1f86Smrg	    ;;
9098b68e1f86Smrg	  irix|nonstopux)
9099b68e1f86Smrg	    func_arith $number_major + $number_minor
9100b68e1f86Smrg	    current=$func_arith_result
910125dbecb6Smrg	    age=$number_minor
910225dbecb6Smrg	    revision=$number_minor
9103b68e1f86Smrg	    lt_irix_increment=no
9104b68e1f86Smrg	    ;;
9105b68e1f86Smrg	  esac
9106b68e1f86Smrg	  ;;
9107b68e1f86Smrg	no)
910825dbecb6Smrg	  current=$1
910925dbecb6Smrg	  revision=$2
911025dbecb6Smrg	  age=$3
9111b68e1f86Smrg	  ;;
9112b68e1f86Smrg	esac
9113b68e1f86Smrg
9114b68e1f86Smrg	# Check that each of the things are valid numbers.
9115b68e1f86Smrg	case $current in
9116b68e1f86Smrg	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]) ;;
9117b68e1f86Smrg	*)
911825dbecb6Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
911925dbecb6Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9120b68e1f86Smrg	  ;;
9121b68e1f86Smrg	esac
9122b68e1f86Smrg
9123b68e1f86Smrg	case $revision in
9124b68e1f86Smrg	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]) ;;
9125b68e1f86Smrg	*)
912625dbecb6Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
912725dbecb6Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9128b68e1f86Smrg	  ;;
9129b68e1f86Smrg	esac
9130b68e1f86Smrg
9131b68e1f86Smrg	case $age in
9132b68e1f86Smrg	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]) ;;
9133b68e1f86Smrg	*)
913425dbecb6Smrg	  func_error "AGE '$age' must be a nonnegative integer"
913525dbecb6Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9136b68e1f86Smrg	  ;;
9137b68e1f86Smrg	esac
9138b68e1f86Smrg
9139b68e1f86Smrg	if test "$age" -gt "$current"; then
914025dbecb6Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
914125dbecb6Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9142b68e1f86Smrg	fi
9143b68e1f86Smrg
9144b68e1f86Smrg	# Calculate the version variables.
9145b68e1f86Smrg	major=
9146b68e1f86Smrg	versuffix=
9147b68e1f86Smrg	verstring=
9148b68e1f86Smrg	case $version_type in
9149b68e1f86Smrg	none) ;;
9150b68e1f86Smrg
9151b68e1f86Smrg	darwin)
9152b68e1f86Smrg	  # Like Linux, but with the current version available in
9153b68e1f86Smrg	  # verstring for coding it into the library header
9154b68e1f86Smrg	  func_arith $current - $age
9155b68e1f86Smrg	  major=.$func_arith_result
915625dbecb6Smrg	  versuffix=$major.$age.$revision
9157b68e1f86Smrg	  # Darwin ld doesn't like 0 for these options...
9158b68e1f86Smrg	  func_arith $current + 1
9159b68e1f86Smrg	  minor_current=$func_arith_result
916025dbecb6Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9161b68e1f86Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
916225dbecb6Smrg          # On Darwin other compilers
916325dbecb6Smrg          case $CC in
916425dbecb6Smrg              nagfor*)
916525dbecb6Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
916625dbecb6Smrg                  ;;
916725dbecb6Smrg              *)
916825dbecb6Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
916925dbecb6Smrg                  ;;
917025dbecb6Smrg          esac
9171b68e1f86Smrg	  ;;
9172b68e1f86Smrg
9173b68e1f86Smrg	freebsd-aout)
917425dbecb6Smrg	  major=.$current
917525dbecb6Smrg	  versuffix=.$current.$revision
9176b68e1f86Smrg	  ;;
9177b68e1f86Smrg
917825dbecb6Smrg	freebsd-elf | midnightbsd-elf)
917925dbecb6Smrg	  func_arith $current - $age
918025dbecb6Smrg	  major=.$func_arith_result
918125dbecb6Smrg	  versuffix=$major.$age.$revision
9182b68e1f86Smrg	  ;;
9183b68e1f86Smrg
9184b68e1f86Smrg	irix | nonstopux)
918525dbecb6Smrg	  if test no = "$lt_irix_increment"; then
9186b68e1f86Smrg	    func_arith $current - $age
9187b68e1f86Smrg	  else
9188b68e1f86Smrg	    func_arith $current - $age + 1
9189b68e1f86Smrg	  fi
9190b68e1f86Smrg	  major=$func_arith_result
9191b68e1f86Smrg
9192b68e1f86Smrg	  case $version_type in
9193b68e1f86Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9194b68e1f86Smrg	    *)         verstring_prefix=sgi ;;
9195b68e1f86Smrg	  esac
919625dbecb6Smrg	  verstring=$verstring_prefix$major.$revision
9197b68e1f86Smrg
9198b68e1f86Smrg	  # Add in all the interfaces that we are compatible with.
9199b68e1f86Smrg	  loop=$revision
920025dbecb6Smrg	  while test 0 -ne "$loop"; do
9201b68e1f86Smrg	    func_arith $revision - $loop
9202b68e1f86Smrg	    iface=$func_arith_result
9203b68e1f86Smrg	    func_arith $loop - 1
9204b68e1f86Smrg	    loop=$func_arith_result
920525dbecb6Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
9206b68e1f86Smrg	  done
9207b68e1f86Smrg
920825dbecb6Smrg	  # Before this point, $major must not contain '.'.
9209b68e1f86Smrg	  major=.$major
921025dbecb6Smrg	  versuffix=$major.$revision
9211b68e1f86Smrg	  ;;
9212b68e1f86Smrg
92133bfa90b6Smrg	linux) # correct to gnu/linux during the next big refactor
9214b68e1f86Smrg	  func_arith $current - $age
9215b68e1f86Smrg	  major=.$func_arith_result
921625dbecb6Smrg	  versuffix=$major.$age.$revision
9217b68e1f86Smrg	  ;;
9218b68e1f86Smrg
9219b68e1f86Smrg	osf)
9220b68e1f86Smrg	  func_arith $current - $age
9221b68e1f86Smrg	  major=.$func_arith_result
922225dbecb6Smrg	  versuffix=.$current.$age.$revision
922325dbecb6Smrg	  verstring=$current.$age.$revision
9224b68e1f86Smrg
9225b68e1f86Smrg	  # Add in all the interfaces that we are compatible with.
9226b68e1f86Smrg	  loop=$age
922725dbecb6Smrg	  while test 0 -ne "$loop"; do
9228b68e1f86Smrg	    func_arith $current - $loop
9229b68e1f86Smrg	    iface=$func_arith_result
9230b68e1f86Smrg	    func_arith $loop - 1
9231b68e1f86Smrg	    loop=$func_arith_result
923225dbecb6Smrg	    verstring=$verstring:$iface.0
9233b68e1f86Smrg	  done
9234b68e1f86Smrg
9235b68e1f86Smrg	  # Make executables depend on our current version.
923625dbecb6Smrg	  func_append verstring ":$current.0"
9237b68e1f86Smrg	  ;;
9238b68e1f86Smrg
9239b68e1f86Smrg	qnx)
924025dbecb6Smrg	  major=.$current
924125dbecb6Smrg	  versuffix=.$current
924225dbecb6Smrg	  ;;
924325dbecb6Smrg
924425dbecb6Smrg	sco)
924525dbecb6Smrg	  major=.$current
924625dbecb6Smrg	  versuffix=.$current
9247b68e1f86Smrg	  ;;
9248b68e1f86Smrg
9249b68e1f86Smrg	sunos)
925025dbecb6Smrg	  major=.$current
925125dbecb6Smrg	  versuffix=.$current.$revision
9252b68e1f86Smrg	  ;;
9253b68e1f86Smrg
9254b68e1f86Smrg	windows)
9255b68e1f86Smrg	  # Use '-' rather than '.', since we only want one
925625dbecb6Smrg	  # extension on DOS 8.3 file systems.
9257b68e1f86Smrg	  func_arith $current - $age
9258b68e1f86Smrg	  major=$func_arith_result
925925dbecb6Smrg	  versuffix=-$major
9260b68e1f86Smrg	  ;;
9261b68e1f86Smrg
9262b68e1f86Smrg	*)
926325dbecb6Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
9264b68e1f86Smrg	  ;;
9265b68e1f86Smrg	esac
9266b68e1f86Smrg
9267b68e1f86Smrg	# Clear the version info if we defaulted, and they specified a release.
9268b68e1f86Smrg	if test -z "$vinfo" && test -n "$release"; then
9269b68e1f86Smrg	  major=
9270b68e1f86Smrg	  case $version_type in
9271b68e1f86Smrg	  darwin)
9272b68e1f86Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9273b68e1f86Smrg	    # problems, so we reset it completely
9274b68e1f86Smrg	    verstring=
9275b68e1f86Smrg	    ;;
9276b68e1f86Smrg	  *)
927725dbecb6Smrg	    verstring=0.0
9278b68e1f86Smrg	    ;;
9279b68e1f86Smrg	  esac
928025dbecb6Smrg	  if test no = "$need_version"; then
9281b68e1f86Smrg	    versuffix=
9282b68e1f86Smrg	  else
928325dbecb6Smrg	    versuffix=.0.0
9284b68e1f86Smrg	  fi
9285b68e1f86Smrg	fi
9286b68e1f86Smrg
9287b68e1f86Smrg	# Remove version info from name if versioning should be avoided
928825dbecb6Smrg	if test yes,no = "$avoid_version,$need_version"; then
9289b68e1f86Smrg	  major=
9290b68e1f86Smrg	  versuffix=
929125dbecb6Smrg	  verstring=
9292b68e1f86Smrg	fi
9293b68e1f86Smrg
9294b68e1f86Smrg	# Check to see if the archive will have undefined symbols.
929525dbecb6Smrg	if test yes = "$allow_undefined"; then
929625dbecb6Smrg	  if test unsupported = "$allow_undefined_flag"; then
929725dbecb6Smrg	    if test yes = "$build_old_libs"; then
929825dbecb6Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
929925dbecb6Smrg	      build_libtool_libs=no
930025dbecb6Smrg	    else
930125dbecb6Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
930225dbecb6Smrg	    fi
9303b68e1f86Smrg	  fi
9304b68e1f86Smrg	else
9305b68e1f86Smrg	  # Don't allow undefined symbols.
930625dbecb6Smrg	  allow_undefined_flag=$no_undefined_flag
9307b68e1f86Smrg	fi
9308b68e1f86Smrg
9309b68e1f86Smrg      fi
9310b68e1f86Smrg
931125dbecb6Smrg      func_generate_dlsyms "$libname" "$libname" :
93123bfa90b6Smrg      func_append libobjs " $symfileobj"
931325dbecb6Smrg      test " " = "$libobjs" && libobjs=
9314b68e1f86Smrg
931525dbecb6Smrg      if test relink != "$opt_mode"; then
9316b68e1f86Smrg	# Remove our outputs, but don't remove object files since they
9317b68e1f86Smrg	# may have been created when compiling PIC objects.
9318b68e1f86Smrg	removelist=
9319b68e1f86Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9320b68e1f86Smrg	for p in $tempremovelist; do
9321b68e1f86Smrg	  case $p in
9322b68e1f86Smrg	    *.$objext | *.gcno)
9323b68e1f86Smrg	       ;;
932425dbecb6Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
932525dbecb6Smrg	       if test -n "$precious_files_regex"; then
9326b68e1f86Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9327b68e1f86Smrg		 then
9328b68e1f86Smrg		   continue
9329b68e1f86Smrg		 fi
9330b68e1f86Smrg	       fi
93313bfa90b6Smrg	       func_append removelist " $p"
9332b68e1f86Smrg	       ;;
9333b68e1f86Smrg	    *) ;;
9334b68e1f86Smrg	  esac
9335b68e1f86Smrg	done
9336b68e1f86Smrg	test -n "$removelist" && \
9337b68e1f86Smrg	  func_show_eval "${RM}r \$removelist"
9338b68e1f86Smrg      fi
9339b68e1f86Smrg
9340b68e1f86Smrg      # Now set the variables for building old libraries.
934125dbecb6Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
93423bfa90b6Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9343b68e1f86Smrg
9344b68e1f86Smrg	# Transform .lo files to .o files.
934525dbecb6Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9346b68e1f86Smrg      fi
9347b68e1f86Smrg
9348b68e1f86Smrg      # Eliminate all temporary directories.
9349b68e1f86Smrg      #for path in $notinst_path; do
93503bfa90b6Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
93513bfa90b6Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
93523bfa90b6Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9353b68e1f86Smrg      #done
9354b68e1f86Smrg
9355b68e1f86Smrg      if test -n "$xrpath"; then
9356b68e1f86Smrg	# If the user specified any rpath flags, then add them.
9357b68e1f86Smrg	temp_xrpath=
9358b68e1f86Smrg	for libdir in $xrpath; do
93593bfa90b6Smrg	  func_replace_sysroot "$libdir"
93603bfa90b6Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9361b68e1f86Smrg	  case "$finalize_rpath " in
9362b68e1f86Smrg	  *" $libdir "*) ;;
93633bfa90b6Smrg	  *) func_append finalize_rpath " $libdir" ;;
9364b68e1f86Smrg	  esac
9365b68e1f86Smrg	done
936625dbecb6Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9367b68e1f86Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9368b68e1f86Smrg	fi
9369b68e1f86Smrg      fi
9370b68e1f86Smrg
9371b68e1f86Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
937225dbecb6Smrg      old_dlfiles=$dlfiles
9373b68e1f86Smrg      dlfiles=
9374b68e1f86Smrg      for lib in $old_dlfiles; do
9375b68e1f86Smrg	case " $dlprefiles $dlfiles " in
9376b68e1f86Smrg	*" $lib "*) ;;
93773bfa90b6Smrg	*) func_append dlfiles " $lib" ;;
9378b68e1f86Smrg	esac
9379b68e1f86Smrg      done
9380b68e1f86Smrg
9381b68e1f86Smrg      # Make sure dlprefiles contains only unique files
938225dbecb6Smrg      old_dlprefiles=$dlprefiles
9383b68e1f86Smrg      dlprefiles=
9384b68e1f86Smrg      for lib in $old_dlprefiles; do
9385b68e1f86Smrg	case "$dlprefiles " in
9386b68e1f86Smrg	*" $lib "*) ;;
93873bfa90b6Smrg	*) func_append dlprefiles " $lib" ;;
9388b68e1f86Smrg	esac
9389b68e1f86Smrg      done
9390b68e1f86Smrg
939125dbecb6Smrg      if test yes = "$build_libtool_libs"; then
9392b68e1f86Smrg	if test -n "$rpath"; then
9393b68e1f86Smrg	  case $host in
93943bfa90b6Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9395b68e1f86Smrg	    # these systems don't actually have a c library (as such)!
9396b68e1f86Smrg	    ;;
9397b68e1f86Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9398b68e1f86Smrg	    # Rhapsody C library is in the System framework
93993bfa90b6Smrg	    func_append deplibs " System.ltframework"
9400b68e1f86Smrg	    ;;
9401b68e1f86Smrg	  *-*-netbsd*)
9402b68e1f86Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9403b68e1f86Smrg	    ;;
940425dbecb6Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9405b68e1f86Smrg	    # Do not include libc due to us having libc/libc_r.
9406b68e1f86Smrg	    ;;
9407b68e1f86Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9408b68e1f86Smrg	    # Causes problems with __ctype
9409b68e1f86Smrg	    ;;
9410b68e1f86Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9411b68e1f86Smrg	    # Compiler inserts libc in the correct place for threads to work
9412b68e1f86Smrg	    ;;
9413b68e1f86Smrg	  *)
9414b68e1f86Smrg	    # Add libc to deplibs on all other systems if necessary.
941525dbecb6Smrg	    if test yes = "$build_libtool_need_lc"; then
94163bfa90b6Smrg	      func_append deplibs " -lc"
9417b68e1f86Smrg	    fi
9418b68e1f86Smrg	    ;;
9419b68e1f86Smrg	  esac
9420b68e1f86Smrg	fi
9421b68e1f86Smrg
9422b68e1f86Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9423b68e1f86Smrg	name_save=$name
9424b68e1f86Smrg	libname_save=$libname
9425b68e1f86Smrg	release_save=$release
9426b68e1f86Smrg	versuffix_save=$versuffix
9427b68e1f86Smrg	major_save=$major
9428b68e1f86Smrg	# I'm not sure if I'm treating the release correctly.  I think
9429b68e1f86Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9430b68e1f86Smrg	# add it in twice.  Is that correct?
943125dbecb6Smrg	release=
943225dbecb6Smrg	versuffix=
943325dbecb6Smrg	major=
9434b68e1f86Smrg	newdeplibs=
9435b68e1f86Smrg	droppeddeps=no
9436b68e1f86Smrg	case $deplibs_check_method in
9437b68e1f86Smrg	pass_all)
9438b68e1f86Smrg	  # Don't check for shared/static.  Everything works.
9439b68e1f86Smrg	  # This might be a little naive.  We might want to check
9440b68e1f86Smrg	  # whether the library exists or not.  But this is on
9441b68e1f86Smrg	  # osf3 & osf4 and I'm not really sure... Just
9442b68e1f86Smrg	  # implementing what was already the behavior.
9443b68e1f86Smrg	  newdeplibs=$deplibs
9444b68e1f86Smrg	  ;;
9445b68e1f86Smrg	test_compile)
9446b68e1f86Smrg	  # This code stresses the "libraries are programs" paradigm to its
9447b68e1f86Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9448b68e1f86Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9449b68e1f86Smrg	  # whether they linked in statically or dynamically with ldd.
9450b68e1f86Smrg	  $opt_dry_run || $RM conftest.c
9451b68e1f86Smrg	  cat > conftest.c <<EOF
9452b68e1f86Smrg	  int main() { return 0; }
9453b68e1f86SmrgEOF
9454b68e1f86Smrg	  $opt_dry_run || $RM conftest
9455b68e1f86Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9456b68e1f86Smrg	    ldd_output=`ldd conftest`
9457b68e1f86Smrg	    for i in $deplibs; do
9458b68e1f86Smrg	      case $i in
9459b68e1f86Smrg	      -l*)
9460b68e1f86Smrg		func_stripname -l '' "$i"
9461b68e1f86Smrg		name=$func_stripname_result
946225dbecb6Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9463b68e1f86Smrg		  case " $predeps $postdeps " in
9464b68e1f86Smrg		  *" $i "*)
94653bfa90b6Smrg		    func_append newdeplibs " $i"
946625dbecb6Smrg		    i=
9467b68e1f86Smrg		    ;;
9468b68e1f86Smrg		  esac
9469b68e1f86Smrg		fi
947025dbecb6Smrg		if test -n "$i"; then
9471b68e1f86Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9472b68e1f86Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9473b68e1f86Smrg		  set dummy $deplib_matches; shift
9474b68e1f86Smrg		  deplib_match=$1
947525dbecb6Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
94763bfa90b6Smrg		    func_append newdeplibs " $i"
9477b68e1f86Smrg		  else
9478b68e1f86Smrg		    droppeddeps=yes
94793bfa90b6Smrg		    echo
9480b68e1f86Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
94813bfa90b6Smrg		    echo "*** I have the capability to make that library automatically link in when"
94823bfa90b6Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
94833bfa90b6Smrg		    echo "*** shared version of the library, which I believe you do not have"
94843bfa90b6Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
94853bfa90b6Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9486b68e1f86Smrg		  fi
9487b68e1f86Smrg		fi
9488b68e1f86Smrg		;;
9489b68e1f86Smrg	      *)
94903bfa90b6Smrg		func_append newdeplibs " $i"
9491b68e1f86Smrg		;;
9492b68e1f86Smrg	      esac
9493b68e1f86Smrg	    done
9494b68e1f86Smrg	  else
9495b68e1f86Smrg	    # Error occurred in the first compile.  Let's try to salvage
9496b68e1f86Smrg	    # the situation: Compile a separate program for each library.
9497b68e1f86Smrg	    for i in $deplibs; do
9498b68e1f86Smrg	      case $i in
9499b68e1f86Smrg	      -l*)
9500b68e1f86Smrg		func_stripname -l '' "$i"
9501b68e1f86Smrg		name=$func_stripname_result
9502b68e1f86Smrg		$opt_dry_run || $RM conftest
9503b68e1f86Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9504b68e1f86Smrg		  ldd_output=`ldd conftest`
950525dbecb6Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9506b68e1f86Smrg		    case " $predeps $postdeps " in
9507b68e1f86Smrg		    *" $i "*)
95083bfa90b6Smrg		      func_append newdeplibs " $i"
950925dbecb6Smrg		      i=
9510b68e1f86Smrg		      ;;
9511b68e1f86Smrg		    esac
9512b68e1f86Smrg		  fi
951325dbecb6Smrg		  if test -n "$i"; then
9514b68e1f86Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9515b68e1f86Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9516b68e1f86Smrg		    set dummy $deplib_matches; shift
9517b68e1f86Smrg		    deplib_match=$1
951825dbecb6Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
95193bfa90b6Smrg		      func_append newdeplibs " $i"
9520b68e1f86Smrg		    else
9521b68e1f86Smrg		      droppeddeps=yes
95223bfa90b6Smrg		      echo
9523b68e1f86Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
95243bfa90b6Smrg		      echo "*** I have the capability to make that library automatically link in when"
95253bfa90b6Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
95263bfa90b6Smrg		      echo "*** shared version of the library, which you do not appear to have"
95273bfa90b6Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
95283bfa90b6Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9529b68e1f86Smrg		    fi
9530b68e1f86Smrg		  fi
9531b68e1f86Smrg		else
9532b68e1f86Smrg		  droppeddeps=yes
95333bfa90b6Smrg		  echo
9534b68e1f86Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
95353bfa90b6Smrg		  echo "*** make it link in!  You will probably need to install it or some"
95363bfa90b6Smrg		  echo "*** library that it depends on before this library will be fully"
95373bfa90b6Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9538b68e1f86Smrg		fi
9539b68e1f86Smrg		;;
9540b68e1f86Smrg	      *)
95413bfa90b6Smrg		func_append newdeplibs " $i"
9542b68e1f86Smrg		;;
9543b68e1f86Smrg	      esac
9544b68e1f86Smrg	    done
9545b68e1f86Smrg	  fi
9546b68e1f86Smrg	  ;;
9547b68e1f86Smrg	file_magic*)
9548b68e1f86Smrg	  set dummy $deplibs_check_method; shift
9549b68e1f86Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9550b68e1f86Smrg	  for a_deplib in $deplibs; do
9551b68e1f86Smrg	    case $a_deplib in
9552b68e1f86Smrg	    -l*)
9553b68e1f86Smrg	      func_stripname -l '' "$a_deplib"
9554b68e1f86Smrg	      name=$func_stripname_result
955525dbecb6Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9556b68e1f86Smrg		case " $predeps $postdeps " in
9557b68e1f86Smrg		*" $a_deplib "*)
95583bfa90b6Smrg		  func_append newdeplibs " $a_deplib"
955925dbecb6Smrg		  a_deplib=
9560b68e1f86Smrg		  ;;
9561b68e1f86Smrg		esac
9562b68e1f86Smrg	      fi
956325dbecb6Smrg	      if test -n "$a_deplib"; then
9564b68e1f86Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
95653bfa90b6Smrg		if test -n "$file_magic_glob"; then
95663bfa90b6Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
95673bfa90b6Smrg		else
95683bfa90b6Smrg		  libnameglob=$libname
95693bfa90b6Smrg		fi
957025dbecb6Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9571b68e1f86Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
957225dbecb6Smrg		  if test yes = "$want_nocaseglob"; then
95733bfa90b6Smrg		    shopt -s nocaseglob
95743bfa90b6Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95753bfa90b6Smrg		    $nocaseglob
95763bfa90b6Smrg		  else
95773bfa90b6Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95783bfa90b6Smrg		  fi
9579b68e1f86Smrg		  for potent_lib in $potential_libs; do
9580b68e1f86Smrg		      # Follow soft links.
9581b68e1f86Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9582b68e1f86Smrg			 $GREP " -> " >/dev/null; then
9583b68e1f86Smrg			continue
9584b68e1f86Smrg		      fi
9585b68e1f86Smrg		      # The statement above tries to avoid entering an
9586b68e1f86Smrg		      # endless loop below, in case of cyclic links.
9587b68e1f86Smrg		      # We might still enter an endless loop, since a link
9588b68e1f86Smrg		      # loop can be closed while we follow links,
9589b68e1f86Smrg		      # but so what?
959025dbecb6Smrg		      potlib=$potent_lib
9591b68e1f86Smrg		      while test -h "$potlib" 2>/dev/null; do
959225dbecb6Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9593b68e1f86Smrg			case $potliblink in
959425dbecb6Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
959525dbecb6Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9596b68e1f86Smrg			esac
9597b68e1f86Smrg		      done
9598b68e1f86Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9599b68e1f86Smrg			 $SED -e 10q |
9600b68e1f86Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
96013bfa90b6Smrg			func_append newdeplibs " $a_deplib"
960225dbecb6Smrg			a_deplib=
9603b68e1f86Smrg			break 2
9604b68e1f86Smrg		      fi
9605b68e1f86Smrg		  done
9606b68e1f86Smrg		done
9607b68e1f86Smrg	      fi
960825dbecb6Smrg	      if test -n "$a_deplib"; then
9609b68e1f86Smrg		droppeddeps=yes
96103bfa90b6Smrg		echo
9611b68e1f86Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96123bfa90b6Smrg		echo "*** I have the capability to make that library automatically link in when"
96133bfa90b6Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96143bfa90b6Smrg		echo "*** shared version of the library, which you do not appear to have"
96153bfa90b6Smrg		echo "*** because I did check the linker path looking for a file starting"
961625dbecb6Smrg		if test -z "$potlib"; then
9617b68e1f86Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9618b68e1f86Smrg		else
9619b68e1f86Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9620b68e1f86Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9621b68e1f86Smrg		fi
9622b68e1f86Smrg	      fi
9623b68e1f86Smrg	      ;;
9624b68e1f86Smrg	    *)
9625b68e1f86Smrg	      # Add a -L argument.
96263bfa90b6Smrg	      func_append newdeplibs " $a_deplib"
9627b68e1f86Smrg	      ;;
9628b68e1f86Smrg	    esac
9629b68e1f86Smrg	  done # Gone through all deplibs.
9630b68e1f86Smrg	  ;;
9631b68e1f86Smrg	match_pattern*)
9632b68e1f86Smrg	  set dummy $deplibs_check_method; shift
9633b68e1f86Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9634b68e1f86Smrg	  for a_deplib in $deplibs; do
9635b68e1f86Smrg	    case $a_deplib in
9636b68e1f86Smrg	    -l*)
9637b68e1f86Smrg	      func_stripname -l '' "$a_deplib"
9638b68e1f86Smrg	      name=$func_stripname_result
963925dbecb6Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9640b68e1f86Smrg		case " $predeps $postdeps " in
9641b68e1f86Smrg		*" $a_deplib "*)
96423bfa90b6Smrg		  func_append newdeplibs " $a_deplib"
964325dbecb6Smrg		  a_deplib=
9644b68e1f86Smrg		  ;;
9645b68e1f86Smrg		esac
9646b68e1f86Smrg	      fi
964725dbecb6Smrg	      if test -n "$a_deplib"; then
9648b68e1f86Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9649b68e1f86Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9650b68e1f86Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9651b68e1f86Smrg		  for potent_lib in $potential_libs; do
965225dbecb6Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
96533bfa90b6Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9654b68e1f86Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
96553bfa90b6Smrg		      func_append newdeplibs " $a_deplib"
965625dbecb6Smrg		      a_deplib=
9657b68e1f86Smrg		      break 2
9658b68e1f86Smrg		    fi
9659b68e1f86Smrg		  done
9660b68e1f86Smrg		done
9661b68e1f86Smrg	      fi
966225dbecb6Smrg	      if test -n "$a_deplib"; then
9663b68e1f86Smrg		droppeddeps=yes
96643bfa90b6Smrg		echo
9665b68e1f86Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96663bfa90b6Smrg		echo "*** I have the capability to make that library automatically link in when"
96673bfa90b6Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96683bfa90b6Smrg		echo "*** shared version of the library, which you do not appear to have"
96693bfa90b6Smrg		echo "*** because I did check the linker path looking for a file starting"
967025dbecb6Smrg		if test -z "$potlib"; then
9671b68e1f86Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9672b68e1f86Smrg		else
9673b68e1f86Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9674b68e1f86Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9675b68e1f86Smrg		fi
9676b68e1f86Smrg	      fi
9677b68e1f86Smrg	      ;;
9678b68e1f86Smrg	    *)
9679b68e1f86Smrg	      # Add a -L argument.
96803bfa90b6Smrg	      func_append newdeplibs " $a_deplib"
9681b68e1f86Smrg	      ;;
9682b68e1f86Smrg	    esac
9683b68e1f86Smrg	  done # Gone through all deplibs.
9684b68e1f86Smrg	  ;;
9685b68e1f86Smrg	none | unknown | *)
968625dbecb6Smrg	  newdeplibs=
96873bfa90b6Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
968825dbecb6Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
968925dbecb6Smrg	    for i in $predeps $postdeps; do
9690b68e1f86Smrg	      # can't use Xsed below, because $i might contain '/'
969125dbecb6Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9692b68e1f86Smrg	    done
9693b68e1f86Smrg	  fi
96943bfa90b6Smrg	  case $tmp_deplibs in
96953bfa90b6Smrg	  *[!\	\ ]*)
96963bfa90b6Smrg	    echo
969725dbecb6Smrg	    if test none = "$deplibs_check_method"; then
96983bfa90b6Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9699b68e1f86Smrg	    else
97003bfa90b6Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9701b68e1f86Smrg	    fi
97023bfa90b6Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9703b68e1f86Smrg	    droppeddeps=yes
97043bfa90b6Smrg	    ;;
97053bfa90b6Smrg	  esac
9706b68e1f86Smrg	  ;;
9707b68e1f86Smrg	esac
9708b68e1f86Smrg	versuffix=$versuffix_save
9709b68e1f86Smrg	major=$major_save
9710b68e1f86Smrg	release=$release_save
9711b68e1f86Smrg	libname=$libname_save
9712b68e1f86Smrg	name=$name_save
9713b68e1f86Smrg
9714b68e1f86Smrg	case $host in
9715b68e1f86Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9716b68e1f86Smrg	  # On Rhapsody replace the C library with the System framework
97173bfa90b6Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9718b68e1f86Smrg	  ;;
9719b68e1f86Smrg	esac
9720b68e1f86Smrg
972125dbecb6Smrg	if test yes = "$droppeddeps"; then
972225dbecb6Smrg	  if test yes = "$module"; then
97233bfa90b6Smrg	    echo
97243bfa90b6Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9725b68e1f86Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
97263bfa90b6Smrg	    echo "*** a static module, that should work as long as the dlopening"
97273bfa90b6Smrg	    echo "*** application is linked with the -dlopen flag."
9728b68e1f86Smrg	    if test -z "$global_symbol_pipe"; then
97293bfa90b6Smrg	      echo
97303bfa90b6Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
973125dbecb6Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
97323bfa90b6Smrg	      echo "*** not find such a program.  So, this module is probably useless."
973325dbecb6Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9734b68e1f86Smrg	    fi
973525dbecb6Smrg	    if test no = "$build_old_libs"; then
973625dbecb6Smrg	      oldlibs=$output_objdir/$libname.$libext
9737b68e1f86Smrg	      build_libtool_libs=module
9738b68e1f86Smrg	      build_old_libs=yes
9739b68e1f86Smrg	    else
9740b68e1f86Smrg	      build_libtool_libs=no
9741b68e1f86Smrg	    fi
9742b68e1f86Smrg	  else
97433bfa90b6Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
97443bfa90b6Smrg	    echo "*** automatically added whenever a program is linked with this library"
97453bfa90b6Smrg	    echo "*** or is declared to -dlopen it."
9746b68e1f86Smrg
974725dbecb6Smrg	    if test no = "$allow_undefined"; then
97483bfa90b6Smrg	      echo
97493bfa90b6Smrg	      echo "*** Since this library must not contain undefined symbols,"
97503bfa90b6Smrg	      echo "*** because either the platform does not support them or"
97513bfa90b6Smrg	      echo "*** it was explicitly requested with -no-undefined,"
97523bfa90b6Smrg	      echo "*** libtool will only create a static version of it."
975325dbecb6Smrg	      if test no = "$build_old_libs"; then
975425dbecb6Smrg		oldlibs=$output_objdir/$libname.$libext
9755b68e1f86Smrg		build_libtool_libs=module
9756b68e1f86Smrg		build_old_libs=yes
9757b68e1f86Smrg	      else
9758b68e1f86Smrg		build_libtool_libs=no
9759b68e1f86Smrg	      fi
9760b68e1f86Smrg	    fi
9761b68e1f86Smrg	  fi
9762b68e1f86Smrg	fi
9763b68e1f86Smrg	# Done checking deplibs!
9764b68e1f86Smrg	deplibs=$newdeplibs
9765b68e1f86Smrg      fi
9766b68e1f86Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9767b68e1f86Smrg      case $host in
9768b68e1f86Smrg	*-*-darwin*)
97693bfa90b6Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97703bfa90b6Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97713bfa90b6Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9772b68e1f86Smrg	  ;;
9773b68e1f86Smrg      esac
9774b68e1f86Smrg
9775b68e1f86Smrg      # move library search paths that coincide with paths to not yet
9776b68e1f86Smrg      # installed libraries to the beginning of the library search list
9777b68e1f86Smrg      new_libs=
9778b68e1f86Smrg      for path in $notinst_path; do
9779b68e1f86Smrg	case " $new_libs " in
9780b68e1f86Smrg	*" -L$path/$objdir "*) ;;
9781b68e1f86Smrg	*)
9782b68e1f86Smrg	  case " $deplibs " in
9783b68e1f86Smrg	  *" -L$path/$objdir "*)
97843bfa90b6Smrg	    func_append new_libs " -L$path/$objdir" ;;
9785b68e1f86Smrg	  esac
9786b68e1f86Smrg	  ;;
9787b68e1f86Smrg	esac
9788b68e1f86Smrg      done
9789b68e1f86Smrg      for deplib in $deplibs; do
9790b68e1f86Smrg	case $deplib in
9791b68e1f86Smrg	-L*)
9792b68e1f86Smrg	  case " $new_libs " in
9793b68e1f86Smrg	  *" $deplib "*) ;;
97943bfa90b6Smrg	  *) func_append new_libs " $deplib" ;;
9795b68e1f86Smrg	  esac
9796b68e1f86Smrg	  ;;
97973bfa90b6Smrg	*) func_append new_libs " $deplib" ;;
9798b68e1f86Smrg	esac
9799b68e1f86Smrg      done
980025dbecb6Smrg      deplibs=$new_libs
9801b68e1f86Smrg
9802b68e1f86Smrg      # All the library-specific variables (install_libdir is set above).
9803b68e1f86Smrg      library_names=
9804b68e1f86Smrg      old_library=
9805b68e1f86Smrg      dlname=
9806b68e1f86Smrg
9807b68e1f86Smrg      # Test again, we may have decided not to build it any more
980825dbecb6Smrg      if test yes = "$build_libtool_libs"; then
980925dbecb6Smrg	# Remove $wl instances when linking with ld.
98103bfa90b6Smrg	# FIXME: should test the right _cmds variable.
98113bfa90b6Smrg	case $archive_cmds in
98123bfa90b6Smrg	  *\$LD\ *) wl= ;;
98133bfa90b6Smrg        esac
981425dbecb6Smrg	if test yes = "$hardcode_into_libs"; then
9815b68e1f86Smrg	  # Hardcode the library paths
9816b68e1f86Smrg	  hardcode_libdirs=
9817b68e1f86Smrg	  dep_rpath=
981825dbecb6Smrg	  rpath=$finalize_rpath
981925dbecb6Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9820b68e1f86Smrg	  for libdir in $rpath; do
9821b68e1f86Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9822b68e1f86Smrg	      if test -n "$hardcode_libdir_separator"; then
98233bfa90b6Smrg		func_replace_sysroot "$libdir"
98243bfa90b6Smrg		libdir=$func_replace_sysroot_result
9825b68e1f86Smrg		if test -z "$hardcode_libdirs"; then
982625dbecb6Smrg		  hardcode_libdirs=$libdir
9827b68e1f86Smrg		else
9828b68e1f86Smrg		  # Just accumulate the unique libdirs.
9829b68e1f86Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9830b68e1f86Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9831b68e1f86Smrg		    ;;
9832b68e1f86Smrg		  *)
98333bfa90b6Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9834b68e1f86Smrg		    ;;
9835b68e1f86Smrg		  esac
9836b68e1f86Smrg		fi
9837b68e1f86Smrg	      else
9838b68e1f86Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
98393bfa90b6Smrg		func_append dep_rpath " $flag"
9840b68e1f86Smrg	      fi
9841b68e1f86Smrg	    elif test -n "$runpath_var"; then
9842b68e1f86Smrg	      case "$perm_rpath " in
9843b68e1f86Smrg	      *" $libdir "*) ;;
98443bfa90b6Smrg	      *) func_append perm_rpath " $libdir" ;;
9845b68e1f86Smrg	      esac
9846b68e1f86Smrg	    fi
9847b68e1f86Smrg	  done
9848b68e1f86Smrg	  # Substitute the hardcoded libdirs into the rpath.
9849b68e1f86Smrg	  if test -n "$hardcode_libdir_separator" &&
9850b68e1f86Smrg	     test -n "$hardcode_libdirs"; then
985125dbecb6Smrg	    libdir=$hardcode_libdirs
98523bfa90b6Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9853b68e1f86Smrg	  fi
9854b68e1f86Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9855b68e1f86Smrg	    # We should set the runpath_var.
9856b68e1f86Smrg	    rpath=
9857b68e1f86Smrg	    for dir in $perm_rpath; do
98583bfa90b6Smrg	      func_append rpath "$dir:"
9859b68e1f86Smrg	    done
9860b68e1f86Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9861b68e1f86Smrg	  fi
9862b68e1f86Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9863b68e1f86Smrg	fi
98646df26cacSmrg
986525dbecb6Smrg	shlibpath=$finalize_shlibpath
986625dbecb6Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9867b68e1f86Smrg	if test -n "$shlibpath"; then
9868b68e1f86Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9869b68e1f86Smrg	fi
98706df26cacSmrg
9871b68e1f86Smrg	# Get the real and link names of the library.
9872b68e1f86Smrg	eval shared_ext=\"$shrext_cmds\"
9873b68e1f86Smrg	eval library_names=\"$library_names_spec\"
9874b68e1f86Smrg	set dummy $library_names
9875b68e1f86Smrg	shift
987625dbecb6Smrg	realname=$1
9877b68e1f86Smrg	shift
98786df26cacSmrg
9879b68e1f86Smrg	if test -n "$soname_spec"; then
9880b68e1f86Smrg	  eval soname=\"$soname_spec\"
9881b68e1f86Smrg	else
988225dbecb6Smrg	  soname=$realname
9883b68e1f86Smrg	fi
9884b68e1f86Smrg	if test -z "$dlname"; then
9885b68e1f86Smrg	  dlname=$soname
9886b68e1f86Smrg	fi
98876df26cacSmrg
988825dbecb6Smrg	lib=$output_objdir/$realname
9889b68e1f86Smrg	linknames=
9890b68e1f86Smrg	for link
9891b68e1f86Smrg	do
98923bfa90b6Smrg	  func_append linknames " $link"
9893b68e1f86Smrg	done
98946df26cacSmrg
9895b68e1f86Smrg	# Use standard objects if they are pic
98963bfa90b6Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9897b68e1f86Smrg	test "X$libobjs" = "X " && libobjs=
98986df26cacSmrg
9899b68e1f86Smrg	delfiles=
9900b68e1f86Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9901b68e1f86Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
990225dbecb6Smrg	  export_symbols=$output_objdir/$libname.uexp
99033bfa90b6Smrg	  func_append delfiles " $export_symbols"
9904b68e1f86Smrg	fi
99056df26cacSmrg
9906b68e1f86Smrg	orig_export_symbols=
9907b68e1f86Smrg	case $host_os in
9908b68e1f86Smrg	cygwin* | mingw* | cegcc*)
9909b68e1f86Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9910b68e1f86Smrg	    # exporting using user supplied symfile
991125dbecb6Smrg	    func_dll_def_p "$export_symbols" || {
9912b68e1f86Smrg	      # and it's NOT already a .def file. Must figure out
9913b68e1f86Smrg	      # which of the given symbols are data symbols and tag
9914b68e1f86Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9915b68e1f86Smrg	      # export_symbols gets reassigned inside the "prepare
9916b68e1f86Smrg	      # the list of exported symbols" if statement, so the
9917b68e1f86Smrg	      # include_expsyms logic still works.
991825dbecb6Smrg	      orig_export_symbols=$export_symbols
9919b68e1f86Smrg	      export_symbols=
9920b68e1f86Smrg	      always_export_symbols=yes
992125dbecb6Smrg	    }
9922b68e1f86Smrg	  fi
9923b68e1f86Smrg	  ;;
9924b68e1f86Smrg	esac
99256df26cacSmrg
9926b68e1f86Smrg	# Prepare the list of exported symbols
9927b68e1f86Smrg	if test -z "$export_symbols"; then
992825dbecb6Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
992925dbecb6Smrg	    func_verbose "generating symbol list for '$libname.la'"
993025dbecb6Smrg	    export_symbols=$output_objdir/$libname.exp
9931b68e1f86Smrg	    $opt_dry_run || $RM $export_symbols
9932b68e1f86Smrg	    cmds=$export_symbols_cmds
993325dbecb6Smrg	    save_ifs=$IFS; IFS='~'
99343bfa90b6Smrg	    for cmd1 in $cmds; do
993525dbecb6Smrg	      IFS=$save_ifs
99363bfa90b6Smrg	      # Take the normal branch if the nm_file_list_spec branch
99373bfa90b6Smrg	      # doesn't work or if tool conversion is not needed.
99383bfa90b6Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
99393bfa90b6Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
99403bfa90b6Smrg		  try_normal_branch=yes
99413bfa90b6Smrg		  eval cmd=\"$cmd1\"
99423bfa90b6Smrg		  func_len " $cmd"
99433bfa90b6Smrg		  len=$func_len_result
99443bfa90b6Smrg		  ;;
99453bfa90b6Smrg		*)
99463bfa90b6Smrg		  try_normal_branch=no
99473bfa90b6Smrg		  ;;
99483bfa90b6Smrg	      esac
994925dbecb6Smrg	      if test yes = "$try_normal_branch" \
99503bfa90b6Smrg		 && { test "$len" -lt "$max_cmd_len" \
99513bfa90b6Smrg		      || test "$max_cmd_len" -le -1; }
99523bfa90b6Smrg	      then
9953b68e1f86Smrg		func_show_eval "$cmd" 'exit $?'
9954b68e1f86Smrg		skipped_export=false
99553bfa90b6Smrg	      elif test -n "$nm_file_list_spec"; then
99563bfa90b6Smrg		func_basename "$output"
99573bfa90b6Smrg		output_la=$func_basename_result
99583bfa90b6Smrg		save_libobjs=$libobjs
99593bfa90b6Smrg		save_output=$output
996025dbecb6Smrg		output=$output_objdir/$output_la.nm
99613bfa90b6Smrg		func_to_tool_file "$output"
99623bfa90b6Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
99633bfa90b6Smrg		func_append delfiles " $output"
99643bfa90b6Smrg		func_verbose "creating $NM input file list: $output"
99653bfa90b6Smrg		for obj in $save_libobjs; do
99663bfa90b6Smrg		  func_to_tool_file "$obj"
99673bfa90b6Smrg		  $ECHO "$func_to_tool_file_result"
99683bfa90b6Smrg		done > "$output"
99693bfa90b6Smrg		eval cmd=\"$cmd1\"
99703bfa90b6Smrg		func_show_eval "$cmd" 'exit $?'
99713bfa90b6Smrg		output=$save_output
99723bfa90b6Smrg		libobjs=$save_libobjs
99733bfa90b6Smrg		skipped_export=false
9974b68e1f86Smrg	      else
9975b68e1f86Smrg		# The command line is too long to execute in one step.
9976b68e1f86Smrg		func_verbose "using reloadable object file for export list..."
9977b68e1f86Smrg		skipped_export=:
9978b68e1f86Smrg		# Break out early, otherwise skipped_export may be
9979b68e1f86Smrg		# set to false by a later but shorter cmd.
9980b68e1f86Smrg		break
9981b68e1f86Smrg	      fi
9982b68e1f86Smrg	    done
998325dbecb6Smrg	    IFS=$save_ifs
998425dbecb6Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9985b68e1f86Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9986b68e1f86Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9987b68e1f86Smrg	    fi
9988b68e1f86Smrg	  fi
9989b68e1f86Smrg	fi
99906df26cacSmrg
9991b68e1f86Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
999225dbecb6Smrg	  tmp_export_symbols=$export_symbols
999325dbecb6Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
99943bfa90b6Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9995b68e1f86Smrg	fi
99966df26cacSmrg
999725dbecb6Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
9998b68e1f86Smrg	  # The given exports_symbols file has to be filtered, so filter it.
999925dbecb6Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10000b68e1f86Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
1000125dbecb6Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10002b68e1f86Smrg	  # though. Also, the filter scales superlinearly with the number of
10003b68e1f86Smrg	  # global variables. join(1) would be nice here, but unfortunately
10004b68e1f86Smrg	  # isn't a blessed tool.
10005b68e1f86Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
100063bfa90b6Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10007b68e1f86Smrg	  export_symbols=$output_objdir/$libname.def
10008b68e1f86Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100096df26cacSmrg	fi
100106df26cacSmrg
10011b68e1f86Smrg	tmp_deplibs=
10012b68e1f86Smrg	for test_deplib in $deplibs; do
10013b68e1f86Smrg	  case " $convenience " in
10014b68e1f86Smrg	  *" $test_deplib "*) ;;
10015b68e1f86Smrg	  *)
100163bfa90b6Smrg	    func_append tmp_deplibs " $test_deplib"
10017b68e1f86Smrg	    ;;
10018b68e1f86Smrg	  esac
10019b68e1f86Smrg	done
1002025dbecb6Smrg	deplibs=$tmp_deplibs
100216df26cacSmrg
10022b68e1f86Smrg	if test -n "$convenience"; then
10023b68e1f86Smrg	  if test -n "$whole_archive_flag_spec" &&
1002425dbecb6Smrg	    test yes = "$compiler_needs_object" &&
10025b68e1f86Smrg	    test -z "$libobjs"; then
10026b68e1f86Smrg	    # extract the archives, so we have objects to list.
10027b68e1f86Smrg	    # TODO: could optimize this to just extract one archive.
10028b68e1f86Smrg	    whole_archive_flag_spec=
10029b68e1f86Smrg	  fi
10030b68e1f86Smrg	  if test -n "$whole_archive_flag_spec"; then
10031b68e1f86Smrg	    save_libobjs=$libobjs
10032b68e1f86Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10033b68e1f86Smrg	    test "X$libobjs" = "X " && libobjs=
10034b68e1f86Smrg	  else
1003525dbecb6Smrg	    gentop=$output_objdir/${outputname}x
100363bfa90b6Smrg	    func_append generated " $gentop"
100376df26cacSmrg
10038b68e1f86Smrg	    func_extract_archives $gentop $convenience
100393bfa90b6Smrg	    func_append libobjs " $func_extract_archives_result"
10040b68e1f86Smrg	    test "X$libobjs" = "X " && libobjs=
10041b68e1f86Smrg	  fi
10042b68e1f86Smrg	fi
100436df26cacSmrg
1004425dbecb6Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10045b68e1f86Smrg	  eval flag=\"$thread_safe_flag_spec\"
100463bfa90b6Smrg	  func_append linker_flags " $flag"
10047b68e1f86Smrg	fi
100486df26cacSmrg
10049b68e1f86Smrg	# Make a backup of the uninstalled library when relinking
1005025dbecb6Smrg	if test relink = "$opt_mode"; then
10051b68e1f86Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
100526df26cacSmrg	fi
100536df26cacSmrg
10054b68e1f86Smrg	# Do each of the archive commands.
1005525dbecb6Smrg	if test yes = "$module" && test -n "$module_cmds"; then
10056b68e1f86Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10057b68e1f86Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10058b68e1f86Smrg	    cmds=$module_expsym_cmds
10059b68e1f86Smrg	  else
10060b68e1f86Smrg	    eval test_cmds=\"$module_cmds\"
10061b68e1f86Smrg	    cmds=$module_cmds
10062b68e1f86Smrg	  fi
10063b68e1f86Smrg	else
10064b68e1f86Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10065b68e1f86Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10066b68e1f86Smrg	    cmds=$archive_expsym_cmds
10067b68e1f86Smrg	  else
10068b68e1f86Smrg	    eval test_cmds=\"$archive_cmds\"
10069b68e1f86Smrg	    cmds=$archive_cmds
10070b68e1f86Smrg	  fi
100716df26cacSmrg	fi
100726df26cacSmrg
1007325dbecb6Smrg	if test : != "$skipped_export" &&
10074b68e1f86Smrg	   func_len " $test_cmds" &&
10075b68e1f86Smrg	   len=$func_len_result &&
10076b68e1f86Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10077b68e1f86Smrg	  :
10078b68e1f86Smrg	else
10079b68e1f86Smrg	  # The command line is too long to link in one step, link piecewise
10080b68e1f86Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10081b68e1f86Smrg	  # script.
100826df26cacSmrg
10083b68e1f86Smrg	  # Save the value of $output and $libobjs because we want to
10084b68e1f86Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10085b68e1f86Smrg	  # want to use save_libobjs as it was before
10086b68e1f86Smrg	  # whole_archive_flag_spec was expanded, because we can't
10087b68e1f86Smrg	  # assume the linker understands whole_archive_flag_spec.
10088b68e1f86Smrg	  # This may have to be revisited, in case too many
10089b68e1f86Smrg	  # convenience libraries get linked in and end up exceeding
10090b68e1f86Smrg	  # the spec.
10091b68e1f86Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10092b68e1f86Smrg	    save_libobjs=$libobjs
10093b68e1f86Smrg	  fi
10094b68e1f86Smrg	  save_output=$output
100953bfa90b6Smrg	  func_basename "$output"
100963bfa90b6Smrg	  output_la=$func_basename_result
100976df26cacSmrg
10098b68e1f86Smrg	  # Clear the reloadable object creation command queue and
10099b68e1f86Smrg	  # initialize k to one.
10100b68e1f86Smrg	  test_cmds=
10101b68e1f86Smrg	  concat_cmds=
10102b68e1f86Smrg	  objlist=
10103b68e1f86Smrg	  last_robj=
10104b68e1f86Smrg	  k=1
101056df26cacSmrg
1010625dbecb6Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
1010725dbecb6Smrg	    output=$output_objdir/$output_la.lnkscript
10108b68e1f86Smrg	    func_verbose "creating GNU ld script: $output"
101093bfa90b6Smrg	    echo 'INPUT (' > $output
10110b68e1f86Smrg	    for obj in $save_libobjs
10111b68e1f86Smrg	    do
101123bfa90b6Smrg	      func_to_tool_file "$obj"
101133bfa90b6Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10114b68e1f86Smrg	    done
101153bfa90b6Smrg	    echo ')' >> $output
101163bfa90b6Smrg	    func_append delfiles " $output"
101173bfa90b6Smrg	    func_to_tool_file "$output"
101183bfa90b6Smrg	    output=$func_to_tool_file_result
1011925dbecb6Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
1012025dbecb6Smrg	    output=$output_objdir/$output_la.lnk
10121b68e1f86Smrg	    func_verbose "creating linker input file list: $output"
10122b68e1f86Smrg	    : > $output
10123b68e1f86Smrg	    set x $save_libobjs
10124b68e1f86Smrg	    shift
10125b68e1f86Smrg	    firstobj=
1012625dbecb6Smrg	    if test yes = "$compiler_needs_object"; then
10127b68e1f86Smrg	      firstobj="$1 "
10128b68e1f86Smrg	      shift
10129b68e1f86Smrg	    fi
10130b68e1f86Smrg	    for obj
10131b68e1f86Smrg	    do
101323bfa90b6Smrg	      func_to_tool_file "$obj"
101333bfa90b6Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10134b68e1f86Smrg	    done
101353bfa90b6Smrg	    func_append delfiles " $output"
101363bfa90b6Smrg	    func_to_tool_file "$output"
101373bfa90b6Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10138b68e1f86Smrg	  else
10139b68e1f86Smrg	    if test -n "$save_libobjs"; then
10140b68e1f86Smrg	      func_verbose "creating reloadable object files..."
1014125dbecb6Smrg	      output=$output_objdir/$output_la-$k.$objext
10142b68e1f86Smrg	      eval test_cmds=\"$reload_cmds\"
10143b68e1f86Smrg	      func_len " $test_cmds"
10144b68e1f86Smrg	      len0=$func_len_result
10145b68e1f86Smrg	      len=$len0
10146b68e1f86Smrg
10147b68e1f86Smrg	      # Loop over the list of objects to be linked.
10148b68e1f86Smrg	      for obj in $save_libobjs
10149b68e1f86Smrg	      do
10150b68e1f86Smrg		func_len " $obj"
10151b68e1f86Smrg		func_arith $len + $func_len_result
10152b68e1f86Smrg		len=$func_arith_result
1015325dbecb6Smrg		if test -z "$objlist" ||
10154b68e1f86Smrg		   test "$len" -lt "$max_cmd_len"; then
10155b68e1f86Smrg		  func_append objlist " $obj"
10156b68e1f86Smrg		else
10157b68e1f86Smrg		  # The command $test_cmds is almost too long, add a
10158b68e1f86Smrg		  # command to the queue.
1015925dbecb6Smrg		  if test 1 -eq "$k"; then
10160b68e1f86Smrg		    # The first file doesn't have a previous command to add.
101613bfa90b6Smrg		    reload_objs=$objlist
101623bfa90b6Smrg		    eval concat_cmds=\"$reload_cmds\"
10163b68e1f86Smrg		  else
10164b68e1f86Smrg		    # All subsequent reloadable object files will link in
10165b68e1f86Smrg		    # the last one created.
101663bfa90b6Smrg		    reload_objs="$objlist $last_robj"
101673bfa90b6Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10168b68e1f86Smrg		  fi
1016925dbecb6Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
10170b68e1f86Smrg		  func_arith $k + 1
10171b68e1f86Smrg		  k=$func_arith_result
1017225dbecb6Smrg		  output=$output_objdir/$output_la-$k.$objext
101733bfa90b6Smrg		  objlist=" $obj"
10174b68e1f86Smrg		  func_len " $last_robj"
10175b68e1f86Smrg		  func_arith $len0 + $func_len_result
10176b68e1f86Smrg		  len=$func_arith_result
10177b68e1f86Smrg		fi
10178b68e1f86Smrg	      done
10179b68e1f86Smrg	      # Handle the remaining objects by creating one last
10180b68e1f86Smrg	      # reloadable object file.  All subsequent reloadable object
10181b68e1f86Smrg	      # files will link in the last one created.
10182b68e1f86Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
101833bfa90b6Smrg	      reload_objs="$objlist $last_robj"
1018425dbecb6Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10185b68e1f86Smrg	      if test -n "$last_robj"; then
1018625dbecb6Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10187b68e1f86Smrg	      fi
101883bfa90b6Smrg	      func_append delfiles " $output"
101896df26cacSmrg
10190b68e1f86Smrg	    else
10191b68e1f86Smrg	      output=
10192b68e1f86Smrg	    fi
10193b68e1f86Smrg
1019425dbecb6Smrg	    ${skipped_export-false} && {
1019525dbecb6Smrg	      func_verbose "generating symbol list for '$libname.la'"
1019625dbecb6Smrg	      export_symbols=$output_objdir/$libname.exp
10197b68e1f86Smrg	      $opt_dry_run || $RM $export_symbols
10198b68e1f86Smrg	      libobjs=$output
10199b68e1f86Smrg	      # Append the command to create the export file.
10200b68e1f86Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10201b68e1f86Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10202b68e1f86Smrg	      if test -n "$last_robj"; then
10203b68e1f86Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10204b68e1f86Smrg	      fi
1020525dbecb6Smrg	    }
102066df26cacSmrg
10207b68e1f86Smrg	    test -n "$save_libobjs" &&
10208b68e1f86Smrg	      func_verbose "creating a temporary reloadable object file: $output"
102096df26cacSmrg
10210b68e1f86Smrg	    # Loop through the commands generated above and execute them.
1021125dbecb6Smrg	    save_ifs=$IFS; IFS='~'
10212b68e1f86Smrg	    for cmd in $concat_cmds; do
1021325dbecb6Smrg	      IFS=$save_ifs
1021425dbecb6Smrg	      $opt_quiet || {
1021525dbecb6Smrg		  func_quote_arg expand,pretty "$cmd"
1021625dbecb6Smrg		  eval "func_echo $func_quote_arg_result"
10217b68e1f86Smrg	      }
10218b68e1f86Smrg	      $opt_dry_run || eval "$cmd" || {
10219b68e1f86Smrg		lt_exit=$?
10220b68e1f86Smrg
10221b68e1f86Smrg		# Restore the uninstalled library and exit
1022225dbecb6Smrg		if test relink = "$opt_mode"; then
10223b68e1f86Smrg		  ( cd "$output_objdir" && \
10224b68e1f86Smrg		    $RM "${realname}T" && \
10225b68e1f86Smrg		    $MV "${realname}U" "$realname" )
10226b68e1f86Smrg		fi
102276df26cacSmrg
10228b68e1f86Smrg		exit $lt_exit
10229b68e1f86Smrg	      }
10230b68e1f86Smrg	    done
1023125dbecb6Smrg	    IFS=$save_ifs
102326df26cacSmrg
10233b68e1f86Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10234b68e1f86Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10235b68e1f86Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
102366df26cacSmrg	    fi
102376df26cacSmrg	  fi
102386df26cacSmrg
1023925dbecb6Smrg          ${skipped_export-false} && {
10240b68e1f86Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
1024125dbecb6Smrg	      tmp_export_symbols=$export_symbols
1024225dbecb6Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
102433bfa90b6Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10244b68e1f86Smrg	    fi
102456df26cacSmrg
10246b68e1f86Smrg	    if test -n "$orig_export_symbols"; then
10247b68e1f86Smrg	      # The given exports_symbols file has to be filtered, so filter it.
1024825dbecb6Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10249b68e1f86Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
1025025dbecb6Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10251b68e1f86Smrg	      # though. Also, the filter scales superlinearly with the number of
10252b68e1f86Smrg	      # global variables. join(1) would be nice here, but unfortunately
10253b68e1f86Smrg	      # isn't a blessed tool.
10254b68e1f86Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
102553bfa90b6Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10256b68e1f86Smrg	      export_symbols=$output_objdir/$libname.def
10257b68e1f86Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10258b68e1f86Smrg	    fi
1025925dbecb6Smrg	  }
102606df26cacSmrg
10261b68e1f86Smrg	  libobjs=$output
10262b68e1f86Smrg	  # Restore the value of output.
10263b68e1f86Smrg	  output=$save_output
102646df26cacSmrg
10265b68e1f86Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10266b68e1f86Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10267b68e1f86Smrg	    test "X$libobjs" = "X " && libobjs=
10268b68e1f86Smrg	  fi
10269b68e1f86Smrg	  # Expand the library linking commands again to reset the
10270b68e1f86Smrg	  # value of $libobjs for piecewise linking.
10271b68e1f86Smrg
10272b68e1f86Smrg	  # Do each of the archive commands.
1027325dbecb6Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
10274b68e1f86Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10275b68e1f86Smrg	      cmds=$module_expsym_cmds
102766df26cacSmrg	    else
10277b68e1f86Smrg	      cmds=$module_cmds
102786df26cacSmrg	    fi
102796df26cacSmrg	  else
10280b68e1f86Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10281b68e1f86Smrg	      cmds=$archive_expsym_cmds
10282b68e1f86Smrg	    else
10283b68e1f86Smrg	      cmds=$archive_cmds
10284b68e1f86Smrg	    fi
102856df26cacSmrg	  fi
102866df26cacSmrg	fi
102876df26cacSmrg
10288b68e1f86Smrg	if test -n "$delfiles"; then
10289b68e1f86Smrg	  # Append the command to remove temporary files to $cmds.
10290b68e1f86Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10291b68e1f86Smrg	fi
102926df26cacSmrg
10293b68e1f86Smrg	# Add any objects from preloaded convenience libraries
10294b68e1f86Smrg	if test -n "$dlprefiles"; then
1029525dbecb6Smrg	  gentop=$output_objdir/${outputname}x
102963bfa90b6Smrg	  func_append generated " $gentop"
102976df26cacSmrg
10298b68e1f86Smrg	  func_extract_archives $gentop $dlprefiles
102993bfa90b6Smrg	  func_append libobjs " $func_extract_archives_result"
10300b68e1f86Smrg	  test "X$libobjs" = "X " && libobjs=
103016df26cacSmrg	fi
103026df26cacSmrg
1030325dbecb6Smrg	save_ifs=$IFS; IFS='~'
10304b68e1f86Smrg	for cmd in $cmds; do
1030525dbecb6Smrg	  IFS=$sp$nl
10306b68e1f86Smrg	  eval cmd=\"$cmd\"
1030725dbecb6Smrg	  IFS=$save_ifs
1030825dbecb6Smrg	  $opt_quiet || {
1030925dbecb6Smrg	    func_quote_arg expand,pretty "$cmd"
1031025dbecb6Smrg	    eval "func_echo $func_quote_arg_result"
10311b68e1f86Smrg	  }
10312b68e1f86Smrg	  $opt_dry_run || eval "$cmd" || {
10313b68e1f86Smrg	    lt_exit=$?
103146df26cacSmrg
10315b68e1f86Smrg	    # Restore the uninstalled library and exit
1031625dbecb6Smrg	    if test relink = "$opt_mode"; then
10317b68e1f86Smrg	      ( cd "$output_objdir" && \
10318b68e1f86Smrg	        $RM "${realname}T" && \
10319b68e1f86Smrg		$MV "${realname}U" "$realname" )
103206df26cacSmrg	    fi
103216df26cacSmrg
10322b68e1f86Smrg	    exit $lt_exit
10323b68e1f86Smrg	  }
10324b68e1f86Smrg	done
1032525dbecb6Smrg	IFS=$save_ifs
103266df26cacSmrg
10327b68e1f86Smrg	# Restore the uninstalled library and exit
1032825dbecb6Smrg	if test relink = "$opt_mode"; then
10329b68e1f86Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
103306df26cacSmrg
10331b68e1f86Smrg	  if test -n "$convenience"; then
10332b68e1f86Smrg	    if test -z "$whole_archive_flag_spec"; then
10333b68e1f86Smrg	      func_show_eval '${RM}r "$gentop"'
10334b68e1f86Smrg	    fi
10335b68e1f86Smrg	  fi
103366df26cacSmrg
10337b68e1f86Smrg	  exit $EXIT_SUCCESS
10338b68e1f86Smrg	fi
103396df26cacSmrg
10340b68e1f86Smrg	# Create links to the real library.
10341b68e1f86Smrg	for linkname in $linknames; do
10342b68e1f86Smrg	  if test "$realname" != "$linkname"; then
10343b68e1f86Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
103446df26cacSmrg	  fi
103456df26cacSmrg	done
103466df26cacSmrg
10347b68e1f86Smrg	# If -module or -export-dynamic was specified, set the dlname.
1034825dbecb6Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10349b68e1f86Smrg	  # On all known operating systems, these are identical.
1035025dbecb6Smrg	  dlname=$soname
10351b68e1f86Smrg	fi
10352b68e1f86Smrg      fi
103536df26cacSmrg      ;;
103546df26cacSmrg
10355b68e1f86Smrg    obj)
1035625dbecb6Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
1035725dbecb6Smrg	func_warning "'-dlopen' is ignored for objects"
10358b68e1f86Smrg      fi
103596df26cacSmrg
10360b68e1f86Smrg      case " $deplibs" in
10361b68e1f86Smrg      *\ -l* | *\ -L*)
1036225dbecb6Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
103636df26cacSmrg      esac
103646df26cacSmrg
10365b68e1f86Smrg      test -n "$rpath" && \
1036625dbecb6Smrg	func_warning "'-rpath' is ignored for objects"
103676df26cacSmrg
10368b68e1f86Smrg      test -n "$xrpath" && \
1036925dbecb6Smrg	func_warning "'-R' is ignored for objects"
103706df26cacSmrg
10371b68e1f86Smrg      test -n "$vinfo" && \
1037225dbecb6Smrg	func_warning "'-version-info' is ignored for objects"
10373b68e1f86Smrg
10374b68e1f86Smrg      test -n "$release" && \
1037525dbecb6Smrg	func_warning "'-release' is ignored for objects"
10376b68e1f86Smrg
10377b68e1f86Smrg      case $output in
10378b68e1f86Smrg      *.lo)
10379b68e1f86Smrg	test -n "$objs$old_deplibs" && \
1038025dbecb6Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10381b68e1f86Smrg
10382b68e1f86Smrg	libobj=$output
10383b68e1f86Smrg	func_lo2o "$libobj"
10384b68e1f86Smrg	obj=$func_lo2o_result
103856df26cacSmrg	;;
103866df26cacSmrg      *)
10387b68e1f86Smrg	libobj=
1038825dbecb6Smrg	obj=$output
103896df26cacSmrg	;;
103906df26cacSmrg      esac
103916df26cacSmrg
10392b68e1f86Smrg      # Delete the old objects.
10393b68e1f86Smrg      $opt_dry_run || $RM $obj $libobj
103946df26cacSmrg
10395b68e1f86Smrg      # Objects from convenience libraries.  This assumes
10396b68e1f86Smrg      # single-version convenience libraries.  Whenever we create
10397b68e1f86Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10398b68e1f86Smrg      # the extraction.
10399b68e1f86Smrg      reload_conv_objs=
10400b68e1f86Smrg      gentop=
1040125dbecb6Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
1040225dbecb6Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
1040325dbecb6Smrg      # into space.
1040425dbecb6Smrg      case $reload_cmds in
1040525dbecb6Smrg        *\$LD[\ \$]*) wl= ;;
1040625dbecb6Smrg      esac
10407b68e1f86Smrg      if test -n "$convenience"; then
10408b68e1f86Smrg	if test -n "$whole_archive_flag_spec"; then
10409b68e1f86Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
1041025dbecb6Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
1041125dbecb6Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10412b68e1f86Smrg	else
1041325dbecb6Smrg	  gentop=$output_objdir/${obj}x
104143bfa90b6Smrg	  func_append generated " $gentop"
104156df26cacSmrg
10416b68e1f86Smrg	  func_extract_archives $gentop $convenience
10417b68e1f86Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10418b68e1f86Smrg	fi
104196df26cacSmrg      fi
104206df26cacSmrg
104213bfa90b6Smrg      # If we're not building shared, we need to use non_pic_objs
1042225dbecb6Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
104233bfa90b6Smrg
10424b68e1f86Smrg      # Create the old-style object.
1042525dbecb6Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
104266df26cacSmrg
1042725dbecb6Smrg      output=$obj
10428b68e1f86Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
104296df26cacSmrg
10430b68e1f86Smrg      # Exit if we aren't doing a library object file.
10431b68e1f86Smrg      if test -z "$libobj"; then
10432b68e1f86Smrg	if test -n "$gentop"; then
10433b68e1f86Smrg	  func_show_eval '${RM}r "$gentop"'
10434b68e1f86Smrg	fi
10435b68e1f86Smrg
10436b68e1f86Smrg	exit $EXIT_SUCCESS
104376df26cacSmrg      fi
10438b68e1f86Smrg
1043925dbecb6Smrg      test yes = "$build_libtool_libs" || {
10440b68e1f86Smrg	if test -n "$gentop"; then
10441b68e1f86Smrg	  func_show_eval '${RM}r "$gentop"'
10442b68e1f86Smrg	fi
10443b68e1f86Smrg
10444b68e1f86Smrg	# Create an invalid libtool object if no PIC, so that we don't
10445b68e1f86Smrg	# accidentally link it into a program.
10446b68e1f86Smrg	# $show "echo timestamp > $libobj"
10447b68e1f86Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10448b68e1f86Smrg	exit $EXIT_SUCCESS
1044925dbecb6Smrg      }
10450b68e1f86Smrg
1045125dbecb6Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10452b68e1f86Smrg	# Only do commands if we really have different PIC objects.
10453b68e1f86Smrg	reload_objs="$libobjs $reload_conv_objs"
1045425dbecb6Smrg	output=$libobj
10455b68e1f86Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10456b68e1f86Smrg      fi
10457b68e1f86Smrg
10458b68e1f86Smrg      if test -n "$gentop"; then
10459b68e1f86Smrg	func_show_eval '${RM}r "$gentop"'
10460b68e1f86Smrg      fi
10461b68e1f86Smrg
10462b68e1f86Smrg      exit $EXIT_SUCCESS
104636df26cacSmrg      ;;
104646df26cacSmrg
10465b68e1f86Smrg    prog)
10466b68e1f86Smrg      case $host in
10467b68e1f86Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10468b68e1f86Smrg	          output=$func_stripname_result.exe;;
10469b68e1f86Smrg      esac
10470b68e1f86Smrg      test -n "$vinfo" && \
1047125dbecb6Smrg	func_warning "'-version-info' is ignored for programs"
104726df26cacSmrg
10473b68e1f86Smrg      test -n "$release" && \
1047425dbecb6Smrg	func_warning "'-release' is ignored for programs"
104756df26cacSmrg
1047625dbecb6Smrg      $preload \
1047725dbecb6Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
1047825dbecb6Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10479b68e1f86Smrg
10480b68e1f86Smrg      case $host in
10481b68e1f86Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10482b68e1f86Smrg	# On Rhapsody replace the C library is the System framework
104833bfa90b6Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
104843bfa90b6Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
104856df26cacSmrg	;;
10486b68e1f86Smrg      esac
104876df26cacSmrg
10488b68e1f86Smrg      case $host in
10489b68e1f86Smrg      *-*-darwin*)
10490b68e1f86Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10491b68e1f86Smrg	# But is supposedly fixed on 10.4 or later (yay!).
1049225dbecb6Smrg	if test CXX = "$tagname"; then
10493b68e1f86Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10494b68e1f86Smrg	    10.[0123])
1049525dbecb6Smrg	      func_append compile_command " $wl-bind_at_load"
1049625dbecb6Smrg	      func_append finalize_command " $wl-bind_at_load"
10497b68e1f86Smrg	    ;;
10498b68e1f86Smrg	  esac
104996df26cacSmrg	fi
10500b68e1f86Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
105013bfa90b6Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105023bfa90b6Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10503b68e1f86Smrg	;;
10504b68e1f86Smrg      esac
105056df26cacSmrg
105066df26cacSmrg
10507b68e1f86Smrg      # move library search paths that coincide with paths to not yet
10508b68e1f86Smrg      # installed libraries to the beginning of the library search list
10509b68e1f86Smrg      new_libs=
10510b68e1f86Smrg      for path in $notinst_path; do
10511b68e1f86Smrg	case " $new_libs " in
10512b68e1f86Smrg	*" -L$path/$objdir "*) ;;
10513b68e1f86Smrg	*)
10514b68e1f86Smrg	  case " $compile_deplibs " in
10515b68e1f86Smrg	  *" -L$path/$objdir "*)
105163bfa90b6Smrg	    func_append new_libs " -L$path/$objdir" ;;
105176df26cacSmrg	  esac
10518b68e1f86Smrg	  ;;
10519b68e1f86Smrg	esac
10520b68e1f86Smrg      done
10521b68e1f86Smrg      for deplib in $compile_deplibs; do
10522b68e1f86Smrg	case $deplib in
10523b68e1f86Smrg	-L*)
10524b68e1f86Smrg	  case " $new_libs " in
10525b68e1f86Smrg	  *" $deplib "*) ;;
105263bfa90b6Smrg	  *) func_append new_libs " $deplib" ;;
105276df26cacSmrg	  esac
10528b68e1f86Smrg	  ;;
105293bfa90b6Smrg	*) func_append new_libs " $deplib" ;;
10530b68e1f86Smrg	esac
10531b68e1f86Smrg      done
1053225dbecb6Smrg      compile_deplibs=$new_libs
105336df26cacSmrg
105346df26cacSmrg
105353bfa90b6Smrg      func_append compile_command " $compile_deplibs"
105363bfa90b6Smrg      func_append finalize_command " $finalize_deplibs"
105376df26cacSmrg
10538b68e1f86Smrg      if test -n "$rpath$xrpath"; then
10539b68e1f86Smrg	# If the user specified any rpath flags, then add them.
10540b68e1f86Smrg	for libdir in $rpath $xrpath; do
10541b68e1f86Smrg	  # This is the magic to use -rpath.
10542b68e1f86Smrg	  case "$finalize_rpath " in
10543b68e1f86Smrg	  *" $libdir "*) ;;
105443bfa90b6Smrg	  *) func_append finalize_rpath " $libdir" ;;
10545b68e1f86Smrg	  esac
10546b68e1f86Smrg	done
10547b68e1f86Smrg      fi
105486df26cacSmrg
10549b68e1f86Smrg      # Now hardcode the library paths
10550b68e1f86Smrg      rpath=
10551b68e1f86Smrg      hardcode_libdirs=
10552b68e1f86Smrg      for libdir in $compile_rpath $finalize_rpath; do
10553b68e1f86Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10554b68e1f86Smrg	  if test -n "$hardcode_libdir_separator"; then
10555b68e1f86Smrg	    if test -z "$hardcode_libdirs"; then
1055625dbecb6Smrg	      hardcode_libdirs=$libdir
10557b68e1f86Smrg	    else
10558b68e1f86Smrg	      # Just accumulate the unique libdirs.
10559b68e1f86Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10560b68e1f86Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10561b68e1f86Smrg		;;
10562b68e1f86Smrg	      *)
105633bfa90b6Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10564b68e1f86Smrg		;;
10565b68e1f86Smrg	      esac
10566b68e1f86Smrg	    fi
105676df26cacSmrg	  else
10568b68e1f86Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
105693bfa90b6Smrg	    func_append rpath " $flag"
105706df26cacSmrg	  fi
10571b68e1f86Smrg	elif test -n "$runpath_var"; then
10572b68e1f86Smrg	  case "$perm_rpath " in
10573b68e1f86Smrg	  *" $libdir "*) ;;
105743bfa90b6Smrg	  *) func_append perm_rpath " $libdir" ;;
10575b68e1f86Smrg	  esac
10576b68e1f86Smrg	fi
10577b68e1f86Smrg	case $host in
10578b68e1f86Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
1057925dbecb6Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10580b68e1f86Smrg	  case :$dllsearchpath: in
10581b68e1f86Smrg	  *":$libdir:"*) ;;
10582b68e1f86Smrg	  ::) dllsearchpath=$libdir;;
105833bfa90b6Smrg	  *) func_append dllsearchpath ":$libdir";;
10584b68e1f86Smrg	  esac
10585b68e1f86Smrg	  case :$dllsearchpath: in
10586b68e1f86Smrg	  *":$testbindir:"*) ;;
10587b68e1f86Smrg	  ::) dllsearchpath=$testbindir;;
105883bfa90b6Smrg	  *) func_append dllsearchpath ":$testbindir";;
10589b68e1f86Smrg	  esac
10590b68e1f86Smrg	  ;;
10591b68e1f86Smrg	esac
10592b68e1f86Smrg      done
10593b68e1f86Smrg      # Substitute the hardcoded libdirs into the rpath.
10594b68e1f86Smrg      if test -n "$hardcode_libdir_separator" &&
10595b68e1f86Smrg	 test -n "$hardcode_libdirs"; then
1059625dbecb6Smrg	libdir=$hardcode_libdirs
10597b68e1f86Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10598b68e1f86Smrg      fi
1059925dbecb6Smrg      compile_rpath=$rpath
106006df26cacSmrg
10601b68e1f86Smrg      rpath=
10602b68e1f86Smrg      hardcode_libdirs=
10603b68e1f86Smrg      for libdir in $finalize_rpath; do
10604b68e1f86Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10605b68e1f86Smrg	  if test -n "$hardcode_libdir_separator"; then
10606b68e1f86Smrg	    if test -z "$hardcode_libdirs"; then
1060725dbecb6Smrg	      hardcode_libdirs=$libdir
10608b68e1f86Smrg	    else
10609b68e1f86Smrg	      # Just accumulate the unique libdirs.
10610b68e1f86Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10611b68e1f86Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10612b68e1f86Smrg		;;
10613b68e1f86Smrg	      *)
106143bfa90b6Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10615b68e1f86Smrg		;;
10616b68e1f86Smrg	      esac
10617b68e1f86Smrg	    fi
106186df26cacSmrg	  else
10619b68e1f86Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
106203bfa90b6Smrg	    func_append rpath " $flag"
106216df26cacSmrg	  fi
10622b68e1f86Smrg	elif test -n "$runpath_var"; then
10623b68e1f86Smrg	  case "$finalize_perm_rpath " in
10624b68e1f86Smrg	  *" $libdir "*) ;;
106253bfa90b6Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10626b68e1f86Smrg	  esac
106276df26cacSmrg	fi
10628b68e1f86Smrg      done
10629b68e1f86Smrg      # Substitute the hardcoded libdirs into the rpath.
10630b68e1f86Smrg      if test -n "$hardcode_libdir_separator" &&
10631b68e1f86Smrg	 test -n "$hardcode_libdirs"; then
1063225dbecb6Smrg	libdir=$hardcode_libdirs
10633b68e1f86Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10634b68e1f86Smrg      fi
1063525dbecb6Smrg      finalize_rpath=$rpath
106366df26cacSmrg
1063725dbecb6Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10638b68e1f86Smrg	# Transform all the library objects into standard objects.
106393bfa90b6Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106403bfa90b6Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10641b68e1f86Smrg      fi
106426df26cacSmrg
1064325dbecb6Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
106446df26cacSmrg
10645b68e1f86Smrg      # template prelinking step
10646b68e1f86Smrg      if test -n "$prelink_cmds"; then
10647b68e1f86Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10648b68e1f86Smrg      fi
106496df26cacSmrg
1065025dbecb6Smrg      wrappers_required=:
10651b68e1f86Smrg      case $host in
106523bfa90b6Smrg      *cegcc* | *mingw32ce*)
106533bfa90b6Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
1065425dbecb6Smrg        wrappers_required=false
106553bfa90b6Smrg        ;;
10656b68e1f86Smrg      *cygwin* | *mingw* )
1065725dbecb6Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10658b68e1f86Smrg        ;;
10659b68e1f86Smrg      *)
1066025dbecb6Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
1066125dbecb6Smrg          wrappers_required=false
10662b68e1f86Smrg        fi
10663b68e1f86Smrg        ;;
10664b68e1f86Smrg      esac
1066525dbecb6Smrg      $wrappers_required || {
10666b68e1f86Smrg	# Replace the output file specification.
106673bfa90b6Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1066825dbecb6Smrg	link_command=$compile_command$compile_rpath
106696df26cacSmrg
10670b68e1f86Smrg	# We have no uninstalled library dependencies, so finalize right now.
10671b68e1f86Smrg	exit_status=0
10672b68e1f86Smrg	func_show_eval "$link_command" 'exit_status=$?'
106736df26cacSmrg
106743bfa90b6Smrg	if test -n "$postlink_cmds"; then
106753bfa90b6Smrg	  func_to_tool_file "$output"
106763bfa90b6Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
106773bfa90b6Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
106783bfa90b6Smrg	fi
106793bfa90b6Smrg
10680b68e1f86Smrg	# Delete the generated files.
1068125dbecb6Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
1068225dbecb6Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
106836df26cacSmrg	fi
106846df26cacSmrg
10685b68e1f86Smrg	exit $exit_status
1068625dbecb6Smrg      }
106876df26cacSmrg
10688b68e1f86Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10689b68e1f86Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10690b68e1f86Smrg      fi
10691b68e1f86Smrg      if test -n "$finalize_shlibpath"; then
10692b68e1f86Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10693b68e1f86Smrg      fi
106946df26cacSmrg
10695b68e1f86Smrg      compile_var=
10696b68e1f86Smrg      finalize_var=
10697b68e1f86Smrg      if test -n "$runpath_var"; then
10698b68e1f86Smrg	if test -n "$perm_rpath"; then
10699b68e1f86Smrg	  # We should set the runpath_var.
10700b68e1f86Smrg	  rpath=
10701b68e1f86Smrg	  for dir in $perm_rpath; do
107023bfa90b6Smrg	    func_append rpath "$dir:"
10703b68e1f86Smrg	  done
10704b68e1f86Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
107056df26cacSmrg	fi
10706b68e1f86Smrg	if test -n "$finalize_perm_rpath"; then
10707b68e1f86Smrg	  # We should set the runpath_var.
10708b68e1f86Smrg	  rpath=
10709b68e1f86Smrg	  for dir in $finalize_perm_rpath; do
107103bfa90b6Smrg	    func_append rpath "$dir:"
10711b68e1f86Smrg	  done
10712b68e1f86Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
107136df26cacSmrg	fi
10714b68e1f86Smrg      fi
107156df26cacSmrg
1071625dbecb6Smrg      if test yes = "$no_install"; then
10717b68e1f86Smrg	# We don't need to create a wrapper script.
1071825dbecb6Smrg	link_command=$compile_var$compile_command$compile_rpath
10719b68e1f86Smrg	# Replace the output file specification.
107203bfa90b6Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10721b68e1f86Smrg	# Delete the old output file.
10722b68e1f86Smrg	$opt_dry_run || $RM $output
10723b68e1f86Smrg	# Link the executable and exit
10724b68e1f86Smrg	func_show_eval "$link_command" 'exit $?'
107253bfa90b6Smrg
107263bfa90b6Smrg	if test -n "$postlink_cmds"; then
107273bfa90b6Smrg	  func_to_tool_file "$output"
107283bfa90b6Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
107293bfa90b6Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
107303bfa90b6Smrg	fi
107313bfa90b6Smrg
107326df26cacSmrg	exit $EXIT_SUCCESS
10733b68e1f86Smrg      fi
107346df26cacSmrg
1073525dbecb6Smrg      case $hardcode_action,$fast_install in
1073625dbecb6Smrg        relink,*)
1073725dbecb6Smrg	  # Fast installation is not supported
1073825dbecb6Smrg	  link_command=$compile_var$compile_command$compile_rpath
1073925dbecb6Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10740b68e1f86Smrg
1074125dbecb6Smrg	  func_warning "this platform does not like uninstalled shared libraries"
1074225dbecb6Smrg	  func_warning "'$output' will be relinked during installation"
1074325dbecb6Smrg	  ;;
1074425dbecb6Smrg        *,yes)
1074525dbecb6Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1074625dbecb6Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
1074725dbecb6Smrg          ;;
1074825dbecb6Smrg	*,no)
1074925dbecb6Smrg	  link_command=$compile_var$compile_command$compile_rpath
1075025dbecb6Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1075125dbecb6Smrg          ;;
1075225dbecb6Smrg	*,needless)
1075325dbecb6Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1075425dbecb6Smrg	  relink_command=
1075525dbecb6Smrg          ;;
1075625dbecb6Smrg      esac
107576df26cacSmrg
10758b68e1f86Smrg      # Replace the output file specification.
107593bfa90b6Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
107606df26cacSmrg
10761b68e1f86Smrg      # Delete the old output files.
10762b68e1f86Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
107636df26cacSmrg
10764b68e1f86Smrg      func_show_eval "$link_command" 'exit $?'
107656df26cacSmrg
107663bfa90b6Smrg      if test -n "$postlink_cmds"; then
107673bfa90b6Smrg	func_to_tool_file "$output_objdir/$outputname"
107683bfa90b6Smrg	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'`
107693bfa90b6Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
107703bfa90b6Smrg      fi
107713bfa90b6Smrg
10772b68e1f86Smrg      # Now create the wrapper script.
10773b68e1f86Smrg      func_verbose "creating $output"
107746df26cacSmrg
10775b68e1f86Smrg      # Quote the relink command for shipping.
10776b68e1f86Smrg      if test -n "$relink_command"; then
10777b68e1f86Smrg	# Preserve any variables that may affect compiler behavior
10778b68e1f86Smrg	for var in $variables_saved_for_relink; do
10779b68e1f86Smrg	  if eval test -z \"\${$var+set}\"; then
10780b68e1f86Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10781b68e1f86Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10782b68e1f86Smrg	    relink_command="$var=; export $var; $relink_command"
107836df26cacSmrg	  else
1078425dbecb6Smrg	    func_quote_arg pretty "$var_value"
1078525dbecb6Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
107866df26cacSmrg	  fi
10787b68e1f86Smrg	done
1078825dbecb6Smrg	func_quote eval cd "`pwd`"
1078925dbecb6Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
1079025dbecb6Smrg	relink_command=$func_quote_arg_unquoted_result
10791b68e1f86Smrg      fi
10792b68e1f86Smrg
10793b68e1f86Smrg      # Only actually do things if not in dry run mode.
10794b68e1f86Smrg      $opt_dry_run || {
10795b68e1f86Smrg	# win32 will think the script is a binary if it has
10796b68e1f86Smrg	# a .exe suffix, so we strip it off here.
10797b68e1f86Smrg	case $output in
10798b68e1f86Smrg	  *.exe) func_stripname '' '.exe' "$output"
10799b68e1f86Smrg	         output=$func_stripname_result ;;
10800b68e1f86Smrg	esac
10801b68e1f86Smrg	# test for cygwin because mv fails w/o .exe extensions
10802b68e1f86Smrg	case $host in
10803b68e1f86Smrg	  *cygwin*)
10804b68e1f86Smrg	    exeext=.exe
10805b68e1f86Smrg	    func_stripname '' '.exe' "$outputname"
10806b68e1f86Smrg	    outputname=$func_stripname_result ;;
10807b68e1f86Smrg	  *) exeext= ;;
108086df26cacSmrg	esac
10809b68e1f86Smrg	case $host in
10810b68e1f86Smrg	  *cygwin* | *mingw* )
10811b68e1f86Smrg	    func_dirname_and_basename "$output" "" "."
10812b68e1f86Smrg	    output_name=$func_basename_result
10813b68e1f86Smrg	    output_path=$func_dirname_result
1081425dbecb6Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
1081525dbecb6Smrg	    cwrapper=$output_path/$output_name.exe
10816b68e1f86Smrg	    $RM $cwrappersource $cwrapper
10817b68e1f86Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10818b68e1f86Smrg
10819b68e1f86Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10820b68e1f86Smrg
10821b68e1f86Smrg	    # The wrapper executable is built using the $host compiler,
10822b68e1f86Smrg	    # because it contains $host paths and files. If cross-
10823b68e1f86Smrg	    # compiling, it, like the target executable, must be
10824b68e1f86Smrg	    # executed on the $host or under an emulation environment.
10825b68e1f86Smrg	    $opt_dry_run || {
10826b68e1f86Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10827b68e1f86Smrg	      $STRIP $cwrapper
10828b68e1f86Smrg	    }
108296df26cacSmrg
10830b68e1f86Smrg	    # Now, create the wrapper script for func_source use:
10831b68e1f86Smrg	    func_ltwrapper_scriptname $cwrapper
10832b68e1f86Smrg	    $RM $func_ltwrapper_scriptname_result
10833b68e1f86Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10834b68e1f86Smrg	    $opt_dry_run || {
10835b68e1f86Smrg	      # note: this script will not be executed, so do not chmod.
1083625dbecb6Smrg	      if test "x$build" = "x$host"; then
10837b68e1f86Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10838b68e1f86Smrg	      else
10839b68e1f86Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10840b68e1f86Smrg	      fi
10841b68e1f86Smrg	    }
10842b68e1f86Smrg	  ;;
10843b68e1f86Smrg	  * )
10844b68e1f86Smrg	    $RM $output
10845b68e1f86Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
108466df26cacSmrg
10847b68e1f86Smrg	    func_emit_wrapper no > $output
10848b68e1f86Smrg	    chmod +x $output
10849b68e1f86Smrg	  ;;
10850b68e1f86Smrg	esac
10851b68e1f86Smrg      }
10852b68e1f86Smrg      exit $EXIT_SUCCESS
10853b68e1f86Smrg      ;;
10854b68e1f86Smrg    esac
108556df26cacSmrg
10856b68e1f86Smrg    # See if we need to build an old-fashioned archive.
10857b68e1f86Smrg    for oldlib in $oldlibs; do
108586df26cacSmrg
1085925dbecb6Smrg      case $build_libtool_libs in
1086025dbecb6Smrg        convenience)
1086125dbecb6Smrg	  oldobjs="$libobjs_save $symfileobj"
1086225dbecb6Smrg	  addlibs=$convenience
10863b68e1f86Smrg	  build_libtool_libs=no
1086425dbecb6Smrg	  ;;
1086525dbecb6Smrg	module)
1086625dbecb6Smrg	  oldobjs=$libobjs_save
1086725dbecb6Smrg	  addlibs=$old_convenience
1086825dbecb6Smrg	  build_libtool_libs=no
1086925dbecb6Smrg          ;;
1087025dbecb6Smrg	*)
10871b68e1f86Smrg	  oldobjs="$old_deplibs $non_pic_objects"
1087225dbecb6Smrg	  $preload && test -f "$symfileobj" \
1087325dbecb6Smrg	    && func_append oldobjs " $symfileobj"
1087425dbecb6Smrg	  addlibs=$old_convenience
1087525dbecb6Smrg	  ;;
1087625dbecb6Smrg      esac
108776df26cacSmrg
10878b68e1f86Smrg      if test -n "$addlibs"; then
1087925dbecb6Smrg	gentop=$output_objdir/${outputname}x
108803bfa90b6Smrg	func_append generated " $gentop"
108816df26cacSmrg
10882b68e1f86Smrg	func_extract_archives $gentop $addlibs
108833bfa90b6Smrg	func_append oldobjs " $func_extract_archives_result"
10884b68e1f86Smrg      fi
108856df26cacSmrg
10886b68e1f86Smrg      # Do each command in the archive commands.
1088725dbecb6Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10888b68e1f86Smrg	cmds=$old_archive_from_new_cmds
10889b68e1f86Smrg      else
108906df26cacSmrg
10891b68e1f86Smrg	# Add any objects from preloaded convenience libraries
10892b68e1f86Smrg	if test -n "$dlprefiles"; then
1089325dbecb6Smrg	  gentop=$output_objdir/${outputname}x
108943bfa90b6Smrg	  func_append generated " $gentop"
108956df26cacSmrg
10896b68e1f86Smrg	  func_extract_archives $gentop $dlprefiles
108973bfa90b6Smrg	  func_append oldobjs " $func_extract_archives_result"
10898b68e1f86Smrg	fi
108996df26cacSmrg
10900b68e1f86Smrg	# POSIX demands no paths to be encoded in archives.  We have
10901b68e1f86Smrg	# to avoid creating archives with duplicate basenames if we
10902b68e1f86Smrg	# might have to extract them afterwards, e.g., when creating a
10903b68e1f86Smrg	# static archive out of a convenience library, or when linking
10904b68e1f86Smrg	# the entirety of a libtool archive into another (currently
10905b68e1f86Smrg	# not supported by libtool).
10906b68e1f86Smrg	if (for obj in $oldobjs
10907b68e1f86Smrg	    do
10908b68e1f86Smrg	      func_basename "$obj"
10909b68e1f86Smrg	      $ECHO "$func_basename_result"
10910b68e1f86Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10911b68e1f86Smrg	  :
10912b68e1f86Smrg	else
109133bfa90b6Smrg	  echo "copying selected object files to avoid basename conflicts..."
1091425dbecb6Smrg	  gentop=$output_objdir/${outputname}x
109153bfa90b6Smrg	  func_append generated " $gentop"
10916b68e1f86Smrg	  func_mkdir_p "$gentop"
10917b68e1f86Smrg	  save_oldobjs=$oldobjs
10918b68e1f86Smrg	  oldobjs=
10919b68e1f86Smrg	  counter=1
10920b68e1f86Smrg	  for obj in $save_oldobjs
10921b68e1f86Smrg	  do
10922b68e1f86Smrg	    func_basename "$obj"
1092325dbecb6Smrg	    objbase=$func_basename_result
10924b68e1f86Smrg	    case " $oldobjs " in
10925b68e1f86Smrg	    " ") oldobjs=$obj ;;
10926b68e1f86Smrg	    *[\ /]"$objbase "*)
10927b68e1f86Smrg	      while :; do
10928b68e1f86Smrg		# Make sure we don't pick an alternate name that also
10929b68e1f86Smrg		# overlaps.
10930b68e1f86Smrg		newobj=lt$counter-$objbase
10931b68e1f86Smrg		func_arith $counter + 1
10932b68e1f86Smrg		counter=$func_arith_result
10933b68e1f86Smrg		case " $oldobjs " in
10934b68e1f86Smrg		*[\ /]"$newobj "*) ;;
10935b68e1f86Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10936b68e1f86Smrg		esac
10937b68e1f86Smrg	      done
10938b68e1f86Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
109393bfa90b6Smrg	      func_append oldobjs " $gentop/$newobj"
10940b68e1f86Smrg	      ;;
109413bfa90b6Smrg	    *) func_append oldobjs " $obj" ;;
10942b68e1f86Smrg	    esac
109436df26cacSmrg	  done
109446df26cacSmrg	fi
109453bfa90b6Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
109463bfa90b6Smrg	tool_oldlib=$func_to_tool_file_result
10947b68e1f86Smrg	eval cmds=\"$old_archive_cmds\"
109486df26cacSmrg
10949b68e1f86Smrg	func_len " $cmds"
10950b68e1f86Smrg	len=$func_len_result
10951b68e1f86Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10952b68e1f86Smrg	  cmds=$old_archive_cmds
109533bfa90b6Smrg	elif test -n "$archiver_list_spec"; then
109543bfa90b6Smrg	  func_verbose "using command file archive linking..."
109553bfa90b6Smrg	  for obj in $oldobjs
109563bfa90b6Smrg	  do
109573bfa90b6Smrg	    func_to_tool_file "$obj"
109583bfa90b6Smrg	    $ECHO "$func_to_tool_file_result"
109593bfa90b6Smrg	  done > $output_objdir/$libname.libcmd
109603bfa90b6Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
109613bfa90b6Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
109623bfa90b6Smrg	  cmds=$old_archive_cmds
10963b68e1f86Smrg	else
10964b68e1f86Smrg	  # the command line is too long to link in one step, link in parts
10965b68e1f86Smrg	  func_verbose "using piecewise archive linking..."
10966b68e1f86Smrg	  save_RANLIB=$RANLIB
10967b68e1f86Smrg	  RANLIB=:
10968b68e1f86Smrg	  objlist=
10969b68e1f86Smrg	  concat_cmds=
10970b68e1f86Smrg	  save_oldobjs=$oldobjs
10971b68e1f86Smrg	  oldobjs=
10972b68e1f86Smrg	  # Is there a better way of finding the last object in the list?
10973b68e1f86Smrg	  for obj in $save_oldobjs
10974b68e1f86Smrg	  do
10975b68e1f86Smrg	    last_oldobj=$obj
10976b68e1f86Smrg	  done
10977b68e1f86Smrg	  eval test_cmds=\"$old_archive_cmds\"
10978b68e1f86Smrg	  func_len " $test_cmds"
10979b68e1f86Smrg	  len0=$func_len_result
10980b68e1f86Smrg	  len=$len0
10981b68e1f86Smrg	  for obj in $save_oldobjs
10982b68e1f86Smrg	  do
10983b68e1f86Smrg	    func_len " $obj"
10984b68e1f86Smrg	    func_arith $len + $func_len_result
10985b68e1f86Smrg	    len=$func_arith_result
10986b68e1f86Smrg	    func_append objlist " $obj"
10987b68e1f86Smrg	    if test "$len" -lt "$max_cmd_len"; then
10988b68e1f86Smrg	      :
10989b68e1f86Smrg	    else
10990b68e1f86Smrg	      # the above command should be used before it gets too long
10991b68e1f86Smrg	      oldobjs=$objlist
1099225dbecb6Smrg	      if test "$obj" = "$last_oldobj"; then
10993b68e1f86Smrg		RANLIB=$save_RANLIB
10994b68e1f86Smrg	      fi
10995b68e1f86Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1099625dbecb6Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
10997b68e1f86Smrg	      objlist=
10998b68e1f86Smrg	      len=$len0
10999b68e1f86Smrg	    fi
11000b68e1f86Smrg	  done
11001b68e1f86Smrg	  RANLIB=$save_RANLIB
11002b68e1f86Smrg	  oldobjs=$objlist
1100325dbecb6Smrg	  if test -z "$oldobjs"; then
11004b68e1f86Smrg	    eval cmds=\"\$concat_cmds\"
11005b68e1f86Smrg	  else
11006b68e1f86Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11007b68e1f86Smrg	  fi
11008b68e1f86Smrg	fi
11009b68e1f86Smrg      fi
11010b68e1f86Smrg      func_execute_cmds "$cmds" 'exit $?'
110116df26cacSmrg    done
110126df26cacSmrg
11013b68e1f86Smrg    test -n "$generated" && \
11014b68e1f86Smrg      func_show_eval "${RM}r$generated"
110156df26cacSmrg
11016b68e1f86Smrg    # Now create the libtool archive.
11017b68e1f86Smrg    case $output in
11018b68e1f86Smrg    *.la)
11019b68e1f86Smrg      old_library=
1102025dbecb6Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11021b68e1f86Smrg      func_verbose "creating $output"
110226df26cacSmrg
11023b68e1f86Smrg      # Preserve any variables that may affect compiler behavior
11024b68e1f86Smrg      for var in $variables_saved_for_relink; do
11025b68e1f86Smrg	if eval test -z \"\${$var+set}\"; then
11026b68e1f86Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11027b68e1f86Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11028b68e1f86Smrg	  relink_command="$var=; export $var; $relink_command"
110296df26cacSmrg	else
1103025dbecb6Smrg	  func_quote_arg pretty,unquoted "$var_value"
1103125dbecb6Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
110326df26cacSmrg	fi
11033b68e1f86Smrg      done
11034b68e1f86Smrg      # Quote the link command for shipping.
1103525dbecb6Smrg      func_quote eval cd "`pwd`"
1103625dbecb6Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1103725dbecb6Smrg      func_quote_arg pretty,unquoted "$relink_command"
1103825dbecb6Smrg      relink_command=$func_quote_arg_unquoted_result
1103925dbecb6Smrg      if test yes = "$hardcode_automatic"; then
11040b68e1f86Smrg	relink_command=
11041b68e1f86Smrg      fi
110426df26cacSmrg
11043b68e1f86Smrg      # Only create the output if not a dry run.
11044b68e1f86Smrg      $opt_dry_run || {
11045b68e1f86Smrg	for installed in no yes; do
1104625dbecb6Smrg	  if test yes = "$installed"; then
11047b68e1f86Smrg	    if test -z "$install_libdir"; then
11048b68e1f86Smrg	      break
11049b68e1f86Smrg	    fi
1105025dbecb6Smrg	    output=$output_objdir/${outputname}i
11051b68e1f86Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11052b68e1f86Smrg	    newdependency_libs=
11053b68e1f86Smrg	    for deplib in $dependency_libs; do
11054b68e1f86Smrg	      case $deplib in
11055b68e1f86Smrg	      *.la)
11056b68e1f86Smrg		func_basename "$deplib"
1105725dbecb6Smrg		name=$func_basename_result
110583bfa90b6Smrg		func_resolve_sysroot "$deplib"
1105925dbecb6Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11060b68e1f86Smrg		test -z "$libdir" && \
1106125dbecb6Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
110623bfa90b6Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
110633bfa90b6Smrg		;;
110643bfa90b6Smrg	      -L*)
110653bfa90b6Smrg		func_stripname -L '' "$deplib"
110663bfa90b6Smrg		func_replace_sysroot "$func_stripname_result"
110673bfa90b6Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11068b68e1f86Smrg		;;
110693bfa90b6Smrg	      -R*)
110703bfa90b6Smrg		func_stripname -R '' "$deplib"
110713bfa90b6Smrg		func_replace_sysroot "$func_stripname_result"
110723bfa90b6Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
110733bfa90b6Smrg		;;
110743bfa90b6Smrg	      *) func_append newdependency_libs " $deplib" ;;
11075b68e1f86Smrg	      esac
11076b68e1f86Smrg	    done
1107725dbecb6Smrg	    dependency_libs=$newdependency_libs
11078b68e1f86Smrg	    newdlfiles=
11079b68e1f86Smrg
11080b68e1f86Smrg	    for lib in $dlfiles; do
11081b68e1f86Smrg	      case $lib in
11082b68e1f86Smrg	      *.la)
11083b68e1f86Smrg	        func_basename "$lib"
1108425dbecb6Smrg		name=$func_basename_result
1108525dbecb6Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11086b68e1f86Smrg		test -z "$libdir" && \
1108725dbecb6Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
110883bfa90b6Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11089b68e1f86Smrg		;;
110903bfa90b6Smrg	      *) func_append newdlfiles " $lib" ;;
11091b68e1f86Smrg	      esac
11092b68e1f86Smrg	    done
1109325dbecb6Smrg	    dlfiles=$newdlfiles
11094b68e1f86Smrg	    newdlprefiles=
11095b68e1f86Smrg	    for lib in $dlprefiles; do
11096b68e1f86Smrg	      case $lib in
11097b68e1f86Smrg	      *.la)
11098b68e1f86Smrg		# Only pass preopened files to the pseudo-archive (for
11099b68e1f86Smrg		# eventual linking with the app. that links it) if we
11100b68e1f86Smrg		# didn't already link the preopened objects directly into
11101b68e1f86Smrg		# the library:
11102b68e1f86Smrg		func_basename "$lib"
1110325dbecb6Smrg		name=$func_basename_result
1110425dbecb6Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11105b68e1f86Smrg		test -z "$libdir" && \
1110625dbecb6Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
111073bfa90b6Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11108b68e1f86Smrg		;;
11109b68e1f86Smrg	      esac
11110b68e1f86Smrg	    done
1111125dbecb6Smrg	    dlprefiles=$newdlprefiles
11112b68e1f86Smrg	  else
11113b68e1f86Smrg	    newdlfiles=
11114b68e1f86Smrg	    for lib in $dlfiles; do
11115b68e1f86Smrg	      case $lib in
1111625dbecb6Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11117b68e1f86Smrg		*) abs=`pwd`"/$lib" ;;
11118b68e1f86Smrg	      esac
111193bfa90b6Smrg	      func_append newdlfiles " $abs"
11120b68e1f86Smrg	    done
1112125dbecb6Smrg	    dlfiles=$newdlfiles
11122b68e1f86Smrg	    newdlprefiles=
11123b68e1f86Smrg	    for lib in $dlprefiles; do
11124b68e1f86Smrg	      case $lib in
1112525dbecb6Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11126b68e1f86Smrg		*) abs=`pwd`"/$lib" ;;
11127b68e1f86Smrg	      esac
111283bfa90b6Smrg	      func_append newdlprefiles " $abs"
11129b68e1f86Smrg	    done
1113025dbecb6Smrg	    dlprefiles=$newdlprefiles
11131b68e1f86Smrg	  fi
11132b68e1f86Smrg	  $RM $output
11133b68e1f86Smrg	  # place dlname in correct position for cygwin
111343bfa90b6Smrg	  # In fact, it would be nice if we could use this code for all target
111353bfa90b6Smrg	  # systems that can't hard-code library paths into their executables
111363bfa90b6Smrg	  # and that have no shared library path variable independent of PATH,
111373bfa90b6Smrg	  # but it turns out we can't easily determine that from inspecting
111383bfa90b6Smrg	  # libtool variables, so we have to hard-code the OSs to which it
111393bfa90b6Smrg	  # applies here; at the moment, that means platforms that use the PE
111403bfa90b6Smrg	  # object format with DLL files.  See the long comment at the top of
111413bfa90b6Smrg	  # tests/bindir.at for full details.
11142b68e1f86Smrg	  tdlname=$dlname
11143b68e1f86Smrg	  case $host,$output,$installed,$module,$dlname in
111443bfa90b6Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
111453bfa90b6Smrg	      # If a -bindir argument was supplied, place the dll there.
1114625dbecb6Smrg	      if test -n "$bindir"; then
111473bfa90b6Smrg		func_relative_path "$install_libdir" "$bindir"
1114825dbecb6Smrg		tdlname=$func_relative_path_result/$dlname
111493bfa90b6Smrg	      else
111503bfa90b6Smrg		# Otherwise fall back on heuristic.
111513bfa90b6Smrg		tdlname=../bin/$dlname
111523bfa90b6Smrg	      fi
111533bfa90b6Smrg	      ;;
11154b68e1f86Smrg	  esac
11155b68e1f86Smrg	  $ECHO > $output "\
11156b68e1f86Smrg# $outputname - a libtool library file
1115725dbecb6Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11158b68e1f86Smrg#
11159b68e1f86Smrg# Please DO NOT delete this file!
11160b68e1f86Smrg# It is necessary for linking the library.
111616df26cacSmrg
11162b68e1f86Smrg# The name that we can dlopen(3).
11163b68e1f86Smrgdlname='$tdlname'
111646df26cacSmrg
11165b68e1f86Smrg# Names of this library.
11166b68e1f86Smrglibrary_names='$library_names'
111676df26cacSmrg
11168b68e1f86Smrg# The name of the static archive.
11169b68e1f86Smrgold_library='$old_library'
111706df26cacSmrg
1117125dbecb6Smrg# Linker flags that cannot go in dependency_libs.
11172b68e1f86Smrginherited_linker_flags='$new_inherited_linker_flags'
111736df26cacSmrg
11174b68e1f86Smrg# Libraries that this one depends upon.
11175b68e1f86Smrgdependency_libs='$dependency_libs'
111766df26cacSmrg
11177b68e1f86Smrg# Names of additional weak libraries provided by this library
11178b68e1f86Smrgweak_library_names='$weak_libs'
111796df26cacSmrg
11180b68e1f86Smrg# Version information for $libname.
11181b68e1f86Smrgcurrent=$current
11182b68e1f86Smrgage=$age
11183b68e1f86Smrgrevision=$revision
111846df26cacSmrg
11185b68e1f86Smrg# Is this an already installed library?
11186b68e1f86Smrginstalled=$installed
111876df26cacSmrg
11188b68e1f86Smrg# Should we warn about portability when linking against -modules?
11189b68e1f86Smrgshouldnotlink=$module
111906df26cacSmrg
11191b68e1f86Smrg# Files to dlopen/dlpreopen
11192b68e1f86Smrgdlopen='$dlfiles'
11193b68e1f86Smrgdlpreopen='$dlprefiles'
111946df26cacSmrg
11195b68e1f86Smrg# Directory that this library needs to be installed in:
11196b68e1f86Smrglibdir='$install_libdir'"
1119725dbecb6Smrg	  if test no,yes = "$installed,$need_relink"; then
11198b68e1f86Smrg	    $ECHO >> $output "\
11199b68e1f86Smrgrelink_command=\"$relink_command\""
11200b68e1f86Smrg	  fi
11201b68e1f86Smrg	done
11202b68e1f86Smrg      }
112036df26cacSmrg
11204b68e1f86Smrg      # Do a symbolic link so that the libtool archive can be found in
11205b68e1f86Smrg      # LD_LIBRARY_PATH before the program is installed.
11206b68e1f86Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11207b68e1f86Smrg      ;;
11208b68e1f86Smrg    esac
11209b68e1f86Smrg    exit $EXIT_SUCCESS
11210b68e1f86Smrg}
112116df26cacSmrg
1121225dbecb6Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
1121325dbecb6Smrg  func_mode_link ${1+"$@"}
1121425dbecb6Smrgfi
112156df26cacSmrg
112166df26cacSmrg
11217b68e1f86Smrg# func_mode_uninstall arg...
11218b68e1f86Smrgfunc_mode_uninstall ()
11219b68e1f86Smrg{
1122025dbecb6Smrg    $debug_cmd
1122125dbecb6Smrg
1122225dbecb6Smrg    RM=$nonopt
112236df26cacSmrg    files=
1122425dbecb6Smrg    rmforce=false
112256df26cacSmrg    exit_status=0
112266df26cacSmrg
112276df26cacSmrg    # This variable tells wrapper scripts just to set variables rather
112286df26cacSmrg    # than running their programs.
1122925dbecb6Smrg    libtool_install_magic=$magic
112306df26cacSmrg
112316df26cacSmrg    for arg
112326df26cacSmrg    do
112336df26cacSmrg      case $arg in
1123425dbecb6Smrg      -f) func_append RM " $arg"; rmforce=: ;;
112353bfa90b6Smrg      -*) func_append RM " $arg" ;;
112363bfa90b6Smrg      *) func_append files " $arg" ;;
112376df26cacSmrg      esac
112386df26cacSmrg    done
112396df26cacSmrg
11240b68e1f86Smrg    test -z "$RM" && \
11241b68e1f86Smrg      func_fatal_help "you must specify an RM program"
112426df26cacSmrg
112436df26cacSmrg    rmdirs=
112446df26cacSmrg
112456df26cacSmrg    for file in $files; do
11246b68e1f86Smrg      func_dirname "$file" "" "."
1124725dbecb6Smrg      dir=$func_dirname_result
1124825dbecb6Smrg      if test . = "$dir"; then
1124925dbecb6Smrg	odir=$objdir
112506df26cacSmrg      else
1125125dbecb6Smrg	odir=$dir/$objdir
112526df26cacSmrg      fi
11253b68e1f86Smrg      func_basename "$file"
1125425dbecb6Smrg      name=$func_basename_result
1125525dbecb6Smrg      test uninstall = "$opt_mode" && odir=$dir
112566df26cacSmrg
112573bfa90b6Smrg      # Remember odir for removal later, being careful to avoid duplicates
1125825dbecb6Smrg      if test clean = "$opt_mode"; then
112596df26cacSmrg	case " $rmdirs " in
112603bfa90b6Smrg	  *" $odir "*) ;;
112613bfa90b6Smrg	  *) func_append rmdirs " $odir" ;;
112626df26cacSmrg	esac
112636df26cacSmrg      fi
112646df26cacSmrg
112656df26cacSmrg      # Don't error if the file doesn't exist and rm -f was used.
11266b68e1f86Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11267b68e1f86Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11268b68e1f86Smrg	 test -f "$file"; then
112696df26cacSmrg	:
112706df26cacSmrg      elif test -d "$file"; then
112716df26cacSmrg	exit_status=1
112726df26cacSmrg	continue
1127325dbecb6Smrg      elif $rmforce; then
112746df26cacSmrg	continue
112756df26cacSmrg      fi
112766df26cacSmrg
1127725dbecb6Smrg      rmfiles=$file
112786df26cacSmrg
112796df26cacSmrg      case $name in
112806df26cacSmrg      *.la)
112816df26cacSmrg	# Possibly a libtool archive, so verify it.
11282b68e1f86Smrg	if func_lalib_p "$file"; then
11283b68e1f86Smrg	  func_source $dir/$name
112846df26cacSmrg
112856df26cacSmrg	  # Delete the libtool libraries and symlinks.
112866df26cacSmrg	  for n in $library_names; do
112873bfa90b6Smrg	    func_append rmfiles " $odir/$n"
112886df26cacSmrg	  done
112893bfa90b6Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
112906df26cacSmrg
1129125dbecb6Smrg	  case $opt_mode in
112926df26cacSmrg	  clean)
112933bfa90b6Smrg	    case " $library_names " in
112946df26cacSmrg	    *" $dlname "*) ;;
112953bfa90b6Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
112966df26cacSmrg	    esac
112973bfa90b6Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
112986df26cacSmrg	    ;;
112996df26cacSmrg	  uninstall)
113006df26cacSmrg	    if test -n "$library_names"; then
113016df26cacSmrg	      # Do each command in the postuninstall commands.
1130225dbecb6Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113036df26cacSmrg	    fi
113046df26cacSmrg
113056df26cacSmrg	    if test -n "$old_library"; then
113066df26cacSmrg	      # Do each command in the old_postuninstall commands.
1130725dbecb6Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
113086df26cacSmrg	    fi
113096df26cacSmrg	    # FIXME: should reinstall the best remaining shared library.
113106df26cacSmrg	    ;;
113116df26cacSmrg	  esac
113126df26cacSmrg	fi
113136df26cacSmrg	;;
113146df26cacSmrg
113156df26cacSmrg      *.lo)
113166df26cacSmrg	# Possibly a libtool object, so verify it.
11317b68e1f86Smrg	if func_lalib_p "$file"; then
113186df26cacSmrg
113196df26cacSmrg	  # Read the .lo file
11320b68e1f86Smrg	  func_source $dir/$name
113216df26cacSmrg
113226df26cacSmrg	  # Add PIC object to the list of files to remove.
1132325dbecb6Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
113243bfa90b6Smrg	    func_append rmfiles " $dir/$pic_object"
113256df26cacSmrg	  fi
113266df26cacSmrg
113276df26cacSmrg	  # Add non-PIC object to the list of files to remove.
1132825dbecb6Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
113293bfa90b6Smrg	    func_append rmfiles " $dir/$non_pic_object"
113306df26cacSmrg	  fi
113316df26cacSmrg	fi
113326df26cacSmrg	;;
113336df26cacSmrg
113346df26cacSmrg      *)
1133525dbecb6Smrg	if test clean = "$opt_mode"; then
113366df26cacSmrg	  noexename=$name
113376df26cacSmrg	  case $file in
113386df26cacSmrg	  *.exe)
11339b68e1f86Smrg	    func_stripname '' '.exe' "$file"
11340b68e1f86Smrg	    file=$func_stripname_result
11341b68e1f86Smrg	    func_stripname '' '.exe' "$name"
11342b68e1f86Smrg	    noexename=$func_stripname_result
113436df26cacSmrg	    # $file with .exe has already been added to rmfiles,
113446df26cacSmrg	    # add $file without .exe
113453bfa90b6Smrg	    func_append rmfiles " $file"
113466df26cacSmrg	    ;;
113476df26cacSmrg	  esac
113486df26cacSmrg	  # Do a test to see if this is a libtool program.
11349b68e1f86Smrg	  if func_ltwrapper_p "$file"; then
11350b68e1f86Smrg	    if func_ltwrapper_executable_p "$file"; then
11351b68e1f86Smrg	      func_ltwrapper_scriptname "$file"
11352b68e1f86Smrg	      relink_command=
11353b68e1f86Smrg	      func_source $func_ltwrapper_scriptname_result
113543bfa90b6Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11355b68e1f86Smrg	    else
11356b68e1f86Smrg	      relink_command=
11357b68e1f86Smrg	      func_source $dir/$noexename
11358b68e1f86Smrg	    fi
113596df26cacSmrg
113606df26cacSmrg	    # note $name still contains .exe if it was in $file originally
113616df26cacSmrg	    # as does the version of $file that was added into $rmfiles
1136225dbecb6Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
1136325dbecb6Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
113643bfa90b6Smrg	      func_append rmfiles " $odir/lt-$name"
113656df26cacSmrg	    fi
1136625dbecb6Smrg	    if test "X$noexename" != "X$name"; then
1136725dbecb6Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
113686df26cacSmrg	    fi
113696df26cacSmrg	  fi
113706df26cacSmrg	fi
113716df26cacSmrg	;;
113726df26cacSmrg      esac
11373b68e1f86Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
113746df26cacSmrg    done
113756df26cacSmrg
1137625dbecb6Smrg    # Try to remove the $objdir's in the directories where we deleted files
113776df26cacSmrg    for dir in $rmdirs; do
113786df26cacSmrg      if test -d "$dir"; then
11379b68e1f86Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
113806df26cacSmrg      fi
113816df26cacSmrg    done
113826df26cacSmrg
113836df26cacSmrg    exit $exit_status
11384b68e1f86Smrg}
113856df26cacSmrg
1138625dbecb6Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
1138725dbecb6Smrg  func_mode_uninstall ${1+"$@"}
1138825dbecb6Smrgfi
113896df26cacSmrg
113903bfa90b6Smrgtest -z "$opt_mode" && {
1139125dbecb6Smrg  help=$generic_help
11392b68e1f86Smrg  func_fatal_help "you must specify a MODE"
11393b68e1f86Smrg}
11394b68e1f86Smrg
11395b68e1f86Smrgtest -z "$exec_cmd" && \
1139625dbecb6Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
113976df26cacSmrg
113986df26cacSmrgif test -n "$exec_cmd"; then
11399b68e1f86Smrg  eval exec "$exec_cmd"
114006df26cacSmrg  exit $EXIT_FAILURE
114016df26cacSmrgfi
114026df26cacSmrg
11403b68e1f86Smrgexit $exit_status
114046df26cacSmrg
114056df26cacSmrg
114066df26cacSmrg# The TAGs below are defined such that we never get into a situation
1140725dbecb6Smrg# where we disable both kinds of libraries.  Given conflicting
114086df26cacSmrg# choices, we go for a static library, that is the most portable,
114096df26cacSmrg# since we can't tell whether shared libraries were disabled because
114106df26cacSmrg# the user asked for that or because the platform doesn't support
114116df26cacSmrg# them.  This is particularly important on AIX, because we don't
114126df26cacSmrg# support having both static and shared libraries enabled at the same
114136df26cacSmrg# time on that platform, so we default to a shared-only configuration.
114146df26cacSmrg# If a disable-shared tag is given, we'll fallback to a static-only
114156df26cacSmrg# configuration.  But we'll never go from static-only to shared-only.
114166df26cacSmrg
114176df26cacSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11418b68e1f86Smrgbuild_libtool_libs=no
11419b68e1f86Smrgbuild_old_libs=yes
114206df26cacSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
114216df26cacSmrg
114226df26cacSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11423b68e1f86Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
114246df26cacSmrg# ### END LIBTOOL TAG CONFIG: disable-static
114256df26cacSmrg
114266df26cacSmrg# Local Variables:
114276df26cacSmrg# mode:shell-script
114286df26cacSmrg# sh-indentation:2
114296df26cacSmrg# End:
11430