166ab3337Smrg#! /usr/bin/env sh
266ab3337Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
366ab3337Smrg##               by inline-source v2019-02-19.15
42a75d1c4Smrg
566ab3337Smrg# libtool (GNU libtool) 2.4.7
666ab3337Smrg# Provide generalized library-building support services.
72a75d1c4Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
82a75d1c4Smrg
966ab3337Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
102a75d1c4Smrg# This is free software; see the source for copying conditions.  There is NO
112a75d1c4Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
122a75d1c4Smrg
132a75d1c4Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14f7ec340bSmacallan# it under the terms of the GNU General Public License as published by
15f7ec340bSmacallan# the Free Software Foundation; either version 2 of the License, or
16f7ec340bSmacallan# (at your option) any later version.
17f7ec340bSmacallan#
182a75d1c4Smrg# As a special exception to the GNU General Public License,
192a75d1c4Smrg# if you distribute this file as part of a program or library that
202a75d1c4Smrg# is built using GNU Libtool, you may include this file under the
212a75d1c4Smrg# same distribution terms that you use for the rest of that program.
222a75d1c4Smrg#
232a75d1c4Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24f7ec340bSmacallan# WITHOUT ANY WARRANTY; without even the implied warranty of
25f7ec340bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26f7ec340bSmacallan# General Public License for more details.
27f7ec340bSmacallan#
28f7ec340bSmacallan# You should have received a copy of the GNU General Public License
2966ab3337Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30f7ec340bSmacallan
3166ab3337Smrg
3266ab3337SmrgPROGRAM=libtool
3366ab3337SmrgPACKAGE=libtool
3466ab3337SmrgVERSION=2.4.7
3566ab3337Smrgpackage_revision=2.4.7
3666ab3337Smrg
3766ab3337Smrg
3866ab3337Smrg## ------ ##
3966ab3337Smrg## Usage. ##
4066ab3337Smrg## ------ ##
4166ab3337Smrg
4266ab3337Smrg# Run './libtool --help' for help with using this script from the
4366ab3337Smrg# command line.
4466ab3337Smrg
4566ab3337Smrg
4666ab3337Smrg## ------------------------------- ##
4766ab3337Smrg## User overridable command paths. ##
4866ab3337Smrg## ------------------------------- ##
4966ab3337Smrg
5066ab3337Smrg# After configure completes, it has a better idea of some of the
5166ab3337Smrg# shell tools we need than the defaults used by the functions shared
5266ab3337Smrg# with bootstrap, so set those here where they can still be over-
5366ab3337Smrg# ridden by the user, but otherwise take precedence.
5466ab3337Smrg
5566ab3337Smrg: ${AUTOCONF="autoconf"}
5666ab3337Smrg: ${AUTOMAKE="automake"}
5766ab3337Smrg
5866ab3337Smrg
5966ab3337Smrg## -------------------------- ##
6066ab3337Smrg## Source external libraries. ##
6166ab3337Smrg## -------------------------- ##
6266ab3337Smrg
6366ab3337Smrg# Much of our low-level functionality needs to be sourced from external
6466ab3337Smrg# libraries, which are installed to $pkgauxdir.
6566ab3337Smrg
6666ab3337Smrg# Set a version string for this script.
6766ab3337Smrgscriptversion=2019-02-19.15; # UTC
6866ab3337Smrg
6966ab3337Smrg# General shell script boiler plate, and helper functions.
7066ab3337Smrg# Written by Gary V. Vaughan, 2004
7166ab3337Smrg
7266ab3337Smrg# This is free software.  There is NO warranty; not even for
7366ab3337Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
742a75d1c4Smrg#
7566ab3337Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
762a75d1c4Smrg#
7766ab3337Smrg# This file is dual licensed under the terms of the MIT license
7866ab3337Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
7966ab3337Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
8066ab3337Smrg# these licenses when using or redistributing this software or any of
8166ab3337Smrg# the files within it.  See the URLs above, or the file `LICENSE`
8266ab3337Smrg# included in the Bootstrap distribution for the full license texts.
8366ab3337Smrg
8466ab3337Smrg# Please report bugs or propose patches to:
8566ab3337Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
8666ab3337Smrg
8766ab3337Smrg
8866ab3337Smrg## ------ ##
8966ab3337Smrg## Usage. ##
9066ab3337Smrg## ------ ##
9166ab3337Smrg
9266ab3337Smrg# Evaluate this file near the top of your script to gain access to
9366ab3337Smrg# the functions and variables defined here:
942a75d1c4Smrg#
9566ab3337Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
962a75d1c4Smrg#
9766ab3337Smrg# If you need to override any of the default environment variable
9866ab3337Smrg# settings, do that before evaluating this file.
99f7ec340bSmacallan
1007ce7e03cSmrg
10166ab3337Smrg## -------------------- ##
10266ab3337Smrg## Shell normalisation. ##
10366ab3337Smrg## -------------------- ##
10466ab3337Smrg
10566ab3337Smrg# Some shells need a little help to be as Bourne compatible as possible.
10666ab3337Smrg# Before doing anything else, make sure all that help has been provided!
10766ab3337Smrg
10866ab3337SmrgDUALCASE=1; export DUALCASE # for MKS sh
10966ab3337Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1107ce7e03cSmrg  emulate sh
1117ce7e03cSmrg  NULLCMD=:
11266ab3337Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1137ce7e03cSmrg  # is contrary to our usage.  Disable this feature.
1147ce7e03cSmrg  alias -g '${1+"$@"}'='"$@"'
115f7ec340bSmacallan  setopt NO_GLOB_SUBST
1167ce7e03cSmrgelse
11766ab3337Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118f7ec340bSmacallanfi
119f7ec340bSmacallan
12066ab3337Smrg# NLS nuisances: We save the old values in case they are required later.
12166ab3337Smrg_G_user_locale=
12266ab3337Smrg_G_safe_locale=
12366ab3337Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1247ce7e03cSmrgdo
12566ab3337Smrg  eval "if test set = \"\${$_G_var+set}\"; then
12666ab3337Smrg          save_$_G_var=\$$_G_var
12766ab3337Smrg          $_G_var=C
12866ab3337Smrg	  export $_G_var
12966ab3337Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
13066ab3337Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1317ce7e03cSmrg	fi"
1327ce7e03cSmrgdone
13366ab3337Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
13466ab3337Smrg# in case the environment reset is needed later and the $save_* variant is not
13566ab3337Smrg# defined (see the code above).
1362a75d1c4SmrgLC_ALL=C
1372a75d1c4SmrgLANGUAGE=C
1382a75d1c4Smrgexport LANGUAGE LC_ALL
1392a75d1c4Smrg
14066ab3337Smrg# Make sure IFS has a sensible default
14166ab3337Smrgsp=' '
14266ab3337Smrgnl='
14366ab3337Smrg'
14466ab3337SmrgIFS="$sp	$nl"
14566ab3337Smrg
14666ab3337Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
14766ab3337Smrgif test "${PATH_SEPARATOR+set}" != set; then
14866ab3337Smrg  PATH_SEPARATOR=:
14966ab3337Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
15066ab3337Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
15166ab3337Smrg      PATH_SEPARATOR=';'
15266ab3337Smrg  }
15366ab3337Smrgfi
1542a75d1c4Smrg
1552a75d1c4Smrg
15666ab3337Smrg# func_unset VAR
15766ab3337Smrg# --------------
15866ab3337Smrg# Portably unset VAR.
15966ab3337Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
16066ab3337Smrg# status if VAR is already unset, which might be problematic if the
16166ab3337Smrg# statement is used at the end of a function (thus poisoning its return
16266ab3337Smrg# value) or when 'set -e' is active (causing even a spurious abort of
16366ab3337Smrg# the script in this case).
16466ab3337Smrgfunc_unset ()
16566ab3337Smrg{
16666ab3337Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
16766ab3337Smrg}
1682a75d1c4Smrg
1692a75d1c4Smrg
17066ab3337Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
17166ab3337Smrgfunc_unset CDPATH
1722a75d1c4Smrg
17366ab3337Smrg# Make sure ${,E,F}GREP behave sanely.
17466ab3337Smrgfunc_unset GREP_OPTIONS
1752a75d1c4Smrg
176f7ec340bSmacallan
17766ab3337Smrg## ------------------------- ##
17866ab3337Smrg## Locate command utilities. ##
17966ab3337Smrg## ------------------------- ##
180f7ec340bSmacallan
181f7ec340bSmacallan
18266ab3337Smrg# func_executable_p FILE
18366ab3337Smrg# ----------------------
18466ab3337Smrg# Check that FILE is an executable regular file.
18566ab3337Smrgfunc_executable_p ()
1862a75d1c4Smrg{
18766ab3337Smrg    test -f "$1" && test -x "$1"
18866ab3337Smrg}
1892a75d1c4Smrg
1902a75d1c4Smrg
19166ab3337Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
19266ab3337Smrg# --------------------------------------------
19366ab3337Smrg# Search for either a program that responds to --version with output
19466ab3337Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
19566ab3337Smrg# trying all the directories in PATH with each of the elements of
19666ab3337Smrg# PROGS_LIST.
19766ab3337Smrg#
19866ab3337Smrg# CHECK_FUNC should accept the path to a candidate program, and
19966ab3337Smrg# set $func_check_prog_result if it truncates its output less than
20066ab3337Smrg# $_G_path_prog_max characters.
20166ab3337Smrgfunc_path_progs ()
2022a75d1c4Smrg{
20366ab3337Smrg    _G_progs_list=$1
20466ab3337Smrg    _G_check_func=$2
20566ab3337Smrg    _G_PATH=${3-"$PATH"}
20666ab3337Smrg
20766ab3337Smrg    _G_path_prog_max=0
20866ab3337Smrg    _G_path_prog_found=false
20966ab3337Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
21066ab3337Smrg    for _G_dir in $_G_PATH; do
21166ab3337Smrg      IFS=$_G_save_IFS
21266ab3337Smrg      test -z "$_G_dir" && _G_dir=.
21366ab3337Smrg      for _G_prog_name in $_G_progs_list; do
21466ab3337Smrg        for _exeext in '' .EXE; do
21566ab3337Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
21666ab3337Smrg          func_executable_p "$_G_path_prog" || continue
21766ab3337Smrg          case `"$_G_path_prog" --version 2>&1` in
21866ab3337Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
21966ab3337Smrg            *)     $_G_check_func $_G_path_prog
22066ab3337Smrg		   func_path_progs_result=$func_check_prog_result
22166ab3337Smrg		   ;;
22266ab3337Smrg          esac
22366ab3337Smrg          $_G_path_prog_found && break 3
22466ab3337Smrg        done
22566ab3337Smrg      done
22666ab3337Smrg    done
22766ab3337Smrg    IFS=$_G_save_IFS
22866ab3337Smrg    test -z "$func_path_progs_result" && {
22966ab3337Smrg      echo "no acceptable sed could be found in \$PATH" >&2
23066ab3337Smrg      exit 1
23166ab3337Smrg    }
23266ab3337Smrg}
2332a75d1c4Smrg
2342a75d1c4Smrg
23566ab3337Smrg# We want to be able to use the functions in this file before configure
23666ab3337Smrg# has figured out where the best binaries are kept, which means we have
23766ab3337Smrg# to search for them ourselves - except when the results are already set
23866ab3337Smrg# where we skip the searches.
2392a75d1c4Smrg
24066ab3337Smrg# Unless the user overrides by setting SED, search the path for either GNU
24166ab3337Smrg# sed, or the sed that truncates its output the least.
24266ab3337Smrgtest -z "$SED" && {
24366ab3337Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
24466ab3337Smrg  for _G_i in 1 2 3 4 5 6 7; do
24566ab3337Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
24666ab3337Smrg  done
24766ab3337Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
24866ab3337Smrg  _G_sed_script=
2492a75d1c4Smrg
25066ab3337Smrg  func_check_prog_sed ()
25166ab3337Smrg  {
25266ab3337Smrg    _G_path_prog=$1
2532a75d1c4Smrg
25466ab3337Smrg    _G_count=0
25566ab3337Smrg    printf 0123456789 >conftest.in
25666ab3337Smrg    while :
25766ab3337Smrg    do
25866ab3337Smrg      cat conftest.in conftest.in >conftest.tmp
25966ab3337Smrg      mv conftest.tmp conftest.in
26066ab3337Smrg      cp conftest.in conftest.nl
26166ab3337Smrg      echo '' >> conftest.nl
26266ab3337Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
26366ab3337Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
26466ab3337Smrg      _G_count=`expr $_G_count + 1`
26566ab3337Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
26666ab3337Smrg        # Best one so far, save it but keep looking for a better one
26766ab3337Smrg        func_check_prog_result=$_G_path_prog
26866ab3337Smrg        _G_path_prog_max=$_G_count
26966ab3337Smrg      fi
27066ab3337Smrg      # 10*(2^10) chars as input seems more than enough
27166ab3337Smrg      test 10 -lt "$_G_count" && break
27266ab3337Smrg    done
27366ab3337Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
27466ab3337Smrg  }
2752a75d1c4Smrg
27666ab3337Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
27766ab3337Smrg  rm -f conftest.sed
27866ab3337Smrg  SED=$func_path_progs_result
27966ab3337Smrg}
2802a75d1c4Smrg
28166ab3337Smrg
28266ab3337Smrg# Unless the user overrides by setting GREP, search the path for either GNU
28366ab3337Smrg# grep, or the grep that truncates its output the least.
28466ab3337Smrgtest -z "$GREP" && {
28566ab3337Smrg  func_check_prog_grep ()
28666ab3337Smrg  {
28766ab3337Smrg    _G_path_prog=$1
28866ab3337Smrg
28966ab3337Smrg    _G_count=0
29066ab3337Smrg    _G_path_prog_max=0
29166ab3337Smrg    printf 0123456789 >conftest.in
29266ab3337Smrg    while :
29366ab3337Smrg    do
29466ab3337Smrg      cat conftest.in conftest.in >conftest.tmp
29566ab3337Smrg      mv conftest.tmp conftest.in
29666ab3337Smrg      cp conftest.in conftest.nl
29766ab3337Smrg      echo 'GREP' >> conftest.nl
29866ab3337Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
29966ab3337Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
30066ab3337Smrg      _G_count=`expr $_G_count + 1`
30166ab3337Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
30266ab3337Smrg        # Best one so far, save it but keep looking for a better one
30366ab3337Smrg        func_check_prog_result=$_G_path_prog
30466ab3337Smrg        _G_path_prog_max=$_G_count
30566ab3337Smrg      fi
30666ab3337Smrg      # 10*(2^10) chars as input seems more than enough
30766ab3337Smrg      test 10 -lt "$_G_count" && break
30866ab3337Smrg    done
30966ab3337Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
31066ab3337Smrg  }
31166ab3337Smrg
31266ab3337Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
31366ab3337Smrg  GREP=$func_path_progs_result
31466ab3337Smrg}
31566ab3337Smrg
31666ab3337Smrg
31766ab3337Smrg## ------------------------------- ##
31866ab3337Smrg## User overridable command paths. ##
31966ab3337Smrg## ------------------------------- ##
32066ab3337Smrg
32166ab3337Smrg# All uppercase variable names are used for environment variables.  These
32266ab3337Smrg# variables can be overridden by the user before calling a script that
32366ab3337Smrg# uses them if a suitable command of that name is not already available
32466ab3337Smrg# in the command search PATH.
32566ab3337Smrg
32666ab3337Smrg: ${CP="cp -f"}
32766ab3337Smrg: ${ECHO="printf %s\n"}
32866ab3337Smrg: ${EGREP="$GREP -E"}
32966ab3337Smrg: ${FGREP="$GREP -F"}
33066ab3337Smrg: ${LN_S="ln -s"}
33166ab3337Smrg: ${MAKE="make"}
33266ab3337Smrg: ${MKDIR="mkdir"}
33366ab3337Smrg: ${MV="mv -f"}
33466ab3337Smrg: ${RM="rm -f"}
33566ab3337Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
33666ab3337Smrg
33766ab3337Smrg
33866ab3337Smrg## -------------------- ##
33966ab3337Smrg## Useful sed snippets. ##
34066ab3337Smrg## -------------------- ##
34166ab3337Smrg
34266ab3337Smrgsed_dirname='s|/[^/]*$||'
34366ab3337Smrgsed_basename='s|^.*/||'
34466ab3337Smrg
34566ab3337Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
34666ab3337Smrg# metacharacters that are still active within double-quoted strings.
34766ab3337Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
34866ab3337Smrg
34966ab3337Smrg# Same as above, but do not quote variable references.
35066ab3337Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
35166ab3337Smrg
35266ab3337Smrg# Sed substitution that turns a string into a regex matching for the
35366ab3337Smrg# string literally.
35466ab3337Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
35566ab3337Smrg
35666ab3337Smrg# Sed substitution that converts a w32 file name or path
35766ab3337Smrg# that contains forward slashes, into one that contains
35866ab3337Smrg# (escaped) backslashes.  A very naive implementation.
35966ab3337Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
36066ab3337Smrg
36166ab3337Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
36266ab3337Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
36366ab3337Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
36466ab3337Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
36566ab3337Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
36666ab3337Smrg_G_bs='\\'
36766ab3337Smrg_G_bs2='\\\\'
36866ab3337Smrg_G_bs4='\\\\\\\\'
36966ab3337Smrg_G_dollar='\$'
37066ab3337Smrgsed_double_backslash="\
37166ab3337Smrg  s/$_G_bs4/&\\
37266ab3337Smrg/g
37366ab3337Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
37466ab3337Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
37566ab3337Smrg  s/\n//g"
37666ab3337Smrg
37766ab3337Smrg# require_check_ifs_backslash
37866ab3337Smrg# ---------------------------
37966ab3337Smrg# Check if we can use backslash as IFS='\' separator, and set
38066ab3337Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
38166ab3337Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
38266ab3337Smrgfunc_require_check_ifs_backslash ()
3832a75d1c4Smrg{
38466ab3337Smrg  _G_save_IFS=$IFS
38566ab3337Smrg  IFS='\'
38666ab3337Smrg  _G_check_ifs_backshlash='a\\b'
38766ab3337Smrg  for _G_i in $_G_check_ifs_backshlash
38866ab3337Smrg  do
38966ab3337Smrg  case $_G_i in
39066ab3337Smrg  a)
39166ab3337Smrg    check_ifs_backshlash_broken=false
3922a75d1c4Smrg    ;;
39366ab3337Smrg  '')
39466ab3337Smrg    break
3952a75d1c4Smrg    ;;
39666ab3337Smrg  *)
39766ab3337Smrg    check_ifs_backshlash_broken=:
39866ab3337Smrg    break
3992a75d1c4Smrg    ;;
4002a75d1c4Smrg  esac
4012a75d1c4Smrg  done
40266ab3337Smrg  IFS=$_G_save_IFS
40366ab3337Smrg  require_check_ifs_backslash=:
4042a75d1c4Smrg}
4052a75d1c4Smrg
4062a75d1c4Smrg
40766ab3337Smrg## ----------------- ##
40866ab3337Smrg## Global variables. ##
40966ab3337Smrg## ----------------- ##
4102a75d1c4Smrg
41166ab3337Smrg# Except for the global variables explicitly listed below, the following
41266ab3337Smrg# functions in the '^func_' namespace, and the '^require_' namespace
41366ab3337Smrg# variables initialised in the 'Resource management' section, sourcing
41466ab3337Smrg# this file will not pollute your global namespace with anything
41566ab3337Smrg# else. There's no portable way to scope variables in Bourne shell
41666ab3337Smrg# though, so actually running these functions will sometimes place
41766ab3337Smrg# results into a variable named after the function, and often use
41866ab3337Smrg# temporary variables in the '^_G_' namespace. If you are careful to
41966ab3337Smrg# avoid using those namespaces casually in your sourcing script, things
42066ab3337Smrg# should continue to work as you expect. And, of course, you can freely
42166ab3337Smrg# overwrite any of the functions or variables defined here before
42266ab3337Smrg# calling anything to customize them.
42366ab3337Smrg
42466ab3337SmrgEXIT_SUCCESS=0
42566ab3337SmrgEXIT_FAILURE=1
42666ab3337SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
42766ab3337SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
42866ab3337Smrg
42966ab3337Smrg# Allow overriding, eg assuming that you follow the convention of
43066ab3337Smrg# putting '$debug_cmd' at the start of all your functions, you can get
43166ab3337Smrg# bash to show function call trace with:
43266ab3337Smrg#
43366ab3337Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
43466ab3337Smrgdebug_cmd=${debug_cmd-":"}
43566ab3337Smrgexit_cmd=:
43666ab3337Smrg
43766ab3337Smrg# By convention, finish your script with:
43866ab3337Smrg#
43966ab3337Smrg#    exit $exit_status
44066ab3337Smrg#
44166ab3337Smrg# so that you can set exit_status to non-zero if you want to indicate
44266ab3337Smrg# something went wrong during execution without actually bailing out at
44366ab3337Smrg# the point of failure.
44466ab3337Smrgexit_status=$EXIT_SUCCESS
44566ab3337Smrg
44666ab3337Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
44766ab3337Smrg# is ksh but when the shell is invoked as "sh" and the current value of
44866ab3337Smrg# the _XPG environment variable is not equal to 1 (one), the special
44966ab3337Smrg# positional parameter $0, within a function call, is the name of the
45066ab3337Smrg# function.
45166ab3337Smrgprogpath=$0
4522a75d1c4Smrg
45366ab3337Smrg# The name of this program.
45466ab3337Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4552a75d1c4Smrg
45666ab3337Smrg# Make sure we have an absolute progpath for reexecution:
4572a75d1c4Smrgcase $progpath in
4582a75d1c4Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4592a75d1c4Smrg  *[\\/]*)
46066ab3337Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4612a75d1c4Smrg     progdir=`cd "$progdir" && pwd`
46266ab3337Smrg     progpath=$progdir/$progname
4632a75d1c4Smrg     ;;
4642a75d1c4Smrg  *)
46566ab3337Smrg     _G_IFS=$IFS
46666ab3337Smrg     IFS=${PATH_SEPARATOR-:}
4672a75d1c4Smrg     for progdir in $PATH; do
46866ab3337Smrg       IFS=$_G_IFS
4692a75d1c4Smrg       test -x "$progdir/$progname" && break
4702a75d1c4Smrg     done
47166ab3337Smrg     IFS=$_G_IFS
4722a75d1c4Smrg     test -n "$progdir" || progdir=`pwd`
47366ab3337Smrg     progpath=$progdir/$progname
4742a75d1c4Smrg     ;;
4752a75d1c4Smrgesac
4762a75d1c4Smrg
4772a75d1c4Smrg
47866ab3337Smrg## ----------------- ##
47966ab3337Smrg## Standard options. ##
48066ab3337Smrg## ----------------- ##
4812a75d1c4Smrg
48266ab3337Smrg# The following options affect the operation of the functions defined
48366ab3337Smrg# below, and should be set appropriately depending on run-time para-
48466ab3337Smrg# meters passed on the command line.
4852a75d1c4Smrg
4862a75d1c4Smrgopt_dry_run=false
4872a75d1c4Smrgopt_quiet=false
4882a75d1c4Smrgopt_verbose=false
4892a75d1c4Smrg
49066ab3337Smrg# Categories 'all' and 'none' are always available.  Append any others
49166ab3337Smrg# you will pass as the first argument to func_warning from your own
49266ab3337Smrg# code.
49366ab3337Smrgwarning_categories=
4942a75d1c4Smrg
49566ab3337Smrg# By default, display warnings according to 'opt_warning_types'.  Set
49666ab3337Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
49766ab3337Smrg# treat the next displayed warning as a fatal error.
49866ab3337Smrgwarning_func=func_warn_and_continue
4992a75d1c4Smrg
50066ab3337Smrg# Set to 'all' to display all warnings, 'none' to suppress all
50166ab3337Smrg# warnings, or a space delimited list of some subset of
50266ab3337Smrg# 'warning_categories' to display only the listed warnings.
50366ab3337Smrgopt_warning_types=all
5042a75d1c4Smrg
5052a75d1c4Smrg
50666ab3337Smrg## -------------------- ##
50766ab3337Smrg## Resource management. ##
50866ab3337Smrg## -------------------- ##
5092a75d1c4Smrg
51066ab3337Smrg# This section contains definitions for functions that each ensure a
51166ab3337Smrg# particular resource (a file, or a non-empty configuration variable for
51266ab3337Smrg# example) is available, and if appropriate to extract default values
51366ab3337Smrg# from pertinent package files. Call them using their associated
51466ab3337Smrg# 'require_*' variable to ensure that they are executed, at most, once.
51566ab3337Smrg#
51666ab3337Smrg# It's entirely deliberate that calling these functions can set
51766ab3337Smrg# variables that don't obey the namespace limitations obeyed by the rest
51866ab3337Smrg# of this file, in order that that they be as useful as possible to
51966ab3337Smrg# callers.
5202a75d1c4Smrg
5212a75d1c4Smrg
52266ab3337Smrg# require_term_colors
52366ab3337Smrg# -------------------
52466ab3337Smrg# Allow display of bold text on terminals that support it.
52566ab3337Smrgrequire_term_colors=func_require_term_colors
52666ab3337Smrgfunc_require_term_colors ()
5272a75d1c4Smrg{
52866ab3337Smrg    $debug_cmd
52966ab3337Smrg
53066ab3337Smrg    test -t 1 && {
53166ab3337Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
53266ab3337Smrg      # precedence, because most terminfo databases neglect to describe
53366ab3337Smrg      # whether color sequences are supported.
53466ab3337Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
53566ab3337Smrg
53666ab3337Smrg      if test 1 = "$USE_ANSI_COLORS"; then
53766ab3337Smrg        # Standard ANSI escape sequences
53866ab3337Smrg        tc_reset='[0m'
53966ab3337Smrg        tc_bold='[1m';   tc_standout='[7m'
54066ab3337Smrg        tc_red='[31m';   tc_green='[32m'
54166ab3337Smrg        tc_blue='[34m';  tc_cyan='[36m'
54266ab3337Smrg      else
54366ab3337Smrg        # Otherwise trust the terminfo database after all.
54466ab3337Smrg        test -n "`tput sgr0 2>/dev/null`" && {
54566ab3337Smrg          tc_reset=`tput sgr0`
54666ab3337Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
54766ab3337Smrg          tc_standout=$tc_bold
54866ab3337Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
54966ab3337Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
55066ab3337Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
55166ab3337Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
55266ab3337Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
55366ab3337Smrg        }
55466ab3337Smrg      fi
55566ab3337Smrg    }
5562a75d1c4Smrg
55766ab3337Smrg    require_term_colors=:
5582a75d1c4Smrg}
5592a75d1c4Smrg
5602a75d1c4Smrg
56166ab3337Smrg## ----------------- ##
56266ab3337Smrg## Function library. ##
56366ab3337Smrg## ----------------- ##
5642a75d1c4Smrg
56566ab3337Smrg# This section contains a variety of useful functions to call in your
56666ab3337Smrg# scripts. Take note of the portable wrappers for features provided by
56766ab3337Smrg# some modern shells, which will fall back to slower equivalents on
56866ab3337Smrg# less featureful shells.
5692a75d1c4Smrg
57066ab3337Smrg
57166ab3337Smrg# func_append VAR VALUE
57266ab3337Smrg# ---------------------
57366ab3337Smrg# Append VALUE onto the existing contents of VAR.
57466ab3337Smrg
57566ab3337Smrg  # We should try to minimise forks, especially on Windows where they are
57666ab3337Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
57766ab3337Smrg  # being used:
57866ab3337Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
57966ab3337Smrg    : ${_G_HAVE_ARITH_OP="yes"}
58066ab3337Smrg    : ${_G_HAVE_XSI_OPS="yes"}
58166ab3337Smrg    # The += operator was introduced in bash 3.1
58266ab3337Smrg    case $BASH_VERSION in
58366ab3337Smrg      [12].* | 3.0 | 3.0*) ;;
58466ab3337Smrg      *)
58566ab3337Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
58666ab3337Smrg        ;;
58766ab3337Smrg    esac
58866ab3337Smrg  fi
58966ab3337Smrg
59066ab3337Smrg  # _G_HAVE_PLUSEQ_OP
59166ab3337Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
59266ab3337Smrg  # useable or anything else if it does not work.
59366ab3337Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
59466ab3337Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
59566ab3337Smrg    && _G_HAVE_PLUSEQ_OP=yes
59666ab3337Smrg
59766ab3337Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
59866ab3337Smrgthen
59966ab3337Smrg  # This is an XSI compatible shell, allowing a faster implementation...
60066ab3337Smrg  eval 'func_append ()
60166ab3337Smrg  {
60266ab3337Smrg    $debug_cmd
60366ab3337Smrg
60466ab3337Smrg    eval "$1+=\$2"
60566ab3337Smrg  }'
60666ab3337Smrgelse
60766ab3337Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
60866ab3337Smrg  func_append ()
60966ab3337Smrg  {
61066ab3337Smrg    $debug_cmd
61166ab3337Smrg
61266ab3337Smrg    eval "$1=\$$1\$2"
61366ab3337Smrg  }
61466ab3337Smrgfi
61566ab3337Smrg
61666ab3337Smrg
61766ab3337Smrg# func_append_quoted VAR VALUE
61866ab3337Smrg# ----------------------------
61966ab3337Smrg# Quote VALUE and append to the end of shell variable VAR, separated
62066ab3337Smrg# by a space.
62166ab3337Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
62266ab3337Smrg  eval 'func_append_quoted ()
62366ab3337Smrg  {
62466ab3337Smrg    $debug_cmd
62566ab3337Smrg
62666ab3337Smrg    func_quote_arg pretty "$2"
62766ab3337Smrg    eval "$1+=\\ \$func_quote_arg_result"
62866ab3337Smrg  }'
62966ab3337Smrgelse
63066ab3337Smrg  func_append_quoted ()
63166ab3337Smrg  {
63266ab3337Smrg    $debug_cmd
63366ab3337Smrg
63466ab3337Smrg    func_quote_arg pretty "$2"
63566ab3337Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
63666ab3337Smrg  }
63766ab3337Smrgfi
63866ab3337Smrg
63966ab3337Smrg
64066ab3337Smrg# func_append_uniq VAR VALUE
64166ab3337Smrg# --------------------------
64266ab3337Smrg# Append unique VALUE onto the existing contents of VAR, assuming
64366ab3337Smrg# entries are delimited by the first character of VALUE.  For example:
64466ab3337Smrg#
64566ab3337Smrg#   func_append_uniq options " --another-option option-argument"
64666ab3337Smrg#
64766ab3337Smrg# will only append to $options if " --another-option option-argument "
64866ab3337Smrg# is not already present somewhere in $options already (note spaces at
64966ab3337Smrg# each end implied by leading space in second argument).
65066ab3337Smrgfunc_append_uniq ()
65166ab3337Smrg{
65266ab3337Smrg    $debug_cmd
65366ab3337Smrg
65466ab3337Smrg    eval _G_current_value='`$ECHO $'$1'`'
65566ab3337Smrg    _G_delim=`expr "$2" : '\(.\)'`
65666ab3337Smrg
65766ab3337Smrg    case $_G_delim$_G_current_value$_G_delim in
65866ab3337Smrg      *"$2$_G_delim"*) ;;
65966ab3337Smrg      *) func_append "$@" ;;
66066ab3337Smrg    esac
66166ab3337Smrg}
66266ab3337Smrg
66366ab3337Smrg
66466ab3337Smrg# func_arith TERM...
66566ab3337Smrg# ------------------
66666ab3337Smrg# Set func_arith_result to the result of evaluating TERMs.
66766ab3337Smrg  test -z "$_G_HAVE_ARITH_OP" \
66866ab3337Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
66966ab3337Smrg    && _G_HAVE_ARITH_OP=yes
67066ab3337Smrg
67166ab3337Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
67266ab3337Smrg  eval 'func_arith ()
67366ab3337Smrg  {
67466ab3337Smrg    $debug_cmd
67566ab3337Smrg
67666ab3337Smrg    func_arith_result=$(( $* ))
67766ab3337Smrg  }'
67866ab3337Smrgelse
67966ab3337Smrg  func_arith ()
68066ab3337Smrg  {
68166ab3337Smrg    $debug_cmd
68266ab3337Smrg
68366ab3337Smrg    func_arith_result=`expr "$@"`
68466ab3337Smrg  }
68566ab3337Smrgfi
68666ab3337Smrg
68766ab3337Smrg
68866ab3337Smrg# func_basename FILE
68966ab3337Smrg# ------------------
69066ab3337Smrg# Set func_basename_result to FILE with everything up to and including
69166ab3337Smrg# the last / stripped.
69266ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
69366ab3337Smrg  # If this shell supports suffix pattern removal, then use it to avoid
69466ab3337Smrg  # forking. Hide the definitions single quotes in case the shell chokes
69566ab3337Smrg  # on unsupported syntax...
69666ab3337Smrg  _b='func_basename_result=${1##*/}'
69766ab3337Smrg  _d='case $1 in
69866ab3337Smrg        */*) func_dirname_result=${1%/*}$2 ;;
69966ab3337Smrg        *  ) func_dirname_result=$3        ;;
70066ab3337Smrg      esac'
70166ab3337Smrg
70266ab3337Smrgelse
70366ab3337Smrg  # ...otherwise fall back to using sed.
70466ab3337Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
70566ab3337Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
70666ab3337Smrg      if test "X$func_dirname_result" = "X$1"; then
70766ab3337Smrg        func_dirname_result=$3
70866ab3337Smrg      else
70966ab3337Smrg        func_append func_dirname_result "$2"
71066ab3337Smrg      fi'
71166ab3337Smrgfi
71266ab3337Smrg
71366ab3337Smrgeval 'func_basename ()
71466ab3337Smrg{
71566ab3337Smrg    $debug_cmd
71666ab3337Smrg
71766ab3337Smrg    '"$_b"'
71866ab3337Smrg}'
71966ab3337Smrg
72066ab3337Smrg
72166ab3337Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
72266ab3337Smrg# -------------------------------------------
72366ab3337Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
72466ab3337Smrg# otherwise set result to NONDIR_REPLACEMENT.
72566ab3337Smrgeval 'func_dirname ()
72666ab3337Smrg{
72766ab3337Smrg    $debug_cmd
72866ab3337Smrg
72966ab3337Smrg    '"$_d"'
73066ab3337Smrg}'
73166ab3337Smrg
73266ab3337Smrg
73366ab3337Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
73466ab3337Smrg# --------------------------------------------------------
73566ab3337Smrg# Perform func_basename and func_dirname in a single function
73666ab3337Smrg# call:
73766ab3337Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
73866ab3337Smrg#             add APPEND to the result, otherwise set result
73966ab3337Smrg#             to NONDIR_REPLACEMENT.
74066ab3337Smrg#             value returned in "$func_dirname_result"
74166ab3337Smrg#   basename: Compute filename of FILE.
74266ab3337Smrg#             value retuned in "$func_basename_result"
74366ab3337Smrg# For efficiency, we do not delegate to the functions above but instead
74466ab3337Smrg# duplicate the functionality here.
74566ab3337Smrgeval 'func_dirname_and_basename ()
74666ab3337Smrg{
74766ab3337Smrg    $debug_cmd
74866ab3337Smrg
74966ab3337Smrg    '"$_b"'
75066ab3337Smrg    '"$_d"'
75166ab3337Smrg}'
75266ab3337Smrg
75366ab3337Smrg
75466ab3337Smrg# func_echo ARG...
75566ab3337Smrg# ----------------
75666ab3337Smrg# Echo program name prefixed message.
75766ab3337Smrgfunc_echo ()
75866ab3337Smrg{
75966ab3337Smrg    $debug_cmd
76066ab3337Smrg
76166ab3337Smrg    _G_message=$*
76266ab3337Smrg
76366ab3337Smrg    func_echo_IFS=$IFS
76466ab3337Smrg    IFS=$nl
76566ab3337Smrg    for _G_line in $_G_message; do
76666ab3337Smrg      IFS=$func_echo_IFS
76766ab3337Smrg      $ECHO "$progname: $_G_line"
76866ab3337Smrg    done
76966ab3337Smrg    IFS=$func_echo_IFS
77066ab3337Smrg}
77166ab3337Smrg
77266ab3337Smrg
77366ab3337Smrg# func_echo_all ARG...
77466ab3337Smrg# --------------------
77566ab3337Smrg# Invoke $ECHO with all args, space-separated.
77666ab3337Smrgfunc_echo_all ()
77766ab3337Smrg{
77866ab3337Smrg    $ECHO "$*"
77966ab3337Smrg}
78066ab3337Smrg
78166ab3337Smrg
78266ab3337Smrg# func_echo_infix_1 INFIX ARG...
78366ab3337Smrg# ------------------------------
78466ab3337Smrg# Echo program name, followed by INFIX on the first line, with any
78566ab3337Smrg# additional lines not showing INFIX.
78666ab3337Smrgfunc_echo_infix_1 ()
78766ab3337Smrg{
78866ab3337Smrg    $debug_cmd
78966ab3337Smrg
79066ab3337Smrg    $require_term_colors
79166ab3337Smrg
79266ab3337Smrg    _G_infix=$1; shift
79366ab3337Smrg    _G_indent=$_G_infix
79466ab3337Smrg    _G_prefix="$progname: $_G_infix: "
79566ab3337Smrg    _G_message=$*
79666ab3337Smrg
79766ab3337Smrg    # Strip color escape sequences before counting printable length
79866ab3337Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
79966ab3337Smrg    do
80066ab3337Smrg      test -n "$_G_tc" && {
80166ab3337Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
80266ab3337Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
80366ab3337Smrg      }
80466ab3337Smrg    done
80566ab3337Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
80666ab3337Smrg
80766ab3337Smrg    func_echo_infix_1_IFS=$IFS
80866ab3337Smrg    IFS=$nl
80966ab3337Smrg    for _G_line in $_G_message; do
81066ab3337Smrg      IFS=$func_echo_infix_1_IFS
81166ab3337Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
81266ab3337Smrg      _G_prefix=$_G_indent
81366ab3337Smrg    done
81466ab3337Smrg    IFS=$func_echo_infix_1_IFS
81566ab3337Smrg}
81666ab3337Smrg
81766ab3337Smrg
81866ab3337Smrg# func_error ARG...
81966ab3337Smrg# -----------------
82066ab3337Smrg# Echo program name prefixed message to standard error.
82166ab3337Smrgfunc_error ()
82266ab3337Smrg{
82366ab3337Smrg    $debug_cmd
82466ab3337Smrg
82566ab3337Smrg    $require_term_colors
82666ab3337Smrg
82766ab3337Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
82866ab3337Smrg}
82966ab3337Smrg
83066ab3337Smrg
83166ab3337Smrg# func_fatal_error ARG...
83266ab3337Smrg# -----------------------
83366ab3337Smrg# Echo program name prefixed message to standard error, and exit.
83466ab3337Smrgfunc_fatal_error ()
83566ab3337Smrg{
83666ab3337Smrg    $debug_cmd
83766ab3337Smrg
83866ab3337Smrg    func_error "$*"
83966ab3337Smrg    exit $EXIT_FAILURE
84066ab3337Smrg}
84166ab3337Smrg
84266ab3337Smrg
84366ab3337Smrg# func_grep EXPRESSION FILENAME
84466ab3337Smrg# -----------------------------
84566ab3337Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
84666ab3337Smrgfunc_grep ()
84766ab3337Smrg{
84866ab3337Smrg    $debug_cmd
84966ab3337Smrg
85066ab3337Smrg    $GREP "$1" "$2" >/dev/null 2>&1
85166ab3337Smrg}
85266ab3337Smrg
85366ab3337Smrg
85466ab3337Smrg# func_len STRING
85566ab3337Smrg# ---------------
85666ab3337Smrg# Set func_len_result to the length of STRING. STRING may not
85766ab3337Smrg# start with a hyphen.
85866ab3337Smrg  test -z "$_G_HAVE_XSI_OPS" \
85966ab3337Smrg    && (eval 'x=a/b/c;
86066ab3337Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
86166ab3337Smrg    && _G_HAVE_XSI_OPS=yes
86266ab3337Smrg
86366ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
86466ab3337Smrg  eval 'func_len ()
86566ab3337Smrg  {
86666ab3337Smrg    $debug_cmd
86766ab3337Smrg
86866ab3337Smrg    func_len_result=${#1}
86966ab3337Smrg  }'
87066ab3337Smrgelse
87166ab3337Smrg  func_len ()
87266ab3337Smrg  {
87366ab3337Smrg    $debug_cmd
87466ab3337Smrg
87566ab3337Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
87666ab3337Smrg  }
87766ab3337Smrgfi
87866ab3337Smrg
87966ab3337Smrg
88066ab3337Smrg# func_mkdir_p DIRECTORY-PATH
88166ab3337Smrg# ---------------------------
8822a75d1c4Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8832a75d1c4Smrgfunc_mkdir_p ()
8842a75d1c4Smrg{
88566ab3337Smrg    $debug_cmd
8862a75d1c4Smrg
88766ab3337Smrg    _G_directory_path=$1
88866ab3337Smrg    _G_dir_list=
8892a75d1c4Smrg
89066ab3337Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
89166ab3337Smrg
89266ab3337Smrg      # Protect directory names starting with '-'
89366ab3337Smrg      case $_G_directory_path in
89466ab3337Smrg        -*) _G_directory_path=./$_G_directory_path ;;
8952a75d1c4Smrg      esac
8962a75d1c4Smrg
8972a75d1c4Smrg      # While some portion of DIR does not yet exist...
89866ab3337Smrg      while test ! -d "$_G_directory_path"; do
8992a75d1c4Smrg        # ...make a list in topmost first order.  Use a colon delimited
9002a75d1c4Smrg	# list incase some portion of path contains whitespace.
90166ab3337Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
9022a75d1c4Smrg
9032a75d1c4Smrg        # If the last portion added has no slash in it, the list is done
90466ab3337Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
9052a75d1c4Smrg
9062a75d1c4Smrg        # ...otherwise throw away the child directory and loop
90766ab3337Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
9082a75d1c4Smrg      done
90966ab3337Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
9102a75d1c4Smrg
91166ab3337Smrg      func_mkdir_p_IFS=$IFS; IFS=:
91266ab3337Smrg      for _G_dir in $_G_dir_list; do
91366ab3337Smrg	IFS=$func_mkdir_p_IFS
91466ab3337Smrg        # mkdir can fail with a 'File exist' error if two processes
9152a75d1c4Smrg        # try to create one of the directories concurrently.  Don't
9162a75d1c4Smrg        # stop in that case!
91766ab3337Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
9182a75d1c4Smrg      done
91966ab3337Smrg      IFS=$func_mkdir_p_IFS
9202a75d1c4Smrg
9212a75d1c4Smrg      # Bail out if we (or some other process) failed to create a directory.
92266ab3337Smrg      test -d "$_G_directory_path" || \
92366ab3337Smrg        func_fatal_error "Failed to create '$1'"
9242a75d1c4Smrg    fi
9252a75d1c4Smrg}
926f7ec340bSmacallan
927f7ec340bSmacallan
92866ab3337Smrg# func_mktempdir [BASENAME]
92966ab3337Smrg# -------------------------
930f7ec340bSmacallan# Make a temporary directory that won't clash with other running
931f7ec340bSmacallan# libtool processes, and avoids race conditions if possible.  If
93266ab3337Smrg# given, BASENAME is the basename for that directory.
933f7ec340bSmacallanfunc_mktempdir ()
934f7ec340bSmacallan{
93566ab3337Smrg    $debug_cmd
93666ab3337Smrg
93766ab3337Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938f7ec340bSmacallan
93966ab3337Smrg    if test : = "$opt_dry_run"; then
940f7ec340bSmacallan      # Return a directory name, but don't create it in dry-run mode
94166ab3337Smrg      _G_tmpdir=$_G_template-$$
942f7ec340bSmacallan    else
943f7ec340bSmacallan
944f7ec340bSmacallan      # If mktemp works, use that first and foremost
94566ab3337Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946f7ec340bSmacallan
94766ab3337Smrg      if test ! -d "$_G_tmpdir"; then
9482a75d1c4Smrg        # Failing that, at least try and use $RANDOM to avoid a race
94966ab3337Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950f7ec340bSmacallan
95166ab3337Smrg        func_mktempdir_umask=`umask`
9522a75d1c4Smrg        umask 0077
95366ab3337Smrg        $MKDIR "$_G_tmpdir"
95466ab3337Smrg        umask $func_mktempdir_umask
955f7ec340bSmacallan      fi
956f7ec340bSmacallan
957f7ec340bSmacallan      # If we're not in dry-run mode, bomb out on failure
95866ab3337Smrg      test -d "$_G_tmpdir" || \
95966ab3337Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960f7ec340bSmacallan    fi
961f7ec340bSmacallan
96266ab3337Smrg    $ECHO "$_G_tmpdir"
963f7ec340bSmacallan}
964f7ec340bSmacallan
965f7ec340bSmacallan
96666ab3337Smrg# func_normal_abspath PATH
96766ab3337Smrg# ------------------------
96866ab3337Smrg# Remove doubled-up and trailing slashes, "." path components,
96966ab3337Smrg# and cancel out any ".." path components in PATH after making
97066ab3337Smrg# it an absolute path.
97166ab3337Smrgfunc_normal_abspath ()
972f7ec340bSmacallan{
97366ab3337Smrg    $debug_cmd
97466ab3337Smrg
97566ab3337Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
97666ab3337Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
97766ab3337Smrg    _G_pathcdr='s|^/[^/]*||'
97866ab3337Smrg    _G_removedotparts=':dotsl
97966ab3337Smrg		s|/\./|/|g
98066ab3337Smrg		t dotsl
98166ab3337Smrg		s|/\.$|/|'
98266ab3337Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
98366ab3337Smrg    _G_finalslash='s|/*$|/|'
98466ab3337Smrg
98566ab3337Smrg    # Start from root dir and reassemble the path.
98666ab3337Smrg    func_normal_abspath_result=
98766ab3337Smrg    func_normal_abspath_tpath=$1
98866ab3337Smrg    func_normal_abspath_altnamespace=
98966ab3337Smrg    case $func_normal_abspath_tpath in
99066ab3337Smrg      "")
99166ab3337Smrg        # Empty path, that just means $cwd.
99266ab3337Smrg        func_stripname '' '/' "`pwd`"
99366ab3337Smrg        func_normal_abspath_result=$func_stripname_result
99466ab3337Smrg        return
99566ab3337Smrg        ;;
99666ab3337Smrg      # The next three entries are used to spot a run of precisely
99766ab3337Smrg      # two leading slashes without using negated character classes;
99866ab3337Smrg      # we take advantage of case's first-match behaviour.
99966ab3337Smrg      ///*)
100066ab3337Smrg        # Unusual form of absolute path, do nothing.
100166ab3337Smrg        ;;
100266ab3337Smrg      //*)
100366ab3337Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
100466ab3337Smrg        # and for example Cygwin uses it to access remote file shares
100566ab3337Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
100666ab3337Smrg        func_normal_abspath_altnamespace=/
100766ab3337Smrg        ;;
100866ab3337Smrg      /*)
100966ab3337Smrg        # Absolute path, do nothing.
101066ab3337Smrg        ;;
10112a75d1c4Smrg      *)
101266ab3337Smrg        # Relative path, prepend $cwd.
101366ab3337Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
101466ab3337Smrg        ;;
10152a75d1c4Smrg    esac
10162a75d1c4Smrg
101766ab3337Smrg    # Cancel out all the simple stuff to save iterations.  We also want
101866ab3337Smrg    # the path to end with a slash for ease of parsing, so make sure
101966ab3337Smrg    # there is one (and only one) here.
102066ab3337Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
102166ab3337Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
102266ab3337Smrg    while :; do
102366ab3337Smrg      # Processed it all yet?
102466ab3337Smrg      if test / = "$func_normal_abspath_tpath"; then
102566ab3337Smrg        # If we ascended to the root using ".." the result may be empty now.
102666ab3337Smrg        if test -z "$func_normal_abspath_result"; then
102766ab3337Smrg          func_normal_abspath_result=/
102866ab3337Smrg        fi
102966ab3337Smrg        break
103066ab3337Smrg      fi
103166ab3337Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
103266ab3337Smrg          -e "$_G_pathcar"`
103366ab3337Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
103466ab3337Smrg          -e "$_G_pathcdr"`
103566ab3337Smrg      # Figure out what to do with it
103666ab3337Smrg      case $func_normal_abspath_tcomponent in
103766ab3337Smrg        "")
103866ab3337Smrg          # Trailing empty path component, ignore it.
103966ab3337Smrg          ;;
104066ab3337Smrg        ..)
104166ab3337Smrg          # Parent dir; strip last assembled component from result.
104266ab3337Smrg          func_dirname "$func_normal_abspath_result"
104366ab3337Smrg          func_normal_abspath_result=$func_dirname_result
104466ab3337Smrg          ;;
104566ab3337Smrg        *)
104666ab3337Smrg          # Actual path component, append it.
104766ab3337Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
104866ab3337Smrg          ;;
104966ab3337Smrg      esac
105066ab3337Smrg    done
105166ab3337Smrg    # Restore leading double-slash if one was found on entry.
105266ab3337Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
105366ab3337Smrg}
105466ab3337Smrg
105566ab3337Smrg
105666ab3337Smrg# func_notquiet ARG...
105766ab3337Smrg# --------------------
105866ab3337Smrg# Echo program name prefixed message only when not in quiet mode.
105966ab3337Smrgfunc_notquiet ()
106066ab3337Smrg{
106166ab3337Smrg    $debug_cmd
106266ab3337Smrg
106366ab3337Smrg    $opt_quiet || func_echo ${1+"$@"}
106466ab3337Smrg
106566ab3337Smrg    # A bug in bash halts the script if the last line of a function
106666ab3337Smrg    # fails when set -e is in force, so we need another command to
106766ab3337Smrg    # work around that:
106866ab3337Smrg    :
106966ab3337Smrg}
107066ab3337Smrg
107166ab3337Smrg
107266ab3337Smrg# func_relative_path SRCDIR DSTDIR
107366ab3337Smrg# --------------------------------
107466ab3337Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
107566ab3337Smrgfunc_relative_path ()
107666ab3337Smrg{
107766ab3337Smrg    $debug_cmd
107866ab3337Smrg
107966ab3337Smrg    func_relative_path_result=
108066ab3337Smrg    func_normal_abspath "$1"
108166ab3337Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
108266ab3337Smrg    func_normal_abspath "$2"
108366ab3337Smrg    func_relative_path_tbindir=$func_normal_abspath_result
108466ab3337Smrg
108566ab3337Smrg    # Ascend the tree starting from libdir
108666ab3337Smrg    while :; do
108766ab3337Smrg      # check if we have found a prefix of bindir
108866ab3337Smrg      case $func_relative_path_tbindir in
108966ab3337Smrg        $func_relative_path_tlibdir)
109066ab3337Smrg          # found an exact match
109166ab3337Smrg          func_relative_path_tcancelled=
109266ab3337Smrg          break
109366ab3337Smrg          ;;
109466ab3337Smrg        $func_relative_path_tlibdir*)
109566ab3337Smrg          # found a matching prefix
109666ab3337Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
109766ab3337Smrg          func_relative_path_tcancelled=$func_stripname_result
109866ab3337Smrg          if test -z "$func_relative_path_result"; then
109966ab3337Smrg            func_relative_path_result=.
110066ab3337Smrg          fi
110166ab3337Smrg          break
110266ab3337Smrg          ;;
110366ab3337Smrg        *)
110466ab3337Smrg          func_dirname $func_relative_path_tlibdir
110566ab3337Smrg          func_relative_path_tlibdir=$func_dirname_result
110666ab3337Smrg          if test -z "$func_relative_path_tlibdir"; then
110766ab3337Smrg            # Have to descend all the way to the root!
110866ab3337Smrg            func_relative_path_result=../$func_relative_path_result
110966ab3337Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
111066ab3337Smrg            break
111166ab3337Smrg          fi
111266ab3337Smrg          func_relative_path_result=../$func_relative_path_result
111366ab3337Smrg          ;;
111466ab3337Smrg      esac
111566ab3337Smrg    done
111666ab3337Smrg
111766ab3337Smrg    # Now calculate path; take care to avoid doubling-up slashes.
111866ab3337Smrg    func_stripname '' '/' "$func_relative_path_result"
111966ab3337Smrg    func_relative_path_result=$func_stripname_result
112066ab3337Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
112166ab3337Smrg    if test -n "$func_stripname_result"; then
112266ab3337Smrg      func_append func_relative_path_result "/$func_stripname_result"
112366ab3337Smrg    fi
112466ab3337Smrg
112566ab3337Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
112666ab3337Smrg    if test -n "$func_relative_path_result"; then
112766ab3337Smrg      func_stripname './' '' "$func_relative_path_result"
112866ab3337Smrg      func_relative_path_result=$func_stripname_result
112966ab3337Smrg    fi
113066ab3337Smrg
113166ab3337Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
113266ab3337Smrg
113366ab3337Smrg    :
113466ab3337Smrg}
113566ab3337Smrg
113666ab3337Smrg
113766ab3337Smrg# func_quote_portable EVAL ARG
113866ab3337Smrg# ----------------------------
113966ab3337Smrg# Internal function to portably implement func_quote_arg.  Note that we still
114066ab3337Smrg# keep attention to performance here so we as much as possible try to avoid
114166ab3337Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
114266ab3337Smrgfunc_quote_portable ()
114366ab3337Smrg{
114466ab3337Smrg    $debug_cmd
114566ab3337Smrg
114666ab3337Smrg    $require_check_ifs_backslash
114766ab3337Smrg
114866ab3337Smrg    func_quote_portable_result=$2
114966ab3337Smrg
115066ab3337Smrg    # one-time-loop (easy break)
115166ab3337Smrg    while true
115266ab3337Smrg    do
115366ab3337Smrg      if $1; then
115466ab3337Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
115566ab3337Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
115666ab3337Smrg        break
115766ab3337Smrg      fi
115866ab3337Smrg
115966ab3337Smrg      # Quote for eval.
116066ab3337Smrg      case $func_quote_portable_result in
116166ab3337Smrg        *[\\\`\"\$]*)
116266ab3337Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
116366ab3337Smrg          # contains the shell wildcard characters.
116466ab3337Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
116566ab3337Smrg            :*|*[\[\*\?]*)
116666ab3337Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
116766ab3337Smrg                  | $SED "$sed_quote_subst"`
116866ab3337Smrg              break
116966ab3337Smrg              ;;
117066ab3337Smrg          esac
117166ab3337Smrg
117266ab3337Smrg          func_quote_portable_old_IFS=$IFS
117366ab3337Smrg          for _G_char in '\' '`' '"' '$'
117466ab3337Smrg          do
117566ab3337Smrg            # STATE($1) PREV($2) SEPARATOR($3)
117666ab3337Smrg            set start "" ""
117766ab3337Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
117866ab3337Smrg            IFS=$_G_char
117966ab3337Smrg            for _G_part in $func_quote_portable_result
118066ab3337Smrg            do
118166ab3337Smrg              case $1 in
118266ab3337Smrg              quote)
118366ab3337Smrg                func_append func_quote_portable_result "$3$2"
118466ab3337Smrg                set quote "$_G_part" "\\$_G_char"
118566ab3337Smrg                ;;
118666ab3337Smrg              start)
118766ab3337Smrg                set first "" ""
118866ab3337Smrg                func_quote_portable_result=
118966ab3337Smrg                ;;
119066ab3337Smrg              first)
119166ab3337Smrg                set quote "$_G_part" ""
119266ab3337Smrg                ;;
119366ab3337Smrg              esac
119466ab3337Smrg            done
119566ab3337Smrg          done
119666ab3337Smrg          IFS=$func_quote_portable_old_IFS
119766ab3337Smrg          ;;
119866ab3337Smrg        *) ;;
119966ab3337Smrg      esac
120066ab3337Smrg      break
120166ab3337Smrg    done
120266ab3337Smrg
120366ab3337Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
120466ab3337Smrg    case $func_quote_portable_result in
120566ab3337Smrg      # double-quote args containing shell metacharacters to delay
120666ab3337Smrg      # word splitting, command substitution and variable expansion
120766ab3337Smrg      # for a subsequent eval.
120866ab3337Smrg      # many bourne shells cannot handle close brackets correctly
12092a75d1c4Smrg      # in scan sets, so we specify it separately.
12102a75d1c4Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
121166ab3337Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
121266ab3337Smrg        ;;
121366ab3337Smrg    esac
121466ab3337Smrg}
121566ab3337Smrg
121666ab3337Smrg
121766ab3337Smrg# func_quotefast_eval ARG
121866ab3337Smrg# -----------------------
121966ab3337Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
122066ab3337Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
122166ab3337Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
122266ab3337Smrg  printf -v _GL_test_printf_tilde %q '~'
122366ab3337Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
122466ab3337Smrg    func_quotefast_eval ()
122566ab3337Smrg    {
122666ab3337Smrg      printf -v func_quotefast_eval_result %q "$1"
122766ab3337Smrg    }
122866ab3337Smrg  else
122966ab3337Smrg    # Broken older Bash implementations.  Make those faster too if possible.
123066ab3337Smrg    func_quotefast_eval ()
123166ab3337Smrg    {
123266ab3337Smrg      case $1 in
123366ab3337Smrg        '~'*)
123466ab3337Smrg          func_quote_portable false "$1"
123566ab3337Smrg          func_quotefast_eval_result=$func_quote_portable_result
123666ab3337Smrg          ;;
123766ab3337Smrg        *)
123866ab3337Smrg          printf -v func_quotefast_eval_result %q "$1"
123966ab3337Smrg          ;;
124066ab3337Smrg      esac
124166ab3337Smrg    }
124266ab3337Smrg  fi
124366ab3337Smrgelse
124466ab3337Smrg  func_quotefast_eval ()
124566ab3337Smrg  {
124666ab3337Smrg    func_quote_portable false "$1"
124766ab3337Smrg    func_quotefast_eval_result=$func_quote_portable_result
124866ab3337Smrg  }
124966ab3337Smrgfi
125066ab3337Smrg
125166ab3337Smrg
125266ab3337Smrg# func_quote_arg MODEs ARG
125366ab3337Smrg# ------------------------
125466ab3337Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
125566ab3337Smrg# specifiers listed below separated by ',' character.  This function returns two
125666ab3337Smrg# values:
125766ab3337Smrg#   i) func_quote_arg_result
125866ab3337Smrg#      double-quoted (when needed), suitable for a subsequent eval
125966ab3337Smrg#  ii) func_quote_arg_unquoted_result
126066ab3337Smrg#      has all characters that are still active within double
126166ab3337Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
126266ab3337Smrg#
126366ab3337Smrg# Available modes:
126466ab3337Smrg# ----------------
126566ab3337Smrg# 'eval' (default)
126666ab3337Smrg#       - escape shell special characters
126766ab3337Smrg# 'expand'
126866ab3337Smrg#       - the same as 'eval';  but do not quote variable references
126966ab3337Smrg# 'pretty'
127066ab3337Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
127166ab3337Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
127266ab3337Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
127366ab3337Smrg# 'unquoted'
127466ab3337Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
127566ab3337Smrg#         wrapping double-quotes.
127666ab3337Smrg#
127766ab3337Smrg# Examples for 'func_quote_arg pretty,unquoted string':
127866ab3337Smrg#
127966ab3337Smrg#   string      | *_result              | *_unquoted_result
128066ab3337Smrg#   ------------+-----------------------+-------------------
128166ab3337Smrg#   "           | \"                    | \"
128266ab3337Smrg#   a b         | "a b"                 | a b
128366ab3337Smrg#   "a b"       | "\"a b\""             | \"a b\"
128466ab3337Smrg#   *           | "*"                   | *
128566ab3337Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
128666ab3337Smrg#
128766ab3337Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
128866ab3337Smrg#
128966ab3337Smrg#   string        |   *_result          |  *_unquoted_result
129066ab3337Smrg#   --------------+---------------------+--------------------
129166ab3337Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
129266ab3337Smrgfunc_quote_arg ()
129366ab3337Smrg{
129466ab3337Smrg    _G_quote_expand=false
129566ab3337Smrg    case ,$1, in
129666ab3337Smrg      *,expand,*)
129766ab3337Smrg        _G_quote_expand=:
129866ab3337Smrg        ;;
129966ab3337Smrg    esac
130066ab3337Smrg
130166ab3337Smrg    case ,$1, in
130266ab3337Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
130366ab3337Smrg        func_quote_portable $_G_quote_expand "$2"
130466ab3337Smrg        func_quote_arg_result=$func_quote_portable_result
130566ab3337Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13062a75d1c4Smrg        ;;
13072a75d1c4Smrg      *)
130866ab3337Smrg        # Faster quote-for-eval for some shells.
130966ab3337Smrg        func_quotefast_eval "$2"
131066ab3337Smrg        func_quote_arg_result=$func_quotefast_eval_result
131166ab3337Smrg        ;;
13122a75d1c4Smrg    esac
13132a75d1c4Smrg}
13142a75d1c4Smrg
13152a75d1c4Smrg
131666ab3337Smrg# func_quote MODEs ARGs...
131766ab3337Smrg# ------------------------
131866ab3337Smrg# Quote all ARGs to be evaled later and join them into single command.  See
131966ab3337Smrg# func_quote_arg's description for more info.
132066ab3337Smrgfunc_quote ()
13212a75d1c4Smrg{
132266ab3337Smrg    $debug_cmd
132366ab3337Smrg    _G_func_quote_mode=$1 ; shift
132466ab3337Smrg    func_quote_result=
132566ab3337Smrg    while test 0 -lt $#; do
132666ab3337Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
132766ab3337Smrg      if test -n "$func_quote_result"; then
132866ab3337Smrg        func_append func_quote_result " $func_quote_arg_result"
132966ab3337Smrg      else
133066ab3337Smrg        func_append func_quote_result "$func_quote_arg_result"
133166ab3337Smrg      fi
133266ab3337Smrg      shift
133366ab3337Smrg    done
133466ab3337Smrg}
133566ab3337Smrg
133666ab3337Smrg
133766ab3337Smrg# func_stripname PREFIX SUFFIX NAME
133866ab3337Smrg# ---------------------------------
133966ab3337Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
134066ab3337Smrg# PREFIX and SUFFIX must not contain globbing or regex special
134166ab3337Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
134266ab3337Smrg# dot (in which case that matches only a dot).
134366ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
134466ab3337Smrg  eval 'func_stripname ()
134566ab3337Smrg  {
134666ab3337Smrg    $debug_cmd
134766ab3337Smrg
134866ab3337Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
134966ab3337Smrg    # positional parameters, so assign one to ordinary variable first.
135066ab3337Smrg    func_stripname_result=$3
135166ab3337Smrg    func_stripname_result=${func_stripname_result#"$1"}
135266ab3337Smrg    func_stripname_result=${func_stripname_result%"$2"}
135366ab3337Smrg  }'
135466ab3337Smrgelse
135566ab3337Smrg  func_stripname ()
135666ab3337Smrg  {
135766ab3337Smrg    $debug_cmd
135866ab3337Smrg
135966ab3337Smrg    case $2 in
136066ab3337Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
136166ab3337Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
136266ab3337Smrg    esac
136366ab3337Smrg  }
136466ab3337Smrgfi
136566ab3337Smrg
136666ab3337Smrg
136766ab3337Smrg# func_show_eval CMD [FAIL_EXP]
136866ab3337Smrg# -----------------------------
136966ab3337Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
137066ab3337Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
137166ab3337Smrg# is given, then evaluate it.
137266ab3337Smrgfunc_show_eval ()
137366ab3337Smrg{
137466ab3337Smrg    $debug_cmd
137566ab3337Smrg
137666ab3337Smrg    _G_cmd=$1
137766ab3337Smrg    _G_fail_exp=${2-':'}
137866ab3337Smrg
137966ab3337Smrg    func_quote_arg pretty,expand "$_G_cmd"
138066ab3337Smrg    eval "func_notquiet $func_quote_arg_result"
138166ab3337Smrg
138266ab3337Smrg    $opt_dry_run || {
138366ab3337Smrg      eval "$_G_cmd"
138466ab3337Smrg      _G_status=$?
138566ab3337Smrg      if test 0 -ne "$_G_status"; then
138666ab3337Smrg	eval "(exit $_G_status); $_G_fail_exp"
138766ab3337Smrg      fi
138866ab3337Smrg    }
138966ab3337Smrg}
139066ab3337Smrg
139166ab3337Smrg
139266ab3337Smrg# func_show_eval_locale CMD [FAIL_EXP]
139366ab3337Smrg# ------------------------------------
139466ab3337Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
139566ab3337Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
139666ab3337Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
139766ab3337Smrgfunc_show_eval_locale ()
139866ab3337Smrg{
139966ab3337Smrg    $debug_cmd
140066ab3337Smrg
140166ab3337Smrg    _G_cmd=$1
140266ab3337Smrg    _G_fail_exp=${2-':'}
140366ab3337Smrg
140466ab3337Smrg    $opt_quiet || {
140566ab3337Smrg      func_quote_arg expand,pretty "$_G_cmd"
140666ab3337Smrg      eval "func_echo $func_quote_arg_result"
140766ab3337Smrg    }
140866ab3337Smrg
140966ab3337Smrg    $opt_dry_run || {
141066ab3337Smrg      eval "$_G_user_locale
141166ab3337Smrg	    $_G_cmd"
141266ab3337Smrg      _G_status=$?
141366ab3337Smrg      eval "$_G_safe_locale"
141466ab3337Smrg      if test 0 -ne "$_G_status"; then
141566ab3337Smrg	eval "(exit $_G_status); $_G_fail_exp"
141666ab3337Smrg      fi
141766ab3337Smrg    }
141866ab3337Smrg}
141966ab3337Smrg
142066ab3337Smrg
142166ab3337Smrg# func_tr_sh
142266ab3337Smrg# ----------
142366ab3337Smrg# Turn $1 into a string suitable for a shell variable name.
142466ab3337Smrg# Result is stored in $func_tr_sh_result.  All characters
142566ab3337Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
142666ab3337Smrg# if $1 begins with a digit, a '_' is prepended as well.
142766ab3337Smrgfunc_tr_sh ()
142866ab3337Smrg{
142966ab3337Smrg    $debug_cmd
143066ab3337Smrg
14312a75d1c4Smrg    case $1 in
143266ab3337Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
143366ab3337Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
143466ab3337Smrg      ;;
143566ab3337Smrg    * )
143666ab3337Smrg      func_tr_sh_result=$1
143766ab3337Smrg      ;;
14382a75d1c4Smrg    esac
143966ab3337Smrg}
14402a75d1c4Smrg
144166ab3337Smrg
144266ab3337Smrg# func_verbose ARG...
144366ab3337Smrg# -------------------
144466ab3337Smrg# Echo program name prefixed message in verbose mode only.
144566ab3337Smrgfunc_verbose ()
144666ab3337Smrg{
144766ab3337Smrg    $debug_cmd
144866ab3337Smrg
144966ab3337Smrg    $opt_verbose && func_echo "$*"
145066ab3337Smrg
145166ab3337Smrg    :
145266ab3337Smrg}
145366ab3337Smrg
145466ab3337Smrg
145566ab3337Smrg# func_warn_and_continue ARG...
145666ab3337Smrg# -----------------------------
145766ab3337Smrg# Echo program name prefixed warning message to standard error.
145866ab3337Smrgfunc_warn_and_continue ()
145966ab3337Smrg{
146066ab3337Smrg    $debug_cmd
146166ab3337Smrg
146266ab3337Smrg    $require_term_colors
146366ab3337Smrg
146466ab3337Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
146566ab3337Smrg}
146666ab3337Smrg
146766ab3337Smrg
146866ab3337Smrg# func_warning CATEGORY ARG...
146966ab3337Smrg# ----------------------------
147066ab3337Smrg# Echo program name prefixed warning message to standard error. Warning
147166ab3337Smrg# messages can be filtered according to CATEGORY, where this function
147266ab3337Smrg# elides messages where CATEGORY is not listed in the global variable
147366ab3337Smrg# 'opt_warning_types'.
147466ab3337Smrgfunc_warning ()
147566ab3337Smrg{
147666ab3337Smrg    $debug_cmd
147766ab3337Smrg
147866ab3337Smrg    # CATEGORY must be in the warning_categories list!
147966ab3337Smrg    case " $warning_categories " in
148066ab3337Smrg      *" $1 "*) ;;
148166ab3337Smrg      *) func_internal_error "invalid warning category '$1'" ;;
14822a75d1c4Smrg    esac
14832a75d1c4Smrg
148466ab3337Smrg    _G_category=$1
148566ab3337Smrg    shift
148666ab3337Smrg
148766ab3337Smrg    case " $opt_warning_types " in
148866ab3337Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
148966ab3337Smrg    esac
149066ab3337Smrg}
149166ab3337Smrg
149266ab3337Smrg
149366ab3337Smrg# func_sort_ver VER1 VER2
149466ab3337Smrg# -----------------------
149566ab3337Smrg# 'sort -V' is not generally available.
149666ab3337Smrg# Note this deviates from the version comparison in automake
149766ab3337Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
149866ab3337Smrg# but this should suffice as we won't be specifying old
149966ab3337Smrg# version formats or redundant trailing .0 in bootstrap.conf.
150066ab3337Smrg# If we did want full compatibility then we should probably
150166ab3337Smrg# use m4_version_compare from autoconf.
150266ab3337Smrgfunc_sort_ver ()
150366ab3337Smrg{
150466ab3337Smrg    $debug_cmd
150566ab3337Smrg
150666ab3337Smrg    printf '%s\n%s\n' "$1" "$2" \
150766ab3337Smrg      | 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
150866ab3337Smrg}
150966ab3337Smrg
151066ab3337Smrg# func_lt_ver PREV CURR
151166ab3337Smrg# ---------------------
151266ab3337Smrg# Return true if PREV and CURR are in the correct order according to
151366ab3337Smrg# func_sort_ver, otherwise false.  Use it like this:
151466ab3337Smrg#
151566ab3337Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
151666ab3337Smrgfunc_lt_ver ()
151766ab3337Smrg{
151866ab3337Smrg    $debug_cmd
151966ab3337Smrg
152066ab3337Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
152166ab3337Smrg}
152266ab3337Smrg
152366ab3337Smrg
152466ab3337Smrg# Local variables:
152566ab3337Smrg# mode: shell-script
152666ab3337Smrg# sh-indentation: 2
152766ab3337Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
152866ab3337Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
152966ab3337Smrg# time-stamp-time-zone: "UTC"
153066ab3337Smrg# End:
153166ab3337Smrg#! /bin/sh
153266ab3337Smrg
153366ab3337Smrg# A portable, pluggable option parser for Bourne shell.
153466ab3337Smrg# Written by Gary V. Vaughan, 2010
153566ab3337Smrg
153666ab3337Smrg# This is free software.  There is NO warranty; not even for
153766ab3337Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153866ab3337Smrg#
153966ab3337Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
154066ab3337Smrg#
154166ab3337Smrg# This file is dual licensed under the terms of the MIT license
154266ab3337Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
154366ab3337Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
154466ab3337Smrg# these licenses when using or redistributing this software or any of
154566ab3337Smrg# the files within it.  See the URLs above, or the file `LICENSE`
154666ab3337Smrg# included in the Bootstrap distribution for the full license texts.
154766ab3337Smrg
154866ab3337Smrg# Please report bugs or propose patches to:
154966ab3337Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
155066ab3337Smrg
155166ab3337Smrg# Set a version string for this script.
155266ab3337Smrgscriptversion=2019-02-19.15; # UTC
155366ab3337Smrg
155466ab3337Smrg
155566ab3337Smrg## ------ ##
155666ab3337Smrg## Usage. ##
155766ab3337Smrg## ------ ##
155866ab3337Smrg
155966ab3337Smrg# This file is a library for parsing options in your shell scripts along
156066ab3337Smrg# with assorted other useful supporting features that you can make use
156166ab3337Smrg# of too.
156266ab3337Smrg#
156366ab3337Smrg# For the simplest scripts you might need only:
156466ab3337Smrg#
156566ab3337Smrg#   #!/bin/sh
156666ab3337Smrg#   . relative/path/to/funclib.sh
156766ab3337Smrg#   . relative/path/to/options-parser
156866ab3337Smrg#   scriptversion=1.0
156966ab3337Smrg#   func_options ${1+"$@"}
157066ab3337Smrg#   eval set dummy "$func_options_result"; shift
157166ab3337Smrg#   ...rest of your script...
157266ab3337Smrg#
157366ab3337Smrg# In order for the '--version' option to work, you will need to have a
157466ab3337Smrg# suitably formatted comment like the one at the top of this file
157566ab3337Smrg# starting with '# Written by ' and ending with '# Copyright'.
157666ab3337Smrg#
157766ab3337Smrg# For '-h' and '--help' to work, you will also need a one line
157866ab3337Smrg# description of your script's purpose in a comment directly above the
157966ab3337Smrg# '# Written by ' line, like the one at the top of this file.
158066ab3337Smrg#
158166ab3337Smrg# The default options also support '--debug', which will turn on shell
158266ab3337Smrg# execution tracing (see the comment above debug_cmd below for another
158366ab3337Smrg# use), and '--verbose' and the func_verbose function to allow your script
158466ab3337Smrg# to display verbose messages only when your user has specified
158566ab3337Smrg# '--verbose'.
158666ab3337Smrg#
158766ab3337Smrg# After sourcing this file, you can plug in processing for additional
158866ab3337Smrg# options by amending the variables from the 'Configuration' section
158966ab3337Smrg# below, and following the instructions in the 'Option parsing'
159066ab3337Smrg# section further down.
159166ab3337Smrg
159266ab3337Smrg## -------------- ##
159366ab3337Smrg## Configuration. ##
159466ab3337Smrg## -------------- ##
159566ab3337Smrg
159666ab3337Smrg# You should override these variables in your script after sourcing this
159766ab3337Smrg# file so that they reflect the customisations you have added to the
159866ab3337Smrg# option parser.
159966ab3337Smrg
160066ab3337Smrg# The usage line for option parsing errors and the start of '-h' and
160166ab3337Smrg# '--help' output messages. You can embed shell variables for delayed
160266ab3337Smrg# expansion at the time the message is displayed, but you will need to
160366ab3337Smrg# quote other shell meta-characters carefully to prevent them being
160466ab3337Smrg# expanded when the contents are evaled.
160566ab3337Smrgusage='$progpath [OPTION]...'
160666ab3337Smrg
160766ab3337Smrg# Short help message in response to '-h' and '--help'.  Add to this or
160866ab3337Smrg# override it after sourcing this library to reflect the full set of
160966ab3337Smrg# options your script accepts.
161066ab3337Smrgusage_message="\
161166ab3337Smrg       --debug        enable verbose shell tracing
161266ab3337Smrg   -W, --warnings=CATEGORY
161366ab3337Smrg                      report the warnings falling in CATEGORY [all]
161466ab3337Smrg   -v, --verbose      verbosely report processing
161566ab3337Smrg       --version      print version information and exit
161666ab3337Smrg   -h, --help         print short or long help message and exit
161766ab3337Smrg"
161866ab3337Smrg
161966ab3337Smrg# Additional text appended to 'usage_message' in response to '--help'.
162066ab3337Smrglong_help_message="
162166ab3337SmrgWarning categories include:
162266ab3337Smrg       'all'          show all warnings
162366ab3337Smrg       'none'         turn off all the warnings
162466ab3337Smrg       'error'        warnings are treated as fatal errors"
162566ab3337Smrg
162666ab3337Smrg# Help message printed before fatal option parsing errors.
162766ab3337Smrgfatal_help="Try '\$progname --help' for more information."
162866ab3337Smrg
162966ab3337Smrg
163066ab3337Smrg
163166ab3337Smrg## ------------------------- ##
163266ab3337Smrg## Hook function management. ##
163366ab3337Smrg## ------------------------- ##
163466ab3337Smrg
163566ab3337Smrg# This section contains functions for adding, removing, and running hooks
163666ab3337Smrg# in the main code.  A hook is just a list of function names that can be
163766ab3337Smrg# run in order later on.
163866ab3337Smrg
163966ab3337Smrg# func_hookable FUNC_NAME
164066ab3337Smrg# -----------------------
164166ab3337Smrg# Declare that FUNC_NAME will run hooks added with
164266ab3337Smrg# 'func_add_hook FUNC_NAME ...'.
164366ab3337Smrgfunc_hookable ()
164466ab3337Smrg{
164566ab3337Smrg    $debug_cmd
164666ab3337Smrg
164766ab3337Smrg    func_append hookable_fns " $1"
164866ab3337Smrg}
164966ab3337Smrg
165066ab3337Smrg
165166ab3337Smrg# func_add_hook FUNC_NAME HOOK_FUNC
165266ab3337Smrg# ---------------------------------
165366ab3337Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
165466ab3337Smrg# first have been declared "hookable" by a call to 'func_hookable'.
165566ab3337Smrgfunc_add_hook ()
165666ab3337Smrg{
165766ab3337Smrg    $debug_cmd
165866ab3337Smrg
165966ab3337Smrg    case " $hookable_fns " in
166066ab3337Smrg      *" $1 "*) ;;
166166ab3337Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
166266ab3337Smrg    esac
166366ab3337Smrg
166466ab3337Smrg    eval func_append ${1}_hooks '" $2"'
166566ab3337Smrg}
166666ab3337Smrg
166766ab3337Smrg
166866ab3337Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
166966ab3337Smrg# ------------------------------------
167066ab3337Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
167166ab3337Smrg# FUNC_NAME.
167266ab3337Smrgfunc_remove_hook ()
167366ab3337Smrg{
167466ab3337Smrg    $debug_cmd
167566ab3337Smrg
167666ab3337Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
167766ab3337Smrg}
167866ab3337Smrg
167966ab3337Smrg
168066ab3337Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
168166ab3337Smrg# ---------------------------------------------
168266ab3337Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
168366ab3337Smrg# *_result variable of FUNC_NAME_B.
168466ab3337Smrgfunc_propagate_result ()
168566ab3337Smrg{
168666ab3337Smrg    $debug_cmd
168766ab3337Smrg
168866ab3337Smrg    func_propagate_result_result=:
168966ab3337Smrg    if eval "test \"\${${1}_result+set}\" = set"
169066ab3337Smrg    then
169166ab3337Smrg      eval "${2}_result=\$${1}_result"
169266ab3337Smrg    else
169366ab3337Smrg      func_propagate_result_result=false
169466ab3337Smrg    fi
169566ab3337Smrg}
169666ab3337Smrg
169766ab3337Smrg
169866ab3337Smrg# func_run_hooks FUNC_NAME [ARG]...
169966ab3337Smrg# ---------------------------------
170066ab3337Smrg# Run all hook functions registered to FUNC_NAME.
170166ab3337Smrg# It's assumed that the list of hook functions contains nothing more
170266ab3337Smrg# than a whitespace-delimited list of legal shell function names, and
170366ab3337Smrg# no effort is wasted trying to catch shell meta-characters or preserve
170466ab3337Smrg# whitespace.
170566ab3337Smrgfunc_run_hooks ()
170666ab3337Smrg{
170766ab3337Smrg    $debug_cmd
170866ab3337Smrg
170966ab3337Smrg    case " $hookable_fns " in
171066ab3337Smrg      *" $1 "*) ;;
171166ab3337Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
171266ab3337Smrg    esac
171366ab3337Smrg
171466ab3337Smrg    eval _G_hook_fns=\$$1_hooks; shift
171566ab3337Smrg
171666ab3337Smrg    for _G_hook in $_G_hook_fns; do
171766ab3337Smrg      func_unset "${_G_hook}_result"
171866ab3337Smrg      eval $_G_hook '${1+"$@"}'
171966ab3337Smrg      func_propagate_result $_G_hook func_run_hooks
172066ab3337Smrg      if $func_propagate_result_result; then
172166ab3337Smrg        eval set dummy "$func_run_hooks_result"; shift
172266ab3337Smrg      fi
172366ab3337Smrg    done
172466ab3337Smrg}
172566ab3337Smrg
172666ab3337Smrg
172766ab3337Smrg
172866ab3337Smrg## --------------- ##
172966ab3337Smrg## Option parsing. ##
173066ab3337Smrg## --------------- ##
173166ab3337Smrg
173266ab3337Smrg# In order to add your own option parsing hooks, you must accept the
173366ab3337Smrg# full positional parameter list from your hook function.  You may remove
173466ab3337Smrg# or edit any options that you action, and then pass back the remaining
173566ab3337Smrg# unprocessed options in '<hooked_function_name>_result', escaped
173666ab3337Smrg# suitably for 'eval'.
173766ab3337Smrg#
173866ab3337Smrg# The '<hooked_function_name>_result' variable is automatically unset
173966ab3337Smrg# before your hook gets called; for best performance, only set the
174066ab3337Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
174166ab3337Smrg# function unnecessarily because it can be an expensive operation on some
174266ab3337Smrg# machines).
174366ab3337Smrg#
174466ab3337Smrg# Like this:
174566ab3337Smrg#
174666ab3337Smrg#    my_options_prep ()
174766ab3337Smrg#    {
174866ab3337Smrg#        $debug_cmd
174966ab3337Smrg#
175066ab3337Smrg#        # Extend the existing usage message.
175166ab3337Smrg#        usage_message=$usage_message'
175266ab3337Smrg#      -s, --silent       don'\''t print informational messages
175366ab3337Smrg#    '
175466ab3337Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
175566ab3337Smrg#        # my_options_prep_result variable intact.
175666ab3337Smrg#    }
175766ab3337Smrg#    func_add_hook func_options_prep my_options_prep
175866ab3337Smrg#
175966ab3337Smrg#
176066ab3337Smrg#    my_silent_option ()
176166ab3337Smrg#    {
176266ab3337Smrg#        $debug_cmd
176366ab3337Smrg#
176466ab3337Smrg#        args_changed=false
176566ab3337Smrg#
176666ab3337Smrg#        # Note that, for efficiency, we parse as many options as we can
176766ab3337Smrg#        # recognise in a loop before passing the remainder back to the
176866ab3337Smrg#        # caller on the first unrecognised argument we encounter.
176966ab3337Smrg#        while test $# -gt 0; do
177066ab3337Smrg#          opt=$1; shift
177166ab3337Smrg#          case $opt in
177266ab3337Smrg#            --silent|-s) opt_silent=:
177366ab3337Smrg#                         args_changed=:
177466ab3337Smrg#                         ;;
177566ab3337Smrg#            # Separate non-argument short options:
177666ab3337Smrg#            -s*)         func_split_short_opt "$_G_opt"
177766ab3337Smrg#                         set dummy "$func_split_short_opt_name" \
177866ab3337Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
177966ab3337Smrg#                         shift
178066ab3337Smrg#                         args_changed=:
178166ab3337Smrg#                         ;;
178266ab3337Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
178366ab3337Smrg#                         # is added back to "$@" in case we need it later,
178466ab3337Smrg#                         # if $args_changed was set to 'true'.
178566ab3337Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
178666ab3337Smrg#          esac
178766ab3337Smrg#        done
178866ab3337Smrg#
178966ab3337Smrg#        # Only call 'func_quote' here if we processed at least one argument.
179066ab3337Smrg#        if $args_changed; then
179166ab3337Smrg#          func_quote eval ${1+"$@"}
179266ab3337Smrg#          my_silent_option_result=$func_quote_result
179366ab3337Smrg#        fi
179466ab3337Smrg#    }
179566ab3337Smrg#    func_add_hook func_parse_options my_silent_option
179666ab3337Smrg#
179766ab3337Smrg#
179866ab3337Smrg#    my_option_validation ()
179966ab3337Smrg#    {
180066ab3337Smrg#        $debug_cmd
180166ab3337Smrg#
180266ab3337Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
180366ab3337Smrg#    '--silent' and '--verbose' options are mutually exclusive."
180466ab3337Smrg#    }
180566ab3337Smrg#    func_add_hook func_validate_options my_option_validation
180666ab3337Smrg#
180766ab3337Smrg# You'll also need to manually amend $usage_message to reflect the extra
180866ab3337Smrg# options you parse.  It's preferable to append if you can, so that
180966ab3337Smrg# multiple option parsing hooks can be added safely.
181066ab3337Smrg
181166ab3337Smrg
181266ab3337Smrg# func_options_finish [ARG]...
181366ab3337Smrg# ----------------------------
181466ab3337Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
181566ab3337Smrgfunc_options_finish ()
181666ab3337Smrg{
181766ab3337Smrg    $debug_cmd
181866ab3337Smrg
181966ab3337Smrg    func_run_hooks func_options ${1+"$@"}
182066ab3337Smrg    func_propagate_result func_run_hooks func_options_finish
182166ab3337Smrg}
182266ab3337Smrg
182366ab3337Smrg
182466ab3337Smrg# func_options [ARG]...
182566ab3337Smrg# ---------------------
182666ab3337Smrg# All the functions called inside func_options are hookable. See the
182766ab3337Smrg# individual implementations for details.
182866ab3337Smrgfunc_hookable func_options
182966ab3337Smrgfunc_options ()
183066ab3337Smrg{
183166ab3337Smrg    $debug_cmd
183266ab3337Smrg
183366ab3337Smrg    _G_options_quoted=false
183466ab3337Smrg
183566ab3337Smrg    for my_func in options_prep parse_options validate_options options_finish
183666ab3337Smrg    do
183766ab3337Smrg      func_unset func_${my_func}_result
183866ab3337Smrg      func_unset func_run_hooks_result
183966ab3337Smrg      eval func_$my_func '${1+"$@"}'
184066ab3337Smrg      func_propagate_result func_$my_func func_options
184166ab3337Smrg      if $func_propagate_result_result; then
184266ab3337Smrg        eval set dummy "$func_options_result"; shift
184366ab3337Smrg        _G_options_quoted=:
184466ab3337Smrg      fi
184566ab3337Smrg    done
184666ab3337Smrg
184766ab3337Smrg    $_G_options_quoted || {
184866ab3337Smrg      # As we (func_options) are top-level options-parser function and
184966ab3337Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
185066ab3337Smrg      # caller.
185166ab3337Smrg      func_quote eval ${1+"$@"}
185266ab3337Smrg      func_options_result=$func_quote_result
185366ab3337Smrg    }
185466ab3337Smrg}
185566ab3337Smrg
185666ab3337Smrg
185766ab3337Smrg# func_options_prep [ARG]...
185866ab3337Smrg# --------------------------
185966ab3337Smrg# All initialisations required before starting the option parse loop.
186066ab3337Smrg# Note that when calling hook functions, we pass through the list of
186166ab3337Smrg# positional parameters.  If a hook function modifies that list, and
186266ab3337Smrg# needs to propagate that back to rest of this script, then the complete
186366ab3337Smrg# modified list must be put in 'func_run_hooks_result' before returning.
186466ab3337Smrgfunc_hookable func_options_prep
186566ab3337Smrgfunc_options_prep ()
186666ab3337Smrg{
186766ab3337Smrg    $debug_cmd
186866ab3337Smrg
186966ab3337Smrg    # Option defaults:
187066ab3337Smrg    opt_verbose=false
187166ab3337Smrg    opt_warning_types=
187266ab3337Smrg
187366ab3337Smrg    func_run_hooks func_options_prep ${1+"$@"}
187466ab3337Smrg    func_propagate_result func_run_hooks func_options_prep
18752a75d1c4Smrg}
18762a75d1c4Smrg
18772a75d1c4Smrg
187866ab3337Smrg# func_parse_options [ARG]...
187966ab3337Smrg# ---------------------------
188066ab3337Smrg# The main option parsing loop.
188166ab3337Smrgfunc_hookable func_parse_options
188266ab3337Smrgfunc_parse_options ()
18832a75d1c4Smrg{
188466ab3337Smrg    $debug_cmd
188566ab3337Smrg
188666ab3337Smrg    _G_parse_options_requote=false
188766ab3337Smrg    # this just eases exit handling
188866ab3337Smrg    while test $# -gt 0; do
188966ab3337Smrg      # Defer to hook functions for initial option parsing, so they
189066ab3337Smrg      # get priority in the event of reusing an option name.
189166ab3337Smrg      func_run_hooks func_parse_options ${1+"$@"}
189266ab3337Smrg      func_propagate_result func_run_hooks func_parse_options
189366ab3337Smrg      if $func_propagate_result_result; then
189466ab3337Smrg        eval set dummy "$func_parse_options_result"; shift
189566ab3337Smrg        # Even though we may have changed "$@", we passed the "$@" array
189666ab3337Smrg        # down into the hook and it quoted it for us (because we are in
189766ab3337Smrg        # this if-branch).  No need to quote it again.
189866ab3337Smrg        _G_parse_options_requote=false
189966ab3337Smrg      fi
19002a75d1c4Smrg
190166ab3337Smrg      # Break out of the loop if we already parsed every option.
190266ab3337Smrg      test $# -gt 0 || break
190366ab3337Smrg
190466ab3337Smrg      # We expect that one of the options parsed in this function matches
190566ab3337Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
190666ab3337Smrg      _G_match_parse_options=:
190766ab3337Smrg      _G_opt=$1
190866ab3337Smrg      shift
190966ab3337Smrg      case $_G_opt in
191066ab3337Smrg        --debug|-x)   debug_cmd='set -x'
191166ab3337Smrg                      func_echo "enabling shell trace mode" >&2
191266ab3337Smrg                      $debug_cmd
191366ab3337Smrg                      ;;
191466ab3337Smrg
191566ab3337Smrg        --no-warnings|--no-warning|--no-warn)
191666ab3337Smrg                      set dummy --warnings none ${1+"$@"}
191766ab3337Smrg                      shift
191866ab3337Smrg		      ;;
19192a75d1c4Smrg
192066ab3337Smrg        --warnings|--warning|-W)
192166ab3337Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
192266ab3337Smrg                        _G_parse_options_requote=:
192366ab3337Smrg                        break
192466ab3337Smrg                      fi
192566ab3337Smrg                      case " $warning_categories $1" in
192666ab3337Smrg                        *" $1 "*)
192766ab3337Smrg                          # trailing space prevents matching last $1 above
192866ab3337Smrg                          func_append_uniq opt_warning_types " $1"
192966ab3337Smrg                          ;;
193066ab3337Smrg                        *all)
193166ab3337Smrg                          opt_warning_types=$warning_categories
193266ab3337Smrg                          ;;
193366ab3337Smrg                        *none)
193466ab3337Smrg                          opt_warning_types=none
193566ab3337Smrg                          warning_func=:
193666ab3337Smrg                          ;;
193766ab3337Smrg                        *error)
193866ab3337Smrg                          opt_warning_types=$warning_categories
193966ab3337Smrg                          warning_func=func_fatal_error
194066ab3337Smrg                          ;;
194166ab3337Smrg                        *)
194266ab3337Smrg                          func_fatal_error \
194366ab3337Smrg                             "unsupported warning category: '$1'"
194466ab3337Smrg                          ;;
194566ab3337Smrg                      esac
194666ab3337Smrg                      shift
194766ab3337Smrg                      ;;
194866ab3337Smrg
194966ab3337Smrg        --verbose|-v) opt_verbose=: ;;
195066ab3337Smrg        --version)    func_version ;;
195166ab3337Smrg        -\?|-h)       func_usage ;;
195266ab3337Smrg        --help)       func_help ;;
195366ab3337Smrg
195466ab3337Smrg	# Separate optargs to long options (plugins may need this):
195566ab3337Smrg	--*=*)        func_split_equals "$_G_opt"
195666ab3337Smrg	              set dummy "$func_split_equals_lhs" \
195766ab3337Smrg                          "$func_split_equals_rhs" ${1+"$@"}
195866ab3337Smrg                      shift
195966ab3337Smrg                      ;;
196066ab3337Smrg
196166ab3337Smrg       # Separate optargs to short options:
196266ab3337Smrg        -W*)
196366ab3337Smrg                      func_split_short_opt "$_G_opt"
196466ab3337Smrg                      set dummy "$func_split_short_opt_name" \
196566ab3337Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
196666ab3337Smrg                      shift
196766ab3337Smrg                      ;;
196866ab3337Smrg
196966ab3337Smrg        # Separate non-argument short options:
197066ab3337Smrg        -\?*|-h*|-v*|-x*)
197166ab3337Smrg                      func_split_short_opt "$_G_opt"
197266ab3337Smrg                      set dummy "$func_split_short_opt_name" \
197366ab3337Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
197466ab3337Smrg                      shift
197566ab3337Smrg                      ;;
197666ab3337Smrg
197766ab3337Smrg        --)           _G_parse_options_requote=: ; break ;;
197866ab3337Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
197966ab3337Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
198066ab3337Smrg                      _G_match_parse_options=false
198166ab3337Smrg                      break
198266ab3337Smrg                      ;;
198366ab3337Smrg      esac
198466ab3337Smrg
198566ab3337Smrg      if $_G_match_parse_options; then
198666ab3337Smrg        _G_parse_options_requote=:
19872a75d1c4Smrg      fi
198866ab3337Smrg    done
198966ab3337Smrg
199066ab3337Smrg    if $_G_parse_options_requote; then
199166ab3337Smrg      # save modified positional parameters for caller
199266ab3337Smrg      func_quote eval ${1+"$@"}
199366ab3337Smrg      func_parse_options_result=$func_quote_result
1994f7ec340bSmacallan    fi
19952a75d1c4Smrg}
19962a75d1c4Smrg
19972a75d1c4Smrg
199866ab3337Smrg# func_validate_options [ARG]...
199966ab3337Smrg# ------------------------------
200066ab3337Smrg# Perform any sanity checks on option settings and/or unconsumed
200166ab3337Smrg# arguments.
200266ab3337Smrgfunc_hookable func_validate_options
200366ab3337Smrgfunc_validate_options ()
20042a75d1c4Smrg{
200566ab3337Smrg    $debug_cmd
20062a75d1c4Smrg
200766ab3337Smrg    # Display all warnings if -W was not given.
200866ab3337Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
20092a75d1c4Smrg
201066ab3337Smrg    func_run_hooks func_validate_options ${1+"$@"}
201166ab3337Smrg    func_propagate_result func_run_hooks func_validate_options
20122a75d1c4Smrg
201366ab3337Smrg    # Bail if the options were screwed!
201466ab3337Smrg    $exit_cmd $EXIT_FAILURE
2015f7ec340bSmacallan}
2016f7ec340bSmacallan
2017f7ec340bSmacallan
20182a75d1c4Smrg
201966ab3337Smrg## ----------------- ##
202066ab3337Smrg## Helper functions. ##
202166ab3337Smrg## ----------------- ##
2022f7ec340bSmacallan
202366ab3337Smrg# This section contains the helper functions used by the rest of the
202466ab3337Smrg# hookable option parser framework in ascii-betical order.
202566ab3337Smrg
202666ab3337Smrg
202766ab3337Smrg# func_fatal_help ARG...
202866ab3337Smrg# ----------------------
202966ab3337Smrg# Echo program name prefixed message to standard error, followed by
203066ab3337Smrg# a help hint, and exit.
203166ab3337Smrgfunc_fatal_help ()
2032f7ec340bSmacallan{
203366ab3337Smrg    $debug_cmd
20342a75d1c4Smrg
203566ab3337Smrg    eval \$ECHO \""Usage: $usage"\"
203666ab3337Smrg    eval \$ECHO \""$fatal_help"\"
203766ab3337Smrg    func_error ${1+"$@"}
203866ab3337Smrg    exit $EXIT_FAILURE
2039f7ec340bSmacallan}
2040f7ec340bSmacallan
204166ab3337Smrg
204266ab3337Smrg# func_help
204366ab3337Smrg# ---------
204466ab3337Smrg# Echo long help message to standard output and exit.
20452a75d1c4Smrgfunc_help ()
2046f7ec340bSmacallan{
204766ab3337Smrg    $debug_cmd
204866ab3337Smrg
204966ab3337Smrg    func_usage_message
205066ab3337Smrg    $ECHO "$long_help_message"
205166ab3337Smrg    exit 0
20522a75d1c4Smrg}
2053f7ec340bSmacallan
205466ab3337Smrg
205566ab3337Smrg# func_missing_arg ARGNAME
205666ab3337Smrg# ------------------------
20572a75d1c4Smrg# Echo program name prefixed message to standard error and set global
20582a75d1c4Smrg# exit_cmd.
20592a75d1c4Smrgfunc_missing_arg ()
20602a75d1c4Smrg{
206166ab3337Smrg    $debug_cmd
2062f7ec340bSmacallan
206366ab3337Smrg    func_error "Missing argument for '$1'."
20642a75d1c4Smrg    exit_cmd=exit
2065f7ec340bSmacallan}
2066f7ec340bSmacallan
2067f7ec340bSmacallan
206866ab3337Smrg# func_split_equals STRING
206966ab3337Smrg# ------------------------
207066ab3337Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
207166ab3337Smrg# after splitting STRING at the '=' sign.
207266ab3337Smrgtest -z "$_G_HAVE_XSI_OPS" \
207366ab3337Smrg    && (eval 'x=a/b/c;
207466ab3337Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
207566ab3337Smrg    && _G_HAVE_XSI_OPS=yes
207666ab3337Smrg
207766ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"
207866ab3337Smrgthen
207966ab3337Smrg  # This is an XSI compatible shell, allowing a faster implementation...
208066ab3337Smrg  eval 'func_split_equals ()
208166ab3337Smrg  {
208266ab3337Smrg      $debug_cmd
208366ab3337Smrg
208466ab3337Smrg      func_split_equals_lhs=${1%%=*}
208566ab3337Smrg      func_split_equals_rhs=${1#*=}
208666ab3337Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
208766ab3337Smrg        func_split_equals_rhs=
208866ab3337Smrg      fi
208966ab3337Smrg  }'
209066ab3337Smrgelse
209166ab3337Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
209266ab3337Smrg  func_split_equals ()
209366ab3337Smrg  {
209466ab3337Smrg      $debug_cmd
209566ab3337Smrg
209666ab3337Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
209766ab3337Smrg      func_split_equals_rhs=
209866ab3337Smrg      test "x$func_split_equals_lhs=" = "x$1" \
209966ab3337Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
210066ab3337Smrg  }
210166ab3337Smrgfi #func_split_equals
210266ab3337Smrg
210366ab3337Smrg
210466ab3337Smrg# func_split_short_opt SHORTOPT
210566ab3337Smrg# -----------------------------
21062a75d1c4Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
21072a75d1c4Smrg# variables after splitting SHORTOPT after the 2nd character.
210866ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"
210966ab3337Smrgthen
211066ab3337Smrg  # This is an XSI compatible shell, allowing a faster implementation...
211166ab3337Smrg  eval 'func_split_short_opt ()
211266ab3337Smrg  {
211366ab3337Smrg      $debug_cmd
211466ab3337Smrg
211566ab3337Smrg      func_split_short_opt_arg=${1#??}
211666ab3337Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
211766ab3337Smrg  }'
211866ab3337Smrgelse
211966ab3337Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
212066ab3337Smrg  func_split_short_opt ()
212166ab3337Smrg  {
212266ab3337Smrg      $debug_cmd
212366ab3337Smrg
212466ab3337Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
212566ab3337Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
212666ab3337Smrg  }
212766ab3337Smrgfi #func_split_short_opt
212866ab3337Smrg
212966ab3337Smrg
213066ab3337Smrg# func_usage
213166ab3337Smrg# ----------
213266ab3337Smrg# Echo short help message to standard output and exit.
213366ab3337Smrgfunc_usage ()
21342a75d1c4Smrg{
213566ab3337Smrg    $debug_cmd
21362a75d1c4Smrg
213766ab3337Smrg    func_usage_message
213866ab3337Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
213966ab3337Smrg    exit 0
214066ab3337Smrg}
2141f7ec340bSmacallan
2142f7ec340bSmacallan
214366ab3337Smrg# func_usage_message
214466ab3337Smrg# ------------------
214566ab3337Smrg# Echo short help message to standard output.
214666ab3337Smrgfunc_usage_message ()
21472a75d1c4Smrg{
214866ab3337Smrg    $debug_cmd
2149f7ec340bSmacallan
215066ab3337Smrg    eval \$ECHO \""Usage: $usage"\"
215166ab3337Smrg    echo
215266ab3337Smrg    $SED -n 's|^# ||
215366ab3337Smrg        /^Written by/{
215466ab3337Smrg          x;p;x
215566ab3337Smrg        }
215666ab3337Smrg	h
215766ab3337Smrg	/^Written by/q' < "$progpath"
215866ab3337Smrg    echo
215966ab3337Smrg    eval \$ECHO \""$usage_message"\"
216066ab3337Smrg}
2161f7ec340bSmacallan
2162f7ec340bSmacallan
216366ab3337Smrg# func_version
216466ab3337Smrg# ------------
216566ab3337Smrg# Echo version message to standard output and exit.
216666ab3337Smrg# The version message is extracted from the calling file's header
216766ab3337Smrg# comments, with leading '# ' stripped:
216866ab3337Smrg#   1. First display the progname and version
216966ab3337Smrg#   2. Followed by the header comment line matching  /^# Written by /
217066ab3337Smrg#   3. Then a blank line followed by the first following line matching
217166ab3337Smrg#      /^# Copyright /
217266ab3337Smrg#   4. Immediately followed by any lines between the previous matches,
217366ab3337Smrg#      except lines preceding the intervening completely blank line.
217466ab3337Smrg# For example, see the header comments of this file.
217566ab3337Smrgfunc_version ()
217666ab3337Smrg{
217766ab3337Smrg    $debug_cmd
2178f7ec340bSmacallan
217966ab3337Smrg    printf '%s\n' "$progname $scriptversion"
218066ab3337Smrg    $SED -n '
218166ab3337Smrg        /^# Written by /!b
218266ab3337Smrg        s|^# ||; p; n
2183f7ec340bSmacallan
218466ab3337Smrg        :fwd2blnk
218566ab3337Smrg        /./ {
218666ab3337Smrg          n
218766ab3337Smrg          b fwd2blnk
218866ab3337Smrg        }
218966ab3337Smrg        p; n
219066ab3337Smrg
219166ab3337Smrg        :holdwrnt
219266ab3337Smrg        s|^# ||
219366ab3337Smrg        s|^# *$||
219466ab3337Smrg        /^Copyright /!{
219566ab3337Smrg          /./H
219666ab3337Smrg          n
219766ab3337Smrg          b holdwrnt
219866ab3337Smrg        }
21997ce7e03cSmrg
220066ab3337Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
220166ab3337Smrg        G
220266ab3337Smrg        s|\(\n\)\n*|\1|g
220366ab3337Smrg        p; q' < "$progpath"
2204f7ec340bSmacallan
220566ab3337Smrg    exit $?
220666ab3337Smrg}
22072a75d1c4Smrg
22082a75d1c4Smrg
220966ab3337Smrg# Local variables:
221066ab3337Smrg# mode: shell-script
221166ab3337Smrg# sh-indentation: 2
221266ab3337Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
221366ab3337Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
221466ab3337Smrg# time-stamp-time-zone: "UTC"
221566ab3337Smrg# End:
22162a75d1c4Smrg
221766ab3337Smrg# Set a version string.
221866ab3337Smrgscriptversion='(GNU libtool) 2.4.7'
22192a75d1c4Smrg
222066ab3337Smrg
222166ab3337Smrg# func_echo ARG...
222266ab3337Smrg# ----------------
222366ab3337Smrg# Libtool also displays the current mode in messages, so override
222466ab3337Smrg# funclib.sh func_echo with this custom definition.
222566ab3337Smrgfunc_echo ()
22262a75d1c4Smrg{
222766ab3337Smrg    $debug_cmd
22282a75d1c4Smrg
222966ab3337Smrg    _G_message=$*
22302a75d1c4Smrg
223166ab3337Smrg    func_echo_IFS=$IFS
223266ab3337Smrg    IFS=$nl
223366ab3337Smrg    for _G_line in $_G_message; do
223466ab3337Smrg      IFS=$func_echo_IFS
223566ab3337Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
223666ab3337Smrg    done
223766ab3337Smrg    IFS=$func_echo_IFS
223866ab3337Smrg}
22392a75d1c4Smrg
22402a75d1c4Smrg
224166ab3337Smrg# func_warning ARG...
224266ab3337Smrg# -------------------
224366ab3337Smrg# Libtool warnings are not categorized, so override funclib.sh
224466ab3337Smrg# func_warning with this simpler definition.
224566ab3337Smrgfunc_warning ()
22462a75d1c4Smrg{
224766ab3337Smrg    $debug_cmd
22482a75d1c4Smrg
224966ab3337Smrg    $warning_func ${1+"$@"}
225066ab3337Smrg}
22512a75d1c4Smrg
22522a75d1c4Smrg
225366ab3337Smrg## ---------------- ##
225466ab3337Smrg## Options parsing. ##
225566ab3337Smrg## ---------------- ##
225666ab3337Smrg
225766ab3337Smrg# Hook in the functions to make sure our own options are parsed during
225866ab3337Smrg# the option parsing loop.
225966ab3337Smrg
226066ab3337Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
226166ab3337Smrg
226266ab3337Smrg# Short help message in response to '-h'.
226366ab3337Smrgusage_message="Options:
226466ab3337Smrg       --config             show all configuration variables
226566ab3337Smrg       --debug              enable verbose shell tracing
226666ab3337Smrg   -n, --dry-run            display commands without modifying any files
226766ab3337Smrg       --features           display basic configuration information and exit
226866ab3337Smrg       --mode=MODE          use operation mode MODE
226966ab3337Smrg       --no-warnings        equivalent to '-Wnone'
227066ab3337Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
227166ab3337Smrg       --quiet, --silent    don't print informational messages
227266ab3337Smrg       --tag=TAG            use configuration variables from tag TAG
227366ab3337Smrg   -v, --verbose            print more informational messages than default
227466ab3337Smrg       --version            print version information
227566ab3337Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
227666ab3337Smrg   -h, --help, --help-all   print short, long, or detailed help message
227766ab3337Smrg"
22782a75d1c4Smrg
227966ab3337Smrg# Additional text appended to 'usage_message' in response to '--help'.
228066ab3337Smrgfunc_help ()
22812a75d1c4Smrg{
228266ab3337Smrg    $debug_cmd
228366ab3337Smrg
228466ab3337Smrg    func_usage_message
228566ab3337Smrg    $ECHO "$long_help_message
228666ab3337Smrg
228766ab3337SmrgMODE must be one of the following:
228866ab3337Smrg
228966ab3337Smrg       clean           remove files from the build directory
229066ab3337Smrg       compile         compile a source file into a libtool object
229166ab3337Smrg       execute         automatically set library path, then run a program
229266ab3337Smrg       finish          complete the installation of libtool libraries
229366ab3337Smrg       install         install libraries or executables
229466ab3337Smrg       link            create a library or an executable
229566ab3337Smrg       uninstall       remove libraries from an installed directory
229666ab3337Smrg
229766ab3337SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
229866ab3337Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
229966ab3337SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
230066ab3337Smrg
230166ab3337SmrgWhen reporting a bug, please describe a test case to reproduce it and
230266ab3337Smrginclude the following information:
230366ab3337Smrg
230466ab3337Smrg       host-triplet:   $host
230566ab3337Smrg       shell:          $SHELL
230666ab3337Smrg       compiler:       $LTCC
230766ab3337Smrg       compiler flags: $LTCFLAGS
230866ab3337Smrg       linker:         $LD (gnu? $with_gnu_ld)
230966ab3337Smrg       version:        $progname (GNU libtool) 2.4.7
231066ab3337Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
231166ab3337Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
231266ab3337Smrg
231366ab3337SmrgReport bugs to <bug-libtool@gnu.org>.
231466ab3337SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
231566ab3337SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
231666ab3337Smrg    exit 0
231766ab3337Smrg}
231866ab3337Smrg
23192a75d1c4Smrg
232066ab3337Smrg# func_lo2o OBJECT-NAME
232166ab3337Smrg# ---------------------
232266ab3337Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
232366ab3337Smrg# object suffix.
23242a75d1c4Smrg
232566ab3337Smrglo2o=s/\\.lo\$/.$objext/
232666ab3337Smrgo2lo=s/\\.$objext\$/.lo/
232766ab3337Smrg
232866ab3337Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
232966ab3337Smrg  eval 'func_lo2o ()
233066ab3337Smrg  {
233166ab3337Smrg    case $1 in
233266ab3337Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
233366ab3337Smrg      *   ) func_lo2o_result=$1               ;;
233466ab3337Smrg    esac
233566ab3337Smrg  }'
233666ab3337Smrg
233766ab3337Smrg  # func_xform LIBOBJ-OR-SOURCE
233866ab3337Smrg  # ---------------------------
233966ab3337Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
234066ab3337Smrg  # suffix to a '.lo' libtool-object suffix.
234166ab3337Smrg  eval 'func_xform ()
234266ab3337Smrg  {
234366ab3337Smrg    func_xform_result=${1%.*}.lo
234466ab3337Smrg  }'
234566ab3337Smrgelse
234666ab3337Smrg  # ...otherwise fall back to using sed.
234766ab3337Smrg  func_lo2o ()
234866ab3337Smrg  {
234966ab3337Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
235066ab3337Smrg  }
235166ab3337Smrg
235266ab3337Smrg  func_xform ()
235366ab3337Smrg  {
235466ab3337Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
235566ab3337Smrg  }
235666ab3337Smrgfi
235766ab3337Smrg
235866ab3337Smrg
235966ab3337Smrg# func_fatal_configuration ARG...
236066ab3337Smrg# -------------------------------
23612a75d1c4Smrg# Echo program name prefixed message to standard error, followed by
23622a75d1c4Smrg# a configuration failure hint, and exit.
23632a75d1c4Smrgfunc_fatal_configuration ()
23642a75d1c4Smrg{
236566ab3337Smrg    func_fatal_error ${1+"$@"} \
236666ab3337Smrg      "See the $PACKAGE documentation for more information." \
236766ab3337Smrg      "Fatal configuration error."
23682a75d1c4Smrg}
23692a75d1c4Smrg
23702a75d1c4Smrg
23712a75d1c4Smrg# func_config
237266ab3337Smrg# -----------
23732a75d1c4Smrg# Display the configuration for all the tags in this script.
23742a75d1c4Smrgfunc_config ()
23752a75d1c4Smrg{
23762a75d1c4Smrg    re_begincf='^# ### BEGIN LIBTOOL'
23772a75d1c4Smrg    re_endcf='^# ### END LIBTOOL'
23782a75d1c4Smrg
23792a75d1c4Smrg    # Default configuration.
23802a75d1c4Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23812a75d1c4Smrg
2382f7ec340bSmacallan    # Now print the configurations for the tags.
2383f7ec340bSmacallan    for tagname in $taglist; do
23842a75d1c4Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385f7ec340bSmacallan    done
2386f7ec340bSmacallan
23872a75d1c4Smrg    exit $?
23882a75d1c4Smrg}
2389f7ec340bSmacallan
239066ab3337Smrg
23912a75d1c4Smrg# func_features
239266ab3337Smrg# -------------
23932a75d1c4Smrg# Display the features supported by this script.
23942a75d1c4Smrgfunc_features ()
23952a75d1c4Smrg{
23962a75d1c4Smrg    echo "host: $host"
239766ab3337Smrg    if test yes = "$build_libtool_libs"; then
23982a75d1c4Smrg      echo "enable shared libraries"
2399f7ec340bSmacallan    else
24002a75d1c4Smrg      echo "disable shared libraries"
2401f7ec340bSmacallan    fi
240266ab3337Smrg    if test yes = "$build_old_libs"; then
24032a75d1c4Smrg      echo "enable static libraries"
2404f7ec340bSmacallan    else
24052a75d1c4Smrg      echo "disable static libraries"
2406f7ec340bSmacallan    fi
2407f7ec340bSmacallan
24082a75d1c4Smrg    exit $?
24092a75d1c4Smrg}
2410f7ec340bSmacallan
241166ab3337Smrg
241266ab3337Smrg# func_enable_tag TAGNAME
241366ab3337Smrg# -----------------------
24142a75d1c4Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
24152a75d1c4Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
24162a75d1c4Smrg# variable here.
24172a75d1c4Smrgfunc_enable_tag ()
24182a75d1c4Smrg{
241966ab3337Smrg    # Global variable:
242066ab3337Smrg    tagname=$1
2421f7ec340bSmacallan
242266ab3337Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
242366ab3337Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
242466ab3337Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425f7ec340bSmacallan
242666ab3337Smrg    # Validate tagname.
242766ab3337Smrg    case $tagname in
242866ab3337Smrg      *[!-_A-Za-z0-9,/]*)
242966ab3337Smrg        func_fatal_error "invalid tag name: $tagname"
243066ab3337Smrg        ;;
243166ab3337Smrg    esac
2432f7ec340bSmacallan
243366ab3337Smrg    # Don't test for the "default" C tag, as we know it's
243466ab3337Smrg    # there but not specially marked.
243566ab3337Smrg    case $tagname in
243666ab3337Smrg        CC) ;;
24372a75d1c4Smrg    *)
243866ab3337Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
243966ab3337Smrg	  taglist="$taglist $tagname"
244066ab3337Smrg
244166ab3337Smrg	  # Evaluate the configuration.  Be careful to quote the path
244266ab3337Smrg	  # and the sed script, to avoid splitting on whitespace, but
244366ab3337Smrg	  # also don't use non-portable quotes within backquotes within
244466ab3337Smrg	  # quotes we have to do it in 2 steps:
244566ab3337Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
244666ab3337Smrg	  eval "$extractedcf"
244766ab3337Smrg        else
244866ab3337Smrg	  func_error "ignoring unknown tag $tagname"
244966ab3337Smrg        fi
245066ab3337Smrg        ;;
245166ab3337Smrg    esac
24522a75d1c4Smrg}
2453f7ec340bSmacallan
245466ab3337Smrg
24552a75d1c4Smrg# func_check_version_match
245666ab3337Smrg# ------------------------
24572a75d1c4Smrg# Ensure that we are using m4 macros, and libtool script from the same
24582a75d1c4Smrg# release of libtool.
24592a75d1c4Smrgfunc_check_version_match ()
24602a75d1c4Smrg{
246166ab3337Smrg    if test "$package_revision" != "$macro_revision"; then
246266ab3337Smrg      if test "$VERSION" != "$macro_version"; then
246366ab3337Smrg        if test -z "$macro_version"; then
246466ab3337Smrg          cat >&2 <<_LT_EOF
24652a75d1c4Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24662a75d1c4Smrg$progname: definition of this LT_INIT comes from an older release.
24672a75d1c4Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24682a75d1c4Smrg$progname: and run autoconf again.
24692a75d1c4Smrg_LT_EOF
247066ab3337Smrg        else
247166ab3337Smrg          cat >&2 <<_LT_EOF
24722a75d1c4Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24732a75d1c4Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
24742a75d1c4Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24752a75d1c4Smrg$progname: and run autoconf again.
24762a75d1c4Smrg_LT_EOF
247766ab3337Smrg        fi
247866ab3337Smrg      else
247966ab3337Smrg        cat >&2 <<_LT_EOF
24802a75d1c4Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
24812a75d1c4Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
24822a75d1c4Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
24832a75d1c4Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
24842a75d1c4Smrg_LT_EOF
248566ab3337Smrg      fi
2486f7ec340bSmacallan
248766ab3337Smrg      exit $EXIT_MISMATCH
248866ab3337Smrg    fi
24892a75d1c4Smrg}
2490f7ec340bSmacallan
2491f7ec340bSmacallan
249266ab3337Smrg# libtool_options_prep [ARG]...
249366ab3337Smrg# -----------------------------
249466ab3337Smrg# Preparation for options parsed by libtool.
249566ab3337Smrglibtool_options_prep ()
249666ab3337Smrg{
249766ab3337Smrg    $debug_mode
2498f7ec340bSmacallan
249966ab3337Smrg    # Option defaults:
250066ab3337Smrg    opt_config=false
250166ab3337Smrg    opt_dlopen=
250266ab3337Smrg    opt_dry_run=false
250366ab3337Smrg    opt_help=false
250466ab3337Smrg    opt_mode=
250566ab3337Smrg    opt_preserve_dup_deps=false
250666ab3337Smrg    opt_quiet=false
2507f7ec340bSmacallan
250866ab3337Smrg    nonopt=
250966ab3337Smrg    preserve_args=
2510f7ec340bSmacallan
251166ab3337Smrg    _G_rc_lt_options_prep=:
25122a75d1c4Smrg
251366ab3337Smrg    # Shorthand for --mode=foo, only valid as the first argument
251466ab3337Smrg    case $1 in
251566ab3337Smrg    clean|clea|cle|cl)
251666ab3337Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
251766ab3337Smrg      ;;
251866ab3337Smrg    compile|compil|compi|comp|com|co|c)
251966ab3337Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
252066ab3337Smrg      ;;
252166ab3337Smrg    execute|execut|execu|exec|exe|ex|e)
252266ab3337Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
252366ab3337Smrg      ;;
252466ab3337Smrg    finish|finis|fini|fin|fi|f)
252566ab3337Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
252666ab3337Smrg      ;;
252766ab3337Smrg    install|instal|insta|inst|ins|in|i)
252866ab3337Smrg      shift; set dummy --mode install ${1+"$@"}; shift
252966ab3337Smrg      ;;
253066ab3337Smrg    link|lin|li|l)
253166ab3337Smrg      shift; set dummy --mode link ${1+"$@"}; shift
253266ab3337Smrg      ;;
253366ab3337Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
253466ab3337Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
253566ab3337Smrg      ;;
253666ab3337Smrg    *)
253766ab3337Smrg      _G_rc_lt_options_prep=false
253866ab3337Smrg      ;;
2539f7ec340bSmacallan    esac
2540f7ec340bSmacallan
254166ab3337Smrg    if $_G_rc_lt_options_prep; then
254266ab3337Smrg      # Pass back the list of options.
254366ab3337Smrg      func_quote eval ${1+"$@"}
254466ab3337Smrg      libtool_options_prep_result=$func_quote_result
254566ab3337Smrg    fi
254666ab3337Smrg}
254766ab3337Smrgfunc_add_hook func_options_prep libtool_options_prep
25482a75d1c4Smrg
2549f7ec340bSmacallan
255066ab3337Smrg# libtool_parse_options [ARG]...
255166ab3337Smrg# ---------------------------------
255266ab3337Smrg# Provide handling for libtool specific options.
255366ab3337Smrglibtool_parse_options ()
255466ab3337Smrg{
255566ab3337Smrg    $debug_cmd
2556f7ec340bSmacallan
255766ab3337Smrg    _G_rc_lt_parse_options=false
2558f7ec340bSmacallan
255966ab3337Smrg    # Perform our own loop to consume as many options as possible in
256066ab3337Smrg    # each iteration.
256166ab3337Smrg    while test $# -gt 0; do
256266ab3337Smrg      _G_match_lt_parse_options=:
256366ab3337Smrg      _G_opt=$1
256466ab3337Smrg      shift
256566ab3337Smrg      case $_G_opt in
256666ab3337Smrg        --dry-run|--dryrun|-n)
256766ab3337Smrg                        opt_dry_run=:
256866ab3337Smrg                        ;;
256966ab3337Smrg
257066ab3337Smrg        --config)       func_config ;;
257166ab3337Smrg
257266ab3337Smrg        --dlopen|-dlopen)
257366ab3337Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
257466ab3337Smrg}$1"
257566ab3337Smrg                        shift
257666ab3337Smrg                        ;;
257766ab3337Smrg
257866ab3337Smrg        --preserve-dup-deps)
257966ab3337Smrg                        opt_preserve_dup_deps=: ;;
258066ab3337Smrg
258166ab3337Smrg        --features)     func_features ;;
258266ab3337Smrg
258366ab3337Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
258466ab3337Smrg
258566ab3337Smrg        --help)         opt_help=: ;;
258666ab3337Smrg
258766ab3337Smrg        --help-all)     opt_help=': help-all' ;;
258866ab3337Smrg
258966ab3337Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
259066ab3337Smrg                        opt_mode=$1
259166ab3337Smrg                        case $1 in
259266ab3337Smrg                          # Valid mode arguments:
259366ab3337Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
259466ab3337Smrg
259566ab3337Smrg                          # Catch anything else as an error
259666ab3337Smrg                          *) func_error "invalid argument for $_G_opt"
259766ab3337Smrg                             exit_cmd=exit
259866ab3337Smrg                             break
259966ab3337Smrg                             ;;
260066ab3337Smrg                        esac
260166ab3337Smrg                        shift
260266ab3337Smrg                        ;;
260366ab3337Smrg
260466ab3337Smrg        --no-silent|--no-quiet)
260566ab3337Smrg                        opt_quiet=false
260666ab3337Smrg                        func_append preserve_args " $_G_opt"
260766ab3337Smrg                        ;;
260866ab3337Smrg
260966ab3337Smrg        --no-warnings|--no-warning|--no-warn)
261066ab3337Smrg                        opt_warning=false
261166ab3337Smrg                        func_append preserve_args " $_G_opt"
261266ab3337Smrg                        ;;
261366ab3337Smrg
261466ab3337Smrg        --no-verbose)
261566ab3337Smrg                        opt_verbose=false
261666ab3337Smrg                        func_append preserve_args " $_G_opt"
261766ab3337Smrg                        ;;
261866ab3337Smrg
261966ab3337Smrg        --silent|--quiet)
262066ab3337Smrg                        opt_quiet=:
262166ab3337Smrg                        opt_verbose=false
262266ab3337Smrg                        func_append preserve_args " $_G_opt"
262366ab3337Smrg                        ;;
262466ab3337Smrg
262566ab3337Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
262666ab3337Smrg                        opt_tag=$1
262766ab3337Smrg                        func_append preserve_args " $_G_opt $1"
262866ab3337Smrg                        func_enable_tag "$1"
262966ab3337Smrg                        shift
263066ab3337Smrg                        ;;
263166ab3337Smrg
263266ab3337Smrg        --verbose|-v)   opt_quiet=false
263366ab3337Smrg                        opt_verbose=:
263466ab3337Smrg                        func_append preserve_args " $_G_opt"
263566ab3337Smrg                        ;;
263666ab3337Smrg
263766ab3337Smrg        # An option not handled by this hook function:
263866ab3337Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
263966ab3337Smrg                        _G_match_lt_parse_options=false
264066ab3337Smrg                        break
264166ab3337Smrg                        ;;
264266ab3337Smrg      esac
264366ab3337Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
264466ab3337Smrg    done
2645f7ec340bSmacallan
264666ab3337Smrg    if $_G_rc_lt_parse_options; then
264766ab3337Smrg      # save modified positional parameters for caller
264866ab3337Smrg      func_quote eval ${1+"$@"}
264966ab3337Smrg      libtool_parse_options_result=$func_quote_result
26502a75d1c4Smrg    fi
265166ab3337Smrg}
265266ab3337Smrgfunc_add_hook func_parse_options libtool_parse_options
2653f7ec340bSmacallan
2654f7ec340bSmacallan
265566ab3337Smrg
265666ab3337Smrg# libtool_validate_options [ARG]...
265766ab3337Smrg# ---------------------------------
265866ab3337Smrg# Perform any sanity checks on option settings and/or unconsumed
265966ab3337Smrg# arguments.
266066ab3337Smrglibtool_validate_options ()
266166ab3337Smrg{
266266ab3337Smrg    # save first non-option argument
266366ab3337Smrg    if test 0 -lt $#; then
266466ab3337Smrg      nonopt=$1
266566ab3337Smrg      shift
26662a75d1c4Smrg    fi
2667f7ec340bSmacallan
266866ab3337Smrg    # preserve --debug
266966ab3337Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
267066ab3337Smrg
267166ab3337Smrg    case $host in
267266ab3337Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
267366ab3337Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
267466ab3337Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
267566ab3337Smrg        # don't eliminate duplications in $postdeps and $predeps
267666ab3337Smrg        opt_duplicate_compiler_generated_deps=:
267766ab3337Smrg        ;;
267866ab3337Smrg      *)
267966ab3337Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
268066ab3337Smrg        ;;
268166ab3337Smrg    esac
2682f7ec340bSmacallan
268366ab3337Smrg    $opt_help || {
268466ab3337Smrg      # Sanity checks first:
268566ab3337Smrg      func_check_version_match
2686f7ec340bSmacallan
268766ab3337Smrg      test yes != "$build_libtool_libs" \
268866ab3337Smrg        && test yes != "$build_old_libs" \
268966ab3337Smrg        && func_fatal_configuration "not configured to build any kind of library"
269066ab3337Smrg
269166ab3337Smrg      # Darwin sucks
269266ab3337Smrg      eval std_shrext=\"$shrext_cmds\"
269366ab3337Smrg
269466ab3337Smrg      # Only execute mode is allowed to have -dlopen flags.
269566ab3337Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
269666ab3337Smrg        func_error "unrecognized option '-dlopen'"
269766ab3337Smrg        $ECHO "$help" 1>&2
269866ab3337Smrg        exit $EXIT_FAILURE
269966ab3337Smrg      fi
270066ab3337Smrg
270166ab3337Smrg      # Change the help message to a mode-specific one.
270266ab3337Smrg      generic_help=$help
270366ab3337Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
270466ab3337Smrg    }
270566ab3337Smrg
270666ab3337Smrg    # Pass back the unparsed argument list
270766ab3337Smrg    func_quote eval ${1+"$@"}
270866ab3337Smrg    libtool_validate_options_result=$func_quote_result
27092a75d1c4Smrg}
271066ab3337Smrgfunc_add_hook func_validate_options libtool_validate_options
2711f7ec340bSmacallan
2712f7ec340bSmacallan
271366ab3337Smrg# Process options as early as possible so that --help and --version
271466ab3337Smrg# can return quickly.
271566ab3337Smrgfunc_options ${1+"$@"}
271666ab3337Smrgeval set dummy "$func_options_result"; shift
271766ab3337Smrg
2718f7ec340bSmacallan
2719f7ec340bSmacallan
27202a75d1c4Smrg## ----------- ##
27212a75d1c4Smrg##    Main.    ##
27222a75d1c4Smrg## ----------- ##
2723f7ec340bSmacallan
272466ab3337Smrgmagic='%%%MAGIC variable%%%'
272566ab3337Smrgmagic_exe='%%%MAGIC EXE variable%%%'
272666ab3337Smrg
272766ab3337Smrg# Global variables.
272866ab3337Smrgextracted_archives=
272966ab3337Smrgextracted_serial=0
273066ab3337Smrg
273166ab3337Smrg# If this variable is set in any of the actions, the command in it
273266ab3337Smrg# will be execed at the end.  This prevents here-documents from being
273366ab3337Smrg# left over by shells.
273466ab3337Smrgexec_cmd=
273566ab3337Smrg
273666ab3337Smrg
273766ab3337Smrg# A function that is used when there is no print builtin or printf.
273866ab3337Smrgfunc_fallback_echo ()
273966ab3337Smrg{
274066ab3337Smrg  eval 'cat <<_LTECHO_EOF
274166ab3337Smrg$1
274266ab3337Smrg_LTECHO_EOF'
274366ab3337Smrg}
274466ab3337Smrg
274566ab3337Smrg# func_generated_by_libtool
274666ab3337Smrg# True iff stdin has been generated by Libtool. This function is only
274766ab3337Smrg# a basic sanity check; it will hardly flush out determined imposters.
274866ab3337Smrgfunc_generated_by_libtool_p ()
274966ab3337Smrg{
275066ab3337Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
275166ab3337Smrg}
275266ab3337Smrg
27532a75d1c4Smrg# func_lalib_p file
275466ab3337Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27552a75d1c4Smrg# This function is only a basic sanity check; it will hardly flush out
27562a75d1c4Smrg# determined imposters.
27572a75d1c4Smrgfunc_lalib_p ()
27582a75d1c4Smrg{
27592a75d1c4Smrg    test -f "$1" &&
276066ab3337Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
27612a75d1c4Smrg}
2762f7ec340bSmacallan
27632a75d1c4Smrg# func_lalib_unsafe_p file
276466ab3337Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27652a75d1c4Smrg# This function implements the same check as func_lalib_p without
27662a75d1c4Smrg# resorting to external programs.  To this end, it redirects stdin and
27672a75d1c4Smrg# closes it afterwards, without saving the original file descriptor.
27682a75d1c4Smrg# As a safety measure, use it only where a negative result would be
276966ab3337Smrg# fatal anyway.  Works if 'file' does not exist.
27702a75d1c4Smrgfunc_lalib_unsafe_p ()
27712a75d1c4Smrg{
27722a75d1c4Smrg    lalib_p=no
27732a75d1c4Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
27742a75d1c4Smrg	for lalib_p_l in 1 2 3 4
27752a75d1c4Smrg	do
27762a75d1c4Smrg	    read lalib_p_line
277766ab3337Smrg	    case $lalib_p_line in
27782a75d1c4Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
27792a75d1c4Smrg	    esac
27802a75d1c4Smrg	done
27812a75d1c4Smrg	exec 0<&5 5<&-
27822a75d1c4Smrg    fi
278366ab3337Smrg    test yes = "$lalib_p"
27842a75d1c4Smrg}
2785f7ec340bSmacallan
27862a75d1c4Smrg# func_ltwrapper_script_p file
27872a75d1c4Smrg# True iff FILE is a libtool wrapper script
27882a75d1c4Smrg# This function is only a basic sanity check; it will hardly flush out
27892a75d1c4Smrg# determined imposters.
27902a75d1c4Smrgfunc_ltwrapper_script_p ()
27912a75d1c4Smrg{
279266ab3337Smrg    test -f "$1" &&
279366ab3337Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
27942a75d1c4Smrg}
2795f7ec340bSmacallan
27962a75d1c4Smrg# func_ltwrapper_executable_p file
27972a75d1c4Smrg# True iff FILE is a libtool wrapper executable
27982a75d1c4Smrg# This function is only a basic sanity check; it will hardly flush out
27992a75d1c4Smrg# determined imposters.
28002a75d1c4Smrgfunc_ltwrapper_executable_p ()
28012a75d1c4Smrg{
28022a75d1c4Smrg    func_ltwrapper_exec_suffix=
28032a75d1c4Smrg    case $1 in
28042a75d1c4Smrg    *.exe) ;;
28052a75d1c4Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2806f7ec340bSmacallan    esac
28072a75d1c4Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
28082a75d1c4Smrg}
2809f7ec340bSmacallan
28102a75d1c4Smrg# func_ltwrapper_scriptname file
28112a75d1c4Smrg# Assumes file is an ltwrapper_executable
28122a75d1c4Smrg# uses $file to determine the appropriate filename for a
28132a75d1c4Smrg# temporary ltwrapper_script.
28142a75d1c4Smrgfunc_ltwrapper_scriptname ()
28152a75d1c4Smrg{
28162a75d1c4Smrg    func_dirname_and_basename "$1" "" "."
28172a75d1c4Smrg    func_stripname '' '.exe' "$func_basename_result"
281866ab3337Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
28192a75d1c4Smrg}
2820f7ec340bSmacallan
28212a75d1c4Smrg# func_ltwrapper_p file
28222a75d1c4Smrg# True iff FILE is a libtool wrapper script or wrapper executable
28232a75d1c4Smrg# This function is only a basic sanity check; it will hardly flush out
28242a75d1c4Smrg# determined imposters.
28252a75d1c4Smrgfunc_ltwrapper_p ()
28262a75d1c4Smrg{
28272a75d1c4Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
28282a75d1c4Smrg}
2829f7ec340bSmacallan
2830f7ec340bSmacallan
28312a75d1c4Smrg# func_execute_cmds commands fail_cmd
28322a75d1c4Smrg# Execute tilde-delimited COMMANDS.
28332a75d1c4Smrg# If FAIL_CMD is given, eval that upon failure.
28342a75d1c4Smrg# FAIL_CMD may read-access the current command in variable CMD!
28352a75d1c4Smrgfunc_execute_cmds ()
28362a75d1c4Smrg{
283766ab3337Smrg    $debug_cmd
283866ab3337Smrg
28392a75d1c4Smrg    save_ifs=$IFS; IFS='~'
28402a75d1c4Smrg    for cmd in $1; do
284166ab3337Smrg      IFS=$sp$nl
28422a75d1c4Smrg      eval cmd=\"$cmd\"
284366ab3337Smrg      IFS=$save_ifs
28442a75d1c4Smrg      func_show_eval "$cmd" "${2-:}"
2845f7ec340bSmacallan    done
28462a75d1c4Smrg    IFS=$save_ifs
28472a75d1c4Smrg}
2848f7ec340bSmacallan
2849f7ec340bSmacallan
28502a75d1c4Smrg# func_source file
28512a75d1c4Smrg# Source FILE, adding directory component if necessary.
28522a75d1c4Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
28532a75d1c4Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
28542a75d1c4Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
285566ab3337Smrg# 'FILE.' does not work on cygwin managed mounts.
28562a75d1c4Smrgfunc_source ()
28572a75d1c4Smrg{
285866ab3337Smrg    $debug_cmd
285966ab3337Smrg
28602a75d1c4Smrg    case $1 in
28612a75d1c4Smrg    */* | *\\*)	. "$1" ;;
28622a75d1c4Smrg    *)		. "./$1" ;;
28632a75d1c4Smrg    esac
28642a75d1c4Smrg}
2865f7ec340bSmacallan
2866f7ec340bSmacallan
28672a75d1c4Smrg# func_resolve_sysroot PATH
28682a75d1c4Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
28692a75d1c4Smrg# func_resolve_sysroot_result
28702a75d1c4Smrgfunc_resolve_sysroot ()
28712a75d1c4Smrg{
28722a75d1c4Smrg  func_resolve_sysroot_result=$1
28732a75d1c4Smrg  case $func_resolve_sysroot_result in
28742a75d1c4Smrg  =*)
28752a75d1c4Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
28762a75d1c4Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
28772a75d1c4Smrg    ;;
28782a75d1c4Smrg  esac
28792a75d1c4Smrg}
2880f7ec340bSmacallan
28812a75d1c4Smrg# func_replace_sysroot PATH
28822a75d1c4Smrg# If PATH begins with the sysroot, replace it with = and
28832a75d1c4Smrg# store the result into func_replace_sysroot_result.
28842a75d1c4Smrgfunc_replace_sysroot ()
28852a75d1c4Smrg{
288666ab3337Smrg  case $lt_sysroot:$1 in
28872a75d1c4Smrg  ?*:"$lt_sysroot"*)
28882a75d1c4Smrg    func_stripname "$lt_sysroot" '' "$1"
288966ab3337Smrg    func_replace_sysroot_result='='$func_stripname_result
28902a75d1c4Smrg    ;;
28912a75d1c4Smrg  *)
28922a75d1c4Smrg    # Including no sysroot.
28932a75d1c4Smrg    func_replace_sysroot_result=$1
28942a75d1c4Smrg    ;;
28952a75d1c4Smrg  esac
28962a75d1c4Smrg}
2897f7ec340bSmacallan
28982a75d1c4Smrg# func_infer_tag arg
28992a75d1c4Smrg# Infer tagged configuration to use if any are available and
29002a75d1c4Smrg# if one wasn't chosen via the "--tag" command line option.
29012a75d1c4Smrg# Only attempt this if the compiler in the base compile
29022a75d1c4Smrg# command doesn't match the default compiler.
29032a75d1c4Smrg# arg is usually of the form 'gcc ...'
29042a75d1c4Smrgfunc_infer_tag ()
29052a75d1c4Smrg{
290666ab3337Smrg    $debug_cmd
290766ab3337Smrg
29082a75d1c4Smrg    if test -n "$available_tags" && test -z "$tagname"; then
29092a75d1c4Smrg      CC_quoted=
29102a75d1c4Smrg      for arg in $CC; do
29112a75d1c4Smrg	func_append_quoted CC_quoted "$arg"
29122a75d1c4Smrg      done
29132a75d1c4Smrg      CC_expanded=`func_echo_all $CC`
29142a75d1c4Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
29152a75d1c4Smrg      case $@ in
29162a75d1c4Smrg      # Blanks in the command may have been stripped by the calling shell,
29172a75d1c4Smrg      # but not from the CC environment variable when configure was run.
29182a75d1c4Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29192a75d1c4Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
29202a75d1c4Smrg      # Blanks at the start of $base_compile will cause this to fail
29212a75d1c4Smrg      # if we don't check for them as well.
29222a75d1c4Smrg      *)
29232a75d1c4Smrg	for z in $available_tags; do
29242a75d1c4Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
29252a75d1c4Smrg	    # Evaluate the configuration.
292666ab3337Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
29272a75d1c4Smrg	    CC_quoted=
29282a75d1c4Smrg	    for arg in $CC; do
29292a75d1c4Smrg	      # Double-quote args containing other shell metacharacters.
29302a75d1c4Smrg	      func_append_quoted CC_quoted "$arg"
29312a75d1c4Smrg	    done
29322a75d1c4Smrg	    CC_expanded=`func_echo_all $CC`
29332a75d1c4Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
29342a75d1c4Smrg	    case "$@ " in
29352a75d1c4Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29362a75d1c4Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
29372a75d1c4Smrg	      # The compiler in the base compile command matches
29382a75d1c4Smrg	      # the one in the tagged configuration.
29392a75d1c4Smrg	      # Assume this is the tagged configuration we want.
29402a75d1c4Smrg	      tagname=$z
29412a75d1c4Smrg	      break
29422a75d1c4Smrg	      ;;
29432a75d1c4Smrg	    esac
29442a75d1c4Smrg	  fi
29452a75d1c4Smrg	done
29462a75d1c4Smrg	# If $tagname still isn't set, then no tagged configuration
29472a75d1c4Smrg	# was found and let the user know that the "--tag" command
29482a75d1c4Smrg	# line option must be used.
29492a75d1c4Smrg	if test -z "$tagname"; then
29502a75d1c4Smrg	  func_echo "unable to infer tagged configuration"
295166ab3337Smrg	  func_fatal_error "specify a tag with '--tag'"
29522a75d1c4Smrg#	else
29532a75d1c4Smrg#	  func_verbose "using $tagname tagged configuration"
29542a75d1c4Smrg	fi
29552a75d1c4Smrg	;;
29562a75d1c4Smrg      esac
2957f7ec340bSmacallan    fi
29582a75d1c4Smrg}
2959f7ec340bSmacallan
2960f7ec340bSmacallan
2961f7ec340bSmacallan
29622a75d1c4Smrg# func_write_libtool_object output_name pic_name nonpic_name
29632a75d1c4Smrg# Create a libtool object file (analogous to a ".la" file),
29642a75d1c4Smrg# but don't create it if we're doing a dry run.
29652a75d1c4Smrgfunc_write_libtool_object ()
29662a75d1c4Smrg{
296766ab3337Smrg    write_libobj=$1
296866ab3337Smrg    if test yes = "$build_libtool_libs"; then
296966ab3337Smrg      write_lobj=\'$2\'
29702a75d1c4Smrg    else
29712a75d1c4Smrg      write_lobj=none
2972f7ec340bSmacallan    fi
2973f7ec340bSmacallan
297466ab3337Smrg    if test yes = "$build_old_libs"; then
297566ab3337Smrg      write_oldobj=\'$3\'
29762a75d1c4Smrg    else
29772a75d1c4Smrg      write_oldobj=none
2978f7ec340bSmacallan    fi
2979f7ec340bSmacallan
29802a75d1c4Smrg    $opt_dry_run || {
29812a75d1c4Smrg      cat >${write_libobj}T <<EOF
29822a75d1c4Smrg# $write_libobj - a libtool object file
298366ab3337Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984f7ec340bSmacallan#
2985f7ec340bSmacallan# Please DO NOT delete this file!
2986f7ec340bSmacallan# It is necessary for linking the library.
2987f7ec340bSmacallan
2988f7ec340bSmacallan# Name of the PIC object.
29892a75d1c4Smrgpic_object=$write_lobj
2990f7ec340bSmacallan
29912a75d1c4Smrg# Name of the non-PIC object
29922a75d1c4Smrgnon_pic_object=$write_oldobj
2993f7ec340bSmacallan
29942a75d1c4SmrgEOF
299566ab3337Smrg      $MV "${write_libobj}T" "$write_libobj"
29962a75d1c4Smrg    }
29972a75d1c4Smrg}
2998f7ec340bSmacallan
2999f7ec340bSmacallan
30002a75d1c4Smrg##################################################
30012a75d1c4Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
30022a75d1c4Smrg##################################################
3003f7ec340bSmacallan
30042a75d1c4Smrg# func_convert_core_file_wine_to_w32 ARG
30052a75d1c4Smrg# Helper function used by file name conversion functions when $build is *nix,
30062a75d1c4Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
30072a75d1c4Smrg# correctly configured wine environment available, with the winepath program
30082a75d1c4Smrg# in $build's $PATH.
30092a75d1c4Smrg#
30102a75d1c4Smrg# ARG is the $build file name to be converted to w32 format.
30112a75d1c4Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
30122a75d1c4Smrg# be empty on error (or when ARG is empty)
30132a75d1c4Smrgfunc_convert_core_file_wine_to_w32 ()
30142a75d1c4Smrg{
301566ab3337Smrg  $debug_cmd
301666ab3337Smrg
301766ab3337Smrg  func_convert_core_file_wine_to_w32_result=$1
30182a75d1c4Smrg  if test -n "$1"; then
30192a75d1c4Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
30202a75d1c4Smrg    # are forced to check the contents of stdout. On the other hand, if the
30212a75d1c4Smrg    # command is not found, the shell will set an exit code of 127 and print
30222a75d1c4Smrg    # *an error message* to stdout. So we must check for both error code of
30232a75d1c4Smrg    # zero AND non-empty stdout, which explains the odd construction:
30242a75d1c4Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
302566ab3337Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
30262a75d1c4Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
302766ab3337Smrg        $SED -e "$sed_naive_backslashify"`
30282a75d1c4Smrg    else
30292a75d1c4Smrg      func_convert_core_file_wine_to_w32_result=
30302a75d1c4Smrg    fi
30312a75d1c4Smrg  fi
30322a75d1c4Smrg}
30332a75d1c4Smrg# end: func_convert_core_file_wine_to_w32
3034f7ec340bSmacallan
30352a75d1c4Smrg
30362a75d1c4Smrg# func_convert_core_path_wine_to_w32 ARG
30372a75d1c4Smrg# Helper function used by path conversion functions when $build is *nix, and
30382a75d1c4Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
30392a75d1c4Smrg# configured wine environment available, with the winepath program in $build's
30402a75d1c4Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
30412a75d1c4Smrg#
30422a75d1c4Smrg# ARG is path to be converted from $build format to win32.
30432a75d1c4Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
30442a75d1c4Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
30452a75d1c4Smrg# are convertible, then the result may be empty.
30462a75d1c4Smrgfunc_convert_core_path_wine_to_w32 ()
30472a75d1c4Smrg{
304866ab3337Smrg  $debug_cmd
304966ab3337Smrg
30502a75d1c4Smrg  # unfortunately, winepath doesn't convert paths, only file names
305166ab3337Smrg  func_convert_core_path_wine_to_w32_result=
30522a75d1c4Smrg  if test -n "$1"; then
30532a75d1c4Smrg    oldIFS=$IFS
30542a75d1c4Smrg    IFS=:
30552a75d1c4Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
30562a75d1c4Smrg      IFS=$oldIFS
30572a75d1c4Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
305866ab3337Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
30592a75d1c4Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
306066ab3337Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
30612a75d1c4Smrg        else
30622a75d1c4Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
30632a75d1c4Smrg        fi
3064f7ec340bSmacallan      fi
30652a75d1c4Smrg    done
30662a75d1c4Smrg    IFS=$oldIFS
30672a75d1c4Smrg  fi
30682a75d1c4Smrg}
30692a75d1c4Smrg# end: func_convert_core_path_wine_to_w32
30702a75d1c4Smrg
30712a75d1c4Smrg
30722a75d1c4Smrg# func_cygpath ARGS...
30732a75d1c4Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
30742a75d1c4Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
30752a75d1c4Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
30762a75d1c4Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
30772a75d1c4Smrg# file name or path is assumed to be in w32 format, as previously converted
30782a75d1c4Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
30792a75d1c4Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
30802a75d1c4Smrg# Cygwin format). Returns an empty string on error.
30812a75d1c4Smrg#
30822a75d1c4Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
30832a75d1c4Smrg# be converted.
30842a75d1c4Smrg#
30852a75d1c4Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
30862a75d1c4Smrg# environment variable; do not put it in $PATH.
30872a75d1c4Smrgfunc_cygpath ()
30882a75d1c4Smrg{
308966ab3337Smrg  $debug_cmd
309066ab3337Smrg
30912a75d1c4Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
30922a75d1c4Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
30932a75d1c4Smrg    if test "$?" -ne 0; then
30942a75d1c4Smrg      # on failure, ensure result is empty
30952a75d1c4Smrg      func_cygpath_result=
30962a75d1c4Smrg    fi
30972a75d1c4Smrg  else
30982a75d1c4Smrg    func_cygpath_result=
309966ab3337Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
31002a75d1c4Smrg  fi
31012a75d1c4Smrg}
31022a75d1c4Smrg#end: func_cygpath
3103f7ec340bSmacallan
3104f7ec340bSmacallan
31052a75d1c4Smrg# func_convert_core_msys_to_w32 ARG
31062a75d1c4Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
31072a75d1c4Smrg# result in func_convert_core_msys_to_w32_result.
31082a75d1c4Smrgfunc_convert_core_msys_to_w32 ()
31092a75d1c4Smrg{
311066ab3337Smrg  $debug_cmd
311166ab3337Smrg
31122a75d1c4Smrg  # awkward: cmd appends spaces to result
31132a75d1c4Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
311466ab3337Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
31152a75d1c4Smrg}
31162a75d1c4Smrg#end: func_convert_core_msys_to_w32
3117f7ec340bSmacallan
3118f7ec340bSmacallan
31192a75d1c4Smrg# func_convert_file_check ARG1 ARG2
31202a75d1c4Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
31212a75d1c4Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
31222a75d1c4Smrg# func_to_host_file_result to ARG1).
31232a75d1c4Smrgfunc_convert_file_check ()
31242a75d1c4Smrg{
312566ab3337Smrg  $debug_cmd
312666ab3337Smrg
312766ab3337Smrg  if test -z "$2" && test -n "$1"; then
31282a75d1c4Smrg    func_error "Could not determine host file name corresponding to"
312966ab3337Smrg    func_error "  '$1'"
31302a75d1c4Smrg    func_error "Continuing, but uninstalled executables may not work."
31312a75d1c4Smrg    # Fallback:
313266ab3337Smrg    func_to_host_file_result=$1
31332a75d1c4Smrg  fi
31342a75d1c4Smrg}
31352a75d1c4Smrg# end func_convert_file_check
3136f7ec340bSmacallan
3137f7ec340bSmacallan
31382a75d1c4Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
31392a75d1c4Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
31402a75d1c4Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
31412a75d1c4Smrg# func_to_host_file_result to a simplistic fallback value (see below).
31422a75d1c4Smrgfunc_convert_path_check ()
31432a75d1c4Smrg{
314466ab3337Smrg  $debug_cmd
314566ab3337Smrg
31462a75d1c4Smrg  if test -z "$4" && test -n "$3"; then
31472a75d1c4Smrg    func_error "Could not determine the host path corresponding to"
314866ab3337Smrg    func_error "  '$3'"
31492a75d1c4Smrg    func_error "Continuing, but uninstalled executables may not work."
31502a75d1c4Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
31512a75d1c4Smrg    # should not be "improved".  See libtool.info.
31522a75d1c4Smrg    if test "x$1" != "x$2"; then
31532a75d1c4Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
31542a75d1c4Smrg      func_to_host_path_result=`echo "$3" |
31552a75d1c4Smrg        $SED -e "$lt_replace_pathsep_chars"`
31562a75d1c4Smrg    else
315766ab3337Smrg      func_to_host_path_result=$3
31582a75d1c4Smrg    fi
31592a75d1c4Smrg  fi
31602a75d1c4Smrg}
31612a75d1c4Smrg# end func_convert_path_check
3162f7ec340bSmacallan
3163f7ec340bSmacallan
31642a75d1c4Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
31652a75d1c4Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
31662a75d1c4Smrg# and appending REPL if ORIG matches BACKPAT.
31672a75d1c4Smrgfunc_convert_path_front_back_pathsep ()
31682a75d1c4Smrg{
316966ab3337Smrg  $debug_cmd
317066ab3337Smrg
31712a75d1c4Smrg  case $4 in
317266ab3337Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
31732a75d1c4Smrg    ;;
31742a75d1c4Smrg  esac
31752a75d1c4Smrg  case $4 in
31762a75d1c4Smrg  $2 ) func_append func_to_host_path_result "$3"
31772a75d1c4Smrg    ;;
31782a75d1c4Smrg  esac
31792a75d1c4Smrg}
31802a75d1c4Smrg# end func_convert_path_front_back_pathsep
3181f7ec340bSmacallan
3182f7ec340bSmacallan
31832a75d1c4Smrg##################################################
31842a75d1c4Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
31852a75d1c4Smrg##################################################
318666ab3337Smrg# invoked via '$to_host_file_cmd ARG'
31872a75d1c4Smrg#
31882a75d1c4Smrg# In each case, ARG is the path to be converted from $build to $host format.
31892a75d1c4Smrg# Result will be available in $func_to_host_file_result.
3190f7ec340bSmacallan
3191f7ec340bSmacallan
31922a75d1c4Smrg# func_to_host_file ARG
31932a75d1c4Smrg# Converts the file name ARG from $build format to $host format. Return result
31942a75d1c4Smrg# in func_to_host_file_result.
31952a75d1c4Smrgfunc_to_host_file ()
31962a75d1c4Smrg{
319766ab3337Smrg  $debug_cmd
319866ab3337Smrg
31992a75d1c4Smrg  $to_host_file_cmd "$1"
32002a75d1c4Smrg}
32012a75d1c4Smrg# end func_to_host_file
3202f7ec340bSmacallan
3203f7ec340bSmacallan
32042a75d1c4Smrg# func_to_tool_file ARG LAZY
32052a75d1c4Smrg# converts the file name ARG from $build format to toolchain format. Return
32062a75d1c4Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
32072a75d1c4Smrg# in (the comma separated) LAZY, no conversion takes place.
32082a75d1c4Smrgfunc_to_tool_file ()
32092a75d1c4Smrg{
321066ab3337Smrg  $debug_cmd
321166ab3337Smrg
32122a75d1c4Smrg  case ,$2, in
32132a75d1c4Smrg    *,"$to_tool_file_cmd",*)
32142a75d1c4Smrg      func_to_tool_file_result=$1
32152a75d1c4Smrg      ;;
32162a75d1c4Smrg    *)
32172a75d1c4Smrg      $to_tool_file_cmd "$1"
32182a75d1c4Smrg      func_to_tool_file_result=$func_to_host_file_result
32192a75d1c4Smrg      ;;
32202a75d1c4Smrg  esac
32212a75d1c4Smrg}
32222a75d1c4Smrg# end func_to_tool_file
3223f7ec340bSmacallan
3224f7ec340bSmacallan
32252a75d1c4Smrg# func_convert_file_noop ARG
32262a75d1c4Smrg# Copy ARG to func_to_host_file_result.
32272a75d1c4Smrgfunc_convert_file_noop ()
32282a75d1c4Smrg{
322966ab3337Smrg  func_to_host_file_result=$1
32302a75d1c4Smrg}
32312a75d1c4Smrg# end func_convert_file_noop
3232f7ec340bSmacallan
3233f7ec340bSmacallan
32342a75d1c4Smrg# func_convert_file_msys_to_w32 ARG
32352a75d1c4Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
32362a75d1c4Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
32372a75d1c4Smrg# func_to_host_file_result.
32382a75d1c4Smrgfunc_convert_file_msys_to_w32 ()
32392a75d1c4Smrg{
324066ab3337Smrg  $debug_cmd
324166ab3337Smrg
324266ab3337Smrg  func_to_host_file_result=$1
32432a75d1c4Smrg  if test -n "$1"; then
32442a75d1c4Smrg    func_convert_core_msys_to_w32 "$1"
324566ab3337Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
32462a75d1c4Smrg  fi
32472a75d1c4Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32482a75d1c4Smrg}
32492a75d1c4Smrg# end func_convert_file_msys_to_w32
3250f7ec340bSmacallan
3251f7ec340bSmacallan
32522a75d1c4Smrg# func_convert_file_cygwin_to_w32 ARG
32532a75d1c4Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
32542a75d1c4Smrg# func_to_host_file_result.
32552a75d1c4Smrgfunc_convert_file_cygwin_to_w32 ()
32562a75d1c4Smrg{
325766ab3337Smrg  $debug_cmd
325866ab3337Smrg
325966ab3337Smrg  func_to_host_file_result=$1
32602a75d1c4Smrg  if test -n "$1"; then
32612a75d1c4Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
32622a75d1c4Smrg    # LT_CYGPATH in this case.
32632a75d1c4Smrg    func_to_host_file_result=`cygpath -m "$1"`
32642a75d1c4Smrg  fi
32652a75d1c4Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32662a75d1c4Smrg}
32672a75d1c4Smrg# end func_convert_file_cygwin_to_w32
3268f7ec340bSmacallan
3269f7ec340bSmacallan
32702a75d1c4Smrg# func_convert_file_nix_to_w32 ARG
32712a75d1c4Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
32722a75d1c4Smrg# and a working winepath. Returns result in func_to_host_file_result.
32732a75d1c4Smrgfunc_convert_file_nix_to_w32 ()
32742a75d1c4Smrg{
327566ab3337Smrg  $debug_cmd
327666ab3337Smrg
327766ab3337Smrg  func_to_host_file_result=$1
32782a75d1c4Smrg  if test -n "$1"; then
32792a75d1c4Smrg    func_convert_core_file_wine_to_w32 "$1"
328066ab3337Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
32812a75d1c4Smrg  fi
32822a75d1c4Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
32832a75d1c4Smrg}
32842a75d1c4Smrg# end func_convert_file_nix_to_w32
3285f7ec340bSmacallan
3286f7ec340bSmacallan
32872a75d1c4Smrg# func_convert_file_msys_to_cygwin ARG
32882a75d1c4Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32892a75d1c4Smrg# Returns result in func_to_host_file_result.
32902a75d1c4Smrgfunc_convert_file_msys_to_cygwin ()
32912a75d1c4Smrg{
329266ab3337Smrg  $debug_cmd
329366ab3337Smrg
329466ab3337Smrg  func_to_host_file_result=$1
32952a75d1c4Smrg  if test -n "$1"; then
32962a75d1c4Smrg    func_convert_core_msys_to_w32 "$1"
32972a75d1c4Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
329866ab3337Smrg    func_to_host_file_result=$func_cygpath_result
32992a75d1c4Smrg  fi
33002a75d1c4Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33012a75d1c4Smrg}
33022a75d1c4Smrg# end func_convert_file_msys_to_cygwin
3303f7ec340bSmacallan
3304f7ec340bSmacallan
33052a75d1c4Smrg# func_convert_file_nix_to_cygwin ARG
33062a75d1c4Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
33072a75d1c4Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
33082a75d1c4Smrg# in func_to_host_file_result.
33092a75d1c4Smrgfunc_convert_file_nix_to_cygwin ()
33102a75d1c4Smrg{
331166ab3337Smrg  $debug_cmd
331266ab3337Smrg
331366ab3337Smrg  func_to_host_file_result=$1
33142a75d1c4Smrg  if test -n "$1"; then
33152a75d1c4Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
33162a75d1c4Smrg    func_convert_core_file_wine_to_w32 "$1"
33172a75d1c4Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
331866ab3337Smrg    func_to_host_file_result=$func_cygpath_result
33192a75d1c4Smrg  fi
33202a75d1c4Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33212a75d1c4Smrg}
33222a75d1c4Smrg# end func_convert_file_nix_to_cygwin
3323f7ec340bSmacallan
3324f7ec340bSmacallan
33252a75d1c4Smrg#############################################
33262a75d1c4Smrg# $build to $host PATH CONVERSION FUNCTIONS #
33272a75d1c4Smrg#############################################
332866ab3337Smrg# invoked via '$to_host_path_cmd ARG'
33292a75d1c4Smrg#
33302a75d1c4Smrg# In each case, ARG is the path to be converted from $build to $host format.
33312a75d1c4Smrg# The result will be available in $func_to_host_path_result.
33322a75d1c4Smrg#
33332a75d1c4Smrg# Path separators are also converted from $build format to $host format.  If
33342a75d1c4Smrg# ARG begins or ends with a path separator character, it is preserved (but
33352a75d1c4Smrg# converted to $host format) on output.
33362a75d1c4Smrg#
33372a75d1c4Smrg# All path conversion functions are named using the following convention:
33382a75d1c4Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
33392a75d1c4Smrg#   path conversion function         : func_convert_path_X_to_Y ()
33402a75d1c4Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
33412a75d1c4Smrg# same.  If conversion functions are added for new $build/$host combinations,
33422a75d1c4Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
33432a75d1c4Smrg# will break.
33442a75d1c4Smrg
33452a75d1c4Smrg
33462a75d1c4Smrg# func_init_to_host_path_cmd
33472a75d1c4Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
33482a75d1c4Smrg# appropriate value, based on the value of $to_host_file_cmd.
33492a75d1c4Smrgto_host_path_cmd=
33502a75d1c4Smrgfunc_init_to_host_path_cmd ()
33512a75d1c4Smrg{
335266ab3337Smrg  $debug_cmd
335366ab3337Smrg
33542a75d1c4Smrg  if test -z "$to_host_path_cmd"; then
33552a75d1c4Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
335666ab3337Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
33572a75d1c4Smrg  fi
33582a75d1c4Smrg}
3359f7ec340bSmacallan
3360f7ec340bSmacallan
33612a75d1c4Smrg# func_to_host_path ARG
33622a75d1c4Smrg# Converts the path ARG from $build format to $host format. Return result
33632a75d1c4Smrg# in func_to_host_path_result.
33642a75d1c4Smrgfunc_to_host_path ()
33652a75d1c4Smrg{
336666ab3337Smrg  $debug_cmd
336766ab3337Smrg
33682a75d1c4Smrg  func_init_to_host_path_cmd
33692a75d1c4Smrg  $to_host_path_cmd "$1"
33702a75d1c4Smrg}
33712a75d1c4Smrg# end func_to_host_path
3372f7ec340bSmacallan
3373f7ec340bSmacallan
33742a75d1c4Smrg# func_convert_path_noop ARG
33752a75d1c4Smrg# Copy ARG to func_to_host_path_result.
33762a75d1c4Smrgfunc_convert_path_noop ()
33772a75d1c4Smrg{
337866ab3337Smrg  func_to_host_path_result=$1
33792a75d1c4Smrg}
33802a75d1c4Smrg# end func_convert_path_noop
3381f7ec340bSmacallan
3382f7ec340bSmacallan
33832a75d1c4Smrg# func_convert_path_msys_to_w32 ARG
33842a75d1c4Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
33852a75d1c4Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
33862a75d1c4Smrg# func_to_host_path_result.
33872a75d1c4Smrgfunc_convert_path_msys_to_w32 ()
33882a75d1c4Smrg{
338966ab3337Smrg  $debug_cmd
339066ab3337Smrg
339166ab3337Smrg  func_to_host_path_result=$1
33922a75d1c4Smrg  if test -n "$1"; then
33932a75d1c4Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
33942a75d1c4Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
33952a75d1c4Smrg    # and winepath ignores them completely.
33962a75d1c4Smrg    func_stripname : : "$1"
33972a75d1c4Smrg    func_to_host_path_tmp1=$func_stripname_result
33982a75d1c4Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
339966ab3337Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
34002a75d1c4Smrg    func_convert_path_check : ";" \
34012a75d1c4Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34022a75d1c4Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34032a75d1c4Smrg  fi
34042a75d1c4Smrg}
34052a75d1c4Smrg# end func_convert_path_msys_to_w32
3406f7ec340bSmacallan
3407f7ec340bSmacallan
34082a75d1c4Smrg# func_convert_path_cygwin_to_w32 ARG
34092a75d1c4Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
34102a75d1c4Smrg# func_to_host_file_result.
34112a75d1c4Smrgfunc_convert_path_cygwin_to_w32 ()
34122a75d1c4Smrg{
341366ab3337Smrg  $debug_cmd
341466ab3337Smrg
341566ab3337Smrg  func_to_host_path_result=$1
34162a75d1c4Smrg  if test -n "$1"; then
34172a75d1c4Smrg    # See func_convert_path_msys_to_w32:
34182a75d1c4Smrg    func_stripname : : "$1"
34192a75d1c4Smrg    func_to_host_path_tmp1=$func_stripname_result
34202a75d1c4Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
34212a75d1c4Smrg    func_convert_path_check : ";" \
34222a75d1c4Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34232a75d1c4Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34242a75d1c4Smrg  fi
34252a75d1c4Smrg}
34262a75d1c4Smrg# end func_convert_path_cygwin_to_w32
3427f7ec340bSmacallan
3428f7ec340bSmacallan
34292a75d1c4Smrg# func_convert_path_nix_to_w32 ARG
34302a75d1c4Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
34312a75d1c4Smrg# a working winepath.  Returns result in func_to_host_file_result.
34322a75d1c4Smrgfunc_convert_path_nix_to_w32 ()
34332a75d1c4Smrg{
343466ab3337Smrg  $debug_cmd
343566ab3337Smrg
343666ab3337Smrg  func_to_host_path_result=$1
34372a75d1c4Smrg  if test -n "$1"; then
34382a75d1c4Smrg    # See func_convert_path_msys_to_w32:
34392a75d1c4Smrg    func_stripname : : "$1"
34402a75d1c4Smrg    func_to_host_path_tmp1=$func_stripname_result
34412a75d1c4Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
344266ab3337Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
34432a75d1c4Smrg    func_convert_path_check : ";" \
34442a75d1c4Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34452a75d1c4Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34462a75d1c4Smrg  fi
34472a75d1c4Smrg}
34482a75d1c4Smrg# end func_convert_path_nix_to_w32
3449f7ec340bSmacallan
3450f7ec340bSmacallan
34512a75d1c4Smrg# func_convert_path_msys_to_cygwin ARG
34522a75d1c4Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
34532a75d1c4Smrg# Returns result in func_to_host_file_result.
34542a75d1c4Smrgfunc_convert_path_msys_to_cygwin ()
34552a75d1c4Smrg{
345666ab3337Smrg  $debug_cmd
345766ab3337Smrg
345866ab3337Smrg  func_to_host_path_result=$1
34592a75d1c4Smrg  if test -n "$1"; then
34602a75d1c4Smrg    # See func_convert_path_msys_to_w32:
34612a75d1c4Smrg    func_stripname : : "$1"
34622a75d1c4Smrg    func_to_host_path_tmp1=$func_stripname_result
34632a75d1c4Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
34642a75d1c4Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
346566ab3337Smrg    func_to_host_path_result=$func_cygpath_result
34662a75d1c4Smrg    func_convert_path_check : : \
34672a75d1c4Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34682a75d1c4Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34692a75d1c4Smrg  fi
34702a75d1c4Smrg}
34712a75d1c4Smrg# end func_convert_path_msys_to_cygwin
3472f7ec340bSmacallan
3473f7ec340bSmacallan
34742a75d1c4Smrg# func_convert_path_nix_to_cygwin ARG
34752a75d1c4Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
34762a75d1c4Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
34772a75d1c4Smrg# func_to_host_file_result.
34782a75d1c4Smrgfunc_convert_path_nix_to_cygwin ()
34792a75d1c4Smrg{
348066ab3337Smrg  $debug_cmd
348166ab3337Smrg
348266ab3337Smrg  func_to_host_path_result=$1
34832a75d1c4Smrg  if test -n "$1"; then
34842a75d1c4Smrg    # Remove leading and trailing path separator characters from
34852a75d1c4Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
34862a75d1c4Smrg    # into '.;' and ';.', and winepath ignores them completely.
34872a75d1c4Smrg    func_stripname : : "$1"
34882a75d1c4Smrg    func_to_host_path_tmp1=$func_stripname_result
34892a75d1c4Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34902a75d1c4Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
349166ab3337Smrg    func_to_host_path_result=$func_cygpath_result
34922a75d1c4Smrg    func_convert_path_check : : \
34932a75d1c4Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34942a75d1c4Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
34952a75d1c4Smrg  fi
34962a75d1c4Smrg}
34972a75d1c4Smrg# end func_convert_path_nix_to_cygwin
3498f7ec340bSmacallan
3499f7ec340bSmacallan
350066ab3337Smrg# func_dll_def_p FILE
350166ab3337Smrg# True iff FILE is a Windows DLL '.def' file.
350266ab3337Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
350366ab3337Smrgfunc_dll_def_p ()
350466ab3337Smrg{
350566ab3337Smrg  $debug_cmd
350666ab3337Smrg
350766ab3337Smrg  func_dll_def_p_tmp=`$SED -n \
350866ab3337Smrg    -e 's/^[	 ]*//' \
350966ab3337Smrg    -e '/^\(;.*\)*$/d' \
351066ab3337Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
351166ab3337Smrg    -e q \
351266ab3337Smrg    "$1"`
351366ab3337Smrg  test DEF = "$func_dll_def_p_tmp"
351466ab3337Smrg}
351566ab3337Smrg
351666ab3337Smrg
35172a75d1c4Smrg# func_mode_compile arg...
35182a75d1c4Smrgfunc_mode_compile ()
35192a75d1c4Smrg{
352066ab3337Smrg    $debug_cmd
352166ab3337Smrg
35222a75d1c4Smrg    # Get the compilation command and the source file.
35232a75d1c4Smrg    base_compile=
352466ab3337Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
35252a75d1c4Smrg    suppress_opt=yes
35262a75d1c4Smrg    suppress_output=
35272a75d1c4Smrg    arg_mode=normal
35282a75d1c4Smrg    libobj=
35292a75d1c4Smrg    later=
35302a75d1c4Smrg    pie_flag=
35312a75d1c4Smrg
35322a75d1c4Smrg    for arg
35332a75d1c4Smrg    do
35342a75d1c4Smrg      case $arg_mode in
35352a75d1c4Smrg      arg  )
35362a75d1c4Smrg	# do not "continue".  Instead, add this to base_compile
353766ab3337Smrg	lastarg=$arg
35382a75d1c4Smrg	arg_mode=normal
35392a75d1c4Smrg	;;
35402a75d1c4Smrg
35412a75d1c4Smrg      target )
354266ab3337Smrg	libobj=$arg
35432a75d1c4Smrg	arg_mode=normal
35442a75d1c4Smrg	continue
35452a75d1c4Smrg	;;
35462a75d1c4Smrg
35472a75d1c4Smrg      normal )
35482a75d1c4Smrg	# Accept any command-line options.
35492a75d1c4Smrg	case $arg in
35502a75d1c4Smrg	-o)
35512a75d1c4Smrg	  test -n "$libobj" && \
355266ab3337Smrg	    func_fatal_error "you cannot specify '-o' more than once"
35532a75d1c4Smrg	  arg_mode=target
3554f7ec340bSmacallan	  continue
3555f7ec340bSmacallan	  ;;
35562a75d1c4Smrg
35572a75d1c4Smrg	-pie | -fpie | -fPIE)
35582a75d1c4Smrg          func_append pie_flag " $arg"
3559f7ec340bSmacallan	  continue
3560f7ec340bSmacallan	  ;;
35612a75d1c4Smrg
35622a75d1c4Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
35632a75d1c4Smrg	  func_append later " $arg"
3564f7ec340bSmacallan	  continue
3565f7ec340bSmacallan	  ;;
35662a75d1c4Smrg
35672a75d1c4Smrg	-no-suppress)
35682a75d1c4Smrg	  suppress_opt=no
3569f7ec340bSmacallan	  continue
3570f7ec340bSmacallan	  ;;
3571f7ec340bSmacallan
35722a75d1c4Smrg	-Xcompiler)
35732a75d1c4Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
35742a75d1c4Smrg	  continue      #  The current "srcfile" will either be retained or
35752a75d1c4Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576f7ec340bSmacallan
35772a75d1c4Smrg	-Wc,*)
35782a75d1c4Smrg	  func_stripname '-Wc,' '' "$arg"
35792a75d1c4Smrg	  args=$func_stripname_result
35802a75d1c4Smrg	  lastarg=
358166ab3337Smrg	  save_ifs=$IFS; IFS=,
35822a75d1c4Smrg	  for arg in $args; do
358366ab3337Smrg	    IFS=$save_ifs
35842a75d1c4Smrg	    func_append_quoted lastarg "$arg"
35852a75d1c4Smrg	  done
358666ab3337Smrg	  IFS=$save_ifs
35872a75d1c4Smrg	  func_stripname ' ' '' "$lastarg"
35882a75d1c4Smrg	  lastarg=$func_stripname_result
3589f7ec340bSmacallan
35902a75d1c4Smrg	  # Add the arguments to base_compile.
35912a75d1c4Smrg	  func_append base_compile " $lastarg"
35922a75d1c4Smrg	  continue
35932a75d1c4Smrg	  ;;
3594f7ec340bSmacallan
35952a75d1c4Smrg	*)
35962a75d1c4Smrg	  # Accept the current argument as the source file.
35972a75d1c4Smrg	  # The previous "srcfile" becomes the current argument.
35982a75d1c4Smrg	  #
359966ab3337Smrg	  lastarg=$srcfile
360066ab3337Smrg	  srcfile=$arg
36012a75d1c4Smrg	  ;;
36022a75d1c4Smrg	esac  #  case $arg
3603f7ec340bSmacallan	;;
36042a75d1c4Smrg      esac    #  case $arg_mode
3605f7ec340bSmacallan
36062a75d1c4Smrg      # Aesthetically quote the previous argument.
36072a75d1c4Smrg      func_append_quoted base_compile "$lastarg"
36082a75d1c4Smrg    done # for arg
3609f7ec340bSmacallan
36102a75d1c4Smrg    case $arg_mode in
36112a75d1c4Smrg    arg)
36122a75d1c4Smrg      func_fatal_error "you must specify an argument for -Xcompile"
36132a75d1c4Smrg      ;;
36142a75d1c4Smrg    target)
361566ab3337Smrg      func_fatal_error "you must specify a target with '-o'"
36162a75d1c4Smrg      ;;
36172a75d1c4Smrg    *)
36182a75d1c4Smrg      # Get the name of the library object.
36192a75d1c4Smrg      test -z "$libobj" && {
36202a75d1c4Smrg	func_basename "$srcfile"
362166ab3337Smrg	libobj=$func_basename_result
36222a75d1c4Smrg      }
36232a75d1c4Smrg      ;;
36242a75d1c4Smrg    esac
3625f7ec340bSmacallan
36262a75d1c4Smrg    # Recognize several different file suffixes.
36272a75d1c4Smrg    # If the user specifies -o file.o, it is replaced with file.lo
36282a75d1c4Smrg    case $libobj in
36292a75d1c4Smrg    *.[cCFSifmso] | \
36302a75d1c4Smrg    *.ada | *.adb | *.ads | *.asm | \
36312a75d1c4Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
363266ab3337Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
36332a75d1c4Smrg      func_xform "$libobj"
36342a75d1c4Smrg      libobj=$func_xform_result
36352a75d1c4Smrg      ;;
36362a75d1c4Smrg    esac
3637f7ec340bSmacallan
36382a75d1c4Smrg    case $libobj in
36392a75d1c4Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
36402a75d1c4Smrg    *)
364166ab3337Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
36422a75d1c4Smrg      ;;
36432a75d1c4Smrg    esac
3644f7ec340bSmacallan
36452a75d1c4Smrg    func_infer_tag $base_compile
3646f7ec340bSmacallan
36472a75d1c4Smrg    for arg in $later; do
36482a75d1c4Smrg      case $arg in
36492a75d1c4Smrg      -shared)
365066ab3337Smrg	test yes = "$build_libtool_libs" \
365166ab3337Smrg	  || func_fatal_configuration "cannot build a shared library"
36522a75d1c4Smrg	build_old_libs=no
3653f7ec340bSmacallan	continue
3654f7ec340bSmacallan	;;
3655f7ec340bSmacallan
36562a75d1c4Smrg      -static)
36572a75d1c4Smrg	build_libtool_libs=no
36582a75d1c4Smrg	build_old_libs=yes
3659f7ec340bSmacallan	continue
3660f7ec340bSmacallan	;;
3661f7ec340bSmacallan
36622a75d1c4Smrg      -prefer-pic)
36632a75d1c4Smrg	pic_mode=yes
3664f7ec340bSmacallan	continue
3665f7ec340bSmacallan	;;
3666f7ec340bSmacallan
36672a75d1c4Smrg      -prefer-non-pic)
36682a75d1c4Smrg	pic_mode=no
3669f7ec340bSmacallan	continue
3670f7ec340bSmacallan	;;
36712a75d1c4Smrg      esac
36722a75d1c4Smrg    done
3673f7ec340bSmacallan
367466ab3337Smrg    func_quote_arg pretty "$libobj"
367566ab3337Smrg    test "X$libobj" != "X$func_quote_arg_result" \
36762a75d1c4Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
367766ab3337Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
36782a75d1c4Smrg    func_dirname_and_basename "$obj" "/" ""
367966ab3337Smrg    objname=$func_basename_result
368066ab3337Smrg    xdir=$func_dirname_result
368166ab3337Smrg    lobj=$xdir$objdir/$objname
3682f7ec340bSmacallan
36832a75d1c4Smrg    test -z "$base_compile" && \
36842a75d1c4Smrg      func_fatal_help "you must specify a compilation command"
3685f7ec340bSmacallan
36862a75d1c4Smrg    # Delete any leftover library objects.
368766ab3337Smrg    if test yes = "$build_old_libs"; then
36882a75d1c4Smrg      removelist="$obj $lobj $libobj ${libobj}T"
36892a75d1c4Smrg    else
36902a75d1c4Smrg      removelist="$lobj $libobj ${libobj}T"
36912a75d1c4Smrg    fi
36927ce7e03cSmrg
36932a75d1c4Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
36942a75d1c4Smrg    case $host_os in
36952a75d1c4Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
36962a75d1c4Smrg      pic_mode=default
36972a75d1c4Smrg      ;;
36982a75d1c4Smrg    esac
369966ab3337Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
37002a75d1c4Smrg      # non-PIC code in shared libraries is not supported
37012a75d1c4Smrg      pic_mode=default
37022a75d1c4Smrg    fi
3703f7ec340bSmacallan
37042a75d1c4Smrg    # Calculate the filename of the output object if compiler does
37052a75d1c4Smrg    # not support -o with -c
370666ab3337Smrg    if test no = "$compiler_c_o"; then
370766ab3337Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
370866ab3337Smrg      lockfile=$output_obj.lock
37092a75d1c4Smrg    else
37102a75d1c4Smrg      output_obj=
37112a75d1c4Smrg      need_locks=no
37122a75d1c4Smrg      lockfile=
37132a75d1c4Smrg    fi
3714f7ec340bSmacallan
37152a75d1c4Smrg    # Lock this critical section if it is needed
37162a75d1c4Smrg    # We use this script file to make the link, it avoids creating a new file
371766ab3337Smrg    if test yes = "$need_locks"; then
37182a75d1c4Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
37192a75d1c4Smrg	func_echo "Waiting for $lockfile to be removed"
37202a75d1c4Smrg	sleep 2
37212a75d1c4Smrg      done
372266ab3337Smrg    elif test warn = "$need_locks"; then
37232a75d1c4Smrg      if test -f "$lockfile"; then
37242a75d1c4Smrg	$ECHO "\
37252a75d1c4Smrg*** ERROR, $lockfile exists and contains:
37262a75d1c4Smrg`cat $lockfile 2>/dev/null`
3727f7ec340bSmacallan
37282a75d1c4SmrgThis indicates that another process is trying to use the same
37292a75d1c4Smrgtemporary object file, and libtool could not work around it because
373066ab3337Smrgyour compiler does not support '-c' and '-o' together.  If you
37312a75d1c4Smrgrepeat this compilation, it may succeed, by chance, but you had better
37322a75d1c4Smrgavoid parallel builds (make -j) in this platform, or get a better
37332a75d1c4Smrgcompiler."
3734f7ec340bSmacallan
37352a75d1c4Smrg	$opt_dry_run || $RM $removelist
37362a75d1c4Smrg	exit $EXIT_FAILURE
37372a75d1c4Smrg      fi
37382a75d1c4Smrg      func_append removelist " $output_obj"
37392a75d1c4Smrg      $ECHO "$srcfile" > "$lockfile"
37402a75d1c4Smrg    fi
3741f7ec340bSmacallan
37422a75d1c4Smrg    $opt_dry_run || $RM $removelist
37432a75d1c4Smrg    func_append removelist " $lockfile"
37442a75d1c4Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3745f7ec340bSmacallan
37462a75d1c4Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
37472a75d1c4Smrg    srcfile=$func_to_tool_file_result
374866ab3337Smrg    func_quote_arg pretty "$srcfile"
374966ab3337Smrg    qsrcfile=$func_quote_arg_result
3750f7ec340bSmacallan
37512a75d1c4Smrg    # Only build a PIC object if we are building libtool libraries.
375266ab3337Smrg    if test yes = "$build_libtool_libs"; then
37532a75d1c4Smrg      # Without this assignment, base_compile gets emptied.
37542a75d1c4Smrg      fbsd_hideous_sh_bug=$base_compile
3755f7ec340bSmacallan
375666ab3337Smrg      if test no != "$pic_mode"; then
37572a75d1c4Smrg	command="$base_compile $qsrcfile $pic_flag"
37582a75d1c4Smrg      else
37592a75d1c4Smrg	# Don't build PIC code
37602a75d1c4Smrg	command="$base_compile $qsrcfile"
37612a75d1c4Smrg      fi
3762f7ec340bSmacallan
37632a75d1c4Smrg      func_mkdir_p "$xdir$objdir"
3764f7ec340bSmacallan
37652a75d1c4Smrg      if test -z "$output_obj"; then
37662a75d1c4Smrg	# Place PIC objects in $objdir
37672a75d1c4Smrg	func_append command " -o $lobj"
37682a75d1c4Smrg      fi
3769f7ec340bSmacallan
37702a75d1c4Smrg      func_show_eval_locale "$command"	\
37712a75d1c4Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772f7ec340bSmacallan
377366ab3337Smrg      if test warn = "$need_locks" &&
37742a75d1c4Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
37752a75d1c4Smrg	$ECHO "\
37762a75d1c4Smrg*** ERROR, $lockfile contains:
37772a75d1c4Smrg`cat $lockfile 2>/dev/null`
3778f7ec340bSmacallan
37792a75d1c4Smrgbut it should contain:
37802a75d1c4Smrg$srcfile
3781f7ec340bSmacallan
37822a75d1c4SmrgThis indicates that another process is trying to use the same
37832a75d1c4Smrgtemporary object file, and libtool could not work around it because
378466ab3337Smrgyour compiler does not support '-c' and '-o' together.  If you
37852a75d1c4Smrgrepeat this compilation, it may succeed, by chance, but you had better
37862a75d1c4Smrgavoid parallel builds (make -j) in this platform, or get a better
37872a75d1c4Smrgcompiler."
3788f7ec340bSmacallan
37892a75d1c4Smrg	$opt_dry_run || $RM $removelist
37902a75d1c4Smrg	exit $EXIT_FAILURE
37912a75d1c4Smrg      fi
3792f7ec340bSmacallan
37932a75d1c4Smrg      # Just move the object if needed, then go on to compile the next one
37942a75d1c4Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
37952a75d1c4Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
37962a75d1c4Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
37972a75d1c4Smrg      fi
3798f7ec340bSmacallan
37992a75d1c4Smrg      # Allow error messages only from the first compilation.
380066ab3337Smrg      if test yes = "$suppress_opt"; then
38012a75d1c4Smrg	suppress_output=' >/dev/null 2>&1'
38022a75d1c4Smrg      fi
38032a75d1c4Smrg    fi
3804f7ec340bSmacallan
38052a75d1c4Smrg    # Only build a position-dependent object if we build old libraries.
380666ab3337Smrg    if test yes = "$build_old_libs"; then
380766ab3337Smrg      if test yes != "$pic_mode"; then
38082a75d1c4Smrg	# Don't build PIC code
38092a75d1c4Smrg	command="$base_compile $qsrcfile$pie_flag"
38102a75d1c4Smrg      else
38112a75d1c4Smrg	command="$base_compile $qsrcfile $pic_flag"
38122a75d1c4Smrg      fi
381366ab3337Smrg      if test yes = "$compiler_c_o"; then
38142a75d1c4Smrg	func_append command " -o $obj"
38152a75d1c4Smrg      fi
3816f7ec340bSmacallan
38172a75d1c4Smrg      # Suppress compiler output if we already did a PIC compilation.
38182a75d1c4Smrg      func_append command "$suppress_output"
38192a75d1c4Smrg      func_show_eval_locale "$command" \
38202a75d1c4Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821f7ec340bSmacallan
382266ab3337Smrg      if test warn = "$need_locks" &&
38232a75d1c4Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
38242a75d1c4Smrg	$ECHO "\
38252a75d1c4Smrg*** ERROR, $lockfile contains:
38262a75d1c4Smrg`cat $lockfile 2>/dev/null`
3827f7ec340bSmacallan
38282a75d1c4Smrgbut it should contain:
38292a75d1c4Smrg$srcfile
3830f7ec340bSmacallan
38312a75d1c4SmrgThis indicates that another process is trying to use the same
38322a75d1c4Smrgtemporary object file, and libtool could not work around it because
383366ab3337Smrgyour compiler does not support '-c' and '-o' together.  If you
38342a75d1c4Smrgrepeat this compilation, it may succeed, by chance, but you had better
38352a75d1c4Smrgavoid parallel builds (make -j) in this platform, or get a better
38362a75d1c4Smrgcompiler."
3837f7ec340bSmacallan
38382a75d1c4Smrg	$opt_dry_run || $RM $removelist
38392a75d1c4Smrg	exit $EXIT_FAILURE
38402a75d1c4Smrg      fi
3841f7ec340bSmacallan
38422a75d1c4Smrg      # Just move the object if needed
38432a75d1c4Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
38442a75d1c4Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
38452a75d1c4Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38462a75d1c4Smrg      fi
38472a75d1c4Smrg    fi
3848f7ec340bSmacallan
38492a75d1c4Smrg    $opt_dry_run || {
38502a75d1c4Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851f7ec340bSmacallan
38522a75d1c4Smrg      # Unlock the critical section if it was locked
385366ab3337Smrg      if test no != "$need_locks"; then
38542a75d1c4Smrg	removelist=$lockfile
38552a75d1c4Smrg        $RM "$lockfile"
38562a75d1c4Smrg      fi
38572a75d1c4Smrg    }
3858f7ec340bSmacallan
38592a75d1c4Smrg    exit $EXIT_SUCCESS
38602a75d1c4Smrg}
3861f7ec340bSmacallan
38622a75d1c4Smrg$opt_help || {
386366ab3337Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
38642a75d1c4Smrg}
3865f7ec340bSmacallan
38662a75d1c4Smrgfunc_mode_help ()
38672a75d1c4Smrg{
38682a75d1c4Smrg    # We need to display help for each of the modes.
38692a75d1c4Smrg    case $opt_mode in
38702a75d1c4Smrg      "")
38712a75d1c4Smrg        # Generic help is extracted from the usage comments
38722a75d1c4Smrg        # at the start of this file.
38732a75d1c4Smrg        func_help
38742a75d1c4Smrg        ;;
3875f7ec340bSmacallan
38762a75d1c4Smrg      clean)
38772a75d1c4Smrg        $ECHO \
38782a75d1c4Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879f7ec340bSmacallan
38802a75d1c4SmrgRemove files from the build directory.
3881f7ec340bSmacallan
38822a75d1c4SmrgRM is the name of the program to use to delete files associated with each FILE
388366ab3337Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38842a75d1c4Smrgto RM.
3885f7ec340bSmacallan
38862a75d1c4SmrgIf FILE is a libtool library, object or program, all the files associated
38872a75d1c4Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
38882a75d1c4Smrg        ;;
3889f7ec340bSmacallan
38902a75d1c4Smrg      compile)
38912a75d1c4Smrg      $ECHO \
38922a75d1c4Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893f7ec340bSmacallan
38942a75d1c4SmrgCompile a source file into a libtool library object.
3895f7ec340bSmacallan
38962a75d1c4SmrgThis mode accepts the following additional options:
3897f7ec340bSmacallan
38982a75d1c4Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
38992a75d1c4Smrg  -no-suppress      do not suppress compiler output for multiple passes
39002a75d1c4Smrg  -prefer-pic       try to build PIC objects only
39012a75d1c4Smrg  -prefer-non-pic   try to build non-PIC objects only
390266ab3337Smrg  -shared           do not build a '.o' file suitable for static linking
390366ab3337Smrg  -static           only build a '.o' file suitable for static linking
390466ab3337Smrg  -Wc,FLAG
390566ab3337Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906f7ec340bSmacallan
390766ab3337SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
39082a75d1c4Smrgfrom the given SOURCEFILE.
3909f7ec340bSmacallan
39102a75d1c4SmrgThe output file name is determined by removing the directory component from
391166ab3337SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
391266ab3337Smrglibrary object suffix, '.lo'."
39132a75d1c4Smrg        ;;
3914f7ec340bSmacallan
39152a75d1c4Smrg      execute)
39162a75d1c4Smrg        $ECHO \
39172a75d1c4Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918f7ec340bSmacallan
39192a75d1c4SmrgAutomatically set library path, then run a program.
3920f7ec340bSmacallan
39212a75d1c4SmrgThis mode accepts the following additional options:
3922f7ec340bSmacallan
39232a75d1c4Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924f7ec340bSmacallan
392566ab3337SmrgThis mode sets the library path environment variable according to '-dlopen'
39262a75d1c4Smrgflags.
3927f7ec340bSmacallan
39282a75d1c4SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
39292a75d1c4Smrginto their corresponding uninstalled binary, and any of their required library
39302a75d1c4Smrgdirectories are added to the library path.
3931f7ec340bSmacallan
39322a75d1c4SmrgThen, COMMAND is executed, with ARGS as arguments."
39332a75d1c4Smrg        ;;
3934f7ec340bSmacallan
39352a75d1c4Smrg      finish)
39362a75d1c4Smrg        $ECHO \
39372a75d1c4Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938f7ec340bSmacallan
39392a75d1c4SmrgComplete the installation of libtool libraries.
39402a75d1c4Smrg
39412a75d1c4SmrgEach LIBDIR is a directory that contains libtool libraries.
39422a75d1c4Smrg
39432a75d1c4SmrgThe commands that this mode executes may require superuser privileges.  Use
394466ab3337Smrgthe '--dry-run' option if you just want to see what would be executed."
39452a75d1c4Smrg        ;;
39462a75d1c4Smrg
39472a75d1c4Smrg      install)
39482a75d1c4Smrg        $ECHO \
39492a75d1c4Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
39502a75d1c4Smrg
39512a75d1c4SmrgInstall executables or libraries.
39522a75d1c4Smrg
39532a75d1c4SmrgINSTALL-COMMAND is the installation command.  The first component should be
395466ab3337Smrgeither the 'install' or 'cp' program.
39552a75d1c4Smrg
39562a75d1c4SmrgThe following components of INSTALL-COMMAND are treated specially:
39572a75d1c4Smrg
39582a75d1c4Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
39592a75d1c4Smrg
39602a75d1c4SmrgThe rest of the components are interpreted as arguments to that command (only
39612a75d1c4SmrgBSD-compatible install options are recognized)."
39622a75d1c4Smrg        ;;
39632a75d1c4Smrg
39642a75d1c4Smrg      link)
39652a75d1c4Smrg        $ECHO \
39662a75d1c4Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
39672a75d1c4Smrg
39682a75d1c4SmrgLink object files or libraries together to form another library, or to
39692a75d1c4Smrgcreate an executable program.
39702a75d1c4Smrg
39712a75d1c4SmrgLINK-COMMAND is a command using the C compiler that you would use to create
39722a75d1c4Smrga program from several object files.
39732a75d1c4Smrg
39742a75d1c4SmrgThe following components of LINK-COMMAND are treated specially:
39752a75d1c4Smrg
39762a75d1c4Smrg  -all-static       do not do any dynamic linking at all
39772a75d1c4Smrg  -avoid-version    do not add a version suffix if possible
39782a75d1c4Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
39792a75d1c4Smrg                    libraries must be found in the PATH setting at runtime)
398066ab3337Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
39812a75d1c4Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
39822a75d1c4Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
39832a75d1c4Smrg  -export-symbols SYMFILE
39842a75d1c4Smrg                    try to export only the symbols listed in SYMFILE
39852a75d1c4Smrg  -export-symbols-regex REGEX
39862a75d1c4Smrg                    try to export only the symbols matching REGEX
39872a75d1c4Smrg  -LLIBDIR          search LIBDIR for required installed libraries
39882a75d1c4Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
39892a75d1c4Smrg  -module           build a library that can dlopened
39902a75d1c4Smrg  -no-fast-install  disable the fast-install mode
39912a75d1c4Smrg  -no-install       link a not-installable executable
39922a75d1c4Smrg  -no-undefined     declare that a library does not refer to external symbols
39932a75d1c4Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
399466ab3337Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
399566ab3337Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
39962a75d1c4Smrg  -precious-files-regex REGEX
39972a75d1c4Smrg                    don't remove output files matching REGEX
39982a75d1c4Smrg  -release RELEASE  specify package release information
39992a75d1c4Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
40002a75d1c4Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
40012a75d1c4Smrg  -shared           only do dynamic linking of libtool libraries
40022a75d1c4Smrg  -shrext SUFFIX    override the standard shared library file extension
40032a75d1c4Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
40042a75d1c4Smrg  -static-libtool-libs
40052a75d1c4Smrg                    do not do any dynamic linking of libtool libraries
40062a75d1c4Smrg  -version-info CURRENT[:REVISION[:AGE]]
40072a75d1c4Smrg                    specify library version info [each variable defaults to 0]
40082a75d1c4Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
40092a75d1c4Smrg  -Wc,FLAG
40102a75d1c4Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
401166ab3337Smrg  -Wa,FLAG
401266ab3337Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
40132a75d1c4Smrg  -Wl,FLAG
40142a75d1c4Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
40152a75d1c4Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
40162a75d1c4Smrg
401766ab3337SmrgAll other options (arguments beginning with '-') are ignored.
40182a75d1c4Smrg
401966ab3337SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
40202a75d1c4Smrgtreated as uninstalled libtool libraries, other files are standard or library
40212a75d1c4Smrgobject files.
40222a75d1c4Smrg
402366ab3337SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
402466ab3337Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
40252a75d1c4Smrgrequired, except when creating a convenience library.
40262a75d1c4Smrg
402766ab3337SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
402866ab3337Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40292a75d1c4Smrg
403066ab3337SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
40312a75d1c4Smrgis created, otherwise an executable program is created."
40322a75d1c4Smrg        ;;
40332a75d1c4Smrg
40342a75d1c4Smrg      uninstall)
40352a75d1c4Smrg        $ECHO \
40362a75d1c4Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
40372a75d1c4Smrg
40382a75d1c4SmrgRemove libraries from an installation directory.
40392a75d1c4Smrg
40402a75d1c4SmrgRM is the name of the program to use to delete files associated with each FILE
404166ab3337Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
40422a75d1c4Smrgto RM.
40432a75d1c4Smrg
40442a75d1c4SmrgIf FILE is a libtool library, all the files associated with it are deleted.
40452a75d1c4SmrgOtherwise, only FILE itself is deleted using RM."
40462a75d1c4Smrg        ;;
40472a75d1c4Smrg
40482a75d1c4Smrg      *)
404966ab3337Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
40502a75d1c4Smrg        ;;
4051f7ec340bSmacallan    esac
4052f7ec340bSmacallan
40532a75d1c4Smrg    echo
405466ab3337Smrg    $ECHO "Try '$progname --help' for more information about other modes."
40552a75d1c4Smrg}
4056f7ec340bSmacallan
40572a75d1c4Smrg# Now that we've collected a possible --mode arg, show help if necessary
40582a75d1c4Smrgif $opt_help; then
405966ab3337Smrg  if test : = "$opt_help"; then
40602a75d1c4Smrg    func_mode_help
40612a75d1c4Smrg  else
40622a75d1c4Smrg    {
40632a75d1c4Smrg      func_help noexit
40642a75d1c4Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40652a75d1c4Smrg	func_mode_help
40662a75d1c4Smrg      done
406766ab3337Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
40682a75d1c4Smrg    {
40692a75d1c4Smrg      func_help noexit
40702a75d1c4Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40712a75d1c4Smrg	echo
40722a75d1c4Smrg	func_mode_help
40732a75d1c4Smrg      done
40742a75d1c4Smrg    } |
407566ab3337Smrg    $SED '1d
40762a75d1c4Smrg      /^When reporting/,/^Report/{
40772a75d1c4Smrg	H
40782a75d1c4Smrg	d
40792a75d1c4Smrg      }
40802a75d1c4Smrg      $x
40812a75d1c4Smrg      /information about other modes/d
40822a75d1c4Smrg      /more detailed .*MODE/d
40832a75d1c4Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
40842a75d1c4Smrg  fi
40852a75d1c4Smrg  exit $?
40862a75d1c4Smrgfi
4087f7ec340bSmacallan
4088f7ec340bSmacallan
40892a75d1c4Smrg# func_mode_execute arg...
40902a75d1c4Smrgfunc_mode_execute ()
40912a75d1c4Smrg{
409266ab3337Smrg    $debug_cmd
409366ab3337Smrg
40942a75d1c4Smrg    # The first argument is the command name.
409566ab3337Smrg    cmd=$nonopt
40962a75d1c4Smrg    test -z "$cmd" && \
40972a75d1c4Smrg      func_fatal_help "you must specify a COMMAND"
40982a75d1c4Smrg
40992a75d1c4Smrg    # Handle -dlopen flags immediately.
41002a75d1c4Smrg    for file in $opt_dlopen; do
41012a75d1c4Smrg      test -f "$file" \
410266ab3337Smrg	|| func_fatal_help "'$file' is not a file"
41032a75d1c4Smrg
41042a75d1c4Smrg      dir=
41052a75d1c4Smrg      case $file in
41062a75d1c4Smrg      *.la)
41072a75d1c4Smrg	func_resolve_sysroot "$file"
41082a75d1c4Smrg	file=$func_resolve_sysroot_result
41092a75d1c4Smrg
41102a75d1c4Smrg	# Check to see that this really is a libtool archive.
41112a75d1c4Smrg	func_lalib_unsafe_p "$file" \
411266ab3337Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
41132a75d1c4Smrg
41142a75d1c4Smrg	# Read the libtool library.
41152a75d1c4Smrg	dlname=
41162a75d1c4Smrg	library_names=
41172a75d1c4Smrg	func_source "$file"
41182a75d1c4Smrg
41192a75d1c4Smrg	# Skip this library if it cannot be dlopened.
41202a75d1c4Smrg	if test -z "$dlname"; then
41212a75d1c4Smrg	  # Warn if it was a shared library.
41222a75d1c4Smrg	  test -n "$library_names" && \
412366ab3337Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
41242a75d1c4Smrg	  continue
41252a75d1c4Smrg	fi
41262a75d1c4Smrg
41272a75d1c4Smrg	func_dirname "$file" "" "."
412866ab3337Smrg	dir=$func_dirname_result
41292a75d1c4Smrg
41302a75d1c4Smrg	if test -f "$dir/$objdir/$dlname"; then
41312a75d1c4Smrg	  func_append dir "/$objdir"
41322a75d1c4Smrg	else
41332a75d1c4Smrg	  if test ! -f "$dir/$dlname"; then
413466ab3337Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
41352a75d1c4Smrg	  fi
41362a75d1c4Smrg	fi
4137f7ec340bSmacallan	;;
41382a75d1c4Smrg
41392a75d1c4Smrg      *.lo)
41402a75d1c4Smrg	# Just add the directory containing the .lo file.
41412a75d1c4Smrg	func_dirname "$file" "" "."
414266ab3337Smrg	dir=$func_dirname_result
4143f7ec340bSmacallan	;;
41442a75d1c4Smrg
41452a75d1c4Smrg      *)
414666ab3337Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
41472a75d1c4Smrg	continue
4148f7ec340bSmacallan	;;
41492a75d1c4Smrg      esac
41502a75d1c4Smrg
41512a75d1c4Smrg      # Get the absolute pathname.
41522a75d1c4Smrg      absdir=`cd "$dir" && pwd`
415366ab3337Smrg      test -n "$absdir" && dir=$absdir
41542a75d1c4Smrg
41552a75d1c4Smrg      # Now add the directory to shlibpath_var.
41562a75d1c4Smrg      if eval "test -z \"\$$shlibpath_var\""; then
41572a75d1c4Smrg	eval "$shlibpath_var=\"\$dir\""
41582a75d1c4Smrg      else
41592a75d1c4Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160f7ec340bSmacallan      fi
41612a75d1c4Smrg    done
41622a75d1c4Smrg
41632a75d1c4Smrg    # This variable tells wrapper scripts just to set shlibpath_var
41642a75d1c4Smrg    # rather than running their programs.
416566ab3337Smrg    libtool_execute_magic=$magic
41662a75d1c4Smrg
41672a75d1c4Smrg    # Check if any of the arguments is a wrapper script.
41682a75d1c4Smrg    args=
41692a75d1c4Smrg    for file
41702a75d1c4Smrg    do
41712a75d1c4Smrg      case $file in
41722a75d1c4Smrg      -* | *.la | *.lo ) ;;
41732a75d1c4Smrg      *)
41742a75d1c4Smrg	# Do a test to see if this is really a libtool program.
41752a75d1c4Smrg	if func_ltwrapper_script_p "$file"; then
41762a75d1c4Smrg	  func_source "$file"
41772a75d1c4Smrg	  # Transform arg to wrapped name.
417866ab3337Smrg	  file=$progdir/$program
41792a75d1c4Smrg	elif func_ltwrapper_executable_p "$file"; then
41802a75d1c4Smrg	  func_ltwrapper_scriptname "$file"
41812a75d1c4Smrg	  func_source "$func_ltwrapper_scriptname_result"
41822a75d1c4Smrg	  # Transform arg to wrapped name.
418366ab3337Smrg	  file=$progdir/$program
41842a75d1c4Smrg	fi
41852a75d1c4Smrg	;;
41862a75d1c4Smrg      esac
41872a75d1c4Smrg      # Quote arguments (to preserve shell metacharacters).
41882a75d1c4Smrg      func_append_quoted args "$file"
41892a75d1c4Smrg    done
41902a75d1c4Smrg
419166ab3337Smrg    if $opt_dry_run; then
419266ab3337Smrg      # Display what would be done.
419366ab3337Smrg      if test -n "$shlibpath_var"; then
419466ab3337Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
419566ab3337Smrg	echo "export $shlibpath_var"
419666ab3337Smrg      fi
419766ab3337Smrg      $ECHO "$cmd$args"
419866ab3337Smrg      exit $EXIT_SUCCESS
419966ab3337Smrg    else
42002a75d1c4Smrg      if test -n "$shlibpath_var"; then
42012a75d1c4Smrg	# Export the shlibpath_var.
42022a75d1c4Smrg	eval "export $shlibpath_var"
4203f7ec340bSmacallan      fi
42042a75d1c4Smrg
42052a75d1c4Smrg      # Restore saved environment variables
42062a75d1c4Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
42072a75d1c4Smrg      do
42082a75d1c4Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
42092a75d1c4Smrg                $lt_var=\$save_$lt_var; export $lt_var
42102a75d1c4Smrg	      else
42112a75d1c4Smrg		$lt_unset $lt_var
42122a75d1c4Smrg	      fi"
42132a75d1c4Smrg      done
42142a75d1c4Smrg
42152a75d1c4Smrg      # Now prepare to actually exec the command.
421666ab3337Smrg      exec_cmd=\$cmd$args
42172a75d1c4Smrg    fi
42182a75d1c4Smrg}
4219f7ec340bSmacallan
422066ab3337Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221f7ec340bSmacallan
4222f7ec340bSmacallan
42232a75d1c4Smrg# func_mode_finish arg...
42242a75d1c4Smrgfunc_mode_finish ()
42252a75d1c4Smrg{
422666ab3337Smrg    $debug_cmd
422766ab3337Smrg
42282a75d1c4Smrg    libs=
42292a75d1c4Smrg    libdirs=
42302a75d1c4Smrg    admincmds=
4231f7ec340bSmacallan
42322a75d1c4Smrg    for opt in "$nonopt" ${1+"$@"}
42332a75d1c4Smrg    do
42342a75d1c4Smrg      if test -d "$opt"; then
42352a75d1c4Smrg	func_append libdirs " $opt"
4236f7ec340bSmacallan
42372a75d1c4Smrg      elif test -f "$opt"; then
42382a75d1c4Smrg	if func_lalib_unsafe_p "$opt"; then
42392a75d1c4Smrg	  func_append libs " $opt"
42402a75d1c4Smrg	else
424166ab3337Smrg	  func_warning "'$opt' is not a valid libtool archive"
4242f7ec340bSmacallan	fi
4243f7ec340bSmacallan
42442a75d1c4Smrg      else
424566ab3337Smrg	func_fatal_error "invalid argument '$opt'"
42462a75d1c4Smrg      fi
42472a75d1c4Smrg    done
4248f7ec340bSmacallan
42492a75d1c4Smrg    if test -n "$libs"; then
42502a75d1c4Smrg      if test -n "$lt_sysroot"; then
42512a75d1c4Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
42522a75d1c4Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
42532a75d1c4Smrg      else
42542a75d1c4Smrg        sysroot_cmd=
42552a75d1c4Smrg      fi
4256f7ec340bSmacallan
42572a75d1c4Smrg      # Remove sysroot references
42582a75d1c4Smrg      if $opt_dry_run; then
42592a75d1c4Smrg        for lib in $libs; do
426066ab3337Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
42612a75d1c4Smrg        done
42622a75d1c4Smrg      else
42632a75d1c4Smrg        tmpdir=`func_mktempdir`
42642a75d1c4Smrg        for lib in $libs; do
426566ab3337Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
42662a75d1c4Smrg	    > $tmpdir/tmp-la
42672a75d1c4Smrg	  mv -f $tmpdir/tmp-la $lib
4268f7ec340bSmacallan	done
42692a75d1c4Smrg        ${RM}r "$tmpdir"
42702a75d1c4Smrg      fi
42712a75d1c4Smrg    fi
42722a75d1c4Smrg
42732a75d1c4Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42742a75d1c4Smrg      for libdir in $libdirs; do
42752a75d1c4Smrg	if test -n "$finish_cmds"; then
42762a75d1c4Smrg	  # Do each command in the finish commands.
42772a75d1c4Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
42782a75d1c4Smrg'"$cmd"'"'
4279f7ec340bSmacallan	fi
42802a75d1c4Smrg	if test -n "$finish_eval"; then
42812a75d1c4Smrg	  # Do the single finish_eval.
42822a75d1c4Smrg	  eval cmds=\"$finish_eval\"
42832a75d1c4Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
42842a75d1c4Smrg       $cmds"
42852a75d1c4Smrg	fi
42862a75d1c4Smrg      done
42872a75d1c4Smrg    fi
4288f7ec340bSmacallan
42892a75d1c4Smrg    # Exit here if they wanted silent mode.
429066ab3337Smrg    $opt_quiet && exit $EXIT_SUCCESS
4291f7ec340bSmacallan
42922a75d1c4Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42932a75d1c4Smrg      echo "----------------------------------------------------------------------"
42942a75d1c4Smrg      echo "Libraries have been installed in:"
42952a75d1c4Smrg      for libdir in $libdirs; do
42962a75d1c4Smrg	$ECHO "   $libdir"
42972a75d1c4Smrg      done
42982a75d1c4Smrg      echo
42992a75d1c4Smrg      echo "If you ever happen to want to link against installed libraries"
43002a75d1c4Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
430166ab3337Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
43022a75d1c4Smrg      echo "flag during linking and do at least one of the following:"
43032a75d1c4Smrg      if test -n "$shlibpath_var"; then
430466ab3337Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
43052a75d1c4Smrg	echo "     during execution"
43062a75d1c4Smrg      fi
43072a75d1c4Smrg      if test -n "$runpath_var"; then
430866ab3337Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
43092a75d1c4Smrg	echo "     during linking"
43102a75d1c4Smrg      fi
43112a75d1c4Smrg      if test -n "$hardcode_libdir_flag_spec"; then
43122a75d1c4Smrg	libdir=LIBDIR
43132a75d1c4Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
43142a75d1c4Smrg
431566ab3337Smrg	$ECHO "   - use the '$flag' linker flag"
43162a75d1c4Smrg      fi
43172a75d1c4Smrg      if test -n "$admincmds"; then
43182a75d1c4Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
43192a75d1c4Smrg      fi
43202a75d1c4Smrg      if test -f /etc/ld.so.conf; then
432166ab3337Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
43222a75d1c4Smrg      fi
43232a75d1c4Smrg      echo
43242a75d1c4Smrg
43252a75d1c4Smrg      echo "See any operating system documentation about shared libraries for"
43262a75d1c4Smrg      case $host in
43272a75d1c4Smrg	solaris2.[6789]|solaris2.1[0-9])
43282a75d1c4Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
43292a75d1c4Smrg	  echo "pages."
43302a75d1c4Smrg	  ;;
4331f7ec340bSmacallan	*)
43322a75d1c4Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333f7ec340bSmacallan	  ;;
43342a75d1c4Smrg      esac
43352a75d1c4Smrg      echo "----------------------------------------------------------------------"
43362a75d1c4Smrg    fi
43372a75d1c4Smrg    exit $EXIT_SUCCESS
43382a75d1c4Smrg}
4339f7ec340bSmacallan
434066ab3337Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341f7ec340bSmacallan
43422a75d1c4Smrg
43432a75d1c4Smrg# func_mode_install arg...
43442a75d1c4Smrgfunc_mode_install ()
43452a75d1c4Smrg{
434666ab3337Smrg    $debug_cmd
434766ab3337Smrg
43482a75d1c4Smrg    # There may be an optional sh(1) argument at the beginning of
43492a75d1c4Smrg    # install_prog (especially on Windows NT).
435066ab3337Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
43512a75d1c4Smrg       # Allow the use of GNU shtool's install command.
435266ab3337Smrg       case $nonopt in *shtool*) :;; *) false;; esac
435366ab3337Smrg    then
43542a75d1c4Smrg      # Aesthetically quote it.
435566ab3337Smrg      func_quote_arg pretty "$nonopt"
435666ab3337Smrg      install_prog="$func_quote_arg_result "
43572a75d1c4Smrg      arg=$1
43582a75d1c4Smrg      shift
43592a75d1c4Smrg    else
43602a75d1c4Smrg      install_prog=
43612a75d1c4Smrg      arg=$nonopt
43622a75d1c4Smrg    fi
43632a75d1c4Smrg
43642a75d1c4Smrg    # The real first argument should be the name of the installation program.
43652a75d1c4Smrg    # Aesthetically quote it.
436666ab3337Smrg    func_quote_arg pretty "$arg"
436766ab3337Smrg    func_append install_prog "$func_quote_arg_result"
43682a75d1c4Smrg    install_shared_prog=$install_prog
43692a75d1c4Smrg    case " $install_prog " in
43702a75d1c4Smrg      *[\\\ /]cp\ *) install_cp=: ;;
43712a75d1c4Smrg      *) install_cp=false ;;
43722a75d1c4Smrg    esac
43732a75d1c4Smrg
43742a75d1c4Smrg    # We need to accept at least all the BSD install flags.
43752a75d1c4Smrg    dest=
43762a75d1c4Smrg    files=
43772a75d1c4Smrg    opts=
43782a75d1c4Smrg    prev=
43792a75d1c4Smrg    install_type=
438066ab3337Smrg    isdir=false
43812a75d1c4Smrg    stripme=
43822a75d1c4Smrg    no_mode=:
43832a75d1c4Smrg    for arg
43842a75d1c4Smrg    do
43852a75d1c4Smrg      arg2=
43862a75d1c4Smrg      if test -n "$dest"; then
43872a75d1c4Smrg	func_append files " $dest"
43882a75d1c4Smrg	dest=$arg
43892a75d1c4Smrg	continue
43902a75d1c4Smrg      fi
43912a75d1c4Smrg
43922a75d1c4Smrg      case $arg in
439366ab3337Smrg      -d) isdir=: ;;
43942a75d1c4Smrg      -f)
43952a75d1c4Smrg	if $install_cp; then :; else
43962a75d1c4Smrg	  prev=$arg
43972a75d1c4Smrg	fi
43982a75d1c4Smrg	;;
43992a75d1c4Smrg      -g | -m | -o)
44002a75d1c4Smrg	prev=$arg
44012a75d1c4Smrg	;;
44022a75d1c4Smrg      -s)
44032a75d1c4Smrg	stripme=" -s"
44042a75d1c4Smrg	continue
44052a75d1c4Smrg	;;
44062a75d1c4Smrg      -*)
44072a75d1c4Smrg	;;
44082a75d1c4Smrg      *)
44092a75d1c4Smrg	# If the previous option needed an argument, then skip it.
44102a75d1c4Smrg	if test -n "$prev"; then
441166ab3337Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
44122a75d1c4Smrg	    arg2=$install_override_mode
44132a75d1c4Smrg	    no_mode=false
4414f7ec340bSmacallan	  fi
44152a75d1c4Smrg	  prev=
44162a75d1c4Smrg	else
44172a75d1c4Smrg	  dest=$arg
4418f7ec340bSmacallan	  continue
4419f7ec340bSmacallan	fi
44202a75d1c4Smrg	;;
44212a75d1c4Smrg      esac
4422f7ec340bSmacallan
44232a75d1c4Smrg      # Aesthetically quote the argument.
442466ab3337Smrg      func_quote_arg pretty "$arg"
442566ab3337Smrg      func_append install_prog " $func_quote_arg_result"
44262a75d1c4Smrg      if test -n "$arg2"; then
442766ab3337Smrg	func_quote_arg pretty "$arg2"
44282a75d1c4Smrg      fi
442966ab3337Smrg      func_append install_shared_prog " $func_quote_arg_result"
44302a75d1c4Smrg    done
4431f7ec340bSmacallan
44322a75d1c4Smrg    test -z "$install_prog" && \
44332a75d1c4Smrg      func_fatal_help "you must specify an install program"
4434f7ec340bSmacallan
44352a75d1c4Smrg    test -n "$prev" && \
443666ab3337Smrg      func_fatal_help "the '$prev' option requires an argument"
4437f7ec340bSmacallan
44382a75d1c4Smrg    if test -n "$install_override_mode" && $no_mode; then
44392a75d1c4Smrg      if $install_cp; then :; else
444066ab3337Smrg	func_quote_arg pretty "$install_override_mode"
444166ab3337Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
44422a75d1c4Smrg      fi
44432a75d1c4Smrg    fi
4444f7ec340bSmacallan
44452a75d1c4Smrg    if test -z "$files"; then
44462a75d1c4Smrg      if test -z "$dest"; then
44472a75d1c4Smrg	func_fatal_help "no file or destination specified"
44482a75d1c4Smrg      else
44492a75d1c4Smrg	func_fatal_help "you must specify a destination"
44502a75d1c4Smrg      fi
44512a75d1c4Smrg    fi
4452f7ec340bSmacallan
44532a75d1c4Smrg    # Strip any trailing slash from the destination.
44542a75d1c4Smrg    func_stripname '' '/' "$dest"
44552a75d1c4Smrg    dest=$func_stripname_result
4456f7ec340bSmacallan
44572a75d1c4Smrg    # Check to see that the destination is a directory.
445866ab3337Smrg    test -d "$dest" && isdir=:
445966ab3337Smrg    if $isdir; then
446066ab3337Smrg      destdir=$dest
44612a75d1c4Smrg      destname=
44622a75d1c4Smrg    else
44632a75d1c4Smrg      func_dirname_and_basename "$dest" "" "."
446466ab3337Smrg      destdir=$func_dirname_result
446566ab3337Smrg      destname=$func_basename_result
4466f7ec340bSmacallan
44672a75d1c4Smrg      # Not a directory, so check to see that there is only one file specified.
44682a75d1c4Smrg      set dummy $files; shift
44692a75d1c4Smrg      test "$#" -gt 1 && \
447066ab3337Smrg	func_fatal_help "'$dest' is not a directory"
44712a75d1c4Smrg    fi
44722a75d1c4Smrg    case $destdir in
44732a75d1c4Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
44742a75d1c4Smrg    *)
44752a75d1c4Smrg      for file in $files; do
44762a75d1c4Smrg	case $file in
44772a75d1c4Smrg	*.lo) ;;
44782a75d1c4Smrg	*)
447966ab3337Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
44802a75d1c4Smrg	  ;;
44812a75d1c4Smrg	esac
44822a75d1c4Smrg      done
44832a75d1c4Smrg      ;;
44842a75d1c4Smrg    esac
4485f7ec340bSmacallan
44862a75d1c4Smrg    # This variable tells wrapper scripts just to set variables rather
44872a75d1c4Smrg    # than running their programs.
448866ab3337Smrg    libtool_install_magic=$magic
4489f7ec340bSmacallan
44902a75d1c4Smrg    staticlibs=
44912a75d1c4Smrg    future_libdirs=
44922a75d1c4Smrg    current_libdirs=
44932a75d1c4Smrg    for file in $files; do
4494f7ec340bSmacallan
44952a75d1c4Smrg      # Do each installation.
44962a75d1c4Smrg      case $file in
44972a75d1c4Smrg      *.$libext)
44982a75d1c4Smrg	# Do the static libraries later.
44992a75d1c4Smrg	func_append staticlibs " $file"
45002a75d1c4Smrg	;;
4501f7ec340bSmacallan
45022a75d1c4Smrg      *.la)
45032a75d1c4Smrg	func_resolve_sysroot "$file"
45042a75d1c4Smrg	file=$func_resolve_sysroot_result
4505f7ec340bSmacallan
45062a75d1c4Smrg	# Check to see that this really is a libtool archive.
45072a75d1c4Smrg	func_lalib_unsafe_p "$file" \
450866ab3337Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4509f7ec340bSmacallan
45102a75d1c4Smrg	library_names=
45112a75d1c4Smrg	old_library=
45122a75d1c4Smrg	relink_command=
45132a75d1c4Smrg	func_source "$file"
4514f7ec340bSmacallan
45152a75d1c4Smrg	# Add the libdir to current_libdirs if it is the destination.
45162a75d1c4Smrg	if test "X$destdir" = "X$libdir"; then
45172a75d1c4Smrg	  case "$current_libdirs " in
45182a75d1c4Smrg	  *" $libdir "*) ;;
45192a75d1c4Smrg	  *) func_append current_libdirs " $libdir" ;;
45202a75d1c4Smrg	  esac
45212a75d1c4Smrg	else
45222a75d1c4Smrg	  # Note the libdir as a future libdir.
45232a75d1c4Smrg	  case "$future_libdirs " in
45242a75d1c4Smrg	  *" $libdir "*) ;;
45252a75d1c4Smrg	  *) func_append future_libdirs " $libdir" ;;
45262a75d1c4Smrg	  esac
45272a75d1c4Smrg	fi
4528f7ec340bSmacallan
45292a75d1c4Smrg	func_dirname "$file" "/" ""
453066ab3337Smrg	dir=$func_dirname_result
45312a75d1c4Smrg	func_append dir "$objdir"
4532f7ec340bSmacallan
45332a75d1c4Smrg	if test -n "$relink_command"; then
45342a75d1c4Smrg	  # Determine the prefix the user has applied to our future dir.
45352a75d1c4Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536f7ec340bSmacallan
45372a75d1c4Smrg	  # Don't allow the user to place us outside of our expected
45382a75d1c4Smrg	  # location b/c this prevents finding dependent libraries that
45392a75d1c4Smrg	  # are installed to the same prefix.
45402a75d1c4Smrg	  # At present, this check doesn't affect windows .dll's that
45412a75d1c4Smrg	  # are installed into $libdir/../bin (currently, that works fine)
45422a75d1c4Smrg	  # but it's something to keep an eye on.
45432a75d1c4Smrg	  test "$inst_prefix_dir" = "$destdir" && \
454466ab3337Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
45452a75d1c4Smrg
45462a75d1c4Smrg	  if test -n "$inst_prefix_dir"; then
45472a75d1c4Smrg	    # Stick the inst_prefix_dir data into the link command.
45482a75d1c4Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549f7ec340bSmacallan	  else
45502a75d1c4Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551f7ec340bSmacallan	  fi
4552f7ec340bSmacallan
455366ab3337Smrg	  func_warning "relinking '$file'"
45542a75d1c4Smrg	  func_show_eval "$relink_command" \
455566ab3337Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
45562a75d1c4Smrg	fi
45572a75d1c4Smrg
45582a75d1c4Smrg	# See the names of the shared library.
45592a75d1c4Smrg	set dummy $library_names; shift
45602a75d1c4Smrg	if test -n "$1"; then
456166ab3337Smrg	  realname=$1
45622a75d1c4Smrg	  shift
45632a75d1c4Smrg
456466ab3337Smrg	  srcname=$realname
456566ab3337Smrg	  test -n "$relink_command" && srcname=${realname}T
45662a75d1c4Smrg
45672a75d1c4Smrg	  # Install the shared library and build the symlinks.
45682a75d1c4Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
45692a75d1c4Smrg	      'exit $?'
457066ab3337Smrg	  tstripme=$stripme
45712a75d1c4Smrg	  case $host_os in
45722a75d1c4Smrg	  cygwin* | mingw* | pw32* | cegcc*)
45732a75d1c4Smrg	    case $realname in
45742a75d1c4Smrg	    *.dll.a)
457566ab3337Smrg	      tstripme=
457666ab3337Smrg	      ;;
457766ab3337Smrg	    esac
457866ab3337Smrg	    ;;
457966ab3337Smrg	  os2*)
458066ab3337Smrg	    case $realname in
458166ab3337Smrg	    *_dll.a)
458266ab3337Smrg	      tstripme=
45832a75d1c4Smrg	      ;;
45842a75d1c4Smrg	    esac
45852a75d1c4Smrg	    ;;
45862a75d1c4Smrg	  esac
45872a75d1c4Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
45882a75d1c4Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589f7ec340bSmacallan	  fi
4590f7ec340bSmacallan
45912a75d1c4Smrg	  if test "$#" -gt 0; then
45922a75d1c4Smrg	    # Delete the old symlinks, and create new ones.
459366ab3337Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
45942a75d1c4Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
45952a75d1c4Smrg	    # so we also need to try rm && ln -s.
45962a75d1c4Smrg	    for linkname
45972a75d1c4Smrg	    do
45982a75d1c4Smrg	      test "$linkname" != "$realname" \
45992a75d1c4Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600f7ec340bSmacallan	    done
4601f7ec340bSmacallan	  fi
4602f7ec340bSmacallan
46032a75d1c4Smrg	  # Do each command in the postinstall commands.
460466ab3337Smrg	  lib=$destdir/$realname
46052a75d1c4Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
46062a75d1c4Smrg	fi
4607f7ec340bSmacallan
46082a75d1c4Smrg	# Install the pseudo-library for information purposes.
46092a75d1c4Smrg	func_basename "$file"
461066ab3337Smrg	name=$func_basename_result
461166ab3337Smrg	instname=$dir/${name}i
46122a75d1c4Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613f7ec340bSmacallan
46142a75d1c4Smrg	# Maybe install the static library, too.
46152a75d1c4Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
46162a75d1c4Smrg	;;
46172a75d1c4Smrg
46182a75d1c4Smrg      *.lo)
46192a75d1c4Smrg	# Install (i.e. copy) a libtool object.
46202a75d1c4Smrg
46212a75d1c4Smrg	# Figure out destination file name, if it wasn't already specified.
46222a75d1c4Smrg	if test -n "$destname"; then
462366ab3337Smrg	  destfile=$destdir/$destname
4624f7ec340bSmacallan	else
46252a75d1c4Smrg	  func_basename "$file"
462666ab3337Smrg	  destfile=$func_basename_result
462766ab3337Smrg	  destfile=$destdir/$destfile
4628f7ec340bSmacallan	fi
46292a75d1c4Smrg
46302a75d1c4Smrg	# Deduce the name of the destination old-style object file.
46312a75d1c4Smrg	case $destfile in
46322a75d1c4Smrg	*.lo)
46332a75d1c4Smrg	  func_lo2o "$destfile"
46342a75d1c4Smrg	  staticdest=$func_lo2o_result
46352a75d1c4Smrg	  ;;
46362a75d1c4Smrg	*.$objext)
463766ab3337Smrg	  staticdest=$destfile
46382a75d1c4Smrg	  destfile=
46392a75d1c4Smrg	  ;;
46402a75d1c4Smrg	*)
464166ab3337Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642f7ec340bSmacallan	  ;;
4643f7ec340bSmacallan	esac
4644f7ec340bSmacallan
46452a75d1c4Smrg	# Install the libtool object if requested.
46462a75d1c4Smrg	test -n "$destfile" && \
46472a75d1c4Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4648f7ec340bSmacallan
46492a75d1c4Smrg	# Install the old object if enabled.
465066ab3337Smrg	if test yes = "$build_old_libs"; then
46512a75d1c4Smrg	  # Deduce the name of the old-style object file.
46522a75d1c4Smrg	  func_lo2o "$file"
46532a75d1c4Smrg	  staticobj=$func_lo2o_result
46542a75d1c4Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
46552a75d1c4Smrg	fi
46562a75d1c4Smrg	exit $EXIT_SUCCESS
46572a75d1c4Smrg	;;
4658f7ec340bSmacallan
46592a75d1c4Smrg      *)
46602a75d1c4Smrg	# Figure out destination file name, if it wasn't already specified.
46612a75d1c4Smrg	if test -n "$destname"; then
466266ab3337Smrg	  destfile=$destdir/$destname
46632a75d1c4Smrg	else
46642a75d1c4Smrg	  func_basename "$file"
466566ab3337Smrg	  destfile=$func_basename_result
466666ab3337Smrg	  destfile=$destdir/$destfile
46672a75d1c4Smrg	fi
4668f7ec340bSmacallan
46692a75d1c4Smrg	# If the file is missing, and there is a .exe on the end, strip it
46702a75d1c4Smrg	# because it is most likely a libtool script we actually want to
46712a75d1c4Smrg	# install
467266ab3337Smrg	stripped_ext=
46732a75d1c4Smrg	case $file in
46742a75d1c4Smrg	  *.exe)
46752a75d1c4Smrg	    if test ! -f "$file"; then
46762a75d1c4Smrg	      func_stripname '' '.exe' "$file"
46772a75d1c4Smrg	      file=$func_stripname_result
467866ab3337Smrg	      stripped_ext=.exe
46792a75d1c4Smrg	    fi
46802a75d1c4Smrg	    ;;
46812a75d1c4Smrg	esac
4682f7ec340bSmacallan
46832a75d1c4Smrg	# Do a test to see if this is really a libtool program.
46842a75d1c4Smrg	case $host in
46852a75d1c4Smrg	*cygwin* | *mingw*)
46862a75d1c4Smrg	    if func_ltwrapper_executable_p "$file"; then
46872a75d1c4Smrg	      func_ltwrapper_scriptname "$file"
46882a75d1c4Smrg	      wrapper=$func_ltwrapper_scriptname_result
46892a75d1c4Smrg	    else
46902a75d1c4Smrg	      func_stripname '' '.exe' "$file"
46912a75d1c4Smrg	      wrapper=$func_stripname_result
46922a75d1c4Smrg	    fi
46932a75d1c4Smrg	    ;;
46942a75d1c4Smrg	*)
46952a75d1c4Smrg	    wrapper=$file
46962a75d1c4Smrg	    ;;
46972a75d1c4Smrg	esac
46982a75d1c4Smrg	if func_ltwrapper_script_p "$wrapper"; then
46992a75d1c4Smrg	  notinst_deplibs=
47002a75d1c4Smrg	  relink_command=
4701f7ec340bSmacallan
47022a75d1c4Smrg	  func_source "$wrapper"
4703f7ec340bSmacallan
47042a75d1c4Smrg	  # Check the variables that should have been set.
47052a75d1c4Smrg	  test -z "$generated_by_libtool_version" && \
470666ab3337Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707f7ec340bSmacallan
470866ab3337Smrg	  finalize=:
47092a75d1c4Smrg	  for lib in $notinst_deplibs; do
47102a75d1c4Smrg	    # Check to see that each library is installed.
47112a75d1c4Smrg	    libdir=
47122a75d1c4Smrg	    if test -f "$lib"; then
47132a75d1c4Smrg	      func_source "$lib"
47142a75d1c4Smrg	    fi
471566ab3337Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
47162a75d1c4Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
471766ab3337Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
471866ab3337Smrg	      finalize=false
47192a75d1c4Smrg	    fi
47202a75d1c4Smrg	  done
4721f7ec340bSmacallan
47222a75d1c4Smrg	  relink_command=
47232a75d1c4Smrg	  func_source "$wrapper"
47242a75d1c4Smrg
47252a75d1c4Smrg	  outputname=
472666ab3337Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
47272a75d1c4Smrg	    $opt_dry_run || {
472866ab3337Smrg	      if $finalize; then
47292a75d1c4Smrg	        tmpdir=`func_mktempdir`
47302a75d1c4Smrg		func_basename "$file$stripped_ext"
473166ab3337Smrg		file=$func_basename_result
473266ab3337Smrg	        outputname=$tmpdir/$file
47332a75d1c4Smrg	        # Replace the output file specification.
47342a75d1c4Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
47352a75d1c4Smrg
473666ab3337Smrg	        $opt_quiet || {
473766ab3337Smrg	          func_quote_arg expand,pretty "$relink_command"
473866ab3337Smrg		  eval "func_echo $func_quote_arg_result"
47392a75d1c4Smrg	        }
47402a75d1c4Smrg	        if eval "$relink_command"; then :
47412a75d1c4Smrg	          else
474266ab3337Smrg		  func_error "error: relink '$file' with the above command before installing it"
47432a75d1c4Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
47442a75d1c4Smrg		  continue
47452a75d1c4Smrg	        fi
474666ab3337Smrg	        file=$outputname
47472a75d1c4Smrg	      else
474866ab3337Smrg	        func_warning "cannot relink '$file'"
47492a75d1c4Smrg	      fi
47502a75d1c4Smrg	    }
47512a75d1c4Smrg	  else
47522a75d1c4Smrg	    # Install the binary that we compiled earlier.
47532a75d1c4Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
47542a75d1c4Smrg	  fi
4755f7ec340bSmacallan	fi
47562a75d1c4Smrg
47572a75d1c4Smrg	# remove .exe since cygwin /usr/bin/install will append another
47582a75d1c4Smrg	# one anyway
47592a75d1c4Smrg	case $install_prog,$host in
47602a75d1c4Smrg	*/usr/bin/install*,*cygwin*)
47612a75d1c4Smrg	  case $file:$destfile in
47622a75d1c4Smrg	  *.exe:*.exe)
47632a75d1c4Smrg	    # this is ok
47642a75d1c4Smrg	    ;;
47652a75d1c4Smrg	  *.exe:*)
47662a75d1c4Smrg	    destfile=$destfile.exe
47672a75d1c4Smrg	    ;;
47682a75d1c4Smrg	  *:*.exe)
47692a75d1c4Smrg	    func_stripname '' '.exe' "$destfile"
47702a75d1c4Smrg	    destfile=$func_stripname_result
47712a75d1c4Smrg	    ;;
47722a75d1c4Smrg	  esac
47732a75d1c4Smrg	  ;;
47742a75d1c4Smrg	esac
47752a75d1c4Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
47762a75d1c4Smrg	$opt_dry_run || if test -n "$outputname"; then
47772a75d1c4Smrg	  ${RM}r "$tmpdir"
4778f7ec340bSmacallan	fi
4779f7ec340bSmacallan	;;
4780f7ec340bSmacallan      esac
47812a75d1c4Smrg    done
4782f7ec340bSmacallan
47832a75d1c4Smrg    for file in $staticlibs; do
47842a75d1c4Smrg      func_basename "$file"
478566ab3337Smrg      name=$func_basename_result
4786f7ec340bSmacallan
47872a75d1c4Smrg      # Set up the ranlib parameters.
478866ab3337Smrg      oldlib=$destdir/$name
478966ab3337Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
479066ab3337Smrg      tool_oldlib=$func_to_tool_file_result
4791f7ec340bSmacallan
47922a75d1c4Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
47932a75d1c4Smrg
47942a75d1c4Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
479566ab3337Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796f7ec340bSmacallan      fi
4797f7ec340bSmacallan
47982a75d1c4Smrg      # Do each command in the postinstall commands.
47992a75d1c4Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
48002a75d1c4Smrg    done
4801f7ec340bSmacallan
48022a75d1c4Smrg    test -n "$future_libdirs" && \
480366ab3337Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804f7ec340bSmacallan
48052a75d1c4Smrg    if test -n "$current_libdirs"; then
48062a75d1c4Smrg      # Maybe just do a dry run.
48072a75d1c4Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
480866ab3337Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
48092a75d1c4Smrg    else
48102a75d1c4Smrg      exit $EXIT_SUCCESS
48112a75d1c4Smrg    fi
48122a75d1c4Smrg}
4813f7ec340bSmacallan
481466ab3337Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815f7ec340bSmacallan
4816f7ec340bSmacallan
48172a75d1c4Smrg# func_generate_dlsyms outputname originator pic_p
48182a75d1c4Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
48192a75d1c4Smrg# a dlpreopen symbol table.
48202a75d1c4Smrgfunc_generate_dlsyms ()
48212a75d1c4Smrg{
482266ab3337Smrg    $debug_cmd
482366ab3337Smrg
482466ab3337Smrg    my_outputname=$1
482566ab3337Smrg    my_originator=$2
482666ab3337Smrg    my_pic_p=${3-false}
482766ab3337Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
48282a75d1c4Smrg    my_dlsyms=
48292a75d1c4Smrg
483066ab3337Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
48312a75d1c4Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
483266ab3337Smrg	my_dlsyms=${my_outputname}S.c
48332a75d1c4Smrg      else
48342a75d1c4Smrg	func_error "not configured to extract global symbols from dlpreopened files"
48352a75d1c4Smrg      fi
48362a75d1c4Smrg    fi
4837f7ec340bSmacallan
48382a75d1c4Smrg    if test -n "$my_dlsyms"; then
48392a75d1c4Smrg      case $my_dlsyms in
48402a75d1c4Smrg      "") ;;
48412a75d1c4Smrg      *.c)
48422a75d1c4Smrg	# Discover the nlist of each of the dlfiles.
484366ab3337Smrg	nlist=$output_objdir/$my_outputname.nm
4844f7ec340bSmacallan
48452a75d1c4Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846f7ec340bSmacallan
48472a75d1c4Smrg	# Parse the name list into a source file.
48482a75d1c4Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849f7ec340bSmacallan
48502a75d1c4Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
485166ab3337Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
485266ab3337Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853f7ec340bSmacallan
48542a75d1c4Smrg#ifdef __cplusplus
48552a75d1c4Smrgextern \"C\" {
48562a75d1c4Smrg#endif
4857f7ec340bSmacallan
485866ab3337Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
48592a75d1c4Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
48602a75d1c4Smrg#endif
4861f7ec340bSmacallan
48622a75d1c4Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
486366ab3337Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
486466ab3337Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
48652a75d1c4Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
48662a75d1c4Smrg# define LT_DLSYM_CONST
486766ab3337Smrg#elif defined __osf__
48682a75d1c4Smrg/* This system does not cope well with relocations in const data.  */
48692a75d1c4Smrg# define LT_DLSYM_CONST
48702a75d1c4Smrg#else
48712a75d1c4Smrg# define LT_DLSYM_CONST const
48722a75d1c4Smrg#endif
4873f7ec340bSmacallan
487466ab3337Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
487566ab3337Smrg
48762a75d1c4Smrg/* External symbol declarations for the compiler. */\
48772a75d1c4Smrg"
4878f7ec340bSmacallan
487966ab3337Smrg	if test yes = "$dlself"; then
488066ab3337Smrg	  func_verbose "generating symbol list for '$output'"
4881f7ec340bSmacallan
48822a75d1c4Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4883f7ec340bSmacallan
48842a75d1c4Smrg	  # Add our own program objects to the symbol list.
48852a75d1c4Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
48862a75d1c4Smrg	  for progfile in $progfiles; do
48872a75d1c4Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
488866ab3337Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
48892a75d1c4Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890f7ec340bSmacallan	  done
4891f7ec340bSmacallan
48922a75d1c4Smrg	  if test -n "$exclude_expsyms"; then
48932a75d1c4Smrg	    $opt_dry_run || {
48942a75d1c4Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
48952a75d1c4Smrg	      eval '$MV "$nlist"T "$nlist"'
48962a75d1c4Smrg	    }
48972a75d1c4Smrg	  fi
4898f7ec340bSmacallan
48992a75d1c4Smrg	  if test -n "$export_symbols_regex"; then
49002a75d1c4Smrg	    $opt_dry_run || {
49012a75d1c4Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
49022a75d1c4Smrg	      eval '$MV "$nlist"T "$nlist"'
49032a75d1c4Smrg	    }
49042a75d1c4Smrg	  fi
4905f7ec340bSmacallan
49062a75d1c4Smrg	  # Prepare the list of exported symbols
49072a75d1c4Smrg	  if test -z "$export_symbols"; then
490866ab3337Smrg	    export_symbols=$output_objdir/$outputname.exp
49092a75d1c4Smrg	    $opt_dry_run || {
49102a75d1c4Smrg	      $RM $export_symbols
491166ab3337Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
49122a75d1c4Smrg	      case $host in
49132a75d1c4Smrg	      *cygwin* | *mingw* | *cegcc* )
49142a75d1c4Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49152a75d1c4Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
49162a75d1c4Smrg	        ;;
49172a75d1c4Smrg	      esac
49182a75d1c4Smrg	    }
49192a75d1c4Smrg	  else
49202a75d1c4Smrg	    $opt_dry_run || {
492166ab3337Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
49222a75d1c4Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
49232a75d1c4Smrg	      eval '$MV "$nlist"T "$nlist"'
49242a75d1c4Smrg	      case $host in
49252a75d1c4Smrg	        *cygwin* | *mingw* | *cegcc* )
49262a75d1c4Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49272a75d1c4Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
49282a75d1c4Smrg	          ;;
49292a75d1c4Smrg	      esac
49302a75d1c4Smrg	    }
49312a75d1c4Smrg	  fi
49322a75d1c4Smrg	fi
4933f7ec340bSmacallan
49342a75d1c4Smrg	for dlprefile in $dlprefiles; do
493566ab3337Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
49362a75d1c4Smrg	  func_basename "$dlprefile"
493766ab3337Smrg	  name=$func_basename_result
49382a75d1c4Smrg          case $host in
49392a75d1c4Smrg	    *cygwin* | *mingw* | *cegcc* )
49402a75d1c4Smrg	      # if an import library, we need to obtain dlname
49412a75d1c4Smrg	      if func_win32_import_lib_p "$dlprefile"; then
49422a75d1c4Smrg	        func_tr_sh "$dlprefile"
49432a75d1c4Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
494466ab3337Smrg	        dlprefile_dlbasename=
49452a75d1c4Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
49462a75d1c4Smrg	          # Use subshell, to avoid clobbering current variable values
49472a75d1c4Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
494866ab3337Smrg	          if test -n "$dlprefile_dlname"; then
49492a75d1c4Smrg	            func_basename "$dlprefile_dlname"
495066ab3337Smrg	            dlprefile_dlbasename=$func_basename_result
49512a75d1c4Smrg	          else
49522a75d1c4Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
49532a75d1c4Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
49542a75d1c4Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
49552a75d1c4Smrg	          fi
49562a75d1c4Smrg	        fi
49572a75d1c4Smrg	        $opt_dry_run || {
495866ab3337Smrg	          if test -n "$dlprefile_dlbasename"; then
49592a75d1c4Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
49602a75d1c4Smrg	          else
49612a75d1c4Smrg	            func_warning "Could not compute DLL name from $name"
49622a75d1c4Smrg	            eval '$ECHO ": $name " >> "$nlist"'
49632a75d1c4Smrg	          fi
49642a75d1c4Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49652a75d1c4Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
49662a75d1c4Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
49672a75d1c4Smrg	        }
49682a75d1c4Smrg	      else # not an import lib
49692a75d1c4Smrg	        $opt_dry_run || {
49702a75d1c4Smrg	          eval '$ECHO ": $name " >> "$nlist"'
49712a75d1c4Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49722a75d1c4Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49732a75d1c4Smrg	        }
49742a75d1c4Smrg	      fi
49752a75d1c4Smrg	    ;;
49762a75d1c4Smrg	    *)
49772a75d1c4Smrg	      $opt_dry_run || {
49782a75d1c4Smrg	        eval '$ECHO ": $name " >> "$nlist"'
49792a75d1c4Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
49802a75d1c4Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
49812a75d1c4Smrg	      }
49822a75d1c4Smrg	    ;;
49832a75d1c4Smrg          esac
49842a75d1c4Smrg	done
4985f7ec340bSmacallan
49862a75d1c4Smrg	$opt_dry_run || {
49872a75d1c4Smrg	  # Make sure we have at least an empty file.
49882a75d1c4Smrg	  test -f "$nlist" || : > "$nlist"
4989f7ec340bSmacallan
49902a75d1c4Smrg	  if test -n "$exclude_expsyms"; then
49912a75d1c4Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
49922a75d1c4Smrg	    $MV "$nlist"T "$nlist"
49932a75d1c4Smrg	  fi
4994f7ec340bSmacallan
49952a75d1c4Smrg	  # Try sorting and uniquifying the output.
49962a75d1c4Smrg	  if $GREP -v "^: " < "$nlist" |
49972a75d1c4Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
49982a75d1c4Smrg		sort -k 3
49992a75d1c4Smrg	      else
50002a75d1c4Smrg		sort +2
50012a75d1c4Smrg	      fi |
50022a75d1c4Smrg	      uniq > "$nlist"S; then
50032a75d1c4Smrg	    :
50042a75d1c4Smrg	  else
50052a75d1c4Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
50062a75d1c4Smrg	  fi
5007f7ec340bSmacallan
50082a75d1c4Smrg	  if test -f "$nlist"S; then
50092a75d1c4Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
50102a75d1c4Smrg	  else
50112a75d1c4Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
50122a75d1c4Smrg	  fi
5013f7ec340bSmacallan
501466ab3337Smrg	  func_show_eval '$RM "${nlist}I"'
501566ab3337Smrg	  if test -n "$global_symbol_to_import"; then
501666ab3337Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
501766ab3337Smrg	  fi
501866ab3337Smrg
50192a75d1c4Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50202a75d1c4Smrg
50212a75d1c4Smrg/* The mapping between symbol names and symbols.  */
50222a75d1c4Smrgtypedef struct {
50232a75d1c4Smrg  const char *name;
50242a75d1c4Smrg  void *address;
50252a75d1c4Smrg} lt_dlsymlist;
50262a75d1c4Smrgextern LT_DLSYM_CONST lt_dlsymlist
502766ab3337Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
502866ab3337Smrg"
502966ab3337Smrg
503066ab3337Smrg	  if test -s "$nlist"I; then
503166ab3337Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
503266ab3337Smrgstatic void lt_syminit(void)
503366ab3337Smrg{
503466ab3337Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
503566ab3337Smrg  for (; symbol->name; ++symbol)
503666ab3337Smrg    {"
503766ab3337Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
503866ab3337Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
503966ab3337Smrg    }
504066ab3337Smrg}"
504166ab3337Smrg	  fi
504266ab3337Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50432a75d1c4SmrgLT_DLSYM_CONST lt_dlsymlist
50442a75d1c4Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
504566ab3337Smrg{ {\"$my_originator\", (void *) 0},"
504666ab3337Smrg
504766ab3337Smrg	  if test -s "$nlist"I; then
504866ab3337Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
504966ab3337Smrg  {\"@INIT@\", (void *) &lt_syminit},"
505066ab3337Smrg	  fi
50512a75d1c4Smrg
50522a75d1c4Smrg	  case $need_lib_prefix in
50532a75d1c4Smrg	  no)
50542a75d1c4Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055f7ec340bSmacallan	    ;;
5056f7ec340bSmacallan	  *)
50572a75d1c4Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058f7ec340bSmacallan	    ;;
5059f7ec340bSmacallan	  esac
50602a75d1c4Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50612a75d1c4Smrg  {0, (void *) 0}
50622a75d1c4Smrg};
5063f7ec340bSmacallan
50642a75d1c4Smrg/* This works around a problem in FreeBSD linker */
50652a75d1c4Smrg#ifdef FREEBSD_WORKAROUND
50662a75d1c4Smrgstatic const void *lt_preloaded_setup() {
50672a75d1c4Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
50682a75d1c4Smrg}
50692a75d1c4Smrg#endif
5070f7ec340bSmacallan
50712a75d1c4Smrg#ifdef __cplusplus
50722a75d1c4Smrg}
50732a75d1c4Smrg#endif\
50742a75d1c4Smrg"
50752a75d1c4Smrg	} # !$opt_dry_run
5076f7ec340bSmacallan
50772a75d1c4Smrg	pic_flag_for_symtable=
50782a75d1c4Smrg	case "$compile_command " in
50792a75d1c4Smrg	*" -static "*) ;;
50802a75d1c4Smrg	*)
50812a75d1c4Smrg	  case $host in
50822a75d1c4Smrg	  # compiling the symbol table file with pic_flag works around
50832a75d1c4Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
50842a75d1c4Smrg	  # linked before any other PIC object.  But we must not use
50852a75d1c4Smrg	  # pic_flag when linking with -static.  The problem exists in
50862a75d1c4Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
508766ab3337Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
50882a75d1c4Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
50892a75d1c4Smrg	  *-*-hpux*)
50902a75d1c4Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
50912a75d1c4Smrg	  *)
509266ab3337Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
50932a75d1c4Smrg	    ;;
50942a75d1c4Smrg	  esac
50952a75d1c4Smrg	  ;;
50962a75d1c4Smrg	esac
50972a75d1c4Smrg	symtab_cflags=
50982a75d1c4Smrg	for arg in $LTCFLAGS; do
50992a75d1c4Smrg	  case $arg in
51002a75d1c4Smrg	  -pie | -fpie | -fPIE) ;;
51012a75d1c4Smrg	  *) func_append symtab_cflags " $arg" ;;
5102f7ec340bSmacallan	  esac
5103f7ec340bSmacallan	done
5104f7ec340bSmacallan
51052a75d1c4Smrg	# Now compile the dynamic symbol file.
51062a75d1c4Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107f7ec340bSmacallan
51082a75d1c4Smrg	# Clean up the generated files.
510966ab3337Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110f7ec340bSmacallan
51112a75d1c4Smrg	# Transform the symbol file into the correct name.
511266ab3337Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
51132a75d1c4Smrg	case $host in
51142a75d1c4Smrg	*cygwin* | *mingw* | *cegcc* )
51152a75d1c4Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
51162a75d1c4Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51172a75d1c4Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51182a75d1c4Smrg	  else
51192a75d1c4Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51202a75d1c4Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51212a75d1c4Smrg	  fi
51222a75d1c4Smrg	  ;;
51232a75d1c4Smrg	*)
51242a75d1c4Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51252a75d1c4Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51262a75d1c4Smrg	  ;;
51272a75d1c4Smrg	esac
51282a75d1c4Smrg	;;
51292a75d1c4Smrg      *)
513066ab3337Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
51312a75d1c4Smrg	;;
51322a75d1c4Smrg      esac
51332a75d1c4Smrg    else
51342a75d1c4Smrg      # We keep going just in case the user didn't refer to
51352a75d1c4Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
51362a75d1c4Smrg      # really was required.
5137f7ec340bSmacallan
51382a75d1c4Smrg      # Nullify the symbol file.
51392a75d1c4Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
51402a75d1c4Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
51412a75d1c4Smrg    fi
51422a75d1c4Smrg}
5143f7ec340bSmacallan
514466ab3337Smrg# func_cygming_gnu_implib_p ARG
514566ab3337Smrg# This predicate returns with zero status (TRUE) if
514666ab3337Smrg# ARG is a GNU/binutils-style import library. Returns
514766ab3337Smrg# with nonzero status (FALSE) otherwise.
514866ab3337Smrgfunc_cygming_gnu_implib_p ()
514966ab3337Smrg{
515066ab3337Smrg  $debug_cmd
515166ab3337Smrg
515266ab3337Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
515366ab3337Smrg  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)$'`
515466ab3337Smrg  test -n "$func_cygming_gnu_implib_tmp"
515566ab3337Smrg}
515666ab3337Smrg
515766ab3337Smrg# func_cygming_ms_implib_p ARG
515866ab3337Smrg# This predicate returns with zero status (TRUE) if
515966ab3337Smrg# ARG is an MS-style import library. Returns
516066ab3337Smrg# with nonzero status (FALSE) otherwise.
516166ab3337Smrgfunc_cygming_ms_implib_p ()
516266ab3337Smrg{
516366ab3337Smrg  $debug_cmd
516466ab3337Smrg
516566ab3337Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
516666ab3337Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
516766ab3337Smrg  test -n "$func_cygming_ms_implib_tmp"
516866ab3337Smrg}
516966ab3337Smrg
51702a75d1c4Smrg# func_win32_libid arg
51712a75d1c4Smrg# return the library type of file 'arg'
51722a75d1c4Smrg#
51732a75d1c4Smrg# Need a lot of goo to handle *both* DLLs and import libs
51742a75d1c4Smrg# Has to be a shell function in order to 'eat' the argument
51752a75d1c4Smrg# that is supplied when $file_magic_command is called.
51762a75d1c4Smrg# Despite the name, also deal with 64 bit binaries.
51772a75d1c4Smrgfunc_win32_libid ()
51782a75d1c4Smrg{
517966ab3337Smrg  $debug_cmd
518066ab3337Smrg
518166ab3337Smrg  win32_libid_type=unknown
51822a75d1c4Smrg  win32_fileres=`file -L $1 2>/dev/null`
51832a75d1c4Smrg  case $win32_fileres in
51842a75d1c4Smrg  *ar\ archive\ import\ library*) # definitely import
51852a75d1c4Smrg    win32_libid_type="x86 archive import"
51862a75d1c4Smrg    ;;
51872a75d1c4Smrg  *ar\ archive*) # could be an import, or static
51882a75d1c4Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
51892a75d1c4Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
51902a75d1c4Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
519166ab3337Smrg      case $nm_interface in
519266ab3337Smrg      "MS dumpbin")
519366ab3337Smrg	if func_cygming_ms_implib_p "$1" ||
519466ab3337Smrg	   func_cygming_gnu_implib_p "$1"
519566ab3337Smrg	then
519666ab3337Smrg	  win32_nmres=import
519766ab3337Smrg	else
519866ab3337Smrg	  win32_nmres=
519966ab3337Smrg	fi
520066ab3337Smrg	;;
520166ab3337Smrg      *)
520266ab3337Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
520366ab3337Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
520466ab3337Smrg	  $SED -n -e '
52052a75d1c4Smrg	    1,100{
52062a75d1c4Smrg		/ I /{
520766ab3337Smrg		    s|.*|import|
52082a75d1c4Smrg		    p
52092a75d1c4Smrg		    q
52102a75d1c4Smrg		}
52112a75d1c4Smrg	    }'`
521266ab3337Smrg	;;
521366ab3337Smrg      esac
52142a75d1c4Smrg      case $win32_nmres in
52152a75d1c4Smrg      import*)  win32_libid_type="x86 archive import";;
52162a75d1c4Smrg      *)        win32_libid_type="x86 archive static";;
52172a75d1c4Smrg      esac
52182a75d1c4Smrg    fi
52192a75d1c4Smrg    ;;
52202a75d1c4Smrg  *DLL*)
52212a75d1c4Smrg    win32_libid_type="x86 DLL"
52222a75d1c4Smrg    ;;
52232a75d1c4Smrg  *executable*) # but shell scripts are "executable" too...
52242a75d1c4Smrg    case $win32_fileres in
52252a75d1c4Smrg    *MS\ Windows\ PE\ Intel*)
52262a75d1c4Smrg      win32_libid_type="x86 DLL"
52272a75d1c4Smrg      ;;
52282a75d1c4Smrg    esac
52292a75d1c4Smrg    ;;
52302a75d1c4Smrg  esac
52312a75d1c4Smrg  $ECHO "$win32_libid_type"
52322a75d1c4Smrg}
52332a75d1c4Smrg
52342a75d1c4Smrg# func_cygming_dll_for_implib ARG
52352a75d1c4Smrg#
52362a75d1c4Smrg# Platform-specific function to extract the
52372a75d1c4Smrg# name of the DLL associated with the specified
52382a75d1c4Smrg# import library ARG.
52392a75d1c4Smrg# Invoked by eval'ing the libtool variable
52402a75d1c4Smrg#    $sharedlib_from_linklib_cmd
52412a75d1c4Smrg# Result is available in the variable
52422a75d1c4Smrg#    $sharedlib_from_linklib_result
52432a75d1c4Smrgfunc_cygming_dll_for_implib ()
52442a75d1c4Smrg{
524566ab3337Smrg  $debug_cmd
524666ab3337Smrg
52472a75d1c4Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
52482a75d1c4Smrg}
52492a75d1c4Smrg
52502a75d1c4Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
52512a75d1c4Smrg#
52522a75d1c4Smrg# The is the core of a fallback implementation of a
52532a75d1c4Smrg# platform-specific function to extract the name of the
52542a75d1c4Smrg# DLL associated with the specified import library LIBNAME.
52552a75d1c4Smrg#
52562a75d1c4Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
52572a75d1c4Smrg# on the platform and compiler that created the implib.
52582a75d1c4Smrg#
52592a75d1c4Smrg# Echos the name of the DLL associated with the
52602a75d1c4Smrg# specified import library.
52612a75d1c4Smrgfunc_cygming_dll_for_implib_fallback_core ()
52622a75d1c4Smrg{
526366ab3337Smrg  $debug_cmd
526466ab3337Smrg
52652a75d1c4Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
52662a75d1c4Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
52672a75d1c4Smrg    $SED '/^Contents of section '"$match_literal"':/{
52682a75d1c4Smrg      # Place marker at beginning of archive member dllname section
52692a75d1c4Smrg      s/.*/====MARK====/
52702a75d1c4Smrg      p
52712a75d1c4Smrg      d
52722a75d1c4Smrg    }
52732a75d1c4Smrg    # These lines can sometimes be longer than 43 characters, but
52742a75d1c4Smrg    # are always uninteresting
52752a75d1c4Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
52762a75d1c4Smrg    /^In archive [^:]*:/d
52772a75d1c4Smrg    # Ensure marker is printed
52782a75d1c4Smrg    /^====MARK====/p
52792a75d1c4Smrg    # Remove all lines with less than 43 characters
52802a75d1c4Smrg    /^.\{43\}/!d
52812a75d1c4Smrg    # From remaining lines, remove first 43 characters
52822a75d1c4Smrg    s/^.\{43\}//' |
52832a75d1c4Smrg    $SED -n '
52842a75d1c4Smrg      # Join marker and all lines until next marker into a single line
52852a75d1c4Smrg      /^====MARK====/ b para
52862a75d1c4Smrg      H
52872a75d1c4Smrg      $ b para
52882a75d1c4Smrg      b
52892a75d1c4Smrg      :para
52902a75d1c4Smrg      x
52912a75d1c4Smrg      s/\n//g
52922a75d1c4Smrg      # Remove the marker
52932a75d1c4Smrg      s/^====MARK====//
52942a75d1c4Smrg      # Remove trailing dots and whitespace
52952a75d1c4Smrg      s/[\. \t]*$//
52962a75d1c4Smrg      # Print
52972a75d1c4Smrg      /./p' |
52982a75d1c4Smrg    # we now have a list, one entry per line, of the stringified
52992a75d1c4Smrg    # contents of the appropriate section of all members of the
530066ab3337Smrg    # archive that possess that section. Heuristic: eliminate
530166ab3337Smrg    # all those that have a first or second character that is
53022a75d1c4Smrg    # a '.' (that is, objdump's representation of an unprintable
53032a75d1c4Smrg    # character.) This should work for all archives with less than
53042a75d1c4Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
53052a75d1c4Smrg    # begins with a literal '.' or a single character followed by
53062a75d1c4Smrg    # a '.'.
53072a75d1c4Smrg    #
53082a75d1c4Smrg    # Of those that remain, print the first one.
53092a75d1c4Smrg    $SED -e '/^\./d;/^.\./d;q'
53102a75d1c4Smrg}
53112a75d1c4Smrg
53122a75d1c4Smrg# func_cygming_dll_for_implib_fallback ARG
53132a75d1c4Smrg# Platform-specific function to extract the
53142a75d1c4Smrg# name of the DLL associated with the specified
53152a75d1c4Smrg# import library ARG.
53162a75d1c4Smrg#
53172a75d1c4Smrg# This fallback implementation is for use when $DLLTOOL
53182a75d1c4Smrg# does not support the --identify-strict option.
53192a75d1c4Smrg# Invoked by eval'ing the libtool variable
53202a75d1c4Smrg#    $sharedlib_from_linklib_cmd
53212a75d1c4Smrg# Result is available in the variable
53222a75d1c4Smrg#    $sharedlib_from_linklib_result
53232a75d1c4Smrgfunc_cygming_dll_for_implib_fallback ()
53242a75d1c4Smrg{
532566ab3337Smrg  $debug_cmd
532666ab3337Smrg
532766ab3337Smrg  if func_cygming_gnu_implib_p "$1"; then
53282a75d1c4Smrg    # binutils import library
53292a75d1c4Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
533066ab3337Smrg  elif func_cygming_ms_implib_p "$1"; then
53312a75d1c4Smrg    # ms-generated import library
53322a75d1c4Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
53332a75d1c4Smrg  else
53342a75d1c4Smrg    # unknown
533566ab3337Smrg    sharedlib_from_linklib_result=
53362a75d1c4Smrg  fi
53372a75d1c4Smrg}
53382a75d1c4Smrg
53392a75d1c4Smrg
53402a75d1c4Smrg# func_extract_an_archive dir oldlib
53412a75d1c4Smrgfunc_extract_an_archive ()
53422a75d1c4Smrg{
534366ab3337Smrg    $debug_cmd
534466ab3337Smrg
534566ab3337Smrg    f_ex_an_ar_dir=$1; shift
534666ab3337Smrg    f_ex_an_ar_oldlib=$1
534766ab3337Smrg    if test yes = "$lock_old_archive_extraction"; then
53482a75d1c4Smrg      lockfile=$f_ex_an_ar_oldlib.lock
53492a75d1c4Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
53502a75d1c4Smrg	func_echo "Waiting for $lockfile to be removed"
53512a75d1c4Smrg	sleep 2
5352f7ec340bSmacallan      done
53532a75d1c4Smrg    fi
53542a75d1c4Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
53552a75d1c4Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
535666ab3337Smrg    if test yes = "$lock_old_archive_extraction"; then
53572a75d1c4Smrg      $opt_dry_run || rm -f "$lockfile"
53582a75d1c4Smrg    fi
53592a75d1c4Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
53602a75d1c4Smrg     :
53612a75d1c4Smrg    else
53622a75d1c4Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
53632a75d1c4Smrg    fi
53642a75d1c4Smrg}
5365f7ec340bSmacallan
53662a75d1c4Smrg
53672a75d1c4Smrg# func_extract_archives gentop oldlib ...
53682a75d1c4Smrgfunc_extract_archives ()
53692a75d1c4Smrg{
537066ab3337Smrg    $debug_cmd
537166ab3337Smrg
537266ab3337Smrg    my_gentop=$1; shift
53732a75d1c4Smrg    my_oldlibs=${1+"$@"}
537466ab3337Smrg    my_oldobjs=
537566ab3337Smrg    my_xlib=
537666ab3337Smrg    my_xabs=
537766ab3337Smrg    my_xdir=
53782a75d1c4Smrg
53792a75d1c4Smrg    for my_xlib in $my_oldlibs; do
53802a75d1c4Smrg      # Extract the objects.
53812a75d1c4Smrg      case $my_xlib in
538266ab3337Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
53832a75d1c4Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
53842a75d1c4Smrg      esac
53852a75d1c4Smrg      func_basename "$my_xlib"
538666ab3337Smrg      my_xlib=$func_basename_result
53872a75d1c4Smrg      my_xlib_u=$my_xlib
53882a75d1c4Smrg      while :; do
53892a75d1c4Smrg        case " $extracted_archives " in
53902a75d1c4Smrg	*" $my_xlib_u "*)
53912a75d1c4Smrg	  func_arith $extracted_serial + 1
53922a75d1c4Smrg	  extracted_serial=$func_arith_result
53932a75d1c4Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
53942a75d1c4Smrg	*) break ;;
5395f7ec340bSmacallan	esac
5396f7ec340bSmacallan      done
53972a75d1c4Smrg      extracted_archives="$extracted_archives $my_xlib_u"
539866ab3337Smrg      my_xdir=$my_gentop/$my_xlib_u
5399f7ec340bSmacallan
54002a75d1c4Smrg      func_mkdir_p "$my_xdir"
5401f7ec340bSmacallan
54022a75d1c4Smrg      case $host in
54032a75d1c4Smrg      *-darwin*)
54042a75d1c4Smrg	func_verbose "Extracting $my_xabs"
54052a75d1c4Smrg	# Do not bother doing anything if just a dry run
54062a75d1c4Smrg	$opt_dry_run || {
54072a75d1c4Smrg	  darwin_orig_dir=`pwd`
54082a75d1c4Smrg	  cd $my_xdir || exit $?
54092a75d1c4Smrg	  darwin_archive=$my_xabs
54102a75d1c4Smrg	  darwin_curdir=`pwd`
541166ab3337Smrg	  func_basename "$darwin_archive"
541266ab3337Smrg	  darwin_base_archive=$func_basename_result
54132a75d1c4Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
54142a75d1c4Smrg	  if test -n "$darwin_arches"; then
54152a75d1c4Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
54162a75d1c4Smrg	    darwin_arch=
54172a75d1c4Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
541866ab3337Smrg	    for darwin_arch in  $darwin_arches; do
541966ab3337Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
542066ab3337Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
542166ab3337Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
542266ab3337Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
54232a75d1c4Smrg	      cd "$darwin_curdir"
542466ab3337Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
54252a75d1c4Smrg	    done # $darwin_arches
54262a75d1c4Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
542766ab3337Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
54282a75d1c4Smrg	    darwin_file=
54292a75d1c4Smrg	    darwin_files=
54302a75d1c4Smrg	    for darwin_file in $darwin_filelist; do
54312a75d1c4Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
54322a75d1c4Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
54332a75d1c4Smrg	    done # $darwin_filelist
54342a75d1c4Smrg	    $RM -rf unfat-$$
54352a75d1c4Smrg	    cd "$darwin_orig_dir"
5436f7ec340bSmacallan	  else
54372a75d1c4Smrg	    cd $darwin_orig_dir
54382a75d1c4Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
54392a75d1c4Smrg	  fi # $darwin_arches
54402a75d1c4Smrg	} # !$opt_dry_run
54412a75d1c4Smrg	;;
54422a75d1c4Smrg      *)
54432a75d1c4Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
54442a75d1c4Smrg	;;
54452a75d1c4Smrg      esac
54462a75d1c4Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
54472a75d1c4Smrg    done
5448f7ec340bSmacallan
544966ab3337Smrg    func_extract_archives_result=$my_oldobjs
54502a75d1c4Smrg}
5451f7ec340bSmacallan
5452f7ec340bSmacallan
54532a75d1c4Smrg# func_emit_wrapper [arg=no]
54542a75d1c4Smrg#
54552a75d1c4Smrg# Emit a libtool wrapper script on stdout.
54562a75d1c4Smrg# Don't directly open a file because we may want to
54572a75d1c4Smrg# incorporate the script contents within a cygwin/mingw
54582a75d1c4Smrg# wrapper executable.  Must ONLY be called from within
54592a75d1c4Smrg# func_mode_link because it depends on a number of variables
54602a75d1c4Smrg# set therein.
54612a75d1c4Smrg#
54622a75d1c4Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
54632a75d1c4Smrg# variable will take.  If 'yes', then the emitted script
546466ab3337Smrg# will assume that the directory where it is stored is
54652a75d1c4Smrg# the $objdir directory.  This is a cygwin/mingw-specific
54662a75d1c4Smrg# behavior.
54672a75d1c4Smrgfunc_emit_wrapper ()
54682a75d1c4Smrg{
54692a75d1c4Smrg	func_emit_wrapper_arg1=${1-no}
5470f7ec340bSmacallan
54712a75d1c4Smrg	$ECHO "\
54722a75d1c4Smrg#! $SHELL
5473f7ec340bSmacallan
54742a75d1c4Smrg# $output - temporary wrapper script for $objdir/$outputname
547566ab3337Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
54762a75d1c4Smrg#
54772a75d1c4Smrg# The $output program cannot be directly executed until all the libtool
54782a75d1c4Smrg# libraries that it depends on are installed.
54792a75d1c4Smrg#
54802a75d1c4Smrg# This wrapper script should never be moved out of the build directory.
54812a75d1c4Smrg# If it is, it will not operate correctly.
5482f7ec340bSmacallan
54832a75d1c4Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
54842a75d1c4Smrg# metacharacters that are still active within double-quoted strings.
54852a75d1c4Smrgsed_quote_subst='$sed_quote_subst'
5486f7ec340bSmacallan
54872a75d1c4Smrg# Be Bourne compatible
54882a75d1c4Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
54892a75d1c4Smrg  emulate sh
54902a75d1c4Smrg  NULLCMD=:
54912a75d1c4Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
54922a75d1c4Smrg  # is contrary to our usage.  Disable this feature.
54932a75d1c4Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
54942a75d1c4Smrg  setopt NO_GLOB_SUBST
54952a75d1c4Smrgelse
54962a75d1c4Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
54972a75d1c4Smrgfi
54982a75d1c4SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
54992a75d1c4SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500f7ec340bSmacallan
55012a75d1c4Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
55022a75d1c4Smrg# if CDPATH is set.
55032a75d1c4Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504f7ec340bSmacallan
55052a75d1c4Smrgrelink_command=\"$relink_command\"
5506f7ec340bSmacallan
55072a75d1c4Smrg# This environment variable determines our operation mode.
55082a75d1c4Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
55092a75d1c4Smrg  # install mode needs the following variables:
55102a75d1c4Smrg  generated_by_libtool_version='$macro_version'
55112a75d1c4Smrg  notinst_deplibs='$notinst_deplibs'
55122a75d1c4Smrgelse
55132a75d1c4Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
55142a75d1c4Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
55152a75d1c4Smrg    file=\"\$0\""
5516f7ec340bSmacallan
551766ab3337Smrg    func_quote_arg pretty "$ECHO"
551866ab3337Smrg    qECHO=$func_quote_arg_result
55192a75d1c4Smrg    $ECHO "\
5520f7ec340bSmacallan
55212a75d1c4Smrg# A function that is used when there is no print builtin or printf.
55222a75d1c4Smrgfunc_fallback_echo ()
55232a75d1c4Smrg{
55242a75d1c4Smrg  eval 'cat <<_LTECHO_EOF
55252a75d1c4Smrg\$1
55262a75d1c4Smrg_LTECHO_EOF'
55272a75d1c4Smrg}
552866ab3337Smrg    ECHO=$qECHO
55292a75d1c4Smrg  fi
5530f7ec340bSmacallan
55312a75d1c4Smrg# Very basic option parsing. These options are (a) specific to
55322a75d1c4Smrg# the libtool wrapper, (b) are identical between the wrapper
553366ab3337Smrg# /script/ and the wrapper /executable/ that is used only on
55342a75d1c4Smrg# windows platforms, and (c) all begin with the string "--lt-"
553566ab3337Smrg# (application programs are unlikely to have options that match
55362a75d1c4Smrg# this pattern).
55372a75d1c4Smrg#
55382a75d1c4Smrg# There are only two supported options: --lt-debug and
55392a75d1c4Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
55402a75d1c4Smrg#
55412a75d1c4Smrg# The first argument to this parsing function should be the
55422a75d1c4Smrg# script's $0 value, followed by "$@".
55432a75d1c4Smrglt_option_debug=
55442a75d1c4Smrgfunc_parse_lt_options ()
55452a75d1c4Smrg{
55462a75d1c4Smrg  lt_script_arg0=\$0
55472a75d1c4Smrg  shift
55482a75d1c4Smrg  for lt_opt
55492a75d1c4Smrg  do
55502a75d1c4Smrg    case \"\$lt_opt\" in
55512a75d1c4Smrg    --lt-debug) lt_option_debug=1 ;;
55522a75d1c4Smrg    --lt-dump-script)
55532a75d1c4Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
55542a75d1c4Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
55552a75d1c4Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
55562a75d1c4Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
55572a75d1c4Smrg        exit 0
55582a75d1c4Smrg      ;;
55592a75d1c4Smrg    --lt-*)
55602a75d1c4Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
55612a75d1c4Smrg        exit 1
55622a75d1c4Smrg      ;;
55632a75d1c4Smrg    esac
55642a75d1c4Smrg  done
5565f7ec340bSmacallan
55662a75d1c4Smrg  # Print the debug banner immediately:
55672a75d1c4Smrg  if test -n \"\$lt_option_debug\"; then
556866ab3337Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
55692a75d1c4Smrg  fi
55702a75d1c4Smrg}
5571f7ec340bSmacallan
55722a75d1c4Smrg# Used when --lt-debug. Prints its arguments to stdout
55732a75d1c4Smrg# (redirection is the responsibility of the caller)
55742a75d1c4Smrgfunc_lt_dump_args ()
55752a75d1c4Smrg{
55762a75d1c4Smrg  lt_dump_args_N=1;
55772a75d1c4Smrg  for lt_arg
55782a75d1c4Smrg  do
557966ab3337Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
55802a75d1c4Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
55812a75d1c4Smrg  done
55822a75d1c4Smrg}
5583f7ec340bSmacallan
55842a75d1c4Smrg# Core function for launching the target application
55852a75d1c4Smrgfunc_exec_program_core ()
55862a75d1c4Smrg{
55872a75d1c4Smrg"
55882a75d1c4Smrg  case $host in
55892a75d1c4Smrg  # Backslashes separate directories on plain windows
55902a75d1c4Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
55912a75d1c4Smrg    $ECHO "\
55922a75d1c4Smrg      if test -n \"\$lt_option_debug\"; then
559366ab3337Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
55942a75d1c4Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
55952a75d1c4Smrg      fi
55962a75d1c4Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
55972a75d1c4Smrg"
55982a75d1c4Smrg    ;;
5599f7ec340bSmacallan
56002a75d1c4Smrg  *)
56012a75d1c4Smrg    $ECHO "\
56022a75d1c4Smrg      if test -n \"\$lt_option_debug\"; then
560366ab3337Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
56042a75d1c4Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
56052a75d1c4Smrg      fi
56062a75d1c4Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
56072a75d1c4Smrg"
56082a75d1c4Smrg    ;;
56092a75d1c4Smrg  esac
56102a75d1c4Smrg  $ECHO "\
56112a75d1c4Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
56122a75d1c4Smrg      exit 1
56132a75d1c4Smrg}
5614f7ec340bSmacallan
56152a75d1c4Smrg# A function to encapsulate launching the target application
56162a75d1c4Smrg# Strips options in the --lt-* namespace from \$@ and
56172a75d1c4Smrg# launches target application with the remaining arguments.
56182a75d1c4Smrgfunc_exec_program ()
56192a75d1c4Smrg{
562066ab3337Smrg  case \" \$* \" in
562166ab3337Smrg  *\\ --lt-*)
562266ab3337Smrg    for lt_wr_arg
562366ab3337Smrg    do
562466ab3337Smrg      case \$lt_wr_arg in
562566ab3337Smrg      --lt-*) ;;
562666ab3337Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
562766ab3337Smrg      esac
562866ab3337Smrg      shift
562966ab3337Smrg    done ;;
563066ab3337Smrg  esac
56312a75d1c4Smrg  func_exec_program_core \${1+\"\$@\"}
56322a75d1c4Smrg}
5633f7ec340bSmacallan
56342a75d1c4Smrg  # Parse options
56352a75d1c4Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636f7ec340bSmacallan
56372a75d1c4Smrg  # Find the directory that this script lives in.
56382a75d1c4Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
56392a75d1c4Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640f7ec340bSmacallan
56412a75d1c4Smrg  # Follow symbolic links until we get to the real thisdir.
56422a75d1c4Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
56432a75d1c4Smrg  while test -n \"\$file\"; do
56442a75d1c4Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645f7ec340bSmacallan
56462a75d1c4Smrg    # If there was a directory component, then change thisdir.
56472a75d1c4Smrg    if test \"x\$destdir\" != \"x\$file\"; then
56482a75d1c4Smrg      case \"\$destdir\" in
56492a75d1c4Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
56502a75d1c4Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
56512a75d1c4Smrg      esac
56522a75d1c4Smrg    fi
5653f7ec340bSmacallan
56542a75d1c4Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
56552a75d1c4Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
56562a75d1c4Smrg  done
5657f7ec340bSmacallan
56582a75d1c4Smrg  # Usually 'no', except on cygwin/mingw when embedded into
56592a75d1c4Smrg  # the cwrapper.
56602a75d1c4Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
56612a75d1c4Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
56622a75d1c4Smrg    # special case for '.'
56632a75d1c4Smrg    if test \"\$thisdir\" = \".\"; then
56642a75d1c4Smrg      thisdir=\`pwd\`
56652a75d1c4Smrg    fi
56662a75d1c4Smrg    # remove .libs from thisdir
56672a75d1c4Smrg    case \"\$thisdir\" in
56682a75d1c4Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
56692a75d1c4Smrg    $objdir )   thisdir=. ;;
56702a75d1c4Smrg    esac
56712a75d1c4Smrg  fi
5672f7ec340bSmacallan
56732a75d1c4Smrg  # Try to get the absolute directory name.
56742a75d1c4Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
56752a75d1c4Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
56762a75d1c4Smrg"
5677f7ec340bSmacallan
567866ab3337Smrg	if test yes = "$fast_install"; then
56792a75d1c4Smrg	  $ECHO "\
56802a75d1c4Smrg  program=lt-'$outputname'$exeext
56812a75d1c4Smrg  progdir=\"\$thisdir/$objdir\"
5682f7ec340bSmacallan
56832a75d1c4Smrg  if test ! -f \"\$progdir/\$program\" ||
568466ab3337Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
56852a75d1c4Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686f7ec340bSmacallan
56872a75d1c4Smrg    file=\"\$\$-\$program\"
5688f7ec340bSmacallan
56892a75d1c4Smrg    if test ! -d \"\$progdir\"; then
56902a75d1c4Smrg      $MKDIR \"\$progdir\"
56912a75d1c4Smrg    else
56922a75d1c4Smrg      $RM \"\$progdir/\$file\"
56932a75d1c4Smrg    fi"
5694f7ec340bSmacallan
56952a75d1c4Smrg	  $ECHO "\
5696f7ec340bSmacallan
56972a75d1c4Smrg    # relink executable if necessary
56982a75d1c4Smrg    if test -n \"\$relink_command\"; then
56992a75d1c4Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
57002a75d1c4Smrg      else
570166ab3337Smrg	\$ECHO \"\$relink_command_output\" >&2
57022a75d1c4Smrg	$RM \"\$progdir/\$file\"
57032a75d1c4Smrg	exit 1
57042a75d1c4Smrg      fi
57052a75d1c4Smrg    fi
5706f7ec340bSmacallan
57072a75d1c4Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
57082a75d1c4Smrg    { $RM \"\$progdir/\$program\";
57092a75d1c4Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
57102a75d1c4Smrg    $RM \"\$progdir/\$file\"
57112a75d1c4Smrg  fi"
57122a75d1c4Smrg	else
57132a75d1c4Smrg	  $ECHO "\
57142a75d1c4Smrg  program='$outputname'
57152a75d1c4Smrg  progdir=\"\$thisdir/$objdir\"
57162a75d1c4Smrg"
5717f7ec340bSmacallan	fi
5718f7ec340bSmacallan
57192a75d1c4Smrg	$ECHO "\
5720f7ec340bSmacallan
57212a75d1c4Smrg  if test -f \"\$progdir/\$program\"; then"
5722f7ec340bSmacallan
57232a75d1c4Smrg	# fixup the dll searchpath if we need to.
57242a75d1c4Smrg	#
57252a75d1c4Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
57262a75d1c4Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
57272a75d1c4Smrg	# libraries must come first.
57282a75d1c4Smrg	if test -n "$dllsearchpath"; then
57292a75d1c4Smrg	  $ECHO "\
57302a75d1c4Smrg    # Add the dll search path components to the executable PATH
57312a75d1c4Smrg    PATH=$dllsearchpath:\$PATH
57322a75d1c4Smrg"
57332a75d1c4Smrg	fi
5734f7ec340bSmacallan
57352a75d1c4Smrg	# Export our shlibpath_var if we have one.
573666ab3337Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57372a75d1c4Smrg	  $ECHO "\
57382a75d1c4Smrg    # Add our own library path to $shlibpath_var
57392a75d1c4Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740f7ec340bSmacallan
57412a75d1c4Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
57422a75d1c4Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
57432a75d1c4Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744f7ec340bSmacallan
57452a75d1c4Smrg    export $shlibpath_var
57462a75d1c4Smrg"
57472a75d1c4Smrg	fi
5748f7ec340bSmacallan
57492a75d1c4Smrg	$ECHO "\
57502a75d1c4Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
57512a75d1c4Smrg      # Run the actual program with our arguments.
57522a75d1c4Smrg      func_exec_program \${1+\"\$@\"}
57532a75d1c4Smrg    fi
57542a75d1c4Smrg  else
57552a75d1c4Smrg    # The program doesn't exist.
575666ab3337Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
57572a75d1c4Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
57582a75d1c4Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
57592a75d1c4Smrg    exit 1
57602a75d1c4Smrg  fi
57612a75d1c4Smrgfi\
57622a75d1c4Smrg"
57632a75d1c4Smrg}
5764f7ec340bSmacallan
5765f7ec340bSmacallan
57662a75d1c4Smrg# func_emit_cwrapperexe_src
57672a75d1c4Smrg# emit the source code for a wrapper executable on stdout
57682a75d1c4Smrg# Must ONLY be called from within func_mode_link because
57692a75d1c4Smrg# it depends on a number of variable set therein.
57702a75d1c4Smrgfunc_emit_cwrapperexe_src ()
57712a75d1c4Smrg{
57722a75d1c4Smrg	cat <<EOF
5773f7ec340bSmacallan
57742a75d1c4Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
577566ab3337Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776f7ec340bSmacallan
57772a75d1c4Smrg   The $output program cannot be directly executed until all the libtool
57782a75d1c4Smrg   libraries that it depends on are installed.
5779f7ec340bSmacallan
57802a75d1c4Smrg   This wrapper executable should never be moved out of the build directory.
57812a75d1c4Smrg   If it is, it will not operate correctly.
57822a75d1c4Smrg*/
57832a75d1c4SmrgEOF
57842a75d1c4Smrg	    cat <<"EOF"
57852a75d1c4Smrg#ifdef _MSC_VER
57862a75d1c4Smrg# define _CRT_SECURE_NO_DEPRECATE 1
57872a75d1c4Smrg#endif
57882a75d1c4Smrg#include <stdio.h>
57892a75d1c4Smrg#include <stdlib.h>
57902a75d1c4Smrg#ifdef _MSC_VER
57912a75d1c4Smrg# include <direct.h>
57922a75d1c4Smrg# include <process.h>
57932a75d1c4Smrg# include <io.h>
57942a75d1c4Smrg#else
57952a75d1c4Smrg# include <unistd.h>
57962a75d1c4Smrg# include <stdint.h>
57972a75d1c4Smrg# ifdef __CYGWIN__
57982a75d1c4Smrg#  include <io.h>
57992a75d1c4Smrg# endif
58002a75d1c4Smrg#endif
58012a75d1c4Smrg#include <malloc.h>
58022a75d1c4Smrg#include <stdarg.h>
58032a75d1c4Smrg#include <assert.h>
58042a75d1c4Smrg#include <string.h>
58052a75d1c4Smrg#include <ctype.h>
58062a75d1c4Smrg#include <errno.h>
58072a75d1c4Smrg#include <fcntl.h>
58082a75d1c4Smrg#include <sys/stat.h>
5809f7ec340bSmacallan
581066ab3337Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
581166ab3337Smrg
58122a75d1c4Smrg/* declarations of non-ANSI functions */
581366ab3337Smrg#if defined __MINGW32__
58142a75d1c4Smrg# ifdef __STRICT_ANSI__
58152a75d1c4Smrgint _putenv (const char *);
58162a75d1c4Smrg# endif
581766ab3337Smrg#elif defined __CYGWIN__
58182a75d1c4Smrg# ifdef __STRICT_ANSI__
58192a75d1c4Smrgchar *realpath (const char *, char *);
58202a75d1c4Smrgint putenv (char *);
58212a75d1c4Smrgint setenv (const char *, const char *, int);
58222a75d1c4Smrg# endif
582366ab3337Smrg/* #elif defined other_platform || defined ... */
58242a75d1c4Smrg#endif
5825f7ec340bSmacallan
58262a75d1c4Smrg/* portability defines, excluding path handling macros */
582766ab3337Smrg#if defined _MSC_VER
58282a75d1c4Smrg# define setmode _setmode
58292a75d1c4Smrg# define stat    _stat
58302a75d1c4Smrg# define chmod   _chmod
58312a75d1c4Smrg# define getcwd  _getcwd
58322a75d1c4Smrg# define putenv  _putenv
58332a75d1c4Smrg# define S_IXUSR _S_IEXEC
583466ab3337Smrg#elif defined __MINGW32__
58352a75d1c4Smrg# define setmode _setmode
58362a75d1c4Smrg# define stat    _stat
58372a75d1c4Smrg# define chmod   _chmod
58382a75d1c4Smrg# define getcwd  _getcwd
58392a75d1c4Smrg# define putenv  _putenv
584066ab3337Smrg#elif defined __CYGWIN__
58412a75d1c4Smrg# define HAVE_SETENV
58422a75d1c4Smrg# define FOPEN_WB "wb"
584366ab3337Smrg/* #elif defined other platforms ... */
58442a75d1c4Smrg#endif
5845f7ec340bSmacallan
584666ab3337Smrg#if defined PATH_MAX
58472a75d1c4Smrg# define LT_PATHMAX PATH_MAX
584866ab3337Smrg#elif defined MAXPATHLEN
58492a75d1c4Smrg# define LT_PATHMAX MAXPATHLEN
58502a75d1c4Smrg#else
58512a75d1c4Smrg# define LT_PATHMAX 1024
58522a75d1c4Smrg#endif
5853f7ec340bSmacallan
58542a75d1c4Smrg#ifndef S_IXOTH
58552a75d1c4Smrg# define S_IXOTH 0
58562a75d1c4Smrg#endif
58572a75d1c4Smrg#ifndef S_IXGRP
58582a75d1c4Smrg# define S_IXGRP 0
58592a75d1c4Smrg#endif
5860f7ec340bSmacallan
58612a75d1c4Smrg/* path handling portability macros */
58622a75d1c4Smrg#ifndef DIR_SEPARATOR
58632a75d1c4Smrg# define DIR_SEPARATOR '/'
58642a75d1c4Smrg# define PATH_SEPARATOR ':'
58652a75d1c4Smrg#endif
5866f7ec340bSmacallan
586766ab3337Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
586866ab3337Smrg  defined __OS2__
58692a75d1c4Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
58702a75d1c4Smrg# define FOPEN_WB "wb"
58712a75d1c4Smrg# ifndef DIR_SEPARATOR_2
58722a75d1c4Smrg#  define DIR_SEPARATOR_2 '\\'
58732a75d1c4Smrg# endif
58742a75d1c4Smrg# ifndef PATH_SEPARATOR_2
58752a75d1c4Smrg#  define PATH_SEPARATOR_2 ';'
58762a75d1c4Smrg# endif
58772a75d1c4Smrg#endif
5878f7ec340bSmacallan
58792a75d1c4Smrg#ifndef DIR_SEPARATOR_2
58802a75d1c4Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
58812a75d1c4Smrg#else /* DIR_SEPARATOR_2 */
58822a75d1c4Smrg# define IS_DIR_SEPARATOR(ch) \
58832a75d1c4Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
58842a75d1c4Smrg#endif /* DIR_SEPARATOR_2 */
5885f7ec340bSmacallan
58862a75d1c4Smrg#ifndef PATH_SEPARATOR_2
58872a75d1c4Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
58882a75d1c4Smrg#else /* PATH_SEPARATOR_2 */
58892a75d1c4Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
58902a75d1c4Smrg#endif /* PATH_SEPARATOR_2 */
5891f7ec340bSmacallan
58922a75d1c4Smrg#ifndef FOPEN_WB
58932a75d1c4Smrg# define FOPEN_WB "w"
58942a75d1c4Smrg#endif
58952a75d1c4Smrg#ifndef _O_BINARY
58962a75d1c4Smrg# define _O_BINARY 0
58972a75d1c4Smrg#endif
5898f7ec340bSmacallan
58992a75d1c4Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
59002a75d1c4Smrg#define XFREE(stale) do { \
590166ab3337Smrg  if (stale) { free (stale); stale = 0; } \
59022a75d1c4Smrg} while (0)
5903f7ec340bSmacallan
590466ab3337Smrg#if defined LT_DEBUGWRAPPER
59052a75d1c4Smrgstatic int lt_debug = 1;
59062a75d1c4Smrg#else
59072a75d1c4Smrgstatic int lt_debug = 0;
59082a75d1c4Smrg#endif
5909f7ec340bSmacallan
59102a75d1c4Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59112a75d1c4Smrg
59122a75d1c4Smrgvoid *xmalloc (size_t num);
59132a75d1c4Smrgchar *xstrdup (const char *string);
59142a75d1c4Smrgconst char *base_name (const char *name);
59152a75d1c4Smrgchar *find_executable (const char *wrapper);
59162a75d1c4Smrgchar *chase_symlinks (const char *pathspec);
59172a75d1c4Smrgint make_executable (const char *path);
59182a75d1c4Smrgint check_executable (const char *path);
59192a75d1c4Smrgchar *strendzap (char *str, const char *pat);
59202a75d1c4Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
59212a75d1c4Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
59222a75d1c4Smrgstatic const char *nonnull (const char *s);
59232a75d1c4Smrgstatic const char *nonempty (const char *s);
59242a75d1c4Smrgvoid lt_setenv (const char *name, const char *value);
59252a75d1c4Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
59262a75d1c4Smrgvoid lt_update_exe_path (const char *name, const char *value);
59272a75d1c4Smrgvoid lt_update_lib_path (const char *name, const char *value);
59282a75d1c4Smrgchar **prepare_spawn (char **argv);
59292a75d1c4Smrgvoid lt_dump_script (FILE *f);
59302a75d1c4SmrgEOF
5931f7ec340bSmacallan
59322a75d1c4Smrg	    cat <<EOF
593366ab3337Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
593466ab3337Smrg# define externally_visible volatile
593566ab3337Smrg#else
593666ab3337Smrg# define externally_visible __attribute__((externally_visible)) volatile
593766ab3337Smrg#endif
593866ab3337Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
59392a75d1c4Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
59402a75d1c4SmrgEOF
5941f7ec340bSmacallan
594266ab3337Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
59432a75d1c4Smrg              func_to_host_path "$temp_rpath"
59442a75d1c4Smrg	      cat <<EOF
59452a75d1c4Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
59462a75d1c4SmrgEOF
59472a75d1c4Smrg	    else
59482a75d1c4Smrg	      cat <<"EOF"
59492a75d1c4Smrgconst char * LIB_PATH_VALUE   = "";
59502a75d1c4SmrgEOF
59512a75d1c4Smrg	    fi
5952f7ec340bSmacallan
59532a75d1c4Smrg	    if test -n "$dllsearchpath"; then
59542a75d1c4Smrg              func_to_host_path "$dllsearchpath:"
59552a75d1c4Smrg	      cat <<EOF
59562a75d1c4Smrgconst char * EXE_PATH_VARNAME = "PATH";
59572a75d1c4Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
59582a75d1c4SmrgEOF
59592a75d1c4Smrg	    else
59602a75d1c4Smrg	      cat <<"EOF"
59612a75d1c4Smrgconst char * EXE_PATH_VARNAME = "";
59622a75d1c4Smrgconst char * EXE_PATH_VALUE   = "";
59632a75d1c4SmrgEOF
59642a75d1c4Smrg	    fi
5965f7ec340bSmacallan
596666ab3337Smrg	    if test yes = "$fast_install"; then
59672a75d1c4Smrg	      cat <<EOF
59682a75d1c4Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
59692a75d1c4SmrgEOF
59702a75d1c4Smrg	    else
59712a75d1c4Smrg	      cat <<EOF
59722a75d1c4Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
59732a75d1c4SmrgEOF
59742a75d1c4Smrg	    fi
5975f7ec340bSmacallan
5976f7ec340bSmacallan
59772a75d1c4Smrg	    cat <<"EOF"
5978f7ec340bSmacallan
59792a75d1c4Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980f7ec340bSmacallan
59812a75d1c4Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
59822a75d1c4Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
59832a75d1c4Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984f7ec340bSmacallan
59852a75d1c4Smrgint
59862a75d1c4Smrgmain (int argc, char *argv[])
59872a75d1c4Smrg{
59882a75d1c4Smrg  char **newargz;
59892a75d1c4Smrg  int  newargc;
59902a75d1c4Smrg  char *tmp_pathspec;
59912a75d1c4Smrg  char *actual_cwrapper_path;
59922a75d1c4Smrg  char *actual_cwrapper_name;
59932a75d1c4Smrg  char *target_name;
59942a75d1c4Smrg  char *lt_argv_zero;
599566ab3337Smrg  int rval = 127;
59962a75d1c4Smrg
59972a75d1c4Smrg  int i;
59982a75d1c4Smrg
59992a75d1c4Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
600066ab3337Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
60012a75d1c4Smrg
60022a75d1c4Smrg  /* very simple arg parsing; don't want to rely on getopt
60032a75d1c4Smrg   * also, copy all non cwrapper options to newargz, except
60042a75d1c4Smrg   * argz[0], which is handled differently
60052a75d1c4Smrg   */
60062a75d1c4Smrg  newargc=0;
60072a75d1c4Smrg  for (i = 1; i < argc; i++)
60082a75d1c4Smrg    {
600966ab3337Smrg      if (STREQ (argv[i], dumpscript_opt))
60102a75d1c4Smrg	{
60112a75d1c4SmrgEOF
601266ab3337Smrg	    case $host in
60132a75d1c4Smrg	      *mingw* | *cygwin* )
60142a75d1c4Smrg		# make stdout use "unix" line endings
60152a75d1c4Smrg		echo "          setmode(1,_O_BINARY);"
6016f7ec340bSmacallan		;;
6017f7ec340bSmacallan	      esac
6018f7ec340bSmacallan
60192a75d1c4Smrg	    cat <<"EOF"
60202a75d1c4Smrg	  lt_dump_script (stdout);
60212a75d1c4Smrg	  return 0;
60222a75d1c4Smrg	}
602366ab3337Smrg      if (STREQ (argv[i], debug_opt))
60242a75d1c4Smrg	{
60252a75d1c4Smrg          lt_debug = 1;
60262a75d1c4Smrg          continue;
60272a75d1c4Smrg	}
602866ab3337Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
60292a75d1c4Smrg        {
60302a75d1c4Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
60312a75d1c4Smrg             namespace, but it is not one of the ones we know about and
60322a75d1c4Smrg             have already dealt with, above (inluding dump-script), then
60332a75d1c4Smrg             report an error. Otherwise, targets might begin to believe
60342a75d1c4Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
60352a75d1c4Smrg             namespace. The first time any user complains about this, we'll
60362a75d1c4Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
60372a75d1c4Smrg             or a configure.ac-settable value.
60382a75d1c4Smrg           */
60392a75d1c4Smrg          lt_fatal (__FILE__, __LINE__,
60402a75d1c4Smrg		    "unrecognized %s option: '%s'",
60412a75d1c4Smrg                    ltwrapper_option_prefix, argv[i]);
60422a75d1c4Smrg        }
60432a75d1c4Smrg      /* otherwise ... */
60442a75d1c4Smrg      newargz[++newargc] = xstrdup (argv[i]);
60452a75d1c4Smrg    }
60462a75d1c4Smrg  newargz[++newargc] = NULL;
6047f7ec340bSmacallan
60482a75d1c4SmrgEOF
60492a75d1c4Smrg	    cat <<EOF
60502a75d1c4Smrg  /* The GNU banner must be the first non-error debug message */
605166ab3337Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
60522a75d1c4SmrgEOF
60532a75d1c4Smrg	    cat <<"EOF"
60542a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
60552a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
60562a75d1c4Smrg
60572a75d1c4Smrg  tmp_pathspec = find_executable (argv[0]);
60582a75d1c4Smrg  if (tmp_pathspec == NULL)
60592a75d1c4Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
60602a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
60612a75d1c4Smrg                  "(main) found exe (before symlink chase) at: %s\n",
60622a75d1c4Smrg		  tmp_pathspec);
60632a75d1c4Smrg
60642a75d1c4Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
60652a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
60662a75d1c4Smrg                  "(main) found exe (after symlink chase) at: %s\n",
60672a75d1c4Smrg		  actual_cwrapper_path);
60682a75d1c4Smrg  XFREE (tmp_pathspec);
60692a75d1c4Smrg
60702a75d1c4Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
60712a75d1c4Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
60722a75d1c4Smrg
60732a75d1c4Smrg  /* wrapper name transforms */
60742a75d1c4Smrg  strendzap (actual_cwrapper_name, ".exe");
60752a75d1c4Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
60762a75d1c4Smrg  XFREE (actual_cwrapper_name);
60772a75d1c4Smrg  actual_cwrapper_name = tmp_pathspec;
60782a75d1c4Smrg  tmp_pathspec = 0;
60792a75d1c4Smrg
60802a75d1c4Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
60812a75d1c4Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
60822a75d1c4Smrg  strendzap (target_name, ".exe");
60832a75d1c4Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
60842a75d1c4Smrg  XFREE (target_name);
60852a75d1c4Smrg  target_name = tmp_pathspec;
60862a75d1c4Smrg  tmp_pathspec = 0;
60872a75d1c4Smrg
60882a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
60892a75d1c4Smrg		  "(main) libtool target name: %s\n",
60902a75d1c4Smrg		  target_name);
60912a75d1c4SmrgEOF
6092f7ec340bSmacallan
60932a75d1c4Smrg	    cat <<EOF
60942a75d1c4Smrg  newargz[0] =
60952a75d1c4Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
60962a75d1c4Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
60972a75d1c4Smrg  strcpy (newargz[0], actual_cwrapper_path);
60982a75d1c4Smrg  strcat (newargz[0], "$objdir");
60992a75d1c4Smrg  strcat (newargz[0], "/");
61002a75d1c4SmrgEOF
6101f7ec340bSmacallan
61022a75d1c4Smrg	    cat <<"EOF"
61032a75d1c4Smrg  /* stop here, and copy so we don't have to do this twice */
61042a75d1c4Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105f7ec340bSmacallan
61062a75d1c4Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
61072a75d1c4Smrg  strcat (newargz[0], actual_cwrapper_name);
6108f7ec340bSmacallan
61092a75d1c4Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
61102a75d1c4Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
61112a75d1c4Smrg  XFREE (tmp_pathspec);
61122a75d1c4Smrg  tmp_pathspec = NULL;
61132a75d1c4SmrgEOF
6114f7ec340bSmacallan
61152a75d1c4Smrg	    case $host_os in
61162a75d1c4Smrg	      mingw*)
61172a75d1c4Smrg	    cat <<"EOF"
61182a75d1c4Smrg  {
61192a75d1c4Smrg    char* p;
61202a75d1c4Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
61212a75d1c4Smrg      {
61222a75d1c4Smrg	*p = '/';
61232a75d1c4Smrg      }
61242a75d1c4Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
61252a75d1c4Smrg      {
61262a75d1c4Smrg	*p = '/';
61272a75d1c4Smrg      }
61282a75d1c4Smrg  }
61292a75d1c4SmrgEOF
61302a75d1c4Smrg	    ;;
61312a75d1c4Smrg	    esac
6132f7ec340bSmacallan
61332a75d1c4Smrg	    cat <<"EOF"
61342a75d1c4Smrg  XFREE (target_name);
61352a75d1c4Smrg  XFREE (actual_cwrapper_path);
61362a75d1c4Smrg  XFREE (actual_cwrapper_name);
61372a75d1c4Smrg
61382a75d1c4Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
61392a75d1c4Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
61402a75d1c4Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
61412a75d1c4Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
61422a75d1c4Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
61432a75d1c4Smrg     libraries must come first. */
61442a75d1c4Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
61452a75d1c4Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
61462a75d1c4Smrg
61472a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
61482a75d1c4Smrg		  nonnull (lt_argv_zero));
61492a75d1c4Smrg  for (i = 0; i < newargc; i++)
61502a75d1c4Smrg    {
61512a75d1c4Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
61522a75d1c4Smrg		      i, nonnull (newargz[i]));
61532a75d1c4Smrg    }
6154f7ec340bSmacallan
61552a75d1c4SmrgEOF
6156f7ec340bSmacallan
61572a75d1c4Smrg	    case $host_os in
61582a75d1c4Smrg	      mingw*)
61592a75d1c4Smrg		cat <<"EOF"
61602a75d1c4Smrg  /* execv doesn't actually work on mingw as expected on unix */
61612a75d1c4Smrg  newargz = prepare_spawn (newargz);
616266ab3337Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
61632a75d1c4Smrg  if (rval == -1)
61642a75d1c4Smrg    {
61652a75d1c4Smrg      /* failed to start process */
61662a75d1c4Smrg      lt_debugprintf (__FILE__, __LINE__,
61672a75d1c4Smrg		      "(main) failed to launch target \"%s\": %s\n",
61682a75d1c4Smrg		      lt_argv_zero, nonnull (strerror (errno)));
61692a75d1c4Smrg      return 127;
61702a75d1c4Smrg    }
61712a75d1c4Smrg  return rval;
61722a75d1c4SmrgEOF
61732a75d1c4Smrg		;;
61742a75d1c4Smrg	      *)
61752a75d1c4Smrg		cat <<"EOF"
61762a75d1c4Smrg  execv (lt_argv_zero, newargz);
61772a75d1c4Smrg  return rval; /* =127, but avoids unused variable warning */
61782a75d1c4SmrgEOF
61792a75d1c4Smrg		;;
61802a75d1c4Smrg	    esac
6181f7ec340bSmacallan
61822a75d1c4Smrg	    cat <<"EOF"
61832a75d1c4Smrg}
6184f7ec340bSmacallan
61852a75d1c4Smrgvoid *
61862a75d1c4Smrgxmalloc (size_t num)
61872a75d1c4Smrg{
61882a75d1c4Smrg  void *p = (void *) malloc (num);
61892a75d1c4Smrg  if (!p)
61902a75d1c4Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191f7ec340bSmacallan
61922a75d1c4Smrg  return p;
61932a75d1c4Smrg}
6194f7ec340bSmacallan
61952a75d1c4Smrgchar *
61962a75d1c4Smrgxstrdup (const char *string)
61972a75d1c4Smrg{
61982a75d1c4Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
61992a75d1c4Smrg			  string) : NULL;
62002a75d1c4Smrg}
6201f7ec340bSmacallan
62022a75d1c4Smrgconst char *
62032a75d1c4Smrgbase_name (const char *name)
62042a75d1c4Smrg{
62052a75d1c4Smrg  const char *base;
6206f7ec340bSmacallan
620766ab3337Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62082a75d1c4Smrg  /* Skip over the disk name in MSDOS pathnames. */
62092a75d1c4Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
62102a75d1c4Smrg    name += 2;
62112a75d1c4Smrg#endif
6212f7ec340bSmacallan
62132a75d1c4Smrg  for (base = name; *name; name++)
62142a75d1c4Smrg    if (IS_DIR_SEPARATOR (*name))
62152a75d1c4Smrg      base = name + 1;
62162a75d1c4Smrg  return base;
62172a75d1c4Smrg}
6218f7ec340bSmacallan
62192a75d1c4Smrgint
62202a75d1c4Smrgcheck_executable (const char *path)
62212a75d1c4Smrg{
62222a75d1c4Smrg  struct stat st;
6223f7ec340bSmacallan
62242a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
62252a75d1c4Smrg                  nonempty (path));
62262a75d1c4Smrg  if ((!path) || (!*path))
62272a75d1c4Smrg    return 0;
6228f7ec340bSmacallan
62292a75d1c4Smrg  if ((stat (path, &st) >= 0)
62302a75d1c4Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
62312a75d1c4Smrg    return 1;
62322a75d1c4Smrg  else
62332a75d1c4Smrg    return 0;
62342a75d1c4Smrg}
6235f7ec340bSmacallan
62362a75d1c4Smrgint
62372a75d1c4Smrgmake_executable (const char *path)
62382a75d1c4Smrg{
62392a75d1c4Smrg  int rval = 0;
62402a75d1c4Smrg  struct stat st;
6241f7ec340bSmacallan
62422a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
62432a75d1c4Smrg                  nonempty (path));
62442a75d1c4Smrg  if ((!path) || (!*path))
62452a75d1c4Smrg    return 0;
6246f7ec340bSmacallan
62472a75d1c4Smrg  if (stat (path, &st) >= 0)
62482a75d1c4Smrg    {
62492a75d1c4Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
62502a75d1c4Smrg    }
62512a75d1c4Smrg  return rval;
62522a75d1c4Smrg}
6253f7ec340bSmacallan
62542a75d1c4Smrg/* Searches for the full path of the wrapper.  Returns
62552a75d1c4Smrg   newly allocated full path name if found, NULL otherwise
62562a75d1c4Smrg   Does not chase symlinks, even on platforms that support them.
62572a75d1c4Smrg*/
62582a75d1c4Smrgchar *
62592a75d1c4Smrgfind_executable (const char *wrapper)
62602a75d1c4Smrg{
62612a75d1c4Smrg  int has_slash = 0;
62622a75d1c4Smrg  const char *p;
62632a75d1c4Smrg  const char *p_next;
62642a75d1c4Smrg  /* static buffer for getcwd */
62652a75d1c4Smrg  char tmp[LT_PATHMAX + 1];
626666ab3337Smrg  size_t tmp_len;
62672a75d1c4Smrg  char *concat_name;
6268f7ec340bSmacallan
62692a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
62702a75d1c4Smrg                  nonempty (wrapper));
6271f7ec340bSmacallan
62722a75d1c4Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
62732a75d1c4Smrg    return NULL;
6274f7ec340bSmacallan
62752a75d1c4Smrg  /* Absolute path? */
627666ab3337Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62772a75d1c4Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
62782a75d1c4Smrg    {
62792a75d1c4Smrg      concat_name = xstrdup (wrapper);
62802a75d1c4Smrg      if (check_executable (concat_name))
62812a75d1c4Smrg	return concat_name;
62822a75d1c4Smrg      XFREE (concat_name);
62832a75d1c4Smrg    }
62842a75d1c4Smrg  else
62852a75d1c4Smrg    {
62862a75d1c4Smrg#endif
62872a75d1c4Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
62882a75d1c4Smrg	{
62892a75d1c4Smrg	  concat_name = xstrdup (wrapper);
62902a75d1c4Smrg	  if (check_executable (concat_name))
62912a75d1c4Smrg	    return concat_name;
62922a75d1c4Smrg	  XFREE (concat_name);
62932a75d1c4Smrg	}
629466ab3337Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62952a75d1c4Smrg    }
62962a75d1c4Smrg#endif
6297f7ec340bSmacallan
62982a75d1c4Smrg  for (p = wrapper; *p; p++)
62992a75d1c4Smrg    if (*p == '/')
63002a75d1c4Smrg      {
63012a75d1c4Smrg	has_slash = 1;
63022a75d1c4Smrg	break;
63032a75d1c4Smrg      }
63042a75d1c4Smrg  if (!has_slash)
63052a75d1c4Smrg    {
63062a75d1c4Smrg      /* no slashes; search PATH */
63072a75d1c4Smrg      const char *path = getenv ("PATH");
63082a75d1c4Smrg      if (path != NULL)
63092a75d1c4Smrg	{
63102a75d1c4Smrg	  for (p = path; *p; p = p_next)
63112a75d1c4Smrg	    {
63122a75d1c4Smrg	      const char *q;
63132a75d1c4Smrg	      size_t p_len;
63142a75d1c4Smrg	      for (q = p; *q; q++)
63152a75d1c4Smrg		if (IS_PATH_SEPARATOR (*q))
63162a75d1c4Smrg		  break;
631766ab3337Smrg	      p_len = (size_t) (q - p);
63182a75d1c4Smrg	      p_next = (*q == '\0' ? q : q + 1);
63192a75d1c4Smrg	      if (p_len == 0)
63202a75d1c4Smrg		{
63212a75d1c4Smrg		  /* empty path: current directory */
63222a75d1c4Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
63232a75d1c4Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63242a75d1c4Smrg                              nonnull (strerror (errno)));
63252a75d1c4Smrg		  tmp_len = strlen (tmp);
63262a75d1c4Smrg		  concat_name =
63272a75d1c4Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63282a75d1c4Smrg		  memcpy (concat_name, tmp, tmp_len);
63292a75d1c4Smrg		  concat_name[tmp_len] = '/';
63302a75d1c4Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
63312a75d1c4Smrg		}
63322a75d1c4Smrg	      else
63332a75d1c4Smrg		{
63342a75d1c4Smrg		  concat_name =
63352a75d1c4Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
63362a75d1c4Smrg		  memcpy (concat_name, p, p_len);
63372a75d1c4Smrg		  concat_name[p_len] = '/';
63382a75d1c4Smrg		  strcpy (concat_name + p_len + 1, wrapper);
63392a75d1c4Smrg		}
63402a75d1c4Smrg	      if (check_executable (concat_name))
63412a75d1c4Smrg		return concat_name;
63422a75d1c4Smrg	      XFREE (concat_name);
63432a75d1c4Smrg	    }
63442a75d1c4Smrg	}
63452a75d1c4Smrg      /* not found in PATH; assume curdir */
63462a75d1c4Smrg    }
63472a75d1c4Smrg  /* Relative path | not found in path: prepend cwd */
63482a75d1c4Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
63492a75d1c4Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63502a75d1c4Smrg              nonnull (strerror (errno)));
63512a75d1c4Smrg  tmp_len = strlen (tmp);
63522a75d1c4Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63532a75d1c4Smrg  memcpy (concat_name, tmp, tmp_len);
63542a75d1c4Smrg  concat_name[tmp_len] = '/';
63552a75d1c4Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
63562a75d1c4Smrg
63572a75d1c4Smrg  if (check_executable (concat_name))
63582a75d1c4Smrg    return concat_name;
63592a75d1c4Smrg  XFREE (concat_name);
63602a75d1c4Smrg  return NULL;
6361f7ec340bSmacallan}
6362f7ec340bSmacallan
63632a75d1c4Smrgchar *
63642a75d1c4Smrgchase_symlinks (const char *pathspec)
63652a75d1c4Smrg{
63662a75d1c4Smrg#ifndef S_ISLNK
63672a75d1c4Smrg  return xstrdup (pathspec);
63682a75d1c4Smrg#else
63692a75d1c4Smrg  char buf[LT_PATHMAX];
63702a75d1c4Smrg  struct stat s;
63712a75d1c4Smrg  char *tmp_pathspec = xstrdup (pathspec);
63722a75d1c4Smrg  char *p;
63732a75d1c4Smrg  int has_symlinks = 0;
63742a75d1c4Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
63752a75d1c4Smrg    {
63762a75d1c4Smrg      lt_debugprintf (__FILE__, __LINE__,
63772a75d1c4Smrg		      "checking path component for symlinks: %s\n",
63782a75d1c4Smrg		      tmp_pathspec);
63792a75d1c4Smrg      if (lstat (tmp_pathspec, &s) == 0)
63802a75d1c4Smrg	{
63812a75d1c4Smrg	  if (S_ISLNK (s.st_mode) != 0)
63822a75d1c4Smrg	    {
63832a75d1c4Smrg	      has_symlinks = 1;
63842a75d1c4Smrg	      break;
63852a75d1c4Smrg	    }
6386f7ec340bSmacallan
63872a75d1c4Smrg	  /* search backwards for last DIR_SEPARATOR */
63882a75d1c4Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
63892a75d1c4Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63902a75d1c4Smrg	    p--;
63912a75d1c4Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63922a75d1c4Smrg	    {
63932a75d1c4Smrg	      /* no more DIR_SEPARATORS left */
63942a75d1c4Smrg	      break;
63952a75d1c4Smrg	    }
63962a75d1c4Smrg	  *p = '\0';
63972a75d1c4Smrg	}
63982a75d1c4Smrg      else
63992a75d1c4Smrg	{
64002a75d1c4Smrg	  lt_fatal (__FILE__, __LINE__,
64012a75d1c4Smrg		    "error accessing file \"%s\": %s",
64022a75d1c4Smrg		    tmp_pathspec, nonnull (strerror (errno)));
64032a75d1c4Smrg	}
64042a75d1c4Smrg    }
64052a75d1c4Smrg  XFREE (tmp_pathspec);
6406f7ec340bSmacallan
64072a75d1c4Smrg  if (!has_symlinks)
64082a75d1c4Smrg    {
64092a75d1c4Smrg      return xstrdup (pathspec);
64102a75d1c4Smrg    }
6411f7ec340bSmacallan
64122a75d1c4Smrg  tmp_pathspec = realpath (pathspec, buf);
64132a75d1c4Smrg  if (tmp_pathspec == 0)
64142a75d1c4Smrg    {
64152a75d1c4Smrg      lt_fatal (__FILE__, __LINE__,
64162a75d1c4Smrg		"could not follow symlinks for %s", pathspec);
64172a75d1c4Smrg    }
64182a75d1c4Smrg  return xstrdup (tmp_pathspec);
64192a75d1c4Smrg#endif
6420f7ec340bSmacallan}
6421f7ec340bSmacallan
64222a75d1c4Smrgchar *
64232a75d1c4Smrgstrendzap (char *str, const char *pat)
64242a75d1c4Smrg{
64252a75d1c4Smrg  size_t len, patlen;
6426f7ec340bSmacallan
64272a75d1c4Smrg  assert (str != NULL);
64282a75d1c4Smrg  assert (pat != NULL);
6429f7ec340bSmacallan
64302a75d1c4Smrg  len = strlen (str);
64312a75d1c4Smrg  patlen = strlen (pat);
6432f7ec340bSmacallan
64332a75d1c4Smrg  if (patlen <= len)
64342a75d1c4Smrg    {
64352a75d1c4Smrg      str += len - patlen;
643666ab3337Smrg      if (STREQ (str, pat))
64372a75d1c4Smrg	*str = '\0';
64382a75d1c4Smrg    }
64392a75d1c4Smrg  return str;
64402a75d1c4Smrg}
6441f7ec340bSmacallan
64422a75d1c4Smrgvoid
64432a75d1c4Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
64442a75d1c4Smrg{
64452a75d1c4Smrg  va_list args;
64462a75d1c4Smrg  if (lt_debug)
64472a75d1c4Smrg    {
64482a75d1c4Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
64492a75d1c4Smrg      va_start (args, fmt);
64502a75d1c4Smrg      (void) vfprintf (stderr, fmt, args);
64512a75d1c4Smrg      va_end (args);
64522a75d1c4Smrg    }
64532a75d1c4Smrg}
6454f7ec340bSmacallan
64552a75d1c4Smrgstatic void
64562a75d1c4Smrglt_error_core (int exit_status, const char *file,
64572a75d1c4Smrg	       int line, const char *mode,
64582a75d1c4Smrg	       const char *message, va_list ap)
64592a75d1c4Smrg{
64602a75d1c4Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
64612a75d1c4Smrg  vfprintf (stderr, message, ap);
64622a75d1c4Smrg  fprintf (stderr, ".\n");
6463f7ec340bSmacallan
64642a75d1c4Smrg  if (exit_status >= 0)
64652a75d1c4Smrg    exit (exit_status);
64662a75d1c4Smrg}
6467f7ec340bSmacallan
64682a75d1c4Smrgvoid
64692a75d1c4Smrglt_fatal (const char *file, int line, const char *message, ...)
64702a75d1c4Smrg{
64712a75d1c4Smrg  va_list ap;
64722a75d1c4Smrg  va_start (ap, message);
64732a75d1c4Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
64742a75d1c4Smrg  va_end (ap);
64752a75d1c4Smrg}
6476f7ec340bSmacallan
64772a75d1c4Smrgstatic const char *
64782a75d1c4Smrgnonnull (const char *s)
64792a75d1c4Smrg{
64802a75d1c4Smrg  return s ? s : "(null)";
64812a75d1c4Smrg}
6482f7ec340bSmacallan
64832a75d1c4Smrgstatic const char *
64842a75d1c4Smrgnonempty (const char *s)
64852a75d1c4Smrg{
64862a75d1c4Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
64872a75d1c4Smrg}
6488f7ec340bSmacallan
64892a75d1c4Smrgvoid
64902a75d1c4Smrglt_setenv (const char *name, const char *value)
64912a75d1c4Smrg{
64922a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
64932a75d1c4Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
64942a75d1c4Smrg                  nonnull (name), nonnull (value));
64952a75d1c4Smrg  {
64962a75d1c4Smrg#ifdef HAVE_SETENV
64972a75d1c4Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
64982a75d1c4Smrg    char *str = xstrdup (value);
64992a75d1c4Smrg    setenv (name, str, 1);
6500f7ec340bSmacallan#else
650166ab3337Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
65022a75d1c4Smrg    char *str = XMALLOC (char, len);
65032a75d1c4Smrg    sprintf (str, "%s=%s", name, value);
65042a75d1c4Smrg    if (putenv (str) != EXIT_SUCCESS)
65052a75d1c4Smrg      {
65062a75d1c4Smrg        XFREE (str);
65072a75d1c4Smrg      }
6508f7ec340bSmacallan#endif
65092a75d1c4Smrg  }
65102a75d1c4Smrg}
6511f7ec340bSmacallan
65122a75d1c4Smrgchar *
65132a75d1c4Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
65142a75d1c4Smrg{
65152a75d1c4Smrg  char *new_value;
65162a75d1c4Smrg  if (orig_value && *orig_value)
65172a75d1c4Smrg    {
651866ab3337Smrg      size_t orig_value_len = strlen (orig_value);
651966ab3337Smrg      size_t add_len = strlen (add);
65202a75d1c4Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
65212a75d1c4Smrg      if (to_end)
65222a75d1c4Smrg        {
65232a75d1c4Smrg          strcpy (new_value, orig_value);
65242a75d1c4Smrg          strcpy (new_value + orig_value_len, add);
65252a75d1c4Smrg        }
65262a75d1c4Smrg      else
65272a75d1c4Smrg        {
65282a75d1c4Smrg          strcpy (new_value, add);
65292a75d1c4Smrg          strcpy (new_value + add_len, orig_value);
65302a75d1c4Smrg        }
65312a75d1c4Smrg    }
65322a75d1c4Smrg  else
65332a75d1c4Smrg    {
65342a75d1c4Smrg      new_value = xstrdup (add);
65352a75d1c4Smrg    }
65362a75d1c4Smrg  return new_value;
65372a75d1c4Smrg}
6538f7ec340bSmacallan
65392a75d1c4Smrgvoid
65402a75d1c4Smrglt_update_exe_path (const char *name, const char *value)
65412a75d1c4Smrg{
65422a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
65432a75d1c4Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
65442a75d1c4Smrg                  nonnull (name), nonnull (value));
6545f7ec340bSmacallan
65462a75d1c4Smrg  if (name && *name && value && *value)
65472a75d1c4Smrg    {
65482a75d1c4Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65492a75d1c4Smrg      /* some systems can't cope with a ':'-terminated path #' */
655066ab3337Smrg      size_t len = strlen (new_value);
655166ab3337Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
65522a75d1c4Smrg        {
655366ab3337Smrg          new_value[--len] = '\0';
65542a75d1c4Smrg        }
65552a75d1c4Smrg      lt_setenv (name, new_value);
65562a75d1c4Smrg      XFREE (new_value);
65572a75d1c4Smrg    }
65582a75d1c4Smrg}
6559f7ec340bSmacallan
65602a75d1c4Smrgvoid
65612a75d1c4Smrglt_update_lib_path (const char *name, const char *value)
6562f7ec340bSmacallan{
65632a75d1c4Smrg  lt_debugprintf (__FILE__, __LINE__,
65642a75d1c4Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
65652a75d1c4Smrg                  nonnull (name), nonnull (value));
6566f7ec340bSmacallan
65672a75d1c4Smrg  if (name && *name && value && *value)
65682a75d1c4Smrg    {
65692a75d1c4Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65702a75d1c4Smrg      lt_setenv (name, new_value);
65712a75d1c4Smrg      XFREE (new_value);
65722a75d1c4Smrg    }
65732a75d1c4Smrg}
6574f7ec340bSmacallan
6575f7ec340bSmacallanEOF
65762a75d1c4Smrg	    case $host_os in
65772a75d1c4Smrg	      mingw*)
65782a75d1c4Smrg		cat <<"EOF"
65792a75d1c4Smrg
65802a75d1c4Smrg/* Prepares an argument vector before calling spawn().
65812a75d1c4Smrg   Note that spawn() does not by itself call the command interpreter
65822a75d1c4Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
65832a75d1c4Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
65842a75d1c4Smrg         GetVersionEx(&v);
65852a75d1c4Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
65862a75d1c4Smrg      }) ? "cmd.exe" : "command.com").
65872a75d1c4Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
65882a75d1c4Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
65892a75d1c4Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
65902a75d1c4Smrg   special way:
65912a75d1c4Smrg   - Space and tab are interpreted as delimiters. They are not treated as
65922a75d1c4Smrg     delimiters if they are surrounded by double quotes: "...".
65932a75d1c4Smrg   - Unescaped double quotes are removed from the input. Their only effect is
65942a75d1c4Smrg     that within double quotes, space and tab are treated like normal
65952a75d1c4Smrg     characters.
65962a75d1c4Smrg   - Backslashes not followed by double quotes are not special.
65972a75d1c4Smrg   - But 2*n+1 backslashes followed by a double quote become
65982a75d1c4Smrg     n backslashes followed by a double quote (n >= 0):
65992a75d1c4Smrg       \" -> "
66002a75d1c4Smrg       \\\" -> \"
66012a75d1c4Smrg       \\\\\" -> \\"
66022a75d1c4Smrg */
66032a75d1c4Smrg#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"
66042a75d1c4Smrg#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"
66052a75d1c4Smrgchar **
66062a75d1c4Smrgprepare_spawn (char **argv)
66072a75d1c4Smrg{
66082a75d1c4Smrg  size_t argc;
66092a75d1c4Smrg  char **new_argv;
66102a75d1c4Smrg  size_t i;
6611f7ec340bSmacallan
66122a75d1c4Smrg  /* Count number of arguments.  */
66132a75d1c4Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6614f7ec340bSmacallan    ;
6615f7ec340bSmacallan
66162a75d1c4Smrg  /* Allocate new argument vector.  */
66172a75d1c4Smrg  new_argv = XMALLOC (char *, argc + 1);
6618f7ec340bSmacallan
66192a75d1c4Smrg  /* Put quoted arguments into the new argument vector.  */
66202a75d1c4Smrg  for (i = 0; i < argc; i++)
66212a75d1c4Smrg    {
66222a75d1c4Smrg      const char *string = argv[i];
66232a75d1c4Smrg
66242a75d1c4Smrg      if (string[0] == '\0')
66252a75d1c4Smrg	new_argv[i] = xstrdup ("\"\"");
66262a75d1c4Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
66272a75d1c4Smrg	{
66282a75d1c4Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
66292a75d1c4Smrg	  size_t length;
66302a75d1c4Smrg	  unsigned int backslashes;
66312a75d1c4Smrg	  const char *s;
66322a75d1c4Smrg	  char *quoted_string;
66332a75d1c4Smrg	  char *p;
66342a75d1c4Smrg
66352a75d1c4Smrg	  length = 0;
66362a75d1c4Smrg	  backslashes = 0;
66372a75d1c4Smrg	  if (quote_around)
66382a75d1c4Smrg	    length++;
66392a75d1c4Smrg	  for (s = string; *s != '\0'; s++)
66402a75d1c4Smrg	    {
66412a75d1c4Smrg	      char c = *s;
66422a75d1c4Smrg	      if (c == '"')
66432a75d1c4Smrg		length += backslashes + 1;
66442a75d1c4Smrg	      length++;
66452a75d1c4Smrg	      if (c == '\\')
66462a75d1c4Smrg		backslashes++;
66472a75d1c4Smrg	      else
66482a75d1c4Smrg		backslashes = 0;
66492a75d1c4Smrg	    }
66502a75d1c4Smrg	  if (quote_around)
66512a75d1c4Smrg	    length += backslashes + 1;
66522a75d1c4Smrg
66532a75d1c4Smrg	  quoted_string = XMALLOC (char, length + 1);
66542a75d1c4Smrg
66552a75d1c4Smrg	  p = quoted_string;
66562a75d1c4Smrg	  backslashes = 0;
66572a75d1c4Smrg	  if (quote_around)
66582a75d1c4Smrg	    *p++ = '"';
66592a75d1c4Smrg	  for (s = string; *s != '\0'; s++)
66602a75d1c4Smrg	    {
66612a75d1c4Smrg	      char c = *s;
66622a75d1c4Smrg	      if (c == '"')
66632a75d1c4Smrg		{
66642a75d1c4Smrg		  unsigned int j;
66652a75d1c4Smrg		  for (j = backslashes + 1; j > 0; j--)
66662a75d1c4Smrg		    *p++ = '\\';
66672a75d1c4Smrg		}
66682a75d1c4Smrg	      *p++ = c;
66692a75d1c4Smrg	      if (c == '\\')
66702a75d1c4Smrg		backslashes++;
66712a75d1c4Smrg	      else
66722a75d1c4Smrg		backslashes = 0;
66732a75d1c4Smrg	    }
66742a75d1c4Smrg	  if (quote_around)
66752a75d1c4Smrg	    {
66762a75d1c4Smrg	      unsigned int j;
66772a75d1c4Smrg	      for (j = backslashes; j > 0; j--)
66782a75d1c4Smrg		*p++ = '\\';
66792a75d1c4Smrg	      *p++ = '"';
66802a75d1c4Smrg	    }
66812a75d1c4Smrg	  *p = '\0';
66822a75d1c4Smrg
66832a75d1c4Smrg	  new_argv[i] = quoted_string;
66842a75d1c4Smrg	}
66852a75d1c4Smrg      else
66862a75d1c4Smrg	new_argv[i] = (char *) string;
66872a75d1c4Smrg    }
66882a75d1c4Smrg  new_argv[argc] = NULL;
6689f7ec340bSmacallan
66902a75d1c4Smrg  return new_argv;
6691f7ec340bSmacallan}
66922a75d1c4SmrgEOF
66932a75d1c4Smrg		;;
66942a75d1c4Smrg	    esac
6695f7ec340bSmacallan
66962a75d1c4Smrg            cat <<"EOF"
66972a75d1c4Smrgvoid lt_dump_script (FILE* f)
6698f7ec340bSmacallan{
66992a75d1c4SmrgEOF
67002a75d1c4Smrg	    func_emit_wrapper yes |
670166ab3337Smrg	      $SED -n -e '
670266ab3337Smrgs/^\(.\{79\}\)\(..*\)/\1\
670366ab3337Smrg\2/
670466ab3337Smrgh
670566ab3337Smrgs/\([\\"]\)/\\\1/g
670666ab3337Smrgs/$/\\n/
670766ab3337Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
670866ab3337Smrgg
670966ab3337SmrgD'
67102a75d1c4Smrg            cat <<"EOF"
6711f7ec340bSmacallan}
67122a75d1c4SmrgEOF
6713f7ec340bSmacallan}
67142a75d1c4Smrg# end: func_emit_cwrapperexe_src
6715f7ec340bSmacallan
67162a75d1c4Smrg# func_win32_import_lib_p ARG
67172a75d1c4Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
67182a75d1c4Smrgfunc_win32_import_lib_p ()
6719f7ec340bSmacallan{
672066ab3337Smrg    $debug_cmd
672166ab3337Smrg
67222a75d1c4Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
67232a75d1c4Smrg    *import*) : ;;
67242a75d1c4Smrg    *) false ;;
67252a75d1c4Smrg    esac
6726f7ec340bSmacallan}
6727f7ec340bSmacallan
672866ab3337Smrg# func_suncc_cstd_abi
672966ab3337Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
673066ab3337Smrg# Several compiler flags select an ABI that is incompatible with the
673166ab3337Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
673266ab3337Smrgfunc_suncc_cstd_abi ()
673366ab3337Smrg{
673466ab3337Smrg    $debug_cmd
673566ab3337Smrg
673666ab3337Smrg    case " $compile_command " in
673766ab3337Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
673866ab3337Smrg      suncc_use_cstd_abi=no
673966ab3337Smrg      ;;
674066ab3337Smrg    *)
674166ab3337Smrg      suncc_use_cstd_abi=yes
674266ab3337Smrg      ;;
674366ab3337Smrg    esac
674466ab3337Smrg}
674566ab3337Smrg
67462a75d1c4Smrg# func_mode_link arg...
67472a75d1c4Smrgfunc_mode_link ()
6748f7ec340bSmacallan{
674966ab3337Smrg    $debug_cmd
675066ab3337Smrg
67512a75d1c4Smrg    case $host in
67522a75d1c4Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
67532a75d1c4Smrg      # It is impossible to link a dll without this setting, and
67542a75d1c4Smrg      # we shouldn't force the makefile maintainer to figure out
675566ab3337Smrg      # what system we are compiling for in order to pass an extra
67562a75d1c4Smrg      # flag for every libtool invocation.
67572a75d1c4Smrg      # allow_undefined=no
6758f7ec340bSmacallan
67592a75d1c4Smrg      # FIXME: Unfortunately, there are problems with the above when trying
676066ab3337Smrg      # to make a dll that has undefined symbols, in which case not
67612a75d1c4Smrg      # even a static library is built.  For now, we need to specify
67622a75d1c4Smrg      # -no-undefined on the libtool link line when we can be certain
67632a75d1c4Smrg      # that all symbols are satisfied, otherwise we get a static library.
67642a75d1c4Smrg      allow_undefined=yes
67652a75d1c4Smrg      ;;
67662a75d1c4Smrg    *)
67672a75d1c4Smrg      allow_undefined=yes
67682a75d1c4Smrg      ;;
67692a75d1c4Smrg    esac
67702a75d1c4Smrg    libtool_args=$nonopt
67712a75d1c4Smrg    base_compile="$nonopt $@"
67722a75d1c4Smrg    compile_command=$nonopt
67732a75d1c4Smrg    finalize_command=$nonopt
6774f7ec340bSmacallan
67752a75d1c4Smrg    compile_rpath=
67762a75d1c4Smrg    finalize_rpath=
67772a75d1c4Smrg    compile_shlibpath=
67782a75d1c4Smrg    finalize_shlibpath=
67792a75d1c4Smrg    convenience=
67802a75d1c4Smrg    old_convenience=
67812a75d1c4Smrg    deplibs=
67822a75d1c4Smrg    old_deplibs=
67832a75d1c4Smrg    compiler_flags=
67842a75d1c4Smrg    linker_flags=
67852a75d1c4Smrg    dllsearchpath=
67862a75d1c4Smrg    lib_search_path=`pwd`
67872a75d1c4Smrg    inst_prefix_dir=
67882a75d1c4Smrg    new_inherited_linker_flags=
6789f7ec340bSmacallan
67902a75d1c4Smrg    avoid_version=no
67912a75d1c4Smrg    bindir=
67922a75d1c4Smrg    dlfiles=
67932a75d1c4Smrg    dlprefiles=
67942a75d1c4Smrg    dlself=no
67952a75d1c4Smrg    export_dynamic=no
67962a75d1c4Smrg    export_symbols=
67972a75d1c4Smrg    export_symbols_regex=
67982a75d1c4Smrg    generated=
67992a75d1c4Smrg    libobjs=
68002a75d1c4Smrg    ltlibs=
68012a75d1c4Smrg    module=no
68022a75d1c4Smrg    no_install=no
68032a75d1c4Smrg    objs=
680466ab3337Smrg    os2dllname=
68052a75d1c4Smrg    non_pic_objects=
68062a75d1c4Smrg    precious_files_regex=
68072a75d1c4Smrg    prefer_static_libs=no
680866ab3337Smrg    preload=false
68092a75d1c4Smrg    prev=
68102a75d1c4Smrg    prevarg=
68112a75d1c4Smrg    release=
68122a75d1c4Smrg    rpath=
68132a75d1c4Smrg    xrpath=
68142a75d1c4Smrg    perm_rpath=
68152a75d1c4Smrg    temp_rpath=
68162a75d1c4Smrg    thread_safe=no
68172a75d1c4Smrg    vinfo=
68182a75d1c4Smrg    vinfo_number=no
68192a75d1c4Smrg    weak_libs=
682066ab3337Smrg    single_module=$wl-single_module
68212a75d1c4Smrg    func_infer_tag $base_compile
6822f7ec340bSmacallan
68232a75d1c4Smrg    # We need to know -static, to get the right output filenames.
68242a75d1c4Smrg    for arg
68252a75d1c4Smrg    do
68262a75d1c4Smrg      case $arg in
68272a75d1c4Smrg      -shared)
682866ab3337Smrg	test yes != "$build_libtool_libs" \
682966ab3337Smrg	  && func_fatal_configuration "cannot build a shared library"
68302a75d1c4Smrg	build_old_libs=no
68312a75d1c4Smrg	break
68322a75d1c4Smrg	;;
68332a75d1c4Smrg      -all-static | -static | -static-libtool-libs)
68342a75d1c4Smrg	case $arg in
68352a75d1c4Smrg	-all-static)
683666ab3337Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
68372a75d1c4Smrg	    func_warning "complete static linking is impossible in this configuration"
68382a75d1c4Smrg	  fi
68392a75d1c4Smrg	  if test -n "$link_static_flag"; then
68402a75d1c4Smrg	    dlopen_self=$dlopen_self_static
68412a75d1c4Smrg	  fi
68422a75d1c4Smrg	  prefer_static_libs=yes
68432a75d1c4Smrg	  ;;
68442a75d1c4Smrg	-static)
68452a75d1c4Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68462a75d1c4Smrg	    dlopen_self=$dlopen_self_static
68472a75d1c4Smrg	  fi
68482a75d1c4Smrg	  prefer_static_libs=built
68492a75d1c4Smrg	  ;;
68502a75d1c4Smrg	-static-libtool-libs)
68512a75d1c4Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68522a75d1c4Smrg	    dlopen_self=$dlopen_self_static
68532a75d1c4Smrg	  fi
68542a75d1c4Smrg	  prefer_static_libs=yes
68552a75d1c4Smrg	  ;;
68562a75d1c4Smrg	esac
68572a75d1c4Smrg	build_libtool_libs=no
68582a75d1c4Smrg	build_old_libs=yes
68592a75d1c4Smrg	break
68602a75d1c4Smrg	;;
68612a75d1c4Smrg      esac
68622a75d1c4Smrg    done
6863f7ec340bSmacallan
68642a75d1c4Smrg    # See if our shared archives depend on static archives.
68652a75d1c4Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866f7ec340bSmacallan
68672a75d1c4Smrg    # Go through the arguments, transforming them on the way.
68682a75d1c4Smrg    while test "$#" -gt 0; do
686966ab3337Smrg      arg=$1
68702a75d1c4Smrg      shift
687166ab3337Smrg      func_quote_arg pretty,unquoted "$arg"
687266ab3337Smrg      qarg=$func_quote_arg_unquoted_result
687366ab3337Smrg      func_append libtool_args " $func_quote_arg_result"
6874f7ec340bSmacallan
68752a75d1c4Smrg      # If the previous option needs an argument, assign it.
68762a75d1c4Smrg      if test -n "$prev"; then
68772a75d1c4Smrg	case $prev in
68782a75d1c4Smrg	output)
68792a75d1c4Smrg	  func_append compile_command " @OUTPUT@"
68802a75d1c4Smrg	  func_append finalize_command " @OUTPUT@"
68812a75d1c4Smrg	  ;;
68822a75d1c4Smrg	esac
6883f7ec340bSmacallan
68842a75d1c4Smrg	case $prev in
68852a75d1c4Smrg	bindir)
688666ab3337Smrg	  bindir=$arg
68872a75d1c4Smrg	  prev=
68882a75d1c4Smrg	  continue
68892a75d1c4Smrg	  ;;
68902a75d1c4Smrg	dlfiles|dlprefiles)
689166ab3337Smrg	  $preload || {
68922a75d1c4Smrg	    # Add the symbol object into the linking commands.
68932a75d1c4Smrg	    func_append compile_command " @SYMFILE@"
68942a75d1c4Smrg	    func_append finalize_command " @SYMFILE@"
689566ab3337Smrg	    preload=:
689666ab3337Smrg	  }
68972a75d1c4Smrg	  case $arg in
68982a75d1c4Smrg	  *.la | *.lo) ;;  # We handle these cases below.
68992a75d1c4Smrg	  force)
690066ab3337Smrg	    if test no = "$dlself"; then
69012a75d1c4Smrg	      dlself=needless
69022a75d1c4Smrg	      export_dynamic=yes
69032a75d1c4Smrg	    fi
69042a75d1c4Smrg	    prev=
69052a75d1c4Smrg	    continue
69062a75d1c4Smrg	    ;;
69072a75d1c4Smrg	  self)
690866ab3337Smrg	    if test dlprefiles = "$prev"; then
69092a75d1c4Smrg	      dlself=yes
691066ab3337Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
69112a75d1c4Smrg	      dlself=yes
69122a75d1c4Smrg	    else
69132a75d1c4Smrg	      dlself=needless
69142a75d1c4Smrg	      export_dynamic=yes
69152a75d1c4Smrg	    fi
69162a75d1c4Smrg	    prev=
69172a75d1c4Smrg	    continue
69182a75d1c4Smrg	    ;;
69192a75d1c4Smrg	  *)
692066ab3337Smrg	    if test dlfiles = "$prev"; then
69212a75d1c4Smrg	      func_append dlfiles " $arg"
69222a75d1c4Smrg	    else
69232a75d1c4Smrg	      func_append dlprefiles " $arg"
69242a75d1c4Smrg	    fi
69252a75d1c4Smrg	    prev=
69262a75d1c4Smrg	    continue
69272a75d1c4Smrg	    ;;
69282a75d1c4Smrg	  esac
69292a75d1c4Smrg	  ;;
69302a75d1c4Smrg	expsyms)
693166ab3337Smrg	  export_symbols=$arg
69322a75d1c4Smrg	  test -f "$arg" \
693366ab3337Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
69342a75d1c4Smrg	  prev=
69352a75d1c4Smrg	  continue
69362a75d1c4Smrg	  ;;
69372a75d1c4Smrg	expsyms_regex)
693866ab3337Smrg	  export_symbols_regex=$arg
69392a75d1c4Smrg	  prev=
69402a75d1c4Smrg	  continue
69412a75d1c4Smrg	  ;;
69422a75d1c4Smrg	framework)
69432a75d1c4Smrg	  case $host in
69442a75d1c4Smrg	    *-*-darwin*)
69452a75d1c4Smrg	      case "$deplibs " in
69462a75d1c4Smrg		*" $qarg.ltframework "*) ;;
69472a75d1c4Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
69482a75d1c4Smrg		   ;;
69492a75d1c4Smrg	      esac
69502a75d1c4Smrg	      ;;
69512a75d1c4Smrg	  esac
69522a75d1c4Smrg	  prev=
69532a75d1c4Smrg	  continue
69542a75d1c4Smrg	  ;;
69552a75d1c4Smrg	inst_prefix)
695666ab3337Smrg	  inst_prefix_dir=$arg
695766ab3337Smrg	  prev=
695866ab3337Smrg	  continue
695966ab3337Smrg	  ;;
696066ab3337Smrg	mllvm)
696166ab3337Smrg	  # Clang does not use LLVM to link, so we can simply discard any
696266ab3337Smrg	  # '-mllvm $arg' options when doing the link step.
69632a75d1c4Smrg	  prev=
69642a75d1c4Smrg	  continue
69652a75d1c4Smrg	  ;;
69662a75d1c4Smrg	objectlist)
69672a75d1c4Smrg	  if test -f "$arg"; then
69682a75d1c4Smrg	    save_arg=$arg
69692a75d1c4Smrg	    moreargs=
69702a75d1c4Smrg	    for fil in `cat "$save_arg"`
69712a75d1c4Smrg	    do
69722a75d1c4Smrg#	      func_append moreargs " $fil"
69732a75d1c4Smrg	      arg=$fil
69742a75d1c4Smrg	      # A libtool-controlled object.
6975f7ec340bSmacallan
69762a75d1c4Smrg	      # Check to see that this really is a libtool object.
69772a75d1c4Smrg	      if func_lalib_unsafe_p "$arg"; then
69782a75d1c4Smrg		pic_object=
69792a75d1c4Smrg		non_pic_object=
6980f7ec340bSmacallan
69812a75d1c4Smrg		# Read the .lo file
69822a75d1c4Smrg		func_source "$arg"
6983f7ec340bSmacallan
69842a75d1c4Smrg		if test -z "$pic_object" ||
69852a75d1c4Smrg		   test -z "$non_pic_object" ||
698666ab3337Smrg		   test none = "$pic_object" &&
698766ab3337Smrg		   test none = "$non_pic_object"; then
698866ab3337Smrg		  func_fatal_error "cannot find name of object for '$arg'"
69892a75d1c4Smrg		fi
6990f7ec340bSmacallan
69912a75d1c4Smrg		# Extract subdirectory from the argument.
69922a75d1c4Smrg		func_dirname "$arg" "/" ""
699366ab3337Smrg		xdir=$func_dirname_result
6994f7ec340bSmacallan
699566ab3337Smrg		if test none != "$pic_object"; then
69962a75d1c4Smrg		  # Prepend the subdirectory the object is found in.
699766ab3337Smrg		  pic_object=$xdir$pic_object
6998f7ec340bSmacallan
699966ab3337Smrg		  if test dlfiles = "$prev"; then
700066ab3337Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
70012a75d1c4Smrg		      func_append dlfiles " $pic_object"
70022a75d1c4Smrg		      prev=
70032a75d1c4Smrg		      continue
70042a75d1c4Smrg		    else
70052a75d1c4Smrg		      # If libtool objects are unsupported, then we need to preload.
70062a75d1c4Smrg		      prev=dlprefiles
70072a75d1c4Smrg		    fi
70082a75d1c4Smrg		  fi
7009f7ec340bSmacallan
70102a75d1c4Smrg		  # CHECK ME:  I think I busted this.  -Ossama
701166ab3337Smrg		  if test dlprefiles = "$prev"; then
70122a75d1c4Smrg		    # Preload the old-style object.
70132a75d1c4Smrg		    func_append dlprefiles " $pic_object"
70142a75d1c4Smrg		    prev=
70152a75d1c4Smrg		  fi
70167ce7e03cSmrg
70172a75d1c4Smrg		  # A PIC object.
70182a75d1c4Smrg		  func_append libobjs " $pic_object"
701966ab3337Smrg		  arg=$pic_object
70202a75d1c4Smrg		fi
7021f7ec340bSmacallan
70222a75d1c4Smrg		# Non-PIC object.
702366ab3337Smrg		if test none != "$non_pic_object"; then
70242a75d1c4Smrg		  # Prepend the subdirectory the object is found in.
702566ab3337Smrg		  non_pic_object=$xdir$non_pic_object
7026f7ec340bSmacallan
70272a75d1c4Smrg		  # A standard non-PIC object
70282a75d1c4Smrg		  func_append non_pic_objects " $non_pic_object"
702966ab3337Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
703066ab3337Smrg		    arg=$non_pic_object
70312a75d1c4Smrg		  fi
70322a75d1c4Smrg		else
70332a75d1c4Smrg		  # If the PIC object exists, use it instead.
70342a75d1c4Smrg		  # $xdir was prepended to $pic_object above.
703566ab3337Smrg		  non_pic_object=$pic_object
70362a75d1c4Smrg		  func_append non_pic_objects " $non_pic_object"
70372a75d1c4Smrg		fi
70382a75d1c4Smrg	      else
70392a75d1c4Smrg		# Only an error if not doing a dry-run.
70402a75d1c4Smrg		if $opt_dry_run; then
70412a75d1c4Smrg		  # Extract subdirectory from the argument.
70422a75d1c4Smrg		  func_dirname "$arg" "/" ""
704366ab3337Smrg		  xdir=$func_dirname_result
70442a75d1c4Smrg
70452a75d1c4Smrg		  func_lo2o "$arg"
70462a75d1c4Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
70472a75d1c4Smrg		  non_pic_object=$xdir$func_lo2o_result
70482a75d1c4Smrg		  func_append libobjs " $pic_object"
70492a75d1c4Smrg		  func_append non_pic_objects " $non_pic_object"
70502a75d1c4Smrg	        else
705166ab3337Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
70522a75d1c4Smrg		fi
70532a75d1c4Smrg	      fi
70542a75d1c4Smrg	    done
70552a75d1c4Smrg	  else
705666ab3337Smrg	    func_fatal_error "link input file '$arg' does not exist"
70572a75d1c4Smrg	  fi
70582a75d1c4Smrg	  arg=$save_arg
70592a75d1c4Smrg	  prev=
70602a75d1c4Smrg	  continue
70612a75d1c4Smrg	  ;;
706266ab3337Smrg	os2dllname)
706366ab3337Smrg	  os2dllname=$arg
706466ab3337Smrg	  prev=
706566ab3337Smrg	  continue
706666ab3337Smrg	  ;;
70672a75d1c4Smrg	precious_regex)
706866ab3337Smrg	  precious_files_regex=$arg
70692a75d1c4Smrg	  prev=
70702a75d1c4Smrg	  continue
70712a75d1c4Smrg	  ;;
70722a75d1c4Smrg	release)
707366ab3337Smrg	  release=-$arg
70742a75d1c4Smrg	  prev=
70752a75d1c4Smrg	  continue
70762a75d1c4Smrg	  ;;
70772a75d1c4Smrg	rpath | xrpath)
70782a75d1c4Smrg	  # We need an absolute path.
70792a75d1c4Smrg	  case $arg in
70802a75d1c4Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
70812a75d1c4Smrg	  *)
70822a75d1c4Smrg	    func_fatal_error "only absolute run-paths are allowed"
70832a75d1c4Smrg	    ;;
70842a75d1c4Smrg	  esac
708566ab3337Smrg	  if test rpath = "$prev"; then
70862a75d1c4Smrg	    case "$rpath " in
70872a75d1c4Smrg	    *" $arg "*) ;;
70882a75d1c4Smrg	    *) func_append rpath " $arg" ;;
70892a75d1c4Smrg	    esac
70902a75d1c4Smrg	  else
70912a75d1c4Smrg	    case "$xrpath " in
70922a75d1c4Smrg	    *" $arg "*) ;;
70932a75d1c4Smrg	    *) func_append xrpath " $arg" ;;
70942a75d1c4Smrg	    esac
70952a75d1c4Smrg	  fi
70962a75d1c4Smrg	  prev=
70972a75d1c4Smrg	  continue
70982a75d1c4Smrg	  ;;
70992a75d1c4Smrg	shrext)
710066ab3337Smrg	  shrext_cmds=$arg
71012a75d1c4Smrg	  prev=
71022a75d1c4Smrg	  continue
71032a75d1c4Smrg	  ;;
71042a75d1c4Smrg	weak)
71052a75d1c4Smrg	  func_append weak_libs " $arg"
71062a75d1c4Smrg	  prev=
71072a75d1c4Smrg	  continue
71082a75d1c4Smrg	  ;;
710966ab3337Smrg	xassembler)
711066ab3337Smrg	  func_append compiler_flags " -Xassembler $qarg"
711166ab3337Smrg	  prev=
711266ab3337Smrg	  func_append compile_command " -Xassembler $qarg"
711366ab3337Smrg	  func_append finalize_command " -Xassembler $qarg"
711466ab3337Smrg	  continue
711566ab3337Smrg	  ;;
71162a75d1c4Smrg	xcclinker)
71172a75d1c4Smrg	  func_append linker_flags " $qarg"
71182a75d1c4Smrg	  func_append compiler_flags " $qarg"
71192a75d1c4Smrg	  prev=
71202a75d1c4Smrg	  func_append compile_command " $qarg"
71212a75d1c4Smrg	  func_append finalize_command " $qarg"
71222a75d1c4Smrg	  continue
71232a75d1c4Smrg	  ;;
71242a75d1c4Smrg	xcompiler)
71252a75d1c4Smrg	  func_append compiler_flags " $qarg"
71262a75d1c4Smrg	  prev=
71272a75d1c4Smrg	  func_append compile_command " $qarg"
71282a75d1c4Smrg	  func_append finalize_command " $qarg"
71292a75d1c4Smrg	  continue
71302a75d1c4Smrg	  ;;
71312a75d1c4Smrg	xlinker)
71322a75d1c4Smrg	  func_append linker_flags " $qarg"
71332a75d1c4Smrg	  func_append compiler_flags " $wl$qarg"
71342a75d1c4Smrg	  prev=
71352a75d1c4Smrg	  func_append compile_command " $wl$qarg"
71362a75d1c4Smrg	  func_append finalize_command " $wl$qarg"
71372a75d1c4Smrg	  continue
71382a75d1c4Smrg	  ;;
71392a75d1c4Smrg	*)
71402a75d1c4Smrg	  eval "$prev=\"\$arg\""
71412a75d1c4Smrg	  prev=
71422a75d1c4Smrg	  continue
71432a75d1c4Smrg	  ;;
71442a75d1c4Smrg	esac
71452a75d1c4Smrg      fi # test -n "$prev"
7146f7ec340bSmacallan
714766ab3337Smrg      prevarg=$arg
7148f7ec340bSmacallan
71492a75d1c4Smrg      case $arg in
71502a75d1c4Smrg      -all-static)
71512a75d1c4Smrg	if test -n "$link_static_flag"; then
71522a75d1c4Smrg	  # See comment for -static flag below, for more details.
71532a75d1c4Smrg	  func_append compile_command " $link_static_flag"
71542a75d1c4Smrg	  func_append finalize_command " $link_static_flag"
71552a75d1c4Smrg	fi
71562a75d1c4Smrg	continue
71572a75d1c4Smrg	;;
7158f7ec340bSmacallan
71592a75d1c4Smrg      -allow-undefined)
71602a75d1c4Smrg	# FIXME: remove this flag sometime in the future.
716166ab3337Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
71622a75d1c4Smrg	;;
7163f7ec340bSmacallan
71642a75d1c4Smrg      -avoid-version)
71652a75d1c4Smrg	avoid_version=yes
71662a75d1c4Smrg	continue
71672a75d1c4Smrg	;;
7168f7ec340bSmacallan
71692a75d1c4Smrg      -bindir)
71702a75d1c4Smrg	prev=bindir
71712a75d1c4Smrg	continue
71722a75d1c4Smrg	;;
71732a75d1c4Smrg
71742a75d1c4Smrg      -dlopen)
71752a75d1c4Smrg	prev=dlfiles
71762a75d1c4Smrg	continue
71772a75d1c4Smrg	;;
71782a75d1c4Smrg
71792a75d1c4Smrg      -dlpreopen)
71802a75d1c4Smrg	prev=dlprefiles
71812a75d1c4Smrg	continue
71822a75d1c4Smrg	;;
71832a75d1c4Smrg
71842a75d1c4Smrg      -export-dynamic)
71852a75d1c4Smrg	export_dynamic=yes
71862a75d1c4Smrg	continue
71872a75d1c4Smrg	;;
71882a75d1c4Smrg
71892a75d1c4Smrg      -export-symbols | -export-symbols-regex)
71902a75d1c4Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
71912a75d1c4Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
71922a75d1c4Smrg	fi
719366ab3337Smrg	if test X-export-symbols = "X$arg"; then
71942a75d1c4Smrg	  prev=expsyms
71952a75d1c4Smrg	else
71962a75d1c4Smrg	  prev=expsyms_regex
71972a75d1c4Smrg	fi
71982a75d1c4Smrg	continue
71992a75d1c4Smrg	;;
72002a75d1c4Smrg
72012a75d1c4Smrg      -framework)
72022a75d1c4Smrg	prev=framework
72032a75d1c4Smrg	continue
72042a75d1c4Smrg	;;
72052a75d1c4Smrg
72062a75d1c4Smrg      -inst-prefix-dir)
72072a75d1c4Smrg	prev=inst_prefix
72082a75d1c4Smrg	continue
72092a75d1c4Smrg	;;
72102a75d1c4Smrg
72112a75d1c4Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
72122a75d1c4Smrg      # so, if we see these flags be careful not to treat them like -L
72132a75d1c4Smrg      -L[A-Z][A-Z]*:*)
72142a75d1c4Smrg	case $with_gcc/$host in
72152a75d1c4Smrg	no/*-*-irix* | /*-*-irix*)
72162a75d1c4Smrg	  func_append compile_command " $arg"
72172a75d1c4Smrg	  func_append finalize_command " $arg"
72182a75d1c4Smrg	  ;;
72192a75d1c4Smrg	esac
72202a75d1c4Smrg	continue
72212a75d1c4Smrg	;;
72222a75d1c4Smrg
72232a75d1c4Smrg      -L*)
72242a75d1c4Smrg	func_stripname "-L" '' "$arg"
72252a75d1c4Smrg	if test -z "$func_stripname_result"; then
72262a75d1c4Smrg	  if test "$#" -gt 0; then
722766ab3337Smrg	    func_fatal_error "require no space between '-L' and '$1'"
72282a75d1c4Smrg	  else
722966ab3337Smrg	    func_fatal_error "need path for '-L' option"
72302a75d1c4Smrg	  fi
72312a75d1c4Smrg	fi
72322a75d1c4Smrg	func_resolve_sysroot "$func_stripname_result"
72332a75d1c4Smrg	dir=$func_resolve_sysroot_result
72342a75d1c4Smrg	# We need an absolute path.
72352a75d1c4Smrg	case $dir in
72362a75d1c4Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
72372a75d1c4Smrg	*)
72382a75d1c4Smrg	  absdir=`cd "$dir" && pwd`
72392a75d1c4Smrg	  test -z "$absdir" && \
724066ab3337Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
724166ab3337Smrg	  dir=$absdir
72422a75d1c4Smrg	  ;;
72432a75d1c4Smrg	esac
72442a75d1c4Smrg	case "$deplibs " in
72452a75d1c4Smrg	*" -L$dir "* | *" $arg "*)
72462a75d1c4Smrg	  # Will only happen for absolute or sysroot arguments
72472a75d1c4Smrg	  ;;
72482a75d1c4Smrg	*)
72492a75d1c4Smrg	  # Preserve sysroot, but never include relative directories
72502a75d1c4Smrg	  case $dir in
72512a75d1c4Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
72522a75d1c4Smrg	    *) func_append deplibs " -L$dir" ;;
72532a75d1c4Smrg	  esac
72542a75d1c4Smrg	  func_append lib_search_path " $dir"
72552a75d1c4Smrg	  ;;
72562a75d1c4Smrg	esac
72572a75d1c4Smrg	case $host in
72582a75d1c4Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
72592a75d1c4Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
72602a75d1c4Smrg	  case :$dllsearchpath: in
72612a75d1c4Smrg	  *":$dir:"*) ;;
72622a75d1c4Smrg	  ::) dllsearchpath=$dir;;
72632a75d1c4Smrg	  *) func_append dllsearchpath ":$dir";;
72642a75d1c4Smrg	  esac
72652a75d1c4Smrg	  case :$dllsearchpath: in
72662a75d1c4Smrg	  *":$testbindir:"*) ;;
72672a75d1c4Smrg	  ::) dllsearchpath=$testbindir;;
72682a75d1c4Smrg	  *) func_append dllsearchpath ":$testbindir";;
72692a75d1c4Smrg	  esac
72702a75d1c4Smrg	  ;;
72712a75d1c4Smrg	esac
72722a75d1c4Smrg	continue
72732a75d1c4Smrg	;;
72742a75d1c4Smrg
72752a75d1c4Smrg      -l*)
727666ab3337Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
72772a75d1c4Smrg	  case $host in
72782a75d1c4Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
72792a75d1c4Smrg	    # These systems don't actually have a C or math library (as such)
72802a75d1c4Smrg	    continue
72812a75d1c4Smrg	    ;;
72822a75d1c4Smrg	  *-*-os2*)
72832a75d1c4Smrg	    # These systems don't actually have a C library (as such)
728466ab3337Smrg	    test X-lc = "X$arg" && continue
72852a75d1c4Smrg	    ;;
728666ab3337Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
72872a75d1c4Smrg	    # Do not include libc due to us having libc/libc_r.
728866ab3337Smrg	    test X-lc = "X$arg" && continue
72892a75d1c4Smrg	    ;;
72902a75d1c4Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
72912a75d1c4Smrg	    # Rhapsody C and math libraries are in the System framework
72922a75d1c4Smrg	    func_append deplibs " System.ltframework"
72932a75d1c4Smrg	    continue
72942a75d1c4Smrg	    ;;
72952a75d1c4Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
72962a75d1c4Smrg	    # Causes problems with __ctype
729766ab3337Smrg	    test X-lc = "X$arg" && continue
72982a75d1c4Smrg	    ;;
72992a75d1c4Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
73002a75d1c4Smrg	    # Compiler inserts libc in the correct place for threads to work
730166ab3337Smrg	    test X-lc = "X$arg" && continue
73022a75d1c4Smrg	    ;;
73032a75d1c4Smrg	  esac
730466ab3337Smrg	elif test X-lc_r = "X$arg"; then
73052a75d1c4Smrg	 case $host in
730666ab3337Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
73072a75d1c4Smrg	   # Do not include libc_r directly, use -pthread flag.
73082a75d1c4Smrg	   continue
73092a75d1c4Smrg	   ;;
73102a75d1c4Smrg	 esac
73112a75d1c4Smrg	fi
73122a75d1c4Smrg	func_append deplibs " $arg"
73132a75d1c4Smrg	continue
73142a75d1c4Smrg	;;
73152a75d1c4Smrg
731666ab3337Smrg      -mllvm)
731766ab3337Smrg	prev=mllvm
731866ab3337Smrg	continue
731966ab3337Smrg	;;
732066ab3337Smrg
73212a75d1c4Smrg      -module)
73222a75d1c4Smrg	module=yes
73232a75d1c4Smrg	continue
73242a75d1c4Smrg	;;
73252a75d1c4Smrg
73262a75d1c4Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
73272a75d1c4Smrg      # classes, name mangling, and exception handling.
73282a75d1c4Smrg      # Darwin uses the -arch flag to determine output architecture.
73292a75d1c4Smrg      -model|-arch|-isysroot|--sysroot)
73302a75d1c4Smrg	func_append compiler_flags " $arg"
73312a75d1c4Smrg	func_append compile_command " $arg"
73322a75d1c4Smrg	func_append finalize_command " $arg"
73332a75d1c4Smrg	prev=xcompiler
73342a75d1c4Smrg	continue
73352a75d1c4Smrg	;;
733666ab3337Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
733766ab3337Smrg     -pthread)
733866ab3337Smrg	case $host in
733966ab3337Smrg	  *solaris2*) ;;
734066ab3337Smrg	  *)
734166ab3337Smrg	    case "$new_inherited_linker_flags " in
734266ab3337Smrg	        *" $arg "*) ;;
734366ab3337Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
734466ab3337Smrg	    esac
734566ab3337Smrg	  ;;
734666ab3337Smrg	esac
734766ab3337Smrg	continue
734866ab3337Smrg	;;
734966ab3337Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
735066ab3337Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
73512a75d1c4Smrg	func_append compiler_flags " $arg"
73522a75d1c4Smrg	func_append compile_command " $arg"
73532a75d1c4Smrg	func_append finalize_command " $arg"
73542a75d1c4Smrg	case "$new_inherited_linker_flags " in
73552a75d1c4Smrg	    *" $arg "*) ;;
73562a75d1c4Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
73572a75d1c4Smrg	esac
73582a75d1c4Smrg	continue
73592a75d1c4Smrg	;;
73602a75d1c4Smrg
73612a75d1c4Smrg      -multi_module)
736266ab3337Smrg	single_module=$wl-multi_module
73632a75d1c4Smrg	continue
73642a75d1c4Smrg	;;
73652a75d1c4Smrg
73662a75d1c4Smrg      -no-fast-install)
73672a75d1c4Smrg	fast_install=no
73682a75d1c4Smrg	continue
73692a75d1c4Smrg	;;
73702a75d1c4Smrg
73712a75d1c4Smrg      -no-install)
73722a75d1c4Smrg	case $host in
73732a75d1c4Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
73742a75d1c4Smrg	  # The PATH hackery in wrapper scripts is required on Windows
73752a75d1c4Smrg	  # and Darwin in order for the loader to find any dlls it needs.
737666ab3337Smrg	  func_warning "'-no-install' is ignored for $host"
737766ab3337Smrg	  func_warning "assuming '-no-fast-install' instead"
73782a75d1c4Smrg	  fast_install=no
73792a75d1c4Smrg	  ;;
73802a75d1c4Smrg	*) no_install=yes ;;
73812a75d1c4Smrg	esac
73822a75d1c4Smrg	continue
73832a75d1c4Smrg	;;
73842a75d1c4Smrg
73852a75d1c4Smrg      -no-undefined)
73862a75d1c4Smrg	allow_undefined=no
73872a75d1c4Smrg	continue
73882a75d1c4Smrg	;;
73892a75d1c4Smrg
73902a75d1c4Smrg      -objectlist)
73912a75d1c4Smrg	prev=objectlist
73922a75d1c4Smrg	continue
73932a75d1c4Smrg	;;
73942a75d1c4Smrg
739566ab3337Smrg      -os2dllname)
739666ab3337Smrg	prev=os2dllname
739766ab3337Smrg	continue
739866ab3337Smrg	;;
739966ab3337Smrg
74002a75d1c4Smrg      -o) prev=output ;;
74012a75d1c4Smrg
74022a75d1c4Smrg      -precious-files-regex)
74032a75d1c4Smrg	prev=precious_regex
74042a75d1c4Smrg	continue
74052a75d1c4Smrg	;;
74062a75d1c4Smrg
74072a75d1c4Smrg      -release)
74082a75d1c4Smrg	prev=release
74092a75d1c4Smrg	continue
74102a75d1c4Smrg	;;
74112a75d1c4Smrg
74122a75d1c4Smrg      -rpath)
74132a75d1c4Smrg	prev=rpath
74142a75d1c4Smrg	continue
74152a75d1c4Smrg	;;
74162a75d1c4Smrg
74172a75d1c4Smrg      -R)
74182a75d1c4Smrg	prev=xrpath
74192a75d1c4Smrg	continue
74202a75d1c4Smrg	;;
74212a75d1c4Smrg
74222a75d1c4Smrg      -R*)
74232a75d1c4Smrg	func_stripname '-R' '' "$arg"
74242a75d1c4Smrg	dir=$func_stripname_result
74252a75d1c4Smrg	# We need an absolute path.
74262a75d1c4Smrg	case $dir in
74272a75d1c4Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
74282a75d1c4Smrg	=*)
74292a75d1c4Smrg	  func_stripname '=' '' "$dir"
74302a75d1c4Smrg	  dir=$lt_sysroot$func_stripname_result
74312a75d1c4Smrg	  ;;
74322a75d1c4Smrg	*)
74332a75d1c4Smrg	  func_fatal_error "only absolute run-paths are allowed"
74342a75d1c4Smrg	  ;;
74352a75d1c4Smrg	esac
74362a75d1c4Smrg	case "$xrpath " in
74372a75d1c4Smrg	*" $dir "*) ;;
74382a75d1c4Smrg	*) func_append xrpath " $dir" ;;
74392a75d1c4Smrg	esac
74402a75d1c4Smrg	continue
74412a75d1c4Smrg	;;
74422a75d1c4Smrg
74432a75d1c4Smrg      -shared)
74442a75d1c4Smrg	# The effects of -shared are defined in a previous loop.
74452a75d1c4Smrg	continue
74462a75d1c4Smrg	;;
74472a75d1c4Smrg
74482a75d1c4Smrg      -shrext)
74492a75d1c4Smrg	prev=shrext
74502a75d1c4Smrg	continue
74512a75d1c4Smrg	;;
74522a75d1c4Smrg
74532a75d1c4Smrg      -static | -static-libtool-libs)
74542a75d1c4Smrg	# The effects of -static are defined in a previous loop.
74552a75d1c4Smrg	# We used to do the same as -all-static on platforms that
74562a75d1c4Smrg	# didn't have a PIC flag, but the assumption that the effects
74572a75d1c4Smrg	# would be equivalent was wrong.  It would break on at least
74582a75d1c4Smrg	# Digital Unix and AIX.
74592a75d1c4Smrg	continue
74602a75d1c4Smrg	;;
74612a75d1c4Smrg
74622a75d1c4Smrg      -thread-safe)
74632a75d1c4Smrg	thread_safe=yes
74642a75d1c4Smrg	continue
74652a75d1c4Smrg	;;
74662a75d1c4Smrg
74672a75d1c4Smrg      -version-info)
74682a75d1c4Smrg	prev=vinfo
74692a75d1c4Smrg	continue
74702a75d1c4Smrg	;;
74712a75d1c4Smrg
74722a75d1c4Smrg      -version-number)
74732a75d1c4Smrg	prev=vinfo
74742a75d1c4Smrg	vinfo_number=yes
74752a75d1c4Smrg	continue
74762a75d1c4Smrg	;;
74772a75d1c4Smrg
74782a75d1c4Smrg      -weak)
74792a75d1c4Smrg        prev=weak
74802a75d1c4Smrg	continue
74812a75d1c4Smrg	;;
74822a75d1c4Smrg
74832a75d1c4Smrg      -Wc,*)
74842a75d1c4Smrg	func_stripname '-Wc,' '' "$arg"
74852a75d1c4Smrg	args=$func_stripname_result
74862a75d1c4Smrg	arg=
748766ab3337Smrg	save_ifs=$IFS; IFS=,
74882a75d1c4Smrg	for flag in $args; do
748966ab3337Smrg	  IFS=$save_ifs
749066ab3337Smrg          func_quote_arg pretty "$flag"
749166ab3337Smrg	  func_append arg " $func_quote_arg_result"
749266ab3337Smrg	  func_append compiler_flags " $func_quote_arg_result"
74932a75d1c4Smrg	done
749466ab3337Smrg	IFS=$save_ifs
74952a75d1c4Smrg	func_stripname ' ' '' "$arg"
74962a75d1c4Smrg	arg=$func_stripname_result
74972a75d1c4Smrg	;;
74982a75d1c4Smrg
74992a75d1c4Smrg      -Wl,*)
75002a75d1c4Smrg	func_stripname '-Wl,' '' "$arg"
75012a75d1c4Smrg	args=$func_stripname_result
75022a75d1c4Smrg	arg=
750366ab3337Smrg	save_ifs=$IFS; IFS=,
75042a75d1c4Smrg	for flag in $args; do
750566ab3337Smrg	  IFS=$save_ifs
750666ab3337Smrg          func_quote_arg pretty "$flag"
750766ab3337Smrg	  func_append arg " $wl$func_quote_arg_result"
750866ab3337Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
750966ab3337Smrg	  func_append linker_flags " $func_quote_arg_result"
75102a75d1c4Smrg	done
751166ab3337Smrg	IFS=$save_ifs
75122a75d1c4Smrg	func_stripname ' ' '' "$arg"
75132a75d1c4Smrg	arg=$func_stripname_result
75142a75d1c4Smrg	;;
75152a75d1c4Smrg
751666ab3337Smrg      -Xassembler)
751766ab3337Smrg        prev=xassembler
751866ab3337Smrg        continue
751966ab3337Smrg        ;;
752066ab3337Smrg
75212a75d1c4Smrg      -Xcompiler)
75222a75d1c4Smrg	prev=xcompiler
75232a75d1c4Smrg	continue
75242a75d1c4Smrg	;;
75252a75d1c4Smrg
75262a75d1c4Smrg      -Xlinker)
75272a75d1c4Smrg	prev=xlinker
75282a75d1c4Smrg	continue
75292a75d1c4Smrg	;;
75302a75d1c4Smrg
75312a75d1c4Smrg      -XCClinker)
75322a75d1c4Smrg	prev=xcclinker
75332a75d1c4Smrg	continue
75342a75d1c4Smrg	;;
75352a75d1c4Smrg
75362a75d1c4Smrg      # -msg_* for osf cc
75372a75d1c4Smrg      -msg_*)
753866ab3337Smrg	func_quote_arg pretty "$arg"
753966ab3337Smrg	arg=$func_quote_arg_result
75402a75d1c4Smrg	;;
75412a75d1c4Smrg
75422a75d1c4Smrg      # Flags to be passed through unchanged, with rationale:
75432a75d1c4Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
75442a75d1c4Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
75452a75d1c4Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
75462a75d1c4Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
75472a75d1c4Smrg      # -q*                  compiler args for the IBM compiler
75482a75d1c4Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
75492a75d1c4Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
75502a75d1c4Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
755166ab3337Smrg      # -fstack-protector*   stack protector flags for GCC
75522a75d1c4Smrg      # @file                GCC response files
75532a75d1c4Smrg      # -tp=*                Portland pgcc target processor selection
75542a75d1c4Smrg      # --sysroot=*          for sysroot support
755566ab3337Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
755666ab3337Smrg      # -specs=*             GCC specs files
755766ab3337Smrg      # -stdlib=*            select c++ std lib with clang
755866ab3337Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
755966ab3337Smrg      # -fuse-ld=*           Linker select flags for GCC
756066ab3337Smrg      # -Wa,*                Pass flags directly to the assembler
75612a75d1c4Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
75622a75d1c4Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
756366ab3337Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
756466ab3337Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
756566ab3337Smrg        func_quote_arg pretty "$arg"
756666ab3337Smrg	arg=$func_quote_arg_result
75672a75d1c4Smrg        func_append compile_command " $arg"
75682a75d1c4Smrg        func_append finalize_command " $arg"
75692a75d1c4Smrg        func_append compiler_flags " $arg"
75702a75d1c4Smrg        continue
75712a75d1c4Smrg        ;;
75722a75d1c4Smrg
757366ab3337Smrg      -Z*)
757466ab3337Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
757566ab3337Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
757666ab3337Smrg	  compiler_flags="$compiler_flags $arg"
757766ab3337Smrg	  func_append compile_command " $arg"
757866ab3337Smrg	  func_append finalize_command " $arg"
757966ab3337Smrg	  case $arg in
758066ab3337Smrg	  -Zlinker | -Zstack)
758166ab3337Smrg	    prev=xcompiler
758266ab3337Smrg	    ;;
758366ab3337Smrg	  esac
758466ab3337Smrg	  continue
758566ab3337Smrg        else
758666ab3337Smrg	  # Otherwise treat like 'Some other compiler flag' below
758766ab3337Smrg	  func_quote_arg pretty "$arg"
758866ab3337Smrg	  arg=$func_quote_arg_result
758966ab3337Smrg        fi
759066ab3337Smrg	;;
759166ab3337Smrg
75922a75d1c4Smrg      # Some other compiler flag.
75932a75d1c4Smrg      -* | +*)
759466ab3337Smrg        func_quote_arg pretty "$arg"
759566ab3337Smrg	arg=$func_quote_arg_result
75962a75d1c4Smrg	;;
75972a75d1c4Smrg
75982a75d1c4Smrg      *.$objext)
75992a75d1c4Smrg	# A standard object.
76002a75d1c4Smrg	func_append objs " $arg"
76012a75d1c4Smrg	;;
76022a75d1c4Smrg
76032a75d1c4Smrg      *.lo)
76042a75d1c4Smrg	# A libtool-controlled object.
76052a75d1c4Smrg
76062a75d1c4Smrg	# Check to see that this really is a libtool object.
76072a75d1c4Smrg	if func_lalib_unsafe_p "$arg"; then
76082a75d1c4Smrg	  pic_object=
76092a75d1c4Smrg	  non_pic_object=
76102a75d1c4Smrg
76112a75d1c4Smrg	  # Read the .lo file
76122a75d1c4Smrg	  func_source "$arg"
76132a75d1c4Smrg
76142a75d1c4Smrg	  if test -z "$pic_object" ||
76152a75d1c4Smrg	     test -z "$non_pic_object" ||
761666ab3337Smrg	     test none = "$pic_object" &&
761766ab3337Smrg	     test none = "$non_pic_object"; then
761866ab3337Smrg	    func_fatal_error "cannot find name of object for '$arg'"
76192a75d1c4Smrg	  fi
76202a75d1c4Smrg
76212a75d1c4Smrg	  # Extract subdirectory from the argument.
76222a75d1c4Smrg	  func_dirname "$arg" "/" ""
762366ab3337Smrg	  xdir=$func_dirname_result
76242a75d1c4Smrg
762566ab3337Smrg	  test none = "$pic_object" || {
76262a75d1c4Smrg	    # Prepend the subdirectory the object is found in.
762766ab3337Smrg	    pic_object=$xdir$pic_object
76282a75d1c4Smrg
762966ab3337Smrg	    if test dlfiles = "$prev"; then
763066ab3337Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
76312a75d1c4Smrg		func_append dlfiles " $pic_object"
76322a75d1c4Smrg		prev=
76332a75d1c4Smrg		continue
76342a75d1c4Smrg	      else
76352a75d1c4Smrg		# If libtool objects are unsupported, then we need to preload.
76362a75d1c4Smrg		prev=dlprefiles
76372a75d1c4Smrg	      fi
76382a75d1c4Smrg	    fi
76392a75d1c4Smrg
76402a75d1c4Smrg	    # CHECK ME:  I think I busted this.  -Ossama
764166ab3337Smrg	    if test dlprefiles = "$prev"; then
76422a75d1c4Smrg	      # Preload the old-style object.
76432a75d1c4Smrg	      func_append dlprefiles " $pic_object"
76442a75d1c4Smrg	      prev=
76452a75d1c4Smrg	    fi
76462a75d1c4Smrg
76472a75d1c4Smrg	    # A PIC object.
76482a75d1c4Smrg	    func_append libobjs " $pic_object"
764966ab3337Smrg	    arg=$pic_object
765066ab3337Smrg	  }
76512a75d1c4Smrg
76522a75d1c4Smrg	  # Non-PIC object.
765366ab3337Smrg	  if test none != "$non_pic_object"; then
76542a75d1c4Smrg	    # Prepend the subdirectory the object is found in.
765566ab3337Smrg	    non_pic_object=$xdir$non_pic_object
76562a75d1c4Smrg
76572a75d1c4Smrg	    # A standard non-PIC object
76582a75d1c4Smrg	    func_append non_pic_objects " $non_pic_object"
765966ab3337Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
766066ab3337Smrg	      arg=$non_pic_object
76612a75d1c4Smrg	    fi
76622a75d1c4Smrg	  else
76632a75d1c4Smrg	    # If the PIC object exists, use it instead.
76642a75d1c4Smrg	    # $xdir was prepended to $pic_object above.
766566ab3337Smrg	    non_pic_object=$pic_object
76662a75d1c4Smrg	    func_append non_pic_objects " $non_pic_object"
76672a75d1c4Smrg	  fi
76682a75d1c4Smrg	else
76692a75d1c4Smrg	  # Only an error if not doing a dry-run.
76702a75d1c4Smrg	  if $opt_dry_run; then
76712a75d1c4Smrg	    # Extract subdirectory from the argument.
76722a75d1c4Smrg	    func_dirname "$arg" "/" ""
767366ab3337Smrg	    xdir=$func_dirname_result
76742a75d1c4Smrg
76752a75d1c4Smrg	    func_lo2o "$arg"
76762a75d1c4Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
76772a75d1c4Smrg	    non_pic_object=$xdir$func_lo2o_result
76782a75d1c4Smrg	    func_append libobjs " $pic_object"
76792a75d1c4Smrg	    func_append non_pic_objects " $non_pic_object"
76802a75d1c4Smrg	  else
768166ab3337Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
76822a75d1c4Smrg	  fi
76832a75d1c4Smrg	fi
76842a75d1c4Smrg	;;
76852a75d1c4Smrg
76862a75d1c4Smrg      *.$libext)
76872a75d1c4Smrg	# An archive.
76882a75d1c4Smrg	func_append deplibs " $arg"
76892a75d1c4Smrg	func_append old_deplibs " $arg"
76902a75d1c4Smrg	continue
76912a75d1c4Smrg	;;
76922a75d1c4Smrg
76932a75d1c4Smrg      *.la)
76942a75d1c4Smrg	# A libtool-controlled library.
76952a75d1c4Smrg
76962a75d1c4Smrg	func_resolve_sysroot "$arg"
769766ab3337Smrg	if test dlfiles = "$prev"; then
76982a75d1c4Smrg	  # This library was specified with -dlopen.
76992a75d1c4Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
77002a75d1c4Smrg	  prev=
770166ab3337Smrg	elif test dlprefiles = "$prev"; then
77022a75d1c4Smrg	  # The library was specified with -dlpreopen.
77032a75d1c4Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
77042a75d1c4Smrg	  prev=
77052a75d1c4Smrg	else
77062a75d1c4Smrg	  func_append deplibs " $func_resolve_sysroot_result"
77072a75d1c4Smrg	fi
77082a75d1c4Smrg	continue
77092a75d1c4Smrg	;;
77102a75d1c4Smrg
77112a75d1c4Smrg      # Some other compiler argument.
77122a75d1c4Smrg      *)
77132a75d1c4Smrg	# Unknown arguments in both finalize_command and compile_command need
77142a75d1c4Smrg	# to be aesthetically quoted because they are evaled later.
771566ab3337Smrg	func_quote_arg pretty "$arg"
771666ab3337Smrg	arg=$func_quote_arg_result
77172a75d1c4Smrg	;;
77182a75d1c4Smrg      esac # arg
77192a75d1c4Smrg
77202a75d1c4Smrg      # Now actually substitute the argument into the commands.
77212a75d1c4Smrg      if test -n "$arg"; then
77222a75d1c4Smrg	func_append compile_command " $arg"
77232a75d1c4Smrg	func_append finalize_command " $arg"
77242a75d1c4Smrg      fi
77252a75d1c4Smrg    done # argument parsing loop
77262a75d1c4Smrg
77272a75d1c4Smrg    test -n "$prev" && \
772866ab3337Smrg      func_fatal_help "the '$prevarg' option requires an argument"
77292a75d1c4Smrg
773066ab3337Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
77312a75d1c4Smrg      eval arg=\"$export_dynamic_flag_spec\"
77322a75d1c4Smrg      func_append compile_command " $arg"
77332a75d1c4Smrg      func_append finalize_command " $arg"
77342a75d1c4Smrg    fi
77352a75d1c4Smrg
77362a75d1c4Smrg    oldlibs=
77372a75d1c4Smrg    # calculate the name of the file, without its directory
77382a75d1c4Smrg    func_basename "$output"
773966ab3337Smrg    outputname=$func_basename_result
774066ab3337Smrg    libobjs_save=$libobjs
77412a75d1c4Smrg
77422a75d1c4Smrg    if test -n "$shlibpath_var"; then
77432a75d1c4Smrg      # get the directories listed in $shlibpath_var
774466ab3337Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
77452a75d1c4Smrg    else
77462a75d1c4Smrg      shlib_search_path=
77472a75d1c4Smrg    fi
77482a75d1c4Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
77492a75d1c4Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
77502a75d1c4Smrg
775166ab3337Smrg    # Definition is injected by LT_CONFIG during libtool generation.
775266ab3337Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
775366ab3337Smrg
77542a75d1c4Smrg    func_dirname "$output" "/" ""
775566ab3337Smrg    output_objdir=$func_dirname_result$objdir
77562a75d1c4Smrg    func_to_tool_file "$output_objdir/"
77572a75d1c4Smrg    tool_output_objdir=$func_to_tool_file_result
77582a75d1c4Smrg    # Create the object directory.
77592a75d1c4Smrg    func_mkdir_p "$output_objdir"
77602a75d1c4Smrg
77612a75d1c4Smrg    # Determine the type of output
77622a75d1c4Smrg    case $output in
77632a75d1c4Smrg    "")
77642a75d1c4Smrg      func_fatal_help "you must specify an output file"
77652a75d1c4Smrg      ;;
77662a75d1c4Smrg    *.$libext) linkmode=oldlib ;;
77672a75d1c4Smrg    *.lo | *.$objext) linkmode=obj ;;
77682a75d1c4Smrg    *.la) linkmode=lib ;;
77692a75d1c4Smrg    *) linkmode=prog ;; # Anything else should be a program.
77702a75d1c4Smrg    esac
77712a75d1c4Smrg
77722a75d1c4Smrg    specialdeplibs=
77732a75d1c4Smrg
77742a75d1c4Smrg    libs=
77752a75d1c4Smrg    # Find all interdependent deplibs by searching for libraries
77762a75d1c4Smrg    # that are linked more than once (e.g. -la -lb -la)
77772a75d1c4Smrg    for deplib in $deplibs; do
777866ab3337Smrg      if $opt_preserve_dup_deps; then
77792a75d1c4Smrg	case "$libs " in
77802a75d1c4Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
77812a75d1c4Smrg	esac
77822a75d1c4Smrg      fi
77832a75d1c4Smrg      func_append libs " $deplib"
77842a75d1c4Smrg    done
77852a75d1c4Smrg
778666ab3337Smrg    if test lib = "$linkmode"; then
77872a75d1c4Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
77882a75d1c4Smrg
77892a75d1c4Smrg      # Compute libraries that are listed more than once in $predeps
77902a75d1c4Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
77912a75d1c4Smrg      # not to be eliminated).
77922a75d1c4Smrg      pre_post_deps=
77932a75d1c4Smrg      if $opt_duplicate_compiler_generated_deps; then
77942a75d1c4Smrg	for pre_post_dep in $predeps $postdeps; do
77952a75d1c4Smrg	  case "$pre_post_deps " in
77962a75d1c4Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
77972a75d1c4Smrg	  esac
77982a75d1c4Smrg	  func_append pre_post_deps " $pre_post_dep"
77992a75d1c4Smrg	done
78002a75d1c4Smrg      fi
78012a75d1c4Smrg      pre_post_deps=
78022a75d1c4Smrg    fi
78032a75d1c4Smrg
78042a75d1c4Smrg    deplibs=
78052a75d1c4Smrg    newdependency_libs=
78062a75d1c4Smrg    newlib_search_path=
78072a75d1c4Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
78082a75d1c4Smrg    notinst_deplibs= # not-installed libtool libraries
78092a75d1c4Smrg    notinst_path= # paths that contain not-installed libtool libraries
78102a75d1c4Smrg
78112a75d1c4Smrg    case $linkmode in
78122a75d1c4Smrg    lib)
78132a75d1c4Smrg	passes="conv dlpreopen link"
78142a75d1c4Smrg	for file in $dlfiles $dlprefiles; do
78152a75d1c4Smrg	  case $file in
78162a75d1c4Smrg	  *.la) ;;
78172a75d1c4Smrg	  *)
781866ab3337Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
78192a75d1c4Smrg	    ;;
78202a75d1c4Smrg	  esac
78212a75d1c4Smrg	done
78222a75d1c4Smrg	;;
78232a75d1c4Smrg    prog)
78242a75d1c4Smrg	compile_deplibs=
78252a75d1c4Smrg	finalize_deplibs=
782666ab3337Smrg	alldeplibs=false
78272a75d1c4Smrg	newdlfiles=
78282a75d1c4Smrg	newdlprefiles=
78292a75d1c4Smrg	passes="conv scan dlopen dlpreopen link"
78302a75d1c4Smrg	;;
78312a75d1c4Smrg    *)  passes="conv"
78322a75d1c4Smrg	;;
78332a75d1c4Smrg    esac
78342a75d1c4Smrg
78352a75d1c4Smrg    for pass in $passes; do
78362a75d1c4Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
78372a75d1c4Smrg      # so that -L comes before libs that need it for instance...
783866ab3337Smrg      if test lib,link = "$linkmode,$pass"; then
78392a75d1c4Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
78402a75d1c4Smrg	##        order, and fix it there properly
78412a75d1c4Smrg        tmp_deplibs=
78422a75d1c4Smrg	for deplib in $deplibs; do
78432a75d1c4Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
78442a75d1c4Smrg	done
784566ab3337Smrg	deplibs=$tmp_deplibs
78462a75d1c4Smrg      fi
78472a75d1c4Smrg
784866ab3337Smrg      if test lib,link = "$linkmode,$pass" ||
784966ab3337Smrg	 test prog,scan = "$linkmode,$pass"; then
785066ab3337Smrg	libs=$deplibs
78512a75d1c4Smrg	deplibs=
78522a75d1c4Smrg      fi
785366ab3337Smrg      if test prog = "$linkmode"; then
78542a75d1c4Smrg	case $pass in
785566ab3337Smrg	dlopen) libs=$dlfiles ;;
785666ab3337Smrg	dlpreopen) libs=$dlprefiles ;;
78572a75d1c4Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
78582a75d1c4Smrg	esac
78592a75d1c4Smrg      fi
786066ab3337Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
78612a75d1c4Smrg	# Collect and forward deplibs of preopened libtool libs
78622a75d1c4Smrg	for lib in $dlprefiles; do
78632a75d1c4Smrg	  # Ignore non-libtool-libs
78642a75d1c4Smrg	  dependency_libs=
78652a75d1c4Smrg	  func_resolve_sysroot "$lib"
78662a75d1c4Smrg	  case $lib in
78672a75d1c4Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
78682a75d1c4Smrg	  esac
78692a75d1c4Smrg
78702a75d1c4Smrg	  # Collect preopened libtool deplibs, except any this library
78712a75d1c4Smrg	  # has declared as weak libs
78722a75d1c4Smrg	  for deplib in $dependency_libs; do
78732a75d1c4Smrg	    func_basename "$deplib"
78742a75d1c4Smrg            deplib_base=$func_basename_result
78752a75d1c4Smrg	    case " $weak_libs " in
78762a75d1c4Smrg	    *" $deplib_base "*) ;;
78772a75d1c4Smrg	    *) func_append deplibs " $deplib" ;;
78782a75d1c4Smrg	    esac
78792a75d1c4Smrg	  done
78802a75d1c4Smrg	done
788166ab3337Smrg	libs=$dlprefiles
78822a75d1c4Smrg      fi
788366ab3337Smrg      if test dlopen = "$pass"; then
78842a75d1c4Smrg	# Collect dlpreopened libraries
788566ab3337Smrg	save_deplibs=$deplibs
78862a75d1c4Smrg	deplibs=
78872a75d1c4Smrg      fi
78882a75d1c4Smrg
78892a75d1c4Smrg      for deplib in $libs; do
78902a75d1c4Smrg	lib=
789166ab3337Smrg	found=false
78922a75d1c4Smrg	case $deplib in
789366ab3337Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
789466ab3337Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
789566ab3337Smrg	  if test prog,link = "$linkmode,$pass"; then
78962a75d1c4Smrg	    compile_deplibs="$deplib $compile_deplibs"
78972a75d1c4Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
78982a75d1c4Smrg	  else
78992a75d1c4Smrg	    func_append compiler_flags " $deplib"
790066ab3337Smrg	    if test lib = "$linkmode"; then
79012a75d1c4Smrg		case "$new_inherited_linker_flags " in
79022a75d1c4Smrg		    *" $deplib "*) ;;
79032a75d1c4Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79042a75d1c4Smrg		esac
79052a75d1c4Smrg	    fi
79062a75d1c4Smrg	  fi
79072a75d1c4Smrg	  continue
79082a75d1c4Smrg	  ;;
79092a75d1c4Smrg	-l*)
791066ab3337Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
791166ab3337Smrg	    func_warning "'-l' is ignored for archives/objects"
79122a75d1c4Smrg	    continue
79132a75d1c4Smrg	  fi
79142a75d1c4Smrg	  func_stripname '-l' '' "$deplib"
79152a75d1c4Smrg	  name=$func_stripname_result
791666ab3337Smrg	  if test lib = "$linkmode"; then
79172a75d1c4Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
79182a75d1c4Smrg	  else
79192a75d1c4Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
79202a75d1c4Smrg	  fi
79212a75d1c4Smrg	  for searchdir in $searchdirs; do
79222a75d1c4Smrg	    for search_ext in .la $std_shrext .so .a; do
79232a75d1c4Smrg	      # Search the libtool library
792466ab3337Smrg	      lib=$searchdir/lib$name$search_ext
79252a75d1c4Smrg	      if test -f "$lib"; then
792666ab3337Smrg		if test .la = "$search_ext"; then
792766ab3337Smrg		  found=:
79282a75d1c4Smrg		else
792966ab3337Smrg		  found=false
79302a75d1c4Smrg		fi
79312a75d1c4Smrg		break 2
79322a75d1c4Smrg	      fi
79332a75d1c4Smrg	    done
79342a75d1c4Smrg	  done
793566ab3337Smrg	  if $found; then
793666ab3337Smrg	    # deplib is a libtool library
79372a75d1c4Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
79382a75d1c4Smrg	    # We need to do some special things here, and not later.
793966ab3337Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
79402a75d1c4Smrg	      case " $predeps $postdeps " in
79412a75d1c4Smrg	      *" $deplib "*)
79422a75d1c4Smrg		if func_lalib_p "$lib"; then
79432a75d1c4Smrg		  library_names=
79442a75d1c4Smrg		  old_library=
79452a75d1c4Smrg		  func_source "$lib"
79462a75d1c4Smrg		  for l in $old_library $library_names; do
794766ab3337Smrg		    ll=$l
79482a75d1c4Smrg		  done
794966ab3337Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
795066ab3337Smrg		    found=false
79512a75d1c4Smrg		    func_dirname "$lib" "" "."
795266ab3337Smrg		    ladir=$func_dirname_result
79532a75d1c4Smrg		    lib=$ladir/$old_library
795466ab3337Smrg		    if test prog,link = "$linkmode,$pass"; then
79552a75d1c4Smrg		      compile_deplibs="$deplib $compile_deplibs"
79562a75d1c4Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
79572a75d1c4Smrg		    else
79582a75d1c4Smrg		      deplibs="$deplib $deplibs"
795966ab3337Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79602a75d1c4Smrg		    fi
79612a75d1c4Smrg		    continue
79622a75d1c4Smrg		  fi
79632a75d1c4Smrg		fi
79642a75d1c4Smrg		;;
79652a75d1c4Smrg	      *) ;;
79662a75d1c4Smrg	      esac
79672a75d1c4Smrg	    fi
796866ab3337Smrg	  else
796966ab3337Smrg	    # deplib doesn't seem to be a libtool library
797066ab3337Smrg	    if test prog,link = "$linkmode,$pass"; then
797166ab3337Smrg	      compile_deplibs="$deplib $compile_deplibs"
797266ab3337Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
797366ab3337Smrg	    else
797466ab3337Smrg	      deplibs="$deplib $deplibs"
797566ab3337Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
797666ab3337Smrg	    fi
797766ab3337Smrg	    continue
79782a75d1c4Smrg	  fi
79792a75d1c4Smrg	  ;; # -l
79802a75d1c4Smrg	*.ltframework)
798166ab3337Smrg	  if test prog,link = "$linkmode,$pass"; then
79822a75d1c4Smrg	    compile_deplibs="$deplib $compile_deplibs"
79832a75d1c4Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
79842a75d1c4Smrg	  else
79852a75d1c4Smrg	    deplibs="$deplib $deplibs"
798666ab3337Smrg	    if test lib = "$linkmode"; then
79872a75d1c4Smrg		case "$new_inherited_linker_flags " in
79882a75d1c4Smrg		    *" $deplib "*) ;;
79892a75d1c4Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79902a75d1c4Smrg		esac
79912a75d1c4Smrg	    fi
79922a75d1c4Smrg	  fi
79932a75d1c4Smrg	  continue
79942a75d1c4Smrg	  ;;
79952a75d1c4Smrg	-L*)
79962a75d1c4Smrg	  case $linkmode in
79972a75d1c4Smrg	  lib)
79982a75d1c4Smrg	    deplibs="$deplib $deplibs"
799966ab3337Smrg	    test conv = "$pass" && continue
80002a75d1c4Smrg	    newdependency_libs="$deplib $newdependency_libs"
80012a75d1c4Smrg	    func_stripname '-L' '' "$deplib"
80022a75d1c4Smrg	    func_resolve_sysroot "$func_stripname_result"
80032a75d1c4Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80042a75d1c4Smrg	    ;;
80052a75d1c4Smrg	  prog)
800666ab3337Smrg	    if test conv = "$pass"; then
80072a75d1c4Smrg	      deplibs="$deplib $deplibs"
80082a75d1c4Smrg	      continue
80092a75d1c4Smrg	    fi
801066ab3337Smrg	    if test scan = "$pass"; then
80112a75d1c4Smrg	      deplibs="$deplib $deplibs"
80122a75d1c4Smrg	    else
80132a75d1c4Smrg	      compile_deplibs="$deplib $compile_deplibs"
80142a75d1c4Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80152a75d1c4Smrg	    fi
80162a75d1c4Smrg	    func_stripname '-L' '' "$deplib"
80172a75d1c4Smrg	    func_resolve_sysroot "$func_stripname_result"
80182a75d1c4Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80192a75d1c4Smrg	    ;;
80202a75d1c4Smrg	  *)
802166ab3337Smrg	    func_warning "'-L' is ignored for archives/objects"
80222a75d1c4Smrg	    ;;
80232a75d1c4Smrg	  esac # linkmode
80242a75d1c4Smrg	  continue
80252a75d1c4Smrg	  ;; # -L
80262a75d1c4Smrg	-R*)
802766ab3337Smrg	  if test link = "$pass"; then
80282a75d1c4Smrg	    func_stripname '-R' '' "$deplib"
80292a75d1c4Smrg	    func_resolve_sysroot "$func_stripname_result"
80302a75d1c4Smrg	    dir=$func_resolve_sysroot_result
80312a75d1c4Smrg	    # Make sure the xrpath contains only unique directories.
80322a75d1c4Smrg	    case "$xrpath " in
80332a75d1c4Smrg	    *" $dir "*) ;;
80342a75d1c4Smrg	    *) func_append xrpath " $dir" ;;
80352a75d1c4Smrg	    esac
80362a75d1c4Smrg	  fi
80372a75d1c4Smrg	  deplibs="$deplib $deplibs"
80382a75d1c4Smrg	  continue
80392a75d1c4Smrg	  ;;
80402a75d1c4Smrg	*.la)
80412a75d1c4Smrg	  func_resolve_sysroot "$deplib"
80422a75d1c4Smrg	  lib=$func_resolve_sysroot_result
80432a75d1c4Smrg	  ;;
80442a75d1c4Smrg	*.$libext)
804566ab3337Smrg	  if test conv = "$pass"; then
80462a75d1c4Smrg	    deplibs="$deplib $deplibs"
80472a75d1c4Smrg	    continue
80482a75d1c4Smrg	  fi
80492a75d1c4Smrg	  case $linkmode in
80502a75d1c4Smrg	  lib)
80512a75d1c4Smrg	    # Linking convenience modules into shared libraries is allowed,
80522a75d1c4Smrg	    # but linking other static libraries is non-portable.
80532a75d1c4Smrg	    case " $dlpreconveniencelibs " in
80542a75d1c4Smrg	    *" $deplib "*) ;;
80552a75d1c4Smrg	    *)
805666ab3337Smrg	      valid_a_lib=false
80572a75d1c4Smrg	      case $deplibs_check_method in
80582a75d1c4Smrg		match_pattern*)
80592a75d1c4Smrg		  set dummy $deplibs_check_method; shift
80602a75d1c4Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
80612a75d1c4Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
80622a75d1c4Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
806366ab3337Smrg		    valid_a_lib=:
80642a75d1c4Smrg		  fi
80652a75d1c4Smrg		;;
80662a75d1c4Smrg		pass_all)
806766ab3337Smrg		  valid_a_lib=:
80682a75d1c4Smrg		;;
80692a75d1c4Smrg	      esac
807066ab3337Smrg	      if $valid_a_lib; then
807166ab3337Smrg		echo
807266ab3337Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
807366ab3337Smrg		$ECHO "*** static library $deplib is not portable!"
807466ab3337Smrg		deplibs="$deplib $deplibs"
807566ab3337Smrg	      else
80762a75d1c4Smrg		echo
80772a75d1c4Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
80782a75d1c4Smrg		echo "*** I have the capability to make that library automatically link in when"
80792a75d1c4Smrg		echo "*** you link to this library.  But I can only do this if you have a"
80802a75d1c4Smrg		echo "*** shared version of the library, which you do not appear to have"
80812a75d1c4Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
80822a75d1c4Smrg		echo "*** that it is just a static archive that I should not use here."
80832a75d1c4Smrg	      fi
80842a75d1c4Smrg	      ;;
80852a75d1c4Smrg	    esac
80862a75d1c4Smrg	    continue
80872a75d1c4Smrg	    ;;
80882a75d1c4Smrg	  prog)
808966ab3337Smrg	    if test link != "$pass"; then
80902a75d1c4Smrg	      deplibs="$deplib $deplibs"
80912a75d1c4Smrg	    else
80922a75d1c4Smrg	      compile_deplibs="$deplib $compile_deplibs"
80932a75d1c4Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80942a75d1c4Smrg	    fi
80952a75d1c4Smrg	    continue
80962a75d1c4Smrg	    ;;
80972a75d1c4Smrg	  esac # linkmode
80982a75d1c4Smrg	  ;; # *.$libext
80992a75d1c4Smrg	*.lo | *.$objext)
810066ab3337Smrg	  if test conv = "$pass"; then
81012a75d1c4Smrg	    deplibs="$deplib $deplibs"
810266ab3337Smrg	  elif test prog = "$linkmode"; then
810366ab3337Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
81042a75d1c4Smrg	      # If there is no dlopen support or we're linking statically,
81052a75d1c4Smrg	      # we need to preload.
81062a75d1c4Smrg	      func_append newdlprefiles " $deplib"
81072a75d1c4Smrg	      compile_deplibs="$deplib $compile_deplibs"
81082a75d1c4Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
81092a75d1c4Smrg	    else
81102a75d1c4Smrg	      func_append newdlfiles " $deplib"
81112a75d1c4Smrg	    fi
81122a75d1c4Smrg	  fi
81132a75d1c4Smrg	  continue
81142a75d1c4Smrg	  ;;
81152a75d1c4Smrg	%DEPLIBS%)
811666ab3337Smrg	  alldeplibs=:
81172a75d1c4Smrg	  continue
81182a75d1c4Smrg	  ;;
81192a75d1c4Smrg	esac # case $deplib
81202a75d1c4Smrg
812166ab3337Smrg	$found || test -f "$lib" \
812266ab3337Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
81232a75d1c4Smrg
81242a75d1c4Smrg	# Check to see that this really is a libtool archive.
81252a75d1c4Smrg	func_lalib_unsafe_p "$lib" \
812666ab3337Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
81272a75d1c4Smrg
81282a75d1c4Smrg	func_dirname "$lib" "" "."
812966ab3337Smrg	ladir=$func_dirname_result
81302a75d1c4Smrg
81312a75d1c4Smrg	dlname=
81322a75d1c4Smrg	dlopen=
81332a75d1c4Smrg	dlpreopen=
81342a75d1c4Smrg	libdir=
81352a75d1c4Smrg	library_names=
81362a75d1c4Smrg	old_library=
81372a75d1c4Smrg	inherited_linker_flags=
81382a75d1c4Smrg	# If the library was installed with an old release of libtool,
81392a75d1c4Smrg	# it will not redefine variables installed, or shouldnotlink
81402a75d1c4Smrg	installed=yes
81412a75d1c4Smrg	shouldnotlink=no
81422a75d1c4Smrg	avoidtemprpath=
81432a75d1c4Smrg
81442a75d1c4Smrg
81452a75d1c4Smrg	# Read the .la file
81462a75d1c4Smrg	func_source "$lib"
81472a75d1c4Smrg
81482a75d1c4Smrg	# Convert "-framework foo" to "foo.ltframework"
81492a75d1c4Smrg	if test -n "$inherited_linker_flags"; then
81502a75d1c4Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
81512a75d1c4Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
81522a75d1c4Smrg	    case " $new_inherited_linker_flags " in
81532a75d1c4Smrg	      *" $tmp_inherited_linker_flag "*) ;;
81542a75d1c4Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
81552a75d1c4Smrg	    esac
81562a75d1c4Smrg	  done
81572a75d1c4Smrg	fi
81582a75d1c4Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
815966ab3337Smrg	if test lib,link = "$linkmode,$pass" ||
816066ab3337Smrg	   test prog,scan = "$linkmode,$pass" ||
816166ab3337Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
81622a75d1c4Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
81632a75d1c4Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
81642a75d1c4Smrg	fi
81652a75d1c4Smrg
816666ab3337Smrg	if test conv = "$pass"; then
81672a75d1c4Smrg	  # Only check for convenience libraries
81682a75d1c4Smrg	  deplibs="$lib $deplibs"
81692a75d1c4Smrg	  if test -z "$libdir"; then
81702a75d1c4Smrg	    if test -z "$old_library"; then
817166ab3337Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
81722a75d1c4Smrg	    fi
81732a75d1c4Smrg	    # It is a libtool convenience library, so add in its objects.
81742a75d1c4Smrg	    func_append convenience " $ladir/$objdir/$old_library"
81752a75d1c4Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
817666ab3337Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
817766ab3337Smrg	    func_fatal_error "'$lib' is not a convenience library"
81782a75d1c4Smrg	  fi
81792a75d1c4Smrg	  tmp_libs=
81802a75d1c4Smrg	  for deplib in $dependency_libs; do
81812a75d1c4Smrg	    deplibs="$deplib $deplibs"
818266ab3337Smrg	    if $opt_preserve_dup_deps; then
81832a75d1c4Smrg	      case "$tmp_libs " in
81842a75d1c4Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
81852a75d1c4Smrg	      esac
81862a75d1c4Smrg	    fi
81872a75d1c4Smrg	    func_append tmp_libs " $deplib"
81882a75d1c4Smrg	  done
81892a75d1c4Smrg	  continue
81902a75d1c4Smrg	fi # $pass = conv
81912a75d1c4Smrg
81922a75d1c4Smrg
81932a75d1c4Smrg	# Get the name of the library we link against.
81942a75d1c4Smrg	linklib=
81952a75d1c4Smrg	if test -n "$old_library" &&
819666ab3337Smrg	   { test yes = "$prefer_static_libs" ||
819766ab3337Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
81982a75d1c4Smrg	  linklib=$old_library
81992a75d1c4Smrg	else
82002a75d1c4Smrg	  for l in $old_library $library_names; do
820166ab3337Smrg	    linklib=$l
82022a75d1c4Smrg	  done
82032a75d1c4Smrg	fi
82042a75d1c4Smrg	if test -z "$linklib"; then
820566ab3337Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
82062a75d1c4Smrg	fi
82072a75d1c4Smrg
82082a75d1c4Smrg	# This library was specified with -dlopen.
820966ab3337Smrg	if test dlopen = "$pass"; then
821066ab3337Smrg	  test -z "$libdir" \
821166ab3337Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
82122a75d1c4Smrg	  if test -z "$dlname" ||
821366ab3337Smrg	     test yes != "$dlopen_support" ||
821466ab3337Smrg	     test no = "$build_libtool_libs"
821566ab3337Smrg	  then
82162a75d1c4Smrg	    # If there is no dlname, no dlopen support or we're linking
82172a75d1c4Smrg	    # statically, we need to preload.  We also need to preload any
82182a75d1c4Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
82192a75d1c4Smrg	    # bomb out in the load deplibs phase.
82202a75d1c4Smrg	    func_append dlprefiles " $lib $dependency_libs"
82212a75d1c4Smrg	  else
82222a75d1c4Smrg	    func_append newdlfiles " $lib"
82232a75d1c4Smrg	  fi
82242a75d1c4Smrg	  continue
82252a75d1c4Smrg	fi # $pass = dlopen
82262a75d1c4Smrg
82272a75d1c4Smrg	# We need an absolute path.
82282a75d1c4Smrg	case $ladir in
822966ab3337Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
82302a75d1c4Smrg	*)
82312a75d1c4Smrg	  abs_ladir=`cd "$ladir" && pwd`
82322a75d1c4Smrg	  if test -z "$abs_ladir"; then
823366ab3337Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
82342a75d1c4Smrg	    func_warning "passing it literally to the linker, although it might fail"
823566ab3337Smrg	    abs_ladir=$ladir
82362a75d1c4Smrg	  fi
82372a75d1c4Smrg	  ;;
82382a75d1c4Smrg	esac
82392a75d1c4Smrg	func_basename "$lib"
824066ab3337Smrg	laname=$func_basename_result
82412a75d1c4Smrg
82422a75d1c4Smrg	# Find the relevant object directory and library name.
824366ab3337Smrg	if test yes = "$installed"; then
82442a75d1c4Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
824566ab3337Smrg	    func_warning "library '$lib' was moved."
824666ab3337Smrg	    dir=$ladir
824766ab3337Smrg	    absdir=$abs_ladir
824866ab3337Smrg	    libdir=$abs_ladir
82492a75d1c4Smrg	  else
825066ab3337Smrg	    dir=$lt_sysroot$libdir
825166ab3337Smrg	    absdir=$lt_sysroot$libdir
82522a75d1c4Smrg	  fi
825366ab3337Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
82542a75d1c4Smrg	else
82552a75d1c4Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
825666ab3337Smrg	    dir=$ladir
825766ab3337Smrg	    absdir=$abs_ladir
82582a75d1c4Smrg	    # Remove this search path later
82592a75d1c4Smrg	    func_append notinst_path " $abs_ladir"
82602a75d1c4Smrg	  else
826166ab3337Smrg	    dir=$ladir/$objdir
826266ab3337Smrg	    absdir=$abs_ladir/$objdir
82632a75d1c4Smrg	    # Remove this search path later
82642a75d1c4Smrg	    func_append notinst_path " $abs_ladir"
82652a75d1c4Smrg	  fi
82662a75d1c4Smrg	fi # $installed = yes
82672a75d1c4Smrg	func_stripname 'lib' '.la' "$laname"
82682a75d1c4Smrg	name=$func_stripname_result
82692a75d1c4Smrg
82702a75d1c4Smrg	# This library was specified with -dlpreopen.
827166ab3337Smrg	if test dlpreopen = "$pass"; then
827266ab3337Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
827366ab3337Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
82742a75d1c4Smrg	  fi
827566ab3337Smrg	  case $host in
82762a75d1c4Smrg	    # special handling for platforms with PE-DLLs.
82772a75d1c4Smrg	    *cygwin* | *mingw* | *cegcc* )
82782a75d1c4Smrg	      # Linker will automatically link against shared library if both
82792a75d1c4Smrg	      # static and shared are present.  Therefore, ensure we extract
82802a75d1c4Smrg	      # symbols from the import library if a shared library is present
82812a75d1c4Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
82822a75d1c4Smrg	      # this by putting the import library name into $newdlprefiles.
82832a75d1c4Smrg	      # We recover the dlopen module name by 'saving' the la file
82842a75d1c4Smrg	      # name in a special purpose variable, and (later) extracting the
82852a75d1c4Smrg	      # dlname from the la file.
82862a75d1c4Smrg	      if test -n "$dlname"; then
82872a75d1c4Smrg	        func_tr_sh "$dir/$linklib"
82882a75d1c4Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
82892a75d1c4Smrg	        func_append newdlprefiles " $dir/$linklib"
82902a75d1c4Smrg	      else
82912a75d1c4Smrg	        func_append newdlprefiles " $dir/$old_library"
82922a75d1c4Smrg	        # Keep a list of preopened convenience libraries to check
82932a75d1c4Smrg	        # that they are being used correctly in the link pass.
82942a75d1c4Smrg	        test -z "$libdir" && \
82952a75d1c4Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
82962a75d1c4Smrg	      fi
82972a75d1c4Smrg	    ;;
82982a75d1c4Smrg	    * )
82992a75d1c4Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
83002a75d1c4Smrg	      # are required to link).
83012a75d1c4Smrg	      if test -n "$old_library"; then
83022a75d1c4Smrg	        func_append newdlprefiles " $dir/$old_library"
83032a75d1c4Smrg	        # Keep a list of preopened convenience libraries to check
83042a75d1c4Smrg	        # that they are being used correctly in the link pass.
83052a75d1c4Smrg	        test -z "$libdir" && \
83062a75d1c4Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
83072a75d1c4Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
83082a75d1c4Smrg	      elif test -n "$dlname"; then
83092a75d1c4Smrg	        func_append newdlprefiles " $dir/$dlname"
83102a75d1c4Smrg	      else
83112a75d1c4Smrg	        func_append newdlprefiles " $dir/$linklib"
83122a75d1c4Smrg	      fi
83132a75d1c4Smrg	    ;;
83142a75d1c4Smrg	  esac
83152a75d1c4Smrg	fi # $pass = dlpreopen
83162a75d1c4Smrg
83172a75d1c4Smrg	if test -z "$libdir"; then
83182a75d1c4Smrg	  # Link the convenience library
831966ab3337Smrg	  if test lib = "$linkmode"; then
83202a75d1c4Smrg	    deplibs="$dir/$old_library $deplibs"
832166ab3337Smrg	  elif test prog,link = "$linkmode,$pass"; then
83222a75d1c4Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
83232a75d1c4Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
83242a75d1c4Smrg	  else
83252a75d1c4Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
83262a75d1c4Smrg	  fi
83272a75d1c4Smrg	  continue
83282a75d1c4Smrg	fi
83292a75d1c4Smrg
83302a75d1c4Smrg
833166ab3337Smrg	if test prog = "$linkmode" && test link != "$pass"; then
83322a75d1c4Smrg	  func_append newlib_search_path " $ladir"
83332a75d1c4Smrg	  deplibs="$lib $deplibs"
83342a75d1c4Smrg
833566ab3337Smrg	  linkalldeplibs=false
833666ab3337Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
833766ab3337Smrg	     test no = "$build_libtool_libs"; then
833866ab3337Smrg	    linkalldeplibs=:
83392a75d1c4Smrg	  fi
83402a75d1c4Smrg
83412a75d1c4Smrg	  tmp_libs=
83422a75d1c4Smrg	  for deplib in $dependency_libs; do
83432a75d1c4Smrg	    case $deplib in
83442a75d1c4Smrg	    -L*) func_stripname '-L' '' "$deplib"
83452a75d1c4Smrg	         func_resolve_sysroot "$func_stripname_result"
83462a75d1c4Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
83472a75d1c4Smrg		 ;;
83482a75d1c4Smrg	    esac
83492a75d1c4Smrg	    # Need to link against all dependency_libs?
835066ab3337Smrg	    if $linkalldeplibs; then
83512a75d1c4Smrg	      deplibs="$deplib $deplibs"
83522a75d1c4Smrg	    else
83532a75d1c4Smrg	      # Need to hardcode shared library paths
83542a75d1c4Smrg	      # or/and link against static libraries
83552a75d1c4Smrg	      newdependency_libs="$deplib $newdependency_libs"
83562a75d1c4Smrg	    fi
835766ab3337Smrg	    if $opt_preserve_dup_deps; then
83582a75d1c4Smrg	      case "$tmp_libs " in
83592a75d1c4Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83602a75d1c4Smrg	      esac
83612a75d1c4Smrg	    fi
83622a75d1c4Smrg	    func_append tmp_libs " $deplib"
83632a75d1c4Smrg	  done # for deplib
83642a75d1c4Smrg	  continue
83652a75d1c4Smrg	fi # $linkmode = prog...
83662a75d1c4Smrg
836766ab3337Smrg	if test prog,link = "$linkmode,$pass"; then
83682a75d1c4Smrg	  if test -n "$library_names" &&
836966ab3337Smrg	     { { test no = "$prefer_static_libs" ||
837066ab3337Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
83712a75d1c4Smrg	       test -z "$old_library"; }; then
83722a75d1c4Smrg	    # We need to hardcode the library path
837366ab3337Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
83742a75d1c4Smrg	      # Make sure the rpath contains only unique directories.
837566ab3337Smrg	      case $temp_rpath: in
83762a75d1c4Smrg	      *"$absdir:"*) ;;
83772a75d1c4Smrg	      *) func_append temp_rpath "$absdir:" ;;
83782a75d1c4Smrg	      esac
83792a75d1c4Smrg	    fi
83802a75d1c4Smrg
83812a75d1c4Smrg	    # Hardcode the library path.
83822a75d1c4Smrg	    # Skip directories that are in the system default run-time
83832a75d1c4Smrg	    # search path.
83842a75d1c4Smrg	    case " $sys_lib_dlsearch_path " in
83852a75d1c4Smrg	    *" $absdir "*) ;;
83862a75d1c4Smrg	    *)
83872a75d1c4Smrg	      case "$compile_rpath " in
83882a75d1c4Smrg	      *" $absdir "*) ;;
83892a75d1c4Smrg	      *) func_append compile_rpath " $absdir" ;;
83902a75d1c4Smrg	      esac
83912a75d1c4Smrg	      ;;
83922a75d1c4Smrg	    esac
83932a75d1c4Smrg	    case " $sys_lib_dlsearch_path " in
83942a75d1c4Smrg	    *" $libdir "*) ;;
83952a75d1c4Smrg	    *)
83962a75d1c4Smrg	      case "$finalize_rpath " in
83972a75d1c4Smrg	      *" $libdir "*) ;;
83982a75d1c4Smrg	      *) func_append finalize_rpath " $libdir" ;;
83992a75d1c4Smrg	      esac
84002a75d1c4Smrg	      ;;
84012a75d1c4Smrg	    esac
84022a75d1c4Smrg	  fi # $linkmode,$pass = prog,link...
84032a75d1c4Smrg
840466ab3337Smrg	  if $alldeplibs &&
840566ab3337Smrg	     { test pass_all = "$deplibs_check_method" ||
840666ab3337Smrg	       { test yes = "$build_libtool_libs" &&
84072a75d1c4Smrg		 test -n "$library_names"; }; }; then
84082a75d1c4Smrg	    # We only need to search for static libraries
84092a75d1c4Smrg	    continue
84102a75d1c4Smrg	  fi
84112a75d1c4Smrg	fi
84122a75d1c4Smrg
84132a75d1c4Smrg	link_static=no # Whether the deplib will be linked statically
84142a75d1c4Smrg	use_static_libs=$prefer_static_libs
841566ab3337Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
84162a75d1c4Smrg	  use_static_libs=no
84172a75d1c4Smrg	fi
84182a75d1c4Smrg	if test -n "$library_names" &&
841966ab3337Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
84202a75d1c4Smrg	  case $host in
842166ab3337Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
84222a75d1c4Smrg	      # No point in relinking DLLs because paths are not encoded
84232a75d1c4Smrg	      func_append notinst_deplibs " $lib"
84242a75d1c4Smrg	      need_relink=no
84252a75d1c4Smrg	    ;;
84262a75d1c4Smrg	  *)
842766ab3337Smrg	    if test no = "$installed"; then
84282a75d1c4Smrg	      func_append notinst_deplibs " $lib"
84292a75d1c4Smrg	      need_relink=yes
84302a75d1c4Smrg	    fi
84312a75d1c4Smrg	    ;;
84322a75d1c4Smrg	  esac
84332a75d1c4Smrg	  # This is a shared library
84342a75d1c4Smrg
84352a75d1c4Smrg	  # Warn about portability, can't link against -module's on some
84362a75d1c4Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
843766ab3337Smrg	  dlopenmodule=
84382a75d1c4Smrg	  for dlpremoduletest in $dlprefiles; do
84392a75d1c4Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
844066ab3337Smrg	      dlopenmodule=$dlpremoduletest
84412a75d1c4Smrg	      break
84422a75d1c4Smrg	    fi
84432a75d1c4Smrg	  done
844466ab3337Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
84452a75d1c4Smrg	    echo
844666ab3337Smrg	    if test prog = "$linkmode"; then
84472a75d1c4Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
84482a75d1c4Smrg	    else
84492a75d1c4Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
84502a75d1c4Smrg	    fi
84512a75d1c4Smrg	    $ECHO "*** $linklib is not portable!"
84522a75d1c4Smrg	  fi
845366ab3337Smrg	  if test lib = "$linkmode" &&
845466ab3337Smrg	     test yes = "$hardcode_into_libs"; then
84552a75d1c4Smrg	    # Hardcode the library path.
84562a75d1c4Smrg	    # Skip directories that are in the system default run-time
84572a75d1c4Smrg	    # search path.
84582a75d1c4Smrg	    case " $sys_lib_dlsearch_path " in
84592a75d1c4Smrg	    *" $absdir "*) ;;
84602a75d1c4Smrg	    *)
84612a75d1c4Smrg	      case "$compile_rpath " in
84622a75d1c4Smrg	      *" $absdir "*) ;;
84632a75d1c4Smrg	      *) func_append compile_rpath " $absdir" ;;
84642a75d1c4Smrg	      esac
84652a75d1c4Smrg	      ;;
84662a75d1c4Smrg	    esac
84672a75d1c4Smrg	    case " $sys_lib_dlsearch_path " in
84682a75d1c4Smrg	    *" $libdir "*) ;;
84692a75d1c4Smrg	    *)
84702a75d1c4Smrg	      case "$finalize_rpath " in
84712a75d1c4Smrg	      *" $libdir "*) ;;
84722a75d1c4Smrg	      *) func_append finalize_rpath " $libdir" ;;
84732a75d1c4Smrg	      esac
84742a75d1c4Smrg	      ;;
84752a75d1c4Smrg	    esac
84762a75d1c4Smrg	  fi
84772a75d1c4Smrg
84782a75d1c4Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
84792a75d1c4Smrg	    # figure out the soname
84802a75d1c4Smrg	    set dummy $library_names
84812a75d1c4Smrg	    shift
848266ab3337Smrg	    realname=$1
84832a75d1c4Smrg	    shift
84842a75d1c4Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
84852a75d1c4Smrg	    # use dlname if we got it. it's perfectly good, no?
84862a75d1c4Smrg	    if test -n "$dlname"; then
848766ab3337Smrg	      soname=$dlname
84882a75d1c4Smrg	    elif test -n "$soname_spec"; then
84892a75d1c4Smrg	      # bleh windows
84902a75d1c4Smrg	      case $host in
849166ab3337Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
84922a75d1c4Smrg	        func_arith $current - $age
84932a75d1c4Smrg		major=$func_arith_result
849466ab3337Smrg		versuffix=-$major
84952a75d1c4Smrg		;;
84962a75d1c4Smrg	      esac
84972a75d1c4Smrg	      eval soname=\"$soname_spec\"
84982a75d1c4Smrg	    else
849966ab3337Smrg	      soname=$realname
85002a75d1c4Smrg	    fi
85012a75d1c4Smrg
85022a75d1c4Smrg	    # Make a new name for the extract_expsyms_cmds to use
850366ab3337Smrg	    soroot=$soname
85042a75d1c4Smrg	    func_basename "$soroot"
850566ab3337Smrg	    soname=$func_basename_result
85062a75d1c4Smrg	    func_stripname 'lib' '.dll' "$soname"
85072a75d1c4Smrg	    newlib=libimp-$func_stripname_result.a
85082a75d1c4Smrg
85092a75d1c4Smrg	    # If the library has no export list, then create one now
85102a75d1c4Smrg	    if test -f "$output_objdir/$soname-def"; then :
85112a75d1c4Smrg	    else
851266ab3337Smrg	      func_verbose "extracting exported symbol list from '$soname'"
85132a75d1c4Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
85142a75d1c4Smrg	    fi
85152a75d1c4Smrg
85162a75d1c4Smrg	    # Create $newlib
85172a75d1c4Smrg	    if test -f "$output_objdir/$newlib"; then :; else
851866ab3337Smrg	      func_verbose "generating import library for '$soname'"
85192a75d1c4Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
85202a75d1c4Smrg	    fi
85212a75d1c4Smrg	    # make sure the library variables are pointing to the new library
85222a75d1c4Smrg	    dir=$output_objdir
85232a75d1c4Smrg	    linklib=$newlib
85242a75d1c4Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
85252a75d1c4Smrg
852666ab3337Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
85272a75d1c4Smrg	    add_shlibpath=
85282a75d1c4Smrg	    add_dir=
85292a75d1c4Smrg	    add=
85302a75d1c4Smrg	    lib_linked=yes
85312a75d1c4Smrg	    case $hardcode_action in
85322a75d1c4Smrg	    immediate | unsupported)
853366ab3337Smrg	      if test no = "$hardcode_direct"; then
853466ab3337Smrg		add=$dir/$linklib
85352a75d1c4Smrg		case $host in
853666ab3337Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
853766ab3337Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
85382a75d1c4Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
853966ab3337Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
85402a75d1c4Smrg		  *-*-darwin* )
854166ab3337Smrg		    # if the lib is a (non-dlopened) module then we cannot
85422a75d1c4Smrg		    # link against it, someone is ignoring the earlier warnings
85432a75d1c4Smrg		    if /usr/bin/file -L $add 2> /dev/null |
854466ab3337Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
85452a75d1c4Smrg		      if test "X$dlopenmodule" != "X$lib"; then
85462a75d1c4Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
854766ab3337Smrg			if test -z "$old_library"; then
85482a75d1c4Smrg			  echo
85492a75d1c4Smrg			  echo "*** And there doesn't seem to be a static archive available"
85502a75d1c4Smrg			  echo "*** The link will probably fail, sorry"
85512a75d1c4Smrg			else
855266ab3337Smrg			  add=$dir/$old_library
85532a75d1c4Smrg			fi
85542a75d1c4Smrg		      elif test -n "$old_library"; then
855566ab3337Smrg			add=$dir/$old_library
85562a75d1c4Smrg		      fi
85572a75d1c4Smrg		    fi
85582a75d1c4Smrg		esac
855966ab3337Smrg	      elif test no = "$hardcode_minus_L"; then
85602a75d1c4Smrg		case $host in
856166ab3337Smrg		*-*-sunos*) add_shlibpath=$dir ;;
85622a75d1c4Smrg		esac
856366ab3337Smrg		add_dir=-L$dir
856466ab3337Smrg		add=-l$name
856566ab3337Smrg	      elif test no = "$hardcode_shlibpath_var"; then
856666ab3337Smrg		add_shlibpath=$dir
856766ab3337Smrg		add=-l$name
85682a75d1c4Smrg	      else
85692a75d1c4Smrg		lib_linked=no
85702a75d1c4Smrg	      fi
85712a75d1c4Smrg	      ;;
85722a75d1c4Smrg	    relink)
857366ab3337Smrg	      if test yes = "$hardcode_direct" &&
857466ab3337Smrg	         test no = "$hardcode_direct_absolute"; then
857566ab3337Smrg		add=$dir/$linklib
857666ab3337Smrg	      elif test yes = "$hardcode_minus_L"; then
857766ab3337Smrg		add_dir=-L$absdir
85782a75d1c4Smrg		# Try looking first in the location we're being installed to.
85792a75d1c4Smrg		if test -n "$inst_prefix_dir"; then
85802a75d1c4Smrg		  case $libdir in
85812a75d1c4Smrg		    [\\/]*)
85822a75d1c4Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
85832a75d1c4Smrg		      ;;
85842a75d1c4Smrg		  esac
85852a75d1c4Smrg		fi
858666ab3337Smrg		add=-l$name
858766ab3337Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
858866ab3337Smrg		add_shlibpath=$dir
858966ab3337Smrg		add=-l$name
85902a75d1c4Smrg	      else
85912a75d1c4Smrg		lib_linked=no
85922a75d1c4Smrg	      fi
85932a75d1c4Smrg	      ;;
85942a75d1c4Smrg	    *) lib_linked=no ;;
85952a75d1c4Smrg	    esac
85962a75d1c4Smrg
859766ab3337Smrg	    if test yes != "$lib_linked"; then
85982a75d1c4Smrg	      func_fatal_configuration "unsupported hardcode properties"
85992a75d1c4Smrg	    fi
86002a75d1c4Smrg
86012a75d1c4Smrg	    if test -n "$add_shlibpath"; then
86022a75d1c4Smrg	      case :$compile_shlibpath: in
86032a75d1c4Smrg	      *":$add_shlibpath:"*) ;;
86042a75d1c4Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
86052a75d1c4Smrg	      esac
86062a75d1c4Smrg	    fi
860766ab3337Smrg	    if test prog = "$linkmode"; then
86082a75d1c4Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
86092a75d1c4Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
86102a75d1c4Smrg	    else
86112a75d1c4Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86122a75d1c4Smrg	      test -n "$add" && deplibs="$add $deplibs"
861366ab3337Smrg	      if test yes != "$hardcode_direct" &&
861466ab3337Smrg		 test yes != "$hardcode_minus_L" &&
861566ab3337Smrg		 test yes = "$hardcode_shlibpath_var"; then
86162a75d1c4Smrg		case :$finalize_shlibpath: in
86172a75d1c4Smrg		*":$libdir:"*) ;;
86182a75d1c4Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
86192a75d1c4Smrg		esac
86202a75d1c4Smrg	      fi
86212a75d1c4Smrg	    fi
86222a75d1c4Smrg	  fi
86232a75d1c4Smrg
862466ab3337Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
86252a75d1c4Smrg	    add_shlibpath=
86262a75d1c4Smrg	    add_dir=
86272a75d1c4Smrg	    add=
86282a75d1c4Smrg	    # Finalize command for both is simple: just hardcode it.
862966ab3337Smrg	    if test yes = "$hardcode_direct" &&
863066ab3337Smrg	       test no = "$hardcode_direct_absolute"; then
863166ab3337Smrg	      add=$libdir/$linklib
863266ab3337Smrg	    elif test yes = "$hardcode_minus_L"; then
863366ab3337Smrg	      add_dir=-L$libdir
863466ab3337Smrg	      add=-l$name
863566ab3337Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
86362a75d1c4Smrg	      case :$finalize_shlibpath: in
86372a75d1c4Smrg	      *":$libdir:"*) ;;
86382a75d1c4Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
86392a75d1c4Smrg	      esac
864066ab3337Smrg	      add=-l$name
864166ab3337Smrg	    elif test yes = "$hardcode_automatic"; then
86422a75d1c4Smrg	      if test -n "$inst_prefix_dir" &&
864366ab3337Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
864466ab3337Smrg		add=$inst_prefix_dir$libdir/$linklib
86452a75d1c4Smrg	      else
864666ab3337Smrg		add=$libdir/$linklib
86472a75d1c4Smrg	      fi
86482a75d1c4Smrg	    else
86492a75d1c4Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
865066ab3337Smrg	      add_dir=-L$libdir
86512a75d1c4Smrg	      # Try looking first in the location we're being installed to.
86522a75d1c4Smrg	      if test -n "$inst_prefix_dir"; then
86532a75d1c4Smrg		case $libdir in
86542a75d1c4Smrg		  [\\/]*)
86552a75d1c4Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
86562a75d1c4Smrg		    ;;
86572a75d1c4Smrg		esac
86582a75d1c4Smrg	      fi
865966ab3337Smrg	      add=-l$name
86602a75d1c4Smrg	    fi
86612a75d1c4Smrg
866266ab3337Smrg	    if test prog = "$linkmode"; then
86632a75d1c4Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
86642a75d1c4Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
86652a75d1c4Smrg	    else
86662a75d1c4Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86672a75d1c4Smrg	      test -n "$add" && deplibs="$add $deplibs"
86682a75d1c4Smrg	    fi
86692a75d1c4Smrg	  fi
867066ab3337Smrg	elif test prog = "$linkmode"; then
86712a75d1c4Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
86722a75d1c4Smrg	  # is not unsupported.  This is valid on all known static and
86732a75d1c4Smrg	  # shared platforms.
867466ab3337Smrg	  if test unsupported != "$hardcode_direct"; then
867566ab3337Smrg	    test -n "$old_library" && linklib=$old_library
86762a75d1c4Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
86772a75d1c4Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
86782a75d1c4Smrg	  else
86792a75d1c4Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
86802a75d1c4Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
86812a75d1c4Smrg	  fi
868266ab3337Smrg	elif test yes = "$build_libtool_libs"; then
86832a75d1c4Smrg	  # Not a shared library
868466ab3337Smrg	  if test pass_all != "$deplibs_check_method"; then
86852a75d1c4Smrg	    # We're trying link a shared library against a static one
86862a75d1c4Smrg	    # but the system doesn't support it.
86872a75d1c4Smrg
86882a75d1c4Smrg	    # Just print a warning and add the library to dependency_libs so
86892a75d1c4Smrg	    # that the program can be linked against the static library.
86902a75d1c4Smrg	    echo
869166ab3337Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
86922a75d1c4Smrg	    echo "*** I have the capability to make that library automatically link in when"
86932a75d1c4Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
86942a75d1c4Smrg	    echo "*** shared version of the library, which you do not appear to have."
869566ab3337Smrg	    if test yes = "$module"; then
86962a75d1c4Smrg	      echo "*** But as you try to build a module library, libtool will still create "
86972a75d1c4Smrg	      echo "*** a static module, that should work as long as the dlopening application"
86982a75d1c4Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
86992a75d1c4Smrg	      if test -z "$global_symbol_pipe"; then
87002a75d1c4Smrg		echo
87012a75d1c4Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
870266ab3337Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
87032a75d1c4Smrg		echo "*** not find such a program.  So, this module is probably useless."
870466ab3337Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
87052a75d1c4Smrg	      fi
870666ab3337Smrg	      if test no = "$build_old_libs"; then
87072a75d1c4Smrg		build_libtool_libs=module
87082a75d1c4Smrg		build_old_libs=yes
87092a75d1c4Smrg	      else
87102a75d1c4Smrg		build_libtool_libs=no
87112a75d1c4Smrg	      fi
87122a75d1c4Smrg	    fi
87132a75d1c4Smrg	  else
87142a75d1c4Smrg	    deplibs="$dir/$old_library $deplibs"
87152a75d1c4Smrg	    link_static=yes
87162a75d1c4Smrg	  fi
87172a75d1c4Smrg	fi # link shared/static library?
87182a75d1c4Smrg
871966ab3337Smrg	if test lib = "$linkmode"; then
87202a75d1c4Smrg	  if test -n "$dependency_libs" &&
872166ab3337Smrg	     { test yes != "$hardcode_into_libs" ||
872266ab3337Smrg	       test yes = "$build_old_libs" ||
872366ab3337Smrg	       test yes = "$link_static"; }; then
87242a75d1c4Smrg	    # Extract -R from dependency_libs
87252a75d1c4Smrg	    temp_deplibs=
87262a75d1c4Smrg	    for libdir in $dependency_libs; do
87272a75d1c4Smrg	      case $libdir in
87282a75d1c4Smrg	      -R*) func_stripname '-R' '' "$libdir"
87292a75d1c4Smrg	           temp_xrpath=$func_stripname_result
87302a75d1c4Smrg		   case " $xrpath " in
87312a75d1c4Smrg		   *" $temp_xrpath "*) ;;
87322a75d1c4Smrg		   *) func_append xrpath " $temp_xrpath";;
87332a75d1c4Smrg		   esac;;
87342a75d1c4Smrg	      *) func_append temp_deplibs " $libdir";;
87352a75d1c4Smrg	      esac
87362a75d1c4Smrg	    done
873766ab3337Smrg	    dependency_libs=$temp_deplibs
87382a75d1c4Smrg	  fi
87392a75d1c4Smrg
87402a75d1c4Smrg	  func_append newlib_search_path " $absdir"
87412a75d1c4Smrg	  # Link against this library
874266ab3337Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
87432a75d1c4Smrg	  # ... and its dependency_libs
87442a75d1c4Smrg	  tmp_libs=
87452a75d1c4Smrg	  for deplib in $dependency_libs; do
87462a75d1c4Smrg	    newdependency_libs="$deplib $newdependency_libs"
87472a75d1c4Smrg	    case $deplib in
87482a75d1c4Smrg              -L*) func_stripname '-L' '' "$deplib"
87492a75d1c4Smrg                   func_resolve_sysroot "$func_stripname_result";;
87502a75d1c4Smrg              *) func_resolve_sysroot "$deplib" ;;
87512a75d1c4Smrg            esac
875266ab3337Smrg	    if $opt_preserve_dup_deps; then
87532a75d1c4Smrg	      case "$tmp_libs " in
87542a75d1c4Smrg	      *" $func_resolve_sysroot_result "*)
87552a75d1c4Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
87562a75d1c4Smrg	      esac
87572a75d1c4Smrg	    fi
87582a75d1c4Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
87592a75d1c4Smrg	  done
87602a75d1c4Smrg
876166ab3337Smrg	  if test no != "$link_all_deplibs"; then
87622a75d1c4Smrg	    # Add the search paths of all dependency libraries
87632a75d1c4Smrg	    for deplib in $dependency_libs; do
87642a75d1c4Smrg	      path=
87652a75d1c4Smrg	      case $deplib in
876666ab3337Smrg	      -L*) path=$deplib ;;
87672a75d1c4Smrg	      *.la)
87682a75d1c4Smrg	        func_resolve_sysroot "$deplib"
87692a75d1c4Smrg	        deplib=$func_resolve_sysroot_result
87702a75d1c4Smrg	        func_dirname "$deplib" "" "."
87712a75d1c4Smrg		dir=$func_dirname_result
87722a75d1c4Smrg		# We need an absolute path.
87732a75d1c4Smrg		case $dir in
877466ab3337Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
87752a75d1c4Smrg		*)
87762a75d1c4Smrg		  absdir=`cd "$dir" && pwd`
87772a75d1c4Smrg		  if test -z "$absdir"; then
877866ab3337Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
877966ab3337Smrg		    absdir=$dir
87802a75d1c4Smrg		  fi
87812a75d1c4Smrg		  ;;
87822a75d1c4Smrg		esac
87832a75d1c4Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
87842a75d1c4Smrg		case $host in
87852a75d1c4Smrg		*-*-darwin*)
87862a75d1c4Smrg		  depdepl=
878766ab3337Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
878866ab3337Smrg		  if test -n "$deplibrary_names"; then
878966ab3337Smrg		    for tmp in $deplibrary_names; do
87902a75d1c4Smrg		      depdepl=$tmp
87912a75d1c4Smrg		    done
879266ab3337Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
879366ab3337Smrg		      depdepl=$absdir/$objdir/$depdepl
879466ab3337Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
87952a75d1c4Smrg                      if test -z "$darwin_install_name"; then
879666ab3337Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
87972a75d1c4Smrg                      fi
879866ab3337Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
879966ab3337Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
88002a75d1c4Smrg		      path=
88012a75d1c4Smrg		    fi
88022a75d1c4Smrg		  fi
88032a75d1c4Smrg		  ;;
88042a75d1c4Smrg		*)
880566ab3337Smrg		  path=-L$absdir/$objdir
88062a75d1c4Smrg		  ;;
88072a75d1c4Smrg		esac
88082a75d1c4Smrg		else
880966ab3337Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
88102a75d1c4Smrg		  test -z "$libdir" && \
881166ab3337Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
88122a75d1c4Smrg		  test "$absdir" != "$libdir" && \
881366ab3337Smrg		    func_warning "'$deplib' seems to be moved"
88142a75d1c4Smrg
881566ab3337Smrg		  path=-L$absdir
88162a75d1c4Smrg		fi
88172a75d1c4Smrg		;;
88182a75d1c4Smrg	      esac
88192a75d1c4Smrg	      case " $deplibs " in
88202a75d1c4Smrg	      *" $path "*) ;;
88212a75d1c4Smrg	      *) deplibs="$path $deplibs" ;;
88222a75d1c4Smrg	      esac
88232a75d1c4Smrg	    done
88242a75d1c4Smrg	  fi # link_all_deplibs != no
88252a75d1c4Smrg	fi # linkmode = lib
88262a75d1c4Smrg      done # for deplib in $libs
882766ab3337Smrg      if test link = "$pass"; then
882866ab3337Smrg	if test prog = "$linkmode"; then
88292a75d1c4Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
88302a75d1c4Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
88312a75d1c4Smrg	else
88322a75d1c4Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
88332a75d1c4Smrg	fi
88342a75d1c4Smrg      fi
883566ab3337Smrg      dependency_libs=$newdependency_libs
883666ab3337Smrg      if test dlpreopen = "$pass"; then
88372a75d1c4Smrg	# Link the dlpreopened libraries before other libraries
88382a75d1c4Smrg	for deplib in $save_deplibs; do
88392a75d1c4Smrg	  deplibs="$deplib $deplibs"
88402a75d1c4Smrg	done
88412a75d1c4Smrg      fi
884266ab3337Smrg      if test dlopen != "$pass"; then
884366ab3337Smrg	test conv = "$pass" || {
88442a75d1c4Smrg	  # Make sure lib_search_path contains only unique directories.
88452a75d1c4Smrg	  lib_search_path=
88462a75d1c4Smrg	  for dir in $newlib_search_path; do
88472a75d1c4Smrg	    case "$lib_search_path " in
88482a75d1c4Smrg	    *" $dir "*) ;;
88492a75d1c4Smrg	    *) func_append lib_search_path " $dir" ;;
88502a75d1c4Smrg	    esac
88512a75d1c4Smrg	  done
88522a75d1c4Smrg	  newlib_search_path=
885366ab3337Smrg	}
88542a75d1c4Smrg
885566ab3337Smrg	if test prog,link = "$linkmode,$pass"; then
88562a75d1c4Smrg	  vars="compile_deplibs finalize_deplibs"
885766ab3337Smrg	else
885866ab3337Smrg	  vars=deplibs
88592a75d1c4Smrg	fi
88602a75d1c4Smrg	for var in $vars dependency_libs; do
88612a75d1c4Smrg	  # Add libraries to $var in reverse order
88622a75d1c4Smrg	  eval tmp_libs=\"\$$var\"
88632a75d1c4Smrg	  new_libs=
88642a75d1c4Smrg	  for deplib in $tmp_libs; do
88652a75d1c4Smrg	    # FIXME: Pedantically, this is the right thing to do, so
88662a75d1c4Smrg	    #        that some nasty dependency loop isn't accidentally
88672a75d1c4Smrg	    #        broken:
88682a75d1c4Smrg	    #new_libs="$deplib $new_libs"
88692a75d1c4Smrg	    # Pragmatically, this seems to cause very few problems in
88702a75d1c4Smrg	    # practice:
88712a75d1c4Smrg	    case $deplib in
88722a75d1c4Smrg	    -L*) new_libs="$deplib $new_libs" ;;
88732a75d1c4Smrg	    -R*) ;;
88742a75d1c4Smrg	    *)
88752a75d1c4Smrg	      # And here is the reason: when a library appears more
88762a75d1c4Smrg	      # than once as an explicit dependence of a library, or
88772a75d1c4Smrg	      # is implicitly linked in more than once by the
88782a75d1c4Smrg	      # compiler, it is considered special, and multiple
88792a75d1c4Smrg	      # occurrences thereof are not removed.  Compare this
88802a75d1c4Smrg	      # with having the same library being listed as a
88812a75d1c4Smrg	      # dependency of multiple other libraries: in this case,
88822a75d1c4Smrg	      # we know (pedantically, we assume) the library does not
88832a75d1c4Smrg	      # need to be listed more than once, so we keep only the
88842a75d1c4Smrg	      # last copy.  This is not always right, but it is rare
88852a75d1c4Smrg	      # enough that we require users that really mean to play
88862a75d1c4Smrg	      # such unportable linking tricks to link the library
88872a75d1c4Smrg	      # using -Wl,-lname, so that libtool does not consider it
88882a75d1c4Smrg	      # for duplicate removal.
88892a75d1c4Smrg	      case " $specialdeplibs " in
88902a75d1c4Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
88912a75d1c4Smrg	      *)
88922a75d1c4Smrg		case " $new_libs " in
88932a75d1c4Smrg		*" $deplib "*) ;;
88942a75d1c4Smrg		*) new_libs="$deplib $new_libs" ;;
88952a75d1c4Smrg		esac
88962a75d1c4Smrg		;;
88972a75d1c4Smrg	      esac
88982a75d1c4Smrg	      ;;
88992a75d1c4Smrg	    esac
89002a75d1c4Smrg	  done
89012a75d1c4Smrg	  tmp_libs=
89022a75d1c4Smrg	  for deplib in $new_libs; do
89032a75d1c4Smrg	    case $deplib in
89042a75d1c4Smrg	    -L*)
89052a75d1c4Smrg	      case " $tmp_libs " in
89062a75d1c4Smrg	      *" $deplib "*) ;;
89072a75d1c4Smrg	      *) func_append tmp_libs " $deplib" ;;
89082a75d1c4Smrg	      esac
89092a75d1c4Smrg	      ;;
89102a75d1c4Smrg	    *) func_append tmp_libs " $deplib" ;;
89112a75d1c4Smrg	    esac
89122a75d1c4Smrg	  done
89132a75d1c4Smrg	  eval $var=\"$tmp_libs\"
89142a75d1c4Smrg	done # for var
89152a75d1c4Smrg      fi
891666ab3337Smrg
891766ab3337Smrg      # Add Sun CC postdeps if required:
891866ab3337Smrg      test CXX = "$tagname" && {
891966ab3337Smrg        case $host_os in
892066ab3337Smrg        linux*)
892166ab3337Smrg          case `$CC -V 2>&1 | $SED 5q` in
892266ab3337Smrg          *Sun\ C*) # Sun C++ 5.9
892366ab3337Smrg            func_suncc_cstd_abi
892466ab3337Smrg
892566ab3337Smrg            if test no != "$suncc_use_cstd_abi"; then
892666ab3337Smrg              func_append postdeps ' -library=Cstd -library=Crun'
892766ab3337Smrg            fi
892866ab3337Smrg            ;;
892966ab3337Smrg          esac
893066ab3337Smrg          ;;
893166ab3337Smrg
893266ab3337Smrg        solaris*)
893366ab3337Smrg          func_cc_basename "$CC"
893466ab3337Smrg          case $func_cc_basename_result in
893566ab3337Smrg          CC* | sunCC*)
893666ab3337Smrg            func_suncc_cstd_abi
893766ab3337Smrg
893866ab3337Smrg            if test no != "$suncc_use_cstd_abi"; then
893966ab3337Smrg              func_append postdeps ' -library=Cstd -library=Crun'
894066ab3337Smrg            fi
894166ab3337Smrg            ;;
894266ab3337Smrg          esac
894366ab3337Smrg          ;;
894466ab3337Smrg        esac
894566ab3337Smrg      }
894666ab3337Smrg
89472a75d1c4Smrg      # Last step: remove runtime libs from dependency_libs
89482a75d1c4Smrg      # (they stay in deplibs)
89492a75d1c4Smrg      tmp_libs=
895066ab3337Smrg      for i in $dependency_libs; do
89512a75d1c4Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
89522a75d1c4Smrg	*" $i "*)
895366ab3337Smrg	  i=
89542a75d1c4Smrg	  ;;
89552a75d1c4Smrg	esac
895666ab3337Smrg	if test -n "$i"; then
89572a75d1c4Smrg	  func_append tmp_libs " $i"
89582a75d1c4Smrg	fi
89592a75d1c4Smrg      done
89602a75d1c4Smrg      dependency_libs=$tmp_libs
89612a75d1c4Smrg    done # for pass
896266ab3337Smrg    if test prog = "$linkmode"; then
896366ab3337Smrg      dlfiles=$newdlfiles
89642a75d1c4Smrg    fi
896566ab3337Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
896666ab3337Smrg      dlprefiles=$newdlprefiles
89672a75d1c4Smrg    fi
89682a75d1c4Smrg
89692a75d1c4Smrg    case $linkmode in
89702a75d1c4Smrg    oldlib)
897166ab3337Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
897266ab3337Smrg	func_warning "'-dlopen' is ignored for archives"
89732a75d1c4Smrg      fi
89742a75d1c4Smrg
89752a75d1c4Smrg      case " $deplibs" in
89762a75d1c4Smrg      *\ -l* | *\ -L*)
897766ab3337Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
89782a75d1c4Smrg      esac
89792a75d1c4Smrg
89802a75d1c4Smrg      test -n "$rpath" && \
898166ab3337Smrg	func_warning "'-rpath' is ignored for archives"
89822a75d1c4Smrg
89832a75d1c4Smrg      test -n "$xrpath" && \
898466ab3337Smrg	func_warning "'-R' is ignored for archives"
89852a75d1c4Smrg
89862a75d1c4Smrg      test -n "$vinfo" && \
898766ab3337Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
89882a75d1c4Smrg
89892a75d1c4Smrg      test -n "$release" && \
899066ab3337Smrg	func_warning "'-release' is ignored for archives"
89912a75d1c4Smrg
89922a75d1c4Smrg      test -n "$export_symbols$export_symbols_regex" && \
899366ab3337Smrg	func_warning "'-export-symbols' is ignored for archives"
89942a75d1c4Smrg
89952a75d1c4Smrg      # Now set the variables for building old libraries.
89962a75d1c4Smrg      build_libtool_libs=no
899766ab3337Smrg      oldlibs=$output
89982a75d1c4Smrg      func_append objs "$old_deplibs"
89992a75d1c4Smrg      ;;
90002a75d1c4Smrg
90012a75d1c4Smrg    lib)
900266ab3337Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
90032a75d1c4Smrg      case $outputname in
90042a75d1c4Smrg      lib*)
90052a75d1c4Smrg	func_stripname 'lib' '.la' "$outputname"
90062a75d1c4Smrg	name=$func_stripname_result
90072a75d1c4Smrg	eval shared_ext=\"$shrext_cmds\"
90082a75d1c4Smrg	eval libname=\"$libname_spec\"
90092a75d1c4Smrg	;;
90102a75d1c4Smrg      *)
901166ab3337Smrg	test no = "$module" \
901266ab3337Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
90132a75d1c4Smrg
901466ab3337Smrg	if test no != "$need_lib_prefix"; then
90152a75d1c4Smrg	  # Add the "lib" prefix for modules if required
90162a75d1c4Smrg	  func_stripname '' '.la' "$outputname"
90172a75d1c4Smrg	  name=$func_stripname_result
90182a75d1c4Smrg	  eval shared_ext=\"$shrext_cmds\"
90192a75d1c4Smrg	  eval libname=\"$libname_spec\"
90202a75d1c4Smrg	else
90212a75d1c4Smrg	  func_stripname '' '.la' "$outputname"
90222a75d1c4Smrg	  libname=$func_stripname_result
90232a75d1c4Smrg	fi
90242a75d1c4Smrg	;;
90252a75d1c4Smrg      esac
90262a75d1c4Smrg
90272a75d1c4Smrg      if test -n "$objs"; then
902866ab3337Smrg	if test pass_all != "$deplibs_check_method"; then
902966ab3337Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
90302a75d1c4Smrg	else
90312a75d1c4Smrg	  echo
90322a75d1c4Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
90332a75d1c4Smrg	  $ECHO "*** objects $objs is not portable!"
90342a75d1c4Smrg	  func_append libobjs " $objs"
90352a75d1c4Smrg	fi
90362a75d1c4Smrg      fi
90372a75d1c4Smrg
903866ab3337Smrg      test no = "$dlself" \
903966ab3337Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
90402a75d1c4Smrg
90412a75d1c4Smrg      set dummy $rpath
90422a75d1c4Smrg      shift
904366ab3337Smrg      test 1 -lt "$#" \
904466ab3337Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
90452a75d1c4Smrg
904666ab3337Smrg      install_libdir=$1
90472a75d1c4Smrg
90482a75d1c4Smrg      oldlibs=
90492a75d1c4Smrg      if test -z "$rpath"; then
905066ab3337Smrg	if test yes = "$build_libtool_libs"; then
90512a75d1c4Smrg	  # Building a libtool convenience library.
905266ab3337Smrg	  # Some compilers have problems with a '.al' extension so
90532a75d1c4Smrg	  # convenience libraries should have the same extension an
90542a75d1c4Smrg	  # archive normally would.
90552a75d1c4Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
90562a75d1c4Smrg	  build_libtool_libs=convenience
90572a75d1c4Smrg	  build_old_libs=yes
90582a75d1c4Smrg	fi
90592a75d1c4Smrg
90602a75d1c4Smrg	test -n "$vinfo" && \
906166ab3337Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
90622a75d1c4Smrg
90632a75d1c4Smrg	test -n "$release" && \
906466ab3337Smrg	  func_warning "'-release' is ignored for convenience libraries"
90652a75d1c4Smrg      else
90662a75d1c4Smrg
90672a75d1c4Smrg	# Parse the version information argument.
906866ab3337Smrg	save_ifs=$IFS; IFS=:
90692a75d1c4Smrg	set dummy $vinfo 0 0 0
90702a75d1c4Smrg	shift
907166ab3337Smrg	IFS=$save_ifs
90722a75d1c4Smrg
90732a75d1c4Smrg	test -n "$7" && \
907466ab3337Smrg	  func_fatal_help "too many parameters to '-version-info'"
90752a75d1c4Smrg
90762a75d1c4Smrg	# convert absolute version numbers to libtool ages
90772a75d1c4Smrg	# this retains compatibility with .la files and attempts
90782a75d1c4Smrg	# to make the code below a bit more comprehensible
90792a75d1c4Smrg
90802a75d1c4Smrg	case $vinfo_number in
90812a75d1c4Smrg	yes)
908266ab3337Smrg	  number_major=$1
908366ab3337Smrg	  number_minor=$2
908466ab3337Smrg	  number_revision=$3
90852a75d1c4Smrg	  #
90862a75d1c4Smrg	  # There are really only two kinds -- those that
90872a75d1c4Smrg	  # use the current revision as the major version
90882a75d1c4Smrg	  # and those that subtract age and use age as
90892a75d1c4Smrg	  # a minor version.  But, then there is irix
909066ab3337Smrg	  # that has an extra 1 added just for fun
90912a75d1c4Smrg	  #
90922a75d1c4Smrg	  case $version_type in
909366ab3337Smrg	  # correct linux to gnu/linux during the next big refactor
909466ab3337Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
90952a75d1c4Smrg	    func_arith $number_major + $number_minor
90962a75d1c4Smrg	    current=$func_arith_result
909766ab3337Smrg	    age=$number_minor
909866ab3337Smrg	    revision=$number_revision
90992a75d1c4Smrg	    ;;
910066ab3337Smrg	  freebsd-aout|qnx|sunos)
910166ab3337Smrg	    current=$number_major
910266ab3337Smrg	    revision=$number_minor
910366ab3337Smrg	    age=0
91042a75d1c4Smrg	    ;;
91052a75d1c4Smrg	  irix|nonstopux)
91062a75d1c4Smrg	    func_arith $number_major + $number_minor
91072a75d1c4Smrg	    current=$func_arith_result
910866ab3337Smrg	    age=$number_minor
910966ab3337Smrg	    revision=$number_minor
91102a75d1c4Smrg	    lt_irix_increment=no
91112a75d1c4Smrg	    ;;
91122a75d1c4Smrg	  esac
91132a75d1c4Smrg	  ;;
91142a75d1c4Smrg	no)
911566ab3337Smrg	  current=$1
911666ab3337Smrg	  revision=$2
911766ab3337Smrg	  age=$3
91182a75d1c4Smrg	  ;;
91192a75d1c4Smrg	esac
91202a75d1c4Smrg
91212a75d1c4Smrg	# Check that each of the things are valid numbers.
91222a75d1c4Smrg	case $current in
91232a75d1c4Smrg	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]) ;;
91242a75d1c4Smrg	*)
912566ab3337Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
912666ab3337Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91272a75d1c4Smrg	  ;;
91282a75d1c4Smrg	esac
91292a75d1c4Smrg
91302a75d1c4Smrg	case $revision in
91312a75d1c4Smrg	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]) ;;
91322a75d1c4Smrg	*)
913366ab3337Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
913466ab3337Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91352a75d1c4Smrg	  ;;
91362a75d1c4Smrg	esac
91372a75d1c4Smrg
91382a75d1c4Smrg	case $age in
91392a75d1c4Smrg	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]) ;;
91402a75d1c4Smrg	*)
914166ab3337Smrg	  func_error "AGE '$age' must be a nonnegative integer"
914266ab3337Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91432a75d1c4Smrg	  ;;
91442a75d1c4Smrg	esac
91452a75d1c4Smrg
91462a75d1c4Smrg	if test "$age" -gt "$current"; then
914766ab3337Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
914866ab3337Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91492a75d1c4Smrg	fi
91502a75d1c4Smrg
91512a75d1c4Smrg	# Calculate the version variables.
91522a75d1c4Smrg	major=
91532a75d1c4Smrg	versuffix=
91542a75d1c4Smrg	verstring=
91552a75d1c4Smrg	case $version_type in
91562a75d1c4Smrg	none) ;;
91572a75d1c4Smrg
91582a75d1c4Smrg	darwin)
91592a75d1c4Smrg	  # Like Linux, but with the current version available in
91602a75d1c4Smrg	  # verstring for coding it into the library header
91612a75d1c4Smrg	  func_arith $current - $age
91622a75d1c4Smrg	  major=.$func_arith_result
916366ab3337Smrg	  versuffix=$major.$age.$revision
91642a75d1c4Smrg	  # Darwin ld doesn't like 0 for these options...
91652a75d1c4Smrg	  func_arith $current + 1
91662a75d1c4Smrg	  minor_current=$func_arith_result
916766ab3337Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91682a75d1c4Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
916966ab3337Smrg          # On Darwin other compilers
917066ab3337Smrg          case $CC in
917166ab3337Smrg              nagfor*)
917266ab3337Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
917366ab3337Smrg                  ;;
917466ab3337Smrg              *)
917566ab3337Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
917666ab3337Smrg                  ;;
917766ab3337Smrg          esac
91782a75d1c4Smrg	  ;;
91792a75d1c4Smrg
91802a75d1c4Smrg	freebsd-aout)
918166ab3337Smrg	  major=.$current
918266ab3337Smrg	  versuffix=.$current.$revision
91832a75d1c4Smrg	  ;;
91842a75d1c4Smrg
918566ab3337Smrg	freebsd-elf | midnightbsd-elf)
918666ab3337Smrg	  func_arith $current - $age
918766ab3337Smrg	  major=.$func_arith_result
918866ab3337Smrg	  versuffix=$major.$age.$revision
91892a75d1c4Smrg	  ;;
91902a75d1c4Smrg
91912a75d1c4Smrg	irix | nonstopux)
919266ab3337Smrg	  if test no = "$lt_irix_increment"; then
91932a75d1c4Smrg	    func_arith $current - $age
91942a75d1c4Smrg	  else
91952a75d1c4Smrg	    func_arith $current - $age + 1
91962a75d1c4Smrg	  fi
91972a75d1c4Smrg	  major=$func_arith_result
91982a75d1c4Smrg
91992a75d1c4Smrg	  case $version_type in
92002a75d1c4Smrg	    nonstopux) verstring_prefix=nonstopux ;;
92012a75d1c4Smrg	    *)         verstring_prefix=sgi ;;
92022a75d1c4Smrg	  esac
920366ab3337Smrg	  verstring=$verstring_prefix$major.$revision
92042a75d1c4Smrg
92052a75d1c4Smrg	  # Add in all the interfaces that we are compatible with.
92062a75d1c4Smrg	  loop=$revision
920766ab3337Smrg	  while test 0 -ne "$loop"; do
92082a75d1c4Smrg	    func_arith $revision - $loop
92092a75d1c4Smrg	    iface=$func_arith_result
92102a75d1c4Smrg	    func_arith $loop - 1
92112a75d1c4Smrg	    loop=$func_arith_result
921266ab3337Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
92132a75d1c4Smrg	  done
92142a75d1c4Smrg
921566ab3337Smrg	  # Before this point, $major must not contain '.'.
92162a75d1c4Smrg	  major=.$major
921766ab3337Smrg	  versuffix=$major.$revision
92182a75d1c4Smrg	  ;;
92192a75d1c4Smrg
922066ab3337Smrg	linux) # correct to gnu/linux during the next big refactor
92212a75d1c4Smrg	  func_arith $current - $age
92222a75d1c4Smrg	  major=.$func_arith_result
922366ab3337Smrg	  versuffix=$major.$age.$revision
92242a75d1c4Smrg	  ;;
92252a75d1c4Smrg
92262a75d1c4Smrg	osf)
92272a75d1c4Smrg	  func_arith $current - $age
92282a75d1c4Smrg	  major=.$func_arith_result
922966ab3337Smrg	  versuffix=.$current.$age.$revision
923066ab3337Smrg	  verstring=$current.$age.$revision
92312a75d1c4Smrg
92322a75d1c4Smrg	  # Add in all the interfaces that we are compatible with.
92332a75d1c4Smrg	  loop=$age
923466ab3337Smrg	  while test 0 -ne "$loop"; do
92352a75d1c4Smrg	    func_arith $current - $loop
92362a75d1c4Smrg	    iface=$func_arith_result
92372a75d1c4Smrg	    func_arith $loop - 1
92382a75d1c4Smrg	    loop=$func_arith_result
923966ab3337Smrg	    verstring=$verstring:$iface.0
92402a75d1c4Smrg	  done
92412a75d1c4Smrg
92422a75d1c4Smrg	  # Make executables depend on our current version.
924366ab3337Smrg	  func_append verstring ":$current.0"
92442a75d1c4Smrg	  ;;
92452a75d1c4Smrg
92462a75d1c4Smrg	qnx)
924766ab3337Smrg	  major=.$current
924866ab3337Smrg	  versuffix=.$current
924966ab3337Smrg	  ;;
925066ab3337Smrg
925166ab3337Smrg	sco)
925266ab3337Smrg	  major=.$current
925366ab3337Smrg	  versuffix=.$current
92542a75d1c4Smrg	  ;;
92552a75d1c4Smrg
92562a75d1c4Smrg	sunos)
925766ab3337Smrg	  major=.$current
925866ab3337Smrg	  versuffix=.$current.$revision
92592a75d1c4Smrg	  ;;
92602a75d1c4Smrg
92612a75d1c4Smrg	windows)
92622a75d1c4Smrg	  # Use '-' rather than '.', since we only want one
926366ab3337Smrg	  # extension on DOS 8.3 file systems.
92642a75d1c4Smrg	  func_arith $current - $age
92652a75d1c4Smrg	  major=$func_arith_result
926666ab3337Smrg	  versuffix=-$major
92672a75d1c4Smrg	  ;;
92682a75d1c4Smrg
92692a75d1c4Smrg	*)
927066ab3337Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
92712a75d1c4Smrg	  ;;
92722a75d1c4Smrg	esac
92732a75d1c4Smrg
92742a75d1c4Smrg	# Clear the version info if we defaulted, and they specified a release.
92752a75d1c4Smrg	if test -z "$vinfo" && test -n "$release"; then
92762a75d1c4Smrg	  major=
92772a75d1c4Smrg	  case $version_type in
92782a75d1c4Smrg	  darwin)
92792a75d1c4Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
92802a75d1c4Smrg	    # problems, so we reset it completely
92812a75d1c4Smrg	    verstring=
92822a75d1c4Smrg	    ;;
92832a75d1c4Smrg	  *)
928466ab3337Smrg	    verstring=0.0
92852a75d1c4Smrg	    ;;
92862a75d1c4Smrg	  esac
928766ab3337Smrg	  if test no = "$need_version"; then
92882a75d1c4Smrg	    versuffix=
92892a75d1c4Smrg	  else
929066ab3337Smrg	    versuffix=.0.0
92912a75d1c4Smrg	  fi
92922a75d1c4Smrg	fi
92932a75d1c4Smrg
92942a75d1c4Smrg	# Remove version info from name if versioning should be avoided
929566ab3337Smrg	if test yes,no = "$avoid_version,$need_version"; then
92962a75d1c4Smrg	  major=
92972a75d1c4Smrg	  versuffix=
929866ab3337Smrg	  verstring=
92992a75d1c4Smrg	fi
93002a75d1c4Smrg
93012a75d1c4Smrg	# Check to see if the archive will have undefined symbols.
930266ab3337Smrg	if test yes = "$allow_undefined"; then
930366ab3337Smrg	  if test unsupported = "$allow_undefined_flag"; then
930466ab3337Smrg	    if test yes = "$build_old_libs"; then
930566ab3337Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
930666ab3337Smrg	      build_libtool_libs=no
930766ab3337Smrg	    else
930866ab3337Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
930966ab3337Smrg	    fi
93102a75d1c4Smrg	  fi
93112a75d1c4Smrg	else
93122a75d1c4Smrg	  # Don't allow undefined symbols.
931366ab3337Smrg	  allow_undefined_flag=$no_undefined_flag
93142a75d1c4Smrg	fi
93152a75d1c4Smrg
93162a75d1c4Smrg      fi
93172a75d1c4Smrg
931866ab3337Smrg      func_generate_dlsyms "$libname" "$libname" :
93192a75d1c4Smrg      func_append libobjs " $symfileobj"
932066ab3337Smrg      test " " = "$libobjs" && libobjs=
93212a75d1c4Smrg
932266ab3337Smrg      if test relink != "$opt_mode"; then
93232a75d1c4Smrg	# Remove our outputs, but don't remove object files since they
93242a75d1c4Smrg	# may have been created when compiling PIC objects.
93252a75d1c4Smrg	removelist=
93262a75d1c4Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
93272a75d1c4Smrg	for p in $tempremovelist; do
93282a75d1c4Smrg	  case $p in
93292a75d1c4Smrg	    *.$objext | *.gcno)
93302a75d1c4Smrg	       ;;
933166ab3337Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
933266ab3337Smrg	       if test -n "$precious_files_regex"; then
93332a75d1c4Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
93342a75d1c4Smrg		 then
93352a75d1c4Smrg		   continue
93362a75d1c4Smrg		 fi
93372a75d1c4Smrg	       fi
93382a75d1c4Smrg	       func_append removelist " $p"
93392a75d1c4Smrg	       ;;
93402a75d1c4Smrg	    *) ;;
93412a75d1c4Smrg	  esac
93422a75d1c4Smrg	done
93432a75d1c4Smrg	test -n "$removelist" && \
93442a75d1c4Smrg	  func_show_eval "${RM}r \$removelist"
93452a75d1c4Smrg      fi
93462a75d1c4Smrg
93472a75d1c4Smrg      # Now set the variables for building old libraries.
934866ab3337Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
93492a75d1c4Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
93502a75d1c4Smrg
93512a75d1c4Smrg	# Transform .lo files to .o files.
935266ab3337Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
93532a75d1c4Smrg      fi
93542a75d1c4Smrg
93552a75d1c4Smrg      # Eliminate all temporary directories.
93562a75d1c4Smrg      #for path in $notinst_path; do
93572a75d1c4Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
93582a75d1c4Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
93592a75d1c4Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
93602a75d1c4Smrg      #done
93612a75d1c4Smrg
93622a75d1c4Smrg      if test -n "$xrpath"; then
93632a75d1c4Smrg	# If the user specified any rpath flags, then add them.
93642a75d1c4Smrg	temp_xrpath=
93652a75d1c4Smrg	for libdir in $xrpath; do
93662a75d1c4Smrg	  func_replace_sysroot "$libdir"
93672a75d1c4Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
93682a75d1c4Smrg	  case "$finalize_rpath " in
93692a75d1c4Smrg	  *" $libdir "*) ;;
93702a75d1c4Smrg	  *) func_append finalize_rpath " $libdir" ;;
93712a75d1c4Smrg	  esac
93722a75d1c4Smrg	done
937366ab3337Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
93742a75d1c4Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
93752a75d1c4Smrg	fi
93762a75d1c4Smrg      fi
93772a75d1c4Smrg
93782a75d1c4Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
937966ab3337Smrg      old_dlfiles=$dlfiles
93802a75d1c4Smrg      dlfiles=
93812a75d1c4Smrg      for lib in $old_dlfiles; do
93822a75d1c4Smrg	case " $dlprefiles $dlfiles " in
93832a75d1c4Smrg	*" $lib "*) ;;
93842a75d1c4Smrg	*) func_append dlfiles " $lib" ;;
93852a75d1c4Smrg	esac
93862a75d1c4Smrg      done
93872a75d1c4Smrg
93882a75d1c4Smrg      # Make sure dlprefiles contains only unique files
938966ab3337Smrg      old_dlprefiles=$dlprefiles
93902a75d1c4Smrg      dlprefiles=
93912a75d1c4Smrg      for lib in $old_dlprefiles; do
93922a75d1c4Smrg	case "$dlprefiles " in
93932a75d1c4Smrg	*" $lib "*) ;;
93942a75d1c4Smrg	*) func_append dlprefiles " $lib" ;;
93952a75d1c4Smrg	esac
93962a75d1c4Smrg      done
93972a75d1c4Smrg
939866ab3337Smrg      if test yes = "$build_libtool_libs"; then
93992a75d1c4Smrg	if test -n "$rpath"; then
94002a75d1c4Smrg	  case $host in
94012a75d1c4Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
94022a75d1c4Smrg	    # these systems don't actually have a c library (as such)!
94032a75d1c4Smrg	    ;;
94042a75d1c4Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
94052a75d1c4Smrg	    # Rhapsody C library is in the System framework
94062a75d1c4Smrg	    func_append deplibs " System.ltframework"
94072a75d1c4Smrg	    ;;
94082a75d1c4Smrg	  *-*-netbsd*)
94092a75d1c4Smrg	    # Don't link with libc until the a.out ld.so is fixed.
94102a75d1c4Smrg	    ;;
941166ab3337Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
94122a75d1c4Smrg	    # Do not include libc due to us having libc/libc_r.
94132a75d1c4Smrg	    ;;
94142a75d1c4Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
94152a75d1c4Smrg	    # Causes problems with __ctype
94162a75d1c4Smrg	    ;;
94172a75d1c4Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
94182a75d1c4Smrg	    # Compiler inserts libc in the correct place for threads to work
94192a75d1c4Smrg	    ;;
94202a75d1c4Smrg	  *)
94212a75d1c4Smrg	    # Add libc to deplibs on all other systems if necessary.
942266ab3337Smrg	    if test yes = "$build_libtool_need_lc"; then
94232a75d1c4Smrg	      func_append deplibs " -lc"
94242a75d1c4Smrg	    fi
94252a75d1c4Smrg	    ;;
94262a75d1c4Smrg	  esac
94272a75d1c4Smrg	fi
94282a75d1c4Smrg
94292a75d1c4Smrg	# Transform deplibs into only deplibs that can be linked in shared.
94302a75d1c4Smrg	name_save=$name
94312a75d1c4Smrg	libname_save=$libname
94322a75d1c4Smrg	release_save=$release
94332a75d1c4Smrg	versuffix_save=$versuffix
94342a75d1c4Smrg	major_save=$major
94352a75d1c4Smrg	# I'm not sure if I'm treating the release correctly.  I think
94362a75d1c4Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
94372a75d1c4Smrg	# add it in twice.  Is that correct?
943866ab3337Smrg	release=
943966ab3337Smrg	versuffix=
944066ab3337Smrg	major=
94412a75d1c4Smrg	newdeplibs=
94422a75d1c4Smrg	droppeddeps=no
94432a75d1c4Smrg	case $deplibs_check_method in
94442a75d1c4Smrg	pass_all)
94452a75d1c4Smrg	  # Don't check for shared/static.  Everything works.
94462a75d1c4Smrg	  # This might be a little naive.  We might want to check
94472a75d1c4Smrg	  # whether the library exists or not.  But this is on
94482a75d1c4Smrg	  # osf3 & osf4 and I'm not really sure... Just
94492a75d1c4Smrg	  # implementing what was already the behavior.
94502a75d1c4Smrg	  newdeplibs=$deplibs
94512a75d1c4Smrg	  ;;
94522a75d1c4Smrg	test_compile)
94532a75d1c4Smrg	  # This code stresses the "libraries are programs" paradigm to its
94542a75d1c4Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
94552a75d1c4Smrg	  # against the deplibs as a proxy for the library.  Then we can check
94562a75d1c4Smrg	  # whether they linked in statically or dynamically with ldd.
94572a75d1c4Smrg	  $opt_dry_run || $RM conftest.c
94582a75d1c4Smrg	  cat > conftest.c <<EOF
94592a75d1c4Smrg	  int main() { return 0; }
94602a75d1c4SmrgEOF
94612a75d1c4Smrg	  $opt_dry_run || $RM conftest
94622a75d1c4Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
94632a75d1c4Smrg	    ldd_output=`ldd conftest`
94642a75d1c4Smrg	    for i in $deplibs; do
94652a75d1c4Smrg	      case $i in
94662a75d1c4Smrg	      -l*)
94672a75d1c4Smrg		func_stripname -l '' "$i"
94682a75d1c4Smrg		name=$func_stripname_result
946966ab3337Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94702a75d1c4Smrg		  case " $predeps $postdeps " in
94712a75d1c4Smrg		  *" $i "*)
94722a75d1c4Smrg		    func_append newdeplibs " $i"
947366ab3337Smrg		    i=
94742a75d1c4Smrg		    ;;
94752a75d1c4Smrg		  esac
94762a75d1c4Smrg		fi
947766ab3337Smrg		if test -n "$i"; then
94782a75d1c4Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
94792a75d1c4Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
94802a75d1c4Smrg		  set dummy $deplib_matches; shift
94812a75d1c4Smrg		  deplib_match=$1
948266ab3337Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
94832a75d1c4Smrg		    func_append newdeplibs " $i"
94842a75d1c4Smrg		  else
94852a75d1c4Smrg		    droppeddeps=yes
94862a75d1c4Smrg		    echo
94872a75d1c4Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
94882a75d1c4Smrg		    echo "*** I have the capability to make that library automatically link in when"
94892a75d1c4Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
94902a75d1c4Smrg		    echo "*** shared version of the library, which I believe you do not have"
94912a75d1c4Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
94922a75d1c4Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
94932a75d1c4Smrg		  fi
94942a75d1c4Smrg		fi
94952a75d1c4Smrg		;;
94962a75d1c4Smrg	      *)
94972a75d1c4Smrg		func_append newdeplibs " $i"
94982a75d1c4Smrg		;;
94992a75d1c4Smrg	      esac
95002a75d1c4Smrg	    done
95012a75d1c4Smrg	  else
95022a75d1c4Smrg	    # Error occurred in the first compile.  Let's try to salvage
95032a75d1c4Smrg	    # the situation: Compile a separate program for each library.
95042a75d1c4Smrg	    for i in $deplibs; do
95052a75d1c4Smrg	      case $i in
95062a75d1c4Smrg	      -l*)
95072a75d1c4Smrg		func_stripname -l '' "$i"
95082a75d1c4Smrg		name=$func_stripname_result
95092a75d1c4Smrg		$opt_dry_run || $RM conftest
95102a75d1c4Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
95112a75d1c4Smrg		  ldd_output=`ldd conftest`
951266ab3337Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95132a75d1c4Smrg		    case " $predeps $postdeps " in
95142a75d1c4Smrg		    *" $i "*)
95152a75d1c4Smrg		      func_append newdeplibs " $i"
951666ab3337Smrg		      i=
95172a75d1c4Smrg		      ;;
95182a75d1c4Smrg		    esac
95192a75d1c4Smrg		  fi
952066ab3337Smrg		  if test -n "$i"; then
95212a75d1c4Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
95222a75d1c4Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
95232a75d1c4Smrg		    set dummy $deplib_matches; shift
95242a75d1c4Smrg		    deplib_match=$1
952566ab3337Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
95262a75d1c4Smrg		      func_append newdeplibs " $i"
95272a75d1c4Smrg		    else
95282a75d1c4Smrg		      droppeddeps=yes
95292a75d1c4Smrg		      echo
95302a75d1c4Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
95312a75d1c4Smrg		      echo "*** I have the capability to make that library automatically link in when"
95322a75d1c4Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
95332a75d1c4Smrg		      echo "*** shared version of the library, which you do not appear to have"
95342a75d1c4Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
95352a75d1c4Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
95362a75d1c4Smrg		    fi
95372a75d1c4Smrg		  fi
95382a75d1c4Smrg		else
95392a75d1c4Smrg		  droppeddeps=yes
95402a75d1c4Smrg		  echo
95412a75d1c4Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
95422a75d1c4Smrg		  echo "*** make it link in!  You will probably need to install it or some"
95432a75d1c4Smrg		  echo "*** library that it depends on before this library will be fully"
95442a75d1c4Smrg		  echo "*** functional.  Installing it before continuing would be even better."
95452a75d1c4Smrg		fi
95462a75d1c4Smrg		;;
95472a75d1c4Smrg	      *)
95482a75d1c4Smrg		func_append newdeplibs " $i"
95492a75d1c4Smrg		;;
95502a75d1c4Smrg	      esac
95512a75d1c4Smrg	    done
95522a75d1c4Smrg	  fi
95532a75d1c4Smrg	  ;;
95542a75d1c4Smrg	file_magic*)
95552a75d1c4Smrg	  set dummy $deplibs_check_method; shift
95562a75d1c4Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
95572a75d1c4Smrg	  for a_deplib in $deplibs; do
95582a75d1c4Smrg	    case $a_deplib in
95592a75d1c4Smrg	    -l*)
95602a75d1c4Smrg	      func_stripname -l '' "$a_deplib"
95612a75d1c4Smrg	      name=$func_stripname_result
956266ab3337Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95632a75d1c4Smrg		case " $predeps $postdeps " in
95642a75d1c4Smrg		*" $a_deplib "*)
95652a75d1c4Smrg		  func_append newdeplibs " $a_deplib"
956666ab3337Smrg		  a_deplib=
95672a75d1c4Smrg		  ;;
95682a75d1c4Smrg		esac
95692a75d1c4Smrg	      fi
957066ab3337Smrg	      if test -n "$a_deplib"; then
95712a75d1c4Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
95722a75d1c4Smrg		if test -n "$file_magic_glob"; then
95732a75d1c4Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
95742a75d1c4Smrg		else
95752a75d1c4Smrg		  libnameglob=$libname
95762a75d1c4Smrg		fi
957766ab3337Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
95782a75d1c4Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
957966ab3337Smrg		  if test yes = "$want_nocaseglob"; then
95802a75d1c4Smrg		    shopt -s nocaseglob
95812a75d1c4Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95822a75d1c4Smrg		    $nocaseglob
95832a75d1c4Smrg		  else
95842a75d1c4Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
95852a75d1c4Smrg		  fi
95862a75d1c4Smrg		  for potent_lib in $potential_libs; do
95872a75d1c4Smrg		      # Follow soft links.
95882a75d1c4Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
95892a75d1c4Smrg			 $GREP " -> " >/dev/null; then
95902a75d1c4Smrg			continue
95912a75d1c4Smrg		      fi
95922a75d1c4Smrg		      # The statement above tries to avoid entering an
95932a75d1c4Smrg		      # endless loop below, in case of cyclic links.
95942a75d1c4Smrg		      # We might still enter an endless loop, since a link
95952a75d1c4Smrg		      # loop can be closed while we follow links,
95962a75d1c4Smrg		      # but so what?
959766ab3337Smrg		      potlib=$potent_lib
95982a75d1c4Smrg		      while test -h "$potlib" 2>/dev/null; do
959966ab3337Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
96002a75d1c4Smrg			case $potliblink in
960166ab3337Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
960266ab3337Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
96032a75d1c4Smrg			esac
96042a75d1c4Smrg		      done
96052a75d1c4Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
96062a75d1c4Smrg			 $SED -e 10q |
96072a75d1c4Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
96082a75d1c4Smrg			func_append newdeplibs " $a_deplib"
960966ab3337Smrg			a_deplib=
96102a75d1c4Smrg			break 2
96112a75d1c4Smrg		      fi
96122a75d1c4Smrg		  done
96132a75d1c4Smrg		done
96142a75d1c4Smrg	      fi
961566ab3337Smrg	      if test -n "$a_deplib"; then
96162a75d1c4Smrg		droppeddeps=yes
96172a75d1c4Smrg		echo
96182a75d1c4Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96192a75d1c4Smrg		echo "*** I have the capability to make that library automatically link in when"
96202a75d1c4Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96212a75d1c4Smrg		echo "*** shared version of the library, which you do not appear to have"
96222a75d1c4Smrg		echo "*** because I did check the linker path looking for a file starting"
962366ab3337Smrg		if test -z "$potlib"; then
96242a75d1c4Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
96252a75d1c4Smrg		else
96262a75d1c4Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96272a75d1c4Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
96282a75d1c4Smrg		fi
96292a75d1c4Smrg	      fi
96302a75d1c4Smrg	      ;;
96312a75d1c4Smrg	    *)
96322a75d1c4Smrg	      # Add a -L argument.
96332a75d1c4Smrg	      func_append newdeplibs " $a_deplib"
96342a75d1c4Smrg	      ;;
96352a75d1c4Smrg	    esac
96362a75d1c4Smrg	  done # Gone through all deplibs.
96372a75d1c4Smrg	  ;;
96382a75d1c4Smrg	match_pattern*)
96392a75d1c4Smrg	  set dummy $deplibs_check_method; shift
96402a75d1c4Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
96412a75d1c4Smrg	  for a_deplib in $deplibs; do
96422a75d1c4Smrg	    case $a_deplib in
96432a75d1c4Smrg	    -l*)
96442a75d1c4Smrg	      func_stripname -l '' "$a_deplib"
96452a75d1c4Smrg	      name=$func_stripname_result
964666ab3337Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96472a75d1c4Smrg		case " $predeps $postdeps " in
96482a75d1c4Smrg		*" $a_deplib "*)
96492a75d1c4Smrg		  func_append newdeplibs " $a_deplib"
965066ab3337Smrg		  a_deplib=
96512a75d1c4Smrg		  ;;
96522a75d1c4Smrg		esac
96532a75d1c4Smrg	      fi
965466ab3337Smrg	      if test -n "$a_deplib"; then
96552a75d1c4Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96562a75d1c4Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
96572a75d1c4Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
96582a75d1c4Smrg		  for potent_lib in $potential_libs; do
965966ab3337Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
96602a75d1c4Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
96612a75d1c4Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
96622a75d1c4Smrg		      func_append newdeplibs " $a_deplib"
966366ab3337Smrg		      a_deplib=
96642a75d1c4Smrg		      break 2
96652a75d1c4Smrg		    fi
96662a75d1c4Smrg		  done
96672a75d1c4Smrg		done
96682a75d1c4Smrg	      fi
966966ab3337Smrg	      if test -n "$a_deplib"; then
96702a75d1c4Smrg		droppeddeps=yes
96712a75d1c4Smrg		echo
96722a75d1c4Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96732a75d1c4Smrg		echo "*** I have the capability to make that library automatically link in when"
96742a75d1c4Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96752a75d1c4Smrg		echo "*** shared version of the library, which you do not appear to have"
96762a75d1c4Smrg		echo "*** because I did check the linker path looking for a file starting"
967766ab3337Smrg		if test -z "$potlib"; then
96782a75d1c4Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
96792a75d1c4Smrg		else
96802a75d1c4Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96812a75d1c4Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
96822a75d1c4Smrg		fi
96832a75d1c4Smrg	      fi
96842a75d1c4Smrg	      ;;
96852a75d1c4Smrg	    *)
96862a75d1c4Smrg	      # Add a -L argument.
96872a75d1c4Smrg	      func_append newdeplibs " $a_deplib"
96882a75d1c4Smrg	      ;;
96892a75d1c4Smrg	    esac
96902a75d1c4Smrg	  done # Gone through all deplibs.
96912a75d1c4Smrg	  ;;
96922a75d1c4Smrg	none | unknown | *)
969366ab3337Smrg	  newdeplibs=
96942a75d1c4Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
969566ab3337Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
969666ab3337Smrg	    for i in $predeps $postdeps; do
96972a75d1c4Smrg	      # can't use Xsed below, because $i might contain '/'
969866ab3337Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
96992a75d1c4Smrg	    done
97002a75d1c4Smrg	  fi
97012a75d1c4Smrg	  case $tmp_deplibs in
97022a75d1c4Smrg	  *[!\	\ ]*)
97032a75d1c4Smrg	    echo
970466ab3337Smrg	    if test none = "$deplibs_check_method"; then
97052a75d1c4Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
97062a75d1c4Smrg	    else
97072a75d1c4Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
97082a75d1c4Smrg	    fi
97092a75d1c4Smrg	    echo "*** All declared inter-library dependencies are being dropped."
97102a75d1c4Smrg	    droppeddeps=yes
97112a75d1c4Smrg	    ;;
97122a75d1c4Smrg	  esac
97132a75d1c4Smrg	  ;;
97142a75d1c4Smrg	esac
97152a75d1c4Smrg	versuffix=$versuffix_save
97162a75d1c4Smrg	major=$major_save
97172a75d1c4Smrg	release=$release_save
97182a75d1c4Smrg	libname=$libname_save
97192a75d1c4Smrg	name=$name_save
97202a75d1c4Smrg
97212a75d1c4Smrg	case $host in
97222a75d1c4Smrg	*-*-rhapsody* | *-*-darwin1.[012])
97232a75d1c4Smrg	  # On Rhapsody replace the C library with the System framework
97242a75d1c4Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
97252a75d1c4Smrg	  ;;
97262a75d1c4Smrg	esac
97272a75d1c4Smrg
972866ab3337Smrg	if test yes = "$droppeddeps"; then
972966ab3337Smrg	  if test yes = "$module"; then
97302a75d1c4Smrg	    echo
97312a75d1c4Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
97322a75d1c4Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
97332a75d1c4Smrg	    echo "*** a static module, that should work as long as the dlopening"
97342a75d1c4Smrg	    echo "*** application is linked with the -dlopen flag."
97352a75d1c4Smrg	    if test -z "$global_symbol_pipe"; then
97362a75d1c4Smrg	      echo
97372a75d1c4Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
973866ab3337Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
97392a75d1c4Smrg	      echo "*** not find such a program.  So, this module is probably useless."
974066ab3337Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
97412a75d1c4Smrg	    fi
974266ab3337Smrg	    if test no = "$build_old_libs"; then
974366ab3337Smrg	      oldlibs=$output_objdir/$libname.$libext
97442a75d1c4Smrg	      build_libtool_libs=module
97452a75d1c4Smrg	      build_old_libs=yes
97462a75d1c4Smrg	    else
97472a75d1c4Smrg	      build_libtool_libs=no
97482a75d1c4Smrg	    fi
97492a75d1c4Smrg	  else
97502a75d1c4Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
97512a75d1c4Smrg	    echo "*** automatically added whenever a program is linked with this library"
97522a75d1c4Smrg	    echo "*** or is declared to -dlopen it."
9753f7ec340bSmacallan
975466ab3337Smrg	    if test no = "$allow_undefined"; then
97552a75d1c4Smrg	      echo
97562a75d1c4Smrg	      echo "*** Since this library must not contain undefined symbols,"
97572a75d1c4Smrg	      echo "*** because either the platform does not support them or"
97582a75d1c4Smrg	      echo "*** it was explicitly requested with -no-undefined,"
97592a75d1c4Smrg	      echo "*** libtool will only create a static version of it."
976066ab3337Smrg	      if test no = "$build_old_libs"; then
976166ab3337Smrg		oldlibs=$output_objdir/$libname.$libext
97622a75d1c4Smrg		build_libtool_libs=module
97632a75d1c4Smrg		build_old_libs=yes
97642a75d1c4Smrg	      else
97652a75d1c4Smrg		build_libtool_libs=no
97662a75d1c4Smrg	      fi
97672a75d1c4Smrg	    fi
97682a75d1c4Smrg	  fi
97692a75d1c4Smrg	fi
97702a75d1c4Smrg	# Done checking deplibs!
97712a75d1c4Smrg	deplibs=$newdeplibs
97722a75d1c4Smrg      fi
97732a75d1c4Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
97742a75d1c4Smrg      case $host in
97752a75d1c4Smrg	*-*-darwin*)
97762a75d1c4Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97772a75d1c4Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97782a75d1c4Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97792a75d1c4Smrg	  ;;
97802a75d1c4Smrg      esac
9781f7ec340bSmacallan
97822a75d1c4Smrg      # move library search paths that coincide with paths to not yet
97832a75d1c4Smrg      # installed libraries to the beginning of the library search list
97842a75d1c4Smrg      new_libs=
97852a75d1c4Smrg      for path in $notinst_path; do
97862a75d1c4Smrg	case " $new_libs " in
97872a75d1c4Smrg	*" -L$path/$objdir "*) ;;
97882a75d1c4Smrg	*)
97892a75d1c4Smrg	  case " $deplibs " in
97902a75d1c4Smrg	  *" -L$path/$objdir "*)
97912a75d1c4Smrg	    func_append new_libs " -L$path/$objdir" ;;
97922a75d1c4Smrg	  esac
97932a75d1c4Smrg	  ;;
97942a75d1c4Smrg	esac
97952a75d1c4Smrg      done
97962a75d1c4Smrg      for deplib in $deplibs; do
97972a75d1c4Smrg	case $deplib in
97982a75d1c4Smrg	-L*)
97992a75d1c4Smrg	  case " $new_libs " in
98002a75d1c4Smrg	  *" $deplib "*) ;;
98012a75d1c4Smrg	  *) func_append new_libs " $deplib" ;;
98022a75d1c4Smrg	  esac
98032a75d1c4Smrg	  ;;
98042a75d1c4Smrg	*) func_append new_libs " $deplib" ;;
98052a75d1c4Smrg	esac
98062a75d1c4Smrg      done
980766ab3337Smrg      deplibs=$new_libs
9808f7ec340bSmacallan
98092a75d1c4Smrg      # All the library-specific variables (install_libdir is set above).
98102a75d1c4Smrg      library_names=
98112a75d1c4Smrg      old_library=
98122a75d1c4Smrg      dlname=
9813f7ec340bSmacallan
98142a75d1c4Smrg      # Test again, we may have decided not to build it any more
981566ab3337Smrg      if test yes = "$build_libtool_libs"; then
981666ab3337Smrg	# Remove $wl instances when linking with ld.
981766ab3337Smrg	# FIXME: should test the right _cmds variable.
981866ab3337Smrg	case $archive_cmds in
981966ab3337Smrg	  *\$LD\ *) wl= ;;
982066ab3337Smrg        esac
982166ab3337Smrg	if test yes = "$hardcode_into_libs"; then
98222a75d1c4Smrg	  # Hardcode the library paths
98232a75d1c4Smrg	  hardcode_libdirs=
98242a75d1c4Smrg	  dep_rpath=
982566ab3337Smrg	  rpath=$finalize_rpath
982666ab3337Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
98272a75d1c4Smrg	  for libdir in $rpath; do
98282a75d1c4Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
98292a75d1c4Smrg	      if test -n "$hardcode_libdir_separator"; then
98302a75d1c4Smrg		func_replace_sysroot "$libdir"
98312a75d1c4Smrg		libdir=$func_replace_sysroot_result
98322a75d1c4Smrg		if test -z "$hardcode_libdirs"; then
983366ab3337Smrg		  hardcode_libdirs=$libdir
98342a75d1c4Smrg		else
98352a75d1c4Smrg		  # Just accumulate the unique libdirs.
98362a75d1c4Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
98372a75d1c4Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
98382a75d1c4Smrg		    ;;
98392a75d1c4Smrg		  *)
98402a75d1c4Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
98412a75d1c4Smrg		    ;;
98422a75d1c4Smrg		  esac
98432a75d1c4Smrg		fi
98442a75d1c4Smrg	      else
98452a75d1c4Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
98462a75d1c4Smrg		func_append dep_rpath " $flag"
98472a75d1c4Smrg	      fi
98482a75d1c4Smrg	    elif test -n "$runpath_var"; then
98492a75d1c4Smrg	      case "$perm_rpath " in
98502a75d1c4Smrg	      *" $libdir "*) ;;
985166ab3337Smrg	      *) func_append perm_rpath " $libdir" ;;
98522a75d1c4Smrg	      esac
98532a75d1c4Smrg	    fi
98542a75d1c4Smrg	  done
98552a75d1c4Smrg	  # Substitute the hardcoded libdirs into the rpath.
98562a75d1c4Smrg	  if test -n "$hardcode_libdir_separator" &&
98572a75d1c4Smrg	     test -n "$hardcode_libdirs"; then
985866ab3337Smrg	    libdir=$hardcode_libdirs
985966ab3337Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
98602a75d1c4Smrg	  fi
98612a75d1c4Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
98622a75d1c4Smrg	    # We should set the runpath_var.
98632a75d1c4Smrg	    rpath=
98642a75d1c4Smrg	    for dir in $perm_rpath; do
98652a75d1c4Smrg	      func_append rpath "$dir:"
98662a75d1c4Smrg	    done
98672a75d1c4Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
98682a75d1c4Smrg	  fi
98692a75d1c4Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
98702a75d1c4Smrg	fi
9871f7ec340bSmacallan
987266ab3337Smrg	shlibpath=$finalize_shlibpath
987366ab3337Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
98742a75d1c4Smrg	if test -n "$shlibpath"; then
98752a75d1c4Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
98762a75d1c4Smrg	fi
9877f7ec340bSmacallan
98782a75d1c4Smrg	# Get the real and link names of the library.
98792a75d1c4Smrg	eval shared_ext=\"$shrext_cmds\"
98802a75d1c4Smrg	eval library_names=\"$library_names_spec\"
98812a75d1c4Smrg	set dummy $library_names
98822a75d1c4Smrg	shift
988366ab3337Smrg	realname=$1
98842a75d1c4Smrg	shift
9885f7ec340bSmacallan
98862a75d1c4Smrg	if test -n "$soname_spec"; then
98872a75d1c4Smrg	  eval soname=\"$soname_spec\"
9888f7ec340bSmacallan	else
988966ab3337Smrg	  soname=$realname
98902a75d1c4Smrg	fi
98912a75d1c4Smrg	if test -z "$dlname"; then
98922a75d1c4Smrg	  dlname=$soname
9893f7ec340bSmacallan	fi
9894f7ec340bSmacallan
989566ab3337Smrg	lib=$output_objdir/$realname
98962a75d1c4Smrg	linknames=
98972a75d1c4Smrg	for link
98982a75d1c4Smrg	do
98992a75d1c4Smrg	  func_append linknames " $link"
99002a75d1c4Smrg	done
9901f7ec340bSmacallan
99022a75d1c4Smrg	# Use standard objects if they are pic
99032a75d1c4Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
99042a75d1c4Smrg	test "X$libobjs" = "X " && libobjs=
9905f7ec340bSmacallan
99062a75d1c4Smrg	delfiles=
99072a75d1c4Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99082a75d1c4Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
990966ab3337Smrg	  export_symbols=$output_objdir/$libname.uexp
99102a75d1c4Smrg	  func_append delfiles " $export_symbols"
99112a75d1c4Smrg	fi
9912f7ec340bSmacallan
99132a75d1c4Smrg	orig_export_symbols=
99142a75d1c4Smrg	case $host_os in
99152a75d1c4Smrg	cygwin* | mingw* | cegcc*)
99162a75d1c4Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
99172a75d1c4Smrg	    # exporting using user supplied symfile
991866ab3337Smrg	    func_dll_def_p "$export_symbols" || {
99192a75d1c4Smrg	      # and it's NOT already a .def file. Must figure out
99202a75d1c4Smrg	      # which of the given symbols are data symbols and tag
99212a75d1c4Smrg	      # them as such. So, trigger use of export_symbols_cmds.
99222a75d1c4Smrg	      # export_symbols gets reassigned inside the "prepare
99232a75d1c4Smrg	      # the list of exported symbols" if statement, so the
99242a75d1c4Smrg	      # include_expsyms logic still works.
992566ab3337Smrg	      orig_export_symbols=$export_symbols
99262a75d1c4Smrg	      export_symbols=
99272a75d1c4Smrg	      always_export_symbols=yes
992866ab3337Smrg	    }
99292a75d1c4Smrg	  fi
99302a75d1c4Smrg	  ;;
99312a75d1c4Smrg	esac
9932f7ec340bSmacallan
99332a75d1c4Smrg	# Prepare the list of exported symbols
99342a75d1c4Smrg	if test -z "$export_symbols"; then
993566ab3337Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
993666ab3337Smrg	    func_verbose "generating symbol list for '$libname.la'"
993766ab3337Smrg	    export_symbols=$output_objdir/$libname.exp
99382a75d1c4Smrg	    $opt_dry_run || $RM $export_symbols
99392a75d1c4Smrg	    cmds=$export_symbols_cmds
994066ab3337Smrg	    save_ifs=$IFS; IFS='~'
99412a75d1c4Smrg	    for cmd1 in $cmds; do
994266ab3337Smrg	      IFS=$save_ifs
99432a75d1c4Smrg	      # Take the normal branch if the nm_file_list_spec branch
99442a75d1c4Smrg	      # doesn't work or if tool conversion is not needed.
99452a75d1c4Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
99462a75d1c4Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
99472a75d1c4Smrg		  try_normal_branch=yes
99482a75d1c4Smrg		  eval cmd=\"$cmd1\"
99492a75d1c4Smrg		  func_len " $cmd"
99502a75d1c4Smrg		  len=$func_len_result
99512a75d1c4Smrg		  ;;
99522a75d1c4Smrg		*)
99532a75d1c4Smrg		  try_normal_branch=no
99542a75d1c4Smrg		  ;;
99552a75d1c4Smrg	      esac
995666ab3337Smrg	      if test yes = "$try_normal_branch" \
99572a75d1c4Smrg		 && { test "$len" -lt "$max_cmd_len" \
99582a75d1c4Smrg		      || test "$max_cmd_len" -le -1; }
99592a75d1c4Smrg	      then
99602a75d1c4Smrg		func_show_eval "$cmd" 'exit $?'
99612a75d1c4Smrg		skipped_export=false
99622a75d1c4Smrg	      elif test -n "$nm_file_list_spec"; then
99632a75d1c4Smrg		func_basename "$output"
99642a75d1c4Smrg		output_la=$func_basename_result
99652a75d1c4Smrg		save_libobjs=$libobjs
99662a75d1c4Smrg		save_output=$output
996766ab3337Smrg		output=$output_objdir/$output_la.nm
99682a75d1c4Smrg		func_to_tool_file "$output"
99692a75d1c4Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
99702a75d1c4Smrg		func_append delfiles " $output"
99712a75d1c4Smrg		func_verbose "creating $NM input file list: $output"
99722a75d1c4Smrg		for obj in $save_libobjs; do
99732a75d1c4Smrg		  func_to_tool_file "$obj"
99742a75d1c4Smrg		  $ECHO "$func_to_tool_file_result"
99752a75d1c4Smrg		done > "$output"
99762a75d1c4Smrg		eval cmd=\"$cmd1\"
99772a75d1c4Smrg		func_show_eval "$cmd" 'exit $?'
99782a75d1c4Smrg		output=$save_output
99792a75d1c4Smrg		libobjs=$save_libobjs
99802a75d1c4Smrg		skipped_export=false
99812a75d1c4Smrg	      else
99822a75d1c4Smrg		# The command line is too long to execute in one step.
99832a75d1c4Smrg		func_verbose "using reloadable object file for export list..."
99842a75d1c4Smrg		skipped_export=:
99852a75d1c4Smrg		# Break out early, otherwise skipped_export may be
99862a75d1c4Smrg		# set to false by a later but shorter cmd.
99872a75d1c4Smrg		break
99882a75d1c4Smrg	      fi
99892a75d1c4Smrg	    done
999066ab3337Smrg	    IFS=$save_ifs
999166ab3337Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
99922a75d1c4Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99932a75d1c4Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99942a75d1c4Smrg	    fi
99952a75d1c4Smrg	  fi
9996f7ec340bSmacallan	fi
9997f7ec340bSmacallan
99982a75d1c4Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
999966ab3337Smrg	  tmp_export_symbols=$export_symbols
1000066ab3337Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
100012a75d1c4Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002f7ec340bSmacallan	fi
10003f7ec340bSmacallan
1000466ab3337Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
100052a75d1c4Smrg	  # The given exports_symbols file has to be filtered, so filter it.
1000666ab3337Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100072a75d1c4Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
1000866ab3337Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
100092a75d1c4Smrg	  # though. Also, the filter scales superlinearly with the number of
100102a75d1c4Smrg	  # global variables. join(1) would be nice here, but unfortunately
100112a75d1c4Smrg	  # isn't a blessed tool.
100122a75d1c4Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
100132a75d1c4Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100142a75d1c4Smrg	  export_symbols=$output_objdir/$libname.def
100152a75d1c4Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100162a75d1c4Smrg	fi
10017f7ec340bSmacallan
100182a75d1c4Smrg	tmp_deplibs=
100192a75d1c4Smrg	for test_deplib in $deplibs; do
100202a75d1c4Smrg	  case " $convenience " in
100212a75d1c4Smrg	  *" $test_deplib "*) ;;
100222a75d1c4Smrg	  *)
100232a75d1c4Smrg	    func_append tmp_deplibs " $test_deplib"
100242a75d1c4Smrg	    ;;
100252a75d1c4Smrg	  esac
100262a75d1c4Smrg	done
1002766ab3337Smrg	deplibs=$tmp_deplibs
10028f7ec340bSmacallan
100292a75d1c4Smrg	if test -n "$convenience"; then
100302a75d1c4Smrg	  if test -n "$whole_archive_flag_spec" &&
1003166ab3337Smrg	    test yes = "$compiler_needs_object" &&
100322a75d1c4Smrg	    test -z "$libobjs"; then
100332a75d1c4Smrg	    # extract the archives, so we have objects to list.
100342a75d1c4Smrg	    # TODO: could optimize this to just extract one archive.
100352a75d1c4Smrg	    whole_archive_flag_spec=
100362a75d1c4Smrg	  fi
100372a75d1c4Smrg	  if test -n "$whole_archive_flag_spec"; then
100382a75d1c4Smrg	    save_libobjs=$libobjs
100392a75d1c4Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100402a75d1c4Smrg	    test "X$libobjs" = "X " && libobjs=
100412a75d1c4Smrg	  else
1004266ab3337Smrg	    gentop=$output_objdir/${outputname}x
100432a75d1c4Smrg	    func_append generated " $gentop"
10044f7ec340bSmacallan
100452a75d1c4Smrg	    func_extract_archives $gentop $convenience
100462a75d1c4Smrg	    func_append libobjs " $func_extract_archives_result"
100472a75d1c4Smrg	    test "X$libobjs" = "X " && libobjs=
100482a75d1c4Smrg	  fi
10049f7ec340bSmacallan	fi
10050f7ec340bSmacallan
1005166ab3337Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
100522a75d1c4Smrg	  eval flag=\"$thread_safe_flag_spec\"
100532a75d1c4Smrg	  func_append linker_flags " $flag"
100542a75d1c4Smrg	fi
10055f7ec340bSmacallan
100562a75d1c4Smrg	# Make a backup of the uninstalled library when relinking
1005766ab3337Smrg	if test relink = "$opt_mode"; then
100582a75d1c4Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
100592a75d1c4Smrg	fi
100602a75d1c4Smrg
100612a75d1c4Smrg	# Do each of the archive commands.
1006266ab3337Smrg	if test yes = "$module" && test -n "$module_cmds"; then
100632a75d1c4Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
100642a75d1c4Smrg	    eval test_cmds=\"$module_expsym_cmds\"
100652a75d1c4Smrg	    cmds=$module_expsym_cmds
100662a75d1c4Smrg	  else
100672a75d1c4Smrg	    eval test_cmds=\"$module_cmds\"
100682a75d1c4Smrg	    cmds=$module_cmds
100692a75d1c4Smrg	  fi
100702a75d1c4Smrg	else
100712a75d1c4Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100722a75d1c4Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
100732a75d1c4Smrg	    cmds=$archive_expsym_cmds
100742a75d1c4Smrg	  else
100752a75d1c4Smrg	    eval test_cmds=\"$archive_cmds\"
100762a75d1c4Smrg	    cmds=$archive_cmds
100772a75d1c4Smrg	  fi
100782a75d1c4Smrg	fi
10079f7ec340bSmacallan
1008066ab3337Smrg	if test : != "$skipped_export" &&
100812a75d1c4Smrg	   func_len " $test_cmds" &&
100822a75d1c4Smrg	   len=$func_len_result &&
100832a75d1c4Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084f7ec340bSmacallan	  :
10085f7ec340bSmacallan	else
100862a75d1c4Smrg	  # The command line is too long to link in one step, link piecewise
100872a75d1c4Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
100882a75d1c4Smrg	  # script.
10089f7ec340bSmacallan
100902a75d1c4Smrg	  # Save the value of $output and $libobjs because we want to
100912a75d1c4Smrg	  # use them later.  If we have whole_archive_flag_spec, we
100922a75d1c4Smrg	  # want to use save_libobjs as it was before
100932a75d1c4Smrg	  # whole_archive_flag_spec was expanded, because we can't
100942a75d1c4Smrg	  # assume the linker understands whole_archive_flag_spec.
100952a75d1c4Smrg	  # This may have to be revisited, in case too many
100962a75d1c4Smrg	  # convenience libraries get linked in and end up exceeding
100972a75d1c4Smrg	  # the spec.
100982a75d1c4Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
100992a75d1c4Smrg	    save_libobjs=$libobjs
10100f7ec340bSmacallan	  fi
101012a75d1c4Smrg	  save_output=$output
101022a75d1c4Smrg	  func_basename "$output"
101032a75d1c4Smrg	  output_la=$func_basename_result
10104f7ec340bSmacallan
101052a75d1c4Smrg	  # Clear the reloadable object creation command queue and
101062a75d1c4Smrg	  # initialize k to one.
101072a75d1c4Smrg	  test_cmds=
10108f7ec340bSmacallan	  concat_cmds=
101092a75d1c4Smrg	  objlist=
101102a75d1c4Smrg	  last_robj=
101112a75d1c4Smrg	  k=1
10112f7ec340bSmacallan
1011366ab3337Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
1011466ab3337Smrg	    output=$output_objdir/$output_la.lnkscript
101152a75d1c4Smrg	    func_verbose "creating GNU ld script: $output"
101162a75d1c4Smrg	    echo 'INPUT (' > $output
101172a75d1c4Smrg	    for obj in $save_libobjs
101182a75d1c4Smrg	    do
101192a75d1c4Smrg	      func_to_tool_file "$obj"
101202a75d1c4Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101212a75d1c4Smrg	    done
101222a75d1c4Smrg	    echo ')' >> $output
101232a75d1c4Smrg	    func_append delfiles " $output"
101242a75d1c4Smrg	    func_to_tool_file "$output"
101252a75d1c4Smrg	    output=$func_to_tool_file_result
1012666ab3337Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
1012766ab3337Smrg	    output=$output_objdir/$output_la.lnk
101282a75d1c4Smrg	    func_verbose "creating linker input file list: $output"
101292a75d1c4Smrg	    : > $output
101302a75d1c4Smrg	    set x $save_libobjs
101312a75d1c4Smrg	    shift
101322a75d1c4Smrg	    firstobj=
1013366ab3337Smrg	    if test yes = "$compiler_needs_object"; then
101342a75d1c4Smrg	      firstobj="$1 "
101352a75d1c4Smrg	      shift
101362a75d1c4Smrg	    fi
101372a75d1c4Smrg	    for obj
101382a75d1c4Smrg	    do
101392a75d1c4Smrg	      func_to_tool_file "$obj"
101402a75d1c4Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101412a75d1c4Smrg	    done
101422a75d1c4Smrg	    func_append delfiles " $output"
101432a75d1c4Smrg	    func_to_tool_file "$output"
101442a75d1c4Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
101452a75d1c4Smrg	  else
101462a75d1c4Smrg	    if test -n "$save_libobjs"; then
101472a75d1c4Smrg	      func_verbose "creating reloadable object files..."
1014866ab3337Smrg	      output=$output_objdir/$output_la-$k.$objext
101492a75d1c4Smrg	      eval test_cmds=\"$reload_cmds\"
101502a75d1c4Smrg	      func_len " $test_cmds"
101512a75d1c4Smrg	      len0=$func_len_result
101522a75d1c4Smrg	      len=$len0
101532a75d1c4Smrg
101542a75d1c4Smrg	      # Loop over the list of objects to be linked.
101552a75d1c4Smrg	      for obj in $save_libobjs
101562a75d1c4Smrg	      do
101572a75d1c4Smrg		func_len " $obj"
101582a75d1c4Smrg		func_arith $len + $func_len_result
101592a75d1c4Smrg		len=$func_arith_result
1016066ab3337Smrg		if test -z "$objlist" ||
101612a75d1c4Smrg		   test "$len" -lt "$max_cmd_len"; then
101622a75d1c4Smrg		  func_append objlist " $obj"
101632a75d1c4Smrg		else
101642a75d1c4Smrg		  # The command $test_cmds is almost too long, add a
101652a75d1c4Smrg		  # command to the queue.
1016666ab3337Smrg		  if test 1 -eq "$k"; then
101672a75d1c4Smrg		    # The first file doesn't have a previous command to add.
101682a75d1c4Smrg		    reload_objs=$objlist
101692a75d1c4Smrg		    eval concat_cmds=\"$reload_cmds\"
101702a75d1c4Smrg		  else
101712a75d1c4Smrg		    # All subsequent reloadable object files will link in
101722a75d1c4Smrg		    # the last one created.
101732a75d1c4Smrg		    reload_objs="$objlist $last_robj"
101742a75d1c4Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
101752a75d1c4Smrg		  fi
1017666ab3337Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
101772a75d1c4Smrg		  func_arith $k + 1
101782a75d1c4Smrg		  k=$func_arith_result
1017966ab3337Smrg		  output=$output_objdir/$output_la-$k.$objext
101802a75d1c4Smrg		  objlist=" $obj"
101812a75d1c4Smrg		  func_len " $last_robj"
101822a75d1c4Smrg		  func_arith $len0 + $func_len_result
101832a75d1c4Smrg		  len=$func_arith_result
101842a75d1c4Smrg		fi
101852a75d1c4Smrg	      done
101862a75d1c4Smrg	      # Handle the remaining objects by creating one last
101872a75d1c4Smrg	      # reloadable object file.  All subsequent reloadable object
101882a75d1c4Smrg	      # files will link in the last one created.
101892a75d1c4Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
101902a75d1c4Smrg	      reload_objs="$objlist $last_robj"
1019166ab3337Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
101922a75d1c4Smrg	      if test -n "$last_robj"; then
1019366ab3337Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194f7ec340bSmacallan	      fi
101952a75d1c4Smrg	      func_append delfiles " $output"
101962a75d1c4Smrg
101972a75d1c4Smrg	    else
101982a75d1c4Smrg	      output=
101992a75d1c4Smrg	    fi
102002a75d1c4Smrg
1020166ab3337Smrg	    ${skipped_export-false} && {
1020266ab3337Smrg	      func_verbose "generating symbol list for '$libname.la'"
1020366ab3337Smrg	      export_symbols=$output_objdir/$libname.exp
102042a75d1c4Smrg	      $opt_dry_run || $RM $export_symbols
102052a75d1c4Smrg	      libobjs=$output
102062a75d1c4Smrg	      # Append the command to create the export file.
10207f7ec340bSmacallan	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102082a75d1c4Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
102092a75d1c4Smrg	      if test -n "$last_robj"; then
102102a75d1c4Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
102112a75d1c4Smrg	      fi
1021266ab3337Smrg	    }
102132a75d1c4Smrg
102142a75d1c4Smrg	    test -n "$save_libobjs" &&
102152a75d1c4Smrg	      func_verbose "creating a temporary reloadable object file: $output"
102162a75d1c4Smrg
102172a75d1c4Smrg	    # Loop through the commands generated above and execute them.
1021866ab3337Smrg	    save_ifs=$IFS; IFS='~'
102192a75d1c4Smrg	    for cmd in $concat_cmds; do
1022066ab3337Smrg	      IFS=$save_ifs
1022166ab3337Smrg	      $opt_quiet || {
1022266ab3337Smrg		  func_quote_arg expand,pretty "$cmd"
1022366ab3337Smrg		  eval "func_echo $func_quote_arg_result"
102242a75d1c4Smrg	      }
102252a75d1c4Smrg	      $opt_dry_run || eval "$cmd" || {
102262a75d1c4Smrg		lt_exit=$?
102272a75d1c4Smrg
102282a75d1c4Smrg		# Restore the uninstalled library and exit
1022966ab3337Smrg		if test relink = "$opt_mode"; then
102302a75d1c4Smrg		  ( cd "$output_objdir" && \
102312a75d1c4Smrg		    $RM "${realname}T" && \
102322a75d1c4Smrg		    $MV "${realname}U" "$realname" )
102332a75d1c4Smrg		fi
102342a75d1c4Smrg
102352a75d1c4Smrg		exit $lt_exit
102362a75d1c4Smrg	      }
102372a75d1c4Smrg	    done
1023866ab3337Smrg	    IFS=$save_ifs
102392a75d1c4Smrg
102402a75d1c4Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
102412a75d1c4Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
102422a75d1c4Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243f7ec340bSmacallan	    fi
10244f7ec340bSmacallan	  fi
10245f7ec340bSmacallan
1024666ab3337Smrg          ${skipped_export-false} && {
102472a75d1c4Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
1024866ab3337Smrg	      tmp_export_symbols=$export_symbols
1024966ab3337Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
102502a75d1c4Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
102512a75d1c4Smrg	    fi
10252f7ec340bSmacallan
102532a75d1c4Smrg	    if test -n "$orig_export_symbols"; then
102542a75d1c4Smrg	      # The given exports_symbols file has to be filtered, so filter it.
1025566ab3337Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
102562a75d1c4Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
1025766ab3337Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
102582a75d1c4Smrg	      # though. Also, the filter scales superlinearly with the number of
102592a75d1c4Smrg	      # global variables. join(1) would be nice here, but unfortunately
102602a75d1c4Smrg	      # isn't a blessed tool.
102612a75d1c4Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
102622a75d1c4Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
102632a75d1c4Smrg	      export_symbols=$output_objdir/$libname.def
102642a75d1c4Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
102652a75d1c4Smrg	    fi
1026666ab3337Smrg	  }
10267f7ec340bSmacallan
102682a75d1c4Smrg	  libobjs=$output
102692a75d1c4Smrg	  # Restore the value of output.
102702a75d1c4Smrg	  output=$save_output
10271f7ec340bSmacallan
102722a75d1c4Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
102732a75d1c4Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
102742a75d1c4Smrg	    test "X$libobjs" = "X " && libobjs=
102752a75d1c4Smrg	  fi
102762a75d1c4Smrg	  # Expand the library linking commands again to reset the
102772a75d1c4Smrg	  # value of $libobjs for piecewise linking.
10278f7ec340bSmacallan
102792a75d1c4Smrg	  # Do each of the archive commands.
1028066ab3337Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
102812a75d1c4Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
102822a75d1c4Smrg	      cmds=$module_expsym_cmds
102832a75d1c4Smrg	    else
102842a75d1c4Smrg	      cmds=$module_cmds
10285f7ec340bSmacallan	    fi
10286f7ec340bSmacallan	  else
102872a75d1c4Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
102882a75d1c4Smrg	      cmds=$archive_expsym_cmds
102892a75d1c4Smrg	    else
102902a75d1c4Smrg	      cmds=$archive_cmds
102912a75d1c4Smrg	    fi
10292f7ec340bSmacallan	  fi
102932a75d1c4Smrg	fi
10294f7ec340bSmacallan
102952a75d1c4Smrg	if test -n "$delfiles"; then
102962a75d1c4Smrg	  # Append the command to remove temporary files to $cmds.
102972a75d1c4Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
102982a75d1c4Smrg	fi
10299f7ec340bSmacallan
103002a75d1c4Smrg	# Add any objects from preloaded convenience libraries
103012a75d1c4Smrg	if test -n "$dlprefiles"; then
1030266ab3337Smrg	  gentop=$output_objdir/${outputname}x
103032a75d1c4Smrg	  func_append generated " $gentop"
10304f7ec340bSmacallan
103052a75d1c4Smrg	  func_extract_archives $gentop $dlprefiles
103062a75d1c4Smrg	  func_append libobjs " $func_extract_archives_result"
103072a75d1c4Smrg	  test "X$libobjs" = "X " && libobjs=
103082a75d1c4Smrg	fi
10309f7ec340bSmacallan
1031066ab3337Smrg	save_ifs=$IFS; IFS='~'
103112a75d1c4Smrg	for cmd in $cmds; do
1031266ab3337Smrg	  IFS=$sp$nl
103132a75d1c4Smrg	  eval cmd=\"$cmd\"
1031466ab3337Smrg	  IFS=$save_ifs
1031566ab3337Smrg	  $opt_quiet || {
1031666ab3337Smrg	    func_quote_arg expand,pretty "$cmd"
1031766ab3337Smrg	    eval "func_echo $func_quote_arg_result"
103182a75d1c4Smrg	  }
103192a75d1c4Smrg	  $opt_dry_run || eval "$cmd" || {
103202a75d1c4Smrg	    lt_exit=$?
10321f7ec340bSmacallan
103222a75d1c4Smrg	    # Restore the uninstalled library and exit
1032366ab3337Smrg	    if test relink = "$opt_mode"; then
103242a75d1c4Smrg	      ( cd "$output_objdir" && \
103252a75d1c4Smrg	        $RM "${realname}T" && \
103262a75d1c4Smrg		$MV "${realname}U" "$realname" )
103272a75d1c4Smrg	    fi
10328f7ec340bSmacallan
103292a75d1c4Smrg	    exit $lt_exit
103302a75d1c4Smrg	  }
103312a75d1c4Smrg	done
1033266ab3337Smrg	IFS=$save_ifs
10333f7ec340bSmacallan
103342a75d1c4Smrg	# Restore the uninstalled library and exit
1033566ab3337Smrg	if test relink = "$opt_mode"; then
103362a75d1c4Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337f7ec340bSmacallan
103382a75d1c4Smrg	  if test -n "$convenience"; then
103392a75d1c4Smrg	    if test -z "$whole_archive_flag_spec"; then
103402a75d1c4Smrg	      func_show_eval '${RM}r "$gentop"'
103412a75d1c4Smrg	    fi
103422a75d1c4Smrg	  fi
10343f7ec340bSmacallan
103442a75d1c4Smrg	  exit $EXIT_SUCCESS
103452a75d1c4Smrg	fi
103462a75d1c4Smrg
103472a75d1c4Smrg	# Create links to the real library.
103482a75d1c4Smrg	for linkname in $linknames; do
103492a75d1c4Smrg	  if test "$realname" != "$linkname"; then
103502a75d1c4Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351f7ec340bSmacallan	  fi
10352f7ec340bSmacallan	done
10353f7ec340bSmacallan
103542a75d1c4Smrg	# If -module or -export-dynamic was specified, set the dlname.
1035566ab3337Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
103562a75d1c4Smrg	  # On all known operating systems, these are identical.
1035766ab3337Smrg	  dlname=$soname
103582a75d1c4Smrg	fi
103592a75d1c4Smrg      fi
10360f7ec340bSmacallan      ;;
10361f7ec340bSmacallan
103622a75d1c4Smrg    obj)
1036366ab3337Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
1036466ab3337Smrg	func_warning "'-dlopen' is ignored for objects"
103652a75d1c4Smrg      fi
10366f7ec340bSmacallan
103672a75d1c4Smrg      case " $deplibs" in
103682a75d1c4Smrg      *\ -l* | *\ -L*)
1036966ab3337Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370f7ec340bSmacallan      esac
10371f7ec340bSmacallan
103722a75d1c4Smrg      test -n "$rpath" && \
1037366ab3337Smrg	func_warning "'-rpath' is ignored for objects"
10374f7ec340bSmacallan
103752a75d1c4Smrg      test -n "$xrpath" && \
1037666ab3337Smrg	func_warning "'-R' is ignored for objects"
10377f7ec340bSmacallan
103782a75d1c4Smrg      test -n "$vinfo" && \
1037966ab3337Smrg	func_warning "'-version-info' is ignored for objects"
103802a75d1c4Smrg
103812a75d1c4Smrg      test -n "$release" && \
1038266ab3337Smrg	func_warning "'-release' is ignored for objects"
103832a75d1c4Smrg
103842a75d1c4Smrg      case $output in
103852a75d1c4Smrg      *.lo)
103862a75d1c4Smrg	test -n "$objs$old_deplibs" && \
1038766ab3337Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
103882a75d1c4Smrg
103892a75d1c4Smrg	libobj=$output
103902a75d1c4Smrg	func_lo2o "$libobj"
103912a75d1c4Smrg	obj=$func_lo2o_result
10392f7ec340bSmacallan	;;
10393f7ec340bSmacallan      *)
103942a75d1c4Smrg	libobj=
1039566ab3337Smrg	obj=$output
10396f7ec340bSmacallan	;;
10397f7ec340bSmacallan      esac
10398f7ec340bSmacallan
103992a75d1c4Smrg      # Delete the old objects.
104002a75d1c4Smrg      $opt_dry_run || $RM $obj $libobj
10401f7ec340bSmacallan
104022a75d1c4Smrg      # Objects from convenience libraries.  This assumes
104032a75d1c4Smrg      # single-version convenience libraries.  Whenever we create
104042a75d1c4Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
104052a75d1c4Smrg      # the extraction.
104062a75d1c4Smrg      reload_conv_objs=
104072a75d1c4Smrg      gentop=
1040866ab3337Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
1040966ab3337Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
1041066ab3337Smrg      # into space.
1041166ab3337Smrg      case $reload_cmds in
1041266ab3337Smrg        *\$LD[\ \$]*) wl= ;;
1041366ab3337Smrg      esac
104142a75d1c4Smrg      if test -n "$convenience"; then
104152a75d1c4Smrg	if test -n "$whole_archive_flag_spec"; then
104162a75d1c4Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
1041766ab3337Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
1041866ab3337Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
104192a75d1c4Smrg	else
1042066ab3337Smrg	  gentop=$output_objdir/${obj}x
104212a75d1c4Smrg	  func_append generated " $gentop"
10422f7ec340bSmacallan
104232a75d1c4Smrg	  func_extract_archives $gentop $convenience
104242a75d1c4Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
104252a75d1c4Smrg	fi
10426f7ec340bSmacallan      fi
10427f7ec340bSmacallan
104282a75d1c4Smrg      # If we're not building shared, we need to use non_pic_objs
1042966ab3337Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430f7ec340bSmacallan
104312a75d1c4Smrg      # Create the old-style object.
1043266ab3337Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433f7ec340bSmacallan
1043466ab3337Smrg      output=$obj
104352a75d1c4Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
104362a75d1c4Smrg
104372a75d1c4Smrg      # Exit if we aren't doing a library object file.
104382a75d1c4Smrg      if test -z "$libobj"; then
104392a75d1c4Smrg	if test -n "$gentop"; then
104402a75d1c4Smrg	  func_show_eval '${RM}r "$gentop"'
104412a75d1c4Smrg	fi
104422a75d1c4Smrg
104432a75d1c4Smrg	exit $EXIT_SUCCESS
10444f7ec340bSmacallan      fi
104452a75d1c4Smrg
1044666ab3337Smrg      test yes = "$build_libtool_libs" || {
104472a75d1c4Smrg	if test -n "$gentop"; then
104482a75d1c4Smrg	  func_show_eval '${RM}r "$gentop"'
104492a75d1c4Smrg	fi
104502a75d1c4Smrg
104512a75d1c4Smrg	# Create an invalid libtool object if no PIC, so that we don't
104522a75d1c4Smrg	# accidentally link it into a program.
104532a75d1c4Smrg	# $show "echo timestamp > $libobj"
104542a75d1c4Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
104552a75d1c4Smrg	exit $EXIT_SUCCESS
1045666ab3337Smrg      }
104572a75d1c4Smrg
1045866ab3337Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
104592a75d1c4Smrg	# Only do commands if we really have different PIC objects.
104602a75d1c4Smrg	reload_objs="$libobjs $reload_conv_objs"
1046166ab3337Smrg	output=$libobj
104622a75d1c4Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
104632a75d1c4Smrg      fi
104642a75d1c4Smrg
104652a75d1c4Smrg      if test -n "$gentop"; then
104662a75d1c4Smrg	func_show_eval '${RM}r "$gentop"'
104672a75d1c4Smrg      fi
104682a75d1c4Smrg
104692a75d1c4Smrg      exit $EXIT_SUCCESS
10470f7ec340bSmacallan      ;;
10471f7ec340bSmacallan
104722a75d1c4Smrg    prog)
104732a75d1c4Smrg      case $host in
104742a75d1c4Smrg	*cygwin*) func_stripname '' '.exe' "$output"
104752a75d1c4Smrg	          output=$func_stripname_result.exe;;
104762a75d1c4Smrg      esac
104772a75d1c4Smrg      test -n "$vinfo" && \
1047866ab3337Smrg	func_warning "'-version-info' is ignored for programs"
10479f7ec340bSmacallan
104802a75d1c4Smrg      test -n "$release" && \
1048166ab3337Smrg	func_warning "'-release' is ignored for programs"
10482f7ec340bSmacallan
1048366ab3337Smrg      $preload \
1048466ab3337Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
1048566ab3337Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104862a75d1c4Smrg
104872a75d1c4Smrg      case $host in
104882a75d1c4Smrg      *-*-rhapsody* | *-*-darwin1.[012])
104892a75d1c4Smrg	# On Rhapsody replace the C library is the System framework
104902a75d1c4Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
104912a75d1c4Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492f7ec340bSmacallan	;;
104932a75d1c4Smrg      esac
10494f7ec340bSmacallan
104952a75d1c4Smrg      case $host in
104962a75d1c4Smrg      *-*-darwin*)
104972a75d1c4Smrg	# Don't allow lazy linking, it breaks C++ global constructors
104982a75d1c4Smrg	# But is supposedly fixed on 10.4 or later (yay!).
1049966ab3337Smrg	if test CXX = "$tagname"; then
105002a75d1c4Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
105012a75d1c4Smrg	    10.[0123])
1050266ab3337Smrg	      func_append compile_command " $wl-bind_at_load"
1050366ab3337Smrg	      func_append finalize_command " $wl-bind_at_load"
105042a75d1c4Smrg	    ;;
105052a75d1c4Smrg	  esac
10506f7ec340bSmacallan	fi
105072a75d1c4Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
105082a75d1c4Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105092a75d1c4Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105102a75d1c4Smrg	;;
105112a75d1c4Smrg      esac
10512f7ec340bSmacallan
10513f7ec340bSmacallan
105142a75d1c4Smrg      # move library search paths that coincide with paths to not yet
105152a75d1c4Smrg      # installed libraries to the beginning of the library search list
105162a75d1c4Smrg      new_libs=
105172a75d1c4Smrg      for path in $notinst_path; do
105182a75d1c4Smrg	case " $new_libs " in
105192a75d1c4Smrg	*" -L$path/$objdir "*) ;;
105202a75d1c4Smrg	*)
105212a75d1c4Smrg	  case " $compile_deplibs " in
105222a75d1c4Smrg	  *" -L$path/$objdir "*)
105232a75d1c4Smrg	    func_append new_libs " -L$path/$objdir" ;;
10524f7ec340bSmacallan	  esac
105252a75d1c4Smrg	  ;;
105262a75d1c4Smrg	esac
105272a75d1c4Smrg      done
105282a75d1c4Smrg      for deplib in $compile_deplibs; do
105292a75d1c4Smrg	case $deplib in
105302a75d1c4Smrg	-L*)
105312a75d1c4Smrg	  case " $new_libs " in
105322a75d1c4Smrg	  *" $deplib "*) ;;
105332a75d1c4Smrg	  *) func_append new_libs " $deplib" ;;
10534f7ec340bSmacallan	  esac
105352a75d1c4Smrg	  ;;
105362a75d1c4Smrg	*) func_append new_libs " $deplib" ;;
105372a75d1c4Smrg	esac
105382a75d1c4Smrg      done
1053966ab3337Smrg      compile_deplibs=$new_libs
10540f7ec340bSmacallan
10541f7ec340bSmacallan
105422a75d1c4Smrg      func_append compile_command " $compile_deplibs"
105432a75d1c4Smrg      func_append finalize_command " $finalize_deplibs"
10544f7ec340bSmacallan
105452a75d1c4Smrg      if test -n "$rpath$xrpath"; then
105462a75d1c4Smrg	# If the user specified any rpath flags, then add them.
105472a75d1c4Smrg	for libdir in $rpath $xrpath; do
105482a75d1c4Smrg	  # This is the magic to use -rpath.
105492a75d1c4Smrg	  case "$finalize_rpath " in
105502a75d1c4Smrg	  *" $libdir "*) ;;
105512a75d1c4Smrg	  *) func_append finalize_rpath " $libdir" ;;
105522a75d1c4Smrg	  esac
105532a75d1c4Smrg	done
105542a75d1c4Smrg      fi
10555f7ec340bSmacallan
105562a75d1c4Smrg      # Now hardcode the library paths
105572a75d1c4Smrg      rpath=
105582a75d1c4Smrg      hardcode_libdirs=
105592a75d1c4Smrg      for libdir in $compile_rpath $finalize_rpath; do
105602a75d1c4Smrg	if test -n "$hardcode_libdir_flag_spec"; then
105612a75d1c4Smrg	  if test -n "$hardcode_libdir_separator"; then
105622a75d1c4Smrg	    if test -z "$hardcode_libdirs"; then
1056366ab3337Smrg	      hardcode_libdirs=$libdir
105642a75d1c4Smrg	    else
105652a75d1c4Smrg	      # Just accumulate the unique libdirs.
105662a75d1c4Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
105672a75d1c4Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
105682a75d1c4Smrg		;;
105692a75d1c4Smrg	      *)
105702a75d1c4Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
105712a75d1c4Smrg		;;
105722a75d1c4Smrg	      esac
105732a75d1c4Smrg	    fi
10574f7ec340bSmacallan	  else
105752a75d1c4Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
105762a75d1c4Smrg	    func_append rpath " $flag"
10577f7ec340bSmacallan	  fi
105782a75d1c4Smrg	elif test -n "$runpath_var"; then
105792a75d1c4Smrg	  case "$perm_rpath " in
105802a75d1c4Smrg	  *" $libdir "*) ;;
105812a75d1c4Smrg	  *) func_append perm_rpath " $libdir" ;;
105822a75d1c4Smrg	  esac
105832a75d1c4Smrg	fi
105842a75d1c4Smrg	case $host in
105852a75d1c4Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
1058666ab3337Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
105872a75d1c4Smrg	  case :$dllsearchpath: in
105882a75d1c4Smrg	  *":$libdir:"*) ;;
105892a75d1c4Smrg	  ::) dllsearchpath=$libdir;;
105902a75d1c4Smrg	  *) func_append dllsearchpath ":$libdir";;
105912a75d1c4Smrg	  esac
105922a75d1c4Smrg	  case :$dllsearchpath: in
105932a75d1c4Smrg	  *":$testbindir:"*) ;;
105942a75d1c4Smrg	  ::) dllsearchpath=$testbindir;;
105952a75d1c4Smrg	  *) func_append dllsearchpath ":$testbindir";;
105962a75d1c4Smrg	  esac
105972a75d1c4Smrg	  ;;
105982a75d1c4Smrg	esac
105992a75d1c4Smrg      done
106002a75d1c4Smrg      # Substitute the hardcoded libdirs into the rpath.
106012a75d1c4Smrg      if test -n "$hardcode_libdir_separator" &&
106022a75d1c4Smrg	 test -n "$hardcode_libdirs"; then
1060366ab3337Smrg	libdir=$hardcode_libdirs
106042a75d1c4Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106052a75d1c4Smrg      fi
1060666ab3337Smrg      compile_rpath=$rpath
10607f7ec340bSmacallan
106082a75d1c4Smrg      rpath=
106092a75d1c4Smrg      hardcode_libdirs=
106102a75d1c4Smrg      for libdir in $finalize_rpath; do
106112a75d1c4Smrg	if test -n "$hardcode_libdir_flag_spec"; then
106122a75d1c4Smrg	  if test -n "$hardcode_libdir_separator"; then
106132a75d1c4Smrg	    if test -z "$hardcode_libdirs"; then
1061466ab3337Smrg	      hardcode_libdirs=$libdir
106152a75d1c4Smrg	    else
106162a75d1c4Smrg	      # Just accumulate the unique libdirs.
106172a75d1c4Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
106182a75d1c4Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
106192a75d1c4Smrg		;;
106202a75d1c4Smrg	      *)
106212a75d1c4Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
106222a75d1c4Smrg		;;
106232a75d1c4Smrg	      esac
106242a75d1c4Smrg	    fi
10625f7ec340bSmacallan	  else
106262a75d1c4Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
106272a75d1c4Smrg	    func_append rpath " $flag"
10628f7ec340bSmacallan	  fi
106292a75d1c4Smrg	elif test -n "$runpath_var"; then
106302a75d1c4Smrg	  case "$finalize_perm_rpath " in
106312a75d1c4Smrg	  *" $libdir "*) ;;
106322a75d1c4Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106332a75d1c4Smrg	  esac
10634f7ec340bSmacallan	fi
106352a75d1c4Smrg      done
106362a75d1c4Smrg      # Substitute the hardcoded libdirs into the rpath.
106372a75d1c4Smrg      if test -n "$hardcode_libdir_separator" &&
106382a75d1c4Smrg	 test -n "$hardcode_libdirs"; then
1063966ab3337Smrg	libdir=$hardcode_libdirs
106402a75d1c4Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106412a75d1c4Smrg      fi
1064266ab3337Smrg      finalize_rpath=$rpath
10643f7ec340bSmacallan
1064466ab3337Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
106452a75d1c4Smrg	# Transform all the library objects into standard objects.
106462a75d1c4Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106472a75d1c4Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106482a75d1c4Smrg      fi
10649f7ec340bSmacallan
1065066ab3337Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651f7ec340bSmacallan
106522a75d1c4Smrg      # template prelinking step
106532a75d1c4Smrg      if test -n "$prelink_cmds"; then
106542a75d1c4Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
106552a75d1c4Smrg      fi
10656f7ec340bSmacallan
1065766ab3337Smrg      wrappers_required=:
106582a75d1c4Smrg      case $host in
106592a75d1c4Smrg      *cegcc* | *mingw32ce*)
106602a75d1c4Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
1066166ab3337Smrg        wrappers_required=false
106622a75d1c4Smrg        ;;
106632a75d1c4Smrg      *cygwin* | *mingw* )
1066466ab3337Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
106652a75d1c4Smrg        ;;
106662a75d1c4Smrg      *)
1066766ab3337Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
1066866ab3337Smrg          wrappers_required=false
106692a75d1c4Smrg        fi
106702a75d1c4Smrg        ;;
106712a75d1c4Smrg      esac
1067266ab3337Smrg      $wrappers_required || {
106732a75d1c4Smrg	# Replace the output file specification.
106742a75d1c4Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1067566ab3337Smrg	link_command=$compile_command$compile_rpath
10676f7ec340bSmacallan
106772a75d1c4Smrg	# We have no uninstalled library dependencies, so finalize right now.
106782a75d1c4Smrg	exit_status=0
106792a75d1c4Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680f7ec340bSmacallan
106812a75d1c4Smrg	if test -n "$postlink_cmds"; then
106822a75d1c4Smrg	  func_to_tool_file "$output"
106832a75d1c4Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
106842a75d1c4Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685f7ec340bSmacallan	fi
10686f7ec340bSmacallan
106872a75d1c4Smrg	# Delete the generated files.
1068866ab3337Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
1068966ab3337Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
106902a75d1c4Smrg	fi
10691f7ec340bSmacallan
106922a75d1c4Smrg	exit $exit_status
1069366ab3337Smrg      }
10694f7ec340bSmacallan
106952a75d1c4Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
106962a75d1c4Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
106972a75d1c4Smrg      fi
106982a75d1c4Smrg      if test -n "$finalize_shlibpath"; then
106992a75d1c4Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
107002a75d1c4Smrg      fi
10701f7ec340bSmacallan
107022a75d1c4Smrg      compile_var=
107032a75d1c4Smrg      finalize_var=
107042a75d1c4Smrg      if test -n "$runpath_var"; then
107052a75d1c4Smrg	if test -n "$perm_rpath"; then
107062a75d1c4Smrg	  # We should set the runpath_var.
107072a75d1c4Smrg	  rpath=
107082a75d1c4Smrg	  for dir in $perm_rpath; do
107092a75d1c4Smrg	    func_append rpath "$dir:"
107102a75d1c4Smrg	  done
107112a75d1c4Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712f7ec340bSmacallan	fi
107132a75d1c4Smrg	if test -n "$finalize_perm_rpath"; then
107142a75d1c4Smrg	  # We should set the runpath_var.
107152a75d1c4Smrg	  rpath=
107162a75d1c4Smrg	  for dir in $finalize_perm_rpath; do
107172a75d1c4Smrg	    func_append rpath "$dir:"
107182a75d1c4Smrg	  done
107192a75d1c4Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720f7ec340bSmacallan	fi
107212a75d1c4Smrg      fi
10722f7ec340bSmacallan
1072366ab3337Smrg      if test yes = "$no_install"; then
107242a75d1c4Smrg	# We don't need to create a wrapper script.
1072566ab3337Smrg	link_command=$compile_var$compile_command$compile_rpath
107262a75d1c4Smrg	# Replace the output file specification.
107272a75d1c4Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
107282a75d1c4Smrg	# Delete the old output file.
107292a75d1c4Smrg	$opt_dry_run || $RM $output
107302a75d1c4Smrg	# Link the executable and exit
107312a75d1c4Smrg	func_show_eval "$link_command" 'exit $?'
10732f7ec340bSmacallan
107332a75d1c4Smrg	if test -n "$postlink_cmds"; then
107342a75d1c4Smrg	  func_to_tool_file "$output"
107352a75d1c4Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
107362a75d1c4Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737f7ec340bSmacallan	fi
107382a75d1c4Smrg
10739f7ec340bSmacallan	exit $EXIT_SUCCESS
107402a75d1c4Smrg      fi
10741f7ec340bSmacallan
1074266ab3337Smrg      case $hardcode_action,$fast_install in
1074366ab3337Smrg        relink,*)
1074466ab3337Smrg	  # Fast installation is not supported
1074566ab3337Smrg	  link_command=$compile_var$compile_command$compile_rpath
1074666ab3337Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107472a75d1c4Smrg
1074866ab3337Smrg	  func_warning "this platform does not like uninstalled shared libraries"
1074966ab3337Smrg	  func_warning "'$output' will be relinked during installation"
1075066ab3337Smrg	  ;;
1075166ab3337Smrg        *,yes)
1075266ab3337Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1075366ab3337Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
1075466ab3337Smrg          ;;
1075566ab3337Smrg	*,no)
1075666ab3337Smrg	  link_command=$compile_var$compile_command$compile_rpath
1075766ab3337Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1075866ab3337Smrg          ;;
1075966ab3337Smrg	*,needless)
1076066ab3337Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
1076166ab3337Smrg	  relink_command=
1076266ab3337Smrg          ;;
1076366ab3337Smrg      esac
10764f7ec340bSmacallan
107652a75d1c4Smrg      # Replace the output file specification.
107662a75d1c4Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767f7ec340bSmacallan
107682a75d1c4Smrg      # Delete the old output files.
107692a75d1c4Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770f7ec340bSmacallan
107712a75d1c4Smrg      func_show_eval "$link_command" 'exit $?'
10772f7ec340bSmacallan
107732a75d1c4Smrg      if test -n "$postlink_cmds"; then
107742a75d1c4Smrg	func_to_tool_file "$output_objdir/$outputname"
107752a75d1c4Smrg	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'`
107762a75d1c4Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
107772a75d1c4Smrg      fi
10778f7ec340bSmacallan
107792a75d1c4Smrg      # Now create the wrapper script.
107802a75d1c4Smrg      func_verbose "creating $output"
10781f7ec340bSmacallan
107822a75d1c4Smrg      # Quote the relink command for shipping.
107832a75d1c4Smrg      if test -n "$relink_command"; then
107842a75d1c4Smrg	# Preserve any variables that may affect compiler behavior
107852a75d1c4Smrg	for var in $variables_saved_for_relink; do
107862a75d1c4Smrg	  if eval test -z \"\${$var+set}\"; then
107872a75d1c4Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107882a75d1c4Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
107892a75d1c4Smrg	    relink_command="$var=; export $var; $relink_command"
10790f7ec340bSmacallan	  else
1079166ab3337Smrg	    func_quote_arg pretty "$var_value"
1079266ab3337Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793f7ec340bSmacallan	  fi
107942a75d1c4Smrg	done
1079566ab3337Smrg	func_quote eval cd "`pwd`"
1079666ab3337Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
1079766ab3337Smrg	relink_command=$func_quote_arg_unquoted_result
107982a75d1c4Smrg      fi
107992a75d1c4Smrg
108002a75d1c4Smrg      # Only actually do things if not in dry run mode.
108012a75d1c4Smrg      $opt_dry_run || {
108022a75d1c4Smrg	# win32 will think the script is a binary if it has
108032a75d1c4Smrg	# a .exe suffix, so we strip it off here.
108042a75d1c4Smrg	case $output in
108052a75d1c4Smrg	  *.exe) func_stripname '' '.exe' "$output"
108062a75d1c4Smrg	         output=$func_stripname_result ;;
10807f7ec340bSmacallan	esac
108082a75d1c4Smrg	# test for cygwin because mv fails w/o .exe extensions
108092a75d1c4Smrg	case $host in
108102a75d1c4Smrg	  *cygwin*)
108112a75d1c4Smrg	    exeext=.exe
108122a75d1c4Smrg	    func_stripname '' '.exe' "$outputname"
108132a75d1c4Smrg	    outputname=$func_stripname_result ;;
108142a75d1c4Smrg	  *) exeext= ;;
108152a75d1c4Smrg	esac
108162a75d1c4Smrg	case $host in
108172a75d1c4Smrg	  *cygwin* | *mingw* )
108182a75d1c4Smrg	    func_dirname_and_basename "$output" "" "."
108192a75d1c4Smrg	    output_name=$func_basename_result
108202a75d1c4Smrg	    output_path=$func_dirname_result
1082166ab3337Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
1082266ab3337Smrg	    cwrapper=$output_path/$output_name.exe
108232a75d1c4Smrg	    $RM $cwrappersource $cwrapper
108242a75d1c4Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
108252a75d1c4Smrg
108262a75d1c4Smrg	    func_emit_cwrapperexe_src > $cwrappersource
108272a75d1c4Smrg
108282a75d1c4Smrg	    # The wrapper executable is built using the $host compiler,
108292a75d1c4Smrg	    # because it contains $host paths and files. If cross-
108302a75d1c4Smrg	    # compiling, it, like the target executable, must be
108312a75d1c4Smrg	    # executed on the $host or under an emulation environment.
108322a75d1c4Smrg	    $opt_dry_run || {
108332a75d1c4Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
108342a75d1c4Smrg	      $STRIP $cwrapper
108352a75d1c4Smrg	    }
10836f7ec340bSmacallan
108372a75d1c4Smrg	    # Now, create the wrapper script for func_source use:
108382a75d1c4Smrg	    func_ltwrapper_scriptname $cwrapper
108392a75d1c4Smrg	    $RM $func_ltwrapper_scriptname_result
108402a75d1c4Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
108412a75d1c4Smrg	    $opt_dry_run || {
108422a75d1c4Smrg	      # note: this script will not be executed, so do not chmod.
1084366ab3337Smrg	      if test "x$build" = "x$host"; then
108442a75d1c4Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108452a75d1c4Smrg	      else
108462a75d1c4Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108472a75d1c4Smrg	      fi
108482a75d1c4Smrg	    }
108492a75d1c4Smrg	  ;;
108502a75d1c4Smrg	  * )
108512a75d1c4Smrg	    $RM $output
108522a75d1c4Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853f7ec340bSmacallan
108542a75d1c4Smrg	    func_emit_wrapper no > $output
108552a75d1c4Smrg	    chmod +x $output
108562a75d1c4Smrg	  ;;
108572a75d1c4Smrg	esac
108582a75d1c4Smrg      }
108592a75d1c4Smrg      exit $EXIT_SUCCESS
108602a75d1c4Smrg      ;;
108612a75d1c4Smrg    esac
10862f7ec340bSmacallan
108632a75d1c4Smrg    # See if we need to build an old-fashioned archive.
108642a75d1c4Smrg    for oldlib in $oldlibs; do
10865f7ec340bSmacallan
1086666ab3337Smrg      case $build_libtool_libs in
1086766ab3337Smrg        convenience)
1086866ab3337Smrg	  oldobjs="$libobjs_save $symfileobj"
1086966ab3337Smrg	  addlibs=$convenience
108702a75d1c4Smrg	  build_libtool_libs=no
1087166ab3337Smrg	  ;;
1087266ab3337Smrg	module)
1087366ab3337Smrg	  oldobjs=$libobjs_save
1087466ab3337Smrg	  addlibs=$old_convenience
1087566ab3337Smrg	  build_libtool_libs=no
1087666ab3337Smrg          ;;
1087766ab3337Smrg	*)
108782a75d1c4Smrg	  oldobjs="$old_deplibs $non_pic_objects"
1087966ab3337Smrg	  $preload && test -f "$symfileobj" \
1088066ab3337Smrg	    && func_append oldobjs " $symfileobj"
1088166ab3337Smrg	  addlibs=$old_convenience
1088266ab3337Smrg	  ;;
1088366ab3337Smrg      esac
10884f7ec340bSmacallan
108852a75d1c4Smrg      if test -n "$addlibs"; then
1088666ab3337Smrg	gentop=$output_objdir/${outputname}x
108872a75d1c4Smrg	func_append generated " $gentop"
10888f7ec340bSmacallan
108892a75d1c4Smrg	func_extract_archives $gentop $addlibs
108902a75d1c4Smrg	func_append oldobjs " $func_extract_archives_result"
108912a75d1c4Smrg      fi
10892f7ec340bSmacallan
108932a75d1c4Smrg      # Do each command in the archive commands.
1089466ab3337Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
108952a75d1c4Smrg	cmds=$old_archive_from_new_cmds
108962a75d1c4Smrg      else
10897f7ec340bSmacallan
108982a75d1c4Smrg	# Add any objects from preloaded convenience libraries
108992a75d1c4Smrg	if test -n "$dlprefiles"; then
1090066ab3337Smrg	  gentop=$output_objdir/${outputname}x
109012a75d1c4Smrg	  func_append generated " $gentop"
10902f7ec340bSmacallan
109032a75d1c4Smrg	  func_extract_archives $gentop $dlprefiles
109042a75d1c4Smrg	  func_append oldobjs " $func_extract_archives_result"
109052a75d1c4Smrg	fi
10906f7ec340bSmacallan
109072a75d1c4Smrg	# POSIX demands no paths to be encoded in archives.  We have
109082a75d1c4Smrg	# to avoid creating archives with duplicate basenames if we
109092a75d1c4Smrg	# might have to extract them afterwards, e.g., when creating a
109102a75d1c4Smrg	# static archive out of a convenience library, or when linking
109112a75d1c4Smrg	# the entirety of a libtool archive into another (currently
109122a75d1c4Smrg	# not supported by libtool).
109132a75d1c4Smrg	if (for obj in $oldobjs
109142a75d1c4Smrg	    do
109152a75d1c4Smrg	      func_basename "$obj"
109162a75d1c4Smrg	      $ECHO "$func_basename_result"
109172a75d1c4Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
109182a75d1c4Smrg	  :
109192a75d1c4Smrg	else
109202a75d1c4Smrg	  echo "copying selected object files to avoid basename conflicts..."
1092166ab3337Smrg	  gentop=$output_objdir/${outputname}x
109222a75d1c4Smrg	  func_append generated " $gentop"
109232a75d1c4Smrg	  func_mkdir_p "$gentop"
109242a75d1c4Smrg	  save_oldobjs=$oldobjs
109252a75d1c4Smrg	  oldobjs=
109262a75d1c4Smrg	  counter=1
109272a75d1c4Smrg	  for obj in $save_oldobjs
109282a75d1c4Smrg	  do
109292a75d1c4Smrg	    func_basename "$obj"
1093066ab3337Smrg	    objbase=$func_basename_result
109312a75d1c4Smrg	    case " $oldobjs " in
109322a75d1c4Smrg	    " ") oldobjs=$obj ;;
109332a75d1c4Smrg	    *[\ /]"$objbase "*)
109342a75d1c4Smrg	      while :; do
109352a75d1c4Smrg		# Make sure we don't pick an alternate name that also
109362a75d1c4Smrg		# overlaps.
109372a75d1c4Smrg		newobj=lt$counter-$objbase
109382a75d1c4Smrg		func_arith $counter + 1
109392a75d1c4Smrg		counter=$func_arith_result
109402a75d1c4Smrg		case " $oldobjs " in
109412a75d1c4Smrg		*[\ /]"$newobj "*) ;;
109422a75d1c4Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
109432a75d1c4Smrg		esac
109442a75d1c4Smrg	      done
109452a75d1c4Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
109462a75d1c4Smrg	      func_append oldobjs " $gentop/$newobj"
109472a75d1c4Smrg	      ;;
109482a75d1c4Smrg	    *) func_append oldobjs " $obj" ;;
109492a75d1c4Smrg	    esac
10950f7ec340bSmacallan	  done
10951f7ec340bSmacallan	fi
1095266ab3337Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
1095366ab3337Smrg	tool_oldlib=$func_to_tool_file_result
109542a75d1c4Smrg	eval cmds=\"$old_archive_cmds\"
10955f7ec340bSmacallan
109562a75d1c4Smrg	func_len " $cmds"
109572a75d1c4Smrg	len=$func_len_result
109582a75d1c4Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
109592a75d1c4Smrg	  cmds=$old_archive_cmds
109602a75d1c4Smrg	elif test -n "$archiver_list_spec"; then
109612a75d1c4Smrg	  func_verbose "using command file archive linking..."
109622a75d1c4Smrg	  for obj in $oldobjs
109632a75d1c4Smrg	  do
109642a75d1c4Smrg	    func_to_tool_file "$obj"
109652a75d1c4Smrg	    $ECHO "$func_to_tool_file_result"
109662a75d1c4Smrg	  done > $output_objdir/$libname.libcmd
109672a75d1c4Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
109682a75d1c4Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
109692a75d1c4Smrg	  cmds=$old_archive_cmds
109702a75d1c4Smrg	else
109712a75d1c4Smrg	  # the command line is too long to link in one step, link in parts
109722a75d1c4Smrg	  func_verbose "using piecewise archive linking..."
109732a75d1c4Smrg	  save_RANLIB=$RANLIB
109742a75d1c4Smrg	  RANLIB=:
109752a75d1c4Smrg	  objlist=
109762a75d1c4Smrg	  concat_cmds=
109772a75d1c4Smrg	  save_oldobjs=$oldobjs
109782a75d1c4Smrg	  oldobjs=
109792a75d1c4Smrg	  # Is there a better way of finding the last object in the list?
109802a75d1c4Smrg	  for obj in $save_oldobjs
109812a75d1c4Smrg	  do
109822a75d1c4Smrg	    last_oldobj=$obj
109832a75d1c4Smrg	  done
109842a75d1c4Smrg	  eval test_cmds=\"$old_archive_cmds\"
109852a75d1c4Smrg	  func_len " $test_cmds"
109862a75d1c4Smrg	  len0=$func_len_result
109872a75d1c4Smrg	  len=$len0
109882a75d1c4Smrg	  for obj in $save_oldobjs
109892a75d1c4Smrg	  do
109902a75d1c4Smrg	    func_len " $obj"
109912a75d1c4Smrg	    func_arith $len + $func_len_result
109922a75d1c4Smrg	    len=$func_arith_result
109932a75d1c4Smrg	    func_append objlist " $obj"
109942a75d1c4Smrg	    if test "$len" -lt "$max_cmd_len"; then
109952a75d1c4Smrg	      :
109962a75d1c4Smrg	    else
109972a75d1c4Smrg	      # the above command should be used before it gets too long
109982a75d1c4Smrg	      oldobjs=$objlist
1099966ab3337Smrg	      if test "$obj" = "$last_oldobj"; then
110002a75d1c4Smrg		RANLIB=$save_RANLIB
110012a75d1c4Smrg	      fi
110022a75d1c4Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1100366ab3337Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
110042a75d1c4Smrg	      objlist=
110052a75d1c4Smrg	      len=$len0
110062a75d1c4Smrg	    fi
110072a75d1c4Smrg	  done
110082a75d1c4Smrg	  RANLIB=$save_RANLIB
110092a75d1c4Smrg	  oldobjs=$objlist
1101066ab3337Smrg	  if test -z "$oldobjs"; then
110112a75d1c4Smrg	    eval cmds=\"\$concat_cmds\"
110122a75d1c4Smrg	  else
110132a75d1c4Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
110142a75d1c4Smrg	  fi
110152a75d1c4Smrg	fi
110162a75d1c4Smrg      fi
110172a75d1c4Smrg      func_execute_cmds "$cmds" 'exit $?'
11018f7ec340bSmacallan    done
11019f7ec340bSmacallan
110202a75d1c4Smrg    test -n "$generated" && \
110212a75d1c4Smrg      func_show_eval "${RM}r$generated"
11022f7ec340bSmacallan
110232a75d1c4Smrg    # Now create the libtool archive.
110242a75d1c4Smrg    case $output in
110252a75d1c4Smrg    *.la)
110262a75d1c4Smrg      old_library=
1102766ab3337Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
110282a75d1c4Smrg      func_verbose "creating $output"
11029f7ec340bSmacallan
110302a75d1c4Smrg      # Preserve any variables that may affect compiler behavior
110312a75d1c4Smrg      for var in $variables_saved_for_relink; do
110322a75d1c4Smrg	if eval test -z \"\${$var+set}\"; then
110332a75d1c4Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
110342a75d1c4Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
110352a75d1c4Smrg	  relink_command="$var=; export $var; $relink_command"
11036f7ec340bSmacallan	else
1103766ab3337Smrg	  func_quote_arg pretty,unquoted "$var_value"
1103866ab3337Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039f7ec340bSmacallan	fi
110402a75d1c4Smrg      done
110412a75d1c4Smrg      # Quote the link command for shipping.
1104266ab3337Smrg      func_quote eval cd "`pwd`"
1104366ab3337Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1104466ab3337Smrg      func_quote_arg pretty,unquoted "$relink_command"
1104566ab3337Smrg      relink_command=$func_quote_arg_unquoted_result
1104666ab3337Smrg      if test yes = "$hardcode_automatic"; then
110472a75d1c4Smrg	relink_command=
110482a75d1c4Smrg      fi
11049f7ec340bSmacallan
110502a75d1c4Smrg      # Only create the output if not a dry run.
110512a75d1c4Smrg      $opt_dry_run || {
110522a75d1c4Smrg	for installed in no yes; do
1105366ab3337Smrg	  if test yes = "$installed"; then
110542a75d1c4Smrg	    if test -z "$install_libdir"; then
110552a75d1c4Smrg	      break
110562a75d1c4Smrg	    fi
1105766ab3337Smrg	    output=$output_objdir/${outputname}i
110582a75d1c4Smrg	    # Replace all uninstalled libtool libraries with the installed ones
110592a75d1c4Smrg	    newdependency_libs=
110602a75d1c4Smrg	    for deplib in $dependency_libs; do
110612a75d1c4Smrg	      case $deplib in
110622a75d1c4Smrg	      *.la)
110632a75d1c4Smrg		func_basename "$deplib"
1106466ab3337Smrg		name=$func_basename_result
1106566ab3337Smrg		func_resolve_sysroot "$deplib"
1106666ab3337Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
110672a75d1c4Smrg		test -z "$libdir" && \
1106866ab3337Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
110692a75d1c4Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
110702a75d1c4Smrg		;;
110712a75d1c4Smrg	      -L*)
110722a75d1c4Smrg		func_stripname -L '' "$deplib"
110732a75d1c4Smrg		func_replace_sysroot "$func_stripname_result"
110742a75d1c4Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
110752a75d1c4Smrg		;;
110762a75d1c4Smrg	      -R*)
110772a75d1c4Smrg		func_stripname -R '' "$deplib"
110782a75d1c4Smrg		func_replace_sysroot "$func_stripname_result"
110792a75d1c4Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
110802a75d1c4Smrg		;;
110812a75d1c4Smrg	      *) func_append newdependency_libs " $deplib" ;;
110822a75d1c4Smrg	      esac
110832a75d1c4Smrg	    done
1108466ab3337Smrg	    dependency_libs=$newdependency_libs
110852a75d1c4Smrg	    newdlfiles=
110862a75d1c4Smrg
110872a75d1c4Smrg	    for lib in $dlfiles; do
110882a75d1c4Smrg	      case $lib in
110892a75d1c4Smrg	      *.la)
110902a75d1c4Smrg	        func_basename "$lib"
1109166ab3337Smrg		name=$func_basename_result
1109266ab3337Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
110932a75d1c4Smrg		test -z "$libdir" && \
1109466ab3337Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
110952a75d1c4Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
110962a75d1c4Smrg		;;
110972a75d1c4Smrg	      *) func_append newdlfiles " $lib" ;;
110982a75d1c4Smrg	      esac
110992a75d1c4Smrg	    done
1110066ab3337Smrg	    dlfiles=$newdlfiles
111012a75d1c4Smrg	    newdlprefiles=
111022a75d1c4Smrg	    for lib in $dlprefiles; do
111032a75d1c4Smrg	      case $lib in
111042a75d1c4Smrg	      *.la)
111052a75d1c4Smrg		# Only pass preopened files to the pseudo-archive (for
111062a75d1c4Smrg		# eventual linking with the app. that links it) if we
111072a75d1c4Smrg		# didn't already link the preopened objects directly into
111082a75d1c4Smrg		# the library:
111092a75d1c4Smrg		func_basename "$lib"
1111066ab3337Smrg		name=$func_basename_result
1111166ab3337Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
111122a75d1c4Smrg		test -z "$libdir" && \
1111366ab3337Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
111142a75d1c4Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
111152a75d1c4Smrg		;;
111162a75d1c4Smrg	      esac
111172a75d1c4Smrg	    done
1111866ab3337Smrg	    dlprefiles=$newdlprefiles
111192a75d1c4Smrg	  else
111202a75d1c4Smrg	    newdlfiles=
111212a75d1c4Smrg	    for lib in $dlfiles; do
111222a75d1c4Smrg	      case $lib in
1112366ab3337Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111242a75d1c4Smrg		*) abs=`pwd`"/$lib" ;;
111252a75d1c4Smrg	      esac
111262a75d1c4Smrg	      func_append newdlfiles " $abs"
111272a75d1c4Smrg	    done
1112866ab3337Smrg	    dlfiles=$newdlfiles
111292a75d1c4Smrg	    newdlprefiles=
111302a75d1c4Smrg	    for lib in $dlprefiles; do
111312a75d1c4Smrg	      case $lib in
1113266ab3337Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111332a75d1c4Smrg		*) abs=`pwd`"/$lib" ;;
111342a75d1c4Smrg	      esac
111352a75d1c4Smrg	      func_append newdlprefiles " $abs"
111362a75d1c4Smrg	    done
1113766ab3337Smrg	    dlprefiles=$newdlprefiles
111382a75d1c4Smrg	  fi
111392a75d1c4Smrg	  $RM $output
111402a75d1c4Smrg	  # place dlname in correct position for cygwin
111412a75d1c4Smrg	  # In fact, it would be nice if we could use this code for all target
111422a75d1c4Smrg	  # systems that can't hard-code library paths into their executables
111432a75d1c4Smrg	  # and that have no shared library path variable independent of PATH,
111442a75d1c4Smrg	  # but it turns out we can't easily determine that from inspecting
111452a75d1c4Smrg	  # libtool variables, so we have to hard-code the OSs to which it
111462a75d1c4Smrg	  # applies here; at the moment, that means platforms that use the PE
111472a75d1c4Smrg	  # object format with DLL files.  See the long comment at the top of
111482a75d1c4Smrg	  # tests/bindir.at for full details.
111492a75d1c4Smrg	  tdlname=$dlname
111502a75d1c4Smrg	  case $host,$output,$installed,$module,$dlname in
111512a75d1c4Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
111522a75d1c4Smrg	      # If a -bindir argument was supplied, place the dll there.
1115366ab3337Smrg	      if test -n "$bindir"; then
111542a75d1c4Smrg		func_relative_path "$install_libdir" "$bindir"
1115566ab3337Smrg		tdlname=$func_relative_path_result/$dlname
111562a75d1c4Smrg	      else
111572a75d1c4Smrg		# Otherwise fall back on heuristic.
111582a75d1c4Smrg		tdlname=../bin/$dlname
111592a75d1c4Smrg	      fi
111602a75d1c4Smrg	      ;;
111612a75d1c4Smrg	  esac
111622a75d1c4Smrg	  $ECHO > $output "\
111632a75d1c4Smrg# $outputname - a libtool library file
1116466ab3337Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
111652a75d1c4Smrg#
111662a75d1c4Smrg# Please DO NOT delete this file!
111672a75d1c4Smrg# It is necessary for linking the library.
11168f7ec340bSmacallan
111692a75d1c4Smrg# The name that we can dlopen(3).
111702a75d1c4Smrgdlname='$tdlname'
11171f7ec340bSmacallan
111722a75d1c4Smrg# Names of this library.
111732a75d1c4Smrglibrary_names='$library_names'
11174f7ec340bSmacallan
111752a75d1c4Smrg# The name of the static archive.
111762a75d1c4Smrgold_library='$old_library'
11177f7ec340bSmacallan
1117866ab3337Smrg# Linker flags that cannot go in dependency_libs.
111792a75d1c4Smrginherited_linker_flags='$new_inherited_linker_flags'
11180f7ec340bSmacallan
111812a75d1c4Smrg# Libraries that this one depends upon.
111822a75d1c4Smrgdependency_libs='$dependency_libs'
11183f7ec340bSmacallan
111842a75d1c4Smrg# Names of additional weak libraries provided by this library
111852a75d1c4Smrgweak_library_names='$weak_libs'
11186f7ec340bSmacallan
111872a75d1c4Smrg# Version information for $libname.
111882a75d1c4Smrgcurrent=$current
111892a75d1c4Smrgage=$age
111902a75d1c4Smrgrevision=$revision
11191f7ec340bSmacallan
111922a75d1c4Smrg# Is this an already installed library?
111932a75d1c4Smrginstalled=$installed
11194f7ec340bSmacallan
111952a75d1c4Smrg# Should we warn about portability when linking against -modules?
111962a75d1c4Smrgshouldnotlink=$module
11197f7ec340bSmacallan
111982a75d1c4Smrg# Files to dlopen/dlpreopen
111992a75d1c4Smrgdlopen='$dlfiles'
112002a75d1c4Smrgdlpreopen='$dlprefiles'
11201f7ec340bSmacallan
112022a75d1c4Smrg# Directory that this library needs to be installed in:
112032a75d1c4Smrglibdir='$install_libdir'"
1120466ab3337Smrg	  if test no,yes = "$installed,$need_relink"; then
112052a75d1c4Smrg	    $ECHO >> $output "\
112062a75d1c4Smrgrelink_command=\"$relink_command\""
112072a75d1c4Smrg	  fi
112082a75d1c4Smrg	done
112092a75d1c4Smrg      }
11210f7ec340bSmacallan
112112a75d1c4Smrg      # Do a symbolic link so that the libtool archive can be found in
112122a75d1c4Smrg      # LD_LIBRARY_PATH before the program is installed.
112132a75d1c4Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
112142a75d1c4Smrg      ;;
112152a75d1c4Smrg    esac
112162a75d1c4Smrg    exit $EXIT_SUCCESS
112172a75d1c4Smrg}
11218f7ec340bSmacallan
1121966ab3337Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
1122066ab3337Smrg  func_mode_link ${1+"$@"}
1122166ab3337Smrgfi
11222f7ec340bSmacallan
11223f7ec340bSmacallan
112242a75d1c4Smrg# func_mode_uninstall arg...
112252a75d1c4Smrgfunc_mode_uninstall ()
112262a75d1c4Smrg{
1122766ab3337Smrg    $debug_cmd
1122866ab3337Smrg
1122966ab3337Smrg    RM=$nonopt
11230f7ec340bSmacallan    files=
1123166ab3337Smrg    rmforce=false
11232f7ec340bSmacallan    exit_status=0
11233f7ec340bSmacallan
11234f7ec340bSmacallan    # This variable tells wrapper scripts just to set variables rather
11235f7ec340bSmacallan    # than running their programs.
1123666ab3337Smrg    libtool_install_magic=$magic
11237f7ec340bSmacallan
11238f7ec340bSmacallan    for arg
11239f7ec340bSmacallan    do
11240f7ec340bSmacallan      case $arg in
1124166ab3337Smrg      -f) func_append RM " $arg"; rmforce=: ;;
112422a75d1c4Smrg      -*) func_append RM " $arg" ;;
112432a75d1c4Smrg      *) func_append files " $arg" ;;
11244f7ec340bSmacallan      esac
11245f7ec340bSmacallan    done
11246f7ec340bSmacallan
112472a75d1c4Smrg    test -z "$RM" && \
112482a75d1c4Smrg      func_fatal_help "you must specify an RM program"
11249f7ec340bSmacallan
11250f7ec340bSmacallan    rmdirs=
11251f7ec340bSmacallan
11252f7ec340bSmacallan    for file in $files; do
112532a75d1c4Smrg      func_dirname "$file" "" "."
1125466ab3337Smrg      dir=$func_dirname_result
1125566ab3337Smrg      if test . = "$dir"; then
1125666ab3337Smrg	odir=$objdir
11257f7ec340bSmacallan      else
1125866ab3337Smrg	odir=$dir/$objdir
11259f7ec340bSmacallan      fi
112602a75d1c4Smrg      func_basename "$file"
1126166ab3337Smrg      name=$func_basename_result
1126266ab3337Smrg      test uninstall = "$opt_mode" && odir=$dir
11263f7ec340bSmacallan
112642a75d1c4Smrg      # Remember odir for removal later, being careful to avoid duplicates
1126566ab3337Smrg      if test clean = "$opt_mode"; then
11266f7ec340bSmacallan	case " $rmdirs " in
112672a75d1c4Smrg	  *" $odir "*) ;;
112682a75d1c4Smrg	  *) func_append rmdirs " $odir" ;;
11269f7ec340bSmacallan	esac
11270f7ec340bSmacallan      fi
11271f7ec340bSmacallan
11272f7ec340bSmacallan      # Don't error if the file doesn't exist and rm -f was used.
112732a75d1c4Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
112742a75d1c4Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
112752a75d1c4Smrg	 test -f "$file"; then
11276f7ec340bSmacallan	:
11277f7ec340bSmacallan      elif test -d "$file"; then
11278f7ec340bSmacallan	exit_status=1
11279f7ec340bSmacallan	continue
1128066ab3337Smrg      elif $rmforce; then
11281f7ec340bSmacallan	continue
11282f7ec340bSmacallan      fi
11283f7ec340bSmacallan
1128466ab3337Smrg      rmfiles=$file
11285f7ec340bSmacallan
11286f7ec340bSmacallan      case $name in
11287f7ec340bSmacallan      *.la)
11288f7ec340bSmacallan	# Possibly a libtool archive, so verify it.
112892a75d1c4Smrg	if func_lalib_p "$file"; then
112902a75d1c4Smrg	  func_source $dir/$name
11291f7ec340bSmacallan
11292f7ec340bSmacallan	  # Delete the libtool libraries and symlinks.
11293f7ec340bSmacallan	  for n in $library_names; do
112942a75d1c4Smrg	    func_append rmfiles " $odir/$n"
11295f7ec340bSmacallan	  done
112962a75d1c4Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297f7ec340bSmacallan
1129866ab3337Smrg	  case $opt_mode in
11299f7ec340bSmacallan	  clean)
113002a75d1c4Smrg	    case " $library_names " in
11301f7ec340bSmacallan	    *" $dlname "*) ;;
113022a75d1c4Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303f7ec340bSmacallan	    esac
113042a75d1c4Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305f7ec340bSmacallan	    ;;
11306f7ec340bSmacallan	  uninstall)
11307f7ec340bSmacallan	    if test -n "$library_names"; then
11308f7ec340bSmacallan	      # Do each command in the postuninstall commands.
1130966ab3337Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310f7ec340bSmacallan	    fi
11311f7ec340bSmacallan
11312f7ec340bSmacallan	    if test -n "$old_library"; then
11313f7ec340bSmacallan	      # Do each command in the old_postuninstall commands.
1131466ab3337Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315f7ec340bSmacallan	    fi
11316f7ec340bSmacallan	    # FIXME: should reinstall the best remaining shared library.
11317f7ec340bSmacallan	    ;;
11318f7ec340bSmacallan	  esac
11319f7ec340bSmacallan	fi
11320f7ec340bSmacallan	;;
11321f7ec340bSmacallan
11322f7ec340bSmacallan      *.lo)
11323f7ec340bSmacallan	# Possibly a libtool object, so verify it.
113242a75d1c4Smrg	if func_lalib_p "$file"; then
11325f7ec340bSmacallan
11326f7ec340bSmacallan	  # Read the .lo file
113272a75d1c4Smrg	  func_source $dir/$name
11328f7ec340bSmacallan
11329f7ec340bSmacallan	  # Add PIC object to the list of files to remove.
1133066ab3337Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
113312a75d1c4Smrg	    func_append rmfiles " $dir/$pic_object"
11332f7ec340bSmacallan	  fi
11333f7ec340bSmacallan
11334f7ec340bSmacallan	  # Add non-PIC object to the list of files to remove.
1133566ab3337Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
113362a75d1c4Smrg	    func_append rmfiles " $dir/$non_pic_object"
11337f7ec340bSmacallan	  fi
11338f7ec340bSmacallan	fi
11339f7ec340bSmacallan	;;
11340f7ec340bSmacallan
11341f7ec340bSmacallan      *)
1134266ab3337Smrg	if test clean = "$opt_mode"; then
11343f7ec340bSmacallan	  noexename=$name
11344f7ec340bSmacallan	  case $file in
11345f7ec340bSmacallan	  *.exe)
113462a75d1c4Smrg	    func_stripname '' '.exe' "$file"
113472a75d1c4Smrg	    file=$func_stripname_result
113482a75d1c4Smrg	    func_stripname '' '.exe' "$name"
113492a75d1c4Smrg	    noexename=$func_stripname_result
11350f7ec340bSmacallan	    # $file with .exe has already been added to rmfiles,
11351f7ec340bSmacallan	    # add $file without .exe
113522a75d1c4Smrg	    func_append rmfiles " $file"
11353f7ec340bSmacallan	    ;;
11354f7ec340bSmacallan	  esac
11355f7ec340bSmacallan	  # Do a test to see if this is a libtool program.
113562a75d1c4Smrg	  if func_ltwrapper_p "$file"; then
113572a75d1c4Smrg	    if func_ltwrapper_executable_p "$file"; then
113582a75d1c4Smrg	      func_ltwrapper_scriptname "$file"
113592a75d1c4Smrg	      relink_command=
113602a75d1c4Smrg	      func_source $func_ltwrapper_scriptname_result
113612a75d1c4Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
113622a75d1c4Smrg	    else
113632a75d1c4Smrg	      relink_command=
113642a75d1c4Smrg	      func_source $dir/$noexename
113652a75d1c4Smrg	    fi
11366f7ec340bSmacallan
11367f7ec340bSmacallan	    # note $name still contains .exe if it was in $file originally
11368f7ec340bSmacallan	    # as does the version of $file that was added into $rmfiles
1136966ab3337Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
1137066ab3337Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
113712a75d1c4Smrg	      func_append rmfiles " $odir/lt-$name"
11372f7ec340bSmacallan	    fi
1137366ab3337Smrg	    if test "X$noexename" != "X$name"; then
1137466ab3337Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375f7ec340bSmacallan	    fi
11376f7ec340bSmacallan	  fi
11377f7ec340bSmacallan	fi
11378f7ec340bSmacallan	;;
11379f7ec340bSmacallan      esac
113802a75d1c4Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381f7ec340bSmacallan    done
11382f7ec340bSmacallan
1138366ab3337Smrg    # Try to remove the $objdir's in the directories where we deleted files
11384f7ec340bSmacallan    for dir in $rmdirs; do
11385f7ec340bSmacallan      if test -d "$dir"; then
113862a75d1c4Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387f7ec340bSmacallan      fi
11388f7ec340bSmacallan    done
11389f7ec340bSmacallan
11390f7ec340bSmacallan    exit $exit_status
113912a75d1c4Smrg}
11392f7ec340bSmacallan
1139366ab3337Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
1139466ab3337Smrg  func_mode_uninstall ${1+"$@"}
1139566ab3337Smrgfi
11396f7ec340bSmacallan
113972a75d1c4Smrgtest -z "$opt_mode" && {
1139866ab3337Smrg  help=$generic_help
113992a75d1c4Smrg  func_fatal_help "you must specify a MODE"
114002a75d1c4Smrg}
114012a75d1c4Smrg
114022a75d1c4Smrgtest -z "$exec_cmd" && \
1140366ab3337Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404f7ec340bSmacallan
11405f7ec340bSmacallanif test -n "$exec_cmd"; then
114062a75d1c4Smrg  eval exec "$exec_cmd"
11407f7ec340bSmacallan  exit $EXIT_FAILURE
11408f7ec340bSmacallanfi
11409f7ec340bSmacallan
114102a75d1c4Smrgexit $exit_status
11411f7ec340bSmacallan
11412f7ec340bSmacallan
11413f7ec340bSmacallan# The TAGs below are defined such that we never get into a situation
1141466ab3337Smrg# where we disable both kinds of libraries.  Given conflicting
11415f7ec340bSmacallan# choices, we go for a static library, that is the most portable,
11416f7ec340bSmacallan# since we can't tell whether shared libraries were disabled because
11417f7ec340bSmacallan# the user asked for that or because the platform doesn't support
11418f7ec340bSmacallan# them.  This is particularly important on AIX, because we don't
11419f7ec340bSmacallan# support having both static and shared libraries enabled at the same
11420f7ec340bSmacallan# time on that platform, so we default to a shared-only configuration.
11421f7ec340bSmacallan# If a disable-shared tag is given, we'll fallback to a static-only
11422f7ec340bSmacallan# configuration.  But we'll never go from static-only to shared-only.
11423f7ec340bSmacallan
11424f7ec340bSmacallan# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
114252a75d1c4Smrgbuild_libtool_libs=no
114262a75d1c4Smrgbuild_old_libs=yes
11427f7ec340bSmacallan# ### END LIBTOOL TAG CONFIG: disable-shared
11428f7ec340bSmacallan
11429f7ec340bSmacallan# ### BEGIN LIBTOOL TAG CONFIG: disable-static
114302a75d1c4Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431f7ec340bSmacallan# ### END LIBTOOL TAG CONFIG: disable-static
11432f7ec340bSmacallan
11433f7ec340bSmacallan# Local Variables:
11434f7ec340bSmacallan# mode:shell-script
11435f7ec340bSmacallan# sh-indentation:2
11436f7ec340bSmacallan# End:
11437