ltmain.sh revision efbcb2bf
15b16253fSmrg#! /usr/bin/env sh
25ec34c4cSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
35b16253fSmrg##               by inline-source v2019-02-19.15
4994689c1Smrg
55b16253fSmrg# libtool (GNU libtool) 2.4.7
65ec34c4cSmrg# Provide generalized library-building support services.
7994689c1Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8994689c1Smrg
95b16253fSmrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10994689c1Smrg# This is free software; see the source for copying conditions.  There is NO
11994689c1Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12994689c1Smrg
13994689c1Smrg# GNU Libtool is free software; you can redistribute it and/or modify
147a84e134Smrg# it under the terms of the GNU General Public License as published by
157a84e134Smrg# the Free Software Foundation; either version 2 of the License, or
167a84e134Smrg# (at your option) any later version.
177a84e134Smrg#
18994689c1Smrg# As a special exception to the GNU General Public License,
19994689c1Smrg# if you distribute this file as part of a program or library that
20994689c1Smrg# is built using GNU Libtool, you may include this file under the
21994689c1Smrg# same distribution terms that you use for the rest of that program.
22994689c1Smrg#
23994689c1Smrg# GNU Libtool is distributed in the hope that it will be useful, but
247a84e134Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
257a84e134Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
267a84e134Smrg# General Public License for more details.
277a84e134Smrg#
287a84e134Smrg# You should have received a copy of the GNU General Public License
295ec34c4cSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30e1e1713cSmrg
317a84e134Smrg
32994689c1SmrgPROGRAM=libtool
337a84e134SmrgPACKAGE=libtool
34efbcb2bfSmrgVERSION="2.4.7 Debian-2.4.7-5"
355b16253fSmrgpackage_revision=2.4.7
36ab902922Smrg
375ec34c4cSmrg
385ec34c4cSmrg## ------ ##
395ec34c4cSmrg## Usage. ##
405ec34c4cSmrg## ------ ##
415ec34c4cSmrg
425ec34c4cSmrg# Run './libtool --help' for help with using this script from the
435ec34c4cSmrg# command line.
445ec34c4cSmrg
455ec34c4cSmrg
465ec34c4cSmrg## ------------------------------- ##
475ec34c4cSmrg## User overridable command paths. ##
485ec34c4cSmrg## ------------------------------- ##
495ec34c4cSmrg
505ec34c4cSmrg# After configure completes, it has a better idea of some of the
515ec34c4cSmrg# shell tools we need than the defaults used by the functions shared
525ec34c4cSmrg# with bootstrap, so set those here where they can still be over-
535ec34c4cSmrg# ridden by the user, but otherwise take precedence.
545ec34c4cSmrg
555ec34c4cSmrg: ${AUTOCONF="autoconf"}
565ec34c4cSmrg: ${AUTOMAKE="automake"}
575ec34c4cSmrg
585ec34c4cSmrg
595ec34c4cSmrg## -------------------------- ##
605ec34c4cSmrg## Source external libraries. ##
615ec34c4cSmrg## -------------------------- ##
625ec34c4cSmrg
635ec34c4cSmrg# Much of our low-level functionality needs to be sourced from external
645ec34c4cSmrg# libraries, which are installed to $pkgauxdir.
655ec34c4cSmrg
665ec34c4cSmrg# Set a version string for this script.
675b16253fSmrgscriptversion=2019-02-19.15; # UTC
685ec34c4cSmrg
695ec34c4cSmrg# General shell script boiler plate, and helper functions.
705ec34c4cSmrg# Written by Gary V. Vaughan, 2004
715ec34c4cSmrg
725b16253fSmrg# This is free software.  There is NO warranty; not even for
735b16253fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
745b16253fSmrg#
755b16253fSmrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
765b16253fSmrg#
775b16253fSmrg# This file is dual licensed under the terms of the MIT license
785b16253fSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
795b16253fSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
805b16253fSmrg# these licenses when using or redistributing this software or any of
815b16253fSmrg# the files within it.  See the URLs above, or the file `LICENSE`
825b16253fSmrg# included in the Bootstrap distribution for the full license texts.
835ec34c4cSmrg
845b16253fSmrg# Please report bugs or propose patches to:
855b16253fSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
865ec34c4cSmrg
875ec34c4cSmrg
885ec34c4cSmrg## ------ ##
895ec34c4cSmrg## Usage. ##
905ec34c4cSmrg## ------ ##
915ec34c4cSmrg
925ec34c4cSmrg# Evaluate this file near the top of your script to gain access to
935ec34c4cSmrg# the functions and variables defined here:
945ec34c4cSmrg#
955ec34c4cSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
965ec34c4cSmrg#
975ec34c4cSmrg# If you need to override any of the default environment variable
985ec34c4cSmrg# settings, do that before evaluating this file.
995ec34c4cSmrg
1005ec34c4cSmrg
1015ec34c4cSmrg## -------------------- ##
1025ec34c4cSmrg## Shell normalisation. ##
1035ec34c4cSmrg## -------------------- ##
1045ec34c4cSmrg
1055ec34c4cSmrg# Some shells need a little help to be as Bourne compatible as possible.
1065ec34c4cSmrg# Before doing anything else, make sure all that help has been provided!
1075ec34c4cSmrg
1085ec34c4cSmrgDUALCASE=1; export DUALCASE # for MKS sh
1095ec34c4cSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110ab902922Smrg  emulate sh
111ab902922Smrg  NULLCMD=:
1125ec34c4cSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113ab902922Smrg  # is contrary to our usage.  Disable this feature.
114ab902922Smrg  alias -g '${1+"$@"}'='"$@"'
1157a84e134Smrg  setopt NO_GLOB_SUBST
116ab902922Smrgelse
1175ec34c4cSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1187a84e134Smrgfi
119e1e1713cSmrg
1205ec34c4cSmrg# NLS nuisances: We save the old values in case they are required later.
1215ec34c4cSmrg_G_user_locale=
1225ec34c4cSmrg_G_safe_locale=
1235ec34c4cSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124ab902922Smrgdo
1255ec34c4cSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1265ec34c4cSmrg          save_$_G_var=\$$_G_var
1275ec34c4cSmrg          $_G_var=C
1285ec34c4cSmrg	  export $_G_var
1295ec34c4cSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1305ec34c4cSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131ab902922Smrg	fi"
132ab902922Smrgdone
1335b16253fSmrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1345b16253fSmrg# in case the environment reset is needed later and the $save_* variant is not
1355b16253fSmrg# defined (see the code above).
1365b16253fSmrgLC_ALL=C
1375b16253fSmrgLANGUAGE=C
1385b16253fSmrgexport LANGUAGE LC_ALL
139994689c1Smrg
1405ec34c4cSmrg# Make sure IFS has a sensible default
1415ec34c4cSmrgsp=' '
1425ec34c4cSmrgnl='
1435ec34c4cSmrg'
1445ec34c4cSmrgIFS="$sp	$nl"
1455ec34c4cSmrg
1465ec34c4cSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1475ec34c4cSmrgif test "${PATH_SEPARATOR+set}" != set; then
1485ec34c4cSmrg  PATH_SEPARATOR=:
1495ec34c4cSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1505ec34c4cSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1515ec34c4cSmrg      PATH_SEPARATOR=';'
1525ec34c4cSmrg  }
1535ec34c4cSmrgfi
154994689c1Smrg
155994689c1Smrg
1565b16253fSmrg# func_unset VAR
1575b16253fSmrg# --------------
1585b16253fSmrg# Portably unset VAR.
1595b16253fSmrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1605b16253fSmrg# status if VAR is already unset, which might be problematic if the
1615b16253fSmrg# statement is used at the end of a function (thus poisoning its return
1625b16253fSmrg# value) or when 'set -e' is active (causing even a spurious abort of
1635b16253fSmrg# the script in this case).
1645b16253fSmrgfunc_unset ()
1655b16253fSmrg{
1665b16253fSmrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1675b16253fSmrg}
1685b16253fSmrg
1695b16253fSmrg
1705b16253fSmrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1715b16253fSmrgfunc_unset CDPATH
1725b16253fSmrg
1735b16253fSmrg# Make sure ${,E,F}GREP behave sanely.
1745b16253fSmrgfunc_unset GREP_OPTIONS
1755b16253fSmrg
176994689c1Smrg
1775ec34c4cSmrg## ------------------------- ##
1785ec34c4cSmrg## Locate command utilities. ##
1795ec34c4cSmrg## ------------------------- ##
1805ec34c4cSmrg
1815ec34c4cSmrg
1825ec34c4cSmrg# func_executable_p FILE
1835ec34c4cSmrg# ----------------------
1845ec34c4cSmrg# Check that FILE is an executable regular file.
1855ec34c4cSmrgfunc_executable_p ()
1865ec34c4cSmrg{
1875ec34c4cSmrg    test -f "$1" && test -x "$1"
1885ec34c4cSmrg}
1895ec34c4cSmrg
1905ec34c4cSmrg
1915ec34c4cSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1925ec34c4cSmrg# --------------------------------------------
1935ec34c4cSmrg# Search for either a program that responds to --version with output
1945ec34c4cSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1955ec34c4cSmrg# trying all the directories in PATH with each of the elements of
1965ec34c4cSmrg# PROGS_LIST.
1975ec34c4cSmrg#
1985ec34c4cSmrg# CHECK_FUNC should accept the path to a candidate program, and
1995ec34c4cSmrg# set $func_check_prog_result if it truncates its output less than
2005ec34c4cSmrg# $_G_path_prog_max characters.
2015ec34c4cSmrgfunc_path_progs ()
2025ec34c4cSmrg{
2035ec34c4cSmrg    _G_progs_list=$1
2045ec34c4cSmrg    _G_check_func=$2
2055ec34c4cSmrg    _G_PATH=${3-"$PATH"}
2065ec34c4cSmrg
2075ec34c4cSmrg    _G_path_prog_max=0
2085ec34c4cSmrg    _G_path_prog_found=false
2095ec34c4cSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
2105ec34c4cSmrg    for _G_dir in $_G_PATH; do
2115ec34c4cSmrg      IFS=$_G_save_IFS
2125ec34c4cSmrg      test -z "$_G_dir" && _G_dir=.
2135ec34c4cSmrg      for _G_prog_name in $_G_progs_list; do
2145ec34c4cSmrg        for _exeext in '' .EXE; do
2155ec34c4cSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2165ec34c4cSmrg          func_executable_p "$_G_path_prog" || continue
2175ec34c4cSmrg          case `"$_G_path_prog" --version 2>&1` in
2185ec34c4cSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2195ec34c4cSmrg            *)     $_G_check_func $_G_path_prog
2205ec34c4cSmrg		   func_path_progs_result=$func_check_prog_result
2215ec34c4cSmrg		   ;;
2225ec34c4cSmrg          esac
2235ec34c4cSmrg          $_G_path_prog_found && break 3
2245ec34c4cSmrg        done
2255ec34c4cSmrg      done
2265ec34c4cSmrg    done
2275ec34c4cSmrg    IFS=$_G_save_IFS
2285ec34c4cSmrg    test -z "$func_path_progs_result" && {
2295ec34c4cSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2305ec34c4cSmrg      exit 1
2315ec34c4cSmrg    }
2325ec34c4cSmrg}
2335ec34c4cSmrg
2345ec34c4cSmrg
2355ec34c4cSmrg# We want to be able to use the functions in this file before configure
2365ec34c4cSmrg# has figured out where the best binaries are kept, which means we have
2375ec34c4cSmrg# to search for them ourselves - except when the results are already set
2385ec34c4cSmrg# where we skip the searches.
2395ec34c4cSmrg
2405ec34c4cSmrg# Unless the user overrides by setting SED, search the path for either GNU
2415ec34c4cSmrg# sed, or the sed that truncates its output the least.
2425ec34c4cSmrgtest -z "$SED" && {
2435ec34c4cSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2445ec34c4cSmrg  for _G_i in 1 2 3 4 5 6 7; do
2455ec34c4cSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2465ec34c4cSmrg  done
2475ec34c4cSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2485ec34c4cSmrg  _G_sed_script=
2495ec34c4cSmrg
2505ec34c4cSmrg  func_check_prog_sed ()
2515ec34c4cSmrg  {
2525ec34c4cSmrg    _G_path_prog=$1
2535ec34c4cSmrg
2545ec34c4cSmrg    _G_count=0
2555ec34c4cSmrg    printf 0123456789 >conftest.in
2565ec34c4cSmrg    while :
2575ec34c4cSmrg    do
2585ec34c4cSmrg      cat conftest.in conftest.in >conftest.tmp
2595ec34c4cSmrg      mv conftest.tmp conftest.in
2605ec34c4cSmrg      cp conftest.in conftest.nl
2615ec34c4cSmrg      echo '' >> conftest.nl
2625ec34c4cSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2635ec34c4cSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2645ec34c4cSmrg      _G_count=`expr $_G_count + 1`
2655ec34c4cSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2665ec34c4cSmrg        # Best one so far, save it but keep looking for a better one
2675ec34c4cSmrg        func_check_prog_result=$_G_path_prog
2685ec34c4cSmrg        _G_path_prog_max=$_G_count
2695ec34c4cSmrg      fi
2705ec34c4cSmrg      # 10*(2^10) chars as input seems more than enough
2715ec34c4cSmrg      test 10 -lt "$_G_count" && break
2725ec34c4cSmrg    done
2735ec34c4cSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2745ec34c4cSmrg  }
2755ec34c4cSmrg
2765b16253fSmrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
2775ec34c4cSmrg  rm -f conftest.sed
2785ec34c4cSmrg  SED=$func_path_progs_result
2795ec34c4cSmrg}
2805ec34c4cSmrg
2815ec34c4cSmrg
2825ec34c4cSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2835ec34c4cSmrg# grep, or the grep that truncates its output the least.
2845ec34c4cSmrgtest -z "$GREP" && {
2855ec34c4cSmrg  func_check_prog_grep ()
2865ec34c4cSmrg  {
2875ec34c4cSmrg    _G_path_prog=$1
2885ec34c4cSmrg
2895ec34c4cSmrg    _G_count=0
2905ec34c4cSmrg    _G_path_prog_max=0
2915ec34c4cSmrg    printf 0123456789 >conftest.in
2925ec34c4cSmrg    while :
2935ec34c4cSmrg    do
2945ec34c4cSmrg      cat conftest.in conftest.in >conftest.tmp
2955ec34c4cSmrg      mv conftest.tmp conftest.in
2965ec34c4cSmrg      cp conftest.in conftest.nl
2975ec34c4cSmrg      echo 'GREP' >> conftest.nl
2985ec34c4cSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2995ec34c4cSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
3005ec34c4cSmrg      _G_count=`expr $_G_count + 1`
3015ec34c4cSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
3025ec34c4cSmrg        # Best one so far, save it but keep looking for a better one
3035ec34c4cSmrg        func_check_prog_result=$_G_path_prog
3045ec34c4cSmrg        _G_path_prog_max=$_G_count
3055ec34c4cSmrg      fi
3065ec34c4cSmrg      # 10*(2^10) chars as input seems more than enough
3075ec34c4cSmrg      test 10 -lt "$_G_count" && break
3085ec34c4cSmrg    done
3095ec34c4cSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
3105ec34c4cSmrg  }
3115ec34c4cSmrg
3125b16253fSmrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
3135ec34c4cSmrg  GREP=$func_path_progs_result
3145ec34c4cSmrg}
3155ec34c4cSmrg
3165ec34c4cSmrg
3175ec34c4cSmrg## ------------------------------- ##
3185ec34c4cSmrg## User overridable command paths. ##
3195ec34c4cSmrg## ------------------------------- ##
3205ec34c4cSmrg
3215ec34c4cSmrg# All uppercase variable names are used for environment variables.  These
3225ec34c4cSmrg# variables can be overridden by the user before calling a script that
3235ec34c4cSmrg# uses them if a suitable command of that name is not already available
3245ec34c4cSmrg# in the command search PATH.
325994689c1Smrg
326994689c1Smrg: ${CP="cp -f"}
3275ec34c4cSmrg: ${ECHO="printf %s\n"}
3285ec34c4cSmrg: ${EGREP="$GREP -E"}
3295ec34c4cSmrg: ${FGREP="$GREP -F"}
3305ec34c4cSmrg: ${LN_S="ln -s"}
331994689c1Smrg: ${MAKE="make"}
332994689c1Smrg: ${MKDIR="mkdir"}
333994689c1Smrg: ${MV="mv -f"}
334994689c1Smrg: ${RM="rm -f"}
335994689c1Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3367a84e134Smrg
337994689c1Smrg
3385ec34c4cSmrg## -------------------- ##
3395ec34c4cSmrg## Useful sed snippets. ##
3405ec34c4cSmrg## -------------------- ##
341f353fbadSmrg
3425ec34c4cSmrgsed_dirname='s|/[^/]*$||'
3435ec34c4cSmrgsed_basename='s|^.*/||'
344f353fbadSmrg
3455ec34c4cSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3465ec34c4cSmrg# metacharacters that are still active within double-quoted strings.
3475ec34c4cSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348f353fbadSmrg
3495ec34c4cSmrg# Same as above, but do not quote variable references.
3505ec34c4cSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351f353fbadSmrg
3525ec34c4cSmrg# Sed substitution that turns a string into a regex matching for the
3535ec34c4cSmrg# string literally.
3545ec34c4cSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355f353fbadSmrg
3565ec34c4cSmrg# Sed substitution that converts a w32 file name or path
3575ec34c4cSmrg# that contains forward slashes, into one that contains
3585ec34c4cSmrg# (escaped) backslashes.  A very naive implementation.
3595ec34c4cSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3605ec34c4cSmrg
3615ec34c4cSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3625ec34c4cSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3635ec34c4cSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3645ec34c4cSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3655ec34c4cSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3665ec34c4cSmrg_G_bs='\\'
3675ec34c4cSmrg_G_bs2='\\\\'
3685ec34c4cSmrg_G_bs4='\\\\\\\\'
3695ec34c4cSmrg_G_dollar='\$'
3705ec34c4cSmrgsed_double_backslash="\
3715ec34c4cSmrg  s/$_G_bs4/&\\
3725ec34c4cSmrg/g
3735ec34c4cSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3745ec34c4cSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3755ec34c4cSmrg  s/\n//g"
376f353fbadSmrg
3775b16253fSmrg# require_check_ifs_backslash
3785b16253fSmrg# ---------------------------
3795b16253fSmrg# Check if we can use backslash as IFS='\' separator, and set
3805b16253fSmrg# $check_ifs_backshlash_broken to ':' or 'false'.
3815b16253fSmrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3825b16253fSmrgfunc_require_check_ifs_backslash ()
3835b16253fSmrg{
3845b16253fSmrg  _G_save_IFS=$IFS
3855b16253fSmrg  IFS='\'
3865b16253fSmrg  _G_check_ifs_backshlash='a\\b'
3875b16253fSmrg  for _G_i in $_G_check_ifs_backshlash
3885b16253fSmrg  do
3895b16253fSmrg  case $_G_i in
3905b16253fSmrg  a)
3915b16253fSmrg    check_ifs_backshlash_broken=false
3925b16253fSmrg    ;;
3935b16253fSmrg  '')
3945b16253fSmrg    break
3955b16253fSmrg    ;;
3965b16253fSmrg  *)
3975b16253fSmrg    check_ifs_backshlash_broken=:
3985b16253fSmrg    break
3995b16253fSmrg    ;;
4005b16253fSmrg  esac
4015b16253fSmrg  done
4025b16253fSmrg  IFS=$_G_save_IFS
4035b16253fSmrg  require_check_ifs_backslash=:
4045b16253fSmrg}
4055b16253fSmrg
406775e7de9Smrg
4075ec34c4cSmrg## ----------------- ##
4085ec34c4cSmrg## Global variables. ##
4095ec34c4cSmrg## ----------------- ##
410994689c1Smrg
4115ec34c4cSmrg# Except for the global variables explicitly listed below, the following
4125ec34c4cSmrg# functions in the '^func_' namespace, and the '^require_' namespace
4135ec34c4cSmrg# variables initialised in the 'Resource management' section, sourcing
4145ec34c4cSmrg# this file will not pollute your global namespace with anything
4155ec34c4cSmrg# else. There's no portable way to scope variables in Bourne shell
4165ec34c4cSmrg# though, so actually running these functions will sometimes place
4175ec34c4cSmrg# results into a variable named after the function, and often use
4185ec34c4cSmrg# temporary variables in the '^_G_' namespace. If you are careful to
4195ec34c4cSmrg# avoid using those namespaces casually in your sourcing script, things
4205ec34c4cSmrg# should continue to work as you expect. And, of course, you can freely
4215ec34c4cSmrg# overwrite any of the functions or variables defined here before
4225ec34c4cSmrg# calling anything to customize them.
423994689c1Smrg
4245ec34c4cSmrgEXIT_SUCCESS=0
4255ec34c4cSmrgEXIT_FAILURE=1
4265ec34c4cSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
4275ec34c4cSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428994689c1Smrg
4295ec34c4cSmrg# Allow overriding, eg assuming that you follow the convention of
4305ec34c4cSmrg# putting '$debug_cmd' at the start of all your functions, you can get
4315ec34c4cSmrg# bash to show function call trace with:
4325ec34c4cSmrg#
433efbcb2bfSmrg#    debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
4345ec34c4cSmrgdebug_cmd=${debug_cmd-":"}
4355ec34c4cSmrgexit_cmd=:
436994689c1Smrg
4375ec34c4cSmrg# By convention, finish your script with:
4385ec34c4cSmrg#
4395ec34c4cSmrg#    exit $exit_status
4405ec34c4cSmrg#
4415ec34c4cSmrg# so that you can set exit_status to non-zero if you want to indicate
4425ec34c4cSmrg# something went wrong during execution without actually bailing out at
4435ec34c4cSmrg# the point of failure.
4445ec34c4cSmrgexit_status=$EXIT_SUCCESS
445994689c1Smrg
4465ec34c4cSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4475ec34c4cSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4485ec34c4cSmrg# the _XPG environment variable is not equal to 1 (one), the special
4495ec34c4cSmrg# positional parameter $0, within a function call, is the name of the
4505ec34c4cSmrg# function.
4515ec34c4cSmrgprogpath=$0
452994689c1Smrg
4535ec34c4cSmrg# The name of this program.
4545ec34c4cSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455994689c1Smrg
4565ec34c4cSmrg# Make sure we have an absolute progpath for reexecution:
457994689c1Smrgcase $progpath in
458994689c1Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459994689c1Smrg  *[\\/]*)
4605ec34c4cSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461994689c1Smrg     progdir=`cd "$progdir" && pwd`
4625ec34c4cSmrg     progpath=$progdir/$progname
463994689c1Smrg     ;;
464994689c1Smrg  *)
4655ec34c4cSmrg     _G_IFS=$IFS
466421c997bSmrg     IFS=${PATH_SEPARATOR-:}
467994689c1Smrg     for progdir in $PATH; do
4685ec34c4cSmrg       IFS=$_G_IFS
469994689c1Smrg       test -x "$progdir/$progname" && break
470994689c1Smrg     done
4715ec34c4cSmrg     IFS=$_G_IFS
472994689c1Smrg     test -n "$progdir" || progdir=`pwd`
4735ec34c4cSmrg     progpath=$progdir/$progname
474994689c1Smrg     ;;
475994689c1Smrgesac
476994689c1Smrg
477994689c1Smrg
4785ec34c4cSmrg## ----------------- ##
4795ec34c4cSmrg## Standard options. ##
4805ec34c4cSmrg## ----------------- ##
481f353fbadSmrg
4825ec34c4cSmrg# The following options affect the operation of the functions defined
4835ec34c4cSmrg# below, and should be set appropriately depending on run-time para-
4845ec34c4cSmrg# meters passed on the command line.
485994689c1Smrg
486994689c1Smrgopt_dry_run=false
487994689c1Smrgopt_quiet=false
488994689c1Smrgopt_verbose=false
489994689c1Smrg
4905ec34c4cSmrg# Categories 'all' and 'none' are always available.  Append any others
4915ec34c4cSmrg# you will pass as the first argument to func_warning from your own
4925ec34c4cSmrg# code.
4935ec34c4cSmrgwarning_categories=
494994689c1Smrg
4955ec34c4cSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4965ec34c4cSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4975ec34c4cSmrg# treat the next displayed warning as a fatal error.
4985ec34c4cSmrgwarning_func=func_warn_and_continue
499994689c1Smrg
5005ec34c4cSmrg# Set to 'all' to display all warnings, 'none' to suppress all
5015ec34c4cSmrg# warnings, or a space delimited list of some subset of
5025ec34c4cSmrg# 'warning_categories' to display only the listed warnings.
5035ec34c4cSmrgopt_warning_types=all
504994689c1Smrg
505994689c1Smrg
5065ec34c4cSmrg## -------------------- ##
5075ec34c4cSmrg## Resource management. ##
5085ec34c4cSmrg## -------------------- ##
509994689c1Smrg
5105ec34c4cSmrg# This section contains definitions for functions that each ensure a
5115ec34c4cSmrg# particular resource (a file, or a non-empty configuration variable for
5125ec34c4cSmrg# example) is available, and if appropriate to extract default values
5135ec34c4cSmrg# from pertinent package files. Call them using their associated
5145ec34c4cSmrg# 'require_*' variable to ensure that they are executed, at most, once.
5155ec34c4cSmrg#
5165ec34c4cSmrg# It's entirely deliberate that calling these functions can set
5175ec34c4cSmrg# variables that don't obey the namespace limitations obeyed by the rest
5185ec34c4cSmrg# of this file, in order that that they be as useful as possible to
5195ec34c4cSmrg# callers.
520994689c1Smrg
521994689c1Smrg
5225ec34c4cSmrg# require_term_colors
5235ec34c4cSmrg# -------------------
5245ec34c4cSmrg# Allow display of bold text on terminals that support it.
5255ec34c4cSmrgrequire_term_colors=func_require_term_colors
5265ec34c4cSmrgfunc_require_term_colors ()
527994689c1Smrg{
5285ec34c4cSmrg    $debug_cmd
5295ec34c4cSmrg
5305ec34c4cSmrg    test -t 1 && {
5315ec34c4cSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
5325ec34c4cSmrg      # precedence, because most terminfo databases neglect to describe
5335ec34c4cSmrg      # whether color sequences are supported.
5345ec34c4cSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
5355ec34c4cSmrg
5365ec34c4cSmrg      if test 1 = "$USE_ANSI_COLORS"; then
5375ec34c4cSmrg        # Standard ANSI escape sequences
5385ec34c4cSmrg        tc_reset='[0m'
5395ec34c4cSmrg        tc_bold='[1m';   tc_standout='[7m'
5405ec34c4cSmrg        tc_red='[31m';   tc_green='[32m'
5415ec34c4cSmrg        tc_blue='[34m';  tc_cyan='[36m'
5425ec34c4cSmrg      else
5435ec34c4cSmrg        # Otherwise trust the terminfo database after all.
5445ec34c4cSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5455ec34c4cSmrg          tc_reset=`tput sgr0`
5465ec34c4cSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5475ec34c4cSmrg          tc_standout=$tc_bold
5485ec34c4cSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5495ec34c4cSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5505ec34c4cSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5515ec34c4cSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5525ec34c4cSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5535ec34c4cSmrg        }
5545ec34c4cSmrg      fi
5555ec34c4cSmrg    }
556994689c1Smrg
5575ec34c4cSmrg    require_term_colors=:
558994689c1Smrg}
559994689c1Smrg
560994689c1Smrg
5615ec34c4cSmrg## ----------------- ##
5625ec34c4cSmrg## Function library. ##
5635ec34c4cSmrg## ----------------- ##
5645ec34c4cSmrg
5655ec34c4cSmrg# This section contains a variety of useful functions to call in your
5665ec34c4cSmrg# scripts. Take note of the portable wrappers for features provided by
5675ec34c4cSmrg# some modern shells, which will fall back to slower equivalents on
5685ec34c4cSmrg# less featureful shells.
5695ec34c4cSmrg
5705ec34c4cSmrg
5715ec34c4cSmrg# func_append VAR VALUE
5725ec34c4cSmrg# ---------------------
5735ec34c4cSmrg# Append VALUE onto the existing contents of VAR.
5745ec34c4cSmrg
5755ec34c4cSmrg  # We should try to minimise forks, especially on Windows where they are
5765ec34c4cSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5775ec34c4cSmrg  # being used:
5785ec34c4cSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5795ec34c4cSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5805ec34c4cSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5815ec34c4cSmrg    # The += operator was introduced in bash 3.1
5825ec34c4cSmrg    case $BASH_VERSION in
5835ec34c4cSmrg      [12].* | 3.0 | 3.0*) ;;
5845ec34c4cSmrg      *)
5855ec34c4cSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5865ec34c4cSmrg        ;;
5875ec34c4cSmrg    esac
5885ec34c4cSmrg  fi
5895ec34c4cSmrg
5905ec34c4cSmrg  # _G_HAVE_PLUSEQ_OP
5915ec34c4cSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5925ec34c4cSmrg  # useable or anything else if it does not work.
5935ec34c4cSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5945ec34c4cSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5955ec34c4cSmrg    && _G_HAVE_PLUSEQ_OP=yes
5965ec34c4cSmrg
5975ec34c4cSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5985ec34c4cSmrgthen
5995ec34c4cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
6005ec34c4cSmrg  eval 'func_append ()
6015ec34c4cSmrg  {
6025ec34c4cSmrg    $debug_cmd
6035ec34c4cSmrg
6045ec34c4cSmrg    eval "$1+=\$2"
6055ec34c4cSmrg  }'
6065ec34c4cSmrgelse
6075ec34c4cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
6085ec34c4cSmrg  func_append ()
6095ec34c4cSmrg  {
6105ec34c4cSmrg    $debug_cmd
6115ec34c4cSmrg
6125ec34c4cSmrg    eval "$1=\$$1\$2"
6135ec34c4cSmrg  }
6145ec34c4cSmrgfi
6155ec34c4cSmrg
6165ec34c4cSmrg
6175ec34c4cSmrg# func_append_quoted VAR VALUE
6185ec34c4cSmrg# ----------------------------
6195ec34c4cSmrg# Quote VALUE and append to the end of shell variable VAR, separated
6205ec34c4cSmrg# by a space.
6215ec34c4cSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
6225ec34c4cSmrg  eval 'func_append_quoted ()
6235ec34c4cSmrg  {
6245ec34c4cSmrg    $debug_cmd
6255ec34c4cSmrg
6265b16253fSmrg    func_quote_arg pretty "$2"
6275b16253fSmrg    eval "$1+=\\ \$func_quote_arg_result"
6285ec34c4cSmrg  }'
6295ec34c4cSmrgelse
6305ec34c4cSmrg  func_append_quoted ()
6315ec34c4cSmrg  {
6325ec34c4cSmrg    $debug_cmd
6335ec34c4cSmrg
6345b16253fSmrg    func_quote_arg pretty "$2"
6355b16253fSmrg    eval "$1=\$$1\\ \$func_quote_arg_result"
6365ec34c4cSmrg  }
6375ec34c4cSmrgfi
6385ec34c4cSmrg
6395ec34c4cSmrg
6405ec34c4cSmrg# func_append_uniq VAR VALUE
6415ec34c4cSmrg# --------------------------
6425ec34c4cSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6435ec34c4cSmrg# entries are delimited by the first character of VALUE.  For example:
6445ec34c4cSmrg#
6455ec34c4cSmrg#   func_append_uniq options " --another-option option-argument"
6465ec34c4cSmrg#
6475ec34c4cSmrg# will only append to $options if " --another-option option-argument "
6485ec34c4cSmrg# is not already present somewhere in $options already (note spaces at
6495ec34c4cSmrg# each end implied by leading space in second argument).
6505ec34c4cSmrgfunc_append_uniq ()
6515ec34c4cSmrg{
6525ec34c4cSmrg    $debug_cmd
6535ec34c4cSmrg
6545ec34c4cSmrg    eval _G_current_value='`$ECHO $'$1'`'
6555ec34c4cSmrg    _G_delim=`expr "$2" : '\(.\)'`
6565ec34c4cSmrg
6575ec34c4cSmrg    case $_G_delim$_G_current_value$_G_delim in
6585ec34c4cSmrg      *"$2$_G_delim"*) ;;
6595ec34c4cSmrg      *) func_append "$@" ;;
6605ec34c4cSmrg    esac
6615ec34c4cSmrg}
6625ec34c4cSmrg
6635ec34c4cSmrg
6645ec34c4cSmrg# func_arith TERM...
6655ec34c4cSmrg# ------------------
6665ec34c4cSmrg# Set func_arith_result to the result of evaluating TERMs.
6675ec34c4cSmrg  test -z "$_G_HAVE_ARITH_OP" \
6685ec34c4cSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6695ec34c4cSmrg    && _G_HAVE_ARITH_OP=yes
6705ec34c4cSmrg
6715ec34c4cSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6725ec34c4cSmrg  eval 'func_arith ()
6735ec34c4cSmrg  {
6745ec34c4cSmrg    $debug_cmd
6755ec34c4cSmrg
6765ec34c4cSmrg    func_arith_result=$(( $* ))
6775ec34c4cSmrg  }'
6785ec34c4cSmrgelse
6795ec34c4cSmrg  func_arith ()
6805ec34c4cSmrg  {
6815ec34c4cSmrg    $debug_cmd
6825ec34c4cSmrg
6835ec34c4cSmrg    func_arith_result=`expr "$@"`
6845ec34c4cSmrg  }
6855ec34c4cSmrgfi
6865ec34c4cSmrg
6875ec34c4cSmrg
6885ec34c4cSmrg# func_basename FILE
6895ec34c4cSmrg# ------------------
6905ec34c4cSmrg# Set func_basename_result to FILE with everything up to and including
6915ec34c4cSmrg# the last / stripped.
6925ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6935ec34c4cSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6945ec34c4cSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6955ec34c4cSmrg  # on unsupported syntax...
6965ec34c4cSmrg  _b='func_basename_result=${1##*/}'
6975ec34c4cSmrg  _d='case $1 in
6985ec34c4cSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6995ec34c4cSmrg        *  ) func_dirname_result=$3        ;;
7005ec34c4cSmrg      esac'
7015ec34c4cSmrg
7025ec34c4cSmrgelse
7035ec34c4cSmrg  # ...otherwise fall back to using sed.
7045ec34c4cSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
7055ec34c4cSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
7065ec34c4cSmrg      if test "X$func_dirname_result" = "X$1"; then
7075ec34c4cSmrg        func_dirname_result=$3
7085ec34c4cSmrg      else
7095ec34c4cSmrg        func_append func_dirname_result "$2"
7105ec34c4cSmrg      fi'
7115ec34c4cSmrgfi
7125ec34c4cSmrg
7135ec34c4cSmrgeval 'func_basename ()
7145ec34c4cSmrg{
7155ec34c4cSmrg    $debug_cmd
7165ec34c4cSmrg
7175ec34c4cSmrg    '"$_b"'
7185ec34c4cSmrg}'
7195ec34c4cSmrg
7205ec34c4cSmrg
7215ec34c4cSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
7225ec34c4cSmrg# -------------------------------------------
7235ec34c4cSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
7245ec34c4cSmrg# otherwise set result to NONDIR_REPLACEMENT.
7255ec34c4cSmrgeval 'func_dirname ()
7265ec34c4cSmrg{
7275ec34c4cSmrg    $debug_cmd
7285ec34c4cSmrg
7295ec34c4cSmrg    '"$_d"'
7305ec34c4cSmrg}'
7315ec34c4cSmrg
7325ec34c4cSmrg
7335ec34c4cSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
7345ec34c4cSmrg# --------------------------------------------------------
7355ec34c4cSmrg# Perform func_basename and func_dirname in a single function
7365ec34c4cSmrg# call:
7375ec34c4cSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
7385ec34c4cSmrg#             add APPEND to the result, otherwise set result
7395ec34c4cSmrg#             to NONDIR_REPLACEMENT.
7405ec34c4cSmrg#             value returned in "$func_dirname_result"
7415ec34c4cSmrg#   basename: Compute filename of FILE.
7425ec34c4cSmrg#             value retuned in "$func_basename_result"
7435ec34c4cSmrg# For efficiency, we do not delegate to the functions above but instead
7445ec34c4cSmrg# duplicate the functionality here.
7455ec34c4cSmrgeval 'func_dirname_and_basename ()
7465ec34c4cSmrg{
7475ec34c4cSmrg    $debug_cmd
7485ec34c4cSmrg
7495ec34c4cSmrg    '"$_b"'
7505ec34c4cSmrg    '"$_d"'
7515ec34c4cSmrg}'
7525ec34c4cSmrg
7535ec34c4cSmrg
7545ec34c4cSmrg# func_echo ARG...
7555ec34c4cSmrg# ----------------
7565ec34c4cSmrg# Echo program name prefixed message.
7575ec34c4cSmrgfunc_echo ()
7585ec34c4cSmrg{
7595ec34c4cSmrg    $debug_cmd
7605ec34c4cSmrg
7615ec34c4cSmrg    _G_message=$*
7625ec34c4cSmrg
7635ec34c4cSmrg    func_echo_IFS=$IFS
7645ec34c4cSmrg    IFS=$nl
7655ec34c4cSmrg    for _G_line in $_G_message; do
7665ec34c4cSmrg      IFS=$func_echo_IFS
7675ec34c4cSmrg      $ECHO "$progname: $_G_line"
7685ec34c4cSmrg    done
7695ec34c4cSmrg    IFS=$func_echo_IFS
7705ec34c4cSmrg}
7715ec34c4cSmrg
7725ec34c4cSmrg
7735ec34c4cSmrg# func_echo_all ARG...
7745ec34c4cSmrg# --------------------
7755ec34c4cSmrg# Invoke $ECHO with all args, space-separated.
7765ec34c4cSmrgfunc_echo_all ()
7775ec34c4cSmrg{
7785ec34c4cSmrg    $ECHO "$*"
7795ec34c4cSmrg}
7805ec34c4cSmrg
7815ec34c4cSmrg
7825ec34c4cSmrg# func_echo_infix_1 INFIX ARG...
7835ec34c4cSmrg# ------------------------------
7845ec34c4cSmrg# Echo program name, followed by INFIX on the first line, with any
7855ec34c4cSmrg# additional lines not showing INFIX.
7865ec34c4cSmrgfunc_echo_infix_1 ()
7875ec34c4cSmrg{
7885ec34c4cSmrg    $debug_cmd
7895ec34c4cSmrg
7905ec34c4cSmrg    $require_term_colors
7915ec34c4cSmrg
7925ec34c4cSmrg    _G_infix=$1; shift
7935ec34c4cSmrg    _G_indent=$_G_infix
7945ec34c4cSmrg    _G_prefix="$progname: $_G_infix: "
7955ec34c4cSmrg    _G_message=$*
7965ec34c4cSmrg
7975ec34c4cSmrg    # Strip color escape sequences before counting printable length
7985ec34c4cSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7995ec34c4cSmrg    do
8005ec34c4cSmrg      test -n "$_G_tc" && {
8015ec34c4cSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
8025ec34c4cSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
8035ec34c4cSmrg      }
8045ec34c4cSmrg    done
8055ec34c4cSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
8065ec34c4cSmrg
8075ec34c4cSmrg    func_echo_infix_1_IFS=$IFS
8085ec34c4cSmrg    IFS=$nl
8095ec34c4cSmrg    for _G_line in $_G_message; do
8105ec34c4cSmrg      IFS=$func_echo_infix_1_IFS
8115ec34c4cSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
8125ec34c4cSmrg      _G_prefix=$_G_indent
8135ec34c4cSmrg    done
8145ec34c4cSmrg    IFS=$func_echo_infix_1_IFS
8155ec34c4cSmrg}
8165ec34c4cSmrg
8175ec34c4cSmrg
8185ec34c4cSmrg# func_error ARG...
8195ec34c4cSmrg# -----------------
8205ec34c4cSmrg# Echo program name prefixed message to standard error.
8215ec34c4cSmrgfunc_error ()
8225ec34c4cSmrg{
8235ec34c4cSmrg    $debug_cmd
8245ec34c4cSmrg
8255ec34c4cSmrg    $require_term_colors
8265ec34c4cSmrg
8275ec34c4cSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
8285ec34c4cSmrg}
8295ec34c4cSmrg
8305ec34c4cSmrg
8315ec34c4cSmrg# func_fatal_error ARG...
8325ec34c4cSmrg# -----------------------
8335ec34c4cSmrg# Echo program name prefixed message to standard error, and exit.
8345ec34c4cSmrgfunc_fatal_error ()
8355ec34c4cSmrg{
8365ec34c4cSmrg    $debug_cmd
8375ec34c4cSmrg
8385ec34c4cSmrg    func_error "$*"
8395ec34c4cSmrg    exit $EXIT_FAILURE
8405ec34c4cSmrg}
8415ec34c4cSmrg
8425ec34c4cSmrg
8435ec34c4cSmrg# func_grep EXPRESSION FILENAME
8445ec34c4cSmrg# -----------------------------
845994689c1Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846994689c1Smrgfunc_grep ()
847994689c1Smrg{
8485ec34c4cSmrg    $debug_cmd
8495ec34c4cSmrg
850994689c1Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851994689c1Smrg}
852994689c1Smrg
853994689c1Smrg
8545ec34c4cSmrg# func_len STRING
8555ec34c4cSmrg# ---------------
8565ec34c4cSmrg# Set func_len_result to the length of STRING. STRING may not
8575ec34c4cSmrg# start with a hyphen.
8585ec34c4cSmrg  test -z "$_G_HAVE_XSI_OPS" \
8595ec34c4cSmrg    && (eval 'x=a/b/c;
8605ec34c4cSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8615ec34c4cSmrg    && _G_HAVE_XSI_OPS=yes
8625ec34c4cSmrg
8635ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8645ec34c4cSmrg  eval 'func_len ()
8655ec34c4cSmrg  {
8665ec34c4cSmrg    $debug_cmd
8675ec34c4cSmrg
8685ec34c4cSmrg    func_len_result=${#1}
8695ec34c4cSmrg  }'
8705ec34c4cSmrgelse
8715ec34c4cSmrg  func_len ()
8725ec34c4cSmrg  {
8735ec34c4cSmrg    $debug_cmd
8745ec34c4cSmrg
8755ec34c4cSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8765ec34c4cSmrg  }
8775ec34c4cSmrgfi
8785ec34c4cSmrg
8795ec34c4cSmrg
8805ec34c4cSmrg# func_mkdir_p DIRECTORY-PATH
8815ec34c4cSmrg# ---------------------------
882994689c1Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883994689c1Smrgfunc_mkdir_p ()
884994689c1Smrg{
8855ec34c4cSmrg    $debug_cmd
8865ec34c4cSmrg
8875ec34c4cSmrg    _G_directory_path=$1
8885ec34c4cSmrg    _G_dir_list=
889994689c1Smrg
8905ec34c4cSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891994689c1Smrg
8925ec34c4cSmrg      # Protect directory names starting with '-'
8935ec34c4cSmrg      case $_G_directory_path in
8945ec34c4cSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895994689c1Smrg      esac
896994689c1Smrg
897994689c1Smrg      # While some portion of DIR does not yet exist...
8985ec34c4cSmrg      while test ! -d "$_G_directory_path"; do
899994689c1Smrg        # ...make a list in topmost first order.  Use a colon delimited
900994689c1Smrg	# list incase some portion of path contains whitespace.
9015ec34c4cSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902994689c1Smrg
903994689c1Smrg        # If the last portion added has no slash in it, the list is done
9045ec34c4cSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905994689c1Smrg
906994689c1Smrg        # ...otherwise throw away the child directory and loop
9075ec34c4cSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908994689c1Smrg      done
9095ec34c4cSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910994689c1Smrg
9115ec34c4cSmrg      func_mkdir_p_IFS=$IFS; IFS=:
9125ec34c4cSmrg      for _G_dir in $_G_dir_list; do
9135ec34c4cSmrg	IFS=$func_mkdir_p_IFS
9145ec34c4cSmrg        # mkdir can fail with a 'File exist' error if two processes
915994689c1Smrg        # try to create one of the directories concurrently.  Don't
916994689c1Smrg        # stop in that case!
9175ec34c4cSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918994689c1Smrg      done
9195ec34c4cSmrg      IFS=$func_mkdir_p_IFS
920994689c1Smrg
921994689c1Smrg      # Bail out if we (or some other process) failed to create a directory.
9225ec34c4cSmrg      test -d "$_G_directory_path" || \
9235ec34c4cSmrg        func_fatal_error "Failed to create '$1'"
924994689c1Smrg    fi
925994689c1Smrg}
9267a84e134Smrg
9277a84e134Smrg
9285ec34c4cSmrg# func_mktempdir [BASENAME]
9295ec34c4cSmrg# -------------------------
9307a84e134Smrg# Make a temporary directory that won't clash with other running
9317a84e134Smrg# libtool processes, and avoids race conditions if possible.  If
9325ec34c4cSmrg# given, BASENAME is the basename for that directory.
9337a84e134Smrgfunc_mktempdir ()
9347a84e134Smrg{
9355ec34c4cSmrg    $debug_cmd
9365ec34c4cSmrg
9375ec34c4cSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
9387a84e134Smrg
9395ec34c4cSmrg    if test : = "$opt_dry_run"; then
9407a84e134Smrg      # Return a directory name, but don't create it in dry-run mode
9415ec34c4cSmrg      _G_tmpdir=$_G_template-$$
9427a84e134Smrg    else
9437a84e134Smrg
9447a84e134Smrg      # If mktemp works, use that first and foremost
9455ec34c4cSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9467a84e134Smrg
9475ec34c4cSmrg      if test ! -d "$_G_tmpdir"; then
948994689c1Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9495ec34c4cSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9507a84e134Smrg
9515ec34c4cSmrg        func_mktempdir_umask=`umask`
952994689c1Smrg        umask 0077
9535ec34c4cSmrg        $MKDIR "$_G_tmpdir"
9545ec34c4cSmrg        umask $func_mktempdir_umask
9557a84e134Smrg      fi
9567a84e134Smrg
9577a84e134Smrg      # If we're not in dry-run mode, bomb out on failure
9585ec34c4cSmrg      test -d "$_G_tmpdir" || \
9595ec34c4cSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9607a84e134Smrg    fi
9617a84e134Smrg
9625ec34c4cSmrg    $ECHO "$_G_tmpdir"
9635ec34c4cSmrg}
9645ec34c4cSmrg
9655ec34c4cSmrg
9665ec34c4cSmrg# func_normal_abspath PATH
9675ec34c4cSmrg# ------------------------
9685ec34c4cSmrg# Remove doubled-up and trailing slashes, "." path components,
9695ec34c4cSmrg# and cancel out any ".." path components in PATH after making
9705ec34c4cSmrg# it an absolute path.
9715ec34c4cSmrgfunc_normal_abspath ()
9725ec34c4cSmrg{
9735ec34c4cSmrg    $debug_cmd
9745ec34c4cSmrg
9755ec34c4cSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9765ec34c4cSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9775ec34c4cSmrg    _G_pathcdr='s|^/[^/]*||'
9785ec34c4cSmrg    _G_removedotparts=':dotsl
9795ec34c4cSmrg		s|/\./|/|g
9805ec34c4cSmrg		t dotsl
9815ec34c4cSmrg		s|/\.$|/|'
9825ec34c4cSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9835ec34c4cSmrg    _G_finalslash='s|/*$|/|'
9845ec34c4cSmrg
9855ec34c4cSmrg    # Start from root dir and reassemble the path.
9865ec34c4cSmrg    func_normal_abspath_result=
9875ec34c4cSmrg    func_normal_abspath_tpath=$1
9885ec34c4cSmrg    func_normal_abspath_altnamespace=
9895ec34c4cSmrg    case $func_normal_abspath_tpath in
9905ec34c4cSmrg      "")
9915ec34c4cSmrg        # Empty path, that just means $cwd.
9925ec34c4cSmrg        func_stripname '' '/' "`pwd`"
9935ec34c4cSmrg        func_normal_abspath_result=$func_stripname_result
9945ec34c4cSmrg        return
9955ec34c4cSmrg        ;;
9965ec34c4cSmrg      # The next three entries are used to spot a run of precisely
9975ec34c4cSmrg      # two leading slashes without using negated character classes;
9985ec34c4cSmrg      # we take advantage of case's first-match behaviour.
9995ec34c4cSmrg      ///*)
10005ec34c4cSmrg        # Unusual form of absolute path, do nothing.
10015ec34c4cSmrg        ;;
10025ec34c4cSmrg      //*)
10035ec34c4cSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
10045ec34c4cSmrg        # and for example Cygwin uses it to access remote file shares
10055ec34c4cSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
10065ec34c4cSmrg        func_normal_abspath_altnamespace=/
10075ec34c4cSmrg        ;;
10085ec34c4cSmrg      /*)
10095ec34c4cSmrg        # Absolute path, do nothing.
10105ec34c4cSmrg        ;;
10115ec34c4cSmrg      *)
10125ec34c4cSmrg        # Relative path, prepend $cwd.
10135ec34c4cSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
10145ec34c4cSmrg        ;;
10155ec34c4cSmrg    esac
10165ec34c4cSmrg
10175ec34c4cSmrg    # Cancel out all the simple stuff to save iterations.  We also want
10185ec34c4cSmrg    # the path to end with a slash for ease of parsing, so make sure
10195ec34c4cSmrg    # there is one (and only one) here.
10205ec34c4cSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10215ec34c4cSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
10225ec34c4cSmrg    while :; do
10235ec34c4cSmrg      # Processed it all yet?
10245ec34c4cSmrg      if test / = "$func_normal_abspath_tpath"; then
10255ec34c4cSmrg        # If we ascended to the root using ".." the result may be empty now.
10265ec34c4cSmrg        if test -z "$func_normal_abspath_result"; then
10275ec34c4cSmrg          func_normal_abspath_result=/
10285ec34c4cSmrg        fi
10295ec34c4cSmrg        break
10305ec34c4cSmrg      fi
10315ec34c4cSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
10325ec34c4cSmrg          -e "$_G_pathcar"`
10335ec34c4cSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10345ec34c4cSmrg          -e "$_G_pathcdr"`
10355ec34c4cSmrg      # Figure out what to do with it
10365ec34c4cSmrg      case $func_normal_abspath_tcomponent in
10375ec34c4cSmrg        "")
10385ec34c4cSmrg          # Trailing empty path component, ignore it.
10395ec34c4cSmrg          ;;
10405ec34c4cSmrg        ..)
10415ec34c4cSmrg          # Parent dir; strip last assembled component from result.
10425ec34c4cSmrg          func_dirname "$func_normal_abspath_result"
10435ec34c4cSmrg          func_normal_abspath_result=$func_dirname_result
10445ec34c4cSmrg          ;;
10455ec34c4cSmrg        *)
10465ec34c4cSmrg          # Actual path component, append it.
10475ec34c4cSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10485ec34c4cSmrg          ;;
10495ec34c4cSmrg      esac
10505ec34c4cSmrg    done
10515ec34c4cSmrg    # Restore leading double-slash if one was found on entry.
10525ec34c4cSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10535ec34c4cSmrg}
10545ec34c4cSmrg
10555ec34c4cSmrg
10565ec34c4cSmrg# func_notquiet ARG...
10575ec34c4cSmrg# --------------------
10585ec34c4cSmrg# Echo program name prefixed message only when not in quiet mode.
10595ec34c4cSmrgfunc_notquiet ()
10605ec34c4cSmrg{
10615ec34c4cSmrg    $debug_cmd
10625ec34c4cSmrg
10635ec34c4cSmrg    $opt_quiet || func_echo ${1+"$@"}
10645ec34c4cSmrg
10655ec34c4cSmrg    # A bug in bash halts the script if the last line of a function
10665ec34c4cSmrg    # fails when set -e is in force, so we need another command to
10675ec34c4cSmrg    # work around that:
10685ec34c4cSmrg    :
10695ec34c4cSmrg}
10705ec34c4cSmrg
10715ec34c4cSmrg
10725ec34c4cSmrg# func_relative_path SRCDIR DSTDIR
10735ec34c4cSmrg# --------------------------------
10745ec34c4cSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10755ec34c4cSmrgfunc_relative_path ()
10765ec34c4cSmrg{
10775ec34c4cSmrg    $debug_cmd
10785ec34c4cSmrg
10795ec34c4cSmrg    func_relative_path_result=
10805ec34c4cSmrg    func_normal_abspath "$1"
10815ec34c4cSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10825ec34c4cSmrg    func_normal_abspath "$2"
10835ec34c4cSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10845ec34c4cSmrg
10855ec34c4cSmrg    # Ascend the tree starting from libdir
10865ec34c4cSmrg    while :; do
10875ec34c4cSmrg      # check if we have found a prefix of bindir
10885ec34c4cSmrg      case $func_relative_path_tbindir in
10895ec34c4cSmrg        $func_relative_path_tlibdir)
10905ec34c4cSmrg          # found an exact match
10915ec34c4cSmrg          func_relative_path_tcancelled=
10925ec34c4cSmrg          break
10935ec34c4cSmrg          ;;
10945ec34c4cSmrg        $func_relative_path_tlibdir*)
10955ec34c4cSmrg          # found a matching prefix
10965ec34c4cSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10975ec34c4cSmrg          func_relative_path_tcancelled=$func_stripname_result
10985ec34c4cSmrg          if test -z "$func_relative_path_result"; then
10995ec34c4cSmrg            func_relative_path_result=.
11005ec34c4cSmrg          fi
11015ec34c4cSmrg          break
11025ec34c4cSmrg          ;;
11035ec34c4cSmrg        *)
11045ec34c4cSmrg          func_dirname $func_relative_path_tlibdir
11055ec34c4cSmrg          func_relative_path_tlibdir=$func_dirname_result
11065ec34c4cSmrg          if test -z "$func_relative_path_tlibdir"; then
11075ec34c4cSmrg            # Have to descend all the way to the root!
11085ec34c4cSmrg            func_relative_path_result=../$func_relative_path_result
11095ec34c4cSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
11105ec34c4cSmrg            break
11115ec34c4cSmrg          fi
11125ec34c4cSmrg          func_relative_path_result=../$func_relative_path_result
11135ec34c4cSmrg          ;;
11145ec34c4cSmrg      esac
11155ec34c4cSmrg    done
11165ec34c4cSmrg
11175ec34c4cSmrg    # Now calculate path; take care to avoid doubling-up slashes.
11185ec34c4cSmrg    func_stripname '' '/' "$func_relative_path_result"
11195ec34c4cSmrg    func_relative_path_result=$func_stripname_result
11205ec34c4cSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
11215ec34c4cSmrg    if test -n "$func_stripname_result"; then
11225ec34c4cSmrg      func_append func_relative_path_result "/$func_stripname_result"
11235ec34c4cSmrg    fi
11245ec34c4cSmrg
11255ec34c4cSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
11265ec34c4cSmrg    if test -n "$func_relative_path_result"; then
11275ec34c4cSmrg      func_stripname './' '' "$func_relative_path_result"
11285ec34c4cSmrg      func_relative_path_result=$func_stripname_result
11295ec34c4cSmrg    fi
11305ec34c4cSmrg
11315ec34c4cSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
11325ec34c4cSmrg
11335ec34c4cSmrg    :
11345ec34c4cSmrg}
11355ec34c4cSmrg
11365ec34c4cSmrg
11375b16253fSmrg# func_quote_portable EVAL ARG
11385b16253fSmrg# ----------------------------
11395b16253fSmrg# Internal function to portably implement func_quote_arg.  Note that we still
11405b16253fSmrg# keep attention to performance here so we as much as possible try to avoid
11415b16253fSmrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11425b16253fSmrgfunc_quote_portable ()
11435ec34c4cSmrg{
11445ec34c4cSmrg    $debug_cmd
11455ec34c4cSmrg
11465b16253fSmrg    $require_check_ifs_backslash
11475ec34c4cSmrg
11485b16253fSmrg    func_quote_portable_result=$2
11495ec34c4cSmrg
11505b16253fSmrg    # one-time-loop (easy break)
11515b16253fSmrg    while true
11525b16253fSmrg    do
11535b16253fSmrg      if $1; then
11545b16253fSmrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11555b16253fSmrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11565b16253fSmrg        break
11575b16253fSmrg      fi
11585b16253fSmrg
11595b16253fSmrg      # Quote for eval.
11605b16253fSmrg      case $func_quote_portable_result in
11615b16253fSmrg        *[\\\`\"\$]*)
11625b16253fSmrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11635b16253fSmrg          # contains the shell wildcard characters.
11645b16253fSmrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11655b16253fSmrg            :*|*[\[\*\?]*)
11665b16253fSmrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11675b16253fSmrg                  | $SED "$sed_quote_subst"`
11685b16253fSmrg              break
11695ec34c4cSmrg              ;;
11705b16253fSmrg          esac
11715b16253fSmrg
11725b16253fSmrg          func_quote_portable_old_IFS=$IFS
11735b16253fSmrg          for _G_char in '\' '`' '"' '$'
11745b16253fSmrg          do
11755b16253fSmrg            # STATE($1) PREV($2) SEPARATOR($3)
11765b16253fSmrg            set start "" ""
11775b16253fSmrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11785b16253fSmrg            IFS=$_G_char
11795b16253fSmrg            for _G_part in $func_quote_portable_result
11805b16253fSmrg            do
11815b16253fSmrg              case $1 in
11825b16253fSmrg              quote)
11835b16253fSmrg                func_append func_quote_portable_result "$3$2"
11845b16253fSmrg                set quote "$_G_part" "\\$_G_char"
11855b16253fSmrg                ;;
11865b16253fSmrg              start)
11875b16253fSmrg                set first "" ""
11885b16253fSmrg                func_quote_portable_result=
11895b16253fSmrg                ;;
11905b16253fSmrg              first)
11915b16253fSmrg                set quote "$_G_part" ""
11925b16253fSmrg                ;;
11935b16253fSmrg              esac
11945b16253fSmrg            done
11955ec34c4cSmrg          done
11965b16253fSmrg          IFS=$func_quote_portable_old_IFS
11975b16253fSmrg          ;;
11985b16253fSmrg        *) ;;
11995b16253fSmrg      esac
12005b16253fSmrg      break
12015b16253fSmrg    done
12025b16253fSmrg
12035b16253fSmrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12045b16253fSmrg    case $func_quote_portable_result in
12055b16253fSmrg      # double-quote args containing shell metacharacters to delay
12065b16253fSmrg      # word splitting, command substitution and variable expansion
12075b16253fSmrg      # for a subsequent eval.
12085b16253fSmrg      # many bourne shells cannot handle close brackets correctly
12095b16253fSmrg      # in scan sets, so we specify it separately.
12105b16253fSmrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12115b16253fSmrg        func_quote_portable_result=\"$func_quote_portable_result\"
12125ec34c4cSmrg        ;;
12135ec34c4cSmrg    esac
12147a84e134Smrg}
12157a84e134Smrg
12167a84e134Smrg
12175b16253fSmrg# func_quotefast_eval ARG
12185b16253fSmrg# -----------------------
12195b16253fSmrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12205b16253fSmrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12215b16253fSmrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12225b16253fSmrg  printf -v _GL_test_printf_tilde %q '~'
12235b16253fSmrg  if test '\~' = "$_GL_test_printf_tilde"; then
12245b16253fSmrg    func_quotefast_eval ()
12255b16253fSmrg    {
12265b16253fSmrg      printf -v func_quotefast_eval_result %q "$1"
12275b16253fSmrg    }
12285b16253fSmrg  else
12295b16253fSmrg    # Broken older Bash implementations.  Make those faster too if possible.
12305b16253fSmrg    func_quotefast_eval ()
12315b16253fSmrg    {
12325b16253fSmrg      case $1 in
12335b16253fSmrg        '~'*)
12345b16253fSmrg          func_quote_portable false "$1"
12355b16253fSmrg          func_quotefast_eval_result=$func_quote_portable_result
12365ec34c4cSmrg          ;;
12375ec34c4cSmrg        *)
12385b16253fSmrg          printf -v func_quotefast_eval_result %q "$1"
12395b16253fSmrg          ;;
12405ec34c4cSmrg      esac
12415b16253fSmrg    }
12425b16253fSmrg  fi
12435b16253fSmrgelse
12445b16253fSmrg  func_quotefast_eval ()
12455b16253fSmrg  {
12465b16253fSmrg    func_quote_portable false "$1"
12475b16253fSmrg    func_quotefast_eval_result=$func_quote_portable_result
12485b16253fSmrg  }
12495b16253fSmrgfi
12505ec34c4cSmrg
12515ec34c4cSmrg
12525b16253fSmrg# func_quote_arg MODEs ARG
12535b16253fSmrg# ------------------------
12545b16253fSmrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12555b16253fSmrg# specifiers listed below separated by ',' character.  This function returns two
12565b16253fSmrg# values:
12575b16253fSmrg#   i) func_quote_arg_result
12585b16253fSmrg#      double-quoted (when needed), suitable for a subsequent eval
12595b16253fSmrg#  ii) func_quote_arg_unquoted_result
12605b16253fSmrg#      has all characters that are still active within double
12615b16253fSmrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12625b16253fSmrg#
12635b16253fSmrg# Available modes:
12645b16253fSmrg# ----------------
12655b16253fSmrg# 'eval' (default)
12665b16253fSmrg#       - escape shell special characters
12675b16253fSmrg# 'expand'
12685b16253fSmrg#       - the same as 'eval';  but do not quote variable references
12695b16253fSmrg# 'pretty'
12705b16253fSmrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12715b16253fSmrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12725b16253fSmrg#         of 'echo a\ b'.  This is slower than default on some shells.
12735b16253fSmrg# 'unquoted'
12745b16253fSmrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12755b16253fSmrg#         wrapping double-quotes.
12765b16253fSmrg#
12775b16253fSmrg# Examples for 'func_quote_arg pretty,unquoted string':
12785b16253fSmrg#
12795b16253fSmrg#   string      | *_result              | *_unquoted_result
12805b16253fSmrg#   ------------+-----------------------+-------------------
12815b16253fSmrg#   "           | \"                    | \"
12825b16253fSmrg#   a b         | "a b"                 | a b
12835b16253fSmrg#   "a b"       | "\"a b\""             | \"a b\"
12845b16253fSmrg#   *           | "*"                   | *
12855b16253fSmrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12865b16253fSmrg#
12875b16253fSmrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12885b16253fSmrg#
12895b16253fSmrg#   string        |   *_result          |  *_unquoted_result
12905b16253fSmrg#   --------------+---------------------+--------------------
12915b16253fSmrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12925b16253fSmrgfunc_quote_arg ()
12935b16253fSmrg{
12945b16253fSmrg    _G_quote_expand=false
12955b16253fSmrg    case ,$1, in
12965b16253fSmrg      *,expand,*)
12975b16253fSmrg        _G_quote_expand=:
12985b16253fSmrg        ;;
1299994689c1Smrg    esac
1300994689c1Smrg
13015b16253fSmrg    case ,$1, in
13025b16253fSmrg      *,pretty,*|*,expand,*|*,unquoted,*)
13035b16253fSmrg        func_quote_portable $_G_quote_expand "$2"
13045b16253fSmrg        func_quote_arg_result=$func_quote_portable_result
13055b16253fSmrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13065b16253fSmrg        ;;
13075b16253fSmrg      *)
13085b16253fSmrg        # Faster quote-for-eval for some shells.
13095b16253fSmrg        func_quotefast_eval "$2"
13105b16253fSmrg        func_quote_arg_result=$func_quotefast_eval_result
1311994689c1Smrg        ;;
13125ec34c4cSmrg    esac
13135b16253fSmrg}
13145ec34c4cSmrg
13155b16253fSmrg
13165b16253fSmrg# func_quote MODEs ARGs...
13175b16253fSmrg# ------------------------
13185b16253fSmrg# Quote all ARGs to be evaled later and join them into single command.  See
13195b16253fSmrg# func_quote_arg's description for more info.
13205b16253fSmrgfunc_quote ()
13215b16253fSmrg{
13225b16253fSmrg    $debug_cmd
13235b16253fSmrg    _G_func_quote_mode=$1 ; shift
13245b16253fSmrg    func_quote_result=
13255b16253fSmrg    while test 0 -lt $#; do
13265b16253fSmrg      func_quote_arg "$_G_func_quote_mode" "$1"
13275b16253fSmrg      if test -n "$func_quote_result"; then
13285b16253fSmrg        func_append func_quote_result " $func_quote_arg_result"
13295b16253fSmrg      else
13305b16253fSmrg        func_append func_quote_result "$func_quote_arg_result"
13315b16253fSmrg      fi
13325b16253fSmrg      shift
13335b16253fSmrg    done
13345ec34c4cSmrg}
13355ec34c4cSmrg
13365ec34c4cSmrg
13375ec34c4cSmrg# func_stripname PREFIX SUFFIX NAME
13385ec34c4cSmrg# ---------------------------------
13395ec34c4cSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
13405ec34c4cSmrg# PREFIX and SUFFIX must not contain globbing or regex special
13415ec34c4cSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
13425ec34c4cSmrg# dot (in which case that matches only a dot).
13435ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
13445ec34c4cSmrg  eval 'func_stripname ()
13455ec34c4cSmrg  {
13465ec34c4cSmrg    $debug_cmd
13475ec34c4cSmrg
13485ec34c4cSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
13495ec34c4cSmrg    # positional parameters, so assign one to ordinary variable first.
13505ec34c4cSmrg    func_stripname_result=$3
13515ec34c4cSmrg    func_stripname_result=${func_stripname_result#"$1"}
13525ec34c4cSmrg    func_stripname_result=${func_stripname_result%"$2"}
13535ec34c4cSmrg  }'
13545ec34c4cSmrgelse
13555ec34c4cSmrg  func_stripname ()
13565ec34c4cSmrg  {
13575ec34c4cSmrg    $debug_cmd
13585ec34c4cSmrg
13595ec34c4cSmrg    case $2 in
13605ec34c4cSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
13615ec34c4cSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
13625ec34c4cSmrg    esac
13635ec34c4cSmrg  }
13645ec34c4cSmrgfi
13655ec34c4cSmrg
13665ec34c4cSmrg
13675ec34c4cSmrg# func_show_eval CMD [FAIL_EXP]
13685ec34c4cSmrg# -----------------------------
13695ec34c4cSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13705ec34c4cSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13715ec34c4cSmrg# is given, then evaluate it.
13725ec34c4cSmrgfunc_show_eval ()
13735ec34c4cSmrg{
13745ec34c4cSmrg    $debug_cmd
13755ec34c4cSmrg
13765ec34c4cSmrg    _G_cmd=$1
13775ec34c4cSmrg    _G_fail_exp=${2-':'}
13785ec34c4cSmrg
13795b16253fSmrg    func_quote_arg pretty,expand "$_G_cmd"
13805b16253fSmrg    eval "func_notquiet $func_quote_arg_result"
13815ec34c4cSmrg
13825ec34c4cSmrg    $opt_dry_run || {
13835ec34c4cSmrg      eval "$_G_cmd"
13845ec34c4cSmrg      _G_status=$?
13855ec34c4cSmrg      if test 0 -ne "$_G_status"; then
13865ec34c4cSmrg	eval "(exit $_G_status); $_G_fail_exp"
13875ec34c4cSmrg      fi
13885ec34c4cSmrg    }
13895ec34c4cSmrg}
13905ec34c4cSmrg
13915ec34c4cSmrg
13925ec34c4cSmrg# func_show_eval_locale CMD [FAIL_EXP]
13935ec34c4cSmrg# ------------------------------------
13945ec34c4cSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13955ec34c4cSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13965ec34c4cSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
13975ec34c4cSmrgfunc_show_eval_locale ()
13985ec34c4cSmrg{
13995ec34c4cSmrg    $debug_cmd
14005ec34c4cSmrg
14015ec34c4cSmrg    _G_cmd=$1
14025ec34c4cSmrg    _G_fail_exp=${2-':'}
14035ec34c4cSmrg
14045ec34c4cSmrg    $opt_quiet || {
14055b16253fSmrg      func_quote_arg expand,pretty "$_G_cmd"
14065b16253fSmrg      eval "func_echo $func_quote_arg_result"
14075ec34c4cSmrg    }
14085ec34c4cSmrg
14095ec34c4cSmrg    $opt_dry_run || {
14105ec34c4cSmrg      eval "$_G_user_locale
14115ec34c4cSmrg	    $_G_cmd"
14125ec34c4cSmrg      _G_status=$?
14135ec34c4cSmrg      eval "$_G_safe_locale"
14145ec34c4cSmrg      if test 0 -ne "$_G_status"; then
14155ec34c4cSmrg	eval "(exit $_G_status); $_G_fail_exp"
14165ec34c4cSmrg      fi
14175ec34c4cSmrg    }
14185ec34c4cSmrg}
14195ec34c4cSmrg
14205ec34c4cSmrg
14215ec34c4cSmrg# func_tr_sh
14225ec34c4cSmrg# ----------
14235ec34c4cSmrg# Turn $1 into a string suitable for a shell variable name.
14245ec34c4cSmrg# Result is stored in $func_tr_sh_result.  All characters
14255ec34c4cSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
14265ec34c4cSmrg# if $1 begins with a digit, a '_' is prepended as well.
14275ec34c4cSmrgfunc_tr_sh ()
14285ec34c4cSmrg{
14295ec34c4cSmrg    $debug_cmd
14305ec34c4cSmrg
14315ec34c4cSmrg    case $1 in
14325ec34c4cSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
14335ec34c4cSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
14345ec34c4cSmrg      ;;
14355ec34c4cSmrg    * )
14365ec34c4cSmrg      func_tr_sh_result=$1
14375ec34c4cSmrg      ;;
14387a84e134Smrg    esac
14397a84e134Smrg}
14407a84e134Smrg
14417a84e134Smrg
14425ec34c4cSmrg# func_verbose ARG...
14435ec34c4cSmrg# -------------------
14445ec34c4cSmrg# Echo program name prefixed message in verbose mode only.
14455ec34c4cSmrgfunc_verbose ()
14465ec34c4cSmrg{
14475ec34c4cSmrg    $debug_cmd
14485ec34c4cSmrg
14495ec34c4cSmrg    $opt_verbose && func_echo "$*"
14505ec34c4cSmrg
14515ec34c4cSmrg    :
14525ec34c4cSmrg}
14535ec34c4cSmrg
14545ec34c4cSmrg
14555ec34c4cSmrg# func_warn_and_continue ARG...
14565ec34c4cSmrg# -----------------------------
14575ec34c4cSmrg# Echo program name prefixed warning message to standard error.
14585ec34c4cSmrgfunc_warn_and_continue ()
14595ec34c4cSmrg{
14605ec34c4cSmrg    $debug_cmd
14615ec34c4cSmrg
14625ec34c4cSmrg    $require_term_colors
14635ec34c4cSmrg
14645ec34c4cSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
14655ec34c4cSmrg}
14665ec34c4cSmrg
14675ec34c4cSmrg
14685ec34c4cSmrg# func_warning CATEGORY ARG...
14695ec34c4cSmrg# ----------------------------
14705ec34c4cSmrg# Echo program name prefixed warning message to standard error. Warning
14715ec34c4cSmrg# messages can be filtered according to CATEGORY, where this function
14725ec34c4cSmrg# elides messages where CATEGORY is not listed in the global variable
14735ec34c4cSmrg# 'opt_warning_types'.
14745ec34c4cSmrgfunc_warning ()
14755ec34c4cSmrg{
14765ec34c4cSmrg    $debug_cmd
14775ec34c4cSmrg
14785ec34c4cSmrg    # CATEGORY must be in the warning_categories list!
14795ec34c4cSmrg    case " $warning_categories " in
14805ec34c4cSmrg      *" $1 "*) ;;
14815ec34c4cSmrg      *) func_internal_error "invalid warning category '$1'" ;;
14825ec34c4cSmrg    esac
14835ec34c4cSmrg
14845ec34c4cSmrg    _G_category=$1
14855ec34c4cSmrg    shift
14865ec34c4cSmrg
14875ec34c4cSmrg    case " $opt_warning_types " in
14885ec34c4cSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
14895ec34c4cSmrg    esac
14905ec34c4cSmrg}
14915ec34c4cSmrg
14925ec34c4cSmrg
14935ec34c4cSmrg# func_sort_ver VER1 VER2
14945ec34c4cSmrg# -----------------------
14955ec34c4cSmrg# 'sort -V' is not generally available.
14965ec34c4cSmrg# Note this deviates from the version comparison in automake
14975ec34c4cSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
14985ec34c4cSmrg# but this should suffice as we won't be specifying old
14995ec34c4cSmrg# version formats or redundant trailing .0 in bootstrap.conf.
15005ec34c4cSmrg# If we did want full compatibility then we should probably
15015ec34c4cSmrg# use m4_version_compare from autoconf.
15025ec34c4cSmrgfunc_sort_ver ()
15035ec34c4cSmrg{
15045ec34c4cSmrg    $debug_cmd
15055ec34c4cSmrg
15065ec34c4cSmrg    printf '%s\n%s\n' "$1" "$2" \
15075ec34c4cSmrg      | 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
15085ec34c4cSmrg}
15095ec34c4cSmrg
15105ec34c4cSmrg# func_lt_ver PREV CURR
15115ec34c4cSmrg# ---------------------
15125ec34c4cSmrg# Return true if PREV and CURR are in the correct order according to
15135ec34c4cSmrg# func_sort_ver, otherwise false.  Use it like this:
15145ec34c4cSmrg#
15155ec34c4cSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
15165ec34c4cSmrgfunc_lt_ver ()
15175ec34c4cSmrg{
15185ec34c4cSmrg    $debug_cmd
15195ec34c4cSmrg
15205ec34c4cSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
15215ec34c4cSmrg}
15225ec34c4cSmrg
15235ec34c4cSmrg
15245ec34c4cSmrg# Local variables:
15255ec34c4cSmrg# mode: shell-script
15265ec34c4cSmrg# sh-indentation: 2
15275ec34c4cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
15285ec34c4cSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
15295ec34c4cSmrg# time-stamp-time-zone: "UTC"
15305ec34c4cSmrg# End:
15315ec34c4cSmrg#! /bin/sh
15325ec34c4cSmrg
15335ec34c4cSmrg# A portable, pluggable option parser for Bourne shell.
15345ec34c4cSmrg# Written by Gary V. Vaughan, 2010
15355ec34c4cSmrg
15365b16253fSmrg# This is free software.  There is NO warranty; not even for
15375b16253fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15385b16253fSmrg#
15395b16253fSmrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
15405b16253fSmrg#
15415b16253fSmrg# This file is dual licensed under the terms of the MIT license
15425b16253fSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
15435b16253fSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15445b16253fSmrg# these licenses when using or redistributing this software or any of
15455b16253fSmrg# the files within it.  See the URLs above, or the file `LICENSE`
15465b16253fSmrg# included in the Bootstrap distribution for the full license texts.
15475ec34c4cSmrg
15485b16253fSmrg# Please report bugs or propose patches to:
15495b16253fSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
15505ec34c4cSmrg
15515b16253fSmrg# Set a version string for this script.
15525b16253fSmrgscriptversion=2019-02-19.15; # UTC
15535ec34c4cSmrg
15545ec34c4cSmrg
15555ec34c4cSmrg## ------ ##
15565ec34c4cSmrg## Usage. ##
15575ec34c4cSmrg## ------ ##
15585ec34c4cSmrg
15595ec34c4cSmrg# This file is a library for parsing options in your shell scripts along
15605ec34c4cSmrg# with assorted other useful supporting features that you can make use
15615ec34c4cSmrg# of too.
15625ec34c4cSmrg#
15635ec34c4cSmrg# For the simplest scripts you might need only:
15645ec34c4cSmrg#
15655ec34c4cSmrg#   #!/bin/sh
15665ec34c4cSmrg#   . relative/path/to/funclib.sh
15675ec34c4cSmrg#   . relative/path/to/options-parser
15685ec34c4cSmrg#   scriptversion=1.0
15695ec34c4cSmrg#   func_options ${1+"$@"}
15705ec34c4cSmrg#   eval set dummy "$func_options_result"; shift
15715ec34c4cSmrg#   ...rest of your script...
15725ec34c4cSmrg#
15735ec34c4cSmrg# In order for the '--version' option to work, you will need to have a
15745ec34c4cSmrg# suitably formatted comment like the one at the top of this file
15755b16253fSmrg# starting with '# Written by ' and ending with '# Copyright'.
15765ec34c4cSmrg#
15775ec34c4cSmrg# For '-h' and '--help' to work, you will also need a one line
15785ec34c4cSmrg# description of your script's purpose in a comment directly above the
15795ec34c4cSmrg# '# Written by ' line, like the one at the top of this file.
15805ec34c4cSmrg#
15815ec34c4cSmrg# The default options also support '--debug', which will turn on shell
15825ec34c4cSmrg# execution tracing (see the comment above debug_cmd below for another
15835ec34c4cSmrg# use), and '--verbose' and the func_verbose function to allow your script
15845ec34c4cSmrg# to display verbose messages only when your user has specified
15855ec34c4cSmrg# '--verbose'.
15865ec34c4cSmrg#
15875b16253fSmrg# After sourcing this file, you can plug in processing for additional
15885ec34c4cSmrg# options by amending the variables from the 'Configuration' section
15895ec34c4cSmrg# below, and following the instructions in the 'Option parsing'
15905ec34c4cSmrg# section further down.
15915ec34c4cSmrg
15925ec34c4cSmrg## -------------- ##
15935ec34c4cSmrg## Configuration. ##
15945ec34c4cSmrg## -------------- ##
15955ec34c4cSmrg
15965ec34c4cSmrg# You should override these variables in your script after sourcing this
15975ec34c4cSmrg# file so that they reflect the customisations you have added to the
15985ec34c4cSmrg# option parser.
15995ec34c4cSmrg
16005ec34c4cSmrg# The usage line for option parsing errors and the start of '-h' and
16015ec34c4cSmrg# '--help' output messages. You can embed shell variables for delayed
16025ec34c4cSmrg# expansion at the time the message is displayed, but you will need to
16035ec34c4cSmrg# quote other shell meta-characters carefully to prevent them being
16045ec34c4cSmrg# expanded when the contents are evaled.
16055ec34c4cSmrgusage='$progpath [OPTION]...'
16065ec34c4cSmrg
16075ec34c4cSmrg# Short help message in response to '-h' and '--help'.  Add to this or
16085ec34c4cSmrg# override it after sourcing this library to reflect the full set of
16095ec34c4cSmrg# options your script accepts.
16105ec34c4cSmrgusage_message="\
16115ec34c4cSmrg       --debug        enable verbose shell tracing
16125ec34c4cSmrg   -W, --warnings=CATEGORY
16135ec34c4cSmrg                      report the warnings falling in CATEGORY [all]
16145ec34c4cSmrg   -v, --verbose      verbosely report processing
16155ec34c4cSmrg       --version      print version information and exit
16165ec34c4cSmrg   -h, --help         print short or long help message and exit
16175ec34c4cSmrg"
16185ec34c4cSmrg
16195ec34c4cSmrg# Additional text appended to 'usage_message' in response to '--help'.
16205ec34c4cSmrglong_help_message="
16215ec34c4cSmrgWarning categories include:
16225ec34c4cSmrg       'all'          show all warnings
16235ec34c4cSmrg       'none'         turn off all the warnings
16245ec34c4cSmrg       'error'        warnings are treated as fatal errors"
16255ec34c4cSmrg
16265ec34c4cSmrg# Help message printed before fatal option parsing errors.
16275ec34c4cSmrgfatal_help="Try '\$progname --help' for more information."
16285ec34c4cSmrg
16295ec34c4cSmrg
16305ec34c4cSmrg
16315ec34c4cSmrg## ------------------------- ##
16325ec34c4cSmrg## Hook function management. ##
16335ec34c4cSmrg## ------------------------- ##
16345ec34c4cSmrg
16355ec34c4cSmrg# This section contains functions for adding, removing, and running hooks
16365b16253fSmrg# in the main code.  A hook is just a list of function names that can be
16375b16253fSmrg# run in order later on.
16385ec34c4cSmrg
16395ec34c4cSmrg# func_hookable FUNC_NAME
16405ec34c4cSmrg# -----------------------
16415ec34c4cSmrg# Declare that FUNC_NAME will run hooks added with
16425ec34c4cSmrg# 'func_add_hook FUNC_NAME ...'.
16435ec34c4cSmrgfunc_hookable ()
16445ec34c4cSmrg{
16455ec34c4cSmrg    $debug_cmd
16465ec34c4cSmrg
16475ec34c4cSmrg    func_append hookable_fns " $1"
16485ec34c4cSmrg}
16495ec34c4cSmrg
16505ec34c4cSmrg
16515ec34c4cSmrg# func_add_hook FUNC_NAME HOOK_FUNC
16525ec34c4cSmrg# ---------------------------------
16535ec34c4cSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
16545ec34c4cSmrg# first have been declared "hookable" by a call to 'func_hookable'.
16555ec34c4cSmrgfunc_add_hook ()
16565ec34c4cSmrg{
16575ec34c4cSmrg    $debug_cmd
16585ec34c4cSmrg
16595ec34c4cSmrg    case " $hookable_fns " in
16605ec34c4cSmrg      *" $1 "*) ;;
16615ec34c4cSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
16625ec34c4cSmrg    esac
16635ec34c4cSmrg
16645ec34c4cSmrg    eval func_append ${1}_hooks '" $2"'
16655ec34c4cSmrg}
16665ec34c4cSmrg
16675ec34c4cSmrg
16685ec34c4cSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
16695ec34c4cSmrg# ------------------------------------
16705b16253fSmrg# Remove HOOK_FUNC from the list of hook functions to be called by
16715b16253fSmrg# FUNC_NAME.
16725ec34c4cSmrgfunc_remove_hook ()
16735ec34c4cSmrg{
16745ec34c4cSmrg    $debug_cmd
16755ec34c4cSmrg
16765ec34c4cSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
16775ec34c4cSmrg}
16785ec34c4cSmrg
16795ec34c4cSmrg
16805b16253fSmrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16815b16253fSmrg# ---------------------------------------------
16825b16253fSmrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16835b16253fSmrg# *_result variable of FUNC_NAME_B.
16845b16253fSmrgfunc_propagate_result ()
16855b16253fSmrg{
16865b16253fSmrg    $debug_cmd
16875b16253fSmrg
16885b16253fSmrg    func_propagate_result_result=:
16895b16253fSmrg    if eval "test \"\${${1}_result+set}\" = set"
16905b16253fSmrg    then
16915b16253fSmrg      eval "${2}_result=\$${1}_result"
16925b16253fSmrg    else
16935b16253fSmrg      func_propagate_result_result=false
16945b16253fSmrg    fi
16955b16253fSmrg}
16965b16253fSmrg
16975b16253fSmrg
16985ec34c4cSmrg# func_run_hooks FUNC_NAME [ARG]...
16995ec34c4cSmrg# ---------------------------------
17005ec34c4cSmrg# Run all hook functions registered to FUNC_NAME.
17015b16253fSmrg# It's assumed that the list of hook functions contains nothing more
17025ec34c4cSmrg# than a whitespace-delimited list of legal shell function names, and
17035ec34c4cSmrg# no effort is wasted trying to catch shell meta-characters or preserve
17045ec34c4cSmrg# whitespace.
17055ec34c4cSmrgfunc_run_hooks ()
17065ec34c4cSmrg{
17075ec34c4cSmrg    $debug_cmd
17085ec34c4cSmrg
1709efbcb2bfSmrg    _G_rc_run_hooks=false
1710efbcb2bfSmrg
17115ec34c4cSmrg    case " $hookable_fns " in
17125ec34c4cSmrg      *" $1 "*) ;;
17135b16253fSmrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17145ec34c4cSmrg    esac
17155ec34c4cSmrg
17165ec34c4cSmrg    eval _G_hook_fns=\$$1_hooks; shift
17175ec34c4cSmrg
17185ec34c4cSmrg    for _G_hook in $_G_hook_fns; do
17195b16253fSmrg      func_unset "${_G_hook}_result"
17205b16253fSmrg      eval $_G_hook '${1+"$@"}'
17215b16253fSmrg      func_propagate_result $_G_hook func_run_hooks
17225b16253fSmrg      if $func_propagate_result_result; then
17235b16253fSmrg        eval set dummy "$func_run_hooks_result"; shift
17245b16253fSmrg      fi
17255ec34c4cSmrg    done
17265ec34c4cSmrg}
17275ec34c4cSmrg
17285ec34c4cSmrg
17295ec34c4cSmrg
17305ec34c4cSmrg## --------------- ##
17315ec34c4cSmrg## Option parsing. ##
17325ec34c4cSmrg## --------------- ##
17335ec34c4cSmrg
17345ec34c4cSmrg# In order to add your own option parsing hooks, you must accept the
17355b16253fSmrg# full positional parameter list from your hook function.  You may remove
17365b16253fSmrg# or edit any options that you action, and then pass back the remaining
17375b16253fSmrg# unprocessed options in '<hooked_function_name>_result', escaped
17385b16253fSmrg# suitably for 'eval'.
17395b16253fSmrg#
17405b16253fSmrg# The '<hooked_function_name>_result' variable is automatically unset
17415b16253fSmrg# before your hook gets called; for best performance, only set the
17425b16253fSmrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17435b16253fSmrg# function unnecessarily because it can be an expensive operation on some
17445b16253fSmrg# machines).
17455b16253fSmrg#
17465b16253fSmrg# Like this:
17475ec34c4cSmrg#
17485ec34c4cSmrg#    my_options_prep ()
17495ec34c4cSmrg#    {
17505ec34c4cSmrg#        $debug_cmd
17515ec34c4cSmrg#
17525ec34c4cSmrg#        # Extend the existing usage message.
17535ec34c4cSmrg#        usage_message=$usage_message'
17545ec34c4cSmrg#      -s, --silent       don'\''t print informational messages
17555ec34c4cSmrg#    '
17565b16253fSmrg#        # No change in '$@' (ignored completely by this hook).  Leave
17575b16253fSmrg#        # my_options_prep_result variable intact.
17585ec34c4cSmrg#    }
17595ec34c4cSmrg#    func_add_hook func_options_prep my_options_prep
17605ec34c4cSmrg#
17615ec34c4cSmrg#
17625ec34c4cSmrg#    my_silent_option ()
17635ec34c4cSmrg#    {
17645ec34c4cSmrg#        $debug_cmd
17655ec34c4cSmrg#
17665b16253fSmrg#        args_changed=false
17675b16253fSmrg#
17685b16253fSmrg#        # Note that, for efficiency, we parse as many options as we can
17695ec34c4cSmrg#        # recognise in a loop before passing the remainder back to the
17705ec34c4cSmrg#        # caller on the first unrecognised argument we encounter.
17715ec34c4cSmrg#        while test $# -gt 0; do
17725ec34c4cSmrg#          opt=$1; shift
17735ec34c4cSmrg#          case $opt in
17745b16253fSmrg#            --silent|-s) opt_silent=:
17755b16253fSmrg#                         args_changed=:
17765b16253fSmrg#                         ;;
17775ec34c4cSmrg#            # Separate non-argument short options:
17785ec34c4cSmrg#            -s*)         func_split_short_opt "$_G_opt"
17795ec34c4cSmrg#                         set dummy "$func_split_short_opt_name" \
17805ec34c4cSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
17815ec34c4cSmrg#                         shift
17825b16253fSmrg#                         args_changed=:
17835ec34c4cSmrg#                         ;;
17845b16253fSmrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17855b16253fSmrg#                         # is added back to "$@" in case we need it later,
17865b16253fSmrg#                         # if $args_changed was set to 'true'.
17875b16253fSmrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17885ec34c4cSmrg#          esac
17895ec34c4cSmrg#        done
17905ec34c4cSmrg#
17915b16253fSmrg#        # Only call 'func_quote' here if we processed at least one argument.
17925b16253fSmrg#        if $args_changed; then
17935b16253fSmrg#          func_quote eval ${1+"$@"}
17945b16253fSmrg#          my_silent_option_result=$func_quote_result
17955b16253fSmrg#        fi
17965ec34c4cSmrg#    }
17975ec34c4cSmrg#    func_add_hook func_parse_options my_silent_option
17985ec34c4cSmrg#
17995ec34c4cSmrg#
18005ec34c4cSmrg#    my_option_validation ()
18015ec34c4cSmrg#    {
18025ec34c4cSmrg#        $debug_cmd
18035ec34c4cSmrg#
18045ec34c4cSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
18055ec34c4cSmrg#    '--silent' and '--verbose' options are mutually exclusive."
18065ec34c4cSmrg#    }
18075ec34c4cSmrg#    func_add_hook func_validate_options my_option_validation
18085ec34c4cSmrg#
18095b16253fSmrg# You'll also need to manually amend $usage_message to reflect the extra
18105ec34c4cSmrg# options you parse.  It's preferable to append if you can, so that
18115ec34c4cSmrg# multiple option parsing hooks can be added safely.
18125ec34c4cSmrg
18135ec34c4cSmrg
18145b16253fSmrg# func_options_finish [ARG]...
18155b16253fSmrg# ----------------------------
18165b16253fSmrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18175b16253fSmrgfunc_options_finish ()
18185b16253fSmrg{
18195b16253fSmrg    $debug_cmd
18205b16253fSmrg
18215b16253fSmrg    func_run_hooks func_options ${1+"$@"}
18225b16253fSmrg    func_propagate_result func_run_hooks func_options_finish
18235b16253fSmrg}
18245b16253fSmrg
18255b16253fSmrg
18265ec34c4cSmrg# func_options [ARG]...
18275ec34c4cSmrg# ---------------------
18285ec34c4cSmrg# All the functions called inside func_options are hookable. See the
18295ec34c4cSmrg# individual implementations for details.
18305ec34c4cSmrgfunc_hookable func_options
18315ec34c4cSmrgfunc_options ()
18327a84e134Smrg{
18335ec34c4cSmrg    $debug_cmd
1834994689c1Smrg
18355b16253fSmrg    _G_options_quoted=false
1836994689c1Smrg
18375b16253fSmrg    for my_func in options_prep parse_options validate_options options_finish
18385b16253fSmrg    do
18395b16253fSmrg      func_unset func_${my_func}_result
18405b16253fSmrg      func_unset func_run_hooks_result
18415b16253fSmrg      eval func_$my_func '${1+"$@"}'
18425b16253fSmrg      func_propagate_result func_$my_func func_options
18435b16253fSmrg      if $func_propagate_result_result; then
18445b16253fSmrg        eval set dummy "$func_options_result"; shift
18455b16253fSmrg        _G_options_quoted=:
18465b16253fSmrg      fi
18475b16253fSmrg    done
18485ec34c4cSmrg
18495b16253fSmrg    $_G_options_quoted || {
18505b16253fSmrg      # As we (func_options) are top-level options-parser function and
18515b16253fSmrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18525b16253fSmrg      # caller.
18535b16253fSmrg      func_quote eval ${1+"$@"}
18545b16253fSmrg      func_options_result=$func_quote_result
18555b16253fSmrg    }
18567a84e134Smrg}
18577a84e134Smrg
18587a84e134Smrg
18595ec34c4cSmrg# func_options_prep [ARG]...
18605ec34c4cSmrg# --------------------------
18615ec34c4cSmrg# All initialisations required before starting the option parse loop.
18625ec34c4cSmrg# Note that when calling hook functions, we pass through the list of
18635ec34c4cSmrg# positional parameters.  If a hook function modifies that list, and
18645b16253fSmrg# needs to propagate that back to rest of this script, then the complete
18655b16253fSmrg# modified list must be put in 'func_run_hooks_result' before returning.
18665ec34c4cSmrgfunc_hookable func_options_prep
18675ec34c4cSmrgfunc_options_prep ()
18687a84e134Smrg{
18695ec34c4cSmrg    $debug_cmd
1870775e7de9Smrg
18715ec34c4cSmrg    # Option defaults:
18725ec34c4cSmrg    opt_verbose=false
18735ec34c4cSmrg    opt_warning_types=
1874994689c1Smrg
18755ec34c4cSmrg    func_run_hooks func_options_prep ${1+"$@"}
18765b16253fSmrg    func_propagate_result func_run_hooks func_options_prep
18777a84e134Smrg}
18787a84e134Smrg
1879994689c1Smrg
18805ec34c4cSmrg# func_parse_options [ARG]...
18815ec34c4cSmrg# ---------------------------
18825ec34c4cSmrg# The main option parsing loop.
18835ec34c4cSmrgfunc_hookable func_parse_options
18845ec34c4cSmrgfunc_parse_options ()
18857a84e134Smrg{
18865ec34c4cSmrg    $debug_cmd
18877a84e134Smrg
18885b16253fSmrg    _G_parse_options_requote=false
18895ec34c4cSmrg    # this just eases exit handling
18905ec34c4cSmrg    while test $# -gt 0; do
18915ec34c4cSmrg      # Defer to hook functions for initial option parsing, so they
18925ec34c4cSmrg      # get priority in the event of reusing an option name.
18935ec34c4cSmrg      func_run_hooks func_parse_options ${1+"$@"}
18945b16253fSmrg      func_propagate_result func_run_hooks func_parse_options
18955b16253fSmrg      if $func_propagate_result_result; then
18965b16253fSmrg        eval set dummy "$func_parse_options_result"; shift
18975b16253fSmrg        # Even though we may have changed "$@", we passed the "$@" array
18985b16253fSmrg        # down into the hook and it quoted it for us (because we are in
18995b16253fSmrg        # this if-branch).  No need to quote it again.
19005b16253fSmrg        _G_parse_options_requote=false
19015b16253fSmrg      fi
19025ec34c4cSmrg
19035ec34c4cSmrg      # Break out of the loop if we already parsed every option.
19045ec34c4cSmrg      test $# -gt 0 || break
19055ec34c4cSmrg
19065b16253fSmrg      # We expect that one of the options parsed in this function matches
19075b16253fSmrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19085b16253fSmrg      _G_match_parse_options=:
19095ec34c4cSmrg      _G_opt=$1
19105ec34c4cSmrg      shift
19115ec34c4cSmrg      case $_G_opt in
19125ec34c4cSmrg        --debug|-x)   debug_cmd='set -x'
19135b16253fSmrg                      func_echo "enabling shell trace mode" >&2
19145ec34c4cSmrg                      $debug_cmd
19155ec34c4cSmrg                      ;;
19165ec34c4cSmrg
19175ec34c4cSmrg        --no-warnings|--no-warning|--no-warn)
19185ec34c4cSmrg                      set dummy --warnings none ${1+"$@"}
19195ec34c4cSmrg                      shift
19205ec34c4cSmrg		      ;;
19215ec34c4cSmrg
19225ec34c4cSmrg        --warnings|--warning|-W)
19235b16253fSmrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19245b16253fSmrg                        _G_parse_options_requote=:
19255b16253fSmrg                        break
19265b16253fSmrg                      fi
19275ec34c4cSmrg                      case " $warning_categories $1" in
19285ec34c4cSmrg                        *" $1 "*)
19295ec34c4cSmrg                          # trailing space prevents matching last $1 above
19305ec34c4cSmrg                          func_append_uniq opt_warning_types " $1"
19315ec34c4cSmrg                          ;;
19325ec34c4cSmrg                        *all)
19335ec34c4cSmrg                          opt_warning_types=$warning_categories
19345ec34c4cSmrg                          ;;
19355ec34c4cSmrg                        *none)
19365ec34c4cSmrg                          opt_warning_types=none
19375ec34c4cSmrg                          warning_func=:
19385ec34c4cSmrg                          ;;
19395ec34c4cSmrg                        *error)
19405ec34c4cSmrg                          opt_warning_types=$warning_categories
19415ec34c4cSmrg                          warning_func=func_fatal_error
19425ec34c4cSmrg                          ;;
19435ec34c4cSmrg                        *)
19445ec34c4cSmrg                          func_fatal_error \
19455ec34c4cSmrg                             "unsupported warning category: '$1'"
19465ec34c4cSmrg                          ;;
19475ec34c4cSmrg                      esac
19485ec34c4cSmrg                      shift
19495ec34c4cSmrg                      ;;
19505ec34c4cSmrg
19515ec34c4cSmrg        --verbose|-v) opt_verbose=: ;;
19525ec34c4cSmrg        --version)    func_version ;;
19535ec34c4cSmrg        -\?|-h)       func_usage ;;
19545ec34c4cSmrg        --help)       func_help ;;
19555ec34c4cSmrg
19565ec34c4cSmrg	# Separate optargs to long options (plugins may need this):
19575ec34c4cSmrg	--*=*)        func_split_equals "$_G_opt"
19585ec34c4cSmrg	              set dummy "$func_split_equals_lhs" \
19595ec34c4cSmrg                          "$func_split_equals_rhs" ${1+"$@"}
19605ec34c4cSmrg                      shift
19615ec34c4cSmrg                      ;;
19625ec34c4cSmrg
19635ec34c4cSmrg       # Separate optargs to short options:
19645ec34c4cSmrg        -W*)
19655ec34c4cSmrg                      func_split_short_opt "$_G_opt"
19665ec34c4cSmrg                      set dummy "$func_split_short_opt_name" \
19675ec34c4cSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
19685ec34c4cSmrg                      shift
19695ec34c4cSmrg                      ;;
19705ec34c4cSmrg
19715ec34c4cSmrg        # Separate non-argument short options:
19725ec34c4cSmrg        -\?*|-h*|-v*|-x*)
19735ec34c4cSmrg                      func_split_short_opt "$_G_opt"
19745ec34c4cSmrg                      set dummy "$func_split_short_opt_name" \
19755ec34c4cSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
19765ec34c4cSmrg                      shift
19775ec34c4cSmrg                      ;;
19785ec34c4cSmrg
19795b16253fSmrg        --)           _G_parse_options_requote=: ; break ;;
19805ec34c4cSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19815b16253fSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19825b16253fSmrg                      _G_match_parse_options=false
19835b16253fSmrg                      break
19845b16253fSmrg                      ;;
19855ec34c4cSmrg      esac
19865b16253fSmrg
19875b16253fSmrg      if $_G_match_parse_options; then
19885b16253fSmrg        _G_parse_options_requote=:
19895b16253fSmrg      fi
19905ec34c4cSmrg    done
19915ec34c4cSmrg
19925b16253fSmrg    if $_G_parse_options_requote; then
19935b16253fSmrg      # save modified positional parameters for caller
19945b16253fSmrg      func_quote eval ${1+"$@"}
19955b16253fSmrg      func_parse_options_result=$func_quote_result
19965b16253fSmrg    fi
1997f353fbadSmrg}
1998f353fbadSmrg
1999775e7de9Smrg
20005ec34c4cSmrg# func_validate_options [ARG]...
20015ec34c4cSmrg# ------------------------------
20025ec34c4cSmrg# Perform any sanity checks on option settings and/or unconsumed
20035ec34c4cSmrg# arguments.
20045ec34c4cSmrgfunc_hookable func_validate_options
20055ec34c4cSmrgfunc_validate_options ()
2006994689c1Smrg{
20075ec34c4cSmrg    $debug_cmd
2008f353fbadSmrg
20095ec34c4cSmrg    # Display all warnings if -W was not given.
20105ec34c4cSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
20115ec34c4cSmrg
20125ec34c4cSmrg    func_run_hooks func_validate_options ${1+"$@"}
20135b16253fSmrg    func_propagate_result func_run_hooks func_validate_options
20145ec34c4cSmrg
20155ec34c4cSmrg    # Bail if the options were screwed!
20165ec34c4cSmrg    $exit_cmd $EXIT_FAILURE
2017994689c1Smrg}
2018775e7de9Smrg
20195ec34c4cSmrg
20205ec34c4cSmrg
20215ec34c4cSmrg## ----------------- ##
20225ec34c4cSmrg## Helper functions. ##
20235ec34c4cSmrg## ----------------- ##
20245ec34c4cSmrg
20255ec34c4cSmrg# This section contains the helper functions used by the rest of the
20265ec34c4cSmrg# hookable option parser framework in ascii-betical order.
20275ec34c4cSmrg
20285ec34c4cSmrg
20295ec34c4cSmrg# func_fatal_help ARG...
20305ec34c4cSmrg# ----------------------
20315ec34c4cSmrg# Echo program name prefixed message to standard error, followed by
20325ec34c4cSmrg# a help hint, and exit.
20335ec34c4cSmrgfunc_fatal_help ()
2034994689c1Smrg{
20355ec34c4cSmrg    $debug_cmd
2036f353fbadSmrg
20375ec34c4cSmrg    eval \$ECHO \""Usage: $usage"\"
20385ec34c4cSmrg    eval \$ECHO \""$fatal_help"\"
20395ec34c4cSmrg    func_error ${1+"$@"}
20405ec34c4cSmrg    exit $EXIT_FAILURE
2041994689c1Smrg}
20427a84e134Smrg
20435ec34c4cSmrg
20445ec34c4cSmrg# func_help
20455ec34c4cSmrg# ---------
20465ec34c4cSmrg# Echo long help message to standard output and exit.
2047994689c1Smrgfunc_help ()
2048994689c1Smrg{
20495ec34c4cSmrg    $debug_cmd
20505ec34c4cSmrg
20515ec34c4cSmrg    func_usage_message
20525ec34c4cSmrg    $ECHO "$long_help_message"
20535ec34c4cSmrg    exit 0
2054994689c1Smrg}
20557a84e134Smrg
20565ec34c4cSmrg
20575ec34c4cSmrg# func_missing_arg ARGNAME
20585ec34c4cSmrg# ------------------------
2059994689c1Smrg# Echo program name prefixed message to standard error and set global
2060994689c1Smrg# exit_cmd.
2061994689c1Smrgfunc_missing_arg ()
2062994689c1Smrg{
20635ec34c4cSmrg    $debug_cmd
2064f353fbadSmrg
20655ec34c4cSmrg    func_error "Missing argument for '$1'."
2066994689c1Smrg    exit_cmd=exit
2067994689c1Smrg}
20687a84e134Smrg
2069775e7de9Smrg
20705ec34c4cSmrg# func_split_equals STRING
20715ec34c4cSmrg# ------------------------
20725b16253fSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20735b16253fSmrg# after splitting STRING at the '=' sign.
20745ec34c4cSmrgtest -z "$_G_HAVE_XSI_OPS" \
20755ec34c4cSmrg    && (eval 'x=a/b/c;
20765ec34c4cSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
20775ec34c4cSmrg    && _G_HAVE_XSI_OPS=yes
20785ec34c4cSmrg
20795ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"
20805ec34c4cSmrgthen
20815ec34c4cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
20825ec34c4cSmrg  eval 'func_split_equals ()
20835ec34c4cSmrg  {
20845ec34c4cSmrg      $debug_cmd
20855ec34c4cSmrg
20865ec34c4cSmrg      func_split_equals_lhs=${1%%=*}
20875ec34c4cSmrg      func_split_equals_rhs=${1#*=}
20885b16253fSmrg      if test "x$func_split_equals_lhs" = "x$1"; then
20895b16253fSmrg        func_split_equals_rhs=
20905b16253fSmrg      fi
20915ec34c4cSmrg  }'
20925ec34c4cSmrgelse
20935ec34c4cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
20945ec34c4cSmrg  func_split_equals ()
20955ec34c4cSmrg  {
20965ec34c4cSmrg      $debug_cmd
20975ec34c4cSmrg
20985ec34c4cSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
20995ec34c4cSmrg      func_split_equals_rhs=
21005b16253fSmrg      test "x$func_split_equals_lhs=" = "x$1" \
21015ec34c4cSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
21025ec34c4cSmrg  }
21035ec34c4cSmrgfi #func_split_equals
21045ec34c4cSmrg
21055ec34c4cSmrg
21065ec34c4cSmrg# func_split_short_opt SHORTOPT
21075ec34c4cSmrg# -----------------------------
2108f353fbadSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2109f353fbadSmrg# variables after splitting SHORTOPT after the 2nd character.
21105ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"
21115ec34c4cSmrgthen
21125ec34c4cSmrg  # This is an XSI compatible shell, allowing a faster implementation...
21135ec34c4cSmrg  eval 'func_split_short_opt ()
21145ec34c4cSmrg  {
21155ec34c4cSmrg      $debug_cmd
21165ec34c4cSmrg
21175ec34c4cSmrg      func_split_short_opt_arg=${1#??}
21185ec34c4cSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
21195ec34c4cSmrg  }'
21205ec34c4cSmrgelse
21215ec34c4cSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
21225ec34c4cSmrg  func_split_short_opt ()
21235ec34c4cSmrg  {
21245ec34c4cSmrg      $debug_cmd
21255ec34c4cSmrg
21265b16253fSmrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
21275ec34c4cSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
21285ec34c4cSmrg  }
21295ec34c4cSmrgfi #func_split_short_opt
21305ec34c4cSmrg
21315ec34c4cSmrg
21325ec34c4cSmrg# func_usage
21335ec34c4cSmrg# ----------
21345ec34c4cSmrg# Echo short help message to standard output and exit.
21355ec34c4cSmrgfunc_usage ()
2136f353fbadSmrg{
21375ec34c4cSmrg    $debug_cmd
2138f353fbadSmrg
21395ec34c4cSmrg    func_usage_message
21405ec34c4cSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
21415ec34c4cSmrg    exit 0
21425ec34c4cSmrg}
2143f353fbadSmrg
2144f353fbadSmrg
21455ec34c4cSmrg# func_usage_message
21465ec34c4cSmrg# ------------------
21475ec34c4cSmrg# Echo short help message to standard output.
21485ec34c4cSmrgfunc_usage_message ()
2149f353fbadSmrg{
21505ec34c4cSmrg    $debug_cmd
2151f353fbadSmrg
21525ec34c4cSmrg    eval \$ECHO \""Usage: $usage"\"
21535ec34c4cSmrg    echo
21545ec34c4cSmrg    $SED -n 's|^# ||
21555ec34c4cSmrg        /^Written by/{
21565ec34c4cSmrg          x;p;x
21575ec34c4cSmrg        }
21585ec34c4cSmrg	h
21595ec34c4cSmrg	/^Written by/q' < "$progpath"
21605ec34c4cSmrg    echo
21615ec34c4cSmrg    eval \$ECHO \""$usage_message"\"
21625ec34c4cSmrg}
2163f353fbadSmrg
21647a84e134Smrg
21655ec34c4cSmrg# func_version
21665ec34c4cSmrg# ------------
21675ec34c4cSmrg# Echo version message to standard output and exit.
21685b16253fSmrg# The version message is extracted from the calling file's header
21695b16253fSmrg# comments, with leading '# ' stripped:
21705b16253fSmrg#   1. First display the progname and version
21715b16253fSmrg#   2. Followed by the header comment line matching  /^# Written by /
21725b16253fSmrg#   3. Then a blank line followed by the first following line matching
21735b16253fSmrg#      /^# Copyright /
21745b16253fSmrg#   4. Immediately followed by any lines between the previous matches,
21755b16253fSmrg#      except lines preceding the intervening completely blank line.
21765b16253fSmrg# For example, see the header comments of this file.
21775ec34c4cSmrgfunc_version ()
21785ec34c4cSmrg{
21795ec34c4cSmrg    $debug_cmd
2180ab902922Smrg
21815ec34c4cSmrg    printf '%s\n' "$progname $scriptversion"
21825ec34c4cSmrg    $SED -n '
21835b16253fSmrg        /^# Written by /!b
21845b16253fSmrg        s|^# ||; p; n
21855b16253fSmrg
21865b16253fSmrg        :fwd2blnk
21875b16253fSmrg        /./ {
21885b16253fSmrg          n
21895b16253fSmrg          b fwd2blnk
21905ec34c4cSmrg        }
21915b16253fSmrg        p; n
21925b16253fSmrg
21935b16253fSmrg        :holdwrnt
21945b16253fSmrg        s|^# ||
21955b16253fSmrg        s|^# *$||
21965b16253fSmrg        /^Copyright /!{
21975b16253fSmrg          /./H
21985b16253fSmrg          n
21995b16253fSmrg          b holdwrnt
22005ec34c4cSmrg        }
22015b16253fSmrg
22025b16253fSmrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22035b16253fSmrg        G
22045b16253fSmrg        s|\(\n\)\n*|\1|g
22055b16253fSmrg        p; q' < "$progpath"
2206775e7de9Smrg
22075ec34c4cSmrg    exit $?
22085ec34c4cSmrg}
22097a84e134Smrg
2210994689c1Smrg
22115ec34c4cSmrg# Local variables:
22125ec34c4cSmrg# mode: shell-script
22135ec34c4cSmrg# sh-indentation: 2
22145ec34c4cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
22155b16253fSmrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
22165ec34c4cSmrg# time-stamp-time-zone: "UTC"
22175ec34c4cSmrg# End:
2218994689c1Smrg
22195ec34c4cSmrg# Set a version string.
22205b16253fSmrgscriptversion='(GNU libtool) 2.4.7'
2221994689c1Smrg
2222994689c1Smrg
22235ec34c4cSmrg# func_echo ARG...
22245ec34c4cSmrg# ----------------
22255ec34c4cSmrg# Libtool also displays the current mode in messages, so override
22265ec34c4cSmrg# funclib.sh func_echo with this custom definition.
22275ec34c4cSmrgfunc_echo ()
2228f353fbadSmrg{
22295ec34c4cSmrg    $debug_cmd
2230f353fbadSmrg
22315ec34c4cSmrg    _G_message=$*
2232f353fbadSmrg
22335ec34c4cSmrg    func_echo_IFS=$IFS
22345ec34c4cSmrg    IFS=$nl
22355ec34c4cSmrg    for _G_line in $_G_message; do
22365ec34c4cSmrg      IFS=$func_echo_IFS
22375ec34c4cSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
22385ec34c4cSmrg    done
22395ec34c4cSmrg    IFS=$func_echo_IFS
22405ec34c4cSmrg}
2241f353fbadSmrg
22425ec34c4cSmrg
22435ec34c4cSmrg# func_warning ARG...
22445ec34c4cSmrg# -------------------
22455ec34c4cSmrg# Libtool warnings are not categorized, so override funclib.sh
22465ec34c4cSmrg# func_warning with this simpler definition.
22475ec34c4cSmrgfunc_warning ()
2248f353fbadSmrg{
22495ec34c4cSmrg    $debug_cmd
2250f353fbadSmrg
22515ec34c4cSmrg    $warning_func ${1+"$@"}
22525ec34c4cSmrg}
2253f353fbadSmrg
2254f353fbadSmrg
22555ec34c4cSmrg## ---------------- ##
22565ec34c4cSmrg## Options parsing. ##
22575ec34c4cSmrg## ---------------- ##
22585ec34c4cSmrg
22595ec34c4cSmrg# Hook in the functions to make sure our own options are parsed during
22605ec34c4cSmrg# the option parsing loop.
22615ec34c4cSmrg
22625ec34c4cSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
22635ec34c4cSmrg
22645ec34c4cSmrg# Short help message in response to '-h'.
22655ec34c4cSmrgusage_message="Options:
22665ec34c4cSmrg       --config             show all configuration variables
22675ec34c4cSmrg       --debug              enable verbose shell tracing
22685ec34c4cSmrg   -n, --dry-run            display commands without modifying any files
22695ec34c4cSmrg       --features           display basic configuration information and exit
22705ec34c4cSmrg       --mode=MODE          use operation mode MODE
22715ec34c4cSmrg       --no-warnings        equivalent to '-Wnone'
22725ec34c4cSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
22735ec34c4cSmrg       --quiet, --silent    don't print informational messages
22745ec34c4cSmrg       --tag=TAG            use configuration variables from tag TAG
22755ec34c4cSmrg   -v, --verbose            print more informational messages than default
22765ec34c4cSmrg       --version            print version information
22775ec34c4cSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
22785ec34c4cSmrg   -h, --help, --help-all   print short, long, or detailed help message
22795ec34c4cSmrg"
2280f353fbadSmrg
22815ec34c4cSmrg# Additional text appended to 'usage_message' in response to '--help'.
22825ec34c4cSmrgfunc_help ()
2283f353fbadSmrg{
22845ec34c4cSmrg    $debug_cmd
22855ec34c4cSmrg
22865ec34c4cSmrg    func_usage_message
22875ec34c4cSmrg    $ECHO "$long_help_message
22885ec34c4cSmrg
22895ec34c4cSmrgMODE must be one of the following:
22905ec34c4cSmrg
22915ec34c4cSmrg       clean           remove files from the build directory
22925ec34c4cSmrg       compile         compile a source file into a libtool object
22935ec34c4cSmrg       execute         automatically set library path, then run a program
22945ec34c4cSmrg       finish          complete the installation of libtool libraries
22955ec34c4cSmrg       install         install libraries or executables
22965ec34c4cSmrg       link            create a library or an executable
22975ec34c4cSmrg       uninstall       remove libraries from an installed directory
22985ec34c4cSmrg
22995ec34c4cSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
23005ec34c4cSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
23015ec34c4cSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
23025ec34c4cSmrg
23035ec34c4cSmrgWhen reporting a bug, please describe a test case to reproduce it and
23045ec34c4cSmrginclude the following information:
23055ec34c4cSmrg
23065ec34c4cSmrg       host-triplet:   $host
23075ec34c4cSmrg       shell:          $SHELL
23085ec34c4cSmrg       compiler:       $LTCC
23095ec34c4cSmrg       compiler flags: $LTCFLAGS
23105ec34c4cSmrg       linker:         $LD (gnu? $with_gnu_ld)
2311efbcb2bfSmrg       version:        $progname $scriptversion Debian-2.4.7-5
23125ec34c4cSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
23135ec34c4cSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
23145ec34c4cSmrg
23155ec34c4cSmrgReport bugs to <bug-libtool@gnu.org>.
2316efbcb2bfSmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
23175ec34c4cSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
23185ec34c4cSmrg    exit 0
23195ec34c4cSmrg}
2320f353fbadSmrg
2321f353fbadSmrg
23225ec34c4cSmrg# func_lo2o OBJECT-NAME
23235ec34c4cSmrg# ---------------------
23245ec34c4cSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
23255ec34c4cSmrg# object suffix.
23265ec34c4cSmrg
23275ec34c4cSmrglo2o=s/\\.lo\$/.$objext/
23285ec34c4cSmrgo2lo=s/\\.$objext\$/.lo/
23295ec34c4cSmrg
23305ec34c4cSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
23315ec34c4cSmrg  eval 'func_lo2o ()
23325ec34c4cSmrg  {
23335ec34c4cSmrg    case $1 in
23345ec34c4cSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
23355ec34c4cSmrg      *   ) func_lo2o_result=$1               ;;
23365ec34c4cSmrg    esac
23375ec34c4cSmrg  }'
23385ec34c4cSmrg
23395ec34c4cSmrg  # func_xform LIBOBJ-OR-SOURCE
23405ec34c4cSmrg  # ---------------------------
23415ec34c4cSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
23425ec34c4cSmrg  # suffix to a '.lo' libtool-object suffix.
23435ec34c4cSmrg  eval 'func_xform ()
23445ec34c4cSmrg  {
23455ec34c4cSmrg    func_xform_result=${1%.*}.lo
23465ec34c4cSmrg  }'
23475ec34c4cSmrgelse
23485ec34c4cSmrg  # ...otherwise fall back to using sed.
23495ec34c4cSmrg  func_lo2o ()
23505ec34c4cSmrg  {
23515ec34c4cSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
23525ec34c4cSmrg  }
23535ec34c4cSmrg
23545ec34c4cSmrg  func_xform ()
23555ec34c4cSmrg  {
23565ec34c4cSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
23575ec34c4cSmrg  }
23585ec34c4cSmrgfi
2359f353fbadSmrg
2360f353fbadSmrg
23615ec34c4cSmrg# func_fatal_configuration ARG...
23625ec34c4cSmrg# -------------------------------
2363994689c1Smrg# Echo program name prefixed message to standard error, followed by
2364994689c1Smrg# a configuration failure hint, and exit.
2365994689c1Smrgfunc_fatal_configuration ()
2366994689c1Smrg{
23675b16253fSmrg    func_fatal_error ${1+"$@"} \
23685ec34c4cSmrg      "See the $PACKAGE documentation for more information." \
23695ec34c4cSmrg      "Fatal configuration error."
2370994689c1Smrg}
2371994689c1Smrg
2372994689c1Smrg
2373994689c1Smrg# func_config
23745ec34c4cSmrg# -----------
2375994689c1Smrg# Display the configuration for all the tags in this script.
2376994689c1Smrgfunc_config ()
2377994689c1Smrg{
2378994689c1Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2379994689c1Smrg    re_endcf='^# ### END LIBTOOL'
2380994689c1Smrg
2381994689c1Smrg    # Default configuration.
2382994689c1Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2383994689c1Smrg
23847a84e134Smrg    # Now print the configurations for the tags.
23857a84e134Smrg    for tagname in $taglist; do
2386994689c1Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
23877a84e134Smrg    done
2388e1e1713cSmrg
2389994689c1Smrg    exit $?
2390994689c1Smrg}
2391e1e1713cSmrg
23925ec34c4cSmrg
2393994689c1Smrg# func_features
23945ec34c4cSmrg# -------------
2395994689c1Smrg# Display the features supported by this script.
2396994689c1Smrgfunc_features ()
2397994689c1Smrg{
2398994689c1Smrg    echo "host: $host"
23995ec34c4cSmrg    if test yes = "$build_libtool_libs"; then
2400994689c1Smrg      echo "enable shared libraries"
24017a84e134Smrg    else
2402994689c1Smrg      echo "disable shared libraries"
24037a84e134Smrg    fi
24045ec34c4cSmrg    if test yes = "$build_old_libs"; then
2405994689c1Smrg      echo "enable static libraries"
24067a84e134Smrg    else
2407994689c1Smrg      echo "disable static libraries"
24087a84e134Smrg    fi
2409994689c1Smrg
24107a84e134Smrg    exit $?
2411994689c1Smrg}
24127a84e134Smrg
24135ec34c4cSmrg
24145ec34c4cSmrg# func_enable_tag TAGNAME
24155ec34c4cSmrg# -----------------------
2416994689c1Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2417994689c1Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2418994689c1Smrg# variable here.
2419994689c1Smrgfunc_enable_tag ()
2420994689c1Smrg{
24215ec34c4cSmrg    # Global variable:
24225ec34c4cSmrg    tagname=$1
24237a84e134Smrg
24245ec34c4cSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
24255ec34c4cSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
24265ec34c4cSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2427775e7de9Smrg
24285ec34c4cSmrg    # Validate tagname.
24295ec34c4cSmrg    case $tagname in
24305ec34c4cSmrg      *[!-_A-Za-z0-9,/]*)
24315ec34c4cSmrg        func_fatal_error "invalid tag name: $tagname"
24325ec34c4cSmrg        ;;
24335ec34c4cSmrg    esac
24347a84e134Smrg
24355ec34c4cSmrg    # Don't test for the "default" C tag, as we know it's
24365ec34c4cSmrg    # there but not specially marked.
24375ec34c4cSmrg    case $tagname in
24385ec34c4cSmrg        CC) ;;
2439994689c1Smrg    *)
24405ec34c4cSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
24415ec34c4cSmrg	  taglist="$taglist $tagname"
24425ec34c4cSmrg
24435ec34c4cSmrg	  # Evaluate the configuration.  Be careful to quote the path
24445ec34c4cSmrg	  # and the sed script, to avoid splitting on whitespace, but
24455ec34c4cSmrg	  # also don't use non-portable quotes within backquotes within
24465ec34c4cSmrg	  # quotes we have to do it in 2 steps:
24475ec34c4cSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
24485ec34c4cSmrg	  eval "$extractedcf"
24495ec34c4cSmrg        else
24505ec34c4cSmrg	  func_error "ignoring unknown tag $tagname"
24515ec34c4cSmrg        fi
24525ec34c4cSmrg        ;;
24535ec34c4cSmrg    esac
2454994689c1Smrg}
2455994689c1Smrg
24565ec34c4cSmrg
2457f353fbadSmrg# func_check_version_match
24585ec34c4cSmrg# ------------------------
2459f353fbadSmrg# Ensure that we are using m4 macros, and libtool script from the same
2460f353fbadSmrg# release of libtool.
2461f353fbadSmrgfunc_check_version_match ()
2462994689c1Smrg{
24635ec34c4cSmrg    if test "$package_revision" != "$macro_revision"; then
24645ec34c4cSmrg      if test "$VERSION" != "$macro_version"; then
24655ec34c4cSmrg        if test -z "$macro_version"; then
24665ec34c4cSmrg          cat >&2 <<_LT_EOF
2467f353fbadSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2468f353fbadSmrg$progname: definition of this LT_INIT comes from an older release.
2469f353fbadSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2470f353fbadSmrg$progname: and run autoconf again.
2471f353fbadSmrg_LT_EOF
24725ec34c4cSmrg        else
24735ec34c4cSmrg          cat >&2 <<_LT_EOF
2474f353fbadSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2475f353fbadSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2476f353fbadSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2477f353fbadSmrg$progname: and run autoconf again.
2478f353fbadSmrg_LT_EOF
24795ec34c4cSmrg        fi
24805ec34c4cSmrg      else
24815ec34c4cSmrg        cat >&2 <<_LT_EOF
2482f353fbadSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2483f353fbadSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2484f353fbadSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2485f353fbadSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2486f353fbadSmrg_LT_EOF
24875ec34c4cSmrg      fi
2488e1e1713cSmrg
24895ec34c4cSmrg      exit $EXIT_MISMATCH
24905ec34c4cSmrg    fi
2491f353fbadSmrg}
2492f353fbadSmrg
2493f353fbadSmrg
24945ec34c4cSmrg# libtool_options_prep [ARG]...
24955ec34c4cSmrg# -----------------------------
24965ec34c4cSmrg# Preparation for options parsed by libtool.
24975ec34c4cSmrglibtool_options_prep ()
24985ec34c4cSmrg{
24995ec34c4cSmrg    $debug_mode
25007a84e134Smrg
25015ec34c4cSmrg    # Option defaults:
25025ec34c4cSmrg    opt_config=false
25035ec34c4cSmrg    opt_dlopen=
25045ec34c4cSmrg    opt_dry_run=false
25055ec34c4cSmrg    opt_help=false
25065ec34c4cSmrg    opt_mode=
25075ec34c4cSmrg    opt_preserve_dup_deps=false
25085ec34c4cSmrg    opt_quiet=false
2509f353fbadSmrg
25105ec34c4cSmrg    nonopt=
25115ec34c4cSmrg    preserve_args=
2512f353fbadSmrg
25135b16253fSmrg    _G_rc_lt_options_prep=:
25145b16253fSmrg
2515efbcb2bfSmrg    _G_rc_lt_options_prep=:
2516efbcb2bfSmrg
25175ec34c4cSmrg    # Shorthand for --mode=foo, only valid as the first argument
25185ec34c4cSmrg    case $1 in
25195ec34c4cSmrg    clean|clea|cle|cl)
25205ec34c4cSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
25215ec34c4cSmrg      ;;
25225ec34c4cSmrg    compile|compil|compi|comp|com|co|c)
25235ec34c4cSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
25245ec34c4cSmrg      ;;
25255ec34c4cSmrg    execute|execut|execu|exec|exe|ex|e)
25265ec34c4cSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
25275ec34c4cSmrg      ;;
25285ec34c4cSmrg    finish|finis|fini|fin|fi|f)
25295ec34c4cSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
25305ec34c4cSmrg      ;;
25315ec34c4cSmrg    install|instal|insta|inst|ins|in|i)
25325ec34c4cSmrg      shift; set dummy --mode install ${1+"$@"}; shift
25335ec34c4cSmrg      ;;
25345ec34c4cSmrg    link|lin|li|l)
25355ec34c4cSmrg      shift; set dummy --mode link ${1+"$@"}; shift
25365ec34c4cSmrg      ;;
25375ec34c4cSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
25385ec34c4cSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
25395ec34c4cSmrg      ;;
25405b16253fSmrg    *)
25415b16253fSmrg      _G_rc_lt_options_prep=false
25425b16253fSmrg      ;;
25435ec34c4cSmrg    esac
25445ec34c4cSmrg
25455b16253fSmrg    if $_G_rc_lt_options_prep; then
25465b16253fSmrg      # Pass back the list of options.
25475b16253fSmrg      func_quote eval ${1+"$@"}
25485b16253fSmrg      libtool_options_prep_result=$func_quote_result
25495b16253fSmrg    fi
25505ec34c4cSmrg}
25515ec34c4cSmrgfunc_add_hook func_options_prep libtool_options_prep
2552f353fbadSmrg
2553f353fbadSmrg
25545ec34c4cSmrg# libtool_parse_options [ARG]...
25555ec34c4cSmrg# ---------------------------------
25565ec34c4cSmrg# Provide handling for libtool specific options.
25575ec34c4cSmrglibtool_parse_options ()
2558f353fbadSmrg{
25595ec34c4cSmrg    $debug_cmd
2560994689c1Smrg
25615b16253fSmrg    _G_rc_lt_parse_options=false
25625b16253fSmrg
25635ec34c4cSmrg    # Perform our own loop to consume as many options as possible in
25645ec34c4cSmrg    # each iteration.
25655ec34c4cSmrg    while test $# -gt 0; do
25665b16253fSmrg      _G_match_lt_parse_options=:
25675ec34c4cSmrg      _G_opt=$1
25685ec34c4cSmrg      shift
25695ec34c4cSmrg      case $_G_opt in
25705ec34c4cSmrg        --dry-run|--dryrun|-n)
25715ec34c4cSmrg                        opt_dry_run=:
25725ec34c4cSmrg                        ;;
25735ec34c4cSmrg
25745ec34c4cSmrg        --config)       func_config ;;
25755ec34c4cSmrg
25765ec34c4cSmrg        --dlopen|-dlopen)
25775ec34c4cSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
25785ec34c4cSmrg}$1"
25795ec34c4cSmrg                        shift
25805ec34c4cSmrg                        ;;
25815ec34c4cSmrg
25825ec34c4cSmrg        --preserve-dup-deps)
25835ec34c4cSmrg                        opt_preserve_dup_deps=: ;;
25845ec34c4cSmrg
25855ec34c4cSmrg        --features)     func_features ;;
25865ec34c4cSmrg
25875ec34c4cSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
25885ec34c4cSmrg
25895ec34c4cSmrg        --help)         opt_help=: ;;
25905ec34c4cSmrg
25915ec34c4cSmrg        --help-all)     opt_help=': help-all' ;;
25925ec34c4cSmrg
25935ec34c4cSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
25945ec34c4cSmrg                        opt_mode=$1
25955ec34c4cSmrg                        case $1 in
25965ec34c4cSmrg                          # Valid mode arguments:
25975ec34c4cSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
25985ec34c4cSmrg
25995ec34c4cSmrg                          # Catch anything else as an error
26005ec34c4cSmrg                          *) func_error "invalid argument for $_G_opt"
26015ec34c4cSmrg                             exit_cmd=exit
26025ec34c4cSmrg                             break
26035ec34c4cSmrg                             ;;
26045ec34c4cSmrg                        esac
26055ec34c4cSmrg                        shift
26065ec34c4cSmrg                        ;;
26075ec34c4cSmrg
26085ec34c4cSmrg        --no-silent|--no-quiet)
26095ec34c4cSmrg                        opt_quiet=false
26105ec34c4cSmrg                        func_append preserve_args " $_G_opt"
26115ec34c4cSmrg                        ;;
26125ec34c4cSmrg
26135ec34c4cSmrg        --no-warnings|--no-warning|--no-warn)
26145ec34c4cSmrg                        opt_warning=false
26155ec34c4cSmrg                        func_append preserve_args " $_G_opt"
26165ec34c4cSmrg                        ;;
26175ec34c4cSmrg
26185ec34c4cSmrg        --no-verbose)
26195ec34c4cSmrg                        opt_verbose=false
26205ec34c4cSmrg                        func_append preserve_args " $_G_opt"
26215ec34c4cSmrg                        ;;
26225ec34c4cSmrg
26235ec34c4cSmrg        --silent|--quiet)
26245ec34c4cSmrg                        opt_quiet=:
26255ec34c4cSmrg                        opt_verbose=false
26265ec34c4cSmrg                        func_append preserve_args " $_G_opt"
26275ec34c4cSmrg                        ;;
26285ec34c4cSmrg
26295ec34c4cSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
26305ec34c4cSmrg                        opt_tag=$1
26315ec34c4cSmrg                        func_append preserve_args " $_G_opt $1"
26325ec34c4cSmrg                        func_enable_tag "$1"
26335ec34c4cSmrg                        shift
26345ec34c4cSmrg                        ;;
26355ec34c4cSmrg
26365ec34c4cSmrg        --verbose|-v)   opt_quiet=false
26375ec34c4cSmrg                        opt_verbose=:
26385ec34c4cSmrg                        func_append preserve_args " $_G_opt"
26395ec34c4cSmrg                        ;;
26405ec34c4cSmrg
26415b16253fSmrg        # An option not handled by this hook function:
26425b16253fSmrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26435b16253fSmrg                        _G_match_lt_parse_options=false
26445b16253fSmrg                        break
26455b16253fSmrg                        ;;
26465ec34c4cSmrg      esac
26475b16253fSmrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
26485ec34c4cSmrg    done
2649f353fbadSmrg
26505b16253fSmrg    if $_G_rc_lt_parse_options; then
26515b16253fSmrg      # save modified positional parameters for caller
26525b16253fSmrg      func_quote eval ${1+"$@"}
26535b16253fSmrg      libtool_parse_options_result=$func_quote_result
26545b16253fSmrg    fi
26555ec34c4cSmrg}
26565ec34c4cSmrgfunc_add_hook func_parse_options libtool_parse_options
2657994689c1Smrg
2658775e7de9Smrg
2659994689c1Smrg
26605ec34c4cSmrg# libtool_validate_options [ARG]...
26615ec34c4cSmrg# ---------------------------------
26625ec34c4cSmrg# Perform any sanity checks on option settings and/or unconsumed
26635ec34c4cSmrg# arguments.
26645ec34c4cSmrglibtool_validate_options ()
26655ec34c4cSmrg{
26665ec34c4cSmrg    # save first non-option argument
26675ec34c4cSmrg    if test 0 -lt $#; then
26685ec34c4cSmrg      nonopt=$1
26695ec34c4cSmrg      shift
2670994689c1Smrg    fi
2671994689c1Smrg
26725ec34c4cSmrg    # preserve --debug
26735ec34c4cSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2674994689c1Smrg
26755ec34c4cSmrg    case $host in
26765ec34c4cSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
26775ec34c4cSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
26785ec34c4cSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
26795ec34c4cSmrg        # don't eliminate duplications in $postdeps and $predeps
26805ec34c4cSmrg        opt_duplicate_compiler_generated_deps=:
26815ec34c4cSmrg        ;;
26825ec34c4cSmrg      *)
26835ec34c4cSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
26845ec34c4cSmrg        ;;
26855ec34c4cSmrg    esac
2686994689c1Smrg
26875ec34c4cSmrg    $opt_help || {
26885ec34c4cSmrg      # Sanity checks first:
26895ec34c4cSmrg      func_check_version_match
26905ec34c4cSmrg
26915ec34c4cSmrg      test yes != "$build_libtool_libs" \
26925ec34c4cSmrg        && test yes != "$build_old_libs" \
26935ec34c4cSmrg        && func_fatal_configuration "not configured to build any kind of library"
26945ec34c4cSmrg
26955ec34c4cSmrg      # Darwin sucks
26965ec34c4cSmrg      eval std_shrext=\"$shrext_cmds\"
26975ec34c4cSmrg
26985ec34c4cSmrg      # Only execute mode is allowed to have -dlopen flags.
26995ec34c4cSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
27005ec34c4cSmrg        func_error "unrecognized option '-dlopen'"
27015ec34c4cSmrg        $ECHO "$help" 1>&2
27025ec34c4cSmrg        exit $EXIT_FAILURE
27035ec34c4cSmrg      fi
2704994689c1Smrg
27055ec34c4cSmrg      # Change the help message to a mode-specific one.
27065ec34c4cSmrg      generic_help=$help
27075ec34c4cSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
27085ec34c4cSmrg    }
2709994689c1Smrg
27105ec34c4cSmrg    # Pass back the unparsed argument list
27115b16253fSmrg    func_quote eval ${1+"$@"}
27125b16253fSmrg    libtool_validate_options_result=$func_quote_result
2713f353fbadSmrg}
27145ec34c4cSmrgfunc_add_hook func_validate_options libtool_validate_options
2715994689c1Smrg
2716994689c1Smrg
27175ec34c4cSmrg# Process options as early as possible so that --help and --version
27185ec34c4cSmrg# can return quickly.
27195ec34c4cSmrgfunc_options ${1+"$@"}
27205ec34c4cSmrgeval set dummy "$func_options_result"; shift
27215ec34c4cSmrg
27227a84e134Smrg
27237a84e134Smrg
2724f353fbadSmrg## ----------- ##
2725f353fbadSmrg##    Main.    ##
2726f353fbadSmrg## ----------- ##
27277a84e134Smrg
27285ec34c4cSmrgmagic='%%%MAGIC variable%%%'
27295ec34c4cSmrgmagic_exe='%%%MAGIC EXE variable%%%'
27305ec34c4cSmrg
27315ec34c4cSmrg# Global variables.
27325ec34c4cSmrgextracted_archives=
27335ec34c4cSmrgextracted_serial=0
27345ec34c4cSmrg
27355ec34c4cSmrg# If this variable is set in any of the actions, the command in it
27365ec34c4cSmrg# will be execed at the end.  This prevents here-documents from being
27375ec34c4cSmrg# left over by shells.
27385ec34c4cSmrgexec_cmd=
27395ec34c4cSmrg
27405ec34c4cSmrg
27415ec34c4cSmrg# A function that is used when there is no print builtin or printf.
27425ec34c4cSmrgfunc_fallback_echo ()
27435ec34c4cSmrg{
27445ec34c4cSmrg  eval 'cat <<_LTECHO_EOF
27455ec34c4cSmrg$1
27465ec34c4cSmrg_LTECHO_EOF'
27475ec34c4cSmrg}
27485ec34c4cSmrg
27495ec34c4cSmrg# func_generated_by_libtool
27505ec34c4cSmrg# True iff stdin has been generated by Libtool. This function is only
27515ec34c4cSmrg# a basic sanity check; it will hardly flush out determined imposters.
27525ec34c4cSmrgfunc_generated_by_libtool_p ()
27535ec34c4cSmrg{
27545ec34c4cSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
27555ec34c4cSmrg}
27565ec34c4cSmrg
2757994689c1Smrg# func_lalib_p file
27585ec34c4cSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2759994689c1Smrg# This function is only a basic sanity check; it will hardly flush out
2760994689c1Smrg# determined imposters.
2761994689c1Smrgfunc_lalib_p ()
2762994689c1Smrg{
2763994689c1Smrg    test -f "$1" &&
27645ec34c4cSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2765994689c1Smrg}
27667a84e134Smrg
2767994689c1Smrg# func_lalib_unsafe_p file
27685ec34c4cSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2769994689c1Smrg# This function implements the same check as func_lalib_p without
2770994689c1Smrg# resorting to external programs.  To this end, it redirects stdin and
2771994689c1Smrg# closes it afterwards, without saving the original file descriptor.
2772994689c1Smrg# As a safety measure, use it only where a negative result would be
27735ec34c4cSmrg# fatal anyway.  Works if 'file' does not exist.
2774994689c1Smrgfunc_lalib_unsafe_p ()
2775994689c1Smrg{
2776994689c1Smrg    lalib_p=no
2777994689c1Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2778994689c1Smrg	for lalib_p_l in 1 2 3 4
2779994689c1Smrg	do
2780994689c1Smrg	    read lalib_p_line
27815ec34c4cSmrg	    case $lalib_p_line in
2782994689c1Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2783994689c1Smrg	    esac
2784994689c1Smrg	done
2785994689c1Smrg	exec 0<&5 5<&-
2786994689c1Smrg    fi
27875ec34c4cSmrg    test yes = "$lalib_p"
2788994689c1Smrg}
27897a84e134Smrg
2790994689c1Smrg# func_ltwrapper_script_p file
2791994689c1Smrg# True iff FILE is a libtool wrapper script
2792994689c1Smrg# This function is only a basic sanity check; it will hardly flush out
2793994689c1Smrg# determined imposters.
2794994689c1Smrgfunc_ltwrapper_script_p ()
2795994689c1Smrg{
27965ec34c4cSmrg    test -f "$1" &&
27975ec34c4cSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2798994689c1Smrg}
27997a84e134Smrg
2800994689c1Smrg# func_ltwrapper_executable_p file
2801994689c1Smrg# True iff FILE is a libtool wrapper executable
2802994689c1Smrg# This function is only a basic sanity check; it will hardly flush out
2803994689c1Smrg# determined imposters.
2804994689c1Smrgfunc_ltwrapper_executable_p ()
2805994689c1Smrg{
2806994689c1Smrg    func_ltwrapper_exec_suffix=
2807994689c1Smrg    case $1 in
2808994689c1Smrg    *.exe) ;;
2809994689c1Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2810994689c1Smrg    esac
2811994689c1Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2812994689c1Smrg}
2813994689c1Smrg
2814994689c1Smrg# func_ltwrapper_scriptname file
2815994689c1Smrg# Assumes file is an ltwrapper_executable
2816994689c1Smrg# uses $file to determine the appropriate filename for a
2817994689c1Smrg# temporary ltwrapper_script.
2818994689c1Smrgfunc_ltwrapper_scriptname ()
2819994689c1Smrg{
2820f353fbadSmrg    func_dirname_and_basename "$1" "" "."
2821f353fbadSmrg    func_stripname '' '.exe' "$func_basename_result"
28225ec34c4cSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2823994689c1Smrg}
2824994689c1Smrg
2825994689c1Smrg# func_ltwrapper_p file
2826994689c1Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2827994689c1Smrg# This function is only a basic sanity check; it will hardly flush out
2828994689c1Smrg# determined imposters.
2829994689c1Smrgfunc_ltwrapper_p ()
2830994689c1Smrg{
2831994689c1Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2832994689c1Smrg}
2833994689c1Smrg
2834994689c1Smrg
2835994689c1Smrg# func_execute_cmds commands fail_cmd
2836994689c1Smrg# Execute tilde-delimited COMMANDS.
2837994689c1Smrg# If FAIL_CMD is given, eval that upon failure.
2838994689c1Smrg# FAIL_CMD may read-access the current command in variable CMD!
2839994689c1Smrgfunc_execute_cmds ()
2840994689c1Smrg{
28415ec34c4cSmrg    $debug_cmd
28425ec34c4cSmrg
2843994689c1Smrg    save_ifs=$IFS; IFS='~'
2844994689c1Smrg    for cmd in $1; do
28455ec34c4cSmrg      IFS=$sp$nl
2846994689c1Smrg      eval cmd=\"$cmd\"
28475ec34c4cSmrg      IFS=$save_ifs
2848994689c1Smrg      func_show_eval "$cmd" "${2-:}"
2849994689c1Smrg    done
2850994689c1Smrg    IFS=$save_ifs
2851994689c1Smrg}
2852994689c1Smrg
2853994689c1Smrg
2854994689c1Smrg# func_source file
2855994689c1Smrg# Source FILE, adding directory component if necessary.
2856994689c1Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2857994689c1Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2858994689c1Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
28595ec34c4cSmrg# 'FILE.' does not work on cygwin managed mounts.
2860994689c1Smrgfunc_source ()
2861994689c1Smrg{
28625ec34c4cSmrg    $debug_cmd
28635ec34c4cSmrg
2864994689c1Smrg    case $1 in
2865994689c1Smrg    */* | *\\*)	. "$1" ;;
2866994689c1Smrg    *)		. "./$1" ;;
2867994689c1Smrg    esac
2868994689c1Smrg}
2869994689c1Smrg
2870994689c1Smrg
2871f353fbadSmrg# func_resolve_sysroot PATH
2872f353fbadSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2873f353fbadSmrg# func_resolve_sysroot_result
2874f353fbadSmrgfunc_resolve_sysroot ()
2875f353fbadSmrg{
2876f353fbadSmrg  func_resolve_sysroot_result=$1
2877f353fbadSmrg  case $func_resolve_sysroot_result in
2878f353fbadSmrg  =*)
2879f353fbadSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2880f353fbadSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2881f353fbadSmrg    ;;
2882f353fbadSmrg  esac
2883f353fbadSmrg}
2884f353fbadSmrg
2885f353fbadSmrg# func_replace_sysroot PATH
2886f353fbadSmrg# If PATH begins with the sysroot, replace it with = and
2887f353fbadSmrg# store the result into func_replace_sysroot_result.
2888f353fbadSmrgfunc_replace_sysroot ()
2889f353fbadSmrg{
28905ec34c4cSmrg  case $lt_sysroot:$1 in
2891f353fbadSmrg  ?*:"$lt_sysroot"*)
2892f353fbadSmrg    func_stripname "$lt_sysroot" '' "$1"
28935ec34c4cSmrg    func_replace_sysroot_result='='$func_stripname_result
2894f353fbadSmrg    ;;
2895f353fbadSmrg  *)
2896f353fbadSmrg    # Including no sysroot.
2897f353fbadSmrg    func_replace_sysroot_result=$1
2898f353fbadSmrg    ;;
2899f353fbadSmrg  esac
2900f353fbadSmrg}
2901f353fbadSmrg
2902994689c1Smrg# func_infer_tag arg
2903994689c1Smrg# Infer tagged configuration to use if any are available and
2904994689c1Smrg# if one wasn't chosen via the "--tag" command line option.
2905994689c1Smrg# Only attempt this if the compiler in the base compile
2906994689c1Smrg# command doesn't match the default compiler.
2907994689c1Smrg# arg is usually of the form 'gcc ...'
2908994689c1Smrgfunc_infer_tag ()
2909994689c1Smrg{
29105ec34c4cSmrg    $debug_cmd
29115ec34c4cSmrg
2912994689c1Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2913994689c1Smrg      CC_quoted=
2914994689c1Smrg      for arg in $CC; do
2915f353fbadSmrg	func_append_quoted CC_quoted "$arg"
2916994689c1Smrg      done
2917994689c1Smrg      CC_expanded=`func_echo_all $CC`
2918994689c1Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2919994689c1Smrg      case $@ in
2920994689c1Smrg      # Blanks in the command may have been stripped by the calling shell,
2921994689c1Smrg      # but not from the CC environment variable when configure was run.
2922994689c1Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2923994689c1Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2924994689c1Smrg      # Blanks at the start of $base_compile will cause this to fail
2925994689c1Smrg      # if we don't check for them as well.
2926994689c1Smrg      *)
2927994689c1Smrg	for z in $available_tags; do
2928994689c1Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2929994689c1Smrg	    # Evaluate the configuration.
29305ec34c4cSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2931994689c1Smrg	    CC_quoted=
2932994689c1Smrg	    for arg in $CC; do
2933994689c1Smrg	      # Double-quote args containing other shell metacharacters.
2934f353fbadSmrg	      func_append_quoted CC_quoted "$arg"
2935994689c1Smrg	    done
2936994689c1Smrg	    CC_expanded=`func_echo_all $CC`
2937994689c1Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2938994689c1Smrg	    case "$@ " in
2939994689c1Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2940994689c1Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2941994689c1Smrg	      # The compiler in the base compile command matches
2942994689c1Smrg	      # the one in the tagged configuration.
2943994689c1Smrg	      # Assume this is the tagged configuration we want.
2944994689c1Smrg	      tagname=$z
2945994689c1Smrg	      break
2946994689c1Smrg	      ;;
2947994689c1Smrg	    esac
2948994689c1Smrg	  fi
2949994689c1Smrg	done
2950994689c1Smrg	# If $tagname still isn't set, then no tagged configuration
2951994689c1Smrg	# was found and let the user know that the "--tag" command
2952994689c1Smrg	# line option must be used.
2953994689c1Smrg	if test -z "$tagname"; then
2954994689c1Smrg	  func_echo "unable to infer tagged configuration"
29555ec34c4cSmrg	  func_fatal_error "specify a tag with '--tag'"
2956994689c1Smrg#	else
2957994689c1Smrg#	  func_verbose "using $tagname tagged configuration"
2958994689c1Smrg	fi
2959994689c1Smrg	;;
2960994689c1Smrg      esac
2961994689c1Smrg    fi
2962994689c1Smrg}
2963994689c1Smrg
2964994689c1Smrg
2965994689c1Smrg
2966f353fbadSmrg# func_write_libtool_object output_name pic_name nonpic_name
2967f353fbadSmrg# Create a libtool object file (analogous to a ".la" file),
2968f353fbadSmrg# but don't create it if we're doing a dry run.
2969f353fbadSmrgfunc_write_libtool_object ()
2970f353fbadSmrg{
29715ec34c4cSmrg    write_libobj=$1
29725ec34c4cSmrg    if test yes = "$build_libtool_libs"; then
29735ec34c4cSmrg      write_lobj=\'$2\'
2974f353fbadSmrg    else
2975f353fbadSmrg      write_lobj=none
2976f353fbadSmrg    fi
2977f353fbadSmrg
29785ec34c4cSmrg    if test yes = "$build_old_libs"; then
29795ec34c4cSmrg      write_oldobj=\'$3\'
2980f353fbadSmrg    else
2981f353fbadSmrg      write_oldobj=none
2982f353fbadSmrg    fi
2983f353fbadSmrg
2984f353fbadSmrg    $opt_dry_run || {
2985f353fbadSmrg      cat >${write_libobj}T <<EOF
2986f353fbadSmrg# $write_libobj - a libtool object file
29875ec34c4cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2988f353fbadSmrg#
2989f353fbadSmrg# Please DO NOT delete this file!
2990f353fbadSmrg# It is necessary for linking the library.
2991f353fbadSmrg
2992f353fbadSmrg# Name of the PIC object.
2993f353fbadSmrgpic_object=$write_lobj
2994f353fbadSmrg
2995f353fbadSmrg# Name of the non-PIC object
2996f353fbadSmrgnon_pic_object=$write_oldobj
2997f353fbadSmrg
2998f353fbadSmrgEOF
29995ec34c4cSmrg      $MV "${write_libobj}T" "$write_libobj"
3000f353fbadSmrg    }
3001f353fbadSmrg}
3002f353fbadSmrg
3003f353fbadSmrg
3004f353fbadSmrg##################################################
3005f353fbadSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3006f353fbadSmrg##################################################
3007f353fbadSmrg
3008f353fbadSmrg# func_convert_core_file_wine_to_w32 ARG
3009f353fbadSmrg# Helper function used by file name conversion functions when $build is *nix,
3010f353fbadSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3011f353fbadSmrg# correctly configured wine environment available, with the winepath program
3012f353fbadSmrg# in $build's $PATH.
3013f353fbadSmrg#
3014f353fbadSmrg# ARG is the $build file name to be converted to w32 format.
3015f353fbadSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3016f353fbadSmrg# be empty on error (or when ARG is empty)
3017f353fbadSmrgfunc_convert_core_file_wine_to_w32 ()
3018f353fbadSmrg{
30195ec34c4cSmrg  $debug_cmd
30205ec34c4cSmrg
30215ec34c4cSmrg  func_convert_core_file_wine_to_w32_result=$1
3022f353fbadSmrg  if test -n "$1"; then
3023f353fbadSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3024f353fbadSmrg    # are forced to check the contents of stdout. On the other hand, if the
3025f353fbadSmrg    # command is not found, the shell will set an exit code of 127 and print
3026f353fbadSmrg    # *an error message* to stdout. So we must check for both error code of
3027f353fbadSmrg    # zero AND non-empty stdout, which explains the odd construction:
3028f353fbadSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
30295ec34c4cSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3030f353fbadSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
30315ec34c4cSmrg        $SED -e "$sed_naive_backslashify"`
3032f353fbadSmrg    else
3033f353fbadSmrg      func_convert_core_file_wine_to_w32_result=
3034f353fbadSmrg    fi
3035f353fbadSmrg  fi
3036f353fbadSmrg}
3037f353fbadSmrg# end: func_convert_core_file_wine_to_w32
3038f353fbadSmrg
3039f353fbadSmrg
3040f353fbadSmrg# func_convert_core_path_wine_to_w32 ARG
3041f353fbadSmrg# Helper function used by path conversion functions when $build is *nix, and
3042f353fbadSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3043f353fbadSmrg# configured wine environment available, with the winepath program in $build's
3044f353fbadSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3045f353fbadSmrg#
3046f353fbadSmrg# ARG is path to be converted from $build format to win32.
3047f353fbadSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3048f353fbadSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3049f353fbadSmrg# are convertible, then the result may be empty.
3050f353fbadSmrgfunc_convert_core_path_wine_to_w32 ()
3051f353fbadSmrg{
30525ec34c4cSmrg  $debug_cmd
30535ec34c4cSmrg
3054f353fbadSmrg  # unfortunately, winepath doesn't convert paths, only file names
30555ec34c4cSmrg  func_convert_core_path_wine_to_w32_result=
3056f353fbadSmrg  if test -n "$1"; then
3057f353fbadSmrg    oldIFS=$IFS
3058f353fbadSmrg    IFS=:
3059f353fbadSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3060f353fbadSmrg      IFS=$oldIFS
3061f353fbadSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
30625ec34c4cSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3063f353fbadSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
30645ec34c4cSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3065f353fbadSmrg        else
3066f353fbadSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3067f353fbadSmrg        fi
3068f353fbadSmrg      fi
3069f353fbadSmrg    done
3070f353fbadSmrg    IFS=$oldIFS
3071f353fbadSmrg  fi
3072f353fbadSmrg}
3073f353fbadSmrg# end: func_convert_core_path_wine_to_w32
3074f353fbadSmrg
3075f353fbadSmrg
3076f353fbadSmrg# func_cygpath ARGS...
3077f353fbadSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3078f353fbadSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3079f353fbadSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3080f353fbadSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3081f353fbadSmrg# file name or path is assumed to be in w32 format, as previously converted
3082f353fbadSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3083f353fbadSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3084f353fbadSmrg# Cygwin format). Returns an empty string on error.
3085f353fbadSmrg#
3086f353fbadSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3087f353fbadSmrg# be converted.
3088f353fbadSmrg#
3089f353fbadSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3090f353fbadSmrg# environment variable; do not put it in $PATH.
3091f353fbadSmrgfunc_cygpath ()
3092f353fbadSmrg{
30935ec34c4cSmrg  $debug_cmd
30945ec34c4cSmrg
3095f353fbadSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3096f353fbadSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3097f353fbadSmrg    if test "$?" -ne 0; then
3098f353fbadSmrg      # on failure, ensure result is empty
3099f353fbadSmrg      func_cygpath_result=
3100f353fbadSmrg    fi
3101f353fbadSmrg  else
3102f353fbadSmrg    func_cygpath_result=
31035ec34c4cSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3104f353fbadSmrg  fi
3105f353fbadSmrg}
3106f353fbadSmrg#end: func_cygpath
3107f353fbadSmrg
3108f353fbadSmrg
3109f353fbadSmrg# func_convert_core_msys_to_w32 ARG
3110f353fbadSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3111f353fbadSmrg# result in func_convert_core_msys_to_w32_result.
3112f353fbadSmrgfunc_convert_core_msys_to_w32 ()
3113f353fbadSmrg{
31145ec34c4cSmrg  $debug_cmd
31155ec34c4cSmrg
3116f353fbadSmrg  # awkward: cmd appends spaces to result
3117f353fbadSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
31185ec34c4cSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3119f353fbadSmrg}
3120f353fbadSmrg#end: func_convert_core_msys_to_w32
3121f353fbadSmrg
3122f353fbadSmrg
3123f353fbadSmrg# func_convert_file_check ARG1 ARG2
3124f353fbadSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3125f353fbadSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3126f353fbadSmrg# func_to_host_file_result to ARG1).
3127f353fbadSmrgfunc_convert_file_check ()
3128f353fbadSmrg{
31295ec34c4cSmrg  $debug_cmd
31305ec34c4cSmrg
31315ec34c4cSmrg  if test -z "$2" && test -n "$1"; then
3132f353fbadSmrg    func_error "Could not determine host file name corresponding to"
31335ec34c4cSmrg    func_error "  '$1'"
3134f353fbadSmrg    func_error "Continuing, but uninstalled executables may not work."
3135f353fbadSmrg    # Fallback:
31365ec34c4cSmrg    func_to_host_file_result=$1
3137f353fbadSmrg  fi
3138f353fbadSmrg}
3139f353fbadSmrg# end func_convert_file_check
3140f353fbadSmrg
3141f353fbadSmrg
3142f353fbadSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3143f353fbadSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3144f353fbadSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3145f353fbadSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3146f353fbadSmrgfunc_convert_path_check ()
3147f353fbadSmrg{
31485ec34c4cSmrg  $debug_cmd
31495ec34c4cSmrg
3150f353fbadSmrg  if test -z "$4" && test -n "$3"; then
3151f353fbadSmrg    func_error "Could not determine the host path corresponding to"
31525ec34c4cSmrg    func_error "  '$3'"
3153f353fbadSmrg    func_error "Continuing, but uninstalled executables may not work."
3154f353fbadSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3155f353fbadSmrg    # should not be "improved".  See libtool.info.
3156f353fbadSmrg    if test "x$1" != "x$2"; then
3157f353fbadSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3158f353fbadSmrg      func_to_host_path_result=`echo "$3" |
3159f353fbadSmrg        $SED -e "$lt_replace_pathsep_chars"`
3160f353fbadSmrg    else
31615ec34c4cSmrg      func_to_host_path_result=$3
3162f353fbadSmrg    fi
3163f353fbadSmrg  fi
3164f353fbadSmrg}
3165f353fbadSmrg# end func_convert_path_check
3166f353fbadSmrg
3167f353fbadSmrg
3168f353fbadSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3169f353fbadSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3170f353fbadSmrg# and appending REPL if ORIG matches BACKPAT.
3171f353fbadSmrgfunc_convert_path_front_back_pathsep ()
3172f353fbadSmrg{
31735ec34c4cSmrg  $debug_cmd
31745ec34c4cSmrg
3175f353fbadSmrg  case $4 in
31765ec34c4cSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3177f353fbadSmrg    ;;
3178f353fbadSmrg  esac
3179f353fbadSmrg  case $4 in
3180f353fbadSmrg  $2 ) func_append func_to_host_path_result "$3"
3181f353fbadSmrg    ;;
3182f353fbadSmrg  esac
3183f353fbadSmrg}
3184f353fbadSmrg# end func_convert_path_front_back_pathsep
3185f353fbadSmrg
3186f353fbadSmrg
3187f353fbadSmrg##################################################
3188f353fbadSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3189f353fbadSmrg##################################################
31905ec34c4cSmrg# invoked via '$to_host_file_cmd ARG'
3191f353fbadSmrg#
3192f353fbadSmrg# In each case, ARG is the path to be converted from $build to $host format.
3193f353fbadSmrg# Result will be available in $func_to_host_file_result.
3194f353fbadSmrg
3195f353fbadSmrg
3196f353fbadSmrg# func_to_host_file ARG
3197f353fbadSmrg# Converts the file name ARG from $build format to $host format. Return result
3198f353fbadSmrg# in func_to_host_file_result.
3199f353fbadSmrgfunc_to_host_file ()
3200f353fbadSmrg{
32015ec34c4cSmrg  $debug_cmd
32025ec34c4cSmrg
3203f353fbadSmrg  $to_host_file_cmd "$1"
3204f353fbadSmrg}
3205f353fbadSmrg# end func_to_host_file
3206f353fbadSmrg
3207f353fbadSmrg
3208f353fbadSmrg# func_to_tool_file ARG LAZY
3209f353fbadSmrg# converts the file name ARG from $build format to toolchain format. Return
3210f353fbadSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3211f353fbadSmrg# in (the comma separated) LAZY, no conversion takes place.
3212f353fbadSmrgfunc_to_tool_file ()
3213f353fbadSmrg{
32145ec34c4cSmrg  $debug_cmd
32155ec34c4cSmrg
3216f353fbadSmrg  case ,$2, in
3217f353fbadSmrg    *,"$to_tool_file_cmd",*)
3218f353fbadSmrg      func_to_tool_file_result=$1
3219f353fbadSmrg      ;;
3220f353fbadSmrg    *)
3221f353fbadSmrg      $to_tool_file_cmd "$1"
3222f353fbadSmrg      func_to_tool_file_result=$func_to_host_file_result
3223f353fbadSmrg      ;;
3224f353fbadSmrg  esac
3225f353fbadSmrg}
3226f353fbadSmrg# end func_to_tool_file
3227f353fbadSmrg
3228f353fbadSmrg
3229f353fbadSmrg# func_convert_file_noop ARG
3230f353fbadSmrg# Copy ARG to func_to_host_file_result.
3231f353fbadSmrgfunc_convert_file_noop ()
3232f353fbadSmrg{
32335ec34c4cSmrg  func_to_host_file_result=$1
3234f353fbadSmrg}
3235f353fbadSmrg# end func_convert_file_noop
3236f353fbadSmrg
3237f353fbadSmrg
3238f353fbadSmrg# func_convert_file_msys_to_w32 ARG
3239f353fbadSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3240f353fbadSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3241f353fbadSmrg# func_to_host_file_result.
3242f353fbadSmrgfunc_convert_file_msys_to_w32 ()
3243f353fbadSmrg{
32445ec34c4cSmrg  $debug_cmd
32455ec34c4cSmrg
32465ec34c4cSmrg  func_to_host_file_result=$1
3247f353fbadSmrg  if test -n "$1"; then
3248f353fbadSmrg    func_convert_core_msys_to_w32 "$1"
32495ec34c4cSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3250f353fbadSmrg  fi
3251f353fbadSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3252f353fbadSmrg}
3253f353fbadSmrg# end func_convert_file_msys_to_w32
3254f353fbadSmrg
3255f353fbadSmrg
3256f353fbadSmrg# func_convert_file_cygwin_to_w32 ARG
3257f353fbadSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3258f353fbadSmrg# func_to_host_file_result.
3259f353fbadSmrgfunc_convert_file_cygwin_to_w32 ()
3260f353fbadSmrg{
32615ec34c4cSmrg  $debug_cmd
32625ec34c4cSmrg
32635ec34c4cSmrg  func_to_host_file_result=$1
3264f353fbadSmrg  if test -n "$1"; then
3265f353fbadSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3266f353fbadSmrg    # LT_CYGPATH in this case.
3267f353fbadSmrg    func_to_host_file_result=`cygpath -m "$1"`
3268f353fbadSmrg  fi
3269f353fbadSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3270f353fbadSmrg}
3271f353fbadSmrg# end func_convert_file_cygwin_to_w32
3272f353fbadSmrg
3273f353fbadSmrg
3274f353fbadSmrg# func_convert_file_nix_to_w32 ARG
3275f353fbadSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3276f353fbadSmrg# and a working winepath. Returns result in func_to_host_file_result.
3277f353fbadSmrgfunc_convert_file_nix_to_w32 ()
3278f353fbadSmrg{
32795ec34c4cSmrg  $debug_cmd
32805ec34c4cSmrg
32815ec34c4cSmrg  func_to_host_file_result=$1
3282f353fbadSmrg  if test -n "$1"; then
3283f353fbadSmrg    func_convert_core_file_wine_to_w32 "$1"
32845ec34c4cSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3285f353fbadSmrg  fi
3286f353fbadSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3287f353fbadSmrg}
3288f353fbadSmrg# end func_convert_file_nix_to_w32
3289f353fbadSmrg
3290f353fbadSmrg
3291f353fbadSmrg# func_convert_file_msys_to_cygwin ARG
3292f353fbadSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3293f353fbadSmrg# Returns result in func_to_host_file_result.
3294f353fbadSmrgfunc_convert_file_msys_to_cygwin ()
3295f353fbadSmrg{
32965ec34c4cSmrg  $debug_cmd
32975ec34c4cSmrg
32985ec34c4cSmrg  func_to_host_file_result=$1
3299f353fbadSmrg  if test -n "$1"; then
3300f353fbadSmrg    func_convert_core_msys_to_w32 "$1"
3301f353fbadSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
33025ec34c4cSmrg    func_to_host_file_result=$func_cygpath_result
3303f353fbadSmrg  fi
3304f353fbadSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3305f353fbadSmrg}
3306f353fbadSmrg# end func_convert_file_msys_to_cygwin
3307f353fbadSmrg
3308f353fbadSmrg
3309f353fbadSmrg# func_convert_file_nix_to_cygwin ARG
3310f353fbadSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3311f353fbadSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3312f353fbadSmrg# in func_to_host_file_result.
3313f353fbadSmrgfunc_convert_file_nix_to_cygwin ()
3314f353fbadSmrg{
33155ec34c4cSmrg  $debug_cmd
33165ec34c4cSmrg
33175ec34c4cSmrg  func_to_host_file_result=$1
3318f353fbadSmrg  if test -n "$1"; then
3319f353fbadSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3320f353fbadSmrg    func_convert_core_file_wine_to_w32 "$1"
3321f353fbadSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
33225ec34c4cSmrg    func_to_host_file_result=$func_cygpath_result
3323f353fbadSmrg  fi
3324f353fbadSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3325f353fbadSmrg}
3326f353fbadSmrg# end func_convert_file_nix_to_cygwin
3327f353fbadSmrg
3328f353fbadSmrg
3329f353fbadSmrg#############################################
3330f353fbadSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3331f353fbadSmrg#############################################
33325ec34c4cSmrg# invoked via '$to_host_path_cmd ARG'
3333f353fbadSmrg#
3334f353fbadSmrg# In each case, ARG is the path to be converted from $build to $host format.
3335f353fbadSmrg# The result will be available in $func_to_host_path_result.
3336f353fbadSmrg#
3337f353fbadSmrg# Path separators are also converted from $build format to $host format.  If
3338f353fbadSmrg# ARG begins or ends with a path separator character, it is preserved (but
3339f353fbadSmrg# converted to $host format) on output.
3340f353fbadSmrg#
3341f353fbadSmrg# All path conversion functions are named using the following convention:
3342f353fbadSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3343f353fbadSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3344f353fbadSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3345f353fbadSmrg# same.  If conversion functions are added for new $build/$host combinations,
3346f353fbadSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3347f353fbadSmrg# will break.
3348f353fbadSmrg
3349f353fbadSmrg
3350f353fbadSmrg# func_init_to_host_path_cmd
3351f353fbadSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3352f353fbadSmrg# appropriate value, based on the value of $to_host_file_cmd.
3353f353fbadSmrgto_host_path_cmd=
3354f353fbadSmrgfunc_init_to_host_path_cmd ()
3355f353fbadSmrg{
33565ec34c4cSmrg  $debug_cmd
33575ec34c4cSmrg
3358f353fbadSmrg  if test -z "$to_host_path_cmd"; then
3359f353fbadSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
33605ec34c4cSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3361f353fbadSmrg  fi
3362f353fbadSmrg}
3363f353fbadSmrg
3364f353fbadSmrg
3365f353fbadSmrg# func_to_host_path ARG
3366f353fbadSmrg# Converts the path ARG from $build format to $host format. Return result
3367f353fbadSmrg# in func_to_host_path_result.
3368f353fbadSmrgfunc_to_host_path ()
3369f353fbadSmrg{
33705ec34c4cSmrg  $debug_cmd
33715ec34c4cSmrg
3372f353fbadSmrg  func_init_to_host_path_cmd
3373f353fbadSmrg  $to_host_path_cmd "$1"
3374f353fbadSmrg}
3375f353fbadSmrg# end func_to_host_path
3376f353fbadSmrg
3377f353fbadSmrg
3378f353fbadSmrg# func_convert_path_noop ARG
3379f353fbadSmrg# Copy ARG to func_to_host_path_result.
3380f353fbadSmrgfunc_convert_path_noop ()
3381f353fbadSmrg{
33825ec34c4cSmrg  func_to_host_path_result=$1
3383f353fbadSmrg}
3384f353fbadSmrg# end func_convert_path_noop
3385f353fbadSmrg
3386f353fbadSmrg
3387f353fbadSmrg# func_convert_path_msys_to_w32 ARG
3388f353fbadSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3389f353fbadSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3390f353fbadSmrg# func_to_host_path_result.
3391f353fbadSmrgfunc_convert_path_msys_to_w32 ()
3392994689c1Smrg{
33935ec34c4cSmrg  $debug_cmd
33945ec34c4cSmrg
33955ec34c4cSmrg  func_to_host_path_result=$1
3396f353fbadSmrg  if test -n "$1"; then
3397f353fbadSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3398f353fbadSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3399f353fbadSmrg    # and winepath ignores them completely.
3400f353fbadSmrg    func_stripname : : "$1"
3401f353fbadSmrg    func_to_host_path_tmp1=$func_stripname_result
3402f353fbadSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
34035ec34c4cSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3404f353fbadSmrg    func_convert_path_check : ";" \
3405f353fbadSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3406f353fbadSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3407f353fbadSmrg  fi
3408f353fbadSmrg}
3409f353fbadSmrg# end func_convert_path_msys_to_w32
3410994689c1Smrg
3411994689c1Smrg
3412f353fbadSmrg# func_convert_path_cygwin_to_w32 ARG
3413f353fbadSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3414f353fbadSmrg# func_to_host_file_result.
3415f353fbadSmrgfunc_convert_path_cygwin_to_w32 ()
3416f353fbadSmrg{
34175ec34c4cSmrg  $debug_cmd
34185ec34c4cSmrg
34195ec34c4cSmrg  func_to_host_path_result=$1
3420f353fbadSmrg  if test -n "$1"; then
3421f353fbadSmrg    # See func_convert_path_msys_to_w32:
3422f353fbadSmrg    func_stripname : : "$1"
3423f353fbadSmrg    func_to_host_path_tmp1=$func_stripname_result
3424f353fbadSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3425f353fbadSmrg    func_convert_path_check : ";" \
3426f353fbadSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3427f353fbadSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3428f353fbadSmrg  fi
3429f353fbadSmrg}
3430f353fbadSmrg# end func_convert_path_cygwin_to_w32
3431994689c1Smrg
3432994689c1Smrg
3433f353fbadSmrg# func_convert_path_nix_to_w32 ARG
3434f353fbadSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3435f353fbadSmrg# a working winepath.  Returns result in func_to_host_file_result.
3436f353fbadSmrgfunc_convert_path_nix_to_w32 ()
3437f353fbadSmrg{
34385ec34c4cSmrg  $debug_cmd
34395ec34c4cSmrg
34405ec34c4cSmrg  func_to_host_path_result=$1
3441f353fbadSmrg  if test -n "$1"; then
3442f353fbadSmrg    # See func_convert_path_msys_to_w32:
3443f353fbadSmrg    func_stripname : : "$1"
3444f353fbadSmrg    func_to_host_path_tmp1=$func_stripname_result
3445f353fbadSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34465ec34c4cSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3447f353fbadSmrg    func_convert_path_check : ";" \
3448f353fbadSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3449f353fbadSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3450f353fbadSmrg  fi
3451f353fbadSmrg}
3452f353fbadSmrg# end func_convert_path_nix_to_w32
3453994689c1Smrg
3454f353fbadSmrg
3455f353fbadSmrg# func_convert_path_msys_to_cygwin ARG
3456f353fbadSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3457f353fbadSmrg# Returns result in func_to_host_file_result.
3458f353fbadSmrgfunc_convert_path_msys_to_cygwin ()
3459f353fbadSmrg{
34605ec34c4cSmrg  $debug_cmd
34615ec34c4cSmrg
34625ec34c4cSmrg  func_to_host_path_result=$1
3463f353fbadSmrg  if test -n "$1"; then
3464f353fbadSmrg    # See func_convert_path_msys_to_w32:
3465f353fbadSmrg    func_stripname : : "$1"
3466f353fbadSmrg    func_to_host_path_tmp1=$func_stripname_result
3467f353fbadSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3468f353fbadSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
34695ec34c4cSmrg    func_to_host_path_result=$func_cygpath_result
3470f353fbadSmrg    func_convert_path_check : : \
3471f353fbadSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3472f353fbadSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3473f353fbadSmrg  fi
3474f353fbadSmrg}
3475f353fbadSmrg# end func_convert_path_msys_to_cygwin
3476f353fbadSmrg
3477f353fbadSmrg
3478f353fbadSmrg# func_convert_path_nix_to_cygwin ARG
3479f353fbadSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3480f353fbadSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3481f353fbadSmrg# func_to_host_file_result.
3482f353fbadSmrgfunc_convert_path_nix_to_cygwin ()
3483f353fbadSmrg{
34845ec34c4cSmrg  $debug_cmd
34855ec34c4cSmrg
34865ec34c4cSmrg  func_to_host_path_result=$1
3487f353fbadSmrg  if test -n "$1"; then
3488f353fbadSmrg    # Remove leading and trailing path separator characters from
3489f353fbadSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3490f353fbadSmrg    # into '.;' and ';.', and winepath ignores them completely.
3491f353fbadSmrg    func_stripname : : "$1"
3492f353fbadSmrg    func_to_host_path_tmp1=$func_stripname_result
3493f353fbadSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3494f353fbadSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
34955ec34c4cSmrg    func_to_host_path_result=$func_cygpath_result
3496f353fbadSmrg    func_convert_path_check : : \
3497f353fbadSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3498f353fbadSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3499f353fbadSmrg  fi
3500994689c1Smrg}
3501f353fbadSmrg# end func_convert_path_nix_to_cygwin
3502f353fbadSmrg
3503994689c1Smrg
35045ec34c4cSmrg# func_dll_def_p FILE
35055ec34c4cSmrg# True iff FILE is a Windows DLL '.def' file.
35065ec34c4cSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
35075ec34c4cSmrgfunc_dll_def_p ()
35085ec34c4cSmrg{
35095ec34c4cSmrg  $debug_cmd
35105ec34c4cSmrg
35115ec34c4cSmrg  func_dll_def_p_tmp=`$SED -n \
35125ec34c4cSmrg    -e 's/^[	 ]*//' \
35135ec34c4cSmrg    -e '/^\(;.*\)*$/d' \
35145ec34c4cSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
35155ec34c4cSmrg    -e q \
35165ec34c4cSmrg    "$1"`
35175ec34c4cSmrg  test DEF = "$func_dll_def_p_tmp"
35185ec34c4cSmrg}
35195ec34c4cSmrg
35205ec34c4cSmrg
3521994689c1Smrg# func_mode_compile arg...
3522994689c1Smrgfunc_mode_compile ()
3523994689c1Smrg{
35245ec34c4cSmrg    $debug_cmd
35255ec34c4cSmrg
3526994689c1Smrg    # Get the compilation command and the source file.
3527994689c1Smrg    base_compile=
35285ec34c4cSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3529994689c1Smrg    suppress_opt=yes
3530994689c1Smrg    suppress_output=
3531994689c1Smrg    arg_mode=normal
3532994689c1Smrg    libobj=
3533994689c1Smrg    later=
3534994689c1Smrg    pie_flag=
3535994689c1Smrg
3536994689c1Smrg    for arg
3537994689c1Smrg    do
3538994689c1Smrg      case $arg_mode in
3539994689c1Smrg      arg  )
3540994689c1Smrg	# do not "continue".  Instead, add this to base_compile
35415ec34c4cSmrg	lastarg=$arg
3542994689c1Smrg	arg_mode=normal
3543994689c1Smrg	;;
3544994689c1Smrg
3545994689c1Smrg      target )
35465ec34c4cSmrg	libobj=$arg
3547994689c1Smrg	arg_mode=normal
3548994689c1Smrg	continue
3549994689c1Smrg	;;
3550994689c1Smrg
3551994689c1Smrg      normal )
3552994689c1Smrg	# Accept any command-line options.
3553994689c1Smrg	case $arg in
3554994689c1Smrg	-o)
3555994689c1Smrg	  test -n "$libobj" && \
35565ec34c4cSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3557994689c1Smrg	  arg_mode=target
3558994689c1Smrg	  continue
3559994689c1Smrg	  ;;
3560994689c1Smrg
3561994689c1Smrg	-pie | -fpie | -fPIE)
3562f353fbadSmrg          func_append pie_flag " $arg"
3563994689c1Smrg	  continue
3564994689c1Smrg	  ;;
3565994689c1Smrg
3566994689c1Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3567f353fbadSmrg	  func_append later " $arg"
3568994689c1Smrg	  continue
3569994689c1Smrg	  ;;
35707a84e134Smrg
35717a84e134Smrg	-no-suppress)
35727a84e134Smrg	  suppress_opt=no
35737a84e134Smrg	  continue
35747a84e134Smrg	  ;;
35757a84e134Smrg
35767a84e134Smrg	-Xcompiler)
35777a84e134Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
35787a84e134Smrg	  continue      #  The current "srcfile" will either be retained or
35797a84e134Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
35807a84e134Smrg
35817a84e134Smrg	-Wc,*)
3582994689c1Smrg	  func_stripname '-Wc,' '' "$arg"
3583994689c1Smrg	  args=$func_stripname_result
35847a84e134Smrg	  lastarg=
35855ec34c4cSmrg	  save_ifs=$IFS; IFS=,
3586994689c1Smrg	  for arg in $args; do
35875ec34c4cSmrg	    IFS=$save_ifs
3588f353fbadSmrg	    func_append_quoted lastarg "$arg"
35897a84e134Smrg	  done
35905ec34c4cSmrg	  IFS=$save_ifs
3591994689c1Smrg	  func_stripname ' ' '' "$lastarg"
3592994689c1Smrg	  lastarg=$func_stripname_result
35937a84e134Smrg
35947a84e134Smrg	  # Add the arguments to base_compile.
3595f353fbadSmrg	  func_append base_compile " $lastarg"
35967a84e134Smrg	  continue
35977a84e134Smrg	  ;;
35987a84e134Smrg
3599994689c1Smrg	*)
36007a84e134Smrg	  # Accept the current argument as the source file.
36017a84e134Smrg	  # The previous "srcfile" becomes the current argument.
36027a84e134Smrg	  #
36035ec34c4cSmrg	  lastarg=$srcfile
36045ec34c4cSmrg	  srcfile=$arg
36057a84e134Smrg	  ;;
36067a84e134Smrg	esac  #  case $arg
36077a84e134Smrg	;;
36087a84e134Smrg      esac    #  case $arg_mode
36097a84e134Smrg
36107a84e134Smrg      # Aesthetically quote the previous argument.
3611f353fbadSmrg      func_append_quoted base_compile "$lastarg"
36127a84e134Smrg    done # for arg
36137a84e134Smrg
36147a84e134Smrg    case $arg_mode in
36157a84e134Smrg    arg)
3616994689c1Smrg      func_fatal_error "you must specify an argument for -Xcompile"
36177a84e134Smrg      ;;
36187a84e134Smrg    target)
36195ec34c4cSmrg      func_fatal_error "you must specify a target with '-o'"
36207a84e134Smrg      ;;
36217a84e134Smrg    *)
36227a84e134Smrg      # Get the name of the library object.
3623994689c1Smrg      test -z "$libobj" && {
3624994689c1Smrg	func_basename "$srcfile"
36255ec34c4cSmrg	libobj=$func_basename_result
3626994689c1Smrg      }
36277a84e134Smrg      ;;
36287a84e134Smrg    esac
36297a84e134Smrg
36307a84e134Smrg    # Recognize several different file suffixes.
36317a84e134Smrg    # If the user specifies -o file.o, it is replaced with file.lo
36327a84e134Smrg    case $libobj in
3633994689c1Smrg    *.[cCFSifmso] | \
3634994689c1Smrg    *.ada | *.adb | *.ads | *.asm | \
3635994689c1Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3636421c997bSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3637994689c1Smrg      func_xform "$libobj"
3638994689c1Smrg      libobj=$func_xform_result
3639994689c1Smrg      ;;
36407a84e134Smrg    esac
36417a84e134Smrg
36427a84e134Smrg    case $libobj in
3643994689c1Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
36447a84e134Smrg    *)
36455ec34c4cSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
36467a84e134Smrg      ;;
36477a84e134Smrg    esac
36487a84e134Smrg
36497a84e134Smrg    func_infer_tag $base_compile
36507a84e134Smrg
36517a84e134Smrg    for arg in $later; do
36527a84e134Smrg      case $arg in
3653994689c1Smrg      -shared)
36545ec34c4cSmrg	test yes = "$build_libtool_libs" \
36555ec34c4cSmrg	  || func_fatal_configuration "cannot build a shared library"
3656994689c1Smrg	build_old_libs=no
3657994689c1Smrg	continue
3658994689c1Smrg	;;
3659994689c1Smrg
36607a84e134Smrg      -static)
3661994689c1Smrg	build_libtool_libs=no
36627a84e134Smrg	build_old_libs=yes
36637a84e134Smrg	continue
36647a84e134Smrg	;;
36657a84e134Smrg
36667a84e134Smrg      -prefer-pic)
36677a84e134Smrg	pic_mode=yes
36687a84e134Smrg	continue
36697a84e134Smrg	;;
36707a84e134Smrg
36717a84e134Smrg      -prefer-non-pic)
36727a84e134Smrg	pic_mode=no
36737a84e134Smrg	continue
36747a84e134Smrg	;;
36757a84e134Smrg      esac
36767a84e134Smrg    done
36777a84e134Smrg
36785b16253fSmrg    func_quote_arg pretty "$libobj"
36795b16253fSmrg    test "X$libobj" != "X$func_quote_arg_result" \
3680994689c1Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
36815ec34c4cSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3682994689c1Smrg    func_dirname_and_basename "$obj" "/" ""
36835ec34c4cSmrg    objname=$func_basename_result
36845ec34c4cSmrg    xdir=$func_dirname_result
36855ec34c4cSmrg    lobj=$xdir$objdir/$objname
36867a84e134Smrg
3687994689c1Smrg    test -z "$base_compile" && \
3688994689c1Smrg      func_fatal_help "you must specify a compilation command"
36897a84e134Smrg
36907a84e134Smrg    # Delete any leftover library objects.
36915ec34c4cSmrg    if test yes = "$build_old_libs"; then
36927a84e134Smrg      removelist="$obj $lobj $libobj ${libobj}T"
36937a84e134Smrg    else
36947a84e134Smrg      removelist="$lobj $libobj ${libobj}T"
36957a84e134Smrg    fi
36967a84e134Smrg
36977a84e134Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
36987a84e134Smrg    case $host_os in
3699994689c1Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
37007a84e134Smrg      pic_mode=default
37017a84e134Smrg      ;;
37027a84e134Smrg    esac
37035ec34c4cSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
37047a84e134Smrg      # non-PIC code in shared libraries is not supported
37057a84e134Smrg      pic_mode=default
37067a84e134Smrg    fi
37077a84e134Smrg
37087a84e134Smrg    # Calculate the filename of the output object if compiler does
37097a84e134Smrg    # not support -o with -c
37105ec34c4cSmrg    if test no = "$compiler_c_o"; then
37115ec34c4cSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
37125ec34c4cSmrg      lockfile=$output_obj.lock
37137a84e134Smrg    else
37147a84e134Smrg      output_obj=
37157a84e134Smrg      need_locks=no
37167a84e134Smrg      lockfile=
37177a84e134Smrg    fi
37187a84e134Smrg
37197a84e134Smrg    # Lock this critical section if it is needed
37207a84e134Smrg    # We use this script file to make the link, it avoids creating a new file
37215ec34c4cSmrg    if test yes = "$need_locks"; then
3722994689c1Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3723994689c1Smrg	func_echo "Waiting for $lockfile to be removed"
37247a84e134Smrg	sleep 2
37257a84e134Smrg      done
37265ec34c4cSmrg    elif test warn = "$need_locks"; then
37277a84e134Smrg      if test -f "$lockfile"; then
3728994689c1Smrg	$ECHO "\
37297a84e134Smrg*** ERROR, $lockfile exists and contains:
37307a84e134Smrg`cat $lockfile 2>/dev/null`
37317a84e134Smrg
37327a84e134SmrgThis indicates that another process is trying to use the same
37337a84e134Smrgtemporary object file, and libtool could not work around it because
37345ec34c4cSmrgyour compiler does not support '-c' and '-o' together.  If you
37357a84e134Smrgrepeat this compilation, it may succeed, by chance, but you had better
37367a84e134Smrgavoid parallel builds (make -j) in this platform, or get a better
37377a84e134Smrgcompiler."
37387a84e134Smrg
3739994689c1Smrg	$opt_dry_run || $RM $removelist
37407a84e134Smrg	exit $EXIT_FAILURE
37417a84e134Smrg      fi
3742f353fbadSmrg      func_append removelist " $output_obj"
3743994689c1Smrg      $ECHO "$srcfile" > "$lockfile"
37447a84e134Smrg    fi
37457a84e134Smrg
3746994689c1Smrg    $opt_dry_run || $RM $removelist
3747f353fbadSmrg    func_append removelist " $lockfile"
3748994689c1Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3749994689c1Smrg
3750f353fbadSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3751f353fbadSmrg    srcfile=$func_to_tool_file_result
37525b16253fSmrg    func_quote_arg pretty "$srcfile"
37535b16253fSmrg    qsrcfile=$func_quote_arg_result
37547a84e134Smrg
37557a84e134Smrg    # Only build a PIC object if we are building libtool libraries.
37565ec34c4cSmrg    if test yes = "$build_libtool_libs"; then
37577a84e134Smrg      # Without this assignment, base_compile gets emptied.
37587a84e134Smrg      fbsd_hideous_sh_bug=$base_compile
37597a84e134Smrg
37605ec34c4cSmrg      if test no != "$pic_mode"; then
37617a84e134Smrg	command="$base_compile $qsrcfile $pic_flag"
37627a84e134Smrg      else
37637a84e134Smrg	# Don't build PIC code
37647a84e134Smrg	command="$base_compile $qsrcfile"
37657a84e134Smrg      fi
37667a84e134Smrg
3767994689c1Smrg      func_mkdir_p "$xdir$objdir"
37687a84e134Smrg
37697a84e134Smrg      if test -z "$output_obj"; then
37707a84e134Smrg	# Place PIC objects in $objdir
3771f353fbadSmrg	func_append command " -o $lobj"
37727a84e134Smrg      fi
37737a84e134Smrg
3774994689c1Smrg      func_show_eval_locale "$command"	\
3775994689c1Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
37767a84e134Smrg
37775ec34c4cSmrg      if test warn = "$need_locks" &&
37787a84e134Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3779994689c1Smrg	$ECHO "\
37807a84e134Smrg*** ERROR, $lockfile contains:
37817a84e134Smrg`cat $lockfile 2>/dev/null`
37827a84e134Smrg
37837a84e134Smrgbut it should contain:
37847a84e134Smrg$srcfile
37857a84e134Smrg
37867a84e134SmrgThis indicates that another process is trying to use the same
37877a84e134Smrgtemporary object file, and libtool could not work around it because
37885ec34c4cSmrgyour compiler does not support '-c' and '-o' together.  If you
37897a84e134Smrgrepeat this compilation, it may succeed, by chance, but you had better
37907a84e134Smrgavoid parallel builds (make -j) in this platform, or get a better
37917a84e134Smrgcompiler."
37927a84e134Smrg
3793994689c1Smrg	$opt_dry_run || $RM $removelist
37947a84e134Smrg	exit $EXIT_FAILURE
37957a84e134Smrg      fi
37967a84e134Smrg
37977a84e134Smrg      # Just move the object if needed, then go on to compile the next one
37987a84e134Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3799994689c1Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3800994689c1Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38017a84e134Smrg      fi
38027a84e134Smrg
38037a84e134Smrg      # Allow error messages only from the first compilation.
38045ec34c4cSmrg      if test yes = "$suppress_opt"; then
3805994689c1Smrg	suppress_output=' >/dev/null 2>&1'
38067a84e134Smrg      fi
38077a84e134Smrg    fi
38087a84e134Smrg
38097a84e134Smrg    # Only build a position-dependent object if we build old libraries.
38105ec34c4cSmrg    if test yes = "$build_old_libs"; then
38115ec34c4cSmrg      if test yes != "$pic_mode"; then
38127a84e134Smrg	# Don't build PIC code
3813994689c1Smrg	command="$base_compile $qsrcfile$pie_flag"
38147a84e134Smrg      else
38157a84e134Smrg	command="$base_compile $qsrcfile $pic_flag"
38167a84e134Smrg      fi
38175ec34c4cSmrg      if test yes = "$compiler_c_o"; then
3818f353fbadSmrg	func_append command " -o $obj"
38197a84e134Smrg      fi
38207a84e134Smrg
38217a84e134Smrg      # Suppress compiler output if we already did a PIC compilation.
3822f353fbadSmrg      func_append command "$suppress_output"
3823994689c1Smrg      func_show_eval_locale "$command" \
3824994689c1Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
38257a84e134Smrg
38265ec34c4cSmrg      if test warn = "$need_locks" &&
38277a84e134Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3828994689c1Smrg	$ECHO "\
38297a84e134Smrg*** ERROR, $lockfile contains:
38307a84e134Smrg`cat $lockfile 2>/dev/null`
38317a84e134Smrg
38327a84e134Smrgbut it should contain:
38337a84e134Smrg$srcfile
38347a84e134Smrg
38357a84e134SmrgThis indicates that another process is trying to use the same
38367a84e134Smrgtemporary object file, and libtool could not work around it because
38375ec34c4cSmrgyour compiler does not support '-c' and '-o' together.  If you
38387a84e134Smrgrepeat this compilation, it may succeed, by chance, but you had better
38397a84e134Smrgavoid parallel builds (make -j) in this platform, or get a better
38407a84e134Smrgcompiler."
38417a84e134Smrg
3842994689c1Smrg	$opt_dry_run || $RM $removelist
38437a84e134Smrg	exit $EXIT_FAILURE
38447a84e134Smrg      fi
38457a84e134Smrg
38467a84e134Smrg      # Just move the object if needed
38477a84e134Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3848994689c1Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3849994689c1Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38507a84e134Smrg      fi
38517a84e134Smrg    fi
38527a84e134Smrg
3853994689c1Smrg    $opt_dry_run || {
3854994689c1Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
38557a84e134Smrg
3856994689c1Smrg      # Unlock the critical section if it was locked
38575ec34c4cSmrg      if test no != "$need_locks"; then
3858994689c1Smrg	removelist=$lockfile
3859994689c1Smrg        $RM "$lockfile"
3860994689c1Smrg      fi
3861994689c1Smrg    }
38627a84e134Smrg
38637a84e134Smrg    exit $EXIT_SUCCESS
3864994689c1Smrg}
38657a84e134Smrg
3866994689c1Smrg$opt_help || {
38675ec34c4cSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3868994689c1Smrg}
38697a84e134Smrg
3870994689c1Smrgfunc_mode_help ()
3871994689c1Smrg{
3872994689c1Smrg    # We need to display help for each of the modes.
3873f353fbadSmrg    case $opt_mode in
3874994689c1Smrg      "")
3875994689c1Smrg        # Generic help is extracted from the usage comments
3876994689c1Smrg        # at the start of this file.
3877994689c1Smrg        func_help
3878994689c1Smrg        ;;
38797a84e134Smrg
3880994689c1Smrg      clean)
3881994689c1Smrg        $ECHO \
3882994689c1Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
38837a84e134Smrg
3884994689c1SmrgRemove files from the build directory.
38857a84e134Smrg
3886994689c1SmrgRM is the name of the program to use to delete files associated with each FILE
38875ec34c4cSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3888994689c1Smrgto RM.
38897a84e134Smrg
3890994689c1SmrgIf FILE is a libtool library, object or program, all the files associated
3891994689c1Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3892994689c1Smrg        ;;
38937a84e134Smrg
3894994689c1Smrg      compile)
3895994689c1Smrg      $ECHO \
3896994689c1Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
38977a84e134Smrg
3898994689c1SmrgCompile a source file into a libtool library object.
38997a84e134Smrg
3900994689c1SmrgThis mode accepts the following additional options:
39017a84e134Smrg
3902994689c1Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3903994689c1Smrg  -no-suppress      do not suppress compiler output for multiple passes
3904994689c1Smrg  -prefer-pic       try to build PIC objects only
3905994689c1Smrg  -prefer-non-pic   try to build non-PIC objects only
39065ec34c4cSmrg  -shared           do not build a '.o' file suitable for static linking
39075ec34c4cSmrg  -static           only build a '.o' file suitable for static linking
39085b16253fSmrg  -Wc,FLAG
39095b16253fSmrg  -Xcompiler FLAG   pass FLAG directly to the compiler
39107a84e134Smrg
39115ec34c4cSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3912994689c1Smrgfrom the given SOURCEFILE.
39137a84e134Smrg
3914994689c1SmrgThe output file name is determined by removing the directory component from
39155ec34c4cSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
39165ec34c4cSmrglibrary object suffix, '.lo'."
3917994689c1Smrg        ;;
39187a84e134Smrg
3919994689c1Smrg      execute)
3920994689c1Smrg        $ECHO \
3921994689c1Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
39227a84e134Smrg
3923994689c1SmrgAutomatically set library path, then run a program.
39247a84e134Smrg
3925994689c1SmrgThis mode accepts the following additional options:
39267a84e134Smrg
3927994689c1Smrg  -dlopen FILE      add the directory containing FILE to the library path
39287a84e134Smrg
39295ec34c4cSmrgThis mode sets the library path environment variable according to '-dlopen'
3930994689c1Smrgflags.
39317a84e134Smrg
3932994689c1SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3933994689c1Smrginto their corresponding uninstalled binary, and any of their required library
3934994689c1Smrgdirectories are added to the library path.
39357a84e134Smrg
3936994689c1SmrgThen, COMMAND is executed, with ARGS as arguments."
3937994689c1Smrg        ;;
39387a84e134Smrg
3939994689c1Smrg      finish)
3940994689c1Smrg        $ECHO \
3941994689c1Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
39427a84e134Smrg
3943994689c1SmrgComplete the installation of libtool libraries.
39447a84e134Smrg
3945994689c1SmrgEach LIBDIR is a directory that contains libtool libraries.
39467a84e134Smrg
3947994689c1SmrgThe commands that this mode executes may require superuser privileges.  Use
39485ec34c4cSmrgthe '--dry-run' option if you just want to see what would be executed."
3949994689c1Smrg        ;;
39507a84e134Smrg
3951994689c1Smrg      install)
3952994689c1Smrg        $ECHO \
3953994689c1Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
39547a84e134Smrg
3955994689c1SmrgInstall executables or libraries.
39567a84e134Smrg
3957994689c1SmrgINSTALL-COMMAND is the installation command.  The first component should be
39585ec34c4cSmrgeither the 'install' or 'cp' program.
39597a84e134Smrg
3960994689c1SmrgThe following components of INSTALL-COMMAND are treated specially:
39617a84e134Smrg
3962994689c1Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
39637a84e134Smrg
3964994689c1SmrgThe rest of the components are interpreted as arguments to that command (only
3965994689c1SmrgBSD-compatible install options are recognized)."
3966994689c1Smrg        ;;
39677a84e134Smrg
3968994689c1Smrg      link)
3969994689c1Smrg        $ECHO \
3970994689c1Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
39717a84e134Smrg
3972994689c1SmrgLink object files or libraries together to form another library, or to
3973994689c1Smrgcreate an executable program.
39747a84e134Smrg
3975994689c1SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3976994689c1Smrga program from several object files.
39777a84e134Smrg
3978994689c1SmrgThe following components of LINK-COMMAND are treated specially:
39797a84e134Smrg
3980994689c1Smrg  -all-static       do not do any dynamic linking at all
3981994689c1Smrg  -avoid-version    do not add a version suffix if possible
3982994689c1Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
3983994689c1Smrg                    libraries must be found in the PATH setting at runtime)
39845ec34c4cSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3985994689c1Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3986994689c1Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3987994689c1Smrg  -export-symbols SYMFILE
3988994689c1Smrg                    try to export only the symbols listed in SYMFILE
3989994689c1Smrg  -export-symbols-regex REGEX
3990994689c1Smrg                    try to export only the symbols matching REGEX
3991994689c1Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3992994689c1Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3993994689c1Smrg  -module           build a library that can dlopened
3994994689c1Smrg  -no-fast-install  disable the fast-install mode
3995994689c1Smrg  -no-install       link a not-installable executable
3996994689c1Smrg  -no-undefined     declare that a library does not refer to external symbols
3997994689c1Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
39985ec34c4cSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
39995ec34c4cSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
4000994689c1Smrg  -precious-files-regex REGEX
4001994689c1Smrg                    don't remove output files matching REGEX
4002994689c1Smrg  -release RELEASE  specify package release information
4003994689c1Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4004994689c1Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4005994689c1Smrg  -shared           only do dynamic linking of libtool libraries
4006994689c1Smrg  -shrext SUFFIX    override the standard shared library file extension
4007994689c1Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4008994689c1Smrg  -static-libtool-libs
4009994689c1Smrg                    do not do any dynamic linking of libtool libraries
4010994689c1Smrg  -version-info CURRENT[:REVISION[:AGE]]
4011994689c1Smrg                    specify library version info [each variable defaults to 0]
4012994689c1Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4013994689c1Smrg  -Wc,FLAG
4014994689c1Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
40155b16253fSmrg  -Wa,FLAG
40165b16253fSmrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4017994689c1Smrg  -Wl,FLAG
4018994689c1Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4019994689c1Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
40207a84e134Smrg
40215ec34c4cSmrgAll other options (arguments beginning with '-') are ignored.
40227a84e134Smrg
40235ec34c4cSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4024994689c1Smrgtreated as uninstalled libtool libraries, other files are standard or library
4025994689c1Smrgobject files.
40267a84e134Smrg
40275ec34c4cSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
40285ec34c4cSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4029994689c1Smrgrequired, except when creating a convenience library.
40307a84e134Smrg
40315ec34c4cSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
40325ec34c4cSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40337a84e134Smrg
40345ec34c4cSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4035994689c1Smrgis created, otherwise an executable program is created."
4036994689c1Smrg        ;;
40377a84e134Smrg
4038994689c1Smrg      uninstall)
4039994689c1Smrg        $ECHO \
4040994689c1Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
40417a84e134Smrg
4042994689c1SmrgRemove libraries from an installation directory.
40437a84e134Smrg
4044994689c1SmrgRM is the name of the program to use to delete files associated with each FILE
40455ec34c4cSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4046994689c1Smrgto RM.
40477a84e134Smrg
4048994689c1SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4049994689c1SmrgOtherwise, only FILE itself is deleted using RM."
4050994689c1Smrg        ;;
40517a84e134Smrg
4052994689c1Smrg      *)
40535ec34c4cSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4054994689c1Smrg        ;;
4055994689c1Smrg    esac
40567a84e134Smrg
4057994689c1Smrg    echo
40585ec34c4cSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4059994689c1Smrg}
4060775e7de9Smrg
4061994689c1Smrg# Now that we've collected a possible --mode arg, show help if necessary
4062994689c1Smrgif $opt_help; then
40635ec34c4cSmrg  if test : = "$opt_help"; then
4064994689c1Smrg    func_mode_help
4065994689c1Smrg  else
4066994689c1Smrg    {
4067994689c1Smrg      func_help noexit
4068f353fbadSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4069994689c1Smrg	func_mode_help
4070994689c1Smrg      done
40715ec34c4cSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4072994689c1Smrg    {
4073994689c1Smrg      func_help noexit
4074f353fbadSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4075994689c1Smrg	echo
4076994689c1Smrg	func_mode_help
4077994689c1Smrg      done
4078994689c1Smrg    } |
40795ec34c4cSmrg    $SED '1d
4080994689c1Smrg      /^When reporting/,/^Report/{
4081994689c1Smrg	H
4082994689c1Smrg	d
4083994689c1Smrg      }
4084994689c1Smrg      $x
4085994689c1Smrg      /information about other modes/d
4086994689c1Smrg      /more detailed .*MODE/d
4087994689c1Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4088994689c1Smrg  fi
4089994689c1Smrg  exit $?
4090994689c1Smrgfi
40917a84e134Smrg
40927a84e134Smrg
4093994689c1Smrg# func_mode_execute arg...
4094994689c1Smrgfunc_mode_execute ()
4095994689c1Smrg{
40965ec34c4cSmrg    $debug_cmd
40975ec34c4cSmrg
4098994689c1Smrg    # The first argument is the command name.
40995ec34c4cSmrg    cmd=$nonopt
4100994689c1Smrg    test -z "$cmd" && \
4101994689c1Smrg      func_fatal_help "you must specify a COMMAND"
4102ab902922Smrg
4103994689c1Smrg    # Handle -dlopen flags immediately.
4104f353fbadSmrg    for file in $opt_dlopen; do
4105994689c1Smrg      test -f "$file" \
41065ec34c4cSmrg	|| func_fatal_help "'$file' is not a file"
41077a84e134Smrg
4108994689c1Smrg      dir=
4109994689c1Smrg      case $file in
4110994689c1Smrg      *.la)
4111f353fbadSmrg	func_resolve_sysroot "$file"
4112f353fbadSmrg	file=$func_resolve_sysroot_result
4113f353fbadSmrg
4114994689c1Smrg	# Check to see that this really is a libtool archive.
4115994689c1Smrg	func_lalib_unsafe_p "$file" \
41165ec34c4cSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
41177a84e134Smrg
4118994689c1Smrg	# Read the libtool library.
4119994689c1Smrg	dlname=
4120994689c1Smrg	library_names=
4121994689c1Smrg	func_source "$file"
41227a84e134Smrg
4123994689c1Smrg	# Skip this library if it cannot be dlopened.
4124994689c1Smrg	if test -z "$dlname"; then
4125994689c1Smrg	  # Warn if it was a shared library.
4126994689c1Smrg	  test -n "$library_names" && \
41275ec34c4cSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4128994689c1Smrg	  continue
4129994689c1Smrg	fi
4130e1e1713cSmrg
4131994689c1Smrg	func_dirname "$file" "" "."
41325ec34c4cSmrg	dir=$func_dirname_result
4133e1e1713cSmrg
4134994689c1Smrg	if test -f "$dir/$objdir/$dlname"; then
4135f353fbadSmrg	  func_append dir "/$objdir"
4136994689c1Smrg	else
4137994689c1Smrg	  if test ! -f "$dir/$dlname"; then
41385ec34c4cSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4139994689c1Smrg	  fi
4140994689c1Smrg	fi
4141775e7de9Smrg	;;
4142e1e1713cSmrg
4143994689c1Smrg      *.lo)
4144994689c1Smrg	# Just add the directory containing the .lo file.
4145994689c1Smrg	func_dirname "$file" "" "."
41465ec34c4cSmrg	dir=$func_dirname_result
4147775e7de9Smrg	;;
4148994689c1Smrg
4149994689c1Smrg      *)
41505ec34c4cSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4151e1e1713cSmrg	continue
4152775e7de9Smrg	;;
4153994689c1Smrg      esac
4154775e7de9Smrg
4155994689c1Smrg      # Get the absolute pathname.
4156994689c1Smrg      absdir=`cd "$dir" && pwd`
41575ec34c4cSmrg      test -n "$absdir" && dir=$absdir
4158775e7de9Smrg
4159994689c1Smrg      # Now add the directory to shlibpath_var.
4160994689c1Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4161994689c1Smrg	eval "$shlibpath_var=\"\$dir\""
4162994689c1Smrg      else
4163994689c1Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4164994689c1Smrg      fi
4165994689c1Smrg    done
4166775e7de9Smrg
4167994689c1Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4168994689c1Smrg    # rather than running their programs.
41695ec34c4cSmrg    libtool_execute_magic=$magic
41707a84e134Smrg
4171994689c1Smrg    # Check if any of the arguments is a wrapper script.
4172994689c1Smrg    args=
4173994689c1Smrg    for file
4174994689c1Smrg    do
4175994689c1Smrg      case $file in
4176994689c1Smrg      -* | *.la | *.lo ) ;;
4177994689c1Smrg      *)
4178994689c1Smrg	# Do a test to see if this is really a libtool program.
4179994689c1Smrg	if func_ltwrapper_script_p "$file"; then
4180994689c1Smrg	  func_source "$file"
4181994689c1Smrg	  # Transform arg to wrapped name.
41825ec34c4cSmrg	  file=$progdir/$program
4183994689c1Smrg	elif func_ltwrapper_executable_p "$file"; then
4184994689c1Smrg	  func_ltwrapper_scriptname "$file"
4185994689c1Smrg	  func_source "$func_ltwrapper_scriptname_result"
4186994689c1Smrg	  # Transform arg to wrapped name.
41875ec34c4cSmrg	  file=$progdir/$program
4188994689c1Smrg	fi
4189e1e1713cSmrg	;;
4190994689c1Smrg      esac
4191994689c1Smrg      # Quote arguments (to preserve shell metacharacters).
4192f353fbadSmrg      func_append_quoted args "$file"
4193994689c1Smrg    done
41947a84e134Smrg
41955ec34c4cSmrg    if $opt_dry_run; then
41965ec34c4cSmrg      # Display what would be done.
41975ec34c4cSmrg      if test -n "$shlibpath_var"; then
41985ec34c4cSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
41995ec34c4cSmrg	echo "export $shlibpath_var"
42005ec34c4cSmrg      fi
42015ec34c4cSmrg      $ECHO "$cmd$args"
42025ec34c4cSmrg      exit $EXIT_SUCCESS
42035ec34c4cSmrg    else
4204994689c1Smrg      if test -n "$shlibpath_var"; then
4205994689c1Smrg	# Export the shlibpath_var.
4206994689c1Smrg	eval "export $shlibpath_var"
4207994689c1Smrg      fi
4208775e7de9Smrg
4209994689c1Smrg      # Restore saved environment variables
4210994689c1Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4211994689c1Smrg      do
4212994689c1Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4213994689c1Smrg                $lt_var=\$save_$lt_var; export $lt_var
4214994689c1Smrg	      else
4215994689c1Smrg		$lt_unset $lt_var
4216994689c1Smrg	      fi"
4217994689c1Smrg      done
42187a84e134Smrg
4219994689c1Smrg      # Now prepare to actually exec the command.
42205ec34c4cSmrg      exec_cmd=\$cmd$args
4221994689c1Smrg    fi
4222994689c1Smrg}
4223775e7de9Smrg
42245ec34c4cSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4225775e7de9Smrg
4226775e7de9Smrg
4227994689c1Smrg# func_mode_finish arg...
4228994689c1Smrgfunc_mode_finish ()
4229994689c1Smrg{
42305ec34c4cSmrg    $debug_cmd
42315ec34c4cSmrg
4232f353fbadSmrg    libs=
4233f353fbadSmrg    libdirs=
4234994689c1Smrg    admincmds=
4235775e7de9Smrg
4236f353fbadSmrg    for opt in "$nonopt" ${1+"$@"}
4237f353fbadSmrg    do
4238f353fbadSmrg      if test -d "$opt"; then
4239f353fbadSmrg	func_append libdirs " $opt"
4240f353fbadSmrg
4241f353fbadSmrg      elif test -f "$opt"; then
4242f353fbadSmrg	if func_lalib_unsafe_p "$opt"; then
4243f353fbadSmrg	  func_append libs " $opt"
4244f353fbadSmrg	else
42455ec34c4cSmrg	  func_warning "'$opt' is not a valid libtool archive"
4246f353fbadSmrg	fi
4247f353fbadSmrg
4248f353fbadSmrg      else
42495ec34c4cSmrg	func_fatal_error "invalid argument '$opt'"
4250f353fbadSmrg      fi
4251f353fbadSmrg    done
4252f353fbadSmrg
4253f353fbadSmrg    if test -n "$libs"; then
4254f353fbadSmrg      if test -n "$lt_sysroot"; then
4255f353fbadSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4256f353fbadSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4257f353fbadSmrg      else
4258f353fbadSmrg        sysroot_cmd=
4259f353fbadSmrg      fi
4260f353fbadSmrg
4261f353fbadSmrg      # Remove sysroot references
4262f353fbadSmrg      if $opt_dry_run; then
4263f353fbadSmrg        for lib in $libs; do
42645ec34c4cSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4265f353fbadSmrg        done
4266f353fbadSmrg      else
4267f353fbadSmrg        tmpdir=`func_mktempdir`
4268f353fbadSmrg        for lib in $libs; do
42695ec34c4cSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4270f353fbadSmrg	    > $tmpdir/tmp-la
4271f353fbadSmrg	  mv -f $tmpdir/tmp-la $lib
4272f353fbadSmrg	done
4273f353fbadSmrg        ${RM}r "$tmpdir"
4274f353fbadSmrg      fi
4275f353fbadSmrg    fi
4276775e7de9Smrg
4277f353fbadSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4278994689c1Smrg      for libdir in $libdirs; do
4279994689c1Smrg	if test -n "$finish_cmds"; then
4280994689c1Smrg	  # Do each command in the finish commands.
4281994689c1Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4282994689c1Smrg'"$cmd"'"'
4283994689c1Smrg	fi
4284994689c1Smrg	if test -n "$finish_eval"; then
4285994689c1Smrg	  # Do the single finish_eval.
4286994689c1Smrg	  eval cmds=\"$finish_eval\"
4287f353fbadSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4288994689c1Smrg       $cmds"
4289994689c1Smrg	fi
4290994689c1Smrg      done
4291994689c1Smrg    fi
4292775e7de9Smrg
4293994689c1Smrg    # Exit here if they wanted silent mode.
42945ec34c4cSmrg    $opt_quiet && exit $EXIT_SUCCESS
4295775e7de9Smrg
4296f353fbadSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4297f353fbadSmrg      echo "----------------------------------------------------------------------"
4298f353fbadSmrg      echo "Libraries have been installed in:"
4299f353fbadSmrg      for libdir in $libdirs; do
4300f353fbadSmrg	$ECHO "   $libdir"
4301f353fbadSmrg      done
4302f353fbadSmrg      echo
4303f353fbadSmrg      echo "If you ever happen to want to link against installed libraries"
4304f353fbadSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
43055ec34c4cSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4306f353fbadSmrg      echo "flag during linking and do at least one of the following:"
4307f353fbadSmrg      if test -n "$shlibpath_var"; then
43085ec34c4cSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4309f353fbadSmrg	echo "     during execution"
4310f353fbadSmrg      fi
4311f353fbadSmrg      if test -n "$runpath_var"; then
43125ec34c4cSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4313f353fbadSmrg	echo "     during linking"
4314f353fbadSmrg      fi
4315f353fbadSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4316f353fbadSmrg	libdir=LIBDIR
4317f353fbadSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4318775e7de9Smrg
43195ec34c4cSmrg	$ECHO "   - use the '$flag' linker flag"
4320f353fbadSmrg      fi
4321f353fbadSmrg      if test -n "$admincmds"; then
4322f353fbadSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4323f353fbadSmrg      fi
4324f353fbadSmrg      if test -f /etc/ld.so.conf; then
43255ec34c4cSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4326f353fbadSmrg      fi
4327f353fbadSmrg      echo
4328775e7de9Smrg
4329f353fbadSmrg      echo "See any operating system documentation about shared libraries for"
4330f353fbadSmrg      case $host in
4331f353fbadSmrg	solaris2.[6789]|solaris2.1[0-9])
4332f353fbadSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4333f353fbadSmrg	  echo "pages."
4334f353fbadSmrg	  ;;
4335f353fbadSmrg	*)
4336f353fbadSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4337f353fbadSmrg	  ;;
4338f353fbadSmrg      esac
4339f353fbadSmrg      echo "----------------------------------------------------------------------"
4340f353fbadSmrg    fi
4341994689c1Smrg    exit $EXIT_SUCCESS
4342994689c1Smrg}
4343775e7de9Smrg
43445ec34c4cSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4345e1e1713cSmrg
43467a84e134Smrg
4347994689c1Smrg# func_mode_install arg...
4348994689c1Smrgfunc_mode_install ()
4349994689c1Smrg{
43505ec34c4cSmrg    $debug_cmd
43515ec34c4cSmrg
4352994689c1Smrg    # There may be an optional sh(1) argument at the beginning of
4353994689c1Smrg    # install_prog (especially on Windows NT).
43545ec34c4cSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4355994689c1Smrg       # Allow the use of GNU shtool's install command.
43565ec34c4cSmrg       case $nonopt in *shtool*) :;; *) false;; esac
43575ec34c4cSmrg    then
4358994689c1Smrg      # Aesthetically quote it.
43595b16253fSmrg      func_quote_arg pretty "$nonopt"
43605b16253fSmrg      install_prog="$func_quote_arg_result "
4361994689c1Smrg      arg=$1
4362994689c1Smrg      shift
4363994689c1Smrg    else
4364994689c1Smrg      install_prog=
4365994689c1Smrg      arg=$nonopt
4366994689c1Smrg    fi
43677a84e134Smrg
4368994689c1Smrg    # The real first argument should be the name of the installation program.
4369994689c1Smrg    # Aesthetically quote it.
43705b16253fSmrg    func_quote_arg pretty "$arg"
43715b16253fSmrg    func_append install_prog "$func_quote_arg_result"
4372994689c1Smrg    install_shared_prog=$install_prog
4373994689c1Smrg    case " $install_prog " in
4374994689c1Smrg      *[\\\ /]cp\ *) install_cp=: ;;
4375994689c1Smrg      *) install_cp=false ;;
4376994689c1Smrg    esac
43777a84e134Smrg
4378994689c1Smrg    # We need to accept at least all the BSD install flags.
4379994689c1Smrg    dest=
4380994689c1Smrg    files=
4381994689c1Smrg    opts=
4382994689c1Smrg    prev=
4383994689c1Smrg    install_type=
43845ec34c4cSmrg    isdir=false
4385994689c1Smrg    stripme=
4386994689c1Smrg    no_mode=:
4387994689c1Smrg    for arg
4388994689c1Smrg    do
4389994689c1Smrg      arg2=
4390994689c1Smrg      if test -n "$dest"; then
4391f353fbadSmrg	func_append files " $dest"
4392994689c1Smrg	dest=$arg
4393e1e1713cSmrg	continue
4394994689c1Smrg      fi
43957a84e134Smrg
4396994689c1Smrg      case $arg in
43975ec34c4cSmrg      -d) isdir=: ;;
4398994689c1Smrg      -f)
4399994689c1Smrg	if $install_cp; then :; else
4400994689c1Smrg	  prev=$arg
4401775e7de9Smrg	fi
4402994689c1Smrg	;;
4403994689c1Smrg      -g | -m | -o)
4404994689c1Smrg	prev=$arg
4405994689c1Smrg	;;
4406994689c1Smrg      -s)
4407994689c1Smrg	stripme=" -s"
4408e1e1713cSmrg	continue
4409e1e1713cSmrg	;;
4410994689c1Smrg      -*)
4411994689c1Smrg	;;
4412e1e1713cSmrg      *)
4413994689c1Smrg	# If the previous option needed an argument, then skip it.
4414994689c1Smrg	if test -n "$prev"; then
44155ec34c4cSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4416994689c1Smrg	    arg2=$install_override_mode
4417994689c1Smrg	    no_mode=false
4418994689c1Smrg	  fi
4419994689c1Smrg	  prev=
4420994689c1Smrg	else
4421994689c1Smrg	  dest=$arg
4422994689c1Smrg	  continue
4423994689c1Smrg	fi
4424775e7de9Smrg	;;
4425994689c1Smrg      esac
44267a84e134Smrg
4427994689c1Smrg      # Aesthetically quote the argument.
44285b16253fSmrg      func_quote_arg pretty "$arg"
44295b16253fSmrg      func_append install_prog " $func_quote_arg_result"
4430994689c1Smrg      if test -n "$arg2"; then
44315b16253fSmrg	func_quote_arg pretty "$arg2"
4432e1e1713cSmrg      fi
44335b16253fSmrg      func_append install_shared_prog " $func_quote_arg_result"
4434994689c1Smrg    done
44357a84e134Smrg
4436994689c1Smrg    test -z "$install_prog" && \
4437994689c1Smrg      func_fatal_help "you must specify an install program"
44387a84e134Smrg
4439994689c1Smrg    test -n "$prev" && \
44405ec34c4cSmrg      func_fatal_help "the '$prev' option requires an argument"
4441775e7de9Smrg
4442994689c1Smrg    if test -n "$install_override_mode" && $no_mode; then
4443994689c1Smrg      if $install_cp; then :; else
44445b16253fSmrg	func_quote_arg pretty "$install_override_mode"
44455b16253fSmrg	func_append install_shared_prog " -m $func_quote_arg_result"
4446994689c1Smrg      fi
4447e1e1713cSmrg    fi
4448775e7de9Smrg
4449994689c1Smrg    if test -z "$files"; then
4450994689c1Smrg      if test -z "$dest"; then
4451994689c1Smrg	func_fatal_help "no file or destination specified"
4452994689c1Smrg      else
4453994689c1Smrg	func_fatal_help "you must specify a destination"
4454775e7de9Smrg      fi
4455775e7de9Smrg    fi
4456775e7de9Smrg
4457994689c1Smrg    # Strip any trailing slash from the destination.
4458994689c1Smrg    func_stripname '' '/' "$dest"
4459994689c1Smrg    dest=$func_stripname_result
44607a84e134Smrg
4461994689c1Smrg    # Check to see that the destination is a directory.
44625ec34c4cSmrg    test -d "$dest" && isdir=:
44635ec34c4cSmrg    if $isdir; then
44645ec34c4cSmrg      destdir=$dest
4465994689c1Smrg      destname=
4466994689c1Smrg    else
4467994689c1Smrg      func_dirname_and_basename "$dest" "" "."
44685ec34c4cSmrg      destdir=$func_dirname_result
44695ec34c4cSmrg      destname=$func_basename_result
4470994689c1Smrg
4471994689c1Smrg      # Not a directory, so check to see that there is only one file specified.
4472994689c1Smrg      set dummy $files; shift
4473994689c1Smrg      test "$#" -gt 1 && \
44745ec34c4cSmrg	func_fatal_help "'$dest' is not a directory"
4475994689c1Smrg    fi
4476994689c1Smrg    case $destdir in
4477994689c1Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4478e1e1713cSmrg    *)
4479994689c1Smrg      for file in $files; do
4480994689c1Smrg	case $file in
4481994689c1Smrg	*.lo) ;;
4482994689c1Smrg	*)
44835ec34c4cSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4484994689c1Smrg	  ;;
4485994689c1Smrg	esac
4486994689c1Smrg      done
4487e1e1713cSmrg      ;;
4488e1e1713cSmrg    esac
44897a84e134Smrg
4490994689c1Smrg    # This variable tells wrapper scripts just to set variables rather
4491994689c1Smrg    # than running their programs.
44925ec34c4cSmrg    libtool_install_magic=$magic
44937a84e134Smrg
4494994689c1Smrg    staticlibs=
4495994689c1Smrg    future_libdirs=
4496994689c1Smrg    current_libdirs=
4497994689c1Smrg    for file in $files; do
44987a84e134Smrg
4499994689c1Smrg      # Do each installation.
4500994689c1Smrg      case $file in
4501994689c1Smrg      *.$libext)
4502994689c1Smrg	# Do the static libraries later.
4503f353fbadSmrg	func_append staticlibs " $file"
4504994689c1Smrg	;;
4505994689c1Smrg
4506994689c1Smrg      *.la)
4507f353fbadSmrg	func_resolve_sysroot "$file"
4508f353fbadSmrg	file=$func_resolve_sysroot_result
4509f353fbadSmrg
4510994689c1Smrg	# Check to see that this really is a libtool archive.
4511994689c1Smrg	func_lalib_unsafe_p "$file" \
45125ec34c4cSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4513994689c1Smrg
4514994689c1Smrg	library_names=
4515994689c1Smrg	old_library=
4516994689c1Smrg	relink_command=
4517994689c1Smrg	func_source "$file"
4518994689c1Smrg
4519994689c1Smrg	# Add the libdir to current_libdirs if it is the destination.
4520994689c1Smrg	if test "X$destdir" = "X$libdir"; then
4521994689c1Smrg	  case "$current_libdirs " in
4522994689c1Smrg	  *" $libdir "*) ;;
4523f353fbadSmrg	  *) func_append current_libdirs " $libdir" ;;
4524775e7de9Smrg	  esac
4525994689c1Smrg	else
4526994689c1Smrg	  # Note the libdir as a future libdir.
4527994689c1Smrg	  case "$future_libdirs " in
4528994689c1Smrg	  *" $libdir "*) ;;
4529f353fbadSmrg	  *) func_append future_libdirs " $libdir" ;;
4530994689c1Smrg	  esac
4531994689c1Smrg	fi
4532775e7de9Smrg
4533994689c1Smrg	func_dirname "$file" "/" ""
45345ec34c4cSmrg	dir=$func_dirname_result
4535f353fbadSmrg	func_append dir "$objdir"
4536994689c1Smrg
4537994689c1Smrg	if test -n "$relink_command"; then
4538994689c1Smrg	  # Determine the prefix the user has applied to our future dir.
4539994689c1Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4540994689c1Smrg
4541994689c1Smrg	  # Don't allow the user to place us outside of our expected
4542994689c1Smrg	  # location b/c this prevents finding dependent libraries that
4543994689c1Smrg	  # are installed to the same prefix.
4544994689c1Smrg	  # At present, this check doesn't affect windows .dll's that
4545994689c1Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4546994689c1Smrg	  # but it's something to keep an eye on.
4547994689c1Smrg	  test "$inst_prefix_dir" = "$destdir" && \
45485ec34c4cSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4549994689c1Smrg
4550994689c1Smrg	  if test -n "$inst_prefix_dir"; then
4551994689c1Smrg	    # Stick the inst_prefix_dir data into the link command.
4552994689c1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4553994689c1Smrg	  else
4554994689c1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4555994689c1Smrg	  fi
4556994689c1Smrg
45575ec34c4cSmrg	  func_warning "relinking '$file'"
4558994689c1Smrg	  func_show_eval "$relink_command" \
45595ec34c4cSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4560994689c1Smrg	fi
4561994689c1Smrg
4562994689c1Smrg	# See the names of the shared library.
4563994689c1Smrg	set dummy $library_names; shift
4564994689c1Smrg	if test -n "$1"; then
45655ec34c4cSmrg	  realname=$1
4566994689c1Smrg	  shift
4567994689c1Smrg
45685ec34c4cSmrg	  srcname=$realname
45695ec34c4cSmrg	  test -n "$relink_command" && srcname=${realname}T
4570994689c1Smrg
4571994689c1Smrg	  # Install the shared library and build the symlinks.
4572994689c1Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4573994689c1Smrg	      'exit $?'
45745ec34c4cSmrg	  tstripme=$stripme
4575994689c1Smrg	  case $host_os in
4576994689c1Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4577994689c1Smrg	    case $realname in
4578994689c1Smrg	    *.dll.a)
45795ec34c4cSmrg	      tstripme=
45805ec34c4cSmrg	      ;;
45815ec34c4cSmrg	    esac
45825ec34c4cSmrg	    ;;
45835ec34c4cSmrg	  os2*)
45845ec34c4cSmrg	    case $realname in
45855ec34c4cSmrg	    *_dll.a)
45865ec34c4cSmrg	      tstripme=
4587994689c1Smrg	      ;;
4588994689c1Smrg	    esac
4589775e7de9Smrg	    ;;
4590775e7de9Smrg	  esac
4591994689c1Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4592994689c1Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4593994689c1Smrg	  fi
4594994689c1Smrg
4595994689c1Smrg	  if test "$#" -gt 0; then
4596994689c1Smrg	    # Delete the old symlinks, and create new ones.
45975ec34c4cSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4598994689c1Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4599994689c1Smrg	    # so we also need to try rm && ln -s.
4600994689c1Smrg	    for linkname
4601994689c1Smrg	    do
4602994689c1Smrg	      test "$linkname" != "$realname" \
4603994689c1Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4604994689c1Smrg	    done
4605994689c1Smrg	  fi
4606994689c1Smrg
4607994689c1Smrg	  # Do each command in the postinstall commands.
46085ec34c4cSmrg	  lib=$destdir/$realname
4609994689c1Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4610994689c1Smrg	fi
4611994689c1Smrg
4612994689c1Smrg	# Install the pseudo-library for information purposes.
4613994689c1Smrg	func_basename "$file"
46145ec34c4cSmrg	name=$func_basename_result
46155ec34c4cSmrg	instname=$dir/${name}i
4616994689c1Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4617994689c1Smrg
4618994689c1Smrg	# Maybe install the static library, too.
4619f353fbadSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4620775e7de9Smrg	;;
4621994689c1Smrg
4622994689c1Smrg      *.lo)
4623994689c1Smrg	# Install (i.e. copy) a libtool object.
4624994689c1Smrg
4625994689c1Smrg	# Figure out destination file name, if it wasn't already specified.
4626994689c1Smrg	if test -n "$destname"; then
46275ec34c4cSmrg	  destfile=$destdir/$destname
4628994689c1Smrg	else
4629994689c1Smrg	  func_basename "$file"
46305ec34c4cSmrg	  destfile=$func_basename_result
46315ec34c4cSmrg	  destfile=$destdir/$destfile
4632994689c1Smrg	fi
4633994689c1Smrg
4634994689c1Smrg	# Deduce the name of the destination old-style object file.
4635994689c1Smrg	case $destfile in
4636994689c1Smrg	*.lo)
4637994689c1Smrg	  func_lo2o "$destfile"
4638994689c1Smrg	  staticdest=$func_lo2o_result
4639e1e1713cSmrg	  ;;
4640994689c1Smrg	*.$objext)
46415ec34c4cSmrg	  staticdest=$destfile
4642994689c1Smrg	  destfile=
4643e1e1713cSmrg	  ;;
4644994689c1Smrg	*)
46455ec34c4cSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4646e1e1713cSmrg	  ;;
4647994689c1Smrg	esac
4648994689c1Smrg
4649994689c1Smrg	# Install the libtool object if requested.
4650994689c1Smrg	test -n "$destfile" && \
4651994689c1Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4652994689c1Smrg
4653994689c1Smrg	# Install the old object if enabled.
46545ec34c4cSmrg	if test yes = "$build_old_libs"; then
4655994689c1Smrg	  # Deduce the name of the old-style object file.
4656994689c1Smrg	  func_lo2o "$file"
4657994689c1Smrg	  staticobj=$func_lo2o_result
4658994689c1Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4659e1e1713cSmrg	fi
4660994689c1Smrg	exit $EXIT_SUCCESS
4661994689c1Smrg	;;
46627a84e134Smrg
4663994689c1Smrg      *)
4664994689c1Smrg	# Figure out destination file name, if it wasn't already specified.
4665994689c1Smrg	if test -n "$destname"; then
46665ec34c4cSmrg	  destfile=$destdir/$destname
4667e1e1713cSmrg	else
4668994689c1Smrg	  func_basename "$file"
46695ec34c4cSmrg	  destfile=$func_basename_result
46705ec34c4cSmrg	  destfile=$destdir/$destfile
4671e1e1713cSmrg	fi
46727a84e134Smrg
4673994689c1Smrg	# If the file is missing, and there is a .exe on the end, strip it
4674994689c1Smrg	# because it is most likely a libtool script we actually want to
4675994689c1Smrg	# install
46765ec34c4cSmrg	stripped_ext=
4677994689c1Smrg	case $file in
4678994689c1Smrg	  *.exe)
4679994689c1Smrg	    if test ! -f "$file"; then
4680994689c1Smrg	      func_stripname '' '.exe' "$file"
4681994689c1Smrg	      file=$func_stripname_result
46825ec34c4cSmrg	      stripped_ext=.exe
4683994689c1Smrg	    fi
4684994689c1Smrg	    ;;
4685994689c1Smrg	esac
46867a84e134Smrg
4687994689c1Smrg	# Do a test to see if this is really a libtool program.
4688994689c1Smrg	case $host in
4689994689c1Smrg	*cygwin* | *mingw*)
4690994689c1Smrg	    if func_ltwrapper_executable_p "$file"; then
4691994689c1Smrg	      func_ltwrapper_scriptname "$file"
4692994689c1Smrg	      wrapper=$func_ltwrapper_scriptname_result
4693994689c1Smrg	    else
4694994689c1Smrg	      func_stripname '' '.exe' "$file"
4695994689c1Smrg	      wrapper=$func_stripname_result
4696994689c1Smrg	    fi
4697994689c1Smrg	    ;;
4698994689c1Smrg	*)
4699994689c1Smrg	    wrapper=$file
4700994689c1Smrg	    ;;
4701994689c1Smrg	esac
4702994689c1Smrg	if func_ltwrapper_script_p "$wrapper"; then
4703994689c1Smrg	  notinst_deplibs=
4704994689c1Smrg	  relink_command=
47057a84e134Smrg
4706994689c1Smrg	  func_source "$wrapper"
47077a84e134Smrg
4708994689c1Smrg	  # Check the variables that should have been set.
4709994689c1Smrg	  test -z "$generated_by_libtool_version" && \
47105ec34c4cSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
47117a84e134Smrg
47125ec34c4cSmrg	  finalize=:
4713994689c1Smrg	  for lib in $notinst_deplibs; do
4714994689c1Smrg	    # Check to see that each library is installed.
4715994689c1Smrg	    libdir=
4716994689c1Smrg	    if test -f "$lib"; then
4717994689c1Smrg	      func_source "$lib"
4718e1e1713cSmrg	    fi
47195ec34c4cSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4720994689c1Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
47215ec34c4cSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
47225ec34c4cSmrg	      finalize=false
4723994689c1Smrg	    fi
4724994689c1Smrg	  done
47257a84e134Smrg
4726994689c1Smrg	  relink_command=
4727994689c1Smrg	  func_source "$wrapper"
47287a84e134Smrg
4729994689c1Smrg	  outputname=
47305ec34c4cSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4731994689c1Smrg	    $opt_dry_run || {
47325ec34c4cSmrg	      if $finalize; then
4733994689c1Smrg	        tmpdir=`func_mktempdir`
4734994689c1Smrg		func_basename "$file$stripped_ext"
47355ec34c4cSmrg		file=$func_basename_result
47365ec34c4cSmrg	        outputname=$tmpdir/$file
4737994689c1Smrg	        # Replace the output file specification.
4738994689c1Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4739994689c1Smrg
47405ec34c4cSmrg	        $opt_quiet || {
47415b16253fSmrg	          func_quote_arg expand,pretty "$relink_command"
47425b16253fSmrg		  eval "func_echo $func_quote_arg_result"
4743994689c1Smrg	        }
4744994689c1Smrg	        if eval "$relink_command"; then :
4745994689c1Smrg	          else
47465ec34c4cSmrg		  func_error "error: relink '$file' with the above command before installing it"
4747994689c1Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4748994689c1Smrg		  continue
4749994689c1Smrg	        fi
47505ec34c4cSmrg	        file=$outputname
4751994689c1Smrg	      else
47525ec34c4cSmrg	        func_warning "cannot relink '$file'"
4753994689c1Smrg	      fi
4754994689c1Smrg	    }
4755e1e1713cSmrg	  else
4756994689c1Smrg	    # Install the binary that we compiled earlier.
4757994689c1Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4758e1e1713cSmrg	  fi
4759994689c1Smrg	fi
47607a84e134Smrg
4761994689c1Smrg	# remove .exe since cygwin /usr/bin/install will append another
4762994689c1Smrg	# one anyway
4763994689c1Smrg	case $install_prog,$host in
4764994689c1Smrg	*/usr/bin/install*,*cygwin*)
4765994689c1Smrg	  case $file:$destfile in
4766994689c1Smrg	  *.exe:*.exe)
4767994689c1Smrg	    # this is ok
4768994689c1Smrg	    ;;
4769994689c1Smrg	  *.exe:*)
4770994689c1Smrg	    destfile=$destfile.exe
4771994689c1Smrg	    ;;
4772994689c1Smrg	  *:*.exe)
4773994689c1Smrg	    func_stripname '' '.exe' "$destfile"
4774994689c1Smrg	    destfile=$func_stripname_result
4775994689c1Smrg	    ;;
4776994689c1Smrg	  esac
4777e1e1713cSmrg	  ;;
4778e1e1713cSmrg	esac
4779994689c1Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4780994689c1Smrg	$opt_dry_run || if test -n "$outputname"; then
4781994689c1Smrg	  ${RM}r "$tmpdir"
4782994689c1Smrg	fi
4783994689c1Smrg	;;
4784994689c1Smrg      esac
4785994689c1Smrg    done
47867a84e134Smrg
4787994689c1Smrg    for file in $staticlibs; do
4788994689c1Smrg      func_basename "$file"
47895ec34c4cSmrg      name=$func_basename_result
4790994689c1Smrg
4791994689c1Smrg      # Set up the ranlib parameters.
47925ec34c4cSmrg      oldlib=$destdir/$name
4793421c997bSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4794421c997bSmrg      tool_oldlib=$func_to_tool_file_result
4795994689c1Smrg
4796994689c1Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4797994689c1Smrg
4798994689c1Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4799421c997bSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4800994689c1Smrg      fi
4801994689c1Smrg
4802994689c1Smrg      # Do each command in the postinstall commands.
4803994689c1Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4804994689c1Smrg    done
4805994689c1Smrg
4806994689c1Smrg    test -n "$future_libdirs" && \
48075ec34c4cSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4808994689c1Smrg
4809994689c1Smrg    if test -n "$current_libdirs"; then
4810994689c1Smrg      # Maybe just do a dry run.
4811994689c1Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
48125ec34c4cSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4813994689c1Smrg    else
4814994689c1Smrg      exit $EXIT_SUCCESS
4815994689c1Smrg    fi
4816994689c1Smrg}
4817994689c1Smrg
48185ec34c4cSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4819994689c1Smrg
4820994689c1Smrg
4821994689c1Smrg# func_generate_dlsyms outputname originator pic_p
4822994689c1Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4823994689c1Smrg# a dlpreopen symbol table.
4824994689c1Smrgfunc_generate_dlsyms ()
4825994689c1Smrg{
48265ec34c4cSmrg    $debug_cmd
48275ec34c4cSmrg
48285ec34c4cSmrg    my_outputname=$1
48295ec34c4cSmrg    my_originator=$2
48305ec34c4cSmrg    my_pic_p=${3-false}
48315ec34c4cSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4832994689c1Smrg    my_dlsyms=
4833994689c1Smrg
48345ec34c4cSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4835994689c1Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
48365ec34c4cSmrg	my_dlsyms=${my_outputname}S.c
4837994689c1Smrg      else
4838994689c1Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4839994689c1Smrg      fi
4840994689c1Smrg    fi
4841994689c1Smrg
4842994689c1Smrg    if test -n "$my_dlsyms"; then
4843994689c1Smrg      case $my_dlsyms in
4844994689c1Smrg      "") ;;
4845994689c1Smrg      *.c)
4846994689c1Smrg	# Discover the nlist of each of the dlfiles.
48475ec34c4cSmrg	nlist=$output_objdir/$my_outputname.nm
4848994689c1Smrg
4849994689c1Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4850994689c1Smrg
4851994689c1Smrg	# Parse the name list into a source file.
4852994689c1Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4853994689c1Smrg
4854994689c1Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
48555ec34c4cSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
48565ec34c4cSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4857994689c1Smrg
4858994689c1Smrg#ifdef __cplusplus
4859994689c1Smrgextern \"C\" {
4860994689c1Smrg#endif
4861994689c1Smrg
48625ec34c4cSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4863994689c1Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4864994689c1Smrg#endif
4865994689c1Smrg
4866f353fbadSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
48675ec34c4cSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
48685ec34c4cSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4869f353fbadSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4870f353fbadSmrg# define LT_DLSYM_CONST
48715ec34c4cSmrg#elif defined __osf__
4872f353fbadSmrg/* This system does not cope well with relocations in const data.  */
4873f353fbadSmrg# define LT_DLSYM_CONST
4874f353fbadSmrg#else
4875f353fbadSmrg# define LT_DLSYM_CONST const
4876f353fbadSmrg#endif
4877f353fbadSmrg
48785ec34c4cSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
48795ec34c4cSmrg
4880994689c1Smrg/* External symbol declarations for the compiler. */\
4881994689c1Smrg"
4882994689c1Smrg
48835ec34c4cSmrg	if test yes = "$dlself"; then
48845ec34c4cSmrg	  func_verbose "generating symbol list for '$output'"
4885994689c1Smrg
4886994689c1Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4887994689c1Smrg
4888994689c1Smrg	  # Add our own program objects to the symbol list.
4889994689c1Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4890994689c1Smrg	  for progfile in $progfiles; do
4891f353fbadSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
48925ec34c4cSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4893f353fbadSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4894994689c1Smrg	  done
4895994689c1Smrg
4896994689c1Smrg	  if test -n "$exclude_expsyms"; then
4897994689c1Smrg	    $opt_dry_run || {
4898994689c1Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4899994689c1Smrg	      eval '$MV "$nlist"T "$nlist"'
4900994689c1Smrg	    }
4901e1e1713cSmrg	  fi
4902994689c1Smrg
4903994689c1Smrg	  if test -n "$export_symbols_regex"; then
4904994689c1Smrg	    $opt_dry_run || {
4905994689c1Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4906994689c1Smrg	      eval '$MV "$nlist"T "$nlist"'
4907994689c1Smrg	    }
4908994689c1Smrg	  fi
4909994689c1Smrg
4910994689c1Smrg	  # Prepare the list of exported symbols
4911994689c1Smrg	  if test -z "$export_symbols"; then
49125ec34c4cSmrg	    export_symbols=$output_objdir/$outputname.exp
4913994689c1Smrg	    $opt_dry_run || {
4914994689c1Smrg	      $RM $export_symbols
49155ec34c4cSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4916994689c1Smrg	      case $host in
4917994689c1Smrg	      *cygwin* | *mingw* | *cegcc* )
4918994689c1Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4919994689c1Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4920994689c1Smrg	        ;;
4921994689c1Smrg	      esac
4922994689c1Smrg	    }
4923e1e1713cSmrg	  else
4924994689c1Smrg	    $opt_dry_run || {
49255ec34c4cSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4926994689c1Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4927994689c1Smrg	      eval '$MV "$nlist"T "$nlist"'
4928994689c1Smrg	      case $host in
4929994689c1Smrg	        *cygwin* | *mingw* | *cegcc* )
4930994689c1Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4931994689c1Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4932994689c1Smrg	          ;;
4933994689c1Smrg	      esac
4934994689c1Smrg	    }
4935e1e1713cSmrg	  fi
4936994689c1Smrg	fi
49377a84e134Smrg
4938994689c1Smrg	for dlprefile in $dlprefiles; do
49395ec34c4cSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4940994689c1Smrg	  func_basename "$dlprefile"
49415ec34c4cSmrg	  name=$func_basename_result
4942f353fbadSmrg          case $host in
4943f353fbadSmrg	    *cygwin* | *mingw* | *cegcc* )
4944f353fbadSmrg	      # if an import library, we need to obtain dlname
4945f353fbadSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4946f353fbadSmrg	        func_tr_sh "$dlprefile"
4947f353fbadSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
49485ec34c4cSmrg	        dlprefile_dlbasename=
4949f353fbadSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4950f353fbadSmrg	          # Use subshell, to avoid clobbering current variable values
4951f353fbadSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
49525ec34c4cSmrg	          if test -n "$dlprefile_dlname"; then
4953f353fbadSmrg	            func_basename "$dlprefile_dlname"
49545ec34c4cSmrg	            dlprefile_dlbasename=$func_basename_result
4955f353fbadSmrg	          else
4956f353fbadSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4957f353fbadSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4958f353fbadSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4959f353fbadSmrg	          fi
4960f353fbadSmrg	        fi
4961f353fbadSmrg	        $opt_dry_run || {
49625ec34c4cSmrg	          if test -n "$dlprefile_dlbasename"; then
4963f353fbadSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4964f353fbadSmrg	          else
4965f353fbadSmrg	            func_warning "Could not compute DLL name from $name"
4966f353fbadSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4967f353fbadSmrg	          fi
4968f353fbadSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4969f353fbadSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4970f353fbadSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4971f353fbadSmrg	        }
4972f353fbadSmrg	      else # not an import lib
4973f353fbadSmrg	        $opt_dry_run || {
4974f353fbadSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4975f353fbadSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4976f353fbadSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4977f353fbadSmrg	        }
4978f353fbadSmrg	      fi
4979f353fbadSmrg	    ;;
4980f353fbadSmrg	    *)
4981f353fbadSmrg	      $opt_dry_run || {
4982f353fbadSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4983f353fbadSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4984f353fbadSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4985f353fbadSmrg	      }
4986f353fbadSmrg	    ;;
4987f353fbadSmrg          esac
4988994689c1Smrg	done
4989994689c1Smrg
4990994689c1Smrg	$opt_dry_run || {
4991994689c1Smrg	  # Make sure we have at least an empty file.
4992994689c1Smrg	  test -f "$nlist" || : > "$nlist"
4993994689c1Smrg
4994994689c1Smrg	  if test -n "$exclude_expsyms"; then
4995994689c1Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4996994689c1Smrg	    $MV "$nlist"T "$nlist"
4997e1e1713cSmrg	  fi
4998994689c1Smrg
4999994689c1Smrg	  # Try sorting and uniquifying the output.
5000994689c1Smrg	  if $GREP -v "^: " < "$nlist" |
5001994689c1Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
5002994689c1Smrg		sort -k 3
5003994689c1Smrg	      else
5004994689c1Smrg		sort +2
5005994689c1Smrg	      fi |
5006994689c1Smrg	      uniq > "$nlist"S; then
5007994689c1Smrg	    :
5008e1e1713cSmrg	  else
5009994689c1Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5010e1e1713cSmrg	  fi
50117a84e134Smrg
5012994689c1Smrg	  if test -f "$nlist"S; then
5013994689c1Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5014e1e1713cSmrg	  else
5015994689c1Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5016e1e1713cSmrg	  fi
50177a84e134Smrg
50185ec34c4cSmrg	  func_show_eval '$RM "${nlist}I"'
50195ec34c4cSmrg	  if test -n "$global_symbol_to_import"; then
50205ec34c4cSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
50215ec34c4cSmrg	  fi
50225ec34c4cSmrg
5023994689c1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50247a84e134Smrg
5025994689c1Smrg/* The mapping between symbol names and symbols.  */
5026994689c1Smrgtypedef struct {
5027994689c1Smrg  const char *name;
5028994689c1Smrg  void *address;
5029994689c1Smrg} lt_dlsymlist;
5030f353fbadSmrgextern LT_DLSYM_CONST lt_dlsymlist
50315ec34c4cSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
50325ec34c4cSmrg"
50335ec34c4cSmrg
50345ec34c4cSmrg	  if test -s "$nlist"I; then
50355ec34c4cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50365ec34c4cSmrgstatic void lt_syminit(void)
50375ec34c4cSmrg{
50385ec34c4cSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
50395ec34c4cSmrg  for (; symbol->name; ++symbol)
50405ec34c4cSmrg    {"
50415ec34c4cSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
50425ec34c4cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50435ec34c4cSmrg    }
50445ec34c4cSmrg}"
50455ec34c4cSmrg	  fi
50465ec34c4cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5047f353fbadSmrgLT_DLSYM_CONST lt_dlsymlist
5048994689c1Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
50495ec34c4cSmrg{ {\"$my_originator\", (void *) 0},"
50505ec34c4cSmrg
50515ec34c4cSmrg	  if test -s "$nlist"I; then
50525ec34c4cSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50535ec34c4cSmrg  {\"@INIT@\", (void *) &lt_syminit},"
50545ec34c4cSmrg	  fi
50557a84e134Smrg
5056994689c1Smrg	  case $need_lib_prefix in
5057994689c1Smrg	  no)
5058994689c1Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5059994689c1Smrg	    ;;
5060994689c1Smrg	  *)
5061994689c1Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5062994689c1Smrg	    ;;
5063994689c1Smrg	  esac
5064994689c1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5065994689c1Smrg  {0, (void *) 0}
5066994689c1Smrg};
50677a84e134Smrg
5068994689c1Smrg/* This works around a problem in FreeBSD linker */
5069994689c1Smrg#ifdef FREEBSD_WORKAROUND
5070994689c1Smrgstatic const void *lt_preloaded_setup() {
5071994689c1Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5072994689c1Smrg}
5073994689c1Smrg#endif
50747a84e134Smrg
5075994689c1Smrg#ifdef __cplusplus
5076994689c1Smrg}
5077994689c1Smrg#endif\
5078994689c1Smrg"
5079994689c1Smrg	} # !$opt_dry_run
5080775e7de9Smrg
5081994689c1Smrg	pic_flag_for_symtable=
5082994689c1Smrg	case "$compile_command " in
5083994689c1Smrg	*" -static "*) ;;
5084994689c1Smrg	*)
5085994689c1Smrg	  case $host in
5086994689c1Smrg	  # compiling the symbol table file with pic_flag works around
5087994689c1Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5088994689c1Smrg	  # linked before any other PIC object.  But we must not use
5089994689c1Smrg	  # pic_flag when linking with -static.  The problem exists in
5090994689c1Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5091421c997bSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5092994689c1Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5093994689c1Smrg	  *-*-hpux*)
5094994689c1Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5095994689c1Smrg	  *)
50965ec34c4cSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5097994689c1Smrg	    ;;
5098994689c1Smrg	  esac
5099994689c1Smrg	  ;;
5100994689c1Smrg	esac
5101994689c1Smrg	symtab_cflags=
5102994689c1Smrg	for arg in $LTCFLAGS; do
5103994689c1Smrg	  case $arg in
5104994689c1Smrg	  -pie | -fpie | -fPIE) ;;
5105f353fbadSmrg	  *) func_append symtab_cflags " $arg" ;;
5106994689c1Smrg	  esac
5107994689c1Smrg	done
51087a84e134Smrg
5109994689c1Smrg	# Now compile the dynamic symbol file.
5110994689c1Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51117a84e134Smrg
5112994689c1Smrg	# Clean up the generated files.
51135ec34c4cSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5114775e7de9Smrg
5115994689c1Smrg	# Transform the symbol file into the correct name.
51165ec34c4cSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5117994689c1Smrg	case $host in
5118994689c1Smrg	*cygwin* | *mingw* | *cegcc* )
5119994689c1Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5120994689c1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5121994689c1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5122994689c1Smrg	  else
5123994689c1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5124994689c1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125994689c1Smrg	  fi
5126994689c1Smrg	  ;;
5127994689c1Smrg	*)
5128994689c1Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5129994689c1Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5130994689c1Smrg	  ;;
5131994689c1Smrg	esac
5132994689c1Smrg	;;
5133994689c1Smrg      *)
51345ec34c4cSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5135994689c1Smrg	;;
5136994689c1Smrg      esac
5137994689c1Smrg    else
5138994689c1Smrg      # We keep going just in case the user didn't refer to
5139994689c1Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5140994689c1Smrg      # really was required.
5141775e7de9Smrg
5142994689c1Smrg      # Nullify the symbol file.
5143994689c1Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5144994689c1Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5145994689c1Smrg    fi
5146994689c1Smrg}
5147775e7de9Smrg
51485ec34c4cSmrg# func_cygming_gnu_implib_p ARG
51495ec34c4cSmrg# This predicate returns with zero status (TRUE) if
51505ec34c4cSmrg# ARG is a GNU/binutils-style import library. Returns
51515ec34c4cSmrg# with nonzero status (FALSE) otherwise.
51525ec34c4cSmrgfunc_cygming_gnu_implib_p ()
51535ec34c4cSmrg{
51545ec34c4cSmrg  $debug_cmd
51555ec34c4cSmrg
51565ec34c4cSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51575ec34c4cSmrg  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)$'`
51585ec34c4cSmrg  test -n "$func_cygming_gnu_implib_tmp"
51595ec34c4cSmrg}
51605ec34c4cSmrg
51615ec34c4cSmrg# func_cygming_ms_implib_p ARG
51625ec34c4cSmrg# This predicate returns with zero status (TRUE) if
51635ec34c4cSmrg# ARG is an MS-style import library. Returns
51645ec34c4cSmrg# with nonzero status (FALSE) otherwise.
51655ec34c4cSmrgfunc_cygming_ms_implib_p ()
51665ec34c4cSmrg{
51675ec34c4cSmrg  $debug_cmd
51685ec34c4cSmrg
51695ec34c4cSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51705ec34c4cSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
51715ec34c4cSmrg  test -n "$func_cygming_ms_implib_tmp"
51725ec34c4cSmrg}
51735ec34c4cSmrg
5174994689c1Smrg# func_win32_libid arg
5175994689c1Smrg# return the library type of file 'arg'
5176994689c1Smrg#
5177994689c1Smrg# Need a lot of goo to handle *both* DLLs and import libs
5178994689c1Smrg# Has to be a shell function in order to 'eat' the argument
5179994689c1Smrg# that is supplied when $file_magic_command is called.
5180994689c1Smrg# Despite the name, also deal with 64 bit binaries.
5181994689c1Smrgfunc_win32_libid ()
5182994689c1Smrg{
51835ec34c4cSmrg  $debug_cmd
51845ec34c4cSmrg
51855ec34c4cSmrg  win32_libid_type=unknown
5186994689c1Smrg  win32_fileres=`file -L $1 2>/dev/null`
5187994689c1Smrg  case $win32_fileres in
5188994689c1Smrg  *ar\ archive\ import\ library*) # definitely import
5189994689c1Smrg    win32_libid_type="x86 archive import"
5190994689c1Smrg    ;;
5191994689c1Smrg  *ar\ archive*) # could be an import, or static
5192994689c1Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5193994689c1Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5194994689c1Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
51955ec34c4cSmrg      case $nm_interface in
51965ec34c4cSmrg      "MS dumpbin")
51975ec34c4cSmrg	if func_cygming_ms_implib_p "$1" ||
51985ec34c4cSmrg	   func_cygming_gnu_implib_p "$1"
51995ec34c4cSmrg	then
52005ec34c4cSmrg	  win32_nmres=import
52015ec34c4cSmrg	else
52025ec34c4cSmrg	  win32_nmres=
52035ec34c4cSmrg	fi
52045ec34c4cSmrg	;;
52055ec34c4cSmrg      *)
52065ec34c4cSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
52075ec34c4cSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
52085ec34c4cSmrg	  $SED -n -e '
5209994689c1Smrg	    1,100{
5210994689c1Smrg		/ I /{
52115ec34c4cSmrg		    s|.*|import|
5212994689c1Smrg		    p
5213994689c1Smrg		    q
5214994689c1Smrg		}
5215994689c1Smrg	    }'`
52165ec34c4cSmrg	;;
52175ec34c4cSmrg      esac
5218994689c1Smrg      case $win32_nmres in
5219994689c1Smrg      import*)  win32_libid_type="x86 archive import";;
5220994689c1Smrg      *)        win32_libid_type="x86 archive static";;
5221994689c1Smrg      esac
5222994689c1Smrg    fi
5223994689c1Smrg    ;;
5224994689c1Smrg  *DLL*)
5225994689c1Smrg    win32_libid_type="x86 DLL"
5226994689c1Smrg    ;;
5227994689c1Smrg  *executable*) # but shell scripts are "executable" too...
5228994689c1Smrg    case $win32_fileres in
5229994689c1Smrg    *MS\ Windows\ PE\ Intel*)
5230994689c1Smrg      win32_libid_type="x86 DLL"
5231994689c1Smrg      ;;
5232994689c1Smrg    esac
5233994689c1Smrg    ;;
5234994689c1Smrg  esac
5235994689c1Smrg  $ECHO "$win32_libid_type"
5236994689c1Smrg}
5237775e7de9Smrg
5238f353fbadSmrg# func_cygming_dll_for_implib ARG
5239f353fbadSmrg#
5240f353fbadSmrg# Platform-specific function to extract the
5241f353fbadSmrg# name of the DLL associated with the specified
5242f353fbadSmrg# import library ARG.
5243f353fbadSmrg# Invoked by eval'ing the libtool variable
5244f353fbadSmrg#    $sharedlib_from_linklib_cmd
5245f353fbadSmrg# Result is available in the variable
5246f353fbadSmrg#    $sharedlib_from_linklib_result
5247f353fbadSmrgfunc_cygming_dll_for_implib ()
5248f353fbadSmrg{
52495ec34c4cSmrg  $debug_cmd
52505ec34c4cSmrg
5251f353fbadSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5252f353fbadSmrg}
5253f353fbadSmrg
5254f353fbadSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5255f353fbadSmrg#
5256f353fbadSmrg# The is the core of a fallback implementation of a
5257f353fbadSmrg# platform-specific function to extract the name of the
5258f353fbadSmrg# DLL associated with the specified import library LIBNAME.
5259f353fbadSmrg#
5260f353fbadSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5261f353fbadSmrg# on the platform and compiler that created the implib.
5262f353fbadSmrg#
5263f353fbadSmrg# Echos the name of the DLL associated with the
5264f353fbadSmrg# specified import library.
5265f353fbadSmrgfunc_cygming_dll_for_implib_fallback_core ()
5266f353fbadSmrg{
52675ec34c4cSmrg  $debug_cmd
52685ec34c4cSmrg
5269f353fbadSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5270f353fbadSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5271f353fbadSmrg    $SED '/^Contents of section '"$match_literal"':/{
5272f353fbadSmrg      # Place marker at beginning of archive member dllname section
5273f353fbadSmrg      s/.*/====MARK====/
5274f353fbadSmrg      p
5275f353fbadSmrg      d
5276f353fbadSmrg    }
5277f353fbadSmrg    # These lines can sometimes be longer than 43 characters, but
5278f353fbadSmrg    # are always uninteresting
5279f353fbadSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5280f353fbadSmrg    /^In archive [^:]*:/d
5281f353fbadSmrg    # Ensure marker is printed
5282f353fbadSmrg    /^====MARK====/p
5283f353fbadSmrg    # Remove all lines with less than 43 characters
5284f353fbadSmrg    /^.\{43\}/!d
5285f353fbadSmrg    # From remaining lines, remove first 43 characters
5286f353fbadSmrg    s/^.\{43\}//' |
5287f353fbadSmrg    $SED -n '
5288f353fbadSmrg      # Join marker and all lines until next marker into a single line
5289f353fbadSmrg      /^====MARK====/ b para
5290f353fbadSmrg      H
5291f353fbadSmrg      $ b para
5292f353fbadSmrg      b
5293f353fbadSmrg      :para
5294f353fbadSmrg      x
5295f353fbadSmrg      s/\n//g
5296f353fbadSmrg      # Remove the marker
5297f353fbadSmrg      s/^====MARK====//
5298f353fbadSmrg      # Remove trailing dots and whitespace
5299f353fbadSmrg      s/[\. \t]*$//
5300f353fbadSmrg      # Print
5301f353fbadSmrg      /./p' |
5302f353fbadSmrg    # we now have a list, one entry per line, of the stringified
5303f353fbadSmrg    # contents of the appropriate section of all members of the
53045ec34c4cSmrg    # archive that possess that section. Heuristic: eliminate
53055ec34c4cSmrg    # all those that have a first or second character that is
5306f353fbadSmrg    # a '.' (that is, objdump's representation of an unprintable
5307f353fbadSmrg    # character.) This should work for all archives with less than
5308f353fbadSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5309f353fbadSmrg    # begins with a literal '.' or a single character followed by
5310f353fbadSmrg    # a '.'.
5311f353fbadSmrg    #
5312f353fbadSmrg    # Of those that remain, print the first one.
5313f353fbadSmrg    $SED -e '/^\./d;/^.\./d;q'
5314f353fbadSmrg}
5315f353fbadSmrg
5316f353fbadSmrg# func_cygming_dll_for_implib_fallback ARG
5317f353fbadSmrg# Platform-specific function to extract the
5318f353fbadSmrg# name of the DLL associated with the specified
5319f353fbadSmrg# import library ARG.
5320f353fbadSmrg#
5321f353fbadSmrg# This fallback implementation is for use when $DLLTOOL
5322f353fbadSmrg# does not support the --identify-strict option.
5323f353fbadSmrg# Invoked by eval'ing the libtool variable
5324f353fbadSmrg#    $sharedlib_from_linklib_cmd
5325f353fbadSmrg# Result is available in the variable
5326f353fbadSmrg#    $sharedlib_from_linklib_result
5327f353fbadSmrgfunc_cygming_dll_for_implib_fallback ()
5328f353fbadSmrg{
53295ec34c4cSmrg  $debug_cmd
53305ec34c4cSmrg
53315ec34c4cSmrg  if func_cygming_gnu_implib_p "$1"; then
5332f353fbadSmrg    # binutils import library
5333f353fbadSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
53345ec34c4cSmrg  elif func_cygming_ms_implib_p "$1"; then
5335f353fbadSmrg    # ms-generated import library
5336f353fbadSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5337f353fbadSmrg  else
5338f353fbadSmrg    # unknown
53395ec34c4cSmrg    sharedlib_from_linklib_result=
5340f353fbadSmrg  fi
5341f353fbadSmrg}
53427a84e134Smrg
53437a84e134Smrg
5344994689c1Smrg# func_extract_an_archive dir oldlib
5345994689c1Smrgfunc_extract_an_archive ()
5346994689c1Smrg{
53475ec34c4cSmrg    $debug_cmd
53485ec34c4cSmrg
53495ec34c4cSmrg    f_ex_an_ar_dir=$1; shift
53505ec34c4cSmrg    f_ex_an_ar_oldlib=$1
53515ec34c4cSmrg    if test yes = "$lock_old_archive_extraction"; then
5352994689c1Smrg      lockfile=$f_ex_an_ar_oldlib.lock
5353994689c1Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5354994689c1Smrg	func_echo "Waiting for $lockfile to be removed"
5355994689c1Smrg	sleep 2
5356994689c1Smrg      done
5357994689c1Smrg    fi
5358994689c1Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5359994689c1Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
53605ec34c4cSmrg    if test yes = "$lock_old_archive_extraction"; then
5361994689c1Smrg      $opt_dry_run || rm -f "$lockfile"
5362994689c1Smrg    fi
5363994689c1Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5364994689c1Smrg     :
5365994689c1Smrg    else
5366994689c1Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5367994689c1Smrg    fi
5368994689c1Smrg}
53697a84e134Smrg
53707a84e134Smrg
5371994689c1Smrg# func_extract_archives gentop oldlib ...
5372994689c1Smrgfunc_extract_archives ()
5373994689c1Smrg{
53745ec34c4cSmrg    $debug_cmd
53755ec34c4cSmrg
53765ec34c4cSmrg    my_gentop=$1; shift
5377994689c1Smrg    my_oldlibs=${1+"$@"}
53785ec34c4cSmrg    my_oldobjs=
53795ec34c4cSmrg    my_xlib=
53805ec34c4cSmrg    my_xabs=
53815ec34c4cSmrg    my_xdir=
53827a84e134Smrg
5383994689c1Smrg    for my_xlib in $my_oldlibs; do
5384994689c1Smrg      # Extract the objects.
5385994689c1Smrg      case $my_xlib in
53865ec34c4cSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5387994689c1Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5388994689c1Smrg      esac
5389994689c1Smrg      func_basename "$my_xlib"
53905ec34c4cSmrg      my_xlib=$func_basename_result
5391994689c1Smrg      my_xlib_u=$my_xlib
5392994689c1Smrg      while :; do
5393994689c1Smrg        case " $extracted_archives " in
5394994689c1Smrg	*" $my_xlib_u "*)
5395994689c1Smrg	  func_arith $extracted_serial + 1
5396994689c1Smrg	  extracted_serial=$func_arith_result
5397994689c1Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5398994689c1Smrg	*) break ;;
5399994689c1Smrg	esac
5400994689c1Smrg      done
5401994689c1Smrg      extracted_archives="$extracted_archives $my_xlib_u"
54025ec34c4cSmrg      my_xdir=$my_gentop/$my_xlib_u
5403775e7de9Smrg
5404994689c1Smrg      func_mkdir_p "$my_xdir"
5405994689c1Smrg
5406994689c1Smrg      case $host in
5407994689c1Smrg      *-darwin*)
5408994689c1Smrg	func_verbose "Extracting $my_xabs"
5409994689c1Smrg	# Do not bother doing anything if just a dry run
5410994689c1Smrg	$opt_dry_run || {
5411994689c1Smrg	  darwin_orig_dir=`pwd`
5412994689c1Smrg	  cd $my_xdir || exit $?
5413994689c1Smrg	  darwin_archive=$my_xabs
5414994689c1Smrg	  darwin_curdir=`pwd`
54155ec34c4cSmrg	  func_basename "$darwin_archive"
54165ec34c4cSmrg	  darwin_base_archive=$func_basename_result
5417994689c1Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5418994689c1Smrg	  if test -n "$darwin_arches"; then
5419994689c1Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5420994689c1Smrg	    darwin_arch=
5421994689c1Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
54225ec34c4cSmrg	    for darwin_arch in  $darwin_arches; do
54235ec34c4cSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
54245ec34c4cSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
54255ec34c4cSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
54265ec34c4cSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5427994689c1Smrg	      cd "$darwin_curdir"
54285ec34c4cSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5429994689c1Smrg	    done # $darwin_arches
5430994689c1Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
54315ec34c4cSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5432994689c1Smrg	    darwin_file=
5433994689c1Smrg	    darwin_files=
5434994689c1Smrg	    for darwin_file in $darwin_filelist; do
5435994689c1Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5436994689c1Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5437994689c1Smrg	    done # $darwin_filelist
5438994689c1Smrg	    $RM -rf unfat-$$
5439994689c1Smrg	    cd "$darwin_orig_dir"
5440e1e1713cSmrg	  else
5441994689c1Smrg	    cd $darwin_orig_dir
5442994689c1Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5443994689c1Smrg	  fi # $darwin_arches
5444994689c1Smrg	} # !$opt_dry_run
5445994689c1Smrg	;;
5446994689c1Smrg      *)
5447994689c1Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5448994689c1Smrg	;;
5449994689c1Smrg      esac
5450994689c1Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5451994689c1Smrg    done
54527a84e134Smrg
54535ec34c4cSmrg    func_extract_archives_result=$my_oldobjs
5454994689c1Smrg}
54557a84e134Smrg
54567a84e134Smrg
5457994689c1Smrg# func_emit_wrapper [arg=no]
5458994689c1Smrg#
5459994689c1Smrg# Emit a libtool wrapper script on stdout.
5460994689c1Smrg# Don't directly open a file because we may want to
5461994689c1Smrg# incorporate the script contents within a cygwin/mingw
5462994689c1Smrg# wrapper executable.  Must ONLY be called from within
5463994689c1Smrg# func_mode_link because it depends on a number of variables
5464994689c1Smrg# set therein.
5465994689c1Smrg#
5466994689c1Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5467994689c1Smrg# variable will take.  If 'yes', then the emitted script
54685ec34c4cSmrg# will assume that the directory where it is stored is
5469994689c1Smrg# the $objdir directory.  This is a cygwin/mingw-specific
5470994689c1Smrg# behavior.
5471994689c1Smrgfunc_emit_wrapper ()
5472994689c1Smrg{
5473994689c1Smrg	func_emit_wrapper_arg1=${1-no}
5474e1e1713cSmrg
5475994689c1Smrg	$ECHO "\
5476994689c1Smrg#! $SHELL
54777a84e134Smrg
5478994689c1Smrg# $output - temporary wrapper script for $objdir/$outputname
54795ec34c4cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5480994689c1Smrg#
5481994689c1Smrg# The $output program cannot be directly executed until all the libtool
5482994689c1Smrg# libraries that it depends on are installed.
5483994689c1Smrg#
5484994689c1Smrg# This wrapper script should never be moved out of the build directory.
5485994689c1Smrg# If it is, it will not operate correctly.
54867a84e134Smrg
5487994689c1Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5488994689c1Smrg# metacharacters that are still active within double-quoted strings.
5489994689c1Smrgsed_quote_subst='$sed_quote_subst'
54907a84e134Smrg
5491994689c1Smrg# Be Bourne compatible
5492994689c1Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5493994689c1Smrg  emulate sh
5494994689c1Smrg  NULLCMD=:
5495994689c1Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5496994689c1Smrg  # is contrary to our usage.  Disable this feature.
5497994689c1Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5498994689c1Smrg  setopt NO_GLOB_SUBST
5499994689c1Smrgelse
5500994689c1Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5501994689c1Smrgfi
5502994689c1SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5503994689c1SmrgDUALCASE=1; export DUALCASE # for MKS sh
55047a84e134Smrg
5505994689c1Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5506994689c1Smrg# if CDPATH is set.
5507994689c1Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
55087a84e134Smrg
5509994689c1Smrgrelink_command=\"$relink_command\"
55107a84e134Smrg
5511994689c1Smrg# This environment variable determines our operation mode.
5512994689c1Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5513994689c1Smrg  # install mode needs the following variables:
5514994689c1Smrg  generated_by_libtool_version='$macro_version'
5515994689c1Smrg  notinst_deplibs='$notinst_deplibs'
5516994689c1Smrgelse
5517994689c1Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5518994689c1Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5519994689c1Smrg    file=\"\$0\""
55207a84e134Smrg
55215b16253fSmrg    func_quote_arg pretty "$ECHO"
55225b16253fSmrg    qECHO=$func_quote_arg_result
5523994689c1Smrg    $ECHO "\
55247a84e134Smrg
5525994689c1Smrg# A function that is used when there is no print builtin or printf.
5526994689c1Smrgfunc_fallback_echo ()
5527994689c1Smrg{
5528994689c1Smrg  eval 'cat <<_LTECHO_EOF
5529994689c1Smrg\$1
5530994689c1Smrg_LTECHO_EOF'
5531994689c1Smrg}
55325b16253fSmrg    ECHO=$qECHO
5533994689c1Smrg  fi
5534994689c1Smrg
5535994689c1Smrg# Very basic option parsing. These options are (a) specific to
5536994689c1Smrg# the libtool wrapper, (b) are identical between the wrapper
55375ec34c4cSmrg# /script/ and the wrapper /executable/ that is used only on
5538994689c1Smrg# windows platforms, and (c) all begin with the string "--lt-"
55395ec34c4cSmrg# (application programs are unlikely to have options that match
5540994689c1Smrg# this pattern).
5541994689c1Smrg#
5542994689c1Smrg# There are only two supported options: --lt-debug and
5543994689c1Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
5544994689c1Smrg#
5545994689c1Smrg# The first argument to this parsing function should be the
5546994689c1Smrg# script's $0 value, followed by "$@".
5547994689c1Smrglt_option_debug=
5548994689c1Smrgfunc_parse_lt_options ()
5549994689c1Smrg{
5550994689c1Smrg  lt_script_arg0=\$0
5551994689c1Smrg  shift
5552994689c1Smrg  for lt_opt
5553994689c1Smrg  do
5554994689c1Smrg    case \"\$lt_opt\" in
5555994689c1Smrg    --lt-debug) lt_option_debug=1 ;;
5556994689c1Smrg    --lt-dump-script)
5557994689c1Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5558994689c1Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5559994689c1Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5560994689c1Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5561994689c1Smrg        exit 0
5562994689c1Smrg      ;;
5563994689c1Smrg    --lt-*)
5564994689c1Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5565994689c1Smrg        exit 1
5566e1e1713cSmrg      ;;
5567994689c1Smrg    esac
5568994689c1Smrg  done
55697a84e134Smrg
5570994689c1Smrg  # Print the debug banner immediately:
5571994689c1Smrg  if test -n \"\$lt_option_debug\"; then
55725ec34c4cSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5573994689c1Smrg  fi
5574994689c1Smrg}
55757a84e134Smrg
5576994689c1Smrg# Used when --lt-debug. Prints its arguments to stdout
5577994689c1Smrg# (redirection is the responsibility of the caller)
5578994689c1Smrgfunc_lt_dump_args ()
5579994689c1Smrg{
5580994689c1Smrg  lt_dump_args_N=1;
5581994689c1Smrg  for lt_arg
5582994689c1Smrg  do
55835ec34c4cSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5584994689c1Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5585994689c1Smrg  done
5586994689c1Smrg}
55877a84e134Smrg
5588994689c1Smrg# Core function for launching the target application
5589994689c1Smrgfunc_exec_program_core ()
5590994689c1Smrg{
5591994689c1Smrg"
5592994689c1Smrg  case $host in
5593994689c1Smrg  # Backslashes separate directories on plain windows
5594994689c1Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
5595994689c1Smrg    $ECHO "\
5596994689c1Smrg      if test -n \"\$lt_option_debug\"; then
55975ec34c4cSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5598994689c1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5599e1e1713cSmrg      fi
5600994689c1Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5601994689c1Smrg"
5602994689c1Smrg    ;;
56037a84e134Smrg
5604994689c1Smrg  *)
5605994689c1Smrg    $ECHO "\
5606994689c1Smrg      if test -n \"\$lt_option_debug\"; then
56075ec34c4cSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5608994689c1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5609e1e1713cSmrg      fi
5610994689c1Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5611994689c1Smrg"
5612994689c1Smrg    ;;
5613994689c1Smrg  esac
5614994689c1Smrg  $ECHO "\
5615994689c1Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5616994689c1Smrg      exit 1
5617994689c1Smrg}
56187a84e134Smrg
5619994689c1Smrg# A function to encapsulate launching the target application
5620994689c1Smrg# Strips options in the --lt-* namespace from \$@ and
5621994689c1Smrg# launches target application with the remaining arguments.
5622994689c1Smrgfunc_exec_program ()
5623994689c1Smrg{
5624421c997bSmrg  case \" \$* \" in
5625421c997bSmrg  *\\ --lt-*)
5626421c997bSmrg    for lt_wr_arg
5627421c997bSmrg    do
5628421c997bSmrg      case \$lt_wr_arg in
5629421c997bSmrg      --lt-*) ;;
5630421c997bSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5631421c997bSmrg      esac
5632421c997bSmrg      shift
5633421c997bSmrg    done ;;
5634421c997bSmrg  esac
5635994689c1Smrg  func_exec_program_core \${1+\"\$@\"}
5636994689c1Smrg}
56377a84e134Smrg
5638994689c1Smrg  # Parse options
5639994689c1Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
56407a84e134Smrg
5641994689c1Smrg  # Find the directory that this script lives in.
5642994689c1Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5643994689c1Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
56447a84e134Smrg
5645994689c1Smrg  # Follow symbolic links until we get to the real thisdir.
5646994689c1Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5647994689c1Smrg  while test -n \"\$file\"; do
5648994689c1Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
56497a84e134Smrg
5650994689c1Smrg    # If there was a directory component, then change thisdir.
5651994689c1Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5652994689c1Smrg      case \"\$destdir\" in
5653994689c1Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5654994689c1Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5655994689c1Smrg      esac
5656994689c1Smrg    fi
56577a84e134Smrg
5658994689c1Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5659994689c1Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5660994689c1Smrg  done
56617a84e134Smrg
5662994689c1Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5663994689c1Smrg  # the cwrapper.
5664994689c1Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5665994689c1Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5666994689c1Smrg    # special case for '.'
5667994689c1Smrg    if test \"\$thisdir\" = \".\"; then
5668994689c1Smrg      thisdir=\`pwd\`
5669994689c1Smrg    fi
5670994689c1Smrg    # remove .libs from thisdir
5671994689c1Smrg    case \"\$thisdir\" in
5672994689c1Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5673994689c1Smrg    $objdir )   thisdir=. ;;
5674994689c1Smrg    esac
5675994689c1Smrg  fi
56767a84e134Smrg
5677994689c1Smrg  # Try to get the absolute directory name.
5678994689c1Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5679994689c1Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5680994689c1Smrg"
56817a84e134Smrg
56825ec34c4cSmrg	if test yes = "$fast_install"; then
5683994689c1Smrg	  $ECHO "\
5684994689c1Smrg  program=lt-'$outputname'$exeext
5685994689c1Smrg  progdir=\"\$thisdir/$objdir\"
56867a84e134Smrg
5687994689c1Smrg  if test ! -f \"\$progdir/\$program\" ||
56885ec34c4cSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5689994689c1Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
56907a84e134Smrg
5691994689c1Smrg    file=\"\$\$-\$program\"
56927a84e134Smrg
5693994689c1Smrg    if test ! -d \"\$progdir\"; then
5694994689c1Smrg      $MKDIR \"\$progdir\"
5695994689c1Smrg    else
5696994689c1Smrg      $RM \"\$progdir/\$file\"
5697994689c1Smrg    fi"
56987a84e134Smrg
5699994689c1Smrg	  $ECHO "\
57007a84e134Smrg
5701994689c1Smrg    # relink executable if necessary
5702994689c1Smrg    if test -n \"\$relink_command\"; then
5703994689c1Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5704994689c1Smrg      else
57055ec34c4cSmrg	\$ECHO \"\$relink_command_output\" >&2
5706994689c1Smrg	$RM \"\$progdir/\$file\"
5707994689c1Smrg	exit 1
5708994689c1Smrg      fi
5709994689c1Smrg    fi
57107a84e134Smrg
5711994689c1Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5712994689c1Smrg    { $RM \"\$progdir/\$program\";
5713994689c1Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5714994689c1Smrg    $RM \"\$progdir/\$file\"
5715994689c1Smrg  fi"
5716994689c1Smrg	else
5717994689c1Smrg	  $ECHO "\
5718994689c1Smrg  program='$outputname'
5719994689c1Smrg  progdir=\"\$thisdir/$objdir\"
5720994689c1Smrg"
5721994689c1Smrg	fi
5722775e7de9Smrg
5723994689c1Smrg	$ECHO "\
57247a84e134Smrg
5725994689c1Smrg  if test -f \"\$progdir/\$program\"; then"
57267a84e134Smrg
5727f353fbadSmrg	# fixup the dll searchpath if we need to.
5728f353fbadSmrg	#
5729f353fbadSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5730f353fbadSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5731f353fbadSmrg	# libraries must come first.
5732f353fbadSmrg	if test -n "$dllsearchpath"; then
5733f353fbadSmrg	  $ECHO "\
5734f353fbadSmrg    # Add the dll search path components to the executable PATH
5735f353fbadSmrg    PATH=$dllsearchpath:\$PATH
5736f353fbadSmrg"
5737f353fbadSmrg	fi
5738f353fbadSmrg
5739994689c1Smrg	# Export our shlibpath_var if we have one.
57405ec34c4cSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5741994689c1Smrg	  $ECHO "\
5742994689c1Smrg    # Add our own library path to $shlibpath_var
5743994689c1Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
57447a84e134Smrg
5745994689c1Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5746994689c1Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5747994689c1Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
57487a84e134Smrg
5749994689c1Smrg    export $shlibpath_var
5750994689c1Smrg"
5751994689c1Smrg	fi
57527a84e134Smrg
5753994689c1Smrg	$ECHO "\
5754994689c1Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5755994689c1Smrg      # Run the actual program with our arguments.
5756994689c1Smrg      func_exec_program \${1+\"\$@\"}
5757994689c1Smrg    fi
5758994689c1Smrg  else
5759994689c1Smrg    # The program doesn't exist.
57605ec34c4cSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5761994689c1Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5762994689c1Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5763994689c1Smrg    exit 1
5764994689c1Smrg  fi
5765994689c1Smrgfi\
5766994689c1Smrg"
5767994689c1Smrg}
57687a84e134Smrg
57697a84e134Smrg
5770994689c1Smrg# func_emit_cwrapperexe_src
5771994689c1Smrg# emit the source code for a wrapper executable on stdout
5772994689c1Smrg# Must ONLY be called from within func_mode_link because
5773994689c1Smrg# it depends on a number of variable set therein.
5774994689c1Smrgfunc_emit_cwrapperexe_src ()
5775994689c1Smrg{
5776994689c1Smrg	cat <<EOF
57777a84e134Smrg
5778994689c1Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
57795ec34c4cSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
57807a84e134Smrg
5781994689c1Smrg   The $output program cannot be directly executed until all the libtool
5782994689c1Smrg   libraries that it depends on are installed.
57837a84e134Smrg
5784994689c1Smrg   This wrapper executable should never be moved out of the build directory.
5785994689c1Smrg   If it is, it will not operate correctly.
5786994689c1Smrg*/
5787994689c1SmrgEOF
5788994689c1Smrg	    cat <<"EOF"
5789994689c1Smrg#ifdef _MSC_VER
5790994689c1Smrg# define _CRT_SECURE_NO_DEPRECATE 1
5791994689c1Smrg#endif
5792994689c1Smrg#include <stdio.h>
5793994689c1Smrg#include <stdlib.h>
5794994689c1Smrg#ifdef _MSC_VER
5795994689c1Smrg# include <direct.h>
5796994689c1Smrg# include <process.h>
5797994689c1Smrg# include <io.h>
5798994689c1Smrg#else
5799994689c1Smrg# include <unistd.h>
5800994689c1Smrg# include <stdint.h>
5801994689c1Smrg# ifdef __CYGWIN__
5802994689c1Smrg#  include <io.h>
5803994689c1Smrg# endif
5804994689c1Smrg#endif
5805994689c1Smrg#include <malloc.h>
5806994689c1Smrg#include <stdarg.h>
5807994689c1Smrg#include <assert.h>
5808994689c1Smrg#include <string.h>
5809994689c1Smrg#include <ctype.h>
5810994689c1Smrg#include <errno.h>
5811994689c1Smrg#include <fcntl.h>
5812994689c1Smrg#include <sys/stat.h>
58137a84e134Smrg
58145ec34c4cSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
58155ec34c4cSmrg
5816994689c1Smrg/* declarations of non-ANSI functions */
58175ec34c4cSmrg#if defined __MINGW32__
5818994689c1Smrg# ifdef __STRICT_ANSI__
5819994689c1Smrgint _putenv (const char *);
5820994689c1Smrg# endif
58215ec34c4cSmrg#elif defined __CYGWIN__
5822994689c1Smrg# ifdef __STRICT_ANSI__
5823994689c1Smrgchar *realpath (const char *, char *);
5824994689c1Smrgint putenv (char *);
5825994689c1Smrgint setenv (const char *, const char *, int);
5826994689c1Smrg# endif
58275ec34c4cSmrg/* #elif defined other_platform || defined ... */
5828994689c1Smrg#endif
58297a84e134Smrg
5830994689c1Smrg/* portability defines, excluding path handling macros */
58315ec34c4cSmrg#if defined _MSC_VER
5832994689c1Smrg# define setmode _setmode
5833994689c1Smrg# define stat    _stat
5834994689c1Smrg# define chmod   _chmod
5835994689c1Smrg# define getcwd  _getcwd
5836994689c1Smrg# define putenv  _putenv
5837994689c1Smrg# define S_IXUSR _S_IEXEC
58385ec34c4cSmrg#elif defined __MINGW32__
5839994689c1Smrg# define setmode _setmode
5840994689c1Smrg# define stat    _stat
5841994689c1Smrg# define chmod   _chmod
5842994689c1Smrg# define getcwd  _getcwd
5843994689c1Smrg# define putenv  _putenv
58445ec34c4cSmrg#elif defined __CYGWIN__
5845994689c1Smrg# define HAVE_SETENV
5846994689c1Smrg# define FOPEN_WB "wb"
58475ec34c4cSmrg/* #elif defined other platforms ... */
5848994689c1Smrg#endif
58497a84e134Smrg
58505ec34c4cSmrg#if defined PATH_MAX
5851994689c1Smrg# define LT_PATHMAX PATH_MAX
58525ec34c4cSmrg#elif defined MAXPATHLEN
5853994689c1Smrg# define LT_PATHMAX MAXPATHLEN
5854994689c1Smrg#else
5855994689c1Smrg# define LT_PATHMAX 1024
5856994689c1Smrg#endif
58577a84e134Smrg
5858994689c1Smrg#ifndef S_IXOTH
5859994689c1Smrg# define S_IXOTH 0
5860994689c1Smrg#endif
5861994689c1Smrg#ifndef S_IXGRP
5862994689c1Smrg# define S_IXGRP 0
5863994689c1Smrg#endif
58647a84e134Smrg
5865994689c1Smrg/* path handling portability macros */
5866994689c1Smrg#ifndef DIR_SEPARATOR
5867994689c1Smrg# define DIR_SEPARATOR '/'
5868994689c1Smrg# define PATH_SEPARATOR ':'
5869994689c1Smrg#endif
58707a84e134Smrg
58715ec34c4cSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
58725ec34c4cSmrg  defined __OS2__
5873994689c1Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5874994689c1Smrg# define FOPEN_WB "wb"
5875994689c1Smrg# ifndef DIR_SEPARATOR_2
5876994689c1Smrg#  define DIR_SEPARATOR_2 '\\'
5877994689c1Smrg# endif
5878994689c1Smrg# ifndef PATH_SEPARATOR_2
5879994689c1Smrg#  define PATH_SEPARATOR_2 ';'
5880994689c1Smrg# endif
5881994689c1Smrg#endif
58827a84e134Smrg
5883994689c1Smrg#ifndef DIR_SEPARATOR_2
5884994689c1Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5885994689c1Smrg#else /* DIR_SEPARATOR_2 */
5886994689c1Smrg# define IS_DIR_SEPARATOR(ch) \
5887994689c1Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5888994689c1Smrg#endif /* DIR_SEPARATOR_2 */
58897a84e134Smrg
5890994689c1Smrg#ifndef PATH_SEPARATOR_2
5891994689c1Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5892994689c1Smrg#else /* PATH_SEPARATOR_2 */
5893994689c1Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5894994689c1Smrg#endif /* PATH_SEPARATOR_2 */
5895994689c1Smrg
5896994689c1Smrg#ifndef FOPEN_WB
5897994689c1Smrg# define FOPEN_WB "w"
5898994689c1Smrg#endif
5899994689c1Smrg#ifndef _O_BINARY
5900994689c1Smrg# define _O_BINARY 0
5901994689c1Smrg#endif
5902994689c1Smrg
5903994689c1Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5904994689c1Smrg#define XFREE(stale) do { \
59055ec34c4cSmrg  if (stale) { free (stale); stale = 0; } \
5906994689c1Smrg} while (0)
5907994689c1Smrg
59085ec34c4cSmrg#if defined LT_DEBUGWRAPPER
5909994689c1Smrgstatic int lt_debug = 1;
5910994689c1Smrg#else
5911994689c1Smrgstatic int lt_debug = 0;
5912994689c1Smrg#endif
5913994689c1Smrg
5914994689c1Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5915994689c1Smrg
5916994689c1Smrgvoid *xmalloc (size_t num);
5917994689c1Smrgchar *xstrdup (const char *string);
5918994689c1Smrgconst char *base_name (const char *name);
5919994689c1Smrgchar *find_executable (const char *wrapper);
5920994689c1Smrgchar *chase_symlinks (const char *pathspec);
5921994689c1Smrgint make_executable (const char *path);
5922994689c1Smrgint check_executable (const char *path);
5923994689c1Smrgchar *strendzap (char *str, const char *pat);
5924994689c1Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5925994689c1Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5926994689c1Smrgstatic const char *nonnull (const char *s);
5927994689c1Smrgstatic const char *nonempty (const char *s);
5928994689c1Smrgvoid lt_setenv (const char *name, const char *value);
5929994689c1Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5930994689c1Smrgvoid lt_update_exe_path (const char *name, const char *value);
5931994689c1Smrgvoid lt_update_lib_path (const char *name, const char *value);
5932994689c1Smrgchar **prepare_spawn (char **argv);
5933994689c1Smrgvoid lt_dump_script (FILE *f);
5934994689c1SmrgEOF
5935994689c1Smrg
5936994689c1Smrg	    cat <<EOF
59375ec34c4cSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
59385ec34c4cSmrg# define externally_visible volatile
59395ec34c4cSmrg#else
59405ec34c4cSmrg# define externally_visible __attribute__((externally_visible)) volatile
59415ec34c4cSmrg#endif
59425ec34c4cSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5943994689c1Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5944994689c1SmrgEOF
5945994689c1Smrg
59465ec34c4cSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5947f353fbadSmrg              func_to_host_path "$temp_rpath"
5948994689c1Smrg	      cat <<EOF
5949f353fbadSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5950e1e1713cSmrgEOF
5951e1e1713cSmrg	    else
5952994689c1Smrg	      cat <<"EOF"
5953994689c1Smrgconst char * LIB_PATH_VALUE   = "";
5954994689c1SmrgEOF
5955e1e1713cSmrg	    fi
5956994689c1Smrg
5957994689c1Smrg	    if test -n "$dllsearchpath"; then
5958f353fbadSmrg              func_to_host_path "$dllsearchpath:"
5959994689c1Smrg	      cat <<EOF
5960994689c1Smrgconst char * EXE_PATH_VARNAME = "PATH";
5961f353fbadSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5962994689c1SmrgEOF
5963e1e1713cSmrg	    else
5964994689c1Smrg	      cat <<"EOF"
5965994689c1Smrgconst char * EXE_PATH_VARNAME = "";
5966994689c1Smrgconst char * EXE_PATH_VALUE   = "";
5967994689c1SmrgEOF
5968e1e1713cSmrg	    fi
5969994689c1Smrg
59705ec34c4cSmrg	    if test yes = "$fast_install"; then
5971994689c1Smrg	      cat <<EOF
5972994689c1Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5973994689c1SmrgEOF
5974e1e1713cSmrg	    else
5975994689c1Smrg	      cat <<EOF
5976994689c1Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5977994689c1SmrgEOF
5978e1e1713cSmrg	    fi
59797a84e134Smrg
59807a84e134Smrg
5981994689c1Smrg	    cat <<"EOF"
59827a84e134Smrg
5983994689c1Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
59847a84e134Smrg
5985994689c1Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5986994689c1Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5987994689c1Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
59887a84e134Smrg
5989994689c1Smrgint
5990994689c1Smrgmain (int argc, char *argv[])
5991994689c1Smrg{
5992994689c1Smrg  char **newargz;
5993994689c1Smrg  int  newargc;
5994994689c1Smrg  char *tmp_pathspec;
5995994689c1Smrg  char *actual_cwrapper_path;
5996994689c1Smrg  char *actual_cwrapper_name;
5997994689c1Smrg  char *target_name;
5998994689c1Smrg  char *lt_argv_zero;
59995ec34c4cSmrg  int rval = 127;
60007a84e134Smrg
6001994689c1Smrg  int i;
60027a84e134Smrg
6003994689c1Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
60045ec34c4cSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
60057a84e134Smrg
6006994689c1Smrg  /* very simple arg parsing; don't want to rely on getopt
6007994689c1Smrg   * also, copy all non cwrapper options to newargz, except
6008994689c1Smrg   * argz[0], which is handled differently
6009994689c1Smrg   */
6010994689c1Smrg  newargc=0;
6011994689c1Smrg  for (i = 1; i < argc; i++)
6012994689c1Smrg    {
60135ec34c4cSmrg      if (STREQ (argv[i], dumpscript_opt))
6014994689c1Smrg	{
6015994689c1SmrgEOF
60165ec34c4cSmrg	    case $host in
6017994689c1Smrg	      *mingw* | *cygwin* )
6018994689c1Smrg		# make stdout use "unix" line endings
6019994689c1Smrg		echo "          setmode(1,_O_BINARY);"
6020994689c1Smrg		;;
6021e1e1713cSmrg	      esac
60227a84e134Smrg
6023994689c1Smrg	    cat <<"EOF"
6024994689c1Smrg	  lt_dump_script (stdout);
6025994689c1Smrg	  return 0;
6026994689c1Smrg	}
60275ec34c4cSmrg      if (STREQ (argv[i], debug_opt))
6028994689c1Smrg	{
6029994689c1Smrg          lt_debug = 1;
6030994689c1Smrg          continue;
6031994689c1Smrg	}
60325ec34c4cSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6033994689c1Smrg        {
6034994689c1Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6035994689c1Smrg             namespace, but it is not one of the ones we know about and
6036994689c1Smrg             have already dealt with, above (inluding dump-script), then
6037994689c1Smrg             report an error. Otherwise, targets might begin to believe
6038994689c1Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6039994689c1Smrg             namespace. The first time any user complains about this, we'll
6040994689c1Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6041994689c1Smrg             or a configure.ac-settable value.
6042994689c1Smrg           */
6043994689c1Smrg          lt_fatal (__FILE__, __LINE__,
6044994689c1Smrg		    "unrecognized %s option: '%s'",
6045994689c1Smrg                    ltwrapper_option_prefix, argv[i]);
6046994689c1Smrg        }
6047994689c1Smrg      /* otherwise ... */
6048994689c1Smrg      newargz[++newargc] = xstrdup (argv[i]);
6049994689c1Smrg    }
6050994689c1Smrg  newargz[++newargc] = NULL;
60517a84e134Smrg
6052994689c1SmrgEOF
6053994689c1Smrg	    cat <<EOF
6054994689c1Smrg  /* The GNU banner must be the first non-error debug message */
60555ec34c4cSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6056994689c1SmrgEOF
6057994689c1Smrg	    cat <<"EOF"
6058994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6059994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6060994689c1Smrg
6061994689c1Smrg  tmp_pathspec = find_executable (argv[0]);
6062994689c1Smrg  if (tmp_pathspec == NULL)
6063994689c1Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6064994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6065994689c1Smrg                  "(main) found exe (before symlink chase) at: %s\n",
6066994689c1Smrg		  tmp_pathspec);
6067994689c1Smrg
6068994689c1Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6069994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6070994689c1Smrg                  "(main) found exe (after symlink chase) at: %s\n",
6071994689c1Smrg		  actual_cwrapper_path);
6072994689c1Smrg  XFREE (tmp_pathspec);
6073994689c1Smrg
6074994689c1Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6075994689c1Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6076994689c1Smrg
6077994689c1Smrg  /* wrapper name transforms */
6078994689c1Smrg  strendzap (actual_cwrapper_name, ".exe");
6079994689c1Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6080994689c1Smrg  XFREE (actual_cwrapper_name);
6081994689c1Smrg  actual_cwrapper_name = tmp_pathspec;
6082994689c1Smrg  tmp_pathspec = 0;
6083994689c1Smrg
6084994689c1Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6085994689c1Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6086994689c1Smrg  strendzap (target_name, ".exe");
6087994689c1Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6088994689c1Smrg  XFREE (target_name);
6089994689c1Smrg  target_name = tmp_pathspec;
6090994689c1Smrg  tmp_pathspec = 0;
6091994689c1Smrg
6092994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6093994689c1Smrg		  "(main) libtool target name: %s\n",
6094994689c1Smrg		  target_name);
6095994689c1SmrgEOF
60967a84e134Smrg
6097994689c1Smrg	    cat <<EOF
6098994689c1Smrg  newargz[0] =
6099994689c1Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6100994689c1Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6101994689c1Smrg  strcpy (newargz[0], actual_cwrapper_path);
6102994689c1Smrg  strcat (newargz[0], "$objdir");
6103994689c1Smrg  strcat (newargz[0], "/");
6104994689c1SmrgEOF
61057a84e134Smrg
6106994689c1Smrg	    cat <<"EOF"
6107994689c1Smrg  /* stop here, and copy so we don't have to do this twice */
6108994689c1Smrg  tmp_pathspec = xstrdup (newargz[0]);
61097a84e134Smrg
6110994689c1Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6111994689c1Smrg  strcat (newargz[0], actual_cwrapper_name);
61127a84e134Smrg
6113994689c1Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6114994689c1Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6115994689c1Smrg  XFREE (tmp_pathspec);
6116994689c1Smrg  tmp_pathspec = NULL;
6117994689c1SmrgEOF
61187a84e134Smrg
6119994689c1Smrg	    case $host_os in
6120994689c1Smrg	      mingw*)
6121994689c1Smrg	    cat <<"EOF"
6122994689c1Smrg  {
6123994689c1Smrg    char* p;
6124994689c1Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6125994689c1Smrg      {
6126994689c1Smrg	*p = '/';
6127994689c1Smrg      }
6128994689c1Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6129994689c1Smrg      {
6130994689c1Smrg	*p = '/';
6131994689c1Smrg      }
6132994689c1Smrg  }
6133994689c1SmrgEOF
6134994689c1Smrg	    ;;
6135994689c1Smrg	    esac
61367a84e134Smrg
6137994689c1Smrg	    cat <<"EOF"
6138994689c1Smrg  XFREE (target_name);
6139994689c1Smrg  XFREE (actual_cwrapper_path);
6140994689c1Smrg  XFREE (actual_cwrapper_name);
61417a84e134Smrg
6142994689c1Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6143994689c1Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6144f353fbadSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6145f353fbadSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6146f353fbadSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6147f353fbadSmrg     libraries must come first. */
6148994689c1Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6149f353fbadSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
61507a84e134Smrg
6151994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6152994689c1Smrg		  nonnull (lt_argv_zero));
6153994689c1Smrg  for (i = 0; i < newargc; i++)
6154994689c1Smrg    {
6155994689c1Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6156994689c1Smrg		      i, nonnull (newargz[i]));
6157994689c1Smrg    }
61587a84e134Smrg
6159994689c1SmrgEOF
61607a84e134Smrg
6161994689c1Smrg	    case $host_os in
6162994689c1Smrg	      mingw*)
6163994689c1Smrg		cat <<"EOF"
6164994689c1Smrg  /* execv doesn't actually work on mingw as expected on unix */
6165994689c1Smrg  newargz = prepare_spawn (newargz);
61665ec34c4cSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6167994689c1Smrg  if (rval == -1)
6168994689c1Smrg    {
6169994689c1Smrg      /* failed to start process */
6170994689c1Smrg      lt_debugprintf (__FILE__, __LINE__,
6171994689c1Smrg		      "(main) failed to launch target \"%s\": %s\n",
6172994689c1Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6173994689c1Smrg      return 127;
6174994689c1Smrg    }
6175994689c1Smrg  return rval;
6176994689c1SmrgEOF
6177994689c1Smrg		;;
6178994689c1Smrg	      *)
6179994689c1Smrg		cat <<"EOF"
6180994689c1Smrg  execv (lt_argv_zero, newargz);
6181994689c1Smrg  return rval; /* =127, but avoids unused variable warning */
6182994689c1SmrgEOF
6183994689c1Smrg		;;
6184994689c1Smrg	    esac
61857a84e134Smrg
6186994689c1Smrg	    cat <<"EOF"
6187994689c1Smrg}
61887a84e134Smrg
6189994689c1Smrgvoid *
6190994689c1Smrgxmalloc (size_t num)
6191994689c1Smrg{
6192994689c1Smrg  void *p = (void *) malloc (num);
6193994689c1Smrg  if (!p)
6194994689c1Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
61957a84e134Smrg
6196994689c1Smrg  return p;
6197994689c1Smrg}
61987a84e134Smrg
6199994689c1Smrgchar *
6200994689c1Smrgxstrdup (const char *string)
6201994689c1Smrg{
6202994689c1Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6203994689c1Smrg			  string) : NULL;
6204994689c1Smrg}
62057a84e134Smrg
6206994689c1Smrgconst char *
6207994689c1Smrgbase_name (const char *name)
6208994689c1Smrg{
6209994689c1Smrg  const char *base;
62107a84e134Smrg
62115ec34c4cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6212994689c1Smrg  /* Skip over the disk name in MSDOS pathnames. */
6213994689c1Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6214994689c1Smrg    name += 2;
6215994689c1Smrg#endif
62167a84e134Smrg
6217994689c1Smrg  for (base = name; *name; name++)
6218994689c1Smrg    if (IS_DIR_SEPARATOR (*name))
6219994689c1Smrg      base = name + 1;
6220994689c1Smrg  return base;
6221994689c1Smrg}
62227a84e134Smrg
6223994689c1Smrgint
6224994689c1Smrgcheck_executable (const char *path)
6225994689c1Smrg{
6226994689c1Smrg  struct stat st;
62277a84e134Smrg
6228994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6229994689c1Smrg                  nonempty (path));
6230994689c1Smrg  if ((!path) || (!*path))
6231994689c1Smrg    return 0;
62327a84e134Smrg
6233994689c1Smrg  if ((stat (path, &st) >= 0)
6234994689c1Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6235994689c1Smrg    return 1;
6236994689c1Smrg  else
6237994689c1Smrg    return 0;
6238994689c1Smrg}
62397a84e134Smrg
6240994689c1Smrgint
6241994689c1Smrgmake_executable (const char *path)
6242994689c1Smrg{
6243994689c1Smrg  int rval = 0;
6244994689c1Smrg  struct stat st;
6245e1e1713cSmrg
6246994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6247994689c1Smrg                  nonempty (path));
6248994689c1Smrg  if ((!path) || (!*path))
6249994689c1Smrg    return 0;
6250e1e1713cSmrg
6251994689c1Smrg  if (stat (path, &st) >= 0)
6252994689c1Smrg    {
6253994689c1Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6254994689c1Smrg    }
6255994689c1Smrg  return rval;
6256994689c1Smrg}
6257e1e1713cSmrg
6258994689c1Smrg/* Searches for the full path of the wrapper.  Returns
6259994689c1Smrg   newly allocated full path name if found, NULL otherwise
6260994689c1Smrg   Does not chase symlinks, even on platforms that support them.
6261994689c1Smrg*/
6262994689c1Smrgchar *
6263994689c1Smrgfind_executable (const char *wrapper)
6264994689c1Smrg{
6265994689c1Smrg  int has_slash = 0;
6266994689c1Smrg  const char *p;
6267994689c1Smrg  const char *p_next;
6268994689c1Smrg  /* static buffer for getcwd */
6269994689c1Smrg  char tmp[LT_PATHMAX + 1];
62705ec34c4cSmrg  size_t tmp_len;
6271994689c1Smrg  char *concat_name;
6272e1e1713cSmrg
6273994689c1Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6274994689c1Smrg                  nonempty (wrapper));
6275e1e1713cSmrg
6276994689c1Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6277994689c1Smrg    return NULL;
62787a84e134Smrg
6279994689c1Smrg  /* Absolute path? */
62805ec34c4cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6281994689c1Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6282994689c1Smrg    {
6283994689c1Smrg      concat_name = xstrdup (wrapper);
6284994689c1Smrg      if (check_executable (concat_name))
6285994689c1Smrg	return concat_name;
6286994689c1Smrg      XFREE (concat_name);
6287994689c1Smrg    }
6288994689c1Smrg  else
6289994689c1Smrg    {
6290994689c1Smrg#endif
6291994689c1Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6292994689c1Smrg	{
6293994689c1Smrg	  concat_name = xstrdup (wrapper);
6294994689c1Smrg	  if (check_executable (concat_name))
6295994689c1Smrg	    return concat_name;
6296994689c1Smrg	  XFREE (concat_name);
6297994689c1Smrg	}
62985ec34c4cSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6299994689c1Smrg    }
6300994689c1Smrg#endif
63017a84e134Smrg
6302994689c1Smrg  for (p = wrapper; *p; p++)
6303994689c1Smrg    if (*p == '/')
6304994689c1Smrg      {
6305994689c1Smrg	has_slash = 1;
6306994689c1Smrg	break;
6307994689c1Smrg      }
6308994689c1Smrg  if (!has_slash)
6309994689c1Smrg    {
6310994689c1Smrg      /* no slashes; search PATH */
6311994689c1Smrg      const char *path = getenv ("PATH");
6312994689c1Smrg      if (path != NULL)
6313994689c1Smrg	{
6314994689c1Smrg	  for (p = path; *p; p = p_next)
6315994689c1Smrg	    {
6316994689c1Smrg	      const char *q;
6317994689c1Smrg	      size_t p_len;
6318994689c1Smrg	      for (q = p; *q; q++)
6319994689c1Smrg		if (IS_PATH_SEPARATOR (*q))
6320994689c1Smrg		  break;
63215ec34c4cSmrg	      p_len = (size_t) (q - p);
6322994689c1Smrg	      p_next = (*q == '\0' ? q : q + 1);
6323994689c1Smrg	      if (p_len == 0)
6324994689c1Smrg		{
6325994689c1Smrg		  /* empty path: current directory */
6326994689c1Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6327994689c1Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6328994689c1Smrg                              nonnull (strerror (errno)));
6329994689c1Smrg		  tmp_len = strlen (tmp);
6330994689c1Smrg		  concat_name =
6331994689c1Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6332994689c1Smrg		  memcpy (concat_name, tmp, tmp_len);
6333994689c1Smrg		  concat_name[tmp_len] = '/';
6334994689c1Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6335994689c1Smrg		}
6336994689c1Smrg	      else
6337994689c1Smrg		{
6338994689c1Smrg		  concat_name =
6339994689c1Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6340994689c1Smrg		  memcpy (concat_name, p, p_len);
6341994689c1Smrg		  concat_name[p_len] = '/';
6342994689c1Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6343994689c1Smrg		}
6344994689c1Smrg	      if (check_executable (concat_name))
6345994689c1Smrg		return concat_name;
6346994689c1Smrg	      XFREE (concat_name);
6347994689c1Smrg	    }
6348994689c1Smrg	}
6349994689c1Smrg      /* not found in PATH; assume curdir */
6350994689c1Smrg    }
6351994689c1Smrg  /* Relative path | not found in path: prepend cwd */
6352994689c1Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6353994689c1Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6354994689c1Smrg              nonnull (strerror (errno)));
6355994689c1Smrg  tmp_len = strlen (tmp);
6356994689c1Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6357994689c1Smrg  memcpy (concat_name, tmp, tmp_len);
6358994689c1Smrg  concat_name[tmp_len] = '/';
6359994689c1Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
63607a84e134Smrg
6361994689c1Smrg  if (check_executable (concat_name))
6362994689c1Smrg    return concat_name;
6363994689c1Smrg  XFREE (concat_name);
6364994689c1Smrg  return NULL;
6365994689c1Smrg}
6366e1e1713cSmrg
6367994689c1Smrgchar *
6368994689c1Smrgchase_symlinks (const char *pathspec)
6369994689c1Smrg{
6370994689c1Smrg#ifndef S_ISLNK
6371994689c1Smrg  return xstrdup (pathspec);
6372994689c1Smrg#else
6373994689c1Smrg  char buf[LT_PATHMAX];
6374994689c1Smrg  struct stat s;
6375994689c1Smrg  char *tmp_pathspec = xstrdup (pathspec);
6376994689c1Smrg  char *p;
6377994689c1Smrg  int has_symlinks = 0;
6378994689c1Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6379994689c1Smrg    {
6380994689c1Smrg      lt_debugprintf (__FILE__, __LINE__,
6381994689c1Smrg		      "checking path component for symlinks: %s\n",
6382994689c1Smrg		      tmp_pathspec);
6383994689c1Smrg      if (lstat (tmp_pathspec, &s) == 0)
6384994689c1Smrg	{
6385994689c1Smrg	  if (S_ISLNK (s.st_mode) != 0)
6386994689c1Smrg	    {
6387994689c1Smrg	      has_symlinks = 1;
6388994689c1Smrg	      break;
6389994689c1Smrg	    }
6390e1e1713cSmrg
6391994689c1Smrg	  /* search backwards for last DIR_SEPARATOR */
6392994689c1Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6393994689c1Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6394994689c1Smrg	    p--;
6395994689c1Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6396994689c1Smrg	    {
6397994689c1Smrg	      /* no more DIR_SEPARATORS left */
6398994689c1Smrg	      break;
6399994689c1Smrg	    }
6400994689c1Smrg	  *p = '\0';
6401994689c1Smrg	}
6402994689c1Smrg      else
6403994689c1Smrg	{
6404994689c1Smrg	  lt_fatal (__FILE__, __LINE__,
6405994689c1Smrg		    "error accessing file \"%s\": %s",
6406994689c1Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6407994689c1Smrg	}
6408994689c1Smrg    }
6409994689c1Smrg  XFREE (tmp_pathspec);
6410e1e1713cSmrg
6411994689c1Smrg  if (!has_symlinks)
6412994689c1Smrg    {
6413994689c1Smrg      return xstrdup (pathspec);
6414994689c1Smrg    }
6415e1e1713cSmrg
6416994689c1Smrg  tmp_pathspec = realpath (pathspec, buf);
6417994689c1Smrg  if (tmp_pathspec == 0)
6418994689c1Smrg    {
6419994689c1Smrg      lt_fatal (__FILE__, __LINE__,
6420994689c1Smrg		"could not follow symlinks for %s", pathspec);
6421994689c1Smrg    }
6422994689c1Smrg  return xstrdup (tmp_pathspec);
6423994689c1Smrg#endif
6424994689c1Smrg}
64257a84e134Smrg
6426994689c1Smrgchar *
6427994689c1Smrgstrendzap (char *str, const char *pat)
6428994689c1Smrg{
6429994689c1Smrg  size_t len, patlen;
64307a84e134Smrg
6431994689c1Smrg  assert (str != NULL);
6432994689c1Smrg  assert (pat != NULL);
64337a84e134Smrg
6434994689c1Smrg  len = strlen (str);
6435994689c1Smrg  patlen = strlen (pat);
64367a84e134Smrg
6437994689c1Smrg  if (patlen <= len)
6438994689c1Smrg    {
6439994689c1Smrg      str += len - patlen;
64405ec34c4cSmrg      if (STREQ (str, pat))
6441994689c1Smrg	*str = '\0';
6442994689c1Smrg    }
6443994689c1Smrg  return str;
6444994689c1Smrg}
64457a84e134Smrg
6446994689c1Smrgvoid
6447994689c1Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6448994689c1Smrg{
6449994689c1Smrg  va_list args;
6450994689c1Smrg  if (lt_debug)
6451994689c1Smrg    {
6452994689c1Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6453994689c1Smrg      va_start (args, fmt);
6454994689c1Smrg      (void) vfprintf (stderr, fmt, args);
6455994689c1Smrg      va_end (args);
6456994689c1Smrg    }
6457994689c1Smrg}
64587a84e134Smrg
6459994689c1Smrgstatic void
6460994689c1Smrglt_error_core (int exit_status, const char *file,
6461994689c1Smrg	       int line, const char *mode,
6462994689c1Smrg	       const char *message, va_list ap)
6463994689c1Smrg{
6464994689c1Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6465994689c1Smrg  vfprintf (stderr, message, ap);
6466994689c1Smrg  fprintf (stderr, ".\n");
64677a84e134Smrg
6468994689c1Smrg  if (exit_status >= 0)
6469994689c1Smrg    exit (exit_status);
6470994689c1Smrg}
64717a84e134Smrg
6472994689c1Smrgvoid
6473994689c1Smrglt_fatal (const char *file, int line, const char *message, ...)
6474994689c1Smrg{
6475994689c1Smrg  va_list ap;
6476994689c1Smrg  va_start (ap, message);
6477994689c1Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6478994689c1Smrg  va_end (ap);
6479994689c1Smrg}
64807a84e134Smrg
6481994689c1Smrgstatic const char *
6482994689c1Smrgnonnull (const char *s)
6483994689c1Smrg{
6484994689c1Smrg  return s ? s : "(null)";
6485994689c1Smrg}
64867a84e134Smrg
6487994689c1Smrgstatic const char *
6488994689c1Smrgnonempty (const char *s)
6489994689c1Smrg{
6490994689c1Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
6491994689c1Smrg}
6492775e7de9Smrg
6493994689c1Smrgvoid
6494994689c1Smrglt_setenv (const char *name, const char *value)
6495994689c1Smrg{
6496994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6497994689c1Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
6498994689c1Smrg                  nonnull (name), nonnull (value));
6499994689c1Smrg  {
6500994689c1Smrg#ifdef HAVE_SETENV
6501994689c1Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6502994689c1Smrg    char *str = xstrdup (value);
6503994689c1Smrg    setenv (name, str, 1);
6504994689c1Smrg#else
65055ec34c4cSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6506994689c1Smrg    char *str = XMALLOC (char, len);
6507994689c1Smrg    sprintf (str, "%s=%s", name, value);
6508994689c1Smrg    if (putenv (str) != EXIT_SUCCESS)
6509994689c1Smrg      {
6510994689c1Smrg        XFREE (str);
6511994689c1Smrg      }
6512994689c1Smrg#endif
6513994689c1Smrg  }
6514994689c1Smrg}
65157a84e134Smrg
6516994689c1Smrgchar *
6517994689c1Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6518994689c1Smrg{
6519994689c1Smrg  char *new_value;
6520994689c1Smrg  if (orig_value && *orig_value)
6521994689c1Smrg    {
65225ec34c4cSmrg      size_t orig_value_len = strlen (orig_value);
65235ec34c4cSmrg      size_t add_len = strlen (add);
6524994689c1Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6525994689c1Smrg      if (to_end)
6526994689c1Smrg        {
6527994689c1Smrg          strcpy (new_value, orig_value);
6528994689c1Smrg          strcpy (new_value + orig_value_len, add);
6529994689c1Smrg        }
6530994689c1Smrg      else
6531994689c1Smrg        {
6532994689c1Smrg          strcpy (new_value, add);
6533994689c1Smrg          strcpy (new_value + add_len, orig_value);
6534994689c1Smrg        }
6535994689c1Smrg    }
6536994689c1Smrg  else
6537994689c1Smrg    {
6538994689c1Smrg      new_value = xstrdup (add);
6539994689c1Smrg    }
6540994689c1Smrg  return new_value;
6541994689c1Smrg}
65427a84e134Smrg
6543994689c1Smrgvoid
6544994689c1Smrglt_update_exe_path (const char *name, const char *value)
6545994689c1Smrg{
6546994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6547994689c1Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6548994689c1Smrg                  nonnull (name), nonnull (value));
65497a84e134Smrg
6550994689c1Smrg  if (name && *name && value && *value)
6551994689c1Smrg    {
6552994689c1Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6553994689c1Smrg      /* some systems can't cope with a ':'-terminated path #' */
65545ec34c4cSmrg      size_t len = strlen (new_value);
65555ec34c4cSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6556994689c1Smrg        {
65575ec34c4cSmrg          new_value[--len] = '\0';
6558994689c1Smrg        }
6559994689c1Smrg      lt_setenv (name, new_value);
6560994689c1Smrg      XFREE (new_value);
6561994689c1Smrg    }
6562994689c1Smrg}
65637a84e134Smrg
6564994689c1Smrgvoid
6565994689c1Smrglt_update_lib_path (const char *name, const char *value)
6566994689c1Smrg{
6567994689c1Smrg  lt_debugprintf (__FILE__, __LINE__,
6568994689c1Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6569994689c1Smrg                  nonnull (name), nonnull (value));
65707a84e134Smrg
6571994689c1Smrg  if (name && *name && value && *value)
6572994689c1Smrg    {
6573994689c1Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6574994689c1Smrg      lt_setenv (name, new_value);
6575994689c1Smrg      XFREE (new_value);
6576994689c1Smrg    }
6577994689c1Smrg}
65787a84e134Smrg
6579994689c1SmrgEOF
6580994689c1Smrg	    case $host_os in
6581994689c1Smrg	      mingw*)
6582994689c1Smrg		cat <<"EOF"
6583994689c1Smrg
6584994689c1Smrg/* Prepares an argument vector before calling spawn().
6585994689c1Smrg   Note that spawn() does not by itself call the command interpreter
6586994689c1Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6587994689c1Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6588994689c1Smrg         GetVersionEx(&v);
6589994689c1Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6590994689c1Smrg      }) ? "cmd.exe" : "command.com").
6591994689c1Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6592994689c1Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6593994689c1Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6594994689c1Smrg   special way:
6595994689c1Smrg   - Space and tab are interpreted as delimiters. They are not treated as
6596994689c1Smrg     delimiters if they are surrounded by double quotes: "...".
6597994689c1Smrg   - Unescaped double quotes are removed from the input. Their only effect is
6598994689c1Smrg     that within double quotes, space and tab are treated like normal
6599994689c1Smrg     characters.
6600994689c1Smrg   - Backslashes not followed by double quotes are not special.
6601994689c1Smrg   - But 2*n+1 backslashes followed by a double quote become
6602994689c1Smrg     n backslashes followed by a double quote (n >= 0):
6603994689c1Smrg       \" -> "
6604994689c1Smrg       \\\" -> \"
6605994689c1Smrg       \\\\\" -> \\"
6606994689c1Smrg */
6607994689c1Smrg#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"
6608994689c1Smrg#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"
6609994689c1Smrgchar **
6610994689c1Smrgprepare_spawn (char **argv)
6611994689c1Smrg{
6612994689c1Smrg  size_t argc;
6613994689c1Smrg  char **new_argv;
6614994689c1Smrg  size_t i;
66157a84e134Smrg
6616994689c1Smrg  /* Count number of arguments.  */
6617994689c1Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6618994689c1Smrg    ;
66197a84e134Smrg
6620994689c1Smrg  /* Allocate new argument vector.  */
6621994689c1Smrg  new_argv = XMALLOC (char *, argc + 1);
66227a84e134Smrg
6623994689c1Smrg  /* Put quoted arguments into the new argument vector.  */
6624994689c1Smrg  for (i = 0; i < argc; i++)
6625994689c1Smrg    {
6626994689c1Smrg      const char *string = argv[i];
6627994689c1Smrg
6628994689c1Smrg      if (string[0] == '\0')
6629994689c1Smrg	new_argv[i] = xstrdup ("\"\"");
6630994689c1Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6631994689c1Smrg	{
6632994689c1Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6633994689c1Smrg	  size_t length;
6634994689c1Smrg	  unsigned int backslashes;
6635994689c1Smrg	  const char *s;
6636994689c1Smrg	  char *quoted_string;
6637994689c1Smrg	  char *p;
6638994689c1Smrg
6639994689c1Smrg	  length = 0;
6640994689c1Smrg	  backslashes = 0;
6641994689c1Smrg	  if (quote_around)
6642994689c1Smrg	    length++;
6643994689c1Smrg	  for (s = string; *s != '\0'; s++)
6644994689c1Smrg	    {
6645994689c1Smrg	      char c = *s;
6646994689c1Smrg	      if (c == '"')
6647994689c1Smrg		length += backslashes + 1;
6648994689c1Smrg	      length++;
6649994689c1Smrg	      if (c == '\\')
6650994689c1Smrg		backslashes++;
6651994689c1Smrg	      else
6652994689c1Smrg		backslashes = 0;
6653994689c1Smrg	    }
6654994689c1Smrg	  if (quote_around)
6655994689c1Smrg	    length += backslashes + 1;
6656994689c1Smrg
6657994689c1Smrg	  quoted_string = XMALLOC (char, length + 1);
6658994689c1Smrg
6659994689c1Smrg	  p = quoted_string;
6660994689c1Smrg	  backslashes = 0;
6661994689c1Smrg	  if (quote_around)
6662994689c1Smrg	    *p++ = '"';
6663994689c1Smrg	  for (s = string; *s != '\0'; s++)
6664994689c1Smrg	    {
6665994689c1Smrg	      char c = *s;
6666994689c1Smrg	      if (c == '"')
6667994689c1Smrg		{
6668994689c1Smrg		  unsigned int j;
6669994689c1Smrg		  for (j = backslashes + 1; j > 0; j--)
6670994689c1Smrg		    *p++ = '\\';
6671994689c1Smrg		}
6672994689c1Smrg	      *p++ = c;
6673994689c1Smrg	      if (c == '\\')
6674994689c1Smrg		backslashes++;
6675994689c1Smrg	      else
6676994689c1Smrg		backslashes = 0;
6677994689c1Smrg	    }
6678994689c1Smrg	  if (quote_around)
6679994689c1Smrg	    {
6680994689c1Smrg	      unsigned int j;
6681994689c1Smrg	      for (j = backslashes; j > 0; j--)
6682994689c1Smrg		*p++ = '\\';
6683994689c1Smrg	      *p++ = '"';
6684994689c1Smrg	    }
6685994689c1Smrg	  *p = '\0';
66867a84e134Smrg
6687994689c1Smrg	  new_argv[i] = quoted_string;
6688994689c1Smrg	}
6689994689c1Smrg      else
6690994689c1Smrg	new_argv[i] = (char *) string;
6691994689c1Smrg    }
6692994689c1Smrg  new_argv[argc] = NULL;
66937a84e134Smrg
6694994689c1Smrg  return new_argv;
6695994689c1Smrg}
6696994689c1SmrgEOF
6697e1e1713cSmrg		;;
6698994689c1Smrg	    esac
66997a84e134Smrg
6700994689c1Smrg            cat <<"EOF"
6701994689c1Smrgvoid lt_dump_script (FILE* f)
6702994689c1Smrg{
6703994689c1SmrgEOF
6704994689c1Smrg	    func_emit_wrapper yes |
6705421c997bSmrg	      $SED -n -e '
6706421c997bSmrgs/^\(.\{79\}\)\(..*\)/\1\
6707421c997bSmrg\2/
6708421c997bSmrgh
6709421c997bSmrgs/\([\\"]\)/\\\1/g
6710421c997bSmrgs/$/\\n/
6711421c997bSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6712421c997bSmrgg
6713421c997bSmrgD'
6714994689c1Smrg            cat <<"EOF"
6715994689c1Smrg}
6716994689c1SmrgEOF
6717994689c1Smrg}
6718994689c1Smrg# end: func_emit_cwrapperexe_src
67197a84e134Smrg
6720994689c1Smrg# func_win32_import_lib_p ARG
6721994689c1Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6722994689c1Smrgfunc_win32_import_lib_p ()
6723994689c1Smrg{
67245ec34c4cSmrg    $debug_cmd
67255ec34c4cSmrg
6726994689c1Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6727994689c1Smrg    *import*) : ;;
6728994689c1Smrg    *) false ;;
6729994689c1Smrg    esac
6730994689c1Smrg}
67317a84e134Smrg
67325ec34c4cSmrg# func_suncc_cstd_abi
67335ec34c4cSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
67345ec34c4cSmrg# Several compiler flags select an ABI that is incompatible with the
67355ec34c4cSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
67365ec34c4cSmrgfunc_suncc_cstd_abi ()
67375ec34c4cSmrg{
67385ec34c4cSmrg    $debug_cmd
67395ec34c4cSmrg
67405ec34c4cSmrg    case " $compile_command " in
67415ec34c4cSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
67425ec34c4cSmrg      suncc_use_cstd_abi=no
67435ec34c4cSmrg      ;;
67445ec34c4cSmrg    *)
67455ec34c4cSmrg      suncc_use_cstd_abi=yes
67465ec34c4cSmrg      ;;
67475ec34c4cSmrg    esac
67485ec34c4cSmrg}
67495ec34c4cSmrg
6750994689c1Smrg# func_mode_link arg...
6751994689c1Smrgfunc_mode_link ()
6752994689c1Smrg{
67535ec34c4cSmrg    $debug_cmd
67545ec34c4cSmrg
6755994689c1Smrg    case $host in
6756994689c1Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6757994689c1Smrg      # It is impossible to link a dll without this setting, and
6758994689c1Smrg      # we shouldn't force the makefile maintainer to figure out
67595ec34c4cSmrg      # what system we are compiling for in order to pass an extra
6760994689c1Smrg      # flag for every libtool invocation.
6761994689c1Smrg      # allow_undefined=no
67627a84e134Smrg
6763994689c1Smrg      # FIXME: Unfortunately, there are problems with the above when trying
67645ec34c4cSmrg      # to make a dll that has undefined symbols, in which case not
6765994689c1Smrg      # even a static library is built.  For now, we need to specify
6766994689c1Smrg      # -no-undefined on the libtool link line when we can be certain
6767994689c1Smrg      # that all symbols are satisfied, otherwise we get a static library.
6768994689c1Smrg      allow_undefined=yes
6769994689c1Smrg      ;;
6770994689c1Smrg    *)
6771994689c1Smrg      allow_undefined=yes
6772994689c1Smrg      ;;
6773994689c1Smrg    esac
6774994689c1Smrg    libtool_args=$nonopt
6775994689c1Smrg    base_compile="$nonopt $@"
6776994689c1Smrg    compile_command=$nonopt
6777994689c1Smrg    finalize_command=$nonopt
67787a84e134Smrg
6779994689c1Smrg    compile_rpath=
6780994689c1Smrg    finalize_rpath=
6781994689c1Smrg    compile_shlibpath=
6782994689c1Smrg    finalize_shlibpath=
6783994689c1Smrg    convenience=
6784994689c1Smrg    old_convenience=
6785994689c1Smrg    deplibs=
6786994689c1Smrg    old_deplibs=
6787994689c1Smrg    compiler_flags=
6788994689c1Smrg    linker_flags=
6789994689c1Smrg    dllsearchpath=
6790994689c1Smrg    lib_search_path=`pwd`
6791994689c1Smrg    inst_prefix_dir=
6792994689c1Smrg    new_inherited_linker_flags=
67937a84e134Smrg
6794994689c1Smrg    avoid_version=no
6795994689c1Smrg    bindir=
6796994689c1Smrg    dlfiles=
6797994689c1Smrg    dlprefiles=
6798994689c1Smrg    dlself=no
6799994689c1Smrg    export_dynamic=no
6800994689c1Smrg    export_symbols=
6801994689c1Smrg    export_symbols_regex=
6802994689c1Smrg    generated=
6803994689c1Smrg    libobjs=
6804994689c1Smrg    ltlibs=
6805994689c1Smrg    module=no
6806994689c1Smrg    no_install=no
6807994689c1Smrg    objs=
68085ec34c4cSmrg    os2dllname=
6809994689c1Smrg    non_pic_objects=
6810994689c1Smrg    precious_files_regex=
6811994689c1Smrg    prefer_static_libs=no
68125ec34c4cSmrg    preload=false
6813994689c1Smrg    prev=
6814994689c1Smrg    prevarg=
6815994689c1Smrg    release=
6816994689c1Smrg    rpath=
6817994689c1Smrg    xrpath=
6818994689c1Smrg    perm_rpath=
6819994689c1Smrg    temp_rpath=
6820994689c1Smrg    thread_safe=no
6821994689c1Smrg    vinfo=
6822994689c1Smrg    vinfo_number=no
6823994689c1Smrg    weak_libs=
68245ec34c4cSmrg    single_module=$wl-single_module
6825994689c1Smrg    func_infer_tag $base_compile
68267a84e134Smrg
6827994689c1Smrg    # We need to know -static, to get the right output filenames.
6828994689c1Smrg    for arg
6829994689c1Smrg    do
6830994689c1Smrg      case $arg in
6831994689c1Smrg      -shared)
68325ec34c4cSmrg	test yes != "$build_libtool_libs" \
68335ec34c4cSmrg	  && func_fatal_configuration "cannot build a shared library"
6834994689c1Smrg	build_old_libs=no
6835994689c1Smrg	break
6836994689c1Smrg	;;
6837994689c1Smrg      -all-static | -static | -static-libtool-libs)
6838994689c1Smrg	case $arg in
6839994689c1Smrg	-all-static)
68405ec34c4cSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6841994689c1Smrg	    func_warning "complete static linking is impossible in this configuration"
6842994689c1Smrg	  fi
6843994689c1Smrg	  if test -n "$link_static_flag"; then
6844994689c1Smrg	    dlopen_self=$dlopen_self_static
6845994689c1Smrg	  fi
6846994689c1Smrg	  prefer_static_libs=yes
6847994689c1Smrg	  ;;
6848994689c1Smrg	-static)
6849994689c1Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6850994689c1Smrg	    dlopen_self=$dlopen_self_static
6851994689c1Smrg	  fi
6852994689c1Smrg	  prefer_static_libs=built
6853994689c1Smrg	  ;;
6854994689c1Smrg	-static-libtool-libs)
6855994689c1Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6856994689c1Smrg	    dlopen_self=$dlopen_self_static
6857994689c1Smrg	  fi
6858994689c1Smrg	  prefer_static_libs=yes
6859994689c1Smrg	  ;;
6860994689c1Smrg	esac
6861994689c1Smrg	build_libtool_libs=no
6862994689c1Smrg	build_old_libs=yes
6863994689c1Smrg	break
6864994689c1Smrg	;;
6865994689c1Smrg      esac
6866994689c1Smrg    done
68677a84e134Smrg
6868994689c1Smrg    # See if our shared archives depend on static archives.
6869994689c1Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
68707a84e134Smrg
6871994689c1Smrg    # Go through the arguments, transforming them on the way.
6872994689c1Smrg    while test "$#" -gt 0; do
68735ec34c4cSmrg      arg=$1
6874994689c1Smrg      shift
68755b16253fSmrg      func_quote_arg pretty,unquoted "$arg"
68765b16253fSmrg      qarg=$func_quote_arg_unquoted_result
68775b16253fSmrg      func_append libtool_args " $func_quote_arg_result"
68787a84e134Smrg
6879994689c1Smrg      # If the previous option needs an argument, assign it.
6880994689c1Smrg      if test -n "$prev"; then
6881994689c1Smrg	case $prev in
6882994689c1Smrg	output)
6883994689c1Smrg	  func_append compile_command " @OUTPUT@"
6884994689c1Smrg	  func_append finalize_command " @OUTPUT@"
6885994689c1Smrg	  ;;
6886994689c1Smrg	esac
68877a84e134Smrg
6888994689c1Smrg	case $prev in
6889994689c1Smrg	bindir)
68905ec34c4cSmrg	  bindir=$arg
6891994689c1Smrg	  prev=
6892994689c1Smrg	  continue
6893994689c1Smrg	  ;;
6894994689c1Smrg	dlfiles|dlprefiles)
68955ec34c4cSmrg	  $preload || {
6896994689c1Smrg	    # Add the symbol object into the linking commands.
6897994689c1Smrg	    func_append compile_command " @SYMFILE@"
6898994689c1Smrg	    func_append finalize_command " @SYMFILE@"
68995ec34c4cSmrg	    preload=:
69005ec34c4cSmrg	  }
6901994689c1Smrg	  case $arg in
6902994689c1Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6903994689c1Smrg	  force)
69045ec34c4cSmrg	    if test no = "$dlself"; then
6905994689c1Smrg	      dlself=needless
6906994689c1Smrg	      export_dynamic=yes
6907e1e1713cSmrg	    fi
6908994689c1Smrg	    prev=
6909994689c1Smrg	    continue
6910994689c1Smrg	    ;;
6911994689c1Smrg	  self)
69125ec34c4cSmrg	    if test dlprefiles = "$prev"; then
6913994689c1Smrg	      dlself=yes
69145ec34c4cSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6915994689c1Smrg	      dlself=yes
6916e1e1713cSmrg	    else
6917994689c1Smrg	      dlself=needless
6918994689c1Smrg	      export_dynamic=yes
6919e1e1713cSmrg	    fi
6920994689c1Smrg	    prev=
6921994689c1Smrg	    continue
6922994689c1Smrg	    ;;
6923994689c1Smrg	  *)
69245ec34c4cSmrg	    if test dlfiles = "$prev"; then
6925f353fbadSmrg	      func_append dlfiles " $arg"
6926e1e1713cSmrg	    else
6927f353fbadSmrg	      func_append dlprefiles " $arg"
6928e1e1713cSmrg	    fi
6929994689c1Smrg	    prev=
6930994689c1Smrg	    continue
6931994689c1Smrg	    ;;
6932994689c1Smrg	  esac
6933994689c1Smrg	  ;;
6934994689c1Smrg	expsyms)
69355ec34c4cSmrg	  export_symbols=$arg
6936994689c1Smrg	  test -f "$arg" \
69375ec34c4cSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6938994689c1Smrg	  prev=
6939994689c1Smrg	  continue
6940994689c1Smrg	  ;;
6941994689c1Smrg	expsyms_regex)
69425ec34c4cSmrg	  export_symbols_regex=$arg
6943994689c1Smrg	  prev=
6944994689c1Smrg	  continue
6945994689c1Smrg	  ;;
6946994689c1Smrg	framework)
6947e1e1713cSmrg	  case $host in
6948994689c1Smrg	    *-*-darwin*)
6949994689c1Smrg	      case "$deplibs " in
6950994689c1Smrg		*" $qarg.ltframework "*) ;;
6951f353fbadSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6952994689c1Smrg		   ;;
6953994689c1Smrg	      esac
6954994689c1Smrg	      ;;
6955e1e1713cSmrg	  esac
6956994689c1Smrg	  prev=
6957994689c1Smrg	  continue
6958e1e1713cSmrg	  ;;
6959994689c1Smrg	inst_prefix)
69605ec34c4cSmrg	  inst_prefix_dir=$arg
69615ec34c4cSmrg	  prev=
69625ec34c4cSmrg	  continue
69635ec34c4cSmrg	  ;;
69645ec34c4cSmrg	mllvm)
69655ec34c4cSmrg	  # Clang does not use LLVM to link, so we can simply discard any
69665ec34c4cSmrg	  # '-mllvm $arg' options when doing the link step.
6967994689c1Smrg	  prev=
6968994689c1Smrg	  continue
6969e1e1713cSmrg	  ;;
6970994689c1Smrg	objectlist)
6971994689c1Smrg	  if test -f "$arg"; then
6972994689c1Smrg	    save_arg=$arg
6973994689c1Smrg	    moreargs=
6974994689c1Smrg	    for fil in `cat "$save_arg"`
6975994689c1Smrg	    do
6976f353fbadSmrg#	      func_append moreargs " $fil"
6977994689c1Smrg	      arg=$fil
6978994689c1Smrg	      # A libtool-controlled object.
69797a84e134Smrg
6980994689c1Smrg	      # Check to see that this really is a libtool object.
6981994689c1Smrg	      if func_lalib_unsafe_p "$arg"; then
6982994689c1Smrg		pic_object=
6983994689c1Smrg		non_pic_object=
6984775e7de9Smrg
6985994689c1Smrg		# Read the .lo file
6986994689c1Smrg		func_source "$arg"
6987775e7de9Smrg
6988994689c1Smrg		if test -z "$pic_object" ||
6989994689c1Smrg		   test -z "$non_pic_object" ||
69905ec34c4cSmrg		   test none = "$pic_object" &&
69915ec34c4cSmrg		   test none = "$non_pic_object"; then
69925ec34c4cSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6993994689c1Smrg		fi
6994775e7de9Smrg
6995994689c1Smrg		# Extract subdirectory from the argument.
6996994689c1Smrg		func_dirname "$arg" "/" ""
69975ec34c4cSmrg		xdir=$func_dirname_result
6998775e7de9Smrg
69995ec34c4cSmrg		if test none != "$pic_object"; then
7000994689c1Smrg		  # Prepend the subdirectory the object is found in.
70015ec34c4cSmrg		  pic_object=$xdir$pic_object
7002775e7de9Smrg
70035ec34c4cSmrg		  if test dlfiles = "$prev"; then
70045ec34c4cSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7005f353fbadSmrg		      func_append dlfiles " $pic_object"
7006994689c1Smrg		      prev=
7007994689c1Smrg		      continue
7008994689c1Smrg		    else
7009994689c1Smrg		      # If libtool objects are unsupported, then we need to preload.
7010994689c1Smrg		      prev=dlprefiles
7011994689c1Smrg		    fi
7012994689c1Smrg		  fi
7013775e7de9Smrg
7014994689c1Smrg		  # CHECK ME:  I think I busted this.  -Ossama
70155ec34c4cSmrg		  if test dlprefiles = "$prev"; then
7016994689c1Smrg		    # Preload the old-style object.
7017f353fbadSmrg		    func_append dlprefiles " $pic_object"
7018994689c1Smrg		    prev=
7019994689c1Smrg		  fi
7020775e7de9Smrg
7021994689c1Smrg		  # A PIC object.
7022994689c1Smrg		  func_append libobjs " $pic_object"
70235ec34c4cSmrg		  arg=$pic_object
7024994689c1Smrg		fi
7025775e7de9Smrg
7026994689c1Smrg		# Non-PIC object.
70275ec34c4cSmrg		if test none != "$non_pic_object"; then
7028994689c1Smrg		  # Prepend the subdirectory the object is found in.
70295ec34c4cSmrg		  non_pic_object=$xdir$non_pic_object
7030775e7de9Smrg
7031994689c1Smrg		  # A standard non-PIC object
7032994689c1Smrg		  func_append non_pic_objects " $non_pic_object"
70335ec34c4cSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
70345ec34c4cSmrg		    arg=$non_pic_object
7035994689c1Smrg		  fi
7036994689c1Smrg		else
7037994689c1Smrg		  # If the PIC object exists, use it instead.
7038994689c1Smrg		  # $xdir was prepended to $pic_object above.
70395ec34c4cSmrg		  non_pic_object=$pic_object
7040994689c1Smrg		  func_append non_pic_objects " $non_pic_object"
7041994689c1Smrg		fi
7042994689c1Smrg	      else
7043994689c1Smrg		# Only an error if not doing a dry-run.
7044994689c1Smrg		if $opt_dry_run; then
7045994689c1Smrg		  # Extract subdirectory from the argument.
7046994689c1Smrg		  func_dirname "$arg" "/" ""
70475ec34c4cSmrg		  xdir=$func_dirname_result
7048994689c1Smrg
7049994689c1Smrg		  func_lo2o "$arg"
7050994689c1Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7051994689c1Smrg		  non_pic_object=$xdir$func_lo2o_result
7052994689c1Smrg		  func_append libobjs " $pic_object"
7053994689c1Smrg		  func_append non_pic_objects " $non_pic_object"
7054994689c1Smrg	        else
70555ec34c4cSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7056994689c1Smrg		fi
7057994689c1Smrg	      fi
7058994689c1Smrg	    done
7059e1e1713cSmrg	  else
70605ec34c4cSmrg	    func_fatal_error "link input file '$arg' does not exist"
7061e1e1713cSmrg	  fi
7062994689c1Smrg	  arg=$save_arg
7063994689c1Smrg	  prev=
7064994689c1Smrg	  continue
7065994689c1Smrg	  ;;
70665ec34c4cSmrg	os2dllname)
70675ec34c4cSmrg	  os2dllname=$arg
70685ec34c4cSmrg	  prev=
70695ec34c4cSmrg	  continue
70705ec34c4cSmrg	  ;;
7071994689c1Smrg	precious_regex)
70725ec34c4cSmrg	  precious_files_regex=$arg
7073994689c1Smrg	  prev=
7074994689c1Smrg	  continue
7075994689c1Smrg	  ;;
7076994689c1Smrg	release)
70775ec34c4cSmrg	  release=-$arg
7078994689c1Smrg	  prev=
7079994689c1Smrg	  continue
7080994689c1Smrg	  ;;
7081994689c1Smrg	rpath | xrpath)
7082994689c1Smrg	  # We need an absolute path.
7083994689c1Smrg	  case $arg in
7084994689c1Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7085994689c1Smrg	  *)
7086994689c1Smrg	    func_fatal_error "only absolute run-paths are allowed"
7087994689c1Smrg	    ;;
7088994689c1Smrg	  esac
70895ec34c4cSmrg	  if test rpath = "$prev"; then
7090994689c1Smrg	    case "$rpath " in
7091994689c1Smrg	    *" $arg "*) ;;
7092f353fbadSmrg	    *) func_append rpath " $arg" ;;
7093994689c1Smrg	    esac
7094e1e1713cSmrg	  else
7095994689c1Smrg	    case "$xrpath " in
7096994689c1Smrg	    *" $arg "*) ;;
7097f353fbadSmrg	    *) func_append xrpath " $arg" ;;
7098994689c1Smrg	    esac
7099e1e1713cSmrg	  fi
7100994689c1Smrg	  prev=
7101994689c1Smrg	  continue
7102994689c1Smrg	  ;;
7103994689c1Smrg	shrext)
71045ec34c4cSmrg	  shrext_cmds=$arg
7105994689c1Smrg	  prev=
7106994689c1Smrg	  continue
7107994689c1Smrg	  ;;
7108994689c1Smrg	weak)
7109f353fbadSmrg	  func_append weak_libs " $arg"
7110994689c1Smrg	  prev=
7111994689c1Smrg	  continue
7112994689c1Smrg	  ;;
71135b16253fSmrg	xassembler)
71145b16253fSmrg	  func_append compiler_flags " -Xassembler $qarg"
71155b16253fSmrg	  prev=
71165b16253fSmrg	  func_append compile_command " -Xassembler $qarg"
71175b16253fSmrg	  func_append finalize_command " -Xassembler $qarg"
71185b16253fSmrg	  continue
71195b16253fSmrg	  ;;
7120994689c1Smrg	xcclinker)
7121f353fbadSmrg	  func_append linker_flags " $qarg"
7122f353fbadSmrg	  func_append compiler_flags " $qarg"
7123994689c1Smrg	  prev=
7124994689c1Smrg	  func_append compile_command " $qarg"
7125994689c1Smrg	  func_append finalize_command " $qarg"
7126994689c1Smrg	  continue
7127994689c1Smrg	  ;;
7128994689c1Smrg	xcompiler)
7129f353fbadSmrg	  func_append compiler_flags " $qarg"
7130994689c1Smrg	  prev=
7131994689c1Smrg	  func_append compile_command " $qarg"
7132994689c1Smrg	  func_append finalize_command " $qarg"
7133994689c1Smrg	  continue
7134994689c1Smrg	  ;;
7135994689c1Smrg	xlinker)
7136f353fbadSmrg	  func_append linker_flags " $qarg"
7137f353fbadSmrg	  func_append compiler_flags " $wl$qarg"
7138994689c1Smrg	  prev=
7139994689c1Smrg	  func_append compile_command " $wl$qarg"
7140994689c1Smrg	  func_append finalize_command " $wl$qarg"
7141994689c1Smrg	  continue
7142994689c1Smrg	  ;;
7143994689c1Smrg	*)
7144994689c1Smrg	  eval "$prev=\"\$arg\""
7145994689c1Smrg	  prev=
7146994689c1Smrg	  continue
7147994689c1Smrg	  ;;
7148775e7de9Smrg	esac
7149994689c1Smrg      fi # test -n "$prev"
7150775e7de9Smrg
71515ec34c4cSmrg      prevarg=$arg
7152775e7de9Smrg
7153994689c1Smrg      case $arg in
7154994689c1Smrg      -all-static)
7155994689c1Smrg	if test -n "$link_static_flag"; then
7156994689c1Smrg	  # See comment for -static flag below, for more details.
7157994689c1Smrg	  func_append compile_command " $link_static_flag"
7158994689c1Smrg	  func_append finalize_command " $link_static_flag"
7159994689c1Smrg	fi
7160994689c1Smrg	continue
7161994689c1Smrg	;;
7162775e7de9Smrg
7163994689c1Smrg      -allow-undefined)
7164994689c1Smrg	# FIXME: remove this flag sometime in the future.
71655ec34c4cSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7166994689c1Smrg	;;
7167775e7de9Smrg
7168994689c1Smrg      -avoid-version)
7169994689c1Smrg	avoid_version=yes
7170994689c1Smrg	continue
7171994689c1Smrg	;;
7172775e7de9Smrg
7173994689c1Smrg      -bindir)
7174994689c1Smrg	prev=bindir
7175994689c1Smrg	continue
7176994689c1Smrg	;;
7177775e7de9Smrg
7178994689c1Smrg      -dlopen)
7179994689c1Smrg	prev=dlfiles
7180994689c1Smrg	continue
7181994689c1Smrg	;;
7182775e7de9Smrg
7183994689c1Smrg      -dlpreopen)
7184994689c1Smrg	prev=dlprefiles
7185994689c1Smrg	continue
7186994689c1Smrg	;;
7187775e7de9Smrg
7188994689c1Smrg      -export-dynamic)
7189994689c1Smrg	export_dynamic=yes
7190994689c1Smrg	continue
7191994689c1Smrg	;;
7192775e7de9Smrg
7193994689c1Smrg      -export-symbols | -export-symbols-regex)
7194994689c1Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7195994689c1Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7196994689c1Smrg	fi
71975ec34c4cSmrg	if test X-export-symbols = "X$arg"; then
7198994689c1Smrg	  prev=expsyms
7199994689c1Smrg	else
7200994689c1Smrg	  prev=expsyms_regex
7201994689c1Smrg	fi
7202994689c1Smrg	continue
7203994689c1Smrg	;;
7204775e7de9Smrg
7205994689c1Smrg      -framework)
7206994689c1Smrg	prev=framework
7207994689c1Smrg	continue
7208994689c1Smrg	;;
7209775e7de9Smrg
7210994689c1Smrg      -inst-prefix-dir)
7211994689c1Smrg	prev=inst_prefix
7212994689c1Smrg	continue
7213994689c1Smrg	;;
7214775e7de9Smrg
7215994689c1Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7216994689c1Smrg      # so, if we see these flags be careful not to treat them like -L
7217994689c1Smrg      -L[A-Z][A-Z]*:*)
7218994689c1Smrg	case $with_gcc/$host in
7219994689c1Smrg	no/*-*-irix* | /*-*-irix*)
7220994689c1Smrg	  func_append compile_command " $arg"
7221994689c1Smrg	  func_append finalize_command " $arg"
7222994689c1Smrg	  ;;
7223994689c1Smrg	esac
7224994689c1Smrg	continue
7225994689c1Smrg	;;
7226775e7de9Smrg
7227994689c1Smrg      -L*)
7228f353fbadSmrg	func_stripname "-L" '' "$arg"
7229f353fbadSmrg	if test -z "$func_stripname_result"; then
7230994689c1Smrg	  if test "$#" -gt 0; then
72315ec34c4cSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7232994689c1Smrg	  else
72335ec34c4cSmrg	    func_fatal_error "need path for '-L' option"
7234994689c1Smrg	  fi
7235994689c1Smrg	fi
7236f353fbadSmrg	func_resolve_sysroot "$func_stripname_result"
7237f353fbadSmrg	dir=$func_resolve_sysroot_result
7238994689c1Smrg	# We need an absolute path.
7239994689c1Smrg	case $dir in
7240994689c1Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7241994689c1Smrg	*)
7242994689c1Smrg	  absdir=`cd "$dir" && pwd`
7243994689c1Smrg	  test -z "$absdir" && \
72445ec34c4cSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
72455ec34c4cSmrg	  dir=$absdir
7246994689c1Smrg	  ;;
7247994689c1Smrg	esac
7248994689c1Smrg	case "$deplibs " in
7249f353fbadSmrg	*" -L$dir "* | *" $arg "*)
7250f353fbadSmrg	  # Will only happen for absolute or sysroot arguments
7251f353fbadSmrg	  ;;
7252994689c1Smrg	*)
7253f353fbadSmrg	  # Preserve sysroot, but never include relative directories
7254f353fbadSmrg	  case $dir in
7255f353fbadSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7256f353fbadSmrg	    *) func_append deplibs " -L$dir" ;;
7257f353fbadSmrg	  esac
7258f353fbadSmrg	  func_append lib_search_path " $dir"
7259994689c1Smrg	  ;;
7260994689c1Smrg	esac
7261994689c1Smrg	case $host in
7262994689c1Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7263994689c1Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7264994689c1Smrg	  case :$dllsearchpath: in
7265994689c1Smrg	  *":$dir:"*) ;;
7266994689c1Smrg	  ::) dllsearchpath=$dir;;
7267f353fbadSmrg	  *) func_append dllsearchpath ":$dir";;
7268994689c1Smrg	  esac
7269994689c1Smrg	  case :$dllsearchpath: in
7270994689c1Smrg	  *":$testbindir:"*) ;;
7271994689c1Smrg	  ::) dllsearchpath=$testbindir;;
7272f353fbadSmrg	  *) func_append dllsearchpath ":$testbindir";;
7273994689c1Smrg	  esac
7274994689c1Smrg	  ;;
7275994689c1Smrg	esac
7276994689c1Smrg	continue
7277994689c1Smrg	;;
7278775e7de9Smrg
7279994689c1Smrg      -l*)
72805ec34c4cSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7281994689c1Smrg	  case $host in
7282994689c1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7283994689c1Smrg	    # These systems don't actually have a C or math library (as such)
7284994689c1Smrg	    continue
7285994689c1Smrg	    ;;
7286994689c1Smrg	  *-*-os2*)
7287994689c1Smrg	    # These systems don't actually have a C library (as such)
72885ec34c4cSmrg	    test X-lc = "X$arg" && continue
7289994689c1Smrg	    ;;
72905b16253fSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7291994689c1Smrg	    # Do not include libc due to us having libc/libc_r.
72925ec34c4cSmrg	    test X-lc = "X$arg" && continue
7293994689c1Smrg	    ;;
7294994689c1Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7295994689c1Smrg	    # Rhapsody C and math libraries are in the System framework
7296f353fbadSmrg	    func_append deplibs " System.ltframework"
7297994689c1Smrg	    continue
7298994689c1Smrg	    ;;
7299994689c1Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7300994689c1Smrg	    # Causes problems with __ctype
73015ec34c4cSmrg	    test X-lc = "X$arg" && continue
7302994689c1Smrg	    ;;
7303994689c1Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7304994689c1Smrg	    # Compiler inserts libc in the correct place for threads to work
73055ec34c4cSmrg	    test X-lc = "X$arg" && continue
7306994689c1Smrg	    ;;
7307994689c1Smrg	  esac
73085ec34c4cSmrg	elif test X-lc_r = "X$arg"; then
7309994689c1Smrg	 case $host in
73105b16253fSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7311994689c1Smrg	   # Do not include libc_r directly, use -pthread flag.
7312994689c1Smrg	   continue
7313994689c1Smrg	   ;;
7314994689c1Smrg	 esac
7315994689c1Smrg	fi
7316f353fbadSmrg	func_append deplibs " $arg"
7317994689c1Smrg	continue
7318994689c1Smrg	;;
7319775e7de9Smrg
73205ec34c4cSmrg      -mllvm)
73215ec34c4cSmrg	prev=mllvm
73225ec34c4cSmrg	continue
73235ec34c4cSmrg	;;
73245ec34c4cSmrg
7325994689c1Smrg      -module)
7326994689c1Smrg	module=yes
7327994689c1Smrg	continue
7328994689c1Smrg	;;
7329775e7de9Smrg
7330994689c1Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7331994689c1Smrg      # classes, name mangling, and exception handling.
7332994689c1Smrg      # Darwin uses the -arch flag to determine output architecture.
7333f353fbadSmrg      -model|-arch|-isysroot|--sysroot)
7334f353fbadSmrg	func_append compiler_flags " $arg"
7335994689c1Smrg	func_append compile_command " $arg"
7336994689c1Smrg	func_append finalize_command " $arg"
7337994689c1Smrg	prev=xcompiler
7338994689c1Smrg	continue
7339994689c1Smrg	;;
73405b16253fSmrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
73415b16253fSmrg     -pthread)
73425b16253fSmrg	case $host in
73435b16253fSmrg	  *solaris2*) ;;
73445b16253fSmrg	  *)
73455b16253fSmrg	    case "$new_inherited_linker_flags " in
73465b16253fSmrg	        *" $arg "*) ;;
73475b16253fSmrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
73485b16253fSmrg	    esac
73495b16253fSmrg	  ;;
73505b16253fSmrg	esac
73515b16253fSmrg	continue
73525b16253fSmrg	;;
73535b16253fSmrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7354421c997bSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7355f353fbadSmrg	func_append compiler_flags " $arg"
7356994689c1Smrg	func_append compile_command " $arg"
7357994689c1Smrg	func_append finalize_command " $arg"
7358994689c1Smrg	case "$new_inherited_linker_flags " in
7359994689c1Smrg	    *" $arg "*) ;;
7360f353fbadSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7361994689c1Smrg	esac
7362994689c1Smrg	continue
7363994689c1Smrg	;;
7364775e7de9Smrg
7365994689c1Smrg      -multi_module)
73665ec34c4cSmrg	single_module=$wl-multi_module
7367994689c1Smrg	continue
7368994689c1Smrg	;;
7369775e7de9Smrg
7370994689c1Smrg      -no-fast-install)
7371994689c1Smrg	fast_install=no
7372994689c1Smrg	continue
7373994689c1Smrg	;;
7374775e7de9Smrg
7375994689c1Smrg      -no-install)
7376994689c1Smrg	case $host in
7377994689c1Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7378994689c1Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7379994689c1Smrg	  # and Darwin in order for the loader to find any dlls it needs.
73805ec34c4cSmrg	  func_warning "'-no-install' is ignored for $host"
73815ec34c4cSmrg	  func_warning "assuming '-no-fast-install' instead"
7382994689c1Smrg	  fast_install=no
7383994689c1Smrg	  ;;
7384994689c1Smrg	*) no_install=yes ;;
7385994689c1Smrg	esac
7386994689c1Smrg	continue
7387994689c1Smrg	;;
7388775e7de9Smrg
7389994689c1Smrg      -no-undefined)
7390994689c1Smrg	allow_undefined=no
7391994689c1Smrg	continue
7392994689c1Smrg	;;
7393775e7de9Smrg
7394994689c1Smrg      -objectlist)
7395994689c1Smrg	prev=objectlist
7396994689c1Smrg	continue
7397994689c1Smrg	;;
7398775e7de9Smrg
73995ec34c4cSmrg      -os2dllname)
74005ec34c4cSmrg	prev=os2dllname
74015ec34c4cSmrg	continue
74025ec34c4cSmrg	;;
74035ec34c4cSmrg
7404994689c1Smrg      -o) prev=output ;;
7405775e7de9Smrg
7406994689c1Smrg      -precious-files-regex)
7407994689c1Smrg	prev=precious_regex
7408994689c1Smrg	continue
7409994689c1Smrg	;;
7410775e7de9Smrg
7411994689c1Smrg      -release)
7412994689c1Smrg	prev=release
7413994689c1Smrg	continue
7414994689c1Smrg	;;
7415775e7de9Smrg
7416994689c1Smrg      -rpath)
7417994689c1Smrg	prev=rpath
7418994689c1Smrg	continue
7419994689c1Smrg	;;
7420775e7de9Smrg
7421994689c1Smrg      -R)
7422994689c1Smrg	prev=xrpath
7423994689c1Smrg	continue
7424994689c1Smrg	;;
7425775e7de9Smrg
7426994689c1Smrg      -R*)
7427994689c1Smrg	func_stripname '-R' '' "$arg"
7428994689c1Smrg	dir=$func_stripname_result
7429994689c1Smrg	# We need an absolute path.
7430994689c1Smrg	case $dir in
7431994689c1Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7432f353fbadSmrg	=*)
7433f353fbadSmrg	  func_stripname '=' '' "$dir"
7434f353fbadSmrg	  dir=$lt_sysroot$func_stripname_result
7435f353fbadSmrg	  ;;
7436994689c1Smrg	*)
7437994689c1Smrg	  func_fatal_error "only absolute run-paths are allowed"
7438994689c1Smrg	  ;;
7439994689c1Smrg	esac
7440994689c1Smrg	case "$xrpath " in
7441994689c1Smrg	*" $dir "*) ;;
7442f353fbadSmrg	*) func_append xrpath " $dir" ;;
7443994689c1Smrg	esac
7444994689c1Smrg	continue
7445994689c1Smrg	;;
7446775e7de9Smrg
7447994689c1Smrg      -shared)
7448994689c1Smrg	# The effects of -shared are defined in a previous loop.
7449994689c1Smrg	continue
7450994689c1Smrg	;;
7451775e7de9Smrg
7452994689c1Smrg      -shrext)
7453994689c1Smrg	prev=shrext
7454994689c1Smrg	continue
7455994689c1Smrg	;;
7456775e7de9Smrg
7457994689c1Smrg      -static | -static-libtool-libs)
7458994689c1Smrg	# The effects of -static are defined in a previous loop.
7459994689c1Smrg	# We used to do the same as -all-static on platforms that
7460994689c1Smrg	# didn't have a PIC flag, but the assumption that the effects
7461994689c1Smrg	# would be equivalent was wrong.  It would break on at least
7462994689c1Smrg	# Digital Unix and AIX.
7463994689c1Smrg	continue
7464994689c1Smrg	;;
7465775e7de9Smrg
7466994689c1Smrg      -thread-safe)
7467994689c1Smrg	thread_safe=yes
7468994689c1Smrg	continue
7469994689c1Smrg	;;
7470775e7de9Smrg
7471994689c1Smrg      -version-info)
7472994689c1Smrg	prev=vinfo
7473994689c1Smrg	continue
7474994689c1Smrg	;;
7475775e7de9Smrg
7476994689c1Smrg      -version-number)
7477994689c1Smrg	prev=vinfo
7478994689c1Smrg	vinfo_number=yes
7479994689c1Smrg	continue
7480994689c1Smrg	;;
74817a84e134Smrg
7482994689c1Smrg      -weak)
7483994689c1Smrg        prev=weak
7484994689c1Smrg	continue
7485994689c1Smrg	;;
7486e1e1713cSmrg
7487994689c1Smrg      -Wc,*)
7488994689c1Smrg	func_stripname '-Wc,' '' "$arg"
7489994689c1Smrg	args=$func_stripname_result
7490994689c1Smrg	arg=
74915ec34c4cSmrg	save_ifs=$IFS; IFS=,
7492994689c1Smrg	for flag in $args; do
74935ec34c4cSmrg	  IFS=$save_ifs
74945b16253fSmrg          func_quote_arg pretty "$flag"
74955b16253fSmrg	  func_append arg " $func_quote_arg_result"
74965b16253fSmrg	  func_append compiler_flags " $func_quote_arg_result"
7497994689c1Smrg	done
74985ec34c4cSmrg	IFS=$save_ifs
7499994689c1Smrg	func_stripname ' ' '' "$arg"
7500994689c1Smrg	arg=$func_stripname_result
7501994689c1Smrg	;;
7502e1e1713cSmrg
7503994689c1Smrg      -Wl,*)
7504994689c1Smrg	func_stripname '-Wl,' '' "$arg"
7505994689c1Smrg	args=$func_stripname_result
7506994689c1Smrg	arg=
75075ec34c4cSmrg	save_ifs=$IFS; IFS=,
7508994689c1Smrg	for flag in $args; do
75095ec34c4cSmrg	  IFS=$save_ifs
75105b16253fSmrg          func_quote_arg pretty "$flag"
75115b16253fSmrg	  func_append arg " $wl$func_quote_arg_result"
75125b16253fSmrg	  func_append compiler_flags " $wl$func_quote_arg_result"
75135b16253fSmrg	  func_append linker_flags " $func_quote_arg_result"
7514994689c1Smrg	done
75155ec34c4cSmrg	IFS=$save_ifs
7516994689c1Smrg	func_stripname ' ' '' "$arg"
7517994689c1Smrg	arg=$func_stripname_result
7518994689c1Smrg	;;
7519e1e1713cSmrg
75205b16253fSmrg      -Xassembler)
75215b16253fSmrg        prev=xassembler
75225b16253fSmrg        continue
75235b16253fSmrg        ;;
75245b16253fSmrg
7525994689c1Smrg      -Xcompiler)
7526994689c1Smrg	prev=xcompiler
7527994689c1Smrg	continue
7528994689c1Smrg	;;
7529e1e1713cSmrg
7530994689c1Smrg      -Xlinker)
7531994689c1Smrg	prev=xlinker
7532994689c1Smrg	continue
7533994689c1Smrg	;;
7534e1e1713cSmrg
7535994689c1Smrg      -XCClinker)
7536994689c1Smrg	prev=xcclinker
7537994689c1Smrg	continue
7538994689c1Smrg	;;
7539e1e1713cSmrg
7540994689c1Smrg      # -msg_* for osf cc
7541994689c1Smrg      -msg_*)
75425b16253fSmrg	func_quote_arg pretty "$arg"
75435b16253fSmrg	arg=$func_quote_arg_result
7544994689c1Smrg	;;
7545e1e1713cSmrg
7546994689c1Smrg      # Flags to be passed through unchanged, with rationale:
7547994689c1Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7548994689c1Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7549994689c1Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7550994689c1Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7551994689c1Smrg      # -q*                  compiler args for the IBM compiler
7552994689c1Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7553994689c1Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7554994689c1Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
75555ec34c4cSmrg      # -fstack-protector*   stack protector flags for GCC
7556994689c1Smrg      # @file                GCC response files
7557994689c1Smrg      # -tp=*                Portland pgcc target processor selection
7558f353fbadSmrg      # --sysroot=*          for sysroot support
75595ec34c4cSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75605ec34c4cSmrg      # -specs=*             GCC specs files
75615ec34c4cSmrg      # -stdlib=*            select c++ std lib with clang
75625ec34c4cSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75635ec34c4cSmrg      # -fuse-ld=*           Linker select flags for GCC
7564efbcb2bfSmrg      # -static-*            direct GCC to link specific libraries statically
7565efbcb2bfSmrg      # -fcilkplus           Cilk Plus language extension features for C/C++
75665b16253fSmrg      # -Wa,*                Pass flags directly to the assembler
7567994689c1Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7568f353fbadSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75695ec34c4cSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7570efbcb2bfSmrg      -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus|-Wa,*)
75715b16253fSmrg        func_quote_arg pretty "$arg"
75725b16253fSmrg	arg=$func_quote_arg_result
7573994689c1Smrg        func_append compile_command " $arg"
7574994689c1Smrg        func_append finalize_command " $arg"
7575f353fbadSmrg        func_append compiler_flags " $arg"
7576994689c1Smrg        continue
7577994689c1Smrg        ;;
7578e1e1713cSmrg
75795ec34c4cSmrg      -Z*)
75805ec34c4cSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
75815ec34c4cSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
75825ec34c4cSmrg	  compiler_flags="$compiler_flags $arg"
75835ec34c4cSmrg	  func_append compile_command " $arg"
75845ec34c4cSmrg	  func_append finalize_command " $arg"
75855ec34c4cSmrg	  case $arg in
75865ec34c4cSmrg	  -Zlinker | -Zstack)
75875ec34c4cSmrg	    prev=xcompiler
75885ec34c4cSmrg	    ;;
75895ec34c4cSmrg	  esac
75905ec34c4cSmrg	  continue
75915ec34c4cSmrg        else
75925ec34c4cSmrg	  # Otherwise treat like 'Some other compiler flag' below
75935b16253fSmrg	  func_quote_arg pretty "$arg"
75945b16253fSmrg	  arg=$func_quote_arg_result
75955ec34c4cSmrg        fi
75965ec34c4cSmrg	;;
75975ec34c4cSmrg
7598994689c1Smrg      # Some other compiler flag.
7599994689c1Smrg      -* | +*)
76005b16253fSmrg        func_quote_arg pretty "$arg"
76015b16253fSmrg	arg=$func_quote_arg_result
7602994689c1Smrg	;;
7603e1e1713cSmrg
7604994689c1Smrg      *.$objext)
7605994689c1Smrg	# A standard object.
7606f353fbadSmrg	func_append objs " $arg"
7607994689c1Smrg	;;
7608e1e1713cSmrg
7609994689c1Smrg      *.lo)
7610994689c1Smrg	# A libtool-controlled object.
7611e1e1713cSmrg
7612994689c1Smrg	# Check to see that this really is a libtool object.
7613994689c1Smrg	if func_lalib_unsafe_p "$arg"; then
7614994689c1Smrg	  pic_object=
7615994689c1Smrg	  non_pic_object=
7616e1e1713cSmrg
7617994689c1Smrg	  # Read the .lo file
7618994689c1Smrg	  func_source "$arg"
7619e1e1713cSmrg
7620994689c1Smrg	  if test -z "$pic_object" ||
7621994689c1Smrg	     test -z "$non_pic_object" ||
76225ec34c4cSmrg	     test none = "$pic_object" &&
76235ec34c4cSmrg	     test none = "$non_pic_object"; then
76245ec34c4cSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7625994689c1Smrg	  fi
7626e1e1713cSmrg
7627994689c1Smrg	  # Extract subdirectory from the argument.
7628994689c1Smrg	  func_dirname "$arg" "/" ""
76295ec34c4cSmrg	  xdir=$func_dirname_result
7630e1e1713cSmrg
76315ec34c4cSmrg	  test none = "$pic_object" || {
7632994689c1Smrg	    # Prepend the subdirectory the object is found in.
76335ec34c4cSmrg	    pic_object=$xdir$pic_object
7634e1e1713cSmrg
76355ec34c4cSmrg	    if test dlfiles = "$prev"; then
76365ec34c4cSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7637f353fbadSmrg		func_append dlfiles " $pic_object"
7638994689c1Smrg		prev=
7639994689c1Smrg		continue
7640994689c1Smrg	      else
7641994689c1Smrg		# If libtool objects are unsupported, then we need to preload.
7642994689c1Smrg		prev=dlprefiles
7643994689c1Smrg	      fi
7644994689c1Smrg	    fi
7645994689c1Smrg
7646994689c1Smrg	    # CHECK ME:  I think I busted this.  -Ossama
76475ec34c4cSmrg	    if test dlprefiles = "$prev"; then
7648994689c1Smrg	      # Preload the old-style object.
7649f353fbadSmrg	      func_append dlprefiles " $pic_object"
7650994689c1Smrg	      prev=
7651994689c1Smrg	    fi
7652994689c1Smrg
7653994689c1Smrg	    # A PIC object.
7654994689c1Smrg	    func_append libobjs " $pic_object"
76555ec34c4cSmrg	    arg=$pic_object
76565ec34c4cSmrg	  }
7657994689c1Smrg
7658994689c1Smrg	  # Non-PIC object.
76595ec34c4cSmrg	  if test none != "$non_pic_object"; then
7660994689c1Smrg	    # Prepend the subdirectory the object is found in.
76615ec34c4cSmrg	    non_pic_object=$xdir$non_pic_object
7662994689c1Smrg
7663994689c1Smrg	    # A standard non-PIC object
7664994689c1Smrg	    func_append non_pic_objects " $non_pic_object"
76655ec34c4cSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
76665ec34c4cSmrg	      arg=$non_pic_object
7667994689c1Smrg	    fi
7668994689c1Smrg	  else
7669994689c1Smrg	    # If the PIC object exists, use it instead.
7670994689c1Smrg	    # $xdir was prepended to $pic_object above.
76715ec34c4cSmrg	    non_pic_object=$pic_object
7672994689c1Smrg	    func_append non_pic_objects " $non_pic_object"
7673994689c1Smrg	  fi
7674994689c1Smrg	else
7675994689c1Smrg	  # Only an error if not doing a dry-run.
7676994689c1Smrg	  if $opt_dry_run; then
7677994689c1Smrg	    # Extract subdirectory from the argument.
7678994689c1Smrg	    func_dirname "$arg" "/" ""
76795ec34c4cSmrg	    xdir=$func_dirname_result
7680994689c1Smrg
7681994689c1Smrg	    func_lo2o "$arg"
7682994689c1Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7683994689c1Smrg	    non_pic_object=$xdir$func_lo2o_result
7684994689c1Smrg	    func_append libobjs " $pic_object"
7685994689c1Smrg	    func_append non_pic_objects " $non_pic_object"
7686994689c1Smrg	  else
76875ec34c4cSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7688994689c1Smrg	  fi
7689994689c1Smrg	fi
7690994689c1Smrg	;;
7691994689c1Smrg
7692994689c1Smrg      *.$libext)
7693994689c1Smrg	# An archive.
7694f353fbadSmrg	func_append deplibs " $arg"
7695f353fbadSmrg	func_append old_deplibs " $arg"
7696994689c1Smrg	continue
7697994689c1Smrg	;;
7698994689c1Smrg
7699994689c1Smrg      *.la)
7700994689c1Smrg	# A libtool-controlled library.
7701994689c1Smrg
7702f353fbadSmrg	func_resolve_sysroot "$arg"
77035ec34c4cSmrg	if test dlfiles = "$prev"; then
7704994689c1Smrg	  # This library was specified with -dlopen.
7705f353fbadSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7706994689c1Smrg	  prev=
77075ec34c4cSmrg	elif test dlprefiles = "$prev"; then
7708994689c1Smrg	  # The library was specified with -dlpreopen.
7709f353fbadSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7710994689c1Smrg	  prev=
7711994689c1Smrg	else
7712f353fbadSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7713994689c1Smrg	fi
7714994689c1Smrg	continue
7715994689c1Smrg	;;
7716994689c1Smrg
7717994689c1Smrg      # Some other compiler argument.
7718994689c1Smrg      *)
7719994689c1Smrg	# Unknown arguments in both finalize_command and compile_command need
7720994689c1Smrg	# to be aesthetically quoted because they are evaled later.
77215b16253fSmrg	func_quote_arg pretty "$arg"
77225b16253fSmrg	arg=$func_quote_arg_result
7723994689c1Smrg	;;
7724994689c1Smrg      esac # arg
7725994689c1Smrg
7726994689c1Smrg      # Now actually substitute the argument into the commands.
7727994689c1Smrg      if test -n "$arg"; then
7728994689c1Smrg	func_append compile_command " $arg"
7729994689c1Smrg	func_append finalize_command " $arg"
7730994689c1Smrg      fi
7731994689c1Smrg    done # argument parsing loop
7732994689c1Smrg
7733994689c1Smrg    test -n "$prev" && \
77345ec34c4cSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7735994689c1Smrg
77365ec34c4cSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7737994689c1Smrg      eval arg=\"$export_dynamic_flag_spec\"
7738994689c1Smrg      func_append compile_command " $arg"
7739994689c1Smrg      func_append finalize_command " $arg"
7740994689c1Smrg    fi
7741994689c1Smrg
7742994689c1Smrg    oldlibs=
7743994689c1Smrg    # calculate the name of the file, without its directory
7744994689c1Smrg    func_basename "$output"
77455ec34c4cSmrg    outputname=$func_basename_result
77465ec34c4cSmrg    libobjs_save=$libobjs
7747994689c1Smrg
7748994689c1Smrg    if test -n "$shlibpath_var"; then
7749994689c1Smrg      # get the directories listed in $shlibpath_var
77505ec34c4cSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7751e1e1713cSmrg    else
7752994689c1Smrg      shlib_search_path=
7753e1e1713cSmrg    fi
7754994689c1Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7755994689c1Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
77567a84e134Smrg
77575ec34c4cSmrg    # Definition is injected by LT_CONFIG during libtool generation.
77585ec34c4cSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
77595ec34c4cSmrg
7760994689c1Smrg    func_dirname "$output" "/" ""
77615ec34c4cSmrg    output_objdir=$func_dirname_result$objdir
7762f353fbadSmrg    func_to_tool_file "$output_objdir/"
7763f353fbadSmrg    tool_output_objdir=$func_to_tool_file_result
7764994689c1Smrg    # Create the object directory.
7765994689c1Smrg    func_mkdir_p "$output_objdir"
77667a84e134Smrg
7767994689c1Smrg    # Determine the type of output
7768994689c1Smrg    case $output in
7769994689c1Smrg    "")
7770994689c1Smrg      func_fatal_help "you must specify an output file"
7771994689c1Smrg      ;;
7772994689c1Smrg    *.$libext) linkmode=oldlib ;;
7773994689c1Smrg    *.lo | *.$objext) linkmode=obj ;;
7774994689c1Smrg    *.la) linkmode=lib ;;
7775994689c1Smrg    *) linkmode=prog ;; # Anything else should be a program.
7776994689c1Smrg    esac
7777994689c1Smrg
7778994689c1Smrg    specialdeplibs=
7779994689c1Smrg
7780994689c1Smrg    libs=
7781994689c1Smrg    # Find all interdependent deplibs by searching for libraries
7782994689c1Smrg    # that are linked more than once (e.g. -la -lb -la)
7783994689c1Smrg    for deplib in $deplibs; do
77845ec34c4cSmrg      if $opt_preserve_dup_deps; then
7785994689c1Smrg	case "$libs " in
7786f353fbadSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7787994689c1Smrg	esac
7788994689c1Smrg      fi
7789f353fbadSmrg      func_append libs " $deplib"
7790994689c1Smrg    done
7791994689c1Smrg
77925ec34c4cSmrg    if test lib = "$linkmode"; then
7793994689c1Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7794994689c1Smrg
7795994689c1Smrg      # Compute libraries that are listed more than once in $predeps
7796994689c1Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7797994689c1Smrg      # not to be eliminated).
7798994689c1Smrg      pre_post_deps=
7799994689c1Smrg      if $opt_duplicate_compiler_generated_deps; then
7800994689c1Smrg	for pre_post_dep in $predeps $postdeps; do
7801994689c1Smrg	  case "$pre_post_deps " in
7802f353fbadSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7803994689c1Smrg	  esac
7804f353fbadSmrg	  func_append pre_post_deps " $pre_post_dep"
7805994689c1Smrg	done
7806994689c1Smrg      fi
7807994689c1Smrg      pre_post_deps=
7808994689c1Smrg    fi
7809994689c1Smrg
7810994689c1Smrg    deplibs=
7811994689c1Smrg    newdependency_libs=
7812994689c1Smrg    newlib_search_path=
7813994689c1Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7814994689c1Smrg    notinst_deplibs= # not-installed libtool libraries
7815994689c1Smrg    notinst_path= # paths that contain not-installed libtool libraries
7816994689c1Smrg
7817994689c1Smrg    case $linkmode in
7818994689c1Smrg    lib)
7819994689c1Smrg	passes="conv dlpreopen link"
7820994689c1Smrg	for file in $dlfiles $dlprefiles; do
7821994689c1Smrg	  case $file in
7822994689c1Smrg	  *.la) ;;
7823994689c1Smrg	  *)
78245ec34c4cSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7825994689c1Smrg	    ;;
7826994689c1Smrg	  esac
7827994689c1Smrg	done
7828994689c1Smrg	;;
7829994689c1Smrg    prog)
7830994689c1Smrg	compile_deplibs=
7831994689c1Smrg	finalize_deplibs=
78325ec34c4cSmrg	alldeplibs=false
7833994689c1Smrg	newdlfiles=
7834994689c1Smrg	newdlprefiles=
7835994689c1Smrg	passes="conv scan dlopen dlpreopen link"
7836994689c1Smrg	;;
7837994689c1Smrg    *)  passes="conv"
7838994689c1Smrg	;;
7839994689c1Smrg    esac
7840994689c1Smrg
7841994689c1Smrg    for pass in $passes; do
7842994689c1Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7843994689c1Smrg      # so that -L comes before libs that need it for instance...
78445ec34c4cSmrg      if test lib,link = "$linkmode,$pass"; then
7845994689c1Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7846994689c1Smrg	##        order, and fix it there properly
7847994689c1Smrg        tmp_deplibs=
7848994689c1Smrg	for deplib in $deplibs; do
7849994689c1Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7850994689c1Smrg	done
78515ec34c4cSmrg	deplibs=$tmp_deplibs
7852994689c1Smrg      fi
7853994689c1Smrg
78545ec34c4cSmrg      if test lib,link = "$linkmode,$pass" ||
78555ec34c4cSmrg	 test prog,scan = "$linkmode,$pass"; then
78565ec34c4cSmrg	libs=$deplibs
7857994689c1Smrg	deplibs=
7858994689c1Smrg      fi
78595ec34c4cSmrg      if test prog = "$linkmode"; then
7860994689c1Smrg	case $pass in
78615ec34c4cSmrg	dlopen) libs=$dlfiles ;;
78625ec34c4cSmrg	dlpreopen) libs=$dlprefiles ;;
7863efbcb2bfSmrg	link)
7864efbcb2bfSmrg	  libs="$deplibs %DEPLIBS%"
7865efbcb2bfSmrg	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
7866efbcb2bfSmrg	  ;;
7867994689c1Smrg	esac
7868994689c1Smrg      fi
78695ec34c4cSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7870994689c1Smrg	# Collect and forward deplibs of preopened libtool libs
7871994689c1Smrg	for lib in $dlprefiles; do
7872994689c1Smrg	  # Ignore non-libtool-libs
7873994689c1Smrg	  dependency_libs=
7874f353fbadSmrg	  func_resolve_sysroot "$lib"
7875994689c1Smrg	  case $lib in
7876f353fbadSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7877994689c1Smrg	  esac
7878994689c1Smrg
7879994689c1Smrg	  # Collect preopened libtool deplibs, except any this library
7880994689c1Smrg	  # has declared as weak libs
7881994689c1Smrg	  for deplib in $dependency_libs; do
7882994689c1Smrg	    func_basename "$deplib"
7883994689c1Smrg            deplib_base=$func_basename_result
7884994689c1Smrg	    case " $weak_libs " in
7885994689c1Smrg	    *" $deplib_base "*) ;;
7886f353fbadSmrg	    *) func_append deplibs " $deplib" ;;
7887994689c1Smrg	    esac
7888994689c1Smrg	  done
7889994689c1Smrg	done
78905ec34c4cSmrg	libs=$dlprefiles
7891994689c1Smrg      fi
78925ec34c4cSmrg      if test dlopen = "$pass"; then
7893994689c1Smrg	# Collect dlpreopened libraries
78945ec34c4cSmrg	save_deplibs=$deplibs
7895994689c1Smrg	deplibs=
7896994689c1Smrg      fi
7897994689c1Smrg
7898994689c1Smrg      for deplib in $libs; do
7899994689c1Smrg	lib=
79005ec34c4cSmrg	found=false
7901994689c1Smrg	case $deplib in
7902421c997bSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7903421c997bSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
79045ec34c4cSmrg	  if test prog,link = "$linkmode,$pass"; then
7905994689c1Smrg	    compile_deplibs="$deplib $compile_deplibs"
7906994689c1Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7907994689c1Smrg	  else
7908f353fbadSmrg	    func_append compiler_flags " $deplib"
79095ec34c4cSmrg	    if test lib = "$linkmode"; then
7910994689c1Smrg		case "$new_inherited_linker_flags " in
7911994689c1Smrg		    *" $deplib "*) ;;
7912f353fbadSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7913994689c1Smrg		esac
7914994689c1Smrg	    fi
7915994689c1Smrg	  fi
7916994689c1Smrg	  continue
7917994689c1Smrg	  ;;
7918994689c1Smrg	-l*)
79195ec34c4cSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
79205ec34c4cSmrg	    func_warning "'-l' is ignored for archives/objects"
7921994689c1Smrg	    continue
7922994689c1Smrg	  fi
7923994689c1Smrg	  func_stripname '-l' '' "$deplib"
7924994689c1Smrg	  name=$func_stripname_result
79255ec34c4cSmrg	  if test lib = "$linkmode"; then
7926994689c1Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7927994689c1Smrg	  else
7928994689c1Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7929994689c1Smrg	  fi
7930994689c1Smrg	  for searchdir in $searchdirs; do
7931994689c1Smrg	    for search_ext in .la $std_shrext .so .a; do
7932994689c1Smrg	      # Search the libtool library
79335ec34c4cSmrg	      lib=$searchdir/lib$name$search_ext
7934994689c1Smrg	      if test -f "$lib"; then
79355ec34c4cSmrg		if test .la = "$search_ext"; then
79365ec34c4cSmrg		  found=:
7937994689c1Smrg		else
79385ec34c4cSmrg		  found=false
7939994689c1Smrg		fi
7940994689c1Smrg		break 2
7941994689c1Smrg	      fi
7942994689c1Smrg	    done
7943994689c1Smrg	  done
79445ec34c4cSmrg	  if $found; then
79455ec34c4cSmrg	    # deplib is a libtool library
7946994689c1Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7947994689c1Smrg	    # We need to do some special things here, and not later.
79485ec34c4cSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7949994689c1Smrg	      case " $predeps $postdeps " in
7950994689c1Smrg	      *" $deplib "*)
7951994689c1Smrg		if func_lalib_p "$lib"; then
7952994689c1Smrg		  library_names=
7953994689c1Smrg		  old_library=
7954994689c1Smrg		  func_source "$lib"
7955994689c1Smrg		  for l in $old_library $library_names; do
79565ec34c4cSmrg		    ll=$l
7957994689c1Smrg		  done
79585ec34c4cSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
79595ec34c4cSmrg		    found=false
7960994689c1Smrg		    func_dirname "$lib" "" "."
79615ec34c4cSmrg		    ladir=$func_dirname_result
7962994689c1Smrg		    lib=$ladir/$old_library
79635ec34c4cSmrg		    if test prog,link = "$linkmode,$pass"; then
7964994689c1Smrg		      compile_deplibs="$deplib $compile_deplibs"
7965994689c1Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7966994689c1Smrg		    else
7967994689c1Smrg		      deplibs="$deplib $deplibs"
79685ec34c4cSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7969994689c1Smrg		    fi
7970994689c1Smrg		    continue
7971994689c1Smrg		  fi
7972994689c1Smrg		fi
7973994689c1Smrg		;;
7974994689c1Smrg	      *) ;;
7975994689c1Smrg	      esac
7976994689c1Smrg	    fi
79775ec34c4cSmrg	  else
79785ec34c4cSmrg	    # deplib doesn't seem to be a libtool library
79795ec34c4cSmrg	    if test prog,link = "$linkmode,$pass"; then
79805ec34c4cSmrg	      compile_deplibs="$deplib $compile_deplibs"
79815ec34c4cSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
79825ec34c4cSmrg	    else
79835ec34c4cSmrg	      deplibs="$deplib $deplibs"
79845ec34c4cSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79855ec34c4cSmrg	    fi
79865ec34c4cSmrg	    continue
7987994689c1Smrg	  fi
7988994689c1Smrg	  ;; # -l
7989994689c1Smrg	*.ltframework)
79905ec34c4cSmrg	  if test prog,link = "$linkmode,$pass"; then
7991994689c1Smrg	    compile_deplibs="$deplib $compile_deplibs"
7992994689c1Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7993994689c1Smrg	  else
7994994689c1Smrg	    deplibs="$deplib $deplibs"
79955ec34c4cSmrg	    if test lib = "$linkmode"; then
7996994689c1Smrg		case "$new_inherited_linker_flags " in
7997994689c1Smrg		    *" $deplib "*) ;;
7998f353fbadSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7999994689c1Smrg		esac
8000994689c1Smrg	    fi
8001994689c1Smrg	  fi
8002994689c1Smrg	  continue
8003994689c1Smrg	  ;;
8004994689c1Smrg	-L*)
8005994689c1Smrg	  case $linkmode in
8006994689c1Smrg	  lib)
8007994689c1Smrg	    deplibs="$deplib $deplibs"
80085ec34c4cSmrg	    test conv = "$pass" && continue
8009994689c1Smrg	    newdependency_libs="$deplib $newdependency_libs"
8010994689c1Smrg	    func_stripname '-L' '' "$deplib"
8011f353fbadSmrg	    func_resolve_sysroot "$func_stripname_result"
8012f353fbadSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8013994689c1Smrg	    ;;
8014994689c1Smrg	  prog)
80155ec34c4cSmrg	    if test conv = "$pass"; then
8016994689c1Smrg	      deplibs="$deplib $deplibs"
8017994689c1Smrg	      continue
8018994689c1Smrg	    fi
80195ec34c4cSmrg	    if test scan = "$pass"; then
8020994689c1Smrg	      deplibs="$deplib $deplibs"
8021994689c1Smrg	    else
8022994689c1Smrg	      compile_deplibs="$deplib $compile_deplibs"
8023994689c1Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8024994689c1Smrg	    fi
8025994689c1Smrg	    func_stripname '-L' '' "$deplib"
8026f353fbadSmrg	    func_resolve_sysroot "$func_stripname_result"
8027f353fbadSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8028994689c1Smrg	    ;;
8029994689c1Smrg	  *)
80305ec34c4cSmrg	    func_warning "'-L' is ignored for archives/objects"
8031994689c1Smrg	    ;;
8032994689c1Smrg	  esac # linkmode
8033994689c1Smrg	  continue
8034994689c1Smrg	  ;; # -L
8035994689c1Smrg	-R*)
80365ec34c4cSmrg	  if test link = "$pass"; then
8037994689c1Smrg	    func_stripname '-R' '' "$deplib"
8038f353fbadSmrg	    func_resolve_sysroot "$func_stripname_result"
8039f353fbadSmrg	    dir=$func_resolve_sysroot_result
8040994689c1Smrg	    # Make sure the xrpath contains only unique directories.
8041994689c1Smrg	    case "$xrpath " in
8042994689c1Smrg	    *" $dir "*) ;;
8043f353fbadSmrg	    *) func_append xrpath " $dir" ;;
8044994689c1Smrg	    esac
8045994689c1Smrg	  fi
8046994689c1Smrg	  deplibs="$deplib $deplibs"
8047994689c1Smrg	  continue
8048994689c1Smrg	  ;;
8049f353fbadSmrg	*.la)
8050f353fbadSmrg	  func_resolve_sysroot "$deplib"
8051f353fbadSmrg	  lib=$func_resolve_sysroot_result
8052f353fbadSmrg	  ;;
8053994689c1Smrg	*.$libext)
80545ec34c4cSmrg	  if test conv = "$pass"; then
8055994689c1Smrg	    deplibs="$deplib $deplibs"
8056994689c1Smrg	    continue
8057994689c1Smrg	  fi
8058994689c1Smrg	  case $linkmode in
8059994689c1Smrg	  lib)
8060994689c1Smrg	    # Linking convenience modules into shared libraries is allowed,
8061994689c1Smrg	    # but linking other static libraries is non-portable.
8062994689c1Smrg	    case " $dlpreconveniencelibs " in
8063994689c1Smrg	    *" $deplib "*) ;;
8064994689c1Smrg	    *)
80655ec34c4cSmrg	      valid_a_lib=false
8066994689c1Smrg	      case $deplibs_check_method in
8067994689c1Smrg		match_pattern*)
8068994689c1Smrg		  set dummy $deplibs_check_method; shift
8069994689c1Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8070994689c1Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8071994689c1Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
80725ec34c4cSmrg		    valid_a_lib=:
8073994689c1Smrg		  fi
8074994689c1Smrg		;;
8075994689c1Smrg		pass_all)
80765ec34c4cSmrg		  valid_a_lib=:
8077994689c1Smrg		;;
8078994689c1Smrg	      esac
80795ec34c4cSmrg	      if $valid_a_lib; then
80805ec34c4cSmrg		echo
80815ec34c4cSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
80825ec34c4cSmrg		$ECHO "*** static library $deplib is not portable!"
80835ec34c4cSmrg		deplibs="$deplib $deplibs"
80845ec34c4cSmrg	      else
8085994689c1Smrg		echo
8086994689c1Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8087994689c1Smrg		echo "*** I have the capability to make that library automatically link in when"
8088994689c1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
8089994689c1Smrg		echo "*** shared version of the library, which you do not appear to have"
8090994689c1Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8091994689c1Smrg		echo "*** that it is just a static archive that I should not use here."
8092994689c1Smrg	      fi
8093994689c1Smrg	      ;;
8094994689c1Smrg	    esac
8095994689c1Smrg	    continue
8096994689c1Smrg	    ;;
8097994689c1Smrg	  prog)
80985ec34c4cSmrg	    if test link != "$pass"; then
8099994689c1Smrg	      deplibs="$deplib $deplibs"
8100994689c1Smrg	    else
8101994689c1Smrg	      compile_deplibs="$deplib $compile_deplibs"
8102994689c1Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8103994689c1Smrg	    fi
8104994689c1Smrg	    continue
8105994689c1Smrg	    ;;
8106994689c1Smrg	  esac # linkmode
8107994689c1Smrg	  ;; # *.$libext
8108994689c1Smrg	*.lo | *.$objext)
81095ec34c4cSmrg	  if test conv = "$pass"; then
8110994689c1Smrg	    deplibs="$deplib $deplibs"
81115ec34c4cSmrg	  elif test prog = "$linkmode"; then
81125ec34c4cSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8113994689c1Smrg	      # If there is no dlopen support or we're linking statically,
8114994689c1Smrg	      # we need to preload.
8115f353fbadSmrg	      func_append newdlprefiles " $deplib"
8116994689c1Smrg	      compile_deplibs="$deplib $compile_deplibs"
8117994689c1Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8118994689c1Smrg	    else
8119f353fbadSmrg	      func_append newdlfiles " $deplib"
8120994689c1Smrg	    fi
8121994689c1Smrg	  fi
8122994689c1Smrg	  continue
8123994689c1Smrg	  ;;
8124994689c1Smrg	%DEPLIBS%)
81255ec34c4cSmrg	  alldeplibs=:
8126994689c1Smrg	  continue
8127994689c1Smrg	  ;;
8128994689c1Smrg	esac # case $deplib
8129994689c1Smrg
81305ec34c4cSmrg	$found || test -f "$lib" \
81315ec34c4cSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8132994689c1Smrg
8133994689c1Smrg	# Check to see that this really is a libtool archive.
8134994689c1Smrg	func_lalib_unsafe_p "$lib" \
81355ec34c4cSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8136994689c1Smrg
8137994689c1Smrg	func_dirname "$lib" "" "."
81385ec34c4cSmrg	ladir=$func_dirname_result
8139994689c1Smrg
8140994689c1Smrg	dlname=
8141994689c1Smrg	dlopen=
8142994689c1Smrg	dlpreopen=
8143994689c1Smrg	libdir=
8144994689c1Smrg	library_names=
8145994689c1Smrg	old_library=
8146994689c1Smrg	inherited_linker_flags=
8147994689c1Smrg	# If the library was installed with an old release of libtool,
8148994689c1Smrg	# it will not redefine variables installed, or shouldnotlink
8149994689c1Smrg	installed=yes
8150994689c1Smrg	shouldnotlink=no
8151994689c1Smrg	avoidtemprpath=
8152994689c1Smrg
8153994689c1Smrg
8154994689c1Smrg	# Read the .la file
8155994689c1Smrg	func_source "$lib"
8156994689c1Smrg
8157994689c1Smrg	# Convert "-framework foo" to "foo.ltframework"
8158994689c1Smrg	if test -n "$inherited_linker_flags"; then
8159994689c1Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8160994689c1Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8161994689c1Smrg	    case " $new_inherited_linker_flags " in
8162994689c1Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8163f353fbadSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8164994689c1Smrg	    esac
8165994689c1Smrg	  done
8166994689c1Smrg	fi
8167994689c1Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
81685ec34c4cSmrg	if test lib,link = "$linkmode,$pass" ||
81695ec34c4cSmrg	   test prog,scan = "$linkmode,$pass" ||
81705ec34c4cSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8171f353fbadSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8172f353fbadSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8173994689c1Smrg	fi
8174994689c1Smrg
81755ec34c4cSmrg	if test conv = "$pass"; then
8176994689c1Smrg	  # Only check for convenience libraries
8177994689c1Smrg	  deplibs="$lib $deplibs"
8178994689c1Smrg	  if test -z "$libdir"; then
8179994689c1Smrg	    if test -z "$old_library"; then
81805ec34c4cSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8181994689c1Smrg	    fi
8182994689c1Smrg	    # It is a libtool convenience library, so add in its objects.
8183f353fbadSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8184f353fbadSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8185efbcb2bfSmrg	    tmp_libs=
8186efbcb2bfSmrg	    for deplib in $dependency_libs; do
8187efbcb2bfSmrg	      deplibs="$deplib $deplibs"
8188efbcb2bfSmrg	      if $opt_preserve_dup_deps; then
8189efbcb2bfSmrg		case "$tmp_libs " in
8190efbcb2bfSmrg		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
8191efbcb2bfSmrg		esac
8192efbcb2bfSmrg	      fi
8193efbcb2bfSmrg	      func_append tmp_libs " $deplib"
8194efbcb2bfSmrg	    done
81955ec34c4cSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
81965ec34c4cSmrg	    func_fatal_error "'$lib' is not a convenience library"
8197994689c1Smrg	  fi
8198994689c1Smrg	  continue
8199994689c1Smrg	fi # $pass = conv
8200994689c1Smrg
8201994689c1Smrg
8202994689c1Smrg	# Get the name of the library we link against.
8203994689c1Smrg	linklib=
8204f353fbadSmrg	if test -n "$old_library" &&
82055ec34c4cSmrg	   { test yes = "$prefer_static_libs" ||
82065ec34c4cSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8207f353fbadSmrg	  linklib=$old_library
8208f353fbadSmrg	else
8209f353fbadSmrg	  for l in $old_library $library_names; do
82105ec34c4cSmrg	    linklib=$l
8211f353fbadSmrg	  done
8212f353fbadSmrg	fi
8213994689c1Smrg	if test -z "$linklib"; then
82145ec34c4cSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8215994689c1Smrg	fi
8216994689c1Smrg
8217994689c1Smrg	# This library was specified with -dlopen.
82185ec34c4cSmrg	if test dlopen = "$pass"; then
82195ec34c4cSmrg	  test -z "$libdir" \
82205ec34c4cSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8221994689c1Smrg	  if test -z "$dlname" ||
82225ec34c4cSmrg	     test yes != "$dlopen_support" ||
82235ec34c4cSmrg	     test no = "$build_libtool_libs"
82245ec34c4cSmrg	  then
8225994689c1Smrg	    # If there is no dlname, no dlopen support or we're linking
8226994689c1Smrg	    # statically, we need to preload.  We also need to preload any
8227994689c1Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8228994689c1Smrg	    # bomb out in the load deplibs phase.
8229f353fbadSmrg	    func_append dlprefiles " $lib $dependency_libs"
8230994689c1Smrg	  else
8231f353fbadSmrg	    func_append newdlfiles " $lib"
8232994689c1Smrg	  fi
8233994689c1Smrg	  continue
8234994689c1Smrg	fi # $pass = dlopen
8235994689c1Smrg
8236994689c1Smrg	# We need an absolute path.
8237994689c1Smrg	case $ladir in
82385ec34c4cSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8239994689c1Smrg	*)
8240994689c1Smrg	  abs_ladir=`cd "$ladir" && pwd`
8241994689c1Smrg	  if test -z "$abs_ladir"; then
82425ec34c4cSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8243994689c1Smrg	    func_warning "passing it literally to the linker, although it might fail"
82445ec34c4cSmrg	    abs_ladir=$ladir
8245994689c1Smrg	  fi
8246994689c1Smrg	  ;;
8247994689c1Smrg	esac
8248994689c1Smrg	func_basename "$lib"
82495ec34c4cSmrg	laname=$func_basename_result
8250994689c1Smrg
8251994689c1Smrg	# Find the relevant object directory and library name.
82525ec34c4cSmrg	if test yes = "$installed"; then
8253f353fbadSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82545ec34c4cSmrg	    func_warning "library '$lib' was moved."
82555ec34c4cSmrg	    dir=$ladir
82565ec34c4cSmrg	    absdir=$abs_ladir
82575ec34c4cSmrg	    libdir=$abs_ladir
8258994689c1Smrg	  else
82595ec34c4cSmrg	    dir=$lt_sysroot$libdir
82605ec34c4cSmrg	    absdir=$lt_sysroot$libdir
8261994689c1Smrg	  fi
82625ec34c4cSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8263994689c1Smrg	else
8264994689c1Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82655ec34c4cSmrg	    dir=$ladir
82665ec34c4cSmrg	    absdir=$abs_ladir
8267994689c1Smrg	    # Remove this search path later
8268f353fbadSmrg	    func_append notinst_path " $abs_ladir"
8269994689c1Smrg	  else
82705ec34c4cSmrg	    dir=$ladir/$objdir
82715ec34c4cSmrg	    absdir=$abs_ladir/$objdir
8272994689c1Smrg	    # Remove this search path later
8273f353fbadSmrg	    func_append notinst_path " $abs_ladir"
8274994689c1Smrg	  fi
8275994689c1Smrg	fi # $installed = yes
8276994689c1Smrg	func_stripname 'lib' '.la' "$laname"
8277994689c1Smrg	name=$func_stripname_result
8278994689c1Smrg
8279994689c1Smrg	# This library was specified with -dlpreopen.
82805ec34c4cSmrg	if test dlpreopen = "$pass"; then
82815ec34c4cSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
82825ec34c4cSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8283994689c1Smrg	  fi
82845ec34c4cSmrg	  case $host in
8285f353fbadSmrg	    # special handling for platforms with PE-DLLs.
8286f353fbadSmrg	    *cygwin* | *mingw* | *cegcc* )
8287f353fbadSmrg	      # Linker will automatically link against shared library if both
8288f353fbadSmrg	      # static and shared are present.  Therefore, ensure we extract
8289f353fbadSmrg	      # symbols from the import library if a shared library is present
8290f353fbadSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8291f353fbadSmrg	      # this by putting the import library name into $newdlprefiles.
8292f353fbadSmrg	      # We recover the dlopen module name by 'saving' the la file
8293f353fbadSmrg	      # name in a special purpose variable, and (later) extracting the
8294f353fbadSmrg	      # dlname from the la file.
8295f353fbadSmrg	      if test -n "$dlname"; then
8296f353fbadSmrg	        func_tr_sh "$dir/$linklib"
8297f353fbadSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8298f353fbadSmrg	        func_append newdlprefiles " $dir/$linklib"
8299f353fbadSmrg	      else
8300f353fbadSmrg	        func_append newdlprefiles " $dir/$old_library"
8301f353fbadSmrg	        # Keep a list of preopened convenience libraries to check
8302f353fbadSmrg	        # that they are being used correctly in the link pass.
8303f353fbadSmrg	        test -z "$libdir" && \
8304f353fbadSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8305f353fbadSmrg	      fi
8306f353fbadSmrg	    ;;
8307f353fbadSmrg	    * )
8308f353fbadSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8309f353fbadSmrg	      # are required to link).
8310f353fbadSmrg	      if test -n "$old_library"; then
8311f353fbadSmrg	        func_append newdlprefiles " $dir/$old_library"
8312f353fbadSmrg	        # Keep a list of preopened convenience libraries to check
8313f353fbadSmrg	        # that they are being used correctly in the link pass.
8314f353fbadSmrg	        test -z "$libdir" && \
8315f353fbadSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8316f353fbadSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8317f353fbadSmrg	      elif test -n "$dlname"; then
8318f353fbadSmrg	        func_append newdlprefiles " $dir/$dlname"
8319f353fbadSmrg	      else
8320f353fbadSmrg	        func_append newdlprefiles " $dir/$linklib"
8321f353fbadSmrg	      fi
8322f353fbadSmrg	    ;;
8323f353fbadSmrg	  esac
8324994689c1Smrg	fi # $pass = dlpreopen
8325994689c1Smrg
8326994689c1Smrg	if test -z "$libdir"; then
8327994689c1Smrg	  # Link the convenience library
83285ec34c4cSmrg	  if test lib = "$linkmode"; then
8329994689c1Smrg	    deplibs="$dir/$old_library $deplibs"
83305ec34c4cSmrg	  elif test prog,link = "$linkmode,$pass"; then
8331994689c1Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8332994689c1Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8333994689c1Smrg	  else
8334994689c1Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8335994689c1Smrg	  fi
8336994689c1Smrg	  continue
8337994689c1Smrg	fi
8338994689c1Smrg
8339994689c1Smrg
83405ec34c4cSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8341f353fbadSmrg	  func_append newlib_search_path " $ladir"
8342994689c1Smrg	  deplibs="$lib $deplibs"
8343994689c1Smrg
83445ec34c4cSmrg	  linkalldeplibs=false
83455ec34c4cSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
83465ec34c4cSmrg	     test no = "$build_libtool_libs"; then
83475ec34c4cSmrg	    linkalldeplibs=:
8348994689c1Smrg	  fi
8349994689c1Smrg
8350994689c1Smrg	  tmp_libs=
8351994689c1Smrg	  for deplib in $dependency_libs; do
8352994689c1Smrg	    case $deplib in
8353994689c1Smrg	    -L*) func_stripname '-L' '' "$deplib"
8354f353fbadSmrg	         func_resolve_sysroot "$func_stripname_result"
8355f353fbadSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8356994689c1Smrg		 ;;
8357994689c1Smrg	    esac
8358994689c1Smrg	    # Need to link against all dependency_libs?
83595ec34c4cSmrg	    if $linkalldeplibs; then
8360994689c1Smrg	      deplibs="$deplib $deplibs"
8361994689c1Smrg	    else
8362994689c1Smrg	      # Need to hardcode shared library paths
8363994689c1Smrg	      # or/and link against static libraries
8364994689c1Smrg	      newdependency_libs="$deplib $newdependency_libs"
8365994689c1Smrg	    fi
83665ec34c4cSmrg	    if $opt_preserve_dup_deps; then
8367994689c1Smrg	      case "$tmp_libs " in
8368f353fbadSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8369994689c1Smrg	      esac
8370994689c1Smrg	    fi
8371f353fbadSmrg	    func_append tmp_libs " $deplib"
8372994689c1Smrg	  done # for deplib
8373994689c1Smrg	  continue
8374994689c1Smrg	fi # $linkmode = prog...
8375994689c1Smrg
83765ec34c4cSmrg	if test prog,link = "$linkmode,$pass"; then
8377994689c1Smrg	  if test -n "$library_names" &&
83785ec34c4cSmrg	     { { test no = "$prefer_static_libs" ||
83795ec34c4cSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8380994689c1Smrg	       test -z "$old_library"; }; then
8381994689c1Smrg	    # We need to hardcode the library path
83825ec34c4cSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8383994689c1Smrg	      # Make sure the rpath contains only unique directories.
83845ec34c4cSmrg	      case $temp_rpath: in
8385994689c1Smrg	      *"$absdir:"*) ;;
8386f353fbadSmrg	      *) func_append temp_rpath "$absdir:" ;;
8387994689c1Smrg	      esac
8388994689c1Smrg	    fi
8389994689c1Smrg
8390994689c1Smrg	    # Hardcode the library path.
8391994689c1Smrg	    # Skip directories that are in the system default run-time
8392994689c1Smrg	    # search path.
8393994689c1Smrg	    case " $sys_lib_dlsearch_path " in
8394994689c1Smrg	    *" $absdir "*) ;;
8395994689c1Smrg	    *)
8396994689c1Smrg	      case "$compile_rpath " in
8397994689c1Smrg	      *" $absdir "*) ;;
8398f353fbadSmrg	      *) func_append compile_rpath " $absdir" ;;
8399994689c1Smrg	      esac
8400994689c1Smrg	      ;;
8401994689c1Smrg	    esac
8402994689c1Smrg	    case " $sys_lib_dlsearch_path " in
8403994689c1Smrg	    *" $libdir "*) ;;
8404994689c1Smrg	    *)
8405994689c1Smrg	      case "$finalize_rpath " in
8406994689c1Smrg	      *" $libdir "*) ;;
8407f353fbadSmrg	      *) func_append finalize_rpath " $libdir" ;;
8408994689c1Smrg	      esac
8409994689c1Smrg	      ;;
8410994689c1Smrg	    esac
8411994689c1Smrg	  fi # $linkmode,$pass = prog,link...
8412994689c1Smrg
84135ec34c4cSmrg	  if $alldeplibs &&
84145ec34c4cSmrg	     { test pass_all = "$deplibs_check_method" ||
84155ec34c4cSmrg	       { test yes = "$build_libtool_libs" &&
8416994689c1Smrg		 test -n "$library_names"; }; }; then
8417994689c1Smrg	    # We only need to search for static libraries
8418994689c1Smrg	    continue
8419994689c1Smrg	  fi
8420994689c1Smrg	fi
8421994689c1Smrg
8422994689c1Smrg	link_static=no # Whether the deplib will be linked statically
8423994689c1Smrg	use_static_libs=$prefer_static_libs
84245ec34c4cSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8425994689c1Smrg	  use_static_libs=no
8426994689c1Smrg	fi
8427994689c1Smrg	if test -n "$library_names" &&
84285ec34c4cSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8429994689c1Smrg	  case $host in
84305ec34c4cSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8431994689c1Smrg	      # No point in relinking DLLs because paths are not encoded
8432f353fbadSmrg	      func_append notinst_deplibs " $lib"
8433994689c1Smrg	      need_relink=no
8434994689c1Smrg	    ;;
8435994689c1Smrg	  *)
84365ec34c4cSmrg	    if test no = "$installed"; then
8437f353fbadSmrg	      func_append notinst_deplibs " $lib"
8438994689c1Smrg	      need_relink=yes
8439994689c1Smrg	    fi
8440994689c1Smrg	    ;;
8441994689c1Smrg	  esac
8442994689c1Smrg	  # This is a shared library
8443994689c1Smrg
8444994689c1Smrg	  # Warn about portability, can't link against -module's on some
8445994689c1Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
84465ec34c4cSmrg	  dlopenmodule=
8447994689c1Smrg	  for dlpremoduletest in $dlprefiles; do
8448994689c1Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
84495ec34c4cSmrg	      dlopenmodule=$dlpremoduletest
8450994689c1Smrg	      break
8451994689c1Smrg	    fi
8452994689c1Smrg	  done
84535ec34c4cSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8454994689c1Smrg	    echo
84555ec34c4cSmrg	    if test prog = "$linkmode"; then
8456994689c1Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8457994689c1Smrg	    else
8458994689c1Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8459994689c1Smrg	    fi
8460994689c1Smrg	    $ECHO "*** $linklib is not portable!"
8461994689c1Smrg	  fi
84625ec34c4cSmrg	  if test lib = "$linkmode" &&
84635ec34c4cSmrg	     test yes = "$hardcode_into_libs"; then
8464994689c1Smrg	    # Hardcode the library path.
8465994689c1Smrg	    # Skip directories that are in the system default run-time
8466994689c1Smrg	    # search path.
8467994689c1Smrg	    case " $sys_lib_dlsearch_path " in
8468994689c1Smrg	    *" $absdir "*) ;;
8469994689c1Smrg	    *)
8470994689c1Smrg	      case "$compile_rpath " in
8471994689c1Smrg	      *" $absdir "*) ;;
8472f353fbadSmrg	      *) func_append compile_rpath " $absdir" ;;
8473994689c1Smrg	      esac
8474994689c1Smrg	      ;;
8475994689c1Smrg	    esac
8476994689c1Smrg	    case " $sys_lib_dlsearch_path " in
8477994689c1Smrg	    *" $libdir "*) ;;
8478994689c1Smrg	    *)
8479994689c1Smrg	      case "$finalize_rpath " in
8480994689c1Smrg	      *" $libdir "*) ;;
8481f353fbadSmrg	      *) func_append finalize_rpath " $libdir" ;;
8482994689c1Smrg	      esac
8483994689c1Smrg	      ;;
8484994689c1Smrg	    esac
8485994689c1Smrg	  fi
8486994689c1Smrg
8487994689c1Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8488994689c1Smrg	    # figure out the soname
8489994689c1Smrg	    set dummy $library_names
8490994689c1Smrg	    shift
84915ec34c4cSmrg	    realname=$1
8492994689c1Smrg	    shift
8493994689c1Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8494994689c1Smrg	    # use dlname if we got it. it's perfectly good, no?
8495994689c1Smrg	    if test -n "$dlname"; then
84965ec34c4cSmrg	      soname=$dlname
8497994689c1Smrg	    elif test -n "$soname_spec"; then
8498994689c1Smrg	      # bleh windows
8499994689c1Smrg	      case $host in
85005ec34c4cSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8501994689c1Smrg	        func_arith $current - $age
8502994689c1Smrg		major=$func_arith_result
85035ec34c4cSmrg		versuffix=-$major
8504994689c1Smrg		;;
8505994689c1Smrg	      esac
8506994689c1Smrg	      eval soname=\"$soname_spec\"
8507994689c1Smrg	    else
85085ec34c4cSmrg	      soname=$realname
8509994689c1Smrg	    fi
8510994689c1Smrg
8511994689c1Smrg	    # Make a new name for the extract_expsyms_cmds to use
85125ec34c4cSmrg	    soroot=$soname
8513994689c1Smrg	    func_basename "$soroot"
85145ec34c4cSmrg	    soname=$func_basename_result
8515994689c1Smrg	    func_stripname 'lib' '.dll' "$soname"
8516994689c1Smrg	    newlib=libimp-$func_stripname_result.a
8517994689c1Smrg
8518994689c1Smrg	    # If the library has no export list, then create one now
8519994689c1Smrg	    if test -f "$output_objdir/$soname-def"; then :
8520994689c1Smrg	    else
85215ec34c4cSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8522994689c1Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8523994689c1Smrg	    fi
8524994689c1Smrg
8525994689c1Smrg	    # Create $newlib
8526994689c1Smrg	    if test -f "$output_objdir/$newlib"; then :; else
85275ec34c4cSmrg	      func_verbose "generating import library for '$soname'"
8528994689c1Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8529994689c1Smrg	    fi
8530994689c1Smrg	    # make sure the library variables are pointing to the new library
8531994689c1Smrg	    dir=$output_objdir
8532994689c1Smrg	    linklib=$newlib
8533994689c1Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8534994689c1Smrg
85355ec34c4cSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8536994689c1Smrg	    add_shlibpath=
8537994689c1Smrg	    add_dir=
8538994689c1Smrg	    add=
8539994689c1Smrg	    lib_linked=yes
8540994689c1Smrg	    case $hardcode_action in
8541994689c1Smrg	    immediate | unsupported)
85425ec34c4cSmrg	      if test no = "$hardcode_direct"; then
85435ec34c4cSmrg		add=$dir/$linklib
8544994689c1Smrg		case $host in
85455ec34c4cSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
85465ec34c4cSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8547994689c1Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
85485ec34c4cSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8549994689c1Smrg		  *-*-darwin* )
85505ec34c4cSmrg		    # if the lib is a (non-dlopened) module then we cannot
8551994689c1Smrg		    # link against it, someone is ignoring the earlier warnings
8552994689c1Smrg		    if /usr/bin/file -L $add 2> /dev/null |
85535ec34c4cSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8554994689c1Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8555994689c1Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
85565ec34c4cSmrg			if test -z "$old_library"; then
8557994689c1Smrg			  echo
8558994689c1Smrg			  echo "*** And there doesn't seem to be a static archive available"
8559994689c1Smrg			  echo "*** The link will probably fail, sorry"
8560994689c1Smrg			else
85615ec34c4cSmrg			  add=$dir/$old_library
8562994689c1Smrg			fi
8563994689c1Smrg		      elif test -n "$old_library"; then
85645ec34c4cSmrg			add=$dir/$old_library
8565994689c1Smrg		      fi
8566994689c1Smrg		    fi
8567994689c1Smrg		esac
85685ec34c4cSmrg	      elif test no = "$hardcode_minus_L"; then
8569994689c1Smrg		case $host in
85705ec34c4cSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8571994689c1Smrg		esac
85725ec34c4cSmrg		add_dir=-L$dir
85735ec34c4cSmrg		add=-l$name
85745ec34c4cSmrg	      elif test no = "$hardcode_shlibpath_var"; then
85755ec34c4cSmrg		add_shlibpath=$dir
85765ec34c4cSmrg		add=-l$name
8577994689c1Smrg	      else
8578994689c1Smrg		lib_linked=no
8579994689c1Smrg	      fi
8580994689c1Smrg	      ;;
8581994689c1Smrg	    relink)
85825ec34c4cSmrg	      if test yes = "$hardcode_direct" &&
85835ec34c4cSmrg	         test no = "$hardcode_direct_absolute"; then
85845ec34c4cSmrg		add=$dir/$linklib
85855ec34c4cSmrg	      elif test yes = "$hardcode_minus_L"; then
85865ec34c4cSmrg		add_dir=-L$absdir
8587994689c1Smrg		# Try looking first in the location we're being installed to.
8588994689c1Smrg		if test -n "$inst_prefix_dir"; then
8589994689c1Smrg		  case $libdir in
8590994689c1Smrg		    [\\/]*)
8591f353fbadSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8592994689c1Smrg		      ;;
8593994689c1Smrg		  esac
8594994689c1Smrg		fi
85955ec34c4cSmrg		add=-l$name
85965ec34c4cSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
85975ec34c4cSmrg		add_shlibpath=$dir
85985ec34c4cSmrg		add=-l$name
8599994689c1Smrg	      else
8600994689c1Smrg		lib_linked=no
8601994689c1Smrg	      fi
8602994689c1Smrg	      ;;
8603994689c1Smrg	    *) lib_linked=no ;;
8604994689c1Smrg	    esac
8605994689c1Smrg
86065ec34c4cSmrg	    if test yes != "$lib_linked"; then
8607994689c1Smrg	      func_fatal_configuration "unsupported hardcode properties"
8608994689c1Smrg	    fi
8609994689c1Smrg
8610994689c1Smrg	    if test -n "$add_shlibpath"; then
8611994689c1Smrg	      case :$compile_shlibpath: in
8612994689c1Smrg	      *":$add_shlibpath:"*) ;;
8613f353fbadSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8614994689c1Smrg	      esac
8615994689c1Smrg	    fi
86165ec34c4cSmrg	    if test prog = "$linkmode"; then
8617994689c1Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8618994689c1Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8619994689c1Smrg	    else
8620994689c1Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8621994689c1Smrg	      test -n "$add" && deplibs="$add $deplibs"
86225ec34c4cSmrg	      if test yes != "$hardcode_direct" &&
86235ec34c4cSmrg		 test yes != "$hardcode_minus_L" &&
86245ec34c4cSmrg		 test yes = "$hardcode_shlibpath_var"; then
8625994689c1Smrg		case :$finalize_shlibpath: in
8626994689c1Smrg		*":$libdir:"*) ;;
8627f353fbadSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8628994689c1Smrg		esac
8629994689c1Smrg	      fi
8630994689c1Smrg	    fi
8631994689c1Smrg	  fi
8632994689c1Smrg
86335ec34c4cSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8634994689c1Smrg	    add_shlibpath=
8635994689c1Smrg	    add_dir=
8636994689c1Smrg	    add=
8637994689c1Smrg	    # Finalize command for both is simple: just hardcode it.
86385ec34c4cSmrg	    if test yes = "$hardcode_direct" &&
86395ec34c4cSmrg	       test no = "$hardcode_direct_absolute"; then
86405ec34c4cSmrg	      add=$libdir/$linklib
86415ec34c4cSmrg	    elif test yes = "$hardcode_minus_L"; then
86425ec34c4cSmrg	      add_dir=-L$libdir
86435ec34c4cSmrg	      add=-l$name
86445ec34c4cSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8645994689c1Smrg	      case :$finalize_shlibpath: in
8646994689c1Smrg	      *":$libdir:"*) ;;
8647f353fbadSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8648994689c1Smrg	      esac
86495ec34c4cSmrg	      add=-l$name
86505ec34c4cSmrg	    elif test yes = "$hardcode_automatic"; then
8651994689c1Smrg	      if test -n "$inst_prefix_dir" &&
86525ec34c4cSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
86535ec34c4cSmrg		add=$inst_prefix_dir$libdir/$linklib
8654994689c1Smrg	      else
86555ec34c4cSmrg		add=$libdir/$linklib
8656994689c1Smrg	      fi
8657994689c1Smrg	    else
8658994689c1Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
86595ec34c4cSmrg	      add_dir=-L$libdir
8660994689c1Smrg	      # Try looking first in the location we're being installed to.
8661994689c1Smrg	      if test -n "$inst_prefix_dir"; then
8662994689c1Smrg		case $libdir in
8663994689c1Smrg		  [\\/]*)
8664f353fbadSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8665994689c1Smrg		    ;;
8666994689c1Smrg		esac
8667994689c1Smrg	      fi
86685ec34c4cSmrg	      add=-l$name
8669994689c1Smrg	    fi
8670994689c1Smrg
86715ec34c4cSmrg	    if test prog = "$linkmode"; then
8672994689c1Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8673994689c1Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8674994689c1Smrg	    else
8675994689c1Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8676994689c1Smrg	      test -n "$add" && deplibs="$add $deplibs"
8677994689c1Smrg	    fi
8678994689c1Smrg	  fi
86795ec34c4cSmrg	elif test prog = "$linkmode"; then
8680994689c1Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8681994689c1Smrg	  # is not unsupported.  This is valid on all known static and
8682994689c1Smrg	  # shared platforms.
86835ec34c4cSmrg	  if test unsupported != "$hardcode_direct"; then
86845ec34c4cSmrg	    test -n "$old_library" && linklib=$old_library
8685994689c1Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8686994689c1Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8687994689c1Smrg	  else
8688994689c1Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8689994689c1Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8690994689c1Smrg	  fi
86915ec34c4cSmrg	elif test yes = "$build_libtool_libs"; then
8692994689c1Smrg	  # Not a shared library
86935ec34c4cSmrg	  if test pass_all != "$deplibs_check_method"; then
8694994689c1Smrg	    # We're trying link a shared library against a static one
8695994689c1Smrg	    # but the system doesn't support it.
8696994689c1Smrg
8697994689c1Smrg	    # Just print a warning and add the library to dependency_libs so
8698994689c1Smrg	    # that the program can be linked against the static library.
8699994689c1Smrg	    echo
87005ec34c4cSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8701994689c1Smrg	    echo "*** I have the capability to make that library automatically link in when"
8702994689c1Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
8703994689c1Smrg	    echo "*** shared version of the library, which you do not appear to have."
87045ec34c4cSmrg	    if test yes = "$module"; then
8705994689c1Smrg	      echo "*** But as you try to build a module library, libtool will still create "
8706994689c1Smrg	      echo "*** a static module, that should work as long as the dlopening application"
8707994689c1Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8708994689c1Smrg	      if test -z "$global_symbol_pipe"; then
8709994689c1Smrg		echo
8710994689c1Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
87115ec34c4cSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8712994689c1Smrg		echo "*** not find such a program.  So, this module is probably useless."
87135ec34c4cSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8714994689c1Smrg	      fi
87155ec34c4cSmrg	      if test no = "$build_old_libs"; then
8716994689c1Smrg		build_libtool_libs=module
8717994689c1Smrg		build_old_libs=yes
8718994689c1Smrg	      else
8719994689c1Smrg		build_libtool_libs=no
8720994689c1Smrg	      fi
8721994689c1Smrg	    fi
8722994689c1Smrg	  else
8723994689c1Smrg	    deplibs="$dir/$old_library $deplibs"
8724994689c1Smrg	    link_static=yes
8725994689c1Smrg	  fi
8726994689c1Smrg	fi # link shared/static library?
8727994689c1Smrg
87285ec34c4cSmrg	if test lib = "$linkmode"; then
8729994689c1Smrg	  if test -n "$dependency_libs" &&
87305ec34c4cSmrg	     { test yes != "$hardcode_into_libs" ||
87315ec34c4cSmrg	       test yes = "$build_old_libs" ||
87325ec34c4cSmrg	       test yes = "$link_static"; }; then
8733994689c1Smrg	    # Extract -R from dependency_libs
8734994689c1Smrg	    temp_deplibs=
8735994689c1Smrg	    for libdir in $dependency_libs; do
8736994689c1Smrg	      case $libdir in
8737994689c1Smrg	      -R*) func_stripname '-R' '' "$libdir"
8738994689c1Smrg	           temp_xrpath=$func_stripname_result
8739994689c1Smrg		   case " $xrpath " in
8740994689c1Smrg		   *" $temp_xrpath "*) ;;
8741f353fbadSmrg		   *) func_append xrpath " $temp_xrpath";;
8742994689c1Smrg		   esac;;
8743f353fbadSmrg	      *) func_append temp_deplibs " $libdir";;
8744994689c1Smrg	      esac
8745994689c1Smrg	    done
87465ec34c4cSmrg	    dependency_libs=$temp_deplibs
8747994689c1Smrg	  fi
8748994689c1Smrg
8749f353fbadSmrg	  func_append newlib_search_path " $absdir"
8750994689c1Smrg	  # Link against this library
87515ec34c4cSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8752994689c1Smrg	  # ... and its dependency_libs
8753994689c1Smrg	  tmp_libs=
8754994689c1Smrg	  for deplib in $dependency_libs; do
8755994689c1Smrg	    newdependency_libs="$deplib $newdependency_libs"
8756f353fbadSmrg	    case $deplib in
8757f353fbadSmrg              -L*) func_stripname '-L' '' "$deplib"
8758f353fbadSmrg                   func_resolve_sysroot "$func_stripname_result";;
8759f353fbadSmrg              *) func_resolve_sysroot "$deplib" ;;
8760f353fbadSmrg            esac
87615ec34c4cSmrg	    if $opt_preserve_dup_deps; then
8762994689c1Smrg	      case "$tmp_libs " in
8763f353fbadSmrg	      *" $func_resolve_sysroot_result "*)
8764f353fbadSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8765994689c1Smrg	      esac
8766994689c1Smrg	    fi
8767f353fbadSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8768994689c1Smrg	  done
8769994689c1Smrg
87705ec34c4cSmrg	  if test no != "$link_all_deplibs"; then
8771994689c1Smrg	    # Add the search paths of all dependency libraries
8772994689c1Smrg	    for deplib in $dependency_libs; do
8773994689c1Smrg	      path=
8774994689c1Smrg	      case $deplib in
87755ec34c4cSmrg	      -L*) path=$deplib ;;
8776994689c1Smrg	      *.la)
8777f353fbadSmrg	        func_resolve_sysroot "$deplib"
8778f353fbadSmrg	        deplib=$func_resolve_sysroot_result
8779994689c1Smrg	        func_dirname "$deplib" "" "."
8780f353fbadSmrg		dir=$func_dirname_result
8781994689c1Smrg		# We need an absolute path.
8782994689c1Smrg		case $dir in
87835ec34c4cSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8784994689c1Smrg		*)
8785994689c1Smrg		  absdir=`cd "$dir" && pwd`
8786994689c1Smrg		  if test -z "$absdir"; then
87875ec34c4cSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
87885ec34c4cSmrg		    absdir=$dir
8789994689c1Smrg		  fi
8790994689c1Smrg		  ;;
8791994689c1Smrg		esac
8792994689c1Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8793994689c1Smrg		case $host in
8794994689c1Smrg		*-*-darwin*)
8795994689c1Smrg		  depdepl=
87965ec34c4cSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
87975ec34c4cSmrg		  if test -n "$deplibrary_names"; then
87985ec34c4cSmrg		    for tmp in $deplibrary_names; do
8799994689c1Smrg		      depdepl=$tmp
8800994689c1Smrg		    done
88015ec34c4cSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
88025ec34c4cSmrg		      depdepl=$absdir/$objdir/$depdepl
88035ec34c4cSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8804994689c1Smrg                      if test -z "$darwin_install_name"; then
88055ec34c4cSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8806994689c1Smrg                      fi
88075ec34c4cSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
88085ec34c4cSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8809994689c1Smrg		      path=
8810994689c1Smrg		    fi
8811994689c1Smrg		  fi
8812994689c1Smrg		  ;;
8813994689c1Smrg		*)
88145ec34c4cSmrg		  path=-L$absdir/$objdir
8815994689c1Smrg		  ;;
8816994689c1Smrg		esac
8817994689c1Smrg		else
88185ec34c4cSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8819994689c1Smrg		  test -z "$libdir" && \
88205ec34c4cSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8821994689c1Smrg		  test "$absdir" != "$libdir" && \
88225ec34c4cSmrg		    func_warning "'$deplib' seems to be moved"
8823994689c1Smrg
88245ec34c4cSmrg		  path=-L$absdir
8825994689c1Smrg		fi
8826994689c1Smrg		;;
8827994689c1Smrg	      esac
8828994689c1Smrg	      case " $deplibs " in
8829994689c1Smrg	      *" $path "*) ;;
8830994689c1Smrg	      *) deplibs="$path $deplibs" ;;
8831994689c1Smrg	      esac
8832994689c1Smrg	    done
8833994689c1Smrg	  fi # link_all_deplibs != no
8834994689c1Smrg	fi # linkmode = lib
8835994689c1Smrg      done # for deplib in $libs
88365ec34c4cSmrg      if test link = "$pass"; then
88375ec34c4cSmrg	if test prog = "$linkmode"; then
8838994689c1Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8839994689c1Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8840994689c1Smrg	else
8841994689c1Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8842994689c1Smrg	fi
8843994689c1Smrg      fi
88445ec34c4cSmrg      dependency_libs=$newdependency_libs
88455ec34c4cSmrg      if test dlpreopen = "$pass"; then
8846994689c1Smrg	# Link the dlpreopened libraries before other libraries
8847994689c1Smrg	for deplib in $save_deplibs; do
8848994689c1Smrg	  deplibs="$deplib $deplibs"
8849994689c1Smrg	done
8850994689c1Smrg      fi
88515ec34c4cSmrg      if test dlopen != "$pass"; then
88525ec34c4cSmrg	test conv = "$pass" || {
8853994689c1Smrg	  # Make sure lib_search_path contains only unique directories.
8854994689c1Smrg	  lib_search_path=
8855994689c1Smrg	  for dir in $newlib_search_path; do
8856994689c1Smrg	    case "$lib_search_path " in
8857994689c1Smrg	    *" $dir "*) ;;
8858f353fbadSmrg	    *) func_append lib_search_path " $dir" ;;
8859994689c1Smrg	    esac
8860994689c1Smrg	  done
8861994689c1Smrg	  newlib_search_path=
88625ec34c4cSmrg	}
8863994689c1Smrg
88645ec34c4cSmrg	if test prog,link = "$linkmode,$pass"; then
8865994689c1Smrg	  vars="compile_deplibs finalize_deplibs"
88665ec34c4cSmrg	else
88675ec34c4cSmrg	  vars=deplibs
8868994689c1Smrg	fi
8869994689c1Smrg	for var in $vars dependency_libs; do
8870994689c1Smrg	  # Add libraries to $var in reverse order
8871994689c1Smrg	  eval tmp_libs=\"\$$var\"
8872994689c1Smrg	  new_libs=
8873994689c1Smrg	  for deplib in $tmp_libs; do
8874994689c1Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8875994689c1Smrg	    #        that some nasty dependency loop isn't accidentally
8876994689c1Smrg	    #        broken:
8877994689c1Smrg	    #new_libs="$deplib $new_libs"
8878994689c1Smrg	    # Pragmatically, this seems to cause very few problems in
8879994689c1Smrg	    # practice:
8880994689c1Smrg	    case $deplib in
8881994689c1Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8882994689c1Smrg	    -R*) ;;
8883994689c1Smrg	    *)
8884994689c1Smrg	      # And here is the reason: when a library appears more
8885994689c1Smrg	      # than once as an explicit dependence of a library, or
8886994689c1Smrg	      # is implicitly linked in more than once by the
8887994689c1Smrg	      # compiler, it is considered special, and multiple
8888994689c1Smrg	      # occurrences thereof are not removed.  Compare this
8889994689c1Smrg	      # with having the same library being listed as a
8890994689c1Smrg	      # dependency of multiple other libraries: in this case,
8891994689c1Smrg	      # we know (pedantically, we assume) the library does not
8892994689c1Smrg	      # need to be listed more than once, so we keep only the
8893994689c1Smrg	      # last copy.  This is not always right, but it is rare
8894994689c1Smrg	      # enough that we require users that really mean to play
8895994689c1Smrg	      # such unportable linking tricks to link the library
8896994689c1Smrg	      # using -Wl,-lname, so that libtool does not consider it
8897994689c1Smrg	      # for duplicate removal.
8898994689c1Smrg	      case " $specialdeplibs " in
8899994689c1Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8900994689c1Smrg	      *)
8901994689c1Smrg		case " $new_libs " in
8902994689c1Smrg		*" $deplib "*) ;;
8903994689c1Smrg		*) new_libs="$deplib $new_libs" ;;
8904994689c1Smrg		esac
8905994689c1Smrg		;;
8906994689c1Smrg	      esac
8907994689c1Smrg	      ;;
8908994689c1Smrg	    esac
8909994689c1Smrg	  done
8910994689c1Smrg	  tmp_libs=
8911994689c1Smrg	  for deplib in $new_libs; do
8912994689c1Smrg	    case $deplib in
8913994689c1Smrg	    -L*)
8914994689c1Smrg	      case " $tmp_libs " in
8915994689c1Smrg	      *" $deplib "*) ;;
8916f353fbadSmrg	      *) func_append tmp_libs " $deplib" ;;
8917994689c1Smrg	      esac
8918994689c1Smrg	      ;;
8919f353fbadSmrg	    *) func_append tmp_libs " $deplib" ;;
8920994689c1Smrg	    esac
8921994689c1Smrg	  done
8922994689c1Smrg	  eval $var=\"$tmp_libs\"
8923994689c1Smrg	done # for var
8924994689c1Smrg      fi
89255ec34c4cSmrg
89265ec34c4cSmrg      # Add Sun CC postdeps if required:
89275ec34c4cSmrg      test CXX = "$tagname" && {
89285ec34c4cSmrg        case $host_os in
89295ec34c4cSmrg        linux*)
89305b16253fSmrg          case `$CC -V 2>&1 | $SED 5q` in
89315ec34c4cSmrg          *Sun\ C*) # Sun C++ 5.9
89325ec34c4cSmrg            func_suncc_cstd_abi
89335ec34c4cSmrg
89345ec34c4cSmrg            if test no != "$suncc_use_cstd_abi"; then
89355ec34c4cSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89365ec34c4cSmrg            fi
89375ec34c4cSmrg            ;;
89385ec34c4cSmrg          esac
89395ec34c4cSmrg          ;;
89405ec34c4cSmrg
89415ec34c4cSmrg        solaris*)
89425ec34c4cSmrg          func_cc_basename "$CC"
89435ec34c4cSmrg          case $func_cc_basename_result in
89445ec34c4cSmrg          CC* | sunCC*)
89455ec34c4cSmrg            func_suncc_cstd_abi
89465ec34c4cSmrg
89475ec34c4cSmrg            if test no != "$suncc_use_cstd_abi"; then
89485ec34c4cSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89495ec34c4cSmrg            fi
89505ec34c4cSmrg            ;;
89515ec34c4cSmrg          esac
89525ec34c4cSmrg          ;;
89535ec34c4cSmrg        esac
89545ec34c4cSmrg      }
89555ec34c4cSmrg
8956994689c1Smrg      # Last step: remove runtime libs from dependency_libs
8957994689c1Smrg      # (they stay in deplibs)
8958994689c1Smrg      tmp_libs=
89595ec34c4cSmrg      for i in $dependency_libs; do
8960994689c1Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8961994689c1Smrg	*" $i "*)
89625ec34c4cSmrg	  i=
8963994689c1Smrg	  ;;
8964994689c1Smrg	esac
89655ec34c4cSmrg	if test -n "$i"; then
8966f353fbadSmrg	  func_append tmp_libs " $i"
8967994689c1Smrg	fi
8968994689c1Smrg      done
8969994689c1Smrg      dependency_libs=$tmp_libs
8970994689c1Smrg    done # for pass
89715ec34c4cSmrg    if test prog = "$linkmode"; then
89725ec34c4cSmrg      dlfiles=$newdlfiles
8973994689c1Smrg    fi
89745ec34c4cSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
89755ec34c4cSmrg      dlprefiles=$newdlprefiles
8976994689c1Smrg    fi
8977994689c1Smrg
8978994689c1Smrg    case $linkmode in
8979994689c1Smrg    oldlib)
89805ec34c4cSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
89815ec34c4cSmrg	func_warning "'-dlopen' is ignored for archives"
8982994689c1Smrg      fi
8983994689c1Smrg
8984994689c1Smrg      case " $deplibs" in
8985994689c1Smrg      *\ -l* | *\ -L*)
89865ec34c4cSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8987994689c1Smrg      esac
8988994689c1Smrg
8989994689c1Smrg      test -n "$rpath" && \
89905ec34c4cSmrg	func_warning "'-rpath' is ignored for archives"
8991994689c1Smrg
8992994689c1Smrg      test -n "$xrpath" && \
89935ec34c4cSmrg	func_warning "'-R' is ignored for archives"
8994994689c1Smrg
8995994689c1Smrg      test -n "$vinfo" && \
89965ec34c4cSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8997994689c1Smrg
8998994689c1Smrg      test -n "$release" && \
89995ec34c4cSmrg	func_warning "'-release' is ignored for archives"
9000994689c1Smrg
9001994689c1Smrg      test -n "$export_symbols$export_symbols_regex" && \
90025ec34c4cSmrg	func_warning "'-export-symbols' is ignored for archives"
9003994689c1Smrg
9004994689c1Smrg      # Now set the variables for building old libraries.
9005994689c1Smrg      build_libtool_libs=no
90065ec34c4cSmrg      oldlibs=$output
9007f353fbadSmrg      func_append objs "$old_deplibs"
9008994689c1Smrg      ;;
9009994689c1Smrg
9010994689c1Smrg    lib)
90115ec34c4cSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9012994689c1Smrg      case $outputname in
9013994689c1Smrg      lib*)
9014994689c1Smrg	func_stripname 'lib' '.la' "$outputname"
9015994689c1Smrg	name=$func_stripname_result
9016994689c1Smrg	eval shared_ext=\"$shrext_cmds\"
9017994689c1Smrg	eval libname=\"$libname_spec\"
9018994689c1Smrg	;;
9019994689c1Smrg      *)
90205ec34c4cSmrg	test no = "$module" \
90215ec34c4cSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9022994689c1Smrg
90235ec34c4cSmrg	if test no != "$need_lib_prefix"; then
9024994689c1Smrg	  # Add the "lib" prefix for modules if required
9025994689c1Smrg	  func_stripname '' '.la' "$outputname"
9026994689c1Smrg	  name=$func_stripname_result
9027994689c1Smrg	  eval shared_ext=\"$shrext_cmds\"
9028994689c1Smrg	  eval libname=\"$libname_spec\"
9029994689c1Smrg	else
9030994689c1Smrg	  func_stripname '' '.la' "$outputname"
9031994689c1Smrg	  libname=$func_stripname_result
9032994689c1Smrg	fi
9033994689c1Smrg	;;
9034994689c1Smrg      esac
9035994689c1Smrg
9036994689c1Smrg      if test -n "$objs"; then
90375ec34c4cSmrg	if test pass_all != "$deplibs_check_method"; then
90385ec34c4cSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9039994689c1Smrg	else
9040994689c1Smrg	  echo
9041994689c1Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9042994689c1Smrg	  $ECHO "*** objects $objs is not portable!"
9043f353fbadSmrg	  func_append libobjs " $objs"
9044994689c1Smrg	fi
9045994689c1Smrg      fi
9046994689c1Smrg
90475ec34c4cSmrg      test no = "$dlself" \
90485ec34c4cSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9049994689c1Smrg
9050994689c1Smrg      set dummy $rpath
9051994689c1Smrg      shift
90525ec34c4cSmrg      test 1 -lt "$#" \
90535ec34c4cSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9054994689c1Smrg
90555ec34c4cSmrg      install_libdir=$1
9056994689c1Smrg
9057994689c1Smrg      oldlibs=
9058994689c1Smrg      if test -z "$rpath"; then
90595ec34c4cSmrg	if test yes = "$build_libtool_libs"; then
9060994689c1Smrg	  # Building a libtool convenience library.
90615ec34c4cSmrg	  # Some compilers have problems with a '.al' extension so
9062994689c1Smrg	  # convenience libraries should have the same extension an
9063994689c1Smrg	  # archive normally would.
9064994689c1Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9065994689c1Smrg	  build_libtool_libs=convenience
9066994689c1Smrg	  build_old_libs=yes
9067994689c1Smrg	fi
9068994689c1Smrg
9069994689c1Smrg	test -n "$vinfo" && \
90705ec34c4cSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9071994689c1Smrg
9072994689c1Smrg	test -n "$release" && \
90735ec34c4cSmrg	  func_warning "'-release' is ignored for convenience libraries"
9074994689c1Smrg      else
9075994689c1Smrg
9076994689c1Smrg	# Parse the version information argument.
90775ec34c4cSmrg	save_ifs=$IFS; IFS=:
9078994689c1Smrg	set dummy $vinfo 0 0 0
9079994689c1Smrg	shift
90805ec34c4cSmrg	IFS=$save_ifs
9081994689c1Smrg
9082994689c1Smrg	test -n "$7" && \
90835ec34c4cSmrg	  func_fatal_help "too many parameters to '-version-info'"
9084994689c1Smrg
9085994689c1Smrg	# convert absolute version numbers to libtool ages
9086994689c1Smrg	# this retains compatibility with .la files and attempts
9087994689c1Smrg	# to make the code below a bit more comprehensible
9088994689c1Smrg
9089994689c1Smrg	case $vinfo_number in
9090994689c1Smrg	yes)
90915ec34c4cSmrg	  number_major=$1
90925ec34c4cSmrg	  number_minor=$2
90935ec34c4cSmrg	  number_revision=$3
9094994689c1Smrg	  #
9095994689c1Smrg	  # There are really only two kinds -- those that
9096994689c1Smrg	  # use the current revision as the major version
9097994689c1Smrg	  # and those that subtract age and use age as
9098994689c1Smrg	  # a minor version.  But, then there is irix
90995ec34c4cSmrg	  # that has an extra 1 added just for fun
9100994689c1Smrg	  #
9101994689c1Smrg	  case $version_type in
9102421c997bSmrg	  # correct linux to gnu/linux during the next big refactor
91035b16253fSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9104994689c1Smrg	    func_arith $number_major + $number_minor
9105994689c1Smrg	    current=$func_arith_result
91065ec34c4cSmrg	    age=$number_minor
91075ec34c4cSmrg	    revision=$number_revision
9108994689c1Smrg	    ;;
91095ec34c4cSmrg	  freebsd-aout|qnx|sunos)
91105ec34c4cSmrg	    current=$number_major
91115ec34c4cSmrg	    revision=$number_minor
91125ec34c4cSmrg	    age=0
9113994689c1Smrg	    ;;
9114994689c1Smrg	  irix|nonstopux)
9115994689c1Smrg	    func_arith $number_major + $number_minor
9116994689c1Smrg	    current=$func_arith_result
91175ec34c4cSmrg	    age=$number_minor
91185ec34c4cSmrg	    revision=$number_minor
9119994689c1Smrg	    lt_irix_increment=no
9120994689c1Smrg	    ;;
9121efbcb2bfSmrg	  *)
9122efbcb2bfSmrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
9123efbcb2bfSmrg	    ;;
9124994689c1Smrg	  esac
9125994689c1Smrg	  ;;
9126994689c1Smrg	no)
91275ec34c4cSmrg	  current=$1
91285ec34c4cSmrg	  revision=$2
91295ec34c4cSmrg	  age=$3
9130994689c1Smrg	  ;;
9131994689c1Smrg	esac
9132994689c1Smrg
9133994689c1Smrg	# Check that each of the things are valid numbers.
9134994689c1Smrg	case $current in
9135994689c1Smrg	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]) ;;
9136994689c1Smrg	*)
91375ec34c4cSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
91385ec34c4cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9139994689c1Smrg	  ;;
9140994689c1Smrg	esac
9141994689c1Smrg
9142994689c1Smrg	case $revision in
9143994689c1Smrg	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]) ;;
9144994689c1Smrg	*)
91455ec34c4cSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
91465ec34c4cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9147994689c1Smrg	  ;;
9148994689c1Smrg	esac
9149994689c1Smrg
9150994689c1Smrg	case $age in
9151994689c1Smrg	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]) ;;
9152994689c1Smrg	*)
91535ec34c4cSmrg	  func_error "AGE '$age' must be a nonnegative integer"
91545ec34c4cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9155994689c1Smrg	  ;;
9156994689c1Smrg	esac
9157994689c1Smrg
9158994689c1Smrg	if test "$age" -gt "$current"; then
91595ec34c4cSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
91605ec34c4cSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9161994689c1Smrg	fi
9162994689c1Smrg
9163994689c1Smrg	# Calculate the version variables.
9164994689c1Smrg	major=
9165994689c1Smrg	versuffix=
9166994689c1Smrg	verstring=
9167994689c1Smrg	case $version_type in
9168994689c1Smrg	none) ;;
9169994689c1Smrg
9170994689c1Smrg	darwin)
9171994689c1Smrg	  # Like Linux, but with the current version available in
9172994689c1Smrg	  # verstring for coding it into the library header
9173994689c1Smrg	  func_arith $current - $age
9174994689c1Smrg	  major=.$func_arith_result
91755ec34c4cSmrg	  versuffix=$major.$age.$revision
9176994689c1Smrg	  # Darwin ld doesn't like 0 for these options...
9177994689c1Smrg	  func_arith $current + 1
9178994689c1Smrg	  minor_current=$func_arith_result
91795ec34c4cSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9180994689c1Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91815ec34c4cSmrg          # On Darwin other compilers
91825ec34c4cSmrg          case $CC in
91835ec34c4cSmrg              nagfor*)
91845ec34c4cSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91855ec34c4cSmrg                  ;;
91865ec34c4cSmrg              *)
91875ec34c4cSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91885ec34c4cSmrg                  ;;
91895ec34c4cSmrg          esac
9190994689c1Smrg	  ;;
9191994689c1Smrg
9192994689c1Smrg	freebsd-aout)
91935ec34c4cSmrg	  major=.$current
91945ec34c4cSmrg	  versuffix=.$current.$revision
9195994689c1Smrg	  ;;
9196994689c1Smrg
91975b16253fSmrg	freebsd-elf | midnightbsd-elf)
91985ec34c4cSmrg	  func_arith $current - $age
91995ec34c4cSmrg	  major=.$func_arith_result
92005ec34c4cSmrg	  versuffix=$major.$age.$revision
9201994689c1Smrg	  ;;
9202994689c1Smrg
9203994689c1Smrg	irix | nonstopux)
92045ec34c4cSmrg	  if test no = "$lt_irix_increment"; then
9205994689c1Smrg	    func_arith $current - $age
9206994689c1Smrg	  else
9207994689c1Smrg	    func_arith $current - $age + 1
9208994689c1Smrg	  fi
9209994689c1Smrg	  major=$func_arith_result
9210994689c1Smrg
9211994689c1Smrg	  case $version_type in
9212994689c1Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9213994689c1Smrg	    *)         verstring_prefix=sgi ;;
9214994689c1Smrg	  esac
92155ec34c4cSmrg	  verstring=$verstring_prefix$major.$revision
9216994689c1Smrg
9217994689c1Smrg	  # Add in all the interfaces that we are compatible with.
9218994689c1Smrg	  loop=$revision
92195ec34c4cSmrg	  while test 0 -ne "$loop"; do
9220994689c1Smrg	    func_arith $revision - $loop
9221994689c1Smrg	    iface=$func_arith_result
9222994689c1Smrg	    func_arith $loop - 1
9223994689c1Smrg	    loop=$func_arith_result
92245ec34c4cSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9225994689c1Smrg	  done
9226994689c1Smrg
92275ec34c4cSmrg	  # Before this point, $major must not contain '.'.
9228994689c1Smrg	  major=.$major
92295ec34c4cSmrg	  versuffix=$major.$revision
9230994689c1Smrg	  ;;
9231994689c1Smrg
9232421c997bSmrg	linux) # correct to gnu/linux during the next big refactor
9233994689c1Smrg	  func_arith $current - $age
9234994689c1Smrg	  major=.$func_arith_result
92355ec34c4cSmrg	  versuffix=$major.$age.$revision
9236994689c1Smrg	  ;;
9237994689c1Smrg
9238994689c1Smrg	osf)
9239994689c1Smrg	  func_arith $current - $age
9240994689c1Smrg	  major=.$func_arith_result
92415ec34c4cSmrg	  versuffix=.$current.$age.$revision
92425ec34c4cSmrg	  verstring=$current.$age.$revision
9243994689c1Smrg
9244994689c1Smrg	  # Add in all the interfaces that we are compatible with.
9245994689c1Smrg	  loop=$age
92465ec34c4cSmrg	  while test 0 -ne "$loop"; do
9247994689c1Smrg	    func_arith $current - $loop
9248994689c1Smrg	    iface=$func_arith_result
9249994689c1Smrg	    func_arith $loop - 1
9250994689c1Smrg	    loop=$func_arith_result
92515ec34c4cSmrg	    verstring=$verstring:$iface.0
9252994689c1Smrg	  done
9253994689c1Smrg
9254994689c1Smrg	  # Make executables depend on our current version.
92555ec34c4cSmrg	  func_append verstring ":$current.0"
9256994689c1Smrg	  ;;
9257994689c1Smrg
9258994689c1Smrg	qnx)
92595ec34c4cSmrg	  major=.$current
92605ec34c4cSmrg	  versuffix=.$current
92615ec34c4cSmrg	  ;;
92625ec34c4cSmrg
92635ec34c4cSmrg	sco)
92645ec34c4cSmrg	  major=.$current
92655ec34c4cSmrg	  versuffix=.$current
9266994689c1Smrg	  ;;
9267994689c1Smrg
9268994689c1Smrg	sunos)
92695ec34c4cSmrg	  major=.$current
92705ec34c4cSmrg	  versuffix=.$current.$revision
9271994689c1Smrg	  ;;
9272994689c1Smrg
9273994689c1Smrg	windows)
9274994689c1Smrg	  # Use '-' rather than '.', since we only want one
92755ec34c4cSmrg	  # extension on DOS 8.3 file systems.
9276994689c1Smrg	  func_arith $current - $age
9277994689c1Smrg	  major=$func_arith_result
92785ec34c4cSmrg	  versuffix=-$major
9279994689c1Smrg	  ;;
9280994689c1Smrg
9281994689c1Smrg	*)
92825ec34c4cSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9283994689c1Smrg	  ;;
9284994689c1Smrg	esac
9285994689c1Smrg
9286994689c1Smrg	# Clear the version info if we defaulted, and they specified a release.
9287994689c1Smrg	if test -z "$vinfo" && test -n "$release"; then
9288994689c1Smrg	  major=
9289994689c1Smrg	  case $version_type in
9290994689c1Smrg	  darwin)
9291994689c1Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9292994689c1Smrg	    # problems, so we reset it completely
9293994689c1Smrg	    verstring=
9294994689c1Smrg	    ;;
9295994689c1Smrg	  *)
92965ec34c4cSmrg	    verstring=0.0
9297994689c1Smrg	    ;;
9298994689c1Smrg	  esac
92995ec34c4cSmrg	  if test no = "$need_version"; then
9300994689c1Smrg	    versuffix=
9301994689c1Smrg	  else
93025ec34c4cSmrg	    versuffix=.0.0
9303994689c1Smrg	  fi
9304994689c1Smrg	fi
9305994689c1Smrg
9306994689c1Smrg	# Remove version info from name if versioning should be avoided
93075ec34c4cSmrg	if test yes,no = "$avoid_version,$need_version"; then
9308994689c1Smrg	  major=
9309994689c1Smrg	  versuffix=
93105ec34c4cSmrg	  verstring=
9311994689c1Smrg	fi
9312994689c1Smrg
9313994689c1Smrg	# Check to see if the archive will have undefined symbols.
93145ec34c4cSmrg	if test yes = "$allow_undefined"; then
93155ec34c4cSmrg	  if test unsupported = "$allow_undefined_flag"; then
93165ec34c4cSmrg	    if test yes = "$build_old_libs"; then
93175ec34c4cSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
93185ec34c4cSmrg	      build_libtool_libs=no
93195ec34c4cSmrg	    else
93205ec34c4cSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
93215ec34c4cSmrg	    fi
9322994689c1Smrg	  fi
9323994689c1Smrg	else
9324994689c1Smrg	  # Don't allow undefined symbols.
93255ec34c4cSmrg	  allow_undefined_flag=$no_undefined_flag
9326994689c1Smrg	fi
9327994689c1Smrg
9328994689c1Smrg      fi
9329994689c1Smrg
93305ec34c4cSmrg      func_generate_dlsyms "$libname" "$libname" :
9331f353fbadSmrg      func_append libobjs " $symfileobj"
93325ec34c4cSmrg      test " " = "$libobjs" && libobjs=
9333994689c1Smrg
93345ec34c4cSmrg      if test relink != "$opt_mode"; then
9335994689c1Smrg	# Remove our outputs, but don't remove object files since they
9336994689c1Smrg	# may have been created when compiling PIC objects.
9337994689c1Smrg	removelist=
9338994689c1Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9339994689c1Smrg	for p in $tempremovelist; do
9340994689c1Smrg	  case $p in
9341994689c1Smrg	    *.$objext | *.gcno)
9342994689c1Smrg	       ;;
93435ec34c4cSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
93445ec34c4cSmrg	       if test -n "$precious_files_regex"; then
9345994689c1Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9346994689c1Smrg		 then
9347994689c1Smrg		   continue
9348994689c1Smrg		 fi
9349994689c1Smrg	       fi
9350f353fbadSmrg	       func_append removelist " $p"
9351994689c1Smrg	       ;;
9352994689c1Smrg	    *) ;;
9353994689c1Smrg	  esac
9354994689c1Smrg	done
9355994689c1Smrg	test -n "$removelist" && \
9356994689c1Smrg	  func_show_eval "${RM}r \$removelist"
9357994689c1Smrg      fi
9358994689c1Smrg
9359994689c1Smrg      # Now set the variables for building old libraries.
93605ec34c4cSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9361f353fbadSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9362994689c1Smrg
9363994689c1Smrg	# Transform .lo files to .o files.
93645ec34c4cSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9365994689c1Smrg      fi
9366994689c1Smrg
9367994689c1Smrg      # Eliminate all temporary directories.
9368994689c1Smrg      #for path in $notinst_path; do
9369994689c1Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9370994689c1Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9371994689c1Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9372994689c1Smrg      #done
9373994689c1Smrg
9374994689c1Smrg      if test -n "$xrpath"; then
9375994689c1Smrg	# If the user specified any rpath flags, then add them.
9376994689c1Smrg	temp_xrpath=
9377994689c1Smrg	for libdir in $xrpath; do
9378f353fbadSmrg	  func_replace_sysroot "$libdir"
9379f353fbadSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9380994689c1Smrg	  case "$finalize_rpath " in
9381994689c1Smrg	  *" $libdir "*) ;;
9382f353fbadSmrg	  *) func_append finalize_rpath " $libdir" ;;
9383994689c1Smrg	  esac
9384994689c1Smrg	done
93855ec34c4cSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9386994689c1Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9387994689c1Smrg	fi
9388994689c1Smrg      fi
9389994689c1Smrg
9390994689c1Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
93915ec34c4cSmrg      old_dlfiles=$dlfiles
9392994689c1Smrg      dlfiles=
9393994689c1Smrg      for lib in $old_dlfiles; do
9394994689c1Smrg	case " $dlprefiles $dlfiles " in
9395994689c1Smrg	*" $lib "*) ;;
9396f353fbadSmrg	*) func_append dlfiles " $lib" ;;
9397994689c1Smrg	esac
9398994689c1Smrg      done
9399994689c1Smrg
9400994689c1Smrg      # Make sure dlprefiles contains only unique files
94015ec34c4cSmrg      old_dlprefiles=$dlprefiles
9402994689c1Smrg      dlprefiles=
9403994689c1Smrg      for lib in $old_dlprefiles; do
9404994689c1Smrg	case "$dlprefiles " in
9405994689c1Smrg	*" $lib "*) ;;
9406f353fbadSmrg	*) func_append dlprefiles " $lib" ;;
9407994689c1Smrg	esac
9408994689c1Smrg      done
9409994689c1Smrg
94105ec34c4cSmrg      if test yes = "$build_libtool_libs"; then
9411994689c1Smrg	if test -n "$rpath"; then
9412994689c1Smrg	  case $host in
9413994689c1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9414994689c1Smrg	    # these systems don't actually have a c library (as such)!
9415994689c1Smrg	    ;;
9416994689c1Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9417994689c1Smrg	    # Rhapsody C library is in the System framework
9418f353fbadSmrg	    func_append deplibs " System.ltframework"
9419994689c1Smrg	    ;;
9420994689c1Smrg	  *-*-netbsd*)
9421994689c1Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9422994689c1Smrg	    ;;
94235b16253fSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9424994689c1Smrg	    # Do not include libc due to us having libc/libc_r.
9425994689c1Smrg	    ;;
9426994689c1Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9427994689c1Smrg	    # Causes problems with __ctype
9428994689c1Smrg	    ;;
9429994689c1Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9430994689c1Smrg	    # Compiler inserts libc in the correct place for threads to work
9431994689c1Smrg	    ;;
9432994689c1Smrg	  *)
9433994689c1Smrg	    # Add libc to deplibs on all other systems if necessary.
94345ec34c4cSmrg	    if test yes = "$build_libtool_need_lc"; then
9435f353fbadSmrg	      func_append deplibs " -lc"
9436994689c1Smrg	    fi
9437994689c1Smrg	    ;;
9438994689c1Smrg	  esac
9439994689c1Smrg	fi
9440994689c1Smrg
9441994689c1Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9442994689c1Smrg	name_save=$name
9443994689c1Smrg	libname_save=$libname
9444994689c1Smrg	release_save=$release
9445994689c1Smrg	versuffix_save=$versuffix
9446994689c1Smrg	major_save=$major
9447994689c1Smrg	# I'm not sure if I'm treating the release correctly.  I think
9448994689c1Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9449994689c1Smrg	# add it in twice.  Is that correct?
94505ec34c4cSmrg	release=
94515ec34c4cSmrg	versuffix=
94525ec34c4cSmrg	major=
9453994689c1Smrg	newdeplibs=
9454994689c1Smrg	droppeddeps=no
9455994689c1Smrg	case $deplibs_check_method in
9456994689c1Smrg	pass_all)
9457994689c1Smrg	  # Don't check for shared/static.  Everything works.
9458994689c1Smrg	  # This might be a little naive.  We might want to check
9459994689c1Smrg	  # whether the library exists or not.  But this is on
9460994689c1Smrg	  # osf3 & osf4 and I'm not really sure... Just
9461994689c1Smrg	  # implementing what was already the behavior.
9462994689c1Smrg	  newdeplibs=$deplibs
9463994689c1Smrg	  ;;
9464994689c1Smrg	test_compile)
9465994689c1Smrg	  # This code stresses the "libraries are programs" paradigm to its
9466994689c1Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9467994689c1Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9468994689c1Smrg	  # whether they linked in statically or dynamically with ldd.
9469994689c1Smrg	  $opt_dry_run || $RM conftest.c
9470994689c1Smrg	  cat > conftest.c <<EOF
9471994689c1Smrg	  int main() { return 0; }
9472994689c1SmrgEOF
9473994689c1Smrg	  $opt_dry_run || $RM conftest
9474994689c1Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9475994689c1Smrg	    ldd_output=`ldd conftest`
9476994689c1Smrg	    for i in $deplibs; do
9477994689c1Smrg	      case $i in
9478994689c1Smrg	      -l*)
9479994689c1Smrg		func_stripname -l '' "$i"
9480994689c1Smrg		name=$func_stripname_result
94815ec34c4cSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9482994689c1Smrg		  case " $predeps $postdeps " in
9483994689c1Smrg		  *" $i "*)
9484f353fbadSmrg		    func_append newdeplibs " $i"
94855ec34c4cSmrg		    i=
9486994689c1Smrg		    ;;
9487994689c1Smrg		  esac
9488994689c1Smrg		fi
94895ec34c4cSmrg		if test -n "$i"; then
9490994689c1Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9491994689c1Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9492994689c1Smrg		  set dummy $deplib_matches; shift
9493994689c1Smrg		  deplib_match=$1
94945ec34c4cSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9495f353fbadSmrg		    func_append newdeplibs " $i"
9496994689c1Smrg		  else
9497994689c1Smrg		    droppeddeps=yes
9498994689c1Smrg		    echo
9499994689c1Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9500994689c1Smrg		    echo "*** I have the capability to make that library automatically link in when"
9501994689c1Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
9502994689c1Smrg		    echo "*** shared version of the library, which I believe you do not have"
9503994689c1Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9504994689c1Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9505994689c1Smrg		  fi
9506994689c1Smrg		fi
9507994689c1Smrg		;;
9508994689c1Smrg	      *)
9509f353fbadSmrg		func_append newdeplibs " $i"
9510994689c1Smrg		;;
9511994689c1Smrg	      esac
9512994689c1Smrg	    done
9513994689c1Smrg	  else
9514994689c1Smrg	    # Error occurred in the first compile.  Let's try to salvage
9515994689c1Smrg	    # the situation: Compile a separate program for each library.
9516994689c1Smrg	    for i in $deplibs; do
9517994689c1Smrg	      case $i in
9518994689c1Smrg	      -l*)
9519994689c1Smrg		func_stripname -l '' "$i"
9520994689c1Smrg		name=$func_stripname_result
9521994689c1Smrg		$opt_dry_run || $RM conftest
9522994689c1Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9523994689c1Smrg		  ldd_output=`ldd conftest`
95245ec34c4cSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9525994689c1Smrg		    case " $predeps $postdeps " in
9526994689c1Smrg		    *" $i "*)
9527f353fbadSmrg		      func_append newdeplibs " $i"
95285ec34c4cSmrg		      i=
9529994689c1Smrg		      ;;
9530994689c1Smrg		    esac
9531994689c1Smrg		  fi
95325ec34c4cSmrg		  if test -n "$i"; then
9533994689c1Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9534994689c1Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9535994689c1Smrg		    set dummy $deplib_matches; shift
9536994689c1Smrg		    deplib_match=$1
95375ec34c4cSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9538f353fbadSmrg		      func_append newdeplibs " $i"
9539994689c1Smrg		    else
9540994689c1Smrg		      droppeddeps=yes
9541994689c1Smrg		      echo
9542994689c1Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9543994689c1Smrg		      echo "*** I have the capability to make that library automatically link in when"
9544994689c1Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
9545994689c1Smrg		      echo "*** shared version of the library, which you do not appear to have"
9546994689c1Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9547994689c1Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9548994689c1Smrg		    fi
9549994689c1Smrg		  fi
9550994689c1Smrg		else
9551994689c1Smrg		  droppeddeps=yes
9552994689c1Smrg		  echo
9553994689c1Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9554994689c1Smrg		  echo "*** make it link in!  You will probably need to install it or some"
9555994689c1Smrg		  echo "*** library that it depends on before this library will be fully"
9556994689c1Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9557994689c1Smrg		fi
9558994689c1Smrg		;;
9559994689c1Smrg	      *)
9560f353fbadSmrg		func_append newdeplibs " $i"
9561994689c1Smrg		;;
9562994689c1Smrg	      esac
9563994689c1Smrg	    done
9564994689c1Smrg	  fi
9565994689c1Smrg	  ;;
9566994689c1Smrg	file_magic*)
9567994689c1Smrg	  set dummy $deplibs_check_method; shift
9568994689c1Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9569994689c1Smrg	  for a_deplib in $deplibs; do
9570994689c1Smrg	    case $a_deplib in
9571994689c1Smrg	    -l*)
9572994689c1Smrg	      func_stripname -l '' "$a_deplib"
9573994689c1Smrg	      name=$func_stripname_result
95745ec34c4cSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9575994689c1Smrg		case " $predeps $postdeps " in
9576994689c1Smrg		*" $a_deplib "*)
9577f353fbadSmrg		  func_append newdeplibs " $a_deplib"
95785ec34c4cSmrg		  a_deplib=
9579994689c1Smrg		  ;;
9580994689c1Smrg		esac
9581994689c1Smrg	      fi
95825ec34c4cSmrg	      if test -n "$a_deplib"; then
9583994689c1Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9584f353fbadSmrg		if test -n "$file_magic_glob"; then
9585f353fbadSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9586f353fbadSmrg		else
9587f353fbadSmrg		  libnameglob=$libname
9588f353fbadSmrg		fi
95895ec34c4cSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9590994689c1Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
95915ec34c4cSmrg		  if test yes = "$want_nocaseglob"; then
9592f353fbadSmrg		    shopt -s nocaseglob
9593f353fbadSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9594f353fbadSmrg		    $nocaseglob
9595f353fbadSmrg		  else
9596f353fbadSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9597f353fbadSmrg		  fi
9598994689c1Smrg		  for potent_lib in $potential_libs; do
9599994689c1Smrg		      # Follow soft links.
9600994689c1Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9601994689c1Smrg			 $GREP " -> " >/dev/null; then
9602994689c1Smrg			continue
9603994689c1Smrg		      fi
9604994689c1Smrg		      # The statement above tries to avoid entering an
9605994689c1Smrg		      # endless loop below, in case of cyclic links.
9606994689c1Smrg		      # We might still enter an endless loop, since a link
9607994689c1Smrg		      # loop can be closed while we follow links,
9608994689c1Smrg		      # but so what?
96095ec34c4cSmrg		      potlib=$potent_lib
9610994689c1Smrg		      while test -h "$potlib" 2>/dev/null; do
96115ec34c4cSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9612994689c1Smrg			case $potliblink in
96135ec34c4cSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
96145ec34c4cSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9615994689c1Smrg			esac
9616994689c1Smrg		      done
9617994689c1Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9618994689c1Smrg			 $SED -e 10q |
9619994689c1Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9620f353fbadSmrg			func_append newdeplibs " $a_deplib"
96215ec34c4cSmrg			a_deplib=
9622994689c1Smrg			break 2
9623994689c1Smrg		      fi
9624994689c1Smrg		  done
9625994689c1Smrg		done
9626994689c1Smrg	      fi
96275ec34c4cSmrg	      if test -n "$a_deplib"; then
9628994689c1Smrg		droppeddeps=yes
9629994689c1Smrg		echo
9630994689c1Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9631994689c1Smrg		echo "*** I have the capability to make that library automatically link in when"
9632994689c1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9633994689c1Smrg		echo "*** shared version of the library, which you do not appear to have"
9634994689c1Smrg		echo "*** because I did check the linker path looking for a file starting"
96355ec34c4cSmrg		if test -z "$potlib"; then
9636994689c1Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9637994689c1Smrg		else
9638994689c1Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9639994689c1Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9640994689c1Smrg		fi
9641994689c1Smrg	      fi
9642994689c1Smrg	      ;;
9643994689c1Smrg	    *)
9644994689c1Smrg	      # Add a -L argument.
9645f353fbadSmrg	      func_append newdeplibs " $a_deplib"
9646994689c1Smrg	      ;;
9647994689c1Smrg	    esac
9648994689c1Smrg	  done # Gone through all deplibs.
9649994689c1Smrg	  ;;
9650994689c1Smrg	match_pattern*)
9651994689c1Smrg	  set dummy $deplibs_check_method; shift
9652994689c1Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9653994689c1Smrg	  for a_deplib in $deplibs; do
9654994689c1Smrg	    case $a_deplib in
9655994689c1Smrg	    -l*)
9656994689c1Smrg	      func_stripname -l '' "$a_deplib"
9657994689c1Smrg	      name=$func_stripname_result
96585ec34c4cSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9659994689c1Smrg		case " $predeps $postdeps " in
9660994689c1Smrg		*" $a_deplib "*)
9661f353fbadSmrg		  func_append newdeplibs " $a_deplib"
96625ec34c4cSmrg		  a_deplib=
9663994689c1Smrg		  ;;
9664994689c1Smrg		esac
9665994689c1Smrg	      fi
96665ec34c4cSmrg	      if test -n "$a_deplib"; then
9667994689c1Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9668994689c1Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9669994689c1Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9670994689c1Smrg		  for potent_lib in $potential_libs; do
96715ec34c4cSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9672994689c1Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9673994689c1Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9674f353fbadSmrg		      func_append newdeplibs " $a_deplib"
96755ec34c4cSmrg		      a_deplib=
9676994689c1Smrg		      break 2
9677994689c1Smrg		    fi
9678994689c1Smrg		  done
9679994689c1Smrg		done
9680994689c1Smrg	      fi
96815ec34c4cSmrg	      if test -n "$a_deplib"; then
9682994689c1Smrg		droppeddeps=yes
9683994689c1Smrg		echo
9684994689c1Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9685994689c1Smrg		echo "*** I have the capability to make that library automatically link in when"
9686994689c1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9687994689c1Smrg		echo "*** shared version of the library, which you do not appear to have"
9688994689c1Smrg		echo "*** because I did check the linker path looking for a file starting"
96895ec34c4cSmrg		if test -z "$potlib"; then
9690994689c1Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9691994689c1Smrg		else
9692994689c1Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9693994689c1Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9694994689c1Smrg		fi
9695994689c1Smrg	      fi
9696994689c1Smrg	      ;;
9697994689c1Smrg	    *)
9698994689c1Smrg	      # Add a -L argument.
9699f353fbadSmrg	      func_append newdeplibs " $a_deplib"
9700994689c1Smrg	      ;;
9701994689c1Smrg	    esac
9702994689c1Smrg	  done # Gone through all deplibs.
9703994689c1Smrg	  ;;
9704994689c1Smrg	none | unknown | *)
97055ec34c4cSmrg	  newdeplibs=
9706994689c1Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
97075ec34c4cSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
97085ec34c4cSmrg	    for i in $predeps $postdeps; do
9709994689c1Smrg	      # can't use Xsed below, because $i might contain '/'
97105ec34c4cSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9711994689c1Smrg	    done
9712994689c1Smrg	  fi
9713994689c1Smrg	  case $tmp_deplibs in
9714994689c1Smrg	  *[!\	\ ]*)
9715994689c1Smrg	    echo
97165ec34c4cSmrg	    if test none = "$deplibs_check_method"; then
9717994689c1Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9718994689c1Smrg	    else
9719994689c1Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9720994689c1Smrg	    fi
9721994689c1Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9722994689c1Smrg	    droppeddeps=yes
9723994689c1Smrg	    ;;
9724994689c1Smrg	  esac
9725994689c1Smrg	  ;;
9726994689c1Smrg	esac
9727994689c1Smrg	versuffix=$versuffix_save
9728994689c1Smrg	major=$major_save
9729994689c1Smrg	release=$release_save
9730994689c1Smrg	libname=$libname_save
9731994689c1Smrg	name=$name_save
9732994689c1Smrg
9733994689c1Smrg	case $host in
9734994689c1Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9735994689c1Smrg	  # On Rhapsody replace the C library with the System framework
9736994689c1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9737994689c1Smrg	  ;;
9738994689c1Smrg	esac
9739994689c1Smrg
97405ec34c4cSmrg	if test yes = "$droppeddeps"; then
97415ec34c4cSmrg	  if test yes = "$module"; then
9742994689c1Smrg	    echo
9743994689c1Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9744994689c1Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9745994689c1Smrg	    echo "*** a static module, that should work as long as the dlopening"
9746994689c1Smrg	    echo "*** application is linked with the -dlopen flag."
9747994689c1Smrg	    if test -z "$global_symbol_pipe"; then
9748994689c1Smrg	      echo
9749994689c1Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
97505ec34c4cSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9751994689c1Smrg	      echo "*** not find such a program.  So, this module is probably useless."
97525ec34c4cSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9753994689c1Smrg	    fi
97545ec34c4cSmrg	    if test no = "$build_old_libs"; then
97555ec34c4cSmrg	      oldlibs=$output_objdir/$libname.$libext
9756994689c1Smrg	      build_libtool_libs=module
9757994689c1Smrg	      build_old_libs=yes
9758994689c1Smrg	    else
9759994689c1Smrg	      build_libtool_libs=no
9760994689c1Smrg	    fi
9761994689c1Smrg	  else
9762994689c1Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9763994689c1Smrg	    echo "*** automatically added whenever a program is linked with this library"
9764994689c1Smrg	    echo "*** or is declared to -dlopen it."
9765994689c1Smrg
97665ec34c4cSmrg	    if test no = "$allow_undefined"; then
9767994689c1Smrg	      echo
9768994689c1Smrg	      echo "*** Since this library must not contain undefined symbols,"
9769994689c1Smrg	      echo "*** because either the platform does not support them or"
9770994689c1Smrg	      echo "*** it was explicitly requested with -no-undefined,"
9771994689c1Smrg	      echo "*** libtool will only create a static version of it."
97725ec34c4cSmrg	      if test no = "$build_old_libs"; then
97735ec34c4cSmrg		oldlibs=$output_objdir/$libname.$libext
9774994689c1Smrg		build_libtool_libs=module
9775994689c1Smrg		build_old_libs=yes
9776994689c1Smrg	      else
9777994689c1Smrg		build_libtool_libs=no
9778994689c1Smrg	      fi
9779994689c1Smrg	    fi
9780994689c1Smrg	  fi
9781994689c1Smrg	fi
9782994689c1Smrg	# Done checking deplibs!
9783994689c1Smrg	deplibs=$newdeplibs
9784994689c1Smrg      fi
9785994689c1Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9786994689c1Smrg      case $host in
9787994689c1Smrg	*-*-darwin*)
9788994689c1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9789994689c1Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9790994689c1Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9791994689c1Smrg	  ;;
9792994689c1Smrg      esac
9793994689c1Smrg
9794994689c1Smrg      # move library search paths that coincide with paths to not yet
9795994689c1Smrg      # installed libraries to the beginning of the library search list
9796994689c1Smrg      new_libs=
9797994689c1Smrg      for path in $notinst_path; do
9798994689c1Smrg	case " $new_libs " in
9799994689c1Smrg	*" -L$path/$objdir "*) ;;
9800994689c1Smrg	*)
9801994689c1Smrg	  case " $deplibs " in
9802994689c1Smrg	  *" -L$path/$objdir "*)
9803f353fbadSmrg	    func_append new_libs " -L$path/$objdir" ;;
9804994689c1Smrg	  esac
9805994689c1Smrg	  ;;
9806994689c1Smrg	esac
9807994689c1Smrg      done
9808994689c1Smrg      for deplib in $deplibs; do
9809994689c1Smrg	case $deplib in
9810994689c1Smrg	-L*)
9811994689c1Smrg	  case " $new_libs " in
9812994689c1Smrg	  *" $deplib "*) ;;
9813f353fbadSmrg	  *) func_append new_libs " $deplib" ;;
9814994689c1Smrg	  esac
9815994689c1Smrg	  ;;
9816f353fbadSmrg	*) func_append new_libs " $deplib" ;;
9817994689c1Smrg	esac
9818994689c1Smrg      done
98195ec34c4cSmrg      deplibs=$new_libs
9820994689c1Smrg
9821994689c1Smrg      # All the library-specific variables (install_libdir is set above).
9822994689c1Smrg      library_names=
9823994689c1Smrg      old_library=
9824994689c1Smrg      dlname=
9825994689c1Smrg
9826994689c1Smrg      # Test again, we may have decided not to build it any more
98275ec34c4cSmrg      if test yes = "$build_libtool_libs"; then
98285ec34c4cSmrg	# Remove $wl instances when linking with ld.
9829421c997bSmrg	# FIXME: should test the right _cmds variable.
9830421c997bSmrg	case $archive_cmds in
9831421c997bSmrg	  *\$LD\ *) wl= ;;
9832421c997bSmrg        esac
98335ec34c4cSmrg	if test yes = "$hardcode_into_libs"; then
9834994689c1Smrg	  # Hardcode the library paths
9835994689c1Smrg	  hardcode_libdirs=
9836994689c1Smrg	  dep_rpath=
98375ec34c4cSmrg	  rpath=$finalize_rpath
98385ec34c4cSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9839994689c1Smrg	  for libdir in $rpath; do
9840994689c1Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9841994689c1Smrg	      if test -n "$hardcode_libdir_separator"; then
9842f353fbadSmrg		func_replace_sysroot "$libdir"
9843f353fbadSmrg		libdir=$func_replace_sysroot_result
9844994689c1Smrg		if test -z "$hardcode_libdirs"; then
98455ec34c4cSmrg		  hardcode_libdirs=$libdir
9846994689c1Smrg		else
9847994689c1Smrg		  # Just accumulate the unique libdirs.
9848994689c1Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9849994689c1Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9850994689c1Smrg		    ;;
9851994689c1Smrg		  *)
9852f353fbadSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9853994689c1Smrg		    ;;
9854994689c1Smrg		  esac
9855994689c1Smrg		fi
9856994689c1Smrg	      else
9857994689c1Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9858f353fbadSmrg		func_append dep_rpath " $flag"
9859994689c1Smrg	      fi
9860994689c1Smrg	    elif test -n "$runpath_var"; then
9861994689c1Smrg	      case "$perm_rpath " in
9862994689c1Smrg	      *" $libdir "*) ;;
9863421c997bSmrg	      *) func_append perm_rpath " $libdir" ;;
9864994689c1Smrg	      esac
9865994689c1Smrg	    fi
9866994689c1Smrg	  done
9867994689c1Smrg	  # Substitute the hardcoded libdirs into the rpath.
9868994689c1Smrg	  if test -n "$hardcode_libdir_separator" &&
9869994689c1Smrg	     test -n "$hardcode_libdirs"; then
98705ec34c4cSmrg	    libdir=$hardcode_libdirs
9871421c997bSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9872994689c1Smrg	  fi
9873994689c1Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9874994689c1Smrg	    # We should set the runpath_var.
9875994689c1Smrg	    rpath=
9876994689c1Smrg	    for dir in $perm_rpath; do
9877f353fbadSmrg	      func_append rpath "$dir:"
9878994689c1Smrg	    done
9879994689c1Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9880994689c1Smrg	  fi
9881994689c1Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9882994689c1Smrg	fi
98837a84e134Smrg
98845ec34c4cSmrg	shlibpath=$finalize_shlibpath
98855ec34c4cSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9886994689c1Smrg	if test -n "$shlibpath"; then
9887994689c1Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9888994689c1Smrg	fi
98897a84e134Smrg
9890994689c1Smrg	# Get the real and link names of the library.
9891994689c1Smrg	eval shared_ext=\"$shrext_cmds\"
9892994689c1Smrg	eval library_names=\"$library_names_spec\"
9893994689c1Smrg	set dummy $library_names
9894994689c1Smrg	shift
98955ec34c4cSmrg	realname=$1
9896994689c1Smrg	shift
98977a84e134Smrg
9898994689c1Smrg	if test -n "$soname_spec"; then
9899994689c1Smrg	  eval soname=\"$soname_spec\"
9900994689c1Smrg	else
99015ec34c4cSmrg	  soname=$realname
9902994689c1Smrg	fi
9903994689c1Smrg	if test -z "$dlname"; then
9904994689c1Smrg	  dlname=$soname
9905994689c1Smrg	fi
99067a84e134Smrg
99075ec34c4cSmrg	lib=$output_objdir/$realname
9908994689c1Smrg	linknames=
9909994689c1Smrg	for link
9910994689c1Smrg	do
9911f353fbadSmrg	  func_append linknames " $link"
9912994689c1Smrg	done
99137a84e134Smrg
9914994689c1Smrg	# Use standard objects if they are pic
9915994689c1Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9916994689c1Smrg	test "X$libobjs" = "X " && libobjs=
99177a84e134Smrg
9918994689c1Smrg	delfiles=
9919994689c1Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9920994689c1Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
99215ec34c4cSmrg	  export_symbols=$output_objdir/$libname.uexp
9922f353fbadSmrg	  func_append delfiles " $export_symbols"
9923994689c1Smrg	fi
99247a84e134Smrg
9925994689c1Smrg	orig_export_symbols=
9926994689c1Smrg	case $host_os in
9927994689c1Smrg	cygwin* | mingw* | cegcc*)
9928994689c1Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9929994689c1Smrg	    # exporting using user supplied symfile
99305ec34c4cSmrg	    func_dll_def_p "$export_symbols" || {
9931994689c1Smrg	      # and it's NOT already a .def file. Must figure out
9932994689c1Smrg	      # which of the given symbols are data symbols and tag
9933994689c1Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9934994689c1Smrg	      # export_symbols gets reassigned inside the "prepare
9935994689c1Smrg	      # the list of exported symbols" if statement, so the
9936994689c1Smrg	      # include_expsyms logic still works.
99375ec34c4cSmrg	      orig_export_symbols=$export_symbols
9938994689c1Smrg	      export_symbols=
9939994689c1Smrg	      always_export_symbols=yes
99405ec34c4cSmrg	    }
9941994689c1Smrg	  fi
9942994689c1Smrg	  ;;
9943994689c1Smrg	esac
99447a84e134Smrg
9945994689c1Smrg	# Prepare the list of exported symbols
9946994689c1Smrg	if test -z "$export_symbols"; then
99475ec34c4cSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
99485ec34c4cSmrg	    func_verbose "generating symbol list for '$libname.la'"
99495ec34c4cSmrg	    export_symbols=$output_objdir/$libname.exp
9950994689c1Smrg	    $opt_dry_run || $RM $export_symbols
9951994689c1Smrg	    cmds=$export_symbols_cmds
99525ec34c4cSmrg	    save_ifs=$IFS; IFS='~'
9953f353fbadSmrg	    for cmd1 in $cmds; do
99545ec34c4cSmrg	      IFS=$save_ifs
9955f353fbadSmrg	      # Take the normal branch if the nm_file_list_spec branch
9956f353fbadSmrg	      # doesn't work or if tool conversion is not needed.
9957f353fbadSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9958f353fbadSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9959f353fbadSmrg		  try_normal_branch=yes
9960f353fbadSmrg		  eval cmd=\"$cmd1\"
9961f353fbadSmrg		  func_len " $cmd"
9962f353fbadSmrg		  len=$func_len_result
9963f353fbadSmrg		  ;;
9964f353fbadSmrg		*)
9965f353fbadSmrg		  try_normal_branch=no
9966f353fbadSmrg		  ;;
9967f353fbadSmrg	      esac
99685ec34c4cSmrg	      if test yes = "$try_normal_branch" \
9969f353fbadSmrg		 && { test "$len" -lt "$max_cmd_len" \
9970f353fbadSmrg		      || test "$max_cmd_len" -le -1; }
9971f353fbadSmrg	      then
9972f353fbadSmrg		func_show_eval "$cmd" 'exit $?'
9973f353fbadSmrg		skipped_export=false
9974f353fbadSmrg	      elif test -n "$nm_file_list_spec"; then
9975f353fbadSmrg		func_basename "$output"
9976f353fbadSmrg		output_la=$func_basename_result
9977f353fbadSmrg		save_libobjs=$libobjs
9978f353fbadSmrg		save_output=$output
99795ec34c4cSmrg		output=$output_objdir/$output_la.nm
9980f353fbadSmrg		func_to_tool_file "$output"
9981f353fbadSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9982f353fbadSmrg		func_append delfiles " $output"
9983f353fbadSmrg		func_verbose "creating $NM input file list: $output"
9984f353fbadSmrg		for obj in $save_libobjs; do
9985f353fbadSmrg		  func_to_tool_file "$obj"
9986f353fbadSmrg		  $ECHO "$func_to_tool_file_result"
9987f353fbadSmrg		done > "$output"
9988f353fbadSmrg		eval cmd=\"$cmd1\"
9989994689c1Smrg		func_show_eval "$cmd" 'exit $?'
9990f353fbadSmrg		output=$save_output
9991f353fbadSmrg		libobjs=$save_libobjs
9992994689c1Smrg		skipped_export=false
9993994689c1Smrg	      else
9994994689c1Smrg		# The command line is too long to execute in one step.
9995994689c1Smrg		func_verbose "using reloadable object file for export list..."
9996994689c1Smrg		skipped_export=:
9997994689c1Smrg		# Break out early, otherwise skipped_export may be
9998994689c1Smrg		# set to false by a later but shorter cmd.
9999994689c1Smrg		break
10000994689c1Smrg	      fi
10001994689c1Smrg	    done
100025ec34c4cSmrg	    IFS=$save_ifs
100035ec34c4cSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
10004994689c1Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10005994689c1Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10006994689c1Smrg	    fi
10007994689c1Smrg	  fi
10008994689c1Smrg	fi
100097a84e134Smrg
10010994689c1Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
100115ec34c4cSmrg	  tmp_export_symbols=$export_symbols
100125ec34c4cSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10013994689c1Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10014994689c1Smrg	fi
100157a84e134Smrg
100165ec34c4cSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10017994689c1Smrg	  # The given exports_symbols file has to be filtered, so filter it.
100185ec34c4cSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10019994689c1Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
100205ec34c4cSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10021994689c1Smrg	  # though. Also, the filter scales superlinearly with the number of
10022994689c1Smrg	  # global variables. join(1) would be nice here, but unfortunately
10023994689c1Smrg	  # isn't a blessed tool.
10024994689c1Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10025f353fbadSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10026994689c1Smrg	  export_symbols=$output_objdir/$libname.def
10027994689c1Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100287a84e134Smrg	fi
100297a84e134Smrg
10030994689c1Smrg	tmp_deplibs=
10031994689c1Smrg	for test_deplib in $deplibs; do
10032994689c1Smrg	  case " $convenience " in
10033994689c1Smrg	  *" $test_deplib "*) ;;
10034994689c1Smrg	  *)
10035f353fbadSmrg	    func_append tmp_deplibs " $test_deplib"
10036994689c1Smrg	    ;;
10037994689c1Smrg	  esac
10038994689c1Smrg	done
100395ec34c4cSmrg	deplibs=$tmp_deplibs
100407a84e134Smrg
10041994689c1Smrg	if test -n "$convenience"; then
10042994689c1Smrg	  if test -n "$whole_archive_flag_spec" &&
100435ec34c4cSmrg	    test yes = "$compiler_needs_object" &&
10044994689c1Smrg	    test -z "$libobjs"; then
10045994689c1Smrg	    # extract the archives, so we have objects to list.
10046994689c1Smrg	    # TODO: could optimize this to just extract one archive.
10047994689c1Smrg	    whole_archive_flag_spec=
10048994689c1Smrg	  fi
10049994689c1Smrg	  if test -n "$whole_archive_flag_spec"; then
10050994689c1Smrg	    save_libobjs=$libobjs
10051994689c1Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10052994689c1Smrg	    test "X$libobjs" = "X " && libobjs=
10053994689c1Smrg	  else
100545ec34c4cSmrg	    gentop=$output_objdir/${outputname}x
10055f353fbadSmrg	    func_append generated " $gentop"
100567a84e134Smrg
10057994689c1Smrg	    func_extract_archives $gentop $convenience
10058f353fbadSmrg	    func_append libobjs " $func_extract_archives_result"
10059994689c1Smrg	    test "X$libobjs" = "X " && libobjs=
10060994689c1Smrg	  fi
10061994689c1Smrg	fi
100627a84e134Smrg
100635ec34c4cSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10064994689c1Smrg	  eval flag=\"$thread_safe_flag_spec\"
10065f353fbadSmrg	  func_append linker_flags " $flag"
10066994689c1Smrg	fi
100677a84e134Smrg
10068994689c1Smrg	# Make a backup of the uninstalled library when relinking
100695ec34c4cSmrg	if test relink = "$opt_mode"; then
10070994689c1Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10071e1e1713cSmrg	fi
100727a84e134Smrg
10073994689c1Smrg	# Do each of the archive commands.
100745ec34c4cSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10075994689c1Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10076994689c1Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10077994689c1Smrg	    cmds=$module_expsym_cmds
10078994689c1Smrg	  else
10079994689c1Smrg	    eval test_cmds=\"$module_cmds\"
10080994689c1Smrg	    cmds=$module_cmds
10081994689c1Smrg	  fi
10082994689c1Smrg	else
10083994689c1Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10084994689c1Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10085994689c1Smrg	    cmds=$archive_expsym_cmds
10086994689c1Smrg	  else
10087994689c1Smrg	    eval test_cmds=\"$archive_cmds\"
10088994689c1Smrg	    cmds=$archive_cmds
10089994689c1Smrg	  fi
10090e1e1713cSmrg	fi
10091775e7de9Smrg
100925ec34c4cSmrg	if test : != "$skipped_export" &&
10093994689c1Smrg	   func_len " $test_cmds" &&
10094994689c1Smrg	   len=$func_len_result &&
10095994689c1Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10096994689c1Smrg	  :
10097994689c1Smrg	else
10098994689c1Smrg	  # The command line is too long to link in one step, link piecewise
10099994689c1Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10100994689c1Smrg	  # script.
101017a84e134Smrg
10102994689c1Smrg	  # Save the value of $output and $libobjs because we want to
10103994689c1Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10104994689c1Smrg	  # want to use save_libobjs as it was before
10105994689c1Smrg	  # whole_archive_flag_spec was expanded, because we can't
10106994689c1Smrg	  # assume the linker understands whole_archive_flag_spec.
10107994689c1Smrg	  # This may have to be revisited, in case too many
10108994689c1Smrg	  # convenience libraries get linked in and end up exceeding
10109994689c1Smrg	  # the spec.
10110994689c1Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10111994689c1Smrg	    save_libobjs=$libobjs
10112994689c1Smrg	  fi
10113994689c1Smrg	  save_output=$output
10114994689c1Smrg	  func_basename "$output"
10115994689c1Smrg	  output_la=$func_basename_result
101167a84e134Smrg
10117994689c1Smrg	  # Clear the reloadable object creation command queue and
10118994689c1Smrg	  # initialize k to one.
10119994689c1Smrg	  test_cmds=
10120994689c1Smrg	  concat_cmds=
10121994689c1Smrg	  objlist=
10122994689c1Smrg	  last_robj=
10123994689c1Smrg	  k=1
101247a84e134Smrg
101255ec34c4cSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
101265ec34c4cSmrg	    output=$output_objdir/$output_la.lnkscript
10127994689c1Smrg	    func_verbose "creating GNU ld script: $output"
10128994689c1Smrg	    echo 'INPUT (' > $output
10129994689c1Smrg	    for obj in $save_libobjs
10130994689c1Smrg	    do
10131f353fbadSmrg	      func_to_tool_file "$obj"
10132f353fbadSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10133994689c1Smrg	    done
10134994689c1Smrg	    echo ')' >> $output
10135f353fbadSmrg	    func_append delfiles " $output"
10136f353fbadSmrg	    func_to_tool_file "$output"
10137f353fbadSmrg	    output=$func_to_tool_file_result
101385ec34c4cSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
101395ec34c4cSmrg	    output=$output_objdir/$output_la.lnk
10140994689c1Smrg	    func_verbose "creating linker input file list: $output"
10141994689c1Smrg	    : > $output
10142994689c1Smrg	    set x $save_libobjs
10143994689c1Smrg	    shift
10144994689c1Smrg	    firstobj=
101455ec34c4cSmrg	    if test yes = "$compiler_needs_object"; then
10146994689c1Smrg	      firstobj="$1 "
10147994689c1Smrg	      shift
10148994689c1Smrg	    fi
10149994689c1Smrg	    for obj
10150994689c1Smrg	    do
10151f353fbadSmrg	      func_to_tool_file "$obj"
10152f353fbadSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10153994689c1Smrg	    done
10154f353fbadSmrg	    func_append delfiles " $output"
10155f353fbadSmrg	    func_to_tool_file "$output"
10156f353fbadSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10157994689c1Smrg	  else
10158994689c1Smrg	    if test -n "$save_libobjs"; then
10159994689c1Smrg	      func_verbose "creating reloadable object files..."
101605ec34c4cSmrg	      output=$output_objdir/$output_la-$k.$objext
10161994689c1Smrg	      eval test_cmds=\"$reload_cmds\"
10162994689c1Smrg	      func_len " $test_cmds"
10163994689c1Smrg	      len0=$func_len_result
10164994689c1Smrg	      len=$len0
10165994689c1Smrg
10166994689c1Smrg	      # Loop over the list of objects to be linked.
10167994689c1Smrg	      for obj in $save_libobjs
10168994689c1Smrg	      do
10169994689c1Smrg		func_len " $obj"
10170994689c1Smrg		func_arith $len + $func_len_result
10171994689c1Smrg		len=$func_arith_result
101725ec34c4cSmrg		if test -z "$objlist" ||
10173994689c1Smrg		   test "$len" -lt "$max_cmd_len"; then
10174994689c1Smrg		  func_append objlist " $obj"
10175994689c1Smrg		else
10176994689c1Smrg		  # The command $test_cmds is almost too long, add a
10177994689c1Smrg		  # command to the queue.
101785ec34c4cSmrg		  if test 1 -eq "$k"; then
10179994689c1Smrg		    # The first file doesn't have a previous command to add.
10180994689c1Smrg		    reload_objs=$objlist
10181994689c1Smrg		    eval concat_cmds=\"$reload_cmds\"
10182994689c1Smrg		  else
10183994689c1Smrg		    # All subsequent reloadable object files will link in
10184994689c1Smrg		    # the last one created.
10185994689c1Smrg		    reload_objs="$objlist $last_robj"
10186994689c1Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10187994689c1Smrg		  fi
101885ec34c4cSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10189994689c1Smrg		  func_arith $k + 1
10190994689c1Smrg		  k=$func_arith_result
101915ec34c4cSmrg		  output=$output_objdir/$output_la-$k.$objext
10192994689c1Smrg		  objlist=" $obj"
10193994689c1Smrg		  func_len " $last_robj"
10194994689c1Smrg		  func_arith $len0 + $func_len_result
10195994689c1Smrg		  len=$func_arith_result
10196994689c1Smrg		fi
10197994689c1Smrg	      done
10198994689c1Smrg	      # Handle the remaining objects by creating one last
10199994689c1Smrg	      # reloadable object file.  All subsequent reloadable object
10200994689c1Smrg	      # files will link in the last one created.
10201994689c1Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10202994689c1Smrg	      reload_objs="$objlist $last_robj"
102035ec34c4cSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10204994689c1Smrg	      if test -n "$last_robj"; then
102055ec34c4cSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10206994689c1Smrg	      fi
10207f353fbadSmrg	      func_append delfiles " $output"
10208994689c1Smrg
10209994689c1Smrg	    else
10210994689c1Smrg	      output=
10211994689c1Smrg	    fi
102127a84e134Smrg
102135ec34c4cSmrg	    ${skipped_export-false} && {
102145ec34c4cSmrg	      func_verbose "generating symbol list for '$libname.la'"
102155ec34c4cSmrg	      export_symbols=$output_objdir/$libname.exp
10216994689c1Smrg	      $opt_dry_run || $RM $export_symbols
10217994689c1Smrg	      libobjs=$output
10218994689c1Smrg	      # Append the command to create the export file.
10219994689c1Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10220994689c1Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10221994689c1Smrg	      if test -n "$last_robj"; then
10222994689c1Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10223994689c1Smrg	      fi
102245ec34c4cSmrg	    }
102257a84e134Smrg
10226994689c1Smrg	    test -n "$save_libobjs" &&
10227994689c1Smrg	      func_verbose "creating a temporary reloadable object file: $output"
102287a84e134Smrg
10229994689c1Smrg	    # Loop through the commands generated above and execute them.
102305ec34c4cSmrg	    save_ifs=$IFS; IFS='~'
10231994689c1Smrg	    for cmd in $concat_cmds; do
102325ec34c4cSmrg	      IFS=$save_ifs
102335ec34c4cSmrg	      $opt_quiet || {
102345b16253fSmrg		  func_quote_arg expand,pretty "$cmd"
102355b16253fSmrg		  eval "func_echo $func_quote_arg_result"
10236994689c1Smrg	      }
10237994689c1Smrg	      $opt_dry_run || eval "$cmd" || {
10238994689c1Smrg		lt_exit=$?
10239994689c1Smrg
10240994689c1Smrg		# Restore the uninstalled library and exit
102415ec34c4cSmrg		if test relink = "$opt_mode"; then
10242994689c1Smrg		  ( cd "$output_objdir" && \
10243994689c1Smrg		    $RM "${realname}T" && \
10244994689c1Smrg		    $MV "${realname}U" "$realname" )
10245994689c1Smrg		fi
102467a84e134Smrg
10247994689c1Smrg		exit $lt_exit
10248994689c1Smrg	      }
10249994689c1Smrg	    done
102505ec34c4cSmrg	    IFS=$save_ifs
102517a84e134Smrg
10252994689c1Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10253994689c1Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10254994689c1Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10255775e7de9Smrg	    fi
10256775e7de9Smrg	  fi
102577a84e134Smrg
102585ec34c4cSmrg          ${skipped_export-false} && {
10259994689c1Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
102605ec34c4cSmrg	      tmp_export_symbols=$export_symbols
102615ec34c4cSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10262994689c1Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10263994689c1Smrg	    fi
102647a84e134Smrg
10265994689c1Smrg	    if test -n "$orig_export_symbols"; then
10266994689c1Smrg	      # The given exports_symbols file has to be filtered, so filter it.
102675ec34c4cSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10268994689c1Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
102695ec34c4cSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10270994689c1Smrg	      # though. Also, the filter scales superlinearly with the number of
10271994689c1Smrg	      # global variables. join(1) would be nice here, but unfortunately
10272994689c1Smrg	      # isn't a blessed tool.
10273994689c1Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10274f353fbadSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10275994689c1Smrg	      export_symbols=$output_objdir/$libname.def
10276994689c1Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10277994689c1Smrg	    fi
102785ec34c4cSmrg	  }
102797a84e134Smrg
10280994689c1Smrg	  libobjs=$output
10281994689c1Smrg	  # Restore the value of output.
10282994689c1Smrg	  output=$save_output
10283e1e1713cSmrg
10284994689c1Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10285994689c1Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10286994689c1Smrg	    test "X$libobjs" = "X " && libobjs=
10287994689c1Smrg	  fi
10288994689c1Smrg	  # Expand the library linking commands again to reset the
10289994689c1Smrg	  # value of $libobjs for piecewise linking.
10290994689c1Smrg
10291994689c1Smrg	  # Do each of the archive commands.
102925ec34c4cSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10293994689c1Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10294994689c1Smrg	      cmds=$module_expsym_cmds
10295775e7de9Smrg	    else
10296994689c1Smrg	      cmds=$module_cmds
102977a84e134Smrg	    fi
102987a84e134Smrg	  else
10299994689c1Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10300994689c1Smrg	      cmds=$archive_expsym_cmds
10301994689c1Smrg	    else
10302994689c1Smrg	      cmds=$archive_cmds
10303994689c1Smrg	    fi
103047a84e134Smrg	  fi
10305775e7de9Smrg	fi
103067a84e134Smrg
10307994689c1Smrg	if test -n "$delfiles"; then
10308994689c1Smrg	  # Append the command to remove temporary files to $cmds.
10309994689c1Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10310994689c1Smrg	fi
10311775e7de9Smrg
10312994689c1Smrg	# Add any objects from preloaded convenience libraries
10313994689c1Smrg	if test -n "$dlprefiles"; then
103145ec34c4cSmrg	  gentop=$output_objdir/${outputname}x
10315f353fbadSmrg	  func_append generated " $gentop"
103167a84e134Smrg
10317994689c1Smrg	  func_extract_archives $gentop $dlprefiles
10318f353fbadSmrg	  func_append libobjs " $func_extract_archives_result"
10319994689c1Smrg	  test "X$libobjs" = "X " && libobjs=
10320775e7de9Smrg	fi
103217a84e134Smrg
103225ec34c4cSmrg	save_ifs=$IFS; IFS='~'
10323994689c1Smrg	for cmd in $cmds; do
103245ec34c4cSmrg	  IFS=$sp$nl
10325994689c1Smrg	  eval cmd=\"$cmd\"
103265ec34c4cSmrg	  IFS=$save_ifs
103275ec34c4cSmrg	  $opt_quiet || {
103285b16253fSmrg	    func_quote_arg expand,pretty "$cmd"
103295b16253fSmrg	    eval "func_echo $func_quote_arg_result"
10330994689c1Smrg	  }
10331994689c1Smrg	  $opt_dry_run || eval "$cmd" || {
10332994689c1Smrg	    lt_exit=$?
103337a84e134Smrg
10334994689c1Smrg	    # Restore the uninstalled library and exit
103355ec34c4cSmrg	    if test relink = "$opt_mode"; then
10336994689c1Smrg	      ( cd "$output_objdir" && \
10337994689c1Smrg	        $RM "${realname}T" && \
10338994689c1Smrg		$MV "${realname}U" "$realname" )
10339e1e1713cSmrg	    fi
103407a84e134Smrg
10341994689c1Smrg	    exit $lt_exit
10342994689c1Smrg	  }
10343994689c1Smrg	done
103445ec34c4cSmrg	IFS=$save_ifs
103457a84e134Smrg
10346994689c1Smrg	# Restore the uninstalled library and exit
103475ec34c4cSmrg	if test relink = "$opt_mode"; then
10348994689c1Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
103497a84e134Smrg
10350994689c1Smrg	  if test -n "$convenience"; then
10351994689c1Smrg	    if test -z "$whole_archive_flag_spec"; then
10352994689c1Smrg	      func_show_eval '${RM}r "$gentop"'
10353994689c1Smrg	    fi
10354994689c1Smrg	  fi
103557a84e134Smrg
10356994689c1Smrg	  exit $EXIT_SUCCESS
10357994689c1Smrg	fi
10358775e7de9Smrg
10359994689c1Smrg	# Create links to the real library.
10360994689c1Smrg	for linkname in $linknames; do
10361994689c1Smrg	  if test "$realname" != "$linkname"; then
10362994689c1Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10363994689c1Smrg	  fi
10364994689c1Smrg	done
10365775e7de9Smrg
10366994689c1Smrg	# If -module or -export-dynamic was specified, set the dlname.
103675ec34c4cSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10368994689c1Smrg	  # On all known operating systems, these are identical.
103695ec34c4cSmrg	  dlname=$soname
10370994689c1Smrg	fi
10371994689c1Smrg      fi
10372994689c1Smrg      ;;
10373775e7de9Smrg
10374994689c1Smrg    obj)
103755ec34c4cSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
103765ec34c4cSmrg	func_warning "'-dlopen' is ignored for objects"
10377994689c1Smrg      fi
10378775e7de9Smrg
10379994689c1Smrg      case " $deplibs" in
10380994689c1Smrg      *\ -l* | *\ -L*)
103815ec34c4cSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10382994689c1Smrg      esac
10383775e7de9Smrg
10384994689c1Smrg      test -n "$rpath" && \
103855ec34c4cSmrg	func_warning "'-rpath' is ignored for objects"
10386775e7de9Smrg
10387994689c1Smrg      test -n "$xrpath" && \
103885ec34c4cSmrg	func_warning "'-R' is ignored for objects"
10389994689c1Smrg
10390994689c1Smrg      test -n "$vinfo" && \
103915ec34c4cSmrg	func_warning "'-version-info' is ignored for objects"
103927a84e134Smrg
10393994689c1Smrg      test -n "$release" && \
103945ec34c4cSmrg	func_warning "'-release' is ignored for objects"
10395e1e1713cSmrg
10396994689c1Smrg      case $output in
10397994689c1Smrg      *.lo)
10398994689c1Smrg	test -n "$objs$old_deplibs" && \
103995ec34c4cSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10400994689c1Smrg
10401994689c1Smrg	libobj=$output
10402994689c1Smrg	func_lo2o "$libobj"
10403994689c1Smrg	obj=$func_lo2o_result
10404994689c1Smrg	;;
10405994689c1Smrg      *)
10406994689c1Smrg	libobj=
104075ec34c4cSmrg	obj=$output
10408e1e1713cSmrg	;;
10409775e7de9Smrg      esac
104107a84e134Smrg
10411994689c1Smrg      # Delete the old objects.
10412994689c1Smrg      $opt_dry_run || $RM $obj $libobj
104137a84e134Smrg
10414994689c1Smrg      # Objects from convenience libraries.  This assumes
10415994689c1Smrg      # single-version convenience libraries.  Whenever we create
10416994689c1Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10417994689c1Smrg      # the extraction.
10418994689c1Smrg      reload_conv_objs=
10419994689c1Smrg      gentop=
104205ec34c4cSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
104215ec34c4cSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
104225ec34c4cSmrg      # into space.
104235ec34c4cSmrg      case $reload_cmds in
104245ec34c4cSmrg        *\$LD[\ \$]*) wl= ;;
104255ec34c4cSmrg      esac
10426994689c1Smrg      if test -n "$convenience"; then
10427994689c1Smrg	if test -n "$whole_archive_flag_spec"; then
10428994689c1Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
104295ec34c4cSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
104305ec34c4cSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10431e1e1713cSmrg	else
104325ec34c4cSmrg	  gentop=$output_objdir/${obj}x
10433f353fbadSmrg	  func_append generated " $gentop"
10434994689c1Smrg
10435994689c1Smrg	  func_extract_archives $gentop $convenience
10436994689c1Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10437e1e1713cSmrg	fi
10438994689c1Smrg      fi
104397a84e134Smrg
10440f353fbadSmrg      # If we're not building shared, we need to use non_pic_objs
104415ec34c4cSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10442f353fbadSmrg
10443994689c1Smrg      # Create the old-style object.
104445ec34c4cSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
104457a84e134Smrg
104465ec34c4cSmrg      output=$obj
10447994689c1Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
104487a84e134Smrg
10449994689c1Smrg      # Exit if we aren't doing a library object file.
10450994689c1Smrg      if test -z "$libobj"; then
10451994689c1Smrg	if test -n "$gentop"; then
10452994689c1Smrg	  func_show_eval '${RM}r "$gentop"'
10453994689c1Smrg	fi
10454e1e1713cSmrg
10455994689c1Smrg	exit $EXIT_SUCCESS
10456e1e1713cSmrg      fi
10457e1e1713cSmrg
104585ec34c4cSmrg      test yes = "$build_libtool_libs" || {
10459994689c1Smrg	if test -n "$gentop"; then
10460994689c1Smrg	  func_show_eval '${RM}r "$gentop"'
10461994689c1Smrg	fi
10462e1e1713cSmrg
10463994689c1Smrg	# Create an invalid libtool object if no PIC, so that we don't
10464994689c1Smrg	# accidentally link it into a program.
10465994689c1Smrg	# $show "echo timestamp > $libobj"
10466994689c1Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10467994689c1Smrg	exit $EXIT_SUCCESS
104685ec34c4cSmrg      }
10469e1e1713cSmrg
104705ec34c4cSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10471994689c1Smrg	# Only do commands if we really have different PIC objects.
10472994689c1Smrg	reload_objs="$libobjs $reload_conv_objs"
104735ec34c4cSmrg	output=$libobj
10474994689c1Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10475e1e1713cSmrg      fi
10476994689c1Smrg
10477994689c1Smrg      if test -n "$gentop"; then
10478994689c1Smrg	func_show_eval '${RM}r "$gentop"'
10479994689c1Smrg      fi
10480994689c1Smrg
10481994689c1Smrg      exit $EXIT_SUCCESS
10482e1e1713cSmrg      ;;
104837a84e134Smrg
10484994689c1Smrg    prog)
10485994689c1Smrg      case $host in
10486994689c1Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10487994689c1Smrg	          output=$func_stripname_result.exe;;
10488994689c1Smrg      esac
10489994689c1Smrg      test -n "$vinfo" && \
104905ec34c4cSmrg	func_warning "'-version-info' is ignored for programs"
104917a84e134Smrg
10492994689c1Smrg      test -n "$release" && \
104935ec34c4cSmrg	func_warning "'-release' is ignored for programs"
104947a84e134Smrg
104955ec34c4cSmrg      $preload \
104965ec34c4cSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
104975ec34c4cSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10498994689c1Smrg
10499994689c1Smrg      case $host in
10500994689c1Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10501994689c1Smrg	# On Rhapsody replace the C library is the System framework
10502994689c1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10503994689c1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10504e1e1713cSmrg	;;
10505994689c1Smrg      esac
10506e1e1713cSmrg
10507994689c1Smrg      case $host in
10508994689c1Smrg      *-*-darwin*)
10509994689c1Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10510994689c1Smrg	# But is supposedly fixed on 10.4 or later (yay!).
105115ec34c4cSmrg	if test CXX = "$tagname"; then
10512994689c1Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10513994689c1Smrg	    10.[0123])
105145ec34c4cSmrg	      func_append compile_command " $wl-bind_at_load"
105155ec34c4cSmrg	      func_append finalize_command " $wl-bind_at_load"
10516994689c1Smrg	    ;;
10517994689c1Smrg	  esac
10518e1e1713cSmrg	fi
10519994689c1Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10520994689c1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10521994689c1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10522994689c1Smrg	;;
10523994689c1Smrg      esac
10524e1e1713cSmrg
10525e1e1713cSmrg
10526994689c1Smrg      # move library search paths that coincide with paths to not yet
10527994689c1Smrg      # installed libraries to the beginning of the library search list
10528994689c1Smrg      new_libs=
10529994689c1Smrg      for path in $notinst_path; do
10530994689c1Smrg	case " $new_libs " in
10531994689c1Smrg	*" -L$path/$objdir "*) ;;
10532994689c1Smrg	*)
10533994689c1Smrg	  case " $compile_deplibs " in
10534994689c1Smrg	  *" -L$path/$objdir "*)
10535f353fbadSmrg	    func_append new_libs " -L$path/$objdir" ;;
10536775e7de9Smrg	  esac
10537994689c1Smrg	  ;;
10538994689c1Smrg	esac
10539994689c1Smrg      done
10540994689c1Smrg      for deplib in $compile_deplibs; do
10541994689c1Smrg	case $deplib in
10542994689c1Smrg	-L*)
10543994689c1Smrg	  case " $new_libs " in
10544994689c1Smrg	  *" $deplib "*) ;;
10545f353fbadSmrg	  *) func_append new_libs " $deplib" ;;
10546775e7de9Smrg	  esac
10547994689c1Smrg	  ;;
10548f353fbadSmrg	*) func_append new_libs " $deplib" ;;
10549994689c1Smrg	esac
10550994689c1Smrg      done
105515ec34c4cSmrg      compile_deplibs=$new_libs
105527a84e134Smrg
10553e1e1713cSmrg
10554f353fbadSmrg      func_append compile_command " $compile_deplibs"
10555f353fbadSmrg      func_append finalize_command " $finalize_deplibs"
10556e1e1713cSmrg
10557994689c1Smrg      if test -n "$rpath$xrpath"; then
10558994689c1Smrg	# If the user specified any rpath flags, then add them.
10559994689c1Smrg	for libdir in $rpath $xrpath; do
10560994689c1Smrg	  # This is the magic to use -rpath.
10561994689c1Smrg	  case "$finalize_rpath " in
10562994689c1Smrg	  *" $libdir "*) ;;
10563f353fbadSmrg	  *) func_append finalize_rpath " $libdir" ;;
10564994689c1Smrg	  esac
10565994689c1Smrg	done
10566994689c1Smrg      fi
10567e1e1713cSmrg
10568994689c1Smrg      # Now hardcode the library paths
10569994689c1Smrg      rpath=
10570994689c1Smrg      hardcode_libdirs=
10571994689c1Smrg      for libdir in $compile_rpath $finalize_rpath; do
10572994689c1Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10573994689c1Smrg	  if test -n "$hardcode_libdir_separator"; then
10574994689c1Smrg	    if test -z "$hardcode_libdirs"; then
105755ec34c4cSmrg	      hardcode_libdirs=$libdir
10576994689c1Smrg	    else
10577994689c1Smrg	      # Just accumulate the unique libdirs.
10578994689c1Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10579994689c1Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10580994689c1Smrg		;;
10581994689c1Smrg	      *)
10582f353fbadSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10583994689c1Smrg		;;
10584994689c1Smrg	      esac
10585994689c1Smrg	    fi
10586e1e1713cSmrg	  else
10587994689c1Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10588f353fbadSmrg	    func_append rpath " $flag"
10589e1e1713cSmrg	  fi
10590994689c1Smrg	elif test -n "$runpath_var"; then
10591994689c1Smrg	  case "$perm_rpath " in
10592994689c1Smrg	  *" $libdir "*) ;;
10593f353fbadSmrg	  *) func_append perm_rpath " $libdir" ;;
10594994689c1Smrg	  esac
10595994689c1Smrg	fi
10596994689c1Smrg	case $host in
10597994689c1Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
105985ec34c4cSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10599994689c1Smrg	  case :$dllsearchpath: in
10600994689c1Smrg	  *":$libdir:"*) ;;
10601994689c1Smrg	  ::) dllsearchpath=$libdir;;
10602f353fbadSmrg	  *) func_append dllsearchpath ":$libdir";;
10603994689c1Smrg	  esac
10604994689c1Smrg	  case :$dllsearchpath: in
10605994689c1Smrg	  *":$testbindir:"*) ;;
10606994689c1Smrg	  ::) dllsearchpath=$testbindir;;
10607f353fbadSmrg	  *) func_append dllsearchpath ":$testbindir";;
10608994689c1Smrg	  esac
10609994689c1Smrg	  ;;
10610994689c1Smrg	esac
10611994689c1Smrg      done
10612994689c1Smrg      # Substitute the hardcoded libdirs into the rpath.
10613994689c1Smrg      if test -n "$hardcode_libdir_separator" &&
10614994689c1Smrg	 test -n "$hardcode_libdirs"; then
106155ec34c4cSmrg	libdir=$hardcode_libdirs
10616994689c1Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10617994689c1Smrg      fi
106185ec34c4cSmrg      compile_rpath=$rpath
10619e1e1713cSmrg
10620994689c1Smrg      rpath=
10621994689c1Smrg      hardcode_libdirs=
10622994689c1Smrg      for libdir in $finalize_rpath; do
10623994689c1Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10624994689c1Smrg	  if test -n "$hardcode_libdir_separator"; then
10625994689c1Smrg	    if test -z "$hardcode_libdirs"; then
106265ec34c4cSmrg	      hardcode_libdirs=$libdir
10627994689c1Smrg	    else
10628994689c1Smrg	      # Just accumulate the unique libdirs.
10629994689c1Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10630994689c1Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10631994689c1Smrg		;;
10632994689c1Smrg	      *)
10633f353fbadSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10634994689c1Smrg		;;
10635994689c1Smrg	      esac
10636994689c1Smrg	    fi
106377a84e134Smrg	  else
10638994689c1Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10639f353fbadSmrg	    func_append rpath " $flag"
106407a84e134Smrg	  fi
10641994689c1Smrg	elif test -n "$runpath_var"; then
10642994689c1Smrg	  case "$finalize_perm_rpath " in
10643994689c1Smrg	  *" $libdir "*) ;;
10644f353fbadSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10645994689c1Smrg	  esac
106467a84e134Smrg	fi
10647994689c1Smrg      done
10648994689c1Smrg      # Substitute the hardcoded libdirs into the rpath.
10649994689c1Smrg      if test -n "$hardcode_libdir_separator" &&
10650994689c1Smrg	 test -n "$hardcode_libdirs"; then
106515ec34c4cSmrg	libdir=$hardcode_libdirs
10652994689c1Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10653994689c1Smrg      fi
106545ec34c4cSmrg      finalize_rpath=$rpath
106557a84e134Smrg
106565ec34c4cSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10657994689c1Smrg	# Transform all the library objects into standard objects.
10658994689c1Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10659994689c1Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10660994689c1Smrg      fi
106617a84e134Smrg
106625ec34c4cSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
106637a84e134Smrg
10664994689c1Smrg      # template prelinking step
10665994689c1Smrg      if test -n "$prelink_cmds"; then
10666994689c1Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10667994689c1Smrg      fi
106687a84e134Smrg
106695ec34c4cSmrg      wrappers_required=:
10670994689c1Smrg      case $host in
10671994689c1Smrg      *cegcc* | *mingw32ce*)
10672994689c1Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
106735ec34c4cSmrg        wrappers_required=false
10674994689c1Smrg        ;;
10675994689c1Smrg      *cygwin* | *mingw* )
106765ec34c4cSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10677994689c1Smrg        ;;
10678994689c1Smrg      *)
106795ec34c4cSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
106805ec34c4cSmrg          wrappers_required=false
10681994689c1Smrg        fi
10682994689c1Smrg        ;;
10683994689c1Smrg      esac
106845ec34c4cSmrg      $wrappers_required || {
10685994689c1Smrg	# Replace the output file specification.
10686994689c1Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
106875ec34c4cSmrg	link_command=$compile_command$compile_rpath
106887a84e134Smrg
10689994689c1Smrg	# We have no uninstalled library dependencies, so finalize right now.
10690994689c1Smrg	exit_status=0
10691994689c1Smrg	func_show_eval "$link_command" 'exit_status=$?'
106927a84e134Smrg
10693f353fbadSmrg	if test -n "$postlink_cmds"; then
10694f353fbadSmrg	  func_to_tool_file "$output"
10695f353fbadSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10696f353fbadSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10697f353fbadSmrg	fi
10698f353fbadSmrg
10699994689c1Smrg	# Delete the generated files.
107005ec34c4cSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
107015ec34c4cSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
107027a84e134Smrg	fi
107037a84e134Smrg
10704994689c1Smrg	exit $exit_status
107055ec34c4cSmrg      }
107067a84e134Smrg
10707994689c1Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10708994689c1Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10709994689c1Smrg      fi
10710994689c1Smrg      if test -n "$finalize_shlibpath"; then
10711994689c1Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10712994689c1Smrg      fi
10713e1e1713cSmrg
10714994689c1Smrg      compile_var=
10715994689c1Smrg      finalize_var=
10716994689c1Smrg      if test -n "$runpath_var"; then
10717994689c1Smrg	if test -n "$perm_rpath"; then
10718994689c1Smrg	  # We should set the runpath_var.
10719994689c1Smrg	  rpath=
10720994689c1Smrg	  for dir in $perm_rpath; do
10721f353fbadSmrg	    func_append rpath "$dir:"
10722994689c1Smrg	  done
10723994689c1Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
107247a84e134Smrg	fi
10725994689c1Smrg	if test -n "$finalize_perm_rpath"; then
10726994689c1Smrg	  # We should set the runpath_var.
10727994689c1Smrg	  rpath=
10728994689c1Smrg	  for dir in $finalize_perm_rpath; do
10729f353fbadSmrg	    func_append rpath "$dir:"
10730994689c1Smrg	  done
10731994689c1Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
107327a84e134Smrg	fi
10733994689c1Smrg      fi
107347a84e134Smrg
107355ec34c4cSmrg      if test yes = "$no_install"; then
10736994689c1Smrg	# We don't need to create a wrapper script.
107375ec34c4cSmrg	link_command=$compile_var$compile_command$compile_rpath
10738994689c1Smrg	# Replace the output file specification.
10739994689c1Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10740994689c1Smrg	# Delete the old output file.
10741994689c1Smrg	$opt_dry_run || $RM $output
10742994689c1Smrg	# Link the executable and exit
10743994689c1Smrg	func_show_eval "$link_command" 'exit $?'
10744f353fbadSmrg
10745f353fbadSmrg	if test -n "$postlink_cmds"; then
10746f353fbadSmrg	  func_to_tool_file "$output"
10747f353fbadSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10748f353fbadSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10749f353fbadSmrg	fi
10750f353fbadSmrg
10751e1e1713cSmrg	exit $EXIT_SUCCESS
10752994689c1Smrg      fi
10753775e7de9Smrg
107545ec34c4cSmrg      case $hardcode_action,$fast_install in
107555ec34c4cSmrg        relink,*)
107565ec34c4cSmrg	  # Fast installation is not supported
107575ec34c4cSmrg	  link_command=$compile_var$compile_command$compile_rpath
107585ec34c4cSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10759994689c1Smrg
107605ec34c4cSmrg	  func_warning "this platform does not like uninstalled shared libraries"
107615ec34c4cSmrg	  func_warning "'$output' will be relinked during installation"
107625ec34c4cSmrg	  ;;
107635ec34c4cSmrg        *,yes)
107645ec34c4cSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107655ec34c4cSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
107665ec34c4cSmrg          ;;
107675ec34c4cSmrg	*,no)
107685ec34c4cSmrg	  link_command=$compile_var$compile_command$compile_rpath
107695ec34c4cSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107705ec34c4cSmrg          ;;
107715ec34c4cSmrg	*,needless)
107725ec34c4cSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107735ec34c4cSmrg	  relink_command=
107745ec34c4cSmrg          ;;
107755ec34c4cSmrg      esac
107767a84e134Smrg
10777994689c1Smrg      # Replace the output file specification.
10778994689c1Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
107797a84e134Smrg
10780994689c1Smrg      # Delete the old output files.
10781994689c1Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
107827a84e134Smrg
10783994689c1Smrg      func_show_eval "$link_command" 'exit $?'
10784e1e1713cSmrg
10785f353fbadSmrg      if test -n "$postlink_cmds"; then
10786f353fbadSmrg	func_to_tool_file "$output_objdir/$outputname"
10787f353fbadSmrg	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'`
10788f353fbadSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10789f353fbadSmrg      fi
10790f353fbadSmrg
10791994689c1Smrg      # Now create the wrapper script.
10792994689c1Smrg      func_verbose "creating $output"
10793e1e1713cSmrg
10794994689c1Smrg      # Quote the relink command for shipping.
10795994689c1Smrg      if test -n "$relink_command"; then
10796994689c1Smrg	# Preserve any variables that may affect compiler behavior
10797994689c1Smrg	for var in $variables_saved_for_relink; do
10798994689c1Smrg	  if eval test -z \"\${$var+set}\"; then
10799994689c1Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10800994689c1Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10801994689c1Smrg	    relink_command="$var=; export $var; $relink_command"
108027a84e134Smrg	  else
108035b16253fSmrg	    func_quote_arg pretty "$var_value"
108045b16253fSmrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
108057a84e134Smrg	  fi
10806994689c1Smrg	done
108075b16253fSmrg	func_quote eval cd "`pwd`"
108085b16253fSmrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
108095b16253fSmrg	relink_command=$func_quote_arg_unquoted_result
10810994689c1Smrg      fi
10811775e7de9Smrg
10812994689c1Smrg      # Only actually do things if not in dry run mode.
10813994689c1Smrg      $opt_dry_run || {
10814994689c1Smrg	# win32 will think the script is a binary if it has
10815994689c1Smrg	# a .exe suffix, so we strip it off here.
10816994689c1Smrg	case $output in
10817994689c1Smrg	  *.exe) func_stripname '' '.exe' "$output"
10818994689c1Smrg	         output=$func_stripname_result ;;
10819994689c1Smrg	esac
10820994689c1Smrg	# test for cygwin because mv fails w/o .exe extensions
10821994689c1Smrg	case $host in
10822994689c1Smrg	  *cygwin*)
10823994689c1Smrg	    exeext=.exe
10824994689c1Smrg	    func_stripname '' '.exe' "$outputname"
10825994689c1Smrg	    outputname=$func_stripname_result ;;
10826994689c1Smrg	  *) exeext= ;;
108277a84e134Smrg	esac
10828994689c1Smrg	case $host in
10829994689c1Smrg	  *cygwin* | *mingw* )
10830994689c1Smrg	    func_dirname_and_basename "$output" "" "."
10831994689c1Smrg	    output_name=$func_basename_result
10832994689c1Smrg	    output_path=$func_dirname_result
108335ec34c4cSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
108345ec34c4cSmrg	    cwrapper=$output_path/$output_name.exe
10835994689c1Smrg	    $RM $cwrappersource $cwrapper
10836994689c1Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10837994689c1Smrg
10838994689c1Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10839994689c1Smrg
10840994689c1Smrg	    # The wrapper executable is built using the $host compiler,
10841994689c1Smrg	    # because it contains $host paths and files. If cross-
10842994689c1Smrg	    # compiling, it, like the target executable, must be
10843994689c1Smrg	    # executed on the $host or under an emulation environment.
10844994689c1Smrg	    $opt_dry_run || {
10845994689c1Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10846994689c1Smrg	      $STRIP $cwrapper
10847994689c1Smrg	    }
108487a84e134Smrg
10849994689c1Smrg	    # Now, create the wrapper script for func_source use:
10850994689c1Smrg	    func_ltwrapper_scriptname $cwrapper
10851994689c1Smrg	    $RM $func_ltwrapper_scriptname_result
10852994689c1Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10853994689c1Smrg	    $opt_dry_run || {
10854994689c1Smrg	      # note: this script will not be executed, so do not chmod.
108555ec34c4cSmrg	      if test "x$build" = "x$host"; then
10856994689c1Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10857994689c1Smrg	      else
10858994689c1Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10859994689c1Smrg	      fi
10860994689c1Smrg	    }
10861994689c1Smrg	  ;;
10862994689c1Smrg	  * )
10863994689c1Smrg	    $RM $output
10864994689c1Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
108657a84e134Smrg
10866994689c1Smrg	    func_emit_wrapper no > $output
10867994689c1Smrg	    chmod +x $output
10868994689c1Smrg	  ;;
10869994689c1Smrg	esac
10870994689c1Smrg      }
10871994689c1Smrg      exit $EXIT_SUCCESS
10872994689c1Smrg      ;;
10873994689c1Smrg    esac
108747a84e134Smrg
10875994689c1Smrg    # See if we need to build an old-fashioned archive.
10876994689c1Smrg    for oldlib in $oldlibs; do
108777a84e134Smrg
108785ec34c4cSmrg      case $build_libtool_libs in
108795ec34c4cSmrg        convenience)
108805ec34c4cSmrg	  oldobjs="$libobjs_save $symfileobj"
108815ec34c4cSmrg	  addlibs=$convenience
10882994689c1Smrg	  build_libtool_libs=no
108835ec34c4cSmrg	  ;;
108845ec34c4cSmrg	module)
108855ec34c4cSmrg	  oldobjs=$libobjs_save
108865ec34c4cSmrg	  addlibs=$old_convenience
108875ec34c4cSmrg	  build_libtool_libs=no
108885ec34c4cSmrg          ;;
108895ec34c4cSmrg	*)
10890994689c1Smrg	  oldobjs="$old_deplibs $non_pic_objects"
108915ec34c4cSmrg	  $preload && test -f "$symfileobj" \
108925ec34c4cSmrg	    && func_append oldobjs " $symfileobj"
108935ec34c4cSmrg	  addlibs=$old_convenience
108945ec34c4cSmrg	  ;;
108955ec34c4cSmrg      esac
108967a84e134Smrg
10897994689c1Smrg      if test -n "$addlibs"; then
108985ec34c4cSmrg	gentop=$output_objdir/${outputname}x
10899f353fbadSmrg	func_append generated " $gentop"
109007a84e134Smrg
10901994689c1Smrg	func_extract_archives $gentop $addlibs
10902f353fbadSmrg	func_append oldobjs " $func_extract_archives_result"
10903994689c1Smrg      fi
109047a84e134Smrg
10905994689c1Smrg      # Do each command in the archive commands.
109065ec34c4cSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10907994689c1Smrg	cmds=$old_archive_from_new_cmds
10908994689c1Smrg      else
109097a84e134Smrg
10910994689c1Smrg	# Add any objects from preloaded convenience libraries
10911994689c1Smrg	if test -n "$dlprefiles"; then
109125ec34c4cSmrg	  gentop=$output_objdir/${outputname}x
10913f353fbadSmrg	  func_append generated " $gentop"
109147a84e134Smrg
10915994689c1Smrg	  func_extract_archives $gentop $dlprefiles
10916f353fbadSmrg	  func_append oldobjs " $func_extract_archives_result"
10917994689c1Smrg	fi
109187a84e134Smrg
10919994689c1Smrg	# POSIX demands no paths to be encoded in archives.  We have
10920994689c1Smrg	# to avoid creating archives with duplicate basenames if we
10921994689c1Smrg	# might have to extract them afterwards, e.g., when creating a
10922994689c1Smrg	# static archive out of a convenience library, or when linking
10923994689c1Smrg	# the entirety of a libtool archive into another (currently
10924994689c1Smrg	# not supported by libtool).
10925994689c1Smrg	if (for obj in $oldobjs
10926994689c1Smrg	    do
10927994689c1Smrg	      func_basename "$obj"
10928994689c1Smrg	      $ECHO "$func_basename_result"
10929994689c1Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10930994689c1Smrg	  :
10931994689c1Smrg	else
10932994689c1Smrg	  echo "copying selected object files to avoid basename conflicts..."
109335ec34c4cSmrg	  gentop=$output_objdir/${outputname}x
10934f353fbadSmrg	  func_append generated " $gentop"
10935994689c1Smrg	  func_mkdir_p "$gentop"
10936994689c1Smrg	  save_oldobjs=$oldobjs
10937994689c1Smrg	  oldobjs=
10938994689c1Smrg	  counter=1
10939994689c1Smrg	  for obj in $save_oldobjs
10940994689c1Smrg	  do
10941994689c1Smrg	    func_basename "$obj"
109425ec34c4cSmrg	    objbase=$func_basename_result
10943994689c1Smrg	    case " $oldobjs " in
10944994689c1Smrg	    " ") oldobjs=$obj ;;
10945994689c1Smrg	    *[\ /]"$objbase "*)
10946994689c1Smrg	      while :; do
10947994689c1Smrg		# Make sure we don't pick an alternate name that also
10948994689c1Smrg		# overlaps.
10949994689c1Smrg		newobj=lt$counter-$objbase
10950994689c1Smrg		func_arith $counter + 1
10951994689c1Smrg		counter=$func_arith_result
10952994689c1Smrg		case " $oldobjs " in
10953994689c1Smrg		*[\ /]"$newobj "*) ;;
10954994689c1Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10955994689c1Smrg		esac
10956994689c1Smrg	      done
10957994689c1Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10958f353fbadSmrg	      func_append oldobjs " $gentop/$newobj"
10959994689c1Smrg	      ;;
10960f353fbadSmrg	    *) func_append oldobjs " $obj" ;;
10961994689c1Smrg	    esac
109627a84e134Smrg	  done
10963775e7de9Smrg	fi
10964421c997bSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10965421c997bSmrg	tool_oldlib=$func_to_tool_file_result
10966994689c1Smrg	eval cmds=\"$old_archive_cmds\"
10967e1e1713cSmrg
10968994689c1Smrg	func_len " $cmds"
10969994689c1Smrg	len=$func_len_result
10970994689c1Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10971994689c1Smrg	  cmds=$old_archive_cmds
10972f353fbadSmrg	elif test -n "$archiver_list_spec"; then
10973f353fbadSmrg	  func_verbose "using command file archive linking..."
10974f353fbadSmrg	  for obj in $oldobjs
10975f353fbadSmrg	  do
10976f353fbadSmrg	    func_to_tool_file "$obj"
10977f353fbadSmrg	    $ECHO "$func_to_tool_file_result"
10978f353fbadSmrg	  done > $output_objdir/$libname.libcmd
10979f353fbadSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10980f353fbadSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10981f353fbadSmrg	  cmds=$old_archive_cmds
10982994689c1Smrg	else
10983994689c1Smrg	  # the command line is too long to link in one step, link in parts
10984994689c1Smrg	  func_verbose "using piecewise archive linking..."
10985994689c1Smrg	  save_RANLIB=$RANLIB
10986994689c1Smrg	  RANLIB=:
10987994689c1Smrg	  objlist=
10988994689c1Smrg	  concat_cmds=
10989994689c1Smrg	  save_oldobjs=$oldobjs
10990994689c1Smrg	  oldobjs=
10991994689c1Smrg	  # Is there a better way of finding the last object in the list?
10992994689c1Smrg	  for obj in $save_oldobjs
10993994689c1Smrg	  do
10994994689c1Smrg	    last_oldobj=$obj
10995994689c1Smrg	  done
10996994689c1Smrg	  eval test_cmds=\"$old_archive_cmds\"
10997994689c1Smrg	  func_len " $test_cmds"
10998994689c1Smrg	  len0=$func_len_result
10999994689c1Smrg	  len=$len0
11000994689c1Smrg	  for obj in $save_oldobjs
11001994689c1Smrg	  do
11002994689c1Smrg	    func_len " $obj"
11003994689c1Smrg	    func_arith $len + $func_len_result
11004994689c1Smrg	    len=$func_arith_result
11005994689c1Smrg	    func_append objlist " $obj"
11006994689c1Smrg	    if test "$len" -lt "$max_cmd_len"; then
11007994689c1Smrg	      :
11008994689c1Smrg	    else
11009994689c1Smrg	      # the above command should be used before it gets too long
11010994689c1Smrg	      oldobjs=$objlist
110115ec34c4cSmrg	      if test "$obj" = "$last_oldobj"; then
11012994689c1Smrg		RANLIB=$save_RANLIB
11013994689c1Smrg	      fi
11014994689c1Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
110155ec34c4cSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11016994689c1Smrg	      objlist=
11017994689c1Smrg	      len=$len0
11018994689c1Smrg	    fi
11019994689c1Smrg	  done
11020994689c1Smrg	  RANLIB=$save_RANLIB
11021994689c1Smrg	  oldobjs=$objlist
110225ec34c4cSmrg	  if test -z "$oldobjs"; then
11023994689c1Smrg	    eval cmds=\"\$concat_cmds\"
11024994689c1Smrg	  else
11025994689c1Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11026994689c1Smrg	  fi
11027994689c1Smrg	fi
11028994689c1Smrg      fi
11029994689c1Smrg      func_execute_cmds "$cmds" 'exit $?'
110307a84e134Smrg    done
110317a84e134Smrg
11032994689c1Smrg    test -n "$generated" && \
11033994689c1Smrg      func_show_eval "${RM}r$generated"
110347a84e134Smrg
11035994689c1Smrg    # Now create the libtool archive.
11036994689c1Smrg    case $output in
11037994689c1Smrg    *.la)
11038994689c1Smrg      old_library=
110395ec34c4cSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11040994689c1Smrg      func_verbose "creating $output"
11041775e7de9Smrg
11042994689c1Smrg      # Preserve any variables that may affect compiler behavior
11043994689c1Smrg      for var in $variables_saved_for_relink; do
11044994689c1Smrg	if eval test -z \"\${$var+set}\"; then
11045994689c1Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11046994689c1Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11047994689c1Smrg	  relink_command="$var=; export $var; $relink_command"
11048e1e1713cSmrg	else
110495b16253fSmrg	  func_quote_arg pretty,unquoted "$var_value"
110505b16253fSmrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11051e1e1713cSmrg	fi
11052994689c1Smrg      done
11053994689c1Smrg      # Quote the link command for shipping.
110545b16253fSmrg      func_quote eval cd "`pwd`"
110555b16253fSmrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
110565b16253fSmrg      func_quote_arg pretty,unquoted "$relink_command"
110575b16253fSmrg      relink_command=$func_quote_arg_unquoted_result
110585ec34c4cSmrg      if test yes = "$hardcode_automatic"; then
11059994689c1Smrg	relink_command=
11060994689c1Smrg      fi
110617a84e134Smrg
11062994689c1Smrg      # Only create the output if not a dry run.
11063994689c1Smrg      $opt_dry_run || {
11064994689c1Smrg	for installed in no yes; do
110655ec34c4cSmrg	  if test yes = "$installed"; then
11066994689c1Smrg	    if test -z "$install_libdir"; then
11067994689c1Smrg	      break
11068994689c1Smrg	    fi
110695ec34c4cSmrg	    output=$output_objdir/${outputname}i
11070994689c1Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11071994689c1Smrg	    newdependency_libs=
11072994689c1Smrg	    for deplib in $dependency_libs; do
11073994689c1Smrg	      case $deplib in
11074994689c1Smrg	      *.la)
11075994689c1Smrg		func_basename "$deplib"
110765ec34c4cSmrg		name=$func_basename_result
11077421c997bSmrg		func_resolve_sysroot "$deplib"
110785ec34c4cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11079994689c1Smrg		test -z "$libdir" && \
110805ec34c4cSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11081f353fbadSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11082f353fbadSmrg		;;
11083f353fbadSmrg	      -L*)
11084f353fbadSmrg		func_stripname -L '' "$deplib"
11085f353fbadSmrg		func_replace_sysroot "$func_stripname_result"
11086f353fbadSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11087f353fbadSmrg		;;
11088f353fbadSmrg	      -R*)
11089f353fbadSmrg		func_stripname -R '' "$deplib"
11090f353fbadSmrg		func_replace_sysroot "$func_stripname_result"
11091f353fbadSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11092994689c1Smrg		;;
11093f353fbadSmrg	      *) func_append newdependency_libs " $deplib" ;;
11094994689c1Smrg	      esac
11095994689c1Smrg	    done
110965ec34c4cSmrg	    dependency_libs=$newdependency_libs
11097994689c1Smrg	    newdlfiles=
11098994689c1Smrg
11099994689c1Smrg	    for lib in $dlfiles; do
11100994689c1Smrg	      case $lib in
11101994689c1Smrg	      *.la)
11102994689c1Smrg	        func_basename "$lib"
111035ec34c4cSmrg		name=$func_basename_result
111045ec34c4cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11105994689c1Smrg		test -z "$libdir" && \
111065ec34c4cSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11107f353fbadSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11108994689c1Smrg		;;
11109f353fbadSmrg	      *) func_append newdlfiles " $lib" ;;
11110994689c1Smrg	      esac
11111994689c1Smrg	    done
111125ec34c4cSmrg	    dlfiles=$newdlfiles
11113994689c1Smrg	    newdlprefiles=
11114994689c1Smrg	    for lib in $dlprefiles; do
11115994689c1Smrg	      case $lib in
11116994689c1Smrg	      *.la)
11117994689c1Smrg		# Only pass preopened files to the pseudo-archive (for
11118994689c1Smrg		# eventual linking with the app. that links it) if we
11119994689c1Smrg		# didn't already link the preopened objects directly into
11120994689c1Smrg		# the library:
11121994689c1Smrg		func_basename "$lib"
111225ec34c4cSmrg		name=$func_basename_result
111235ec34c4cSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11124994689c1Smrg		test -z "$libdir" && \
111255ec34c4cSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11126f353fbadSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11127994689c1Smrg		;;
11128994689c1Smrg	      esac
11129994689c1Smrg	    done
111305ec34c4cSmrg	    dlprefiles=$newdlprefiles
11131994689c1Smrg	  else
11132994689c1Smrg	    newdlfiles=
11133994689c1Smrg	    for lib in $dlfiles; do
11134994689c1Smrg	      case $lib in
111355ec34c4cSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11136994689c1Smrg		*) abs=`pwd`"/$lib" ;;
11137994689c1Smrg	      esac
11138f353fbadSmrg	      func_append newdlfiles " $abs"
11139994689c1Smrg	    done
111405ec34c4cSmrg	    dlfiles=$newdlfiles
11141994689c1Smrg	    newdlprefiles=
11142994689c1Smrg	    for lib in $dlprefiles; do
11143994689c1Smrg	      case $lib in
111445ec34c4cSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11145994689c1Smrg		*) abs=`pwd`"/$lib" ;;
11146994689c1Smrg	      esac
11147f353fbadSmrg	      func_append newdlprefiles " $abs"
11148994689c1Smrg	    done
111495ec34c4cSmrg	    dlprefiles=$newdlprefiles
11150994689c1Smrg	  fi
11151994689c1Smrg	  $RM $output
11152994689c1Smrg	  # place dlname in correct position for cygwin
11153994689c1Smrg	  # In fact, it would be nice if we could use this code for all target
11154994689c1Smrg	  # systems that can't hard-code library paths into their executables
11155994689c1Smrg	  # and that have no shared library path variable independent of PATH,
11156994689c1Smrg	  # but it turns out we can't easily determine that from inspecting
11157994689c1Smrg	  # libtool variables, so we have to hard-code the OSs to which it
11158994689c1Smrg	  # applies here; at the moment, that means platforms that use the PE
11159994689c1Smrg	  # object format with DLL files.  See the long comment at the top of
11160994689c1Smrg	  # tests/bindir.at for full details.
11161994689c1Smrg	  tdlname=$dlname
11162994689c1Smrg	  case $host,$output,$installed,$module,$dlname in
11163994689c1Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11164994689c1Smrg	      # If a -bindir argument was supplied, place the dll there.
111655ec34c4cSmrg	      if test -n "$bindir"; then
11166994689c1Smrg		func_relative_path "$install_libdir" "$bindir"
111675ec34c4cSmrg		tdlname=$func_relative_path_result/$dlname
11168994689c1Smrg	      else
11169994689c1Smrg		# Otherwise fall back on heuristic.
11170994689c1Smrg		tdlname=../bin/$dlname
11171994689c1Smrg	      fi
11172994689c1Smrg	      ;;
11173994689c1Smrg	  esac
11174994689c1Smrg	  $ECHO > $output "\
11175994689c1Smrg# $outputname - a libtool library file
111765ec34c4cSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11177994689c1Smrg#
11178994689c1Smrg# Please DO NOT delete this file!
11179994689c1Smrg# It is necessary for linking the library.
111807a84e134Smrg
11181994689c1Smrg# The name that we can dlopen(3).
11182994689c1Smrgdlname='$tdlname'
111837a84e134Smrg
11184994689c1Smrg# Names of this library.
11185994689c1Smrglibrary_names='$library_names'
111867a84e134Smrg
11187994689c1Smrg# The name of the static archive.
11188994689c1Smrgold_library='$old_library'
111897a84e134Smrg
111905ec34c4cSmrg# Linker flags that cannot go in dependency_libs.
11191994689c1Smrginherited_linker_flags='$new_inherited_linker_flags'
111927a84e134Smrg
11193994689c1Smrg# Libraries that this one depends upon.
11194994689c1Smrgdependency_libs='$dependency_libs'
111957a84e134Smrg
11196994689c1Smrg# Names of additional weak libraries provided by this library
11197994689c1Smrgweak_library_names='$weak_libs'
111987a84e134Smrg
11199994689c1Smrg# Version information for $libname.
11200994689c1Smrgcurrent=$current
11201994689c1Smrgage=$age
11202994689c1Smrgrevision=$revision
112037a84e134Smrg
11204994689c1Smrg# Is this an already installed library?
11205994689c1Smrginstalled=$installed
112067a84e134Smrg
11207994689c1Smrg# Should we warn about portability when linking against -modules?
11208994689c1Smrgshouldnotlink=$module
112097a84e134Smrg
11210994689c1Smrg# Files to dlopen/dlpreopen
11211994689c1Smrgdlopen='$dlfiles'
11212994689c1Smrgdlpreopen='$dlprefiles'
112137a84e134Smrg
11214994689c1Smrg# Directory that this library needs to be installed in:
11215994689c1Smrglibdir='$install_libdir'"
112165ec34c4cSmrg	  if test no,yes = "$installed,$need_relink"; then
11217994689c1Smrg	    $ECHO >> $output "\
11218994689c1Smrgrelink_command=\"$relink_command\""
11219994689c1Smrg	  fi
11220994689c1Smrg	done
11221994689c1Smrg      }
112227a84e134Smrg
11223994689c1Smrg      # Do a symbolic link so that the libtool archive can be found in
11224994689c1Smrg      # LD_LIBRARY_PATH before the program is installed.
11225994689c1Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11226994689c1Smrg      ;;
11227994689c1Smrg    esac
11228994689c1Smrg    exit $EXIT_SUCCESS
11229994689c1Smrg}
11230e1e1713cSmrg
112315ec34c4cSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
112325ec34c4cSmrg  func_mode_link ${1+"$@"}
112335ec34c4cSmrgfi
112347a84e134Smrg
112357a84e134Smrg
11236994689c1Smrg# func_mode_uninstall arg...
11237994689c1Smrgfunc_mode_uninstall ()
11238994689c1Smrg{
112395ec34c4cSmrg    $debug_cmd
112405ec34c4cSmrg
112415ec34c4cSmrg    RM=$nonopt
112427a84e134Smrg    files=
112435ec34c4cSmrg    rmforce=false
112447a84e134Smrg    exit_status=0
112457a84e134Smrg
112467a84e134Smrg    # This variable tells wrapper scripts just to set variables rather
112477a84e134Smrg    # than running their programs.
112485ec34c4cSmrg    libtool_install_magic=$magic
112497a84e134Smrg
112507a84e134Smrg    for arg
112517a84e134Smrg    do
112527a84e134Smrg      case $arg in
112535ec34c4cSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11254f353fbadSmrg      -*) func_append RM " $arg" ;;
11255f353fbadSmrg      *) func_append files " $arg" ;;
112567a84e134Smrg      esac
112577a84e134Smrg    done
112587a84e134Smrg
11259994689c1Smrg    test -z "$RM" && \
11260994689c1Smrg      func_fatal_help "you must specify an RM program"
112617a84e134Smrg
112627a84e134Smrg    rmdirs=
112637a84e134Smrg
112647a84e134Smrg    for file in $files; do
11265994689c1Smrg      func_dirname "$file" "" "."
112665ec34c4cSmrg      dir=$func_dirname_result
112675ec34c4cSmrg      if test . = "$dir"; then
112685ec34c4cSmrg	odir=$objdir
112697a84e134Smrg      else
112705ec34c4cSmrg	odir=$dir/$objdir
112717a84e134Smrg      fi
11272994689c1Smrg      func_basename "$file"
112735ec34c4cSmrg      name=$func_basename_result
112745ec34c4cSmrg      test uninstall = "$opt_mode" && odir=$dir
112757a84e134Smrg
11276f353fbadSmrg      # Remember odir for removal later, being careful to avoid duplicates
112775ec34c4cSmrg      if test clean = "$opt_mode"; then
112787a84e134Smrg	case " $rmdirs " in
11279f353fbadSmrg	  *" $odir "*) ;;
11280f353fbadSmrg	  *) func_append rmdirs " $odir" ;;
112817a84e134Smrg	esac
112827a84e134Smrg      fi
112837a84e134Smrg
112847a84e134Smrg      # Don't error if the file doesn't exist and rm -f was used.
11285994689c1Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11286994689c1Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11287994689c1Smrg	 test -f "$file"; then
112887a84e134Smrg	:
112897a84e134Smrg      elif test -d "$file"; then
112907a84e134Smrg	exit_status=1
112917a84e134Smrg	continue
112925ec34c4cSmrg      elif $rmforce; then
112937a84e134Smrg	continue
112947a84e134Smrg      fi
112957a84e134Smrg
112965ec34c4cSmrg      rmfiles=$file
112977a84e134Smrg
112987a84e134Smrg      case $name in
112997a84e134Smrg      *.la)
113007a84e134Smrg	# Possibly a libtool archive, so verify it.
11301994689c1Smrg	if func_lalib_p "$file"; then
11302994689c1Smrg	  func_source $dir/$name
113037a84e134Smrg
113047a84e134Smrg	  # Delete the libtool libraries and symlinks.
113057a84e134Smrg	  for n in $library_names; do
11306f353fbadSmrg	    func_append rmfiles " $odir/$n"
113077a84e134Smrg	  done
11308f353fbadSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
113097a84e134Smrg
113105ec34c4cSmrg	  case $opt_mode in
113117a84e134Smrg	  clean)
11312f353fbadSmrg	    case " $library_names " in
113137a84e134Smrg	    *" $dlname "*) ;;
11314f353fbadSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
113157a84e134Smrg	    esac
11316f353fbadSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
113177a84e134Smrg	    ;;
113187a84e134Smrg	  uninstall)
113197a84e134Smrg	    if test -n "$library_names"; then
113207a84e134Smrg	      # Do each command in the postuninstall commands.
113215ec34c4cSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113227a84e134Smrg	    fi
113237a84e134Smrg
113247a84e134Smrg	    if test -n "$old_library"; then
113257a84e134Smrg	      # Do each command in the old_postuninstall commands.
113265ec34c4cSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
113277a84e134Smrg	    fi
113287a84e134Smrg	    # FIXME: should reinstall the best remaining shared library.
113297a84e134Smrg	    ;;
113307a84e134Smrg	  esac
113317a84e134Smrg	fi
113327a84e134Smrg	;;
113337a84e134Smrg
113347a84e134Smrg      *.lo)
113357a84e134Smrg	# Possibly a libtool object, so verify it.
11336994689c1Smrg	if func_lalib_p "$file"; then
113377a84e134Smrg
113387a84e134Smrg	  # Read the .lo file
11339994689c1Smrg	  func_source $dir/$name
113407a84e134Smrg
113417a84e134Smrg	  # Add PIC object to the list of files to remove.
113425ec34c4cSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11343f353fbadSmrg	    func_append rmfiles " $dir/$pic_object"
113447a84e134Smrg	  fi
113457a84e134Smrg
113467a84e134Smrg	  # Add non-PIC object to the list of files to remove.
113475ec34c4cSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11348f353fbadSmrg	    func_append rmfiles " $dir/$non_pic_object"
113497a84e134Smrg	  fi
113507a84e134Smrg	fi
113517a84e134Smrg	;;
113527a84e134Smrg
113537a84e134Smrg      *)
113545ec34c4cSmrg	if test clean = "$opt_mode"; then
113557a84e134Smrg	  noexename=$name
113567a84e134Smrg	  case $file in
113577a84e134Smrg	  *.exe)
11358994689c1Smrg	    func_stripname '' '.exe' "$file"
11359994689c1Smrg	    file=$func_stripname_result
11360994689c1Smrg	    func_stripname '' '.exe' "$name"
11361994689c1Smrg	    noexename=$func_stripname_result
113627a84e134Smrg	    # $file with .exe has already been added to rmfiles,
113637a84e134Smrg	    # add $file without .exe
11364f353fbadSmrg	    func_append rmfiles " $file"
113657a84e134Smrg	    ;;
113667a84e134Smrg	  esac
113677a84e134Smrg	  # Do a test to see if this is a libtool program.
11368994689c1Smrg	  if func_ltwrapper_p "$file"; then
11369994689c1Smrg	    if func_ltwrapper_executable_p "$file"; then
11370994689c1Smrg	      func_ltwrapper_scriptname "$file"
11371994689c1Smrg	      relink_command=
11372994689c1Smrg	      func_source $func_ltwrapper_scriptname_result
11373f353fbadSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11374994689c1Smrg	    else
11375994689c1Smrg	      relink_command=
11376994689c1Smrg	      func_source $dir/$noexename
11377994689c1Smrg	    fi
113787a84e134Smrg
113797a84e134Smrg	    # note $name still contains .exe if it was in $file originally
113807a84e134Smrg	    # as does the version of $file that was added into $rmfiles
113815ec34c4cSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
113825ec34c4cSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11383f353fbadSmrg	      func_append rmfiles " $odir/lt-$name"
113847a84e134Smrg	    fi
113855ec34c4cSmrg	    if test "X$noexename" != "X$name"; then
113865ec34c4cSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
113877a84e134Smrg	    fi
113887a84e134Smrg	  fi
113897a84e134Smrg	fi
113907a84e134Smrg	;;
113917a84e134Smrg      esac
11392994689c1Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
113937a84e134Smrg    done
113947a84e134Smrg
113955ec34c4cSmrg    # Try to remove the $objdir's in the directories where we deleted files
113967a84e134Smrg    for dir in $rmdirs; do
113977a84e134Smrg      if test -d "$dir"; then
11398994689c1Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
113997a84e134Smrg      fi
114007a84e134Smrg    done
114017a84e134Smrg
114027a84e134Smrg    exit $exit_status
11403994689c1Smrg}
114047a84e134Smrg
114055ec34c4cSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
114065ec34c4cSmrg  func_mode_uninstall ${1+"$@"}
114075ec34c4cSmrgfi
11408775e7de9Smrg
11409f353fbadSmrgtest -z "$opt_mode" && {
114105ec34c4cSmrg  help=$generic_help
11411994689c1Smrg  func_fatal_help "you must specify a MODE"
11412994689c1Smrg}
11413994689c1Smrg
11414994689c1Smrgtest -z "$exec_cmd" && \
114155ec34c4cSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
114167a84e134Smrg
114177a84e134Smrgif test -n "$exec_cmd"; then
11418994689c1Smrg  eval exec "$exec_cmd"
114197a84e134Smrg  exit $EXIT_FAILURE
114207a84e134Smrgfi
114217a84e134Smrg
11422994689c1Smrgexit $exit_status
11423e1e1713cSmrg
114247a84e134Smrg
114257a84e134Smrg# The TAGs below are defined such that we never get into a situation
114265ec34c4cSmrg# where we disable both kinds of libraries.  Given conflicting
114277a84e134Smrg# choices, we go for a static library, that is the most portable,
114287a84e134Smrg# since we can't tell whether shared libraries were disabled because
114297a84e134Smrg# the user asked for that or because the platform doesn't support
114307a84e134Smrg# them.  This is particularly important on AIX, because we don't
114317a84e134Smrg# support having both static and shared libraries enabled at the same
114327a84e134Smrg# time on that platform, so we default to a shared-only configuration.
114337a84e134Smrg# If a disable-shared tag is given, we'll fallback to a static-only
114347a84e134Smrg# configuration.  But we'll never go from static-only to shared-only.
114357a84e134Smrg
114367a84e134Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11437994689c1Smrgbuild_libtool_libs=no
11438994689c1Smrgbuild_old_libs=yes
114397a84e134Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
114407a84e134Smrg
114417a84e134Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11442994689c1Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
114437a84e134Smrg# ### END LIBTOOL TAG CONFIG: disable-static
114447a84e134Smrg
114457a84e134Smrg# Local Variables:
114467a84e134Smrg# mode:shell-script
114477a84e134Smrg# sh-indentation:2
114487a84e134Smrg# End:
11449