10814a2baSmrg#! /usr/bin/env sh
20814a2baSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
30814a2baSmrg##               by inline-source v2019-02-19.15
463847c39Smrg
50814a2baSmrg# libtool (GNU libtool) 2.4.7
60814a2baSmrg# Provide generalized library-building support services.
763847c39Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
863847c39Smrg
90814a2baSmrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
1063847c39Smrg# This is free software; see the source for copying conditions.  There is NO
1163847c39Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1263847c39Smrg
1363847c39Smrg# GNU Libtool is free software; you can redistribute it and/or modify
1476888252Smrg# it under the terms of the GNU General Public License as published by
1576888252Smrg# the Free Software Foundation; either version 2 of the License, or
1676888252Smrg# (at your option) any later version.
1776888252Smrg#
1863847c39Smrg# As a special exception to the GNU General Public License,
1963847c39Smrg# if you distribute this file as part of a program or library that
2063847c39Smrg# is built using GNU Libtool, you may include this file under the
2163847c39Smrg# same distribution terms that you use for the rest of that program.
2263847c39Smrg#
2363847c39Smrg# GNU Libtool is distributed in the hope that it will be useful, but
2476888252Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
2576888252Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2676888252Smrg# General Public License for more details.
2776888252Smrg#
2876888252Smrg# You should have received a copy of the GNU General Public License
290814a2baSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30d8556812Smrg
310814a2baSmrg
320814a2baSmrgPROGRAM=libtool
330814a2baSmrgPACKAGE=libtool
340814a2baSmrgVERSION=2.4.7
350814a2baSmrgpackage_revision=2.4.7
360814a2baSmrg
370814a2baSmrg
380814a2baSmrg## ------ ##
390814a2baSmrg## Usage. ##
400814a2baSmrg## ------ ##
410814a2baSmrg
420814a2baSmrg# Run './libtool --help' for help with using this script from the
430814a2baSmrg# command line.
440814a2baSmrg
450814a2baSmrg
460814a2baSmrg## ------------------------------- ##
470814a2baSmrg## User overridable command paths. ##
480814a2baSmrg## ------------------------------- ##
490814a2baSmrg
500814a2baSmrg# After configure completes, it has a better idea of some of the
510814a2baSmrg# shell tools we need than the defaults used by the functions shared
520814a2baSmrg# with bootstrap, so set those here where they can still be over-
530814a2baSmrg# ridden by the user, but otherwise take precedence.
540814a2baSmrg
550814a2baSmrg: ${AUTOCONF="autoconf"}
560814a2baSmrg: ${AUTOMAKE="automake"}
570814a2baSmrg
580814a2baSmrg
590814a2baSmrg## -------------------------- ##
600814a2baSmrg## Source external libraries. ##
610814a2baSmrg## -------------------------- ##
620814a2baSmrg
630814a2baSmrg# Much of our low-level functionality needs to be sourced from external
640814a2baSmrg# libraries, which are installed to $pkgauxdir.
650814a2baSmrg
660814a2baSmrg# Set a version string for this script.
670814a2baSmrgscriptversion=2019-02-19.15; # UTC
680814a2baSmrg
690814a2baSmrg# General shell script boiler plate, and helper functions.
700814a2baSmrg# Written by Gary V. Vaughan, 2004
710814a2baSmrg
720814a2baSmrg# This is free software.  There is NO warranty; not even for
730814a2baSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7463847c39Smrg#
750814a2baSmrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
7663847c39Smrg#
770814a2baSmrg# This file is dual licensed under the terms of the MIT license
780814a2baSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
790814a2baSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
800814a2baSmrg# these licenses when using or redistributing this software or any of
810814a2baSmrg# the files within it.  See the URLs above, or the file `LICENSE`
820814a2baSmrg# included in the Bootstrap distribution for the full license texts.
830814a2baSmrg
840814a2baSmrg# Please report bugs or propose patches to:
850814a2baSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
860814a2baSmrg
870814a2baSmrg
880814a2baSmrg## ------ ##
890814a2baSmrg## Usage. ##
900814a2baSmrg## ------ ##
910814a2baSmrg
920814a2baSmrg# Evaluate this file near the top of your script to gain access to
930814a2baSmrg# the functions and variables defined here:
9463847c39Smrg#
950814a2baSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
9663847c39Smrg#
970814a2baSmrg# If you need to override any of the default environment variable
980814a2baSmrg# settings, do that before evaluating this file.
9986dafe34Smrg
10086dafe34Smrg
1010814a2baSmrg## -------------------- ##
1020814a2baSmrg## Shell normalisation. ##
1030814a2baSmrg## -------------------- ##
1040814a2baSmrg
1050814a2baSmrg# Some shells need a little help to be as Bourne compatible as possible.
1060814a2baSmrg# Before doing anything else, make sure all that help has been provided!
1070814a2baSmrg
1080814a2baSmrgDUALCASE=1; export DUALCASE # for MKS sh
1090814a2baSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
11086dafe34Smrg  emulate sh
11186dafe34Smrg  NULLCMD=:
1120814a2baSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
11386dafe34Smrg  # is contrary to our usage.  Disable this feature.
11486dafe34Smrg  alias -g '${1+"$@"}'='"$@"'
11586dafe34Smrg  setopt NO_GLOB_SUBST
11686dafe34Smrgelse
1170814a2baSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
11886dafe34Smrgfi
119d8556812Smrg
1200814a2baSmrg# NLS nuisances: We save the old values in case they are required later.
1210814a2baSmrg_G_user_locale=
1220814a2baSmrg_G_safe_locale=
1230814a2baSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
12486dafe34Smrgdo
1250814a2baSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1260814a2baSmrg          save_$_G_var=\$$_G_var
1270814a2baSmrg          $_G_var=C
1280814a2baSmrg	  export $_G_var
1290814a2baSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1300814a2baSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
13186dafe34Smrg	fi"
13286dafe34Smrgdone
1330814a2baSmrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1340814a2baSmrg# in case the environment reset is needed later and the $save_* variant is not
1350814a2baSmrg# defined (see the code above).
13663847c39SmrgLC_ALL=C
13763847c39SmrgLANGUAGE=C
13863847c39Smrgexport LANGUAGE LC_ALL
13963847c39Smrg
1400814a2baSmrg# Make sure IFS has a sensible default
1410814a2baSmrgsp=' '
1420814a2baSmrgnl='
1430814a2baSmrg'
1440814a2baSmrgIFS="$sp	$nl"
1450814a2baSmrg
1460814a2baSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1470814a2baSmrgif test "${PATH_SEPARATOR+set}" != set; then
1480814a2baSmrg  PATH_SEPARATOR=:
1490814a2baSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1500814a2baSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1510814a2baSmrg      PATH_SEPARATOR=';'
1520814a2baSmrg  }
1530814a2baSmrgfi
15463847c39Smrg
15563847c39Smrg
1560814a2baSmrg# func_unset VAR
1570814a2baSmrg# --------------
1580814a2baSmrg# Portably unset VAR.
1590814a2baSmrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1600814a2baSmrg# status if VAR is already unset, which might be problematic if the
1610814a2baSmrg# statement is used at the end of a function (thus poisoning its return
1620814a2baSmrg# value) or when 'set -e' is active (causing even a spurious abort of
1630814a2baSmrg# the script in this case).
1640814a2baSmrgfunc_unset ()
1650814a2baSmrg{
1660814a2baSmrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1670814a2baSmrg}
16863847c39Smrg
16963847c39Smrg
1700814a2baSmrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1710814a2baSmrgfunc_unset CDPATH
17263847c39Smrg
1730814a2baSmrg# Make sure ${,E,F}GREP behave sanely.
1740814a2baSmrgfunc_unset GREP_OPTIONS
17563847c39Smrg
17686dafe34Smrg
1770814a2baSmrg## ------------------------- ##
1780814a2baSmrg## Locate command utilities. ##
1790814a2baSmrg## ------------------------- ##
18086dafe34Smrg
18186dafe34Smrg
1820814a2baSmrg# func_executable_p FILE
1830814a2baSmrg# ----------------------
1840814a2baSmrg# Check that FILE is an executable regular file.
1850814a2baSmrgfunc_executable_p ()
18663847c39Smrg{
1870814a2baSmrg    test -f "$1" && test -x "$1"
1880814a2baSmrg}
18963847c39Smrg
19063847c39Smrg
1910814a2baSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1920814a2baSmrg# --------------------------------------------
1930814a2baSmrg# Search for either a program that responds to --version with output
1940814a2baSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1950814a2baSmrg# trying all the directories in PATH with each of the elements of
1960814a2baSmrg# PROGS_LIST.
1970814a2baSmrg#
1980814a2baSmrg# CHECK_FUNC should accept the path to a candidate program, and
1990814a2baSmrg# set $func_check_prog_result if it truncates its output less than
2000814a2baSmrg# $_G_path_prog_max characters.
2010814a2baSmrgfunc_path_progs ()
20263847c39Smrg{
2030814a2baSmrg    _G_progs_list=$1
2040814a2baSmrg    _G_check_func=$2
2050814a2baSmrg    _G_PATH=${3-"$PATH"}
2060814a2baSmrg
2070814a2baSmrg    _G_path_prog_max=0
2080814a2baSmrg    _G_path_prog_found=false
2090814a2baSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
2100814a2baSmrg    for _G_dir in $_G_PATH; do
2110814a2baSmrg      IFS=$_G_save_IFS
2120814a2baSmrg      test -z "$_G_dir" && _G_dir=.
2130814a2baSmrg      for _G_prog_name in $_G_progs_list; do
2140814a2baSmrg        for _exeext in '' .EXE; do
2150814a2baSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2160814a2baSmrg          func_executable_p "$_G_path_prog" || continue
2170814a2baSmrg          case `"$_G_path_prog" --version 2>&1` in
2180814a2baSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2190814a2baSmrg            *)     $_G_check_func $_G_path_prog
2200814a2baSmrg		   func_path_progs_result=$func_check_prog_result
2210814a2baSmrg		   ;;
2220814a2baSmrg          esac
2230814a2baSmrg          $_G_path_prog_found && break 3
2240814a2baSmrg        done
2250814a2baSmrg      done
2260814a2baSmrg    done
2270814a2baSmrg    IFS=$_G_save_IFS
2280814a2baSmrg    test -z "$func_path_progs_result" && {
2290814a2baSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2300814a2baSmrg      exit 1
2310814a2baSmrg    }
2320814a2baSmrg}
23363847c39Smrg
23463847c39Smrg
2350814a2baSmrg# We want to be able to use the functions in this file before configure
2360814a2baSmrg# has figured out where the best binaries are kept, which means we have
2370814a2baSmrg# to search for them ourselves - except when the results are already set
2380814a2baSmrg# where we skip the searches.
23963847c39Smrg
2400814a2baSmrg# Unless the user overrides by setting SED, search the path for either GNU
2410814a2baSmrg# sed, or the sed that truncates its output the least.
2420814a2baSmrgtest -z "$SED" && {
2430814a2baSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2440814a2baSmrg  for _G_i in 1 2 3 4 5 6 7; do
2450814a2baSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2460814a2baSmrg  done
2470814a2baSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2480814a2baSmrg  _G_sed_script=
24963847c39Smrg
2500814a2baSmrg  func_check_prog_sed ()
2510814a2baSmrg  {
2520814a2baSmrg    _G_path_prog=$1
25363847c39Smrg
2540814a2baSmrg    _G_count=0
2550814a2baSmrg    printf 0123456789 >conftest.in
2560814a2baSmrg    while :
2570814a2baSmrg    do
2580814a2baSmrg      cat conftest.in conftest.in >conftest.tmp
2590814a2baSmrg      mv conftest.tmp conftest.in
2600814a2baSmrg      cp conftest.in conftest.nl
2610814a2baSmrg      echo '' >> conftest.nl
2620814a2baSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2630814a2baSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2640814a2baSmrg      _G_count=`expr $_G_count + 1`
2650814a2baSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2660814a2baSmrg        # Best one so far, save it but keep looking for a better one
2670814a2baSmrg        func_check_prog_result=$_G_path_prog
2680814a2baSmrg        _G_path_prog_max=$_G_count
2690814a2baSmrg      fi
2700814a2baSmrg      # 10*(2^10) chars as input seems more than enough
2710814a2baSmrg      test 10 -lt "$_G_count" && break
2720814a2baSmrg    done
2730814a2baSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2740814a2baSmrg  }
27563847c39Smrg
2760814a2baSmrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
2770814a2baSmrg  rm -f conftest.sed
2780814a2baSmrg  SED=$func_path_progs_result
2790814a2baSmrg}
28063847c39Smrg
2810814a2baSmrg
2820814a2baSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2830814a2baSmrg# grep, or the grep that truncates its output the least.
2840814a2baSmrgtest -z "$GREP" && {
2850814a2baSmrg  func_check_prog_grep ()
2860814a2baSmrg  {
2870814a2baSmrg    _G_path_prog=$1
2880814a2baSmrg
2890814a2baSmrg    _G_count=0
2900814a2baSmrg    _G_path_prog_max=0
2910814a2baSmrg    printf 0123456789 >conftest.in
2920814a2baSmrg    while :
2930814a2baSmrg    do
2940814a2baSmrg      cat conftest.in conftest.in >conftest.tmp
2950814a2baSmrg      mv conftest.tmp conftest.in
2960814a2baSmrg      cp conftest.in conftest.nl
2970814a2baSmrg      echo 'GREP' >> conftest.nl
2980814a2baSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2990814a2baSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
3000814a2baSmrg      _G_count=`expr $_G_count + 1`
3010814a2baSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
3020814a2baSmrg        # Best one so far, save it but keep looking for a better one
3030814a2baSmrg        func_check_prog_result=$_G_path_prog
3040814a2baSmrg        _G_path_prog_max=$_G_count
3050814a2baSmrg      fi
3060814a2baSmrg      # 10*(2^10) chars as input seems more than enough
3070814a2baSmrg      test 10 -lt "$_G_count" && break
3080814a2baSmrg    done
3090814a2baSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
3100814a2baSmrg  }
3110814a2baSmrg
3120814a2baSmrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
3130814a2baSmrg  GREP=$func_path_progs_result
3140814a2baSmrg}
3150814a2baSmrg
3160814a2baSmrg
3170814a2baSmrg## ------------------------------- ##
3180814a2baSmrg## User overridable command paths. ##
3190814a2baSmrg## ------------------------------- ##
3200814a2baSmrg
3210814a2baSmrg# All uppercase variable names are used for environment variables.  These
3220814a2baSmrg# variables can be overridden by the user before calling a script that
3230814a2baSmrg# uses them if a suitable command of that name is not already available
3240814a2baSmrg# in the command search PATH.
3250814a2baSmrg
3260814a2baSmrg: ${CP="cp -f"}
3270814a2baSmrg: ${ECHO="printf %s\n"}
3280814a2baSmrg: ${EGREP="$GREP -E"}
3290814a2baSmrg: ${FGREP="$GREP -F"}
3300814a2baSmrg: ${LN_S="ln -s"}
3310814a2baSmrg: ${MAKE="make"}
3320814a2baSmrg: ${MKDIR="mkdir"}
3330814a2baSmrg: ${MV="mv -f"}
3340814a2baSmrg: ${RM="rm -f"}
3350814a2baSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3360814a2baSmrg
3370814a2baSmrg
3380814a2baSmrg## -------------------- ##
3390814a2baSmrg## Useful sed snippets. ##
3400814a2baSmrg## -------------------- ##
3410814a2baSmrg
3420814a2baSmrgsed_dirname='s|/[^/]*$||'
3430814a2baSmrgsed_basename='s|^.*/||'
3440814a2baSmrg
3450814a2baSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3460814a2baSmrg# metacharacters that are still active within double-quoted strings.
3470814a2baSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3480814a2baSmrg
3490814a2baSmrg# Same as above, but do not quote variable references.
3500814a2baSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3510814a2baSmrg
3520814a2baSmrg# Sed substitution that turns a string into a regex matching for the
3530814a2baSmrg# string literally.
3540814a2baSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3550814a2baSmrg
3560814a2baSmrg# Sed substitution that converts a w32 file name or path
3570814a2baSmrg# that contains forward slashes, into one that contains
3580814a2baSmrg# (escaped) backslashes.  A very naive implementation.
3590814a2baSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3600814a2baSmrg
3610814a2baSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3620814a2baSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3630814a2baSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3640814a2baSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3650814a2baSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3660814a2baSmrg_G_bs='\\'
3670814a2baSmrg_G_bs2='\\\\'
3680814a2baSmrg_G_bs4='\\\\\\\\'
3690814a2baSmrg_G_dollar='\$'
3700814a2baSmrgsed_double_backslash="\
3710814a2baSmrg  s/$_G_bs4/&\\
3720814a2baSmrg/g
3730814a2baSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3740814a2baSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3750814a2baSmrg  s/\n//g"
3760814a2baSmrg
3770814a2baSmrg# require_check_ifs_backslash
3780814a2baSmrg# ---------------------------
3790814a2baSmrg# Check if we can use backslash as IFS='\' separator, and set
3800814a2baSmrg# $check_ifs_backshlash_broken to ':' or 'false'.
3810814a2baSmrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3820814a2baSmrgfunc_require_check_ifs_backslash ()
38363847c39Smrg{
3840814a2baSmrg  _G_save_IFS=$IFS
3850814a2baSmrg  IFS='\'
3860814a2baSmrg  _G_check_ifs_backshlash='a\\b'
3870814a2baSmrg  for _G_i in $_G_check_ifs_backshlash
3880814a2baSmrg  do
3890814a2baSmrg  case $_G_i in
3900814a2baSmrg  a)
3910814a2baSmrg    check_ifs_backshlash_broken=false
39263847c39Smrg    ;;
3930814a2baSmrg  '')
3940814a2baSmrg    break
39563847c39Smrg    ;;
3960814a2baSmrg  *)
3970814a2baSmrg    check_ifs_backshlash_broken=:
3980814a2baSmrg    break
39963847c39Smrg    ;;
40063847c39Smrg  esac
40163847c39Smrg  done
4020814a2baSmrg  IFS=$_G_save_IFS
4030814a2baSmrg  require_check_ifs_backslash=:
40463847c39Smrg}
40563847c39Smrg
40663847c39Smrg
4070814a2baSmrg## ----------------- ##
4080814a2baSmrg## Global variables. ##
4090814a2baSmrg## ----------------- ##
41063847c39Smrg
4110814a2baSmrg# Except for the global variables explicitly listed below, the following
4120814a2baSmrg# functions in the '^func_' namespace, and the '^require_' namespace
4130814a2baSmrg# variables initialised in the 'Resource management' section, sourcing
4140814a2baSmrg# this file will not pollute your global namespace with anything
4150814a2baSmrg# else. There's no portable way to scope variables in Bourne shell
4160814a2baSmrg# though, so actually running these functions will sometimes place
4170814a2baSmrg# results into a variable named after the function, and often use
4180814a2baSmrg# temporary variables in the '^_G_' namespace. If you are careful to
4190814a2baSmrg# avoid using those namespaces casually in your sourcing script, things
4200814a2baSmrg# should continue to work as you expect. And, of course, you can freely
4210814a2baSmrg# overwrite any of the functions or variables defined here before
4220814a2baSmrg# calling anything to customize them.
4230814a2baSmrg
4240814a2baSmrgEXIT_SUCCESS=0
4250814a2baSmrgEXIT_FAILURE=1
4260814a2baSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
4270814a2baSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4280814a2baSmrg
4290814a2baSmrg# Allow overriding, eg assuming that you follow the convention of
4300814a2baSmrg# putting '$debug_cmd' at the start of all your functions, you can get
4310814a2baSmrg# bash to show function call trace with:
4320814a2baSmrg#
4330814a2baSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
4340814a2baSmrgdebug_cmd=${debug_cmd-":"}
4350814a2baSmrgexit_cmd=:
4360814a2baSmrg
4370814a2baSmrg# By convention, finish your script with:
4380814a2baSmrg#
4390814a2baSmrg#    exit $exit_status
4400814a2baSmrg#
4410814a2baSmrg# so that you can set exit_status to non-zero if you want to indicate
4420814a2baSmrg# something went wrong during execution without actually bailing out at
4430814a2baSmrg# the point of failure.
4440814a2baSmrgexit_status=$EXIT_SUCCESS
44563847c39Smrg
4460814a2baSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4470814a2baSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4480814a2baSmrg# the _XPG environment variable is not equal to 1 (one), the special
4490814a2baSmrg# positional parameter $0, within a function call, is the name of the
4500814a2baSmrg# function.
4510814a2baSmrgprogpath=$0
4520814a2baSmrg
4530814a2baSmrg# The name of this program.
4540814a2baSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
45563847c39Smrg
4560814a2baSmrg# Make sure we have an absolute progpath for reexecution:
45763847c39Smrgcase $progpath in
45863847c39Smrg  [\\/]*|[A-Za-z]:\\*) ;;
45963847c39Smrg  *[\\/]*)
4600814a2baSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
46163847c39Smrg     progdir=`cd "$progdir" && pwd`
4620814a2baSmrg     progpath=$progdir/$progname
46363847c39Smrg     ;;
46463847c39Smrg  *)
4650814a2baSmrg     _G_IFS=$IFS
46663847c39Smrg     IFS=${PATH_SEPARATOR-:}
46763847c39Smrg     for progdir in $PATH; do
4680814a2baSmrg       IFS=$_G_IFS
46963847c39Smrg       test -x "$progdir/$progname" && break
47063847c39Smrg     done
4710814a2baSmrg     IFS=$_G_IFS
47263847c39Smrg     test -n "$progdir" || progdir=`pwd`
4730814a2baSmrg     progpath=$progdir/$progname
47463847c39Smrg     ;;
47563847c39Smrgesac
47663847c39Smrg
47763847c39Smrg
4780814a2baSmrg## ----------------- ##
4790814a2baSmrg## Standard options. ##
4800814a2baSmrg## ----------------- ##
48163847c39Smrg
4820814a2baSmrg# The following options affect the operation of the functions defined
4830814a2baSmrg# below, and should be set appropriately depending on run-time para-
4840814a2baSmrg# meters passed on the command line.
48563847c39Smrg
48663847c39Smrgopt_dry_run=false
48763847c39Smrgopt_quiet=false
48863847c39Smrgopt_verbose=false
48963847c39Smrg
4900814a2baSmrg# Categories 'all' and 'none' are always available.  Append any others
4910814a2baSmrg# you will pass as the first argument to func_warning from your own
4920814a2baSmrg# code.
4930814a2baSmrgwarning_categories=
49463847c39Smrg
4950814a2baSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4960814a2baSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4970814a2baSmrg# treat the next displayed warning as a fatal error.
4980814a2baSmrgwarning_func=func_warn_and_continue
49963847c39Smrg
5000814a2baSmrg# Set to 'all' to display all warnings, 'none' to suppress all
5010814a2baSmrg# warnings, or a space delimited list of some subset of
5020814a2baSmrg# 'warning_categories' to display only the listed warnings.
5030814a2baSmrgopt_warning_types=all
50463847c39Smrg
50563847c39Smrg
5060814a2baSmrg## -------------------- ##
5070814a2baSmrg## Resource management. ##
5080814a2baSmrg## -------------------- ##
50963847c39Smrg
5100814a2baSmrg# This section contains definitions for functions that each ensure a
5110814a2baSmrg# particular resource (a file, or a non-empty configuration variable for
5120814a2baSmrg# example) is available, and if appropriate to extract default values
5130814a2baSmrg# from pertinent package files. Call them using their associated
5140814a2baSmrg# 'require_*' variable to ensure that they are executed, at most, once.
5150814a2baSmrg#
5160814a2baSmrg# It's entirely deliberate that calling these functions can set
5170814a2baSmrg# variables that don't obey the namespace limitations obeyed by the rest
5180814a2baSmrg# of this file, in order that that they be as useful as possible to
5190814a2baSmrg# callers.
52063847c39Smrg
52163847c39Smrg
5220814a2baSmrg# require_term_colors
5230814a2baSmrg# -------------------
5240814a2baSmrg# Allow display of bold text on terminals that support it.
5250814a2baSmrgrequire_term_colors=func_require_term_colors
5260814a2baSmrgfunc_require_term_colors ()
52763847c39Smrg{
5280814a2baSmrg    $debug_cmd
5290814a2baSmrg
5300814a2baSmrg    test -t 1 && {
5310814a2baSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
5320814a2baSmrg      # precedence, because most terminfo databases neglect to describe
5330814a2baSmrg      # whether color sequences are supported.
5340814a2baSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
5350814a2baSmrg
5360814a2baSmrg      if test 1 = "$USE_ANSI_COLORS"; then
5370814a2baSmrg        # Standard ANSI escape sequences
5380814a2baSmrg        tc_reset='[0m'
5390814a2baSmrg        tc_bold='[1m';   tc_standout='[7m'
5400814a2baSmrg        tc_red='[31m';   tc_green='[32m'
5410814a2baSmrg        tc_blue='[34m';  tc_cyan='[36m'
5420814a2baSmrg      else
5430814a2baSmrg        # Otherwise trust the terminfo database after all.
5440814a2baSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5450814a2baSmrg          tc_reset=`tput sgr0`
5460814a2baSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5470814a2baSmrg          tc_standout=$tc_bold
5480814a2baSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5490814a2baSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5500814a2baSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5510814a2baSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5520814a2baSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5530814a2baSmrg        }
5540814a2baSmrg      fi
5550814a2baSmrg    }
55663847c39Smrg
5570814a2baSmrg    require_term_colors=:
55863847c39Smrg}
55963847c39Smrg
56063847c39Smrg
5610814a2baSmrg## ----------------- ##
5620814a2baSmrg## Function library. ##
5630814a2baSmrg## ----------------- ##
56463847c39Smrg
5650814a2baSmrg# This section contains a variety of useful functions to call in your
5660814a2baSmrg# scripts. Take note of the portable wrappers for features provided by
5670814a2baSmrg# some modern shells, which will fall back to slower equivalents on
5680814a2baSmrg# less featureful shells.
56963847c39Smrg
5700814a2baSmrg
5710814a2baSmrg# func_append VAR VALUE
5720814a2baSmrg# ---------------------
5730814a2baSmrg# Append VALUE onto the existing contents of VAR.
5740814a2baSmrg
5750814a2baSmrg  # We should try to minimise forks, especially on Windows where they are
5760814a2baSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5770814a2baSmrg  # being used:
5780814a2baSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5790814a2baSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5800814a2baSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5810814a2baSmrg    # The += operator was introduced in bash 3.1
5820814a2baSmrg    case $BASH_VERSION in
5830814a2baSmrg      [12].* | 3.0 | 3.0*) ;;
5840814a2baSmrg      *)
5850814a2baSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5860814a2baSmrg        ;;
5870814a2baSmrg    esac
5880814a2baSmrg  fi
5890814a2baSmrg
5900814a2baSmrg  # _G_HAVE_PLUSEQ_OP
5910814a2baSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5920814a2baSmrg  # useable or anything else if it does not work.
5930814a2baSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5940814a2baSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5950814a2baSmrg    && _G_HAVE_PLUSEQ_OP=yes
5960814a2baSmrg
5970814a2baSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5980814a2baSmrgthen
5990814a2baSmrg  # This is an XSI compatible shell, allowing a faster implementation...
6000814a2baSmrg  eval 'func_append ()
6010814a2baSmrg  {
6020814a2baSmrg    $debug_cmd
6030814a2baSmrg
6040814a2baSmrg    eval "$1+=\$2"
6050814a2baSmrg  }'
6060814a2baSmrgelse
6070814a2baSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
6080814a2baSmrg  func_append ()
6090814a2baSmrg  {
6100814a2baSmrg    $debug_cmd
6110814a2baSmrg
6120814a2baSmrg    eval "$1=\$$1\$2"
6130814a2baSmrg  }
6140814a2baSmrgfi
6150814a2baSmrg
6160814a2baSmrg
6170814a2baSmrg# func_append_quoted VAR VALUE
6180814a2baSmrg# ----------------------------
6190814a2baSmrg# Quote VALUE and append to the end of shell variable VAR, separated
6200814a2baSmrg# by a space.
6210814a2baSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
6220814a2baSmrg  eval 'func_append_quoted ()
6230814a2baSmrg  {
6240814a2baSmrg    $debug_cmd
6250814a2baSmrg
6260814a2baSmrg    func_quote_arg pretty "$2"
6270814a2baSmrg    eval "$1+=\\ \$func_quote_arg_result"
6280814a2baSmrg  }'
6290814a2baSmrgelse
6300814a2baSmrg  func_append_quoted ()
6310814a2baSmrg  {
6320814a2baSmrg    $debug_cmd
6330814a2baSmrg
6340814a2baSmrg    func_quote_arg pretty "$2"
6350814a2baSmrg    eval "$1=\$$1\\ \$func_quote_arg_result"
6360814a2baSmrg  }
6370814a2baSmrgfi
6380814a2baSmrg
6390814a2baSmrg
6400814a2baSmrg# func_append_uniq VAR VALUE
6410814a2baSmrg# --------------------------
6420814a2baSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6430814a2baSmrg# entries are delimited by the first character of VALUE.  For example:
6440814a2baSmrg#
6450814a2baSmrg#   func_append_uniq options " --another-option option-argument"
6460814a2baSmrg#
6470814a2baSmrg# will only append to $options if " --another-option option-argument "
6480814a2baSmrg# is not already present somewhere in $options already (note spaces at
6490814a2baSmrg# each end implied by leading space in second argument).
6500814a2baSmrgfunc_append_uniq ()
6510814a2baSmrg{
6520814a2baSmrg    $debug_cmd
6530814a2baSmrg
6540814a2baSmrg    eval _G_current_value='`$ECHO $'$1'`'
6550814a2baSmrg    _G_delim=`expr "$2" : '\(.\)'`
6560814a2baSmrg
6570814a2baSmrg    case $_G_delim$_G_current_value$_G_delim in
6580814a2baSmrg      *"$2$_G_delim"*) ;;
6590814a2baSmrg      *) func_append "$@" ;;
6600814a2baSmrg    esac
6610814a2baSmrg}
6620814a2baSmrg
6630814a2baSmrg
6640814a2baSmrg# func_arith TERM...
6650814a2baSmrg# ------------------
6660814a2baSmrg# Set func_arith_result to the result of evaluating TERMs.
6670814a2baSmrg  test -z "$_G_HAVE_ARITH_OP" \
6680814a2baSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6690814a2baSmrg    && _G_HAVE_ARITH_OP=yes
6700814a2baSmrg
6710814a2baSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6720814a2baSmrg  eval 'func_arith ()
6730814a2baSmrg  {
6740814a2baSmrg    $debug_cmd
6750814a2baSmrg
6760814a2baSmrg    func_arith_result=$(( $* ))
6770814a2baSmrg  }'
6780814a2baSmrgelse
6790814a2baSmrg  func_arith ()
6800814a2baSmrg  {
6810814a2baSmrg    $debug_cmd
6820814a2baSmrg
6830814a2baSmrg    func_arith_result=`expr "$@"`
6840814a2baSmrg  }
6850814a2baSmrgfi
6860814a2baSmrg
6870814a2baSmrg
6880814a2baSmrg# func_basename FILE
6890814a2baSmrg# ------------------
6900814a2baSmrg# Set func_basename_result to FILE with everything up to and including
6910814a2baSmrg# the last / stripped.
6920814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6930814a2baSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6940814a2baSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6950814a2baSmrg  # on unsupported syntax...
6960814a2baSmrg  _b='func_basename_result=${1##*/}'
6970814a2baSmrg  _d='case $1 in
6980814a2baSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6990814a2baSmrg        *  ) func_dirname_result=$3        ;;
7000814a2baSmrg      esac'
7010814a2baSmrg
7020814a2baSmrgelse
7030814a2baSmrg  # ...otherwise fall back to using sed.
7040814a2baSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
7050814a2baSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
7060814a2baSmrg      if test "X$func_dirname_result" = "X$1"; then
7070814a2baSmrg        func_dirname_result=$3
7080814a2baSmrg      else
7090814a2baSmrg        func_append func_dirname_result "$2"
7100814a2baSmrg      fi'
7110814a2baSmrgfi
7120814a2baSmrg
7130814a2baSmrgeval 'func_basename ()
7140814a2baSmrg{
7150814a2baSmrg    $debug_cmd
7160814a2baSmrg
7170814a2baSmrg    '"$_b"'
7180814a2baSmrg}'
7190814a2baSmrg
7200814a2baSmrg
7210814a2baSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
7220814a2baSmrg# -------------------------------------------
7230814a2baSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
7240814a2baSmrg# otherwise set result to NONDIR_REPLACEMENT.
7250814a2baSmrgeval 'func_dirname ()
7260814a2baSmrg{
7270814a2baSmrg    $debug_cmd
7280814a2baSmrg
7290814a2baSmrg    '"$_d"'
7300814a2baSmrg}'
7310814a2baSmrg
7320814a2baSmrg
7330814a2baSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
7340814a2baSmrg# --------------------------------------------------------
7350814a2baSmrg# Perform func_basename and func_dirname in a single function
7360814a2baSmrg# call:
7370814a2baSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
7380814a2baSmrg#             add APPEND to the result, otherwise set result
7390814a2baSmrg#             to NONDIR_REPLACEMENT.
7400814a2baSmrg#             value returned in "$func_dirname_result"
7410814a2baSmrg#   basename: Compute filename of FILE.
7420814a2baSmrg#             value retuned in "$func_basename_result"
7430814a2baSmrg# For efficiency, we do not delegate to the functions above but instead
7440814a2baSmrg# duplicate the functionality here.
7450814a2baSmrgeval 'func_dirname_and_basename ()
7460814a2baSmrg{
7470814a2baSmrg    $debug_cmd
7480814a2baSmrg
7490814a2baSmrg    '"$_b"'
7500814a2baSmrg    '"$_d"'
7510814a2baSmrg}'
7520814a2baSmrg
7530814a2baSmrg
7540814a2baSmrg# func_echo ARG...
7550814a2baSmrg# ----------------
7560814a2baSmrg# Echo program name prefixed message.
7570814a2baSmrgfunc_echo ()
7580814a2baSmrg{
7590814a2baSmrg    $debug_cmd
7600814a2baSmrg
7610814a2baSmrg    _G_message=$*
7620814a2baSmrg
7630814a2baSmrg    func_echo_IFS=$IFS
7640814a2baSmrg    IFS=$nl
7650814a2baSmrg    for _G_line in $_G_message; do
7660814a2baSmrg      IFS=$func_echo_IFS
7670814a2baSmrg      $ECHO "$progname: $_G_line"
7680814a2baSmrg    done
7690814a2baSmrg    IFS=$func_echo_IFS
7700814a2baSmrg}
7710814a2baSmrg
7720814a2baSmrg
7730814a2baSmrg# func_echo_all ARG...
7740814a2baSmrg# --------------------
7750814a2baSmrg# Invoke $ECHO with all args, space-separated.
7760814a2baSmrgfunc_echo_all ()
7770814a2baSmrg{
7780814a2baSmrg    $ECHO "$*"
7790814a2baSmrg}
7800814a2baSmrg
7810814a2baSmrg
7820814a2baSmrg# func_echo_infix_1 INFIX ARG...
7830814a2baSmrg# ------------------------------
7840814a2baSmrg# Echo program name, followed by INFIX on the first line, with any
7850814a2baSmrg# additional lines not showing INFIX.
7860814a2baSmrgfunc_echo_infix_1 ()
7870814a2baSmrg{
7880814a2baSmrg    $debug_cmd
7890814a2baSmrg
7900814a2baSmrg    $require_term_colors
7910814a2baSmrg
7920814a2baSmrg    _G_infix=$1; shift
7930814a2baSmrg    _G_indent=$_G_infix
7940814a2baSmrg    _G_prefix="$progname: $_G_infix: "
7950814a2baSmrg    _G_message=$*
7960814a2baSmrg
7970814a2baSmrg    # Strip color escape sequences before counting printable length
7980814a2baSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7990814a2baSmrg    do
8000814a2baSmrg      test -n "$_G_tc" && {
8010814a2baSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
8020814a2baSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
8030814a2baSmrg      }
8040814a2baSmrg    done
8050814a2baSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
8060814a2baSmrg
8070814a2baSmrg    func_echo_infix_1_IFS=$IFS
8080814a2baSmrg    IFS=$nl
8090814a2baSmrg    for _G_line in $_G_message; do
8100814a2baSmrg      IFS=$func_echo_infix_1_IFS
8110814a2baSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
8120814a2baSmrg      _G_prefix=$_G_indent
8130814a2baSmrg    done
8140814a2baSmrg    IFS=$func_echo_infix_1_IFS
8150814a2baSmrg}
8160814a2baSmrg
8170814a2baSmrg
8180814a2baSmrg# func_error ARG...
8190814a2baSmrg# -----------------
8200814a2baSmrg# Echo program name prefixed message to standard error.
8210814a2baSmrgfunc_error ()
8220814a2baSmrg{
8230814a2baSmrg    $debug_cmd
8240814a2baSmrg
8250814a2baSmrg    $require_term_colors
8260814a2baSmrg
8270814a2baSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
8280814a2baSmrg}
8290814a2baSmrg
8300814a2baSmrg
8310814a2baSmrg# func_fatal_error ARG...
8320814a2baSmrg# -----------------------
8330814a2baSmrg# Echo program name prefixed message to standard error, and exit.
8340814a2baSmrgfunc_fatal_error ()
8350814a2baSmrg{
8360814a2baSmrg    $debug_cmd
8370814a2baSmrg
8380814a2baSmrg    func_error "$*"
8390814a2baSmrg    exit $EXIT_FAILURE
8400814a2baSmrg}
8410814a2baSmrg
8420814a2baSmrg
8430814a2baSmrg# func_grep EXPRESSION FILENAME
8440814a2baSmrg# -----------------------------
8450814a2baSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8460814a2baSmrgfunc_grep ()
84763847c39Smrg{
8480814a2baSmrg    $debug_cmd
8490814a2baSmrg
8500814a2baSmrg    $GREP "$1" "$2" >/dev/null 2>&1
8510814a2baSmrg}
8520814a2baSmrg
85363847c39Smrg
8540814a2baSmrg# func_len STRING
8550814a2baSmrg# ---------------
8560814a2baSmrg# Set func_len_result to the length of STRING. STRING may not
8570814a2baSmrg# start with a hyphen.
8580814a2baSmrg  test -z "$_G_HAVE_XSI_OPS" \
8590814a2baSmrg    && (eval 'x=a/b/c;
8600814a2baSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8610814a2baSmrg    && _G_HAVE_XSI_OPS=yes
8620814a2baSmrg
8630814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8640814a2baSmrg  eval 'func_len ()
8650814a2baSmrg  {
8660814a2baSmrg    $debug_cmd
8670814a2baSmrg
8680814a2baSmrg    func_len_result=${#1}
8690814a2baSmrg  }'
8700814a2baSmrgelse
8710814a2baSmrg  func_len ()
8720814a2baSmrg  {
8730814a2baSmrg    $debug_cmd
8740814a2baSmrg
8750814a2baSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8760814a2baSmrg  }
8770814a2baSmrgfi
8780814a2baSmrg
8790814a2baSmrg
8800814a2baSmrg# func_mkdir_p DIRECTORY-PATH
8810814a2baSmrg# ---------------------------
8820814a2baSmrg# Make sure the entire path to DIRECTORY-PATH is available.
8830814a2baSmrgfunc_mkdir_p ()
8840814a2baSmrg{
8850814a2baSmrg    $debug_cmd
88663847c39Smrg
8870814a2baSmrg    _G_directory_path=$1
8880814a2baSmrg    _G_dir_list=
8890814a2baSmrg
8900814a2baSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8910814a2baSmrg
8920814a2baSmrg      # Protect directory names starting with '-'
8930814a2baSmrg      case $_G_directory_path in
8940814a2baSmrg        -*) _G_directory_path=./$_G_directory_path ;;
89563847c39Smrg      esac
89663847c39Smrg
89763847c39Smrg      # While some portion of DIR does not yet exist...
8980814a2baSmrg      while test ! -d "$_G_directory_path"; do
89963847c39Smrg        # ...make a list in topmost first order.  Use a colon delimited
90063847c39Smrg	# list incase some portion of path contains whitespace.
9010814a2baSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
90263847c39Smrg
90363847c39Smrg        # If the last portion added has no slash in it, the list is done
9040814a2baSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
90563847c39Smrg
90663847c39Smrg        # ...otherwise throw away the child directory and loop
9070814a2baSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
90863847c39Smrg      done
9090814a2baSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
91063847c39Smrg
9110814a2baSmrg      func_mkdir_p_IFS=$IFS; IFS=:
9120814a2baSmrg      for _G_dir in $_G_dir_list; do
9130814a2baSmrg	IFS=$func_mkdir_p_IFS
9140814a2baSmrg        # mkdir can fail with a 'File exist' error if two processes
91563847c39Smrg        # try to create one of the directories concurrently.  Don't
91663847c39Smrg        # stop in that case!
9170814a2baSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
91863847c39Smrg      done
9190814a2baSmrg      IFS=$func_mkdir_p_IFS
92063847c39Smrg
92163847c39Smrg      # Bail out if we (or some other process) failed to create a directory.
9220814a2baSmrg      test -d "$_G_directory_path" || \
9230814a2baSmrg        func_fatal_error "Failed to create '$1'"
92463847c39Smrg    fi
92563847c39Smrg}
92676888252Smrg
92776888252Smrg
9280814a2baSmrg# func_mktempdir [BASENAME]
9290814a2baSmrg# -------------------------
93076888252Smrg# Make a temporary directory that won't clash with other running
93176888252Smrg# libtool processes, and avoids race conditions if possible.  If
9320814a2baSmrg# given, BASENAME is the basename for that directory.
93376888252Smrgfunc_mktempdir ()
93476888252Smrg{
9350814a2baSmrg    $debug_cmd
93676888252Smrg
9370814a2baSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
9380814a2baSmrg
9390814a2baSmrg    if test : = "$opt_dry_run"; then
94076888252Smrg      # Return a directory name, but don't create it in dry-run mode
9410814a2baSmrg      _G_tmpdir=$_G_template-$$
94276888252Smrg    else
94376888252Smrg
94476888252Smrg      # If mktemp works, use that first and foremost
9450814a2baSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
94676888252Smrg
9470814a2baSmrg      if test ! -d "$_G_tmpdir"; then
94863847c39Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9490814a2baSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
95076888252Smrg
9510814a2baSmrg        func_mktempdir_umask=`umask`
95263847c39Smrg        umask 0077
9530814a2baSmrg        $MKDIR "$_G_tmpdir"
9540814a2baSmrg        umask $func_mktempdir_umask
95576888252Smrg      fi
95676888252Smrg
95776888252Smrg      # If we're not in dry-run mode, bomb out on failure
9580814a2baSmrg      test -d "$_G_tmpdir" || \
9590814a2baSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
96076888252Smrg    fi
96176888252Smrg
9620814a2baSmrg    $ECHO "$_G_tmpdir"
96376888252Smrg}
96476888252Smrg
96576888252Smrg
9660814a2baSmrg# func_normal_abspath PATH
9670814a2baSmrg# ------------------------
9680814a2baSmrg# Remove doubled-up and trailing slashes, "." path components,
9690814a2baSmrg# and cancel out any ".." path components in PATH after making
9700814a2baSmrg# it an absolute path.
9710814a2baSmrgfunc_normal_abspath ()
97276888252Smrg{
9730814a2baSmrg    $debug_cmd
9740814a2baSmrg
9750814a2baSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9760814a2baSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9770814a2baSmrg    _G_pathcdr='s|^/[^/]*||'
9780814a2baSmrg    _G_removedotparts=':dotsl
9790814a2baSmrg		s|/\./|/|g
9800814a2baSmrg		t dotsl
9810814a2baSmrg		s|/\.$|/|'
9820814a2baSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9830814a2baSmrg    _G_finalslash='s|/*$|/|'
9840814a2baSmrg
9850814a2baSmrg    # Start from root dir and reassemble the path.
9860814a2baSmrg    func_normal_abspath_result=
9870814a2baSmrg    func_normal_abspath_tpath=$1
9880814a2baSmrg    func_normal_abspath_altnamespace=
9890814a2baSmrg    case $func_normal_abspath_tpath in
9900814a2baSmrg      "")
9910814a2baSmrg        # Empty path, that just means $cwd.
9920814a2baSmrg        func_stripname '' '/' "`pwd`"
9930814a2baSmrg        func_normal_abspath_result=$func_stripname_result
9940814a2baSmrg        return
9950814a2baSmrg        ;;
9960814a2baSmrg      # The next three entries are used to spot a run of precisely
9970814a2baSmrg      # two leading slashes without using negated character classes;
9980814a2baSmrg      # we take advantage of case's first-match behaviour.
9990814a2baSmrg      ///*)
10000814a2baSmrg        # Unusual form of absolute path, do nothing.
10010814a2baSmrg        ;;
10020814a2baSmrg      //*)
10030814a2baSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
10040814a2baSmrg        # and for example Cygwin uses it to access remote file shares
10050814a2baSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
10060814a2baSmrg        func_normal_abspath_altnamespace=/
10070814a2baSmrg        ;;
10080814a2baSmrg      /*)
10090814a2baSmrg        # Absolute path, do nothing.
10100814a2baSmrg        ;;
101163847c39Smrg      *)
10120814a2baSmrg        # Relative path, prepend $cwd.
10130814a2baSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
10140814a2baSmrg        ;;
101563847c39Smrg    esac
101663847c39Smrg
10170814a2baSmrg    # Cancel out all the simple stuff to save iterations.  We also want
10180814a2baSmrg    # the path to end with a slash for ease of parsing, so make sure
10190814a2baSmrg    # there is one (and only one) here.
10200814a2baSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10210814a2baSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
10220814a2baSmrg    while :; do
10230814a2baSmrg      # Processed it all yet?
10240814a2baSmrg      if test / = "$func_normal_abspath_tpath"; then
10250814a2baSmrg        # If we ascended to the root using ".." the result may be empty now.
10260814a2baSmrg        if test -z "$func_normal_abspath_result"; then
10270814a2baSmrg          func_normal_abspath_result=/
10280814a2baSmrg        fi
10290814a2baSmrg        break
10300814a2baSmrg      fi
10310814a2baSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
10320814a2baSmrg          -e "$_G_pathcar"`
10330814a2baSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10340814a2baSmrg          -e "$_G_pathcdr"`
10350814a2baSmrg      # Figure out what to do with it
10360814a2baSmrg      case $func_normal_abspath_tcomponent in
10370814a2baSmrg        "")
10380814a2baSmrg          # Trailing empty path component, ignore it.
10390814a2baSmrg          ;;
10400814a2baSmrg        ..)
10410814a2baSmrg          # Parent dir; strip last assembled component from result.
10420814a2baSmrg          func_dirname "$func_normal_abspath_result"
10430814a2baSmrg          func_normal_abspath_result=$func_dirname_result
10440814a2baSmrg          ;;
10450814a2baSmrg        *)
10460814a2baSmrg          # Actual path component, append it.
10470814a2baSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10480814a2baSmrg          ;;
10490814a2baSmrg      esac
10500814a2baSmrg    done
10510814a2baSmrg    # Restore leading double-slash if one was found on entry.
10520814a2baSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10530814a2baSmrg}
10540814a2baSmrg
10550814a2baSmrg
10560814a2baSmrg# func_notquiet ARG...
10570814a2baSmrg# --------------------
10580814a2baSmrg# Echo program name prefixed message only when not in quiet mode.
10590814a2baSmrgfunc_notquiet ()
10600814a2baSmrg{
10610814a2baSmrg    $debug_cmd
10620814a2baSmrg
10630814a2baSmrg    $opt_quiet || func_echo ${1+"$@"}
10640814a2baSmrg
10650814a2baSmrg    # A bug in bash halts the script if the last line of a function
10660814a2baSmrg    # fails when set -e is in force, so we need another command to
10670814a2baSmrg    # work around that:
10680814a2baSmrg    :
10690814a2baSmrg}
10700814a2baSmrg
10710814a2baSmrg
10720814a2baSmrg# func_relative_path SRCDIR DSTDIR
10730814a2baSmrg# --------------------------------
10740814a2baSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10750814a2baSmrgfunc_relative_path ()
10760814a2baSmrg{
10770814a2baSmrg    $debug_cmd
10780814a2baSmrg
10790814a2baSmrg    func_relative_path_result=
10800814a2baSmrg    func_normal_abspath "$1"
10810814a2baSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10820814a2baSmrg    func_normal_abspath "$2"
10830814a2baSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10840814a2baSmrg
10850814a2baSmrg    # Ascend the tree starting from libdir
10860814a2baSmrg    while :; do
10870814a2baSmrg      # check if we have found a prefix of bindir
10880814a2baSmrg      case $func_relative_path_tbindir in
10890814a2baSmrg        $func_relative_path_tlibdir)
10900814a2baSmrg          # found an exact match
10910814a2baSmrg          func_relative_path_tcancelled=
10920814a2baSmrg          break
10930814a2baSmrg          ;;
10940814a2baSmrg        $func_relative_path_tlibdir*)
10950814a2baSmrg          # found a matching prefix
10960814a2baSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10970814a2baSmrg          func_relative_path_tcancelled=$func_stripname_result
10980814a2baSmrg          if test -z "$func_relative_path_result"; then
10990814a2baSmrg            func_relative_path_result=.
11000814a2baSmrg          fi
11010814a2baSmrg          break
11020814a2baSmrg          ;;
11030814a2baSmrg        *)
11040814a2baSmrg          func_dirname $func_relative_path_tlibdir
11050814a2baSmrg          func_relative_path_tlibdir=$func_dirname_result
11060814a2baSmrg          if test -z "$func_relative_path_tlibdir"; then
11070814a2baSmrg            # Have to descend all the way to the root!
11080814a2baSmrg            func_relative_path_result=../$func_relative_path_result
11090814a2baSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
11100814a2baSmrg            break
11110814a2baSmrg          fi
11120814a2baSmrg          func_relative_path_result=../$func_relative_path_result
11130814a2baSmrg          ;;
11140814a2baSmrg      esac
11150814a2baSmrg    done
11160814a2baSmrg
11170814a2baSmrg    # Now calculate path; take care to avoid doubling-up slashes.
11180814a2baSmrg    func_stripname '' '/' "$func_relative_path_result"
11190814a2baSmrg    func_relative_path_result=$func_stripname_result
11200814a2baSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
11210814a2baSmrg    if test -n "$func_stripname_result"; then
11220814a2baSmrg      func_append func_relative_path_result "/$func_stripname_result"
11230814a2baSmrg    fi
11240814a2baSmrg
11250814a2baSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
11260814a2baSmrg    if test -n "$func_relative_path_result"; then
11270814a2baSmrg      func_stripname './' '' "$func_relative_path_result"
11280814a2baSmrg      func_relative_path_result=$func_stripname_result
11290814a2baSmrg    fi
11300814a2baSmrg
11310814a2baSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
11320814a2baSmrg
11330814a2baSmrg    :
11340814a2baSmrg}
11350814a2baSmrg
11360814a2baSmrg
11370814a2baSmrg# func_quote_portable EVAL ARG
11380814a2baSmrg# ----------------------------
11390814a2baSmrg# Internal function to portably implement func_quote_arg.  Note that we still
11400814a2baSmrg# keep attention to performance here so we as much as possible try to avoid
11410814a2baSmrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11420814a2baSmrgfunc_quote_portable ()
11430814a2baSmrg{
11440814a2baSmrg    $debug_cmd
11450814a2baSmrg
11460814a2baSmrg    $require_check_ifs_backslash
11470814a2baSmrg
11480814a2baSmrg    func_quote_portable_result=$2
11490814a2baSmrg
11500814a2baSmrg    # one-time-loop (easy break)
11510814a2baSmrg    while true
11520814a2baSmrg    do
11530814a2baSmrg      if $1; then
11540814a2baSmrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11550814a2baSmrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11560814a2baSmrg        break
11570814a2baSmrg      fi
11580814a2baSmrg
11590814a2baSmrg      # Quote for eval.
11600814a2baSmrg      case $func_quote_portable_result in
11610814a2baSmrg        *[\\\`\"\$]*)
11620814a2baSmrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11630814a2baSmrg          # contains the shell wildcard characters.
11640814a2baSmrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11650814a2baSmrg            :*|*[\[\*\?]*)
11660814a2baSmrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11670814a2baSmrg                  | $SED "$sed_quote_subst"`
11680814a2baSmrg              break
11690814a2baSmrg              ;;
11700814a2baSmrg          esac
11710814a2baSmrg
11720814a2baSmrg          func_quote_portable_old_IFS=$IFS
11730814a2baSmrg          for _G_char in '\' '`' '"' '$'
11740814a2baSmrg          do
11750814a2baSmrg            # STATE($1) PREV($2) SEPARATOR($3)
11760814a2baSmrg            set start "" ""
11770814a2baSmrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11780814a2baSmrg            IFS=$_G_char
11790814a2baSmrg            for _G_part in $func_quote_portable_result
11800814a2baSmrg            do
11810814a2baSmrg              case $1 in
11820814a2baSmrg              quote)
11830814a2baSmrg                func_append func_quote_portable_result "$3$2"
11840814a2baSmrg                set quote "$_G_part" "\\$_G_char"
11850814a2baSmrg                ;;
11860814a2baSmrg              start)
11870814a2baSmrg                set first "" ""
11880814a2baSmrg                func_quote_portable_result=
11890814a2baSmrg                ;;
11900814a2baSmrg              first)
11910814a2baSmrg                set quote "$_G_part" ""
11920814a2baSmrg                ;;
11930814a2baSmrg              esac
11940814a2baSmrg            done
11950814a2baSmrg          done
11960814a2baSmrg          IFS=$func_quote_portable_old_IFS
11970814a2baSmrg          ;;
11980814a2baSmrg        *) ;;
11990814a2baSmrg      esac
12000814a2baSmrg      break
12010814a2baSmrg    done
12020814a2baSmrg
12030814a2baSmrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12040814a2baSmrg    case $func_quote_portable_result in
12050814a2baSmrg      # double-quote args containing shell metacharacters to delay
12060814a2baSmrg      # word splitting, command substitution and variable expansion
12070814a2baSmrg      # for a subsequent eval.
12080814a2baSmrg      # many bourne shells cannot handle close brackets correctly
120963847c39Smrg      # in scan sets, so we specify it separately.
121063847c39Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12110814a2baSmrg        func_quote_portable_result=\"$func_quote_portable_result\"
121263847c39Smrg        ;;
121363847c39Smrg    esac
121463847c39Smrg}
121563847c39Smrg
121663847c39Smrg
12170814a2baSmrg# func_quotefast_eval ARG
12180814a2baSmrg# -----------------------
12190814a2baSmrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12200814a2baSmrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12210814a2baSmrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12220814a2baSmrg  printf -v _GL_test_printf_tilde %q '~'
12230814a2baSmrg  if test '\~' = "$_GL_test_printf_tilde"; then
12240814a2baSmrg    func_quotefast_eval ()
12250814a2baSmrg    {
12260814a2baSmrg      printf -v func_quotefast_eval_result %q "$1"
12270814a2baSmrg    }
12280814a2baSmrg  else
12290814a2baSmrg    # Broken older Bash implementations.  Make those faster too if possible.
12300814a2baSmrg    func_quotefast_eval ()
12310814a2baSmrg    {
12320814a2baSmrg      case $1 in
12330814a2baSmrg        '~'*)
12340814a2baSmrg          func_quote_portable false "$1"
12350814a2baSmrg          func_quotefast_eval_result=$func_quote_portable_result
12360814a2baSmrg          ;;
12370814a2baSmrg        *)
12380814a2baSmrg          printf -v func_quotefast_eval_result %q "$1"
12390814a2baSmrg          ;;
12400814a2baSmrg      esac
12410814a2baSmrg    }
12420814a2baSmrg  fi
12430814a2baSmrgelse
12440814a2baSmrg  func_quotefast_eval ()
12450814a2baSmrg  {
12460814a2baSmrg    func_quote_portable false "$1"
12470814a2baSmrg    func_quotefast_eval_result=$func_quote_portable_result
12480814a2baSmrg  }
12490814a2baSmrgfi
12500814a2baSmrg
12510814a2baSmrg
12520814a2baSmrg# func_quote_arg MODEs ARG
12530814a2baSmrg# ------------------------
12540814a2baSmrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12550814a2baSmrg# specifiers listed below separated by ',' character.  This function returns two
12560814a2baSmrg# values:
12570814a2baSmrg#   i) func_quote_arg_result
12580814a2baSmrg#      double-quoted (when needed), suitable for a subsequent eval
12590814a2baSmrg#  ii) func_quote_arg_unquoted_result
12600814a2baSmrg#      has all characters that are still active within double
12610814a2baSmrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12620814a2baSmrg#
12630814a2baSmrg# Available modes:
12640814a2baSmrg# ----------------
12650814a2baSmrg# 'eval' (default)
12660814a2baSmrg#       - escape shell special characters
12670814a2baSmrg# 'expand'
12680814a2baSmrg#       - the same as 'eval';  but do not quote variable references
12690814a2baSmrg# 'pretty'
12700814a2baSmrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12710814a2baSmrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12720814a2baSmrg#         of 'echo a\ b'.  This is slower than default on some shells.
12730814a2baSmrg# 'unquoted'
12740814a2baSmrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12750814a2baSmrg#         wrapping double-quotes.
12760814a2baSmrg#
12770814a2baSmrg# Examples for 'func_quote_arg pretty,unquoted string':
12780814a2baSmrg#
12790814a2baSmrg#   string      | *_result              | *_unquoted_result
12800814a2baSmrg#   ------------+-----------------------+-------------------
12810814a2baSmrg#   "           | \"                    | \"
12820814a2baSmrg#   a b         | "a b"                 | a b
12830814a2baSmrg#   "a b"       | "\"a b\""             | \"a b\"
12840814a2baSmrg#   *           | "*"                   | *
12850814a2baSmrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12860814a2baSmrg#
12870814a2baSmrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12880814a2baSmrg#
12890814a2baSmrg#   string        |   *_result          |  *_unquoted_result
12900814a2baSmrg#   --------------+---------------------+--------------------
12910814a2baSmrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12920814a2baSmrgfunc_quote_arg ()
129363847c39Smrg{
12940814a2baSmrg    _G_quote_expand=false
12950814a2baSmrg    case ,$1, in
12960814a2baSmrg      *,expand,*)
12970814a2baSmrg        _G_quote_expand=:
12980814a2baSmrg        ;;
129963847c39Smrg    esac
130063847c39Smrg
13010814a2baSmrg    case ,$1, in
13020814a2baSmrg      *,pretty,*|*,expand,*|*,unquoted,*)
13030814a2baSmrg        func_quote_portable $_G_quote_expand "$2"
13040814a2baSmrg        func_quote_arg_result=$func_quote_portable_result
13050814a2baSmrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13060814a2baSmrg        ;;
13070814a2baSmrg      *)
13080814a2baSmrg        # Faster quote-for-eval for some shells.
13090814a2baSmrg        func_quotefast_eval "$2"
13100814a2baSmrg        func_quote_arg_result=$func_quotefast_eval_result
131163847c39Smrg        ;;
131263847c39Smrg    esac
13130814a2baSmrg}
13140814a2baSmrg
131563847c39Smrg
13160814a2baSmrg# func_quote MODEs ARGs...
13170814a2baSmrg# ------------------------
13180814a2baSmrg# Quote all ARGs to be evaled later and join them into single command.  See
13190814a2baSmrg# func_quote_arg's description for more info.
13200814a2baSmrgfunc_quote ()
13210814a2baSmrg{
13220814a2baSmrg    $debug_cmd
13230814a2baSmrg    _G_func_quote_mode=$1 ; shift
13240814a2baSmrg    func_quote_result=
13250814a2baSmrg    while test 0 -lt $#; do
13260814a2baSmrg      func_quote_arg "$_G_func_quote_mode" "$1"
13270814a2baSmrg      if test -n "$func_quote_result"; then
13280814a2baSmrg        func_append func_quote_result " $func_quote_arg_result"
13290814a2baSmrg      else
13300814a2baSmrg        func_append func_quote_result "$func_quote_arg_result"
13310814a2baSmrg      fi
13320814a2baSmrg      shift
13330814a2baSmrg    done
133463847c39Smrg}
133563847c39Smrg
133663847c39Smrg
13370814a2baSmrg# func_stripname PREFIX SUFFIX NAME
13380814a2baSmrg# ---------------------------------
13390814a2baSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
13400814a2baSmrg# PREFIX and SUFFIX must not contain globbing or regex special
13410814a2baSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
13420814a2baSmrg# dot (in which case that matches only a dot).
13430814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
13440814a2baSmrg  eval 'func_stripname ()
13450814a2baSmrg  {
13460814a2baSmrg    $debug_cmd
13470814a2baSmrg
13480814a2baSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
13490814a2baSmrg    # positional parameters, so assign one to ordinary variable first.
13500814a2baSmrg    func_stripname_result=$3
13510814a2baSmrg    func_stripname_result=${func_stripname_result#"$1"}
13520814a2baSmrg    func_stripname_result=${func_stripname_result%"$2"}
13530814a2baSmrg  }'
13540814a2baSmrgelse
13550814a2baSmrg  func_stripname ()
13560814a2baSmrg  {
13570814a2baSmrg    $debug_cmd
13580814a2baSmrg
13590814a2baSmrg    case $2 in
13600814a2baSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
13610814a2baSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
13620814a2baSmrg    esac
13630814a2baSmrg  }
13640814a2baSmrgfi
13650814a2baSmrg
13660814a2baSmrg
13670814a2baSmrg# func_show_eval CMD [FAIL_EXP]
13680814a2baSmrg# -----------------------------
13690814a2baSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
137063847c39Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
137163847c39Smrg# is given, then evaluate it.
137263847c39Smrgfunc_show_eval ()
137363847c39Smrg{
13740814a2baSmrg    $debug_cmd
13750814a2baSmrg
13760814a2baSmrg    _G_cmd=$1
13770814a2baSmrg    _G_fail_exp=${2-':'}
13780814a2baSmrg
13790814a2baSmrg    func_quote_arg pretty,expand "$_G_cmd"
13800814a2baSmrg    eval "func_notquiet $func_quote_arg_result"
13810814a2baSmrg
13820814a2baSmrg    $opt_dry_run || {
13830814a2baSmrg      eval "$_G_cmd"
13840814a2baSmrg      _G_status=$?
13850814a2baSmrg      if test 0 -ne "$_G_status"; then
13860814a2baSmrg	eval "(exit $_G_status); $_G_fail_exp"
13870814a2baSmrg      fi
13880814a2baSmrg    }
13890814a2baSmrg}
13900814a2baSmrg
13910814a2baSmrg
13920814a2baSmrg# func_show_eval_locale CMD [FAIL_EXP]
13930814a2baSmrg# ------------------------------------
13940814a2baSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13950814a2baSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13960814a2baSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
13970814a2baSmrgfunc_show_eval_locale ()
13980814a2baSmrg{
13990814a2baSmrg    $debug_cmd
14000814a2baSmrg
14010814a2baSmrg    _G_cmd=$1
14020814a2baSmrg    _G_fail_exp=${2-':'}
14030814a2baSmrg
14040814a2baSmrg    $opt_quiet || {
14050814a2baSmrg      func_quote_arg expand,pretty "$_G_cmd"
14060814a2baSmrg      eval "func_echo $func_quote_arg_result"
14070814a2baSmrg    }
14080814a2baSmrg
14090814a2baSmrg    $opt_dry_run || {
14100814a2baSmrg      eval "$_G_user_locale
14110814a2baSmrg	    $_G_cmd"
14120814a2baSmrg      _G_status=$?
14130814a2baSmrg      eval "$_G_safe_locale"
14140814a2baSmrg      if test 0 -ne "$_G_status"; then
14150814a2baSmrg	eval "(exit $_G_status); $_G_fail_exp"
14160814a2baSmrg      fi
14170814a2baSmrg    }
14180814a2baSmrg}
14190814a2baSmrg
14200814a2baSmrg
14210814a2baSmrg# func_tr_sh
14220814a2baSmrg# ----------
14230814a2baSmrg# Turn $1 into a string suitable for a shell variable name.
14240814a2baSmrg# Result is stored in $func_tr_sh_result.  All characters
14250814a2baSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
14260814a2baSmrg# if $1 begins with a digit, a '_' is prepended as well.
14270814a2baSmrgfunc_tr_sh ()
14280814a2baSmrg{
14290814a2baSmrg    $debug_cmd
14300814a2baSmrg
14310814a2baSmrg    case $1 in
14320814a2baSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
14330814a2baSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
14340814a2baSmrg      ;;
14350814a2baSmrg    * )
14360814a2baSmrg      func_tr_sh_result=$1
14370814a2baSmrg      ;;
14380814a2baSmrg    esac
14390814a2baSmrg}
14400814a2baSmrg
14410814a2baSmrg
14420814a2baSmrg# func_verbose ARG...
14430814a2baSmrg# -------------------
14440814a2baSmrg# Echo program name prefixed message in verbose mode only.
14450814a2baSmrgfunc_verbose ()
14460814a2baSmrg{
14470814a2baSmrg    $debug_cmd
14480814a2baSmrg
14490814a2baSmrg    $opt_verbose && func_echo "$*"
14500814a2baSmrg
14510814a2baSmrg    :
14520814a2baSmrg}
14530814a2baSmrg
14540814a2baSmrg
14550814a2baSmrg# func_warn_and_continue ARG...
14560814a2baSmrg# -----------------------------
14570814a2baSmrg# Echo program name prefixed warning message to standard error.
14580814a2baSmrgfunc_warn_and_continue ()
14590814a2baSmrg{
14600814a2baSmrg    $debug_cmd
14610814a2baSmrg
14620814a2baSmrg    $require_term_colors
14630814a2baSmrg
14640814a2baSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
14650814a2baSmrg}
14660814a2baSmrg
14670814a2baSmrg
14680814a2baSmrg# func_warning CATEGORY ARG...
14690814a2baSmrg# ----------------------------
14700814a2baSmrg# Echo program name prefixed warning message to standard error. Warning
14710814a2baSmrg# messages can be filtered according to CATEGORY, where this function
14720814a2baSmrg# elides messages where CATEGORY is not listed in the global variable
14730814a2baSmrg# 'opt_warning_types'.
14740814a2baSmrgfunc_warning ()
14750814a2baSmrg{
14760814a2baSmrg    $debug_cmd
14770814a2baSmrg
14780814a2baSmrg    # CATEGORY must be in the warning_categories list!
14790814a2baSmrg    case " $warning_categories " in
14800814a2baSmrg      *" $1 "*) ;;
14810814a2baSmrg      *) func_internal_error "invalid warning category '$1'" ;;
14820814a2baSmrg    esac
14830814a2baSmrg
14840814a2baSmrg    _G_category=$1
14850814a2baSmrg    shift
14860814a2baSmrg
14870814a2baSmrg    case " $opt_warning_types " in
14880814a2baSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
14890814a2baSmrg    esac
14900814a2baSmrg}
14910814a2baSmrg
14920814a2baSmrg
14930814a2baSmrg# func_sort_ver VER1 VER2
14940814a2baSmrg# -----------------------
14950814a2baSmrg# 'sort -V' is not generally available.
14960814a2baSmrg# Note this deviates from the version comparison in automake
14970814a2baSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
14980814a2baSmrg# but this should suffice as we won't be specifying old
14990814a2baSmrg# version formats or redundant trailing .0 in bootstrap.conf.
15000814a2baSmrg# If we did want full compatibility then we should probably
15010814a2baSmrg# use m4_version_compare from autoconf.
15020814a2baSmrgfunc_sort_ver ()
15030814a2baSmrg{
15040814a2baSmrg    $debug_cmd
15050814a2baSmrg
15060814a2baSmrg    printf '%s\n%s\n' "$1" "$2" \
15070814a2baSmrg      | 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
15080814a2baSmrg}
15090814a2baSmrg
15100814a2baSmrg# func_lt_ver PREV CURR
15110814a2baSmrg# ---------------------
15120814a2baSmrg# Return true if PREV and CURR are in the correct order according to
15130814a2baSmrg# func_sort_ver, otherwise false.  Use it like this:
15140814a2baSmrg#
15150814a2baSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
15160814a2baSmrgfunc_lt_ver ()
15170814a2baSmrg{
15180814a2baSmrg    $debug_cmd
15190814a2baSmrg
15200814a2baSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
15210814a2baSmrg}
15220814a2baSmrg
15230814a2baSmrg
15240814a2baSmrg# Local variables:
15250814a2baSmrg# mode: shell-script
15260814a2baSmrg# sh-indentation: 2
15270814a2baSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
15280814a2baSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
15290814a2baSmrg# time-stamp-time-zone: "UTC"
15300814a2baSmrg# End:
15310814a2baSmrg#! /bin/sh
15320814a2baSmrg
15330814a2baSmrg# A portable, pluggable option parser for Bourne shell.
15340814a2baSmrg# Written by Gary V. Vaughan, 2010
15350814a2baSmrg
15360814a2baSmrg# This is free software.  There is NO warranty; not even for
15370814a2baSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15380814a2baSmrg#
15390814a2baSmrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
15400814a2baSmrg#
15410814a2baSmrg# This file is dual licensed under the terms of the MIT license
15420814a2baSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
15430814a2baSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15440814a2baSmrg# these licenses when using or redistributing this software or any of
15450814a2baSmrg# the files within it.  See the URLs above, or the file `LICENSE`
15460814a2baSmrg# included in the Bootstrap distribution for the full license texts.
15470814a2baSmrg
15480814a2baSmrg# Please report bugs or propose patches to:
15490814a2baSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
15500814a2baSmrg
15510814a2baSmrg# Set a version string for this script.
15520814a2baSmrgscriptversion=2019-02-19.15; # UTC
15530814a2baSmrg
15540814a2baSmrg
15550814a2baSmrg## ------ ##
15560814a2baSmrg## Usage. ##
15570814a2baSmrg## ------ ##
15580814a2baSmrg
15590814a2baSmrg# This file is a library for parsing options in your shell scripts along
15600814a2baSmrg# with assorted other useful supporting features that you can make use
15610814a2baSmrg# of too.
15620814a2baSmrg#
15630814a2baSmrg# For the simplest scripts you might need only:
15640814a2baSmrg#
15650814a2baSmrg#   #!/bin/sh
15660814a2baSmrg#   . relative/path/to/funclib.sh
15670814a2baSmrg#   . relative/path/to/options-parser
15680814a2baSmrg#   scriptversion=1.0
15690814a2baSmrg#   func_options ${1+"$@"}
15700814a2baSmrg#   eval set dummy "$func_options_result"; shift
15710814a2baSmrg#   ...rest of your script...
15720814a2baSmrg#
15730814a2baSmrg# In order for the '--version' option to work, you will need to have a
15740814a2baSmrg# suitably formatted comment like the one at the top of this file
15750814a2baSmrg# starting with '# Written by ' and ending with '# Copyright'.
15760814a2baSmrg#
15770814a2baSmrg# For '-h' and '--help' to work, you will also need a one line
15780814a2baSmrg# description of your script's purpose in a comment directly above the
15790814a2baSmrg# '# Written by ' line, like the one at the top of this file.
15800814a2baSmrg#
15810814a2baSmrg# The default options also support '--debug', which will turn on shell
15820814a2baSmrg# execution tracing (see the comment above debug_cmd below for another
15830814a2baSmrg# use), and '--verbose' and the func_verbose function to allow your script
15840814a2baSmrg# to display verbose messages only when your user has specified
15850814a2baSmrg# '--verbose'.
15860814a2baSmrg#
15870814a2baSmrg# After sourcing this file, you can plug in processing for additional
15880814a2baSmrg# options by amending the variables from the 'Configuration' section
15890814a2baSmrg# below, and following the instructions in the 'Option parsing'
15900814a2baSmrg# section further down.
15910814a2baSmrg
15920814a2baSmrg## -------------- ##
15930814a2baSmrg## Configuration. ##
15940814a2baSmrg## -------------- ##
15950814a2baSmrg
15960814a2baSmrg# You should override these variables in your script after sourcing this
15970814a2baSmrg# file so that they reflect the customisations you have added to the
15980814a2baSmrg# option parser.
15990814a2baSmrg
16000814a2baSmrg# The usage line for option parsing errors and the start of '-h' and
16010814a2baSmrg# '--help' output messages. You can embed shell variables for delayed
16020814a2baSmrg# expansion at the time the message is displayed, but you will need to
16030814a2baSmrg# quote other shell meta-characters carefully to prevent them being
16040814a2baSmrg# expanded when the contents are evaled.
16050814a2baSmrgusage='$progpath [OPTION]...'
16060814a2baSmrg
16070814a2baSmrg# Short help message in response to '-h' and '--help'.  Add to this or
16080814a2baSmrg# override it after sourcing this library to reflect the full set of
16090814a2baSmrg# options your script accepts.
16100814a2baSmrgusage_message="\
16110814a2baSmrg       --debug        enable verbose shell tracing
16120814a2baSmrg   -W, --warnings=CATEGORY
16130814a2baSmrg                      report the warnings falling in CATEGORY [all]
16140814a2baSmrg   -v, --verbose      verbosely report processing
16150814a2baSmrg       --version      print version information and exit
16160814a2baSmrg   -h, --help         print short or long help message and exit
16170814a2baSmrg"
16180814a2baSmrg
16190814a2baSmrg# Additional text appended to 'usage_message' in response to '--help'.
16200814a2baSmrglong_help_message="
16210814a2baSmrgWarning categories include:
16220814a2baSmrg       'all'          show all warnings
16230814a2baSmrg       'none'         turn off all the warnings
16240814a2baSmrg       'error'        warnings are treated as fatal errors"
16250814a2baSmrg
16260814a2baSmrg# Help message printed before fatal option parsing errors.
16270814a2baSmrgfatal_help="Try '\$progname --help' for more information."
16280814a2baSmrg
16290814a2baSmrg
16300814a2baSmrg
16310814a2baSmrg## ------------------------- ##
16320814a2baSmrg## Hook function management. ##
16330814a2baSmrg## ------------------------- ##
16340814a2baSmrg
16350814a2baSmrg# This section contains functions for adding, removing, and running hooks
16360814a2baSmrg# in the main code.  A hook is just a list of function names that can be
16370814a2baSmrg# run in order later on.
16380814a2baSmrg
16390814a2baSmrg# func_hookable FUNC_NAME
16400814a2baSmrg# -----------------------
16410814a2baSmrg# Declare that FUNC_NAME will run hooks added with
16420814a2baSmrg# 'func_add_hook FUNC_NAME ...'.
16430814a2baSmrgfunc_hookable ()
16440814a2baSmrg{
16450814a2baSmrg    $debug_cmd
16460814a2baSmrg
16470814a2baSmrg    func_append hookable_fns " $1"
16480814a2baSmrg}
16490814a2baSmrg
16500814a2baSmrg
16510814a2baSmrg# func_add_hook FUNC_NAME HOOK_FUNC
16520814a2baSmrg# ---------------------------------
16530814a2baSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
16540814a2baSmrg# first have been declared "hookable" by a call to 'func_hookable'.
16550814a2baSmrgfunc_add_hook ()
16560814a2baSmrg{
16570814a2baSmrg    $debug_cmd
16580814a2baSmrg
16590814a2baSmrg    case " $hookable_fns " in
16600814a2baSmrg      *" $1 "*) ;;
16610814a2baSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
16620814a2baSmrg    esac
16630814a2baSmrg
16640814a2baSmrg    eval func_append ${1}_hooks '" $2"'
16650814a2baSmrg}
16660814a2baSmrg
16670814a2baSmrg
16680814a2baSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
16690814a2baSmrg# ------------------------------------
16700814a2baSmrg# Remove HOOK_FUNC from the list of hook functions to be called by
16710814a2baSmrg# FUNC_NAME.
16720814a2baSmrgfunc_remove_hook ()
16730814a2baSmrg{
16740814a2baSmrg    $debug_cmd
16750814a2baSmrg
16760814a2baSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
16770814a2baSmrg}
16780814a2baSmrg
16790814a2baSmrg
16800814a2baSmrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16810814a2baSmrg# ---------------------------------------------
16820814a2baSmrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16830814a2baSmrg# *_result variable of FUNC_NAME_B.
16840814a2baSmrgfunc_propagate_result ()
16850814a2baSmrg{
16860814a2baSmrg    $debug_cmd
16870814a2baSmrg
16880814a2baSmrg    func_propagate_result_result=:
16890814a2baSmrg    if eval "test \"\${${1}_result+set}\" = set"
16900814a2baSmrg    then
16910814a2baSmrg      eval "${2}_result=\$${1}_result"
16920814a2baSmrg    else
16930814a2baSmrg      func_propagate_result_result=false
16940814a2baSmrg    fi
16950814a2baSmrg}
16960814a2baSmrg
16970814a2baSmrg
16980814a2baSmrg# func_run_hooks FUNC_NAME [ARG]...
16990814a2baSmrg# ---------------------------------
17000814a2baSmrg# Run all hook functions registered to FUNC_NAME.
17010814a2baSmrg# It's assumed that the list of hook functions contains nothing more
17020814a2baSmrg# than a whitespace-delimited list of legal shell function names, and
17030814a2baSmrg# no effort is wasted trying to catch shell meta-characters or preserve
17040814a2baSmrg# whitespace.
17050814a2baSmrgfunc_run_hooks ()
17060814a2baSmrg{
17070814a2baSmrg    $debug_cmd
17080814a2baSmrg
17090814a2baSmrg    case " $hookable_fns " in
17100814a2baSmrg      *" $1 "*) ;;
17110814a2baSmrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17120814a2baSmrg    esac
17130814a2baSmrg
17140814a2baSmrg    eval _G_hook_fns=\$$1_hooks; shift
17150814a2baSmrg
17160814a2baSmrg    for _G_hook in $_G_hook_fns; do
17170814a2baSmrg      func_unset "${_G_hook}_result"
17180814a2baSmrg      eval $_G_hook '${1+"$@"}'
17190814a2baSmrg      func_propagate_result $_G_hook func_run_hooks
17200814a2baSmrg      if $func_propagate_result_result; then
17210814a2baSmrg        eval set dummy "$func_run_hooks_result"; shift
17220814a2baSmrg      fi
17230814a2baSmrg    done
17240814a2baSmrg}
17250814a2baSmrg
17260814a2baSmrg
17270814a2baSmrg
17280814a2baSmrg## --------------- ##
17290814a2baSmrg## Option parsing. ##
17300814a2baSmrg## --------------- ##
17310814a2baSmrg
17320814a2baSmrg# In order to add your own option parsing hooks, you must accept the
17330814a2baSmrg# full positional parameter list from your hook function.  You may remove
17340814a2baSmrg# or edit any options that you action, and then pass back the remaining
17350814a2baSmrg# unprocessed options in '<hooked_function_name>_result', escaped
17360814a2baSmrg# suitably for 'eval'.
17370814a2baSmrg#
17380814a2baSmrg# The '<hooked_function_name>_result' variable is automatically unset
17390814a2baSmrg# before your hook gets called; for best performance, only set the
17400814a2baSmrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17410814a2baSmrg# function unnecessarily because it can be an expensive operation on some
17420814a2baSmrg# machines).
17430814a2baSmrg#
17440814a2baSmrg# Like this:
17450814a2baSmrg#
17460814a2baSmrg#    my_options_prep ()
17470814a2baSmrg#    {
17480814a2baSmrg#        $debug_cmd
17490814a2baSmrg#
17500814a2baSmrg#        # Extend the existing usage message.
17510814a2baSmrg#        usage_message=$usage_message'
17520814a2baSmrg#      -s, --silent       don'\''t print informational messages
17530814a2baSmrg#    '
17540814a2baSmrg#        # No change in '$@' (ignored completely by this hook).  Leave
17550814a2baSmrg#        # my_options_prep_result variable intact.
17560814a2baSmrg#    }
17570814a2baSmrg#    func_add_hook func_options_prep my_options_prep
17580814a2baSmrg#
17590814a2baSmrg#
17600814a2baSmrg#    my_silent_option ()
17610814a2baSmrg#    {
17620814a2baSmrg#        $debug_cmd
17630814a2baSmrg#
17640814a2baSmrg#        args_changed=false
17650814a2baSmrg#
17660814a2baSmrg#        # Note that, for efficiency, we parse as many options as we can
17670814a2baSmrg#        # recognise in a loop before passing the remainder back to the
17680814a2baSmrg#        # caller on the first unrecognised argument we encounter.
17690814a2baSmrg#        while test $# -gt 0; do
17700814a2baSmrg#          opt=$1; shift
17710814a2baSmrg#          case $opt in
17720814a2baSmrg#            --silent|-s) opt_silent=:
17730814a2baSmrg#                         args_changed=:
17740814a2baSmrg#                         ;;
17750814a2baSmrg#            # Separate non-argument short options:
17760814a2baSmrg#            -s*)         func_split_short_opt "$_G_opt"
17770814a2baSmrg#                         set dummy "$func_split_short_opt_name" \
17780814a2baSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
17790814a2baSmrg#                         shift
17800814a2baSmrg#                         args_changed=:
17810814a2baSmrg#                         ;;
17820814a2baSmrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17830814a2baSmrg#                         # is added back to "$@" in case we need it later,
17840814a2baSmrg#                         # if $args_changed was set to 'true'.
17850814a2baSmrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17860814a2baSmrg#          esac
17870814a2baSmrg#        done
17880814a2baSmrg#
17890814a2baSmrg#        # Only call 'func_quote' here if we processed at least one argument.
17900814a2baSmrg#        if $args_changed; then
17910814a2baSmrg#          func_quote eval ${1+"$@"}
17920814a2baSmrg#          my_silent_option_result=$func_quote_result
17930814a2baSmrg#        fi
17940814a2baSmrg#    }
17950814a2baSmrg#    func_add_hook func_parse_options my_silent_option
17960814a2baSmrg#
17970814a2baSmrg#
17980814a2baSmrg#    my_option_validation ()
17990814a2baSmrg#    {
18000814a2baSmrg#        $debug_cmd
18010814a2baSmrg#
18020814a2baSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
18030814a2baSmrg#    '--silent' and '--verbose' options are mutually exclusive."
18040814a2baSmrg#    }
18050814a2baSmrg#    func_add_hook func_validate_options my_option_validation
18060814a2baSmrg#
18070814a2baSmrg# You'll also need to manually amend $usage_message to reflect the extra
18080814a2baSmrg# options you parse.  It's preferable to append if you can, so that
18090814a2baSmrg# multiple option parsing hooks can be added safely.
18100814a2baSmrg
18110814a2baSmrg
18120814a2baSmrg# func_options_finish [ARG]...
18130814a2baSmrg# ----------------------------
18140814a2baSmrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18150814a2baSmrgfunc_options_finish ()
18160814a2baSmrg{
18170814a2baSmrg    $debug_cmd
18180814a2baSmrg
18190814a2baSmrg    func_run_hooks func_options ${1+"$@"}
18200814a2baSmrg    func_propagate_result func_run_hooks func_options_finish
18210814a2baSmrg}
18220814a2baSmrg
18230814a2baSmrg
18240814a2baSmrg# func_options [ARG]...
18250814a2baSmrg# ---------------------
18260814a2baSmrg# All the functions called inside func_options are hookable. See the
18270814a2baSmrg# individual implementations for details.
18280814a2baSmrgfunc_hookable func_options
18290814a2baSmrgfunc_options ()
18300814a2baSmrg{
18310814a2baSmrg    $debug_cmd
18320814a2baSmrg
18330814a2baSmrg    _G_options_quoted=false
18340814a2baSmrg
18350814a2baSmrg    for my_func in options_prep parse_options validate_options options_finish
18360814a2baSmrg    do
18370814a2baSmrg      func_unset func_${my_func}_result
18380814a2baSmrg      func_unset func_run_hooks_result
18390814a2baSmrg      eval func_$my_func '${1+"$@"}'
18400814a2baSmrg      func_propagate_result func_$my_func func_options
18410814a2baSmrg      if $func_propagate_result_result; then
18420814a2baSmrg        eval set dummy "$func_options_result"; shift
18430814a2baSmrg        _G_options_quoted=:
18440814a2baSmrg      fi
18450814a2baSmrg    done
18460814a2baSmrg
18470814a2baSmrg    $_G_options_quoted || {
18480814a2baSmrg      # As we (func_options) are top-level options-parser function and
18490814a2baSmrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18500814a2baSmrg      # caller.
18510814a2baSmrg      func_quote eval ${1+"$@"}
18520814a2baSmrg      func_options_result=$func_quote_result
18530814a2baSmrg    }
18540814a2baSmrg}
18550814a2baSmrg
18560814a2baSmrg
18570814a2baSmrg# func_options_prep [ARG]...
18580814a2baSmrg# --------------------------
18590814a2baSmrg# All initialisations required before starting the option parse loop.
18600814a2baSmrg# Note that when calling hook functions, we pass through the list of
18610814a2baSmrg# positional parameters.  If a hook function modifies that list, and
18620814a2baSmrg# needs to propagate that back to rest of this script, then the complete
18630814a2baSmrg# modified list must be put in 'func_run_hooks_result' before returning.
18640814a2baSmrgfunc_hookable func_options_prep
18650814a2baSmrgfunc_options_prep ()
18660814a2baSmrg{
18670814a2baSmrg    $debug_cmd
18680814a2baSmrg
18690814a2baSmrg    # Option defaults:
18700814a2baSmrg    opt_verbose=false
18710814a2baSmrg    opt_warning_types=
18720814a2baSmrg
18730814a2baSmrg    func_run_hooks func_options_prep ${1+"$@"}
18740814a2baSmrg    func_propagate_result func_run_hooks func_options_prep
18750814a2baSmrg}
18760814a2baSmrg
18770814a2baSmrg
18780814a2baSmrg# func_parse_options [ARG]...
18790814a2baSmrg# ---------------------------
18800814a2baSmrg# The main option parsing loop.
18810814a2baSmrgfunc_hookable func_parse_options
18820814a2baSmrgfunc_parse_options ()
18830814a2baSmrg{
18840814a2baSmrg    $debug_cmd
18850814a2baSmrg
18860814a2baSmrg    _G_parse_options_requote=false
18870814a2baSmrg    # this just eases exit handling
18880814a2baSmrg    while test $# -gt 0; do
18890814a2baSmrg      # Defer to hook functions for initial option parsing, so they
18900814a2baSmrg      # get priority in the event of reusing an option name.
18910814a2baSmrg      func_run_hooks func_parse_options ${1+"$@"}
18920814a2baSmrg      func_propagate_result func_run_hooks func_parse_options
18930814a2baSmrg      if $func_propagate_result_result; then
18940814a2baSmrg        eval set dummy "$func_parse_options_result"; shift
18950814a2baSmrg        # Even though we may have changed "$@", we passed the "$@" array
18960814a2baSmrg        # down into the hook and it quoted it for us (because we are in
18970814a2baSmrg        # this if-branch).  No need to quote it again.
18980814a2baSmrg        _G_parse_options_requote=false
18990814a2baSmrg      fi
19000814a2baSmrg
19010814a2baSmrg      # Break out of the loop if we already parsed every option.
19020814a2baSmrg      test $# -gt 0 || break
19030814a2baSmrg
19040814a2baSmrg      # We expect that one of the options parsed in this function matches
19050814a2baSmrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19060814a2baSmrg      _G_match_parse_options=:
19070814a2baSmrg      _G_opt=$1
19080814a2baSmrg      shift
19090814a2baSmrg      case $_G_opt in
19100814a2baSmrg        --debug|-x)   debug_cmd='set -x'
19110814a2baSmrg                      func_echo "enabling shell trace mode" >&2
19120814a2baSmrg                      $debug_cmd
19130814a2baSmrg                      ;;
19140814a2baSmrg
19150814a2baSmrg        --no-warnings|--no-warning|--no-warn)
19160814a2baSmrg                      set dummy --warnings none ${1+"$@"}
19170814a2baSmrg                      shift
19180814a2baSmrg		      ;;
191963847c39Smrg
19200814a2baSmrg        --warnings|--warning|-W)
19210814a2baSmrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19220814a2baSmrg                        _G_parse_options_requote=:
19230814a2baSmrg                        break
19240814a2baSmrg                      fi
19250814a2baSmrg                      case " $warning_categories $1" in
19260814a2baSmrg                        *" $1 "*)
19270814a2baSmrg                          # trailing space prevents matching last $1 above
19280814a2baSmrg                          func_append_uniq opt_warning_types " $1"
19290814a2baSmrg                          ;;
19300814a2baSmrg                        *all)
19310814a2baSmrg                          opt_warning_types=$warning_categories
19320814a2baSmrg                          ;;
19330814a2baSmrg                        *none)
19340814a2baSmrg                          opt_warning_types=none
19350814a2baSmrg                          warning_func=:
19360814a2baSmrg                          ;;
19370814a2baSmrg                        *error)
19380814a2baSmrg                          opt_warning_types=$warning_categories
19390814a2baSmrg                          warning_func=func_fatal_error
19400814a2baSmrg                          ;;
19410814a2baSmrg                        *)
19420814a2baSmrg                          func_fatal_error \
19430814a2baSmrg                             "unsupported warning category: '$1'"
19440814a2baSmrg                          ;;
19450814a2baSmrg                      esac
19460814a2baSmrg                      shift
19470814a2baSmrg                      ;;
19480814a2baSmrg
19490814a2baSmrg        --verbose|-v) opt_verbose=: ;;
19500814a2baSmrg        --version)    func_version ;;
19510814a2baSmrg        -\?|-h)       func_usage ;;
19520814a2baSmrg        --help)       func_help ;;
19530814a2baSmrg
19540814a2baSmrg	# Separate optargs to long options (plugins may need this):
19550814a2baSmrg	--*=*)        func_split_equals "$_G_opt"
19560814a2baSmrg	              set dummy "$func_split_equals_lhs" \
19570814a2baSmrg                          "$func_split_equals_rhs" ${1+"$@"}
19580814a2baSmrg                      shift
19590814a2baSmrg                      ;;
19600814a2baSmrg
19610814a2baSmrg       # Separate optargs to short options:
19620814a2baSmrg        -W*)
19630814a2baSmrg                      func_split_short_opt "$_G_opt"
19640814a2baSmrg                      set dummy "$func_split_short_opt_name" \
19650814a2baSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
19660814a2baSmrg                      shift
19670814a2baSmrg                      ;;
19680814a2baSmrg
19690814a2baSmrg        # Separate non-argument short options:
19700814a2baSmrg        -\?*|-h*|-v*|-x*)
19710814a2baSmrg                      func_split_short_opt "$_G_opt"
19720814a2baSmrg                      set dummy "$func_split_short_opt_name" \
19730814a2baSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
19740814a2baSmrg                      shift
19750814a2baSmrg                      ;;
19760814a2baSmrg
19770814a2baSmrg        --)           _G_parse_options_requote=: ; break ;;
19780814a2baSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19790814a2baSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19800814a2baSmrg                      _G_match_parse_options=false
19810814a2baSmrg                      break
19820814a2baSmrg                      ;;
19830814a2baSmrg      esac
198463847c39Smrg
19850814a2baSmrg      if $_G_match_parse_options; then
19860814a2baSmrg        _G_parse_options_requote=:
198763847c39Smrg      fi
19880814a2baSmrg    done
19890814a2baSmrg
19900814a2baSmrg    if $_G_parse_options_requote; then
19910814a2baSmrg      # save modified positional parameters for caller
19920814a2baSmrg      func_quote eval ${1+"$@"}
19930814a2baSmrg      func_parse_options_result=$func_quote_result
1994d8556812Smrg    fi
199563847c39Smrg}
199663847c39Smrg
199763847c39Smrg
19980814a2baSmrg# func_validate_options [ARG]...
19990814a2baSmrg# ------------------------------
20000814a2baSmrg# Perform any sanity checks on option settings and/or unconsumed
20010814a2baSmrg# arguments.
20020814a2baSmrgfunc_hookable func_validate_options
20030814a2baSmrgfunc_validate_options ()
200463847c39Smrg{
20050814a2baSmrg    $debug_cmd
200663847c39Smrg
20070814a2baSmrg    # Display all warnings if -W was not given.
20080814a2baSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
200963847c39Smrg
20100814a2baSmrg    func_run_hooks func_validate_options ${1+"$@"}
20110814a2baSmrg    func_propagate_result func_run_hooks func_validate_options
201263847c39Smrg
20130814a2baSmrg    # Bail if the options were screwed!
20140814a2baSmrg    $exit_cmd $EXIT_FAILURE
201576888252Smrg}
201676888252Smrg
201776888252Smrg
201863847c39Smrg
20190814a2baSmrg## ----------------- ##
20200814a2baSmrg## Helper functions. ##
20210814a2baSmrg## ----------------- ##
202276888252Smrg
20230814a2baSmrg# This section contains the helper functions used by the rest of the
20240814a2baSmrg# hookable option parser framework in ascii-betical order.
20250814a2baSmrg
20260814a2baSmrg
20270814a2baSmrg# func_fatal_help ARG...
20280814a2baSmrg# ----------------------
20290814a2baSmrg# Echo program name prefixed message to standard error, followed by
20300814a2baSmrg# a help hint, and exit.
20310814a2baSmrgfunc_fatal_help ()
203276888252Smrg{
20330814a2baSmrg    $debug_cmd
203463847c39Smrg
20350814a2baSmrg    eval \$ECHO \""Usage: $usage"\"
20360814a2baSmrg    eval \$ECHO \""$fatal_help"\"
20370814a2baSmrg    func_error ${1+"$@"}
20380814a2baSmrg    exit $EXIT_FAILURE
203976888252Smrg}
204076888252Smrg
20410814a2baSmrg
20420814a2baSmrg# func_help
20430814a2baSmrg# ---------
20440814a2baSmrg# Echo long help message to standard output and exit.
204563847c39Smrgfunc_help ()
204676888252Smrg{
20470814a2baSmrg    $debug_cmd
20480814a2baSmrg
20490814a2baSmrg    func_usage_message
20500814a2baSmrg    $ECHO "$long_help_message"
20510814a2baSmrg    exit 0
205263847c39Smrg}
205376888252Smrg
20540814a2baSmrg
20550814a2baSmrg# func_missing_arg ARGNAME
20560814a2baSmrg# ------------------------
205763847c39Smrg# Echo program name prefixed message to standard error and set global
205863847c39Smrg# exit_cmd.
205963847c39Smrgfunc_missing_arg ()
206063847c39Smrg{
20610814a2baSmrg    $debug_cmd
206276888252Smrg
20630814a2baSmrg    func_error "Missing argument for '$1'."
206463847c39Smrg    exit_cmd=exit
206586dafe34Smrg}
206686dafe34Smrg
206786dafe34Smrg
20680814a2baSmrg# func_split_equals STRING
20690814a2baSmrg# ------------------------
20700814a2baSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20710814a2baSmrg# after splitting STRING at the '=' sign.
20720814a2baSmrgtest -z "$_G_HAVE_XSI_OPS" \
20730814a2baSmrg    && (eval 'x=a/b/c;
20740814a2baSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
20750814a2baSmrg    && _G_HAVE_XSI_OPS=yes
20760814a2baSmrg
20770814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"
20780814a2baSmrgthen
20790814a2baSmrg  # This is an XSI compatible shell, allowing a faster implementation...
20800814a2baSmrg  eval 'func_split_equals ()
20810814a2baSmrg  {
20820814a2baSmrg      $debug_cmd
20830814a2baSmrg
20840814a2baSmrg      func_split_equals_lhs=${1%%=*}
20850814a2baSmrg      func_split_equals_rhs=${1#*=}
20860814a2baSmrg      if test "x$func_split_equals_lhs" = "x$1"; then
20870814a2baSmrg        func_split_equals_rhs=
20880814a2baSmrg      fi
20890814a2baSmrg  }'
20900814a2baSmrgelse
20910814a2baSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
20920814a2baSmrg  func_split_equals ()
20930814a2baSmrg  {
20940814a2baSmrg      $debug_cmd
20950814a2baSmrg
20960814a2baSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
20970814a2baSmrg      func_split_equals_rhs=
20980814a2baSmrg      test "x$func_split_equals_lhs=" = "x$1" \
20990814a2baSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
21000814a2baSmrg  }
21010814a2baSmrgfi #func_split_equals
21020814a2baSmrg
21030814a2baSmrg
21040814a2baSmrg# func_split_short_opt SHORTOPT
21050814a2baSmrg# -----------------------------
210663847c39Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
210763847c39Smrg# variables after splitting SHORTOPT after the 2nd character.
21080814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"
21090814a2baSmrgthen
21100814a2baSmrg  # This is an XSI compatible shell, allowing a faster implementation...
21110814a2baSmrg  eval 'func_split_short_opt ()
21120814a2baSmrg  {
21130814a2baSmrg      $debug_cmd
21140814a2baSmrg
21150814a2baSmrg      func_split_short_opt_arg=${1#??}
21160814a2baSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
21170814a2baSmrg  }'
21180814a2baSmrgelse
21190814a2baSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
21200814a2baSmrg  func_split_short_opt ()
21210814a2baSmrg  {
21220814a2baSmrg      $debug_cmd
21230814a2baSmrg
21240814a2baSmrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
21250814a2baSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
21260814a2baSmrg  }
21270814a2baSmrgfi #func_split_short_opt
21280814a2baSmrg
21290814a2baSmrg
21300814a2baSmrg# func_usage
21310814a2baSmrg# ----------
21320814a2baSmrg# Echo short help message to standard output and exit.
21330814a2baSmrgfunc_usage ()
213463847c39Smrg{
21350814a2baSmrg    $debug_cmd
213663847c39Smrg
21370814a2baSmrg    func_usage_message
21380814a2baSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
21390814a2baSmrg    exit 0
21400814a2baSmrg}
214186dafe34Smrg
214276888252Smrg
21430814a2baSmrg# func_usage_message
21440814a2baSmrg# ------------------
21450814a2baSmrg# Echo short help message to standard output.
21460814a2baSmrgfunc_usage_message ()
214763847c39Smrg{
21480814a2baSmrg    $debug_cmd
21490814a2baSmrg
21500814a2baSmrg    eval \$ECHO \""Usage: $usage"\"
21510814a2baSmrg    echo
21520814a2baSmrg    $SED -n 's|^# ||
21530814a2baSmrg        /^Written by/{
21540814a2baSmrg          x;p;x
21550814a2baSmrg        }
21560814a2baSmrg	h
21570814a2baSmrg	/^Written by/q' < "$progpath"
21580814a2baSmrg    echo
21590814a2baSmrg    eval \$ECHO \""$usage_message"\"
21600814a2baSmrg}
216176888252Smrg
216276888252Smrg
21630814a2baSmrg# func_version
21640814a2baSmrg# ------------
21650814a2baSmrg# Echo version message to standard output and exit.
21660814a2baSmrg# The version message is extracted from the calling file's header
21670814a2baSmrg# comments, with leading '# ' stripped:
21680814a2baSmrg#   1. First display the progname and version
21690814a2baSmrg#   2. Followed by the header comment line matching  /^# Written by /
21700814a2baSmrg#   3. Then a blank line followed by the first following line matching
21710814a2baSmrg#      /^# Copyright /
21720814a2baSmrg#   4. Immediately followed by any lines between the previous matches,
21730814a2baSmrg#      except lines preceding the intervening completely blank line.
21740814a2baSmrg# For example, see the header comments of this file.
21750814a2baSmrgfunc_version ()
21760814a2baSmrg{
21770814a2baSmrg    $debug_cmd
217876888252Smrg
21790814a2baSmrg    printf '%s\n' "$progname $scriptversion"
21800814a2baSmrg    $SED -n '
21810814a2baSmrg        /^# Written by /!b
21820814a2baSmrg        s|^# ||; p; n
218386dafe34Smrg
21840814a2baSmrg        :fwd2blnk
21850814a2baSmrg        /./ {
21860814a2baSmrg          n
21870814a2baSmrg          b fwd2blnk
21880814a2baSmrg        }
21890814a2baSmrg        p; n
21900814a2baSmrg
21910814a2baSmrg        :holdwrnt
21920814a2baSmrg        s|^# ||
21930814a2baSmrg        s|^# *$||
21940814a2baSmrg        /^Copyright /!{
21950814a2baSmrg          /./H
21960814a2baSmrg          n
21970814a2baSmrg          b holdwrnt
21980814a2baSmrg        }
219986dafe34Smrg
22000814a2baSmrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22010814a2baSmrg        G
22020814a2baSmrg        s|\(\n\)\n*|\1|g
22030814a2baSmrg        p; q' < "$progpath"
220486dafe34Smrg
22050814a2baSmrg    exit $?
22060814a2baSmrg}
220776888252Smrg
220863847c39Smrg
22090814a2baSmrg# Local variables:
22100814a2baSmrg# mode: shell-script
22110814a2baSmrg# sh-indentation: 2
22120814a2baSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
22130814a2baSmrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
22140814a2baSmrg# time-stamp-time-zone: "UTC"
22150814a2baSmrg# End:
221663847c39Smrg
22170814a2baSmrg# Set a version string.
22180814a2baSmrgscriptversion='(GNU libtool) 2.4.7'
221963847c39Smrg
222063847c39Smrg
22210814a2baSmrg# func_echo ARG...
22220814a2baSmrg# ----------------
22230814a2baSmrg# Libtool also displays the current mode in messages, so override
22240814a2baSmrg# funclib.sh func_echo with this custom definition.
22250814a2baSmrgfunc_echo ()
222663847c39Smrg{
22270814a2baSmrg    $debug_cmd
222863847c39Smrg
22290814a2baSmrg    _G_message=$*
223063847c39Smrg
22310814a2baSmrg    func_echo_IFS=$IFS
22320814a2baSmrg    IFS=$nl
22330814a2baSmrg    for _G_line in $_G_message; do
22340814a2baSmrg      IFS=$func_echo_IFS
22350814a2baSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
22360814a2baSmrg    done
22370814a2baSmrg    IFS=$func_echo_IFS
22380814a2baSmrg}
223963847c39Smrg
224063847c39Smrg
22410814a2baSmrg# func_warning ARG...
22420814a2baSmrg# -------------------
22430814a2baSmrg# Libtool warnings are not categorized, so override funclib.sh
22440814a2baSmrg# func_warning with this simpler definition.
22450814a2baSmrgfunc_warning ()
224663847c39Smrg{
22470814a2baSmrg    $debug_cmd
224863847c39Smrg
22490814a2baSmrg    $warning_func ${1+"$@"}
22500814a2baSmrg}
225163847c39Smrg
225263847c39Smrg
22530814a2baSmrg## ---------------- ##
22540814a2baSmrg## Options parsing. ##
22550814a2baSmrg## ---------------- ##
22560814a2baSmrg
22570814a2baSmrg# Hook in the functions to make sure our own options are parsed during
22580814a2baSmrg# the option parsing loop.
22590814a2baSmrg
22600814a2baSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
22610814a2baSmrg
22620814a2baSmrg# Short help message in response to '-h'.
22630814a2baSmrgusage_message="Options:
22640814a2baSmrg       --config             show all configuration variables
22650814a2baSmrg       --debug              enable verbose shell tracing
22660814a2baSmrg   -n, --dry-run            display commands without modifying any files
22670814a2baSmrg       --features           display basic configuration information and exit
22680814a2baSmrg       --mode=MODE          use operation mode MODE
22690814a2baSmrg       --no-warnings        equivalent to '-Wnone'
22700814a2baSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
22710814a2baSmrg       --quiet, --silent    don't print informational messages
22720814a2baSmrg       --tag=TAG            use configuration variables from tag TAG
22730814a2baSmrg   -v, --verbose            print more informational messages than default
22740814a2baSmrg       --version            print version information
22750814a2baSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
22760814a2baSmrg   -h, --help, --help-all   print short, long, or detailed help message
22770814a2baSmrg"
227863847c39Smrg
22790814a2baSmrg# Additional text appended to 'usage_message' in response to '--help'.
22800814a2baSmrgfunc_help ()
228163847c39Smrg{
22820814a2baSmrg    $debug_cmd
22830814a2baSmrg
22840814a2baSmrg    func_usage_message
22850814a2baSmrg    $ECHO "$long_help_message
22860814a2baSmrg
22870814a2baSmrgMODE must be one of the following:
22880814a2baSmrg
22890814a2baSmrg       clean           remove files from the build directory
22900814a2baSmrg       compile         compile a source file into a libtool object
22910814a2baSmrg       execute         automatically set library path, then run a program
22920814a2baSmrg       finish          complete the installation of libtool libraries
22930814a2baSmrg       install         install libraries or executables
22940814a2baSmrg       link            create a library or an executable
22950814a2baSmrg       uninstall       remove libraries from an installed directory
22960814a2baSmrg
22970814a2baSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
22980814a2baSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
22990814a2baSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
23000814a2baSmrg
23010814a2baSmrgWhen reporting a bug, please describe a test case to reproduce it and
23020814a2baSmrginclude the following information:
23030814a2baSmrg
23040814a2baSmrg       host-triplet:   $host
23050814a2baSmrg       shell:          $SHELL
23060814a2baSmrg       compiler:       $LTCC
23070814a2baSmrg       compiler flags: $LTCFLAGS
23080814a2baSmrg       linker:         $LD (gnu? $with_gnu_ld)
23090814a2baSmrg       version:        $progname (GNU libtool) 2.4.7
23100814a2baSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
23110814a2baSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
23120814a2baSmrg
23130814a2baSmrgReport bugs to <bug-libtool@gnu.org>.
23140814a2baSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
23150814a2baSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
23160814a2baSmrg    exit 0
23170814a2baSmrg}
23180814a2baSmrg
23190814a2baSmrg
23200814a2baSmrg# func_lo2o OBJECT-NAME
23210814a2baSmrg# ---------------------
23220814a2baSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
23230814a2baSmrg# object suffix.
23240814a2baSmrg
23250814a2baSmrglo2o=s/\\.lo\$/.$objext/
23260814a2baSmrgo2lo=s/\\.$objext\$/.lo/
23270814a2baSmrg
23280814a2baSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
23290814a2baSmrg  eval 'func_lo2o ()
23300814a2baSmrg  {
23310814a2baSmrg    case $1 in
23320814a2baSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
23330814a2baSmrg      *   ) func_lo2o_result=$1               ;;
23340814a2baSmrg    esac
23350814a2baSmrg  }'
23360814a2baSmrg
23370814a2baSmrg  # func_xform LIBOBJ-OR-SOURCE
23380814a2baSmrg  # ---------------------------
23390814a2baSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
23400814a2baSmrg  # suffix to a '.lo' libtool-object suffix.
23410814a2baSmrg  eval 'func_xform ()
23420814a2baSmrg  {
23430814a2baSmrg    func_xform_result=${1%.*}.lo
23440814a2baSmrg  }'
23450814a2baSmrgelse
23460814a2baSmrg  # ...otherwise fall back to using sed.
23470814a2baSmrg  func_lo2o ()
23480814a2baSmrg  {
23490814a2baSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
23500814a2baSmrg  }
23510814a2baSmrg
23520814a2baSmrg  func_xform ()
23530814a2baSmrg  {
23540814a2baSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
23550814a2baSmrg  }
23560814a2baSmrgfi
235763847c39Smrg
235863847c39Smrg
23590814a2baSmrg# func_fatal_configuration ARG...
23600814a2baSmrg# -------------------------------
236163847c39Smrg# Echo program name prefixed message to standard error, followed by
236263847c39Smrg# a configuration failure hint, and exit.
236363847c39Smrgfunc_fatal_configuration ()
236463847c39Smrg{
23650814a2baSmrg    func_fatal_error ${1+"$@"} \
23660814a2baSmrg      "See the $PACKAGE documentation for more information." \
23670814a2baSmrg      "Fatal configuration error."
236863847c39Smrg}
236963847c39Smrg
237063847c39Smrg
237163847c39Smrg# func_config
23720814a2baSmrg# -----------
237363847c39Smrg# Display the configuration for all the tags in this script.
237463847c39Smrgfunc_config ()
237563847c39Smrg{
237663847c39Smrg    re_begincf='^# ### BEGIN LIBTOOL'
237763847c39Smrg    re_endcf='^# ### END LIBTOOL'
237863847c39Smrg
237963847c39Smrg    # Default configuration.
238063847c39Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
238163847c39Smrg
238276888252Smrg    # Now print the configurations for the tags.
238376888252Smrg    for tagname in $taglist; do
238463847c39Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
238576888252Smrg    done
2386d8556812Smrg
238763847c39Smrg    exit $?
238863847c39Smrg}
2389d8556812Smrg
23900814a2baSmrg
239163847c39Smrg# func_features
23920814a2baSmrg# -------------
239363847c39Smrg# Display the features supported by this script.
239463847c39Smrgfunc_features ()
239563847c39Smrg{
239663847c39Smrg    echo "host: $host"
23970814a2baSmrg    if test yes = "$build_libtool_libs"; then
239863847c39Smrg      echo "enable shared libraries"
239976888252Smrg    else
240063847c39Smrg      echo "disable shared libraries"
240176888252Smrg    fi
24020814a2baSmrg    if test yes = "$build_old_libs"; then
240363847c39Smrg      echo "enable static libraries"
240476888252Smrg    else
240563847c39Smrg      echo "disable static libraries"
240676888252Smrg    fi
240776888252Smrg
240863847c39Smrg    exit $?
240963847c39Smrg}
241076888252Smrg
24110814a2baSmrg
24120814a2baSmrg# func_enable_tag TAGNAME
24130814a2baSmrg# -----------------------
241463847c39Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
241563847c39Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
241663847c39Smrg# variable here.
241763847c39Smrgfunc_enable_tag ()
241863847c39Smrg{
24190814a2baSmrg    # Global variable:
24200814a2baSmrg    tagname=$1
242176888252Smrg
24220814a2baSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
24230814a2baSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
24240814a2baSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425d8556812Smrg
24260814a2baSmrg    # Validate tagname.
24270814a2baSmrg    case $tagname in
24280814a2baSmrg      *[!-_A-Za-z0-9,/]*)
24290814a2baSmrg        func_fatal_error "invalid tag name: $tagname"
24300814a2baSmrg        ;;
24310814a2baSmrg    esac
2432d8556812Smrg
24330814a2baSmrg    # Don't test for the "default" C tag, as we know it's
24340814a2baSmrg    # there but not specially marked.
24350814a2baSmrg    case $tagname in
24360814a2baSmrg        CC) ;;
243763847c39Smrg    *)
24380814a2baSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
24390814a2baSmrg	  taglist="$taglist $tagname"
24400814a2baSmrg
24410814a2baSmrg	  # Evaluate the configuration.  Be careful to quote the path
24420814a2baSmrg	  # and the sed script, to avoid splitting on whitespace, but
24430814a2baSmrg	  # also don't use non-portable quotes within backquotes within
24440814a2baSmrg	  # quotes we have to do it in 2 steps:
24450814a2baSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
24460814a2baSmrg	  eval "$extractedcf"
24470814a2baSmrg        else
24480814a2baSmrg	  func_error "ignoring unknown tag $tagname"
24490814a2baSmrg        fi
24500814a2baSmrg        ;;
24510814a2baSmrg    esac
245263847c39Smrg}
2453d8556812Smrg
24540814a2baSmrg
245563847c39Smrg# func_check_version_match
24560814a2baSmrg# ------------------------
245763847c39Smrg# Ensure that we are using m4 macros, and libtool script from the same
245863847c39Smrg# release of libtool.
245963847c39Smrgfunc_check_version_match ()
246063847c39Smrg{
24610814a2baSmrg    if test "$package_revision" != "$macro_revision"; then
24620814a2baSmrg      if test "$VERSION" != "$macro_version"; then
24630814a2baSmrg        if test -z "$macro_version"; then
24640814a2baSmrg          cat >&2 <<_LT_EOF
246563847c39Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
246663847c39Smrg$progname: definition of this LT_INIT comes from an older release.
246763847c39Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
246863847c39Smrg$progname: and run autoconf again.
246963847c39Smrg_LT_EOF
24700814a2baSmrg        else
24710814a2baSmrg          cat >&2 <<_LT_EOF
247263847c39Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
247363847c39Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
247463847c39Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
247563847c39Smrg$progname: and run autoconf again.
247663847c39Smrg_LT_EOF
24770814a2baSmrg        fi
24780814a2baSmrg      else
24790814a2baSmrg        cat >&2 <<_LT_EOF
248063847c39Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
248163847c39Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
248263847c39Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
248363847c39Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
248463847c39Smrg_LT_EOF
24850814a2baSmrg      fi
2486d8556812Smrg
24870814a2baSmrg      exit $EXIT_MISMATCH
24880814a2baSmrg    fi
248963847c39Smrg}
249076888252Smrg
249186dafe34Smrg
24920814a2baSmrg# libtool_options_prep [ARG]...
24930814a2baSmrg# -----------------------------
24940814a2baSmrg# Preparation for options parsed by libtool.
24950814a2baSmrglibtool_options_prep ()
24960814a2baSmrg{
24970814a2baSmrg    $debug_mode
249886dafe34Smrg
24990814a2baSmrg    # Option defaults:
25000814a2baSmrg    opt_config=false
25010814a2baSmrg    opt_dlopen=
25020814a2baSmrg    opt_dry_run=false
25030814a2baSmrg    opt_help=false
25040814a2baSmrg    opt_mode=
25050814a2baSmrg    opt_preserve_dup_deps=false
25060814a2baSmrg    opt_quiet=false
250786dafe34Smrg
25080814a2baSmrg    nonopt=
25090814a2baSmrg    preserve_args=
251086dafe34Smrg
25110814a2baSmrg    _G_rc_lt_options_prep=:
251263847c39Smrg
25130814a2baSmrg    # Shorthand for --mode=foo, only valid as the first argument
25140814a2baSmrg    case $1 in
25150814a2baSmrg    clean|clea|cle|cl)
25160814a2baSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
25170814a2baSmrg      ;;
25180814a2baSmrg    compile|compil|compi|comp|com|co|c)
25190814a2baSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
25200814a2baSmrg      ;;
25210814a2baSmrg    execute|execut|execu|exec|exe|ex|e)
25220814a2baSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
25230814a2baSmrg      ;;
25240814a2baSmrg    finish|finis|fini|fin|fi|f)
25250814a2baSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
25260814a2baSmrg      ;;
25270814a2baSmrg    install|instal|insta|inst|ins|in|i)
25280814a2baSmrg      shift; set dummy --mode install ${1+"$@"}; shift
25290814a2baSmrg      ;;
25300814a2baSmrg    link|lin|li|l)
25310814a2baSmrg      shift; set dummy --mode link ${1+"$@"}; shift
25320814a2baSmrg      ;;
25330814a2baSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
25340814a2baSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
25350814a2baSmrg      ;;
25360814a2baSmrg    *)
25370814a2baSmrg      _G_rc_lt_options_prep=false
25380814a2baSmrg      ;;
2539d8556812Smrg    esac
254076888252Smrg
25410814a2baSmrg    if $_G_rc_lt_options_prep; then
25420814a2baSmrg      # Pass back the list of options.
25430814a2baSmrg      func_quote eval ${1+"$@"}
25440814a2baSmrg      libtool_options_prep_result=$func_quote_result
25450814a2baSmrg    fi
25460814a2baSmrg}
25470814a2baSmrgfunc_add_hook func_options_prep libtool_options_prep
254863847c39Smrg
254976888252Smrg
25500814a2baSmrg# libtool_parse_options [ARG]...
25510814a2baSmrg# ---------------------------------
25520814a2baSmrg# Provide handling for libtool specific options.
25530814a2baSmrglibtool_parse_options ()
25540814a2baSmrg{
25550814a2baSmrg    $debug_cmd
255676888252Smrg
25570814a2baSmrg    _G_rc_lt_parse_options=false
255876888252Smrg
25590814a2baSmrg    # Perform our own loop to consume as many options as possible in
25600814a2baSmrg    # each iteration.
25610814a2baSmrg    while test $# -gt 0; do
25620814a2baSmrg      _G_match_lt_parse_options=:
25630814a2baSmrg      _G_opt=$1
25640814a2baSmrg      shift
25650814a2baSmrg      case $_G_opt in
25660814a2baSmrg        --dry-run|--dryrun|-n)
25670814a2baSmrg                        opt_dry_run=:
25680814a2baSmrg                        ;;
25690814a2baSmrg
25700814a2baSmrg        --config)       func_config ;;
25710814a2baSmrg
25720814a2baSmrg        --dlopen|-dlopen)
25730814a2baSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
25740814a2baSmrg}$1"
25750814a2baSmrg                        shift
25760814a2baSmrg                        ;;
25770814a2baSmrg
25780814a2baSmrg        --preserve-dup-deps)
25790814a2baSmrg                        opt_preserve_dup_deps=: ;;
25800814a2baSmrg
25810814a2baSmrg        --features)     func_features ;;
25820814a2baSmrg
25830814a2baSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
25840814a2baSmrg
25850814a2baSmrg        --help)         opt_help=: ;;
25860814a2baSmrg
25870814a2baSmrg        --help-all)     opt_help=': help-all' ;;
25880814a2baSmrg
25890814a2baSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
25900814a2baSmrg                        opt_mode=$1
25910814a2baSmrg                        case $1 in
25920814a2baSmrg                          # Valid mode arguments:
25930814a2baSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
25940814a2baSmrg
25950814a2baSmrg                          # Catch anything else as an error
25960814a2baSmrg                          *) func_error "invalid argument for $_G_opt"
25970814a2baSmrg                             exit_cmd=exit
25980814a2baSmrg                             break
25990814a2baSmrg                             ;;
26000814a2baSmrg                        esac
26010814a2baSmrg                        shift
26020814a2baSmrg                        ;;
26030814a2baSmrg
26040814a2baSmrg        --no-silent|--no-quiet)
26050814a2baSmrg                        opt_quiet=false
26060814a2baSmrg                        func_append preserve_args " $_G_opt"
26070814a2baSmrg                        ;;
26080814a2baSmrg
26090814a2baSmrg        --no-warnings|--no-warning|--no-warn)
26100814a2baSmrg                        opt_warning=false
26110814a2baSmrg                        func_append preserve_args " $_G_opt"
26120814a2baSmrg                        ;;
26130814a2baSmrg
26140814a2baSmrg        --no-verbose)
26150814a2baSmrg                        opt_verbose=false
26160814a2baSmrg                        func_append preserve_args " $_G_opt"
26170814a2baSmrg                        ;;
26180814a2baSmrg
26190814a2baSmrg        --silent|--quiet)
26200814a2baSmrg                        opt_quiet=:
26210814a2baSmrg                        opt_verbose=false
26220814a2baSmrg                        func_append preserve_args " $_G_opt"
26230814a2baSmrg                        ;;
26240814a2baSmrg
26250814a2baSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
26260814a2baSmrg                        opt_tag=$1
26270814a2baSmrg                        func_append preserve_args " $_G_opt $1"
26280814a2baSmrg                        func_enable_tag "$1"
26290814a2baSmrg                        shift
26300814a2baSmrg                        ;;
26310814a2baSmrg
26320814a2baSmrg        --verbose|-v)   opt_quiet=false
26330814a2baSmrg                        opt_verbose=:
26340814a2baSmrg                        func_append preserve_args " $_G_opt"
26350814a2baSmrg                        ;;
26360814a2baSmrg
26370814a2baSmrg        # An option not handled by this hook function:
26380814a2baSmrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26390814a2baSmrg                        _G_match_lt_parse_options=false
26400814a2baSmrg                        break
26410814a2baSmrg                        ;;
26420814a2baSmrg      esac
26430814a2baSmrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
26440814a2baSmrg    done
264576888252Smrg
26460814a2baSmrg    if $_G_rc_lt_parse_options; then
26470814a2baSmrg      # save modified positional parameters for caller
26480814a2baSmrg      func_quote eval ${1+"$@"}
26490814a2baSmrg      libtool_parse_options_result=$func_quote_result
265063847c39Smrg    fi
26510814a2baSmrg}
26520814a2baSmrgfunc_add_hook func_parse_options libtool_parse_options
26530814a2baSmrg
265486dafe34Smrg
265586dafe34Smrg
26560814a2baSmrg# libtool_validate_options [ARG]...
26570814a2baSmrg# ---------------------------------
26580814a2baSmrg# Perform any sanity checks on option settings and/or unconsumed
26590814a2baSmrg# arguments.
26600814a2baSmrglibtool_validate_options ()
26610814a2baSmrg{
26620814a2baSmrg    # save first non-option argument
26630814a2baSmrg    if test 0 -lt $#; then
26640814a2baSmrg      nonopt=$1
26650814a2baSmrg      shift
266663847c39Smrg    fi
266786dafe34Smrg
26680814a2baSmrg    # preserve --debug
26690814a2baSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26700814a2baSmrg
26710814a2baSmrg    case $host in
26720814a2baSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
26730814a2baSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
26740814a2baSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
26750814a2baSmrg        # don't eliminate duplications in $postdeps and $predeps
26760814a2baSmrg        opt_duplicate_compiler_generated_deps=:
26770814a2baSmrg        ;;
26780814a2baSmrg      *)
26790814a2baSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
26800814a2baSmrg        ;;
26810814a2baSmrg    esac
26820814a2baSmrg
26830814a2baSmrg    $opt_help || {
26840814a2baSmrg      # Sanity checks first:
26850814a2baSmrg      func_check_version_match
26860814a2baSmrg
26870814a2baSmrg      test yes != "$build_libtool_libs" \
26880814a2baSmrg        && test yes != "$build_old_libs" \
26890814a2baSmrg        && func_fatal_configuration "not configured to build any kind of library"
26900814a2baSmrg
26910814a2baSmrg      # Darwin sucks
26920814a2baSmrg      eval std_shrext=\"$shrext_cmds\"
2693d8556812Smrg
26940814a2baSmrg      # Only execute mode is allowed to have -dlopen flags.
26950814a2baSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
26960814a2baSmrg        func_error "unrecognized option '-dlopen'"
26970814a2baSmrg        $ECHO "$help" 1>&2
26980814a2baSmrg        exit $EXIT_FAILURE
26990814a2baSmrg      fi
27000814a2baSmrg
27010814a2baSmrg      # Change the help message to a mode-specific one.
27020814a2baSmrg      generic_help=$help
27030814a2baSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
27040814a2baSmrg    }
270576888252Smrg
27060814a2baSmrg    # Pass back the unparsed argument list
27070814a2baSmrg    func_quote eval ${1+"$@"}
27080814a2baSmrg    libtool_validate_options_result=$func_quote_result
270963847c39Smrg}
27100814a2baSmrgfunc_add_hook func_validate_options libtool_validate_options
27110814a2baSmrg
271276888252Smrg
27130814a2baSmrg# Process options as early as possible so that --help and --version
27140814a2baSmrg# can return quickly.
27150814a2baSmrgfunc_options ${1+"$@"}
27160814a2baSmrgeval set dummy "$func_options_result"; shift
271776888252Smrg
2718d8556812Smrg
2719d8556812Smrg
272063847c39Smrg## ----------- ##
272163847c39Smrg##    Main.    ##
272263847c39Smrg## ----------- ##
272376888252Smrg
27240814a2baSmrgmagic='%%%MAGIC variable%%%'
27250814a2baSmrgmagic_exe='%%%MAGIC EXE variable%%%'
27260814a2baSmrg
27270814a2baSmrg# Global variables.
27280814a2baSmrgextracted_archives=
27290814a2baSmrgextracted_serial=0
27300814a2baSmrg
27310814a2baSmrg# If this variable is set in any of the actions, the command in it
27320814a2baSmrg# will be execed at the end.  This prevents here-documents from being
27330814a2baSmrg# left over by shells.
27340814a2baSmrgexec_cmd=
27350814a2baSmrg
27360814a2baSmrg
27370814a2baSmrg# A function that is used when there is no print builtin or printf.
27380814a2baSmrgfunc_fallback_echo ()
27390814a2baSmrg{
27400814a2baSmrg  eval 'cat <<_LTECHO_EOF
27410814a2baSmrg$1
27420814a2baSmrg_LTECHO_EOF'
27430814a2baSmrg}
27440814a2baSmrg
27450814a2baSmrg# func_generated_by_libtool
27460814a2baSmrg# True iff stdin has been generated by Libtool. This function is only
27470814a2baSmrg# a basic sanity check; it will hardly flush out determined imposters.
27480814a2baSmrgfunc_generated_by_libtool_p ()
27490814a2baSmrg{
27500814a2baSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
27510814a2baSmrg}
27520814a2baSmrg
275363847c39Smrg# func_lalib_p file
27540814a2baSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
275563847c39Smrg# This function is only a basic sanity check; it will hardly flush out
275663847c39Smrg# determined imposters.
275763847c39Smrgfunc_lalib_p ()
275863847c39Smrg{
275963847c39Smrg    test -f "$1" &&
27600814a2baSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
276163847c39Smrg}
276276888252Smrg
276363847c39Smrg# func_lalib_unsafe_p file
27640814a2baSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
276563847c39Smrg# This function implements the same check as func_lalib_p without
276663847c39Smrg# resorting to external programs.  To this end, it redirects stdin and
276763847c39Smrg# closes it afterwards, without saving the original file descriptor.
276863847c39Smrg# As a safety measure, use it only where a negative result would be
27690814a2baSmrg# fatal anyway.  Works if 'file' does not exist.
277063847c39Smrgfunc_lalib_unsafe_p ()
277163847c39Smrg{
277263847c39Smrg    lalib_p=no
277363847c39Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
277463847c39Smrg	for lalib_p_l in 1 2 3 4
277563847c39Smrg	do
277663847c39Smrg	    read lalib_p_line
27770814a2baSmrg	    case $lalib_p_line in
277863847c39Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
277963847c39Smrg	    esac
278063847c39Smrg	done
278163847c39Smrg	exec 0<&5 5<&-
278263847c39Smrg    fi
27830814a2baSmrg    test yes = "$lalib_p"
278463847c39Smrg}
278576888252Smrg
278663847c39Smrg# func_ltwrapper_script_p file
278763847c39Smrg# True iff FILE is a libtool wrapper script
278863847c39Smrg# This function is only a basic sanity check; it will hardly flush out
278963847c39Smrg# determined imposters.
279063847c39Smrgfunc_ltwrapper_script_p ()
279163847c39Smrg{
27920814a2baSmrg    test -f "$1" &&
27930814a2baSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
279463847c39Smrg}
2795d8556812Smrg
279663847c39Smrg# func_ltwrapper_executable_p file
279763847c39Smrg# True iff FILE is a libtool wrapper executable
279863847c39Smrg# This function is only a basic sanity check; it will hardly flush out
279963847c39Smrg# determined imposters.
280063847c39Smrgfunc_ltwrapper_executable_p ()
280163847c39Smrg{
280263847c39Smrg    func_ltwrapper_exec_suffix=
280363847c39Smrg    case $1 in
280463847c39Smrg    *.exe) ;;
280563847c39Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
280676888252Smrg    esac
280763847c39Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
280863847c39Smrg}
280976888252Smrg
281063847c39Smrg# func_ltwrapper_scriptname file
281163847c39Smrg# Assumes file is an ltwrapper_executable
281263847c39Smrg# uses $file to determine the appropriate filename for a
281363847c39Smrg# temporary ltwrapper_script.
281463847c39Smrgfunc_ltwrapper_scriptname ()
281563847c39Smrg{
281663847c39Smrg    func_dirname_and_basename "$1" "" "."
281763847c39Smrg    func_stripname '' '.exe' "$func_basename_result"
28180814a2baSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
281963847c39Smrg}
282076888252Smrg
282163847c39Smrg# func_ltwrapper_p file
282263847c39Smrg# True iff FILE is a libtool wrapper script or wrapper executable
282363847c39Smrg# This function is only a basic sanity check; it will hardly flush out
282463847c39Smrg# determined imposters.
282563847c39Smrgfunc_ltwrapper_p ()
282663847c39Smrg{
282763847c39Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
282863847c39Smrg}
282976888252Smrg
283076888252Smrg
283163847c39Smrg# func_execute_cmds commands fail_cmd
283263847c39Smrg# Execute tilde-delimited COMMANDS.
283363847c39Smrg# If FAIL_CMD is given, eval that upon failure.
283463847c39Smrg# FAIL_CMD may read-access the current command in variable CMD!
283563847c39Smrgfunc_execute_cmds ()
283663847c39Smrg{
28370814a2baSmrg    $debug_cmd
28380814a2baSmrg
283963847c39Smrg    save_ifs=$IFS; IFS='~'
284063847c39Smrg    for cmd in $1; do
28410814a2baSmrg      IFS=$sp$nl
284263847c39Smrg      eval cmd=\"$cmd\"
28430814a2baSmrg      IFS=$save_ifs
284463847c39Smrg      func_show_eval "$cmd" "${2-:}"
284576888252Smrg    done
284663847c39Smrg    IFS=$save_ifs
284763847c39Smrg}
284876888252Smrg
284976888252Smrg
285063847c39Smrg# func_source file
285163847c39Smrg# Source FILE, adding directory component if necessary.
285263847c39Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
285363847c39Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
285463847c39Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
28550814a2baSmrg# 'FILE.' does not work on cygwin managed mounts.
285663847c39Smrgfunc_source ()
285763847c39Smrg{
28580814a2baSmrg    $debug_cmd
28590814a2baSmrg
286063847c39Smrg    case $1 in
286163847c39Smrg    */* | *\\*)	. "$1" ;;
286263847c39Smrg    *)		. "./$1" ;;
286363847c39Smrg    esac
286463847c39Smrg}
286576888252Smrg
286676888252Smrg
286763847c39Smrg# func_resolve_sysroot PATH
286863847c39Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
286963847c39Smrg# func_resolve_sysroot_result
287063847c39Smrgfunc_resolve_sysroot ()
287163847c39Smrg{
287263847c39Smrg  func_resolve_sysroot_result=$1
287363847c39Smrg  case $func_resolve_sysroot_result in
287463847c39Smrg  =*)
287563847c39Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
287663847c39Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
287763847c39Smrg    ;;
287863847c39Smrg  esac
287963847c39Smrg}
2880d8556812Smrg
288163847c39Smrg# func_replace_sysroot PATH
288263847c39Smrg# If PATH begins with the sysroot, replace it with = and
288363847c39Smrg# store the result into func_replace_sysroot_result.
288463847c39Smrgfunc_replace_sysroot ()
288563847c39Smrg{
28860814a2baSmrg  case $lt_sysroot:$1 in
288763847c39Smrg  ?*:"$lt_sysroot"*)
288863847c39Smrg    func_stripname "$lt_sysroot" '' "$1"
28890814a2baSmrg    func_replace_sysroot_result='='$func_stripname_result
289063847c39Smrg    ;;
289163847c39Smrg  *)
289263847c39Smrg    # Including no sysroot.
289363847c39Smrg    func_replace_sysroot_result=$1
289463847c39Smrg    ;;
289563847c39Smrg  esac
289663847c39Smrg}
289776888252Smrg
289863847c39Smrg# func_infer_tag arg
289963847c39Smrg# Infer tagged configuration to use if any are available and
290063847c39Smrg# if one wasn't chosen via the "--tag" command line option.
290163847c39Smrg# Only attempt this if the compiler in the base compile
290263847c39Smrg# command doesn't match the default compiler.
290363847c39Smrg# arg is usually of the form 'gcc ...'
290463847c39Smrgfunc_infer_tag ()
290563847c39Smrg{
29060814a2baSmrg    $debug_cmd
29070814a2baSmrg
290863847c39Smrg    if test -n "$available_tags" && test -z "$tagname"; then
290963847c39Smrg      CC_quoted=
291063847c39Smrg      for arg in $CC; do
291163847c39Smrg	func_append_quoted CC_quoted "$arg"
291263847c39Smrg      done
291363847c39Smrg      CC_expanded=`func_echo_all $CC`
291463847c39Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
291563847c39Smrg      case $@ in
291663847c39Smrg      # Blanks in the command may have been stripped by the calling shell,
291763847c39Smrg      # but not from the CC environment variable when configure was run.
291863847c39Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291963847c39Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
292063847c39Smrg      # Blanks at the start of $base_compile will cause this to fail
292163847c39Smrg      # if we don't check for them as well.
292263847c39Smrg      *)
292363847c39Smrg	for z in $available_tags; do
292463847c39Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
292563847c39Smrg	    # Evaluate the configuration.
29260814a2baSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
292763847c39Smrg	    CC_quoted=
292863847c39Smrg	    for arg in $CC; do
292963847c39Smrg	      # Double-quote args containing other shell metacharacters.
293063847c39Smrg	      func_append_quoted CC_quoted "$arg"
293163847c39Smrg	    done
293263847c39Smrg	    CC_expanded=`func_echo_all $CC`
293363847c39Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
293463847c39Smrg	    case "$@ " in
293563847c39Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
293663847c39Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
293763847c39Smrg	      # The compiler in the base compile command matches
293863847c39Smrg	      # the one in the tagged configuration.
293963847c39Smrg	      # Assume this is the tagged configuration we want.
294063847c39Smrg	      tagname=$z
294163847c39Smrg	      break
294263847c39Smrg	      ;;
294363847c39Smrg	    esac
294463847c39Smrg	  fi
294563847c39Smrg	done
294663847c39Smrg	# If $tagname still isn't set, then no tagged configuration
294763847c39Smrg	# was found and let the user know that the "--tag" command
294863847c39Smrg	# line option must be used.
294963847c39Smrg	if test -z "$tagname"; then
295063847c39Smrg	  func_echo "unable to infer tagged configuration"
29510814a2baSmrg	  func_fatal_error "specify a tag with '--tag'"
295263847c39Smrg#	else
295363847c39Smrg#	  func_verbose "using $tagname tagged configuration"
295463847c39Smrg	fi
295563847c39Smrg	;;
295663847c39Smrg      esac
295776888252Smrg    fi
295863847c39Smrg}
295976888252Smrg
296076888252Smrg
296176888252Smrg
296263847c39Smrg# func_write_libtool_object output_name pic_name nonpic_name
296363847c39Smrg# Create a libtool object file (analogous to a ".la" file),
296463847c39Smrg# but don't create it if we're doing a dry run.
296563847c39Smrgfunc_write_libtool_object ()
296663847c39Smrg{
29670814a2baSmrg    write_libobj=$1
29680814a2baSmrg    if test yes = "$build_libtool_libs"; then
29690814a2baSmrg      write_lobj=\'$2\'
297063847c39Smrg    else
297163847c39Smrg      write_lobj=none
297276888252Smrg    fi
297376888252Smrg
29740814a2baSmrg    if test yes = "$build_old_libs"; then
29750814a2baSmrg      write_oldobj=\'$3\'
297663847c39Smrg    else
297763847c39Smrg      write_oldobj=none
297876888252Smrg    fi
2979d8556812Smrg
298063847c39Smrg    $opt_dry_run || {
298163847c39Smrg      cat >${write_libobj}T <<EOF
298263847c39Smrg# $write_libobj - a libtool object file
29830814a2baSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984d8556812Smrg#
2985d8556812Smrg# Please DO NOT delete this file!
2986d8556812Smrg# It is necessary for linking the library.
2987d8556812Smrg
2988d8556812Smrg# Name of the PIC object.
298963847c39Smrgpic_object=$write_lobj
299076888252Smrg
299163847c39Smrg# Name of the non-PIC object
299263847c39Smrgnon_pic_object=$write_oldobj
299376888252Smrg
299463847c39SmrgEOF
29950814a2baSmrg      $MV "${write_libobj}T" "$write_libobj"
299663847c39Smrg    }
299763847c39Smrg}
299876888252Smrg
299976888252Smrg
300063847c39Smrg##################################################
300163847c39Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
300263847c39Smrg##################################################
300376888252Smrg
300463847c39Smrg# func_convert_core_file_wine_to_w32 ARG
300563847c39Smrg# Helper function used by file name conversion functions when $build is *nix,
300663847c39Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
300763847c39Smrg# correctly configured wine environment available, with the winepath program
300863847c39Smrg# in $build's $PATH.
300963847c39Smrg#
301063847c39Smrg# ARG is the $build file name to be converted to w32 format.
301163847c39Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
301263847c39Smrg# be empty on error (or when ARG is empty)
301363847c39Smrgfunc_convert_core_file_wine_to_w32 ()
301463847c39Smrg{
30150814a2baSmrg  $debug_cmd
30160814a2baSmrg
30170814a2baSmrg  func_convert_core_file_wine_to_w32_result=$1
301863847c39Smrg  if test -n "$1"; then
301963847c39Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
302063847c39Smrg    # are forced to check the contents of stdout. On the other hand, if the
302163847c39Smrg    # command is not found, the shell will set an exit code of 127 and print
302263847c39Smrg    # *an error message* to stdout. So we must check for both error code of
302363847c39Smrg    # zero AND non-empty stdout, which explains the odd construction:
302463847c39Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
30250814a2baSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
302663847c39Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
30270814a2baSmrg        $SED -e "$sed_naive_backslashify"`
302863847c39Smrg    else
302963847c39Smrg      func_convert_core_file_wine_to_w32_result=
303063847c39Smrg    fi
303163847c39Smrg  fi
303263847c39Smrg}
303363847c39Smrg# end: func_convert_core_file_wine_to_w32
3034d8556812Smrg
303563847c39Smrg
303663847c39Smrg# func_convert_core_path_wine_to_w32 ARG
303763847c39Smrg# Helper function used by path conversion functions when $build is *nix, and
303863847c39Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
303963847c39Smrg# configured wine environment available, with the winepath program in $build's
304063847c39Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
304163847c39Smrg#
304263847c39Smrg# ARG is path to be converted from $build format to win32.
304363847c39Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
304463847c39Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
304563847c39Smrg# are convertible, then the result may be empty.
304663847c39Smrgfunc_convert_core_path_wine_to_w32 ()
304763847c39Smrg{
30480814a2baSmrg  $debug_cmd
30490814a2baSmrg
305063847c39Smrg  # unfortunately, winepath doesn't convert paths, only file names
30510814a2baSmrg  func_convert_core_path_wine_to_w32_result=
305263847c39Smrg  if test -n "$1"; then
305363847c39Smrg    oldIFS=$IFS
305463847c39Smrg    IFS=:
305563847c39Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
305663847c39Smrg      IFS=$oldIFS
305763847c39Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
30580814a2baSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
305963847c39Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
30600814a2baSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
306163847c39Smrg        else
306263847c39Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
306363847c39Smrg        fi
3064d8556812Smrg      fi
306563847c39Smrg    done
306663847c39Smrg    IFS=$oldIFS
306763847c39Smrg  fi
306863847c39Smrg}
306963847c39Smrg# end: func_convert_core_path_wine_to_w32
307063847c39Smrg
307163847c39Smrg
307263847c39Smrg# func_cygpath ARGS...
307363847c39Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
307463847c39Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
307563847c39Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
307663847c39Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
307763847c39Smrg# file name or path is assumed to be in w32 format, as previously converted
307863847c39Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
307963847c39Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
308063847c39Smrg# Cygwin format). Returns an empty string on error.
308163847c39Smrg#
308263847c39Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
308363847c39Smrg# be converted.
308463847c39Smrg#
308563847c39Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
308663847c39Smrg# environment variable; do not put it in $PATH.
308763847c39Smrgfunc_cygpath ()
308863847c39Smrg{
30890814a2baSmrg  $debug_cmd
30900814a2baSmrg
309163847c39Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
309263847c39Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
309363847c39Smrg    if test "$?" -ne 0; then
309463847c39Smrg      # on failure, ensure result is empty
309563847c39Smrg      func_cygpath_result=
309663847c39Smrg    fi
309763847c39Smrg  else
309863847c39Smrg    func_cygpath_result=
30990814a2baSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
310063847c39Smrg  fi
310163847c39Smrg}
310263847c39Smrg#end: func_cygpath
310376888252Smrg
310476888252Smrg
310563847c39Smrg# func_convert_core_msys_to_w32 ARG
310663847c39Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
310763847c39Smrg# result in func_convert_core_msys_to_w32_result.
310863847c39Smrgfunc_convert_core_msys_to_w32 ()
310963847c39Smrg{
31100814a2baSmrg  $debug_cmd
31110814a2baSmrg
311263847c39Smrg  # awkward: cmd appends spaces to result
311363847c39Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
31140814a2baSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
311563847c39Smrg}
311663847c39Smrg#end: func_convert_core_msys_to_w32
311776888252Smrg
311876888252Smrg
311963847c39Smrg# func_convert_file_check ARG1 ARG2
312063847c39Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
312163847c39Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
312263847c39Smrg# func_to_host_file_result to ARG1).
312363847c39Smrgfunc_convert_file_check ()
312463847c39Smrg{
31250814a2baSmrg  $debug_cmd
31260814a2baSmrg
31270814a2baSmrg  if test -z "$2" && test -n "$1"; then
312863847c39Smrg    func_error "Could not determine host file name corresponding to"
31290814a2baSmrg    func_error "  '$1'"
313063847c39Smrg    func_error "Continuing, but uninstalled executables may not work."
313163847c39Smrg    # Fallback:
31320814a2baSmrg    func_to_host_file_result=$1
313363847c39Smrg  fi
313463847c39Smrg}
313563847c39Smrg# end func_convert_file_check
313676888252Smrg
313776888252Smrg
313863847c39Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
313963847c39Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
314063847c39Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
314163847c39Smrg# func_to_host_file_result to a simplistic fallback value (see below).
314263847c39Smrgfunc_convert_path_check ()
314363847c39Smrg{
31440814a2baSmrg  $debug_cmd
31450814a2baSmrg
314663847c39Smrg  if test -z "$4" && test -n "$3"; then
314763847c39Smrg    func_error "Could not determine the host path corresponding to"
31480814a2baSmrg    func_error "  '$3'"
314963847c39Smrg    func_error "Continuing, but uninstalled executables may not work."
315063847c39Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
315163847c39Smrg    # should not be "improved".  See libtool.info.
315263847c39Smrg    if test "x$1" != "x$2"; then
315363847c39Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
315463847c39Smrg      func_to_host_path_result=`echo "$3" |
315563847c39Smrg        $SED -e "$lt_replace_pathsep_chars"`
315663847c39Smrg    else
31570814a2baSmrg      func_to_host_path_result=$3
315863847c39Smrg    fi
315963847c39Smrg  fi
316063847c39Smrg}
316163847c39Smrg# end func_convert_path_check
3162d8556812Smrg
3163d8556812Smrg
316463847c39Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
316563847c39Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
316663847c39Smrg# and appending REPL if ORIG matches BACKPAT.
316763847c39Smrgfunc_convert_path_front_back_pathsep ()
316863847c39Smrg{
31690814a2baSmrg  $debug_cmd
31700814a2baSmrg
317163847c39Smrg  case $4 in
31720814a2baSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
317363847c39Smrg    ;;
317463847c39Smrg  esac
317563847c39Smrg  case $4 in
317663847c39Smrg  $2 ) func_append func_to_host_path_result "$3"
317763847c39Smrg    ;;
317863847c39Smrg  esac
317963847c39Smrg}
318063847c39Smrg# end func_convert_path_front_back_pathsep
3181d8556812Smrg
318276888252Smrg
318363847c39Smrg##################################################
318463847c39Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
318563847c39Smrg##################################################
31860814a2baSmrg# invoked via '$to_host_file_cmd ARG'
318763847c39Smrg#
318863847c39Smrg# In each case, ARG is the path to be converted from $build to $host format.
318963847c39Smrg# Result will be available in $func_to_host_file_result.
319076888252Smrg
319176888252Smrg
319263847c39Smrg# func_to_host_file ARG
319363847c39Smrg# Converts the file name ARG from $build format to $host format. Return result
319463847c39Smrg# in func_to_host_file_result.
319563847c39Smrgfunc_to_host_file ()
319663847c39Smrg{
31970814a2baSmrg  $debug_cmd
31980814a2baSmrg
319963847c39Smrg  $to_host_file_cmd "$1"
320063847c39Smrg}
320163847c39Smrg# end func_to_host_file
320276888252Smrg
320376888252Smrg
320463847c39Smrg# func_to_tool_file ARG LAZY
320563847c39Smrg# converts the file name ARG from $build format to toolchain format. Return
320663847c39Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
320763847c39Smrg# in (the comma separated) LAZY, no conversion takes place.
320863847c39Smrgfunc_to_tool_file ()
320963847c39Smrg{
32100814a2baSmrg  $debug_cmd
32110814a2baSmrg
321263847c39Smrg  case ,$2, in
321363847c39Smrg    *,"$to_tool_file_cmd",*)
321463847c39Smrg      func_to_tool_file_result=$1
321563847c39Smrg      ;;
321663847c39Smrg    *)
321763847c39Smrg      $to_tool_file_cmd "$1"
321863847c39Smrg      func_to_tool_file_result=$func_to_host_file_result
321963847c39Smrg      ;;
322063847c39Smrg  esac
322163847c39Smrg}
322263847c39Smrg# end func_to_tool_file
322376888252Smrg
322476888252Smrg
322563847c39Smrg# func_convert_file_noop ARG
322663847c39Smrg# Copy ARG to func_to_host_file_result.
322763847c39Smrgfunc_convert_file_noop ()
322863847c39Smrg{
32290814a2baSmrg  func_to_host_file_result=$1
323063847c39Smrg}
323163847c39Smrg# end func_convert_file_noop
3232d8556812Smrg
3233d8556812Smrg
323463847c39Smrg# func_convert_file_msys_to_w32 ARG
323563847c39Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
323663847c39Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
323763847c39Smrg# func_to_host_file_result.
323863847c39Smrgfunc_convert_file_msys_to_w32 ()
323963847c39Smrg{
32400814a2baSmrg  $debug_cmd
32410814a2baSmrg
32420814a2baSmrg  func_to_host_file_result=$1
324363847c39Smrg  if test -n "$1"; then
324463847c39Smrg    func_convert_core_msys_to_w32 "$1"
32450814a2baSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
324663847c39Smrg  fi
324763847c39Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
324863847c39Smrg}
324963847c39Smrg# end func_convert_file_msys_to_w32
3250d8556812Smrg
325176888252Smrg
325263847c39Smrg# func_convert_file_cygwin_to_w32 ARG
325363847c39Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
325463847c39Smrg# func_to_host_file_result.
325563847c39Smrgfunc_convert_file_cygwin_to_w32 ()
325663847c39Smrg{
32570814a2baSmrg  $debug_cmd
32580814a2baSmrg
32590814a2baSmrg  func_to_host_file_result=$1
326063847c39Smrg  if test -n "$1"; then
326163847c39Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
326263847c39Smrg    # LT_CYGPATH in this case.
326363847c39Smrg    func_to_host_file_result=`cygpath -m "$1"`
326463847c39Smrg  fi
326563847c39Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
326663847c39Smrg}
326763847c39Smrg# end func_convert_file_cygwin_to_w32
326876888252Smrg
326976888252Smrg
327063847c39Smrg# func_convert_file_nix_to_w32 ARG
327163847c39Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
327263847c39Smrg# and a working winepath. Returns result in func_to_host_file_result.
327363847c39Smrgfunc_convert_file_nix_to_w32 ()
327463847c39Smrg{
32750814a2baSmrg  $debug_cmd
32760814a2baSmrg
32770814a2baSmrg  func_to_host_file_result=$1
327863847c39Smrg  if test -n "$1"; then
327963847c39Smrg    func_convert_core_file_wine_to_w32 "$1"
32800814a2baSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
328163847c39Smrg  fi
328263847c39Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
328363847c39Smrg}
328463847c39Smrg# end func_convert_file_nix_to_w32
328576888252Smrg
328676888252Smrg
328763847c39Smrg# func_convert_file_msys_to_cygwin ARG
328863847c39Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
328963847c39Smrg# Returns result in func_to_host_file_result.
329063847c39Smrgfunc_convert_file_msys_to_cygwin ()
329163847c39Smrg{
32920814a2baSmrg  $debug_cmd
32930814a2baSmrg
32940814a2baSmrg  func_to_host_file_result=$1
329563847c39Smrg  if test -n "$1"; then
329663847c39Smrg    func_convert_core_msys_to_w32 "$1"
329763847c39Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
32980814a2baSmrg    func_to_host_file_result=$func_cygpath_result
329963847c39Smrg  fi
330063847c39Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
330163847c39Smrg}
330263847c39Smrg# end func_convert_file_msys_to_cygwin
330376888252Smrg
330476888252Smrg
330563847c39Smrg# func_convert_file_nix_to_cygwin ARG
330663847c39Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
330763847c39Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
330863847c39Smrg# in func_to_host_file_result.
330963847c39Smrgfunc_convert_file_nix_to_cygwin ()
331063847c39Smrg{
33110814a2baSmrg  $debug_cmd
33120814a2baSmrg
33130814a2baSmrg  func_to_host_file_result=$1
331463847c39Smrg  if test -n "$1"; then
331563847c39Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
331663847c39Smrg    func_convert_core_file_wine_to_w32 "$1"
331763847c39Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
33180814a2baSmrg    func_to_host_file_result=$func_cygpath_result
331963847c39Smrg  fi
332063847c39Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
332163847c39Smrg}
332263847c39Smrg# end func_convert_file_nix_to_cygwin
332376888252Smrg
332476888252Smrg
332563847c39Smrg#############################################
332663847c39Smrg# $build to $host PATH CONVERSION FUNCTIONS #
332763847c39Smrg#############################################
33280814a2baSmrg# invoked via '$to_host_path_cmd ARG'
332963847c39Smrg#
333063847c39Smrg# In each case, ARG is the path to be converted from $build to $host format.
333163847c39Smrg# The result will be available in $func_to_host_path_result.
333263847c39Smrg#
333363847c39Smrg# Path separators are also converted from $build format to $host format.  If
333463847c39Smrg# ARG begins or ends with a path separator character, it is preserved (but
333563847c39Smrg# converted to $host format) on output.
333663847c39Smrg#
333763847c39Smrg# All path conversion functions are named using the following convention:
333863847c39Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
333963847c39Smrg#   path conversion function         : func_convert_path_X_to_Y ()
334063847c39Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
334163847c39Smrg# same.  If conversion functions are added for new $build/$host combinations,
334263847c39Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
334363847c39Smrg# will break.
334463847c39Smrg
334563847c39Smrg
334663847c39Smrg# func_init_to_host_path_cmd
334763847c39Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
334863847c39Smrg# appropriate value, based on the value of $to_host_file_cmd.
334963847c39Smrgto_host_path_cmd=
335063847c39Smrgfunc_init_to_host_path_cmd ()
335163847c39Smrg{
33520814a2baSmrg  $debug_cmd
33530814a2baSmrg
335463847c39Smrg  if test -z "$to_host_path_cmd"; then
335563847c39Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
33560814a2baSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
335763847c39Smrg  fi
335863847c39Smrg}
335976888252Smrg
336076888252Smrg
336163847c39Smrg# func_to_host_path ARG
336263847c39Smrg# Converts the path ARG from $build format to $host format. Return result
336363847c39Smrg# in func_to_host_path_result.
336463847c39Smrgfunc_to_host_path ()
336563847c39Smrg{
33660814a2baSmrg  $debug_cmd
33670814a2baSmrg
336863847c39Smrg  func_init_to_host_path_cmd
336963847c39Smrg  $to_host_path_cmd "$1"
337063847c39Smrg}
337163847c39Smrg# end func_to_host_path
337276888252Smrg
337376888252Smrg
337463847c39Smrg# func_convert_path_noop ARG
337563847c39Smrg# Copy ARG to func_to_host_path_result.
337663847c39Smrgfunc_convert_path_noop ()
337763847c39Smrg{
33780814a2baSmrg  func_to_host_path_result=$1
337963847c39Smrg}
338063847c39Smrg# end func_convert_path_noop
338176888252Smrg
338276888252Smrg
338363847c39Smrg# func_convert_path_msys_to_w32 ARG
338463847c39Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
338563847c39Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
338663847c39Smrg# func_to_host_path_result.
338763847c39Smrgfunc_convert_path_msys_to_w32 ()
338863847c39Smrg{
33890814a2baSmrg  $debug_cmd
33900814a2baSmrg
33910814a2baSmrg  func_to_host_path_result=$1
339263847c39Smrg  if test -n "$1"; then
339363847c39Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
339463847c39Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
339563847c39Smrg    # and winepath ignores them completely.
339663847c39Smrg    func_stripname : : "$1"
339763847c39Smrg    func_to_host_path_tmp1=$func_stripname_result
339863847c39Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
33990814a2baSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
340063847c39Smrg    func_convert_path_check : ";" \
340163847c39Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
340263847c39Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
340363847c39Smrg  fi
340463847c39Smrg}
340563847c39Smrg# end func_convert_path_msys_to_w32
340676888252Smrg
340776888252Smrg
340863847c39Smrg# func_convert_path_cygwin_to_w32 ARG
340963847c39Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
341063847c39Smrg# func_to_host_file_result.
341163847c39Smrgfunc_convert_path_cygwin_to_w32 ()
341263847c39Smrg{
34130814a2baSmrg  $debug_cmd
34140814a2baSmrg
34150814a2baSmrg  func_to_host_path_result=$1
341663847c39Smrg  if test -n "$1"; then
341763847c39Smrg    # See func_convert_path_msys_to_w32:
341863847c39Smrg    func_stripname : : "$1"
341963847c39Smrg    func_to_host_path_tmp1=$func_stripname_result
342063847c39Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
342163847c39Smrg    func_convert_path_check : ";" \
342263847c39Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
342363847c39Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
342463847c39Smrg  fi
342563847c39Smrg}
342663847c39Smrg# end func_convert_path_cygwin_to_w32
342776888252Smrg
342876888252Smrg
342963847c39Smrg# func_convert_path_nix_to_w32 ARG
343063847c39Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
343163847c39Smrg# a working winepath.  Returns result in func_to_host_file_result.
343263847c39Smrgfunc_convert_path_nix_to_w32 ()
343363847c39Smrg{
34340814a2baSmrg  $debug_cmd
34350814a2baSmrg
34360814a2baSmrg  func_to_host_path_result=$1
343763847c39Smrg  if test -n "$1"; then
343863847c39Smrg    # See func_convert_path_msys_to_w32:
343963847c39Smrg    func_stripname : : "$1"
344063847c39Smrg    func_to_host_path_tmp1=$func_stripname_result
344163847c39Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34420814a2baSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
344363847c39Smrg    func_convert_path_check : ";" \
344463847c39Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
344563847c39Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
344663847c39Smrg  fi
344763847c39Smrg}
344863847c39Smrg# end func_convert_path_nix_to_w32
344976888252Smrg
345076888252Smrg
345163847c39Smrg# func_convert_path_msys_to_cygwin ARG
345263847c39Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
345363847c39Smrg# Returns result in func_to_host_file_result.
345463847c39Smrgfunc_convert_path_msys_to_cygwin ()
345563847c39Smrg{
34560814a2baSmrg  $debug_cmd
34570814a2baSmrg
34580814a2baSmrg  func_to_host_path_result=$1
345963847c39Smrg  if test -n "$1"; then
346063847c39Smrg    # See func_convert_path_msys_to_w32:
346163847c39Smrg    func_stripname : : "$1"
346263847c39Smrg    func_to_host_path_tmp1=$func_stripname_result
346363847c39Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
346463847c39Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
34650814a2baSmrg    func_to_host_path_result=$func_cygpath_result
346663847c39Smrg    func_convert_path_check : : \
346763847c39Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
346863847c39Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
346963847c39Smrg  fi
347063847c39Smrg}
347163847c39Smrg# end func_convert_path_msys_to_cygwin
347276888252Smrg
347376888252Smrg
347463847c39Smrg# func_convert_path_nix_to_cygwin ARG
347563847c39Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
347663847c39Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
347763847c39Smrg# func_to_host_file_result.
347863847c39Smrgfunc_convert_path_nix_to_cygwin ()
347963847c39Smrg{
34800814a2baSmrg  $debug_cmd
34810814a2baSmrg
34820814a2baSmrg  func_to_host_path_result=$1
348363847c39Smrg  if test -n "$1"; then
348463847c39Smrg    # Remove leading and trailing path separator characters from
348563847c39Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
348663847c39Smrg    # into '.;' and ';.', and winepath ignores them completely.
348763847c39Smrg    func_stripname : : "$1"
348863847c39Smrg    func_to_host_path_tmp1=$func_stripname_result
348963847c39Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
349063847c39Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
34910814a2baSmrg    func_to_host_path_result=$func_cygpath_result
349263847c39Smrg    func_convert_path_check : : \
349363847c39Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
349463847c39Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
349563847c39Smrg  fi
349663847c39Smrg}
349763847c39Smrg# end func_convert_path_nix_to_cygwin
349876888252Smrg
349976888252Smrg
35000814a2baSmrg# func_dll_def_p FILE
35010814a2baSmrg# True iff FILE is a Windows DLL '.def' file.
35020814a2baSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
35030814a2baSmrgfunc_dll_def_p ()
35040814a2baSmrg{
35050814a2baSmrg  $debug_cmd
35060814a2baSmrg
35070814a2baSmrg  func_dll_def_p_tmp=`$SED -n \
35080814a2baSmrg    -e 's/^[	 ]*//' \
35090814a2baSmrg    -e '/^\(;.*\)*$/d' \
35100814a2baSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
35110814a2baSmrg    -e q \
35120814a2baSmrg    "$1"`
35130814a2baSmrg  test DEF = "$func_dll_def_p_tmp"
35140814a2baSmrg}
35150814a2baSmrg
35160814a2baSmrg
351763847c39Smrg# func_mode_compile arg...
351863847c39Smrgfunc_mode_compile ()
351963847c39Smrg{
35200814a2baSmrg    $debug_cmd
35210814a2baSmrg
352263847c39Smrg    # Get the compilation command and the source file.
352363847c39Smrg    base_compile=
35240814a2baSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
352563847c39Smrg    suppress_opt=yes
352663847c39Smrg    suppress_output=
352763847c39Smrg    arg_mode=normal
352863847c39Smrg    libobj=
352963847c39Smrg    later=
353063847c39Smrg    pie_flag=
353163847c39Smrg
353263847c39Smrg    for arg
353363847c39Smrg    do
353463847c39Smrg      case $arg_mode in
353563847c39Smrg      arg  )
353663847c39Smrg	# do not "continue".  Instead, add this to base_compile
35370814a2baSmrg	lastarg=$arg
353863847c39Smrg	arg_mode=normal
353963847c39Smrg	;;
354063847c39Smrg
354163847c39Smrg      target )
35420814a2baSmrg	libobj=$arg
354363847c39Smrg	arg_mode=normal
354463847c39Smrg	continue
354563847c39Smrg	;;
354663847c39Smrg
354763847c39Smrg      normal )
354863847c39Smrg	# Accept any command-line options.
354963847c39Smrg	case $arg in
355063847c39Smrg	-o)
355163847c39Smrg	  test -n "$libobj" && \
35520814a2baSmrg	    func_fatal_error "you cannot specify '-o' more than once"
355363847c39Smrg	  arg_mode=target
3554d8556812Smrg	  continue
3555d8556812Smrg	  ;;
355663847c39Smrg
355763847c39Smrg	-pie | -fpie | -fPIE)
355863847c39Smrg          func_append pie_flag " $arg"
3559d8556812Smrg	  continue
3560d8556812Smrg	  ;;
356163847c39Smrg
356263847c39Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
356363847c39Smrg	  func_append later " $arg"
3564d8556812Smrg	  continue
3565d8556812Smrg	  ;;
356663847c39Smrg
356763847c39Smrg	-no-suppress)
356863847c39Smrg	  suppress_opt=no
3569d8556812Smrg	  continue
3570d8556812Smrg	  ;;
357176888252Smrg
357263847c39Smrg	-Xcompiler)
357363847c39Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
357463847c39Smrg	  continue      #  The current "srcfile" will either be retained or
357563847c39Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
357676888252Smrg
357763847c39Smrg	-Wc,*)
357863847c39Smrg	  func_stripname '-Wc,' '' "$arg"
357963847c39Smrg	  args=$func_stripname_result
358063847c39Smrg	  lastarg=
35810814a2baSmrg	  save_ifs=$IFS; IFS=,
358263847c39Smrg	  for arg in $args; do
35830814a2baSmrg	    IFS=$save_ifs
358463847c39Smrg	    func_append_quoted lastarg "$arg"
358563847c39Smrg	  done
35860814a2baSmrg	  IFS=$save_ifs
358763847c39Smrg	  func_stripname ' ' '' "$lastarg"
358863847c39Smrg	  lastarg=$func_stripname_result
358976888252Smrg
359063847c39Smrg	  # Add the arguments to base_compile.
359163847c39Smrg	  func_append base_compile " $lastarg"
359263847c39Smrg	  continue
359363847c39Smrg	  ;;
359476888252Smrg
359563847c39Smrg	*)
359663847c39Smrg	  # Accept the current argument as the source file.
359763847c39Smrg	  # The previous "srcfile" becomes the current argument.
359863847c39Smrg	  #
35990814a2baSmrg	  lastarg=$srcfile
36000814a2baSmrg	  srcfile=$arg
360163847c39Smrg	  ;;
360263847c39Smrg	esac  #  case $arg
3603d8556812Smrg	;;
360463847c39Smrg      esac    #  case $arg_mode
360576888252Smrg
360663847c39Smrg      # Aesthetically quote the previous argument.
360763847c39Smrg      func_append_quoted base_compile "$lastarg"
360863847c39Smrg    done # for arg
360976888252Smrg
361063847c39Smrg    case $arg_mode in
361163847c39Smrg    arg)
361263847c39Smrg      func_fatal_error "you must specify an argument for -Xcompile"
361363847c39Smrg      ;;
361463847c39Smrg    target)
36150814a2baSmrg      func_fatal_error "you must specify a target with '-o'"
361663847c39Smrg      ;;
361763847c39Smrg    *)
361863847c39Smrg      # Get the name of the library object.
361963847c39Smrg      test -z "$libobj" && {
362063847c39Smrg	func_basename "$srcfile"
36210814a2baSmrg	libobj=$func_basename_result
362263847c39Smrg      }
362363847c39Smrg      ;;
362463847c39Smrg    esac
362576888252Smrg
362663847c39Smrg    # Recognize several different file suffixes.
362763847c39Smrg    # If the user specifies -o file.o, it is replaced with file.lo
362863847c39Smrg    case $libobj in
362963847c39Smrg    *.[cCFSifmso] | \
363063847c39Smrg    *.ada | *.adb | *.ads | *.asm | \
363163847c39Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
363263847c39Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
363363847c39Smrg      func_xform "$libobj"
363463847c39Smrg      libobj=$func_xform_result
363563847c39Smrg      ;;
363663847c39Smrg    esac
363776888252Smrg
363863847c39Smrg    case $libobj in
363963847c39Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
364063847c39Smrg    *)
36410814a2baSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
364263847c39Smrg      ;;
364363847c39Smrg    esac
364476888252Smrg
364563847c39Smrg    func_infer_tag $base_compile
364676888252Smrg
364763847c39Smrg    for arg in $later; do
364863847c39Smrg      case $arg in
364963847c39Smrg      -shared)
36500814a2baSmrg	test yes = "$build_libtool_libs" \
36510814a2baSmrg	  || func_fatal_configuration "cannot build a shared library"
365263847c39Smrg	build_old_libs=no
3653d8556812Smrg	continue
3654d8556812Smrg	;;
365576888252Smrg
365663847c39Smrg      -static)
365763847c39Smrg	build_libtool_libs=no
365863847c39Smrg	build_old_libs=yes
3659d8556812Smrg	continue
3660d8556812Smrg	;;
366176888252Smrg
366263847c39Smrg      -prefer-pic)
366363847c39Smrg	pic_mode=yes
3664d8556812Smrg	continue
3665d8556812Smrg	;;
366676888252Smrg
366763847c39Smrg      -prefer-non-pic)
366863847c39Smrg	pic_mode=no
3669d8556812Smrg	continue
367076888252Smrg	;;
367163847c39Smrg      esac
367263847c39Smrg    done
367376888252Smrg
36740814a2baSmrg    func_quote_arg pretty "$libobj"
36750814a2baSmrg    test "X$libobj" != "X$func_quote_arg_result" \
367663847c39Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
36770814a2baSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
367863847c39Smrg    func_dirname_and_basename "$obj" "/" ""
36790814a2baSmrg    objname=$func_basename_result
36800814a2baSmrg    xdir=$func_dirname_result
36810814a2baSmrg    lobj=$xdir$objdir/$objname
368276888252Smrg
368363847c39Smrg    test -z "$base_compile" && \
368463847c39Smrg      func_fatal_help "you must specify a compilation command"
368576888252Smrg
368663847c39Smrg    # Delete any leftover library objects.
36870814a2baSmrg    if test yes = "$build_old_libs"; then
368863847c39Smrg      removelist="$obj $lobj $libobj ${libobj}T"
368963847c39Smrg    else
369063847c39Smrg      removelist="$lobj $libobj ${libobj}T"
369163847c39Smrg    fi
369276888252Smrg
369363847c39Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
369463847c39Smrg    case $host_os in
369563847c39Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
369663847c39Smrg      pic_mode=default
369763847c39Smrg      ;;
369863847c39Smrg    esac
36990814a2baSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
370063847c39Smrg      # non-PIC code in shared libraries is not supported
370163847c39Smrg      pic_mode=default
370263847c39Smrg    fi
370376888252Smrg
370463847c39Smrg    # Calculate the filename of the output object if compiler does
370563847c39Smrg    # not support -o with -c
37060814a2baSmrg    if test no = "$compiler_c_o"; then
37070814a2baSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
37080814a2baSmrg      lockfile=$output_obj.lock
370963847c39Smrg    else
371063847c39Smrg      output_obj=
371163847c39Smrg      need_locks=no
371263847c39Smrg      lockfile=
371363847c39Smrg    fi
371476888252Smrg
371563847c39Smrg    # Lock this critical section if it is needed
371663847c39Smrg    # We use this script file to make the link, it avoids creating a new file
37170814a2baSmrg    if test yes = "$need_locks"; then
371863847c39Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
371963847c39Smrg	func_echo "Waiting for $lockfile to be removed"
372063847c39Smrg	sleep 2
372163847c39Smrg      done
37220814a2baSmrg    elif test warn = "$need_locks"; then
372363847c39Smrg      if test -f "$lockfile"; then
372463847c39Smrg	$ECHO "\
372563847c39Smrg*** ERROR, $lockfile exists and contains:
372663847c39Smrg`cat $lockfile 2>/dev/null`
372776888252Smrg
372863847c39SmrgThis indicates that another process is trying to use the same
372963847c39Smrgtemporary object file, and libtool could not work around it because
37300814a2baSmrgyour compiler does not support '-c' and '-o' together.  If you
373163847c39Smrgrepeat this compilation, it may succeed, by chance, but you had better
373263847c39Smrgavoid parallel builds (make -j) in this platform, or get a better
373363847c39Smrgcompiler."
373476888252Smrg
373563847c39Smrg	$opt_dry_run || $RM $removelist
373663847c39Smrg	exit $EXIT_FAILURE
373763847c39Smrg      fi
373863847c39Smrg      func_append removelist " $output_obj"
373963847c39Smrg      $ECHO "$srcfile" > "$lockfile"
374063847c39Smrg    fi
374176888252Smrg
374263847c39Smrg    $opt_dry_run || $RM $removelist
374363847c39Smrg    func_append removelist " $lockfile"
374463847c39Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
374576888252Smrg
374663847c39Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
374763847c39Smrg    srcfile=$func_to_tool_file_result
37480814a2baSmrg    func_quote_arg pretty "$srcfile"
37490814a2baSmrg    qsrcfile=$func_quote_arg_result
375076888252Smrg
375163847c39Smrg    # Only build a PIC object if we are building libtool libraries.
37520814a2baSmrg    if test yes = "$build_libtool_libs"; then
375363847c39Smrg      # Without this assignment, base_compile gets emptied.
375463847c39Smrg      fbsd_hideous_sh_bug=$base_compile
375576888252Smrg
37560814a2baSmrg      if test no != "$pic_mode"; then
375763847c39Smrg	command="$base_compile $qsrcfile $pic_flag"
375863847c39Smrg      else
375963847c39Smrg	# Don't build PIC code
376063847c39Smrg	command="$base_compile $qsrcfile"
376163847c39Smrg      fi
376276888252Smrg
376363847c39Smrg      func_mkdir_p "$xdir$objdir"
376476888252Smrg
376563847c39Smrg      if test -z "$output_obj"; then
376663847c39Smrg	# Place PIC objects in $objdir
376763847c39Smrg	func_append command " -o $lobj"
376863847c39Smrg      fi
376986dafe34Smrg
377063847c39Smrg      func_show_eval_locale "$command"	\
377163847c39Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
377276888252Smrg
37730814a2baSmrg      if test warn = "$need_locks" &&
377463847c39Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
377563847c39Smrg	$ECHO "\
377663847c39Smrg*** ERROR, $lockfile contains:
377763847c39Smrg`cat $lockfile 2>/dev/null`
3778d8556812Smrg
377963847c39Smrgbut it should contain:
378063847c39Smrg$srcfile
3781d8556812Smrg
378263847c39SmrgThis indicates that another process is trying to use the same
378363847c39Smrgtemporary object file, and libtool could not work around it because
37840814a2baSmrgyour compiler does not support '-c' and '-o' together.  If you
378563847c39Smrgrepeat this compilation, it may succeed, by chance, but you had better
378663847c39Smrgavoid parallel builds (make -j) in this platform, or get a better
378763847c39Smrgcompiler."
378876888252Smrg
378963847c39Smrg	$opt_dry_run || $RM $removelist
379063847c39Smrg	exit $EXIT_FAILURE
379163847c39Smrg      fi
379276888252Smrg
379363847c39Smrg      # Just move the object if needed, then go on to compile the next one
379463847c39Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
379563847c39Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
379663847c39Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
379763847c39Smrg      fi
379876888252Smrg
379963847c39Smrg      # Allow error messages only from the first compilation.
38000814a2baSmrg      if test yes = "$suppress_opt"; then
380163847c39Smrg	suppress_output=' >/dev/null 2>&1'
380263847c39Smrg      fi
380363847c39Smrg    fi
380476888252Smrg
380563847c39Smrg    # Only build a position-dependent object if we build old libraries.
38060814a2baSmrg    if test yes = "$build_old_libs"; then
38070814a2baSmrg      if test yes != "$pic_mode"; then
380863847c39Smrg	# Don't build PIC code
380963847c39Smrg	command="$base_compile $qsrcfile$pie_flag"
381063847c39Smrg      else
381163847c39Smrg	command="$base_compile $qsrcfile $pic_flag"
381263847c39Smrg      fi
38130814a2baSmrg      if test yes = "$compiler_c_o"; then
381463847c39Smrg	func_append command " -o $obj"
381563847c39Smrg      fi
381676888252Smrg
381763847c39Smrg      # Suppress compiler output if we already did a PIC compilation.
381863847c39Smrg      func_append command "$suppress_output"
381963847c39Smrg      func_show_eval_locale "$command" \
382063847c39Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
382186dafe34Smrg
38220814a2baSmrg      if test warn = "$need_locks" &&
382363847c39Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
382463847c39Smrg	$ECHO "\
382563847c39Smrg*** ERROR, $lockfile contains:
382663847c39Smrg`cat $lockfile 2>/dev/null`
382776888252Smrg
382863847c39Smrgbut it should contain:
382963847c39Smrg$srcfile
383086dafe34Smrg
383163847c39SmrgThis indicates that another process is trying to use the same
383263847c39Smrgtemporary object file, and libtool could not work around it because
38330814a2baSmrgyour compiler does not support '-c' and '-o' together.  If you
383463847c39Smrgrepeat this compilation, it may succeed, by chance, but you had better
383563847c39Smrgavoid parallel builds (make -j) in this platform, or get a better
383663847c39Smrgcompiler."
383786dafe34Smrg
383863847c39Smrg	$opt_dry_run || $RM $removelist
383963847c39Smrg	exit $EXIT_FAILURE
384063847c39Smrg      fi
384186dafe34Smrg
384263847c39Smrg      # Just move the object if needed
384363847c39Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
384463847c39Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
384563847c39Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
384663847c39Smrg      fi
384763847c39Smrg    fi
384886dafe34Smrg
384963847c39Smrg    $opt_dry_run || {
385063847c39Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
385186dafe34Smrg
385263847c39Smrg      # Unlock the critical section if it was locked
38530814a2baSmrg      if test no != "$need_locks"; then
385463847c39Smrg	removelist=$lockfile
385563847c39Smrg        $RM "$lockfile"
385663847c39Smrg      fi
385763847c39Smrg    }
385886dafe34Smrg
385963847c39Smrg    exit $EXIT_SUCCESS
386063847c39Smrg}
386186dafe34Smrg
386263847c39Smrg$opt_help || {
38630814a2baSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
386463847c39Smrg}
386586dafe34Smrg
386663847c39Smrgfunc_mode_help ()
386763847c39Smrg{
386863847c39Smrg    # We need to display help for each of the modes.
386963847c39Smrg    case $opt_mode in
387063847c39Smrg      "")
387163847c39Smrg        # Generic help is extracted from the usage comments
387263847c39Smrg        # at the start of this file.
387363847c39Smrg        func_help
387463847c39Smrg        ;;
387586dafe34Smrg
387663847c39Smrg      clean)
387763847c39Smrg        $ECHO \
387863847c39Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
387986dafe34Smrg
388063847c39SmrgRemove files from the build directory.
3881d8556812Smrg
388263847c39SmrgRM is the name of the program to use to delete files associated with each FILE
38830814a2baSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
388463847c39Smrgto RM.
388576888252Smrg
388663847c39SmrgIf FILE is a libtool library, object or program, all the files associated
388763847c39Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
388863847c39Smrg        ;;
388976888252Smrg
389063847c39Smrg      compile)
389163847c39Smrg      $ECHO \
389263847c39Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
389376888252Smrg
389463847c39SmrgCompile a source file into a libtool library object.
389576888252Smrg
389663847c39SmrgThis mode accepts the following additional options:
389776888252Smrg
389863847c39Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
389963847c39Smrg  -no-suppress      do not suppress compiler output for multiple passes
390063847c39Smrg  -prefer-pic       try to build PIC objects only
390163847c39Smrg  -prefer-non-pic   try to build non-PIC objects only
39020814a2baSmrg  -shared           do not build a '.o' file suitable for static linking
39030814a2baSmrg  -static           only build a '.o' file suitable for static linking
39040814a2baSmrg  -Wc,FLAG
39050814a2baSmrg  -Xcompiler FLAG   pass FLAG directly to the compiler
390686dafe34Smrg
39070814a2baSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
390863847c39Smrgfrom the given SOURCEFILE.
390976888252Smrg
391063847c39SmrgThe output file name is determined by removing the directory component from
39110814a2baSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
39120814a2baSmrglibrary object suffix, '.lo'."
391363847c39Smrg        ;;
391486dafe34Smrg
391563847c39Smrg      execute)
391663847c39Smrg        $ECHO \
391763847c39Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
391876888252Smrg
391963847c39SmrgAutomatically set library path, then run a program.
392076888252Smrg
392163847c39SmrgThis mode accepts the following additional options:
392276888252Smrg
392363847c39Smrg  -dlopen FILE      add the directory containing FILE to the library path
392486dafe34Smrg
39250814a2baSmrgThis mode sets the library path environment variable according to '-dlopen'
392663847c39Smrgflags.
392776888252Smrg
392863847c39SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
392963847c39Smrginto their corresponding uninstalled binary, and any of their required library
393063847c39Smrgdirectories are added to the library path.
393176888252Smrg
393263847c39SmrgThen, COMMAND is executed, with ARGS as arguments."
393363847c39Smrg        ;;
393463847c39Smrg
393563847c39Smrg      finish)
393663847c39Smrg        $ECHO \
393763847c39Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
393863847c39Smrg
393963847c39SmrgComplete the installation of libtool libraries.
394063847c39Smrg
394163847c39SmrgEach LIBDIR is a directory that contains libtool libraries.
394263847c39Smrg
394363847c39SmrgThe commands that this mode executes may require superuser privileges.  Use
39440814a2baSmrgthe '--dry-run' option if you just want to see what would be executed."
394563847c39Smrg        ;;
394663847c39Smrg
394763847c39Smrg      install)
394863847c39Smrg        $ECHO \
394963847c39Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
395063847c39Smrg
395163847c39SmrgInstall executables or libraries.
395263847c39Smrg
395363847c39SmrgINSTALL-COMMAND is the installation command.  The first component should be
39540814a2baSmrgeither the 'install' or 'cp' program.
395563847c39Smrg
395663847c39SmrgThe following components of INSTALL-COMMAND are treated specially:
395763847c39Smrg
395863847c39Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
395963847c39Smrg
396063847c39SmrgThe rest of the components are interpreted as arguments to that command (only
396163847c39SmrgBSD-compatible install options are recognized)."
396263847c39Smrg        ;;
396363847c39Smrg
396463847c39Smrg      link)
396563847c39Smrg        $ECHO \
396663847c39Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
396763847c39Smrg
396863847c39SmrgLink object files or libraries together to form another library, or to
396963847c39Smrgcreate an executable program.
397063847c39Smrg
397163847c39SmrgLINK-COMMAND is a command using the C compiler that you would use to create
397263847c39Smrga program from several object files.
397363847c39Smrg
397463847c39SmrgThe following components of LINK-COMMAND are treated specially:
397563847c39Smrg
397663847c39Smrg  -all-static       do not do any dynamic linking at all
397763847c39Smrg  -avoid-version    do not add a version suffix if possible
397863847c39Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397963847c39Smrg                    libraries must be found in the PATH setting at runtime)
39800814a2baSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
398163847c39Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
398263847c39Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
398363847c39Smrg  -export-symbols SYMFILE
398463847c39Smrg                    try to export only the symbols listed in SYMFILE
398563847c39Smrg  -export-symbols-regex REGEX
398663847c39Smrg                    try to export only the symbols matching REGEX
398763847c39Smrg  -LLIBDIR          search LIBDIR for required installed libraries
398863847c39Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
398963847c39Smrg  -module           build a library that can dlopened
399063847c39Smrg  -no-fast-install  disable the fast-install mode
399163847c39Smrg  -no-install       link a not-installable executable
399263847c39Smrg  -no-undefined     declare that a library does not refer to external symbols
399363847c39Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
39940814a2baSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
39950814a2baSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
399663847c39Smrg  -precious-files-regex REGEX
399763847c39Smrg                    don't remove output files matching REGEX
399863847c39Smrg  -release RELEASE  specify package release information
399963847c39Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
400063847c39Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
400163847c39Smrg  -shared           only do dynamic linking of libtool libraries
400263847c39Smrg  -shrext SUFFIX    override the standard shared library file extension
400363847c39Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
400463847c39Smrg  -static-libtool-libs
400563847c39Smrg                    do not do any dynamic linking of libtool libraries
400663847c39Smrg  -version-info CURRENT[:REVISION[:AGE]]
400763847c39Smrg                    specify library version info [each variable defaults to 0]
400863847c39Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400963847c39Smrg  -Wc,FLAG
401063847c39Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
40110814a2baSmrg  -Wa,FLAG
40120814a2baSmrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
401363847c39Smrg  -Wl,FLAG
401463847c39Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
401563847c39Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
401663847c39Smrg
40170814a2baSmrgAll other options (arguments beginning with '-') are ignored.
401863847c39Smrg
40190814a2baSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
402063847c39Smrgtreated as uninstalled libtool libraries, other files are standard or library
402163847c39Smrgobject files.
402263847c39Smrg
40230814a2baSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
40240814a2baSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
402563847c39Smrgrequired, except when creating a convenience library.
402663847c39Smrg
40270814a2baSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
40280814a2baSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
402963847c39Smrg
40300814a2baSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
403163847c39Smrgis created, otherwise an executable program is created."
403263847c39Smrg        ;;
403363847c39Smrg
403463847c39Smrg      uninstall)
403563847c39Smrg        $ECHO \
403663847c39Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
403763847c39Smrg
403863847c39SmrgRemove libraries from an installation directory.
403963847c39Smrg
404063847c39SmrgRM is the name of the program to use to delete files associated with each FILE
40410814a2baSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
404263847c39Smrgto RM.
404363847c39Smrg
404463847c39SmrgIf FILE is a libtool library, all the files associated with it are deleted.
404563847c39SmrgOtherwise, only FILE itself is deleted using RM."
404663847c39Smrg        ;;
404763847c39Smrg
404863847c39Smrg      *)
40490814a2baSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
405063847c39Smrg        ;;
4051d8556812Smrg    esac
405276888252Smrg
405363847c39Smrg    echo
40540814a2baSmrg    $ECHO "Try '$progname --help' for more information about other modes."
405563847c39Smrg}
405686dafe34Smrg
405763847c39Smrg# Now that we've collected a possible --mode arg, show help if necessary
405863847c39Smrgif $opt_help; then
40590814a2baSmrg  if test : = "$opt_help"; then
406063847c39Smrg    func_mode_help
406163847c39Smrg  else
406263847c39Smrg    {
406363847c39Smrg      func_help noexit
406463847c39Smrg      for opt_mode in compile link execute install finish uninstall clean; do
406563847c39Smrg	func_mode_help
406663847c39Smrg      done
40670814a2baSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406863847c39Smrg    {
406963847c39Smrg      func_help noexit
407063847c39Smrg      for opt_mode in compile link execute install finish uninstall clean; do
407163847c39Smrg	echo
407263847c39Smrg	func_mode_help
407363847c39Smrg      done
407463847c39Smrg    } |
40750814a2baSmrg    $SED '1d
407663847c39Smrg      /^When reporting/,/^Report/{
407763847c39Smrg	H
407863847c39Smrg	d
407963847c39Smrg      }
408063847c39Smrg      $x
408163847c39Smrg      /information about other modes/d
408263847c39Smrg      /more detailed .*MODE/d
408363847c39Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
408463847c39Smrg  fi
408563847c39Smrg  exit $?
408663847c39Smrgfi
408786dafe34Smrg
408886dafe34Smrg
408963847c39Smrg# func_mode_execute arg...
409063847c39Smrgfunc_mode_execute ()
409163847c39Smrg{
40920814a2baSmrg    $debug_cmd
40930814a2baSmrg
409463847c39Smrg    # The first argument is the command name.
40950814a2baSmrg    cmd=$nonopt
409663847c39Smrg    test -z "$cmd" && \
409763847c39Smrg      func_fatal_help "you must specify a COMMAND"
409863847c39Smrg
409963847c39Smrg    # Handle -dlopen flags immediately.
410063847c39Smrg    for file in $opt_dlopen; do
410163847c39Smrg      test -f "$file" \
41020814a2baSmrg	|| func_fatal_help "'$file' is not a file"
410363847c39Smrg
410463847c39Smrg      dir=
410563847c39Smrg      case $file in
410663847c39Smrg      *.la)
410763847c39Smrg	func_resolve_sysroot "$file"
410863847c39Smrg	file=$func_resolve_sysroot_result
410963847c39Smrg
411063847c39Smrg	# Check to see that this really is a libtool archive.
411163847c39Smrg	func_lalib_unsafe_p "$file" \
41120814a2baSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
411363847c39Smrg
411463847c39Smrg	# Read the libtool library.
411563847c39Smrg	dlname=
411663847c39Smrg	library_names=
411763847c39Smrg	func_source "$file"
411863847c39Smrg
411963847c39Smrg	# Skip this library if it cannot be dlopened.
412063847c39Smrg	if test -z "$dlname"; then
412163847c39Smrg	  # Warn if it was a shared library.
412263847c39Smrg	  test -n "$library_names" && \
41230814a2baSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
412463847c39Smrg	  continue
412563847c39Smrg	fi
412663847c39Smrg
412763847c39Smrg	func_dirname "$file" "" "."
41280814a2baSmrg	dir=$func_dirname_result
412963847c39Smrg
413063847c39Smrg	if test -f "$dir/$objdir/$dlname"; then
413163847c39Smrg	  func_append dir "/$objdir"
413263847c39Smrg	else
413363847c39Smrg	  if test ! -f "$dir/$dlname"; then
41340814a2baSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
413563847c39Smrg	  fi
413663847c39Smrg	fi
413786dafe34Smrg	;;
413863847c39Smrg
413963847c39Smrg      *.lo)
414063847c39Smrg	# Just add the directory containing the .lo file.
414163847c39Smrg	func_dirname "$file" "" "."
41420814a2baSmrg	dir=$func_dirname_result
4143d8556812Smrg	;;
414463847c39Smrg
414563847c39Smrg      *)
41460814a2baSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
414763847c39Smrg	continue
414886dafe34Smrg	;;
414963847c39Smrg      esac
415063847c39Smrg
415163847c39Smrg      # Get the absolute pathname.
415263847c39Smrg      absdir=`cd "$dir" && pwd`
41530814a2baSmrg      test -n "$absdir" && dir=$absdir
415463847c39Smrg
415563847c39Smrg      # Now add the directory to shlibpath_var.
415663847c39Smrg      if eval "test -z \"\$$shlibpath_var\""; then
415763847c39Smrg	eval "$shlibpath_var=\"\$dir\""
415863847c39Smrg      else
415963847c39Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160d8556812Smrg      fi
416163847c39Smrg    done
416263847c39Smrg
416363847c39Smrg    # This variable tells wrapper scripts just to set shlibpath_var
416463847c39Smrg    # rather than running their programs.
41650814a2baSmrg    libtool_execute_magic=$magic
416663847c39Smrg
416763847c39Smrg    # Check if any of the arguments is a wrapper script.
416863847c39Smrg    args=
416963847c39Smrg    for file
417063847c39Smrg    do
417163847c39Smrg      case $file in
417263847c39Smrg      -* | *.la | *.lo ) ;;
417363847c39Smrg      *)
417463847c39Smrg	# Do a test to see if this is really a libtool program.
417563847c39Smrg	if func_ltwrapper_script_p "$file"; then
417663847c39Smrg	  func_source "$file"
417763847c39Smrg	  # Transform arg to wrapped name.
41780814a2baSmrg	  file=$progdir/$program
417963847c39Smrg	elif func_ltwrapper_executable_p "$file"; then
418063847c39Smrg	  func_ltwrapper_scriptname "$file"
418163847c39Smrg	  func_source "$func_ltwrapper_scriptname_result"
418263847c39Smrg	  # Transform arg to wrapped name.
41830814a2baSmrg	  file=$progdir/$program
418463847c39Smrg	fi
418563847c39Smrg	;;
418663847c39Smrg      esac
418763847c39Smrg      # Quote arguments (to preserve shell metacharacters).
418863847c39Smrg      func_append_quoted args "$file"
418963847c39Smrg    done
419063847c39Smrg
41910814a2baSmrg    if $opt_dry_run; then
41920814a2baSmrg      # Display what would be done.
41930814a2baSmrg      if test -n "$shlibpath_var"; then
41940814a2baSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
41950814a2baSmrg	echo "export $shlibpath_var"
41960814a2baSmrg      fi
41970814a2baSmrg      $ECHO "$cmd$args"
41980814a2baSmrg      exit $EXIT_SUCCESS
41990814a2baSmrg    else
420063847c39Smrg      if test -n "$shlibpath_var"; then
420163847c39Smrg	# Export the shlibpath_var.
420263847c39Smrg	eval "export $shlibpath_var"
4203d8556812Smrg      fi
420463847c39Smrg
420563847c39Smrg      # Restore saved environment variables
420663847c39Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
420763847c39Smrg      do
420863847c39Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
420963847c39Smrg                $lt_var=\$save_$lt_var; export $lt_var
421063847c39Smrg	      else
421163847c39Smrg		$lt_unset $lt_var
421263847c39Smrg	      fi"
421363847c39Smrg      done
421463847c39Smrg
421563847c39Smrg      # Now prepare to actually exec the command.
42160814a2baSmrg      exec_cmd=\$cmd$args
421763847c39Smrg    fi
421863847c39Smrg}
421976888252Smrg
42200814a2baSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
422176888252Smrg
422276888252Smrg
422363847c39Smrg# func_mode_finish arg...
422463847c39Smrgfunc_mode_finish ()
422563847c39Smrg{
42260814a2baSmrg    $debug_cmd
42270814a2baSmrg
422863847c39Smrg    libs=
422963847c39Smrg    libdirs=
423063847c39Smrg    admincmds=
423176888252Smrg
423263847c39Smrg    for opt in "$nonopt" ${1+"$@"}
423363847c39Smrg    do
423463847c39Smrg      if test -d "$opt"; then
423563847c39Smrg	func_append libdirs " $opt"
423676888252Smrg
423763847c39Smrg      elif test -f "$opt"; then
423863847c39Smrg	if func_lalib_unsafe_p "$opt"; then
423963847c39Smrg	  func_append libs " $opt"
424063847c39Smrg	else
42410814a2baSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242d8556812Smrg	fi
424376888252Smrg
424463847c39Smrg      else
42450814a2baSmrg	func_fatal_error "invalid argument '$opt'"
424663847c39Smrg      fi
424763847c39Smrg    done
424876888252Smrg
424963847c39Smrg    if test -n "$libs"; then
425063847c39Smrg      if test -n "$lt_sysroot"; then
425163847c39Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
425263847c39Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
425363847c39Smrg      else
425463847c39Smrg        sysroot_cmd=
425563847c39Smrg      fi
425676888252Smrg
425763847c39Smrg      # Remove sysroot references
425863847c39Smrg      if $opt_dry_run; then
425963847c39Smrg        for lib in $libs; do
42600814a2baSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
426163847c39Smrg        done
426263847c39Smrg      else
426363847c39Smrg        tmpdir=`func_mktempdir`
426463847c39Smrg        for lib in $libs; do
42650814a2baSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
426663847c39Smrg	    > $tmpdir/tmp-la
426763847c39Smrg	  mv -f $tmpdir/tmp-la $lib
4268d8556812Smrg	done
426963847c39Smrg        ${RM}r "$tmpdir"
427063847c39Smrg      fi
427163847c39Smrg    fi
427263847c39Smrg
427363847c39Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
427463847c39Smrg      for libdir in $libdirs; do
427563847c39Smrg	if test -n "$finish_cmds"; then
427663847c39Smrg	  # Do each command in the finish commands.
427763847c39Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
427863847c39Smrg'"$cmd"'"'
427963847c39Smrg	fi
428063847c39Smrg	if test -n "$finish_eval"; then
428163847c39Smrg	  # Do the single finish_eval.
428263847c39Smrg	  eval cmds=\"$finish_eval\"
428363847c39Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
428463847c39Smrg       $cmds"
428576888252Smrg	fi
428663847c39Smrg      done
428763847c39Smrg    fi
428876888252Smrg
428963847c39Smrg    # Exit here if they wanted silent mode.
42900814a2baSmrg    $opt_quiet && exit $EXIT_SUCCESS
429176888252Smrg
429263847c39Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
429363847c39Smrg      echo "----------------------------------------------------------------------"
429463847c39Smrg      echo "Libraries have been installed in:"
429563847c39Smrg      for libdir in $libdirs; do
429663847c39Smrg	$ECHO "   $libdir"
429763847c39Smrg      done
429863847c39Smrg      echo
429963847c39Smrg      echo "If you ever happen to want to link against installed libraries"
430063847c39Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
43010814a2baSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
430263847c39Smrg      echo "flag during linking and do at least one of the following:"
430363847c39Smrg      if test -n "$shlibpath_var"; then
43040814a2baSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
430563847c39Smrg	echo "     during execution"
430663847c39Smrg      fi
430763847c39Smrg      if test -n "$runpath_var"; then
43080814a2baSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
430963847c39Smrg	echo "     during linking"
431063847c39Smrg      fi
431163847c39Smrg      if test -n "$hardcode_libdir_flag_spec"; then
431263847c39Smrg	libdir=LIBDIR
431363847c39Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
431463847c39Smrg
43150814a2baSmrg	$ECHO "   - use the '$flag' linker flag"
431663847c39Smrg      fi
431763847c39Smrg      if test -n "$admincmds"; then
431863847c39Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
431963847c39Smrg      fi
432063847c39Smrg      if test -f /etc/ld.so.conf; then
43210814a2baSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
432263847c39Smrg      fi
432363847c39Smrg      echo
432463847c39Smrg
432563847c39Smrg      echo "See any operating system documentation about shared libraries for"
432663847c39Smrg      case $host in
432763847c39Smrg	solaris2.[6789]|solaris2.1[0-9])
432863847c39Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
432963847c39Smrg	  echo "pages."
433063847c39Smrg	  ;;
4331d8556812Smrg	*)
433263847c39Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333d8556812Smrg	  ;;
433463847c39Smrg      esac
433563847c39Smrg      echo "----------------------------------------------------------------------"
433663847c39Smrg    fi
433763847c39Smrg    exit $EXIT_SUCCESS
433863847c39Smrg}
433976888252Smrg
43400814a2baSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
434176888252Smrg
434276888252Smrg
434363847c39Smrg# func_mode_install arg...
434463847c39Smrgfunc_mode_install ()
434563847c39Smrg{
43460814a2baSmrg    $debug_cmd
43470814a2baSmrg
434863847c39Smrg    # There may be an optional sh(1) argument at the beginning of
434963847c39Smrg    # install_prog (especially on Windows NT).
43500814a2baSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
435163847c39Smrg       # Allow the use of GNU shtool's install command.
43520814a2baSmrg       case $nonopt in *shtool*) :;; *) false;; esac
43530814a2baSmrg    then
435463847c39Smrg      # Aesthetically quote it.
43550814a2baSmrg      func_quote_arg pretty "$nonopt"
43560814a2baSmrg      install_prog="$func_quote_arg_result "
435763847c39Smrg      arg=$1
435863847c39Smrg      shift
435963847c39Smrg    else
436063847c39Smrg      install_prog=
436163847c39Smrg      arg=$nonopt
436263847c39Smrg    fi
436363847c39Smrg
436463847c39Smrg    # The real first argument should be the name of the installation program.
436563847c39Smrg    # Aesthetically quote it.
43660814a2baSmrg    func_quote_arg pretty "$arg"
43670814a2baSmrg    func_append install_prog "$func_quote_arg_result"
436863847c39Smrg    install_shared_prog=$install_prog
436963847c39Smrg    case " $install_prog " in
437063847c39Smrg      *[\\\ /]cp\ *) install_cp=: ;;
437163847c39Smrg      *) install_cp=false ;;
437263847c39Smrg    esac
437363847c39Smrg
437463847c39Smrg    # We need to accept at least all the BSD install flags.
437563847c39Smrg    dest=
437663847c39Smrg    files=
437763847c39Smrg    opts=
437863847c39Smrg    prev=
437963847c39Smrg    install_type=
43800814a2baSmrg    isdir=false
438163847c39Smrg    stripme=
438263847c39Smrg    no_mode=:
438363847c39Smrg    for arg
438463847c39Smrg    do
438563847c39Smrg      arg2=
438663847c39Smrg      if test -n "$dest"; then
438763847c39Smrg	func_append files " $dest"
438863847c39Smrg	dest=$arg
438963847c39Smrg	continue
439063847c39Smrg      fi
439163847c39Smrg
439263847c39Smrg      case $arg in
43930814a2baSmrg      -d) isdir=: ;;
439463847c39Smrg      -f)
439563847c39Smrg	if $install_cp; then :; else
439663847c39Smrg	  prev=$arg
439763847c39Smrg	fi
439863847c39Smrg	;;
439963847c39Smrg      -g | -m | -o)
440063847c39Smrg	prev=$arg
440163847c39Smrg	;;
440263847c39Smrg      -s)
440363847c39Smrg	stripme=" -s"
440463847c39Smrg	continue
440563847c39Smrg	;;
440663847c39Smrg      -*)
440763847c39Smrg	;;
440863847c39Smrg      *)
440963847c39Smrg	# If the previous option needed an argument, then skip it.
441063847c39Smrg	if test -n "$prev"; then
44110814a2baSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
441263847c39Smrg	    arg2=$install_override_mode
441363847c39Smrg	    no_mode=false
4414d8556812Smrg	  fi
441563847c39Smrg	  prev=
441663847c39Smrg	else
441763847c39Smrg	  dest=$arg
4418d8556812Smrg	  continue
4419d8556812Smrg	fi
442063847c39Smrg	;;
442163847c39Smrg      esac
442276888252Smrg
442363847c39Smrg      # Aesthetically quote the argument.
44240814a2baSmrg      func_quote_arg pretty "$arg"
44250814a2baSmrg      func_append install_prog " $func_quote_arg_result"
442663847c39Smrg      if test -n "$arg2"; then
44270814a2baSmrg	func_quote_arg pretty "$arg2"
442863847c39Smrg      fi
44290814a2baSmrg      func_append install_shared_prog " $func_quote_arg_result"
443063847c39Smrg    done
443176888252Smrg
443263847c39Smrg    test -z "$install_prog" && \
443363847c39Smrg      func_fatal_help "you must specify an install program"
443476888252Smrg
443563847c39Smrg    test -n "$prev" && \
44360814a2baSmrg      func_fatal_help "the '$prev' option requires an argument"
443776888252Smrg
443863847c39Smrg    if test -n "$install_override_mode" && $no_mode; then
443963847c39Smrg      if $install_cp; then :; else
44400814a2baSmrg	func_quote_arg pretty "$install_override_mode"
44410814a2baSmrg	func_append install_shared_prog " -m $func_quote_arg_result"
444263847c39Smrg      fi
444363847c39Smrg    fi
444476888252Smrg
444563847c39Smrg    if test -z "$files"; then
444663847c39Smrg      if test -z "$dest"; then
444763847c39Smrg	func_fatal_help "no file or destination specified"
444863847c39Smrg      else
444963847c39Smrg	func_fatal_help "you must specify a destination"
445063847c39Smrg      fi
445163847c39Smrg    fi
445276888252Smrg
445363847c39Smrg    # Strip any trailing slash from the destination.
445463847c39Smrg    func_stripname '' '/' "$dest"
445563847c39Smrg    dest=$func_stripname_result
445676888252Smrg
445763847c39Smrg    # Check to see that the destination is a directory.
44580814a2baSmrg    test -d "$dest" && isdir=:
44590814a2baSmrg    if $isdir; then
44600814a2baSmrg      destdir=$dest
446163847c39Smrg      destname=
446263847c39Smrg    else
446363847c39Smrg      func_dirname_and_basename "$dest" "" "."
44640814a2baSmrg      destdir=$func_dirname_result
44650814a2baSmrg      destname=$func_basename_result
446676888252Smrg
446763847c39Smrg      # Not a directory, so check to see that there is only one file specified.
446863847c39Smrg      set dummy $files; shift
446963847c39Smrg      test "$#" -gt 1 && \
44700814a2baSmrg	func_fatal_help "'$dest' is not a directory"
447163847c39Smrg    fi
447263847c39Smrg    case $destdir in
447363847c39Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
447463847c39Smrg    *)
447563847c39Smrg      for file in $files; do
447663847c39Smrg	case $file in
447763847c39Smrg	*.lo) ;;
447863847c39Smrg	*)
44790814a2baSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
448063847c39Smrg	  ;;
448163847c39Smrg	esac
448263847c39Smrg      done
448363847c39Smrg      ;;
448463847c39Smrg    esac
448576888252Smrg
448663847c39Smrg    # This variable tells wrapper scripts just to set variables rather
448763847c39Smrg    # than running their programs.
44880814a2baSmrg    libtool_install_magic=$magic
448976888252Smrg
449063847c39Smrg    staticlibs=
449163847c39Smrg    future_libdirs=
449263847c39Smrg    current_libdirs=
449363847c39Smrg    for file in $files; do
449476888252Smrg
449563847c39Smrg      # Do each installation.
449663847c39Smrg      case $file in
449763847c39Smrg      *.$libext)
449863847c39Smrg	# Do the static libraries later.
449963847c39Smrg	func_append staticlibs " $file"
450063847c39Smrg	;;
450176888252Smrg
450263847c39Smrg      *.la)
450363847c39Smrg	func_resolve_sysroot "$file"
450463847c39Smrg	file=$func_resolve_sysroot_result
450576888252Smrg
450663847c39Smrg	# Check to see that this really is a libtool archive.
450763847c39Smrg	func_lalib_unsafe_p "$file" \
45080814a2baSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
450976888252Smrg
451063847c39Smrg	library_names=
451163847c39Smrg	old_library=
451263847c39Smrg	relink_command=
451363847c39Smrg	func_source "$file"
451476888252Smrg
451563847c39Smrg	# Add the libdir to current_libdirs if it is the destination.
451663847c39Smrg	if test "X$destdir" = "X$libdir"; then
451763847c39Smrg	  case "$current_libdirs " in
451863847c39Smrg	  *" $libdir "*) ;;
451963847c39Smrg	  *) func_append current_libdirs " $libdir" ;;
452063847c39Smrg	  esac
452163847c39Smrg	else
452263847c39Smrg	  # Note the libdir as a future libdir.
452363847c39Smrg	  case "$future_libdirs " in
452463847c39Smrg	  *" $libdir "*) ;;
452563847c39Smrg	  *) func_append future_libdirs " $libdir" ;;
452663847c39Smrg	  esac
452763847c39Smrg	fi
452876888252Smrg
452963847c39Smrg	func_dirname "$file" "/" ""
45300814a2baSmrg	dir=$func_dirname_result
453163847c39Smrg	func_append dir "$objdir"
453276888252Smrg
453363847c39Smrg	if test -n "$relink_command"; then
453463847c39Smrg	  # Determine the prefix the user has applied to our future dir.
453563847c39Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
453676888252Smrg
453763847c39Smrg	  # Don't allow the user to place us outside of our expected
453863847c39Smrg	  # location b/c this prevents finding dependent libraries that
453963847c39Smrg	  # are installed to the same prefix.
454063847c39Smrg	  # At present, this check doesn't affect windows .dll's that
454163847c39Smrg	  # are installed into $libdir/../bin (currently, that works fine)
454263847c39Smrg	  # but it's something to keep an eye on.
454363847c39Smrg	  test "$inst_prefix_dir" = "$destdir" && \
45440814a2baSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
454563847c39Smrg
454663847c39Smrg	  if test -n "$inst_prefix_dir"; then
454763847c39Smrg	    # Stick the inst_prefix_dir data into the link command.
454863847c39Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549d8556812Smrg	  else
455063847c39Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551d8556812Smrg	  fi
455276888252Smrg
45530814a2baSmrg	  func_warning "relinking '$file'"
455463847c39Smrg	  func_show_eval "$relink_command" \
45550814a2baSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
455663847c39Smrg	fi
455763847c39Smrg
455863847c39Smrg	# See the names of the shared library.
455963847c39Smrg	set dummy $library_names; shift
456063847c39Smrg	if test -n "$1"; then
45610814a2baSmrg	  realname=$1
456263847c39Smrg	  shift
456363847c39Smrg
45640814a2baSmrg	  srcname=$realname
45650814a2baSmrg	  test -n "$relink_command" && srcname=${realname}T
456663847c39Smrg
456763847c39Smrg	  # Install the shared library and build the symlinks.
456863847c39Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
456963847c39Smrg	      'exit $?'
45700814a2baSmrg	  tstripme=$stripme
457163847c39Smrg	  case $host_os in
457263847c39Smrg	  cygwin* | mingw* | pw32* | cegcc*)
457363847c39Smrg	    case $realname in
457463847c39Smrg	    *.dll.a)
45750814a2baSmrg	      tstripme=
45760814a2baSmrg	      ;;
45770814a2baSmrg	    esac
45780814a2baSmrg	    ;;
45790814a2baSmrg	  os2*)
45800814a2baSmrg	    case $realname in
45810814a2baSmrg	    *_dll.a)
45820814a2baSmrg	      tstripme=
458363847c39Smrg	      ;;
458463847c39Smrg	    esac
458563847c39Smrg	    ;;
458663847c39Smrg	  esac
458763847c39Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
458863847c39Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589d8556812Smrg	  fi
459076888252Smrg
459163847c39Smrg	  if test "$#" -gt 0; then
459263847c39Smrg	    # Delete the old symlinks, and create new ones.
45930814a2baSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
459463847c39Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
459563847c39Smrg	    # so we also need to try rm && ln -s.
459663847c39Smrg	    for linkname
459763847c39Smrg	    do
459863847c39Smrg	      test "$linkname" != "$realname" \
459963847c39Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600d8556812Smrg	    done
4601d8556812Smrg	  fi
460276888252Smrg
460363847c39Smrg	  # Do each command in the postinstall commands.
46040814a2baSmrg	  lib=$destdir/$realname
460563847c39Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
460663847c39Smrg	fi
460786dafe34Smrg
460863847c39Smrg	# Install the pseudo-library for information purposes.
460963847c39Smrg	func_basename "$file"
46100814a2baSmrg	name=$func_basename_result
46110814a2baSmrg	instname=$dir/${name}i
461263847c39Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613d8556812Smrg
461463847c39Smrg	# Maybe install the static library, too.
461563847c39Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
461663847c39Smrg	;;
461763847c39Smrg
461863847c39Smrg      *.lo)
461963847c39Smrg	# Install (i.e. copy) a libtool object.
462063847c39Smrg
462163847c39Smrg	# Figure out destination file name, if it wasn't already specified.
462263847c39Smrg	if test -n "$destname"; then
46230814a2baSmrg	  destfile=$destdir/$destname
4624d8556812Smrg	else
462563847c39Smrg	  func_basename "$file"
46260814a2baSmrg	  destfile=$func_basename_result
46270814a2baSmrg	  destfile=$destdir/$destfile
4628d8556812Smrg	fi
462963847c39Smrg
463063847c39Smrg	# Deduce the name of the destination old-style object file.
463163847c39Smrg	case $destfile in
463263847c39Smrg	*.lo)
463363847c39Smrg	  func_lo2o "$destfile"
463463847c39Smrg	  staticdest=$func_lo2o_result
463563847c39Smrg	  ;;
463663847c39Smrg	*.$objext)
46370814a2baSmrg	  staticdest=$destfile
463863847c39Smrg	  destfile=
463963847c39Smrg	  ;;
464063847c39Smrg	*)
46410814a2baSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
464286dafe34Smrg	  ;;
464386dafe34Smrg	esac
464486dafe34Smrg
464563847c39Smrg	# Install the libtool object if requested.
464663847c39Smrg	test -n "$destfile" && \
464763847c39Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
464886dafe34Smrg
464963847c39Smrg	# Install the old object if enabled.
46500814a2baSmrg	if test yes = "$build_old_libs"; then
465163847c39Smrg	  # Deduce the name of the old-style object file.
465263847c39Smrg	  func_lo2o "$file"
465363847c39Smrg	  staticobj=$func_lo2o_result
465463847c39Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
465563847c39Smrg	fi
465663847c39Smrg	exit $EXIT_SUCCESS
465763847c39Smrg	;;
465876888252Smrg
465963847c39Smrg      *)
466063847c39Smrg	# Figure out destination file name, if it wasn't already specified.
466163847c39Smrg	if test -n "$destname"; then
46620814a2baSmrg	  destfile=$destdir/$destname
466363847c39Smrg	else
466463847c39Smrg	  func_basename "$file"
46650814a2baSmrg	  destfile=$func_basename_result
46660814a2baSmrg	  destfile=$destdir/$destfile
466763847c39Smrg	fi
466876888252Smrg
466963847c39Smrg	# If the file is missing, and there is a .exe on the end, strip it
467063847c39Smrg	# because it is most likely a libtool script we actually want to
467163847c39Smrg	# install
46720814a2baSmrg	stripped_ext=
467363847c39Smrg	case $file in
467463847c39Smrg	  *.exe)
467563847c39Smrg	    if test ! -f "$file"; then
467663847c39Smrg	      func_stripname '' '.exe' "$file"
467763847c39Smrg	      file=$func_stripname_result
46780814a2baSmrg	      stripped_ext=.exe
467963847c39Smrg	    fi
468063847c39Smrg	    ;;
468163847c39Smrg	esac
468276888252Smrg
468363847c39Smrg	# Do a test to see if this is really a libtool program.
468463847c39Smrg	case $host in
468563847c39Smrg	*cygwin* | *mingw*)
468663847c39Smrg	    if func_ltwrapper_executable_p "$file"; then
468763847c39Smrg	      func_ltwrapper_scriptname "$file"
468863847c39Smrg	      wrapper=$func_ltwrapper_scriptname_result
468963847c39Smrg	    else
469063847c39Smrg	      func_stripname '' '.exe' "$file"
469163847c39Smrg	      wrapper=$func_stripname_result
469263847c39Smrg	    fi
469363847c39Smrg	    ;;
469463847c39Smrg	*)
469563847c39Smrg	    wrapper=$file
469663847c39Smrg	    ;;
469763847c39Smrg	esac
469863847c39Smrg	if func_ltwrapper_script_p "$wrapper"; then
469963847c39Smrg	  notinst_deplibs=
470063847c39Smrg	  relink_command=
470176888252Smrg
470263847c39Smrg	  func_source "$wrapper"
470376888252Smrg
470463847c39Smrg	  # Check the variables that should have been set.
470563847c39Smrg	  test -z "$generated_by_libtool_version" && \
47060814a2baSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
470776888252Smrg
47080814a2baSmrg	  finalize=:
470963847c39Smrg	  for lib in $notinst_deplibs; do
471063847c39Smrg	    # Check to see that each library is installed.
471163847c39Smrg	    libdir=
471263847c39Smrg	    if test -f "$lib"; then
471363847c39Smrg	      func_source "$lib"
471463847c39Smrg	    fi
47150814a2baSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
471663847c39Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
47170814a2baSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
47180814a2baSmrg	      finalize=false
471963847c39Smrg	    fi
472063847c39Smrg	  done
472176888252Smrg
472263847c39Smrg	  relink_command=
472363847c39Smrg	  func_source "$wrapper"
472463847c39Smrg
472563847c39Smrg	  outputname=
47260814a2baSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
472763847c39Smrg	    $opt_dry_run || {
47280814a2baSmrg	      if $finalize; then
472963847c39Smrg	        tmpdir=`func_mktempdir`
473063847c39Smrg		func_basename "$file$stripped_ext"
47310814a2baSmrg		file=$func_basename_result
47320814a2baSmrg	        outputname=$tmpdir/$file
473363847c39Smrg	        # Replace the output file specification.
473463847c39Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
473563847c39Smrg
47360814a2baSmrg	        $opt_quiet || {
47370814a2baSmrg	          func_quote_arg expand,pretty "$relink_command"
47380814a2baSmrg		  eval "func_echo $func_quote_arg_result"
473963847c39Smrg	        }
474063847c39Smrg	        if eval "$relink_command"; then :
474163847c39Smrg	          else
47420814a2baSmrg		  func_error "error: relink '$file' with the above command before installing it"
474363847c39Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
474463847c39Smrg		  continue
474563847c39Smrg	        fi
47460814a2baSmrg	        file=$outputname
474763847c39Smrg	      else
47480814a2baSmrg	        func_warning "cannot relink '$file'"
474963847c39Smrg	      fi
475063847c39Smrg	    }
475163847c39Smrg	  else
475263847c39Smrg	    # Install the binary that we compiled earlier.
475363847c39Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
475463847c39Smrg	  fi
4755d8556812Smrg	fi
475663847c39Smrg
475763847c39Smrg	# remove .exe since cygwin /usr/bin/install will append another
475863847c39Smrg	# one anyway
475963847c39Smrg	case $install_prog,$host in
476063847c39Smrg	*/usr/bin/install*,*cygwin*)
476163847c39Smrg	  case $file:$destfile in
476263847c39Smrg	  *.exe:*.exe)
476363847c39Smrg	    # this is ok
476463847c39Smrg	    ;;
476563847c39Smrg	  *.exe:*)
476663847c39Smrg	    destfile=$destfile.exe
476763847c39Smrg	    ;;
476863847c39Smrg	  *:*.exe)
476963847c39Smrg	    func_stripname '' '.exe' "$destfile"
477063847c39Smrg	    destfile=$func_stripname_result
477163847c39Smrg	    ;;
477263847c39Smrg	  esac
477363847c39Smrg	  ;;
477463847c39Smrg	esac
477563847c39Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
477663847c39Smrg	$opt_dry_run || if test -n "$outputname"; then
477763847c39Smrg	  ${RM}r "$tmpdir"
4778d8556812Smrg	fi
4779d8556812Smrg	;;
4780d8556812Smrg      esac
478163847c39Smrg    done
478286dafe34Smrg
478363847c39Smrg    for file in $staticlibs; do
478463847c39Smrg      func_basename "$file"
47850814a2baSmrg      name=$func_basename_result
478686dafe34Smrg
478763847c39Smrg      # Set up the ranlib parameters.
47880814a2baSmrg      oldlib=$destdir/$name
478963847c39Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
479063847c39Smrg      tool_oldlib=$func_to_tool_file_result
479186dafe34Smrg
479263847c39Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
479363847c39Smrg
479463847c39Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
479563847c39Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796d8556812Smrg      fi
479786dafe34Smrg
479863847c39Smrg      # Do each command in the postinstall commands.
479963847c39Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
480063847c39Smrg    done
480186dafe34Smrg
480263847c39Smrg    test -n "$future_libdirs" && \
48030814a2baSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
480486dafe34Smrg
480563847c39Smrg    if test -n "$current_libdirs"; then
480663847c39Smrg      # Maybe just do a dry run.
480763847c39Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
48080814a2baSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
480963847c39Smrg    else
481063847c39Smrg      exit $EXIT_SUCCESS
481163847c39Smrg    fi
481263847c39Smrg}
481386dafe34Smrg
48140814a2baSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
481586dafe34Smrg
481686dafe34Smrg
481763847c39Smrg# func_generate_dlsyms outputname originator pic_p
481863847c39Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
481963847c39Smrg# a dlpreopen symbol table.
482063847c39Smrgfunc_generate_dlsyms ()
482163847c39Smrg{
48220814a2baSmrg    $debug_cmd
48230814a2baSmrg
48240814a2baSmrg    my_outputname=$1
48250814a2baSmrg    my_originator=$2
48260814a2baSmrg    my_pic_p=${3-false}
48270814a2baSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
482863847c39Smrg    my_dlsyms=
482963847c39Smrg
48300814a2baSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
483163847c39Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
48320814a2baSmrg	my_dlsyms=${my_outputname}S.c
483363847c39Smrg      else
483463847c39Smrg	func_error "not configured to extract global symbols from dlpreopened files"
483563847c39Smrg      fi
483663847c39Smrg    fi
483786dafe34Smrg
483863847c39Smrg    if test -n "$my_dlsyms"; then
483963847c39Smrg      case $my_dlsyms in
484063847c39Smrg      "") ;;
484163847c39Smrg      *.c)
484263847c39Smrg	# Discover the nlist of each of the dlfiles.
48430814a2baSmrg	nlist=$output_objdir/$my_outputname.nm
484486dafe34Smrg
484563847c39Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
484686dafe34Smrg
484763847c39Smrg	# Parse the name list into a source file.
484863847c39Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
484986dafe34Smrg
485063847c39Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
48510814a2baSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
48520814a2baSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
485386dafe34Smrg
485463847c39Smrg#ifdef __cplusplus
485563847c39Smrgextern \"C\" {
485663847c39Smrg#endif
485786dafe34Smrg
48580814a2baSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485963847c39Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
486063847c39Smrg#endif
486186dafe34Smrg
486263847c39Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
48630814a2baSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
48640814a2baSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
486563847c39Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
486663847c39Smrg# define LT_DLSYM_CONST
48670814a2baSmrg#elif defined __osf__
486863847c39Smrg/* This system does not cope well with relocations in const data.  */
486963847c39Smrg# define LT_DLSYM_CONST
487063847c39Smrg#else
487163847c39Smrg# define LT_DLSYM_CONST const
487263847c39Smrg#endif
487386dafe34Smrg
48740814a2baSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
48750814a2baSmrg
487663847c39Smrg/* External symbol declarations for the compiler. */\
487763847c39Smrg"
487886dafe34Smrg
48790814a2baSmrg	if test yes = "$dlself"; then
48800814a2baSmrg	  func_verbose "generating symbol list for '$output'"
488186dafe34Smrg
488263847c39Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
488376888252Smrg
488463847c39Smrg	  # Add our own program objects to the symbol list.
488563847c39Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
488663847c39Smrg	  for progfile in $progfiles; do
488763847c39Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
48880814a2baSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
488963847c39Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890d8556812Smrg	  done
489176888252Smrg
489263847c39Smrg	  if test -n "$exclude_expsyms"; then
489363847c39Smrg	    $opt_dry_run || {
489463847c39Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
489563847c39Smrg	      eval '$MV "$nlist"T "$nlist"'
489663847c39Smrg	    }
489763847c39Smrg	  fi
489876888252Smrg
489963847c39Smrg	  if test -n "$export_symbols_regex"; then
490063847c39Smrg	    $opt_dry_run || {
490163847c39Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
490263847c39Smrg	      eval '$MV "$nlist"T "$nlist"'
490363847c39Smrg	    }
490463847c39Smrg	  fi
490576888252Smrg
490663847c39Smrg	  # Prepare the list of exported symbols
490763847c39Smrg	  if test -z "$export_symbols"; then
49080814a2baSmrg	    export_symbols=$output_objdir/$outputname.exp
490963847c39Smrg	    $opt_dry_run || {
491063847c39Smrg	      $RM $export_symbols
49110814a2baSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
491263847c39Smrg	      case $host in
491363847c39Smrg	      *cygwin* | *mingw* | *cegcc* )
491463847c39Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
491563847c39Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
491663847c39Smrg	        ;;
491763847c39Smrg	      esac
491863847c39Smrg	    }
491963847c39Smrg	  else
492063847c39Smrg	    $opt_dry_run || {
49210814a2baSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
492263847c39Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
492363847c39Smrg	      eval '$MV "$nlist"T "$nlist"'
492463847c39Smrg	      case $host in
492563847c39Smrg	        *cygwin* | *mingw* | *cegcc* )
492663847c39Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
492763847c39Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
492863847c39Smrg	          ;;
492963847c39Smrg	      esac
493063847c39Smrg	    }
493163847c39Smrg	  fi
493263847c39Smrg	fi
493376888252Smrg
493463847c39Smrg	for dlprefile in $dlprefiles; do
49350814a2baSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
493663847c39Smrg	  func_basename "$dlprefile"
49370814a2baSmrg	  name=$func_basename_result
493863847c39Smrg          case $host in
493963847c39Smrg	    *cygwin* | *mingw* | *cegcc* )
494063847c39Smrg	      # if an import library, we need to obtain dlname
494163847c39Smrg	      if func_win32_import_lib_p "$dlprefile"; then
494263847c39Smrg	        func_tr_sh "$dlprefile"
494363847c39Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
49440814a2baSmrg	        dlprefile_dlbasename=
494563847c39Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
494663847c39Smrg	          # Use subshell, to avoid clobbering current variable values
494763847c39Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
49480814a2baSmrg	          if test -n "$dlprefile_dlname"; then
494963847c39Smrg	            func_basename "$dlprefile_dlname"
49500814a2baSmrg	            dlprefile_dlbasename=$func_basename_result
495163847c39Smrg	          else
495263847c39Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
495363847c39Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
495463847c39Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
495563847c39Smrg	          fi
495663847c39Smrg	        fi
495763847c39Smrg	        $opt_dry_run || {
49580814a2baSmrg	          if test -n "$dlprefile_dlbasename"; then
495963847c39Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
496063847c39Smrg	          else
496163847c39Smrg	            func_warning "Could not compute DLL name from $name"
496263847c39Smrg	            eval '$ECHO ": $name " >> "$nlist"'
496363847c39Smrg	          fi
496463847c39Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
496563847c39Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
496663847c39Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
496763847c39Smrg	        }
496863847c39Smrg	      else # not an import lib
496963847c39Smrg	        $opt_dry_run || {
497063847c39Smrg	          eval '$ECHO ": $name " >> "$nlist"'
497163847c39Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
497263847c39Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
497363847c39Smrg	        }
497463847c39Smrg	      fi
497563847c39Smrg	    ;;
497663847c39Smrg	    *)
497763847c39Smrg	      $opt_dry_run || {
497863847c39Smrg	        eval '$ECHO ": $name " >> "$nlist"'
497963847c39Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
498063847c39Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
498163847c39Smrg	      }
498263847c39Smrg	    ;;
498363847c39Smrg          esac
498463847c39Smrg	done
498576888252Smrg
498663847c39Smrg	$opt_dry_run || {
498763847c39Smrg	  # Make sure we have at least an empty file.
498863847c39Smrg	  test -f "$nlist" || : > "$nlist"
498976888252Smrg
499063847c39Smrg	  if test -n "$exclude_expsyms"; then
499163847c39Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
499263847c39Smrg	    $MV "$nlist"T "$nlist"
499363847c39Smrg	  fi
499476888252Smrg
499563847c39Smrg	  # Try sorting and uniquifying the output.
499663847c39Smrg	  if $GREP -v "^: " < "$nlist" |
499763847c39Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
499863847c39Smrg		sort -k 3
499963847c39Smrg	      else
500063847c39Smrg		sort +2
500163847c39Smrg	      fi |
500263847c39Smrg	      uniq > "$nlist"S; then
500363847c39Smrg	    :
500463847c39Smrg	  else
500563847c39Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
500663847c39Smrg	  fi
500776888252Smrg
500863847c39Smrg	  if test -f "$nlist"S; then
500963847c39Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
501063847c39Smrg	  else
501163847c39Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
501263847c39Smrg	  fi
501376888252Smrg
50140814a2baSmrg	  func_show_eval '$RM "${nlist}I"'
50150814a2baSmrg	  if test -n "$global_symbol_to_import"; then
50160814a2baSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
50170814a2baSmrg	  fi
50180814a2baSmrg
501963847c39Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
502063847c39Smrg
502163847c39Smrg/* The mapping between symbol names and symbols.  */
502263847c39Smrgtypedef struct {
502363847c39Smrg  const char *name;
502463847c39Smrg  void *address;
502563847c39Smrg} lt_dlsymlist;
502663847c39Smrgextern LT_DLSYM_CONST lt_dlsymlist
50270814a2baSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
50280814a2baSmrg"
50290814a2baSmrg
50300814a2baSmrg	  if test -s "$nlist"I; then
50310814a2baSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50320814a2baSmrgstatic void lt_syminit(void)
50330814a2baSmrg{
50340814a2baSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
50350814a2baSmrg  for (; symbol->name; ++symbol)
50360814a2baSmrg    {"
50370814a2baSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
50380814a2baSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50390814a2baSmrg    }
50400814a2baSmrg}"
50410814a2baSmrg	  fi
50420814a2baSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
504363847c39SmrgLT_DLSYM_CONST lt_dlsymlist
504463847c39Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
50450814a2baSmrg{ {\"$my_originator\", (void *) 0},"
50460814a2baSmrg
50470814a2baSmrg	  if test -s "$nlist"I; then
50480814a2baSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50490814a2baSmrg  {\"@INIT@\", (void *) &lt_syminit},"
50500814a2baSmrg	  fi
505163847c39Smrg
505263847c39Smrg	  case $need_lib_prefix in
505363847c39Smrg	  no)
505463847c39Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
505586dafe34Smrg	    ;;
5056d8556812Smrg	  *)
505763847c39Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058d8556812Smrg	    ;;
5059d8556812Smrg	  esac
506063847c39Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
506163847c39Smrg  {0, (void *) 0}
506263847c39Smrg};
506376888252Smrg
506463847c39Smrg/* This works around a problem in FreeBSD linker */
506563847c39Smrg#ifdef FREEBSD_WORKAROUND
506663847c39Smrgstatic const void *lt_preloaded_setup() {
506763847c39Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
506863847c39Smrg}
506963847c39Smrg#endif
507076888252Smrg
507163847c39Smrg#ifdef __cplusplus
507263847c39Smrg}
507363847c39Smrg#endif\
507463847c39Smrg"
507563847c39Smrg	} # !$opt_dry_run
507676888252Smrg
507763847c39Smrg	pic_flag_for_symtable=
507863847c39Smrg	case "$compile_command " in
507963847c39Smrg	*" -static "*) ;;
508063847c39Smrg	*)
508163847c39Smrg	  case $host in
508263847c39Smrg	  # compiling the symbol table file with pic_flag works around
508363847c39Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
508463847c39Smrg	  # linked before any other PIC object.  But we must not use
508563847c39Smrg	  # pic_flag when linking with -static.  The problem exists in
508663847c39Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
508763847c39Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
508863847c39Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
508963847c39Smrg	  *-*-hpux*)
509063847c39Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
509163847c39Smrg	  *)
50920814a2baSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
509363847c39Smrg	    ;;
509463847c39Smrg	  esac
509563847c39Smrg	  ;;
509663847c39Smrg	esac
509763847c39Smrg	symtab_cflags=
509863847c39Smrg	for arg in $LTCFLAGS; do
509963847c39Smrg	  case $arg in
510063847c39Smrg	  -pie | -fpie | -fPIE) ;;
510163847c39Smrg	  *) func_append symtab_cflags " $arg" ;;
5102d8556812Smrg	  esac
5103d8556812Smrg	done
510476888252Smrg
510563847c39Smrg	# Now compile the dynamic symbol file.
510663847c39Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
510776888252Smrg
510863847c39Smrg	# Clean up the generated files.
51090814a2baSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
511076888252Smrg
511163847c39Smrg	# Transform the symbol file into the correct name.
51120814a2baSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
511363847c39Smrg	case $host in
511463847c39Smrg	*cygwin* | *mingw* | *cegcc* )
511563847c39Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
511663847c39Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511763847c39Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511863847c39Smrg	  else
511963847c39Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512063847c39Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512163847c39Smrg	  fi
512263847c39Smrg	  ;;
512363847c39Smrg	*)
512463847c39Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512563847c39Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512663847c39Smrg	  ;;
512763847c39Smrg	esac
512863847c39Smrg	;;
512963847c39Smrg      *)
51300814a2baSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
513163847c39Smrg	;;
513263847c39Smrg      esac
513363847c39Smrg    else
513463847c39Smrg      # We keep going just in case the user didn't refer to
513563847c39Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
513663847c39Smrg      # really was required.
513776888252Smrg
513863847c39Smrg      # Nullify the symbol file.
513963847c39Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
514063847c39Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
514163847c39Smrg    fi
514263847c39Smrg}
514376888252Smrg
51440814a2baSmrg# func_cygming_gnu_implib_p ARG
51450814a2baSmrg# This predicate returns with zero status (TRUE) if
51460814a2baSmrg# ARG is a GNU/binutils-style import library. Returns
51470814a2baSmrg# with nonzero status (FALSE) otherwise.
51480814a2baSmrgfunc_cygming_gnu_implib_p ()
51490814a2baSmrg{
51500814a2baSmrg  $debug_cmd
51510814a2baSmrg
51520814a2baSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51530814a2baSmrg  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)$'`
51540814a2baSmrg  test -n "$func_cygming_gnu_implib_tmp"
51550814a2baSmrg}
51560814a2baSmrg
51570814a2baSmrg# func_cygming_ms_implib_p ARG
51580814a2baSmrg# This predicate returns with zero status (TRUE) if
51590814a2baSmrg# ARG is an MS-style import library. Returns
51600814a2baSmrg# with nonzero status (FALSE) otherwise.
51610814a2baSmrgfunc_cygming_ms_implib_p ()
51620814a2baSmrg{
51630814a2baSmrg  $debug_cmd
51640814a2baSmrg
51650814a2baSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51660814a2baSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
51670814a2baSmrg  test -n "$func_cygming_ms_implib_tmp"
51680814a2baSmrg}
51690814a2baSmrg
517063847c39Smrg# func_win32_libid arg
517163847c39Smrg# return the library type of file 'arg'
517263847c39Smrg#
517363847c39Smrg# Need a lot of goo to handle *both* DLLs and import libs
517463847c39Smrg# Has to be a shell function in order to 'eat' the argument
517563847c39Smrg# that is supplied when $file_magic_command is called.
517663847c39Smrg# Despite the name, also deal with 64 bit binaries.
517763847c39Smrgfunc_win32_libid ()
517863847c39Smrg{
51790814a2baSmrg  $debug_cmd
51800814a2baSmrg
51810814a2baSmrg  win32_libid_type=unknown
518263847c39Smrg  win32_fileres=`file -L $1 2>/dev/null`
518363847c39Smrg  case $win32_fileres in
518463847c39Smrg  *ar\ archive\ import\ library*) # definitely import
518563847c39Smrg    win32_libid_type="x86 archive import"
518663847c39Smrg    ;;
518763847c39Smrg  *ar\ archive*) # could be an import, or static
518863847c39Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
518963847c39Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
519063847c39Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
51910814a2baSmrg      case $nm_interface in
51920814a2baSmrg      "MS dumpbin")
51930814a2baSmrg	if func_cygming_ms_implib_p "$1" ||
51940814a2baSmrg	   func_cygming_gnu_implib_p "$1"
51950814a2baSmrg	then
51960814a2baSmrg	  win32_nmres=import
51970814a2baSmrg	else
51980814a2baSmrg	  win32_nmres=
51990814a2baSmrg	fi
52000814a2baSmrg	;;
52010814a2baSmrg      *)
52020814a2baSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
52030814a2baSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
52040814a2baSmrg	  $SED -n -e '
520563847c39Smrg	    1,100{
520663847c39Smrg		/ I /{
52070814a2baSmrg		    s|.*|import|
520863847c39Smrg		    p
520963847c39Smrg		    q
521063847c39Smrg		}
521163847c39Smrg	    }'`
52120814a2baSmrg	;;
52130814a2baSmrg      esac
521463847c39Smrg      case $win32_nmres in
521563847c39Smrg      import*)  win32_libid_type="x86 archive import";;
521663847c39Smrg      *)        win32_libid_type="x86 archive static";;
521763847c39Smrg      esac
521863847c39Smrg    fi
521963847c39Smrg    ;;
522063847c39Smrg  *DLL*)
522163847c39Smrg    win32_libid_type="x86 DLL"
522263847c39Smrg    ;;
522363847c39Smrg  *executable*) # but shell scripts are "executable" too...
522463847c39Smrg    case $win32_fileres in
522563847c39Smrg    *MS\ Windows\ PE\ Intel*)
522663847c39Smrg      win32_libid_type="x86 DLL"
522763847c39Smrg      ;;
522863847c39Smrg    esac
522963847c39Smrg    ;;
523063847c39Smrg  esac
523163847c39Smrg  $ECHO "$win32_libid_type"
523263847c39Smrg}
523363847c39Smrg
523463847c39Smrg# func_cygming_dll_for_implib ARG
523563847c39Smrg#
523663847c39Smrg# Platform-specific function to extract the
523763847c39Smrg# name of the DLL associated with the specified
523863847c39Smrg# import library ARG.
523963847c39Smrg# Invoked by eval'ing the libtool variable
524063847c39Smrg#    $sharedlib_from_linklib_cmd
524163847c39Smrg# Result is available in the variable
524263847c39Smrg#    $sharedlib_from_linklib_result
524363847c39Smrgfunc_cygming_dll_for_implib ()
524463847c39Smrg{
52450814a2baSmrg  $debug_cmd
52460814a2baSmrg
524763847c39Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
524863847c39Smrg}
524963847c39Smrg
525063847c39Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
525163847c39Smrg#
525263847c39Smrg# The is the core of a fallback implementation of a
525363847c39Smrg# platform-specific function to extract the name of the
525463847c39Smrg# DLL associated with the specified import library LIBNAME.
525563847c39Smrg#
525663847c39Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
525763847c39Smrg# on the platform and compiler that created the implib.
525863847c39Smrg#
525963847c39Smrg# Echos the name of the DLL associated with the
526063847c39Smrg# specified import library.
526163847c39Smrgfunc_cygming_dll_for_implib_fallback_core ()
526263847c39Smrg{
52630814a2baSmrg  $debug_cmd
52640814a2baSmrg
526563847c39Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
526663847c39Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
526763847c39Smrg    $SED '/^Contents of section '"$match_literal"':/{
526863847c39Smrg      # Place marker at beginning of archive member dllname section
526963847c39Smrg      s/.*/====MARK====/
527063847c39Smrg      p
527163847c39Smrg      d
527263847c39Smrg    }
527363847c39Smrg    # These lines can sometimes be longer than 43 characters, but
527463847c39Smrg    # are always uninteresting
527563847c39Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
527663847c39Smrg    /^In archive [^:]*:/d
527763847c39Smrg    # Ensure marker is printed
527863847c39Smrg    /^====MARK====/p
527963847c39Smrg    # Remove all lines with less than 43 characters
528063847c39Smrg    /^.\{43\}/!d
528163847c39Smrg    # From remaining lines, remove first 43 characters
528263847c39Smrg    s/^.\{43\}//' |
528363847c39Smrg    $SED -n '
528463847c39Smrg      # Join marker and all lines until next marker into a single line
528563847c39Smrg      /^====MARK====/ b para
528663847c39Smrg      H
528763847c39Smrg      $ b para
528863847c39Smrg      b
528963847c39Smrg      :para
529063847c39Smrg      x
529163847c39Smrg      s/\n//g
529263847c39Smrg      # Remove the marker
529363847c39Smrg      s/^====MARK====//
529463847c39Smrg      # Remove trailing dots and whitespace
529563847c39Smrg      s/[\. \t]*$//
529663847c39Smrg      # Print
529763847c39Smrg      /./p' |
529863847c39Smrg    # we now have a list, one entry per line, of the stringified
529963847c39Smrg    # contents of the appropriate section of all members of the
53000814a2baSmrg    # archive that possess that section. Heuristic: eliminate
53010814a2baSmrg    # all those that have a first or second character that is
530263847c39Smrg    # a '.' (that is, objdump's representation of an unprintable
530363847c39Smrg    # character.) This should work for all archives with less than
530463847c39Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
530563847c39Smrg    # begins with a literal '.' or a single character followed by
530663847c39Smrg    # a '.'.
530763847c39Smrg    #
530863847c39Smrg    # Of those that remain, print the first one.
530963847c39Smrg    $SED -e '/^\./d;/^.\./d;q'
531063847c39Smrg}
531163847c39Smrg
531263847c39Smrg# func_cygming_dll_for_implib_fallback ARG
531363847c39Smrg# Platform-specific function to extract the
531463847c39Smrg# name of the DLL associated with the specified
531563847c39Smrg# import library ARG.
531663847c39Smrg#
531763847c39Smrg# This fallback implementation is for use when $DLLTOOL
531863847c39Smrg# does not support the --identify-strict option.
531963847c39Smrg# Invoked by eval'ing the libtool variable
532063847c39Smrg#    $sharedlib_from_linklib_cmd
532163847c39Smrg# Result is available in the variable
532263847c39Smrg#    $sharedlib_from_linklib_result
532363847c39Smrgfunc_cygming_dll_for_implib_fallback ()
532463847c39Smrg{
53250814a2baSmrg  $debug_cmd
53260814a2baSmrg
53270814a2baSmrg  if func_cygming_gnu_implib_p "$1"; then
532863847c39Smrg    # binutils import library
532963847c39Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
53300814a2baSmrg  elif func_cygming_ms_implib_p "$1"; then
533163847c39Smrg    # ms-generated import library
533263847c39Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
533363847c39Smrg  else
533463847c39Smrg    # unknown
53350814a2baSmrg    sharedlib_from_linklib_result=
533663847c39Smrg  fi
533763847c39Smrg}
533863847c39Smrg
533963847c39Smrg
534063847c39Smrg# func_extract_an_archive dir oldlib
534163847c39Smrgfunc_extract_an_archive ()
534263847c39Smrg{
53430814a2baSmrg    $debug_cmd
53440814a2baSmrg
53450814a2baSmrg    f_ex_an_ar_dir=$1; shift
53460814a2baSmrg    f_ex_an_ar_oldlib=$1
53470814a2baSmrg    if test yes = "$lock_old_archive_extraction"; then
534863847c39Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534963847c39Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
535063847c39Smrg	func_echo "Waiting for $lockfile to be removed"
535163847c39Smrg	sleep 2
5352d8556812Smrg      done
535363847c39Smrg    fi
535463847c39Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
535563847c39Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
53560814a2baSmrg    if test yes = "$lock_old_archive_extraction"; then
535763847c39Smrg      $opt_dry_run || rm -f "$lockfile"
535863847c39Smrg    fi
535963847c39Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
536063847c39Smrg     :
536163847c39Smrg    else
536263847c39Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
536363847c39Smrg    fi
536463847c39Smrg}
536576888252Smrg
536663847c39Smrg
536763847c39Smrg# func_extract_archives gentop oldlib ...
536863847c39Smrgfunc_extract_archives ()
536963847c39Smrg{
53700814a2baSmrg    $debug_cmd
53710814a2baSmrg
53720814a2baSmrg    my_gentop=$1; shift
537363847c39Smrg    my_oldlibs=${1+"$@"}
53740814a2baSmrg    my_oldobjs=
53750814a2baSmrg    my_xlib=
53760814a2baSmrg    my_xabs=
53770814a2baSmrg    my_xdir=
537863847c39Smrg
537963847c39Smrg    for my_xlib in $my_oldlibs; do
538063847c39Smrg      # Extract the objects.
538163847c39Smrg      case $my_xlib in
53820814a2baSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
538363847c39Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
538463847c39Smrg      esac
538563847c39Smrg      func_basename "$my_xlib"
53860814a2baSmrg      my_xlib=$func_basename_result
538763847c39Smrg      my_xlib_u=$my_xlib
538863847c39Smrg      while :; do
538963847c39Smrg        case " $extracted_archives " in
539063847c39Smrg	*" $my_xlib_u "*)
539163847c39Smrg	  func_arith $extracted_serial + 1
539263847c39Smrg	  extracted_serial=$func_arith_result
539363847c39Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
539463847c39Smrg	*) break ;;
5395d8556812Smrg	esac
5396d8556812Smrg      done
539763847c39Smrg      extracted_archives="$extracted_archives $my_xlib_u"
53980814a2baSmrg      my_xdir=$my_gentop/$my_xlib_u
539976888252Smrg
540063847c39Smrg      func_mkdir_p "$my_xdir"
540176888252Smrg
540263847c39Smrg      case $host in
540363847c39Smrg      *-darwin*)
540463847c39Smrg	func_verbose "Extracting $my_xabs"
540563847c39Smrg	# Do not bother doing anything if just a dry run
540663847c39Smrg	$opt_dry_run || {
540763847c39Smrg	  darwin_orig_dir=`pwd`
540863847c39Smrg	  cd $my_xdir || exit $?
540963847c39Smrg	  darwin_archive=$my_xabs
541063847c39Smrg	  darwin_curdir=`pwd`
54110814a2baSmrg	  func_basename "$darwin_archive"
54120814a2baSmrg	  darwin_base_archive=$func_basename_result
541363847c39Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
541463847c39Smrg	  if test -n "$darwin_arches"; then
541563847c39Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
541663847c39Smrg	    darwin_arch=
541763847c39Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
54180814a2baSmrg	    for darwin_arch in  $darwin_arches; do
54190814a2baSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
54200814a2baSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
54210814a2baSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
54220814a2baSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
542363847c39Smrg	      cd "$darwin_curdir"
54240814a2baSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
542563847c39Smrg	    done # $darwin_arches
542663847c39Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
54270814a2baSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
542863847c39Smrg	    darwin_file=
542963847c39Smrg	    darwin_files=
543063847c39Smrg	    for darwin_file in $darwin_filelist; do
543163847c39Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
543263847c39Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
543363847c39Smrg	    done # $darwin_filelist
543463847c39Smrg	    $RM -rf unfat-$$
543563847c39Smrg	    cd "$darwin_orig_dir"
5436d8556812Smrg	  else
543763847c39Smrg	    cd $darwin_orig_dir
543863847c39Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
543963847c39Smrg	  fi # $darwin_arches
544063847c39Smrg	} # !$opt_dry_run
544163847c39Smrg	;;
544263847c39Smrg      *)
544363847c39Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
544463847c39Smrg	;;
544563847c39Smrg      esac
544663847c39Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
544763847c39Smrg    done
544876888252Smrg
54490814a2baSmrg    func_extract_archives_result=$my_oldobjs
545063847c39Smrg}
545176888252Smrg
545276888252Smrg
545363847c39Smrg# func_emit_wrapper [arg=no]
545463847c39Smrg#
545563847c39Smrg# Emit a libtool wrapper script on stdout.
545663847c39Smrg# Don't directly open a file because we may want to
545763847c39Smrg# incorporate the script contents within a cygwin/mingw
545863847c39Smrg# wrapper executable.  Must ONLY be called from within
545963847c39Smrg# func_mode_link because it depends on a number of variables
546063847c39Smrg# set therein.
546163847c39Smrg#
546263847c39Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
546363847c39Smrg# variable will take.  If 'yes', then the emitted script
54640814a2baSmrg# will assume that the directory where it is stored is
546563847c39Smrg# the $objdir directory.  This is a cygwin/mingw-specific
546663847c39Smrg# behavior.
546763847c39Smrgfunc_emit_wrapper ()
546863847c39Smrg{
546963847c39Smrg	func_emit_wrapper_arg1=${1-no}
547076888252Smrg
547163847c39Smrg	$ECHO "\
547263847c39Smrg#! $SHELL
547376888252Smrg
547463847c39Smrg# $output - temporary wrapper script for $objdir/$outputname
54750814a2baSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
547663847c39Smrg#
547763847c39Smrg# The $output program cannot be directly executed until all the libtool
547863847c39Smrg# libraries that it depends on are installed.
547963847c39Smrg#
548063847c39Smrg# This wrapper script should never be moved out of the build directory.
548163847c39Smrg# If it is, it will not operate correctly.
548276888252Smrg
548363847c39Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
548463847c39Smrg# metacharacters that are still active within double-quoted strings.
548563847c39Smrgsed_quote_subst='$sed_quote_subst'
548676888252Smrg
548763847c39Smrg# Be Bourne compatible
548863847c39Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
548963847c39Smrg  emulate sh
549063847c39Smrg  NULLCMD=:
549163847c39Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
549263847c39Smrg  # is contrary to our usage.  Disable this feature.
549363847c39Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
549463847c39Smrg  setopt NO_GLOB_SUBST
549563847c39Smrgelse
549663847c39Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
549763847c39Smrgfi
549863847c39SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
549963847c39SmrgDUALCASE=1; export DUALCASE # for MKS sh
550076888252Smrg
550163847c39Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
550263847c39Smrg# if CDPATH is set.
550363847c39Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
550476888252Smrg
550563847c39Smrgrelink_command=\"$relink_command\"
550676888252Smrg
550763847c39Smrg# This environment variable determines our operation mode.
550863847c39Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
550963847c39Smrg  # install mode needs the following variables:
551063847c39Smrg  generated_by_libtool_version='$macro_version'
551163847c39Smrg  notinst_deplibs='$notinst_deplibs'
551263847c39Smrgelse
551363847c39Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
551463847c39Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
551563847c39Smrg    file=\"\$0\""
551676888252Smrg
55170814a2baSmrg    func_quote_arg pretty "$ECHO"
55180814a2baSmrg    qECHO=$func_quote_arg_result
551963847c39Smrg    $ECHO "\
552076888252Smrg
552163847c39Smrg# A function that is used when there is no print builtin or printf.
552263847c39Smrgfunc_fallback_echo ()
552363847c39Smrg{
552463847c39Smrg  eval 'cat <<_LTECHO_EOF
552563847c39Smrg\$1
552663847c39Smrg_LTECHO_EOF'
552763847c39Smrg}
55280814a2baSmrg    ECHO=$qECHO
552963847c39Smrg  fi
553076888252Smrg
553163847c39Smrg# Very basic option parsing. These options are (a) specific to
553263847c39Smrg# the libtool wrapper, (b) are identical between the wrapper
55330814a2baSmrg# /script/ and the wrapper /executable/ that is used only on
553463847c39Smrg# windows platforms, and (c) all begin with the string "--lt-"
55350814a2baSmrg# (application programs are unlikely to have options that match
553663847c39Smrg# this pattern).
553763847c39Smrg#
553863847c39Smrg# There are only two supported options: --lt-debug and
553963847c39Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
554063847c39Smrg#
554163847c39Smrg# The first argument to this parsing function should be the
554263847c39Smrg# script's $0 value, followed by "$@".
554363847c39Smrglt_option_debug=
554463847c39Smrgfunc_parse_lt_options ()
554563847c39Smrg{
554663847c39Smrg  lt_script_arg0=\$0
554763847c39Smrg  shift
554863847c39Smrg  for lt_opt
554963847c39Smrg  do
555063847c39Smrg    case \"\$lt_opt\" in
555163847c39Smrg    --lt-debug) lt_option_debug=1 ;;
555263847c39Smrg    --lt-dump-script)
555363847c39Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
555463847c39Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
555563847c39Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
555663847c39Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555763847c39Smrg        exit 0
555863847c39Smrg      ;;
555963847c39Smrg    --lt-*)
556063847c39Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
556163847c39Smrg        exit 1
556263847c39Smrg      ;;
556363847c39Smrg    esac
556463847c39Smrg  done
556576888252Smrg
556663847c39Smrg  # Print the debug banner immediately:
556763847c39Smrg  if test -n \"\$lt_option_debug\"; then
55680814a2baSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556963847c39Smrg  fi
557063847c39Smrg}
557176888252Smrg
557263847c39Smrg# Used when --lt-debug. Prints its arguments to stdout
557363847c39Smrg# (redirection is the responsibility of the caller)
557463847c39Smrgfunc_lt_dump_args ()
557563847c39Smrg{
557663847c39Smrg  lt_dump_args_N=1;
557763847c39Smrg  for lt_arg
557863847c39Smrg  do
55790814a2baSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
558063847c39Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
558163847c39Smrg  done
558263847c39Smrg}
558376888252Smrg
558463847c39Smrg# Core function for launching the target application
558563847c39Smrgfunc_exec_program_core ()
558663847c39Smrg{
558763847c39Smrg"
558863847c39Smrg  case $host in
558963847c39Smrg  # Backslashes separate directories on plain windows
559063847c39Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
559163847c39Smrg    $ECHO "\
559263847c39Smrg      if test -n \"\$lt_option_debug\"; then
55930814a2baSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
559463847c39Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
559563847c39Smrg      fi
559663847c39Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559763847c39Smrg"
559863847c39Smrg    ;;
559976888252Smrg
560063847c39Smrg  *)
560163847c39Smrg    $ECHO "\
560263847c39Smrg      if test -n \"\$lt_option_debug\"; then
56030814a2baSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
560463847c39Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
560563847c39Smrg      fi
560663847c39Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560763847c39Smrg"
560863847c39Smrg    ;;
560963847c39Smrg  esac
561063847c39Smrg  $ECHO "\
561163847c39Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
561263847c39Smrg      exit 1
561363847c39Smrg}
561476888252Smrg
561563847c39Smrg# A function to encapsulate launching the target application
561663847c39Smrg# Strips options in the --lt-* namespace from \$@ and
561763847c39Smrg# launches target application with the remaining arguments.
561863847c39Smrgfunc_exec_program ()
561963847c39Smrg{
562063847c39Smrg  case \" \$* \" in
562163847c39Smrg  *\\ --lt-*)
562263847c39Smrg    for lt_wr_arg
562363847c39Smrg    do
562463847c39Smrg      case \$lt_wr_arg in
562563847c39Smrg      --lt-*) ;;
562663847c39Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
562763847c39Smrg      esac
562863847c39Smrg      shift
562963847c39Smrg    done ;;
563063847c39Smrg  esac
563163847c39Smrg  func_exec_program_core \${1+\"\$@\"}
563263847c39Smrg}
563376888252Smrg
563463847c39Smrg  # Parse options
563563847c39Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
563676888252Smrg
563763847c39Smrg  # Find the directory that this script lives in.
563863847c39Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
563963847c39Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
564076888252Smrg
564163847c39Smrg  # Follow symbolic links until we get to the real thisdir.
564263847c39Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
564363847c39Smrg  while test -n \"\$file\"; do
564463847c39Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
564576888252Smrg
564663847c39Smrg    # If there was a directory component, then change thisdir.
564763847c39Smrg    if test \"x\$destdir\" != \"x\$file\"; then
564863847c39Smrg      case \"\$destdir\" in
564963847c39Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
565063847c39Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
565163847c39Smrg      esac
565263847c39Smrg    fi
565376888252Smrg
565463847c39Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
565563847c39Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
565663847c39Smrg  done
565776888252Smrg
565863847c39Smrg  # Usually 'no', except on cygwin/mingw when embedded into
565963847c39Smrg  # the cwrapper.
566063847c39Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
566163847c39Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
566263847c39Smrg    # special case for '.'
566363847c39Smrg    if test \"\$thisdir\" = \".\"; then
566463847c39Smrg      thisdir=\`pwd\`
566563847c39Smrg    fi
566663847c39Smrg    # remove .libs from thisdir
566763847c39Smrg    case \"\$thisdir\" in
566863847c39Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
566963847c39Smrg    $objdir )   thisdir=. ;;
567063847c39Smrg    esac
567163847c39Smrg  fi
567276888252Smrg
567363847c39Smrg  # Try to get the absolute directory name.
567463847c39Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
567563847c39Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
567663847c39Smrg"
567776888252Smrg
56780814a2baSmrg	if test yes = "$fast_install"; then
567963847c39Smrg	  $ECHO "\
568063847c39Smrg  program=lt-'$outputname'$exeext
568163847c39Smrg  progdir=\"\$thisdir/$objdir\"
568276888252Smrg
568363847c39Smrg  if test ! -f \"\$progdir/\$program\" ||
56840814a2baSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
568563847c39Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
568676888252Smrg
568763847c39Smrg    file=\"\$\$-\$program\"
568876888252Smrg
568963847c39Smrg    if test ! -d \"\$progdir\"; then
569063847c39Smrg      $MKDIR \"\$progdir\"
569163847c39Smrg    else
569263847c39Smrg      $RM \"\$progdir/\$file\"
569363847c39Smrg    fi"
569476888252Smrg
569563847c39Smrg	  $ECHO "\
569676888252Smrg
569763847c39Smrg    # relink executable if necessary
569863847c39Smrg    if test -n \"\$relink_command\"; then
569963847c39Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
570063847c39Smrg      else
57010814a2baSmrg	\$ECHO \"\$relink_command_output\" >&2
570263847c39Smrg	$RM \"\$progdir/\$file\"
570363847c39Smrg	exit 1
570463847c39Smrg      fi
570563847c39Smrg    fi
5706d8556812Smrg
570763847c39Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
570863847c39Smrg    { $RM \"\$progdir/\$program\";
570963847c39Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
571063847c39Smrg    $RM \"\$progdir/\$file\"
571163847c39Smrg  fi"
571263847c39Smrg	else
571363847c39Smrg	  $ECHO "\
571463847c39Smrg  program='$outputname'
571563847c39Smrg  progdir=\"\$thisdir/$objdir\"
571663847c39Smrg"
571763847c39Smrg	fi
5718d8556812Smrg
571963847c39Smrg	$ECHO "\
5720d8556812Smrg
572163847c39Smrg  if test -f \"\$progdir/\$program\"; then"
572263847c39Smrg
572363847c39Smrg	# fixup the dll searchpath if we need to.
572463847c39Smrg	#
572563847c39Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
572663847c39Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
572763847c39Smrg	# libraries must come first.
572863847c39Smrg	if test -n "$dllsearchpath"; then
572963847c39Smrg	  $ECHO "\
573063847c39Smrg    # Add the dll search path components to the executable PATH
573163847c39Smrg    PATH=$dllsearchpath:\$PATH
573263847c39Smrg"
5733d8556812Smrg	fi
5734d8556812Smrg
573563847c39Smrg	# Export our shlibpath_var if we have one.
57360814a2baSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
573763847c39Smrg	  $ECHO "\
573863847c39Smrg    # Add our own library path to $shlibpath_var
573963847c39Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740d8556812Smrg
574163847c39Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
574263847c39Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
574363847c39Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
574463847c39Smrg
574563847c39Smrg    export $shlibpath_var
574663847c39Smrg"
5747d8556812Smrg	fi
574876888252Smrg
574963847c39Smrg	$ECHO "\
575063847c39Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
575163847c39Smrg      # Run the actual program with our arguments.
575263847c39Smrg      func_exec_program \${1+\"\$@\"}
575363847c39Smrg    fi
575463847c39Smrg  else
575563847c39Smrg    # The program doesn't exist.
57560814a2baSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
575763847c39Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575863847c39Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
575963847c39Smrg    exit 1
576063847c39Smrg  fi
576163847c39Smrgfi\
576263847c39Smrg"
576363847c39Smrg}
576476888252Smrg
576576888252Smrg
576663847c39Smrg# func_emit_cwrapperexe_src
576763847c39Smrg# emit the source code for a wrapper executable on stdout
576863847c39Smrg# Must ONLY be called from within func_mode_link because
576963847c39Smrg# it depends on a number of variable set therein.
577063847c39Smrgfunc_emit_cwrapperexe_src ()
577163847c39Smrg{
577263847c39Smrg	cat <<EOF
5773d8556812Smrg
577463847c39Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
57750814a2baSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776d8556812Smrg
577763847c39Smrg   The $output program cannot be directly executed until all the libtool
577863847c39Smrg   libraries that it depends on are installed.
5779d8556812Smrg
578063847c39Smrg   This wrapper executable should never be moved out of the build directory.
578163847c39Smrg   If it is, it will not operate correctly.
578263847c39Smrg*/
578363847c39SmrgEOF
578463847c39Smrg	    cat <<"EOF"
578563847c39Smrg#ifdef _MSC_VER
578663847c39Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578763847c39Smrg#endif
578863847c39Smrg#include <stdio.h>
578963847c39Smrg#include <stdlib.h>
579063847c39Smrg#ifdef _MSC_VER
579163847c39Smrg# include <direct.h>
579263847c39Smrg# include <process.h>
579363847c39Smrg# include <io.h>
579463847c39Smrg#else
579563847c39Smrg# include <unistd.h>
579663847c39Smrg# include <stdint.h>
579763847c39Smrg# ifdef __CYGWIN__
579863847c39Smrg#  include <io.h>
579963847c39Smrg# endif
580063847c39Smrg#endif
580163847c39Smrg#include <malloc.h>
580263847c39Smrg#include <stdarg.h>
580363847c39Smrg#include <assert.h>
580463847c39Smrg#include <string.h>
580563847c39Smrg#include <ctype.h>
580663847c39Smrg#include <errno.h>
580763847c39Smrg#include <fcntl.h>
580863847c39Smrg#include <sys/stat.h>
5809d8556812Smrg
58100814a2baSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
58110814a2baSmrg
581263847c39Smrg/* declarations of non-ANSI functions */
58130814a2baSmrg#if defined __MINGW32__
581463847c39Smrg# ifdef __STRICT_ANSI__
581563847c39Smrgint _putenv (const char *);
581663847c39Smrg# endif
58170814a2baSmrg#elif defined __CYGWIN__
581863847c39Smrg# ifdef __STRICT_ANSI__
581963847c39Smrgchar *realpath (const char *, char *);
582063847c39Smrgint putenv (char *);
582163847c39Smrgint setenv (const char *, const char *, int);
582263847c39Smrg# endif
58230814a2baSmrg/* #elif defined other_platform || defined ... */
582463847c39Smrg#endif
582576888252Smrg
582663847c39Smrg/* portability defines, excluding path handling macros */
58270814a2baSmrg#if defined _MSC_VER
582863847c39Smrg# define setmode _setmode
582963847c39Smrg# define stat    _stat
583063847c39Smrg# define chmod   _chmod
583163847c39Smrg# define getcwd  _getcwd
583263847c39Smrg# define putenv  _putenv
583363847c39Smrg# define S_IXUSR _S_IEXEC
58340814a2baSmrg#elif defined __MINGW32__
583563847c39Smrg# define setmode _setmode
583663847c39Smrg# define stat    _stat
583763847c39Smrg# define chmod   _chmod
583863847c39Smrg# define getcwd  _getcwd
583963847c39Smrg# define putenv  _putenv
58400814a2baSmrg#elif defined __CYGWIN__
584163847c39Smrg# define HAVE_SETENV
584263847c39Smrg# define FOPEN_WB "wb"
58430814a2baSmrg/* #elif defined other platforms ... */
584463847c39Smrg#endif
584576888252Smrg
58460814a2baSmrg#if defined PATH_MAX
584763847c39Smrg# define LT_PATHMAX PATH_MAX
58480814a2baSmrg#elif defined MAXPATHLEN
584963847c39Smrg# define LT_PATHMAX MAXPATHLEN
585063847c39Smrg#else
585163847c39Smrg# define LT_PATHMAX 1024
585263847c39Smrg#endif
585376888252Smrg
585463847c39Smrg#ifndef S_IXOTH
585563847c39Smrg# define S_IXOTH 0
585663847c39Smrg#endif
585763847c39Smrg#ifndef S_IXGRP
585863847c39Smrg# define S_IXGRP 0
585963847c39Smrg#endif
586076888252Smrg
586163847c39Smrg/* path handling portability macros */
586263847c39Smrg#ifndef DIR_SEPARATOR
586363847c39Smrg# define DIR_SEPARATOR '/'
586463847c39Smrg# define PATH_SEPARATOR ':'
586563847c39Smrg#endif
586676888252Smrg
58670814a2baSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
58680814a2baSmrg  defined __OS2__
586963847c39Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
587063847c39Smrg# define FOPEN_WB "wb"
587163847c39Smrg# ifndef DIR_SEPARATOR_2
587263847c39Smrg#  define DIR_SEPARATOR_2 '\\'
587363847c39Smrg# endif
587463847c39Smrg# ifndef PATH_SEPARATOR_2
587563847c39Smrg#  define PATH_SEPARATOR_2 ';'
587663847c39Smrg# endif
587763847c39Smrg#endif
587876888252Smrg
587963847c39Smrg#ifndef DIR_SEPARATOR_2
588063847c39Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
588163847c39Smrg#else /* DIR_SEPARATOR_2 */
588263847c39Smrg# define IS_DIR_SEPARATOR(ch) \
588363847c39Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
588463847c39Smrg#endif /* DIR_SEPARATOR_2 */
588576888252Smrg
588663847c39Smrg#ifndef PATH_SEPARATOR_2
588763847c39Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
588863847c39Smrg#else /* PATH_SEPARATOR_2 */
588963847c39Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
589063847c39Smrg#endif /* PATH_SEPARATOR_2 */
589176888252Smrg
589263847c39Smrg#ifndef FOPEN_WB
589363847c39Smrg# define FOPEN_WB "w"
589463847c39Smrg#endif
589563847c39Smrg#ifndef _O_BINARY
589663847c39Smrg# define _O_BINARY 0
589763847c39Smrg#endif
589876888252Smrg
589963847c39Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
590063847c39Smrg#define XFREE(stale) do { \
59010814a2baSmrg  if (stale) { free (stale); stale = 0; } \
590263847c39Smrg} while (0)
590376888252Smrg
59040814a2baSmrg#if defined LT_DEBUGWRAPPER
590563847c39Smrgstatic int lt_debug = 1;
590663847c39Smrg#else
590763847c39Smrgstatic int lt_debug = 0;
590863847c39Smrg#endif
590976888252Smrg
591063847c39Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
591163847c39Smrg
591263847c39Smrgvoid *xmalloc (size_t num);
591363847c39Smrgchar *xstrdup (const char *string);
591463847c39Smrgconst char *base_name (const char *name);
591563847c39Smrgchar *find_executable (const char *wrapper);
591663847c39Smrgchar *chase_symlinks (const char *pathspec);
591763847c39Smrgint make_executable (const char *path);
591863847c39Smrgint check_executable (const char *path);
591963847c39Smrgchar *strendzap (char *str, const char *pat);
592063847c39Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
592163847c39Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
592263847c39Smrgstatic const char *nonnull (const char *s);
592363847c39Smrgstatic const char *nonempty (const char *s);
592463847c39Smrgvoid lt_setenv (const char *name, const char *value);
592563847c39Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
592663847c39Smrgvoid lt_update_exe_path (const char *name, const char *value);
592763847c39Smrgvoid lt_update_lib_path (const char *name, const char *value);
592863847c39Smrgchar **prepare_spawn (char **argv);
592963847c39Smrgvoid lt_dump_script (FILE *f);
593063847c39SmrgEOF
593176888252Smrg
593263847c39Smrg	    cat <<EOF
59330814a2baSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
59340814a2baSmrg# define externally_visible volatile
59350814a2baSmrg#else
59360814a2baSmrg# define externally_visible __attribute__((externally_visible)) volatile
59370814a2baSmrg#endif
59380814a2baSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
593963847c39Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
594063847c39SmrgEOF
594176888252Smrg
59420814a2baSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
594363847c39Smrg              func_to_host_path "$temp_rpath"
594463847c39Smrg	      cat <<EOF
594563847c39Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
594663847c39SmrgEOF
594763847c39Smrg	    else
594863847c39Smrg	      cat <<"EOF"
594963847c39Smrgconst char * LIB_PATH_VALUE   = "";
595063847c39SmrgEOF
595163847c39Smrg	    fi
595276888252Smrg
595363847c39Smrg	    if test -n "$dllsearchpath"; then
595463847c39Smrg              func_to_host_path "$dllsearchpath:"
595563847c39Smrg	      cat <<EOF
595663847c39Smrgconst char * EXE_PATH_VARNAME = "PATH";
595763847c39Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
595863847c39SmrgEOF
595963847c39Smrg	    else
596063847c39Smrg	      cat <<"EOF"
596163847c39Smrgconst char * EXE_PATH_VARNAME = "";
596263847c39Smrgconst char * EXE_PATH_VALUE   = "";
596363847c39SmrgEOF
596463847c39Smrg	    fi
596576888252Smrg
59660814a2baSmrg	    if test yes = "$fast_install"; then
596763847c39Smrg	      cat <<EOF
596863847c39Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
596963847c39SmrgEOF
597063847c39Smrg	    else
597163847c39Smrg	      cat <<EOF
597263847c39Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
597363847c39SmrgEOF
597463847c39Smrg	    fi
597576888252Smrg
597676888252Smrg
597763847c39Smrg	    cat <<"EOF"
597876888252Smrg
597963847c39Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
598076888252Smrg
598163847c39Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
598263847c39Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
598363847c39Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
598476888252Smrg
598563847c39Smrgint
598663847c39Smrgmain (int argc, char *argv[])
598763847c39Smrg{
598863847c39Smrg  char **newargz;
598963847c39Smrg  int  newargc;
599063847c39Smrg  char *tmp_pathspec;
599163847c39Smrg  char *actual_cwrapper_path;
599263847c39Smrg  char *actual_cwrapper_name;
599363847c39Smrg  char *target_name;
599463847c39Smrg  char *lt_argv_zero;
59950814a2baSmrg  int rval = 127;
599663847c39Smrg
599763847c39Smrg  int i;
599876888252Smrg
599963847c39Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
60000814a2baSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
600176888252Smrg
600263847c39Smrg  /* very simple arg parsing; don't want to rely on getopt
600363847c39Smrg   * also, copy all non cwrapper options to newargz, except
600463847c39Smrg   * argz[0], which is handled differently
600563847c39Smrg   */
600663847c39Smrg  newargc=0;
600763847c39Smrg  for (i = 1; i < argc; i++)
600863847c39Smrg    {
60090814a2baSmrg      if (STREQ (argv[i], dumpscript_opt))
601063847c39Smrg	{
601163847c39SmrgEOF
60120814a2baSmrg	    case $host in
601363847c39Smrg	      *mingw* | *cygwin* )
601463847c39Smrg		# make stdout use "unix" line endings
601563847c39Smrg		echo "          setmode(1,_O_BINARY);"
601663847c39Smrg		;;
601763847c39Smrg	      esac
601876888252Smrg
601963847c39Smrg	    cat <<"EOF"
602063847c39Smrg	  lt_dump_script (stdout);
602163847c39Smrg	  return 0;
602263847c39Smrg	}
60230814a2baSmrg      if (STREQ (argv[i], debug_opt))
602463847c39Smrg	{
602563847c39Smrg          lt_debug = 1;
602663847c39Smrg          continue;
602763847c39Smrg	}
60280814a2baSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602963847c39Smrg        {
603063847c39Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
603163847c39Smrg             namespace, but it is not one of the ones we know about and
603263847c39Smrg             have already dealt with, above (inluding dump-script), then
603363847c39Smrg             report an error. Otherwise, targets might begin to believe
603463847c39Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
603563847c39Smrg             namespace. The first time any user complains about this, we'll
603663847c39Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603763847c39Smrg             or a configure.ac-settable value.
603863847c39Smrg           */
603963847c39Smrg          lt_fatal (__FILE__, __LINE__,
604063847c39Smrg		    "unrecognized %s option: '%s'",
604163847c39Smrg                    ltwrapper_option_prefix, argv[i]);
604263847c39Smrg        }
604363847c39Smrg      /* otherwise ... */
604463847c39Smrg      newargz[++newargc] = xstrdup (argv[i]);
604563847c39Smrg    }
604663847c39Smrg  newargz[++newargc] = NULL;
604776888252Smrg
604863847c39SmrgEOF
604963847c39Smrg	    cat <<EOF
605063847c39Smrg  /* The GNU banner must be the first non-error debug message */
60510814a2baSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
605263847c39SmrgEOF
605363847c39Smrg	    cat <<"EOF"
605463847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
605563847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
605663847c39Smrg
605763847c39Smrg  tmp_pathspec = find_executable (argv[0]);
605863847c39Smrg  if (tmp_pathspec == NULL)
605963847c39Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
606063847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
606163847c39Smrg                  "(main) found exe (before symlink chase) at: %s\n",
606263847c39Smrg		  tmp_pathspec);
606363847c39Smrg
606463847c39Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
606563847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
606663847c39Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606763847c39Smrg		  actual_cwrapper_path);
606863847c39Smrg  XFREE (tmp_pathspec);
606963847c39Smrg
607063847c39Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
607163847c39Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
607263847c39Smrg
607363847c39Smrg  /* wrapper name transforms */
607463847c39Smrg  strendzap (actual_cwrapper_name, ".exe");
607563847c39Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
607663847c39Smrg  XFREE (actual_cwrapper_name);
607763847c39Smrg  actual_cwrapper_name = tmp_pathspec;
607863847c39Smrg  tmp_pathspec = 0;
607963847c39Smrg
608063847c39Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
608163847c39Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
608263847c39Smrg  strendzap (target_name, ".exe");
608363847c39Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
608463847c39Smrg  XFREE (target_name);
608563847c39Smrg  target_name = tmp_pathspec;
608663847c39Smrg  tmp_pathspec = 0;
608763847c39Smrg
608863847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
608963847c39Smrg		  "(main) libtool target name: %s\n",
609063847c39Smrg		  target_name);
609163847c39SmrgEOF
609263847c39Smrg
609363847c39Smrg	    cat <<EOF
609463847c39Smrg  newargz[0] =
609563847c39Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
609663847c39Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
609763847c39Smrg  strcpy (newargz[0], actual_cwrapper_path);
609863847c39Smrg  strcat (newargz[0], "$objdir");
609963847c39Smrg  strcat (newargz[0], "/");
610063847c39SmrgEOF
610163847c39Smrg
610263847c39Smrg	    cat <<"EOF"
610363847c39Smrg  /* stop here, and copy so we don't have to do this twice */
610463847c39Smrg  tmp_pathspec = xstrdup (newargz[0]);
610563847c39Smrg
610663847c39Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
610763847c39Smrg  strcat (newargz[0], actual_cwrapper_name);
610863847c39Smrg
610963847c39Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
611063847c39Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
611163847c39Smrg  XFREE (tmp_pathspec);
611263847c39Smrg  tmp_pathspec = NULL;
611363847c39SmrgEOF
611463847c39Smrg
611563847c39Smrg	    case $host_os in
611663847c39Smrg	      mingw*)
611763847c39Smrg	    cat <<"EOF"
611863847c39Smrg  {
611963847c39Smrg    char* p;
612063847c39Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
612163847c39Smrg      {
612263847c39Smrg	*p = '/';
612363847c39Smrg      }
612463847c39Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
612563847c39Smrg      {
612663847c39Smrg	*p = '/';
612763847c39Smrg      }
612863847c39Smrg  }
612963847c39SmrgEOF
613063847c39Smrg	    ;;
613163847c39Smrg	    esac
613263847c39Smrg
613363847c39Smrg	    cat <<"EOF"
613463847c39Smrg  XFREE (target_name);
613563847c39Smrg  XFREE (actual_cwrapper_path);
613663847c39Smrg  XFREE (actual_cwrapper_name);
613763847c39Smrg
613863847c39Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
613963847c39Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
614063847c39Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
614163847c39Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
614263847c39Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
614363847c39Smrg     libraries must come first. */
614463847c39Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
614563847c39Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
614663847c39Smrg
614763847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614863847c39Smrg		  nonnull (lt_argv_zero));
614963847c39Smrg  for (i = 0; i < newargc; i++)
615063847c39Smrg    {
615163847c39Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
615263847c39Smrg		      i, nonnull (newargz[i]));
615363847c39Smrg    }
615463847c39Smrg
615563847c39SmrgEOF
615663847c39Smrg
615763847c39Smrg	    case $host_os in
615863847c39Smrg	      mingw*)
615963847c39Smrg		cat <<"EOF"
616063847c39Smrg  /* execv doesn't actually work on mingw as expected on unix */
616163847c39Smrg  newargz = prepare_spawn (newargz);
61620814a2baSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
616363847c39Smrg  if (rval == -1)
616463847c39Smrg    {
616563847c39Smrg      /* failed to start process */
616663847c39Smrg      lt_debugprintf (__FILE__, __LINE__,
616763847c39Smrg		      "(main) failed to launch target \"%s\": %s\n",
616863847c39Smrg		      lt_argv_zero, nonnull (strerror (errno)));
616963847c39Smrg      return 127;
617063847c39Smrg    }
617163847c39Smrg  return rval;
617263847c39SmrgEOF
6173d8556812Smrg		;;
6174d8556812Smrg	      *)
617563847c39Smrg		cat <<"EOF"
617663847c39Smrg  execv (lt_argv_zero, newargz);
617763847c39Smrg  return rval; /* =127, but avoids unused variable warning */
617863847c39SmrgEOF
6179d8556812Smrg		;;
618063847c39Smrg	    esac
618176888252Smrg
618263847c39Smrg	    cat <<"EOF"
618363847c39Smrg}
618476888252Smrg
618563847c39Smrgvoid *
618663847c39Smrgxmalloc (size_t num)
618763847c39Smrg{
618863847c39Smrg  void *p = (void *) malloc (num);
618963847c39Smrg  if (!p)
619063847c39Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
619176888252Smrg
619263847c39Smrg  return p;
619363847c39Smrg}
619476888252Smrg
619563847c39Smrgchar *
619663847c39Smrgxstrdup (const char *string)
619763847c39Smrg{
619863847c39Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
619963847c39Smrg			  string) : NULL;
620063847c39Smrg}
620176888252Smrg
620263847c39Smrgconst char *
620363847c39Smrgbase_name (const char *name)
620463847c39Smrg{
620563847c39Smrg  const char *base;
620676888252Smrg
62070814a2baSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
620863847c39Smrg  /* Skip over the disk name in MSDOS pathnames. */
620963847c39Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
621063847c39Smrg    name += 2;
6211d8556812Smrg#endif
621276888252Smrg
621363847c39Smrg  for (base = name; *name; name++)
621463847c39Smrg    if (IS_DIR_SEPARATOR (*name))
621563847c39Smrg      base = name + 1;
621663847c39Smrg  return base;
621763847c39Smrg}
621876888252Smrg
621963847c39Smrgint
622063847c39Smrgcheck_executable (const char *path)
622163847c39Smrg{
622263847c39Smrg  struct stat st;
622376888252Smrg
622463847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
622563847c39Smrg                  nonempty (path));
622663847c39Smrg  if ((!path) || (!*path))
622763847c39Smrg    return 0;
622876888252Smrg
622963847c39Smrg  if ((stat (path, &st) >= 0)
623063847c39Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
623163847c39Smrg    return 1;
623263847c39Smrg  else
623363847c39Smrg    return 0;
623463847c39Smrg}
623576888252Smrg
623663847c39Smrgint
623763847c39Smrgmake_executable (const char *path)
623863847c39Smrg{
623963847c39Smrg  int rval = 0;
624063847c39Smrg  struct stat st;
624176888252Smrg
624263847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
624363847c39Smrg                  nonempty (path));
624463847c39Smrg  if ((!path) || (!*path))
624563847c39Smrg    return 0;
624676888252Smrg
624763847c39Smrg  if (stat (path, &st) >= 0)
624863847c39Smrg    {
624963847c39Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
625063847c39Smrg    }
625163847c39Smrg  return rval;
625263847c39Smrg}
625376888252Smrg
625463847c39Smrg/* Searches for the full path of the wrapper.  Returns
625563847c39Smrg   newly allocated full path name if found, NULL otherwise
625663847c39Smrg   Does not chase symlinks, even on platforms that support them.
625763847c39Smrg*/
625863847c39Smrgchar *
625963847c39Smrgfind_executable (const char *wrapper)
626063847c39Smrg{
626163847c39Smrg  int has_slash = 0;
626263847c39Smrg  const char *p;
626363847c39Smrg  const char *p_next;
626463847c39Smrg  /* static buffer for getcwd */
626563847c39Smrg  char tmp[LT_PATHMAX + 1];
62660814a2baSmrg  size_t tmp_len;
626763847c39Smrg  char *concat_name;
626876888252Smrg
626963847c39Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
627063847c39Smrg                  nonempty (wrapper));
627176888252Smrg
627263847c39Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
627363847c39Smrg    return NULL;
627476888252Smrg
627563847c39Smrg  /* Absolute path? */
62760814a2baSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
627763847c39Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
627863847c39Smrg    {
627963847c39Smrg      concat_name = xstrdup (wrapper);
628063847c39Smrg      if (check_executable (concat_name))
628163847c39Smrg	return concat_name;
628263847c39Smrg      XFREE (concat_name);
628363847c39Smrg    }
628463847c39Smrg  else
628563847c39Smrg    {
628663847c39Smrg#endif
628763847c39Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
628863847c39Smrg	{
628963847c39Smrg	  concat_name = xstrdup (wrapper);
629063847c39Smrg	  if (check_executable (concat_name))
629163847c39Smrg	    return concat_name;
629263847c39Smrg	  XFREE (concat_name);
629363847c39Smrg	}
62940814a2baSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
629563847c39Smrg    }
629663847c39Smrg#endif
629776888252Smrg
629863847c39Smrg  for (p = wrapper; *p; p++)
629963847c39Smrg    if (*p == '/')
630063847c39Smrg      {
630163847c39Smrg	has_slash = 1;
630263847c39Smrg	break;
630363847c39Smrg      }
630463847c39Smrg  if (!has_slash)
630563847c39Smrg    {
630663847c39Smrg      /* no slashes; search PATH */
630763847c39Smrg      const char *path = getenv ("PATH");
630863847c39Smrg      if (path != NULL)
630963847c39Smrg	{
631063847c39Smrg	  for (p = path; *p; p = p_next)
631163847c39Smrg	    {
631263847c39Smrg	      const char *q;
631363847c39Smrg	      size_t p_len;
631463847c39Smrg	      for (q = p; *q; q++)
631563847c39Smrg		if (IS_PATH_SEPARATOR (*q))
631663847c39Smrg		  break;
63170814a2baSmrg	      p_len = (size_t) (q - p);
631863847c39Smrg	      p_next = (*q == '\0' ? q : q + 1);
631963847c39Smrg	      if (p_len == 0)
632063847c39Smrg		{
632163847c39Smrg		  /* empty path: current directory */
632263847c39Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
632363847c39Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
632463847c39Smrg                              nonnull (strerror (errno)));
632563847c39Smrg		  tmp_len = strlen (tmp);
632663847c39Smrg		  concat_name =
632763847c39Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
632863847c39Smrg		  memcpy (concat_name, tmp, tmp_len);
632963847c39Smrg		  concat_name[tmp_len] = '/';
633063847c39Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
633163847c39Smrg		}
633263847c39Smrg	      else
633363847c39Smrg		{
633463847c39Smrg		  concat_name =
633563847c39Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
633663847c39Smrg		  memcpy (concat_name, p, p_len);
633763847c39Smrg		  concat_name[p_len] = '/';
633863847c39Smrg		  strcpy (concat_name + p_len + 1, wrapper);
633963847c39Smrg		}
634063847c39Smrg	      if (check_executable (concat_name))
634163847c39Smrg		return concat_name;
634263847c39Smrg	      XFREE (concat_name);
634363847c39Smrg	    }
634463847c39Smrg	}
634563847c39Smrg      /* not found in PATH; assume curdir */
634663847c39Smrg    }
634763847c39Smrg  /* Relative path | not found in path: prepend cwd */
634863847c39Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634963847c39Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
635063847c39Smrg              nonnull (strerror (errno)));
635163847c39Smrg  tmp_len = strlen (tmp);
635263847c39Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
635363847c39Smrg  memcpy (concat_name, tmp, tmp_len);
635463847c39Smrg  concat_name[tmp_len] = '/';
635563847c39Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
635676888252Smrg
635763847c39Smrg  if (check_executable (concat_name))
635863847c39Smrg    return concat_name;
635963847c39Smrg  XFREE (concat_name);
636063847c39Smrg  return NULL;
636163847c39Smrg}
636276888252Smrg
636363847c39Smrgchar *
636463847c39Smrgchase_symlinks (const char *pathspec)
636563847c39Smrg{
636663847c39Smrg#ifndef S_ISLNK
636763847c39Smrg  return xstrdup (pathspec);
636863847c39Smrg#else
636963847c39Smrg  char buf[LT_PATHMAX];
637063847c39Smrg  struct stat s;
637163847c39Smrg  char *tmp_pathspec = xstrdup (pathspec);
637263847c39Smrg  char *p;
637363847c39Smrg  int has_symlinks = 0;
637463847c39Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
637563847c39Smrg    {
637663847c39Smrg      lt_debugprintf (__FILE__, __LINE__,
637763847c39Smrg		      "checking path component for symlinks: %s\n",
637863847c39Smrg		      tmp_pathspec);
637963847c39Smrg      if (lstat (tmp_pathspec, &s) == 0)
638063847c39Smrg	{
638163847c39Smrg	  if (S_ISLNK (s.st_mode) != 0)
638263847c39Smrg	    {
638363847c39Smrg	      has_symlinks = 1;
638463847c39Smrg	      break;
638563847c39Smrg	    }
638663847c39Smrg
638763847c39Smrg	  /* search backwards for last DIR_SEPARATOR */
638863847c39Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
638963847c39Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639063847c39Smrg	    p--;
639163847c39Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639263847c39Smrg	    {
639363847c39Smrg	      /* no more DIR_SEPARATORS left */
639463847c39Smrg	      break;
639563847c39Smrg	    }
639663847c39Smrg	  *p = '\0';
639763847c39Smrg	}
639863847c39Smrg      else
639963847c39Smrg	{
640063847c39Smrg	  lt_fatal (__FILE__, __LINE__,
640163847c39Smrg		    "error accessing file \"%s\": %s",
640263847c39Smrg		    tmp_pathspec, nonnull (strerror (errno)));
640363847c39Smrg	}
640463847c39Smrg    }
640563847c39Smrg  XFREE (tmp_pathspec);
640676888252Smrg
640763847c39Smrg  if (!has_symlinks)
640863847c39Smrg    {
640963847c39Smrg      return xstrdup (pathspec);
641063847c39Smrg    }
641176888252Smrg
641263847c39Smrg  tmp_pathspec = realpath (pathspec, buf);
641363847c39Smrg  if (tmp_pathspec == 0)
641463847c39Smrg    {
641563847c39Smrg      lt_fatal (__FILE__, __LINE__,
641663847c39Smrg		"could not follow symlinks for %s", pathspec);
641763847c39Smrg    }
641863847c39Smrg  return xstrdup (tmp_pathspec);
6419d8556812Smrg#endif
642063847c39Smrg}
642176888252Smrg
642263847c39Smrgchar *
642363847c39Smrgstrendzap (char *str, const char *pat)
642463847c39Smrg{
642563847c39Smrg  size_t len, patlen;
642676888252Smrg
642763847c39Smrg  assert (str != NULL);
642863847c39Smrg  assert (pat != NULL);
642976888252Smrg
643063847c39Smrg  len = strlen (str);
643163847c39Smrg  patlen = strlen (pat);
643276888252Smrg
643363847c39Smrg  if (patlen <= len)
643463847c39Smrg    {
643563847c39Smrg      str += len - patlen;
64360814a2baSmrg      if (STREQ (str, pat))
643763847c39Smrg	*str = '\0';
643863847c39Smrg    }
643963847c39Smrg  return str;
6440d8556812Smrg}
644186dafe34Smrg
644263847c39Smrgvoid
644363847c39Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
644463847c39Smrg{
644563847c39Smrg  va_list args;
644663847c39Smrg  if (lt_debug)
644763847c39Smrg    {
644863847c39Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644963847c39Smrg      va_start (args, fmt);
645063847c39Smrg      (void) vfprintf (stderr, fmt, args);
645163847c39Smrg      va_end (args);
645263847c39Smrg    }
645363847c39Smrg}
645486dafe34Smrg
645563847c39Smrgstatic void
645663847c39Smrglt_error_core (int exit_status, const char *file,
645763847c39Smrg	       int line, const char *mode,
645863847c39Smrg	       const char *message, va_list ap)
645963847c39Smrg{
646063847c39Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
646163847c39Smrg  vfprintf (stderr, message, ap);
646263847c39Smrg  fprintf (stderr, ".\n");
646386dafe34Smrg
646463847c39Smrg  if (exit_status >= 0)
646563847c39Smrg    exit (exit_status);
6466d8556812Smrg}
646786dafe34Smrg
646863847c39Smrgvoid
646963847c39Smrglt_fatal (const char *file, int line, const char *message, ...)
647063847c39Smrg{
647163847c39Smrg  va_list ap;
647263847c39Smrg  va_start (ap, message);
647363847c39Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
647463847c39Smrg  va_end (ap);
6475d8556812Smrg}
647686dafe34Smrg
647763847c39Smrgstatic const char *
647863847c39Smrgnonnull (const char *s)
647963847c39Smrg{
648063847c39Smrg  return s ? s : "(null)";
648163847c39Smrg}
648286dafe34Smrg
648363847c39Smrgstatic const char *
648463847c39Smrgnonempty (const char *s)
648563847c39Smrg{
648663847c39Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648763847c39Smrg}
648886dafe34Smrg
648963847c39Smrgvoid
649063847c39Smrglt_setenv (const char *name, const char *value)
649163847c39Smrg{
649263847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
649363847c39Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
649463847c39Smrg                  nonnull (name), nonnull (value));
649563847c39Smrg  {
649663847c39Smrg#ifdef HAVE_SETENV
649763847c39Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
649863847c39Smrg    char *str = xstrdup (value);
649963847c39Smrg    setenv (name, str, 1);
650063847c39Smrg#else
65010814a2baSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
650263847c39Smrg    char *str = XMALLOC (char, len);
650363847c39Smrg    sprintf (str, "%s=%s", name, value);
650463847c39Smrg    if (putenv (str) != EXIT_SUCCESS)
650563847c39Smrg      {
650663847c39Smrg        XFREE (str);
650763847c39Smrg      }
650863847c39Smrg#endif
650963847c39Smrg  }
651063847c39Smrg}
651186dafe34Smrg
651263847c39Smrgchar *
651363847c39Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
651463847c39Smrg{
651563847c39Smrg  char *new_value;
651663847c39Smrg  if (orig_value && *orig_value)
651763847c39Smrg    {
65180814a2baSmrg      size_t orig_value_len = strlen (orig_value);
65190814a2baSmrg      size_t add_len = strlen (add);
652063847c39Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
652163847c39Smrg      if (to_end)
652263847c39Smrg        {
652363847c39Smrg          strcpy (new_value, orig_value);
652463847c39Smrg          strcpy (new_value + orig_value_len, add);
652563847c39Smrg        }
6526d8556812Smrg      else
652763847c39Smrg        {
652863847c39Smrg          strcpy (new_value, add);
652963847c39Smrg          strcpy (new_value + add_len, orig_value);
653063847c39Smrg        }
653163847c39Smrg    }
653263847c39Smrg  else
653363847c39Smrg    {
653463847c39Smrg      new_value = xstrdup (add);
653563847c39Smrg    }
653663847c39Smrg  return new_value;
653763847c39Smrg}
653886dafe34Smrg
653963847c39Smrgvoid
654063847c39Smrglt_update_exe_path (const char *name, const char *value)
654163847c39Smrg{
654263847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
654363847c39Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
654463847c39Smrg                  nonnull (name), nonnull (value));
654586dafe34Smrg
654663847c39Smrg  if (name && *name && value && *value)
654763847c39Smrg    {
654863847c39Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
654963847c39Smrg      /* some systems can't cope with a ':'-terminated path #' */
65500814a2baSmrg      size_t len = strlen (new_value);
65510814a2baSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
655263847c39Smrg        {
65530814a2baSmrg          new_value[--len] = '\0';
655463847c39Smrg        }
655563847c39Smrg      lt_setenv (name, new_value);
655663847c39Smrg      XFREE (new_value);
655763847c39Smrg    }
655863847c39Smrg}
655986dafe34Smrg
656063847c39Smrgvoid
656163847c39Smrglt_update_lib_path (const char *name, const char *value)
656263847c39Smrg{
656363847c39Smrg  lt_debugprintf (__FILE__, __LINE__,
656463847c39Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
656563847c39Smrg                  nonnull (name), nonnull (value));
656686dafe34Smrg
656763847c39Smrg  if (name && *name && value && *value)
656863847c39Smrg    {
656963847c39Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
657063847c39Smrg      lt_setenv (name, new_value);
657163847c39Smrg      XFREE (new_value);
657263847c39Smrg    }
657363847c39Smrg}
657486dafe34Smrg
6575d8556812SmrgEOF
657663847c39Smrg	    case $host_os in
657763847c39Smrg	      mingw*)
657863847c39Smrg		cat <<"EOF"
657963847c39Smrg
658063847c39Smrg/* Prepares an argument vector before calling spawn().
658163847c39Smrg   Note that spawn() does not by itself call the command interpreter
658263847c39Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
658363847c39Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
658463847c39Smrg         GetVersionEx(&v);
658563847c39Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
658663847c39Smrg      }) ? "cmd.exe" : "command.com").
658763847c39Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658863847c39Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658963847c39Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
659063847c39Smrg   special way:
659163847c39Smrg   - Space and tab are interpreted as delimiters. They are not treated as
659263847c39Smrg     delimiters if they are surrounded by double quotes: "...".
659363847c39Smrg   - Unescaped double quotes are removed from the input. Their only effect is
659463847c39Smrg     that within double quotes, space and tab are treated like normal
659563847c39Smrg     characters.
659663847c39Smrg   - Backslashes not followed by double quotes are not special.
659763847c39Smrg   - But 2*n+1 backslashes followed by a double quote become
659863847c39Smrg     n backslashes followed by a double quote (n >= 0):
659963847c39Smrg       \" -> "
660063847c39Smrg       \\\" -> \"
660163847c39Smrg       \\\\\" -> \\"
660263847c39Smrg */
660363847c39Smrg#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"
660463847c39Smrg#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"
660563847c39Smrgchar **
660663847c39Smrgprepare_spawn (char **argv)
6607d8556812Smrg{
660863847c39Smrg  size_t argc;
660963847c39Smrg  char **new_argv;
661063847c39Smrg  size_t i;
661186dafe34Smrg
661263847c39Smrg  /* Count number of arguments.  */
661363847c39Smrg  for (argc = 0; argv[argc] != NULL; argc++)
661463847c39Smrg    ;
661586dafe34Smrg
661663847c39Smrg  /* Allocate new argument vector.  */
661763847c39Smrg  new_argv = XMALLOC (char *, argc + 1);
661886dafe34Smrg
661963847c39Smrg  /* Put quoted arguments into the new argument vector.  */
662063847c39Smrg  for (i = 0; i < argc; i++)
662163847c39Smrg    {
662263847c39Smrg      const char *string = argv[i];
662363847c39Smrg
662463847c39Smrg      if (string[0] == '\0')
662563847c39Smrg	new_argv[i] = xstrdup ("\"\"");
662663847c39Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662763847c39Smrg	{
662863847c39Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662963847c39Smrg	  size_t length;
663063847c39Smrg	  unsigned int backslashes;
663163847c39Smrg	  const char *s;
663263847c39Smrg	  char *quoted_string;
663363847c39Smrg	  char *p;
663463847c39Smrg
663563847c39Smrg	  length = 0;
663663847c39Smrg	  backslashes = 0;
663763847c39Smrg	  if (quote_around)
663863847c39Smrg	    length++;
663963847c39Smrg	  for (s = string; *s != '\0'; s++)
664063847c39Smrg	    {
664163847c39Smrg	      char c = *s;
664263847c39Smrg	      if (c == '"')
664363847c39Smrg		length += backslashes + 1;
664463847c39Smrg	      length++;
664563847c39Smrg	      if (c == '\\')
664663847c39Smrg		backslashes++;
664763847c39Smrg	      else
664863847c39Smrg		backslashes = 0;
664963847c39Smrg	    }
665063847c39Smrg	  if (quote_around)
665163847c39Smrg	    length += backslashes + 1;
665263847c39Smrg
665363847c39Smrg	  quoted_string = XMALLOC (char, length + 1);
665463847c39Smrg
665563847c39Smrg	  p = quoted_string;
665663847c39Smrg	  backslashes = 0;
665763847c39Smrg	  if (quote_around)
665863847c39Smrg	    *p++ = '"';
665963847c39Smrg	  for (s = string; *s != '\0'; s++)
666063847c39Smrg	    {
666163847c39Smrg	      char c = *s;
666263847c39Smrg	      if (c == '"')
666363847c39Smrg		{
666463847c39Smrg		  unsigned int j;
666563847c39Smrg		  for (j = backslashes + 1; j > 0; j--)
666663847c39Smrg		    *p++ = '\\';
666763847c39Smrg		}
666863847c39Smrg	      *p++ = c;
666963847c39Smrg	      if (c == '\\')
667063847c39Smrg		backslashes++;
667163847c39Smrg	      else
667263847c39Smrg		backslashes = 0;
667363847c39Smrg	    }
667463847c39Smrg	  if (quote_around)
667563847c39Smrg	    {
667663847c39Smrg	      unsigned int j;
667763847c39Smrg	      for (j = backslashes; j > 0; j--)
667863847c39Smrg		*p++ = '\\';
667963847c39Smrg	      *p++ = '"';
668063847c39Smrg	    }
668163847c39Smrg	  *p = '\0';
668286dafe34Smrg
668363847c39Smrg	  new_argv[i] = quoted_string;
668463847c39Smrg	}
668563847c39Smrg      else
668663847c39Smrg	new_argv[i] = (char *) string;
668763847c39Smrg    }
668863847c39Smrg  new_argv[argc] = NULL;
668986dafe34Smrg
669063847c39Smrg  return new_argv;
669163847c39Smrg}
6692d8556812SmrgEOF
669363847c39Smrg		;;
669463847c39Smrg	    esac
669586dafe34Smrg
669663847c39Smrg            cat <<"EOF"
669763847c39Smrgvoid lt_dump_script (FILE* f)
669863847c39Smrg{
6699d8556812SmrgEOF
670063847c39Smrg	    func_emit_wrapper yes |
670163847c39Smrg	      $SED -n -e '
670263847c39Smrgs/^\(.\{79\}\)\(..*\)/\1\
670363847c39Smrg\2/
670463847c39Smrgh
670563847c39Smrgs/\([\\"]\)/\\\1/g
670663847c39Smrgs/$/\\n/
670763847c39Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
670863847c39Smrgg
670963847c39SmrgD'
671063847c39Smrg            cat <<"EOF"
6711d8556812Smrg}
671263847c39SmrgEOF
6713d8556812Smrg}
671463847c39Smrg# end: func_emit_cwrapperexe_src
671586dafe34Smrg
671663847c39Smrg# func_win32_import_lib_p ARG
671763847c39Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671863847c39Smrgfunc_win32_import_lib_p ()
6719d8556812Smrg{
67200814a2baSmrg    $debug_cmd
67210814a2baSmrg
672263847c39Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
672363847c39Smrg    *import*) : ;;
672463847c39Smrg    *) false ;;
672563847c39Smrg    esac
6726d8556812Smrg}
672786dafe34Smrg
67280814a2baSmrg# func_suncc_cstd_abi
67290814a2baSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
67300814a2baSmrg# Several compiler flags select an ABI that is incompatible with the
67310814a2baSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
67320814a2baSmrgfunc_suncc_cstd_abi ()
67330814a2baSmrg{
67340814a2baSmrg    $debug_cmd
67350814a2baSmrg
67360814a2baSmrg    case " $compile_command " in
67370814a2baSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
67380814a2baSmrg      suncc_use_cstd_abi=no
67390814a2baSmrg      ;;
67400814a2baSmrg    *)
67410814a2baSmrg      suncc_use_cstd_abi=yes
67420814a2baSmrg      ;;
67430814a2baSmrg    esac
67440814a2baSmrg}
67450814a2baSmrg
674663847c39Smrg# func_mode_link arg...
674763847c39Smrgfunc_mode_link ()
6748d8556812Smrg{
67490814a2baSmrg    $debug_cmd
67500814a2baSmrg
675163847c39Smrg    case $host in
675263847c39Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
675363847c39Smrg      # It is impossible to link a dll without this setting, and
675463847c39Smrg      # we shouldn't force the makefile maintainer to figure out
67550814a2baSmrg      # what system we are compiling for in order to pass an extra
675663847c39Smrg      # flag for every libtool invocation.
675763847c39Smrg      # allow_undefined=no
675886dafe34Smrg
675963847c39Smrg      # FIXME: Unfortunately, there are problems with the above when trying
67600814a2baSmrg      # to make a dll that has undefined symbols, in which case not
676163847c39Smrg      # even a static library is built.  For now, we need to specify
676263847c39Smrg      # -no-undefined on the libtool link line when we can be certain
676363847c39Smrg      # that all symbols are satisfied, otherwise we get a static library.
676463847c39Smrg      allow_undefined=yes
676563847c39Smrg      ;;
676663847c39Smrg    *)
676763847c39Smrg      allow_undefined=yes
676863847c39Smrg      ;;
676963847c39Smrg    esac
677063847c39Smrg    libtool_args=$nonopt
677163847c39Smrg    base_compile="$nonopt $@"
677263847c39Smrg    compile_command=$nonopt
677363847c39Smrg    finalize_command=$nonopt
677486dafe34Smrg
677563847c39Smrg    compile_rpath=
677663847c39Smrg    finalize_rpath=
677763847c39Smrg    compile_shlibpath=
677863847c39Smrg    finalize_shlibpath=
677963847c39Smrg    convenience=
678063847c39Smrg    old_convenience=
678163847c39Smrg    deplibs=
678263847c39Smrg    old_deplibs=
678363847c39Smrg    compiler_flags=
678463847c39Smrg    linker_flags=
678563847c39Smrg    dllsearchpath=
678663847c39Smrg    lib_search_path=`pwd`
678763847c39Smrg    inst_prefix_dir=
678863847c39Smrg    new_inherited_linker_flags=
678986dafe34Smrg
679063847c39Smrg    avoid_version=no
679163847c39Smrg    bindir=
679263847c39Smrg    dlfiles=
679363847c39Smrg    dlprefiles=
679463847c39Smrg    dlself=no
679563847c39Smrg    export_dynamic=no
679663847c39Smrg    export_symbols=
679763847c39Smrg    export_symbols_regex=
679863847c39Smrg    generated=
679963847c39Smrg    libobjs=
680063847c39Smrg    ltlibs=
680163847c39Smrg    module=no
680263847c39Smrg    no_install=no
680363847c39Smrg    objs=
68040814a2baSmrg    os2dllname=
680563847c39Smrg    non_pic_objects=
680663847c39Smrg    precious_files_regex=
680763847c39Smrg    prefer_static_libs=no
68080814a2baSmrg    preload=false
680963847c39Smrg    prev=
681063847c39Smrg    prevarg=
681163847c39Smrg    release=
681263847c39Smrg    rpath=
681363847c39Smrg    xrpath=
681463847c39Smrg    perm_rpath=
681563847c39Smrg    temp_rpath=
681663847c39Smrg    thread_safe=no
681763847c39Smrg    vinfo=
681863847c39Smrg    vinfo_number=no
681963847c39Smrg    weak_libs=
68200814a2baSmrg    single_module=$wl-single_module
682163847c39Smrg    func_infer_tag $base_compile
682286dafe34Smrg
682363847c39Smrg    # We need to know -static, to get the right output filenames.
682463847c39Smrg    for arg
682563847c39Smrg    do
682663847c39Smrg      case $arg in
682763847c39Smrg      -shared)
68280814a2baSmrg	test yes != "$build_libtool_libs" \
68290814a2baSmrg	  && func_fatal_configuration "cannot build a shared library"
683063847c39Smrg	build_old_libs=no
683163847c39Smrg	break
683263847c39Smrg	;;
683363847c39Smrg      -all-static | -static | -static-libtool-libs)
683463847c39Smrg	case $arg in
683563847c39Smrg	-all-static)
68360814a2baSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
683763847c39Smrg	    func_warning "complete static linking is impossible in this configuration"
683863847c39Smrg	  fi
683963847c39Smrg	  if test -n "$link_static_flag"; then
684063847c39Smrg	    dlopen_self=$dlopen_self_static
684163847c39Smrg	  fi
684263847c39Smrg	  prefer_static_libs=yes
684363847c39Smrg	  ;;
684463847c39Smrg	-static)
684563847c39Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
684663847c39Smrg	    dlopen_self=$dlopen_self_static
684763847c39Smrg	  fi
684863847c39Smrg	  prefer_static_libs=built
684963847c39Smrg	  ;;
685063847c39Smrg	-static-libtool-libs)
685163847c39Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
685263847c39Smrg	    dlopen_self=$dlopen_self_static
685363847c39Smrg	  fi
685463847c39Smrg	  prefer_static_libs=yes
685563847c39Smrg	  ;;
685663847c39Smrg	esac
685763847c39Smrg	build_libtool_libs=no
685863847c39Smrg	build_old_libs=yes
685963847c39Smrg	break
686063847c39Smrg	;;
686163847c39Smrg      esac
686263847c39Smrg    done
686386dafe34Smrg
686463847c39Smrg    # See if our shared archives depend on static archives.
686563847c39Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
686686dafe34Smrg
686763847c39Smrg    # Go through the arguments, transforming them on the way.
686863847c39Smrg    while test "$#" -gt 0; do
68690814a2baSmrg      arg=$1
687063847c39Smrg      shift
68710814a2baSmrg      func_quote_arg pretty,unquoted "$arg"
68720814a2baSmrg      qarg=$func_quote_arg_unquoted_result
68730814a2baSmrg      func_append libtool_args " $func_quote_arg_result"
687476888252Smrg
687563847c39Smrg      # If the previous option needs an argument, assign it.
687663847c39Smrg      if test -n "$prev"; then
687763847c39Smrg	case $prev in
687863847c39Smrg	output)
687963847c39Smrg	  func_append compile_command " @OUTPUT@"
688063847c39Smrg	  func_append finalize_command " @OUTPUT@"
688163847c39Smrg	  ;;
688263847c39Smrg	esac
6883d8556812Smrg
688463847c39Smrg	case $prev in
688563847c39Smrg	bindir)
68860814a2baSmrg	  bindir=$arg
688763847c39Smrg	  prev=
688863847c39Smrg	  continue
688963847c39Smrg	  ;;
689063847c39Smrg	dlfiles|dlprefiles)
68910814a2baSmrg	  $preload || {
689263847c39Smrg	    # Add the symbol object into the linking commands.
689363847c39Smrg	    func_append compile_command " @SYMFILE@"
689463847c39Smrg	    func_append finalize_command " @SYMFILE@"
68950814a2baSmrg	    preload=:
68960814a2baSmrg	  }
689763847c39Smrg	  case $arg in
689863847c39Smrg	  *.la | *.lo) ;;  # We handle these cases below.
689963847c39Smrg	  force)
69000814a2baSmrg	    if test no = "$dlself"; then
690163847c39Smrg	      dlself=needless
690263847c39Smrg	      export_dynamic=yes
690363847c39Smrg	    fi
690463847c39Smrg	    prev=
690563847c39Smrg	    continue
690663847c39Smrg	    ;;
690763847c39Smrg	  self)
69080814a2baSmrg	    if test dlprefiles = "$prev"; then
690963847c39Smrg	      dlself=yes
69100814a2baSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
691163847c39Smrg	      dlself=yes
691263847c39Smrg	    else
691363847c39Smrg	      dlself=needless
691463847c39Smrg	      export_dynamic=yes
691563847c39Smrg	    fi
691663847c39Smrg	    prev=
691763847c39Smrg	    continue
691863847c39Smrg	    ;;
691963847c39Smrg	  *)
69200814a2baSmrg	    if test dlfiles = "$prev"; then
692163847c39Smrg	      func_append dlfiles " $arg"
692263847c39Smrg	    else
692363847c39Smrg	      func_append dlprefiles " $arg"
692463847c39Smrg	    fi
692563847c39Smrg	    prev=
692663847c39Smrg	    continue
692763847c39Smrg	    ;;
692863847c39Smrg	  esac
692963847c39Smrg	  ;;
693063847c39Smrg	expsyms)
69310814a2baSmrg	  export_symbols=$arg
693263847c39Smrg	  test -f "$arg" \
69330814a2baSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
693463847c39Smrg	  prev=
693563847c39Smrg	  continue
693663847c39Smrg	  ;;
693763847c39Smrg	expsyms_regex)
69380814a2baSmrg	  export_symbols_regex=$arg
693963847c39Smrg	  prev=
694063847c39Smrg	  continue
694163847c39Smrg	  ;;
694263847c39Smrg	framework)
694363847c39Smrg	  case $host in
694463847c39Smrg	    *-*-darwin*)
694563847c39Smrg	      case "$deplibs " in
694663847c39Smrg		*" $qarg.ltframework "*) ;;
694763847c39Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
694863847c39Smrg		   ;;
694963847c39Smrg	      esac
695063847c39Smrg	      ;;
695163847c39Smrg	  esac
695263847c39Smrg	  prev=
695363847c39Smrg	  continue
695463847c39Smrg	  ;;
695563847c39Smrg	inst_prefix)
69560814a2baSmrg	  inst_prefix_dir=$arg
69570814a2baSmrg	  prev=
69580814a2baSmrg	  continue
69590814a2baSmrg	  ;;
69600814a2baSmrg	mllvm)
69610814a2baSmrg	  # Clang does not use LLVM to link, so we can simply discard any
69620814a2baSmrg	  # '-mllvm $arg' options when doing the link step.
696363847c39Smrg	  prev=
696463847c39Smrg	  continue
696563847c39Smrg	  ;;
696663847c39Smrg	objectlist)
696763847c39Smrg	  if test -f "$arg"; then
696863847c39Smrg	    save_arg=$arg
696963847c39Smrg	    moreargs=
697063847c39Smrg	    for fil in `cat "$save_arg"`
697163847c39Smrg	    do
697263847c39Smrg#	      func_append moreargs " $fil"
697363847c39Smrg	      arg=$fil
697463847c39Smrg	      # A libtool-controlled object.
6975d8556812Smrg
697663847c39Smrg	      # Check to see that this really is a libtool object.
697763847c39Smrg	      if func_lalib_unsafe_p "$arg"; then
697863847c39Smrg		pic_object=
697963847c39Smrg		non_pic_object=
6980d8556812Smrg
698163847c39Smrg		# Read the .lo file
698263847c39Smrg		func_source "$arg"
6983d8556812Smrg
698463847c39Smrg		if test -z "$pic_object" ||
698563847c39Smrg		   test -z "$non_pic_object" ||
69860814a2baSmrg		   test none = "$pic_object" &&
69870814a2baSmrg		   test none = "$non_pic_object"; then
69880814a2baSmrg		  func_fatal_error "cannot find name of object for '$arg'"
698963847c39Smrg		fi
6990d8556812Smrg
699163847c39Smrg		# Extract subdirectory from the argument.
699263847c39Smrg		func_dirname "$arg" "/" ""
69930814a2baSmrg		xdir=$func_dirname_result
6994d8556812Smrg
69950814a2baSmrg		if test none != "$pic_object"; then
699663847c39Smrg		  # Prepend the subdirectory the object is found in.
69970814a2baSmrg		  pic_object=$xdir$pic_object
6998d8556812Smrg
69990814a2baSmrg		  if test dlfiles = "$prev"; then
70000814a2baSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
700163847c39Smrg		      func_append dlfiles " $pic_object"
700263847c39Smrg		      prev=
700363847c39Smrg		      continue
700463847c39Smrg		    else
700563847c39Smrg		      # If libtool objects are unsupported, then we need to preload.
700663847c39Smrg		      prev=dlprefiles
700763847c39Smrg		    fi
700863847c39Smrg		  fi
7009d8556812Smrg
701063847c39Smrg		  # CHECK ME:  I think I busted this.  -Ossama
70110814a2baSmrg		  if test dlprefiles = "$prev"; then
701263847c39Smrg		    # Preload the old-style object.
701363847c39Smrg		    func_append dlprefiles " $pic_object"
701463847c39Smrg		    prev=
701563847c39Smrg		  fi
7016d8556812Smrg
701763847c39Smrg		  # A PIC object.
701863847c39Smrg		  func_append libobjs " $pic_object"
70190814a2baSmrg		  arg=$pic_object
702063847c39Smrg		fi
7021d8556812Smrg
702263847c39Smrg		# Non-PIC object.
70230814a2baSmrg		if test none != "$non_pic_object"; then
702463847c39Smrg		  # Prepend the subdirectory the object is found in.
70250814a2baSmrg		  non_pic_object=$xdir$non_pic_object
7026d8556812Smrg
702763847c39Smrg		  # A standard non-PIC object
702863847c39Smrg		  func_append non_pic_objects " $non_pic_object"
70290814a2baSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
70300814a2baSmrg		    arg=$non_pic_object
703163847c39Smrg		  fi
703263847c39Smrg		else
703363847c39Smrg		  # If the PIC object exists, use it instead.
703463847c39Smrg		  # $xdir was prepended to $pic_object above.
70350814a2baSmrg		  non_pic_object=$pic_object
703663847c39Smrg		  func_append non_pic_objects " $non_pic_object"
703763847c39Smrg		fi
703863847c39Smrg	      else
703963847c39Smrg		# Only an error if not doing a dry-run.
704063847c39Smrg		if $opt_dry_run; then
704163847c39Smrg		  # Extract subdirectory from the argument.
704263847c39Smrg		  func_dirname "$arg" "/" ""
70430814a2baSmrg		  xdir=$func_dirname_result
704463847c39Smrg
704563847c39Smrg		  func_lo2o "$arg"
704663847c39Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
704763847c39Smrg		  non_pic_object=$xdir$func_lo2o_result
704863847c39Smrg		  func_append libobjs " $pic_object"
704963847c39Smrg		  func_append non_pic_objects " $non_pic_object"
705063847c39Smrg	        else
70510814a2baSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
705263847c39Smrg		fi
705363847c39Smrg	      fi
705463847c39Smrg	    done
705563847c39Smrg	  else
70560814a2baSmrg	    func_fatal_error "link input file '$arg' does not exist"
705763847c39Smrg	  fi
705863847c39Smrg	  arg=$save_arg
705963847c39Smrg	  prev=
706063847c39Smrg	  continue
706163847c39Smrg	  ;;
70620814a2baSmrg	os2dllname)
70630814a2baSmrg	  os2dllname=$arg
70640814a2baSmrg	  prev=
70650814a2baSmrg	  continue
70660814a2baSmrg	  ;;
706763847c39Smrg	precious_regex)
70680814a2baSmrg	  precious_files_regex=$arg
706963847c39Smrg	  prev=
707063847c39Smrg	  continue
707163847c39Smrg	  ;;
707263847c39Smrg	release)
70730814a2baSmrg	  release=-$arg
707463847c39Smrg	  prev=
707563847c39Smrg	  continue
707663847c39Smrg	  ;;
707763847c39Smrg	rpath | xrpath)
707863847c39Smrg	  # We need an absolute path.
707963847c39Smrg	  case $arg in
708063847c39Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
708163847c39Smrg	  *)
708263847c39Smrg	    func_fatal_error "only absolute run-paths are allowed"
708363847c39Smrg	    ;;
708463847c39Smrg	  esac
70850814a2baSmrg	  if test rpath = "$prev"; then
708663847c39Smrg	    case "$rpath " in
708763847c39Smrg	    *" $arg "*) ;;
708863847c39Smrg	    *) func_append rpath " $arg" ;;
708963847c39Smrg	    esac
709063847c39Smrg	  else
709163847c39Smrg	    case "$xrpath " in
709263847c39Smrg	    *" $arg "*) ;;
709363847c39Smrg	    *) func_append xrpath " $arg" ;;
709463847c39Smrg	    esac
709563847c39Smrg	  fi
709663847c39Smrg	  prev=
709763847c39Smrg	  continue
709863847c39Smrg	  ;;
709963847c39Smrg	shrext)
71000814a2baSmrg	  shrext_cmds=$arg
710163847c39Smrg	  prev=
710263847c39Smrg	  continue
710363847c39Smrg	  ;;
710463847c39Smrg	weak)
710563847c39Smrg	  func_append weak_libs " $arg"
710663847c39Smrg	  prev=
710763847c39Smrg	  continue
710863847c39Smrg	  ;;
71090814a2baSmrg	xassembler)
71100814a2baSmrg	  func_append compiler_flags " -Xassembler $qarg"
71110814a2baSmrg	  prev=
71120814a2baSmrg	  func_append compile_command " -Xassembler $qarg"
71130814a2baSmrg	  func_append finalize_command " -Xassembler $qarg"
71140814a2baSmrg	  continue
71150814a2baSmrg	  ;;
711663847c39Smrg	xcclinker)
711763847c39Smrg	  func_append linker_flags " $qarg"
711863847c39Smrg	  func_append compiler_flags " $qarg"
711963847c39Smrg	  prev=
712063847c39Smrg	  func_append compile_command " $qarg"
712163847c39Smrg	  func_append finalize_command " $qarg"
712263847c39Smrg	  continue
712363847c39Smrg	  ;;
712463847c39Smrg	xcompiler)
712563847c39Smrg	  func_append compiler_flags " $qarg"
712663847c39Smrg	  prev=
712763847c39Smrg	  func_append compile_command " $qarg"
712863847c39Smrg	  func_append finalize_command " $qarg"
712963847c39Smrg	  continue
713063847c39Smrg	  ;;
713163847c39Smrg	xlinker)
713263847c39Smrg	  func_append linker_flags " $qarg"
713363847c39Smrg	  func_append compiler_flags " $wl$qarg"
713463847c39Smrg	  prev=
713563847c39Smrg	  func_append compile_command " $wl$qarg"
713663847c39Smrg	  func_append finalize_command " $wl$qarg"
713763847c39Smrg	  continue
713863847c39Smrg	  ;;
713963847c39Smrg	*)
714063847c39Smrg	  eval "$prev=\"\$arg\""
714163847c39Smrg	  prev=
714263847c39Smrg	  continue
714363847c39Smrg	  ;;
714463847c39Smrg	esac
714563847c39Smrg      fi # test -n "$prev"
7146d8556812Smrg
71470814a2baSmrg      prevarg=$arg
7148d8556812Smrg
714963847c39Smrg      case $arg in
715063847c39Smrg      -all-static)
715163847c39Smrg	if test -n "$link_static_flag"; then
715263847c39Smrg	  # See comment for -static flag below, for more details.
715363847c39Smrg	  func_append compile_command " $link_static_flag"
715463847c39Smrg	  func_append finalize_command " $link_static_flag"
715563847c39Smrg	fi
715663847c39Smrg	continue
715763847c39Smrg	;;
7158d8556812Smrg
715963847c39Smrg      -allow-undefined)
716063847c39Smrg	# FIXME: remove this flag sometime in the future.
71610814a2baSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
716263847c39Smrg	;;
7163d8556812Smrg
716463847c39Smrg      -avoid-version)
716563847c39Smrg	avoid_version=yes
716663847c39Smrg	continue
716763847c39Smrg	;;
7168d8556812Smrg
716963847c39Smrg      -bindir)
717063847c39Smrg	prev=bindir
717163847c39Smrg	continue
717263847c39Smrg	;;
717376888252Smrg
717463847c39Smrg      -dlopen)
717563847c39Smrg	prev=dlfiles
717663847c39Smrg	continue
717763847c39Smrg	;;
717876888252Smrg
717963847c39Smrg      -dlpreopen)
718063847c39Smrg	prev=dlprefiles
718163847c39Smrg	continue
718263847c39Smrg	;;
718376888252Smrg
718463847c39Smrg      -export-dynamic)
718563847c39Smrg	export_dynamic=yes
718663847c39Smrg	continue
718763847c39Smrg	;;
718876888252Smrg
718963847c39Smrg      -export-symbols | -export-symbols-regex)
719063847c39Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
719163847c39Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
719263847c39Smrg	fi
71930814a2baSmrg	if test X-export-symbols = "X$arg"; then
719463847c39Smrg	  prev=expsyms
719563847c39Smrg	else
719663847c39Smrg	  prev=expsyms_regex
719763847c39Smrg	fi
719863847c39Smrg	continue
719963847c39Smrg	;;
720076888252Smrg
720163847c39Smrg      -framework)
720263847c39Smrg	prev=framework
720363847c39Smrg	continue
720463847c39Smrg	;;
720576888252Smrg
720663847c39Smrg      -inst-prefix-dir)
720763847c39Smrg	prev=inst_prefix
720863847c39Smrg	continue
720963847c39Smrg	;;
721076888252Smrg
721163847c39Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
721263847c39Smrg      # so, if we see these flags be careful not to treat them like -L
721363847c39Smrg      -L[A-Z][A-Z]*:*)
721463847c39Smrg	case $with_gcc/$host in
721563847c39Smrg	no/*-*-irix* | /*-*-irix*)
721663847c39Smrg	  func_append compile_command " $arg"
721763847c39Smrg	  func_append finalize_command " $arg"
721863847c39Smrg	  ;;
721963847c39Smrg	esac
722063847c39Smrg	continue
722163847c39Smrg	;;
722276888252Smrg
722363847c39Smrg      -L*)
722463847c39Smrg	func_stripname "-L" '' "$arg"
722563847c39Smrg	if test -z "$func_stripname_result"; then
722663847c39Smrg	  if test "$#" -gt 0; then
72270814a2baSmrg	    func_fatal_error "require no space between '-L' and '$1'"
722863847c39Smrg	  else
72290814a2baSmrg	    func_fatal_error "need path for '-L' option"
723063847c39Smrg	  fi
723163847c39Smrg	fi
723263847c39Smrg	func_resolve_sysroot "$func_stripname_result"
723363847c39Smrg	dir=$func_resolve_sysroot_result
723463847c39Smrg	# We need an absolute path.
723563847c39Smrg	case $dir in
723663847c39Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
723763847c39Smrg	*)
723863847c39Smrg	  absdir=`cd "$dir" && pwd`
723963847c39Smrg	  test -z "$absdir" && \
72400814a2baSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
72410814a2baSmrg	  dir=$absdir
724263847c39Smrg	  ;;
724363847c39Smrg	esac
724463847c39Smrg	case "$deplibs " in
724563847c39Smrg	*" -L$dir "* | *" $arg "*)
724663847c39Smrg	  # Will only happen for absolute or sysroot arguments
724763847c39Smrg	  ;;
724863847c39Smrg	*)
724963847c39Smrg	  # Preserve sysroot, but never include relative directories
725063847c39Smrg	  case $dir in
725163847c39Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
725263847c39Smrg	    *) func_append deplibs " -L$dir" ;;
725363847c39Smrg	  esac
725463847c39Smrg	  func_append lib_search_path " $dir"
725563847c39Smrg	  ;;
725663847c39Smrg	esac
725763847c39Smrg	case $host in
725863847c39Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725963847c39Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
726063847c39Smrg	  case :$dllsearchpath: in
726163847c39Smrg	  *":$dir:"*) ;;
726263847c39Smrg	  ::) dllsearchpath=$dir;;
726363847c39Smrg	  *) func_append dllsearchpath ":$dir";;
726463847c39Smrg	  esac
726563847c39Smrg	  case :$dllsearchpath: in
726663847c39Smrg	  *":$testbindir:"*) ;;
726763847c39Smrg	  ::) dllsearchpath=$testbindir;;
726863847c39Smrg	  *) func_append dllsearchpath ":$testbindir";;
726963847c39Smrg	  esac
727063847c39Smrg	  ;;
727163847c39Smrg	esac
727263847c39Smrg	continue
727363847c39Smrg	;;
727476888252Smrg
727563847c39Smrg      -l*)
72760814a2baSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
727763847c39Smrg	  case $host in
727863847c39Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
727963847c39Smrg	    # These systems don't actually have a C or math library (as such)
728063847c39Smrg	    continue
728163847c39Smrg	    ;;
728263847c39Smrg	  *-*-os2*)
728363847c39Smrg	    # These systems don't actually have a C library (as such)
72840814a2baSmrg	    test X-lc = "X$arg" && continue
728563847c39Smrg	    ;;
72860814a2baSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
728763847c39Smrg	    # Do not include libc due to us having libc/libc_r.
72880814a2baSmrg	    test X-lc = "X$arg" && continue
728963847c39Smrg	    ;;
729063847c39Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
729163847c39Smrg	    # Rhapsody C and math libraries are in the System framework
729263847c39Smrg	    func_append deplibs " System.ltframework"
729363847c39Smrg	    continue
729463847c39Smrg	    ;;
729563847c39Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
729663847c39Smrg	    # Causes problems with __ctype
72970814a2baSmrg	    test X-lc = "X$arg" && continue
729863847c39Smrg	    ;;
729963847c39Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
730063847c39Smrg	    # Compiler inserts libc in the correct place for threads to work
73010814a2baSmrg	    test X-lc = "X$arg" && continue
730263847c39Smrg	    ;;
730363847c39Smrg	  esac
73040814a2baSmrg	elif test X-lc_r = "X$arg"; then
730563847c39Smrg	 case $host in
73060814a2baSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
730763847c39Smrg	   # Do not include libc_r directly, use -pthread flag.
730863847c39Smrg	   continue
730963847c39Smrg	   ;;
731063847c39Smrg	 esac
731163847c39Smrg	fi
731263847c39Smrg	func_append deplibs " $arg"
731363847c39Smrg	continue
731463847c39Smrg	;;
731563847c39Smrg
73160814a2baSmrg      -mllvm)
73170814a2baSmrg	prev=mllvm
73180814a2baSmrg	continue
73190814a2baSmrg	;;
73200814a2baSmrg
732163847c39Smrg      -module)
732263847c39Smrg	module=yes
732363847c39Smrg	continue
732463847c39Smrg	;;
732563847c39Smrg
732663847c39Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
732763847c39Smrg      # classes, name mangling, and exception handling.
732863847c39Smrg      # Darwin uses the -arch flag to determine output architecture.
732963847c39Smrg      -model|-arch|-isysroot|--sysroot)
733063847c39Smrg	func_append compiler_flags " $arg"
733163847c39Smrg	func_append compile_command " $arg"
733263847c39Smrg	func_append finalize_command " $arg"
733363847c39Smrg	prev=xcompiler
733463847c39Smrg	continue
733563847c39Smrg	;;
73360814a2baSmrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
73370814a2baSmrg     -pthread)
73380814a2baSmrg	case $host in
73390814a2baSmrg	  *solaris2*) ;;
73400814a2baSmrg	  *)
73410814a2baSmrg	    case "$new_inherited_linker_flags " in
73420814a2baSmrg	        *" $arg "*) ;;
73430814a2baSmrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
73440814a2baSmrg	    esac
73450814a2baSmrg	  ;;
73460814a2baSmrg	esac
73470814a2baSmrg	continue
73480814a2baSmrg	;;
73490814a2baSmrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
735063847c39Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
735163847c39Smrg	func_append compiler_flags " $arg"
735263847c39Smrg	func_append compile_command " $arg"
735363847c39Smrg	func_append finalize_command " $arg"
735463847c39Smrg	case "$new_inherited_linker_flags " in
735563847c39Smrg	    *" $arg "*) ;;
735663847c39Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
735763847c39Smrg	esac
735863847c39Smrg	continue
735963847c39Smrg	;;
736063847c39Smrg
736163847c39Smrg      -multi_module)
73620814a2baSmrg	single_module=$wl-multi_module
736363847c39Smrg	continue
736463847c39Smrg	;;
736563847c39Smrg
736663847c39Smrg      -no-fast-install)
736763847c39Smrg	fast_install=no
736863847c39Smrg	continue
736963847c39Smrg	;;
737063847c39Smrg
737163847c39Smrg      -no-install)
737263847c39Smrg	case $host in
737363847c39Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
737463847c39Smrg	  # The PATH hackery in wrapper scripts is required on Windows
737563847c39Smrg	  # and Darwin in order for the loader to find any dlls it needs.
73760814a2baSmrg	  func_warning "'-no-install' is ignored for $host"
73770814a2baSmrg	  func_warning "assuming '-no-fast-install' instead"
737863847c39Smrg	  fast_install=no
737963847c39Smrg	  ;;
738063847c39Smrg	*) no_install=yes ;;
738163847c39Smrg	esac
738263847c39Smrg	continue
738363847c39Smrg	;;
738463847c39Smrg
738563847c39Smrg      -no-undefined)
738663847c39Smrg	allow_undefined=no
738763847c39Smrg	continue
738863847c39Smrg	;;
738963847c39Smrg
739063847c39Smrg      -objectlist)
739163847c39Smrg	prev=objectlist
739263847c39Smrg	continue
739363847c39Smrg	;;
739463847c39Smrg
73950814a2baSmrg      -os2dllname)
73960814a2baSmrg	prev=os2dllname
73970814a2baSmrg	continue
73980814a2baSmrg	;;
73990814a2baSmrg
740063847c39Smrg      -o) prev=output ;;
740163847c39Smrg
740263847c39Smrg      -precious-files-regex)
740363847c39Smrg	prev=precious_regex
740463847c39Smrg	continue
740563847c39Smrg	;;
740663847c39Smrg
740763847c39Smrg      -release)
740863847c39Smrg	prev=release
740963847c39Smrg	continue
741063847c39Smrg	;;
741163847c39Smrg
741263847c39Smrg      -rpath)
741363847c39Smrg	prev=rpath
741463847c39Smrg	continue
741563847c39Smrg	;;
741663847c39Smrg
741763847c39Smrg      -R)
741863847c39Smrg	prev=xrpath
741963847c39Smrg	continue
742063847c39Smrg	;;
742163847c39Smrg
742263847c39Smrg      -R*)
742363847c39Smrg	func_stripname '-R' '' "$arg"
742463847c39Smrg	dir=$func_stripname_result
742563847c39Smrg	# We need an absolute path.
742663847c39Smrg	case $dir in
742763847c39Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
742863847c39Smrg	=*)
742963847c39Smrg	  func_stripname '=' '' "$dir"
743063847c39Smrg	  dir=$lt_sysroot$func_stripname_result
743163847c39Smrg	  ;;
743263847c39Smrg	*)
743363847c39Smrg	  func_fatal_error "only absolute run-paths are allowed"
743463847c39Smrg	  ;;
743563847c39Smrg	esac
743663847c39Smrg	case "$xrpath " in
743763847c39Smrg	*" $dir "*) ;;
743863847c39Smrg	*) func_append xrpath " $dir" ;;
743963847c39Smrg	esac
744063847c39Smrg	continue
744163847c39Smrg	;;
744263847c39Smrg
744363847c39Smrg      -shared)
744463847c39Smrg	# The effects of -shared are defined in a previous loop.
744563847c39Smrg	continue
744663847c39Smrg	;;
744763847c39Smrg
744863847c39Smrg      -shrext)
744963847c39Smrg	prev=shrext
745063847c39Smrg	continue
745163847c39Smrg	;;
745263847c39Smrg
745363847c39Smrg      -static | -static-libtool-libs)
745463847c39Smrg	# The effects of -static are defined in a previous loop.
745563847c39Smrg	# We used to do the same as -all-static on platforms that
745663847c39Smrg	# didn't have a PIC flag, but the assumption that the effects
745763847c39Smrg	# would be equivalent was wrong.  It would break on at least
745863847c39Smrg	# Digital Unix and AIX.
745963847c39Smrg	continue
746063847c39Smrg	;;
746163847c39Smrg
746263847c39Smrg      -thread-safe)
746363847c39Smrg	thread_safe=yes
746463847c39Smrg	continue
746563847c39Smrg	;;
746663847c39Smrg
746763847c39Smrg      -version-info)
746863847c39Smrg	prev=vinfo
746963847c39Smrg	continue
747063847c39Smrg	;;
747163847c39Smrg
747263847c39Smrg      -version-number)
747363847c39Smrg	prev=vinfo
747463847c39Smrg	vinfo_number=yes
747563847c39Smrg	continue
747663847c39Smrg	;;
747763847c39Smrg
747863847c39Smrg      -weak)
747963847c39Smrg        prev=weak
748063847c39Smrg	continue
748163847c39Smrg	;;
748263847c39Smrg
748363847c39Smrg      -Wc,*)
748463847c39Smrg	func_stripname '-Wc,' '' "$arg"
748563847c39Smrg	args=$func_stripname_result
748663847c39Smrg	arg=
74870814a2baSmrg	save_ifs=$IFS; IFS=,
748863847c39Smrg	for flag in $args; do
74890814a2baSmrg	  IFS=$save_ifs
74900814a2baSmrg          func_quote_arg pretty "$flag"
74910814a2baSmrg	  func_append arg " $func_quote_arg_result"
74920814a2baSmrg	  func_append compiler_flags " $func_quote_arg_result"
749363847c39Smrg	done
74940814a2baSmrg	IFS=$save_ifs
749563847c39Smrg	func_stripname ' ' '' "$arg"
749663847c39Smrg	arg=$func_stripname_result
749763847c39Smrg	;;
749863847c39Smrg
749963847c39Smrg      -Wl,*)
750063847c39Smrg	func_stripname '-Wl,' '' "$arg"
750163847c39Smrg	args=$func_stripname_result
750263847c39Smrg	arg=
75030814a2baSmrg	save_ifs=$IFS; IFS=,
750463847c39Smrg	for flag in $args; do
75050814a2baSmrg	  IFS=$save_ifs
75060814a2baSmrg          func_quote_arg pretty "$flag"
75070814a2baSmrg	  func_append arg " $wl$func_quote_arg_result"
75080814a2baSmrg	  func_append compiler_flags " $wl$func_quote_arg_result"
75090814a2baSmrg	  func_append linker_flags " $func_quote_arg_result"
751063847c39Smrg	done
75110814a2baSmrg	IFS=$save_ifs
751263847c39Smrg	func_stripname ' ' '' "$arg"
751363847c39Smrg	arg=$func_stripname_result
751463847c39Smrg	;;
751563847c39Smrg
75160814a2baSmrg      -Xassembler)
75170814a2baSmrg        prev=xassembler
75180814a2baSmrg        continue
75190814a2baSmrg        ;;
75200814a2baSmrg
752163847c39Smrg      -Xcompiler)
752263847c39Smrg	prev=xcompiler
752363847c39Smrg	continue
752463847c39Smrg	;;
752563847c39Smrg
752663847c39Smrg      -Xlinker)
752763847c39Smrg	prev=xlinker
752863847c39Smrg	continue
752963847c39Smrg	;;
753063847c39Smrg
753163847c39Smrg      -XCClinker)
753263847c39Smrg	prev=xcclinker
753363847c39Smrg	continue
753463847c39Smrg	;;
753563847c39Smrg
753663847c39Smrg      # -msg_* for osf cc
753763847c39Smrg      -msg_*)
75380814a2baSmrg	func_quote_arg pretty "$arg"
75390814a2baSmrg	arg=$func_quote_arg_result
754063847c39Smrg	;;
754163847c39Smrg
754263847c39Smrg      # Flags to be passed through unchanged, with rationale:
754363847c39Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
754463847c39Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
754563847c39Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
754663847c39Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754763847c39Smrg      # -q*                  compiler args for the IBM compiler
754863847c39Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754963847c39Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
755063847c39Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
75510814a2baSmrg      # -fstack-protector*   stack protector flags for GCC
755263847c39Smrg      # @file                GCC response files
755363847c39Smrg      # -tp=*                Portland pgcc target processor selection
755463847c39Smrg      # --sysroot=*          for sysroot support
75550814a2baSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75560814a2baSmrg      # -specs=*             GCC specs files
75570814a2baSmrg      # -stdlib=*            select c++ std lib with clang
75580814a2baSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75590814a2baSmrg      # -fuse-ld=*           Linker select flags for GCC
75600814a2baSmrg      # -Wa,*                Pass flags directly to the assembler
756163847c39Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
756263847c39Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75630814a2baSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
75640814a2baSmrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
75650814a2baSmrg        func_quote_arg pretty "$arg"
75660814a2baSmrg	arg=$func_quote_arg_result
756763847c39Smrg        func_append compile_command " $arg"
756863847c39Smrg        func_append finalize_command " $arg"
756963847c39Smrg        func_append compiler_flags " $arg"
757063847c39Smrg        continue
757163847c39Smrg        ;;
757263847c39Smrg
75730814a2baSmrg      -Z*)
75740814a2baSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
75750814a2baSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
75760814a2baSmrg	  compiler_flags="$compiler_flags $arg"
75770814a2baSmrg	  func_append compile_command " $arg"
75780814a2baSmrg	  func_append finalize_command " $arg"
75790814a2baSmrg	  case $arg in
75800814a2baSmrg	  -Zlinker | -Zstack)
75810814a2baSmrg	    prev=xcompiler
75820814a2baSmrg	    ;;
75830814a2baSmrg	  esac
75840814a2baSmrg	  continue
75850814a2baSmrg        else
75860814a2baSmrg	  # Otherwise treat like 'Some other compiler flag' below
75870814a2baSmrg	  func_quote_arg pretty "$arg"
75880814a2baSmrg	  arg=$func_quote_arg_result
75890814a2baSmrg        fi
75900814a2baSmrg	;;
75910814a2baSmrg
759263847c39Smrg      # Some other compiler flag.
759363847c39Smrg      -* | +*)
75940814a2baSmrg        func_quote_arg pretty "$arg"
75950814a2baSmrg	arg=$func_quote_arg_result
759663847c39Smrg	;;
759763847c39Smrg
759863847c39Smrg      *.$objext)
759963847c39Smrg	# A standard object.
760063847c39Smrg	func_append objs " $arg"
760163847c39Smrg	;;
760263847c39Smrg
760363847c39Smrg      *.lo)
760463847c39Smrg	# A libtool-controlled object.
760563847c39Smrg
760663847c39Smrg	# Check to see that this really is a libtool object.
760763847c39Smrg	if func_lalib_unsafe_p "$arg"; then
760863847c39Smrg	  pic_object=
760963847c39Smrg	  non_pic_object=
761063847c39Smrg
761163847c39Smrg	  # Read the .lo file
761263847c39Smrg	  func_source "$arg"
761363847c39Smrg
761463847c39Smrg	  if test -z "$pic_object" ||
761563847c39Smrg	     test -z "$non_pic_object" ||
76160814a2baSmrg	     test none = "$pic_object" &&
76170814a2baSmrg	     test none = "$non_pic_object"; then
76180814a2baSmrg	    func_fatal_error "cannot find name of object for '$arg'"
761963847c39Smrg	  fi
762063847c39Smrg
762163847c39Smrg	  # Extract subdirectory from the argument.
762263847c39Smrg	  func_dirname "$arg" "/" ""
76230814a2baSmrg	  xdir=$func_dirname_result
762463847c39Smrg
76250814a2baSmrg	  test none = "$pic_object" || {
762663847c39Smrg	    # Prepend the subdirectory the object is found in.
76270814a2baSmrg	    pic_object=$xdir$pic_object
762863847c39Smrg
76290814a2baSmrg	    if test dlfiles = "$prev"; then
76300814a2baSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
763163847c39Smrg		func_append dlfiles " $pic_object"
763263847c39Smrg		prev=
763363847c39Smrg		continue
763463847c39Smrg	      else
763563847c39Smrg		# If libtool objects are unsupported, then we need to preload.
763663847c39Smrg		prev=dlprefiles
763763847c39Smrg	      fi
763863847c39Smrg	    fi
763963847c39Smrg
764063847c39Smrg	    # CHECK ME:  I think I busted this.  -Ossama
76410814a2baSmrg	    if test dlprefiles = "$prev"; then
764263847c39Smrg	      # Preload the old-style object.
764363847c39Smrg	      func_append dlprefiles " $pic_object"
764463847c39Smrg	      prev=
764563847c39Smrg	    fi
764663847c39Smrg
764763847c39Smrg	    # A PIC object.
764863847c39Smrg	    func_append libobjs " $pic_object"
76490814a2baSmrg	    arg=$pic_object
76500814a2baSmrg	  }
765163847c39Smrg
765263847c39Smrg	  # Non-PIC object.
76530814a2baSmrg	  if test none != "$non_pic_object"; then
765463847c39Smrg	    # Prepend the subdirectory the object is found in.
76550814a2baSmrg	    non_pic_object=$xdir$non_pic_object
765663847c39Smrg
765763847c39Smrg	    # A standard non-PIC object
765863847c39Smrg	    func_append non_pic_objects " $non_pic_object"
76590814a2baSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
76600814a2baSmrg	      arg=$non_pic_object
766163847c39Smrg	    fi
766263847c39Smrg	  else
766363847c39Smrg	    # If the PIC object exists, use it instead.
766463847c39Smrg	    # $xdir was prepended to $pic_object above.
76650814a2baSmrg	    non_pic_object=$pic_object
766663847c39Smrg	    func_append non_pic_objects " $non_pic_object"
766763847c39Smrg	  fi
766863847c39Smrg	else
766963847c39Smrg	  # Only an error if not doing a dry-run.
767063847c39Smrg	  if $opt_dry_run; then
767163847c39Smrg	    # Extract subdirectory from the argument.
767263847c39Smrg	    func_dirname "$arg" "/" ""
76730814a2baSmrg	    xdir=$func_dirname_result
767463847c39Smrg
767563847c39Smrg	    func_lo2o "$arg"
767663847c39Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
767763847c39Smrg	    non_pic_object=$xdir$func_lo2o_result
767863847c39Smrg	    func_append libobjs " $pic_object"
767963847c39Smrg	    func_append non_pic_objects " $non_pic_object"
768063847c39Smrg	  else
76810814a2baSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
768263847c39Smrg	  fi
768363847c39Smrg	fi
768463847c39Smrg	;;
768563847c39Smrg
768663847c39Smrg      *.$libext)
768763847c39Smrg	# An archive.
768863847c39Smrg	func_append deplibs " $arg"
768963847c39Smrg	func_append old_deplibs " $arg"
769063847c39Smrg	continue
769163847c39Smrg	;;
769263847c39Smrg
769363847c39Smrg      *.la)
769463847c39Smrg	# A libtool-controlled library.
769563847c39Smrg
769663847c39Smrg	func_resolve_sysroot "$arg"
76970814a2baSmrg	if test dlfiles = "$prev"; then
769863847c39Smrg	  # This library was specified with -dlopen.
769963847c39Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
770063847c39Smrg	  prev=
77010814a2baSmrg	elif test dlprefiles = "$prev"; then
770263847c39Smrg	  # The library was specified with -dlpreopen.
770363847c39Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
770463847c39Smrg	  prev=
770563847c39Smrg	else
770663847c39Smrg	  func_append deplibs " $func_resolve_sysroot_result"
770763847c39Smrg	fi
770863847c39Smrg	continue
770963847c39Smrg	;;
771063847c39Smrg
771163847c39Smrg      # Some other compiler argument.
771263847c39Smrg      *)
771363847c39Smrg	# Unknown arguments in both finalize_command and compile_command need
771463847c39Smrg	# to be aesthetically quoted because they are evaled later.
77150814a2baSmrg	func_quote_arg pretty "$arg"
77160814a2baSmrg	arg=$func_quote_arg_result
771763847c39Smrg	;;
771863847c39Smrg      esac # arg
771963847c39Smrg
772063847c39Smrg      # Now actually substitute the argument into the commands.
772163847c39Smrg      if test -n "$arg"; then
772263847c39Smrg	func_append compile_command " $arg"
772363847c39Smrg	func_append finalize_command " $arg"
772463847c39Smrg      fi
772563847c39Smrg    done # argument parsing loop
772663847c39Smrg
772763847c39Smrg    test -n "$prev" && \
77280814a2baSmrg      func_fatal_help "the '$prevarg' option requires an argument"
772963847c39Smrg
77300814a2baSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
773163847c39Smrg      eval arg=\"$export_dynamic_flag_spec\"
773263847c39Smrg      func_append compile_command " $arg"
773363847c39Smrg      func_append finalize_command " $arg"
773463847c39Smrg    fi
773563847c39Smrg
773663847c39Smrg    oldlibs=
773763847c39Smrg    # calculate the name of the file, without its directory
773863847c39Smrg    func_basename "$output"
77390814a2baSmrg    outputname=$func_basename_result
77400814a2baSmrg    libobjs_save=$libobjs
774163847c39Smrg
774263847c39Smrg    if test -n "$shlibpath_var"; then
774363847c39Smrg      # get the directories listed in $shlibpath_var
77440814a2baSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
774563847c39Smrg    else
774663847c39Smrg      shlib_search_path=
774763847c39Smrg    fi
774863847c39Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
774963847c39Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
775063847c39Smrg
77510814a2baSmrg    # Definition is injected by LT_CONFIG during libtool generation.
77520814a2baSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
77530814a2baSmrg
775463847c39Smrg    func_dirname "$output" "/" ""
77550814a2baSmrg    output_objdir=$func_dirname_result$objdir
775663847c39Smrg    func_to_tool_file "$output_objdir/"
775763847c39Smrg    tool_output_objdir=$func_to_tool_file_result
775863847c39Smrg    # Create the object directory.
775963847c39Smrg    func_mkdir_p "$output_objdir"
776063847c39Smrg
776163847c39Smrg    # Determine the type of output
776263847c39Smrg    case $output in
776363847c39Smrg    "")
776463847c39Smrg      func_fatal_help "you must specify an output file"
776563847c39Smrg      ;;
776663847c39Smrg    *.$libext) linkmode=oldlib ;;
776763847c39Smrg    *.lo | *.$objext) linkmode=obj ;;
776863847c39Smrg    *.la) linkmode=lib ;;
776963847c39Smrg    *) linkmode=prog ;; # Anything else should be a program.
777063847c39Smrg    esac
777163847c39Smrg
777263847c39Smrg    specialdeplibs=
777363847c39Smrg
777463847c39Smrg    libs=
777563847c39Smrg    # Find all interdependent deplibs by searching for libraries
777663847c39Smrg    # that are linked more than once (e.g. -la -lb -la)
777763847c39Smrg    for deplib in $deplibs; do
77780814a2baSmrg      if $opt_preserve_dup_deps; then
777963847c39Smrg	case "$libs " in
778063847c39Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
778163847c39Smrg	esac
778263847c39Smrg      fi
778363847c39Smrg      func_append libs " $deplib"
778463847c39Smrg    done
778563847c39Smrg
77860814a2baSmrg    if test lib = "$linkmode"; then
778763847c39Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
778863847c39Smrg
778963847c39Smrg      # Compute libraries that are listed more than once in $predeps
779063847c39Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
779163847c39Smrg      # not to be eliminated).
779263847c39Smrg      pre_post_deps=
779363847c39Smrg      if $opt_duplicate_compiler_generated_deps; then
779463847c39Smrg	for pre_post_dep in $predeps $postdeps; do
779563847c39Smrg	  case "$pre_post_deps " in
779663847c39Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
779763847c39Smrg	  esac
779863847c39Smrg	  func_append pre_post_deps " $pre_post_dep"
779963847c39Smrg	done
780063847c39Smrg      fi
780163847c39Smrg      pre_post_deps=
780263847c39Smrg    fi
780363847c39Smrg
780463847c39Smrg    deplibs=
780563847c39Smrg    newdependency_libs=
780663847c39Smrg    newlib_search_path=
780763847c39Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
780863847c39Smrg    notinst_deplibs= # not-installed libtool libraries
780963847c39Smrg    notinst_path= # paths that contain not-installed libtool libraries
781063847c39Smrg
781163847c39Smrg    case $linkmode in
781263847c39Smrg    lib)
781363847c39Smrg	passes="conv dlpreopen link"
781463847c39Smrg	for file in $dlfiles $dlprefiles; do
781563847c39Smrg	  case $file in
781663847c39Smrg	  *.la) ;;
781763847c39Smrg	  *)
78180814a2baSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
781963847c39Smrg	    ;;
782063847c39Smrg	  esac
782163847c39Smrg	done
782263847c39Smrg	;;
782363847c39Smrg    prog)
782463847c39Smrg	compile_deplibs=
782563847c39Smrg	finalize_deplibs=
78260814a2baSmrg	alldeplibs=false
782763847c39Smrg	newdlfiles=
782863847c39Smrg	newdlprefiles=
782963847c39Smrg	passes="conv scan dlopen dlpreopen link"
783063847c39Smrg	;;
783163847c39Smrg    *)  passes="conv"
783263847c39Smrg	;;
783363847c39Smrg    esac
783463847c39Smrg
783563847c39Smrg    for pass in $passes; do
783663847c39Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
783763847c39Smrg      # so that -L comes before libs that need it for instance...
78380814a2baSmrg      if test lib,link = "$linkmode,$pass"; then
783963847c39Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
784063847c39Smrg	##        order, and fix it there properly
784163847c39Smrg        tmp_deplibs=
784263847c39Smrg	for deplib in $deplibs; do
784363847c39Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
784463847c39Smrg	done
78450814a2baSmrg	deplibs=$tmp_deplibs
784663847c39Smrg      fi
784763847c39Smrg
78480814a2baSmrg      if test lib,link = "$linkmode,$pass" ||
78490814a2baSmrg	 test prog,scan = "$linkmode,$pass"; then
78500814a2baSmrg	libs=$deplibs
785163847c39Smrg	deplibs=
785263847c39Smrg      fi
78530814a2baSmrg      if test prog = "$linkmode"; then
785463847c39Smrg	case $pass in
78550814a2baSmrg	dlopen) libs=$dlfiles ;;
78560814a2baSmrg	dlpreopen) libs=$dlprefiles ;;
78570814a2baSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
785863847c39Smrg	esac
785963847c39Smrg      fi
78600814a2baSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
786163847c39Smrg	# Collect and forward deplibs of preopened libtool libs
786263847c39Smrg	for lib in $dlprefiles; do
786363847c39Smrg	  # Ignore non-libtool-libs
786463847c39Smrg	  dependency_libs=
786563847c39Smrg	  func_resolve_sysroot "$lib"
786663847c39Smrg	  case $lib in
786763847c39Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
786863847c39Smrg	  esac
786963847c39Smrg
787063847c39Smrg	  # Collect preopened libtool deplibs, except any this library
787163847c39Smrg	  # has declared as weak libs
787263847c39Smrg	  for deplib in $dependency_libs; do
787363847c39Smrg	    func_basename "$deplib"
787463847c39Smrg            deplib_base=$func_basename_result
787563847c39Smrg	    case " $weak_libs " in
787663847c39Smrg	    *" $deplib_base "*) ;;
787763847c39Smrg	    *) func_append deplibs " $deplib" ;;
787863847c39Smrg	    esac
787963847c39Smrg	  done
788063847c39Smrg	done
78810814a2baSmrg	libs=$dlprefiles
788263847c39Smrg      fi
78830814a2baSmrg      if test dlopen = "$pass"; then
788463847c39Smrg	# Collect dlpreopened libraries
78850814a2baSmrg	save_deplibs=$deplibs
788663847c39Smrg	deplibs=
788763847c39Smrg      fi
788863847c39Smrg
788963847c39Smrg      for deplib in $libs; do
789063847c39Smrg	lib=
78910814a2baSmrg	found=false
789263847c39Smrg	case $deplib in
789363847c39Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
789463847c39Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
78950814a2baSmrg	  if test prog,link = "$linkmode,$pass"; then
789663847c39Smrg	    compile_deplibs="$deplib $compile_deplibs"
789763847c39Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
789863847c39Smrg	  else
789963847c39Smrg	    func_append compiler_flags " $deplib"
79000814a2baSmrg	    if test lib = "$linkmode"; then
790163847c39Smrg		case "$new_inherited_linker_flags " in
790263847c39Smrg		    *" $deplib "*) ;;
790363847c39Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
790463847c39Smrg		esac
790563847c39Smrg	    fi
790663847c39Smrg	  fi
790763847c39Smrg	  continue
790863847c39Smrg	  ;;
790963847c39Smrg	-l*)
79100814a2baSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
79110814a2baSmrg	    func_warning "'-l' is ignored for archives/objects"
791263847c39Smrg	    continue
791363847c39Smrg	  fi
791463847c39Smrg	  func_stripname '-l' '' "$deplib"
791563847c39Smrg	  name=$func_stripname_result
79160814a2baSmrg	  if test lib = "$linkmode"; then
791763847c39Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
791863847c39Smrg	  else
791963847c39Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
792063847c39Smrg	  fi
792163847c39Smrg	  for searchdir in $searchdirs; do
792263847c39Smrg	    for search_ext in .la $std_shrext .so .a; do
792363847c39Smrg	      # Search the libtool library
79240814a2baSmrg	      lib=$searchdir/lib$name$search_ext
792563847c39Smrg	      if test -f "$lib"; then
79260814a2baSmrg		if test .la = "$search_ext"; then
79270814a2baSmrg		  found=:
792863847c39Smrg		else
79290814a2baSmrg		  found=false
793063847c39Smrg		fi
793163847c39Smrg		break 2
793263847c39Smrg	      fi
793363847c39Smrg	    done
793463847c39Smrg	  done
79350814a2baSmrg	  if $found; then
79360814a2baSmrg	    # deplib is a libtool library
793763847c39Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
793863847c39Smrg	    # We need to do some special things here, and not later.
79390814a2baSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
794063847c39Smrg	      case " $predeps $postdeps " in
794163847c39Smrg	      *" $deplib "*)
794263847c39Smrg		if func_lalib_p "$lib"; then
794363847c39Smrg		  library_names=
794463847c39Smrg		  old_library=
794563847c39Smrg		  func_source "$lib"
794663847c39Smrg		  for l in $old_library $library_names; do
79470814a2baSmrg		    ll=$l
794863847c39Smrg		  done
79490814a2baSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
79500814a2baSmrg		    found=false
795163847c39Smrg		    func_dirname "$lib" "" "."
79520814a2baSmrg		    ladir=$func_dirname_result
795363847c39Smrg		    lib=$ladir/$old_library
79540814a2baSmrg		    if test prog,link = "$linkmode,$pass"; then
795563847c39Smrg		      compile_deplibs="$deplib $compile_deplibs"
795663847c39Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
795763847c39Smrg		    else
795863847c39Smrg		      deplibs="$deplib $deplibs"
79590814a2baSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
796063847c39Smrg		    fi
796163847c39Smrg		    continue
796263847c39Smrg		  fi
796363847c39Smrg		fi
796463847c39Smrg		;;
796563847c39Smrg	      *) ;;
796663847c39Smrg	      esac
796763847c39Smrg	    fi
79680814a2baSmrg	  else
79690814a2baSmrg	    # deplib doesn't seem to be a libtool library
79700814a2baSmrg	    if test prog,link = "$linkmode,$pass"; then
79710814a2baSmrg	      compile_deplibs="$deplib $compile_deplibs"
79720814a2baSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
79730814a2baSmrg	    else
79740814a2baSmrg	      deplibs="$deplib $deplibs"
79750814a2baSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79760814a2baSmrg	    fi
79770814a2baSmrg	    continue
797863847c39Smrg	  fi
797963847c39Smrg	  ;; # -l
798063847c39Smrg	*.ltframework)
79810814a2baSmrg	  if test prog,link = "$linkmode,$pass"; then
798263847c39Smrg	    compile_deplibs="$deplib $compile_deplibs"
798363847c39Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
798463847c39Smrg	  else
798563847c39Smrg	    deplibs="$deplib $deplibs"
79860814a2baSmrg	    if test lib = "$linkmode"; then
798763847c39Smrg		case "$new_inherited_linker_flags " in
798863847c39Smrg		    *" $deplib "*) ;;
798963847c39Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
799063847c39Smrg		esac
799163847c39Smrg	    fi
799263847c39Smrg	  fi
799363847c39Smrg	  continue
799463847c39Smrg	  ;;
799563847c39Smrg	-L*)
799663847c39Smrg	  case $linkmode in
799763847c39Smrg	  lib)
799863847c39Smrg	    deplibs="$deplib $deplibs"
79990814a2baSmrg	    test conv = "$pass" && continue
800063847c39Smrg	    newdependency_libs="$deplib $newdependency_libs"
800163847c39Smrg	    func_stripname '-L' '' "$deplib"
800263847c39Smrg	    func_resolve_sysroot "$func_stripname_result"
800363847c39Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
800463847c39Smrg	    ;;
800563847c39Smrg	  prog)
80060814a2baSmrg	    if test conv = "$pass"; then
800763847c39Smrg	      deplibs="$deplib $deplibs"
800863847c39Smrg	      continue
800963847c39Smrg	    fi
80100814a2baSmrg	    if test scan = "$pass"; then
801163847c39Smrg	      deplibs="$deplib $deplibs"
801263847c39Smrg	    else
801363847c39Smrg	      compile_deplibs="$deplib $compile_deplibs"
801463847c39Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
801563847c39Smrg	    fi
801663847c39Smrg	    func_stripname '-L' '' "$deplib"
801763847c39Smrg	    func_resolve_sysroot "$func_stripname_result"
801863847c39Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
801963847c39Smrg	    ;;
802063847c39Smrg	  *)
80210814a2baSmrg	    func_warning "'-L' is ignored for archives/objects"
802263847c39Smrg	    ;;
802363847c39Smrg	  esac # linkmode
802463847c39Smrg	  continue
802563847c39Smrg	  ;; # -L
802663847c39Smrg	-R*)
80270814a2baSmrg	  if test link = "$pass"; then
802863847c39Smrg	    func_stripname '-R' '' "$deplib"
802963847c39Smrg	    func_resolve_sysroot "$func_stripname_result"
803063847c39Smrg	    dir=$func_resolve_sysroot_result
803163847c39Smrg	    # Make sure the xrpath contains only unique directories.
803263847c39Smrg	    case "$xrpath " in
803363847c39Smrg	    *" $dir "*) ;;
803463847c39Smrg	    *) func_append xrpath " $dir" ;;
803563847c39Smrg	    esac
803663847c39Smrg	  fi
803763847c39Smrg	  deplibs="$deplib $deplibs"
803863847c39Smrg	  continue
803963847c39Smrg	  ;;
804063847c39Smrg	*.la)
804163847c39Smrg	  func_resolve_sysroot "$deplib"
804263847c39Smrg	  lib=$func_resolve_sysroot_result
804363847c39Smrg	  ;;
804463847c39Smrg	*.$libext)
80450814a2baSmrg	  if test conv = "$pass"; then
804663847c39Smrg	    deplibs="$deplib $deplibs"
804763847c39Smrg	    continue
804863847c39Smrg	  fi
804963847c39Smrg	  case $linkmode in
805063847c39Smrg	  lib)
805163847c39Smrg	    # Linking convenience modules into shared libraries is allowed,
805263847c39Smrg	    # but linking other static libraries is non-portable.
805363847c39Smrg	    case " $dlpreconveniencelibs " in
805463847c39Smrg	    *" $deplib "*) ;;
805563847c39Smrg	    *)
80560814a2baSmrg	      valid_a_lib=false
805763847c39Smrg	      case $deplibs_check_method in
805863847c39Smrg		match_pattern*)
805963847c39Smrg		  set dummy $deplibs_check_method; shift
806063847c39Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
806163847c39Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
806263847c39Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
80630814a2baSmrg		    valid_a_lib=:
806463847c39Smrg		  fi
806563847c39Smrg		;;
806663847c39Smrg		pass_all)
80670814a2baSmrg		  valid_a_lib=:
806863847c39Smrg		;;
806963847c39Smrg	      esac
80700814a2baSmrg	      if $valid_a_lib; then
80710814a2baSmrg		echo
80720814a2baSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
80730814a2baSmrg		$ECHO "*** static library $deplib is not portable!"
80740814a2baSmrg		deplibs="$deplib $deplibs"
80750814a2baSmrg	      else
807663847c39Smrg		echo
807763847c39Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807863847c39Smrg		echo "*** I have the capability to make that library automatically link in when"
807963847c39Smrg		echo "*** you link to this library.  But I can only do this if you have a"
808063847c39Smrg		echo "*** shared version of the library, which you do not appear to have"
808163847c39Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
808263847c39Smrg		echo "*** that it is just a static archive that I should not use here."
808363847c39Smrg	      fi
808463847c39Smrg	      ;;
808563847c39Smrg	    esac
808663847c39Smrg	    continue
808763847c39Smrg	    ;;
808863847c39Smrg	  prog)
80890814a2baSmrg	    if test link != "$pass"; then
809063847c39Smrg	      deplibs="$deplib $deplibs"
809163847c39Smrg	    else
809263847c39Smrg	      compile_deplibs="$deplib $compile_deplibs"
809363847c39Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
809463847c39Smrg	    fi
809563847c39Smrg	    continue
809663847c39Smrg	    ;;
809763847c39Smrg	  esac # linkmode
809863847c39Smrg	  ;; # *.$libext
809963847c39Smrg	*.lo | *.$objext)
81000814a2baSmrg	  if test conv = "$pass"; then
810163847c39Smrg	    deplibs="$deplib $deplibs"
81020814a2baSmrg	  elif test prog = "$linkmode"; then
81030814a2baSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
810463847c39Smrg	      # If there is no dlopen support or we're linking statically,
810563847c39Smrg	      # we need to preload.
810663847c39Smrg	      func_append newdlprefiles " $deplib"
810763847c39Smrg	      compile_deplibs="$deplib $compile_deplibs"
810863847c39Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
810963847c39Smrg	    else
811063847c39Smrg	      func_append newdlfiles " $deplib"
811163847c39Smrg	    fi
811263847c39Smrg	  fi
811363847c39Smrg	  continue
811463847c39Smrg	  ;;
811563847c39Smrg	%DEPLIBS%)
81160814a2baSmrg	  alldeplibs=:
811763847c39Smrg	  continue
811863847c39Smrg	  ;;
811963847c39Smrg	esac # case $deplib
812063847c39Smrg
81210814a2baSmrg	$found || test -f "$lib" \
81220814a2baSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
812363847c39Smrg
812463847c39Smrg	# Check to see that this really is a libtool archive.
812563847c39Smrg	func_lalib_unsafe_p "$lib" \
81260814a2baSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
812763847c39Smrg
812863847c39Smrg	func_dirname "$lib" "" "."
81290814a2baSmrg	ladir=$func_dirname_result
813063847c39Smrg
813163847c39Smrg	dlname=
813263847c39Smrg	dlopen=
813363847c39Smrg	dlpreopen=
813463847c39Smrg	libdir=
813563847c39Smrg	library_names=
813663847c39Smrg	old_library=
813763847c39Smrg	inherited_linker_flags=
813863847c39Smrg	# If the library was installed with an old release of libtool,
813963847c39Smrg	# it will not redefine variables installed, or shouldnotlink
814063847c39Smrg	installed=yes
814163847c39Smrg	shouldnotlink=no
814263847c39Smrg	avoidtemprpath=
814363847c39Smrg
814463847c39Smrg
814563847c39Smrg	# Read the .la file
814663847c39Smrg	func_source "$lib"
814763847c39Smrg
814863847c39Smrg	# Convert "-framework foo" to "foo.ltframework"
814963847c39Smrg	if test -n "$inherited_linker_flags"; then
815063847c39Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
815163847c39Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
815263847c39Smrg	    case " $new_inherited_linker_flags " in
815363847c39Smrg	      *" $tmp_inherited_linker_flag "*) ;;
815463847c39Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
815563847c39Smrg	    esac
815663847c39Smrg	  done
815763847c39Smrg	fi
815863847c39Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
81590814a2baSmrg	if test lib,link = "$linkmode,$pass" ||
81600814a2baSmrg	   test prog,scan = "$linkmode,$pass" ||
81610814a2baSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
816263847c39Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
816363847c39Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
816463847c39Smrg	fi
816563847c39Smrg
81660814a2baSmrg	if test conv = "$pass"; then
816763847c39Smrg	  # Only check for convenience libraries
816863847c39Smrg	  deplibs="$lib $deplibs"
816963847c39Smrg	  if test -z "$libdir"; then
817063847c39Smrg	    if test -z "$old_library"; then
81710814a2baSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
817263847c39Smrg	    fi
817363847c39Smrg	    # It is a libtool convenience library, so add in its objects.
817463847c39Smrg	    func_append convenience " $ladir/$objdir/$old_library"
817563847c39Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
81760814a2baSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
81770814a2baSmrg	    func_fatal_error "'$lib' is not a convenience library"
817863847c39Smrg	  fi
81790814a2baSmrg	  tmp_libs=
81800814a2baSmrg	  for deplib in $dependency_libs; do
81810814a2baSmrg	    deplibs="$deplib $deplibs"
81820814a2baSmrg	    if $opt_preserve_dup_deps; then
81830814a2baSmrg	      case "$tmp_libs " in
81840814a2baSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
81850814a2baSmrg	      esac
81860814a2baSmrg	    fi
81870814a2baSmrg	    func_append tmp_libs " $deplib"
81880814a2baSmrg	  done
818963847c39Smrg	  continue
819063847c39Smrg	fi # $pass = conv
819163847c39Smrg
819263847c39Smrg
819363847c39Smrg	# Get the name of the library we link against.
819463847c39Smrg	linklib=
819563847c39Smrg	if test -n "$old_library" &&
81960814a2baSmrg	   { test yes = "$prefer_static_libs" ||
81970814a2baSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
819863847c39Smrg	  linklib=$old_library
819963847c39Smrg	else
820063847c39Smrg	  for l in $old_library $library_names; do
82010814a2baSmrg	    linklib=$l
820263847c39Smrg	  done
820363847c39Smrg	fi
820463847c39Smrg	if test -z "$linklib"; then
82050814a2baSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
820663847c39Smrg	fi
820763847c39Smrg
820863847c39Smrg	# This library was specified with -dlopen.
82090814a2baSmrg	if test dlopen = "$pass"; then
82100814a2baSmrg	  test -z "$libdir" \
82110814a2baSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
821263847c39Smrg	  if test -z "$dlname" ||
82130814a2baSmrg	     test yes != "$dlopen_support" ||
82140814a2baSmrg	     test no = "$build_libtool_libs"
82150814a2baSmrg	  then
821663847c39Smrg	    # If there is no dlname, no dlopen support or we're linking
821763847c39Smrg	    # statically, we need to preload.  We also need to preload any
821863847c39Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
821963847c39Smrg	    # bomb out in the load deplibs phase.
822063847c39Smrg	    func_append dlprefiles " $lib $dependency_libs"
822163847c39Smrg	  else
822263847c39Smrg	    func_append newdlfiles " $lib"
822363847c39Smrg	  fi
822463847c39Smrg	  continue
822563847c39Smrg	fi # $pass = dlopen
822663847c39Smrg
822763847c39Smrg	# We need an absolute path.
822863847c39Smrg	case $ladir in
82290814a2baSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
823063847c39Smrg	*)
823163847c39Smrg	  abs_ladir=`cd "$ladir" && pwd`
823263847c39Smrg	  if test -z "$abs_ladir"; then
82330814a2baSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
823463847c39Smrg	    func_warning "passing it literally to the linker, although it might fail"
82350814a2baSmrg	    abs_ladir=$ladir
823663847c39Smrg	  fi
823763847c39Smrg	  ;;
823863847c39Smrg	esac
823963847c39Smrg	func_basename "$lib"
82400814a2baSmrg	laname=$func_basename_result
824163847c39Smrg
824263847c39Smrg	# Find the relevant object directory and library name.
82430814a2baSmrg	if test yes = "$installed"; then
824463847c39Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82450814a2baSmrg	    func_warning "library '$lib' was moved."
82460814a2baSmrg	    dir=$ladir
82470814a2baSmrg	    absdir=$abs_ladir
82480814a2baSmrg	    libdir=$abs_ladir
824963847c39Smrg	  else
82500814a2baSmrg	    dir=$lt_sysroot$libdir
82510814a2baSmrg	    absdir=$lt_sysroot$libdir
825263847c39Smrg	  fi
82530814a2baSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
825463847c39Smrg	else
825563847c39Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82560814a2baSmrg	    dir=$ladir
82570814a2baSmrg	    absdir=$abs_ladir
825863847c39Smrg	    # Remove this search path later
825963847c39Smrg	    func_append notinst_path " $abs_ladir"
826063847c39Smrg	  else
82610814a2baSmrg	    dir=$ladir/$objdir
82620814a2baSmrg	    absdir=$abs_ladir/$objdir
826363847c39Smrg	    # Remove this search path later
826463847c39Smrg	    func_append notinst_path " $abs_ladir"
826563847c39Smrg	  fi
826663847c39Smrg	fi # $installed = yes
826763847c39Smrg	func_stripname 'lib' '.la' "$laname"
826863847c39Smrg	name=$func_stripname_result
826963847c39Smrg
827063847c39Smrg	# This library was specified with -dlpreopen.
82710814a2baSmrg	if test dlpreopen = "$pass"; then
82720814a2baSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
82730814a2baSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
827463847c39Smrg	  fi
82750814a2baSmrg	  case $host in
827663847c39Smrg	    # special handling for platforms with PE-DLLs.
827763847c39Smrg	    *cygwin* | *mingw* | *cegcc* )
827863847c39Smrg	      # Linker will automatically link against shared library if both
827963847c39Smrg	      # static and shared are present.  Therefore, ensure we extract
828063847c39Smrg	      # symbols from the import library if a shared library is present
828163847c39Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
828263847c39Smrg	      # this by putting the import library name into $newdlprefiles.
828363847c39Smrg	      # We recover the dlopen module name by 'saving' the la file
828463847c39Smrg	      # name in a special purpose variable, and (later) extracting the
828563847c39Smrg	      # dlname from the la file.
828663847c39Smrg	      if test -n "$dlname"; then
828763847c39Smrg	        func_tr_sh "$dir/$linklib"
828863847c39Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
828963847c39Smrg	        func_append newdlprefiles " $dir/$linklib"
829063847c39Smrg	      else
829163847c39Smrg	        func_append newdlprefiles " $dir/$old_library"
829263847c39Smrg	        # Keep a list of preopened convenience libraries to check
829363847c39Smrg	        # that they are being used correctly in the link pass.
829463847c39Smrg	        test -z "$libdir" && \
829563847c39Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
829663847c39Smrg	      fi
829763847c39Smrg	    ;;
829863847c39Smrg	    * )
829963847c39Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
830063847c39Smrg	      # are required to link).
830163847c39Smrg	      if test -n "$old_library"; then
830263847c39Smrg	        func_append newdlprefiles " $dir/$old_library"
830363847c39Smrg	        # Keep a list of preopened convenience libraries to check
830463847c39Smrg	        # that they are being used correctly in the link pass.
830563847c39Smrg	        test -z "$libdir" && \
830663847c39Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
830763847c39Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
830863847c39Smrg	      elif test -n "$dlname"; then
830963847c39Smrg	        func_append newdlprefiles " $dir/$dlname"
831063847c39Smrg	      else
831163847c39Smrg	        func_append newdlprefiles " $dir/$linklib"
831263847c39Smrg	      fi
831363847c39Smrg	    ;;
831463847c39Smrg	  esac
831563847c39Smrg	fi # $pass = dlpreopen
831663847c39Smrg
831763847c39Smrg	if test -z "$libdir"; then
831863847c39Smrg	  # Link the convenience library
83190814a2baSmrg	  if test lib = "$linkmode"; then
832063847c39Smrg	    deplibs="$dir/$old_library $deplibs"
83210814a2baSmrg	  elif test prog,link = "$linkmode,$pass"; then
832263847c39Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
832363847c39Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
832463847c39Smrg	  else
832563847c39Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
832663847c39Smrg	  fi
832763847c39Smrg	  continue
832863847c39Smrg	fi
832963847c39Smrg
833063847c39Smrg
83310814a2baSmrg	if test prog = "$linkmode" && test link != "$pass"; then
833263847c39Smrg	  func_append newlib_search_path " $ladir"
833363847c39Smrg	  deplibs="$lib $deplibs"
833463847c39Smrg
83350814a2baSmrg	  linkalldeplibs=false
83360814a2baSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
83370814a2baSmrg	     test no = "$build_libtool_libs"; then
83380814a2baSmrg	    linkalldeplibs=:
833963847c39Smrg	  fi
834063847c39Smrg
834163847c39Smrg	  tmp_libs=
834263847c39Smrg	  for deplib in $dependency_libs; do
834363847c39Smrg	    case $deplib in
834463847c39Smrg	    -L*) func_stripname '-L' '' "$deplib"
834563847c39Smrg	         func_resolve_sysroot "$func_stripname_result"
834663847c39Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
834763847c39Smrg		 ;;
834863847c39Smrg	    esac
834963847c39Smrg	    # Need to link against all dependency_libs?
83500814a2baSmrg	    if $linkalldeplibs; then
835163847c39Smrg	      deplibs="$deplib $deplibs"
835263847c39Smrg	    else
835363847c39Smrg	      # Need to hardcode shared library paths
835463847c39Smrg	      # or/and link against static libraries
835563847c39Smrg	      newdependency_libs="$deplib $newdependency_libs"
835663847c39Smrg	    fi
83570814a2baSmrg	    if $opt_preserve_dup_deps; then
835863847c39Smrg	      case "$tmp_libs " in
835963847c39Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
836063847c39Smrg	      esac
836163847c39Smrg	    fi
836263847c39Smrg	    func_append tmp_libs " $deplib"
836363847c39Smrg	  done # for deplib
836463847c39Smrg	  continue
836563847c39Smrg	fi # $linkmode = prog...
836663847c39Smrg
83670814a2baSmrg	if test prog,link = "$linkmode,$pass"; then
836863847c39Smrg	  if test -n "$library_names" &&
83690814a2baSmrg	     { { test no = "$prefer_static_libs" ||
83700814a2baSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
837163847c39Smrg	       test -z "$old_library"; }; then
837263847c39Smrg	    # We need to hardcode the library path
83730814a2baSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
837463847c39Smrg	      # Make sure the rpath contains only unique directories.
83750814a2baSmrg	      case $temp_rpath: in
837663847c39Smrg	      *"$absdir:"*) ;;
837763847c39Smrg	      *) func_append temp_rpath "$absdir:" ;;
837863847c39Smrg	      esac
837963847c39Smrg	    fi
838063847c39Smrg
838163847c39Smrg	    # Hardcode the library path.
838263847c39Smrg	    # Skip directories that are in the system default run-time
838363847c39Smrg	    # search path.
838463847c39Smrg	    case " $sys_lib_dlsearch_path " in
838563847c39Smrg	    *" $absdir "*) ;;
838663847c39Smrg	    *)
838763847c39Smrg	      case "$compile_rpath " in
838863847c39Smrg	      *" $absdir "*) ;;
838963847c39Smrg	      *) func_append compile_rpath " $absdir" ;;
839063847c39Smrg	      esac
839163847c39Smrg	      ;;
839263847c39Smrg	    esac
839363847c39Smrg	    case " $sys_lib_dlsearch_path " in
839463847c39Smrg	    *" $libdir "*) ;;
839563847c39Smrg	    *)
839663847c39Smrg	      case "$finalize_rpath " in
839763847c39Smrg	      *" $libdir "*) ;;
839863847c39Smrg	      *) func_append finalize_rpath " $libdir" ;;
839963847c39Smrg	      esac
840063847c39Smrg	      ;;
840163847c39Smrg	    esac
840263847c39Smrg	  fi # $linkmode,$pass = prog,link...
840363847c39Smrg
84040814a2baSmrg	  if $alldeplibs &&
84050814a2baSmrg	     { test pass_all = "$deplibs_check_method" ||
84060814a2baSmrg	       { test yes = "$build_libtool_libs" &&
840763847c39Smrg		 test -n "$library_names"; }; }; then
840863847c39Smrg	    # We only need to search for static libraries
840963847c39Smrg	    continue
841063847c39Smrg	  fi
841163847c39Smrg	fi
841263847c39Smrg
841363847c39Smrg	link_static=no # Whether the deplib will be linked statically
841463847c39Smrg	use_static_libs=$prefer_static_libs
84150814a2baSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
841663847c39Smrg	  use_static_libs=no
841763847c39Smrg	fi
841863847c39Smrg	if test -n "$library_names" &&
84190814a2baSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
842063847c39Smrg	  case $host in
84210814a2baSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
842263847c39Smrg	      # No point in relinking DLLs because paths are not encoded
842363847c39Smrg	      func_append notinst_deplibs " $lib"
842463847c39Smrg	      need_relink=no
842563847c39Smrg	    ;;
842663847c39Smrg	  *)
84270814a2baSmrg	    if test no = "$installed"; then
842863847c39Smrg	      func_append notinst_deplibs " $lib"
842963847c39Smrg	      need_relink=yes
843063847c39Smrg	    fi
843163847c39Smrg	    ;;
843263847c39Smrg	  esac
843363847c39Smrg	  # This is a shared library
843463847c39Smrg
843563847c39Smrg	  # Warn about portability, can't link against -module's on some
843663847c39Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
84370814a2baSmrg	  dlopenmodule=
843863847c39Smrg	  for dlpremoduletest in $dlprefiles; do
843963847c39Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
84400814a2baSmrg	      dlopenmodule=$dlpremoduletest
844163847c39Smrg	      break
844263847c39Smrg	    fi
844363847c39Smrg	  done
84440814a2baSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
844563847c39Smrg	    echo
84460814a2baSmrg	    if test prog = "$linkmode"; then
844763847c39Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
844863847c39Smrg	    else
844963847c39Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
845063847c39Smrg	    fi
845163847c39Smrg	    $ECHO "*** $linklib is not portable!"
845263847c39Smrg	  fi
84530814a2baSmrg	  if test lib = "$linkmode" &&
84540814a2baSmrg	     test yes = "$hardcode_into_libs"; then
845563847c39Smrg	    # Hardcode the library path.
845663847c39Smrg	    # Skip directories that are in the system default run-time
845763847c39Smrg	    # search path.
845863847c39Smrg	    case " $sys_lib_dlsearch_path " in
845963847c39Smrg	    *" $absdir "*) ;;
846063847c39Smrg	    *)
846163847c39Smrg	      case "$compile_rpath " in
846263847c39Smrg	      *" $absdir "*) ;;
846363847c39Smrg	      *) func_append compile_rpath " $absdir" ;;
846463847c39Smrg	      esac
846563847c39Smrg	      ;;
846663847c39Smrg	    esac
846763847c39Smrg	    case " $sys_lib_dlsearch_path " in
846863847c39Smrg	    *" $libdir "*) ;;
846963847c39Smrg	    *)
847063847c39Smrg	      case "$finalize_rpath " in
847163847c39Smrg	      *" $libdir "*) ;;
847263847c39Smrg	      *) func_append finalize_rpath " $libdir" ;;
847363847c39Smrg	      esac
847463847c39Smrg	      ;;
847563847c39Smrg	    esac
847663847c39Smrg	  fi
847763847c39Smrg
847863847c39Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
847963847c39Smrg	    # figure out the soname
848063847c39Smrg	    set dummy $library_names
848163847c39Smrg	    shift
84820814a2baSmrg	    realname=$1
848363847c39Smrg	    shift
848463847c39Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
848563847c39Smrg	    # use dlname if we got it. it's perfectly good, no?
848663847c39Smrg	    if test -n "$dlname"; then
84870814a2baSmrg	      soname=$dlname
848863847c39Smrg	    elif test -n "$soname_spec"; then
848963847c39Smrg	      # bleh windows
849063847c39Smrg	      case $host in
84910814a2baSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
849263847c39Smrg	        func_arith $current - $age
849363847c39Smrg		major=$func_arith_result
84940814a2baSmrg		versuffix=-$major
849563847c39Smrg		;;
849663847c39Smrg	      esac
849763847c39Smrg	      eval soname=\"$soname_spec\"
849863847c39Smrg	    else
84990814a2baSmrg	      soname=$realname
850063847c39Smrg	    fi
850163847c39Smrg
850263847c39Smrg	    # Make a new name for the extract_expsyms_cmds to use
85030814a2baSmrg	    soroot=$soname
850463847c39Smrg	    func_basename "$soroot"
85050814a2baSmrg	    soname=$func_basename_result
850663847c39Smrg	    func_stripname 'lib' '.dll' "$soname"
850763847c39Smrg	    newlib=libimp-$func_stripname_result.a
850863847c39Smrg
850963847c39Smrg	    # If the library has no export list, then create one now
851063847c39Smrg	    if test -f "$output_objdir/$soname-def"; then :
851163847c39Smrg	    else
85120814a2baSmrg	      func_verbose "extracting exported symbol list from '$soname'"
851363847c39Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
851463847c39Smrg	    fi
851563847c39Smrg
851663847c39Smrg	    # Create $newlib
851763847c39Smrg	    if test -f "$output_objdir/$newlib"; then :; else
85180814a2baSmrg	      func_verbose "generating import library for '$soname'"
851963847c39Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
852063847c39Smrg	    fi
852163847c39Smrg	    # make sure the library variables are pointing to the new library
852263847c39Smrg	    dir=$output_objdir
852363847c39Smrg	    linklib=$newlib
852463847c39Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
852563847c39Smrg
85260814a2baSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
852763847c39Smrg	    add_shlibpath=
852863847c39Smrg	    add_dir=
852963847c39Smrg	    add=
853063847c39Smrg	    lib_linked=yes
853163847c39Smrg	    case $hardcode_action in
853263847c39Smrg	    immediate | unsupported)
85330814a2baSmrg	      if test no = "$hardcode_direct"; then
85340814a2baSmrg		add=$dir/$linklib
853563847c39Smrg		case $host in
85360814a2baSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
85370814a2baSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
853863847c39Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
85390814a2baSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
854063847c39Smrg		  *-*-darwin* )
85410814a2baSmrg		    # if the lib is a (non-dlopened) module then we cannot
854263847c39Smrg		    # link against it, someone is ignoring the earlier warnings
854363847c39Smrg		    if /usr/bin/file -L $add 2> /dev/null |
85440814a2baSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
854563847c39Smrg		      if test "X$dlopenmodule" != "X$lib"; then
854663847c39Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
85470814a2baSmrg			if test -z "$old_library"; then
854863847c39Smrg			  echo
854963847c39Smrg			  echo "*** And there doesn't seem to be a static archive available"
855063847c39Smrg			  echo "*** The link will probably fail, sorry"
855163847c39Smrg			else
85520814a2baSmrg			  add=$dir/$old_library
855363847c39Smrg			fi
855463847c39Smrg		      elif test -n "$old_library"; then
85550814a2baSmrg			add=$dir/$old_library
855663847c39Smrg		      fi
855763847c39Smrg		    fi
855863847c39Smrg		esac
85590814a2baSmrg	      elif test no = "$hardcode_minus_L"; then
856063847c39Smrg		case $host in
85610814a2baSmrg		*-*-sunos*) add_shlibpath=$dir ;;
856263847c39Smrg		esac
85630814a2baSmrg		add_dir=-L$dir
85640814a2baSmrg		add=-l$name
85650814a2baSmrg	      elif test no = "$hardcode_shlibpath_var"; then
85660814a2baSmrg		add_shlibpath=$dir
85670814a2baSmrg		add=-l$name
856863847c39Smrg	      else
856963847c39Smrg		lib_linked=no
857063847c39Smrg	      fi
857163847c39Smrg	      ;;
857263847c39Smrg	    relink)
85730814a2baSmrg	      if test yes = "$hardcode_direct" &&
85740814a2baSmrg	         test no = "$hardcode_direct_absolute"; then
85750814a2baSmrg		add=$dir/$linklib
85760814a2baSmrg	      elif test yes = "$hardcode_minus_L"; then
85770814a2baSmrg		add_dir=-L$absdir
857863847c39Smrg		# Try looking first in the location we're being installed to.
857963847c39Smrg		if test -n "$inst_prefix_dir"; then
858063847c39Smrg		  case $libdir in
858163847c39Smrg		    [\\/]*)
858263847c39Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
858363847c39Smrg		      ;;
858463847c39Smrg		  esac
858563847c39Smrg		fi
85860814a2baSmrg		add=-l$name
85870814a2baSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
85880814a2baSmrg		add_shlibpath=$dir
85890814a2baSmrg		add=-l$name
859063847c39Smrg	      else
859163847c39Smrg		lib_linked=no
859263847c39Smrg	      fi
859363847c39Smrg	      ;;
859463847c39Smrg	    *) lib_linked=no ;;
859563847c39Smrg	    esac
859663847c39Smrg
85970814a2baSmrg	    if test yes != "$lib_linked"; then
859863847c39Smrg	      func_fatal_configuration "unsupported hardcode properties"
859963847c39Smrg	    fi
860063847c39Smrg
860163847c39Smrg	    if test -n "$add_shlibpath"; then
860263847c39Smrg	      case :$compile_shlibpath: in
860363847c39Smrg	      *":$add_shlibpath:"*) ;;
860463847c39Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
860563847c39Smrg	      esac
860663847c39Smrg	    fi
86070814a2baSmrg	    if test prog = "$linkmode"; then
860863847c39Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
860963847c39Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
861063847c39Smrg	    else
861163847c39Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
861263847c39Smrg	      test -n "$add" && deplibs="$add $deplibs"
86130814a2baSmrg	      if test yes != "$hardcode_direct" &&
86140814a2baSmrg		 test yes != "$hardcode_minus_L" &&
86150814a2baSmrg		 test yes = "$hardcode_shlibpath_var"; then
861663847c39Smrg		case :$finalize_shlibpath: in
861763847c39Smrg		*":$libdir:"*) ;;
861863847c39Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
861963847c39Smrg		esac
862063847c39Smrg	      fi
862163847c39Smrg	    fi
862263847c39Smrg	  fi
862363847c39Smrg
86240814a2baSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
862563847c39Smrg	    add_shlibpath=
862663847c39Smrg	    add_dir=
862763847c39Smrg	    add=
862863847c39Smrg	    # Finalize command for both is simple: just hardcode it.
86290814a2baSmrg	    if test yes = "$hardcode_direct" &&
86300814a2baSmrg	       test no = "$hardcode_direct_absolute"; then
86310814a2baSmrg	      add=$libdir/$linklib
86320814a2baSmrg	    elif test yes = "$hardcode_minus_L"; then
86330814a2baSmrg	      add_dir=-L$libdir
86340814a2baSmrg	      add=-l$name
86350814a2baSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
863663847c39Smrg	      case :$finalize_shlibpath: in
863763847c39Smrg	      *":$libdir:"*) ;;
863863847c39Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
863963847c39Smrg	      esac
86400814a2baSmrg	      add=-l$name
86410814a2baSmrg	    elif test yes = "$hardcode_automatic"; then
864263847c39Smrg	      if test -n "$inst_prefix_dir" &&
86430814a2baSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
86440814a2baSmrg		add=$inst_prefix_dir$libdir/$linklib
864563847c39Smrg	      else
86460814a2baSmrg		add=$libdir/$linklib
864763847c39Smrg	      fi
864863847c39Smrg	    else
864963847c39Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
86500814a2baSmrg	      add_dir=-L$libdir
865163847c39Smrg	      # Try looking first in the location we're being installed to.
865263847c39Smrg	      if test -n "$inst_prefix_dir"; then
865363847c39Smrg		case $libdir in
865463847c39Smrg		  [\\/]*)
865563847c39Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
865663847c39Smrg		    ;;
865763847c39Smrg		esac
865863847c39Smrg	      fi
86590814a2baSmrg	      add=-l$name
866063847c39Smrg	    fi
866163847c39Smrg
86620814a2baSmrg	    if test prog = "$linkmode"; then
866363847c39Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
866463847c39Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
866563847c39Smrg	    else
866663847c39Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
866763847c39Smrg	      test -n "$add" && deplibs="$add $deplibs"
866863847c39Smrg	    fi
866963847c39Smrg	  fi
86700814a2baSmrg	elif test prog = "$linkmode"; then
867163847c39Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
867263847c39Smrg	  # is not unsupported.  This is valid on all known static and
867363847c39Smrg	  # shared platforms.
86740814a2baSmrg	  if test unsupported != "$hardcode_direct"; then
86750814a2baSmrg	    test -n "$old_library" && linklib=$old_library
867663847c39Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
867763847c39Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
867863847c39Smrg	  else
867963847c39Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
868063847c39Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
868163847c39Smrg	  fi
86820814a2baSmrg	elif test yes = "$build_libtool_libs"; then
868363847c39Smrg	  # Not a shared library
86840814a2baSmrg	  if test pass_all != "$deplibs_check_method"; then
868563847c39Smrg	    # We're trying link a shared library against a static one
868663847c39Smrg	    # but the system doesn't support it.
868763847c39Smrg
868863847c39Smrg	    # Just print a warning and add the library to dependency_libs so
868963847c39Smrg	    # that the program can be linked against the static library.
869063847c39Smrg	    echo
86910814a2baSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
869263847c39Smrg	    echo "*** I have the capability to make that library automatically link in when"
869363847c39Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
869463847c39Smrg	    echo "*** shared version of the library, which you do not appear to have."
86950814a2baSmrg	    if test yes = "$module"; then
869663847c39Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869763847c39Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869863847c39Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
869963847c39Smrg	      if test -z "$global_symbol_pipe"; then
870063847c39Smrg		echo
870163847c39Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
87020814a2baSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
870363847c39Smrg		echo "*** not find such a program.  So, this module is probably useless."
87040814a2baSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
870563847c39Smrg	      fi
87060814a2baSmrg	      if test no = "$build_old_libs"; then
870763847c39Smrg		build_libtool_libs=module
870863847c39Smrg		build_old_libs=yes
870963847c39Smrg	      else
871063847c39Smrg		build_libtool_libs=no
871163847c39Smrg	      fi
871263847c39Smrg	    fi
871363847c39Smrg	  else
871463847c39Smrg	    deplibs="$dir/$old_library $deplibs"
871563847c39Smrg	    link_static=yes
871663847c39Smrg	  fi
871763847c39Smrg	fi # link shared/static library?
871863847c39Smrg
87190814a2baSmrg	if test lib = "$linkmode"; then
872063847c39Smrg	  if test -n "$dependency_libs" &&
87210814a2baSmrg	     { test yes != "$hardcode_into_libs" ||
87220814a2baSmrg	       test yes = "$build_old_libs" ||
87230814a2baSmrg	       test yes = "$link_static"; }; then
872463847c39Smrg	    # Extract -R from dependency_libs
872563847c39Smrg	    temp_deplibs=
872663847c39Smrg	    for libdir in $dependency_libs; do
872763847c39Smrg	      case $libdir in
872863847c39Smrg	      -R*) func_stripname '-R' '' "$libdir"
872963847c39Smrg	           temp_xrpath=$func_stripname_result
873063847c39Smrg		   case " $xrpath " in
873163847c39Smrg		   *" $temp_xrpath "*) ;;
873263847c39Smrg		   *) func_append xrpath " $temp_xrpath";;
873363847c39Smrg		   esac;;
873463847c39Smrg	      *) func_append temp_deplibs " $libdir";;
873563847c39Smrg	      esac
873663847c39Smrg	    done
87370814a2baSmrg	    dependency_libs=$temp_deplibs
873863847c39Smrg	  fi
873963847c39Smrg
874063847c39Smrg	  func_append newlib_search_path " $absdir"
874163847c39Smrg	  # Link against this library
87420814a2baSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
874363847c39Smrg	  # ... and its dependency_libs
874463847c39Smrg	  tmp_libs=
874563847c39Smrg	  for deplib in $dependency_libs; do
874663847c39Smrg	    newdependency_libs="$deplib $newdependency_libs"
874763847c39Smrg	    case $deplib in
874863847c39Smrg              -L*) func_stripname '-L' '' "$deplib"
874963847c39Smrg                   func_resolve_sysroot "$func_stripname_result";;
875063847c39Smrg              *) func_resolve_sysroot "$deplib" ;;
875163847c39Smrg            esac
87520814a2baSmrg	    if $opt_preserve_dup_deps; then
875363847c39Smrg	      case "$tmp_libs " in
875463847c39Smrg	      *" $func_resolve_sysroot_result "*)
875563847c39Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
875663847c39Smrg	      esac
875763847c39Smrg	    fi
875863847c39Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
875963847c39Smrg	  done
876063847c39Smrg
87610814a2baSmrg	  if test no != "$link_all_deplibs"; then
876263847c39Smrg	    # Add the search paths of all dependency libraries
876363847c39Smrg	    for deplib in $dependency_libs; do
876463847c39Smrg	      path=
876563847c39Smrg	      case $deplib in
87660814a2baSmrg	      -L*) path=$deplib ;;
876763847c39Smrg	      *.la)
876863847c39Smrg	        func_resolve_sysroot "$deplib"
876963847c39Smrg	        deplib=$func_resolve_sysroot_result
877063847c39Smrg	        func_dirname "$deplib" "" "."
877163847c39Smrg		dir=$func_dirname_result
877263847c39Smrg		# We need an absolute path.
877363847c39Smrg		case $dir in
87740814a2baSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
877563847c39Smrg		*)
877663847c39Smrg		  absdir=`cd "$dir" && pwd`
877763847c39Smrg		  if test -z "$absdir"; then
87780814a2baSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
87790814a2baSmrg		    absdir=$dir
878063847c39Smrg		  fi
878163847c39Smrg		  ;;
878263847c39Smrg		esac
878363847c39Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
878463847c39Smrg		case $host in
878563847c39Smrg		*-*-darwin*)
878663847c39Smrg		  depdepl=
87870814a2baSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
87880814a2baSmrg		  if test -n "$deplibrary_names"; then
87890814a2baSmrg		    for tmp in $deplibrary_names; do
879063847c39Smrg		      depdepl=$tmp
879163847c39Smrg		    done
87920814a2baSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
87930814a2baSmrg		      depdepl=$absdir/$objdir/$depdepl
87940814a2baSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
879563847c39Smrg                      if test -z "$darwin_install_name"; then
87960814a2baSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
879763847c39Smrg                      fi
87980814a2baSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
87990814a2baSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
880063847c39Smrg		      path=
880163847c39Smrg		    fi
880263847c39Smrg		  fi
880363847c39Smrg		  ;;
880463847c39Smrg		*)
88050814a2baSmrg		  path=-L$absdir/$objdir
880663847c39Smrg		  ;;
880763847c39Smrg		esac
880863847c39Smrg		else
88090814a2baSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
881063847c39Smrg		  test -z "$libdir" && \
88110814a2baSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
881263847c39Smrg		  test "$absdir" != "$libdir" && \
88130814a2baSmrg		    func_warning "'$deplib' seems to be moved"
881463847c39Smrg
88150814a2baSmrg		  path=-L$absdir
881663847c39Smrg		fi
881763847c39Smrg		;;
881863847c39Smrg	      esac
881963847c39Smrg	      case " $deplibs " in
882063847c39Smrg	      *" $path "*) ;;
882163847c39Smrg	      *) deplibs="$path $deplibs" ;;
882263847c39Smrg	      esac
882363847c39Smrg	    done
882463847c39Smrg	  fi # link_all_deplibs != no
882563847c39Smrg	fi # linkmode = lib
882663847c39Smrg      done # for deplib in $libs
88270814a2baSmrg      if test link = "$pass"; then
88280814a2baSmrg	if test prog = "$linkmode"; then
882963847c39Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
883063847c39Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
883163847c39Smrg	else
883263847c39Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
883363847c39Smrg	fi
883463847c39Smrg      fi
88350814a2baSmrg      dependency_libs=$newdependency_libs
88360814a2baSmrg      if test dlpreopen = "$pass"; then
883763847c39Smrg	# Link the dlpreopened libraries before other libraries
883863847c39Smrg	for deplib in $save_deplibs; do
883963847c39Smrg	  deplibs="$deplib $deplibs"
884063847c39Smrg	done
884163847c39Smrg      fi
88420814a2baSmrg      if test dlopen != "$pass"; then
88430814a2baSmrg	test conv = "$pass" || {
884463847c39Smrg	  # Make sure lib_search_path contains only unique directories.
884563847c39Smrg	  lib_search_path=
884663847c39Smrg	  for dir in $newlib_search_path; do
884763847c39Smrg	    case "$lib_search_path " in
884863847c39Smrg	    *" $dir "*) ;;
884963847c39Smrg	    *) func_append lib_search_path " $dir" ;;
885063847c39Smrg	    esac
885163847c39Smrg	  done
885263847c39Smrg	  newlib_search_path=
88530814a2baSmrg	}
885463847c39Smrg
88550814a2baSmrg	if test prog,link = "$linkmode,$pass"; then
885663847c39Smrg	  vars="compile_deplibs finalize_deplibs"
88570814a2baSmrg	else
88580814a2baSmrg	  vars=deplibs
885963847c39Smrg	fi
886063847c39Smrg	for var in $vars dependency_libs; do
886163847c39Smrg	  # Add libraries to $var in reverse order
886263847c39Smrg	  eval tmp_libs=\"\$$var\"
886363847c39Smrg	  new_libs=
886463847c39Smrg	  for deplib in $tmp_libs; do
886563847c39Smrg	    # FIXME: Pedantically, this is the right thing to do, so
886663847c39Smrg	    #        that some nasty dependency loop isn't accidentally
886763847c39Smrg	    #        broken:
886863847c39Smrg	    #new_libs="$deplib $new_libs"
886963847c39Smrg	    # Pragmatically, this seems to cause very few problems in
887063847c39Smrg	    # practice:
887163847c39Smrg	    case $deplib in
887263847c39Smrg	    -L*) new_libs="$deplib $new_libs" ;;
887363847c39Smrg	    -R*) ;;
887463847c39Smrg	    *)
887563847c39Smrg	      # And here is the reason: when a library appears more
887663847c39Smrg	      # than once as an explicit dependence of a library, or
887763847c39Smrg	      # is implicitly linked in more than once by the
887863847c39Smrg	      # compiler, it is considered special, and multiple
887963847c39Smrg	      # occurrences thereof are not removed.  Compare this
888063847c39Smrg	      # with having the same library being listed as a
888163847c39Smrg	      # dependency of multiple other libraries: in this case,
888263847c39Smrg	      # we know (pedantically, we assume) the library does not
888363847c39Smrg	      # need to be listed more than once, so we keep only the
888463847c39Smrg	      # last copy.  This is not always right, but it is rare
888563847c39Smrg	      # enough that we require users that really mean to play
888663847c39Smrg	      # such unportable linking tricks to link the library
888763847c39Smrg	      # using -Wl,-lname, so that libtool does not consider it
888863847c39Smrg	      # for duplicate removal.
888963847c39Smrg	      case " $specialdeplibs " in
889063847c39Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
889163847c39Smrg	      *)
889263847c39Smrg		case " $new_libs " in
889363847c39Smrg		*" $deplib "*) ;;
889463847c39Smrg		*) new_libs="$deplib $new_libs" ;;
889563847c39Smrg		esac
889663847c39Smrg		;;
889763847c39Smrg	      esac
889863847c39Smrg	      ;;
889963847c39Smrg	    esac
890063847c39Smrg	  done
890163847c39Smrg	  tmp_libs=
890263847c39Smrg	  for deplib in $new_libs; do
890363847c39Smrg	    case $deplib in
890463847c39Smrg	    -L*)
890563847c39Smrg	      case " $tmp_libs " in
890663847c39Smrg	      *" $deplib "*) ;;
890763847c39Smrg	      *) func_append tmp_libs " $deplib" ;;
890863847c39Smrg	      esac
890963847c39Smrg	      ;;
891063847c39Smrg	    *) func_append tmp_libs " $deplib" ;;
891163847c39Smrg	    esac
891263847c39Smrg	  done
891363847c39Smrg	  eval $var=\"$tmp_libs\"
891463847c39Smrg	done # for var
891563847c39Smrg      fi
89160814a2baSmrg
89170814a2baSmrg      # Add Sun CC postdeps if required:
89180814a2baSmrg      test CXX = "$tagname" && {
89190814a2baSmrg        case $host_os in
89200814a2baSmrg        linux*)
89210814a2baSmrg          case `$CC -V 2>&1 | $SED 5q` in
89220814a2baSmrg          *Sun\ C*) # Sun C++ 5.9
89230814a2baSmrg            func_suncc_cstd_abi
89240814a2baSmrg
89250814a2baSmrg            if test no != "$suncc_use_cstd_abi"; then
89260814a2baSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89270814a2baSmrg            fi
89280814a2baSmrg            ;;
89290814a2baSmrg          esac
89300814a2baSmrg          ;;
89310814a2baSmrg
89320814a2baSmrg        solaris*)
89330814a2baSmrg          func_cc_basename "$CC"
89340814a2baSmrg          case $func_cc_basename_result in
89350814a2baSmrg          CC* | sunCC*)
89360814a2baSmrg            func_suncc_cstd_abi
89370814a2baSmrg
89380814a2baSmrg            if test no != "$suncc_use_cstd_abi"; then
89390814a2baSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89400814a2baSmrg            fi
89410814a2baSmrg            ;;
89420814a2baSmrg          esac
89430814a2baSmrg          ;;
89440814a2baSmrg        esac
89450814a2baSmrg      }
89460814a2baSmrg
894763847c39Smrg      # Last step: remove runtime libs from dependency_libs
894863847c39Smrg      # (they stay in deplibs)
894963847c39Smrg      tmp_libs=
89500814a2baSmrg      for i in $dependency_libs; do
895163847c39Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
895263847c39Smrg	*" $i "*)
89530814a2baSmrg	  i=
895463847c39Smrg	  ;;
895563847c39Smrg	esac
89560814a2baSmrg	if test -n "$i"; then
895763847c39Smrg	  func_append tmp_libs " $i"
895863847c39Smrg	fi
895963847c39Smrg      done
896063847c39Smrg      dependency_libs=$tmp_libs
896163847c39Smrg    done # for pass
89620814a2baSmrg    if test prog = "$linkmode"; then
89630814a2baSmrg      dlfiles=$newdlfiles
896463847c39Smrg    fi
89650814a2baSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
89660814a2baSmrg      dlprefiles=$newdlprefiles
896763847c39Smrg    fi
896863847c39Smrg
896963847c39Smrg    case $linkmode in
897063847c39Smrg    oldlib)
89710814a2baSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
89720814a2baSmrg	func_warning "'-dlopen' is ignored for archives"
897363847c39Smrg      fi
897463847c39Smrg
897563847c39Smrg      case " $deplibs" in
897663847c39Smrg      *\ -l* | *\ -L*)
89770814a2baSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
897863847c39Smrg      esac
897963847c39Smrg
898063847c39Smrg      test -n "$rpath" && \
89810814a2baSmrg	func_warning "'-rpath' is ignored for archives"
898263847c39Smrg
898363847c39Smrg      test -n "$xrpath" && \
89840814a2baSmrg	func_warning "'-R' is ignored for archives"
898563847c39Smrg
898663847c39Smrg      test -n "$vinfo" && \
89870814a2baSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
898863847c39Smrg
898963847c39Smrg      test -n "$release" && \
89900814a2baSmrg	func_warning "'-release' is ignored for archives"
899163847c39Smrg
899263847c39Smrg      test -n "$export_symbols$export_symbols_regex" && \
89930814a2baSmrg	func_warning "'-export-symbols' is ignored for archives"
899463847c39Smrg
899563847c39Smrg      # Now set the variables for building old libraries.
899663847c39Smrg      build_libtool_libs=no
89970814a2baSmrg      oldlibs=$output
899863847c39Smrg      func_append objs "$old_deplibs"
899963847c39Smrg      ;;
900063847c39Smrg
900163847c39Smrg    lib)
90020814a2baSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
900363847c39Smrg      case $outputname in
900463847c39Smrg      lib*)
900563847c39Smrg	func_stripname 'lib' '.la' "$outputname"
900663847c39Smrg	name=$func_stripname_result
900763847c39Smrg	eval shared_ext=\"$shrext_cmds\"
900863847c39Smrg	eval libname=\"$libname_spec\"
900963847c39Smrg	;;
901063847c39Smrg      *)
90110814a2baSmrg	test no = "$module" \
90120814a2baSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
901363847c39Smrg
90140814a2baSmrg	if test no != "$need_lib_prefix"; then
901563847c39Smrg	  # Add the "lib" prefix for modules if required
901663847c39Smrg	  func_stripname '' '.la' "$outputname"
901763847c39Smrg	  name=$func_stripname_result
901863847c39Smrg	  eval shared_ext=\"$shrext_cmds\"
901963847c39Smrg	  eval libname=\"$libname_spec\"
902063847c39Smrg	else
902163847c39Smrg	  func_stripname '' '.la' "$outputname"
902263847c39Smrg	  libname=$func_stripname_result
902363847c39Smrg	fi
902463847c39Smrg	;;
902563847c39Smrg      esac
902663847c39Smrg
902763847c39Smrg      if test -n "$objs"; then
90280814a2baSmrg	if test pass_all != "$deplibs_check_method"; then
90290814a2baSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
903063847c39Smrg	else
903163847c39Smrg	  echo
903263847c39Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
903363847c39Smrg	  $ECHO "*** objects $objs is not portable!"
903463847c39Smrg	  func_append libobjs " $objs"
903563847c39Smrg	fi
903663847c39Smrg      fi
903763847c39Smrg
90380814a2baSmrg      test no = "$dlself" \
90390814a2baSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
904063847c39Smrg
904163847c39Smrg      set dummy $rpath
904263847c39Smrg      shift
90430814a2baSmrg      test 1 -lt "$#" \
90440814a2baSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
904563847c39Smrg
90460814a2baSmrg      install_libdir=$1
904763847c39Smrg
904863847c39Smrg      oldlibs=
904963847c39Smrg      if test -z "$rpath"; then
90500814a2baSmrg	if test yes = "$build_libtool_libs"; then
905163847c39Smrg	  # Building a libtool convenience library.
90520814a2baSmrg	  # Some compilers have problems with a '.al' extension so
905363847c39Smrg	  # convenience libraries should have the same extension an
905463847c39Smrg	  # archive normally would.
905563847c39Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
905663847c39Smrg	  build_libtool_libs=convenience
905763847c39Smrg	  build_old_libs=yes
905863847c39Smrg	fi
905963847c39Smrg
906063847c39Smrg	test -n "$vinfo" && \
90610814a2baSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
906263847c39Smrg
906363847c39Smrg	test -n "$release" && \
90640814a2baSmrg	  func_warning "'-release' is ignored for convenience libraries"
906563847c39Smrg      else
906663847c39Smrg
906763847c39Smrg	# Parse the version information argument.
90680814a2baSmrg	save_ifs=$IFS; IFS=:
906963847c39Smrg	set dummy $vinfo 0 0 0
907063847c39Smrg	shift
90710814a2baSmrg	IFS=$save_ifs
907263847c39Smrg
907363847c39Smrg	test -n "$7" && \
90740814a2baSmrg	  func_fatal_help "too many parameters to '-version-info'"
907563847c39Smrg
907663847c39Smrg	# convert absolute version numbers to libtool ages
907763847c39Smrg	# this retains compatibility with .la files and attempts
907863847c39Smrg	# to make the code below a bit more comprehensible
907963847c39Smrg
908063847c39Smrg	case $vinfo_number in
908163847c39Smrg	yes)
90820814a2baSmrg	  number_major=$1
90830814a2baSmrg	  number_minor=$2
90840814a2baSmrg	  number_revision=$3
908563847c39Smrg	  #
908663847c39Smrg	  # There are really only two kinds -- those that
908763847c39Smrg	  # use the current revision as the major version
908863847c39Smrg	  # and those that subtract age and use age as
908963847c39Smrg	  # a minor version.  But, then there is irix
90900814a2baSmrg	  # that has an extra 1 added just for fun
909163847c39Smrg	  #
909263847c39Smrg	  case $version_type in
909363847c39Smrg	  # correct linux to gnu/linux during the next big refactor
90940814a2baSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
909563847c39Smrg	    func_arith $number_major + $number_minor
909663847c39Smrg	    current=$func_arith_result
90970814a2baSmrg	    age=$number_minor
90980814a2baSmrg	    revision=$number_revision
909963847c39Smrg	    ;;
91000814a2baSmrg	  freebsd-aout|qnx|sunos)
91010814a2baSmrg	    current=$number_major
91020814a2baSmrg	    revision=$number_minor
91030814a2baSmrg	    age=0
910463847c39Smrg	    ;;
910563847c39Smrg	  irix|nonstopux)
910663847c39Smrg	    func_arith $number_major + $number_minor
910763847c39Smrg	    current=$func_arith_result
91080814a2baSmrg	    age=$number_minor
91090814a2baSmrg	    revision=$number_minor
911063847c39Smrg	    lt_irix_increment=no
911163847c39Smrg	    ;;
911263847c39Smrg	  esac
911363847c39Smrg	  ;;
911463847c39Smrg	no)
91150814a2baSmrg	  current=$1
91160814a2baSmrg	  revision=$2
91170814a2baSmrg	  age=$3
911863847c39Smrg	  ;;
911963847c39Smrg	esac
912063847c39Smrg
912163847c39Smrg	# Check that each of the things are valid numbers.
912263847c39Smrg	case $current in
912363847c39Smrg	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]) ;;
912463847c39Smrg	*)
91250814a2baSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
91260814a2baSmrg	  func_fatal_error "'$vinfo' is not valid version information"
912763847c39Smrg	  ;;
912863847c39Smrg	esac
912963847c39Smrg
913063847c39Smrg	case $revision in
913163847c39Smrg	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]) ;;
913263847c39Smrg	*)
91330814a2baSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
91340814a2baSmrg	  func_fatal_error "'$vinfo' is not valid version information"
913563847c39Smrg	  ;;
913663847c39Smrg	esac
913763847c39Smrg
913863847c39Smrg	case $age in
913963847c39Smrg	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]) ;;
914063847c39Smrg	*)
91410814a2baSmrg	  func_error "AGE '$age' must be a nonnegative integer"
91420814a2baSmrg	  func_fatal_error "'$vinfo' is not valid version information"
914363847c39Smrg	  ;;
914463847c39Smrg	esac
914563847c39Smrg
914663847c39Smrg	if test "$age" -gt "$current"; then
91470814a2baSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
91480814a2baSmrg	  func_fatal_error "'$vinfo' is not valid version information"
914963847c39Smrg	fi
915063847c39Smrg
915163847c39Smrg	# Calculate the version variables.
915263847c39Smrg	major=
915363847c39Smrg	versuffix=
915463847c39Smrg	verstring=
915563847c39Smrg	case $version_type in
915663847c39Smrg	none) ;;
915763847c39Smrg
915863847c39Smrg	darwin)
915963847c39Smrg	  # Like Linux, but with the current version available in
916063847c39Smrg	  # verstring for coding it into the library header
916163847c39Smrg	  func_arith $current - $age
916263847c39Smrg	  major=.$func_arith_result
91630814a2baSmrg	  versuffix=$major.$age.$revision
916463847c39Smrg	  # Darwin ld doesn't like 0 for these options...
916563847c39Smrg	  func_arith $current + 1
916663847c39Smrg	  minor_current=$func_arith_result
91670814a2baSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
916863847c39Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91690814a2baSmrg          # On Darwin other compilers
91700814a2baSmrg          case $CC in
91710814a2baSmrg              nagfor*)
91720814a2baSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91730814a2baSmrg                  ;;
91740814a2baSmrg              *)
91750814a2baSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91760814a2baSmrg                  ;;
91770814a2baSmrg          esac
917863847c39Smrg	  ;;
917963847c39Smrg
918063847c39Smrg	freebsd-aout)
91810814a2baSmrg	  major=.$current
91820814a2baSmrg	  versuffix=.$current.$revision
918363847c39Smrg	  ;;
918463847c39Smrg
91850814a2baSmrg	freebsd-elf | midnightbsd-elf)
91860814a2baSmrg	  func_arith $current - $age
91870814a2baSmrg	  major=.$func_arith_result
91880814a2baSmrg	  versuffix=$major.$age.$revision
918963847c39Smrg	  ;;
919063847c39Smrg
919163847c39Smrg	irix | nonstopux)
91920814a2baSmrg	  if test no = "$lt_irix_increment"; then
919363847c39Smrg	    func_arith $current - $age
919463847c39Smrg	  else
919563847c39Smrg	    func_arith $current - $age + 1
919663847c39Smrg	  fi
919763847c39Smrg	  major=$func_arith_result
919863847c39Smrg
919963847c39Smrg	  case $version_type in
920063847c39Smrg	    nonstopux) verstring_prefix=nonstopux ;;
920163847c39Smrg	    *)         verstring_prefix=sgi ;;
920263847c39Smrg	  esac
92030814a2baSmrg	  verstring=$verstring_prefix$major.$revision
920463847c39Smrg
920563847c39Smrg	  # Add in all the interfaces that we are compatible with.
920663847c39Smrg	  loop=$revision
92070814a2baSmrg	  while test 0 -ne "$loop"; do
920863847c39Smrg	    func_arith $revision - $loop
920963847c39Smrg	    iface=$func_arith_result
921063847c39Smrg	    func_arith $loop - 1
921163847c39Smrg	    loop=$func_arith_result
92120814a2baSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
921363847c39Smrg	  done
921463847c39Smrg
92150814a2baSmrg	  # Before this point, $major must not contain '.'.
921663847c39Smrg	  major=.$major
92170814a2baSmrg	  versuffix=$major.$revision
921863847c39Smrg	  ;;
921963847c39Smrg
922063847c39Smrg	linux) # correct to gnu/linux during the next big refactor
922163847c39Smrg	  func_arith $current - $age
922263847c39Smrg	  major=.$func_arith_result
92230814a2baSmrg	  versuffix=$major.$age.$revision
922463847c39Smrg	  ;;
922563847c39Smrg
922663847c39Smrg	osf)
922763847c39Smrg	  func_arith $current - $age
922863847c39Smrg	  major=.$func_arith_result
92290814a2baSmrg	  versuffix=.$current.$age.$revision
92300814a2baSmrg	  verstring=$current.$age.$revision
923163847c39Smrg
923263847c39Smrg	  # Add in all the interfaces that we are compatible with.
923363847c39Smrg	  loop=$age
92340814a2baSmrg	  while test 0 -ne "$loop"; do
923563847c39Smrg	    func_arith $current - $loop
923663847c39Smrg	    iface=$func_arith_result
923763847c39Smrg	    func_arith $loop - 1
923863847c39Smrg	    loop=$func_arith_result
92390814a2baSmrg	    verstring=$verstring:$iface.0
924063847c39Smrg	  done
924163847c39Smrg
924263847c39Smrg	  # Make executables depend on our current version.
92430814a2baSmrg	  func_append verstring ":$current.0"
924463847c39Smrg	  ;;
924563847c39Smrg
924663847c39Smrg	qnx)
92470814a2baSmrg	  major=.$current
92480814a2baSmrg	  versuffix=.$current
92490814a2baSmrg	  ;;
92500814a2baSmrg
92510814a2baSmrg	sco)
92520814a2baSmrg	  major=.$current
92530814a2baSmrg	  versuffix=.$current
925463847c39Smrg	  ;;
925563847c39Smrg
925663847c39Smrg	sunos)
92570814a2baSmrg	  major=.$current
92580814a2baSmrg	  versuffix=.$current.$revision
925963847c39Smrg	  ;;
926063847c39Smrg
926163847c39Smrg	windows)
926263847c39Smrg	  # Use '-' rather than '.', since we only want one
92630814a2baSmrg	  # extension on DOS 8.3 file systems.
926463847c39Smrg	  func_arith $current - $age
926563847c39Smrg	  major=$func_arith_result
92660814a2baSmrg	  versuffix=-$major
926763847c39Smrg	  ;;
926863847c39Smrg
926963847c39Smrg	*)
92700814a2baSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
927163847c39Smrg	  ;;
927263847c39Smrg	esac
927363847c39Smrg
927463847c39Smrg	# Clear the version info if we defaulted, and they specified a release.
927563847c39Smrg	if test -z "$vinfo" && test -n "$release"; then
927663847c39Smrg	  major=
927763847c39Smrg	  case $version_type in
927863847c39Smrg	  darwin)
927963847c39Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
928063847c39Smrg	    # problems, so we reset it completely
928163847c39Smrg	    verstring=
928263847c39Smrg	    ;;
928363847c39Smrg	  *)
92840814a2baSmrg	    verstring=0.0
928563847c39Smrg	    ;;
928663847c39Smrg	  esac
92870814a2baSmrg	  if test no = "$need_version"; then
928863847c39Smrg	    versuffix=
928963847c39Smrg	  else
92900814a2baSmrg	    versuffix=.0.0
929163847c39Smrg	  fi
929263847c39Smrg	fi
929363847c39Smrg
929463847c39Smrg	# Remove version info from name if versioning should be avoided
92950814a2baSmrg	if test yes,no = "$avoid_version,$need_version"; then
929663847c39Smrg	  major=
929763847c39Smrg	  versuffix=
92980814a2baSmrg	  verstring=
929963847c39Smrg	fi
930063847c39Smrg
930163847c39Smrg	# Check to see if the archive will have undefined symbols.
93020814a2baSmrg	if test yes = "$allow_undefined"; then
93030814a2baSmrg	  if test unsupported = "$allow_undefined_flag"; then
93040814a2baSmrg	    if test yes = "$build_old_libs"; then
93050814a2baSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
93060814a2baSmrg	      build_libtool_libs=no
93070814a2baSmrg	    else
93080814a2baSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
93090814a2baSmrg	    fi
931063847c39Smrg	  fi
931163847c39Smrg	else
931263847c39Smrg	  # Don't allow undefined symbols.
93130814a2baSmrg	  allow_undefined_flag=$no_undefined_flag
931463847c39Smrg	fi
931563847c39Smrg
931663847c39Smrg      fi
931763847c39Smrg
93180814a2baSmrg      func_generate_dlsyms "$libname" "$libname" :
931963847c39Smrg      func_append libobjs " $symfileobj"
93200814a2baSmrg      test " " = "$libobjs" && libobjs=
932163847c39Smrg
93220814a2baSmrg      if test relink != "$opt_mode"; then
932363847c39Smrg	# Remove our outputs, but don't remove object files since they
932463847c39Smrg	# may have been created when compiling PIC objects.
932563847c39Smrg	removelist=
932663847c39Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
932763847c39Smrg	for p in $tempremovelist; do
932863847c39Smrg	  case $p in
932963847c39Smrg	    *.$objext | *.gcno)
933063847c39Smrg	       ;;
93310814a2baSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
93320814a2baSmrg	       if test -n "$precious_files_regex"; then
933363847c39Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
933463847c39Smrg		 then
933563847c39Smrg		   continue
933663847c39Smrg		 fi
933763847c39Smrg	       fi
933863847c39Smrg	       func_append removelist " $p"
933963847c39Smrg	       ;;
934063847c39Smrg	    *) ;;
934163847c39Smrg	  esac
934263847c39Smrg	done
934363847c39Smrg	test -n "$removelist" && \
934463847c39Smrg	  func_show_eval "${RM}r \$removelist"
934563847c39Smrg      fi
934663847c39Smrg
934763847c39Smrg      # Now set the variables for building old libraries.
93480814a2baSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
934963847c39Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
935063847c39Smrg
935163847c39Smrg	# Transform .lo files to .o files.
93520814a2baSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
935363847c39Smrg      fi
935463847c39Smrg
935563847c39Smrg      # Eliminate all temporary directories.
935663847c39Smrg      #for path in $notinst_path; do
935763847c39Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935863847c39Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935963847c39Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
936063847c39Smrg      #done
936163847c39Smrg
936263847c39Smrg      if test -n "$xrpath"; then
936363847c39Smrg	# If the user specified any rpath flags, then add them.
936463847c39Smrg	temp_xrpath=
936563847c39Smrg	for libdir in $xrpath; do
936663847c39Smrg	  func_replace_sysroot "$libdir"
936763847c39Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
936863847c39Smrg	  case "$finalize_rpath " in
936963847c39Smrg	  *" $libdir "*) ;;
937063847c39Smrg	  *) func_append finalize_rpath " $libdir" ;;
937163847c39Smrg	  esac
937263847c39Smrg	done
93730814a2baSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
937463847c39Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
937563847c39Smrg	fi
937663847c39Smrg      fi
937763847c39Smrg
937863847c39Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
93790814a2baSmrg      old_dlfiles=$dlfiles
938063847c39Smrg      dlfiles=
938163847c39Smrg      for lib in $old_dlfiles; do
938263847c39Smrg	case " $dlprefiles $dlfiles " in
938363847c39Smrg	*" $lib "*) ;;
938463847c39Smrg	*) func_append dlfiles " $lib" ;;
938563847c39Smrg	esac
938663847c39Smrg      done
938763847c39Smrg
938863847c39Smrg      # Make sure dlprefiles contains only unique files
93890814a2baSmrg      old_dlprefiles=$dlprefiles
939063847c39Smrg      dlprefiles=
939163847c39Smrg      for lib in $old_dlprefiles; do
939263847c39Smrg	case "$dlprefiles " in
939363847c39Smrg	*" $lib "*) ;;
939463847c39Smrg	*) func_append dlprefiles " $lib" ;;
939563847c39Smrg	esac
939663847c39Smrg      done
939763847c39Smrg
93980814a2baSmrg      if test yes = "$build_libtool_libs"; then
939963847c39Smrg	if test -n "$rpath"; then
940063847c39Smrg	  case $host in
940163847c39Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
940263847c39Smrg	    # these systems don't actually have a c library (as such)!
940363847c39Smrg	    ;;
940463847c39Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
940563847c39Smrg	    # Rhapsody C library is in the System framework
940663847c39Smrg	    func_append deplibs " System.ltframework"
940763847c39Smrg	    ;;
940863847c39Smrg	  *-*-netbsd*)
940963847c39Smrg	    # Don't link with libc until the a.out ld.so is fixed.
941063847c39Smrg	    ;;
94110814a2baSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
941263847c39Smrg	    # Do not include libc due to us having libc/libc_r.
941363847c39Smrg	    ;;
941463847c39Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
941563847c39Smrg	    # Causes problems with __ctype
941663847c39Smrg	    ;;
941763847c39Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
941863847c39Smrg	    # Compiler inserts libc in the correct place for threads to work
941963847c39Smrg	    ;;
942063847c39Smrg	  *)
942163847c39Smrg	    # Add libc to deplibs on all other systems if necessary.
94220814a2baSmrg	    if test yes = "$build_libtool_need_lc"; then
942363847c39Smrg	      func_append deplibs " -lc"
942463847c39Smrg	    fi
942563847c39Smrg	    ;;
942663847c39Smrg	  esac
942763847c39Smrg	fi
942863847c39Smrg
942963847c39Smrg	# Transform deplibs into only deplibs that can be linked in shared.
943063847c39Smrg	name_save=$name
943163847c39Smrg	libname_save=$libname
943263847c39Smrg	release_save=$release
943363847c39Smrg	versuffix_save=$versuffix
943463847c39Smrg	major_save=$major
943563847c39Smrg	# I'm not sure if I'm treating the release correctly.  I think
943663847c39Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
943763847c39Smrg	# add it in twice.  Is that correct?
94380814a2baSmrg	release=
94390814a2baSmrg	versuffix=
94400814a2baSmrg	major=
944163847c39Smrg	newdeplibs=
944263847c39Smrg	droppeddeps=no
944363847c39Smrg	case $deplibs_check_method in
944463847c39Smrg	pass_all)
944563847c39Smrg	  # Don't check for shared/static.  Everything works.
944663847c39Smrg	  # This might be a little naive.  We might want to check
944763847c39Smrg	  # whether the library exists or not.  But this is on
944863847c39Smrg	  # osf3 & osf4 and I'm not really sure... Just
944963847c39Smrg	  # implementing what was already the behavior.
945063847c39Smrg	  newdeplibs=$deplibs
945163847c39Smrg	  ;;
945263847c39Smrg	test_compile)
945363847c39Smrg	  # This code stresses the "libraries are programs" paradigm to its
945463847c39Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
945563847c39Smrg	  # against the deplibs as a proxy for the library.  Then we can check
945663847c39Smrg	  # whether they linked in statically or dynamically with ldd.
945763847c39Smrg	  $opt_dry_run || $RM conftest.c
945863847c39Smrg	  cat > conftest.c <<EOF
945963847c39Smrg	  int main() { return 0; }
946063847c39SmrgEOF
946163847c39Smrg	  $opt_dry_run || $RM conftest
946263847c39Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
946363847c39Smrg	    ldd_output=`ldd conftest`
946463847c39Smrg	    for i in $deplibs; do
946563847c39Smrg	      case $i in
946663847c39Smrg	      -l*)
946763847c39Smrg		func_stripname -l '' "$i"
946863847c39Smrg		name=$func_stripname_result
94690814a2baSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
947063847c39Smrg		  case " $predeps $postdeps " in
947163847c39Smrg		  *" $i "*)
947263847c39Smrg		    func_append newdeplibs " $i"
94730814a2baSmrg		    i=
947463847c39Smrg		    ;;
947563847c39Smrg		  esac
947663847c39Smrg		fi
94770814a2baSmrg		if test -n "$i"; then
947863847c39Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
947963847c39Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
948063847c39Smrg		  set dummy $deplib_matches; shift
948163847c39Smrg		  deplib_match=$1
94820814a2baSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
948363847c39Smrg		    func_append newdeplibs " $i"
948463847c39Smrg		  else
948563847c39Smrg		    droppeddeps=yes
948663847c39Smrg		    echo
948763847c39Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948863847c39Smrg		    echo "*** I have the capability to make that library automatically link in when"
948963847c39Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
949063847c39Smrg		    echo "*** shared version of the library, which I believe you do not have"
949163847c39Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
949263847c39Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
949363847c39Smrg		  fi
949463847c39Smrg		fi
949563847c39Smrg		;;
949663847c39Smrg	      *)
949763847c39Smrg		func_append newdeplibs " $i"
949863847c39Smrg		;;
949963847c39Smrg	      esac
950063847c39Smrg	    done
950163847c39Smrg	  else
950263847c39Smrg	    # Error occurred in the first compile.  Let's try to salvage
950363847c39Smrg	    # the situation: Compile a separate program for each library.
950463847c39Smrg	    for i in $deplibs; do
950563847c39Smrg	      case $i in
950663847c39Smrg	      -l*)
950763847c39Smrg		func_stripname -l '' "$i"
950863847c39Smrg		name=$func_stripname_result
950963847c39Smrg		$opt_dry_run || $RM conftest
951063847c39Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
951163847c39Smrg		  ldd_output=`ldd conftest`
95120814a2baSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
951363847c39Smrg		    case " $predeps $postdeps " in
951463847c39Smrg		    *" $i "*)
951563847c39Smrg		      func_append newdeplibs " $i"
95160814a2baSmrg		      i=
951763847c39Smrg		      ;;
951863847c39Smrg		    esac
951963847c39Smrg		  fi
95200814a2baSmrg		  if test -n "$i"; then
952163847c39Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
952263847c39Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
952363847c39Smrg		    set dummy $deplib_matches; shift
952463847c39Smrg		    deplib_match=$1
95250814a2baSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
952663847c39Smrg		      func_append newdeplibs " $i"
952763847c39Smrg		    else
952863847c39Smrg		      droppeddeps=yes
952963847c39Smrg		      echo
953063847c39Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
953163847c39Smrg		      echo "*** I have the capability to make that library automatically link in when"
953263847c39Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
953363847c39Smrg		      echo "*** shared version of the library, which you do not appear to have"
953463847c39Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
953563847c39Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
953663847c39Smrg		    fi
953763847c39Smrg		  fi
953863847c39Smrg		else
953963847c39Smrg		  droppeddeps=yes
954063847c39Smrg		  echo
954163847c39Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
954263847c39Smrg		  echo "*** make it link in!  You will probably need to install it or some"
954363847c39Smrg		  echo "*** library that it depends on before this library will be fully"
954463847c39Smrg		  echo "*** functional.  Installing it before continuing would be even better."
954563847c39Smrg		fi
954663847c39Smrg		;;
954763847c39Smrg	      *)
954863847c39Smrg		func_append newdeplibs " $i"
954963847c39Smrg		;;
955063847c39Smrg	      esac
955163847c39Smrg	    done
955263847c39Smrg	  fi
955363847c39Smrg	  ;;
955463847c39Smrg	file_magic*)
955563847c39Smrg	  set dummy $deplibs_check_method; shift
955663847c39Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
955763847c39Smrg	  for a_deplib in $deplibs; do
955863847c39Smrg	    case $a_deplib in
955963847c39Smrg	    -l*)
956063847c39Smrg	      func_stripname -l '' "$a_deplib"
956163847c39Smrg	      name=$func_stripname_result
95620814a2baSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
956363847c39Smrg		case " $predeps $postdeps " in
956463847c39Smrg		*" $a_deplib "*)
956563847c39Smrg		  func_append newdeplibs " $a_deplib"
95660814a2baSmrg		  a_deplib=
956763847c39Smrg		  ;;
956863847c39Smrg		esac
956963847c39Smrg	      fi
95700814a2baSmrg	      if test -n "$a_deplib"; then
957163847c39Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
957263847c39Smrg		if test -n "$file_magic_glob"; then
957363847c39Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
957463847c39Smrg		else
957563847c39Smrg		  libnameglob=$libname
957663847c39Smrg		fi
95770814a2baSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
957863847c39Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
95790814a2baSmrg		  if test yes = "$want_nocaseglob"; then
958063847c39Smrg		    shopt -s nocaseglob
958163847c39Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958263847c39Smrg		    $nocaseglob
958363847c39Smrg		  else
958463847c39Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958563847c39Smrg		  fi
958663847c39Smrg		  for potent_lib in $potential_libs; do
958763847c39Smrg		      # Follow soft links.
958863847c39Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
958963847c39Smrg			 $GREP " -> " >/dev/null; then
959063847c39Smrg			continue
959163847c39Smrg		      fi
959263847c39Smrg		      # The statement above tries to avoid entering an
959363847c39Smrg		      # endless loop below, in case of cyclic links.
959463847c39Smrg		      # We might still enter an endless loop, since a link
959563847c39Smrg		      # loop can be closed while we follow links,
959663847c39Smrg		      # but so what?
95970814a2baSmrg		      potlib=$potent_lib
959863847c39Smrg		      while test -h "$potlib" 2>/dev/null; do
95990814a2baSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
960063847c39Smrg			case $potliblink in
96010814a2baSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
96020814a2baSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
960363847c39Smrg			esac
960463847c39Smrg		      done
960563847c39Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
960663847c39Smrg			 $SED -e 10q |
960763847c39Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
960863847c39Smrg			func_append newdeplibs " $a_deplib"
96090814a2baSmrg			a_deplib=
961063847c39Smrg			break 2
961163847c39Smrg		      fi
961263847c39Smrg		  done
961363847c39Smrg		done
961463847c39Smrg	      fi
96150814a2baSmrg	      if test -n "$a_deplib"; then
961663847c39Smrg		droppeddeps=yes
961763847c39Smrg		echo
961863847c39Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961963847c39Smrg		echo "*** I have the capability to make that library automatically link in when"
962063847c39Smrg		echo "*** you link to this library.  But I can only do this if you have a"
962163847c39Smrg		echo "*** shared version of the library, which you do not appear to have"
962263847c39Smrg		echo "*** because I did check the linker path looking for a file starting"
96230814a2baSmrg		if test -z "$potlib"; then
962463847c39Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
962563847c39Smrg		else
962663847c39Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
962763847c39Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
962863847c39Smrg		fi
962963847c39Smrg	      fi
963063847c39Smrg	      ;;
963163847c39Smrg	    *)
963263847c39Smrg	      # Add a -L argument.
963363847c39Smrg	      func_append newdeplibs " $a_deplib"
963463847c39Smrg	      ;;
963563847c39Smrg	    esac
963663847c39Smrg	  done # Gone through all deplibs.
963763847c39Smrg	  ;;
963863847c39Smrg	match_pattern*)
963963847c39Smrg	  set dummy $deplibs_check_method; shift
964063847c39Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
964163847c39Smrg	  for a_deplib in $deplibs; do
964263847c39Smrg	    case $a_deplib in
964363847c39Smrg	    -l*)
964463847c39Smrg	      func_stripname -l '' "$a_deplib"
964563847c39Smrg	      name=$func_stripname_result
96460814a2baSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
964763847c39Smrg		case " $predeps $postdeps " in
964863847c39Smrg		*" $a_deplib "*)
964963847c39Smrg		  func_append newdeplibs " $a_deplib"
96500814a2baSmrg		  a_deplib=
965163847c39Smrg		  ;;
965263847c39Smrg		esac
965363847c39Smrg	      fi
96540814a2baSmrg	      if test -n "$a_deplib"; then
965563847c39Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
965663847c39Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
965763847c39Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
965863847c39Smrg		  for potent_lib in $potential_libs; do
96590814a2baSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
966063847c39Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
966163847c39Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
966263847c39Smrg		      func_append newdeplibs " $a_deplib"
96630814a2baSmrg		      a_deplib=
966463847c39Smrg		      break 2
966563847c39Smrg		    fi
966663847c39Smrg		  done
966763847c39Smrg		done
966863847c39Smrg	      fi
96690814a2baSmrg	      if test -n "$a_deplib"; then
967063847c39Smrg		droppeddeps=yes
967163847c39Smrg		echo
967263847c39Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
967363847c39Smrg		echo "*** I have the capability to make that library automatically link in when"
967463847c39Smrg		echo "*** you link to this library.  But I can only do this if you have a"
967563847c39Smrg		echo "*** shared version of the library, which you do not appear to have"
967663847c39Smrg		echo "*** because I did check the linker path looking for a file starting"
96770814a2baSmrg		if test -z "$potlib"; then
967863847c39Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
967963847c39Smrg		else
968063847c39Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
968163847c39Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
968263847c39Smrg		fi
968363847c39Smrg	      fi
968463847c39Smrg	      ;;
968563847c39Smrg	    *)
968663847c39Smrg	      # Add a -L argument.
968763847c39Smrg	      func_append newdeplibs " $a_deplib"
968863847c39Smrg	      ;;
968963847c39Smrg	    esac
969063847c39Smrg	  done # Gone through all deplibs.
969163847c39Smrg	  ;;
969263847c39Smrg	none | unknown | *)
96930814a2baSmrg	  newdeplibs=
969463847c39Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
96950814a2baSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96960814a2baSmrg	    for i in $predeps $postdeps; do
969763847c39Smrg	      # can't use Xsed below, because $i might contain '/'
96980814a2baSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
969963847c39Smrg	    done
970063847c39Smrg	  fi
970163847c39Smrg	  case $tmp_deplibs in
970263847c39Smrg	  *[!\	\ ]*)
970363847c39Smrg	    echo
97040814a2baSmrg	    if test none = "$deplibs_check_method"; then
970563847c39Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
970663847c39Smrg	    else
970763847c39Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
970863847c39Smrg	    fi
970963847c39Smrg	    echo "*** All declared inter-library dependencies are being dropped."
971063847c39Smrg	    droppeddeps=yes
971163847c39Smrg	    ;;
971263847c39Smrg	  esac
971363847c39Smrg	  ;;
971463847c39Smrg	esac
971563847c39Smrg	versuffix=$versuffix_save
971663847c39Smrg	major=$major_save
971763847c39Smrg	release=$release_save
971863847c39Smrg	libname=$libname_save
971963847c39Smrg	name=$name_save
972076888252Smrg
972163847c39Smrg	case $host in
972263847c39Smrg	*-*-rhapsody* | *-*-darwin1.[012])
972363847c39Smrg	  # On Rhapsody replace the C library with the System framework
972463847c39Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
972563847c39Smrg	  ;;
972663847c39Smrg	esac
972776888252Smrg
97280814a2baSmrg	if test yes = "$droppeddeps"; then
97290814a2baSmrg	  if test yes = "$module"; then
973063847c39Smrg	    echo
973163847c39Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
973263847c39Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
973363847c39Smrg	    echo "*** a static module, that should work as long as the dlopening"
973463847c39Smrg	    echo "*** application is linked with the -dlopen flag."
973563847c39Smrg	    if test -z "$global_symbol_pipe"; then
973663847c39Smrg	      echo
973763847c39Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
97380814a2baSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973963847c39Smrg	      echo "*** not find such a program.  So, this module is probably useless."
97400814a2baSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
974163847c39Smrg	    fi
97420814a2baSmrg	    if test no = "$build_old_libs"; then
97430814a2baSmrg	      oldlibs=$output_objdir/$libname.$libext
974463847c39Smrg	      build_libtool_libs=module
974563847c39Smrg	      build_old_libs=yes
974663847c39Smrg	    else
974763847c39Smrg	      build_libtool_libs=no
974863847c39Smrg	    fi
974963847c39Smrg	  else
975063847c39Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
975163847c39Smrg	    echo "*** automatically added whenever a program is linked with this library"
975263847c39Smrg	    echo "*** or is declared to -dlopen it."
975376888252Smrg
97540814a2baSmrg	    if test no = "$allow_undefined"; then
975563847c39Smrg	      echo
975663847c39Smrg	      echo "*** Since this library must not contain undefined symbols,"
975763847c39Smrg	      echo "*** because either the platform does not support them or"
975863847c39Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975963847c39Smrg	      echo "*** libtool will only create a static version of it."
97600814a2baSmrg	      if test no = "$build_old_libs"; then
97610814a2baSmrg		oldlibs=$output_objdir/$libname.$libext
976263847c39Smrg		build_libtool_libs=module
976363847c39Smrg		build_old_libs=yes
976463847c39Smrg	      else
976563847c39Smrg		build_libtool_libs=no
976663847c39Smrg	      fi
976763847c39Smrg	    fi
976863847c39Smrg	  fi
976986dafe34Smrg	fi
977063847c39Smrg	# Done checking deplibs!
977163847c39Smrg	deplibs=$newdeplibs
977263847c39Smrg      fi
977363847c39Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
977463847c39Smrg      case $host in
977563847c39Smrg	*-*-darwin*)
977663847c39Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977763847c39Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977863847c39Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977963847c39Smrg	  ;;
978063847c39Smrg      esac
978176888252Smrg
978263847c39Smrg      # move library search paths that coincide with paths to not yet
978363847c39Smrg      # installed libraries to the beginning of the library search list
978463847c39Smrg      new_libs=
978563847c39Smrg      for path in $notinst_path; do
978663847c39Smrg	case " $new_libs " in
978763847c39Smrg	*" -L$path/$objdir "*) ;;
978863847c39Smrg	*)
978963847c39Smrg	  case " $deplibs " in
979063847c39Smrg	  *" -L$path/$objdir "*)
979163847c39Smrg	    func_append new_libs " -L$path/$objdir" ;;
979263847c39Smrg	  esac
979363847c39Smrg	  ;;
979463847c39Smrg	esac
979563847c39Smrg      done
979663847c39Smrg      for deplib in $deplibs; do
979763847c39Smrg	case $deplib in
979863847c39Smrg	-L*)
979963847c39Smrg	  case " $new_libs " in
980063847c39Smrg	  *" $deplib "*) ;;
980163847c39Smrg	  *) func_append new_libs " $deplib" ;;
980263847c39Smrg	  esac
980363847c39Smrg	  ;;
980463847c39Smrg	*) func_append new_libs " $deplib" ;;
980563847c39Smrg	esac
980663847c39Smrg      done
98070814a2baSmrg      deplibs=$new_libs
980876888252Smrg
980963847c39Smrg      # All the library-specific variables (install_libdir is set above).
981063847c39Smrg      library_names=
981163847c39Smrg      old_library=
981263847c39Smrg      dlname=
981376888252Smrg
981463847c39Smrg      # Test again, we may have decided not to build it any more
98150814a2baSmrg      if test yes = "$build_libtool_libs"; then
98160814a2baSmrg	# Remove $wl instances when linking with ld.
981763847c39Smrg	# FIXME: should test the right _cmds variable.
981863847c39Smrg	case $archive_cmds in
981963847c39Smrg	  *\$LD\ *) wl= ;;
982063847c39Smrg        esac
98210814a2baSmrg	if test yes = "$hardcode_into_libs"; then
982263847c39Smrg	  # Hardcode the library paths
982363847c39Smrg	  hardcode_libdirs=
982463847c39Smrg	  dep_rpath=
98250814a2baSmrg	  rpath=$finalize_rpath
98260814a2baSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
982763847c39Smrg	  for libdir in $rpath; do
982863847c39Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
982963847c39Smrg	      if test -n "$hardcode_libdir_separator"; then
983063847c39Smrg		func_replace_sysroot "$libdir"
983163847c39Smrg		libdir=$func_replace_sysroot_result
983263847c39Smrg		if test -z "$hardcode_libdirs"; then
98330814a2baSmrg		  hardcode_libdirs=$libdir
983463847c39Smrg		else
983563847c39Smrg		  # Just accumulate the unique libdirs.
983663847c39Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
983763847c39Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
983863847c39Smrg		    ;;
983963847c39Smrg		  *)
984063847c39Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
984163847c39Smrg		    ;;
984263847c39Smrg		  esac
984363847c39Smrg		fi
984463847c39Smrg	      else
984563847c39Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
984663847c39Smrg		func_append dep_rpath " $flag"
984763847c39Smrg	      fi
984863847c39Smrg	    elif test -n "$runpath_var"; then
984963847c39Smrg	      case "$perm_rpath " in
985063847c39Smrg	      *" $libdir "*) ;;
985163847c39Smrg	      *) func_append perm_rpath " $libdir" ;;
985263847c39Smrg	      esac
985363847c39Smrg	    fi
985463847c39Smrg	  done
985563847c39Smrg	  # Substitute the hardcoded libdirs into the rpath.
985663847c39Smrg	  if test -n "$hardcode_libdir_separator" &&
985763847c39Smrg	     test -n "$hardcode_libdirs"; then
98580814a2baSmrg	    libdir=$hardcode_libdirs
985963847c39Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
986063847c39Smrg	  fi
986163847c39Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
986263847c39Smrg	    # We should set the runpath_var.
986363847c39Smrg	    rpath=
986463847c39Smrg	    for dir in $perm_rpath; do
986563847c39Smrg	      func_append rpath "$dir:"
986663847c39Smrg	    done
986763847c39Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
986863847c39Smrg	  fi
986963847c39Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870d8556812Smrg	fi
987176888252Smrg
98720814a2baSmrg	shlibpath=$finalize_shlibpath
98730814a2baSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
987463847c39Smrg	if test -n "$shlibpath"; then
987563847c39Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876d8556812Smrg	fi
987776888252Smrg
987863847c39Smrg	# Get the real and link names of the library.
987963847c39Smrg	eval shared_ext=\"$shrext_cmds\"
988063847c39Smrg	eval library_names=\"$library_names_spec\"
988163847c39Smrg	set dummy $library_names
988263847c39Smrg	shift
98830814a2baSmrg	realname=$1
988463847c39Smrg	shift
988576888252Smrg
988663847c39Smrg	if test -n "$soname_spec"; then
988763847c39Smrg	  eval soname=\"$soname_spec\"
9888d8556812Smrg	else
98890814a2baSmrg	  soname=$realname
989063847c39Smrg	fi
989163847c39Smrg	if test -z "$dlname"; then
989263847c39Smrg	  dlname=$soname
9893d8556812Smrg	fi
989476888252Smrg
98950814a2baSmrg	lib=$output_objdir/$realname
989663847c39Smrg	linknames=
989763847c39Smrg	for link
989863847c39Smrg	do
989963847c39Smrg	  func_append linknames " $link"
990063847c39Smrg	done
990176888252Smrg
990263847c39Smrg	# Use standard objects if they are pic
990363847c39Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
990463847c39Smrg	test "X$libobjs" = "X " && libobjs=
990586dafe34Smrg
990663847c39Smrg	delfiles=
990763847c39Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
990863847c39Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
99090814a2baSmrg	  export_symbols=$output_objdir/$libname.uexp
991063847c39Smrg	  func_append delfiles " $export_symbols"
991163847c39Smrg	fi
991276888252Smrg
991363847c39Smrg	orig_export_symbols=
991463847c39Smrg	case $host_os in
991563847c39Smrg	cygwin* | mingw* | cegcc*)
991663847c39Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
991763847c39Smrg	    # exporting using user supplied symfile
99180814a2baSmrg	    func_dll_def_p "$export_symbols" || {
991963847c39Smrg	      # and it's NOT already a .def file. Must figure out
992063847c39Smrg	      # which of the given symbols are data symbols and tag
992163847c39Smrg	      # them as such. So, trigger use of export_symbols_cmds.
992263847c39Smrg	      # export_symbols gets reassigned inside the "prepare
992363847c39Smrg	      # the list of exported symbols" if statement, so the
992463847c39Smrg	      # include_expsyms logic still works.
99250814a2baSmrg	      orig_export_symbols=$export_symbols
992663847c39Smrg	      export_symbols=
992763847c39Smrg	      always_export_symbols=yes
99280814a2baSmrg	    }
992986dafe34Smrg	  fi
993063847c39Smrg	  ;;
993163847c39Smrg	esac
993276888252Smrg
993363847c39Smrg	# Prepare the list of exported symbols
993463847c39Smrg	if test -z "$export_symbols"; then
99350814a2baSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
99360814a2baSmrg	    func_verbose "generating symbol list for '$libname.la'"
99370814a2baSmrg	    export_symbols=$output_objdir/$libname.exp
993863847c39Smrg	    $opt_dry_run || $RM $export_symbols
993963847c39Smrg	    cmds=$export_symbols_cmds
99400814a2baSmrg	    save_ifs=$IFS; IFS='~'
994163847c39Smrg	    for cmd1 in $cmds; do
99420814a2baSmrg	      IFS=$save_ifs
994363847c39Smrg	      # Take the normal branch if the nm_file_list_spec branch
994463847c39Smrg	      # doesn't work or if tool conversion is not needed.
994563847c39Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
994663847c39Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
994763847c39Smrg		  try_normal_branch=yes
994863847c39Smrg		  eval cmd=\"$cmd1\"
994963847c39Smrg		  func_len " $cmd"
995063847c39Smrg		  len=$func_len_result
995163847c39Smrg		  ;;
995263847c39Smrg		*)
995363847c39Smrg		  try_normal_branch=no
995463847c39Smrg		  ;;
995563847c39Smrg	      esac
99560814a2baSmrg	      if test yes = "$try_normal_branch" \
995763847c39Smrg		 && { test "$len" -lt "$max_cmd_len" \
995863847c39Smrg		      || test "$max_cmd_len" -le -1; }
995963847c39Smrg	      then
996063847c39Smrg		func_show_eval "$cmd" 'exit $?'
996163847c39Smrg		skipped_export=false
996263847c39Smrg	      elif test -n "$nm_file_list_spec"; then
996363847c39Smrg		func_basename "$output"
996463847c39Smrg		output_la=$func_basename_result
996563847c39Smrg		save_libobjs=$libobjs
996663847c39Smrg		save_output=$output
99670814a2baSmrg		output=$output_objdir/$output_la.nm
996863847c39Smrg		func_to_tool_file "$output"
996963847c39Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
997063847c39Smrg		func_append delfiles " $output"
997163847c39Smrg		func_verbose "creating $NM input file list: $output"
997263847c39Smrg		for obj in $save_libobjs; do
997363847c39Smrg		  func_to_tool_file "$obj"
997463847c39Smrg		  $ECHO "$func_to_tool_file_result"
997563847c39Smrg		done > "$output"
997663847c39Smrg		eval cmd=\"$cmd1\"
997763847c39Smrg		func_show_eval "$cmd" 'exit $?'
997863847c39Smrg		output=$save_output
997963847c39Smrg		libobjs=$save_libobjs
998063847c39Smrg		skipped_export=false
998163847c39Smrg	      else
998263847c39Smrg		# The command line is too long to execute in one step.
998363847c39Smrg		func_verbose "using reloadable object file for export list..."
998463847c39Smrg		skipped_export=:
998563847c39Smrg		# Break out early, otherwise skipped_export may be
998663847c39Smrg		# set to false by a later but shorter cmd.
998763847c39Smrg		break
998863847c39Smrg	      fi
998963847c39Smrg	    done
99900814a2baSmrg	    IFS=$save_ifs
99910814a2baSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
999263847c39Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
999363847c39Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
999463847c39Smrg	    fi
999563847c39Smrg	  fi
999663847c39Smrg	fi
999763847c39Smrg
999863847c39Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99990814a2baSmrg	  tmp_export_symbols=$export_symbols
100000814a2baSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1000163847c39Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002d8556812Smrg	fi
1000376888252Smrg
100040814a2baSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
1000563847c39Smrg	  # The given exports_symbols file has to be filtered, so filter it.
100060814a2baSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1000763847c39Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
100080814a2baSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
1000963847c39Smrg	  # though. Also, the filter scales superlinearly with the number of
1001063847c39Smrg	  # global variables. join(1) would be nice here, but unfortunately
1001163847c39Smrg	  # isn't a blessed tool.
1001263847c39Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1001363847c39Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1001463847c39Smrg	  export_symbols=$output_objdir/$libname.def
1001563847c39Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1001663847c39Smrg	fi
1001786dafe34Smrg
1001863847c39Smrg	tmp_deplibs=
1001963847c39Smrg	for test_deplib in $deplibs; do
1002063847c39Smrg	  case " $convenience " in
1002163847c39Smrg	  *" $test_deplib "*) ;;
1002263847c39Smrg	  *)
1002363847c39Smrg	    func_append tmp_deplibs " $test_deplib"
1002463847c39Smrg	    ;;
1002563847c39Smrg	  esac
1002663847c39Smrg	done
100270814a2baSmrg	deplibs=$tmp_deplibs
10028d8556812Smrg
1002963847c39Smrg	if test -n "$convenience"; then
1003063847c39Smrg	  if test -n "$whole_archive_flag_spec" &&
100310814a2baSmrg	    test yes = "$compiler_needs_object" &&
1003263847c39Smrg	    test -z "$libobjs"; then
1003363847c39Smrg	    # extract the archives, so we have objects to list.
1003463847c39Smrg	    # TODO: could optimize this to just extract one archive.
1003563847c39Smrg	    whole_archive_flag_spec=
1003663847c39Smrg	  fi
1003763847c39Smrg	  if test -n "$whole_archive_flag_spec"; then
1003863847c39Smrg	    save_libobjs=$libobjs
1003963847c39Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1004063847c39Smrg	    test "X$libobjs" = "X " && libobjs=
1004176888252Smrg	  else
100420814a2baSmrg	    gentop=$output_objdir/${outputname}x
1004363847c39Smrg	    func_append generated " $gentop"
1004463847c39Smrg
1004563847c39Smrg	    func_extract_archives $gentop $convenience
1004663847c39Smrg	    func_append libobjs " $func_extract_archives_result"
1004763847c39Smrg	    test "X$libobjs" = "X " && libobjs=
1004876888252Smrg	  fi
1004976888252Smrg	fi
1005086dafe34Smrg
100510814a2baSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
1005263847c39Smrg	  eval flag=\"$thread_safe_flag_spec\"
1005363847c39Smrg	  func_append linker_flags " $flag"
1005463847c39Smrg	fi
1005576888252Smrg
1005663847c39Smrg	# Make a backup of the uninstalled library when relinking
100570814a2baSmrg	if test relink = "$opt_mode"; then
1005863847c39Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
1005963847c39Smrg	fi
1006086dafe34Smrg
1006163847c39Smrg	# Do each of the archive commands.
100620814a2baSmrg	if test yes = "$module" && test -n "$module_cmds"; then
1006363847c39Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1006463847c39Smrg	    eval test_cmds=\"$module_expsym_cmds\"
1006563847c39Smrg	    cmds=$module_expsym_cmds
1006663847c39Smrg	  else
1006763847c39Smrg	    eval test_cmds=\"$module_cmds\"
1006863847c39Smrg	    cmds=$module_cmds
1006963847c39Smrg	  fi
10070d8556812Smrg	else
1007163847c39Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1007263847c39Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
1007363847c39Smrg	    cmds=$archive_expsym_cmds
1007463847c39Smrg	  else
1007563847c39Smrg	    eval test_cmds=\"$archive_cmds\"
1007663847c39Smrg	    cmds=$archive_cmds
1007763847c39Smrg	  fi
1007886dafe34Smrg	fi
1007986dafe34Smrg
100800814a2baSmrg	if test : != "$skipped_export" &&
1008163847c39Smrg	   func_len " $test_cmds" &&
1008263847c39Smrg	   len=$func_len_result &&
1008363847c39Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1008463847c39Smrg	  :
1008563847c39Smrg	else
1008663847c39Smrg	  # The command line is too long to link in one step, link piecewise
1008763847c39Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
1008863847c39Smrg	  # script.
1008986dafe34Smrg
1009063847c39Smrg	  # Save the value of $output and $libobjs because we want to
1009163847c39Smrg	  # use them later.  If we have whole_archive_flag_spec, we
1009263847c39Smrg	  # want to use save_libobjs as it was before
1009363847c39Smrg	  # whole_archive_flag_spec was expanded, because we can't
1009463847c39Smrg	  # assume the linker understands whole_archive_flag_spec.
1009563847c39Smrg	  # This may have to be revisited, in case too many
1009663847c39Smrg	  # convenience libraries get linked in and end up exceeding
1009763847c39Smrg	  # the spec.
1009863847c39Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
1009963847c39Smrg	    save_libobjs=$libobjs
1010063847c39Smrg	  fi
1010163847c39Smrg	  save_output=$output
1010263847c39Smrg	  func_basename "$output"
1010363847c39Smrg	  output_la=$func_basename_result
1010463847c39Smrg
1010563847c39Smrg	  # Clear the reloadable object creation command queue and
1010663847c39Smrg	  # initialize k to one.
1010763847c39Smrg	  test_cmds=
1010863847c39Smrg	  concat_cmds=
1010963847c39Smrg	  objlist=
1011063847c39Smrg	  last_robj=
1011163847c39Smrg	  k=1
1011263847c39Smrg
101130814a2baSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
101140814a2baSmrg	    output=$output_objdir/$output_la.lnkscript
1011563847c39Smrg	    func_verbose "creating GNU ld script: $output"
1011663847c39Smrg	    echo 'INPUT (' > $output
1011763847c39Smrg	    for obj in $save_libobjs
1011863847c39Smrg	    do
1011963847c39Smrg	      func_to_tool_file "$obj"
1012063847c39Smrg	      $ECHO "$func_to_tool_file_result" >> $output
1012163847c39Smrg	    done
1012263847c39Smrg	    echo ')' >> $output
1012363847c39Smrg	    func_append delfiles " $output"
1012463847c39Smrg	    func_to_tool_file "$output"
1012563847c39Smrg	    output=$func_to_tool_file_result
101260814a2baSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
101270814a2baSmrg	    output=$output_objdir/$output_la.lnk
1012863847c39Smrg	    func_verbose "creating linker input file list: $output"
1012963847c39Smrg	    : > $output
1013063847c39Smrg	    set x $save_libobjs
1013163847c39Smrg	    shift
1013263847c39Smrg	    firstobj=
101330814a2baSmrg	    if test yes = "$compiler_needs_object"; then
1013463847c39Smrg	      firstobj="$1 "
1013563847c39Smrg	      shift
10136d8556812Smrg	    fi
1013763847c39Smrg	    for obj
1013863847c39Smrg	    do
1013963847c39Smrg	      func_to_tool_file "$obj"
1014063847c39Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10141d8556812Smrg	    done
1014263847c39Smrg	    func_append delfiles " $output"
1014363847c39Smrg	    func_to_tool_file "$output"
1014463847c39Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
1014563847c39Smrg	  else
1014663847c39Smrg	    if test -n "$save_libobjs"; then
1014763847c39Smrg	      func_verbose "creating reloadable object files..."
101480814a2baSmrg	      output=$output_objdir/$output_la-$k.$objext
1014963847c39Smrg	      eval test_cmds=\"$reload_cmds\"
1015063847c39Smrg	      func_len " $test_cmds"
1015163847c39Smrg	      len0=$func_len_result
1015263847c39Smrg	      len=$len0
1015363847c39Smrg
1015463847c39Smrg	      # Loop over the list of objects to be linked.
1015563847c39Smrg	      for obj in $save_libobjs
1015663847c39Smrg	      do
1015763847c39Smrg		func_len " $obj"
1015863847c39Smrg		func_arith $len + $func_len_result
1015963847c39Smrg		len=$func_arith_result
101600814a2baSmrg		if test -z "$objlist" ||
1016163847c39Smrg		   test "$len" -lt "$max_cmd_len"; then
1016263847c39Smrg		  func_append objlist " $obj"
1016363847c39Smrg		else
1016463847c39Smrg		  # The command $test_cmds is almost too long, add a
1016563847c39Smrg		  # command to the queue.
101660814a2baSmrg		  if test 1 -eq "$k"; then
1016763847c39Smrg		    # The first file doesn't have a previous command to add.
1016863847c39Smrg		    reload_objs=$objlist
1016963847c39Smrg		    eval concat_cmds=\"$reload_cmds\"
1017063847c39Smrg		  else
1017163847c39Smrg		    # All subsequent reloadable object files will link in
1017263847c39Smrg		    # the last one created.
1017363847c39Smrg		    reload_objs="$objlist $last_robj"
1017463847c39Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
1017563847c39Smrg		  fi
101760814a2baSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
1017763847c39Smrg		  func_arith $k + 1
1017863847c39Smrg		  k=$func_arith_result
101790814a2baSmrg		  output=$output_objdir/$output_la-$k.$objext
1018063847c39Smrg		  objlist=" $obj"
1018163847c39Smrg		  func_len " $last_robj"
1018263847c39Smrg		  func_arith $len0 + $func_len_result
1018363847c39Smrg		  len=$func_arith_result
1018463847c39Smrg		fi
1018563847c39Smrg	      done
1018663847c39Smrg	      # Handle the remaining objects by creating one last
1018763847c39Smrg	      # reloadable object file.  All subsequent reloadable object
1018863847c39Smrg	      # files will link in the last one created.
1018963847c39Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1019063847c39Smrg	      reload_objs="$objlist $last_robj"
101910814a2baSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
1019263847c39Smrg	      if test -n "$last_robj"; then
101930814a2baSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194d8556812Smrg	      fi
1019563847c39Smrg	      func_append delfiles " $output"
1019663847c39Smrg
1019763847c39Smrg	    else
1019863847c39Smrg	      output=
1019963847c39Smrg	    fi
1020063847c39Smrg
102010814a2baSmrg	    ${skipped_export-false} && {
102020814a2baSmrg	      func_verbose "generating symbol list for '$libname.la'"
102030814a2baSmrg	      export_symbols=$output_objdir/$libname.exp
1020463847c39Smrg	      $opt_dry_run || $RM $export_symbols
1020563847c39Smrg	      libobjs=$output
1020663847c39Smrg	      # Append the command to create the export file.
1020763847c39Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1020863847c39Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
1020963847c39Smrg	      if test -n "$last_robj"; then
1021063847c39Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211d8556812Smrg	      fi
102120814a2baSmrg	    }
1021363847c39Smrg
1021463847c39Smrg	    test -n "$save_libobjs" &&
1021563847c39Smrg	      func_verbose "creating a temporary reloadable object file: $output"
1021663847c39Smrg
1021763847c39Smrg	    # Loop through the commands generated above and execute them.
102180814a2baSmrg	    save_ifs=$IFS; IFS='~'
1021963847c39Smrg	    for cmd in $concat_cmds; do
102200814a2baSmrg	      IFS=$save_ifs
102210814a2baSmrg	      $opt_quiet || {
102220814a2baSmrg		  func_quote_arg expand,pretty "$cmd"
102230814a2baSmrg		  eval "func_echo $func_quote_arg_result"
1022463847c39Smrg	      }
1022563847c39Smrg	      $opt_dry_run || eval "$cmd" || {
1022663847c39Smrg		lt_exit=$?
1022763847c39Smrg
1022863847c39Smrg		# Restore the uninstalled library and exit
102290814a2baSmrg		if test relink = "$opt_mode"; then
1023063847c39Smrg		  ( cd "$output_objdir" && \
1023163847c39Smrg		    $RM "${realname}T" && \
1023263847c39Smrg		    $MV "${realname}U" "$realname" )
1023363847c39Smrg		fi
1023463847c39Smrg
1023563847c39Smrg		exit $lt_exit
1023663847c39Smrg	      }
10237d8556812Smrg	    done
102380814a2baSmrg	    IFS=$save_ifs
1023963847c39Smrg
1024063847c39Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
1024163847c39Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
1024263847c39Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
1024363847c39Smrg	    fi
1024463847c39Smrg	  fi
1024563847c39Smrg
102460814a2baSmrg          ${skipped_export-false} && {
1024763847c39Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
102480814a2baSmrg	      tmp_export_symbols=$export_symbols
102490814a2baSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1025063847c39Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1025163847c39Smrg	    fi
1025263847c39Smrg
1025363847c39Smrg	    if test -n "$orig_export_symbols"; then
1025463847c39Smrg	      # The given exports_symbols file has to be filtered, so filter it.
102550814a2baSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1025663847c39Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
102570814a2baSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
1025863847c39Smrg	      # though. Also, the filter scales superlinearly with the number of
1025963847c39Smrg	      # global variables. join(1) would be nice here, but unfortunately
1026063847c39Smrg	      # isn't a blessed tool.
1026163847c39Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1026263847c39Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1026363847c39Smrg	      export_symbols=$output_objdir/$libname.def
1026463847c39Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1026563847c39Smrg	    fi
102660814a2baSmrg	  }
1026763847c39Smrg
1026863847c39Smrg	  libobjs=$output
1026963847c39Smrg	  # Restore the value of output.
1027063847c39Smrg	  output=$save_output
1027163847c39Smrg
1027263847c39Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
1027363847c39Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1027463847c39Smrg	    test "X$libobjs" = "X " && libobjs=
1027563847c39Smrg	  fi
1027663847c39Smrg	  # Expand the library linking commands again to reset the
1027763847c39Smrg	  # value of $libobjs for piecewise linking.
1027863847c39Smrg
1027963847c39Smrg	  # Do each of the archive commands.
102800814a2baSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
1028163847c39Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1028263847c39Smrg	      cmds=$module_expsym_cmds
1028363847c39Smrg	    else
1028463847c39Smrg	      cmds=$module_cmds
1028563847c39Smrg	    fi
10286d8556812Smrg	  else
1028763847c39Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1028863847c39Smrg	      cmds=$archive_expsym_cmds
1028963847c39Smrg	    else
1029063847c39Smrg	      cmds=$archive_cmds
1029163847c39Smrg	    fi
10292d8556812Smrg	  fi
1029363847c39Smrg	fi
1029486dafe34Smrg
1029563847c39Smrg	if test -n "$delfiles"; then
1029663847c39Smrg	  # Append the command to remove temporary files to $cmds.
1029763847c39Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1029863847c39Smrg	fi
1029976888252Smrg
1030063847c39Smrg	# Add any objects from preloaded convenience libraries
1030163847c39Smrg	if test -n "$dlprefiles"; then
103020814a2baSmrg	  gentop=$output_objdir/${outputname}x
1030363847c39Smrg	  func_append generated " $gentop"
1030476888252Smrg
1030563847c39Smrg	  func_extract_archives $gentop $dlprefiles
1030663847c39Smrg	  func_append libobjs " $func_extract_archives_result"
1030763847c39Smrg	  test "X$libobjs" = "X " && libobjs=
1030863847c39Smrg	fi
1030976888252Smrg
103100814a2baSmrg	save_ifs=$IFS; IFS='~'
1031163847c39Smrg	for cmd in $cmds; do
103120814a2baSmrg	  IFS=$sp$nl
1031363847c39Smrg	  eval cmd=\"$cmd\"
103140814a2baSmrg	  IFS=$save_ifs
103150814a2baSmrg	  $opt_quiet || {
103160814a2baSmrg	    func_quote_arg expand,pretty "$cmd"
103170814a2baSmrg	    eval "func_echo $func_quote_arg_result"
1031863847c39Smrg	  }
1031963847c39Smrg	  $opt_dry_run || eval "$cmd" || {
1032063847c39Smrg	    lt_exit=$?
1032176888252Smrg
1032263847c39Smrg	    # Restore the uninstalled library and exit
103230814a2baSmrg	    if test relink = "$opt_mode"; then
1032463847c39Smrg	      ( cd "$output_objdir" && \
1032563847c39Smrg	        $RM "${realname}T" && \
1032663847c39Smrg		$MV "${realname}U" "$realname" )
1032763847c39Smrg	    fi
1032876888252Smrg
1032963847c39Smrg	    exit $lt_exit
1033063847c39Smrg	  }
1033163847c39Smrg	done
103320814a2baSmrg	IFS=$save_ifs
1033376888252Smrg
1033463847c39Smrg	# Restore the uninstalled library and exit
103350814a2baSmrg	if test relink = "$opt_mode"; then
1033663847c39Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
1033776888252Smrg
1033863847c39Smrg	  if test -n "$convenience"; then
1033963847c39Smrg	    if test -z "$whole_archive_flag_spec"; then
1034063847c39Smrg	      func_show_eval '${RM}r "$gentop"'
1034163847c39Smrg	    fi
1034263847c39Smrg	  fi
1034376888252Smrg
1034463847c39Smrg	  exit $EXIT_SUCCESS
1034563847c39Smrg	fi
1034663847c39Smrg
1034763847c39Smrg	# Create links to the real library.
1034863847c39Smrg	for linkname in $linknames; do
1034963847c39Smrg	  if test "$realname" != "$linkname"; then
1035063847c39Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351d8556812Smrg	  fi
10352d8556812Smrg	done
1035376888252Smrg
1035463847c39Smrg	# If -module or -export-dynamic was specified, set the dlname.
103550814a2baSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1035663847c39Smrg	  # On all known operating systems, these are identical.
103570814a2baSmrg	  dlname=$soname
1035863847c39Smrg	fi
1035963847c39Smrg      fi
1036086dafe34Smrg      ;;
1036176888252Smrg
1036263847c39Smrg    obj)
103630814a2baSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
103640814a2baSmrg	func_warning "'-dlopen' is ignored for objects"
1036563847c39Smrg      fi
10366d8556812Smrg
1036763847c39Smrg      case " $deplibs" in
1036863847c39Smrg      *\ -l* | *\ -L*)
103690814a2baSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
1037076888252Smrg      esac
1037176888252Smrg
1037263847c39Smrg      test -n "$rpath" && \
103730814a2baSmrg	func_warning "'-rpath' is ignored for objects"
1037476888252Smrg
1037563847c39Smrg      test -n "$xrpath" && \
103760814a2baSmrg	func_warning "'-R' is ignored for objects"
1037776888252Smrg
1037863847c39Smrg      test -n "$vinfo" && \
103790814a2baSmrg	func_warning "'-version-info' is ignored for objects"
1038063847c39Smrg
1038163847c39Smrg      test -n "$release" && \
103820814a2baSmrg	func_warning "'-release' is ignored for objects"
1038363847c39Smrg
1038463847c39Smrg      case $output in
1038563847c39Smrg      *.lo)
1038663847c39Smrg	test -n "$objs$old_deplibs" && \
103870814a2baSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1038863847c39Smrg
1038963847c39Smrg	libobj=$output
1039063847c39Smrg	func_lo2o "$libobj"
1039163847c39Smrg	obj=$func_lo2o_result
10392d8556812Smrg	;;
10393d8556812Smrg      *)
1039463847c39Smrg	libobj=
103950814a2baSmrg	obj=$output
1039676888252Smrg	;;
1039776888252Smrg      esac
1039876888252Smrg
1039963847c39Smrg      # Delete the old objects.
1040063847c39Smrg      $opt_dry_run || $RM $obj $libobj
1040176888252Smrg
1040263847c39Smrg      # Objects from convenience libraries.  This assumes
1040363847c39Smrg      # single-version convenience libraries.  Whenever we create
1040463847c39Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1040563847c39Smrg      # the extraction.
1040663847c39Smrg      reload_conv_objs=
1040763847c39Smrg      gentop=
104080814a2baSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
104090814a2baSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
104100814a2baSmrg      # into space.
104110814a2baSmrg      case $reload_cmds in
104120814a2baSmrg        *\$LD[\ \$]*) wl= ;;
104130814a2baSmrg      esac
1041463847c39Smrg      if test -n "$convenience"; then
1041563847c39Smrg	if test -n "$whole_archive_flag_spec"; then
1041663847c39Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
104170814a2baSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
104180814a2baSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
1041963847c39Smrg	else
104200814a2baSmrg	  gentop=$output_objdir/${obj}x
1042163847c39Smrg	  func_append generated " $gentop"
10422d8556812Smrg
1042363847c39Smrg	  func_extract_archives $gentop $convenience
1042463847c39Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
1042563847c39Smrg	fi
10426d8556812Smrg      fi
10427d8556812Smrg
1042863847c39Smrg      # If we're not building shared, we need to use non_pic_objs
104290814a2baSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430d8556812Smrg
1043163847c39Smrg      # Create the old-style object.
104320814a2baSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433d8556812Smrg
104340814a2baSmrg      output=$obj
1043563847c39Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
1043663847c39Smrg
1043763847c39Smrg      # Exit if we aren't doing a library object file.
1043863847c39Smrg      if test -z "$libobj"; then
1043963847c39Smrg	if test -n "$gentop"; then
1044063847c39Smrg	  func_show_eval '${RM}r "$gentop"'
1044163847c39Smrg	fi
1044263847c39Smrg
1044363847c39Smrg	exit $EXIT_SUCCESS
10444d8556812Smrg      fi
1044563847c39Smrg
104460814a2baSmrg      test yes = "$build_libtool_libs" || {
1044763847c39Smrg	if test -n "$gentop"; then
1044863847c39Smrg	  func_show_eval '${RM}r "$gentop"'
1044963847c39Smrg	fi
1045063847c39Smrg
1045163847c39Smrg	# Create an invalid libtool object if no PIC, so that we don't
1045263847c39Smrg	# accidentally link it into a program.
1045363847c39Smrg	# $show "echo timestamp > $libobj"
1045463847c39Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1045563847c39Smrg	exit $EXIT_SUCCESS
104560814a2baSmrg      }
1045763847c39Smrg
104580814a2baSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1045963847c39Smrg	# Only do commands if we really have different PIC objects.
1046063847c39Smrg	reload_objs="$libobjs $reload_conv_objs"
104610814a2baSmrg	output=$libobj
1046263847c39Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
1046363847c39Smrg      fi
1046463847c39Smrg
1046563847c39Smrg      if test -n "$gentop"; then
1046663847c39Smrg	func_show_eval '${RM}r "$gentop"'
1046763847c39Smrg      fi
1046863847c39Smrg
1046963847c39Smrg      exit $EXIT_SUCCESS
10470d8556812Smrg      ;;
1047176888252Smrg
1047263847c39Smrg    prog)
1047363847c39Smrg      case $host in
1047463847c39Smrg	*cygwin*) func_stripname '' '.exe' "$output"
1047563847c39Smrg	          output=$func_stripname_result.exe;;
1047663847c39Smrg      esac
1047763847c39Smrg      test -n "$vinfo" && \
104780814a2baSmrg	func_warning "'-version-info' is ignored for programs"
1047976888252Smrg
1048063847c39Smrg      test -n "$release" && \
104810814a2baSmrg	func_warning "'-release' is ignored for programs"
1048276888252Smrg
104830814a2baSmrg      $preload \
104840814a2baSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
104850814a2baSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1048663847c39Smrg
1048763847c39Smrg      case $host in
1048863847c39Smrg      *-*-rhapsody* | *-*-darwin1.[012])
1048963847c39Smrg	# On Rhapsody replace the C library is the System framework
1049063847c39Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1049163847c39Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492d8556812Smrg	;;
1049363847c39Smrg      esac
10494d8556812Smrg
1049563847c39Smrg      case $host in
1049663847c39Smrg      *-*-darwin*)
1049763847c39Smrg	# Don't allow lazy linking, it breaks C++ global constructors
1049863847c39Smrg	# But is supposedly fixed on 10.4 or later (yay!).
104990814a2baSmrg	if test CXX = "$tagname"; then
1050063847c39Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1050163847c39Smrg	    10.[0123])
105020814a2baSmrg	      func_append compile_command " $wl-bind_at_load"
105030814a2baSmrg	      func_append finalize_command " $wl-bind_at_load"
1050463847c39Smrg	    ;;
1050563847c39Smrg	  esac
10506d8556812Smrg	fi
1050763847c39Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050863847c39Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050963847c39Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1051063847c39Smrg	;;
1051163847c39Smrg      esac
10512d8556812Smrg
10513d8556812Smrg
1051463847c39Smrg      # move library search paths that coincide with paths to not yet
1051563847c39Smrg      # installed libraries to the beginning of the library search list
1051663847c39Smrg      new_libs=
1051763847c39Smrg      for path in $notinst_path; do
1051863847c39Smrg	case " $new_libs " in
1051963847c39Smrg	*" -L$path/$objdir "*) ;;
1052063847c39Smrg	*)
1052163847c39Smrg	  case " $compile_deplibs " in
1052263847c39Smrg	  *" -L$path/$objdir "*)
1052363847c39Smrg	    func_append new_libs " -L$path/$objdir" ;;
1052486dafe34Smrg	  esac
1052563847c39Smrg	  ;;
1052663847c39Smrg	esac
1052763847c39Smrg      done
1052863847c39Smrg      for deplib in $compile_deplibs; do
1052963847c39Smrg	case $deplib in
1053063847c39Smrg	-L*)
1053163847c39Smrg	  case " $new_libs " in
1053263847c39Smrg	  *" $deplib "*) ;;
1053363847c39Smrg	  *) func_append new_libs " $deplib" ;;
1053476888252Smrg	  esac
1053563847c39Smrg	  ;;
1053663847c39Smrg	*) func_append new_libs " $deplib" ;;
1053763847c39Smrg	esac
1053863847c39Smrg      done
105390814a2baSmrg      compile_deplibs=$new_libs
1054086dafe34Smrg
10541d8556812Smrg
1054263847c39Smrg      func_append compile_command " $compile_deplibs"
1054363847c39Smrg      func_append finalize_command " $finalize_deplibs"
10544d8556812Smrg
1054563847c39Smrg      if test -n "$rpath$xrpath"; then
1054663847c39Smrg	# If the user specified any rpath flags, then add them.
1054763847c39Smrg	for libdir in $rpath $xrpath; do
1054863847c39Smrg	  # This is the magic to use -rpath.
1054963847c39Smrg	  case "$finalize_rpath " in
1055063847c39Smrg	  *" $libdir "*) ;;
1055163847c39Smrg	  *) func_append finalize_rpath " $libdir" ;;
1055263847c39Smrg	  esac
1055363847c39Smrg	done
1055463847c39Smrg      fi
10555d8556812Smrg
1055663847c39Smrg      # Now hardcode the library paths
1055763847c39Smrg      rpath=
1055863847c39Smrg      hardcode_libdirs=
1055963847c39Smrg      for libdir in $compile_rpath $finalize_rpath; do
1056063847c39Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1056163847c39Smrg	  if test -n "$hardcode_libdir_separator"; then
1056263847c39Smrg	    if test -z "$hardcode_libdirs"; then
105630814a2baSmrg	      hardcode_libdirs=$libdir
1056463847c39Smrg	    else
1056563847c39Smrg	      # Just accumulate the unique libdirs.
1056663847c39Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1056763847c39Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1056863847c39Smrg		;;
1056963847c39Smrg	      *)
1057063847c39Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1057163847c39Smrg		;;
1057263847c39Smrg	      esac
1057363847c39Smrg	    fi
10574d8556812Smrg	  else
1057563847c39Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1057663847c39Smrg	    func_append rpath " $flag"
10577d8556812Smrg	  fi
1057863847c39Smrg	elif test -n "$runpath_var"; then
1057963847c39Smrg	  case "$perm_rpath " in
1058063847c39Smrg	  *" $libdir "*) ;;
1058163847c39Smrg	  *) func_append perm_rpath " $libdir" ;;
1058263847c39Smrg	  esac
1058363847c39Smrg	fi
1058463847c39Smrg	case $host in
1058563847c39Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
105860814a2baSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1058763847c39Smrg	  case :$dllsearchpath: in
1058863847c39Smrg	  *":$libdir:"*) ;;
1058963847c39Smrg	  ::) dllsearchpath=$libdir;;
1059063847c39Smrg	  *) func_append dllsearchpath ":$libdir";;
1059163847c39Smrg	  esac
1059263847c39Smrg	  case :$dllsearchpath: in
1059363847c39Smrg	  *":$testbindir:"*) ;;
1059463847c39Smrg	  ::) dllsearchpath=$testbindir;;
1059563847c39Smrg	  *) func_append dllsearchpath ":$testbindir";;
1059663847c39Smrg	  esac
1059763847c39Smrg	  ;;
1059863847c39Smrg	esac
1059963847c39Smrg      done
1060063847c39Smrg      # Substitute the hardcoded libdirs into the rpath.
1060163847c39Smrg      if test -n "$hardcode_libdir_separator" &&
1060263847c39Smrg	 test -n "$hardcode_libdirs"; then
106030814a2baSmrg	libdir=$hardcode_libdirs
1060463847c39Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1060563847c39Smrg      fi
106060814a2baSmrg      compile_rpath=$rpath
10607d8556812Smrg
1060863847c39Smrg      rpath=
1060963847c39Smrg      hardcode_libdirs=
1061063847c39Smrg      for libdir in $finalize_rpath; do
1061163847c39Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1061263847c39Smrg	  if test -n "$hardcode_libdir_separator"; then
1061363847c39Smrg	    if test -z "$hardcode_libdirs"; then
106140814a2baSmrg	      hardcode_libdirs=$libdir
1061563847c39Smrg	    else
1061663847c39Smrg	      # Just accumulate the unique libdirs.
1061763847c39Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1061863847c39Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1061963847c39Smrg		;;
1062063847c39Smrg	      *)
1062163847c39Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1062263847c39Smrg		;;
1062363847c39Smrg	      esac
1062463847c39Smrg	    fi
1062586dafe34Smrg	  else
1062663847c39Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1062763847c39Smrg	    func_append rpath " $flag"
1062886dafe34Smrg	  fi
1062963847c39Smrg	elif test -n "$runpath_var"; then
1063063847c39Smrg	  case "$finalize_perm_rpath " in
1063163847c39Smrg	  *" $libdir "*) ;;
1063263847c39Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1063363847c39Smrg	  esac
1063476888252Smrg	fi
1063563847c39Smrg      done
1063663847c39Smrg      # Substitute the hardcoded libdirs into the rpath.
1063763847c39Smrg      if test -n "$hardcode_libdir_separator" &&
1063863847c39Smrg	 test -n "$hardcode_libdirs"; then
106390814a2baSmrg	libdir=$hardcode_libdirs
1064063847c39Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1064163847c39Smrg      fi
106420814a2baSmrg      finalize_rpath=$rpath
1064376888252Smrg
106440814a2baSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1064563847c39Smrg	# Transform all the library objects into standard objects.
1064663847c39Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064763847c39Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064863847c39Smrg      fi
1064976888252Smrg
106500814a2baSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
1065176888252Smrg
1065263847c39Smrg      # template prelinking step
1065363847c39Smrg      if test -n "$prelink_cmds"; then
1065463847c39Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1065563847c39Smrg      fi
1065676888252Smrg
106570814a2baSmrg      wrappers_required=:
1065863847c39Smrg      case $host in
1065963847c39Smrg      *cegcc* | *mingw32ce*)
1066063847c39Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
106610814a2baSmrg        wrappers_required=false
1066263847c39Smrg        ;;
1066363847c39Smrg      *cygwin* | *mingw* )
106640814a2baSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
1066563847c39Smrg        ;;
1066663847c39Smrg      *)
106670814a2baSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
106680814a2baSmrg          wrappers_required=false
1066963847c39Smrg        fi
1067063847c39Smrg        ;;
1067163847c39Smrg      esac
106720814a2baSmrg      $wrappers_required || {
1067363847c39Smrg	# Replace the output file specification.
1067463847c39Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
106750814a2baSmrg	link_command=$compile_command$compile_rpath
1067676888252Smrg
1067763847c39Smrg	# We have no uninstalled library dependencies, so finalize right now.
1067863847c39Smrg	exit_status=0
1067963847c39Smrg	func_show_eval "$link_command" 'exit_status=$?'
1068076888252Smrg
1068163847c39Smrg	if test -n "$postlink_cmds"; then
1068263847c39Smrg	  func_to_tool_file "$output"
1068363847c39Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1068463847c39Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1068586dafe34Smrg	fi
1068676888252Smrg
1068763847c39Smrg	# Delete the generated files.
106880814a2baSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
106890814a2baSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
1069063847c39Smrg	fi
1069176888252Smrg
1069263847c39Smrg	exit $exit_status
106930814a2baSmrg      }
1069476888252Smrg
1069563847c39Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1069663847c39Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1069763847c39Smrg      fi
1069863847c39Smrg      if test -n "$finalize_shlibpath"; then
1069963847c39Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1070063847c39Smrg      fi
10701d8556812Smrg
1070263847c39Smrg      compile_var=
1070363847c39Smrg      finalize_var=
1070463847c39Smrg      if test -n "$runpath_var"; then
1070563847c39Smrg	if test -n "$perm_rpath"; then
1070663847c39Smrg	  # We should set the runpath_var.
1070763847c39Smrg	  rpath=
1070863847c39Smrg	  for dir in $perm_rpath; do
1070963847c39Smrg	    func_append rpath "$dir:"
1071063847c39Smrg	  done
1071163847c39Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
1071276888252Smrg	fi
1071363847c39Smrg	if test -n "$finalize_perm_rpath"; then
1071463847c39Smrg	  # We should set the runpath_var.
1071563847c39Smrg	  rpath=
1071663847c39Smrg	  for dir in $finalize_perm_rpath; do
1071763847c39Smrg	    func_append rpath "$dir:"
1071863847c39Smrg	  done
1071963847c39Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
1072086dafe34Smrg	fi
1072163847c39Smrg      fi
1072276888252Smrg
107230814a2baSmrg      if test yes = "$no_install"; then
1072463847c39Smrg	# We don't need to create a wrapper script.
107250814a2baSmrg	link_command=$compile_var$compile_command$compile_rpath
1072663847c39Smrg	# Replace the output file specification.
1072763847c39Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1072863847c39Smrg	# Delete the old output file.
1072963847c39Smrg	$opt_dry_run || $RM $output
1073063847c39Smrg	# Link the executable and exit
1073163847c39Smrg	func_show_eval "$link_command" 'exit $?'
1073276888252Smrg
1073363847c39Smrg	if test -n "$postlink_cmds"; then
1073463847c39Smrg	  func_to_tool_file "$output"
1073563847c39Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1073663847c39Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737d8556812Smrg	fi
1073863847c39Smrg
10739d8556812Smrg	exit $EXIT_SUCCESS
1074063847c39Smrg      fi
1074176888252Smrg
107420814a2baSmrg      case $hardcode_action,$fast_install in
107430814a2baSmrg        relink,*)
107440814a2baSmrg	  # Fast installation is not supported
107450814a2baSmrg	  link_command=$compile_var$compile_command$compile_rpath
107460814a2baSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1074763847c39Smrg
107480814a2baSmrg	  func_warning "this platform does not like uninstalled shared libraries"
107490814a2baSmrg	  func_warning "'$output' will be relinked during installation"
107500814a2baSmrg	  ;;
107510814a2baSmrg        *,yes)
107520814a2baSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107530814a2baSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
107540814a2baSmrg          ;;
107550814a2baSmrg	*,no)
107560814a2baSmrg	  link_command=$compile_var$compile_command$compile_rpath
107570814a2baSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107580814a2baSmrg          ;;
107590814a2baSmrg	*,needless)
107600814a2baSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107610814a2baSmrg	  relink_command=
107620814a2baSmrg          ;;
107630814a2baSmrg      esac
1076476888252Smrg
1076563847c39Smrg      # Replace the output file specification.
1076663847c39Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
1076776888252Smrg
1076863847c39Smrg      # Delete the old output files.
1076963847c39Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
1077076888252Smrg
1077163847c39Smrg      func_show_eval "$link_command" 'exit $?'
1077276888252Smrg
1077363847c39Smrg      if test -n "$postlink_cmds"; then
1077463847c39Smrg	func_to_tool_file "$output_objdir/$outputname"
1077563847c39Smrg	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'`
1077663847c39Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1077763847c39Smrg      fi
10778d8556812Smrg
1077963847c39Smrg      # Now create the wrapper script.
1078063847c39Smrg      func_verbose "creating $output"
10781d8556812Smrg
1078263847c39Smrg      # Quote the relink command for shipping.
1078363847c39Smrg      if test -n "$relink_command"; then
1078463847c39Smrg	# Preserve any variables that may affect compiler behavior
1078563847c39Smrg	for var in $variables_saved_for_relink; do
1078663847c39Smrg	  if eval test -z \"\${$var+set}\"; then
1078763847c39Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1078863847c39Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1078963847c39Smrg	    relink_command="$var=; export $var; $relink_command"
1079086dafe34Smrg	  else
107910814a2baSmrg	    func_quote_arg pretty "$var_value"
107920814a2baSmrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
1079386dafe34Smrg	  fi
1079463847c39Smrg	done
107950814a2baSmrg	func_quote eval cd "`pwd`"
107960814a2baSmrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
107970814a2baSmrg	relink_command=$func_quote_arg_unquoted_result
1079863847c39Smrg      fi
1079963847c39Smrg
1080063847c39Smrg      # Only actually do things if not in dry run mode.
1080163847c39Smrg      $opt_dry_run || {
1080263847c39Smrg	# win32 will think the script is a binary if it has
1080363847c39Smrg	# a .exe suffix, so we strip it off here.
1080463847c39Smrg	case $output in
1080563847c39Smrg	  *.exe) func_stripname '' '.exe' "$output"
1080663847c39Smrg	         output=$func_stripname_result ;;
1080776888252Smrg	esac
1080863847c39Smrg	# test for cygwin because mv fails w/o .exe extensions
1080963847c39Smrg	case $host in
1081063847c39Smrg	  *cygwin*)
1081163847c39Smrg	    exeext=.exe
1081263847c39Smrg	    func_stripname '' '.exe' "$outputname"
1081363847c39Smrg	    outputname=$func_stripname_result ;;
1081463847c39Smrg	  *) exeext= ;;
1081563847c39Smrg	esac
1081663847c39Smrg	case $host in
1081763847c39Smrg	  *cygwin* | *mingw* )
1081863847c39Smrg	    func_dirname_and_basename "$output" "" "."
1081963847c39Smrg	    output_name=$func_basename_result
1082063847c39Smrg	    output_path=$func_dirname_result
108210814a2baSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
108220814a2baSmrg	    cwrapper=$output_path/$output_name.exe
1082363847c39Smrg	    $RM $cwrappersource $cwrapper
1082463847c39Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1082563847c39Smrg
1082663847c39Smrg	    func_emit_cwrapperexe_src > $cwrappersource
1082763847c39Smrg
1082863847c39Smrg	    # The wrapper executable is built using the $host compiler,
1082963847c39Smrg	    # because it contains $host paths and files. If cross-
1083063847c39Smrg	    # compiling, it, like the target executable, must be
1083163847c39Smrg	    # executed on the $host or under an emulation environment.
1083263847c39Smrg	    $opt_dry_run || {
1083363847c39Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1083463847c39Smrg	      $STRIP $cwrapper
1083563847c39Smrg	    }
1083676888252Smrg
1083763847c39Smrg	    # Now, create the wrapper script for func_source use:
1083863847c39Smrg	    func_ltwrapper_scriptname $cwrapper
1083963847c39Smrg	    $RM $func_ltwrapper_scriptname_result
1084063847c39Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1084163847c39Smrg	    $opt_dry_run || {
1084263847c39Smrg	      # note: this script will not be executed, so do not chmod.
108430814a2baSmrg	      if test "x$build" = "x$host"; then
1084463847c39Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1084563847c39Smrg	      else
1084663847c39Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1084763847c39Smrg	      fi
1084863847c39Smrg	    }
1084963847c39Smrg	  ;;
1085063847c39Smrg	  * )
1085163847c39Smrg	    $RM $output
1085263847c39Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
1085376888252Smrg
1085463847c39Smrg	    func_emit_wrapper no > $output
1085563847c39Smrg	    chmod +x $output
1085663847c39Smrg	  ;;
1085763847c39Smrg	esac
1085863847c39Smrg      }
1085963847c39Smrg      exit $EXIT_SUCCESS
1086063847c39Smrg      ;;
1086163847c39Smrg    esac
1086276888252Smrg
1086363847c39Smrg    # See if we need to build an old-fashioned archive.
1086463847c39Smrg    for oldlib in $oldlibs; do
1086576888252Smrg
108660814a2baSmrg      case $build_libtool_libs in
108670814a2baSmrg        convenience)
108680814a2baSmrg	  oldobjs="$libobjs_save $symfileobj"
108690814a2baSmrg	  addlibs=$convenience
1087063847c39Smrg	  build_libtool_libs=no
108710814a2baSmrg	  ;;
108720814a2baSmrg	module)
108730814a2baSmrg	  oldobjs=$libobjs_save
108740814a2baSmrg	  addlibs=$old_convenience
108750814a2baSmrg	  build_libtool_libs=no
108760814a2baSmrg          ;;
108770814a2baSmrg	*)
1087863847c39Smrg	  oldobjs="$old_deplibs $non_pic_objects"
108790814a2baSmrg	  $preload && test -f "$symfileobj" \
108800814a2baSmrg	    && func_append oldobjs " $symfileobj"
108810814a2baSmrg	  addlibs=$old_convenience
108820814a2baSmrg	  ;;
108830814a2baSmrg      esac
1088476888252Smrg
1088563847c39Smrg      if test -n "$addlibs"; then
108860814a2baSmrg	gentop=$output_objdir/${outputname}x
1088763847c39Smrg	func_append generated " $gentop"
1088876888252Smrg
1088963847c39Smrg	func_extract_archives $gentop $addlibs
1089063847c39Smrg	func_append oldobjs " $func_extract_archives_result"
1089163847c39Smrg      fi
1089276888252Smrg
1089363847c39Smrg      # Do each command in the archive commands.
108940814a2baSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1089563847c39Smrg	cmds=$old_archive_from_new_cmds
1089663847c39Smrg      else
1089776888252Smrg
1089863847c39Smrg	# Add any objects from preloaded convenience libraries
1089963847c39Smrg	if test -n "$dlprefiles"; then
109000814a2baSmrg	  gentop=$output_objdir/${outputname}x
1090163847c39Smrg	  func_append generated " $gentop"
1090276888252Smrg
1090363847c39Smrg	  func_extract_archives $gentop $dlprefiles
1090463847c39Smrg	  func_append oldobjs " $func_extract_archives_result"
1090563847c39Smrg	fi
1090676888252Smrg
1090763847c39Smrg	# POSIX demands no paths to be encoded in archives.  We have
1090863847c39Smrg	# to avoid creating archives with duplicate basenames if we
1090963847c39Smrg	# might have to extract them afterwards, e.g., when creating a
1091063847c39Smrg	# static archive out of a convenience library, or when linking
1091163847c39Smrg	# the entirety of a libtool archive into another (currently
1091263847c39Smrg	# not supported by libtool).
1091363847c39Smrg	if (for obj in $oldobjs
1091463847c39Smrg	    do
1091563847c39Smrg	      func_basename "$obj"
1091663847c39Smrg	      $ECHO "$func_basename_result"
1091763847c39Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
1091863847c39Smrg	  :
1091963847c39Smrg	else
1092063847c39Smrg	  echo "copying selected object files to avoid basename conflicts..."
109210814a2baSmrg	  gentop=$output_objdir/${outputname}x
1092263847c39Smrg	  func_append generated " $gentop"
1092363847c39Smrg	  func_mkdir_p "$gentop"
1092463847c39Smrg	  save_oldobjs=$oldobjs
1092563847c39Smrg	  oldobjs=
1092663847c39Smrg	  counter=1
1092763847c39Smrg	  for obj in $save_oldobjs
1092863847c39Smrg	  do
1092963847c39Smrg	    func_basename "$obj"
109300814a2baSmrg	    objbase=$func_basename_result
1093163847c39Smrg	    case " $oldobjs " in
1093263847c39Smrg	    " ") oldobjs=$obj ;;
1093363847c39Smrg	    *[\ /]"$objbase "*)
1093463847c39Smrg	      while :; do
1093563847c39Smrg		# Make sure we don't pick an alternate name that also
1093663847c39Smrg		# overlaps.
1093763847c39Smrg		newobj=lt$counter-$objbase
1093863847c39Smrg		func_arith $counter + 1
1093963847c39Smrg		counter=$func_arith_result
1094063847c39Smrg		case " $oldobjs " in
1094163847c39Smrg		*[\ /]"$newobj "*) ;;
1094263847c39Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1094363847c39Smrg		esac
1094463847c39Smrg	      done
1094563847c39Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1094663847c39Smrg	      func_append oldobjs " $gentop/$newobj"
1094763847c39Smrg	      ;;
1094863847c39Smrg	    *) func_append oldobjs " $obj" ;;
1094963847c39Smrg	    esac
1095076888252Smrg	  done
1095186dafe34Smrg	fi
1095263847c39Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
1095363847c39Smrg	tool_oldlib=$func_to_tool_file_result
1095463847c39Smrg	eval cmds=\"$old_archive_cmds\"
10955d8556812Smrg
1095663847c39Smrg	func_len " $cmds"
1095763847c39Smrg	len=$func_len_result
1095863847c39Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1095963847c39Smrg	  cmds=$old_archive_cmds
1096063847c39Smrg	elif test -n "$archiver_list_spec"; then
1096163847c39Smrg	  func_verbose "using command file archive linking..."
1096263847c39Smrg	  for obj in $oldobjs
1096363847c39Smrg	  do
1096463847c39Smrg	    func_to_tool_file "$obj"
1096563847c39Smrg	    $ECHO "$func_to_tool_file_result"
1096663847c39Smrg	  done > $output_objdir/$libname.libcmd
1096763847c39Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1096863847c39Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1096963847c39Smrg	  cmds=$old_archive_cmds
1097063847c39Smrg	else
1097163847c39Smrg	  # the command line is too long to link in one step, link in parts
1097263847c39Smrg	  func_verbose "using piecewise archive linking..."
1097363847c39Smrg	  save_RANLIB=$RANLIB
1097463847c39Smrg	  RANLIB=:
1097563847c39Smrg	  objlist=
1097663847c39Smrg	  concat_cmds=
1097763847c39Smrg	  save_oldobjs=$oldobjs
1097863847c39Smrg	  oldobjs=
1097963847c39Smrg	  # Is there a better way of finding the last object in the list?
1098063847c39Smrg	  for obj in $save_oldobjs
1098163847c39Smrg	  do
1098263847c39Smrg	    last_oldobj=$obj
1098363847c39Smrg	  done
1098463847c39Smrg	  eval test_cmds=\"$old_archive_cmds\"
1098563847c39Smrg	  func_len " $test_cmds"
1098663847c39Smrg	  len0=$func_len_result
1098763847c39Smrg	  len=$len0
1098863847c39Smrg	  for obj in $save_oldobjs
1098963847c39Smrg	  do
1099063847c39Smrg	    func_len " $obj"
1099163847c39Smrg	    func_arith $len + $func_len_result
1099263847c39Smrg	    len=$func_arith_result
1099363847c39Smrg	    func_append objlist " $obj"
1099463847c39Smrg	    if test "$len" -lt "$max_cmd_len"; then
1099563847c39Smrg	      :
1099663847c39Smrg	    else
1099763847c39Smrg	      # the above command should be used before it gets too long
1099863847c39Smrg	      oldobjs=$objlist
109990814a2baSmrg	      if test "$obj" = "$last_oldobj"; then
1100063847c39Smrg		RANLIB=$save_RANLIB
1100163847c39Smrg	      fi
1100263847c39Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
110030814a2baSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1100463847c39Smrg	      objlist=
1100563847c39Smrg	      len=$len0
1100663847c39Smrg	    fi
1100763847c39Smrg	  done
1100863847c39Smrg	  RANLIB=$save_RANLIB
1100963847c39Smrg	  oldobjs=$objlist
110100814a2baSmrg	  if test -z "$oldobjs"; then
1101163847c39Smrg	    eval cmds=\"\$concat_cmds\"
1101263847c39Smrg	  else
1101363847c39Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1101463847c39Smrg	  fi
1101563847c39Smrg	fi
1101663847c39Smrg      fi
1101763847c39Smrg      func_execute_cmds "$cmds" 'exit $?'
1101876888252Smrg    done
1101976888252Smrg
1102063847c39Smrg    test -n "$generated" && \
1102163847c39Smrg      func_show_eval "${RM}r$generated"
1102276888252Smrg
1102363847c39Smrg    # Now create the libtool archive.
1102463847c39Smrg    case $output in
1102563847c39Smrg    *.la)
1102663847c39Smrg      old_library=
110270814a2baSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1102863847c39Smrg      func_verbose "creating $output"
1102986dafe34Smrg
1103063847c39Smrg      # Preserve any variables that may affect compiler behavior
1103163847c39Smrg      for var in $variables_saved_for_relink; do
1103263847c39Smrg	if eval test -z \"\${$var+set}\"; then
1103363847c39Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1103463847c39Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
1103563847c39Smrg	  relink_command="$var=; export $var; $relink_command"
11036d8556812Smrg	else
110370814a2baSmrg	  func_quote_arg pretty,unquoted "$var_value"
110380814a2baSmrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039d8556812Smrg	fi
1104063847c39Smrg      done
1104163847c39Smrg      # Quote the link command for shipping.
110420814a2baSmrg      func_quote eval cd "`pwd`"
110430814a2baSmrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
110440814a2baSmrg      func_quote_arg pretty,unquoted "$relink_command"
110450814a2baSmrg      relink_command=$func_quote_arg_unquoted_result
110460814a2baSmrg      if test yes = "$hardcode_automatic"; then
1104763847c39Smrg	relink_command=
1104863847c39Smrg      fi
1104976888252Smrg
1105063847c39Smrg      # Only create the output if not a dry run.
1105163847c39Smrg      $opt_dry_run || {
1105263847c39Smrg	for installed in no yes; do
110530814a2baSmrg	  if test yes = "$installed"; then
1105463847c39Smrg	    if test -z "$install_libdir"; then
1105563847c39Smrg	      break
1105663847c39Smrg	    fi
110570814a2baSmrg	    output=$output_objdir/${outputname}i
1105863847c39Smrg	    # Replace all uninstalled libtool libraries with the installed ones
1105963847c39Smrg	    newdependency_libs=
1106063847c39Smrg	    for deplib in $dependency_libs; do
1106163847c39Smrg	      case $deplib in
1106263847c39Smrg	      *.la)
1106363847c39Smrg		func_basename "$deplib"
110640814a2baSmrg		name=$func_basename_result
1106563847c39Smrg		func_resolve_sysroot "$deplib"
110660814a2baSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1106763847c39Smrg		test -z "$libdir" && \
110680814a2baSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1106963847c39Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1107063847c39Smrg		;;
1107163847c39Smrg	      -L*)
1107263847c39Smrg		func_stripname -L '' "$deplib"
1107363847c39Smrg		func_replace_sysroot "$func_stripname_result"
1107463847c39Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1107563847c39Smrg		;;
1107663847c39Smrg	      -R*)
1107763847c39Smrg		func_stripname -R '' "$deplib"
1107863847c39Smrg		func_replace_sysroot "$func_stripname_result"
1107963847c39Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
1108063847c39Smrg		;;
1108163847c39Smrg	      *) func_append newdependency_libs " $deplib" ;;
1108263847c39Smrg	      esac
1108363847c39Smrg	    done
110840814a2baSmrg	    dependency_libs=$newdependency_libs
1108563847c39Smrg	    newdlfiles=
1108663847c39Smrg
1108763847c39Smrg	    for lib in $dlfiles; do
1108863847c39Smrg	      case $lib in
1108963847c39Smrg	      *.la)
1109063847c39Smrg	        func_basename "$lib"
110910814a2baSmrg		name=$func_basename_result
110920814a2baSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1109363847c39Smrg		test -z "$libdir" && \
110940814a2baSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1109563847c39Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1109663847c39Smrg		;;
1109763847c39Smrg	      *) func_append newdlfiles " $lib" ;;
1109863847c39Smrg	      esac
1109963847c39Smrg	    done
111000814a2baSmrg	    dlfiles=$newdlfiles
1110163847c39Smrg	    newdlprefiles=
1110263847c39Smrg	    for lib in $dlprefiles; do
1110363847c39Smrg	      case $lib in
1110463847c39Smrg	      *.la)
1110563847c39Smrg		# Only pass preopened files to the pseudo-archive (for
1110663847c39Smrg		# eventual linking with the app. that links it) if we
1110763847c39Smrg		# didn't already link the preopened objects directly into
1110863847c39Smrg		# the library:
1110963847c39Smrg		func_basename "$lib"
111100814a2baSmrg		name=$func_basename_result
111110814a2baSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1111263847c39Smrg		test -z "$libdir" && \
111130814a2baSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1111463847c39Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1111563847c39Smrg		;;
1111663847c39Smrg	      esac
1111763847c39Smrg	    done
111180814a2baSmrg	    dlprefiles=$newdlprefiles
1111963847c39Smrg	  else
1112063847c39Smrg	    newdlfiles=
1112163847c39Smrg	    for lib in $dlfiles; do
1112263847c39Smrg	      case $lib in
111230814a2baSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1112463847c39Smrg		*) abs=`pwd`"/$lib" ;;
1112563847c39Smrg	      esac
1112663847c39Smrg	      func_append newdlfiles " $abs"
1112763847c39Smrg	    done
111280814a2baSmrg	    dlfiles=$newdlfiles
1112963847c39Smrg	    newdlprefiles=
1113063847c39Smrg	    for lib in $dlprefiles; do
1113163847c39Smrg	      case $lib in
111320814a2baSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1113363847c39Smrg		*) abs=`pwd`"/$lib" ;;
1113463847c39Smrg	      esac
1113563847c39Smrg	      func_append newdlprefiles " $abs"
1113663847c39Smrg	    done
111370814a2baSmrg	    dlprefiles=$newdlprefiles
1113863847c39Smrg	  fi
1113963847c39Smrg	  $RM $output
1114063847c39Smrg	  # place dlname in correct position for cygwin
1114163847c39Smrg	  # In fact, it would be nice if we could use this code for all target
1114263847c39Smrg	  # systems that can't hard-code library paths into their executables
1114363847c39Smrg	  # and that have no shared library path variable independent of PATH,
1114463847c39Smrg	  # but it turns out we can't easily determine that from inspecting
1114563847c39Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1114663847c39Smrg	  # applies here; at the moment, that means platforms that use the PE
1114763847c39Smrg	  # object format with DLL files.  See the long comment at the top of
1114863847c39Smrg	  # tests/bindir.at for full details.
1114963847c39Smrg	  tdlname=$dlname
1115063847c39Smrg	  case $host,$output,$installed,$module,$dlname in
1115163847c39Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1115263847c39Smrg	      # If a -bindir argument was supplied, place the dll there.
111530814a2baSmrg	      if test -n "$bindir"; then
1115463847c39Smrg		func_relative_path "$install_libdir" "$bindir"
111550814a2baSmrg		tdlname=$func_relative_path_result/$dlname
1115663847c39Smrg	      else
1115763847c39Smrg		# Otherwise fall back on heuristic.
1115863847c39Smrg		tdlname=../bin/$dlname
1115963847c39Smrg	      fi
1116063847c39Smrg	      ;;
1116163847c39Smrg	  esac
1116263847c39Smrg	  $ECHO > $output "\
1116363847c39Smrg# $outputname - a libtool library file
111640814a2baSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1116563847c39Smrg#
1116663847c39Smrg# Please DO NOT delete this file!
1116763847c39Smrg# It is necessary for linking the library.
1116876888252Smrg
1116963847c39Smrg# The name that we can dlopen(3).
1117063847c39Smrgdlname='$tdlname'
1117176888252Smrg
1117263847c39Smrg# Names of this library.
1117363847c39Smrglibrary_names='$library_names'
1117476888252Smrg
1117563847c39Smrg# The name of the static archive.
1117663847c39Smrgold_library='$old_library'
1117776888252Smrg
111780814a2baSmrg# Linker flags that cannot go in dependency_libs.
1117963847c39Smrginherited_linker_flags='$new_inherited_linker_flags'
1118076888252Smrg
1118163847c39Smrg# Libraries that this one depends upon.
1118263847c39Smrgdependency_libs='$dependency_libs'
1118376888252Smrg
1118463847c39Smrg# Names of additional weak libraries provided by this library
1118563847c39Smrgweak_library_names='$weak_libs'
1118676888252Smrg
1118763847c39Smrg# Version information for $libname.
1118863847c39Smrgcurrent=$current
1118963847c39Smrgage=$age
1119063847c39Smrgrevision=$revision
1119176888252Smrg
1119263847c39Smrg# Is this an already installed library?
1119363847c39Smrginstalled=$installed
1119476888252Smrg
1119563847c39Smrg# Should we warn about portability when linking against -modules?
1119663847c39Smrgshouldnotlink=$module
1119776888252Smrg
1119863847c39Smrg# Files to dlopen/dlpreopen
1119963847c39Smrgdlopen='$dlfiles'
1120063847c39Smrgdlpreopen='$dlprefiles'
1120176888252Smrg
1120263847c39Smrg# Directory that this library needs to be installed in:
1120363847c39Smrglibdir='$install_libdir'"
112040814a2baSmrg	  if test no,yes = "$installed,$need_relink"; then
1120563847c39Smrg	    $ECHO >> $output "\
1120663847c39Smrgrelink_command=\"$relink_command\""
1120763847c39Smrg	  fi
1120863847c39Smrg	done
1120963847c39Smrg      }
1121076888252Smrg
1121163847c39Smrg      # Do a symbolic link so that the libtool archive can be found in
1121263847c39Smrg      # LD_LIBRARY_PATH before the program is installed.
1121363847c39Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1121463847c39Smrg      ;;
1121563847c39Smrg    esac
1121663847c39Smrg    exit $EXIT_SUCCESS
1121763847c39Smrg}
11218d8556812Smrg
112190814a2baSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
112200814a2baSmrg  func_mode_link ${1+"$@"}
112210814a2baSmrgfi
1122276888252Smrg
1122376888252Smrg
1122463847c39Smrg# func_mode_uninstall arg...
1122563847c39Smrgfunc_mode_uninstall ()
1122663847c39Smrg{
112270814a2baSmrg    $debug_cmd
112280814a2baSmrg
112290814a2baSmrg    RM=$nonopt
1123076888252Smrg    files=
112310814a2baSmrg    rmforce=false
1123276888252Smrg    exit_status=0
1123376888252Smrg
1123476888252Smrg    # This variable tells wrapper scripts just to set variables rather
1123576888252Smrg    # than running their programs.
112360814a2baSmrg    libtool_install_magic=$magic
1123776888252Smrg
1123876888252Smrg    for arg
1123976888252Smrg    do
1124076888252Smrg      case $arg in
112410814a2baSmrg      -f) func_append RM " $arg"; rmforce=: ;;
1124263847c39Smrg      -*) func_append RM " $arg" ;;
1124363847c39Smrg      *) func_append files " $arg" ;;
1124476888252Smrg      esac
1124576888252Smrg    done
1124676888252Smrg
1124763847c39Smrg    test -z "$RM" && \
1124863847c39Smrg      func_fatal_help "you must specify an RM program"
1124976888252Smrg
1125076888252Smrg    rmdirs=
1125176888252Smrg
1125276888252Smrg    for file in $files; do
1125363847c39Smrg      func_dirname "$file" "" "."
112540814a2baSmrg      dir=$func_dirname_result
112550814a2baSmrg      if test . = "$dir"; then
112560814a2baSmrg	odir=$objdir
1125776888252Smrg      else
112580814a2baSmrg	odir=$dir/$objdir
1125976888252Smrg      fi
1126063847c39Smrg      func_basename "$file"
112610814a2baSmrg      name=$func_basename_result
112620814a2baSmrg      test uninstall = "$opt_mode" && odir=$dir
1126376888252Smrg
1126463847c39Smrg      # Remember odir for removal later, being careful to avoid duplicates
112650814a2baSmrg      if test clean = "$opt_mode"; then
1126676888252Smrg	case " $rmdirs " in
1126763847c39Smrg	  *" $odir "*) ;;
1126863847c39Smrg	  *) func_append rmdirs " $odir" ;;
1126976888252Smrg	esac
1127076888252Smrg      fi
1127176888252Smrg
1127276888252Smrg      # Don't error if the file doesn't exist and rm -f was used.
1127363847c39Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1127463847c39Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1127563847c39Smrg	 test -f "$file"; then
1127676888252Smrg	:
1127776888252Smrg      elif test -d "$file"; then
1127876888252Smrg	exit_status=1
1127976888252Smrg	continue
112800814a2baSmrg      elif $rmforce; then
1128176888252Smrg	continue
1128276888252Smrg      fi
1128376888252Smrg
112840814a2baSmrg      rmfiles=$file
1128576888252Smrg
1128676888252Smrg      case $name in
1128776888252Smrg      *.la)
1128876888252Smrg	# Possibly a libtool archive, so verify it.
1128963847c39Smrg	if func_lalib_p "$file"; then
1129063847c39Smrg	  func_source $dir/$name
1129176888252Smrg
1129276888252Smrg	  # Delete the libtool libraries and symlinks.
1129376888252Smrg	  for n in $library_names; do
1129463847c39Smrg	    func_append rmfiles " $odir/$n"
1129576888252Smrg	  done
1129663847c39Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
1129776888252Smrg
112980814a2baSmrg	  case $opt_mode in
1129976888252Smrg	  clean)
1130063847c39Smrg	    case " $library_names " in
1130176888252Smrg	    *" $dlname "*) ;;
1130263847c39Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
1130376888252Smrg	    esac
1130463847c39Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
1130576888252Smrg	    ;;
1130676888252Smrg	  uninstall)
1130776888252Smrg	    if test -n "$library_names"; then
1130876888252Smrg	      # Do each command in the postuninstall commands.
113090814a2baSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
1131076888252Smrg	    fi
1131176888252Smrg
1131276888252Smrg	    if test -n "$old_library"; then
1131376888252Smrg	      # Do each command in the old_postuninstall commands.
113140814a2baSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
1131576888252Smrg	    fi
1131676888252Smrg	    # FIXME: should reinstall the best remaining shared library.
1131776888252Smrg	    ;;
1131876888252Smrg	  esac
1131976888252Smrg	fi
1132076888252Smrg	;;
1132176888252Smrg
1132276888252Smrg      *.lo)
1132376888252Smrg	# Possibly a libtool object, so verify it.
1132463847c39Smrg	if func_lalib_p "$file"; then
1132576888252Smrg
1132676888252Smrg	  # Read the .lo file
1132763847c39Smrg	  func_source $dir/$name
1132876888252Smrg
1132976888252Smrg	  # Add PIC object to the list of files to remove.
113300814a2baSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1133163847c39Smrg	    func_append rmfiles " $dir/$pic_object"
1133276888252Smrg	  fi
1133376888252Smrg
1133476888252Smrg	  # Add non-PIC object to the list of files to remove.
113350814a2baSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1133663847c39Smrg	    func_append rmfiles " $dir/$non_pic_object"
1133776888252Smrg	  fi
1133876888252Smrg	fi
1133976888252Smrg	;;
1134076888252Smrg
1134176888252Smrg      *)
113420814a2baSmrg	if test clean = "$opt_mode"; then
1134376888252Smrg	  noexename=$name
1134476888252Smrg	  case $file in
1134576888252Smrg	  *.exe)
1134663847c39Smrg	    func_stripname '' '.exe' "$file"
1134763847c39Smrg	    file=$func_stripname_result
1134863847c39Smrg	    func_stripname '' '.exe' "$name"
1134963847c39Smrg	    noexename=$func_stripname_result
1135076888252Smrg	    # $file with .exe has already been added to rmfiles,
1135176888252Smrg	    # add $file without .exe
1135263847c39Smrg	    func_append rmfiles " $file"
1135376888252Smrg	    ;;
1135476888252Smrg	  esac
1135576888252Smrg	  # Do a test to see if this is a libtool program.
1135663847c39Smrg	  if func_ltwrapper_p "$file"; then
1135763847c39Smrg	    if func_ltwrapper_executable_p "$file"; then
1135863847c39Smrg	      func_ltwrapper_scriptname "$file"
1135963847c39Smrg	      relink_command=
1136063847c39Smrg	      func_source $func_ltwrapper_scriptname_result
1136163847c39Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1136263847c39Smrg	    else
1136363847c39Smrg	      relink_command=
1136463847c39Smrg	      func_source $dir/$noexename
1136563847c39Smrg	    fi
1136676888252Smrg
1136776888252Smrg	    # note $name still contains .exe if it was in $file originally
1136876888252Smrg	    # as does the version of $file that was added into $rmfiles
113690814a2baSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
113700814a2baSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1137163847c39Smrg	      func_append rmfiles " $odir/lt-$name"
1137276888252Smrg	    fi
113730814a2baSmrg	    if test "X$noexename" != "X$name"; then
113740814a2baSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
1137576888252Smrg	    fi
1137676888252Smrg	  fi
1137776888252Smrg	fi
1137876888252Smrg	;;
1137976888252Smrg      esac
1138063847c39Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
1138176888252Smrg    done
1138276888252Smrg
113830814a2baSmrg    # Try to remove the $objdir's in the directories where we deleted files
1138476888252Smrg    for dir in $rmdirs; do
1138576888252Smrg      if test -d "$dir"; then
1138663847c39Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
1138776888252Smrg      fi
1138876888252Smrg    done
1138976888252Smrg
1139076888252Smrg    exit $exit_status
1139163847c39Smrg}
1139276888252Smrg
113930814a2baSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
113940814a2baSmrg  func_mode_uninstall ${1+"$@"}
113950814a2baSmrgfi
1139686dafe34Smrg
1139763847c39Smrgtest -z "$opt_mode" && {
113980814a2baSmrg  help=$generic_help
1139963847c39Smrg  func_fatal_help "you must specify a MODE"
1140063847c39Smrg}
1140163847c39Smrg
1140263847c39Smrgtest -z "$exec_cmd" && \
114030814a2baSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
1140476888252Smrg
1140576888252Smrgif test -n "$exec_cmd"; then
1140663847c39Smrg  eval exec "$exec_cmd"
1140776888252Smrg  exit $EXIT_FAILURE
1140876888252Smrgfi
1140976888252Smrg
1141063847c39Smrgexit $exit_status
11411d8556812Smrg
1141276888252Smrg
1141376888252Smrg# The TAGs below are defined such that we never get into a situation
114140814a2baSmrg# where we disable both kinds of libraries.  Given conflicting
1141576888252Smrg# choices, we go for a static library, that is the most portable,
1141676888252Smrg# since we can't tell whether shared libraries were disabled because
1141776888252Smrg# the user asked for that or because the platform doesn't support
1141876888252Smrg# them.  This is particularly important on AIX, because we don't
1141976888252Smrg# support having both static and shared libraries enabled at the same
1142076888252Smrg# time on that platform, so we default to a shared-only configuration.
1142176888252Smrg# If a disable-shared tag is given, we'll fallback to a static-only
1142276888252Smrg# configuration.  But we'll never go from static-only to shared-only.
1142376888252Smrg
1142476888252Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1142563847c39Smrgbuild_libtool_libs=no
1142663847c39Smrgbuild_old_libs=yes
1142776888252Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
1142876888252Smrg
1142976888252Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1143063847c39Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
1143176888252Smrg# ### END LIBTOOL TAG CONFIG: disable-static
1143276888252Smrg
1143376888252Smrg# Local Variables:
1143476888252Smrg# mode:shell-script
1143576888252Smrg# sh-indentation:2
1143676888252Smrg# End:
11437