ltmain.sh revision 6fc0178d
16fc0178dSmrg#! /bin/sh
26fc0178dSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
36fc0178dSmrg##               by inline-source v2014-01-03.01
47a3b38f7Smrg
56fc0178dSmrg# libtool (GNU libtool) 2.4.6
66fc0178dSmrg# Provide generalized library-building support services.
77a3b38f7Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
87a3b38f7Smrg
96fc0178dSmrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
107a3b38f7Smrg# This is free software; see the source for copying conditions.  There is NO
117a3b38f7Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
127a3b38f7Smrg
137a3b38f7Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14ff559fabSmrg# it under the terms of the GNU General Public License as published by
15ff559fabSmrg# the Free Software Foundation; either version 2 of the License, or
16ff559fabSmrg# (at your option) any later version.
17ff559fabSmrg#
187a3b38f7Smrg# As a special exception to the GNU General Public License,
197a3b38f7Smrg# if you distribute this file as part of a program or library that
207a3b38f7Smrg# is built using GNU Libtool, you may include this file under the
217a3b38f7Smrg# same distribution terms that you use for the rest of that program.
227a3b38f7Smrg#
237a3b38f7Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24ff559fabSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25ff559fabSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26ff559fabSmrg# General Public License for more details.
27ff559fabSmrg#
28ff559fabSmrg# You should have received a copy of the GNU General Public License
296fc0178dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
307a3b38f7Smrg
317a3b38f7Smrg
3244dda7b2SmrgPROGRAM=libtool
337a3b38f7SmrgPACKAGE=libtool
346fc0178dSmrgVERSION=2.4.6
356fc0178dSmrgpackage_revision=2.4.6
367a3b38f7Smrg
376fc0178dSmrg
386fc0178dSmrg## ------ ##
396fc0178dSmrg## Usage. ##
406fc0178dSmrg## ------ ##
416fc0178dSmrg
426fc0178dSmrg# Run './libtool --help' for help with using this script from the
436fc0178dSmrg# command line.
446fc0178dSmrg
456fc0178dSmrg
466fc0178dSmrg## ------------------------------- ##
476fc0178dSmrg## User overridable command paths. ##
486fc0178dSmrg## ------------------------------- ##
496fc0178dSmrg
506fc0178dSmrg# After configure completes, it has a better idea of some of the
516fc0178dSmrg# shell tools we need than the defaults used by the functions shared
526fc0178dSmrg# with bootstrap, so set those here where they can still be over-
536fc0178dSmrg# ridden by the user, but otherwise take precedence.
546fc0178dSmrg
556fc0178dSmrg: ${AUTOCONF="autoconf"}
566fc0178dSmrg: ${AUTOMAKE="automake"}
576fc0178dSmrg
586fc0178dSmrg
596fc0178dSmrg## -------------------------- ##
606fc0178dSmrg## Source external libraries. ##
616fc0178dSmrg## -------------------------- ##
626fc0178dSmrg
636fc0178dSmrg# Much of our low-level functionality needs to be sourced from external
646fc0178dSmrg# libraries, which are installed to $pkgauxdir.
656fc0178dSmrg
666fc0178dSmrg# Set a version string for this script.
676fc0178dSmrgscriptversion=2015-01-20.17; # UTC
686fc0178dSmrg
696fc0178dSmrg# General shell script boiler plate, and helper functions.
706fc0178dSmrg# Written by Gary V. Vaughan, 2004
716fc0178dSmrg
726fc0178dSmrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
736fc0178dSmrg# This is free software; see the source for copying conditions.  There is NO
746fc0178dSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
756fc0178dSmrg
766fc0178dSmrg# This program is free software; you can redistribute it and/or modify
776fc0178dSmrg# it under the terms of the GNU General Public License as published by
786fc0178dSmrg# the Free Software Foundation; either version 3 of the License, or
796fc0178dSmrg# (at your option) any later version.
806fc0178dSmrg
816fc0178dSmrg# As a special exception to the GNU General Public License, if you distribute
826fc0178dSmrg# this file as part of a program or library that is built using GNU Libtool,
836fc0178dSmrg# you may include this file under the same distribution terms that you use
846fc0178dSmrg# for the rest of that program.
856fc0178dSmrg
866fc0178dSmrg# This program is distributed in the hope that it will be useful,
876fc0178dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
886fc0178dSmrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
896fc0178dSmrg# General Public License for more details.
906fc0178dSmrg
916fc0178dSmrg# You should have received a copy of the GNU General Public License
926fc0178dSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
936fc0178dSmrg
946fc0178dSmrg# Please report bugs or propose patches to gary@gnu.org.
956fc0178dSmrg
966fc0178dSmrg
976fc0178dSmrg## ------ ##
986fc0178dSmrg## Usage. ##
996fc0178dSmrg## ------ ##
1006fc0178dSmrg
1016fc0178dSmrg# Evaluate this file near the top of your script to gain access to
1026fc0178dSmrg# the functions and variables defined here:
1036fc0178dSmrg#
1046fc0178dSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
1056fc0178dSmrg#
1066fc0178dSmrg# If you need to override any of the default environment variable
1076fc0178dSmrg# settings, do that before evaluating this file.
1086fc0178dSmrg
1096fc0178dSmrg
1106fc0178dSmrg## -------------------- ##
1116fc0178dSmrg## Shell normalisation. ##
1126fc0178dSmrg## -------------------- ##
1136fc0178dSmrg
1146fc0178dSmrg# Some shells need a little help to be as Bourne compatible as possible.
1156fc0178dSmrg# Before doing anything else, make sure all that help has been provided!
1166fc0178dSmrg
1176fc0178dSmrgDUALCASE=1; export DUALCASE # for MKS sh
1186fc0178dSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1197a3b38f7Smrg  emulate sh
1207a3b38f7Smrg  NULLCMD=:
1216fc0178dSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1227a3b38f7Smrg  # is contrary to our usage.  Disable this feature.
1237a3b38f7Smrg  alias -g '${1+"$@"}'='"$@"'
1247a3b38f7Smrg  setopt NO_GLOB_SUBST
1257a3b38f7Smrgelse
1266fc0178dSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1277a3b38f7Smrgfi
12844dda7b2Smrg
1296fc0178dSmrg# NLS nuisances: We save the old values in case they are required later.
1306fc0178dSmrg_G_user_locale=
1316fc0178dSmrg_G_safe_locale=
1326fc0178dSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1337a3b38f7Smrgdo
1346fc0178dSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1356fc0178dSmrg          save_$_G_var=\$$_G_var
1366fc0178dSmrg          $_G_var=C
1376fc0178dSmrg	  export $_G_var
1386fc0178dSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1396fc0178dSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1407a3b38f7Smrg	fi"
1417a3b38f7Smrgdone
1427a3b38f7Smrg
1436fc0178dSmrg# CDPATH.
1446fc0178dSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
1457a3b38f7Smrg
1466fc0178dSmrg# Make sure IFS has a sensible default
1476fc0178dSmrgsp=' '
1486fc0178dSmrgnl='
1496fc0178dSmrg'
1506fc0178dSmrgIFS="$sp	$nl"
1516fc0178dSmrg
1526fc0178dSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1536fc0178dSmrgif test "${PATH_SEPARATOR+set}" != set; then
1546fc0178dSmrg  PATH_SEPARATOR=:
1556fc0178dSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1566fc0178dSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1576fc0178dSmrg      PATH_SEPARATOR=';'
1586fc0178dSmrg  }
1596fc0178dSmrgfi
1607a3b38f7Smrg
1617a3b38f7Smrg
1627a3b38f7Smrg
1636fc0178dSmrg## ------------------------- ##
1646fc0178dSmrg## Locate command utilities. ##
1656fc0178dSmrg## ------------------------- ##
1666fc0178dSmrg
1676fc0178dSmrg
1686fc0178dSmrg# func_executable_p FILE
1696fc0178dSmrg# ----------------------
1706fc0178dSmrg# Check that FILE is an executable regular file.
1716fc0178dSmrgfunc_executable_p ()
1726fc0178dSmrg{
1736fc0178dSmrg    test -f "$1" && test -x "$1"
1746fc0178dSmrg}
1756fc0178dSmrg
1766fc0178dSmrg
1776fc0178dSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1786fc0178dSmrg# --------------------------------------------
1796fc0178dSmrg# Search for either a program that responds to --version with output
1806fc0178dSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1816fc0178dSmrg# trying all the directories in PATH with each of the elements of
1826fc0178dSmrg# PROGS_LIST.
1836fc0178dSmrg#
1846fc0178dSmrg# CHECK_FUNC should accept the path to a candidate program, and
1856fc0178dSmrg# set $func_check_prog_result if it truncates its output less than
1866fc0178dSmrg# $_G_path_prog_max characters.
1876fc0178dSmrgfunc_path_progs ()
1886fc0178dSmrg{
1896fc0178dSmrg    _G_progs_list=$1
1906fc0178dSmrg    _G_check_func=$2
1916fc0178dSmrg    _G_PATH=${3-"$PATH"}
1926fc0178dSmrg
1936fc0178dSmrg    _G_path_prog_max=0
1946fc0178dSmrg    _G_path_prog_found=false
1956fc0178dSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
1966fc0178dSmrg    for _G_dir in $_G_PATH; do
1976fc0178dSmrg      IFS=$_G_save_IFS
1986fc0178dSmrg      test -z "$_G_dir" && _G_dir=.
1996fc0178dSmrg      for _G_prog_name in $_G_progs_list; do
2006fc0178dSmrg        for _exeext in '' .EXE; do
2016fc0178dSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2026fc0178dSmrg          func_executable_p "$_G_path_prog" || continue
2036fc0178dSmrg          case `"$_G_path_prog" --version 2>&1` in
2046fc0178dSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2056fc0178dSmrg            *)     $_G_check_func $_G_path_prog
2066fc0178dSmrg		   func_path_progs_result=$func_check_prog_result
2076fc0178dSmrg		   ;;
2086fc0178dSmrg          esac
2096fc0178dSmrg          $_G_path_prog_found && break 3
2106fc0178dSmrg        done
2116fc0178dSmrg      done
2126fc0178dSmrg    done
2136fc0178dSmrg    IFS=$_G_save_IFS
2146fc0178dSmrg    test -z "$func_path_progs_result" && {
2156fc0178dSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2166fc0178dSmrg      exit 1
2176fc0178dSmrg    }
2186fc0178dSmrg}
2196fc0178dSmrg
2206fc0178dSmrg
2216fc0178dSmrg# We want to be able to use the functions in this file before configure
2226fc0178dSmrg# has figured out where the best binaries are kept, which means we have
2236fc0178dSmrg# to search for them ourselves - except when the results are already set
2246fc0178dSmrg# where we skip the searches.
2256fc0178dSmrg
2266fc0178dSmrg# Unless the user overrides by setting SED, search the path for either GNU
2276fc0178dSmrg# sed, or the sed that truncates its output the least.
2286fc0178dSmrgtest -z "$SED" && {
2296fc0178dSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2306fc0178dSmrg  for _G_i in 1 2 3 4 5 6 7; do
2316fc0178dSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2326fc0178dSmrg  done
2336fc0178dSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2346fc0178dSmrg  _G_sed_script=
2356fc0178dSmrg
2366fc0178dSmrg  func_check_prog_sed ()
2376fc0178dSmrg  {
2386fc0178dSmrg    _G_path_prog=$1
2396fc0178dSmrg
2406fc0178dSmrg    _G_count=0
2416fc0178dSmrg    printf 0123456789 >conftest.in
2426fc0178dSmrg    while :
2436fc0178dSmrg    do
2446fc0178dSmrg      cat conftest.in conftest.in >conftest.tmp
2456fc0178dSmrg      mv conftest.tmp conftest.in
2466fc0178dSmrg      cp conftest.in conftest.nl
2476fc0178dSmrg      echo '' >> conftest.nl
2486fc0178dSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2496fc0178dSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2506fc0178dSmrg      _G_count=`expr $_G_count + 1`
2516fc0178dSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2526fc0178dSmrg        # Best one so far, save it but keep looking for a better one
2536fc0178dSmrg        func_check_prog_result=$_G_path_prog
2546fc0178dSmrg        _G_path_prog_max=$_G_count
2556fc0178dSmrg      fi
2566fc0178dSmrg      # 10*(2^10) chars as input seems more than enough
2576fc0178dSmrg      test 10 -lt "$_G_count" && break
2586fc0178dSmrg    done
2596fc0178dSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2606fc0178dSmrg  }
2616fc0178dSmrg
2626fc0178dSmrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
2636fc0178dSmrg  rm -f conftest.sed
2646fc0178dSmrg  SED=$func_path_progs_result
2656fc0178dSmrg}
2666fc0178dSmrg
2676fc0178dSmrg
2686fc0178dSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2696fc0178dSmrg# grep, or the grep that truncates its output the least.
2706fc0178dSmrgtest -z "$GREP" && {
2716fc0178dSmrg  func_check_prog_grep ()
2726fc0178dSmrg  {
2736fc0178dSmrg    _G_path_prog=$1
2746fc0178dSmrg
2756fc0178dSmrg    _G_count=0
2766fc0178dSmrg    _G_path_prog_max=0
2776fc0178dSmrg    printf 0123456789 >conftest.in
2786fc0178dSmrg    while :
2796fc0178dSmrg    do
2806fc0178dSmrg      cat conftest.in conftest.in >conftest.tmp
2816fc0178dSmrg      mv conftest.tmp conftest.in
2826fc0178dSmrg      cp conftest.in conftest.nl
2836fc0178dSmrg      echo 'GREP' >> conftest.nl
2846fc0178dSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2856fc0178dSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2866fc0178dSmrg      _G_count=`expr $_G_count + 1`
2876fc0178dSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2886fc0178dSmrg        # Best one so far, save it but keep looking for a better one
2896fc0178dSmrg        func_check_prog_result=$_G_path_prog
2906fc0178dSmrg        _G_path_prog_max=$_G_count
2916fc0178dSmrg      fi
2926fc0178dSmrg      # 10*(2^10) chars as input seems more than enough
2936fc0178dSmrg      test 10 -lt "$_G_count" && break
2946fc0178dSmrg    done
2956fc0178dSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2966fc0178dSmrg  }
2976fc0178dSmrg
2986fc0178dSmrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
2996fc0178dSmrg  GREP=$func_path_progs_result
3006fc0178dSmrg}
3016fc0178dSmrg
3026fc0178dSmrg
3036fc0178dSmrg## ------------------------------- ##
3046fc0178dSmrg## User overridable command paths. ##
3056fc0178dSmrg## ------------------------------- ##
3066fc0178dSmrg
3076fc0178dSmrg# All uppercase variable names are used for environment variables.  These
3086fc0178dSmrg# variables can be overridden by the user before calling a script that
3096fc0178dSmrg# uses them if a suitable command of that name is not already available
3106fc0178dSmrg# in the command search PATH.
3117a3b38f7Smrg
3127a3b38f7Smrg: ${CP="cp -f"}
3136fc0178dSmrg: ${ECHO="printf %s\n"}
3146fc0178dSmrg: ${EGREP="$GREP -E"}
3156fc0178dSmrg: ${FGREP="$GREP -F"}
3166fc0178dSmrg: ${LN_S="ln -s"}
3177a3b38f7Smrg: ${MAKE="make"}
3187a3b38f7Smrg: ${MKDIR="mkdir"}
3197a3b38f7Smrg: ${MV="mv -f"}
3207a3b38f7Smrg: ${RM="rm -f"}
3217a3b38f7Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3227a3b38f7Smrg
3237a3b38f7Smrg
3246fc0178dSmrg## -------------------- ##
3256fc0178dSmrg## Useful sed snippets. ##
3266fc0178dSmrg## -------------------- ##
327862f5301Smrg
3286fc0178dSmrgsed_dirname='s|/[^/]*$||'
3296fc0178dSmrgsed_basename='s|^.*/||'
330862f5301Smrg
3316fc0178dSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3326fc0178dSmrg# metacharacters that are still active within double-quoted strings.
3336fc0178dSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
334862f5301Smrg
3356fc0178dSmrg# Same as above, but do not quote variable references.
3366fc0178dSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
337862f5301Smrg
3386fc0178dSmrg# Sed substitution that turns a string into a regex matching for the
3396fc0178dSmrg# string literally.
3406fc0178dSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
341862f5301Smrg
3426fc0178dSmrg# Sed substitution that converts a w32 file name or path
3436fc0178dSmrg# that contains forward slashes, into one that contains
3446fc0178dSmrg# (escaped) backslashes.  A very naive implementation.
3456fc0178dSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3466fc0178dSmrg
3476fc0178dSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3486fc0178dSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3496fc0178dSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3506fc0178dSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3516fc0178dSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3526fc0178dSmrg_G_bs='\\'
3536fc0178dSmrg_G_bs2='\\\\'
3546fc0178dSmrg_G_bs4='\\\\\\\\'
3556fc0178dSmrg_G_dollar='\$'
3566fc0178dSmrgsed_double_backslash="\
3576fc0178dSmrg  s/$_G_bs4/&\\
3586fc0178dSmrg/g
3596fc0178dSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3606fc0178dSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3616fc0178dSmrg  s/\n//g"
362862f5301Smrg
3637a3b38f7Smrg
3646fc0178dSmrg## ----------------- ##
3656fc0178dSmrg## Global variables. ##
3666fc0178dSmrg## ----------------- ##
367ff559fabSmrg
3686fc0178dSmrg# Except for the global variables explicitly listed below, the following
3696fc0178dSmrg# functions in the '^func_' namespace, and the '^require_' namespace
3706fc0178dSmrg# variables initialised in the 'Resource management' section, sourcing
3716fc0178dSmrg# this file will not pollute your global namespace with anything
3726fc0178dSmrg# else. There's no portable way to scope variables in Bourne shell
3736fc0178dSmrg# though, so actually running these functions will sometimes place
3746fc0178dSmrg# results into a variable named after the function, and often use
3756fc0178dSmrg# temporary variables in the '^_G_' namespace. If you are careful to
3766fc0178dSmrg# avoid using those namespaces casually in your sourcing script, things
3776fc0178dSmrg# should continue to work as you expect. And, of course, you can freely
3786fc0178dSmrg# overwrite any of the functions or variables defined here before
3796fc0178dSmrg# calling anything to customize them.
38044dda7b2Smrg
3816fc0178dSmrgEXIT_SUCCESS=0
3826fc0178dSmrgEXIT_FAILURE=1
3836fc0178dSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
3846fc0178dSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
38544dda7b2Smrg
3866fc0178dSmrg# Allow overriding, eg assuming that you follow the convention of
3876fc0178dSmrg# putting '$debug_cmd' at the start of all your functions, you can get
3886fc0178dSmrg# bash to show function call trace with:
3896fc0178dSmrg#
3906fc0178dSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
3916fc0178dSmrgdebug_cmd=${debug_cmd-":"}
3926fc0178dSmrgexit_cmd=:
39344dda7b2Smrg
3946fc0178dSmrg# By convention, finish your script with:
3956fc0178dSmrg#
3966fc0178dSmrg#    exit $exit_status
3976fc0178dSmrg#
3986fc0178dSmrg# so that you can set exit_status to non-zero if you want to indicate
3996fc0178dSmrg# something went wrong during execution without actually bailing out at
4006fc0178dSmrg# the point of failure.
4016fc0178dSmrgexit_status=$EXIT_SUCCESS
40244dda7b2Smrg
4036fc0178dSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4046fc0178dSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4056fc0178dSmrg# the _XPG environment variable is not equal to 1 (one), the special
4066fc0178dSmrg# positional parameter $0, within a function call, is the name of the
4076fc0178dSmrg# function.
4086fc0178dSmrgprogpath=$0
409ff559fabSmrg
4106fc0178dSmrg# The name of this program.
4116fc0178dSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
412ff559fabSmrg
4136fc0178dSmrg# Make sure we have an absolute progpath for reexecution:
4147a3b38f7Smrgcase $progpath in
4157a3b38f7Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4167a3b38f7Smrg  *[\\/]*)
4176fc0178dSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4187a3b38f7Smrg     progdir=`cd "$progdir" && pwd`
4196fc0178dSmrg     progpath=$progdir/$progname
4207a3b38f7Smrg     ;;
4217a3b38f7Smrg  *)
4226fc0178dSmrg     _G_IFS=$IFS
423fc544a13Smrg     IFS=${PATH_SEPARATOR-:}
4247a3b38f7Smrg     for progdir in $PATH; do
4256fc0178dSmrg       IFS=$_G_IFS
4267a3b38f7Smrg       test -x "$progdir/$progname" && break
4277a3b38f7Smrg     done
4286fc0178dSmrg     IFS=$_G_IFS
4297a3b38f7Smrg     test -n "$progdir" || progdir=`pwd`
4306fc0178dSmrg     progpath=$progdir/$progname
4317a3b38f7Smrg     ;;
4327a3b38f7Smrgesac
433ff559fabSmrg
4347a3b38f7Smrg
4356fc0178dSmrg## ----------------- ##
4366fc0178dSmrg## Standard options. ##
4376fc0178dSmrg## ----------------- ##
438862f5301Smrg
4396fc0178dSmrg# The following options affect the operation of the functions defined
4406fc0178dSmrg# below, and should be set appropriately depending on run-time para-
4416fc0178dSmrg# meters passed on the command line.
4427a3b38f7Smrg
4437a3b38f7Smrgopt_dry_run=false
4447a3b38f7Smrgopt_quiet=false
4457a3b38f7Smrgopt_verbose=false
4467a3b38f7Smrg
4476fc0178dSmrg# Categories 'all' and 'none' are always available.  Append any others
4486fc0178dSmrg# you will pass as the first argument to func_warning from your own
4496fc0178dSmrg# code.
4506fc0178dSmrgwarning_categories=
451ff559fabSmrg
4526fc0178dSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4536fc0178dSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4546fc0178dSmrg# treat the next displayed warning as a fatal error.
4556fc0178dSmrgwarning_func=func_warn_and_continue
456ff559fabSmrg
4576fc0178dSmrg# Set to 'all' to display all warnings, 'none' to suppress all
4586fc0178dSmrg# warnings, or a space delimited list of some subset of
4596fc0178dSmrg# 'warning_categories' to display only the listed warnings.
4606fc0178dSmrgopt_warning_types=all
461ff559fabSmrg
46244dda7b2Smrg
4636fc0178dSmrg## -------------------- ##
4646fc0178dSmrg## Resource management. ##
4656fc0178dSmrg## -------------------- ##
466ff559fabSmrg
4676fc0178dSmrg# This section contains definitions for functions that each ensure a
4686fc0178dSmrg# particular resource (a file, or a non-empty configuration variable for
4696fc0178dSmrg# example) is available, and if appropriate to extract default values
4706fc0178dSmrg# from pertinent package files. Call them using their associated
4716fc0178dSmrg# 'require_*' variable to ensure that they are executed, at most, once.
4726fc0178dSmrg#
4736fc0178dSmrg# It's entirely deliberate that calling these functions can set
4746fc0178dSmrg# variables that don't obey the namespace limitations obeyed by the rest
4756fc0178dSmrg# of this file, in order that that they be as useful as possible to
4766fc0178dSmrg# callers.
477ff559fabSmrg
478ff559fabSmrg
4796fc0178dSmrg# require_term_colors
4806fc0178dSmrg# -------------------
4816fc0178dSmrg# Allow display of bold text on terminals that support it.
4826fc0178dSmrgrequire_term_colors=func_require_term_colors
4836fc0178dSmrgfunc_require_term_colors ()
4847a3b38f7Smrg{
4856fc0178dSmrg    $debug_cmd
4866fc0178dSmrg
4876fc0178dSmrg    test -t 1 && {
4886fc0178dSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
4896fc0178dSmrg      # precedence, because most terminfo databases neglect to describe
4906fc0178dSmrg      # whether color sequences are supported.
4916fc0178dSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
4926fc0178dSmrg
4936fc0178dSmrg      if test 1 = "$USE_ANSI_COLORS"; then
4946fc0178dSmrg        # Standard ANSI escape sequences
4956fc0178dSmrg        tc_reset='[0m'
4966fc0178dSmrg        tc_bold='[1m';   tc_standout='[7m'
4976fc0178dSmrg        tc_red='[31m';   tc_green='[32m'
4986fc0178dSmrg        tc_blue='[34m';  tc_cyan='[36m'
4996fc0178dSmrg      else
5006fc0178dSmrg        # Otherwise trust the terminfo database after all.
5016fc0178dSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5026fc0178dSmrg          tc_reset=`tput sgr0`
5036fc0178dSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5046fc0178dSmrg          tc_standout=$tc_bold
5056fc0178dSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5066fc0178dSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5076fc0178dSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5086fc0178dSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5096fc0178dSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5106fc0178dSmrg        }
5116fc0178dSmrg      fi
5126fc0178dSmrg    }
513ff559fabSmrg
5146fc0178dSmrg    require_term_colors=:
5157a3b38f7Smrg}
516ff559fabSmrg
517ff559fabSmrg
5186fc0178dSmrg## ----------------- ##
5196fc0178dSmrg## Function library. ##
5206fc0178dSmrg## ----------------- ##
5216fc0178dSmrg
5226fc0178dSmrg# This section contains a variety of useful functions to call in your
5236fc0178dSmrg# scripts. Take note of the portable wrappers for features provided by
5246fc0178dSmrg# some modern shells, which will fall back to slower equivalents on
5256fc0178dSmrg# less featureful shells.
5266fc0178dSmrg
5276fc0178dSmrg
5286fc0178dSmrg# func_append VAR VALUE
5296fc0178dSmrg# ---------------------
5306fc0178dSmrg# Append VALUE onto the existing contents of VAR.
5316fc0178dSmrg
5326fc0178dSmrg  # We should try to minimise forks, especially on Windows where they are
5336fc0178dSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5346fc0178dSmrg  # being used:
5356fc0178dSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5366fc0178dSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5376fc0178dSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5386fc0178dSmrg    # The += operator was introduced in bash 3.1
5396fc0178dSmrg    case $BASH_VERSION in
5406fc0178dSmrg      [12].* | 3.0 | 3.0*) ;;
5416fc0178dSmrg      *)
5426fc0178dSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5436fc0178dSmrg        ;;
5446fc0178dSmrg    esac
5456fc0178dSmrg  fi
5466fc0178dSmrg
5476fc0178dSmrg  # _G_HAVE_PLUSEQ_OP
5486fc0178dSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5496fc0178dSmrg  # useable or anything else if it does not work.
5506fc0178dSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5516fc0178dSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5526fc0178dSmrg    && _G_HAVE_PLUSEQ_OP=yes
5536fc0178dSmrg
5546fc0178dSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5556fc0178dSmrgthen
5566fc0178dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
5576fc0178dSmrg  eval 'func_append ()
5586fc0178dSmrg  {
5596fc0178dSmrg    $debug_cmd
5606fc0178dSmrg
5616fc0178dSmrg    eval "$1+=\$2"
5626fc0178dSmrg  }'
5636fc0178dSmrgelse
5646fc0178dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
5656fc0178dSmrg  func_append ()
5666fc0178dSmrg  {
5676fc0178dSmrg    $debug_cmd
5686fc0178dSmrg
5696fc0178dSmrg    eval "$1=\$$1\$2"
5706fc0178dSmrg  }
5716fc0178dSmrgfi
5726fc0178dSmrg
5736fc0178dSmrg
5746fc0178dSmrg# func_append_quoted VAR VALUE
5756fc0178dSmrg# ----------------------------
5766fc0178dSmrg# Quote VALUE and append to the end of shell variable VAR, separated
5776fc0178dSmrg# by a space.
5786fc0178dSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
5796fc0178dSmrg  eval 'func_append_quoted ()
5806fc0178dSmrg  {
5816fc0178dSmrg    $debug_cmd
5826fc0178dSmrg
5836fc0178dSmrg    func_quote_for_eval "$2"
5846fc0178dSmrg    eval "$1+=\\ \$func_quote_for_eval_result"
5856fc0178dSmrg  }'
5866fc0178dSmrgelse
5876fc0178dSmrg  func_append_quoted ()
5886fc0178dSmrg  {
5896fc0178dSmrg    $debug_cmd
5906fc0178dSmrg
5916fc0178dSmrg    func_quote_for_eval "$2"
5926fc0178dSmrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
5936fc0178dSmrg  }
5946fc0178dSmrgfi
5956fc0178dSmrg
5966fc0178dSmrg
5976fc0178dSmrg# func_append_uniq VAR VALUE
5986fc0178dSmrg# --------------------------
5996fc0178dSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6006fc0178dSmrg# entries are delimited by the first character of VALUE.  For example:
6016fc0178dSmrg#
6026fc0178dSmrg#   func_append_uniq options " --another-option option-argument"
6036fc0178dSmrg#
6046fc0178dSmrg# will only append to $options if " --another-option option-argument "
6056fc0178dSmrg# is not already present somewhere in $options already (note spaces at
6066fc0178dSmrg# each end implied by leading space in second argument).
6076fc0178dSmrgfunc_append_uniq ()
6086fc0178dSmrg{
6096fc0178dSmrg    $debug_cmd
6106fc0178dSmrg
6116fc0178dSmrg    eval _G_current_value='`$ECHO $'$1'`'
6126fc0178dSmrg    _G_delim=`expr "$2" : '\(.\)'`
6136fc0178dSmrg
6146fc0178dSmrg    case $_G_delim$_G_current_value$_G_delim in
6156fc0178dSmrg      *"$2$_G_delim"*) ;;
6166fc0178dSmrg      *) func_append "$@" ;;
6176fc0178dSmrg    esac
6186fc0178dSmrg}
6196fc0178dSmrg
6206fc0178dSmrg
6216fc0178dSmrg# func_arith TERM...
6226fc0178dSmrg# ------------------
6236fc0178dSmrg# Set func_arith_result to the result of evaluating TERMs.
6246fc0178dSmrg  test -z "$_G_HAVE_ARITH_OP" \
6256fc0178dSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6266fc0178dSmrg    && _G_HAVE_ARITH_OP=yes
6276fc0178dSmrg
6286fc0178dSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6296fc0178dSmrg  eval 'func_arith ()
6306fc0178dSmrg  {
6316fc0178dSmrg    $debug_cmd
6326fc0178dSmrg
6336fc0178dSmrg    func_arith_result=$(( $* ))
6346fc0178dSmrg  }'
6356fc0178dSmrgelse
6366fc0178dSmrg  func_arith ()
6376fc0178dSmrg  {
6386fc0178dSmrg    $debug_cmd
6396fc0178dSmrg
6406fc0178dSmrg    func_arith_result=`expr "$@"`
6416fc0178dSmrg  }
6426fc0178dSmrgfi
6436fc0178dSmrg
6446fc0178dSmrg
6456fc0178dSmrg# func_basename FILE
6466fc0178dSmrg# ------------------
6476fc0178dSmrg# Set func_basename_result to FILE with everything up to and including
6486fc0178dSmrg# the last / stripped.
6496fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6506fc0178dSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6516fc0178dSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6526fc0178dSmrg  # on unsupported syntax...
6536fc0178dSmrg  _b='func_basename_result=${1##*/}'
6546fc0178dSmrg  _d='case $1 in
6556fc0178dSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6566fc0178dSmrg        *  ) func_dirname_result=$3        ;;
6576fc0178dSmrg      esac'
6586fc0178dSmrg
6596fc0178dSmrgelse
6606fc0178dSmrg  # ...otherwise fall back to using sed.
6616fc0178dSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
6626fc0178dSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
6636fc0178dSmrg      if test "X$func_dirname_result" = "X$1"; then
6646fc0178dSmrg        func_dirname_result=$3
6656fc0178dSmrg      else
6666fc0178dSmrg        func_append func_dirname_result "$2"
6676fc0178dSmrg      fi'
6686fc0178dSmrgfi
6696fc0178dSmrg
6706fc0178dSmrgeval 'func_basename ()
6716fc0178dSmrg{
6726fc0178dSmrg    $debug_cmd
6736fc0178dSmrg
6746fc0178dSmrg    '"$_b"'
6756fc0178dSmrg}'
6766fc0178dSmrg
6776fc0178dSmrg
6786fc0178dSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
6796fc0178dSmrg# -------------------------------------------
6806fc0178dSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
6816fc0178dSmrg# otherwise set result to NONDIR_REPLACEMENT.
6826fc0178dSmrgeval 'func_dirname ()
6836fc0178dSmrg{
6846fc0178dSmrg    $debug_cmd
6856fc0178dSmrg
6866fc0178dSmrg    '"$_d"'
6876fc0178dSmrg}'
6886fc0178dSmrg
6896fc0178dSmrg
6906fc0178dSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
6916fc0178dSmrg# --------------------------------------------------------
6926fc0178dSmrg# Perform func_basename and func_dirname in a single function
6936fc0178dSmrg# call:
6946fc0178dSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
6956fc0178dSmrg#             add APPEND to the result, otherwise set result
6966fc0178dSmrg#             to NONDIR_REPLACEMENT.
6976fc0178dSmrg#             value returned in "$func_dirname_result"
6986fc0178dSmrg#   basename: Compute filename of FILE.
6996fc0178dSmrg#             value retuned in "$func_basename_result"
7006fc0178dSmrg# For efficiency, we do not delegate to the functions above but instead
7016fc0178dSmrg# duplicate the functionality here.
7026fc0178dSmrgeval 'func_dirname_and_basename ()
7036fc0178dSmrg{
7046fc0178dSmrg    $debug_cmd
7056fc0178dSmrg
7066fc0178dSmrg    '"$_b"'
7076fc0178dSmrg    '"$_d"'
7086fc0178dSmrg}'
7096fc0178dSmrg
7106fc0178dSmrg
7116fc0178dSmrg# func_echo ARG...
7126fc0178dSmrg# ----------------
7136fc0178dSmrg# Echo program name prefixed message.
7146fc0178dSmrgfunc_echo ()
7156fc0178dSmrg{
7166fc0178dSmrg    $debug_cmd
7176fc0178dSmrg
7186fc0178dSmrg    _G_message=$*
7196fc0178dSmrg
7206fc0178dSmrg    func_echo_IFS=$IFS
7216fc0178dSmrg    IFS=$nl
7226fc0178dSmrg    for _G_line in $_G_message; do
7236fc0178dSmrg      IFS=$func_echo_IFS
7246fc0178dSmrg      $ECHO "$progname: $_G_line"
7256fc0178dSmrg    done
7266fc0178dSmrg    IFS=$func_echo_IFS
7276fc0178dSmrg}
7286fc0178dSmrg
7296fc0178dSmrg
7306fc0178dSmrg# func_echo_all ARG...
7316fc0178dSmrg# --------------------
7326fc0178dSmrg# Invoke $ECHO with all args, space-separated.
7336fc0178dSmrgfunc_echo_all ()
7346fc0178dSmrg{
7356fc0178dSmrg    $ECHO "$*"
7366fc0178dSmrg}
7376fc0178dSmrg
7386fc0178dSmrg
7396fc0178dSmrg# func_echo_infix_1 INFIX ARG...
7406fc0178dSmrg# ------------------------------
7416fc0178dSmrg# Echo program name, followed by INFIX on the first line, with any
7426fc0178dSmrg# additional lines not showing INFIX.
7436fc0178dSmrgfunc_echo_infix_1 ()
7446fc0178dSmrg{
7456fc0178dSmrg    $debug_cmd
7466fc0178dSmrg
7476fc0178dSmrg    $require_term_colors
7486fc0178dSmrg
7496fc0178dSmrg    _G_infix=$1; shift
7506fc0178dSmrg    _G_indent=$_G_infix
7516fc0178dSmrg    _G_prefix="$progname: $_G_infix: "
7526fc0178dSmrg    _G_message=$*
7536fc0178dSmrg
7546fc0178dSmrg    # Strip color escape sequences before counting printable length
7556fc0178dSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7566fc0178dSmrg    do
7576fc0178dSmrg      test -n "$_G_tc" && {
7586fc0178dSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
7596fc0178dSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
7606fc0178dSmrg      }
7616fc0178dSmrg    done
7626fc0178dSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
7636fc0178dSmrg
7646fc0178dSmrg    func_echo_infix_1_IFS=$IFS
7656fc0178dSmrg    IFS=$nl
7666fc0178dSmrg    for _G_line in $_G_message; do
7676fc0178dSmrg      IFS=$func_echo_infix_1_IFS
7686fc0178dSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
7696fc0178dSmrg      _G_prefix=$_G_indent
7706fc0178dSmrg    done
7716fc0178dSmrg    IFS=$func_echo_infix_1_IFS
7726fc0178dSmrg}
7736fc0178dSmrg
7746fc0178dSmrg
7756fc0178dSmrg# func_error ARG...
7766fc0178dSmrg# -----------------
7776fc0178dSmrg# Echo program name prefixed message to standard error.
7786fc0178dSmrgfunc_error ()
7796fc0178dSmrg{
7806fc0178dSmrg    $debug_cmd
7816fc0178dSmrg
7826fc0178dSmrg    $require_term_colors
7836fc0178dSmrg
7846fc0178dSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
7856fc0178dSmrg}
7866fc0178dSmrg
7876fc0178dSmrg
7886fc0178dSmrg# func_fatal_error ARG...
7896fc0178dSmrg# -----------------------
7906fc0178dSmrg# Echo program name prefixed message to standard error, and exit.
7916fc0178dSmrgfunc_fatal_error ()
7926fc0178dSmrg{
7936fc0178dSmrg    $debug_cmd
7946fc0178dSmrg
7956fc0178dSmrg    func_error "$*"
7966fc0178dSmrg    exit $EXIT_FAILURE
7976fc0178dSmrg}
7986fc0178dSmrg
7996fc0178dSmrg
8006fc0178dSmrg# func_grep EXPRESSION FILENAME
8016fc0178dSmrg# -----------------------------
8027a3b38f7Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8037a3b38f7Smrgfunc_grep ()
8047a3b38f7Smrg{
8056fc0178dSmrg    $debug_cmd
8066fc0178dSmrg
8077a3b38f7Smrg    $GREP "$1" "$2" >/dev/null 2>&1
8087a3b38f7Smrg}
8097a3b38f7Smrg
8107a3b38f7Smrg
8116fc0178dSmrg# func_len STRING
8126fc0178dSmrg# ---------------
8136fc0178dSmrg# Set func_len_result to the length of STRING. STRING may not
8146fc0178dSmrg# start with a hyphen.
8156fc0178dSmrg  test -z "$_G_HAVE_XSI_OPS" \
8166fc0178dSmrg    && (eval 'x=a/b/c;
8176fc0178dSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8186fc0178dSmrg    && _G_HAVE_XSI_OPS=yes
8196fc0178dSmrg
8206fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8216fc0178dSmrg  eval 'func_len ()
8226fc0178dSmrg  {
8236fc0178dSmrg    $debug_cmd
8246fc0178dSmrg
8256fc0178dSmrg    func_len_result=${#1}
8266fc0178dSmrg  }'
8276fc0178dSmrgelse
8286fc0178dSmrg  func_len ()
8296fc0178dSmrg  {
8306fc0178dSmrg    $debug_cmd
8316fc0178dSmrg
8326fc0178dSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8336fc0178dSmrg  }
8346fc0178dSmrgfi
8356fc0178dSmrg
8366fc0178dSmrg
8376fc0178dSmrg# func_mkdir_p DIRECTORY-PATH
8386fc0178dSmrg# ---------------------------
8397a3b38f7Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8407a3b38f7Smrgfunc_mkdir_p ()
8417a3b38f7Smrg{
8426fc0178dSmrg    $debug_cmd
8437a3b38f7Smrg
8446fc0178dSmrg    _G_directory_path=$1
8456fc0178dSmrg    _G_dir_list=
8467a3b38f7Smrg
8476fc0178dSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8486fc0178dSmrg
8496fc0178dSmrg      # Protect directory names starting with '-'
8506fc0178dSmrg      case $_G_directory_path in
8516fc0178dSmrg        -*) _G_directory_path=./$_G_directory_path ;;
8527a3b38f7Smrg      esac
8537a3b38f7Smrg
8547a3b38f7Smrg      # While some portion of DIR does not yet exist...
8556fc0178dSmrg      while test ! -d "$_G_directory_path"; do
8567a3b38f7Smrg        # ...make a list in topmost first order.  Use a colon delimited
8577a3b38f7Smrg	# list incase some portion of path contains whitespace.
8586fc0178dSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
8597a3b38f7Smrg
8607a3b38f7Smrg        # If the last portion added has no slash in it, the list is done
8616fc0178dSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
8627a3b38f7Smrg
8637a3b38f7Smrg        # ...otherwise throw away the child directory and loop
8646fc0178dSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
8657a3b38f7Smrg      done
8666fc0178dSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
8677a3b38f7Smrg
8686fc0178dSmrg      func_mkdir_p_IFS=$IFS; IFS=:
8696fc0178dSmrg      for _G_dir in $_G_dir_list; do
8706fc0178dSmrg	IFS=$func_mkdir_p_IFS
8716fc0178dSmrg        # mkdir can fail with a 'File exist' error if two processes
8727a3b38f7Smrg        # try to create one of the directories concurrently.  Don't
8737a3b38f7Smrg        # stop in that case!
8746fc0178dSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
8757a3b38f7Smrg      done
8766fc0178dSmrg      IFS=$func_mkdir_p_IFS
8777a3b38f7Smrg
8787a3b38f7Smrg      # Bail out if we (or some other process) failed to create a directory.
8796fc0178dSmrg      test -d "$_G_directory_path" || \
8806fc0178dSmrg        func_fatal_error "Failed to create '$1'"
8817a3b38f7Smrg    fi
8827a3b38f7Smrg}
883ff559fabSmrg
884ff559fabSmrg
8856fc0178dSmrg# func_mktempdir [BASENAME]
8866fc0178dSmrg# -------------------------
887ff559fabSmrg# Make a temporary directory that won't clash with other running
888ff559fabSmrg# libtool processes, and avoids race conditions if possible.  If
8896fc0178dSmrg# given, BASENAME is the basename for that directory.
890ff559fabSmrgfunc_mktempdir ()
891ff559fabSmrg{
8926fc0178dSmrg    $debug_cmd
8936fc0178dSmrg
8946fc0178dSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
895ff559fabSmrg
8966fc0178dSmrg    if test : = "$opt_dry_run"; then
897ff559fabSmrg      # Return a directory name, but don't create it in dry-run mode
8986fc0178dSmrg      _G_tmpdir=$_G_template-$$
899ff559fabSmrg    else
900ff559fabSmrg
901ff559fabSmrg      # If mktemp works, use that first and foremost
9026fc0178dSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903ff559fabSmrg
9046fc0178dSmrg      if test ! -d "$_G_tmpdir"; then
9057a3b38f7Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9066fc0178dSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
907ff559fabSmrg
9086fc0178dSmrg        func_mktempdir_umask=`umask`
9097a3b38f7Smrg        umask 0077
9106fc0178dSmrg        $MKDIR "$_G_tmpdir"
9116fc0178dSmrg        umask $func_mktempdir_umask
912ff559fabSmrg      fi
913ff559fabSmrg
914ff559fabSmrg      # If we're not in dry-run mode, bomb out on failure
9156fc0178dSmrg      test -d "$_G_tmpdir" || \
9166fc0178dSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9176fc0178dSmrg    fi
9186fc0178dSmrg
9196fc0178dSmrg    $ECHO "$_G_tmpdir"
9206fc0178dSmrg}
9216fc0178dSmrg
9226fc0178dSmrg
9236fc0178dSmrg# func_normal_abspath PATH
9246fc0178dSmrg# ------------------------
9256fc0178dSmrg# Remove doubled-up and trailing slashes, "." path components,
9266fc0178dSmrg# and cancel out any ".." path components in PATH after making
9276fc0178dSmrg# it an absolute path.
9286fc0178dSmrgfunc_normal_abspath ()
9296fc0178dSmrg{
9306fc0178dSmrg    $debug_cmd
9316fc0178dSmrg
9326fc0178dSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9336fc0178dSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9346fc0178dSmrg    _G_pathcdr='s|^/[^/]*||'
9356fc0178dSmrg    _G_removedotparts=':dotsl
9366fc0178dSmrg		s|/\./|/|g
9376fc0178dSmrg		t dotsl
9386fc0178dSmrg		s|/\.$|/|'
9396fc0178dSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9406fc0178dSmrg    _G_finalslash='s|/*$|/|'
9416fc0178dSmrg
9426fc0178dSmrg    # Start from root dir and reassemble the path.
9436fc0178dSmrg    func_normal_abspath_result=
9446fc0178dSmrg    func_normal_abspath_tpath=$1
9456fc0178dSmrg    func_normal_abspath_altnamespace=
9466fc0178dSmrg    case $func_normal_abspath_tpath in
9476fc0178dSmrg      "")
9486fc0178dSmrg        # Empty path, that just means $cwd.
9496fc0178dSmrg        func_stripname '' '/' "`pwd`"
9506fc0178dSmrg        func_normal_abspath_result=$func_stripname_result
9516fc0178dSmrg        return
9526fc0178dSmrg        ;;
9536fc0178dSmrg      # The next three entries are used to spot a run of precisely
9546fc0178dSmrg      # two leading slashes without using negated character classes;
9556fc0178dSmrg      # we take advantage of case's first-match behaviour.
9566fc0178dSmrg      ///*)
9576fc0178dSmrg        # Unusual form of absolute path, do nothing.
9586fc0178dSmrg        ;;
9596fc0178dSmrg      //*)
9606fc0178dSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
9616fc0178dSmrg        # and for example Cygwin uses it to access remote file shares
9626fc0178dSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
9636fc0178dSmrg        func_normal_abspath_altnamespace=/
9646fc0178dSmrg        ;;
9656fc0178dSmrg      /*)
9666fc0178dSmrg        # Absolute path, do nothing.
9676fc0178dSmrg        ;;
9686fc0178dSmrg      *)
9696fc0178dSmrg        # Relative path, prepend $cwd.
9706fc0178dSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
9716fc0178dSmrg        ;;
9726fc0178dSmrg    esac
9736fc0178dSmrg
9746fc0178dSmrg    # Cancel out all the simple stuff to save iterations.  We also want
9756fc0178dSmrg    # the path to end with a slash for ease of parsing, so make sure
9766fc0178dSmrg    # there is one (and only one) here.
9776fc0178dSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
9786fc0178dSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
9796fc0178dSmrg    while :; do
9806fc0178dSmrg      # Processed it all yet?
9816fc0178dSmrg      if test / = "$func_normal_abspath_tpath"; then
9826fc0178dSmrg        # If we ascended to the root using ".." the result may be empty now.
9836fc0178dSmrg        if test -z "$func_normal_abspath_result"; then
9846fc0178dSmrg          func_normal_abspath_result=/
9856fc0178dSmrg        fi
9866fc0178dSmrg        break
9876fc0178dSmrg      fi
9886fc0178dSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
9896fc0178dSmrg          -e "$_G_pathcar"`
9906fc0178dSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
9916fc0178dSmrg          -e "$_G_pathcdr"`
9926fc0178dSmrg      # Figure out what to do with it
9936fc0178dSmrg      case $func_normal_abspath_tcomponent in
9946fc0178dSmrg        "")
9956fc0178dSmrg          # Trailing empty path component, ignore it.
9966fc0178dSmrg          ;;
9976fc0178dSmrg        ..)
9986fc0178dSmrg          # Parent dir; strip last assembled component from result.
9996fc0178dSmrg          func_dirname "$func_normal_abspath_result"
10006fc0178dSmrg          func_normal_abspath_result=$func_dirname_result
10016fc0178dSmrg          ;;
10026fc0178dSmrg        *)
10036fc0178dSmrg          # Actual path component, append it.
10046fc0178dSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10056fc0178dSmrg          ;;
10066fc0178dSmrg      esac
10076fc0178dSmrg    done
10086fc0178dSmrg    # Restore leading double-slash if one was found on entry.
10096fc0178dSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10106fc0178dSmrg}
10116fc0178dSmrg
10126fc0178dSmrg
10136fc0178dSmrg# func_notquiet ARG...
10146fc0178dSmrg# --------------------
10156fc0178dSmrg# Echo program name prefixed message only when not in quiet mode.
10166fc0178dSmrgfunc_notquiet ()
10176fc0178dSmrg{
10186fc0178dSmrg    $debug_cmd
10196fc0178dSmrg
10206fc0178dSmrg    $opt_quiet || func_echo ${1+"$@"}
10216fc0178dSmrg
10226fc0178dSmrg    # A bug in bash halts the script if the last line of a function
10236fc0178dSmrg    # fails when set -e is in force, so we need another command to
10246fc0178dSmrg    # work around that:
10256fc0178dSmrg    :
10266fc0178dSmrg}
10276fc0178dSmrg
10286fc0178dSmrg
10296fc0178dSmrg# func_relative_path SRCDIR DSTDIR
10306fc0178dSmrg# --------------------------------
10316fc0178dSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10326fc0178dSmrgfunc_relative_path ()
10336fc0178dSmrg{
10346fc0178dSmrg    $debug_cmd
10356fc0178dSmrg
10366fc0178dSmrg    func_relative_path_result=
10376fc0178dSmrg    func_normal_abspath "$1"
10386fc0178dSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10396fc0178dSmrg    func_normal_abspath "$2"
10406fc0178dSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10416fc0178dSmrg
10426fc0178dSmrg    # Ascend the tree starting from libdir
10436fc0178dSmrg    while :; do
10446fc0178dSmrg      # check if we have found a prefix of bindir
10456fc0178dSmrg      case $func_relative_path_tbindir in
10466fc0178dSmrg        $func_relative_path_tlibdir)
10476fc0178dSmrg          # found an exact match
10486fc0178dSmrg          func_relative_path_tcancelled=
10496fc0178dSmrg          break
10506fc0178dSmrg          ;;
10516fc0178dSmrg        $func_relative_path_tlibdir*)
10526fc0178dSmrg          # found a matching prefix
10536fc0178dSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10546fc0178dSmrg          func_relative_path_tcancelled=$func_stripname_result
10556fc0178dSmrg          if test -z "$func_relative_path_result"; then
10566fc0178dSmrg            func_relative_path_result=.
10576fc0178dSmrg          fi
10586fc0178dSmrg          break
10596fc0178dSmrg          ;;
10606fc0178dSmrg        *)
10616fc0178dSmrg          func_dirname $func_relative_path_tlibdir
10626fc0178dSmrg          func_relative_path_tlibdir=$func_dirname_result
10636fc0178dSmrg          if test -z "$func_relative_path_tlibdir"; then
10646fc0178dSmrg            # Have to descend all the way to the root!
10656fc0178dSmrg            func_relative_path_result=../$func_relative_path_result
10666fc0178dSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
10676fc0178dSmrg            break
10686fc0178dSmrg          fi
10696fc0178dSmrg          func_relative_path_result=../$func_relative_path_result
10706fc0178dSmrg          ;;
10716fc0178dSmrg      esac
10726fc0178dSmrg    done
10736fc0178dSmrg
10746fc0178dSmrg    # Now calculate path; take care to avoid doubling-up slashes.
10756fc0178dSmrg    func_stripname '' '/' "$func_relative_path_result"
10766fc0178dSmrg    func_relative_path_result=$func_stripname_result
10776fc0178dSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
10786fc0178dSmrg    if test -n "$func_stripname_result"; then
10796fc0178dSmrg      func_append func_relative_path_result "/$func_stripname_result"
10806fc0178dSmrg    fi
10816fc0178dSmrg
10826fc0178dSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
10836fc0178dSmrg    if test -n "$func_relative_path_result"; then
10846fc0178dSmrg      func_stripname './' '' "$func_relative_path_result"
10856fc0178dSmrg      func_relative_path_result=$func_stripname_result
1086ff559fabSmrg    fi
1087ff559fabSmrg
10886fc0178dSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
10896fc0178dSmrg
10906fc0178dSmrg    :
10916fc0178dSmrg}
10926fc0178dSmrg
10936fc0178dSmrg
10946fc0178dSmrg# func_quote_for_eval ARG...
10956fc0178dSmrg# --------------------------
10966fc0178dSmrg# Aesthetically quote ARGs to be evaled later.
10976fc0178dSmrg# This function returns two values:
10986fc0178dSmrg#   i) func_quote_for_eval_result
10996fc0178dSmrg#      double-quoted, suitable for a subsequent eval
11006fc0178dSmrg#  ii) func_quote_for_eval_unquoted_result
11016fc0178dSmrg#      has all characters that are still active within double
11026fc0178dSmrg#      quotes backslashified.
11036fc0178dSmrgfunc_quote_for_eval ()
11046fc0178dSmrg{
11056fc0178dSmrg    $debug_cmd
11066fc0178dSmrg
11076fc0178dSmrg    func_quote_for_eval_unquoted_result=
11086fc0178dSmrg    func_quote_for_eval_result=
11096fc0178dSmrg    while test 0 -lt $#; do
11106fc0178dSmrg      case $1 in
11116fc0178dSmrg        *[\\\`\"\$]*)
11126fc0178dSmrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
11136fc0178dSmrg        *)
11146fc0178dSmrg          _G_unquoted_arg=$1 ;;
11156fc0178dSmrg      esac
11166fc0178dSmrg      if test -n "$func_quote_for_eval_unquoted_result"; then
11176fc0178dSmrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
11186fc0178dSmrg      else
11196fc0178dSmrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
11206fc0178dSmrg      fi
11216fc0178dSmrg
11226fc0178dSmrg      case $_G_unquoted_arg in
11236fc0178dSmrg        # Double-quote args containing shell metacharacters to delay
11246fc0178dSmrg        # word splitting, command substitution and variable expansion
11256fc0178dSmrg        # for a subsequent eval.
11266fc0178dSmrg        # Many Bourne shells cannot handle close brackets correctly
11276fc0178dSmrg        # in scan sets, so we specify it separately.
11286fc0178dSmrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
11296fc0178dSmrg          _G_quoted_arg=\"$_G_unquoted_arg\"
11306fc0178dSmrg          ;;
11316fc0178dSmrg        *)
11326fc0178dSmrg          _G_quoted_arg=$_G_unquoted_arg
11336fc0178dSmrg	  ;;
11346fc0178dSmrg      esac
11356fc0178dSmrg
11366fc0178dSmrg      if test -n "$func_quote_for_eval_result"; then
11376fc0178dSmrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
11386fc0178dSmrg      else
11396fc0178dSmrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
11406fc0178dSmrg      fi
11416fc0178dSmrg      shift
11426fc0178dSmrg    done
11436fc0178dSmrg}
11446fc0178dSmrg
11456fc0178dSmrg
11466fc0178dSmrg# func_quote_for_expand ARG
11476fc0178dSmrg# -------------------------
11486fc0178dSmrg# Aesthetically quote ARG to be evaled later; same as above,
11496fc0178dSmrg# but do not quote variable references.
11506fc0178dSmrgfunc_quote_for_expand ()
11516fc0178dSmrg{
11526fc0178dSmrg    $debug_cmd
11536fc0178dSmrg
11546fc0178dSmrg    case $1 in
11556fc0178dSmrg      *[\\\`\"]*)
11566fc0178dSmrg	_G_arg=`$ECHO "$1" | $SED \
11576fc0178dSmrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
11586fc0178dSmrg      *)
11596fc0178dSmrg        _G_arg=$1 ;;
11606fc0178dSmrg    esac
11616fc0178dSmrg
11626fc0178dSmrg    case $_G_arg in
11636fc0178dSmrg      # Double-quote args containing shell metacharacters to delay
11646fc0178dSmrg      # word splitting and command substitution for a subsequent eval.
11656fc0178dSmrg      # Many Bourne shells cannot handle close brackets correctly
11666fc0178dSmrg      # in scan sets, so we specify it separately.
11676fc0178dSmrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
11686fc0178dSmrg        _G_arg=\"$_G_arg\"
11696fc0178dSmrg        ;;
11706fc0178dSmrg    esac
11716fc0178dSmrg
11726fc0178dSmrg    func_quote_for_expand_result=$_G_arg
11736fc0178dSmrg}
11746fc0178dSmrg
11756fc0178dSmrg
11766fc0178dSmrg# func_stripname PREFIX SUFFIX NAME
11776fc0178dSmrg# ---------------------------------
11786fc0178dSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
11796fc0178dSmrg# PREFIX and SUFFIX must not contain globbing or regex special
11806fc0178dSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
11816fc0178dSmrg# dot (in which case that matches only a dot).
11826fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
11836fc0178dSmrg  eval 'func_stripname ()
11846fc0178dSmrg  {
11856fc0178dSmrg    $debug_cmd
11866fc0178dSmrg
11876fc0178dSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
11886fc0178dSmrg    # positional parameters, so assign one to ordinary variable first.
11896fc0178dSmrg    func_stripname_result=$3
11906fc0178dSmrg    func_stripname_result=${func_stripname_result#"$1"}
11916fc0178dSmrg    func_stripname_result=${func_stripname_result%"$2"}
11926fc0178dSmrg  }'
11936fc0178dSmrgelse
11946fc0178dSmrg  func_stripname ()
11956fc0178dSmrg  {
11966fc0178dSmrg    $debug_cmd
11976fc0178dSmrg
11986fc0178dSmrg    case $2 in
11996fc0178dSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
12006fc0178dSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
12016fc0178dSmrg    esac
12026fc0178dSmrg  }
12036fc0178dSmrgfi
12046fc0178dSmrg
12056fc0178dSmrg
12066fc0178dSmrg# func_show_eval CMD [FAIL_EXP]
12076fc0178dSmrg# -----------------------------
12086fc0178dSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12096fc0178dSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12106fc0178dSmrg# is given, then evaluate it.
12116fc0178dSmrgfunc_show_eval ()
12126fc0178dSmrg{
12136fc0178dSmrg    $debug_cmd
12146fc0178dSmrg
12156fc0178dSmrg    _G_cmd=$1
12166fc0178dSmrg    _G_fail_exp=${2-':'}
12176fc0178dSmrg
12186fc0178dSmrg    func_quote_for_expand "$_G_cmd"
12196fc0178dSmrg    eval "func_notquiet $func_quote_for_expand_result"
12206fc0178dSmrg
12216fc0178dSmrg    $opt_dry_run || {
12226fc0178dSmrg      eval "$_G_cmd"
12236fc0178dSmrg      _G_status=$?
12246fc0178dSmrg      if test 0 -ne "$_G_status"; then
12256fc0178dSmrg	eval "(exit $_G_status); $_G_fail_exp"
12266fc0178dSmrg      fi
12276fc0178dSmrg    }
12286fc0178dSmrg}
12296fc0178dSmrg
12306fc0178dSmrg
12316fc0178dSmrg# func_show_eval_locale CMD [FAIL_EXP]
12326fc0178dSmrg# ------------------------------------
12336fc0178dSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12346fc0178dSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12356fc0178dSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
12366fc0178dSmrgfunc_show_eval_locale ()
12376fc0178dSmrg{
12386fc0178dSmrg    $debug_cmd
12396fc0178dSmrg
12406fc0178dSmrg    _G_cmd=$1
12416fc0178dSmrg    _G_fail_exp=${2-':'}
12426fc0178dSmrg
12436fc0178dSmrg    $opt_quiet || {
12446fc0178dSmrg      func_quote_for_expand "$_G_cmd"
12456fc0178dSmrg      eval "func_echo $func_quote_for_expand_result"
12466fc0178dSmrg    }
12476fc0178dSmrg
12486fc0178dSmrg    $opt_dry_run || {
12496fc0178dSmrg      eval "$_G_user_locale
12506fc0178dSmrg	    $_G_cmd"
12516fc0178dSmrg      _G_status=$?
12526fc0178dSmrg      eval "$_G_safe_locale"
12536fc0178dSmrg      if test 0 -ne "$_G_status"; then
12546fc0178dSmrg	eval "(exit $_G_status); $_G_fail_exp"
12556fc0178dSmrg      fi
12566fc0178dSmrg    }
12576fc0178dSmrg}
12586fc0178dSmrg
12596fc0178dSmrg
12606fc0178dSmrg# func_tr_sh
12616fc0178dSmrg# ----------
12626fc0178dSmrg# Turn $1 into a string suitable for a shell variable name.
12636fc0178dSmrg# Result is stored in $func_tr_sh_result.  All characters
12646fc0178dSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
12656fc0178dSmrg# if $1 begins with a digit, a '_' is prepended as well.
12666fc0178dSmrgfunc_tr_sh ()
12676fc0178dSmrg{
12686fc0178dSmrg    $debug_cmd
12696fc0178dSmrg
12706fc0178dSmrg    case $1 in
12716fc0178dSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
12726fc0178dSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
12736fc0178dSmrg      ;;
12746fc0178dSmrg    * )
12756fc0178dSmrg      func_tr_sh_result=$1
12766fc0178dSmrg      ;;
12776fc0178dSmrg    esac
12786fc0178dSmrg}
12796fc0178dSmrg
12806fc0178dSmrg
12816fc0178dSmrg# func_verbose ARG...
12826fc0178dSmrg# -------------------
12836fc0178dSmrg# Echo program name prefixed message in verbose mode only.
12846fc0178dSmrgfunc_verbose ()
12856fc0178dSmrg{
12866fc0178dSmrg    $debug_cmd
12876fc0178dSmrg
12886fc0178dSmrg    $opt_verbose && func_echo "$*"
12896fc0178dSmrg
12906fc0178dSmrg    :
12916fc0178dSmrg}
12926fc0178dSmrg
12936fc0178dSmrg
12946fc0178dSmrg# func_warn_and_continue ARG...
12956fc0178dSmrg# -----------------------------
12966fc0178dSmrg# Echo program name prefixed warning message to standard error.
12976fc0178dSmrgfunc_warn_and_continue ()
12986fc0178dSmrg{
12996fc0178dSmrg    $debug_cmd
13006fc0178dSmrg
13016fc0178dSmrg    $require_term_colors
13026fc0178dSmrg
13036fc0178dSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
13046fc0178dSmrg}
13056fc0178dSmrg
13066fc0178dSmrg
13076fc0178dSmrg# func_warning CATEGORY ARG...
13086fc0178dSmrg# ----------------------------
13096fc0178dSmrg# Echo program name prefixed warning message to standard error. Warning
13106fc0178dSmrg# messages can be filtered according to CATEGORY, where this function
13116fc0178dSmrg# elides messages where CATEGORY is not listed in the global variable
13126fc0178dSmrg# 'opt_warning_types'.
13136fc0178dSmrgfunc_warning ()
13146fc0178dSmrg{
13156fc0178dSmrg    $debug_cmd
13166fc0178dSmrg
13176fc0178dSmrg    # CATEGORY must be in the warning_categories list!
13186fc0178dSmrg    case " $warning_categories " in
13196fc0178dSmrg      *" $1 "*) ;;
13206fc0178dSmrg      *) func_internal_error "invalid warning category '$1'" ;;
13216fc0178dSmrg    esac
13226fc0178dSmrg
13236fc0178dSmrg    _G_category=$1
13246fc0178dSmrg    shift
13256fc0178dSmrg
13266fc0178dSmrg    case " $opt_warning_types " in
13276fc0178dSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
13286fc0178dSmrg    esac
13296fc0178dSmrg}
13306fc0178dSmrg
13316fc0178dSmrg
13326fc0178dSmrg# func_sort_ver VER1 VER2
13336fc0178dSmrg# -----------------------
13346fc0178dSmrg# 'sort -V' is not generally available.
13356fc0178dSmrg# Note this deviates from the version comparison in automake
13366fc0178dSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
13376fc0178dSmrg# but this should suffice as we won't be specifying old
13386fc0178dSmrg# version formats or redundant trailing .0 in bootstrap.conf.
13396fc0178dSmrg# If we did want full compatibility then we should probably
13406fc0178dSmrg# use m4_version_compare from autoconf.
13416fc0178dSmrgfunc_sort_ver ()
13426fc0178dSmrg{
13436fc0178dSmrg    $debug_cmd
13446fc0178dSmrg
13456fc0178dSmrg    printf '%s\n%s\n' "$1" "$2" \
13466fc0178dSmrg      | 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
13476fc0178dSmrg}
13486fc0178dSmrg
13496fc0178dSmrg# func_lt_ver PREV CURR
13506fc0178dSmrg# ---------------------
13516fc0178dSmrg# Return true if PREV and CURR are in the correct order according to
13526fc0178dSmrg# func_sort_ver, otherwise false.  Use it like this:
13536fc0178dSmrg#
13546fc0178dSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
13556fc0178dSmrgfunc_lt_ver ()
13566fc0178dSmrg{
13576fc0178dSmrg    $debug_cmd
13586fc0178dSmrg
13596fc0178dSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
13606fc0178dSmrg}
13616fc0178dSmrg
13626fc0178dSmrg
13636fc0178dSmrg# Local variables:
13646fc0178dSmrg# mode: shell-script
13656fc0178dSmrg# sh-indentation: 2
13666fc0178dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
13676fc0178dSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
13686fc0178dSmrg# time-stamp-time-zone: "UTC"
13696fc0178dSmrg# End:
13706fc0178dSmrg#! /bin/sh
13716fc0178dSmrg
13726fc0178dSmrg# Set a version string for this script.
13736fc0178dSmrgscriptversion=2014-01-07.03; # UTC
13746fc0178dSmrg
13756fc0178dSmrg# A portable, pluggable option parser for Bourne shell.
13766fc0178dSmrg# Written by Gary V. Vaughan, 2010
13776fc0178dSmrg
13786fc0178dSmrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
13796fc0178dSmrg# This is free software; see the source for copying conditions.  There is NO
13806fc0178dSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13816fc0178dSmrg
13826fc0178dSmrg# This program is free software: you can redistribute it and/or modify
13836fc0178dSmrg# it under the terms of the GNU General Public License as published by
13846fc0178dSmrg# the Free Software Foundation, either version 3 of the License, or
13856fc0178dSmrg# (at your option) any later version.
13866fc0178dSmrg
13876fc0178dSmrg# This program is distributed in the hope that it will be useful,
13886fc0178dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
13896fc0178dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13906fc0178dSmrg# GNU General Public License for more details.
13916fc0178dSmrg
13926fc0178dSmrg# You should have received a copy of the GNU General Public License
13936fc0178dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13946fc0178dSmrg
13956fc0178dSmrg# Please report bugs or propose patches to gary@gnu.org.
13966fc0178dSmrg
13976fc0178dSmrg
13986fc0178dSmrg## ------ ##
13996fc0178dSmrg## Usage. ##
14006fc0178dSmrg## ------ ##
14016fc0178dSmrg
14026fc0178dSmrg# This file is a library for parsing options in your shell scripts along
14036fc0178dSmrg# with assorted other useful supporting features that you can make use
14046fc0178dSmrg# of too.
14056fc0178dSmrg#
14066fc0178dSmrg# For the simplest scripts you might need only:
14076fc0178dSmrg#
14086fc0178dSmrg#   #!/bin/sh
14096fc0178dSmrg#   . relative/path/to/funclib.sh
14106fc0178dSmrg#   . relative/path/to/options-parser
14116fc0178dSmrg#   scriptversion=1.0
14126fc0178dSmrg#   func_options ${1+"$@"}
14136fc0178dSmrg#   eval set dummy "$func_options_result"; shift
14146fc0178dSmrg#   ...rest of your script...
14156fc0178dSmrg#
14166fc0178dSmrg# In order for the '--version' option to work, you will need to have a
14176fc0178dSmrg# suitably formatted comment like the one at the top of this file
14186fc0178dSmrg# starting with '# Written by ' and ending with '# warranty; '.
14196fc0178dSmrg#
14206fc0178dSmrg# For '-h' and '--help' to work, you will also need a one line
14216fc0178dSmrg# description of your script's purpose in a comment directly above the
14226fc0178dSmrg# '# Written by ' line, like the one at the top of this file.
14236fc0178dSmrg#
14246fc0178dSmrg# The default options also support '--debug', which will turn on shell
14256fc0178dSmrg# execution tracing (see the comment above debug_cmd below for another
14266fc0178dSmrg# use), and '--verbose' and the func_verbose function to allow your script
14276fc0178dSmrg# to display verbose messages only when your user has specified
14286fc0178dSmrg# '--verbose'.
14296fc0178dSmrg#
14306fc0178dSmrg# After sourcing this file, you can plug processing for additional
14316fc0178dSmrg# options by amending the variables from the 'Configuration' section
14326fc0178dSmrg# below, and following the instructions in the 'Option parsing'
14336fc0178dSmrg# section further down.
14346fc0178dSmrg
14356fc0178dSmrg## -------------- ##
14366fc0178dSmrg## Configuration. ##
14376fc0178dSmrg## -------------- ##
14386fc0178dSmrg
14396fc0178dSmrg# You should override these variables in your script after sourcing this
14406fc0178dSmrg# file so that they reflect the customisations you have added to the
14416fc0178dSmrg# option parser.
14426fc0178dSmrg
14436fc0178dSmrg# The usage line for option parsing errors and the start of '-h' and
14446fc0178dSmrg# '--help' output messages. You can embed shell variables for delayed
14456fc0178dSmrg# expansion at the time the message is displayed, but you will need to
14466fc0178dSmrg# quote other shell meta-characters carefully to prevent them being
14476fc0178dSmrg# expanded when the contents are evaled.
14486fc0178dSmrgusage='$progpath [OPTION]...'
14496fc0178dSmrg
14506fc0178dSmrg# Short help message in response to '-h' and '--help'.  Add to this or
14516fc0178dSmrg# override it after sourcing this library to reflect the full set of
14526fc0178dSmrg# options your script accepts.
14536fc0178dSmrgusage_message="\
14546fc0178dSmrg       --debug        enable verbose shell tracing
14556fc0178dSmrg   -W, --warnings=CATEGORY
14566fc0178dSmrg                      report the warnings falling in CATEGORY [all]
14576fc0178dSmrg   -v, --verbose      verbosely report processing
14586fc0178dSmrg       --version      print version information and exit
14596fc0178dSmrg   -h, --help         print short or long help message and exit
14606fc0178dSmrg"
14616fc0178dSmrg
14626fc0178dSmrg# Additional text appended to 'usage_message' in response to '--help'.
14636fc0178dSmrglong_help_message="
14646fc0178dSmrgWarning categories include:
14656fc0178dSmrg       'all'          show all warnings
14666fc0178dSmrg       'none'         turn off all the warnings
14676fc0178dSmrg       'error'        warnings are treated as fatal errors"
14686fc0178dSmrg
14696fc0178dSmrg# Help message printed before fatal option parsing errors.
14706fc0178dSmrgfatal_help="Try '\$progname --help' for more information."
14716fc0178dSmrg
14726fc0178dSmrg
14736fc0178dSmrg
14746fc0178dSmrg## ------------------------- ##
14756fc0178dSmrg## Hook function management. ##
14766fc0178dSmrg## ------------------------- ##
14776fc0178dSmrg
14786fc0178dSmrg# This section contains functions for adding, removing, and running hooks
14796fc0178dSmrg# to the main code.  A hook is just a named list of of function, that can
14806fc0178dSmrg# be run in order later on.
14816fc0178dSmrg
14826fc0178dSmrg# func_hookable FUNC_NAME
14836fc0178dSmrg# -----------------------
14846fc0178dSmrg# Declare that FUNC_NAME will run hooks added with
14856fc0178dSmrg# 'func_add_hook FUNC_NAME ...'.
14866fc0178dSmrgfunc_hookable ()
14876fc0178dSmrg{
14886fc0178dSmrg    $debug_cmd
14896fc0178dSmrg
14906fc0178dSmrg    func_append hookable_fns " $1"
14916fc0178dSmrg}
14926fc0178dSmrg
14936fc0178dSmrg
14946fc0178dSmrg# func_add_hook FUNC_NAME HOOK_FUNC
14956fc0178dSmrg# ---------------------------------
14966fc0178dSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
14976fc0178dSmrg# first have been declared "hookable" by a call to 'func_hookable'.
14986fc0178dSmrgfunc_add_hook ()
14996fc0178dSmrg{
15006fc0178dSmrg    $debug_cmd
15016fc0178dSmrg
15026fc0178dSmrg    case " $hookable_fns " in
15036fc0178dSmrg      *" $1 "*) ;;
15046fc0178dSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
15056fc0178dSmrg    esac
15066fc0178dSmrg
15076fc0178dSmrg    eval func_append ${1}_hooks '" $2"'
15086fc0178dSmrg}
15096fc0178dSmrg
15106fc0178dSmrg
15116fc0178dSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
15126fc0178dSmrg# ------------------------------------
15136fc0178dSmrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
15146fc0178dSmrgfunc_remove_hook ()
15156fc0178dSmrg{
15166fc0178dSmrg    $debug_cmd
15176fc0178dSmrg
15186fc0178dSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
15196fc0178dSmrg}
15206fc0178dSmrg
15216fc0178dSmrg
15226fc0178dSmrg# func_run_hooks FUNC_NAME [ARG]...
15236fc0178dSmrg# ---------------------------------
15246fc0178dSmrg# Run all hook functions registered to FUNC_NAME.
15256fc0178dSmrg# It is assumed that the list of hook functions contains nothing more
15266fc0178dSmrg# than a whitespace-delimited list of legal shell function names, and
15276fc0178dSmrg# no effort is wasted trying to catch shell meta-characters or preserve
15286fc0178dSmrg# whitespace.
15296fc0178dSmrgfunc_run_hooks ()
15306fc0178dSmrg{
15316fc0178dSmrg    $debug_cmd
15326fc0178dSmrg
15336fc0178dSmrg    case " $hookable_fns " in
15346fc0178dSmrg      *" $1 "*) ;;
15356fc0178dSmrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
15366fc0178dSmrg    esac
15376fc0178dSmrg
15386fc0178dSmrg    eval _G_hook_fns=\$$1_hooks; shift
15396fc0178dSmrg
15406fc0178dSmrg    for _G_hook in $_G_hook_fns; do
15416fc0178dSmrg      eval $_G_hook '"$@"'
15426fc0178dSmrg
15436fc0178dSmrg      # store returned options list back into positional
15446fc0178dSmrg      # parameters for next 'cmd' execution.
15456fc0178dSmrg      eval _G_hook_result=\$${_G_hook}_result
15466fc0178dSmrg      eval set dummy "$_G_hook_result"; shift
15476fc0178dSmrg    done
15486fc0178dSmrg
15496fc0178dSmrg    func_quote_for_eval ${1+"$@"}
15506fc0178dSmrg    func_run_hooks_result=$func_quote_for_eval_result
15516fc0178dSmrg}
15526fc0178dSmrg
15536fc0178dSmrg
15546fc0178dSmrg
15556fc0178dSmrg## --------------- ##
15566fc0178dSmrg## Option parsing. ##
15576fc0178dSmrg## --------------- ##
15586fc0178dSmrg
15596fc0178dSmrg# In order to add your own option parsing hooks, you must accept the
15606fc0178dSmrg# full positional parameter list in your hook function, remove any
15616fc0178dSmrg# options that you action, and then pass back the remaining unprocessed
15626fc0178dSmrg# options in '<hooked_function_name>_result', escaped suitably for
15636fc0178dSmrg# 'eval'.  Like this:
15646fc0178dSmrg#
15656fc0178dSmrg#    my_options_prep ()
15666fc0178dSmrg#    {
15676fc0178dSmrg#        $debug_cmd
15686fc0178dSmrg#
15696fc0178dSmrg#        # Extend the existing usage message.
15706fc0178dSmrg#        usage_message=$usage_message'
15716fc0178dSmrg#      -s, --silent       don'\''t print informational messages
15726fc0178dSmrg#    '
15736fc0178dSmrg#
15746fc0178dSmrg#        func_quote_for_eval ${1+"$@"}
15756fc0178dSmrg#        my_options_prep_result=$func_quote_for_eval_result
15766fc0178dSmrg#    }
15776fc0178dSmrg#    func_add_hook func_options_prep my_options_prep
15786fc0178dSmrg#
15796fc0178dSmrg#
15806fc0178dSmrg#    my_silent_option ()
15816fc0178dSmrg#    {
15826fc0178dSmrg#        $debug_cmd
15836fc0178dSmrg#
15846fc0178dSmrg#        # Note that for efficiency, we parse as many options as we can
15856fc0178dSmrg#        # recognise in a loop before passing the remainder back to the
15866fc0178dSmrg#        # caller on the first unrecognised argument we encounter.
15876fc0178dSmrg#        while test $# -gt 0; do
15886fc0178dSmrg#          opt=$1; shift
15896fc0178dSmrg#          case $opt in
15906fc0178dSmrg#            --silent|-s) opt_silent=: ;;
15916fc0178dSmrg#            # Separate non-argument short options:
15926fc0178dSmrg#            -s*)         func_split_short_opt "$_G_opt"
15936fc0178dSmrg#                         set dummy "$func_split_short_opt_name" \
15946fc0178dSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
15956fc0178dSmrg#                         shift
15966fc0178dSmrg#                         ;;
15976fc0178dSmrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
15986fc0178dSmrg#          esac
15996fc0178dSmrg#        done
16006fc0178dSmrg#
16016fc0178dSmrg#        func_quote_for_eval ${1+"$@"}
16026fc0178dSmrg#        my_silent_option_result=$func_quote_for_eval_result
16036fc0178dSmrg#    }
16046fc0178dSmrg#    func_add_hook func_parse_options my_silent_option
16056fc0178dSmrg#
16066fc0178dSmrg#
16076fc0178dSmrg#    my_option_validation ()
16086fc0178dSmrg#    {
16096fc0178dSmrg#        $debug_cmd
16106fc0178dSmrg#
16116fc0178dSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
16126fc0178dSmrg#    '--silent' and '--verbose' options are mutually exclusive."
16136fc0178dSmrg#
16146fc0178dSmrg#        func_quote_for_eval ${1+"$@"}
16156fc0178dSmrg#        my_option_validation_result=$func_quote_for_eval_result
16166fc0178dSmrg#    }
16176fc0178dSmrg#    func_add_hook func_validate_options my_option_validation
16186fc0178dSmrg#
16196fc0178dSmrg# You'll alse need to manually amend $usage_message to reflect the extra
16206fc0178dSmrg# options you parse.  It's preferable to append if you can, so that
16216fc0178dSmrg# multiple option parsing hooks can be added safely.
16226fc0178dSmrg
16236fc0178dSmrg
16246fc0178dSmrg# func_options [ARG]...
16256fc0178dSmrg# ---------------------
16266fc0178dSmrg# All the functions called inside func_options are hookable. See the
16276fc0178dSmrg# individual implementations for details.
16286fc0178dSmrgfunc_hookable func_options
16296fc0178dSmrgfunc_options ()
16306fc0178dSmrg{
16316fc0178dSmrg    $debug_cmd
16326fc0178dSmrg
16336fc0178dSmrg    func_options_prep ${1+"$@"}
16346fc0178dSmrg    eval func_parse_options \
16356fc0178dSmrg        ${func_options_prep_result+"$func_options_prep_result"}
16366fc0178dSmrg    eval func_validate_options \
16376fc0178dSmrg        ${func_parse_options_result+"$func_parse_options_result"}
16386fc0178dSmrg
16396fc0178dSmrg    eval func_run_hooks func_options \
16406fc0178dSmrg        ${func_validate_options_result+"$func_validate_options_result"}
16416fc0178dSmrg
16426fc0178dSmrg    # save modified positional parameters for caller
16436fc0178dSmrg    func_options_result=$func_run_hooks_result
1644ff559fabSmrg}
1645ff559fabSmrg
1646ff559fabSmrg
16476fc0178dSmrg# func_options_prep [ARG]...
16486fc0178dSmrg# --------------------------
16496fc0178dSmrg# All initialisations required before starting the option parse loop.
16506fc0178dSmrg# Note that when calling hook functions, we pass through the list of
16516fc0178dSmrg# positional parameters.  If a hook function modifies that list, and
16526fc0178dSmrg# needs to propogate that back to rest of this script, then the complete
16536fc0178dSmrg# modified list must be put in 'func_run_hooks_result' before
16546fc0178dSmrg# returning.
16556fc0178dSmrgfunc_hookable func_options_prep
16566fc0178dSmrgfunc_options_prep ()
1657ff559fabSmrg{
16586fc0178dSmrg    $debug_cmd
16597a3b38f7Smrg
16606fc0178dSmrg    # Option defaults:
16616fc0178dSmrg    opt_verbose=false
16626fc0178dSmrg    opt_warning_types=
16636fc0178dSmrg
16646fc0178dSmrg    func_run_hooks func_options_prep ${1+"$@"}
16656fc0178dSmrg
16666fc0178dSmrg    # save modified positional parameters for caller
16676fc0178dSmrg    func_options_prep_result=$func_run_hooks_result
1668ff559fabSmrg}
1669ff559fabSmrg
1670ff559fabSmrg
16716fc0178dSmrg# func_parse_options [ARG]...
16726fc0178dSmrg# ---------------------------
16736fc0178dSmrg# The main option parsing loop.
16746fc0178dSmrgfunc_hookable func_parse_options
16756fc0178dSmrgfunc_parse_options ()
1676ff559fabSmrg{
16776fc0178dSmrg    $debug_cmd
16787a3b38f7Smrg
16796fc0178dSmrg    func_parse_options_result=
16807a3b38f7Smrg
16816fc0178dSmrg    # this just eases exit handling
16826fc0178dSmrg    while test $# -gt 0; do
16836fc0178dSmrg      # Defer to hook functions for initial option parsing, so they
16846fc0178dSmrg      # get priority in the event of reusing an option name.
16856fc0178dSmrg      func_run_hooks func_parse_options ${1+"$@"}
1686ff559fabSmrg
16876fc0178dSmrg      # Adjust func_parse_options positional parameters to match
16886fc0178dSmrg      eval set dummy "$func_run_hooks_result"; shift
1689ff559fabSmrg
16906fc0178dSmrg      # Break out of the loop if we already parsed every option.
16916fc0178dSmrg      test $# -gt 0 || break
1692ff559fabSmrg
16936fc0178dSmrg      _G_opt=$1
16946fc0178dSmrg      shift
16956fc0178dSmrg      case $_G_opt in
16966fc0178dSmrg        --debug|-x)   debug_cmd='set -x'
16976fc0178dSmrg                      func_echo "enabling shell trace mode"
16986fc0178dSmrg                      $debug_cmd
16996fc0178dSmrg                      ;;
17006fc0178dSmrg
17016fc0178dSmrg        --no-warnings|--no-warning|--no-warn)
17026fc0178dSmrg                      set dummy --warnings none ${1+"$@"}
17036fc0178dSmrg                      shift
17046fc0178dSmrg		      ;;
17057a3b38f7Smrg
17066fc0178dSmrg        --warnings|--warning|-W)
17076fc0178dSmrg                      test $# = 0 && func_missing_arg $_G_opt && break
17086fc0178dSmrg                      case " $warning_categories $1" in
17096fc0178dSmrg                        *" $1 "*)
17106fc0178dSmrg                          # trailing space prevents matching last $1 above
17116fc0178dSmrg                          func_append_uniq opt_warning_types " $1"
17126fc0178dSmrg                          ;;
17136fc0178dSmrg                        *all)
17146fc0178dSmrg                          opt_warning_types=$warning_categories
17156fc0178dSmrg                          ;;
17166fc0178dSmrg                        *none)
17176fc0178dSmrg                          opt_warning_types=none
17186fc0178dSmrg                          warning_func=:
17196fc0178dSmrg                          ;;
17206fc0178dSmrg                        *error)
17216fc0178dSmrg                          opt_warning_types=$warning_categories
17226fc0178dSmrg                          warning_func=func_fatal_error
17236fc0178dSmrg                          ;;
17246fc0178dSmrg                        *)
17256fc0178dSmrg                          func_fatal_error \
17266fc0178dSmrg                             "unsupported warning category: '$1'"
17276fc0178dSmrg                          ;;
17286fc0178dSmrg                      esac
17296fc0178dSmrg                      shift
17306fc0178dSmrg                      ;;
17316fc0178dSmrg
17326fc0178dSmrg        --verbose|-v) opt_verbose=: ;;
17336fc0178dSmrg        --version)    func_version ;;
17346fc0178dSmrg        -\?|-h)       func_usage ;;
17356fc0178dSmrg        --help)       func_help ;;
17366fc0178dSmrg
17376fc0178dSmrg	# Separate optargs to long options (plugins may need this):
17386fc0178dSmrg	--*=*)        func_split_equals "$_G_opt"
17396fc0178dSmrg	              set dummy "$func_split_equals_lhs" \
17406fc0178dSmrg                          "$func_split_equals_rhs" ${1+"$@"}
17416fc0178dSmrg                      shift
17426fc0178dSmrg                      ;;
17436fc0178dSmrg
17446fc0178dSmrg       # Separate optargs to short options:
17456fc0178dSmrg        -W*)
17466fc0178dSmrg                      func_split_short_opt "$_G_opt"
17476fc0178dSmrg                      set dummy "$func_split_short_opt_name" \
17486fc0178dSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
17496fc0178dSmrg                      shift
17506fc0178dSmrg                      ;;
17516fc0178dSmrg
17526fc0178dSmrg        # Separate non-argument short options:
17536fc0178dSmrg        -\?*|-h*|-v*|-x*)
17546fc0178dSmrg                      func_split_short_opt "$_G_opt"
17556fc0178dSmrg                      set dummy "$func_split_short_opt_name" \
17566fc0178dSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
17576fc0178dSmrg                      shift
17586fc0178dSmrg                      ;;
17596fc0178dSmrg
17606fc0178dSmrg        --)           break ;;
17616fc0178dSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
17626fc0178dSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17636fc0178dSmrg      esac
17646fc0178dSmrg    done
17656fc0178dSmrg
17666fc0178dSmrg    # save modified positional parameters for caller
17676fc0178dSmrg    func_quote_for_eval ${1+"$@"}
17686fc0178dSmrg    func_parse_options_result=$func_quote_for_eval_result
1769ff559fabSmrg}
1770ff559fabSmrg
17717a3b38f7Smrg
17726fc0178dSmrg# func_validate_options [ARG]...
17736fc0178dSmrg# ------------------------------
17746fc0178dSmrg# Perform any sanity checks on option settings and/or unconsumed
17756fc0178dSmrg# arguments.
17766fc0178dSmrgfunc_hookable func_validate_options
17776fc0178dSmrgfunc_validate_options ()
1778ff559fabSmrg{
17796fc0178dSmrg    $debug_cmd
1780ff559fabSmrg
17816fc0178dSmrg    # Display all warnings if -W was not given.
17826fc0178dSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
17837a3b38f7Smrg
17846fc0178dSmrg    func_run_hooks func_validate_options ${1+"$@"}
1785ff559fabSmrg
17866fc0178dSmrg    # Bail if the options were screwed!
17876fc0178dSmrg    $exit_cmd $EXIT_FAILURE
17886fc0178dSmrg
17896fc0178dSmrg    # save modified positional parameters for caller
17906fc0178dSmrg    func_validate_options_result=$func_run_hooks_result
1791862f5301Smrg}
1792862f5301Smrg
1793ff559fabSmrg
1794862f5301Smrg
17956fc0178dSmrg## ----------------- ##
17966fc0178dSmrg## Helper functions. ##
17976fc0178dSmrg## ----------------- ##
17987a3b38f7Smrg
17996fc0178dSmrg# This section contains the helper functions used by the rest of the
18006fc0178dSmrg# hookable option parser framework in ascii-betical order.
18016fc0178dSmrg
18026fc0178dSmrg
18036fc0178dSmrg# func_fatal_help ARG...
18046fc0178dSmrg# ----------------------
18056fc0178dSmrg# Echo program name prefixed message to standard error, followed by
18066fc0178dSmrg# a help hint, and exit.
18076fc0178dSmrgfunc_fatal_help ()
18087a3b38f7Smrg{
18096fc0178dSmrg    $debug_cmd
1810862f5301Smrg
18116fc0178dSmrg    eval \$ECHO \""Usage: $usage"\"
18126fc0178dSmrg    eval \$ECHO \""$fatal_help"\"
18136fc0178dSmrg    func_error ${1+"$@"}
18146fc0178dSmrg    exit $EXIT_FAILURE
18157a3b38f7Smrg}
18167a3b38f7Smrg
18176fc0178dSmrg
18186fc0178dSmrg# func_help
18196fc0178dSmrg# ---------
18206fc0178dSmrg# Echo long help message to standard output and exit.
18217a3b38f7Smrgfunc_help ()
18227a3b38f7Smrg{
18236fc0178dSmrg    $debug_cmd
18246fc0178dSmrg
18256fc0178dSmrg    func_usage_message
18266fc0178dSmrg    $ECHO "$long_help_message"
18276fc0178dSmrg    exit 0
18287a3b38f7Smrg}
18297a3b38f7Smrg
18306fc0178dSmrg
18316fc0178dSmrg# func_missing_arg ARGNAME
18326fc0178dSmrg# ------------------------
18337a3b38f7Smrg# Echo program name prefixed message to standard error and set global
18347a3b38f7Smrg# exit_cmd.
18357a3b38f7Smrgfunc_missing_arg ()
18367a3b38f7Smrg{
18376fc0178dSmrg    $debug_cmd
1838862f5301Smrg
18396fc0178dSmrg    func_error "Missing argument for '$1'."
18407a3b38f7Smrg    exit_cmd=exit
18417a3b38f7Smrg}
18427a3b38f7Smrg
18437a3b38f7Smrg
18446fc0178dSmrg# func_split_equals STRING
18456fc0178dSmrg# ------------------------
18466fc0178dSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
18476fc0178dSmrg# splitting STRING at the '=' sign.
18486fc0178dSmrgtest -z "$_G_HAVE_XSI_OPS" \
18496fc0178dSmrg    && (eval 'x=a/b/c;
18506fc0178dSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
18516fc0178dSmrg    && _G_HAVE_XSI_OPS=yes
18526fc0178dSmrg
18536fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"
18546fc0178dSmrgthen
18556fc0178dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
18566fc0178dSmrg  eval 'func_split_equals ()
18576fc0178dSmrg  {
18586fc0178dSmrg      $debug_cmd
18596fc0178dSmrg
18606fc0178dSmrg      func_split_equals_lhs=${1%%=*}
18616fc0178dSmrg      func_split_equals_rhs=${1#*=}
18626fc0178dSmrg      test "x$func_split_equals_lhs" = "x$1" \
18636fc0178dSmrg        && func_split_equals_rhs=
18646fc0178dSmrg  }'
18656fc0178dSmrgelse
18666fc0178dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
18676fc0178dSmrg  func_split_equals ()
18686fc0178dSmrg  {
18696fc0178dSmrg      $debug_cmd
18706fc0178dSmrg
18716fc0178dSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
18726fc0178dSmrg      func_split_equals_rhs=
18736fc0178dSmrg      test "x$func_split_equals_lhs" = "x$1" \
18746fc0178dSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
18756fc0178dSmrg  }
18766fc0178dSmrgfi #func_split_equals
18776fc0178dSmrg
18786fc0178dSmrg
18796fc0178dSmrg# func_split_short_opt SHORTOPT
18806fc0178dSmrg# -----------------------------
1881862f5301Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
1882862f5301Smrg# variables after splitting SHORTOPT after the 2nd character.
18836fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"
18846fc0178dSmrgthen
18856fc0178dSmrg  # This is an XSI compatible shell, allowing a faster implementation...
18866fc0178dSmrg  eval 'func_split_short_opt ()
18876fc0178dSmrg  {
18886fc0178dSmrg      $debug_cmd
18896fc0178dSmrg
18906fc0178dSmrg      func_split_short_opt_arg=${1#??}
18916fc0178dSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
18926fc0178dSmrg  }'
18936fc0178dSmrgelse
18946fc0178dSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
18956fc0178dSmrg  func_split_short_opt ()
18966fc0178dSmrg  {
18976fc0178dSmrg      $debug_cmd
18986fc0178dSmrg
18996fc0178dSmrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
19006fc0178dSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
19016fc0178dSmrg  }
19026fc0178dSmrgfi #func_split_short_opt
19036fc0178dSmrg
19046fc0178dSmrg
19056fc0178dSmrg# func_usage
19066fc0178dSmrg# ----------
19076fc0178dSmrg# Echo short help message to standard output and exit.
19086fc0178dSmrgfunc_usage ()
1909862f5301Smrg{
19106fc0178dSmrg    $debug_cmd
1911862f5301Smrg
19126fc0178dSmrg    func_usage_message
19136fc0178dSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
19146fc0178dSmrg    exit 0
19156fc0178dSmrg}
1916862f5301Smrg
1917862f5301Smrg
19186fc0178dSmrg# func_usage_message
19196fc0178dSmrg# ------------------
19206fc0178dSmrg# Echo short help message to standard output.
19216fc0178dSmrgfunc_usage_message ()
1922862f5301Smrg{
19236fc0178dSmrg    $debug_cmd
1924862f5301Smrg
19256fc0178dSmrg    eval \$ECHO \""Usage: $usage"\"
19266fc0178dSmrg    echo
19276fc0178dSmrg    $SED -n 's|^# ||
19286fc0178dSmrg        /^Written by/{
19296fc0178dSmrg          x;p;x
19306fc0178dSmrg        }
19316fc0178dSmrg	h
19326fc0178dSmrg	/^Written by/q' < "$progpath"
19336fc0178dSmrg    echo
19346fc0178dSmrg    eval \$ECHO \""$usage_message"\"
19356fc0178dSmrg}
1936862f5301Smrg
19377a3b38f7Smrg
19386fc0178dSmrg# func_version
19396fc0178dSmrg# ------------
19406fc0178dSmrg# Echo version message to standard output and exit.
19416fc0178dSmrgfunc_version ()
19426fc0178dSmrg{
19436fc0178dSmrg    $debug_cmd
19447a3b38f7Smrg
19456fc0178dSmrg    printf '%s\n' "$progname $scriptversion"
19466fc0178dSmrg    $SED -n '
19476fc0178dSmrg        /(C)/!b go
19486fc0178dSmrg        :more
19496fc0178dSmrg        /\./!{
19506fc0178dSmrg          N
19516fc0178dSmrg          s|\n# | |
19526fc0178dSmrg          b more
19536fc0178dSmrg        }
19546fc0178dSmrg        :go
19556fc0178dSmrg        /^# Written by /,/# warranty; / {
19566fc0178dSmrg          s|^# ||
19576fc0178dSmrg          s|^# *$||
19586fc0178dSmrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
19596fc0178dSmrg          p
19606fc0178dSmrg        }
19616fc0178dSmrg        /^# Written by / {
19626fc0178dSmrg          s|^# ||
19636fc0178dSmrg          p
19646fc0178dSmrg        }
19656fc0178dSmrg        /^warranty; /q' < "$progpath"
19667a3b38f7Smrg
19676fc0178dSmrg    exit $?
19686fc0178dSmrg}
19697a3b38f7Smrg
1970ff559fabSmrg
19716fc0178dSmrg# Local variables:
19726fc0178dSmrg# mode: shell-script
19736fc0178dSmrg# sh-indentation: 2
19746fc0178dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
19756fc0178dSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
19766fc0178dSmrg# time-stamp-time-zone: "UTC"
19776fc0178dSmrg# End:
1978ff559fabSmrg
19796fc0178dSmrg# Set a version string.
19806fc0178dSmrgscriptversion='(GNU libtool) 2.4.6'
1981ff559fabSmrg
1982ff559fabSmrg
19836fc0178dSmrg# func_echo ARG...
19846fc0178dSmrg# ----------------
19856fc0178dSmrg# Libtool also displays the current mode in messages, so override
19866fc0178dSmrg# funclib.sh func_echo with this custom definition.
19876fc0178dSmrgfunc_echo ()
1988862f5301Smrg{
19896fc0178dSmrg    $debug_cmd
1990862f5301Smrg
19916fc0178dSmrg    _G_message=$*
1992862f5301Smrg
19936fc0178dSmrg    func_echo_IFS=$IFS
19946fc0178dSmrg    IFS=$nl
19956fc0178dSmrg    for _G_line in $_G_message; do
19966fc0178dSmrg      IFS=$func_echo_IFS
19976fc0178dSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
19986fc0178dSmrg    done
19996fc0178dSmrg    IFS=$func_echo_IFS
20006fc0178dSmrg}
2001862f5301Smrg
20026fc0178dSmrg
20036fc0178dSmrg# func_warning ARG...
20046fc0178dSmrg# -------------------
20056fc0178dSmrg# Libtool warnings are not categorized, so override funclib.sh
20066fc0178dSmrg# func_warning with this simpler definition.
20076fc0178dSmrgfunc_warning ()
2008862f5301Smrg{
20096fc0178dSmrg    $debug_cmd
2010862f5301Smrg
20116fc0178dSmrg    $warning_func ${1+"$@"}
20126fc0178dSmrg}
2013862f5301Smrg
2014862f5301Smrg
20156fc0178dSmrg## ---------------- ##
20166fc0178dSmrg## Options parsing. ##
20176fc0178dSmrg## ---------------- ##
20186fc0178dSmrg
20196fc0178dSmrg# Hook in the functions to make sure our own options are parsed during
20206fc0178dSmrg# the option parsing loop.
20216fc0178dSmrg
20226fc0178dSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
20236fc0178dSmrg
20246fc0178dSmrg# Short help message in response to '-h'.
20256fc0178dSmrgusage_message="Options:
20266fc0178dSmrg       --config             show all configuration variables
20276fc0178dSmrg       --debug              enable verbose shell tracing
20286fc0178dSmrg   -n, --dry-run            display commands without modifying any files
20296fc0178dSmrg       --features           display basic configuration information and exit
20306fc0178dSmrg       --mode=MODE          use operation mode MODE
20316fc0178dSmrg       --no-warnings        equivalent to '-Wnone'
20326fc0178dSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
20336fc0178dSmrg       --quiet, --silent    don't print informational messages
20346fc0178dSmrg       --tag=TAG            use configuration variables from tag TAG
20356fc0178dSmrg   -v, --verbose            print more informational messages than default
20366fc0178dSmrg       --version            print version information
20376fc0178dSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
20386fc0178dSmrg   -h, --help, --help-all   print short, long, or detailed help message
20396fc0178dSmrg"
2040862f5301Smrg
20416fc0178dSmrg# Additional text appended to 'usage_message' in response to '--help'.
20426fc0178dSmrgfunc_help ()
2043862f5301Smrg{
20446fc0178dSmrg    $debug_cmd
20456fc0178dSmrg
20466fc0178dSmrg    func_usage_message
20476fc0178dSmrg    $ECHO "$long_help_message
20486fc0178dSmrg
20496fc0178dSmrgMODE must be one of the following:
20506fc0178dSmrg
20516fc0178dSmrg       clean           remove files from the build directory
20526fc0178dSmrg       compile         compile a source file into a libtool object
20536fc0178dSmrg       execute         automatically set library path, then run a program
20546fc0178dSmrg       finish          complete the installation of libtool libraries
20556fc0178dSmrg       install         install libraries or executables
20566fc0178dSmrg       link            create a library or an executable
20576fc0178dSmrg       uninstall       remove libraries from an installed directory
20586fc0178dSmrg
20596fc0178dSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
20606fc0178dSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
20616fc0178dSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
20626fc0178dSmrg
20636fc0178dSmrgWhen reporting a bug, please describe a test case to reproduce it and
20646fc0178dSmrginclude the following information:
20656fc0178dSmrg
20666fc0178dSmrg       host-triplet:   $host
20676fc0178dSmrg       shell:          $SHELL
20686fc0178dSmrg       compiler:       $LTCC
20696fc0178dSmrg       compiler flags: $LTCFLAGS
20706fc0178dSmrg       linker:         $LD (gnu? $with_gnu_ld)
20716fc0178dSmrg       version:        $progname (GNU libtool) 2.4.6
20726fc0178dSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
20736fc0178dSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
20746fc0178dSmrg
20756fc0178dSmrgReport bugs to <bug-libtool@gnu.org>.
20766fc0178dSmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
20776fc0178dSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
20786fc0178dSmrg    exit 0
20796fc0178dSmrg}
2080862f5301Smrg
2081862f5301Smrg
20826fc0178dSmrg# func_lo2o OBJECT-NAME
20836fc0178dSmrg# ---------------------
20846fc0178dSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
20856fc0178dSmrg# object suffix.
20866fc0178dSmrg
20876fc0178dSmrglo2o=s/\\.lo\$/.$objext/
20886fc0178dSmrgo2lo=s/\\.$objext\$/.lo/
20896fc0178dSmrg
20906fc0178dSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
20916fc0178dSmrg  eval 'func_lo2o ()
20926fc0178dSmrg  {
20936fc0178dSmrg    case $1 in
20946fc0178dSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
20956fc0178dSmrg      *   ) func_lo2o_result=$1               ;;
20966fc0178dSmrg    esac
20976fc0178dSmrg  }'
20986fc0178dSmrg
20996fc0178dSmrg  # func_xform LIBOBJ-OR-SOURCE
21006fc0178dSmrg  # ---------------------------
21016fc0178dSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
21026fc0178dSmrg  # suffix to a '.lo' libtool-object suffix.
21036fc0178dSmrg  eval 'func_xform ()
21046fc0178dSmrg  {
21056fc0178dSmrg    func_xform_result=${1%.*}.lo
21066fc0178dSmrg  }'
21076fc0178dSmrgelse
21086fc0178dSmrg  # ...otherwise fall back to using sed.
21096fc0178dSmrg  func_lo2o ()
21106fc0178dSmrg  {
21116fc0178dSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
21126fc0178dSmrg  }
21136fc0178dSmrg
21146fc0178dSmrg  func_xform ()
21156fc0178dSmrg  {
21166fc0178dSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
21176fc0178dSmrg  }
21186fc0178dSmrgfi
2119862f5301Smrg
2120862f5301Smrg
21216fc0178dSmrg# func_fatal_configuration ARG...
21226fc0178dSmrg# -------------------------------
21237a3b38f7Smrg# Echo program name prefixed message to standard error, followed by
21247a3b38f7Smrg# a configuration failure hint, and exit.
21257a3b38f7Smrgfunc_fatal_configuration ()
21267a3b38f7Smrg{
21276fc0178dSmrg    func__fatal_error ${1+"$@"} \
21286fc0178dSmrg      "See the $PACKAGE documentation for more information." \
21296fc0178dSmrg      "Fatal configuration error."
21307a3b38f7Smrg}
21317a3b38f7Smrg
21327a3b38f7Smrg
21337a3b38f7Smrg# func_config
21346fc0178dSmrg# -----------
21357a3b38f7Smrg# Display the configuration for all the tags in this script.
21367a3b38f7Smrgfunc_config ()
21377a3b38f7Smrg{
21387a3b38f7Smrg    re_begincf='^# ### BEGIN LIBTOOL'
21397a3b38f7Smrg    re_endcf='^# ### END LIBTOOL'
21407a3b38f7Smrg
21417a3b38f7Smrg    # Default configuration.
21427a3b38f7Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2143ff559fabSmrg
2144ff559fabSmrg    # Now print the configurations for the tags.
2145ff559fabSmrg    for tagname in $taglist; do
21467a3b38f7Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2147ff559fabSmrg    done
2148ff559fabSmrg
21497a3b38f7Smrg    exit $?
21507a3b38f7Smrg}
2151ff559fabSmrg
21526fc0178dSmrg
21537a3b38f7Smrg# func_features
21546fc0178dSmrg# -------------
21557a3b38f7Smrg# Display the features supported by this script.
21567a3b38f7Smrgfunc_features ()
21577a3b38f7Smrg{
215844dda7b2Smrg    echo "host: $host"
21596fc0178dSmrg    if test yes = "$build_libtool_libs"; then
216044dda7b2Smrg      echo "enable shared libraries"
2161ff559fabSmrg    else
216244dda7b2Smrg      echo "disable shared libraries"
2163ff559fabSmrg    fi
21646fc0178dSmrg    if test yes = "$build_old_libs"; then
216544dda7b2Smrg      echo "enable static libraries"
2166ff559fabSmrg    else
216744dda7b2Smrg      echo "disable static libraries"
2168ff559fabSmrg    fi
21697a3b38f7Smrg
2170ff559fabSmrg    exit $?
21717a3b38f7Smrg}
21727a3b38f7Smrg
21736fc0178dSmrg
21746fc0178dSmrg# func_enable_tag TAGNAME
21756fc0178dSmrg# -----------------------
21767a3b38f7Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
21777a3b38f7Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
21787a3b38f7Smrg# variable here.
21797a3b38f7Smrgfunc_enable_tag ()
21807a3b38f7Smrg{
21816fc0178dSmrg    # Global variable:
21826fc0178dSmrg    tagname=$1
2183ff559fabSmrg
21846fc0178dSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
21856fc0178dSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
21866fc0178dSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2187ff559fabSmrg
21886fc0178dSmrg    # Validate tagname.
21896fc0178dSmrg    case $tagname in
21906fc0178dSmrg      *[!-_A-Za-z0-9,/]*)
21916fc0178dSmrg        func_fatal_error "invalid tag name: $tagname"
21926fc0178dSmrg        ;;
21936fc0178dSmrg    esac
2194ff559fabSmrg
21956fc0178dSmrg    # Don't test for the "default" C tag, as we know it's
21966fc0178dSmrg    # there but not specially marked.
21976fc0178dSmrg    case $tagname in
21986fc0178dSmrg        CC) ;;
21997a3b38f7Smrg    *)
22006fc0178dSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
22016fc0178dSmrg	  taglist="$taglist $tagname"
22026fc0178dSmrg
22036fc0178dSmrg	  # Evaluate the configuration.  Be careful to quote the path
22046fc0178dSmrg	  # and the sed script, to avoid splitting on whitespace, but
22056fc0178dSmrg	  # also don't use non-portable quotes within backquotes within
22066fc0178dSmrg	  # quotes we have to do it in 2 steps:
22076fc0178dSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
22086fc0178dSmrg	  eval "$extractedcf"
22096fc0178dSmrg        else
22106fc0178dSmrg	  func_error "ignoring unknown tag $tagname"
22116fc0178dSmrg        fi
22126fc0178dSmrg        ;;
22136fc0178dSmrg    esac
22147a3b38f7Smrg}
2215ff559fabSmrg
22166fc0178dSmrg
2217862f5301Smrg# func_check_version_match
22186fc0178dSmrg# ------------------------
2219862f5301Smrg# Ensure that we are using m4 macros, and libtool script from the same
2220862f5301Smrg# release of libtool.
2221862f5301Smrgfunc_check_version_match ()
22227a3b38f7Smrg{
22236fc0178dSmrg    if test "$package_revision" != "$macro_revision"; then
22246fc0178dSmrg      if test "$VERSION" != "$macro_version"; then
22256fc0178dSmrg        if test -z "$macro_version"; then
22266fc0178dSmrg          cat >&2 <<_LT_EOF
2227862f5301Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2228862f5301Smrg$progname: definition of this LT_INIT comes from an older release.
2229862f5301Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2230862f5301Smrg$progname: and run autoconf again.
2231862f5301Smrg_LT_EOF
22326fc0178dSmrg        else
22336fc0178dSmrg          cat >&2 <<_LT_EOF
2234862f5301Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2235862f5301Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2236862f5301Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2237862f5301Smrg$progname: and run autoconf again.
2238862f5301Smrg_LT_EOF
22396fc0178dSmrg        fi
22406fc0178dSmrg      else
22416fc0178dSmrg        cat >&2 <<_LT_EOF
2242862f5301Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2243862f5301Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2244862f5301Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2245862f5301Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
2246862f5301Smrg_LT_EOF
22476fc0178dSmrg      fi
2248ff559fabSmrg
22496fc0178dSmrg      exit $EXIT_MISMATCH
22506fc0178dSmrg    fi
2251862f5301Smrg}
2252862f5301Smrg
2253862f5301Smrg
22546fc0178dSmrg# libtool_options_prep [ARG]...
22556fc0178dSmrg# -----------------------------
22566fc0178dSmrg# Preparation for options parsed by libtool.
22576fc0178dSmrglibtool_options_prep ()
22586fc0178dSmrg{
22596fc0178dSmrg    $debug_mode
2260ff559fabSmrg
22616fc0178dSmrg    # Option defaults:
22626fc0178dSmrg    opt_config=false
22636fc0178dSmrg    opt_dlopen=
22646fc0178dSmrg    opt_dry_run=false
22656fc0178dSmrg    opt_help=false
22666fc0178dSmrg    opt_mode=
22676fc0178dSmrg    opt_preserve_dup_deps=false
22686fc0178dSmrg    opt_quiet=false
2269862f5301Smrg
22706fc0178dSmrg    nonopt=
22716fc0178dSmrg    preserve_args=
2272862f5301Smrg
22736fc0178dSmrg    # Shorthand for --mode=foo, only valid as the first argument
22746fc0178dSmrg    case $1 in
22756fc0178dSmrg    clean|clea|cle|cl)
22766fc0178dSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
22776fc0178dSmrg      ;;
22786fc0178dSmrg    compile|compil|compi|comp|com|co|c)
22796fc0178dSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
22806fc0178dSmrg      ;;
22816fc0178dSmrg    execute|execut|execu|exec|exe|ex|e)
22826fc0178dSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
22836fc0178dSmrg      ;;
22846fc0178dSmrg    finish|finis|fini|fin|fi|f)
22856fc0178dSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
22866fc0178dSmrg      ;;
22876fc0178dSmrg    install|instal|insta|inst|ins|in|i)
22886fc0178dSmrg      shift; set dummy --mode install ${1+"$@"}; shift
22896fc0178dSmrg      ;;
22906fc0178dSmrg    link|lin|li|l)
22916fc0178dSmrg      shift; set dummy --mode link ${1+"$@"}; shift
22926fc0178dSmrg      ;;
22936fc0178dSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
22946fc0178dSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
22956fc0178dSmrg      ;;
22966fc0178dSmrg    esac
22976fc0178dSmrg
22986fc0178dSmrg    # Pass back the list of options.
22996fc0178dSmrg    func_quote_for_eval ${1+"$@"}
23006fc0178dSmrg    libtool_options_prep_result=$func_quote_for_eval_result
23016fc0178dSmrg}
23026fc0178dSmrgfunc_add_hook func_options_prep libtool_options_prep
2303862f5301Smrg
2304862f5301Smrg
23056fc0178dSmrg# libtool_parse_options [ARG]...
23066fc0178dSmrg# ---------------------------------
23076fc0178dSmrg# Provide handling for libtool specific options.
23086fc0178dSmrglibtool_parse_options ()
2309862f5301Smrg{
23106fc0178dSmrg    $debug_cmd
23117a3b38f7Smrg
23126fc0178dSmrg    # Perform our own loop to consume as many options as possible in
23136fc0178dSmrg    # each iteration.
23146fc0178dSmrg    while test $# -gt 0; do
23156fc0178dSmrg      _G_opt=$1
23166fc0178dSmrg      shift
23176fc0178dSmrg      case $_G_opt in
23186fc0178dSmrg        --dry-run|--dryrun|-n)
23196fc0178dSmrg                        opt_dry_run=:
23206fc0178dSmrg                        ;;
23216fc0178dSmrg
23226fc0178dSmrg        --config)       func_config ;;
23236fc0178dSmrg
23246fc0178dSmrg        --dlopen|-dlopen)
23256fc0178dSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
23266fc0178dSmrg}$1"
23276fc0178dSmrg                        shift
23286fc0178dSmrg                        ;;
23296fc0178dSmrg
23306fc0178dSmrg        --preserve-dup-deps)
23316fc0178dSmrg                        opt_preserve_dup_deps=: ;;
23326fc0178dSmrg
23336fc0178dSmrg        --features)     func_features ;;
23346fc0178dSmrg
23356fc0178dSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
23366fc0178dSmrg
23376fc0178dSmrg        --help)         opt_help=: ;;
23386fc0178dSmrg
23396fc0178dSmrg        --help-all)     opt_help=': help-all' ;;
23406fc0178dSmrg
23416fc0178dSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
23426fc0178dSmrg                        opt_mode=$1
23436fc0178dSmrg                        case $1 in
23446fc0178dSmrg                          # Valid mode arguments:
23456fc0178dSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
23466fc0178dSmrg
23476fc0178dSmrg                          # Catch anything else as an error
23486fc0178dSmrg                          *) func_error "invalid argument for $_G_opt"
23496fc0178dSmrg                             exit_cmd=exit
23506fc0178dSmrg                             break
23516fc0178dSmrg                             ;;
23526fc0178dSmrg                        esac
23536fc0178dSmrg                        shift
23546fc0178dSmrg                        ;;
23556fc0178dSmrg
23566fc0178dSmrg        --no-silent|--no-quiet)
23576fc0178dSmrg                        opt_quiet=false
23586fc0178dSmrg                        func_append preserve_args " $_G_opt"
23596fc0178dSmrg                        ;;
23606fc0178dSmrg
23616fc0178dSmrg        --no-warnings|--no-warning|--no-warn)
23626fc0178dSmrg                        opt_warning=false
23636fc0178dSmrg                        func_append preserve_args " $_G_opt"
23646fc0178dSmrg                        ;;
23656fc0178dSmrg
23666fc0178dSmrg        --no-verbose)
23676fc0178dSmrg                        opt_verbose=false
23686fc0178dSmrg                        func_append preserve_args " $_G_opt"
23696fc0178dSmrg                        ;;
23706fc0178dSmrg
23716fc0178dSmrg        --silent|--quiet)
23726fc0178dSmrg                        opt_quiet=:
23736fc0178dSmrg                        opt_verbose=false
23746fc0178dSmrg                        func_append preserve_args " $_G_opt"
23756fc0178dSmrg                        ;;
23766fc0178dSmrg
23776fc0178dSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
23786fc0178dSmrg                        opt_tag=$1
23796fc0178dSmrg                        func_append preserve_args " $_G_opt $1"
23806fc0178dSmrg                        func_enable_tag "$1"
23816fc0178dSmrg                        shift
23826fc0178dSmrg                        ;;
23836fc0178dSmrg
23846fc0178dSmrg        --verbose|-v)   opt_quiet=false
23856fc0178dSmrg                        opt_verbose=:
23866fc0178dSmrg                        func_append preserve_args " $_G_opt"
23876fc0178dSmrg                        ;;
23886fc0178dSmrg
23896fc0178dSmrg	# An option not handled by this hook function:
23906fc0178dSmrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
23916fc0178dSmrg      esac
23926fc0178dSmrg    done
2393862f5301Smrg
2394862f5301Smrg
23956fc0178dSmrg    # save modified positional parameters for caller
23966fc0178dSmrg    func_quote_for_eval ${1+"$@"}
23976fc0178dSmrg    libtool_parse_options_result=$func_quote_for_eval_result
23986fc0178dSmrg}
23996fc0178dSmrgfunc_add_hook func_parse_options libtool_parse_options
24007a3b38f7Smrg
2401ff559fabSmrg
24027a3b38f7Smrg
24036fc0178dSmrg# libtool_validate_options [ARG]...
24046fc0178dSmrg# ---------------------------------
24056fc0178dSmrg# Perform any sanity checks on option settings and/or unconsumed
24066fc0178dSmrg# arguments.
24076fc0178dSmrglibtool_validate_options ()
24086fc0178dSmrg{
24096fc0178dSmrg    # save first non-option argument
24106fc0178dSmrg    if test 0 -lt $#; then
24116fc0178dSmrg      nonopt=$1
24126fc0178dSmrg      shift
24137a3b38f7Smrg    fi
24147a3b38f7Smrg
24156fc0178dSmrg    # preserve --debug
24166fc0178dSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
24177a3b38f7Smrg
24186fc0178dSmrg    case $host in
24196fc0178dSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
24206fc0178dSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
24216fc0178dSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
24226fc0178dSmrg        # don't eliminate duplications in $postdeps and $predeps
24236fc0178dSmrg        opt_duplicate_compiler_generated_deps=:
24246fc0178dSmrg        ;;
24256fc0178dSmrg      *)
24266fc0178dSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
24276fc0178dSmrg        ;;
24286fc0178dSmrg    esac
24297a3b38f7Smrg
24306fc0178dSmrg    $opt_help || {
24316fc0178dSmrg      # Sanity checks first:
24326fc0178dSmrg      func_check_version_match
24336fc0178dSmrg
24346fc0178dSmrg      test yes != "$build_libtool_libs" \
24356fc0178dSmrg        && test yes != "$build_old_libs" \
24366fc0178dSmrg        && func_fatal_configuration "not configured to build any kind of library"
24376fc0178dSmrg
24386fc0178dSmrg      # Darwin sucks
24396fc0178dSmrg      eval std_shrext=\"$shrext_cmds\"
24406fc0178dSmrg
24416fc0178dSmrg      # Only execute mode is allowed to have -dlopen flags.
24426fc0178dSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
24436fc0178dSmrg        func_error "unrecognized option '-dlopen'"
24446fc0178dSmrg        $ECHO "$help" 1>&2
24456fc0178dSmrg        exit $EXIT_FAILURE
24466fc0178dSmrg      fi
24477a3b38f7Smrg
24486fc0178dSmrg      # Change the help message to a mode-specific one.
24496fc0178dSmrg      generic_help=$help
24506fc0178dSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
24516fc0178dSmrg    }
24527a3b38f7Smrg
24536fc0178dSmrg    # Pass back the unparsed argument list
24546fc0178dSmrg    func_quote_for_eval ${1+"$@"}
24556fc0178dSmrg    libtool_validate_options_result=$func_quote_for_eval_result
2456862f5301Smrg}
24576fc0178dSmrgfunc_add_hook func_validate_options libtool_validate_options
24587a3b38f7Smrg
24597a3b38f7Smrg
24606fc0178dSmrg# Process options as early as possible so that --help and --version
24616fc0178dSmrg# can return quickly.
24626fc0178dSmrgfunc_options ${1+"$@"}
24636fc0178dSmrgeval set dummy "$func_options_result"; shift
24646fc0178dSmrg
2465ff559fabSmrg
2466ff559fabSmrg
2467862f5301Smrg## ----------- ##
2468862f5301Smrg##    Main.    ##
2469862f5301Smrg## ----------- ##
2470ff559fabSmrg
24716fc0178dSmrgmagic='%%%MAGIC variable%%%'
24726fc0178dSmrgmagic_exe='%%%MAGIC EXE variable%%%'
24736fc0178dSmrg
24746fc0178dSmrg# Global variables.
24756fc0178dSmrgextracted_archives=
24766fc0178dSmrgextracted_serial=0
24776fc0178dSmrg
24786fc0178dSmrg# If this variable is set in any of the actions, the command in it
24796fc0178dSmrg# will be execed at the end.  This prevents here-documents from being
24806fc0178dSmrg# left over by shells.
24816fc0178dSmrgexec_cmd=
24826fc0178dSmrg
24836fc0178dSmrg
24846fc0178dSmrg# A function that is used when there is no print builtin or printf.
24856fc0178dSmrgfunc_fallback_echo ()
24866fc0178dSmrg{
24876fc0178dSmrg  eval 'cat <<_LTECHO_EOF
24886fc0178dSmrg$1
24896fc0178dSmrg_LTECHO_EOF'
24906fc0178dSmrg}
24916fc0178dSmrg
24926fc0178dSmrg# func_generated_by_libtool
24936fc0178dSmrg# True iff stdin has been generated by Libtool. This function is only
24946fc0178dSmrg# a basic sanity check; it will hardly flush out determined imposters.
24956fc0178dSmrgfunc_generated_by_libtool_p ()
24966fc0178dSmrg{
24976fc0178dSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
24986fc0178dSmrg}
24996fc0178dSmrg
25007a3b38f7Smrg# func_lalib_p file
25016fc0178dSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
25027a3b38f7Smrg# This function is only a basic sanity check; it will hardly flush out
25037a3b38f7Smrg# determined imposters.
25047a3b38f7Smrgfunc_lalib_p ()
25057a3b38f7Smrg{
25067a3b38f7Smrg    test -f "$1" &&
25076fc0178dSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
25087a3b38f7Smrg}
2509ff559fabSmrg
25107a3b38f7Smrg# func_lalib_unsafe_p file
25116fc0178dSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
25127a3b38f7Smrg# This function implements the same check as func_lalib_p without
25137a3b38f7Smrg# resorting to external programs.  To this end, it redirects stdin and
25147a3b38f7Smrg# closes it afterwards, without saving the original file descriptor.
25157a3b38f7Smrg# As a safety measure, use it only where a negative result would be
25166fc0178dSmrg# fatal anyway.  Works if 'file' does not exist.
25177a3b38f7Smrgfunc_lalib_unsafe_p ()
25187a3b38f7Smrg{
25197a3b38f7Smrg    lalib_p=no
25207a3b38f7Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
25217a3b38f7Smrg	for lalib_p_l in 1 2 3 4
25227a3b38f7Smrg	do
25237a3b38f7Smrg	    read lalib_p_line
25246fc0178dSmrg	    case $lalib_p_line in
25257a3b38f7Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
25267a3b38f7Smrg	    esac
25277a3b38f7Smrg	done
25287a3b38f7Smrg	exec 0<&5 5<&-
25297a3b38f7Smrg    fi
25306fc0178dSmrg    test yes = "$lalib_p"
25317a3b38f7Smrg}
2532ff559fabSmrg
25337a3b38f7Smrg# func_ltwrapper_script_p file
25347a3b38f7Smrg# True iff FILE is a libtool wrapper script
25357a3b38f7Smrg# This function is only a basic sanity check; it will hardly flush out
25367a3b38f7Smrg# determined imposters.
25377a3b38f7Smrgfunc_ltwrapper_script_p ()
25387a3b38f7Smrg{
25396fc0178dSmrg    test -f "$1" &&
25406fc0178dSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
25417a3b38f7Smrg}
2542ff559fabSmrg
25437a3b38f7Smrg# func_ltwrapper_executable_p file
25447a3b38f7Smrg# True iff FILE is a libtool wrapper executable
25457a3b38f7Smrg# This function is only a basic sanity check; it will hardly flush out
25467a3b38f7Smrg# determined imposters.
25477a3b38f7Smrgfunc_ltwrapper_executable_p ()
25487a3b38f7Smrg{
25497a3b38f7Smrg    func_ltwrapper_exec_suffix=
25507a3b38f7Smrg    case $1 in
25517a3b38f7Smrg    *.exe) ;;
25527a3b38f7Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
25537a3b38f7Smrg    esac
25547a3b38f7Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
25557a3b38f7Smrg}
2556ff559fabSmrg
25577a3b38f7Smrg# func_ltwrapper_scriptname file
25587a3b38f7Smrg# Assumes file is an ltwrapper_executable
25597a3b38f7Smrg# uses $file to determine the appropriate filename for a
25607a3b38f7Smrg# temporary ltwrapper_script.
25617a3b38f7Smrgfunc_ltwrapper_scriptname ()
25627a3b38f7Smrg{
2563862f5301Smrg    func_dirname_and_basename "$1" "" "."
2564862f5301Smrg    func_stripname '' '.exe' "$func_basename_result"
25656fc0178dSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
25667a3b38f7Smrg}
2567ff559fabSmrg
25687a3b38f7Smrg# func_ltwrapper_p file
25697a3b38f7Smrg# True iff FILE is a libtool wrapper script or wrapper executable
25707a3b38f7Smrg# This function is only a basic sanity check; it will hardly flush out
25717a3b38f7Smrg# determined imposters.
25727a3b38f7Smrgfunc_ltwrapper_p ()
25737a3b38f7Smrg{
25747a3b38f7Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
25757a3b38f7Smrg}
2576ff559fabSmrg
2577ff559fabSmrg
25787a3b38f7Smrg# func_execute_cmds commands fail_cmd
25797a3b38f7Smrg# Execute tilde-delimited COMMANDS.
25807a3b38f7Smrg# If FAIL_CMD is given, eval that upon failure.
25817a3b38f7Smrg# FAIL_CMD may read-access the current command in variable CMD!
25827a3b38f7Smrgfunc_execute_cmds ()
25837a3b38f7Smrg{
25846fc0178dSmrg    $debug_cmd
25856fc0178dSmrg
25867a3b38f7Smrg    save_ifs=$IFS; IFS='~'
25877a3b38f7Smrg    for cmd in $1; do
25886fc0178dSmrg      IFS=$sp$nl
25897a3b38f7Smrg      eval cmd=\"$cmd\"
25906fc0178dSmrg      IFS=$save_ifs
25917a3b38f7Smrg      func_show_eval "$cmd" "${2-:}"
25927a3b38f7Smrg    done
25937a3b38f7Smrg    IFS=$save_ifs
25947a3b38f7Smrg}
25957a3b38f7Smrg
25967a3b38f7Smrg
25977a3b38f7Smrg# func_source file
25987a3b38f7Smrg# Source FILE, adding directory component if necessary.
25997a3b38f7Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
26007a3b38f7Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
26017a3b38f7Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
26026fc0178dSmrg# 'FILE.' does not work on cygwin managed mounts.
26037a3b38f7Smrgfunc_source ()
26047a3b38f7Smrg{
26056fc0178dSmrg    $debug_cmd
26066fc0178dSmrg
26077a3b38f7Smrg    case $1 in
26087a3b38f7Smrg    */* | *\\*)	. "$1" ;;
26097a3b38f7Smrg    *)		. "./$1" ;;
26107a3b38f7Smrg    esac
26117a3b38f7Smrg}
26127a3b38f7Smrg
26137a3b38f7Smrg
2614862f5301Smrg# func_resolve_sysroot PATH
2615862f5301Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
2616862f5301Smrg# func_resolve_sysroot_result
2617862f5301Smrgfunc_resolve_sysroot ()
2618862f5301Smrg{
2619862f5301Smrg  func_resolve_sysroot_result=$1
2620862f5301Smrg  case $func_resolve_sysroot_result in
2621862f5301Smrg  =*)
2622862f5301Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2623862f5301Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2624862f5301Smrg    ;;
2625862f5301Smrg  esac
2626862f5301Smrg}
2627862f5301Smrg
2628862f5301Smrg# func_replace_sysroot PATH
2629862f5301Smrg# If PATH begins with the sysroot, replace it with = and
2630862f5301Smrg# store the result into func_replace_sysroot_result.
2631862f5301Smrgfunc_replace_sysroot ()
2632862f5301Smrg{
26336fc0178dSmrg  case $lt_sysroot:$1 in
2634862f5301Smrg  ?*:"$lt_sysroot"*)
2635862f5301Smrg    func_stripname "$lt_sysroot" '' "$1"
26366fc0178dSmrg    func_replace_sysroot_result='='$func_stripname_result
2637862f5301Smrg    ;;
2638862f5301Smrg  *)
2639862f5301Smrg    # Including no sysroot.
2640862f5301Smrg    func_replace_sysroot_result=$1
2641862f5301Smrg    ;;
2642862f5301Smrg  esac
2643862f5301Smrg}
2644862f5301Smrg
26457a3b38f7Smrg# func_infer_tag arg
26467a3b38f7Smrg# Infer tagged configuration to use if any are available and
26477a3b38f7Smrg# if one wasn't chosen via the "--tag" command line option.
26487a3b38f7Smrg# Only attempt this if the compiler in the base compile
26497a3b38f7Smrg# command doesn't match the default compiler.
26507a3b38f7Smrg# arg is usually of the form 'gcc ...'
26517a3b38f7Smrgfunc_infer_tag ()
26527a3b38f7Smrg{
26536fc0178dSmrg    $debug_cmd
26546fc0178dSmrg
26557a3b38f7Smrg    if test -n "$available_tags" && test -z "$tagname"; then
26567a3b38f7Smrg      CC_quoted=
26577a3b38f7Smrg      for arg in $CC; do
2658862f5301Smrg	func_append_quoted CC_quoted "$arg"
26597a3b38f7Smrg      done
266044dda7b2Smrg      CC_expanded=`func_echo_all $CC`
266144dda7b2Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
26627a3b38f7Smrg      case $@ in
26637a3b38f7Smrg      # Blanks in the command may have been stripped by the calling shell,
26647a3b38f7Smrg      # but not from the CC environment variable when configure was run.
266544dda7b2Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
266644dda7b2Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
26677a3b38f7Smrg      # Blanks at the start of $base_compile will cause this to fail
26687a3b38f7Smrg      # if we don't check for them as well.
26697a3b38f7Smrg      *)
26707a3b38f7Smrg	for z in $available_tags; do
26717a3b38f7Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
26727a3b38f7Smrg	    # Evaluate the configuration.
26736fc0178dSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
26747a3b38f7Smrg	    CC_quoted=
26757a3b38f7Smrg	    for arg in $CC; do
26767a3b38f7Smrg	      # Double-quote args containing other shell metacharacters.
2677862f5301Smrg	      func_append_quoted CC_quoted "$arg"
26787a3b38f7Smrg	    done
267944dda7b2Smrg	    CC_expanded=`func_echo_all $CC`
268044dda7b2Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
26817a3b38f7Smrg	    case "$@ " in
268244dda7b2Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
268344dda7b2Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
26847a3b38f7Smrg	      # The compiler in the base compile command matches
26857a3b38f7Smrg	      # the one in the tagged configuration.
26867a3b38f7Smrg	      # Assume this is the tagged configuration we want.
26877a3b38f7Smrg	      tagname=$z
26887a3b38f7Smrg	      break
26897a3b38f7Smrg	      ;;
2690ff559fabSmrg	    esac
26917a3b38f7Smrg	  fi
26927a3b38f7Smrg	done
26937a3b38f7Smrg	# If $tagname still isn't set, then no tagged configuration
26947a3b38f7Smrg	# was found and let the user know that the "--tag" command
26957a3b38f7Smrg	# line option must be used.
26967a3b38f7Smrg	if test -z "$tagname"; then
26977a3b38f7Smrg	  func_echo "unable to infer tagged configuration"
26986fc0178dSmrg	  func_fatal_error "specify a tag with '--tag'"
26997a3b38f7Smrg#	else
27007a3b38f7Smrg#	  func_verbose "using $tagname tagged configuration"
27017a3b38f7Smrg	fi
27027a3b38f7Smrg	;;
27037a3b38f7Smrg      esac
27047a3b38f7Smrg    fi
27057a3b38f7Smrg}
27067a3b38f7Smrg
27077a3b38f7Smrg
27087a3b38f7Smrg
2709862f5301Smrg# func_write_libtool_object output_name pic_name nonpic_name
2710862f5301Smrg# Create a libtool object file (analogous to a ".la" file),
2711862f5301Smrg# but don't create it if we're doing a dry run.
2712862f5301Smrgfunc_write_libtool_object ()
2713862f5301Smrg{
27146fc0178dSmrg    write_libobj=$1
27156fc0178dSmrg    if test yes = "$build_libtool_libs"; then
27166fc0178dSmrg      write_lobj=\'$2\'
2717862f5301Smrg    else
2718862f5301Smrg      write_lobj=none
2719862f5301Smrg    fi
2720862f5301Smrg
27216fc0178dSmrg    if test yes = "$build_old_libs"; then
27226fc0178dSmrg      write_oldobj=\'$3\'
2723862f5301Smrg    else
2724862f5301Smrg      write_oldobj=none
2725862f5301Smrg    fi
2726862f5301Smrg
2727862f5301Smrg    $opt_dry_run || {
2728862f5301Smrg      cat >${write_libobj}T <<EOF
2729862f5301Smrg# $write_libobj - a libtool object file
27306fc0178dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2731862f5301Smrg#
2732862f5301Smrg# Please DO NOT delete this file!
2733862f5301Smrg# It is necessary for linking the library.
2734862f5301Smrg
2735862f5301Smrg# Name of the PIC object.
2736862f5301Smrgpic_object=$write_lobj
2737862f5301Smrg
2738862f5301Smrg# Name of the non-PIC object
2739862f5301Smrgnon_pic_object=$write_oldobj
2740862f5301Smrg
2741862f5301SmrgEOF
27426fc0178dSmrg      $MV "${write_libobj}T" "$write_libobj"
2743862f5301Smrg    }
2744862f5301Smrg}
2745862f5301Smrg
2746862f5301Smrg
2747862f5301Smrg##################################################
2748862f5301Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
2749862f5301Smrg##################################################
2750862f5301Smrg
2751862f5301Smrg# func_convert_core_file_wine_to_w32 ARG
2752862f5301Smrg# Helper function used by file name conversion functions when $build is *nix,
2753862f5301Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
2754862f5301Smrg# correctly configured wine environment available, with the winepath program
2755862f5301Smrg# in $build's $PATH.
2756862f5301Smrg#
2757862f5301Smrg# ARG is the $build file name to be converted to w32 format.
2758862f5301Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
2759862f5301Smrg# be empty on error (or when ARG is empty)
2760862f5301Smrgfunc_convert_core_file_wine_to_w32 ()
2761862f5301Smrg{
27626fc0178dSmrg  $debug_cmd
27636fc0178dSmrg
27646fc0178dSmrg  func_convert_core_file_wine_to_w32_result=$1
2765862f5301Smrg  if test -n "$1"; then
2766862f5301Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
2767862f5301Smrg    # are forced to check the contents of stdout. On the other hand, if the
2768862f5301Smrg    # command is not found, the shell will set an exit code of 127 and print
2769862f5301Smrg    # *an error message* to stdout. So we must check for both error code of
2770862f5301Smrg    # zero AND non-empty stdout, which explains the odd construction:
2771862f5301Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
27726fc0178dSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
2773862f5301Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
27746fc0178dSmrg        $SED -e "$sed_naive_backslashify"`
2775862f5301Smrg    else
2776862f5301Smrg      func_convert_core_file_wine_to_w32_result=
2777862f5301Smrg    fi
2778862f5301Smrg  fi
2779862f5301Smrg}
2780862f5301Smrg# end: func_convert_core_file_wine_to_w32
2781862f5301Smrg
2782862f5301Smrg
2783862f5301Smrg# func_convert_core_path_wine_to_w32 ARG
2784862f5301Smrg# Helper function used by path conversion functions when $build is *nix, and
2785862f5301Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
2786862f5301Smrg# configured wine environment available, with the winepath program in $build's
2787862f5301Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
2788862f5301Smrg#
2789862f5301Smrg# ARG is path to be converted from $build format to win32.
2790862f5301Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
2791862f5301Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
2792862f5301Smrg# are convertible, then the result may be empty.
2793862f5301Smrgfunc_convert_core_path_wine_to_w32 ()
2794862f5301Smrg{
27956fc0178dSmrg  $debug_cmd
27966fc0178dSmrg
2797862f5301Smrg  # unfortunately, winepath doesn't convert paths, only file names
27986fc0178dSmrg  func_convert_core_path_wine_to_w32_result=
2799862f5301Smrg  if test -n "$1"; then
2800862f5301Smrg    oldIFS=$IFS
2801862f5301Smrg    IFS=:
2802862f5301Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
2803862f5301Smrg      IFS=$oldIFS
2804862f5301Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
28056fc0178dSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
2806862f5301Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
28076fc0178dSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
2808862f5301Smrg        else
2809862f5301Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
2810862f5301Smrg        fi
2811862f5301Smrg      fi
2812862f5301Smrg    done
2813862f5301Smrg    IFS=$oldIFS
2814862f5301Smrg  fi
2815862f5301Smrg}
2816862f5301Smrg# end: func_convert_core_path_wine_to_w32
2817862f5301Smrg
2818862f5301Smrg
2819862f5301Smrg# func_cygpath ARGS...
2820862f5301Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
2821862f5301Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
2822862f5301Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
2823862f5301Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
2824862f5301Smrg# file name or path is assumed to be in w32 format, as previously converted
2825862f5301Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
2826862f5301Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
2827862f5301Smrg# Cygwin format). Returns an empty string on error.
2828862f5301Smrg#
2829862f5301Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
2830862f5301Smrg# be converted.
2831862f5301Smrg#
2832862f5301Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
2833862f5301Smrg# environment variable; do not put it in $PATH.
2834862f5301Smrgfunc_cygpath ()
2835862f5301Smrg{
28366fc0178dSmrg  $debug_cmd
28376fc0178dSmrg
2838862f5301Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
2839862f5301Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
2840862f5301Smrg    if test "$?" -ne 0; then
2841862f5301Smrg      # on failure, ensure result is empty
2842862f5301Smrg      func_cygpath_result=
2843862f5301Smrg    fi
2844862f5301Smrg  else
2845862f5301Smrg    func_cygpath_result=
28466fc0178dSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
2847862f5301Smrg  fi
2848862f5301Smrg}
2849862f5301Smrg#end: func_cygpath
2850862f5301Smrg
2851862f5301Smrg
2852862f5301Smrg# func_convert_core_msys_to_w32 ARG
2853862f5301Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
2854862f5301Smrg# result in func_convert_core_msys_to_w32_result.
2855862f5301Smrgfunc_convert_core_msys_to_w32 ()
2856862f5301Smrg{
28576fc0178dSmrg  $debug_cmd
28586fc0178dSmrg
2859862f5301Smrg  # awkward: cmd appends spaces to result
2860862f5301Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
28616fc0178dSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
2862862f5301Smrg}
2863862f5301Smrg#end: func_convert_core_msys_to_w32
2864862f5301Smrg
2865862f5301Smrg
2866862f5301Smrg# func_convert_file_check ARG1 ARG2
2867862f5301Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
2868862f5301Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
2869862f5301Smrg# func_to_host_file_result to ARG1).
2870862f5301Smrgfunc_convert_file_check ()
2871862f5301Smrg{
28726fc0178dSmrg  $debug_cmd
28736fc0178dSmrg
28746fc0178dSmrg  if test -z "$2" && test -n "$1"; then
2875862f5301Smrg    func_error "Could not determine host file name corresponding to"
28766fc0178dSmrg    func_error "  '$1'"
2877862f5301Smrg    func_error "Continuing, but uninstalled executables may not work."
2878862f5301Smrg    # Fallback:
28796fc0178dSmrg    func_to_host_file_result=$1
2880862f5301Smrg  fi
2881862f5301Smrg}
2882862f5301Smrg# end func_convert_file_check
2883862f5301Smrg
2884862f5301Smrg
2885862f5301Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
2886862f5301Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
2887862f5301Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
2888862f5301Smrg# func_to_host_file_result to a simplistic fallback value (see below).
2889862f5301Smrgfunc_convert_path_check ()
2890862f5301Smrg{
28916fc0178dSmrg  $debug_cmd
28926fc0178dSmrg
2893862f5301Smrg  if test -z "$4" && test -n "$3"; then
2894862f5301Smrg    func_error "Could not determine the host path corresponding to"
28956fc0178dSmrg    func_error "  '$3'"
2896862f5301Smrg    func_error "Continuing, but uninstalled executables may not work."
2897862f5301Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
2898862f5301Smrg    # should not be "improved".  See libtool.info.
2899862f5301Smrg    if test "x$1" != "x$2"; then
2900862f5301Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
2901862f5301Smrg      func_to_host_path_result=`echo "$3" |
2902862f5301Smrg        $SED -e "$lt_replace_pathsep_chars"`
2903862f5301Smrg    else
29046fc0178dSmrg      func_to_host_path_result=$3
2905862f5301Smrg    fi
2906862f5301Smrg  fi
2907862f5301Smrg}
2908862f5301Smrg# end func_convert_path_check
2909862f5301Smrg
2910862f5301Smrg
2911862f5301Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
2912862f5301Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
2913862f5301Smrg# and appending REPL if ORIG matches BACKPAT.
2914862f5301Smrgfunc_convert_path_front_back_pathsep ()
2915862f5301Smrg{
29166fc0178dSmrg  $debug_cmd
29176fc0178dSmrg
2918862f5301Smrg  case $4 in
29196fc0178dSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
2920862f5301Smrg    ;;
2921862f5301Smrg  esac
2922862f5301Smrg  case $4 in
2923862f5301Smrg  $2 ) func_append func_to_host_path_result "$3"
2924862f5301Smrg    ;;
2925862f5301Smrg  esac
2926862f5301Smrg}
2927862f5301Smrg# end func_convert_path_front_back_pathsep
2928862f5301Smrg
2929862f5301Smrg
2930862f5301Smrg##################################################
2931862f5301Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
2932862f5301Smrg##################################################
29336fc0178dSmrg# invoked via '$to_host_file_cmd ARG'
2934862f5301Smrg#
2935862f5301Smrg# In each case, ARG is the path to be converted from $build to $host format.
2936862f5301Smrg# Result will be available in $func_to_host_file_result.
2937862f5301Smrg
2938862f5301Smrg
2939862f5301Smrg# func_to_host_file ARG
2940862f5301Smrg# Converts the file name ARG from $build format to $host format. Return result
2941862f5301Smrg# in func_to_host_file_result.
2942862f5301Smrgfunc_to_host_file ()
2943862f5301Smrg{
29446fc0178dSmrg  $debug_cmd
29456fc0178dSmrg
2946862f5301Smrg  $to_host_file_cmd "$1"
2947862f5301Smrg}
2948862f5301Smrg# end func_to_host_file
2949862f5301Smrg
2950862f5301Smrg
2951862f5301Smrg# func_to_tool_file ARG LAZY
2952862f5301Smrg# converts the file name ARG from $build format to toolchain format. Return
2953862f5301Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
2954862f5301Smrg# in (the comma separated) LAZY, no conversion takes place.
2955862f5301Smrgfunc_to_tool_file ()
2956862f5301Smrg{
29576fc0178dSmrg  $debug_cmd
29586fc0178dSmrg
2959862f5301Smrg  case ,$2, in
2960862f5301Smrg    *,"$to_tool_file_cmd",*)
2961862f5301Smrg      func_to_tool_file_result=$1
2962862f5301Smrg      ;;
2963862f5301Smrg    *)
2964862f5301Smrg      $to_tool_file_cmd "$1"
2965862f5301Smrg      func_to_tool_file_result=$func_to_host_file_result
2966862f5301Smrg      ;;
2967862f5301Smrg  esac
2968862f5301Smrg}
2969862f5301Smrg# end func_to_tool_file
2970862f5301Smrg
2971862f5301Smrg
2972862f5301Smrg# func_convert_file_noop ARG
2973862f5301Smrg# Copy ARG to func_to_host_file_result.
2974862f5301Smrgfunc_convert_file_noop ()
2975862f5301Smrg{
29766fc0178dSmrg  func_to_host_file_result=$1
2977862f5301Smrg}
2978862f5301Smrg# end func_convert_file_noop
2979862f5301Smrg
2980862f5301Smrg
2981862f5301Smrg# func_convert_file_msys_to_w32 ARG
2982862f5301Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
2983862f5301Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
2984862f5301Smrg# func_to_host_file_result.
2985862f5301Smrgfunc_convert_file_msys_to_w32 ()
2986862f5301Smrg{
29876fc0178dSmrg  $debug_cmd
29886fc0178dSmrg
29896fc0178dSmrg  func_to_host_file_result=$1
2990862f5301Smrg  if test -n "$1"; then
2991862f5301Smrg    func_convert_core_msys_to_w32 "$1"
29926fc0178dSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
2993862f5301Smrg  fi
2994862f5301Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
2995862f5301Smrg}
2996862f5301Smrg# end func_convert_file_msys_to_w32
2997862f5301Smrg
2998862f5301Smrg
2999862f5301Smrg# func_convert_file_cygwin_to_w32 ARG
3000862f5301Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3001862f5301Smrg# func_to_host_file_result.
3002862f5301Smrgfunc_convert_file_cygwin_to_w32 ()
3003862f5301Smrg{
30046fc0178dSmrg  $debug_cmd
30056fc0178dSmrg
30066fc0178dSmrg  func_to_host_file_result=$1
3007862f5301Smrg  if test -n "$1"; then
3008862f5301Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3009862f5301Smrg    # LT_CYGPATH in this case.
3010862f5301Smrg    func_to_host_file_result=`cygpath -m "$1"`
3011862f5301Smrg  fi
3012862f5301Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3013862f5301Smrg}
3014862f5301Smrg# end func_convert_file_cygwin_to_w32
3015862f5301Smrg
3016862f5301Smrg
3017862f5301Smrg# func_convert_file_nix_to_w32 ARG
3018862f5301Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3019862f5301Smrg# and a working winepath. Returns result in func_to_host_file_result.
3020862f5301Smrgfunc_convert_file_nix_to_w32 ()
3021862f5301Smrg{
30226fc0178dSmrg  $debug_cmd
30236fc0178dSmrg
30246fc0178dSmrg  func_to_host_file_result=$1
3025862f5301Smrg  if test -n "$1"; then
3026862f5301Smrg    func_convert_core_file_wine_to_w32 "$1"
30276fc0178dSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3028862f5301Smrg  fi
3029862f5301Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3030862f5301Smrg}
3031862f5301Smrg# end func_convert_file_nix_to_w32
3032862f5301Smrg
3033862f5301Smrg
3034862f5301Smrg# func_convert_file_msys_to_cygwin ARG
3035862f5301Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3036862f5301Smrg# Returns result in func_to_host_file_result.
3037862f5301Smrgfunc_convert_file_msys_to_cygwin ()
3038862f5301Smrg{
30396fc0178dSmrg  $debug_cmd
30406fc0178dSmrg
30416fc0178dSmrg  func_to_host_file_result=$1
3042862f5301Smrg  if test -n "$1"; then
3043862f5301Smrg    func_convert_core_msys_to_w32 "$1"
3044862f5301Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
30456fc0178dSmrg    func_to_host_file_result=$func_cygpath_result
3046862f5301Smrg  fi
3047862f5301Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3048862f5301Smrg}
3049862f5301Smrg# end func_convert_file_msys_to_cygwin
3050862f5301Smrg
3051862f5301Smrg
3052862f5301Smrg# func_convert_file_nix_to_cygwin ARG
3053862f5301Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3054862f5301Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3055862f5301Smrg# in func_to_host_file_result.
3056862f5301Smrgfunc_convert_file_nix_to_cygwin ()
3057862f5301Smrg{
30586fc0178dSmrg  $debug_cmd
30596fc0178dSmrg
30606fc0178dSmrg  func_to_host_file_result=$1
3061862f5301Smrg  if test -n "$1"; then
3062862f5301Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3063862f5301Smrg    func_convert_core_file_wine_to_w32 "$1"
3064862f5301Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
30656fc0178dSmrg    func_to_host_file_result=$func_cygpath_result
3066862f5301Smrg  fi
3067862f5301Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3068862f5301Smrg}
3069862f5301Smrg# end func_convert_file_nix_to_cygwin
3070862f5301Smrg
3071862f5301Smrg
3072862f5301Smrg#############################################
3073862f5301Smrg# $build to $host PATH CONVERSION FUNCTIONS #
3074862f5301Smrg#############################################
30756fc0178dSmrg# invoked via '$to_host_path_cmd ARG'
3076862f5301Smrg#
3077862f5301Smrg# In each case, ARG is the path to be converted from $build to $host format.
3078862f5301Smrg# The result will be available in $func_to_host_path_result.
3079862f5301Smrg#
3080862f5301Smrg# Path separators are also converted from $build format to $host format.  If
3081862f5301Smrg# ARG begins or ends with a path separator character, it is preserved (but
3082862f5301Smrg# converted to $host format) on output.
3083862f5301Smrg#
3084862f5301Smrg# All path conversion functions are named using the following convention:
3085862f5301Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
3086862f5301Smrg#   path conversion function         : func_convert_path_X_to_Y ()
3087862f5301Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3088862f5301Smrg# same.  If conversion functions are added for new $build/$host combinations,
3089862f5301Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3090862f5301Smrg# will break.
3091862f5301Smrg
3092862f5301Smrg
3093862f5301Smrg# func_init_to_host_path_cmd
3094862f5301Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3095862f5301Smrg# appropriate value, based on the value of $to_host_file_cmd.
3096862f5301Smrgto_host_path_cmd=
3097862f5301Smrgfunc_init_to_host_path_cmd ()
3098862f5301Smrg{
30996fc0178dSmrg  $debug_cmd
31006fc0178dSmrg
3101862f5301Smrg  if test -z "$to_host_path_cmd"; then
3102862f5301Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
31036fc0178dSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3104862f5301Smrg  fi
3105862f5301Smrg}
3106862f5301Smrg
3107862f5301Smrg
3108862f5301Smrg# func_to_host_path ARG
3109862f5301Smrg# Converts the path ARG from $build format to $host format. Return result
3110862f5301Smrg# in func_to_host_path_result.
3111862f5301Smrgfunc_to_host_path ()
3112862f5301Smrg{
31136fc0178dSmrg  $debug_cmd
31146fc0178dSmrg
3115862f5301Smrg  func_init_to_host_path_cmd
3116862f5301Smrg  $to_host_path_cmd "$1"
3117862f5301Smrg}
3118862f5301Smrg# end func_to_host_path
3119862f5301Smrg
3120862f5301Smrg
3121862f5301Smrg# func_convert_path_noop ARG
3122862f5301Smrg# Copy ARG to func_to_host_path_result.
3123862f5301Smrgfunc_convert_path_noop ()
3124862f5301Smrg{
31256fc0178dSmrg  func_to_host_path_result=$1
3126862f5301Smrg}
3127862f5301Smrg# end func_convert_path_noop
3128862f5301Smrg
3129862f5301Smrg
3130862f5301Smrg# func_convert_path_msys_to_w32 ARG
3131862f5301Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3132862f5301Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3133862f5301Smrg# func_to_host_path_result.
3134862f5301Smrgfunc_convert_path_msys_to_w32 ()
31357a3b38f7Smrg{
31366fc0178dSmrg  $debug_cmd
31376fc0178dSmrg
31386fc0178dSmrg  func_to_host_path_result=$1
3139862f5301Smrg  if test -n "$1"; then
3140862f5301Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3141862f5301Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3142862f5301Smrg    # and winepath ignores them completely.
3143862f5301Smrg    func_stripname : : "$1"
3144862f5301Smrg    func_to_host_path_tmp1=$func_stripname_result
3145862f5301Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
31466fc0178dSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3147862f5301Smrg    func_convert_path_check : ";" \
3148862f5301Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3149862f5301Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3150862f5301Smrg  fi
3151862f5301Smrg}
3152862f5301Smrg# end func_convert_path_msys_to_w32
31537a3b38f7Smrg
31547a3b38f7Smrg
3155862f5301Smrg# func_convert_path_cygwin_to_w32 ARG
3156862f5301Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3157862f5301Smrg# func_to_host_file_result.
3158862f5301Smrgfunc_convert_path_cygwin_to_w32 ()
3159862f5301Smrg{
31606fc0178dSmrg  $debug_cmd
31616fc0178dSmrg
31626fc0178dSmrg  func_to_host_path_result=$1
3163862f5301Smrg  if test -n "$1"; then
3164862f5301Smrg    # See func_convert_path_msys_to_w32:
3165862f5301Smrg    func_stripname : : "$1"
3166862f5301Smrg    func_to_host_path_tmp1=$func_stripname_result
3167862f5301Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3168862f5301Smrg    func_convert_path_check : ";" \
3169862f5301Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3170862f5301Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3171862f5301Smrg  fi
3172862f5301Smrg}
3173862f5301Smrg# end func_convert_path_cygwin_to_w32
31747a3b38f7Smrg
31757a3b38f7Smrg
3176862f5301Smrg# func_convert_path_nix_to_w32 ARG
3177862f5301Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3178862f5301Smrg# a working winepath.  Returns result in func_to_host_file_result.
3179862f5301Smrgfunc_convert_path_nix_to_w32 ()
3180862f5301Smrg{
31816fc0178dSmrg  $debug_cmd
31826fc0178dSmrg
31836fc0178dSmrg  func_to_host_path_result=$1
3184862f5301Smrg  if test -n "$1"; then
3185862f5301Smrg    # See func_convert_path_msys_to_w32:
3186862f5301Smrg    func_stripname : : "$1"
3187862f5301Smrg    func_to_host_path_tmp1=$func_stripname_result
3188862f5301Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
31896fc0178dSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3190862f5301Smrg    func_convert_path_check : ";" \
3191862f5301Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3192862f5301Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3193862f5301Smrg  fi
3194862f5301Smrg}
3195862f5301Smrg# end func_convert_path_nix_to_w32
31967a3b38f7Smrg
3197862f5301Smrg
3198862f5301Smrg# func_convert_path_msys_to_cygwin ARG
3199862f5301Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3200862f5301Smrg# Returns result in func_to_host_file_result.
3201862f5301Smrgfunc_convert_path_msys_to_cygwin ()
3202862f5301Smrg{
32036fc0178dSmrg  $debug_cmd
32046fc0178dSmrg
32056fc0178dSmrg  func_to_host_path_result=$1
3206862f5301Smrg  if test -n "$1"; then
3207862f5301Smrg    # See func_convert_path_msys_to_w32:
3208862f5301Smrg    func_stripname : : "$1"
3209862f5301Smrg    func_to_host_path_tmp1=$func_stripname_result
3210862f5301Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3211862f5301Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
32126fc0178dSmrg    func_to_host_path_result=$func_cygpath_result
3213862f5301Smrg    func_convert_path_check : : \
3214862f5301Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3215862f5301Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3216862f5301Smrg  fi
3217862f5301Smrg}
3218862f5301Smrg# end func_convert_path_msys_to_cygwin
3219862f5301Smrg
3220862f5301Smrg
3221862f5301Smrg# func_convert_path_nix_to_cygwin ARG
3222862f5301Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3223862f5301Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3224862f5301Smrg# func_to_host_file_result.
3225862f5301Smrgfunc_convert_path_nix_to_cygwin ()
3226862f5301Smrg{
32276fc0178dSmrg  $debug_cmd
32286fc0178dSmrg
32296fc0178dSmrg  func_to_host_path_result=$1
3230862f5301Smrg  if test -n "$1"; then
3231862f5301Smrg    # Remove leading and trailing path separator characters from
3232862f5301Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3233862f5301Smrg    # into '.;' and ';.', and winepath ignores them completely.
3234862f5301Smrg    func_stripname : : "$1"
3235862f5301Smrg    func_to_host_path_tmp1=$func_stripname_result
3236862f5301Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3237862f5301Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
32386fc0178dSmrg    func_to_host_path_result=$func_cygpath_result
3239862f5301Smrg    func_convert_path_check : : \
3240862f5301Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3241862f5301Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3242862f5301Smrg  fi
32437a3b38f7Smrg}
3244862f5301Smrg# end func_convert_path_nix_to_cygwin
3245862f5301Smrg
32467a3b38f7Smrg
32476fc0178dSmrg# func_dll_def_p FILE
32486fc0178dSmrg# True iff FILE is a Windows DLL '.def' file.
32496fc0178dSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
32506fc0178dSmrgfunc_dll_def_p ()
32516fc0178dSmrg{
32526fc0178dSmrg  $debug_cmd
32536fc0178dSmrg
32546fc0178dSmrg  func_dll_def_p_tmp=`$SED -n \
32556fc0178dSmrg    -e 's/^[	 ]*//' \
32566fc0178dSmrg    -e '/^\(;.*\)*$/d' \
32576fc0178dSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
32586fc0178dSmrg    -e q \
32596fc0178dSmrg    "$1"`
32606fc0178dSmrg  test DEF = "$func_dll_def_p_tmp"
32616fc0178dSmrg}
32626fc0178dSmrg
32636fc0178dSmrg
32647a3b38f7Smrg# func_mode_compile arg...
32657a3b38f7Smrgfunc_mode_compile ()
32667a3b38f7Smrg{
32676fc0178dSmrg    $debug_cmd
32686fc0178dSmrg
32697a3b38f7Smrg    # Get the compilation command and the source file.
32707a3b38f7Smrg    base_compile=
32716fc0178dSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
32727a3b38f7Smrg    suppress_opt=yes
32737a3b38f7Smrg    suppress_output=
32747a3b38f7Smrg    arg_mode=normal
32757a3b38f7Smrg    libobj=
32767a3b38f7Smrg    later=
32777a3b38f7Smrg    pie_flag=
32787a3b38f7Smrg
32797a3b38f7Smrg    for arg
32807a3b38f7Smrg    do
32817a3b38f7Smrg      case $arg_mode in
32827a3b38f7Smrg      arg  )
32837a3b38f7Smrg	# do not "continue".  Instead, add this to base_compile
32846fc0178dSmrg	lastarg=$arg
32857a3b38f7Smrg	arg_mode=normal
32867a3b38f7Smrg	;;
32877a3b38f7Smrg
32887a3b38f7Smrg      target )
32896fc0178dSmrg	libobj=$arg
32907a3b38f7Smrg	arg_mode=normal
32917a3b38f7Smrg	continue
32927a3b38f7Smrg	;;
32937a3b38f7Smrg
32947a3b38f7Smrg      normal )
32957a3b38f7Smrg	# Accept any command-line options.
32967a3b38f7Smrg	case $arg in
32977a3b38f7Smrg	-o)
32987a3b38f7Smrg	  test -n "$libobj" && \
32996fc0178dSmrg	    func_fatal_error "you cannot specify '-o' more than once"
33007a3b38f7Smrg	  arg_mode=target
33017a3b38f7Smrg	  continue
33027a3b38f7Smrg	  ;;
33037a3b38f7Smrg
33047a3b38f7Smrg	-pie | -fpie | -fPIE)
3305862f5301Smrg          func_append pie_flag " $arg"
33067a3b38f7Smrg	  continue
33077a3b38f7Smrg	  ;;
33087a3b38f7Smrg
33097a3b38f7Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3310862f5301Smrg	  func_append later " $arg"
33117a3b38f7Smrg	  continue
33127a3b38f7Smrg	  ;;
33137a3b38f7Smrg
33147a3b38f7Smrg	-no-suppress)
33157a3b38f7Smrg	  suppress_opt=no
33167a3b38f7Smrg	  continue
33177a3b38f7Smrg	  ;;
33187a3b38f7Smrg
33197a3b38f7Smrg	-Xcompiler)
33207a3b38f7Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
33217a3b38f7Smrg	  continue      #  The current "srcfile" will either be retained or
33227a3b38f7Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
33237a3b38f7Smrg
33247a3b38f7Smrg	-Wc,*)
33257a3b38f7Smrg	  func_stripname '-Wc,' '' "$arg"
33267a3b38f7Smrg	  args=$func_stripname_result
33277a3b38f7Smrg	  lastarg=
33286fc0178dSmrg	  save_ifs=$IFS; IFS=,
33297a3b38f7Smrg	  for arg in $args; do
33306fc0178dSmrg	    IFS=$save_ifs
3331862f5301Smrg	    func_append_quoted lastarg "$arg"
3332ff559fabSmrg	  done
33336fc0178dSmrg	  IFS=$save_ifs
33347a3b38f7Smrg	  func_stripname ' ' '' "$lastarg"
33357a3b38f7Smrg	  lastarg=$func_stripname_result
3336ff559fabSmrg
3337ff559fabSmrg	  # Add the arguments to base_compile.
3338862f5301Smrg	  func_append base_compile " $lastarg"
3339ff559fabSmrg	  continue
3340ff559fabSmrg	  ;;
3341ff559fabSmrg
33427a3b38f7Smrg	*)
3343ff559fabSmrg	  # Accept the current argument as the source file.
3344ff559fabSmrg	  # The previous "srcfile" becomes the current argument.
3345ff559fabSmrg	  #
33466fc0178dSmrg	  lastarg=$srcfile
33476fc0178dSmrg	  srcfile=$arg
3348ff559fabSmrg	  ;;
3349ff559fabSmrg	esac  #  case $arg
3350ff559fabSmrg	;;
3351ff559fabSmrg      esac    #  case $arg_mode
3352ff559fabSmrg
3353ff559fabSmrg      # Aesthetically quote the previous argument.
3354862f5301Smrg      func_append_quoted base_compile "$lastarg"
3355ff559fabSmrg    done # for arg
3356ff559fabSmrg
3357ff559fabSmrg    case $arg_mode in
3358ff559fabSmrg    arg)
33597a3b38f7Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3360ff559fabSmrg      ;;
3361ff559fabSmrg    target)
33626fc0178dSmrg      func_fatal_error "you must specify a target with '-o'"
3363ff559fabSmrg      ;;
3364ff559fabSmrg    *)
3365ff559fabSmrg      # Get the name of the library object.
33667a3b38f7Smrg      test -z "$libobj" && {
33677a3b38f7Smrg	func_basename "$srcfile"
33686fc0178dSmrg	libobj=$func_basename_result
33697a3b38f7Smrg      }
3370ff559fabSmrg      ;;
3371ff559fabSmrg    esac
3372ff559fabSmrg
3373ff559fabSmrg    # Recognize several different file suffixes.
3374ff559fabSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3375ff559fabSmrg    case $libobj in
33767a3b38f7Smrg    *.[cCFSifmso] | \
33777a3b38f7Smrg    *.ada | *.adb | *.ads | *.asm | \
33787a3b38f7Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3379fc544a13Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
33807a3b38f7Smrg      func_xform "$libobj"
33817a3b38f7Smrg      libobj=$func_xform_result
33827a3b38f7Smrg      ;;
3383ff559fabSmrg    esac
3384ff559fabSmrg
3385ff559fabSmrg    case $libobj in
33867a3b38f7Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3387ff559fabSmrg    *)
33886fc0178dSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3389ff559fabSmrg      ;;
3390ff559fabSmrg    esac
3391ff559fabSmrg
3392ff559fabSmrg    func_infer_tag $base_compile
3393ff559fabSmrg
3394ff559fabSmrg    for arg in $later; do
3395ff559fabSmrg      case $arg in
33967a3b38f7Smrg      -shared)
33976fc0178dSmrg	test yes = "$build_libtool_libs" \
33986fc0178dSmrg	  || func_fatal_configuration "cannot build a shared library"
33997a3b38f7Smrg	build_old_libs=no
34007a3b38f7Smrg	continue
34017a3b38f7Smrg	;;
34027a3b38f7Smrg
3403ff559fabSmrg      -static)
34047a3b38f7Smrg	build_libtool_libs=no
3405ff559fabSmrg	build_old_libs=yes
3406ff559fabSmrg	continue
3407ff559fabSmrg	;;
3408ff559fabSmrg
3409ff559fabSmrg      -prefer-pic)
3410ff559fabSmrg	pic_mode=yes
3411ff559fabSmrg	continue
3412ff559fabSmrg	;;
3413ff559fabSmrg
3414ff559fabSmrg      -prefer-non-pic)
3415ff559fabSmrg	pic_mode=no
3416ff559fabSmrg	continue
3417ff559fabSmrg	;;
3418ff559fabSmrg      esac
3419ff559fabSmrg    done
3420ff559fabSmrg
34217a3b38f7Smrg    func_quote_for_eval "$libobj"
34227a3b38f7Smrg    test "X$libobj" != "X$func_quote_for_eval_result" \
34237a3b38f7Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
34246fc0178dSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
34257a3b38f7Smrg    func_dirname_and_basename "$obj" "/" ""
34266fc0178dSmrg    objname=$func_basename_result
34276fc0178dSmrg    xdir=$func_dirname_result
34286fc0178dSmrg    lobj=$xdir$objdir/$objname
3429ff559fabSmrg
34307a3b38f7Smrg    test -z "$base_compile" && \
34317a3b38f7Smrg      func_fatal_help "you must specify a compilation command"
3432ff559fabSmrg
3433ff559fabSmrg    # Delete any leftover library objects.
34346fc0178dSmrg    if test yes = "$build_old_libs"; then
3435ff559fabSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3436ff559fabSmrg    else
3437ff559fabSmrg      removelist="$lobj $libobj ${libobj}T"
3438ff559fabSmrg    fi
3439ff559fabSmrg
3440ff559fabSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3441ff559fabSmrg    case $host_os in
34427a3b38f7Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3443ff559fabSmrg      pic_mode=default
3444ff559fabSmrg      ;;
3445ff559fabSmrg    esac
34466fc0178dSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3447ff559fabSmrg      # non-PIC code in shared libraries is not supported
3448ff559fabSmrg      pic_mode=default
3449ff559fabSmrg    fi
3450ff559fabSmrg
3451ff559fabSmrg    # Calculate the filename of the output object if compiler does
3452ff559fabSmrg    # not support -o with -c
34536fc0178dSmrg    if test no = "$compiler_c_o"; then
34546fc0178dSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
34556fc0178dSmrg      lockfile=$output_obj.lock
3456ff559fabSmrg    else
3457ff559fabSmrg      output_obj=
3458ff559fabSmrg      need_locks=no
3459ff559fabSmrg      lockfile=
3460ff559fabSmrg    fi
3461ff559fabSmrg
3462ff559fabSmrg    # Lock this critical section if it is needed
3463ff559fabSmrg    # We use this script file to make the link, it avoids creating a new file
34646fc0178dSmrg    if test yes = "$need_locks"; then
34657a3b38f7Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
34667a3b38f7Smrg	func_echo "Waiting for $lockfile to be removed"
3467ff559fabSmrg	sleep 2
3468ff559fabSmrg      done
34696fc0178dSmrg    elif test warn = "$need_locks"; then
3470ff559fabSmrg      if test -f "$lockfile"; then
34717a3b38f7Smrg	$ECHO "\
3472ff559fabSmrg*** ERROR, $lockfile exists and contains:
3473ff559fabSmrg`cat $lockfile 2>/dev/null`
3474ff559fabSmrg
3475ff559fabSmrgThis indicates that another process is trying to use the same
3476ff559fabSmrgtemporary object file, and libtool could not work around it because
34776fc0178dSmrgyour compiler does not support '-c' and '-o' together.  If you
3478ff559fabSmrgrepeat this compilation, it may succeed, by chance, but you had better
3479ff559fabSmrgavoid parallel builds (make -j) in this platform, or get a better
3480ff559fabSmrgcompiler."
3481ff559fabSmrg
34827a3b38f7Smrg	$opt_dry_run || $RM $removelist
3483ff559fabSmrg	exit $EXIT_FAILURE
3484ff559fabSmrg      fi
3485862f5301Smrg      func_append removelist " $output_obj"
34867a3b38f7Smrg      $ECHO "$srcfile" > "$lockfile"
3487ff559fabSmrg    fi
3488ff559fabSmrg
34897a3b38f7Smrg    $opt_dry_run || $RM $removelist
3490862f5301Smrg    func_append removelist " $lockfile"
34917a3b38f7Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
34927a3b38f7Smrg
3493862f5301Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3494862f5301Smrg    srcfile=$func_to_tool_file_result
34957a3b38f7Smrg    func_quote_for_eval "$srcfile"
34967a3b38f7Smrg    qsrcfile=$func_quote_for_eval_result
3497ff559fabSmrg
3498ff559fabSmrg    # Only build a PIC object if we are building libtool libraries.
34996fc0178dSmrg    if test yes = "$build_libtool_libs"; then
3500ff559fabSmrg      # Without this assignment, base_compile gets emptied.
3501ff559fabSmrg      fbsd_hideous_sh_bug=$base_compile
3502ff559fabSmrg
35036fc0178dSmrg      if test no != "$pic_mode"; then
3504ff559fabSmrg	command="$base_compile $qsrcfile $pic_flag"
3505ff559fabSmrg      else
3506ff559fabSmrg	# Don't build PIC code
3507ff559fabSmrg	command="$base_compile $qsrcfile"
3508ff559fabSmrg      fi
3509ff559fabSmrg
35107a3b38f7Smrg      func_mkdir_p "$xdir$objdir"
3511ff559fabSmrg
3512ff559fabSmrg      if test -z "$output_obj"; then
3513ff559fabSmrg	# Place PIC objects in $objdir
3514862f5301Smrg	func_append command " -o $lobj"
3515ff559fabSmrg      fi
3516ff559fabSmrg
35177a3b38f7Smrg      func_show_eval_locale "$command"	\
35187a3b38f7Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3519ff559fabSmrg
35206fc0178dSmrg      if test warn = "$need_locks" &&
3521ff559fabSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
35227a3b38f7Smrg	$ECHO "\
3523ff559fabSmrg*** ERROR, $lockfile contains:
3524ff559fabSmrg`cat $lockfile 2>/dev/null`
3525ff559fabSmrg
3526ff559fabSmrgbut it should contain:
3527ff559fabSmrg$srcfile
3528ff559fabSmrg
3529ff559fabSmrgThis indicates that another process is trying to use the same
3530ff559fabSmrgtemporary object file, and libtool could not work around it because
35316fc0178dSmrgyour compiler does not support '-c' and '-o' together.  If you
3532ff559fabSmrgrepeat this compilation, it may succeed, by chance, but you had better
3533ff559fabSmrgavoid parallel builds (make -j) in this platform, or get a better
3534ff559fabSmrgcompiler."
3535ff559fabSmrg
35367a3b38f7Smrg	$opt_dry_run || $RM $removelist
3537ff559fabSmrg	exit $EXIT_FAILURE
3538ff559fabSmrg      fi
3539ff559fabSmrg
3540ff559fabSmrg      # Just move the object if needed, then go on to compile the next one
3541ff559fabSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
35427a3b38f7Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
35437a3b38f7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3544ff559fabSmrg      fi
3545ff559fabSmrg
3546ff559fabSmrg      # Allow error messages only from the first compilation.
35476fc0178dSmrg      if test yes = "$suppress_opt"; then
35487a3b38f7Smrg	suppress_output=' >/dev/null 2>&1'
3549ff559fabSmrg      fi
3550ff559fabSmrg    fi
3551ff559fabSmrg
3552ff559fabSmrg    # Only build a position-dependent object if we build old libraries.
35536fc0178dSmrg    if test yes = "$build_old_libs"; then
35546fc0178dSmrg      if test yes != "$pic_mode"; then
3555ff559fabSmrg	# Don't build PIC code
35567a3b38f7Smrg	command="$base_compile $qsrcfile$pie_flag"
3557ff559fabSmrg      else
3558ff559fabSmrg	command="$base_compile $qsrcfile $pic_flag"
3559ff559fabSmrg      fi
35606fc0178dSmrg      if test yes = "$compiler_c_o"; then
3561862f5301Smrg	func_append command " -o $obj"
3562ff559fabSmrg      fi
3563ff559fabSmrg
3564ff559fabSmrg      # Suppress compiler output if we already did a PIC compilation.
3565862f5301Smrg      func_append command "$suppress_output"
35667a3b38f7Smrg      func_show_eval_locale "$command" \
35677a3b38f7Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3568ff559fabSmrg
35696fc0178dSmrg      if test warn = "$need_locks" &&
3570ff559fabSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
35717a3b38f7Smrg	$ECHO "\
3572ff559fabSmrg*** ERROR, $lockfile contains:
3573ff559fabSmrg`cat $lockfile 2>/dev/null`
3574ff559fabSmrg
3575ff559fabSmrgbut it should contain:
3576ff559fabSmrg$srcfile
3577ff559fabSmrg
3578ff559fabSmrgThis indicates that another process is trying to use the same
3579ff559fabSmrgtemporary object file, and libtool could not work around it because
35806fc0178dSmrgyour compiler does not support '-c' and '-o' together.  If you
3581ff559fabSmrgrepeat this compilation, it may succeed, by chance, but you had better
3582ff559fabSmrgavoid parallel builds (make -j) in this platform, or get a better
3583ff559fabSmrgcompiler."
3584ff559fabSmrg
35857a3b38f7Smrg	$opt_dry_run || $RM $removelist
3586ff559fabSmrg	exit $EXIT_FAILURE
3587ff559fabSmrg      fi
3588ff559fabSmrg
3589ff559fabSmrg      # Just move the object if needed
3590ff559fabSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
35917a3b38f7Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
35927a3b38f7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3593ff559fabSmrg      fi
3594ff559fabSmrg    fi
3595ff559fabSmrg
35967a3b38f7Smrg    $opt_dry_run || {
35977a3b38f7Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3598ff559fabSmrg
35997a3b38f7Smrg      # Unlock the critical section if it was locked
36006fc0178dSmrg      if test no != "$need_locks"; then
36017a3b38f7Smrg	removelist=$lockfile
36027a3b38f7Smrg        $RM "$lockfile"
36037a3b38f7Smrg      fi
36047a3b38f7Smrg    }
3605ff559fabSmrg
3606ff559fabSmrg    exit $EXIT_SUCCESS
36077a3b38f7Smrg}
3608ff559fabSmrg
36097a3b38f7Smrg$opt_help || {
36106fc0178dSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
36117a3b38f7Smrg}
3612ff559fabSmrg
36137a3b38f7Smrgfunc_mode_help ()
36147a3b38f7Smrg{
36157a3b38f7Smrg    # We need to display help for each of the modes.
3616862f5301Smrg    case $opt_mode in
36177a3b38f7Smrg      "")
36187a3b38f7Smrg        # Generic help is extracted from the usage comments
36197a3b38f7Smrg        # at the start of this file.
36207a3b38f7Smrg        func_help
36217a3b38f7Smrg        ;;
3622ff559fabSmrg
36237a3b38f7Smrg      clean)
36247a3b38f7Smrg        $ECHO \
36257a3b38f7Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3626ff559fabSmrg
36277a3b38f7SmrgRemove files from the build directory.
3628ff559fabSmrg
36297a3b38f7SmrgRM is the name of the program to use to delete files associated with each FILE
36306fc0178dSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
36317a3b38f7Smrgto RM.
3632ff559fabSmrg
36337a3b38f7SmrgIf FILE is a libtool library, object or program, all the files associated
36347a3b38f7Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
36357a3b38f7Smrg        ;;
3636ff559fabSmrg
36377a3b38f7Smrg      compile)
36387a3b38f7Smrg      $ECHO \
36397a3b38f7Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3640ff559fabSmrg
36417a3b38f7SmrgCompile a source file into a libtool library object.
3642ff559fabSmrg
36437a3b38f7SmrgThis mode accepts the following additional options:
3644ff559fabSmrg
36457a3b38f7Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
36467a3b38f7Smrg  -no-suppress      do not suppress compiler output for multiple passes
364744dda7b2Smrg  -prefer-pic       try to build PIC objects only
364844dda7b2Smrg  -prefer-non-pic   try to build non-PIC objects only
36496fc0178dSmrg  -shared           do not build a '.o' file suitable for static linking
36506fc0178dSmrg  -static           only build a '.o' file suitable for static linking
365144dda7b2Smrg  -Wc,FLAG          pass FLAG directly to the compiler
3652ff559fabSmrg
36536fc0178dSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
36547a3b38f7Smrgfrom the given SOURCEFILE.
3655ff559fabSmrg
36567a3b38f7SmrgThe output file name is determined by removing the directory component from
36576fc0178dSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
36586fc0178dSmrglibrary object suffix, '.lo'."
36597a3b38f7Smrg        ;;
3660ff559fabSmrg
36617a3b38f7Smrg      execute)
36627a3b38f7Smrg        $ECHO \
36637a3b38f7Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3664ff559fabSmrg
36657a3b38f7SmrgAutomatically set library path, then run a program.
3666ff559fabSmrg
36677a3b38f7SmrgThis mode accepts the following additional options:
3668ff559fabSmrg
36697a3b38f7Smrg  -dlopen FILE      add the directory containing FILE to the library path
3670ff559fabSmrg
36716fc0178dSmrgThis mode sets the library path environment variable according to '-dlopen'
36727a3b38f7Smrgflags.
3673ff559fabSmrg
36747a3b38f7SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
36757a3b38f7Smrginto their corresponding uninstalled binary, and any of their required library
36767a3b38f7Smrgdirectories are added to the library path.
3677ff559fabSmrg
36787a3b38f7SmrgThen, COMMAND is executed, with ARGS as arguments."
36797a3b38f7Smrg        ;;
3680ff559fabSmrg
36817a3b38f7Smrg      finish)
36827a3b38f7Smrg        $ECHO \
36837a3b38f7Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3684ff559fabSmrg
36857a3b38f7SmrgComplete the installation of libtool libraries.
3686ff559fabSmrg
36877a3b38f7SmrgEach LIBDIR is a directory that contains libtool libraries.
3688ff559fabSmrg
36897a3b38f7SmrgThe commands that this mode executes may require superuser privileges.  Use
36906fc0178dSmrgthe '--dry-run' option if you just want to see what would be executed."
36917a3b38f7Smrg        ;;
3692ff559fabSmrg
36937a3b38f7Smrg      install)
36947a3b38f7Smrg        $ECHO \
36957a3b38f7Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3696ff559fabSmrg
36977a3b38f7SmrgInstall executables or libraries.
3698ff559fabSmrg
36997a3b38f7SmrgINSTALL-COMMAND is the installation command.  The first component should be
37006fc0178dSmrgeither the 'install' or 'cp' program.
3701ff559fabSmrg
37027a3b38f7SmrgThe following components of INSTALL-COMMAND are treated specially:
3703ff559fabSmrg
370444dda7b2Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3705ff559fabSmrg
37067a3b38f7SmrgThe rest of the components are interpreted as arguments to that command (only
37077a3b38f7SmrgBSD-compatible install options are recognized)."
37087a3b38f7Smrg        ;;
3709ff559fabSmrg
37107a3b38f7Smrg      link)
37117a3b38f7Smrg        $ECHO \
37127a3b38f7Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3713ff559fabSmrg
37147a3b38f7SmrgLink object files or libraries together to form another library, or to
37157a3b38f7Smrgcreate an executable program.
3716ff559fabSmrg
37177a3b38f7SmrgLINK-COMMAND is a command using the C compiler that you would use to create
37187a3b38f7Smrga program from several object files.
3719ff559fabSmrg
37207a3b38f7SmrgThe following components of LINK-COMMAND are treated specially:
3721ff559fabSmrg
37227a3b38f7Smrg  -all-static       do not do any dynamic linking at all
37237a3b38f7Smrg  -avoid-version    do not add a version suffix if possible
372444dda7b2Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
372544dda7b2Smrg                    libraries must be found in the PATH setting at runtime)
37266fc0178dSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
37277a3b38f7Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
37287a3b38f7Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
37297a3b38f7Smrg  -export-symbols SYMFILE
37307a3b38f7Smrg                    try to export only the symbols listed in SYMFILE
37317a3b38f7Smrg  -export-symbols-regex REGEX
37327a3b38f7Smrg                    try to export only the symbols matching REGEX
37337a3b38f7Smrg  -LLIBDIR          search LIBDIR for required installed libraries
37347a3b38f7Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
37357a3b38f7Smrg  -module           build a library that can dlopened
37367a3b38f7Smrg  -no-fast-install  disable the fast-install mode
37377a3b38f7Smrg  -no-install       link a not-installable executable
37387a3b38f7Smrg  -no-undefined     declare that a library does not refer to external symbols
37397a3b38f7Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
37406fc0178dSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
37416fc0178dSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
37427a3b38f7Smrg  -precious-files-regex REGEX
37437a3b38f7Smrg                    don't remove output files matching REGEX
37447a3b38f7Smrg  -release RELEASE  specify package release information
37457a3b38f7Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
37467a3b38f7Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
37477a3b38f7Smrg  -shared           only do dynamic linking of libtool libraries
37487a3b38f7Smrg  -shrext SUFFIX    override the standard shared library file extension
37497a3b38f7Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
37507a3b38f7Smrg  -static-libtool-libs
37517a3b38f7Smrg                    do not do any dynamic linking of libtool libraries
37527a3b38f7Smrg  -version-info CURRENT[:REVISION[:AGE]]
37537a3b38f7Smrg                    specify library version info [each variable defaults to 0]
37547a3b38f7Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
375544dda7b2Smrg  -Wc,FLAG
375644dda7b2Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
375744dda7b2Smrg  -Wl,FLAG
375844dda7b2Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
375944dda7b2Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
3760ff559fabSmrg
37616fc0178dSmrgAll other options (arguments beginning with '-') are ignored.
3762ff559fabSmrg
37636fc0178dSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
37647a3b38f7Smrgtreated as uninstalled libtool libraries, other files are standard or library
37657a3b38f7Smrgobject files.
3766ff559fabSmrg
37676fc0178dSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
37686fc0178dSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
37697a3b38f7Smrgrequired, except when creating a convenience library.
3770ff559fabSmrg
37716fc0178dSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
37726fc0178dSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
3773ff559fabSmrg
37746fc0178dSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
37757a3b38f7Smrgis created, otherwise an executable program is created."
3776ff559fabSmrg        ;;
3777ff559fabSmrg
37787a3b38f7Smrg      uninstall)
37797a3b38f7Smrg        $ECHO \
37807a3b38f7Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
3781ff559fabSmrg
37827a3b38f7SmrgRemove libraries from an installation directory.
3783ff559fabSmrg
37847a3b38f7SmrgRM is the name of the program to use to delete files associated with each FILE
37856fc0178dSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
37867a3b38f7Smrgto RM.
3787ff559fabSmrg
37887a3b38f7SmrgIf FILE is a libtool library, all the files associated with it are deleted.
37897a3b38f7SmrgOtherwise, only FILE itself is deleted using RM."
37907a3b38f7Smrg        ;;
3791ff559fabSmrg
37927a3b38f7Smrg      *)
37936fc0178dSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
37947a3b38f7Smrg        ;;
37957a3b38f7Smrg    esac
3796ff559fabSmrg
379744dda7b2Smrg    echo
37986fc0178dSmrg    $ECHO "Try '$progname --help' for more information about other modes."
37997a3b38f7Smrg}
3800ff559fabSmrg
380144dda7b2Smrg# Now that we've collected a possible --mode arg, show help if necessary
380244dda7b2Smrgif $opt_help; then
38036fc0178dSmrg  if test : = "$opt_help"; then
380444dda7b2Smrg    func_mode_help
380544dda7b2Smrg  else
380644dda7b2Smrg    {
380744dda7b2Smrg      func_help noexit
3808862f5301Smrg      for opt_mode in compile link execute install finish uninstall clean; do
380944dda7b2Smrg	func_mode_help
381044dda7b2Smrg      done
38116fc0178dSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
381244dda7b2Smrg    {
381344dda7b2Smrg      func_help noexit
3814862f5301Smrg      for opt_mode in compile link execute install finish uninstall clean; do
381544dda7b2Smrg	echo
381644dda7b2Smrg	func_mode_help
381744dda7b2Smrg      done
381844dda7b2Smrg    } |
38196fc0178dSmrg    $SED '1d
382044dda7b2Smrg      /^When reporting/,/^Report/{
382144dda7b2Smrg	H
382244dda7b2Smrg	d
382344dda7b2Smrg      }
382444dda7b2Smrg      $x
382544dda7b2Smrg      /information about other modes/d
382644dda7b2Smrg      /more detailed .*MODE/d
382744dda7b2Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
382844dda7b2Smrg  fi
382944dda7b2Smrg  exit $?
383044dda7b2Smrgfi
3831ff559fabSmrg
3832ff559fabSmrg
38337a3b38f7Smrg# func_mode_execute arg...
38347a3b38f7Smrgfunc_mode_execute ()
38357a3b38f7Smrg{
38366fc0178dSmrg    $debug_cmd
38376fc0178dSmrg
38387a3b38f7Smrg    # The first argument is the command name.
38396fc0178dSmrg    cmd=$nonopt
38407a3b38f7Smrg    test -z "$cmd" && \
38417a3b38f7Smrg      func_fatal_help "you must specify a COMMAND"
3842ff559fabSmrg
38437a3b38f7Smrg    # Handle -dlopen flags immediately.
3844862f5301Smrg    for file in $opt_dlopen; do
38457a3b38f7Smrg      test -f "$file" \
38466fc0178dSmrg	|| func_fatal_help "'$file' is not a file"
3847ff559fabSmrg
38487a3b38f7Smrg      dir=
38497a3b38f7Smrg      case $file in
38507a3b38f7Smrg      *.la)
3851862f5301Smrg	func_resolve_sysroot "$file"
3852862f5301Smrg	file=$func_resolve_sysroot_result
3853862f5301Smrg
38547a3b38f7Smrg	# Check to see that this really is a libtool archive.
38557a3b38f7Smrg	func_lalib_unsafe_p "$file" \
38566fc0178dSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
3857ff559fabSmrg
38587a3b38f7Smrg	# Read the libtool library.
38597a3b38f7Smrg	dlname=
38607a3b38f7Smrg	library_names=
38617a3b38f7Smrg	func_source "$file"
3862ff559fabSmrg
38637a3b38f7Smrg	# Skip this library if it cannot be dlopened.
38647a3b38f7Smrg	if test -z "$dlname"; then
38657a3b38f7Smrg	  # Warn if it was a shared library.
38667a3b38f7Smrg	  test -n "$library_names" && \
38676fc0178dSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
38687a3b38f7Smrg	  continue
38697a3b38f7Smrg	fi
3870ff559fabSmrg
38717a3b38f7Smrg	func_dirname "$file" "" "."
38726fc0178dSmrg	dir=$func_dirname_result
3873ff559fabSmrg
38747a3b38f7Smrg	if test -f "$dir/$objdir/$dlname"; then
3875862f5301Smrg	  func_append dir "/$objdir"
38767a3b38f7Smrg	else
38777a3b38f7Smrg	  if test ! -f "$dir/$dlname"; then
38786fc0178dSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
38797a3b38f7Smrg	  fi
38807a3b38f7Smrg	fi
3881ff559fabSmrg	;;
3882ff559fabSmrg
38837a3b38f7Smrg      *.lo)
38847a3b38f7Smrg	# Just add the directory containing the .lo file.
38857a3b38f7Smrg	func_dirname "$file" "" "."
38866fc0178dSmrg	dir=$func_dirname_result
3887ff559fabSmrg	;;
3888ff559fabSmrg
38897a3b38f7Smrg      *)
38906fc0178dSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
3891ff559fabSmrg	continue
3892ff559fabSmrg	;;
38937a3b38f7Smrg      esac
3894ff559fabSmrg
38957a3b38f7Smrg      # Get the absolute pathname.
38967a3b38f7Smrg      absdir=`cd "$dir" && pwd`
38976fc0178dSmrg      test -n "$absdir" && dir=$absdir
3898ff559fabSmrg
38997a3b38f7Smrg      # Now add the directory to shlibpath_var.
39007a3b38f7Smrg      if eval "test -z \"\$$shlibpath_var\""; then
39017a3b38f7Smrg	eval "$shlibpath_var=\"\$dir\""
39027a3b38f7Smrg      else
39037a3b38f7Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
39047a3b38f7Smrg      fi
39057a3b38f7Smrg    done
3906ff559fabSmrg
39077a3b38f7Smrg    # This variable tells wrapper scripts just to set shlibpath_var
39087a3b38f7Smrg    # rather than running their programs.
39096fc0178dSmrg    libtool_execute_magic=$magic
3910ff559fabSmrg
39117a3b38f7Smrg    # Check if any of the arguments is a wrapper script.
39127a3b38f7Smrg    args=
39137a3b38f7Smrg    for file
39147a3b38f7Smrg    do
39157a3b38f7Smrg      case $file in
391644dda7b2Smrg      -* | *.la | *.lo ) ;;
39177a3b38f7Smrg      *)
39187a3b38f7Smrg	# Do a test to see if this is really a libtool program.
39197a3b38f7Smrg	if func_ltwrapper_script_p "$file"; then
39207a3b38f7Smrg	  func_source "$file"
39217a3b38f7Smrg	  # Transform arg to wrapped name.
39226fc0178dSmrg	  file=$progdir/$program
39237a3b38f7Smrg	elif func_ltwrapper_executable_p "$file"; then
39247a3b38f7Smrg	  func_ltwrapper_scriptname "$file"
39257a3b38f7Smrg	  func_source "$func_ltwrapper_scriptname_result"
39267a3b38f7Smrg	  # Transform arg to wrapped name.
39276fc0178dSmrg	  file=$progdir/$program
39287a3b38f7Smrg	fi
39297a3b38f7Smrg	;;
39307a3b38f7Smrg      esac
39317a3b38f7Smrg      # Quote arguments (to preserve shell metacharacters).
3932862f5301Smrg      func_append_quoted args "$file"
39337a3b38f7Smrg    done
3934ff559fabSmrg
39356fc0178dSmrg    if $opt_dry_run; then
39366fc0178dSmrg      # Display what would be done.
39376fc0178dSmrg      if test -n "$shlibpath_var"; then
39386fc0178dSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
39396fc0178dSmrg	echo "export $shlibpath_var"
39406fc0178dSmrg      fi
39416fc0178dSmrg      $ECHO "$cmd$args"
39426fc0178dSmrg      exit $EXIT_SUCCESS
39436fc0178dSmrg    else
39447a3b38f7Smrg      if test -n "$shlibpath_var"; then
39457a3b38f7Smrg	# Export the shlibpath_var.
39467a3b38f7Smrg	eval "export $shlibpath_var"
39477a3b38f7Smrg      fi
3948ff559fabSmrg
39497a3b38f7Smrg      # Restore saved environment variables
39507a3b38f7Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
39517a3b38f7Smrg      do
39527a3b38f7Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
39537a3b38f7Smrg                $lt_var=\$save_$lt_var; export $lt_var
39547a3b38f7Smrg	      else
39557a3b38f7Smrg		$lt_unset $lt_var
39567a3b38f7Smrg	      fi"
39577a3b38f7Smrg      done
3958ff559fabSmrg
39597a3b38f7Smrg      # Now prepare to actually exec the command.
39606fc0178dSmrg      exec_cmd=\$cmd$args
39617a3b38f7Smrg    fi
39627a3b38f7Smrg}
3963ff559fabSmrg
39646fc0178dSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
3965ff559fabSmrg
3966ff559fabSmrg
39677a3b38f7Smrg# func_mode_finish arg...
39687a3b38f7Smrgfunc_mode_finish ()
39697a3b38f7Smrg{
39706fc0178dSmrg    $debug_cmd
39716fc0178dSmrg
3972862f5301Smrg    libs=
3973862f5301Smrg    libdirs=
39747a3b38f7Smrg    admincmds=
3975ff559fabSmrg
3976862f5301Smrg    for opt in "$nonopt" ${1+"$@"}
3977862f5301Smrg    do
3978862f5301Smrg      if test -d "$opt"; then
3979862f5301Smrg	func_append libdirs " $opt"
3980862f5301Smrg
3981862f5301Smrg      elif test -f "$opt"; then
3982862f5301Smrg	if func_lalib_unsafe_p "$opt"; then
3983862f5301Smrg	  func_append libs " $opt"
3984862f5301Smrg	else
39856fc0178dSmrg	  func_warning "'$opt' is not a valid libtool archive"
3986862f5301Smrg	fi
3987862f5301Smrg
3988862f5301Smrg      else
39896fc0178dSmrg	func_fatal_error "invalid argument '$opt'"
3990862f5301Smrg      fi
3991862f5301Smrg    done
3992862f5301Smrg
3993862f5301Smrg    if test -n "$libs"; then
3994862f5301Smrg      if test -n "$lt_sysroot"; then
3995862f5301Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
3996862f5301Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
3997862f5301Smrg      else
3998862f5301Smrg        sysroot_cmd=
3999862f5301Smrg      fi
4000862f5301Smrg
4001862f5301Smrg      # Remove sysroot references
4002862f5301Smrg      if $opt_dry_run; then
4003862f5301Smrg        for lib in $libs; do
40046fc0178dSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4005862f5301Smrg        done
4006862f5301Smrg      else
4007862f5301Smrg        tmpdir=`func_mktempdir`
4008862f5301Smrg        for lib in $libs; do
40096fc0178dSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4010862f5301Smrg	    > $tmpdir/tmp-la
4011862f5301Smrg	  mv -f $tmpdir/tmp-la $lib
4012862f5301Smrg	done
4013862f5301Smrg        ${RM}r "$tmpdir"
4014862f5301Smrg      fi
4015862f5301Smrg    fi
4016ff559fabSmrg
4017862f5301Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
40187a3b38f7Smrg      for libdir in $libdirs; do
40197a3b38f7Smrg	if test -n "$finish_cmds"; then
40207a3b38f7Smrg	  # Do each command in the finish commands.
40217a3b38f7Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
40227a3b38f7Smrg'"$cmd"'"'
40237a3b38f7Smrg	fi
40247a3b38f7Smrg	if test -n "$finish_eval"; then
40257a3b38f7Smrg	  # Do the single finish_eval.
40267a3b38f7Smrg	  eval cmds=\"$finish_eval\"
4027862f5301Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
40287a3b38f7Smrg       $cmds"
40297a3b38f7Smrg	fi
40307a3b38f7Smrg      done
40317a3b38f7Smrg    fi
4032ff559fabSmrg
40337a3b38f7Smrg    # Exit here if they wanted silent mode.
40346fc0178dSmrg    $opt_quiet && exit $EXIT_SUCCESS
4035ff559fabSmrg
4036862f5301Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4037862f5301Smrg      echo "----------------------------------------------------------------------"
4038862f5301Smrg      echo "Libraries have been installed in:"
4039862f5301Smrg      for libdir in $libdirs; do
4040862f5301Smrg	$ECHO "   $libdir"
4041862f5301Smrg      done
4042862f5301Smrg      echo
4043862f5301Smrg      echo "If you ever happen to want to link against installed libraries"
4044862f5301Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
40456fc0178dSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4046862f5301Smrg      echo "flag during linking and do at least one of the following:"
4047862f5301Smrg      if test -n "$shlibpath_var"; then
40486fc0178dSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4049862f5301Smrg	echo "     during execution"
4050862f5301Smrg      fi
4051862f5301Smrg      if test -n "$runpath_var"; then
40526fc0178dSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4053862f5301Smrg	echo "     during linking"
4054862f5301Smrg      fi
4055862f5301Smrg      if test -n "$hardcode_libdir_flag_spec"; then
4056862f5301Smrg	libdir=LIBDIR
4057862f5301Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4058ff559fabSmrg
40596fc0178dSmrg	$ECHO "   - use the '$flag' linker flag"
4060862f5301Smrg      fi
4061862f5301Smrg      if test -n "$admincmds"; then
4062862f5301Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4063862f5301Smrg      fi
4064862f5301Smrg      if test -f /etc/ld.so.conf; then
40656fc0178dSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4066862f5301Smrg      fi
4067862f5301Smrg      echo
4068ff559fabSmrg
4069862f5301Smrg      echo "See any operating system documentation about shared libraries for"
4070862f5301Smrg      case $host in
4071862f5301Smrg	solaris2.[6789]|solaris2.1[0-9])
4072862f5301Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4073862f5301Smrg	  echo "pages."
4074862f5301Smrg	  ;;
4075862f5301Smrg	*)
4076862f5301Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4077862f5301Smrg	  ;;
4078862f5301Smrg      esac
4079862f5301Smrg      echo "----------------------------------------------------------------------"
4080862f5301Smrg    fi
40817a3b38f7Smrg    exit $EXIT_SUCCESS
40827a3b38f7Smrg}
4083ff559fabSmrg
40846fc0178dSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4085ff559fabSmrg
4086ff559fabSmrg
40877a3b38f7Smrg# func_mode_install arg...
40887a3b38f7Smrgfunc_mode_install ()
40897a3b38f7Smrg{
40906fc0178dSmrg    $debug_cmd
40916fc0178dSmrg
40927a3b38f7Smrg    # There may be an optional sh(1) argument at the beginning of
40937a3b38f7Smrg    # install_prog (especially on Windows NT).
40946fc0178dSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
40957a3b38f7Smrg       # Allow the use of GNU shtool's install command.
40966fc0178dSmrg       case $nonopt in *shtool*) :;; *) false;; esac
40976fc0178dSmrg    then
40987a3b38f7Smrg      # Aesthetically quote it.
40997a3b38f7Smrg      func_quote_for_eval "$nonopt"
41007a3b38f7Smrg      install_prog="$func_quote_for_eval_result "
41017a3b38f7Smrg      arg=$1
41027a3b38f7Smrg      shift
41037a3b38f7Smrg    else
41047a3b38f7Smrg      install_prog=
41057a3b38f7Smrg      arg=$nonopt
41067a3b38f7Smrg    fi
4107ff559fabSmrg
41087a3b38f7Smrg    # The real first argument should be the name of the installation program.
41097a3b38f7Smrg    # Aesthetically quote it.
41107a3b38f7Smrg    func_quote_for_eval "$arg"
4111862f5301Smrg    func_append install_prog "$func_quote_for_eval_result"
411244dda7b2Smrg    install_shared_prog=$install_prog
411344dda7b2Smrg    case " $install_prog " in
411444dda7b2Smrg      *[\\\ /]cp\ *) install_cp=: ;;
411544dda7b2Smrg      *) install_cp=false ;;
411644dda7b2Smrg    esac
41177a3b38f7Smrg
41187a3b38f7Smrg    # We need to accept at least all the BSD install flags.
41197a3b38f7Smrg    dest=
41207a3b38f7Smrg    files=
41217a3b38f7Smrg    opts=
41227a3b38f7Smrg    prev=
41237a3b38f7Smrg    install_type=
41246fc0178dSmrg    isdir=false
41257a3b38f7Smrg    stripme=
412644dda7b2Smrg    no_mode=:
41277a3b38f7Smrg    for arg
41287a3b38f7Smrg    do
412944dda7b2Smrg      arg2=
41307a3b38f7Smrg      if test -n "$dest"; then
4131862f5301Smrg	func_append files " $dest"
41327a3b38f7Smrg	dest=$arg
41337a3b38f7Smrg	continue
4134ff559fabSmrg      fi
4135ff559fabSmrg
41367a3b38f7Smrg      case $arg in
41376fc0178dSmrg      -d) isdir=: ;;
41387a3b38f7Smrg      -f)
413944dda7b2Smrg	if $install_cp; then :; else
414044dda7b2Smrg	  prev=$arg
414144dda7b2Smrg	fi
41427a3b38f7Smrg	;;
41437a3b38f7Smrg      -g | -m | -o)
41447a3b38f7Smrg	prev=$arg
41457a3b38f7Smrg	;;
41467a3b38f7Smrg      -s)
41477a3b38f7Smrg	stripme=" -s"
41487a3b38f7Smrg	continue
41497a3b38f7Smrg	;;
41507a3b38f7Smrg      -*)
41517a3b38f7Smrg	;;
41527a3b38f7Smrg      *)
41537a3b38f7Smrg	# If the previous option needed an argument, then skip it.
41547a3b38f7Smrg	if test -n "$prev"; then
41556fc0178dSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
415644dda7b2Smrg	    arg2=$install_override_mode
415744dda7b2Smrg	    no_mode=false
415844dda7b2Smrg	  fi
41597a3b38f7Smrg	  prev=
41607a3b38f7Smrg	else
41617a3b38f7Smrg	  dest=$arg
41627a3b38f7Smrg	  continue
41637a3b38f7Smrg	fi
41647a3b38f7Smrg	;;
41657a3b38f7Smrg      esac
4166ff559fabSmrg
41677a3b38f7Smrg      # Aesthetically quote the argument.
41687a3b38f7Smrg      func_quote_for_eval "$arg"
4169862f5301Smrg      func_append install_prog " $func_quote_for_eval_result"
417044dda7b2Smrg      if test -n "$arg2"; then
417144dda7b2Smrg	func_quote_for_eval "$arg2"
417244dda7b2Smrg      fi
4173862f5301Smrg      func_append install_shared_prog " $func_quote_for_eval_result"
41747a3b38f7Smrg    done
4175ff559fabSmrg
41767a3b38f7Smrg    test -z "$install_prog" && \
41777a3b38f7Smrg      func_fatal_help "you must specify an install program"
4178ff559fabSmrg
41797a3b38f7Smrg    test -n "$prev" && \
41806fc0178dSmrg      func_fatal_help "the '$prev' option requires an argument"
4181ff559fabSmrg
418244dda7b2Smrg    if test -n "$install_override_mode" && $no_mode; then
418344dda7b2Smrg      if $install_cp; then :; else
418444dda7b2Smrg	func_quote_for_eval "$install_override_mode"
4185862f5301Smrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
418644dda7b2Smrg      fi
418744dda7b2Smrg    fi
418844dda7b2Smrg
41897a3b38f7Smrg    if test -z "$files"; then
41907a3b38f7Smrg      if test -z "$dest"; then
41917a3b38f7Smrg	func_fatal_help "no file or destination specified"
41927a3b38f7Smrg      else
41937a3b38f7Smrg	func_fatal_help "you must specify a destination"
4194ff559fabSmrg      fi
4195ff559fabSmrg    fi
4196ff559fabSmrg
41977a3b38f7Smrg    # Strip any trailing slash from the destination.
41987a3b38f7Smrg    func_stripname '' '/' "$dest"
41997a3b38f7Smrg    dest=$func_stripname_result
4200ff559fabSmrg
42017a3b38f7Smrg    # Check to see that the destination is a directory.
42026fc0178dSmrg    test -d "$dest" && isdir=:
42036fc0178dSmrg    if $isdir; then
42046fc0178dSmrg      destdir=$dest
42057a3b38f7Smrg      destname=
42067a3b38f7Smrg    else
42077a3b38f7Smrg      func_dirname_and_basename "$dest" "" "."
42086fc0178dSmrg      destdir=$func_dirname_result
42096fc0178dSmrg      destname=$func_basename_result
42107a3b38f7Smrg
42117a3b38f7Smrg      # Not a directory, so check to see that there is only one file specified.
42127a3b38f7Smrg      set dummy $files; shift
42137a3b38f7Smrg      test "$#" -gt 1 && \
42146fc0178dSmrg	func_fatal_help "'$dest' is not a directory"
42157a3b38f7Smrg    fi
42167a3b38f7Smrg    case $destdir in
42177a3b38f7Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4218ff559fabSmrg    *)
42197a3b38f7Smrg      for file in $files; do
42207a3b38f7Smrg	case $file in
42217a3b38f7Smrg	*.lo) ;;
42227a3b38f7Smrg	*)
42236fc0178dSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
42247a3b38f7Smrg	  ;;
42257a3b38f7Smrg	esac
42267a3b38f7Smrg      done
4227ff559fabSmrg      ;;
4228ff559fabSmrg    esac
4229ff559fabSmrg
42307a3b38f7Smrg    # This variable tells wrapper scripts just to set variables rather
42317a3b38f7Smrg    # than running their programs.
42326fc0178dSmrg    libtool_install_magic=$magic
4233ff559fabSmrg
42347a3b38f7Smrg    staticlibs=
42357a3b38f7Smrg    future_libdirs=
42367a3b38f7Smrg    current_libdirs=
42377a3b38f7Smrg    for file in $files; do
4238ff559fabSmrg
42397a3b38f7Smrg      # Do each installation.
42407a3b38f7Smrg      case $file in
42417a3b38f7Smrg      *.$libext)
42427a3b38f7Smrg	# Do the static libraries later.
4243862f5301Smrg	func_append staticlibs " $file"
42447a3b38f7Smrg	;;
42457a3b38f7Smrg
42467a3b38f7Smrg      *.la)
4247862f5301Smrg	func_resolve_sysroot "$file"
4248862f5301Smrg	file=$func_resolve_sysroot_result
4249862f5301Smrg
42507a3b38f7Smrg	# Check to see that this really is a libtool archive.
42517a3b38f7Smrg	func_lalib_unsafe_p "$file" \
42526fc0178dSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
42537a3b38f7Smrg
42547a3b38f7Smrg	library_names=
42557a3b38f7Smrg	old_library=
42567a3b38f7Smrg	relink_command=
42577a3b38f7Smrg	func_source "$file"
42587a3b38f7Smrg
42597a3b38f7Smrg	# Add the libdir to current_libdirs if it is the destination.
42607a3b38f7Smrg	if test "X$destdir" = "X$libdir"; then
42617a3b38f7Smrg	  case "$current_libdirs " in
42627a3b38f7Smrg	  *" $libdir "*) ;;
4263862f5301Smrg	  *) func_append current_libdirs " $libdir" ;;
4264ff559fabSmrg	  esac
42657a3b38f7Smrg	else
42667a3b38f7Smrg	  # Note the libdir as a future libdir.
42677a3b38f7Smrg	  case "$future_libdirs " in
42687a3b38f7Smrg	  *" $libdir "*) ;;
4269862f5301Smrg	  *) func_append future_libdirs " $libdir" ;;
42707a3b38f7Smrg	  esac
42717a3b38f7Smrg	fi
4272ff559fabSmrg
42737a3b38f7Smrg	func_dirname "$file" "/" ""
42746fc0178dSmrg	dir=$func_dirname_result
4275862f5301Smrg	func_append dir "$objdir"
42767a3b38f7Smrg
42777a3b38f7Smrg	if test -n "$relink_command"; then
42787a3b38f7Smrg	  # Determine the prefix the user has applied to our future dir.
427944dda7b2Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
42807a3b38f7Smrg
42817a3b38f7Smrg	  # Don't allow the user to place us outside of our expected
42827a3b38f7Smrg	  # location b/c this prevents finding dependent libraries that
42837a3b38f7Smrg	  # are installed to the same prefix.
42847a3b38f7Smrg	  # At present, this check doesn't affect windows .dll's that
42857a3b38f7Smrg	  # are installed into $libdir/../bin (currently, that works fine)
42867a3b38f7Smrg	  # but it's something to keep an eye on.
42877a3b38f7Smrg	  test "$inst_prefix_dir" = "$destdir" && \
42886fc0178dSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
42897a3b38f7Smrg
42907a3b38f7Smrg	  if test -n "$inst_prefix_dir"; then
42917a3b38f7Smrg	    # Stick the inst_prefix_dir data into the link command.
429244dda7b2Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
42937a3b38f7Smrg	  else
429444dda7b2Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
42957a3b38f7Smrg	  fi
42967a3b38f7Smrg
42976fc0178dSmrg	  func_warning "relinking '$file'"
42987a3b38f7Smrg	  func_show_eval "$relink_command" \
42996fc0178dSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
43007a3b38f7Smrg	fi
43017a3b38f7Smrg
43027a3b38f7Smrg	# See the names of the shared library.
43037a3b38f7Smrg	set dummy $library_names; shift
43047a3b38f7Smrg	if test -n "$1"; then
43056fc0178dSmrg	  realname=$1
43067a3b38f7Smrg	  shift
43077a3b38f7Smrg
43086fc0178dSmrg	  srcname=$realname
43096fc0178dSmrg	  test -n "$relink_command" && srcname=${realname}T
43107a3b38f7Smrg
43117a3b38f7Smrg	  # Install the shared library and build the symlinks.
431244dda7b2Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
43137a3b38f7Smrg	      'exit $?'
43146fc0178dSmrg	  tstripme=$stripme
43157a3b38f7Smrg	  case $host_os in
43167a3b38f7Smrg	  cygwin* | mingw* | pw32* | cegcc*)
43177a3b38f7Smrg	    case $realname in
43187a3b38f7Smrg	    *.dll.a)
43196fc0178dSmrg	      tstripme=
43206fc0178dSmrg	      ;;
43216fc0178dSmrg	    esac
43226fc0178dSmrg	    ;;
43236fc0178dSmrg	  os2*)
43246fc0178dSmrg	    case $realname in
43256fc0178dSmrg	    *_dll.a)
43266fc0178dSmrg	      tstripme=
43277a3b38f7Smrg	      ;;
43287a3b38f7Smrg	    esac
4329ff559fabSmrg	    ;;
4330ff559fabSmrg	  esac
43317a3b38f7Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
43327a3b38f7Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4333ff559fabSmrg	  fi
43347a3b38f7Smrg
43357a3b38f7Smrg	  if test "$#" -gt 0; then
43367a3b38f7Smrg	    # Delete the old symlinks, and create new ones.
43376fc0178dSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
43387a3b38f7Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
43397a3b38f7Smrg	    # so we also need to try rm && ln -s.
43407a3b38f7Smrg	    for linkname
43417a3b38f7Smrg	    do
43427a3b38f7Smrg	      test "$linkname" != "$realname" \
43437a3b38f7Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4344ff559fabSmrg	    done
4345ff559fabSmrg	  fi
4346ff559fabSmrg
43477a3b38f7Smrg	  # Do each command in the postinstall commands.
43486fc0178dSmrg	  lib=$destdir/$realname
43497a3b38f7Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4350ff559fabSmrg	fi
4351ff559fabSmrg
43527a3b38f7Smrg	# Install the pseudo-library for information purposes.
43537a3b38f7Smrg	func_basename "$file"
43546fc0178dSmrg	name=$func_basename_result
43556fc0178dSmrg	instname=$dir/${name}i
43567a3b38f7Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4357ff559fabSmrg
43587a3b38f7Smrg	# Maybe install the static library, too.
4359862f5301Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
43607a3b38f7Smrg	;;
4361ff559fabSmrg
43627a3b38f7Smrg      *.lo)
43637a3b38f7Smrg	# Install (i.e. copy) a libtool object.
4364ff559fabSmrg
43657a3b38f7Smrg	# Figure out destination file name, if it wasn't already specified.
43667a3b38f7Smrg	if test -n "$destname"; then
43676fc0178dSmrg	  destfile=$destdir/$destname
43687a3b38f7Smrg	else
43697a3b38f7Smrg	  func_basename "$file"
43706fc0178dSmrg	  destfile=$func_basename_result
43716fc0178dSmrg	  destfile=$destdir/$destfile
43727a3b38f7Smrg	fi
43737a3b38f7Smrg
43747a3b38f7Smrg	# Deduce the name of the destination old-style object file.
43757a3b38f7Smrg	case $destfile in
43767a3b38f7Smrg	*.lo)
43777a3b38f7Smrg	  func_lo2o "$destfile"
43787a3b38f7Smrg	  staticdest=$func_lo2o_result
43797a3b38f7Smrg	  ;;
43807a3b38f7Smrg	*.$objext)
43816fc0178dSmrg	  staticdest=$destfile
43827a3b38f7Smrg	  destfile=
43837a3b38f7Smrg	  ;;
43847a3b38f7Smrg	*)
43856fc0178dSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
43867a3b38f7Smrg	  ;;
4387ff559fabSmrg	esac
4388ff559fabSmrg
43897a3b38f7Smrg	# Install the libtool object if requested.
43907a3b38f7Smrg	test -n "$destfile" && \
43917a3b38f7Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
43927a3b38f7Smrg
43937a3b38f7Smrg	# Install the old object if enabled.
43946fc0178dSmrg	if test yes = "$build_old_libs"; then
43957a3b38f7Smrg	  # Deduce the name of the old-style object file.
43967a3b38f7Smrg	  func_lo2o "$file"
43977a3b38f7Smrg	  staticobj=$func_lo2o_result
43987a3b38f7Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4399ff559fabSmrg	fi
44007a3b38f7Smrg	exit $EXIT_SUCCESS
44017a3b38f7Smrg	;;
4402ff559fabSmrg
44037a3b38f7Smrg      *)
44047a3b38f7Smrg	# Figure out destination file name, if it wasn't already specified.
44057a3b38f7Smrg	if test -n "$destname"; then
44066fc0178dSmrg	  destfile=$destdir/$destname
44077a3b38f7Smrg	else
44087a3b38f7Smrg	  func_basename "$file"
44096fc0178dSmrg	  destfile=$func_basename_result
44106fc0178dSmrg	  destfile=$destdir/$destfile
44117a3b38f7Smrg	fi
44127a3b38f7Smrg
44137a3b38f7Smrg	# If the file is missing, and there is a .exe on the end, strip it
44147a3b38f7Smrg	# because it is most likely a libtool script we actually want to
44157a3b38f7Smrg	# install
44166fc0178dSmrg	stripped_ext=
44177a3b38f7Smrg	case $file in
44187a3b38f7Smrg	  *.exe)
44197a3b38f7Smrg	    if test ! -f "$file"; then
44207a3b38f7Smrg	      func_stripname '' '.exe' "$file"
44217a3b38f7Smrg	      file=$func_stripname_result
44226fc0178dSmrg	      stripped_ext=.exe
4423ff559fabSmrg	    fi
44247a3b38f7Smrg	    ;;
44257a3b38f7Smrg	esac
4426ff559fabSmrg
44277a3b38f7Smrg	# Do a test to see if this is really a libtool program.
44287a3b38f7Smrg	case $host in
44297a3b38f7Smrg	*cygwin* | *mingw*)
44307a3b38f7Smrg	    if func_ltwrapper_executable_p "$file"; then
44317a3b38f7Smrg	      func_ltwrapper_scriptname "$file"
44327a3b38f7Smrg	      wrapper=$func_ltwrapper_scriptname_result
44337a3b38f7Smrg	    else
44347a3b38f7Smrg	      func_stripname '' '.exe' "$file"
44357a3b38f7Smrg	      wrapper=$func_stripname_result
44367a3b38f7Smrg	    fi
44377a3b38f7Smrg	    ;;
44387a3b38f7Smrg	*)
44397a3b38f7Smrg	    wrapper=$file
44407a3b38f7Smrg	    ;;
44417a3b38f7Smrg	esac
44427a3b38f7Smrg	if func_ltwrapper_script_p "$wrapper"; then
44437a3b38f7Smrg	  notinst_deplibs=
44447a3b38f7Smrg	  relink_command=
4445ff559fabSmrg
44467a3b38f7Smrg	  func_source "$wrapper"
4447ff559fabSmrg
44487a3b38f7Smrg	  # Check the variables that should have been set.
44497a3b38f7Smrg	  test -z "$generated_by_libtool_version" && \
44506fc0178dSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
44517a3b38f7Smrg
44526fc0178dSmrg	  finalize=:
44537a3b38f7Smrg	  for lib in $notinst_deplibs; do
44547a3b38f7Smrg	    # Check to see that each library is installed.
44557a3b38f7Smrg	    libdir=
44567a3b38f7Smrg	    if test -f "$lib"; then
44577a3b38f7Smrg	      func_source "$lib"
44587a3b38f7Smrg	    fi
44596fc0178dSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
44607a3b38f7Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
44616fc0178dSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
44626fc0178dSmrg	      finalize=false
44637a3b38f7Smrg	    fi
44647a3b38f7Smrg	  done
44657a3b38f7Smrg
44667a3b38f7Smrg	  relink_command=
44677a3b38f7Smrg	  func_source "$wrapper"
44687a3b38f7Smrg
44697a3b38f7Smrg	  outputname=
44706fc0178dSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
44717a3b38f7Smrg	    $opt_dry_run || {
44726fc0178dSmrg	      if $finalize; then
44737a3b38f7Smrg	        tmpdir=`func_mktempdir`
44747a3b38f7Smrg		func_basename "$file$stripped_ext"
44756fc0178dSmrg		file=$func_basename_result
44766fc0178dSmrg	        outputname=$tmpdir/$file
44777a3b38f7Smrg	        # Replace the output file specification.
447844dda7b2Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
44797a3b38f7Smrg
44806fc0178dSmrg	        $opt_quiet || {
44817a3b38f7Smrg	          func_quote_for_expand "$relink_command"
44827a3b38f7Smrg		  eval "func_echo $func_quote_for_expand_result"
44837a3b38f7Smrg	        }
44847a3b38f7Smrg	        if eval "$relink_command"; then :
44857a3b38f7Smrg	          else
44866fc0178dSmrg		  func_error "error: relink '$file' with the above command before installing it"
44877a3b38f7Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
44887a3b38f7Smrg		  continue
44897a3b38f7Smrg	        fi
44906fc0178dSmrg	        file=$outputname
44917a3b38f7Smrg	      else
44926fc0178dSmrg	        func_warning "cannot relink '$file'"
44937a3b38f7Smrg	      fi
44947a3b38f7Smrg	    }
4495ff559fabSmrg	  else
44967a3b38f7Smrg	    # Install the binary that we compiled earlier.
449744dda7b2Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4498ff559fabSmrg	  fi
44997a3b38f7Smrg	fi
4500ff559fabSmrg
45017a3b38f7Smrg	# remove .exe since cygwin /usr/bin/install will append another
45027a3b38f7Smrg	# one anyway
45037a3b38f7Smrg	case $install_prog,$host in
45047a3b38f7Smrg	*/usr/bin/install*,*cygwin*)
45057a3b38f7Smrg	  case $file:$destfile in
45067a3b38f7Smrg	  *.exe:*.exe)
45077a3b38f7Smrg	    # this is ok
45087a3b38f7Smrg	    ;;
45097a3b38f7Smrg	  *.exe:*)
45107a3b38f7Smrg	    destfile=$destfile.exe
45117a3b38f7Smrg	    ;;
45127a3b38f7Smrg	  *:*.exe)
45137a3b38f7Smrg	    func_stripname '' '.exe' "$destfile"
45147a3b38f7Smrg	    destfile=$func_stripname_result
45157a3b38f7Smrg	    ;;
45167a3b38f7Smrg	  esac
4517ff559fabSmrg	  ;;
4518ff559fabSmrg	esac
45197a3b38f7Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
45207a3b38f7Smrg	$opt_dry_run || if test -n "$outputname"; then
45217a3b38f7Smrg	  ${RM}r "$tmpdir"
45227a3b38f7Smrg	fi
45237a3b38f7Smrg	;;
45247a3b38f7Smrg      esac
45257a3b38f7Smrg    done
4526ff559fabSmrg
45277a3b38f7Smrg    for file in $staticlibs; do
45287a3b38f7Smrg      func_basename "$file"
45296fc0178dSmrg      name=$func_basename_result
4530ff559fabSmrg
45317a3b38f7Smrg      # Set up the ranlib parameters.
45326fc0178dSmrg      oldlib=$destdir/$name
4533fc544a13Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4534fc544a13Smrg      tool_oldlib=$func_to_tool_file_result
4535ff559fabSmrg
45367a3b38f7Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4537ff559fabSmrg
45387a3b38f7Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4539fc544a13Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
45407a3b38f7Smrg      fi
4541ff559fabSmrg
45427a3b38f7Smrg      # Do each command in the postinstall commands.
45437a3b38f7Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
45447a3b38f7Smrg    done
4545ff559fabSmrg
45467a3b38f7Smrg    test -n "$future_libdirs" && \
45476fc0178dSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4548ff559fabSmrg
45497a3b38f7Smrg    if test -n "$current_libdirs"; then
45507a3b38f7Smrg      # Maybe just do a dry run.
45517a3b38f7Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
45526fc0178dSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
45537a3b38f7Smrg    else
45547a3b38f7Smrg      exit $EXIT_SUCCESS
45557a3b38f7Smrg    fi
45567a3b38f7Smrg}
4557ff559fabSmrg
45586fc0178dSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4559ff559fabSmrg
4560ff559fabSmrg
45617a3b38f7Smrg# func_generate_dlsyms outputname originator pic_p
45627a3b38f7Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
45637a3b38f7Smrg# a dlpreopen symbol table.
45647a3b38f7Smrgfunc_generate_dlsyms ()
45657a3b38f7Smrg{
45666fc0178dSmrg    $debug_cmd
45676fc0178dSmrg
45686fc0178dSmrg    my_outputname=$1
45696fc0178dSmrg    my_originator=$2
45706fc0178dSmrg    my_pic_p=${3-false}
45716fc0178dSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
45727a3b38f7Smrg    my_dlsyms=
45737a3b38f7Smrg
45746fc0178dSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
45757a3b38f7Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
45766fc0178dSmrg	my_dlsyms=${my_outputname}S.c
45777a3b38f7Smrg      else
45787a3b38f7Smrg	func_error "not configured to extract global symbols from dlpreopened files"
45797a3b38f7Smrg      fi
45807a3b38f7Smrg    fi
4581ff559fabSmrg
45827a3b38f7Smrg    if test -n "$my_dlsyms"; then
45837a3b38f7Smrg      case $my_dlsyms in
45847a3b38f7Smrg      "") ;;
45857a3b38f7Smrg      *.c)
45867a3b38f7Smrg	# Discover the nlist of each of the dlfiles.
45876fc0178dSmrg	nlist=$output_objdir/$my_outputname.nm
45887a3b38f7Smrg
45897a3b38f7Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
45907a3b38f7Smrg
45917a3b38f7Smrg	# Parse the name list into a source file.
45927a3b38f7Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
45937a3b38f7Smrg
45947a3b38f7Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
45956fc0178dSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
45966fc0178dSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
45977a3b38f7Smrg
45987a3b38f7Smrg#ifdef __cplusplus
45997a3b38f7Smrgextern \"C\" {
46007a3b38f7Smrg#endif
46017a3b38f7Smrg
46026fc0178dSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
460344dda7b2Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
460444dda7b2Smrg#endif
460544dda7b2Smrg
4606862f5301Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
46076fc0178dSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
46086fc0178dSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4609862f5301Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4610862f5301Smrg# define LT_DLSYM_CONST
46116fc0178dSmrg#elif defined __osf__
4612862f5301Smrg/* This system does not cope well with relocations in const data.  */
4613862f5301Smrg# define LT_DLSYM_CONST
4614862f5301Smrg#else
4615862f5301Smrg# define LT_DLSYM_CONST const
4616862f5301Smrg#endif
4617862f5301Smrg
46186fc0178dSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
46196fc0178dSmrg
46207a3b38f7Smrg/* External symbol declarations for the compiler. */\
46217a3b38f7Smrg"
46227a3b38f7Smrg
46236fc0178dSmrg	if test yes = "$dlself"; then
46246fc0178dSmrg	  func_verbose "generating symbol list for '$output'"
46257a3b38f7Smrg
46267a3b38f7Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
46277a3b38f7Smrg
46287a3b38f7Smrg	  # Add our own program objects to the symbol list.
462944dda7b2Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
46307a3b38f7Smrg	  for progfile in $progfiles; do
4631862f5301Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
46326fc0178dSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4633862f5301Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
46347a3b38f7Smrg	  done
46357a3b38f7Smrg
46367a3b38f7Smrg	  if test -n "$exclude_expsyms"; then
46377a3b38f7Smrg	    $opt_dry_run || {
46387a3b38f7Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
46397a3b38f7Smrg	      eval '$MV "$nlist"T "$nlist"'
46407a3b38f7Smrg	    }
4641ff559fabSmrg	  fi
4642ff559fabSmrg
46437a3b38f7Smrg	  if test -n "$export_symbols_regex"; then
46447a3b38f7Smrg	    $opt_dry_run || {
46457a3b38f7Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
46467a3b38f7Smrg	      eval '$MV "$nlist"T "$nlist"'
46477a3b38f7Smrg	    }
4648ff559fabSmrg	  fi
46497a3b38f7Smrg
46507a3b38f7Smrg	  # Prepare the list of exported symbols
46517a3b38f7Smrg	  if test -z "$export_symbols"; then
46526fc0178dSmrg	    export_symbols=$output_objdir/$outputname.exp
46537a3b38f7Smrg	    $opt_dry_run || {
46547a3b38f7Smrg	      $RM $export_symbols
46556fc0178dSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
46567a3b38f7Smrg	      case $host in
46577a3b38f7Smrg	      *cygwin* | *mingw* | *cegcc* )
46587a3b38f7Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
46597a3b38f7Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
46607a3b38f7Smrg	        ;;
4661ff559fabSmrg	      esac
46627a3b38f7Smrg	    }
46637a3b38f7Smrg	  else
46647a3b38f7Smrg	    $opt_dry_run || {
46656fc0178dSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
46667a3b38f7Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
46677a3b38f7Smrg	      eval '$MV "$nlist"T "$nlist"'
46687a3b38f7Smrg	      case $host in
466944dda7b2Smrg	        *cygwin* | *mingw* | *cegcc* )
46707a3b38f7Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
46717a3b38f7Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
46727a3b38f7Smrg	          ;;
4673ff559fabSmrg	      esac
46747a3b38f7Smrg	    }
4675ff559fabSmrg	  fi
46767a3b38f7Smrg	fi
4677ff559fabSmrg
46787a3b38f7Smrg	for dlprefile in $dlprefiles; do
46796fc0178dSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
46807a3b38f7Smrg	  func_basename "$dlprefile"
46816fc0178dSmrg	  name=$func_basename_result
4682862f5301Smrg          case $host in
4683862f5301Smrg	    *cygwin* | *mingw* | *cegcc* )
4684862f5301Smrg	      # if an import library, we need to obtain dlname
4685862f5301Smrg	      if func_win32_import_lib_p "$dlprefile"; then
4686862f5301Smrg	        func_tr_sh "$dlprefile"
4687862f5301Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
46886fc0178dSmrg	        dlprefile_dlbasename=
4689862f5301Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4690862f5301Smrg	          # Use subshell, to avoid clobbering current variable values
4691862f5301Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
46926fc0178dSmrg	          if test -n "$dlprefile_dlname"; then
4693862f5301Smrg	            func_basename "$dlprefile_dlname"
46946fc0178dSmrg	            dlprefile_dlbasename=$func_basename_result
4695862f5301Smrg	          else
4696862f5301Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4697862f5301Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4698862f5301Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4699862f5301Smrg	          fi
4700862f5301Smrg	        fi
4701862f5301Smrg	        $opt_dry_run || {
47026fc0178dSmrg	          if test -n "$dlprefile_dlbasename"; then
4703862f5301Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4704862f5301Smrg	          else
4705862f5301Smrg	            func_warning "Could not compute DLL name from $name"
4706862f5301Smrg	            eval '$ECHO ": $name " >> "$nlist"'
4707862f5301Smrg	          fi
4708862f5301Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4709862f5301Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4710862f5301Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4711862f5301Smrg	        }
4712862f5301Smrg	      else # not an import lib
4713862f5301Smrg	        $opt_dry_run || {
4714862f5301Smrg	          eval '$ECHO ": $name " >> "$nlist"'
4715862f5301Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4716862f5301Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4717862f5301Smrg	        }
4718862f5301Smrg	      fi
4719862f5301Smrg	    ;;
4720862f5301Smrg	    *)
4721862f5301Smrg	      $opt_dry_run || {
4722862f5301Smrg	        eval '$ECHO ": $name " >> "$nlist"'
4723862f5301Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4724862f5301Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4725862f5301Smrg	      }
4726862f5301Smrg	    ;;
4727862f5301Smrg          esac
47287a3b38f7Smrg	done
4729ff559fabSmrg
47307a3b38f7Smrg	$opt_dry_run || {
47317a3b38f7Smrg	  # Make sure we have at least an empty file.
47327a3b38f7Smrg	  test -f "$nlist" || : > "$nlist"
4733ff559fabSmrg
47347a3b38f7Smrg	  if test -n "$exclude_expsyms"; then
47357a3b38f7Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
47367a3b38f7Smrg	    $MV "$nlist"T "$nlist"
4737ff559fabSmrg	  fi
4738ff559fabSmrg
47397a3b38f7Smrg	  # Try sorting and uniquifying the output.
47407a3b38f7Smrg	  if $GREP -v "^: " < "$nlist" |
47417a3b38f7Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
47427a3b38f7Smrg		sort -k 3
4743ff559fabSmrg	      else
47447a3b38f7Smrg		sort +2
47457a3b38f7Smrg	      fi |
47467a3b38f7Smrg	      uniq > "$nlist"S; then
47477a3b38f7Smrg	    :
4748ff559fabSmrg	  else
47497a3b38f7Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4750ff559fabSmrg	  fi
4751ff559fabSmrg
47527a3b38f7Smrg	  if test -f "$nlist"S; then
47537a3b38f7Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
4754ff559fabSmrg	  else
475544dda7b2Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
4756ff559fabSmrg	  fi
4757ff559fabSmrg
47586fc0178dSmrg	  func_show_eval '$RM "${nlist}I"'
47596fc0178dSmrg	  if test -n "$global_symbol_to_import"; then
47606fc0178dSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
47616fc0178dSmrg	  fi
47626fc0178dSmrg
476344dda7b2Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
4764ff559fabSmrg
47657a3b38f7Smrg/* The mapping between symbol names and symbols.  */
47667a3b38f7Smrgtypedef struct {
47677a3b38f7Smrg  const char *name;
47687a3b38f7Smrg  void *address;
47697a3b38f7Smrg} lt_dlsymlist;
4770862f5301Smrgextern LT_DLSYM_CONST lt_dlsymlist
47716fc0178dSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
47726fc0178dSmrg"
47736fc0178dSmrg
47746fc0178dSmrg	  if test -s "$nlist"I; then
47756fc0178dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47766fc0178dSmrgstatic void lt_syminit(void)
47776fc0178dSmrg{
47786fc0178dSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
47796fc0178dSmrg  for (; symbol->name; ++symbol)
47806fc0178dSmrg    {"
47816fc0178dSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
47826fc0178dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47836fc0178dSmrg    }
47846fc0178dSmrg}"
47856fc0178dSmrg	  fi
47866fc0178dSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
4787862f5301SmrgLT_DLSYM_CONST lt_dlsymlist
47887a3b38f7Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
47896fc0178dSmrg{ {\"$my_originator\", (void *) 0},"
47906fc0178dSmrg
47916fc0178dSmrg	  if test -s "$nlist"I; then
47926fc0178dSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
47936fc0178dSmrg  {\"@INIT@\", (void *) &lt_syminit},"
47946fc0178dSmrg	  fi
47957a3b38f7Smrg
47967a3b38f7Smrg	  case $need_lib_prefix in
47977a3b38f7Smrg	  no)
47987a3b38f7Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
47997a3b38f7Smrg	    ;;
48007a3b38f7Smrg	  *)
48017a3b38f7Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
48027a3b38f7Smrg	    ;;
48037a3b38f7Smrg	  esac
480444dda7b2Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
48057a3b38f7Smrg  {0, (void *) 0}
48067a3b38f7Smrg};
48077a3b38f7Smrg
48087a3b38f7Smrg/* This works around a problem in FreeBSD linker */
48097a3b38f7Smrg#ifdef FREEBSD_WORKAROUND
48107a3b38f7Smrgstatic const void *lt_preloaded_setup() {
48117a3b38f7Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
48127a3b38f7Smrg}
48137a3b38f7Smrg#endif
48147a3b38f7Smrg
48157a3b38f7Smrg#ifdef __cplusplus
48167a3b38f7Smrg}
48177a3b38f7Smrg#endif\
48187a3b38f7Smrg"
48197a3b38f7Smrg	} # !$opt_dry_run
48207a3b38f7Smrg
48217a3b38f7Smrg	pic_flag_for_symtable=
48227a3b38f7Smrg	case "$compile_command " in
48237a3b38f7Smrg	*" -static "*) ;;
48247a3b38f7Smrg	*)
48257a3b38f7Smrg	  case $host in
48267a3b38f7Smrg	  # compiling the symbol table file with pic_flag works around
48277a3b38f7Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
48287a3b38f7Smrg	  # linked before any other PIC object.  But we must not use
48297a3b38f7Smrg	  # pic_flag when linking with -static.  The problem exists in
48307a3b38f7Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
4831fc544a13Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
48327a3b38f7Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
48337a3b38f7Smrg	  *-*-hpux*)
48347a3b38f7Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
48357a3b38f7Smrg	  *)
48366fc0178dSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
48377a3b38f7Smrg	    ;;
48387a3b38f7Smrg	  esac
48397a3b38f7Smrg	  ;;
48407a3b38f7Smrg	esac
48417a3b38f7Smrg	symtab_cflags=
48427a3b38f7Smrg	for arg in $LTCFLAGS; do
48437a3b38f7Smrg	  case $arg in
48447a3b38f7Smrg	  -pie | -fpie | -fPIE) ;;
4845862f5301Smrg	  *) func_append symtab_cflags " $arg" ;;
48467a3b38f7Smrg	  esac
48477a3b38f7Smrg	done
4848ff559fabSmrg
48497a3b38f7Smrg	# Now compile the dynamic symbol file.
48507a3b38f7Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
4851ff559fabSmrg
48527a3b38f7Smrg	# Clean up the generated files.
48536fc0178dSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
48547a3b38f7Smrg
48557a3b38f7Smrg	# Transform the symbol file into the correct name.
48566fc0178dSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
48577a3b38f7Smrg	case $host in
48587a3b38f7Smrg	*cygwin* | *mingw* | *cegcc* )
48597a3b38f7Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
486044dda7b2Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
486144dda7b2Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
48627a3b38f7Smrg	  else
486344dda7b2Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
486444dda7b2Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
48657a3b38f7Smrg	  fi
48667a3b38f7Smrg	  ;;
48677a3b38f7Smrg	*)
486844dda7b2Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
486944dda7b2Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4870ff559fabSmrg	  ;;
4871ff559fabSmrg	esac
48727a3b38f7Smrg	;;
48737a3b38f7Smrg      *)
48746fc0178dSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
48757a3b38f7Smrg	;;
48767a3b38f7Smrg      esac
48777a3b38f7Smrg    else
48787a3b38f7Smrg      # We keep going just in case the user didn't refer to
48797a3b38f7Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
48807a3b38f7Smrg      # really was required.
48817a3b38f7Smrg
48827a3b38f7Smrg      # Nullify the symbol file.
488344dda7b2Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
488444dda7b2Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
4885ff559fabSmrg    fi
48867a3b38f7Smrg}
4887ff559fabSmrg
48886fc0178dSmrg# func_cygming_gnu_implib_p ARG
48896fc0178dSmrg# This predicate returns with zero status (TRUE) if
48906fc0178dSmrg# ARG is a GNU/binutils-style import library. Returns
48916fc0178dSmrg# with nonzero status (FALSE) otherwise.
48926fc0178dSmrgfunc_cygming_gnu_implib_p ()
48936fc0178dSmrg{
48946fc0178dSmrg  $debug_cmd
48956fc0178dSmrg
48966fc0178dSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
48976fc0178dSmrg  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)$'`
48986fc0178dSmrg  test -n "$func_cygming_gnu_implib_tmp"
48996fc0178dSmrg}
49006fc0178dSmrg
49016fc0178dSmrg# func_cygming_ms_implib_p ARG
49026fc0178dSmrg# This predicate returns with zero status (TRUE) if
49036fc0178dSmrg# ARG is an MS-style import library. Returns
49046fc0178dSmrg# with nonzero status (FALSE) otherwise.
49056fc0178dSmrgfunc_cygming_ms_implib_p ()
49066fc0178dSmrg{
49076fc0178dSmrg  $debug_cmd
49086fc0178dSmrg
49096fc0178dSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
49106fc0178dSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
49116fc0178dSmrg  test -n "$func_cygming_ms_implib_tmp"
49126fc0178dSmrg}
49136fc0178dSmrg
49147a3b38f7Smrg# func_win32_libid arg
49157a3b38f7Smrg# return the library type of file 'arg'
49167a3b38f7Smrg#
49177a3b38f7Smrg# Need a lot of goo to handle *both* DLLs and import libs
49187a3b38f7Smrg# Has to be a shell function in order to 'eat' the argument
49197a3b38f7Smrg# that is supplied when $file_magic_command is called.
492044dda7b2Smrg# Despite the name, also deal with 64 bit binaries.
49217a3b38f7Smrgfunc_win32_libid ()
49227a3b38f7Smrg{
49236fc0178dSmrg  $debug_cmd
49246fc0178dSmrg
49256fc0178dSmrg  win32_libid_type=unknown
49267a3b38f7Smrg  win32_fileres=`file -L $1 2>/dev/null`
49277a3b38f7Smrg  case $win32_fileres in
49287a3b38f7Smrg  *ar\ archive\ import\ library*) # definitely import
49297a3b38f7Smrg    win32_libid_type="x86 archive import"
49307a3b38f7Smrg    ;;
49317a3b38f7Smrg  *ar\ archive*) # could be an import, or static
493244dda7b2Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
49337a3b38f7Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
493444dda7b2Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
49356fc0178dSmrg      case $nm_interface in
49366fc0178dSmrg      "MS dumpbin")
49376fc0178dSmrg	if func_cygming_ms_implib_p "$1" ||
49386fc0178dSmrg	   func_cygming_gnu_implib_p "$1"
49396fc0178dSmrg	then
49406fc0178dSmrg	  win32_nmres=import
49416fc0178dSmrg	else
49426fc0178dSmrg	  win32_nmres=
49436fc0178dSmrg	fi
49446fc0178dSmrg	;;
49456fc0178dSmrg      *)
49466fc0178dSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
49476fc0178dSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
49486fc0178dSmrg	  $SED -n -e '
49497a3b38f7Smrg	    1,100{
49507a3b38f7Smrg		/ I /{
49516fc0178dSmrg		    s|.*|import|
49527a3b38f7Smrg		    p
49537a3b38f7Smrg		    q
49547a3b38f7Smrg		}
49557a3b38f7Smrg	    }'`
49566fc0178dSmrg	;;
49576fc0178dSmrg      esac
49587a3b38f7Smrg      case $win32_nmres in
49597a3b38f7Smrg      import*)  win32_libid_type="x86 archive import";;
49607a3b38f7Smrg      *)        win32_libid_type="x86 archive static";;
49617a3b38f7Smrg      esac
49627a3b38f7Smrg    fi
49637a3b38f7Smrg    ;;
49647a3b38f7Smrg  *DLL*)
49657a3b38f7Smrg    win32_libid_type="x86 DLL"
49667a3b38f7Smrg    ;;
49677a3b38f7Smrg  *executable*) # but shell scripts are "executable" too...
49687a3b38f7Smrg    case $win32_fileres in
49697a3b38f7Smrg    *MS\ Windows\ PE\ Intel*)
49707a3b38f7Smrg      win32_libid_type="x86 DLL"
49717a3b38f7Smrg      ;;
49727a3b38f7Smrg    esac
49737a3b38f7Smrg    ;;
49747a3b38f7Smrg  esac
49757a3b38f7Smrg  $ECHO "$win32_libid_type"
49767a3b38f7Smrg}
4977ff559fabSmrg
4978862f5301Smrg# func_cygming_dll_for_implib ARG
4979862f5301Smrg#
4980862f5301Smrg# Platform-specific function to extract the
4981862f5301Smrg# name of the DLL associated with the specified
4982862f5301Smrg# import library ARG.
4983862f5301Smrg# Invoked by eval'ing the libtool variable
4984862f5301Smrg#    $sharedlib_from_linklib_cmd
4985862f5301Smrg# Result is available in the variable
4986862f5301Smrg#    $sharedlib_from_linklib_result
4987862f5301Smrgfunc_cygming_dll_for_implib ()
4988862f5301Smrg{
49896fc0178dSmrg  $debug_cmd
49906fc0178dSmrg
4991862f5301Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
4992862f5301Smrg}
4993862f5301Smrg
4994862f5301Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
4995862f5301Smrg#
4996862f5301Smrg# The is the core of a fallback implementation of a
4997862f5301Smrg# platform-specific function to extract the name of the
4998862f5301Smrg# DLL associated with the specified import library LIBNAME.
4999862f5301Smrg#
5000862f5301Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5001862f5301Smrg# on the platform and compiler that created the implib.
5002862f5301Smrg#
5003862f5301Smrg# Echos the name of the DLL associated with the
5004862f5301Smrg# specified import library.
5005862f5301Smrgfunc_cygming_dll_for_implib_fallback_core ()
5006862f5301Smrg{
50076fc0178dSmrg  $debug_cmd
50086fc0178dSmrg
5009862f5301Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5010862f5301Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5011862f5301Smrg    $SED '/^Contents of section '"$match_literal"':/{
5012862f5301Smrg      # Place marker at beginning of archive member dllname section
5013862f5301Smrg      s/.*/====MARK====/
5014862f5301Smrg      p
5015862f5301Smrg      d
5016862f5301Smrg    }
5017862f5301Smrg    # These lines can sometimes be longer than 43 characters, but
5018862f5301Smrg    # are always uninteresting
5019862f5301Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
5020862f5301Smrg    /^In archive [^:]*:/d
5021862f5301Smrg    # Ensure marker is printed
5022862f5301Smrg    /^====MARK====/p
5023862f5301Smrg    # Remove all lines with less than 43 characters
5024862f5301Smrg    /^.\{43\}/!d
5025862f5301Smrg    # From remaining lines, remove first 43 characters
5026862f5301Smrg    s/^.\{43\}//' |
5027862f5301Smrg    $SED -n '
5028862f5301Smrg      # Join marker and all lines until next marker into a single line
5029862f5301Smrg      /^====MARK====/ b para
5030862f5301Smrg      H
5031862f5301Smrg      $ b para
5032862f5301Smrg      b
5033862f5301Smrg      :para
5034862f5301Smrg      x
5035862f5301Smrg      s/\n//g
5036862f5301Smrg      # Remove the marker
5037862f5301Smrg      s/^====MARK====//
5038862f5301Smrg      # Remove trailing dots and whitespace
5039862f5301Smrg      s/[\. \t]*$//
5040862f5301Smrg      # Print
5041862f5301Smrg      /./p' |
5042862f5301Smrg    # we now have a list, one entry per line, of the stringified
5043862f5301Smrg    # contents of the appropriate section of all members of the
50446fc0178dSmrg    # archive that possess that section. Heuristic: eliminate
50456fc0178dSmrg    # all those that have a first or second character that is
5046862f5301Smrg    # a '.' (that is, objdump's representation of an unprintable
5047862f5301Smrg    # character.) This should work for all archives with less than
5048862f5301Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
5049862f5301Smrg    # begins with a literal '.' or a single character followed by
5050862f5301Smrg    # a '.'.
5051862f5301Smrg    #
5052862f5301Smrg    # Of those that remain, print the first one.
5053862f5301Smrg    $SED -e '/^\./d;/^.\./d;q'
5054862f5301Smrg}
5055862f5301Smrg
5056862f5301Smrg# func_cygming_dll_for_implib_fallback ARG
5057862f5301Smrg# Platform-specific function to extract the
5058862f5301Smrg# name of the DLL associated with the specified
5059862f5301Smrg# import library ARG.
5060862f5301Smrg#
5061862f5301Smrg# This fallback implementation is for use when $DLLTOOL
5062862f5301Smrg# does not support the --identify-strict option.
5063862f5301Smrg# Invoked by eval'ing the libtool variable
5064862f5301Smrg#    $sharedlib_from_linklib_cmd
5065862f5301Smrg# Result is available in the variable
5066862f5301Smrg#    $sharedlib_from_linklib_result
5067862f5301Smrgfunc_cygming_dll_for_implib_fallback ()
5068862f5301Smrg{
50696fc0178dSmrg  $debug_cmd
50706fc0178dSmrg
50716fc0178dSmrg  if func_cygming_gnu_implib_p "$1"; then
5072862f5301Smrg    # binutils import library
5073862f5301Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
50746fc0178dSmrg  elif func_cygming_ms_implib_p "$1"; then
5075862f5301Smrg    # ms-generated import library
5076862f5301Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5077862f5301Smrg  else
5078862f5301Smrg    # unknown
50796fc0178dSmrg    sharedlib_from_linklib_result=
5080862f5301Smrg  fi
5081862f5301Smrg}
5082ff559fabSmrg
5083ff559fabSmrg
50847a3b38f7Smrg# func_extract_an_archive dir oldlib
50857a3b38f7Smrgfunc_extract_an_archive ()
50867a3b38f7Smrg{
50876fc0178dSmrg    $debug_cmd
50886fc0178dSmrg
50896fc0178dSmrg    f_ex_an_ar_dir=$1; shift
50906fc0178dSmrg    f_ex_an_ar_oldlib=$1
50916fc0178dSmrg    if test yes = "$lock_old_archive_extraction"; then
509244dda7b2Smrg      lockfile=$f_ex_an_ar_oldlib.lock
509344dda7b2Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
509444dda7b2Smrg	func_echo "Waiting for $lockfile to be removed"
509544dda7b2Smrg	sleep 2
509644dda7b2Smrg      done
509744dda7b2Smrg    fi
509844dda7b2Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
509944dda7b2Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
51006fc0178dSmrg    if test yes = "$lock_old_archive_extraction"; then
510144dda7b2Smrg      $opt_dry_run || rm -f "$lockfile"
510244dda7b2Smrg    fi
51037a3b38f7Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
51047a3b38f7Smrg     :
51057a3b38f7Smrg    else
51067a3b38f7Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
51077a3b38f7Smrg    fi
51087a3b38f7Smrg}
5109ff559fabSmrg
5110ff559fabSmrg
51117a3b38f7Smrg# func_extract_archives gentop oldlib ...
51127a3b38f7Smrgfunc_extract_archives ()
51137a3b38f7Smrg{
51146fc0178dSmrg    $debug_cmd
51156fc0178dSmrg
51166fc0178dSmrg    my_gentop=$1; shift
51177a3b38f7Smrg    my_oldlibs=${1+"$@"}
51186fc0178dSmrg    my_oldobjs=
51196fc0178dSmrg    my_xlib=
51206fc0178dSmrg    my_xabs=
51216fc0178dSmrg    my_xdir=
5122ff559fabSmrg
51237a3b38f7Smrg    for my_xlib in $my_oldlibs; do
51247a3b38f7Smrg      # Extract the objects.
51257a3b38f7Smrg      case $my_xlib in
51266fc0178dSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
51277a3b38f7Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
51287a3b38f7Smrg      esac
51297a3b38f7Smrg      func_basename "$my_xlib"
51306fc0178dSmrg      my_xlib=$func_basename_result
51317a3b38f7Smrg      my_xlib_u=$my_xlib
51327a3b38f7Smrg      while :; do
51337a3b38f7Smrg        case " $extracted_archives " in
51347a3b38f7Smrg	*" $my_xlib_u "*)
51357a3b38f7Smrg	  func_arith $extracted_serial + 1
51367a3b38f7Smrg	  extracted_serial=$func_arith_result
51377a3b38f7Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
51387a3b38f7Smrg	*) break ;;
51397a3b38f7Smrg	esac
51407a3b38f7Smrg      done
51417a3b38f7Smrg      extracted_archives="$extracted_archives $my_xlib_u"
51426fc0178dSmrg      my_xdir=$my_gentop/$my_xlib_u
5143ff559fabSmrg
51447a3b38f7Smrg      func_mkdir_p "$my_xdir"
5145ff559fabSmrg
51467a3b38f7Smrg      case $host in
51477a3b38f7Smrg      *-darwin*)
51487a3b38f7Smrg	func_verbose "Extracting $my_xabs"
51497a3b38f7Smrg	# Do not bother doing anything if just a dry run
51507a3b38f7Smrg	$opt_dry_run || {
51517a3b38f7Smrg	  darwin_orig_dir=`pwd`
51527a3b38f7Smrg	  cd $my_xdir || exit $?
51537a3b38f7Smrg	  darwin_archive=$my_xabs
51547a3b38f7Smrg	  darwin_curdir=`pwd`
51556fc0178dSmrg	  func_basename "$darwin_archive"
51566fc0178dSmrg	  darwin_base_archive=$func_basename_result
51577a3b38f7Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
51587a3b38f7Smrg	  if test -n "$darwin_arches"; then
51597a3b38f7Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
51607a3b38f7Smrg	    darwin_arch=
51617a3b38f7Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
51626fc0178dSmrg	    for darwin_arch in  $darwin_arches; do
51636fc0178dSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
51646fc0178dSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
51656fc0178dSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
51666fc0178dSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
51677a3b38f7Smrg	      cd "$darwin_curdir"
51686fc0178dSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
51697a3b38f7Smrg	    done # $darwin_arches
51707a3b38f7Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
51716fc0178dSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
51727a3b38f7Smrg	    darwin_file=
51737a3b38f7Smrg	    darwin_files=
51747a3b38f7Smrg	    for darwin_file in $darwin_filelist; do
517544dda7b2Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
51767a3b38f7Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
51777a3b38f7Smrg	    done # $darwin_filelist
51787a3b38f7Smrg	    $RM -rf unfat-$$
51797a3b38f7Smrg	    cd "$darwin_orig_dir"
51807a3b38f7Smrg	  else
51817a3b38f7Smrg	    cd $darwin_orig_dir
51827a3b38f7Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
51837a3b38f7Smrg	  fi # $darwin_arches
51847a3b38f7Smrg	} # !$opt_dry_run
51857a3b38f7Smrg	;;
51867a3b38f7Smrg      *)
51877a3b38f7Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
51887a3b38f7Smrg	;;
5189ff559fabSmrg      esac
519044dda7b2Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
51917a3b38f7Smrg    done
5192ff559fabSmrg
51936fc0178dSmrg    func_extract_archives_result=$my_oldobjs
51947a3b38f7Smrg}
5195ff559fabSmrg
5196ff559fabSmrg
519744dda7b2Smrg# func_emit_wrapper [arg=no]
519844dda7b2Smrg#
519944dda7b2Smrg# Emit a libtool wrapper script on stdout.
520044dda7b2Smrg# Don't directly open a file because we may want to
520144dda7b2Smrg# incorporate the script contents within a cygwin/mingw
520244dda7b2Smrg# wrapper executable.  Must ONLY be called from within
520344dda7b2Smrg# func_mode_link because it depends on a number of variables
520444dda7b2Smrg# set therein.
52057a3b38f7Smrg#
520644dda7b2Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
520744dda7b2Smrg# variable will take.  If 'yes', then the emitted script
52086fc0178dSmrg# will assume that the directory where it is stored is
520944dda7b2Smrg# the $objdir directory.  This is a cygwin/mingw-specific
521044dda7b2Smrg# behavior.
521144dda7b2Smrgfunc_emit_wrapper ()
52127a3b38f7Smrg{
521344dda7b2Smrg	func_emit_wrapper_arg1=${1-no}
5214ff559fabSmrg
52157a3b38f7Smrg	$ECHO "\
52167a3b38f7Smrg#! $SHELL
5217ff559fabSmrg
52187a3b38f7Smrg# $output - temporary wrapper script for $objdir/$outputname
52196fc0178dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
52207a3b38f7Smrg#
52217a3b38f7Smrg# The $output program cannot be directly executed until all the libtool
52227a3b38f7Smrg# libraries that it depends on are installed.
52237a3b38f7Smrg#
52247a3b38f7Smrg# This wrapper script should never be moved out of the build directory.
52257a3b38f7Smrg# If it is, it will not operate correctly.
5226ff559fabSmrg
52277a3b38f7Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
52287a3b38f7Smrg# metacharacters that are still active within double-quoted strings.
52297a3b38f7Smrgsed_quote_subst='$sed_quote_subst'
5230ff559fabSmrg
52317a3b38f7Smrg# Be Bourne compatible
52327a3b38f7Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
52337a3b38f7Smrg  emulate sh
52347a3b38f7Smrg  NULLCMD=:
52357a3b38f7Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
52367a3b38f7Smrg  # is contrary to our usage.  Disable this feature.
52377a3b38f7Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
52387a3b38f7Smrg  setopt NO_GLOB_SUBST
52397a3b38f7Smrgelse
52407a3b38f7Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
52417a3b38f7Smrgfi
52427a3b38f7SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
52437a3b38f7SmrgDUALCASE=1; export DUALCASE # for MKS sh
5244ff559fabSmrg
52457a3b38f7Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
52467a3b38f7Smrg# if CDPATH is set.
52477a3b38f7Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5248ff559fabSmrg
52497a3b38f7Smrgrelink_command=\"$relink_command\"
5250ff559fabSmrg
52517a3b38f7Smrg# This environment variable determines our operation mode.
52527a3b38f7Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
52537a3b38f7Smrg  # install mode needs the following variables:
52547a3b38f7Smrg  generated_by_libtool_version='$macro_version'
52557a3b38f7Smrg  notinst_deplibs='$notinst_deplibs'
52567a3b38f7Smrgelse
52577a3b38f7Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
52587a3b38f7Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
525944dda7b2Smrg    file=\"\$0\""
526044dda7b2Smrg
526144dda7b2Smrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
526244dda7b2Smrg    $ECHO "\
526344dda7b2Smrg
526444dda7b2Smrg# A function that is used when there is no print builtin or printf.
526544dda7b2Smrgfunc_fallback_echo ()
526644dda7b2Smrg{
526744dda7b2Smrg  eval 'cat <<_LTECHO_EOF
526844dda7b2Smrg\$1
526944dda7b2Smrg_LTECHO_EOF'
527044dda7b2Smrg}
527144dda7b2Smrg    ECHO=\"$qECHO\"
527244dda7b2Smrg  fi
527344dda7b2Smrg
527444dda7b2Smrg# Very basic option parsing. These options are (a) specific to
527544dda7b2Smrg# the libtool wrapper, (b) are identical between the wrapper
52766fc0178dSmrg# /script/ and the wrapper /executable/ that is used only on
527744dda7b2Smrg# windows platforms, and (c) all begin with the string "--lt-"
52786fc0178dSmrg# (application programs are unlikely to have options that match
527944dda7b2Smrg# this pattern).
528044dda7b2Smrg#
528144dda7b2Smrg# There are only two supported options: --lt-debug and
528244dda7b2Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
528344dda7b2Smrg#
528444dda7b2Smrg# The first argument to this parsing function should be the
528544dda7b2Smrg# script's $0 value, followed by "$@".
528644dda7b2Smrglt_option_debug=
528744dda7b2Smrgfunc_parse_lt_options ()
528844dda7b2Smrg{
528944dda7b2Smrg  lt_script_arg0=\$0
529044dda7b2Smrg  shift
529144dda7b2Smrg  for lt_opt
529244dda7b2Smrg  do
529344dda7b2Smrg    case \"\$lt_opt\" in
529444dda7b2Smrg    --lt-debug) lt_option_debug=1 ;;
529544dda7b2Smrg    --lt-dump-script)
529644dda7b2Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
529744dda7b2Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
529844dda7b2Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
529944dda7b2Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
530044dda7b2Smrg        exit 0
530144dda7b2Smrg      ;;
530244dda7b2Smrg    --lt-*)
530344dda7b2Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
530444dda7b2Smrg        exit 1
530544dda7b2Smrg      ;;
530644dda7b2Smrg    esac
530744dda7b2Smrg  done
530844dda7b2Smrg
530944dda7b2Smrg  # Print the debug banner immediately:
531044dda7b2Smrg  if test -n \"\$lt_option_debug\"; then
53116fc0178dSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
531244dda7b2Smrg  fi
531344dda7b2Smrg}
531444dda7b2Smrg
531544dda7b2Smrg# Used when --lt-debug. Prints its arguments to stdout
531644dda7b2Smrg# (redirection is the responsibility of the caller)
531744dda7b2Smrgfunc_lt_dump_args ()
531844dda7b2Smrg{
531944dda7b2Smrg  lt_dump_args_N=1;
532044dda7b2Smrg  for lt_arg
532144dda7b2Smrg  do
53226fc0178dSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
532344dda7b2Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
532444dda7b2Smrg  done
532544dda7b2Smrg}
532644dda7b2Smrg
532744dda7b2Smrg# Core function for launching the target application
532844dda7b2Smrgfunc_exec_program_core ()
532944dda7b2Smrg{
53307a3b38f7Smrg"
533144dda7b2Smrg  case $host in
533244dda7b2Smrg  # Backslashes separate directories on plain windows
533344dda7b2Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
533444dda7b2Smrg    $ECHO "\
533544dda7b2Smrg      if test -n \"\$lt_option_debug\"; then
53366fc0178dSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
533744dda7b2Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
533844dda7b2Smrg      fi
533944dda7b2Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
534044dda7b2Smrg"
534144dda7b2Smrg    ;;
534244dda7b2Smrg
534344dda7b2Smrg  *)
534444dda7b2Smrg    $ECHO "\
534544dda7b2Smrg      if test -n \"\$lt_option_debug\"; then
53466fc0178dSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
534744dda7b2Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
534844dda7b2Smrg      fi
534944dda7b2Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
535044dda7b2Smrg"
535144dda7b2Smrg    ;;
535244dda7b2Smrg  esac
535344dda7b2Smrg  $ECHO "\
535444dda7b2Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
535544dda7b2Smrg      exit 1
535644dda7b2Smrg}
535744dda7b2Smrg
535844dda7b2Smrg# A function to encapsulate launching the target application
535944dda7b2Smrg# Strips options in the --lt-* namespace from \$@ and
536044dda7b2Smrg# launches target application with the remaining arguments.
536144dda7b2Smrgfunc_exec_program ()
536244dda7b2Smrg{
5363fc544a13Smrg  case \" \$* \" in
5364fc544a13Smrg  *\\ --lt-*)
5365fc544a13Smrg    for lt_wr_arg
5366fc544a13Smrg    do
5367fc544a13Smrg      case \$lt_wr_arg in
5368fc544a13Smrg      --lt-*) ;;
5369fc544a13Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5370fc544a13Smrg      esac
5371fc544a13Smrg      shift
5372fc544a13Smrg    done ;;
5373fc544a13Smrg  esac
537444dda7b2Smrg  func_exec_program_core \${1+\"\$@\"}
537544dda7b2Smrg}
537644dda7b2Smrg
537744dda7b2Smrg  # Parse options
537844dda7b2Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5379ff559fabSmrg
53807a3b38f7Smrg  # Find the directory that this script lives in.
538144dda7b2Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
53827a3b38f7Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5383ff559fabSmrg
53847a3b38f7Smrg  # Follow symbolic links until we get to the real thisdir.
538544dda7b2Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
53867a3b38f7Smrg  while test -n \"\$file\"; do
538744dda7b2Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5388ff559fabSmrg
53897a3b38f7Smrg    # If there was a directory component, then change thisdir.
53907a3b38f7Smrg    if test \"x\$destdir\" != \"x\$file\"; then
53917a3b38f7Smrg      case \"\$destdir\" in
53927a3b38f7Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
53937a3b38f7Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
53947a3b38f7Smrg      esac
53957a3b38f7Smrg    fi
5396ff559fabSmrg
539744dda7b2Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
539844dda7b2Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
53997a3b38f7Smrg  done
5400ff559fabSmrg
54017a3b38f7Smrg  # Usually 'no', except on cygwin/mingw when embedded into
54027a3b38f7Smrg  # the cwrapper.
540344dda7b2Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
54047a3b38f7Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
54057a3b38f7Smrg    # special case for '.'
54067a3b38f7Smrg    if test \"\$thisdir\" = \".\"; then
54077a3b38f7Smrg      thisdir=\`pwd\`
54087a3b38f7Smrg    fi
54097a3b38f7Smrg    # remove .libs from thisdir
54107a3b38f7Smrg    case \"\$thisdir\" in
541144dda7b2Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
54127a3b38f7Smrg    $objdir )   thisdir=. ;;
54137a3b38f7Smrg    esac
54147a3b38f7Smrg  fi
5415ff559fabSmrg
54167a3b38f7Smrg  # Try to get the absolute directory name.
54177a3b38f7Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
54187a3b38f7Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
54197a3b38f7Smrg"
5420ff559fabSmrg
54216fc0178dSmrg	if test yes = "$fast_install"; then
54227a3b38f7Smrg	  $ECHO "\
54237a3b38f7Smrg  program=lt-'$outputname'$exeext
54247a3b38f7Smrg  progdir=\"\$thisdir/$objdir\"
5425ff559fabSmrg
54267a3b38f7Smrg  if test ! -f \"\$progdir/\$program\" ||
54276fc0178dSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
54287a3b38f7Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5429ff559fabSmrg
54307a3b38f7Smrg    file=\"\$\$-\$program\"
5431ff559fabSmrg
54327a3b38f7Smrg    if test ! -d \"\$progdir\"; then
54337a3b38f7Smrg      $MKDIR \"\$progdir\"
54347a3b38f7Smrg    else
54357a3b38f7Smrg      $RM \"\$progdir/\$file\"
54367a3b38f7Smrg    fi"
5437ff559fabSmrg
54387a3b38f7Smrg	  $ECHO "\
5439ff559fabSmrg
54407a3b38f7Smrg    # relink executable if necessary
54417a3b38f7Smrg    if test -n \"\$relink_command\"; then
54427a3b38f7Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
54437a3b38f7Smrg      else
54446fc0178dSmrg	\$ECHO \"\$relink_command_output\" >&2
54457a3b38f7Smrg	$RM \"\$progdir/\$file\"
54467a3b38f7Smrg	exit 1
54477a3b38f7Smrg      fi
54487a3b38f7Smrg    fi
5449ff559fabSmrg
54507a3b38f7Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
54517a3b38f7Smrg    { $RM \"\$progdir/\$program\";
54527a3b38f7Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
54537a3b38f7Smrg    $RM \"\$progdir/\$file\"
54547a3b38f7Smrg  fi"
54557a3b38f7Smrg	else
54567a3b38f7Smrg	  $ECHO "\
54577a3b38f7Smrg  program='$outputname'
54587a3b38f7Smrg  progdir=\"\$thisdir/$objdir\"
54597a3b38f7Smrg"
54607a3b38f7Smrg	fi
5461ff559fabSmrg
54627a3b38f7Smrg	$ECHO "\
5463ff559fabSmrg
54647a3b38f7Smrg  if test -f \"\$progdir/\$program\"; then"
5465ff559fabSmrg
5466862f5301Smrg	# fixup the dll searchpath if we need to.
5467862f5301Smrg	#
5468862f5301Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5469862f5301Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5470862f5301Smrg	# libraries must come first.
5471862f5301Smrg	if test -n "$dllsearchpath"; then
5472862f5301Smrg	  $ECHO "\
5473862f5301Smrg    # Add the dll search path components to the executable PATH
5474862f5301Smrg    PATH=$dllsearchpath:\$PATH
5475862f5301Smrg"
5476862f5301Smrg	fi
5477862f5301Smrg
54787a3b38f7Smrg	# Export our shlibpath_var if we have one.
54796fc0178dSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
54807a3b38f7Smrg	  $ECHO "\
54817a3b38f7Smrg    # Add our own library path to $shlibpath_var
54827a3b38f7Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5483ff559fabSmrg
54847a3b38f7Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
54857a3b38f7Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
548644dda7b2Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5487ff559fabSmrg
54887a3b38f7Smrg    export $shlibpath_var
54897a3b38f7Smrg"
5490ff559fabSmrg	fi
5491ff559fabSmrg
54927a3b38f7Smrg	$ECHO "\
54937a3b38f7Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
54947a3b38f7Smrg      # Run the actual program with our arguments.
549544dda7b2Smrg      func_exec_program \${1+\"\$@\"}
54967a3b38f7Smrg    fi
54977a3b38f7Smrg  else
54987a3b38f7Smrg    # The program doesn't exist.
54996fc0178dSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
55007a3b38f7Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
550144dda7b2Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
55027a3b38f7Smrg    exit 1
55037a3b38f7Smrg  fi
55047a3b38f7Smrgfi\
55057a3b38f7Smrg"
55067a3b38f7Smrg}
5507ff559fabSmrg
5508ff559fabSmrg
55097a3b38f7Smrg# func_emit_cwrapperexe_src
55107a3b38f7Smrg# emit the source code for a wrapper executable on stdout
55117a3b38f7Smrg# Must ONLY be called from within func_mode_link because
55127a3b38f7Smrg# it depends on a number of variable set therein.
55137a3b38f7Smrgfunc_emit_cwrapperexe_src ()
55147a3b38f7Smrg{
55157a3b38f7Smrg	cat <<EOF
5516ff559fabSmrg
55177a3b38f7Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
55186fc0178dSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5519ff559fabSmrg
55207a3b38f7Smrg   The $output program cannot be directly executed until all the libtool
55217a3b38f7Smrg   libraries that it depends on are installed.
5522ff559fabSmrg
55237a3b38f7Smrg   This wrapper executable should never be moved out of the build directory.
55247a3b38f7Smrg   If it is, it will not operate correctly.
55257a3b38f7Smrg*/
55267a3b38f7SmrgEOF
55277a3b38f7Smrg	    cat <<"EOF"
552844dda7b2Smrg#ifdef _MSC_VER
552944dda7b2Smrg# define _CRT_SECURE_NO_DEPRECATE 1
553044dda7b2Smrg#endif
55317a3b38f7Smrg#include <stdio.h>
55327a3b38f7Smrg#include <stdlib.h>
55337a3b38f7Smrg#ifdef _MSC_VER
55347a3b38f7Smrg# include <direct.h>
55357a3b38f7Smrg# include <process.h>
55367a3b38f7Smrg# include <io.h>
55377a3b38f7Smrg#else
55387a3b38f7Smrg# include <unistd.h>
55397a3b38f7Smrg# include <stdint.h>
55407a3b38f7Smrg# ifdef __CYGWIN__
55417a3b38f7Smrg#  include <io.h>
55427a3b38f7Smrg# endif
55437a3b38f7Smrg#endif
55447a3b38f7Smrg#include <malloc.h>
55457a3b38f7Smrg#include <stdarg.h>
55467a3b38f7Smrg#include <assert.h>
55477a3b38f7Smrg#include <string.h>
55487a3b38f7Smrg#include <ctype.h>
55497a3b38f7Smrg#include <errno.h>
55507a3b38f7Smrg#include <fcntl.h>
55517a3b38f7Smrg#include <sys/stat.h>
55527a3b38f7Smrg
55536fc0178dSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
55546fc0178dSmrg
555544dda7b2Smrg/* declarations of non-ANSI functions */
55566fc0178dSmrg#if defined __MINGW32__
555744dda7b2Smrg# ifdef __STRICT_ANSI__
555844dda7b2Smrgint _putenv (const char *);
555944dda7b2Smrg# endif
55606fc0178dSmrg#elif defined __CYGWIN__
556144dda7b2Smrg# ifdef __STRICT_ANSI__
556244dda7b2Smrgchar *realpath (const char *, char *);
556344dda7b2Smrgint putenv (char *);
556444dda7b2Smrgint setenv (const char *, const char *, int);
556544dda7b2Smrg# endif
55666fc0178dSmrg/* #elif defined other_platform || defined ... */
556744dda7b2Smrg#endif
556844dda7b2Smrg
556944dda7b2Smrg/* portability defines, excluding path handling macros */
55706fc0178dSmrg#if defined _MSC_VER
557144dda7b2Smrg# define setmode _setmode
557244dda7b2Smrg# define stat    _stat
557344dda7b2Smrg# define chmod   _chmod
557444dda7b2Smrg# define getcwd  _getcwd
557544dda7b2Smrg# define putenv  _putenv
557644dda7b2Smrg# define S_IXUSR _S_IEXEC
55776fc0178dSmrg#elif defined __MINGW32__
557844dda7b2Smrg# define setmode _setmode
557944dda7b2Smrg# define stat    _stat
558044dda7b2Smrg# define chmod   _chmod
558144dda7b2Smrg# define getcwd  _getcwd
558244dda7b2Smrg# define putenv  _putenv
55836fc0178dSmrg#elif defined __CYGWIN__
558444dda7b2Smrg# define HAVE_SETENV
558544dda7b2Smrg# define FOPEN_WB "wb"
55866fc0178dSmrg/* #elif defined other platforms ... */
558744dda7b2Smrg#endif
558844dda7b2Smrg
55896fc0178dSmrg#if defined PATH_MAX
55907a3b38f7Smrg# define LT_PATHMAX PATH_MAX
55916fc0178dSmrg#elif defined MAXPATHLEN
55927a3b38f7Smrg# define LT_PATHMAX MAXPATHLEN
55937a3b38f7Smrg#else
55947a3b38f7Smrg# define LT_PATHMAX 1024
55957a3b38f7Smrg#endif
55967a3b38f7Smrg
55977a3b38f7Smrg#ifndef S_IXOTH
55987a3b38f7Smrg# define S_IXOTH 0
55997a3b38f7Smrg#endif
56007a3b38f7Smrg#ifndef S_IXGRP
56017a3b38f7Smrg# define S_IXGRP 0
56027a3b38f7Smrg#endif
56037a3b38f7Smrg
560444dda7b2Smrg/* path handling portability macros */
56057a3b38f7Smrg#ifndef DIR_SEPARATOR
56067a3b38f7Smrg# define DIR_SEPARATOR '/'
56077a3b38f7Smrg# define PATH_SEPARATOR ':'
56087a3b38f7Smrg#endif
56097a3b38f7Smrg
56106fc0178dSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
56116fc0178dSmrg  defined __OS2__
56127a3b38f7Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
56137a3b38f7Smrg# define FOPEN_WB "wb"
56147a3b38f7Smrg# ifndef DIR_SEPARATOR_2
56157a3b38f7Smrg#  define DIR_SEPARATOR_2 '\\'
56167a3b38f7Smrg# endif
56177a3b38f7Smrg# ifndef PATH_SEPARATOR_2
56187a3b38f7Smrg#  define PATH_SEPARATOR_2 ';'
56197a3b38f7Smrg# endif
56207a3b38f7Smrg#endif
56217a3b38f7Smrg
56227a3b38f7Smrg#ifndef DIR_SEPARATOR_2
56237a3b38f7Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
56247a3b38f7Smrg#else /* DIR_SEPARATOR_2 */
56257a3b38f7Smrg# define IS_DIR_SEPARATOR(ch) \
56267a3b38f7Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
56277a3b38f7Smrg#endif /* DIR_SEPARATOR_2 */
56287a3b38f7Smrg
56297a3b38f7Smrg#ifndef PATH_SEPARATOR_2
56307a3b38f7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
56317a3b38f7Smrg#else /* PATH_SEPARATOR_2 */
56327a3b38f7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
56337a3b38f7Smrg#endif /* PATH_SEPARATOR_2 */
56347a3b38f7Smrg
56357a3b38f7Smrg#ifndef FOPEN_WB
56367a3b38f7Smrg# define FOPEN_WB "w"
56377a3b38f7Smrg#endif
56387a3b38f7Smrg#ifndef _O_BINARY
56397a3b38f7Smrg# define _O_BINARY 0
56407a3b38f7Smrg#endif
56417a3b38f7Smrg
56427a3b38f7Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
56437a3b38f7Smrg#define XFREE(stale) do { \
56446fc0178dSmrg  if (stale) { free (stale); stale = 0; } \
56457a3b38f7Smrg} while (0)
56467a3b38f7Smrg
56476fc0178dSmrg#if defined LT_DEBUGWRAPPER
564844dda7b2Smrgstatic int lt_debug = 1;
56497a3b38f7Smrg#else
565044dda7b2Smrgstatic int lt_debug = 0;
56517a3b38f7Smrg#endif
56527a3b38f7Smrg
565344dda7b2Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
56547a3b38f7Smrg
56557a3b38f7Smrgvoid *xmalloc (size_t num);
56567a3b38f7Smrgchar *xstrdup (const char *string);
56577a3b38f7Smrgconst char *base_name (const char *name);
56587a3b38f7Smrgchar *find_executable (const char *wrapper);
56597a3b38f7Smrgchar *chase_symlinks (const char *pathspec);
56607a3b38f7Smrgint make_executable (const char *path);
56617a3b38f7Smrgint check_executable (const char *path);
56627a3b38f7Smrgchar *strendzap (char *str, const char *pat);
566344dda7b2Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
566444dda7b2Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
566544dda7b2Smrgstatic const char *nonnull (const char *s);
566644dda7b2Smrgstatic const char *nonempty (const char *s);
56677a3b38f7Smrgvoid lt_setenv (const char *name, const char *value);
56687a3b38f7Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
56697a3b38f7Smrgvoid lt_update_exe_path (const char *name, const char *value);
56707a3b38f7Smrgvoid lt_update_lib_path (const char *name, const char *value);
567144dda7b2Smrgchar **prepare_spawn (char **argv);
567244dda7b2Smrgvoid lt_dump_script (FILE *f);
56737a3b38f7SmrgEOF
56747a3b38f7Smrg
56757a3b38f7Smrg	    cat <<EOF
56766fc0178dSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
56776fc0178dSmrg# define externally_visible volatile
56786fc0178dSmrg#else
56796fc0178dSmrg# define externally_visible __attribute__((externally_visible)) volatile
56806fc0178dSmrg#endif
56816fc0178dSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
56827a3b38f7Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
56837a3b38f7SmrgEOF
56847a3b38f7Smrg
56856fc0178dSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5686862f5301Smrg              func_to_host_path "$temp_rpath"
56877a3b38f7Smrg	      cat <<EOF
5688862f5301Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5689ff559fabSmrgEOF
5690ff559fabSmrg	    else
56917a3b38f7Smrg	      cat <<"EOF"
56927a3b38f7Smrgconst char * LIB_PATH_VALUE   = "";
56937a3b38f7SmrgEOF
5694ff559fabSmrg	    fi
56957a3b38f7Smrg
56967a3b38f7Smrg	    if test -n "$dllsearchpath"; then
5697862f5301Smrg              func_to_host_path "$dllsearchpath:"
56987a3b38f7Smrg	      cat <<EOF
56997a3b38f7Smrgconst char * EXE_PATH_VARNAME = "PATH";
5700862f5301Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
57017a3b38f7SmrgEOF
5702ff559fabSmrg	    else
57037a3b38f7Smrg	      cat <<"EOF"
57047a3b38f7Smrgconst char * EXE_PATH_VARNAME = "";
57057a3b38f7Smrgconst char * EXE_PATH_VALUE   = "";
57067a3b38f7SmrgEOF
5707ff559fabSmrg	    fi
57087a3b38f7Smrg
57096fc0178dSmrg	    if test yes = "$fast_install"; then
57107a3b38f7Smrg	      cat <<EOF
57117a3b38f7Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
57127a3b38f7SmrgEOF
5713ff559fabSmrg	    else
57147a3b38f7Smrg	      cat <<EOF
57157a3b38f7Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
57167a3b38f7SmrgEOF
5717ff559fabSmrg	    fi
5718ff559fabSmrg
5719ff559fabSmrg
57207a3b38f7Smrg	    cat <<"EOF"
5721ff559fabSmrg
57227a3b38f7Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5723ff559fabSmrg
57247a3b38f7Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
57257a3b38f7Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
572644dda7b2Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5727ff559fabSmrg
57287a3b38f7Smrgint
57297a3b38f7Smrgmain (int argc, char *argv[])
57307a3b38f7Smrg{
57317a3b38f7Smrg  char **newargz;
57327a3b38f7Smrg  int  newargc;
57337a3b38f7Smrg  char *tmp_pathspec;
57347a3b38f7Smrg  char *actual_cwrapper_path;
57357a3b38f7Smrg  char *actual_cwrapper_name;
57367a3b38f7Smrg  char *target_name;
57377a3b38f7Smrg  char *lt_argv_zero;
57386fc0178dSmrg  int rval = 127;
5739ff559fabSmrg
57407a3b38f7Smrg  int i;
5741ff559fabSmrg
57427a3b38f7Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
57436fc0178dSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5744ff559fabSmrg
574544dda7b2Smrg  /* very simple arg parsing; don't want to rely on getopt
574644dda7b2Smrg   * also, copy all non cwrapper options to newargz, except
574744dda7b2Smrg   * argz[0], which is handled differently
574844dda7b2Smrg   */
574944dda7b2Smrg  newargc=0;
57507a3b38f7Smrg  for (i = 1; i < argc; i++)
57517a3b38f7Smrg    {
57526fc0178dSmrg      if (STREQ (argv[i], dumpscript_opt))
57537a3b38f7Smrg	{
57547a3b38f7SmrgEOF
57556fc0178dSmrg	    case $host in
57567a3b38f7Smrg	      *mingw* | *cygwin* )
57577a3b38f7Smrg		# make stdout use "unix" line endings
57587a3b38f7Smrg		echo "          setmode(1,_O_BINARY);"
57597a3b38f7Smrg		;;
57607a3b38f7Smrg	      esac
5761ff559fabSmrg
57627a3b38f7Smrg	    cat <<"EOF"
576344dda7b2Smrg	  lt_dump_script (stdout);
57647a3b38f7Smrg	  return 0;
57657a3b38f7Smrg	}
57666fc0178dSmrg      if (STREQ (argv[i], debug_opt))
576744dda7b2Smrg	{
576844dda7b2Smrg          lt_debug = 1;
576944dda7b2Smrg          continue;
577044dda7b2Smrg	}
57716fc0178dSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
577244dda7b2Smrg        {
577344dda7b2Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
577444dda7b2Smrg             namespace, but it is not one of the ones we know about and
577544dda7b2Smrg             have already dealt with, above (inluding dump-script), then
577644dda7b2Smrg             report an error. Otherwise, targets might begin to believe
577744dda7b2Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
577844dda7b2Smrg             namespace. The first time any user complains about this, we'll
577944dda7b2Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
578044dda7b2Smrg             or a configure.ac-settable value.
578144dda7b2Smrg           */
578244dda7b2Smrg          lt_fatal (__FILE__, __LINE__,
578344dda7b2Smrg		    "unrecognized %s option: '%s'",
578444dda7b2Smrg                    ltwrapper_option_prefix, argv[i]);
578544dda7b2Smrg        }
578644dda7b2Smrg      /* otherwise ... */
578744dda7b2Smrg      newargz[++newargc] = xstrdup (argv[i]);
57887a3b38f7Smrg    }
578944dda7b2Smrg  newargz[++newargc] = NULL;
579044dda7b2Smrg
579144dda7b2SmrgEOF
579244dda7b2Smrg	    cat <<EOF
579344dda7b2Smrg  /* The GNU banner must be the first non-error debug message */
57946fc0178dSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
579544dda7b2SmrgEOF
579644dda7b2Smrg	    cat <<"EOF"
579744dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
579844dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
5799ff559fabSmrg
58007a3b38f7Smrg  tmp_pathspec = find_executable (argv[0]);
58017a3b38f7Smrg  if (tmp_pathspec == NULL)
580244dda7b2Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
580344dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
580444dda7b2Smrg                  "(main) found exe (before symlink chase) at: %s\n",
580544dda7b2Smrg		  tmp_pathspec);
58067a3b38f7Smrg
58077a3b38f7Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
580844dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
580944dda7b2Smrg                  "(main) found exe (after symlink chase) at: %s\n",
581044dda7b2Smrg		  actual_cwrapper_path);
58117a3b38f7Smrg  XFREE (tmp_pathspec);
58127a3b38f7Smrg
581344dda7b2Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
58147a3b38f7Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
58157a3b38f7Smrg
58167a3b38f7Smrg  /* wrapper name transforms */
58177a3b38f7Smrg  strendzap (actual_cwrapper_name, ".exe");
58187a3b38f7Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
58197a3b38f7Smrg  XFREE (actual_cwrapper_name);
58207a3b38f7Smrg  actual_cwrapper_name = tmp_pathspec;
58217a3b38f7Smrg  tmp_pathspec = 0;
58227a3b38f7Smrg
58237a3b38f7Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
58247a3b38f7Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
58257a3b38f7Smrg  strendzap (target_name, ".exe");
58267a3b38f7Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
58277a3b38f7Smrg  XFREE (target_name);
58287a3b38f7Smrg  target_name = tmp_pathspec;
58297a3b38f7Smrg  tmp_pathspec = 0;
58307a3b38f7Smrg
583144dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
583244dda7b2Smrg		  "(main) libtool target name: %s\n",
583344dda7b2Smrg		  target_name);
58347a3b38f7SmrgEOF
5835ff559fabSmrg
58367a3b38f7Smrg	    cat <<EOF
58377a3b38f7Smrg  newargz[0] =
58387a3b38f7Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
58397a3b38f7Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
58407a3b38f7Smrg  strcpy (newargz[0], actual_cwrapper_path);
58417a3b38f7Smrg  strcat (newargz[0], "$objdir");
58427a3b38f7Smrg  strcat (newargz[0], "/");
58437a3b38f7SmrgEOF
5844ff559fabSmrg
58457a3b38f7Smrg	    cat <<"EOF"
58467a3b38f7Smrg  /* stop here, and copy so we don't have to do this twice */
58477a3b38f7Smrg  tmp_pathspec = xstrdup (newargz[0]);
5848ff559fabSmrg
58497a3b38f7Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
58507a3b38f7Smrg  strcat (newargz[0], actual_cwrapper_name);
5851ff559fabSmrg
58527a3b38f7Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
58537a3b38f7Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
58547a3b38f7Smrg  XFREE (tmp_pathspec);
58557a3b38f7Smrg  tmp_pathspec = NULL;
58567a3b38f7SmrgEOF
5857ff559fabSmrg
58587a3b38f7Smrg	    case $host_os in
58597a3b38f7Smrg	      mingw*)
58607a3b38f7Smrg	    cat <<"EOF"
58617a3b38f7Smrg  {
58627a3b38f7Smrg    char* p;
58637a3b38f7Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
58647a3b38f7Smrg      {
58657a3b38f7Smrg	*p = '/';
58667a3b38f7Smrg      }
58677a3b38f7Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
58687a3b38f7Smrg      {
58697a3b38f7Smrg	*p = '/';
58707a3b38f7Smrg      }
58717a3b38f7Smrg  }
58727a3b38f7SmrgEOF
58737a3b38f7Smrg	    ;;
58747a3b38f7Smrg	    esac
5875ff559fabSmrg
58767a3b38f7Smrg	    cat <<"EOF"
58777a3b38f7Smrg  XFREE (target_name);
58787a3b38f7Smrg  XFREE (actual_cwrapper_path);
58797a3b38f7Smrg  XFREE (actual_cwrapper_name);
5880ff559fabSmrg
58817a3b38f7Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
58827a3b38f7Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
5883862f5301Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
5884862f5301Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
5885862f5301Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
5886862f5301Smrg     libraries must come first. */
58877a3b38f7Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
5888862f5301Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
5889ff559fabSmrg
589044dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
589144dda7b2Smrg		  nonnull (lt_argv_zero));
58927a3b38f7Smrg  for (i = 0; i < newargc; i++)
58937a3b38f7Smrg    {
589444dda7b2Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
589544dda7b2Smrg		      i, nonnull (newargz[i]));
58967a3b38f7Smrg    }
5897ff559fabSmrg
58987a3b38f7SmrgEOF
5899ff559fabSmrg
59007a3b38f7Smrg	    case $host_os in
59017a3b38f7Smrg	      mingw*)
59027a3b38f7Smrg		cat <<"EOF"
59037a3b38f7Smrg  /* execv doesn't actually work on mingw as expected on unix */
590444dda7b2Smrg  newargz = prepare_spawn (newargz);
59056fc0178dSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
59067a3b38f7Smrg  if (rval == -1)
59077a3b38f7Smrg    {
59087a3b38f7Smrg      /* failed to start process */
590944dda7b2Smrg      lt_debugprintf (__FILE__, __LINE__,
591044dda7b2Smrg		      "(main) failed to launch target \"%s\": %s\n",
591144dda7b2Smrg		      lt_argv_zero, nonnull (strerror (errno)));
59127a3b38f7Smrg      return 127;
59137a3b38f7Smrg    }
59147a3b38f7Smrg  return rval;
59157a3b38f7SmrgEOF
59167a3b38f7Smrg		;;
59177a3b38f7Smrg	      *)
59187a3b38f7Smrg		cat <<"EOF"
59197a3b38f7Smrg  execv (lt_argv_zero, newargz);
59207a3b38f7Smrg  return rval; /* =127, but avoids unused variable warning */
59217a3b38f7SmrgEOF
59227a3b38f7Smrg		;;
59237a3b38f7Smrg	    esac
5924ff559fabSmrg
59257a3b38f7Smrg	    cat <<"EOF"
59267a3b38f7Smrg}
5927ff559fabSmrg
59287a3b38f7Smrgvoid *
59297a3b38f7Smrgxmalloc (size_t num)
59307a3b38f7Smrg{
59317a3b38f7Smrg  void *p = (void *) malloc (num);
59327a3b38f7Smrg  if (!p)
593344dda7b2Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
5934ff559fabSmrg
59357a3b38f7Smrg  return p;
59367a3b38f7Smrg}
5937ff559fabSmrg
59387a3b38f7Smrgchar *
59397a3b38f7Smrgxstrdup (const char *string)
59407a3b38f7Smrg{
59417a3b38f7Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
59427a3b38f7Smrg			  string) : NULL;
59437a3b38f7Smrg}
5944ff559fabSmrg
59457a3b38f7Smrgconst char *
59467a3b38f7Smrgbase_name (const char *name)
59477a3b38f7Smrg{
59487a3b38f7Smrg  const char *base;
5949ff559fabSmrg
59506fc0178dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
59517a3b38f7Smrg  /* Skip over the disk name in MSDOS pathnames. */
59527a3b38f7Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
59537a3b38f7Smrg    name += 2;
59547a3b38f7Smrg#endif
5955ff559fabSmrg
59567a3b38f7Smrg  for (base = name; *name; name++)
59577a3b38f7Smrg    if (IS_DIR_SEPARATOR (*name))
59587a3b38f7Smrg      base = name + 1;
59597a3b38f7Smrg  return base;
59607a3b38f7Smrg}
5961ff559fabSmrg
59627a3b38f7Smrgint
59637a3b38f7Smrgcheck_executable (const char *path)
59647a3b38f7Smrg{
59657a3b38f7Smrg  struct stat st;
5966ff559fabSmrg
596744dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
596844dda7b2Smrg                  nonempty (path));
59697a3b38f7Smrg  if ((!path) || (!*path))
59707a3b38f7Smrg    return 0;
5971ff559fabSmrg
59727a3b38f7Smrg  if ((stat (path, &st) >= 0)
59737a3b38f7Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
59747a3b38f7Smrg    return 1;
59757a3b38f7Smrg  else
59767a3b38f7Smrg    return 0;
59777a3b38f7Smrg}
5978ff559fabSmrg
59797a3b38f7Smrgint
59807a3b38f7Smrgmake_executable (const char *path)
59817a3b38f7Smrg{
59827a3b38f7Smrg  int rval = 0;
59837a3b38f7Smrg  struct stat st;
5984ff559fabSmrg
598544dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
598644dda7b2Smrg                  nonempty (path));
59877a3b38f7Smrg  if ((!path) || (!*path))
59887a3b38f7Smrg    return 0;
5989ff559fabSmrg
59907a3b38f7Smrg  if (stat (path, &st) >= 0)
59917a3b38f7Smrg    {
59927a3b38f7Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
59937a3b38f7Smrg    }
59947a3b38f7Smrg  return rval;
59957a3b38f7Smrg}
5996ff559fabSmrg
59977a3b38f7Smrg/* Searches for the full path of the wrapper.  Returns
59987a3b38f7Smrg   newly allocated full path name if found, NULL otherwise
59997a3b38f7Smrg   Does not chase symlinks, even on platforms that support them.
60007a3b38f7Smrg*/
60017a3b38f7Smrgchar *
60027a3b38f7Smrgfind_executable (const char *wrapper)
60037a3b38f7Smrg{
60047a3b38f7Smrg  int has_slash = 0;
60057a3b38f7Smrg  const char *p;
60067a3b38f7Smrg  const char *p_next;
60077a3b38f7Smrg  /* static buffer for getcwd */
60087a3b38f7Smrg  char tmp[LT_PATHMAX + 1];
60096fc0178dSmrg  size_t tmp_len;
60107a3b38f7Smrg  char *concat_name;
6011ff559fabSmrg
601244dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
601344dda7b2Smrg                  nonempty (wrapper));
6014ff559fabSmrg
60157a3b38f7Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
60167a3b38f7Smrg    return NULL;
6017ff559fabSmrg
60187a3b38f7Smrg  /* Absolute path? */
60196fc0178dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
60207a3b38f7Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
60217a3b38f7Smrg    {
60227a3b38f7Smrg      concat_name = xstrdup (wrapper);
60237a3b38f7Smrg      if (check_executable (concat_name))
60247a3b38f7Smrg	return concat_name;
60257a3b38f7Smrg      XFREE (concat_name);
60267a3b38f7Smrg    }
60277a3b38f7Smrg  else
60287a3b38f7Smrg    {
60297a3b38f7Smrg#endif
60307a3b38f7Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
60317a3b38f7Smrg	{
60327a3b38f7Smrg	  concat_name = xstrdup (wrapper);
60337a3b38f7Smrg	  if (check_executable (concat_name))
60347a3b38f7Smrg	    return concat_name;
60357a3b38f7Smrg	  XFREE (concat_name);
60367a3b38f7Smrg	}
60376fc0178dSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
60387a3b38f7Smrg    }
60397a3b38f7Smrg#endif
6040ff559fabSmrg
60417a3b38f7Smrg  for (p = wrapper; *p; p++)
60427a3b38f7Smrg    if (*p == '/')
60437a3b38f7Smrg      {
60447a3b38f7Smrg	has_slash = 1;
60457a3b38f7Smrg	break;
60467a3b38f7Smrg      }
60477a3b38f7Smrg  if (!has_slash)
60487a3b38f7Smrg    {
60497a3b38f7Smrg      /* no slashes; search PATH */
60507a3b38f7Smrg      const char *path = getenv ("PATH");
60517a3b38f7Smrg      if (path != NULL)
60527a3b38f7Smrg	{
60537a3b38f7Smrg	  for (p = path; *p; p = p_next)
60547a3b38f7Smrg	    {
60557a3b38f7Smrg	      const char *q;
60567a3b38f7Smrg	      size_t p_len;
60577a3b38f7Smrg	      for (q = p; *q; q++)
60587a3b38f7Smrg		if (IS_PATH_SEPARATOR (*q))
60597a3b38f7Smrg		  break;
60606fc0178dSmrg	      p_len = (size_t) (q - p);
60617a3b38f7Smrg	      p_next = (*q == '\0' ? q : q + 1);
60627a3b38f7Smrg	      if (p_len == 0)
60637a3b38f7Smrg		{
60647a3b38f7Smrg		  /* empty path: current directory */
60657a3b38f7Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
606644dda7b2Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
606744dda7b2Smrg                              nonnull (strerror (errno)));
60687a3b38f7Smrg		  tmp_len = strlen (tmp);
60697a3b38f7Smrg		  concat_name =
60707a3b38f7Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
60717a3b38f7Smrg		  memcpy (concat_name, tmp, tmp_len);
60727a3b38f7Smrg		  concat_name[tmp_len] = '/';
60737a3b38f7Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
60747a3b38f7Smrg		}
60757a3b38f7Smrg	      else
60767a3b38f7Smrg		{
60777a3b38f7Smrg		  concat_name =
60787a3b38f7Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
60797a3b38f7Smrg		  memcpy (concat_name, p, p_len);
60807a3b38f7Smrg		  concat_name[p_len] = '/';
60817a3b38f7Smrg		  strcpy (concat_name + p_len + 1, wrapper);
60827a3b38f7Smrg		}
60837a3b38f7Smrg	      if (check_executable (concat_name))
60847a3b38f7Smrg		return concat_name;
60857a3b38f7Smrg	      XFREE (concat_name);
60867a3b38f7Smrg	    }
60877a3b38f7Smrg	}
60887a3b38f7Smrg      /* not found in PATH; assume curdir */
60897a3b38f7Smrg    }
60907a3b38f7Smrg  /* Relative path | not found in path: prepend cwd */
60917a3b38f7Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
609244dda7b2Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
609344dda7b2Smrg              nonnull (strerror (errno)));
60947a3b38f7Smrg  tmp_len = strlen (tmp);
60957a3b38f7Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
60967a3b38f7Smrg  memcpy (concat_name, tmp, tmp_len);
60977a3b38f7Smrg  concat_name[tmp_len] = '/';
60987a3b38f7Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6099ff559fabSmrg
61007a3b38f7Smrg  if (check_executable (concat_name))
61017a3b38f7Smrg    return concat_name;
61027a3b38f7Smrg  XFREE (concat_name);
61037a3b38f7Smrg  return NULL;
61047a3b38f7Smrg}
6105ff559fabSmrg
61067a3b38f7Smrgchar *
61077a3b38f7Smrgchase_symlinks (const char *pathspec)
61087a3b38f7Smrg{
61097a3b38f7Smrg#ifndef S_ISLNK
61107a3b38f7Smrg  return xstrdup (pathspec);
61117a3b38f7Smrg#else
61127a3b38f7Smrg  char buf[LT_PATHMAX];
61137a3b38f7Smrg  struct stat s;
61147a3b38f7Smrg  char *tmp_pathspec = xstrdup (pathspec);
61157a3b38f7Smrg  char *p;
61167a3b38f7Smrg  int has_symlinks = 0;
61177a3b38f7Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
61187a3b38f7Smrg    {
611944dda7b2Smrg      lt_debugprintf (__FILE__, __LINE__,
612044dda7b2Smrg		      "checking path component for symlinks: %s\n",
612144dda7b2Smrg		      tmp_pathspec);
61227a3b38f7Smrg      if (lstat (tmp_pathspec, &s) == 0)
61237a3b38f7Smrg	{
61247a3b38f7Smrg	  if (S_ISLNK (s.st_mode) != 0)
61257a3b38f7Smrg	    {
61267a3b38f7Smrg	      has_symlinks = 1;
61277a3b38f7Smrg	      break;
61287a3b38f7Smrg	    }
6129ff559fabSmrg
61307a3b38f7Smrg	  /* search backwards for last DIR_SEPARATOR */
61317a3b38f7Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
61327a3b38f7Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
61337a3b38f7Smrg	    p--;
61347a3b38f7Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
61357a3b38f7Smrg	    {
61367a3b38f7Smrg	      /* no more DIR_SEPARATORS left */
61377a3b38f7Smrg	      break;
61387a3b38f7Smrg	    }
61397a3b38f7Smrg	  *p = '\0';
61407a3b38f7Smrg	}
61417a3b38f7Smrg      else
61427a3b38f7Smrg	{
614344dda7b2Smrg	  lt_fatal (__FILE__, __LINE__,
614444dda7b2Smrg		    "error accessing file \"%s\": %s",
614544dda7b2Smrg		    tmp_pathspec, nonnull (strerror (errno)));
61467a3b38f7Smrg	}
61477a3b38f7Smrg    }
61487a3b38f7Smrg  XFREE (tmp_pathspec);
6149ff559fabSmrg
61507a3b38f7Smrg  if (!has_symlinks)
61517a3b38f7Smrg    {
61527a3b38f7Smrg      return xstrdup (pathspec);
61537a3b38f7Smrg    }
6154ff559fabSmrg
61557a3b38f7Smrg  tmp_pathspec = realpath (pathspec, buf);
61567a3b38f7Smrg  if (tmp_pathspec == 0)
61577a3b38f7Smrg    {
615844dda7b2Smrg      lt_fatal (__FILE__, __LINE__,
615944dda7b2Smrg		"could not follow symlinks for %s", pathspec);
61607a3b38f7Smrg    }
61617a3b38f7Smrg  return xstrdup (tmp_pathspec);
61627a3b38f7Smrg#endif
61637a3b38f7Smrg}
6164ff559fabSmrg
61657a3b38f7Smrgchar *
61667a3b38f7Smrgstrendzap (char *str, const char *pat)
61677a3b38f7Smrg{
61687a3b38f7Smrg  size_t len, patlen;
6169ff559fabSmrg
61707a3b38f7Smrg  assert (str != NULL);
61717a3b38f7Smrg  assert (pat != NULL);
6172ff559fabSmrg
61737a3b38f7Smrg  len = strlen (str);
61747a3b38f7Smrg  patlen = strlen (pat);
6175ff559fabSmrg
61767a3b38f7Smrg  if (patlen <= len)
61777a3b38f7Smrg    {
61787a3b38f7Smrg      str += len - patlen;
61796fc0178dSmrg      if (STREQ (str, pat))
61807a3b38f7Smrg	*str = '\0';
61817a3b38f7Smrg    }
61827a3b38f7Smrg  return str;
61837a3b38f7Smrg}
6184ff559fabSmrg
618544dda7b2Smrgvoid
618644dda7b2Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
618744dda7b2Smrg{
618844dda7b2Smrg  va_list args;
618944dda7b2Smrg  if (lt_debug)
619044dda7b2Smrg    {
619144dda7b2Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
619244dda7b2Smrg      va_start (args, fmt);
619344dda7b2Smrg      (void) vfprintf (stderr, fmt, args);
619444dda7b2Smrg      va_end (args);
619544dda7b2Smrg    }
619644dda7b2Smrg}
619744dda7b2Smrg
61987a3b38f7Smrgstatic void
619944dda7b2Smrglt_error_core (int exit_status, const char *file,
620044dda7b2Smrg	       int line, const char *mode,
62017a3b38f7Smrg	       const char *message, va_list ap)
62027a3b38f7Smrg{
620344dda7b2Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
62047a3b38f7Smrg  vfprintf (stderr, message, ap);
62057a3b38f7Smrg  fprintf (stderr, ".\n");
6206ff559fabSmrg
62077a3b38f7Smrg  if (exit_status >= 0)
62087a3b38f7Smrg    exit (exit_status);
62097a3b38f7Smrg}
6210ff559fabSmrg
62117a3b38f7Smrgvoid
621244dda7b2Smrglt_fatal (const char *file, int line, const char *message, ...)
62137a3b38f7Smrg{
62147a3b38f7Smrg  va_list ap;
62157a3b38f7Smrg  va_start (ap, message);
621644dda7b2Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
62177a3b38f7Smrg  va_end (ap);
62187a3b38f7Smrg}
6219ff559fabSmrg
622044dda7b2Smrgstatic const char *
622144dda7b2Smrgnonnull (const char *s)
622244dda7b2Smrg{
622344dda7b2Smrg  return s ? s : "(null)";
622444dda7b2Smrg}
622544dda7b2Smrg
622644dda7b2Smrgstatic const char *
622744dda7b2Smrgnonempty (const char *s)
622844dda7b2Smrg{
622944dda7b2Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
623044dda7b2Smrg}
623144dda7b2Smrg
62327a3b38f7Smrgvoid
62337a3b38f7Smrglt_setenv (const char *name, const char *value)
62347a3b38f7Smrg{
623544dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
623644dda7b2Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
623744dda7b2Smrg                  nonnull (name), nonnull (value));
62387a3b38f7Smrg  {
62397a3b38f7Smrg#ifdef HAVE_SETENV
62407a3b38f7Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
62417a3b38f7Smrg    char *str = xstrdup (value);
62427a3b38f7Smrg    setenv (name, str, 1);
62437a3b38f7Smrg#else
62446fc0178dSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
62457a3b38f7Smrg    char *str = XMALLOC (char, len);
62467a3b38f7Smrg    sprintf (str, "%s=%s", name, value);
62477a3b38f7Smrg    if (putenv (str) != EXIT_SUCCESS)
62487a3b38f7Smrg      {
62497a3b38f7Smrg        XFREE (str);
62507a3b38f7Smrg      }
62517a3b38f7Smrg#endif
62527a3b38f7Smrg  }
62537a3b38f7Smrg}
6254ff559fabSmrg
62557a3b38f7Smrgchar *
62567a3b38f7Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
62577a3b38f7Smrg{
62587a3b38f7Smrg  char *new_value;
62597a3b38f7Smrg  if (orig_value && *orig_value)
62607a3b38f7Smrg    {
62616fc0178dSmrg      size_t orig_value_len = strlen (orig_value);
62626fc0178dSmrg      size_t add_len = strlen (add);
62637a3b38f7Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
62647a3b38f7Smrg      if (to_end)
62657a3b38f7Smrg        {
62667a3b38f7Smrg          strcpy (new_value, orig_value);
62677a3b38f7Smrg          strcpy (new_value + orig_value_len, add);
62687a3b38f7Smrg        }
62697a3b38f7Smrg      else
62707a3b38f7Smrg        {
62717a3b38f7Smrg          strcpy (new_value, add);
62727a3b38f7Smrg          strcpy (new_value + add_len, orig_value);
62737a3b38f7Smrg        }
62747a3b38f7Smrg    }
62757a3b38f7Smrg  else
62767a3b38f7Smrg    {
62777a3b38f7Smrg      new_value = xstrdup (add);
62787a3b38f7Smrg    }
62797a3b38f7Smrg  return new_value;
62807a3b38f7Smrg}
6281ff559fabSmrg
62827a3b38f7Smrgvoid
62837a3b38f7Smrglt_update_exe_path (const char *name, const char *value)
62847a3b38f7Smrg{
628544dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
628644dda7b2Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
628744dda7b2Smrg                  nonnull (name), nonnull (value));
6288ff559fabSmrg
62897a3b38f7Smrg  if (name && *name && value && *value)
62907a3b38f7Smrg    {
62917a3b38f7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
62927a3b38f7Smrg      /* some systems can't cope with a ':'-terminated path #' */
62936fc0178dSmrg      size_t len = strlen (new_value);
62946fc0178dSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
62957a3b38f7Smrg        {
62966fc0178dSmrg          new_value[--len] = '\0';
62977a3b38f7Smrg        }
62987a3b38f7Smrg      lt_setenv (name, new_value);
62997a3b38f7Smrg      XFREE (new_value);
63007a3b38f7Smrg    }
63017a3b38f7Smrg}
6302ff559fabSmrg
63037a3b38f7Smrgvoid
63047a3b38f7Smrglt_update_lib_path (const char *name, const char *value)
63057a3b38f7Smrg{
630644dda7b2Smrg  lt_debugprintf (__FILE__, __LINE__,
630744dda7b2Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
630844dda7b2Smrg                  nonnull (name), nonnull (value));
6309ff559fabSmrg
63107a3b38f7Smrg  if (name && *name && value && *value)
63117a3b38f7Smrg    {
63127a3b38f7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
63137a3b38f7Smrg      lt_setenv (name, new_value);
63147a3b38f7Smrg      XFREE (new_value);
63157a3b38f7Smrg    }
63167a3b38f7Smrg}
6317ff559fabSmrg
631844dda7b2SmrgEOF
631944dda7b2Smrg	    case $host_os in
632044dda7b2Smrg	      mingw*)
632144dda7b2Smrg		cat <<"EOF"
632244dda7b2Smrg
632344dda7b2Smrg/* Prepares an argument vector before calling spawn().
632444dda7b2Smrg   Note that spawn() does not by itself call the command interpreter
632544dda7b2Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
632644dda7b2Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
632744dda7b2Smrg         GetVersionEx(&v);
632844dda7b2Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
632944dda7b2Smrg      }) ? "cmd.exe" : "command.com").
633044dda7b2Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
633144dda7b2Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
633244dda7b2Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
633344dda7b2Smrg   special way:
633444dda7b2Smrg   - Space and tab are interpreted as delimiters. They are not treated as
633544dda7b2Smrg     delimiters if they are surrounded by double quotes: "...".
633644dda7b2Smrg   - Unescaped double quotes are removed from the input. Their only effect is
633744dda7b2Smrg     that within double quotes, space and tab are treated like normal
633844dda7b2Smrg     characters.
633944dda7b2Smrg   - Backslashes not followed by double quotes are not special.
634044dda7b2Smrg   - But 2*n+1 backslashes followed by a double quote become
634144dda7b2Smrg     n backslashes followed by a double quote (n >= 0):
634244dda7b2Smrg       \" -> "
634344dda7b2Smrg       \\\" -> \"
634444dda7b2Smrg       \\\\\" -> \\"
634544dda7b2Smrg */
634644dda7b2Smrg#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"
634744dda7b2Smrg#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"
634844dda7b2Smrgchar **
634944dda7b2Smrgprepare_spawn (char **argv)
635044dda7b2Smrg{
635144dda7b2Smrg  size_t argc;
635244dda7b2Smrg  char **new_argv;
635344dda7b2Smrg  size_t i;
635444dda7b2Smrg
635544dda7b2Smrg  /* Count number of arguments.  */
635644dda7b2Smrg  for (argc = 0; argv[argc] != NULL; argc++)
635744dda7b2Smrg    ;
635844dda7b2Smrg
635944dda7b2Smrg  /* Allocate new argument vector.  */
636044dda7b2Smrg  new_argv = XMALLOC (char *, argc + 1);
636144dda7b2Smrg
636244dda7b2Smrg  /* Put quoted arguments into the new argument vector.  */
636344dda7b2Smrg  for (i = 0; i < argc; i++)
636444dda7b2Smrg    {
636544dda7b2Smrg      const char *string = argv[i];
636644dda7b2Smrg
636744dda7b2Smrg      if (string[0] == '\0')
636844dda7b2Smrg	new_argv[i] = xstrdup ("\"\"");
636944dda7b2Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
637044dda7b2Smrg	{
637144dda7b2Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
637244dda7b2Smrg	  size_t length;
637344dda7b2Smrg	  unsigned int backslashes;
637444dda7b2Smrg	  const char *s;
637544dda7b2Smrg	  char *quoted_string;
637644dda7b2Smrg	  char *p;
637744dda7b2Smrg
637844dda7b2Smrg	  length = 0;
637944dda7b2Smrg	  backslashes = 0;
638044dda7b2Smrg	  if (quote_around)
638144dda7b2Smrg	    length++;
638244dda7b2Smrg	  for (s = string; *s != '\0'; s++)
638344dda7b2Smrg	    {
638444dda7b2Smrg	      char c = *s;
638544dda7b2Smrg	      if (c == '"')
638644dda7b2Smrg		length += backslashes + 1;
638744dda7b2Smrg	      length++;
638844dda7b2Smrg	      if (c == '\\')
638944dda7b2Smrg		backslashes++;
639044dda7b2Smrg	      else
639144dda7b2Smrg		backslashes = 0;
639244dda7b2Smrg	    }
639344dda7b2Smrg	  if (quote_around)
639444dda7b2Smrg	    length += backslashes + 1;
639544dda7b2Smrg
639644dda7b2Smrg	  quoted_string = XMALLOC (char, length + 1);
639744dda7b2Smrg
639844dda7b2Smrg	  p = quoted_string;
639944dda7b2Smrg	  backslashes = 0;
640044dda7b2Smrg	  if (quote_around)
640144dda7b2Smrg	    *p++ = '"';
640244dda7b2Smrg	  for (s = string; *s != '\0'; s++)
640344dda7b2Smrg	    {
640444dda7b2Smrg	      char c = *s;
640544dda7b2Smrg	      if (c == '"')
640644dda7b2Smrg		{
640744dda7b2Smrg		  unsigned int j;
640844dda7b2Smrg		  for (j = backslashes + 1; j > 0; j--)
640944dda7b2Smrg		    *p++ = '\\';
641044dda7b2Smrg		}
641144dda7b2Smrg	      *p++ = c;
641244dda7b2Smrg	      if (c == '\\')
641344dda7b2Smrg		backslashes++;
641444dda7b2Smrg	      else
641544dda7b2Smrg		backslashes = 0;
641644dda7b2Smrg	    }
641744dda7b2Smrg	  if (quote_around)
641844dda7b2Smrg	    {
641944dda7b2Smrg	      unsigned int j;
642044dda7b2Smrg	      for (j = backslashes; j > 0; j--)
642144dda7b2Smrg		*p++ = '\\';
642244dda7b2Smrg	      *p++ = '"';
642344dda7b2Smrg	    }
642444dda7b2Smrg	  *p = '\0';
642544dda7b2Smrg
642644dda7b2Smrg	  new_argv[i] = quoted_string;
642744dda7b2Smrg	}
642844dda7b2Smrg      else
642944dda7b2Smrg	new_argv[i] = (char *) string;
643044dda7b2Smrg    }
643144dda7b2Smrg  new_argv[argc] = NULL;
643244dda7b2Smrg
643344dda7b2Smrg  return new_argv;
643444dda7b2Smrg}
643544dda7b2SmrgEOF
643644dda7b2Smrg		;;
643744dda7b2Smrg	    esac
643844dda7b2Smrg
643944dda7b2Smrg            cat <<"EOF"
644044dda7b2Smrgvoid lt_dump_script (FILE* f)
644144dda7b2Smrg{
644244dda7b2SmrgEOF
644344dda7b2Smrg	    func_emit_wrapper yes |
6444fc544a13Smrg	      $SED -n -e '
6445fc544a13Smrgs/^\(.\{79\}\)\(..*\)/\1\
6446fc544a13Smrg\2/
6447fc544a13Smrgh
6448fc544a13Smrgs/\([\\"]\)/\\\1/g
6449fc544a13Smrgs/$/\\n/
6450fc544a13Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6451fc544a13Smrgg
6452fc544a13SmrgD'
645344dda7b2Smrg            cat <<"EOF"
645444dda7b2Smrg}
64557a3b38f7SmrgEOF
64567a3b38f7Smrg}
64577a3b38f7Smrg# end: func_emit_cwrapperexe_src
6458ff559fabSmrg
645944dda7b2Smrg# func_win32_import_lib_p ARG
646044dda7b2Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
646144dda7b2Smrgfunc_win32_import_lib_p ()
646244dda7b2Smrg{
64636fc0178dSmrg    $debug_cmd
64646fc0178dSmrg
646544dda7b2Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
646644dda7b2Smrg    *import*) : ;;
646744dda7b2Smrg    *) false ;;
646844dda7b2Smrg    esac
646944dda7b2Smrg}
647044dda7b2Smrg
64716fc0178dSmrg# func_suncc_cstd_abi
64726fc0178dSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
64736fc0178dSmrg# Several compiler flags select an ABI that is incompatible with the
64746fc0178dSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
64756fc0178dSmrgfunc_suncc_cstd_abi ()
64766fc0178dSmrg{
64776fc0178dSmrg    $debug_cmd
64786fc0178dSmrg
64796fc0178dSmrg    case " $compile_command " in
64806fc0178dSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
64816fc0178dSmrg      suncc_use_cstd_abi=no
64826fc0178dSmrg      ;;
64836fc0178dSmrg    *)
64846fc0178dSmrg      suncc_use_cstd_abi=yes
64856fc0178dSmrg      ;;
64866fc0178dSmrg    esac
64876fc0178dSmrg}
64886fc0178dSmrg
64897a3b38f7Smrg# func_mode_link arg...
64907a3b38f7Smrgfunc_mode_link ()
64917a3b38f7Smrg{
64926fc0178dSmrg    $debug_cmd
64936fc0178dSmrg
64947a3b38f7Smrg    case $host in
64957a3b38f7Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
64967a3b38f7Smrg      # It is impossible to link a dll without this setting, and
64977a3b38f7Smrg      # we shouldn't force the makefile maintainer to figure out
64986fc0178dSmrg      # what system we are compiling for in order to pass an extra
64997a3b38f7Smrg      # flag for every libtool invocation.
65007a3b38f7Smrg      # allow_undefined=no
6501ff559fabSmrg
65027a3b38f7Smrg      # FIXME: Unfortunately, there are problems with the above when trying
65036fc0178dSmrg      # to make a dll that has undefined symbols, in which case not
65047a3b38f7Smrg      # even a static library is built.  For now, we need to specify
65057a3b38f7Smrg      # -no-undefined on the libtool link line when we can be certain
65067a3b38f7Smrg      # that all symbols are satisfied, otherwise we get a static library.
65077a3b38f7Smrg      allow_undefined=yes
65087a3b38f7Smrg      ;;
65097a3b38f7Smrg    *)
65107a3b38f7Smrg      allow_undefined=yes
65117a3b38f7Smrg      ;;
65127a3b38f7Smrg    esac
65137a3b38f7Smrg    libtool_args=$nonopt
65147a3b38f7Smrg    base_compile="$nonopt $@"
65157a3b38f7Smrg    compile_command=$nonopt
65167a3b38f7Smrg    finalize_command=$nonopt
6517ff559fabSmrg
65187a3b38f7Smrg    compile_rpath=
65197a3b38f7Smrg    finalize_rpath=
65207a3b38f7Smrg    compile_shlibpath=
65217a3b38f7Smrg    finalize_shlibpath=
65227a3b38f7Smrg    convenience=
65237a3b38f7Smrg    old_convenience=
65247a3b38f7Smrg    deplibs=
65257a3b38f7Smrg    old_deplibs=
65267a3b38f7Smrg    compiler_flags=
65277a3b38f7Smrg    linker_flags=
65287a3b38f7Smrg    dllsearchpath=
65297a3b38f7Smrg    lib_search_path=`pwd`
65307a3b38f7Smrg    inst_prefix_dir=
65317a3b38f7Smrg    new_inherited_linker_flags=
6532ff559fabSmrg
65337a3b38f7Smrg    avoid_version=no
653444dda7b2Smrg    bindir=
65357a3b38f7Smrg    dlfiles=
65367a3b38f7Smrg    dlprefiles=
65377a3b38f7Smrg    dlself=no
65387a3b38f7Smrg    export_dynamic=no
65397a3b38f7Smrg    export_symbols=
65407a3b38f7Smrg    export_symbols_regex=
65417a3b38f7Smrg    generated=
65427a3b38f7Smrg    libobjs=
65437a3b38f7Smrg    ltlibs=
65447a3b38f7Smrg    module=no
65457a3b38f7Smrg    no_install=no
65467a3b38f7Smrg    objs=
65476fc0178dSmrg    os2dllname=
65487a3b38f7Smrg    non_pic_objects=
65497a3b38f7Smrg    precious_files_regex=
65507a3b38f7Smrg    prefer_static_libs=no
65516fc0178dSmrg    preload=false
65527a3b38f7Smrg    prev=
65537a3b38f7Smrg    prevarg=
65547a3b38f7Smrg    release=
65557a3b38f7Smrg    rpath=
65567a3b38f7Smrg    xrpath=
65577a3b38f7Smrg    perm_rpath=
65587a3b38f7Smrg    temp_rpath=
65597a3b38f7Smrg    thread_safe=no
65607a3b38f7Smrg    vinfo=
65617a3b38f7Smrg    vinfo_number=no
65627a3b38f7Smrg    weak_libs=
65636fc0178dSmrg    single_module=$wl-single_module
65647a3b38f7Smrg    func_infer_tag $base_compile
6565ff559fabSmrg
65667a3b38f7Smrg    # We need to know -static, to get the right output filenames.
65677a3b38f7Smrg    for arg
65687a3b38f7Smrg    do
65697a3b38f7Smrg      case $arg in
65707a3b38f7Smrg      -shared)
65716fc0178dSmrg	test yes != "$build_libtool_libs" \
65726fc0178dSmrg	  && func_fatal_configuration "cannot build a shared library"
65737a3b38f7Smrg	build_old_libs=no
65747a3b38f7Smrg	break
65757a3b38f7Smrg	;;
65767a3b38f7Smrg      -all-static | -static | -static-libtool-libs)
65777a3b38f7Smrg	case $arg in
65787a3b38f7Smrg	-all-static)
65796fc0178dSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
65807a3b38f7Smrg	    func_warning "complete static linking is impossible in this configuration"
6581ff559fabSmrg	  fi
65827a3b38f7Smrg	  if test -n "$link_static_flag"; then
65837a3b38f7Smrg	    dlopen_self=$dlopen_self_static
6584ff559fabSmrg	  fi
65857a3b38f7Smrg	  prefer_static_libs=yes
6586ff559fabSmrg	  ;;
65877a3b38f7Smrg	-static)
65887a3b38f7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
65897a3b38f7Smrg	    dlopen_self=$dlopen_self_static
65907a3b38f7Smrg	  fi
65917a3b38f7Smrg	  prefer_static_libs=built
65927a3b38f7Smrg	  ;;
65937a3b38f7Smrg	-static-libtool-libs)
65947a3b38f7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
65957a3b38f7Smrg	    dlopen_self=$dlopen_self_static
65967a3b38f7Smrg	  fi
65977a3b38f7Smrg	  prefer_static_libs=yes
6598ff559fabSmrg	  ;;
6599ff559fabSmrg	esac
66007a3b38f7Smrg	build_libtool_libs=no
66017a3b38f7Smrg	build_old_libs=yes
66027a3b38f7Smrg	break
66037a3b38f7Smrg	;;
66047a3b38f7Smrg      esac
66057a3b38f7Smrg    done
6606ff559fabSmrg
66077a3b38f7Smrg    # See if our shared archives depend on static archives.
66087a3b38f7Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6609ff559fabSmrg
66107a3b38f7Smrg    # Go through the arguments, transforming them on the way.
66117a3b38f7Smrg    while test "$#" -gt 0; do
66126fc0178dSmrg      arg=$1
66137a3b38f7Smrg      shift
66147a3b38f7Smrg      func_quote_for_eval "$arg"
66157a3b38f7Smrg      qarg=$func_quote_for_eval_unquoted_result
66167a3b38f7Smrg      func_append libtool_args " $func_quote_for_eval_result"
6617ff559fabSmrg
66187a3b38f7Smrg      # If the previous option needs an argument, assign it.
66197a3b38f7Smrg      if test -n "$prev"; then
66207a3b38f7Smrg	case $prev in
66217a3b38f7Smrg	output)
66227a3b38f7Smrg	  func_append compile_command " @OUTPUT@"
66237a3b38f7Smrg	  func_append finalize_command " @OUTPUT@"
66247a3b38f7Smrg	  ;;
66257a3b38f7Smrg	esac
6626ff559fabSmrg
66277a3b38f7Smrg	case $prev in
662844dda7b2Smrg	bindir)
66296fc0178dSmrg	  bindir=$arg
663044dda7b2Smrg	  prev=
663144dda7b2Smrg	  continue
663244dda7b2Smrg	  ;;
66337a3b38f7Smrg	dlfiles|dlprefiles)
66346fc0178dSmrg	  $preload || {
66357a3b38f7Smrg	    # Add the symbol object into the linking commands.
66367a3b38f7Smrg	    func_append compile_command " @SYMFILE@"
66377a3b38f7Smrg	    func_append finalize_command " @SYMFILE@"
66386fc0178dSmrg	    preload=:
66396fc0178dSmrg	  }
66407a3b38f7Smrg	  case $arg in
66417a3b38f7Smrg	  *.la | *.lo) ;;  # We handle these cases below.
66427a3b38f7Smrg	  force)
66436fc0178dSmrg	    if test no = "$dlself"; then
66447a3b38f7Smrg	      dlself=needless
66457a3b38f7Smrg	      export_dynamic=yes
66467a3b38f7Smrg	    fi
66477a3b38f7Smrg	    prev=
66487a3b38f7Smrg	    continue
66497a3b38f7Smrg	    ;;
66507a3b38f7Smrg	  self)
66516fc0178dSmrg	    if test dlprefiles = "$prev"; then
66527a3b38f7Smrg	      dlself=yes
66536fc0178dSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
66547a3b38f7Smrg	      dlself=yes
66557a3b38f7Smrg	    else
66567a3b38f7Smrg	      dlself=needless
66577a3b38f7Smrg	      export_dynamic=yes
66587a3b38f7Smrg	    fi
66597a3b38f7Smrg	    prev=
66607a3b38f7Smrg	    continue
6661ff559fabSmrg	    ;;
6662ff559fabSmrg	  *)
66636fc0178dSmrg	    if test dlfiles = "$prev"; then
6664862f5301Smrg	      func_append dlfiles " $arg"
66657a3b38f7Smrg	    else
6666862f5301Smrg	      func_append dlprefiles " $arg"
66677a3b38f7Smrg	    fi
66687a3b38f7Smrg	    prev=
66697a3b38f7Smrg	    continue
6670ff559fabSmrg	    ;;
6671ff559fabSmrg	  esac
66727a3b38f7Smrg	  ;;
66737a3b38f7Smrg	expsyms)
66746fc0178dSmrg	  export_symbols=$arg
66757a3b38f7Smrg	  test -f "$arg" \
66766fc0178dSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
66777a3b38f7Smrg	  prev=
66787a3b38f7Smrg	  continue
66797a3b38f7Smrg	  ;;
66807a3b38f7Smrg	expsyms_regex)
66816fc0178dSmrg	  export_symbols_regex=$arg
66827a3b38f7Smrg	  prev=
66837a3b38f7Smrg	  continue
66847a3b38f7Smrg	  ;;
66857a3b38f7Smrg	framework)
66867a3b38f7Smrg	  case $host in
66877a3b38f7Smrg	    *-*-darwin*)
66887a3b38f7Smrg	      case "$deplibs " in
66897a3b38f7Smrg		*" $qarg.ltframework "*) ;;
6690862f5301Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
66917a3b38f7Smrg		   ;;
66927a3b38f7Smrg	      esac
66937a3b38f7Smrg	      ;;
66947a3b38f7Smrg	  esac
66957a3b38f7Smrg	  prev=
66967a3b38f7Smrg	  continue
66977a3b38f7Smrg	  ;;
66987a3b38f7Smrg	inst_prefix)
66996fc0178dSmrg	  inst_prefix_dir=$arg
67006fc0178dSmrg	  prev=
67016fc0178dSmrg	  continue
67026fc0178dSmrg	  ;;
67036fc0178dSmrg	mllvm)
67046fc0178dSmrg	  # Clang does not use LLVM to link, so we can simply discard any
67056fc0178dSmrg	  # '-mllvm $arg' options when doing the link step.
67067a3b38f7Smrg	  prev=
67077a3b38f7Smrg	  continue
67087a3b38f7Smrg	  ;;
67097a3b38f7Smrg	objectlist)
67107a3b38f7Smrg	  if test -f "$arg"; then
67117a3b38f7Smrg	    save_arg=$arg
67127a3b38f7Smrg	    moreargs=
67137a3b38f7Smrg	    for fil in `cat "$save_arg"`
67147a3b38f7Smrg	    do
6715862f5301Smrg#	      func_append moreargs " $fil"
67167a3b38f7Smrg	      arg=$fil
67177a3b38f7Smrg	      # A libtool-controlled object.
6718ff559fabSmrg
67197a3b38f7Smrg	      # Check to see that this really is a libtool object.
67207a3b38f7Smrg	      if func_lalib_unsafe_p "$arg"; then
67217a3b38f7Smrg		pic_object=
67227a3b38f7Smrg		non_pic_object=
6723ff559fabSmrg
67247a3b38f7Smrg		# Read the .lo file
67257a3b38f7Smrg		func_source "$arg"
6726ff559fabSmrg
67277a3b38f7Smrg		if test -z "$pic_object" ||
67287a3b38f7Smrg		   test -z "$non_pic_object" ||
67296fc0178dSmrg		   test none = "$pic_object" &&
67306fc0178dSmrg		   test none = "$non_pic_object"; then
67316fc0178dSmrg		  func_fatal_error "cannot find name of object for '$arg'"
67327a3b38f7Smrg		fi
6733ff559fabSmrg
67347a3b38f7Smrg		# Extract subdirectory from the argument.
67357a3b38f7Smrg		func_dirname "$arg" "/" ""
67366fc0178dSmrg		xdir=$func_dirname_result
6737ff559fabSmrg
67386fc0178dSmrg		if test none != "$pic_object"; then
67397a3b38f7Smrg		  # Prepend the subdirectory the object is found in.
67406fc0178dSmrg		  pic_object=$xdir$pic_object
6741ff559fabSmrg
67426fc0178dSmrg		  if test dlfiles = "$prev"; then
67436fc0178dSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
6744862f5301Smrg		      func_append dlfiles " $pic_object"
67457a3b38f7Smrg		      prev=
67467a3b38f7Smrg		      continue
67477a3b38f7Smrg		    else
67487a3b38f7Smrg		      # If libtool objects are unsupported, then we need to preload.
67497a3b38f7Smrg		      prev=dlprefiles
67507a3b38f7Smrg		    fi
67517a3b38f7Smrg		  fi
6752ff559fabSmrg
67537a3b38f7Smrg		  # CHECK ME:  I think I busted this.  -Ossama
67546fc0178dSmrg		  if test dlprefiles = "$prev"; then
67557a3b38f7Smrg		    # Preload the old-style object.
6756862f5301Smrg		    func_append dlprefiles " $pic_object"
67577a3b38f7Smrg		    prev=
67587a3b38f7Smrg		  fi
6759ff559fabSmrg
67607a3b38f7Smrg		  # A PIC object.
67617a3b38f7Smrg		  func_append libobjs " $pic_object"
67626fc0178dSmrg		  arg=$pic_object
67637a3b38f7Smrg		fi
6764ff559fabSmrg
67657a3b38f7Smrg		# Non-PIC object.
67666fc0178dSmrg		if test none != "$non_pic_object"; then
67677a3b38f7Smrg		  # Prepend the subdirectory the object is found in.
67686fc0178dSmrg		  non_pic_object=$xdir$non_pic_object
6769ff559fabSmrg
67707a3b38f7Smrg		  # A standard non-PIC object
67717a3b38f7Smrg		  func_append non_pic_objects " $non_pic_object"
67726fc0178dSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
67736fc0178dSmrg		    arg=$non_pic_object
67747a3b38f7Smrg		  fi
67757a3b38f7Smrg		else
67767a3b38f7Smrg		  # If the PIC object exists, use it instead.
67777a3b38f7Smrg		  # $xdir was prepended to $pic_object above.
67786fc0178dSmrg		  non_pic_object=$pic_object
67797a3b38f7Smrg		  func_append non_pic_objects " $non_pic_object"
67807a3b38f7Smrg		fi
67817a3b38f7Smrg	      else
67827a3b38f7Smrg		# Only an error if not doing a dry-run.
67837a3b38f7Smrg		if $opt_dry_run; then
67847a3b38f7Smrg		  # Extract subdirectory from the argument.
67857a3b38f7Smrg		  func_dirname "$arg" "/" ""
67866fc0178dSmrg		  xdir=$func_dirname_result
67877a3b38f7Smrg
67887a3b38f7Smrg		  func_lo2o "$arg"
67897a3b38f7Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
67907a3b38f7Smrg		  non_pic_object=$xdir$func_lo2o_result
67917a3b38f7Smrg		  func_append libobjs " $pic_object"
67927a3b38f7Smrg		  func_append non_pic_objects " $non_pic_object"
67937a3b38f7Smrg	        else
67946fc0178dSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
67957a3b38f7Smrg		fi
67967a3b38f7Smrg	      fi
67977a3b38f7Smrg	    done
67987a3b38f7Smrg	  else
67996fc0178dSmrg	    func_fatal_error "link input file '$arg' does not exist"
68007a3b38f7Smrg	  fi
68017a3b38f7Smrg	  arg=$save_arg
68027a3b38f7Smrg	  prev=
68037a3b38f7Smrg	  continue
68047a3b38f7Smrg	  ;;
68056fc0178dSmrg	os2dllname)
68066fc0178dSmrg	  os2dllname=$arg
68076fc0178dSmrg	  prev=
68086fc0178dSmrg	  continue
68096fc0178dSmrg	  ;;
68107a3b38f7Smrg	precious_regex)
68116fc0178dSmrg	  precious_files_regex=$arg
68127a3b38f7Smrg	  prev=
68137a3b38f7Smrg	  continue
68147a3b38f7Smrg	  ;;
68157a3b38f7Smrg	release)
68166fc0178dSmrg	  release=-$arg
68177a3b38f7Smrg	  prev=
68187a3b38f7Smrg	  continue
68197a3b38f7Smrg	  ;;
68207a3b38f7Smrg	rpath | xrpath)
68217a3b38f7Smrg	  # We need an absolute path.
68227a3b38f7Smrg	  case $arg in
68237a3b38f7Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
68247a3b38f7Smrg	  *)
68257a3b38f7Smrg	    func_fatal_error "only absolute run-paths are allowed"
68267a3b38f7Smrg	    ;;
68277a3b38f7Smrg	  esac
68286fc0178dSmrg	  if test rpath = "$prev"; then
68297a3b38f7Smrg	    case "$rpath " in
68307a3b38f7Smrg	    *" $arg "*) ;;
6831862f5301Smrg	    *) func_append rpath " $arg" ;;
68327a3b38f7Smrg	    esac
68337a3b38f7Smrg	  else
68347a3b38f7Smrg	    case "$xrpath " in
68357a3b38f7Smrg	    *" $arg "*) ;;
6836862f5301Smrg	    *) func_append xrpath " $arg" ;;
68377a3b38f7Smrg	    esac
68387a3b38f7Smrg	  fi
68397a3b38f7Smrg	  prev=
68407a3b38f7Smrg	  continue
68417a3b38f7Smrg	  ;;
68427a3b38f7Smrg	shrext)
68436fc0178dSmrg	  shrext_cmds=$arg
68447a3b38f7Smrg	  prev=
68457a3b38f7Smrg	  continue
68467a3b38f7Smrg	  ;;
68477a3b38f7Smrg	weak)
6848862f5301Smrg	  func_append weak_libs " $arg"
68497a3b38f7Smrg	  prev=
68507a3b38f7Smrg	  continue
68517a3b38f7Smrg	  ;;
68527a3b38f7Smrg	xcclinker)
6853862f5301Smrg	  func_append linker_flags " $qarg"
6854862f5301Smrg	  func_append compiler_flags " $qarg"
68557a3b38f7Smrg	  prev=
68567a3b38f7Smrg	  func_append compile_command " $qarg"
68577a3b38f7Smrg	  func_append finalize_command " $qarg"
68587a3b38f7Smrg	  continue
68597a3b38f7Smrg	  ;;
68607a3b38f7Smrg	xcompiler)
6861862f5301Smrg	  func_append compiler_flags " $qarg"
68627a3b38f7Smrg	  prev=
68637a3b38f7Smrg	  func_append compile_command " $qarg"
68647a3b38f7Smrg	  func_append finalize_command " $qarg"
68657a3b38f7Smrg	  continue
68667a3b38f7Smrg	  ;;
68677a3b38f7Smrg	xlinker)
6868862f5301Smrg	  func_append linker_flags " $qarg"
6869862f5301Smrg	  func_append compiler_flags " $wl$qarg"
68707a3b38f7Smrg	  prev=
68717a3b38f7Smrg	  func_append compile_command " $wl$qarg"
68727a3b38f7Smrg	  func_append finalize_command " $wl$qarg"
68737a3b38f7Smrg	  continue
68747a3b38f7Smrg	  ;;
68757a3b38f7Smrg	*)
68767a3b38f7Smrg	  eval "$prev=\"\$arg\""
68777a3b38f7Smrg	  prev=
68787a3b38f7Smrg	  continue
68797a3b38f7Smrg	  ;;
6880ff559fabSmrg	esac
68817a3b38f7Smrg      fi # test -n "$prev"
6882ff559fabSmrg
68836fc0178dSmrg      prevarg=$arg
6884ff559fabSmrg
68857a3b38f7Smrg      case $arg in
68867a3b38f7Smrg      -all-static)
68877a3b38f7Smrg	if test -n "$link_static_flag"; then
68887a3b38f7Smrg	  # See comment for -static flag below, for more details.
68897a3b38f7Smrg	  func_append compile_command " $link_static_flag"
68907a3b38f7Smrg	  func_append finalize_command " $link_static_flag"
68917a3b38f7Smrg	fi
68927a3b38f7Smrg	continue
68937a3b38f7Smrg	;;
6894ff559fabSmrg
68957a3b38f7Smrg      -allow-undefined)
68967a3b38f7Smrg	# FIXME: remove this flag sometime in the future.
68976fc0178dSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
68987a3b38f7Smrg	;;
6899ff559fabSmrg
69007a3b38f7Smrg      -avoid-version)
69017a3b38f7Smrg	avoid_version=yes
69027a3b38f7Smrg	continue
69037a3b38f7Smrg	;;
6904ff559fabSmrg
690544dda7b2Smrg      -bindir)
690644dda7b2Smrg	prev=bindir
690744dda7b2Smrg	continue
690844dda7b2Smrg	;;
690944dda7b2Smrg
69107a3b38f7Smrg      -dlopen)
69117a3b38f7Smrg	prev=dlfiles
69127a3b38f7Smrg	continue
69137a3b38f7Smrg	;;
6914ff559fabSmrg
69157a3b38f7Smrg      -dlpreopen)
69167a3b38f7Smrg	prev=dlprefiles
69177a3b38f7Smrg	continue
69187a3b38f7Smrg	;;
6919ff559fabSmrg
69207a3b38f7Smrg      -export-dynamic)
69217a3b38f7Smrg	export_dynamic=yes
69227a3b38f7Smrg	continue
69237a3b38f7Smrg	;;
6924ff559fabSmrg
69257a3b38f7Smrg      -export-symbols | -export-symbols-regex)
69267a3b38f7Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
69277a3b38f7Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
69287a3b38f7Smrg	fi
69296fc0178dSmrg	if test X-export-symbols = "X$arg"; then
69307a3b38f7Smrg	  prev=expsyms
69317a3b38f7Smrg	else
69327a3b38f7Smrg	  prev=expsyms_regex
69337a3b38f7Smrg	fi
69347a3b38f7Smrg	continue
69357a3b38f7Smrg	;;
6936ff559fabSmrg
69377a3b38f7Smrg      -framework)
69387a3b38f7Smrg	prev=framework
69397a3b38f7Smrg	continue
69407a3b38f7Smrg	;;
6941ff559fabSmrg
69427a3b38f7Smrg      -inst-prefix-dir)
69437a3b38f7Smrg	prev=inst_prefix
69447a3b38f7Smrg	continue
69457a3b38f7Smrg	;;
6946ff559fabSmrg
69477a3b38f7Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
69487a3b38f7Smrg      # so, if we see these flags be careful not to treat them like -L
69497a3b38f7Smrg      -L[A-Z][A-Z]*:*)
69507a3b38f7Smrg	case $with_gcc/$host in
69517a3b38f7Smrg	no/*-*-irix* | /*-*-irix*)
69527a3b38f7Smrg	  func_append compile_command " $arg"
69537a3b38f7Smrg	  func_append finalize_command " $arg"
69547a3b38f7Smrg	  ;;
69557a3b38f7Smrg	esac
69567a3b38f7Smrg	continue
69577a3b38f7Smrg	;;
6958ff559fabSmrg
69597a3b38f7Smrg      -L*)
6960862f5301Smrg	func_stripname "-L" '' "$arg"
6961862f5301Smrg	if test -z "$func_stripname_result"; then
69627a3b38f7Smrg	  if test "$#" -gt 0; then
69636fc0178dSmrg	    func_fatal_error "require no space between '-L' and '$1'"
69647a3b38f7Smrg	  else
69656fc0178dSmrg	    func_fatal_error "need path for '-L' option"
69667a3b38f7Smrg	  fi
69677a3b38f7Smrg	fi
6968862f5301Smrg	func_resolve_sysroot "$func_stripname_result"
6969862f5301Smrg	dir=$func_resolve_sysroot_result
69707a3b38f7Smrg	# We need an absolute path.
69717a3b38f7Smrg	case $dir in
69727a3b38f7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
69737a3b38f7Smrg	*)
69747a3b38f7Smrg	  absdir=`cd "$dir" && pwd`
69757a3b38f7Smrg	  test -z "$absdir" && \
69766fc0178dSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
69776fc0178dSmrg	  dir=$absdir
69787a3b38f7Smrg	  ;;
69797a3b38f7Smrg	esac
69807a3b38f7Smrg	case "$deplibs " in
6981862f5301Smrg	*" -L$dir "* | *" $arg "*)
6982862f5301Smrg	  # Will only happen for absolute or sysroot arguments
6983862f5301Smrg	  ;;
69847a3b38f7Smrg	*)
6985862f5301Smrg	  # Preserve sysroot, but never include relative directories
6986862f5301Smrg	  case $dir in
6987862f5301Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
6988862f5301Smrg	    *) func_append deplibs " -L$dir" ;;
6989862f5301Smrg	  esac
6990862f5301Smrg	  func_append lib_search_path " $dir"
69917a3b38f7Smrg	  ;;
69927a3b38f7Smrg	esac
69937a3b38f7Smrg	case $host in
69947a3b38f7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
699544dda7b2Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
69967a3b38f7Smrg	  case :$dllsearchpath: in
69977a3b38f7Smrg	  *":$dir:"*) ;;
69987a3b38f7Smrg	  ::) dllsearchpath=$dir;;
6999862f5301Smrg	  *) func_append dllsearchpath ":$dir";;
70007a3b38f7Smrg	  esac
70017a3b38f7Smrg	  case :$dllsearchpath: in
70027a3b38f7Smrg	  *":$testbindir:"*) ;;
70037a3b38f7Smrg	  ::) dllsearchpath=$testbindir;;
7004862f5301Smrg	  *) func_append dllsearchpath ":$testbindir";;
70057a3b38f7Smrg	  esac
70067a3b38f7Smrg	  ;;
70077a3b38f7Smrg	esac
70087a3b38f7Smrg	continue
70097a3b38f7Smrg	;;
7010ff559fabSmrg
70117a3b38f7Smrg      -l*)
70126fc0178dSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
70137a3b38f7Smrg	  case $host in
701444dda7b2Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
70157a3b38f7Smrg	    # These systems don't actually have a C or math library (as such)
70167a3b38f7Smrg	    continue
70177a3b38f7Smrg	    ;;
70187a3b38f7Smrg	  *-*-os2*)
70197a3b38f7Smrg	    # These systems don't actually have a C library (as such)
70206fc0178dSmrg	    test X-lc = "X$arg" && continue
70217a3b38f7Smrg	    ;;
70226fc0178dSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
70237a3b38f7Smrg	    # Do not include libc due to us having libc/libc_r.
70246fc0178dSmrg	    test X-lc = "X$arg" && continue
70257a3b38f7Smrg	    ;;
70267a3b38f7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
70277a3b38f7Smrg	    # Rhapsody C and math libraries are in the System framework
7028862f5301Smrg	    func_append deplibs " System.ltframework"
70297a3b38f7Smrg	    continue
70307a3b38f7Smrg	    ;;
70317a3b38f7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
70327a3b38f7Smrg	    # Causes problems with __ctype
70336fc0178dSmrg	    test X-lc = "X$arg" && continue
70347a3b38f7Smrg	    ;;
70357a3b38f7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
70367a3b38f7Smrg	    # Compiler inserts libc in the correct place for threads to work
70376fc0178dSmrg	    test X-lc = "X$arg" && continue
70387a3b38f7Smrg	    ;;
70397a3b38f7Smrg	  esac
70406fc0178dSmrg	elif test X-lc_r = "X$arg"; then
70417a3b38f7Smrg	 case $host in
70426fc0178dSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
70437a3b38f7Smrg	   # Do not include libc_r directly, use -pthread flag.
70447a3b38f7Smrg	   continue
70457a3b38f7Smrg	   ;;
70467a3b38f7Smrg	 esac
70477a3b38f7Smrg	fi
7048862f5301Smrg	func_append deplibs " $arg"
70497a3b38f7Smrg	continue
70507a3b38f7Smrg	;;
7051ff559fabSmrg
70526fc0178dSmrg      -mllvm)
70536fc0178dSmrg	prev=mllvm
70546fc0178dSmrg	continue
70556fc0178dSmrg	;;
70566fc0178dSmrg
70577a3b38f7Smrg      -module)
70587a3b38f7Smrg	module=yes
70597a3b38f7Smrg	continue
70607a3b38f7Smrg	;;
7061ff559fabSmrg
70627a3b38f7Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
70637a3b38f7Smrg      # classes, name mangling, and exception handling.
70647a3b38f7Smrg      # Darwin uses the -arch flag to determine output architecture.
7065862f5301Smrg      -model|-arch|-isysroot|--sysroot)
7066862f5301Smrg	func_append compiler_flags " $arg"
70677a3b38f7Smrg	func_append compile_command " $arg"
70687a3b38f7Smrg	func_append finalize_command " $arg"
70697a3b38f7Smrg	prev=xcompiler
70707a3b38f7Smrg	continue
70717a3b38f7Smrg	;;
7072ff559fabSmrg
7073fc544a13Smrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7074fc544a13Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7075862f5301Smrg	func_append compiler_flags " $arg"
70767a3b38f7Smrg	func_append compile_command " $arg"
70777a3b38f7Smrg	func_append finalize_command " $arg"
70787a3b38f7Smrg	case "$new_inherited_linker_flags " in
70797a3b38f7Smrg	    *" $arg "*) ;;
7080862f5301Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
70817a3b38f7Smrg	esac
70827a3b38f7Smrg	continue
70837a3b38f7Smrg	;;
7084ff559fabSmrg
70857a3b38f7Smrg      -multi_module)
70866fc0178dSmrg	single_module=$wl-multi_module
70877a3b38f7Smrg	continue
70887a3b38f7Smrg	;;
7089ff559fabSmrg
70907a3b38f7Smrg      -no-fast-install)
70917a3b38f7Smrg	fast_install=no
70927a3b38f7Smrg	continue
70937a3b38f7Smrg	;;
7094ff559fabSmrg
70957a3b38f7Smrg      -no-install)
70967a3b38f7Smrg	case $host in
70977a3b38f7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
70987a3b38f7Smrg	  # The PATH hackery in wrapper scripts is required on Windows
70997a3b38f7Smrg	  # and Darwin in order for the loader to find any dlls it needs.
71006fc0178dSmrg	  func_warning "'-no-install' is ignored for $host"
71016fc0178dSmrg	  func_warning "assuming '-no-fast-install' instead"
71027a3b38f7Smrg	  fast_install=no
71037a3b38f7Smrg	  ;;
71047a3b38f7Smrg	*) no_install=yes ;;
71057a3b38f7Smrg	esac
71067a3b38f7Smrg	continue
71077a3b38f7Smrg	;;
7108ff559fabSmrg
71097a3b38f7Smrg      -no-undefined)
71107a3b38f7Smrg	allow_undefined=no
71117a3b38f7Smrg	continue
71127a3b38f7Smrg	;;
7113ff559fabSmrg
71147a3b38f7Smrg      -objectlist)
71157a3b38f7Smrg	prev=objectlist
71167a3b38f7Smrg	continue
71177a3b38f7Smrg	;;
7118ff559fabSmrg
71196fc0178dSmrg      -os2dllname)
71206fc0178dSmrg	prev=os2dllname
71216fc0178dSmrg	continue
71226fc0178dSmrg	;;
71236fc0178dSmrg
71247a3b38f7Smrg      -o) prev=output ;;
7125ff559fabSmrg
71267a3b38f7Smrg      -precious-files-regex)
71277a3b38f7Smrg	prev=precious_regex
71287a3b38f7Smrg	continue
71297a3b38f7Smrg	;;
7130ff559fabSmrg
71317a3b38f7Smrg      -release)
71327a3b38f7Smrg	prev=release
71337a3b38f7Smrg	continue
71347a3b38f7Smrg	;;
7135ff559fabSmrg
71367a3b38f7Smrg      -rpath)
71377a3b38f7Smrg	prev=rpath
71387a3b38f7Smrg	continue
71397a3b38f7Smrg	;;
7140ff559fabSmrg
71417a3b38f7Smrg      -R)
71427a3b38f7Smrg	prev=xrpath
71437a3b38f7Smrg	continue
71447a3b38f7Smrg	;;
7145ff559fabSmrg
71467a3b38f7Smrg      -R*)
71477a3b38f7Smrg	func_stripname '-R' '' "$arg"
71487a3b38f7Smrg	dir=$func_stripname_result
71497a3b38f7Smrg	# We need an absolute path.
71507a3b38f7Smrg	case $dir in
71517a3b38f7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7152862f5301Smrg	=*)
7153862f5301Smrg	  func_stripname '=' '' "$dir"
7154862f5301Smrg	  dir=$lt_sysroot$func_stripname_result
7155862f5301Smrg	  ;;
71567a3b38f7Smrg	*)
71577a3b38f7Smrg	  func_fatal_error "only absolute run-paths are allowed"
71587a3b38f7Smrg	  ;;
71597a3b38f7Smrg	esac
71607a3b38f7Smrg	case "$xrpath " in
71617a3b38f7Smrg	*" $dir "*) ;;
7162862f5301Smrg	*) func_append xrpath " $dir" ;;
71637a3b38f7Smrg	esac
71647a3b38f7Smrg	continue
71657a3b38f7Smrg	;;
7166ff559fabSmrg
71677a3b38f7Smrg      -shared)
71687a3b38f7Smrg	# The effects of -shared are defined in a previous loop.
71697a3b38f7Smrg	continue
71707a3b38f7Smrg	;;
7171ff559fabSmrg
71727a3b38f7Smrg      -shrext)
71737a3b38f7Smrg	prev=shrext
71747a3b38f7Smrg	continue
71757a3b38f7Smrg	;;
7176ff559fabSmrg
71777a3b38f7Smrg      -static | -static-libtool-libs)
71787a3b38f7Smrg	# The effects of -static are defined in a previous loop.
71797a3b38f7Smrg	# We used to do the same as -all-static on platforms that
71807a3b38f7Smrg	# didn't have a PIC flag, but the assumption that the effects
71817a3b38f7Smrg	# would be equivalent was wrong.  It would break on at least
71827a3b38f7Smrg	# Digital Unix and AIX.
71837a3b38f7Smrg	continue
71847a3b38f7Smrg	;;
7185ff559fabSmrg
71867a3b38f7Smrg      -thread-safe)
71877a3b38f7Smrg	thread_safe=yes
71887a3b38f7Smrg	continue
71897a3b38f7Smrg	;;
7190ff559fabSmrg
71917a3b38f7Smrg      -version-info)
71927a3b38f7Smrg	prev=vinfo
71937a3b38f7Smrg	continue
71947a3b38f7Smrg	;;
7195ff559fabSmrg
71967a3b38f7Smrg      -version-number)
71977a3b38f7Smrg	prev=vinfo
71987a3b38f7Smrg	vinfo_number=yes
71997a3b38f7Smrg	continue
72007a3b38f7Smrg	;;
7201ff559fabSmrg
72027a3b38f7Smrg      -weak)
72037a3b38f7Smrg        prev=weak
72047a3b38f7Smrg	continue
72057a3b38f7Smrg	;;
7206ff559fabSmrg
72077a3b38f7Smrg      -Wc,*)
72087a3b38f7Smrg	func_stripname '-Wc,' '' "$arg"
72097a3b38f7Smrg	args=$func_stripname_result
72107a3b38f7Smrg	arg=
72116fc0178dSmrg	save_ifs=$IFS; IFS=,
72127a3b38f7Smrg	for flag in $args; do
72136fc0178dSmrg	  IFS=$save_ifs
72147a3b38f7Smrg          func_quote_for_eval "$flag"
7215862f5301Smrg	  func_append arg " $func_quote_for_eval_result"
7216862f5301Smrg	  func_append compiler_flags " $func_quote_for_eval_result"
72177a3b38f7Smrg	done
72186fc0178dSmrg	IFS=$save_ifs
72197a3b38f7Smrg	func_stripname ' ' '' "$arg"
72207a3b38f7Smrg	arg=$func_stripname_result
72217a3b38f7Smrg	;;
7222ff559fabSmrg
72237a3b38f7Smrg      -Wl,*)
72247a3b38f7Smrg	func_stripname '-Wl,' '' "$arg"
72257a3b38f7Smrg	args=$func_stripname_result
72267a3b38f7Smrg	arg=
72276fc0178dSmrg	save_ifs=$IFS; IFS=,
72287a3b38f7Smrg	for flag in $args; do
72296fc0178dSmrg	  IFS=$save_ifs
72307a3b38f7Smrg          func_quote_for_eval "$flag"
7231862f5301Smrg	  func_append arg " $wl$func_quote_for_eval_result"
7232862f5301Smrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
7233862f5301Smrg	  func_append linker_flags " $func_quote_for_eval_result"
72347a3b38f7Smrg	done
72356fc0178dSmrg	IFS=$save_ifs
72367a3b38f7Smrg	func_stripname ' ' '' "$arg"
72377a3b38f7Smrg	arg=$func_stripname_result
72387a3b38f7Smrg	;;
7239ff559fabSmrg
72407a3b38f7Smrg      -Xcompiler)
72417a3b38f7Smrg	prev=xcompiler
72427a3b38f7Smrg	continue
72437a3b38f7Smrg	;;
7244ff559fabSmrg
72457a3b38f7Smrg      -Xlinker)
72467a3b38f7Smrg	prev=xlinker
72477a3b38f7Smrg	continue
72487a3b38f7Smrg	;;
7249ff559fabSmrg
72507a3b38f7Smrg      -XCClinker)
72517a3b38f7Smrg	prev=xcclinker
72527a3b38f7Smrg	continue
72537a3b38f7Smrg	;;
7254ff559fabSmrg
72557a3b38f7Smrg      # -msg_* for osf cc
72567a3b38f7Smrg      -msg_*)
72577a3b38f7Smrg	func_quote_for_eval "$arg"
72586fc0178dSmrg	arg=$func_quote_for_eval_result
72597a3b38f7Smrg	;;
7260ff559fabSmrg
726144dda7b2Smrg      # Flags to be passed through unchanged, with rationale:
726244dda7b2Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
726344dda7b2Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
726444dda7b2Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
726544dda7b2Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
726644dda7b2Smrg      # -q*                  compiler args for the IBM compiler
726744dda7b2Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
726844dda7b2Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
726944dda7b2Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
72706fc0178dSmrg      # -fstack-protector*   stack protector flags for GCC
727144dda7b2Smrg      # @file                GCC response files
727244dda7b2Smrg      # -tp=*                Portland pgcc target processor selection
7273862f5301Smrg      # --sysroot=*          for sysroot support
72746fc0178dSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
72756fc0178dSmrg      # -stdlib=*            select c++ std lib with clang
72767a3b38f7Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7277862f5301Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
72786fc0178dSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)
72797a3b38f7Smrg        func_quote_for_eval "$arg"
72806fc0178dSmrg	arg=$func_quote_for_eval_result
72817a3b38f7Smrg        func_append compile_command " $arg"
72827a3b38f7Smrg        func_append finalize_command " $arg"
7283862f5301Smrg        func_append compiler_flags " $arg"
72847a3b38f7Smrg        continue
72857a3b38f7Smrg        ;;
7286ff559fabSmrg
72876fc0178dSmrg      -Z*)
72886fc0178dSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
72896fc0178dSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
72906fc0178dSmrg	  compiler_flags="$compiler_flags $arg"
72916fc0178dSmrg	  func_append compile_command " $arg"
72926fc0178dSmrg	  func_append finalize_command " $arg"
72936fc0178dSmrg	  case $arg in
72946fc0178dSmrg	  -Zlinker | -Zstack)
72956fc0178dSmrg	    prev=xcompiler
72966fc0178dSmrg	    ;;
72976fc0178dSmrg	  esac
72986fc0178dSmrg	  continue
72996fc0178dSmrg        else
73006fc0178dSmrg	  # Otherwise treat like 'Some other compiler flag' below
73016fc0178dSmrg	  func_quote_for_eval "$arg"
73026fc0178dSmrg	  arg=$func_quote_for_eval_result
73036fc0178dSmrg        fi
73046fc0178dSmrg	;;
73056fc0178dSmrg
73067a3b38f7Smrg      # Some other compiler flag.
73077a3b38f7Smrg      -* | +*)
73087a3b38f7Smrg        func_quote_for_eval "$arg"
73096fc0178dSmrg	arg=$func_quote_for_eval_result
73107a3b38f7Smrg	;;
7311ff559fabSmrg
73127a3b38f7Smrg      *.$objext)
73137a3b38f7Smrg	# A standard object.
7314862f5301Smrg	func_append objs " $arg"
73157a3b38f7Smrg	;;
73167a3b38f7Smrg
73177a3b38f7Smrg      *.lo)
73187a3b38f7Smrg	# A libtool-controlled object.
73197a3b38f7Smrg
73207a3b38f7Smrg	# Check to see that this really is a libtool object.
73217a3b38f7Smrg	if func_lalib_unsafe_p "$arg"; then
73227a3b38f7Smrg	  pic_object=
73237a3b38f7Smrg	  non_pic_object=
73247a3b38f7Smrg
73257a3b38f7Smrg	  # Read the .lo file
73267a3b38f7Smrg	  func_source "$arg"
73277a3b38f7Smrg
73287a3b38f7Smrg	  if test -z "$pic_object" ||
73297a3b38f7Smrg	     test -z "$non_pic_object" ||
73306fc0178dSmrg	     test none = "$pic_object" &&
73316fc0178dSmrg	     test none = "$non_pic_object"; then
73326fc0178dSmrg	    func_fatal_error "cannot find name of object for '$arg'"
73337a3b38f7Smrg	  fi
73347a3b38f7Smrg
73357a3b38f7Smrg	  # Extract subdirectory from the argument.
73367a3b38f7Smrg	  func_dirname "$arg" "/" ""
73376fc0178dSmrg	  xdir=$func_dirname_result
73387a3b38f7Smrg
73396fc0178dSmrg	  test none = "$pic_object" || {
73407a3b38f7Smrg	    # Prepend the subdirectory the object is found in.
73416fc0178dSmrg	    pic_object=$xdir$pic_object
73427a3b38f7Smrg
73436fc0178dSmrg	    if test dlfiles = "$prev"; then
73446fc0178dSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7345862f5301Smrg		func_append dlfiles " $pic_object"
73467a3b38f7Smrg		prev=
73477a3b38f7Smrg		continue
73487a3b38f7Smrg	      else
73497a3b38f7Smrg		# If libtool objects are unsupported, then we need to preload.
73507a3b38f7Smrg		prev=dlprefiles
73517a3b38f7Smrg	      fi
73527a3b38f7Smrg	    fi
73537a3b38f7Smrg
73547a3b38f7Smrg	    # CHECK ME:  I think I busted this.  -Ossama
73556fc0178dSmrg	    if test dlprefiles = "$prev"; then
73567a3b38f7Smrg	      # Preload the old-style object.
7357862f5301Smrg	      func_append dlprefiles " $pic_object"
73587a3b38f7Smrg	      prev=
73597a3b38f7Smrg	    fi
73607a3b38f7Smrg
73617a3b38f7Smrg	    # A PIC object.
73627a3b38f7Smrg	    func_append libobjs " $pic_object"
73636fc0178dSmrg	    arg=$pic_object
73646fc0178dSmrg	  }
73657a3b38f7Smrg
73667a3b38f7Smrg	  # Non-PIC object.
73676fc0178dSmrg	  if test none != "$non_pic_object"; then
73687a3b38f7Smrg	    # Prepend the subdirectory the object is found in.
73696fc0178dSmrg	    non_pic_object=$xdir$non_pic_object
73707a3b38f7Smrg
73717a3b38f7Smrg	    # A standard non-PIC object
73727a3b38f7Smrg	    func_append non_pic_objects " $non_pic_object"
73736fc0178dSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
73746fc0178dSmrg	      arg=$non_pic_object
73757a3b38f7Smrg	    fi
73767a3b38f7Smrg	  else
73777a3b38f7Smrg	    # If the PIC object exists, use it instead.
73787a3b38f7Smrg	    # $xdir was prepended to $pic_object above.
73796fc0178dSmrg	    non_pic_object=$pic_object
73807a3b38f7Smrg	    func_append non_pic_objects " $non_pic_object"
73817a3b38f7Smrg	  fi
73827a3b38f7Smrg	else
73837a3b38f7Smrg	  # Only an error if not doing a dry-run.
73847a3b38f7Smrg	  if $opt_dry_run; then
73857a3b38f7Smrg	    # Extract subdirectory from the argument.
73867a3b38f7Smrg	    func_dirname "$arg" "/" ""
73876fc0178dSmrg	    xdir=$func_dirname_result
73887a3b38f7Smrg
73897a3b38f7Smrg	    func_lo2o "$arg"
73907a3b38f7Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
73917a3b38f7Smrg	    non_pic_object=$xdir$func_lo2o_result
73927a3b38f7Smrg	    func_append libobjs " $pic_object"
73937a3b38f7Smrg	    func_append non_pic_objects " $non_pic_object"
73947a3b38f7Smrg	  else
73956fc0178dSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
73967a3b38f7Smrg	  fi
73977a3b38f7Smrg	fi
73987a3b38f7Smrg	;;
73997a3b38f7Smrg
74007a3b38f7Smrg      *.$libext)
74017a3b38f7Smrg	# An archive.
7402862f5301Smrg	func_append deplibs " $arg"
7403862f5301Smrg	func_append old_deplibs " $arg"
74047a3b38f7Smrg	continue
74057a3b38f7Smrg	;;
74067a3b38f7Smrg
74077a3b38f7Smrg      *.la)
74087a3b38f7Smrg	# A libtool-controlled library.
74097a3b38f7Smrg
7410862f5301Smrg	func_resolve_sysroot "$arg"
74116fc0178dSmrg	if test dlfiles = "$prev"; then
74127a3b38f7Smrg	  # This library was specified with -dlopen.
7413862f5301Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
74147a3b38f7Smrg	  prev=
74156fc0178dSmrg	elif test dlprefiles = "$prev"; then
74167a3b38f7Smrg	  # The library was specified with -dlpreopen.
7417862f5301Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
74187a3b38f7Smrg	  prev=
74197a3b38f7Smrg	else
7420862f5301Smrg	  func_append deplibs " $func_resolve_sysroot_result"
74217a3b38f7Smrg	fi
74227a3b38f7Smrg	continue
74237a3b38f7Smrg	;;
74247a3b38f7Smrg
74257a3b38f7Smrg      # Some other compiler argument.
74267a3b38f7Smrg      *)
74277a3b38f7Smrg	# Unknown arguments in both finalize_command and compile_command need
74287a3b38f7Smrg	# to be aesthetically quoted because they are evaled later.
74297a3b38f7Smrg	func_quote_for_eval "$arg"
74306fc0178dSmrg	arg=$func_quote_for_eval_result
74317a3b38f7Smrg	;;
74327a3b38f7Smrg      esac # arg
74337a3b38f7Smrg
74347a3b38f7Smrg      # Now actually substitute the argument into the commands.
74357a3b38f7Smrg      if test -n "$arg"; then
74367a3b38f7Smrg	func_append compile_command " $arg"
74377a3b38f7Smrg	func_append finalize_command " $arg"
74387a3b38f7Smrg      fi
74397a3b38f7Smrg    done # argument parsing loop
74407a3b38f7Smrg
74417a3b38f7Smrg    test -n "$prev" && \
74426fc0178dSmrg      func_fatal_help "the '$prevarg' option requires an argument"
74437a3b38f7Smrg
74446fc0178dSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
74457a3b38f7Smrg      eval arg=\"$export_dynamic_flag_spec\"
74467a3b38f7Smrg      func_append compile_command " $arg"
74477a3b38f7Smrg      func_append finalize_command " $arg"
74487a3b38f7Smrg    fi
74497a3b38f7Smrg
74507a3b38f7Smrg    oldlibs=
74517a3b38f7Smrg    # calculate the name of the file, without its directory
74527a3b38f7Smrg    func_basename "$output"
74536fc0178dSmrg    outputname=$func_basename_result
74546fc0178dSmrg    libobjs_save=$libobjs
74557a3b38f7Smrg
74567a3b38f7Smrg    if test -n "$shlibpath_var"; then
74577a3b38f7Smrg      # get the directories listed in $shlibpath_var
74586fc0178dSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7459ff559fabSmrg    else
74607a3b38f7Smrg      shlib_search_path=
7461ff559fabSmrg    fi
74627a3b38f7Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
74637a3b38f7Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7464ff559fabSmrg
74656fc0178dSmrg    # Definition is injected by LT_CONFIG during libtool generation.
74666fc0178dSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
74676fc0178dSmrg
74687a3b38f7Smrg    func_dirname "$output" "/" ""
74696fc0178dSmrg    output_objdir=$func_dirname_result$objdir
7470862f5301Smrg    func_to_tool_file "$output_objdir/"
7471862f5301Smrg    tool_output_objdir=$func_to_tool_file_result
74727a3b38f7Smrg    # Create the object directory.
74737a3b38f7Smrg    func_mkdir_p "$output_objdir"
7474ff559fabSmrg
74757a3b38f7Smrg    # Determine the type of output
74767a3b38f7Smrg    case $output in
74777a3b38f7Smrg    "")
74787a3b38f7Smrg      func_fatal_help "you must specify an output file"
74797a3b38f7Smrg      ;;
74807a3b38f7Smrg    *.$libext) linkmode=oldlib ;;
74817a3b38f7Smrg    *.lo | *.$objext) linkmode=obj ;;
74827a3b38f7Smrg    *.la) linkmode=lib ;;
74837a3b38f7Smrg    *) linkmode=prog ;; # Anything else should be a program.
74847a3b38f7Smrg    esac
74857a3b38f7Smrg
74867a3b38f7Smrg    specialdeplibs=
74877a3b38f7Smrg
74887a3b38f7Smrg    libs=
74897a3b38f7Smrg    # Find all interdependent deplibs by searching for libraries
74907a3b38f7Smrg    # that are linked more than once (e.g. -la -lb -la)
74917a3b38f7Smrg    for deplib in $deplibs; do
74926fc0178dSmrg      if $opt_preserve_dup_deps; then
74937a3b38f7Smrg	case "$libs " in
7494862f5301Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
74957a3b38f7Smrg	esac
74967a3b38f7Smrg      fi
7497862f5301Smrg      func_append libs " $deplib"
74987a3b38f7Smrg    done
74997a3b38f7Smrg
75006fc0178dSmrg    if test lib = "$linkmode"; then
75017a3b38f7Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
75027a3b38f7Smrg
75037a3b38f7Smrg      # Compute libraries that are listed more than once in $predeps
75047a3b38f7Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
75057a3b38f7Smrg      # not to be eliminated).
75067a3b38f7Smrg      pre_post_deps=
75077a3b38f7Smrg      if $opt_duplicate_compiler_generated_deps; then
75087a3b38f7Smrg	for pre_post_dep in $predeps $postdeps; do
75097a3b38f7Smrg	  case "$pre_post_deps " in
7510862f5301Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
75117a3b38f7Smrg	  esac
7512862f5301Smrg	  func_append pre_post_deps " $pre_post_dep"
75137a3b38f7Smrg	done
75147a3b38f7Smrg      fi
75157a3b38f7Smrg      pre_post_deps=
75167a3b38f7Smrg    fi
75177a3b38f7Smrg
75187a3b38f7Smrg    deplibs=
75197a3b38f7Smrg    newdependency_libs=
75207a3b38f7Smrg    newlib_search_path=
75217a3b38f7Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
75227a3b38f7Smrg    notinst_deplibs= # not-installed libtool libraries
75237a3b38f7Smrg    notinst_path= # paths that contain not-installed libtool libraries
75247a3b38f7Smrg
75257a3b38f7Smrg    case $linkmode in
75267a3b38f7Smrg    lib)
75277a3b38f7Smrg	passes="conv dlpreopen link"
75287a3b38f7Smrg	for file in $dlfiles $dlprefiles; do
75297a3b38f7Smrg	  case $file in
75307a3b38f7Smrg	  *.la) ;;
75317a3b38f7Smrg	  *)
75326fc0178dSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
75337a3b38f7Smrg	    ;;
75347a3b38f7Smrg	  esac
75357a3b38f7Smrg	done
75367a3b38f7Smrg	;;
75377a3b38f7Smrg    prog)
75387a3b38f7Smrg	compile_deplibs=
75397a3b38f7Smrg	finalize_deplibs=
75406fc0178dSmrg	alldeplibs=false
75417a3b38f7Smrg	newdlfiles=
75427a3b38f7Smrg	newdlprefiles=
75437a3b38f7Smrg	passes="conv scan dlopen dlpreopen link"
75447a3b38f7Smrg	;;
75457a3b38f7Smrg    *)  passes="conv"
75467a3b38f7Smrg	;;
75477a3b38f7Smrg    esac
75487a3b38f7Smrg
75497a3b38f7Smrg    for pass in $passes; do
75507a3b38f7Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
75517a3b38f7Smrg      # so that -L comes before libs that need it for instance...
75526fc0178dSmrg      if test lib,link = "$linkmode,$pass"; then
75537a3b38f7Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
75547a3b38f7Smrg	##        order, and fix it there properly
75557a3b38f7Smrg        tmp_deplibs=
75567a3b38f7Smrg	for deplib in $deplibs; do
75577a3b38f7Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
75587a3b38f7Smrg	done
75596fc0178dSmrg	deplibs=$tmp_deplibs
75607a3b38f7Smrg      fi
75617a3b38f7Smrg
75626fc0178dSmrg      if test lib,link = "$linkmode,$pass" ||
75636fc0178dSmrg	 test prog,scan = "$linkmode,$pass"; then
75646fc0178dSmrg	libs=$deplibs
75657a3b38f7Smrg	deplibs=
75667a3b38f7Smrg      fi
75676fc0178dSmrg      if test prog = "$linkmode"; then
75687a3b38f7Smrg	case $pass in
75696fc0178dSmrg	dlopen) libs=$dlfiles ;;
75706fc0178dSmrg	dlpreopen) libs=$dlprefiles ;;
75717a3b38f7Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
75727a3b38f7Smrg	esac
75737a3b38f7Smrg      fi
75746fc0178dSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
75757a3b38f7Smrg	# Collect and forward deplibs of preopened libtool libs
75767a3b38f7Smrg	for lib in $dlprefiles; do
75777a3b38f7Smrg	  # Ignore non-libtool-libs
75787a3b38f7Smrg	  dependency_libs=
7579862f5301Smrg	  func_resolve_sysroot "$lib"
75807a3b38f7Smrg	  case $lib in
7581862f5301Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
75827a3b38f7Smrg	  esac
75837a3b38f7Smrg
75847a3b38f7Smrg	  # Collect preopened libtool deplibs, except any this library
75857a3b38f7Smrg	  # has declared as weak libs
75867a3b38f7Smrg	  for deplib in $dependency_libs; do
758744dda7b2Smrg	    func_basename "$deplib"
758844dda7b2Smrg            deplib_base=$func_basename_result
75897a3b38f7Smrg	    case " $weak_libs " in
75907a3b38f7Smrg	    *" $deplib_base "*) ;;
7591862f5301Smrg	    *) func_append deplibs " $deplib" ;;
75927a3b38f7Smrg	    esac
75937a3b38f7Smrg	  done
75947a3b38f7Smrg	done
75956fc0178dSmrg	libs=$dlprefiles
75967a3b38f7Smrg      fi
75976fc0178dSmrg      if test dlopen = "$pass"; then
75987a3b38f7Smrg	# Collect dlpreopened libraries
75996fc0178dSmrg	save_deplibs=$deplibs
76007a3b38f7Smrg	deplibs=
76017a3b38f7Smrg      fi
76027a3b38f7Smrg
76037a3b38f7Smrg      for deplib in $libs; do
76047a3b38f7Smrg	lib=
76056fc0178dSmrg	found=false
76067a3b38f7Smrg	case $deplib in
7607fc544a13Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7608fc544a13Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
76096fc0178dSmrg	  if test prog,link = "$linkmode,$pass"; then
76107a3b38f7Smrg	    compile_deplibs="$deplib $compile_deplibs"
76117a3b38f7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
76127a3b38f7Smrg	  else
7613862f5301Smrg	    func_append compiler_flags " $deplib"
76146fc0178dSmrg	    if test lib = "$linkmode"; then
76157a3b38f7Smrg		case "$new_inherited_linker_flags " in
76167a3b38f7Smrg		    *" $deplib "*) ;;
7617862f5301Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
76187a3b38f7Smrg		esac
76197a3b38f7Smrg	    fi
76207a3b38f7Smrg	  fi
76217a3b38f7Smrg	  continue
76227a3b38f7Smrg	  ;;
76237a3b38f7Smrg	-l*)
76246fc0178dSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
76256fc0178dSmrg	    func_warning "'-l' is ignored for archives/objects"
76267a3b38f7Smrg	    continue
76277a3b38f7Smrg	  fi
76287a3b38f7Smrg	  func_stripname '-l' '' "$deplib"
76297a3b38f7Smrg	  name=$func_stripname_result
76306fc0178dSmrg	  if test lib = "$linkmode"; then
76317a3b38f7Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
76327a3b38f7Smrg	  else
76337a3b38f7Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
76347a3b38f7Smrg	  fi
76357a3b38f7Smrg	  for searchdir in $searchdirs; do
76367a3b38f7Smrg	    for search_ext in .la $std_shrext .so .a; do
76377a3b38f7Smrg	      # Search the libtool library
76386fc0178dSmrg	      lib=$searchdir/lib$name$search_ext
76397a3b38f7Smrg	      if test -f "$lib"; then
76406fc0178dSmrg		if test .la = "$search_ext"; then
76416fc0178dSmrg		  found=:
76427a3b38f7Smrg		else
76436fc0178dSmrg		  found=false
76447a3b38f7Smrg		fi
76457a3b38f7Smrg		break 2
76467a3b38f7Smrg	      fi
76477a3b38f7Smrg	    done
76487a3b38f7Smrg	  done
76496fc0178dSmrg	  if $found; then
76506fc0178dSmrg	    # deplib is a libtool library
76517a3b38f7Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
76527a3b38f7Smrg	    # We need to do some special things here, and not later.
76536fc0178dSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
76547a3b38f7Smrg	      case " $predeps $postdeps " in
76557a3b38f7Smrg	      *" $deplib "*)
76567a3b38f7Smrg		if func_lalib_p "$lib"; then
76577a3b38f7Smrg		  library_names=
76587a3b38f7Smrg		  old_library=
76597a3b38f7Smrg		  func_source "$lib"
76607a3b38f7Smrg		  for l in $old_library $library_names; do
76616fc0178dSmrg		    ll=$l
76627a3b38f7Smrg		  done
76636fc0178dSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
76646fc0178dSmrg		    found=false
76657a3b38f7Smrg		    func_dirname "$lib" "" "."
76666fc0178dSmrg		    ladir=$func_dirname_result
76677a3b38f7Smrg		    lib=$ladir/$old_library
76686fc0178dSmrg		    if test prog,link = "$linkmode,$pass"; then
76697a3b38f7Smrg		      compile_deplibs="$deplib $compile_deplibs"
76707a3b38f7Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
76717a3b38f7Smrg		    else
76727a3b38f7Smrg		      deplibs="$deplib $deplibs"
76736fc0178dSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
76747a3b38f7Smrg		    fi
76757a3b38f7Smrg		    continue
76767a3b38f7Smrg		  fi
76777a3b38f7Smrg		fi
76787a3b38f7Smrg		;;
76797a3b38f7Smrg	      *) ;;
76807a3b38f7Smrg	      esac
76817a3b38f7Smrg	    fi
76826fc0178dSmrg	  else
76836fc0178dSmrg	    # deplib doesn't seem to be a libtool library
76846fc0178dSmrg	    if test prog,link = "$linkmode,$pass"; then
76856fc0178dSmrg	      compile_deplibs="$deplib $compile_deplibs"
76866fc0178dSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
76876fc0178dSmrg	    else
76886fc0178dSmrg	      deplibs="$deplib $deplibs"
76896fc0178dSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
76906fc0178dSmrg	    fi
76916fc0178dSmrg	    continue
76927a3b38f7Smrg	  fi
76937a3b38f7Smrg	  ;; # -l
76947a3b38f7Smrg	*.ltframework)
76956fc0178dSmrg	  if test prog,link = "$linkmode,$pass"; then
76967a3b38f7Smrg	    compile_deplibs="$deplib $compile_deplibs"
76977a3b38f7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
76987a3b38f7Smrg	  else
76997a3b38f7Smrg	    deplibs="$deplib $deplibs"
77006fc0178dSmrg	    if test lib = "$linkmode"; then
77017a3b38f7Smrg		case "$new_inherited_linker_flags " in
77027a3b38f7Smrg		    *" $deplib "*) ;;
7703862f5301Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
77047a3b38f7Smrg		esac
77057a3b38f7Smrg	    fi
77067a3b38f7Smrg	  fi
77077a3b38f7Smrg	  continue
77087a3b38f7Smrg	  ;;
77097a3b38f7Smrg	-L*)
77107a3b38f7Smrg	  case $linkmode in
77117a3b38f7Smrg	  lib)
77127a3b38f7Smrg	    deplibs="$deplib $deplibs"
77136fc0178dSmrg	    test conv = "$pass" && continue
77147a3b38f7Smrg	    newdependency_libs="$deplib $newdependency_libs"
77157a3b38f7Smrg	    func_stripname '-L' '' "$deplib"
7716862f5301Smrg	    func_resolve_sysroot "$func_stripname_result"
7717862f5301Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
77187a3b38f7Smrg	    ;;
77197a3b38f7Smrg	  prog)
77206fc0178dSmrg	    if test conv = "$pass"; then
77217a3b38f7Smrg	      deplibs="$deplib $deplibs"
77227a3b38f7Smrg	      continue
77237a3b38f7Smrg	    fi
77246fc0178dSmrg	    if test scan = "$pass"; then
77257a3b38f7Smrg	      deplibs="$deplib $deplibs"
77267a3b38f7Smrg	    else
77277a3b38f7Smrg	      compile_deplibs="$deplib $compile_deplibs"
77287a3b38f7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
77297a3b38f7Smrg	    fi
77307a3b38f7Smrg	    func_stripname '-L' '' "$deplib"
7731862f5301Smrg	    func_resolve_sysroot "$func_stripname_result"
7732862f5301Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
77337a3b38f7Smrg	    ;;
77347a3b38f7Smrg	  *)
77356fc0178dSmrg	    func_warning "'-L' is ignored for archives/objects"
77367a3b38f7Smrg	    ;;
77377a3b38f7Smrg	  esac # linkmode
77387a3b38f7Smrg	  continue
77397a3b38f7Smrg	  ;; # -L
77407a3b38f7Smrg	-R*)
77416fc0178dSmrg	  if test link = "$pass"; then
77427a3b38f7Smrg	    func_stripname '-R' '' "$deplib"
7743862f5301Smrg	    func_resolve_sysroot "$func_stripname_result"
7744862f5301Smrg	    dir=$func_resolve_sysroot_result
77457a3b38f7Smrg	    # Make sure the xrpath contains only unique directories.
77467a3b38f7Smrg	    case "$xrpath " in
77477a3b38f7Smrg	    *" $dir "*) ;;
7748862f5301Smrg	    *) func_append xrpath " $dir" ;;
77497a3b38f7Smrg	    esac
77507a3b38f7Smrg	  fi
77517a3b38f7Smrg	  deplibs="$deplib $deplibs"
77527a3b38f7Smrg	  continue
77537a3b38f7Smrg	  ;;
7754862f5301Smrg	*.la)
7755862f5301Smrg	  func_resolve_sysroot "$deplib"
7756862f5301Smrg	  lib=$func_resolve_sysroot_result
7757862f5301Smrg	  ;;
77587a3b38f7Smrg	*.$libext)
77596fc0178dSmrg	  if test conv = "$pass"; then
77607a3b38f7Smrg	    deplibs="$deplib $deplibs"
77617a3b38f7Smrg	    continue
77627a3b38f7Smrg	  fi
77637a3b38f7Smrg	  case $linkmode in
77647a3b38f7Smrg	  lib)
77657a3b38f7Smrg	    # Linking convenience modules into shared libraries is allowed,
77667a3b38f7Smrg	    # but linking other static libraries is non-portable.
77677a3b38f7Smrg	    case " $dlpreconveniencelibs " in
77687a3b38f7Smrg	    *" $deplib "*) ;;
77697a3b38f7Smrg	    *)
77706fc0178dSmrg	      valid_a_lib=false
77717a3b38f7Smrg	      case $deplibs_check_method in
77727a3b38f7Smrg		match_pattern*)
77737a3b38f7Smrg		  set dummy $deplibs_check_method; shift
77747a3b38f7Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
777544dda7b2Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
77767a3b38f7Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
77776fc0178dSmrg		    valid_a_lib=:
77787a3b38f7Smrg		  fi
77797a3b38f7Smrg		;;
77807a3b38f7Smrg		pass_all)
77816fc0178dSmrg		  valid_a_lib=:
77827a3b38f7Smrg		;;
77837a3b38f7Smrg	      esac
77846fc0178dSmrg	      if $valid_a_lib; then
77856fc0178dSmrg		echo
77866fc0178dSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
77876fc0178dSmrg		$ECHO "*** static library $deplib is not portable!"
77886fc0178dSmrg		deplibs="$deplib $deplibs"
77896fc0178dSmrg	      else
779044dda7b2Smrg		echo
77917a3b38f7Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
779244dda7b2Smrg		echo "*** I have the capability to make that library automatically link in when"
779344dda7b2Smrg		echo "*** you link to this library.  But I can only do this if you have a"
779444dda7b2Smrg		echo "*** shared version of the library, which you do not appear to have"
779544dda7b2Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
779644dda7b2Smrg		echo "*** that it is just a static archive that I should not use here."
77977a3b38f7Smrg	      fi
77987a3b38f7Smrg	      ;;
77997a3b38f7Smrg	    esac
78007a3b38f7Smrg	    continue
78017a3b38f7Smrg	    ;;
78027a3b38f7Smrg	  prog)
78036fc0178dSmrg	    if test link != "$pass"; then
78047a3b38f7Smrg	      deplibs="$deplib $deplibs"
78057a3b38f7Smrg	    else
78067a3b38f7Smrg	      compile_deplibs="$deplib $compile_deplibs"
78077a3b38f7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
78087a3b38f7Smrg	    fi
78097a3b38f7Smrg	    continue
78107a3b38f7Smrg	    ;;
78117a3b38f7Smrg	  esac # linkmode
78127a3b38f7Smrg	  ;; # *.$libext
78137a3b38f7Smrg	*.lo | *.$objext)
78146fc0178dSmrg	  if test conv = "$pass"; then
78157a3b38f7Smrg	    deplibs="$deplib $deplibs"
78166fc0178dSmrg	  elif test prog = "$linkmode"; then
78176fc0178dSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
78187a3b38f7Smrg	      # If there is no dlopen support or we're linking statically,
78197a3b38f7Smrg	      # we need to preload.
7820862f5301Smrg	      func_append newdlprefiles " $deplib"
78217a3b38f7Smrg	      compile_deplibs="$deplib $compile_deplibs"
78227a3b38f7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
78237a3b38f7Smrg	    else
7824862f5301Smrg	      func_append newdlfiles " $deplib"
78257a3b38f7Smrg	    fi
78267a3b38f7Smrg	  fi
78277a3b38f7Smrg	  continue
78287a3b38f7Smrg	  ;;
78297a3b38f7Smrg	%DEPLIBS%)
78306fc0178dSmrg	  alldeplibs=:
78317a3b38f7Smrg	  continue
78327a3b38f7Smrg	  ;;
78337a3b38f7Smrg	esac # case $deplib
78347a3b38f7Smrg
78356fc0178dSmrg	$found || test -f "$lib" \
78366fc0178dSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
78377a3b38f7Smrg
78387a3b38f7Smrg	# Check to see that this really is a libtool archive.
78397a3b38f7Smrg	func_lalib_unsafe_p "$lib" \
78406fc0178dSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
78417a3b38f7Smrg
78427a3b38f7Smrg	func_dirname "$lib" "" "."
78436fc0178dSmrg	ladir=$func_dirname_result
78447a3b38f7Smrg
78457a3b38f7Smrg	dlname=
78467a3b38f7Smrg	dlopen=
78477a3b38f7Smrg	dlpreopen=
78487a3b38f7Smrg	libdir=
78497a3b38f7Smrg	library_names=
78507a3b38f7Smrg	old_library=
78517a3b38f7Smrg	inherited_linker_flags=
78527a3b38f7Smrg	# If the library was installed with an old release of libtool,
78537a3b38f7Smrg	# it will not redefine variables installed, or shouldnotlink
78547a3b38f7Smrg	installed=yes
78557a3b38f7Smrg	shouldnotlink=no
78567a3b38f7Smrg	avoidtemprpath=
78577a3b38f7Smrg
78587a3b38f7Smrg
78597a3b38f7Smrg	# Read the .la file
78607a3b38f7Smrg	func_source "$lib"
78617a3b38f7Smrg
78627a3b38f7Smrg	# Convert "-framework foo" to "foo.ltframework"
78637a3b38f7Smrg	if test -n "$inherited_linker_flags"; then
786444dda7b2Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
78657a3b38f7Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
78667a3b38f7Smrg	    case " $new_inherited_linker_flags " in
78677a3b38f7Smrg	      *" $tmp_inherited_linker_flag "*) ;;
7868862f5301Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
78697a3b38f7Smrg	    esac
78707a3b38f7Smrg	  done
78717a3b38f7Smrg	fi
787244dda7b2Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
78736fc0178dSmrg	if test lib,link = "$linkmode,$pass" ||
78746fc0178dSmrg	   test prog,scan = "$linkmode,$pass" ||
78756fc0178dSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
7876862f5301Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
7877862f5301Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
78787a3b38f7Smrg	fi
78797a3b38f7Smrg
78806fc0178dSmrg	if test conv = "$pass"; then
78817a3b38f7Smrg	  # Only check for convenience libraries
78827a3b38f7Smrg	  deplibs="$lib $deplibs"
78837a3b38f7Smrg	  if test -z "$libdir"; then
78847a3b38f7Smrg	    if test -z "$old_library"; then
78856fc0178dSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
78867a3b38f7Smrg	    fi
78877a3b38f7Smrg	    # It is a libtool convenience library, so add in its objects.
7888862f5301Smrg	    func_append convenience " $ladir/$objdir/$old_library"
7889862f5301Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
78906fc0178dSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
78916fc0178dSmrg	    func_fatal_error "'$lib' is not a convenience library"
78927a3b38f7Smrg	  fi
78937a3b38f7Smrg	  tmp_libs=
78947a3b38f7Smrg	  for deplib in $dependency_libs; do
78957a3b38f7Smrg	    deplibs="$deplib $deplibs"
78966fc0178dSmrg	    if $opt_preserve_dup_deps; then
78977a3b38f7Smrg	      case "$tmp_libs " in
7898862f5301Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
78997a3b38f7Smrg	      esac
79007a3b38f7Smrg	    fi
7901862f5301Smrg	    func_append tmp_libs " $deplib"
79027a3b38f7Smrg	  done
79037a3b38f7Smrg	  continue
79047a3b38f7Smrg	fi # $pass = conv
79057a3b38f7Smrg
79067a3b38f7Smrg
79077a3b38f7Smrg	# Get the name of the library we link against.
79087a3b38f7Smrg	linklib=
7909862f5301Smrg	if test -n "$old_library" &&
79106fc0178dSmrg	   { test yes = "$prefer_static_libs" ||
79116fc0178dSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
7912862f5301Smrg	  linklib=$old_library
7913862f5301Smrg	else
7914862f5301Smrg	  for l in $old_library $library_names; do
79156fc0178dSmrg	    linklib=$l
7916862f5301Smrg	  done
7917862f5301Smrg	fi
79187a3b38f7Smrg	if test -z "$linklib"; then
79196fc0178dSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
79207a3b38f7Smrg	fi
79217a3b38f7Smrg
79227a3b38f7Smrg	# This library was specified with -dlopen.
79236fc0178dSmrg	if test dlopen = "$pass"; then
79246fc0178dSmrg	  test -z "$libdir" \
79256fc0178dSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
79267a3b38f7Smrg	  if test -z "$dlname" ||
79276fc0178dSmrg	     test yes != "$dlopen_support" ||
79286fc0178dSmrg	     test no = "$build_libtool_libs"
79296fc0178dSmrg	  then
79307a3b38f7Smrg	    # If there is no dlname, no dlopen support or we're linking
79317a3b38f7Smrg	    # statically, we need to preload.  We also need to preload any
79327a3b38f7Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
79337a3b38f7Smrg	    # bomb out in the load deplibs phase.
7934862f5301Smrg	    func_append dlprefiles " $lib $dependency_libs"
79357a3b38f7Smrg	  else
7936862f5301Smrg	    func_append newdlfiles " $lib"
79377a3b38f7Smrg	  fi
79387a3b38f7Smrg	  continue
79397a3b38f7Smrg	fi # $pass = dlopen
79407a3b38f7Smrg
79417a3b38f7Smrg	# We need an absolute path.
79427a3b38f7Smrg	case $ladir in
79436fc0178dSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
79447a3b38f7Smrg	*)
79457a3b38f7Smrg	  abs_ladir=`cd "$ladir" && pwd`
79467a3b38f7Smrg	  if test -z "$abs_ladir"; then
79476fc0178dSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
79487a3b38f7Smrg	    func_warning "passing it literally to the linker, although it might fail"
79496fc0178dSmrg	    abs_ladir=$ladir
79507a3b38f7Smrg	  fi
79517a3b38f7Smrg	  ;;
79527a3b38f7Smrg	esac
79537a3b38f7Smrg	func_basename "$lib"
79546fc0178dSmrg	laname=$func_basename_result
79557a3b38f7Smrg
79567a3b38f7Smrg	# Find the relevant object directory and library name.
79576fc0178dSmrg	if test yes = "$installed"; then
7958862f5301Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
79596fc0178dSmrg	    func_warning "library '$lib' was moved."
79606fc0178dSmrg	    dir=$ladir
79616fc0178dSmrg	    absdir=$abs_ladir
79626fc0178dSmrg	    libdir=$abs_ladir
79637a3b38f7Smrg	  else
79646fc0178dSmrg	    dir=$lt_sysroot$libdir
79656fc0178dSmrg	    absdir=$lt_sysroot$libdir
79667a3b38f7Smrg	  fi
79676fc0178dSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
79687a3b38f7Smrg	else
79697a3b38f7Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
79706fc0178dSmrg	    dir=$ladir
79716fc0178dSmrg	    absdir=$abs_ladir
79727a3b38f7Smrg	    # Remove this search path later
7973862f5301Smrg	    func_append notinst_path " $abs_ladir"
79747a3b38f7Smrg	  else
79756fc0178dSmrg	    dir=$ladir/$objdir
79766fc0178dSmrg	    absdir=$abs_ladir/$objdir
79777a3b38f7Smrg	    # Remove this search path later
7978862f5301Smrg	    func_append notinst_path " $abs_ladir"
79797a3b38f7Smrg	  fi
79807a3b38f7Smrg	fi # $installed = yes
79817a3b38f7Smrg	func_stripname 'lib' '.la' "$laname"
79827a3b38f7Smrg	name=$func_stripname_result
79837a3b38f7Smrg
79847a3b38f7Smrg	# This library was specified with -dlpreopen.
79856fc0178dSmrg	if test dlpreopen = "$pass"; then
79866fc0178dSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
79876fc0178dSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
79887a3b38f7Smrg	  fi
79896fc0178dSmrg	  case $host in
7990862f5301Smrg	    # special handling for platforms with PE-DLLs.
7991862f5301Smrg	    *cygwin* | *mingw* | *cegcc* )
7992862f5301Smrg	      # Linker will automatically link against shared library if both
7993862f5301Smrg	      # static and shared are present.  Therefore, ensure we extract
7994862f5301Smrg	      # symbols from the import library if a shared library is present
7995862f5301Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
7996862f5301Smrg	      # this by putting the import library name into $newdlprefiles.
7997862f5301Smrg	      # We recover the dlopen module name by 'saving' the la file
7998862f5301Smrg	      # name in a special purpose variable, and (later) extracting the
7999862f5301Smrg	      # dlname from the la file.
8000862f5301Smrg	      if test -n "$dlname"; then
8001862f5301Smrg	        func_tr_sh "$dir/$linklib"
8002862f5301Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8003862f5301Smrg	        func_append newdlprefiles " $dir/$linklib"
8004862f5301Smrg	      else
8005862f5301Smrg	        func_append newdlprefiles " $dir/$old_library"
8006862f5301Smrg	        # Keep a list of preopened convenience libraries to check
8007862f5301Smrg	        # that they are being used correctly in the link pass.
8008862f5301Smrg	        test -z "$libdir" && \
8009862f5301Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8010862f5301Smrg	      fi
8011862f5301Smrg	    ;;
8012862f5301Smrg	    * )
8013862f5301Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8014862f5301Smrg	      # are required to link).
8015862f5301Smrg	      if test -n "$old_library"; then
8016862f5301Smrg	        func_append newdlprefiles " $dir/$old_library"
8017862f5301Smrg	        # Keep a list of preopened convenience libraries to check
8018862f5301Smrg	        # that they are being used correctly in the link pass.
8019862f5301Smrg	        test -z "$libdir" && \
8020862f5301Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8021862f5301Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8022862f5301Smrg	      elif test -n "$dlname"; then
8023862f5301Smrg	        func_append newdlprefiles " $dir/$dlname"
8024862f5301Smrg	      else
8025862f5301Smrg	        func_append newdlprefiles " $dir/$linklib"
8026862f5301Smrg	      fi
8027862f5301Smrg	    ;;
8028862f5301Smrg	  esac
80297a3b38f7Smrg	fi # $pass = dlpreopen
80307a3b38f7Smrg
80317a3b38f7Smrg	if test -z "$libdir"; then
80327a3b38f7Smrg	  # Link the convenience library
80336fc0178dSmrg	  if test lib = "$linkmode"; then
80347a3b38f7Smrg	    deplibs="$dir/$old_library $deplibs"
80356fc0178dSmrg	  elif test prog,link = "$linkmode,$pass"; then
80367a3b38f7Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
80377a3b38f7Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
80387a3b38f7Smrg	  else
80397a3b38f7Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
80407a3b38f7Smrg	  fi
80417a3b38f7Smrg	  continue
80427a3b38f7Smrg	fi
80437a3b38f7Smrg
80447a3b38f7Smrg
80456fc0178dSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8046862f5301Smrg	  func_append newlib_search_path " $ladir"
80477a3b38f7Smrg	  deplibs="$lib $deplibs"
80487a3b38f7Smrg
80496fc0178dSmrg	  linkalldeplibs=false
80506fc0178dSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
80516fc0178dSmrg	     test no = "$build_libtool_libs"; then
80526fc0178dSmrg	    linkalldeplibs=:
80537a3b38f7Smrg	  fi
80547a3b38f7Smrg
80557a3b38f7Smrg	  tmp_libs=
80567a3b38f7Smrg	  for deplib in $dependency_libs; do
80577a3b38f7Smrg	    case $deplib in
80587a3b38f7Smrg	    -L*) func_stripname '-L' '' "$deplib"
8059862f5301Smrg	         func_resolve_sysroot "$func_stripname_result"
8060862f5301Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
80617a3b38f7Smrg		 ;;
80627a3b38f7Smrg	    esac
80637a3b38f7Smrg	    # Need to link against all dependency_libs?
80646fc0178dSmrg	    if $linkalldeplibs; then
80657a3b38f7Smrg	      deplibs="$deplib $deplibs"
80667a3b38f7Smrg	    else
80677a3b38f7Smrg	      # Need to hardcode shared library paths
80687a3b38f7Smrg	      # or/and link against static libraries
80697a3b38f7Smrg	      newdependency_libs="$deplib $newdependency_libs"
80707a3b38f7Smrg	    fi
80716fc0178dSmrg	    if $opt_preserve_dup_deps; then
80727a3b38f7Smrg	      case "$tmp_libs " in
8073862f5301Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
80747a3b38f7Smrg	      esac
80757a3b38f7Smrg	    fi
8076862f5301Smrg	    func_append tmp_libs " $deplib"
80777a3b38f7Smrg	  done # for deplib
80787a3b38f7Smrg	  continue
80797a3b38f7Smrg	fi # $linkmode = prog...
80807a3b38f7Smrg
80816fc0178dSmrg	if test prog,link = "$linkmode,$pass"; then
80827a3b38f7Smrg	  if test -n "$library_names" &&
80836fc0178dSmrg	     { { test no = "$prefer_static_libs" ||
80846fc0178dSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
80857a3b38f7Smrg	       test -z "$old_library"; }; then
80867a3b38f7Smrg	    # We need to hardcode the library path
80876fc0178dSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
80887a3b38f7Smrg	      # Make sure the rpath contains only unique directories.
80896fc0178dSmrg	      case $temp_rpath: in
80907a3b38f7Smrg	      *"$absdir:"*) ;;
8091862f5301Smrg	      *) func_append temp_rpath "$absdir:" ;;
80927a3b38f7Smrg	      esac
80937a3b38f7Smrg	    fi
80947a3b38f7Smrg
80957a3b38f7Smrg	    # Hardcode the library path.
80967a3b38f7Smrg	    # Skip directories that are in the system default run-time
80977a3b38f7Smrg	    # search path.
80987a3b38f7Smrg	    case " $sys_lib_dlsearch_path " in
80997a3b38f7Smrg	    *" $absdir "*) ;;
81007a3b38f7Smrg	    *)
81017a3b38f7Smrg	      case "$compile_rpath " in
81027a3b38f7Smrg	      *" $absdir "*) ;;
8103862f5301Smrg	      *) func_append compile_rpath " $absdir" ;;
81047a3b38f7Smrg	      esac
81057a3b38f7Smrg	      ;;
81067a3b38f7Smrg	    esac
81077a3b38f7Smrg	    case " $sys_lib_dlsearch_path " in
81087a3b38f7Smrg	    *" $libdir "*) ;;
81097a3b38f7Smrg	    *)
81107a3b38f7Smrg	      case "$finalize_rpath " in
81117a3b38f7Smrg	      *" $libdir "*) ;;
8112862f5301Smrg	      *) func_append finalize_rpath " $libdir" ;;
81137a3b38f7Smrg	      esac
81147a3b38f7Smrg	      ;;
81157a3b38f7Smrg	    esac
81167a3b38f7Smrg	  fi # $linkmode,$pass = prog,link...
81177a3b38f7Smrg
81186fc0178dSmrg	  if $alldeplibs &&
81196fc0178dSmrg	     { test pass_all = "$deplibs_check_method" ||
81206fc0178dSmrg	       { test yes = "$build_libtool_libs" &&
81217a3b38f7Smrg		 test -n "$library_names"; }; }; then
81227a3b38f7Smrg	    # We only need to search for static libraries
81237a3b38f7Smrg	    continue
81247a3b38f7Smrg	  fi
81257a3b38f7Smrg	fi
81267a3b38f7Smrg
81277a3b38f7Smrg	link_static=no # Whether the deplib will be linked statically
81287a3b38f7Smrg	use_static_libs=$prefer_static_libs
81296fc0178dSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
81307a3b38f7Smrg	  use_static_libs=no
81317a3b38f7Smrg	fi
81327a3b38f7Smrg	if test -n "$library_names" &&
81336fc0178dSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
81347a3b38f7Smrg	  case $host in
81356fc0178dSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
81367a3b38f7Smrg	      # No point in relinking DLLs because paths are not encoded
8137862f5301Smrg	      func_append notinst_deplibs " $lib"
81387a3b38f7Smrg	      need_relink=no
81397a3b38f7Smrg	    ;;
81407a3b38f7Smrg	  *)
81416fc0178dSmrg	    if test no = "$installed"; then
8142862f5301Smrg	      func_append notinst_deplibs " $lib"
81437a3b38f7Smrg	      need_relink=yes
81447a3b38f7Smrg	    fi
81457a3b38f7Smrg	    ;;
81467a3b38f7Smrg	  esac
81477a3b38f7Smrg	  # This is a shared library
81487a3b38f7Smrg
81497a3b38f7Smrg	  # Warn about portability, can't link against -module's on some
81507a3b38f7Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
81516fc0178dSmrg	  dlopenmodule=
81527a3b38f7Smrg	  for dlpremoduletest in $dlprefiles; do
81537a3b38f7Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
81546fc0178dSmrg	      dlopenmodule=$dlpremoduletest
81557a3b38f7Smrg	      break
81567a3b38f7Smrg	    fi
81577a3b38f7Smrg	  done
81586fc0178dSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
815944dda7b2Smrg	    echo
81606fc0178dSmrg	    if test prog = "$linkmode"; then
81617a3b38f7Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
81627a3b38f7Smrg	    else
81637a3b38f7Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
81647a3b38f7Smrg	    fi
81657a3b38f7Smrg	    $ECHO "*** $linklib is not portable!"
81667a3b38f7Smrg	  fi
81676fc0178dSmrg	  if test lib = "$linkmode" &&
81686fc0178dSmrg	     test yes = "$hardcode_into_libs"; then
81697a3b38f7Smrg	    # Hardcode the library path.
81707a3b38f7Smrg	    # Skip directories that are in the system default run-time
81717a3b38f7Smrg	    # search path.
81727a3b38f7Smrg	    case " $sys_lib_dlsearch_path " in
81737a3b38f7Smrg	    *" $absdir "*) ;;
81747a3b38f7Smrg	    *)
81757a3b38f7Smrg	      case "$compile_rpath " in
81767a3b38f7Smrg	      *" $absdir "*) ;;
8177862f5301Smrg	      *) func_append compile_rpath " $absdir" ;;
81787a3b38f7Smrg	      esac
81797a3b38f7Smrg	      ;;
81807a3b38f7Smrg	    esac
81817a3b38f7Smrg	    case " $sys_lib_dlsearch_path " in
81827a3b38f7Smrg	    *" $libdir "*) ;;
81837a3b38f7Smrg	    *)
81847a3b38f7Smrg	      case "$finalize_rpath " in
81857a3b38f7Smrg	      *" $libdir "*) ;;
8186862f5301Smrg	      *) func_append finalize_rpath " $libdir" ;;
81877a3b38f7Smrg	      esac
81887a3b38f7Smrg	      ;;
81897a3b38f7Smrg	    esac
81907a3b38f7Smrg	  fi
81917a3b38f7Smrg
81927a3b38f7Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
81937a3b38f7Smrg	    # figure out the soname
81947a3b38f7Smrg	    set dummy $library_names
81957a3b38f7Smrg	    shift
81966fc0178dSmrg	    realname=$1
81977a3b38f7Smrg	    shift
81987a3b38f7Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
81997a3b38f7Smrg	    # use dlname if we got it. it's perfectly good, no?
82007a3b38f7Smrg	    if test -n "$dlname"; then
82016fc0178dSmrg	      soname=$dlname
82027a3b38f7Smrg	    elif test -n "$soname_spec"; then
82037a3b38f7Smrg	      # bleh windows
82047a3b38f7Smrg	      case $host in
82056fc0178dSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
82067a3b38f7Smrg	        func_arith $current - $age
82077a3b38f7Smrg		major=$func_arith_result
82086fc0178dSmrg		versuffix=-$major
82097a3b38f7Smrg		;;
82107a3b38f7Smrg	      esac
82117a3b38f7Smrg	      eval soname=\"$soname_spec\"
82127a3b38f7Smrg	    else
82136fc0178dSmrg	      soname=$realname
82147a3b38f7Smrg	    fi
82157a3b38f7Smrg
82167a3b38f7Smrg	    # Make a new name for the extract_expsyms_cmds to use
82176fc0178dSmrg	    soroot=$soname
82187a3b38f7Smrg	    func_basename "$soroot"
82196fc0178dSmrg	    soname=$func_basename_result
82207a3b38f7Smrg	    func_stripname 'lib' '.dll' "$soname"
82217a3b38f7Smrg	    newlib=libimp-$func_stripname_result.a
82227a3b38f7Smrg
82237a3b38f7Smrg	    # If the library has no export list, then create one now
82247a3b38f7Smrg	    if test -f "$output_objdir/$soname-def"; then :
82257a3b38f7Smrg	    else
82266fc0178dSmrg	      func_verbose "extracting exported symbol list from '$soname'"
82277a3b38f7Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
82287a3b38f7Smrg	    fi
82297a3b38f7Smrg
82307a3b38f7Smrg	    # Create $newlib
82317a3b38f7Smrg	    if test -f "$output_objdir/$newlib"; then :; else
82326fc0178dSmrg	      func_verbose "generating import library for '$soname'"
82337a3b38f7Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
82347a3b38f7Smrg	    fi
82357a3b38f7Smrg	    # make sure the library variables are pointing to the new library
82367a3b38f7Smrg	    dir=$output_objdir
82377a3b38f7Smrg	    linklib=$newlib
82387a3b38f7Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
82397a3b38f7Smrg
82406fc0178dSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
82417a3b38f7Smrg	    add_shlibpath=
82427a3b38f7Smrg	    add_dir=
82437a3b38f7Smrg	    add=
82447a3b38f7Smrg	    lib_linked=yes
82457a3b38f7Smrg	    case $hardcode_action in
82467a3b38f7Smrg	    immediate | unsupported)
82476fc0178dSmrg	      if test no = "$hardcode_direct"; then
82486fc0178dSmrg		add=$dir/$linklib
82497a3b38f7Smrg		case $host in
82506fc0178dSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
82516fc0178dSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
82527a3b38f7Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
82536fc0178dSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
82547a3b38f7Smrg		  *-*-darwin* )
82556fc0178dSmrg		    # if the lib is a (non-dlopened) module then we cannot
82567a3b38f7Smrg		    # link against it, someone is ignoring the earlier warnings
82577a3b38f7Smrg		    if /usr/bin/file -L $add 2> /dev/null |
82586fc0178dSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
82597a3b38f7Smrg		      if test "X$dlopenmodule" != "X$lib"; then
82607a3b38f7Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
82616fc0178dSmrg			if test -z "$old_library"; then
826244dda7b2Smrg			  echo
826344dda7b2Smrg			  echo "*** And there doesn't seem to be a static archive available"
826444dda7b2Smrg			  echo "*** The link will probably fail, sorry"
82657a3b38f7Smrg			else
82666fc0178dSmrg			  add=$dir/$old_library
82677a3b38f7Smrg			fi
82687a3b38f7Smrg		      elif test -n "$old_library"; then
82696fc0178dSmrg			add=$dir/$old_library
82707a3b38f7Smrg		      fi
82717a3b38f7Smrg		    fi
82727a3b38f7Smrg		esac
82736fc0178dSmrg	      elif test no = "$hardcode_minus_L"; then
82747a3b38f7Smrg		case $host in
82756fc0178dSmrg		*-*-sunos*) add_shlibpath=$dir ;;
82767a3b38f7Smrg		esac
82776fc0178dSmrg		add_dir=-L$dir
82786fc0178dSmrg		add=-l$name
82796fc0178dSmrg	      elif test no = "$hardcode_shlibpath_var"; then
82806fc0178dSmrg		add_shlibpath=$dir
82816fc0178dSmrg		add=-l$name
82827a3b38f7Smrg	      else
82837a3b38f7Smrg		lib_linked=no
82847a3b38f7Smrg	      fi
82857a3b38f7Smrg	      ;;
82867a3b38f7Smrg	    relink)
82876fc0178dSmrg	      if test yes = "$hardcode_direct" &&
82886fc0178dSmrg	         test no = "$hardcode_direct_absolute"; then
82896fc0178dSmrg		add=$dir/$linklib
82906fc0178dSmrg	      elif test yes = "$hardcode_minus_L"; then
82916fc0178dSmrg		add_dir=-L$absdir
82927a3b38f7Smrg		# Try looking first in the location we're being installed to.
82937a3b38f7Smrg		if test -n "$inst_prefix_dir"; then
82947a3b38f7Smrg		  case $libdir in
82957a3b38f7Smrg		    [\\/]*)
8296862f5301Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
82977a3b38f7Smrg		      ;;
82987a3b38f7Smrg		  esac
82997a3b38f7Smrg		fi
83006fc0178dSmrg		add=-l$name
83016fc0178dSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
83026fc0178dSmrg		add_shlibpath=$dir
83036fc0178dSmrg		add=-l$name
83047a3b38f7Smrg	      else
83057a3b38f7Smrg		lib_linked=no
83067a3b38f7Smrg	      fi
83077a3b38f7Smrg	      ;;
83087a3b38f7Smrg	    *) lib_linked=no ;;
83097a3b38f7Smrg	    esac
83107a3b38f7Smrg
83116fc0178dSmrg	    if test yes != "$lib_linked"; then
83127a3b38f7Smrg	      func_fatal_configuration "unsupported hardcode properties"
83137a3b38f7Smrg	    fi
83147a3b38f7Smrg
83157a3b38f7Smrg	    if test -n "$add_shlibpath"; then
83167a3b38f7Smrg	      case :$compile_shlibpath: in
83177a3b38f7Smrg	      *":$add_shlibpath:"*) ;;
8318862f5301Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
83197a3b38f7Smrg	      esac
83207a3b38f7Smrg	    fi
83216fc0178dSmrg	    if test prog = "$linkmode"; then
83227a3b38f7Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
83237a3b38f7Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
83247a3b38f7Smrg	    else
83257a3b38f7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
83267a3b38f7Smrg	      test -n "$add" && deplibs="$add $deplibs"
83276fc0178dSmrg	      if test yes != "$hardcode_direct" &&
83286fc0178dSmrg		 test yes != "$hardcode_minus_L" &&
83296fc0178dSmrg		 test yes = "$hardcode_shlibpath_var"; then
83307a3b38f7Smrg		case :$finalize_shlibpath: in
83317a3b38f7Smrg		*":$libdir:"*) ;;
8332862f5301Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
83337a3b38f7Smrg		esac
83347a3b38f7Smrg	      fi
83357a3b38f7Smrg	    fi
83367a3b38f7Smrg	  fi
83377a3b38f7Smrg
83386fc0178dSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
83397a3b38f7Smrg	    add_shlibpath=
83407a3b38f7Smrg	    add_dir=
83417a3b38f7Smrg	    add=
83427a3b38f7Smrg	    # Finalize command for both is simple: just hardcode it.
83436fc0178dSmrg	    if test yes = "$hardcode_direct" &&
83446fc0178dSmrg	       test no = "$hardcode_direct_absolute"; then
83456fc0178dSmrg	      add=$libdir/$linklib
83466fc0178dSmrg	    elif test yes = "$hardcode_minus_L"; then
83476fc0178dSmrg	      add_dir=-L$libdir
83486fc0178dSmrg	      add=-l$name
83496fc0178dSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
83507a3b38f7Smrg	      case :$finalize_shlibpath: in
83517a3b38f7Smrg	      *":$libdir:"*) ;;
8352862f5301Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
83537a3b38f7Smrg	      esac
83546fc0178dSmrg	      add=-l$name
83556fc0178dSmrg	    elif test yes = "$hardcode_automatic"; then
83567a3b38f7Smrg	      if test -n "$inst_prefix_dir" &&
83576fc0178dSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
83586fc0178dSmrg		add=$inst_prefix_dir$libdir/$linklib
83597a3b38f7Smrg	      else
83606fc0178dSmrg		add=$libdir/$linklib
83617a3b38f7Smrg	      fi
83627a3b38f7Smrg	    else
83637a3b38f7Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
83646fc0178dSmrg	      add_dir=-L$libdir
83657a3b38f7Smrg	      # Try looking first in the location we're being installed to.
83667a3b38f7Smrg	      if test -n "$inst_prefix_dir"; then
83677a3b38f7Smrg		case $libdir in
83687a3b38f7Smrg		  [\\/]*)
8369862f5301Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
83707a3b38f7Smrg		    ;;
83717a3b38f7Smrg		esac
83727a3b38f7Smrg	      fi
83736fc0178dSmrg	      add=-l$name
83747a3b38f7Smrg	    fi
83757a3b38f7Smrg
83766fc0178dSmrg	    if test prog = "$linkmode"; then
83777a3b38f7Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
83787a3b38f7Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
83797a3b38f7Smrg	    else
83807a3b38f7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
83817a3b38f7Smrg	      test -n "$add" && deplibs="$add $deplibs"
83827a3b38f7Smrg	    fi
83837a3b38f7Smrg	  fi
83846fc0178dSmrg	elif test prog = "$linkmode"; then
83857a3b38f7Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
83867a3b38f7Smrg	  # is not unsupported.  This is valid on all known static and
83877a3b38f7Smrg	  # shared platforms.
83886fc0178dSmrg	  if test unsupported != "$hardcode_direct"; then
83896fc0178dSmrg	    test -n "$old_library" && linklib=$old_library
83907a3b38f7Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
83917a3b38f7Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
83927a3b38f7Smrg	  else
83937a3b38f7Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
83947a3b38f7Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
83957a3b38f7Smrg	  fi
83966fc0178dSmrg	elif test yes = "$build_libtool_libs"; then
83977a3b38f7Smrg	  # Not a shared library
83986fc0178dSmrg	  if test pass_all != "$deplibs_check_method"; then
83997a3b38f7Smrg	    # We're trying link a shared library against a static one
84007a3b38f7Smrg	    # but the system doesn't support it.
84017a3b38f7Smrg
84027a3b38f7Smrg	    # Just print a warning and add the library to dependency_libs so
84037a3b38f7Smrg	    # that the program can be linked against the static library.
840444dda7b2Smrg	    echo
84056fc0178dSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
840644dda7b2Smrg	    echo "*** I have the capability to make that library automatically link in when"
840744dda7b2Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
840844dda7b2Smrg	    echo "*** shared version of the library, which you do not appear to have."
84096fc0178dSmrg	    if test yes = "$module"; then
841044dda7b2Smrg	      echo "*** But as you try to build a module library, libtool will still create "
841144dda7b2Smrg	      echo "*** a static module, that should work as long as the dlopening application"
841244dda7b2Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
84137a3b38f7Smrg	      if test -z "$global_symbol_pipe"; then
841444dda7b2Smrg		echo
841544dda7b2Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
84166fc0178dSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
841744dda7b2Smrg		echo "*** not find such a program.  So, this module is probably useless."
84186fc0178dSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
84197a3b38f7Smrg	      fi
84206fc0178dSmrg	      if test no = "$build_old_libs"; then
84217a3b38f7Smrg		build_libtool_libs=module
84227a3b38f7Smrg		build_old_libs=yes
84237a3b38f7Smrg	      else
84247a3b38f7Smrg		build_libtool_libs=no
84257a3b38f7Smrg	      fi
84267a3b38f7Smrg	    fi
84277a3b38f7Smrg	  else
84287a3b38f7Smrg	    deplibs="$dir/$old_library $deplibs"
84297a3b38f7Smrg	    link_static=yes
84307a3b38f7Smrg	  fi
84317a3b38f7Smrg	fi # link shared/static library?
84327a3b38f7Smrg
84336fc0178dSmrg	if test lib = "$linkmode"; then
84347a3b38f7Smrg	  if test -n "$dependency_libs" &&
84356fc0178dSmrg	     { test yes != "$hardcode_into_libs" ||
84366fc0178dSmrg	       test yes = "$build_old_libs" ||
84376fc0178dSmrg	       test yes = "$link_static"; }; then
84387a3b38f7Smrg	    # Extract -R from dependency_libs
84397a3b38f7Smrg	    temp_deplibs=
84407a3b38f7Smrg	    for libdir in $dependency_libs; do
84417a3b38f7Smrg	      case $libdir in
84427a3b38f7Smrg	      -R*) func_stripname '-R' '' "$libdir"
84437a3b38f7Smrg	           temp_xrpath=$func_stripname_result
84447a3b38f7Smrg		   case " $xrpath " in
84457a3b38f7Smrg		   *" $temp_xrpath "*) ;;
8446862f5301Smrg		   *) func_append xrpath " $temp_xrpath";;
84477a3b38f7Smrg		   esac;;
8448862f5301Smrg	      *) func_append temp_deplibs " $libdir";;
84497a3b38f7Smrg	      esac
84507a3b38f7Smrg	    done
84516fc0178dSmrg	    dependency_libs=$temp_deplibs
84527a3b38f7Smrg	  fi
84537a3b38f7Smrg
8454862f5301Smrg	  func_append newlib_search_path " $absdir"
84557a3b38f7Smrg	  # Link against this library
84566fc0178dSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
84577a3b38f7Smrg	  # ... and its dependency_libs
84587a3b38f7Smrg	  tmp_libs=
84597a3b38f7Smrg	  for deplib in $dependency_libs; do
84607a3b38f7Smrg	    newdependency_libs="$deplib $newdependency_libs"
8461862f5301Smrg	    case $deplib in
8462862f5301Smrg              -L*) func_stripname '-L' '' "$deplib"
8463862f5301Smrg                   func_resolve_sysroot "$func_stripname_result";;
8464862f5301Smrg              *) func_resolve_sysroot "$deplib" ;;
8465862f5301Smrg            esac
84666fc0178dSmrg	    if $opt_preserve_dup_deps; then
84677a3b38f7Smrg	      case "$tmp_libs " in
8468862f5301Smrg	      *" $func_resolve_sysroot_result "*)
8469862f5301Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
84707a3b38f7Smrg	      esac
84717a3b38f7Smrg	    fi
8472862f5301Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
84737a3b38f7Smrg	  done
84747a3b38f7Smrg
84756fc0178dSmrg	  if test no != "$link_all_deplibs"; then
84767a3b38f7Smrg	    # Add the search paths of all dependency libraries
84777a3b38f7Smrg	    for deplib in $dependency_libs; do
847844dda7b2Smrg	      path=
84797a3b38f7Smrg	      case $deplib in
84806fc0178dSmrg	      -L*) path=$deplib ;;
84817a3b38f7Smrg	      *.la)
8482862f5301Smrg	        func_resolve_sysroot "$deplib"
8483862f5301Smrg	        deplib=$func_resolve_sysroot_result
84847a3b38f7Smrg	        func_dirname "$deplib" "" "."
8485862f5301Smrg		dir=$func_dirname_result
84867a3b38f7Smrg		# We need an absolute path.
84877a3b38f7Smrg		case $dir in
84886fc0178dSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
84897a3b38f7Smrg		*)
84907a3b38f7Smrg		  absdir=`cd "$dir" && pwd`
84917a3b38f7Smrg		  if test -z "$absdir"; then
84926fc0178dSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
84936fc0178dSmrg		    absdir=$dir
84947a3b38f7Smrg		  fi
84957a3b38f7Smrg		  ;;
84967a3b38f7Smrg		esac
84977a3b38f7Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
84987a3b38f7Smrg		case $host in
84997a3b38f7Smrg		*-*-darwin*)
85007a3b38f7Smrg		  depdepl=
85016fc0178dSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
85026fc0178dSmrg		  if test -n "$deplibrary_names"; then
85036fc0178dSmrg		    for tmp in $deplibrary_names; do
85047a3b38f7Smrg		      depdepl=$tmp
85057a3b38f7Smrg		    done
85066fc0178dSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
85076fc0178dSmrg		      depdepl=$absdir/$objdir/$depdepl
85086fc0178dSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
85097a3b38f7Smrg                      if test -z "$darwin_install_name"; then
85106fc0178dSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
85117a3b38f7Smrg                      fi
85126fc0178dSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
85136fc0178dSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
85147a3b38f7Smrg		      path=
85157a3b38f7Smrg		    fi
85167a3b38f7Smrg		  fi
85177a3b38f7Smrg		  ;;
85187a3b38f7Smrg		*)
85196fc0178dSmrg		  path=-L$absdir/$objdir
85207a3b38f7Smrg		  ;;
85217a3b38f7Smrg		esac
85227a3b38f7Smrg		else
85236fc0178dSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
85247a3b38f7Smrg		  test -z "$libdir" && \
85256fc0178dSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
85267a3b38f7Smrg		  test "$absdir" != "$libdir" && \
85276fc0178dSmrg		    func_warning "'$deplib' seems to be moved"
85287a3b38f7Smrg
85296fc0178dSmrg		  path=-L$absdir
85307a3b38f7Smrg		fi
85317a3b38f7Smrg		;;
85327a3b38f7Smrg	      esac
85337a3b38f7Smrg	      case " $deplibs " in
85347a3b38f7Smrg	      *" $path "*) ;;
85357a3b38f7Smrg	      *) deplibs="$path $deplibs" ;;
85367a3b38f7Smrg	      esac
85377a3b38f7Smrg	    done
85387a3b38f7Smrg	  fi # link_all_deplibs != no
85397a3b38f7Smrg	fi # linkmode = lib
85407a3b38f7Smrg      done # for deplib in $libs
85416fc0178dSmrg      if test link = "$pass"; then
85426fc0178dSmrg	if test prog = "$linkmode"; then
85437a3b38f7Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
85447a3b38f7Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
85457a3b38f7Smrg	else
854644dda7b2Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
85477a3b38f7Smrg	fi
85487a3b38f7Smrg      fi
85496fc0178dSmrg      dependency_libs=$newdependency_libs
85506fc0178dSmrg      if test dlpreopen = "$pass"; then
85517a3b38f7Smrg	# Link the dlpreopened libraries before other libraries
85527a3b38f7Smrg	for deplib in $save_deplibs; do
85537a3b38f7Smrg	  deplibs="$deplib $deplibs"
85547a3b38f7Smrg	done
85557a3b38f7Smrg      fi
85566fc0178dSmrg      if test dlopen != "$pass"; then
85576fc0178dSmrg	test conv = "$pass" || {
85587a3b38f7Smrg	  # Make sure lib_search_path contains only unique directories.
85597a3b38f7Smrg	  lib_search_path=
85607a3b38f7Smrg	  for dir in $newlib_search_path; do
85617a3b38f7Smrg	    case "$lib_search_path " in
85627a3b38f7Smrg	    *" $dir "*) ;;
8563862f5301Smrg	    *) func_append lib_search_path " $dir" ;;
85647a3b38f7Smrg	    esac
85657a3b38f7Smrg	  done
85667a3b38f7Smrg	  newlib_search_path=
85676fc0178dSmrg	}
85687a3b38f7Smrg
85696fc0178dSmrg	if test prog,link = "$linkmode,$pass"; then
85707a3b38f7Smrg	  vars="compile_deplibs finalize_deplibs"
85716fc0178dSmrg	else
85726fc0178dSmrg	  vars=deplibs
85737a3b38f7Smrg	fi
85747a3b38f7Smrg	for var in $vars dependency_libs; do
85757a3b38f7Smrg	  # Add libraries to $var in reverse order
85767a3b38f7Smrg	  eval tmp_libs=\"\$$var\"
85777a3b38f7Smrg	  new_libs=
85787a3b38f7Smrg	  for deplib in $tmp_libs; do
85797a3b38f7Smrg	    # FIXME: Pedantically, this is the right thing to do, so
85807a3b38f7Smrg	    #        that some nasty dependency loop isn't accidentally
85817a3b38f7Smrg	    #        broken:
85827a3b38f7Smrg	    #new_libs="$deplib $new_libs"
85837a3b38f7Smrg	    # Pragmatically, this seems to cause very few problems in
85847a3b38f7Smrg	    # practice:
85857a3b38f7Smrg	    case $deplib in
85867a3b38f7Smrg	    -L*) new_libs="$deplib $new_libs" ;;
85877a3b38f7Smrg	    -R*) ;;
85887a3b38f7Smrg	    *)
85897a3b38f7Smrg	      # And here is the reason: when a library appears more
85907a3b38f7Smrg	      # than once as an explicit dependence of a library, or
85917a3b38f7Smrg	      # is implicitly linked in more than once by the
85927a3b38f7Smrg	      # compiler, it is considered special, and multiple
85937a3b38f7Smrg	      # occurrences thereof are not removed.  Compare this
85947a3b38f7Smrg	      # with having the same library being listed as a
85957a3b38f7Smrg	      # dependency of multiple other libraries: in this case,
85967a3b38f7Smrg	      # we know (pedantically, we assume) the library does not
85977a3b38f7Smrg	      # need to be listed more than once, so we keep only the
85987a3b38f7Smrg	      # last copy.  This is not always right, but it is rare
85997a3b38f7Smrg	      # enough that we require users that really mean to play
86007a3b38f7Smrg	      # such unportable linking tricks to link the library
86017a3b38f7Smrg	      # using -Wl,-lname, so that libtool does not consider it
86027a3b38f7Smrg	      # for duplicate removal.
86037a3b38f7Smrg	      case " $specialdeplibs " in
86047a3b38f7Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
86057a3b38f7Smrg	      *)
86067a3b38f7Smrg		case " $new_libs " in
86077a3b38f7Smrg		*" $deplib "*) ;;
86087a3b38f7Smrg		*) new_libs="$deplib $new_libs" ;;
86097a3b38f7Smrg		esac
86107a3b38f7Smrg		;;
86117a3b38f7Smrg	      esac
86127a3b38f7Smrg	      ;;
86137a3b38f7Smrg	    esac
86147a3b38f7Smrg	  done
86157a3b38f7Smrg	  tmp_libs=
86167a3b38f7Smrg	  for deplib in $new_libs; do
86177a3b38f7Smrg	    case $deplib in
86187a3b38f7Smrg	    -L*)
86197a3b38f7Smrg	      case " $tmp_libs " in
86207a3b38f7Smrg	      *" $deplib "*) ;;
8621862f5301Smrg	      *) func_append tmp_libs " $deplib" ;;
86227a3b38f7Smrg	      esac
86237a3b38f7Smrg	      ;;
8624862f5301Smrg	    *) func_append tmp_libs " $deplib" ;;
86257a3b38f7Smrg	    esac
86267a3b38f7Smrg	  done
86277a3b38f7Smrg	  eval $var=\"$tmp_libs\"
86287a3b38f7Smrg	done # for var
86297a3b38f7Smrg      fi
86306fc0178dSmrg
86316fc0178dSmrg      # Add Sun CC postdeps if required:
86326fc0178dSmrg      test CXX = "$tagname" && {
86336fc0178dSmrg        case $host_os in
86346fc0178dSmrg        linux*)
86356fc0178dSmrg          case `$CC -V 2>&1 | sed 5q` in
86366fc0178dSmrg          *Sun\ C*) # Sun C++ 5.9
86376fc0178dSmrg            func_suncc_cstd_abi
86386fc0178dSmrg
86396fc0178dSmrg            if test no != "$suncc_use_cstd_abi"; then
86406fc0178dSmrg              func_append postdeps ' -library=Cstd -library=Crun'
86416fc0178dSmrg            fi
86426fc0178dSmrg            ;;
86436fc0178dSmrg          esac
86446fc0178dSmrg          ;;
86456fc0178dSmrg
86466fc0178dSmrg        solaris*)
86476fc0178dSmrg          func_cc_basename "$CC"
86486fc0178dSmrg          case $func_cc_basename_result in
86496fc0178dSmrg          CC* | sunCC*)
86506fc0178dSmrg            func_suncc_cstd_abi
86516fc0178dSmrg
86526fc0178dSmrg            if test no != "$suncc_use_cstd_abi"; then
86536fc0178dSmrg              func_append postdeps ' -library=Cstd -library=Crun'
86546fc0178dSmrg            fi
86556fc0178dSmrg            ;;
86566fc0178dSmrg          esac
86576fc0178dSmrg          ;;
86586fc0178dSmrg        esac
86596fc0178dSmrg      }
86606fc0178dSmrg
86617a3b38f7Smrg      # Last step: remove runtime libs from dependency_libs
86627a3b38f7Smrg      # (they stay in deplibs)
86637a3b38f7Smrg      tmp_libs=
86646fc0178dSmrg      for i in $dependency_libs; do
86657a3b38f7Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
86667a3b38f7Smrg	*" $i "*)
86676fc0178dSmrg	  i=
86687a3b38f7Smrg	  ;;
86697a3b38f7Smrg	esac
86706fc0178dSmrg	if test -n "$i"; then
8671862f5301Smrg	  func_append tmp_libs " $i"
86727a3b38f7Smrg	fi
86737a3b38f7Smrg      done
86747a3b38f7Smrg      dependency_libs=$tmp_libs
86757a3b38f7Smrg    done # for pass
86766fc0178dSmrg    if test prog = "$linkmode"; then
86776fc0178dSmrg      dlfiles=$newdlfiles
86787a3b38f7Smrg    fi
86796fc0178dSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
86806fc0178dSmrg      dlprefiles=$newdlprefiles
86817a3b38f7Smrg    fi
86827a3b38f7Smrg
86837a3b38f7Smrg    case $linkmode in
86847a3b38f7Smrg    oldlib)
86856fc0178dSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
86866fc0178dSmrg	func_warning "'-dlopen' is ignored for archives"
86877a3b38f7Smrg      fi
86887a3b38f7Smrg
86897a3b38f7Smrg      case " $deplibs" in
86907a3b38f7Smrg      *\ -l* | *\ -L*)
86916fc0178dSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
86927a3b38f7Smrg      esac
86937a3b38f7Smrg
86947a3b38f7Smrg      test -n "$rpath" && \
86956fc0178dSmrg	func_warning "'-rpath' is ignored for archives"
86967a3b38f7Smrg
86977a3b38f7Smrg      test -n "$xrpath" && \
86986fc0178dSmrg	func_warning "'-R' is ignored for archives"
86997a3b38f7Smrg
87007a3b38f7Smrg      test -n "$vinfo" && \
87016fc0178dSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
87027a3b38f7Smrg
87037a3b38f7Smrg      test -n "$release" && \
87046fc0178dSmrg	func_warning "'-release' is ignored for archives"
87057a3b38f7Smrg
87067a3b38f7Smrg      test -n "$export_symbols$export_symbols_regex" && \
87076fc0178dSmrg	func_warning "'-export-symbols' is ignored for archives"
87087a3b38f7Smrg
87097a3b38f7Smrg      # Now set the variables for building old libraries.
87107a3b38f7Smrg      build_libtool_libs=no
87116fc0178dSmrg      oldlibs=$output
8712862f5301Smrg      func_append objs "$old_deplibs"
87137a3b38f7Smrg      ;;
87147a3b38f7Smrg
87157a3b38f7Smrg    lib)
87166fc0178dSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
87177a3b38f7Smrg      case $outputname in
87187a3b38f7Smrg      lib*)
87197a3b38f7Smrg	func_stripname 'lib' '.la' "$outputname"
87207a3b38f7Smrg	name=$func_stripname_result
87217a3b38f7Smrg	eval shared_ext=\"$shrext_cmds\"
87227a3b38f7Smrg	eval libname=\"$libname_spec\"
87237a3b38f7Smrg	;;
87247a3b38f7Smrg      *)
87256fc0178dSmrg	test no = "$module" \
87266fc0178dSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
87277a3b38f7Smrg
87286fc0178dSmrg	if test no != "$need_lib_prefix"; then
87297a3b38f7Smrg	  # Add the "lib" prefix for modules if required
87307a3b38f7Smrg	  func_stripname '' '.la' "$outputname"
87317a3b38f7Smrg	  name=$func_stripname_result
87327a3b38f7Smrg	  eval shared_ext=\"$shrext_cmds\"
87337a3b38f7Smrg	  eval libname=\"$libname_spec\"
87347a3b38f7Smrg	else
87357a3b38f7Smrg	  func_stripname '' '.la' "$outputname"
87367a3b38f7Smrg	  libname=$func_stripname_result
87377a3b38f7Smrg	fi
87387a3b38f7Smrg	;;
87397a3b38f7Smrg      esac
87407a3b38f7Smrg
87417a3b38f7Smrg      if test -n "$objs"; then
87426fc0178dSmrg	if test pass_all != "$deplibs_check_method"; then
87436fc0178dSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
87447a3b38f7Smrg	else
874544dda7b2Smrg	  echo
87467a3b38f7Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
87477a3b38f7Smrg	  $ECHO "*** objects $objs is not portable!"
8748862f5301Smrg	  func_append libobjs " $objs"
87497a3b38f7Smrg	fi
87507a3b38f7Smrg      fi
87517a3b38f7Smrg
87526fc0178dSmrg      test no = "$dlself" \
87536fc0178dSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
87547a3b38f7Smrg
87557a3b38f7Smrg      set dummy $rpath
87567a3b38f7Smrg      shift
87576fc0178dSmrg      test 1 -lt "$#" \
87586fc0178dSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
87597a3b38f7Smrg
87606fc0178dSmrg      install_libdir=$1
87617a3b38f7Smrg
87627a3b38f7Smrg      oldlibs=
87637a3b38f7Smrg      if test -z "$rpath"; then
87646fc0178dSmrg	if test yes = "$build_libtool_libs"; then
87657a3b38f7Smrg	  # Building a libtool convenience library.
87666fc0178dSmrg	  # Some compilers have problems with a '.al' extension so
87677a3b38f7Smrg	  # convenience libraries should have the same extension an
87687a3b38f7Smrg	  # archive normally would.
87697a3b38f7Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
87707a3b38f7Smrg	  build_libtool_libs=convenience
87717a3b38f7Smrg	  build_old_libs=yes
87727a3b38f7Smrg	fi
87737a3b38f7Smrg
87747a3b38f7Smrg	test -n "$vinfo" && \
87756fc0178dSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
87767a3b38f7Smrg
87777a3b38f7Smrg	test -n "$release" && \
87786fc0178dSmrg	  func_warning "'-release' is ignored for convenience libraries"
87797a3b38f7Smrg      else
87807a3b38f7Smrg
87817a3b38f7Smrg	# Parse the version information argument.
87826fc0178dSmrg	save_ifs=$IFS; IFS=:
87837a3b38f7Smrg	set dummy $vinfo 0 0 0
87847a3b38f7Smrg	shift
87856fc0178dSmrg	IFS=$save_ifs
87867a3b38f7Smrg
87877a3b38f7Smrg	test -n "$7" && \
87886fc0178dSmrg	  func_fatal_help "too many parameters to '-version-info'"
87897a3b38f7Smrg
87907a3b38f7Smrg	# convert absolute version numbers to libtool ages
87917a3b38f7Smrg	# this retains compatibility with .la files and attempts
87927a3b38f7Smrg	# to make the code below a bit more comprehensible
87937a3b38f7Smrg
87947a3b38f7Smrg	case $vinfo_number in
87957a3b38f7Smrg	yes)
87966fc0178dSmrg	  number_major=$1
87976fc0178dSmrg	  number_minor=$2
87986fc0178dSmrg	  number_revision=$3
87997a3b38f7Smrg	  #
88007a3b38f7Smrg	  # There are really only two kinds -- those that
88017a3b38f7Smrg	  # use the current revision as the major version
88027a3b38f7Smrg	  # and those that subtract age and use age as
88037a3b38f7Smrg	  # a minor version.  But, then there is irix
88046fc0178dSmrg	  # that has an extra 1 added just for fun
88057a3b38f7Smrg	  #
88067a3b38f7Smrg	  case $version_type in
8807fc544a13Smrg	  # correct linux to gnu/linux during the next big refactor
88086fc0178dSmrg	  darwin|freebsd-elf|linux|osf|windows|none)
88097a3b38f7Smrg	    func_arith $number_major + $number_minor
88107a3b38f7Smrg	    current=$func_arith_result
88116fc0178dSmrg	    age=$number_minor
88126fc0178dSmrg	    revision=$number_revision
88137a3b38f7Smrg	    ;;
88146fc0178dSmrg	  freebsd-aout|qnx|sunos)
88156fc0178dSmrg	    current=$number_major
88166fc0178dSmrg	    revision=$number_minor
88176fc0178dSmrg	    age=0
88187a3b38f7Smrg	    ;;
88197a3b38f7Smrg	  irix|nonstopux)
88207a3b38f7Smrg	    func_arith $number_major + $number_minor
88217a3b38f7Smrg	    current=$func_arith_result
88226fc0178dSmrg	    age=$number_minor
88236fc0178dSmrg	    revision=$number_minor
88247a3b38f7Smrg	    lt_irix_increment=no
88257a3b38f7Smrg	    ;;
88267a3b38f7Smrg	  esac
88277a3b38f7Smrg	  ;;
88287a3b38f7Smrg	no)
88296fc0178dSmrg	  current=$1
88306fc0178dSmrg	  revision=$2
88316fc0178dSmrg	  age=$3
88327a3b38f7Smrg	  ;;
88337a3b38f7Smrg	esac
88347a3b38f7Smrg
88357a3b38f7Smrg	# Check that each of the things are valid numbers.
88367a3b38f7Smrg	case $current in
88377a3b38f7Smrg	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]) ;;
88387a3b38f7Smrg	*)
88396fc0178dSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
88406fc0178dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
88417a3b38f7Smrg	  ;;
88427a3b38f7Smrg	esac
88437a3b38f7Smrg
88447a3b38f7Smrg	case $revision in
88457a3b38f7Smrg	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]) ;;
88467a3b38f7Smrg	*)
88476fc0178dSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
88486fc0178dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
88497a3b38f7Smrg	  ;;
88507a3b38f7Smrg	esac
88517a3b38f7Smrg
88527a3b38f7Smrg	case $age in
88537a3b38f7Smrg	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]) ;;
88547a3b38f7Smrg	*)
88556fc0178dSmrg	  func_error "AGE '$age' must be a nonnegative integer"
88566fc0178dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
88577a3b38f7Smrg	  ;;
88587a3b38f7Smrg	esac
88597a3b38f7Smrg
88607a3b38f7Smrg	if test "$age" -gt "$current"; then
88616fc0178dSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
88626fc0178dSmrg	  func_fatal_error "'$vinfo' is not valid version information"
88637a3b38f7Smrg	fi
88647a3b38f7Smrg
88657a3b38f7Smrg	# Calculate the version variables.
88667a3b38f7Smrg	major=
88677a3b38f7Smrg	versuffix=
88687a3b38f7Smrg	verstring=
88697a3b38f7Smrg	case $version_type in
88707a3b38f7Smrg	none) ;;
88717a3b38f7Smrg
88727a3b38f7Smrg	darwin)
88737a3b38f7Smrg	  # Like Linux, but with the current version available in
88747a3b38f7Smrg	  # verstring for coding it into the library header
88757a3b38f7Smrg	  func_arith $current - $age
88767a3b38f7Smrg	  major=.$func_arith_result
88776fc0178dSmrg	  versuffix=$major.$age.$revision
88787a3b38f7Smrg	  # Darwin ld doesn't like 0 for these options...
88797a3b38f7Smrg	  func_arith $current + 1
88807a3b38f7Smrg	  minor_current=$func_arith_result
88816fc0178dSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
88827a3b38f7Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
88836fc0178dSmrg          # On Darwin other compilers
88846fc0178dSmrg          case $CC in
88856fc0178dSmrg              nagfor*)
88866fc0178dSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
88876fc0178dSmrg                  ;;
88886fc0178dSmrg              *)
88896fc0178dSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
88906fc0178dSmrg                  ;;
88916fc0178dSmrg          esac
88927a3b38f7Smrg	  ;;
88937a3b38f7Smrg
88947a3b38f7Smrg	freebsd-aout)
88956fc0178dSmrg	  major=.$current
88966fc0178dSmrg	  versuffix=.$current.$revision
88977a3b38f7Smrg	  ;;
88987a3b38f7Smrg
88997a3b38f7Smrg	freebsd-elf)
89006fc0178dSmrg	  func_arith $current - $age
89016fc0178dSmrg	  major=.$func_arith_result
89026fc0178dSmrg	  versuffix=$major.$age.$revision
89037a3b38f7Smrg	  ;;
89047a3b38f7Smrg
89057a3b38f7Smrg	irix | nonstopux)
89066fc0178dSmrg	  if test no = "$lt_irix_increment"; then
89077a3b38f7Smrg	    func_arith $current - $age
89087a3b38f7Smrg	  else
89097a3b38f7Smrg	    func_arith $current - $age + 1
89107a3b38f7Smrg	  fi
89117a3b38f7Smrg	  major=$func_arith_result
89127a3b38f7Smrg
89137a3b38f7Smrg	  case $version_type in
89147a3b38f7Smrg	    nonstopux) verstring_prefix=nonstopux ;;
89157a3b38f7Smrg	    *)         verstring_prefix=sgi ;;
89167a3b38f7Smrg	  esac
89176fc0178dSmrg	  verstring=$verstring_prefix$major.$revision
89187a3b38f7Smrg
89197a3b38f7Smrg	  # Add in all the interfaces that we are compatible with.
89207a3b38f7Smrg	  loop=$revision
89216fc0178dSmrg	  while test 0 -ne "$loop"; do
89227a3b38f7Smrg	    func_arith $revision - $loop
89237a3b38f7Smrg	    iface=$func_arith_result
89247a3b38f7Smrg	    func_arith $loop - 1
89257a3b38f7Smrg	    loop=$func_arith_result
89266fc0178dSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
89277a3b38f7Smrg	  done
89287a3b38f7Smrg
89296fc0178dSmrg	  # Before this point, $major must not contain '.'.
89307a3b38f7Smrg	  major=.$major
89316fc0178dSmrg	  versuffix=$major.$revision
89327a3b38f7Smrg	  ;;
89337a3b38f7Smrg
8934fc544a13Smrg	linux) # correct to gnu/linux during the next big refactor
89357a3b38f7Smrg	  func_arith $current - $age
89367a3b38f7Smrg	  major=.$func_arith_result
89376fc0178dSmrg	  versuffix=$major.$age.$revision
89387a3b38f7Smrg	  ;;
89397a3b38f7Smrg
89407a3b38f7Smrg	osf)
89417a3b38f7Smrg	  func_arith $current - $age
89427a3b38f7Smrg	  major=.$func_arith_result
89436fc0178dSmrg	  versuffix=.$current.$age.$revision
89446fc0178dSmrg	  verstring=$current.$age.$revision
89457a3b38f7Smrg
89467a3b38f7Smrg	  # Add in all the interfaces that we are compatible with.
89477a3b38f7Smrg	  loop=$age
89486fc0178dSmrg	  while test 0 -ne "$loop"; do
89497a3b38f7Smrg	    func_arith $current - $loop
89507a3b38f7Smrg	    iface=$func_arith_result
89517a3b38f7Smrg	    func_arith $loop - 1
89527a3b38f7Smrg	    loop=$func_arith_result
89536fc0178dSmrg	    verstring=$verstring:$iface.0
89547a3b38f7Smrg	  done
89557a3b38f7Smrg
89567a3b38f7Smrg	  # Make executables depend on our current version.
89576fc0178dSmrg	  func_append verstring ":$current.0"
89587a3b38f7Smrg	  ;;
89597a3b38f7Smrg
89607a3b38f7Smrg	qnx)
89616fc0178dSmrg	  major=.$current
89626fc0178dSmrg	  versuffix=.$current
89636fc0178dSmrg	  ;;
89646fc0178dSmrg
89656fc0178dSmrg	sco)
89666fc0178dSmrg	  major=.$current
89676fc0178dSmrg	  versuffix=.$current
89687a3b38f7Smrg	  ;;
89697a3b38f7Smrg
89707a3b38f7Smrg	sunos)
89716fc0178dSmrg	  major=.$current
89726fc0178dSmrg	  versuffix=.$current.$revision
89737a3b38f7Smrg	  ;;
89747a3b38f7Smrg
89757a3b38f7Smrg	windows)
89767a3b38f7Smrg	  # Use '-' rather than '.', since we only want one
89776fc0178dSmrg	  # extension on DOS 8.3 file systems.
89787a3b38f7Smrg	  func_arith $current - $age
89797a3b38f7Smrg	  major=$func_arith_result
89806fc0178dSmrg	  versuffix=-$major
89817a3b38f7Smrg	  ;;
89827a3b38f7Smrg
89837a3b38f7Smrg	*)
89846fc0178dSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
89857a3b38f7Smrg	  ;;
89867a3b38f7Smrg	esac
89877a3b38f7Smrg
89887a3b38f7Smrg	# Clear the version info if we defaulted, and they specified a release.
89897a3b38f7Smrg	if test -z "$vinfo" && test -n "$release"; then
89907a3b38f7Smrg	  major=
89917a3b38f7Smrg	  case $version_type in
89927a3b38f7Smrg	  darwin)
89937a3b38f7Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
89947a3b38f7Smrg	    # problems, so we reset it completely
89957a3b38f7Smrg	    verstring=
89967a3b38f7Smrg	    ;;
89977a3b38f7Smrg	  *)
89986fc0178dSmrg	    verstring=0.0
89997a3b38f7Smrg	    ;;
90007a3b38f7Smrg	  esac
90016fc0178dSmrg	  if test no = "$need_version"; then
90027a3b38f7Smrg	    versuffix=
90037a3b38f7Smrg	  else
90046fc0178dSmrg	    versuffix=.0.0
90057a3b38f7Smrg	  fi
90067a3b38f7Smrg	fi
90077a3b38f7Smrg
90087a3b38f7Smrg	# Remove version info from name if versioning should be avoided
90096fc0178dSmrg	if test yes,no = "$avoid_version,$need_version"; then
90107a3b38f7Smrg	  major=
90117a3b38f7Smrg	  versuffix=
90126fc0178dSmrg	  verstring=
90137a3b38f7Smrg	fi
90147a3b38f7Smrg
90157a3b38f7Smrg	# Check to see if the archive will have undefined symbols.
90166fc0178dSmrg	if test yes = "$allow_undefined"; then
90176fc0178dSmrg	  if test unsupported = "$allow_undefined_flag"; then
90186fc0178dSmrg	    if test yes = "$build_old_libs"; then
90196fc0178dSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
90206fc0178dSmrg	      build_libtool_libs=no
90216fc0178dSmrg	    else
90226fc0178dSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
90236fc0178dSmrg	    fi
90247a3b38f7Smrg	  fi
90257a3b38f7Smrg	else
90267a3b38f7Smrg	  # Don't allow undefined symbols.
90276fc0178dSmrg	  allow_undefined_flag=$no_undefined_flag
90287a3b38f7Smrg	fi
90297a3b38f7Smrg
90307a3b38f7Smrg      fi
90317a3b38f7Smrg
90326fc0178dSmrg      func_generate_dlsyms "$libname" "$libname" :
9033862f5301Smrg      func_append libobjs " $symfileobj"
90346fc0178dSmrg      test " " = "$libobjs" && libobjs=
90357a3b38f7Smrg
90366fc0178dSmrg      if test relink != "$opt_mode"; then
90377a3b38f7Smrg	# Remove our outputs, but don't remove object files since they
90387a3b38f7Smrg	# may have been created when compiling PIC objects.
90397a3b38f7Smrg	removelist=
90407a3b38f7Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
90417a3b38f7Smrg	for p in $tempremovelist; do
90427a3b38f7Smrg	  case $p in
90437a3b38f7Smrg	    *.$objext | *.gcno)
90447a3b38f7Smrg	       ;;
90456fc0178dSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
90466fc0178dSmrg	       if test -n "$precious_files_regex"; then
90477a3b38f7Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
90487a3b38f7Smrg		 then
90497a3b38f7Smrg		   continue
90507a3b38f7Smrg		 fi
90517a3b38f7Smrg	       fi
9052862f5301Smrg	       func_append removelist " $p"
90537a3b38f7Smrg	       ;;
90547a3b38f7Smrg	    *) ;;
90557a3b38f7Smrg	  esac
90567a3b38f7Smrg	done
90577a3b38f7Smrg	test -n "$removelist" && \
90587a3b38f7Smrg	  func_show_eval "${RM}r \$removelist"
90597a3b38f7Smrg      fi
90607a3b38f7Smrg
90617a3b38f7Smrg      # Now set the variables for building old libraries.
90626fc0178dSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9063862f5301Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
90647a3b38f7Smrg
90657a3b38f7Smrg	# Transform .lo files to .o files.
90666fc0178dSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
90677a3b38f7Smrg      fi
90687a3b38f7Smrg
90697a3b38f7Smrg      # Eliminate all temporary directories.
90707a3b38f7Smrg      #for path in $notinst_path; do
907144dda7b2Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
907244dda7b2Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
907344dda7b2Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
90747a3b38f7Smrg      #done
90757a3b38f7Smrg
90767a3b38f7Smrg      if test -n "$xrpath"; then
90777a3b38f7Smrg	# If the user specified any rpath flags, then add them.
90787a3b38f7Smrg	temp_xrpath=
90797a3b38f7Smrg	for libdir in $xrpath; do
9080862f5301Smrg	  func_replace_sysroot "$libdir"
9081862f5301Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
90827a3b38f7Smrg	  case "$finalize_rpath " in
90837a3b38f7Smrg	  *" $libdir "*) ;;
9084862f5301Smrg	  *) func_append finalize_rpath " $libdir" ;;
90857a3b38f7Smrg	  esac
90867a3b38f7Smrg	done
90876fc0178dSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
90887a3b38f7Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
90897a3b38f7Smrg	fi
90907a3b38f7Smrg      fi
90917a3b38f7Smrg
90927a3b38f7Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
90936fc0178dSmrg      old_dlfiles=$dlfiles
90947a3b38f7Smrg      dlfiles=
90957a3b38f7Smrg      for lib in $old_dlfiles; do
90967a3b38f7Smrg	case " $dlprefiles $dlfiles " in
90977a3b38f7Smrg	*" $lib "*) ;;
9098862f5301Smrg	*) func_append dlfiles " $lib" ;;
90997a3b38f7Smrg	esac
91007a3b38f7Smrg      done
91017a3b38f7Smrg
91027a3b38f7Smrg      # Make sure dlprefiles contains only unique files
91036fc0178dSmrg      old_dlprefiles=$dlprefiles
91047a3b38f7Smrg      dlprefiles=
91057a3b38f7Smrg      for lib in $old_dlprefiles; do
91067a3b38f7Smrg	case "$dlprefiles " in
91077a3b38f7Smrg	*" $lib "*) ;;
9108862f5301Smrg	*) func_append dlprefiles " $lib" ;;
91097a3b38f7Smrg	esac
91107a3b38f7Smrg      done
91117a3b38f7Smrg
91126fc0178dSmrg      if test yes = "$build_libtool_libs"; then
91137a3b38f7Smrg	if test -n "$rpath"; then
91147a3b38f7Smrg	  case $host in
911544dda7b2Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
91167a3b38f7Smrg	    # these systems don't actually have a c library (as such)!
91177a3b38f7Smrg	    ;;
91187a3b38f7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
91197a3b38f7Smrg	    # Rhapsody C library is in the System framework
9120862f5301Smrg	    func_append deplibs " System.ltframework"
91217a3b38f7Smrg	    ;;
91227a3b38f7Smrg	  *-*-netbsd*)
91237a3b38f7Smrg	    # Don't link with libc until the a.out ld.so is fixed.
91247a3b38f7Smrg	    ;;
91257a3b38f7Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
91267a3b38f7Smrg	    # Do not include libc due to us having libc/libc_r.
91277a3b38f7Smrg	    ;;
91287a3b38f7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
91297a3b38f7Smrg	    # Causes problems with __ctype
91307a3b38f7Smrg	    ;;
91317a3b38f7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
91327a3b38f7Smrg	    # Compiler inserts libc in the correct place for threads to work
91337a3b38f7Smrg	    ;;
91347a3b38f7Smrg	  *)
91357a3b38f7Smrg	    # Add libc to deplibs on all other systems if necessary.
91366fc0178dSmrg	    if test yes = "$build_libtool_need_lc"; then
9137862f5301Smrg	      func_append deplibs " -lc"
91387a3b38f7Smrg	    fi
91397a3b38f7Smrg	    ;;
91407a3b38f7Smrg	  esac
91417a3b38f7Smrg	fi
91427a3b38f7Smrg
91437a3b38f7Smrg	# Transform deplibs into only deplibs that can be linked in shared.
91447a3b38f7Smrg	name_save=$name
91457a3b38f7Smrg	libname_save=$libname
91467a3b38f7Smrg	release_save=$release
91477a3b38f7Smrg	versuffix_save=$versuffix
91487a3b38f7Smrg	major_save=$major
91497a3b38f7Smrg	# I'm not sure if I'm treating the release correctly.  I think
91507a3b38f7Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
91517a3b38f7Smrg	# add it in twice.  Is that correct?
91526fc0178dSmrg	release=
91536fc0178dSmrg	versuffix=
91546fc0178dSmrg	major=
91557a3b38f7Smrg	newdeplibs=
91567a3b38f7Smrg	droppeddeps=no
91577a3b38f7Smrg	case $deplibs_check_method in
91587a3b38f7Smrg	pass_all)
91597a3b38f7Smrg	  # Don't check for shared/static.  Everything works.
91607a3b38f7Smrg	  # This might be a little naive.  We might want to check
91617a3b38f7Smrg	  # whether the library exists or not.  But this is on
91627a3b38f7Smrg	  # osf3 & osf4 and I'm not really sure... Just
91637a3b38f7Smrg	  # implementing what was already the behavior.
91647a3b38f7Smrg	  newdeplibs=$deplibs
91657a3b38f7Smrg	  ;;
91667a3b38f7Smrg	test_compile)
91677a3b38f7Smrg	  # This code stresses the "libraries are programs" paradigm to its
91687a3b38f7Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
91697a3b38f7Smrg	  # against the deplibs as a proxy for the library.  Then we can check
91707a3b38f7Smrg	  # whether they linked in statically or dynamically with ldd.
91717a3b38f7Smrg	  $opt_dry_run || $RM conftest.c
91727a3b38f7Smrg	  cat > conftest.c <<EOF
91737a3b38f7Smrg	  int main() { return 0; }
91747a3b38f7SmrgEOF
91757a3b38f7Smrg	  $opt_dry_run || $RM conftest
91767a3b38f7Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
91777a3b38f7Smrg	    ldd_output=`ldd conftest`
91787a3b38f7Smrg	    for i in $deplibs; do
91797a3b38f7Smrg	      case $i in
91807a3b38f7Smrg	      -l*)
91817a3b38f7Smrg		func_stripname -l '' "$i"
91827a3b38f7Smrg		name=$func_stripname_result
91836fc0178dSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
91847a3b38f7Smrg		  case " $predeps $postdeps " in
91857a3b38f7Smrg		  *" $i "*)
9186862f5301Smrg		    func_append newdeplibs " $i"
91876fc0178dSmrg		    i=
91887a3b38f7Smrg		    ;;
91897a3b38f7Smrg		  esac
91907a3b38f7Smrg		fi
91916fc0178dSmrg		if test -n "$i"; then
91927a3b38f7Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
91937a3b38f7Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
91947a3b38f7Smrg		  set dummy $deplib_matches; shift
91957a3b38f7Smrg		  deplib_match=$1
91966fc0178dSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9197862f5301Smrg		    func_append newdeplibs " $i"
91987a3b38f7Smrg		  else
91997a3b38f7Smrg		    droppeddeps=yes
920044dda7b2Smrg		    echo
92017a3b38f7Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
920244dda7b2Smrg		    echo "*** I have the capability to make that library automatically link in when"
920344dda7b2Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
920444dda7b2Smrg		    echo "*** shared version of the library, which I believe you do not have"
920544dda7b2Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
920644dda7b2Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
92077a3b38f7Smrg		  fi
92087a3b38f7Smrg		fi
92097a3b38f7Smrg		;;
92107a3b38f7Smrg	      *)
9211862f5301Smrg		func_append newdeplibs " $i"
92127a3b38f7Smrg		;;
92137a3b38f7Smrg	      esac
92147a3b38f7Smrg	    done
92157a3b38f7Smrg	  else
92167a3b38f7Smrg	    # Error occurred in the first compile.  Let's try to salvage
92177a3b38f7Smrg	    # the situation: Compile a separate program for each library.
92187a3b38f7Smrg	    for i in $deplibs; do
92197a3b38f7Smrg	      case $i in
92207a3b38f7Smrg	      -l*)
92217a3b38f7Smrg		func_stripname -l '' "$i"
92227a3b38f7Smrg		name=$func_stripname_result
92237a3b38f7Smrg		$opt_dry_run || $RM conftest
92247a3b38f7Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
92257a3b38f7Smrg		  ldd_output=`ldd conftest`
92266fc0178dSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
92277a3b38f7Smrg		    case " $predeps $postdeps " in
92287a3b38f7Smrg		    *" $i "*)
9229862f5301Smrg		      func_append newdeplibs " $i"
92306fc0178dSmrg		      i=
92317a3b38f7Smrg		      ;;
92327a3b38f7Smrg		    esac
92337a3b38f7Smrg		  fi
92346fc0178dSmrg		  if test -n "$i"; then
92357a3b38f7Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
92367a3b38f7Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
92377a3b38f7Smrg		    set dummy $deplib_matches; shift
92387a3b38f7Smrg		    deplib_match=$1
92396fc0178dSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9240862f5301Smrg		      func_append newdeplibs " $i"
92417a3b38f7Smrg		    else
92427a3b38f7Smrg		      droppeddeps=yes
924344dda7b2Smrg		      echo
92447a3b38f7Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
924544dda7b2Smrg		      echo "*** I have the capability to make that library automatically link in when"
924644dda7b2Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
924744dda7b2Smrg		      echo "*** shared version of the library, which you do not appear to have"
924844dda7b2Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
924944dda7b2Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
92507a3b38f7Smrg		    fi
92517a3b38f7Smrg		  fi
92527a3b38f7Smrg		else
92537a3b38f7Smrg		  droppeddeps=yes
925444dda7b2Smrg		  echo
92557a3b38f7Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
925644dda7b2Smrg		  echo "*** make it link in!  You will probably need to install it or some"
925744dda7b2Smrg		  echo "*** library that it depends on before this library will be fully"
925844dda7b2Smrg		  echo "*** functional.  Installing it before continuing would be even better."
92597a3b38f7Smrg		fi
92607a3b38f7Smrg		;;
92617a3b38f7Smrg	      *)
9262862f5301Smrg		func_append newdeplibs " $i"
92637a3b38f7Smrg		;;
92647a3b38f7Smrg	      esac
92657a3b38f7Smrg	    done
92667a3b38f7Smrg	  fi
92677a3b38f7Smrg	  ;;
92687a3b38f7Smrg	file_magic*)
92697a3b38f7Smrg	  set dummy $deplibs_check_method; shift
92707a3b38f7Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
92717a3b38f7Smrg	  for a_deplib in $deplibs; do
92727a3b38f7Smrg	    case $a_deplib in
92737a3b38f7Smrg	    -l*)
92747a3b38f7Smrg	      func_stripname -l '' "$a_deplib"
92757a3b38f7Smrg	      name=$func_stripname_result
92766fc0178dSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
92777a3b38f7Smrg		case " $predeps $postdeps " in
92787a3b38f7Smrg		*" $a_deplib "*)
9279862f5301Smrg		  func_append newdeplibs " $a_deplib"
92806fc0178dSmrg		  a_deplib=
92817a3b38f7Smrg		  ;;
92827a3b38f7Smrg		esac
92837a3b38f7Smrg	      fi
92846fc0178dSmrg	      if test -n "$a_deplib"; then
92857a3b38f7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9286862f5301Smrg		if test -n "$file_magic_glob"; then
9287862f5301Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9288862f5301Smrg		else
9289862f5301Smrg		  libnameglob=$libname
9290862f5301Smrg		fi
92916fc0178dSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
92927a3b38f7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
92936fc0178dSmrg		  if test yes = "$want_nocaseglob"; then
9294862f5301Smrg		    shopt -s nocaseglob
9295862f5301Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9296862f5301Smrg		    $nocaseglob
9297862f5301Smrg		  else
9298862f5301Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9299862f5301Smrg		  fi
93007a3b38f7Smrg		  for potent_lib in $potential_libs; do
93017a3b38f7Smrg		      # Follow soft links.
93027a3b38f7Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
93037a3b38f7Smrg			 $GREP " -> " >/dev/null; then
93047a3b38f7Smrg			continue
93057a3b38f7Smrg		      fi
93067a3b38f7Smrg		      # The statement above tries to avoid entering an
93077a3b38f7Smrg		      # endless loop below, in case of cyclic links.
93087a3b38f7Smrg		      # We might still enter an endless loop, since a link
93097a3b38f7Smrg		      # loop can be closed while we follow links,
93107a3b38f7Smrg		      # but so what?
93116fc0178dSmrg		      potlib=$potent_lib
93127a3b38f7Smrg		      while test -h "$potlib" 2>/dev/null; do
93136fc0178dSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
93147a3b38f7Smrg			case $potliblink in
93156fc0178dSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
93166fc0178dSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
93177a3b38f7Smrg			esac
93187a3b38f7Smrg		      done
93197a3b38f7Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
93207a3b38f7Smrg			 $SED -e 10q |
93217a3b38f7Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9322862f5301Smrg			func_append newdeplibs " $a_deplib"
93236fc0178dSmrg			a_deplib=
93247a3b38f7Smrg			break 2
93257a3b38f7Smrg		      fi
93267a3b38f7Smrg		  done
93277a3b38f7Smrg		done
93287a3b38f7Smrg	      fi
93296fc0178dSmrg	      if test -n "$a_deplib"; then
93307a3b38f7Smrg		droppeddeps=yes
933144dda7b2Smrg		echo
93327a3b38f7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
933344dda7b2Smrg		echo "*** I have the capability to make that library automatically link in when"
933444dda7b2Smrg		echo "*** you link to this library.  But I can only do this if you have a"
933544dda7b2Smrg		echo "*** shared version of the library, which you do not appear to have"
933644dda7b2Smrg		echo "*** because I did check the linker path looking for a file starting"
93376fc0178dSmrg		if test -z "$potlib"; then
93387a3b38f7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
93397a3b38f7Smrg		else
93407a3b38f7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
93417a3b38f7Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
93427a3b38f7Smrg		fi
93437a3b38f7Smrg	      fi
93447a3b38f7Smrg	      ;;
93457a3b38f7Smrg	    *)
93467a3b38f7Smrg	      # Add a -L argument.
9347862f5301Smrg	      func_append newdeplibs " $a_deplib"
93487a3b38f7Smrg	      ;;
93497a3b38f7Smrg	    esac
93507a3b38f7Smrg	  done # Gone through all deplibs.
93517a3b38f7Smrg	  ;;
93527a3b38f7Smrg	match_pattern*)
93537a3b38f7Smrg	  set dummy $deplibs_check_method; shift
93547a3b38f7Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
93557a3b38f7Smrg	  for a_deplib in $deplibs; do
93567a3b38f7Smrg	    case $a_deplib in
93577a3b38f7Smrg	    -l*)
93587a3b38f7Smrg	      func_stripname -l '' "$a_deplib"
93597a3b38f7Smrg	      name=$func_stripname_result
93606fc0178dSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
93617a3b38f7Smrg		case " $predeps $postdeps " in
93627a3b38f7Smrg		*" $a_deplib "*)
9363862f5301Smrg		  func_append newdeplibs " $a_deplib"
93646fc0178dSmrg		  a_deplib=
93657a3b38f7Smrg		  ;;
93667a3b38f7Smrg		esac
93677a3b38f7Smrg	      fi
93686fc0178dSmrg	      if test -n "$a_deplib"; then
93697a3b38f7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
93707a3b38f7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
93717a3b38f7Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
93727a3b38f7Smrg		  for potent_lib in $potential_libs; do
93736fc0178dSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
937444dda7b2Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
93757a3b38f7Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9376862f5301Smrg		      func_append newdeplibs " $a_deplib"
93776fc0178dSmrg		      a_deplib=
93787a3b38f7Smrg		      break 2
93797a3b38f7Smrg		    fi
93807a3b38f7Smrg		  done
93817a3b38f7Smrg		done
93827a3b38f7Smrg	      fi
93836fc0178dSmrg	      if test -n "$a_deplib"; then
93847a3b38f7Smrg		droppeddeps=yes
938544dda7b2Smrg		echo
93867a3b38f7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
938744dda7b2Smrg		echo "*** I have the capability to make that library automatically link in when"
938844dda7b2Smrg		echo "*** you link to this library.  But I can only do this if you have a"
938944dda7b2Smrg		echo "*** shared version of the library, which you do not appear to have"
939044dda7b2Smrg		echo "*** because I did check the linker path looking for a file starting"
93916fc0178dSmrg		if test -z "$potlib"; then
93927a3b38f7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
93937a3b38f7Smrg		else
93947a3b38f7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
93957a3b38f7Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
93967a3b38f7Smrg		fi
93977a3b38f7Smrg	      fi
93987a3b38f7Smrg	      ;;
93997a3b38f7Smrg	    *)
94007a3b38f7Smrg	      # Add a -L argument.
9401862f5301Smrg	      func_append newdeplibs " $a_deplib"
94027a3b38f7Smrg	      ;;
94037a3b38f7Smrg	    esac
94047a3b38f7Smrg	  done # Gone through all deplibs.
94057a3b38f7Smrg	  ;;
94067a3b38f7Smrg	none | unknown | *)
94076fc0178dSmrg	  newdeplibs=
940844dda7b2Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
94096fc0178dSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94106fc0178dSmrg	    for i in $predeps $postdeps; do
94117a3b38f7Smrg	      # can't use Xsed below, because $i might contain '/'
94126fc0178dSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
94137a3b38f7Smrg	    done
94147a3b38f7Smrg	  fi
941544dda7b2Smrg	  case $tmp_deplibs in
941644dda7b2Smrg	  *[!\	\ ]*)
941744dda7b2Smrg	    echo
94186fc0178dSmrg	    if test none = "$deplibs_check_method"; then
941944dda7b2Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
94207a3b38f7Smrg	    else
942144dda7b2Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
94227a3b38f7Smrg	    fi
942344dda7b2Smrg	    echo "*** All declared inter-library dependencies are being dropped."
94247a3b38f7Smrg	    droppeddeps=yes
942544dda7b2Smrg	    ;;
942644dda7b2Smrg	  esac
94277a3b38f7Smrg	  ;;
94287a3b38f7Smrg	esac
94297a3b38f7Smrg	versuffix=$versuffix_save
94307a3b38f7Smrg	major=$major_save
94317a3b38f7Smrg	release=$release_save
94327a3b38f7Smrg	libname=$libname_save
94337a3b38f7Smrg	name=$name_save
94347a3b38f7Smrg
94357a3b38f7Smrg	case $host in
94367a3b38f7Smrg	*-*-rhapsody* | *-*-darwin1.[012])
94377a3b38f7Smrg	  # On Rhapsody replace the C library with the System framework
943844dda7b2Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
94397a3b38f7Smrg	  ;;
94407a3b38f7Smrg	esac
94417a3b38f7Smrg
94426fc0178dSmrg	if test yes = "$droppeddeps"; then
94436fc0178dSmrg	  if test yes = "$module"; then
944444dda7b2Smrg	    echo
944544dda7b2Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
94467a3b38f7Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
944744dda7b2Smrg	    echo "*** a static module, that should work as long as the dlopening"
944844dda7b2Smrg	    echo "*** application is linked with the -dlopen flag."
94497a3b38f7Smrg	    if test -z "$global_symbol_pipe"; then
945044dda7b2Smrg	      echo
945144dda7b2Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
94526fc0178dSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
945344dda7b2Smrg	      echo "*** not find such a program.  So, this module is probably useless."
94546fc0178dSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
94557a3b38f7Smrg	    fi
94566fc0178dSmrg	    if test no = "$build_old_libs"; then
94576fc0178dSmrg	      oldlibs=$output_objdir/$libname.$libext
94587a3b38f7Smrg	      build_libtool_libs=module
94597a3b38f7Smrg	      build_old_libs=yes
94607a3b38f7Smrg	    else
94617a3b38f7Smrg	      build_libtool_libs=no
94627a3b38f7Smrg	    fi
94637a3b38f7Smrg	  else
946444dda7b2Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
946544dda7b2Smrg	    echo "*** automatically added whenever a program is linked with this library"
946644dda7b2Smrg	    echo "*** or is declared to -dlopen it."
94677a3b38f7Smrg
94686fc0178dSmrg	    if test no = "$allow_undefined"; then
946944dda7b2Smrg	      echo
947044dda7b2Smrg	      echo "*** Since this library must not contain undefined symbols,"
947144dda7b2Smrg	      echo "*** because either the platform does not support them or"
947244dda7b2Smrg	      echo "*** it was explicitly requested with -no-undefined,"
947344dda7b2Smrg	      echo "*** libtool will only create a static version of it."
94746fc0178dSmrg	      if test no = "$build_old_libs"; then
94756fc0178dSmrg		oldlibs=$output_objdir/$libname.$libext
94767a3b38f7Smrg		build_libtool_libs=module
94777a3b38f7Smrg		build_old_libs=yes
94787a3b38f7Smrg	      else
94797a3b38f7Smrg		build_libtool_libs=no
94807a3b38f7Smrg	      fi
94817a3b38f7Smrg	    fi
94827a3b38f7Smrg	  fi
94837a3b38f7Smrg	fi
94847a3b38f7Smrg	# Done checking deplibs!
94857a3b38f7Smrg	deplibs=$newdeplibs
94867a3b38f7Smrg      fi
94877a3b38f7Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
94887a3b38f7Smrg      case $host in
94897a3b38f7Smrg	*-*-darwin*)
949044dda7b2Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
949144dda7b2Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
949244dda7b2Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
94937a3b38f7Smrg	  ;;
94947a3b38f7Smrg      esac
94957a3b38f7Smrg
94967a3b38f7Smrg      # move library search paths that coincide with paths to not yet
94977a3b38f7Smrg      # installed libraries to the beginning of the library search list
94987a3b38f7Smrg      new_libs=
94997a3b38f7Smrg      for path in $notinst_path; do
95007a3b38f7Smrg	case " $new_libs " in
95017a3b38f7Smrg	*" -L$path/$objdir "*) ;;
95027a3b38f7Smrg	*)
95037a3b38f7Smrg	  case " $deplibs " in
95047a3b38f7Smrg	  *" -L$path/$objdir "*)
9505862f5301Smrg	    func_append new_libs " -L$path/$objdir" ;;
95067a3b38f7Smrg	  esac
95077a3b38f7Smrg	  ;;
95087a3b38f7Smrg	esac
95097a3b38f7Smrg      done
95107a3b38f7Smrg      for deplib in $deplibs; do
95117a3b38f7Smrg	case $deplib in
95127a3b38f7Smrg	-L*)
95137a3b38f7Smrg	  case " $new_libs " in
95147a3b38f7Smrg	  *" $deplib "*) ;;
9515862f5301Smrg	  *) func_append new_libs " $deplib" ;;
95167a3b38f7Smrg	  esac
95177a3b38f7Smrg	  ;;
9518862f5301Smrg	*) func_append new_libs " $deplib" ;;
95197a3b38f7Smrg	esac
95207a3b38f7Smrg      done
95216fc0178dSmrg      deplibs=$new_libs
95227a3b38f7Smrg
95237a3b38f7Smrg      # All the library-specific variables (install_libdir is set above).
95247a3b38f7Smrg      library_names=
95257a3b38f7Smrg      old_library=
95267a3b38f7Smrg      dlname=
95277a3b38f7Smrg
95287a3b38f7Smrg      # Test again, we may have decided not to build it any more
95296fc0178dSmrg      if test yes = "$build_libtool_libs"; then
95306fc0178dSmrg	# Remove $wl instances when linking with ld.
9531fc544a13Smrg	# FIXME: should test the right _cmds variable.
9532fc544a13Smrg	case $archive_cmds in
9533fc544a13Smrg	  *\$LD\ *) wl= ;;
9534fc544a13Smrg        esac
95356fc0178dSmrg	if test yes = "$hardcode_into_libs"; then
95367a3b38f7Smrg	  # Hardcode the library paths
95377a3b38f7Smrg	  hardcode_libdirs=
95387a3b38f7Smrg	  dep_rpath=
95396fc0178dSmrg	  rpath=$finalize_rpath
95406fc0178dSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
95417a3b38f7Smrg	  for libdir in $rpath; do
95427a3b38f7Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
95437a3b38f7Smrg	      if test -n "$hardcode_libdir_separator"; then
9544862f5301Smrg		func_replace_sysroot "$libdir"
9545862f5301Smrg		libdir=$func_replace_sysroot_result
95467a3b38f7Smrg		if test -z "$hardcode_libdirs"; then
95476fc0178dSmrg		  hardcode_libdirs=$libdir
95487a3b38f7Smrg		else
95497a3b38f7Smrg		  # Just accumulate the unique libdirs.
95507a3b38f7Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
95517a3b38f7Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
95527a3b38f7Smrg		    ;;
95537a3b38f7Smrg		  *)
9554862f5301Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
95557a3b38f7Smrg		    ;;
95567a3b38f7Smrg		  esac
95577a3b38f7Smrg		fi
95587a3b38f7Smrg	      else
95597a3b38f7Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9560862f5301Smrg		func_append dep_rpath " $flag"
95617a3b38f7Smrg	      fi
95627a3b38f7Smrg	    elif test -n "$runpath_var"; then
95637a3b38f7Smrg	      case "$perm_rpath " in
95647a3b38f7Smrg	      *" $libdir "*) ;;
9565fc544a13Smrg	      *) func_append perm_rpath " $libdir" ;;
95667a3b38f7Smrg	      esac
95677a3b38f7Smrg	    fi
95687a3b38f7Smrg	  done
95697a3b38f7Smrg	  # Substitute the hardcoded libdirs into the rpath.
95707a3b38f7Smrg	  if test -n "$hardcode_libdir_separator" &&
95717a3b38f7Smrg	     test -n "$hardcode_libdirs"; then
95726fc0178dSmrg	    libdir=$hardcode_libdirs
9573fc544a13Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
95747a3b38f7Smrg	  fi
95757a3b38f7Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
95767a3b38f7Smrg	    # We should set the runpath_var.
95777a3b38f7Smrg	    rpath=
95787a3b38f7Smrg	    for dir in $perm_rpath; do
9579862f5301Smrg	      func_append rpath "$dir:"
95807a3b38f7Smrg	    done
95817a3b38f7Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
95827a3b38f7Smrg	  fi
95837a3b38f7Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
95847a3b38f7Smrg	fi
9585ff559fabSmrg
95866fc0178dSmrg	shlibpath=$finalize_shlibpath
95876fc0178dSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
95887a3b38f7Smrg	if test -n "$shlibpath"; then
95897a3b38f7Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
95907a3b38f7Smrg	fi
9591ff559fabSmrg
95927a3b38f7Smrg	# Get the real and link names of the library.
95937a3b38f7Smrg	eval shared_ext=\"$shrext_cmds\"
95947a3b38f7Smrg	eval library_names=\"$library_names_spec\"
95957a3b38f7Smrg	set dummy $library_names
95967a3b38f7Smrg	shift
95976fc0178dSmrg	realname=$1
95987a3b38f7Smrg	shift
9599ff559fabSmrg
96007a3b38f7Smrg	if test -n "$soname_spec"; then
96017a3b38f7Smrg	  eval soname=\"$soname_spec\"
96027a3b38f7Smrg	else
96036fc0178dSmrg	  soname=$realname
96047a3b38f7Smrg	fi
96057a3b38f7Smrg	if test -z "$dlname"; then
96067a3b38f7Smrg	  dlname=$soname
96077a3b38f7Smrg	fi
9608ff559fabSmrg
96096fc0178dSmrg	lib=$output_objdir/$realname
96107a3b38f7Smrg	linknames=
96117a3b38f7Smrg	for link
96127a3b38f7Smrg	do
9613862f5301Smrg	  func_append linknames " $link"
96147a3b38f7Smrg	done
9615ff559fabSmrg
96167a3b38f7Smrg	# Use standard objects if they are pic
961744dda7b2Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
96187a3b38f7Smrg	test "X$libobjs" = "X " && libobjs=
9619ff559fabSmrg
96207a3b38f7Smrg	delfiles=
96217a3b38f7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
96227a3b38f7Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
96236fc0178dSmrg	  export_symbols=$output_objdir/$libname.uexp
9624862f5301Smrg	  func_append delfiles " $export_symbols"
96257a3b38f7Smrg	fi
9626ff559fabSmrg
96277a3b38f7Smrg	orig_export_symbols=
96287a3b38f7Smrg	case $host_os in
96297a3b38f7Smrg	cygwin* | mingw* | cegcc*)
96307a3b38f7Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
96317a3b38f7Smrg	    # exporting using user supplied symfile
96326fc0178dSmrg	    func_dll_def_p "$export_symbols" || {
96337a3b38f7Smrg	      # and it's NOT already a .def file. Must figure out
96347a3b38f7Smrg	      # which of the given symbols are data symbols and tag
96357a3b38f7Smrg	      # them as such. So, trigger use of export_symbols_cmds.
96367a3b38f7Smrg	      # export_symbols gets reassigned inside the "prepare
96377a3b38f7Smrg	      # the list of exported symbols" if statement, so the
96387a3b38f7Smrg	      # include_expsyms logic still works.
96396fc0178dSmrg	      orig_export_symbols=$export_symbols
96407a3b38f7Smrg	      export_symbols=
96417a3b38f7Smrg	      always_export_symbols=yes
96426fc0178dSmrg	    }
96437a3b38f7Smrg	  fi
96447a3b38f7Smrg	  ;;
96457a3b38f7Smrg	esac
9646ff559fabSmrg
96477a3b38f7Smrg	# Prepare the list of exported symbols
96487a3b38f7Smrg	if test -z "$export_symbols"; then
96496fc0178dSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
96506fc0178dSmrg	    func_verbose "generating symbol list for '$libname.la'"
96516fc0178dSmrg	    export_symbols=$output_objdir/$libname.exp
96527a3b38f7Smrg	    $opt_dry_run || $RM $export_symbols
96537a3b38f7Smrg	    cmds=$export_symbols_cmds
96546fc0178dSmrg	    save_ifs=$IFS; IFS='~'
9655862f5301Smrg	    for cmd1 in $cmds; do
96566fc0178dSmrg	      IFS=$save_ifs
9657862f5301Smrg	      # Take the normal branch if the nm_file_list_spec branch
9658862f5301Smrg	      # doesn't work or if tool conversion is not needed.
9659862f5301Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9660862f5301Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9661862f5301Smrg		  try_normal_branch=yes
9662862f5301Smrg		  eval cmd=\"$cmd1\"
9663862f5301Smrg		  func_len " $cmd"
9664862f5301Smrg		  len=$func_len_result
9665862f5301Smrg		  ;;
9666862f5301Smrg		*)
9667862f5301Smrg		  try_normal_branch=no
9668862f5301Smrg		  ;;
9669862f5301Smrg	      esac
96706fc0178dSmrg	      if test yes = "$try_normal_branch" \
9671862f5301Smrg		 && { test "$len" -lt "$max_cmd_len" \
9672862f5301Smrg		      || test "$max_cmd_len" -le -1; }
9673862f5301Smrg	      then
9674862f5301Smrg		func_show_eval "$cmd" 'exit $?'
9675862f5301Smrg		skipped_export=false
9676862f5301Smrg	      elif test -n "$nm_file_list_spec"; then
9677862f5301Smrg		func_basename "$output"
9678862f5301Smrg		output_la=$func_basename_result
9679862f5301Smrg		save_libobjs=$libobjs
9680862f5301Smrg		save_output=$output
96816fc0178dSmrg		output=$output_objdir/$output_la.nm
9682862f5301Smrg		func_to_tool_file "$output"
9683862f5301Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9684862f5301Smrg		func_append delfiles " $output"
9685862f5301Smrg		func_verbose "creating $NM input file list: $output"
9686862f5301Smrg		for obj in $save_libobjs; do
9687862f5301Smrg		  func_to_tool_file "$obj"
9688862f5301Smrg		  $ECHO "$func_to_tool_file_result"
9689862f5301Smrg		done > "$output"
9690862f5301Smrg		eval cmd=\"$cmd1\"
96917a3b38f7Smrg		func_show_eval "$cmd" 'exit $?'
9692862f5301Smrg		output=$save_output
9693862f5301Smrg		libobjs=$save_libobjs
96947a3b38f7Smrg		skipped_export=false
96957a3b38f7Smrg	      else
96967a3b38f7Smrg		# The command line is too long to execute in one step.
96977a3b38f7Smrg		func_verbose "using reloadable object file for export list..."
96987a3b38f7Smrg		skipped_export=:
96997a3b38f7Smrg		# Break out early, otherwise skipped_export may be
97007a3b38f7Smrg		# set to false by a later but shorter cmd.
97017a3b38f7Smrg		break
97027a3b38f7Smrg	      fi
97037a3b38f7Smrg	    done
97046fc0178dSmrg	    IFS=$save_ifs
97056fc0178dSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
97067a3b38f7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
97077a3b38f7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
97087a3b38f7Smrg	    fi
97097a3b38f7Smrg	  fi
97107a3b38f7Smrg	fi
9711ff559fabSmrg
97127a3b38f7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
97136fc0178dSmrg	  tmp_export_symbols=$export_symbols
97146fc0178dSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
971544dda7b2Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
97167a3b38f7Smrg	fi
9717ff559fabSmrg
97186fc0178dSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
97197a3b38f7Smrg	  # The given exports_symbols file has to be filtered, so filter it.
97206fc0178dSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
97217a3b38f7Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
97226fc0178dSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
97237a3b38f7Smrg	  # though. Also, the filter scales superlinearly with the number of
97247a3b38f7Smrg	  # global variables. join(1) would be nice here, but unfortunately
97257a3b38f7Smrg	  # isn't a blessed tool.
97267a3b38f7Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
9727862f5301Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
97287a3b38f7Smrg	  export_symbols=$output_objdir/$libname.def
97297a3b38f7Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9730ff559fabSmrg	fi
9731ff559fabSmrg
97327a3b38f7Smrg	tmp_deplibs=
97337a3b38f7Smrg	for test_deplib in $deplibs; do
97347a3b38f7Smrg	  case " $convenience " in
97357a3b38f7Smrg	  *" $test_deplib "*) ;;
97367a3b38f7Smrg	  *)
9737862f5301Smrg	    func_append tmp_deplibs " $test_deplib"
97387a3b38f7Smrg	    ;;
97397a3b38f7Smrg	  esac
97407a3b38f7Smrg	done
97416fc0178dSmrg	deplibs=$tmp_deplibs
9742ff559fabSmrg
97437a3b38f7Smrg	if test -n "$convenience"; then
97447a3b38f7Smrg	  if test -n "$whole_archive_flag_spec" &&
97456fc0178dSmrg	    test yes = "$compiler_needs_object" &&
97467a3b38f7Smrg	    test -z "$libobjs"; then
97477a3b38f7Smrg	    # extract the archives, so we have objects to list.
97487a3b38f7Smrg	    # TODO: could optimize this to just extract one archive.
97497a3b38f7Smrg	    whole_archive_flag_spec=
97507a3b38f7Smrg	  fi
97517a3b38f7Smrg	  if test -n "$whole_archive_flag_spec"; then
97527a3b38f7Smrg	    save_libobjs=$libobjs
97537a3b38f7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
97547a3b38f7Smrg	    test "X$libobjs" = "X " && libobjs=
97557a3b38f7Smrg	  else
97566fc0178dSmrg	    gentop=$output_objdir/${outputname}x
9757862f5301Smrg	    func_append generated " $gentop"
9758ff559fabSmrg
97597a3b38f7Smrg	    func_extract_archives $gentop $convenience
9760862f5301Smrg	    func_append libobjs " $func_extract_archives_result"
97617a3b38f7Smrg	    test "X$libobjs" = "X " && libobjs=
97627a3b38f7Smrg	  fi
97637a3b38f7Smrg	fi
9764ff559fabSmrg
97656fc0178dSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
97667a3b38f7Smrg	  eval flag=\"$thread_safe_flag_spec\"
9767862f5301Smrg	  func_append linker_flags " $flag"
97687a3b38f7Smrg	fi
9769ff559fabSmrg
97707a3b38f7Smrg	# Make a backup of the uninstalled library when relinking
97716fc0178dSmrg	if test relink = "$opt_mode"; then
97727a3b38f7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
9773ff559fabSmrg	fi
9774ff559fabSmrg
97757a3b38f7Smrg	# Do each of the archive commands.
97766fc0178dSmrg	if test yes = "$module" && test -n "$module_cmds"; then
97777a3b38f7Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
97787a3b38f7Smrg	    eval test_cmds=\"$module_expsym_cmds\"
97797a3b38f7Smrg	    cmds=$module_expsym_cmds
97807a3b38f7Smrg	  else
97817a3b38f7Smrg	    eval test_cmds=\"$module_cmds\"
97827a3b38f7Smrg	    cmds=$module_cmds
97837a3b38f7Smrg	  fi
97847a3b38f7Smrg	else
97857a3b38f7Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
97867a3b38f7Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
97877a3b38f7Smrg	    cmds=$archive_expsym_cmds
97887a3b38f7Smrg	  else
97897a3b38f7Smrg	    eval test_cmds=\"$archive_cmds\"
97907a3b38f7Smrg	    cmds=$archive_cmds
97917a3b38f7Smrg	  fi
9792ff559fabSmrg	fi
9793ff559fabSmrg
97946fc0178dSmrg	if test : != "$skipped_export" &&
97957a3b38f7Smrg	   func_len " $test_cmds" &&
97967a3b38f7Smrg	   len=$func_len_result &&
97977a3b38f7Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
97987a3b38f7Smrg	  :
97997a3b38f7Smrg	else
98007a3b38f7Smrg	  # The command line is too long to link in one step, link piecewise
98017a3b38f7Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
98027a3b38f7Smrg	  # script.
9803ff559fabSmrg
98047a3b38f7Smrg	  # Save the value of $output and $libobjs because we want to
98057a3b38f7Smrg	  # use them later.  If we have whole_archive_flag_spec, we
98067a3b38f7Smrg	  # want to use save_libobjs as it was before
98077a3b38f7Smrg	  # whole_archive_flag_spec was expanded, because we can't
98087a3b38f7Smrg	  # assume the linker understands whole_archive_flag_spec.
98097a3b38f7Smrg	  # This may have to be revisited, in case too many
98107a3b38f7Smrg	  # convenience libraries get linked in and end up exceeding
98117a3b38f7Smrg	  # the spec.
98127a3b38f7Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
98137a3b38f7Smrg	    save_libobjs=$libobjs
98147a3b38f7Smrg	  fi
98157a3b38f7Smrg	  save_output=$output
981644dda7b2Smrg	  func_basename "$output"
981744dda7b2Smrg	  output_la=$func_basename_result
9818ff559fabSmrg
98197a3b38f7Smrg	  # Clear the reloadable object creation command queue and
98207a3b38f7Smrg	  # initialize k to one.
98217a3b38f7Smrg	  test_cmds=
98227a3b38f7Smrg	  concat_cmds=
98237a3b38f7Smrg	  objlist=
98247a3b38f7Smrg	  last_robj=
98257a3b38f7Smrg	  k=1
9826ff559fabSmrg
98276fc0178dSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
98286fc0178dSmrg	    output=$output_objdir/$output_la.lnkscript
98297a3b38f7Smrg	    func_verbose "creating GNU ld script: $output"
983044dda7b2Smrg	    echo 'INPUT (' > $output
98317a3b38f7Smrg	    for obj in $save_libobjs
98327a3b38f7Smrg	    do
9833862f5301Smrg	      func_to_tool_file "$obj"
9834862f5301Smrg	      $ECHO "$func_to_tool_file_result" >> $output
98357a3b38f7Smrg	    done
983644dda7b2Smrg	    echo ')' >> $output
9837862f5301Smrg	    func_append delfiles " $output"
9838862f5301Smrg	    func_to_tool_file "$output"
9839862f5301Smrg	    output=$func_to_tool_file_result
98406fc0178dSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
98416fc0178dSmrg	    output=$output_objdir/$output_la.lnk
98427a3b38f7Smrg	    func_verbose "creating linker input file list: $output"
98437a3b38f7Smrg	    : > $output
98447a3b38f7Smrg	    set x $save_libobjs
98457a3b38f7Smrg	    shift
98467a3b38f7Smrg	    firstobj=
98476fc0178dSmrg	    if test yes = "$compiler_needs_object"; then
98487a3b38f7Smrg	      firstobj="$1 "
98497a3b38f7Smrg	      shift
98507a3b38f7Smrg	    fi
98517a3b38f7Smrg	    for obj
98527a3b38f7Smrg	    do
9853862f5301Smrg	      func_to_tool_file "$obj"
9854862f5301Smrg	      $ECHO "$func_to_tool_file_result" >> $output
98557a3b38f7Smrg	    done
9856862f5301Smrg	    func_append delfiles " $output"
9857862f5301Smrg	    func_to_tool_file "$output"
9858862f5301Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
98597a3b38f7Smrg	  else
98607a3b38f7Smrg	    if test -n "$save_libobjs"; then
98617a3b38f7Smrg	      func_verbose "creating reloadable object files..."
98626fc0178dSmrg	      output=$output_objdir/$output_la-$k.$objext
98637a3b38f7Smrg	      eval test_cmds=\"$reload_cmds\"
98647a3b38f7Smrg	      func_len " $test_cmds"
98657a3b38f7Smrg	      len0=$func_len_result
98667a3b38f7Smrg	      len=$len0
98677a3b38f7Smrg
98687a3b38f7Smrg	      # Loop over the list of objects to be linked.
98697a3b38f7Smrg	      for obj in $save_libobjs
98707a3b38f7Smrg	      do
98717a3b38f7Smrg		func_len " $obj"
98727a3b38f7Smrg		func_arith $len + $func_len_result
98737a3b38f7Smrg		len=$func_arith_result
98746fc0178dSmrg		if test -z "$objlist" ||
98757a3b38f7Smrg		   test "$len" -lt "$max_cmd_len"; then
98767a3b38f7Smrg		  func_append objlist " $obj"
98777a3b38f7Smrg		else
98787a3b38f7Smrg		  # The command $test_cmds is almost too long, add a
98797a3b38f7Smrg		  # command to the queue.
98806fc0178dSmrg		  if test 1 -eq "$k"; then
98817a3b38f7Smrg		    # The first file doesn't have a previous command to add.
988244dda7b2Smrg		    reload_objs=$objlist
988344dda7b2Smrg		    eval concat_cmds=\"$reload_cmds\"
98847a3b38f7Smrg		  else
98857a3b38f7Smrg		    # All subsequent reloadable object files will link in
98867a3b38f7Smrg		    # the last one created.
988744dda7b2Smrg		    reload_objs="$objlist $last_robj"
988844dda7b2Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
98897a3b38f7Smrg		  fi
98906fc0178dSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
98917a3b38f7Smrg		  func_arith $k + 1
98927a3b38f7Smrg		  k=$func_arith_result
98936fc0178dSmrg		  output=$output_objdir/$output_la-$k.$objext
989444dda7b2Smrg		  objlist=" $obj"
98957a3b38f7Smrg		  func_len " $last_robj"
98967a3b38f7Smrg		  func_arith $len0 + $func_len_result
98977a3b38f7Smrg		  len=$func_arith_result
98987a3b38f7Smrg		fi
98997a3b38f7Smrg	      done
99007a3b38f7Smrg	      # Handle the remaining objects by creating one last
99017a3b38f7Smrg	      # reloadable object file.  All subsequent reloadable object
99027a3b38f7Smrg	      # files will link in the last one created.
99037a3b38f7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
990444dda7b2Smrg	      reload_objs="$objlist $last_robj"
99056fc0178dSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
99067a3b38f7Smrg	      if test -n "$last_robj"; then
99076fc0178dSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
99087a3b38f7Smrg	      fi
9909862f5301Smrg	      func_append delfiles " $output"
9910ff559fabSmrg
99117a3b38f7Smrg	    else
99127a3b38f7Smrg	      output=
99137a3b38f7Smrg	    fi
9914ff559fabSmrg
99156fc0178dSmrg	    ${skipped_export-false} && {
99166fc0178dSmrg	      func_verbose "generating symbol list for '$libname.la'"
99176fc0178dSmrg	      export_symbols=$output_objdir/$libname.exp
99187a3b38f7Smrg	      $opt_dry_run || $RM $export_symbols
99197a3b38f7Smrg	      libobjs=$output
99207a3b38f7Smrg	      # Append the command to create the export file.
99217a3b38f7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
99227a3b38f7Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
99237a3b38f7Smrg	      if test -n "$last_robj"; then
99247a3b38f7Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
99257a3b38f7Smrg	      fi
99266fc0178dSmrg	    }
9927ff559fabSmrg
99287a3b38f7Smrg	    test -n "$save_libobjs" &&
99297a3b38f7Smrg	      func_verbose "creating a temporary reloadable object file: $output"
9930ff559fabSmrg
99317a3b38f7Smrg	    # Loop through the commands generated above and execute them.
99326fc0178dSmrg	    save_ifs=$IFS; IFS='~'
99337a3b38f7Smrg	    for cmd in $concat_cmds; do
99346fc0178dSmrg	      IFS=$save_ifs
99356fc0178dSmrg	      $opt_quiet || {
99367a3b38f7Smrg		  func_quote_for_expand "$cmd"
99377a3b38f7Smrg		  eval "func_echo $func_quote_for_expand_result"
99387a3b38f7Smrg	      }
99397a3b38f7Smrg	      $opt_dry_run || eval "$cmd" || {
99407a3b38f7Smrg		lt_exit=$?
99417a3b38f7Smrg
99427a3b38f7Smrg		# Restore the uninstalled library and exit
99436fc0178dSmrg		if test relink = "$opt_mode"; then
99447a3b38f7Smrg		  ( cd "$output_objdir" && \
99457a3b38f7Smrg		    $RM "${realname}T" && \
99467a3b38f7Smrg		    $MV "${realname}U" "$realname" )
99477a3b38f7Smrg		fi
9948ff559fabSmrg
99497a3b38f7Smrg		exit $lt_exit
99507a3b38f7Smrg	      }
99517a3b38f7Smrg	    done
99526fc0178dSmrg	    IFS=$save_ifs
99537a3b38f7Smrg
99547a3b38f7Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
99557a3b38f7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99567a3b38f7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9957ff559fabSmrg	    fi
9958ff559fabSmrg	  fi
9959ff559fabSmrg
99606fc0178dSmrg          ${skipped_export-false} && {
99617a3b38f7Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
99626fc0178dSmrg	      tmp_export_symbols=$export_symbols
99636fc0178dSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
996444dda7b2Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
99657a3b38f7Smrg	    fi
9966ff559fabSmrg
99677a3b38f7Smrg	    if test -n "$orig_export_symbols"; then
99687a3b38f7Smrg	      # The given exports_symbols file has to be filtered, so filter it.
99696fc0178dSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
99707a3b38f7Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
99716fc0178dSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
99727a3b38f7Smrg	      # though. Also, the filter scales superlinearly with the number of
99737a3b38f7Smrg	      # global variables. join(1) would be nice here, but unfortunately
99747a3b38f7Smrg	      # isn't a blessed tool.
99757a3b38f7Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
9976862f5301Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
99777a3b38f7Smrg	      export_symbols=$output_objdir/$libname.def
99787a3b38f7Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
99797a3b38f7Smrg	    fi
99806fc0178dSmrg	  }
9981ff559fabSmrg
99827a3b38f7Smrg	  libobjs=$output
99837a3b38f7Smrg	  # Restore the value of output.
99847a3b38f7Smrg	  output=$save_output
9985ff559fabSmrg
99867a3b38f7Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
99877a3b38f7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
99887a3b38f7Smrg	    test "X$libobjs" = "X " && libobjs=
99897a3b38f7Smrg	  fi
99907a3b38f7Smrg	  # Expand the library linking commands again to reset the
99917a3b38f7Smrg	  # value of $libobjs for piecewise linking.
99927a3b38f7Smrg
99937a3b38f7Smrg	  # Do each of the archive commands.
99946fc0178dSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
99957a3b38f7Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
99967a3b38f7Smrg	      cmds=$module_expsym_cmds
9997ff559fabSmrg	    else
99987a3b38f7Smrg	      cmds=$module_cmds
9999ff559fabSmrg	    fi
10000ff559fabSmrg	  else
100017a3b38f7Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100027a3b38f7Smrg	      cmds=$archive_expsym_cmds
100037a3b38f7Smrg	    else
100047a3b38f7Smrg	      cmds=$archive_cmds
100057a3b38f7Smrg	    fi
10006ff559fabSmrg	  fi
10007ff559fabSmrg	fi
10008ff559fabSmrg
100097a3b38f7Smrg	if test -n "$delfiles"; then
100107a3b38f7Smrg	  # Append the command to remove temporary files to $cmds.
100117a3b38f7Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
100127a3b38f7Smrg	fi
10013ff559fabSmrg
100147a3b38f7Smrg	# Add any objects from preloaded convenience libraries
100157a3b38f7Smrg	if test -n "$dlprefiles"; then
100166fc0178dSmrg	  gentop=$output_objdir/${outputname}x
10017862f5301Smrg	  func_append generated " $gentop"
10018ff559fabSmrg
100197a3b38f7Smrg	  func_extract_archives $gentop $dlprefiles
10020862f5301Smrg	  func_append libobjs " $func_extract_archives_result"
100217a3b38f7Smrg	  test "X$libobjs" = "X " && libobjs=
10022ff559fabSmrg	fi
10023ff559fabSmrg
100246fc0178dSmrg	save_ifs=$IFS; IFS='~'
100257a3b38f7Smrg	for cmd in $cmds; do
100266fc0178dSmrg	  IFS=$sp$nl
100277a3b38f7Smrg	  eval cmd=\"$cmd\"
100286fc0178dSmrg	  IFS=$save_ifs
100296fc0178dSmrg	  $opt_quiet || {
100307a3b38f7Smrg	    func_quote_for_expand "$cmd"
100317a3b38f7Smrg	    eval "func_echo $func_quote_for_expand_result"
100327a3b38f7Smrg	  }
100337a3b38f7Smrg	  $opt_dry_run || eval "$cmd" || {
100347a3b38f7Smrg	    lt_exit=$?
10035ff559fabSmrg
100367a3b38f7Smrg	    # Restore the uninstalled library and exit
100376fc0178dSmrg	    if test relink = "$opt_mode"; then
100387a3b38f7Smrg	      ( cd "$output_objdir" && \
100397a3b38f7Smrg	        $RM "${realname}T" && \
100407a3b38f7Smrg		$MV "${realname}U" "$realname" )
100417a3b38f7Smrg	    fi
100427a3b38f7Smrg
100437a3b38f7Smrg	    exit $lt_exit
100447a3b38f7Smrg	  }
100457a3b38f7Smrg	done
100466fc0178dSmrg	IFS=$save_ifs
100477a3b38f7Smrg
100487a3b38f7Smrg	# Restore the uninstalled library and exit
100496fc0178dSmrg	if test relink = "$opt_mode"; then
100507a3b38f7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
100517a3b38f7Smrg
100527a3b38f7Smrg	  if test -n "$convenience"; then
100537a3b38f7Smrg	    if test -z "$whole_archive_flag_spec"; then
100547a3b38f7Smrg	      func_show_eval '${RM}r "$gentop"'
10055ff559fabSmrg	    fi
10056ff559fabSmrg	  fi
10057ff559fabSmrg
100587a3b38f7Smrg	  exit $EXIT_SUCCESS
100597a3b38f7Smrg	fi
10060ff559fabSmrg
100617a3b38f7Smrg	# Create links to the real library.
100627a3b38f7Smrg	for linkname in $linknames; do
100637a3b38f7Smrg	  if test "$realname" != "$linkname"; then
100647a3b38f7Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
100657a3b38f7Smrg	  fi
100667a3b38f7Smrg	done
100677a3b38f7Smrg
100687a3b38f7Smrg	# If -module or -export-dynamic was specified, set the dlname.
100696fc0178dSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
100707a3b38f7Smrg	  # On all known operating systems, these are identical.
100716fc0178dSmrg	  dlname=$soname
100727a3b38f7Smrg	fi
100737a3b38f7Smrg      fi
100747a3b38f7Smrg      ;;
100757a3b38f7Smrg
100767a3b38f7Smrg    obj)
100776fc0178dSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
100786fc0178dSmrg	func_warning "'-dlopen' is ignored for objects"
100797a3b38f7Smrg      fi
100807a3b38f7Smrg
100817a3b38f7Smrg      case " $deplibs" in
100827a3b38f7Smrg      *\ -l* | *\ -L*)
100836fc0178dSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
100847a3b38f7Smrg      esac
100857a3b38f7Smrg
100867a3b38f7Smrg      test -n "$rpath" && \
100876fc0178dSmrg	func_warning "'-rpath' is ignored for objects"
100887a3b38f7Smrg
100897a3b38f7Smrg      test -n "$xrpath" && \
100906fc0178dSmrg	func_warning "'-R' is ignored for objects"
100917a3b38f7Smrg
100927a3b38f7Smrg      test -n "$vinfo" && \
100936fc0178dSmrg	func_warning "'-version-info' is ignored for objects"
100947a3b38f7Smrg
100957a3b38f7Smrg      test -n "$release" && \
100966fc0178dSmrg	func_warning "'-release' is ignored for objects"
100977a3b38f7Smrg
100987a3b38f7Smrg      case $output in
100997a3b38f7Smrg      *.lo)
101007a3b38f7Smrg	test -n "$objs$old_deplibs" && \
101016fc0178dSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
101027a3b38f7Smrg
101037a3b38f7Smrg	libobj=$output
101047a3b38f7Smrg	func_lo2o "$libobj"
101057a3b38f7Smrg	obj=$func_lo2o_result
101067a3b38f7Smrg	;;
101077a3b38f7Smrg      *)
101087a3b38f7Smrg	libobj=
101096fc0178dSmrg	obj=$output
101107a3b38f7Smrg	;;
101117a3b38f7Smrg      esac
101127a3b38f7Smrg
101137a3b38f7Smrg      # Delete the old objects.
101147a3b38f7Smrg      $opt_dry_run || $RM $obj $libobj
101157a3b38f7Smrg
101167a3b38f7Smrg      # Objects from convenience libraries.  This assumes
101177a3b38f7Smrg      # single-version convenience libraries.  Whenever we create
101187a3b38f7Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
101197a3b38f7Smrg      # the extraction.
101207a3b38f7Smrg      reload_conv_objs=
101217a3b38f7Smrg      gentop=
101226fc0178dSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
101236fc0178dSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
101246fc0178dSmrg      # into space.
101256fc0178dSmrg      case $reload_cmds in
101266fc0178dSmrg        *\$LD[\ \$]*) wl= ;;
101276fc0178dSmrg      esac
101287a3b38f7Smrg      if test -n "$convenience"; then
101297a3b38f7Smrg	if test -n "$whole_archive_flag_spec"; then
101307a3b38f7Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
101316fc0178dSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
101326fc0178dSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
101337a3b38f7Smrg	else
101346fc0178dSmrg	  gentop=$output_objdir/${obj}x
10135862f5301Smrg	  func_append generated " $gentop"
101367a3b38f7Smrg
101377a3b38f7Smrg	  func_extract_archives $gentop $convenience
101387a3b38f7Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
101397a3b38f7Smrg	fi
101407a3b38f7Smrg      fi
10141ff559fabSmrg
10142862f5301Smrg      # If we're not building shared, we need to use non_pic_objs
101436fc0178dSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10144862f5301Smrg
101457a3b38f7Smrg      # Create the old-style object.
101466fc0178dSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10147ff559fabSmrg
101486fc0178dSmrg      output=$obj
101497a3b38f7Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10150ff559fabSmrg
101517a3b38f7Smrg      # Exit if we aren't doing a library object file.
101527a3b38f7Smrg      if test -z "$libobj"; then
101537a3b38f7Smrg	if test -n "$gentop"; then
101547a3b38f7Smrg	  func_show_eval '${RM}r "$gentop"'
101557a3b38f7Smrg	fi
10156ff559fabSmrg
101577a3b38f7Smrg	exit $EXIT_SUCCESS
101587a3b38f7Smrg      fi
10159ff559fabSmrg
101606fc0178dSmrg      test yes = "$build_libtool_libs" || {
101617a3b38f7Smrg	if test -n "$gentop"; then
101627a3b38f7Smrg	  func_show_eval '${RM}r "$gentop"'
101637a3b38f7Smrg	fi
10164ff559fabSmrg
101657a3b38f7Smrg	# Create an invalid libtool object if no PIC, so that we don't
101667a3b38f7Smrg	# accidentally link it into a program.
101677a3b38f7Smrg	# $show "echo timestamp > $libobj"
101687a3b38f7Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
101697a3b38f7Smrg	exit $EXIT_SUCCESS
101706fc0178dSmrg      }
10171ff559fabSmrg
101726fc0178dSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
101737a3b38f7Smrg	# Only do commands if we really have different PIC objects.
101747a3b38f7Smrg	reload_objs="$libobjs $reload_conv_objs"
101756fc0178dSmrg	output=$libobj
101767a3b38f7Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10177ff559fabSmrg      fi
10178ff559fabSmrg
101797a3b38f7Smrg      if test -n "$gentop"; then
101807a3b38f7Smrg	func_show_eval '${RM}r "$gentop"'
101817a3b38f7Smrg      fi
10182ff559fabSmrg
101837a3b38f7Smrg      exit $EXIT_SUCCESS
101847a3b38f7Smrg      ;;
10185ff559fabSmrg
101867a3b38f7Smrg    prog)
101877a3b38f7Smrg      case $host in
101887a3b38f7Smrg	*cygwin*) func_stripname '' '.exe' "$output"
101897a3b38f7Smrg	          output=$func_stripname_result.exe;;
10190ff559fabSmrg      esac
101917a3b38f7Smrg      test -n "$vinfo" && \
101926fc0178dSmrg	func_warning "'-version-info' is ignored for programs"
10193ff559fabSmrg
101947a3b38f7Smrg      test -n "$release" && \
101956fc0178dSmrg	func_warning "'-release' is ignored for programs"
10196ff559fabSmrg
101976fc0178dSmrg      $preload \
101986fc0178dSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
101996fc0178dSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10200ff559fabSmrg
102017a3b38f7Smrg      case $host in
102027a3b38f7Smrg      *-*-rhapsody* | *-*-darwin1.[012])
102037a3b38f7Smrg	# On Rhapsody replace the C library is the System framework
1020444dda7b2Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1020544dda7b2Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10206ff559fabSmrg	;;
10207ff559fabSmrg      esac
10208ff559fabSmrg
102097a3b38f7Smrg      case $host in
102107a3b38f7Smrg      *-*-darwin*)
102117a3b38f7Smrg	# Don't allow lazy linking, it breaks C++ global constructors
102127a3b38f7Smrg	# But is supposedly fixed on 10.4 or later (yay!).
102136fc0178dSmrg	if test CXX = "$tagname"; then
102147a3b38f7Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
102157a3b38f7Smrg	    10.[0123])
102166fc0178dSmrg	      func_append compile_command " $wl-bind_at_load"
102176fc0178dSmrg	      func_append finalize_command " $wl-bind_at_load"
102187a3b38f7Smrg	    ;;
102197a3b38f7Smrg	  esac
102207a3b38f7Smrg	fi
102217a3b38f7Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1022244dda7b2Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1022344dda7b2Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10224ff559fabSmrg	;;
10225ff559fabSmrg      esac
10226ff559fabSmrg
10227ff559fabSmrg
102287a3b38f7Smrg      # move library search paths that coincide with paths to not yet
102297a3b38f7Smrg      # installed libraries to the beginning of the library search list
102307a3b38f7Smrg      new_libs=
102317a3b38f7Smrg      for path in $notinst_path; do
102327a3b38f7Smrg	case " $new_libs " in
102337a3b38f7Smrg	*" -L$path/$objdir "*) ;;
10234ff559fabSmrg	*)
102357a3b38f7Smrg	  case " $compile_deplibs " in
102367a3b38f7Smrg	  *" -L$path/$objdir "*)
10237862f5301Smrg	    func_append new_libs " -L$path/$objdir" ;;
102387a3b38f7Smrg	  esac
10239ff559fabSmrg	  ;;
10240ff559fabSmrg	esac
10241ff559fabSmrg      done
102427a3b38f7Smrg      for deplib in $compile_deplibs; do
102437a3b38f7Smrg	case $deplib in
102447a3b38f7Smrg	-L*)
102457a3b38f7Smrg	  case " $new_libs " in
102467a3b38f7Smrg	  *" $deplib "*) ;;
10247862f5301Smrg	  *) func_append new_libs " $deplib" ;;
102487a3b38f7Smrg	  esac
102497a3b38f7Smrg	  ;;
10250862f5301Smrg	*) func_append new_libs " $deplib" ;;
102517a3b38f7Smrg	esac
102527a3b38f7Smrg      done
102536fc0178dSmrg      compile_deplibs=$new_libs
10254ff559fabSmrg
10255ff559fabSmrg
10256862f5301Smrg      func_append compile_command " $compile_deplibs"
10257862f5301Smrg      func_append finalize_command " $finalize_deplibs"
10258ff559fabSmrg
102597a3b38f7Smrg      if test -n "$rpath$xrpath"; then
102607a3b38f7Smrg	# If the user specified any rpath flags, then add them.
102617a3b38f7Smrg	for libdir in $rpath $xrpath; do
102627a3b38f7Smrg	  # This is the magic to use -rpath.
102637a3b38f7Smrg	  case "$finalize_rpath " in
102647a3b38f7Smrg	  *" $libdir "*) ;;
10265862f5301Smrg	  *) func_append finalize_rpath " $libdir" ;;
102667a3b38f7Smrg	  esac
102677a3b38f7Smrg	done
102687a3b38f7Smrg      fi
10269ff559fabSmrg
102707a3b38f7Smrg      # Now hardcode the library paths
102717a3b38f7Smrg      rpath=
102727a3b38f7Smrg      hardcode_libdirs=
102737a3b38f7Smrg      for libdir in $compile_rpath $finalize_rpath; do
102747a3b38f7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
102757a3b38f7Smrg	  if test -n "$hardcode_libdir_separator"; then
102767a3b38f7Smrg	    if test -z "$hardcode_libdirs"; then
102776fc0178dSmrg	      hardcode_libdirs=$libdir
102787a3b38f7Smrg	    else
102797a3b38f7Smrg	      # Just accumulate the unique libdirs.
102807a3b38f7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
102817a3b38f7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
102827a3b38f7Smrg		;;
102837a3b38f7Smrg	      *)
10284862f5301Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
102857a3b38f7Smrg		;;
102867a3b38f7Smrg	      esac
102877a3b38f7Smrg	    fi
102887a3b38f7Smrg	  else
102897a3b38f7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10290862f5301Smrg	    func_append rpath " $flag"
102917a3b38f7Smrg	  fi
102927a3b38f7Smrg	elif test -n "$runpath_var"; then
102937a3b38f7Smrg	  case "$perm_rpath " in
10294ff559fabSmrg	  *" $libdir "*) ;;
10295862f5301Smrg	  *) func_append perm_rpath " $libdir" ;;
10296ff559fabSmrg	  esac
102977a3b38f7Smrg	fi
102987a3b38f7Smrg	case $host in
102997a3b38f7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
103006fc0178dSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
103017a3b38f7Smrg	  case :$dllsearchpath: in
103027a3b38f7Smrg	  *":$libdir:"*) ;;
103037a3b38f7Smrg	  ::) dllsearchpath=$libdir;;
10304862f5301Smrg	  *) func_append dllsearchpath ":$libdir";;
103057a3b38f7Smrg	  esac
103067a3b38f7Smrg	  case :$dllsearchpath: in
103077a3b38f7Smrg	  *":$testbindir:"*) ;;
103087a3b38f7Smrg	  ::) dllsearchpath=$testbindir;;
10309862f5301Smrg	  *) func_append dllsearchpath ":$testbindir";;
103107a3b38f7Smrg	  esac
103117a3b38f7Smrg	  ;;
103127a3b38f7Smrg	esac
103137a3b38f7Smrg      done
103147a3b38f7Smrg      # Substitute the hardcoded libdirs into the rpath.
103157a3b38f7Smrg      if test -n "$hardcode_libdir_separator" &&
103167a3b38f7Smrg	 test -n "$hardcode_libdirs"; then
103176fc0178dSmrg	libdir=$hardcode_libdirs
103187a3b38f7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
103197a3b38f7Smrg      fi
103206fc0178dSmrg      compile_rpath=$rpath
103217a3b38f7Smrg
103227a3b38f7Smrg      rpath=
103237a3b38f7Smrg      hardcode_libdirs=
103247a3b38f7Smrg      for libdir in $finalize_rpath; do
103257a3b38f7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
103267a3b38f7Smrg	  if test -n "$hardcode_libdir_separator"; then
103277a3b38f7Smrg	    if test -z "$hardcode_libdirs"; then
103286fc0178dSmrg	      hardcode_libdirs=$libdir
103297a3b38f7Smrg	    else
103307a3b38f7Smrg	      # Just accumulate the unique libdirs.
103317a3b38f7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
103327a3b38f7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
103337a3b38f7Smrg		;;
103347a3b38f7Smrg	      *)
10335862f5301Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
103367a3b38f7Smrg		;;
103377a3b38f7Smrg	      esac
103387a3b38f7Smrg	    fi
103397a3b38f7Smrg	  else
103407a3b38f7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10341862f5301Smrg	    func_append rpath " $flag"
103427a3b38f7Smrg	  fi
103437a3b38f7Smrg	elif test -n "$runpath_var"; then
103447a3b38f7Smrg	  case "$finalize_perm_rpath " in
10345ff559fabSmrg	  *" $libdir "*) ;;
10346862f5301Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10347ff559fabSmrg	  esac
10348ff559fabSmrg	fi
103497a3b38f7Smrg      done
103507a3b38f7Smrg      # Substitute the hardcoded libdirs into the rpath.
103517a3b38f7Smrg      if test -n "$hardcode_libdir_separator" &&
103527a3b38f7Smrg	 test -n "$hardcode_libdirs"; then
103536fc0178dSmrg	libdir=$hardcode_libdirs
103547a3b38f7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
103557a3b38f7Smrg      fi
103566fc0178dSmrg      finalize_rpath=$rpath
10357ff559fabSmrg
103586fc0178dSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
103597a3b38f7Smrg	# Transform all the library objects into standard objects.
1036044dda7b2Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1036144dda7b2Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
103627a3b38f7Smrg      fi
10363ff559fabSmrg
103646fc0178dSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10365ff559fabSmrg
103667a3b38f7Smrg      # template prelinking step
103677a3b38f7Smrg      if test -n "$prelink_cmds"; then
103687a3b38f7Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
103697a3b38f7Smrg      fi
10370ff559fabSmrg
103716fc0178dSmrg      wrappers_required=:
103727a3b38f7Smrg      case $host in
1037344dda7b2Smrg      *cegcc* | *mingw32ce*)
1037444dda7b2Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
103756fc0178dSmrg        wrappers_required=false
1037644dda7b2Smrg        ;;
103777a3b38f7Smrg      *cygwin* | *mingw* )
103786fc0178dSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
103797a3b38f7Smrg        ;;
103807a3b38f7Smrg      *)
103816fc0178dSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
103826fc0178dSmrg          wrappers_required=false
103837a3b38f7Smrg        fi
103847a3b38f7Smrg        ;;
103857a3b38f7Smrg      esac
103866fc0178dSmrg      $wrappers_required || {
103877a3b38f7Smrg	# Replace the output file specification.
1038844dda7b2Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
103896fc0178dSmrg	link_command=$compile_command$compile_rpath
10390ff559fabSmrg
103917a3b38f7Smrg	# We have no uninstalled library dependencies, so finalize right now.
103927a3b38f7Smrg	exit_status=0
103937a3b38f7Smrg	func_show_eval "$link_command" 'exit_status=$?'
10394ff559fabSmrg
10395862f5301Smrg	if test -n "$postlink_cmds"; then
10396862f5301Smrg	  func_to_tool_file "$output"
10397862f5301Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10398862f5301Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10399862f5301Smrg	fi
10400862f5301Smrg
104017a3b38f7Smrg	# Delete the generated files.
104026fc0178dSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
104036fc0178dSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
104047a3b38f7Smrg	fi
10405ff559fabSmrg
104067a3b38f7Smrg	exit $exit_status
104076fc0178dSmrg      }
10408ff559fabSmrg
104097a3b38f7Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
104107a3b38f7Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
104117a3b38f7Smrg      fi
104127a3b38f7Smrg      if test -n "$finalize_shlibpath"; then
104137a3b38f7Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
104147a3b38f7Smrg      fi
10415ff559fabSmrg
104167a3b38f7Smrg      compile_var=
104177a3b38f7Smrg      finalize_var=
104187a3b38f7Smrg      if test -n "$runpath_var"; then
104197a3b38f7Smrg	if test -n "$perm_rpath"; then
104207a3b38f7Smrg	  # We should set the runpath_var.
104217a3b38f7Smrg	  rpath=
104227a3b38f7Smrg	  for dir in $perm_rpath; do
10423862f5301Smrg	    func_append rpath "$dir:"
10424ff559fabSmrg	  done
104257a3b38f7Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10426ff559fabSmrg	fi
104277a3b38f7Smrg	if test -n "$finalize_perm_rpath"; then
104287a3b38f7Smrg	  # We should set the runpath_var.
104297a3b38f7Smrg	  rpath=
104307a3b38f7Smrg	  for dir in $finalize_perm_rpath; do
10431862f5301Smrg	    func_append rpath "$dir:"
104327a3b38f7Smrg	  done
104337a3b38f7Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
104347a3b38f7Smrg	fi
104357a3b38f7Smrg      fi
10436ff559fabSmrg
104376fc0178dSmrg      if test yes = "$no_install"; then
104387a3b38f7Smrg	# We don't need to create a wrapper script.
104396fc0178dSmrg	link_command=$compile_var$compile_command$compile_rpath
104407a3b38f7Smrg	# Replace the output file specification.
1044144dda7b2Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
104427a3b38f7Smrg	# Delete the old output file.
104437a3b38f7Smrg	$opt_dry_run || $RM $output
104447a3b38f7Smrg	# Link the executable and exit
104457a3b38f7Smrg	func_show_eval "$link_command" 'exit $?'
10446862f5301Smrg
10447862f5301Smrg	if test -n "$postlink_cmds"; then
10448862f5301Smrg	  func_to_tool_file "$output"
10449862f5301Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10450862f5301Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10451862f5301Smrg	fi
10452862f5301Smrg
104537a3b38f7Smrg	exit $EXIT_SUCCESS
104547a3b38f7Smrg      fi
10455ff559fabSmrg
104566fc0178dSmrg      case $hardcode_action,$fast_install in
104576fc0178dSmrg        relink,*)
104586fc0178dSmrg	  # Fast installation is not supported
104596fc0178dSmrg	  link_command=$compile_var$compile_command$compile_rpath
104606fc0178dSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10461ff559fabSmrg
104626fc0178dSmrg	  func_warning "this platform does not like uninstalled shared libraries"
104636fc0178dSmrg	  func_warning "'$output' will be relinked during installation"
104646fc0178dSmrg	  ;;
104656fc0178dSmrg        *,yes)
104666fc0178dSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
104676fc0178dSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
104686fc0178dSmrg          ;;
104696fc0178dSmrg	*,no)
104706fc0178dSmrg	  link_command=$compile_var$compile_command$compile_rpath
104716fc0178dSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
104726fc0178dSmrg          ;;
104736fc0178dSmrg	*,needless)
104746fc0178dSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
104756fc0178dSmrg	  relink_command=
104766fc0178dSmrg          ;;
104776fc0178dSmrg      esac
10478ff559fabSmrg
104797a3b38f7Smrg      # Replace the output file specification.
1048044dda7b2Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10481ff559fabSmrg
104827a3b38f7Smrg      # Delete the old output files.
104837a3b38f7Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10484ff559fabSmrg
104857a3b38f7Smrg      func_show_eval "$link_command" 'exit $?'
10486ff559fabSmrg
10487862f5301Smrg      if test -n "$postlink_cmds"; then
10488862f5301Smrg	func_to_tool_file "$output_objdir/$outputname"
10489862f5301Smrg	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'`
10490862f5301Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10491862f5301Smrg      fi
10492862f5301Smrg
104937a3b38f7Smrg      # Now create the wrapper script.
104947a3b38f7Smrg      func_verbose "creating $output"
10495ff559fabSmrg
104967a3b38f7Smrg      # Quote the relink command for shipping.
104977a3b38f7Smrg      if test -n "$relink_command"; then
104987a3b38f7Smrg	# Preserve any variables that may affect compiler behavior
104997a3b38f7Smrg	for var in $variables_saved_for_relink; do
105007a3b38f7Smrg	  if eval test -z \"\${$var+set}\"; then
105017a3b38f7Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
105027a3b38f7Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
105037a3b38f7Smrg	    relink_command="$var=; export $var; $relink_command"
105047a3b38f7Smrg	  else
105057a3b38f7Smrg	    func_quote_for_eval "$var_value"
105067a3b38f7Smrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
105077a3b38f7Smrg	  fi
105087a3b38f7Smrg	done
105097a3b38f7Smrg	relink_command="(cd `pwd`; $relink_command)"
1051044dda7b2Smrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
105117a3b38f7Smrg      fi
10512ff559fabSmrg
105137a3b38f7Smrg      # Only actually do things if not in dry run mode.
105147a3b38f7Smrg      $opt_dry_run || {
105157a3b38f7Smrg	# win32 will think the script is a binary if it has
105167a3b38f7Smrg	# a .exe suffix, so we strip it off here.
105177a3b38f7Smrg	case $output in
105187a3b38f7Smrg	  *.exe) func_stripname '' '.exe' "$output"
105197a3b38f7Smrg	         output=$func_stripname_result ;;
105207a3b38f7Smrg	esac
105217a3b38f7Smrg	# test for cygwin because mv fails w/o .exe extensions
10522ff559fabSmrg	case $host in
105237a3b38f7Smrg	  *cygwin*)
105247a3b38f7Smrg	    exeext=.exe
105257a3b38f7Smrg	    func_stripname '' '.exe' "$outputname"
105267a3b38f7Smrg	    outputname=$func_stripname_result ;;
105277a3b38f7Smrg	  *) exeext= ;;
10528ff559fabSmrg	esac
105297a3b38f7Smrg	case $host in
105307a3b38f7Smrg	  *cygwin* | *mingw* )
105317a3b38f7Smrg	    func_dirname_and_basename "$output" "" "."
105327a3b38f7Smrg	    output_name=$func_basename_result
105337a3b38f7Smrg	    output_path=$func_dirname_result
105346fc0178dSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
105356fc0178dSmrg	    cwrapper=$output_path/$output_name.exe
105367a3b38f7Smrg	    $RM $cwrappersource $cwrapper
105377a3b38f7Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
105387a3b38f7Smrg
105397a3b38f7Smrg	    func_emit_cwrapperexe_src > $cwrappersource
105407a3b38f7Smrg
105417a3b38f7Smrg	    # The wrapper executable is built using the $host compiler,
105427a3b38f7Smrg	    # because it contains $host paths and files. If cross-
105437a3b38f7Smrg	    # compiling, it, like the target executable, must be
105447a3b38f7Smrg	    # executed on the $host or under an emulation environment.
105457a3b38f7Smrg	    $opt_dry_run || {
105467a3b38f7Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
105477a3b38f7Smrg	      $STRIP $cwrapper
105487a3b38f7Smrg	    }
10549ff559fabSmrg
105507a3b38f7Smrg	    # Now, create the wrapper script for func_source use:
105517a3b38f7Smrg	    func_ltwrapper_scriptname $cwrapper
105527a3b38f7Smrg	    $RM $func_ltwrapper_scriptname_result
105537a3b38f7Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
105547a3b38f7Smrg	    $opt_dry_run || {
105557a3b38f7Smrg	      # note: this script will not be executed, so do not chmod.
105566fc0178dSmrg	      if test "x$build" = "x$host"; then
105577a3b38f7Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10558ff559fabSmrg	      else
105597a3b38f7Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10560ff559fabSmrg	      fi
105617a3b38f7Smrg	    }
105627a3b38f7Smrg	  ;;
105637a3b38f7Smrg	  * )
105647a3b38f7Smrg	    $RM $output
105657a3b38f7Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10566ff559fabSmrg
105677a3b38f7Smrg	    func_emit_wrapper no > $output
105687a3b38f7Smrg	    chmod +x $output
10569ff559fabSmrg	  ;;
10570ff559fabSmrg	esac
105717a3b38f7Smrg      }
105727a3b38f7Smrg      exit $EXIT_SUCCESS
105737a3b38f7Smrg      ;;
105747a3b38f7Smrg    esac
10575ff559fabSmrg
105767a3b38f7Smrg    # See if we need to build an old-fashioned archive.
105777a3b38f7Smrg    for oldlib in $oldlibs; do
10578ff559fabSmrg
105796fc0178dSmrg      case $build_libtool_libs in
105806fc0178dSmrg        convenience)
105816fc0178dSmrg	  oldobjs="$libobjs_save $symfileobj"
105826fc0178dSmrg	  addlibs=$convenience
105837a3b38f7Smrg	  build_libtool_libs=no
105846fc0178dSmrg	  ;;
105856fc0178dSmrg	module)
105866fc0178dSmrg	  oldobjs=$libobjs_save
105876fc0178dSmrg	  addlibs=$old_convenience
105886fc0178dSmrg	  build_libtool_libs=no
105896fc0178dSmrg          ;;
105906fc0178dSmrg	*)
105917a3b38f7Smrg	  oldobjs="$old_deplibs $non_pic_objects"
105926fc0178dSmrg	  $preload && test -f "$symfileobj" \
105936fc0178dSmrg	    && func_append oldobjs " $symfileobj"
105946fc0178dSmrg	  addlibs=$old_convenience
105956fc0178dSmrg	  ;;
105966fc0178dSmrg      esac
10597ff559fabSmrg
105987a3b38f7Smrg      if test -n "$addlibs"; then
105996fc0178dSmrg	gentop=$output_objdir/${outputname}x
10600862f5301Smrg	func_append generated " $gentop"
10601ff559fabSmrg
106027a3b38f7Smrg	func_extract_archives $gentop $addlibs
10603862f5301Smrg	func_append oldobjs " $func_extract_archives_result"
106047a3b38f7Smrg      fi
10605ff559fabSmrg
106067a3b38f7Smrg      # Do each command in the archive commands.
106076fc0178dSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
106087a3b38f7Smrg	cmds=$old_archive_from_new_cmds
106097a3b38f7Smrg      else
10610ff559fabSmrg
106117a3b38f7Smrg	# Add any objects from preloaded convenience libraries
106127a3b38f7Smrg	if test -n "$dlprefiles"; then
106136fc0178dSmrg	  gentop=$output_objdir/${outputname}x
10614862f5301Smrg	  func_append generated " $gentop"
10615ff559fabSmrg
106167a3b38f7Smrg	  func_extract_archives $gentop $dlprefiles
10617862f5301Smrg	  func_append oldobjs " $func_extract_archives_result"
106187a3b38f7Smrg	fi
10619ff559fabSmrg
106207a3b38f7Smrg	# POSIX demands no paths to be encoded in archives.  We have
106217a3b38f7Smrg	# to avoid creating archives with duplicate basenames if we
106227a3b38f7Smrg	# might have to extract them afterwards, e.g., when creating a
106237a3b38f7Smrg	# static archive out of a convenience library, or when linking
106247a3b38f7Smrg	# the entirety of a libtool archive into another (currently
106257a3b38f7Smrg	# not supported by libtool).
106267a3b38f7Smrg	if (for obj in $oldobjs
106277a3b38f7Smrg	    do
106287a3b38f7Smrg	      func_basename "$obj"
106297a3b38f7Smrg	      $ECHO "$func_basename_result"
106307a3b38f7Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
106317a3b38f7Smrg	  :
106327a3b38f7Smrg	else
1063344dda7b2Smrg	  echo "copying selected object files to avoid basename conflicts..."
106346fc0178dSmrg	  gentop=$output_objdir/${outputname}x
10635862f5301Smrg	  func_append generated " $gentop"
106367a3b38f7Smrg	  func_mkdir_p "$gentop"
106377a3b38f7Smrg	  save_oldobjs=$oldobjs
106387a3b38f7Smrg	  oldobjs=
106397a3b38f7Smrg	  counter=1
106407a3b38f7Smrg	  for obj in $save_oldobjs
106417a3b38f7Smrg	  do
106427a3b38f7Smrg	    func_basename "$obj"
106436fc0178dSmrg	    objbase=$func_basename_result
106447a3b38f7Smrg	    case " $oldobjs " in
106457a3b38f7Smrg	    " ") oldobjs=$obj ;;
106467a3b38f7Smrg	    *[\ /]"$objbase "*)
106477a3b38f7Smrg	      while :; do
106487a3b38f7Smrg		# Make sure we don't pick an alternate name that also
106497a3b38f7Smrg		# overlaps.
106507a3b38f7Smrg		newobj=lt$counter-$objbase
106517a3b38f7Smrg		func_arith $counter + 1
106527a3b38f7Smrg		counter=$func_arith_result
106537a3b38f7Smrg		case " $oldobjs " in
106547a3b38f7Smrg		*[\ /]"$newobj "*) ;;
106557a3b38f7Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
106567a3b38f7Smrg		esac
106577a3b38f7Smrg	      done
106587a3b38f7Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10659862f5301Smrg	      func_append oldobjs " $gentop/$newobj"
106607a3b38f7Smrg	      ;;
10661862f5301Smrg	    *) func_append oldobjs " $obj" ;;
106627a3b38f7Smrg	    esac
10663ff559fabSmrg	  done
10664ff559fabSmrg	fi
10665fc544a13Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10666fc544a13Smrg	tool_oldlib=$func_to_tool_file_result
106677a3b38f7Smrg	eval cmds=\"$old_archive_cmds\"
10668ff559fabSmrg
106697a3b38f7Smrg	func_len " $cmds"
106707a3b38f7Smrg	len=$func_len_result
106717a3b38f7Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
106727a3b38f7Smrg	  cmds=$old_archive_cmds
10673862f5301Smrg	elif test -n "$archiver_list_spec"; then
10674862f5301Smrg	  func_verbose "using command file archive linking..."
10675862f5301Smrg	  for obj in $oldobjs
10676862f5301Smrg	  do
10677862f5301Smrg	    func_to_tool_file "$obj"
10678862f5301Smrg	    $ECHO "$func_to_tool_file_result"
10679862f5301Smrg	  done > $output_objdir/$libname.libcmd
10680862f5301Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10681862f5301Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10682862f5301Smrg	  cmds=$old_archive_cmds
106837a3b38f7Smrg	else
106847a3b38f7Smrg	  # the command line is too long to link in one step, link in parts
106857a3b38f7Smrg	  func_verbose "using piecewise archive linking..."
106867a3b38f7Smrg	  save_RANLIB=$RANLIB
106877a3b38f7Smrg	  RANLIB=:
106887a3b38f7Smrg	  objlist=
106897a3b38f7Smrg	  concat_cmds=
106907a3b38f7Smrg	  save_oldobjs=$oldobjs
106917a3b38f7Smrg	  oldobjs=
106927a3b38f7Smrg	  # Is there a better way of finding the last object in the list?
106937a3b38f7Smrg	  for obj in $save_oldobjs
106947a3b38f7Smrg	  do
106957a3b38f7Smrg	    last_oldobj=$obj
106967a3b38f7Smrg	  done
106977a3b38f7Smrg	  eval test_cmds=\"$old_archive_cmds\"
106987a3b38f7Smrg	  func_len " $test_cmds"
106997a3b38f7Smrg	  len0=$func_len_result
107007a3b38f7Smrg	  len=$len0
107017a3b38f7Smrg	  for obj in $save_oldobjs
107027a3b38f7Smrg	  do
107037a3b38f7Smrg	    func_len " $obj"
107047a3b38f7Smrg	    func_arith $len + $func_len_result
107057a3b38f7Smrg	    len=$func_arith_result
107067a3b38f7Smrg	    func_append objlist " $obj"
107077a3b38f7Smrg	    if test "$len" -lt "$max_cmd_len"; then
107087a3b38f7Smrg	      :
107097a3b38f7Smrg	    else
107107a3b38f7Smrg	      # the above command should be used before it gets too long
107117a3b38f7Smrg	      oldobjs=$objlist
107126fc0178dSmrg	      if test "$obj" = "$last_oldobj"; then
107137a3b38f7Smrg		RANLIB=$save_RANLIB
107147a3b38f7Smrg	      fi
107157a3b38f7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
107166fc0178dSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
107177a3b38f7Smrg	      objlist=
107187a3b38f7Smrg	      len=$len0
107197a3b38f7Smrg	    fi
107207a3b38f7Smrg	  done
107217a3b38f7Smrg	  RANLIB=$save_RANLIB
107227a3b38f7Smrg	  oldobjs=$objlist
107236fc0178dSmrg	  if test -z "$oldobjs"; then
107247a3b38f7Smrg	    eval cmds=\"\$concat_cmds\"
107257a3b38f7Smrg	  else
107267a3b38f7Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
107277a3b38f7Smrg	  fi
107287a3b38f7Smrg	fi
107297a3b38f7Smrg      fi
107307a3b38f7Smrg      func_execute_cmds "$cmds" 'exit $?'
10731ff559fabSmrg    done
10732ff559fabSmrg
107337a3b38f7Smrg    test -n "$generated" && \
107347a3b38f7Smrg      func_show_eval "${RM}r$generated"
10735ff559fabSmrg
107367a3b38f7Smrg    # Now create the libtool archive.
107377a3b38f7Smrg    case $output in
107387a3b38f7Smrg    *.la)
107397a3b38f7Smrg      old_library=
107406fc0178dSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
107417a3b38f7Smrg      func_verbose "creating $output"
10742ff559fabSmrg
107437a3b38f7Smrg      # Preserve any variables that may affect compiler behavior
107447a3b38f7Smrg      for var in $variables_saved_for_relink; do
107457a3b38f7Smrg	if eval test -z \"\${$var+set}\"; then
107467a3b38f7Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107477a3b38f7Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
107487a3b38f7Smrg	  relink_command="$var=; export $var; $relink_command"
10749ff559fabSmrg	else
107507a3b38f7Smrg	  func_quote_for_eval "$var_value"
107517a3b38f7Smrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10752ff559fabSmrg	fi
107537a3b38f7Smrg      done
107547a3b38f7Smrg      # Quote the link command for shipping.
107556fc0178dSmrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1075644dda7b2Smrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
107576fc0178dSmrg      if test yes = "$hardcode_automatic"; then
107587a3b38f7Smrg	relink_command=
107597a3b38f7Smrg      fi
10760ff559fabSmrg
107617a3b38f7Smrg      # Only create the output if not a dry run.
107627a3b38f7Smrg      $opt_dry_run || {
107637a3b38f7Smrg	for installed in no yes; do
107646fc0178dSmrg	  if test yes = "$installed"; then
107657a3b38f7Smrg	    if test -z "$install_libdir"; then
107667a3b38f7Smrg	      break
107677a3b38f7Smrg	    fi
107686fc0178dSmrg	    output=$output_objdir/${outputname}i
107697a3b38f7Smrg	    # Replace all uninstalled libtool libraries with the installed ones
107707a3b38f7Smrg	    newdependency_libs=
107717a3b38f7Smrg	    for deplib in $dependency_libs; do
107727a3b38f7Smrg	      case $deplib in
107737a3b38f7Smrg	      *.la)
107747a3b38f7Smrg		func_basename "$deplib"
107756fc0178dSmrg		name=$func_basename_result
10776fc544a13Smrg		func_resolve_sysroot "$deplib"
107776fc0178dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
107787a3b38f7Smrg		test -z "$libdir" && \
107796fc0178dSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
10780862f5301Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
10781862f5301Smrg		;;
10782862f5301Smrg	      -L*)
10783862f5301Smrg		func_stripname -L '' "$deplib"
10784862f5301Smrg		func_replace_sysroot "$func_stripname_result"
10785862f5301Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
10786862f5301Smrg		;;
10787862f5301Smrg	      -R*)
10788862f5301Smrg		func_stripname -R '' "$deplib"
10789862f5301Smrg		func_replace_sysroot "$func_stripname_result"
10790862f5301Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
107917a3b38f7Smrg		;;
10792862f5301Smrg	      *) func_append newdependency_libs " $deplib" ;;
107937a3b38f7Smrg	      esac
107947a3b38f7Smrg	    done
107956fc0178dSmrg	    dependency_libs=$newdependency_libs
107967a3b38f7Smrg	    newdlfiles=
107977a3b38f7Smrg
107987a3b38f7Smrg	    for lib in $dlfiles; do
107997a3b38f7Smrg	      case $lib in
108007a3b38f7Smrg	      *.la)
108017a3b38f7Smrg	        func_basename "$lib"
108026fc0178dSmrg		name=$func_basename_result
108036fc0178dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
108047a3b38f7Smrg		test -z "$libdir" && \
108056fc0178dSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
10806862f5301Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
108077a3b38f7Smrg		;;
10808862f5301Smrg	      *) func_append newdlfiles " $lib" ;;
108097a3b38f7Smrg	      esac
108107a3b38f7Smrg	    done
108116fc0178dSmrg	    dlfiles=$newdlfiles
108127a3b38f7Smrg	    newdlprefiles=
108137a3b38f7Smrg	    for lib in $dlprefiles; do
108147a3b38f7Smrg	      case $lib in
108157a3b38f7Smrg	      *.la)
108167a3b38f7Smrg		# Only pass preopened files to the pseudo-archive (for
108177a3b38f7Smrg		# eventual linking with the app. that links it) if we
108187a3b38f7Smrg		# didn't already link the preopened objects directly into
108197a3b38f7Smrg		# the library:
108207a3b38f7Smrg		func_basename "$lib"
108216fc0178dSmrg		name=$func_basename_result
108226fc0178dSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
108237a3b38f7Smrg		test -z "$libdir" && \
108246fc0178dSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
10825862f5301Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
108267a3b38f7Smrg		;;
108277a3b38f7Smrg	      esac
108287a3b38f7Smrg	    done
108296fc0178dSmrg	    dlprefiles=$newdlprefiles
108307a3b38f7Smrg	  else
108317a3b38f7Smrg	    newdlfiles=
108327a3b38f7Smrg	    for lib in $dlfiles; do
108337a3b38f7Smrg	      case $lib in
108346fc0178dSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
108357a3b38f7Smrg		*) abs=`pwd`"/$lib" ;;
108367a3b38f7Smrg	      esac
10837862f5301Smrg	      func_append newdlfiles " $abs"
108387a3b38f7Smrg	    done
108396fc0178dSmrg	    dlfiles=$newdlfiles
108407a3b38f7Smrg	    newdlprefiles=
108417a3b38f7Smrg	    for lib in $dlprefiles; do
108427a3b38f7Smrg	      case $lib in
108436fc0178dSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
108447a3b38f7Smrg		*) abs=`pwd`"/$lib" ;;
108457a3b38f7Smrg	      esac
10846862f5301Smrg	      func_append newdlprefiles " $abs"
108477a3b38f7Smrg	    done
108486fc0178dSmrg	    dlprefiles=$newdlprefiles
108497a3b38f7Smrg	  fi
108507a3b38f7Smrg	  $RM $output
108517a3b38f7Smrg	  # place dlname in correct position for cygwin
1085244dda7b2Smrg	  # In fact, it would be nice if we could use this code for all target
1085344dda7b2Smrg	  # systems that can't hard-code library paths into their executables
1085444dda7b2Smrg	  # and that have no shared library path variable independent of PATH,
1085544dda7b2Smrg	  # but it turns out we can't easily determine that from inspecting
1085644dda7b2Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1085744dda7b2Smrg	  # applies here; at the moment, that means platforms that use the PE
1085844dda7b2Smrg	  # object format with DLL files.  See the long comment at the top of
1085944dda7b2Smrg	  # tests/bindir.at for full details.
108607a3b38f7Smrg	  tdlname=$dlname
108617a3b38f7Smrg	  case $host,$output,$installed,$module,$dlname in
1086244dda7b2Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1086344dda7b2Smrg	      # If a -bindir argument was supplied, place the dll there.
108646fc0178dSmrg	      if test -n "$bindir"; then
1086544dda7b2Smrg		func_relative_path "$install_libdir" "$bindir"
108666fc0178dSmrg		tdlname=$func_relative_path_result/$dlname
1086744dda7b2Smrg	      else
1086844dda7b2Smrg		# Otherwise fall back on heuristic.
1086944dda7b2Smrg		tdlname=../bin/$dlname
1087044dda7b2Smrg	      fi
1087144dda7b2Smrg	      ;;
108727a3b38f7Smrg	  esac
108737a3b38f7Smrg	  $ECHO > $output "\
108747a3b38f7Smrg# $outputname - a libtool library file
108756fc0178dSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
108767a3b38f7Smrg#
108777a3b38f7Smrg# Please DO NOT delete this file!
108787a3b38f7Smrg# It is necessary for linking the library.
10879ff559fabSmrg
108807a3b38f7Smrg# The name that we can dlopen(3).
108817a3b38f7Smrgdlname='$tdlname'
10882ff559fabSmrg
108837a3b38f7Smrg# Names of this library.
108847a3b38f7Smrglibrary_names='$library_names'
10885ff559fabSmrg
108867a3b38f7Smrg# The name of the static archive.
108877a3b38f7Smrgold_library='$old_library'
10888ff559fabSmrg
108896fc0178dSmrg# Linker flags that cannot go in dependency_libs.
108907a3b38f7Smrginherited_linker_flags='$new_inherited_linker_flags'
10891ff559fabSmrg
108927a3b38f7Smrg# Libraries that this one depends upon.
108937a3b38f7Smrgdependency_libs='$dependency_libs'
10894ff559fabSmrg
108957a3b38f7Smrg# Names of additional weak libraries provided by this library
108967a3b38f7Smrgweak_library_names='$weak_libs'
10897ff559fabSmrg
108987a3b38f7Smrg# Version information for $libname.
108997a3b38f7Smrgcurrent=$current
109007a3b38f7Smrgage=$age
109017a3b38f7Smrgrevision=$revision
10902ff559fabSmrg
109037a3b38f7Smrg# Is this an already installed library?
109047a3b38f7Smrginstalled=$installed
10905ff559fabSmrg
109067a3b38f7Smrg# Should we warn about portability when linking against -modules?
109077a3b38f7Smrgshouldnotlink=$module
10908ff559fabSmrg
109097a3b38f7Smrg# Files to dlopen/dlpreopen
109107a3b38f7Smrgdlopen='$dlfiles'
109117a3b38f7Smrgdlpreopen='$dlprefiles'
10912ff559fabSmrg
109137a3b38f7Smrg# Directory that this library needs to be installed in:
109147a3b38f7Smrglibdir='$install_libdir'"
109156fc0178dSmrg	  if test no,yes = "$installed,$need_relink"; then
109167a3b38f7Smrg	    $ECHO >> $output "\
109177a3b38f7Smrgrelink_command=\"$relink_command\""
109187a3b38f7Smrg	  fi
109197a3b38f7Smrg	done
109207a3b38f7Smrg      }
10921ff559fabSmrg
109227a3b38f7Smrg      # Do a symbolic link so that the libtool archive can be found in
109237a3b38f7Smrg      # LD_LIBRARY_PATH before the program is installed.
109247a3b38f7Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
109257a3b38f7Smrg      ;;
109267a3b38f7Smrg    esac
109277a3b38f7Smrg    exit $EXIT_SUCCESS
109287a3b38f7Smrg}
10929ff559fabSmrg
109306fc0178dSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
109316fc0178dSmrg  func_mode_link ${1+"$@"}
109326fc0178dSmrgfi
10933ff559fabSmrg
10934ff559fabSmrg
109357a3b38f7Smrg# func_mode_uninstall arg...
109367a3b38f7Smrgfunc_mode_uninstall ()
109377a3b38f7Smrg{
109386fc0178dSmrg    $debug_cmd
109396fc0178dSmrg
109406fc0178dSmrg    RM=$nonopt
10941ff559fabSmrg    files=
109426fc0178dSmrg    rmforce=false
10943ff559fabSmrg    exit_status=0
10944ff559fabSmrg
10945ff559fabSmrg    # This variable tells wrapper scripts just to set variables rather
10946ff559fabSmrg    # than running their programs.
109476fc0178dSmrg    libtool_install_magic=$magic
10948ff559fabSmrg
10949ff559fabSmrg    for arg
10950ff559fabSmrg    do
10951ff559fabSmrg      case $arg in
109526fc0178dSmrg      -f) func_append RM " $arg"; rmforce=: ;;
10953862f5301Smrg      -*) func_append RM " $arg" ;;
10954862f5301Smrg      *) func_append files " $arg" ;;
10955ff559fabSmrg      esac
10956ff559fabSmrg    done
10957ff559fabSmrg
109587a3b38f7Smrg    test -z "$RM" && \
109597a3b38f7Smrg      func_fatal_help "you must specify an RM program"
10960ff559fabSmrg
10961ff559fabSmrg    rmdirs=
10962ff559fabSmrg
10963ff559fabSmrg    for file in $files; do
109647a3b38f7Smrg      func_dirname "$file" "" "."
109656fc0178dSmrg      dir=$func_dirname_result
109666fc0178dSmrg      if test . = "$dir"; then
109676fc0178dSmrg	odir=$objdir
10968ff559fabSmrg      else
109696fc0178dSmrg	odir=$dir/$objdir
10970ff559fabSmrg      fi
109717a3b38f7Smrg      func_basename "$file"
109726fc0178dSmrg      name=$func_basename_result
109736fc0178dSmrg      test uninstall = "$opt_mode" && odir=$dir
10974ff559fabSmrg
10975862f5301Smrg      # Remember odir for removal later, being careful to avoid duplicates
109766fc0178dSmrg      if test clean = "$opt_mode"; then
10977ff559fabSmrg	case " $rmdirs " in
10978862f5301Smrg	  *" $odir "*) ;;
10979862f5301Smrg	  *) func_append rmdirs " $odir" ;;
10980ff559fabSmrg	esac
10981ff559fabSmrg      fi
10982ff559fabSmrg
10983ff559fabSmrg      # Don't error if the file doesn't exist and rm -f was used.
109847a3b38f7Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
109857a3b38f7Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
109867a3b38f7Smrg	 test -f "$file"; then
10987ff559fabSmrg	:
10988ff559fabSmrg      elif test -d "$file"; then
10989ff559fabSmrg	exit_status=1
10990ff559fabSmrg	continue
109916fc0178dSmrg      elif $rmforce; then
10992ff559fabSmrg	continue
10993ff559fabSmrg      fi
10994ff559fabSmrg
109956fc0178dSmrg      rmfiles=$file
10996ff559fabSmrg
10997ff559fabSmrg      case $name in
10998ff559fabSmrg      *.la)
10999ff559fabSmrg	# Possibly a libtool archive, so verify it.
110007a3b38f7Smrg	if func_lalib_p "$file"; then
110017a3b38f7Smrg	  func_source $dir/$name
11002ff559fabSmrg
11003ff559fabSmrg	  # Delete the libtool libraries and symlinks.
11004ff559fabSmrg	  for n in $library_names; do
11005862f5301Smrg	    func_append rmfiles " $odir/$n"
11006ff559fabSmrg	  done
11007862f5301Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11008ff559fabSmrg
110096fc0178dSmrg	  case $opt_mode in
11010ff559fabSmrg	  clean)
11011862f5301Smrg	    case " $library_names " in
11012ff559fabSmrg	    *" $dlname "*) ;;
11013862f5301Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11014ff559fabSmrg	    esac
11015862f5301Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11016ff559fabSmrg	    ;;
11017ff559fabSmrg	  uninstall)
11018ff559fabSmrg	    if test -n "$library_names"; then
11019ff559fabSmrg	      # Do each command in the postuninstall commands.
110206fc0178dSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11021ff559fabSmrg	    fi
11022ff559fabSmrg
11023ff559fabSmrg	    if test -n "$old_library"; then
11024ff559fabSmrg	      # Do each command in the old_postuninstall commands.
110256fc0178dSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11026ff559fabSmrg	    fi
11027ff559fabSmrg	    # FIXME: should reinstall the best remaining shared library.
11028ff559fabSmrg	    ;;
11029ff559fabSmrg	  esac
11030ff559fabSmrg	fi
11031ff559fabSmrg	;;
11032ff559fabSmrg
11033ff559fabSmrg      *.lo)
11034ff559fabSmrg	# Possibly a libtool object, so verify it.
110357a3b38f7Smrg	if func_lalib_p "$file"; then
11036ff559fabSmrg
11037ff559fabSmrg	  # Read the .lo file
110387a3b38f7Smrg	  func_source $dir/$name
11039ff559fabSmrg
11040ff559fabSmrg	  # Add PIC object to the list of files to remove.
110416fc0178dSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11042862f5301Smrg	    func_append rmfiles " $dir/$pic_object"
11043ff559fabSmrg	  fi
11044ff559fabSmrg
11045ff559fabSmrg	  # Add non-PIC object to the list of files to remove.
110466fc0178dSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11047862f5301Smrg	    func_append rmfiles " $dir/$non_pic_object"
11048ff559fabSmrg	  fi
11049ff559fabSmrg	fi
11050ff559fabSmrg	;;
11051ff559fabSmrg
11052ff559fabSmrg      *)
110536fc0178dSmrg	if test clean = "$opt_mode"; then
11054ff559fabSmrg	  noexename=$name
11055ff559fabSmrg	  case $file in
11056ff559fabSmrg	  *.exe)
110577a3b38f7Smrg	    func_stripname '' '.exe' "$file"
110587a3b38f7Smrg	    file=$func_stripname_result
110597a3b38f7Smrg	    func_stripname '' '.exe' "$name"
110607a3b38f7Smrg	    noexename=$func_stripname_result
11061ff559fabSmrg	    # $file with .exe has already been added to rmfiles,
11062ff559fabSmrg	    # add $file without .exe
11063862f5301Smrg	    func_append rmfiles " $file"
11064ff559fabSmrg	    ;;
11065ff559fabSmrg	  esac
11066ff559fabSmrg	  # Do a test to see if this is a libtool program.
110677a3b38f7Smrg	  if func_ltwrapper_p "$file"; then
110687a3b38f7Smrg	    if func_ltwrapper_executable_p "$file"; then
110697a3b38f7Smrg	      func_ltwrapper_scriptname "$file"
110707a3b38f7Smrg	      relink_command=
110717a3b38f7Smrg	      func_source $func_ltwrapper_scriptname_result
11072862f5301Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
110737a3b38f7Smrg	    else
110747a3b38f7Smrg	      relink_command=
110757a3b38f7Smrg	      func_source $dir/$noexename
110767a3b38f7Smrg	    fi
11077ff559fabSmrg
11078ff559fabSmrg	    # note $name still contains .exe if it was in $file originally
11079ff559fabSmrg	    # as does the version of $file that was added into $rmfiles
110806fc0178dSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
110816fc0178dSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11082862f5301Smrg	      func_append rmfiles " $odir/lt-$name"
11083ff559fabSmrg	    fi
110846fc0178dSmrg	    if test "X$noexename" != "X$name"; then
110856fc0178dSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
11086ff559fabSmrg	    fi
11087ff559fabSmrg	  fi
11088ff559fabSmrg	fi
11089ff559fabSmrg	;;
11090ff559fabSmrg      esac
110917a3b38f7Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11092ff559fabSmrg    done
11093ff559fabSmrg
110946fc0178dSmrg    # Try to remove the $objdir's in the directories where we deleted files
11095ff559fabSmrg    for dir in $rmdirs; do
11096ff559fabSmrg      if test -d "$dir"; then
110977a3b38f7Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11098ff559fabSmrg      fi
11099ff559fabSmrg    done
11100ff559fabSmrg
11101ff559fabSmrg    exit $exit_status
111027a3b38f7Smrg}
11103ff559fabSmrg
111046fc0178dSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
111056fc0178dSmrg  func_mode_uninstall ${1+"$@"}
111066fc0178dSmrgfi
11107ff559fabSmrg
11108862f5301Smrgtest -z "$opt_mode" && {
111096fc0178dSmrg  help=$generic_help
111107a3b38f7Smrg  func_fatal_help "you must specify a MODE"
111117a3b38f7Smrg}
111127a3b38f7Smrg
111137a3b38f7Smrgtest -z "$exec_cmd" && \
111146fc0178dSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
11115ff559fabSmrg
11116ff559fabSmrgif test -n "$exec_cmd"; then
111177a3b38f7Smrg  eval exec "$exec_cmd"
11118ff559fabSmrg  exit $EXIT_FAILURE
11119ff559fabSmrgfi
11120ff559fabSmrg
111217a3b38f7Smrgexit $exit_status
11122ff559fabSmrg
11123ff559fabSmrg
11124ff559fabSmrg# The TAGs below are defined such that we never get into a situation
111256fc0178dSmrg# where we disable both kinds of libraries.  Given conflicting
11126ff559fabSmrg# choices, we go for a static library, that is the most portable,
11127ff559fabSmrg# since we can't tell whether shared libraries were disabled because
11128ff559fabSmrg# the user asked for that or because the platform doesn't support
11129ff559fabSmrg# them.  This is particularly important on AIX, because we don't
11130ff559fabSmrg# support having both static and shared libraries enabled at the same
11131ff559fabSmrg# time on that platform, so we default to a shared-only configuration.
11132ff559fabSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11133ff559fabSmrg# configuration.  But we'll never go from static-only to shared-only.
11134ff559fabSmrg
11135ff559fabSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
111367a3b38f7Smrgbuild_libtool_libs=no
111377a3b38f7Smrgbuild_old_libs=yes
11138ff559fabSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11139ff559fabSmrg
11140ff559fabSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
111417a3b38f7Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11142ff559fabSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11143ff559fabSmrg
11144ff559fabSmrg# Local Variables:
11145ff559fabSmrg# mode:shell-script
11146ff559fabSmrg# sh-indentation:2
11147ff559fabSmrg# End:
11148