122663e35Smrg#! /usr/bin/env sh
27322289dSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
322663e35Smrg##               by inline-source v2019-02-19.15
4d769e936Smrg
522663e35Smrg# libtool (GNU libtool) 2.4.7
67322289dSmrg# Provide generalized library-building support services.
7d769e936Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8d769e936Smrg
922663e35Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10d769e936Smrg# This is free software; see the source for copying conditions.  There is NO
11d769e936Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12d769e936Smrg
13d769e936Smrg# GNU Libtool is free software; you can redistribute it and/or modify
141d54945dSmrg# it under the terms of the GNU General Public License as published by
151d54945dSmrg# the Free Software Foundation; either version 2 of the License, or
161d54945dSmrg# (at your option) any later version.
171d54945dSmrg#
18d769e936Smrg# As a special exception to the GNU General Public License,
19d769e936Smrg# if you distribute this file as part of a program or library that
20d769e936Smrg# is built using GNU Libtool, you may include this file under the
21d769e936Smrg# same distribution terms that you use for the rest of that program.
22d769e936Smrg#
23d769e936Smrg# GNU Libtool is distributed in the hope that it will be useful, but
241d54945dSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
251d54945dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
261d54945dSmrg# General Public License for more details.
271d54945dSmrg#
281d54945dSmrg# You should have received a copy of the GNU General Public License
297322289dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30ec713c28Smrg
311d54945dSmrg
32d769e936SmrgPROGRAM=libtool
331d54945dSmrgPACKAGE=libtool
3422663e35SmrgVERSION=2.4.7
3522663e35Smrgpackage_revision=2.4.7
361d54945dSmrg
377322289dSmrg
387322289dSmrg## ------ ##
397322289dSmrg## Usage. ##
407322289dSmrg## ------ ##
417322289dSmrg
427322289dSmrg# Run './libtool --help' for help with using this script from the
437322289dSmrg# command line.
447322289dSmrg
457322289dSmrg
467322289dSmrg## ------------------------------- ##
477322289dSmrg## User overridable command paths. ##
487322289dSmrg## ------------------------------- ##
497322289dSmrg
507322289dSmrg# After configure completes, it has a better idea of some of the
517322289dSmrg# shell tools we need than the defaults used by the functions shared
527322289dSmrg# with bootstrap, so set those here where they can still be over-
537322289dSmrg# ridden by the user, but otherwise take precedence.
547322289dSmrg
557322289dSmrg: ${AUTOCONF="autoconf"}
567322289dSmrg: ${AUTOMAKE="automake"}
577322289dSmrg
587322289dSmrg
597322289dSmrg## -------------------------- ##
607322289dSmrg## Source external libraries. ##
617322289dSmrg## -------------------------- ##
627322289dSmrg
637322289dSmrg# Much of our low-level functionality needs to be sourced from external
647322289dSmrg# libraries, which are installed to $pkgauxdir.
657322289dSmrg
667322289dSmrg# Set a version string for this script.
6722663e35Smrgscriptversion=2019-02-19.15; # UTC
687322289dSmrg
697322289dSmrg# General shell script boiler plate, and helper functions.
707322289dSmrg# Written by Gary V. Vaughan, 2004
717322289dSmrg
7222663e35Smrg# This is free software.  There is NO warranty; not even for
7322663e35Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7422663e35Smrg#
7522663e35Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
7622663e35Smrg#
7722663e35Smrg# This file is dual licensed under the terms of the MIT license
7822663e35Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
7922663e35Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
8022663e35Smrg# these licenses when using or redistributing this software or any of
8122663e35Smrg# the files within it.  See the URLs above, or the file `LICENSE`
8222663e35Smrg# included in the Bootstrap distribution for the full license texts.
837322289dSmrg
8422663e35Smrg# Please report bugs or propose patches to:
8522663e35Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
867322289dSmrg
877322289dSmrg
887322289dSmrg## ------ ##
897322289dSmrg## Usage. ##
907322289dSmrg## ------ ##
917322289dSmrg
927322289dSmrg# Evaluate this file near the top of your script to gain access to
937322289dSmrg# the functions and variables defined here:
947322289dSmrg#
957322289dSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
967322289dSmrg#
977322289dSmrg# If you need to override any of the default environment variable
987322289dSmrg# settings, do that before evaluating this file.
997322289dSmrg
1007322289dSmrg
1017322289dSmrg## -------------------- ##
1027322289dSmrg## Shell normalisation. ##
1037322289dSmrg## -------------------- ##
1047322289dSmrg
1057322289dSmrg# Some shells need a little help to be as Bourne compatible as possible.
1067322289dSmrg# Before doing anything else, make sure all that help has been provided!
1077322289dSmrg
1087322289dSmrgDUALCASE=1; export DUALCASE # for MKS sh
1097322289dSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110ba85709eSmrg  emulate sh
111ba85709eSmrg  NULLCMD=:
1127322289dSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113ba85709eSmrg  # is contrary to our usage.  Disable this feature.
114ba85709eSmrg  alias -g '${1+"$@"}'='"$@"'
1151d54945dSmrg  setopt NO_GLOB_SUBST
116ba85709eSmrgelse
1177322289dSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1181d54945dSmrgfi
119ec713c28Smrg
1207322289dSmrg# NLS nuisances: We save the old values in case they are required later.
1217322289dSmrg_G_user_locale=
1227322289dSmrg_G_safe_locale=
1237322289dSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124ba85709eSmrgdo
1257322289dSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1267322289dSmrg          save_$_G_var=\$$_G_var
1277322289dSmrg          $_G_var=C
1287322289dSmrg	  export $_G_var
1297322289dSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1307322289dSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131786a6f21Smrg	fi"
132ba85709eSmrgdone
13322663e35Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
13422663e35Smrg# in case the environment reset is needed later and the $save_* variant is not
13522663e35Smrg# defined (see the code above).
13622663e35SmrgLC_ALL=C
13722663e35SmrgLANGUAGE=C
13822663e35Smrgexport LANGUAGE LC_ALL
1391d54945dSmrg
1407322289dSmrg# Make sure IFS has a sensible default
1417322289dSmrgsp=' '
1427322289dSmrgnl='
1437322289dSmrg'
1447322289dSmrgIFS="$sp	$nl"
1457322289dSmrg
1467322289dSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1477322289dSmrgif test "${PATH_SEPARATOR+set}" != set; then
1487322289dSmrg  PATH_SEPARATOR=:
1497322289dSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1507322289dSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1517322289dSmrg      PATH_SEPARATOR=';'
1527322289dSmrg  }
1537322289dSmrgfi
154d769e936Smrg
155d769e936Smrg
15622663e35Smrg# func_unset VAR
15722663e35Smrg# --------------
15822663e35Smrg# Portably unset VAR.
15922663e35Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
16022663e35Smrg# status if VAR is already unset, which might be problematic if the
16122663e35Smrg# statement is used at the end of a function (thus poisoning its return
16222663e35Smrg# value) or when 'set -e' is active (causing even a spurious abort of
16322663e35Smrg# the script in this case).
16422663e35Smrgfunc_unset ()
16522663e35Smrg{
16622663e35Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
16722663e35Smrg}
16822663e35Smrg
16922663e35Smrg
17022663e35Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
17122663e35Smrgfunc_unset CDPATH
17222663e35Smrg
17322663e35Smrg# Make sure ${,E,F}GREP behave sanely.
17422663e35Smrgfunc_unset GREP_OPTIONS
17522663e35Smrg
176d769e936Smrg
1777322289dSmrg## ------------------------- ##
1787322289dSmrg## Locate command utilities. ##
1797322289dSmrg## ------------------------- ##
1807322289dSmrg
1817322289dSmrg
1827322289dSmrg# func_executable_p FILE
1837322289dSmrg# ----------------------
1847322289dSmrg# Check that FILE is an executable regular file.
1857322289dSmrgfunc_executable_p ()
1867322289dSmrg{
1877322289dSmrg    test -f "$1" && test -x "$1"
1887322289dSmrg}
1897322289dSmrg
1907322289dSmrg
1917322289dSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1927322289dSmrg# --------------------------------------------
1937322289dSmrg# Search for either a program that responds to --version with output
1947322289dSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1957322289dSmrg# trying all the directories in PATH with each of the elements of
1967322289dSmrg# PROGS_LIST.
1977322289dSmrg#
1987322289dSmrg# CHECK_FUNC should accept the path to a candidate program, and
1997322289dSmrg# set $func_check_prog_result if it truncates its output less than
2007322289dSmrg# $_G_path_prog_max characters.
2017322289dSmrgfunc_path_progs ()
2027322289dSmrg{
2037322289dSmrg    _G_progs_list=$1
2047322289dSmrg    _G_check_func=$2
2057322289dSmrg    _G_PATH=${3-"$PATH"}
2067322289dSmrg
2077322289dSmrg    _G_path_prog_max=0
2087322289dSmrg    _G_path_prog_found=false
2097322289dSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
2107322289dSmrg    for _G_dir in $_G_PATH; do
2117322289dSmrg      IFS=$_G_save_IFS
2127322289dSmrg      test -z "$_G_dir" && _G_dir=.
2137322289dSmrg      for _G_prog_name in $_G_progs_list; do
2147322289dSmrg        for _exeext in '' .EXE; do
2157322289dSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2167322289dSmrg          func_executable_p "$_G_path_prog" || continue
2177322289dSmrg          case `"$_G_path_prog" --version 2>&1` in
2187322289dSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2197322289dSmrg            *)     $_G_check_func $_G_path_prog
2207322289dSmrg		   func_path_progs_result=$func_check_prog_result
2217322289dSmrg		   ;;
2227322289dSmrg          esac
2237322289dSmrg          $_G_path_prog_found && break 3
2247322289dSmrg        done
2257322289dSmrg      done
2267322289dSmrg    done
2277322289dSmrg    IFS=$_G_save_IFS
2287322289dSmrg    test -z "$func_path_progs_result" && {
2297322289dSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2307322289dSmrg      exit 1
2317322289dSmrg    }
2327322289dSmrg}
2337322289dSmrg
2347322289dSmrg
2357322289dSmrg# We want to be able to use the functions in this file before configure
2367322289dSmrg# has figured out where the best binaries are kept, which means we have
2377322289dSmrg# to search for them ourselves - except when the results are already set
2387322289dSmrg# where we skip the searches.
2397322289dSmrg
2407322289dSmrg# Unless the user overrides by setting SED, search the path for either GNU
2417322289dSmrg# sed, or the sed that truncates its output the least.
2427322289dSmrgtest -z "$SED" && {
2437322289dSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2447322289dSmrg  for _G_i in 1 2 3 4 5 6 7; do
2457322289dSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2467322289dSmrg  done
2477322289dSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2487322289dSmrg  _G_sed_script=
2497322289dSmrg
2507322289dSmrg  func_check_prog_sed ()
2517322289dSmrg  {
2527322289dSmrg    _G_path_prog=$1
2537322289dSmrg
2547322289dSmrg    _G_count=0
2557322289dSmrg    printf 0123456789 >conftest.in
2567322289dSmrg    while :
2577322289dSmrg    do
2587322289dSmrg      cat conftest.in conftest.in >conftest.tmp
2597322289dSmrg      mv conftest.tmp conftest.in
2607322289dSmrg      cp conftest.in conftest.nl
2617322289dSmrg      echo '' >> conftest.nl
2627322289dSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2637322289dSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2647322289dSmrg      _G_count=`expr $_G_count + 1`
2657322289dSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2667322289dSmrg        # Best one so far, save it but keep looking for a better one
2677322289dSmrg        func_check_prog_result=$_G_path_prog
2687322289dSmrg        _G_path_prog_max=$_G_count
2697322289dSmrg      fi
2707322289dSmrg      # 10*(2^10) chars as input seems more than enough
2717322289dSmrg      test 10 -lt "$_G_count" && break
2727322289dSmrg    done
2737322289dSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2747322289dSmrg  }
2757322289dSmrg
27622663e35Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
2777322289dSmrg  rm -f conftest.sed
2787322289dSmrg  SED=$func_path_progs_result
2797322289dSmrg}
2807322289dSmrg
2817322289dSmrg
2827322289dSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2837322289dSmrg# grep, or the grep that truncates its output the least.
2847322289dSmrgtest -z "$GREP" && {
2857322289dSmrg  func_check_prog_grep ()
2867322289dSmrg  {
2877322289dSmrg    _G_path_prog=$1
2887322289dSmrg
2897322289dSmrg    _G_count=0
2907322289dSmrg    _G_path_prog_max=0
2917322289dSmrg    printf 0123456789 >conftest.in
2927322289dSmrg    while :
2937322289dSmrg    do
2947322289dSmrg      cat conftest.in conftest.in >conftest.tmp
2957322289dSmrg      mv conftest.tmp conftest.in
2967322289dSmrg      cp conftest.in conftest.nl
2977322289dSmrg      echo 'GREP' >> conftest.nl
2987322289dSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2997322289dSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
3007322289dSmrg      _G_count=`expr $_G_count + 1`
3017322289dSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
3027322289dSmrg        # Best one so far, save it but keep looking for a better one
3037322289dSmrg        func_check_prog_result=$_G_path_prog
3047322289dSmrg        _G_path_prog_max=$_G_count
3057322289dSmrg      fi
3067322289dSmrg      # 10*(2^10) chars as input seems more than enough
3077322289dSmrg      test 10 -lt "$_G_count" && break
3087322289dSmrg    done
3097322289dSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
3107322289dSmrg  }
3117322289dSmrg
31222663e35Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
3137322289dSmrg  GREP=$func_path_progs_result
3147322289dSmrg}
3157322289dSmrg
3167322289dSmrg
3177322289dSmrg## ------------------------------- ##
3187322289dSmrg## User overridable command paths. ##
3197322289dSmrg## ------------------------------- ##
3207322289dSmrg
3217322289dSmrg# All uppercase variable names are used for environment variables.  These
3227322289dSmrg# variables can be overridden by the user before calling a script that
3237322289dSmrg# uses them if a suitable command of that name is not already available
3247322289dSmrg# in the command search PATH.
325d769e936Smrg
326d769e936Smrg: ${CP="cp -f"}
3277322289dSmrg: ${ECHO="printf %s\n"}
3287322289dSmrg: ${EGREP="$GREP -E"}
3297322289dSmrg: ${FGREP="$GREP -F"}
3307322289dSmrg: ${LN_S="ln -s"}
331d769e936Smrg: ${MAKE="make"}
332d769e936Smrg: ${MKDIR="mkdir"}
333d769e936Smrg: ${MV="mv -f"}
334d769e936Smrg: ${RM="rm -f"}
335d769e936Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3361d54945dSmrg
337786a6f21Smrg
3387322289dSmrg## -------------------- ##
3397322289dSmrg## Useful sed snippets. ##
3407322289dSmrg## -------------------- ##
341d769e936Smrg
3427322289dSmrgsed_dirname='s|/[^/]*$||'
3437322289dSmrgsed_basename='s|^.*/||'
344d769e936Smrg
3457322289dSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3467322289dSmrg# metacharacters that are still active within double-quoted strings.
3477322289dSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348d769e936Smrg
3497322289dSmrg# Same as above, but do not quote variable references.
3507322289dSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351d769e936Smrg
3527322289dSmrg# Sed substitution that turns a string into a regex matching for the
3537322289dSmrg# string literally.
3547322289dSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355d769e936Smrg
3567322289dSmrg# Sed substitution that converts a w32 file name or path
3577322289dSmrg# that contains forward slashes, into one that contains
3587322289dSmrg# (escaped) backslashes.  A very naive implementation.
3597322289dSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3607322289dSmrg
3617322289dSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3627322289dSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3637322289dSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3647322289dSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3657322289dSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3667322289dSmrg_G_bs='\\'
3677322289dSmrg_G_bs2='\\\\'
3687322289dSmrg_G_bs4='\\\\\\\\'
3697322289dSmrg_G_dollar='\$'
3707322289dSmrgsed_double_backslash="\
3717322289dSmrg  s/$_G_bs4/&\\
3727322289dSmrg/g
3737322289dSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3747322289dSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3757322289dSmrg  s/\n//g"
376d769e936Smrg
37722663e35Smrg# require_check_ifs_backslash
37822663e35Smrg# ---------------------------
37922663e35Smrg# Check if we can use backslash as IFS='\' separator, and set
38022663e35Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
38122663e35Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
38222663e35Smrgfunc_require_check_ifs_backslash ()
38322663e35Smrg{
38422663e35Smrg  _G_save_IFS=$IFS
38522663e35Smrg  IFS='\'
38622663e35Smrg  _G_check_ifs_backshlash='a\\b'
38722663e35Smrg  for _G_i in $_G_check_ifs_backshlash
38822663e35Smrg  do
38922663e35Smrg  case $_G_i in
39022663e35Smrg  a)
39122663e35Smrg    check_ifs_backshlash_broken=false
39222663e35Smrg    ;;
39322663e35Smrg  '')
39422663e35Smrg    break
39522663e35Smrg    ;;
39622663e35Smrg  *)
39722663e35Smrg    check_ifs_backshlash_broken=:
39822663e35Smrg    break
39922663e35Smrg    ;;
40022663e35Smrg  esac
40122663e35Smrg  done
40222663e35Smrg  IFS=$_G_save_IFS
40322663e35Smrg  require_check_ifs_backslash=:
40422663e35Smrg}
40522663e35Smrg
406d769e936Smrg
4077322289dSmrg## ----------------- ##
4087322289dSmrg## Global variables. ##
4097322289dSmrg## ----------------- ##
410d769e936Smrg
4117322289dSmrg# Except for the global variables explicitly listed below, the following
4127322289dSmrg# functions in the '^func_' namespace, and the '^require_' namespace
4137322289dSmrg# variables initialised in the 'Resource management' section, sourcing
4147322289dSmrg# this file will not pollute your global namespace with anything
4157322289dSmrg# else. There's no portable way to scope variables in Bourne shell
4167322289dSmrg# though, so actually running these functions will sometimes place
4177322289dSmrg# results into a variable named after the function, and often use
4187322289dSmrg# temporary variables in the '^_G_' namespace. If you are careful to
4197322289dSmrg# avoid using those namespaces casually in your sourcing script, things
4207322289dSmrg# should continue to work as you expect. And, of course, you can freely
4217322289dSmrg# overwrite any of the functions or variables defined here before
4227322289dSmrg# calling anything to customize them.
423d769e936Smrg
4247322289dSmrgEXIT_SUCCESS=0
4257322289dSmrgEXIT_FAILURE=1
4267322289dSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
4277322289dSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428d769e936Smrg
4297322289dSmrg# Allow overriding, eg assuming that you follow the convention of
4307322289dSmrg# putting '$debug_cmd' at the start of all your functions, you can get
4317322289dSmrg# bash to show function call trace with:
4327322289dSmrg#
4337322289dSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
4347322289dSmrgdebug_cmd=${debug_cmd-":"}
4357322289dSmrgexit_cmd=:
436d769e936Smrg
4377322289dSmrg# By convention, finish your script with:
4387322289dSmrg#
4397322289dSmrg#    exit $exit_status
4407322289dSmrg#
4417322289dSmrg# so that you can set exit_status to non-zero if you want to indicate
4427322289dSmrg# something went wrong during execution without actually bailing out at
4437322289dSmrg# the point of failure.
4447322289dSmrgexit_status=$EXIT_SUCCESS
445d769e936Smrg
4467322289dSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4477322289dSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4487322289dSmrg# the _XPG environment variable is not equal to 1 (one), the special
4497322289dSmrg# positional parameter $0, within a function call, is the name of the
4507322289dSmrg# function.
4517322289dSmrgprogpath=$0
452d769e936Smrg
4537322289dSmrg# The name of this program.
4547322289dSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455d769e936Smrg
4567322289dSmrg# Make sure we have an absolute progpath for reexecution:
457d769e936Smrgcase $progpath in
458d769e936Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459d769e936Smrg  *[\\/]*)
4607322289dSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461d769e936Smrg     progdir=`cd "$progdir" && pwd`
4627322289dSmrg     progpath=$progdir/$progname
463d769e936Smrg     ;;
464d769e936Smrg  *)
4657322289dSmrg     _G_IFS=$IFS
466d769e936Smrg     IFS=${PATH_SEPARATOR-:}
467d769e936Smrg     for progdir in $PATH; do
4687322289dSmrg       IFS=$_G_IFS
469d769e936Smrg       test -x "$progdir/$progname" && break
470d769e936Smrg     done
4717322289dSmrg     IFS=$_G_IFS
472d769e936Smrg     test -n "$progdir" || progdir=`pwd`
4737322289dSmrg     progpath=$progdir/$progname
474d769e936Smrg     ;;
475d769e936Smrgesac
476d769e936Smrg
477d769e936Smrg
4787322289dSmrg## ----------------- ##
4797322289dSmrg## Standard options. ##
4807322289dSmrg## ----------------- ##
481d769e936Smrg
4827322289dSmrg# The following options affect the operation of the functions defined
4837322289dSmrg# below, and should be set appropriately depending on run-time para-
4847322289dSmrg# meters passed on the command line.
485d769e936Smrg
486d769e936Smrgopt_dry_run=false
487d769e936Smrgopt_quiet=false
488d769e936Smrgopt_verbose=false
489d769e936Smrg
4907322289dSmrg# Categories 'all' and 'none' are always available.  Append any others
4917322289dSmrg# you will pass as the first argument to func_warning from your own
4927322289dSmrg# code.
4937322289dSmrgwarning_categories=
494d769e936Smrg
4957322289dSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4967322289dSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4977322289dSmrg# treat the next displayed warning as a fatal error.
4987322289dSmrgwarning_func=func_warn_and_continue
499d769e936Smrg
5007322289dSmrg# Set to 'all' to display all warnings, 'none' to suppress all
5017322289dSmrg# warnings, or a space delimited list of some subset of
5027322289dSmrg# 'warning_categories' to display only the listed warnings.
5037322289dSmrgopt_warning_types=all
504d769e936Smrg
505d769e936Smrg
5067322289dSmrg## -------------------- ##
5077322289dSmrg## Resource management. ##
5087322289dSmrg## -------------------- ##
509d769e936Smrg
5107322289dSmrg# This section contains definitions for functions that each ensure a
5117322289dSmrg# particular resource (a file, or a non-empty configuration variable for
5127322289dSmrg# example) is available, and if appropriate to extract default values
5137322289dSmrg# from pertinent package files. Call them using their associated
5147322289dSmrg# 'require_*' variable to ensure that they are executed, at most, once.
5157322289dSmrg#
5167322289dSmrg# It's entirely deliberate that calling these functions can set
5177322289dSmrg# variables that don't obey the namespace limitations obeyed by the rest
5187322289dSmrg# of this file, in order that that they be as useful as possible to
5197322289dSmrg# callers.
520d769e936Smrg
521d769e936Smrg
5227322289dSmrg# require_term_colors
5237322289dSmrg# -------------------
5247322289dSmrg# Allow display of bold text on terminals that support it.
5257322289dSmrgrequire_term_colors=func_require_term_colors
5267322289dSmrgfunc_require_term_colors ()
527d769e936Smrg{
5287322289dSmrg    $debug_cmd
5297322289dSmrg
5307322289dSmrg    test -t 1 && {
5317322289dSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
5327322289dSmrg      # precedence, because most terminfo databases neglect to describe
5337322289dSmrg      # whether color sequences are supported.
5347322289dSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
5357322289dSmrg
5367322289dSmrg      if test 1 = "$USE_ANSI_COLORS"; then
5377322289dSmrg        # Standard ANSI escape sequences
5387322289dSmrg        tc_reset='[0m'
5397322289dSmrg        tc_bold='[1m';   tc_standout='[7m'
5407322289dSmrg        tc_red='[31m';   tc_green='[32m'
5417322289dSmrg        tc_blue='[34m';  tc_cyan='[36m'
5427322289dSmrg      else
5437322289dSmrg        # Otherwise trust the terminfo database after all.
5447322289dSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5457322289dSmrg          tc_reset=`tput sgr0`
5467322289dSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5477322289dSmrg          tc_standout=$tc_bold
5487322289dSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5497322289dSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5507322289dSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5517322289dSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5527322289dSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5537322289dSmrg        }
5547322289dSmrg      fi
5557322289dSmrg    }
556d769e936Smrg
5577322289dSmrg    require_term_colors=:
558d769e936Smrg}
559d769e936Smrg
560d769e936Smrg
5617322289dSmrg## ----------------- ##
5627322289dSmrg## Function library. ##
5637322289dSmrg## ----------------- ##
5647322289dSmrg
5657322289dSmrg# This section contains a variety of useful functions to call in your
5667322289dSmrg# scripts. Take note of the portable wrappers for features provided by
5677322289dSmrg# some modern shells, which will fall back to slower equivalents on
5687322289dSmrg# less featureful shells.
5697322289dSmrg
5707322289dSmrg
5717322289dSmrg# func_append VAR VALUE
5727322289dSmrg# ---------------------
5737322289dSmrg# Append VALUE onto the existing contents of VAR.
5747322289dSmrg
5757322289dSmrg  # We should try to minimise forks, especially on Windows where they are
5767322289dSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5777322289dSmrg  # being used:
5787322289dSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5797322289dSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5807322289dSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5817322289dSmrg    # The += operator was introduced in bash 3.1
5827322289dSmrg    case $BASH_VERSION in
5837322289dSmrg      [12].* | 3.0 | 3.0*) ;;
5847322289dSmrg      *)
5857322289dSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5867322289dSmrg        ;;
5877322289dSmrg    esac
5887322289dSmrg  fi
5897322289dSmrg
5907322289dSmrg  # _G_HAVE_PLUSEQ_OP
5917322289dSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5927322289dSmrg  # useable or anything else if it does not work.
5937322289dSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5947322289dSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5957322289dSmrg    && _G_HAVE_PLUSEQ_OP=yes
5967322289dSmrg
5977322289dSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5987322289dSmrgthen
5997322289dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
6007322289dSmrg  eval 'func_append ()
6017322289dSmrg  {
6027322289dSmrg    $debug_cmd
6037322289dSmrg
6047322289dSmrg    eval "$1+=\$2"
6057322289dSmrg  }'
6067322289dSmrgelse
6077322289dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
6087322289dSmrg  func_append ()
6097322289dSmrg  {
6107322289dSmrg    $debug_cmd
6117322289dSmrg
6127322289dSmrg    eval "$1=\$$1\$2"
6137322289dSmrg  }
6147322289dSmrgfi
6157322289dSmrg
6167322289dSmrg
6177322289dSmrg# func_append_quoted VAR VALUE
6187322289dSmrg# ----------------------------
6197322289dSmrg# Quote VALUE and append to the end of shell variable VAR, separated
6207322289dSmrg# by a space.
6217322289dSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
6227322289dSmrg  eval 'func_append_quoted ()
6237322289dSmrg  {
6247322289dSmrg    $debug_cmd
6257322289dSmrg
62622663e35Smrg    func_quote_arg pretty "$2"
62722663e35Smrg    eval "$1+=\\ \$func_quote_arg_result"
6287322289dSmrg  }'
6297322289dSmrgelse
6307322289dSmrg  func_append_quoted ()
6317322289dSmrg  {
6327322289dSmrg    $debug_cmd
6337322289dSmrg
63422663e35Smrg    func_quote_arg pretty "$2"
63522663e35Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
6367322289dSmrg  }
6377322289dSmrgfi
6387322289dSmrg
6397322289dSmrg
6407322289dSmrg# func_append_uniq VAR VALUE
6417322289dSmrg# --------------------------
6427322289dSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6437322289dSmrg# entries are delimited by the first character of VALUE.  For example:
6447322289dSmrg#
6457322289dSmrg#   func_append_uniq options " --another-option option-argument"
6467322289dSmrg#
6477322289dSmrg# will only append to $options if " --another-option option-argument "
6487322289dSmrg# is not already present somewhere in $options already (note spaces at
6497322289dSmrg# each end implied by leading space in second argument).
6507322289dSmrgfunc_append_uniq ()
6517322289dSmrg{
6527322289dSmrg    $debug_cmd
6537322289dSmrg
6547322289dSmrg    eval _G_current_value='`$ECHO $'$1'`'
6557322289dSmrg    _G_delim=`expr "$2" : '\(.\)'`
6567322289dSmrg
6577322289dSmrg    case $_G_delim$_G_current_value$_G_delim in
6587322289dSmrg      *"$2$_G_delim"*) ;;
6597322289dSmrg      *) func_append "$@" ;;
6607322289dSmrg    esac
6617322289dSmrg}
6627322289dSmrg
6637322289dSmrg
6647322289dSmrg# func_arith TERM...
6657322289dSmrg# ------------------
6667322289dSmrg# Set func_arith_result to the result of evaluating TERMs.
6677322289dSmrg  test -z "$_G_HAVE_ARITH_OP" \
6687322289dSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6697322289dSmrg    && _G_HAVE_ARITH_OP=yes
6707322289dSmrg
6717322289dSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6727322289dSmrg  eval 'func_arith ()
6737322289dSmrg  {
6747322289dSmrg    $debug_cmd
6757322289dSmrg
6767322289dSmrg    func_arith_result=$(( $* ))
6777322289dSmrg  }'
6787322289dSmrgelse
6797322289dSmrg  func_arith ()
6807322289dSmrg  {
6817322289dSmrg    $debug_cmd
6827322289dSmrg
6837322289dSmrg    func_arith_result=`expr "$@"`
6847322289dSmrg  }
6857322289dSmrgfi
6867322289dSmrg
6877322289dSmrg
6887322289dSmrg# func_basename FILE
6897322289dSmrg# ------------------
6907322289dSmrg# Set func_basename_result to FILE with everything up to and including
6917322289dSmrg# the last / stripped.
6927322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6937322289dSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6947322289dSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6957322289dSmrg  # on unsupported syntax...
6967322289dSmrg  _b='func_basename_result=${1##*/}'
6977322289dSmrg  _d='case $1 in
6987322289dSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6997322289dSmrg        *  ) func_dirname_result=$3        ;;
7007322289dSmrg      esac'
7017322289dSmrg
7027322289dSmrgelse
7037322289dSmrg  # ...otherwise fall back to using sed.
7047322289dSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
7057322289dSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
7067322289dSmrg      if test "X$func_dirname_result" = "X$1"; then
7077322289dSmrg        func_dirname_result=$3
7087322289dSmrg      else
7097322289dSmrg        func_append func_dirname_result "$2"
7107322289dSmrg      fi'
7117322289dSmrgfi
7127322289dSmrg
7137322289dSmrgeval 'func_basename ()
7147322289dSmrg{
7157322289dSmrg    $debug_cmd
7167322289dSmrg
7177322289dSmrg    '"$_b"'
7187322289dSmrg}'
7197322289dSmrg
7207322289dSmrg
7217322289dSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
7227322289dSmrg# -------------------------------------------
7237322289dSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
7247322289dSmrg# otherwise set result to NONDIR_REPLACEMENT.
7257322289dSmrgeval 'func_dirname ()
7267322289dSmrg{
7277322289dSmrg    $debug_cmd
7287322289dSmrg
7297322289dSmrg    '"$_d"'
7307322289dSmrg}'
7317322289dSmrg
7327322289dSmrg
7337322289dSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
7347322289dSmrg# --------------------------------------------------------
7357322289dSmrg# Perform func_basename and func_dirname in a single function
7367322289dSmrg# call:
7377322289dSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
7387322289dSmrg#             add APPEND to the result, otherwise set result
7397322289dSmrg#             to NONDIR_REPLACEMENT.
7407322289dSmrg#             value returned in "$func_dirname_result"
7417322289dSmrg#   basename: Compute filename of FILE.
7427322289dSmrg#             value retuned in "$func_basename_result"
7437322289dSmrg# For efficiency, we do not delegate to the functions above but instead
7447322289dSmrg# duplicate the functionality here.
7457322289dSmrgeval 'func_dirname_and_basename ()
7467322289dSmrg{
7477322289dSmrg    $debug_cmd
7487322289dSmrg
7497322289dSmrg    '"$_b"'
7507322289dSmrg    '"$_d"'
7517322289dSmrg}'
7527322289dSmrg
7537322289dSmrg
7547322289dSmrg# func_echo ARG...
7557322289dSmrg# ----------------
7567322289dSmrg# Echo program name prefixed message.
7577322289dSmrgfunc_echo ()
7587322289dSmrg{
7597322289dSmrg    $debug_cmd
7607322289dSmrg
7617322289dSmrg    _G_message=$*
7627322289dSmrg
7637322289dSmrg    func_echo_IFS=$IFS
7647322289dSmrg    IFS=$nl
7657322289dSmrg    for _G_line in $_G_message; do
7667322289dSmrg      IFS=$func_echo_IFS
7677322289dSmrg      $ECHO "$progname: $_G_line"
7687322289dSmrg    done
7697322289dSmrg    IFS=$func_echo_IFS
7707322289dSmrg}
7717322289dSmrg
7727322289dSmrg
7737322289dSmrg# func_echo_all ARG...
7747322289dSmrg# --------------------
7757322289dSmrg# Invoke $ECHO with all args, space-separated.
7767322289dSmrgfunc_echo_all ()
7777322289dSmrg{
7787322289dSmrg    $ECHO "$*"
7797322289dSmrg}
7807322289dSmrg
7817322289dSmrg
7827322289dSmrg# func_echo_infix_1 INFIX ARG...
7837322289dSmrg# ------------------------------
7847322289dSmrg# Echo program name, followed by INFIX on the first line, with any
7857322289dSmrg# additional lines not showing INFIX.
7867322289dSmrgfunc_echo_infix_1 ()
7877322289dSmrg{
7887322289dSmrg    $debug_cmd
7897322289dSmrg
7907322289dSmrg    $require_term_colors
7917322289dSmrg
7927322289dSmrg    _G_infix=$1; shift
7937322289dSmrg    _G_indent=$_G_infix
7947322289dSmrg    _G_prefix="$progname: $_G_infix: "
7957322289dSmrg    _G_message=$*
7967322289dSmrg
7977322289dSmrg    # Strip color escape sequences before counting printable length
7987322289dSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7997322289dSmrg    do
8007322289dSmrg      test -n "$_G_tc" && {
8017322289dSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
8027322289dSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
8037322289dSmrg      }
8047322289dSmrg    done
8057322289dSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
8067322289dSmrg
8077322289dSmrg    func_echo_infix_1_IFS=$IFS
8087322289dSmrg    IFS=$nl
8097322289dSmrg    for _G_line in $_G_message; do
8107322289dSmrg      IFS=$func_echo_infix_1_IFS
8117322289dSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
8127322289dSmrg      _G_prefix=$_G_indent
8137322289dSmrg    done
8147322289dSmrg    IFS=$func_echo_infix_1_IFS
8157322289dSmrg}
8167322289dSmrg
8177322289dSmrg
8187322289dSmrg# func_error ARG...
8197322289dSmrg# -----------------
8207322289dSmrg# Echo program name prefixed message to standard error.
8217322289dSmrgfunc_error ()
8227322289dSmrg{
8237322289dSmrg    $debug_cmd
8247322289dSmrg
8257322289dSmrg    $require_term_colors
8267322289dSmrg
8277322289dSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
8287322289dSmrg}
8297322289dSmrg
8307322289dSmrg
8317322289dSmrg# func_fatal_error ARG...
8327322289dSmrg# -----------------------
8337322289dSmrg# Echo program name prefixed message to standard error, and exit.
8347322289dSmrgfunc_fatal_error ()
8357322289dSmrg{
8367322289dSmrg    $debug_cmd
8377322289dSmrg
8387322289dSmrg    func_error "$*"
8397322289dSmrg    exit $EXIT_FAILURE
8407322289dSmrg}
8417322289dSmrg
8427322289dSmrg
8437322289dSmrg# func_grep EXPRESSION FILENAME
8447322289dSmrg# -----------------------------
845d769e936Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846d769e936Smrgfunc_grep ()
847d769e936Smrg{
8487322289dSmrg    $debug_cmd
8497322289dSmrg
850d769e936Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851d769e936Smrg}
852d769e936Smrg
853d769e936Smrg
8547322289dSmrg# func_len STRING
8557322289dSmrg# ---------------
8567322289dSmrg# Set func_len_result to the length of STRING. STRING may not
8577322289dSmrg# start with a hyphen.
8587322289dSmrg  test -z "$_G_HAVE_XSI_OPS" \
8597322289dSmrg    && (eval 'x=a/b/c;
8607322289dSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8617322289dSmrg    && _G_HAVE_XSI_OPS=yes
8627322289dSmrg
8637322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8647322289dSmrg  eval 'func_len ()
8657322289dSmrg  {
8667322289dSmrg    $debug_cmd
8677322289dSmrg
8687322289dSmrg    func_len_result=${#1}
8697322289dSmrg  }'
8707322289dSmrgelse
8717322289dSmrg  func_len ()
8727322289dSmrg  {
8737322289dSmrg    $debug_cmd
8747322289dSmrg
8757322289dSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8767322289dSmrg  }
8777322289dSmrgfi
8787322289dSmrg
8797322289dSmrg
8807322289dSmrg# func_mkdir_p DIRECTORY-PATH
8817322289dSmrg# ---------------------------
882d769e936Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883d769e936Smrgfunc_mkdir_p ()
884d769e936Smrg{
8857322289dSmrg    $debug_cmd
886d769e936Smrg
8877322289dSmrg    _G_directory_path=$1
8887322289dSmrg    _G_dir_list=
889d769e936Smrg
8907322289dSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8917322289dSmrg
8927322289dSmrg      # Protect directory names starting with '-'
8937322289dSmrg      case $_G_directory_path in
8947322289dSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895d769e936Smrg      esac
896d769e936Smrg
897d769e936Smrg      # While some portion of DIR does not yet exist...
8987322289dSmrg      while test ! -d "$_G_directory_path"; do
899d769e936Smrg        # ...make a list in topmost first order.  Use a colon delimited
900d769e936Smrg	# list incase some portion of path contains whitespace.
9017322289dSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902d769e936Smrg
903d769e936Smrg        # If the last portion added has no slash in it, the list is done
9047322289dSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905d769e936Smrg
906d769e936Smrg        # ...otherwise throw away the child directory and loop
9077322289dSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908d769e936Smrg      done
9097322289dSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910d769e936Smrg
9117322289dSmrg      func_mkdir_p_IFS=$IFS; IFS=:
9127322289dSmrg      for _G_dir in $_G_dir_list; do
9137322289dSmrg	IFS=$func_mkdir_p_IFS
9147322289dSmrg        # mkdir can fail with a 'File exist' error if two processes
915d769e936Smrg        # try to create one of the directories concurrently.  Don't
916d769e936Smrg        # stop in that case!
9177322289dSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918d769e936Smrg      done
9197322289dSmrg      IFS=$func_mkdir_p_IFS
920d769e936Smrg
921d769e936Smrg      # Bail out if we (or some other process) failed to create a directory.
9227322289dSmrg      test -d "$_G_directory_path" || \
9237322289dSmrg        func_fatal_error "Failed to create '$1'"
924d769e936Smrg    fi
925d769e936Smrg}
9261d54945dSmrg
9271d54945dSmrg
9287322289dSmrg# func_mktempdir [BASENAME]
9297322289dSmrg# -------------------------
9301d54945dSmrg# Make a temporary directory that won't clash with other running
9311d54945dSmrg# libtool processes, and avoids race conditions if possible.  If
9327322289dSmrg# given, BASENAME is the basename for that directory.
9331d54945dSmrgfunc_mktempdir ()
9341d54945dSmrg{
9357322289dSmrg    $debug_cmd
9367322289dSmrg
9377322289dSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
9381d54945dSmrg
9397322289dSmrg    if test : = "$opt_dry_run"; then
9401d54945dSmrg      # Return a directory name, but don't create it in dry-run mode
9417322289dSmrg      _G_tmpdir=$_G_template-$$
9421d54945dSmrg    else
9431d54945dSmrg
9441d54945dSmrg      # If mktemp works, use that first and foremost
9457322289dSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9461d54945dSmrg
9477322289dSmrg      if test ! -d "$_G_tmpdir"; then
948d769e936Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9497322289dSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9501d54945dSmrg
9517322289dSmrg        func_mktempdir_umask=`umask`
952d769e936Smrg        umask 0077
9537322289dSmrg        $MKDIR "$_G_tmpdir"
9547322289dSmrg        umask $func_mktempdir_umask
9551d54945dSmrg      fi
9561d54945dSmrg
9571d54945dSmrg      # If we're not in dry-run mode, bomb out on failure
9587322289dSmrg      test -d "$_G_tmpdir" || \
9597322289dSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9607322289dSmrg    fi
9617322289dSmrg
9627322289dSmrg    $ECHO "$_G_tmpdir"
9637322289dSmrg}
9647322289dSmrg
9657322289dSmrg
9667322289dSmrg# func_normal_abspath PATH
9677322289dSmrg# ------------------------
9687322289dSmrg# Remove doubled-up and trailing slashes, "." path components,
9697322289dSmrg# and cancel out any ".." path components in PATH after making
9707322289dSmrg# it an absolute path.
9717322289dSmrgfunc_normal_abspath ()
9727322289dSmrg{
9737322289dSmrg    $debug_cmd
9747322289dSmrg
9757322289dSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9767322289dSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9777322289dSmrg    _G_pathcdr='s|^/[^/]*||'
9787322289dSmrg    _G_removedotparts=':dotsl
9797322289dSmrg		s|/\./|/|g
9807322289dSmrg		t dotsl
9817322289dSmrg		s|/\.$|/|'
9827322289dSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9837322289dSmrg    _G_finalslash='s|/*$|/|'
9847322289dSmrg
9857322289dSmrg    # Start from root dir and reassemble the path.
9867322289dSmrg    func_normal_abspath_result=
9877322289dSmrg    func_normal_abspath_tpath=$1
9887322289dSmrg    func_normal_abspath_altnamespace=
9897322289dSmrg    case $func_normal_abspath_tpath in
9907322289dSmrg      "")
9917322289dSmrg        # Empty path, that just means $cwd.
9927322289dSmrg        func_stripname '' '/' "`pwd`"
9937322289dSmrg        func_normal_abspath_result=$func_stripname_result
9947322289dSmrg        return
9957322289dSmrg        ;;
9967322289dSmrg      # The next three entries are used to spot a run of precisely
9977322289dSmrg      # two leading slashes without using negated character classes;
9987322289dSmrg      # we take advantage of case's first-match behaviour.
9997322289dSmrg      ///*)
10007322289dSmrg        # Unusual form of absolute path, do nothing.
10017322289dSmrg        ;;
10027322289dSmrg      //*)
10037322289dSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
10047322289dSmrg        # and for example Cygwin uses it to access remote file shares
10057322289dSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
10067322289dSmrg        func_normal_abspath_altnamespace=/
10077322289dSmrg        ;;
10087322289dSmrg      /*)
10097322289dSmrg        # Absolute path, do nothing.
10107322289dSmrg        ;;
10117322289dSmrg      *)
10127322289dSmrg        # Relative path, prepend $cwd.
10137322289dSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
10147322289dSmrg        ;;
10157322289dSmrg    esac
10167322289dSmrg
10177322289dSmrg    # Cancel out all the simple stuff to save iterations.  We also want
10187322289dSmrg    # the path to end with a slash for ease of parsing, so make sure
10197322289dSmrg    # there is one (and only one) here.
10207322289dSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10217322289dSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
10227322289dSmrg    while :; do
10237322289dSmrg      # Processed it all yet?
10247322289dSmrg      if test / = "$func_normal_abspath_tpath"; then
10257322289dSmrg        # If we ascended to the root using ".." the result may be empty now.
10267322289dSmrg        if test -z "$func_normal_abspath_result"; then
10277322289dSmrg          func_normal_abspath_result=/
10287322289dSmrg        fi
10297322289dSmrg        break
10307322289dSmrg      fi
10317322289dSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
10327322289dSmrg          -e "$_G_pathcar"`
10337322289dSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10347322289dSmrg          -e "$_G_pathcdr"`
10357322289dSmrg      # Figure out what to do with it
10367322289dSmrg      case $func_normal_abspath_tcomponent in
10377322289dSmrg        "")
10387322289dSmrg          # Trailing empty path component, ignore it.
10397322289dSmrg          ;;
10407322289dSmrg        ..)
10417322289dSmrg          # Parent dir; strip last assembled component from result.
10427322289dSmrg          func_dirname "$func_normal_abspath_result"
10437322289dSmrg          func_normal_abspath_result=$func_dirname_result
10447322289dSmrg          ;;
10457322289dSmrg        *)
10467322289dSmrg          # Actual path component, append it.
10477322289dSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10487322289dSmrg          ;;
10497322289dSmrg      esac
10507322289dSmrg    done
10517322289dSmrg    # Restore leading double-slash if one was found on entry.
10527322289dSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10537322289dSmrg}
10547322289dSmrg
10557322289dSmrg
10567322289dSmrg# func_notquiet ARG...
10577322289dSmrg# --------------------
10587322289dSmrg# Echo program name prefixed message only when not in quiet mode.
10597322289dSmrgfunc_notquiet ()
10607322289dSmrg{
10617322289dSmrg    $debug_cmd
10627322289dSmrg
10637322289dSmrg    $opt_quiet || func_echo ${1+"$@"}
10647322289dSmrg
10657322289dSmrg    # A bug in bash halts the script if the last line of a function
10667322289dSmrg    # fails when set -e is in force, so we need another command to
10677322289dSmrg    # work around that:
10687322289dSmrg    :
10697322289dSmrg}
10707322289dSmrg
10717322289dSmrg
10727322289dSmrg# func_relative_path SRCDIR DSTDIR
10737322289dSmrg# --------------------------------
10747322289dSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10757322289dSmrgfunc_relative_path ()
10767322289dSmrg{
10777322289dSmrg    $debug_cmd
10787322289dSmrg
10797322289dSmrg    func_relative_path_result=
10807322289dSmrg    func_normal_abspath "$1"
10817322289dSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10827322289dSmrg    func_normal_abspath "$2"
10837322289dSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10847322289dSmrg
10857322289dSmrg    # Ascend the tree starting from libdir
10867322289dSmrg    while :; do
10877322289dSmrg      # check if we have found a prefix of bindir
10887322289dSmrg      case $func_relative_path_tbindir in
10897322289dSmrg        $func_relative_path_tlibdir)
10907322289dSmrg          # found an exact match
10917322289dSmrg          func_relative_path_tcancelled=
10927322289dSmrg          break
10937322289dSmrg          ;;
10947322289dSmrg        $func_relative_path_tlibdir*)
10957322289dSmrg          # found a matching prefix
10967322289dSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10977322289dSmrg          func_relative_path_tcancelled=$func_stripname_result
10987322289dSmrg          if test -z "$func_relative_path_result"; then
10997322289dSmrg            func_relative_path_result=.
11007322289dSmrg          fi
11017322289dSmrg          break
11027322289dSmrg          ;;
11037322289dSmrg        *)
11047322289dSmrg          func_dirname $func_relative_path_tlibdir
11057322289dSmrg          func_relative_path_tlibdir=$func_dirname_result
11067322289dSmrg          if test -z "$func_relative_path_tlibdir"; then
11077322289dSmrg            # Have to descend all the way to the root!
11087322289dSmrg            func_relative_path_result=../$func_relative_path_result
11097322289dSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
11107322289dSmrg            break
11117322289dSmrg          fi
11127322289dSmrg          func_relative_path_result=../$func_relative_path_result
11137322289dSmrg          ;;
11147322289dSmrg      esac
11157322289dSmrg    done
11167322289dSmrg
11177322289dSmrg    # Now calculate path; take care to avoid doubling-up slashes.
11187322289dSmrg    func_stripname '' '/' "$func_relative_path_result"
11197322289dSmrg    func_relative_path_result=$func_stripname_result
11207322289dSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
11217322289dSmrg    if test -n "$func_stripname_result"; then
11227322289dSmrg      func_append func_relative_path_result "/$func_stripname_result"
11237322289dSmrg    fi
11247322289dSmrg
11257322289dSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
11267322289dSmrg    if test -n "$func_relative_path_result"; then
11277322289dSmrg      func_stripname './' '' "$func_relative_path_result"
11287322289dSmrg      func_relative_path_result=$func_stripname_result
11291d54945dSmrg    fi
11301d54945dSmrg
11317322289dSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
11327322289dSmrg
11337322289dSmrg    :
11347322289dSmrg}
11357322289dSmrg
11367322289dSmrg
113722663e35Smrg# func_quote_portable EVAL ARG
113822663e35Smrg# ----------------------------
113922663e35Smrg# Internal function to portably implement func_quote_arg.  Note that we still
114022663e35Smrg# keep attention to performance here so we as much as possible try to avoid
114122663e35Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
114222663e35Smrgfunc_quote_portable ()
11437322289dSmrg{
11447322289dSmrg    $debug_cmd
11457322289dSmrg
114622663e35Smrg    $require_check_ifs_backslash
114722663e35Smrg
114822663e35Smrg    func_quote_portable_result=$2
114922663e35Smrg
115022663e35Smrg    # one-time-loop (easy break)
115122663e35Smrg    while true
115222663e35Smrg    do
115322663e35Smrg      if $1; then
115422663e35Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
115522663e35Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
115622663e35Smrg        break
11577322289dSmrg      fi
11587322289dSmrg
115922663e35Smrg      # Quote for eval.
116022663e35Smrg      case $func_quote_portable_result in
116122663e35Smrg        *[\\\`\"\$]*)
116222663e35Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
116322663e35Smrg          # contains the shell wildcard characters.
116422663e35Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
116522663e35Smrg            :*|*[\[\*\?]*)
116622663e35Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
116722663e35Smrg                  | $SED "$sed_quote_subst"`
116822663e35Smrg              break
116922663e35Smrg              ;;
117022663e35Smrg          esac
117122663e35Smrg
117222663e35Smrg          func_quote_portable_old_IFS=$IFS
117322663e35Smrg          for _G_char in '\' '`' '"' '$'
117422663e35Smrg          do
117522663e35Smrg            # STATE($1) PREV($2) SEPARATOR($3)
117622663e35Smrg            set start "" ""
117722663e35Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
117822663e35Smrg            IFS=$_G_char
117922663e35Smrg            for _G_part in $func_quote_portable_result
118022663e35Smrg            do
118122663e35Smrg              case $1 in
118222663e35Smrg              quote)
118322663e35Smrg                func_append func_quote_portable_result "$3$2"
118422663e35Smrg                set quote "$_G_part" "\\$_G_char"
118522663e35Smrg                ;;
118622663e35Smrg              start)
118722663e35Smrg                set first "" ""
118822663e35Smrg                func_quote_portable_result=
118922663e35Smrg                ;;
119022663e35Smrg              first)
119122663e35Smrg                set quote "$_G_part" ""
119222663e35Smrg                ;;
119322663e35Smrg              esac
119422663e35Smrg            done
119522663e35Smrg          done
119622663e35Smrg          IFS=$func_quote_portable_old_IFS
11977322289dSmrg          ;;
119822663e35Smrg        *) ;;
11997322289dSmrg      esac
120022663e35Smrg      break
12017322289dSmrg    done
120222663e35Smrg
120322663e35Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
120422663e35Smrg    case $func_quote_portable_result in
120522663e35Smrg      # double-quote args containing shell metacharacters to delay
120622663e35Smrg      # word splitting, command substitution and variable expansion
120722663e35Smrg      # for a subsequent eval.
120822663e35Smrg      # many bourne shells cannot handle close brackets correctly
120922663e35Smrg      # in scan sets, so we specify it separately.
121022663e35Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
121122663e35Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
121222663e35Smrg        ;;
121322663e35Smrg    esac
12147322289dSmrg}
12157322289dSmrg
12167322289dSmrg
121722663e35Smrg# func_quotefast_eval ARG
121822663e35Smrg# -----------------------
121922663e35Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
122022663e35Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
122122663e35Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
122222663e35Smrg  printf -v _GL_test_printf_tilde %q '~'
122322663e35Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
122422663e35Smrg    func_quotefast_eval ()
122522663e35Smrg    {
122622663e35Smrg      printf -v func_quotefast_eval_result %q "$1"
122722663e35Smrg    }
122822663e35Smrg  else
122922663e35Smrg    # Broken older Bash implementations.  Make those faster too if possible.
123022663e35Smrg    func_quotefast_eval ()
123122663e35Smrg    {
123222663e35Smrg      case $1 in
123322663e35Smrg        '~'*)
123422663e35Smrg          func_quote_portable false "$1"
123522663e35Smrg          func_quotefast_eval_result=$func_quote_portable_result
123622663e35Smrg          ;;
123722663e35Smrg        *)
123822663e35Smrg          printf -v func_quotefast_eval_result %q "$1"
123922663e35Smrg          ;;
124022663e35Smrg      esac
124122663e35Smrg    }
124222663e35Smrg  fi
124322663e35Smrgelse
124422663e35Smrg  func_quotefast_eval ()
124522663e35Smrg  {
124622663e35Smrg    func_quote_portable false "$1"
124722663e35Smrg    func_quotefast_eval_result=$func_quote_portable_result
124822663e35Smrg  }
124922663e35Smrgfi
12507322289dSmrg
125122663e35Smrg
125222663e35Smrg# func_quote_arg MODEs ARG
125322663e35Smrg# ------------------------
125422663e35Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
125522663e35Smrg# specifiers listed below separated by ',' character.  This function returns two
125622663e35Smrg# values:
125722663e35Smrg#   i) func_quote_arg_result
125822663e35Smrg#      double-quoted (when needed), suitable for a subsequent eval
125922663e35Smrg#  ii) func_quote_arg_unquoted_result
126022663e35Smrg#      has all characters that are still active within double
126122663e35Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
126222663e35Smrg#
126322663e35Smrg# Available modes:
126422663e35Smrg# ----------------
126522663e35Smrg# 'eval' (default)
126622663e35Smrg#       - escape shell special characters
126722663e35Smrg# 'expand'
126822663e35Smrg#       - the same as 'eval';  but do not quote variable references
126922663e35Smrg# 'pretty'
127022663e35Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
127122663e35Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
127222663e35Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
127322663e35Smrg# 'unquoted'
127422663e35Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
127522663e35Smrg#         wrapping double-quotes.
127622663e35Smrg#
127722663e35Smrg# Examples for 'func_quote_arg pretty,unquoted string':
127822663e35Smrg#
127922663e35Smrg#   string      | *_result              | *_unquoted_result
128022663e35Smrg#   ------------+-----------------------+-------------------
128122663e35Smrg#   "           | \"                    | \"
128222663e35Smrg#   a b         | "a b"                 | a b
128322663e35Smrg#   "a b"       | "\"a b\""             | \"a b\"
128422663e35Smrg#   *           | "*"                   | *
128522663e35Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
128622663e35Smrg#
128722663e35Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
128822663e35Smrg#
128922663e35Smrg#   string        |   *_result          |  *_unquoted_result
129022663e35Smrg#   --------------+---------------------+--------------------
129122663e35Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
129222663e35Smrgfunc_quote_arg ()
129322663e35Smrg{
129422663e35Smrg    _G_quote_expand=false
129522663e35Smrg    case ,$1, in
129622663e35Smrg      *,expand,*)
129722663e35Smrg        _G_quote_expand=:
129822663e35Smrg        ;;
12997322289dSmrg    esac
13007322289dSmrg
130122663e35Smrg    case ,$1, in
130222663e35Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
130322663e35Smrg        func_quote_portable $_G_quote_expand "$2"
130422663e35Smrg        func_quote_arg_result=$func_quote_portable_result
130522663e35Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
130622663e35Smrg        ;;
130722663e35Smrg      *)
130822663e35Smrg        # Faster quote-for-eval for some shells.
130922663e35Smrg        func_quotefast_eval "$2"
131022663e35Smrg        func_quote_arg_result=$func_quotefast_eval_result
13117322289dSmrg        ;;
13127322289dSmrg    esac
131322663e35Smrg}
131422663e35Smrg
13157322289dSmrg
131622663e35Smrg# func_quote MODEs ARGs...
131722663e35Smrg# ------------------------
131822663e35Smrg# Quote all ARGs to be evaled later and join them into single command.  See
131922663e35Smrg# func_quote_arg's description for more info.
132022663e35Smrgfunc_quote ()
132122663e35Smrg{
132222663e35Smrg    $debug_cmd
132322663e35Smrg    _G_func_quote_mode=$1 ; shift
132422663e35Smrg    func_quote_result=
132522663e35Smrg    while test 0 -lt $#; do
132622663e35Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
132722663e35Smrg      if test -n "$func_quote_result"; then
132822663e35Smrg        func_append func_quote_result " $func_quote_arg_result"
132922663e35Smrg      else
133022663e35Smrg        func_append func_quote_result "$func_quote_arg_result"
133122663e35Smrg      fi
133222663e35Smrg      shift
133322663e35Smrg    done
13347322289dSmrg}
13357322289dSmrg
13367322289dSmrg
13377322289dSmrg# func_stripname PREFIX SUFFIX NAME
13387322289dSmrg# ---------------------------------
13397322289dSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
13407322289dSmrg# PREFIX and SUFFIX must not contain globbing or regex special
13417322289dSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
13427322289dSmrg# dot (in which case that matches only a dot).
13437322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
13447322289dSmrg  eval 'func_stripname ()
13457322289dSmrg  {
13467322289dSmrg    $debug_cmd
13477322289dSmrg
13487322289dSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
13497322289dSmrg    # positional parameters, so assign one to ordinary variable first.
13507322289dSmrg    func_stripname_result=$3
13517322289dSmrg    func_stripname_result=${func_stripname_result#"$1"}
13527322289dSmrg    func_stripname_result=${func_stripname_result%"$2"}
13537322289dSmrg  }'
13547322289dSmrgelse
13557322289dSmrg  func_stripname ()
13567322289dSmrg  {
13577322289dSmrg    $debug_cmd
13587322289dSmrg
13597322289dSmrg    case $2 in
13607322289dSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
13617322289dSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
13627322289dSmrg    esac
13637322289dSmrg  }
13647322289dSmrgfi
13657322289dSmrg
13667322289dSmrg
13677322289dSmrg# func_show_eval CMD [FAIL_EXP]
13687322289dSmrg# -----------------------------
13697322289dSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13707322289dSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13717322289dSmrg# is given, then evaluate it.
13727322289dSmrgfunc_show_eval ()
13737322289dSmrg{
13747322289dSmrg    $debug_cmd
13757322289dSmrg
13767322289dSmrg    _G_cmd=$1
13777322289dSmrg    _G_fail_exp=${2-':'}
13787322289dSmrg
137922663e35Smrg    func_quote_arg pretty,expand "$_G_cmd"
138022663e35Smrg    eval "func_notquiet $func_quote_arg_result"
13817322289dSmrg
13827322289dSmrg    $opt_dry_run || {
13837322289dSmrg      eval "$_G_cmd"
13847322289dSmrg      _G_status=$?
13857322289dSmrg      if test 0 -ne "$_G_status"; then
13867322289dSmrg	eval "(exit $_G_status); $_G_fail_exp"
13877322289dSmrg      fi
13887322289dSmrg    }
13897322289dSmrg}
13907322289dSmrg
13917322289dSmrg
13927322289dSmrg# func_show_eval_locale CMD [FAIL_EXP]
13937322289dSmrg# ------------------------------------
13947322289dSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13957322289dSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13967322289dSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
13977322289dSmrgfunc_show_eval_locale ()
13987322289dSmrg{
13997322289dSmrg    $debug_cmd
14007322289dSmrg
14017322289dSmrg    _G_cmd=$1
14027322289dSmrg    _G_fail_exp=${2-':'}
14037322289dSmrg
14047322289dSmrg    $opt_quiet || {
140522663e35Smrg      func_quote_arg expand,pretty "$_G_cmd"
140622663e35Smrg      eval "func_echo $func_quote_arg_result"
14077322289dSmrg    }
14087322289dSmrg
14097322289dSmrg    $opt_dry_run || {
14107322289dSmrg      eval "$_G_user_locale
14117322289dSmrg	    $_G_cmd"
14127322289dSmrg      _G_status=$?
14137322289dSmrg      eval "$_G_safe_locale"
14147322289dSmrg      if test 0 -ne "$_G_status"; then
14157322289dSmrg	eval "(exit $_G_status); $_G_fail_exp"
14167322289dSmrg      fi
14177322289dSmrg    }
14187322289dSmrg}
14197322289dSmrg
14207322289dSmrg
14217322289dSmrg# func_tr_sh
14227322289dSmrg# ----------
14237322289dSmrg# Turn $1 into a string suitable for a shell variable name.
14247322289dSmrg# Result is stored in $func_tr_sh_result.  All characters
14257322289dSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
14267322289dSmrg# if $1 begins with a digit, a '_' is prepended as well.
14277322289dSmrgfunc_tr_sh ()
14287322289dSmrg{
14297322289dSmrg    $debug_cmd
14307322289dSmrg
14317322289dSmrg    case $1 in
14327322289dSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
14337322289dSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
14347322289dSmrg      ;;
14357322289dSmrg    * )
14367322289dSmrg      func_tr_sh_result=$1
14377322289dSmrg      ;;
14387322289dSmrg    esac
14397322289dSmrg}
14407322289dSmrg
14417322289dSmrg
14427322289dSmrg# func_verbose ARG...
14437322289dSmrg# -------------------
14447322289dSmrg# Echo program name prefixed message in verbose mode only.
14457322289dSmrgfunc_verbose ()
14467322289dSmrg{
14477322289dSmrg    $debug_cmd
14487322289dSmrg
14497322289dSmrg    $opt_verbose && func_echo "$*"
14507322289dSmrg
14517322289dSmrg    :
14527322289dSmrg}
14537322289dSmrg
14547322289dSmrg
14557322289dSmrg# func_warn_and_continue ARG...
14567322289dSmrg# -----------------------------
14577322289dSmrg# Echo program name prefixed warning message to standard error.
14587322289dSmrgfunc_warn_and_continue ()
14597322289dSmrg{
14607322289dSmrg    $debug_cmd
14617322289dSmrg
14627322289dSmrg    $require_term_colors
14637322289dSmrg
14647322289dSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
14657322289dSmrg}
14667322289dSmrg
14677322289dSmrg
14687322289dSmrg# func_warning CATEGORY ARG...
14697322289dSmrg# ----------------------------
14707322289dSmrg# Echo program name prefixed warning message to standard error. Warning
14717322289dSmrg# messages can be filtered according to CATEGORY, where this function
14727322289dSmrg# elides messages where CATEGORY is not listed in the global variable
14737322289dSmrg# 'opt_warning_types'.
14747322289dSmrgfunc_warning ()
14757322289dSmrg{
14767322289dSmrg    $debug_cmd
14777322289dSmrg
14787322289dSmrg    # CATEGORY must be in the warning_categories list!
14797322289dSmrg    case " $warning_categories " in
14807322289dSmrg      *" $1 "*) ;;
14817322289dSmrg      *) func_internal_error "invalid warning category '$1'" ;;
14827322289dSmrg    esac
14837322289dSmrg
14847322289dSmrg    _G_category=$1
14857322289dSmrg    shift
14867322289dSmrg
14877322289dSmrg    case " $opt_warning_types " in
14887322289dSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
14897322289dSmrg    esac
14907322289dSmrg}
14917322289dSmrg
14927322289dSmrg
14937322289dSmrg# func_sort_ver VER1 VER2
14947322289dSmrg# -----------------------
14957322289dSmrg# 'sort -V' is not generally available.
14967322289dSmrg# Note this deviates from the version comparison in automake
14977322289dSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
14987322289dSmrg# but this should suffice as we won't be specifying old
14997322289dSmrg# version formats or redundant trailing .0 in bootstrap.conf.
15007322289dSmrg# If we did want full compatibility then we should probably
15017322289dSmrg# use m4_version_compare from autoconf.
15027322289dSmrgfunc_sort_ver ()
15037322289dSmrg{
15047322289dSmrg    $debug_cmd
15057322289dSmrg
15067322289dSmrg    printf '%s\n%s\n' "$1" "$2" \
15077322289dSmrg      | 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
15087322289dSmrg}
15097322289dSmrg
15107322289dSmrg# func_lt_ver PREV CURR
15117322289dSmrg# ---------------------
15127322289dSmrg# Return true if PREV and CURR are in the correct order according to
15137322289dSmrg# func_sort_ver, otherwise false.  Use it like this:
15147322289dSmrg#
15157322289dSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
15167322289dSmrgfunc_lt_ver ()
15177322289dSmrg{
15187322289dSmrg    $debug_cmd
15197322289dSmrg
15207322289dSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
15217322289dSmrg}
15227322289dSmrg
15237322289dSmrg
15247322289dSmrg# Local variables:
15257322289dSmrg# mode: shell-script
15267322289dSmrg# sh-indentation: 2
15277322289dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
15287322289dSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
15297322289dSmrg# time-stamp-time-zone: "UTC"
15307322289dSmrg# End:
15317322289dSmrg#! /bin/sh
15327322289dSmrg
15337322289dSmrg# A portable, pluggable option parser for Bourne shell.
15347322289dSmrg# Written by Gary V. Vaughan, 2010
15357322289dSmrg
153622663e35Smrg# This is free software.  There is NO warranty; not even for
153722663e35Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153822663e35Smrg#
153922663e35Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
154022663e35Smrg#
154122663e35Smrg# This file is dual licensed under the terms of the MIT license
154222663e35Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
154322663e35Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
154422663e35Smrg# these licenses when using or redistributing this software or any of
154522663e35Smrg# the files within it.  See the URLs above, or the file `LICENSE`
154622663e35Smrg# included in the Bootstrap distribution for the full license texts.
15477322289dSmrg
154822663e35Smrg# Please report bugs or propose patches to:
154922663e35Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
15507322289dSmrg
155122663e35Smrg# Set a version string for this script.
155222663e35Smrgscriptversion=2019-02-19.15; # UTC
15537322289dSmrg
15547322289dSmrg
15557322289dSmrg## ------ ##
15567322289dSmrg## Usage. ##
15577322289dSmrg## ------ ##
15587322289dSmrg
15597322289dSmrg# This file is a library for parsing options in your shell scripts along
15607322289dSmrg# with assorted other useful supporting features that you can make use
15617322289dSmrg# of too.
15627322289dSmrg#
15637322289dSmrg# For the simplest scripts you might need only:
15647322289dSmrg#
15657322289dSmrg#   #!/bin/sh
15667322289dSmrg#   . relative/path/to/funclib.sh
15677322289dSmrg#   . relative/path/to/options-parser
15687322289dSmrg#   scriptversion=1.0
15697322289dSmrg#   func_options ${1+"$@"}
15707322289dSmrg#   eval set dummy "$func_options_result"; shift
15717322289dSmrg#   ...rest of your script...
15727322289dSmrg#
15737322289dSmrg# In order for the '--version' option to work, you will need to have a
15747322289dSmrg# suitably formatted comment like the one at the top of this file
157522663e35Smrg# starting with '# Written by ' and ending with '# Copyright'.
15767322289dSmrg#
15777322289dSmrg# For '-h' and '--help' to work, you will also need a one line
15787322289dSmrg# description of your script's purpose in a comment directly above the
15797322289dSmrg# '# Written by ' line, like the one at the top of this file.
15807322289dSmrg#
15817322289dSmrg# The default options also support '--debug', which will turn on shell
15827322289dSmrg# execution tracing (see the comment above debug_cmd below for another
15837322289dSmrg# use), and '--verbose' and the func_verbose function to allow your script
15847322289dSmrg# to display verbose messages only when your user has specified
15857322289dSmrg# '--verbose'.
15867322289dSmrg#
158722663e35Smrg# After sourcing this file, you can plug in processing for additional
15887322289dSmrg# options by amending the variables from the 'Configuration' section
15897322289dSmrg# below, and following the instructions in the 'Option parsing'
15907322289dSmrg# section further down.
15917322289dSmrg
15927322289dSmrg## -------------- ##
15937322289dSmrg## Configuration. ##
15947322289dSmrg## -------------- ##
15957322289dSmrg
15967322289dSmrg# You should override these variables in your script after sourcing this
15977322289dSmrg# file so that they reflect the customisations you have added to the
15987322289dSmrg# option parser.
15997322289dSmrg
16007322289dSmrg# The usage line for option parsing errors and the start of '-h' and
16017322289dSmrg# '--help' output messages. You can embed shell variables for delayed
16027322289dSmrg# expansion at the time the message is displayed, but you will need to
16037322289dSmrg# quote other shell meta-characters carefully to prevent them being
16047322289dSmrg# expanded when the contents are evaled.
16057322289dSmrgusage='$progpath [OPTION]...'
16067322289dSmrg
16077322289dSmrg# Short help message in response to '-h' and '--help'.  Add to this or
16087322289dSmrg# override it after sourcing this library to reflect the full set of
16097322289dSmrg# options your script accepts.
16107322289dSmrgusage_message="\
16117322289dSmrg       --debug        enable verbose shell tracing
16127322289dSmrg   -W, --warnings=CATEGORY
16137322289dSmrg                      report the warnings falling in CATEGORY [all]
16147322289dSmrg   -v, --verbose      verbosely report processing
16157322289dSmrg       --version      print version information and exit
16167322289dSmrg   -h, --help         print short or long help message and exit
16177322289dSmrg"
16187322289dSmrg
16197322289dSmrg# Additional text appended to 'usage_message' in response to '--help'.
16207322289dSmrglong_help_message="
16217322289dSmrgWarning categories include:
16227322289dSmrg       'all'          show all warnings
16237322289dSmrg       'none'         turn off all the warnings
16247322289dSmrg       'error'        warnings are treated as fatal errors"
16257322289dSmrg
16267322289dSmrg# Help message printed before fatal option parsing errors.
16277322289dSmrgfatal_help="Try '\$progname --help' for more information."
16287322289dSmrg
16297322289dSmrg
16307322289dSmrg
16317322289dSmrg## ------------------------- ##
16327322289dSmrg## Hook function management. ##
16337322289dSmrg## ------------------------- ##
16347322289dSmrg
16357322289dSmrg# This section contains functions for adding, removing, and running hooks
163622663e35Smrg# in the main code.  A hook is just a list of function names that can be
163722663e35Smrg# run in order later on.
16387322289dSmrg
16397322289dSmrg# func_hookable FUNC_NAME
16407322289dSmrg# -----------------------
16417322289dSmrg# Declare that FUNC_NAME will run hooks added with
16427322289dSmrg# 'func_add_hook FUNC_NAME ...'.
16437322289dSmrgfunc_hookable ()
16447322289dSmrg{
16457322289dSmrg    $debug_cmd
16467322289dSmrg
16477322289dSmrg    func_append hookable_fns " $1"
16487322289dSmrg}
16497322289dSmrg
16507322289dSmrg
16517322289dSmrg# func_add_hook FUNC_NAME HOOK_FUNC
16527322289dSmrg# ---------------------------------
16537322289dSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
16547322289dSmrg# first have been declared "hookable" by a call to 'func_hookable'.
16557322289dSmrgfunc_add_hook ()
16567322289dSmrg{
16577322289dSmrg    $debug_cmd
16587322289dSmrg
16597322289dSmrg    case " $hookable_fns " in
16607322289dSmrg      *" $1 "*) ;;
16617322289dSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
16627322289dSmrg    esac
16637322289dSmrg
16647322289dSmrg    eval func_append ${1}_hooks '" $2"'
16657322289dSmrg}
16667322289dSmrg
16677322289dSmrg
16687322289dSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
16697322289dSmrg# ------------------------------------
167022663e35Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
167122663e35Smrg# FUNC_NAME.
16727322289dSmrgfunc_remove_hook ()
16737322289dSmrg{
16747322289dSmrg    $debug_cmd
16757322289dSmrg
16767322289dSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
16777322289dSmrg}
16787322289dSmrg
16797322289dSmrg
168022663e35Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
168122663e35Smrg# ---------------------------------------------
168222663e35Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
168322663e35Smrg# *_result variable of FUNC_NAME_B.
168422663e35Smrgfunc_propagate_result ()
168522663e35Smrg{
168622663e35Smrg    $debug_cmd
168722663e35Smrg
168822663e35Smrg    func_propagate_result_result=:
168922663e35Smrg    if eval "test \"\${${1}_result+set}\" = set"
169022663e35Smrg    then
169122663e35Smrg      eval "${2}_result=\$${1}_result"
169222663e35Smrg    else
169322663e35Smrg      func_propagate_result_result=false
169422663e35Smrg    fi
169522663e35Smrg}
169622663e35Smrg
169722663e35Smrg
16987322289dSmrg# func_run_hooks FUNC_NAME [ARG]...
16997322289dSmrg# ---------------------------------
17007322289dSmrg# Run all hook functions registered to FUNC_NAME.
170122663e35Smrg# It's assumed that the list of hook functions contains nothing more
17027322289dSmrg# than a whitespace-delimited list of legal shell function names, and
17037322289dSmrg# no effort is wasted trying to catch shell meta-characters or preserve
17047322289dSmrg# whitespace.
17057322289dSmrgfunc_run_hooks ()
17067322289dSmrg{
17077322289dSmrg    $debug_cmd
17087322289dSmrg
17097322289dSmrg    case " $hookable_fns " in
17107322289dSmrg      *" $1 "*) ;;
171122663e35Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17127322289dSmrg    esac
17137322289dSmrg
17147322289dSmrg    eval _G_hook_fns=\$$1_hooks; shift
17157322289dSmrg
17167322289dSmrg    for _G_hook in $_G_hook_fns; do
171722663e35Smrg      func_unset "${_G_hook}_result"
171822663e35Smrg      eval $_G_hook '${1+"$@"}'
171922663e35Smrg      func_propagate_result $_G_hook func_run_hooks
172022663e35Smrg      if $func_propagate_result_result; then
172122663e35Smrg        eval set dummy "$func_run_hooks_result"; shift
172222663e35Smrg      fi
17237322289dSmrg    done
17247322289dSmrg}
17257322289dSmrg
17267322289dSmrg
17277322289dSmrg
17287322289dSmrg## --------------- ##
17297322289dSmrg## Option parsing. ##
17307322289dSmrg## --------------- ##
17317322289dSmrg
17327322289dSmrg# In order to add your own option parsing hooks, you must accept the
173322663e35Smrg# full positional parameter list from your hook function.  You may remove
173422663e35Smrg# or edit any options that you action, and then pass back the remaining
173522663e35Smrg# unprocessed options in '<hooked_function_name>_result', escaped
173622663e35Smrg# suitably for 'eval'.
173722663e35Smrg#
173822663e35Smrg# The '<hooked_function_name>_result' variable is automatically unset
173922663e35Smrg# before your hook gets called; for best performance, only set the
174022663e35Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
174122663e35Smrg# function unnecessarily because it can be an expensive operation on some
174222663e35Smrg# machines).
174322663e35Smrg#
174422663e35Smrg# Like this:
17457322289dSmrg#
17467322289dSmrg#    my_options_prep ()
17477322289dSmrg#    {
17487322289dSmrg#        $debug_cmd
17497322289dSmrg#
17507322289dSmrg#        # Extend the existing usage message.
17517322289dSmrg#        usage_message=$usage_message'
17527322289dSmrg#      -s, --silent       don'\''t print informational messages
17537322289dSmrg#    '
175422663e35Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
175522663e35Smrg#        # my_options_prep_result variable intact.
17567322289dSmrg#    }
17577322289dSmrg#    func_add_hook func_options_prep my_options_prep
17587322289dSmrg#
17597322289dSmrg#
17607322289dSmrg#    my_silent_option ()
17617322289dSmrg#    {
17627322289dSmrg#        $debug_cmd
17637322289dSmrg#
176422663e35Smrg#        args_changed=false
176522663e35Smrg#
176622663e35Smrg#        # Note that, for efficiency, we parse as many options as we can
17677322289dSmrg#        # recognise in a loop before passing the remainder back to the
17687322289dSmrg#        # caller on the first unrecognised argument we encounter.
17697322289dSmrg#        while test $# -gt 0; do
17707322289dSmrg#          opt=$1; shift
17717322289dSmrg#          case $opt in
177222663e35Smrg#            --silent|-s) opt_silent=:
177322663e35Smrg#                         args_changed=:
177422663e35Smrg#                         ;;
17757322289dSmrg#            # Separate non-argument short options:
17767322289dSmrg#            -s*)         func_split_short_opt "$_G_opt"
17777322289dSmrg#                         set dummy "$func_split_short_opt_name" \
17787322289dSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
17797322289dSmrg#                         shift
178022663e35Smrg#                         args_changed=:
17817322289dSmrg#                         ;;
178222663e35Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
178322663e35Smrg#                         # is added back to "$@" in case we need it later,
178422663e35Smrg#                         # if $args_changed was set to 'true'.
178522663e35Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17867322289dSmrg#          esac
17877322289dSmrg#        done
17887322289dSmrg#
178922663e35Smrg#        # Only call 'func_quote' here if we processed at least one argument.
179022663e35Smrg#        if $args_changed; then
179122663e35Smrg#          func_quote eval ${1+"$@"}
179222663e35Smrg#          my_silent_option_result=$func_quote_result
179322663e35Smrg#        fi
17947322289dSmrg#    }
17957322289dSmrg#    func_add_hook func_parse_options my_silent_option
17967322289dSmrg#
17977322289dSmrg#
17987322289dSmrg#    my_option_validation ()
17997322289dSmrg#    {
18007322289dSmrg#        $debug_cmd
18017322289dSmrg#
18027322289dSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
18037322289dSmrg#    '--silent' and '--verbose' options are mutually exclusive."
18047322289dSmrg#    }
18057322289dSmrg#    func_add_hook func_validate_options my_option_validation
18067322289dSmrg#
180722663e35Smrg# You'll also need to manually amend $usage_message to reflect the extra
18087322289dSmrg# options you parse.  It's preferable to append if you can, so that
18097322289dSmrg# multiple option parsing hooks can be added safely.
18107322289dSmrg
18117322289dSmrg
181222663e35Smrg# func_options_finish [ARG]...
181322663e35Smrg# ----------------------------
181422663e35Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
181522663e35Smrgfunc_options_finish ()
181622663e35Smrg{
181722663e35Smrg    $debug_cmd
181822663e35Smrg
181922663e35Smrg    func_run_hooks func_options ${1+"$@"}
182022663e35Smrg    func_propagate_result func_run_hooks func_options_finish
182122663e35Smrg}
182222663e35Smrg
182322663e35Smrg
18247322289dSmrg# func_options [ARG]...
18257322289dSmrg# ---------------------
18267322289dSmrg# All the functions called inside func_options are hookable. See the
18277322289dSmrg# individual implementations for details.
18287322289dSmrgfunc_hookable func_options
18297322289dSmrgfunc_options ()
18307322289dSmrg{
18317322289dSmrg    $debug_cmd
18327322289dSmrg
183322663e35Smrg    _G_options_quoted=false
18347322289dSmrg
183522663e35Smrg    for my_func in options_prep parse_options validate_options options_finish
183622663e35Smrg    do
183722663e35Smrg      func_unset func_${my_func}_result
183822663e35Smrg      func_unset func_run_hooks_result
183922663e35Smrg      eval func_$my_func '${1+"$@"}'
184022663e35Smrg      func_propagate_result func_$my_func func_options
184122663e35Smrg      if $func_propagate_result_result; then
184222663e35Smrg        eval set dummy "$func_options_result"; shift
184322663e35Smrg        _G_options_quoted=:
184422663e35Smrg      fi
184522663e35Smrg    done
18467322289dSmrg
184722663e35Smrg    $_G_options_quoted || {
184822663e35Smrg      # As we (func_options) are top-level options-parser function and
184922663e35Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
185022663e35Smrg      # caller.
185122663e35Smrg      func_quote eval ${1+"$@"}
185222663e35Smrg      func_options_result=$func_quote_result
185322663e35Smrg    }
18541d54945dSmrg}
18551d54945dSmrg
18561d54945dSmrg
18577322289dSmrg# func_options_prep [ARG]...
18587322289dSmrg# --------------------------
18597322289dSmrg# All initialisations required before starting the option parse loop.
18607322289dSmrg# Note that when calling hook functions, we pass through the list of
18617322289dSmrg# positional parameters.  If a hook function modifies that list, and
186222663e35Smrg# needs to propagate that back to rest of this script, then the complete
186322663e35Smrg# modified list must be put in 'func_run_hooks_result' before returning.
18647322289dSmrgfunc_hookable func_options_prep
18657322289dSmrgfunc_options_prep ()
18661d54945dSmrg{
18677322289dSmrg    $debug_cmd
1868d769e936Smrg
18697322289dSmrg    # Option defaults:
18707322289dSmrg    opt_verbose=false
18717322289dSmrg    opt_warning_types=
18727322289dSmrg
18737322289dSmrg    func_run_hooks func_options_prep ${1+"$@"}
187422663e35Smrg    func_propagate_result func_run_hooks func_options_prep
1875d769e936Smrg}
1876d769e936Smrg
1877d769e936Smrg
18787322289dSmrg# func_parse_options [ARG]...
18797322289dSmrg# ---------------------------
18807322289dSmrg# The main option parsing loop.
18817322289dSmrgfunc_hookable func_parse_options
18827322289dSmrgfunc_parse_options ()
1883d769e936Smrg{
18847322289dSmrg    $debug_cmd
1885d769e936Smrg
188622663e35Smrg    _G_parse_options_requote=false
18877322289dSmrg    # this just eases exit handling
18887322289dSmrg    while test $# -gt 0; do
18897322289dSmrg      # Defer to hook functions for initial option parsing, so they
18907322289dSmrg      # get priority in the event of reusing an option name.
18917322289dSmrg      func_run_hooks func_parse_options ${1+"$@"}
189222663e35Smrg      func_propagate_result func_run_hooks func_parse_options
189322663e35Smrg      if $func_propagate_result_result; then
189422663e35Smrg        eval set dummy "$func_parse_options_result"; shift
189522663e35Smrg        # Even though we may have changed "$@", we passed the "$@" array
189622663e35Smrg        # down into the hook and it quoted it for us (because we are in
189722663e35Smrg        # this if-branch).  No need to quote it again.
189822663e35Smrg        _G_parse_options_requote=false
189922663e35Smrg      fi
1900d769e936Smrg
19017322289dSmrg      # Break out of the loop if we already parsed every option.
19027322289dSmrg      test $# -gt 0 || break
1903d769e936Smrg
190422663e35Smrg      # We expect that one of the options parsed in this function matches
190522663e35Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
190622663e35Smrg      _G_match_parse_options=:
19077322289dSmrg      _G_opt=$1
19087322289dSmrg      shift
19097322289dSmrg      case $_G_opt in
19107322289dSmrg        --debug|-x)   debug_cmd='set -x'
191122663e35Smrg                      func_echo "enabling shell trace mode" >&2
19127322289dSmrg                      $debug_cmd
19137322289dSmrg                      ;;
19147322289dSmrg
19157322289dSmrg        --no-warnings|--no-warning|--no-warn)
19167322289dSmrg                      set dummy --warnings none ${1+"$@"}
19177322289dSmrg                      shift
19187322289dSmrg		      ;;
1919d769e936Smrg
19207322289dSmrg        --warnings|--warning|-W)
192122663e35Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
192222663e35Smrg                        _G_parse_options_requote=:
192322663e35Smrg                        break
192422663e35Smrg                      fi
19257322289dSmrg                      case " $warning_categories $1" in
19267322289dSmrg                        *" $1 "*)
19277322289dSmrg                          # trailing space prevents matching last $1 above
19287322289dSmrg                          func_append_uniq opt_warning_types " $1"
19297322289dSmrg                          ;;
19307322289dSmrg                        *all)
19317322289dSmrg                          opt_warning_types=$warning_categories
19327322289dSmrg                          ;;
19337322289dSmrg                        *none)
19347322289dSmrg                          opt_warning_types=none
19357322289dSmrg                          warning_func=:
19367322289dSmrg                          ;;
19377322289dSmrg                        *error)
19387322289dSmrg                          opt_warning_types=$warning_categories
19397322289dSmrg                          warning_func=func_fatal_error
19407322289dSmrg                          ;;
19417322289dSmrg                        *)
19427322289dSmrg                          func_fatal_error \
19437322289dSmrg                             "unsupported warning category: '$1'"
19447322289dSmrg                          ;;
19457322289dSmrg                      esac
19467322289dSmrg                      shift
19477322289dSmrg                      ;;
19487322289dSmrg
19497322289dSmrg        --verbose|-v) opt_verbose=: ;;
19507322289dSmrg        --version)    func_version ;;
19517322289dSmrg        -\?|-h)       func_usage ;;
19527322289dSmrg        --help)       func_help ;;
19537322289dSmrg
19547322289dSmrg	# Separate optargs to long options (plugins may need this):
19557322289dSmrg	--*=*)        func_split_equals "$_G_opt"
19567322289dSmrg	              set dummy "$func_split_equals_lhs" \
19577322289dSmrg                          "$func_split_equals_rhs" ${1+"$@"}
19587322289dSmrg                      shift
19597322289dSmrg                      ;;
19607322289dSmrg
19617322289dSmrg       # Separate optargs to short options:
19627322289dSmrg        -W*)
19637322289dSmrg                      func_split_short_opt "$_G_opt"
19647322289dSmrg                      set dummy "$func_split_short_opt_name" \
19657322289dSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
19667322289dSmrg                      shift
19677322289dSmrg                      ;;
19687322289dSmrg
19697322289dSmrg        # Separate non-argument short options:
19707322289dSmrg        -\?*|-h*|-v*|-x*)
19717322289dSmrg                      func_split_short_opt "$_G_opt"
19727322289dSmrg                      set dummy "$func_split_short_opt_name" \
19737322289dSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
19747322289dSmrg                      shift
19757322289dSmrg                      ;;
19767322289dSmrg
197722663e35Smrg        --)           _G_parse_options_requote=: ; break ;;
19787322289dSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
197922663e35Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
198022663e35Smrg                      _G_match_parse_options=false
198122663e35Smrg                      break
198222663e35Smrg                      ;;
19837322289dSmrg      esac
198422663e35Smrg
198522663e35Smrg      if $_G_match_parse_options; then
198622663e35Smrg        _G_parse_options_requote=:
198722663e35Smrg      fi
19887322289dSmrg    done
19897322289dSmrg
199022663e35Smrg    if $_G_parse_options_requote; then
199122663e35Smrg      # save modified positional parameters for caller
199222663e35Smrg      func_quote eval ${1+"$@"}
199322663e35Smrg      func_parse_options_result=$func_quote_result
199422663e35Smrg    fi
1995d769e936Smrg}
1996d769e936Smrg
1997d769e936Smrg
19987322289dSmrg# func_validate_options [ARG]...
19997322289dSmrg# ------------------------------
20007322289dSmrg# Perform any sanity checks on option settings and/or unconsumed
20017322289dSmrg# arguments.
20027322289dSmrgfunc_hookable func_validate_options
20037322289dSmrgfunc_validate_options ()
2004d769e936Smrg{
20057322289dSmrg    $debug_cmd
2006d769e936Smrg
20077322289dSmrg    # Display all warnings if -W was not given.
20087322289dSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009d769e936Smrg
20107322289dSmrg    func_run_hooks func_validate_options ${1+"$@"}
201122663e35Smrg    func_propagate_result func_run_hooks func_validate_options
2012d769e936Smrg
20137322289dSmrg    # Bail if the options were screwed!
20147322289dSmrg    $exit_cmd $EXIT_FAILURE
20151d54945dSmrg}
20161d54945dSmrg
20171d54945dSmrg
2018d769e936Smrg
20197322289dSmrg## ----------------- ##
20207322289dSmrg## Helper functions. ##
20217322289dSmrg## ----------------- ##
20221d54945dSmrg
20237322289dSmrg# This section contains the helper functions used by the rest of the
20247322289dSmrg# hookable option parser framework in ascii-betical order.
20257322289dSmrg
20267322289dSmrg
20277322289dSmrg# func_fatal_help ARG...
20287322289dSmrg# ----------------------
20297322289dSmrg# Echo program name prefixed message to standard error, followed by
20307322289dSmrg# a help hint, and exit.
20317322289dSmrgfunc_fatal_help ()
20321d54945dSmrg{
20337322289dSmrg    $debug_cmd
2034d769e936Smrg
20357322289dSmrg    eval \$ECHO \""Usage: $usage"\"
20367322289dSmrg    eval \$ECHO \""$fatal_help"\"
20377322289dSmrg    func_error ${1+"$@"}
20387322289dSmrg    exit $EXIT_FAILURE
20391d54945dSmrg}
20401d54945dSmrg
20417322289dSmrg
20427322289dSmrg# func_help
20437322289dSmrg# ---------
20447322289dSmrg# Echo long help message to standard output and exit.
2045d769e936Smrgfunc_help ()
20461d54945dSmrg{
20477322289dSmrg    $debug_cmd
20487322289dSmrg
20497322289dSmrg    func_usage_message
20507322289dSmrg    $ECHO "$long_help_message"
20517322289dSmrg    exit 0
2052d769e936Smrg}
20531d54945dSmrg
20547322289dSmrg
20557322289dSmrg# func_missing_arg ARGNAME
20567322289dSmrg# ------------------------
2057d769e936Smrg# Echo program name prefixed message to standard error and set global
2058d769e936Smrg# exit_cmd.
2059d769e936Smrgfunc_missing_arg ()
2060d769e936Smrg{
20617322289dSmrg    $debug_cmd
2062786a6f21Smrg
20637322289dSmrg    func_error "Missing argument for '$1'."
2064d769e936Smrg    exit_cmd=exit
20651d54945dSmrg}
20661d54945dSmrg
2067786a6f21Smrg
20687322289dSmrg# func_split_equals STRING
20697322289dSmrg# ------------------------
207022663e35Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
207122663e35Smrg# after splitting STRING at the '=' sign.
20727322289dSmrgtest -z "$_G_HAVE_XSI_OPS" \
20737322289dSmrg    && (eval 'x=a/b/c;
20747322289dSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
20757322289dSmrg    && _G_HAVE_XSI_OPS=yes
20767322289dSmrg
20777322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"
20787322289dSmrgthen
20797322289dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
20807322289dSmrg  eval 'func_split_equals ()
20817322289dSmrg  {
20827322289dSmrg      $debug_cmd
20837322289dSmrg
20847322289dSmrg      func_split_equals_lhs=${1%%=*}
20857322289dSmrg      func_split_equals_rhs=${1#*=}
208622663e35Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
208722663e35Smrg        func_split_equals_rhs=
208822663e35Smrg      fi
20897322289dSmrg  }'
20907322289dSmrgelse
20917322289dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
20927322289dSmrg  func_split_equals ()
20937322289dSmrg  {
20947322289dSmrg      $debug_cmd
20957322289dSmrg
20967322289dSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
20977322289dSmrg      func_split_equals_rhs=
209822663e35Smrg      test "x$func_split_equals_lhs=" = "x$1" \
20997322289dSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
21007322289dSmrg  }
21017322289dSmrgfi #func_split_equals
21027322289dSmrg
21037322289dSmrg
21047322289dSmrg# func_split_short_opt SHORTOPT
21057322289dSmrg# -----------------------------
2106d769e936Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107d769e936Smrg# variables after splitting SHORTOPT after the 2nd character.
21087322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"
21097322289dSmrgthen
21107322289dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
21117322289dSmrg  eval 'func_split_short_opt ()
21127322289dSmrg  {
21137322289dSmrg      $debug_cmd
21147322289dSmrg
21157322289dSmrg      func_split_short_opt_arg=${1#??}
21167322289dSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
21177322289dSmrg  }'
21187322289dSmrgelse
21197322289dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
21207322289dSmrg  func_split_short_opt ()
21217322289dSmrg  {
21227322289dSmrg      $debug_cmd
21237322289dSmrg
212422663e35Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
21257322289dSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
21267322289dSmrg  }
21277322289dSmrgfi #func_split_short_opt
21287322289dSmrg
21297322289dSmrg
21307322289dSmrg# func_usage
21317322289dSmrg# ----------
21327322289dSmrg# Echo short help message to standard output and exit.
21337322289dSmrgfunc_usage ()
2134d769e936Smrg{
21357322289dSmrg    $debug_cmd
2136d769e936Smrg
21377322289dSmrg    func_usage_message
21387322289dSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
21397322289dSmrg    exit 0
21407322289dSmrg}
2141786a6f21Smrg
21421d54945dSmrg
21437322289dSmrg# func_usage_message
21447322289dSmrg# ------------------
21457322289dSmrg# Echo short help message to standard output.
21467322289dSmrgfunc_usage_message ()
2147d769e936Smrg{
21487322289dSmrg    $debug_cmd
21491d54945dSmrg
21507322289dSmrg    eval \$ECHO \""Usage: $usage"\"
21517322289dSmrg    echo
21527322289dSmrg    $SED -n 's|^# ||
21537322289dSmrg        /^Written by/{
21547322289dSmrg          x;p;x
21557322289dSmrg        }
21567322289dSmrg	h
21577322289dSmrg	/^Written by/q' < "$progpath"
21587322289dSmrg    echo
21597322289dSmrg    eval \$ECHO \""$usage_message"\"
21607322289dSmrg}
21611d54945dSmrg
21621d54945dSmrg
21637322289dSmrg# func_version
21647322289dSmrg# ------------
21657322289dSmrg# Echo version message to standard output and exit.
216622663e35Smrg# The version message is extracted from the calling file's header
216722663e35Smrg# comments, with leading '# ' stripped:
216822663e35Smrg#   1. First display the progname and version
216922663e35Smrg#   2. Followed by the header comment line matching  /^# Written by /
217022663e35Smrg#   3. Then a blank line followed by the first following line matching
217122663e35Smrg#      /^# Copyright /
217222663e35Smrg#   4. Immediately followed by any lines between the previous matches,
217322663e35Smrg#      except lines preceding the intervening completely blank line.
217422663e35Smrg# For example, see the header comments of this file.
21757322289dSmrgfunc_version ()
21767322289dSmrg{
21777322289dSmrg    $debug_cmd
21781d54945dSmrg
21797322289dSmrg    printf '%s\n' "$progname $scriptversion"
21807322289dSmrg    $SED -n '
218122663e35Smrg        /^# Written by /!b
218222663e35Smrg        s|^# ||; p; n
218322663e35Smrg
218422663e35Smrg        :fwd2blnk
218522663e35Smrg        /./ {
218622663e35Smrg          n
218722663e35Smrg          b fwd2blnk
21887322289dSmrg        }
218922663e35Smrg        p; n
219022663e35Smrg
219122663e35Smrg        :holdwrnt
219222663e35Smrg        s|^# ||
219322663e35Smrg        s|^# *$||
219422663e35Smrg        /^Copyright /!{
219522663e35Smrg          /./H
219622663e35Smrg          n
219722663e35Smrg          b holdwrnt
21987322289dSmrg        }
219922663e35Smrg
220022663e35Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
220122663e35Smrg        G
220222663e35Smrg        s|\(\n\)\n*|\1|g
220322663e35Smrg        p; q' < "$progpath"
22041d54945dSmrg
22057322289dSmrg    exit $?
22067322289dSmrg}
2207786a6f21Smrg
2208786a6f21Smrg
22097322289dSmrg# Local variables:
22107322289dSmrg# mode: shell-script
22117322289dSmrg# sh-indentation: 2
22127322289dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
221322663e35Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
22147322289dSmrg# time-stamp-time-zone: "UTC"
22157322289dSmrg# End:
2216d769e936Smrg
22177322289dSmrg# Set a version string.
221822663e35Smrgscriptversion='(GNU libtool) 2.4.7'
2219d769e936Smrg
2220d769e936Smrg
22217322289dSmrg# func_echo ARG...
22227322289dSmrg# ----------------
22237322289dSmrg# Libtool also displays the current mode in messages, so override
22247322289dSmrg# funclib.sh func_echo with this custom definition.
22257322289dSmrgfunc_echo ()
2226d769e936Smrg{
22277322289dSmrg    $debug_cmd
2228d769e936Smrg
22297322289dSmrg    _G_message=$*
2230d769e936Smrg
22317322289dSmrg    func_echo_IFS=$IFS
22327322289dSmrg    IFS=$nl
22337322289dSmrg    for _G_line in $_G_message; do
22347322289dSmrg      IFS=$func_echo_IFS
22357322289dSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
22367322289dSmrg    done
22377322289dSmrg    IFS=$func_echo_IFS
22387322289dSmrg}
2239d769e936Smrg
22407322289dSmrg
22417322289dSmrg# func_warning ARG...
22427322289dSmrg# -------------------
22437322289dSmrg# Libtool warnings are not categorized, so override funclib.sh
22447322289dSmrg# func_warning with this simpler definition.
22457322289dSmrgfunc_warning ()
2246d769e936Smrg{
22477322289dSmrg    $debug_cmd
2248d769e936Smrg
22497322289dSmrg    $warning_func ${1+"$@"}
22507322289dSmrg}
2251d769e936Smrg
2252d769e936Smrg
22537322289dSmrg## ---------------- ##
22547322289dSmrg## Options parsing. ##
22557322289dSmrg## ---------------- ##
22567322289dSmrg
22577322289dSmrg# Hook in the functions to make sure our own options are parsed during
22587322289dSmrg# the option parsing loop.
22597322289dSmrg
22607322289dSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
22617322289dSmrg
22627322289dSmrg# Short help message in response to '-h'.
22637322289dSmrgusage_message="Options:
22647322289dSmrg       --config             show all configuration variables
22657322289dSmrg       --debug              enable verbose shell tracing
22667322289dSmrg   -n, --dry-run            display commands without modifying any files
22677322289dSmrg       --features           display basic configuration information and exit
22687322289dSmrg       --mode=MODE          use operation mode MODE
22697322289dSmrg       --no-warnings        equivalent to '-Wnone'
22707322289dSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
22717322289dSmrg       --quiet, --silent    don't print informational messages
22727322289dSmrg       --tag=TAG            use configuration variables from tag TAG
22737322289dSmrg   -v, --verbose            print more informational messages than default
22747322289dSmrg       --version            print version information
22757322289dSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
22767322289dSmrg   -h, --help, --help-all   print short, long, or detailed help message
22777322289dSmrg"
2278d769e936Smrg
22797322289dSmrg# Additional text appended to 'usage_message' in response to '--help'.
22807322289dSmrgfunc_help ()
2281d769e936Smrg{
22827322289dSmrg    $debug_cmd
22837322289dSmrg
22847322289dSmrg    func_usage_message
22857322289dSmrg    $ECHO "$long_help_message
22867322289dSmrg
22877322289dSmrgMODE must be one of the following:
22887322289dSmrg
22897322289dSmrg       clean           remove files from the build directory
22907322289dSmrg       compile         compile a source file into a libtool object
22917322289dSmrg       execute         automatically set library path, then run a program
22927322289dSmrg       finish          complete the installation of libtool libraries
22937322289dSmrg       install         install libraries or executables
22947322289dSmrg       link            create a library or an executable
22957322289dSmrg       uninstall       remove libraries from an installed directory
22967322289dSmrg
22977322289dSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
22987322289dSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
22997322289dSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
23007322289dSmrg
23017322289dSmrgWhen reporting a bug, please describe a test case to reproduce it and
23027322289dSmrginclude the following information:
23037322289dSmrg
23047322289dSmrg       host-triplet:   $host
23057322289dSmrg       shell:          $SHELL
23067322289dSmrg       compiler:       $LTCC
23077322289dSmrg       compiler flags: $LTCFLAGS
23087322289dSmrg       linker:         $LD (gnu? $with_gnu_ld)
230922663e35Smrg       version:        $progname (GNU libtool) 2.4.7
23107322289dSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
23117322289dSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
23127322289dSmrg
23137322289dSmrgReport bugs to <bug-libtool@gnu.org>.
231422663e35SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
23157322289dSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
23167322289dSmrg    exit 0
23177322289dSmrg}
2318d769e936Smrg
2319d769e936Smrg
23207322289dSmrg# func_lo2o OBJECT-NAME
23217322289dSmrg# ---------------------
23227322289dSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
23237322289dSmrg# object suffix.
23247322289dSmrg
23257322289dSmrglo2o=s/\\.lo\$/.$objext/
23267322289dSmrgo2lo=s/\\.$objext\$/.lo/
23277322289dSmrg
23287322289dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
23297322289dSmrg  eval 'func_lo2o ()
23307322289dSmrg  {
23317322289dSmrg    case $1 in
23327322289dSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
23337322289dSmrg      *   ) func_lo2o_result=$1               ;;
23347322289dSmrg    esac
23357322289dSmrg  }'
23367322289dSmrg
23377322289dSmrg  # func_xform LIBOBJ-OR-SOURCE
23387322289dSmrg  # ---------------------------
23397322289dSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
23407322289dSmrg  # suffix to a '.lo' libtool-object suffix.
23417322289dSmrg  eval 'func_xform ()
23427322289dSmrg  {
23437322289dSmrg    func_xform_result=${1%.*}.lo
23447322289dSmrg  }'
23457322289dSmrgelse
23467322289dSmrg  # ...otherwise fall back to using sed.
23477322289dSmrg  func_lo2o ()
23487322289dSmrg  {
23497322289dSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
23507322289dSmrg  }
23517322289dSmrg
23527322289dSmrg  func_xform ()
23537322289dSmrg  {
23547322289dSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
23557322289dSmrg  }
23567322289dSmrgfi
2357d769e936Smrg
2358d769e936Smrg
23597322289dSmrg# func_fatal_configuration ARG...
23607322289dSmrg# -------------------------------
2361d769e936Smrg# Echo program name prefixed message to standard error, followed by
2362d769e936Smrg# a configuration failure hint, and exit.
2363d769e936Smrgfunc_fatal_configuration ()
2364d769e936Smrg{
236522663e35Smrg    func_fatal_error ${1+"$@"} \
23667322289dSmrg      "See the $PACKAGE documentation for more information." \
23677322289dSmrg      "Fatal configuration error."
2368d769e936Smrg}
2369d769e936Smrg
2370d769e936Smrg
2371d769e936Smrg# func_config
23727322289dSmrg# -----------
2373d769e936Smrg# Display the configuration for all the tags in this script.
2374d769e936Smrgfunc_config ()
2375d769e936Smrg{
2376d769e936Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377d769e936Smrg    re_endcf='^# ### END LIBTOOL'
2378d769e936Smrg
2379d769e936Smrg    # Default configuration.
2380d769e936Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2381d769e936Smrg
23821d54945dSmrg    # Now print the configurations for the tags.
23831d54945dSmrg    for tagname in $taglist; do
2384d769e936Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
23851d54945dSmrg    done
2386ec713c28Smrg
2387d769e936Smrg    exit $?
2388d769e936Smrg}
2389ec713c28Smrg
23907322289dSmrg
2391d769e936Smrg# func_features
23927322289dSmrg# -------------
2393d769e936Smrg# Display the features supported by this script.
2394d769e936Smrgfunc_features ()
2395d769e936Smrg{
2396d769e936Smrg    echo "host: $host"
23977322289dSmrg    if test yes = "$build_libtool_libs"; then
2398d769e936Smrg      echo "enable shared libraries"
23991d54945dSmrg    else
2400d769e936Smrg      echo "disable shared libraries"
24011d54945dSmrg    fi
24027322289dSmrg    if test yes = "$build_old_libs"; then
2403d769e936Smrg      echo "enable static libraries"
24041d54945dSmrg    else
2405d769e936Smrg      echo "disable static libraries"
24061d54945dSmrg    fi
24071d54945dSmrg
2408d769e936Smrg    exit $?
2409d769e936Smrg}
2410786a6f21Smrg
24117322289dSmrg
24127322289dSmrg# func_enable_tag TAGNAME
24137322289dSmrg# -----------------------
2414d769e936Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415d769e936Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416d769e936Smrg# variable here.
2417d769e936Smrgfunc_enable_tag ()
2418d769e936Smrg{
24197322289dSmrg    # Global variable:
24207322289dSmrg    tagname=$1
24211d54945dSmrg
24227322289dSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
24237322289dSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
24247322289dSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425ec713c28Smrg
24267322289dSmrg    # Validate tagname.
24277322289dSmrg    case $tagname in
24287322289dSmrg      *[!-_A-Za-z0-9,/]*)
24297322289dSmrg        func_fatal_error "invalid tag name: $tagname"
24307322289dSmrg        ;;
24317322289dSmrg    esac
2432ec713c28Smrg
24337322289dSmrg    # Don't test for the "default" C tag, as we know it's
24347322289dSmrg    # there but not specially marked.
24357322289dSmrg    case $tagname in
24367322289dSmrg        CC) ;;
2437d769e936Smrg    *)
24387322289dSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
24397322289dSmrg	  taglist="$taglist $tagname"
24407322289dSmrg
24417322289dSmrg	  # Evaluate the configuration.  Be careful to quote the path
24427322289dSmrg	  # and the sed script, to avoid splitting on whitespace, but
24437322289dSmrg	  # also don't use non-portable quotes within backquotes within
24447322289dSmrg	  # quotes we have to do it in 2 steps:
24457322289dSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
24467322289dSmrg	  eval "$extractedcf"
24477322289dSmrg        else
24487322289dSmrg	  func_error "ignoring unknown tag $tagname"
24497322289dSmrg        fi
24507322289dSmrg        ;;
24517322289dSmrg    esac
2452d769e936Smrg}
2453ec713c28Smrg
24547322289dSmrg
2455d769e936Smrg# func_check_version_match
24567322289dSmrg# ------------------------
2457d769e936Smrg# Ensure that we are using m4 macros, and libtool script from the same
2458d769e936Smrg# release of libtool.
2459d769e936Smrgfunc_check_version_match ()
2460d769e936Smrg{
24617322289dSmrg    if test "$package_revision" != "$macro_revision"; then
24627322289dSmrg      if test "$VERSION" != "$macro_version"; then
24637322289dSmrg        if test -z "$macro_version"; then
24647322289dSmrg          cat >&2 <<_LT_EOF
2465d769e936Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466d769e936Smrg$progname: definition of this LT_INIT comes from an older release.
2467d769e936Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468d769e936Smrg$progname: and run autoconf again.
2469d769e936Smrg_LT_EOF
24707322289dSmrg        else
24717322289dSmrg          cat >&2 <<_LT_EOF
2472d769e936Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473d769e936Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474d769e936Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475d769e936Smrg$progname: and run autoconf again.
2476d769e936Smrg_LT_EOF
24777322289dSmrg        fi
24787322289dSmrg      else
24797322289dSmrg        cat >&2 <<_LT_EOF
2480d769e936Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481d769e936Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482d769e936Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483d769e936Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484d769e936Smrg_LT_EOF
24857322289dSmrg      fi
2486ec713c28Smrg
24877322289dSmrg      exit $EXIT_MISMATCH
24887322289dSmrg    fi
2489d769e936Smrg}
24901d54945dSmrg
2491786a6f21Smrg
24927322289dSmrg# libtool_options_prep [ARG]...
24937322289dSmrg# -----------------------------
24947322289dSmrg# Preparation for options parsed by libtool.
24957322289dSmrglibtool_options_prep ()
24967322289dSmrg{
24977322289dSmrg    $debug_mode
2498786a6f21Smrg
24997322289dSmrg    # Option defaults:
25007322289dSmrg    opt_config=false
25017322289dSmrg    opt_dlopen=
25027322289dSmrg    opt_dry_run=false
25037322289dSmrg    opt_help=false
25047322289dSmrg    opt_mode=
25057322289dSmrg    opt_preserve_dup_deps=false
25067322289dSmrg    opt_quiet=false
2507786a6f21Smrg
25087322289dSmrg    nonopt=
25097322289dSmrg    preserve_args=
2510786a6f21Smrg
251122663e35Smrg    _G_rc_lt_options_prep=:
251222663e35Smrg
25137322289dSmrg    # Shorthand for --mode=foo, only valid as the first argument
25147322289dSmrg    case $1 in
25157322289dSmrg    clean|clea|cle|cl)
25167322289dSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
25177322289dSmrg      ;;
25187322289dSmrg    compile|compil|compi|comp|com|co|c)
25197322289dSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
25207322289dSmrg      ;;
25217322289dSmrg    execute|execut|execu|exec|exe|ex|e)
25227322289dSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
25237322289dSmrg      ;;
25247322289dSmrg    finish|finis|fini|fin|fi|f)
25257322289dSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
25267322289dSmrg      ;;
25277322289dSmrg    install|instal|insta|inst|ins|in|i)
25287322289dSmrg      shift; set dummy --mode install ${1+"$@"}; shift
25297322289dSmrg      ;;
25307322289dSmrg    link|lin|li|l)
25317322289dSmrg      shift; set dummy --mode link ${1+"$@"}; shift
25327322289dSmrg      ;;
25337322289dSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
25347322289dSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
25357322289dSmrg      ;;
253622663e35Smrg    *)
253722663e35Smrg      _G_rc_lt_options_prep=false
253822663e35Smrg      ;;
25397322289dSmrg    esac
25407322289dSmrg
254122663e35Smrg    if $_G_rc_lt_options_prep; then
254222663e35Smrg      # Pass back the list of options.
254322663e35Smrg      func_quote eval ${1+"$@"}
254422663e35Smrg      libtool_options_prep_result=$func_quote_result
254522663e35Smrg    fi
25467322289dSmrg}
25477322289dSmrgfunc_add_hook func_options_prep libtool_options_prep
2548786a6f21Smrg
2549d769e936Smrg
25507322289dSmrg# libtool_parse_options [ARG]...
25517322289dSmrg# ---------------------------------
25527322289dSmrg# Provide handling for libtool specific options.
25537322289dSmrglibtool_parse_options ()
2554d769e936Smrg{
25557322289dSmrg    $debug_cmd
25561d54945dSmrg
255722663e35Smrg    _G_rc_lt_parse_options=false
255822663e35Smrg
25597322289dSmrg    # Perform our own loop to consume as many options as possible in
25607322289dSmrg    # each iteration.
25617322289dSmrg    while test $# -gt 0; do
256222663e35Smrg      _G_match_lt_parse_options=:
25637322289dSmrg      _G_opt=$1
25647322289dSmrg      shift
25657322289dSmrg      case $_G_opt in
25667322289dSmrg        --dry-run|--dryrun|-n)
25677322289dSmrg                        opt_dry_run=:
25687322289dSmrg                        ;;
25697322289dSmrg
25707322289dSmrg        --config)       func_config ;;
25717322289dSmrg
25727322289dSmrg        --dlopen|-dlopen)
25737322289dSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
25747322289dSmrg}$1"
25757322289dSmrg                        shift
25767322289dSmrg                        ;;
25777322289dSmrg
25787322289dSmrg        --preserve-dup-deps)
25797322289dSmrg                        opt_preserve_dup_deps=: ;;
25807322289dSmrg
25817322289dSmrg        --features)     func_features ;;
25827322289dSmrg
25837322289dSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
25847322289dSmrg
25857322289dSmrg        --help)         opt_help=: ;;
25867322289dSmrg
25877322289dSmrg        --help-all)     opt_help=': help-all' ;;
25887322289dSmrg
25897322289dSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
25907322289dSmrg                        opt_mode=$1
25917322289dSmrg                        case $1 in
25927322289dSmrg                          # Valid mode arguments:
25937322289dSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
25947322289dSmrg
25957322289dSmrg                          # Catch anything else as an error
25967322289dSmrg                          *) func_error "invalid argument for $_G_opt"
25977322289dSmrg                             exit_cmd=exit
25987322289dSmrg                             break
25997322289dSmrg                             ;;
26007322289dSmrg                        esac
26017322289dSmrg                        shift
26027322289dSmrg                        ;;
26037322289dSmrg
26047322289dSmrg        --no-silent|--no-quiet)
26057322289dSmrg                        opt_quiet=false
26067322289dSmrg                        func_append preserve_args " $_G_opt"
26077322289dSmrg                        ;;
26087322289dSmrg
26097322289dSmrg        --no-warnings|--no-warning|--no-warn)
26107322289dSmrg                        opt_warning=false
26117322289dSmrg                        func_append preserve_args " $_G_opt"
26127322289dSmrg                        ;;
26137322289dSmrg
26147322289dSmrg        --no-verbose)
26157322289dSmrg                        opt_verbose=false
26167322289dSmrg                        func_append preserve_args " $_G_opt"
26177322289dSmrg                        ;;
26187322289dSmrg
26197322289dSmrg        --silent|--quiet)
26207322289dSmrg                        opt_quiet=:
26217322289dSmrg                        opt_verbose=false
26227322289dSmrg                        func_append preserve_args " $_G_opt"
26237322289dSmrg                        ;;
26247322289dSmrg
26257322289dSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
26267322289dSmrg                        opt_tag=$1
26277322289dSmrg                        func_append preserve_args " $_G_opt $1"
26287322289dSmrg                        func_enable_tag "$1"
26297322289dSmrg                        shift
26307322289dSmrg                        ;;
26317322289dSmrg
26327322289dSmrg        --verbose|-v)   opt_quiet=false
26337322289dSmrg                        opt_verbose=:
26347322289dSmrg                        func_append preserve_args " $_G_opt"
26357322289dSmrg                        ;;
26367322289dSmrg
263722663e35Smrg        # An option not handled by this hook function:
263822663e35Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
263922663e35Smrg                        _G_match_lt_parse_options=false
264022663e35Smrg                        break
264122663e35Smrg                        ;;
26427322289dSmrg      esac
264322663e35Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
26447322289dSmrg    done
2645d769e936Smrg
264622663e35Smrg    if $_G_rc_lt_parse_options; then
264722663e35Smrg      # save modified positional parameters for caller
264822663e35Smrg      func_quote eval ${1+"$@"}
264922663e35Smrg      libtool_parse_options_result=$func_quote_result
265022663e35Smrg    fi
26517322289dSmrg}
26527322289dSmrgfunc_add_hook func_parse_options libtool_parse_options
26531d54945dSmrg
26541d54945dSmrg
26551d54945dSmrg
26567322289dSmrg# libtool_validate_options [ARG]...
26577322289dSmrg# ---------------------------------
26587322289dSmrg# Perform any sanity checks on option settings and/or unconsumed
26597322289dSmrg# arguments.
26607322289dSmrglibtool_validate_options ()
26617322289dSmrg{
26627322289dSmrg    # save first non-option argument
26637322289dSmrg    if test 0 -lt $#; then
26647322289dSmrg      nonopt=$1
26657322289dSmrg      shift
2666d769e936Smrg    fi
2667786a6f21Smrg
26687322289dSmrg    # preserve --debug
26697322289dSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26701d54945dSmrg
26717322289dSmrg    case $host in
26727322289dSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
26737322289dSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
26747322289dSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
26757322289dSmrg        # don't eliminate duplications in $postdeps and $predeps
26767322289dSmrg        opt_duplicate_compiler_generated_deps=:
26777322289dSmrg        ;;
26787322289dSmrg      *)
26797322289dSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
26807322289dSmrg        ;;
26817322289dSmrg    esac
26821d54945dSmrg
26837322289dSmrg    $opt_help || {
26847322289dSmrg      # Sanity checks first:
26857322289dSmrg      func_check_version_match
26867322289dSmrg
26877322289dSmrg      test yes != "$build_libtool_libs" \
26887322289dSmrg        && test yes != "$build_old_libs" \
26897322289dSmrg        && func_fatal_configuration "not configured to build any kind of library"
26907322289dSmrg
26917322289dSmrg      # Darwin sucks
26927322289dSmrg      eval std_shrext=\"$shrext_cmds\"
26937322289dSmrg
26947322289dSmrg      # Only execute mode is allowed to have -dlopen flags.
26957322289dSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
26967322289dSmrg        func_error "unrecognized option '-dlopen'"
26977322289dSmrg        $ECHO "$help" 1>&2
26987322289dSmrg        exit $EXIT_FAILURE
26997322289dSmrg      fi
2700ec713c28Smrg
27017322289dSmrg      # Change the help message to a mode-specific one.
27027322289dSmrg      generic_help=$help
27037322289dSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
27047322289dSmrg    }
27051d54945dSmrg
27067322289dSmrg    # Pass back the unparsed argument list
270722663e35Smrg    func_quote eval ${1+"$@"}
270822663e35Smrg    libtool_validate_options_result=$func_quote_result
2709d769e936Smrg}
27107322289dSmrgfunc_add_hook func_validate_options libtool_validate_options
27111d54945dSmrg
27121d54945dSmrg
27137322289dSmrg# Process options as early as possible so that --help and --version
27147322289dSmrg# can return quickly.
27157322289dSmrgfunc_options ${1+"$@"}
27167322289dSmrgeval set dummy "$func_options_result"; shift
27177322289dSmrg
2718ec713c28Smrg
2719ec713c28Smrg
2720d769e936Smrg## ----------- ##
2721d769e936Smrg##    Main.    ##
2722d769e936Smrg## ----------- ##
27231d54945dSmrg
27247322289dSmrgmagic='%%%MAGIC variable%%%'
27257322289dSmrgmagic_exe='%%%MAGIC EXE variable%%%'
27267322289dSmrg
27277322289dSmrg# Global variables.
27287322289dSmrgextracted_archives=
27297322289dSmrgextracted_serial=0
27307322289dSmrg
27317322289dSmrg# If this variable is set in any of the actions, the command in it
27327322289dSmrg# will be execed at the end.  This prevents here-documents from being
27337322289dSmrg# left over by shells.
27347322289dSmrgexec_cmd=
27357322289dSmrg
27367322289dSmrg
27377322289dSmrg# A function that is used when there is no print builtin or printf.
27387322289dSmrgfunc_fallback_echo ()
27397322289dSmrg{
27407322289dSmrg  eval 'cat <<_LTECHO_EOF
27417322289dSmrg$1
27427322289dSmrg_LTECHO_EOF'
27437322289dSmrg}
27447322289dSmrg
27457322289dSmrg# func_generated_by_libtool
27467322289dSmrg# True iff stdin has been generated by Libtool. This function is only
27477322289dSmrg# a basic sanity check; it will hardly flush out determined imposters.
27487322289dSmrgfunc_generated_by_libtool_p ()
27497322289dSmrg{
27507322289dSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
27517322289dSmrg}
27527322289dSmrg
2753d769e936Smrg# func_lalib_p file
27547322289dSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2755d769e936Smrg# This function is only a basic sanity check; it will hardly flush out
2756d769e936Smrg# determined imposters.
2757d769e936Smrgfunc_lalib_p ()
2758d769e936Smrg{
2759d769e936Smrg    test -f "$1" &&
27607322289dSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2761d769e936Smrg}
27621d54945dSmrg
2763d769e936Smrg# func_lalib_unsafe_p file
27647322289dSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2765d769e936Smrg# This function implements the same check as func_lalib_p without
2766d769e936Smrg# resorting to external programs.  To this end, it redirects stdin and
2767d769e936Smrg# closes it afterwards, without saving the original file descriptor.
2768d769e936Smrg# As a safety measure, use it only where a negative result would be
27697322289dSmrg# fatal anyway.  Works if 'file' does not exist.
2770d769e936Smrgfunc_lalib_unsafe_p ()
2771d769e936Smrg{
2772d769e936Smrg    lalib_p=no
2773d769e936Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2774d769e936Smrg	for lalib_p_l in 1 2 3 4
2775d769e936Smrg	do
2776d769e936Smrg	    read lalib_p_line
27777322289dSmrg	    case $lalib_p_line in
2778d769e936Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2779d769e936Smrg	    esac
2780d769e936Smrg	done
2781d769e936Smrg	exec 0<&5 5<&-
2782d769e936Smrg    fi
27837322289dSmrg    test yes = "$lalib_p"
2784d769e936Smrg}
27851d54945dSmrg
2786d769e936Smrg# func_ltwrapper_script_p file
2787d769e936Smrg# True iff FILE is a libtool wrapper script
2788d769e936Smrg# This function is only a basic sanity check; it will hardly flush out
2789d769e936Smrg# determined imposters.
2790d769e936Smrgfunc_ltwrapper_script_p ()
2791d769e936Smrg{
27927322289dSmrg    test -f "$1" &&
27937322289dSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2794d769e936Smrg}
2795ec713c28Smrg
2796d769e936Smrg# func_ltwrapper_executable_p file
2797d769e936Smrg# True iff FILE is a libtool wrapper executable
2798d769e936Smrg# This function is only a basic sanity check; it will hardly flush out
2799d769e936Smrg# determined imposters.
2800d769e936Smrgfunc_ltwrapper_executable_p ()
2801d769e936Smrg{
2802d769e936Smrg    func_ltwrapper_exec_suffix=
2803d769e936Smrg    case $1 in
2804d769e936Smrg    *.exe) ;;
2805d769e936Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
28061d54945dSmrg    esac
2807d769e936Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2808d769e936Smrg}
28091d54945dSmrg
2810d769e936Smrg# func_ltwrapper_scriptname file
2811d769e936Smrg# Assumes file is an ltwrapper_executable
2812d769e936Smrg# uses $file to determine the appropriate filename for a
2813d769e936Smrg# temporary ltwrapper_script.
2814d769e936Smrgfunc_ltwrapper_scriptname ()
2815d769e936Smrg{
2816d769e936Smrg    func_dirname_and_basename "$1" "" "."
2817d769e936Smrg    func_stripname '' '.exe' "$func_basename_result"
28187322289dSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2819d769e936Smrg}
28201d54945dSmrg
2821d769e936Smrg# func_ltwrapper_p file
2822d769e936Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2823d769e936Smrg# This function is only a basic sanity check; it will hardly flush out
2824d769e936Smrg# determined imposters.
2825d769e936Smrgfunc_ltwrapper_p ()
2826d769e936Smrg{
2827d769e936Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2828d769e936Smrg}
28291d54945dSmrg
28301d54945dSmrg
2831d769e936Smrg# func_execute_cmds commands fail_cmd
2832d769e936Smrg# Execute tilde-delimited COMMANDS.
2833d769e936Smrg# If FAIL_CMD is given, eval that upon failure.
2834d769e936Smrg# FAIL_CMD may read-access the current command in variable CMD!
2835d769e936Smrgfunc_execute_cmds ()
2836d769e936Smrg{
28377322289dSmrg    $debug_cmd
28387322289dSmrg
2839d769e936Smrg    save_ifs=$IFS; IFS='~'
2840d769e936Smrg    for cmd in $1; do
28417322289dSmrg      IFS=$sp$nl
2842d769e936Smrg      eval cmd=\"$cmd\"
28437322289dSmrg      IFS=$save_ifs
2844d769e936Smrg      func_show_eval "$cmd" "${2-:}"
28451d54945dSmrg    done
2846d769e936Smrg    IFS=$save_ifs
2847d769e936Smrg}
28481d54945dSmrg
28491d54945dSmrg
2850d769e936Smrg# func_source file
2851d769e936Smrg# Source FILE, adding directory component if necessary.
2852d769e936Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2853d769e936Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2854d769e936Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
28557322289dSmrg# 'FILE.' does not work on cygwin managed mounts.
2856d769e936Smrgfunc_source ()
2857d769e936Smrg{
28587322289dSmrg    $debug_cmd
28597322289dSmrg
2860d769e936Smrg    case $1 in
2861d769e936Smrg    */* | *\\*)	. "$1" ;;
2862d769e936Smrg    *)		. "./$1" ;;
2863d769e936Smrg    esac
2864d769e936Smrg}
28651d54945dSmrg
28661d54945dSmrg
2867d769e936Smrg# func_resolve_sysroot PATH
2868d769e936Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869d769e936Smrg# func_resolve_sysroot_result
2870d769e936Smrgfunc_resolve_sysroot ()
2871d769e936Smrg{
2872d769e936Smrg  func_resolve_sysroot_result=$1
2873d769e936Smrg  case $func_resolve_sysroot_result in
2874d769e936Smrg  =*)
2875d769e936Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876d769e936Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877d769e936Smrg    ;;
2878d769e936Smrg  esac
2879d769e936Smrg}
2880ec713c28Smrg
2881d769e936Smrg# func_replace_sysroot PATH
2882d769e936Smrg# If PATH begins with the sysroot, replace it with = and
2883d769e936Smrg# store the result into func_replace_sysroot_result.
2884d769e936Smrgfunc_replace_sysroot ()
2885d769e936Smrg{
28867322289dSmrg  case $lt_sysroot:$1 in
2887d769e936Smrg  ?*:"$lt_sysroot"*)
2888d769e936Smrg    func_stripname "$lt_sysroot" '' "$1"
28897322289dSmrg    func_replace_sysroot_result='='$func_stripname_result
2890d769e936Smrg    ;;
2891d769e936Smrg  *)
2892d769e936Smrg    # Including no sysroot.
2893d769e936Smrg    func_replace_sysroot_result=$1
2894d769e936Smrg    ;;
2895d769e936Smrg  esac
2896d769e936Smrg}
28971d54945dSmrg
2898d769e936Smrg# func_infer_tag arg
2899d769e936Smrg# Infer tagged configuration to use if any are available and
2900d769e936Smrg# if one wasn't chosen via the "--tag" command line option.
2901d769e936Smrg# Only attempt this if the compiler in the base compile
2902d769e936Smrg# command doesn't match the default compiler.
2903d769e936Smrg# arg is usually of the form 'gcc ...'
2904d769e936Smrgfunc_infer_tag ()
2905d769e936Smrg{
29067322289dSmrg    $debug_cmd
29077322289dSmrg
2908d769e936Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2909d769e936Smrg      CC_quoted=
2910d769e936Smrg      for arg in $CC; do
2911d769e936Smrg	func_append_quoted CC_quoted "$arg"
2912d769e936Smrg      done
2913d769e936Smrg      CC_expanded=`func_echo_all $CC`
2914d769e936Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2915d769e936Smrg      case $@ in
2916d769e936Smrg      # Blanks in the command may have been stripped by the calling shell,
2917d769e936Smrg      # but not from the CC environment variable when configure was run.
2918d769e936Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2919d769e936Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2920d769e936Smrg      # Blanks at the start of $base_compile will cause this to fail
2921d769e936Smrg      # if we don't check for them as well.
2922d769e936Smrg      *)
2923d769e936Smrg	for z in $available_tags; do
2924d769e936Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2925d769e936Smrg	    # Evaluate the configuration.
29267322289dSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2927d769e936Smrg	    CC_quoted=
2928d769e936Smrg	    for arg in $CC; do
2929d769e936Smrg	      # Double-quote args containing other shell metacharacters.
2930d769e936Smrg	      func_append_quoted CC_quoted "$arg"
2931d769e936Smrg	    done
2932d769e936Smrg	    CC_expanded=`func_echo_all $CC`
2933d769e936Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2934d769e936Smrg	    case "$@ " in
2935d769e936Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2936d769e936Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2937d769e936Smrg	      # The compiler in the base compile command matches
2938d769e936Smrg	      # the one in the tagged configuration.
2939d769e936Smrg	      # Assume this is the tagged configuration we want.
2940d769e936Smrg	      tagname=$z
2941d769e936Smrg	      break
2942d769e936Smrg	      ;;
2943d769e936Smrg	    esac
2944d769e936Smrg	  fi
2945d769e936Smrg	done
2946d769e936Smrg	# If $tagname still isn't set, then no tagged configuration
2947d769e936Smrg	# was found and let the user know that the "--tag" command
2948d769e936Smrg	# line option must be used.
2949d769e936Smrg	if test -z "$tagname"; then
2950d769e936Smrg	  func_echo "unable to infer tagged configuration"
29517322289dSmrg	  func_fatal_error "specify a tag with '--tag'"
2952d769e936Smrg#	else
2953d769e936Smrg#	  func_verbose "using $tagname tagged configuration"
2954d769e936Smrg	fi
2955d769e936Smrg	;;
2956d769e936Smrg      esac
29571d54945dSmrg    fi
2958d769e936Smrg}
29591d54945dSmrg
29601d54945dSmrg
29611d54945dSmrg
2962d769e936Smrg# func_write_libtool_object output_name pic_name nonpic_name
2963d769e936Smrg# Create a libtool object file (analogous to a ".la" file),
2964d769e936Smrg# but don't create it if we're doing a dry run.
2965d769e936Smrgfunc_write_libtool_object ()
2966d769e936Smrg{
29677322289dSmrg    write_libobj=$1
29687322289dSmrg    if test yes = "$build_libtool_libs"; then
29697322289dSmrg      write_lobj=\'$2\'
2970d769e936Smrg    else
2971d769e936Smrg      write_lobj=none
29721d54945dSmrg    fi
29731d54945dSmrg
29747322289dSmrg    if test yes = "$build_old_libs"; then
29757322289dSmrg      write_oldobj=\'$3\'
2976d769e936Smrg    else
2977d769e936Smrg      write_oldobj=none
29781d54945dSmrg    fi
2979ec713c28Smrg
2980d769e936Smrg    $opt_dry_run || {
2981d769e936Smrg      cat >${write_libobj}T <<EOF
2982d769e936Smrg# $write_libobj - a libtool object file
29837322289dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984ec713c28Smrg#
2985ec713c28Smrg# Please DO NOT delete this file!
2986ec713c28Smrg# It is necessary for linking the library.
2987ec713c28Smrg
2988ec713c28Smrg# Name of the PIC object.
2989d769e936Smrgpic_object=$write_lobj
29901d54945dSmrg
2991d769e936Smrg# Name of the non-PIC object
2992d769e936Smrgnon_pic_object=$write_oldobj
29931d54945dSmrg
2994d769e936SmrgEOF
29957322289dSmrg      $MV "${write_libobj}T" "$write_libobj"
2996d769e936Smrg    }
2997d769e936Smrg}
29981d54945dSmrg
29991d54945dSmrg
3000d769e936Smrg##################################################
3001d769e936Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002d769e936Smrg##################################################
30031d54945dSmrg
3004d769e936Smrg# func_convert_core_file_wine_to_w32 ARG
3005d769e936Smrg# Helper function used by file name conversion functions when $build is *nix,
3006d769e936Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007d769e936Smrg# correctly configured wine environment available, with the winepath program
3008d769e936Smrg# in $build's $PATH.
3009d769e936Smrg#
3010d769e936Smrg# ARG is the $build file name to be converted to w32 format.
3011d769e936Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012d769e936Smrg# be empty on error (or when ARG is empty)
3013d769e936Smrgfunc_convert_core_file_wine_to_w32 ()
3014d769e936Smrg{
30157322289dSmrg  $debug_cmd
30167322289dSmrg
30177322289dSmrg  func_convert_core_file_wine_to_w32_result=$1
3018d769e936Smrg  if test -n "$1"; then
3019d769e936Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020d769e936Smrg    # are forced to check the contents of stdout. On the other hand, if the
3021d769e936Smrg    # command is not found, the shell will set an exit code of 127 and print
3022d769e936Smrg    # *an error message* to stdout. So we must check for both error code of
3023d769e936Smrg    # zero AND non-empty stdout, which explains the odd construction:
3024d769e936Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
30257322289dSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026d769e936Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
30277322289dSmrg        $SED -e "$sed_naive_backslashify"`
3028d769e936Smrg    else
3029d769e936Smrg      func_convert_core_file_wine_to_w32_result=
3030d769e936Smrg    fi
3031d769e936Smrg  fi
3032d769e936Smrg}
3033d769e936Smrg# end: func_convert_core_file_wine_to_w32
3034ec713c28Smrg
3035d769e936Smrg
3036d769e936Smrg# func_convert_core_path_wine_to_w32 ARG
3037d769e936Smrg# Helper function used by path conversion functions when $build is *nix, and
3038d769e936Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039d769e936Smrg# configured wine environment available, with the winepath program in $build's
3040d769e936Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041d769e936Smrg#
3042d769e936Smrg# ARG is path to be converted from $build format to win32.
3043d769e936Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044d769e936Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045d769e936Smrg# are convertible, then the result may be empty.
3046d769e936Smrgfunc_convert_core_path_wine_to_w32 ()
3047d769e936Smrg{
30487322289dSmrg  $debug_cmd
30497322289dSmrg
3050d769e936Smrg  # unfortunately, winepath doesn't convert paths, only file names
30517322289dSmrg  func_convert_core_path_wine_to_w32_result=
3052d769e936Smrg  if test -n "$1"; then
3053d769e936Smrg    oldIFS=$IFS
3054d769e936Smrg    IFS=:
3055d769e936Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056d769e936Smrg      IFS=$oldIFS
3057d769e936Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
30587322289dSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059d769e936Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
30607322289dSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061d769e936Smrg        else
3062d769e936Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063d769e936Smrg        fi
3064ec713c28Smrg      fi
3065d769e936Smrg    done
3066d769e936Smrg    IFS=$oldIFS
3067d769e936Smrg  fi
3068d769e936Smrg}
3069d769e936Smrg# end: func_convert_core_path_wine_to_w32
3070d769e936Smrg
3071d769e936Smrg
3072d769e936Smrg# func_cygpath ARGS...
3073d769e936Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074d769e936Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075d769e936Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076d769e936Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077d769e936Smrg# file name or path is assumed to be in w32 format, as previously converted
3078d769e936Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079d769e936Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080d769e936Smrg# Cygwin format). Returns an empty string on error.
3081d769e936Smrg#
3082d769e936Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083d769e936Smrg# be converted.
3084d769e936Smrg#
3085d769e936Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086d769e936Smrg# environment variable; do not put it in $PATH.
3087d769e936Smrgfunc_cygpath ()
3088d769e936Smrg{
30897322289dSmrg  $debug_cmd
30907322289dSmrg
3091d769e936Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092d769e936Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093d769e936Smrg    if test "$?" -ne 0; then
3094d769e936Smrg      # on failure, ensure result is empty
3095d769e936Smrg      func_cygpath_result=
3096d769e936Smrg    fi
3097d769e936Smrg  else
3098d769e936Smrg    func_cygpath_result=
30997322289dSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100d769e936Smrg  fi
3101d769e936Smrg}
3102d769e936Smrg#end: func_cygpath
31031d54945dSmrg
31041d54945dSmrg
3105d769e936Smrg# func_convert_core_msys_to_w32 ARG
3106d769e936Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107d769e936Smrg# result in func_convert_core_msys_to_w32_result.
3108d769e936Smrgfunc_convert_core_msys_to_w32 ()
3109d769e936Smrg{
31107322289dSmrg  $debug_cmd
31117322289dSmrg
3112d769e936Smrg  # awkward: cmd appends spaces to result
3113d769e936Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
31147322289dSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115d769e936Smrg}
3116d769e936Smrg#end: func_convert_core_msys_to_w32
31171d54945dSmrg
31181d54945dSmrg
3119d769e936Smrg# func_convert_file_check ARG1 ARG2
3120d769e936Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121d769e936Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122d769e936Smrg# func_to_host_file_result to ARG1).
3123d769e936Smrgfunc_convert_file_check ()
3124d769e936Smrg{
31257322289dSmrg  $debug_cmd
31267322289dSmrg
31277322289dSmrg  if test -z "$2" && test -n "$1"; then
3128d769e936Smrg    func_error "Could not determine host file name corresponding to"
31297322289dSmrg    func_error "  '$1'"
3130d769e936Smrg    func_error "Continuing, but uninstalled executables may not work."
3131d769e936Smrg    # Fallback:
31327322289dSmrg    func_to_host_file_result=$1
3133d769e936Smrg  fi
3134d769e936Smrg}
3135d769e936Smrg# end func_convert_file_check
31361d54945dSmrg
31371d54945dSmrg
3138d769e936Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139d769e936Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140d769e936Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141d769e936Smrg# func_to_host_file_result to a simplistic fallback value (see below).
3142d769e936Smrgfunc_convert_path_check ()
3143d769e936Smrg{
31447322289dSmrg  $debug_cmd
31457322289dSmrg
3146d769e936Smrg  if test -z "$4" && test -n "$3"; then
3147d769e936Smrg    func_error "Could not determine the host path corresponding to"
31487322289dSmrg    func_error "  '$3'"
3149d769e936Smrg    func_error "Continuing, but uninstalled executables may not work."
3150d769e936Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151d769e936Smrg    # should not be "improved".  See libtool.info.
3152d769e936Smrg    if test "x$1" != "x$2"; then
3153d769e936Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154d769e936Smrg      func_to_host_path_result=`echo "$3" |
3155d769e936Smrg        $SED -e "$lt_replace_pathsep_chars"`
3156d769e936Smrg    else
31577322289dSmrg      func_to_host_path_result=$3
3158d769e936Smrg    fi
3159d769e936Smrg  fi
3160d769e936Smrg}
3161d769e936Smrg# end func_convert_path_check
3162ec713c28Smrg
3163ec713c28Smrg
3164d769e936Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165d769e936Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166d769e936Smrg# and appending REPL if ORIG matches BACKPAT.
3167d769e936Smrgfunc_convert_path_front_back_pathsep ()
3168d769e936Smrg{
31697322289dSmrg  $debug_cmd
31707322289dSmrg
3171d769e936Smrg  case $4 in
31727322289dSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173d769e936Smrg    ;;
3174d769e936Smrg  esac
3175d769e936Smrg  case $4 in
3176d769e936Smrg  $2 ) func_append func_to_host_path_result "$3"
3177d769e936Smrg    ;;
3178d769e936Smrg  esac
3179d769e936Smrg}
3180d769e936Smrg# end func_convert_path_front_back_pathsep
3181ec713c28Smrg
31821d54945dSmrg
3183d769e936Smrg##################################################
3184d769e936Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185d769e936Smrg##################################################
31867322289dSmrg# invoked via '$to_host_file_cmd ARG'
3187d769e936Smrg#
3188d769e936Smrg# In each case, ARG is the path to be converted from $build to $host format.
3189d769e936Smrg# Result will be available in $func_to_host_file_result.
31901d54945dSmrg
31911d54945dSmrg
3192d769e936Smrg# func_to_host_file ARG
3193d769e936Smrg# Converts the file name ARG from $build format to $host format. Return result
3194d769e936Smrg# in func_to_host_file_result.
3195d769e936Smrgfunc_to_host_file ()
3196d769e936Smrg{
31977322289dSmrg  $debug_cmd
31987322289dSmrg
3199d769e936Smrg  $to_host_file_cmd "$1"
3200d769e936Smrg}
3201d769e936Smrg# end func_to_host_file
32021d54945dSmrg
32031d54945dSmrg
3204d769e936Smrg# func_to_tool_file ARG LAZY
3205d769e936Smrg# converts the file name ARG from $build format to toolchain format. Return
3206d769e936Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207d769e936Smrg# in (the comma separated) LAZY, no conversion takes place.
3208d769e936Smrgfunc_to_tool_file ()
3209d769e936Smrg{
32107322289dSmrg  $debug_cmd
32117322289dSmrg
3212d769e936Smrg  case ,$2, in
3213d769e936Smrg    *,"$to_tool_file_cmd",*)
3214d769e936Smrg      func_to_tool_file_result=$1
3215d769e936Smrg      ;;
3216d769e936Smrg    *)
3217d769e936Smrg      $to_tool_file_cmd "$1"
3218d769e936Smrg      func_to_tool_file_result=$func_to_host_file_result
3219d769e936Smrg      ;;
3220d769e936Smrg  esac
3221d769e936Smrg}
3222d769e936Smrg# end func_to_tool_file
32231d54945dSmrg
32241d54945dSmrg
3225d769e936Smrg# func_convert_file_noop ARG
3226d769e936Smrg# Copy ARG to func_to_host_file_result.
3227d769e936Smrgfunc_convert_file_noop ()
3228d769e936Smrg{
32297322289dSmrg  func_to_host_file_result=$1
3230d769e936Smrg}
3231d769e936Smrg# end func_convert_file_noop
3232ec713c28Smrg
3233ec713c28Smrg
3234d769e936Smrg# func_convert_file_msys_to_w32 ARG
3235d769e936Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236d769e936Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237d769e936Smrg# func_to_host_file_result.
3238d769e936Smrgfunc_convert_file_msys_to_w32 ()
3239d769e936Smrg{
32407322289dSmrg  $debug_cmd
32417322289dSmrg
32427322289dSmrg  func_to_host_file_result=$1
3243d769e936Smrg  if test -n "$1"; then
3244d769e936Smrg    func_convert_core_msys_to_w32 "$1"
32457322289dSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246d769e936Smrg  fi
3247d769e936Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248d769e936Smrg}
3249d769e936Smrg# end func_convert_file_msys_to_w32
3250ec713c28Smrg
32511d54945dSmrg
3252d769e936Smrg# func_convert_file_cygwin_to_w32 ARG
3253d769e936Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254d769e936Smrg# func_to_host_file_result.
3255d769e936Smrgfunc_convert_file_cygwin_to_w32 ()
3256d769e936Smrg{
32577322289dSmrg  $debug_cmd
32587322289dSmrg
32597322289dSmrg  func_to_host_file_result=$1
3260d769e936Smrg  if test -n "$1"; then
3261d769e936Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262d769e936Smrg    # LT_CYGPATH in this case.
3263d769e936Smrg    func_to_host_file_result=`cygpath -m "$1"`
3264d769e936Smrg  fi
3265d769e936Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266d769e936Smrg}
3267d769e936Smrg# end func_convert_file_cygwin_to_w32
32681d54945dSmrg
32691d54945dSmrg
3270d769e936Smrg# func_convert_file_nix_to_w32 ARG
3271d769e936Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272d769e936Smrg# and a working winepath. Returns result in func_to_host_file_result.
3273d769e936Smrgfunc_convert_file_nix_to_w32 ()
3274d769e936Smrg{
32757322289dSmrg  $debug_cmd
32767322289dSmrg
32777322289dSmrg  func_to_host_file_result=$1
3278d769e936Smrg  if test -n "$1"; then
3279d769e936Smrg    func_convert_core_file_wine_to_w32 "$1"
32807322289dSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281d769e936Smrg  fi
3282d769e936Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283d769e936Smrg}
3284d769e936Smrg# end func_convert_file_nix_to_w32
32851d54945dSmrg
32861d54945dSmrg
3287d769e936Smrg# func_convert_file_msys_to_cygwin ARG
3288d769e936Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289d769e936Smrg# Returns result in func_to_host_file_result.
3290d769e936Smrgfunc_convert_file_msys_to_cygwin ()
3291d769e936Smrg{
32927322289dSmrg  $debug_cmd
32937322289dSmrg
32947322289dSmrg  func_to_host_file_result=$1
3295d769e936Smrg  if test -n "$1"; then
3296d769e936Smrg    func_convert_core_msys_to_w32 "$1"
3297d769e936Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
32987322289dSmrg    func_to_host_file_result=$func_cygpath_result
3299d769e936Smrg  fi
3300d769e936Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301d769e936Smrg}
3302d769e936Smrg# end func_convert_file_msys_to_cygwin
33031d54945dSmrg
33041d54945dSmrg
3305d769e936Smrg# func_convert_file_nix_to_cygwin ARG
3306d769e936Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307d769e936Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308d769e936Smrg# in func_to_host_file_result.
3309d769e936Smrgfunc_convert_file_nix_to_cygwin ()
3310d769e936Smrg{
33117322289dSmrg  $debug_cmd
33127322289dSmrg
33137322289dSmrg  func_to_host_file_result=$1
3314d769e936Smrg  if test -n "$1"; then
3315d769e936Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316d769e936Smrg    func_convert_core_file_wine_to_w32 "$1"
3317d769e936Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
33187322289dSmrg    func_to_host_file_result=$func_cygpath_result
3319d769e936Smrg  fi
3320d769e936Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321d769e936Smrg}
3322d769e936Smrg# end func_convert_file_nix_to_cygwin
33231d54945dSmrg
33241d54945dSmrg
3325d769e936Smrg#############################################
3326d769e936Smrg# $build to $host PATH CONVERSION FUNCTIONS #
3327d769e936Smrg#############################################
33287322289dSmrg# invoked via '$to_host_path_cmd ARG'
3329d769e936Smrg#
3330d769e936Smrg# In each case, ARG is the path to be converted from $build to $host format.
3331d769e936Smrg# The result will be available in $func_to_host_path_result.
3332d769e936Smrg#
3333d769e936Smrg# Path separators are also converted from $build format to $host format.  If
3334d769e936Smrg# ARG begins or ends with a path separator character, it is preserved (but
3335d769e936Smrg# converted to $host format) on output.
3336d769e936Smrg#
3337d769e936Smrg# All path conversion functions are named using the following convention:
3338d769e936Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339d769e936Smrg#   path conversion function         : func_convert_path_X_to_Y ()
3340d769e936Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341d769e936Smrg# same.  If conversion functions are added for new $build/$host combinations,
3342d769e936Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343d769e936Smrg# will break.
3344d769e936Smrg
3345d769e936Smrg
3346d769e936Smrg# func_init_to_host_path_cmd
3347d769e936Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348d769e936Smrg# appropriate value, based on the value of $to_host_file_cmd.
3349d769e936Smrgto_host_path_cmd=
3350d769e936Smrgfunc_init_to_host_path_cmd ()
3351d769e936Smrg{
33527322289dSmrg  $debug_cmd
33537322289dSmrg
3354d769e936Smrg  if test -z "$to_host_path_cmd"; then
3355d769e936Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
33567322289dSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357d769e936Smrg  fi
3358d769e936Smrg}
33591d54945dSmrg
33601d54945dSmrg
3361d769e936Smrg# func_to_host_path ARG
3362d769e936Smrg# Converts the path ARG from $build format to $host format. Return result
3363d769e936Smrg# in func_to_host_path_result.
3364d769e936Smrgfunc_to_host_path ()
3365d769e936Smrg{
33667322289dSmrg  $debug_cmd
33677322289dSmrg
3368d769e936Smrg  func_init_to_host_path_cmd
3369d769e936Smrg  $to_host_path_cmd "$1"
3370d769e936Smrg}
3371d769e936Smrg# end func_to_host_path
33721d54945dSmrg
33731d54945dSmrg
3374d769e936Smrg# func_convert_path_noop ARG
3375d769e936Smrg# Copy ARG to func_to_host_path_result.
3376d769e936Smrgfunc_convert_path_noop ()
3377d769e936Smrg{
33787322289dSmrg  func_to_host_path_result=$1
3379d769e936Smrg}
3380d769e936Smrg# end func_convert_path_noop
33811d54945dSmrg
33821d54945dSmrg
3383d769e936Smrg# func_convert_path_msys_to_w32 ARG
3384d769e936Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385d769e936Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386d769e936Smrg# func_to_host_path_result.
3387d769e936Smrgfunc_convert_path_msys_to_w32 ()
3388d769e936Smrg{
33897322289dSmrg  $debug_cmd
33907322289dSmrg
33917322289dSmrg  func_to_host_path_result=$1
3392d769e936Smrg  if test -n "$1"; then
3393d769e936Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394d769e936Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395d769e936Smrg    # and winepath ignores them completely.
3396d769e936Smrg    func_stripname : : "$1"
3397d769e936Smrg    func_to_host_path_tmp1=$func_stripname_result
3398d769e936Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
33997322289dSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400d769e936Smrg    func_convert_path_check : ";" \
3401d769e936Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402d769e936Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403d769e936Smrg  fi
3404d769e936Smrg}
3405d769e936Smrg# end func_convert_path_msys_to_w32
34061d54945dSmrg
34071d54945dSmrg
3408d769e936Smrg# func_convert_path_cygwin_to_w32 ARG
3409d769e936Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410d769e936Smrg# func_to_host_file_result.
3411d769e936Smrgfunc_convert_path_cygwin_to_w32 ()
3412d769e936Smrg{
34137322289dSmrg  $debug_cmd
34147322289dSmrg
34157322289dSmrg  func_to_host_path_result=$1
3416d769e936Smrg  if test -n "$1"; then
3417d769e936Smrg    # See func_convert_path_msys_to_w32:
3418d769e936Smrg    func_stripname : : "$1"
3419d769e936Smrg    func_to_host_path_tmp1=$func_stripname_result
3420d769e936Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421d769e936Smrg    func_convert_path_check : ";" \
3422d769e936Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423d769e936Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424d769e936Smrg  fi
3425d769e936Smrg}
3426d769e936Smrg# end func_convert_path_cygwin_to_w32
34271d54945dSmrg
34281d54945dSmrg
3429d769e936Smrg# func_convert_path_nix_to_w32 ARG
3430d769e936Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431d769e936Smrg# a working winepath.  Returns result in func_to_host_file_result.
3432d769e936Smrgfunc_convert_path_nix_to_w32 ()
3433d769e936Smrg{
34347322289dSmrg  $debug_cmd
34357322289dSmrg
34367322289dSmrg  func_to_host_path_result=$1
3437d769e936Smrg  if test -n "$1"; then
3438d769e936Smrg    # See func_convert_path_msys_to_w32:
3439d769e936Smrg    func_stripname : : "$1"
3440d769e936Smrg    func_to_host_path_tmp1=$func_stripname_result
3441d769e936Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34427322289dSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443d769e936Smrg    func_convert_path_check : ";" \
3444d769e936Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445d769e936Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446d769e936Smrg  fi
3447d769e936Smrg}
3448d769e936Smrg# end func_convert_path_nix_to_w32
34491d54945dSmrg
34501d54945dSmrg
3451d769e936Smrg# func_convert_path_msys_to_cygwin ARG
3452d769e936Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453d769e936Smrg# Returns result in func_to_host_file_result.
3454d769e936Smrgfunc_convert_path_msys_to_cygwin ()
3455d769e936Smrg{
34567322289dSmrg  $debug_cmd
34577322289dSmrg
34587322289dSmrg  func_to_host_path_result=$1
3459d769e936Smrg  if test -n "$1"; then
3460d769e936Smrg    # See func_convert_path_msys_to_w32:
3461d769e936Smrg    func_stripname : : "$1"
3462d769e936Smrg    func_to_host_path_tmp1=$func_stripname_result
3463d769e936Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464d769e936Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
34657322289dSmrg    func_to_host_path_result=$func_cygpath_result
3466d769e936Smrg    func_convert_path_check : : \
3467d769e936Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468d769e936Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469d769e936Smrg  fi
3470d769e936Smrg}
3471d769e936Smrg# end func_convert_path_msys_to_cygwin
34721d54945dSmrg
34731d54945dSmrg
3474d769e936Smrg# func_convert_path_nix_to_cygwin ARG
3475d769e936Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476d769e936Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477d769e936Smrg# func_to_host_file_result.
3478d769e936Smrgfunc_convert_path_nix_to_cygwin ()
3479d769e936Smrg{
34807322289dSmrg  $debug_cmd
34817322289dSmrg
34827322289dSmrg  func_to_host_path_result=$1
3483d769e936Smrg  if test -n "$1"; then
3484d769e936Smrg    # Remove leading and trailing path separator characters from
3485d769e936Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486d769e936Smrg    # into '.;' and ';.', and winepath ignores them completely.
3487d769e936Smrg    func_stripname : : "$1"
3488d769e936Smrg    func_to_host_path_tmp1=$func_stripname_result
3489d769e936Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490d769e936Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
34917322289dSmrg    func_to_host_path_result=$func_cygpath_result
3492d769e936Smrg    func_convert_path_check : : \
3493d769e936Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494d769e936Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495d769e936Smrg  fi
3496d769e936Smrg}
3497d769e936Smrg# end func_convert_path_nix_to_cygwin
34981d54945dSmrg
34991d54945dSmrg
35007322289dSmrg# func_dll_def_p FILE
35017322289dSmrg# True iff FILE is a Windows DLL '.def' file.
35027322289dSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
35037322289dSmrgfunc_dll_def_p ()
35047322289dSmrg{
35057322289dSmrg  $debug_cmd
35067322289dSmrg
35077322289dSmrg  func_dll_def_p_tmp=`$SED -n \
35087322289dSmrg    -e 's/^[	 ]*//' \
35097322289dSmrg    -e '/^\(;.*\)*$/d' \
35107322289dSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
35117322289dSmrg    -e q \
35127322289dSmrg    "$1"`
35137322289dSmrg  test DEF = "$func_dll_def_p_tmp"
35147322289dSmrg}
35157322289dSmrg
35167322289dSmrg
3517d769e936Smrg# func_mode_compile arg...
3518d769e936Smrgfunc_mode_compile ()
3519d769e936Smrg{
35207322289dSmrg    $debug_cmd
35217322289dSmrg
3522d769e936Smrg    # Get the compilation command and the source file.
3523d769e936Smrg    base_compile=
35247322289dSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3525d769e936Smrg    suppress_opt=yes
3526d769e936Smrg    suppress_output=
3527d769e936Smrg    arg_mode=normal
3528d769e936Smrg    libobj=
3529d769e936Smrg    later=
3530d769e936Smrg    pie_flag=
3531d769e936Smrg
3532d769e936Smrg    for arg
3533d769e936Smrg    do
3534d769e936Smrg      case $arg_mode in
3535d769e936Smrg      arg  )
3536d769e936Smrg	# do not "continue".  Instead, add this to base_compile
35377322289dSmrg	lastarg=$arg
3538d769e936Smrg	arg_mode=normal
3539d769e936Smrg	;;
3540d769e936Smrg
3541d769e936Smrg      target )
35427322289dSmrg	libobj=$arg
3543d769e936Smrg	arg_mode=normal
3544d769e936Smrg	continue
3545d769e936Smrg	;;
3546d769e936Smrg
3547d769e936Smrg      normal )
3548d769e936Smrg	# Accept any command-line options.
3549d769e936Smrg	case $arg in
3550d769e936Smrg	-o)
3551d769e936Smrg	  test -n "$libobj" && \
35527322289dSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3553d769e936Smrg	  arg_mode=target
3554ec713c28Smrg	  continue
3555ec713c28Smrg	  ;;
3556d769e936Smrg
3557d769e936Smrg	-pie | -fpie | -fPIE)
3558d769e936Smrg          func_append pie_flag " $arg"
3559ec713c28Smrg	  continue
3560ec713c28Smrg	  ;;
3561d769e936Smrg
3562d769e936Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563d769e936Smrg	  func_append later " $arg"
3564ec713c28Smrg	  continue
3565ec713c28Smrg	  ;;
3566d769e936Smrg
3567d769e936Smrg	-no-suppress)
3568d769e936Smrg	  suppress_opt=no
3569ec713c28Smrg	  continue
3570ec713c28Smrg	  ;;
35711d54945dSmrg
3572d769e936Smrg	-Xcompiler)
3573d769e936Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574d769e936Smrg	  continue      #  The current "srcfile" will either be retained or
3575d769e936Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
35761d54945dSmrg
3577d769e936Smrg	-Wc,*)
3578d769e936Smrg	  func_stripname '-Wc,' '' "$arg"
3579d769e936Smrg	  args=$func_stripname_result
3580d769e936Smrg	  lastarg=
35817322289dSmrg	  save_ifs=$IFS; IFS=,
3582d769e936Smrg	  for arg in $args; do
35837322289dSmrg	    IFS=$save_ifs
3584d769e936Smrg	    func_append_quoted lastarg "$arg"
3585d769e936Smrg	  done
35867322289dSmrg	  IFS=$save_ifs
3587d769e936Smrg	  func_stripname ' ' '' "$lastarg"
3588d769e936Smrg	  lastarg=$func_stripname_result
35891d54945dSmrg
3590d769e936Smrg	  # Add the arguments to base_compile.
3591d769e936Smrg	  func_append base_compile " $lastarg"
3592d769e936Smrg	  continue
3593d769e936Smrg	  ;;
35941d54945dSmrg
3595d769e936Smrg	*)
3596d769e936Smrg	  # Accept the current argument as the source file.
3597d769e936Smrg	  # The previous "srcfile" becomes the current argument.
3598d769e936Smrg	  #
35997322289dSmrg	  lastarg=$srcfile
36007322289dSmrg	  srcfile=$arg
3601d769e936Smrg	  ;;
3602d769e936Smrg	esac  #  case $arg
3603ec713c28Smrg	;;
3604d769e936Smrg      esac    #  case $arg_mode
36051d54945dSmrg
3606d769e936Smrg      # Aesthetically quote the previous argument.
3607d769e936Smrg      func_append_quoted base_compile "$lastarg"
3608d769e936Smrg    done # for arg
36091d54945dSmrg
3610d769e936Smrg    case $arg_mode in
3611d769e936Smrg    arg)
3612d769e936Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613d769e936Smrg      ;;
3614d769e936Smrg    target)
36157322289dSmrg      func_fatal_error "you must specify a target with '-o'"
3616d769e936Smrg      ;;
3617d769e936Smrg    *)
3618d769e936Smrg      # Get the name of the library object.
3619d769e936Smrg      test -z "$libobj" && {
3620d769e936Smrg	func_basename "$srcfile"
36217322289dSmrg	libobj=$func_basename_result
3622d769e936Smrg      }
3623d769e936Smrg      ;;
3624d769e936Smrg    esac
36251d54945dSmrg
3626d769e936Smrg    # Recognize several different file suffixes.
3627d769e936Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3628d769e936Smrg    case $libobj in
3629d769e936Smrg    *.[cCFSifmso] | \
3630d769e936Smrg    *.ada | *.adb | *.ads | *.asm | \
3631d769e936Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632d769e936Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3633d769e936Smrg      func_xform "$libobj"
3634d769e936Smrg      libobj=$func_xform_result
3635d769e936Smrg      ;;
3636d769e936Smrg    esac
36371d54945dSmrg
3638d769e936Smrg    case $libobj in
3639d769e936Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640d769e936Smrg    *)
36417322289dSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642d769e936Smrg      ;;
3643d769e936Smrg    esac
36441d54945dSmrg
3645d769e936Smrg    func_infer_tag $base_compile
36461d54945dSmrg
3647d769e936Smrg    for arg in $later; do
3648d769e936Smrg      case $arg in
3649d769e936Smrg      -shared)
36507322289dSmrg	test yes = "$build_libtool_libs" \
36517322289dSmrg	  || func_fatal_configuration "cannot build a shared library"
3652d769e936Smrg	build_old_libs=no
3653ec713c28Smrg	continue
3654ec713c28Smrg	;;
36551d54945dSmrg
3656d769e936Smrg      -static)
3657d769e936Smrg	build_libtool_libs=no
3658d769e936Smrg	build_old_libs=yes
3659ec713c28Smrg	continue
3660ec713c28Smrg	;;
36611d54945dSmrg
3662d769e936Smrg      -prefer-pic)
3663d769e936Smrg	pic_mode=yes
3664ec713c28Smrg	continue
3665ec713c28Smrg	;;
36661d54945dSmrg
3667d769e936Smrg      -prefer-non-pic)
3668d769e936Smrg	pic_mode=no
3669ec713c28Smrg	continue
36701d54945dSmrg	;;
3671d769e936Smrg      esac
3672d769e936Smrg    done
36731d54945dSmrg
367422663e35Smrg    func_quote_arg pretty "$libobj"
367522663e35Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3676d769e936Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
36777322289dSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3678d769e936Smrg    func_dirname_and_basename "$obj" "/" ""
36797322289dSmrg    objname=$func_basename_result
36807322289dSmrg    xdir=$func_dirname_result
36817322289dSmrg    lobj=$xdir$objdir/$objname
36821d54945dSmrg
3683d769e936Smrg    test -z "$base_compile" && \
3684d769e936Smrg      func_fatal_help "you must specify a compilation command"
36851d54945dSmrg
3686d769e936Smrg    # Delete any leftover library objects.
36877322289dSmrg    if test yes = "$build_old_libs"; then
3688d769e936Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3689d769e936Smrg    else
3690d769e936Smrg      removelist="$lobj $libobj ${libobj}T"
3691d769e936Smrg    fi
36921d54945dSmrg
3693d769e936Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694d769e936Smrg    case $host_os in
3695d769e936Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696d769e936Smrg      pic_mode=default
3697d769e936Smrg      ;;
3698d769e936Smrg    esac
36997322289dSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700d769e936Smrg      # non-PIC code in shared libraries is not supported
3701d769e936Smrg      pic_mode=default
3702d769e936Smrg    fi
37031d54945dSmrg
3704d769e936Smrg    # Calculate the filename of the output object if compiler does
3705d769e936Smrg    # not support -o with -c
37067322289dSmrg    if test no = "$compiler_c_o"; then
37077322289dSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
37087322289dSmrg      lockfile=$output_obj.lock
3709d769e936Smrg    else
3710d769e936Smrg      output_obj=
3711d769e936Smrg      need_locks=no
3712d769e936Smrg      lockfile=
3713d769e936Smrg    fi
37141d54945dSmrg
3715d769e936Smrg    # Lock this critical section if it is needed
3716d769e936Smrg    # We use this script file to make the link, it avoids creating a new file
37177322289dSmrg    if test yes = "$need_locks"; then
3718d769e936Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3719d769e936Smrg	func_echo "Waiting for $lockfile to be removed"
3720d769e936Smrg	sleep 2
3721d769e936Smrg      done
37227322289dSmrg    elif test warn = "$need_locks"; then
3723d769e936Smrg      if test -f "$lockfile"; then
3724d769e936Smrg	$ECHO "\
3725d769e936Smrg*** ERROR, $lockfile exists and contains:
3726d769e936Smrg`cat $lockfile 2>/dev/null`
37271d54945dSmrg
3728d769e936SmrgThis indicates that another process is trying to use the same
3729d769e936Smrgtemporary object file, and libtool could not work around it because
37307322289dSmrgyour compiler does not support '-c' and '-o' together.  If you
3731d769e936Smrgrepeat this compilation, it may succeed, by chance, but you had better
3732d769e936Smrgavoid parallel builds (make -j) in this platform, or get a better
3733d769e936Smrgcompiler."
37341d54945dSmrg
3735d769e936Smrg	$opt_dry_run || $RM $removelist
3736d769e936Smrg	exit $EXIT_FAILURE
3737d769e936Smrg      fi
3738d769e936Smrg      func_append removelist " $output_obj"
3739d769e936Smrg      $ECHO "$srcfile" > "$lockfile"
3740d769e936Smrg    fi
37411d54945dSmrg
3742d769e936Smrg    $opt_dry_run || $RM $removelist
3743d769e936Smrg    func_append removelist " $lockfile"
3744d769e936Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
37451d54945dSmrg
3746d769e936Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747d769e936Smrg    srcfile=$func_to_tool_file_result
374822663e35Smrg    func_quote_arg pretty "$srcfile"
374922663e35Smrg    qsrcfile=$func_quote_arg_result
37501d54945dSmrg
3751d769e936Smrg    # Only build a PIC object if we are building libtool libraries.
37527322289dSmrg    if test yes = "$build_libtool_libs"; then
3753d769e936Smrg      # Without this assignment, base_compile gets emptied.
3754d769e936Smrg      fbsd_hideous_sh_bug=$base_compile
37551d54945dSmrg
37567322289dSmrg      if test no != "$pic_mode"; then
3757d769e936Smrg	command="$base_compile $qsrcfile $pic_flag"
3758d769e936Smrg      else
3759d769e936Smrg	# Don't build PIC code
3760d769e936Smrg	command="$base_compile $qsrcfile"
3761d769e936Smrg      fi
37621d54945dSmrg
3763d769e936Smrg      func_mkdir_p "$xdir$objdir"
37641d54945dSmrg
3765d769e936Smrg      if test -z "$output_obj"; then
3766d769e936Smrg	# Place PIC objects in $objdir
3767d769e936Smrg	func_append command " -o $lobj"
3768d769e936Smrg      fi
37691d54945dSmrg
3770d769e936Smrg      func_show_eval_locale "$command"	\
3771d769e936Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
37721d54945dSmrg
37737322289dSmrg      if test warn = "$need_locks" &&
3774d769e936Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3775d769e936Smrg	$ECHO "\
3776d769e936Smrg*** ERROR, $lockfile contains:
3777d769e936Smrg`cat $lockfile 2>/dev/null`
3778ec713c28Smrg
3779d769e936Smrgbut it should contain:
3780d769e936Smrg$srcfile
3781ec713c28Smrg
3782d769e936SmrgThis indicates that another process is trying to use the same
3783d769e936Smrgtemporary object file, and libtool could not work around it because
37847322289dSmrgyour compiler does not support '-c' and '-o' together.  If you
3785d769e936Smrgrepeat this compilation, it may succeed, by chance, but you had better
3786d769e936Smrgavoid parallel builds (make -j) in this platform, or get a better
3787d769e936Smrgcompiler."
37881d54945dSmrg
3789d769e936Smrg	$opt_dry_run || $RM $removelist
3790d769e936Smrg	exit $EXIT_FAILURE
3791d769e936Smrg      fi
37921d54945dSmrg
3793d769e936Smrg      # Just move the object if needed, then go on to compile the next one
3794d769e936Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3795d769e936Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3796d769e936Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797d769e936Smrg      fi
37981d54945dSmrg
3799d769e936Smrg      # Allow error messages only from the first compilation.
38007322289dSmrg      if test yes = "$suppress_opt"; then
3801d769e936Smrg	suppress_output=' >/dev/null 2>&1'
3802d769e936Smrg      fi
3803d769e936Smrg    fi
38041d54945dSmrg
3805d769e936Smrg    # Only build a position-dependent object if we build old libraries.
38067322289dSmrg    if test yes = "$build_old_libs"; then
38077322289dSmrg      if test yes != "$pic_mode"; then
3808d769e936Smrg	# Don't build PIC code
3809d769e936Smrg	command="$base_compile $qsrcfile$pie_flag"
3810d769e936Smrg      else
3811d769e936Smrg	command="$base_compile $qsrcfile $pic_flag"
3812d769e936Smrg      fi
38137322289dSmrg      if test yes = "$compiler_c_o"; then
3814d769e936Smrg	func_append command " -o $obj"
3815d769e936Smrg      fi
38161d54945dSmrg
3817d769e936Smrg      # Suppress compiler output if we already did a PIC compilation.
3818d769e936Smrg      func_append command "$suppress_output"
3819d769e936Smrg      func_show_eval_locale "$command" \
3820d769e936Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
38211d54945dSmrg
38227322289dSmrg      if test warn = "$need_locks" &&
3823d769e936Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3824d769e936Smrg	$ECHO "\
3825d769e936Smrg*** ERROR, $lockfile contains:
3826d769e936Smrg`cat $lockfile 2>/dev/null`
38271d54945dSmrg
3828d769e936Smrgbut it should contain:
3829d769e936Smrg$srcfile
3830786a6f21Smrg
3831d769e936SmrgThis indicates that another process is trying to use the same
3832d769e936Smrgtemporary object file, and libtool could not work around it because
38337322289dSmrgyour compiler does not support '-c' and '-o' together.  If you
3834d769e936Smrgrepeat this compilation, it may succeed, by chance, but you had better
3835d769e936Smrgavoid parallel builds (make -j) in this platform, or get a better
3836d769e936Smrgcompiler."
3837786a6f21Smrg
3838d769e936Smrg	$opt_dry_run || $RM $removelist
3839d769e936Smrg	exit $EXIT_FAILURE
3840d769e936Smrg      fi
3841786a6f21Smrg
3842d769e936Smrg      # Just move the object if needed
3843d769e936Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3844d769e936Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3845d769e936Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846d769e936Smrg      fi
3847d769e936Smrg    fi
3848786a6f21Smrg
3849d769e936Smrg    $opt_dry_run || {
3850d769e936Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851786a6f21Smrg
3852d769e936Smrg      # Unlock the critical section if it was locked
38537322289dSmrg      if test no != "$need_locks"; then
3854d769e936Smrg	removelist=$lockfile
3855d769e936Smrg        $RM "$lockfile"
3856d769e936Smrg      fi
3857d769e936Smrg    }
3858786a6f21Smrg
3859d769e936Smrg    exit $EXIT_SUCCESS
3860d769e936Smrg}
3861786a6f21Smrg
3862d769e936Smrg$opt_help || {
38637322289dSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3864d769e936Smrg}
3865786a6f21Smrg
3866d769e936Smrgfunc_mode_help ()
3867d769e936Smrg{
3868d769e936Smrg    # We need to display help for each of the modes.
3869d769e936Smrg    case $opt_mode in
3870d769e936Smrg      "")
3871d769e936Smrg        # Generic help is extracted from the usage comments
3872d769e936Smrg        # at the start of this file.
3873d769e936Smrg        func_help
3874d769e936Smrg        ;;
3875786a6f21Smrg
3876d769e936Smrg      clean)
3877d769e936Smrg        $ECHO \
3878d769e936Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879786a6f21Smrg
3880d769e936SmrgRemove files from the build directory.
3881ec713c28Smrg
3882d769e936SmrgRM is the name of the program to use to delete files associated with each FILE
38837322289dSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3884d769e936Smrgto RM.
3885786a6f21Smrg
3886d769e936SmrgIf FILE is a libtool library, object or program, all the files associated
3887d769e936Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3888d769e936Smrg        ;;
3889786a6f21Smrg
3890d769e936Smrg      compile)
3891d769e936Smrg      $ECHO \
3892d769e936Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893786a6f21Smrg
3894d769e936SmrgCompile a source file into a libtool library object.
3895786a6f21Smrg
3896d769e936SmrgThis mode accepts the following additional options:
3897786a6f21Smrg
3898d769e936Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3899d769e936Smrg  -no-suppress      do not suppress compiler output for multiple passes
3900d769e936Smrg  -prefer-pic       try to build PIC objects only
3901d769e936Smrg  -prefer-non-pic   try to build non-PIC objects only
39027322289dSmrg  -shared           do not build a '.o' file suitable for static linking
39037322289dSmrg  -static           only build a '.o' file suitable for static linking
390422663e35Smrg  -Wc,FLAG
390522663e35Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906786a6f21Smrg
39077322289dSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3908d769e936Smrgfrom the given SOURCEFILE.
39091d54945dSmrg
3910d769e936SmrgThe output file name is determined by removing the directory component from
39117322289dSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
39127322289dSmrglibrary object suffix, '.lo'."
3913d769e936Smrg        ;;
39141d54945dSmrg
3915d769e936Smrg      execute)
3916d769e936Smrg        $ECHO \
3917d769e936Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
39181d54945dSmrg
3919d769e936SmrgAutomatically set library path, then run a program.
39201d54945dSmrg
3921d769e936SmrgThis mode accepts the following additional options:
39221d54945dSmrg
3923d769e936Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924786a6f21Smrg
39257322289dSmrgThis mode sets the library path environment variable according to '-dlopen'
3926d769e936Smrgflags.
3927786a6f21Smrg
3928d769e936SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3929d769e936Smrginto their corresponding uninstalled binary, and any of their required library
3930d769e936Smrgdirectories are added to the library path.
39311d54945dSmrg
3932d769e936SmrgThen, COMMAND is executed, with ARGS as arguments."
3933d769e936Smrg        ;;
3934d769e936Smrg
3935d769e936Smrg      finish)
3936d769e936Smrg        $ECHO \
3937d769e936Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938d769e936Smrg
3939d769e936SmrgComplete the installation of libtool libraries.
3940d769e936Smrg
3941d769e936SmrgEach LIBDIR is a directory that contains libtool libraries.
3942d769e936Smrg
3943d769e936SmrgThe commands that this mode executes may require superuser privileges.  Use
39447322289dSmrgthe '--dry-run' option if you just want to see what would be executed."
3945d769e936Smrg        ;;
3946d769e936Smrg
3947d769e936Smrg      install)
3948d769e936Smrg        $ECHO \
3949d769e936Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950d769e936Smrg
3951d769e936SmrgInstall executables or libraries.
3952d769e936Smrg
3953d769e936SmrgINSTALL-COMMAND is the installation command.  The first component should be
39547322289dSmrgeither the 'install' or 'cp' program.
3955d769e936Smrg
3956d769e936SmrgThe following components of INSTALL-COMMAND are treated specially:
3957d769e936Smrg
3958d769e936Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959d769e936Smrg
3960d769e936SmrgThe rest of the components are interpreted as arguments to that command (only
3961d769e936SmrgBSD-compatible install options are recognized)."
3962d769e936Smrg        ;;
3963d769e936Smrg
3964d769e936Smrg      link)
3965d769e936Smrg        $ECHO \
3966d769e936Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967d769e936Smrg
3968d769e936SmrgLink object files or libraries together to form another library, or to
3969d769e936Smrgcreate an executable program.
3970d769e936Smrg
3971d769e936SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3972d769e936Smrga program from several object files.
3973d769e936Smrg
3974d769e936SmrgThe following components of LINK-COMMAND are treated specially:
3975d769e936Smrg
3976d769e936Smrg  -all-static       do not do any dynamic linking at all
3977d769e936Smrg  -avoid-version    do not add a version suffix if possible
3978d769e936Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
3979d769e936Smrg                    libraries must be found in the PATH setting at runtime)
39807322289dSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3981d769e936Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3982d769e936Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3983d769e936Smrg  -export-symbols SYMFILE
3984d769e936Smrg                    try to export only the symbols listed in SYMFILE
3985d769e936Smrg  -export-symbols-regex REGEX
3986d769e936Smrg                    try to export only the symbols matching REGEX
3987d769e936Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3988d769e936Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3989d769e936Smrg  -module           build a library that can dlopened
3990d769e936Smrg  -no-fast-install  disable the fast-install mode
3991d769e936Smrg  -no-install       link a not-installable executable
3992d769e936Smrg  -no-undefined     declare that a library does not refer to external symbols
3993d769e936Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
39947322289dSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
39957322289dSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3996d769e936Smrg  -precious-files-regex REGEX
3997d769e936Smrg                    don't remove output files matching REGEX
3998d769e936Smrg  -release RELEASE  specify package release information
3999d769e936Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4000d769e936Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4001d769e936Smrg  -shared           only do dynamic linking of libtool libraries
4002d769e936Smrg  -shrext SUFFIX    override the standard shared library file extension
4003d769e936Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4004d769e936Smrg  -static-libtool-libs
4005d769e936Smrg                    do not do any dynamic linking of libtool libraries
4006d769e936Smrg  -version-info CURRENT[:REVISION[:AGE]]
4007d769e936Smrg                    specify library version info [each variable defaults to 0]
4008d769e936Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4009d769e936Smrg  -Wc,FLAG
4010d769e936Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
401122663e35Smrg  -Wa,FLAG
401222663e35Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4013d769e936Smrg  -Wl,FLAG
4014d769e936Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4015d769e936Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016d769e936Smrg
40177322289dSmrgAll other options (arguments beginning with '-') are ignored.
4018d769e936Smrg
40197322289dSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4020d769e936Smrgtreated as uninstalled libtool libraries, other files are standard or library
4021d769e936Smrgobject files.
4022d769e936Smrg
40237322289dSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
40247322289dSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4025d769e936Smrgrequired, except when creating a convenience library.
4026d769e936Smrg
40277322289dSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
40287322289dSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4029d769e936Smrg
40307322289dSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4031d769e936Smrgis created, otherwise an executable program is created."
4032d769e936Smrg        ;;
4033d769e936Smrg
4034d769e936Smrg      uninstall)
4035d769e936Smrg        $ECHO \
4036d769e936Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037d769e936Smrg
4038d769e936SmrgRemove libraries from an installation directory.
4039d769e936Smrg
4040d769e936SmrgRM is the name of the program to use to delete files associated with each FILE
40417322289dSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4042d769e936Smrgto RM.
4043d769e936Smrg
4044d769e936SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4045d769e936SmrgOtherwise, only FILE itself is deleted using RM."
4046d769e936Smrg        ;;
4047d769e936Smrg
4048d769e936Smrg      *)
40497322289dSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4050d769e936Smrg        ;;
4051ec713c28Smrg    esac
40521d54945dSmrg
4053d769e936Smrg    echo
40547322289dSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4055d769e936Smrg}
40561d54945dSmrg
4057d769e936Smrg# Now that we've collected a possible --mode arg, show help if necessary
4058d769e936Smrgif $opt_help; then
40597322289dSmrg  if test : = "$opt_help"; then
4060d769e936Smrg    func_mode_help
4061d769e936Smrg  else
4062d769e936Smrg    {
4063d769e936Smrg      func_help noexit
4064d769e936Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4065d769e936Smrg	func_mode_help
4066d769e936Smrg      done
40677322289dSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4068d769e936Smrg    {
4069d769e936Smrg      func_help noexit
4070d769e936Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4071d769e936Smrg	echo
4072d769e936Smrg	func_mode_help
4073d769e936Smrg      done
4074d769e936Smrg    } |
40757322289dSmrg    $SED '1d
4076d769e936Smrg      /^When reporting/,/^Report/{
4077d769e936Smrg	H
4078d769e936Smrg	d
4079d769e936Smrg      }
4080d769e936Smrg      $x
4081d769e936Smrg      /information about other modes/d
4082d769e936Smrg      /more detailed .*MODE/d
4083d769e936Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4084d769e936Smrg  fi
4085d769e936Smrg  exit $?
4086d769e936Smrgfi
40871d54945dSmrg
40881d54945dSmrg
4089d769e936Smrg# func_mode_execute arg...
4090d769e936Smrgfunc_mode_execute ()
4091d769e936Smrg{
40927322289dSmrg    $debug_cmd
40937322289dSmrg
4094d769e936Smrg    # The first argument is the command name.
40957322289dSmrg    cmd=$nonopt
4096d769e936Smrg    test -z "$cmd" && \
4097d769e936Smrg      func_fatal_help "you must specify a COMMAND"
4098d769e936Smrg
4099d769e936Smrg    # Handle -dlopen flags immediately.
4100d769e936Smrg    for file in $opt_dlopen; do
4101d769e936Smrg      test -f "$file" \
41027322289dSmrg	|| func_fatal_help "'$file' is not a file"
4103d769e936Smrg
4104d769e936Smrg      dir=
4105d769e936Smrg      case $file in
4106d769e936Smrg      *.la)
4107d769e936Smrg	func_resolve_sysroot "$file"
4108d769e936Smrg	file=$func_resolve_sysroot_result
4109d769e936Smrg
4110d769e936Smrg	# Check to see that this really is a libtool archive.
4111d769e936Smrg	func_lalib_unsafe_p "$file" \
41127322289dSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113d769e936Smrg
4114d769e936Smrg	# Read the libtool library.
4115d769e936Smrg	dlname=
4116d769e936Smrg	library_names=
4117d769e936Smrg	func_source "$file"
4118d769e936Smrg
4119d769e936Smrg	# Skip this library if it cannot be dlopened.
4120d769e936Smrg	if test -z "$dlname"; then
4121d769e936Smrg	  # Warn if it was a shared library.
4122d769e936Smrg	  test -n "$library_names" && \
41237322289dSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4124d769e936Smrg	  continue
4125d769e936Smrg	fi
4126d769e936Smrg
4127d769e936Smrg	func_dirname "$file" "" "."
41287322289dSmrg	dir=$func_dirname_result
4129d769e936Smrg
4130d769e936Smrg	if test -f "$dir/$objdir/$dlname"; then
4131d769e936Smrg	  func_append dir "/$objdir"
4132d769e936Smrg	else
4133d769e936Smrg	  if test ! -f "$dir/$dlname"; then
41347322289dSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4135d769e936Smrg	  fi
4136d769e936Smrg	fi
4137786a6f21Smrg	;;
4138d769e936Smrg
4139d769e936Smrg      *.lo)
4140d769e936Smrg	# Just add the directory containing the .lo file.
4141d769e936Smrg	func_dirname "$file" "" "."
41427322289dSmrg	dir=$func_dirname_result
4143ec713c28Smrg	;;
4144d769e936Smrg
4145d769e936Smrg      *)
41467322289dSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147d769e936Smrg	continue
4148786a6f21Smrg	;;
4149d769e936Smrg      esac
4150d769e936Smrg
4151d769e936Smrg      # Get the absolute pathname.
4152d769e936Smrg      absdir=`cd "$dir" && pwd`
41537322289dSmrg      test -n "$absdir" && dir=$absdir
4154d769e936Smrg
4155d769e936Smrg      # Now add the directory to shlibpath_var.
4156d769e936Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4157d769e936Smrg	eval "$shlibpath_var=\"\$dir\""
4158d769e936Smrg      else
4159d769e936Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160ec713c28Smrg      fi
4161d769e936Smrg    done
4162d769e936Smrg
4163d769e936Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4164d769e936Smrg    # rather than running their programs.
41657322289dSmrg    libtool_execute_magic=$magic
4166d769e936Smrg
4167d769e936Smrg    # Check if any of the arguments is a wrapper script.
4168d769e936Smrg    args=
4169d769e936Smrg    for file
4170d769e936Smrg    do
4171d769e936Smrg      case $file in
4172d769e936Smrg      -* | *.la | *.lo ) ;;
4173d769e936Smrg      *)
4174d769e936Smrg	# Do a test to see if this is really a libtool program.
4175d769e936Smrg	if func_ltwrapper_script_p "$file"; then
4176d769e936Smrg	  func_source "$file"
4177d769e936Smrg	  # Transform arg to wrapped name.
41787322289dSmrg	  file=$progdir/$program
4179d769e936Smrg	elif func_ltwrapper_executable_p "$file"; then
4180d769e936Smrg	  func_ltwrapper_scriptname "$file"
4181d769e936Smrg	  func_source "$func_ltwrapper_scriptname_result"
4182d769e936Smrg	  # Transform arg to wrapped name.
41837322289dSmrg	  file=$progdir/$program
4184d769e936Smrg	fi
4185d769e936Smrg	;;
4186d769e936Smrg      esac
4187d769e936Smrg      # Quote arguments (to preserve shell metacharacters).
4188d769e936Smrg      func_append_quoted args "$file"
4189d769e936Smrg    done
4190d769e936Smrg
41917322289dSmrg    if $opt_dry_run; then
41927322289dSmrg      # Display what would be done.
41937322289dSmrg      if test -n "$shlibpath_var"; then
41947322289dSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
41957322289dSmrg	echo "export $shlibpath_var"
41967322289dSmrg      fi
41977322289dSmrg      $ECHO "$cmd$args"
41987322289dSmrg      exit $EXIT_SUCCESS
41997322289dSmrg    else
4200d769e936Smrg      if test -n "$shlibpath_var"; then
4201d769e936Smrg	# Export the shlibpath_var.
4202d769e936Smrg	eval "export $shlibpath_var"
4203ec713c28Smrg      fi
4204d769e936Smrg
4205d769e936Smrg      # Restore saved environment variables
4206d769e936Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4207d769e936Smrg      do
4208d769e936Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4209d769e936Smrg                $lt_var=\$save_$lt_var; export $lt_var
4210d769e936Smrg	      else
4211d769e936Smrg		$lt_unset $lt_var
4212d769e936Smrg	      fi"
4213d769e936Smrg      done
4214d769e936Smrg
4215d769e936Smrg      # Now prepare to actually exec the command.
42167322289dSmrg      exec_cmd=\$cmd$args
4217d769e936Smrg    fi
4218d769e936Smrg}
42191d54945dSmrg
42207322289dSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
42211d54945dSmrg
42221d54945dSmrg
4223d769e936Smrg# func_mode_finish arg...
4224d769e936Smrgfunc_mode_finish ()
4225d769e936Smrg{
42267322289dSmrg    $debug_cmd
42277322289dSmrg
4228d769e936Smrg    libs=
4229d769e936Smrg    libdirs=
4230d769e936Smrg    admincmds=
42311d54945dSmrg
4232d769e936Smrg    for opt in "$nonopt" ${1+"$@"}
4233d769e936Smrg    do
4234d769e936Smrg      if test -d "$opt"; then
4235d769e936Smrg	func_append libdirs " $opt"
42361d54945dSmrg
4237d769e936Smrg      elif test -f "$opt"; then
4238d769e936Smrg	if func_lalib_unsafe_p "$opt"; then
4239d769e936Smrg	  func_append libs " $opt"
4240d769e936Smrg	else
42417322289dSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242ec713c28Smrg	fi
42431d54945dSmrg
4244d769e936Smrg      else
42457322289dSmrg	func_fatal_error "invalid argument '$opt'"
4246d769e936Smrg      fi
4247d769e936Smrg    done
42481d54945dSmrg
4249d769e936Smrg    if test -n "$libs"; then
4250d769e936Smrg      if test -n "$lt_sysroot"; then
4251d769e936Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252d769e936Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253d769e936Smrg      else
4254d769e936Smrg        sysroot_cmd=
4255d769e936Smrg      fi
42561d54945dSmrg
4257d769e936Smrg      # Remove sysroot references
4258d769e936Smrg      if $opt_dry_run; then
4259d769e936Smrg        for lib in $libs; do
42607322289dSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261d769e936Smrg        done
4262d769e936Smrg      else
4263d769e936Smrg        tmpdir=`func_mktempdir`
4264d769e936Smrg        for lib in $libs; do
42657322289dSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266d769e936Smrg	    > $tmpdir/tmp-la
4267d769e936Smrg	  mv -f $tmpdir/tmp-la $lib
4268ec713c28Smrg	done
4269d769e936Smrg        ${RM}r "$tmpdir"
4270d769e936Smrg      fi
4271d769e936Smrg    fi
4272d769e936Smrg
4273d769e936Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4274d769e936Smrg      for libdir in $libdirs; do
4275d769e936Smrg	if test -n "$finish_cmds"; then
4276d769e936Smrg	  # Do each command in the finish commands.
4277d769e936Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4278d769e936Smrg'"$cmd"'"'
4279d769e936Smrg	fi
4280d769e936Smrg	if test -n "$finish_eval"; then
4281d769e936Smrg	  # Do the single finish_eval.
4282d769e936Smrg	  eval cmds=\"$finish_eval\"
4283d769e936Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4284d769e936Smrg       $cmds"
42851d54945dSmrg	fi
4286d769e936Smrg      done
4287d769e936Smrg    fi
42881d54945dSmrg
4289d769e936Smrg    # Exit here if they wanted silent mode.
42907322289dSmrg    $opt_quiet && exit $EXIT_SUCCESS
42911d54945dSmrg
4292d769e936Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293d769e936Smrg      echo "----------------------------------------------------------------------"
4294d769e936Smrg      echo "Libraries have been installed in:"
4295d769e936Smrg      for libdir in $libdirs; do
4296d769e936Smrg	$ECHO "   $libdir"
4297d769e936Smrg      done
4298d769e936Smrg      echo
4299d769e936Smrg      echo "If you ever happen to want to link against installed libraries"
4300d769e936Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
43017322289dSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302d769e936Smrg      echo "flag during linking and do at least one of the following:"
4303d769e936Smrg      if test -n "$shlibpath_var"; then
43047322289dSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305d769e936Smrg	echo "     during execution"
4306d769e936Smrg      fi
4307d769e936Smrg      if test -n "$runpath_var"; then
43087322289dSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309d769e936Smrg	echo "     during linking"
4310d769e936Smrg      fi
4311d769e936Smrg      if test -n "$hardcode_libdir_flag_spec"; then
4312d769e936Smrg	libdir=LIBDIR
4313d769e936Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314d769e936Smrg
43157322289dSmrg	$ECHO "   - use the '$flag' linker flag"
4316d769e936Smrg      fi
4317d769e936Smrg      if test -n "$admincmds"; then
4318d769e936Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319d769e936Smrg      fi
4320d769e936Smrg      if test -f /etc/ld.so.conf; then
43217322289dSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322d769e936Smrg      fi
4323d769e936Smrg      echo
4324d769e936Smrg
4325d769e936Smrg      echo "See any operating system documentation about shared libraries for"
4326d769e936Smrg      case $host in
4327d769e936Smrg	solaris2.[6789]|solaris2.1[0-9])
4328d769e936Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329d769e936Smrg	  echo "pages."
4330d769e936Smrg	  ;;
4331ec713c28Smrg	*)
4332d769e936Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333ec713c28Smrg	  ;;
4334d769e936Smrg      esac
4335d769e936Smrg      echo "----------------------------------------------------------------------"
4336d769e936Smrg    fi
4337d769e936Smrg    exit $EXIT_SUCCESS
4338d769e936Smrg}
43391d54945dSmrg
43407322289dSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
43411d54945dSmrg
43421d54945dSmrg
4343d769e936Smrg# func_mode_install arg...
4344d769e936Smrgfunc_mode_install ()
4345d769e936Smrg{
43467322289dSmrg    $debug_cmd
43477322289dSmrg
4348d769e936Smrg    # There may be an optional sh(1) argument at the beginning of
4349d769e936Smrg    # install_prog (especially on Windows NT).
43507322289dSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4351d769e936Smrg       # Allow the use of GNU shtool's install command.
43527322289dSmrg       case $nonopt in *shtool*) :;; *) false;; esac
43537322289dSmrg    then
4354d769e936Smrg      # Aesthetically quote it.
435522663e35Smrg      func_quote_arg pretty "$nonopt"
435622663e35Smrg      install_prog="$func_quote_arg_result "
4357d769e936Smrg      arg=$1
4358d769e936Smrg      shift
4359d769e936Smrg    else
4360d769e936Smrg      install_prog=
4361d769e936Smrg      arg=$nonopt
4362d769e936Smrg    fi
4363d769e936Smrg
4364d769e936Smrg    # The real first argument should be the name of the installation program.
4365d769e936Smrg    # Aesthetically quote it.
436622663e35Smrg    func_quote_arg pretty "$arg"
436722663e35Smrg    func_append install_prog "$func_quote_arg_result"
4368d769e936Smrg    install_shared_prog=$install_prog
4369d769e936Smrg    case " $install_prog " in
4370d769e936Smrg      *[\\\ /]cp\ *) install_cp=: ;;
4371d769e936Smrg      *) install_cp=false ;;
4372d769e936Smrg    esac
4373d769e936Smrg
4374d769e936Smrg    # We need to accept at least all the BSD install flags.
4375d769e936Smrg    dest=
4376d769e936Smrg    files=
4377d769e936Smrg    opts=
4378d769e936Smrg    prev=
4379d769e936Smrg    install_type=
43807322289dSmrg    isdir=false
4381d769e936Smrg    stripme=
4382d769e936Smrg    no_mode=:
4383d769e936Smrg    for arg
4384d769e936Smrg    do
4385d769e936Smrg      arg2=
4386d769e936Smrg      if test -n "$dest"; then
4387d769e936Smrg	func_append files " $dest"
4388d769e936Smrg	dest=$arg
4389d769e936Smrg	continue
4390d769e936Smrg      fi
4391d769e936Smrg
4392d769e936Smrg      case $arg in
43937322289dSmrg      -d) isdir=: ;;
4394d769e936Smrg      -f)
4395d769e936Smrg	if $install_cp; then :; else
4396d769e936Smrg	  prev=$arg
4397d769e936Smrg	fi
4398d769e936Smrg	;;
4399d769e936Smrg      -g | -m | -o)
4400d769e936Smrg	prev=$arg
4401d769e936Smrg	;;
4402d769e936Smrg      -s)
4403d769e936Smrg	stripme=" -s"
4404d769e936Smrg	continue
4405d769e936Smrg	;;
4406d769e936Smrg      -*)
4407d769e936Smrg	;;
4408d769e936Smrg      *)
4409d769e936Smrg	# If the previous option needed an argument, then skip it.
4410d769e936Smrg	if test -n "$prev"; then
44117322289dSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4412d769e936Smrg	    arg2=$install_override_mode
4413d769e936Smrg	    no_mode=false
4414ec713c28Smrg	  fi
4415d769e936Smrg	  prev=
4416d769e936Smrg	else
4417d769e936Smrg	  dest=$arg
4418ec713c28Smrg	  continue
4419ec713c28Smrg	fi
4420d769e936Smrg	;;
4421d769e936Smrg      esac
44221d54945dSmrg
4423d769e936Smrg      # Aesthetically quote the argument.
442422663e35Smrg      func_quote_arg pretty "$arg"
442522663e35Smrg      func_append install_prog " $func_quote_arg_result"
4426d769e936Smrg      if test -n "$arg2"; then
442722663e35Smrg	func_quote_arg pretty "$arg2"
4428d769e936Smrg      fi
442922663e35Smrg      func_append install_shared_prog " $func_quote_arg_result"
4430d769e936Smrg    done
44311d54945dSmrg
4432d769e936Smrg    test -z "$install_prog" && \
4433d769e936Smrg      func_fatal_help "you must specify an install program"
44341d54945dSmrg
4435d769e936Smrg    test -n "$prev" && \
44367322289dSmrg      func_fatal_help "the '$prev' option requires an argument"
44371d54945dSmrg
4438d769e936Smrg    if test -n "$install_override_mode" && $no_mode; then
4439d769e936Smrg      if $install_cp; then :; else
444022663e35Smrg	func_quote_arg pretty "$install_override_mode"
444122663e35Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4442d769e936Smrg      fi
4443d769e936Smrg    fi
44441d54945dSmrg
4445d769e936Smrg    if test -z "$files"; then
4446d769e936Smrg      if test -z "$dest"; then
4447d769e936Smrg	func_fatal_help "no file or destination specified"
4448d769e936Smrg      else
4449d769e936Smrg	func_fatal_help "you must specify a destination"
4450d769e936Smrg      fi
4451d769e936Smrg    fi
44521d54945dSmrg
4453d769e936Smrg    # Strip any trailing slash from the destination.
4454d769e936Smrg    func_stripname '' '/' "$dest"
4455d769e936Smrg    dest=$func_stripname_result
44561d54945dSmrg
4457d769e936Smrg    # Check to see that the destination is a directory.
44587322289dSmrg    test -d "$dest" && isdir=:
44597322289dSmrg    if $isdir; then
44607322289dSmrg      destdir=$dest
4461d769e936Smrg      destname=
4462d769e936Smrg    else
4463d769e936Smrg      func_dirname_and_basename "$dest" "" "."
44647322289dSmrg      destdir=$func_dirname_result
44657322289dSmrg      destname=$func_basename_result
44661d54945dSmrg
4467d769e936Smrg      # Not a directory, so check to see that there is only one file specified.
4468d769e936Smrg      set dummy $files; shift
4469d769e936Smrg      test "$#" -gt 1 && \
44707322289dSmrg	func_fatal_help "'$dest' is not a directory"
4471d769e936Smrg    fi
4472d769e936Smrg    case $destdir in
4473d769e936Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474d769e936Smrg    *)
4475d769e936Smrg      for file in $files; do
4476d769e936Smrg	case $file in
4477d769e936Smrg	*.lo) ;;
4478d769e936Smrg	*)
44797322289dSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4480d769e936Smrg	  ;;
4481d769e936Smrg	esac
4482d769e936Smrg      done
4483d769e936Smrg      ;;
4484d769e936Smrg    esac
44851d54945dSmrg
4486d769e936Smrg    # This variable tells wrapper scripts just to set variables rather
4487d769e936Smrg    # than running their programs.
44887322289dSmrg    libtool_install_magic=$magic
44891d54945dSmrg
4490d769e936Smrg    staticlibs=
4491d769e936Smrg    future_libdirs=
4492d769e936Smrg    current_libdirs=
4493d769e936Smrg    for file in $files; do
44941d54945dSmrg
4495d769e936Smrg      # Do each installation.
4496d769e936Smrg      case $file in
4497d769e936Smrg      *.$libext)
4498d769e936Smrg	# Do the static libraries later.
4499d769e936Smrg	func_append staticlibs " $file"
4500d769e936Smrg	;;
45011d54945dSmrg
4502d769e936Smrg      *.la)
4503d769e936Smrg	func_resolve_sysroot "$file"
4504d769e936Smrg	file=$func_resolve_sysroot_result
45051d54945dSmrg
4506d769e936Smrg	# Check to see that this really is a libtool archive.
4507d769e936Smrg	func_lalib_unsafe_p "$file" \
45087322289dSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
45091d54945dSmrg
4510d769e936Smrg	library_names=
4511d769e936Smrg	old_library=
4512d769e936Smrg	relink_command=
4513d769e936Smrg	func_source "$file"
45141d54945dSmrg
4515d769e936Smrg	# Add the libdir to current_libdirs if it is the destination.
4516d769e936Smrg	if test "X$destdir" = "X$libdir"; then
4517d769e936Smrg	  case "$current_libdirs " in
4518d769e936Smrg	  *" $libdir "*) ;;
4519d769e936Smrg	  *) func_append current_libdirs " $libdir" ;;
4520d769e936Smrg	  esac
4521d769e936Smrg	else
4522d769e936Smrg	  # Note the libdir as a future libdir.
4523d769e936Smrg	  case "$future_libdirs " in
4524d769e936Smrg	  *" $libdir "*) ;;
4525d769e936Smrg	  *) func_append future_libdirs " $libdir" ;;
4526d769e936Smrg	  esac
4527d769e936Smrg	fi
45281d54945dSmrg
4529d769e936Smrg	func_dirname "$file" "/" ""
45307322289dSmrg	dir=$func_dirname_result
4531d769e936Smrg	func_append dir "$objdir"
4532786a6f21Smrg
4533d769e936Smrg	if test -n "$relink_command"; then
4534d769e936Smrg	  # Determine the prefix the user has applied to our future dir.
4535d769e936Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536786a6f21Smrg
4537d769e936Smrg	  # Don't allow the user to place us outside of our expected
4538d769e936Smrg	  # location b/c this prevents finding dependent libraries that
4539d769e936Smrg	  # are installed to the same prefix.
4540d769e936Smrg	  # At present, this check doesn't affect windows .dll's that
4541d769e936Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4542d769e936Smrg	  # but it's something to keep an eye on.
4543d769e936Smrg	  test "$inst_prefix_dir" = "$destdir" && \
45447322289dSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4545d769e936Smrg
4546d769e936Smrg	  if test -n "$inst_prefix_dir"; then
4547d769e936Smrg	    # Stick the inst_prefix_dir data into the link command.
4548d769e936Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549ec713c28Smrg	  else
4550d769e936Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551ec713c28Smrg	  fi
4552786a6f21Smrg
45537322289dSmrg	  func_warning "relinking '$file'"
4554d769e936Smrg	  func_show_eval "$relink_command" \
45557322289dSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4556d769e936Smrg	fi
4557d769e936Smrg
4558d769e936Smrg	# See the names of the shared library.
4559d769e936Smrg	set dummy $library_names; shift
4560d769e936Smrg	if test -n "$1"; then
45617322289dSmrg	  realname=$1
4562d769e936Smrg	  shift
4563d769e936Smrg
45647322289dSmrg	  srcname=$realname
45657322289dSmrg	  test -n "$relink_command" && srcname=${realname}T
4566d769e936Smrg
4567d769e936Smrg	  # Install the shared library and build the symlinks.
4568d769e936Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4569d769e936Smrg	      'exit $?'
45707322289dSmrg	  tstripme=$stripme
4571d769e936Smrg	  case $host_os in
4572d769e936Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4573d769e936Smrg	    case $realname in
4574d769e936Smrg	    *.dll.a)
45757322289dSmrg	      tstripme=
45767322289dSmrg	      ;;
45777322289dSmrg	    esac
45787322289dSmrg	    ;;
45797322289dSmrg	  os2*)
45807322289dSmrg	    case $realname in
45817322289dSmrg	    *_dll.a)
45827322289dSmrg	      tstripme=
4583d769e936Smrg	      ;;
4584d769e936Smrg	    esac
4585d769e936Smrg	    ;;
4586d769e936Smrg	  esac
4587d769e936Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4588d769e936Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589ec713c28Smrg	  fi
4590786a6f21Smrg
4591d769e936Smrg	  if test "$#" -gt 0; then
4592d769e936Smrg	    # Delete the old symlinks, and create new ones.
45937322289dSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4594d769e936Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4595d769e936Smrg	    # so we also need to try rm && ln -s.
4596d769e936Smrg	    for linkname
4597d769e936Smrg	    do
4598d769e936Smrg	      test "$linkname" != "$realname" \
4599d769e936Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600ec713c28Smrg	    done
4601ec713c28Smrg	  fi
4602786a6f21Smrg
4603d769e936Smrg	  # Do each command in the postinstall commands.
46047322289dSmrg	  lib=$destdir/$realname
4605d769e936Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606d769e936Smrg	fi
46071d54945dSmrg
4608d769e936Smrg	# Install the pseudo-library for information purposes.
4609d769e936Smrg	func_basename "$file"
46107322289dSmrg	name=$func_basename_result
46117322289dSmrg	instname=$dir/${name}i
4612d769e936Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613ec713c28Smrg
4614d769e936Smrg	# Maybe install the static library, too.
4615d769e936Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616d769e936Smrg	;;
4617d769e936Smrg
4618d769e936Smrg      *.lo)
4619d769e936Smrg	# Install (i.e. copy) a libtool object.
4620d769e936Smrg
4621d769e936Smrg	# Figure out destination file name, if it wasn't already specified.
4622d769e936Smrg	if test -n "$destname"; then
46237322289dSmrg	  destfile=$destdir/$destname
4624ec713c28Smrg	else
4625d769e936Smrg	  func_basename "$file"
46267322289dSmrg	  destfile=$func_basename_result
46277322289dSmrg	  destfile=$destdir/$destfile
4628ec713c28Smrg	fi
4629d769e936Smrg
4630d769e936Smrg	# Deduce the name of the destination old-style object file.
4631d769e936Smrg	case $destfile in
4632d769e936Smrg	*.lo)
4633d769e936Smrg	  func_lo2o "$destfile"
4634d769e936Smrg	  staticdest=$func_lo2o_result
4635d769e936Smrg	  ;;
4636d769e936Smrg	*.$objext)
46377322289dSmrg	  staticdest=$destfile
4638d769e936Smrg	  destfile=
4639d769e936Smrg	  ;;
4640d769e936Smrg	*)
46417322289dSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
46421d54945dSmrg	  ;;
46431d54945dSmrg	esac
46441d54945dSmrg
4645d769e936Smrg	# Install the libtool object if requested.
4646d769e936Smrg	test -n "$destfile" && \
4647d769e936Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46481d54945dSmrg
4649d769e936Smrg	# Install the old object if enabled.
46507322289dSmrg	if test yes = "$build_old_libs"; then
4651d769e936Smrg	  # Deduce the name of the old-style object file.
4652d769e936Smrg	  func_lo2o "$file"
4653d769e936Smrg	  staticobj=$func_lo2o_result
4654d769e936Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655d769e936Smrg	fi
4656d769e936Smrg	exit $EXIT_SUCCESS
4657d769e936Smrg	;;
46581d54945dSmrg
4659d769e936Smrg      *)
4660d769e936Smrg	# Figure out destination file name, if it wasn't already specified.
4661d769e936Smrg	if test -n "$destname"; then
46627322289dSmrg	  destfile=$destdir/$destname
4663d769e936Smrg	else
4664d769e936Smrg	  func_basename "$file"
46657322289dSmrg	  destfile=$func_basename_result
46667322289dSmrg	  destfile=$destdir/$destfile
4667d769e936Smrg	fi
46681d54945dSmrg
4669d769e936Smrg	# If the file is missing, and there is a .exe on the end, strip it
4670d769e936Smrg	# because it is most likely a libtool script we actually want to
4671d769e936Smrg	# install
46727322289dSmrg	stripped_ext=
4673d769e936Smrg	case $file in
4674d769e936Smrg	  *.exe)
4675d769e936Smrg	    if test ! -f "$file"; then
4676d769e936Smrg	      func_stripname '' '.exe' "$file"
4677d769e936Smrg	      file=$func_stripname_result
46787322289dSmrg	      stripped_ext=.exe
4679d769e936Smrg	    fi
4680d769e936Smrg	    ;;
4681d769e936Smrg	esac
46821d54945dSmrg
4683d769e936Smrg	# Do a test to see if this is really a libtool program.
4684d769e936Smrg	case $host in
4685d769e936Smrg	*cygwin* | *mingw*)
4686d769e936Smrg	    if func_ltwrapper_executable_p "$file"; then
4687d769e936Smrg	      func_ltwrapper_scriptname "$file"
4688d769e936Smrg	      wrapper=$func_ltwrapper_scriptname_result
4689d769e936Smrg	    else
4690d769e936Smrg	      func_stripname '' '.exe' "$file"
4691d769e936Smrg	      wrapper=$func_stripname_result
4692d769e936Smrg	    fi
4693d769e936Smrg	    ;;
4694d769e936Smrg	*)
4695d769e936Smrg	    wrapper=$file
4696d769e936Smrg	    ;;
4697d769e936Smrg	esac
4698d769e936Smrg	if func_ltwrapper_script_p "$wrapper"; then
4699d769e936Smrg	  notinst_deplibs=
4700d769e936Smrg	  relink_command=
47011d54945dSmrg
4702d769e936Smrg	  func_source "$wrapper"
47031d54945dSmrg
4704d769e936Smrg	  # Check the variables that should have been set.
4705d769e936Smrg	  test -z "$generated_by_libtool_version" && \
47067322289dSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
47071d54945dSmrg
47087322289dSmrg	  finalize=:
4709d769e936Smrg	  for lib in $notinst_deplibs; do
4710d769e936Smrg	    # Check to see that each library is installed.
4711d769e936Smrg	    libdir=
4712d769e936Smrg	    if test -f "$lib"; then
4713d769e936Smrg	      func_source "$lib"
4714d769e936Smrg	    fi
47157322289dSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4716d769e936Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
47177322289dSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
47187322289dSmrg	      finalize=false
4719d769e936Smrg	    fi
4720d769e936Smrg	  done
47211d54945dSmrg
4722d769e936Smrg	  relink_command=
4723d769e936Smrg	  func_source "$wrapper"
4724d769e936Smrg
4725d769e936Smrg	  outputname=
47267322289dSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4727d769e936Smrg	    $opt_dry_run || {
47287322289dSmrg	      if $finalize; then
4729d769e936Smrg	        tmpdir=`func_mktempdir`
4730d769e936Smrg		func_basename "$file$stripped_ext"
47317322289dSmrg		file=$func_basename_result
47327322289dSmrg	        outputname=$tmpdir/$file
4733d769e936Smrg	        # Replace the output file specification.
4734d769e936Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4735d769e936Smrg
47367322289dSmrg	        $opt_quiet || {
473722663e35Smrg	          func_quote_arg expand,pretty "$relink_command"
473822663e35Smrg		  eval "func_echo $func_quote_arg_result"
4739d769e936Smrg	        }
4740d769e936Smrg	        if eval "$relink_command"; then :
4741d769e936Smrg	          else
47427322289dSmrg		  func_error "error: relink '$file' with the above command before installing it"
4743d769e936Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4744d769e936Smrg		  continue
4745d769e936Smrg	        fi
47467322289dSmrg	        file=$outputname
4747d769e936Smrg	      else
47487322289dSmrg	        func_warning "cannot relink '$file'"
4749d769e936Smrg	      fi
4750d769e936Smrg	    }
4751d769e936Smrg	  else
4752d769e936Smrg	    # Install the binary that we compiled earlier.
4753d769e936Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754d769e936Smrg	  fi
4755ec713c28Smrg	fi
4756d769e936Smrg
4757d769e936Smrg	# remove .exe since cygwin /usr/bin/install will append another
4758d769e936Smrg	# one anyway
4759d769e936Smrg	case $install_prog,$host in
4760d769e936Smrg	*/usr/bin/install*,*cygwin*)
4761d769e936Smrg	  case $file:$destfile in
4762d769e936Smrg	  *.exe:*.exe)
4763d769e936Smrg	    # this is ok
4764d769e936Smrg	    ;;
4765d769e936Smrg	  *.exe:*)
4766d769e936Smrg	    destfile=$destfile.exe
4767d769e936Smrg	    ;;
4768d769e936Smrg	  *:*.exe)
4769d769e936Smrg	    func_stripname '' '.exe' "$destfile"
4770d769e936Smrg	    destfile=$func_stripname_result
4771d769e936Smrg	    ;;
4772d769e936Smrg	  esac
4773d769e936Smrg	  ;;
4774d769e936Smrg	esac
4775d769e936Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4776d769e936Smrg	$opt_dry_run || if test -n "$outputname"; then
4777d769e936Smrg	  ${RM}r "$tmpdir"
4778ec713c28Smrg	fi
4779ec713c28Smrg	;;
4780ec713c28Smrg      esac
4781d769e936Smrg    done
47821d54945dSmrg
4783d769e936Smrg    for file in $staticlibs; do
4784d769e936Smrg      func_basename "$file"
47857322289dSmrg      name=$func_basename_result
4786786a6f21Smrg
4787d769e936Smrg      # Set up the ranlib parameters.
47887322289dSmrg      oldlib=$destdir/$name
4789d769e936Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790d769e936Smrg      tool_oldlib=$func_to_tool_file_result
4791786a6f21Smrg
4792d769e936Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4793d769e936Smrg
4794d769e936Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795d769e936Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796ec713c28Smrg      fi
4797786a6f21Smrg
4798d769e936Smrg      # Do each command in the postinstall commands.
4799d769e936Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4800d769e936Smrg    done
4801786a6f21Smrg
4802d769e936Smrg    test -n "$future_libdirs" && \
48037322289dSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804786a6f21Smrg
4805d769e936Smrg    if test -n "$current_libdirs"; then
4806d769e936Smrg      # Maybe just do a dry run.
4807d769e936Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
48087322289dSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4809d769e936Smrg    else
4810d769e936Smrg      exit $EXIT_SUCCESS
4811d769e936Smrg    fi
4812d769e936Smrg}
4813786a6f21Smrg
48147322289dSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815786a6f21Smrg
4816786a6f21Smrg
4817d769e936Smrg# func_generate_dlsyms outputname originator pic_p
4818d769e936Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4819d769e936Smrg# a dlpreopen symbol table.
4820d769e936Smrgfunc_generate_dlsyms ()
4821d769e936Smrg{
48227322289dSmrg    $debug_cmd
48237322289dSmrg
48247322289dSmrg    my_outputname=$1
48257322289dSmrg    my_originator=$2
48267322289dSmrg    my_pic_p=${3-false}
48277322289dSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4828d769e936Smrg    my_dlsyms=
4829d769e936Smrg
48307322289dSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4831d769e936Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
48327322289dSmrg	my_dlsyms=${my_outputname}S.c
4833d769e936Smrg      else
4834d769e936Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4835d769e936Smrg      fi
4836d769e936Smrg    fi
4837786a6f21Smrg
4838d769e936Smrg    if test -n "$my_dlsyms"; then
4839d769e936Smrg      case $my_dlsyms in
4840d769e936Smrg      "") ;;
4841d769e936Smrg      *.c)
4842d769e936Smrg	# Discover the nlist of each of the dlfiles.
48437322289dSmrg	nlist=$output_objdir/$my_outputname.nm
4844786a6f21Smrg
4845d769e936Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846786a6f21Smrg
4847d769e936Smrg	# Parse the name list into a source file.
4848d769e936Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849786a6f21Smrg
4850d769e936Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
48517322289dSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
48527322289dSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853786a6f21Smrg
4854d769e936Smrg#ifdef __cplusplus
4855d769e936Smrgextern \"C\" {
4856d769e936Smrg#endif
4857786a6f21Smrg
48587322289dSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4859d769e936Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4860d769e936Smrg#endif
4861786a6f21Smrg
4862d769e936Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
48637322289dSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
48647322289dSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865d769e936Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866d769e936Smrg# define LT_DLSYM_CONST
48677322289dSmrg#elif defined __osf__
4868d769e936Smrg/* This system does not cope well with relocations in const data.  */
4869d769e936Smrg# define LT_DLSYM_CONST
4870d769e936Smrg#else
4871d769e936Smrg# define LT_DLSYM_CONST const
4872d769e936Smrg#endif
4873786a6f21Smrg
48747322289dSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
48757322289dSmrg
4876d769e936Smrg/* External symbol declarations for the compiler. */\
4877d769e936Smrg"
4878786a6f21Smrg
48797322289dSmrg	if test yes = "$dlself"; then
48807322289dSmrg	  func_verbose "generating symbol list for '$output'"
4881786a6f21Smrg
4882d769e936Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
48831d54945dSmrg
4884d769e936Smrg	  # Add our own program objects to the symbol list.
4885d769e936Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4886d769e936Smrg	  for progfile in $progfiles; do
4887d769e936Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
48887322289dSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889d769e936Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890ec713c28Smrg	  done
48911d54945dSmrg
4892d769e936Smrg	  if test -n "$exclude_expsyms"; then
4893d769e936Smrg	    $opt_dry_run || {
4894d769e936Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4895d769e936Smrg	      eval '$MV "$nlist"T "$nlist"'
4896d769e936Smrg	    }
4897d769e936Smrg	  fi
48981d54945dSmrg
4899d769e936Smrg	  if test -n "$export_symbols_regex"; then
4900d769e936Smrg	    $opt_dry_run || {
4901d769e936Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4902d769e936Smrg	      eval '$MV "$nlist"T "$nlist"'
4903d769e936Smrg	    }
4904d769e936Smrg	  fi
49051d54945dSmrg
4906d769e936Smrg	  # Prepare the list of exported symbols
4907d769e936Smrg	  if test -z "$export_symbols"; then
49087322289dSmrg	    export_symbols=$output_objdir/$outputname.exp
4909d769e936Smrg	    $opt_dry_run || {
4910d769e936Smrg	      $RM $export_symbols
49117322289dSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4912d769e936Smrg	      case $host in
4913d769e936Smrg	      *cygwin* | *mingw* | *cegcc* )
4914d769e936Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4915d769e936Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4916d769e936Smrg	        ;;
4917d769e936Smrg	      esac
4918d769e936Smrg	    }
4919d769e936Smrg	  else
4920d769e936Smrg	    $opt_dry_run || {
49217322289dSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4922d769e936Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4923d769e936Smrg	      eval '$MV "$nlist"T "$nlist"'
4924d769e936Smrg	      case $host in
4925d769e936Smrg	        *cygwin* | *mingw* | *cegcc* )
4926d769e936Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4927d769e936Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4928d769e936Smrg	          ;;
4929d769e936Smrg	      esac
4930d769e936Smrg	    }
4931d769e936Smrg	  fi
4932d769e936Smrg	fi
49331d54945dSmrg
4934d769e936Smrg	for dlprefile in $dlprefiles; do
49357322289dSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4936d769e936Smrg	  func_basename "$dlprefile"
49377322289dSmrg	  name=$func_basename_result
4938d769e936Smrg          case $host in
4939d769e936Smrg	    *cygwin* | *mingw* | *cegcc* )
4940d769e936Smrg	      # if an import library, we need to obtain dlname
4941d769e936Smrg	      if func_win32_import_lib_p "$dlprefile"; then
4942d769e936Smrg	        func_tr_sh "$dlprefile"
4943d769e936Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
49447322289dSmrg	        dlprefile_dlbasename=
4945d769e936Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946d769e936Smrg	          # Use subshell, to avoid clobbering current variable values
4947d769e936Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
49487322289dSmrg	          if test -n "$dlprefile_dlname"; then
4949d769e936Smrg	            func_basename "$dlprefile_dlname"
49507322289dSmrg	            dlprefile_dlbasename=$func_basename_result
4951d769e936Smrg	          else
4952d769e936Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953d769e936Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954d769e936Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955d769e936Smrg	          fi
4956d769e936Smrg	        fi
4957d769e936Smrg	        $opt_dry_run || {
49587322289dSmrg	          if test -n "$dlprefile_dlbasename"; then
4959d769e936Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960d769e936Smrg	          else
4961d769e936Smrg	            func_warning "Could not compute DLL name from $name"
4962d769e936Smrg	            eval '$ECHO ": $name " >> "$nlist"'
4963d769e936Smrg	          fi
4964d769e936Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965d769e936Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966d769e936Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967d769e936Smrg	        }
4968d769e936Smrg	      else # not an import lib
4969d769e936Smrg	        $opt_dry_run || {
4970d769e936Smrg	          eval '$ECHO ": $name " >> "$nlist"'
4971d769e936Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972d769e936Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973d769e936Smrg	        }
4974d769e936Smrg	      fi
4975d769e936Smrg	    ;;
4976d769e936Smrg	    *)
4977d769e936Smrg	      $opt_dry_run || {
4978d769e936Smrg	        eval '$ECHO ": $name " >> "$nlist"'
4979d769e936Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980d769e936Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981d769e936Smrg	      }
4982d769e936Smrg	    ;;
4983d769e936Smrg          esac
4984d769e936Smrg	done
49851d54945dSmrg
4986d769e936Smrg	$opt_dry_run || {
4987d769e936Smrg	  # Make sure we have at least an empty file.
4988d769e936Smrg	  test -f "$nlist" || : > "$nlist"
49891d54945dSmrg
4990d769e936Smrg	  if test -n "$exclude_expsyms"; then
4991d769e936Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4992d769e936Smrg	    $MV "$nlist"T "$nlist"
4993d769e936Smrg	  fi
49941d54945dSmrg
4995d769e936Smrg	  # Try sorting and uniquifying the output.
4996d769e936Smrg	  if $GREP -v "^: " < "$nlist" |
4997d769e936Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4998d769e936Smrg		sort -k 3
4999d769e936Smrg	      else
5000d769e936Smrg		sort +2
5001d769e936Smrg	      fi |
5002d769e936Smrg	      uniq > "$nlist"S; then
5003d769e936Smrg	    :
5004d769e936Smrg	  else
5005d769e936Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006d769e936Smrg	  fi
50071d54945dSmrg
5008d769e936Smrg	  if test -f "$nlist"S; then
5009d769e936Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010d769e936Smrg	  else
5011d769e936Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012d769e936Smrg	  fi
50131d54945dSmrg
50147322289dSmrg	  func_show_eval '$RM "${nlist}I"'
50157322289dSmrg	  if test -n "$global_symbol_to_import"; then
50167322289dSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
50177322289dSmrg	  fi
50187322289dSmrg
5019d769e936Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020d769e936Smrg
5021d769e936Smrg/* The mapping between symbol names and symbols.  */
5022d769e936Smrgtypedef struct {
5023d769e936Smrg  const char *name;
5024d769e936Smrg  void *address;
5025d769e936Smrg} lt_dlsymlist;
5026d769e936Smrgextern LT_DLSYM_CONST lt_dlsymlist
50277322289dSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
50287322289dSmrg"
50297322289dSmrg
50307322289dSmrg	  if test -s "$nlist"I; then
50317322289dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50327322289dSmrgstatic void lt_syminit(void)
50337322289dSmrg{
50347322289dSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
50357322289dSmrg  for (; symbol->name; ++symbol)
50367322289dSmrg    {"
50377322289dSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
50387322289dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50397322289dSmrg    }
50407322289dSmrg}"
50417322289dSmrg	  fi
50427322289dSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043d769e936SmrgLT_DLSYM_CONST lt_dlsymlist
5044d769e936Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
50457322289dSmrg{ {\"$my_originator\", (void *) 0},"
50467322289dSmrg
50477322289dSmrg	  if test -s "$nlist"I; then
50487322289dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50497322289dSmrg  {\"@INIT@\", (void *) &lt_syminit},"
50507322289dSmrg	  fi
5051d769e936Smrg
5052d769e936Smrg	  case $need_lib_prefix in
5053d769e936Smrg	  no)
5054d769e936Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055786a6f21Smrg	    ;;
5056ec713c28Smrg	  *)
5057d769e936Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058ec713c28Smrg	    ;;
5059ec713c28Smrg	  esac
5060d769e936Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5061d769e936Smrg  {0, (void *) 0}
5062d769e936Smrg};
50631d54945dSmrg
5064d769e936Smrg/* This works around a problem in FreeBSD linker */
5065d769e936Smrg#ifdef FREEBSD_WORKAROUND
5066d769e936Smrgstatic const void *lt_preloaded_setup() {
5067d769e936Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5068d769e936Smrg}
5069d769e936Smrg#endif
50701d54945dSmrg
5071d769e936Smrg#ifdef __cplusplus
5072d769e936Smrg}
5073d769e936Smrg#endif\
5074d769e936Smrg"
5075d769e936Smrg	} # !$opt_dry_run
50761d54945dSmrg
5077d769e936Smrg	pic_flag_for_symtable=
5078d769e936Smrg	case "$compile_command " in
5079d769e936Smrg	*" -static "*) ;;
5080d769e936Smrg	*)
5081d769e936Smrg	  case $host in
5082d769e936Smrg	  # compiling the symbol table file with pic_flag works around
5083d769e936Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5084d769e936Smrg	  # linked before any other PIC object.  But we must not use
5085d769e936Smrg	  # pic_flag when linking with -static.  The problem exists in
5086d769e936Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087d769e936Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5088d769e936Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5089d769e936Smrg	  *-*-hpux*)
5090d769e936Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5091d769e936Smrg	  *)
50927322289dSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5093d769e936Smrg	    ;;
5094d769e936Smrg	  esac
5095d769e936Smrg	  ;;
5096d769e936Smrg	esac
5097d769e936Smrg	symtab_cflags=
5098d769e936Smrg	for arg in $LTCFLAGS; do
5099d769e936Smrg	  case $arg in
5100d769e936Smrg	  -pie | -fpie | -fPIE) ;;
5101d769e936Smrg	  *) func_append symtab_cflags " $arg" ;;
5102ec713c28Smrg	  esac
5103ec713c28Smrg	done
51041d54945dSmrg
5105d769e936Smrg	# Now compile the dynamic symbol file.
5106d769e936Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51071d54945dSmrg
5108d769e936Smrg	# Clean up the generated files.
51097322289dSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
51101d54945dSmrg
5111d769e936Smrg	# Transform the symbol file into the correct name.
51127322289dSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5113d769e936Smrg	case $host in
5114d769e936Smrg	*cygwin* | *mingw* | *cegcc* )
5115d769e936Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5116d769e936Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5117d769e936Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5118d769e936Smrg	  else
5119d769e936Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5120d769e936Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121d769e936Smrg	  fi
5122d769e936Smrg	  ;;
5123d769e936Smrg	*)
5124d769e936Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125d769e936Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5126d769e936Smrg	  ;;
5127d769e936Smrg	esac
5128d769e936Smrg	;;
5129d769e936Smrg      *)
51307322289dSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5131d769e936Smrg	;;
5132d769e936Smrg      esac
5133d769e936Smrg    else
5134d769e936Smrg      # We keep going just in case the user didn't refer to
5135d769e936Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5136d769e936Smrg      # really was required.
51371d54945dSmrg
5138d769e936Smrg      # Nullify the symbol file.
5139d769e936Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5140d769e936Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5141d769e936Smrg    fi
5142d769e936Smrg}
51431d54945dSmrg
51447322289dSmrg# func_cygming_gnu_implib_p ARG
51457322289dSmrg# This predicate returns with zero status (TRUE) if
51467322289dSmrg# ARG is a GNU/binutils-style import library. Returns
51477322289dSmrg# with nonzero status (FALSE) otherwise.
51487322289dSmrgfunc_cygming_gnu_implib_p ()
51497322289dSmrg{
51507322289dSmrg  $debug_cmd
51517322289dSmrg
51527322289dSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51537322289dSmrg  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)$'`
51547322289dSmrg  test -n "$func_cygming_gnu_implib_tmp"
51557322289dSmrg}
51567322289dSmrg
51577322289dSmrg# func_cygming_ms_implib_p ARG
51587322289dSmrg# This predicate returns with zero status (TRUE) if
51597322289dSmrg# ARG is an MS-style import library. Returns
51607322289dSmrg# with nonzero status (FALSE) otherwise.
51617322289dSmrgfunc_cygming_ms_implib_p ()
51627322289dSmrg{
51637322289dSmrg  $debug_cmd
51647322289dSmrg
51657322289dSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51667322289dSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
51677322289dSmrg  test -n "$func_cygming_ms_implib_tmp"
51687322289dSmrg}
51697322289dSmrg
5170d769e936Smrg# func_win32_libid arg
5171d769e936Smrg# return the library type of file 'arg'
5172d769e936Smrg#
5173d769e936Smrg# Need a lot of goo to handle *both* DLLs and import libs
5174d769e936Smrg# Has to be a shell function in order to 'eat' the argument
5175d769e936Smrg# that is supplied when $file_magic_command is called.
5176d769e936Smrg# Despite the name, also deal with 64 bit binaries.
5177d769e936Smrgfunc_win32_libid ()
5178d769e936Smrg{
51797322289dSmrg  $debug_cmd
51807322289dSmrg
51817322289dSmrg  win32_libid_type=unknown
5182d769e936Smrg  win32_fileres=`file -L $1 2>/dev/null`
5183d769e936Smrg  case $win32_fileres in
5184d769e936Smrg  *ar\ archive\ import\ library*) # definitely import
5185d769e936Smrg    win32_libid_type="x86 archive import"
5186d769e936Smrg    ;;
5187d769e936Smrg  *ar\ archive*) # could be an import, or static
5188d769e936Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5189d769e936Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5190d769e936Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
51917322289dSmrg      case $nm_interface in
51927322289dSmrg      "MS dumpbin")
51937322289dSmrg	if func_cygming_ms_implib_p "$1" ||
51947322289dSmrg	   func_cygming_gnu_implib_p "$1"
51957322289dSmrg	then
51967322289dSmrg	  win32_nmres=import
51977322289dSmrg	else
51987322289dSmrg	  win32_nmres=
51997322289dSmrg	fi
52007322289dSmrg	;;
52017322289dSmrg      *)
52027322289dSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
52037322289dSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
52047322289dSmrg	  $SED -n -e '
5205d769e936Smrg	    1,100{
5206d769e936Smrg		/ I /{
52077322289dSmrg		    s|.*|import|
5208d769e936Smrg		    p
5209d769e936Smrg		    q
5210d769e936Smrg		}
5211d769e936Smrg	    }'`
52127322289dSmrg	;;
52137322289dSmrg      esac
5214d769e936Smrg      case $win32_nmres in
5215d769e936Smrg      import*)  win32_libid_type="x86 archive import";;
5216d769e936Smrg      *)        win32_libid_type="x86 archive static";;
5217d769e936Smrg      esac
5218d769e936Smrg    fi
5219d769e936Smrg    ;;
5220d769e936Smrg  *DLL*)
5221d769e936Smrg    win32_libid_type="x86 DLL"
5222d769e936Smrg    ;;
5223d769e936Smrg  *executable*) # but shell scripts are "executable" too...
5224d769e936Smrg    case $win32_fileres in
5225d769e936Smrg    *MS\ Windows\ PE\ Intel*)
5226d769e936Smrg      win32_libid_type="x86 DLL"
5227d769e936Smrg      ;;
5228d769e936Smrg    esac
5229d769e936Smrg    ;;
5230d769e936Smrg  esac
5231d769e936Smrg  $ECHO "$win32_libid_type"
5232d769e936Smrg}
5233d769e936Smrg
5234d769e936Smrg# func_cygming_dll_for_implib ARG
5235d769e936Smrg#
5236d769e936Smrg# Platform-specific function to extract the
5237d769e936Smrg# name of the DLL associated with the specified
5238d769e936Smrg# import library ARG.
5239d769e936Smrg# Invoked by eval'ing the libtool variable
5240d769e936Smrg#    $sharedlib_from_linklib_cmd
5241d769e936Smrg# Result is available in the variable
5242d769e936Smrg#    $sharedlib_from_linklib_result
5243d769e936Smrgfunc_cygming_dll_for_implib ()
5244d769e936Smrg{
52457322289dSmrg  $debug_cmd
52467322289dSmrg
5247d769e936Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248d769e936Smrg}
5249d769e936Smrg
5250d769e936Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251d769e936Smrg#
5252d769e936Smrg# The is the core of a fallback implementation of a
5253d769e936Smrg# platform-specific function to extract the name of the
5254d769e936Smrg# DLL associated with the specified import library LIBNAME.
5255d769e936Smrg#
5256d769e936Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257d769e936Smrg# on the platform and compiler that created the implib.
5258d769e936Smrg#
5259d769e936Smrg# Echos the name of the DLL associated with the
5260d769e936Smrg# specified import library.
5261d769e936Smrgfunc_cygming_dll_for_implib_fallback_core ()
5262d769e936Smrg{
52637322289dSmrg  $debug_cmd
52647322289dSmrg
5265d769e936Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266d769e936Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267d769e936Smrg    $SED '/^Contents of section '"$match_literal"':/{
5268d769e936Smrg      # Place marker at beginning of archive member dllname section
5269d769e936Smrg      s/.*/====MARK====/
5270d769e936Smrg      p
5271d769e936Smrg      d
5272d769e936Smrg    }
5273d769e936Smrg    # These lines can sometimes be longer than 43 characters, but
5274d769e936Smrg    # are always uninteresting
5275d769e936Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276d769e936Smrg    /^In archive [^:]*:/d
5277d769e936Smrg    # Ensure marker is printed
5278d769e936Smrg    /^====MARK====/p
5279d769e936Smrg    # Remove all lines with less than 43 characters
5280d769e936Smrg    /^.\{43\}/!d
5281d769e936Smrg    # From remaining lines, remove first 43 characters
5282d769e936Smrg    s/^.\{43\}//' |
5283d769e936Smrg    $SED -n '
5284d769e936Smrg      # Join marker and all lines until next marker into a single line
5285d769e936Smrg      /^====MARK====/ b para
5286d769e936Smrg      H
5287d769e936Smrg      $ b para
5288d769e936Smrg      b
5289d769e936Smrg      :para
5290d769e936Smrg      x
5291d769e936Smrg      s/\n//g
5292d769e936Smrg      # Remove the marker
5293d769e936Smrg      s/^====MARK====//
5294d769e936Smrg      # Remove trailing dots and whitespace
5295d769e936Smrg      s/[\. \t]*$//
5296d769e936Smrg      # Print
5297d769e936Smrg      /./p' |
5298d769e936Smrg    # we now have a list, one entry per line, of the stringified
5299d769e936Smrg    # contents of the appropriate section of all members of the
53007322289dSmrg    # archive that possess that section. Heuristic: eliminate
53017322289dSmrg    # all those that have a first or second character that is
5302d769e936Smrg    # a '.' (that is, objdump's representation of an unprintable
5303d769e936Smrg    # character.) This should work for all archives with less than
5304d769e936Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305d769e936Smrg    # begins with a literal '.' or a single character followed by
5306d769e936Smrg    # a '.'.
5307d769e936Smrg    #
5308d769e936Smrg    # Of those that remain, print the first one.
5309d769e936Smrg    $SED -e '/^\./d;/^.\./d;q'
5310d769e936Smrg}
5311d769e936Smrg
5312d769e936Smrg# func_cygming_dll_for_implib_fallback ARG
5313d769e936Smrg# Platform-specific function to extract the
5314d769e936Smrg# name of the DLL associated with the specified
5315d769e936Smrg# import library ARG.
5316d769e936Smrg#
5317d769e936Smrg# This fallback implementation is for use when $DLLTOOL
5318d769e936Smrg# does not support the --identify-strict option.
5319d769e936Smrg# Invoked by eval'ing the libtool variable
5320d769e936Smrg#    $sharedlib_from_linklib_cmd
5321d769e936Smrg# Result is available in the variable
5322d769e936Smrg#    $sharedlib_from_linklib_result
5323d769e936Smrgfunc_cygming_dll_for_implib_fallback ()
5324d769e936Smrg{
53257322289dSmrg  $debug_cmd
53267322289dSmrg
53277322289dSmrg  if func_cygming_gnu_implib_p "$1"; then
5328d769e936Smrg    # binutils import library
5329d769e936Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
53307322289dSmrg  elif func_cygming_ms_implib_p "$1"; then
5331d769e936Smrg    # ms-generated import library
5332d769e936Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333d769e936Smrg  else
5334d769e936Smrg    # unknown
53357322289dSmrg    sharedlib_from_linklib_result=
5336d769e936Smrg  fi
5337d769e936Smrg}
5338d769e936Smrg
5339d769e936Smrg
5340d769e936Smrg# func_extract_an_archive dir oldlib
5341d769e936Smrgfunc_extract_an_archive ()
5342d769e936Smrg{
53437322289dSmrg    $debug_cmd
53447322289dSmrg
53457322289dSmrg    f_ex_an_ar_dir=$1; shift
53467322289dSmrg    f_ex_an_ar_oldlib=$1
53477322289dSmrg    if test yes = "$lock_old_archive_extraction"; then
5348d769e936Smrg      lockfile=$f_ex_an_ar_oldlib.lock
5349d769e936Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5350d769e936Smrg	func_echo "Waiting for $lockfile to be removed"
5351d769e936Smrg	sleep 2
5352ec713c28Smrg      done
5353d769e936Smrg    fi
5354d769e936Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5355d769e936Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
53567322289dSmrg    if test yes = "$lock_old_archive_extraction"; then
5357d769e936Smrg      $opt_dry_run || rm -f "$lockfile"
5358d769e936Smrg    fi
5359d769e936Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5360d769e936Smrg     :
5361d769e936Smrg    else
5362d769e936Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5363d769e936Smrg    fi
5364d769e936Smrg}
53651d54945dSmrg
5366d769e936Smrg
5367d769e936Smrg# func_extract_archives gentop oldlib ...
5368d769e936Smrgfunc_extract_archives ()
5369d769e936Smrg{
53707322289dSmrg    $debug_cmd
53717322289dSmrg
53727322289dSmrg    my_gentop=$1; shift
5373d769e936Smrg    my_oldlibs=${1+"$@"}
53747322289dSmrg    my_oldobjs=
53757322289dSmrg    my_xlib=
53767322289dSmrg    my_xabs=
53777322289dSmrg    my_xdir=
5378d769e936Smrg
5379d769e936Smrg    for my_xlib in $my_oldlibs; do
5380d769e936Smrg      # Extract the objects.
5381d769e936Smrg      case $my_xlib in
53827322289dSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5383d769e936Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5384d769e936Smrg      esac
5385d769e936Smrg      func_basename "$my_xlib"
53867322289dSmrg      my_xlib=$func_basename_result
5387d769e936Smrg      my_xlib_u=$my_xlib
5388d769e936Smrg      while :; do
5389d769e936Smrg        case " $extracted_archives " in
5390d769e936Smrg	*" $my_xlib_u "*)
5391d769e936Smrg	  func_arith $extracted_serial + 1
5392d769e936Smrg	  extracted_serial=$func_arith_result
5393d769e936Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5394d769e936Smrg	*) break ;;
5395ec713c28Smrg	esac
5396ec713c28Smrg      done
5397d769e936Smrg      extracted_archives="$extracted_archives $my_xlib_u"
53987322289dSmrg      my_xdir=$my_gentop/$my_xlib_u
53991d54945dSmrg
5400d769e936Smrg      func_mkdir_p "$my_xdir"
54011d54945dSmrg
5402d769e936Smrg      case $host in
5403d769e936Smrg      *-darwin*)
5404d769e936Smrg	func_verbose "Extracting $my_xabs"
5405d769e936Smrg	# Do not bother doing anything if just a dry run
5406d769e936Smrg	$opt_dry_run || {
5407d769e936Smrg	  darwin_orig_dir=`pwd`
5408d769e936Smrg	  cd $my_xdir || exit $?
5409d769e936Smrg	  darwin_archive=$my_xabs
5410d769e936Smrg	  darwin_curdir=`pwd`
54117322289dSmrg	  func_basename "$darwin_archive"
54127322289dSmrg	  darwin_base_archive=$func_basename_result
5413d769e936Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5414d769e936Smrg	  if test -n "$darwin_arches"; then
5415d769e936Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5416d769e936Smrg	    darwin_arch=
5417d769e936Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
54187322289dSmrg	    for darwin_arch in  $darwin_arches; do
54197322289dSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
54207322289dSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
54217322289dSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
54227322289dSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5423d769e936Smrg	      cd "$darwin_curdir"
54247322289dSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5425d769e936Smrg	    done # $darwin_arches
5426d769e936Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
54277322289dSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5428d769e936Smrg	    darwin_file=
5429d769e936Smrg	    darwin_files=
5430d769e936Smrg	    for darwin_file in $darwin_filelist; do
5431d769e936Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5432d769e936Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5433d769e936Smrg	    done # $darwin_filelist
5434d769e936Smrg	    $RM -rf unfat-$$
5435d769e936Smrg	    cd "$darwin_orig_dir"
5436ec713c28Smrg	  else
5437d769e936Smrg	    cd $darwin_orig_dir
5438d769e936Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5439d769e936Smrg	  fi # $darwin_arches
5440d769e936Smrg	} # !$opt_dry_run
5441d769e936Smrg	;;
5442d769e936Smrg      *)
5443d769e936Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5444d769e936Smrg	;;
5445d769e936Smrg      esac
5446d769e936Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5447d769e936Smrg    done
54481d54945dSmrg
54497322289dSmrg    func_extract_archives_result=$my_oldobjs
5450d769e936Smrg}
54511d54945dSmrg
54521d54945dSmrg
5453d769e936Smrg# func_emit_wrapper [arg=no]
5454d769e936Smrg#
5455d769e936Smrg# Emit a libtool wrapper script on stdout.
5456d769e936Smrg# Don't directly open a file because we may want to
5457d769e936Smrg# incorporate the script contents within a cygwin/mingw
5458d769e936Smrg# wrapper executable.  Must ONLY be called from within
5459d769e936Smrg# func_mode_link because it depends on a number of variables
5460d769e936Smrg# set therein.
5461d769e936Smrg#
5462d769e936Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5463d769e936Smrg# variable will take.  If 'yes', then the emitted script
54647322289dSmrg# will assume that the directory where it is stored is
5465d769e936Smrg# the $objdir directory.  This is a cygwin/mingw-specific
5466d769e936Smrg# behavior.
5467d769e936Smrgfunc_emit_wrapper ()
5468d769e936Smrg{
5469d769e936Smrg	func_emit_wrapper_arg1=${1-no}
54701d54945dSmrg
5471d769e936Smrg	$ECHO "\
5472d769e936Smrg#! $SHELL
54731d54945dSmrg
5474d769e936Smrg# $output - temporary wrapper script for $objdir/$outputname
54757322289dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5476d769e936Smrg#
5477d769e936Smrg# The $output program cannot be directly executed until all the libtool
5478d769e936Smrg# libraries that it depends on are installed.
5479d769e936Smrg#
5480d769e936Smrg# This wrapper script should never be moved out of the build directory.
5481d769e936Smrg# If it is, it will not operate correctly.
54821d54945dSmrg
5483d769e936Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5484d769e936Smrg# metacharacters that are still active within double-quoted strings.
5485d769e936Smrgsed_quote_subst='$sed_quote_subst'
54861d54945dSmrg
5487d769e936Smrg# Be Bourne compatible
5488d769e936Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5489d769e936Smrg  emulate sh
5490d769e936Smrg  NULLCMD=:
5491d769e936Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5492d769e936Smrg  # is contrary to our usage.  Disable this feature.
5493d769e936Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5494d769e936Smrg  setopt NO_GLOB_SUBST
5495d769e936Smrgelse
5496d769e936Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5497d769e936Smrgfi
5498d769e936SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5499d769e936SmrgDUALCASE=1; export DUALCASE # for MKS sh
55001d54945dSmrg
5501d769e936Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5502d769e936Smrg# if CDPATH is set.
5503d769e936Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
55041d54945dSmrg
5505d769e936Smrgrelink_command=\"$relink_command\"
55061d54945dSmrg
5507d769e936Smrg# This environment variable determines our operation mode.
5508d769e936Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5509d769e936Smrg  # install mode needs the following variables:
5510d769e936Smrg  generated_by_libtool_version='$macro_version'
5511d769e936Smrg  notinst_deplibs='$notinst_deplibs'
5512d769e936Smrgelse
5513d769e936Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5514d769e936Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5515d769e936Smrg    file=\"\$0\""
55161d54945dSmrg
551722663e35Smrg    func_quote_arg pretty "$ECHO"
551822663e35Smrg    qECHO=$func_quote_arg_result
5519d769e936Smrg    $ECHO "\
55201d54945dSmrg
5521d769e936Smrg# A function that is used when there is no print builtin or printf.
5522d769e936Smrgfunc_fallback_echo ()
5523d769e936Smrg{
5524d769e936Smrg  eval 'cat <<_LTECHO_EOF
5525d769e936Smrg\$1
5526d769e936Smrg_LTECHO_EOF'
5527d769e936Smrg}
552822663e35Smrg    ECHO=$qECHO
5529d769e936Smrg  fi
55301d54945dSmrg
5531d769e936Smrg# Very basic option parsing. These options are (a) specific to
5532d769e936Smrg# the libtool wrapper, (b) are identical between the wrapper
55337322289dSmrg# /script/ and the wrapper /executable/ that is used only on
5534d769e936Smrg# windows platforms, and (c) all begin with the string "--lt-"
55357322289dSmrg# (application programs are unlikely to have options that match
5536d769e936Smrg# this pattern).
5537d769e936Smrg#
5538d769e936Smrg# There are only two supported options: --lt-debug and
5539d769e936Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
5540d769e936Smrg#
5541d769e936Smrg# The first argument to this parsing function should be the
5542d769e936Smrg# script's $0 value, followed by "$@".
5543d769e936Smrglt_option_debug=
5544d769e936Smrgfunc_parse_lt_options ()
5545d769e936Smrg{
5546d769e936Smrg  lt_script_arg0=\$0
5547d769e936Smrg  shift
5548d769e936Smrg  for lt_opt
5549d769e936Smrg  do
5550d769e936Smrg    case \"\$lt_opt\" in
5551d769e936Smrg    --lt-debug) lt_option_debug=1 ;;
5552d769e936Smrg    --lt-dump-script)
5553d769e936Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5554d769e936Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5555d769e936Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5556d769e936Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5557d769e936Smrg        exit 0
5558d769e936Smrg      ;;
5559d769e936Smrg    --lt-*)
5560d769e936Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5561d769e936Smrg        exit 1
5562d769e936Smrg      ;;
5563d769e936Smrg    esac
5564d769e936Smrg  done
55651d54945dSmrg
5566d769e936Smrg  # Print the debug banner immediately:
5567d769e936Smrg  if test -n \"\$lt_option_debug\"; then
55687322289dSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5569d769e936Smrg  fi
5570d769e936Smrg}
55711d54945dSmrg
5572d769e936Smrg# Used when --lt-debug. Prints its arguments to stdout
5573d769e936Smrg# (redirection is the responsibility of the caller)
5574d769e936Smrgfunc_lt_dump_args ()
5575d769e936Smrg{
5576d769e936Smrg  lt_dump_args_N=1;
5577d769e936Smrg  for lt_arg
5578d769e936Smrg  do
55797322289dSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5580d769e936Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5581d769e936Smrg  done
5582d769e936Smrg}
55831d54945dSmrg
5584d769e936Smrg# Core function for launching the target application
5585d769e936Smrgfunc_exec_program_core ()
5586d769e936Smrg{
5587d769e936Smrg"
5588d769e936Smrg  case $host in
5589d769e936Smrg  # Backslashes separate directories on plain windows
5590d769e936Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
5591d769e936Smrg    $ECHO "\
5592d769e936Smrg      if test -n \"\$lt_option_debug\"; then
55937322289dSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5594d769e936Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595d769e936Smrg      fi
5596d769e936Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5597d769e936Smrg"
5598d769e936Smrg    ;;
55991d54945dSmrg
5600d769e936Smrg  *)
5601d769e936Smrg    $ECHO "\
5602d769e936Smrg      if test -n \"\$lt_option_debug\"; then
56037322289dSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5604d769e936Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605d769e936Smrg      fi
5606d769e936Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5607d769e936Smrg"
5608d769e936Smrg    ;;
5609d769e936Smrg  esac
5610d769e936Smrg  $ECHO "\
5611d769e936Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5612d769e936Smrg      exit 1
5613d769e936Smrg}
56141d54945dSmrg
5615d769e936Smrg# A function to encapsulate launching the target application
5616d769e936Smrg# Strips options in the --lt-* namespace from \$@ and
5617d769e936Smrg# launches target application with the remaining arguments.
5618d769e936Smrgfunc_exec_program ()
5619d769e936Smrg{
5620d769e936Smrg  case \" \$* \" in
5621d769e936Smrg  *\\ --lt-*)
5622d769e936Smrg    for lt_wr_arg
5623d769e936Smrg    do
5624d769e936Smrg      case \$lt_wr_arg in
5625d769e936Smrg      --lt-*) ;;
5626d769e936Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627d769e936Smrg      esac
5628d769e936Smrg      shift
5629d769e936Smrg    done ;;
5630d769e936Smrg  esac
5631d769e936Smrg  func_exec_program_core \${1+\"\$@\"}
5632d769e936Smrg}
56331d54945dSmrg
5634d769e936Smrg  # Parse options
5635d769e936Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
56361d54945dSmrg
5637d769e936Smrg  # Find the directory that this script lives in.
5638d769e936Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5639d769e936Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
56401d54945dSmrg
5641d769e936Smrg  # Follow symbolic links until we get to the real thisdir.
5642d769e936Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5643d769e936Smrg  while test -n \"\$file\"; do
5644d769e936Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
56451d54945dSmrg
5646d769e936Smrg    # If there was a directory component, then change thisdir.
5647d769e936Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5648d769e936Smrg      case \"\$destdir\" in
5649d769e936Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5650d769e936Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651d769e936Smrg      esac
5652d769e936Smrg    fi
56531d54945dSmrg
5654d769e936Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5655d769e936Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5656d769e936Smrg  done
56571d54945dSmrg
5658d769e936Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5659d769e936Smrg  # the cwrapper.
5660d769e936Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5661d769e936Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5662d769e936Smrg    # special case for '.'
5663d769e936Smrg    if test \"\$thisdir\" = \".\"; then
5664d769e936Smrg      thisdir=\`pwd\`
5665d769e936Smrg    fi
5666d769e936Smrg    # remove .libs from thisdir
5667d769e936Smrg    case \"\$thisdir\" in
5668d769e936Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5669d769e936Smrg    $objdir )   thisdir=. ;;
5670d769e936Smrg    esac
5671d769e936Smrg  fi
56721d54945dSmrg
5673d769e936Smrg  # Try to get the absolute directory name.
5674d769e936Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5675d769e936Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5676d769e936Smrg"
56771d54945dSmrg
56787322289dSmrg	if test yes = "$fast_install"; then
5679d769e936Smrg	  $ECHO "\
5680d769e936Smrg  program=lt-'$outputname'$exeext
5681d769e936Smrg  progdir=\"\$thisdir/$objdir\"
56821d54945dSmrg
5683d769e936Smrg  if test ! -f \"\$progdir/\$program\" ||
56847322289dSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5685d769e936Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
56861d54945dSmrg
5687d769e936Smrg    file=\"\$\$-\$program\"
56881d54945dSmrg
5689d769e936Smrg    if test ! -d \"\$progdir\"; then
5690d769e936Smrg      $MKDIR \"\$progdir\"
5691d769e936Smrg    else
5692d769e936Smrg      $RM \"\$progdir/\$file\"
5693d769e936Smrg    fi"
56941d54945dSmrg
5695d769e936Smrg	  $ECHO "\
56961d54945dSmrg
5697d769e936Smrg    # relink executable if necessary
5698d769e936Smrg    if test -n \"\$relink_command\"; then
5699d769e936Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5700d769e936Smrg      else
57017322289dSmrg	\$ECHO \"\$relink_command_output\" >&2
5702d769e936Smrg	$RM \"\$progdir/\$file\"
5703d769e936Smrg	exit 1
5704d769e936Smrg      fi
5705d769e936Smrg    fi
5706ec713c28Smrg
5707d769e936Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5708d769e936Smrg    { $RM \"\$progdir/\$program\";
5709d769e936Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5710d769e936Smrg    $RM \"\$progdir/\$file\"
5711d769e936Smrg  fi"
5712d769e936Smrg	else
5713d769e936Smrg	  $ECHO "\
5714d769e936Smrg  program='$outputname'
5715d769e936Smrg  progdir=\"\$thisdir/$objdir\"
5716d769e936Smrg"
5717d769e936Smrg	fi
5718ec713c28Smrg
5719d769e936Smrg	$ECHO "\
5720ec713c28Smrg
5721d769e936Smrg  if test -f \"\$progdir/\$program\"; then"
5722d769e936Smrg
5723d769e936Smrg	# fixup the dll searchpath if we need to.
5724d769e936Smrg	#
5725d769e936Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726d769e936Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727d769e936Smrg	# libraries must come first.
5728d769e936Smrg	if test -n "$dllsearchpath"; then
5729d769e936Smrg	  $ECHO "\
5730d769e936Smrg    # Add the dll search path components to the executable PATH
5731d769e936Smrg    PATH=$dllsearchpath:\$PATH
5732d769e936Smrg"
5733ec713c28Smrg	fi
5734ec713c28Smrg
5735d769e936Smrg	# Export our shlibpath_var if we have one.
57367322289dSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5737d769e936Smrg	  $ECHO "\
5738d769e936Smrg    # Add our own library path to $shlibpath_var
5739d769e936Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740ec713c28Smrg
5741d769e936Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5742d769e936Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5743d769e936Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744d769e936Smrg
5745d769e936Smrg    export $shlibpath_var
5746d769e936Smrg"
5747ec713c28Smrg	fi
57481d54945dSmrg
5749d769e936Smrg	$ECHO "\
5750d769e936Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5751d769e936Smrg      # Run the actual program with our arguments.
5752d769e936Smrg      func_exec_program \${1+\"\$@\"}
5753d769e936Smrg    fi
5754d769e936Smrg  else
5755d769e936Smrg    # The program doesn't exist.
57567322289dSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5757d769e936Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5758d769e936Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5759d769e936Smrg    exit 1
5760d769e936Smrg  fi
5761d769e936Smrgfi\
5762d769e936Smrg"
5763d769e936Smrg}
57641d54945dSmrg
57651d54945dSmrg
5766d769e936Smrg# func_emit_cwrapperexe_src
5767d769e936Smrg# emit the source code for a wrapper executable on stdout
5768d769e936Smrg# Must ONLY be called from within func_mode_link because
5769d769e936Smrg# it depends on a number of variable set therein.
5770d769e936Smrgfunc_emit_cwrapperexe_src ()
5771d769e936Smrg{
5772d769e936Smrg	cat <<EOF
5773ec713c28Smrg
5774d769e936Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
57757322289dSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776ec713c28Smrg
5777d769e936Smrg   The $output program cannot be directly executed until all the libtool
5778d769e936Smrg   libraries that it depends on are installed.
5779ec713c28Smrg
5780d769e936Smrg   This wrapper executable should never be moved out of the build directory.
5781d769e936Smrg   If it is, it will not operate correctly.
5782d769e936Smrg*/
5783d769e936SmrgEOF
5784d769e936Smrg	    cat <<"EOF"
5785d769e936Smrg#ifdef _MSC_VER
5786d769e936Smrg# define _CRT_SECURE_NO_DEPRECATE 1
5787d769e936Smrg#endif
5788d769e936Smrg#include <stdio.h>
5789d769e936Smrg#include <stdlib.h>
5790d769e936Smrg#ifdef _MSC_VER
5791d769e936Smrg# include <direct.h>
5792d769e936Smrg# include <process.h>
5793d769e936Smrg# include <io.h>
5794d769e936Smrg#else
5795d769e936Smrg# include <unistd.h>
5796d769e936Smrg# include <stdint.h>
5797d769e936Smrg# ifdef __CYGWIN__
5798d769e936Smrg#  include <io.h>
5799d769e936Smrg# endif
5800d769e936Smrg#endif
5801d769e936Smrg#include <malloc.h>
5802d769e936Smrg#include <stdarg.h>
5803d769e936Smrg#include <assert.h>
5804d769e936Smrg#include <string.h>
5805d769e936Smrg#include <ctype.h>
5806d769e936Smrg#include <errno.h>
5807d769e936Smrg#include <fcntl.h>
5808d769e936Smrg#include <sys/stat.h>
5809ec713c28Smrg
58107322289dSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
58117322289dSmrg
5812d769e936Smrg/* declarations of non-ANSI functions */
58137322289dSmrg#if defined __MINGW32__
5814d769e936Smrg# ifdef __STRICT_ANSI__
5815d769e936Smrgint _putenv (const char *);
5816d769e936Smrg# endif
58177322289dSmrg#elif defined __CYGWIN__
5818d769e936Smrg# ifdef __STRICT_ANSI__
5819d769e936Smrgchar *realpath (const char *, char *);
5820d769e936Smrgint putenv (char *);
5821d769e936Smrgint setenv (const char *, const char *, int);
5822d769e936Smrg# endif
58237322289dSmrg/* #elif defined other_platform || defined ... */
5824d769e936Smrg#endif
58251d54945dSmrg
5826d769e936Smrg/* portability defines, excluding path handling macros */
58277322289dSmrg#if defined _MSC_VER
5828d769e936Smrg# define setmode _setmode
5829d769e936Smrg# define stat    _stat
5830d769e936Smrg# define chmod   _chmod
5831d769e936Smrg# define getcwd  _getcwd
5832d769e936Smrg# define putenv  _putenv
5833d769e936Smrg# define S_IXUSR _S_IEXEC
58347322289dSmrg#elif defined __MINGW32__
5835d769e936Smrg# define setmode _setmode
5836d769e936Smrg# define stat    _stat
5837d769e936Smrg# define chmod   _chmod
5838d769e936Smrg# define getcwd  _getcwd
5839d769e936Smrg# define putenv  _putenv
58407322289dSmrg#elif defined __CYGWIN__
5841d769e936Smrg# define HAVE_SETENV
5842d769e936Smrg# define FOPEN_WB "wb"
58437322289dSmrg/* #elif defined other platforms ... */
5844d769e936Smrg#endif
58451d54945dSmrg
58467322289dSmrg#if defined PATH_MAX
5847d769e936Smrg# define LT_PATHMAX PATH_MAX
58487322289dSmrg#elif defined MAXPATHLEN
5849d769e936Smrg# define LT_PATHMAX MAXPATHLEN
5850d769e936Smrg#else
5851d769e936Smrg# define LT_PATHMAX 1024
5852d769e936Smrg#endif
58531d54945dSmrg
5854d769e936Smrg#ifndef S_IXOTH
5855d769e936Smrg# define S_IXOTH 0
5856d769e936Smrg#endif
5857d769e936Smrg#ifndef S_IXGRP
5858d769e936Smrg# define S_IXGRP 0
5859d769e936Smrg#endif
58601d54945dSmrg
5861d769e936Smrg/* path handling portability macros */
5862d769e936Smrg#ifndef DIR_SEPARATOR
5863d769e936Smrg# define DIR_SEPARATOR '/'
5864d769e936Smrg# define PATH_SEPARATOR ':'
5865d769e936Smrg#endif
58661d54945dSmrg
58677322289dSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
58687322289dSmrg  defined __OS2__
5869d769e936Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5870d769e936Smrg# define FOPEN_WB "wb"
5871d769e936Smrg# ifndef DIR_SEPARATOR_2
5872d769e936Smrg#  define DIR_SEPARATOR_2 '\\'
5873d769e936Smrg# endif
5874d769e936Smrg# ifndef PATH_SEPARATOR_2
5875d769e936Smrg#  define PATH_SEPARATOR_2 ';'
5876d769e936Smrg# endif
5877d769e936Smrg#endif
58781d54945dSmrg
5879d769e936Smrg#ifndef DIR_SEPARATOR_2
5880d769e936Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5881d769e936Smrg#else /* DIR_SEPARATOR_2 */
5882d769e936Smrg# define IS_DIR_SEPARATOR(ch) \
5883d769e936Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5884d769e936Smrg#endif /* DIR_SEPARATOR_2 */
58851d54945dSmrg
5886d769e936Smrg#ifndef PATH_SEPARATOR_2
5887d769e936Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5888d769e936Smrg#else /* PATH_SEPARATOR_2 */
5889d769e936Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5890d769e936Smrg#endif /* PATH_SEPARATOR_2 */
58911d54945dSmrg
5892d769e936Smrg#ifndef FOPEN_WB
5893d769e936Smrg# define FOPEN_WB "w"
5894d769e936Smrg#endif
5895d769e936Smrg#ifndef _O_BINARY
5896d769e936Smrg# define _O_BINARY 0
5897d769e936Smrg#endif
58981d54945dSmrg
5899d769e936Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5900d769e936Smrg#define XFREE(stale) do { \
59017322289dSmrg  if (stale) { free (stale); stale = 0; } \
5902d769e936Smrg} while (0)
59031d54945dSmrg
59047322289dSmrg#if defined LT_DEBUGWRAPPER
5905d769e936Smrgstatic int lt_debug = 1;
5906d769e936Smrg#else
5907d769e936Smrgstatic int lt_debug = 0;
5908d769e936Smrg#endif
59091d54945dSmrg
5910d769e936Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5911d769e936Smrg
5912d769e936Smrgvoid *xmalloc (size_t num);
5913d769e936Smrgchar *xstrdup (const char *string);
5914d769e936Smrgconst char *base_name (const char *name);
5915d769e936Smrgchar *find_executable (const char *wrapper);
5916d769e936Smrgchar *chase_symlinks (const char *pathspec);
5917d769e936Smrgint make_executable (const char *path);
5918d769e936Smrgint check_executable (const char *path);
5919d769e936Smrgchar *strendzap (char *str, const char *pat);
5920d769e936Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5921d769e936Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5922d769e936Smrgstatic const char *nonnull (const char *s);
5923d769e936Smrgstatic const char *nonempty (const char *s);
5924d769e936Smrgvoid lt_setenv (const char *name, const char *value);
5925d769e936Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5926d769e936Smrgvoid lt_update_exe_path (const char *name, const char *value);
5927d769e936Smrgvoid lt_update_lib_path (const char *name, const char *value);
5928d769e936Smrgchar **prepare_spawn (char **argv);
5929d769e936Smrgvoid lt_dump_script (FILE *f);
5930d769e936SmrgEOF
59311d54945dSmrg
5932d769e936Smrg	    cat <<EOF
59337322289dSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
59347322289dSmrg# define externally_visible volatile
59357322289dSmrg#else
59367322289dSmrg# define externally_visible __attribute__((externally_visible)) volatile
59377322289dSmrg#endif
59387322289dSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5939d769e936Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5940d769e936SmrgEOF
59411d54945dSmrg
59427322289dSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943d769e936Smrg              func_to_host_path "$temp_rpath"
5944d769e936Smrg	      cat <<EOF
5945d769e936Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946d769e936SmrgEOF
5947d769e936Smrg	    else
5948d769e936Smrg	      cat <<"EOF"
5949d769e936Smrgconst char * LIB_PATH_VALUE   = "";
5950d769e936SmrgEOF
5951d769e936Smrg	    fi
59521d54945dSmrg
5953d769e936Smrg	    if test -n "$dllsearchpath"; then
5954d769e936Smrg              func_to_host_path "$dllsearchpath:"
5955d769e936Smrg	      cat <<EOF
5956d769e936Smrgconst char * EXE_PATH_VARNAME = "PATH";
5957d769e936Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958d769e936SmrgEOF
5959d769e936Smrg	    else
5960d769e936Smrg	      cat <<"EOF"
5961d769e936Smrgconst char * EXE_PATH_VARNAME = "";
5962d769e936Smrgconst char * EXE_PATH_VALUE   = "";
5963d769e936SmrgEOF
5964d769e936Smrg	    fi
59651d54945dSmrg
59667322289dSmrg	    if test yes = "$fast_install"; then
5967d769e936Smrg	      cat <<EOF
5968d769e936Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5969d769e936SmrgEOF
5970d769e936Smrg	    else
5971d769e936Smrg	      cat <<EOF
5972d769e936Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5973d769e936SmrgEOF
5974d769e936Smrg	    fi
59751d54945dSmrg
59761d54945dSmrg
5977d769e936Smrg	    cat <<"EOF"
59781d54945dSmrg
5979d769e936Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
59801d54945dSmrg
5981d769e936Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5982d769e936Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5983d769e936Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
59841d54945dSmrg
5985d769e936Smrgint
5986d769e936Smrgmain (int argc, char *argv[])
5987d769e936Smrg{
5988d769e936Smrg  char **newargz;
5989d769e936Smrg  int  newargc;
5990d769e936Smrg  char *tmp_pathspec;
5991d769e936Smrg  char *actual_cwrapper_path;
5992d769e936Smrg  char *actual_cwrapper_name;
5993d769e936Smrg  char *target_name;
5994d769e936Smrg  char *lt_argv_zero;
59957322289dSmrg  int rval = 127;
5996d769e936Smrg
5997d769e936Smrg  int i;
59981d54945dSmrg
5999d769e936Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
60007322289dSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
60011d54945dSmrg
6002d769e936Smrg  /* very simple arg parsing; don't want to rely on getopt
6003d769e936Smrg   * also, copy all non cwrapper options to newargz, except
6004d769e936Smrg   * argz[0], which is handled differently
6005d769e936Smrg   */
6006d769e936Smrg  newargc=0;
6007d769e936Smrg  for (i = 1; i < argc; i++)
6008d769e936Smrg    {
60097322289dSmrg      if (STREQ (argv[i], dumpscript_opt))
6010d769e936Smrg	{
6011d769e936SmrgEOF
60127322289dSmrg	    case $host in
6013d769e936Smrg	      *mingw* | *cygwin* )
6014d769e936Smrg		# make stdout use "unix" line endings
6015d769e936Smrg		echo "          setmode(1,_O_BINARY);"
6016d769e936Smrg		;;
6017d769e936Smrg	      esac
60181d54945dSmrg
6019d769e936Smrg	    cat <<"EOF"
6020d769e936Smrg	  lt_dump_script (stdout);
6021d769e936Smrg	  return 0;
6022d769e936Smrg	}
60237322289dSmrg      if (STREQ (argv[i], debug_opt))
6024d769e936Smrg	{
6025d769e936Smrg          lt_debug = 1;
6026d769e936Smrg          continue;
6027d769e936Smrg	}
60287322289dSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6029d769e936Smrg        {
6030d769e936Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6031d769e936Smrg             namespace, but it is not one of the ones we know about and
6032d769e936Smrg             have already dealt with, above (inluding dump-script), then
6033d769e936Smrg             report an error. Otherwise, targets might begin to believe
6034d769e936Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6035d769e936Smrg             namespace. The first time any user complains about this, we'll
6036d769e936Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6037d769e936Smrg             or a configure.ac-settable value.
6038d769e936Smrg           */
6039d769e936Smrg          lt_fatal (__FILE__, __LINE__,
6040d769e936Smrg		    "unrecognized %s option: '%s'",
6041d769e936Smrg                    ltwrapper_option_prefix, argv[i]);
6042d769e936Smrg        }
6043d769e936Smrg      /* otherwise ... */
6044d769e936Smrg      newargz[++newargc] = xstrdup (argv[i]);
6045d769e936Smrg    }
6046d769e936Smrg  newargz[++newargc] = NULL;
60471d54945dSmrg
6048d769e936SmrgEOF
6049d769e936Smrg	    cat <<EOF
6050d769e936Smrg  /* The GNU banner must be the first non-error debug message */
60517322289dSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6052d769e936SmrgEOF
6053d769e936Smrg	    cat <<"EOF"
6054d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6055d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6056d769e936Smrg
6057d769e936Smrg  tmp_pathspec = find_executable (argv[0]);
6058d769e936Smrg  if (tmp_pathspec == NULL)
6059d769e936Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6060d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6061d769e936Smrg                  "(main) found exe (before symlink chase) at: %s\n",
6062d769e936Smrg		  tmp_pathspec);
6063d769e936Smrg
6064d769e936Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6065d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6066d769e936Smrg                  "(main) found exe (after symlink chase) at: %s\n",
6067d769e936Smrg		  actual_cwrapper_path);
6068d769e936Smrg  XFREE (tmp_pathspec);
6069d769e936Smrg
6070d769e936Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6071d769e936Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6072d769e936Smrg
6073d769e936Smrg  /* wrapper name transforms */
6074d769e936Smrg  strendzap (actual_cwrapper_name, ".exe");
6075d769e936Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6076d769e936Smrg  XFREE (actual_cwrapper_name);
6077d769e936Smrg  actual_cwrapper_name = tmp_pathspec;
6078d769e936Smrg  tmp_pathspec = 0;
6079d769e936Smrg
6080d769e936Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6081d769e936Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6082d769e936Smrg  strendzap (target_name, ".exe");
6083d769e936Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6084d769e936Smrg  XFREE (target_name);
6085d769e936Smrg  target_name = tmp_pathspec;
6086d769e936Smrg  tmp_pathspec = 0;
6087d769e936Smrg
6088d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6089d769e936Smrg		  "(main) libtool target name: %s\n",
6090d769e936Smrg		  target_name);
6091d769e936SmrgEOF
6092d769e936Smrg
6093d769e936Smrg	    cat <<EOF
6094d769e936Smrg  newargz[0] =
6095d769e936Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6096d769e936Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6097d769e936Smrg  strcpy (newargz[0], actual_cwrapper_path);
6098d769e936Smrg  strcat (newargz[0], "$objdir");
6099d769e936Smrg  strcat (newargz[0], "/");
6100d769e936SmrgEOF
6101d769e936Smrg
6102d769e936Smrg	    cat <<"EOF"
6103d769e936Smrg  /* stop here, and copy so we don't have to do this twice */
6104d769e936Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105d769e936Smrg
6106d769e936Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6107d769e936Smrg  strcat (newargz[0], actual_cwrapper_name);
6108d769e936Smrg
6109d769e936Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6110d769e936Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6111d769e936Smrg  XFREE (tmp_pathspec);
6112d769e936Smrg  tmp_pathspec = NULL;
6113d769e936SmrgEOF
6114d769e936Smrg
6115d769e936Smrg	    case $host_os in
6116d769e936Smrg	      mingw*)
6117d769e936Smrg	    cat <<"EOF"
6118d769e936Smrg  {
6119d769e936Smrg    char* p;
6120d769e936Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6121d769e936Smrg      {
6122d769e936Smrg	*p = '/';
6123d769e936Smrg      }
6124d769e936Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6125d769e936Smrg      {
6126d769e936Smrg	*p = '/';
6127d769e936Smrg      }
6128d769e936Smrg  }
6129d769e936SmrgEOF
6130d769e936Smrg	    ;;
6131d769e936Smrg	    esac
6132d769e936Smrg
6133d769e936Smrg	    cat <<"EOF"
6134d769e936Smrg  XFREE (target_name);
6135d769e936Smrg  XFREE (actual_cwrapper_path);
6136d769e936Smrg  XFREE (actual_cwrapper_name);
6137d769e936Smrg
6138d769e936Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6139d769e936Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140d769e936Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141d769e936Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142d769e936Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143d769e936Smrg     libraries must come first. */
6144d769e936Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145d769e936Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146d769e936Smrg
6147d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6148d769e936Smrg		  nonnull (lt_argv_zero));
6149d769e936Smrg  for (i = 0; i < newargc; i++)
6150d769e936Smrg    {
6151d769e936Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6152d769e936Smrg		      i, nonnull (newargz[i]));
6153d769e936Smrg    }
6154d769e936Smrg
6155d769e936SmrgEOF
6156d769e936Smrg
6157d769e936Smrg	    case $host_os in
6158d769e936Smrg	      mingw*)
6159d769e936Smrg		cat <<"EOF"
6160d769e936Smrg  /* execv doesn't actually work on mingw as expected on unix */
6161d769e936Smrg  newargz = prepare_spawn (newargz);
61627322289dSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6163d769e936Smrg  if (rval == -1)
6164d769e936Smrg    {
6165d769e936Smrg      /* failed to start process */
6166d769e936Smrg      lt_debugprintf (__FILE__, __LINE__,
6167d769e936Smrg		      "(main) failed to launch target \"%s\": %s\n",
6168d769e936Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6169d769e936Smrg      return 127;
6170d769e936Smrg    }
6171d769e936Smrg  return rval;
6172d769e936SmrgEOF
6173ec713c28Smrg		;;
6174ec713c28Smrg	      *)
6175d769e936Smrg		cat <<"EOF"
6176d769e936Smrg  execv (lt_argv_zero, newargz);
6177d769e936Smrg  return rval; /* =127, but avoids unused variable warning */
6178d769e936SmrgEOF
6179ec713c28Smrg		;;
6180d769e936Smrg	    esac
61811d54945dSmrg
6182d769e936Smrg	    cat <<"EOF"
6183d769e936Smrg}
61841d54945dSmrg
6185d769e936Smrgvoid *
6186d769e936Smrgxmalloc (size_t num)
6187d769e936Smrg{
6188d769e936Smrg  void *p = (void *) malloc (num);
6189d769e936Smrg  if (!p)
6190d769e936Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
61911d54945dSmrg
6192d769e936Smrg  return p;
6193d769e936Smrg}
61941d54945dSmrg
6195d769e936Smrgchar *
6196d769e936Smrgxstrdup (const char *string)
6197d769e936Smrg{
6198d769e936Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6199d769e936Smrg			  string) : NULL;
6200d769e936Smrg}
62011d54945dSmrg
6202d769e936Smrgconst char *
6203d769e936Smrgbase_name (const char *name)
6204d769e936Smrg{
6205d769e936Smrg  const char *base;
62061d54945dSmrg
62077322289dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6208d769e936Smrg  /* Skip over the disk name in MSDOS pathnames. */
6209d769e936Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6210d769e936Smrg    name += 2;
6211ec713c28Smrg#endif
62121d54945dSmrg
6213d769e936Smrg  for (base = name; *name; name++)
6214d769e936Smrg    if (IS_DIR_SEPARATOR (*name))
6215d769e936Smrg      base = name + 1;
6216d769e936Smrg  return base;
6217d769e936Smrg}
62181d54945dSmrg
6219d769e936Smrgint
6220d769e936Smrgcheck_executable (const char *path)
6221d769e936Smrg{
6222d769e936Smrg  struct stat st;
62231d54945dSmrg
6224d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6225d769e936Smrg                  nonempty (path));
6226d769e936Smrg  if ((!path) || (!*path))
6227d769e936Smrg    return 0;
62281d54945dSmrg
6229d769e936Smrg  if ((stat (path, &st) >= 0)
6230d769e936Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6231d769e936Smrg    return 1;
6232d769e936Smrg  else
6233d769e936Smrg    return 0;
6234d769e936Smrg}
62351d54945dSmrg
6236d769e936Smrgint
6237d769e936Smrgmake_executable (const char *path)
6238d769e936Smrg{
6239d769e936Smrg  int rval = 0;
6240d769e936Smrg  struct stat st;
62411d54945dSmrg
6242d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6243d769e936Smrg                  nonempty (path));
6244d769e936Smrg  if ((!path) || (!*path))
6245d769e936Smrg    return 0;
62461d54945dSmrg
6247d769e936Smrg  if (stat (path, &st) >= 0)
6248d769e936Smrg    {
6249d769e936Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6250d769e936Smrg    }
6251d769e936Smrg  return rval;
6252d769e936Smrg}
62531d54945dSmrg
6254d769e936Smrg/* Searches for the full path of the wrapper.  Returns
6255d769e936Smrg   newly allocated full path name if found, NULL otherwise
6256d769e936Smrg   Does not chase symlinks, even on platforms that support them.
6257d769e936Smrg*/
6258d769e936Smrgchar *
6259d769e936Smrgfind_executable (const char *wrapper)
6260d769e936Smrg{
6261d769e936Smrg  int has_slash = 0;
6262d769e936Smrg  const char *p;
6263d769e936Smrg  const char *p_next;
6264d769e936Smrg  /* static buffer for getcwd */
6265d769e936Smrg  char tmp[LT_PATHMAX + 1];
62667322289dSmrg  size_t tmp_len;
6267d769e936Smrg  char *concat_name;
62681d54945dSmrg
6269d769e936Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6270d769e936Smrg                  nonempty (wrapper));
62711d54945dSmrg
6272d769e936Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6273d769e936Smrg    return NULL;
62741d54945dSmrg
6275d769e936Smrg  /* Absolute path? */
62767322289dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6277d769e936Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6278d769e936Smrg    {
6279d769e936Smrg      concat_name = xstrdup (wrapper);
6280d769e936Smrg      if (check_executable (concat_name))
6281d769e936Smrg	return concat_name;
6282d769e936Smrg      XFREE (concat_name);
6283d769e936Smrg    }
6284d769e936Smrg  else
6285d769e936Smrg    {
6286d769e936Smrg#endif
6287d769e936Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6288d769e936Smrg	{
6289d769e936Smrg	  concat_name = xstrdup (wrapper);
6290d769e936Smrg	  if (check_executable (concat_name))
6291d769e936Smrg	    return concat_name;
6292d769e936Smrg	  XFREE (concat_name);
6293d769e936Smrg	}
62947322289dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6295d769e936Smrg    }
6296d769e936Smrg#endif
62971d54945dSmrg
6298d769e936Smrg  for (p = wrapper; *p; p++)
6299d769e936Smrg    if (*p == '/')
6300d769e936Smrg      {
6301d769e936Smrg	has_slash = 1;
6302d769e936Smrg	break;
6303d769e936Smrg      }
6304d769e936Smrg  if (!has_slash)
6305d769e936Smrg    {
6306d769e936Smrg      /* no slashes; search PATH */
6307d769e936Smrg      const char *path = getenv ("PATH");
6308d769e936Smrg      if (path != NULL)
6309d769e936Smrg	{
6310d769e936Smrg	  for (p = path; *p; p = p_next)
6311d769e936Smrg	    {
6312d769e936Smrg	      const char *q;
6313d769e936Smrg	      size_t p_len;
6314d769e936Smrg	      for (q = p; *q; q++)
6315d769e936Smrg		if (IS_PATH_SEPARATOR (*q))
6316d769e936Smrg		  break;
63177322289dSmrg	      p_len = (size_t) (q - p);
6318d769e936Smrg	      p_next = (*q == '\0' ? q : q + 1);
6319d769e936Smrg	      if (p_len == 0)
6320d769e936Smrg		{
6321d769e936Smrg		  /* empty path: current directory */
6322d769e936Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6323d769e936Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6324d769e936Smrg                              nonnull (strerror (errno)));
6325d769e936Smrg		  tmp_len = strlen (tmp);
6326d769e936Smrg		  concat_name =
6327d769e936Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6328d769e936Smrg		  memcpy (concat_name, tmp, tmp_len);
6329d769e936Smrg		  concat_name[tmp_len] = '/';
6330d769e936Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6331d769e936Smrg		}
6332d769e936Smrg	      else
6333d769e936Smrg		{
6334d769e936Smrg		  concat_name =
6335d769e936Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6336d769e936Smrg		  memcpy (concat_name, p, p_len);
6337d769e936Smrg		  concat_name[p_len] = '/';
6338d769e936Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6339d769e936Smrg		}
6340d769e936Smrg	      if (check_executable (concat_name))
6341d769e936Smrg		return concat_name;
6342d769e936Smrg	      XFREE (concat_name);
6343d769e936Smrg	    }
6344d769e936Smrg	}
6345d769e936Smrg      /* not found in PATH; assume curdir */
6346d769e936Smrg    }
6347d769e936Smrg  /* Relative path | not found in path: prepend cwd */
6348d769e936Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6349d769e936Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6350d769e936Smrg              nonnull (strerror (errno)));
6351d769e936Smrg  tmp_len = strlen (tmp);
6352d769e936Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6353d769e936Smrg  memcpy (concat_name, tmp, tmp_len);
6354d769e936Smrg  concat_name[tmp_len] = '/';
6355d769e936Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
63561d54945dSmrg
6357d769e936Smrg  if (check_executable (concat_name))
6358d769e936Smrg    return concat_name;
6359d769e936Smrg  XFREE (concat_name);
6360d769e936Smrg  return NULL;
6361d769e936Smrg}
63621d54945dSmrg
6363d769e936Smrgchar *
6364d769e936Smrgchase_symlinks (const char *pathspec)
6365d769e936Smrg{
6366d769e936Smrg#ifndef S_ISLNK
6367d769e936Smrg  return xstrdup (pathspec);
6368d769e936Smrg#else
6369d769e936Smrg  char buf[LT_PATHMAX];
6370d769e936Smrg  struct stat s;
6371d769e936Smrg  char *tmp_pathspec = xstrdup (pathspec);
6372d769e936Smrg  char *p;
6373d769e936Smrg  int has_symlinks = 0;
6374d769e936Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6375d769e936Smrg    {
6376d769e936Smrg      lt_debugprintf (__FILE__, __LINE__,
6377d769e936Smrg		      "checking path component for symlinks: %s\n",
6378d769e936Smrg		      tmp_pathspec);
6379d769e936Smrg      if (lstat (tmp_pathspec, &s) == 0)
6380d769e936Smrg	{
6381d769e936Smrg	  if (S_ISLNK (s.st_mode) != 0)
6382d769e936Smrg	    {
6383d769e936Smrg	      has_symlinks = 1;
6384d769e936Smrg	      break;
6385d769e936Smrg	    }
6386d769e936Smrg
6387d769e936Smrg	  /* search backwards for last DIR_SEPARATOR */
6388d769e936Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6389d769e936Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6390d769e936Smrg	    p--;
6391d769e936Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6392d769e936Smrg	    {
6393d769e936Smrg	      /* no more DIR_SEPARATORS left */
6394d769e936Smrg	      break;
6395d769e936Smrg	    }
6396d769e936Smrg	  *p = '\0';
6397d769e936Smrg	}
6398d769e936Smrg      else
6399d769e936Smrg	{
6400d769e936Smrg	  lt_fatal (__FILE__, __LINE__,
6401d769e936Smrg		    "error accessing file \"%s\": %s",
6402d769e936Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6403d769e936Smrg	}
6404d769e936Smrg    }
6405d769e936Smrg  XFREE (tmp_pathspec);
64061d54945dSmrg
6407d769e936Smrg  if (!has_symlinks)
6408d769e936Smrg    {
6409d769e936Smrg      return xstrdup (pathspec);
6410d769e936Smrg    }
6411ba85709eSmrg
6412d769e936Smrg  tmp_pathspec = realpath (pathspec, buf);
6413d769e936Smrg  if (tmp_pathspec == 0)
6414d769e936Smrg    {
6415d769e936Smrg      lt_fatal (__FILE__, __LINE__,
6416d769e936Smrg		"could not follow symlinks for %s", pathspec);
6417d769e936Smrg    }
6418d769e936Smrg  return xstrdup (tmp_pathspec);
6419ec713c28Smrg#endif
6420d769e936Smrg}
64211d54945dSmrg
6422d769e936Smrgchar *
6423d769e936Smrgstrendzap (char *str, const char *pat)
6424d769e936Smrg{
6425d769e936Smrg  size_t len, patlen;
64261d54945dSmrg
6427d769e936Smrg  assert (str != NULL);
6428d769e936Smrg  assert (pat != NULL);
64291d54945dSmrg
6430d769e936Smrg  len = strlen (str);
6431d769e936Smrg  patlen = strlen (pat);
64321d54945dSmrg
6433d769e936Smrg  if (patlen <= len)
6434d769e936Smrg    {
6435d769e936Smrg      str += len - patlen;
64367322289dSmrg      if (STREQ (str, pat))
6437d769e936Smrg	*str = '\0';
6438d769e936Smrg    }
6439d769e936Smrg  return str;
6440ec713c28Smrg}
64411d54945dSmrg
6442d769e936Smrgvoid
6443d769e936Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6444d769e936Smrg{
6445d769e936Smrg  va_list args;
6446d769e936Smrg  if (lt_debug)
6447d769e936Smrg    {
6448d769e936Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6449d769e936Smrg      va_start (args, fmt);
6450d769e936Smrg      (void) vfprintf (stderr, fmt, args);
6451d769e936Smrg      va_end (args);
6452d769e936Smrg    }
6453d769e936Smrg}
64541d54945dSmrg
6455d769e936Smrgstatic void
6456d769e936Smrglt_error_core (int exit_status, const char *file,
6457d769e936Smrg	       int line, const char *mode,
6458d769e936Smrg	       const char *message, va_list ap)
6459d769e936Smrg{
6460d769e936Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6461d769e936Smrg  vfprintf (stderr, message, ap);
6462d769e936Smrg  fprintf (stderr, ".\n");
64631d54945dSmrg
6464d769e936Smrg  if (exit_status >= 0)
6465d769e936Smrg    exit (exit_status);
6466ec713c28Smrg}
64671d54945dSmrg
6468d769e936Smrgvoid
6469d769e936Smrglt_fatal (const char *file, int line, const char *message, ...)
6470d769e936Smrg{
6471d769e936Smrg  va_list ap;
6472d769e936Smrg  va_start (ap, message);
6473d769e936Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6474d769e936Smrg  va_end (ap);
6475ec713c28Smrg}
64761d54945dSmrg
6477d769e936Smrgstatic const char *
6478d769e936Smrgnonnull (const char *s)
6479d769e936Smrg{
6480d769e936Smrg  return s ? s : "(null)";
6481d769e936Smrg}
6482786a6f21Smrg
6483d769e936Smrgstatic const char *
6484d769e936Smrgnonempty (const char *s)
6485d769e936Smrg{
6486d769e936Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
6487d769e936Smrg}
64881d54945dSmrg
6489d769e936Smrgvoid
6490d769e936Smrglt_setenv (const char *name, const char *value)
6491d769e936Smrg{
6492d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6493d769e936Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
6494d769e936Smrg                  nonnull (name), nonnull (value));
6495d769e936Smrg  {
6496d769e936Smrg#ifdef HAVE_SETENV
6497d769e936Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6498d769e936Smrg    char *str = xstrdup (value);
6499d769e936Smrg    setenv (name, str, 1);
6500d769e936Smrg#else
65017322289dSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6502d769e936Smrg    char *str = XMALLOC (char, len);
6503d769e936Smrg    sprintf (str, "%s=%s", name, value);
6504d769e936Smrg    if (putenv (str) != EXIT_SUCCESS)
6505d769e936Smrg      {
6506d769e936Smrg        XFREE (str);
6507d769e936Smrg      }
6508d769e936Smrg#endif
6509d769e936Smrg  }
6510d769e936Smrg}
65111d54945dSmrg
6512d769e936Smrgchar *
6513d769e936Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6514d769e936Smrg{
6515d769e936Smrg  char *new_value;
6516d769e936Smrg  if (orig_value && *orig_value)
6517d769e936Smrg    {
65187322289dSmrg      size_t orig_value_len = strlen (orig_value);
65197322289dSmrg      size_t add_len = strlen (add);
6520d769e936Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6521d769e936Smrg      if (to_end)
6522d769e936Smrg        {
6523d769e936Smrg          strcpy (new_value, orig_value);
6524d769e936Smrg          strcpy (new_value + orig_value_len, add);
6525d769e936Smrg        }
6526ec713c28Smrg      else
6527d769e936Smrg        {
6528d769e936Smrg          strcpy (new_value, add);
6529d769e936Smrg          strcpy (new_value + add_len, orig_value);
6530d769e936Smrg        }
6531d769e936Smrg    }
6532d769e936Smrg  else
6533d769e936Smrg    {
6534d769e936Smrg      new_value = xstrdup (add);
6535d769e936Smrg    }
6536d769e936Smrg  return new_value;
6537d769e936Smrg}
6538786a6f21Smrg
6539d769e936Smrgvoid
6540d769e936Smrglt_update_exe_path (const char *name, const char *value)
6541d769e936Smrg{
6542d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6543d769e936Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6544d769e936Smrg                  nonnull (name), nonnull (value));
6545786a6f21Smrg
6546d769e936Smrg  if (name && *name && value && *value)
6547d769e936Smrg    {
6548d769e936Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6549d769e936Smrg      /* some systems can't cope with a ':'-terminated path #' */
65507322289dSmrg      size_t len = strlen (new_value);
65517322289dSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6552d769e936Smrg        {
65537322289dSmrg          new_value[--len] = '\0';
6554d769e936Smrg        }
6555d769e936Smrg      lt_setenv (name, new_value);
6556d769e936Smrg      XFREE (new_value);
6557d769e936Smrg    }
6558d769e936Smrg}
6559786a6f21Smrg
6560d769e936Smrgvoid
6561d769e936Smrglt_update_lib_path (const char *name, const char *value)
6562d769e936Smrg{
6563d769e936Smrg  lt_debugprintf (__FILE__, __LINE__,
6564d769e936Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6565d769e936Smrg                  nonnull (name), nonnull (value));
6566786a6f21Smrg
6567d769e936Smrg  if (name && *name && value && *value)
6568d769e936Smrg    {
6569d769e936Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6570d769e936Smrg      lt_setenv (name, new_value);
6571d769e936Smrg      XFREE (new_value);
6572d769e936Smrg    }
6573d769e936Smrg}
6574786a6f21Smrg
6575ec713c28SmrgEOF
6576d769e936Smrg	    case $host_os in
6577d769e936Smrg	      mingw*)
6578d769e936Smrg		cat <<"EOF"
6579d769e936Smrg
6580d769e936Smrg/* Prepares an argument vector before calling spawn().
6581d769e936Smrg   Note that spawn() does not by itself call the command interpreter
6582d769e936Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6583d769e936Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6584d769e936Smrg         GetVersionEx(&v);
6585d769e936Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6586d769e936Smrg      }) ? "cmd.exe" : "command.com").
6587d769e936Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6588d769e936Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6589d769e936Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6590d769e936Smrg   special way:
6591d769e936Smrg   - Space and tab are interpreted as delimiters. They are not treated as
6592d769e936Smrg     delimiters if they are surrounded by double quotes: "...".
6593d769e936Smrg   - Unescaped double quotes are removed from the input. Their only effect is
6594d769e936Smrg     that within double quotes, space and tab are treated like normal
6595d769e936Smrg     characters.
6596d769e936Smrg   - Backslashes not followed by double quotes are not special.
6597d769e936Smrg   - But 2*n+1 backslashes followed by a double quote become
6598d769e936Smrg     n backslashes followed by a double quote (n >= 0):
6599d769e936Smrg       \" -> "
6600d769e936Smrg       \\\" -> \"
6601d769e936Smrg       \\\\\" -> \\"
6602d769e936Smrg */
6603d769e936Smrg#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"
6604d769e936Smrg#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"
6605d769e936Smrgchar **
6606d769e936Smrgprepare_spawn (char **argv)
6607ec713c28Smrg{
6608d769e936Smrg  size_t argc;
6609d769e936Smrg  char **new_argv;
6610d769e936Smrg  size_t i;
6611786a6f21Smrg
6612d769e936Smrg  /* Count number of arguments.  */
6613d769e936Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6614d769e936Smrg    ;
6615786a6f21Smrg
6616d769e936Smrg  /* Allocate new argument vector.  */
6617d769e936Smrg  new_argv = XMALLOC (char *, argc + 1);
6618786a6f21Smrg
6619d769e936Smrg  /* Put quoted arguments into the new argument vector.  */
6620d769e936Smrg  for (i = 0; i < argc; i++)
6621d769e936Smrg    {
6622d769e936Smrg      const char *string = argv[i];
6623d769e936Smrg
6624d769e936Smrg      if (string[0] == '\0')
6625d769e936Smrg	new_argv[i] = xstrdup ("\"\"");
6626d769e936Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6627d769e936Smrg	{
6628d769e936Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6629d769e936Smrg	  size_t length;
6630d769e936Smrg	  unsigned int backslashes;
6631d769e936Smrg	  const char *s;
6632d769e936Smrg	  char *quoted_string;
6633d769e936Smrg	  char *p;
6634d769e936Smrg
6635d769e936Smrg	  length = 0;
6636d769e936Smrg	  backslashes = 0;
6637d769e936Smrg	  if (quote_around)
6638d769e936Smrg	    length++;
6639d769e936Smrg	  for (s = string; *s != '\0'; s++)
6640d769e936Smrg	    {
6641d769e936Smrg	      char c = *s;
6642d769e936Smrg	      if (c == '"')
6643d769e936Smrg		length += backslashes + 1;
6644d769e936Smrg	      length++;
6645d769e936Smrg	      if (c == '\\')
6646d769e936Smrg		backslashes++;
6647d769e936Smrg	      else
6648d769e936Smrg		backslashes = 0;
6649d769e936Smrg	    }
6650d769e936Smrg	  if (quote_around)
6651d769e936Smrg	    length += backslashes + 1;
6652d769e936Smrg
6653d769e936Smrg	  quoted_string = XMALLOC (char, length + 1);
6654d769e936Smrg
6655d769e936Smrg	  p = quoted_string;
6656d769e936Smrg	  backslashes = 0;
6657d769e936Smrg	  if (quote_around)
6658d769e936Smrg	    *p++ = '"';
6659d769e936Smrg	  for (s = string; *s != '\0'; s++)
6660d769e936Smrg	    {
6661d769e936Smrg	      char c = *s;
6662d769e936Smrg	      if (c == '"')
6663d769e936Smrg		{
6664d769e936Smrg		  unsigned int j;
6665d769e936Smrg		  for (j = backslashes + 1; j > 0; j--)
6666d769e936Smrg		    *p++ = '\\';
6667d769e936Smrg		}
6668d769e936Smrg	      *p++ = c;
6669d769e936Smrg	      if (c == '\\')
6670d769e936Smrg		backslashes++;
6671d769e936Smrg	      else
6672d769e936Smrg		backslashes = 0;
6673d769e936Smrg	    }
6674d769e936Smrg	  if (quote_around)
6675d769e936Smrg	    {
6676d769e936Smrg	      unsigned int j;
6677d769e936Smrg	      for (j = backslashes; j > 0; j--)
6678d769e936Smrg		*p++ = '\\';
6679d769e936Smrg	      *p++ = '"';
6680d769e936Smrg	    }
6681d769e936Smrg	  *p = '\0';
6682786a6f21Smrg
6683d769e936Smrg	  new_argv[i] = quoted_string;
6684d769e936Smrg	}
6685d769e936Smrg      else
6686d769e936Smrg	new_argv[i] = (char *) string;
6687d769e936Smrg    }
6688d769e936Smrg  new_argv[argc] = NULL;
6689786a6f21Smrg
6690d769e936Smrg  return new_argv;
6691d769e936Smrg}
6692ec713c28SmrgEOF
6693d769e936Smrg		;;
6694d769e936Smrg	    esac
6695786a6f21Smrg
6696d769e936Smrg            cat <<"EOF"
6697d769e936Smrgvoid lt_dump_script (FILE* f)
6698d769e936Smrg{
6699ec713c28SmrgEOF
6700d769e936Smrg	    func_emit_wrapper yes |
6701d769e936Smrg	      $SED -n -e '
6702d769e936Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703d769e936Smrg\2/
6704d769e936Smrgh
6705d769e936Smrgs/\([\\"]\)/\\\1/g
6706d769e936Smrgs/$/\\n/
6707d769e936Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708d769e936Smrgg
6709d769e936SmrgD'
6710d769e936Smrg            cat <<"EOF"
6711ec713c28Smrg}
6712d769e936SmrgEOF
6713ec713c28Smrg}
6714d769e936Smrg# end: func_emit_cwrapperexe_src
6715786a6f21Smrg
6716d769e936Smrg# func_win32_import_lib_p ARG
6717d769e936Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6718d769e936Smrgfunc_win32_import_lib_p ()
6719ec713c28Smrg{
67207322289dSmrg    $debug_cmd
67217322289dSmrg
6722d769e936Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6723d769e936Smrg    *import*) : ;;
6724d769e936Smrg    *) false ;;
6725d769e936Smrg    esac
6726ec713c28Smrg}
6727786a6f21Smrg
67287322289dSmrg# func_suncc_cstd_abi
67297322289dSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
67307322289dSmrg# Several compiler flags select an ABI that is incompatible with the
67317322289dSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
67327322289dSmrgfunc_suncc_cstd_abi ()
67337322289dSmrg{
67347322289dSmrg    $debug_cmd
67357322289dSmrg
67367322289dSmrg    case " $compile_command " in
67377322289dSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
67387322289dSmrg      suncc_use_cstd_abi=no
67397322289dSmrg      ;;
67407322289dSmrg    *)
67417322289dSmrg      suncc_use_cstd_abi=yes
67427322289dSmrg      ;;
67437322289dSmrg    esac
67447322289dSmrg}
67457322289dSmrg
6746d769e936Smrg# func_mode_link arg...
6747d769e936Smrgfunc_mode_link ()
6748ec713c28Smrg{
67497322289dSmrg    $debug_cmd
67507322289dSmrg
6751d769e936Smrg    case $host in
6752d769e936Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6753d769e936Smrg      # It is impossible to link a dll without this setting, and
6754d769e936Smrg      # we shouldn't force the makefile maintainer to figure out
67557322289dSmrg      # what system we are compiling for in order to pass an extra
6756d769e936Smrg      # flag for every libtool invocation.
6757d769e936Smrg      # allow_undefined=no
6758786a6f21Smrg
6759d769e936Smrg      # FIXME: Unfortunately, there are problems with the above when trying
67607322289dSmrg      # to make a dll that has undefined symbols, in which case not
6761d769e936Smrg      # even a static library is built.  For now, we need to specify
6762d769e936Smrg      # -no-undefined on the libtool link line when we can be certain
6763d769e936Smrg      # that all symbols are satisfied, otherwise we get a static library.
6764d769e936Smrg      allow_undefined=yes
6765d769e936Smrg      ;;
6766d769e936Smrg    *)
6767d769e936Smrg      allow_undefined=yes
6768d769e936Smrg      ;;
6769d769e936Smrg    esac
6770d769e936Smrg    libtool_args=$nonopt
6771d769e936Smrg    base_compile="$nonopt $@"
6772d769e936Smrg    compile_command=$nonopt
6773d769e936Smrg    finalize_command=$nonopt
6774786a6f21Smrg
6775d769e936Smrg    compile_rpath=
6776d769e936Smrg    finalize_rpath=
6777d769e936Smrg    compile_shlibpath=
6778d769e936Smrg    finalize_shlibpath=
6779d769e936Smrg    convenience=
6780d769e936Smrg    old_convenience=
6781d769e936Smrg    deplibs=
6782d769e936Smrg    old_deplibs=
6783d769e936Smrg    compiler_flags=
6784d769e936Smrg    linker_flags=
6785d769e936Smrg    dllsearchpath=
6786d769e936Smrg    lib_search_path=`pwd`
6787d769e936Smrg    inst_prefix_dir=
6788d769e936Smrg    new_inherited_linker_flags=
6789786a6f21Smrg
6790d769e936Smrg    avoid_version=no
6791d769e936Smrg    bindir=
6792d769e936Smrg    dlfiles=
6793d769e936Smrg    dlprefiles=
6794d769e936Smrg    dlself=no
6795d769e936Smrg    export_dynamic=no
6796d769e936Smrg    export_symbols=
6797d769e936Smrg    export_symbols_regex=
6798d769e936Smrg    generated=
6799d769e936Smrg    libobjs=
6800d769e936Smrg    ltlibs=
6801d769e936Smrg    module=no
6802d769e936Smrg    no_install=no
6803d769e936Smrg    objs=
68047322289dSmrg    os2dllname=
6805d769e936Smrg    non_pic_objects=
6806d769e936Smrg    precious_files_regex=
6807d769e936Smrg    prefer_static_libs=no
68087322289dSmrg    preload=false
6809d769e936Smrg    prev=
6810d769e936Smrg    prevarg=
6811d769e936Smrg    release=
6812d769e936Smrg    rpath=
6813d769e936Smrg    xrpath=
6814d769e936Smrg    perm_rpath=
6815d769e936Smrg    temp_rpath=
6816d769e936Smrg    thread_safe=no
6817d769e936Smrg    vinfo=
6818d769e936Smrg    vinfo_number=no
6819d769e936Smrg    weak_libs=
68207322289dSmrg    single_module=$wl-single_module
6821d769e936Smrg    func_infer_tag $base_compile
68221d54945dSmrg
6823d769e936Smrg    # We need to know -static, to get the right output filenames.
6824d769e936Smrg    for arg
6825d769e936Smrg    do
6826d769e936Smrg      case $arg in
6827d769e936Smrg      -shared)
68287322289dSmrg	test yes != "$build_libtool_libs" \
68297322289dSmrg	  && func_fatal_configuration "cannot build a shared library"
6830d769e936Smrg	build_old_libs=no
6831d769e936Smrg	break
6832d769e936Smrg	;;
6833d769e936Smrg      -all-static | -static | -static-libtool-libs)
6834d769e936Smrg	case $arg in
6835d769e936Smrg	-all-static)
68367322289dSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6837d769e936Smrg	    func_warning "complete static linking is impossible in this configuration"
6838d769e936Smrg	  fi
6839d769e936Smrg	  if test -n "$link_static_flag"; then
6840d769e936Smrg	    dlopen_self=$dlopen_self_static
6841d769e936Smrg	  fi
6842d769e936Smrg	  prefer_static_libs=yes
6843d769e936Smrg	  ;;
6844d769e936Smrg	-static)
6845d769e936Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6846d769e936Smrg	    dlopen_self=$dlopen_self_static
6847d769e936Smrg	  fi
6848d769e936Smrg	  prefer_static_libs=built
6849d769e936Smrg	  ;;
6850d769e936Smrg	-static-libtool-libs)
6851d769e936Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6852d769e936Smrg	    dlopen_self=$dlopen_self_static
6853d769e936Smrg	  fi
6854d769e936Smrg	  prefer_static_libs=yes
6855d769e936Smrg	  ;;
6856d769e936Smrg	esac
6857d769e936Smrg	build_libtool_libs=no
6858d769e936Smrg	build_old_libs=yes
6859d769e936Smrg	break
6860d769e936Smrg	;;
6861d769e936Smrg      esac
6862d769e936Smrg    done
68631d54945dSmrg
6864d769e936Smrg    # See if our shared archives depend on static archives.
6865d769e936Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
68661d54945dSmrg
6867d769e936Smrg    # Go through the arguments, transforming them on the way.
6868d769e936Smrg    while test "$#" -gt 0; do
68697322289dSmrg      arg=$1
6870d769e936Smrg      shift
687122663e35Smrg      func_quote_arg pretty,unquoted "$arg"
687222663e35Smrg      qarg=$func_quote_arg_unquoted_result
687322663e35Smrg      func_append libtool_args " $func_quote_arg_result"
68741d54945dSmrg
6875d769e936Smrg      # If the previous option needs an argument, assign it.
6876d769e936Smrg      if test -n "$prev"; then
6877d769e936Smrg	case $prev in
6878d769e936Smrg	output)
6879d769e936Smrg	  func_append compile_command " @OUTPUT@"
6880d769e936Smrg	  func_append finalize_command " @OUTPUT@"
6881d769e936Smrg	  ;;
6882d769e936Smrg	esac
6883ec713c28Smrg
6884d769e936Smrg	case $prev in
6885d769e936Smrg	bindir)
68867322289dSmrg	  bindir=$arg
6887d769e936Smrg	  prev=
6888d769e936Smrg	  continue
6889d769e936Smrg	  ;;
6890d769e936Smrg	dlfiles|dlprefiles)
68917322289dSmrg	  $preload || {
6892d769e936Smrg	    # Add the symbol object into the linking commands.
6893d769e936Smrg	    func_append compile_command " @SYMFILE@"
6894d769e936Smrg	    func_append finalize_command " @SYMFILE@"
68957322289dSmrg	    preload=:
68967322289dSmrg	  }
6897d769e936Smrg	  case $arg in
6898d769e936Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6899d769e936Smrg	  force)
69007322289dSmrg	    if test no = "$dlself"; then
6901d769e936Smrg	      dlself=needless
6902d769e936Smrg	      export_dynamic=yes
6903d769e936Smrg	    fi
6904d769e936Smrg	    prev=
6905d769e936Smrg	    continue
6906d769e936Smrg	    ;;
6907d769e936Smrg	  self)
69087322289dSmrg	    if test dlprefiles = "$prev"; then
6909d769e936Smrg	      dlself=yes
69107322289dSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6911d769e936Smrg	      dlself=yes
6912d769e936Smrg	    else
6913d769e936Smrg	      dlself=needless
6914d769e936Smrg	      export_dynamic=yes
6915d769e936Smrg	    fi
6916d769e936Smrg	    prev=
6917d769e936Smrg	    continue
6918d769e936Smrg	    ;;
6919d769e936Smrg	  *)
69207322289dSmrg	    if test dlfiles = "$prev"; then
6921d769e936Smrg	      func_append dlfiles " $arg"
6922d769e936Smrg	    else
6923d769e936Smrg	      func_append dlprefiles " $arg"
6924d769e936Smrg	    fi
6925d769e936Smrg	    prev=
6926d769e936Smrg	    continue
6927d769e936Smrg	    ;;
6928d769e936Smrg	  esac
6929d769e936Smrg	  ;;
6930d769e936Smrg	expsyms)
69317322289dSmrg	  export_symbols=$arg
6932d769e936Smrg	  test -f "$arg" \
69337322289dSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6934d769e936Smrg	  prev=
6935d769e936Smrg	  continue
6936d769e936Smrg	  ;;
6937d769e936Smrg	expsyms_regex)
69387322289dSmrg	  export_symbols_regex=$arg
6939d769e936Smrg	  prev=
6940d769e936Smrg	  continue
6941d769e936Smrg	  ;;
6942d769e936Smrg	framework)
6943d769e936Smrg	  case $host in
6944d769e936Smrg	    *-*-darwin*)
6945d769e936Smrg	      case "$deplibs " in
6946d769e936Smrg		*" $qarg.ltframework "*) ;;
6947d769e936Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6948d769e936Smrg		   ;;
6949d769e936Smrg	      esac
6950d769e936Smrg	      ;;
6951d769e936Smrg	  esac
6952d769e936Smrg	  prev=
6953d769e936Smrg	  continue
6954d769e936Smrg	  ;;
6955d769e936Smrg	inst_prefix)
69567322289dSmrg	  inst_prefix_dir=$arg
69577322289dSmrg	  prev=
69587322289dSmrg	  continue
69597322289dSmrg	  ;;
69607322289dSmrg	mllvm)
69617322289dSmrg	  # Clang does not use LLVM to link, so we can simply discard any
69627322289dSmrg	  # '-mllvm $arg' options when doing the link step.
6963d769e936Smrg	  prev=
6964d769e936Smrg	  continue
6965d769e936Smrg	  ;;
6966d769e936Smrg	objectlist)
6967d769e936Smrg	  if test -f "$arg"; then
6968d769e936Smrg	    save_arg=$arg
6969d769e936Smrg	    moreargs=
6970d769e936Smrg	    for fil in `cat "$save_arg"`
6971d769e936Smrg	    do
6972d769e936Smrg#	      func_append moreargs " $fil"
6973d769e936Smrg	      arg=$fil
6974d769e936Smrg	      # A libtool-controlled object.
6975ec713c28Smrg
6976d769e936Smrg	      # Check to see that this really is a libtool object.
6977d769e936Smrg	      if func_lalib_unsafe_p "$arg"; then
6978d769e936Smrg		pic_object=
6979d769e936Smrg		non_pic_object=
6980ec713c28Smrg
6981d769e936Smrg		# Read the .lo file
6982d769e936Smrg		func_source "$arg"
6983ec713c28Smrg
6984d769e936Smrg		if test -z "$pic_object" ||
6985d769e936Smrg		   test -z "$non_pic_object" ||
69867322289dSmrg		   test none = "$pic_object" &&
69877322289dSmrg		   test none = "$non_pic_object"; then
69887322289dSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6989d769e936Smrg		fi
6990ec713c28Smrg
6991d769e936Smrg		# Extract subdirectory from the argument.
6992d769e936Smrg		func_dirname "$arg" "/" ""
69937322289dSmrg		xdir=$func_dirname_result
6994ec713c28Smrg
69957322289dSmrg		if test none != "$pic_object"; then
6996d769e936Smrg		  # Prepend the subdirectory the object is found in.
69977322289dSmrg		  pic_object=$xdir$pic_object
6998ec713c28Smrg
69997322289dSmrg		  if test dlfiles = "$prev"; then
70007322289dSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001d769e936Smrg		      func_append dlfiles " $pic_object"
7002d769e936Smrg		      prev=
7003d769e936Smrg		      continue
7004d769e936Smrg		    else
7005d769e936Smrg		      # If libtool objects are unsupported, then we need to preload.
7006d769e936Smrg		      prev=dlprefiles
7007d769e936Smrg		    fi
7008d769e936Smrg		  fi
7009ec713c28Smrg
7010d769e936Smrg		  # CHECK ME:  I think I busted this.  -Ossama
70117322289dSmrg		  if test dlprefiles = "$prev"; then
7012d769e936Smrg		    # Preload the old-style object.
7013d769e936Smrg		    func_append dlprefiles " $pic_object"
7014d769e936Smrg		    prev=
7015d769e936Smrg		  fi
7016ec713c28Smrg
7017d769e936Smrg		  # A PIC object.
7018d769e936Smrg		  func_append libobjs " $pic_object"
70197322289dSmrg		  arg=$pic_object
7020d769e936Smrg		fi
7021ec713c28Smrg
7022d769e936Smrg		# Non-PIC object.
70237322289dSmrg		if test none != "$non_pic_object"; then
7024d769e936Smrg		  # Prepend the subdirectory the object is found in.
70257322289dSmrg		  non_pic_object=$xdir$non_pic_object
7026ec713c28Smrg
7027d769e936Smrg		  # A standard non-PIC object
7028d769e936Smrg		  func_append non_pic_objects " $non_pic_object"
70297322289dSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
70307322289dSmrg		    arg=$non_pic_object
7031d769e936Smrg		  fi
7032d769e936Smrg		else
7033d769e936Smrg		  # If the PIC object exists, use it instead.
7034d769e936Smrg		  # $xdir was prepended to $pic_object above.
70357322289dSmrg		  non_pic_object=$pic_object
7036d769e936Smrg		  func_append non_pic_objects " $non_pic_object"
7037d769e936Smrg		fi
7038d769e936Smrg	      else
7039d769e936Smrg		# Only an error if not doing a dry-run.
7040d769e936Smrg		if $opt_dry_run; then
7041d769e936Smrg		  # Extract subdirectory from the argument.
7042d769e936Smrg		  func_dirname "$arg" "/" ""
70437322289dSmrg		  xdir=$func_dirname_result
7044d769e936Smrg
7045d769e936Smrg		  func_lo2o "$arg"
7046d769e936Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7047d769e936Smrg		  non_pic_object=$xdir$func_lo2o_result
7048d769e936Smrg		  func_append libobjs " $pic_object"
7049d769e936Smrg		  func_append non_pic_objects " $non_pic_object"
7050d769e936Smrg	        else
70517322289dSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7052d769e936Smrg		fi
7053d769e936Smrg	      fi
7054d769e936Smrg	    done
7055d769e936Smrg	  else
70567322289dSmrg	    func_fatal_error "link input file '$arg' does not exist"
7057d769e936Smrg	  fi
7058d769e936Smrg	  arg=$save_arg
7059d769e936Smrg	  prev=
7060d769e936Smrg	  continue
7061d769e936Smrg	  ;;
70627322289dSmrg	os2dllname)
70637322289dSmrg	  os2dllname=$arg
70647322289dSmrg	  prev=
70657322289dSmrg	  continue
70667322289dSmrg	  ;;
7067d769e936Smrg	precious_regex)
70687322289dSmrg	  precious_files_regex=$arg
7069d769e936Smrg	  prev=
7070d769e936Smrg	  continue
7071d769e936Smrg	  ;;
7072d769e936Smrg	release)
70737322289dSmrg	  release=-$arg
7074d769e936Smrg	  prev=
7075d769e936Smrg	  continue
7076d769e936Smrg	  ;;
7077d769e936Smrg	rpath | xrpath)
7078d769e936Smrg	  # We need an absolute path.
7079d769e936Smrg	  case $arg in
7080d769e936Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7081d769e936Smrg	  *)
7082d769e936Smrg	    func_fatal_error "only absolute run-paths are allowed"
7083d769e936Smrg	    ;;
7084d769e936Smrg	  esac
70857322289dSmrg	  if test rpath = "$prev"; then
7086d769e936Smrg	    case "$rpath " in
7087d769e936Smrg	    *" $arg "*) ;;
7088d769e936Smrg	    *) func_append rpath " $arg" ;;
7089d769e936Smrg	    esac
7090d769e936Smrg	  else
7091d769e936Smrg	    case "$xrpath " in
7092d769e936Smrg	    *" $arg "*) ;;
7093d769e936Smrg	    *) func_append xrpath " $arg" ;;
7094d769e936Smrg	    esac
7095d769e936Smrg	  fi
7096d769e936Smrg	  prev=
7097d769e936Smrg	  continue
7098d769e936Smrg	  ;;
7099d769e936Smrg	shrext)
71007322289dSmrg	  shrext_cmds=$arg
7101d769e936Smrg	  prev=
7102d769e936Smrg	  continue
7103d769e936Smrg	  ;;
7104d769e936Smrg	weak)
7105d769e936Smrg	  func_append weak_libs " $arg"
7106d769e936Smrg	  prev=
7107d769e936Smrg	  continue
7108d769e936Smrg	  ;;
710922663e35Smrg	xassembler)
711022663e35Smrg	  func_append compiler_flags " -Xassembler $qarg"
711122663e35Smrg	  prev=
711222663e35Smrg	  func_append compile_command " -Xassembler $qarg"
711322663e35Smrg	  func_append finalize_command " -Xassembler $qarg"
711422663e35Smrg	  continue
711522663e35Smrg	  ;;
7116d769e936Smrg	xcclinker)
7117d769e936Smrg	  func_append linker_flags " $qarg"
7118d769e936Smrg	  func_append compiler_flags " $qarg"
7119d769e936Smrg	  prev=
7120d769e936Smrg	  func_append compile_command " $qarg"
7121d769e936Smrg	  func_append finalize_command " $qarg"
7122d769e936Smrg	  continue
7123d769e936Smrg	  ;;
7124d769e936Smrg	xcompiler)
7125d769e936Smrg	  func_append compiler_flags " $qarg"
7126d769e936Smrg	  prev=
7127d769e936Smrg	  func_append compile_command " $qarg"
7128d769e936Smrg	  func_append finalize_command " $qarg"
7129d769e936Smrg	  continue
7130d769e936Smrg	  ;;
7131d769e936Smrg	xlinker)
7132d769e936Smrg	  func_append linker_flags " $qarg"
7133d769e936Smrg	  func_append compiler_flags " $wl$qarg"
7134d769e936Smrg	  prev=
7135d769e936Smrg	  func_append compile_command " $wl$qarg"
7136d769e936Smrg	  func_append finalize_command " $wl$qarg"
7137d769e936Smrg	  continue
7138d769e936Smrg	  ;;
7139d769e936Smrg	*)
7140d769e936Smrg	  eval "$prev=\"\$arg\""
7141d769e936Smrg	  prev=
7142d769e936Smrg	  continue
7143d769e936Smrg	  ;;
7144d769e936Smrg	esac
7145d769e936Smrg      fi # test -n "$prev"
7146ec713c28Smrg
71477322289dSmrg      prevarg=$arg
7148ec713c28Smrg
7149d769e936Smrg      case $arg in
7150d769e936Smrg      -all-static)
7151d769e936Smrg	if test -n "$link_static_flag"; then
7152d769e936Smrg	  # See comment for -static flag below, for more details.
7153d769e936Smrg	  func_append compile_command " $link_static_flag"
7154d769e936Smrg	  func_append finalize_command " $link_static_flag"
7155d769e936Smrg	fi
7156d769e936Smrg	continue
7157d769e936Smrg	;;
7158ec713c28Smrg
7159d769e936Smrg      -allow-undefined)
7160d769e936Smrg	# FIXME: remove this flag sometime in the future.
71617322289dSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7162d769e936Smrg	;;
7163ec713c28Smrg
7164d769e936Smrg      -avoid-version)
7165d769e936Smrg	avoid_version=yes
7166d769e936Smrg	continue
7167d769e936Smrg	;;
7168ec713c28Smrg
7169d769e936Smrg      -bindir)
7170d769e936Smrg	prev=bindir
7171d769e936Smrg	continue
7172d769e936Smrg	;;
71731d54945dSmrg
7174d769e936Smrg      -dlopen)
7175d769e936Smrg	prev=dlfiles
7176d769e936Smrg	continue
7177d769e936Smrg	;;
71781d54945dSmrg
7179d769e936Smrg      -dlpreopen)
7180d769e936Smrg	prev=dlprefiles
7181d769e936Smrg	continue
7182d769e936Smrg	;;
71831d54945dSmrg
7184d769e936Smrg      -export-dynamic)
7185d769e936Smrg	export_dynamic=yes
7186d769e936Smrg	continue
7187d769e936Smrg	;;
7188786a6f21Smrg
7189d769e936Smrg      -export-symbols | -export-symbols-regex)
7190d769e936Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7191d769e936Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7192d769e936Smrg	fi
71937322289dSmrg	if test X-export-symbols = "X$arg"; then
7194d769e936Smrg	  prev=expsyms
7195d769e936Smrg	else
7196d769e936Smrg	  prev=expsyms_regex
7197d769e936Smrg	fi
7198d769e936Smrg	continue
7199d769e936Smrg	;;
7200786a6f21Smrg
7201d769e936Smrg      -framework)
7202d769e936Smrg	prev=framework
7203d769e936Smrg	continue
7204d769e936Smrg	;;
72051d54945dSmrg
7206d769e936Smrg      -inst-prefix-dir)
7207d769e936Smrg	prev=inst_prefix
7208d769e936Smrg	continue
7209d769e936Smrg	;;
72101d54945dSmrg
7211d769e936Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7212d769e936Smrg      # so, if we see these flags be careful not to treat them like -L
7213d769e936Smrg      -L[A-Z][A-Z]*:*)
7214d769e936Smrg	case $with_gcc/$host in
7215d769e936Smrg	no/*-*-irix* | /*-*-irix*)
7216d769e936Smrg	  func_append compile_command " $arg"
7217d769e936Smrg	  func_append finalize_command " $arg"
7218d769e936Smrg	  ;;
7219d769e936Smrg	esac
7220d769e936Smrg	continue
7221d769e936Smrg	;;
72221d54945dSmrg
7223d769e936Smrg      -L*)
7224d769e936Smrg	func_stripname "-L" '' "$arg"
7225d769e936Smrg	if test -z "$func_stripname_result"; then
7226d769e936Smrg	  if test "$#" -gt 0; then
72277322289dSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7228d769e936Smrg	  else
72297322289dSmrg	    func_fatal_error "need path for '-L' option"
7230d769e936Smrg	  fi
7231d769e936Smrg	fi
7232d769e936Smrg	func_resolve_sysroot "$func_stripname_result"
7233d769e936Smrg	dir=$func_resolve_sysroot_result
7234d769e936Smrg	# We need an absolute path.
7235d769e936Smrg	case $dir in
7236d769e936Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7237d769e936Smrg	*)
7238d769e936Smrg	  absdir=`cd "$dir" && pwd`
7239d769e936Smrg	  test -z "$absdir" && \
72407322289dSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
72417322289dSmrg	  dir=$absdir
7242d769e936Smrg	  ;;
7243d769e936Smrg	esac
7244d769e936Smrg	case "$deplibs " in
7245d769e936Smrg	*" -L$dir "* | *" $arg "*)
7246d769e936Smrg	  # Will only happen for absolute or sysroot arguments
7247d769e936Smrg	  ;;
7248d769e936Smrg	*)
7249d769e936Smrg	  # Preserve sysroot, but never include relative directories
7250d769e936Smrg	  case $dir in
7251d769e936Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252d769e936Smrg	    *) func_append deplibs " -L$dir" ;;
7253d769e936Smrg	  esac
7254d769e936Smrg	  func_append lib_search_path " $dir"
7255d769e936Smrg	  ;;
7256d769e936Smrg	esac
7257d769e936Smrg	case $host in
7258d769e936Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7259d769e936Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7260d769e936Smrg	  case :$dllsearchpath: in
7261d769e936Smrg	  *":$dir:"*) ;;
7262d769e936Smrg	  ::) dllsearchpath=$dir;;
7263d769e936Smrg	  *) func_append dllsearchpath ":$dir";;
7264d769e936Smrg	  esac
7265d769e936Smrg	  case :$dllsearchpath: in
7266d769e936Smrg	  *":$testbindir:"*) ;;
7267d769e936Smrg	  ::) dllsearchpath=$testbindir;;
7268d769e936Smrg	  *) func_append dllsearchpath ":$testbindir";;
7269d769e936Smrg	  esac
7270d769e936Smrg	  ;;
7271d769e936Smrg	esac
7272d769e936Smrg	continue
7273d769e936Smrg	;;
72741d54945dSmrg
7275d769e936Smrg      -l*)
72767322289dSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7277d769e936Smrg	  case $host in
7278d769e936Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7279d769e936Smrg	    # These systems don't actually have a C or math library (as such)
7280d769e936Smrg	    continue
7281d769e936Smrg	    ;;
7282d769e936Smrg	  *-*-os2*)
7283d769e936Smrg	    # These systems don't actually have a C library (as such)
72847322289dSmrg	    test X-lc = "X$arg" && continue
7285d769e936Smrg	    ;;
728622663e35Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7287d769e936Smrg	    # Do not include libc due to us having libc/libc_r.
72887322289dSmrg	    test X-lc = "X$arg" && continue
7289d769e936Smrg	    ;;
7290d769e936Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7291d769e936Smrg	    # Rhapsody C and math libraries are in the System framework
7292d769e936Smrg	    func_append deplibs " System.ltframework"
7293d769e936Smrg	    continue
7294d769e936Smrg	    ;;
7295d769e936Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7296d769e936Smrg	    # Causes problems with __ctype
72977322289dSmrg	    test X-lc = "X$arg" && continue
7298d769e936Smrg	    ;;
7299d769e936Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7300d769e936Smrg	    # Compiler inserts libc in the correct place for threads to work
73017322289dSmrg	    test X-lc = "X$arg" && continue
7302d769e936Smrg	    ;;
7303d769e936Smrg	  esac
73047322289dSmrg	elif test X-lc_r = "X$arg"; then
7305d769e936Smrg	 case $host in
730622663e35Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7307d769e936Smrg	   # Do not include libc_r directly, use -pthread flag.
7308d769e936Smrg	   continue
7309d769e936Smrg	   ;;
7310d769e936Smrg	 esac
7311d769e936Smrg	fi
7312d769e936Smrg	func_append deplibs " $arg"
7313d769e936Smrg	continue
7314d769e936Smrg	;;
7315d769e936Smrg
73167322289dSmrg      -mllvm)
73177322289dSmrg	prev=mllvm
73187322289dSmrg	continue
73197322289dSmrg	;;
73207322289dSmrg
7321d769e936Smrg      -module)
7322d769e936Smrg	module=yes
7323d769e936Smrg	continue
7324d769e936Smrg	;;
7325d769e936Smrg
7326d769e936Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7327d769e936Smrg      # classes, name mangling, and exception handling.
7328d769e936Smrg      # Darwin uses the -arch flag to determine output architecture.
7329d769e936Smrg      -model|-arch|-isysroot|--sysroot)
7330d769e936Smrg	func_append compiler_flags " $arg"
7331d769e936Smrg	func_append compile_command " $arg"
7332d769e936Smrg	func_append finalize_command " $arg"
7333d769e936Smrg	prev=xcompiler
7334d769e936Smrg	continue
7335d769e936Smrg	;;
733622663e35Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
733722663e35Smrg     -pthread)
733822663e35Smrg	case $host in
733922663e35Smrg	  *solaris2*) ;;
734022663e35Smrg	  *)
734122663e35Smrg	    case "$new_inherited_linker_flags " in
734222663e35Smrg	        *" $arg "*) ;;
734322663e35Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
734422663e35Smrg	    esac
734522663e35Smrg	  ;;
734622663e35Smrg	esac
734722663e35Smrg	continue
734822663e35Smrg	;;
734922663e35Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350d769e936Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351d769e936Smrg	func_append compiler_flags " $arg"
7352d769e936Smrg	func_append compile_command " $arg"
7353d769e936Smrg	func_append finalize_command " $arg"
7354d769e936Smrg	case "$new_inherited_linker_flags " in
7355d769e936Smrg	    *" $arg "*) ;;
7356d769e936Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7357d769e936Smrg	esac
7358d769e936Smrg	continue
7359d769e936Smrg	;;
7360d769e936Smrg
7361d769e936Smrg      -multi_module)
73627322289dSmrg	single_module=$wl-multi_module
7363d769e936Smrg	continue
7364d769e936Smrg	;;
7365d769e936Smrg
7366d769e936Smrg      -no-fast-install)
7367d769e936Smrg	fast_install=no
7368d769e936Smrg	continue
7369d769e936Smrg	;;
7370d769e936Smrg
7371d769e936Smrg      -no-install)
7372d769e936Smrg	case $host in
7373d769e936Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7374d769e936Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7375d769e936Smrg	  # and Darwin in order for the loader to find any dlls it needs.
73767322289dSmrg	  func_warning "'-no-install' is ignored for $host"
73777322289dSmrg	  func_warning "assuming '-no-fast-install' instead"
7378d769e936Smrg	  fast_install=no
7379d769e936Smrg	  ;;
7380d769e936Smrg	*) no_install=yes ;;
7381d769e936Smrg	esac
7382d769e936Smrg	continue
7383d769e936Smrg	;;
7384d769e936Smrg
7385d769e936Smrg      -no-undefined)
7386d769e936Smrg	allow_undefined=no
7387d769e936Smrg	continue
7388d769e936Smrg	;;
7389d769e936Smrg
7390d769e936Smrg      -objectlist)
7391d769e936Smrg	prev=objectlist
7392d769e936Smrg	continue
7393d769e936Smrg	;;
7394d769e936Smrg
73957322289dSmrg      -os2dllname)
73967322289dSmrg	prev=os2dllname
73977322289dSmrg	continue
73987322289dSmrg	;;
73997322289dSmrg
7400d769e936Smrg      -o) prev=output ;;
7401d769e936Smrg
7402d769e936Smrg      -precious-files-regex)
7403d769e936Smrg	prev=precious_regex
7404d769e936Smrg	continue
7405d769e936Smrg	;;
7406d769e936Smrg
7407d769e936Smrg      -release)
7408d769e936Smrg	prev=release
7409d769e936Smrg	continue
7410d769e936Smrg	;;
7411d769e936Smrg
7412d769e936Smrg      -rpath)
7413d769e936Smrg	prev=rpath
7414d769e936Smrg	continue
7415d769e936Smrg	;;
7416d769e936Smrg
7417d769e936Smrg      -R)
7418d769e936Smrg	prev=xrpath
7419d769e936Smrg	continue
7420d769e936Smrg	;;
7421d769e936Smrg
7422d769e936Smrg      -R*)
7423d769e936Smrg	func_stripname '-R' '' "$arg"
7424d769e936Smrg	dir=$func_stripname_result
7425d769e936Smrg	# We need an absolute path.
7426d769e936Smrg	case $dir in
7427d769e936Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428d769e936Smrg	=*)
7429d769e936Smrg	  func_stripname '=' '' "$dir"
7430d769e936Smrg	  dir=$lt_sysroot$func_stripname_result
7431d769e936Smrg	  ;;
7432d769e936Smrg	*)
7433d769e936Smrg	  func_fatal_error "only absolute run-paths are allowed"
7434d769e936Smrg	  ;;
7435d769e936Smrg	esac
7436d769e936Smrg	case "$xrpath " in
7437d769e936Smrg	*" $dir "*) ;;
7438d769e936Smrg	*) func_append xrpath " $dir" ;;
7439d769e936Smrg	esac
7440d769e936Smrg	continue
7441d769e936Smrg	;;
7442d769e936Smrg
7443d769e936Smrg      -shared)
7444d769e936Smrg	# The effects of -shared are defined in a previous loop.
7445d769e936Smrg	continue
7446d769e936Smrg	;;
7447d769e936Smrg
7448d769e936Smrg      -shrext)
7449d769e936Smrg	prev=shrext
7450d769e936Smrg	continue
7451d769e936Smrg	;;
7452d769e936Smrg
7453d769e936Smrg      -static | -static-libtool-libs)
7454d769e936Smrg	# The effects of -static are defined in a previous loop.
7455d769e936Smrg	# We used to do the same as -all-static on platforms that
7456d769e936Smrg	# didn't have a PIC flag, but the assumption that the effects
7457d769e936Smrg	# would be equivalent was wrong.  It would break on at least
7458d769e936Smrg	# Digital Unix and AIX.
7459d769e936Smrg	continue
7460d769e936Smrg	;;
7461d769e936Smrg
7462d769e936Smrg      -thread-safe)
7463d769e936Smrg	thread_safe=yes
7464d769e936Smrg	continue
7465d769e936Smrg	;;
7466d769e936Smrg
7467d769e936Smrg      -version-info)
7468d769e936Smrg	prev=vinfo
7469d769e936Smrg	continue
7470d769e936Smrg	;;
7471d769e936Smrg
7472d769e936Smrg      -version-number)
7473d769e936Smrg	prev=vinfo
7474d769e936Smrg	vinfo_number=yes
7475d769e936Smrg	continue
7476d769e936Smrg	;;
7477d769e936Smrg
7478d769e936Smrg      -weak)
7479d769e936Smrg        prev=weak
7480d769e936Smrg	continue
7481d769e936Smrg	;;
7482d769e936Smrg
7483d769e936Smrg      -Wc,*)
7484d769e936Smrg	func_stripname '-Wc,' '' "$arg"
7485d769e936Smrg	args=$func_stripname_result
7486d769e936Smrg	arg=
74877322289dSmrg	save_ifs=$IFS; IFS=,
7488d769e936Smrg	for flag in $args; do
74897322289dSmrg	  IFS=$save_ifs
749022663e35Smrg          func_quote_arg pretty "$flag"
749122663e35Smrg	  func_append arg " $func_quote_arg_result"
749222663e35Smrg	  func_append compiler_flags " $func_quote_arg_result"
7493d769e936Smrg	done
74947322289dSmrg	IFS=$save_ifs
7495d769e936Smrg	func_stripname ' ' '' "$arg"
7496d769e936Smrg	arg=$func_stripname_result
7497d769e936Smrg	;;
7498d769e936Smrg
7499d769e936Smrg      -Wl,*)
7500d769e936Smrg	func_stripname '-Wl,' '' "$arg"
7501d769e936Smrg	args=$func_stripname_result
7502d769e936Smrg	arg=
75037322289dSmrg	save_ifs=$IFS; IFS=,
7504d769e936Smrg	for flag in $args; do
75057322289dSmrg	  IFS=$save_ifs
750622663e35Smrg          func_quote_arg pretty "$flag"
750722663e35Smrg	  func_append arg " $wl$func_quote_arg_result"
750822663e35Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
750922663e35Smrg	  func_append linker_flags " $func_quote_arg_result"
7510d769e936Smrg	done
75117322289dSmrg	IFS=$save_ifs
7512d769e936Smrg	func_stripname ' ' '' "$arg"
7513d769e936Smrg	arg=$func_stripname_result
7514d769e936Smrg	;;
7515d769e936Smrg
751622663e35Smrg      -Xassembler)
751722663e35Smrg        prev=xassembler
751822663e35Smrg        continue
751922663e35Smrg        ;;
752022663e35Smrg
7521d769e936Smrg      -Xcompiler)
7522d769e936Smrg	prev=xcompiler
7523d769e936Smrg	continue
7524d769e936Smrg	;;
7525d769e936Smrg
7526d769e936Smrg      -Xlinker)
7527d769e936Smrg	prev=xlinker
7528d769e936Smrg	continue
7529d769e936Smrg	;;
7530d769e936Smrg
7531d769e936Smrg      -XCClinker)
7532d769e936Smrg	prev=xcclinker
7533d769e936Smrg	continue
7534d769e936Smrg	;;
7535d769e936Smrg
7536d769e936Smrg      # -msg_* for osf cc
7537d769e936Smrg      -msg_*)
753822663e35Smrg	func_quote_arg pretty "$arg"
753922663e35Smrg	arg=$func_quote_arg_result
7540d769e936Smrg	;;
7541d769e936Smrg
7542d769e936Smrg      # Flags to be passed through unchanged, with rationale:
7543d769e936Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7544d769e936Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7545d769e936Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7546d769e936Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7547d769e936Smrg      # -q*                  compiler args for the IBM compiler
7548d769e936Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7549d769e936Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7550d769e936Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
75517322289dSmrg      # -fstack-protector*   stack protector flags for GCC
7552d769e936Smrg      # @file                GCC response files
7553d769e936Smrg      # -tp=*                Portland pgcc target processor selection
7554d769e936Smrg      # --sysroot=*          for sysroot support
75557322289dSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556024581f2Smrg      # -specs=*             GCC specs files
75577322289dSmrg      # -stdlib=*            select c++ std lib with clang
7558024581f2Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
755922663e35Smrg      # -fuse-ld=*           Linker select flags for GCC
756022663e35Smrg      # -Wa,*                Pass flags directly to the assembler
7561d769e936Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562d769e936Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563024581f2Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
756422663e35Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
756522663e35Smrg        func_quote_arg pretty "$arg"
756622663e35Smrg	arg=$func_quote_arg_result
7567d769e936Smrg        func_append compile_command " $arg"
7568d769e936Smrg        func_append finalize_command " $arg"
7569d769e936Smrg        func_append compiler_flags " $arg"
7570d769e936Smrg        continue
7571d769e936Smrg        ;;
7572d769e936Smrg
75737322289dSmrg      -Z*)
75747322289dSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
75757322289dSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
75767322289dSmrg	  compiler_flags="$compiler_flags $arg"
75777322289dSmrg	  func_append compile_command " $arg"
75787322289dSmrg	  func_append finalize_command " $arg"
75797322289dSmrg	  case $arg in
75807322289dSmrg	  -Zlinker | -Zstack)
75817322289dSmrg	    prev=xcompiler
75827322289dSmrg	    ;;
75837322289dSmrg	  esac
75847322289dSmrg	  continue
75857322289dSmrg        else
75867322289dSmrg	  # Otherwise treat like 'Some other compiler flag' below
758722663e35Smrg	  func_quote_arg pretty "$arg"
758822663e35Smrg	  arg=$func_quote_arg_result
75897322289dSmrg        fi
75907322289dSmrg	;;
75917322289dSmrg
7592d769e936Smrg      # Some other compiler flag.
7593d769e936Smrg      -* | +*)
759422663e35Smrg        func_quote_arg pretty "$arg"
759522663e35Smrg	arg=$func_quote_arg_result
7596d769e936Smrg	;;
7597d769e936Smrg
7598d769e936Smrg      *.$objext)
7599d769e936Smrg	# A standard object.
7600d769e936Smrg	func_append objs " $arg"
7601d769e936Smrg	;;
7602d769e936Smrg
7603d769e936Smrg      *.lo)
7604d769e936Smrg	# A libtool-controlled object.
7605d769e936Smrg
7606d769e936Smrg	# Check to see that this really is a libtool object.
7607d769e936Smrg	if func_lalib_unsafe_p "$arg"; then
7608d769e936Smrg	  pic_object=
7609d769e936Smrg	  non_pic_object=
7610d769e936Smrg
7611d769e936Smrg	  # Read the .lo file
7612d769e936Smrg	  func_source "$arg"
7613d769e936Smrg
7614d769e936Smrg	  if test -z "$pic_object" ||
7615d769e936Smrg	     test -z "$non_pic_object" ||
76167322289dSmrg	     test none = "$pic_object" &&
76177322289dSmrg	     test none = "$non_pic_object"; then
76187322289dSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7619d769e936Smrg	  fi
7620d769e936Smrg
7621d769e936Smrg	  # Extract subdirectory from the argument.
7622d769e936Smrg	  func_dirname "$arg" "/" ""
76237322289dSmrg	  xdir=$func_dirname_result
7624d769e936Smrg
76257322289dSmrg	  test none = "$pic_object" || {
7626d769e936Smrg	    # Prepend the subdirectory the object is found in.
76277322289dSmrg	    pic_object=$xdir$pic_object
7628d769e936Smrg
76297322289dSmrg	    if test dlfiles = "$prev"; then
76307322289dSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631d769e936Smrg		func_append dlfiles " $pic_object"
7632d769e936Smrg		prev=
7633d769e936Smrg		continue
7634d769e936Smrg	      else
7635d769e936Smrg		# If libtool objects are unsupported, then we need to preload.
7636d769e936Smrg		prev=dlprefiles
7637d769e936Smrg	      fi
7638d769e936Smrg	    fi
7639d769e936Smrg
7640d769e936Smrg	    # CHECK ME:  I think I busted this.  -Ossama
76417322289dSmrg	    if test dlprefiles = "$prev"; then
7642d769e936Smrg	      # Preload the old-style object.
7643d769e936Smrg	      func_append dlprefiles " $pic_object"
7644d769e936Smrg	      prev=
7645d769e936Smrg	    fi
7646d769e936Smrg
7647d769e936Smrg	    # A PIC object.
7648d769e936Smrg	    func_append libobjs " $pic_object"
76497322289dSmrg	    arg=$pic_object
76507322289dSmrg	  }
7651d769e936Smrg
7652d769e936Smrg	  # Non-PIC object.
76537322289dSmrg	  if test none != "$non_pic_object"; then
7654d769e936Smrg	    # Prepend the subdirectory the object is found in.
76557322289dSmrg	    non_pic_object=$xdir$non_pic_object
7656d769e936Smrg
7657d769e936Smrg	    # A standard non-PIC object
7658d769e936Smrg	    func_append non_pic_objects " $non_pic_object"
76597322289dSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
76607322289dSmrg	      arg=$non_pic_object
7661d769e936Smrg	    fi
7662d769e936Smrg	  else
7663d769e936Smrg	    # If the PIC object exists, use it instead.
7664d769e936Smrg	    # $xdir was prepended to $pic_object above.
76657322289dSmrg	    non_pic_object=$pic_object
7666d769e936Smrg	    func_append non_pic_objects " $non_pic_object"
7667d769e936Smrg	  fi
7668d769e936Smrg	else
7669d769e936Smrg	  # Only an error if not doing a dry-run.
7670d769e936Smrg	  if $opt_dry_run; then
7671d769e936Smrg	    # Extract subdirectory from the argument.
7672d769e936Smrg	    func_dirname "$arg" "/" ""
76737322289dSmrg	    xdir=$func_dirname_result
7674d769e936Smrg
7675d769e936Smrg	    func_lo2o "$arg"
7676d769e936Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7677d769e936Smrg	    non_pic_object=$xdir$func_lo2o_result
7678d769e936Smrg	    func_append libobjs " $pic_object"
7679d769e936Smrg	    func_append non_pic_objects " $non_pic_object"
7680d769e936Smrg	  else
76817322289dSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7682d769e936Smrg	  fi
7683d769e936Smrg	fi
7684d769e936Smrg	;;
7685d769e936Smrg
7686d769e936Smrg      *.$libext)
7687d769e936Smrg	# An archive.
7688d769e936Smrg	func_append deplibs " $arg"
7689d769e936Smrg	func_append old_deplibs " $arg"
7690d769e936Smrg	continue
7691d769e936Smrg	;;
7692d769e936Smrg
7693d769e936Smrg      *.la)
7694d769e936Smrg	# A libtool-controlled library.
7695d769e936Smrg
7696d769e936Smrg	func_resolve_sysroot "$arg"
76977322289dSmrg	if test dlfiles = "$prev"; then
7698d769e936Smrg	  # This library was specified with -dlopen.
7699d769e936Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7700d769e936Smrg	  prev=
77017322289dSmrg	elif test dlprefiles = "$prev"; then
7702d769e936Smrg	  # The library was specified with -dlpreopen.
7703d769e936Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7704d769e936Smrg	  prev=
7705d769e936Smrg	else
7706d769e936Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7707d769e936Smrg	fi
7708d769e936Smrg	continue
7709d769e936Smrg	;;
7710d769e936Smrg
7711d769e936Smrg      # Some other compiler argument.
7712d769e936Smrg      *)
7713d769e936Smrg	# Unknown arguments in both finalize_command and compile_command need
7714d769e936Smrg	# to be aesthetically quoted because they are evaled later.
771522663e35Smrg	func_quote_arg pretty "$arg"
771622663e35Smrg	arg=$func_quote_arg_result
7717d769e936Smrg	;;
7718d769e936Smrg      esac # arg
7719d769e936Smrg
7720d769e936Smrg      # Now actually substitute the argument into the commands.
7721d769e936Smrg      if test -n "$arg"; then
7722d769e936Smrg	func_append compile_command " $arg"
7723d769e936Smrg	func_append finalize_command " $arg"
7724d769e936Smrg      fi
7725d769e936Smrg    done # argument parsing loop
7726d769e936Smrg
7727d769e936Smrg    test -n "$prev" && \
77287322289dSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7729d769e936Smrg
77307322289dSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7731d769e936Smrg      eval arg=\"$export_dynamic_flag_spec\"
7732d769e936Smrg      func_append compile_command " $arg"
7733d769e936Smrg      func_append finalize_command " $arg"
7734d769e936Smrg    fi
7735d769e936Smrg
7736d769e936Smrg    oldlibs=
7737d769e936Smrg    # calculate the name of the file, without its directory
7738d769e936Smrg    func_basename "$output"
77397322289dSmrg    outputname=$func_basename_result
77407322289dSmrg    libobjs_save=$libobjs
7741d769e936Smrg
7742d769e936Smrg    if test -n "$shlibpath_var"; then
7743d769e936Smrg      # get the directories listed in $shlibpath_var
77447322289dSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745d769e936Smrg    else
7746d769e936Smrg      shlib_search_path=
7747d769e936Smrg    fi
7748d769e936Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7749d769e936Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750d769e936Smrg
77517322289dSmrg    # Definition is injected by LT_CONFIG during libtool generation.
77527322289dSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
77537322289dSmrg
7754d769e936Smrg    func_dirname "$output" "/" ""
77557322289dSmrg    output_objdir=$func_dirname_result$objdir
7756d769e936Smrg    func_to_tool_file "$output_objdir/"
7757d769e936Smrg    tool_output_objdir=$func_to_tool_file_result
7758d769e936Smrg    # Create the object directory.
7759d769e936Smrg    func_mkdir_p "$output_objdir"
7760d769e936Smrg
7761d769e936Smrg    # Determine the type of output
7762d769e936Smrg    case $output in
7763d769e936Smrg    "")
7764d769e936Smrg      func_fatal_help "you must specify an output file"
7765d769e936Smrg      ;;
7766d769e936Smrg    *.$libext) linkmode=oldlib ;;
7767d769e936Smrg    *.lo | *.$objext) linkmode=obj ;;
7768d769e936Smrg    *.la) linkmode=lib ;;
7769d769e936Smrg    *) linkmode=prog ;; # Anything else should be a program.
7770d769e936Smrg    esac
7771d769e936Smrg
7772d769e936Smrg    specialdeplibs=
7773d769e936Smrg
7774d769e936Smrg    libs=
7775d769e936Smrg    # Find all interdependent deplibs by searching for libraries
7776d769e936Smrg    # that are linked more than once (e.g. -la -lb -la)
7777d769e936Smrg    for deplib in $deplibs; do
77787322289dSmrg      if $opt_preserve_dup_deps; then
7779d769e936Smrg	case "$libs " in
7780d769e936Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7781d769e936Smrg	esac
7782d769e936Smrg      fi
7783d769e936Smrg      func_append libs " $deplib"
7784d769e936Smrg    done
7785d769e936Smrg
77867322289dSmrg    if test lib = "$linkmode"; then
7787d769e936Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7788d769e936Smrg
7789d769e936Smrg      # Compute libraries that are listed more than once in $predeps
7790d769e936Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7791d769e936Smrg      # not to be eliminated).
7792d769e936Smrg      pre_post_deps=
7793d769e936Smrg      if $opt_duplicate_compiler_generated_deps; then
7794d769e936Smrg	for pre_post_dep in $predeps $postdeps; do
7795d769e936Smrg	  case "$pre_post_deps " in
7796d769e936Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7797d769e936Smrg	  esac
7798d769e936Smrg	  func_append pre_post_deps " $pre_post_dep"
7799d769e936Smrg	done
7800d769e936Smrg      fi
7801d769e936Smrg      pre_post_deps=
7802d769e936Smrg    fi
7803d769e936Smrg
7804d769e936Smrg    deplibs=
7805d769e936Smrg    newdependency_libs=
7806d769e936Smrg    newlib_search_path=
7807d769e936Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7808d769e936Smrg    notinst_deplibs= # not-installed libtool libraries
7809d769e936Smrg    notinst_path= # paths that contain not-installed libtool libraries
7810d769e936Smrg
7811d769e936Smrg    case $linkmode in
7812d769e936Smrg    lib)
7813d769e936Smrg	passes="conv dlpreopen link"
7814d769e936Smrg	for file in $dlfiles $dlprefiles; do
7815d769e936Smrg	  case $file in
7816d769e936Smrg	  *.la) ;;
7817d769e936Smrg	  *)
78187322289dSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7819d769e936Smrg	    ;;
7820d769e936Smrg	  esac
7821d769e936Smrg	done
7822d769e936Smrg	;;
7823d769e936Smrg    prog)
7824d769e936Smrg	compile_deplibs=
7825d769e936Smrg	finalize_deplibs=
78267322289dSmrg	alldeplibs=false
7827d769e936Smrg	newdlfiles=
7828d769e936Smrg	newdlprefiles=
7829d769e936Smrg	passes="conv scan dlopen dlpreopen link"
7830d769e936Smrg	;;
7831d769e936Smrg    *)  passes="conv"
7832d769e936Smrg	;;
7833d769e936Smrg    esac
7834d769e936Smrg
7835d769e936Smrg    for pass in $passes; do
7836d769e936Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7837d769e936Smrg      # so that -L comes before libs that need it for instance...
78387322289dSmrg      if test lib,link = "$linkmode,$pass"; then
7839d769e936Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7840d769e936Smrg	##        order, and fix it there properly
7841d769e936Smrg        tmp_deplibs=
7842d769e936Smrg	for deplib in $deplibs; do
7843d769e936Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7844d769e936Smrg	done
78457322289dSmrg	deplibs=$tmp_deplibs
7846d769e936Smrg      fi
7847d769e936Smrg
78487322289dSmrg      if test lib,link = "$linkmode,$pass" ||
78497322289dSmrg	 test prog,scan = "$linkmode,$pass"; then
78507322289dSmrg	libs=$deplibs
7851d769e936Smrg	deplibs=
7852d769e936Smrg      fi
78537322289dSmrg      if test prog = "$linkmode"; then
7854d769e936Smrg	case $pass in
78557322289dSmrg	dlopen) libs=$dlfiles ;;
78567322289dSmrg	dlpreopen) libs=$dlprefiles ;;
785722663e35Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7858d769e936Smrg	esac
7859d769e936Smrg      fi
78607322289dSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7861d769e936Smrg	# Collect and forward deplibs of preopened libtool libs
7862d769e936Smrg	for lib in $dlprefiles; do
7863d769e936Smrg	  # Ignore non-libtool-libs
7864d769e936Smrg	  dependency_libs=
7865d769e936Smrg	  func_resolve_sysroot "$lib"
7866d769e936Smrg	  case $lib in
7867d769e936Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7868d769e936Smrg	  esac
7869d769e936Smrg
7870d769e936Smrg	  # Collect preopened libtool deplibs, except any this library
7871d769e936Smrg	  # has declared as weak libs
7872d769e936Smrg	  for deplib in $dependency_libs; do
7873d769e936Smrg	    func_basename "$deplib"
7874d769e936Smrg            deplib_base=$func_basename_result
7875d769e936Smrg	    case " $weak_libs " in
7876d769e936Smrg	    *" $deplib_base "*) ;;
7877d769e936Smrg	    *) func_append deplibs " $deplib" ;;
7878d769e936Smrg	    esac
7879d769e936Smrg	  done
7880d769e936Smrg	done
78817322289dSmrg	libs=$dlprefiles
7882d769e936Smrg      fi
78837322289dSmrg      if test dlopen = "$pass"; then
7884d769e936Smrg	# Collect dlpreopened libraries
78857322289dSmrg	save_deplibs=$deplibs
7886d769e936Smrg	deplibs=
7887d769e936Smrg      fi
7888d769e936Smrg
7889d769e936Smrg      for deplib in $libs; do
7890d769e936Smrg	lib=
78917322289dSmrg	found=false
7892d769e936Smrg	case $deplib in
7893d769e936Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894d769e936Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
78957322289dSmrg	  if test prog,link = "$linkmode,$pass"; then
7896d769e936Smrg	    compile_deplibs="$deplib $compile_deplibs"
7897d769e936Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7898d769e936Smrg	  else
7899d769e936Smrg	    func_append compiler_flags " $deplib"
79007322289dSmrg	    if test lib = "$linkmode"; then
7901d769e936Smrg		case "$new_inherited_linker_flags " in
7902d769e936Smrg		    *" $deplib "*) ;;
7903d769e936Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7904d769e936Smrg		esac
7905d769e936Smrg	    fi
7906d769e936Smrg	  fi
7907d769e936Smrg	  continue
7908d769e936Smrg	  ;;
7909d769e936Smrg	-l*)
79107322289dSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
79117322289dSmrg	    func_warning "'-l' is ignored for archives/objects"
7912d769e936Smrg	    continue
7913d769e936Smrg	  fi
7914d769e936Smrg	  func_stripname '-l' '' "$deplib"
7915d769e936Smrg	  name=$func_stripname_result
79167322289dSmrg	  if test lib = "$linkmode"; then
7917d769e936Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7918d769e936Smrg	  else
7919d769e936Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7920d769e936Smrg	  fi
7921d769e936Smrg	  for searchdir in $searchdirs; do
7922d769e936Smrg	    for search_ext in .la $std_shrext .so .a; do
7923d769e936Smrg	      # Search the libtool library
79247322289dSmrg	      lib=$searchdir/lib$name$search_ext
7925d769e936Smrg	      if test -f "$lib"; then
79267322289dSmrg		if test .la = "$search_ext"; then
79277322289dSmrg		  found=:
7928d769e936Smrg		else
79297322289dSmrg		  found=false
7930d769e936Smrg		fi
7931d769e936Smrg		break 2
7932d769e936Smrg	      fi
7933d769e936Smrg	    done
7934d769e936Smrg	  done
79357322289dSmrg	  if $found; then
79367322289dSmrg	    # deplib is a libtool library
7937d769e936Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7938d769e936Smrg	    # We need to do some special things here, and not later.
79397322289dSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7940d769e936Smrg	      case " $predeps $postdeps " in
7941d769e936Smrg	      *" $deplib "*)
7942d769e936Smrg		if func_lalib_p "$lib"; then
7943d769e936Smrg		  library_names=
7944d769e936Smrg		  old_library=
7945d769e936Smrg		  func_source "$lib"
7946d769e936Smrg		  for l in $old_library $library_names; do
79477322289dSmrg		    ll=$l
7948d769e936Smrg		  done
79497322289dSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
79507322289dSmrg		    found=false
7951d769e936Smrg		    func_dirname "$lib" "" "."
79527322289dSmrg		    ladir=$func_dirname_result
7953d769e936Smrg		    lib=$ladir/$old_library
79547322289dSmrg		    if test prog,link = "$linkmode,$pass"; then
7955d769e936Smrg		      compile_deplibs="$deplib $compile_deplibs"
7956d769e936Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7957d769e936Smrg		    else
7958d769e936Smrg		      deplibs="$deplib $deplibs"
79597322289dSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7960d769e936Smrg		    fi
7961d769e936Smrg		    continue
7962d769e936Smrg		  fi
7963d769e936Smrg		fi
7964d769e936Smrg		;;
7965d769e936Smrg	      *) ;;
7966d769e936Smrg	      esac
7967d769e936Smrg	    fi
79687322289dSmrg	  else
79697322289dSmrg	    # deplib doesn't seem to be a libtool library
79707322289dSmrg	    if test prog,link = "$linkmode,$pass"; then
79717322289dSmrg	      compile_deplibs="$deplib $compile_deplibs"
79727322289dSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
79737322289dSmrg	    else
79747322289dSmrg	      deplibs="$deplib $deplibs"
79757322289dSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79767322289dSmrg	    fi
79777322289dSmrg	    continue
7978d769e936Smrg	  fi
7979d769e936Smrg	  ;; # -l
7980d769e936Smrg	*.ltframework)
79817322289dSmrg	  if test prog,link = "$linkmode,$pass"; then
7982d769e936Smrg	    compile_deplibs="$deplib $compile_deplibs"
7983d769e936Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7984d769e936Smrg	  else
7985d769e936Smrg	    deplibs="$deplib $deplibs"
79867322289dSmrg	    if test lib = "$linkmode"; then
7987d769e936Smrg		case "$new_inherited_linker_flags " in
7988d769e936Smrg		    *" $deplib "*) ;;
7989d769e936Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7990d769e936Smrg		esac
7991d769e936Smrg	    fi
7992d769e936Smrg	  fi
7993d769e936Smrg	  continue
7994d769e936Smrg	  ;;
7995d769e936Smrg	-L*)
7996d769e936Smrg	  case $linkmode in
7997d769e936Smrg	  lib)
7998d769e936Smrg	    deplibs="$deplib $deplibs"
79997322289dSmrg	    test conv = "$pass" && continue
8000d769e936Smrg	    newdependency_libs="$deplib $newdependency_libs"
8001d769e936Smrg	    func_stripname '-L' '' "$deplib"
8002d769e936Smrg	    func_resolve_sysroot "$func_stripname_result"
8003d769e936Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8004d769e936Smrg	    ;;
8005d769e936Smrg	  prog)
80067322289dSmrg	    if test conv = "$pass"; then
8007d769e936Smrg	      deplibs="$deplib $deplibs"
8008d769e936Smrg	      continue
8009d769e936Smrg	    fi
80107322289dSmrg	    if test scan = "$pass"; then
8011d769e936Smrg	      deplibs="$deplib $deplibs"
8012d769e936Smrg	    else
8013d769e936Smrg	      compile_deplibs="$deplib $compile_deplibs"
8014d769e936Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8015d769e936Smrg	    fi
8016d769e936Smrg	    func_stripname '-L' '' "$deplib"
8017d769e936Smrg	    func_resolve_sysroot "$func_stripname_result"
8018d769e936Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8019d769e936Smrg	    ;;
8020d769e936Smrg	  *)
80217322289dSmrg	    func_warning "'-L' is ignored for archives/objects"
8022d769e936Smrg	    ;;
8023d769e936Smrg	  esac # linkmode
8024d769e936Smrg	  continue
8025d769e936Smrg	  ;; # -L
8026d769e936Smrg	-R*)
80277322289dSmrg	  if test link = "$pass"; then
8028d769e936Smrg	    func_stripname '-R' '' "$deplib"
8029d769e936Smrg	    func_resolve_sysroot "$func_stripname_result"
8030d769e936Smrg	    dir=$func_resolve_sysroot_result
8031d769e936Smrg	    # Make sure the xrpath contains only unique directories.
8032d769e936Smrg	    case "$xrpath " in
8033d769e936Smrg	    *" $dir "*) ;;
8034d769e936Smrg	    *) func_append xrpath " $dir" ;;
8035d769e936Smrg	    esac
8036d769e936Smrg	  fi
8037d769e936Smrg	  deplibs="$deplib $deplibs"
8038d769e936Smrg	  continue
8039d769e936Smrg	  ;;
8040d769e936Smrg	*.la)
8041d769e936Smrg	  func_resolve_sysroot "$deplib"
8042d769e936Smrg	  lib=$func_resolve_sysroot_result
8043d769e936Smrg	  ;;
8044d769e936Smrg	*.$libext)
80457322289dSmrg	  if test conv = "$pass"; then
8046d769e936Smrg	    deplibs="$deplib $deplibs"
8047d769e936Smrg	    continue
8048d769e936Smrg	  fi
8049d769e936Smrg	  case $linkmode in
8050d769e936Smrg	  lib)
8051d769e936Smrg	    # Linking convenience modules into shared libraries is allowed,
8052d769e936Smrg	    # but linking other static libraries is non-portable.
8053d769e936Smrg	    case " $dlpreconveniencelibs " in
8054d769e936Smrg	    *" $deplib "*) ;;
8055d769e936Smrg	    *)
80567322289dSmrg	      valid_a_lib=false
8057d769e936Smrg	      case $deplibs_check_method in
8058d769e936Smrg		match_pattern*)
8059d769e936Smrg		  set dummy $deplibs_check_method; shift
8060d769e936Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8061d769e936Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8062d769e936Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
80637322289dSmrg		    valid_a_lib=:
8064d769e936Smrg		  fi
8065d769e936Smrg		;;
8066d769e936Smrg		pass_all)
80677322289dSmrg		  valid_a_lib=:
8068d769e936Smrg		;;
8069d769e936Smrg	      esac
80707322289dSmrg	      if $valid_a_lib; then
80717322289dSmrg		echo
80727322289dSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
80737322289dSmrg		$ECHO "*** static library $deplib is not portable!"
80747322289dSmrg		deplibs="$deplib $deplibs"
80757322289dSmrg	      else
8076d769e936Smrg		echo
8077d769e936Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8078d769e936Smrg		echo "*** I have the capability to make that library automatically link in when"
8079d769e936Smrg		echo "*** you link to this library.  But I can only do this if you have a"
8080d769e936Smrg		echo "*** shared version of the library, which you do not appear to have"
8081d769e936Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8082d769e936Smrg		echo "*** that it is just a static archive that I should not use here."
8083d769e936Smrg	      fi
8084d769e936Smrg	      ;;
8085d769e936Smrg	    esac
8086d769e936Smrg	    continue
8087d769e936Smrg	    ;;
8088d769e936Smrg	  prog)
80897322289dSmrg	    if test link != "$pass"; then
8090d769e936Smrg	      deplibs="$deplib $deplibs"
8091d769e936Smrg	    else
8092d769e936Smrg	      compile_deplibs="$deplib $compile_deplibs"
8093d769e936Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8094d769e936Smrg	    fi
8095d769e936Smrg	    continue
8096d769e936Smrg	    ;;
8097d769e936Smrg	  esac # linkmode
8098d769e936Smrg	  ;; # *.$libext
8099d769e936Smrg	*.lo | *.$objext)
81007322289dSmrg	  if test conv = "$pass"; then
8101d769e936Smrg	    deplibs="$deplib $deplibs"
81027322289dSmrg	  elif test prog = "$linkmode"; then
81037322289dSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8104d769e936Smrg	      # If there is no dlopen support or we're linking statically,
8105d769e936Smrg	      # we need to preload.
8106d769e936Smrg	      func_append newdlprefiles " $deplib"
8107d769e936Smrg	      compile_deplibs="$deplib $compile_deplibs"
8108d769e936Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8109d769e936Smrg	    else
8110d769e936Smrg	      func_append newdlfiles " $deplib"
8111d769e936Smrg	    fi
8112d769e936Smrg	  fi
8113d769e936Smrg	  continue
8114d769e936Smrg	  ;;
8115d769e936Smrg	%DEPLIBS%)
81167322289dSmrg	  alldeplibs=:
8117d769e936Smrg	  continue
8118d769e936Smrg	  ;;
8119d769e936Smrg	esac # case $deplib
8120d769e936Smrg
81217322289dSmrg	$found || test -f "$lib" \
81227322289dSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8123d769e936Smrg
8124d769e936Smrg	# Check to see that this really is a libtool archive.
8125d769e936Smrg	func_lalib_unsafe_p "$lib" \
81267322289dSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8127d769e936Smrg
8128d769e936Smrg	func_dirname "$lib" "" "."
81297322289dSmrg	ladir=$func_dirname_result
8130d769e936Smrg
8131d769e936Smrg	dlname=
8132d769e936Smrg	dlopen=
8133d769e936Smrg	dlpreopen=
8134d769e936Smrg	libdir=
8135d769e936Smrg	library_names=
8136d769e936Smrg	old_library=
8137d769e936Smrg	inherited_linker_flags=
8138d769e936Smrg	# If the library was installed with an old release of libtool,
8139d769e936Smrg	# it will not redefine variables installed, or shouldnotlink
8140d769e936Smrg	installed=yes
8141d769e936Smrg	shouldnotlink=no
8142d769e936Smrg	avoidtemprpath=
8143d769e936Smrg
8144d769e936Smrg
8145d769e936Smrg	# Read the .la file
8146d769e936Smrg	func_source "$lib"
8147d769e936Smrg
8148d769e936Smrg	# Convert "-framework foo" to "foo.ltframework"
8149d769e936Smrg	if test -n "$inherited_linker_flags"; then
8150d769e936Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8151d769e936Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8152d769e936Smrg	    case " $new_inherited_linker_flags " in
8153d769e936Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8154d769e936Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8155d769e936Smrg	    esac
8156d769e936Smrg	  done
8157d769e936Smrg	fi
8158d769e936Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
81597322289dSmrg	if test lib,link = "$linkmode,$pass" ||
81607322289dSmrg	   test prog,scan = "$linkmode,$pass" ||
81617322289dSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162d769e936Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163d769e936Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8164d769e936Smrg	fi
8165d769e936Smrg
81667322289dSmrg	if test conv = "$pass"; then
8167d769e936Smrg	  # Only check for convenience libraries
8168d769e936Smrg	  deplibs="$lib $deplibs"
8169d769e936Smrg	  if test -z "$libdir"; then
8170d769e936Smrg	    if test -z "$old_library"; then
81717322289dSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8172d769e936Smrg	    fi
8173d769e936Smrg	    # It is a libtool convenience library, so add in its objects.
8174d769e936Smrg	    func_append convenience " $ladir/$objdir/$old_library"
8175d769e936Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
81767322289dSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
81777322289dSmrg	    func_fatal_error "'$lib' is not a convenience library"
8178d769e936Smrg	  fi
817922663e35Smrg	  tmp_libs=
818022663e35Smrg	  for deplib in $dependency_libs; do
818122663e35Smrg	    deplibs="$deplib $deplibs"
818222663e35Smrg	    if $opt_preserve_dup_deps; then
818322663e35Smrg	      case "$tmp_libs " in
818422663e35Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
818522663e35Smrg	      esac
818622663e35Smrg	    fi
818722663e35Smrg	    func_append tmp_libs " $deplib"
818822663e35Smrg	  done
8189d769e936Smrg	  continue
8190d769e936Smrg	fi # $pass = conv
8191d769e936Smrg
8192d769e936Smrg
8193d769e936Smrg	# Get the name of the library we link against.
8194d769e936Smrg	linklib=
8195d769e936Smrg	if test -n "$old_library" &&
81967322289dSmrg	   { test yes = "$prefer_static_libs" ||
81977322289dSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198d769e936Smrg	  linklib=$old_library
8199d769e936Smrg	else
8200d769e936Smrg	  for l in $old_library $library_names; do
82017322289dSmrg	    linklib=$l
8202d769e936Smrg	  done
8203d769e936Smrg	fi
8204d769e936Smrg	if test -z "$linklib"; then
82057322289dSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8206d769e936Smrg	fi
8207d769e936Smrg
8208d769e936Smrg	# This library was specified with -dlopen.
82097322289dSmrg	if test dlopen = "$pass"; then
82107322289dSmrg	  test -z "$libdir" \
82117322289dSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8212d769e936Smrg	  if test -z "$dlname" ||
82137322289dSmrg	     test yes != "$dlopen_support" ||
82147322289dSmrg	     test no = "$build_libtool_libs"
82157322289dSmrg	  then
8216d769e936Smrg	    # If there is no dlname, no dlopen support or we're linking
8217d769e936Smrg	    # statically, we need to preload.  We also need to preload any
8218d769e936Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8219d769e936Smrg	    # bomb out in the load deplibs phase.
8220d769e936Smrg	    func_append dlprefiles " $lib $dependency_libs"
8221d769e936Smrg	  else
8222d769e936Smrg	    func_append newdlfiles " $lib"
8223d769e936Smrg	  fi
8224d769e936Smrg	  continue
8225d769e936Smrg	fi # $pass = dlopen
8226d769e936Smrg
8227d769e936Smrg	# We need an absolute path.
8228d769e936Smrg	case $ladir in
82297322289dSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8230d769e936Smrg	*)
8231d769e936Smrg	  abs_ladir=`cd "$ladir" && pwd`
8232d769e936Smrg	  if test -z "$abs_ladir"; then
82337322289dSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8234d769e936Smrg	    func_warning "passing it literally to the linker, although it might fail"
82357322289dSmrg	    abs_ladir=$ladir
8236d769e936Smrg	  fi
8237d769e936Smrg	  ;;
8238d769e936Smrg	esac
8239d769e936Smrg	func_basename "$lib"
82407322289dSmrg	laname=$func_basename_result
8241d769e936Smrg
8242d769e936Smrg	# Find the relevant object directory and library name.
82437322289dSmrg	if test yes = "$installed"; then
8244d769e936Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82457322289dSmrg	    func_warning "library '$lib' was moved."
82467322289dSmrg	    dir=$ladir
82477322289dSmrg	    absdir=$abs_ladir
82487322289dSmrg	    libdir=$abs_ladir
8249d769e936Smrg	  else
82507322289dSmrg	    dir=$lt_sysroot$libdir
82517322289dSmrg	    absdir=$lt_sysroot$libdir
8252d769e936Smrg	  fi
82537322289dSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8254d769e936Smrg	else
8255d769e936Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82567322289dSmrg	    dir=$ladir
82577322289dSmrg	    absdir=$abs_ladir
8258d769e936Smrg	    # Remove this search path later
8259d769e936Smrg	    func_append notinst_path " $abs_ladir"
8260d769e936Smrg	  else
82617322289dSmrg	    dir=$ladir/$objdir
82627322289dSmrg	    absdir=$abs_ladir/$objdir
8263d769e936Smrg	    # Remove this search path later
8264d769e936Smrg	    func_append notinst_path " $abs_ladir"
8265d769e936Smrg	  fi
8266d769e936Smrg	fi # $installed = yes
8267d769e936Smrg	func_stripname 'lib' '.la' "$laname"
8268d769e936Smrg	name=$func_stripname_result
8269d769e936Smrg
8270d769e936Smrg	# This library was specified with -dlpreopen.
82717322289dSmrg	if test dlpreopen = "$pass"; then
82727322289dSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
82737322289dSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8274d769e936Smrg	  fi
82757322289dSmrg	  case $host in
8276d769e936Smrg	    # special handling for platforms with PE-DLLs.
8277d769e936Smrg	    *cygwin* | *mingw* | *cegcc* )
8278d769e936Smrg	      # Linker will automatically link against shared library if both
8279d769e936Smrg	      # static and shared are present.  Therefore, ensure we extract
8280d769e936Smrg	      # symbols from the import library if a shared library is present
8281d769e936Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282d769e936Smrg	      # this by putting the import library name into $newdlprefiles.
8283d769e936Smrg	      # We recover the dlopen module name by 'saving' the la file
8284d769e936Smrg	      # name in a special purpose variable, and (later) extracting the
8285d769e936Smrg	      # dlname from the la file.
8286d769e936Smrg	      if test -n "$dlname"; then
8287d769e936Smrg	        func_tr_sh "$dir/$linklib"
8288d769e936Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289d769e936Smrg	        func_append newdlprefiles " $dir/$linklib"
8290d769e936Smrg	      else
8291d769e936Smrg	        func_append newdlprefiles " $dir/$old_library"
8292d769e936Smrg	        # Keep a list of preopened convenience libraries to check
8293d769e936Smrg	        # that they are being used correctly in the link pass.
8294d769e936Smrg	        test -z "$libdir" && \
8295d769e936Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296d769e936Smrg	      fi
8297d769e936Smrg	    ;;
8298d769e936Smrg	    * )
8299d769e936Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300d769e936Smrg	      # are required to link).
8301d769e936Smrg	      if test -n "$old_library"; then
8302d769e936Smrg	        func_append newdlprefiles " $dir/$old_library"
8303d769e936Smrg	        # Keep a list of preopened convenience libraries to check
8304d769e936Smrg	        # that they are being used correctly in the link pass.
8305d769e936Smrg	        test -z "$libdir" && \
8306d769e936Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307d769e936Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308d769e936Smrg	      elif test -n "$dlname"; then
8309d769e936Smrg	        func_append newdlprefiles " $dir/$dlname"
8310d769e936Smrg	      else
8311d769e936Smrg	        func_append newdlprefiles " $dir/$linklib"
8312d769e936Smrg	      fi
8313d769e936Smrg	    ;;
8314d769e936Smrg	  esac
8315d769e936Smrg	fi # $pass = dlpreopen
8316d769e936Smrg
8317d769e936Smrg	if test -z "$libdir"; then
8318d769e936Smrg	  # Link the convenience library
83197322289dSmrg	  if test lib = "$linkmode"; then
8320d769e936Smrg	    deplibs="$dir/$old_library $deplibs"
83217322289dSmrg	  elif test prog,link = "$linkmode,$pass"; then
8322d769e936Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8323d769e936Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8324d769e936Smrg	  else
8325d769e936Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8326d769e936Smrg	  fi
8327d769e936Smrg	  continue
8328d769e936Smrg	fi
8329d769e936Smrg
8330d769e936Smrg
83317322289dSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8332d769e936Smrg	  func_append newlib_search_path " $ladir"
8333d769e936Smrg	  deplibs="$lib $deplibs"
8334d769e936Smrg
83357322289dSmrg	  linkalldeplibs=false
83367322289dSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
83377322289dSmrg	     test no = "$build_libtool_libs"; then
83387322289dSmrg	    linkalldeplibs=:
8339d769e936Smrg	  fi
8340d769e936Smrg
8341d769e936Smrg	  tmp_libs=
8342d769e936Smrg	  for deplib in $dependency_libs; do
8343d769e936Smrg	    case $deplib in
8344d769e936Smrg	    -L*) func_stripname '-L' '' "$deplib"
8345d769e936Smrg	         func_resolve_sysroot "$func_stripname_result"
8346d769e936Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8347d769e936Smrg		 ;;
8348d769e936Smrg	    esac
8349d769e936Smrg	    # Need to link against all dependency_libs?
83507322289dSmrg	    if $linkalldeplibs; then
8351d769e936Smrg	      deplibs="$deplib $deplibs"
8352d769e936Smrg	    else
8353d769e936Smrg	      # Need to hardcode shared library paths
8354d769e936Smrg	      # or/and link against static libraries
8355d769e936Smrg	      newdependency_libs="$deplib $newdependency_libs"
8356d769e936Smrg	    fi
83577322289dSmrg	    if $opt_preserve_dup_deps; then
8358d769e936Smrg	      case "$tmp_libs " in
8359d769e936Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8360d769e936Smrg	      esac
8361d769e936Smrg	    fi
8362d769e936Smrg	    func_append tmp_libs " $deplib"
8363d769e936Smrg	  done # for deplib
8364d769e936Smrg	  continue
8365d769e936Smrg	fi # $linkmode = prog...
8366d769e936Smrg
83677322289dSmrg	if test prog,link = "$linkmode,$pass"; then
8368d769e936Smrg	  if test -n "$library_names" &&
83697322289dSmrg	     { { test no = "$prefer_static_libs" ||
83707322289dSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8371d769e936Smrg	       test -z "$old_library"; }; then
8372d769e936Smrg	    # We need to hardcode the library path
83737322289dSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8374d769e936Smrg	      # Make sure the rpath contains only unique directories.
83757322289dSmrg	      case $temp_rpath: in
8376d769e936Smrg	      *"$absdir:"*) ;;
8377d769e936Smrg	      *) func_append temp_rpath "$absdir:" ;;
8378d769e936Smrg	      esac
8379d769e936Smrg	    fi
8380d769e936Smrg
8381d769e936Smrg	    # Hardcode the library path.
8382d769e936Smrg	    # Skip directories that are in the system default run-time
8383d769e936Smrg	    # search path.
8384d769e936Smrg	    case " $sys_lib_dlsearch_path " in
8385d769e936Smrg	    *" $absdir "*) ;;
8386d769e936Smrg	    *)
8387d769e936Smrg	      case "$compile_rpath " in
8388d769e936Smrg	      *" $absdir "*) ;;
8389d769e936Smrg	      *) func_append compile_rpath " $absdir" ;;
8390d769e936Smrg	      esac
8391d769e936Smrg	      ;;
8392d769e936Smrg	    esac
8393d769e936Smrg	    case " $sys_lib_dlsearch_path " in
8394d769e936Smrg	    *" $libdir "*) ;;
8395d769e936Smrg	    *)
8396d769e936Smrg	      case "$finalize_rpath " in
8397d769e936Smrg	      *" $libdir "*) ;;
8398d769e936Smrg	      *) func_append finalize_rpath " $libdir" ;;
8399d769e936Smrg	      esac
8400d769e936Smrg	      ;;
8401d769e936Smrg	    esac
8402d769e936Smrg	  fi # $linkmode,$pass = prog,link...
8403d769e936Smrg
84047322289dSmrg	  if $alldeplibs &&
84057322289dSmrg	     { test pass_all = "$deplibs_check_method" ||
84067322289dSmrg	       { test yes = "$build_libtool_libs" &&
8407d769e936Smrg		 test -n "$library_names"; }; }; then
8408d769e936Smrg	    # We only need to search for static libraries
8409d769e936Smrg	    continue
8410d769e936Smrg	  fi
8411d769e936Smrg	fi
8412d769e936Smrg
8413d769e936Smrg	link_static=no # Whether the deplib will be linked statically
8414d769e936Smrg	use_static_libs=$prefer_static_libs
84157322289dSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8416d769e936Smrg	  use_static_libs=no
8417d769e936Smrg	fi
8418d769e936Smrg	if test -n "$library_names" &&
84197322289dSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8420d769e936Smrg	  case $host in
84217322289dSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8422d769e936Smrg	      # No point in relinking DLLs because paths are not encoded
8423d769e936Smrg	      func_append notinst_deplibs " $lib"
8424d769e936Smrg	      need_relink=no
8425d769e936Smrg	    ;;
8426d769e936Smrg	  *)
84277322289dSmrg	    if test no = "$installed"; then
8428d769e936Smrg	      func_append notinst_deplibs " $lib"
8429d769e936Smrg	      need_relink=yes
8430d769e936Smrg	    fi
8431d769e936Smrg	    ;;
8432d769e936Smrg	  esac
8433d769e936Smrg	  # This is a shared library
8434d769e936Smrg
8435d769e936Smrg	  # Warn about portability, can't link against -module's on some
8436d769e936Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
84377322289dSmrg	  dlopenmodule=
8438d769e936Smrg	  for dlpremoduletest in $dlprefiles; do
8439d769e936Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
84407322289dSmrg	      dlopenmodule=$dlpremoduletest
8441d769e936Smrg	      break
8442d769e936Smrg	    fi
8443d769e936Smrg	  done
84447322289dSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8445d769e936Smrg	    echo
84467322289dSmrg	    if test prog = "$linkmode"; then
8447d769e936Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8448d769e936Smrg	    else
8449d769e936Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8450d769e936Smrg	    fi
8451d769e936Smrg	    $ECHO "*** $linklib is not portable!"
8452d769e936Smrg	  fi
84537322289dSmrg	  if test lib = "$linkmode" &&
84547322289dSmrg	     test yes = "$hardcode_into_libs"; then
8455d769e936Smrg	    # Hardcode the library path.
8456d769e936Smrg	    # Skip directories that are in the system default run-time
8457d769e936Smrg	    # search path.
8458d769e936Smrg	    case " $sys_lib_dlsearch_path " in
8459d769e936Smrg	    *" $absdir "*) ;;
8460d769e936Smrg	    *)
8461d769e936Smrg	      case "$compile_rpath " in
8462d769e936Smrg	      *" $absdir "*) ;;
8463d769e936Smrg	      *) func_append compile_rpath " $absdir" ;;
8464d769e936Smrg	      esac
8465d769e936Smrg	      ;;
8466d769e936Smrg	    esac
8467d769e936Smrg	    case " $sys_lib_dlsearch_path " in
8468d769e936Smrg	    *" $libdir "*) ;;
8469d769e936Smrg	    *)
8470d769e936Smrg	      case "$finalize_rpath " in
8471d769e936Smrg	      *" $libdir "*) ;;
8472d769e936Smrg	      *) func_append finalize_rpath " $libdir" ;;
8473d769e936Smrg	      esac
8474d769e936Smrg	      ;;
8475d769e936Smrg	    esac
8476d769e936Smrg	  fi
8477d769e936Smrg
8478d769e936Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8479d769e936Smrg	    # figure out the soname
8480d769e936Smrg	    set dummy $library_names
8481d769e936Smrg	    shift
84827322289dSmrg	    realname=$1
8483d769e936Smrg	    shift
8484d769e936Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8485d769e936Smrg	    # use dlname if we got it. it's perfectly good, no?
8486d769e936Smrg	    if test -n "$dlname"; then
84877322289dSmrg	      soname=$dlname
8488d769e936Smrg	    elif test -n "$soname_spec"; then
8489d769e936Smrg	      # bleh windows
8490d769e936Smrg	      case $host in
84917322289dSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8492d769e936Smrg	        func_arith $current - $age
8493d769e936Smrg		major=$func_arith_result
84947322289dSmrg		versuffix=-$major
8495d769e936Smrg		;;
8496d769e936Smrg	      esac
8497d769e936Smrg	      eval soname=\"$soname_spec\"
8498d769e936Smrg	    else
84997322289dSmrg	      soname=$realname
8500d769e936Smrg	    fi
8501d769e936Smrg
8502d769e936Smrg	    # Make a new name for the extract_expsyms_cmds to use
85037322289dSmrg	    soroot=$soname
8504d769e936Smrg	    func_basename "$soroot"
85057322289dSmrg	    soname=$func_basename_result
8506d769e936Smrg	    func_stripname 'lib' '.dll' "$soname"
8507d769e936Smrg	    newlib=libimp-$func_stripname_result.a
8508d769e936Smrg
8509d769e936Smrg	    # If the library has no export list, then create one now
8510d769e936Smrg	    if test -f "$output_objdir/$soname-def"; then :
8511d769e936Smrg	    else
85127322289dSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8513d769e936Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8514d769e936Smrg	    fi
8515d769e936Smrg
8516d769e936Smrg	    # Create $newlib
8517d769e936Smrg	    if test -f "$output_objdir/$newlib"; then :; else
85187322289dSmrg	      func_verbose "generating import library for '$soname'"
8519d769e936Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8520d769e936Smrg	    fi
8521d769e936Smrg	    # make sure the library variables are pointing to the new library
8522d769e936Smrg	    dir=$output_objdir
8523d769e936Smrg	    linklib=$newlib
8524d769e936Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8525d769e936Smrg
85267322289dSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8527d769e936Smrg	    add_shlibpath=
8528d769e936Smrg	    add_dir=
8529d769e936Smrg	    add=
8530d769e936Smrg	    lib_linked=yes
8531d769e936Smrg	    case $hardcode_action in
8532d769e936Smrg	    immediate | unsupported)
85337322289dSmrg	      if test no = "$hardcode_direct"; then
85347322289dSmrg		add=$dir/$linklib
8535d769e936Smrg		case $host in
85367322289dSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
85377322289dSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8538d769e936Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
85397322289dSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8540d769e936Smrg		  *-*-darwin* )
85417322289dSmrg		    # if the lib is a (non-dlopened) module then we cannot
8542d769e936Smrg		    # link against it, someone is ignoring the earlier warnings
8543d769e936Smrg		    if /usr/bin/file -L $add 2> /dev/null |
85447322289dSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8545d769e936Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8546d769e936Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
85477322289dSmrg			if test -z "$old_library"; then
8548d769e936Smrg			  echo
8549d769e936Smrg			  echo "*** And there doesn't seem to be a static archive available"
8550d769e936Smrg			  echo "*** The link will probably fail, sorry"
8551d769e936Smrg			else
85527322289dSmrg			  add=$dir/$old_library
8553d769e936Smrg			fi
8554d769e936Smrg		      elif test -n "$old_library"; then
85557322289dSmrg			add=$dir/$old_library
8556d769e936Smrg		      fi
8557d769e936Smrg		    fi
8558d769e936Smrg		esac
85597322289dSmrg	      elif test no = "$hardcode_minus_L"; then
8560d769e936Smrg		case $host in
85617322289dSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8562d769e936Smrg		esac
85637322289dSmrg		add_dir=-L$dir
85647322289dSmrg		add=-l$name
85657322289dSmrg	      elif test no = "$hardcode_shlibpath_var"; then
85667322289dSmrg		add_shlibpath=$dir
85677322289dSmrg		add=-l$name
8568d769e936Smrg	      else
8569d769e936Smrg		lib_linked=no
8570d769e936Smrg	      fi
8571d769e936Smrg	      ;;
8572d769e936Smrg	    relink)
85737322289dSmrg	      if test yes = "$hardcode_direct" &&
85747322289dSmrg	         test no = "$hardcode_direct_absolute"; then
85757322289dSmrg		add=$dir/$linklib
85767322289dSmrg	      elif test yes = "$hardcode_minus_L"; then
85777322289dSmrg		add_dir=-L$absdir
8578d769e936Smrg		# Try looking first in the location we're being installed to.
8579d769e936Smrg		if test -n "$inst_prefix_dir"; then
8580d769e936Smrg		  case $libdir in
8581d769e936Smrg		    [\\/]*)
8582d769e936Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8583d769e936Smrg		      ;;
8584d769e936Smrg		  esac
8585d769e936Smrg		fi
85867322289dSmrg		add=-l$name
85877322289dSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
85887322289dSmrg		add_shlibpath=$dir
85897322289dSmrg		add=-l$name
8590d769e936Smrg	      else
8591d769e936Smrg		lib_linked=no
8592d769e936Smrg	      fi
8593d769e936Smrg	      ;;
8594d769e936Smrg	    *) lib_linked=no ;;
8595d769e936Smrg	    esac
8596d769e936Smrg
85977322289dSmrg	    if test yes != "$lib_linked"; then
8598d769e936Smrg	      func_fatal_configuration "unsupported hardcode properties"
8599d769e936Smrg	    fi
8600d769e936Smrg
8601d769e936Smrg	    if test -n "$add_shlibpath"; then
8602d769e936Smrg	      case :$compile_shlibpath: in
8603d769e936Smrg	      *":$add_shlibpath:"*) ;;
8604d769e936Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8605d769e936Smrg	      esac
8606d769e936Smrg	    fi
86077322289dSmrg	    if test prog = "$linkmode"; then
8608d769e936Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8609d769e936Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8610d769e936Smrg	    else
8611d769e936Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8612d769e936Smrg	      test -n "$add" && deplibs="$add $deplibs"
86137322289dSmrg	      if test yes != "$hardcode_direct" &&
86147322289dSmrg		 test yes != "$hardcode_minus_L" &&
86157322289dSmrg		 test yes = "$hardcode_shlibpath_var"; then
8616d769e936Smrg		case :$finalize_shlibpath: in
8617d769e936Smrg		*":$libdir:"*) ;;
8618d769e936Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8619d769e936Smrg		esac
8620d769e936Smrg	      fi
8621d769e936Smrg	    fi
8622d769e936Smrg	  fi
8623d769e936Smrg
86247322289dSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8625d769e936Smrg	    add_shlibpath=
8626d769e936Smrg	    add_dir=
8627d769e936Smrg	    add=
8628d769e936Smrg	    # Finalize command for both is simple: just hardcode it.
86297322289dSmrg	    if test yes = "$hardcode_direct" &&
86307322289dSmrg	       test no = "$hardcode_direct_absolute"; then
86317322289dSmrg	      add=$libdir/$linklib
86327322289dSmrg	    elif test yes = "$hardcode_minus_L"; then
86337322289dSmrg	      add_dir=-L$libdir
86347322289dSmrg	      add=-l$name
86357322289dSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8636d769e936Smrg	      case :$finalize_shlibpath: in
8637d769e936Smrg	      *":$libdir:"*) ;;
8638d769e936Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8639d769e936Smrg	      esac
86407322289dSmrg	      add=-l$name
86417322289dSmrg	    elif test yes = "$hardcode_automatic"; then
8642d769e936Smrg	      if test -n "$inst_prefix_dir" &&
86437322289dSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
86447322289dSmrg		add=$inst_prefix_dir$libdir/$linklib
8645d769e936Smrg	      else
86467322289dSmrg		add=$libdir/$linklib
8647d769e936Smrg	      fi
8648d769e936Smrg	    else
8649d769e936Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
86507322289dSmrg	      add_dir=-L$libdir
8651d769e936Smrg	      # Try looking first in the location we're being installed to.
8652d769e936Smrg	      if test -n "$inst_prefix_dir"; then
8653d769e936Smrg		case $libdir in
8654d769e936Smrg		  [\\/]*)
8655d769e936Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8656d769e936Smrg		    ;;
8657d769e936Smrg		esac
8658d769e936Smrg	      fi
86597322289dSmrg	      add=-l$name
8660d769e936Smrg	    fi
8661d769e936Smrg
86627322289dSmrg	    if test prog = "$linkmode"; then
8663d769e936Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8664d769e936Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8665d769e936Smrg	    else
8666d769e936Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8667d769e936Smrg	      test -n "$add" && deplibs="$add $deplibs"
8668d769e936Smrg	    fi
8669d769e936Smrg	  fi
86707322289dSmrg	elif test prog = "$linkmode"; then
8671d769e936Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8672d769e936Smrg	  # is not unsupported.  This is valid on all known static and
8673d769e936Smrg	  # shared platforms.
86747322289dSmrg	  if test unsupported != "$hardcode_direct"; then
86757322289dSmrg	    test -n "$old_library" && linklib=$old_library
8676d769e936Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8677d769e936Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8678d769e936Smrg	  else
8679d769e936Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8680d769e936Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8681d769e936Smrg	  fi
86827322289dSmrg	elif test yes = "$build_libtool_libs"; then
8683d769e936Smrg	  # Not a shared library
86847322289dSmrg	  if test pass_all != "$deplibs_check_method"; then
8685d769e936Smrg	    # We're trying link a shared library against a static one
8686d769e936Smrg	    # but the system doesn't support it.
8687d769e936Smrg
8688d769e936Smrg	    # Just print a warning and add the library to dependency_libs so
8689d769e936Smrg	    # that the program can be linked against the static library.
8690d769e936Smrg	    echo
86917322289dSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8692d769e936Smrg	    echo "*** I have the capability to make that library automatically link in when"
8693d769e936Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
8694d769e936Smrg	    echo "*** shared version of the library, which you do not appear to have."
86957322289dSmrg	    if test yes = "$module"; then
8696d769e936Smrg	      echo "*** But as you try to build a module library, libtool will still create "
8697d769e936Smrg	      echo "*** a static module, that should work as long as the dlopening application"
8698d769e936Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8699d769e936Smrg	      if test -z "$global_symbol_pipe"; then
8700d769e936Smrg		echo
8701d769e936Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
87027322289dSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8703d769e936Smrg		echo "*** not find such a program.  So, this module is probably useless."
87047322289dSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8705d769e936Smrg	      fi
87067322289dSmrg	      if test no = "$build_old_libs"; then
8707d769e936Smrg		build_libtool_libs=module
8708d769e936Smrg		build_old_libs=yes
8709d769e936Smrg	      else
8710d769e936Smrg		build_libtool_libs=no
8711d769e936Smrg	      fi
8712d769e936Smrg	    fi
8713d769e936Smrg	  else
8714d769e936Smrg	    deplibs="$dir/$old_library $deplibs"
8715d769e936Smrg	    link_static=yes
8716d769e936Smrg	  fi
8717d769e936Smrg	fi # link shared/static library?
8718d769e936Smrg
87197322289dSmrg	if test lib = "$linkmode"; then
8720d769e936Smrg	  if test -n "$dependency_libs" &&
87217322289dSmrg	     { test yes != "$hardcode_into_libs" ||
87227322289dSmrg	       test yes = "$build_old_libs" ||
87237322289dSmrg	       test yes = "$link_static"; }; then
8724d769e936Smrg	    # Extract -R from dependency_libs
8725d769e936Smrg	    temp_deplibs=
8726d769e936Smrg	    for libdir in $dependency_libs; do
8727d769e936Smrg	      case $libdir in
8728d769e936Smrg	      -R*) func_stripname '-R' '' "$libdir"
8729d769e936Smrg	           temp_xrpath=$func_stripname_result
8730d769e936Smrg		   case " $xrpath " in
8731d769e936Smrg		   *" $temp_xrpath "*) ;;
8732d769e936Smrg		   *) func_append xrpath " $temp_xrpath";;
8733d769e936Smrg		   esac;;
8734d769e936Smrg	      *) func_append temp_deplibs " $libdir";;
8735d769e936Smrg	      esac
8736d769e936Smrg	    done
87377322289dSmrg	    dependency_libs=$temp_deplibs
8738d769e936Smrg	  fi
8739d769e936Smrg
8740d769e936Smrg	  func_append newlib_search_path " $absdir"
8741d769e936Smrg	  # Link against this library
87427322289dSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8743d769e936Smrg	  # ... and its dependency_libs
8744d769e936Smrg	  tmp_libs=
8745d769e936Smrg	  for deplib in $dependency_libs; do
8746d769e936Smrg	    newdependency_libs="$deplib $newdependency_libs"
8747d769e936Smrg	    case $deplib in
8748d769e936Smrg              -L*) func_stripname '-L' '' "$deplib"
8749d769e936Smrg                   func_resolve_sysroot "$func_stripname_result";;
8750d769e936Smrg              *) func_resolve_sysroot "$deplib" ;;
8751d769e936Smrg            esac
87527322289dSmrg	    if $opt_preserve_dup_deps; then
8753d769e936Smrg	      case "$tmp_libs " in
8754d769e936Smrg	      *" $func_resolve_sysroot_result "*)
8755d769e936Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8756d769e936Smrg	      esac
8757d769e936Smrg	    fi
8758d769e936Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8759d769e936Smrg	  done
8760d769e936Smrg
87617322289dSmrg	  if test no != "$link_all_deplibs"; then
8762d769e936Smrg	    # Add the search paths of all dependency libraries
8763d769e936Smrg	    for deplib in $dependency_libs; do
8764d769e936Smrg	      path=
8765d769e936Smrg	      case $deplib in
87667322289dSmrg	      -L*) path=$deplib ;;
8767d769e936Smrg	      *.la)
8768d769e936Smrg	        func_resolve_sysroot "$deplib"
8769d769e936Smrg	        deplib=$func_resolve_sysroot_result
8770d769e936Smrg	        func_dirname "$deplib" "" "."
8771d769e936Smrg		dir=$func_dirname_result
8772d769e936Smrg		# We need an absolute path.
8773d769e936Smrg		case $dir in
87747322289dSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8775d769e936Smrg		*)
8776d769e936Smrg		  absdir=`cd "$dir" && pwd`
8777d769e936Smrg		  if test -z "$absdir"; then
87787322289dSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
87797322289dSmrg		    absdir=$dir
8780d769e936Smrg		  fi
8781d769e936Smrg		  ;;
8782d769e936Smrg		esac
8783d769e936Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8784d769e936Smrg		case $host in
8785d769e936Smrg		*-*-darwin*)
8786d769e936Smrg		  depdepl=
87877322289dSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
87887322289dSmrg		  if test -n "$deplibrary_names"; then
87897322289dSmrg		    for tmp in $deplibrary_names; do
8790d769e936Smrg		      depdepl=$tmp
8791d769e936Smrg		    done
87927322289dSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
87937322289dSmrg		      depdepl=$absdir/$objdir/$depdepl
87947322289dSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8795d769e936Smrg                      if test -z "$darwin_install_name"; then
87967322289dSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8797d769e936Smrg                      fi
87987322289dSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
87997322289dSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8800d769e936Smrg		      path=
8801d769e936Smrg		    fi
8802d769e936Smrg		  fi
8803d769e936Smrg		  ;;
8804d769e936Smrg		*)
88057322289dSmrg		  path=-L$absdir/$objdir
8806d769e936Smrg		  ;;
8807d769e936Smrg		esac
8808d769e936Smrg		else
88097322289dSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8810d769e936Smrg		  test -z "$libdir" && \
88117322289dSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8812d769e936Smrg		  test "$absdir" != "$libdir" && \
88137322289dSmrg		    func_warning "'$deplib' seems to be moved"
8814d769e936Smrg
88157322289dSmrg		  path=-L$absdir
8816d769e936Smrg		fi
8817d769e936Smrg		;;
8818d769e936Smrg	      esac
8819d769e936Smrg	      case " $deplibs " in
8820d769e936Smrg	      *" $path "*) ;;
8821d769e936Smrg	      *) deplibs="$path $deplibs" ;;
8822d769e936Smrg	      esac
8823d769e936Smrg	    done
8824d769e936Smrg	  fi # link_all_deplibs != no
8825d769e936Smrg	fi # linkmode = lib
8826d769e936Smrg      done # for deplib in $libs
88277322289dSmrg      if test link = "$pass"; then
88287322289dSmrg	if test prog = "$linkmode"; then
8829d769e936Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8830d769e936Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8831d769e936Smrg	else
8832d769e936Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8833d769e936Smrg	fi
8834d769e936Smrg      fi
88357322289dSmrg      dependency_libs=$newdependency_libs
88367322289dSmrg      if test dlpreopen = "$pass"; then
8837d769e936Smrg	# Link the dlpreopened libraries before other libraries
8838d769e936Smrg	for deplib in $save_deplibs; do
8839d769e936Smrg	  deplibs="$deplib $deplibs"
8840d769e936Smrg	done
8841d769e936Smrg      fi
88427322289dSmrg      if test dlopen != "$pass"; then
88437322289dSmrg	test conv = "$pass" || {
8844d769e936Smrg	  # Make sure lib_search_path contains only unique directories.
8845d769e936Smrg	  lib_search_path=
8846d769e936Smrg	  for dir in $newlib_search_path; do
8847d769e936Smrg	    case "$lib_search_path " in
8848d769e936Smrg	    *" $dir "*) ;;
8849d769e936Smrg	    *) func_append lib_search_path " $dir" ;;
8850d769e936Smrg	    esac
8851d769e936Smrg	  done
8852d769e936Smrg	  newlib_search_path=
88537322289dSmrg	}
8854d769e936Smrg
88557322289dSmrg	if test prog,link = "$linkmode,$pass"; then
8856d769e936Smrg	  vars="compile_deplibs finalize_deplibs"
88577322289dSmrg	else
88587322289dSmrg	  vars=deplibs
8859d769e936Smrg	fi
8860d769e936Smrg	for var in $vars dependency_libs; do
8861d769e936Smrg	  # Add libraries to $var in reverse order
8862d769e936Smrg	  eval tmp_libs=\"\$$var\"
8863d769e936Smrg	  new_libs=
8864d769e936Smrg	  for deplib in $tmp_libs; do
8865d769e936Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8866d769e936Smrg	    #        that some nasty dependency loop isn't accidentally
8867d769e936Smrg	    #        broken:
8868d769e936Smrg	    #new_libs="$deplib $new_libs"
8869d769e936Smrg	    # Pragmatically, this seems to cause very few problems in
8870d769e936Smrg	    # practice:
8871d769e936Smrg	    case $deplib in
8872d769e936Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8873d769e936Smrg	    -R*) ;;
8874d769e936Smrg	    *)
8875d769e936Smrg	      # And here is the reason: when a library appears more
8876d769e936Smrg	      # than once as an explicit dependence of a library, or
8877d769e936Smrg	      # is implicitly linked in more than once by the
8878d769e936Smrg	      # compiler, it is considered special, and multiple
8879d769e936Smrg	      # occurrences thereof are not removed.  Compare this
8880d769e936Smrg	      # with having the same library being listed as a
8881d769e936Smrg	      # dependency of multiple other libraries: in this case,
8882d769e936Smrg	      # we know (pedantically, we assume) the library does not
8883d769e936Smrg	      # need to be listed more than once, so we keep only the
8884d769e936Smrg	      # last copy.  This is not always right, but it is rare
8885d769e936Smrg	      # enough that we require users that really mean to play
8886d769e936Smrg	      # such unportable linking tricks to link the library
8887d769e936Smrg	      # using -Wl,-lname, so that libtool does not consider it
8888d769e936Smrg	      # for duplicate removal.
8889d769e936Smrg	      case " $specialdeplibs " in
8890d769e936Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8891d769e936Smrg	      *)
8892d769e936Smrg		case " $new_libs " in
8893d769e936Smrg		*" $deplib "*) ;;
8894d769e936Smrg		*) new_libs="$deplib $new_libs" ;;
8895d769e936Smrg		esac
8896d769e936Smrg		;;
8897d769e936Smrg	      esac
8898d769e936Smrg	      ;;
8899d769e936Smrg	    esac
8900d769e936Smrg	  done
8901d769e936Smrg	  tmp_libs=
8902d769e936Smrg	  for deplib in $new_libs; do
8903d769e936Smrg	    case $deplib in
8904d769e936Smrg	    -L*)
8905d769e936Smrg	      case " $tmp_libs " in
8906d769e936Smrg	      *" $deplib "*) ;;
8907d769e936Smrg	      *) func_append tmp_libs " $deplib" ;;
8908d769e936Smrg	      esac
8909d769e936Smrg	      ;;
8910d769e936Smrg	    *) func_append tmp_libs " $deplib" ;;
8911d769e936Smrg	    esac
8912d769e936Smrg	  done
8913d769e936Smrg	  eval $var=\"$tmp_libs\"
8914d769e936Smrg	done # for var
8915d769e936Smrg      fi
89167322289dSmrg
89177322289dSmrg      # Add Sun CC postdeps if required:
89187322289dSmrg      test CXX = "$tagname" && {
89197322289dSmrg        case $host_os in
89207322289dSmrg        linux*)
892122663e35Smrg          case `$CC -V 2>&1 | $SED 5q` in
89227322289dSmrg          *Sun\ C*) # Sun C++ 5.9
89237322289dSmrg            func_suncc_cstd_abi
89247322289dSmrg
89257322289dSmrg            if test no != "$suncc_use_cstd_abi"; then
89267322289dSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89277322289dSmrg            fi
89287322289dSmrg            ;;
89297322289dSmrg          esac
89307322289dSmrg          ;;
89317322289dSmrg
89327322289dSmrg        solaris*)
89337322289dSmrg          func_cc_basename "$CC"
89347322289dSmrg          case $func_cc_basename_result in
89357322289dSmrg          CC* | sunCC*)
89367322289dSmrg            func_suncc_cstd_abi
89377322289dSmrg
89387322289dSmrg            if test no != "$suncc_use_cstd_abi"; then
89397322289dSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89407322289dSmrg            fi
89417322289dSmrg            ;;
89427322289dSmrg          esac
89437322289dSmrg          ;;
89447322289dSmrg        esac
89457322289dSmrg      }
89467322289dSmrg
8947d769e936Smrg      # Last step: remove runtime libs from dependency_libs
8948d769e936Smrg      # (they stay in deplibs)
8949d769e936Smrg      tmp_libs=
89507322289dSmrg      for i in $dependency_libs; do
8951d769e936Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8952d769e936Smrg	*" $i "*)
89537322289dSmrg	  i=
8954d769e936Smrg	  ;;
8955d769e936Smrg	esac
89567322289dSmrg	if test -n "$i"; then
8957d769e936Smrg	  func_append tmp_libs " $i"
8958d769e936Smrg	fi
8959d769e936Smrg      done
8960d769e936Smrg      dependency_libs=$tmp_libs
8961d769e936Smrg    done # for pass
89627322289dSmrg    if test prog = "$linkmode"; then
89637322289dSmrg      dlfiles=$newdlfiles
8964d769e936Smrg    fi
89657322289dSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
89667322289dSmrg      dlprefiles=$newdlprefiles
8967d769e936Smrg    fi
8968d769e936Smrg
8969d769e936Smrg    case $linkmode in
8970d769e936Smrg    oldlib)
89717322289dSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
89727322289dSmrg	func_warning "'-dlopen' is ignored for archives"
8973d769e936Smrg      fi
8974d769e936Smrg
8975d769e936Smrg      case " $deplibs" in
8976d769e936Smrg      *\ -l* | *\ -L*)
89777322289dSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8978d769e936Smrg      esac
8979d769e936Smrg
8980d769e936Smrg      test -n "$rpath" && \
89817322289dSmrg	func_warning "'-rpath' is ignored for archives"
8982d769e936Smrg
8983d769e936Smrg      test -n "$xrpath" && \
89847322289dSmrg	func_warning "'-R' is ignored for archives"
8985d769e936Smrg
8986d769e936Smrg      test -n "$vinfo" && \
89877322289dSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8988d769e936Smrg
8989d769e936Smrg      test -n "$release" && \
89907322289dSmrg	func_warning "'-release' is ignored for archives"
8991d769e936Smrg
8992d769e936Smrg      test -n "$export_symbols$export_symbols_regex" && \
89937322289dSmrg	func_warning "'-export-symbols' is ignored for archives"
8994d769e936Smrg
8995d769e936Smrg      # Now set the variables for building old libraries.
8996d769e936Smrg      build_libtool_libs=no
89977322289dSmrg      oldlibs=$output
8998d769e936Smrg      func_append objs "$old_deplibs"
8999d769e936Smrg      ;;
9000d769e936Smrg
9001d769e936Smrg    lib)
90027322289dSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9003d769e936Smrg      case $outputname in
9004d769e936Smrg      lib*)
9005d769e936Smrg	func_stripname 'lib' '.la' "$outputname"
9006d769e936Smrg	name=$func_stripname_result
9007d769e936Smrg	eval shared_ext=\"$shrext_cmds\"
9008d769e936Smrg	eval libname=\"$libname_spec\"
9009d769e936Smrg	;;
9010d769e936Smrg      *)
90117322289dSmrg	test no = "$module" \
90127322289dSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9013d769e936Smrg
90147322289dSmrg	if test no != "$need_lib_prefix"; then
9015d769e936Smrg	  # Add the "lib" prefix for modules if required
9016d769e936Smrg	  func_stripname '' '.la' "$outputname"
9017d769e936Smrg	  name=$func_stripname_result
9018d769e936Smrg	  eval shared_ext=\"$shrext_cmds\"
9019d769e936Smrg	  eval libname=\"$libname_spec\"
9020d769e936Smrg	else
9021d769e936Smrg	  func_stripname '' '.la' "$outputname"
9022d769e936Smrg	  libname=$func_stripname_result
9023d769e936Smrg	fi
9024d769e936Smrg	;;
9025d769e936Smrg      esac
9026d769e936Smrg
9027d769e936Smrg      if test -n "$objs"; then
90287322289dSmrg	if test pass_all != "$deplibs_check_method"; then
90297322289dSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9030d769e936Smrg	else
9031d769e936Smrg	  echo
9032d769e936Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9033d769e936Smrg	  $ECHO "*** objects $objs is not portable!"
9034d769e936Smrg	  func_append libobjs " $objs"
9035d769e936Smrg	fi
9036d769e936Smrg      fi
9037d769e936Smrg
90387322289dSmrg      test no = "$dlself" \
90397322289dSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9040d769e936Smrg
9041d769e936Smrg      set dummy $rpath
9042d769e936Smrg      shift
90437322289dSmrg      test 1 -lt "$#" \
90447322289dSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9045d769e936Smrg
90467322289dSmrg      install_libdir=$1
9047d769e936Smrg
9048d769e936Smrg      oldlibs=
9049d769e936Smrg      if test -z "$rpath"; then
90507322289dSmrg	if test yes = "$build_libtool_libs"; then
9051d769e936Smrg	  # Building a libtool convenience library.
90527322289dSmrg	  # Some compilers have problems with a '.al' extension so
9053d769e936Smrg	  # convenience libraries should have the same extension an
9054d769e936Smrg	  # archive normally would.
9055d769e936Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9056d769e936Smrg	  build_libtool_libs=convenience
9057d769e936Smrg	  build_old_libs=yes
9058d769e936Smrg	fi
9059d769e936Smrg
9060d769e936Smrg	test -n "$vinfo" && \
90617322289dSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9062d769e936Smrg
9063d769e936Smrg	test -n "$release" && \
90647322289dSmrg	  func_warning "'-release' is ignored for convenience libraries"
9065d769e936Smrg      else
9066d769e936Smrg
9067d769e936Smrg	# Parse the version information argument.
90687322289dSmrg	save_ifs=$IFS; IFS=:
9069d769e936Smrg	set dummy $vinfo 0 0 0
9070d769e936Smrg	shift
90717322289dSmrg	IFS=$save_ifs
9072d769e936Smrg
9073d769e936Smrg	test -n "$7" && \
90747322289dSmrg	  func_fatal_help "too many parameters to '-version-info'"
9075d769e936Smrg
9076d769e936Smrg	# convert absolute version numbers to libtool ages
9077d769e936Smrg	# this retains compatibility with .la files and attempts
9078d769e936Smrg	# to make the code below a bit more comprehensible
9079d769e936Smrg
9080d769e936Smrg	case $vinfo_number in
9081d769e936Smrg	yes)
90827322289dSmrg	  number_major=$1
90837322289dSmrg	  number_minor=$2
90847322289dSmrg	  number_revision=$3
9085d769e936Smrg	  #
9086d769e936Smrg	  # There are really only two kinds -- those that
9087d769e936Smrg	  # use the current revision as the major version
9088d769e936Smrg	  # and those that subtract age and use age as
9089d769e936Smrg	  # a minor version.  But, then there is irix
90907322289dSmrg	  # that has an extra 1 added just for fun
9091d769e936Smrg	  #
9092d769e936Smrg	  case $version_type in
9093d769e936Smrg	  # correct linux to gnu/linux during the next big refactor
909422663e35Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9095d769e936Smrg	    func_arith $number_major + $number_minor
9096d769e936Smrg	    current=$func_arith_result
90977322289dSmrg	    age=$number_minor
90987322289dSmrg	    revision=$number_revision
9099d769e936Smrg	    ;;
91007322289dSmrg	  freebsd-aout|qnx|sunos)
91017322289dSmrg	    current=$number_major
91027322289dSmrg	    revision=$number_minor
91037322289dSmrg	    age=0
9104d769e936Smrg	    ;;
9105d769e936Smrg	  irix|nonstopux)
9106d769e936Smrg	    func_arith $number_major + $number_minor
9107d769e936Smrg	    current=$func_arith_result
91087322289dSmrg	    age=$number_minor
91097322289dSmrg	    revision=$number_minor
9110d769e936Smrg	    lt_irix_increment=no
9111d769e936Smrg	    ;;
9112d769e936Smrg	  esac
9113d769e936Smrg	  ;;
9114d769e936Smrg	no)
91157322289dSmrg	  current=$1
91167322289dSmrg	  revision=$2
91177322289dSmrg	  age=$3
9118d769e936Smrg	  ;;
9119d769e936Smrg	esac
9120d769e936Smrg
9121d769e936Smrg	# Check that each of the things are valid numbers.
9122d769e936Smrg	case $current in
9123d769e936Smrg	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]) ;;
9124d769e936Smrg	*)
91257322289dSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
91267322289dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9127d769e936Smrg	  ;;
9128d769e936Smrg	esac
9129d769e936Smrg
9130d769e936Smrg	case $revision in
9131d769e936Smrg	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]) ;;
9132d769e936Smrg	*)
91337322289dSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
91347322289dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9135d769e936Smrg	  ;;
9136d769e936Smrg	esac
9137d769e936Smrg
9138d769e936Smrg	case $age in
9139d769e936Smrg	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]) ;;
9140d769e936Smrg	*)
91417322289dSmrg	  func_error "AGE '$age' must be a nonnegative integer"
91427322289dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9143d769e936Smrg	  ;;
9144d769e936Smrg	esac
9145d769e936Smrg
9146d769e936Smrg	if test "$age" -gt "$current"; then
91477322289dSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
91487322289dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9149d769e936Smrg	fi
9150d769e936Smrg
9151d769e936Smrg	# Calculate the version variables.
9152d769e936Smrg	major=
9153d769e936Smrg	versuffix=
9154d769e936Smrg	verstring=
9155d769e936Smrg	case $version_type in
9156d769e936Smrg	none) ;;
9157d769e936Smrg
9158d769e936Smrg	darwin)
9159d769e936Smrg	  # Like Linux, but with the current version available in
9160d769e936Smrg	  # verstring for coding it into the library header
9161d769e936Smrg	  func_arith $current - $age
9162d769e936Smrg	  major=.$func_arith_result
91637322289dSmrg	  versuffix=$major.$age.$revision
9164d769e936Smrg	  # Darwin ld doesn't like 0 for these options...
9165d769e936Smrg	  func_arith $current + 1
9166d769e936Smrg	  minor_current=$func_arith_result
91677322289dSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168d769e936Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91697322289dSmrg          # On Darwin other compilers
91707322289dSmrg          case $CC in
91717322289dSmrg              nagfor*)
91727322289dSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91737322289dSmrg                  ;;
91747322289dSmrg              *)
91757322289dSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91767322289dSmrg                  ;;
91777322289dSmrg          esac
9178d769e936Smrg	  ;;
9179d769e936Smrg
9180d769e936Smrg	freebsd-aout)
91817322289dSmrg	  major=.$current
91827322289dSmrg	  versuffix=.$current.$revision
9183d769e936Smrg	  ;;
9184d769e936Smrg
918522663e35Smrg	freebsd-elf | midnightbsd-elf)
91867322289dSmrg	  func_arith $current - $age
91877322289dSmrg	  major=.$func_arith_result
91887322289dSmrg	  versuffix=$major.$age.$revision
9189d769e936Smrg	  ;;
9190d769e936Smrg
9191d769e936Smrg	irix | nonstopux)
91927322289dSmrg	  if test no = "$lt_irix_increment"; then
9193d769e936Smrg	    func_arith $current - $age
9194d769e936Smrg	  else
9195d769e936Smrg	    func_arith $current - $age + 1
9196d769e936Smrg	  fi
9197d769e936Smrg	  major=$func_arith_result
9198d769e936Smrg
9199d769e936Smrg	  case $version_type in
9200d769e936Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9201d769e936Smrg	    *)         verstring_prefix=sgi ;;
9202d769e936Smrg	  esac
92037322289dSmrg	  verstring=$verstring_prefix$major.$revision
9204d769e936Smrg
9205d769e936Smrg	  # Add in all the interfaces that we are compatible with.
9206d769e936Smrg	  loop=$revision
92077322289dSmrg	  while test 0 -ne "$loop"; do
9208d769e936Smrg	    func_arith $revision - $loop
9209d769e936Smrg	    iface=$func_arith_result
9210d769e936Smrg	    func_arith $loop - 1
9211d769e936Smrg	    loop=$func_arith_result
92127322289dSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213d769e936Smrg	  done
9214d769e936Smrg
92157322289dSmrg	  # Before this point, $major must not contain '.'.
9216d769e936Smrg	  major=.$major
92177322289dSmrg	  versuffix=$major.$revision
9218d769e936Smrg	  ;;
9219d769e936Smrg
9220d769e936Smrg	linux) # correct to gnu/linux during the next big refactor
9221d769e936Smrg	  func_arith $current - $age
9222d769e936Smrg	  major=.$func_arith_result
92237322289dSmrg	  versuffix=$major.$age.$revision
9224d769e936Smrg	  ;;
9225d769e936Smrg
9226d769e936Smrg	osf)
9227d769e936Smrg	  func_arith $current - $age
9228d769e936Smrg	  major=.$func_arith_result
92297322289dSmrg	  versuffix=.$current.$age.$revision
92307322289dSmrg	  verstring=$current.$age.$revision
9231d769e936Smrg
9232d769e936Smrg	  # Add in all the interfaces that we are compatible with.
9233d769e936Smrg	  loop=$age
92347322289dSmrg	  while test 0 -ne "$loop"; do
9235d769e936Smrg	    func_arith $current - $loop
9236d769e936Smrg	    iface=$func_arith_result
9237d769e936Smrg	    func_arith $loop - 1
9238d769e936Smrg	    loop=$func_arith_result
92397322289dSmrg	    verstring=$verstring:$iface.0
9240d769e936Smrg	  done
9241d769e936Smrg
9242d769e936Smrg	  # Make executables depend on our current version.
92437322289dSmrg	  func_append verstring ":$current.0"
9244d769e936Smrg	  ;;
9245d769e936Smrg
9246d769e936Smrg	qnx)
92477322289dSmrg	  major=.$current
92487322289dSmrg	  versuffix=.$current
92497322289dSmrg	  ;;
92507322289dSmrg
92517322289dSmrg	sco)
92527322289dSmrg	  major=.$current
92537322289dSmrg	  versuffix=.$current
9254d769e936Smrg	  ;;
9255d769e936Smrg
9256d769e936Smrg	sunos)
92577322289dSmrg	  major=.$current
92587322289dSmrg	  versuffix=.$current.$revision
9259d769e936Smrg	  ;;
9260d769e936Smrg
9261d769e936Smrg	windows)
9262d769e936Smrg	  # Use '-' rather than '.', since we only want one
92637322289dSmrg	  # extension on DOS 8.3 file systems.
9264d769e936Smrg	  func_arith $current - $age
9265d769e936Smrg	  major=$func_arith_result
92667322289dSmrg	  versuffix=-$major
9267d769e936Smrg	  ;;
9268d769e936Smrg
9269d769e936Smrg	*)
92707322289dSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271d769e936Smrg	  ;;
9272d769e936Smrg	esac
9273d769e936Smrg
9274d769e936Smrg	# Clear the version info if we defaulted, and they specified a release.
9275d769e936Smrg	if test -z "$vinfo" && test -n "$release"; then
9276d769e936Smrg	  major=
9277d769e936Smrg	  case $version_type in
9278d769e936Smrg	  darwin)
9279d769e936Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280d769e936Smrg	    # problems, so we reset it completely
9281d769e936Smrg	    verstring=
9282d769e936Smrg	    ;;
9283d769e936Smrg	  *)
92847322289dSmrg	    verstring=0.0
9285d769e936Smrg	    ;;
9286d769e936Smrg	  esac
92877322289dSmrg	  if test no = "$need_version"; then
9288d769e936Smrg	    versuffix=
9289d769e936Smrg	  else
92907322289dSmrg	    versuffix=.0.0
9291d769e936Smrg	  fi
9292d769e936Smrg	fi
9293d769e936Smrg
9294d769e936Smrg	# Remove version info from name if versioning should be avoided
92957322289dSmrg	if test yes,no = "$avoid_version,$need_version"; then
9296d769e936Smrg	  major=
9297d769e936Smrg	  versuffix=
92987322289dSmrg	  verstring=
9299d769e936Smrg	fi
9300d769e936Smrg
9301d769e936Smrg	# Check to see if the archive will have undefined symbols.
93027322289dSmrg	if test yes = "$allow_undefined"; then
93037322289dSmrg	  if test unsupported = "$allow_undefined_flag"; then
93047322289dSmrg	    if test yes = "$build_old_libs"; then
93057322289dSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
93067322289dSmrg	      build_libtool_libs=no
93077322289dSmrg	    else
93087322289dSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
93097322289dSmrg	    fi
9310d769e936Smrg	  fi
9311d769e936Smrg	else
9312d769e936Smrg	  # Don't allow undefined symbols.
93137322289dSmrg	  allow_undefined_flag=$no_undefined_flag
9314d769e936Smrg	fi
9315d769e936Smrg
9316d769e936Smrg      fi
9317d769e936Smrg
93187322289dSmrg      func_generate_dlsyms "$libname" "$libname" :
9319d769e936Smrg      func_append libobjs " $symfileobj"
93207322289dSmrg      test " " = "$libobjs" && libobjs=
9321d769e936Smrg
93227322289dSmrg      if test relink != "$opt_mode"; then
9323d769e936Smrg	# Remove our outputs, but don't remove object files since they
9324d769e936Smrg	# may have been created when compiling PIC objects.
9325d769e936Smrg	removelist=
9326d769e936Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327d769e936Smrg	for p in $tempremovelist; do
9328d769e936Smrg	  case $p in
9329d769e936Smrg	    *.$objext | *.gcno)
9330d769e936Smrg	       ;;
93317322289dSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
93327322289dSmrg	       if test -n "$precious_files_regex"; then
9333d769e936Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334d769e936Smrg		 then
9335d769e936Smrg		   continue
9336d769e936Smrg		 fi
9337d769e936Smrg	       fi
9338d769e936Smrg	       func_append removelist " $p"
9339d769e936Smrg	       ;;
9340d769e936Smrg	    *) ;;
9341d769e936Smrg	  esac
9342d769e936Smrg	done
9343d769e936Smrg	test -n "$removelist" && \
9344d769e936Smrg	  func_show_eval "${RM}r \$removelist"
9345d769e936Smrg      fi
9346d769e936Smrg
9347d769e936Smrg      # Now set the variables for building old libraries.
93487322289dSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349d769e936Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350d769e936Smrg
9351d769e936Smrg	# Transform .lo files to .o files.
93527322289dSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353d769e936Smrg      fi
9354d769e936Smrg
9355d769e936Smrg      # Eliminate all temporary directories.
9356d769e936Smrg      #for path in $notinst_path; do
9357d769e936Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358d769e936Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359d769e936Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360d769e936Smrg      #done
9361d769e936Smrg
9362d769e936Smrg      if test -n "$xrpath"; then
9363d769e936Smrg	# If the user specified any rpath flags, then add them.
9364d769e936Smrg	temp_xrpath=
9365d769e936Smrg	for libdir in $xrpath; do
9366d769e936Smrg	  func_replace_sysroot "$libdir"
9367d769e936Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368d769e936Smrg	  case "$finalize_rpath " in
9369d769e936Smrg	  *" $libdir "*) ;;
9370d769e936Smrg	  *) func_append finalize_rpath " $libdir" ;;
9371d769e936Smrg	  esac
9372d769e936Smrg	done
93737322289dSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374d769e936Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375d769e936Smrg	fi
9376d769e936Smrg      fi
9377d769e936Smrg
9378d769e936Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
93797322289dSmrg      old_dlfiles=$dlfiles
9380d769e936Smrg      dlfiles=
9381d769e936Smrg      for lib in $old_dlfiles; do
9382d769e936Smrg	case " $dlprefiles $dlfiles " in
9383d769e936Smrg	*" $lib "*) ;;
9384d769e936Smrg	*) func_append dlfiles " $lib" ;;
9385d769e936Smrg	esac
9386d769e936Smrg      done
9387d769e936Smrg
9388d769e936Smrg      # Make sure dlprefiles contains only unique files
93897322289dSmrg      old_dlprefiles=$dlprefiles
9390d769e936Smrg      dlprefiles=
9391d769e936Smrg      for lib in $old_dlprefiles; do
9392d769e936Smrg	case "$dlprefiles " in
9393d769e936Smrg	*" $lib "*) ;;
9394d769e936Smrg	*) func_append dlprefiles " $lib" ;;
9395d769e936Smrg	esac
9396d769e936Smrg      done
9397d769e936Smrg
93987322289dSmrg      if test yes = "$build_libtool_libs"; then
9399d769e936Smrg	if test -n "$rpath"; then
9400d769e936Smrg	  case $host in
9401d769e936Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402d769e936Smrg	    # these systems don't actually have a c library (as such)!
9403d769e936Smrg	    ;;
9404d769e936Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405d769e936Smrg	    # Rhapsody C library is in the System framework
9406d769e936Smrg	    func_append deplibs " System.ltframework"
9407d769e936Smrg	    ;;
9408d769e936Smrg	  *-*-netbsd*)
9409d769e936Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9410d769e936Smrg	    ;;
941122663e35Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412d769e936Smrg	    # Do not include libc due to us having libc/libc_r.
9413d769e936Smrg	    ;;
9414d769e936Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415d769e936Smrg	    # Causes problems with __ctype
9416d769e936Smrg	    ;;
9417d769e936Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418d769e936Smrg	    # Compiler inserts libc in the correct place for threads to work
9419d769e936Smrg	    ;;
9420d769e936Smrg	  *)
9421d769e936Smrg	    # Add libc to deplibs on all other systems if necessary.
94227322289dSmrg	    if test yes = "$build_libtool_need_lc"; then
9423d769e936Smrg	      func_append deplibs " -lc"
9424d769e936Smrg	    fi
9425d769e936Smrg	    ;;
9426d769e936Smrg	  esac
9427d769e936Smrg	fi
9428d769e936Smrg
9429d769e936Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9430d769e936Smrg	name_save=$name
9431d769e936Smrg	libname_save=$libname
9432d769e936Smrg	release_save=$release
9433d769e936Smrg	versuffix_save=$versuffix
9434d769e936Smrg	major_save=$major
9435d769e936Smrg	# I'm not sure if I'm treating the release correctly.  I think
9436d769e936Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437d769e936Smrg	# add it in twice.  Is that correct?
94387322289dSmrg	release=
94397322289dSmrg	versuffix=
94407322289dSmrg	major=
9441d769e936Smrg	newdeplibs=
9442d769e936Smrg	droppeddeps=no
9443d769e936Smrg	case $deplibs_check_method in
9444d769e936Smrg	pass_all)
9445d769e936Smrg	  # Don't check for shared/static.  Everything works.
9446d769e936Smrg	  # This might be a little naive.  We might want to check
9447d769e936Smrg	  # whether the library exists or not.  But this is on
9448d769e936Smrg	  # osf3 & osf4 and I'm not really sure... Just
9449d769e936Smrg	  # implementing what was already the behavior.
9450d769e936Smrg	  newdeplibs=$deplibs
9451d769e936Smrg	  ;;
9452d769e936Smrg	test_compile)
9453d769e936Smrg	  # This code stresses the "libraries are programs" paradigm to its
9454d769e936Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455d769e936Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9456d769e936Smrg	  # whether they linked in statically or dynamically with ldd.
9457d769e936Smrg	  $opt_dry_run || $RM conftest.c
9458d769e936Smrg	  cat > conftest.c <<EOF
9459d769e936Smrg	  int main() { return 0; }
9460d769e936SmrgEOF
9461d769e936Smrg	  $opt_dry_run || $RM conftest
9462d769e936Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463d769e936Smrg	    ldd_output=`ldd conftest`
9464d769e936Smrg	    for i in $deplibs; do
9465d769e936Smrg	      case $i in
9466d769e936Smrg	      -l*)
9467d769e936Smrg		func_stripname -l '' "$i"
9468d769e936Smrg		name=$func_stripname_result
94697322289dSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470d769e936Smrg		  case " $predeps $postdeps " in
9471d769e936Smrg		  *" $i "*)
9472d769e936Smrg		    func_append newdeplibs " $i"
94737322289dSmrg		    i=
9474d769e936Smrg		    ;;
9475d769e936Smrg		  esac
9476d769e936Smrg		fi
94777322289dSmrg		if test -n "$i"; then
9478d769e936Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479d769e936Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480d769e936Smrg		  set dummy $deplib_matches; shift
9481d769e936Smrg		  deplib_match=$1
94827322289dSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483d769e936Smrg		    func_append newdeplibs " $i"
9484d769e936Smrg		  else
9485d769e936Smrg		    droppeddeps=yes
9486d769e936Smrg		    echo
9487d769e936Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488d769e936Smrg		    echo "*** I have the capability to make that library automatically link in when"
9489d769e936Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490d769e936Smrg		    echo "*** shared version of the library, which I believe you do not have"
9491d769e936Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492d769e936Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493d769e936Smrg		  fi
9494d769e936Smrg		fi
9495d769e936Smrg		;;
9496d769e936Smrg	      *)
9497d769e936Smrg		func_append newdeplibs " $i"
9498d769e936Smrg		;;
9499d769e936Smrg	      esac
9500d769e936Smrg	    done
9501d769e936Smrg	  else
9502d769e936Smrg	    # Error occurred in the first compile.  Let's try to salvage
9503d769e936Smrg	    # the situation: Compile a separate program for each library.
9504d769e936Smrg	    for i in $deplibs; do
9505d769e936Smrg	      case $i in
9506d769e936Smrg	      -l*)
9507d769e936Smrg		func_stripname -l '' "$i"
9508d769e936Smrg		name=$func_stripname_result
9509d769e936Smrg		$opt_dry_run || $RM conftest
9510d769e936Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511d769e936Smrg		  ldd_output=`ldd conftest`
95127322289dSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513d769e936Smrg		    case " $predeps $postdeps " in
9514d769e936Smrg		    *" $i "*)
9515d769e936Smrg		      func_append newdeplibs " $i"
95167322289dSmrg		      i=
9517d769e936Smrg		      ;;
9518d769e936Smrg		    esac
9519d769e936Smrg		  fi
95207322289dSmrg		  if test -n "$i"; then
9521d769e936Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522d769e936Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523d769e936Smrg		    set dummy $deplib_matches; shift
9524d769e936Smrg		    deplib_match=$1
95257322289dSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526d769e936Smrg		      func_append newdeplibs " $i"
9527d769e936Smrg		    else
9528d769e936Smrg		      droppeddeps=yes
9529d769e936Smrg		      echo
9530d769e936Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531d769e936Smrg		      echo "*** I have the capability to make that library automatically link in when"
9532d769e936Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533d769e936Smrg		      echo "*** shared version of the library, which you do not appear to have"
9534d769e936Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535d769e936Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536d769e936Smrg		    fi
9537d769e936Smrg		  fi
9538d769e936Smrg		else
9539d769e936Smrg		  droppeddeps=yes
9540d769e936Smrg		  echo
9541d769e936Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542d769e936Smrg		  echo "*** make it link in!  You will probably need to install it or some"
9543d769e936Smrg		  echo "*** library that it depends on before this library will be fully"
9544d769e936Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9545d769e936Smrg		fi
9546d769e936Smrg		;;
9547d769e936Smrg	      *)
9548d769e936Smrg		func_append newdeplibs " $i"
9549d769e936Smrg		;;
9550d769e936Smrg	      esac
9551d769e936Smrg	    done
9552d769e936Smrg	  fi
9553d769e936Smrg	  ;;
9554d769e936Smrg	file_magic*)
9555d769e936Smrg	  set dummy $deplibs_check_method; shift
9556d769e936Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557d769e936Smrg	  for a_deplib in $deplibs; do
9558d769e936Smrg	    case $a_deplib in
9559d769e936Smrg	    -l*)
9560d769e936Smrg	      func_stripname -l '' "$a_deplib"
9561d769e936Smrg	      name=$func_stripname_result
95627322289dSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563d769e936Smrg		case " $predeps $postdeps " in
9564d769e936Smrg		*" $a_deplib "*)
9565d769e936Smrg		  func_append newdeplibs " $a_deplib"
95667322289dSmrg		  a_deplib=
9567d769e936Smrg		  ;;
9568d769e936Smrg		esac
9569d769e936Smrg	      fi
95707322289dSmrg	      if test -n "$a_deplib"; then
9571d769e936Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572d769e936Smrg		if test -n "$file_magic_glob"; then
9573d769e936Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574d769e936Smrg		else
9575d769e936Smrg		  libnameglob=$libname
9576d769e936Smrg		fi
95777322289dSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578d769e936Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
95797322289dSmrg		  if test yes = "$want_nocaseglob"; then
9580d769e936Smrg		    shopt -s nocaseglob
9581d769e936Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582d769e936Smrg		    $nocaseglob
9583d769e936Smrg		  else
9584d769e936Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585d769e936Smrg		  fi
9586d769e936Smrg		  for potent_lib in $potential_libs; do
9587d769e936Smrg		      # Follow soft links.
9588d769e936Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589d769e936Smrg			 $GREP " -> " >/dev/null; then
9590d769e936Smrg			continue
9591d769e936Smrg		      fi
9592d769e936Smrg		      # The statement above tries to avoid entering an
9593d769e936Smrg		      # endless loop below, in case of cyclic links.
9594d769e936Smrg		      # We might still enter an endless loop, since a link
9595d769e936Smrg		      # loop can be closed while we follow links,
9596d769e936Smrg		      # but so what?
95977322289dSmrg		      potlib=$potent_lib
9598d769e936Smrg		      while test -h "$potlib" 2>/dev/null; do
95997322289dSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600d769e936Smrg			case $potliblink in
96017322289dSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
96027322289dSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603d769e936Smrg			esac
9604d769e936Smrg		      done
9605d769e936Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606d769e936Smrg			 $SED -e 10q |
9607d769e936Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608d769e936Smrg			func_append newdeplibs " $a_deplib"
96097322289dSmrg			a_deplib=
9610d769e936Smrg			break 2
9611d769e936Smrg		      fi
9612d769e936Smrg		  done
9613d769e936Smrg		done
9614d769e936Smrg	      fi
96157322289dSmrg	      if test -n "$a_deplib"; then
9616d769e936Smrg		droppeddeps=yes
9617d769e936Smrg		echo
9618d769e936Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619d769e936Smrg		echo "*** I have the capability to make that library automatically link in when"
9620d769e936Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9621d769e936Smrg		echo "*** shared version of the library, which you do not appear to have"
9622d769e936Smrg		echo "*** because I did check the linker path looking for a file starting"
96237322289dSmrg		if test -z "$potlib"; then
9624d769e936Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625d769e936Smrg		else
9626d769e936Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627d769e936Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628d769e936Smrg		fi
9629d769e936Smrg	      fi
9630d769e936Smrg	      ;;
9631d769e936Smrg	    *)
9632d769e936Smrg	      # Add a -L argument.
9633d769e936Smrg	      func_append newdeplibs " $a_deplib"
9634d769e936Smrg	      ;;
9635d769e936Smrg	    esac
9636d769e936Smrg	  done # Gone through all deplibs.
9637d769e936Smrg	  ;;
9638d769e936Smrg	match_pattern*)
9639d769e936Smrg	  set dummy $deplibs_check_method; shift
9640d769e936Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641d769e936Smrg	  for a_deplib in $deplibs; do
9642d769e936Smrg	    case $a_deplib in
9643d769e936Smrg	    -l*)
9644d769e936Smrg	      func_stripname -l '' "$a_deplib"
9645d769e936Smrg	      name=$func_stripname_result
96467322289dSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647d769e936Smrg		case " $predeps $postdeps " in
9648d769e936Smrg		*" $a_deplib "*)
9649d769e936Smrg		  func_append newdeplibs " $a_deplib"
96507322289dSmrg		  a_deplib=
9651d769e936Smrg		  ;;
9652d769e936Smrg		esac
9653d769e936Smrg	      fi
96547322289dSmrg	      if test -n "$a_deplib"; then
9655d769e936Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656d769e936Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657d769e936Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658d769e936Smrg		  for potent_lib in $potential_libs; do
96597322289dSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660d769e936Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661d769e936Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662d769e936Smrg		      func_append newdeplibs " $a_deplib"
96637322289dSmrg		      a_deplib=
9664d769e936Smrg		      break 2
9665d769e936Smrg		    fi
9666d769e936Smrg		  done
9667d769e936Smrg		done
9668d769e936Smrg	      fi
96697322289dSmrg	      if test -n "$a_deplib"; then
9670d769e936Smrg		droppeddeps=yes
9671d769e936Smrg		echo
9672d769e936Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673d769e936Smrg		echo "*** I have the capability to make that library automatically link in when"
9674d769e936Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9675d769e936Smrg		echo "*** shared version of the library, which you do not appear to have"
9676d769e936Smrg		echo "*** because I did check the linker path looking for a file starting"
96777322289dSmrg		if test -z "$potlib"; then
9678d769e936Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679d769e936Smrg		else
9680d769e936Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681d769e936Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682d769e936Smrg		fi
9683d769e936Smrg	      fi
9684d769e936Smrg	      ;;
9685d769e936Smrg	    *)
9686d769e936Smrg	      # Add a -L argument.
9687d769e936Smrg	      func_append newdeplibs " $a_deplib"
9688d769e936Smrg	      ;;
9689d769e936Smrg	    esac
9690d769e936Smrg	  done # Gone through all deplibs.
9691d769e936Smrg	  ;;
9692d769e936Smrg	none | unknown | *)
96937322289dSmrg	  newdeplibs=
9694d769e936Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
96957322289dSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96967322289dSmrg	    for i in $predeps $postdeps; do
9697d769e936Smrg	      # can't use Xsed below, because $i might contain '/'
96987322289dSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699d769e936Smrg	    done
9700d769e936Smrg	  fi
9701d769e936Smrg	  case $tmp_deplibs in
9702d769e936Smrg	  *[!\	\ ]*)
9703d769e936Smrg	    echo
97047322289dSmrg	    if test none = "$deplibs_check_method"; then
9705d769e936Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706d769e936Smrg	    else
9707d769e936Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708d769e936Smrg	    fi
9709d769e936Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9710d769e936Smrg	    droppeddeps=yes
9711d769e936Smrg	    ;;
9712d769e936Smrg	  esac
9713d769e936Smrg	  ;;
9714d769e936Smrg	esac
9715d769e936Smrg	versuffix=$versuffix_save
9716d769e936Smrg	major=$major_save
9717d769e936Smrg	release=$release_save
9718d769e936Smrg	libname=$libname_save
9719d769e936Smrg	name=$name_save
97201d54945dSmrg
9721d769e936Smrg	case $host in
9722d769e936Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9723d769e936Smrg	  # On Rhapsody replace the C library with the System framework
9724d769e936Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725d769e936Smrg	  ;;
9726d769e936Smrg	esac
9727786a6f21Smrg
97287322289dSmrg	if test yes = "$droppeddeps"; then
97297322289dSmrg	  if test yes = "$module"; then
9730d769e936Smrg	    echo
9731d769e936Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732d769e936Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733d769e936Smrg	    echo "*** a static module, that should work as long as the dlopening"
9734d769e936Smrg	    echo "*** application is linked with the -dlopen flag."
9735d769e936Smrg	    if test -z "$global_symbol_pipe"; then
9736d769e936Smrg	      echo
9737d769e936Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
97387322289dSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739d769e936Smrg	      echo "*** not find such a program.  So, this module is probably useless."
97407322289dSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741d769e936Smrg	    fi
97427322289dSmrg	    if test no = "$build_old_libs"; then
97437322289dSmrg	      oldlibs=$output_objdir/$libname.$libext
9744d769e936Smrg	      build_libtool_libs=module
9745d769e936Smrg	      build_old_libs=yes
9746d769e936Smrg	    else
9747d769e936Smrg	      build_libtool_libs=no
9748d769e936Smrg	    fi
9749d769e936Smrg	  else
9750d769e936Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751d769e936Smrg	    echo "*** automatically added whenever a program is linked with this library"
9752d769e936Smrg	    echo "*** or is declared to -dlopen it."
9753786a6f21Smrg
97547322289dSmrg	    if test no = "$allow_undefined"; then
9755d769e936Smrg	      echo
9756d769e936Smrg	      echo "*** Since this library must not contain undefined symbols,"
9757d769e936Smrg	      echo "*** because either the platform does not support them or"
9758d769e936Smrg	      echo "*** it was explicitly requested with -no-undefined,"
9759d769e936Smrg	      echo "*** libtool will only create a static version of it."
97607322289dSmrg	      if test no = "$build_old_libs"; then
97617322289dSmrg		oldlibs=$output_objdir/$libname.$libext
9762d769e936Smrg		build_libtool_libs=module
9763d769e936Smrg		build_old_libs=yes
9764d769e936Smrg	      else
9765d769e936Smrg		build_libtool_libs=no
9766d769e936Smrg	      fi
9767d769e936Smrg	    fi
9768d769e936Smrg	  fi
97691d54945dSmrg	fi
9770d769e936Smrg	# Done checking deplibs!
9771d769e936Smrg	deplibs=$newdeplibs
9772d769e936Smrg      fi
9773d769e936Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774d769e936Smrg      case $host in
9775d769e936Smrg	*-*-darwin*)
9776d769e936Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777d769e936Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778d769e936Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779d769e936Smrg	  ;;
9780d769e936Smrg      esac
97811d54945dSmrg
9782d769e936Smrg      # move library search paths that coincide with paths to not yet
9783d769e936Smrg      # installed libraries to the beginning of the library search list
9784d769e936Smrg      new_libs=
9785d769e936Smrg      for path in $notinst_path; do
9786d769e936Smrg	case " $new_libs " in
9787d769e936Smrg	*" -L$path/$objdir "*) ;;
9788d769e936Smrg	*)
9789d769e936Smrg	  case " $deplibs " in
9790d769e936Smrg	  *" -L$path/$objdir "*)
9791d769e936Smrg	    func_append new_libs " -L$path/$objdir" ;;
9792d769e936Smrg	  esac
9793d769e936Smrg	  ;;
9794d769e936Smrg	esac
9795d769e936Smrg      done
9796d769e936Smrg      for deplib in $deplibs; do
9797d769e936Smrg	case $deplib in
9798d769e936Smrg	-L*)
9799d769e936Smrg	  case " $new_libs " in
9800d769e936Smrg	  *" $deplib "*) ;;
9801d769e936Smrg	  *) func_append new_libs " $deplib" ;;
9802d769e936Smrg	  esac
9803d769e936Smrg	  ;;
9804d769e936Smrg	*) func_append new_libs " $deplib" ;;
9805d769e936Smrg	esac
9806d769e936Smrg      done
98077322289dSmrg      deplibs=$new_libs
98081d54945dSmrg
9809d769e936Smrg      # All the library-specific variables (install_libdir is set above).
9810d769e936Smrg      library_names=
9811d769e936Smrg      old_library=
9812d769e936Smrg      dlname=
98131d54945dSmrg
9814d769e936Smrg      # Test again, we may have decided not to build it any more
98157322289dSmrg      if test yes = "$build_libtool_libs"; then
98167322289dSmrg	# Remove $wl instances when linking with ld.
9817d769e936Smrg	# FIXME: should test the right _cmds variable.
9818d769e936Smrg	case $archive_cmds in
9819d769e936Smrg	  *\$LD\ *) wl= ;;
9820d769e936Smrg        esac
98217322289dSmrg	if test yes = "$hardcode_into_libs"; then
9822d769e936Smrg	  # Hardcode the library paths
9823d769e936Smrg	  hardcode_libdirs=
9824d769e936Smrg	  dep_rpath=
98257322289dSmrg	  rpath=$finalize_rpath
98267322289dSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827d769e936Smrg	  for libdir in $rpath; do
9828d769e936Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829d769e936Smrg	      if test -n "$hardcode_libdir_separator"; then
9830d769e936Smrg		func_replace_sysroot "$libdir"
9831d769e936Smrg		libdir=$func_replace_sysroot_result
9832d769e936Smrg		if test -z "$hardcode_libdirs"; then
98337322289dSmrg		  hardcode_libdirs=$libdir
9834d769e936Smrg		else
9835d769e936Smrg		  # Just accumulate the unique libdirs.
9836d769e936Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837d769e936Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838d769e936Smrg		    ;;
9839d769e936Smrg		  *)
9840d769e936Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841d769e936Smrg		    ;;
9842d769e936Smrg		  esac
9843d769e936Smrg		fi
9844d769e936Smrg	      else
9845d769e936Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846d769e936Smrg		func_append dep_rpath " $flag"
9847d769e936Smrg	      fi
9848d769e936Smrg	    elif test -n "$runpath_var"; then
9849d769e936Smrg	      case "$perm_rpath " in
9850d769e936Smrg	      *" $libdir "*) ;;
9851d769e936Smrg	      *) func_append perm_rpath " $libdir" ;;
9852d769e936Smrg	      esac
9853d769e936Smrg	    fi
9854d769e936Smrg	  done
9855d769e936Smrg	  # Substitute the hardcoded libdirs into the rpath.
9856d769e936Smrg	  if test -n "$hardcode_libdir_separator" &&
9857d769e936Smrg	     test -n "$hardcode_libdirs"; then
98587322289dSmrg	    libdir=$hardcode_libdirs
9859d769e936Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860d769e936Smrg	  fi
9861d769e936Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862d769e936Smrg	    # We should set the runpath_var.
9863d769e936Smrg	    rpath=
9864d769e936Smrg	    for dir in $perm_rpath; do
9865d769e936Smrg	      func_append rpath "$dir:"
9866d769e936Smrg	    done
9867d769e936Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868d769e936Smrg	  fi
9869d769e936Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870ec713c28Smrg	fi
9871786a6f21Smrg
98727322289dSmrg	shlibpath=$finalize_shlibpath
98737322289dSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874d769e936Smrg	if test -n "$shlibpath"; then
9875d769e936Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876ec713c28Smrg	fi
9877786a6f21Smrg
9878d769e936Smrg	# Get the real and link names of the library.
9879d769e936Smrg	eval shared_ext=\"$shrext_cmds\"
9880d769e936Smrg	eval library_names=\"$library_names_spec\"
9881d769e936Smrg	set dummy $library_names
9882d769e936Smrg	shift
98837322289dSmrg	realname=$1
9884d769e936Smrg	shift
9885786a6f21Smrg
9886d769e936Smrg	if test -n "$soname_spec"; then
9887d769e936Smrg	  eval soname=\"$soname_spec\"
9888ec713c28Smrg	else
98897322289dSmrg	  soname=$realname
9890d769e936Smrg	fi
9891d769e936Smrg	if test -z "$dlname"; then
9892d769e936Smrg	  dlname=$soname
9893ec713c28Smrg	fi
9894786a6f21Smrg
98957322289dSmrg	lib=$output_objdir/$realname
9896d769e936Smrg	linknames=
9897d769e936Smrg	for link
9898d769e936Smrg	do
9899d769e936Smrg	  func_append linknames " $link"
9900d769e936Smrg	done
9901786a6f21Smrg
9902d769e936Smrg	# Use standard objects if they are pic
9903d769e936Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904d769e936Smrg	test "X$libobjs" = "X " && libobjs=
9905786a6f21Smrg
9906d769e936Smrg	delfiles=
9907d769e936Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908d769e936Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
99097322289dSmrg	  export_symbols=$output_objdir/$libname.uexp
9910d769e936Smrg	  func_append delfiles " $export_symbols"
9911d769e936Smrg	fi
99121d54945dSmrg
9913d769e936Smrg	orig_export_symbols=
9914d769e936Smrg	case $host_os in
9915d769e936Smrg	cygwin* | mingw* | cegcc*)
9916d769e936Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917d769e936Smrg	    # exporting using user supplied symfile
99187322289dSmrg	    func_dll_def_p "$export_symbols" || {
9919d769e936Smrg	      # and it's NOT already a .def file. Must figure out
9920d769e936Smrg	      # which of the given symbols are data symbols and tag
9921d769e936Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9922d769e936Smrg	      # export_symbols gets reassigned inside the "prepare
9923d769e936Smrg	      # the list of exported symbols" if statement, so the
9924d769e936Smrg	      # include_expsyms logic still works.
99257322289dSmrg	      orig_export_symbols=$export_symbols
9926d769e936Smrg	      export_symbols=
9927d769e936Smrg	      always_export_symbols=yes
99287322289dSmrg	    }
9929786a6f21Smrg	  fi
9930d769e936Smrg	  ;;
9931d769e936Smrg	esac
99321d54945dSmrg
9933d769e936Smrg	# Prepare the list of exported symbols
9934d769e936Smrg	if test -z "$export_symbols"; then
99357322289dSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
99367322289dSmrg	    func_verbose "generating symbol list for '$libname.la'"
99377322289dSmrg	    export_symbols=$output_objdir/$libname.exp
9938d769e936Smrg	    $opt_dry_run || $RM $export_symbols
9939d769e936Smrg	    cmds=$export_symbols_cmds
99407322289dSmrg	    save_ifs=$IFS; IFS='~'
9941d769e936Smrg	    for cmd1 in $cmds; do
99427322289dSmrg	      IFS=$save_ifs
9943d769e936Smrg	      # Take the normal branch if the nm_file_list_spec branch
9944d769e936Smrg	      # doesn't work or if tool conversion is not needed.
9945d769e936Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946d769e936Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947d769e936Smrg		  try_normal_branch=yes
9948d769e936Smrg		  eval cmd=\"$cmd1\"
9949d769e936Smrg		  func_len " $cmd"
9950d769e936Smrg		  len=$func_len_result
9951d769e936Smrg		  ;;
9952d769e936Smrg		*)
9953d769e936Smrg		  try_normal_branch=no
9954d769e936Smrg		  ;;
9955d769e936Smrg	      esac
99567322289dSmrg	      if test yes = "$try_normal_branch" \
9957d769e936Smrg		 && { test "$len" -lt "$max_cmd_len" \
9958d769e936Smrg		      || test "$max_cmd_len" -le -1; }
9959d769e936Smrg	      then
9960d769e936Smrg		func_show_eval "$cmd" 'exit $?'
9961d769e936Smrg		skipped_export=false
9962d769e936Smrg	      elif test -n "$nm_file_list_spec"; then
9963d769e936Smrg		func_basename "$output"
9964d769e936Smrg		output_la=$func_basename_result
9965d769e936Smrg		save_libobjs=$libobjs
9966d769e936Smrg		save_output=$output
99677322289dSmrg		output=$output_objdir/$output_la.nm
9968d769e936Smrg		func_to_tool_file "$output"
9969d769e936Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970d769e936Smrg		func_append delfiles " $output"
9971d769e936Smrg		func_verbose "creating $NM input file list: $output"
9972d769e936Smrg		for obj in $save_libobjs; do
9973d769e936Smrg		  func_to_tool_file "$obj"
9974d769e936Smrg		  $ECHO "$func_to_tool_file_result"
9975d769e936Smrg		done > "$output"
9976d769e936Smrg		eval cmd=\"$cmd1\"
9977d769e936Smrg		func_show_eval "$cmd" 'exit $?'
9978d769e936Smrg		output=$save_output
9979d769e936Smrg		libobjs=$save_libobjs
9980d769e936Smrg		skipped_export=false
9981d769e936Smrg	      else
9982d769e936Smrg		# The command line is too long to execute in one step.
9983d769e936Smrg		func_verbose "using reloadable object file for export list..."
9984d769e936Smrg		skipped_export=:
9985d769e936Smrg		# Break out early, otherwise skipped_export may be
9986d769e936Smrg		# set to false by a later but shorter cmd.
9987d769e936Smrg		break
9988d769e936Smrg	      fi
9989d769e936Smrg	    done
99907322289dSmrg	    IFS=$save_ifs
99917322289dSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992d769e936Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993d769e936Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994d769e936Smrg	    fi
9995d769e936Smrg	  fi
9996d769e936Smrg	fi
9997d769e936Smrg
9998d769e936Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99997322289dSmrg	  tmp_export_symbols=$export_symbols
100007322289dSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001d769e936Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002ec713c28Smrg	fi
100031d54945dSmrg
100047322289dSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005d769e936Smrg	  # The given exports_symbols file has to be filtered, so filter it.
100067322289dSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007d769e936Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
100087322289dSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009d769e936Smrg	  # though. Also, the filter scales superlinearly with the number of
10010d769e936Smrg	  # global variables. join(1) would be nice here, but unfortunately
10011d769e936Smrg	  # isn't a blessed tool.
10012d769e936Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013d769e936Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014d769e936Smrg	  export_symbols=$output_objdir/$libname.def
10015d769e936Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016d769e936Smrg	fi
100171d54945dSmrg
10018d769e936Smrg	tmp_deplibs=
10019d769e936Smrg	for test_deplib in $deplibs; do
10020d769e936Smrg	  case " $convenience " in
10021d769e936Smrg	  *" $test_deplib "*) ;;
10022d769e936Smrg	  *)
10023d769e936Smrg	    func_append tmp_deplibs " $test_deplib"
10024d769e936Smrg	    ;;
10025d769e936Smrg	  esac
10026d769e936Smrg	done
100277322289dSmrg	deplibs=$tmp_deplibs
10028ec713c28Smrg
10029d769e936Smrg	if test -n "$convenience"; then
10030d769e936Smrg	  if test -n "$whole_archive_flag_spec" &&
100317322289dSmrg	    test yes = "$compiler_needs_object" &&
10032d769e936Smrg	    test -z "$libobjs"; then
10033d769e936Smrg	    # extract the archives, so we have objects to list.
10034d769e936Smrg	    # TODO: could optimize this to just extract one archive.
10035d769e936Smrg	    whole_archive_flag_spec=
10036d769e936Smrg	  fi
10037d769e936Smrg	  if test -n "$whole_archive_flag_spec"; then
10038d769e936Smrg	    save_libobjs=$libobjs
10039d769e936Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040d769e936Smrg	    test "X$libobjs" = "X " && libobjs=
10041786a6f21Smrg	  else
100427322289dSmrg	    gentop=$output_objdir/${outputname}x
10043d769e936Smrg	    func_append generated " $gentop"
10044d769e936Smrg
10045d769e936Smrg	    func_extract_archives $gentop $convenience
10046d769e936Smrg	    func_append libobjs " $func_extract_archives_result"
10047d769e936Smrg	    test "X$libobjs" = "X " && libobjs=
10048786a6f21Smrg	  fi
10049786a6f21Smrg	fi
100501d54945dSmrg
100517322289dSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052d769e936Smrg	  eval flag=\"$thread_safe_flag_spec\"
10053d769e936Smrg	  func_append linker_flags " $flag"
10054d769e936Smrg	fi
100551d54945dSmrg
10056d769e936Smrg	# Make a backup of the uninstalled library when relinking
100577322289dSmrg	if test relink = "$opt_mode"; then
10058d769e936Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059d769e936Smrg	fi
10060786a6f21Smrg
10061d769e936Smrg	# Do each of the archive commands.
100627322289dSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10063d769e936Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064d769e936Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10065d769e936Smrg	    cmds=$module_expsym_cmds
10066d769e936Smrg	  else
10067d769e936Smrg	    eval test_cmds=\"$module_cmds\"
10068d769e936Smrg	    cmds=$module_cmds
10069d769e936Smrg	  fi
10070ec713c28Smrg	else
10071d769e936Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072d769e936Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073d769e936Smrg	    cmds=$archive_expsym_cmds
10074d769e936Smrg	  else
10075d769e936Smrg	    eval test_cmds=\"$archive_cmds\"
10076d769e936Smrg	    cmds=$archive_cmds
10077d769e936Smrg	  fi
10078786a6f21Smrg	fi
100791d54945dSmrg
100807322289dSmrg	if test : != "$skipped_export" &&
10081d769e936Smrg	   func_len " $test_cmds" &&
10082d769e936Smrg	   len=$func_len_result &&
10083d769e936Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084d769e936Smrg	  :
10085d769e936Smrg	else
10086d769e936Smrg	  # The command line is too long to link in one step, link piecewise
10087d769e936Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088d769e936Smrg	  # script.
100891d54945dSmrg
10090d769e936Smrg	  # Save the value of $output and $libobjs because we want to
10091d769e936Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10092d769e936Smrg	  # want to use save_libobjs as it was before
10093d769e936Smrg	  # whole_archive_flag_spec was expanded, because we can't
10094d769e936Smrg	  # assume the linker understands whole_archive_flag_spec.
10095d769e936Smrg	  # This may have to be revisited, in case too many
10096d769e936Smrg	  # convenience libraries get linked in and end up exceeding
10097d769e936Smrg	  # the spec.
10098d769e936Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099d769e936Smrg	    save_libobjs=$libobjs
10100d769e936Smrg	  fi
10101d769e936Smrg	  save_output=$output
10102d769e936Smrg	  func_basename "$output"
10103d769e936Smrg	  output_la=$func_basename_result
10104d769e936Smrg
10105d769e936Smrg	  # Clear the reloadable object creation command queue and
10106d769e936Smrg	  # initialize k to one.
10107d769e936Smrg	  test_cmds=
10108d769e936Smrg	  concat_cmds=
10109d769e936Smrg	  objlist=
10110d769e936Smrg	  last_robj=
10111d769e936Smrg	  k=1
10112d769e936Smrg
101137322289dSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
101147322289dSmrg	    output=$output_objdir/$output_la.lnkscript
10115d769e936Smrg	    func_verbose "creating GNU ld script: $output"
10116d769e936Smrg	    echo 'INPUT (' > $output
10117d769e936Smrg	    for obj in $save_libobjs
10118d769e936Smrg	    do
10119d769e936Smrg	      func_to_tool_file "$obj"
10120d769e936Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10121d769e936Smrg	    done
10122d769e936Smrg	    echo ')' >> $output
10123d769e936Smrg	    func_append delfiles " $output"
10124d769e936Smrg	    func_to_tool_file "$output"
10125d769e936Smrg	    output=$func_to_tool_file_result
101267322289dSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
101277322289dSmrg	    output=$output_objdir/$output_la.lnk
10128d769e936Smrg	    func_verbose "creating linker input file list: $output"
10129d769e936Smrg	    : > $output
10130d769e936Smrg	    set x $save_libobjs
10131d769e936Smrg	    shift
10132d769e936Smrg	    firstobj=
101337322289dSmrg	    if test yes = "$compiler_needs_object"; then
10134d769e936Smrg	      firstobj="$1 "
10135d769e936Smrg	      shift
10136ec713c28Smrg	    fi
10137d769e936Smrg	    for obj
10138d769e936Smrg	    do
10139d769e936Smrg	      func_to_tool_file "$obj"
10140d769e936Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10141ec713c28Smrg	    done
10142d769e936Smrg	    func_append delfiles " $output"
10143d769e936Smrg	    func_to_tool_file "$output"
10144d769e936Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145d769e936Smrg	  else
10146d769e936Smrg	    if test -n "$save_libobjs"; then
10147d769e936Smrg	      func_verbose "creating reloadable object files..."
101487322289dSmrg	      output=$output_objdir/$output_la-$k.$objext
10149d769e936Smrg	      eval test_cmds=\"$reload_cmds\"
10150d769e936Smrg	      func_len " $test_cmds"
10151d769e936Smrg	      len0=$func_len_result
10152d769e936Smrg	      len=$len0
10153d769e936Smrg
10154d769e936Smrg	      # Loop over the list of objects to be linked.
10155d769e936Smrg	      for obj in $save_libobjs
10156d769e936Smrg	      do
10157d769e936Smrg		func_len " $obj"
10158d769e936Smrg		func_arith $len + $func_len_result
10159d769e936Smrg		len=$func_arith_result
101607322289dSmrg		if test -z "$objlist" ||
10161d769e936Smrg		   test "$len" -lt "$max_cmd_len"; then
10162d769e936Smrg		  func_append objlist " $obj"
10163d769e936Smrg		else
10164d769e936Smrg		  # The command $test_cmds is almost too long, add a
10165d769e936Smrg		  # command to the queue.
101667322289dSmrg		  if test 1 -eq "$k"; then
10167d769e936Smrg		    # The first file doesn't have a previous command to add.
10168d769e936Smrg		    reload_objs=$objlist
10169d769e936Smrg		    eval concat_cmds=\"$reload_cmds\"
10170d769e936Smrg		  else
10171d769e936Smrg		    # All subsequent reloadable object files will link in
10172d769e936Smrg		    # the last one created.
10173d769e936Smrg		    reload_objs="$objlist $last_robj"
10174d769e936Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175d769e936Smrg		  fi
101767322289dSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177d769e936Smrg		  func_arith $k + 1
10178d769e936Smrg		  k=$func_arith_result
101797322289dSmrg		  output=$output_objdir/$output_la-$k.$objext
10180d769e936Smrg		  objlist=" $obj"
10181d769e936Smrg		  func_len " $last_robj"
10182d769e936Smrg		  func_arith $len0 + $func_len_result
10183d769e936Smrg		  len=$func_arith_result
10184d769e936Smrg		fi
10185d769e936Smrg	      done
10186d769e936Smrg	      # Handle the remaining objects by creating one last
10187d769e936Smrg	      # reloadable object file.  All subsequent reloadable object
10188d769e936Smrg	      # files will link in the last one created.
10189d769e936Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190d769e936Smrg	      reload_objs="$objlist $last_robj"
101917322289dSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192d769e936Smrg	      if test -n "$last_robj"; then
101937322289dSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194ec713c28Smrg	      fi
10195d769e936Smrg	      func_append delfiles " $output"
10196d769e936Smrg
10197d769e936Smrg	    else
10198d769e936Smrg	      output=
10199d769e936Smrg	    fi
10200d769e936Smrg
102017322289dSmrg	    ${skipped_export-false} && {
102027322289dSmrg	      func_verbose "generating symbol list for '$libname.la'"
102037322289dSmrg	      export_symbols=$output_objdir/$libname.exp
10204d769e936Smrg	      $opt_dry_run || $RM $export_symbols
10205d769e936Smrg	      libobjs=$output
10206d769e936Smrg	      # Append the command to create the export file.
10207d769e936Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208d769e936Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209d769e936Smrg	      if test -n "$last_robj"; then
10210d769e936Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211ec713c28Smrg	      fi
102127322289dSmrg	    }
10213d769e936Smrg
10214d769e936Smrg	    test -n "$save_libobjs" &&
10215d769e936Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216d769e936Smrg
10217d769e936Smrg	    # Loop through the commands generated above and execute them.
102187322289dSmrg	    save_ifs=$IFS; IFS='~'
10219d769e936Smrg	    for cmd in $concat_cmds; do
102207322289dSmrg	      IFS=$save_ifs
102217322289dSmrg	      $opt_quiet || {
1022222663e35Smrg		  func_quote_arg expand,pretty "$cmd"
1022322663e35Smrg		  eval "func_echo $func_quote_arg_result"
10224d769e936Smrg	      }
10225d769e936Smrg	      $opt_dry_run || eval "$cmd" || {
10226d769e936Smrg		lt_exit=$?
10227d769e936Smrg
10228d769e936Smrg		# Restore the uninstalled library and exit
102297322289dSmrg		if test relink = "$opt_mode"; then
10230d769e936Smrg		  ( cd "$output_objdir" && \
10231d769e936Smrg		    $RM "${realname}T" && \
10232d769e936Smrg		    $MV "${realname}U" "$realname" )
10233d769e936Smrg		fi
10234d769e936Smrg
10235d769e936Smrg		exit $lt_exit
10236d769e936Smrg	      }
10237ec713c28Smrg	    done
102387322289dSmrg	    IFS=$save_ifs
10239d769e936Smrg
10240d769e936Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241d769e936Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242d769e936Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243d769e936Smrg	    fi
10244d769e936Smrg	  fi
10245d769e936Smrg
102467322289dSmrg          ${skipped_export-false} && {
10247d769e936Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
102487322289dSmrg	      tmp_export_symbols=$export_symbols
102497322289dSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250d769e936Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251d769e936Smrg	    fi
10252d769e936Smrg
10253d769e936Smrg	    if test -n "$orig_export_symbols"; then
10254d769e936Smrg	      # The given exports_symbols file has to be filtered, so filter it.
102557322289dSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256d769e936Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
102577322289dSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258d769e936Smrg	      # though. Also, the filter scales superlinearly with the number of
10259d769e936Smrg	      # global variables. join(1) would be nice here, but unfortunately
10260d769e936Smrg	      # isn't a blessed tool.
10261d769e936Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262d769e936Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263d769e936Smrg	      export_symbols=$output_objdir/$libname.def
10264d769e936Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265d769e936Smrg	    fi
102667322289dSmrg	  }
10267d769e936Smrg
10268d769e936Smrg	  libobjs=$output
10269d769e936Smrg	  # Restore the value of output.
10270d769e936Smrg	  output=$save_output
10271d769e936Smrg
10272d769e936Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273d769e936Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274d769e936Smrg	    test "X$libobjs" = "X " && libobjs=
10275d769e936Smrg	  fi
10276d769e936Smrg	  # Expand the library linking commands again to reset the
10277d769e936Smrg	  # value of $libobjs for piecewise linking.
10278d769e936Smrg
10279d769e936Smrg	  # Do each of the archive commands.
102807322289dSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281d769e936Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282d769e936Smrg	      cmds=$module_expsym_cmds
10283d769e936Smrg	    else
10284d769e936Smrg	      cmds=$module_cmds
10285d769e936Smrg	    fi
10286ec713c28Smrg	  else
10287d769e936Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288d769e936Smrg	      cmds=$archive_expsym_cmds
10289d769e936Smrg	    else
10290d769e936Smrg	      cmds=$archive_cmds
10291d769e936Smrg	    fi
10292ec713c28Smrg	  fi
10293d769e936Smrg	fi
102941d54945dSmrg
10295d769e936Smrg	if test -n "$delfiles"; then
10296d769e936Smrg	  # Append the command to remove temporary files to $cmds.
10297d769e936Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298d769e936Smrg	fi
102991d54945dSmrg
10300d769e936Smrg	# Add any objects from preloaded convenience libraries
10301d769e936Smrg	if test -n "$dlprefiles"; then
103027322289dSmrg	  gentop=$output_objdir/${outputname}x
10303d769e936Smrg	  func_append generated " $gentop"
103041d54945dSmrg
10305d769e936Smrg	  func_extract_archives $gentop $dlprefiles
10306d769e936Smrg	  func_append libobjs " $func_extract_archives_result"
10307d769e936Smrg	  test "X$libobjs" = "X " && libobjs=
10308d769e936Smrg	fi
103091d54945dSmrg
103107322289dSmrg	save_ifs=$IFS; IFS='~'
10311d769e936Smrg	for cmd in $cmds; do
103127322289dSmrg	  IFS=$sp$nl
10313d769e936Smrg	  eval cmd=\"$cmd\"
103147322289dSmrg	  IFS=$save_ifs
103157322289dSmrg	  $opt_quiet || {
1031622663e35Smrg	    func_quote_arg expand,pretty "$cmd"
1031722663e35Smrg	    eval "func_echo $func_quote_arg_result"
10318d769e936Smrg	  }
10319d769e936Smrg	  $opt_dry_run || eval "$cmd" || {
10320d769e936Smrg	    lt_exit=$?
10321786a6f21Smrg
10322d769e936Smrg	    # Restore the uninstalled library and exit
103237322289dSmrg	    if test relink = "$opt_mode"; then
10324d769e936Smrg	      ( cd "$output_objdir" && \
10325d769e936Smrg	        $RM "${realname}T" && \
10326d769e936Smrg		$MV "${realname}U" "$realname" )
10327d769e936Smrg	    fi
10328786a6f21Smrg
10329d769e936Smrg	    exit $lt_exit
10330d769e936Smrg	  }
10331d769e936Smrg	done
103327322289dSmrg	IFS=$save_ifs
10333786a6f21Smrg
10334d769e936Smrg	# Restore the uninstalled library and exit
103357322289dSmrg	if test relink = "$opt_mode"; then
10336d769e936Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337786a6f21Smrg
10338d769e936Smrg	  if test -n "$convenience"; then
10339d769e936Smrg	    if test -z "$whole_archive_flag_spec"; then
10340d769e936Smrg	      func_show_eval '${RM}r "$gentop"'
10341d769e936Smrg	    fi
10342d769e936Smrg	  fi
10343786a6f21Smrg
10344d769e936Smrg	  exit $EXIT_SUCCESS
10345d769e936Smrg	fi
10346d769e936Smrg
10347d769e936Smrg	# Create links to the real library.
10348d769e936Smrg	for linkname in $linknames; do
10349d769e936Smrg	  if test "$realname" != "$linkname"; then
10350d769e936Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351ec713c28Smrg	  fi
10352ec713c28Smrg	done
10353786a6f21Smrg
10354d769e936Smrg	# If -module or -export-dynamic was specified, set the dlname.
103557322289dSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356d769e936Smrg	  # On all known operating systems, these are identical.
103577322289dSmrg	  dlname=$soname
10358d769e936Smrg	fi
10359d769e936Smrg      fi
103601d54945dSmrg      ;;
103611d54945dSmrg
10362d769e936Smrg    obj)
103637322289dSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
103647322289dSmrg	func_warning "'-dlopen' is ignored for objects"
10365d769e936Smrg      fi
10366ec713c28Smrg
10367d769e936Smrg      case " $deplibs" in
10368d769e936Smrg      *\ -l* | *\ -L*)
103697322289dSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370786a6f21Smrg      esac
103711d54945dSmrg
10372d769e936Smrg      test -n "$rpath" && \
103737322289dSmrg	func_warning "'-rpath' is ignored for objects"
103741d54945dSmrg
10375d769e936Smrg      test -n "$xrpath" && \
103767322289dSmrg	func_warning "'-R' is ignored for objects"
10377786a6f21Smrg
10378d769e936Smrg      test -n "$vinfo" && \
103797322289dSmrg	func_warning "'-version-info' is ignored for objects"
10380d769e936Smrg
10381d769e936Smrg      test -n "$release" && \
103827322289dSmrg	func_warning "'-release' is ignored for objects"
10383d769e936Smrg
10384d769e936Smrg      case $output in
10385d769e936Smrg      *.lo)
10386d769e936Smrg	test -n "$objs$old_deplibs" && \
103877322289dSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388d769e936Smrg
10389d769e936Smrg	libobj=$output
10390d769e936Smrg	func_lo2o "$libobj"
10391d769e936Smrg	obj=$func_lo2o_result
10392ec713c28Smrg	;;
10393ec713c28Smrg      *)
10394d769e936Smrg	libobj=
103957322289dSmrg	obj=$output
103961d54945dSmrg	;;
10397786a6f21Smrg      esac
103981d54945dSmrg
10399d769e936Smrg      # Delete the old objects.
10400d769e936Smrg      $opt_dry_run || $RM $obj $libobj
104011d54945dSmrg
10402d769e936Smrg      # Objects from convenience libraries.  This assumes
10403d769e936Smrg      # single-version convenience libraries.  Whenever we create
10404d769e936Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405d769e936Smrg      # the extraction.
10406d769e936Smrg      reload_conv_objs=
10407d769e936Smrg      gentop=
104087322289dSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
104097322289dSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
104107322289dSmrg      # into space.
104117322289dSmrg      case $reload_cmds in
104127322289dSmrg        *\$LD[\ \$]*) wl= ;;
104137322289dSmrg      esac
10414d769e936Smrg      if test -n "$convenience"; then
10415d769e936Smrg	if test -n "$whole_archive_flag_spec"; then
10416d769e936Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
104177322289dSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
104187322289dSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419d769e936Smrg	else
104207322289dSmrg	  gentop=$output_objdir/${obj}x
10421d769e936Smrg	  func_append generated " $gentop"
10422ec713c28Smrg
10423d769e936Smrg	  func_extract_archives $gentop $convenience
10424d769e936Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425d769e936Smrg	fi
10426ec713c28Smrg      fi
10427ec713c28Smrg
10428d769e936Smrg      # If we're not building shared, we need to use non_pic_objs
104297322289dSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430ec713c28Smrg
10431d769e936Smrg      # Create the old-style object.
104327322289dSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433ec713c28Smrg
104347322289dSmrg      output=$obj
10435d769e936Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436d769e936Smrg
10437d769e936Smrg      # Exit if we aren't doing a library object file.
10438d769e936Smrg      if test -z "$libobj"; then
10439d769e936Smrg	if test -n "$gentop"; then
10440d769e936Smrg	  func_show_eval '${RM}r "$gentop"'
10441d769e936Smrg	fi
10442d769e936Smrg
10443d769e936Smrg	exit $EXIT_SUCCESS
10444ec713c28Smrg      fi
10445d769e936Smrg
104467322289dSmrg      test yes = "$build_libtool_libs" || {
10447d769e936Smrg	if test -n "$gentop"; then
10448d769e936Smrg	  func_show_eval '${RM}r "$gentop"'
10449d769e936Smrg	fi
10450d769e936Smrg
10451d769e936Smrg	# Create an invalid libtool object if no PIC, so that we don't
10452d769e936Smrg	# accidentally link it into a program.
10453d769e936Smrg	# $show "echo timestamp > $libobj"
10454d769e936Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455d769e936Smrg	exit $EXIT_SUCCESS
104567322289dSmrg      }
10457d769e936Smrg
104587322289dSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459d769e936Smrg	# Only do commands if we really have different PIC objects.
10460d769e936Smrg	reload_objs="$libobjs $reload_conv_objs"
104617322289dSmrg	output=$libobj
10462d769e936Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463d769e936Smrg      fi
10464d769e936Smrg
10465d769e936Smrg      if test -n "$gentop"; then
10466d769e936Smrg	func_show_eval '${RM}r "$gentop"'
10467d769e936Smrg      fi
10468d769e936Smrg
10469d769e936Smrg      exit $EXIT_SUCCESS
10470ec713c28Smrg      ;;
104711d54945dSmrg
10472d769e936Smrg    prog)
10473d769e936Smrg      case $host in
10474d769e936Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10475d769e936Smrg	          output=$func_stripname_result.exe;;
10476d769e936Smrg      esac
10477d769e936Smrg      test -n "$vinfo" && \
104787322289dSmrg	func_warning "'-version-info' is ignored for programs"
104791d54945dSmrg
10480d769e936Smrg      test -n "$release" && \
104817322289dSmrg	func_warning "'-release' is ignored for programs"
104821d54945dSmrg
104837322289dSmrg      $preload \
104847322289dSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
104857322289dSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10486d769e936Smrg
10487d769e936Smrg      case $host in
10488d769e936Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10489d769e936Smrg	# On Rhapsody replace the C library is the System framework
10490d769e936Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491d769e936Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492ec713c28Smrg	;;
10493d769e936Smrg      esac
10494ec713c28Smrg
10495d769e936Smrg      case $host in
10496d769e936Smrg      *-*-darwin*)
10497d769e936Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10498d769e936Smrg	# But is supposedly fixed on 10.4 or later (yay!).
104997322289dSmrg	if test CXX = "$tagname"; then
10500d769e936Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501d769e936Smrg	    10.[0123])
105027322289dSmrg	      func_append compile_command " $wl-bind_at_load"
105037322289dSmrg	      func_append finalize_command " $wl-bind_at_load"
10504d769e936Smrg	    ;;
10505d769e936Smrg	  esac
10506ec713c28Smrg	fi
10507d769e936Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508d769e936Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509d769e936Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10510d769e936Smrg	;;
10511d769e936Smrg      esac
10512ec713c28Smrg
10513ec713c28Smrg
10514d769e936Smrg      # move library search paths that coincide with paths to not yet
10515d769e936Smrg      # installed libraries to the beginning of the library search list
10516d769e936Smrg      new_libs=
10517d769e936Smrg      for path in $notinst_path; do
10518d769e936Smrg	case " $new_libs " in
10519d769e936Smrg	*" -L$path/$objdir "*) ;;
10520d769e936Smrg	*)
10521d769e936Smrg	  case " $compile_deplibs " in
10522d769e936Smrg	  *" -L$path/$objdir "*)
10523d769e936Smrg	    func_append new_libs " -L$path/$objdir" ;;
10524786a6f21Smrg	  esac
10525d769e936Smrg	  ;;
10526d769e936Smrg	esac
10527d769e936Smrg      done
10528d769e936Smrg      for deplib in $compile_deplibs; do
10529d769e936Smrg	case $deplib in
10530d769e936Smrg	-L*)
10531d769e936Smrg	  case " $new_libs " in
10532d769e936Smrg	  *" $deplib "*) ;;
10533d769e936Smrg	  *) func_append new_libs " $deplib" ;;
10534786a6f21Smrg	  esac
10535d769e936Smrg	  ;;
10536d769e936Smrg	*) func_append new_libs " $deplib" ;;
10537d769e936Smrg	esac
10538d769e936Smrg      done
105397322289dSmrg      compile_deplibs=$new_libs
105401d54945dSmrg
10541ec713c28Smrg
10542d769e936Smrg      func_append compile_command " $compile_deplibs"
10543d769e936Smrg      func_append finalize_command " $finalize_deplibs"
10544ec713c28Smrg
10545d769e936Smrg      if test -n "$rpath$xrpath"; then
10546d769e936Smrg	# If the user specified any rpath flags, then add them.
10547d769e936Smrg	for libdir in $rpath $xrpath; do
10548d769e936Smrg	  # This is the magic to use -rpath.
10549d769e936Smrg	  case "$finalize_rpath " in
10550d769e936Smrg	  *" $libdir "*) ;;
10551d769e936Smrg	  *) func_append finalize_rpath " $libdir" ;;
10552d769e936Smrg	  esac
10553d769e936Smrg	done
10554d769e936Smrg      fi
10555ec713c28Smrg
10556d769e936Smrg      # Now hardcode the library paths
10557d769e936Smrg      rpath=
10558d769e936Smrg      hardcode_libdirs=
10559d769e936Smrg      for libdir in $compile_rpath $finalize_rpath; do
10560d769e936Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10561d769e936Smrg	  if test -n "$hardcode_libdir_separator"; then
10562d769e936Smrg	    if test -z "$hardcode_libdirs"; then
105637322289dSmrg	      hardcode_libdirs=$libdir
10564d769e936Smrg	    else
10565d769e936Smrg	      # Just accumulate the unique libdirs.
10566d769e936Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567d769e936Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568d769e936Smrg		;;
10569d769e936Smrg	      *)
10570d769e936Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571d769e936Smrg		;;
10572d769e936Smrg	      esac
10573d769e936Smrg	    fi
10574ec713c28Smrg	  else
10575d769e936Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576d769e936Smrg	    func_append rpath " $flag"
10577ec713c28Smrg	  fi
10578d769e936Smrg	elif test -n "$runpath_var"; then
10579d769e936Smrg	  case "$perm_rpath " in
10580d769e936Smrg	  *" $libdir "*) ;;
10581d769e936Smrg	  *) func_append perm_rpath " $libdir" ;;
10582d769e936Smrg	  esac
10583d769e936Smrg	fi
10584d769e936Smrg	case $host in
10585d769e936Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
105867322289dSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587d769e936Smrg	  case :$dllsearchpath: in
10588d769e936Smrg	  *":$libdir:"*) ;;
10589d769e936Smrg	  ::) dllsearchpath=$libdir;;
10590d769e936Smrg	  *) func_append dllsearchpath ":$libdir";;
10591d769e936Smrg	  esac
10592d769e936Smrg	  case :$dllsearchpath: in
10593d769e936Smrg	  *":$testbindir:"*) ;;
10594d769e936Smrg	  ::) dllsearchpath=$testbindir;;
10595d769e936Smrg	  *) func_append dllsearchpath ":$testbindir";;
10596d769e936Smrg	  esac
10597d769e936Smrg	  ;;
10598d769e936Smrg	esac
10599d769e936Smrg      done
10600d769e936Smrg      # Substitute the hardcoded libdirs into the rpath.
10601d769e936Smrg      if test -n "$hardcode_libdir_separator" &&
10602d769e936Smrg	 test -n "$hardcode_libdirs"; then
106037322289dSmrg	libdir=$hardcode_libdirs
10604d769e936Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605d769e936Smrg      fi
106067322289dSmrg      compile_rpath=$rpath
10607ec713c28Smrg
10608d769e936Smrg      rpath=
10609d769e936Smrg      hardcode_libdirs=
10610d769e936Smrg      for libdir in $finalize_rpath; do
10611d769e936Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10612d769e936Smrg	  if test -n "$hardcode_libdir_separator"; then
10613d769e936Smrg	    if test -z "$hardcode_libdirs"; then
106147322289dSmrg	      hardcode_libdirs=$libdir
10615d769e936Smrg	    else
10616d769e936Smrg	      # Just accumulate the unique libdirs.
10617d769e936Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618d769e936Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619d769e936Smrg		;;
10620d769e936Smrg	      *)
10621d769e936Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622d769e936Smrg		;;
10623d769e936Smrg	      esac
10624d769e936Smrg	    fi
106251d54945dSmrg	  else
10626d769e936Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627d769e936Smrg	    func_append rpath " $flag"
106281d54945dSmrg	  fi
10629d769e936Smrg	elif test -n "$runpath_var"; then
10630d769e936Smrg	  case "$finalize_perm_rpath " in
10631d769e936Smrg	  *" $libdir "*) ;;
10632d769e936Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10633d769e936Smrg	  esac
106341d54945dSmrg	fi
10635d769e936Smrg      done
10636d769e936Smrg      # Substitute the hardcoded libdirs into the rpath.
10637d769e936Smrg      if test -n "$hardcode_libdir_separator" &&
10638d769e936Smrg	 test -n "$hardcode_libdirs"; then
106397322289dSmrg	libdir=$hardcode_libdirs
10640d769e936Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641d769e936Smrg      fi
106427322289dSmrg      finalize_rpath=$rpath
106431d54945dSmrg
106447322289dSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645d769e936Smrg	# Transform all the library objects into standard objects.
10646d769e936Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647d769e936Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648d769e936Smrg      fi
106491d54945dSmrg
106507322289dSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
106511d54945dSmrg
10652d769e936Smrg      # template prelinking step
10653d769e936Smrg      if test -n "$prelink_cmds"; then
10654d769e936Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655d769e936Smrg      fi
106561d54945dSmrg
106577322289dSmrg      wrappers_required=:
10658d769e936Smrg      case $host in
10659d769e936Smrg      *cegcc* | *mingw32ce*)
10660d769e936Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
106617322289dSmrg        wrappers_required=false
10662d769e936Smrg        ;;
10663d769e936Smrg      *cygwin* | *mingw* )
106647322289dSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665d769e936Smrg        ;;
10666d769e936Smrg      *)
106677322289dSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
106687322289dSmrg          wrappers_required=false
10669d769e936Smrg        fi
10670d769e936Smrg        ;;
10671d769e936Smrg      esac
106727322289dSmrg      $wrappers_required || {
10673d769e936Smrg	# Replace the output file specification.
10674d769e936Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
106757322289dSmrg	link_command=$compile_command$compile_rpath
106761d54945dSmrg
10677d769e936Smrg	# We have no uninstalled library dependencies, so finalize right now.
10678d769e936Smrg	exit_status=0
10679d769e936Smrg	func_show_eval "$link_command" 'exit_status=$?'
106801d54945dSmrg
10681d769e936Smrg	if test -n "$postlink_cmds"; then
10682d769e936Smrg	  func_to_tool_file "$output"
10683d769e936Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684d769e936Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
106851d54945dSmrg	fi
106861d54945dSmrg
10687d769e936Smrg	# Delete the generated files.
106887322289dSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
106897322289dSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690d769e936Smrg	fi
106911d54945dSmrg
10692d769e936Smrg	exit $exit_status
106937322289dSmrg      }
106941d54945dSmrg
10695d769e936Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696d769e936Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697d769e936Smrg      fi
10698d769e936Smrg      if test -n "$finalize_shlibpath"; then
10699d769e936Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700d769e936Smrg      fi
10701ec713c28Smrg
10702d769e936Smrg      compile_var=
10703d769e936Smrg      finalize_var=
10704d769e936Smrg      if test -n "$runpath_var"; then
10705d769e936Smrg	if test -n "$perm_rpath"; then
10706d769e936Smrg	  # We should set the runpath_var.
10707d769e936Smrg	  rpath=
10708d769e936Smrg	  for dir in $perm_rpath; do
10709d769e936Smrg	    func_append rpath "$dir:"
10710d769e936Smrg	  done
10711d769e936Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
107121d54945dSmrg	fi
10713d769e936Smrg	if test -n "$finalize_perm_rpath"; then
10714d769e936Smrg	  # We should set the runpath_var.
10715d769e936Smrg	  rpath=
10716d769e936Smrg	  for dir in $finalize_perm_rpath; do
10717d769e936Smrg	    func_append rpath "$dir:"
10718d769e936Smrg	  done
10719d769e936Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
107201d54945dSmrg	fi
10721d769e936Smrg      fi
107221d54945dSmrg
107237322289dSmrg      if test yes = "$no_install"; then
10724d769e936Smrg	# We don't need to create a wrapper script.
107257322289dSmrg	link_command=$compile_var$compile_command$compile_rpath
10726d769e936Smrg	# Replace the output file specification.
10727d769e936Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728d769e936Smrg	# Delete the old output file.
10729d769e936Smrg	$opt_dry_run || $RM $output
10730d769e936Smrg	# Link the executable and exit
10731d769e936Smrg	func_show_eval "$link_command" 'exit $?'
107321d54945dSmrg
10733d769e936Smrg	if test -n "$postlink_cmds"; then
10734d769e936Smrg	  func_to_tool_file "$output"
10735d769e936Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736d769e936Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737ec713c28Smrg	fi
10738d769e936Smrg
10739ec713c28Smrg	exit $EXIT_SUCCESS
10740d769e936Smrg      fi
10741786a6f21Smrg
107427322289dSmrg      case $hardcode_action,$fast_install in
107437322289dSmrg        relink,*)
107447322289dSmrg	  # Fast installation is not supported
107457322289dSmrg	  link_command=$compile_var$compile_command$compile_rpath
107467322289dSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10747d769e936Smrg
107487322289dSmrg	  func_warning "this platform does not like uninstalled shared libraries"
107497322289dSmrg	  func_warning "'$output' will be relinked during installation"
107507322289dSmrg	  ;;
107517322289dSmrg        *,yes)
107527322289dSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107537322289dSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
107547322289dSmrg          ;;
107557322289dSmrg	*,no)
107567322289dSmrg	  link_command=$compile_var$compile_command$compile_rpath
107577322289dSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107587322289dSmrg          ;;
107597322289dSmrg	*,needless)
107607322289dSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107617322289dSmrg	  relink_command=
107627322289dSmrg          ;;
107637322289dSmrg      esac
107641d54945dSmrg
10765d769e936Smrg      # Replace the output file specification.
10766d769e936Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
107671d54945dSmrg
10768d769e936Smrg      # Delete the old output files.
10769d769e936Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
107701d54945dSmrg
10771d769e936Smrg      func_show_eval "$link_command" 'exit $?'
107721d54945dSmrg
10773d769e936Smrg      if test -n "$postlink_cmds"; then
10774d769e936Smrg	func_to_tool_file "$output_objdir/$outputname"
10775d769e936Smrg	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'`
10776d769e936Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777d769e936Smrg      fi
10778ec713c28Smrg
10779d769e936Smrg      # Now create the wrapper script.
10780d769e936Smrg      func_verbose "creating $output"
10781ec713c28Smrg
10782d769e936Smrg      # Quote the relink command for shipping.
10783d769e936Smrg      if test -n "$relink_command"; then
10784d769e936Smrg	# Preserve any variables that may affect compiler behavior
10785d769e936Smrg	for var in $variables_saved_for_relink; do
10786d769e936Smrg	  if eval test -z \"\${$var+set}\"; then
10787d769e936Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788d769e936Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789d769e936Smrg	    relink_command="$var=; export $var; $relink_command"
107901d54945dSmrg	  else
1079122663e35Smrg	    func_quote_arg pretty "$var_value"
1079222663e35Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
107931d54945dSmrg	  fi
10794d769e936Smrg	done
1079522663e35Smrg	func_quote eval cd "`pwd`"
1079622663e35Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
1079722663e35Smrg	relink_command=$func_quote_arg_unquoted_result
10798d769e936Smrg      fi
10799d769e936Smrg
10800d769e936Smrg      # Only actually do things if not in dry run mode.
10801d769e936Smrg      $opt_dry_run || {
10802d769e936Smrg	# win32 will think the script is a binary if it has
10803d769e936Smrg	# a .exe suffix, so we strip it off here.
10804d769e936Smrg	case $output in
10805d769e936Smrg	  *.exe) func_stripname '' '.exe' "$output"
10806d769e936Smrg	         output=$func_stripname_result ;;
10807786a6f21Smrg	esac
10808d769e936Smrg	# test for cygwin because mv fails w/o .exe extensions
10809d769e936Smrg	case $host in
10810d769e936Smrg	  *cygwin*)
10811d769e936Smrg	    exeext=.exe
10812d769e936Smrg	    func_stripname '' '.exe' "$outputname"
10813d769e936Smrg	    outputname=$func_stripname_result ;;
10814d769e936Smrg	  *) exeext= ;;
10815d769e936Smrg	esac
10816d769e936Smrg	case $host in
10817d769e936Smrg	  *cygwin* | *mingw* )
10818d769e936Smrg	    func_dirname_and_basename "$output" "" "."
10819d769e936Smrg	    output_name=$func_basename_result
10820d769e936Smrg	    output_path=$func_dirname_result
108217322289dSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
108227322289dSmrg	    cwrapper=$output_path/$output_name.exe
10823d769e936Smrg	    $RM $cwrappersource $cwrapper
10824d769e936Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825d769e936Smrg
10826d769e936Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10827d769e936Smrg
10828d769e936Smrg	    # The wrapper executable is built using the $host compiler,
10829d769e936Smrg	    # because it contains $host paths and files. If cross-
10830d769e936Smrg	    # compiling, it, like the target executable, must be
10831d769e936Smrg	    # executed on the $host or under an emulation environment.
10832d769e936Smrg	    $opt_dry_run || {
10833d769e936Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834d769e936Smrg	      $STRIP $cwrapper
10835d769e936Smrg	    }
108361d54945dSmrg
10837d769e936Smrg	    # Now, create the wrapper script for func_source use:
10838d769e936Smrg	    func_ltwrapper_scriptname $cwrapper
10839d769e936Smrg	    $RM $func_ltwrapper_scriptname_result
10840d769e936Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841d769e936Smrg	    $opt_dry_run || {
10842d769e936Smrg	      # note: this script will not be executed, so do not chmod.
108437322289dSmrg	      if test "x$build" = "x$host"; then
10844d769e936Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10845d769e936Smrg	      else
10846d769e936Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10847d769e936Smrg	      fi
10848d769e936Smrg	    }
10849d769e936Smrg	  ;;
10850d769e936Smrg	  * )
10851d769e936Smrg	    $RM $output
10852d769e936Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
108531d54945dSmrg
10854d769e936Smrg	    func_emit_wrapper no > $output
10855d769e936Smrg	    chmod +x $output
10856d769e936Smrg	  ;;
10857d769e936Smrg	esac
10858d769e936Smrg      }
10859d769e936Smrg      exit $EXIT_SUCCESS
10860d769e936Smrg      ;;
10861d769e936Smrg    esac
108621d54945dSmrg
10863d769e936Smrg    # See if we need to build an old-fashioned archive.
10864d769e936Smrg    for oldlib in $oldlibs; do
108651d54945dSmrg
108667322289dSmrg      case $build_libtool_libs in
108677322289dSmrg        convenience)
108687322289dSmrg	  oldobjs="$libobjs_save $symfileobj"
108697322289dSmrg	  addlibs=$convenience
10870d769e936Smrg	  build_libtool_libs=no
108717322289dSmrg	  ;;
108727322289dSmrg	module)
108737322289dSmrg	  oldobjs=$libobjs_save
108747322289dSmrg	  addlibs=$old_convenience
108757322289dSmrg	  build_libtool_libs=no
108767322289dSmrg          ;;
108777322289dSmrg	*)
10878d769e936Smrg	  oldobjs="$old_deplibs $non_pic_objects"
108797322289dSmrg	  $preload && test -f "$symfileobj" \
108807322289dSmrg	    && func_append oldobjs " $symfileobj"
108817322289dSmrg	  addlibs=$old_convenience
108827322289dSmrg	  ;;
108837322289dSmrg      esac
108841d54945dSmrg
10885d769e936Smrg      if test -n "$addlibs"; then
108867322289dSmrg	gentop=$output_objdir/${outputname}x
10887d769e936Smrg	func_append generated " $gentop"
108881d54945dSmrg
10889d769e936Smrg	func_extract_archives $gentop $addlibs
10890d769e936Smrg	func_append oldobjs " $func_extract_archives_result"
10891d769e936Smrg      fi
108921d54945dSmrg
10893d769e936Smrg      # Do each command in the archive commands.
108947322289dSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895d769e936Smrg	cmds=$old_archive_from_new_cmds
10896d769e936Smrg      else
108971d54945dSmrg
10898d769e936Smrg	# Add any objects from preloaded convenience libraries
10899d769e936Smrg	if test -n "$dlprefiles"; then
109007322289dSmrg	  gentop=$output_objdir/${outputname}x
10901d769e936Smrg	  func_append generated " $gentop"
109021d54945dSmrg
10903d769e936Smrg	  func_extract_archives $gentop $dlprefiles
10904d769e936Smrg	  func_append oldobjs " $func_extract_archives_result"
10905d769e936Smrg	fi
109061d54945dSmrg
10907d769e936Smrg	# POSIX demands no paths to be encoded in archives.  We have
10908d769e936Smrg	# to avoid creating archives with duplicate basenames if we
10909d769e936Smrg	# might have to extract them afterwards, e.g., when creating a
10910d769e936Smrg	# static archive out of a convenience library, or when linking
10911d769e936Smrg	# the entirety of a libtool archive into another (currently
10912d769e936Smrg	# not supported by libtool).
10913d769e936Smrg	if (for obj in $oldobjs
10914d769e936Smrg	    do
10915d769e936Smrg	      func_basename "$obj"
10916d769e936Smrg	      $ECHO "$func_basename_result"
10917d769e936Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918d769e936Smrg	  :
10919d769e936Smrg	else
10920d769e936Smrg	  echo "copying selected object files to avoid basename conflicts..."
109217322289dSmrg	  gentop=$output_objdir/${outputname}x
10922d769e936Smrg	  func_append generated " $gentop"
10923d769e936Smrg	  func_mkdir_p "$gentop"
10924d769e936Smrg	  save_oldobjs=$oldobjs
10925d769e936Smrg	  oldobjs=
10926d769e936Smrg	  counter=1
10927d769e936Smrg	  for obj in $save_oldobjs
10928d769e936Smrg	  do
10929d769e936Smrg	    func_basename "$obj"
109307322289dSmrg	    objbase=$func_basename_result
10931d769e936Smrg	    case " $oldobjs " in
10932d769e936Smrg	    " ") oldobjs=$obj ;;
10933d769e936Smrg	    *[\ /]"$objbase "*)
10934d769e936Smrg	      while :; do
10935d769e936Smrg		# Make sure we don't pick an alternate name that also
10936d769e936Smrg		# overlaps.
10937d769e936Smrg		newobj=lt$counter-$objbase
10938d769e936Smrg		func_arith $counter + 1
10939d769e936Smrg		counter=$func_arith_result
10940d769e936Smrg		case " $oldobjs " in
10941d769e936Smrg		*[\ /]"$newobj "*) ;;
10942d769e936Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943d769e936Smrg		esac
10944d769e936Smrg	      done
10945d769e936Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946d769e936Smrg	      func_append oldobjs " $gentop/$newobj"
10947d769e936Smrg	      ;;
10948d769e936Smrg	    *) func_append oldobjs " $obj" ;;
10949d769e936Smrg	    esac
109501d54945dSmrg	  done
10951786a6f21Smrg	fi
10952d769e936Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953d769e936Smrg	tool_oldlib=$func_to_tool_file_result
10954d769e936Smrg	eval cmds=\"$old_archive_cmds\"
10955ec713c28Smrg
10956d769e936Smrg	func_len " $cmds"
10957d769e936Smrg	len=$func_len_result
10958d769e936Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959d769e936Smrg	  cmds=$old_archive_cmds
10960d769e936Smrg	elif test -n "$archiver_list_spec"; then
10961d769e936Smrg	  func_verbose "using command file archive linking..."
10962d769e936Smrg	  for obj in $oldobjs
10963d769e936Smrg	  do
10964d769e936Smrg	    func_to_tool_file "$obj"
10965d769e936Smrg	    $ECHO "$func_to_tool_file_result"
10966d769e936Smrg	  done > $output_objdir/$libname.libcmd
10967d769e936Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968d769e936Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969d769e936Smrg	  cmds=$old_archive_cmds
10970d769e936Smrg	else
10971d769e936Smrg	  # the command line is too long to link in one step, link in parts
10972d769e936Smrg	  func_verbose "using piecewise archive linking..."
10973d769e936Smrg	  save_RANLIB=$RANLIB
10974d769e936Smrg	  RANLIB=:
10975d769e936Smrg	  objlist=
10976d769e936Smrg	  concat_cmds=
10977d769e936Smrg	  save_oldobjs=$oldobjs
10978d769e936Smrg	  oldobjs=
10979d769e936Smrg	  # Is there a better way of finding the last object in the list?
10980d769e936Smrg	  for obj in $save_oldobjs
10981d769e936Smrg	  do
10982d769e936Smrg	    last_oldobj=$obj
10983d769e936Smrg	  done
10984d769e936Smrg	  eval test_cmds=\"$old_archive_cmds\"
10985d769e936Smrg	  func_len " $test_cmds"
10986d769e936Smrg	  len0=$func_len_result
10987d769e936Smrg	  len=$len0
10988d769e936Smrg	  for obj in $save_oldobjs
10989d769e936Smrg	  do
10990d769e936Smrg	    func_len " $obj"
10991d769e936Smrg	    func_arith $len + $func_len_result
10992d769e936Smrg	    len=$func_arith_result
10993d769e936Smrg	    func_append objlist " $obj"
10994d769e936Smrg	    if test "$len" -lt "$max_cmd_len"; then
10995d769e936Smrg	      :
10996d769e936Smrg	    else
10997d769e936Smrg	      # the above command should be used before it gets too long
10998d769e936Smrg	      oldobjs=$objlist
109997322289dSmrg	      if test "$obj" = "$last_oldobj"; then
11000d769e936Smrg		RANLIB=$save_RANLIB
11001d769e936Smrg	      fi
11002d769e936Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
110037322289dSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004d769e936Smrg	      objlist=
11005d769e936Smrg	      len=$len0
11006d769e936Smrg	    fi
11007d769e936Smrg	  done
11008d769e936Smrg	  RANLIB=$save_RANLIB
11009d769e936Smrg	  oldobjs=$objlist
110107322289dSmrg	  if test -z "$oldobjs"; then
11011d769e936Smrg	    eval cmds=\"\$concat_cmds\"
11012d769e936Smrg	  else
11013d769e936Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014d769e936Smrg	  fi
11015d769e936Smrg	fi
11016d769e936Smrg      fi
11017d769e936Smrg      func_execute_cmds "$cmds" 'exit $?'
110181d54945dSmrg    done
110191d54945dSmrg
11020d769e936Smrg    test -n "$generated" && \
11021d769e936Smrg      func_show_eval "${RM}r$generated"
110221d54945dSmrg
11023d769e936Smrg    # Now create the libtool archive.
11024d769e936Smrg    case $output in
11025d769e936Smrg    *.la)
11026d769e936Smrg      old_library=
110277322289dSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028d769e936Smrg      func_verbose "creating $output"
110291d54945dSmrg
11030d769e936Smrg      # Preserve any variables that may affect compiler behavior
11031d769e936Smrg      for var in $variables_saved_for_relink; do
11032d769e936Smrg	if eval test -z \"\${$var+set}\"; then
11033d769e936Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034d769e936Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035d769e936Smrg	  relink_command="$var=; export $var; $relink_command"
11036ec713c28Smrg	else
1103722663e35Smrg	  func_quote_arg pretty,unquoted "$var_value"
1103822663e35Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039ec713c28Smrg	fi
11040d769e936Smrg      done
11041d769e936Smrg      # Quote the link command for shipping.
1104222663e35Smrg      func_quote eval cd "`pwd`"
1104322663e35Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1104422663e35Smrg      func_quote_arg pretty,unquoted "$relink_command"
1104522663e35Smrg      relink_command=$func_quote_arg_unquoted_result
110467322289dSmrg      if test yes = "$hardcode_automatic"; then
11047d769e936Smrg	relink_command=
11048d769e936Smrg      fi
110491d54945dSmrg
11050d769e936Smrg      # Only create the output if not a dry run.
11051d769e936Smrg      $opt_dry_run || {
11052d769e936Smrg	for installed in no yes; do
110537322289dSmrg	  if test yes = "$installed"; then
11054d769e936Smrg	    if test -z "$install_libdir"; then
11055d769e936Smrg	      break
11056d769e936Smrg	    fi
110577322289dSmrg	    output=$output_objdir/${outputname}i
11058d769e936Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11059d769e936Smrg	    newdependency_libs=
11060d769e936Smrg	    for deplib in $dependency_libs; do
11061d769e936Smrg	      case $deplib in
11062d769e936Smrg	      *.la)
11063d769e936Smrg		func_basename "$deplib"
110647322289dSmrg		name=$func_basename_result
11065d769e936Smrg		func_resolve_sysroot "$deplib"
110667322289dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067d769e936Smrg		test -z "$libdir" && \
110687322289dSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069d769e936Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070d769e936Smrg		;;
11071d769e936Smrg	      -L*)
11072d769e936Smrg		func_stripname -L '' "$deplib"
11073d769e936Smrg		func_replace_sysroot "$func_stripname_result"
11074d769e936Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11075d769e936Smrg		;;
11076d769e936Smrg	      -R*)
11077d769e936Smrg		func_stripname -R '' "$deplib"
11078d769e936Smrg		func_replace_sysroot "$func_stripname_result"
11079d769e936Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080d769e936Smrg		;;
11081d769e936Smrg	      *) func_append newdependency_libs " $deplib" ;;
11082d769e936Smrg	      esac
11083d769e936Smrg	    done
110847322289dSmrg	    dependency_libs=$newdependency_libs
11085d769e936Smrg	    newdlfiles=
11086d769e936Smrg
11087d769e936Smrg	    for lib in $dlfiles; do
11088d769e936Smrg	      case $lib in
11089d769e936Smrg	      *.la)
11090d769e936Smrg	        func_basename "$lib"
110917322289dSmrg		name=$func_basename_result
110927322289dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093d769e936Smrg		test -z "$libdir" && \
110947322289dSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095d769e936Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096d769e936Smrg		;;
11097d769e936Smrg	      *) func_append newdlfiles " $lib" ;;
11098d769e936Smrg	      esac
11099d769e936Smrg	    done
111007322289dSmrg	    dlfiles=$newdlfiles
11101d769e936Smrg	    newdlprefiles=
11102d769e936Smrg	    for lib in $dlprefiles; do
11103d769e936Smrg	      case $lib in
11104d769e936Smrg	      *.la)
11105d769e936Smrg		# Only pass preopened files to the pseudo-archive (for
11106d769e936Smrg		# eventual linking with the app. that links it) if we
11107d769e936Smrg		# didn't already link the preopened objects directly into
11108d769e936Smrg		# the library:
11109d769e936Smrg		func_basename "$lib"
111107322289dSmrg		name=$func_basename_result
111117322289dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112d769e936Smrg		test -z "$libdir" && \
111137322289dSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114d769e936Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115d769e936Smrg		;;
11116d769e936Smrg	      esac
11117d769e936Smrg	    done
111187322289dSmrg	    dlprefiles=$newdlprefiles
11119d769e936Smrg	  else
11120d769e936Smrg	    newdlfiles=
11121d769e936Smrg	    for lib in $dlfiles; do
11122d769e936Smrg	      case $lib in
111237322289dSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124d769e936Smrg		*) abs=`pwd`"/$lib" ;;
11125d769e936Smrg	      esac
11126d769e936Smrg	      func_append newdlfiles " $abs"
11127d769e936Smrg	    done
111287322289dSmrg	    dlfiles=$newdlfiles
11129d769e936Smrg	    newdlprefiles=
11130d769e936Smrg	    for lib in $dlprefiles; do
11131d769e936Smrg	      case $lib in
111327322289dSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133d769e936Smrg		*) abs=`pwd`"/$lib" ;;
11134d769e936Smrg	      esac
11135d769e936Smrg	      func_append newdlprefiles " $abs"
11136d769e936Smrg	    done
111377322289dSmrg	    dlprefiles=$newdlprefiles
11138d769e936Smrg	  fi
11139d769e936Smrg	  $RM $output
11140d769e936Smrg	  # place dlname in correct position for cygwin
11141d769e936Smrg	  # In fact, it would be nice if we could use this code for all target
11142d769e936Smrg	  # systems that can't hard-code library paths into their executables
11143d769e936Smrg	  # and that have no shared library path variable independent of PATH,
11144d769e936Smrg	  # but it turns out we can't easily determine that from inspecting
11145d769e936Smrg	  # libtool variables, so we have to hard-code the OSs to which it
11146d769e936Smrg	  # applies here; at the moment, that means platforms that use the PE
11147d769e936Smrg	  # object format with DLL files.  See the long comment at the top of
11148d769e936Smrg	  # tests/bindir.at for full details.
11149d769e936Smrg	  tdlname=$dlname
11150d769e936Smrg	  case $host,$output,$installed,$module,$dlname in
11151d769e936Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152d769e936Smrg	      # If a -bindir argument was supplied, place the dll there.
111537322289dSmrg	      if test -n "$bindir"; then
11154d769e936Smrg		func_relative_path "$install_libdir" "$bindir"
111557322289dSmrg		tdlname=$func_relative_path_result/$dlname
11156d769e936Smrg	      else
11157d769e936Smrg		# Otherwise fall back on heuristic.
11158d769e936Smrg		tdlname=../bin/$dlname
11159d769e936Smrg	      fi
11160d769e936Smrg	      ;;
11161d769e936Smrg	  esac
11162d769e936Smrg	  $ECHO > $output "\
11163d769e936Smrg# $outputname - a libtool library file
111647322289dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165d769e936Smrg#
11166d769e936Smrg# Please DO NOT delete this file!
11167d769e936Smrg# It is necessary for linking the library.
111681d54945dSmrg
11169d769e936Smrg# The name that we can dlopen(3).
11170d769e936Smrgdlname='$tdlname'
111711d54945dSmrg
11172d769e936Smrg# Names of this library.
11173d769e936Smrglibrary_names='$library_names'
111741d54945dSmrg
11175d769e936Smrg# The name of the static archive.
11176d769e936Smrgold_library='$old_library'
111771d54945dSmrg
111787322289dSmrg# Linker flags that cannot go in dependency_libs.
11179d769e936Smrginherited_linker_flags='$new_inherited_linker_flags'
111801d54945dSmrg
11181d769e936Smrg# Libraries that this one depends upon.
11182d769e936Smrgdependency_libs='$dependency_libs'
111831d54945dSmrg
11184d769e936Smrg# Names of additional weak libraries provided by this library
11185d769e936Smrgweak_library_names='$weak_libs'
111861d54945dSmrg
11187d769e936Smrg# Version information for $libname.
11188d769e936Smrgcurrent=$current
11189d769e936Smrgage=$age
11190d769e936Smrgrevision=$revision
111911d54945dSmrg
11192d769e936Smrg# Is this an already installed library?
11193d769e936Smrginstalled=$installed
111941d54945dSmrg
11195d769e936Smrg# Should we warn about portability when linking against -modules?
11196d769e936Smrgshouldnotlink=$module
111971d54945dSmrg
11198d769e936Smrg# Files to dlopen/dlpreopen
11199d769e936Smrgdlopen='$dlfiles'
11200d769e936Smrgdlpreopen='$dlprefiles'
112011d54945dSmrg
11202d769e936Smrg# Directory that this library needs to be installed in:
11203d769e936Smrglibdir='$install_libdir'"
112047322289dSmrg	  if test no,yes = "$installed,$need_relink"; then
11205d769e936Smrg	    $ECHO >> $output "\
11206d769e936Smrgrelink_command=\"$relink_command\""
11207d769e936Smrg	  fi
11208d769e936Smrg	done
11209d769e936Smrg      }
11210ba85709eSmrg
11211d769e936Smrg      # Do a symbolic link so that the libtool archive can be found in
11212d769e936Smrg      # LD_LIBRARY_PATH before the program is installed.
11213d769e936Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214d769e936Smrg      ;;
11215d769e936Smrg    esac
11216d769e936Smrg    exit $EXIT_SUCCESS
11217d769e936Smrg}
11218ec713c28Smrg
112197322289dSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
112207322289dSmrg  func_mode_link ${1+"$@"}
112217322289dSmrgfi
112221d54945dSmrg
112231d54945dSmrg
11224d769e936Smrg# func_mode_uninstall arg...
11225d769e936Smrgfunc_mode_uninstall ()
11226d769e936Smrg{
112277322289dSmrg    $debug_cmd
112287322289dSmrg
112297322289dSmrg    RM=$nonopt
112301d54945dSmrg    files=
112317322289dSmrg    rmforce=false
112321d54945dSmrg    exit_status=0
112331d54945dSmrg
112341d54945dSmrg    # This variable tells wrapper scripts just to set variables rather
112351d54945dSmrg    # than running their programs.
112367322289dSmrg    libtool_install_magic=$magic
112371d54945dSmrg
112381d54945dSmrg    for arg
112391d54945dSmrg    do
112401d54945dSmrg      case $arg in
112417322289dSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11242d769e936Smrg      -*) func_append RM " $arg" ;;
11243d769e936Smrg      *) func_append files " $arg" ;;
112441d54945dSmrg      esac
112451d54945dSmrg    done
112461d54945dSmrg
11247d769e936Smrg    test -z "$RM" && \
11248d769e936Smrg      func_fatal_help "you must specify an RM program"
112491d54945dSmrg
112501d54945dSmrg    rmdirs=
112511d54945dSmrg
112521d54945dSmrg    for file in $files; do
11253d769e936Smrg      func_dirname "$file" "" "."
112547322289dSmrg      dir=$func_dirname_result
112557322289dSmrg      if test . = "$dir"; then
112567322289dSmrg	odir=$objdir
112571d54945dSmrg      else
112587322289dSmrg	odir=$dir/$objdir
112591d54945dSmrg      fi
11260d769e936Smrg      func_basename "$file"
112617322289dSmrg      name=$func_basename_result
112627322289dSmrg      test uninstall = "$opt_mode" && odir=$dir
112631d54945dSmrg
11264d769e936Smrg      # Remember odir for removal later, being careful to avoid duplicates
112657322289dSmrg      if test clean = "$opt_mode"; then
112661d54945dSmrg	case " $rmdirs " in
11267d769e936Smrg	  *" $odir "*) ;;
11268d769e936Smrg	  *) func_append rmdirs " $odir" ;;
112691d54945dSmrg	esac
112701d54945dSmrg      fi
112711d54945dSmrg
112721d54945dSmrg      # Don't error if the file doesn't exist and rm -f was used.
11273d769e936Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274d769e936Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275d769e936Smrg	 test -f "$file"; then
112761d54945dSmrg	:
112771d54945dSmrg      elif test -d "$file"; then
112781d54945dSmrg	exit_status=1
112791d54945dSmrg	continue
112807322289dSmrg      elif $rmforce; then
112811d54945dSmrg	continue
112821d54945dSmrg      fi
112831d54945dSmrg
112847322289dSmrg      rmfiles=$file
112851d54945dSmrg
112861d54945dSmrg      case $name in
112871d54945dSmrg      *.la)
112881d54945dSmrg	# Possibly a libtool archive, so verify it.
11289d769e936Smrg	if func_lalib_p "$file"; then
11290d769e936Smrg	  func_source $dir/$name
112911d54945dSmrg
112921d54945dSmrg	  # Delete the libtool libraries and symlinks.
112931d54945dSmrg	  for n in $library_names; do
11294d769e936Smrg	    func_append rmfiles " $odir/$n"
112951d54945dSmrg	  done
11296d769e936Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
112971d54945dSmrg
112987322289dSmrg	  case $opt_mode in
112991d54945dSmrg	  clean)
11300d769e936Smrg	    case " $library_names " in
113011d54945dSmrg	    *" $dlname "*) ;;
11302d769e936Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
113031d54945dSmrg	    esac
11304d769e936Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
113051d54945dSmrg	    ;;
113061d54945dSmrg	  uninstall)
113071d54945dSmrg	    if test -n "$library_names"; then
113081d54945dSmrg	      # Do each command in the postuninstall commands.
113097322289dSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113101d54945dSmrg	    fi
113111d54945dSmrg
113121d54945dSmrg	    if test -n "$old_library"; then
113131d54945dSmrg	      # Do each command in the old_postuninstall commands.
113147322289dSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
113151d54945dSmrg	    fi
113161d54945dSmrg	    # FIXME: should reinstall the best remaining shared library.
113171d54945dSmrg	    ;;
113181d54945dSmrg	  esac
113191d54945dSmrg	fi
113201d54945dSmrg	;;
113211d54945dSmrg
113221d54945dSmrg      *.lo)
113231d54945dSmrg	# Possibly a libtool object, so verify it.
11324d769e936Smrg	if func_lalib_p "$file"; then
113251d54945dSmrg
113261d54945dSmrg	  # Read the .lo file
11327d769e936Smrg	  func_source $dir/$name
113281d54945dSmrg
113291d54945dSmrg	  # Add PIC object to the list of files to remove.
113307322289dSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331d769e936Smrg	    func_append rmfiles " $dir/$pic_object"
113321d54945dSmrg	  fi
113331d54945dSmrg
113341d54945dSmrg	  # Add non-PIC object to the list of files to remove.
113357322289dSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336d769e936Smrg	    func_append rmfiles " $dir/$non_pic_object"
113371d54945dSmrg	  fi
113381d54945dSmrg	fi
113391d54945dSmrg	;;
113401d54945dSmrg
113411d54945dSmrg      *)
113427322289dSmrg	if test clean = "$opt_mode"; then
113431d54945dSmrg	  noexename=$name
113441d54945dSmrg	  case $file in
113451d54945dSmrg	  *.exe)
11346d769e936Smrg	    func_stripname '' '.exe' "$file"
11347d769e936Smrg	    file=$func_stripname_result
11348d769e936Smrg	    func_stripname '' '.exe' "$name"
11349d769e936Smrg	    noexename=$func_stripname_result
113501d54945dSmrg	    # $file with .exe has already been added to rmfiles,
113511d54945dSmrg	    # add $file without .exe
11352d769e936Smrg	    func_append rmfiles " $file"
113531d54945dSmrg	    ;;
113541d54945dSmrg	  esac
113551d54945dSmrg	  # Do a test to see if this is a libtool program.
11356d769e936Smrg	  if func_ltwrapper_p "$file"; then
11357d769e936Smrg	    if func_ltwrapper_executable_p "$file"; then
11358d769e936Smrg	      func_ltwrapper_scriptname "$file"
11359d769e936Smrg	      relink_command=
11360d769e936Smrg	      func_source $func_ltwrapper_scriptname_result
11361d769e936Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362d769e936Smrg	    else
11363d769e936Smrg	      relink_command=
11364d769e936Smrg	      func_source $dir/$noexename
11365d769e936Smrg	    fi
113661d54945dSmrg
113671d54945dSmrg	    # note $name still contains .exe if it was in $file originally
113681d54945dSmrg	    # as does the version of $file that was added into $rmfiles
113697322289dSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
113707322289dSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371d769e936Smrg	      func_append rmfiles " $odir/lt-$name"
113721d54945dSmrg	    fi
113737322289dSmrg	    if test "X$noexename" != "X$name"; then
113747322289dSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
113751d54945dSmrg	    fi
113761d54945dSmrg	  fi
113771d54945dSmrg	fi
113781d54945dSmrg	;;
113791d54945dSmrg      esac
11380d769e936Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
113811d54945dSmrg    done
113821d54945dSmrg
113837322289dSmrg    # Try to remove the $objdir's in the directories where we deleted files
113841d54945dSmrg    for dir in $rmdirs; do
113851d54945dSmrg      if test -d "$dir"; then
11386d769e936Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
113871d54945dSmrg      fi
113881d54945dSmrg    done
113891d54945dSmrg
113901d54945dSmrg    exit $exit_status
11391d769e936Smrg}
113921d54945dSmrg
113937322289dSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
113947322289dSmrg  func_mode_uninstall ${1+"$@"}
113957322289dSmrgfi
11396786a6f21Smrg
11397d769e936Smrgtest -z "$opt_mode" && {
113987322289dSmrg  help=$generic_help
11399d769e936Smrg  func_fatal_help "you must specify a MODE"
11400d769e936Smrg}
11401d769e936Smrg
11402d769e936Smrgtest -z "$exec_cmd" && \
114037322289dSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
114041d54945dSmrg
114051d54945dSmrgif test -n "$exec_cmd"; then
11406d769e936Smrg  eval exec "$exec_cmd"
114071d54945dSmrg  exit $EXIT_FAILURE
114081d54945dSmrgfi
114091d54945dSmrg
11410d769e936Smrgexit $exit_status
11411ec713c28Smrg
114121d54945dSmrg
114131d54945dSmrg# The TAGs below are defined such that we never get into a situation
114147322289dSmrg# where we disable both kinds of libraries.  Given conflicting
114151d54945dSmrg# choices, we go for a static library, that is the most portable,
114161d54945dSmrg# since we can't tell whether shared libraries were disabled because
114171d54945dSmrg# the user asked for that or because the platform doesn't support
114181d54945dSmrg# them.  This is particularly important on AIX, because we don't
114191d54945dSmrg# support having both static and shared libraries enabled at the same
114201d54945dSmrg# time on that platform, so we default to a shared-only configuration.
114211d54945dSmrg# If a disable-shared tag is given, we'll fallback to a static-only
114221d54945dSmrg# configuration.  But we'll never go from static-only to shared-only.
114231d54945dSmrg
114241d54945dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425d769e936Smrgbuild_libtool_libs=no
11426d769e936Smrgbuild_old_libs=yes
114271d54945dSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
114281d54945dSmrg
114291d54945dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430d769e936Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
114311d54945dSmrg# ### END LIBTOOL TAG CONFIG: disable-static
114321d54945dSmrg
114331d54945dSmrg# Local Variables:
114341d54945dSmrg# mode:shell-script
114351d54945dSmrg# sh-indentation:2
114361d54945dSmrg# End:
11437