12b2b4fcbSmrg#! /usr/bin/env sh
2300bf1aeSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
32b2b4fcbSmrg##               by inline-source v2019-02-19.15
46aec45a7Smrg
52b2b4fcbSmrg# libtool (GNU libtool) 2.4.7
6300bf1aeSmrg# Provide generalized library-building support services.
76aec45a7Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
86aec45a7Smrg
92b2b4fcbSmrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
106aec45a7Smrg# This is free software; see the source for copying conditions.  There is NO
116aec45a7Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
126aec45a7Smrg
136aec45a7Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14ab47cfaaSmrg# it under the terms of the GNU General Public License as published by
15ab47cfaaSmrg# the Free Software Foundation; either version 2 of the License, or
16ab47cfaaSmrg# (at your option) any later version.
17ab47cfaaSmrg#
186aec45a7Smrg# As a special exception to the GNU General Public License,
196aec45a7Smrg# if you distribute this file as part of a program or library that
206aec45a7Smrg# is built using GNU Libtool, you may include this file under the
216aec45a7Smrg# same distribution terms that you use for the rest of that program.
226aec45a7Smrg#
236aec45a7Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24ab47cfaaSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25ab47cfaaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26ab47cfaaSmrg# General Public License for more details.
27ab47cfaaSmrg#
28ab47cfaaSmrg# You should have received a copy of the GNU General Public License
29300bf1aeSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
305c42550eSmrg
31ab47cfaaSmrg
326aec45a7SmrgPROGRAM=libtool
33ab47cfaaSmrgPACKAGE=libtool
342b2b4fcbSmrgVERSION=2.4.7
352b2b4fcbSmrgpackage_revision=2.4.7
368697ee19Smrg
37300bf1aeSmrg
38300bf1aeSmrg## ------ ##
39300bf1aeSmrg## Usage. ##
40300bf1aeSmrg## ------ ##
41300bf1aeSmrg
42300bf1aeSmrg# Run './libtool --help' for help with using this script from the
43300bf1aeSmrg# command line.
44300bf1aeSmrg
45300bf1aeSmrg
46300bf1aeSmrg## ------------------------------- ##
47300bf1aeSmrg## User overridable command paths. ##
48300bf1aeSmrg## ------------------------------- ##
49300bf1aeSmrg
50300bf1aeSmrg# After configure completes, it has a better idea of some of the
51300bf1aeSmrg# shell tools we need than the defaults used by the functions shared
52300bf1aeSmrg# with bootstrap, so set those here where they can still be over-
53300bf1aeSmrg# ridden by the user, but otherwise take precedence.
54300bf1aeSmrg
55300bf1aeSmrg: ${AUTOCONF="autoconf"}
56300bf1aeSmrg: ${AUTOMAKE="automake"}
57300bf1aeSmrg
58300bf1aeSmrg
59300bf1aeSmrg## -------------------------- ##
60300bf1aeSmrg## Source external libraries. ##
61300bf1aeSmrg## -------------------------- ##
62300bf1aeSmrg
63300bf1aeSmrg# Much of our low-level functionality needs to be sourced from external
64300bf1aeSmrg# libraries, which are installed to $pkgauxdir.
65300bf1aeSmrg
66300bf1aeSmrg# Set a version string for this script.
672b2b4fcbSmrgscriptversion=2019-02-19.15; # UTC
68300bf1aeSmrg
69300bf1aeSmrg# General shell script boiler plate, and helper functions.
70300bf1aeSmrg# Written by Gary V. Vaughan, 2004
71300bf1aeSmrg
722b2b4fcbSmrg# This is free software.  There is NO warranty; not even for
732b2b4fcbSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
742b2b4fcbSmrg#
752b2b4fcbSmrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
762b2b4fcbSmrg#
772b2b4fcbSmrg# This file is dual licensed under the terms of the MIT license
782b2b4fcbSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
792b2b4fcbSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
802b2b4fcbSmrg# these licenses when using or redistributing this software or any of
812b2b4fcbSmrg# the files within it.  See the URLs above, or the file `LICENSE`
822b2b4fcbSmrg# included in the Bootstrap distribution for the full license texts.
83300bf1aeSmrg
842b2b4fcbSmrg# Please report bugs or propose patches to:
852b2b4fcbSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
86300bf1aeSmrg
87300bf1aeSmrg
88300bf1aeSmrg## ------ ##
89300bf1aeSmrg## Usage. ##
90300bf1aeSmrg## ------ ##
91300bf1aeSmrg
92300bf1aeSmrg# Evaluate this file near the top of your script to gain access to
93300bf1aeSmrg# the functions and variables defined here:
94300bf1aeSmrg#
95300bf1aeSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96300bf1aeSmrg#
97300bf1aeSmrg# If you need to override any of the default environment variable
98300bf1aeSmrg# settings, do that before evaluating this file.
99300bf1aeSmrg
100300bf1aeSmrg
101300bf1aeSmrg## -------------------- ##
102300bf1aeSmrg## Shell normalisation. ##
103300bf1aeSmrg## -------------------- ##
104300bf1aeSmrg
105300bf1aeSmrg# Some shells need a little help to be as Bourne compatible as possible.
106300bf1aeSmrg# Before doing anything else, make sure all that help has been provided!
107300bf1aeSmrg
108300bf1aeSmrgDUALCASE=1; export DUALCASE # for MKS sh
109300bf1aeSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1108697ee19Smrg  emulate sh
1118697ee19Smrg  NULLCMD=:
112300bf1aeSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1138697ee19Smrg  # is contrary to our usage.  Disable this feature.
1148697ee19Smrg  alias -g '${1+"$@"}'='"$@"'
115ab47cfaaSmrg  setopt NO_GLOB_SUBST
1168697ee19Smrgelse
117300bf1aeSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118ab47cfaaSmrgfi
1195c42550eSmrg
120300bf1aeSmrg# NLS nuisances: We save the old values in case they are required later.
121300bf1aeSmrg_G_user_locale=
122300bf1aeSmrg_G_safe_locale=
123300bf1aeSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1248697ee19Smrgdo
125300bf1aeSmrg  eval "if test set = \"\${$_G_var+set}\"; then
126300bf1aeSmrg          save_$_G_var=\$$_G_var
127300bf1aeSmrg          $_G_var=C
128300bf1aeSmrg	  export $_G_var
129300bf1aeSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130300bf1aeSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1318697ee19Smrg	fi"
1328697ee19Smrgdone
1332b2b4fcbSmrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1342b2b4fcbSmrg# in case the environment reset is needed later and the $save_* variant is not
1352b2b4fcbSmrg# defined (see the code above).
1362b2b4fcbSmrgLC_ALL=C
1372b2b4fcbSmrgLANGUAGE=C
1382b2b4fcbSmrgexport LANGUAGE LC_ALL
1396aec45a7Smrg
140300bf1aeSmrg# Make sure IFS has a sensible default
141300bf1aeSmrgsp=' '
142300bf1aeSmrgnl='
143300bf1aeSmrg'
144300bf1aeSmrgIFS="$sp	$nl"
145300bf1aeSmrg
146300bf1aeSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
147300bf1aeSmrgif test "${PATH_SEPARATOR+set}" != set; then
148300bf1aeSmrg  PATH_SEPARATOR=:
149300bf1aeSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150300bf1aeSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151300bf1aeSmrg      PATH_SEPARATOR=';'
152300bf1aeSmrg  }
153300bf1aeSmrgfi
1546aec45a7Smrg
1556aec45a7Smrg
1562b2b4fcbSmrg# func_unset VAR
1572b2b4fcbSmrg# --------------
1582b2b4fcbSmrg# Portably unset VAR.
1592b2b4fcbSmrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1602b2b4fcbSmrg# status if VAR is already unset, which might be problematic if the
1612b2b4fcbSmrg# statement is used at the end of a function (thus poisoning its return
1622b2b4fcbSmrg# value) or when 'set -e' is active (causing even a spurious abort of
1632b2b4fcbSmrg# the script in this case).
1642b2b4fcbSmrgfunc_unset ()
1652b2b4fcbSmrg{
1662b2b4fcbSmrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1672b2b4fcbSmrg}
1682b2b4fcbSmrg
1692b2b4fcbSmrg
1702b2b4fcbSmrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1712b2b4fcbSmrgfunc_unset CDPATH
1722b2b4fcbSmrg
1732b2b4fcbSmrg# Make sure ${,E,F}GREP behave sanely.
1742b2b4fcbSmrgfunc_unset GREP_OPTIONS
1752b2b4fcbSmrg
1766aec45a7Smrg
177300bf1aeSmrg## ------------------------- ##
178300bf1aeSmrg## Locate command utilities. ##
179300bf1aeSmrg## ------------------------- ##
180300bf1aeSmrg
181300bf1aeSmrg
182300bf1aeSmrg# func_executable_p FILE
183300bf1aeSmrg# ----------------------
184300bf1aeSmrg# Check that FILE is an executable regular file.
185300bf1aeSmrgfunc_executable_p ()
186300bf1aeSmrg{
187300bf1aeSmrg    test -f "$1" && test -x "$1"
188300bf1aeSmrg}
189300bf1aeSmrg
190300bf1aeSmrg
191300bf1aeSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192300bf1aeSmrg# --------------------------------------------
193300bf1aeSmrg# Search for either a program that responds to --version with output
194300bf1aeSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195300bf1aeSmrg# trying all the directories in PATH with each of the elements of
196300bf1aeSmrg# PROGS_LIST.
197300bf1aeSmrg#
198300bf1aeSmrg# CHECK_FUNC should accept the path to a candidate program, and
199300bf1aeSmrg# set $func_check_prog_result if it truncates its output less than
200300bf1aeSmrg# $_G_path_prog_max characters.
201300bf1aeSmrgfunc_path_progs ()
202300bf1aeSmrg{
203300bf1aeSmrg    _G_progs_list=$1
204300bf1aeSmrg    _G_check_func=$2
205300bf1aeSmrg    _G_PATH=${3-"$PATH"}
206300bf1aeSmrg
207300bf1aeSmrg    _G_path_prog_max=0
208300bf1aeSmrg    _G_path_prog_found=false
209300bf1aeSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210300bf1aeSmrg    for _G_dir in $_G_PATH; do
211300bf1aeSmrg      IFS=$_G_save_IFS
212300bf1aeSmrg      test -z "$_G_dir" && _G_dir=.
213300bf1aeSmrg      for _G_prog_name in $_G_progs_list; do
214300bf1aeSmrg        for _exeext in '' .EXE; do
215300bf1aeSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216300bf1aeSmrg          func_executable_p "$_G_path_prog" || continue
217300bf1aeSmrg          case `"$_G_path_prog" --version 2>&1` in
218300bf1aeSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219300bf1aeSmrg            *)     $_G_check_func $_G_path_prog
220300bf1aeSmrg		   func_path_progs_result=$func_check_prog_result
221300bf1aeSmrg		   ;;
222300bf1aeSmrg          esac
223300bf1aeSmrg          $_G_path_prog_found && break 3
224300bf1aeSmrg        done
225300bf1aeSmrg      done
226300bf1aeSmrg    done
227300bf1aeSmrg    IFS=$_G_save_IFS
228300bf1aeSmrg    test -z "$func_path_progs_result" && {
229300bf1aeSmrg      echo "no acceptable sed could be found in \$PATH" >&2
230300bf1aeSmrg      exit 1
231300bf1aeSmrg    }
232300bf1aeSmrg}
233300bf1aeSmrg
234300bf1aeSmrg
235300bf1aeSmrg# We want to be able to use the functions in this file before configure
236300bf1aeSmrg# has figured out where the best binaries are kept, which means we have
237300bf1aeSmrg# to search for them ourselves - except when the results are already set
238300bf1aeSmrg# where we skip the searches.
239300bf1aeSmrg
240300bf1aeSmrg# Unless the user overrides by setting SED, search the path for either GNU
241300bf1aeSmrg# sed, or the sed that truncates its output the least.
242300bf1aeSmrgtest -z "$SED" && {
243300bf1aeSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244300bf1aeSmrg  for _G_i in 1 2 3 4 5 6 7; do
245300bf1aeSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246300bf1aeSmrg  done
247300bf1aeSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248300bf1aeSmrg  _G_sed_script=
249300bf1aeSmrg
250300bf1aeSmrg  func_check_prog_sed ()
251300bf1aeSmrg  {
252300bf1aeSmrg    _G_path_prog=$1
253300bf1aeSmrg
254300bf1aeSmrg    _G_count=0
255300bf1aeSmrg    printf 0123456789 >conftest.in
256300bf1aeSmrg    while :
257300bf1aeSmrg    do
258300bf1aeSmrg      cat conftest.in conftest.in >conftest.tmp
259300bf1aeSmrg      mv conftest.tmp conftest.in
260300bf1aeSmrg      cp conftest.in conftest.nl
261300bf1aeSmrg      echo '' >> conftest.nl
262300bf1aeSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263300bf1aeSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264300bf1aeSmrg      _G_count=`expr $_G_count + 1`
265300bf1aeSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266300bf1aeSmrg        # Best one so far, save it but keep looking for a better one
267300bf1aeSmrg        func_check_prog_result=$_G_path_prog
268300bf1aeSmrg        _G_path_prog_max=$_G_count
269300bf1aeSmrg      fi
270300bf1aeSmrg      # 10*(2^10) chars as input seems more than enough
271300bf1aeSmrg      test 10 -lt "$_G_count" && break
272300bf1aeSmrg    done
273300bf1aeSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274300bf1aeSmrg  }
275300bf1aeSmrg
2762b2b4fcbSmrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277300bf1aeSmrg  rm -f conftest.sed
278300bf1aeSmrg  SED=$func_path_progs_result
279300bf1aeSmrg}
280300bf1aeSmrg
281300bf1aeSmrg
282300bf1aeSmrg# Unless the user overrides by setting GREP, search the path for either GNU
283300bf1aeSmrg# grep, or the grep that truncates its output the least.
284300bf1aeSmrgtest -z "$GREP" && {
285300bf1aeSmrg  func_check_prog_grep ()
286300bf1aeSmrg  {
287300bf1aeSmrg    _G_path_prog=$1
288300bf1aeSmrg
289300bf1aeSmrg    _G_count=0
290300bf1aeSmrg    _G_path_prog_max=0
291300bf1aeSmrg    printf 0123456789 >conftest.in
292300bf1aeSmrg    while :
293300bf1aeSmrg    do
294300bf1aeSmrg      cat conftest.in conftest.in >conftest.tmp
295300bf1aeSmrg      mv conftest.tmp conftest.in
296300bf1aeSmrg      cp conftest.in conftest.nl
297300bf1aeSmrg      echo 'GREP' >> conftest.nl
298300bf1aeSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299300bf1aeSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300300bf1aeSmrg      _G_count=`expr $_G_count + 1`
301300bf1aeSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302300bf1aeSmrg        # Best one so far, save it but keep looking for a better one
303300bf1aeSmrg        func_check_prog_result=$_G_path_prog
304300bf1aeSmrg        _G_path_prog_max=$_G_count
305300bf1aeSmrg      fi
306300bf1aeSmrg      # 10*(2^10) chars as input seems more than enough
307300bf1aeSmrg      test 10 -lt "$_G_count" && break
308300bf1aeSmrg    done
309300bf1aeSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310300bf1aeSmrg  }
311300bf1aeSmrg
3122b2b4fcbSmrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313300bf1aeSmrg  GREP=$func_path_progs_result
314300bf1aeSmrg}
315300bf1aeSmrg
316300bf1aeSmrg
317300bf1aeSmrg## ------------------------------- ##
318300bf1aeSmrg## User overridable command paths. ##
319300bf1aeSmrg## ------------------------------- ##
320300bf1aeSmrg
321300bf1aeSmrg# All uppercase variable names are used for environment variables.  These
322300bf1aeSmrg# variables can be overridden by the user before calling a script that
323300bf1aeSmrg# uses them if a suitable command of that name is not already available
324300bf1aeSmrg# in the command search PATH.
3256aec45a7Smrg
3266aec45a7Smrg: ${CP="cp -f"}
327300bf1aeSmrg: ${ECHO="printf %s\n"}
328300bf1aeSmrg: ${EGREP="$GREP -E"}
329300bf1aeSmrg: ${FGREP="$GREP -F"}
330300bf1aeSmrg: ${LN_S="ln -s"}
3316aec45a7Smrg: ${MAKE="make"}
3326aec45a7Smrg: ${MKDIR="mkdir"}
3336aec45a7Smrg: ${MV="mv -f"}
3346aec45a7Smrg: ${RM="rm -f"}
3356aec45a7Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336ab47cfaaSmrg
3376aec45a7Smrg
338300bf1aeSmrg## -------------------- ##
339300bf1aeSmrg## Useful sed snippets. ##
340300bf1aeSmrg## -------------------- ##
341aa9e3350Smrg
342300bf1aeSmrgsed_dirname='s|/[^/]*$||'
343300bf1aeSmrgsed_basename='s|^.*/||'
344aa9e3350Smrg
345300bf1aeSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
346300bf1aeSmrg# metacharacters that are still active within double-quoted strings.
347300bf1aeSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348aa9e3350Smrg
349300bf1aeSmrg# Same as above, but do not quote variable references.
350300bf1aeSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351aa9e3350Smrg
352300bf1aeSmrg# Sed substitution that turns a string into a regex matching for the
353300bf1aeSmrg# string literally.
354300bf1aeSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355aa9e3350Smrg
356300bf1aeSmrg# Sed substitution that converts a w32 file name or path
357300bf1aeSmrg# that contains forward slashes, into one that contains
358300bf1aeSmrg# (escaped) backslashes.  A very naive implementation.
359300bf1aeSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360300bf1aeSmrg
361300bf1aeSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362300bf1aeSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363300bf1aeSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364300bf1aeSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
365300bf1aeSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366300bf1aeSmrg_G_bs='\\'
367300bf1aeSmrg_G_bs2='\\\\'
368300bf1aeSmrg_G_bs4='\\\\\\\\'
369300bf1aeSmrg_G_dollar='\$'
370300bf1aeSmrgsed_double_backslash="\
371300bf1aeSmrg  s/$_G_bs4/&\\
372300bf1aeSmrg/g
373300bf1aeSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374300bf1aeSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375300bf1aeSmrg  s/\n//g"
376aa9e3350Smrg
3772b2b4fcbSmrg# require_check_ifs_backslash
3782b2b4fcbSmrg# ---------------------------
3792b2b4fcbSmrg# Check if we can use backslash as IFS='\' separator, and set
3802b2b4fcbSmrg# $check_ifs_backshlash_broken to ':' or 'false'.
3812b2b4fcbSmrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3822b2b4fcbSmrgfunc_require_check_ifs_backslash ()
3832b2b4fcbSmrg{
3842b2b4fcbSmrg  _G_save_IFS=$IFS
3852b2b4fcbSmrg  IFS='\'
3862b2b4fcbSmrg  _G_check_ifs_backshlash='a\\b'
3872b2b4fcbSmrg  for _G_i in $_G_check_ifs_backshlash
3882b2b4fcbSmrg  do
3892b2b4fcbSmrg  case $_G_i in
3902b2b4fcbSmrg  a)
3912b2b4fcbSmrg    check_ifs_backshlash_broken=false
3922b2b4fcbSmrg    ;;
3932b2b4fcbSmrg  '')
3942b2b4fcbSmrg    break
3952b2b4fcbSmrg    ;;
3962b2b4fcbSmrg  *)
3972b2b4fcbSmrg    check_ifs_backshlash_broken=:
3982b2b4fcbSmrg    break
3992b2b4fcbSmrg    ;;
4002b2b4fcbSmrg  esac
4012b2b4fcbSmrg  done
4022b2b4fcbSmrg  IFS=$_G_save_IFS
4032b2b4fcbSmrg  require_check_ifs_backslash=:
4042b2b4fcbSmrg}
4052b2b4fcbSmrg
4061473d951Smrg
407300bf1aeSmrg## ----------------- ##
408300bf1aeSmrg## Global variables. ##
409300bf1aeSmrg## ----------------- ##
4106aec45a7Smrg
411300bf1aeSmrg# Except for the global variables explicitly listed below, the following
412300bf1aeSmrg# functions in the '^func_' namespace, and the '^require_' namespace
413300bf1aeSmrg# variables initialised in the 'Resource management' section, sourcing
414300bf1aeSmrg# this file will not pollute your global namespace with anything
415300bf1aeSmrg# else. There's no portable way to scope variables in Bourne shell
416300bf1aeSmrg# though, so actually running these functions will sometimes place
417300bf1aeSmrg# results into a variable named after the function, and often use
418300bf1aeSmrg# temporary variables in the '^_G_' namespace. If you are careful to
419300bf1aeSmrg# avoid using those namespaces casually in your sourcing script, things
420300bf1aeSmrg# should continue to work as you expect. And, of course, you can freely
421300bf1aeSmrg# overwrite any of the functions or variables defined here before
422300bf1aeSmrg# calling anything to customize them.
4236aec45a7Smrg
424300bf1aeSmrgEXIT_SUCCESS=0
425300bf1aeSmrgEXIT_FAILURE=1
426300bf1aeSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427300bf1aeSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4286aec45a7Smrg
429300bf1aeSmrg# Allow overriding, eg assuming that you follow the convention of
430300bf1aeSmrg# putting '$debug_cmd' at the start of all your functions, you can get
431300bf1aeSmrg# bash to show function call trace with:
432300bf1aeSmrg#
433300bf1aeSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434300bf1aeSmrgdebug_cmd=${debug_cmd-":"}
435300bf1aeSmrgexit_cmd=:
4366aec45a7Smrg
437300bf1aeSmrg# By convention, finish your script with:
438300bf1aeSmrg#
439300bf1aeSmrg#    exit $exit_status
440300bf1aeSmrg#
441300bf1aeSmrg# so that you can set exit_status to non-zero if you want to indicate
442300bf1aeSmrg# something went wrong during execution without actually bailing out at
443300bf1aeSmrg# the point of failure.
444300bf1aeSmrgexit_status=$EXIT_SUCCESS
4456aec45a7Smrg
446300bf1aeSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447300bf1aeSmrg# is ksh but when the shell is invoked as "sh" and the current value of
448300bf1aeSmrg# the _XPG environment variable is not equal to 1 (one), the special
449300bf1aeSmrg# positional parameter $0, within a function call, is the name of the
450300bf1aeSmrg# function.
451300bf1aeSmrgprogpath=$0
4526aec45a7Smrg
453300bf1aeSmrg# The name of this program.
454300bf1aeSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4556aec45a7Smrg
456300bf1aeSmrg# Make sure we have an absolute progpath for reexecution:
4576aec45a7Smrgcase $progpath in
4586aec45a7Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4596aec45a7Smrg  *[\\/]*)
460300bf1aeSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4616aec45a7Smrg     progdir=`cd "$progdir" && pwd`
462300bf1aeSmrg     progpath=$progdir/$progname
4636aec45a7Smrg     ;;
4646aec45a7Smrg  *)
465300bf1aeSmrg     _G_IFS=$IFS
466aa9e3350Smrg     IFS=${PATH_SEPARATOR-:}
4676aec45a7Smrg     for progdir in $PATH; do
468300bf1aeSmrg       IFS=$_G_IFS
4696aec45a7Smrg       test -x "$progdir/$progname" && break
4706aec45a7Smrg     done
471300bf1aeSmrg     IFS=$_G_IFS
4726aec45a7Smrg     test -n "$progdir" || progdir=`pwd`
473300bf1aeSmrg     progpath=$progdir/$progname
4746aec45a7Smrg     ;;
4756aec45a7Smrgesac
4766aec45a7Smrg
4776aec45a7Smrg
478300bf1aeSmrg## ----------------- ##
479300bf1aeSmrg## Standard options. ##
480300bf1aeSmrg## ----------------- ##
481aa9e3350Smrg
482300bf1aeSmrg# The following options affect the operation of the functions defined
483300bf1aeSmrg# below, and should be set appropriately depending on run-time para-
484300bf1aeSmrg# meters passed on the command line.
4856aec45a7Smrg
4866aec45a7Smrgopt_dry_run=false
4876aec45a7Smrgopt_quiet=false
4886aec45a7Smrgopt_verbose=false
4896aec45a7Smrg
490300bf1aeSmrg# Categories 'all' and 'none' are always available.  Append any others
491300bf1aeSmrg# you will pass as the first argument to func_warning from your own
492300bf1aeSmrg# code.
493300bf1aeSmrgwarning_categories=
4946aec45a7Smrg
495300bf1aeSmrg# By default, display warnings according to 'opt_warning_types'.  Set
496300bf1aeSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497300bf1aeSmrg# treat the next displayed warning as a fatal error.
498300bf1aeSmrgwarning_func=func_warn_and_continue
4996aec45a7Smrg
500300bf1aeSmrg# Set to 'all' to display all warnings, 'none' to suppress all
501300bf1aeSmrg# warnings, or a space delimited list of some subset of
502300bf1aeSmrg# 'warning_categories' to display only the listed warnings.
503300bf1aeSmrgopt_warning_types=all
5046aec45a7Smrg
5056aec45a7Smrg
506300bf1aeSmrg## -------------------- ##
507300bf1aeSmrg## Resource management. ##
508300bf1aeSmrg## -------------------- ##
5096aec45a7Smrg
510300bf1aeSmrg# This section contains definitions for functions that each ensure a
511300bf1aeSmrg# particular resource (a file, or a non-empty configuration variable for
512300bf1aeSmrg# example) is available, and if appropriate to extract default values
513300bf1aeSmrg# from pertinent package files. Call them using their associated
514300bf1aeSmrg# 'require_*' variable to ensure that they are executed, at most, once.
515300bf1aeSmrg#
516300bf1aeSmrg# It's entirely deliberate that calling these functions can set
517300bf1aeSmrg# variables that don't obey the namespace limitations obeyed by the rest
518300bf1aeSmrg# of this file, in order that that they be as useful as possible to
519300bf1aeSmrg# callers.
5206aec45a7Smrg
5216aec45a7Smrg
522300bf1aeSmrg# require_term_colors
523300bf1aeSmrg# -------------------
524300bf1aeSmrg# Allow display of bold text on terminals that support it.
525300bf1aeSmrgrequire_term_colors=func_require_term_colors
526300bf1aeSmrgfunc_require_term_colors ()
5276aec45a7Smrg{
528300bf1aeSmrg    $debug_cmd
529300bf1aeSmrg
530300bf1aeSmrg    test -t 1 && {
531300bf1aeSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532300bf1aeSmrg      # precedence, because most terminfo databases neglect to describe
533300bf1aeSmrg      # whether color sequences are supported.
534300bf1aeSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535300bf1aeSmrg
536300bf1aeSmrg      if test 1 = "$USE_ANSI_COLORS"; then
537300bf1aeSmrg        # Standard ANSI escape sequences
538300bf1aeSmrg        tc_reset='[0m'
539300bf1aeSmrg        tc_bold='[1m';   tc_standout='[7m'
540300bf1aeSmrg        tc_red='[31m';   tc_green='[32m'
541300bf1aeSmrg        tc_blue='[34m';  tc_cyan='[36m'
542300bf1aeSmrg      else
543300bf1aeSmrg        # Otherwise trust the terminfo database after all.
544300bf1aeSmrg        test -n "`tput sgr0 2>/dev/null`" && {
545300bf1aeSmrg          tc_reset=`tput sgr0`
546300bf1aeSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547300bf1aeSmrg          tc_standout=$tc_bold
548300bf1aeSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549300bf1aeSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550300bf1aeSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551300bf1aeSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552300bf1aeSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553300bf1aeSmrg        }
554300bf1aeSmrg      fi
555300bf1aeSmrg    }
5566aec45a7Smrg
557300bf1aeSmrg    require_term_colors=:
5586aec45a7Smrg}
5596aec45a7Smrg
5606aec45a7Smrg
561300bf1aeSmrg## ----------------- ##
562300bf1aeSmrg## Function library. ##
563300bf1aeSmrg## ----------------- ##
564300bf1aeSmrg
565300bf1aeSmrg# This section contains a variety of useful functions to call in your
566300bf1aeSmrg# scripts. Take note of the portable wrappers for features provided by
567300bf1aeSmrg# some modern shells, which will fall back to slower equivalents on
568300bf1aeSmrg# less featureful shells.
569300bf1aeSmrg
570300bf1aeSmrg
571300bf1aeSmrg# func_append VAR VALUE
572300bf1aeSmrg# ---------------------
573300bf1aeSmrg# Append VALUE onto the existing contents of VAR.
574300bf1aeSmrg
575300bf1aeSmrg  # We should try to minimise forks, especially on Windows where they are
576300bf1aeSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577300bf1aeSmrg  # being used:
578300bf1aeSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579300bf1aeSmrg    : ${_G_HAVE_ARITH_OP="yes"}
580300bf1aeSmrg    : ${_G_HAVE_XSI_OPS="yes"}
581300bf1aeSmrg    # The += operator was introduced in bash 3.1
582300bf1aeSmrg    case $BASH_VERSION in
583300bf1aeSmrg      [12].* | 3.0 | 3.0*) ;;
584300bf1aeSmrg      *)
585300bf1aeSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586300bf1aeSmrg        ;;
587300bf1aeSmrg    esac
588300bf1aeSmrg  fi
589300bf1aeSmrg
590300bf1aeSmrg  # _G_HAVE_PLUSEQ_OP
591300bf1aeSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
592300bf1aeSmrg  # useable or anything else if it does not work.
593300bf1aeSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594300bf1aeSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595300bf1aeSmrg    && _G_HAVE_PLUSEQ_OP=yes
596300bf1aeSmrg
597300bf1aeSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598300bf1aeSmrgthen
599300bf1aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
600300bf1aeSmrg  eval 'func_append ()
601300bf1aeSmrg  {
602300bf1aeSmrg    $debug_cmd
603300bf1aeSmrg
604300bf1aeSmrg    eval "$1+=\$2"
605300bf1aeSmrg  }'
606300bf1aeSmrgelse
607300bf1aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608300bf1aeSmrg  func_append ()
609300bf1aeSmrg  {
610300bf1aeSmrg    $debug_cmd
611300bf1aeSmrg
612300bf1aeSmrg    eval "$1=\$$1\$2"
613300bf1aeSmrg  }
614300bf1aeSmrgfi
615300bf1aeSmrg
616300bf1aeSmrg
617300bf1aeSmrg# func_append_quoted VAR VALUE
618300bf1aeSmrg# ----------------------------
619300bf1aeSmrg# Quote VALUE and append to the end of shell variable VAR, separated
620300bf1aeSmrg# by a space.
621300bf1aeSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622300bf1aeSmrg  eval 'func_append_quoted ()
623300bf1aeSmrg  {
624300bf1aeSmrg    $debug_cmd
625300bf1aeSmrg
6262b2b4fcbSmrg    func_quote_arg pretty "$2"
6272b2b4fcbSmrg    eval "$1+=\\ \$func_quote_arg_result"
628300bf1aeSmrg  }'
629300bf1aeSmrgelse
630300bf1aeSmrg  func_append_quoted ()
631300bf1aeSmrg  {
632300bf1aeSmrg    $debug_cmd
633300bf1aeSmrg
6342b2b4fcbSmrg    func_quote_arg pretty "$2"
6352b2b4fcbSmrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636300bf1aeSmrg  }
637300bf1aeSmrgfi
638300bf1aeSmrg
639300bf1aeSmrg
640300bf1aeSmrg# func_append_uniq VAR VALUE
641300bf1aeSmrg# --------------------------
642300bf1aeSmrg# Append unique VALUE onto the existing contents of VAR, assuming
643300bf1aeSmrg# entries are delimited by the first character of VALUE.  For example:
644300bf1aeSmrg#
645300bf1aeSmrg#   func_append_uniq options " --another-option option-argument"
646300bf1aeSmrg#
647300bf1aeSmrg# will only append to $options if " --another-option option-argument "
648300bf1aeSmrg# is not already present somewhere in $options already (note spaces at
649300bf1aeSmrg# each end implied by leading space in second argument).
650300bf1aeSmrgfunc_append_uniq ()
651300bf1aeSmrg{
652300bf1aeSmrg    $debug_cmd
653300bf1aeSmrg
654300bf1aeSmrg    eval _G_current_value='`$ECHO $'$1'`'
655300bf1aeSmrg    _G_delim=`expr "$2" : '\(.\)'`
656300bf1aeSmrg
657300bf1aeSmrg    case $_G_delim$_G_current_value$_G_delim in
658300bf1aeSmrg      *"$2$_G_delim"*) ;;
659300bf1aeSmrg      *) func_append "$@" ;;
660300bf1aeSmrg    esac
661300bf1aeSmrg}
662300bf1aeSmrg
663300bf1aeSmrg
664300bf1aeSmrg# func_arith TERM...
665300bf1aeSmrg# ------------------
666300bf1aeSmrg# Set func_arith_result to the result of evaluating TERMs.
667300bf1aeSmrg  test -z "$_G_HAVE_ARITH_OP" \
668300bf1aeSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669300bf1aeSmrg    && _G_HAVE_ARITH_OP=yes
670300bf1aeSmrg
671300bf1aeSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
672300bf1aeSmrg  eval 'func_arith ()
673300bf1aeSmrg  {
674300bf1aeSmrg    $debug_cmd
675300bf1aeSmrg
676300bf1aeSmrg    func_arith_result=$(( $* ))
677300bf1aeSmrg  }'
678300bf1aeSmrgelse
679300bf1aeSmrg  func_arith ()
680300bf1aeSmrg  {
681300bf1aeSmrg    $debug_cmd
682300bf1aeSmrg
683300bf1aeSmrg    func_arith_result=`expr "$@"`
684300bf1aeSmrg  }
685300bf1aeSmrgfi
686300bf1aeSmrg
687300bf1aeSmrg
688300bf1aeSmrg# func_basename FILE
689300bf1aeSmrg# ------------------
690300bf1aeSmrg# Set func_basename_result to FILE with everything up to and including
691300bf1aeSmrg# the last / stripped.
692300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
693300bf1aeSmrg  # If this shell supports suffix pattern removal, then use it to avoid
694300bf1aeSmrg  # forking. Hide the definitions single quotes in case the shell chokes
695300bf1aeSmrg  # on unsupported syntax...
696300bf1aeSmrg  _b='func_basename_result=${1##*/}'
697300bf1aeSmrg  _d='case $1 in
698300bf1aeSmrg        */*) func_dirname_result=${1%/*}$2 ;;
699300bf1aeSmrg        *  ) func_dirname_result=$3        ;;
700300bf1aeSmrg      esac'
701300bf1aeSmrg
702300bf1aeSmrgelse
703300bf1aeSmrg  # ...otherwise fall back to using sed.
704300bf1aeSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705300bf1aeSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706300bf1aeSmrg      if test "X$func_dirname_result" = "X$1"; then
707300bf1aeSmrg        func_dirname_result=$3
708300bf1aeSmrg      else
709300bf1aeSmrg        func_append func_dirname_result "$2"
710300bf1aeSmrg      fi'
711300bf1aeSmrgfi
712300bf1aeSmrg
713300bf1aeSmrgeval 'func_basename ()
714300bf1aeSmrg{
715300bf1aeSmrg    $debug_cmd
716300bf1aeSmrg
717300bf1aeSmrg    '"$_b"'
718300bf1aeSmrg}'
719300bf1aeSmrg
720300bf1aeSmrg
721300bf1aeSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722300bf1aeSmrg# -------------------------------------------
723300bf1aeSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724300bf1aeSmrg# otherwise set result to NONDIR_REPLACEMENT.
725300bf1aeSmrgeval 'func_dirname ()
726300bf1aeSmrg{
727300bf1aeSmrg    $debug_cmd
728300bf1aeSmrg
729300bf1aeSmrg    '"$_d"'
730300bf1aeSmrg}'
731300bf1aeSmrg
732300bf1aeSmrg
733300bf1aeSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734300bf1aeSmrg# --------------------------------------------------------
735300bf1aeSmrg# Perform func_basename and func_dirname in a single function
736300bf1aeSmrg# call:
737300bf1aeSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738300bf1aeSmrg#             add APPEND to the result, otherwise set result
739300bf1aeSmrg#             to NONDIR_REPLACEMENT.
740300bf1aeSmrg#             value returned in "$func_dirname_result"
741300bf1aeSmrg#   basename: Compute filename of FILE.
742300bf1aeSmrg#             value retuned in "$func_basename_result"
743300bf1aeSmrg# For efficiency, we do not delegate to the functions above but instead
744300bf1aeSmrg# duplicate the functionality here.
745300bf1aeSmrgeval 'func_dirname_and_basename ()
746300bf1aeSmrg{
747300bf1aeSmrg    $debug_cmd
748300bf1aeSmrg
749300bf1aeSmrg    '"$_b"'
750300bf1aeSmrg    '"$_d"'
751300bf1aeSmrg}'
752300bf1aeSmrg
753300bf1aeSmrg
754300bf1aeSmrg# func_echo ARG...
755300bf1aeSmrg# ----------------
756300bf1aeSmrg# Echo program name prefixed message.
757300bf1aeSmrgfunc_echo ()
758300bf1aeSmrg{
759300bf1aeSmrg    $debug_cmd
760300bf1aeSmrg
761300bf1aeSmrg    _G_message=$*
762300bf1aeSmrg
763300bf1aeSmrg    func_echo_IFS=$IFS
764300bf1aeSmrg    IFS=$nl
765300bf1aeSmrg    for _G_line in $_G_message; do
766300bf1aeSmrg      IFS=$func_echo_IFS
767300bf1aeSmrg      $ECHO "$progname: $_G_line"
768300bf1aeSmrg    done
769300bf1aeSmrg    IFS=$func_echo_IFS
770300bf1aeSmrg}
771300bf1aeSmrg
772300bf1aeSmrg
773300bf1aeSmrg# func_echo_all ARG...
774300bf1aeSmrg# --------------------
775300bf1aeSmrg# Invoke $ECHO with all args, space-separated.
776300bf1aeSmrgfunc_echo_all ()
777300bf1aeSmrg{
778300bf1aeSmrg    $ECHO "$*"
779300bf1aeSmrg}
780300bf1aeSmrg
781300bf1aeSmrg
782300bf1aeSmrg# func_echo_infix_1 INFIX ARG...
783300bf1aeSmrg# ------------------------------
784300bf1aeSmrg# Echo program name, followed by INFIX on the first line, with any
785300bf1aeSmrg# additional lines not showing INFIX.
786300bf1aeSmrgfunc_echo_infix_1 ()
787300bf1aeSmrg{
788300bf1aeSmrg    $debug_cmd
789300bf1aeSmrg
790300bf1aeSmrg    $require_term_colors
791300bf1aeSmrg
792300bf1aeSmrg    _G_infix=$1; shift
793300bf1aeSmrg    _G_indent=$_G_infix
794300bf1aeSmrg    _G_prefix="$progname: $_G_infix: "
795300bf1aeSmrg    _G_message=$*
796300bf1aeSmrg
797300bf1aeSmrg    # Strip color escape sequences before counting printable length
798300bf1aeSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799300bf1aeSmrg    do
800300bf1aeSmrg      test -n "$_G_tc" && {
801300bf1aeSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802300bf1aeSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803300bf1aeSmrg      }
804300bf1aeSmrg    done
805300bf1aeSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806300bf1aeSmrg
807300bf1aeSmrg    func_echo_infix_1_IFS=$IFS
808300bf1aeSmrg    IFS=$nl
809300bf1aeSmrg    for _G_line in $_G_message; do
810300bf1aeSmrg      IFS=$func_echo_infix_1_IFS
811300bf1aeSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812300bf1aeSmrg      _G_prefix=$_G_indent
813300bf1aeSmrg    done
814300bf1aeSmrg    IFS=$func_echo_infix_1_IFS
815300bf1aeSmrg}
816300bf1aeSmrg
817300bf1aeSmrg
818300bf1aeSmrg# func_error ARG...
819300bf1aeSmrg# -----------------
820300bf1aeSmrg# Echo program name prefixed message to standard error.
821300bf1aeSmrgfunc_error ()
822300bf1aeSmrg{
823300bf1aeSmrg    $debug_cmd
824300bf1aeSmrg
825300bf1aeSmrg    $require_term_colors
826300bf1aeSmrg
827300bf1aeSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828300bf1aeSmrg}
829300bf1aeSmrg
830300bf1aeSmrg
831300bf1aeSmrg# func_fatal_error ARG...
832300bf1aeSmrg# -----------------------
833300bf1aeSmrg# Echo program name prefixed message to standard error, and exit.
834300bf1aeSmrgfunc_fatal_error ()
835300bf1aeSmrg{
836300bf1aeSmrg    $debug_cmd
837300bf1aeSmrg
838300bf1aeSmrg    func_error "$*"
839300bf1aeSmrg    exit $EXIT_FAILURE
840300bf1aeSmrg}
841300bf1aeSmrg
842300bf1aeSmrg
843300bf1aeSmrg# func_grep EXPRESSION FILENAME
844300bf1aeSmrg# -----------------------------
8456aec45a7Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8466aec45a7Smrgfunc_grep ()
8476aec45a7Smrg{
848300bf1aeSmrg    $debug_cmd
849300bf1aeSmrg
8506aec45a7Smrg    $GREP "$1" "$2" >/dev/null 2>&1
8516aec45a7Smrg}
8526aec45a7Smrg
8536aec45a7Smrg
854300bf1aeSmrg# func_len STRING
855300bf1aeSmrg# ---------------
856300bf1aeSmrg# Set func_len_result to the length of STRING. STRING may not
857300bf1aeSmrg# start with a hyphen.
858300bf1aeSmrg  test -z "$_G_HAVE_XSI_OPS" \
859300bf1aeSmrg    && (eval 'x=a/b/c;
860300bf1aeSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861300bf1aeSmrg    && _G_HAVE_XSI_OPS=yes
862300bf1aeSmrg
863300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
864300bf1aeSmrg  eval 'func_len ()
865300bf1aeSmrg  {
866300bf1aeSmrg    $debug_cmd
867300bf1aeSmrg
868300bf1aeSmrg    func_len_result=${#1}
869300bf1aeSmrg  }'
870300bf1aeSmrgelse
871300bf1aeSmrg  func_len ()
872300bf1aeSmrg  {
873300bf1aeSmrg    $debug_cmd
874300bf1aeSmrg
875300bf1aeSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876300bf1aeSmrg  }
877300bf1aeSmrgfi
878300bf1aeSmrg
879300bf1aeSmrg
880300bf1aeSmrg# func_mkdir_p DIRECTORY-PATH
881300bf1aeSmrg# ---------------------------
8826aec45a7Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8836aec45a7Smrgfunc_mkdir_p ()
8846aec45a7Smrg{
885300bf1aeSmrg    $debug_cmd
886300bf1aeSmrg
887300bf1aeSmrg    _G_directory_path=$1
888300bf1aeSmrg    _G_dir_list=
8896aec45a7Smrg
890300bf1aeSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8916aec45a7Smrg
892300bf1aeSmrg      # Protect directory names starting with '-'
893300bf1aeSmrg      case $_G_directory_path in
894300bf1aeSmrg        -*) _G_directory_path=./$_G_directory_path ;;
8956aec45a7Smrg      esac
8966aec45a7Smrg
8976aec45a7Smrg      # While some portion of DIR does not yet exist...
898300bf1aeSmrg      while test ! -d "$_G_directory_path"; do
8996aec45a7Smrg        # ...make a list in topmost first order.  Use a colon delimited
9006aec45a7Smrg	# list incase some portion of path contains whitespace.
901300bf1aeSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
9026aec45a7Smrg
9036aec45a7Smrg        # If the last portion added has no slash in it, the list is done
904300bf1aeSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
9056aec45a7Smrg
9066aec45a7Smrg        # ...otherwise throw away the child directory and loop
907300bf1aeSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
9086aec45a7Smrg      done
909300bf1aeSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
9106aec45a7Smrg
911300bf1aeSmrg      func_mkdir_p_IFS=$IFS; IFS=:
912300bf1aeSmrg      for _G_dir in $_G_dir_list; do
913300bf1aeSmrg	IFS=$func_mkdir_p_IFS
914300bf1aeSmrg        # mkdir can fail with a 'File exist' error if two processes
9156aec45a7Smrg        # try to create one of the directories concurrently.  Don't
9166aec45a7Smrg        # stop in that case!
917300bf1aeSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
9186aec45a7Smrg      done
919300bf1aeSmrg      IFS=$func_mkdir_p_IFS
9206aec45a7Smrg
9216aec45a7Smrg      # Bail out if we (or some other process) failed to create a directory.
922300bf1aeSmrg      test -d "$_G_directory_path" || \
923300bf1aeSmrg        func_fatal_error "Failed to create '$1'"
9246aec45a7Smrg    fi
9256aec45a7Smrg}
926ab47cfaaSmrg
927ab47cfaaSmrg
928300bf1aeSmrg# func_mktempdir [BASENAME]
929300bf1aeSmrg# -------------------------
930ab47cfaaSmrg# Make a temporary directory that won't clash with other running
931ab47cfaaSmrg# libtool processes, and avoids race conditions if possible.  If
932300bf1aeSmrg# given, BASENAME is the basename for that directory.
933ab47cfaaSmrgfunc_mktempdir ()
934ab47cfaaSmrg{
935300bf1aeSmrg    $debug_cmd
936300bf1aeSmrg
937300bf1aeSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938ab47cfaaSmrg
939300bf1aeSmrg    if test : = "$opt_dry_run"; then
940ab47cfaaSmrg      # Return a directory name, but don't create it in dry-run mode
941300bf1aeSmrg      _G_tmpdir=$_G_template-$$
942ab47cfaaSmrg    else
943ab47cfaaSmrg
944ab47cfaaSmrg      # If mktemp works, use that first and foremost
945300bf1aeSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946ab47cfaaSmrg
947300bf1aeSmrg      if test ! -d "$_G_tmpdir"; then
9486aec45a7Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949300bf1aeSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950ab47cfaaSmrg
951300bf1aeSmrg        func_mktempdir_umask=`umask`
9526aec45a7Smrg        umask 0077
953300bf1aeSmrg        $MKDIR "$_G_tmpdir"
954300bf1aeSmrg        umask $func_mktempdir_umask
955ab47cfaaSmrg      fi
956ab47cfaaSmrg
957ab47cfaaSmrg      # If we're not in dry-run mode, bomb out on failure
958300bf1aeSmrg      test -d "$_G_tmpdir" || \
959300bf1aeSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960ab47cfaaSmrg    fi
961ab47cfaaSmrg
962300bf1aeSmrg    $ECHO "$_G_tmpdir"
963ab47cfaaSmrg}
964ab47cfaaSmrg
965ab47cfaaSmrg
966300bf1aeSmrg# func_normal_abspath PATH
967300bf1aeSmrg# ------------------------
968300bf1aeSmrg# Remove doubled-up and trailing slashes, "." path components,
969300bf1aeSmrg# and cancel out any ".." path components in PATH after making
970300bf1aeSmrg# it an absolute path.
971300bf1aeSmrgfunc_normal_abspath ()
972ab47cfaaSmrg{
973300bf1aeSmrg    $debug_cmd
9746aec45a7Smrg
975300bf1aeSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
976300bf1aeSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977300bf1aeSmrg    _G_pathcdr='s|^/[^/]*||'
978300bf1aeSmrg    _G_removedotparts=':dotsl
979300bf1aeSmrg		s|/\./|/|g
980300bf1aeSmrg		t dotsl
981300bf1aeSmrg		s|/\.$|/|'
982300bf1aeSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
983300bf1aeSmrg    _G_finalslash='s|/*$|/|'
984300bf1aeSmrg
985300bf1aeSmrg    # Start from root dir and reassemble the path.
986300bf1aeSmrg    func_normal_abspath_result=
987300bf1aeSmrg    func_normal_abspath_tpath=$1
988300bf1aeSmrg    func_normal_abspath_altnamespace=
989300bf1aeSmrg    case $func_normal_abspath_tpath in
990300bf1aeSmrg      "")
991300bf1aeSmrg        # Empty path, that just means $cwd.
992300bf1aeSmrg        func_stripname '' '/' "`pwd`"
993300bf1aeSmrg        func_normal_abspath_result=$func_stripname_result
994300bf1aeSmrg        return
995300bf1aeSmrg        ;;
996300bf1aeSmrg      # The next three entries are used to spot a run of precisely
997300bf1aeSmrg      # two leading slashes without using negated character classes;
998300bf1aeSmrg      # we take advantage of case's first-match behaviour.
999300bf1aeSmrg      ///*)
1000300bf1aeSmrg        # Unusual form of absolute path, do nothing.
1001300bf1aeSmrg        ;;
1002300bf1aeSmrg      //*)
1003300bf1aeSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004300bf1aeSmrg        # and for example Cygwin uses it to access remote file shares
1005300bf1aeSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006300bf1aeSmrg        func_normal_abspath_altnamespace=/
1007300bf1aeSmrg        ;;
1008300bf1aeSmrg      /*)
1009300bf1aeSmrg        # Absolute path, do nothing.
10106aec45a7Smrg        ;;
10116aec45a7Smrg      *)
1012300bf1aeSmrg        # Relative path, prepend $cwd.
1013300bf1aeSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014300bf1aeSmrg        ;;
1015ab47cfaaSmrg    esac
1016300bf1aeSmrg
1017300bf1aeSmrg    # Cancel out all the simple stuff to save iterations.  We also want
1018300bf1aeSmrg    # the path to end with a slash for ease of parsing, so make sure
1019300bf1aeSmrg    # there is one (and only one) here.
1020300bf1aeSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021300bf1aeSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022300bf1aeSmrg    while :; do
1023300bf1aeSmrg      # Processed it all yet?
1024300bf1aeSmrg      if test / = "$func_normal_abspath_tpath"; then
1025300bf1aeSmrg        # If we ascended to the root using ".." the result may be empty now.
1026300bf1aeSmrg        if test -z "$func_normal_abspath_result"; then
1027300bf1aeSmrg          func_normal_abspath_result=/
1028300bf1aeSmrg        fi
1029300bf1aeSmrg        break
1030300bf1aeSmrg      fi
1031300bf1aeSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032300bf1aeSmrg          -e "$_G_pathcar"`
1033300bf1aeSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034300bf1aeSmrg          -e "$_G_pathcdr"`
1035300bf1aeSmrg      # Figure out what to do with it
1036300bf1aeSmrg      case $func_normal_abspath_tcomponent in
1037300bf1aeSmrg        "")
1038300bf1aeSmrg          # Trailing empty path component, ignore it.
1039300bf1aeSmrg          ;;
1040300bf1aeSmrg        ..)
1041300bf1aeSmrg          # Parent dir; strip last assembled component from result.
1042300bf1aeSmrg          func_dirname "$func_normal_abspath_result"
1043300bf1aeSmrg          func_normal_abspath_result=$func_dirname_result
1044300bf1aeSmrg          ;;
1045300bf1aeSmrg        *)
1046300bf1aeSmrg          # Actual path component, append it.
1047300bf1aeSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048300bf1aeSmrg          ;;
1049300bf1aeSmrg      esac
1050300bf1aeSmrg    done
1051300bf1aeSmrg    # Restore leading double-slash if one was found on entry.
1052300bf1aeSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053300bf1aeSmrg}
1054300bf1aeSmrg
1055300bf1aeSmrg
1056300bf1aeSmrg# func_notquiet ARG...
1057300bf1aeSmrg# --------------------
1058300bf1aeSmrg# Echo program name prefixed message only when not in quiet mode.
1059300bf1aeSmrgfunc_notquiet ()
1060300bf1aeSmrg{
1061300bf1aeSmrg    $debug_cmd
1062300bf1aeSmrg
1063300bf1aeSmrg    $opt_quiet || func_echo ${1+"$@"}
1064300bf1aeSmrg
1065300bf1aeSmrg    # A bug in bash halts the script if the last line of a function
1066300bf1aeSmrg    # fails when set -e is in force, so we need another command to
1067300bf1aeSmrg    # work around that:
1068300bf1aeSmrg    :
1069300bf1aeSmrg}
1070300bf1aeSmrg
1071300bf1aeSmrg
1072300bf1aeSmrg# func_relative_path SRCDIR DSTDIR
1073300bf1aeSmrg# --------------------------------
1074300bf1aeSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075300bf1aeSmrgfunc_relative_path ()
1076300bf1aeSmrg{
1077300bf1aeSmrg    $debug_cmd
1078300bf1aeSmrg
1079300bf1aeSmrg    func_relative_path_result=
1080300bf1aeSmrg    func_normal_abspath "$1"
1081300bf1aeSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082300bf1aeSmrg    func_normal_abspath "$2"
1083300bf1aeSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1084300bf1aeSmrg
1085300bf1aeSmrg    # Ascend the tree starting from libdir
1086300bf1aeSmrg    while :; do
1087300bf1aeSmrg      # check if we have found a prefix of bindir
1088300bf1aeSmrg      case $func_relative_path_tbindir in
1089300bf1aeSmrg        $func_relative_path_tlibdir)
1090300bf1aeSmrg          # found an exact match
1091300bf1aeSmrg          func_relative_path_tcancelled=
1092300bf1aeSmrg          break
1093300bf1aeSmrg          ;;
1094300bf1aeSmrg        $func_relative_path_tlibdir*)
1095300bf1aeSmrg          # found a matching prefix
1096300bf1aeSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097300bf1aeSmrg          func_relative_path_tcancelled=$func_stripname_result
1098300bf1aeSmrg          if test -z "$func_relative_path_result"; then
1099300bf1aeSmrg            func_relative_path_result=.
1100300bf1aeSmrg          fi
1101300bf1aeSmrg          break
1102300bf1aeSmrg          ;;
1103300bf1aeSmrg        *)
1104300bf1aeSmrg          func_dirname $func_relative_path_tlibdir
1105300bf1aeSmrg          func_relative_path_tlibdir=$func_dirname_result
1106300bf1aeSmrg          if test -z "$func_relative_path_tlibdir"; then
1107300bf1aeSmrg            # Have to descend all the way to the root!
1108300bf1aeSmrg            func_relative_path_result=../$func_relative_path_result
1109300bf1aeSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110300bf1aeSmrg            break
1111300bf1aeSmrg          fi
1112300bf1aeSmrg          func_relative_path_result=../$func_relative_path_result
1113300bf1aeSmrg          ;;
1114300bf1aeSmrg      esac
1115300bf1aeSmrg    done
1116300bf1aeSmrg
1117300bf1aeSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1118300bf1aeSmrg    func_stripname '' '/' "$func_relative_path_result"
1119300bf1aeSmrg    func_relative_path_result=$func_stripname_result
1120300bf1aeSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121300bf1aeSmrg    if test -n "$func_stripname_result"; then
1122300bf1aeSmrg      func_append func_relative_path_result "/$func_stripname_result"
1123300bf1aeSmrg    fi
1124300bf1aeSmrg
1125300bf1aeSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126300bf1aeSmrg    if test -n "$func_relative_path_result"; then
1127300bf1aeSmrg      func_stripname './' '' "$func_relative_path_result"
1128300bf1aeSmrg      func_relative_path_result=$func_stripname_result
1129300bf1aeSmrg    fi
1130300bf1aeSmrg
1131300bf1aeSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132300bf1aeSmrg
1133300bf1aeSmrg    :
1134ab47cfaaSmrg}
1135ab47cfaaSmrg
1136ab47cfaaSmrg
11372b2b4fcbSmrg# func_quote_portable EVAL ARG
11382b2b4fcbSmrg# ----------------------------
11392b2b4fcbSmrg# Internal function to portably implement func_quote_arg.  Note that we still
11402b2b4fcbSmrg# keep attention to performance here so we as much as possible try to avoid
11412b2b4fcbSmrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11422b2b4fcbSmrgfunc_quote_portable ()
1143300bf1aeSmrg{
1144300bf1aeSmrg    $debug_cmd
1145300bf1aeSmrg
11462b2b4fcbSmrg    $require_check_ifs_backslash
11472b2b4fcbSmrg
11482b2b4fcbSmrg    func_quote_portable_result=$2
11492b2b4fcbSmrg
11502b2b4fcbSmrg    # one-time-loop (easy break)
11512b2b4fcbSmrg    while true
11522b2b4fcbSmrg    do
11532b2b4fcbSmrg      if $1; then
11542b2b4fcbSmrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11552b2b4fcbSmrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11562b2b4fcbSmrg        break
1157300bf1aeSmrg      fi
1158300bf1aeSmrg
11592b2b4fcbSmrg      # Quote for eval.
11602b2b4fcbSmrg      case $func_quote_portable_result in
11612b2b4fcbSmrg        *[\\\`\"\$]*)
11622b2b4fcbSmrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11632b2b4fcbSmrg          # contains the shell wildcard characters.
11642b2b4fcbSmrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11652b2b4fcbSmrg            :*|*[\[\*\?]*)
11662b2b4fcbSmrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11672b2b4fcbSmrg                  | $SED "$sed_quote_subst"`
11682b2b4fcbSmrg              break
11692b2b4fcbSmrg              ;;
11702b2b4fcbSmrg          esac
11712b2b4fcbSmrg
11722b2b4fcbSmrg          func_quote_portable_old_IFS=$IFS
11732b2b4fcbSmrg          for _G_char in '\' '`' '"' '$'
11742b2b4fcbSmrg          do
11752b2b4fcbSmrg            # STATE($1) PREV($2) SEPARATOR($3)
11762b2b4fcbSmrg            set start "" ""
11772b2b4fcbSmrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11782b2b4fcbSmrg            IFS=$_G_char
11792b2b4fcbSmrg            for _G_part in $func_quote_portable_result
11802b2b4fcbSmrg            do
11812b2b4fcbSmrg              case $1 in
11822b2b4fcbSmrg              quote)
11832b2b4fcbSmrg                func_append func_quote_portable_result "$3$2"
11842b2b4fcbSmrg                set quote "$_G_part" "\\$_G_char"
11852b2b4fcbSmrg                ;;
11862b2b4fcbSmrg              start)
11872b2b4fcbSmrg                set first "" ""
11882b2b4fcbSmrg                func_quote_portable_result=
11892b2b4fcbSmrg                ;;
11902b2b4fcbSmrg              first)
11912b2b4fcbSmrg                set quote "$_G_part" ""
11922b2b4fcbSmrg                ;;
11932b2b4fcbSmrg              esac
11942b2b4fcbSmrg            done
11952b2b4fcbSmrg          done
11962b2b4fcbSmrg          IFS=$func_quote_portable_old_IFS
1197300bf1aeSmrg          ;;
11982b2b4fcbSmrg        *) ;;
1199300bf1aeSmrg      esac
12002b2b4fcbSmrg      break
1201300bf1aeSmrg    done
12022b2b4fcbSmrg
12032b2b4fcbSmrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12042b2b4fcbSmrg    case $func_quote_portable_result in
12052b2b4fcbSmrg      # double-quote args containing shell metacharacters to delay
12062b2b4fcbSmrg      # word splitting, command substitution and variable expansion
12072b2b4fcbSmrg      # for a subsequent eval.
12082b2b4fcbSmrg      # many bourne shells cannot handle close brackets correctly
12092b2b4fcbSmrg      # in scan sets, so we specify it separately.
12102b2b4fcbSmrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12112b2b4fcbSmrg        func_quote_portable_result=\"$func_quote_portable_result\"
12122b2b4fcbSmrg        ;;
12132b2b4fcbSmrg    esac
1214300bf1aeSmrg}
1215300bf1aeSmrg
1216300bf1aeSmrg
12172b2b4fcbSmrg# func_quotefast_eval ARG
12182b2b4fcbSmrg# -----------------------
12192b2b4fcbSmrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12202b2b4fcbSmrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12212b2b4fcbSmrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12222b2b4fcbSmrg  printf -v _GL_test_printf_tilde %q '~'
12232b2b4fcbSmrg  if test '\~' = "$_GL_test_printf_tilde"; then
12242b2b4fcbSmrg    func_quotefast_eval ()
12252b2b4fcbSmrg    {
12262b2b4fcbSmrg      printf -v func_quotefast_eval_result %q "$1"
12272b2b4fcbSmrg    }
12282b2b4fcbSmrg  else
12292b2b4fcbSmrg    # Broken older Bash implementations.  Make those faster too if possible.
12302b2b4fcbSmrg    func_quotefast_eval ()
12312b2b4fcbSmrg    {
12322b2b4fcbSmrg      case $1 in
12332b2b4fcbSmrg        '~'*)
12342b2b4fcbSmrg          func_quote_portable false "$1"
12352b2b4fcbSmrg          func_quotefast_eval_result=$func_quote_portable_result
12362b2b4fcbSmrg          ;;
12372b2b4fcbSmrg        *)
12382b2b4fcbSmrg          printf -v func_quotefast_eval_result %q "$1"
12392b2b4fcbSmrg          ;;
12402b2b4fcbSmrg      esac
12412b2b4fcbSmrg    }
12422b2b4fcbSmrg  fi
12432b2b4fcbSmrgelse
12442b2b4fcbSmrg  func_quotefast_eval ()
12452b2b4fcbSmrg  {
12462b2b4fcbSmrg    func_quote_portable false "$1"
12472b2b4fcbSmrg    func_quotefast_eval_result=$func_quote_portable_result
12482b2b4fcbSmrg  }
12492b2b4fcbSmrgfi
1250300bf1aeSmrg
12512b2b4fcbSmrg
12522b2b4fcbSmrg# func_quote_arg MODEs ARG
12532b2b4fcbSmrg# ------------------------
12542b2b4fcbSmrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12552b2b4fcbSmrg# specifiers listed below separated by ',' character.  This function returns two
12562b2b4fcbSmrg# values:
12572b2b4fcbSmrg#   i) func_quote_arg_result
12582b2b4fcbSmrg#      double-quoted (when needed), suitable for a subsequent eval
12592b2b4fcbSmrg#  ii) func_quote_arg_unquoted_result
12602b2b4fcbSmrg#      has all characters that are still active within double
12612b2b4fcbSmrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12622b2b4fcbSmrg#
12632b2b4fcbSmrg# Available modes:
12642b2b4fcbSmrg# ----------------
12652b2b4fcbSmrg# 'eval' (default)
12662b2b4fcbSmrg#       - escape shell special characters
12672b2b4fcbSmrg# 'expand'
12682b2b4fcbSmrg#       - the same as 'eval';  but do not quote variable references
12692b2b4fcbSmrg# 'pretty'
12702b2b4fcbSmrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12712b2b4fcbSmrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12722b2b4fcbSmrg#         of 'echo a\ b'.  This is slower than default on some shells.
12732b2b4fcbSmrg# 'unquoted'
12742b2b4fcbSmrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12752b2b4fcbSmrg#         wrapping double-quotes.
12762b2b4fcbSmrg#
12772b2b4fcbSmrg# Examples for 'func_quote_arg pretty,unquoted string':
12782b2b4fcbSmrg#
12792b2b4fcbSmrg#   string      | *_result              | *_unquoted_result
12802b2b4fcbSmrg#   ------------+-----------------------+-------------------
12812b2b4fcbSmrg#   "           | \"                    | \"
12822b2b4fcbSmrg#   a b         | "a b"                 | a b
12832b2b4fcbSmrg#   "a b"       | "\"a b\""             | \"a b\"
12842b2b4fcbSmrg#   *           | "*"                   | *
12852b2b4fcbSmrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12862b2b4fcbSmrg#
12872b2b4fcbSmrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12882b2b4fcbSmrg#
12892b2b4fcbSmrg#   string        |   *_result          |  *_unquoted_result
12902b2b4fcbSmrg#   --------------+---------------------+--------------------
12912b2b4fcbSmrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12922b2b4fcbSmrgfunc_quote_arg ()
12932b2b4fcbSmrg{
12942b2b4fcbSmrg    _G_quote_expand=false
12952b2b4fcbSmrg    case ,$1, in
12962b2b4fcbSmrg      *,expand,*)
12972b2b4fcbSmrg        _G_quote_expand=:
12982b2b4fcbSmrg        ;;
12996aec45a7Smrg    esac
13006aec45a7Smrg
13012b2b4fcbSmrg    case ,$1, in
13022b2b4fcbSmrg      *,pretty,*|*,expand,*|*,unquoted,*)
13032b2b4fcbSmrg        func_quote_portable $_G_quote_expand "$2"
13042b2b4fcbSmrg        func_quote_arg_result=$func_quote_portable_result
13052b2b4fcbSmrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13062b2b4fcbSmrg        ;;
13072b2b4fcbSmrg      *)
13082b2b4fcbSmrg        # Faster quote-for-eval for some shells.
13092b2b4fcbSmrg        func_quotefast_eval "$2"
13102b2b4fcbSmrg        func_quote_arg_result=$func_quotefast_eval_result
13116aec45a7Smrg        ;;
13126aec45a7Smrg    esac
13132b2b4fcbSmrg}
13142b2b4fcbSmrg
13156aec45a7Smrg
13162b2b4fcbSmrg# func_quote MODEs ARGs...
13172b2b4fcbSmrg# ------------------------
13182b2b4fcbSmrg# Quote all ARGs to be evaled later and join them into single command.  See
13192b2b4fcbSmrg# func_quote_arg's description for more info.
13202b2b4fcbSmrgfunc_quote ()
13212b2b4fcbSmrg{
13222b2b4fcbSmrg    $debug_cmd
13232b2b4fcbSmrg    _G_func_quote_mode=$1 ; shift
13242b2b4fcbSmrg    func_quote_result=
13252b2b4fcbSmrg    while test 0 -lt $#; do
13262b2b4fcbSmrg      func_quote_arg "$_G_func_quote_mode" "$1"
13272b2b4fcbSmrg      if test -n "$func_quote_result"; then
13282b2b4fcbSmrg        func_append func_quote_result " $func_quote_arg_result"
13292b2b4fcbSmrg      else
13302b2b4fcbSmrg        func_append func_quote_result "$func_quote_arg_result"
13312b2b4fcbSmrg      fi
13322b2b4fcbSmrg      shift
13332b2b4fcbSmrg    done
1334300bf1aeSmrg}
1335300bf1aeSmrg
1336300bf1aeSmrg
1337300bf1aeSmrg# func_stripname PREFIX SUFFIX NAME
1338300bf1aeSmrg# ---------------------------------
1339300bf1aeSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340300bf1aeSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1341300bf1aeSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342300bf1aeSmrg# dot (in which case that matches only a dot).
1343300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344300bf1aeSmrg  eval 'func_stripname ()
1345300bf1aeSmrg  {
1346300bf1aeSmrg    $debug_cmd
1347300bf1aeSmrg
1348300bf1aeSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349300bf1aeSmrg    # positional parameters, so assign one to ordinary variable first.
1350300bf1aeSmrg    func_stripname_result=$3
1351300bf1aeSmrg    func_stripname_result=${func_stripname_result#"$1"}
1352300bf1aeSmrg    func_stripname_result=${func_stripname_result%"$2"}
1353300bf1aeSmrg  }'
1354300bf1aeSmrgelse
1355300bf1aeSmrg  func_stripname ()
1356300bf1aeSmrg  {
1357300bf1aeSmrg    $debug_cmd
1358300bf1aeSmrg
1359300bf1aeSmrg    case $2 in
1360300bf1aeSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361300bf1aeSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362300bf1aeSmrg    esac
1363300bf1aeSmrg  }
1364300bf1aeSmrgfi
1365300bf1aeSmrg
1366300bf1aeSmrg
1367300bf1aeSmrg# func_show_eval CMD [FAIL_EXP]
1368300bf1aeSmrg# -----------------------------
1369300bf1aeSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370300bf1aeSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371300bf1aeSmrg# is given, then evaluate it.
1372300bf1aeSmrgfunc_show_eval ()
1373300bf1aeSmrg{
1374300bf1aeSmrg    $debug_cmd
1375300bf1aeSmrg
1376300bf1aeSmrg    _G_cmd=$1
1377300bf1aeSmrg    _G_fail_exp=${2-':'}
1378300bf1aeSmrg
13792b2b4fcbSmrg    func_quote_arg pretty,expand "$_G_cmd"
13802b2b4fcbSmrg    eval "func_notquiet $func_quote_arg_result"
1381300bf1aeSmrg
1382300bf1aeSmrg    $opt_dry_run || {
1383300bf1aeSmrg      eval "$_G_cmd"
1384300bf1aeSmrg      _G_status=$?
1385300bf1aeSmrg      if test 0 -ne "$_G_status"; then
1386300bf1aeSmrg	eval "(exit $_G_status); $_G_fail_exp"
1387300bf1aeSmrg      fi
1388300bf1aeSmrg    }
1389300bf1aeSmrg}
1390300bf1aeSmrg
1391300bf1aeSmrg
1392300bf1aeSmrg# func_show_eval_locale CMD [FAIL_EXP]
1393300bf1aeSmrg# ------------------------------------
1394300bf1aeSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395300bf1aeSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396300bf1aeSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397300bf1aeSmrgfunc_show_eval_locale ()
1398300bf1aeSmrg{
1399300bf1aeSmrg    $debug_cmd
1400300bf1aeSmrg
1401300bf1aeSmrg    _G_cmd=$1
1402300bf1aeSmrg    _G_fail_exp=${2-':'}
1403300bf1aeSmrg
1404300bf1aeSmrg    $opt_quiet || {
14052b2b4fcbSmrg      func_quote_arg expand,pretty "$_G_cmd"
14062b2b4fcbSmrg      eval "func_echo $func_quote_arg_result"
1407300bf1aeSmrg    }
1408300bf1aeSmrg
1409300bf1aeSmrg    $opt_dry_run || {
1410300bf1aeSmrg      eval "$_G_user_locale
1411300bf1aeSmrg	    $_G_cmd"
1412300bf1aeSmrg      _G_status=$?
1413300bf1aeSmrg      eval "$_G_safe_locale"
1414300bf1aeSmrg      if test 0 -ne "$_G_status"; then
1415300bf1aeSmrg	eval "(exit $_G_status); $_G_fail_exp"
1416300bf1aeSmrg      fi
1417300bf1aeSmrg    }
1418300bf1aeSmrg}
1419300bf1aeSmrg
1420300bf1aeSmrg
1421300bf1aeSmrg# func_tr_sh
1422300bf1aeSmrg# ----------
1423300bf1aeSmrg# Turn $1 into a string suitable for a shell variable name.
1424300bf1aeSmrg# Result is stored in $func_tr_sh_result.  All characters
1425300bf1aeSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426300bf1aeSmrg# if $1 begins with a digit, a '_' is prepended as well.
1427300bf1aeSmrgfunc_tr_sh ()
1428300bf1aeSmrg{
1429300bf1aeSmrg    $debug_cmd
1430300bf1aeSmrg
1431300bf1aeSmrg    case $1 in
1432300bf1aeSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433300bf1aeSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434300bf1aeSmrg      ;;
1435300bf1aeSmrg    * )
1436300bf1aeSmrg      func_tr_sh_result=$1
1437300bf1aeSmrg      ;;
1438300bf1aeSmrg    esac
1439300bf1aeSmrg}
1440300bf1aeSmrg
1441300bf1aeSmrg
1442300bf1aeSmrg# func_verbose ARG...
1443300bf1aeSmrg# -------------------
1444300bf1aeSmrg# Echo program name prefixed message in verbose mode only.
1445300bf1aeSmrgfunc_verbose ()
1446300bf1aeSmrg{
1447300bf1aeSmrg    $debug_cmd
1448300bf1aeSmrg
1449300bf1aeSmrg    $opt_verbose && func_echo "$*"
1450300bf1aeSmrg
1451300bf1aeSmrg    :
1452300bf1aeSmrg}
1453300bf1aeSmrg
1454300bf1aeSmrg
1455300bf1aeSmrg# func_warn_and_continue ARG...
1456300bf1aeSmrg# -----------------------------
1457300bf1aeSmrg# Echo program name prefixed warning message to standard error.
1458300bf1aeSmrgfunc_warn_and_continue ()
1459300bf1aeSmrg{
1460300bf1aeSmrg    $debug_cmd
1461300bf1aeSmrg
1462300bf1aeSmrg    $require_term_colors
1463300bf1aeSmrg
1464300bf1aeSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465300bf1aeSmrg}
1466300bf1aeSmrg
1467300bf1aeSmrg
1468300bf1aeSmrg# func_warning CATEGORY ARG...
1469300bf1aeSmrg# ----------------------------
1470300bf1aeSmrg# Echo program name prefixed warning message to standard error. Warning
1471300bf1aeSmrg# messages can be filtered according to CATEGORY, where this function
1472300bf1aeSmrg# elides messages where CATEGORY is not listed in the global variable
1473300bf1aeSmrg# 'opt_warning_types'.
1474300bf1aeSmrgfunc_warning ()
1475300bf1aeSmrg{
1476300bf1aeSmrg    $debug_cmd
1477300bf1aeSmrg
1478300bf1aeSmrg    # CATEGORY must be in the warning_categories list!
1479300bf1aeSmrg    case " $warning_categories " in
1480300bf1aeSmrg      *" $1 "*) ;;
1481300bf1aeSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1482300bf1aeSmrg    esac
1483300bf1aeSmrg
1484300bf1aeSmrg    _G_category=$1
1485300bf1aeSmrg    shift
1486300bf1aeSmrg
1487300bf1aeSmrg    case " $opt_warning_types " in
1488300bf1aeSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489300bf1aeSmrg    esac
1490ab47cfaaSmrg}
1491ab47cfaaSmrg
1492ab47cfaaSmrg
1493300bf1aeSmrg# func_sort_ver VER1 VER2
1494300bf1aeSmrg# -----------------------
1495300bf1aeSmrg# 'sort -V' is not generally available.
1496300bf1aeSmrg# Note this deviates from the version comparison in automake
1497300bf1aeSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498300bf1aeSmrg# but this should suffice as we won't be specifying old
1499300bf1aeSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1500300bf1aeSmrg# If we did want full compatibility then we should probably
1501300bf1aeSmrg# use m4_version_compare from autoconf.
1502300bf1aeSmrgfunc_sort_ver ()
1503300bf1aeSmrg{
1504300bf1aeSmrg    $debug_cmd
1505300bf1aeSmrg
1506300bf1aeSmrg    printf '%s\n%s\n' "$1" "$2" \
1507300bf1aeSmrg      | 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
1508300bf1aeSmrg}
1509300bf1aeSmrg
1510300bf1aeSmrg# func_lt_ver PREV CURR
1511300bf1aeSmrg# ---------------------
1512300bf1aeSmrg# Return true if PREV and CURR are in the correct order according to
1513300bf1aeSmrg# func_sort_ver, otherwise false.  Use it like this:
1514300bf1aeSmrg#
1515300bf1aeSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516300bf1aeSmrgfunc_lt_ver ()
1517300bf1aeSmrg{
1518300bf1aeSmrg    $debug_cmd
1519300bf1aeSmrg
1520300bf1aeSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521300bf1aeSmrg}
1522300bf1aeSmrg
1523300bf1aeSmrg
1524300bf1aeSmrg# Local variables:
1525300bf1aeSmrg# mode: shell-script
1526300bf1aeSmrg# sh-indentation: 2
1527300bf1aeSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528300bf1aeSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529300bf1aeSmrg# time-stamp-time-zone: "UTC"
1530300bf1aeSmrg# End:
1531300bf1aeSmrg#! /bin/sh
1532300bf1aeSmrg
1533300bf1aeSmrg# A portable, pluggable option parser for Bourne shell.
1534300bf1aeSmrg# Written by Gary V. Vaughan, 2010
1535300bf1aeSmrg
15362b2b4fcbSmrg# This is free software.  There is NO warranty; not even for
15372b2b4fcbSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15382b2b4fcbSmrg#
15392b2b4fcbSmrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
15402b2b4fcbSmrg#
15412b2b4fcbSmrg# This file is dual licensed under the terms of the MIT license
15422b2b4fcbSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
15432b2b4fcbSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15442b2b4fcbSmrg# these licenses when using or redistributing this software or any of
15452b2b4fcbSmrg# the files within it.  See the URLs above, or the file `LICENSE`
15462b2b4fcbSmrg# included in the Bootstrap distribution for the full license texts.
1547300bf1aeSmrg
15482b2b4fcbSmrg# Please report bugs or propose patches to:
15492b2b4fcbSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550300bf1aeSmrg
15512b2b4fcbSmrg# Set a version string for this script.
15522b2b4fcbSmrgscriptversion=2019-02-19.15; # UTC
1553300bf1aeSmrg
1554300bf1aeSmrg
1555300bf1aeSmrg## ------ ##
1556300bf1aeSmrg## Usage. ##
1557300bf1aeSmrg## ------ ##
1558300bf1aeSmrg
1559300bf1aeSmrg# This file is a library for parsing options in your shell scripts along
1560300bf1aeSmrg# with assorted other useful supporting features that you can make use
1561300bf1aeSmrg# of too.
1562300bf1aeSmrg#
1563300bf1aeSmrg# For the simplest scripts you might need only:
1564300bf1aeSmrg#
1565300bf1aeSmrg#   #!/bin/sh
1566300bf1aeSmrg#   . relative/path/to/funclib.sh
1567300bf1aeSmrg#   . relative/path/to/options-parser
1568300bf1aeSmrg#   scriptversion=1.0
1569300bf1aeSmrg#   func_options ${1+"$@"}
1570300bf1aeSmrg#   eval set dummy "$func_options_result"; shift
1571300bf1aeSmrg#   ...rest of your script...
1572300bf1aeSmrg#
1573300bf1aeSmrg# In order for the '--version' option to work, you will need to have a
1574300bf1aeSmrg# suitably formatted comment like the one at the top of this file
15752b2b4fcbSmrg# starting with '# Written by ' and ending with '# Copyright'.
1576300bf1aeSmrg#
1577300bf1aeSmrg# For '-h' and '--help' to work, you will also need a one line
1578300bf1aeSmrg# description of your script's purpose in a comment directly above the
1579300bf1aeSmrg# '# Written by ' line, like the one at the top of this file.
1580300bf1aeSmrg#
1581300bf1aeSmrg# The default options also support '--debug', which will turn on shell
1582300bf1aeSmrg# execution tracing (see the comment above debug_cmd below for another
1583300bf1aeSmrg# use), and '--verbose' and the func_verbose function to allow your script
1584300bf1aeSmrg# to display verbose messages only when your user has specified
1585300bf1aeSmrg# '--verbose'.
1586300bf1aeSmrg#
15872b2b4fcbSmrg# After sourcing this file, you can plug in processing for additional
1588300bf1aeSmrg# options by amending the variables from the 'Configuration' section
1589300bf1aeSmrg# below, and following the instructions in the 'Option parsing'
1590300bf1aeSmrg# section further down.
1591300bf1aeSmrg
1592300bf1aeSmrg## -------------- ##
1593300bf1aeSmrg## Configuration. ##
1594300bf1aeSmrg## -------------- ##
1595300bf1aeSmrg
1596300bf1aeSmrg# You should override these variables in your script after sourcing this
1597300bf1aeSmrg# file so that they reflect the customisations you have added to the
1598300bf1aeSmrg# option parser.
1599300bf1aeSmrg
1600300bf1aeSmrg# The usage line for option parsing errors and the start of '-h' and
1601300bf1aeSmrg# '--help' output messages. You can embed shell variables for delayed
1602300bf1aeSmrg# expansion at the time the message is displayed, but you will need to
1603300bf1aeSmrg# quote other shell meta-characters carefully to prevent them being
1604300bf1aeSmrg# expanded when the contents are evaled.
1605300bf1aeSmrgusage='$progpath [OPTION]...'
1606300bf1aeSmrg
1607300bf1aeSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1608300bf1aeSmrg# override it after sourcing this library to reflect the full set of
1609300bf1aeSmrg# options your script accepts.
1610300bf1aeSmrgusage_message="\
1611300bf1aeSmrg       --debug        enable verbose shell tracing
1612300bf1aeSmrg   -W, --warnings=CATEGORY
1613300bf1aeSmrg                      report the warnings falling in CATEGORY [all]
1614300bf1aeSmrg   -v, --verbose      verbosely report processing
1615300bf1aeSmrg       --version      print version information and exit
1616300bf1aeSmrg   -h, --help         print short or long help message and exit
1617300bf1aeSmrg"
1618300bf1aeSmrg
1619300bf1aeSmrg# Additional text appended to 'usage_message' in response to '--help'.
1620300bf1aeSmrglong_help_message="
1621300bf1aeSmrgWarning categories include:
1622300bf1aeSmrg       'all'          show all warnings
1623300bf1aeSmrg       'none'         turn off all the warnings
1624300bf1aeSmrg       'error'        warnings are treated as fatal errors"
1625300bf1aeSmrg
1626300bf1aeSmrg# Help message printed before fatal option parsing errors.
1627300bf1aeSmrgfatal_help="Try '\$progname --help' for more information."
1628300bf1aeSmrg
1629300bf1aeSmrg
1630300bf1aeSmrg
1631300bf1aeSmrg## ------------------------- ##
1632300bf1aeSmrg## Hook function management. ##
1633300bf1aeSmrg## ------------------------- ##
1634300bf1aeSmrg
1635300bf1aeSmrg# This section contains functions for adding, removing, and running hooks
16362b2b4fcbSmrg# in the main code.  A hook is just a list of function names that can be
16372b2b4fcbSmrg# run in order later on.
1638300bf1aeSmrg
1639300bf1aeSmrg# func_hookable FUNC_NAME
1640300bf1aeSmrg# -----------------------
1641300bf1aeSmrg# Declare that FUNC_NAME will run hooks added with
1642300bf1aeSmrg# 'func_add_hook FUNC_NAME ...'.
1643300bf1aeSmrgfunc_hookable ()
1644300bf1aeSmrg{
1645300bf1aeSmrg    $debug_cmd
1646300bf1aeSmrg
1647300bf1aeSmrg    func_append hookable_fns " $1"
1648300bf1aeSmrg}
1649300bf1aeSmrg
1650300bf1aeSmrg
1651300bf1aeSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1652300bf1aeSmrg# ---------------------------------
1653300bf1aeSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654300bf1aeSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1655300bf1aeSmrgfunc_add_hook ()
1656300bf1aeSmrg{
1657300bf1aeSmrg    $debug_cmd
1658300bf1aeSmrg
1659300bf1aeSmrg    case " $hookable_fns " in
1660300bf1aeSmrg      *" $1 "*) ;;
1661300bf1aeSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662300bf1aeSmrg    esac
1663300bf1aeSmrg
1664300bf1aeSmrg    eval func_append ${1}_hooks '" $2"'
1665300bf1aeSmrg}
1666300bf1aeSmrg
1667300bf1aeSmrg
1668300bf1aeSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669300bf1aeSmrg# ------------------------------------
16702b2b4fcbSmrg# Remove HOOK_FUNC from the list of hook functions to be called by
16712b2b4fcbSmrg# FUNC_NAME.
1672300bf1aeSmrgfunc_remove_hook ()
1673300bf1aeSmrg{
1674300bf1aeSmrg    $debug_cmd
1675300bf1aeSmrg
1676300bf1aeSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677300bf1aeSmrg}
1678300bf1aeSmrg
1679300bf1aeSmrg
16802b2b4fcbSmrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16812b2b4fcbSmrg# ---------------------------------------------
16822b2b4fcbSmrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16832b2b4fcbSmrg# *_result variable of FUNC_NAME_B.
16842b2b4fcbSmrgfunc_propagate_result ()
16852b2b4fcbSmrg{
16862b2b4fcbSmrg    $debug_cmd
16872b2b4fcbSmrg
16882b2b4fcbSmrg    func_propagate_result_result=:
16892b2b4fcbSmrg    if eval "test \"\${${1}_result+set}\" = set"
16902b2b4fcbSmrg    then
16912b2b4fcbSmrg      eval "${2}_result=\$${1}_result"
16922b2b4fcbSmrg    else
16932b2b4fcbSmrg      func_propagate_result_result=false
16942b2b4fcbSmrg    fi
16952b2b4fcbSmrg}
16962b2b4fcbSmrg
16972b2b4fcbSmrg
1698300bf1aeSmrg# func_run_hooks FUNC_NAME [ARG]...
1699300bf1aeSmrg# ---------------------------------
1700300bf1aeSmrg# Run all hook functions registered to FUNC_NAME.
17012b2b4fcbSmrg# It's assumed that the list of hook functions contains nothing more
1702300bf1aeSmrg# than a whitespace-delimited list of legal shell function names, and
1703300bf1aeSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1704300bf1aeSmrg# whitespace.
1705300bf1aeSmrgfunc_run_hooks ()
1706300bf1aeSmrg{
1707300bf1aeSmrg    $debug_cmd
1708300bf1aeSmrg
1709300bf1aeSmrg    case " $hookable_fns " in
1710300bf1aeSmrg      *" $1 "*) ;;
17112b2b4fcbSmrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712300bf1aeSmrg    esac
1713300bf1aeSmrg
1714300bf1aeSmrg    eval _G_hook_fns=\$$1_hooks; shift
1715300bf1aeSmrg
1716300bf1aeSmrg    for _G_hook in $_G_hook_fns; do
17172b2b4fcbSmrg      func_unset "${_G_hook}_result"
17182b2b4fcbSmrg      eval $_G_hook '${1+"$@"}'
17192b2b4fcbSmrg      func_propagate_result $_G_hook func_run_hooks
17202b2b4fcbSmrg      if $func_propagate_result_result; then
17212b2b4fcbSmrg        eval set dummy "$func_run_hooks_result"; shift
17222b2b4fcbSmrg      fi
1723300bf1aeSmrg    done
1724300bf1aeSmrg}
1725300bf1aeSmrg
1726300bf1aeSmrg
1727300bf1aeSmrg
1728300bf1aeSmrg## --------------- ##
1729300bf1aeSmrg## Option parsing. ##
1730300bf1aeSmrg## --------------- ##
1731300bf1aeSmrg
1732300bf1aeSmrg# In order to add your own option parsing hooks, you must accept the
17332b2b4fcbSmrg# full positional parameter list from your hook function.  You may remove
17342b2b4fcbSmrg# or edit any options that you action, and then pass back the remaining
17352b2b4fcbSmrg# unprocessed options in '<hooked_function_name>_result', escaped
17362b2b4fcbSmrg# suitably for 'eval'.
17372b2b4fcbSmrg#
17382b2b4fcbSmrg# The '<hooked_function_name>_result' variable is automatically unset
17392b2b4fcbSmrg# before your hook gets called; for best performance, only set the
17402b2b4fcbSmrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17412b2b4fcbSmrg# function unnecessarily because it can be an expensive operation on some
17422b2b4fcbSmrg# machines).
17432b2b4fcbSmrg#
17442b2b4fcbSmrg# Like this:
1745300bf1aeSmrg#
1746300bf1aeSmrg#    my_options_prep ()
1747300bf1aeSmrg#    {
1748300bf1aeSmrg#        $debug_cmd
1749300bf1aeSmrg#
1750300bf1aeSmrg#        # Extend the existing usage message.
1751300bf1aeSmrg#        usage_message=$usage_message'
1752300bf1aeSmrg#      -s, --silent       don'\''t print informational messages
1753300bf1aeSmrg#    '
17542b2b4fcbSmrg#        # No change in '$@' (ignored completely by this hook).  Leave
17552b2b4fcbSmrg#        # my_options_prep_result variable intact.
1756300bf1aeSmrg#    }
1757300bf1aeSmrg#    func_add_hook func_options_prep my_options_prep
1758300bf1aeSmrg#
1759300bf1aeSmrg#
1760300bf1aeSmrg#    my_silent_option ()
1761300bf1aeSmrg#    {
1762300bf1aeSmrg#        $debug_cmd
1763300bf1aeSmrg#
17642b2b4fcbSmrg#        args_changed=false
17652b2b4fcbSmrg#
17662b2b4fcbSmrg#        # Note that, for efficiency, we parse as many options as we can
1767300bf1aeSmrg#        # recognise in a loop before passing the remainder back to the
1768300bf1aeSmrg#        # caller on the first unrecognised argument we encounter.
1769300bf1aeSmrg#        while test $# -gt 0; do
1770300bf1aeSmrg#          opt=$1; shift
1771300bf1aeSmrg#          case $opt in
17722b2b4fcbSmrg#            --silent|-s) opt_silent=:
17732b2b4fcbSmrg#                         args_changed=:
17742b2b4fcbSmrg#                         ;;
1775300bf1aeSmrg#            # Separate non-argument short options:
1776300bf1aeSmrg#            -s*)         func_split_short_opt "$_G_opt"
1777300bf1aeSmrg#                         set dummy "$func_split_short_opt_name" \
1778300bf1aeSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779300bf1aeSmrg#                         shift
17802b2b4fcbSmrg#                         args_changed=:
1781300bf1aeSmrg#                         ;;
17822b2b4fcbSmrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17832b2b4fcbSmrg#                         # is added back to "$@" in case we need it later,
17842b2b4fcbSmrg#                         # if $args_changed was set to 'true'.
17852b2b4fcbSmrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786300bf1aeSmrg#          esac
1787300bf1aeSmrg#        done
1788300bf1aeSmrg#
17892b2b4fcbSmrg#        # Only call 'func_quote' here if we processed at least one argument.
17902b2b4fcbSmrg#        if $args_changed; then
17912b2b4fcbSmrg#          func_quote eval ${1+"$@"}
17922b2b4fcbSmrg#          my_silent_option_result=$func_quote_result
17932b2b4fcbSmrg#        fi
1794300bf1aeSmrg#    }
1795300bf1aeSmrg#    func_add_hook func_parse_options my_silent_option
1796300bf1aeSmrg#
1797300bf1aeSmrg#
1798300bf1aeSmrg#    my_option_validation ()
1799300bf1aeSmrg#    {
1800300bf1aeSmrg#        $debug_cmd
1801300bf1aeSmrg#
1802300bf1aeSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803300bf1aeSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1804300bf1aeSmrg#    }
1805300bf1aeSmrg#    func_add_hook func_validate_options my_option_validation
1806300bf1aeSmrg#
18072b2b4fcbSmrg# You'll also need to manually amend $usage_message to reflect the extra
1808300bf1aeSmrg# options you parse.  It's preferable to append if you can, so that
1809300bf1aeSmrg# multiple option parsing hooks can be added safely.
1810300bf1aeSmrg
1811300bf1aeSmrg
18122b2b4fcbSmrg# func_options_finish [ARG]...
18132b2b4fcbSmrg# ----------------------------
18142b2b4fcbSmrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18152b2b4fcbSmrgfunc_options_finish ()
18162b2b4fcbSmrg{
18172b2b4fcbSmrg    $debug_cmd
18182b2b4fcbSmrg
18192b2b4fcbSmrg    func_run_hooks func_options ${1+"$@"}
18202b2b4fcbSmrg    func_propagate_result func_run_hooks func_options_finish
18212b2b4fcbSmrg}
18222b2b4fcbSmrg
18232b2b4fcbSmrg
1824300bf1aeSmrg# func_options [ARG]...
1825300bf1aeSmrg# ---------------------
1826300bf1aeSmrg# All the functions called inside func_options are hookable. See the
1827300bf1aeSmrg# individual implementations for details.
1828300bf1aeSmrgfunc_hookable func_options
1829300bf1aeSmrgfunc_options ()
1830ab47cfaaSmrg{
1831300bf1aeSmrg    $debug_cmd
18321473d951Smrg
18332b2b4fcbSmrg    _G_options_quoted=false
18346aec45a7Smrg
18352b2b4fcbSmrg    for my_func in options_prep parse_options validate_options options_finish
18362b2b4fcbSmrg    do
18372b2b4fcbSmrg      func_unset func_${my_func}_result
18382b2b4fcbSmrg      func_unset func_run_hooks_result
18392b2b4fcbSmrg      eval func_$my_func '${1+"$@"}'
18402b2b4fcbSmrg      func_propagate_result func_$my_func func_options
18412b2b4fcbSmrg      if $func_propagate_result_result; then
18422b2b4fcbSmrg        eval set dummy "$func_options_result"; shift
18432b2b4fcbSmrg        _G_options_quoted=:
18442b2b4fcbSmrg      fi
18452b2b4fcbSmrg    done
1846300bf1aeSmrg
18472b2b4fcbSmrg    $_G_options_quoted || {
18482b2b4fcbSmrg      # As we (func_options) are top-level options-parser function and
18492b2b4fcbSmrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18502b2b4fcbSmrg      # caller.
18512b2b4fcbSmrg      func_quote eval ${1+"$@"}
18522b2b4fcbSmrg      func_options_result=$func_quote_result
18532b2b4fcbSmrg    }
1854ab47cfaaSmrg}
1855ab47cfaaSmrg
18566aec45a7Smrg
1857300bf1aeSmrg# func_options_prep [ARG]...
1858300bf1aeSmrg# --------------------------
1859300bf1aeSmrg# All initialisations required before starting the option parse loop.
1860300bf1aeSmrg# Note that when calling hook functions, we pass through the list of
1861300bf1aeSmrg# positional parameters.  If a hook function modifies that list, and
18622b2b4fcbSmrg# needs to propagate that back to rest of this script, then the complete
18632b2b4fcbSmrg# modified list must be put in 'func_run_hooks_result' before returning.
1864300bf1aeSmrgfunc_hookable func_options_prep
1865300bf1aeSmrgfunc_options_prep ()
1866ab47cfaaSmrg{
1867300bf1aeSmrg    $debug_cmd
1868ab47cfaaSmrg
1869300bf1aeSmrg    # Option defaults:
1870300bf1aeSmrg    opt_verbose=false
1871300bf1aeSmrg    opt_warning_types=
18721473d951Smrg
1873300bf1aeSmrg    func_run_hooks func_options_prep ${1+"$@"}
18742b2b4fcbSmrg    func_propagate_result func_run_hooks func_options_prep
1875ab47cfaaSmrg}
1876ab47cfaaSmrg
1877300bf1aeSmrg
1878300bf1aeSmrg# func_parse_options [ARG]...
1879300bf1aeSmrg# ---------------------------
1880300bf1aeSmrg# The main option parsing loop.
1881300bf1aeSmrgfunc_hookable func_parse_options
1882300bf1aeSmrgfunc_parse_options ()
1883aa9e3350Smrg{
1884300bf1aeSmrg    $debug_cmd
1885300bf1aeSmrg
18862b2b4fcbSmrg    _G_parse_options_requote=false
1887300bf1aeSmrg    # this just eases exit handling
1888300bf1aeSmrg    while test $# -gt 0; do
1889300bf1aeSmrg      # Defer to hook functions for initial option parsing, so they
1890300bf1aeSmrg      # get priority in the event of reusing an option name.
1891300bf1aeSmrg      func_run_hooks func_parse_options ${1+"$@"}
18922b2b4fcbSmrg      func_propagate_result func_run_hooks func_parse_options
18932b2b4fcbSmrg      if $func_propagate_result_result; then
18942b2b4fcbSmrg        eval set dummy "$func_parse_options_result"; shift
18952b2b4fcbSmrg        # Even though we may have changed "$@", we passed the "$@" array
18962b2b4fcbSmrg        # down into the hook and it quoted it for us (because we are in
18972b2b4fcbSmrg        # this if-branch).  No need to quote it again.
18982b2b4fcbSmrg        _G_parse_options_requote=false
18992b2b4fcbSmrg      fi
1900300bf1aeSmrg
1901300bf1aeSmrg      # Break out of the loop if we already parsed every option.
1902300bf1aeSmrg      test $# -gt 0 || break
1903300bf1aeSmrg
19042b2b4fcbSmrg      # We expect that one of the options parsed in this function matches
19052b2b4fcbSmrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19062b2b4fcbSmrg      _G_match_parse_options=:
1907300bf1aeSmrg      _G_opt=$1
1908300bf1aeSmrg      shift
1909300bf1aeSmrg      case $_G_opt in
1910300bf1aeSmrg        --debug|-x)   debug_cmd='set -x'
19112b2b4fcbSmrg                      func_echo "enabling shell trace mode" >&2
1912300bf1aeSmrg                      $debug_cmd
1913300bf1aeSmrg                      ;;
1914300bf1aeSmrg
1915300bf1aeSmrg        --no-warnings|--no-warning|--no-warn)
1916300bf1aeSmrg                      set dummy --warnings none ${1+"$@"}
1917300bf1aeSmrg                      shift
1918300bf1aeSmrg		      ;;
1919300bf1aeSmrg
1920300bf1aeSmrg        --warnings|--warning|-W)
19212b2b4fcbSmrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19222b2b4fcbSmrg                        _G_parse_options_requote=:
19232b2b4fcbSmrg                        break
19242b2b4fcbSmrg                      fi
1925300bf1aeSmrg                      case " $warning_categories $1" in
1926300bf1aeSmrg                        *" $1 "*)
1927300bf1aeSmrg                          # trailing space prevents matching last $1 above
1928300bf1aeSmrg                          func_append_uniq opt_warning_types " $1"
1929300bf1aeSmrg                          ;;
1930300bf1aeSmrg                        *all)
1931300bf1aeSmrg                          opt_warning_types=$warning_categories
1932300bf1aeSmrg                          ;;
1933300bf1aeSmrg                        *none)
1934300bf1aeSmrg                          opt_warning_types=none
1935300bf1aeSmrg                          warning_func=:
1936300bf1aeSmrg                          ;;
1937300bf1aeSmrg                        *error)
1938300bf1aeSmrg                          opt_warning_types=$warning_categories
1939300bf1aeSmrg                          warning_func=func_fatal_error
1940300bf1aeSmrg                          ;;
1941300bf1aeSmrg                        *)
1942300bf1aeSmrg                          func_fatal_error \
1943300bf1aeSmrg                             "unsupported warning category: '$1'"
1944300bf1aeSmrg                          ;;
1945300bf1aeSmrg                      esac
1946300bf1aeSmrg                      shift
1947300bf1aeSmrg                      ;;
1948300bf1aeSmrg
1949300bf1aeSmrg        --verbose|-v) opt_verbose=: ;;
1950300bf1aeSmrg        --version)    func_version ;;
1951300bf1aeSmrg        -\?|-h)       func_usage ;;
1952300bf1aeSmrg        --help)       func_help ;;
1953300bf1aeSmrg
1954300bf1aeSmrg	# Separate optargs to long options (plugins may need this):
1955300bf1aeSmrg	--*=*)        func_split_equals "$_G_opt"
1956300bf1aeSmrg	              set dummy "$func_split_equals_lhs" \
1957300bf1aeSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1958300bf1aeSmrg                      shift
1959300bf1aeSmrg                      ;;
1960300bf1aeSmrg
1961300bf1aeSmrg       # Separate optargs to short options:
1962300bf1aeSmrg        -W*)
1963300bf1aeSmrg                      func_split_short_opt "$_G_opt"
1964300bf1aeSmrg                      set dummy "$func_split_short_opt_name" \
1965300bf1aeSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966300bf1aeSmrg                      shift
1967300bf1aeSmrg                      ;;
1968300bf1aeSmrg
1969300bf1aeSmrg        # Separate non-argument short options:
1970300bf1aeSmrg        -\?*|-h*|-v*|-x*)
1971300bf1aeSmrg                      func_split_short_opt "$_G_opt"
1972300bf1aeSmrg                      set dummy "$func_split_short_opt_name" \
1973300bf1aeSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974300bf1aeSmrg                      shift
1975300bf1aeSmrg                      ;;
1976300bf1aeSmrg
19772b2b4fcbSmrg        --)           _G_parse_options_requote=: ; break ;;
1978300bf1aeSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19792b2b4fcbSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19802b2b4fcbSmrg                      _G_match_parse_options=false
19812b2b4fcbSmrg                      break
19822b2b4fcbSmrg                      ;;
1983300bf1aeSmrg      esac
19842b2b4fcbSmrg
19852b2b4fcbSmrg      if $_G_match_parse_options; then
19862b2b4fcbSmrg        _G_parse_options_requote=:
19872b2b4fcbSmrg      fi
1988300bf1aeSmrg    done
1989300bf1aeSmrg
19902b2b4fcbSmrg    if $_G_parse_options_requote; then
19912b2b4fcbSmrg      # save modified positional parameters for caller
19922b2b4fcbSmrg      func_quote eval ${1+"$@"}
19932b2b4fcbSmrg      func_parse_options_result=$func_quote_result
19942b2b4fcbSmrg    fi
1995aa9e3350Smrg}
1996aa9e3350Smrg
19971473d951Smrg
1998300bf1aeSmrg# func_validate_options [ARG]...
1999300bf1aeSmrg# ------------------------------
2000300bf1aeSmrg# Perform any sanity checks on option settings and/or unconsumed
2001300bf1aeSmrg# arguments.
2002300bf1aeSmrgfunc_hookable func_validate_options
2003300bf1aeSmrgfunc_validate_options ()
20046aec45a7Smrg{
2005300bf1aeSmrg    $debug_cmd
2006aa9e3350Smrg
2007300bf1aeSmrg    # Display all warnings if -W was not given.
2008300bf1aeSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009300bf1aeSmrg
2010300bf1aeSmrg    func_run_hooks func_validate_options ${1+"$@"}
20112b2b4fcbSmrg    func_propagate_result func_run_hooks func_validate_options
2012300bf1aeSmrg
2013300bf1aeSmrg    # Bail if the options were screwed!
2014300bf1aeSmrg    $exit_cmd $EXIT_FAILURE
20156aec45a7Smrg}
20161473d951Smrg
2017300bf1aeSmrg
2018300bf1aeSmrg
2019300bf1aeSmrg## ----------------- ##
2020300bf1aeSmrg## Helper functions. ##
2021300bf1aeSmrg## ----------------- ##
2022300bf1aeSmrg
2023300bf1aeSmrg# This section contains the helper functions used by the rest of the
2024300bf1aeSmrg# hookable option parser framework in ascii-betical order.
2025300bf1aeSmrg
2026300bf1aeSmrg
2027300bf1aeSmrg# func_fatal_help ARG...
2028300bf1aeSmrg# ----------------------
2029300bf1aeSmrg# Echo program name prefixed message to standard error, followed by
2030300bf1aeSmrg# a help hint, and exit.
2031300bf1aeSmrgfunc_fatal_help ()
20326aec45a7Smrg{
2033300bf1aeSmrg    $debug_cmd
2034aa9e3350Smrg
2035300bf1aeSmrg    eval \$ECHO \""Usage: $usage"\"
2036300bf1aeSmrg    eval \$ECHO \""$fatal_help"\"
2037300bf1aeSmrg    func_error ${1+"$@"}
2038300bf1aeSmrg    exit $EXIT_FAILURE
20396aec45a7Smrg}
2040ab47cfaaSmrg
2041300bf1aeSmrg
2042300bf1aeSmrg# func_help
2043300bf1aeSmrg# ---------
2044300bf1aeSmrg# Echo long help message to standard output and exit.
20456aec45a7Smrgfunc_help ()
20466aec45a7Smrg{
2047300bf1aeSmrg    $debug_cmd
2048300bf1aeSmrg
2049300bf1aeSmrg    func_usage_message
2050300bf1aeSmrg    $ECHO "$long_help_message"
2051300bf1aeSmrg    exit 0
20526aec45a7Smrg}
2053ab47cfaaSmrg
2054300bf1aeSmrg
2055300bf1aeSmrg# func_missing_arg ARGNAME
2056300bf1aeSmrg# ------------------------
20576aec45a7Smrg# Echo program name prefixed message to standard error and set global
20586aec45a7Smrg# exit_cmd.
20596aec45a7Smrgfunc_missing_arg ()
20606aec45a7Smrg{
2061300bf1aeSmrg    $debug_cmd
2062aa9e3350Smrg
2063300bf1aeSmrg    func_error "Missing argument for '$1'."
20646aec45a7Smrg    exit_cmd=exit
20656aec45a7Smrg}
2066ab47cfaaSmrg
20671473d951Smrg
2068300bf1aeSmrg# func_split_equals STRING
2069300bf1aeSmrg# ------------------------
20702b2b4fcbSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20712b2b4fcbSmrg# after splitting STRING at the '=' sign.
2072300bf1aeSmrgtest -z "$_G_HAVE_XSI_OPS" \
2073300bf1aeSmrg    && (eval 'x=a/b/c;
2074300bf1aeSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075300bf1aeSmrg    && _G_HAVE_XSI_OPS=yes
2076300bf1aeSmrg
2077300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"
2078300bf1aeSmrgthen
2079300bf1aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2080300bf1aeSmrg  eval 'func_split_equals ()
2081300bf1aeSmrg  {
2082300bf1aeSmrg      $debug_cmd
2083300bf1aeSmrg
2084300bf1aeSmrg      func_split_equals_lhs=${1%%=*}
2085300bf1aeSmrg      func_split_equals_rhs=${1#*=}
20862b2b4fcbSmrg      if test "x$func_split_equals_lhs" = "x$1"; then
20872b2b4fcbSmrg        func_split_equals_rhs=
20882b2b4fcbSmrg      fi
2089300bf1aeSmrg  }'
2090300bf1aeSmrgelse
2091300bf1aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092300bf1aeSmrg  func_split_equals ()
2093300bf1aeSmrg  {
2094300bf1aeSmrg      $debug_cmd
2095300bf1aeSmrg
2096300bf1aeSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097300bf1aeSmrg      func_split_equals_rhs=
20982b2b4fcbSmrg      test "x$func_split_equals_lhs=" = "x$1" \
2099300bf1aeSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100300bf1aeSmrg  }
2101300bf1aeSmrgfi #func_split_equals
2102300bf1aeSmrg
2103300bf1aeSmrg
2104300bf1aeSmrg# func_split_short_opt SHORTOPT
2105300bf1aeSmrg# -----------------------------
2106aa9e3350Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107aa9e3350Smrg# variables after splitting SHORTOPT after the 2nd character.
2108300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"
2109300bf1aeSmrgthen
2110300bf1aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2111300bf1aeSmrg  eval 'func_split_short_opt ()
2112300bf1aeSmrg  {
2113300bf1aeSmrg      $debug_cmd
2114300bf1aeSmrg
2115300bf1aeSmrg      func_split_short_opt_arg=${1#??}
2116300bf1aeSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117300bf1aeSmrg  }'
2118300bf1aeSmrgelse
2119300bf1aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120300bf1aeSmrg  func_split_short_opt ()
2121300bf1aeSmrg  {
2122300bf1aeSmrg      $debug_cmd
2123300bf1aeSmrg
21242b2b4fcbSmrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125300bf1aeSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126300bf1aeSmrg  }
2127300bf1aeSmrgfi #func_split_short_opt
2128300bf1aeSmrg
2129300bf1aeSmrg
2130300bf1aeSmrg# func_usage
2131300bf1aeSmrg# ----------
2132300bf1aeSmrg# Echo short help message to standard output and exit.
2133300bf1aeSmrgfunc_usage ()
2134aa9e3350Smrg{
2135300bf1aeSmrg    $debug_cmd
2136aa9e3350Smrg
2137300bf1aeSmrg    func_usage_message
2138300bf1aeSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139300bf1aeSmrg    exit 0
2140300bf1aeSmrg}
2141aa9e3350Smrg
2142aa9e3350Smrg
2143300bf1aeSmrg# func_usage_message
2144300bf1aeSmrg# ------------------
2145300bf1aeSmrg# Echo short help message to standard output.
2146300bf1aeSmrgfunc_usage_message ()
2147aa9e3350Smrg{
2148300bf1aeSmrg    $debug_cmd
2149aa9e3350Smrg
2150300bf1aeSmrg    eval \$ECHO \""Usage: $usage"\"
2151300bf1aeSmrg    echo
2152300bf1aeSmrg    $SED -n 's|^# ||
2153300bf1aeSmrg        /^Written by/{
2154300bf1aeSmrg          x;p;x
2155300bf1aeSmrg        }
2156300bf1aeSmrg	h
2157300bf1aeSmrg	/^Written by/q' < "$progpath"
2158300bf1aeSmrg    echo
2159300bf1aeSmrg    eval \$ECHO \""$usage_message"\"
2160300bf1aeSmrg}
2161aa9e3350Smrg
2162ab47cfaaSmrg
2163300bf1aeSmrg# func_version
2164300bf1aeSmrg# ------------
2165300bf1aeSmrg# Echo version message to standard output and exit.
21662b2b4fcbSmrg# The version message is extracted from the calling file's header
21672b2b4fcbSmrg# comments, with leading '# ' stripped:
21682b2b4fcbSmrg#   1. First display the progname and version
21692b2b4fcbSmrg#   2. Followed by the header comment line matching  /^# Written by /
21702b2b4fcbSmrg#   3. Then a blank line followed by the first following line matching
21712b2b4fcbSmrg#      /^# Copyright /
21722b2b4fcbSmrg#   4. Immediately followed by any lines between the previous matches,
21732b2b4fcbSmrg#      except lines preceding the intervening completely blank line.
21742b2b4fcbSmrg# For example, see the header comments of this file.
2175300bf1aeSmrgfunc_version ()
2176300bf1aeSmrg{
2177300bf1aeSmrg    $debug_cmd
21788697ee19Smrg
2179300bf1aeSmrg    printf '%s\n' "$progname $scriptversion"
2180300bf1aeSmrg    $SED -n '
21812b2b4fcbSmrg        /^# Written by /!b
21822b2b4fcbSmrg        s|^# ||; p; n
21832b2b4fcbSmrg
21842b2b4fcbSmrg        :fwd2blnk
21852b2b4fcbSmrg        /./ {
21862b2b4fcbSmrg          n
21872b2b4fcbSmrg          b fwd2blnk
2188300bf1aeSmrg        }
21892b2b4fcbSmrg        p; n
21902b2b4fcbSmrg
21912b2b4fcbSmrg        :holdwrnt
21922b2b4fcbSmrg        s|^# ||
21932b2b4fcbSmrg        s|^# *$||
21942b2b4fcbSmrg        /^Copyright /!{
21952b2b4fcbSmrg          /./H
21962b2b4fcbSmrg          n
21972b2b4fcbSmrg          b holdwrnt
2198300bf1aeSmrg        }
21992b2b4fcbSmrg
22002b2b4fcbSmrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22012b2b4fcbSmrg        G
22022b2b4fcbSmrg        s|\(\n\)\n*|\1|g
22032b2b4fcbSmrg        p; q' < "$progpath"
22041473d951Smrg
2205300bf1aeSmrg    exit $?
2206300bf1aeSmrg}
2207ab47cfaaSmrg
22086aec45a7Smrg
2209300bf1aeSmrg# Local variables:
2210300bf1aeSmrg# mode: shell-script
2211300bf1aeSmrg# sh-indentation: 2
2212300bf1aeSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
22132b2b4fcbSmrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214300bf1aeSmrg# time-stamp-time-zone: "UTC"
2215300bf1aeSmrg# End:
22166aec45a7Smrg
2217300bf1aeSmrg# Set a version string.
22182b2b4fcbSmrgscriptversion='(GNU libtool) 2.4.7'
22196aec45a7Smrg
22206aec45a7Smrg
2221300bf1aeSmrg# func_echo ARG...
2222300bf1aeSmrg# ----------------
2223300bf1aeSmrg# Libtool also displays the current mode in messages, so override
2224300bf1aeSmrg# funclib.sh func_echo with this custom definition.
2225300bf1aeSmrgfunc_echo ()
2226aa9e3350Smrg{
2227300bf1aeSmrg    $debug_cmd
2228aa9e3350Smrg
2229300bf1aeSmrg    _G_message=$*
2230300bf1aeSmrg
2231300bf1aeSmrg    func_echo_IFS=$IFS
2232300bf1aeSmrg    IFS=$nl
2233300bf1aeSmrg    for _G_line in $_G_message; do
2234300bf1aeSmrg      IFS=$func_echo_IFS
2235300bf1aeSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236300bf1aeSmrg    done
2237300bf1aeSmrg    IFS=$func_echo_IFS
2238300bf1aeSmrg}
2239aa9e3350Smrg
2240aa9e3350Smrg
2241300bf1aeSmrg# func_warning ARG...
2242300bf1aeSmrg# -------------------
2243300bf1aeSmrg# Libtool warnings are not categorized, so override funclib.sh
2244300bf1aeSmrg# func_warning with this simpler definition.
2245300bf1aeSmrgfunc_warning ()
2246aa9e3350Smrg{
2247300bf1aeSmrg    $debug_cmd
2248300bf1aeSmrg
2249300bf1aeSmrg    $warning_func ${1+"$@"}
2250300bf1aeSmrg}
2251300bf1aeSmrg
2252aa9e3350Smrg
2253300bf1aeSmrg## ---------------- ##
2254300bf1aeSmrg## Options parsing. ##
2255300bf1aeSmrg## ---------------- ##
2256300bf1aeSmrg
2257300bf1aeSmrg# Hook in the functions to make sure our own options are parsed during
2258300bf1aeSmrg# the option parsing loop.
2259300bf1aeSmrg
2260300bf1aeSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261300bf1aeSmrg
2262300bf1aeSmrg# Short help message in response to '-h'.
2263300bf1aeSmrgusage_message="Options:
2264300bf1aeSmrg       --config             show all configuration variables
2265300bf1aeSmrg       --debug              enable verbose shell tracing
2266300bf1aeSmrg   -n, --dry-run            display commands without modifying any files
2267300bf1aeSmrg       --features           display basic configuration information and exit
2268300bf1aeSmrg       --mode=MODE          use operation mode MODE
2269300bf1aeSmrg       --no-warnings        equivalent to '-Wnone'
2270300bf1aeSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271300bf1aeSmrg       --quiet, --silent    don't print informational messages
2272300bf1aeSmrg       --tag=TAG            use configuration variables from tag TAG
2273300bf1aeSmrg   -v, --verbose            print more informational messages than default
2274300bf1aeSmrg       --version            print version information
2275300bf1aeSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276300bf1aeSmrg   -h, --help, --help-all   print short, long, or detailed help message
2277300bf1aeSmrg"
2278aa9e3350Smrg
2279300bf1aeSmrg# Additional text appended to 'usage_message' in response to '--help'.
2280300bf1aeSmrgfunc_help ()
2281aa9e3350Smrg{
2282300bf1aeSmrg    $debug_cmd
2283300bf1aeSmrg
2284300bf1aeSmrg    func_usage_message
2285300bf1aeSmrg    $ECHO "$long_help_message
2286300bf1aeSmrg
2287300bf1aeSmrgMODE must be one of the following:
2288300bf1aeSmrg
2289300bf1aeSmrg       clean           remove files from the build directory
2290300bf1aeSmrg       compile         compile a source file into a libtool object
2291300bf1aeSmrg       execute         automatically set library path, then run a program
2292300bf1aeSmrg       finish          complete the installation of libtool libraries
2293300bf1aeSmrg       install         install libraries or executables
2294300bf1aeSmrg       link            create a library or an executable
2295300bf1aeSmrg       uninstall       remove libraries from an installed directory
2296300bf1aeSmrg
2297300bf1aeSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298300bf1aeSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299300bf1aeSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300300bf1aeSmrg
2301300bf1aeSmrgWhen reporting a bug, please describe a test case to reproduce it and
2302300bf1aeSmrginclude the following information:
2303300bf1aeSmrg
2304300bf1aeSmrg       host-triplet:   $host
2305300bf1aeSmrg       shell:          $SHELL
2306300bf1aeSmrg       compiler:       $LTCC
2307300bf1aeSmrg       compiler flags: $LTCFLAGS
2308300bf1aeSmrg       linker:         $LD (gnu? $with_gnu_ld)
23092b2b4fcbSmrg       version:        $progname (GNU libtool) 2.4.7
2310300bf1aeSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311300bf1aeSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312300bf1aeSmrg
2313300bf1aeSmrgReport bugs to <bug-libtool@gnu.org>.
2314300bf1aeSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315300bf1aeSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316300bf1aeSmrg    exit 0
2317300bf1aeSmrg}
2318aa9e3350Smrg
2319aa9e3350Smrg
2320300bf1aeSmrg# func_lo2o OBJECT-NAME
2321300bf1aeSmrg# ---------------------
2322300bf1aeSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323300bf1aeSmrg# object suffix.
2324aa9e3350Smrg
2325300bf1aeSmrglo2o=s/\\.lo\$/.$objext/
2326300bf1aeSmrgo2lo=s/\\.$objext\$/.lo/
2327aa9e3350Smrg
2328300bf1aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329300bf1aeSmrg  eval 'func_lo2o ()
2330300bf1aeSmrg  {
2331300bf1aeSmrg    case $1 in
2332300bf1aeSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333300bf1aeSmrg      *   ) func_lo2o_result=$1               ;;
2334300bf1aeSmrg    esac
2335300bf1aeSmrg  }'
2336300bf1aeSmrg
2337300bf1aeSmrg  # func_xform LIBOBJ-OR-SOURCE
2338300bf1aeSmrg  # ---------------------------
2339300bf1aeSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340300bf1aeSmrg  # suffix to a '.lo' libtool-object suffix.
2341300bf1aeSmrg  eval 'func_xform ()
2342300bf1aeSmrg  {
2343300bf1aeSmrg    func_xform_result=${1%.*}.lo
2344300bf1aeSmrg  }'
2345300bf1aeSmrgelse
2346300bf1aeSmrg  # ...otherwise fall back to using sed.
2347300bf1aeSmrg  func_lo2o ()
2348300bf1aeSmrg  {
2349300bf1aeSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350300bf1aeSmrg  }
2351300bf1aeSmrg
2352300bf1aeSmrg  func_xform ()
2353300bf1aeSmrg  {
2354300bf1aeSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355300bf1aeSmrg  }
2356300bf1aeSmrgfi
2357aa9e3350Smrg
2358aa9e3350Smrg
2359300bf1aeSmrg# func_fatal_configuration ARG...
2360300bf1aeSmrg# -------------------------------
23616aec45a7Smrg# Echo program name prefixed message to standard error, followed by
23626aec45a7Smrg# a configuration failure hint, and exit.
23636aec45a7Smrgfunc_fatal_configuration ()
23646aec45a7Smrg{
23652b2b4fcbSmrg    func_fatal_error ${1+"$@"} \
2366300bf1aeSmrg      "See the $PACKAGE documentation for more information." \
2367300bf1aeSmrg      "Fatal configuration error."
23686aec45a7Smrg}
23696aec45a7Smrg
23706aec45a7Smrg
23716aec45a7Smrg# func_config
2372300bf1aeSmrg# -----------
23736aec45a7Smrg# Display the configuration for all the tags in this script.
23746aec45a7Smrgfunc_config ()
23756aec45a7Smrg{
23766aec45a7Smrg    re_begincf='^# ### BEGIN LIBTOOL'
23776aec45a7Smrg    re_endcf='^# ### END LIBTOOL'
23786aec45a7Smrg
23796aec45a7Smrg    # Default configuration.
23806aec45a7Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23816aec45a7Smrg
2382ab47cfaaSmrg    # Now print the configurations for the tags.
2383ab47cfaaSmrg    for tagname in $taglist; do
23846aec45a7Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385ab47cfaaSmrg    done
23865c42550eSmrg
23876aec45a7Smrg    exit $?
23886aec45a7Smrg}
23895c42550eSmrg
2390300bf1aeSmrg
23916aec45a7Smrg# func_features
2392300bf1aeSmrg# -------------
23936aec45a7Smrg# Display the features supported by this script.
23946aec45a7Smrgfunc_features ()
23956aec45a7Smrg{
23966aec45a7Smrg    echo "host: $host"
2397300bf1aeSmrg    if test yes = "$build_libtool_libs"; then
23986aec45a7Smrg      echo "enable shared libraries"
2399ab47cfaaSmrg    else
24006aec45a7Smrg      echo "disable shared libraries"
2401ab47cfaaSmrg    fi
2402300bf1aeSmrg    if test yes = "$build_old_libs"; then
24036aec45a7Smrg      echo "enable static libraries"
2404ab47cfaaSmrg    else
24056aec45a7Smrg      echo "disable static libraries"
2406ab47cfaaSmrg    fi
24076aec45a7Smrg
2408ab47cfaaSmrg    exit $?
24096aec45a7Smrg}
2410ab47cfaaSmrg
2411300bf1aeSmrg
2412300bf1aeSmrg# func_enable_tag TAGNAME
2413300bf1aeSmrg# -----------------------
24146aec45a7Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
24156aec45a7Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
24166aec45a7Smrg# variable here.
24176aec45a7Smrgfunc_enable_tag ()
24186aec45a7Smrg{
2419300bf1aeSmrg    # Global variable:
2420300bf1aeSmrg    tagname=$1
2421ab47cfaaSmrg
2422300bf1aeSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423300bf1aeSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424300bf1aeSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24251473d951Smrg
2426300bf1aeSmrg    # Validate tagname.
2427300bf1aeSmrg    case $tagname in
2428300bf1aeSmrg      *[!-_A-Za-z0-9,/]*)
2429300bf1aeSmrg        func_fatal_error "invalid tag name: $tagname"
2430300bf1aeSmrg        ;;
2431300bf1aeSmrg    esac
2432ab47cfaaSmrg
2433300bf1aeSmrg    # Don't test for the "default" C tag, as we know it's
2434300bf1aeSmrg    # there but not specially marked.
2435300bf1aeSmrg    case $tagname in
2436300bf1aeSmrg        CC) ;;
24376aec45a7Smrg    *)
2438300bf1aeSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439300bf1aeSmrg	  taglist="$taglist $tagname"
2440300bf1aeSmrg
2441300bf1aeSmrg	  # Evaluate the configuration.  Be careful to quote the path
2442300bf1aeSmrg	  # and the sed script, to avoid splitting on whitespace, but
2443300bf1aeSmrg	  # also don't use non-portable quotes within backquotes within
2444300bf1aeSmrg	  # quotes we have to do it in 2 steps:
2445300bf1aeSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446300bf1aeSmrg	  eval "$extractedcf"
2447300bf1aeSmrg        else
2448300bf1aeSmrg	  func_error "ignoring unknown tag $tagname"
2449300bf1aeSmrg        fi
2450300bf1aeSmrg        ;;
2451300bf1aeSmrg    esac
24526aec45a7Smrg}
24536aec45a7Smrg
2454300bf1aeSmrg
2455aa9e3350Smrg# func_check_version_match
2456300bf1aeSmrg# ------------------------
2457aa9e3350Smrg# Ensure that we are using m4 macros, and libtool script from the same
2458aa9e3350Smrg# release of libtool.
2459aa9e3350Smrgfunc_check_version_match ()
24606aec45a7Smrg{
2461300bf1aeSmrg    if test "$package_revision" != "$macro_revision"; then
2462300bf1aeSmrg      if test "$VERSION" != "$macro_version"; then
2463300bf1aeSmrg        if test -z "$macro_version"; then
2464300bf1aeSmrg          cat >&2 <<_LT_EOF
2465aa9e3350Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466aa9e3350Smrg$progname: definition of this LT_INIT comes from an older release.
2467aa9e3350Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468aa9e3350Smrg$progname: and run autoconf again.
2469aa9e3350Smrg_LT_EOF
2470300bf1aeSmrg        else
2471300bf1aeSmrg          cat >&2 <<_LT_EOF
2472aa9e3350Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473aa9e3350Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474aa9e3350Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475aa9e3350Smrg$progname: and run autoconf again.
2476aa9e3350Smrg_LT_EOF
2477300bf1aeSmrg        fi
2478300bf1aeSmrg      else
2479300bf1aeSmrg        cat >&2 <<_LT_EOF
2480aa9e3350Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481aa9e3350Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482aa9e3350Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483aa9e3350Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484aa9e3350Smrg_LT_EOF
2485300bf1aeSmrg      fi
2486aa9e3350Smrg
2487300bf1aeSmrg      exit $EXIT_MISMATCH
2488300bf1aeSmrg    fi
2489aa9e3350Smrg}
2490aa9e3350Smrg
2491aa9e3350Smrg
2492300bf1aeSmrg# libtool_options_prep [ARG]...
2493300bf1aeSmrg# -----------------------------
2494300bf1aeSmrg# Preparation for options parsed by libtool.
2495300bf1aeSmrglibtool_options_prep ()
2496300bf1aeSmrg{
2497300bf1aeSmrg    $debug_mode
2498aa9e3350Smrg
2499300bf1aeSmrg    # Option defaults:
2500300bf1aeSmrg    opt_config=false
2501300bf1aeSmrg    opt_dlopen=
2502300bf1aeSmrg    opt_dry_run=false
2503300bf1aeSmrg    opt_help=false
2504300bf1aeSmrg    opt_mode=
2505300bf1aeSmrg    opt_preserve_dup_deps=false
2506300bf1aeSmrg    opt_quiet=false
2507aa9e3350Smrg
2508300bf1aeSmrg    nonopt=
2509300bf1aeSmrg    preserve_args=
2510aa9e3350Smrg
25112b2b4fcbSmrg    _G_rc_lt_options_prep=:
25122b2b4fcbSmrg
2513300bf1aeSmrg    # Shorthand for --mode=foo, only valid as the first argument
2514300bf1aeSmrg    case $1 in
2515300bf1aeSmrg    clean|clea|cle|cl)
2516300bf1aeSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517300bf1aeSmrg      ;;
2518300bf1aeSmrg    compile|compil|compi|comp|com|co|c)
2519300bf1aeSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520300bf1aeSmrg      ;;
2521300bf1aeSmrg    execute|execut|execu|exec|exe|ex|e)
2522300bf1aeSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523300bf1aeSmrg      ;;
2524300bf1aeSmrg    finish|finis|fini|fin|fi|f)
2525300bf1aeSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526300bf1aeSmrg      ;;
2527300bf1aeSmrg    install|instal|insta|inst|ins|in|i)
2528300bf1aeSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2529300bf1aeSmrg      ;;
2530300bf1aeSmrg    link|lin|li|l)
2531300bf1aeSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2532300bf1aeSmrg      ;;
2533300bf1aeSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534300bf1aeSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535300bf1aeSmrg      ;;
25362b2b4fcbSmrg    *)
25372b2b4fcbSmrg      _G_rc_lt_options_prep=false
25382b2b4fcbSmrg      ;;
2539300bf1aeSmrg    esac
2540300bf1aeSmrg
25412b2b4fcbSmrg    if $_G_rc_lt_options_prep; then
25422b2b4fcbSmrg      # Pass back the list of options.
25432b2b4fcbSmrg      func_quote eval ${1+"$@"}
25442b2b4fcbSmrg      libtool_options_prep_result=$func_quote_result
25452b2b4fcbSmrg    fi
2546300bf1aeSmrg}
2547300bf1aeSmrgfunc_add_hook func_options_prep libtool_options_prep
25485c42550eSmrg
2549ab47cfaaSmrg
2550300bf1aeSmrg# libtool_parse_options [ARG]...
2551300bf1aeSmrg# ---------------------------------
2552300bf1aeSmrg# Provide handling for libtool specific options.
2553300bf1aeSmrglibtool_parse_options ()
2554aa9e3350Smrg{
2555300bf1aeSmrg    $debug_cmd
25566aec45a7Smrg
25572b2b4fcbSmrg    _G_rc_lt_parse_options=false
25582b2b4fcbSmrg
2559300bf1aeSmrg    # Perform our own loop to consume as many options as possible in
2560300bf1aeSmrg    # each iteration.
2561300bf1aeSmrg    while test $# -gt 0; do
25622b2b4fcbSmrg      _G_match_lt_parse_options=:
2563300bf1aeSmrg      _G_opt=$1
2564300bf1aeSmrg      shift
2565300bf1aeSmrg      case $_G_opt in
2566300bf1aeSmrg        --dry-run|--dryrun|-n)
2567300bf1aeSmrg                        opt_dry_run=:
2568300bf1aeSmrg                        ;;
2569300bf1aeSmrg
2570300bf1aeSmrg        --config)       func_config ;;
2571300bf1aeSmrg
2572300bf1aeSmrg        --dlopen|-dlopen)
2573300bf1aeSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574300bf1aeSmrg}$1"
2575300bf1aeSmrg                        shift
2576300bf1aeSmrg                        ;;
2577300bf1aeSmrg
2578300bf1aeSmrg        --preserve-dup-deps)
2579300bf1aeSmrg                        opt_preserve_dup_deps=: ;;
2580300bf1aeSmrg
2581300bf1aeSmrg        --features)     func_features ;;
2582300bf1aeSmrg
2583300bf1aeSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584300bf1aeSmrg
2585300bf1aeSmrg        --help)         opt_help=: ;;
2586300bf1aeSmrg
2587300bf1aeSmrg        --help-all)     opt_help=': help-all' ;;
2588300bf1aeSmrg
2589300bf1aeSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590300bf1aeSmrg                        opt_mode=$1
2591300bf1aeSmrg                        case $1 in
2592300bf1aeSmrg                          # Valid mode arguments:
2593300bf1aeSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594300bf1aeSmrg
2595300bf1aeSmrg                          # Catch anything else as an error
2596300bf1aeSmrg                          *) func_error "invalid argument for $_G_opt"
2597300bf1aeSmrg                             exit_cmd=exit
2598300bf1aeSmrg                             break
2599300bf1aeSmrg                             ;;
2600300bf1aeSmrg                        esac
2601300bf1aeSmrg                        shift
2602300bf1aeSmrg                        ;;
2603300bf1aeSmrg
2604300bf1aeSmrg        --no-silent|--no-quiet)
2605300bf1aeSmrg                        opt_quiet=false
2606300bf1aeSmrg                        func_append preserve_args " $_G_opt"
2607300bf1aeSmrg                        ;;
2608300bf1aeSmrg
2609300bf1aeSmrg        --no-warnings|--no-warning|--no-warn)
2610300bf1aeSmrg                        opt_warning=false
2611300bf1aeSmrg                        func_append preserve_args " $_G_opt"
2612300bf1aeSmrg                        ;;
2613300bf1aeSmrg
2614300bf1aeSmrg        --no-verbose)
2615300bf1aeSmrg                        opt_verbose=false
2616300bf1aeSmrg                        func_append preserve_args " $_G_opt"
2617300bf1aeSmrg                        ;;
2618300bf1aeSmrg
2619300bf1aeSmrg        --silent|--quiet)
2620300bf1aeSmrg                        opt_quiet=:
2621300bf1aeSmrg                        opt_verbose=false
2622300bf1aeSmrg                        func_append preserve_args " $_G_opt"
2623300bf1aeSmrg                        ;;
2624300bf1aeSmrg
2625300bf1aeSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626300bf1aeSmrg                        opt_tag=$1
2627300bf1aeSmrg                        func_append preserve_args " $_G_opt $1"
2628300bf1aeSmrg                        func_enable_tag "$1"
2629300bf1aeSmrg                        shift
2630300bf1aeSmrg                        ;;
2631300bf1aeSmrg
2632300bf1aeSmrg        --verbose|-v)   opt_quiet=false
2633300bf1aeSmrg                        opt_verbose=:
2634300bf1aeSmrg                        func_append preserve_args " $_G_opt"
2635300bf1aeSmrg                        ;;
2636300bf1aeSmrg
26372b2b4fcbSmrg        # An option not handled by this hook function:
26382b2b4fcbSmrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26392b2b4fcbSmrg                        _G_match_lt_parse_options=false
26402b2b4fcbSmrg                        break
26412b2b4fcbSmrg                        ;;
2642300bf1aeSmrg      esac
26432b2b4fcbSmrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644300bf1aeSmrg    done
2645aa9e3350Smrg
26462b2b4fcbSmrg    if $_G_rc_lt_parse_options; then
26472b2b4fcbSmrg      # save modified positional parameters for caller
26482b2b4fcbSmrg      func_quote eval ${1+"$@"}
26492b2b4fcbSmrg      libtool_parse_options_result=$func_quote_result
26502b2b4fcbSmrg    fi
2651300bf1aeSmrg}
2652300bf1aeSmrgfunc_add_hook func_parse_options libtool_parse_options
26536aec45a7Smrg
26541473d951Smrg
26556aec45a7Smrg
2656300bf1aeSmrg# libtool_validate_options [ARG]...
2657300bf1aeSmrg# ---------------------------------
2658300bf1aeSmrg# Perform any sanity checks on option settings and/or unconsumed
2659300bf1aeSmrg# arguments.
2660300bf1aeSmrglibtool_validate_options ()
2661300bf1aeSmrg{
2662300bf1aeSmrg    # save first non-option argument
2663300bf1aeSmrg    if test 0 -lt $#; then
2664300bf1aeSmrg      nonopt=$1
2665300bf1aeSmrg      shift
26666aec45a7Smrg    fi
26676aec45a7Smrg
2668300bf1aeSmrg    # preserve --debug
2669300bf1aeSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26706aec45a7Smrg
2671300bf1aeSmrg    case $host in
2672300bf1aeSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673300bf1aeSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674300bf1aeSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675300bf1aeSmrg        # don't eliminate duplications in $postdeps and $predeps
2676300bf1aeSmrg        opt_duplicate_compiler_generated_deps=:
2677300bf1aeSmrg        ;;
2678300bf1aeSmrg      *)
2679300bf1aeSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680300bf1aeSmrg        ;;
2681300bf1aeSmrg    esac
26826aec45a7Smrg
2683300bf1aeSmrg    $opt_help || {
2684300bf1aeSmrg      # Sanity checks first:
2685300bf1aeSmrg      func_check_version_match
26866aec45a7Smrg
2687300bf1aeSmrg      test yes != "$build_libtool_libs" \
2688300bf1aeSmrg        && test yes != "$build_old_libs" \
2689300bf1aeSmrg        && func_fatal_configuration "not configured to build any kind of library"
26906aec45a7Smrg
2691300bf1aeSmrg      # Darwin sucks
2692300bf1aeSmrg      eval std_shrext=\"$shrext_cmds\"
2693300bf1aeSmrg
2694300bf1aeSmrg      # Only execute mode is allowed to have -dlopen flags.
2695300bf1aeSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696300bf1aeSmrg        func_error "unrecognized option '-dlopen'"
2697300bf1aeSmrg        $ECHO "$help" 1>&2
2698300bf1aeSmrg        exit $EXIT_FAILURE
2699300bf1aeSmrg      fi
2700300bf1aeSmrg
2701300bf1aeSmrg      # Change the help message to a mode-specific one.
2702300bf1aeSmrg      generic_help=$help
2703300bf1aeSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704300bf1aeSmrg    }
2705300bf1aeSmrg
2706300bf1aeSmrg    # Pass back the unparsed argument list
27072b2b4fcbSmrg    func_quote eval ${1+"$@"}
27082b2b4fcbSmrg    libtool_validate_options_result=$func_quote_result
2709aa9e3350Smrg}
2710300bf1aeSmrgfunc_add_hook func_validate_options libtool_validate_options
2711300bf1aeSmrg
27126aec45a7Smrg
2713300bf1aeSmrg# Process options as early as possible so that --help and --version
2714300bf1aeSmrg# can return quickly.
2715300bf1aeSmrgfunc_options ${1+"$@"}
2716300bf1aeSmrgeval set dummy "$func_options_result"; shift
27176aec45a7Smrg
2718ab47cfaaSmrg
2719ab47cfaaSmrg
2720aa9e3350Smrg## ----------- ##
2721aa9e3350Smrg##    Main.    ##
2722aa9e3350Smrg## ----------- ##
2723ab47cfaaSmrg
2724300bf1aeSmrgmagic='%%%MAGIC variable%%%'
2725300bf1aeSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2726300bf1aeSmrg
2727300bf1aeSmrg# Global variables.
2728300bf1aeSmrgextracted_archives=
2729300bf1aeSmrgextracted_serial=0
2730300bf1aeSmrg
2731300bf1aeSmrg# If this variable is set in any of the actions, the command in it
2732300bf1aeSmrg# will be execed at the end.  This prevents here-documents from being
2733300bf1aeSmrg# left over by shells.
2734300bf1aeSmrgexec_cmd=
2735300bf1aeSmrg
2736300bf1aeSmrg
2737300bf1aeSmrg# A function that is used when there is no print builtin or printf.
2738300bf1aeSmrgfunc_fallback_echo ()
2739300bf1aeSmrg{
2740300bf1aeSmrg  eval 'cat <<_LTECHO_EOF
2741300bf1aeSmrg$1
2742300bf1aeSmrg_LTECHO_EOF'
2743300bf1aeSmrg}
2744300bf1aeSmrg
2745300bf1aeSmrg# func_generated_by_libtool
2746300bf1aeSmrg# True iff stdin has been generated by Libtool. This function is only
2747300bf1aeSmrg# a basic sanity check; it will hardly flush out determined imposters.
2748300bf1aeSmrgfunc_generated_by_libtool_p ()
2749300bf1aeSmrg{
2750300bf1aeSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751300bf1aeSmrg}
2752300bf1aeSmrg
27536aec45a7Smrg# func_lalib_p file
2754300bf1aeSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27556aec45a7Smrg# This function is only a basic sanity check; it will hardly flush out
27566aec45a7Smrg# determined imposters.
27576aec45a7Smrgfunc_lalib_p ()
27586aec45a7Smrg{
27596aec45a7Smrg    test -f "$1" &&
2760300bf1aeSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
27616aec45a7Smrg}
2762ab47cfaaSmrg
27636aec45a7Smrg# func_lalib_unsafe_p file
2764300bf1aeSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27656aec45a7Smrg# This function implements the same check as func_lalib_p without
27666aec45a7Smrg# resorting to external programs.  To this end, it redirects stdin and
27676aec45a7Smrg# closes it afterwards, without saving the original file descriptor.
27686aec45a7Smrg# As a safety measure, use it only where a negative result would be
2769300bf1aeSmrg# fatal anyway.  Works if 'file' does not exist.
27706aec45a7Smrgfunc_lalib_unsafe_p ()
27716aec45a7Smrg{
27726aec45a7Smrg    lalib_p=no
27736aec45a7Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
27746aec45a7Smrg	for lalib_p_l in 1 2 3 4
27756aec45a7Smrg	do
27766aec45a7Smrg	    read lalib_p_line
2777300bf1aeSmrg	    case $lalib_p_line in
27786aec45a7Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
27796aec45a7Smrg	    esac
27806aec45a7Smrg	done
27816aec45a7Smrg	exec 0<&5 5<&-
27826aec45a7Smrg    fi
2783300bf1aeSmrg    test yes = "$lalib_p"
27846aec45a7Smrg}
2785ab47cfaaSmrg
27866aec45a7Smrg# func_ltwrapper_script_p file
27876aec45a7Smrg# True iff FILE is a libtool wrapper script
27886aec45a7Smrg# This function is only a basic sanity check; it will hardly flush out
27896aec45a7Smrg# determined imposters.
27906aec45a7Smrgfunc_ltwrapper_script_p ()
27916aec45a7Smrg{
2792300bf1aeSmrg    test -f "$1" &&
2793300bf1aeSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
27946aec45a7Smrg}
2795ab47cfaaSmrg
27966aec45a7Smrg# func_ltwrapper_executable_p file
27976aec45a7Smrg# True iff FILE is a libtool wrapper executable
27986aec45a7Smrg# This function is only a basic sanity check; it will hardly flush out
27996aec45a7Smrg# determined imposters.
28006aec45a7Smrgfunc_ltwrapper_executable_p ()
28016aec45a7Smrg{
28026aec45a7Smrg    func_ltwrapper_exec_suffix=
28036aec45a7Smrg    case $1 in
28046aec45a7Smrg    *.exe) ;;
28056aec45a7Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
28066aec45a7Smrg    esac
28076aec45a7Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
28086aec45a7Smrg}
28096aec45a7Smrg
28106aec45a7Smrg# func_ltwrapper_scriptname file
28116aec45a7Smrg# Assumes file is an ltwrapper_executable
28126aec45a7Smrg# uses $file to determine the appropriate filename for a
28136aec45a7Smrg# temporary ltwrapper_script.
28146aec45a7Smrgfunc_ltwrapper_scriptname ()
28156aec45a7Smrg{
2816aa9e3350Smrg    func_dirname_and_basename "$1" "" "."
2817aa9e3350Smrg    func_stripname '' '.exe' "$func_basename_result"
2818300bf1aeSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
28196aec45a7Smrg}
28206aec45a7Smrg
28216aec45a7Smrg# func_ltwrapper_p file
28226aec45a7Smrg# True iff FILE is a libtool wrapper script or wrapper executable
28236aec45a7Smrg# This function is only a basic sanity check; it will hardly flush out
28246aec45a7Smrg# determined imposters.
28256aec45a7Smrgfunc_ltwrapper_p ()
28266aec45a7Smrg{
28276aec45a7Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
28286aec45a7Smrg}
28296aec45a7Smrg
28306aec45a7Smrg
28316aec45a7Smrg# func_execute_cmds commands fail_cmd
28326aec45a7Smrg# Execute tilde-delimited COMMANDS.
28336aec45a7Smrg# If FAIL_CMD is given, eval that upon failure.
28346aec45a7Smrg# FAIL_CMD may read-access the current command in variable CMD!
28356aec45a7Smrgfunc_execute_cmds ()
28366aec45a7Smrg{
2837300bf1aeSmrg    $debug_cmd
2838300bf1aeSmrg
28396aec45a7Smrg    save_ifs=$IFS; IFS='~'
28406aec45a7Smrg    for cmd in $1; do
2841300bf1aeSmrg      IFS=$sp$nl
28426aec45a7Smrg      eval cmd=\"$cmd\"
2843300bf1aeSmrg      IFS=$save_ifs
28446aec45a7Smrg      func_show_eval "$cmd" "${2-:}"
28456aec45a7Smrg    done
28466aec45a7Smrg    IFS=$save_ifs
28476aec45a7Smrg}
28486aec45a7Smrg
28496aec45a7Smrg
28506aec45a7Smrg# func_source file
28516aec45a7Smrg# Source FILE, adding directory component if necessary.
28526aec45a7Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
28536aec45a7Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
28546aec45a7Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855300bf1aeSmrg# 'FILE.' does not work on cygwin managed mounts.
28566aec45a7Smrgfunc_source ()
28576aec45a7Smrg{
2858300bf1aeSmrg    $debug_cmd
2859300bf1aeSmrg
28606aec45a7Smrg    case $1 in
28616aec45a7Smrg    */* | *\\*)	. "$1" ;;
28626aec45a7Smrg    *)		. "./$1" ;;
28636aec45a7Smrg    esac
28646aec45a7Smrg}
28656aec45a7Smrg
28666aec45a7Smrg
2867aa9e3350Smrg# func_resolve_sysroot PATH
2868aa9e3350Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869aa9e3350Smrg# func_resolve_sysroot_result
2870aa9e3350Smrgfunc_resolve_sysroot ()
2871aa9e3350Smrg{
2872aa9e3350Smrg  func_resolve_sysroot_result=$1
2873aa9e3350Smrg  case $func_resolve_sysroot_result in
2874aa9e3350Smrg  =*)
2875aa9e3350Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876aa9e3350Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877aa9e3350Smrg    ;;
2878aa9e3350Smrg  esac
2879aa9e3350Smrg}
2880aa9e3350Smrg
2881aa9e3350Smrg# func_replace_sysroot PATH
2882aa9e3350Smrg# If PATH begins with the sysroot, replace it with = and
2883aa9e3350Smrg# store the result into func_replace_sysroot_result.
2884aa9e3350Smrgfunc_replace_sysroot ()
2885aa9e3350Smrg{
2886300bf1aeSmrg  case $lt_sysroot:$1 in
2887aa9e3350Smrg  ?*:"$lt_sysroot"*)
2888aa9e3350Smrg    func_stripname "$lt_sysroot" '' "$1"
2889300bf1aeSmrg    func_replace_sysroot_result='='$func_stripname_result
2890aa9e3350Smrg    ;;
2891aa9e3350Smrg  *)
2892aa9e3350Smrg    # Including no sysroot.
2893aa9e3350Smrg    func_replace_sysroot_result=$1
2894aa9e3350Smrg    ;;
2895aa9e3350Smrg  esac
2896aa9e3350Smrg}
2897aa9e3350Smrg
28986aec45a7Smrg# func_infer_tag arg
28996aec45a7Smrg# Infer tagged configuration to use if any are available and
29006aec45a7Smrg# if one wasn't chosen via the "--tag" command line option.
29016aec45a7Smrg# Only attempt this if the compiler in the base compile
29026aec45a7Smrg# command doesn't match the default compiler.
29036aec45a7Smrg# arg is usually of the form 'gcc ...'
29046aec45a7Smrgfunc_infer_tag ()
29056aec45a7Smrg{
2906300bf1aeSmrg    $debug_cmd
2907300bf1aeSmrg
29086aec45a7Smrg    if test -n "$available_tags" && test -z "$tagname"; then
29096aec45a7Smrg      CC_quoted=
29106aec45a7Smrg      for arg in $CC; do
2911aa9e3350Smrg	func_append_quoted CC_quoted "$arg"
29126aec45a7Smrg      done
29136aec45a7Smrg      CC_expanded=`func_echo_all $CC`
29146aec45a7Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
29156aec45a7Smrg      case $@ in
29166aec45a7Smrg      # Blanks in the command may have been stripped by the calling shell,
29176aec45a7Smrg      # but not from the CC environment variable when configure was run.
29186aec45a7Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29196aec45a7Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
29206aec45a7Smrg      # Blanks at the start of $base_compile will cause this to fail
29216aec45a7Smrg      # if we don't check for them as well.
29226aec45a7Smrg      *)
29236aec45a7Smrg	for z in $available_tags; do
29246aec45a7Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
29256aec45a7Smrg	    # Evaluate the configuration.
2926300bf1aeSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
29276aec45a7Smrg	    CC_quoted=
29286aec45a7Smrg	    for arg in $CC; do
29296aec45a7Smrg	      # Double-quote args containing other shell metacharacters.
2930aa9e3350Smrg	      func_append_quoted CC_quoted "$arg"
29316aec45a7Smrg	    done
29326aec45a7Smrg	    CC_expanded=`func_echo_all $CC`
29336aec45a7Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
29346aec45a7Smrg	    case "$@ " in
29356aec45a7Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29366aec45a7Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
29376aec45a7Smrg	      # The compiler in the base compile command matches
29386aec45a7Smrg	      # the one in the tagged configuration.
29396aec45a7Smrg	      # Assume this is the tagged configuration we want.
29406aec45a7Smrg	      tagname=$z
29416aec45a7Smrg	      break
29426aec45a7Smrg	      ;;
29436aec45a7Smrg	    esac
29446aec45a7Smrg	  fi
29456aec45a7Smrg	done
29466aec45a7Smrg	# If $tagname still isn't set, then no tagged configuration
29476aec45a7Smrg	# was found and let the user know that the "--tag" command
29486aec45a7Smrg	# line option must be used.
29496aec45a7Smrg	if test -z "$tagname"; then
29506aec45a7Smrg	  func_echo "unable to infer tagged configuration"
2951300bf1aeSmrg	  func_fatal_error "specify a tag with '--tag'"
29526aec45a7Smrg#	else
29536aec45a7Smrg#	  func_verbose "using $tagname tagged configuration"
29546aec45a7Smrg	fi
29556aec45a7Smrg	;;
29566aec45a7Smrg      esac
29576aec45a7Smrg    fi
29586aec45a7Smrg}
29596aec45a7Smrg
29606aec45a7Smrg
2961aa9e3350Smrg
2962aa9e3350Smrg# func_write_libtool_object output_name pic_name nonpic_name
2963aa9e3350Smrg# Create a libtool object file (analogous to a ".la" file),
2964aa9e3350Smrg# but don't create it if we're doing a dry run.
2965aa9e3350Smrgfunc_write_libtool_object ()
2966aa9e3350Smrg{
2967300bf1aeSmrg    write_libobj=$1
2968300bf1aeSmrg    if test yes = "$build_libtool_libs"; then
2969300bf1aeSmrg      write_lobj=\'$2\'
2970aa9e3350Smrg    else
2971aa9e3350Smrg      write_lobj=none
2972aa9e3350Smrg    fi
2973aa9e3350Smrg
2974300bf1aeSmrg    if test yes = "$build_old_libs"; then
2975300bf1aeSmrg      write_oldobj=\'$3\'
2976aa9e3350Smrg    else
2977aa9e3350Smrg      write_oldobj=none
2978aa9e3350Smrg    fi
2979aa9e3350Smrg
2980aa9e3350Smrg    $opt_dry_run || {
2981aa9e3350Smrg      cat >${write_libobj}T <<EOF
2982aa9e3350Smrg# $write_libobj - a libtool object file
2983300bf1aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984aa9e3350Smrg#
2985aa9e3350Smrg# Please DO NOT delete this file!
2986aa9e3350Smrg# It is necessary for linking the library.
2987aa9e3350Smrg
2988aa9e3350Smrg# Name of the PIC object.
2989aa9e3350Smrgpic_object=$write_lobj
2990aa9e3350Smrg
2991aa9e3350Smrg# Name of the non-PIC object
2992aa9e3350Smrgnon_pic_object=$write_oldobj
2993aa9e3350Smrg
2994aa9e3350SmrgEOF
2995300bf1aeSmrg      $MV "${write_libobj}T" "$write_libobj"
2996aa9e3350Smrg    }
2997aa9e3350Smrg}
2998aa9e3350Smrg
2999aa9e3350Smrg
3000aa9e3350Smrg##################################################
3001aa9e3350Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002aa9e3350Smrg##################################################
3003aa9e3350Smrg
3004aa9e3350Smrg# func_convert_core_file_wine_to_w32 ARG
3005aa9e3350Smrg# Helper function used by file name conversion functions when $build is *nix,
3006aa9e3350Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007aa9e3350Smrg# correctly configured wine environment available, with the winepath program
3008aa9e3350Smrg# in $build's $PATH.
3009aa9e3350Smrg#
3010aa9e3350Smrg# ARG is the $build file name to be converted to w32 format.
3011aa9e3350Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012aa9e3350Smrg# be empty on error (or when ARG is empty)
3013aa9e3350Smrgfunc_convert_core_file_wine_to_w32 ()
3014aa9e3350Smrg{
3015300bf1aeSmrg  $debug_cmd
3016300bf1aeSmrg
3017300bf1aeSmrg  func_convert_core_file_wine_to_w32_result=$1
3018aa9e3350Smrg  if test -n "$1"; then
3019aa9e3350Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020aa9e3350Smrg    # are forced to check the contents of stdout. On the other hand, if the
3021aa9e3350Smrg    # command is not found, the shell will set an exit code of 127 and print
3022aa9e3350Smrg    # *an error message* to stdout. So we must check for both error code of
3023aa9e3350Smrg    # zero AND non-empty stdout, which explains the odd construction:
3024aa9e3350Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025300bf1aeSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026aa9e3350Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027300bf1aeSmrg        $SED -e "$sed_naive_backslashify"`
3028aa9e3350Smrg    else
3029aa9e3350Smrg      func_convert_core_file_wine_to_w32_result=
3030aa9e3350Smrg    fi
3031aa9e3350Smrg  fi
3032aa9e3350Smrg}
3033aa9e3350Smrg# end: func_convert_core_file_wine_to_w32
3034aa9e3350Smrg
3035aa9e3350Smrg
3036aa9e3350Smrg# func_convert_core_path_wine_to_w32 ARG
3037aa9e3350Smrg# Helper function used by path conversion functions when $build is *nix, and
3038aa9e3350Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039aa9e3350Smrg# configured wine environment available, with the winepath program in $build's
3040aa9e3350Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041aa9e3350Smrg#
3042aa9e3350Smrg# ARG is path to be converted from $build format to win32.
3043aa9e3350Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044aa9e3350Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045aa9e3350Smrg# are convertible, then the result may be empty.
3046aa9e3350Smrgfunc_convert_core_path_wine_to_w32 ()
3047aa9e3350Smrg{
3048300bf1aeSmrg  $debug_cmd
3049300bf1aeSmrg
3050aa9e3350Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051300bf1aeSmrg  func_convert_core_path_wine_to_w32_result=
3052aa9e3350Smrg  if test -n "$1"; then
3053aa9e3350Smrg    oldIFS=$IFS
3054aa9e3350Smrg    IFS=:
3055aa9e3350Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056aa9e3350Smrg      IFS=$oldIFS
3057aa9e3350Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058300bf1aeSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059aa9e3350Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060300bf1aeSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061aa9e3350Smrg        else
3062aa9e3350Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063aa9e3350Smrg        fi
3064aa9e3350Smrg      fi
3065aa9e3350Smrg    done
3066aa9e3350Smrg    IFS=$oldIFS
3067aa9e3350Smrg  fi
3068aa9e3350Smrg}
3069aa9e3350Smrg# end: func_convert_core_path_wine_to_w32
3070aa9e3350Smrg
3071aa9e3350Smrg
3072aa9e3350Smrg# func_cygpath ARGS...
3073aa9e3350Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074aa9e3350Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075aa9e3350Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076aa9e3350Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077aa9e3350Smrg# file name or path is assumed to be in w32 format, as previously converted
3078aa9e3350Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079aa9e3350Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080aa9e3350Smrg# Cygwin format). Returns an empty string on error.
3081aa9e3350Smrg#
3082aa9e3350Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083aa9e3350Smrg# be converted.
3084aa9e3350Smrg#
3085aa9e3350Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086aa9e3350Smrg# environment variable; do not put it in $PATH.
3087aa9e3350Smrgfunc_cygpath ()
3088aa9e3350Smrg{
3089300bf1aeSmrg  $debug_cmd
3090300bf1aeSmrg
3091aa9e3350Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092aa9e3350Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093aa9e3350Smrg    if test "$?" -ne 0; then
3094aa9e3350Smrg      # on failure, ensure result is empty
3095aa9e3350Smrg      func_cygpath_result=
3096aa9e3350Smrg    fi
3097aa9e3350Smrg  else
3098aa9e3350Smrg    func_cygpath_result=
3099300bf1aeSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100aa9e3350Smrg  fi
3101aa9e3350Smrg}
3102aa9e3350Smrg#end: func_cygpath
3103aa9e3350Smrg
3104aa9e3350Smrg
3105aa9e3350Smrg# func_convert_core_msys_to_w32 ARG
3106aa9e3350Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107aa9e3350Smrg# result in func_convert_core_msys_to_w32_result.
3108aa9e3350Smrgfunc_convert_core_msys_to_w32 ()
3109aa9e3350Smrg{
3110300bf1aeSmrg  $debug_cmd
3111300bf1aeSmrg
3112aa9e3350Smrg  # awkward: cmd appends spaces to result
3113aa9e3350Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114300bf1aeSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115aa9e3350Smrg}
3116aa9e3350Smrg#end: func_convert_core_msys_to_w32
3117aa9e3350Smrg
3118aa9e3350Smrg
3119aa9e3350Smrg# func_convert_file_check ARG1 ARG2
3120aa9e3350Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121aa9e3350Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122aa9e3350Smrg# func_to_host_file_result to ARG1).
3123aa9e3350Smrgfunc_convert_file_check ()
3124aa9e3350Smrg{
3125300bf1aeSmrg  $debug_cmd
3126300bf1aeSmrg
3127300bf1aeSmrg  if test -z "$2" && test -n "$1"; then
3128aa9e3350Smrg    func_error "Could not determine host file name corresponding to"
3129300bf1aeSmrg    func_error "  '$1'"
3130aa9e3350Smrg    func_error "Continuing, but uninstalled executables may not work."
3131aa9e3350Smrg    # Fallback:
3132300bf1aeSmrg    func_to_host_file_result=$1
3133aa9e3350Smrg  fi
3134aa9e3350Smrg}
3135aa9e3350Smrg# end func_convert_file_check
3136aa9e3350Smrg
3137aa9e3350Smrg
3138aa9e3350Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139aa9e3350Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140aa9e3350Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141aa9e3350Smrg# func_to_host_file_result to a simplistic fallback value (see below).
3142aa9e3350Smrgfunc_convert_path_check ()
3143aa9e3350Smrg{
3144300bf1aeSmrg  $debug_cmd
3145300bf1aeSmrg
3146aa9e3350Smrg  if test -z "$4" && test -n "$3"; then
3147aa9e3350Smrg    func_error "Could not determine the host path corresponding to"
3148300bf1aeSmrg    func_error "  '$3'"
3149aa9e3350Smrg    func_error "Continuing, but uninstalled executables may not work."
3150aa9e3350Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151aa9e3350Smrg    # should not be "improved".  See libtool.info.
3152aa9e3350Smrg    if test "x$1" != "x$2"; then
3153aa9e3350Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154aa9e3350Smrg      func_to_host_path_result=`echo "$3" |
3155aa9e3350Smrg        $SED -e "$lt_replace_pathsep_chars"`
3156aa9e3350Smrg    else
3157300bf1aeSmrg      func_to_host_path_result=$3
3158aa9e3350Smrg    fi
3159aa9e3350Smrg  fi
3160aa9e3350Smrg}
3161aa9e3350Smrg# end func_convert_path_check
3162aa9e3350Smrg
3163aa9e3350Smrg
3164aa9e3350Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165aa9e3350Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166aa9e3350Smrg# and appending REPL if ORIG matches BACKPAT.
3167aa9e3350Smrgfunc_convert_path_front_back_pathsep ()
3168aa9e3350Smrg{
3169300bf1aeSmrg  $debug_cmd
3170300bf1aeSmrg
3171aa9e3350Smrg  case $4 in
3172300bf1aeSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173aa9e3350Smrg    ;;
3174aa9e3350Smrg  esac
3175aa9e3350Smrg  case $4 in
3176aa9e3350Smrg  $2 ) func_append func_to_host_path_result "$3"
3177aa9e3350Smrg    ;;
3178aa9e3350Smrg  esac
3179aa9e3350Smrg}
3180aa9e3350Smrg# end func_convert_path_front_back_pathsep
3181aa9e3350Smrg
3182aa9e3350Smrg
3183aa9e3350Smrg##################################################
3184aa9e3350Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185aa9e3350Smrg##################################################
3186300bf1aeSmrg# invoked via '$to_host_file_cmd ARG'
3187aa9e3350Smrg#
3188aa9e3350Smrg# In each case, ARG is the path to be converted from $build to $host format.
3189aa9e3350Smrg# Result will be available in $func_to_host_file_result.
3190aa9e3350Smrg
3191aa9e3350Smrg
3192aa9e3350Smrg# func_to_host_file ARG
3193aa9e3350Smrg# Converts the file name ARG from $build format to $host format. Return result
3194aa9e3350Smrg# in func_to_host_file_result.
3195aa9e3350Smrgfunc_to_host_file ()
3196aa9e3350Smrg{
3197300bf1aeSmrg  $debug_cmd
3198300bf1aeSmrg
3199aa9e3350Smrg  $to_host_file_cmd "$1"
3200aa9e3350Smrg}
3201aa9e3350Smrg# end func_to_host_file
3202aa9e3350Smrg
3203aa9e3350Smrg
3204aa9e3350Smrg# func_to_tool_file ARG LAZY
3205aa9e3350Smrg# converts the file name ARG from $build format to toolchain format. Return
3206aa9e3350Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207aa9e3350Smrg# in (the comma separated) LAZY, no conversion takes place.
3208aa9e3350Smrgfunc_to_tool_file ()
3209aa9e3350Smrg{
3210300bf1aeSmrg  $debug_cmd
3211300bf1aeSmrg
3212aa9e3350Smrg  case ,$2, in
3213aa9e3350Smrg    *,"$to_tool_file_cmd",*)
3214aa9e3350Smrg      func_to_tool_file_result=$1
3215aa9e3350Smrg      ;;
3216aa9e3350Smrg    *)
3217aa9e3350Smrg      $to_tool_file_cmd "$1"
3218aa9e3350Smrg      func_to_tool_file_result=$func_to_host_file_result
3219aa9e3350Smrg      ;;
3220aa9e3350Smrg  esac
3221aa9e3350Smrg}
3222aa9e3350Smrg# end func_to_tool_file
3223aa9e3350Smrg
3224aa9e3350Smrg
3225aa9e3350Smrg# func_convert_file_noop ARG
3226aa9e3350Smrg# Copy ARG to func_to_host_file_result.
3227aa9e3350Smrgfunc_convert_file_noop ()
3228aa9e3350Smrg{
3229300bf1aeSmrg  func_to_host_file_result=$1
3230aa9e3350Smrg}
3231aa9e3350Smrg# end func_convert_file_noop
3232aa9e3350Smrg
3233aa9e3350Smrg
3234aa9e3350Smrg# func_convert_file_msys_to_w32 ARG
3235aa9e3350Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236aa9e3350Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237aa9e3350Smrg# func_to_host_file_result.
3238aa9e3350Smrgfunc_convert_file_msys_to_w32 ()
3239aa9e3350Smrg{
3240300bf1aeSmrg  $debug_cmd
3241300bf1aeSmrg
3242300bf1aeSmrg  func_to_host_file_result=$1
3243aa9e3350Smrg  if test -n "$1"; then
3244aa9e3350Smrg    func_convert_core_msys_to_w32 "$1"
3245300bf1aeSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246aa9e3350Smrg  fi
3247aa9e3350Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248aa9e3350Smrg}
3249aa9e3350Smrg# end func_convert_file_msys_to_w32
3250aa9e3350Smrg
3251aa9e3350Smrg
3252aa9e3350Smrg# func_convert_file_cygwin_to_w32 ARG
3253aa9e3350Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254aa9e3350Smrg# func_to_host_file_result.
3255aa9e3350Smrgfunc_convert_file_cygwin_to_w32 ()
3256aa9e3350Smrg{
3257300bf1aeSmrg  $debug_cmd
3258300bf1aeSmrg
3259300bf1aeSmrg  func_to_host_file_result=$1
3260aa9e3350Smrg  if test -n "$1"; then
3261aa9e3350Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262aa9e3350Smrg    # LT_CYGPATH in this case.
3263aa9e3350Smrg    func_to_host_file_result=`cygpath -m "$1"`
3264aa9e3350Smrg  fi
3265aa9e3350Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266aa9e3350Smrg}
3267aa9e3350Smrg# end func_convert_file_cygwin_to_w32
3268aa9e3350Smrg
3269aa9e3350Smrg
3270aa9e3350Smrg# func_convert_file_nix_to_w32 ARG
3271aa9e3350Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272aa9e3350Smrg# and a working winepath. Returns result in func_to_host_file_result.
3273aa9e3350Smrgfunc_convert_file_nix_to_w32 ()
3274aa9e3350Smrg{
3275300bf1aeSmrg  $debug_cmd
3276300bf1aeSmrg
3277300bf1aeSmrg  func_to_host_file_result=$1
3278aa9e3350Smrg  if test -n "$1"; then
3279aa9e3350Smrg    func_convert_core_file_wine_to_w32 "$1"
3280300bf1aeSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281aa9e3350Smrg  fi
3282aa9e3350Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283aa9e3350Smrg}
3284aa9e3350Smrg# end func_convert_file_nix_to_w32
3285aa9e3350Smrg
3286aa9e3350Smrg
3287aa9e3350Smrg# func_convert_file_msys_to_cygwin ARG
3288aa9e3350Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289aa9e3350Smrg# Returns result in func_to_host_file_result.
3290aa9e3350Smrgfunc_convert_file_msys_to_cygwin ()
3291aa9e3350Smrg{
3292300bf1aeSmrg  $debug_cmd
3293300bf1aeSmrg
3294300bf1aeSmrg  func_to_host_file_result=$1
3295aa9e3350Smrg  if test -n "$1"; then
3296aa9e3350Smrg    func_convert_core_msys_to_w32 "$1"
3297aa9e3350Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298300bf1aeSmrg    func_to_host_file_result=$func_cygpath_result
3299aa9e3350Smrg  fi
3300aa9e3350Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301aa9e3350Smrg}
3302aa9e3350Smrg# end func_convert_file_msys_to_cygwin
3303aa9e3350Smrg
3304aa9e3350Smrg
3305aa9e3350Smrg# func_convert_file_nix_to_cygwin ARG
3306aa9e3350Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307aa9e3350Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308aa9e3350Smrg# in func_to_host_file_result.
3309aa9e3350Smrgfunc_convert_file_nix_to_cygwin ()
3310aa9e3350Smrg{
3311300bf1aeSmrg  $debug_cmd
3312300bf1aeSmrg
3313300bf1aeSmrg  func_to_host_file_result=$1
3314aa9e3350Smrg  if test -n "$1"; then
3315aa9e3350Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316aa9e3350Smrg    func_convert_core_file_wine_to_w32 "$1"
3317aa9e3350Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318300bf1aeSmrg    func_to_host_file_result=$func_cygpath_result
3319aa9e3350Smrg  fi
3320aa9e3350Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321aa9e3350Smrg}
3322aa9e3350Smrg# end func_convert_file_nix_to_cygwin
3323aa9e3350Smrg
3324aa9e3350Smrg
3325aa9e3350Smrg#############################################
3326aa9e3350Smrg# $build to $host PATH CONVERSION FUNCTIONS #
3327aa9e3350Smrg#############################################
3328300bf1aeSmrg# invoked via '$to_host_path_cmd ARG'
3329aa9e3350Smrg#
3330aa9e3350Smrg# In each case, ARG is the path to be converted from $build to $host format.
3331aa9e3350Smrg# The result will be available in $func_to_host_path_result.
3332aa9e3350Smrg#
3333aa9e3350Smrg# Path separators are also converted from $build format to $host format.  If
3334aa9e3350Smrg# ARG begins or ends with a path separator character, it is preserved (but
3335aa9e3350Smrg# converted to $host format) on output.
3336aa9e3350Smrg#
3337aa9e3350Smrg# All path conversion functions are named using the following convention:
3338aa9e3350Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339aa9e3350Smrg#   path conversion function         : func_convert_path_X_to_Y ()
3340aa9e3350Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341aa9e3350Smrg# same.  If conversion functions are added for new $build/$host combinations,
3342aa9e3350Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343aa9e3350Smrg# will break.
3344aa9e3350Smrg
3345aa9e3350Smrg
3346aa9e3350Smrg# func_init_to_host_path_cmd
3347aa9e3350Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348aa9e3350Smrg# appropriate value, based on the value of $to_host_file_cmd.
3349aa9e3350Smrgto_host_path_cmd=
3350aa9e3350Smrgfunc_init_to_host_path_cmd ()
3351aa9e3350Smrg{
3352300bf1aeSmrg  $debug_cmd
3353300bf1aeSmrg
3354aa9e3350Smrg  if test -z "$to_host_path_cmd"; then
3355aa9e3350Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356300bf1aeSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357aa9e3350Smrg  fi
3358aa9e3350Smrg}
3359aa9e3350Smrg
3360aa9e3350Smrg
3361aa9e3350Smrg# func_to_host_path ARG
3362aa9e3350Smrg# Converts the path ARG from $build format to $host format. Return result
3363aa9e3350Smrg# in func_to_host_path_result.
3364aa9e3350Smrgfunc_to_host_path ()
3365aa9e3350Smrg{
3366300bf1aeSmrg  $debug_cmd
3367300bf1aeSmrg
3368aa9e3350Smrg  func_init_to_host_path_cmd
3369aa9e3350Smrg  $to_host_path_cmd "$1"
3370aa9e3350Smrg}
3371aa9e3350Smrg# end func_to_host_path
3372aa9e3350Smrg
3373aa9e3350Smrg
3374aa9e3350Smrg# func_convert_path_noop ARG
3375aa9e3350Smrg# Copy ARG to func_to_host_path_result.
3376aa9e3350Smrgfunc_convert_path_noop ()
3377aa9e3350Smrg{
3378300bf1aeSmrg  func_to_host_path_result=$1
3379aa9e3350Smrg}
3380aa9e3350Smrg# end func_convert_path_noop
3381aa9e3350Smrg
3382aa9e3350Smrg
3383aa9e3350Smrg# func_convert_path_msys_to_w32 ARG
3384aa9e3350Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385aa9e3350Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386aa9e3350Smrg# func_to_host_path_result.
3387aa9e3350Smrgfunc_convert_path_msys_to_w32 ()
3388aa9e3350Smrg{
3389300bf1aeSmrg  $debug_cmd
3390300bf1aeSmrg
3391300bf1aeSmrg  func_to_host_path_result=$1
3392aa9e3350Smrg  if test -n "$1"; then
3393aa9e3350Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394aa9e3350Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395aa9e3350Smrg    # and winepath ignores them completely.
3396aa9e3350Smrg    func_stripname : : "$1"
3397aa9e3350Smrg    func_to_host_path_tmp1=$func_stripname_result
3398aa9e3350Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399300bf1aeSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400aa9e3350Smrg    func_convert_path_check : ";" \
3401aa9e3350Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402aa9e3350Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403aa9e3350Smrg  fi
3404aa9e3350Smrg}
3405aa9e3350Smrg# end func_convert_path_msys_to_w32
3406aa9e3350Smrg
3407aa9e3350Smrg
3408aa9e3350Smrg# func_convert_path_cygwin_to_w32 ARG
3409aa9e3350Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410aa9e3350Smrg# func_to_host_file_result.
3411aa9e3350Smrgfunc_convert_path_cygwin_to_w32 ()
3412aa9e3350Smrg{
3413300bf1aeSmrg  $debug_cmd
3414300bf1aeSmrg
3415300bf1aeSmrg  func_to_host_path_result=$1
3416aa9e3350Smrg  if test -n "$1"; then
3417aa9e3350Smrg    # See func_convert_path_msys_to_w32:
3418aa9e3350Smrg    func_stripname : : "$1"
3419aa9e3350Smrg    func_to_host_path_tmp1=$func_stripname_result
3420aa9e3350Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421aa9e3350Smrg    func_convert_path_check : ";" \
3422aa9e3350Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423aa9e3350Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424aa9e3350Smrg  fi
3425aa9e3350Smrg}
3426aa9e3350Smrg# end func_convert_path_cygwin_to_w32
3427aa9e3350Smrg
3428aa9e3350Smrg
3429aa9e3350Smrg# func_convert_path_nix_to_w32 ARG
3430aa9e3350Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431aa9e3350Smrg# a working winepath.  Returns result in func_to_host_file_result.
3432aa9e3350Smrgfunc_convert_path_nix_to_w32 ()
34336aec45a7Smrg{
3434300bf1aeSmrg  $debug_cmd
3435300bf1aeSmrg
3436300bf1aeSmrg  func_to_host_path_result=$1
3437aa9e3350Smrg  if test -n "$1"; then
3438aa9e3350Smrg    # See func_convert_path_msys_to_w32:
3439aa9e3350Smrg    func_stripname : : "$1"
3440aa9e3350Smrg    func_to_host_path_tmp1=$func_stripname_result
3441aa9e3350Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442300bf1aeSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443aa9e3350Smrg    func_convert_path_check : ";" \
3444aa9e3350Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445aa9e3350Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446aa9e3350Smrg  fi
3447aa9e3350Smrg}
3448aa9e3350Smrg# end func_convert_path_nix_to_w32
34496aec45a7Smrg
34506aec45a7Smrg
3451aa9e3350Smrg# func_convert_path_msys_to_cygwin ARG
3452aa9e3350Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453aa9e3350Smrg# Returns result in func_to_host_file_result.
3454aa9e3350Smrgfunc_convert_path_msys_to_cygwin ()
3455aa9e3350Smrg{
3456300bf1aeSmrg  $debug_cmd
3457300bf1aeSmrg
3458300bf1aeSmrg  func_to_host_path_result=$1
3459aa9e3350Smrg  if test -n "$1"; then
3460aa9e3350Smrg    # See func_convert_path_msys_to_w32:
3461aa9e3350Smrg    func_stripname : : "$1"
3462aa9e3350Smrg    func_to_host_path_tmp1=$func_stripname_result
3463aa9e3350Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464aa9e3350Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465300bf1aeSmrg    func_to_host_path_result=$func_cygpath_result
3466aa9e3350Smrg    func_convert_path_check : : \
3467aa9e3350Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468aa9e3350Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469aa9e3350Smrg  fi
3470aa9e3350Smrg}
3471aa9e3350Smrg# end func_convert_path_msys_to_cygwin
34726aec45a7Smrg
34736aec45a7Smrg
3474aa9e3350Smrg# func_convert_path_nix_to_cygwin ARG
3475aa9e3350Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476aa9e3350Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477aa9e3350Smrg# func_to_host_file_result.
3478aa9e3350Smrgfunc_convert_path_nix_to_cygwin ()
3479aa9e3350Smrg{
3480300bf1aeSmrg  $debug_cmd
3481300bf1aeSmrg
3482300bf1aeSmrg  func_to_host_path_result=$1
3483aa9e3350Smrg  if test -n "$1"; then
3484aa9e3350Smrg    # Remove leading and trailing path separator characters from
3485aa9e3350Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486aa9e3350Smrg    # into '.;' and ';.', and winepath ignores them completely.
3487aa9e3350Smrg    func_stripname : : "$1"
3488aa9e3350Smrg    func_to_host_path_tmp1=$func_stripname_result
3489aa9e3350Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490aa9e3350Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491300bf1aeSmrg    func_to_host_path_result=$func_cygpath_result
3492aa9e3350Smrg    func_convert_path_check : : \
3493aa9e3350Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494aa9e3350Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495aa9e3350Smrg  fi
34966aec45a7Smrg}
3497aa9e3350Smrg# end func_convert_path_nix_to_cygwin
3498aa9e3350Smrg
34996aec45a7Smrg
3500300bf1aeSmrg# func_dll_def_p FILE
3501300bf1aeSmrg# True iff FILE is a Windows DLL '.def' file.
3502300bf1aeSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503300bf1aeSmrgfunc_dll_def_p ()
3504300bf1aeSmrg{
3505300bf1aeSmrg  $debug_cmd
3506300bf1aeSmrg
3507300bf1aeSmrg  func_dll_def_p_tmp=`$SED -n \
3508300bf1aeSmrg    -e 's/^[	 ]*//' \
3509300bf1aeSmrg    -e '/^\(;.*\)*$/d' \
3510300bf1aeSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511300bf1aeSmrg    -e q \
3512300bf1aeSmrg    "$1"`
3513300bf1aeSmrg  test DEF = "$func_dll_def_p_tmp"
3514300bf1aeSmrg}
3515300bf1aeSmrg
3516300bf1aeSmrg
35176aec45a7Smrg# func_mode_compile arg...
35186aec45a7Smrgfunc_mode_compile ()
35196aec45a7Smrg{
3520300bf1aeSmrg    $debug_cmd
3521300bf1aeSmrg
35226aec45a7Smrg    # Get the compilation command and the source file.
35236aec45a7Smrg    base_compile=
3524300bf1aeSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
35256aec45a7Smrg    suppress_opt=yes
35266aec45a7Smrg    suppress_output=
35276aec45a7Smrg    arg_mode=normal
35286aec45a7Smrg    libobj=
35296aec45a7Smrg    later=
35306aec45a7Smrg    pie_flag=
35316aec45a7Smrg
35326aec45a7Smrg    for arg
35336aec45a7Smrg    do
35346aec45a7Smrg      case $arg_mode in
35356aec45a7Smrg      arg  )
35366aec45a7Smrg	# do not "continue".  Instead, add this to base_compile
3537300bf1aeSmrg	lastarg=$arg
35386aec45a7Smrg	arg_mode=normal
35396aec45a7Smrg	;;
35406aec45a7Smrg
35416aec45a7Smrg      target )
3542300bf1aeSmrg	libobj=$arg
35436aec45a7Smrg	arg_mode=normal
35446aec45a7Smrg	continue
35456aec45a7Smrg	;;
35466aec45a7Smrg
35476aec45a7Smrg      normal )
35486aec45a7Smrg	# Accept any command-line options.
35496aec45a7Smrg	case $arg in
35506aec45a7Smrg	-o)
35516aec45a7Smrg	  test -n "$libobj" && \
3552300bf1aeSmrg	    func_fatal_error "you cannot specify '-o' more than once"
35536aec45a7Smrg	  arg_mode=target
35546aec45a7Smrg	  continue
35556aec45a7Smrg	  ;;
35566aec45a7Smrg
35576aec45a7Smrg	-pie | -fpie | -fPIE)
3558aa9e3350Smrg          func_append pie_flag " $arg"
35596aec45a7Smrg	  continue
35606aec45a7Smrg	  ;;
35616aec45a7Smrg
35626aec45a7Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563aa9e3350Smrg	  func_append later " $arg"
35646aec45a7Smrg	  continue
35656aec45a7Smrg	  ;;
35661473d951Smrg
35671473d951Smrg	-no-suppress)
3568ab47cfaaSmrg	  suppress_opt=no
3569ab47cfaaSmrg	  continue
3570ab47cfaaSmrg	  ;;
3571ab47cfaaSmrg
3572ab47cfaaSmrg	-Xcompiler)
3573ab47cfaaSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574ab47cfaaSmrg	  continue      #  The current "srcfile" will either be retained or
3575ab47cfaaSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576ab47cfaaSmrg
3577ab47cfaaSmrg	-Wc,*)
35786aec45a7Smrg	  func_stripname '-Wc,' '' "$arg"
35796aec45a7Smrg	  args=$func_stripname_result
3580ab47cfaaSmrg	  lastarg=
3581300bf1aeSmrg	  save_ifs=$IFS; IFS=,
35826aec45a7Smrg	  for arg in $args; do
3583300bf1aeSmrg	    IFS=$save_ifs
3584aa9e3350Smrg	    func_append_quoted lastarg "$arg"
3585ab47cfaaSmrg	  done
3586300bf1aeSmrg	  IFS=$save_ifs
35876aec45a7Smrg	  func_stripname ' ' '' "$lastarg"
35886aec45a7Smrg	  lastarg=$func_stripname_result
3589ab47cfaaSmrg
3590ab47cfaaSmrg	  # Add the arguments to base_compile.
3591aa9e3350Smrg	  func_append base_compile " $lastarg"
3592ab47cfaaSmrg	  continue
3593ab47cfaaSmrg	  ;;
3594ab47cfaaSmrg
35956aec45a7Smrg	*)
3596ab47cfaaSmrg	  # Accept the current argument as the source file.
3597ab47cfaaSmrg	  # The previous "srcfile" becomes the current argument.
3598ab47cfaaSmrg	  #
3599300bf1aeSmrg	  lastarg=$srcfile
3600300bf1aeSmrg	  srcfile=$arg
3601ab47cfaaSmrg	  ;;
3602ab47cfaaSmrg	esac  #  case $arg
3603ab47cfaaSmrg	;;
3604ab47cfaaSmrg      esac    #  case $arg_mode
3605ab47cfaaSmrg
3606ab47cfaaSmrg      # Aesthetically quote the previous argument.
3607aa9e3350Smrg      func_append_quoted base_compile "$lastarg"
3608ab47cfaaSmrg    done # for arg
3609ab47cfaaSmrg
3610ab47cfaaSmrg    case $arg_mode in
3611ab47cfaaSmrg    arg)
36126aec45a7Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613ab47cfaaSmrg      ;;
3614ab47cfaaSmrg    target)
3615300bf1aeSmrg      func_fatal_error "you must specify a target with '-o'"
3616ab47cfaaSmrg      ;;
3617ab47cfaaSmrg    *)
3618ab47cfaaSmrg      # Get the name of the library object.
36196aec45a7Smrg      test -z "$libobj" && {
36206aec45a7Smrg	func_basename "$srcfile"
3621300bf1aeSmrg	libobj=$func_basename_result
36226aec45a7Smrg      }
3623ab47cfaaSmrg      ;;
3624ab47cfaaSmrg    esac
3625ab47cfaaSmrg
3626ab47cfaaSmrg    # Recognize several different file suffixes.
3627ab47cfaaSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3628ab47cfaaSmrg    case $libobj in
36296aec45a7Smrg    *.[cCFSifmso] | \
36306aec45a7Smrg    *.ada | *.adb | *.ads | *.asm | \
36316aec45a7Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632aa9e3350Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
36336aec45a7Smrg      func_xform "$libobj"
36346aec45a7Smrg      libobj=$func_xform_result
36356aec45a7Smrg      ;;
3636ab47cfaaSmrg    esac
3637ab47cfaaSmrg
3638ab47cfaaSmrg    case $libobj in
36396aec45a7Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640ab47cfaaSmrg    *)
3641300bf1aeSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642ab47cfaaSmrg      ;;
3643ab47cfaaSmrg    esac
3644ab47cfaaSmrg
3645ab47cfaaSmrg    func_infer_tag $base_compile
3646ab47cfaaSmrg
3647ab47cfaaSmrg    for arg in $later; do
3648ab47cfaaSmrg      case $arg in
36496aec45a7Smrg      -shared)
3650300bf1aeSmrg	test yes = "$build_libtool_libs" \
3651300bf1aeSmrg	  || func_fatal_configuration "cannot build a shared library"
36526aec45a7Smrg	build_old_libs=no
36536aec45a7Smrg	continue
36546aec45a7Smrg	;;
36556aec45a7Smrg
3656ab47cfaaSmrg      -static)
36576aec45a7Smrg	build_libtool_libs=no
3658ab47cfaaSmrg	build_old_libs=yes
3659ab47cfaaSmrg	continue
3660ab47cfaaSmrg	;;
3661ab47cfaaSmrg
3662ab47cfaaSmrg      -prefer-pic)
3663ab47cfaaSmrg	pic_mode=yes
3664ab47cfaaSmrg	continue
3665ab47cfaaSmrg	;;
3666ab47cfaaSmrg
3667ab47cfaaSmrg      -prefer-non-pic)
3668ab47cfaaSmrg	pic_mode=no
3669ab47cfaaSmrg	continue
3670ab47cfaaSmrg	;;
3671ab47cfaaSmrg      esac
3672ab47cfaaSmrg    done
3673ab47cfaaSmrg
36742b2b4fcbSmrg    func_quote_arg pretty "$libobj"
36752b2b4fcbSmrg    test "X$libobj" != "X$func_quote_arg_result" \
36766aec45a7Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677300bf1aeSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
36786aec45a7Smrg    func_dirname_and_basename "$obj" "/" ""
3679300bf1aeSmrg    objname=$func_basename_result
3680300bf1aeSmrg    xdir=$func_dirname_result
3681300bf1aeSmrg    lobj=$xdir$objdir/$objname
3682ab47cfaaSmrg
36836aec45a7Smrg    test -z "$base_compile" && \
36846aec45a7Smrg      func_fatal_help "you must specify a compilation command"
3685ab47cfaaSmrg
3686ab47cfaaSmrg    # Delete any leftover library objects.
3687300bf1aeSmrg    if test yes = "$build_old_libs"; then
3688ab47cfaaSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3689ab47cfaaSmrg    else
3690ab47cfaaSmrg      removelist="$lobj $libobj ${libobj}T"
3691ab47cfaaSmrg    fi
3692ab47cfaaSmrg
3693ab47cfaaSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694ab47cfaaSmrg    case $host_os in
36956aec45a7Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696ab47cfaaSmrg      pic_mode=default
3697ab47cfaaSmrg      ;;
3698ab47cfaaSmrg    esac
3699300bf1aeSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700ab47cfaaSmrg      # non-PIC code in shared libraries is not supported
3701ab47cfaaSmrg      pic_mode=default
3702ab47cfaaSmrg    fi
3703ab47cfaaSmrg
3704ab47cfaaSmrg    # Calculate the filename of the output object if compiler does
3705ab47cfaaSmrg    # not support -o with -c
3706300bf1aeSmrg    if test no = "$compiler_c_o"; then
3707300bf1aeSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708300bf1aeSmrg      lockfile=$output_obj.lock
3709ab47cfaaSmrg    else
3710ab47cfaaSmrg      output_obj=
3711ab47cfaaSmrg      need_locks=no
3712ab47cfaaSmrg      lockfile=
3713ab47cfaaSmrg    fi
3714ab47cfaaSmrg
3715ab47cfaaSmrg    # Lock this critical section if it is needed
3716ab47cfaaSmrg    # We use this script file to make the link, it avoids creating a new file
3717300bf1aeSmrg    if test yes = "$need_locks"; then
37186aec45a7Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
37196aec45a7Smrg	func_echo "Waiting for $lockfile to be removed"
3720ab47cfaaSmrg	sleep 2
3721ab47cfaaSmrg      done
3722300bf1aeSmrg    elif test warn = "$need_locks"; then
3723ab47cfaaSmrg      if test -f "$lockfile"; then
37246aec45a7Smrg	$ECHO "\
3725ab47cfaaSmrg*** ERROR, $lockfile exists and contains:
3726ab47cfaaSmrg`cat $lockfile 2>/dev/null`
3727ab47cfaaSmrg
3728ab47cfaaSmrgThis indicates that another process is trying to use the same
3729ab47cfaaSmrgtemporary object file, and libtool could not work around it because
3730300bf1aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3731ab47cfaaSmrgrepeat this compilation, it may succeed, by chance, but you had better
3732ab47cfaaSmrgavoid parallel builds (make -j) in this platform, or get a better
3733ab47cfaaSmrgcompiler."
3734ab47cfaaSmrg
37356aec45a7Smrg	$opt_dry_run || $RM $removelist
3736ab47cfaaSmrg	exit $EXIT_FAILURE
3737ab47cfaaSmrg      fi
3738aa9e3350Smrg      func_append removelist " $output_obj"
37396aec45a7Smrg      $ECHO "$srcfile" > "$lockfile"
3740ab47cfaaSmrg    fi
3741ab47cfaaSmrg
37426aec45a7Smrg    $opt_dry_run || $RM $removelist
3743aa9e3350Smrg    func_append removelist " $lockfile"
37446aec45a7Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
37456aec45a7Smrg
3746aa9e3350Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747aa9e3350Smrg    srcfile=$func_to_tool_file_result
37482b2b4fcbSmrg    func_quote_arg pretty "$srcfile"
37492b2b4fcbSmrg    qsrcfile=$func_quote_arg_result
3750ab47cfaaSmrg
3751ab47cfaaSmrg    # Only build a PIC object if we are building libtool libraries.
3752300bf1aeSmrg    if test yes = "$build_libtool_libs"; then
3753ab47cfaaSmrg      # Without this assignment, base_compile gets emptied.
3754ab47cfaaSmrg      fbsd_hideous_sh_bug=$base_compile
3755ab47cfaaSmrg
3756300bf1aeSmrg      if test no != "$pic_mode"; then
3757ab47cfaaSmrg	command="$base_compile $qsrcfile $pic_flag"
3758ab47cfaaSmrg      else
3759ab47cfaaSmrg	# Don't build PIC code
3760ab47cfaaSmrg	command="$base_compile $qsrcfile"
3761ab47cfaaSmrg      fi
3762ab47cfaaSmrg
37636aec45a7Smrg      func_mkdir_p "$xdir$objdir"
3764ab47cfaaSmrg
3765ab47cfaaSmrg      if test -z "$output_obj"; then
3766ab47cfaaSmrg	# Place PIC objects in $objdir
3767aa9e3350Smrg	func_append command " -o $lobj"
3768ab47cfaaSmrg      fi
3769ab47cfaaSmrg
37706aec45a7Smrg      func_show_eval_locale "$command"	\
37716aec45a7Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772ab47cfaaSmrg
3773300bf1aeSmrg      if test warn = "$need_locks" &&
3774ab47cfaaSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
37756aec45a7Smrg	$ECHO "\
3776ab47cfaaSmrg*** ERROR, $lockfile contains:
3777ab47cfaaSmrg`cat $lockfile 2>/dev/null`
3778ab47cfaaSmrg
3779ab47cfaaSmrgbut it should contain:
3780ab47cfaaSmrg$srcfile
3781ab47cfaaSmrg
3782ab47cfaaSmrgThis indicates that another process is trying to use the same
3783ab47cfaaSmrgtemporary object file, and libtool could not work around it because
3784300bf1aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3785ab47cfaaSmrgrepeat this compilation, it may succeed, by chance, but you had better
3786ab47cfaaSmrgavoid parallel builds (make -j) in this platform, or get a better
3787ab47cfaaSmrgcompiler."
3788ab47cfaaSmrg
37896aec45a7Smrg	$opt_dry_run || $RM $removelist
3790ab47cfaaSmrg	exit $EXIT_FAILURE
3791ab47cfaaSmrg      fi
3792ab47cfaaSmrg
3793ab47cfaaSmrg      # Just move the object if needed, then go on to compile the next one
3794ab47cfaaSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
37956aec45a7Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
37966aec45a7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797ab47cfaaSmrg      fi
3798ab47cfaaSmrg
3799ab47cfaaSmrg      # Allow error messages only from the first compilation.
3800300bf1aeSmrg      if test yes = "$suppress_opt"; then
38016aec45a7Smrg	suppress_output=' >/dev/null 2>&1'
3802ab47cfaaSmrg      fi
3803ab47cfaaSmrg    fi
3804ab47cfaaSmrg
3805ab47cfaaSmrg    # Only build a position-dependent object if we build old libraries.
3806300bf1aeSmrg    if test yes = "$build_old_libs"; then
3807300bf1aeSmrg      if test yes != "$pic_mode"; then
3808ab47cfaaSmrg	# Don't build PIC code
38096aec45a7Smrg	command="$base_compile $qsrcfile$pie_flag"
3810ab47cfaaSmrg      else
3811ab47cfaaSmrg	command="$base_compile $qsrcfile $pic_flag"
3812ab47cfaaSmrg      fi
3813300bf1aeSmrg      if test yes = "$compiler_c_o"; then
3814aa9e3350Smrg	func_append command " -o $obj"
3815ab47cfaaSmrg      fi
3816ab47cfaaSmrg
3817ab47cfaaSmrg      # Suppress compiler output if we already did a PIC compilation.
3818aa9e3350Smrg      func_append command "$suppress_output"
38196aec45a7Smrg      func_show_eval_locale "$command" \
38206aec45a7Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821ab47cfaaSmrg
3822300bf1aeSmrg      if test warn = "$need_locks" &&
3823ab47cfaaSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
38246aec45a7Smrg	$ECHO "\
3825ab47cfaaSmrg*** ERROR, $lockfile contains:
3826ab47cfaaSmrg`cat $lockfile 2>/dev/null`
3827ab47cfaaSmrg
3828ab47cfaaSmrgbut it should contain:
3829ab47cfaaSmrg$srcfile
3830ab47cfaaSmrg
3831ab47cfaaSmrgThis indicates that another process is trying to use the same
3832ab47cfaaSmrgtemporary object file, and libtool could not work around it because
3833300bf1aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3834ab47cfaaSmrgrepeat this compilation, it may succeed, by chance, but you had better
3835ab47cfaaSmrgavoid parallel builds (make -j) in this platform, or get a better
3836ab47cfaaSmrgcompiler."
3837ab47cfaaSmrg
38386aec45a7Smrg	$opt_dry_run || $RM $removelist
3839ab47cfaaSmrg	exit $EXIT_FAILURE
3840ab47cfaaSmrg      fi
3841ab47cfaaSmrg
3842ab47cfaaSmrg      # Just move the object if needed
3843ab47cfaaSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
38446aec45a7Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
38456aec45a7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846ab47cfaaSmrg      fi
3847ab47cfaaSmrg    fi
3848ab47cfaaSmrg
38496aec45a7Smrg    $opt_dry_run || {
38506aec45a7Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851ab47cfaaSmrg
38526aec45a7Smrg      # Unlock the critical section if it was locked
3853300bf1aeSmrg      if test no != "$need_locks"; then
38546aec45a7Smrg	removelist=$lockfile
38556aec45a7Smrg        $RM "$lockfile"
38566aec45a7Smrg      fi
38576aec45a7Smrg    }
3858ab47cfaaSmrg
3859ab47cfaaSmrg    exit $EXIT_SUCCESS
38606aec45a7Smrg}
3861ab47cfaaSmrg
38626aec45a7Smrg$opt_help || {
3863300bf1aeSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
38646aec45a7Smrg}
3865ab47cfaaSmrg
38666aec45a7Smrgfunc_mode_help ()
38676aec45a7Smrg{
38686aec45a7Smrg    # We need to display help for each of the modes.
3869aa9e3350Smrg    case $opt_mode in
38706aec45a7Smrg      "")
38716aec45a7Smrg        # Generic help is extracted from the usage comments
38726aec45a7Smrg        # at the start of this file.
38736aec45a7Smrg        func_help
38746aec45a7Smrg        ;;
3875ab47cfaaSmrg
38766aec45a7Smrg      clean)
38776aec45a7Smrg        $ECHO \
38786aec45a7Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879ab47cfaaSmrg
38806aec45a7SmrgRemove files from the build directory.
3881ab47cfaaSmrg
38826aec45a7SmrgRM is the name of the program to use to delete files associated with each FILE
3883300bf1aeSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38846aec45a7Smrgto RM.
3885ab47cfaaSmrg
38866aec45a7SmrgIf FILE is a libtool library, object or program, all the files associated
38876aec45a7Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
38886aec45a7Smrg        ;;
3889ab47cfaaSmrg
38906aec45a7Smrg      compile)
38916aec45a7Smrg      $ECHO \
38926aec45a7Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893ab47cfaaSmrg
38946aec45a7SmrgCompile a source file into a libtool library object.
3895ab47cfaaSmrg
38966aec45a7SmrgThis mode accepts the following additional options:
3897ab47cfaaSmrg
38986aec45a7Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
38996aec45a7Smrg  -no-suppress      do not suppress compiler output for multiple passes
39006aec45a7Smrg  -prefer-pic       try to build PIC objects only
39016aec45a7Smrg  -prefer-non-pic   try to build non-PIC objects only
3902300bf1aeSmrg  -shared           do not build a '.o' file suitable for static linking
3903300bf1aeSmrg  -static           only build a '.o' file suitable for static linking
39042b2b4fcbSmrg  -Wc,FLAG
39052b2b4fcbSmrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906ab47cfaaSmrg
3907300bf1aeSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
39086aec45a7Smrgfrom the given SOURCEFILE.
3909ab47cfaaSmrg
39106aec45a7SmrgThe output file name is determined by removing the directory component from
3911300bf1aeSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912300bf1aeSmrglibrary object suffix, '.lo'."
39136aec45a7Smrg        ;;
3914ab47cfaaSmrg
39156aec45a7Smrg      execute)
39166aec45a7Smrg        $ECHO \
39176aec45a7Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918ab47cfaaSmrg
39196aec45a7SmrgAutomatically set library path, then run a program.
3920ab47cfaaSmrg
39216aec45a7SmrgThis mode accepts the following additional options:
3922ab47cfaaSmrg
39236aec45a7Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924ab47cfaaSmrg
3925300bf1aeSmrgThis mode sets the library path environment variable according to '-dlopen'
39266aec45a7Smrgflags.
3927ab47cfaaSmrg
39286aec45a7SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
39296aec45a7Smrginto their corresponding uninstalled binary, and any of their required library
39306aec45a7Smrgdirectories are added to the library path.
3931ab47cfaaSmrg
39326aec45a7SmrgThen, COMMAND is executed, with ARGS as arguments."
39336aec45a7Smrg        ;;
3934ab47cfaaSmrg
39356aec45a7Smrg      finish)
39366aec45a7Smrg        $ECHO \
39376aec45a7Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938ab47cfaaSmrg
39396aec45a7SmrgComplete the installation of libtool libraries.
3940ab47cfaaSmrg
39416aec45a7SmrgEach LIBDIR is a directory that contains libtool libraries.
3942ab47cfaaSmrg
39436aec45a7SmrgThe commands that this mode executes may require superuser privileges.  Use
3944300bf1aeSmrgthe '--dry-run' option if you just want to see what would be executed."
39456aec45a7Smrg        ;;
3946ab47cfaaSmrg
39476aec45a7Smrg      install)
39486aec45a7Smrg        $ECHO \
39496aec45a7Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950ab47cfaaSmrg
39516aec45a7SmrgInstall executables or libraries.
3952ab47cfaaSmrg
39536aec45a7SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954300bf1aeSmrgeither the 'install' or 'cp' program.
3955ab47cfaaSmrg
39566aec45a7SmrgThe following components of INSTALL-COMMAND are treated specially:
3957ab47cfaaSmrg
39586aec45a7Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959ab47cfaaSmrg
39606aec45a7SmrgThe rest of the components are interpreted as arguments to that command (only
39616aec45a7SmrgBSD-compatible install options are recognized)."
39626aec45a7Smrg        ;;
3963ab47cfaaSmrg
39646aec45a7Smrg      link)
39656aec45a7Smrg        $ECHO \
39666aec45a7Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967ab47cfaaSmrg
39686aec45a7SmrgLink object files or libraries together to form another library, or to
39696aec45a7Smrgcreate an executable program.
3970ab47cfaaSmrg
39716aec45a7SmrgLINK-COMMAND is a command using the C compiler that you would use to create
39726aec45a7Smrga program from several object files.
3973ab47cfaaSmrg
39746aec45a7SmrgThe following components of LINK-COMMAND are treated specially:
3975ab47cfaaSmrg
39766aec45a7Smrg  -all-static       do not do any dynamic linking at all
39776aec45a7Smrg  -avoid-version    do not add a version suffix if possible
39786aec45a7Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
39796aec45a7Smrg                    libraries must be found in the PATH setting at runtime)
3980300bf1aeSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
39816aec45a7Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
39826aec45a7Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
39836aec45a7Smrg  -export-symbols SYMFILE
39846aec45a7Smrg                    try to export only the symbols listed in SYMFILE
39856aec45a7Smrg  -export-symbols-regex REGEX
39866aec45a7Smrg                    try to export only the symbols matching REGEX
39876aec45a7Smrg  -LLIBDIR          search LIBDIR for required installed libraries
39886aec45a7Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
39896aec45a7Smrg  -module           build a library that can dlopened
39906aec45a7Smrg  -no-fast-install  disable the fast-install mode
39916aec45a7Smrg  -no-install       link a not-installable executable
39926aec45a7Smrg  -no-undefined     declare that a library does not refer to external symbols
39936aec45a7Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994300bf1aeSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995300bf1aeSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
39966aec45a7Smrg  -precious-files-regex REGEX
39976aec45a7Smrg                    don't remove output files matching REGEX
39986aec45a7Smrg  -release RELEASE  specify package release information
39996aec45a7Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
40006aec45a7Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
40016aec45a7Smrg  -shared           only do dynamic linking of libtool libraries
40026aec45a7Smrg  -shrext SUFFIX    override the standard shared library file extension
40036aec45a7Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
40046aec45a7Smrg  -static-libtool-libs
40056aec45a7Smrg                    do not do any dynamic linking of libtool libraries
40066aec45a7Smrg  -version-info CURRENT[:REVISION[:AGE]]
40076aec45a7Smrg                    specify library version info [each variable defaults to 0]
40086aec45a7Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
40096aec45a7Smrg  -Wc,FLAG
40106aec45a7Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
40112b2b4fcbSmrg  -Wa,FLAG
40122b2b4fcbSmrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
40136aec45a7Smrg  -Wl,FLAG
40146aec45a7Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
40156aec45a7Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016ab47cfaaSmrg
4017300bf1aeSmrgAll other options (arguments beginning with '-') are ignored.
4018ab47cfaaSmrg
4019300bf1aeSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
40206aec45a7Smrgtreated as uninstalled libtool libraries, other files are standard or library
40216aec45a7Smrgobject files.
4022ab47cfaaSmrg
4023300bf1aeSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024300bf1aeSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
40256aec45a7Smrgrequired, except when creating a convenience library.
4026ab47cfaaSmrg
4027300bf1aeSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028300bf1aeSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4029ab47cfaaSmrg
4030300bf1aeSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
40316aec45a7Smrgis created, otherwise an executable program is created."
40326aec45a7Smrg        ;;
4033ab47cfaaSmrg
40346aec45a7Smrg      uninstall)
40356aec45a7Smrg        $ECHO \
40366aec45a7Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037ab47cfaaSmrg
40386aec45a7SmrgRemove libraries from an installation directory.
4039ab47cfaaSmrg
40406aec45a7SmrgRM is the name of the program to use to delete files associated with each FILE
4041300bf1aeSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
40426aec45a7Smrgto RM.
4043ab47cfaaSmrg
40446aec45a7SmrgIf FILE is a libtool library, all the files associated with it are deleted.
40456aec45a7SmrgOtherwise, only FILE itself is deleted using RM."
40466aec45a7Smrg        ;;
4047ab47cfaaSmrg
40486aec45a7Smrg      *)
4049300bf1aeSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
40506aec45a7Smrg        ;;
40516aec45a7Smrg    esac
4052ab47cfaaSmrg
40536aec45a7Smrg    echo
4054300bf1aeSmrg    $ECHO "Try '$progname --help' for more information about other modes."
40556aec45a7Smrg}
40561473d951Smrg
40576aec45a7Smrg# Now that we've collected a possible --mode arg, show help if necessary
40586aec45a7Smrgif $opt_help; then
4059300bf1aeSmrg  if test : = "$opt_help"; then
40606aec45a7Smrg    func_mode_help
40616aec45a7Smrg  else
40626aec45a7Smrg    {
40636aec45a7Smrg      func_help noexit
4064aa9e3350Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40656aec45a7Smrg	func_mode_help
40666aec45a7Smrg      done
4067300bf1aeSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
40686aec45a7Smrg    {
40696aec45a7Smrg      func_help noexit
4070aa9e3350Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40716aec45a7Smrg	echo
40726aec45a7Smrg	func_mode_help
40736aec45a7Smrg      done
40746aec45a7Smrg    } |
4075300bf1aeSmrg    $SED '1d
40766aec45a7Smrg      /^When reporting/,/^Report/{
40776aec45a7Smrg	H
40786aec45a7Smrg	d
40796aec45a7Smrg      }
40806aec45a7Smrg      $x
40816aec45a7Smrg      /information about other modes/d
40826aec45a7Smrg      /more detailed .*MODE/d
40836aec45a7Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
40846aec45a7Smrg  fi
40856aec45a7Smrg  exit $?
40866aec45a7Smrgfi
40871473d951Smrg
40881473d951Smrg
40896aec45a7Smrg# func_mode_execute arg...
40906aec45a7Smrgfunc_mode_execute ()
40916aec45a7Smrg{
4092300bf1aeSmrg    $debug_cmd
4093300bf1aeSmrg
40946aec45a7Smrg    # The first argument is the command name.
4095300bf1aeSmrg    cmd=$nonopt
40966aec45a7Smrg    test -z "$cmd" && \
40976aec45a7Smrg      func_fatal_help "you must specify a COMMAND"
40981473d951Smrg
40996aec45a7Smrg    # Handle -dlopen flags immediately.
4100aa9e3350Smrg    for file in $opt_dlopen; do
41016aec45a7Smrg      test -f "$file" \
4102300bf1aeSmrg	|| func_fatal_help "'$file' is not a file"
41031473d951Smrg
41046aec45a7Smrg      dir=
41056aec45a7Smrg      case $file in
41066aec45a7Smrg      *.la)
4107aa9e3350Smrg	func_resolve_sysroot "$file"
4108aa9e3350Smrg	file=$func_resolve_sysroot_result
4109aa9e3350Smrg
41106aec45a7Smrg	# Check to see that this really is a libtool archive.
41116aec45a7Smrg	func_lalib_unsafe_p "$file" \
4112300bf1aeSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
41131473d951Smrg
41146aec45a7Smrg	# Read the libtool library.
41156aec45a7Smrg	dlname=
41166aec45a7Smrg	library_names=
41176aec45a7Smrg	func_source "$file"
41181473d951Smrg
41196aec45a7Smrg	# Skip this library if it cannot be dlopened.
41206aec45a7Smrg	if test -z "$dlname"; then
41216aec45a7Smrg	  # Warn if it was a shared library.
41226aec45a7Smrg	  test -n "$library_names" && \
4123300bf1aeSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
41246aec45a7Smrg	  continue
41256aec45a7Smrg	fi
41265c42550eSmrg
41276aec45a7Smrg	func_dirname "$file" "" "."
4128300bf1aeSmrg	dir=$func_dirname_result
41295c42550eSmrg
41306aec45a7Smrg	if test -f "$dir/$objdir/$dlname"; then
4131aa9e3350Smrg	  func_append dir "/$objdir"
41326aec45a7Smrg	else
41336aec45a7Smrg	  if test ! -f "$dir/$dlname"; then
4134300bf1aeSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
41356aec45a7Smrg	  fi
41366aec45a7Smrg	fi
41371473d951Smrg	;;
41385c42550eSmrg
41396aec45a7Smrg      *.lo)
41406aec45a7Smrg	# Just add the directory containing the .lo file.
41416aec45a7Smrg	func_dirname "$file" "" "."
4142300bf1aeSmrg	dir=$func_dirname_result
41431473d951Smrg	;;
41446aec45a7Smrg
41456aec45a7Smrg      *)
4146300bf1aeSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
41475c42550eSmrg	continue
4148ab47cfaaSmrg	;;
41496aec45a7Smrg      esac
4150ab47cfaaSmrg
41516aec45a7Smrg      # Get the absolute pathname.
41526aec45a7Smrg      absdir=`cd "$dir" && pwd`
4153300bf1aeSmrg      test -n "$absdir" && dir=$absdir
4154ab47cfaaSmrg
41556aec45a7Smrg      # Now add the directory to shlibpath_var.
41566aec45a7Smrg      if eval "test -z \"\$$shlibpath_var\""; then
41576aec45a7Smrg	eval "$shlibpath_var=\"\$dir\""
41586aec45a7Smrg      else
41596aec45a7Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
41606aec45a7Smrg      fi
41616aec45a7Smrg    done
4162ab47cfaaSmrg
41636aec45a7Smrg    # This variable tells wrapper scripts just to set shlibpath_var
41646aec45a7Smrg    # rather than running their programs.
4165300bf1aeSmrg    libtool_execute_magic=$magic
4166ab47cfaaSmrg
41676aec45a7Smrg    # Check if any of the arguments is a wrapper script.
41686aec45a7Smrg    args=
41696aec45a7Smrg    for file
41706aec45a7Smrg    do
41716aec45a7Smrg      case $file in
41726aec45a7Smrg      -* | *.la | *.lo ) ;;
41736aec45a7Smrg      *)
41746aec45a7Smrg	# Do a test to see if this is really a libtool program.
41756aec45a7Smrg	if func_ltwrapper_script_p "$file"; then
41766aec45a7Smrg	  func_source "$file"
41776aec45a7Smrg	  # Transform arg to wrapped name.
4178300bf1aeSmrg	  file=$progdir/$program
41796aec45a7Smrg	elif func_ltwrapper_executable_p "$file"; then
41806aec45a7Smrg	  func_ltwrapper_scriptname "$file"
41816aec45a7Smrg	  func_source "$func_ltwrapper_scriptname_result"
41826aec45a7Smrg	  # Transform arg to wrapped name.
4183300bf1aeSmrg	  file=$progdir/$program
41846aec45a7Smrg	fi
41855c42550eSmrg	;;
41866aec45a7Smrg      esac
41876aec45a7Smrg      # Quote arguments (to preserve shell metacharacters).
4188aa9e3350Smrg      func_append_quoted args "$file"
41896aec45a7Smrg    done
4190ab47cfaaSmrg
4191300bf1aeSmrg    if $opt_dry_run; then
4192300bf1aeSmrg      # Display what would be done.
4193300bf1aeSmrg      if test -n "$shlibpath_var"; then
4194300bf1aeSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195300bf1aeSmrg	echo "export $shlibpath_var"
4196300bf1aeSmrg      fi
4197300bf1aeSmrg      $ECHO "$cmd$args"
4198300bf1aeSmrg      exit $EXIT_SUCCESS
4199300bf1aeSmrg    else
42006aec45a7Smrg      if test -n "$shlibpath_var"; then
42016aec45a7Smrg	# Export the shlibpath_var.
42026aec45a7Smrg	eval "export $shlibpath_var"
42036aec45a7Smrg      fi
4204ab47cfaaSmrg
42056aec45a7Smrg      # Restore saved environment variables
42066aec45a7Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
42076aec45a7Smrg      do
42086aec45a7Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
42096aec45a7Smrg                $lt_var=\$save_$lt_var; export $lt_var
42106aec45a7Smrg	      else
42116aec45a7Smrg		$lt_unset $lt_var
42126aec45a7Smrg	      fi"
42136aec45a7Smrg      done
4214ab47cfaaSmrg
42156aec45a7Smrg      # Now prepare to actually exec the command.
4216300bf1aeSmrg      exec_cmd=\$cmd$args
42176aec45a7Smrg    fi
42186aec45a7Smrg}
42191473d951Smrg
4220300bf1aeSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
42211473d951Smrg
42221473d951Smrg
42236aec45a7Smrg# func_mode_finish arg...
42246aec45a7Smrgfunc_mode_finish ()
42256aec45a7Smrg{
4226300bf1aeSmrg    $debug_cmd
4227300bf1aeSmrg
4228aa9e3350Smrg    libs=
4229aa9e3350Smrg    libdirs=
42306aec45a7Smrg    admincmds=
42311473d951Smrg
4232aa9e3350Smrg    for opt in "$nonopt" ${1+"$@"}
4233aa9e3350Smrg    do
4234aa9e3350Smrg      if test -d "$opt"; then
4235aa9e3350Smrg	func_append libdirs " $opt"
4236aa9e3350Smrg
4237aa9e3350Smrg      elif test -f "$opt"; then
4238aa9e3350Smrg	if func_lalib_unsafe_p "$opt"; then
4239aa9e3350Smrg	  func_append libs " $opt"
4240aa9e3350Smrg	else
4241300bf1aeSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242aa9e3350Smrg	fi
4243aa9e3350Smrg
4244aa9e3350Smrg      else
4245300bf1aeSmrg	func_fatal_error "invalid argument '$opt'"
4246aa9e3350Smrg      fi
4247aa9e3350Smrg    done
4248aa9e3350Smrg
4249aa9e3350Smrg    if test -n "$libs"; then
4250aa9e3350Smrg      if test -n "$lt_sysroot"; then
4251aa9e3350Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252aa9e3350Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253aa9e3350Smrg      else
4254aa9e3350Smrg        sysroot_cmd=
4255aa9e3350Smrg      fi
4256aa9e3350Smrg
4257aa9e3350Smrg      # Remove sysroot references
4258aa9e3350Smrg      if $opt_dry_run; then
4259aa9e3350Smrg        for lib in $libs; do
4260300bf1aeSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261aa9e3350Smrg        done
4262aa9e3350Smrg      else
4263aa9e3350Smrg        tmpdir=`func_mktempdir`
4264aa9e3350Smrg        for lib in $libs; do
4265300bf1aeSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266aa9e3350Smrg	    > $tmpdir/tmp-la
4267aa9e3350Smrg	  mv -f $tmpdir/tmp-la $lib
4268aa9e3350Smrg	done
4269aa9e3350Smrg        ${RM}r "$tmpdir"
4270aa9e3350Smrg      fi
4271aa9e3350Smrg    fi
42721473d951Smrg
4273aa9e3350Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42746aec45a7Smrg      for libdir in $libdirs; do
42756aec45a7Smrg	if test -n "$finish_cmds"; then
42766aec45a7Smrg	  # Do each command in the finish commands.
42776aec45a7Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
42786aec45a7Smrg'"$cmd"'"'
42796aec45a7Smrg	fi
42806aec45a7Smrg	if test -n "$finish_eval"; then
42816aec45a7Smrg	  # Do the single finish_eval.
42826aec45a7Smrg	  eval cmds=\"$finish_eval\"
4283aa9e3350Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
42846aec45a7Smrg       $cmds"
42856aec45a7Smrg	fi
42866aec45a7Smrg      done
42876aec45a7Smrg    fi
42881473d951Smrg
42896aec45a7Smrg    # Exit here if they wanted silent mode.
4290300bf1aeSmrg    $opt_quiet && exit $EXIT_SUCCESS
42911473d951Smrg
4292aa9e3350Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293aa9e3350Smrg      echo "----------------------------------------------------------------------"
4294aa9e3350Smrg      echo "Libraries have been installed in:"
4295aa9e3350Smrg      for libdir in $libdirs; do
4296aa9e3350Smrg	$ECHO "   $libdir"
4297aa9e3350Smrg      done
4298aa9e3350Smrg      echo
4299aa9e3350Smrg      echo "If you ever happen to want to link against installed libraries"
4300aa9e3350Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301300bf1aeSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302aa9e3350Smrg      echo "flag during linking and do at least one of the following:"
4303aa9e3350Smrg      if test -n "$shlibpath_var"; then
4304300bf1aeSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305aa9e3350Smrg	echo "     during execution"
4306aa9e3350Smrg      fi
4307aa9e3350Smrg      if test -n "$runpath_var"; then
4308300bf1aeSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309aa9e3350Smrg	echo "     during linking"
4310aa9e3350Smrg      fi
4311aa9e3350Smrg      if test -n "$hardcode_libdir_flag_spec"; then
4312aa9e3350Smrg	libdir=LIBDIR
4313aa9e3350Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
43141473d951Smrg
4315300bf1aeSmrg	$ECHO "   - use the '$flag' linker flag"
4316aa9e3350Smrg      fi
4317aa9e3350Smrg      if test -n "$admincmds"; then
4318aa9e3350Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319aa9e3350Smrg      fi
4320aa9e3350Smrg      if test -f /etc/ld.so.conf; then
4321300bf1aeSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322aa9e3350Smrg      fi
4323aa9e3350Smrg      echo
43241473d951Smrg
4325aa9e3350Smrg      echo "See any operating system documentation about shared libraries for"
4326aa9e3350Smrg      case $host in
4327aa9e3350Smrg	solaris2.[6789]|solaris2.1[0-9])
4328aa9e3350Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329aa9e3350Smrg	  echo "pages."
4330aa9e3350Smrg	  ;;
4331aa9e3350Smrg	*)
4332aa9e3350Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333aa9e3350Smrg	  ;;
4334aa9e3350Smrg      esac
4335aa9e3350Smrg      echo "----------------------------------------------------------------------"
4336aa9e3350Smrg    fi
43376aec45a7Smrg    exit $EXIT_SUCCESS
43386aec45a7Smrg}
43391473d951Smrg
4340300bf1aeSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
43415c42550eSmrg
4342ab47cfaaSmrg
43436aec45a7Smrg# func_mode_install arg...
43446aec45a7Smrgfunc_mode_install ()
43456aec45a7Smrg{
4346300bf1aeSmrg    $debug_cmd
4347300bf1aeSmrg
43486aec45a7Smrg    # There may be an optional sh(1) argument at the beginning of
43496aec45a7Smrg    # install_prog (especially on Windows NT).
4350300bf1aeSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
43516aec45a7Smrg       # Allow the use of GNU shtool's install command.
4352300bf1aeSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4353300bf1aeSmrg    then
43546aec45a7Smrg      # Aesthetically quote it.
43552b2b4fcbSmrg      func_quote_arg pretty "$nonopt"
43562b2b4fcbSmrg      install_prog="$func_quote_arg_result "
43576aec45a7Smrg      arg=$1
43586aec45a7Smrg      shift
43596aec45a7Smrg    else
43606aec45a7Smrg      install_prog=
43616aec45a7Smrg      arg=$nonopt
43626aec45a7Smrg    fi
4363ab47cfaaSmrg
43646aec45a7Smrg    # The real first argument should be the name of the installation program.
43656aec45a7Smrg    # Aesthetically quote it.
43662b2b4fcbSmrg    func_quote_arg pretty "$arg"
43672b2b4fcbSmrg    func_append install_prog "$func_quote_arg_result"
43686aec45a7Smrg    install_shared_prog=$install_prog
43696aec45a7Smrg    case " $install_prog " in
43706aec45a7Smrg      *[\\\ /]cp\ *) install_cp=: ;;
43716aec45a7Smrg      *) install_cp=false ;;
43726aec45a7Smrg    esac
4373ab47cfaaSmrg
43746aec45a7Smrg    # We need to accept at least all the BSD install flags.
43756aec45a7Smrg    dest=
43766aec45a7Smrg    files=
43776aec45a7Smrg    opts=
43786aec45a7Smrg    prev=
43796aec45a7Smrg    install_type=
4380300bf1aeSmrg    isdir=false
43816aec45a7Smrg    stripme=
43826aec45a7Smrg    no_mode=:
43836aec45a7Smrg    for arg
43846aec45a7Smrg    do
43856aec45a7Smrg      arg2=
43866aec45a7Smrg      if test -n "$dest"; then
4387aa9e3350Smrg	func_append files " $dest"
43886aec45a7Smrg	dest=$arg
43895c42550eSmrg	continue
43906aec45a7Smrg      fi
4391ab47cfaaSmrg
43926aec45a7Smrg      case $arg in
4393300bf1aeSmrg      -d) isdir=: ;;
43946aec45a7Smrg      -f)
43956aec45a7Smrg	if $install_cp; then :; else
43966aec45a7Smrg	  prev=$arg
4397ab47cfaaSmrg	fi
43986aec45a7Smrg	;;
43996aec45a7Smrg      -g | -m | -o)
44006aec45a7Smrg	prev=$arg
44016aec45a7Smrg	;;
44026aec45a7Smrg      -s)
44036aec45a7Smrg	stripme=" -s"
44045c42550eSmrg	continue
44055c42550eSmrg	;;
44066aec45a7Smrg      -*)
44076aec45a7Smrg	;;
44085c42550eSmrg      *)
44096aec45a7Smrg	# If the previous option needed an argument, then skip it.
44106aec45a7Smrg	if test -n "$prev"; then
4411300bf1aeSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
44126aec45a7Smrg	    arg2=$install_override_mode
44136aec45a7Smrg	    no_mode=false
44146aec45a7Smrg	  fi
44156aec45a7Smrg	  prev=
44166aec45a7Smrg	else
44176aec45a7Smrg	  dest=$arg
44186aec45a7Smrg	  continue
44196aec45a7Smrg	fi
44201473d951Smrg	;;
44216aec45a7Smrg      esac
4422ab47cfaaSmrg
44236aec45a7Smrg      # Aesthetically quote the argument.
44242b2b4fcbSmrg      func_quote_arg pretty "$arg"
44252b2b4fcbSmrg      func_append install_prog " $func_quote_arg_result"
44266aec45a7Smrg      if test -n "$arg2"; then
44272b2b4fcbSmrg	func_quote_arg pretty "$arg2"
44285c42550eSmrg      fi
44292b2b4fcbSmrg      func_append install_shared_prog " $func_quote_arg_result"
44306aec45a7Smrg    done
44311473d951Smrg
44326aec45a7Smrg    test -z "$install_prog" && \
44336aec45a7Smrg      func_fatal_help "you must specify an install program"
44341473d951Smrg
44356aec45a7Smrg    test -n "$prev" && \
4436300bf1aeSmrg      func_fatal_help "the '$prev' option requires an argument"
44371473d951Smrg
44386aec45a7Smrg    if test -n "$install_override_mode" && $no_mode; then
44396aec45a7Smrg      if $install_cp; then :; else
44402b2b4fcbSmrg	func_quote_arg pretty "$install_override_mode"
44412b2b4fcbSmrg	func_append install_shared_prog " -m $func_quote_arg_result"
44426aec45a7Smrg      fi
44435c42550eSmrg    fi
44441473d951Smrg
44456aec45a7Smrg    if test -z "$files"; then
44466aec45a7Smrg      if test -z "$dest"; then
44476aec45a7Smrg	func_fatal_help "no file or destination specified"
44486aec45a7Smrg      else
44496aec45a7Smrg	func_fatal_help "you must specify a destination"
44501473d951Smrg      fi
44511473d951Smrg    fi
44521473d951Smrg
44536aec45a7Smrg    # Strip any trailing slash from the destination.
44546aec45a7Smrg    func_stripname '' '/' "$dest"
44556aec45a7Smrg    dest=$func_stripname_result
4456ab47cfaaSmrg
44576aec45a7Smrg    # Check to see that the destination is a directory.
4458300bf1aeSmrg    test -d "$dest" && isdir=:
4459300bf1aeSmrg    if $isdir; then
4460300bf1aeSmrg      destdir=$dest
44616aec45a7Smrg      destname=
44626aec45a7Smrg    else
44636aec45a7Smrg      func_dirname_and_basename "$dest" "" "."
4464300bf1aeSmrg      destdir=$func_dirname_result
4465300bf1aeSmrg      destname=$func_basename_result
44666aec45a7Smrg
44676aec45a7Smrg      # Not a directory, so check to see that there is only one file specified.
44686aec45a7Smrg      set dummy $files; shift
44696aec45a7Smrg      test "$#" -gt 1 && \
4470300bf1aeSmrg	func_fatal_help "'$dest' is not a directory"
44716aec45a7Smrg    fi
44726aec45a7Smrg    case $destdir in
44736aec45a7Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
44745c42550eSmrg    *)
44756aec45a7Smrg      for file in $files; do
44766aec45a7Smrg	case $file in
44776aec45a7Smrg	*.lo) ;;
44786aec45a7Smrg	*)
4479300bf1aeSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
44806aec45a7Smrg	  ;;
44816aec45a7Smrg	esac
44826aec45a7Smrg      done
44835c42550eSmrg      ;;
44845c42550eSmrg    esac
4485ab47cfaaSmrg
44866aec45a7Smrg    # This variable tells wrapper scripts just to set variables rather
44876aec45a7Smrg    # than running their programs.
4488300bf1aeSmrg    libtool_install_magic=$magic
4489ab47cfaaSmrg
44906aec45a7Smrg    staticlibs=
44916aec45a7Smrg    future_libdirs=
44926aec45a7Smrg    current_libdirs=
44936aec45a7Smrg    for file in $files; do
4494ab47cfaaSmrg
44956aec45a7Smrg      # Do each installation.
44966aec45a7Smrg      case $file in
44976aec45a7Smrg      *.$libext)
44986aec45a7Smrg	# Do the static libraries later.
4499aa9e3350Smrg	func_append staticlibs " $file"
45006aec45a7Smrg	;;
45016aec45a7Smrg
45026aec45a7Smrg      *.la)
4503aa9e3350Smrg	func_resolve_sysroot "$file"
4504aa9e3350Smrg	file=$func_resolve_sysroot_result
4505aa9e3350Smrg
45066aec45a7Smrg	# Check to see that this really is a libtool archive.
45076aec45a7Smrg	func_lalib_unsafe_p "$file" \
4508300bf1aeSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
45096aec45a7Smrg
45106aec45a7Smrg	library_names=
45116aec45a7Smrg	old_library=
45126aec45a7Smrg	relink_command=
45136aec45a7Smrg	func_source "$file"
45146aec45a7Smrg
45156aec45a7Smrg	# Add the libdir to current_libdirs if it is the destination.
45166aec45a7Smrg	if test "X$destdir" = "X$libdir"; then
45176aec45a7Smrg	  case "$current_libdirs " in
45186aec45a7Smrg	  *" $libdir "*) ;;
4519aa9e3350Smrg	  *) func_append current_libdirs " $libdir" ;;
45201473d951Smrg	  esac
45216aec45a7Smrg	else
45226aec45a7Smrg	  # Note the libdir as a future libdir.
45236aec45a7Smrg	  case "$future_libdirs " in
45246aec45a7Smrg	  *" $libdir "*) ;;
4525aa9e3350Smrg	  *) func_append future_libdirs " $libdir" ;;
45266aec45a7Smrg	  esac
45276aec45a7Smrg	fi
4528ab47cfaaSmrg
45296aec45a7Smrg	func_dirname "$file" "/" ""
4530300bf1aeSmrg	dir=$func_dirname_result
4531aa9e3350Smrg	func_append dir "$objdir"
45326aec45a7Smrg
45336aec45a7Smrg	if test -n "$relink_command"; then
45346aec45a7Smrg	  # Determine the prefix the user has applied to our future dir.
45356aec45a7Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
45366aec45a7Smrg
45376aec45a7Smrg	  # Don't allow the user to place us outside of our expected
45386aec45a7Smrg	  # location b/c this prevents finding dependent libraries that
45396aec45a7Smrg	  # are installed to the same prefix.
45406aec45a7Smrg	  # At present, this check doesn't affect windows .dll's that
45416aec45a7Smrg	  # are installed into $libdir/../bin (currently, that works fine)
45426aec45a7Smrg	  # but it's something to keep an eye on.
45436aec45a7Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544300bf1aeSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
45456aec45a7Smrg
45466aec45a7Smrg	  if test -n "$inst_prefix_dir"; then
45476aec45a7Smrg	    # Stick the inst_prefix_dir data into the link command.
45486aec45a7Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
45496aec45a7Smrg	  else
45506aec45a7Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
45516aec45a7Smrg	  fi
45526aec45a7Smrg
4553300bf1aeSmrg	  func_warning "relinking '$file'"
45546aec45a7Smrg	  func_show_eval "$relink_command" \
4555300bf1aeSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
45566aec45a7Smrg	fi
45576aec45a7Smrg
45586aec45a7Smrg	# See the names of the shared library.
45596aec45a7Smrg	set dummy $library_names; shift
45606aec45a7Smrg	if test -n "$1"; then
4561300bf1aeSmrg	  realname=$1
45626aec45a7Smrg	  shift
45636aec45a7Smrg
4564300bf1aeSmrg	  srcname=$realname
4565300bf1aeSmrg	  test -n "$relink_command" && srcname=${realname}T
45666aec45a7Smrg
45676aec45a7Smrg	  # Install the shared library and build the symlinks.
45686aec45a7Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
45696aec45a7Smrg	      'exit $?'
4570300bf1aeSmrg	  tstripme=$stripme
45716aec45a7Smrg	  case $host_os in
45726aec45a7Smrg	  cygwin* | mingw* | pw32* | cegcc*)
45736aec45a7Smrg	    case $realname in
45746aec45a7Smrg	    *.dll.a)
4575300bf1aeSmrg	      tstripme=
4576300bf1aeSmrg	      ;;
4577300bf1aeSmrg	    esac
4578300bf1aeSmrg	    ;;
4579300bf1aeSmrg	  os2*)
4580300bf1aeSmrg	    case $realname in
4581300bf1aeSmrg	    *_dll.a)
4582300bf1aeSmrg	      tstripme=
45836aec45a7Smrg	      ;;
45846aec45a7Smrg	    esac
45851473d951Smrg	    ;;
45861473d951Smrg	  esac
45876aec45a7Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
45886aec45a7Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
45896aec45a7Smrg	  fi
45906aec45a7Smrg
45916aec45a7Smrg	  if test "$#" -gt 0; then
45926aec45a7Smrg	    # Delete the old symlinks, and create new ones.
4593300bf1aeSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
45946aec45a7Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
45956aec45a7Smrg	    # so we also need to try rm && ln -s.
45966aec45a7Smrg	    for linkname
45976aec45a7Smrg	    do
45986aec45a7Smrg	      test "$linkname" != "$realname" \
45996aec45a7Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
46006aec45a7Smrg	    done
46016aec45a7Smrg	  fi
46026aec45a7Smrg
46036aec45a7Smrg	  # Do each command in the postinstall commands.
4604300bf1aeSmrg	  lib=$destdir/$realname
46056aec45a7Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
46066aec45a7Smrg	fi
46076aec45a7Smrg
46086aec45a7Smrg	# Install the pseudo-library for information purposes.
46096aec45a7Smrg	func_basename "$file"
4610300bf1aeSmrg	name=$func_basename_result
4611300bf1aeSmrg	instname=$dir/${name}i
46126aec45a7Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
46136aec45a7Smrg
46146aec45a7Smrg	# Maybe install the static library, too.
4615aa9e3350Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
46161473d951Smrg	;;
46176aec45a7Smrg
46186aec45a7Smrg      *.lo)
46196aec45a7Smrg	# Install (i.e. copy) a libtool object.
46206aec45a7Smrg
46216aec45a7Smrg	# Figure out destination file name, if it wasn't already specified.
46226aec45a7Smrg	if test -n "$destname"; then
4623300bf1aeSmrg	  destfile=$destdir/$destname
46246aec45a7Smrg	else
46256aec45a7Smrg	  func_basename "$file"
4626300bf1aeSmrg	  destfile=$func_basename_result
4627300bf1aeSmrg	  destfile=$destdir/$destfile
46286aec45a7Smrg	fi
46296aec45a7Smrg
46306aec45a7Smrg	# Deduce the name of the destination old-style object file.
46316aec45a7Smrg	case $destfile in
46326aec45a7Smrg	*.lo)
46336aec45a7Smrg	  func_lo2o "$destfile"
46346aec45a7Smrg	  staticdest=$func_lo2o_result
46355c42550eSmrg	  ;;
46366aec45a7Smrg	*.$objext)
4637300bf1aeSmrg	  staticdest=$destfile
46386aec45a7Smrg	  destfile=
46395c42550eSmrg	  ;;
46406aec45a7Smrg	*)
4641300bf1aeSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
46425c42550eSmrg	  ;;
46436aec45a7Smrg	esac
46446aec45a7Smrg
46456aec45a7Smrg	# Install the libtool object if requested.
46466aec45a7Smrg	test -n "$destfile" && \
46476aec45a7Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46486aec45a7Smrg
46496aec45a7Smrg	# Install the old object if enabled.
4650300bf1aeSmrg	if test yes = "$build_old_libs"; then
46516aec45a7Smrg	  # Deduce the name of the old-style object file.
46526aec45a7Smrg	  func_lo2o "$file"
46536aec45a7Smrg	  staticobj=$func_lo2o_result
46546aec45a7Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
46555c42550eSmrg	fi
46566aec45a7Smrg	exit $EXIT_SUCCESS
46576aec45a7Smrg	;;
4658ab47cfaaSmrg
46596aec45a7Smrg      *)
46606aec45a7Smrg	# Figure out destination file name, if it wasn't already specified.
46616aec45a7Smrg	if test -n "$destname"; then
4662300bf1aeSmrg	  destfile=$destdir/$destname
46635c42550eSmrg	else
46646aec45a7Smrg	  func_basename "$file"
4665300bf1aeSmrg	  destfile=$func_basename_result
4666300bf1aeSmrg	  destfile=$destdir/$destfile
46675c42550eSmrg	fi
4668ab47cfaaSmrg
46696aec45a7Smrg	# If the file is missing, and there is a .exe on the end, strip it
46706aec45a7Smrg	# because it is most likely a libtool script we actually want to
46716aec45a7Smrg	# install
4672300bf1aeSmrg	stripped_ext=
46736aec45a7Smrg	case $file in
46746aec45a7Smrg	  *.exe)
46756aec45a7Smrg	    if test ! -f "$file"; then
46766aec45a7Smrg	      func_stripname '' '.exe' "$file"
46776aec45a7Smrg	      file=$func_stripname_result
4678300bf1aeSmrg	      stripped_ext=.exe
46796aec45a7Smrg	    fi
46806aec45a7Smrg	    ;;
46816aec45a7Smrg	esac
4682ab47cfaaSmrg
46836aec45a7Smrg	# Do a test to see if this is really a libtool program.
46846aec45a7Smrg	case $host in
46856aec45a7Smrg	*cygwin* | *mingw*)
46866aec45a7Smrg	    if func_ltwrapper_executable_p "$file"; then
46876aec45a7Smrg	      func_ltwrapper_scriptname "$file"
46886aec45a7Smrg	      wrapper=$func_ltwrapper_scriptname_result
46896aec45a7Smrg	    else
46906aec45a7Smrg	      func_stripname '' '.exe' "$file"
46916aec45a7Smrg	      wrapper=$func_stripname_result
46926aec45a7Smrg	    fi
46936aec45a7Smrg	    ;;
46946aec45a7Smrg	*)
46956aec45a7Smrg	    wrapper=$file
46966aec45a7Smrg	    ;;
46976aec45a7Smrg	esac
46986aec45a7Smrg	if func_ltwrapper_script_p "$wrapper"; then
46996aec45a7Smrg	  notinst_deplibs=
47006aec45a7Smrg	  relink_command=
4701ab47cfaaSmrg
47026aec45a7Smrg	  func_source "$wrapper"
4703ab47cfaaSmrg
47046aec45a7Smrg	  # Check the variables that should have been set.
47056aec45a7Smrg	  test -z "$generated_by_libtool_version" && \
4706300bf1aeSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707ab47cfaaSmrg
4708300bf1aeSmrg	  finalize=:
47096aec45a7Smrg	  for lib in $notinst_deplibs; do
47106aec45a7Smrg	    # Check to see that each library is installed.
47116aec45a7Smrg	    libdir=
47126aec45a7Smrg	    if test -f "$lib"; then
47136aec45a7Smrg	      func_source "$lib"
47145c42550eSmrg	    fi
4715300bf1aeSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
47166aec45a7Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717300bf1aeSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718300bf1aeSmrg	      finalize=false
47196aec45a7Smrg	    fi
47206aec45a7Smrg	  done
4721ab47cfaaSmrg
47226aec45a7Smrg	  relink_command=
47236aec45a7Smrg	  func_source "$wrapper"
4724ab47cfaaSmrg
47256aec45a7Smrg	  outputname=
4726300bf1aeSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
47276aec45a7Smrg	    $opt_dry_run || {
4728300bf1aeSmrg	      if $finalize; then
47296aec45a7Smrg	        tmpdir=`func_mktempdir`
47306aec45a7Smrg		func_basename "$file$stripped_ext"
4731300bf1aeSmrg		file=$func_basename_result
4732300bf1aeSmrg	        outputname=$tmpdir/$file
47336aec45a7Smrg	        # Replace the output file specification.
47346aec45a7Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
47356aec45a7Smrg
4736300bf1aeSmrg	        $opt_quiet || {
47372b2b4fcbSmrg	          func_quote_arg expand,pretty "$relink_command"
47382b2b4fcbSmrg		  eval "func_echo $func_quote_arg_result"
47396aec45a7Smrg	        }
47406aec45a7Smrg	        if eval "$relink_command"; then :
47416aec45a7Smrg	          else
4742300bf1aeSmrg		  func_error "error: relink '$file' with the above command before installing it"
47436aec45a7Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
47446aec45a7Smrg		  continue
47456aec45a7Smrg	        fi
4746300bf1aeSmrg	        file=$outputname
47476aec45a7Smrg	      else
4748300bf1aeSmrg	        func_warning "cannot relink '$file'"
47496aec45a7Smrg	      fi
47506aec45a7Smrg	    }
47515c42550eSmrg	  else
47526aec45a7Smrg	    # Install the binary that we compiled earlier.
47536aec45a7Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
47545c42550eSmrg	  fi
47556aec45a7Smrg	fi
4756ab47cfaaSmrg
47576aec45a7Smrg	# remove .exe since cygwin /usr/bin/install will append another
47586aec45a7Smrg	# one anyway
47596aec45a7Smrg	case $install_prog,$host in
47606aec45a7Smrg	*/usr/bin/install*,*cygwin*)
47616aec45a7Smrg	  case $file:$destfile in
47626aec45a7Smrg	  *.exe:*.exe)
47636aec45a7Smrg	    # this is ok
47646aec45a7Smrg	    ;;
47656aec45a7Smrg	  *.exe:*)
47666aec45a7Smrg	    destfile=$destfile.exe
47676aec45a7Smrg	    ;;
47686aec45a7Smrg	  *:*.exe)
47696aec45a7Smrg	    func_stripname '' '.exe' "$destfile"
47706aec45a7Smrg	    destfile=$func_stripname_result
47716aec45a7Smrg	    ;;
47726aec45a7Smrg	  esac
47735c42550eSmrg	  ;;
47745c42550eSmrg	esac
47756aec45a7Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
47766aec45a7Smrg	$opt_dry_run || if test -n "$outputname"; then
47776aec45a7Smrg	  ${RM}r "$tmpdir"
47786aec45a7Smrg	fi
47796aec45a7Smrg	;;
47806aec45a7Smrg      esac
47816aec45a7Smrg    done
4782ab47cfaaSmrg
47836aec45a7Smrg    for file in $staticlibs; do
47846aec45a7Smrg      func_basename "$file"
4785300bf1aeSmrg      name=$func_basename_result
47866aec45a7Smrg
47876aec45a7Smrg      # Set up the ranlib parameters.
4788300bf1aeSmrg      oldlib=$destdir/$name
4789aa9e3350Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790aa9e3350Smrg      tool_oldlib=$func_to_tool_file_result
47916aec45a7Smrg
47926aec45a7Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
47936aec45a7Smrg
47946aec45a7Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795aa9e3350Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
47966aec45a7Smrg      fi
47976aec45a7Smrg
47986aec45a7Smrg      # Do each command in the postinstall commands.
47996aec45a7Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
48006aec45a7Smrg    done
48016aec45a7Smrg
48026aec45a7Smrg    test -n "$future_libdirs" && \
4803300bf1aeSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
48046aec45a7Smrg
48056aec45a7Smrg    if test -n "$current_libdirs"; then
48066aec45a7Smrg      # Maybe just do a dry run.
48076aec45a7Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808300bf1aeSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
48096aec45a7Smrg    else
48106aec45a7Smrg      exit $EXIT_SUCCESS
48116aec45a7Smrg    fi
48126aec45a7Smrg}
48136aec45a7Smrg
4814300bf1aeSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
48156aec45a7Smrg
48166aec45a7Smrg
48176aec45a7Smrg# func_generate_dlsyms outputname originator pic_p
48186aec45a7Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
48196aec45a7Smrg# a dlpreopen symbol table.
48206aec45a7Smrgfunc_generate_dlsyms ()
48216aec45a7Smrg{
4822300bf1aeSmrg    $debug_cmd
4823300bf1aeSmrg
4824300bf1aeSmrg    my_outputname=$1
4825300bf1aeSmrg    my_originator=$2
4826300bf1aeSmrg    my_pic_p=${3-false}
4827300bf1aeSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
48286aec45a7Smrg    my_dlsyms=
48296aec45a7Smrg
4830300bf1aeSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
48316aec45a7Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832300bf1aeSmrg	my_dlsyms=${my_outputname}S.c
48336aec45a7Smrg      else
48346aec45a7Smrg	func_error "not configured to extract global symbols from dlpreopened files"
48356aec45a7Smrg      fi
48366aec45a7Smrg    fi
48376aec45a7Smrg
48386aec45a7Smrg    if test -n "$my_dlsyms"; then
48396aec45a7Smrg      case $my_dlsyms in
48406aec45a7Smrg      "") ;;
48416aec45a7Smrg      *.c)
48426aec45a7Smrg	# Discover the nlist of each of the dlfiles.
4843300bf1aeSmrg	nlist=$output_objdir/$my_outputname.nm
48446aec45a7Smrg
48456aec45a7Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
48466aec45a7Smrg
48476aec45a7Smrg	# Parse the name list into a source file.
48486aec45a7Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
48496aec45a7Smrg
48506aec45a7Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851300bf1aeSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852300bf1aeSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
48536aec45a7Smrg
48546aec45a7Smrg#ifdef __cplusplus
48556aec45a7Smrgextern \"C\" {
48566aec45a7Smrg#endif
48576aec45a7Smrg
4858300bf1aeSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
48596aec45a7Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
48606aec45a7Smrg#endif
48616aec45a7Smrg
4862aa9e3350Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863300bf1aeSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864300bf1aeSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865aa9e3350Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866aa9e3350Smrg# define LT_DLSYM_CONST
4867300bf1aeSmrg#elif defined __osf__
4868aa9e3350Smrg/* This system does not cope well with relocations in const data.  */
4869aa9e3350Smrg# define LT_DLSYM_CONST
4870aa9e3350Smrg#else
4871aa9e3350Smrg# define LT_DLSYM_CONST const
4872aa9e3350Smrg#endif
4873aa9e3350Smrg
4874300bf1aeSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875300bf1aeSmrg
48766aec45a7Smrg/* External symbol declarations for the compiler. */\
48776aec45a7Smrg"
48786aec45a7Smrg
4879300bf1aeSmrg	if test yes = "$dlself"; then
4880300bf1aeSmrg	  func_verbose "generating symbol list for '$output'"
48816aec45a7Smrg
48826aec45a7Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
48836aec45a7Smrg
48846aec45a7Smrg	  # Add our own program objects to the symbol list.
48856aec45a7Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
48866aec45a7Smrg	  for progfile in $progfiles; do
4887aa9e3350Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888300bf1aeSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889aa9e3350Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
48906aec45a7Smrg	  done
48916aec45a7Smrg
48926aec45a7Smrg	  if test -n "$exclude_expsyms"; then
48936aec45a7Smrg	    $opt_dry_run || {
48946aec45a7Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
48956aec45a7Smrg	      eval '$MV "$nlist"T "$nlist"'
48966aec45a7Smrg	    }
48975c42550eSmrg	  fi
48986aec45a7Smrg
48996aec45a7Smrg	  if test -n "$export_symbols_regex"; then
49006aec45a7Smrg	    $opt_dry_run || {
49016aec45a7Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
49026aec45a7Smrg	      eval '$MV "$nlist"T "$nlist"'
49036aec45a7Smrg	    }
49046aec45a7Smrg	  fi
49056aec45a7Smrg
49066aec45a7Smrg	  # Prepare the list of exported symbols
49076aec45a7Smrg	  if test -z "$export_symbols"; then
4908300bf1aeSmrg	    export_symbols=$output_objdir/$outputname.exp
49096aec45a7Smrg	    $opt_dry_run || {
49106aec45a7Smrg	      $RM $export_symbols
4911300bf1aeSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
49126aec45a7Smrg	      case $host in
49136aec45a7Smrg	      *cygwin* | *mingw* | *cegcc* )
49146aec45a7Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49156aec45a7Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
49166aec45a7Smrg	        ;;
49176aec45a7Smrg	      esac
49186aec45a7Smrg	    }
49195c42550eSmrg	  else
49206aec45a7Smrg	    $opt_dry_run || {
4921300bf1aeSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
49226aec45a7Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
49236aec45a7Smrg	      eval '$MV "$nlist"T "$nlist"'
49246aec45a7Smrg	      case $host in
49256aec45a7Smrg	        *cygwin* | *mingw* | *cegcc* )
49266aec45a7Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49276aec45a7Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
49286aec45a7Smrg	          ;;
49296aec45a7Smrg	      esac
49306aec45a7Smrg	    }
49315c42550eSmrg	  fi
49326aec45a7Smrg	fi
4933ab47cfaaSmrg
49346aec45a7Smrg	for dlprefile in $dlprefiles; do
4935300bf1aeSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
49366aec45a7Smrg	  func_basename "$dlprefile"
4937300bf1aeSmrg	  name=$func_basename_result
4938aa9e3350Smrg          case $host in
4939aa9e3350Smrg	    *cygwin* | *mingw* | *cegcc* )
4940aa9e3350Smrg	      # if an import library, we need to obtain dlname
4941aa9e3350Smrg	      if func_win32_import_lib_p "$dlprefile"; then
4942aa9e3350Smrg	        func_tr_sh "$dlprefile"
4943aa9e3350Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944300bf1aeSmrg	        dlprefile_dlbasename=
4945aa9e3350Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946aa9e3350Smrg	          # Use subshell, to avoid clobbering current variable values
4947aa9e3350Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948300bf1aeSmrg	          if test -n "$dlprefile_dlname"; then
4949aa9e3350Smrg	            func_basename "$dlprefile_dlname"
4950300bf1aeSmrg	            dlprefile_dlbasename=$func_basename_result
4951aa9e3350Smrg	          else
4952aa9e3350Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953aa9e3350Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954aa9e3350Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955aa9e3350Smrg	          fi
4956aa9e3350Smrg	        fi
4957aa9e3350Smrg	        $opt_dry_run || {
4958300bf1aeSmrg	          if test -n "$dlprefile_dlbasename"; then
4959aa9e3350Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960aa9e3350Smrg	          else
4961aa9e3350Smrg	            func_warning "Could not compute DLL name from $name"
4962aa9e3350Smrg	            eval '$ECHO ": $name " >> "$nlist"'
4963aa9e3350Smrg	          fi
4964aa9e3350Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965aa9e3350Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966aa9e3350Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967aa9e3350Smrg	        }
4968aa9e3350Smrg	      else # not an import lib
4969aa9e3350Smrg	        $opt_dry_run || {
4970aa9e3350Smrg	          eval '$ECHO ": $name " >> "$nlist"'
4971aa9e3350Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972aa9e3350Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973aa9e3350Smrg	        }
4974aa9e3350Smrg	      fi
4975aa9e3350Smrg	    ;;
4976aa9e3350Smrg	    *)
4977aa9e3350Smrg	      $opt_dry_run || {
4978aa9e3350Smrg	        eval '$ECHO ": $name " >> "$nlist"'
4979aa9e3350Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980aa9e3350Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981aa9e3350Smrg	      }
4982aa9e3350Smrg	    ;;
4983aa9e3350Smrg          esac
49846aec45a7Smrg	done
49856aec45a7Smrg
49866aec45a7Smrg	$opt_dry_run || {
49876aec45a7Smrg	  # Make sure we have at least an empty file.
49886aec45a7Smrg	  test -f "$nlist" || : > "$nlist"
49896aec45a7Smrg
49906aec45a7Smrg	  if test -n "$exclude_expsyms"; then
49916aec45a7Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
49926aec45a7Smrg	    $MV "$nlist"T "$nlist"
49935c42550eSmrg	  fi
49946aec45a7Smrg
49956aec45a7Smrg	  # Try sorting and uniquifying the output.
49966aec45a7Smrg	  if $GREP -v "^: " < "$nlist" |
49976aec45a7Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
49986aec45a7Smrg		sort -k 3
49996aec45a7Smrg	      else
50006aec45a7Smrg		sort +2
50016aec45a7Smrg	      fi |
50026aec45a7Smrg	      uniq > "$nlist"S; then
50036aec45a7Smrg	    :
50045c42550eSmrg	  else
50056aec45a7Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
50065c42550eSmrg	  fi
5007ab47cfaaSmrg
50086aec45a7Smrg	  if test -f "$nlist"S; then
50096aec45a7Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
50105c42550eSmrg	  else
50116aec45a7Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
50125c42550eSmrg	  fi
5013ab47cfaaSmrg
5014300bf1aeSmrg	  func_show_eval '$RM "${nlist}I"'
5015300bf1aeSmrg	  if test -n "$global_symbol_to_import"; then
5016300bf1aeSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017300bf1aeSmrg	  fi
5018300bf1aeSmrg
50196aec45a7Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020ab47cfaaSmrg
50216aec45a7Smrg/* The mapping between symbol names and symbols.  */
50226aec45a7Smrgtypedef struct {
50236aec45a7Smrg  const char *name;
50246aec45a7Smrg  void *address;
50256aec45a7Smrg} lt_dlsymlist;
5026aa9e3350Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027300bf1aeSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028300bf1aeSmrg"
5029300bf1aeSmrg
5030300bf1aeSmrg	  if test -s "$nlist"I; then
5031300bf1aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032300bf1aeSmrgstatic void lt_syminit(void)
5033300bf1aeSmrg{
5034300bf1aeSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035300bf1aeSmrg  for (; symbol->name; ++symbol)
5036300bf1aeSmrg    {"
5037300bf1aeSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038300bf1aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039300bf1aeSmrg    }
5040300bf1aeSmrg}"
5041300bf1aeSmrg	  fi
5042300bf1aeSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043aa9e3350SmrgLT_DLSYM_CONST lt_dlsymlist
50446aec45a7Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045300bf1aeSmrg{ {\"$my_originator\", (void *) 0},"
5046300bf1aeSmrg
5047300bf1aeSmrg	  if test -s "$nlist"I; then
5048300bf1aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049300bf1aeSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5050300bf1aeSmrg	  fi
5051ab47cfaaSmrg
50526aec45a7Smrg	  case $need_lib_prefix in
50536aec45a7Smrg	  no)
50546aec45a7Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
50556aec45a7Smrg	    ;;
50566aec45a7Smrg	  *)
50576aec45a7Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
50586aec45a7Smrg	    ;;
50596aec45a7Smrg	  esac
50606aec45a7Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50616aec45a7Smrg  {0, (void *) 0}
50626aec45a7Smrg};
50631473d951Smrg
50646aec45a7Smrg/* This works around a problem in FreeBSD linker */
50656aec45a7Smrg#ifdef FREEBSD_WORKAROUND
50666aec45a7Smrgstatic const void *lt_preloaded_setup() {
50676aec45a7Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
50686aec45a7Smrg}
50696aec45a7Smrg#endif
5070ab47cfaaSmrg
50716aec45a7Smrg#ifdef __cplusplus
50726aec45a7Smrg}
50736aec45a7Smrg#endif\
50746aec45a7Smrg"
50756aec45a7Smrg	} # !$opt_dry_run
50761473d951Smrg
50776aec45a7Smrg	pic_flag_for_symtable=
50786aec45a7Smrg	case "$compile_command " in
50796aec45a7Smrg	*" -static "*) ;;
50806aec45a7Smrg	*)
50816aec45a7Smrg	  case $host in
50826aec45a7Smrg	  # compiling the symbol table file with pic_flag works around
50836aec45a7Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
50846aec45a7Smrg	  # linked before any other PIC object.  But we must not use
50856aec45a7Smrg	  # pic_flag when linking with -static.  The problem exists in
50866aec45a7Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087aa9e3350Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
50886aec45a7Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
50896aec45a7Smrg	  *-*-hpux*)
50906aec45a7Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
50916aec45a7Smrg	  *)
5092300bf1aeSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
50936aec45a7Smrg	    ;;
50946aec45a7Smrg	  esac
50956aec45a7Smrg	  ;;
50966aec45a7Smrg	esac
50976aec45a7Smrg	symtab_cflags=
50986aec45a7Smrg	for arg in $LTCFLAGS; do
50996aec45a7Smrg	  case $arg in
51006aec45a7Smrg	  -pie | -fpie | -fPIE) ;;
5101aa9e3350Smrg	  *) func_append symtab_cflags " $arg" ;;
51026aec45a7Smrg	  esac
51036aec45a7Smrg	done
5104ab47cfaaSmrg
51056aec45a7Smrg	# Now compile the dynamic symbol file.
51066aec45a7Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107ab47cfaaSmrg
51086aec45a7Smrg	# Clean up the generated files.
5109300bf1aeSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
51101473d951Smrg
51116aec45a7Smrg	# Transform the symbol file into the correct name.
5112300bf1aeSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
51136aec45a7Smrg	case $host in
51146aec45a7Smrg	*cygwin* | *mingw* | *cegcc* )
51156aec45a7Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
51166aec45a7Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51176aec45a7Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51186aec45a7Smrg	  else
51196aec45a7Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51206aec45a7Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51216aec45a7Smrg	  fi
51226aec45a7Smrg	  ;;
51236aec45a7Smrg	*)
51246aec45a7Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51256aec45a7Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51266aec45a7Smrg	  ;;
51276aec45a7Smrg	esac
51286aec45a7Smrg	;;
51296aec45a7Smrg      *)
5130300bf1aeSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
51316aec45a7Smrg	;;
51326aec45a7Smrg      esac
51336aec45a7Smrg    else
51346aec45a7Smrg      # We keep going just in case the user didn't refer to
51356aec45a7Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
51366aec45a7Smrg      # really was required.
51371473d951Smrg
51386aec45a7Smrg      # Nullify the symbol file.
51396aec45a7Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
51406aec45a7Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
51416aec45a7Smrg    fi
51426aec45a7Smrg}
51431473d951Smrg
5144300bf1aeSmrg# func_cygming_gnu_implib_p ARG
5145300bf1aeSmrg# This predicate returns with zero status (TRUE) if
5146300bf1aeSmrg# ARG is a GNU/binutils-style import library. Returns
5147300bf1aeSmrg# with nonzero status (FALSE) otherwise.
5148300bf1aeSmrgfunc_cygming_gnu_implib_p ()
5149300bf1aeSmrg{
5150300bf1aeSmrg  $debug_cmd
5151300bf1aeSmrg
5152300bf1aeSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153300bf1aeSmrg  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)$'`
5154300bf1aeSmrg  test -n "$func_cygming_gnu_implib_tmp"
5155300bf1aeSmrg}
5156300bf1aeSmrg
5157300bf1aeSmrg# func_cygming_ms_implib_p ARG
5158300bf1aeSmrg# This predicate returns with zero status (TRUE) if
5159300bf1aeSmrg# ARG is an MS-style import library. Returns
5160300bf1aeSmrg# with nonzero status (FALSE) otherwise.
5161300bf1aeSmrgfunc_cygming_ms_implib_p ()
5162300bf1aeSmrg{
5163300bf1aeSmrg  $debug_cmd
5164300bf1aeSmrg
5165300bf1aeSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166300bf1aeSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167300bf1aeSmrg  test -n "$func_cygming_ms_implib_tmp"
5168300bf1aeSmrg}
5169300bf1aeSmrg
51706aec45a7Smrg# func_win32_libid arg
51716aec45a7Smrg# return the library type of file 'arg'
51726aec45a7Smrg#
51736aec45a7Smrg# Need a lot of goo to handle *both* DLLs and import libs
51746aec45a7Smrg# Has to be a shell function in order to 'eat' the argument
51756aec45a7Smrg# that is supplied when $file_magic_command is called.
51766aec45a7Smrg# Despite the name, also deal with 64 bit binaries.
51776aec45a7Smrgfunc_win32_libid ()
51786aec45a7Smrg{
5179300bf1aeSmrg  $debug_cmd
5180300bf1aeSmrg
5181300bf1aeSmrg  win32_libid_type=unknown
51826aec45a7Smrg  win32_fileres=`file -L $1 2>/dev/null`
51836aec45a7Smrg  case $win32_fileres in
51846aec45a7Smrg  *ar\ archive\ import\ library*) # definitely import
51856aec45a7Smrg    win32_libid_type="x86 archive import"
51866aec45a7Smrg    ;;
51876aec45a7Smrg  *ar\ archive*) # could be an import, or static
51886aec45a7Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
51896aec45a7Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
51906aec45a7Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191300bf1aeSmrg      case $nm_interface in
5192300bf1aeSmrg      "MS dumpbin")
5193300bf1aeSmrg	if func_cygming_ms_implib_p "$1" ||
5194300bf1aeSmrg	   func_cygming_gnu_implib_p "$1"
5195300bf1aeSmrg	then
5196300bf1aeSmrg	  win32_nmres=import
5197300bf1aeSmrg	else
5198300bf1aeSmrg	  win32_nmres=
5199300bf1aeSmrg	fi
5200300bf1aeSmrg	;;
5201300bf1aeSmrg      *)
5202300bf1aeSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203300bf1aeSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204300bf1aeSmrg	  $SED -n -e '
52056aec45a7Smrg	    1,100{
52066aec45a7Smrg		/ I /{
5207300bf1aeSmrg		    s|.*|import|
52086aec45a7Smrg		    p
52096aec45a7Smrg		    q
52106aec45a7Smrg		}
52116aec45a7Smrg	    }'`
5212300bf1aeSmrg	;;
5213300bf1aeSmrg      esac
52146aec45a7Smrg      case $win32_nmres in
52156aec45a7Smrg      import*)  win32_libid_type="x86 archive import";;
52166aec45a7Smrg      *)        win32_libid_type="x86 archive static";;
52176aec45a7Smrg      esac
52186aec45a7Smrg    fi
52196aec45a7Smrg    ;;
52206aec45a7Smrg  *DLL*)
52216aec45a7Smrg    win32_libid_type="x86 DLL"
52226aec45a7Smrg    ;;
52236aec45a7Smrg  *executable*) # but shell scripts are "executable" too...
52246aec45a7Smrg    case $win32_fileres in
52256aec45a7Smrg    *MS\ Windows\ PE\ Intel*)
52266aec45a7Smrg      win32_libid_type="x86 DLL"
52276aec45a7Smrg      ;;
52286aec45a7Smrg    esac
52296aec45a7Smrg    ;;
52306aec45a7Smrg  esac
52316aec45a7Smrg  $ECHO "$win32_libid_type"
52326aec45a7Smrg}
52331473d951Smrg
5234aa9e3350Smrg# func_cygming_dll_for_implib ARG
5235aa9e3350Smrg#
5236aa9e3350Smrg# Platform-specific function to extract the
5237aa9e3350Smrg# name of the DLL associated with the specified
5238aa9e3350Smrg# import library ARG.
5239aa9e3350Smrg# Invoked by eval'ing the libtool variable
5240aa9e3350Smrg#    $sharedlib_from_linklib_cmd
5241aa9e3350Smrg# Result is available in the variable
5242aa9e3350Smrg#    $sharedlib_from_linklib_result
5243aa9e3350Smrgfunc_cygming_dll_for_implib ()
5244aa9e3350Smrg{
5245300bf1aeSmrg  $debug_cmd
5246300bf1aeSmrg
5247aa9e3350Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248aa9e3350Smrg}
5249aa9e3350Smrg
5250aa9e3350Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251aa9e3350Smrg#
5252aa9e3350Smrg# The is the core of a fallback implementation of a
5253aa9e3350Smrg# platform-specific function to extract the name of the
5254aa9e3350Smrg# DLL associated with the specified import library LIBNAME.
5255aa9e3350Smrg#
5256aa9e3350Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257aa9e3350Smrg# on the platform and compiler that created the implib.
5258aa9e3350Smrg#
5259aa9e3350Smrg# Echos the name of the DLL associated with the
5260aa9e3350Smrg# specified import library.
5261aa9e3350Smrgfunc_cygming_dll_for_implib_fallback_core ()
5262aa9e3350Smrg{
5263300bf1aeSmrg  $debug_cmd
5264300bf1aeSmrg
5265aa9e3350Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266aa9e3350Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267aa9e3350Smrg    $SED '/^Contents of section '"$match_literal"':/{
5268aa9e3350Smrg      # Place marker at beginning of archive member dllname section
5269aa9e3350Smrg      s/.*/====MARK====/
5270aa9e3350Smrg      p
5271aa9e3350Smrg      d
5272aa9e3350Smrg    }
5273aa9e3350Smrg    # These lines can sometimes be longer than 43 characters, but
5274aa9e3350Smrg    # are always uninteresting
5275aa9e3350Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276aa9e3350Smrg    /^In archive [^:]*:/d
5277aa9e3350Smrg    # Ensure marker is printed
5278aa9e3350Smrg    /^====MARK====/p
5279aa9e3350Smrg    # Remove all lines with less than 43 characters
5280aa9e3350Smrg    /^.\{43\}/!d
5281aa9e3350Smrg    # From remaining lines, remove first 43 characters
5282aa9e3350Smrg    s/^.\{43\}//' |
5283aa9e3350Smrg    $SED -n '
5284aa9e3350Smrg      # Join marker and all lines until next marker into a single line
5285aa9e3350Smrg      /^====MARK====/ b para
5286aa9e3350Smrg      H
5287aa9e3350Smrg      $ b para
5288aa9e3350Smrg      b
5289aa9e3350Smrg      :para
5290aa9e3350Smrg      x
5291aa9e3350Smrg      s/\n//g
5292aa9e3350Smrg      # Remove the marker
5293aa9e3350Smrg      s/^====MARK====//
5294aa9e3350Smrg      # Remove trailing dots and whitespace
5295aa9e3350Smrg      s/[\. \t]*$//
5296aa9e3350Smrg      # Print
5297aa9e3350Smrg      /./p' |
5298aa9e3350Smrg    # we now have a list, one entry per line, of the stringified
5299aa9e3350Smrg    # contents of the appropriate section of all members of the
5300300bf1aeSmrg    # archive that possess that section. Heuristic: eliminate
5301300bf1aeSmrg    # all those that have a first or second character that is
5302aa9e3350Smrg    # a '.' (that is, objdump's representation of an unprintable
5303aa9e3350Smrg    # character.) This should work for all archives with less than
5304aa9e3350Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305aa9e3350Smrg    # begins with a literal '.' or a single character followed by
5306aa9e3350Smrg    # a '.'.
5307aa9e3350Smrg    #
5308aa9e3350Smrg    # Of those that remain, print the first one.
5309aa9e3350Smrg    $SED -e '/^\./d;/^.\./d;q'
5310aa9e3350Smrg}
5311aa9e3350Smrg
5312aa9e3350Smrg# func_cygming_dll_for_implib_fallback ARG
5313aa9e3350Smrg# Platform-specific function to extract the
5314aa9e3350Smrg# name of the DLL associated with the specified
5315aa9e3350Smrg# import library ARG.
5316aa9e3350Smrg#
5317aa9e3350Smrg# This fallback implementation is for use when $DLLTOOL
5318aa9e3350Smrg# does not support the --identify-strict option.
5319aa9e3350Smrg# Invoked by eval'ing the libtool variable
5320aa9e3350Smrg#    $sharedlib_from_linklib_cmd
5321aa9e3350Smrg# Result is available in the variable
5322aa9e3350Smrg#    $sharedlib_from_linklib_result
5323aa9e3350Smrgfunc_cygming_dll_for_implib_fallback ()
5324aa9e3350Smrg{
5325300bf1aeSmrg  $debug_cmd
5326300bf1aeSmrg
5327300bf1aeSmrg  if func_cygming_gnu_implib_p "$1"; then
5328aa9e3350Smrg    # binutils import library
5329aa9e3350Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330300bf1aeSmrg  elif func_cygming_ms_implib_p "$1"; then
5331aa9e3350Smrg    # ms-generated import library
5332aa9e3350Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333aa9e3350Smrg  else
5334aa9e3350Smrg    # unknown
5335300bf1aeSmrg    sharedlib_from_linklib_result=
5336aa9e3350Smrg  fi
5337aa9e3350Smrg}
5338ab47cfaaSmrg
5339ab47cfaaSmrg
53406aec45a7Smrg# func_extract_an_archive dir oldlib
53416aec45a7Smrgfunc_extract_an_archive ()
53426aec45a7Smrg{
5343300bf1aeSmrg    $debug_cmd
5344300bf1aeSmrg
5345300bf1aeSmrg    f_ex_an_ar_dir=$1; shift
5346300bf1aeSmrg    f_ex_an_ar_oldlib=$1
5347300bf1aeSmrg    if test yes = "$lock_old_archive_extraction"; then
53486aec45a7Smrg      lockfile=$f_ex_an_ar_oldlib.lock
53496aec45a7Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
53506aec45a7Smrg	func_echo "Waiting for $lockfile to be removed"
53516aec45a7Smrg	sleep 2
53526aec45a7Smrg      done
53536aec45a7Smrg    fi
53546aec45a7Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
53556aec45a7Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356300bf1aeSmrg    if test yes = "$lock_old_archive_extraction"; then
53576aec45a7Smrg      $opt_dry_run || rm -f "$lockfile"
53586aec45a7Smrg    fi
53596aec45a7Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
53606aec45a7Smrg     :
53616aec45a7Smrg    else
53626aec45a7Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
53636aec45a7Smrg    fi
53646aec45a7Smrg}
53651473d951Smrg
53661473d951Smrg
53676aec45a7Smrg# func_extract_archives gentop oldlib ...
53686aec45a7Smrgfunc_extract_archives ()
53696aec45a7Smrg{
5370300bf1aeSmrg    $debug_cmd
5371300bf1aeSmrg
5372300bf1aeSmrg    my_gentop=$1; shift
53736aec45a7Smrg    my_oldlibs=${1+"$@"}
5374300bf1aeSmrg    my_oldobjs=
5375300bf1aeSmrg    my_xlib=
5376300bf1aeSmrg    my_xabs=
5377300bf1aeSmrg    my_xdir=
53781473d951Smrg
53796aec45a7Smrg    for my_xlib in $my_oldlibs; do
53806aec45a7Smrg      # Extract the objects.
53816aec45a7Smrg      case $my_xlib in
5382300bf1aeSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
53836aec45a7Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
53846aec45a7Smrg      esac
53856aec45a7Smrg      func_basename "$my_xlib"
5386300bf1aeSmrg      my_xlib=$func_basename_result
53876aec45a7Smrg      my_xlib_u=$my_xlib
53886aec45a7Smrg      while :; do
53896aec45a7Smrg        case " $extracted_archives " in
53906aec45a7Smrg	*" $my_xlib_u "*)
53916aec45a7Smrg	  func_arith $extracted_serial + 1
53926aec45a7Smrg	  extracted_serial=$func_arith_result
53936aec45a7Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
53946aec45a7Smrg	*) break ;;
53956aec45a7Smrg	esac
53966aec45a7Smrg      done
53976aec45a7Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398300bf1aeSmrg      my_xdir=$my_gentop/$my_xlib_u
53991473d951Smrg
54006aec45a7Smrg      func_mkdir_p "$my_xdir"
54016aec45a7Smrg
54026aec45a7Smrg      case $host in
54036aec45a7Smrg      *-darwin*)
54046aec45a7Smrg	func_verbose "Extracting $my_xabs"
54056aec45a7Smrg	# Do not bother doing anything if just a dry run
54066aec45a7Smrg	$opt_dry_run || {
54076aec45a7Smrg	  darwin_orig_dir=`pwd`
54086aec45a7Smrg	  cd $my_xdir || exit $?
54096aec45a7Smrg	  darwin_archive=$my_xabs
54106aec45a7Smrg	  darwin_curdir=`pwd`
5411300bf1aeSmrg	  func_basename "$darwin_archive"
5412300bf1aeSmrg	  darwin_base_archive=$func_basename_result
54136aec45a7Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
54146aec45a7Smrg	  if test -n "$darwin_arches"; then
54156aec45a7Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
54166aec45a7Smrg	    darwin_arch=
54176aec45a7Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418300bf1aeSmrg	    for darwin_arch in  $darwin_arches; do
5419300bf1aeSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420300bf1aeSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421300bf1aeSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422300bf1aeSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
54236aec45a7Smrg	      cd "$darwin_curdir"
5424300bf1aeSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
54256aec45a7Smrg	    done # $darwin_arches
54266aec45a7Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427300bf1aeSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
54286aec45a7Smrg	    darwin_file=
54296aec45a7Smrg	    darwin_files=
54306aec45a7Smrg	    for darwin_file in $darwin_filelist; do
54316aec45a7Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
54326aec45a7Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
54336aec45a7Smrg	    done # $darwin_filelist
54346aec45a7Smrg	    $RM -rf unfat-$$
54356aec45a7Smrg	    cd "$darwin_orig_dir"
54365c42550eSmrg	  else
54376aec45a7Smrg	    cd $darwin_orig_dir
54386aec45a7Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
54396aec45a7Smrg	  fi # $darwin_arches
54406aec45a7Smrg	} # !$opt_dry_run
54416aec45a7Smrg	;;
54426aec45a7Smrg      *)
54436aec45a7Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
54446aec45a7Smrg	;;
54456aec45a7Smrg      esac
54466aec45a7Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
54476aec45a7Smrg    done
5448ab47cfaaSmrg
5449300bf1aeSmrg    func_extract_archives_result=$my_oldobjs
54506aec45a7Smrg}
5451ab47cfaaSmrg
54521473d951Smrg
54536aec45a7Smrg# func_emit_wrapper [arg=no]
54546aec45a7Smrg#
54556aec45a7Smrg# Emit a libtool wrapper script on stdout.
54566aec45a7Smrg# Don't directly open a file because we may want to
54576aec45a7Smrg# incorporate the script contents within a cygwin/mingw
54586aec45a7Smrg# wrapper executable.  Must ONLY be called from within
54596aec45a7Smrg# func_mode_link because it depends on a number of variables
54606aec45a7Smrg# set therein.
54616aec45a7Smrg#
54626aec45a7Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
54636aec45a7Smrg# variable will take.  If 'yes', then the emitted script
5464300bf1aeSmrg# will assume that the directory where it is stored is
54656aec45a7Smrg# the $objdir directory.  This is a cygwin/mingw-specific
54666aec45a7Smrg# behavior.
54676aec45a7Smrgfunc_emit_wrapper ()
54686aec45a7Smrg{
54696aec45a7Smrg	func_emit_wrapper_arg1=${1-no}
54705c42550eSmrg
54716aec45a7Smrg	$ECHO "\
54726aec45a7Smrg#! $SHELL
54731473d951Smrg
54746aec45a7Smrg# $output - temporary wrapper script for $objdir/$outputname
5475300bf1aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
54766aec45a7Smrg#
54776aec45a7Smrg# The $output program cannot be directly executed until all the libtool
54786aec45a7Smrg# libraries that it depends on are installed.
54796aec45a7Smrg#
54806aec45a7Smrg# This wrapper script should never be moved out of the build directory.
54816aec45a7Smrg# If it is, it will not operate correctly.
5482ab47cfaaSmrg
54836aec45a7Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
54846aec45a7Smrg# metacharacters that are still active within double-quoted strings.
54856aec45a7Smrgsed_quote_subst='$sed_quote_subst'
5486ab47cfaaSmrg
54876aec45a7Smrg# Be Bourne compatible
54886aec45a7Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
54896aec45a7Smrg  emulate sh
54906aec45a7Smrg  NULLCMD=:
54916aec45a7Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
54926aec45a7Smrg  # is contrary to our usage.  Disable this feature.
54936aec45a7Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
54946aec45a7Smrg  setopt NO_GLOB_SUBST
54956aec45a7Smrgelse
54966aec45a7Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
54976aec45a7Smrgfi
54986aec45a7SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
54996aec45a7SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500ab47cfaaSmrg
55016aec45a7Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
55026aec45a7Smrg# if CDPATH is set.
55036aec45a7Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504ab47cfaaSmrg
55056aec45a7Smrgrelink_command=\"$relink_command\"
5506ab47cfaaSmrg
55076aec45a7Smrg# This environment variable determines our operation mode.
55086aec45a7Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
55096aec45a7Smrg  # install mode needs the following variables:
55106aec45a7Smrg  generated_by_libtool_version='$macro_version'
55116aec45a7Smrg  notinst_deplibs='$notinst_deplibs'
55126aec45a7Smrgelse
55136aec45a7Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
55146aec45a7Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
55156aec45a7Smrg    file=\"\$0\""
5516ab47cfaaSmrg
55172b2b4fcbSmrg    func_quote_arg pretty "$ECHO"
55182b2b4fcbSmrg    qECHO=$func_quote_arg_result
55196aec45a7Smrg    $ECHO "\
5520ab47cfaaSmrg
55216aec45a7Smrg# A function that is used when there is no print builtin or printf.
55226aec45a7Smrgfunc_fallback_echo ()
55236aec45a7Smrg{
55246aec45a7Smrg  eval 'cat <<_LTECHO_EOF
55256aec45a7Smrg\$1
55266aec45a7Smrg_LTECHO_EOF'
55276aec45a7Smrg}
55282b2b4fcbSmrg    ECHO=$qECHO
55296aec45a7Smrg  fi
55306aec45a7Smrg
55316aec45a7Smrg# Very basic option parsing. These options are (a) specific to
55326aec45a7Smrg# the libtool wrapper, (b) are identical between the wrapper
5533300bf1aeSmrg# /script/ and the wrapper /executable/ that is used only on
55346aec45a7Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535300bf1aeSmrg# (application programs are unlikely to have options that match
55366aec45a7Smrg# this pattern).
55376aec45a7Smrg#
55386aec45a7Smrg# There are only two supported options: --lt-debug and
55396aec45a7Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
55406aec45a7Smrg#
55416aec45a7Smrg# The first argument to this parsing function should be the
55426aec45a7Smrg# script's $0 value, followed by "$@".
55436aec45a7Smrglt_option_debug=
55446aec45a7Smrgfunc_parse_lt_options ()
55456aec45a7Smrg{
55466aec45a7Smrg  lt_script_arg0=\$0
55476aec45a7Smrg  shift
55486aec45a7Smrg  for lt_opt
55496aec45a7Smrg  do
55506aec45a7Smrg    case \"\$lt_opt\" in
55516aec45a7Smrg    --lt-debug) lt_option_debug=1 ;;
55526aec45a7Smrg    --lt-dump-script)
55536aec45a7Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
55546aec45a7Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
55556aec45a7Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
55566aec45a7Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
55576aec45a7Smrg        exit 0
55586aec45a7Smrg      ;;
55596aec45a7Smrg    --lt-*)
55606aec45a7Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
55616aec45a7Smrg        exit 1
55625c42550eSmrg      ;;
55636aec45a7Smrg    esac
55646aec45a7Smrg  done
5565ab47cfaaSmrg
55666aec45a7Smrg  # Print the debug banner immediately:
55676aec45a7Smrg  if test -n \"\$lt_option_debug\"; then
5568300bf1aeSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
55696aec45a7Smrg  fi
55706aec45a7Smrg}
5571ab47cfaaSmrg
55726aec45a7Smrg# Used when --lt-debug. Prints its arguments to stdout
55736aec45a7Smrg# (redirection is the responsibility of the caller)
55746aec45a7Smrgfunc_lt_dump_args ()
55756aec45a7Smrg{
55766aec45a7Smrg  lt_dump_args_N=1;
55776aec45a7Smrg  for lt_arg
55786aec45a7Smrg  do
5579300bf1aeSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
55806aec45a7Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
55816aec45a7Smrg  done
55826aec45a7Smrg}
5583ab47cfaaSmrg
55846aec45a7Smrg# Core function for launching the target application
55856aec45a7Smrgfunc_exec_program_core ()
55866aec45a7Smrg{
55876aec45a7Smrg"
55886aec45a7Smrg  case $host in
55896aec45a7Smrg  # Backslashes separate directories on plain windows
55906aec45a7Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
55916aec45a7Smrg    $ECHO "\
55926aec45a7Smrg      if test -n \"\$lt_option_debug\"; then
5593300bf1aeSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
55946aec45a7Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
55955c42550eSmrg      fi
55966aec45a7Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
55976aec45a7Smrg"
55986aec45a7Smrg    ;;
5599ab47cfaaSmrg
56006aec45a7Smrg  *)
56016aec45a7Smrg    $ECHO "\
56026aec45a7Smrg      if test -n \"\$lt_option_debug\"; then
5603300bf1aeSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
56046aec45a7Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
56055c42550eSmrg      fi
56066aec45a7Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
56076aec45a7Smrg"
56086aec45a7Smrg    ;;
56096aec45a7Smrg  esac
56106aec45a7Smrg  $ECHO "\
56116aec45a7Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
56126aec45a7Smrg      exit 1
56136aec45a7Smrg}
5614ab47cfaaSmrg
56156aec45a7Smrg# A function to encapsulate launching the target application
56166aec45a7Smrg# Strips options in the --lt-* namespace from \$@ and
56176aec45a7Smrg# launches target application with the remaining arguments.
56186aec45a7Smrgfunc_exec_program ()
56196aec45a7Smrg{
5620aa9e3350Smrg  case \" \$* \" in
5621aa9e3350Smrg  *\\ --lt-*)
5622aa9e3350Smrg    for lt_wr_arg
5623aa9e3350Smrg    do
5624aa9e3350Smrg      case \$lt_wr_arg in
5625aa9e3350Smrg      --lt-*) ;;
5626aa9e3350Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627aa9e3350Smrg      esac
5628aa9e3350Smrg      shift
5629aa9e3350Smrg    done ;;
5630aa9e3350Smrg  esac
56316aec45a7Smrg  func_exec_program_core \${1+\"\$@\"}
56326aec45a7Smrg}
5633ab47cfaaSmrg
56346aec45a7Smrg  # Parse options
56356aec45a7Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636ab47cfaaSmrg
56376aec45a7Smrg  # Find the directory that this script lives in.
56386aec45a7Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
56396aec45a7Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640ab47cfaaSmrg
56416aec45a7Smrg  # Follow symbolic links until we get to the real thisdir.
56426aec45a7Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
56436aec45a7Smrg  while test -n \"\$file\"; do
56446aec45a7Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645ab47cfaaSmrg
56466aec45a7Smrg    # If there was a directory component, then change thisdir.
56476aec45a7Smrg    if test \"x\$destdir\" != \"x\$file\"; then
56486aec45a7Smrg      case \"\$destdir\" in
56496aec45a7Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
56506aec45a7Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
56516aec45a7Smrg      esac
56526aec45a7Smrg    fi
5653ab47cfaaSmrg
56546aec45a7Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
56556aec45a7Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
56566aec45a7Smrg  done
5657ab47cfaaSmrg
56586aec45a7Smrg  # Usually 'no', except on cygwin/mingw when embedded into
56596aec45a7Smrg  # the cwrapper.
56606aec45a7Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
56616aec45a7Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
56626aec45a7Smrg    # special case for '.'
56636aec45a7Smrg    if test \"\$thisdir\" = \".\"; then
56646aec45a7Smrg      thisdir=\`pwd\`
56656aec45a7Smrg    fi
56666aec45a7Smrg    # remove .libs from thisdir
56676aec45a7Smrg    case \"\$thisdir\" in
56686aec45a7Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
56696aec45a7Smrg    $objdir )   thisdir=. ;;
56706aec45a7Smrg    esac
56716aec45a7Smrg  fi
5672ab47cfaaSmrg
56736aec45a7Smrg  # Try to get the absolute directory name.
56746aec45a7Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
56756aec45a7Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
56766aec45a7Smrg"
5677ab47cfaaSmrg
5678300bf1aeSmrg	if test yes = "$fast_install"; then
56796aec45a7Smrg	  $ECHO "\
56806aec45a7Smrg  program=lt-'$outputname'$exeext
56816aec45a7Smrg  progdir=\"\$thisdir/$objdir\"
5682ab47cfaaSmrg
56836aec45a7Smrg  if test ! -f \"\$progdir/\$program\" ||
5684300bf1aeSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
56856aec45a7Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686ab47cfaaSmrg
56876aec45a7Smrg    file=\"\$\$-\$program\"
5688ab47cfaaSmrg
56896aec45a7Smrg    if test ! -d \"\$progdir\"; then
56906aec45a7Smrg      $MKDIR \"\$progdir\"
56916aec45a7Smrg    else
56926aec45a7Smrg      $RM \"\$progdir/\$file\"
56936aec45a7Smrg    fi"
5694ab47cfaaSmrg
56956aec45a7Smrg	  $ECHO "\
5696ab47cfaaSmrg
56976aec45a7Smrg    # relink executable if necessary
56986aec45a7Smrg    if test -n \"\$relink_command\"; then
56996aec45a7Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
57006aec45a7Smrg      else
5701300bf1aeSmrg	\$ECHO \"\$relink_command_output\" >&2
57026aec45a7Smrg	$RM \"\$progdir/\$file\"
57036aec45a7Smrg	exit 1
57046aec45a7Smrg      fi
57056aec45a7Smrg    fi
5706ab47cfaaSmrg
57076aec45a7Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
57086aec45a7Smrg    { $RM \"\$progdir/\$program\";
57096aec45a7Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
57106aec45a7Smrg    $RM \"\$progdir/\$file\"
57116aec45a7Smrg  fi"
57126aec45a7Smrg	else
57136aec45a7Smrg	  $ECHO "\
57146aec45a7Smrg  program='$outputname'
57156aec45a7Smrg  progdir=\"\$thisdir/$objdir\"
57166aec45a7Smrg"
57176aec45a7Smrg	fi
5718ab47cfaaSmrg
57196aec45a7Smrg	$ECHO "\
5720ab47cfaaSmrg
57216aec45a7Smrg  if test -f \"\$progdir/\$program\"; then"
5722ab47cfaaSmrg
5723aa9e3350Smrg	# fixup the dll searchpath if we need to.
5724aa9e3350Smrg	#
5725aa9e3350Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726aa9e3350Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727aa9e3350Smrg	# libraries must come first.
5728aa9e3350Smrg	if test -n "$dllsearchpath"; then
5729aa9e3350Smrg	  $ECHO "\
5730aa9e3350Smrg    # Add the dll search path components to the executable PATH
5731aa9e3350Smrg    PATH=$dllsearchpath:\$PATH
5732aa9e3350Smrg"
5733aa9e3350Smrg	fi
5734aa9e3350Smrg
57356aec45a7Smrg	# Export our shlibpath_var if we have one.
5736300bf1aeSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57376aec45a7Smrg	  $ECHO "\
57386aec45a7Smrg    # Add our own library path to $shlibpath_var
57396aec45a7Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740ab47cfaaSmrg
57416aec45a7Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
57426aec45a7Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
57436aec45a7Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744ab47cfaaSmrg
57456aec45a7Smrg    export $shlibpath_var
57466aec45a7Smrg"
57476aec45a7Smrg	fi
57481473d951Smrg
57496aec45a7Smrg	$ECHO "\
57506aec45a7Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
57516aec45a7Smrg      # Run the actual program with our arguments.
57526aec45a7Smrg      func_exec_program \${1+\"\$@\"}
57536aec45a7Smrg    fi
57546aec45a7Smrg  else
57556aec45a7Smrg    # The program doesn't exist.
5756300bf1aeSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
57576aec45a7Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
57586aec45a7Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
57596aec45a7Smrg    exit 1
57606aec45a7Smrg  fi
57616aec45a7Smrgfi\
57626aec45a7Smrg"
57636aec45a7Smrg}
57641473d951Smrg
57651473d951Smrg
57666aec45a7Smrg# func_emit_cwrapperexe_src
57676aec45a7Smrg# emit the source code for a wrapper executable on stdout
57686aec45a7Smrg# Must ONLY be called from within func_mode_link because
57696aec45a7Smrg# it depends on a number of variable set therein.
57706aec45a7Smrgfunc_emit_cwrapperexe_src ()
57716aec45a7Smrg{
57726aec45a7Smrg	cat <<EOF
5773ab47cfaaSmrg
57746aec45a7Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775300bf1aeSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776ab47cfaaSmrg
57776aec45a7Smrg   The $output program cannot be directly executed until all the libtool
57786aec45a7Smrg   libraries that it depends on are installed.
5779ab47cfaaSmrg
57806aec45a7Smrg   This wrapper executable should never be moved out of the build directory.
57816aec45a7Smrg   If it is, it will not operate correctly.
57826aec45a7Smrg*/
57836aec45a7SmrgEOF
57846aec45a7Smrg	    cat <<"EOF"
57856aec45a7Smrg#ifdef _MSC_VER
57866aec45a7Smrg# define _CRT_SECURE_NO_DEPRECATE 1
57876aec45a7Smrg#endif
57886aec45a7Smrg#include <stdio.h>
57896aec45a7Smrg#include <stdlib.h>
57906aec45a7Smrg#ifdef _MSC_VER
57916aec45a7Smrg# include <direct.h>
57926aec45a7Smrg# include <process.h>
57936aec45a7Smrg# include <io.h>
57946aec45a7Smrg#else
57956aec45a7Smrg# include <unistd.h>
57966aec45a7Smrg# include <stdint.h>
57976aec45a7Smrg# ifdef __CYGWIN__
57986aec45a7Smrg#  include <io.h>
57996aec45a7Smrg# endif
58006aec45a7Smrg#endif
58016aec45a7Smrg#include <malloc.h>
58026aec45a7Smrg#include <stdarg.h>
58036aec45a7Smrg#include <assert.h>
58046aec45a7Smrg#include <string.h>
58056aec45a7Smrg#include <ctype.h>
58066aec45a7Smrg#include <errno.h>
58076aec45a7Smrg#include <fcntl.h>
58086aec45a7Smrg#include <sys/stat.h>
5809ab47cfaaSmrg
5810300bf1aeSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811300bf1aeSmrg
58126aec45a7Smrg/* declarations of non-ANSI functions */
5813300bf1aeSmrg#if defined __MINGW32__
58146aec45a7Smrg# ifdef __STRICT_ANSI__
58156aec45a7Smrgint _putenv (const char *);
58166aec45a7Smrg# endif
5817300bf1aeSmrg#elif defined __CYGWIN__
58186aec45a7Smrg# ifdef __STRICT_ANSI__
58196aec45a7Smrgchar *realpath (const char *, char *);
58206aec45a7Smrgint putenv (char *);
58216aec45a7Smrgint setenv (const char *, const char *, int);
58226aec45a7Smrg# endif
5823300bf1aeSmrg/* #elif defined other_platform || defined ... */
58246aec45a7Smrg#endif
5825ab47cfaaSmrg
58266aec45a7Smrg/* portability defines, excluding path handling macros */
5827300bf1aeSmrg#if defined _MSC_VER
58286aec45a7Smrg# define setmode _setmode
58296aec45a7Smrg# define stat    _stat
58306aec45a7Smrg# define chmod   _chmod
58316aec45a7Smrg# define getcwd  _getcwd
58326aec45a7Smrg# define putenv  _putenv
58336aec45a7Smrg# define S_IXUSR _S_IEXEC
5834300bf1aeSmrg#elif defined __MINGW32__
58356aec45a7Smrg# define setmode _setmode
58366aec45a7Smrg# define stat    _stat
58376aec45a7Smrg# define chmod   _chmod
58386aec45a7Smrg# define getcwd  _getcwd
58396aec45a7Smrg# define putenv  _putenv
5840300bf1aeSmrg#elif defined __CYGWIN__
58416aec45a7Smrg# define HAVE_SETENV
58426aec45a7Smrg# define FOPEN_WB "wb"
5843300bf1aeSmrg/* #elif defined other platforms ... */
58446aec45a7Smrg#endif
5845ab47cfaaSmrg
5846300bf1aeSmrg#if defined PATH_MAX
58476aec45a7Smrg# define LT_PATHMAX PATH_MAX
5848300bf1aeSmrg#elif defined MAXPATHLEN
58496aec45a7Smrg# define LT_PATHMAX MAXPATHLEN
58506aec45a7Smrg#else
58516aec45a7Smrg# define LT_PATHMAX 1024
58526aec45a7Smrg#endif
5853ab47cfaaSmrg
58546aec45a7Smrg#ifndef S_IXOTH
58556aec45a7Smrg# define S_IXOTH 0
58566aec45a7Smrg#endif
58576aec45a7Smrg#ifndef S_IXGRP
58586aec45a7Smrg# define S_IXGRP 0
58596aec45a7Smrg#endif
5860ab47cfaaSmrg
58616aec45a7Smrg/* path handling portability macros */
58626aec45a7Smrg#ifndef DIR_SEPARATOR
58636aec45a7Smrg# define DIR_SEPARATOR '/'
58646aec45a7Smrg# define PATH_SEPARATOR ':'
58656aec45a7Smrg#endif
5866ab47cfaaSmrg
5867300bf1aeSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868300bf1aeSmrg  defined __OS2__
58696aec45a7Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
58706aec45a7Smrg# define FOPEN_WB "wb"
58716aec45a7Smrg# ifndef DIR_SEPARATOR_2
58726aec45a7Smrg#  define DIR_SEPARATOR_2 '\\'
58736aec45a7Smrg# endif
58746aec45a7Smrg# ifndef PATH_SEPARATOR_2
58756aec45a7Smrg#  define PATH_SEPARATOR_2 ';'
58766aec45a7Smrg# endif
58776aec45a7Smrg#endif
5878ab47cfaaSmrg
58796aec45a7Smrg#ifndef DIR_SEPARATOR_2
58806aec45a7Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
58816aec45a7Smrg#else /* DIR_SEPARATOR_2 */
58826aec45a7Smrg# define IS_DIR_SEPARATOR(ch) \
58836aec45a7Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
58846aec45a7Smrg#endif /* DIR_SEPARATOR_2 */
5885ab47cfaaSmrg
58866aec45a7Smrg#ifndef PATH_SEPARATOR_2
58876aec45a7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
58886aec45a7Smrg#else /* PATH_SEPARATOR_2 */
58896aec45a7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
58906aec45a7Smrg#endif /* PATH_SEPARATOR_2 */
58916aec45a7Smrg
58926aec45a7Smrg#ifndef FOPEN_WB
58936aec45a7Smrg# define FOPEN_WB "w"
58946aec45a7Smrg#endif
58956aec45a7Smrg#ifndef _O_BINARY
58966aec45a7Smrg# define _O_BINARY 0
58976aec45a7Smrg#endif
58986aec45a7Smrg
58996aec45a7Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
59006aec45a7Smrg#define XFREE(stale) do { \
5901300bf1aeSmrg  if (stale) { free (stale); stale = 0; } \
59026aec45a7Smrg} while (0)
59036aec45a7Smrg
5904300bf1aeSmrg#if defined LT_DEBUGWRAPPER
59056aec45a7Smrgstatic int lt_debug = 1;
59066aec45a7Smrg#else
59076aec45a7Smrgstatic int lt_debug = 0;
59086aec45a7Smrg#endif
59096aec45a7Smrg
59106aec45a7Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59116aec45a7Smrg
59126aec45a7Smrgvoid *xmalloc (size_t num);
59136aec45a7Smrgchar *xstrdup (const char *string);
59146aec45a7Smrgconst char *base_name (const char *name);
59156aec45a7Smrgchar *find_executable (const char *wrapper);
59166aec45a7Smrgchar *chase_symlinks (const char *pathspec);
59176aec45a7Smrgint make_executable (const char *path);
59186aec45a7Smrgint check_executable (const char *path);
59196aec45a7Smrgchar *strendzap (char *str, const char *pat);
59206aec45a7Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
59216aec45a7Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
59226aec45a7Smrgstatic const char *nonnull (const char *s);
59236aec45a7Smrgstatic const char *nonempty (const char *s);
59246aec45a7Smrgvoid lt_setenv (const char *name, const char *value);
59256aec45a7Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
59266aec45a7Smrgvoid lt_update_exe_path (const char *name, const char *value);
59276aec45a7Smrgvoid lt_update_lib_path (const char *name, const char *value);
59286aec45a7Smrgchar **prepare_spawn (char **argv);
59296aec45a7Smrgvoid lt_dump_script (FILE *f);
59306aec45a7SmrgEOF
59316aec45a7Smrg
59326aec45a7Smrg	    cat <<EOF
5933300bf1aeSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934300bf1aeSmrg# define externally_visible volatile
5935300bf1aeSmrg#else
5936300bf1aeSmrg# define externally_visible __attribute__((externally_visible)) volatile
5937300bf1aeSmrg#endif
5938300bf1aeSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
59396aec45a7Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
59406aec45a7SmrgEOF
59416aec45a7Smrg
5942300bf1aeSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943aa9e3350Smrg              func_to_host_path "$temp_rpath"
59446aec45a7Smrg	      cat <<EOF
5945aa9e3350Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
59465c42550eSmrgEOF
59475c42550eSmrg	    else
59486aec45a7Smrg	      cat <<"EOF"
59496aec45a7Smrgconst char * LIB_PATH_VALUE   = "";
59506aec45a7SmrgEOF
59515c42550eSmrg	    fi
59526aec45a7Smrg
59536aec45a7Smrg	    if test -n "$dllsearchpath"; then
5954aa9e3350Smrg              func_to_host_path "$dllsearchpath:"
59556aec45a7Smrg	      cat <<EOF
59566aec45a7Smrgconst char * EXE_PATH_VARNAME = "PATH";
5957aa9e3350Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
59586aec45a7SmrgEOF
59595c42550eSmrg	    else
59606aec45a7Smrg	      cat <<"EOF"
59616aec45a7Smrgconst char * EXE_PATH_VARNAME = "";
59626aec45a7Smrgconst char * EXE_PATH_VALUE   = "";
59636aec45a7SmrgEOF
59645c42550eSmrg	    fi
59656aec45a7Smrg
5966300bf1aeSmrg	    if test yes = "$fast_install"; then
59676aec45a7Smrg	      cat <<EOF
59686aec45a7Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
59696aec45a7SmrgEOF
59705c42550eSmrg	    else
59716aec45a7Smrg	      cat <<EOF
59726aec45a7Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
59736aec45a7SmrgEOF
59745c42550eSmrg	    fi
5975ab47cfaaSmrg
5976ab47cfaaSmrg
59776aec45a7Smrg	    cat <<"EOF"
5978ab47cfaaSmrg
59796aec45a7Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980ab47cfaaSmrg
59816aec45a7Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
59826aec45a7Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
59836aec45a7Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984ab47cfaaSmrg
59856aec45a7Smrgint
59866aec45a7Smrgmain (int argc, char *argv[])
59876aec45a7Smrg{
59886aec45a7Smrg  char **newargz;
59896aec45a7Smrg  int  newargc;
59906aec45a7Smrg  char *tmp_pathspec;
59916aec45a7Smrg  char *actual_cwrapper_path;
59926aec45a7Smrg  char *actual_cwrapper_name;
59936aec45a7Smrg  char *target_name;
59946aec45a7Smrg  char *lt_argv_zero;
5995300bf1aeSmrg  int rval = 127;
5996ab47cfaaSmrg
59976aec45a7Smrg  int i;
5998ab47cfaaSmrg
59996aec45a7Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000300bf1aeSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001ab47cfaaSmrg
60026aec45a7Smrg  /* very simple arg parsing; don't want to rely on getopt
60036aec45a7Smrg   * also, copy all non cwrapper options to newargz, except
60046aec45a7Smrg   * argz[0], which is handled differently
60056aec45a7Smrg   */
60066aec45a7Smrg  newargc=0;
60076aec45a7Smrg  for (i = 1; i < argc; i++)
60086aec45a7Smrg    {
6009300bf1aeSmrg      if (STREQ (argv[i], dumpscript_opt))
60106aec45a7Smrg	{
60116aec45a7SmrgEOF
6012300bf1aeSmrg	    case $host in
60136aec45a7Smrg	      *mingw* | *cygwin* )
60146aec45a7Smrg		# make stdout use "unix" line endings
60156aec45a7Smrg		echo "          setmode(1,_O_BINARY);"
60166aec45a7Smrg		;;
60175c42550eSmrg	      esac
6018ab47cfaaSmrg
60196aec45a7Smrg	    cat <<"EOF"
60206aec45a7Smrg	  lt_dump_script (stdout);
60216aec45a7Smrg	  return 0;
60226aec45a7Smrg	}
6023300bf1aeSmrg      if (STREQ (argv[i], debug_opt))
60246aec45a7Smrg	{
60256aec45a7Smrg          lt_debug = 1;
60266aec45a7Smrg          continue;
60276aec45a7Smrg	}
6028300bf1aeSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
60296aec45a7Smrg        {
60306aec45a7Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
60316aec45a7Smrg             namespace, but it is not one of the ones we know about and
60326aec45a7Smrg             have already dealt with, above (inluding dump-script), then
60336aec45a7Smrg             report an error. Otherwise, targets might begin to believe
60346aec45a7Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
60356aec45a7Smrg             namespace. The first time any user complains about this, we'll
60366aec45a7Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
60376aec45a7Smrg             or a configure.ac-settable value.
60386aec45a7Smrg           */
60396aec45a7Smrg          lt_fatal (__FILE__, __LINE__,
60406aec45a7Smrg		    "unrecognized %s option: '%s'",
60416aec45a7Smrg                    ltwrapper_option_prefix, argv[i]);
60426aec45a7Smrg        }
60436aec45a7Smrg      /* otherwise ... */
60446aec45a7Smrg      newargz[++newargc] = xstrdup (argv[i]);
60456aec45a7Smrg    }
60466aec45a7Smrg  newargz[++newargc] = NULL;
6047ab47cfaaSmrg
60486aec45a7SmrgEOF
60496aec45a7Smrg	    cat <<EOF
60506aec45a7Smrg  /* The GNU banner must be the first non-error debug message */
6051300bf1aeSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
60526aec45a7SmrgEOF
60536aec45a7Smrg	    cat <<"EOF"
60546aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
60556aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
60566aec45a7Smrg
60576aec45a7Smrg  tmp_pathspec = find_executable (argv[0]);
60586aec45a7Smrg  if (tmp_pathspec == NULL)
60596aec45a7Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
60606aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
60616aec45a7Smrg                  "(main) found exe (before symlink chase) at: %s\n",
60626aec45a7Smrg		  tmp_pathspec);
60636aec45a7Smrg
60646aec45a7Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
60656aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
60666aec45a7Smrg                  "(main) found exe (after symlink chase) at: %s\n",
60676aec45a7Smrg		  actual_cwrapper_path);
60686aec45a7Smrg  XFREE (tmp_pathspec);
60696aec45a7Smrg
60706aec45a7Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
60716aec45a7Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
60726aec45a7Smrg
60736aec45a7Smrg  /* wrapper name transforms */
60746aec45a7Smrg  strendzap (actual_cwrapper_name, ".exe");
60756aec45a7Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
60766aec45a7Smrg  XFREE (actual_cwrapper_name);
60776aec45a7Smrg  actual_cwrapper_name = tmp_pathspec;
60786aec45a7Smrg  tmp_pathspec = 0;
60796aec45a7Smrg
60806aec45a7Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
60816aec45a7Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
60826aec45a7Smrg  strendzap (target_name, ".exe");
60836aec45a7Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
60846aec45a7Smrg  XFREE (target_name);
60856aec45a7Smrg  target_name = tmp_pathspec;
60866aec45a7Smrg  tmp_pathspec = 0;
60876aec45a7Smrg
60886aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
60896aec45a7Smrg		  "(main) libtool target name: %s\n",
60906aec45a7Smrg		  target_name);
60916aec45a7SmrgEOF
6092ab47cfaaSmrg
60936aec45a7Smrg	    cat <<EOF
60946aec45a7Smrg  newargz[0] =
60956aec45a7Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
60966aec45a7Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
60976aec45a7Smrg  strcpy (newargz[0], actual_cwrapper_path);
60986aec45a7Smrg  strcat (newargz[0], "$objdir");
60996aec45a7Smrg  strcat (newargz[0], "/");
61006aec45a7SmrgEOF
6101ab47cfaaSmrg
61026aec45a7Smrg	    cat <<"EOF"
61036aec45a7Smrg  /* stop here, and copy so we don't have to do this twice */
61046aec45a7Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105ab47cfaaSmrg
61066aec45a7Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
61076aec45a7Smrg  strcat (newargz[0], actual_cwrapper_name);
6108ab47cfaaSmrg
61096aec45a7Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
61106aec45a7Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
61116aec45a7Smrg  XFREE (tmp_pathspec);
61126aec45a7Smrg  tmp_pathspec = NULL;
61136aec45a7SmrgEOF
6114ab47cfaaSmrg
61156aec45a7Smrg	    case $host_os in
61166aec45a7Smrg	      mingw*)
61176aec45a7Smrg	    cat <<"EOF"
61186aec45a7Smrg  {
61196aec45a7Smrg    char* p;
61206aec45a7Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
61216aec45a7Smrg      {
61226aec45a7Smrg	*p = '/';
61236aec45a7Smrg      }
61246aec45a7Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
61256aec45a7Smrg      {
61266aec45a7Smrg	*p = '/';
61276aec45a7Smrg      }
61286aec45a7Smrg  }
61296aec45a7SmrgEOF
61306aec45a7Smrg	    ;;
61316aec45a7Smrg	    esac
6132ab47cfaaSmrg
61336aec45a7Smrg	    cat <<"EOF"
61346aec45a7Smrg  XFREE (target_name);
61356aec45a7Smrg  XFREE (actual_cwrapper_path);
61366aec45a7Smrg  XFREE (actual_cwrapper_name);
6137ab47cfaaSmrg
61386aec45a7Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
61396aec45a7Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140aa9e3350Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141aa9e3350Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142aa9e3350Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143aa9e3350Smrg     libraries must come first. */
61446aec45a7Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145aa9e3350Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146ab47cfaaSmrg
61476aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
61486aec45a7Smrg		  nonnull (lt_argv_zero));
61496aec45a7Smrg  for (i = 0; i < newargc; i++)
61506aec45a7Smrg    {
61516aec45a7Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
61526aec45a7Smrg		      i, nonnull (newargz[i]));
61536aec45a7Smrg    }
6154ab47cfaaSmrg
61556aec45a7SmrgEOF
6156ab47cfaaSmrg
61576aec45a7Smrg	    case $host_os in
61586aec45a7Smrg	      mingw*)
61596aec45a7Smrg		cat <<"EOF"
61606aec45a7Smrg  /* execv doesn't actually work on mingw as expected on unix */
61616aec45a7Smrg  newargz = prepare_spawn (newargz);
6162300bf1aeSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
61636aec45a7Smrg  if (rval == -1)
61646aec45a7Smrg    {
61656aec45a7Smrg      /* failed to start process */
61666aec45a7Smrg      lt_debugprintf (__FILE__, __LINE__,
61676aec45a7Smrg		      "(main) failed to launch target \"%s\": %s\n",
61686aec45a7Smrg		      lt_argv_zero, nonnull (strerror (errno)));
61696aec45a7Smrg      return 127;
61706aec45a7Smrg    }
61716aec45a7Smrg  return rval;
61726aec45a7SmrgEOF
61736aec45a7Smrg		;;
61746aec45a7Smrg	      *)
61756aec45a7Smrg		cat <<"EOF"
61766aec45a7Smrg  execv (lt_argv_zero, newargz);
61776aec45a7Smrg  return rval; /* =127, but avoids unused variable warning */
61786aec45a7SmrgEOF
61796aec45a7Smrg		;;
61806aec45a7Smrg	    esac
6181ab47cfaaSmrg
61826aec45a7Smrg	    cat <<"EOF"
61836aec45a7Smrg}
6184ab47cfaaSmrg
61856aec45a7Smrgvoid *
61866aec45a7Smrgxmalloc (size_t num)
61876aec45a7Smrg{
61886aec45a7Smrg  void *p = (void *) malloc (num);
61896aec45a7Smrg  if (!p)
61906aec45a7Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191ab47cfaaSmrg
61926aec45a7Smrg  return p;
61936aec45a7Smrg}
6194ab47cfaaSmrg
61956aec45a7Smrgchar *
61966aec45a7Smrgxstrdup (const char *string)
61976aec45a7Smrg{
61986aec45a7Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
61996aec45a7Smrg			  string) : NULL;
62006aec45a7Smrg}
6201ab47cfaaSmrg
62026aec45a7Smrgconst char *
62036aec45a7Smrgbase_name (const char *name)
62046aec45a7Smrg{
62056aec45a7Smrg  const char *base;
6206ab47cfaaSmrg
6207300bf1aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62086aec45a7Smrg  /* Skip over the disk name in MSDOS pathnames. */
62096aec45a7Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
62106aec45a7Smrg    name += 2;
62116aec45a7Smrg#endif
6212ab47cfaaSmrg
62136aec45a7Smrg  for (base = name; *name; name++)
62146aec45a7Smrg    if (IS_DIR_SEPARATOR (*name))
62156aec45a7Smrg      base = name + 1;
62166aec45a7Smrg  return base;
62176aec45a7Smrg}
6218ab47cfaaSmrg
62196aec45a7Smrgint
62206aec45a7Smrgcheck_executable (const char *path)
62216aec45a7Smrg{
62226aec45a7Smrg  struct stat st;
6223ab47cfaaSmrg
62246aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
62256aec45a7Smrg                  nonempty (path));
62266aec45a7Smrg  if ((!path) || (!*path))
62276aec45a7Smrg    return 0;
6228ab47cfaaSmrg
62296aec45a7Smrg  if ((stat (path, &st) >= 0)
62306aec45a7Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
62316aec45a7Smrg    return 1;
62326aec45a7Smrg  else
62336aec45a7Smrg    return 0;
62346aec45a7Smrg}
6235ab47cfaaSmrg
62366aec45a7Smrgint
62376aec45a7Smrgmake_executable (const char *path)
62386aec45a7Smrg{
62396aec45a7Smrg  int rval = 0;
62406aec45a7Smrg  struct stat st;
62415c42550eSmrg
62426aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
62436aec45a7Smrg                  nonempty (path));
62446aec45a7Smrg  if ((!path) || (!*path))
62456aec45a7Smrg    return 0;
62465c42550eSmrg
62476aec45a7Smrg  if (stat (path, &st) >= 0)
62486aec45a7Smrg    {
62496aec45a7Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
62506aec45a7Smrg    }
62516aec45a7Smrg  return rval;
62526aec45a7Smrg}
62535c42550eSmrg
62546aec45a7Smrg/* Searches for the full path of the wrapper.  Returns
62556aec45a7Smrg   newly allocated full path name if found, NULL otherwise
62566aec45a7Smrg   Does not chase symlinks, even on platforms that support them.
62576aec45a7Smrg*/
62586aec45a7Smrgchar *
62596aec45a7Smrgfind_executable (const char *wrapper)
62606aec45a7Smrg{
62616aec45a7Smrg  int has_slash = 0;
62626aec45a7Smrg  const char *p;
62636aec45a7Smrg  const char *p_next;
62646aec45a7Smrg  /* static buffer for getcwd */
62656aec45a7Smrg  char tmp[LT_PATHMAX + 1];
6266300bf1aeSmrg  size_t tmp_len;
62676aec45a7Smrg  char *concat_name;
62685c42550eSmrg
62696aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
62706aec45a7Smrg                  nonempty (wrapper));
62715c42550eSmrg
62726aec45a7Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
62736aec45a7Smrg    return NULL;
6274ab47cfaaSmrg
62756aec45a7Smrg  /* Absolute path? */
6276300bf1aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62776aec45a7Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
62786aec45a7Smrg    {
62796aec45a7Smrg      concat_name = xstrdup (wrapper);
62806aec45a7Smrg      if (check_executable (concat_name))
62816aec45a7Smrg	return concat_name;
62826aec45a7Smrg      XFREE (concat_name);
62836aec45a7Smrg    }
62846aec45a7Smrg  else
62856aec45a7Smrg    {
62866aec45a7Smrg#endif
62876aec45a7Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
62886aec45a7Smrg	{
62896aec45a7Smrg	  concat_name = xstrdup (wrapper);
62906aec45a7Smrg	  if (check_executable (concat_name))
62916aec45a7Smrg	    return concat_name;
62926aec45a7Smrg	  XFREE (concat_name);
62936aec45a7Smrg	}
6294300bf1aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62956aec45a7Smrg    }
62966aec45a7Smrg#endif
6297ab47cfaaSmrg
62986aec45a7Smrg  for (p = wrapper; *p; p++)
62996aec45a7Smrg    if (*p == '/')
63006aec45a7Smrg      {
63016aec45a7Smrg	has_slash = 1;
63026aec45a7Smrg	break;
63036aec45a7Smrg      }
63046aec45a7Smrg  if (!has_slash)
63056aec45a7Smrg    {
63066aec45a7Smrg      /* no slashes; search PATH */
63076aec45a7Smrg      const char *path = getenv ("PATH");
63086aec45a7Smrg      if (path != NULL)
63096aec45a7Smrg	{
63106aec45a7Smrg	  for (p = path; *p; p = p_next)
63116aec45a7Smrg	    {
63126aec45a7Smrg	      const char *q;
63136aec45a7Smrg	      size_t p_len;
63146aec45a7Smrg	      for (q = p; *q; q++)
63156aec45a7Smrg		if (IS_PATH_SEPARATOR (*q))
63166aec45a7Smrg		  break;
6317300bf1aeSmrg	      p_len = (size_t) (q - p);
63186aec45a7Smrg	      p_next = (*q == '\0' ? q : q + 1);
63196aec45a7Smrg	      if (p_len == 0)
63206aec45a7Smrg		{
63216aec45a7Smrg		  /* empty path: current directory */
63226aec45a7Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
63236aec45a7Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63246aec45a7Smrg                              nonnull (strerror (errno)));
63256aec45a7Smrg		  tmp_len = strlen (tmp);
63266aec45a7Smrg		  concat_name =
63276aec45a7Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63286aec45a7Smrg		  memcpy (concat_name, tmp, tmp_len);
63296aec45a7Smrg		  concat_name[tmp_len] = '/';
63306aec45a7Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
63316aec45a7Smrg		}
63326aec45a7Smrg	      else
63336aec45a7Smrg		{
63346aec45a7Smrg		  concat_name =
63356aec45a7Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
63366aec45a7Smrg		  memcpy (concat_name, p, p_len);
63376aec45a7Smrg		  concat_name[p_len] = '/';
63386aec45a7Smrg		  strcpy (concat_name + p_len + 1, wrapper);
63396aec45a7Smrg		}
63406aec45a7Smrg	      if (check_executable (concat_name))
63416aec45a7Smrg		return concat_name;
63426aec45a7Smrg	      XFREE (concat_name);
63436aec45a7Smrg	    }
63446aec45a7Smrg	}
63456aec45a7Smrg      /* not found in PATH; assume curdir */
63466aec45a7Smrg    }
63476aec45a7Smrg  /* Relative path | not found in path: prepend cwd */
63486aec45a7Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
63496aec45a7Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63506aec45a7Smrg              nonnull (strerror (errno)));
63516aec45a7Smrg  tmp_len = strlen (tmp);
63526aec45a7Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63536aec45a7Smrg  memcpy (concat_name, tmp, tmp_len);
63546aec45a7Smrg  concat_name[tmp_len] = '/';
63556aec45a7Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356ab47cfaaSmrg
63576aec45a7Smrg  if (check_executable (concat_name))
63586aec45a7Smrg    return concat_name;
63596aec45a7Smrg  XFREE (concat_name);
63606aec45a7Smrg  return NULL;
63616aec45a7Smrg}
63625c42550eSmrg
63636aec45a7Smrgchar *
63646aec45a7Smrgchase_symlinks (const char *pathspec)
63656aec45a7Smrg{
63666aec45a7Smrg#ifndef S_ISLNK
63676aec45a7Smrg  return xstrdup (pathspec);
63686aec45a7Smrg#else
63696aec45a7Smrg  char buf[LT_PATHMAX];
63706aec45a7Smrg  struct stat s;
63716aec45a7Smrg  char *tmp_pathspec = xstrdup (pathspec);
63726aec45a7Smrg  char *p;
63736aec45a7Smrg  int has_symlinks = 0;
63746aec45a7Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
63756aec45a7Smrg    {
63766aec45a7Smrg      lt_debugprintf (__FILE__, __LINE__,
63776aec45a7Smrg		      "checking path component for symlinks: %s\n",
63786aec45a7Smrg		      tmp_pathspec);
63796aec45a7Smrg      if (lstat (tmp_pathspec, &s) == 0)
63806aec45a7Smrg	{
63816aec45a7Smrg	  if (S_ISLNK (s.st_mode) != 0)
63826aec45a7Smrg	    {
63836aec45a7Smrg	      has_symlinks = 1;
63846aec45a7Smrg	      break;
63856aec45a7Smrg	    }
63865c42550eSmrg
63876aec45a7Smrg	  /* search backwards for last DIR_SEPARATOR */
63886aec45a7Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
63896aec45a7Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63906aec45a7Smrg	    p--;
63916aec45a7Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63926aec45a7Smrg	    {
63936aec45a7Smrg	      /* no more DIR_SEPARATORS left */
63946aec45a7Smrg	      break;
63956aec45a7Smrg	    }
63966aec45a7Smrg	  *p = '\0';
63976aec45a7Smrg	}
63986aec45a7Smrg      else
63996aec45a7Smrg	{
64006aec45a7Smrg	  lt_fatal (__FILE__, __LINE__,
64016aec45a7Smrg		    "error accessing file \"%s\": %s",
64026aec45a7Smrg		    tmp_pathspec, nonnull (strerror (errno)));
64036aec45a7Smrg	}
64046aec45a7Smrg    }
64056aec45a7Smrg  XFREE (tmp_pathspec);
64065c42550eSmrg
64076aec45a7Smrg  if (!has_symlinks)
64086aec45a7Smrg    {
64096aec45a7Smrg      return xstrdup (pathspec);
64106aec45a7Smrg    }
64115c42550eSmrg
64126aec45a7Smrg  tmp_pathspec = realpath (pathspec, buf);
64136aec45a7Smrg  if (tmp_pathspec == 0)
64146aec45a7Smrg    {
64156aec45a7Smrg      lt_fatal (__FILE__, __LINE__,
64166aec45a7Smrg		"could not follow symlinks for %s", pathspec);
64176aec45a7Smrg    }
64186aec45a7Smrg  return xstrdup (tmp_pathspec);
64196aec45a7Smrg#endif
64206aec45a7Smrg}
6421ab47cfaaSmrg
64226aec45a7Smrgchar *
64236aec45a7Smrgstrendzap (char *str, const char *pat)
64246aec45a7Smrg{
64256aec45a7Smrg  size_t len, patlen;
6426ab47cfaaSmrg
64276aec45a7Smrg  assert (str != NULL);
64286aec45a7Smrg  assert (pat != NULL);
6429ab47cfaaSmrg
64306aec45a7Smrg  len = strlen (str);
64316aec45a7Smrg  patlen = strlen (pat);
6432ab47cfaaSmrg
64336aec45a7Smrg  if (patlen <= len)
64346aec45a7Smrg    {
64356aec45a7Smrg      str += len - patlen;
6436300bf1aeSmrg      if (STREQ (str, pat))
64376aec45a7Smrg	*str = '\0';
64386aec45a7Smrg    }
64396aec45a7Smrg  return str;
64406aec45a7Smrg}
6441ab47cfaaSmrg
64426aec45a7Smrgvoid
64436aec45a7Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
64446aec45a7Smrg{
64456aec45a7Smrg  va_list args;
64466aec45a7Smrg  if (lt_debug)
64476aec45a7Smrg    {
64486aec45a7Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
64496aec45a7Smrg      va_start (args, fmt);
64506aec45a7Smrg      (void) vfprintf (stderr, fmt, args);
64516aec45a7Smrg      va_end (args);
64526aec45a7Smrg    }
64536aec45a7Smrg}
6454ab47cfaaSmrg
64556aec45a7Smrgstatic void
64566aec45a7Smrglt_error_core (int exit_status, const char *file,
64576aec45a7Smrg	       int line, const char *mode,
64586aec45a7Smrg	       const char *message, va_list ap)
64596aec45a7Smrg{
64606aec45a7Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
64616aec45a7Smrg  vfprintf (stderr, message, ap);
64626aec45a7Smrg  fprintf (stderr, ".\n");
6463ab47cfaaSmrg
64646aec45a7Smrg  if (exit_status >= 0)
64656aec45a7Smrg    exit (exit_status);
64666aec45a7Smrg}
6467ab47cfaaSmrg
64686aec45a7Smrgvoid
64696aec45a7Smrglt_fatal (const char *file, int line, const char *message, ...)
64706aec45a7Smrg{
64716aec45a7Smrg  va_list ap;
64726aec45a7Smrg  va_start (ap, message);
64736aec45a7Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
64746aec45a7Smrg  va_end (ap);
64756aec45a7Smrg}
6476ab47cfaaSmrg
64776aec45a7Smrgstatic const char *
64786aec45a7Smrgnonnull (const char *s)
64796aec45a7Smrg{
64806aec45a7Smrg  return s ? s : "(null)";
64816aec45a7Smrg}
6482ab47cfaaSmrg
64836aec45a7Smrgstatic const char *
64846aec45a7Smrgnonempty (const char *s)
64856aec45a7Smrg{
64866aec45a7Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
64876aec45a7Smrg}
6488ab47cfaaSmrg
64896aec45a7Smrgvoid
64906aec45a7Smrglt_setenv (const char *name, const char *value)
64916aec45a7Smrg{
64926aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
64936aec45a7Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
64946aec45a7Smrg                  nonnull (name), nonnull (value));
64956aec45a7Smrg  {
64966aec45a7Smrg#ifdef HAVE_SETENV
64976aec45a7Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
64986aec45a7Smrg    char *str = xstrdup (value);
64996aec45a7Smrg    setenv (name, str, 1);
65006aec45a7Smrg#else
6501300bf1aeSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
65026aec45a7Smrg    char *str = XMALLOC (char, len);
65036aec45a7Smrg    sprintf (str, "%s=%s", name, value);
65046aec45a7Smrg    if (putenv (str) != EXIT_SUCCESS)
65056aec45a7Smrg      {
65066aec45a7Smrg        XFREE (str);
65076aec45a7Smrg      }
65086aec45a7Smrg#endif
65096aec45a7Smrg  }
65106aec45a7Smrg}
6511ab47cfaaSmrg
65126aec45a7Smrgchar *
65136aec45a7Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
65146aec45a7Smrg{
65156aec45a7Smrg  char *new_value;
65166aec45a7Smrg  if (orig_value && *orig_value)
65176aec45a7Smrg    {
6518300bf1aeSmrg      size_t orig_value_len = strlen (orig_value);
6519300bf1aeSmrg      size_t add_len = strlen (add);
65206aec45a7Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
65216aec45a7Smrg      if (to_end)
65226aec45a7Smrg        {
65236aec45a7Smrg          strcpy (new_value, orig_value);
65246aec45a7Smrg          strcpy (new_value + orig_value_len, add);
65256aec45a7Smrg        }
65266aec45a7Smrg      else
65276aec45a7Smrg        {
65286aec45a7Smrg          strcpy (new_value, add);
65296aec45a7Smrg          strcpy (new_value + add_len, orig_value);
65306aec45a7Smrg        }
65316aec45a7Smrg    }
65326aec45a7Smrg  else
65336aec45a7Smrg    {
65346aec45a7Smrg      new_value = xstrdup (add);
65356aec45a7Smrg    }
65366aec45a7Smrg  return new_value;
65376aec45a7Smrg}
6538ab47cfaaSmrg
65396aec45a7Smrgvoid
65406aec45a7Smrglt_update_exe_path (const char *name, const char *value)
65416aec45a7Smrg{
65426aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
65436aec45a7Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
65446aec45a7Smrg                  nonnull (name), nonnull (value));
6545ab47cfaaSmrg
65466aec45a7Smrg  if (name && *name && value && *value)
65476aec45a7Smrg    {
65486aec45a7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65496aec45a7Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550300bf1aeSmrg      size_t len = strlen (new_value);
6551300bf1aeSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
65526aec45a7Smrg        {
6553300bf1aeSmrg          new_value[--len] = '\0';
65546aec45a7Smrg        }
65556aec45a7Smrg      lt_setenv (name, new_value);
65566aec45a7Smrg      XFREE (new_value);
65576aec45a7Smrg    }
65586aec45a7Smrg}
6559ab47cfaaSmrg
65606aec45a7Smrgvoid
65616aec45a7Smrglt_update_lib_path (const char *name, const char *value)
65626aec45a7Smrg{
65636aec45a7Smrg  lt_debugprintf (__FILE__, __LINE__,
65646aec45a7Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
65656aec45a7Smrg                  nonnull (name), nonnull (value));
6566ab47cfaaSmrg
65676aec45a7Smrg  if (name && *name && value && *value)
65686aec45a7Smrg    {
65696aec45a7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65706aec45a7Smrg      lt_setenv (name, new_value);
65716aec45a7Smrg      XFREE (new_value);
65726aec45a7Smrg    }
65736aec45a7Smrg}
6574ab47cfaaSmrg
65756aec45a7SmrgEOF
65766aec45a7Smrg	    case $host_os in
65776aec45a7Smrg	      mingw*)
65786aec45a7Smrg		cat <<"EOF"
65796aec45a7Smrg
65806aec45a7Smrg/* Prepares an argument vector before calling spawn().
65816aec45a7Smrg   Note that spawn() does not by itself call the command interpreter
65826aec45a7Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
65836aec45a7Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
65846aec45a7Smrg         GetVersionEx(&v);
65856aec45a7Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
65866aec45a7Smrg      }) ? "cmd.exe" : "command.com").
65876aec45a7Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
65886aec45a7Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
65896aec45a7Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
65906aec45a7Smrg   special way:
65916aec45a7Smrg   - Space and tab are interpreted as delimiters. They are not treated as
65926aec45a7Smrg     delimiters if they are surrounded by double quotes: "...".
65936aec45a7Smrg   - Unescaped double quotes are removed from the input. Their only effect is
65946aec45a7Smrg     that within double quotes, space and tab are treated like normal
65956aec45a7Smrg     characters.
65966aec45a7Smrg   - Backslashes not followed by double quotes are not special.
65976aec45a7Smrg   - But 2*n+1 backslashes followed by a double quote become
65986aec45a7Smrg     n backslashes followed by a double quote (n >= 0):
65996aec45a7Smrg       \" -> "
66006aec45a7Smrg       \\\" -> \"
66016aec45a7Smrg       \\\\\" -> \\"
66026aec45a7Smrg */
66036aec45a7Smrg#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"
66046aec45a7Smrg#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"
66056aec45a7Smrgchar **
66066aec45a7Smrgprepare_spawn (char **argv)
66076aec45a7Smrg{
66086aec45a7Smrg  size_t argc;
66096aec45a7Smrg  char **new_argv;
66106aec45a7Smrg  size_t i;
6611ab47cfaaSmrg
66126aec45a7Smrg  /* Count number of arguments.  */
66136aec45a7Smrg  for (argc = 0; argv[argc] != NULL; argc++)
66146aec45a7Smrg    ;
6615ab47cfaaSmrg
66166aec45a7Smrg  /* Allocate new argument vector.  */
66176aec45a7Smrg  new_argv = XMALLOC (char *, argc + 1);
6618ab47cfaaSmrg
66196aec45a7Smrg  /* Put quoted arguments into the new argument vector.  */
66206aec45a7Smrg  for (i = 0; i < argc; i++)
66216aec45a7Smrg    {
66226aec45a7Smrg      const char *string = argv[i];
66236aec45a7Smrg
66246aec45a7Smrg      if (string[0] == '\0')
66256aec45a7Smrg	new_argv[i] = xstrdup ("\"\"");
66266aec45a7Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
66276aec45a7Smrg	{
66286aec45a7Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
66296aec45a7Smrg	  size_t length;
66306aec45a7Smrg	  unsigned int backslashes;
66316aec45a7Smrg	  const char *s;
66326aec45a7Smrg	  char *quoted_string;
66336aec45a7Smrg	  char *p;
66346aec45a7Smrg
66356aec45a7Smrg	  length = 0;
66366aec45a7Smrg	  backslashes = 0;
66376aec45a7Smrg	  if (quote_around)
66386aec45a7Smrg	    length++;
66396aec45a7Smrg	  for (s = string; *s != '\0'; s++)
66406aec45a7Smrg	    {
66416aec45a7Smrg	      char c = *s;
66426aec45a7Smrg	      if (c == '"')
66436aec45a7Smrg		length += backslashes + 1;
66446aec45a7Smrg	      length++;
66456aec45a7Smrg	      if (c == '\\')
66466aec45a7Smrg		backslashes++;
66476aec45a7Smrg	      else
66486aec45a7Smrg		backslashes = 0;
66496aec45a7Smrg	    }
66506aec45a7Smrg	  if (quote_around)
66516aec45a7Smrg	    length += backslashes + 1;
66526aec45a7Smrg
66536aec45a7Smrg	  quoted_string = XMALLOC (char, length + 1);
66546aec45a7Smrg
66556aec45a7Smrg	  p = quoted_string;
66566aec45a7Smrg	  backslashes = 0;
66576aec45a7Smrg	  if (quote_around)
66586aec45a7Smrg	    *p++ = '"';
66596aec45a7Smrg	  for (s = string; *s != '\0'; s++)
66606aec45a7Smrg	    {
66616aec45a7Smrg	      char c = *s;
66626aec45a7Smrg	      if (c == '"')
66636aec45a7Smrg		{
66646aec45a7Smrg		  unsigned int j;
66656aec45a7Smrg		  for (j = backslashes + 1; j > 0; j--)
66666aec45a7Smrg		    *p++ = '\\';
66676aec45a7Smrg		}
66686aec45a7Smrg	      *p++ = c;
66696aec45a7Smrg	      if (c == '\\')
66706aec45a7Smrg		backslashes++;
66716aec45a7Smrg	      else
66726aec45a7Smrg		backslashes = 0;
66736aec45a7Smrg	    }
66746aec45a7Smrg	  if (quote_around)
66756aec45a7Smrg	    {
66766aec45a7Smrg	      unsigned int j;
66776aec45a7Smrg	      for (j = backslashes; j > 0; j--)
66786aec45a7Smrg		*p++ = '\\';
66796aec45a7Smrg	      *p++ = '"';
66806aec45a7Smrg	    }
66816aec45a7Smrg	  *p = '\0';
6682ab47cfaaSmrg
66836aec45a7Smrg	  new_argv[i] = quoted_string;
66846aec45a7Smrg	}
66856aec45a7Smrg      else
66866aec45a7Smrg	new_argv[i] = (char *) string;
66876aec45a7Smrg    }
66886aec45a7Smrg  new_argv[argc] = NULL;
6689ab47cfaaSmrg
66906aec45a7Smrg  return new_argv;
66916aec45a7Smrg}
66926aec45a7SmrgEOF
66935c42550eSmrg		;;
66946aec45a7Smrg	    esac
6695ab47cfaaSmrg
66966aec45a7Smrg            cat <<"EOF"
66976aec45a7Smrgvoid lt_dump_script (FILE* f)
66986aec45a7Smrg{
66996aec45a7SmrgEOF
67006aec45a7Smrg	    func_emit_wrapper yes |
6701aa9e3350Smrg	      $SED -n -e '
6702aa9e3350Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703aa9e3350Smrg\2/
6704aa9e3350Smrgh
6705aa9e3350Smrgs/\([\\"]\)/\\\1/g
6706aa9e3350Smrgs/$/\\n/
6707aa9e3350Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708aa9e3350Smrgg
6709aa9e3350SmrgD'
67106aec45a7Smrg            cat <<"EOF"
67116aec45a7Smrg}
67126aec45a7SmrgEOF
67136aec45a7Smrg}
67146aec45a7Smrg# end: func_emit_cwrapperexe_src
6715ab47cfaaSmrg
67166aec45a7Smrg# func_win32_import_lib_p ARG
67176aec45a7Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
67186aec45a7Smrgfunc_win32_import_lib_p ()
67196aec45a7Smrg{
6720300bf1aeSmrg    $debug_cmd
6721300bf1aeSmrg
67226aec45a7Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
67236aec45a7Smrg    *import*) : ;;
67246aec45a7Smrg    *) false ;;
67256aec45a7Smrg    esac
67266aec45a7Smrg}
6727ab47cfaaSmrg
6728300bf1aeSmrg# func_suncc_cstd_abi
6729300bf1aeSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730300bf1aeSmrg# Several compiler flags select an ABI that is incompatible with the
6731300bf1aeSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732300bf1aeSmrgfunc_suncc_cstd_abi ()
6733300bf1aeSmrg{
6734300bf1aeSmrg    $debug_cmd
6735300bf1aeSmrg
6736300bf1aeSmrg    case " $compile_command " in
6737300bf1aeSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738300bf1aeSmrg      suncc_use_cstd_abi=no
6739300bf1aeSmrg      ;;
6740300bf1aeSmrg    *)
6741300bf1aeSmrg      suncc_use_cstd_abi=yes
6742300bf1aeSmrg      ;;
6743300bf1aeSmrg    esac
6744300bf1aeSmrg}
6745300bf1aeSmrg
67466aec45a7Smrg# func_mode_link arg...
67476aec45a7Smrgfunc_mode_link ()
67486aec45a7Smrg{
6749300bf1aeSmrg    $debug_cmd
6750300bf1aeSmrg
67516aec45a7Smrg    case $host in
67526aec45a7Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
67536aec45a7Smrg      # It is impossible to link a dll without this setting, and
67546aec45a7Smrg      # we shouldn't force the makefile maintainer to figure out
6755300bf1aeSmrg      # what system we are compiling for in order to pass an extra
67566aec45a7Smrg      # flag for every libtool invocation.
67576aec45a7Smrg      # allow_undefined=no
6758ab47cfaaSmrg
67596aec45a7Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760300bf1aeSmrg      # to make a dll that has undefined symbols, in which case not
67616aec45a7Smrg      # even a static library is built.  For now, we need to specify
67626aec45a7Smrg      # -no-undefined on the libtool link line when we can be certain
67636aec45a7Smrg      # that all symbols are satisfied, otherwise we get a static library.
67646aec45a7Smrg      allow_undefined=yes
67656aec45a7Smrg      ;;
67666aec45a7Smrg    *)
67676aec45a7Smrg      allow_undefined=yes
67686aec45a7Smrg      ;;
67696aec45a7Smrg    esac
67706aec45a7Smrg    libtool_args=$nonopt
67716aec45a7Smrg    base_compile="$nonopt $@"
67726aec45a7Smrg    compile_command=$nonopt
67736aec45a7Smrg    finalize_command=$nonopt
6774ab47cfaaSmrg
67756aec45a7Smrg    compile_rpath=
67766aec45a7Smrg    finalize_rpath=
67776aec45a7Smrg    compile_shlibpath=
67786aec45a7Smrg    finalize_shlibpath=
67796aec45a7Smrg    convenience=
67806aec45a7Smrg    old_convenience=
67816aec45a7Smrg    deplibs=
67826aec45a7Smrg    old_deplibs=
67836aec45a7Smrg    compiler_flags=
67846aec45a7Smrg    linker_flags=
67856aec45a7Smrg    dllsearchpath=
67866aec45a7Smrg    lib_search_path=`pwd`
67876aec45a7Smrg    inst_prefix_dir=
67886aec45a7Smrg    new_inherited_linker_flags=
6789ab47cfaaSmrg
67906aec45a7Smrg    avoid_version=no
67916aec45a7Smrg    bindir=
67926aec45a7Smrg    dlfiles=
67936aec45a7Smrg    dlprefiles=
67946aec45a7Smrg    dlself=no
67956aec45a7Smrg    export_dynamic=no
67966aec45a7Smrg    export_symbols=
67976aec45a7Smrg    export_symbols_regex=
67986aec45a7Smrg    generated=
67996aec45a7Smrg    libobjs=
68006aec45a7Smrg    ltlibs=
68016aec45a7Smrg    module=no
68026aec45a7Smrg    no_install=no
68036aec45a7Smrg    objs=
6804300bf1aeSmrg    os2dllname=
68056aec45a7Smrg    non_pic_objects=
68066aec45a7Smrg    precious_files_regex=
68076aec45a7Smrg    prefer_static_libs=no
6808300bf1aeSmrg    preload=false
68096aec45a7Smrg    prev=
68106aec45a7Smrg    prevarg=
68116aec45a7Smrg    release=
68126aec45a7Smrg    rpath=
68136aec45a7Smrg    xrpath=
68146aec45a7Smrg    perm_rpath=
68156aec45a7Smrg    temp_rpath=
68166aec45a7Smrg    thread_safe=no
68176aec45a7Smrg    vinfo=
68186aec45a7Smrg    vinfo_number=no
68196aec45a7Smrg    weak_libs=
6820300bf1aeSmrg    single_module=$wl-single_module
68216aec45a7Smrg    func_infer_tag $base_compile
6822ab47cfaaSmrg
68236aec45a7Smrg    # We need to know -static, to get the right output filenames.
68246aec45a7Smrg    for arg
68256aec45a7Smrg    do
68266aec45a7Smrg      case $arg in
68276aec45a7Smrg      -shared)
6828300bf1aeSmrg	test yes != "$build_libtool_libs" \
6829300bf1aeSmrg	  && func_fatal_configuration "cannot build a shared library"
68306aec45a7Smrg	build_old_libs=no
68316aec45a7Smrg	break
68326aec45a7Smrg	;;
68336aec45a7Smrg      -all-static | -static | -static-libtool-libs)
68346aec45a7Smrg	case $arg in
68356aec45a7Smrg	-all-static)
6836300bf1aeSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
68376aec45a7Smrg	    func_warning "complete static linking is impossible in this configuration"
68386aec45a7Smrg	  fi
68396aec45a7Smrg	  if test -n "$link_static_flag"; then
68406aec45a7Smrg	    dlopen_self=$dlopen_self_static
68416aec45a7Smrg	  fi
68426aec45a7Smrg	  prefer_static_libs=yes
68436aec45a7Smrg	  ;;
68446aec45a7Smrg	-static)
68456aec45a7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68466aec45a7Smrg	    dlopen_self=$dlopen_self_static
68476aec45a7Smrg	  fi
68486aec45a7Smrg	  prefer_static_libs=built
68496aec45a7Smrg	  ;;
68506aec45a7Smrg	-static-libtool-libs)
68516aec45a7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68526aec45a7Smrg	    dlopen_self=$dlopen_self_static
68536aec45a7Smrg	  fi
68546aec45a7Smrg	  prefer_static_libs=yes
68556aec45a7Smrg	  ;;
68566aec45a7Smrg	esac
68576aec45a7Smrg	build_libtool_libs=no
68586aec45a7Smrg	build_old_libs=yes
68596aec45a7Smrg	break
68606aec45a7Smrg	;;
68616aec45a7Smrg      esac
68626aec45a7Smrg    done
6863ab47cfaaSmrg
68646aec45a7Smrg    # See if our shared archives depend on static archives.
68656aec45a7Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866ab47cfaaSmrg
68676aec45a7Smrg    # Go through the arguments, transforming them on the way.
68686aec45a7Smrg    while test "$#" -gt 0; do
6869300bf1aeSmrg      arg=$1
68706aec45a7Smrg      shift
68712b2b4fcbSmrg      func_quote_arg pretty,unquoted "$arg"
68722b2b4fcbSmrg      qarg=$func_quote_arg_unquoted_result
68732b2b4fcbSmrg      func_append libtool_args " $func_quote_arg_result"
6874ab47cfaaSmrg
68756aec45a7Smrg      # If the previous option needs an argument, assign it.
68766aec45a7Smrg      if test -n "$prev"; then
68776aec45a7Smrg	case $prev in
68786aec45a7Smrg	output)
68796aec45a7Smrg	  func_append compile_command " @OUTPUT@"
68806aec45a7Smrg	  func_append finalize_command " @OUTPUT@"
68816aec45a7Smrg	  ;;
68826aec45a7Smrg	esac
6883ab47cfaaSmrg
68846aec45a7Smrg	case $prev in
68856aec45a7Smrg	bindir)
6886300bf1aeSmrg	  bindir=$arg
68876aec45a7Smrg	  prev=
68886aec45a7Smrg	  continue
68896aec45a7Smrg	  ;;
68906aec45a7Smrg	dlfiles|dlprefiles)
6891300bf1aeSmrg	  $preload || {
68926aec45a7Smrg	    # Add the symbol object into the linking commands.
68936aec45a7Smrg	    func_append compile_command " @SYMFILE@"
68946aec45a7Smrg	    func_append finalize_command " @SYMFILE@"
6895300bf1aeSmrg	    preload=:
6896300bf1aeSmrg	  }
68976aec45a7Smrg	  case $arg in
68986aec45a7Smrg	  *.la | *.lo) ;;  # We handle these cases below.
68996aec45a7Smrg	  force)
6900300bf1aeSmrg	    if test no = "$dlself"; then
69016aec45a7Smrg	      dlself=needless
69026aec45a7Smrg	      export_dynamic=yes
69035c42550eSmrg	    fi
69046aec45a7Smrg	    prev=
69056aec45a7Smrg	    continue
69066aec45a7Smrg	    ;;
69076aec45a7Smrg	  self)
6908300bf1aeSmrg	    if test dlprefiles = "$prev"; then
69096aec45a7Smrg	      dlself=yes
6910300bf1aeSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
69116aec45a7Smrg	      dlself=yes
69125c42550eSmrg	    else
69136aec45a7Smrg	      dlself=needless
69146aec45a7Smrg	      export_dynamic=yes
69155c42550eSmrg	    fi
69166aec45a7Smrg	    prev=
69176aec45a7Smrg	    continue
69186aec45a7Smrg	    ;;
69196aec45a7Smrg	  *)
6920300bf1aeSmrg	    if test dlfiles = "$prev"; then
6921aa9e3350Smrg	      func_append dlfiles " $arg"
69225c42550eSmrg	    else
6923aa9e3350Smrg	      func_append dlprefiles " $arg"
69245c42550eSmrg	    fi
69256aec45a7Smrg	    prev=
69266aec45a7Smrg	    continue
69276aec45a7Smrg	    ;;
69286aec45a7Smrg	  esac
69296aec45a7Smrg	  ;;
69306aec45a7Smrg	expsyms)
6931300bf1aeSmrg	  export_symbols=$arg
69326aec45a7Smrg	  test -f "$arg" \
6933300bf1aeSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
69346aec45a7Smrg	  prev=
69356aec45a7Smrg	  continue
69366aec45a7Smrg	  ;;
69376aec45a7Smrg	expsyms_regex)
6938300bf1aeSmrg	  export_symbols_regex=$arg
69396aec45a7Smrg	  prev=
69406aec45a7Smrg	  continue
69416aec45a7Smrg	  ;;
69426aec45a7Smrg	framework)
69435c42550eSmrg	  case $host in
69446aec45a7Smrg	    *-*-darwin*)
69456aec45a7Smrg	      case "$deplibs " in
69466aec45a7Smrg		*" $qarg.ltframework "*) ;;
6947aa9e3350Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
69486aec45a7Smrg		   ;;
69496aec45a7Smrg	      esac
69506aec45a7Smrg	      ;;
69515c42550eSmrg	  esac
69526aec45a7Smrg	  prev=
69536aec45a7Smrg	  continue
69545c42550eSmrg	  ;;
69556aec45a7Smrg	inst_prefix)
6956300bf1aeSmrg	  inst_prefix_dir=$arg
6957300bf1aeSmrg	  prev=
6958300bf1aeSmrg	  continue
6959300bf1aeSmrg	  ;;
6960300bf1aeSmrg	mllvm)
6961300bf1aeSmrg	  # Clang does not use LLVM to link, so we can simply discard any
6962300bf1aeSmrg	  # '-mllvm $arg' options when doing the link step.
69636aec45a7Smrg	  prev=
69646aec45a7Smrg	  continue
69655c42550eSmrg	  ;;
69666aec45a7Smrg	objectlist)
69676aec45a7Smrg	  if test -f "$arg"; then
69686aec45a7Smrg	    save_arg=$arg
69696aec45a7Smrg	    moreargs=
69706aec45a7Smrg	    for fil in `cat "$save_arg"`
69716aec45a7Smrg	    do
6972aa9e3350Smrg#	      func_append moreargs " $fil"
69736aec45a7Smrg	      arg=$fil
69746aec45a7Smrg	      # A libtool-controlled object.
6975ab47cfaaSmrg
69766aec45a7Smrg	      # Check to see that this really is a libtool object.
69776aec45a7Smrg	      if func_lalib_unsafe_p "$arg"; then
69786aec45a7Smrg		pic_object=
69796aec45a7Smrg		non_pic_object=
6980ab47cfaaSmrg
69816aec45a7Smrg		# Read the .lo file
69826aec45a7Smrg		func_source "$arg"
6983ab47cfaaSmrg
69846aec45a7Smrg		if test -z "$pic_object" ||
69856aec45a7Smrg		   test -z "$non_pic_object" ||
6986300bf1aeSmrg		   test none = "$pic_object" &&
6987300bf1aeSmrg		   test none = "$non_pic_object"; then
6988300bf1aeSmrg		  func_fatal_error "cannot find name of object for '$arg'"
69896aec45a7Smrg		fi
6990ab47cfaaSmrg
69916aec45a7Smrg		# Extract subdirectory from the argument.
69926aec45a7Smrg		func_dirname "$arg" "/" ""
6993300bf1aeSmrg		xdir=$func_dirname_result
6994ab47cfaaSmrg
6995300bf1aeSmrg		if test none != "$pic_object"; then
69966aec45a7Smrg		  # Prepend the subdirectory the object is found in.
6997300bf1aeSmrg		  pic_object=$xdir$pic_object
6998ab47cfaaSmrg
6999300bf1aeSmrg		  if test dlfiles = "$prev"; then
7000300bf1aeSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001aa9e3350Smrg		      func_append dlfiles " $pic_object"
70026aec45a7Smrg		      prev=
70036aec45a7Smrg		      continue
70046aec45a7Smrg		    else
70056aec45a7Smrg		      # If libtool objects are unsupported, then we need to preload.
70066aec45a7Smrg		      prev=dlprefiles
70076aec45a7Smrg		    fi
70086aec45a7Smrg		  fi
70098697ee19Smrg
70106aec45a7Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011300bf1aeSmrg		  if test dlprefiles = "$prev"; then
70126aec45a7Smrg		    # Preload the old-style object.
7013aa9e3350Smrg		    func_append dlprefiles " $pic_object"
70146aec45a7Smrg		    prev=
70156aec45a7Smrg		  fi
7016ab47cfaaSmrg
70176aec45a7Smrg		  # A PIC object.
70186aec45a7Smrg		  func_append libobjs " $pic_object"
7019300bf1aeSmrg		  arg=$pic_object
70206aec45a7Smrg		fi
70211473d951Smrg
70226aec45a7Smrg		# Non-PIC object.
7023300bf1aeSmrg		if test none != "$non_pic_object"; then
70246aec45a7Smrg		  # Prepend the subdirectory the object is found in.
7025300bf1aeSmrg		  non_pic_object=$xdir$non_pic_object
70261473d951Smrg
70276aec45a7Smrg		  # A standard non-PIC object
70286aec45a7Smrg		  func_append non_pic_objects " $non_pic_object"
7029300bf1aeSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030300bf1aeSmrg		    arg=$non_pic_object
70316aec45a7Smrg		  fi
70326aec45a7Smrg		else
70336aec45a7Smrg		  # If the PIC object exists, use it instead.
70346aec45a7Smrg		  # $xdir was prepended to $pic_object above.
7035300bf1aeSmrg		  non_pic_object=$pic_object
70366aec45a7Smrg		  func_append non_pic_objects " $non_pic_object"
70376aec45a7Smrg		fi
70386aec45a7Smrg	      else
70396aec45a7Smrg		# Only an error if not doing a dry-run.
70406aec45a7Smrg		if $opt_dry_run; then
70416aec45a7Smrg		  # Extract subdirectory from the argument.
70426aec45a7Smrg		  func_dirname "$arg" "/" ""
7043300bf1aeSmrg		  xdir=$func_dirname_result
70446aec45a7Smrg
70456aec45a7Smrg		  func_lo2o "$arg"
70466aec45a7Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
70476aec45a7Smrg		  non_pic_object=$xdir$func_lo2o_result
70486aec45a7Smrg		  func_append libobjs " $pic_object"
70496aec45a7Smrg		  func_append non_pic_objects " $non_pic_object"
70506aec45a7Smrg	        else
7051300bf1aeSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
70526aec45a7Smrg		fi
70536aec45a7Smrg	      fi
70546aec45a7Smrg	    done
70555c42550eSmrg	  else
7056300bf1aeSmrg	    func_fatal_error "link input file '$arg' does not exist"
70575c42550eSmrg	  fi
70586aec45a7Smrg	  arg=$save_arg
70596aec45a7Smrg	  prev=
70606aec45a7Smrg	  continue
70616aec45a7Smrg	  ;;
7062300bf1aeSmrg	os2dllname)
7063300bf1aeSmrg	  os2dllname=$arg
7064300bf1aeSmrg	  prev=
7065300bf1aeSmrg	  continue
7066300bf1aeSmrg	  ;;
70676aec45a7Smrg	precious_regex)
7068300bf1aeSmrg	  precious_files_regex=$arg
70696aec45a7Smrg	  prev=
70706aec45a7Smrg	  continue
70716aec45a7Smrg	  ;;
70726aec45a7Smrg	release)
7073300bf1aeSmrg	  release=-$arg
70746aec45a7Smrg	  prev=
70756aec45a7Smrg	  continue
70766aec45a7Smrg	  ;;
70776aec45a7Smrg	rpath | xrpath)
70786aec45a7Smrg	  # We need an absolute path.
70796aec45a7Smrg	  case $arg in
70806aec45a7Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
70816aec45a7Smrg	  *)
70826aec45a7Smrg	    func_fatal_error "only absolute run-paths are allowed"
70836aec45a7Smrg	    ;;
70846aec45a7Smrg	  esac
7085300bf1aeSmrg	  if test rpath = "$prev"; then
70866aec45a7Smrg	    case "$rpath " in
70876aec45a7Smrg	    *" $arg "*) ;;
7088aa9e3350Smrg	    *) func_append rpath " $arg" ;;
70896aec45a7Smrg	    esac
70905c42550eSmrg	  else
70916aec45a7Smrg	    case "$xrpath " in
70926aec45a7Smrg	    *" $arg "*) ;;
7093aa9e3350Smrg	    *) func_append xrpath " $arg" ;;
70946aec45a7Smrg	    esac
70955c42550eSmrg	  fi
70966aec45a7Smrg	  prev=
70976aec45a7Smrg	  continue
70986aec45a7Smrg	  ;;
70996aec45a7Smrg	shrext)
7100300bf1aeSmrg	  shrext_cmds=$arg
71016aec45a7Smrg	  prev=
71026aec45a7Smrg	  continue
71036aec45a7Smrg	  ;;
71046aec45a7Smrg	weak)
7105aa9e3350Smrg	  func_append weak_libs " $arg"
71066aec45a7Smrg	  prev=
71076aec45a7Smrg	  continue
71086aec45a7Smrg	  ;;
71092b2b4fcbSmrg	xassembler)
71102b2b4fcbSmrg	  func_append compiler_flags " -Xassembler $qarg"
71112b2b4fcbSmrg	  prev=
71122b2b4fcbSmrg	  func_append compile_command " -Xassembler $qarg"
71132b2b4fcbSmrg	  func_append finalize_command " -Xassembler $qarg"
71142b2b4fcbSmrg	  continue
71152b2b4fcbSmrg	  ;;
71166aec45a7Smrg	xcclinker)
7117aa9e3350Smrg	  func_append linker_flags " $qarg"
7118aa9e3350Smrg	  func_append compiler_flags " $qarg"
71196aec45a7Smrg	  prev=
71206aec45a7Smrg	  func_append compile_command " $qarg"
71216aec45a7Smrg	  func_append finalize_command " $qarg"
71226aec45a7Smrg	  continue
71236aec45a7Smrg	  ;;
71246aec45a7Smrg	xcompiler)
7125aa9e3350Smrg	  func_append compiler_flags " $qarg"
71266aec45a7Smrg	  prev=
71276aec45a7Smrg	  func_append compile_command " $qarg"
71286aec45a7Smrg	  func_append finalize_command " $qarg"
71296aec45a7Smrg	  continue
71306aec45a7Smrg	  ;;
71316aec45a7Smrg	xlinker)
7132aa9e3350Smrg	  func_append linker_flags " $qarg"
7133aa9e3350Smrg	  func_append compiler_flags " $wl$qarg"
71346aec45a7Smrg	  prev=
71356aec45a7Smrg	  func_append compile_command " $wl$qarg"
71366aec45a7Smrg	  func_append finalize_command " $wl$qarg"
71376aec45a7Smrg	  continue
71386aec45a7Smrg	  ;;
71396aec45a7Smrg	*)
71406aec45a7Smrg	  eval "$prev=\"\$arg\""
71416aec45a7Smrg	  prev=
71426aec45a7Smrg	  continue
71436aec45a7Smrg	  ;;
71441473d951Smrg	esac
71456aec45a7Smrg      fi # test -n "$prev"
71461473d951Smrg
7147300bf1aeSmrg      prevarg=$arg
71481473d951Smrg
71496aec45a7Smrg      case $arg in
71506aec45a7Smrg      -all-static)
71516aec45a7Smrg	if test -n "$link_static_flag"; then
71526aec45a7Smrg	  # See comment for -static flag below, for more details.
71536aec45a7Smrg	  func_append compile_command " $link_static_flag"
71546aec45a7Smrg	  func_append finalize_command " $link_static_flag"
71556aec45a7Smrg	fi
71566aec45a7Smrg	continue
71576aec45a7Smrg	;;
71581473d951Smrg
71596aec45a7Smrg      -allow-undefined)
71606aec45a7Smrg	# FIXME: remove this flag sometime in the future.
7161300bf1aeSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
71626aec45a7Smrg	;;
71631473d951Smrg
71646aec45a7Smrg      -avoid-version)
71656aec45a7Smrg	avoid_version=yes
71666aec45a7Smrg	continue
71676aec45a7Smrg	;;
71681473d951Smrg
71696aec45a7Smrg      -bindir)
71706aec45a7Smrg	prev=bindir
71716aec45a7Smrg	continue
71726aec45a7Smrg	;;
71731473d951Smrg
71746aec45a7Smrg      -dlopen)
71756aec45a7Smrg	prev=dlfiles
71766aec45a7Smrg	continue
71776aec45a7Smrg	;;
71781473d951Smrg
71796aec45a7Smrg      -dlpreopen)
71806aec45a7Smrg	prev=dlprefiles
71816aec45a7Smrg	continue
71826aec45a7Smrg	;;
71831473d951Smrg
71846aec45a7Smrg      -export-dynamic)
71856aec45a7Smrg	export_dynamic=yes
71866aec45a7Smrg	continue
71876aec45a7Smrg	;;
71881473d951Smrg
71896aec45a7Smrg      -export-symbols | -export-symbols-regex)
71906aec45a7Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
71916aec45a7Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
71926aec45a7Smrg	fi
7193300bf1aeSmrg	if test X-export-symbols = "X$arg"; then
71946aec45a7Smrg	  prev=expsyms
71956aec45a7Smrg	else
71966aec45a7Smrg	  prev=expsyms_regex
71976aec45a7Smrg	fi
71986aec45a7Smrg	continue
71996aec45a7Smrg	;;
72001473d951Smrg
72016aec45a7Smrg      -framework)
72026aec45a7Smrg	prev=framework
72036aec45a7Smrg	continue
72046aec45a7Smrg	;;
72051473d951Smrg
72066aec45a7Smrg      -inst-prefix-dir)
72076aec45a7Smrg	prev=inst_prefix
72086aec45a7Smrg	continue
72096aec45a7Smrg	;;
72101473d951Smrg
72116aec45a7Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
72126aec45a7Smrg      # so, if we see these flags be careful not to treat them like -L
72136aec45a7Smrg      -L[A-Z][A-Z]*:*)
72146aec45a7Smrg	case $with_gcc/$host in
72156aec45a7Smrg	no/*-*-irix* | /*-*-irix*)
72166aec45a7Smrg	  func_append compile_command " $arg"
72176aec45a7Smrg	  func_append finalize_command " $arg"
72186aec45a7Smrg	  ;;
72196aec45a7Smrg	esac
72206aec45a7Smrg	continue
72216aec45a7Smrg	;;
72221473d951Smrg
72236aec45a7Smrg      -L*)
7224aa9e3350Smrg	func_stripname "-L" '' "$arg"
7225aa9e3350Smrg	if test -z "$func_stripname_result"; then
72266aec45a7Smrg	  if test "$#" -gt 0; then
7227300bf1aeSmrg	    func_fatal_error "require no space between '-L' and '$1'"
72286aec45a7Smrg	  else
7229300bf1aeSmrg	    func_fatal_error "need path for '-L' option"
72306aec45a7Smrg	  fi
72316aec45a7Smrg	fi
7232aa9e3350Smrg	func_resolve_sysroot "$func_stripname_result"
7233aa9e3350Smrg	dir=$func_resolve_sysroot_result
72346aec45a7Smrg	# We need an absolute path.
72356aec45a7Smrg	case $dir in
72366aec45a7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
72376aec45a7Smrg	*)
72386aec45a7Smrg	  absdir=`cd "$dir" && pwd`
72396aec45a7Smrg	  test -z "$absdir" && \
7240300bf1aeSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241300bf1aeSmrg	  dir=$absdir
72426aec45a7Smrg	  ;;
72436aec45a7Smrg	esac
72446aec45a7Smrg	case "$deplibs " in
7245aa9e3350Smrg	*" -L$dir "* | *" $arg "*)
7246aa9e3350Smrg	  # Will only happen for absolute or sysroot arguments
7247aa9e3350Smrg	  ;;
72486aec45a7Smrg	*)
7249aa9e3350Smrg	  # Preserve sysroot, but never include relative directories
7250aa9e3350Smrg	  case $dir in
7251aa9e3350Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252aa9e3350Smrg	    *) func_append deplibs " -L$dir" ;;
7253aa9e3350Smrg	  esac
7254aa9e3350Smrg	  func_append lib_search_path " $dir"
72556aec45a7Smrg	  ;;
72566aec45a7Smrg	esac
72576aec45a7Smrg	case $host in
72586aec45a7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
72596aec45a7Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
72606aec45a7Smrg	  case :$dllsearchpath: in
72616aec45a7Smrg	  *":$dir:"*) ;;
72626aec45a7Smrg	  ::) dllsearchpath=$dir;;
7263aa9e3350Smrg	  *) func_append dllsearchpath ":$dir";;
72646aec45a7Smrg	  esac
72656aec45a7Smrg	  case :$dllsearchpath: in
72666aec45a7Smrg	  *":$testbindir:"*) ;;
72676aec45a7Smrg	  ::) dllsearchpath=$testbindir;;
7268aa9e3350Smrg	  *) func_append dllsearchpath ":$testbindir";;
72696aec45a7Smrg	  esac
72706aec45a7Smrg	  ;;
72716aec45a7Smrg	esac
72726aec45a7Smrg	continue
72736aec45a7Smrg	;;
72741473d951Smrg
72756aec45a7Smrg      -l*)
7276300bf1aeSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
72776aec45a7Smrg	  case $host in
72786aec45a7Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
72796aec45a7Smrg	    # These systems don't actually have a C or math library (as such)
72806aec45a7Smrg	    continue
72816aec45a7Smrg	    ;;
72826aec45a7Smrg	  *-*-os2*)
72836aec45a7Smrg	    # These systems don't actually have a C library (as such)
7284300bf1aeSmrg	    test X-lc = "X$arg" && continue
72856aec45a7Smrg	    ;;
72862b2b4fcbSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
72876aec45a7Smrg	    # Do not include libc due to us having libc/libc_r.
7288300bf1aeSmrg	    test X-lc = "X$arg" && continue
72896aec45a7Smrg	    ;;
72906aec45a7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
72916aec45a7Smrg	    # Rhapsody C and math libraries are in the System framework
7292aa9e3350Smrg	    func_append deplibs " System.ltframework"
72936aec45a7Smrg	    continue
72946aec45a7Smrg	    ;;
72956aec45a7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
72966aec45a7Smrg	    # Causes problems with __ctype
7297300bf1aeSmrg	    test X-lc = "X$arg" && continue
72986aec45a7Smrg	    ;;
72996aec45a7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
73006aec45a7Smrg	    # Compiler inserts libc in the correct place for threads to work
7301300bf1aeSmrg	    test X-lc = "X$arg" && continue
73026aec45a7Smrg	    ;;
73036aec45a7Smrg	  esac
7304300bf1aeSmrg	elif test X-lc_r = "X$arg"; then
73056aec45a7Smrg	 case $host in
73062b2b4fcbSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
73076aec45a7Smrg	   # Do not include libc_r directly, use -pthread flag.
73086aec45a7Smrg	   continue
73096aec45a7Smrg	   ;;
73106aec45a7Smrg	 esac
73116aec45a7Smrg	fi
7312aa9e3350Smrg	func_append deplibs " $arg"
73136aec45a7Smrg	continue
73146aec45a7Smrg	;;
73151473d951Smrg
7316300bf1aeSmrg      -mllvm)
7317300bf1aeSmrg	prev=mllvm
7318300bf1aeSmrg	continue
7319300bf1aeSmrg	;;
7320300bf1aeSmrg
73216aec45a7Smrg      -module)
73226aec45a7Smrg	module=yes
73236aec45a7Smrg	continue
73246aec45a7Smrg	;;
73251473d951Smrg
73266aec45a7Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
73276aec45a7Smrg      # classes, name mangling, and exception handling.
73286aec45a7Smrg      # Darwin uses the -arch flag to determine output architecture.
7329aa9e3350Smrg      -model|-arch|-isysroot|--sysroot)
7330aa9e3350Smrg	func_append compiler_flags " $arg"
73316aec45a7Smrg	func_append compile_command " $arg"
73326aec45a7Smrg	func_append finalize_command " $arg"
73336aec45a7Smrg	prev=xcompiler
73346aec45a7Smrg	continue
73356aec45a7Smrg	;;
73362b2b4fcbSmrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
73372b2b4fcbSmrg     -pthread)
73382b2b4fcbSmrg	case $host in
73392b2b4fcbSmrg	  *solaris2*) ;;
73402b2b4fcbSmrg	  *)
73412b2b4fcbSmrg	    case "$new_inherited_linker_flags " in
73422b2b4fcbSmrg	        *" $arg "*) ;;
73432b2b4fcbSmrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
73442b2b4fcbSmrg	    esac
73452b2b4fcbSmrg	  ;;
73462b2b4fcbSmrg	esac
73472b2b4fcbSmrg	continue
73482b2b4fcbSmrg	;;
73492b2b4fcbSmrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350aa9e3350Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351aa9e3350Smrg	func_append compiler_flags " $arg"
73526aec45a7Smrg	func_append compile_command " $arg"
73536aec45a7Smrg	func_append finalize_command " $arg"
73546aec45a7Smrg	case "$new_inherited_linker_flags " in
73556aec45a7Smrg	    *" $arg "*) ;;
7356aa9e3350Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
73576aec45a7Smrg	esac
73586aec45a7Smrg	continue
73596aec45a7Smrg	;;
73601473d951Smrg
73616aec45a7Smrg      -multi_module)
7362300bf1aeSmrg	single_module=$wl-multi_module
73636aec45a7Smrg	continue
73646aec45a7Smrg	;;
73651473d951Smrg
73666aec45a7Smrg      -no-fast-install)
73676aec45a7Smrg	fast_install=no
73686aec45a7Smrg	continue
73696aec45a7Smrg	;;
73701473d951Smrg
73716aec45a7Smrg      -no-install)
73726aec45a7Smrg	case $host in
73736aec45a7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
73746aec45a7Smrg	  # The PATH hackery in wrapper scripts is required on Windows
73756aec45a7Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376300bf1aeSmrg	  func_warning "'-no-install' is ignored for $host"
7377300bf1aeSmrg	  func_warning "assuming '-no-fast-install' instead"
73786aec45a7Smrg	  fast_install=no
73796aec45a7Smrg	  ;;
73806aec45a7Smrg	*) no_install=yes ;;
73816aec45a7Smrg	esac
73826aec45a7Smrg	continue
73836aec45a7Smrg	;;
73841473d951Smrg
73856aec45a7Smrg      -no-undefined)
73866aec45a7Smrg	allow_undefined=no
73876aec45a7Smrg	continue
73886aec45a7Smrg	;;
73891473d951Smrg
73906aec45a7Smrg      -objectlist)
73916aec45a7Smrg	prev=objectlist
73926aec45a7Smrg	continue
73936aec45a7Smrg	;;
73941473d951Smrg
7395300bf1aeSmrg      -os2dllname)
7396300bf1aeSmrg	prev=os2dllname
7397300bf1aeSmrg	continue
7398300bf1aeSmrg	;;
7399300bf1aeSmrg
74006aec45a7Smrg      -o) prev=output ;;
74011473d951Smrg
74026aec45a7Smrg      -precious-files-regex)
74036aec45a7Smrg	prev=precious_regex
74046aec45a7Smrg	continue
74056aec45a7Smrg	;;
74061473d951Smrg
74076aec45a7Smrg      -release)
74086aec45a7Smrg	prev=release
74096aec45a7Smrg	continue
74106aec45a7Smrg	;;
74111473d951Smrg
74126aec45a7Smrg      -rpath)
74136aec45a7Smrg	prev=rpath
74146aec45a7Smrg	continue
74156aec45a7Smrg	;;
74161473d951Smrg
74176aec45a7Smrg      -R)
74186aec45a7Smrg	prev=xrpath
74196aec45a7Smrg	continue
74206aec45a7Smrg	;;
74211473d951Smrg
74226aec45a7Smrg      -R*)
74236aec45a7Smrg	func_stripname '-R' '' "$arg"
74246aec45a7Smrg	dir=$func_stripname_result
74256aec45a7Smrg	# We need an absolute path.
74266aec45a7Smrg	case $dir in
74276aec45a7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428aa9e3350Smrg	=*)
7429aa9e3350Smrg	  func_stripname '=' '' "$dir"
7430aa9e3350Smrg	  dir=$lt_sysroot$func_stripname_result
7431aa9e3350Smrg	  ;;
74326aec45a7Smrg	*)
74336aec45a7Smrg	  func_fatal_error "only absolute run-paths are allowed"
74346aec45a7Smrg	  ;;
74356aec45a7Smrg	esac
74366aec45a7Smrg	case "$xrpath " in
74376aec45a7Smrg	*" $dir "*) ;;
7438aa9e3350Smrg	*) func_append xrpath " $dir" ;;
74396aec45a7Smrg	esac
74406aec45a7Smrg	continue
74416aec45a7Smrg	;;
74421473d951Smrg
74436aec45a7Smrg      -shared)
74446aec45a7Smrg	# The effects of -shared are defined in a previous loop.
74456aec45a7Smrg	continue
74466aec45a7Smrg	;;
74471473d951Smrg
74486aec45a7Smrg      -shrext)
74496aec45a7Smrg	prev=shrext
74506aec45a7Smrg	continue
74516aec45a7Smrg	;;
74521473d951Smrg
74536aec45a7Smrg      -static | -static-libtool-libs)
74546aec45a7Smrg	# The effects of -static are defined in a previous loop.
74556aec45a7Smrg	# We used to do the same as -all-static on platforms that
74566aec45a7Smrg	# didn't have a PIC flag, but the assumption that the effects
74576aec45a7Smrg	# would be equivalent was wrong.  It would break on at least
74586aec45a7Smrg	# Digital Unix and AIX.
74596aec45a7Smrg	continue
74606aec45a7Smrg	;;
74611473d951Smrg
74626aec45a7Smrg      -thread-safe)
74636aec45a7Smrg	thread_safe=yes
74646aec45a7Smrg	continue
74656aec45a7Smrg	;;
74661473d951Smrg
74676aec45a7Smrg      -version-info)
74686aec45a7Smrg	prev=vinfo
74696aec45a7Smrg	continue
74706aec45a7Smrg	;;
74711473d951Smrg
74726aec45a7Smrg      -version-number)
74736aec45a7Smrg	prev=vinfo
74746aec45a7Smrg	vinfo_number=yes
74756aec45a7Smrg	continue
74766aec45a7Smrg	;;
7477ab47cfaaSmrg
74786aec45a7Smrg      -weak)
74796aec45a7Smrg        prev=weak
74806aec45a7Smrg	continue
74816aec45a7Smrg	;;
74825c42550eSmrg
74836aec45a7Smrg      -Wc,*)
74846aec45a7Smrg	func_stripname '-Wc,' '' "$arg"
74856aec45a7Smrg	args=$func_stripname_result
74866aec45a7Smrg	arg=
7487300bf1aeSmrg	save_ifs=$IFS; IFS=,
74886aec45a7Smrg	for flag in $args; do
7489300bf1aeSmrg	  IFS=$save_ifs
74902b2b4fcbSmrg          func_quote_arg pretty "$flag"
74912b2b4fcbSmrg	  func_append arg " $func_quote_arg_result"
74922b2b4fcbSmrg	  func_append compiler_flags " $func_quote_arg_result"
74936aec45a7Smrg	done
7494300bf1aeSmrg	IFS=$save_ifs
74956aec45a7Smrg	func_stripname ' ' '' "$arg"
74966aec45a7Smrg	arg=$func_stripname_result
74976aec45a7Smrg	;;
74985c42550eSmrg
74996aec45a7Smrg      -Wl,*)
75006aec45a7Smrg	func_stripname '-Wl,' '' "$arg"
75016aec45a7Smrg	args=$func_stripname_result
75026aec45a7Smrg	arg=
7503300bf1aeSmrg	save_ifs=$IFS; IFS=,
75046aec45a7Smrg	for flag in $args; do
7505300bf1aeSmrg	  IFS=$save_ifs
75062b2b4fcbSmrg          func_quote_arg pretty "$flag"
75072b2b4fcbSmrg	  func_append arg " $wl$func_quote_arg_result"
75082b2b4fcbSmrg	  func_append compiler_flags " $wl$func_quote_arg_result"
75092b2b4fcbSmrg	  func_append linker_flags " $func_quote_arg_result"
75106aec45a7Smrg	done
7511300bf1aeSmrg	IFS=$save_ifs
75126aec45a7Smrg	func_stripname ' ' '' "$arg"
75136aec45a7Smrg	arg=$func_stripname_result
75146aec45a7Smrg	;;
75155c42550eSmrg
75162b2b4fcbSmrg      -Xassembler)
75172b2b4fcbSmrg        prev=xassembler
75182b2b4fcbSmrg        continue
75192b2b4fcbSmrg        ;;
75202b2b4fcbSmrg
75216aec45a7Smrg      -Xcompiler)
75226aec45a7Smrg	prev=xcompiler
75236aec45a7Smrg	continue
75246aec45a7Smrg	;;
75255c42550eSmrg
75266aec45a7Smrg      -Xlinker)
75276aec45a7Smrg	prev=xlinker
75286aec45a7Smrg	continue
75296aec45a7Smrg	;;
75305c42550eSmrg
75316aec45a7Smrg      -XCClinker)
75326aec45a7Smrg	prev=xcclinker
75336aec45a7Smrg	continue
75346aec45a7Smrg	;;
75355c42550eSmrg
75366aec45a7Smrg      # -msg_* for osf cc
75376aec45a7Smrg      -msg_*)
75382b2b4fcbSmrg	func_quote_arg pretty "$arg"
75392b2b4fcbSmrg	arg=$func_quote_arg_result
75406aec45a7Smrg	;;
75415c42550eSmrg
75426aec45a7Smrg      # Flags to be passed through unchanged, with rationale:
75436aec45a7Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
75446aec45a7Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
75456aec45a7Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
75466aec45a7Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
75476aec45a7Smrg      # -q*                  compiler args for the IBM compiler
75486aec45a7Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
75496aec45a7Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
75506aec45a7Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551300bf1aeSmrg      # -fstack-protector*   stack protector flags for GCC
75526aec45a7Smrg      # @file                GCC response files
75536aec45a7Smrg      # -tp=*                Portland pgcc target processor selection
7554aa9e3350Smrg      # --sysroot=*          for sysroot support
7555300bf1aeSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75562b2b4fcbSmrg      # -specs=*             GCC specs files
7557300bf1aeSmrg      # -stdlib=*            select c++ std lib with clang
75582b2b4fcbSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75592b2b4fcbSmrg      # -fuse-ld=*           Linker select flags for GCC
75602b2b4fcbSmrg      # -Wa,*                Pass flags directly to the assembler
75616aec45a7Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562aa9e3350Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75632b2b4fcbSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
75642b2b4fcbSmrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
75652b2b4fcbSmrg        func_quote_arg pretty "$arg"
75662b2b4fcbSmrg	arg=$func_quote_arg_result
75676aec45a7Smrg        func_append compile_command " $arg"
75686aec45a7Smrg        func_append finalize_command " $arg"
7569aa9e3350Smrg        func_append compiler_flags " $arg"
75706aec45a7Smrg        continue
75716aec45a7Smrg        ;;
75725c42550eSmrg
7573300bf1aeSmrg      -Z*)
7574300bf1aeSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575300bf1aeSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576300bf1aeSmrg	  compiler_flags="$compiler_flags $arg"
7577300bf1aeSmrg	  func_append compile_command " $arg"
7578300bf1aeSmrg	  func_append finalize_command " $arg"
7579300bf1aeSmrg	  case $arg in
7580300bf1aeSmrg	  -Zlinker | -Zstack)
7581300bf1aeSmrg	    prev=xcompiler
7582300bf1aeSmrg	    ;;
7583300bf1aeSmrg	  esac
7584300bf1aeSmrg	  continue
7585300bf1aeSmrg        else
7586300bf1aeSmrg	  # Otherwise treat like 'Some other compiler flag' below
75872b2b4fcbSmrg	  func_quote_arg pretty "$arg"
75882b2b4fcbSmrg	  arg=$func_quote_arg_result
7589300bf1aeSmrg        fi
7590300bf1aeSmrg	;;
7591300bf1aeSmrg
75926aec45a7Smrg      # Some other compiler flag.
75936aec45a7Smrg      -* | +*)
75942b2b4fcbSmrg        func_quote_arg pretty "$arg"
75952b2b4fcbSmrg	arg=$func_quote_arg_result
75966aec45a7Smrg	;;
75975c42550eSmrg
75986aec45a7Smrg      *.$objext)
75996aec45a7Smrg	# A standard object.
7600aa9e3350Smrg	func_append objs " $arg"
76016aec45a7Smrg	;;
76025c42550eSmrg
76036aec45a7Smrg      *.lo)
76046aec45a7Smrg	# A libtool-controlled object.
76055c42550eSmrg
76066aec45a7Smrg	# Check to see that this really is a libtool object.
76076aec45a7Smrg	if func_lalib_unsafe_p "$arg"; then
76086aec45a7Smrg	  pic_object=
76096aec45a7Smrg	  non_pic_object=
76105c42550eSmrg
76116aec45a7Smrg	  # Read the .lo file
76126aec45a7Smrg	  func_source "$arg"
76135c42550eSmrg
76146aec45a7Smrg	  if test -z "$pic_object" ||
76156aec45a7Smrg	     test -z "$non_pic_object" ||
7616300bf1aeSmrg	     test none = "$pic_object" &&
7617300bf1aeSmrg	     test none = "$non_pic_object"; then
7618300bf1aeSmrg	    func_fatal_error "cannot find name of object for '$arg'"
76196aec45a7Smrg	  fi
76205c42550eSmrg
76216aec45a7Smrg	  # Extract subdirectory from the argument.
76226aec45a7Smrg	  func_dirname "$arg" "/" ""
7623300bf1aeSmrg	  xdir=$func_dirname_result
76245c42550eSmrg
7625300bf1aeSmrg	  test none = "$pic_object" || {
76266aec45a7Smrg	    # Prepend the subdirectory the object is found in.
7627300bf1aeSmrg	    pic_object=$xdir$pic_object
76285c42550eSmrg
7629300bf1aeSmrg	    if test dlfiles = "$prev"; then
7630300bf1aeSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631aa9e3350Smrg		func_append dlfiles " $pic_object"
76326aec45a7Smrg		prev=
76336aec45a7Smrg		continue
76346aec45a7Smrg	      else
76356aec45a7Smrg		# If libtool objects are unsupported, then we need to preload.
76366aec45a7Smrg		prev=dlprefiles
76376aec45a7Smrg	      fi
76386aec45a7Smrg	    fi
76396aec45a7Smrg
76406aec45a7Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641300bf1aeSmrg	    if test dlprefiles = "$prev"; then
76426aec45a7Smrg	      # Preload the old-style object.
7643aa9e3350Smrg	      func_append dlprefiles " $pic_object"
76446aec45a7Smrg	      prev=
76456aec45a7Smrg	    fi
76466aec45a7Smrg
76476aec45a7Smrg	    # A PIC object.
76486aec45a7Smrg	    func_append libobjs " $pic_object"
7649300bf1aeSmrg	    arg=$pic_object
7650300bf1aeSmrg	  }
76516aec45a7Smrg
76526aec45a7Smrg	  # Non-PIC object.
7653300bf1aeSmrg	  if test none != "$non_pic_object"; then
76546aec45a7Smrg	    # Prepend the subdirectory the object is found in.
7655300bf1aeSmrg	    non_pic_object=$xdir$non_pic_object
76566aec45a7Smrg
76576aec45a7Smrg	    # A standard non-PIC object
76586aec45a7Smrg	    func_append non_pic_objects " $non_pic_object"
7659300bf1aeSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660300bf1aeSmrg	      arg=$non_pic_object
76616aec45a7Smrg	    fi
76626aec45a7Smrg	  else
76636aec45a7Smrg	    # If the PIC object exists, use it instead.
76646aec45a7Smrg	    # $xdir was prepended to $pic_object above.
7665300bf1aeSmrg	    non_pic_object=$pic_object
76666aec45a7Smrg	    func_append non_pic_objects " $non_pic_object"
76676aec45a7Smrg	  fi
76686aec45a7Smrg	else
76696aec45a7Smrg	  # Only an error if not doing a dry-run.
76706aec45a7Smrg	  if $opt_dry_run; then
76716aec45a7Smrg	    # Extract subdirectory from the argument.
76726aec45a7Smrg	    func_dirname "$arg" "/" ""
7673300bf1aeSmrg	    xdir=$func_dirname_result
76746aec45a7Smrg
76756aec45a7Smrg	    func_lo2o "$arg"
76766aec45a7Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
76776aec45a7Smrg	    non_pic_object=$xdir$func_lo2o_result
76786aec45a7Smrg	    func_append libobjs " $pic_object"
76796aec45a7Smrg	    func_append non_pic_objects " $non_pic_object"
76806aec45a7Smrg	  else
7681300bf1aeSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
76826aec45a7Smrg	  fi
76836aec45a7Smrg	fi
76846aec45a7Smrg	;;
76856aec45a7Smrg
76866aec45a7Smrg      *.$libext)
76876aec45a7Smrg	# An archive.
7688aa9e3350Smrg	func_append deplibs " $arg"
7689aa9e3350Smrg	func_append old_deplibs " $arg"
76906aec45a7Smrg	continue
76916aec45a7Smrg	;;
76926aec45a7Smrg
76936aec45a7Smrg      *.la)
76946aec45a7Smrg	# A libtool-controlled library.
76956aec45a7Smrg
7696aa9e3350Smrg	func_resolve_sysroot "$arg"
7697300bf1aeSmrg	if test dlfiles = "$prev"; then
76986aec45a7Smrg	  # This library was specified with -dlopen.
7699aa9e3350Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
77006aec45a7Smrg	  prev=
7701300bf1aeSmrg	elif test dlprefiles = "$prev"; then
77026aec45a7Smrg	  # The library was specified with -dlpreopen.
7703aa9e3350Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
77046aec45a7Smrg	  prev=
77056aec45a7Smrg	else
7706aa9e3350Smrg	  func_append deplibs " $func_resolve_sysroot_result"
77076aec45a7Smrg	fi
77086aec45a7Smrg	continue
77096aec45a7Smrg	;;
77106aec45a7Smrg
77116aec45a7Smrg      # Some other compiler argument.
77126aec45a7Smrg      *)
77136aec45a7Smrg	# Unknown arguments in both finalize_command and compile_command need
77146aec45a7Smrg	# to be aesthetically quoted because they are evaled later.
77152b2b4fcbSmrg	func_quote_arg pretty "$arg"
77162b2b4fcbSmrg	arg=$func_quote_arg_result
77176aec45a7Smrg	;;
77186aec45a7Smrg      esac # arg
77196aec45a7Smrg
77206aec45a7Smrg      # Now actually substitute the argument into the commands.
77216aec45a7Smrg      if test -n "$arg"; then
77226aec45a7Smrg	func_append compile_command " $arg"
77236aec45a7Smrg	func_append finalize_command " $arg"
77246aec45a7Smrg      fi
77256aec45a7Smrg    done # argument parsing loop
77266aec45a7Smrg
77276aec45a7Smrg    test -n "$prev" && \
7728300bf1aeSmrg      func_fatal_help "the '$prevarg' option requires an argument"
77296aec45a7Smrg
7730300bf1aeSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
77316aec45a7Smrg      eval arg=\"$export_dynamic_flag_spec\"
77326aec45a7Smrg      func_append compile_command " $arg"
77336aec45a7Smrg      func_append finalize_command " $arg"
77346aec45a7Smrg    fi
77356aec45a7Smrg
77366aec45a7Smrg    oldlibs=
77376aec45a7Smrg    # calculate the name of the file, without its directory
77386aec45a7Smrg    func_basename "$output"
7739300bf1aeSmrg    outputname=$func_basename_result
7740300bf1aeSmrg    libobjs_save=$libobjs
77416aec45a7Smrg
77426aec45a7Smrg    if test -n "$shlibpath_var"; then
77436aec45a7Smrg      # get the directories listed in $shlibpath_var
7744300bf1aeSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
77455c42550eSmrg    else
77466aec45a7Smrg      shlib_search_path=
77475c42550eSmrg    fi
77486aec45a7Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
77496aec45a7Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750ab47cfaaSmrg
7751300bf1aeSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7752300bf1aeSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753300bf1aeSmrg
77546aec45a7Smrg    func_dirname "$output" "/" ""
7755300bf1aeSmrg    output_objdir=$func_dirname_result$objdir
7756aa9e3350Smrg    func_to_tool_file "$output_objdir/"
7757aa9e3350Smrg    tool_output_objdir=$func_to_tool_file_result
77586aec45a7Smrg    # Create the object directory.
77596aec45a7Smrg    func_mkdir_p "$output_objdir"
7760ab47cfaaSmrg
77616aec45a7Smrg    # Determine the type of output
77626aec45a7Smrg    case $output in
77636aec45a7Smrg    "")
77646aec45a7Smrg      func_fatal_help "you must specify an output file"
77656aec45a7Smrg      ;;
77666aec45a7Smrg    *.$libext) linkmode=oldlib ;;
77676aec45a7Smrg    *.lo | *.$objext) linkmode=obj ;;
77686aec45a7Smrg    *.la) linkmode=lib ;;
77696aec45a7Smrg    *) linkmode=prog ;; # Anything else should be a program.
77706aec45a7Smrg    esac
77716aec45a7Smrg
77726aec45a7Smrg    specialdeplibs=
77736aec45a7Smrg
77746aec45a7Smrg    libs=
77756aec45a7Smrg    # Find all interdependent deplibs by searching for libraries
77766aec45a7Smrg    # that are linked more than once (e.g. -la -lb -la)
77776aec45a7Smrg    for deplib in $deplibs; do
7778300bf1aeSmrg      if $opt_preserve_dup_deps; then
77796aec45a7Smrg	case "$libs " in
7780aa9e3350Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
77816aec45a7Smrg	esac
77826aec45a7Smrg      fi
7783aa9e3350Smrg      func_append libs " $deplib"
77846aec45a7Smrg    done
77856aec45a7Smrg
7786300bf1aeSmrg    if test lib = "$linkmode"; then
77876aec45a7Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
77886aec45a7Smrg
77896aec45a7Smrg      # Compute libraries that are listed more than once in $predeps
77906aec45a7Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
77916aec45a7Smrg      # not to be eliminated).
77926aec45a7Smrg      pre_post_deps=
77936aec45a7Smrg      if $opt_duplicate_compiler_generated_deps; then
77946aec45a7Smrg	for pre_post_dep in $predeps $postdeps; do
77956aec45a7Smrg	  case "$pre_post_deps " in
7796aa9e3350Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
77976aec45a7Smrg	  esac
7798aa9e3350Smrg	  func_append pre_post_deps " $pre_post_dep"
77996aec45a7Smrg	done
78006aec45a7Smrg      fi
78016aec45a7Smrg      pre_post_deps=
78026aec45a7Smrg    fi
78036aec45a7Smrg
78046aec45a7Smrg    deplibs=
78056aec45a7Smrg    newdependency_libs=
78066aec45a7Smrg    newlib_search_path=
78076aec45a7Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
78086aec45a7Smrg    notinst_deplibs= # not-installed libtool libraries
78096aec45a7Smrg    notinst_path= # paths that contain not-installed libtool libraries
78106aec45a7Smrg
78116aec45a7Smrg    case $linkmode in
78126aec45a7Smrg    lib)
78136aec45a7Smrg	passes="conv dlpreopen link"
78146aec45a7Smrg	for file in $dlfiles $dlprefiles; do
78156aec45a7Smrg	  case $file in
78166aec45a7Smrg	  *.la) ;;
78176aec45a7Smrg	  *)
7818300bf1aeSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
78196aec45a7Smrg	    ;;
78206aec45a7Smrg	  esac
78216aec45a7Smrg	done
78226aec45a7Smrg	;;
78236aec45a7Smrg    prog)
78246aec45a7Smrg	compile_deplibs=
78256aec45a7Smrg	finalize_deplibs=
7826300bf1aeSmrg	alldeplibs=false
78276aec45a7Smrg	newdlfiles=
78286aec45a7Smrg	newdlprefiles=
78296aec45a7Smrg	passes="conv scan dlopen dlpreopen link"
78306aec45a7Smrg	;;
78316aec45a7Smrg    *)  passes="conv"
78326aec45a7Smrg	;;
78336aec45a7Smrg    esac
78346aec45a7Smrg
78356aec45a7Smrg    for pass in $passes; do
78366aec45a7Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
78376aec45a7Smrg      # so that -L comes before libs that need it for instance...
7838300bf1aeSmrg      if test lib,link = "$linkmode,$pass"; then
78396aec45a7Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
78406aec45a7Smrg	##        order, and fix it there properly
78416aec45a7Smrg        tmp_deplibs=
78426aec45a7Smrg	for deplib in $deplibs; do
78436aec45a7Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
78446aec45a7Smrg	done
7845300bf1aeSmrg	deplibs=$tmp_deplibs
78466aec45a7Smrg      fi
78476aec45a7Smrg
7848300bf1aeSmrg      if test lib,link = "$linkmode,$pass" ||
7849300bf1aeSmrg	 test prog,scan = "$linkmode,$pass"; then
7850300bf1aeSmrg	libs=$deplibs
78516aec45a7Smrg	deplibs=
78526aec45a7Smrg      fi
7853300bf1aeSmrg      if test prog = "$linkmode"; then
78546aec45a7Smrg	case $pass in
7855300bf1aeSmrg	dlopen) libs=$dlfiles ;;
7856300bf1aeSmrg	dlpreopen) libs=$dlprefiles ;;
7857300bf1aeSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
78586aec45a7Smrg	esac
78596aec45a7Smrg      fi
7860300bf1aeSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
78616aec45a7Smrg	# Collect and forward deplibs of preopened libtool libs
78626aec45a7Smrg	for lib in $dlprefiles; do
78636aec45a7Smrg	  # Ignore non-libtool-libs
78646aec45a7Smrg	  dependency_libs=
7865aa9e3350Smrg	  func_resolve_sysroot "$lib"
78666aec45a7Smrg	  case $lib in
7867aa9e3350Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
78686aec45a7Smrg	  esac
78696aec45a7Smrg
78706aec45a7Smrg	  # Collect preopened libtool deplibs, except any this library
78716aec45a7Smrg	  # has declared as weak libs
78726aec45a7Smrg	  for deplib in $dependency_libs; do
78736aec45a7Smrg	    func_basename "$deplib"
78746aec45a7Smrg            deplib_base=$func_basename_result
78756aec45a7Smrg	    case " $weak_libs " in
78766aec45a7Smrg	    *" $deplib_base "*) ;;
7877aa9e3350Smrg	    *) func_append deplibs " $deplib" ;;
78786aec45a7Smrg	    esac
78796aec45a7Smrg	  done
78806aec45a7Smrg	done
7881300bf1aeSmrg	libs=$dlprefiles
78826aec45a7Smrg      fi
7883300bf1aeSmrg      if test dlopen = "$pass"; then
78846aec45a7Smrg	# Collect dlpreopened libraries
7885300bf1aeSmrg	save_deplibs=$deplibs
78866aec45a7Smrg	deplibs=
78876aec45a7Smrg      fi
78886aec45a7Smrg
78896aec45a7Smrg      for deplib in $libs; do
78906aec45a7Smrg	lib=
7891300bf1aeSmrg	found=false
78926aec45a7Smrg	case $deplib in
7893aa9e3350Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894aa9e3350Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895300bf1aeSmrg	  if test prog,link = "$linkmode,$pass"; then
78966aec45a7Smrg	    compile_deplibs="$deplib $compile_deplibs"
78976aec45a7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
78986aec45a7Smrg	  else
7899aa9e3350Smrg	    func_append compiler_flags " $deplib"
7900300bf1aeSmrg	    if test lib = "$linkmode"; then
79016aec45a7Smrg		case "$new_inherited_linker_flags " in
79026aec45a7Smrg		    *" $deplib "*) ;;
7903aa9e3350Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79046aec45a7Smrg		esac
79056aec45a7Smrg	    fi
79066aec45a7Smrg	  fi
79076aec45a7Smrg	  continue
79086aec45a7Smrg	  ;;
79096aec45a7Smrg	-l*)
7910300bf1aeSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911300bf1aeSmrg	    func_warning "'-l' is ignored for archives/objects"
79126aec45a7Smrg	    continue
79136aec45a7Smrg	  fi
79146aec45a7Smrg	  func_stripname '-l' '' "$deplib"
79156aec45a7Smrg	  name=$func_stripname_result
7916300bf1aeSmrg	  if test lib = "$linkmode"; then
79176aec45a7Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
79186aec45a7Smrg	  else
79196aec45a7Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
79206aec45a7Smrg	  fi
79216aec45a7Smrg	  for searchdir in $searchdirs; do
79226aec45a7Smrg	    for search_ext in .la $std_shrext .so .a; do
79236aec45a7Smrg	      # Search the libtool library
7924300bf1aeSmrg	      lib=$searchdir/lib$name$search_ext
79256aec45a7Smrg	      if test -f "$lib"; then
7926300bf1aeSmrg		if test .la = "$search_ext"; then
7927300bf1aeSmrg		  found=:
79286aec45a7Smrg		else
7929300bf1aeSmrg		  found=false
79306aec45a7Smrg		fi
79316aec45a7Smrg		break 2
79326aec45a7Smrg	      fi
79336aec45a7Smrg	    done
79346aec45a7Smrg	  done
7935300bf1aeSmrg	  if $found; then
7936300bf1aeSmrg	    # deplib is a libtool library
79376aec45a7Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
79386aec45a7Smrg	    # We need to do some special things here, and not later.
7939300bf1aeSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
79406aec45a7Smrg	      case " $predeps $postdeps " in
79416aec45a7Smrg	      *" $deplib "*)
79426aec45a7Smrg		if func_lalib_p "$lib"; then
79436aec45a7Smrg		  library_names=
79446aec45a7Smrg		  old_library=
79456aec45a7Smrg		  func_source "$lib"
79466aec45a7Smrg		  for l in $old_library $library_names; do
7947300bf1aeSmrg		    ll=$l
79486aec45a7Smrg		  done
7949300bf1aeSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950300bf1aeSmrg		    found=false
79516aec45a7Smrg		    func_dirname "$lib" "" "."
7952300bf1aeSmrg		    ladir=$func_dirname_result
79536aec45a7Smrg		    lib=$ladir/$old_library
7954300bf1aeSmrg		    if test prog,link = "$linkmode,$pass"; then
79556aec45a7Smrg		      compile_deplibs="$deplib $compile_deplibs"
79566aec45a7Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
79576aec45a7Smrg		    else
79586aec45a7Smrg		      deplibs="$deplib $deplibs"
7959300bf1aeSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79606aec45a7Smrg		    fi
79616aec45a7Smrg		    continue
79626aec45a7Smrg		  fi
79636aec45a7Smrg		fi
79646aec45a7Smrg		;;
79656aec45a7Smrg	      *) ;;
79666aec45a7Smrg	      esac
79676aec45a7Smrg	    fi
7968300bf1aeSmrg	  else
7969300bf1aeSmrg	    # deplib doesn't seem to be a libtool library
7970300bf1aeSmrg	    if test prog,link = "$linkmode,$pass"; then
7971300bf1aeSmrg	      compile_deplibs="$deplib $compile_deplibs"
7972300bf1aeSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973300bf1aeSmrg	    else
7974300bf1aeSmrg	      deplibs="$deplib $deplibs"
7975300bf1aeSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976300bf1aeSmrg	    fi
7977300bf1aeSmrg	    continue
79786aec45a7Smrg	  fi
79796aec45a7Smrg	  ;; # -l
79806aec45a7Smrg	*.ltframework)
7981300bf1aeSmrg	  if test prog,link = "$linkmode,$pass"; then
79826aec45a7Smrg	    compile_deplibs="$deplib $compile_deplibs"
79836aec45a7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
79846aec45a7Smrg	  else
79856aec45a7Smrg	    deplibs="$deplib $deplibs"
7986300bf1aeSmrg	    if test lib = "$linkmode"; then
79876aec45a7Smrg		case "$new_inherited_linker_flags " in
79886aec45a7Smrg		    *" $deplib "*) ;;
7989aa9e3350Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79906aec45a7Smrg		esac
79916aec45a7Smrg	    fi
79926aec45a7Smrg	  fi
79936aec45a7Smrg	  continue
79946aec45a7Smrg	  ;;
79956aec45a7Smrg	-L*)
79966aec45a7Smrg	  case $linkmode in
79976aec45a7Smrg	  lib)
79986aec45a7Smrg	    deplibs="$deplib $deplibs"
7999300bf1aeSmrg	    test conv = "$pass" && continue
80006aec45a7Smrg	    newdependency_libs="$deplib $newdependency_libs"
80016aec45a7Smrg	    func_stripname '-L' '' "$deplib"
8002aa9e3350Smrg	    func_resolve_sysroot "$func_stripname_result"
8003aa9e3350Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80046aec45a7Smrg	    ;;
80056aec45a7Smrg	  prog)
8006300bf1aeSmrg	    if test conv = "$pass"; then
80076aec45a7Smrg	      deplibs="$deplib $deplibs"
80086aec45a7Smrg	      continue
80096aec45a7Smrg	    fi
8010300bf1aeSmrg	    if test scan = "$pass"; then
80116aec45a7Smrg	      deplibs="$deplib $deplibs"
80126aec45a7Smrg	    else
80136aec45a7Smrg	      compile_deplibs="$deplib $compile_deplibs"
80146aec45a7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80156aec45a7Smrg	    fi
80166aec45a7Smrg	    func_stripname '-L' '' "$deplib"
8017aa9e3350Smrg	    func_resolve_sysroot "$func_stripname_result"
8018aa9e3350Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80196aec45a7Smrg	    ;;
80206aec45a7Smrg	  *)
8021300bf1aeSmrg	    func_warning "'-L' is ignored for archives/objects"
80226aec45a7Smrg	    ;;
80236aec45a7Smrg	  esac # linkmode
80246aec45a7Smrg	  continue
80256aec45a7Smrg	  ;; # -L
80266aec45a7Smrg	-R*)
8027300bf1aeSmrg	  if test link = "$pass"; then
80286aec45a7Smrg	    func_stripname '-R' '' "$deplib"
8029aa9e3350Smrg	    func_resolve_sysroot "$func_stripname_result"
8030aa9e3350Smrg	    dir=$func_resolve_sysroot_result
80316aec45a7Smrg	    # Make sure the xrpath contains only unique directories.
80326aec45a7Smrg	    case "$xrpath " in
80336aec45a7Smrg	    *" $dir "*) ;;
8034aa9e3350Smrg	    *) func_append xrpath " $dir" ;;
80356aec45a7Smrg	    esac
80366aec45a7Smrg	  fi
80376aec45a7Smrg	  deplibs="$deplib $deplibs"
80386aec45a7Smrg	  continue
80396aec45a7Smrg	  ;;
8040aa9e3350Smrg	*.la)
8041aa9e3350Smrg	  func_resolve_sysroot "$deplib"
8042aa9e3350Smrg	  lib=$func_resolve_sysroot_result
8043aa9e3350Smrg	  ;;
80446aec45a7Smrg	*.$libext)
8045300bf1aeSmrg	  if test conv = "$pass"; then
80466aec45a7Smrg	    deplibs="$deplib $deplibs"
80476aec45a7Smrg	    continue
80486aec45a7Smrg	  fi
80496aec45a7Smrg	  case $linkmode in
80506aec45a7Smrg	  lib)
80516aec45a7Smrg	    # Linking convenience modules into shared libraries is allowed,
80526aec45a7Smrg	    # but linking other static libraries is non-portable.
80536aec45a7Smrg	    case " $dlpreconveniencelibs " in
80546aec45a7Smrg	    *" $deplib "*) ;;
80556aec45a7Smrg	    *)
8056300bf1aeSmrg	      valid_a_lib=false
80576aec45a7Smrg	      case $deplibs_check_method in
80586aec45a7Smrg		match_pattern*)
80596aec45a7Smrg		  set dummy $deplibs_check_method; shift
80606aec45a7Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
80616aec45a7Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
80626aec45a7Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063300bf1aeSmrg		    valid_a_lib=:
80646aec45a7Smrg		  fi
80656aec45a7Smrg		;;
80666aec45a7Smrg		pass_all)
8067300bf1aeSmrg		  valid_a_lib=:
80686aec45a7Smrg		;;
80696aec45a7Smrg	      esac
8070300bf1aeSmrg	      if $valid_a_lib; then
8071300bf1aeSmrg		echo
8072300bf1aeSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073300bf1aeSmrg		$ECHO "*** static library $deplib is not portable!"
8074300bf1aeSmrg		deplibs="$deplib $deplibs"
8075300bf1aeSmrg	      else
80766aec45a7Smrg		echo
80776aec45a7Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
80786aec45a7Smrg		echo "*** I have the capability to make that library automatically link in when"
80796aec45a7Smrg		echo "*** you link to this library.  But I can only do this if you have a"
80806aec45a7Smrg		echo "*** shared version of the library, which you do not appear to have"
80816aec45a7Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
80826aec45a7Smrg		echo "*** that it is just a static archive that I should not use here."
80836aec45a7Smrg	      fi
80846aec45a7Smrg	      ;;
80856aec45a7Smrg	    esac
80866aec45a7Smrg	    continue
80876aec45a7Smrg	    ;;
80886aec45a7Smrg	  prog)
8089300bf1aeSmrg	    if test link != "$pass"; then
80906aec45a7Smrg	      deplibs="$deplib $deplibs"
80916aec45a7Smrg	    else
80926aec45a7Smrg	      compile_deplibs="$deplib $compile_deplibs"
80936aec45a7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80946aec45a7Smrg	    fi
80956aec45a7Smrg	    continue
80966aec45a7Smrg	    ;;
80976aec45a7Smrg	  esac # linkmode
80986aec45a7Smrg	  ;; # *.$libext
80996aec45a7Smrg	*.lo | *.$objext)
8100300bf1aeSmrg	  if test conv = "$pass"; then
81016aec45a7Smrg	    deplibs="$deplib $deplibs"
8102300bf1aeSmrg	  elif test prog = "$linkmode"; then
8103300bf1aeSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
81046aec45a7Smrg	      # If there is no dlopen support or we're linking statically,
81056aec45a7Smrg	      # we need to preload.
8106aa9e3350Smrg	      func_append newdlprefiles " $deplib"
81076aec45a7Smrg	      compile_deplibs="$deplib $compile_deplibs"
81086aec45a7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
81096aec45a7Smrg	    else
8110aa9e3350Smrg	      func_append newdlfiles " $deplib"
81116aec45a7Smrg	    fi
81126aec45a7Smrg	  fi
81136aec45a7Smrg	  continue
81146aec45a7Smrg	  ;;
81156aec45a7Smrg	%DEPLIBS%)
8116300bf1aeSmrg	  alldeplibs=:
81176aec45a7Smrg	  continue
81186aec45a7Smrg	  ;;
81196aec45a7Smrg	esac # case $deplib
81206aec45a7Smrg
8121300bf1aeSmrg	$found || test -f "$lib" \
8122300bf1aeSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
81236aec45a7Smrg
81246aec45a7Smrg	# Check to see that this really is a libtool archive.
81256aec45a7Smrg	func_lalib_unsafe_p "$lib" \
8126300bf1aeSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
81276aec45a7Smrg
81286aec45a7Smrg	func_dirname "$lib" "" "."
8129300bf1aeSmrg	ladir=$func_dirname_result
81306aec45a7Smrg
81316aec45a7Smrg	dlname=
81326aec45a7Smrg	dlopen=
81336aec45a7Smrg	dlpreopen=
81346aec45a7Smrg	libdir=
81356aec45a7Smrg	library_names=
81366aec45a7Smrg	old_library=
81376aec45a7Smrg	inherited_linker_flags=
81386aec45a7Smrg	# If the library was installed with an old release of libtool,
81396aec45a7Smrg	# it will not redefine variables installed, or shouldnotlink
81406aec45a7Smrg	installed=yes
81416aec45a7Smrg	shouldnotlink=no
81426aec45a7Smrg	avoidtemprpath=
81436aec45a7Smrg
81446aec45a7Smrg
81456aec45a7Smrg	# Read the .la file
81466aec45a7Smrg	func_source "$lib"
81476aec45a7Smrg
81486aec45a7Smrg	# Convert "-framework foo" to "foo.ltframework"
81496aec45a7Smrg	if test -n "$inherited_linker_flags"; then
81506aec45a7Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
81516aec45a7Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
81526aec45a7Smrg	    case " $new_inherited_linker_flags " in
81536aec45a7Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8154aa9e3350Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
81556aec45a7Smrg	    esac
81566aec45a7Smrg	  done
81576aec45a7Smrg	fi
81586aec45a7Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159300bf1aeSmrg	if test lib,link = "$linkmode,$pass" ||
8160300bf1aeSmrg	   test prog,scan = "$linkmode,$pass" ||
8161300bf1aeSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162aa9e3350Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163aa9e3350Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
81646aec45a7Smrg	fi
81656aec45a7Smrg
8166300bf1aeSmrg	if test conv = "$pass"; then
81676aec45a7Smrg	  # Only check for convenience libraries
81686aec45a7Smrg	  deplibs="$lib $deplibs"
81696aec45a7Smrg	  if test -z "$libdir"; then
81706aec45a7Smrg	    if test -z "$old_library"; then
8171300bf1aeSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
81726aec45a7Smrg	    fi
81736aec45a7Smrg	    # It is a libtool convenience library, so add in its objects.
8174aa9e3350Smrg	    func_append convenience " $ladir/$objdir/$old_library"
8175aa9e3350Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176300bf1aeSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177300bf1aeSmrg	    func_fatal_error "'$lib' is not a convenience library"
81786aec45a7Smrg	  fi
8179300bf1aeSmrg	  tmp_libs=
8180300bf1aeSmrg	  for deplib in $dependency_libs; do
8181300bf1aeSmrg	    deplibs="$deplib $deplibs"
8182300bf1aeSmrg	    if $opt_preserve_dup_deps; then
8183300bf1aeSmrg	      case "$tmp_libs " in
8184300bf1aeSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185300bf1aeSmrg	      esac
8186300bf1aeSmrg	    fi
8187300bf1aeSmrg	    func_append tmp_libs " $deplib"
8188300bf1aeSmrg	  done
81896aec45a7Smrg	  continue
81906aec45a7Smrg	fi # $pass = conv
81916aec45a7Smrg
81926aec45a7Smrg
81936aec45a7Smrg	# Get the name of the library we link against.
81946aec45a7Smrg	linklib=
8195aa9e3350Smrg	if test -n "$old_library" &&
8196300bf1aeSmrg	   { test yes = "$prefer_static_libs" ||
8197300bf1aeSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198aa9e3350Smrg	  linklib=$old_library
8199aa9e3350Smrg	else
8200aa9e3350Smrg	  for l in $old_library $library_names; do
8201300bf1aeSmrg	    linklib=$l
8202aa9e3350Smrg	  done
8203aa9e3350Smrg	fi
82046aec45a7Smrg	if test -z "$linklib"; then
8205300bf1aeSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
82066aec45a7Smrg	fi
82076aec45a7Smrg
82086aec45a7Smrg	# This library was specified with -dlopen.
8209300bf1aeSmrg	if test dlopen = "$pass"; then
8210300bf1aeSmrg	  test -z "$libdir" \
8211300bf1aeSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
82126aec45a7Smrg	  if test -z "$dlname" ||
8213300bf1aeSmrg	     test yes != "$dlopen_support" ||
8214300bf1aeSmrg	     test no = "$build_libtool_libs"
8215300bf1aeSmrg	  then
82166aec45a7Smrg	    # If there is no dlname, no dlopen support or we're linking
82176aec45a7Smrg	    # statically, we need to preload.  We also need to preload any
82186aec45a7Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
82196aec45a7Smrg	    # bomb out in the load deplibs phase.
8220aa9e3350Smrg	    func_append dlprefiles " $lib $dependency_libs"
82216aec45a7Smrg	  else
8222aa9e3350Smrg	    func_append newdlfiles " $lib"
82236aec45a7Smrg	  fi
82246aec45a7Smrg	  continue
82256aec45a7Smrg	fi # $pass = dlopen
82266aec45a7Smrg
82276aec45a7Smrg	# We need an absolute path.
82286aec45a7Smrg	case $ladir in
8229300bf1aeSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
82306aec45a7Smrg	*)
82316aec45a7Smrg	  abs_ladir=`cd "$ladir" && pwd`
82326aec45a7Smrg	  if test -z "$abs_ladir"; then
8233300bf1aeSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
82346aec45a7Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235300bf1aeSmrg	    abs_ladir=$ladir
82366aec45a7Smrg	  fi
82376aec45a7Smrg	  ;;
82386aec45a7Smrg	esac
82396aec45a7Smrg	func_basename "$lib"
8240300bf1aeSmrg	laname=$func_basename_result
82416aec45a7Smrg
82426aec45a7Smrg	# Find the relevant object directory and library name.
8243300bf1aeSmrg	if test yes = "$installed"; then
8244aa9e3350Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245300bf1aeSmrg	    func_warning "library '$lib' was moved."
8246300bf1aeSmrg	    dir=$ladir
8247300bf1aeSmrg	    absdir=$abs_ladir
8248300bf1aeSmrg	    libdir=$abs_ladir
82496aec45a7Smrg	  else
8250300bf1aeSmrg	    dir=$lt_sysroot$libdir
8251300bf1aeSmrg	    absdir=$lt_sysroot$libdir
82526aec45a7Smrg	  fi
8253300bf1aeSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
82546aec45a7Smrg	else
82556aec45a7Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256300bf1aeSmrg	    dir=$ladir
8257300bf1aeSmrg	    absdir=$abs_ladir
82586aec45a7Smrg	    # Remove this search path later
8259aa9e3350Smrg	    func_append notinst_path " $abs_ladir"
82606aec45a7Smrg	  else
8261300bf1aeSmrg	    dir=$ladir/$objdir
8262300bf1aeSmrg	    absdir=$abs_ladir/$objdir
82636aec45a7Smrg	    # Remove this search path later
8264aa9e3350Smrg	    func_append notinst_path " $abs_ladir"
82656aec45a7Smrg	  fi
82666aec45a7Smrg	fi # $installed = yes
82676aec45a7Smrg	func_stripname 'lib' '.la' "$laname"
82686aec45a7Smrg	name=$func_stripname_result
82696aec45a7Smrg
82706aec45a7Smrg	# This library was specified with -dlpreopen.
8271300bf1aeSmrg	if test dlpreopen = "$pass"; then
8272300bf1aeSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273300bf1aeSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
82746aec45a7Smrg	  fi
8275300bf1aeSmrg	  case $host in
8276aa9e3350Smrg	    # special handling for platforms with PE-DLLs.
8277aa9e3350Smrg	    *cygwin* | *mingw* | *cegcc* )
8278aa9e3350Smrg	      # Linker will automatically link against shared library if both
8279aa9e3350Smrg	      # static and shared are present.  Therefore, ensure we extract
8280aa9e3350Smrg	      # symbols from the import library if a shared library is present
8281aa9e3350Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282aa9e3350Smrg	      # this by putting the import library name into $newdlprefiles.
8283aa9e3350Smrg	      # We recover the dlopen module name by 'saving' the la file
8284aa9e3350Smrg	      # name in a special purpose variable, and (later) extracting the
8285aa9e3350Smrg	      # dlname from the la file.
8286aa9e3350Smrg	      if test -n "$dlname"; then
8287aa9e3350Smrg	        func_tr_sh "$dir/$linklib"
8288aa9e3350Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289aa9e3350Smrg	        func_append newdlprefiles " $dir/$linklib"
8290aa9e3350Smrg	      else
8291aa9e3350Smrg	        func_append newdlprefiles " $dir/$old_library"
8292aa9e3350Smrg	        # Keep a list of preopened convenience libraries to check
8293aa9e3350Smrg	        # that they are being used correctly in the link pass.
8294aa9e3350Smrg	        test -z "$libdir" && \
8295aa9e3350Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296aa9e3350Smrg	      fi
8297aa9e3350Smrg	    ;;
8298aa9e3350Smrg	    * )
8299aa9e3350Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300aa9e3350Smrg	      # are required to link).
8301aa9e3350Smrg	      if test -n "$old_library"; then
8302aa9e3350Smrg	        func_append newdlprefiles " $dir/$old_library"
8303aa9e3350Smrg	        # Keep a list of preopened convenience libraries to check
8304aa9e3350Smrg	        # that they are being used correctly in the link pass.
8305aa9e3350Smrg	        test -z "$libdir" && \
8306aa9e3350Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307aa9e3350Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308aa9e3350Smrg	      elif test -n "$dlname"; then
8309aa9e3350Smrg	        func_append newdlprefiles " $dir/$dlname"
8310aa9e3350Smrg	      else
8311aa9e3350Smrg	        func_append newdlprefiles " $dir/$linklib"
8312aa9e3350Smrg	      fi
8313aa9e3350Smrg	    ;;
8314aa9e3350Smrg	  esac
83156aec45a7Smrg	fi # $pass = dlpreopen
83166aec45a7Smrg
83176aec45a7Smrg	if test -z "$libdir"; then
83186aec45a7Smrg	  # Link the convenience library
8319300bf1aeSmrg	  if test lib = "$linkmode"; then
83206aec45a7Smrg	    deplibs="$dir/$old_library $deplibs"
8321300bf1aeSmrg	  elif test prog,link = "$linkmode,$pass"; then
83226aec45a7Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
83236aec45a7Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
83246aec45a7Smrg	  else
83256aec45a7Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
83266aec45a7Smrg	  fi
83276aec45a7Smrg	  continue
83286aec45a7Smrg	fi
83296aec45a7Smrg
83306aec45a7Smrg
8331300bf1aeSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8332aa9e3350Smrg	  func_append newlib_search_path " $ladir"
83336aec45a7Smrg	  deplibs="$lib $deplibs"
83346aec45a7Smrg
8335300bf1aeSmrg	  linkalldeplibs=false
8336300bf1aeSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337300bf1aeSmrg	     test no = "$build_libtool_libs"; then
8338300bf1aeSmrg	    linkalldeplibs=:
83396aec45a7Smrg	  fi
83406aec45a7Smrg
83416aec45a7Smrg	  tmp_libs=
83426aec45a7Smrg	  for deplib in $dependency_libs; do
83436aec45a7Smrg	    case $deplib in
83446aec45a7Smrg	    -L*) func_stripname '-L' '' "$deplib"
8345aa9e3350Smrg	         func_resolve_sysroot "$func_stripname_result"
8346aa9e3350Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
83476aec45a7Smrg		 ;;
83486aec45a7Smrg	    esac
83496aec45a7Smrg	    # Need to link against all dependency_libs?
8350300bf1aeSmrg	    if $linkalldeplibs; then
83516aec45a7Smrg	      deplibs="$deplib $deplibs"
83526aec45a7Smrg	    else
83536aec45a7Smrg	      # Need to hardcode shared library paths
83546aec45a7Smrg	      # or/and link against static libraries
83556aec45a7Smrg	      newdependency_libs="$deplib $newdependency_libs"
83566aec45a7Smrg	    fi
8357300bf1aeSmrg	    if $opt_preserve_dup_deps; then
83586aec45a7Smrg	      case "$tmp_libs " in
8359aa9e3350Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83606aec45a7Smrg	      esac
83616aec45a7Smrg	    fi
8362aa9e3350Smrg	    func_append tmp_libs " $deplib"
83636aec45a7Smrg	  done # for deplib
83646aec45a7Smrg	  continue
83656aec45a7Smrg	fi # $linkmode = prog...
83666aec45a7Smrg
8367300bf1aeSmrg	if test prog,link = "$linkmode,$pass"; then
83686aec45a7Smrg	  if test -n "$library_names" &&
8369300bf1aeSmrg	     { { test no = "$prefer_static_libs" ||
8370300bf1aeSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
83716aec45a7Smrg	       test -z "$old_library"; }; then
83726aec45a7Smrg	    # We need to hardcode the library path
8373300bf1aeSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
83746aec45a7Smrg	      # Make sure the rpath contains only unique directories.
8375300bf1aeSmrg	      case $temp_rpath: in
83766aec45a7Smrg	      *"$absdir:"*) ;;
8377aa9e3350Smrg	      *) func_append temp_rpath "$absdir:" ;;
83786aec45a7Smrg	      esac
83796aec45a7Smrg	    fi
83806aec45a7Smrg
83816aec45a7Smrg	    # Hardcode the library path.
83826aec45a7Smrg	    # Skip directories that are in the system default run-time
83836aec45a7Smrg	    # search path.
83846aec45a7Smrg	    case " $sys_lib_dlsearch_path " in
83856aec45a7Smrg	    *" $absdir "*) ;;
83866aec45a7Smrg	    *)
83876aec45a7Smrg	      case "$compile_rpath " in
83886aec45a7Smrg	      *" $absdir "*) ;;
8389aa9e3350Smrg	      *) func_append compile_rpath " $absdir" ;;
83906aec45a7Smrg	      esac
83916aec45a7Smrg	      ;;
83926aec45a7Smrg	    esac
83936aec45a7Smrg	    case " $sys_lib_dlsearch_path " in
83946aec45a7Smrg	    *" $libdir "*) ;;
83956aec45a7Smrg	    *)
83966aec45a7Smrg	      case "$finalize_rpath " in
83976aec45a7Smrg	      *" $libdir "*) ;;
8398aa9e3350Smrg	      *) func_append finalize_rpath " $libdir" ;;
83996aec45a7Smrg	      esac
84006aec45a7Smrg	      ;;
84016aec45a7Smrg	    esac
84026aec45a7Smrg	  fi # $linkmode,$pass = prog,link...
84036aec45a7Smrg
8404300bf1aeSmrg	  if $alldeplibs &&
8405300bf1aeSmrg	     { test pass_all = "$deplibs_check_method" ||
8406300bf1aeSmrg	       { test yes = "$build_libtool_libs" &&
84076aec45a7Smrg		 test -n "$library_names"; }; }; then
84086aec45a7Smrg	    # We only need to search for static libraries
84096aec45a7Smrg	    continue
84106aec45a7Smrg	  fi
84116aec45a7Smrg	fi
84126aec45a7Smrg
84136aec45a7Smrg	link_static=no # Whether the deplib will be linked statically
84146aec45a7Smrg	use_static_libs=$prefer_static_libs
8415300bf1aeSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
84166aec45a7Smrg	  use_static_libs=no
84176aec45a7Smrg	fi
84186aec45a7Smrg	if test -n "$library_names" &&
8419300bf1aeSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
84206aec45a7Smrg	  case $host in
8421300bf1aeSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
84226aec45a7Smrg	      # No point in relinking DLLs because paths are not encoded
8423aa9e3350Smrg	      func_append notinst_deplibs " $lib"
84246aec45a7Smrg	      need_relink=no
84256aec45a7Smrg	    ;;
84266aec45a7Smrg	  *)
8427300bf1aeSmrg	    if test no = "$installed"; then
8428aa9e3350Smrg	      func_append notinst_deplibs " $lib"
84296aec45a7Smrg	      need_relink=yes
84306aec45a7Smrg	    fi
84316aec45a7Smrg	    ;;
84326aec45a7Smrg	  esac
84336aec45a7Smrg	  # This is a shared library
84346aec45a7Smrg
84356aec45a7Smrg	  # Warn about portability, can't link against -module's on some
84366aec45a7Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437300bf1aeSmrg	  dlopenmodule=
84386aec45a7Smrg	  for dlpremoduletest in $dlprefiles; do
84396aec45a7Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440300bf1aeSmrg	      dlopenmodule=$dlpremoduletest
84416aec45a7Smrg	      break
84426aec45a7Smrg	    fi
84436aec45a7Smrg	  done
8444300bf1aeSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
84456aec45a7Smrg	    echo
8446300bf1aeSmrg	    if test prog = "$linkmode"; then
84476aec45a7Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
84486aec45a7Smrg	    else
84496aec45a7Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
84506aec45a7Smrg	    fi
84516aec45a7Smrg	    $ECHO "*** $linklib is not portable!"
84526aec45a7Smrg	  fi
8453300bf1aeSmrg	  if test lib = "$linkmode" &&
8454300bf1aeSmrg	     test yes = "$hardcode_into_libs"; then
84556aec45a7Smrg	    # Hardcode the library path.
84566aec45a7Smrg	    # Skip directories that are in the system default run-time
84576aec45a7Smrg	    # search path.
84586aec45a7Smrg	    case " $sys_lib_dlsearch_path " in
84596aec45a7Smrg	    *" $absdir "*) ;;
84606aec45a7Smrg	    *)
84616aec45a7Smrg	      case "$compile_rpath " in
84626aec45a7Smrg	      *" $absdir "*) ;;
8463aa9e3350Smrg	      *) func_append compile_rpath " $absdir" ;;
84646aec45a7Smrg	      esac
84656aec45a7Smrg	      ;;
84666aec45a7Smrg	    esac
84676aec45a7Smrg	    case " $sys_lib_dlsearch_path " in
84686aec45a7Smrg	    *" $libdir "*) ;;
84696aec45a7Smrg	    *)
84706aec45a7Smrg	      case "$finalize_rpath " in
84716aec45a7Smrg	      *" $libdir "*) ;;
8472aa9e3350Smrg	      *) func_append finalize_rpath " $libdir" ;;
84736aec45a7Smrg	      esac
84746aec45a7Smrg	      ;;
84756aec45a7Smrg	    esac
84766aec45a7Smrg	  fi
84776aec45a7Smrg
84786aec45a7Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
84796aec45a7Smrg	    # figure out the soname
84806aec45a7Smrg	    set dummy $library_names
84816aec45a7Smrg	    shift
8482300bf1aeSmrg	    realname=$1
84836aec45a7Smrg	    shift
84846aec45a7Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
84856aec45a7Smrg	    # use dlname if we got it. it's perfectly good, no?
84866aec45a7Smrg	    if test -n "$dlname"; then
8487300bf1aeSmrg	      soname=$dlname
84886aec45a7Smrg	    elif test -n "$soname_spec"; then
84896aec45a7Smrg	      # bleh windows
84906aec45a7Smrg	      case $host in
8491300bf1aeSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
84926aec45a7Smrg	        func_arith $current - $age
84936aec45a7Smrg		major=$func_arith_result
8494300bf1aeSmrg		versuffix=-$major
84956aec45a7Smrg		;;
84966aec45a7Smrg	      esac
84976aec45a7Smrg	      eval soname=\"$soname_spec\"
84986aec45a7Smrg	    else
8499300bf1aeSmrg	      soname=$realname
85006aec45a7Smrg	    fi
85016aec45a7Smrg
85026aec45a7Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503300bf1aeSmrg	    soroot=$soname
85046aec45a7Smrg	    func_basename "$soroot"
8505300bf1aeSmrg	    soname=$func_basename_result
85066aec45a7Smrg	    func_stripname 'lib' '.dll' "$soname"
85076aec45a7Smrg	    newlib=libimp-$func_stripname_result.a
85086aec45a7Smrg
85096aec45a7Smrg	    # If the library has no export list, then create one now
85106aec45a7Smrg	    if test -f "$output_objdir/$soname-def"; then :
85116aec45a7Smrg	    else
8512300bf1aeSmrg	      func_verbose "extracting exported symbol list from '$soname'"
85136aec45a7Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
85146aec45a7Smrg	    fi
85156aec45a7Smrg
85166aec45a7Smrg	    # Create $newlib
85176aec45a7Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518300bf1aeSmrg	      func_verbose "generating import library for '$soname'"
85196aec45a7Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
85206aec45a7Smrg	    fi
85216aec45a7Smrg	    # make sure the library variables are pointing to the new library
85226aec45a7Smrg	    dir=$output_objdir
85236aec45a7Smrg	    linklib=$newlib
85246aec45a7Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
85256aec45a7Smrg
8526300bf1aeSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
85276aec45a7Smrg	    add_shlibpath=
85286aec45a7Smrg	    add_dir=
85296aec45a7Smrg	    add=
85306aec45a7Smrg	    lib_linked=yes
85316aec45a7Smrg	    case $hardcode_action in
85326aec45a7Smrg	    immediate | unsupported)
8533300bf1aeSmrg	      if test no = "$hardcode_direct"; then
8534300bf1aeSmrg		add=$dir/$linklib
85356aec45a7Smrg		case $host in
8536300bf1aeSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537300bf1aeSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
85386aec45a7Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539300bf1aeSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
85406aec45a7Smrg		  *-*-darwin* )
8541300bf1aeSmrg		    # if the lib is a (non-dlopened) module then we cannot
85426aec45a7Smrg		    # link against it, someone is ignoring the earlier warnings
85436aec45a7Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544300bf1aeSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
85456aec45a7Smrg		      if test "X$dlopenmodule" != "X$lib"; then
85466aec45a7Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547300bf1aeSmrg			if test -z "$old_library"; then
85486aec45a7Smrg			  echo
85496aec45a7Smrg			  echo "*** And there doesn't seem to be a static archive available"
85506aec45a7Smrg			  echo "*** The link will probably fail, sorry"
85516aec45a7Smrg			else
8552300bf1aeSmrg			  add=$dir/$old_library
85536aec45a7Smrg			fi
85546aec45a7Smrg		      elif test -n "$old_library"; then
8555300bf1aeSmrg			add=$dir/$old_library
85566aec45a7Smrg		      fi
85576aec45a7Smrg		    fi
85586aec45a7Smrg		esac
8559300bf1aeSmrg	      elif test no = "$hardcode_minus_L"; then
85606aec45a7Smrg		case $host in
8561300bf1aeSmrg		*-*-sunos*) add_shlibpath=$dir ;;
85626aec45a7Smrg		esac
8563300bf1aeSmrg		add_dir=-L$dir
8564300bf1aeSmrg		add=-l$name
8565300bf1aeSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8566300bf1aeSmrg		add_shlibpath=$dir
8567300bf1aeSmrg		add=-l$name
85686aec45a7Smrg	      else
85696aec45a7Smrg		lib_linked=no
85706aec45a7Smrg	      fi
85716aec45a7Smrg	      ;;
85726aec45a7Smrg	    relink)
8573300bf1aeSmrg	      if test yes = "$hardcode_direct" &&
8574300bf1aeSmrg	         test no = "$hardcode_direct_absolute"; then
8575300bf1aeSmrg		add=$dir/$linklib
8576300bf1aeSmrg	      elif test yes = "$hardcode_minus_L"; then
8577300bf1aeSmrg		add_dir=-L$absdir
85786aec45a7Smrg		# Try looking first in the location we're being installed to.
85796aec45a7Smrg		if test -n "$inst_prefix_dir"; then
85806aec45a7Smrg		  case $libdir in
85816aec45a7Smrg		    [\\/]*)
8582aa9e3350Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
85836aec45a7Smrg		      ;;
85846aec45a7Smrg		  esac
85856aec45a7Smrg		fi
8586300bf1aeSmrg		add=-l$name
8587300bf1aeSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588300bf1aeSmrg		add_shlibpath=$dir
8589300bf1aeSmrg		add=-l$name
85906aec45a7Smrg	      else
85916aec45a7Smrg		lib_linked=no
85926aec45a7Smrg	      fi
85936aec45a7Smrg	      ;;
85946aec45a7Smrg	    *) lib_linked=no ;;
85956aec45a7Smrg	    esac
85966aec45a7Smrg
8597300bf1aeSmrg	    if test yes != "$lib_linked"; then
85986aec45a7Smrg	      func_fatal_configuration "unsupported hardcode properties"
85996aec45a7Smrg	    fi
86006aec45a7Smrg
86016aec45a7Smrg	    if test -n "$add_shlibpath"; then
86026aec45a7Smrg	      case :$compile_shlibpath: in
86036aec45a7Smrg	      *":$add_shlibpath:"*) ;;
8604aa9e3350Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
86056aec45a7Smrg	      esac
86066aec45a7Smrg	    fi
8607300bf1aeSmrg	    if test prog = "$linkmode"; then
86086aec45a7Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
86096aec45a7Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
86106aec45a7Smrg	    else
86116aec45a7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86126aec45a7Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613300bf1aeSmrg	      if test yes != "$hardcode_direct" &&
8614300bf1aeSmrg		 test yes != "$hardcode_minus_L" &&
8615300bf1aeSmrg		 test yes = "$hardcode_shlibpath_var"; then
86166aec45a7Smrg		case :$finalize_shlibpath: in
86176aec45a7Smrg		*":$libdir:"*) ;;
8618aa9e3350Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
86196aec45a7Smrg		esac
86206aec45a7Smrg	      fi
86216aec45a7Smrg	    fi
86226aec45a7Smrg	  fi
86236aec45a7Smrg
8624300bf1aeSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
86256aec45a7Smrg	    add_shlibpath=
86266aec45a7Smrg	    add_dir=
86276aec45a7Smrg	    add=
86286aec45a7Smrg	    # Finalize command for both is simple: just hardcode it.
8629300bf1aeSmrg	    if test yes = "$hardcode_direct" &&
8630300bf1aeSmrg	       test no = "$hardcode_direct_absolute"; then
8631300bf1aeSmrg	      add=$libdir/$linklib
8632300bf1aeSmrg	    elif test yes = "$hardcode_minus_L"; then
8633300bf1aeSmrg	      add_dir=-L$libdir
8634300bf1aeSmrg	      add=-l$name
8635300bf1aeSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
86366aec45a7Smrg	      case :$finalize_shlibpath: in
86376aec45a7Smrg	      *":$libdir:"*) ;;
8638aa9e3350Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
86396aec45a7Smrg	      esac
8640300bf1aeSmrg	      add=-l$name
8641300bf1aeSmrg	    elif test yes = "$hardcode_automatic"; then
86426aec45a7Smrg	      if test -n "$inst_prefix_dir" &&
8643300bf1aeSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644300bf1aeSmrg		add=$inst_prefix_dir$libdir/$linklib
86456aec45a7Smrg	      else
8646300bf1aeSmrg		add=$libdir/$linklib
86476aec45a7Smrg	      fi
86486aec45a7Smrg	    else
86496aec45a7Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650300bf1aeSmrg	      add_dir=-L$libdir
86516aec45a7Smrg	      # Try looking first in the location we're being installed to.
86526aec45a7Smrg	      if test -n "$inst_prefix_dir"; then
86536aec45a7Smrg		case $libdir in
86546aec45a7Smrg		  [\\/]*)
8655aa9e3350Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
86566aec45a7Smrg		    ;;
86576aec45a7Smrg		esac
86586aec45a7Smrg	      fi
8659300bf1aeSmrg	      add=-l$name
86606aec45a7Smrg	    fi
86616aec45a7Smrg
8662300bf1aeSmrg	    if test prog = "$linkmode"; then
86636aec45a7Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
86646aec45a7Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
86656aec45a7Smrg	    else
86666aec45a7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86676aec45a7Smrg	      test -n "$add" && deplibs="$add $deplibs"
86686aec45a7Smrg	    fi
86696aec45a7Smrg	  fi
8670300bf1aeSmrg	elif test prog = "$linkmode"; then
86716aec45a7Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
86726aec45a7Smrg	  # is not unsupported.  This is valid on all known static and
86736aec45a7Smrg	  # shared platforms.
8674300bf1aeSmrg	  if test unsupported != "$hardcode_direct"; then
8675300bf1aeSmrg	    test -n "$old_library" && linklib=$old_library
86766aec45a7Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
86776aec45a7Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
86786aec45a7Smrg	  else
86796aec45a7Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
86806aec45a7Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
86816aec45a7Smrg	  fi
8682300bf1aeSmrg	elif test yes = "$build_libtool_libs"; then
86836aec45a7Smrg	  # Not a shared library
8684300bf1aeSmrg	  if test pass_all != "$deplibs_check_method"; then
86856aec45a7Smrg	    # We're trying link a shared library against a static one
86866aec45a7Smrg	    # but the system doesn't support it.
86876aec45a7Smrg
86886aec45a7Smrg	    # Just print a warning and add the library to dependency_libs so
86896aec45a7Smrg	    # that the program can be linked against the static library.
86906aec45a7Smrg	    echo
8691300bf1aeSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
86926aec45a7Smrg	    echo "*** I have the capability to make that library automatically link in when"
86936aec45a7Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
86946aec45a7Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695300bf1aeSmrg	    if test yes = "$module"; then
86966aec45a7Smrg	      echo "*** But as you try to build a module library, libtool will still create "
86976aec45a7Smrg	      echo "*** a static module, that should work as long as the dlopening application"
86986aec45a7Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
86996aec45a7Smrg	      if test -z "$global_symbol_pipe"; then
87006aec45a7Smrg		echo
87016aec45a7Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702300bf1aeSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
87036aec45a7Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704300bf1aeSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
87056aec45a7Smrg	      fi
8706300bf1aeSmrg	      if test no = "$build_old_libs"; then
87076aec45a7Smrg		build_libtool_libs=module
87086aec45a7Smrg		build_old_libs=yes
87096aec45a7Smrg	      else
87106aec45a7Smrg		build_libtool_libs=no
87116aec45a7Smrg	      fi
87126aec45a7Smrg	    fi
87136aec45a7Smrg	  else
87146aec45a7Smrg	    deplibs="$dir/$old_library $deplibs"
87156aec45a7Smrg	    link_static=yes
87166aec45a7Smrg	  fi
87176aec45a7Smrg	fi # link shared/static library?
87186aec45a7Smrg
8719300bf1aeSmrg	if test lib = "$linkmode"; then
87206aec45a7Smrg	  if test -n "$dependency_libs" &&
8721300bf1aeSmrg	     { test yes != "$hardcode_into_libs" ||
8722300bf1aeSmrg	       test yes = "$build_old_libs" ||
8723300bf1aeSmrg	       test yes = "$link_static"; }; then
87246aec45a7Smrg	    # Extract -R from dependency_libs
87256aec45a7Smrg	    temp_deplibs=
87266aec45a7Smrg	    for libdir in $dependency_libs; do
87276aec45a7Smrg	      case $libdir in
87286aec45a7Smrg	      -R*) func_stripname '-R' '' "$libdir"
87296aec45a7Smrg	           temp_xrpath=$func_stripname_result
87306aec45a7Smrg		   case " $xrpath " in
87316aec45a7Smrg		   *" $temp_xrpath "*) ;;
8732aa9e3350Smrg		   *) func_append xrpath " $temp_xrpath";;
87336aec45a7Smrg		   esac;;
8734aa9e3350Smrg	      *) func_append temp_deplibs " $libdir";;
87356aec45a7Smrg	      esac
87366aec45a7Smrg	    done
8737300bf1aeSmrg	    dependency_libs=$temp_deplibs
87386aec45a7Smrg	  fi
87396aec45a7Smrg
8740aa9e3350Smrg	  func_append newlib_search_path " $absdir"
87416aec45a7Smrg	  # Link against this library
8742300bf1aeSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
87436aec45a7Smrg	  # ... and its dependency_libs
87446aec45a7Smrg	  tmp_libs=
87456aec45a7Smrg	  for deplib in $dependency_libs; do
87466aec45a7Smrg	    newdependency_libs="$deplib $newdependency_libs"
8747aa9e3350Smrg	    case $deplib in
8748aa9e3350Smrg              -L*) func_stripname '-L' '' "$deplib"
8749aa9e3350Smrg                   func_resolve_sysroot "$func_stripname_result";;
8750aa9e3350Smrg              *) func_resolve_sysroot "$deplib" ;;
8751aa9e3350Smrg            esac
8752300bf1aeSmrg	    if $opt_preserve_dup_deps; then
87536aec45a7Smrg	      case "$tmp_libs " in
8754aa9e3350Smrg	      *" $func_resolve_sysroot_result "*)
8755aa9e3350Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
87566aec45a7Smrg	      esac
87576aec45a7Smrg	    fi
8758aa9e3350Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
87596aec45a7Smrg	  done
87606aec45a7Smrg
8761300bf1aeSmrg	  if test no != "$link_all_deplibs"; then
87626aec45a7Smrg	    # Add the search paths of all dependency libraries
87636aec45a7Smrg	    for deplib in $dependency_libs; do
87646aec45a7Smrg	      path=
87656aec45a7Smrg	      case $deplib in
8766300bf1aeSmrg	      -L*) path=$deplib ;;
87676aec45a7Smrg	      *.la)
8768aa9e3350Smrg	        func_resolve_sysroot "$deplib"
8769aa9e3350Smrg	        deplib=$func_resolve_sysroot_result
87706aec45a7Smrg	        func_dirname "$deplib" "" "."
8771aa9e3350Smrg		dir=$func_dirname_result
87726aec45a7Smrg		# We need an absolute path.
87736aec45a7Smrg		case $dir in
8774300bf1aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
87756aec45a7Smrg		*)
87766aec45a7Smrg		  absdir=`cd "$dir" && pwd`
87776aec45a7Smrg		  if test -z "$absdir"; then
8778300bf1aeSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779300bf1aeSmrg		    absdir=$dir
87806aec45a7Smrg		  fi
87816aec45a7Smrg		  ;;
87826aec45a7Smrg		esac
87836aec45a7Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
87846aec45a7Smrg		case $host in
87856aec45a7Smrg		*-*-darwin*)
87866aec45a7Smrg		  depdepl=
8787300bf1aeSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788300bf1aeSmrg		  if test -n "$deplibrary_names"; then
8789300bf1aeSmrg		    for tmp in $deplibrary_names; do
87906aec45a7Smrg		      depdepl=$tmp
87916aec45a7Smrg		    done
8792300bf1aeSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793300bf1aeSmrg		      depdepl=$absdir/$objdir/$depdepl
8794300bf1aeSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
87956aec45a7Smrg                      if test -z "$darwin_install_name"; then
8796300bf1aeSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
87976aec45a7Smrg                      fi
8798300bf1aeSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799300bf1aeSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
88006aec45a7Smrg		      path=
88016aec45a7Smrg		    fi
88026aec45a7Smrg		  fi
88036aec45a7Smrg		  ;;
88046aec45a7Smrg		*)
8805300bf1aeSmrg		  path=-L$absdir/$objdir
88066aec45a7Smrg		  ;;
88076aec45a7Smrg		esac
88086aec45a7Smrg		else
8809300bf1aeSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
88106aec45a7Smrg		  test -z "$libdir" && \
8811300bf1aeSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
88126aec45a7Smrg		  test "$absdir" != "$libdir" && \
8813300bf1aeSmrg		    func_warning "'$deplib' seems to be moved"
88146aec45a7Smrg
8815300bf1aeSmrg		  path=-L$absdir
88166aec45a7Smrg		fi
88176aec45a7Smrg		;;
88186aec45a7Smrg	      esac
88196aec45a7Smrg	      case " $deplibs " in
88206aec45a7Smrg	      *" $path "*) ;;
88216aec45a7Smrg	      *) deplibs="$path $deplibs" ;;
88226aec45a7Smrg	      esac
88236aec45a7Smrg	    done
88246aec45a7Smrg	  fi # link_all_deplibs != no
88256aec45a7Smrg	fi # linkmode = lib
88266aec45a7Smrg      done # for deplib in $libs
8827300bf1aeSmrg      if test link = "$pass"; then
8828300bf1aeSmrg	if test prog = "$linkmode"; then
88296aec45a7Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
88306aec45a7Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
88316aec45a7Smrg	else
88326aec45a7Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
88336aec45a7Smrg	fi
88346aec45a7Smrg      fi
8835300bf1aeSmrg      dependency_libs=$newdependency_libs
8836300bf1aeSmrg      if test dlpreopen = "$pass"; then
88376aec45a7Smrg	# Link the dlpreopened libraries before other libraries
88386aec45a7Smrg	for deplib in $save_deplibs; do
88396aec45a7Smrg	  deplibs="$deplib $deplibs"
88406aec45a7Smrg	done
88416aec45a7Smrg      fi
8842300bf1aeSmrg      if test dlopen != "$pass"; then
8843300bf1aeSmrg	test conv = "$pass" || {
88446aec45a7Smrg	  # Make sure lib_search_path contains only unique directories.
88456aec45a7Smrg	  lib_search_path=
88466aec45a7Smrg	  for dir in $newlib_search_path; do
88476aec45a7Smrg	    case "$lib_search_path " in
88486aec45a7Smrg	    *" $dir "*) ;;
8849aa9e3350Smrg	    *) func_append lib_search_path " $dir" ;;
88506aec45a7Smrg	    esac
88516aec45a7Smrg	  done
88526aec45a7Smrg	  newlib_search_path=
8853300bf1aeSmrg	}
88546aec45a7Smrg
8855300bf1aeSmrg	if test prog,link = "$linkmode,$pass"; then
88566aec45a7Smrg	  vars="compile_deplibs finalize_deplibs"
8857300bf1aeSmrg	else
8858300bf1aeSmrg	  vars=deplibs
88596aec45a7Smrg	fi
88606aec45a7Smrg	for var in $vars dependency_libs; do
88616aec45a7Smrg	  # Add libraries to $var in reverse order
88626aec45a7Smrg	  eval tmp_libs=\"\$$var\"
88636aec45a7Smrg	  new_libs=
88646aec45a7Smrg	  for deplib in $tmp_libs; do
88656aec45a7Smrg	    # FIXME: Pedantically, this is the right thing to do, so
88666aec45a7Smrg	    #        that some nasty dependency loop isn't accidentally
88676aec45a7Smrg	    #        broken:
88686aec45a7Smrg	    #new_libs="$deplib $new_libs"
88696aec45a7Smrg	    # Pragmatically, this seems to cause very few problems in
88706aec45a7Smrg	    # practice:
88716aec45a7Smrg	    case $deplib in
88726aec45a7Smrg	    -L*) new_libs="$deplib $new_libs" ;;
88736aec45a7Smrg	    -R*) ;;
88746aec45a7Smrg	    *)
88756aec45a7Smrg	      # And here is the reason: when a library appears more
88766aec45a7Smrg	      # than once as an explicit dependence of a library, or
88776aec45a7Smrg	      # is implicitly linked in more than once by the
88786aec45a7Smrg	      # compiler, it is considered special, and multiple
88796aec45a7Smrg	      # occurrences thereof are not removed.  Compare this
88806aec45a7Smrg	      # with having the same library being listed as a
88816aec45a7Smrg	      # dependency of multiple other libraries: in this case,
88826aec45a7Smrg	      # we know (pedantically, we assume) the library does not
88836aec45a7Smrg	      # need to be listed more than once, so we keep only the
88846aec45a7Smrg	      # last copy.  This is not always right, but it is rare
88856aec45a7Smrg	      # enough that we require users that really mean to play
88866aec45a7Smrg	      # such unportable linking tricks to link the library
88876aec45a7Smrg	      # using -Wl,-lname, so that libtool does not consider it
88886aec45a7Smrg	      # for duplicate removal.
88896aec45a7Smrg	      case " $specialdeplibs " in
88906aec45a7Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
88916aec45a7Smrg	      *)
88926aec45a7Smrg		case " $new_libs " in
88936aec45a7Smrg		*" $deplib "*) ;;
88946aec45a7Smrg		*) new_libs="$deplib $new_libs" ;;
88956aec45a7Smrg		esac
88966aec45a7Smrg		;;
88976aec45a7Smrg	      esac
88986aec45a7Smrg	      ;;
88996aec45a7Smrg	    esac
89006aec45a7Smrg	  done
89016aec45a7Smrg	  tmp_libs=
89026aec45a7Smrg	  for deplib in $new_libs; do
89036aec45a7Smrg	    case $deplib in
89046aec45a7Smrg	    -L*)
89056aec45a7Smrg	      case " $tmp_libs " in
89066aec45a7Smrg	      *" $deplib "*) ;;
8907aa9e3350Smrg	      *) func_append tmp_libs " $deplib" ;;
89086aec45a7Smrg	      esac
89096aec45a7Smrg	      ;;
8910aa9e3350Smrg	    *) func_append tmp_libs " $deplib" ;;
89116aec45a7Smrg	    esac
89126aec45a7Smrg	  done
89136aec45a7Smrg	  eval $var=\"$tmp_libs\"
89146aec45a7Smrg	done # for var
89156aec45a7Smrg      fi
8916300bf1aeSmrg
8917300bf1aeSmrg      # Add Sun CC postdeps if required:
8918300bf1aeSmrg      test CXX = "$tagname" && {
8919300bf1aeSmrg        case $host_os in
8920300bf1aeSmrg        linux*)
89212b2b4fcbSmrg          case `$CC -V 2>&1 | $SED 5q` in
8922300bf1aeSmrg          *Sun\ C*) # Sun C++ 5.9
8923300bf1aeSmrg            func_suncc_cstd_abi
8924300bf1aeSmrg
8925300bf1aeSmrg            if test no != "$suncc_use_cstd_abi"; then
8926300bf1aeSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8927300bf1aeSmrg            fi
8928300bf1aeSmrg            ;;
8929300bf1aeSmrg          esac
8930300bf1aeSmrg          ;;
8931300bf1aeSmrg
8932300bf1aeSmrg        solaris*)
8933300bf1aeSmrg          func_cc_basename "$CC"
8934300bf1aeSmrg          case $func_cc_basename_result in
8935300bf1aeSmrg          CC* | sunCC*)
8936300bf1aeSmrg            func_suncc_cstd_abi
8937300bf1aeSmrg
8938300bf1aeSmrg            if test no != "$suncc_use_cstd_abi"; then
8939300bf1aeSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8940300bf1aeSmrg            fi
8941300bf1aeSmrg            ;;
8942300bf1aeSmrg          esac
8943300bf1aeSmrg          ;;
8944300bf1aeSmrg        esac
8945300bf1aeSmrg      }
8946300bf1aeSmrg
89476aec45a7Smrg      # Last step: remove runtime libs from dependency_libs
89486aec45a7Smrg      # (they stay in deplibs)
89496aec45a7Smrg      tmp_libs=
8950300bf1aeSmrg      for i in $dependency_libs; do
89516aec45a7Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
89526aec45a7Smrg	*" $i "*)
8953300bf1aeSmrg	  i=
89546aec45a7Smrg	  ;;
89556aec45a7Smrg	esac
8956300bf1aeSmrg	if test -n "$i"; then
8957aa9e3350Smrg	  func_append tmp_libs " $i"
89586aec45a7Smrg	fi
89596aec45a7Smrg      done
89606aec45a7Smrg      dependency_libs=$tmp_libs
89616aec45a7Smrg    done # for pass
8962300bf1aeSmrg    if test prog = "$linkmode"; then
8963300bf1aeSmrg      dlfiles=$newdlfiles
89646aec45a7Smrg    fi
8965300bf1aeSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966300bf1aeSmrg      dlprefiles=$newdlprefiles
89676aec45a7Smrg    fi
89686aec45a7Smrg
89696aec45a7Smrg    case $linkmode in
89706aec45a7Smrg    oldlib)
8971300bf1aeSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972300bf1aeSmrg	func_warning "'-dlopen' is ignored for archives"
89736aec45a7Smrg      fi
89746aec45a7Smrg
89756aec45a7Smrg      case " $deplibs" in
89766aec45a7Smrg      *\ -l* | *\ -L*)
8977300bf1aeSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
89786aec45a7Smrg      esac
89796aec45a7Smrg
89806aec45a7Smrg      test -n "$rpath" && \
8981300bf1aeSmrg	func_warning "'-rpath' is ignored for archives"
89826aec45a7Smrg
89836aec45a7Smrg      test -n "$xrpath" && \
8984300bf1aeSmrg	func_warning "'-R' is ignored for archives"
89856aec45a7Smrg
89866aec45a7Smrg      test -n "$vinfo" && \
8987300bf1aeSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
89886aec45a7Smrg
89896aec45a7Smrg      test -n "$release" && \
8990300bf1aeSmrg	func_warning "'-release' is ignored for archives"
89916aec45a7Smrg
89926aec45a7Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993300bf1aeSmrg	func_warning "'-export-symbols' is ignored for archives"
89946aec45a7Smrg
89956aec45a7Smrg      # Now set the variables for building old libraries.
89966aec45a7Smrg      build_libtool_libs=no
8997300bf1aeSmrg      oldlibs=$output
8998aa9e3350Smrg      func_append objs "$old_deplibs"
89996aec45a7Smrg      ;;
90006aec45a7Smrg
90016aec45a7Smrg    lib)
9002300bf1aeSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
90036aec45a7Smrg      case $outputname in
90046aec45a7Smrg      lib*)
90056aec45a7Smrg	func_stripname 'lib' '.la' "$outputname"
90066aec45a7Smrg	name=$func_stripname_result
90076aec45a7Smrg	eval shared_ext=\"$shrext_cmds\"
90086aec45a7Smrg	eval libname=\"$libname_spec\"
90096aec45a7Smrg	;;
90106aec45a7Smrg      *)
9011300bf1aeSmrg	test no = "$module" \
9012300bf1aeSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
90136aec45a7Smrg
9014300bf1aeSmrg	if test no != "$need_lib_prefix"; then
90156aec45a7Smrg	  # Add the "lib" prefix for modules if required
90166aec45a7Smrg	  func_stripname '' '.la' "$outputname"
90176aec45a7Smrg	  name=$func_stripname_result
90186aec45a7Smrg	  eval shared_ext=\"$shrext_cmds\"
90196aec45a7Smrg	  eval libname=\"$libname_spec\"
90206aec45a7Smrg	else
90216aec45a7Smrg	  func_stripname '' '.la' "$outputname"
90226aec45a7Smrg	  libname=$func_stripname_result
90236aec45a7Smrg	fi
90246aec45a7Smrg	;;
90256aec45a7Smrg      esac
90266aec45a7Smrg
90276aec45a7Smrg      if test -n "$objs"; then
9028300bf1aeSmrg	if test pass_all != "$deplibs_check_method"; then
9029300bf1aeSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
90306aec45a7Smrg	else
90316aec45a7Smrg	  echo
90326aec45a7Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
90336aec45a7Smrg	  $ECHO "*** objects $objs is not portable!"
9034aa9e3350Smrg	  func_append libobjs " $objs"
90356aec45a7Smrg	fi
90366aec45a7Smrg      fi
90376aec45a7Smrg
9038300bf1aeSmrg      test no = "$dlself" \
9039300bf1aeSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
90406aec45a7Smrg
90416aec45a7Smrg      set dummy $rpath
90426aec45a7Smrg      shift
9043300bf1aeSmrg      test 1 -lt "$#" \
9044300bf1aeSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
90456aec45a7Smrg
9046300bf1aeSmrg      install_libdir=$1
90476aec45a7Smrg
90486aec45a7Smrg      oldlibs=
90496aec45a7Smrg      if test -z "$rpath"; then
9050300bf1aeSmrg	if test yes = "$build_libtool_libs"; then
90516aec45a7Smrg	  # Building a libtool convenience library.
9052300bf1aeSmrg	  # Some compilers have problems with a '.al' extension so
90536aec45a7Smrg	  # convenience libraries should have the same extension an
90546aec45a7Smrg	  # archive normally would.
90556aec45a7Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
90566aec45a7Smrg	  build_libtool_libs=convenience
90576aec45a7Smrg	  build_old_libs=yes
90586aec45a7Smrg	fi
90596aec45a7Smrg
90606aec45a7Smrg	test -n "$vinfo" && \
9061300bf1aeSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
90626aec45a7Smrg
90636aec45a7Smrg	test -n "$release" && \
9064300bf1aeSmrg	  func_warning "'-release' is ignored for convenience libraries"
90656aec45a7Smrg      else
90666aec45a7Smrg
90676aec45a7Smrg	# Parse the version information argument.
9068300bf1aeSmrg	save_ifs=$IFS; IFS=:
90696aec45a7Smrg	set dummy $vinfo 0 0 0
90706aec45a7Smrg	shift
9071300bf1aeSmrg	IFS=$save_ifs
90726aec45a7Smrg
90736aec45a7Smrg	test -n "$7" && \
9074300bf1aeSmrg	  func_fatal_help "too many parameters to '-version-info'"
90756aec45a7Smrg
90766aec45a7Smrg	# convert absolute version numbers to libtool ages
90776aec45a7Smrg	# this retains compatibility with .la files and attempts
90786aec45a7Smrg	# to make the code below a bit more comprehensible
90796aec45a7Smrg
90806aec45a7Smrg	case $vinfo_number in
90816aec45a7Smrg	yes)
9082300bf1aeSmrg	  number_major=$1
9083300bf1aeSmrg	  number_minor=$2
9084300bf1aeSmrg	  number_revision=$3
90856aec45a7Smrg	  #
90866aec45a7Smrg	  # There are really only two kinds -- those that
90876aec45a7Smrg	  # use the current revision as the major version
90886aec45a7Smrg	  # and those that subtract age and use age as
90896aec45a7Smrg	  # a minor version.  But, then there is irix
9090300bf1aeSmrg	  # that has an extra 1 added just for fun
90916aec45a7Smrg	  #
90926aec45a7Smrg	  case $version_type in
9093aa9e3350Smrg	  # correct linux to gnu/linux during the next big refactor
90942b2b4fcbSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
90956aec45a7Smrg	    func_arith $number_major + $number_minor
90966aec45a7Smrg	    current=$func_arith_result
9097300bf1aeSmrg	    age=$number_minor
9098300bf1aeSmrg	    revision=$number_revision
90996aec45a7Smrg	    ;;
9100300bf1aeSmrg	  freebsd-aout|qnx|sunos)
9101300bf1aeSmrg	    current=$number_major
9102300bf1aeSmrg	    revision=$number_minor
9103300bf1aeSmrg	    age=0
91046aec45a7Smrg	    ;;
91056aec45a7Smrg	  irix|nonstopux)
91066aec45a7Smrg	    func_arith $number_major + $number_minor
91076aec45a7Smrg	    current=$func_arith_result
9108300bf1aeSmrg	    age=$number_minor
9109300bf1aeSmrg	    revision=$number_minor
91106aec45a7Smrg	    lt_irix_increment=no
91116aec45a7Smrg	    ;;
91126aec45a7Smrg	  esac
91136aec45a7Smrg	  ;;
91146aec45a7Smrg	no)
9115300bf1aeSmrg	  current=$1
9116300bf1aeSmrg	  revision=$2
9117300bf1aeSmrg	  age=$3
91186aec45a7Smrg	  ;;
91196aec45a7Smrg	esac
91206aec45a7Smrg
91216aec45a7Smrg	# Check that each of the things are valid numbers.
91226aec45a7Smrg	case $current in
91236aec45a7Smrg	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]) ;;
91246aec45a7Smrg	*)
9125300bf1aeSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126300bf1aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
91276aec45a7Smrg	  ;;
91286aec45a7Smrg	esac
91296aec45a7Smrg
91306aec45a7Smrg	case $revision in
91316aec45a7Smrg	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]) ;;
91326aec45a7Smrg	*)
9133300bf1aeSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134300bf1aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
91356aec45a7Smrg	  ;;
91366aec45a7Smrg	esac
91376aec45a7Smrg
91386aec45a7Smrg	case $age in
91396aec45a7Smrg	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]) ;;
91406aec45a7Smrg	*)
9141300bf1aeSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9142300bf1aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
91436aec45a7Smrg	  ;;
91446aec45a7Smrg	esac
91456aec45a7Smrg
91466aec45a7Smrg	if test "$age" -gt "$current"; then
9147300bf1aeSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148300bf1aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
91496aec45a7Smrg	fi
91506aec45a7Smrg
91516aec45a7Smrg	# Calculate the version variables.
91526aec45a7Smrg	major=
91536aec45a7Smrg	versuffix=
91546aec45a7Smrg	verstring=
91556aec45a7Smrg	case $version_type in
91566aec45a7Smrg	none) ;;
91576aec45a7Smrg
91586aec45a7Smrg	darwin)
91596aec45a7Smrg	  # Like Linux, but with the current version available in
91606aec45a7Smrg	  # verstring for coding it into the library header
91616aec45a7Smrg	  func_arith $current - $age
91626aec45a7Smrg	  major=.$func_arith_result
9163300bf1aeSmrg	  versuffix=$major.$age.$revision
91646aec45a7Smrg	  # Darwin ld doesn't like 0 for these options...
91656aec45a7Smrg	  func_arith $current + 1
91666aec45a7Smrg	  minor_current=$func_arith_result
9167300bf1aeSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91686aec45a7Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169300bf1aeSmrg          # On Darwin other compilers
9170300bf1aeSmrg          case $CC in
9171300bf1aeSmrg              nagfor*)
9172300bf1aeSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173300bf1aeSmrg                  ;;
9174300bf1aeSmrg              *)
9175300bf1aeSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176300bf1aeSmrg                  ;;
9177300bf1aeSmrg          esac
91786aec45a7Smrg	  ;;
91796aec45a7Smrg
91806aec45a7Smrg	freebsd-aout)
9181300bf1aeSmrg	  major=.$current
9182300bf1aeSmrg	  versuffix=.$current.$revision
91836aec45a7Smrg	  ;;
91846aec45a7Smrg
91852b2b4fcbSmrg	freebsd-elf | midnightbsd-elf)
9186300bf1aeSmrg	  func_arith $current - $age
9187300bf1aeSmrg	  major=.$func_arith_result
9188300bf1aeSmrg	  versuffix=$major.$age.$revision
91896aec45a7Smrg	  ;;
91906aec45a7Smrg
91916aec45a7Smrg	irix | nonstopux)
9192300bf1aeSmrg	  if test no = "$lt_irix_increment"; then
91936aec45a7Smrg	    func_arith $current - $age
91946aec45a7Smrg	  else
91956aec45a7Smrg	    func_arith $current - $age + 1
91966aec45a7Smrg	  fi
91976aec45a7Smrg	  major=$func_arith_result
91986aec45a7Smrg
91996aec45a7Smrg	  case $version_type in
92006aec45a7Smrg	    nonstopux) verstring_prefix=nonstopux ;;
92016aec45a7Smrg	    *)         verstring_prefix=sgi ;;
92026aec45a7Smrg	  esac
9203300bf1aeSmrg	  verstring=$verstring_prefix$major.$revision
92046aec45a7Smrg
92056aec45a7Smrg	  # Add in all the interfaces that we are compatible with.
92066aec45a7Smrg	  loop=$revision
9207300bf1aeSmrg	  while test 0 -ne "$loop"; do
92086aec45a7Smrg	    func_arith $revision - $loop
92096aec45a7Smrg	    iface=$func_arith_result
92106aec45a7Smrg	    func_arith $loop - 1
92116aec45a7Smrg	    loop=$func_arith_result
9212300bf1aeSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
92136aec45a7Smrg	  done
92146aec45a7Smrg
9215300bf1aeSmrg	  # Before this point, $major must not contain '.'.
92166aec45a7Smrg	  major=.$major
9217300bf1aeSmrg	  versuffix=$major.$revision
92186aec45a7Smrg	  ;;
92196aec45a7Smrg
9220aa9e3350Smrg	linux) # correct to gnu/linux during the next big refactor
92216aec45a7Smrg	  func_arith $current - $age
92226aec45a7Smrg	  major=.$func_arith_result
9223300bf1aeSmrg	  versuffix=$major.$age.$revision
92246aec45a7Smrg	  ;;
92256aec45a7Smrg
92266aec45a7Smrg	osf)
92276aec45a7Smrg	  func_arith $current - $age
92286aec45a7Smrg	  major=.$func_arith_result
9229300bf1aeSmrg	  versuffix=.$current.$age.$revision
9230300bf1aeSmrg	  verstring=$current.$age.$revision
92316aec45a7Smrg
92326aec45a7Smrg	  # Add in all the interfaces that we are compatible with.
92336aec45a7Smrg	  loop=$age
9234300bf1aeSmrg	  while test 0 -ne "$loop"; do
92356aec45a7Smrg	    func_arith $current - $loop
92366aec45a7Smrg	    iface=$func_arith_result
92376aec45a7Smrg	    func_arith $loop - 1
92386aec45a7Smrg	    loop=$func_arith_result
9239300bf1aeSmrg	    verstring=$verstring:$iface.0
92406aec45a7Smrg	  done
92416aec45a7Smrg
92426aec45a7Smrg	  # Make executables depend on our current version.
9243300bf1aeSmrg	  func_append verstring ":$current.0"
92446aec45a7Smrg	  ;;
92456aec45a7Smrg
92466aec45a7Smrg	qnx)
9247300bf1aeSmrg	  major=.$current
9248300bf1aeSmrg	  versuffix=.$current
9249300bf1aeSmrg	  ;;
9250300bf1aeSmrg
9251300bf1aeSmrg	sco)
9252300bf1aeSmrg	  major=.$current
9253300bf1aeSmrg	  versuffix=.$current
92546aec45a7Smrg	  ;;
92556aec45a7Smrg
92566aec45a7Smrg	sunos)
9257300bf1aeSmrg	  major=.$current
9258300bf1aeSmrg	  versuffix=.$current.$revision
92596aec45a7Smrg	  ;;
92606aec45a7Smrg
92616aec45a7Smrg	windows)
92626aec45a7Smrg	  # Use '-' rather than '.', since we only want one
9263300bf1aeSmrg	  # extension on DOS 8.3 file systems.
92646aec45a7Smrg	  func_arith $current - $age
92656aec45a7Smrg	  major=$func_arith_result
9266300bf1aeSmrg	  versuffix=-$major
92676aec45a7Smrg	  ;;
92686aec45a7Smrg
92696aec45a7Smrg	*)
9270300bf1aeSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
92716aec45a7Smrg	  ;;
92726aec45a7Smrg	esac
92736aec45a7Smrg
92746aec45a7Smrg	# Clear the version info if we defaulted, and they specified a release.
92756aec45a7Smrg	if test -z "$vinfo" && test -n "$release"; then
92766aec45a7Smrg	  major=
92776aec45a7Smrg	  case $version_type in
92786aec45a7Smrg	  darwin)
92796aec45a7Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
92806aec45a7Smrg	    # problems, so we reset it completely
92816aec45a7Smrg	    verstring=
92826aec45a7Smrg	    ;;
92836aec45a7Smrg	  *)
9284300bf1aeSmrg	    verstring=0.0
92856aec45a7Smrg	    ;;
92866aec45a7Smrg	  esac
9287300bf1aeSmrg	  if test no = "$need_version"; then
92886aec45a7Smrg	    versuffix=
92896aec45a7Smrg	  else
9290300bf1aeSmrg	    versuffix=.0.0
92916aec45a7Smrg	  fi
92926aec45a7Smrg	fi
92936aec45a7Smrg
92946aec45a7Smrg	# Remove version info from name if versioning should be avoided
9295300bf1aeSmrg	if test yes,no = "$avoid_version,$need_version"; then
92966aec45a7Smrg	  major=
92976aec45a7Smrg	  versuffix=
9298300bf1aeSmrg	  verstring=
92996aec45a7Smrg	fi
93006aec45a7Smrg
93016aec45a7Smrg	# Check to see if the archive will have undefined symbols.
9302300bf1aeSmrg	if test yes = "$allow_undefined"; then
9303300bf1aeSmrg	  if test unsupported = "$allow_undefined_flag"; then
9304300bf1aeSmrg	    if test yes = "$build_old_libs"; then
9305300bf1aeSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306300bf1aeSmrg	      build_libtool_libs=no
9307300bf1aeSmrg	    else
9308300bf1aeSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309300bf1aeSmrg	    fi
93106aec45a7Smrg	  fi
93116aec45a7Smrg	else
93126aec45a7Smrg	  # Don't allow undefined symbols.
9313300bf1aeSmrg	  allow_undefined_flag=$no_undefined_flag
93146aec45a7Smrg	fi
93156aec45a7Smrg
93166aec45a7Smrg      fi
93176aec45a7Smrg
9318300bf1aeSmrg      func_generate_dlsyms "$libname" "$libname" :
9319aa9e3350Smrg      func_append libobjs " $symfileobj"
9320300bf1aeSmrg      test " " = "$libobjs" && libobjs=
93216aec45a7Smrg
9322300bf1aeSmrg      if test relink != "$opt_mode"; then
93236aec45a7Smrg	# Remove our outputs, but don't remove object files since they
93246aec45a7Smrg	# may have been created when compiling PIC objects.
93256aec45a7Smrg	removelist=
93266aec45a7Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
93276aec45a7Smrg	for p in $tempremovelist; do
93286aec45a7Smrg	  case $p in
93296aec45a7Smrg	    *.$objext | *.gcno)
93306aec45a7Smrg	       ;;
9331300bf1aeSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332300bf1aeSmrg	       if test -n "$precious_files_regex"; then
93336aec45a7Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
93346aec45a7Smrg		 then
93356aec45a7Smrg		   continue
93366aec45a7Smrg		 fi
93376aec45a7Smrg	       fi
9338aa9e3350Smrg	       func_append removelist " $p"
93396aec45a7Smrg	       ;;
93406aec45a7Smrg	    *) ;;
93416aec45a7Smrg	  esac
93426aec45a7Smrg	done
93436aec45a7Smrg	test -n "$removelist" && \
93446aec45a7Smrg	  func_show_eval "${RM}r \$removelist"
93456aec45a7Smrg      fi
93466aec45a7Smrg
93476aec45a7Smrg      # Now set the variables for building old libraries.
9348300bf1aeSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349aa9e3350Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
93506aec45a7Smrg
93516aec45a7Smrg	# Transform .lo files to .o files.
9352300bf1aeSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
93536aec45a7Smrg      fi
93546aec45a7Smrg
93556aec45a7Smrg      # Eliminate all temporary directories.
93566aec45a7Smrg      #for path in $notinst_path; do
93576aec45a7Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
93586aec45a7Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
93596aec45a7Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
93606aec45a7Smrg      #done
93616aec45a7Smrg
93626aec45a7Smrg      if test -n "$xrpath"; then
93636aec45a7Smrg	# If the user specified any rpath flags, then add them.
93646aec45a7Smrg	temp_xrpath=
93656aec45a7Smrg	for libdir in $xrpath; do
9366aa9e3350Smrg	  func_replace_sysroot "$libdir"
9367aa9e3350Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
93686aec45a7Smrg	  case "$finalize_rpath " in
93696aec45a7Smrg	  *" $libdir "*) ;;
9370aa9e3350Smrg	  *) func_append finalize_rpath " $libdir" ;;
93716aec45a7Smrg	  esac
93726aec45a7Smrg	done
9373300bf1aeSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
93746aec45a7Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
93756aec45a7Smrg	fi
93766aec45a7Smrg      fi
93776aec45a7Smrg
93786aec45a7Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379300bf1aeSmrg      old_dlfiles=$dlfiles
93806aec45a7Smrg      dlfiles=
93816aec45a7Smrg      for lib in $old_dlfiles; do
93826aec45a7Smrg	case " $dlprefiles $dlfiles " in
93836aec45a7Smrg	*" $lib "*) ;;
9384aa9e3350Smrg	*) func_append dlfiles " $lib" ;;
93856aec45a7Smrg	esac
93866aec45a7Smrg      done
93876aec45a7Smrg
93886aec45a7Smrg      # Make sure dlprefiles contains only unique files
9389300bf1aeSmrg      old_dlprefiles=$dlprefiles
93906aec45a7Smrg      dlprefiles=
93916aec45a7Smrg      for lib in $old_dlprefiles; do
93926aec45a7Smrg	case "$dlprefiles " in
93936aec45a7Smrg	*" $lib "*) ;;
9394aa9e3350Smrg	*) func_append dlprefiles " $lib" ;;
93956aec45a7Smrg	esac
93966aec45a7Smrg      done
93976aec45a7Smrg
9398300bf1aeSmrg      if test yes = "$build_libtool_libs"; then
93996aec45a7Smrg	if test -n "$rpath"; then
94006aec45a7Smrg	  case $host in
94016aec45a7Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
94026aec45a7Smrg	    # these systems don't actually have a c library (as such)!
94036aec45a7Smrg	    ;;
94046aec45a7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
94056aec45a7Smrg	    # Rhapsody C library is in the System framework
9406aa9e3350Smrg	    func_append deplibs " System.ltframework"
94076aec45a7Smrg	    ;;
94086aec45a7Smrg	  *-*-netbsd*)
94096aec45a7Smrg	    # Don't link with libc until the a.out ld.so is fixed.
94106aec45a7Smrg	    ;;
94112b2b4fcbSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
94126aec45a7Smrg	    # Do not include libc due to us having libc/libc_r.
94136aec45a7Smrg	    ;;
94146aec45a7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
94156aec45a7Smrg	    # Causes problems with __ctype
94166aec45a7Smrg	    ;;
94176aec45a7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
94186aec45a7Smrg	    # Compiler inserts libc in the correct place for threads to work
94196aec45a7Smrg	    ;;
94206aec45a7Smrg	  *)
94216aec45a7Smrg	    # Add libc to deplibs on all other systems if necessary.
9422300bf1aeSmrg	    if test yes = "$build_libtool_need_lc"; then
9423aa9e3350Smrg	      func_append deplibs " -lc"
94246aec45a7Smrg	    fi
94256aec45a7Smrg	    ;;
94266aec45a7Smrg	  esac
94276aec45a7Smrg	fi
94286aec45a7Smrg
94296aec45a7Smrg	# Transform deplibs into only deplibs that can be linked in shared.
94306aec45a7Smrg	name_save=$name
94316aec45a7Smrg	libname_save=$libname
94326aec45a7Smrg	release_save=$release
94336aec45a7Smrg	versuffix_save=$versuffix
94346aec45a7Smrg	major_save=$major
94356aec45a7Smrg	# I'm not sure if I'm treating the release correctly.  I think
94366aec45a7Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
94376aec45a7Smrg	# add it in twice.  Is that correct?
9438300bf1aeSmrg	release=
9439300bf1aeSmrg	versuffix=
9440300bf1aeSmrg	major=
94416aec45a7Smrg	newdeplibs=
94426aec45a7Smrg	droppeddeps=no
94436aec45a7Smrg	case $deplibs_check_method in
94446aec45a7Smrg	pass_all)
94456aec45a7Smrg	  # Don't check for shared/static.  Everything works.
94466aec45a7Smrg	  # This might be a little naive.  We might want to check
94476aec45a7Smrg	  # whether the library exists or not.  But this is on
94486aec45a7Smrg	  # osf3 & osf4 and I'm not really sure... Just
94496aec45a7Smrg	  # implementing what was already the behavior.
94506aec45a7Smrg	  newdeplibs=$deplibs
94516aec45a7Smrg	  ;;
94526aec45a7Smrg	test_compile)
94536aec45a7Smrg	  # This code stresses the "libraries are programs" paradigm to its
94546aec45a7Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
94556aec45a7Smrg	  # against the deplibs as a proxy for the library.  Then we can check
94566aec45a7Smrg	  # whether they linked in statically or dynamically with ldd.
94576aec45a7Smrg	  $opt_dry_run || $RM conftest.c
94586aec45a7Smrg	  cat > conftest.c <<EOF
94596aec45a7Smrg	  int main() { return 0; }
94606aec45a7SmrgEOF
94616aec45a7Smrg	  $opt_dry_run || $RM conftest
94626aec45a7Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
94636aec45a7Smrg	    ldd_output=`ldd conftest`
94646aec45a7Smrg	    for i in $deplibs; do
94656aec45a7Smrg	      case $i in
94666aec45a7Smrg	      -l*)
94676aec45a7Smrg		func_stripname -l '' "$i"
94686aec45a7Smrg		name=$func_stripname_result
9469300bf1aeSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94706aec45a7Smrg		  case " $predeps $postdeps " in
94716aec45a7Smrg		  *" $i "*)
9472aa9e3350Smrg		    func_append newdeplibs " $i"
9473300bf1aeSmrg		    i=
94746aec45a7Smrg		    ;;
94756aec45a7Smrg		  esac
94766aec45a7Smrg		fi
9477300bf1aeSmrg		if test -n "$i"; then
94786aec45a7Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
94796aec45a7Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
94806aec45a7Smrg		  set dummy $deplib_matches; shift
94816aec45a7Smrg		  deplib_match=$1
9482300bf1aeSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483aa9e3350Smrg		    func_append newdeplibs " $i"
94846aec45a7Smrg		  else
94856aec45a7Smrg		    droppeddeps=yes
94866aec45a7Smrg		    echo
94876aec45a7Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
94886aec45a7Smrg		    echo "*** I have the capability to make that library automatically link in when"
94896aec45a7Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
94906aec45a7Smrg		    echo "*** shared version of the library, which I believe you do not have"
94916aec45a7Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
94926aec45a7Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
94936aec45a7Smrg		  fi
94946aec45a7Smrg		fi
94956aec45a7Smrg		;;
94966aec45a7Smrg	      *)
9497aa9e3350Smrg		func_append newdeplibs " $i"
94986aec45a7Smrg		;;
94996aec45a7Smrg	      esac
95006aec45a7Smrg	    done
95016aec45a7Smrg	  else
95026aec45a7Smrg	    # Error occurred in the first compile.  Let's try to salvage
95036aec45a7Smrg	    # the situation: Compile a separate program for each library.
95046aec45a7Smrg	    for i in $deplibs; do
95056aec45a7Smrg	      case $i in
95066aec45a7Smrg	      -l*)
95076aec45a7Smrg		func_stripname -l '' "$i"
95086aec45a7Smrg		name=$func_stripname_result
95096aec45a7Smrg		$opt_dry_run || $RM conftest
95106aec45a7Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
95116aec45a7Smrg		  ldd_output=`ldd conftest`
9512300bf1aeSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95136aec45a7Smrg		    case " $predeps $postdeps " in
95146aec45a7Smrg		    *" $i "*)
9515aa9e3350Smrg		      func_append newdeplibs " $i"
9516300bf1aeSmrg		      i=
95176aec45a7Smrg		      ;;
95186aec45a7Smrg		    esac
95196aec45a7Smrg		  fi
9520300bf1aeSmrg		  if test -n "$i"; then
95216aec45a7Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
95226aec45a7Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
95236aec45a7Smrg		    set dummy $deplib_matches; shift
95246aec45a7Smrg		    deplib_match=$1
9525300bf1aeSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526aa9e3350Smrg		      func_append newdeplibs " $i"
95276aec45a7Smrg		    else
95286aec45a7Smrg		      droppeddeps=yes
95296aec45a7Smrg		      echo
95306aec45a7Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
95316aec45a7Smrg		      echo "*** I have the capability to make that library automatically link in when"
95326aec45a7Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
95336aec45a7Smrg		      echo "*** shared version of the library, which you do not appear to have"
95346aec45a7Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
95356aec45a7Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
95366aec45a7Smrg		    fi
95376aec45a7Smrg		  fi
95386aec45a7Smrg		else
95396aec45a7Smrg		  droppeddeps=yes
95406aec45a7Smrg		  echo
95416aec45a7Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
95426aec45a7Smrg		  echo "*** make it link in!  You will probably need to install it or some"
95436aec45a7Smrg		  echo "*** library that it depends on before this library will be fully"
95446aec45a7Smrg		  echo "*** functional.  Installing it before continuing would be even better."
95456aec45a7Smrg		fi
95466aec45a7Smrg		;;
95476aec45a7Smrg	      *)
9548aa9e3350Smrg		func_append newdeplibs " $i"
95496aec45a7Smrg		;;
95506aec45a7Smrg	      esac
95516aec45a7Smrg	    done
95526aec45a7Smrg	  fi
95536aec45a7Smrg	  ;;
95546aec45a7Smrg	file_magic*)
95556aec45a7Smrg	  set dummy $deplibs_check_method; shift
95566aec45a7Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
95576aec45a7Smrg	  for a_deplib in $deplibs; do
95586aec45a7Smrg	    case $a_deplib in
95596aec45a7Smrg	    -l*)
95606aec45a7Smrg	      func_stripname -l '' "$a_deplib"
95616aec45a7Smrg	      name=$func_stripname_result
9562300bf1aeSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95636aec45a7Smrg		case " $predeps $postdeps " in
95646aec45a7Smrg		*" $a_deplib "*)
9565aa9e3350Smrg		  func_append newdeplibs " $a_deplib"
9566300bf1aeSmrg		  a_deplib=
95676aec45a7Smrg		  ;;
95686aec45a7Smrg		esac
95696aec45a7Smrg	      fi
9570300bf1aeSmrg	      if test -n "$a_deplib"; then
95716aec45a7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572aa9e3350Smrg		if test -n "$file_magic_glob"; then
9573aa9e3350Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574aa9e3350Smrg		else
9575aa9e3350Smrg		  libnameglob=$libname
9576aa9e3350Smrg		fi
9577300bf1aeSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
95786aec45a7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579300bf1aeSmrg		  if test yes = "$want_nocaseglob"; then
9580aa9e3350Smrg		    shopt -s nocaseglob
9581aa9e3350Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582aa9e3350Smrg		    $nocaseglob
9583aa9e3350Smrg		  else
9584aa9e3350Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585aa9e3350Smrg		  fi
95866aec45a7Smrg		  for potent_lib in $potential_libs; do
95876aec45a7Smrg		      # Follow soft links.
95886aec45a7Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
95896aec45a7Smrg			 $GREP " -> " >/dev/null; then
95906aec45a7Smrg			continue
95916aec45a7Smrg		      fi
95926aec45a7Smrg		      # The statement above tries to avoid entering an
95936aec45a7Smrg		      # endless loop below, in case of cyclic links.
95946aec45a7Smrg		      # We might still enter an endless loop, since a link
95956aec45a7Smrg		      # loop can be closed while we follow links,
95966aec45a7Smrg		      # but so what?
9597300bf1aeSmrg		      potlib=$potent_lib
95986aec45a7Smrg		      while test -h "$potlib" 2>/dev/null; do
9599300bf1aeSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
96006aec45a7Smrg			case $potliblink in
9601300bf1aeSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602300bf1aeSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
96036aec45a7Smrg			esac
96046aec45a7Smrg		      done
96056aec45a7Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
96066aec45a7Smrg			 $SED -e 10q |
96076aec45a7Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608aa9e3350Smrg			func_append newdeplibs " $a_deplib"
9609300bf1aeSmrg			a_deplib=
96106aec45a7Smrg			break 2
96116aec45a7Smrg		      fi
96126aec45a7Smrg		  done
96136aec45a7Smrg		done
96146aec45a7Smrg	      fi
9615300bf1aeSmrg	      if test -n "$a_deplib"; then
96166aec45a7Smrg		droppeddeps=yes
96176aec45a7Smrg		echo
96186aec45a7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96196aec45a7Smrg		echo "*** I have the capability to make that library automatically link in when"
96206aec45a7Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96216aec45a7Smrg		echo "*** shared version of the library, which you do not appear to have"
96226aec45a7Smrg		echo "*** because I did check the linker path looking for a file starting"
9623300bf1aeSmrg		if test -z "$potlib"; then
96246aec45a7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
96256aec45a7Smrg		else
96266aec45a7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96276aec45a7Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
96286aec45a7Smrg		fi
96296aec45a7Smrg	      fi
96306aec45a7Smrg	      ;;
96316aec45a7Smrg	    *)
96326aec45a7Smrg	      # Add a -L argument.
9633aa9e3350Smrg	      func_append newdeplibs " $a_deplib"
96346aec45a7Smrg	      ;;
96356aec45a7Smrg	    esac
96366aec45a7Smrg	  done # Gone through all deplibs.
96376aec45a7Smrg	  ;;
96386aec45a7Smrg	match_pattern*)
96396aec45a7Smrg	  set dummy $deplibs_check_method; shift
96406aec45a7Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
96416aec45a7Smrg	  for a_deplib in $deplibs; do
96426aec45a7Smrg	    case $a_deplib in
96436aec45a7Smrg	    -l*)
96446aec45a7Smrg	      func_stripname -l '' "$a_deplib"
96456aec45a7Smrg	      name=$func_stripname_result
9646300bf1aeSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96476aec45a7Smrg		case " $predeps $postdeps " in
96486aec45a7Smrg		*" $a_deplib "*)
9649aa9e3350Smrg		  func_append newdeplibs " $a_deplib"
9650300bf1aeSmrg		  a_deplib=
96516aec45a7Smrg		  ;;
96526aec45a7Smrg		esac
96536aec45a7Smrg	      fi
9654300bf1aeSmrg	      if test -n "$a_deplib"; then
96556aec45a7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96566aec45a7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
96576aec45a7Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
96586aec45a7Smrg		  for potent_lib in $potential_libs; do
9659300bf1aeSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
96606aec45a7Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
96616aec45a7Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662aa9e3350Smrg		      func_append newdeplibs " $a_deplib"
9663300bf1aeSmrg		      a_deplib=
96646aec45a7Smrg		      break 2
96656aec45a7Smrg		    fi
96666aec45a7Smrg		  done
96676aec45a7Smrg		done
96686aec45a7Smrg	      fi
9669300bf1aeSmrg	      if test -n "$a_deplib"; then
96706aec45a7Smrg		droppeddeps=yes
96716aec45a7Smrg		echo
96726aec45a7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96736aec45a7Smrg		echo "*** I have the capability to make that library automatically link in when"
96746aec45a7Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96756aec45a7Smrg		echo "*** shared version of the library, which you do not appear to have"
96766aec45a7Smrg		echo "*** because I did check the linker path looking for a file starting"
9677300bf1aeSmrg		if test -z "$potlib"; then
96786aec45a7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
96796aec45a7Smrg		else
96806aec45a7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96816aec45a7Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
96826aec45a7Smrg		fi
96836aec45a7Smrg	      fi
96846aec45a7Smrg	      ;;
96856aec45a7Smrg	    *)
96866aec45a7Smrg	      # Add a -L argument.
9687aa9e3350Smrg	      func_append newdeplibs " $a_deplib"
96886aec45a7Smrg	      ;;
96896aec45a7Smrg	    esac
96906aec45a7Smrg	  done # Gone through all deplibs.
96916aec45a7Smrg	  ;;
96926aec45a7Smrg	none | unknown | *)
9693300bf1aeSmrg	  newdeplibs=
96946aec45a7Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695300bf1aeSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696300bf1aeSmrg	    for i in $predeps $postdeps; do
96976aec45a7Smrg	      # can't use Xsed below, because $i might contain '/'
9698300bf1aeSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
96996aec45a7Smrg	    done
97006aec45a7Smrg	  fi
97016aec45a7Smrg	  case $tmp_deplibs in
97026aec45a7Smrg	  *[!\	\ ]*)
97036aec45a7Smrg	    echo
9704300bf1aeSmrg	    if test none = "$deplibs_check_method"; then
97056aec45a7Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
97066aec45a7Smrg	    else
97076aec45a7Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
97086aec45a7Smrg	    fi
97096aec45a7Smrg	    echo "*** All declared inter-library dependencies are being dropped."
97106aec45a7Smrg	    droppeddeps=yes
97116aec45a7Smrg	    ;;
97126aec45a7Smrg	  esac
97136aec45a7Smrg	  ;;
97146aec45a7Smrg	esac
97156aec45a7Smrg	versuffix=$versuffix_save
97166aec45a7Smrg	major=$major_save
97176aec45a7Smrg	release=$release_save
97186aec45a7Smrg	libname=$libname_save
97196aec45a7Smrg	name=$name_save
97206aec45a7Smrg
97216aec45a7Smrg	case $host in
97226aec45a7Smrg	*-*-rhapsody* | *-*-darwin1.[012])
97236aec45a7Smrg	  # On Rhapsody replace the C library with the System framework
97246aec45a7Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
97256aec45a7Smrg	  ;;
97266aec45a7Smrg	esac
97276aec45a7Smrg
9728300bf1aeSmrg	if test yes = "$droppeddeps"; then
9729300bf1aeSmrg	  if test yes = "$module"; then
97306aec45a7Smrg	    echo
97316aec45a7Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
97326aec45a7Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
97336aec45a7Smrg	    echo "*** a static module, that should work as long as the dlopening"
97346aec45a7Smrg	    echo "*** application is linked with the -dlopen flag."
97356aec45a7Smrg	    if test -z "$global_symbol_pipe"; then
97366aec45a7Smrg	      echo
97376aec45a7Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738300bf1aeSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
97396aec45a7Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740300bf1aeSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
97416aec45a7Smrg	    fi
9742300bf1aeSmrg	    if test no = "$build_old_libs"; then
9743300bf1aeSmrg	      oldlibs=$output_objdir/$libname.$libext
97446aec45a7Smrg	      build_libtool_libs=module
97456aec45a7Smrg	      build_old_libs=yes
97466aec45a7Smrg	    else
97476aec45a7Smrg	      build_libtool_libs=no
97486aec45a7Smrg	    fi
97496aec45a7Smrg	  else
97506aec45a7Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
97516aec45a7Smrg	    echo "*** automatically added whenever a program is linked with this library"
97526aec45a7Smrg	    echo "*** or is declared to -dlopen it."
97536aec45a7Smrg
9754300bf1aeSmrg	    if test no = "$allow_undefined"; then
97556aec45a7Smrg	      echo
97566aec45a7Smrg	      echo "*** Since this library must not contain undefined symbols,"
97576aec45a7Smrg	      echo "*** because either the platform does not support them or"
97586aec45a7Smrg	      echo "*** it was explicitly requested with -no-undefined,"
97596aec45a7Smrg	      echo "*** libtool will only create a static version of it."
9760300bf1aeSmrg	      if test no = "$build_old_libs"; then
9761300bf1aeSmrg		oldlibs=$output_objdir/$libname.$libext
97626aec45a7Smrg		build_libtool_libs=module
97636aec45a7Smrg		build_old_libs=yes
97646aec45a7Smrg	      else
97656aec45a7Smrg		build_libtool_libs=no
97666aec45a7Smrg	      fi
97676aec45a7Smrg	    fi
97686aec45a7Smrg	  fi
97696aec45a7Smrg	fi
97706aec45a7Smrg	# Done checking deplibs!
97716aec45a7Smrg	deplibs=$newdeplibs
97726aec45a7Smrg      fi
97736aec45a7Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
97746aec45a7Smrg      case $host in
97756aec45a7Smrg	*-*-darwin*)
97766aec45a7Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97776aec45a7Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97786aec45a7Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97796aec45a7Smrg	  ;;
97806aec45a7Smrg      esac
97816aec45a7Smrg
97826aec45a7Smrg      # move library search paths that coincide with paths to not yet
97836aec45a7Smrg      # installed libraries to the beginning of the library search list
97846aec45a7Smrg      new_libs=
97856aec45a7Smrg      for path in $notinst_path; do
97866aec45a7Smrg	case " $new_libs " in
97876aec45a7Smrg	*" -L$path/$objdir "*) ;;
97886aec45a7Smrg	*)
97896aec45a7Smrg	  case " $deplibs " in
97906aec45a7Smrg	  *" -L$path/$objdir "*)
9791aa9e3350Smrg	    func_append new_libs " -L$path/$objdir" ;;
97926aec45a7Smrg	  esac
97936aec45a7Smrg	  ;;
97946aec45a7Smrg	esac
97956aec45a7Smrg      done
97966aec45a7Smrg      for deplib in $deplibs; do
97976aec45a7Smrg	case $deplib in
97986aec45a7Smrg	-L*)
97996aec45a7Smrg	  case " $new_libs " in
98006aec45a7Smrg	  *" $deplib "*) ;;
9801aa9e3350Smrg	  *) func_append new_libs " $deplib" ;;
98026aec45a7Smrg	  esac
98036aec45a7Smrg	  ;;
9804aa9e3350Smrg	*) func_append new_libs " $deplib" ;;
98056aec45a7Smrg	esac
98066aec45a7Smrg      done
9807300bf1aeSmrg      deplibs=$new_libs
98086aec45a7Smrg
98096aec45a7Smrg      # All the library-specific variables (install_libdir is set above).
98106aec45a7Smrg      library_names=
98116aec45a7Smrg      old_library=
98126aec45a7Smrg      dlname=
98136aec45a7Smrg
98146aec45a7Smrg      # Test again, we may have decided not to build it any more
9815300bf1aeSmrg      if test yes = "$build_libtool_libs"; then
9816300bf1aeSmrg	# Remove $wl instances when linking with ld.
9817aa9e3350Smrg	# FIXME: should test the right _cmds variable.
9818aa9e3350Smrg	case $archive_cmds in
9819aa9e3350Smrg	  *\$LD\ *) wl= ;;
9820aa9e3350Smrg        esac
9821300bf1aeSmrg	if test yes = "$hardcode_into_libs"; then
98226aec45a7Smrg	  # Hardcode the library paths
98236aec45a7Smrg	  hardcode_libdirs=
98246aec45a7Smrg	  dep_rpath=
9825300bf1aeSmrg	  rpath=$finalize_rpath
9826300bf1aeSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
98276aec45a7Smrg	  for libdir in $rpath; do
98286aec45a7Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
98296aec45a7Smrg	      if test -n "$hardcode_libdir_separator"; then
9830aa9e3350Smrg		func_replace_sysroot "$libdir"
9831aa9e3350Smrg		libdir=$func_replace_sysroot_result
98326aec45a7Smrg		if test -z "$hardcode_libdirs"; then
9833300bf1aeSmrg		  hardcode_libdirs=$libdir
98346aec45a7Smrg		else
98356aec45a7Smrg		  # Just accumulate the unique libdirs.
98366aec45a7Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
98376aec45a7Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
98386aec45a7Smrg		    ;;
98396aec45a7Smrg		  *)
9840aa9e3350Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
98416aec45a7Smrg		    ;;
98426aec45a7Smrg		  esac
98436aec45a7Smrg		fi
98446aec45a7Smrg	      else
98456aec45a7Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846aa9e3350Smrg		func_append dep_rpath " $flag"
98476aec45a7Smrg	      fi
98486aec45a7Smrg	    elif test -n "$runpath_var"; then
98496aec45a7Smrg	      case "$perm_rpath " in
98506aec45a7Smrg	      *" $libdir "*) ;;
9851aa9e3350Smrg	      *) func_append perm_rpath " $libdir" ;;
98526aec45a7Smrg	      esac
98536aec45a7Smrg	    fi
98546aec45a7Smrg	  done
98556aec45a7Smrg	  # Substitute the hardcoded libdirs into the rpath.
98566aec45a7Smrg	  if test -n "$hardcode_libdir_separator" &&
98576aec45a7Smrg	     test -n "$hardcode_libdirs"; then
9858300bf1aeSmrg	    libdir=$hardcode_libdirs
9859aa9e3350Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
98606aec45a7Smrg	  fi
98616aec45a7Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
98626aec45a7Smrg	    # We should set the runpath_var.
98636aec45a7Smrg	    rpath=
98646aec45a7Smrg	    for dir in $perm_rpath; do
9865aa9e3350Smrg	      func_append rpath "$dir:"
98666aec45a7Smrg	    done
98676aec45a7Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
98686aec45a7Smrg	  fi
98696aec45a7Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
98706aec45a7Smrg	fi
9871ab47cfaaSmrg
9872300bf1aeSmrg	shlibpath=$finalize_shlibpath
9873300bf1aeSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
98746aec45a7Smrg	if test -n "$shlibpath"; then
98756aec45a7Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
98766aec45a7Smrg	fi
9877ab47cfaaSmrg
98786aec45a7Smrg	# Get the real and link names of the library.
98796aec45a7Smrg	eval shared_ext=\"$shrext_cmds\"
98806aec45a7Smrg	eval library_names=\"$library_names_spec\"
98816aec45a7Smrg	set dummy $library_names
98826aec45a7Smrg	shift
9883300bf1aeSmrg	realname=$1
98846aec45a7Smrg	shift
9885ab47cfaaSmrg
98866aec45a7Smrg	if test -n "$soname_spec"; then
98876aec45a7Smrg	  eval soname=\"$soname_spec\"
98886aec45a7Smrg	else
9889300bf1aeSmrg	  soname=$realname
98906aec45a7Smrg	fi
98916aec45a7Smrg	if test -z "$dlname"; then
98926aec45a7Smrg	  dlname=$soname
98936aec45a7Smrg	fi
9894ab47cfaaSmrg
9895300bf1aeSmrg	lib=$output_objdir/$realname
98966aec45a7Smrg	linknames=
98976aec45a7Smrg	for link
98986aec45a7Smrg	do
9899aa9e3350Smrg	  func_append linknames " $link"
99006aec45a7Smrg	done
9901ab47cfaaSmrg
99026aec45a7Smrg	# Use standard objects if they are pic
99036aec45a7Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
99046aec45a7Smrg	test "X$libobjs" = "X " && libobjs=
9905ab47cfaaSmrg
99066aec45a7Smrg	delfiles=
99076aec45a7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99086aec45a7Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909300bf1aeSmrg	  export_symbols=$output_objdir/$libname.uexp
9910aa9e3350Smrg	  func_append delfiles " $export_symbols"
99116aec45a7Smrg	fi
9912ab47cfaaSmrg
99136aec45a7Smrg	orig_export_symbols=
99146aec45a7Smrg	case $host_os in
99156aec45a7Smrg	cygwin* | mingw* | cegcc*)
99166aec45a7Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
99176aec45a7Smrg	    # exporting using user supplied symfile
9918300bf1aeSmrg	    func_dll_def_p "$export_symbols" || {
99196aec45a7Smrg	      # and it's NOT already a .def file. Must figure out
99206aec45a7Smrg	      # which of the given symbols are data symbols and tag
99216aec45a7Smrg	      # them as such. So, trigger use of export_symbols_cmds.
99226aec45a7Smrg	      # export_symbols gets reassigned inside the "prepare
99236aec45a7Smrg	      # the list of exported symbols" if statement, so the
99246aec45a7Smrg	      # include_expsyms logic still works.
9925300bf1aeSmrg	      orig_export_symbols=$export_symbols
99266aec45a7Smrg	      export_symbols=
99276aec45a7Smrg	      always_export_symbols=yes
9928300bf1aeSmrg	    }
99296aec45a7Smrg	  fi
99306aec45a7Smrg	  ;;
99316aec45a7Smrg	esac
9932ab47cfaaSmrg
99336aec45a7Smrg	# Prepare the list of exported symbols
99346aec45a7Smrg	if test -z "$export_symbols"; then
9935300bf1aeSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936300bf1aeSmrg	    func_verbose "generating symbol list for '$libname.la'"
9937300bf1aeSmrg	    export_symbols=$output_objdir/$libname.exp
99386aec45a7Smrg	    $opt_dry_run || $RM $export_symbols
99396aec45a7Smrg	    cmds=$export_symbols_cmds
9940300bf1aeSmrg	    save_ifs=$IFS; IFS='~'
9941aa9e3350Smrg	    for cmd1 in $cmds; do
9942300bf1aeSmrg	      IFS=$save_ifs
9943aa9e3350Smrg	      # Take the normal branch if the nm_file_list_spec branch
9944aa9e3350Smrg	      # doesn't work or if tool conversion is not needed.
9945aa9e3350Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946aa9e3350Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947aa9e3350Smrg		  try_normal_branch=yes
9948aa9e3350Smrg		  eval cmd=\"$cmd1\"
9949aa9e3350Smrg		  func_len " $cmd"
9950aa9e3350Smrg		  len=$func_len_result
9951aa9e3350Smrg		  ;;
9952aa9e3350Smrg		*)
9953aa9e3350Smrg		  try_normal_branch=no
9954aa9e3350Smrg		  ;;
9955aa9e3350Smrg	      esac
9956300bf1aeSmrg	      if test yes = "$try_normal_branch" \
9957aa9e3350Smrg		 && { test "$len" -lt "$max_cmd_len" \
9958aa9e3350Smrg		      || test "$max_cmd_len" -le -1; }
9959aa9e3350Smrg	      then
9960aa9e3350Smrg		func_show_eval "$cmd" 'exit $?'
9961aa9e3350Smrg		skipped_export=false
9962aa9e3350Smrg	      elif test -n "$nm_file_list_spec"; then
9963aa9e3350Smrg		func_basename "$output"
9964aa9e3350Smrg		output_la=$func_basename_result
9965aa9e3350Smrg		save_libobjs=$libobjs
9966aa9e3350Smrg		save_output=$output
9967300bf1aeSmrg		output=$output_objdir/$output_la.nm
9968aa9e3350Smrg		func_to_tool_file "$output"
9969aa9e3350Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970aa9e3350Smrg		func_append delfiles " $output"
9971aa9e3350Smrg		func_verbose "creating $NM input file list: $output"
9972aa9e3350Smrg		for obj in $save_libobjs; do
9973aa9e3350Smrg		  func_to_tool_file "$obj"
9974aa9e3350Smrg		  $ECHO "$func_to_tool_file_result"
9975aa9e3350Smrg		done > "$output"
9976aa9e3350Smrg		eval cmd=\"$cmd1\"
99776aec45a7Smrg		func_show_eval "$cmd" 'exit $?'
9978aa9e3350Smrg		output=$save_output
9979aa9e3350Smrg		libobjs=$save_libobjs
99806aec45a7Smrg		skipped_export=false
99816aec45a7Smrg	      else
99826aec45a7Smrg		# The command line is too long to execute in one step.
99836aec45a7Smrg		func_verbose "using reloadable object file for export list..."
99846aec45a7Smrg		skipped_export=:
99856aec45a7Smrg		# Break out early, otherwise skipped_export may be
99866aec45a7Smrg		# set to false by a later but shorter cmd.
99876aec45a7Smrg		break
99886aec45a7Smrg	      fi
99896aec45a7Smrg	    done
9990300bf1aeSmrg	    IFS=$save_ifs
9991300bf1aeSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
99926aec45a7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99936aec45a7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99946aec45a7Smrg	    fi
99956aec45a7Smrg	  fi
99966aec45a7Smrg	fi
9997ab47cfaaSmrg
99986aec45a7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999300bf1aeSmrg	  tmp_export_symbols=$export_symbols
10000300bf1aeSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
100016aec45a7Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
100026aec45a7Smrg	fi
10003ab47cfaaSmrg
10004300bf1aeSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
100056aec45a7Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006300bf1aeSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100076aec45a7Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008300bf1aeSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
100096aec45a7Smrg	  # though. Also, the filter scales superlinearly with the number of
100106aec45a7Smrg	  # global variables. join(1) would be nice here, but unfortunately
100116aec45a7Smrg	  # isn't a blessed tool.
100126aec45a7Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013aa9e3350Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100146aec45a7Smrg	  export_symbols=$output_objdir/$libname.def
100156aec45a7Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100161473d951Smrg	fi
10017ab47cfaaSmrg
100186aec45a7Smrg	tmp_deplibs=
100196aec45a7Smrg	for test_deplib in $deplibs; do
100206aec45a7Smrg	  case " $convenience " in
100216aec45a7Smrg	  *" $test_deplib "*) ;;
100226aec45a7Smrg	  *)
10023aa9e3350Smrg	    func_append tmp_deplibs " $test_deplib"
100246aec45a7Smrg	    ;;
100256aec45a7Smrg	  esac
100266aec45a7Smrg	done
10027300bf1aeSmrg	deplibs=$tmp_deplibs
10028ab47cfaaSmrg
100296aec45a7Smrg	if test -n "$convenience"; then
100306aec45a7Smrg	  if test -n "$whole_archive_flag_spec" &&
10031300bf1aeSmrg	    test yes = "$compiler_needs_object" &&
100326aec45a7Smrg	    test -z "$libobjs"; then
100336aec45a7Smrg	    # extract the archives, so we have objects to list.
100346aec45a7Smrg	    # TODO: could optimize this to just extract one archive.
100356aec45a7Smrg	    whole_archive_flag_spec=
100366aec45a7Smrg	  fi
100376aec45a7Smrg	  if test -n "$whole_archive_flag_spec"; then
100386aec45a7Smrg	    save_libobjs=$libobjs
100396aec45a7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100406aec45a7Smrg	    test "X$libobjs" = "X " && libobjs=
100416aec45a7Smrg	  else
10042300bf1aeSmrg	    gentop=$output_objdir/${outputname}x
10043aa9e3350Smrg	    func_append generated " $gentop"
10044ab47cfaaSmrg
100456aec45a7Smrg	    func_extract_archives $gentop $convenience
10046aa9e3350Smrg	    func_append libobjs " $func_extract_archives_result"
100476aec45a7Smrg	    test "X$libobjs" = "X " && libobjs=
100486aec45a7Smrg	  fi
100496aec45a7Smrg	fi
10050ab47cfaaSmrg
10051300bf1aeSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
100526aec45a7Smrg	  eval flag=\"$thread_safe_flag_spec\"
10053aa9e3350Smrg	  func_append linker_flags " $flag"
100546aec45a7Smrg	fi
10055ab47cfaaSmrg
100566aec45a7Smrg	# Make a backup of the uninstalled library when relinking
10057300bf1aeSmrg	if test relink = "$opt_mode"; then
100586aec45a7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
100595c42550eSmrg	fi
10060ab47cfaaSmrg
100616aec45a7Smrg	# Do each of the archive commands.
10062300bf1aeSmrg	if test yes = "$module" && test -n "$module_cmds"; then
100636aec45a7Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
100646aec45a7Smrg	    eval test_cmds=\"$module_expsym_cmds\"
100656aec45a7Smrg	    cmds=$module_expsym_cmds
100666aec45a7Smrg	  else
100676aec45a7Smrg	    eval test_cmds=\"$module_cmds\"
100686aec45a7Smrg	    cmds=$module_cmds
100696aec45a7Smrg	  fi
100706aec45a7Smrg	else
100716aec45a7Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100726aec45a7Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
100736aec45a7Smrg	    cmds=$archive_expsym_cmds
100746aec45a7Smrg	  else
100756aec45a7Smrg	    eval test_cmds=\"$archive_cmds\"
100766aec45a7Smrg	    cmds=$archive_cmds
100776aec45a7Smrg	  fi
100785c42550eSmrg	fi
10079ab47cfaaSmrg
10080300bf1aeSmrg	if test : != "$skipped_export" &&
100816aec45a7Smrg	   func_len " $test_cmds" &&
100826aec45a7Smrg	   len=$func_len_result &&
100836aec45a7Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
100846aec45a7Smrg	  :
100856aec45a7Smrg	else
100866aec45a7Smrg	  # The command line is too long to link in one step, link piecewise
100876aec45a7Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
100886aec45a7Smrg	  # script.
10089ab47cfaaSmrg
100906aec45a7Smrg	  # Save the value of $output and $libobjs because we want to
100916aec45a7Smrg	  # use them later.  If we have whole_archive_flag_spec, we
100926aec45a7Smrg	  # want to use save_libobjs as it was before
100936aec45a7Smrg	  # whole_archive_flag_spec was expanded, because we can't
100946aec45a7Smrg	  # assume the linker understands whole_archive_flag_spec.
100956aec45a7Smrg	  # This may have to be revisited, in case too many
100966aec45a7Smrg	  # convenience libraries get linked in and end up exceeding
100976aec45a7Smrg	  # the spec.
100986aec45a7Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
100996aec45a7Smrg	    save_libobjs=$libobjs
101006aec45a7Smrg	  fi
101016aec45a7Smrg	  save_output=$output
101026aec45a7Smrg	  func_basename "$output"
101036aec45a7Smrg	  output_la=$func_basename_result
101041473d951Smrg
101056aec45a7Smrg	  # Clear the reloadable object creation command queue and
101066aec45a7Smrg	  # initialize k to one.
101076aec45a7Smrg	  test_cmds=
101086aec45a7Smrg	  concat_cmds=
101096aec45a7Smrg	  objlist=
101106aec45a7Smrg	  last_robj=
101116aec45a7Smrg	  k=1
10112ab47cfaaSmrg
10113300bf1aeSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114300bf1aeSmrg	    output=$output_objdir/$output_la.lnkscript
101156aec45a7Smrg	    func_verbose "creating GNU ld script: $output"
101166aec45a7Smrg	    echo 'INPUT (' > $output
101176aec45a7Smrg	    for obj in $save_libobjs
101186aec45a7Smrg	    do
10119aa9e3350Smrg	      func_to_tool_file "$obj"
10120aa9e3350Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101216aec45a7Smrg	    done
101226aec45a7Smrg	    echo ')' >> $output
10123aa9e3350Smrg	    func_append delfiles " $output"
10124aa9e3350Smrg	    func_to_tool_file "$output"
10125aa9e3350Smrg	    output=$func_to_tool_file_result
10126300bf1aeSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127300bf1aeSmrg	    output=$output_objdir/$output_la.lnk
101286aec45a7Smrg	    func_verbose "creating linker input file list: $output"
101296aec45a7Smrg	    : > $output
101306aec45a7Smrg	    set x $save_libobjs
101316aec45a7Smrg	    shift
101326aec45a7Smrg	    firstobj=
10133300bf1aeSmrg	    if test yes = "$compiler_needs_object"; then
101346aec45a7Smrg	      firstobj="$1 "
101356aec45a7Smrg	      shift
101366aec45a7Smrg	    fi
101376aec45a7Smrg	    for obj
101386aec45a7Smrg	    do
10139aa9e3350Smrg	      func_to_tool_file "$obj"
10140aa9e3350Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101416aec45a7Smrg	    done
10142aa9e3350Smrg	    func_append delfiles " $output"
10143aa9e3350Smrg	    func_to_tool_file "$output"
10144aa9e3350Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
101456aec45a7Smrg	  else
101466aec45a7Smrg	    if test -n "$save_libobjs"; then
101476aec45a7Smrg	      func_verbose "creating reloadable object files..."
10148300bf1aeSmrg	      output=$output_objdir/$output_la-$k.$objext
101496aec45a7Smrg	      eval test_cmds=\"$reload_cmds\"
101506aec45a7Smrg	      func_len " $test_cmds"
101516aec45a7Smrg	      len0=$func_len_result
101526aec45a7Smrg	      len=$len0
101536aec45a7Smrg
101546aec45a7Smrg	      # Loop over the list of objects to be linked.
101556aec45a7Smrg	      for obj in $save_libobjs
101566aec45a7Smrg	      do
101576aec45a7Smrg		func_len " $obj"
101586aec45a7Smrg		func_arith $len + $func_len_result
101596aec45a7Smrg		len=$func_arith_result
10160300bf1aeSmrg		if test -z "$objlist" ||
101616aec45a7Smrg		   test "$len" -lt "$max_cmd_len"; then
101626aec45a7Smrg		  func_append objlist " $obj"
101636aec45a7Smrg		else
101646aec45a7Smrg		  # The command $test_cmds is almost too long, add a
101656aec45a7Smrg		  # command to the queue.
10166300bf1aeSmrg		  if test 1 -eq "$k"; then
101676aec45a7Smrg		    # The first file doesn't have a previous command to add.
101686aec45a7Smrg		    reload_objs=$objlist
101696aec45a7Smrg		    eval concat_cmds=\"$reload_cmds\"
101706aec45a7Smrg		  else
101716aec45a7Smrg		    # All subsequent reloadable object files will link in
101726aec45a7Smrg		    # the last one created.
101736aec45a7Smrg		    reload_objs="$objlist $last_robj"
101746aec45a7Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
101756aec45a7Smrg		  fi
10176300bf1aeSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
101776aec45a7Smrg		  func_arith $k + 1
101786aec45a7Smrg		  k=$func_arith_result
10179300bf1aeSmrg		  output=$output_objdir/$output_la-$k.$objext
101806aec45a7Smrg		  objlist=" $obj"
101816aec45a7Smrg		  func_len " $last_robj"
101826aec45a7Smrg		  func_arith $len0 + $func_len_result
101836aec45a7Smrg		  len=$func_arith_result
101846aec45a7Smrg		fi
101856aec45a7Smrg	      done
101866aec45a7Smrg	      # Handle the remaining objects by creating one last
101876aec45a7Smrg	      # reloadable object file.  All subsequent reloadable object
101886aec45a7Smrg	      # files will link in the last one created.
101896aec45a7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
101906aec45a7Smrg	      reload_objs="$objlist $last_robj"
10191300bf1aeSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
101926aec45a7Smrg	      if test -n "$last_robj"; then
10193300bf1aeSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
101946aec45a7Smrg	      fi
10195aa9e3350Smrg	      func_append delfiles " $output"
101966aec45a7Smrg
101976aec45a7Smrg	    else
101986aec45a7Smrg	      output=
101996aec45a7Smrg	    fi
10200ab47cfaaSmrg
10201300bf1aeSmrg	    ${skipped_export-false} && {
10202300bf1aeSmrg	      func_verbose "generating symbol list for '$libname.la'"
10203300bf1aeSmrg	      export_symbols=$output_objdir/$libname.exp
102046aec45a7Smrg	      $opt_dry_run || $RM $export_symbols
102056aec45a7Smrg	      libobjs=$output
102066aec45a7Smrg	      # Append the command to create the export file.
102076aec45a7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102086aec45a7Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
102096aec45a7Smrg	      if test -n "$last_robj"; then
102106aec45a7Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
102116aec45a7Smrg	      fi
10212300bf1aeSmrg	    }
10213ab47cfaaSmrg
102146aec45a7Smrg	    test -n "$save_libobjs" &&
102156aec45a7Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216ab47cfaaSmrg
102176aec45a7Smrg	    # Loop through the commands generated above and execute them.
10218300bf1aeSmrg	    save_ifs=$IFS; IFS='~'
102196aec45a7Smrg	    for cmd in $concat_cmds; do
10220300bf1aeSmrg	      IFS=$save_ifs
10221300bf1aeSmrg	      $opt_quiet || {
102222b2b4fcbSmrg		  func_quote_arg expand,pretty "$cmd"
102232b2b4fcbSmrg		  eval "func_echo $func_quote_arg_result"
102246aec45a7Smrg	      }
102256aec45a7Smrg	      $opt_dry_run || eval "$cmd" || {
102266aec45a7Smrg		lt_exit=$?
102276aec45a7Smrg
102286aec45a7Smrg		# Restore the uninstalled library and exit
10229300bf1aeSmrg		if test relink = "$opt_mode"; then
102306aec45a7Smrg		  ( cd "$output_objdir" && \
102316aec45a7Smrg		    $RM "${realname}T" && \
102326aec45a7Smrg		    $MV "${realname}U" "$realname" )
102336aec45a7Smrg		fi
10234ab47cfaaSmrg
102356aec45a7Smrg		exit $lt_exit
102366aec45a7Smrg	      }
102376aec45a7Smrg	    done
10238300bf1aeSmrg	    IFS=$save_ifs
10239ab47cfaaSmrg
102406aec45a7Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
102416aec45a7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
102426aec45a7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
102431473d951Smrg	    fi
102441473d951Smrg	  fi
10245ab47cfaaSmrg
10246300bf1aeSmrg          ${skipped_export-false} && {
102476aec45a7Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248300bf1aeSmrg	      tmp_export_symbols=$export_symbols
10249300bf1aeSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
102506aec45a7Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
102516aec45a7Smrg	    fi
10252ab47cfaaSmrg
102536aec45a7Smrg	    if test -n "$orig_export_symbols"; then
102546aec45a7Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255300bf1aeSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
102566aec45a7Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257300bf1aeSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
102586aec45a7Smrg	      # though. Also, the filter scales superlinearly with the number of
102596aec45a7Smrg	      # global variables. join(1) would be nice here, but unfortunately
102606aec45a7Smrg	      # isn't a blessed tool.
102616aec45a7Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262aa9e3350Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
102636aec45a7Smrg	      export_symbols=$output_objdir/$libname.def
102646aec45a7Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
102656aec45a7Smrg	    fi
10266300bf1aeSmrg	  }
102671473d951Smrg
102686aec45a7Smrg	  libobjs=$output
102696aec45a7Smrg	  # Restore the value of output.
102706aec45a7Smrg	  output=$save_output
102715c42550eSmrg
102726aec45a7Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
102736aec45a7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
102746aec45a7Smrg	    test "X$libobjs" = "X " && libobjs=
102756aec45a7Smrg	  fi
102766aec45a7Smrg	  # Expand the library linking commands again to reset the
102776aec45a7Smrg	  # value of $libobjs for piecewise linking.
102786aec45a7Smrg
102796aec45a7Smrg	  # Do each of the archive commands.
10280300bf1aeSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
102816aec45a7Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
102826aec45a7Smrg	      cmds=$module_expsym_cmds
10283ab47cfaaSmrg	    else
102846aec45a7Smrg	      cmds=$module_cmds
10285ab47cfaaSmrg	    fi
10286ab47cfaaSmrg	  else
102876aec45a7Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
102886aec45a7Smrg	      cmds=$archive_expsym_cmds
102896aec45a7Smrg	    else
102906aec45a7Smrg	      cmds=$archive_cmds
102916aec45a7Smrg	    fi
10292ab47cfaaSmrg	  fi
10293ab47cfaaSmrg	fi
10294ab47cfaaSmrg
102956aec45a7Smrg	if test -n "$delfiles"; then
102966aec45a7Smrg	  # Append the command to remove temporary files to $cmds.
102976aec45a7Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
102986aec45a7Smrg	fi
10299ab47cfaaSmrg
103006aec45a7Smrg	# Add any objects from preloaded convenience libraries
103016aec45a7Smrg	if test -n "$dlprefiles"; then
10302300bf1aeSmrg	  gentop=$output_objdir/${outputname}x
10303aa9e3350Smrg	  func_append generated " $gentop"
10304ab47cfaaSmrg
103056aec45a7Smrg	  func_extract_archives $gentop $dlprefiles
10306aa9e3350Smrg	  func_append libobjs " $func_extract_archives_result"
103076aec45a7Smrg	  test "X$libobjs" = "X " && libobjs=
103081473d951Smrg	fi
10309ab47cfaaSmrg
10310300bf1aeSmrg	save_ifs=$IFS; IFS='~'
103116aec45a7Smrg	for cmd in $cmds; do
10312300bf1aeSmrg	  IFS=$sp$nl
103136aec45a7Smrg	  eval cmd=\"$cmd\"
10314300bf1aeSmrg	  IFS=$save_ifs
10315300bf1aeSmrg	  $opt_quiet || {
103162b2b4fcbSmrg	    func_quote_arg expand,pretty "$cmd"
103172b2b4fcbSmrg	    eval "func_echo $func_quote_arg_result"
103186aec45a7Smrg	  }
103196aec45a7Smrg	  $opt_dry_run || eval "$cmd" || {
103206aec45a7Smrg	    lt_exit=$?
10321ab47cfaaSmrg
103226aec45a7Smrg	    # Restore the uninstalled library and exit
10323300bf1aeSmrg	    if test relink = "$opt_mode"; then
103246aec45a7Smrg	      ( cd "$output_objdir" && \
103256aec45a7Smrg	        $RM "${realname}T" && \
103266aec45a7Smrg		$MV "${realname}U" "$realname" )
103275c42550eSmrg	    fi
10328ab47cfaaSmrg
103296aec45a7Smrg	    exit $lt_exit
103306aec45a7Smrg	  }
103316aec45a7Smrg	done
10332300bf1aeSmrg	IFS=$save_ifs
10333ab47cfaaSmrg
103346aec45a7Smrg	# Restore the uninstalled library and exit
10335300bf1aeSmrg	if test relink = "$opt_mode"; then
103366aec45a7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337ab47cfaaSmrg
103386aec45a7Smrg	  if test -n "$convenience"; then
103396aec45a7Smrg	    if test -z "$whole_archive_flag_spec"; then
103406aec45a7Smrg	      func_show_eval '${RM}r "$gentop"'
103416aec45a7Smrg	    fi
103426aec45a7Smrg	  fi
10343ab47cfaaSmrg
103446aec45a7Smrg	  exit $EXIT_SUCCESS
103456aec45a7Smrg	fi
103461473d951Smrg
103476aec45a7Smrg	# Create links to the real library.
103486aec45a7Smrg	for linkname in $linknames; do
103496aec45a7Smrg	  if test "$realname" != "$linkname"; then
103506aec45a7Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
103516aec45a7Smrg	  fi
103526aec45a7Smrg	done
103531473d951Smrg
103546aec45a7Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355300bf1aeSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
103566aec45a7Smrg	  # On all known operating systems, these are identical.
10357300bf1aeSmrg	  dlname=$soname
103586aec45a7Smrg	fi
103596aec45a7Smrg      fi
103606aec45a7Smrg      ;;
103611473d951Smrg
103626aec45a7Smrg    obj)
10363300bf1aeSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364300bf1aeSmrg	func_warning "'-dlopen' is ignored for objects"
103656aec45a7Smrg      fi
103661473d951Smrg
103676aec45a7Smrg      case " $deplibs" in
103686aec45a7Smrg      *\ -l* | *\ -L*)
10369300bf1aeSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
103706aec45a7Smrg      esac
103711473d951Smrg
103726aec45a7Smrg      test -n "$rpath" && \
10373300bf1aeSmrg	func_warning "'-rpath' is ignored for objects"
103741473d951Smrg
103756aec45a7Smrg      test -n "$xrpath" && \
10376300bf1aeSmrg	func_warning "'-R' is ignored for objects"
103776aec45a7Smrg
103786aec45a7Smrg      test -n "$vinfo" && \
10379300bf1aeSmrg	func_warning "'-version-info' is ignored for objects"
10380ab47cfaaSmrg
103816aec45a7Smrg      test -n "$release" && \
10382300bf1aeSmrg	func_warning "'-release' is ignored for objects"
103835c42550eSmrg
103846aec45a7Smrg      case $output in
103856aec45a7Smrg      *.lo)
103866aec45a7Smrg	test -n "$objs$old_deplibs" && \
10387300bf1aeSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
103886aec45a7Smrg
103896aec45a7Smrg	libobj=$output
103906aec45a7Smrg	func_lo2o "$libobj"
103916aec45a7Smrg	obj=$func_lo2o_result
103926aec45a7Smrg	;;
103936aec45a7Smrg      *)
103946aec45a7Smrg	libobj=
10395300bf1aeSmrg	obj=$output
103965c42550eSmrg	;;
103971473d951Smrg      esac
10398ab47cfaaSmrg
103996aec45a7Smrg      # Delete the old objects.
104006aec45a7Smrg      $opt_dry_run || $RM $obj $libobj
10401ab47cfaaSmrg
104026aec45a7Smrg      # Objects from convenience libraries.  This assumes
104036aec45a7Smrg      # single-version convenience libraries.  Whenever we create
104046aec45a7Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
104056aec45a7Smrg      # the extraction.
104066aec45a7Smrg      reload_conv_objs=
104076aec45a7Smrg      gentop=
10408300bf1aeSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409300bf1aeSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410300bf1aeSmrg      # into space.
10411300bf1aeSmrg      case $reload_cmds in
10412300bf1aeSmrg        *\$LD[\ \$]*) wl= ;;
10413300bf1aeSmrg      esac
104146aec45a7Smrg      if test -n "$convenience"; then
104156aec45a7Smrg	if test -n "$whole_archive_flag_spec"; then
104166aec45a7Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417300bf1aeSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418300bf1aeSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
104195c42550eSmrg	else
10420300bf1aeSmrg	  gentop=$output_objdir/${obj}x
10421aa9e3350Smrg	  func_append generated " $gentop"
104226aec45a7Smrg
104236aec45a7Smrg	  func_extract_archives $gentop $convenience
104246aec45a7Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
104255c42550eSmrg	fi
104266aec45a7Smrg      fi
10427ab47cfaaSmrg
10428aa9e3350Smrg      # If we're not building shared, we need to use non_pic_objs
10429300bf1aeSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430aa9e3350Smrg
104316aec45a7Smrg      # Create the old-style object.
10432300bf1aeSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433ab47cfaaSmrg
10434300bf1aeSmrg      output=$obj
104356aec45a7Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436ab47cfaaSmrg
104376aec45a7Smrg      # Exit if we aren't doing a library object file.
104386aec45a7Smrg      if test -z "$libobj"; then
104396aec45a7Smrg	if test -n "$gentop"; then
104406aec45a7Smrg	  func_show_eval '${RM}r "$gentop"'
104416aec45a7Smrg	fi
104425c42550eSmrg
104436aec45a7Smrg	exit $EXIT_SUCCESS
104445c42550eSmrg      fi
104455c42550eSmrg
10446300bf1aeSmrg      test yes = "$build_libtool_libs" || {
104476aec45a7Smrg	if test -n "$gentop"; then
104486aec45a7Smrg	  func_show_eval '${RM}r "$gentop"'
104496aec45a7Smrg	fi
104505c42550eSmrg
104516aec45a7Smrg	# Create an invalid libtool object if no PIC, so that we don't
104526aec45a7Smrg	# accidentally link it into a program.
104536aec45a7Smrg	# $show "echo timestamp > $libobj"
104546aec45a7Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
104556aec45a7Smrg	exit $EXIT_SUCCESS
10456300bf1aeSmrg      }
104575c42550eSmrg
10458300bf1aeSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
104596aec45a7Smrg	# Only do commands if we really have different PIC objects.
104606aec45a7Smrg	reload_objs="$libobjs $reload_conv_objs"
10461300bf1aeSmrg	output=$libobj
104626aec45a7Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
104635c42550eSmrg      fi
104646aec45a7Smrg
104656aec45a7Smrg      if test -n "$gentop"; then
104666aec45a7Smrg	func_show_eval '${RM}r "$gentop"'
104676aec45a7Smrg      fi
104686aec45a7Smrg
104696aec45a7Smrg      exit $EXIT_SUCCESS
104705c42550eSmrg      ;;
10471ab47cfaaSmrg
104726aec45a7Smrg    prog)
104736aec45a7Smrg      case $host in
104746aec45a7Smrg	*cygwin*) func_stripname '' '.exe' "$output"
104756aec45a7Smrg	          output=$func_stripname_result.exe;;
104766aec45a7Smrg      esac
104776aec45a7Smrg      test -n "$vinfo" && \
10478300bf1aeSmrg	func_warning "'-version-info' is ignored for programs"
10479ab47cfaaSmrg
104806aec45a7Smrg      test -n "$release" && \
10481300bf1aeSmrg	func_warning "'-release' is ignored for programs"
10482ab47cfaaSmrg
10483300bf1aeSmrg      $preload \
10484300bf1aeSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485300bf1aeSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104866aec45a7Smrg
104876aec45a7Smrg      case $host in
104886aec45a7Smrg      *-*-rhapsody* | *-*-darwin1.[012])
104896aec45a7Smrg	# On Rhapsody replace the C library is the System framework
104906aec45a7Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
104916aec45a7Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
104925c42550eSmrg	;;
104936aec45a7Smrg      esac
104945c42550eSmrg
104956aec45a7Smrg      case $host in
104966aec45a7Smrg      *-*-darwin*)
104976aec45a7Smrg	# Don't allow lazy linking, it breaks C++ global constructors
104986aec45a7Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499300bf1aeSmrg	if test CXX = "$tagname"; then
105006aec45a7Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
105016aec45a7Smrg	    10.[0123])
10502300bf1aeSmrg	      func_append compile_command " $wl-bind_at_load"
10503300bf1aeSmrg	      func_append finalize_command " $wl-bind_at_load"
105046aec45a7Smrg	    ;;
105056aec45a7Smrg	  esac
105065c42550eSmrg	fi
105076aec45a7Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
105086aec45a7Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105096aec45a7Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105106aec45a7Smrg	;;
105116aec45a7Smrg      esac
105125c42550eSmrg
105135c42550eSmrg
105146aec45a7Smrg      # move library search paths that coincide with paths to not yet
105156aec45a7Smrg      # installed libraries to the beginning of the library search list
105166aec45a7Smrg      new_libs=
105176aec45a7Smrg      for path in $notinst_path; do
105186aec45a7Smrg	case " $new_libs " in
105196aec45a7Smrg	*" -L$path/$objdir "*) ;;
105206aec45a7Smrg	*)
105216aec45a7Smrg	  case " $compile_deplibs " in
105226aec45a7Smrg	  *" -L$path/$objdir "*)
10523aa9e3350Smrg	    func_append new_libs " -L$path/$objdir" ;;
105241473d951Smrg	  esac
105256aec45a7Smrg	  ;;
105266aec45a7Smrg	esac
105276aec45a7Smrg      done
105286aec45a7Smrg      for deplib in $compile_deplibs; do
105296aec45a7Smrg	case $deplib in
105306aec45a7Smrg	-L*)
105316aec45a7Smrg	  case " $new_libs " in
105326aec45a7Smrg	  *" $deplib "*) ;;
10533aa9e3350Smrg	  *) func_append new_libs " $deplib" ;;
105341473d951Smrg	  esac
105356aec45a7Smrg	  ;;
10536aa9e3350Smrg	*) func_append new_libs " $deplib" ;;
105376aec45a7Smrg	esac
105386aec45a7Smrg      done
10539300bf1aeSmrg      compile_deplibs=$new_libs
10540ab47cfaaSmrg
105415c42550eSmrg
10542aa9e3350Smrg      func_append compile_command " $compile_deplibs"
10543aa9e3350Smrg      func_append finalize_command " $finalize_deplibs"
105445c42550eSmrg
105456aec45a7Smrg      if test -n "$rpath$xrpath"; then
105466aec45a7Smrg	# If the user specified any rpath flags, then add them.
105476aec45a7Smrg	for libdir in $rpath $xrpath; do
105486aec45a7Smrg	  # This is the magic to use -rpath.
105496aec45a7Smrg	  case "$finalize_rpath " in
105506aec45a7Smrg	  *" $libdir "*) ;;
10551aa9e3350Smrg	  *) func_append finalize_rpath " $libdir" ;;
105526aec45a7Smrg	  esac
105536aec45a7Smrg	done
105546aec45a7Smrg      fi
105555c42550eSmrg
105566aec45a7Smrg      # Now hardcode the library paths
105576aec45a7Smrg      rpath=
105586aec45a7Smrg      hardcode_libdirs=
105596aec45a7Smrg      for libdir in $compile_rpath $finalize_rpath; do
105606aec45a7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
105616aec45a7Smrg	  if test -n "$hardcode_libdir_separator"; then
105626aec45a7Smrg	    if test -z "$hardcode_libdirs"; then
10563300bf1aeSmrg	      hardcode_libdirs=$libdir
105646aec45a7Smrg	    else
105656aec45a7Smrg	      # Just accumulate the unique libdirs.
105666aec45a7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
105676aec45a7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
105686aec45a7Smrg		;;
105696aec45a7Smrg	      *)
10570aa9e3350Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
105716aec45a7Smrg		;;
105726aec45a7Smrg	      esac
105736aec45a7Smrg	    fi
105745c42550eSmrg	  else
105756aec45a7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576aa9e3350Smrg	    func_append rpath " $flag"
105775c42550eSmrg	  fi
105786aec45a7Smrg	elif test -n "$runpath_var"; then
105796aec45a7Smrg	  case "$perm_rpath " in
105806aec45a7Smrg	  *" $libdir "*) ;;
10581aa9e3350Smrg	  *) func_append perm_rpath " $libdir" ;;
105826aec45a7Smrg	  esac
105836aec45a7Smrg	fi
105846aec45a7Smrg	case $host in
105856aec45a7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586300bf1aeSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
105876aec45a7Smrg	  case :$dllsearchpath: in
105886aec45a7Smrg	  *":$libdir:"*) ;;
105896aec45a7Smrg	  ::) dllsearchpath=$libdir;;
10590aa9e3350Smrg	  *) func_append dllsearchpath ":$libdir";;
105916aec45a7Smrg	  esac
105926aec45a7Smrg	  case :$dllsearchpath: in
105936aec45a7Smrg	  *":$testbindir:"*) ;;
105946aec45a7Smrg	  ::) dllsearchpath=$testbindir;;
10595aa9e3350Smrg	  *) func_append dllsearchpath ":$testbindir";;
105966aec45a7Smrg	  esac
105976aec45a7Smrg	  ;;
105986aec45a7Smrg	esac
105996aec45a7Smrg      done
106006aec45a7Smrg      # Substitute the hardcoded libdirs into the rpath.
106016aec45a7Smrg      if test -n "$hardcode_libdir_separator" &&
106026aec45a7Smrg	 test -n "$hardcode_libdirs"; then
10603300bf1aeSmrg	libdir=$hardcode_libdirs
106046aec45a7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106056aec45a7Smrg      fi
10606300bf1aeSmrg      compile_rpath=$rpath
106075c42550eSmrg
106086aec45a7Smrg      rpath=
106096aec45a7Smrg      hardcode_libdirs=
106106aec45a7Smrg      for libdir in $finalize_rpath; do
106116aec45a7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
106126aec45a7Smrg	  if test -n "$hardcode_libdir_separator"; then
106136aec45a7Smrg	    if test -z "$hardcode_libdirs"; then
10614300bf1aeSmrg	      hardcode_libdirs=$libdir
106156aec45a7Smrg	    else
106166aec45a7Smrg	      # Just accumulate the unique libdirs.
106176aec45a7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
106186aec45a7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
106196aec45a7Smrg		;;
106206aec45a7Smrg	      *)
10621aa9e3350Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
106226aec45a7Smrg		;;
106236aec45a7Smrg	      esac
106246aec45a7Smrg	    fi
10625ab47cfaaSmrg	  else
106266aec45a7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627aa9e3350Smrg	    func_append rpath " $flag"
10628ab47cfaaSmrg	  fi
106296aec45a7Smrg	elif test -n "$runpath_var"; then
106306aec45a7Smrg	  case "$finalize_perm_rpath " in
106316aec45a7Smrg	  *" $libdir "*) ;;
10632aa9e3350Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106336aec45a7Smrg	  esac
10634ab47cfaaSmrg	fi
106356aec45a7Smrg      done
106366aec45a7Smrg      # Substitute the hardcoded libdirs into the rpath.
106376aec45a7Smrg      if test -n "$hardcode_libdir_separator" &&
106386aec45a7Smrg	 test -n "$hardcode_libdirs"; then
10639300bf1aeSmrg	libdir=$hardcode_libdirs
106406aec45a7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106416aec45a7Smrg      fi
10642300bf1aeSmrg      finalize_rpath=$rpath
10643ab47cfaaSmrg
10644300bf1aeSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
106456aec45a7Smrg	# Transform all the library objects into standard objects.
106466aec45a7Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106476aec45a7Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106486aec45a7Smrg      fi
10649ab47cfaaSmrg
10650300bf1aeSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651ab47cfaaSmrg
106526aec45a7Smrg      # template prelinking step
106536aec45a7Smrg      if test -n "$prelink_cmds"; then
106546aec45a7Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
106556aec45a7Smrg      fi
10656ab47cfaaSmrg
10657300bf1aeSmrg      wrappers_required=:
106586aec45a7Smrg      case $host in
106596aec45a7Smrg      *cegcc* | *mingw32ce*)
106606aec45a7Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661300bf1aeSmrg        wrappers_required=false
106626aec45a7Smrg        ;;
106636aec45a7Smrg      *cygwin* | *mingw* )
10664300bf1aeSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
106656aec45a7Smrg        ;;
106666aec45a7Smrg      *)
10667300bf1aeSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668300bf1aeSmrg          wrappers_required=false
106696aec45a7Smrg        fi
106706aec45a7Smrg        ;;
106716aec45a7Smrg      esac
10672300bf1aeSmrg      $wrappers_required || {
106736aec45a7Smrg	# Replace the output file specification.
106746aec45a7Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675300bf1aeSmrg	link_command=$compile_command$compile_rpath
10676ab47cfaaSmrg
106776aec45a7Smrg	# We have no uninstalled library dependencies, so finalize right now.
106786aec45a7Smrg	exit_status=0
106796aec45a7Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680ab47cfaaSmrg
10681aa9e3350Smrg	if test -n "$postlink_cmds"; then
10682aa9e3350Smrg	  func_to_tool_file "$output"
10683aa9e3350Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684aa9e3350Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685aa9e3350Smrg	fi
10686aa9e3350Smrg
106876aec45a7Smrg	# Delete the generated files.
10688300bf1aeSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689300bf1aeSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690ab47cfaaSmrg	fi
10691ab47cfaaSmrg
106926aec45a7Smrg	exit $exit_status
10693300bf1aeSmrg      }
10694ab47cfaaSmrg
106956aec45a7Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
106966aec45a7Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
106976aec45a7Smrg      fi
106986aec45a7Smrg      if test -n "$finalize_shlibpath"; then
106996aec45a7Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
107006aec45a7Smrg      fi
107015c42550eSmrg
107026aec45a7Smrg      compile_var=
107036aec45a7Smrg      finalize_var=
107046aec45a7Smrg      if test -n "$runpath_var"; then
107056aec45a7Smrg	if test -n "$perm_rpath"; then
107066aec45a7Smrg	  # We should set the runpath_var.
107076aec45a7Smrg	  rpath=
107086aec45a7Smrg	  for dir in $perm_rpath; do
10709aa9e3350Smrg	    func_append rpath "$dir:"
107106aec45a7Smrg	  done
107116aec45a7Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712ab47cfaaSmrg	fi
107136aec45a7Smrg	if test -n "$finalize_perm_rpath"; then
107146aec45a7Smrg	  # We should set the runpath_var.
107156aec45a7Smrg	  rpath=
107166aec45a7Smrg	  for dir in $finalize_perm_rpath; do
10717aa9e3350Smrg	    func_append rpath "$dir:"
107186aec45a7Smrg	  done
107196aec45a7Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720ab47cfaaSmrg	fi
107216aec45a7Smrg      fi
10722ab47cfaaSmrg
10723300bf1aeSmrg      if test yes = "$no_install"; then
107246aec45a7Smrg	# We don't need to create a wrapper script.
10725300bf1aeSmrg	link_command=$compile_var$compile_command$compile_rpath
107266aec45a7Smrg	# Replace the output file specification.
107276aec45a7Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
107286aec45a7Smrg	# Delete the old output file.
107296aec45a7Smrg	$opt_dry_run || $RM $output
107306aec45a7Smrg	# Link the executable and exit
107316aec45a7Smrg	func_show_eval "$link_command" 'exit $?'
10732aa9e3350Smrg
10733aa9e3350Smrg	if test -n "$postlink_cmds"; then
10734aa9e3350Smrg	  func_to_tool_file "$output"
10735aa9e3350Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736aa9e3350Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737aa9e3350Smrg	fi
10738aa9e3350Smrg
107395c42550eSmrg	exit $EXIT_SUCCESS
107406aec45a7Smrg      fi
107411473d951Smrg
10742300bf1aeSmrg      case $hardcode_action,$fast_install in
10743300bf1aeSmrg        relink,*)
10744300bf1aeSmrg	  # Fast installation is not supported
10745300bf1aeSmrg	  link_command=$compile_var$compile_command$compile_rpath
10746300bf1aeSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107476aec45a7Smrg
10748300bf1aeSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10749300bf1aeSmrg	  func_warning "'$output' will be relinked during installation"
10750300bf1aeSmrg	  ;;
10751300bf1aeSmrg        *,yes)
10752300bf1aeSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753300bf1aeSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754300bf1aeSmrg          ;;
10755300bf1aeSmrg	*,no)
10756300bf1aeSmrg	  link_command=$compile_var$compile_command$compile_rpath
10757300bf1aeSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758300bf1aeSmrg          ;;
10759300bf1aeSmrg	*,needless)
10760300bf1aeSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761300bf1aeSmrg	  relink_command=
10762300bf1aeSmrg          ;;
10763300bf1aeSmrg      esac
10764ab47cfaaSmrg
107656aec45a7Smrg      # Replace the output file specification.
107666aec45a7Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767ab47cfaaSmrg
107686aec45a7Smrg      # Delete the old output files.
107696aec45a7Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770ab47cfaaSmrg
107716aec45a7Smrg      func_show_eval "$link_command" 'exit $?'
107725c42550eSmrg
10773aa9e3350Smrg      if test -n "$postlink_cmds"; then
10774aa9e3350Smrg	func_to_tool_file "$output_objdir/$outputname"
10775aa9e3350Smrg	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'`
10776aa9e3350Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777aa9e3350Smrg      fi
10778aa9e3350Smrg
107796aec45a7Smrg      # Now create the wrapper script.
107806aec45a7Smrg      func_verbose "creating $output"
107815c42550eSmrg
107826aec45a7Smrg      # Quote the relink command for shipping.
107836aec45a7Smrg      if test -n "$relink_command"; then
107846aec45a7Smrg	# Preserve any variables that may affect compiler behavior
107856aec45a7Smrg	for var in $variables_saved_for_relink; do
107866aec45a7Smrg	  if eval test -z \"\${$var+set}\"; then
107876aec45a7Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107886aec45a7Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
107896aec45a7Smrg	    relink_command="$var=; export $var; $relink_command"
10790ab47cfaaSmrg	  else
107912b2b4fcbSmrg	    func_quote_arg pretty "$var_value"
107922b2b4fcbSmrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793ab47cfaaSmrg	  fi
107946aec45a7Smrg	done
107952b2b4fcbSmrg	func_quote eval cd "`pwd`"
107962b2b4fcbSmrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
107972b2b4fcbSmrg	relink_command=$func_quote_arg_unquoted_result
107986aec45a7Smrg      fi
107991473d951Smrg
108006aec45a7Smrg      # Only actually do things if not in dry run mode.
108016aec45a7Smrg      $opt_dry_run || {
108026aec45a7Smrg	# win32 will think the script is a binary if it has
108036aec45a7Smrg	# a .exe suffix, so we strip it off here.
108046aec45a7Smrg	case $output in
108056aec45a7Smrg	  *.exe) func_stripname '' '.exe' "$output"
108066aec45a7Smrg	         output=$func_stripname_result ;;
108076aec45a7Smrg	esac
108086aec45a7Smrg	# test for cygwin because mv fails w/o .exe extensions
108096aec45a7Smrg	case $host in
108106aec45a7Smrg	  *cygwin*)
108116aec45a7Smrg	    exeext=.exe
108126aec45a7Smrg	    func_stripname '' '.exe' "$outputname"
108136aec45a7Smrg	    outputname=$func_stripname_result ;;
108146aec45a7Smrg	  *) exeext= ;;
10815ab47cfaaSmrg	esac
108166aec45a7Smrg	case $host in
108176aec45a7Smrg	  *cygwin* | *mingw* )
108186aec45a7Smrg	    func_dirname_and_basename "$output" "" "."
108196aec45a7Smrg	    output_name=$func_basename_result
108206aec45a7Smrg	    output_path=$func_dirname_result
10821300bf1aeSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822300bf1aeSmrg	    cwrapper=$output_path/$output_name.exe
108236aec45a7Smrg	    $RM $cwrappersource $cwrapper
108246aec45a7Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
108256aec45a7Smrg
108266aec45a7Smrg	    func_emit_cwrapperexe_src > $cwrappersource
108276aec45a7Smrg
108286aec45a7Smrg	    # The wrapper executable is built using the $host compiler,
108296aec45a7Smrg	    # because it contains $host paths and files. If cross-
108306aec45a7Smrg	    # compiling, it, like the target executable, must be
108316aec45a7Smrg	    # executed on the $host or under an emulation environment.
108326aec45a7Smrg	    $opt_dry_run || {
108336aec45a7Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
108346aec45a7Smrg	      $STRIP $cwrapper
108356aec45a7Smrg	    }
10836ab47cfaaSmrg
108376aec45a7Smrg	    # Now, create the wrapper script for func_source use:
108386aec45a7Smrg	    func_ltwrapper_scriptname $cwrapper
108396aec45a7Smrg	    $RM $func_ltwrapper_scriptname_result
108406aec45a7Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
108416aec45a7Smrg	    $opt_dry_run || {
108426aec45a7Smrg	      # note: this script will not be executed, so do not chmod.
10843300bf1aeSmrg	      if test "x$build" = "x$host"; then
108446aec45a7Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108456aec45a7Smrg	      else
108466aec45a7Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108476aec45a7Smrg	      fi
108486aec45a7Smrg	    }
108496aec45a7Smrg	  ;;
108506aec45a7Smrg	  * )
108516aec45a7Smrg	    $RM $output
108526aec45a7Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853ab47cfaaSmrg
108546aec45a7Smrg	    func_emit_wrapper no > $output
108556aec45a7Smrg	    chmod +x $output
108566aec45a7Smrg	  ;;
108576aec45a7Smrg	esac
108586aec45a7Smrg      }
108596aec45a7Smrg      exit $EXIT_SUCCESS
108606aec45a7Smrg      ;;
108616aec45a7Smrg    esac
10862ab47cfaaSmrg
108636aec45a7Smrg    # See if we need to build an old-fashioned archive.
108646aec45a7Smrg    for oldlib in $oldlibs; do
10865ab47cfaaSmrg
10866300bf1aeSmrg      case $build_libtool_libs in
10867300bf1aeSmrg        convenience)
10868300bf1aeSmrg	  oldobjs="$libobjs_save $symfileobj"
10869300bf1aeSmrg	  addlibs=$convenience
108706aec45a7Smrg	  build_libtool_libs=no
10871300bf1aeSmrg	  ;;
10872300bf1aeSmrg	module)
10873300bf1aeSmrg	  oldobjs=$libobjs_save
10874300bf1aeSmrg	  addlibs=$old_convenience
10875300bf1aeSmrg	  build_libtool_libs=no
10876300bf1aeSmrg          ;;
10877300bf1aeSmrg	*)
108786aec45a7Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879300bf1aeSmrg	  $preload && test -f "$symfileobj" \
10880300bf1aeSmrg	    && func_append oldobjs " $symfileobj"
10881300bf1aeSmrg	  addlibs=$old_convenience
10882300bf1aeSmrg	  ;;
10883300bf1aeSmrg      esac
10884ab47cfaaSmrg
108856aec45a7Smrg      if test -n "$addlibs"; then
10886300bf1aeSmrg	gentop=$output_objdir/${outputname}x
10887aa9e3350Smrg	func_append generated " $gentop"
10888ab47cfaaSmrg
108896aec45a7Smrg	func_extract_archives $gentop $addlibs
10890aa9e3350Smrg	func_append oldobjs " $func_extract_archives_result"
108916aec45a7Smrg      fi
10892ab47cfaaSmrg
108936aec45a7Smrg      # Do each command in the archive commands.
10894300bf1aeSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
108956aec45a7Smrg	cmds=$old_archive_from_new_cmds
108966aec45a7Smrg      else
10897ab47cfaaSmrg
108986aec45a7Smrg	# Add any objects from preloaded convenience libraries
108996aec45a7Smrg	if test -n "$dlprefiles"; then
10900300bf1aeSmrg	  gentop=$output_objdir/${outputname}x
10901aa9e3350Smrg	  func_append generated " $gentop"
10902ab47cfaaSmrg
109036aec45a7Smrg	  func_extract_archives $gentop $dlprefiles
10904aa9e3350Smrg	  func_append oldobjs " $func_extract_archives_result"
109056aec45a7Smrg	fi
10906ab47cfaaSmrg
109076aec45a7Smrg	# POSIX demands no paths to be encoded in archives.  We have
109086aec45a7Smrg	# to avoid creating archives with duplicate basenames if we
109096aec45a7Smrg	# might have to extract them afterwards, e.g., when creating a
109106aec45a7Smrg	# static archive out of a convenience library, or when linking
109116aec45a7Smrg	# the entirety of a libtool archive into another (currently
109126aec45a7Smrg	# not supported by libtool).
109136aec45a7Smrg	if (for obj in $oldobjs
109146aec45a7Smrg	    do
109156aec45a7Smrg	      func_basename "$obj"
109166aec45a7Smrg	      $ECHO "$func_basename_result"
109176aec45a7Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
109186aec45a7Smrg	  :
109196aec45a7Smrg	else
109206aec45a7Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921300bf1aeSmrg	  gentop=$output_objdir/${outputname}x
10922aa9e3350Smrg	  func_append generated " $gentop"
109236aec45a7Smrg	  func_mkdir_p "$gentop"
109246aec45a7Smrg	  save_oldobjs=$oldobjs
109256aec45a7Smrg	  oldobjs=
109266aec45a7Smrg	  counter=1
109276aec45a7Smrg	  for obj in $save_oldobjs
109286aec45a7Smrg	  do
109296aec45a7Smrg	    func_basename "$obj"
10930300bf1aeSmrg	    objbase=$func_basename_result
109316aec45a7Smrg	    case " $oldobjs " in
109326aec45a7Smrg	    " ") oldobjs=$obj ;;
109336aec45a7Smrg	    *[\ /]"$objbase "*)
109346aec45a7Smrg	      while :; do
109356aec45a7Smrg		# Make sure we don't pick an alternate name that also
109366aec45a7Smrg		# overlaps.
109376aec45a7Smrg		newobj=lt$counter-$objbase
109386aec45a7Smrg		func_arith $counter + 1
109396aec45a7Smrg		counter=$func_arith_result
109406aec45a7Smrg		case " $oldobjs " in
109416aec45a7Smrg		*[\ /]"$newobj "*) ;;
109426aec45a7Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
109436aec45a7Smrg		esac
109446aec45a7Smrg	      done
109456aec45a7Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946aa9e3350Smrg	      func_append oldobjs " $gentop/$newobj"
109476aec45a7Smrg	      ;;
10948aa9e3350Smrg	    *) func_append oldobjs " $obj" ;;
109496aec45a7Smrg	    esac
10950ab47cfaaSmrg	  done
109511473d951Smrg	fi
10952aa9e3350Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953aa9e3350Smrg	tool_oldlib=$func_to_tool_file_result
109546aec45a7Smrg	eval cmds=\"$old_archive_cmds\"
109555c42550eSmrg
109566aec45a7Smrg	func_len " $cmds"
109576aec45a7Smrg	len=$func_len_result
109586aec45a7Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
109596aec45a7Smrg	  cmds=$old_archive_cmds
10960aa9e3350Smrg	elif test -n "$archiver_list_spec"; then
10961aa9e3350Smrg	  func_verbose "using command file archive linking..."
10962aa9e3350Smrg	  for obj in $oldobjs
10963aa9e3350Smrg	  do
10964aa9e3350Smrg	    func_to_tool_file "$obj"
10965aa9e3350Smrg	    $ECHO "$func_to_tool_file_result"
10966aa9e3350Smrg	  done > $output_objdir/$libname.libcmd
10967aa9e3350Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968aa9e3350Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969aa9e3350Smrg	  cmds=$old_archive_cmds
109706aec45a7Smrg	else
109716aec45a7Smrg	  # the command line is too long to link in one step, link in parts
109726aec45a7Smrg	  func_verbose "using piecewise archive linking..."
109736aec45a7Smrg	  save_RANLIB=$RANLIB
109746aec45a7Smrg	  RANLIB=:
109756aec45a7Smrg	  objlist=
109766aec45a7Smrg	  concat_cmds=
109776aec45a7Smrg	  save_oldobjs=$oldobjs
109786aec45a7Smrg	  oldobjs=
109796aec45a7Smrg	  # Is there a better way of finding the last object in the list?
109806aec45a7Smrg	  for obj in $save_oldobjs
109816aec45a7Smrg	  do
109826aec45a7Smrg	    last_oldobj=$obj
109836aec45a7Smrg	  done
109846aec45a7Smrg	  eval test_cmds=\"$old_archive_cmds\"
109856aec45a7Smrg	  func_len " $test_cmds"
109866aec45a7Smrg	  len0=$func_len_result
109876aec45a7Smrg	  len=$len0
109886aec45a7Smrg	  for obj in $save_oldobjs
109896aec45a7Smrg	  do
109906aec45a7Smrg	    func_len " $obj"
109916aec45a7Smrg	    func_arith $len + $func_len_result
109926aec45a7Smrg	    len=$func_arith_result
109936aec45a7Smrg	    func_append objlist " $obj"
109946aec45a7Smrg	    if test "$len" -lt "$max_cmd_len"; then
109956aec45a7Smrg	      :
109966aec45a7Smrg	    else
109976aec45a7Smrg	      # the above command should be used before it gets too long
109986aec45a7Smrg	      oldobjs=$objlist
10999300bf1aeSmrg	      if test "$obj" = "$last_oldobj"; then
110006aec45a7Smrg		RANLIB=$save_RANLIB
110016aec45a7Smrg	      fi
110026aec45a7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003300bf1aeSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
110046aec45a7Smrg	      objlist=
110056aec45a7Smrg	      len=$len0
110066aec45a7Smrg	    fi
110076aec45a7Smrg	  done
110086aec45a7Smrg	  RANLIB=$save_RANLIB
110096aec45a7Smrg	  oldobjs=$objlist
11010300bf1aeSmrg	  if test -z "$oldobjs"; then
110116aec45a7Smrg	    eval cmds=\"\$concat_cmds\"
110126aec45a7Smrg	  else
110136aec45a7Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
110146aec45a7Smrg	  fi
110156aec45a7Smrg	fi
110166aec45a7Smrg      fi
110176aec45a7Smrg      func_execute_cmds "$cmds" 'exit $?'
11018ab47cfaaSmrg    done
11019ab47cfaaSmrg
110206aec45a7Smrg    test -n "$generated" && \
110216aec45a7Smrg      func_show_eval "${RM}r$generated"
11022ab47cfaaSmrg
110236aec45a7Smrg    # Now create the libtool archive.
110246aec45a7Smrg    case $output in
110256aec45a7Smrg    *.la)
110266aec45a7Smrg      old_library=
11027300bf1aeSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
110286aec45a7Smrg      func_verbose "creating $output"
110291473d951Smrg
110306aec45a7Smrg      # Preserve any variables that may affect compiler behavior
110316aec45a7Smrg      for var in $variables_saved_for_relink; do
110326aec45a7Smrg	if eval test -z \"\${$var+set}\"; then
110336aec45a7Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
110346aec45a7Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
110356aec45a7Smrg	  relink_command="$var=; export $var; $relink_command"
110365c42550eSmrg	else
110372b2b4fcbSmrg	  func_quote_arg pretty,unquoted "$var_value"
110382b2b4fcbSmrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
110395c42550eSmrg	fi
110406aec45a7Smrg      done
110416aec45a7Smrg      # Quote the link command for shipping.
110422b2b4fcbSmrg      func_quote eval cd "`pwd`"
110432b2b4fcbSmrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
110442b2b4fcbSmrg      func_quote_arg pretty,unquoted "$relink_command"
110452b2b4fcbSmrg      relink_command=$func_quote_arg_unquoted_result
11046300bf1aeSmrg      if test yes = "$hardcode_automatic"; then
110476aec45a7Smrg	relink_command=
110486aec45a7Smrg      fi
11049ab47cfaaSmrg
110506aec45a7Smrg      # Only create the output if not a dry run.
110516aec45a7Smrg      $opt_dry_run || {
110526aec45a7Smrg	for installed in no yes; do
11053300bf1aeSmrg	  if test yes = "$installed"; then
110546aec45a7Smrg	    if test -z "$install_libdir"; then
110556aec45a7Smrg	      break
110566aec45a7Smrg	    fi
11057300bf1aeSmrg	    output=$output_objdir/${outputname}i
110586aec45a7Smrg	    # Replace all uninstalled libtool libraries with the installed ones
110596aec45a7Smrg	    newdependency_libs=
110606aec45a7Smrg	    for deplib in $dependency_libs; do
110616aec45a7Smrg	      case $deplib in
110626aec45a7Smrg	      *.la)
110636aec45a7Smrg		func_basename "$deplib"
11064300bf1aeSmrg		name=$func_basename_result
11065aa9e3350Smrg		func_resolve_sysroot "$deplib"
11066300bf1aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
110676aec45a7Smrg		test -z "$libdir" && \
11068300bf1aeSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069aa9e3350Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070aa9e3350Smrg		;;
11071aa9e3350Smrg	      -L*)
11072aa9e3350Smrg		func_stripname -L '' "$deplib"
11073aa9e3350Smrg		func_replace_sysroot "$func_stripname_result"
11074aa9e3350Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11075aa9e3350Smrg		;;
11076aa9e3350Smrg	      -R*)
11077aa9e3350Smrg		func_stripname -R '' "$deplib"
11078aa9e3350Smrg		func_replace_sysroot "$func_stripname_result"
11079aa9e3350Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
110806aec45a7Smrg		;;
11081aa9e3350Smrg	      *) func_append newdependency_libs " $deplib" ;;
110826aec45a7Smrg	      esac
110836aec45a7Smrg	    done
11084300bf1aeSmrg	    dependency_libs=$newdependency_libs
110856aec45a7Smrg	    newdlfiles=
110866aec45a7Smrg
110876aec45a7Smrg	    for lib in $dlfiles; do
110886aec45a7Smrg	      case $lib in
110896aec45a7Smrg	      *.la)
110906aec45a7Smrg	        func_basename "$lib"
11091300bf1aeSmrg		name=$func_basename_result
11092300bf1aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
110936aec45a7Smrg		test -z "$libdir" && \
11094300bf1aeSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095aa9e3350Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
110966aec45a7Smrg		;;
11097aa9e3350Smrg	      *) func_append newdlfiles " $lib" ;;
110986aec45a7Smrg	      esac
110996aec45a7Smrg	    done
11100300bf1aeSmrg	    dlfiles=$newdlfiles
111016aec45a7Smrg	    newdlprefiles=
111026aec45a7Smrg	    for lib in $dlprefiles; do
111036aec45a7Smrg	      case $lib in
111046aec45a7Smrg	      *.la)
111056aec45a7Smrg		# Only pass preopened files to the pseudo-archive (for
111066aec45a7Smrg		# eventual linking with the app. that links it) if we
111076aec45a7Smrg		# didn't already link the preopened objects directly into
111086aec45a7Smrg		# the library:
111096aec45a7Smrg		func_basename "$lib"
11110300bf1aeSmrg		name=$func_basename_result
11111300bf1aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
111126aec45a7Smrg		test -z "$libdir" && \
11113300bf1aeSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114aa9e3350Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
111156aec45a7Smrg		;;
111166aec45a7Smrg	      esac
111176aec45a7Smrg	    done
11118300bf1aeSmrg	    dlprefiles=$newdlprefiles
111196aec45a7Smrg	  else
111206aec45a7Smrg	    newdlfiles=
111216aec45a7Smrg	    for lib in $dlfiles; do
111226aec45a7Smrg	      case $lib in
11123300bf1aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111246aec45a7Smrg		*) abs=`pwd`"/$lib" ;;
111256aec45a7Smrg	      esac
11126aa9e3350Smrg	      func_append newdlfiles " $abs"
111276aec45a7Smrg	    done
11128300bf1aeSmrg	    dlfiles=$newdlfiles
111296aec45a7Smrg	    newdlprefiles=
111306aec45a7Smrg	    for lib in $dlprefiles; do
111316aec45a7Smrg	      case $lib in
11132300bf1aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111336aec45a7Smrg		*) abs=`pwd`"/$lib" ;;
111346aec45a7Smrg	      esac
11135aa9e3350Smrg	      func_append newdlprefiles " $abs"
111366aec45a7Smrg	    done
11137300bf1aeSmrg	    dlprefiles=$newdlprefiles
111386aec45a7Smrg	  fi
111396aec45a7Smrg	  $RM $output
111406aec45a7Smrg	  # place dlname in correct position for cygwin
111416aec45a7Smrg	  # In fact, it would be nice if we could use this code for all target
111426aec45a7Smrg	  # systems that can't hard-code library paths into their executables
111436aec45a7Smrg	  # and that have no shared library path variable independent of PATH,
111446aec45a7Smrg	  # but it turns out we can't easily determine that from inspecting
111456aec45a7Smrg	  # libtool variables, so we have to hard-code the OSs to which it
111466aec45a7Smrg	  # applies here; at the moment, that means platforms that use the PE
111476aec45a7Smrg	  # object format with DLL files.  See the long comment at the top of
111486aec45a7Smrg	  # tests/bindir.at for full details.
111496aec45a7Smrg	  tdlname=$dlname
111506aec45a7Smrg	  case $host,$output,$installed,$module,$dlname in
111516aec45a7Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
111526aec45a7Smrg	      # If a -bindir argument was supplied, place the dll there.
11153300bf1aeSmrg	      if test -n "$bindir"; then
111546aec45a7Smrg		func_relative_path "$install_libdir" "$bindir"
11155300bf1aeSmrg		tdlname=$func_relative_path_result/$dlname
111566aec45a7Smrg	      else
111576aec45a7Smrg		# Otherwise fall back on heuristic.
111586aec45a7Smrg		tdlname=../bin/$dlname
111596aec45a7Smrg	      fi
111606aec45a7Smrg	      ;;
111616aec45a7Smrg	  esac
111626aec45a7Smrg	  $ECHO > $output "\
111636aec45a7Smrg# $outputname - a libtool library file
11164300bf1aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
111656aec45a7Smrg#
111666aec45a7Smrg# Please DO NOT delete this file!
111676aec45a7Smrg# It is necessary for linking the library.
11168ab47cfaaSmrg
111696aec45a7Smrg# The name that we can dlopen(3).
111706aec45a7Smrgdlname='$tdlname'
11171ab47cfaaSmrg
111726aec45a7Smrg# Names of this library.
111736aec45a7Smrglibrary_names='$library_names'
11174ab47cfaaSmrg
111756aec45a7Smrg# The name of the static archive.
111766aec45a7Smrgold_library='$old_library'
11177ab47cfaaSmrg
11178300bf1aeSmrg# Linker flags that cannot go in dependency_libs.
111796aec45a7Smrginherited_linker_flags='$new_inherited_linker_flags'
11180ab47cfaaSmrg
111816aec45a7Smrg# Libraries that this one depends upon.
111826aec45a7Smrgdependency_libs='$dependency_libs'
11183ab47cfaaSmrg
111846aec45a7Smrg# Names of additional weak libraries provided by this library
111856aec45a7Smrgweak_library_names='$weak_libs'
11186ab47cfaaSmrg
111876aec45a7Smrg# Version information for $libname.
111886aec45a7Smrgcurrent=$current
111896aec45a7Smrgage=$age
111906aec45a7Smrgrevision=$revision
11191ab47cfaaSmrg
111926aec45a7Smrg# Is this an already installed library?
111936aec45a7Smrginstalled=$installed
11194ab47cfaaSmrg
111956aec45a7Smrg# Should we warn about portability when linking against -modules?
111966aec45a7Smrgshouldnotlink=$module
11197ab47cfaaSmrg
111986aec45a7Smrg# Files to dlopen/dlpreopen
111996aec45a7Smrgdlopen='$dlfiles'
112006aec45a7Smrgdlpreopen='$dlprefiles'
11201ab47cfaaSmrg
112026aec45a7Smrg# Directory that this library needs to be installed in:
112036aec45a7Smrglibdir='$install_libdir'"
11204300bf1aeSmrg	  if test no,yes = "$installed,$need_relink"; then
112056aec45a7Smrg	    $ECHO >> $output "\
112066aec45a7Smrgrelink_command=\"$relink_command\""
112076aec45a7Smrg	  fi
112086aec45a7Smrg	done
112096aec45a7Smrg      }
11210ab47cfaaSmrg
112116aec45a7Smrg      # Do a symbolic link so that the libtool archive can be found in
112126aec45a7Smrg      # LD_LIBRARY_PATH before the program is installed.
112136aec45a7Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
112146aec45a7Smrg      ;;
112156aec45a7Smrg    esac
112166aec45a7Smrg    exit $EXIT_SUCCESS
112176aec45a7Smrg}
112185c42550eSmrg
11219300bf1aeSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220300bf1aeSmrg  func_mode_link ${1+"$@"}
11221300bf1aeSmrgfi
11222ab47cfaaSmrg
11223ab47cfaaSmrg
112246aec45a7Smrg# func_mode_uninstall arg...
112256aec45a7Smrgfunc_mode_uninstall ()
112266aec45a7Smrg{
11227300bf1aeSmrg    $debug_cmd
11228300bf1aeSmrg
11229300bf1aeSmrg    RM=$nonopt
11230ab47cfaaSmrg    files=
11231300bf1aeSmrg    rmforce=false
11232ab47cfaaSmrg    exit_status=0
11233ab47cfaaSmrg
11234ab47cfaaSmrg    # This variable tells wrapper scripts just to set variables rather
11235ab47cfaaSmrg    # than running their programs.
11236300bf1aeSmrg    libtool_install_magic=$magic
11237ab47cfaaSmrg
11238ab47cfaaSmrg    for arg
11239ab47cfaaSmrg    do
11240ab47cfaaSmrg      case $arg in
11241300bf1aeSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11242aa9e3350Smrg      -*) func_append RM " $arg" ;;
11243aa9e3350Smrg      *) func_append files " $arg" ;;
11244ab47cfaaSmrg      esac
11245ab47cfaaSmrg    done
11246ab47cfaaSmrg
112476aec45a7Smrg    test -z "$RM" && \
112486aec45a7Smrg      func_fatal_help "you must specify an RM program"
11249ab47cfaaSmrg
11250ab47cfaaSmrg    rmdirs=
11251ab47cfaaSmrg
11252ab47cfaaSmrg    for file in $files; do
112536aec45a7Smrg      func_dirname "$file" "" "."
11254300bf1aeSmrg      dir=$func_dirname_result
11255300bf1aeSmrg      if test . = "$dir"; then
11256300bf1aeSmrg	odir=$objdir
11257ab47cfaaSmrg      else
11258300bf1aeSmrg	odir=$dir/$objdir
11259ab47cfaaSmrg      fi
112606aec45a7Smrg      func_basename "$file"
11261300bf1aeSmrg      name=$func_basename_result
11262300bf1aeSmrg      test uninstall = "$opt_mode" && odir=$dir
11263ab47cfaaSmrg
11264aa9e3350Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265300bf1aeSmrg      if test clean = "$opt_mode"; then
11266ab47cfaaSmrg	case " $rmdirs " in
11267aa9e3350Smrg	  *" $odir "*) ;;
11268aa9e3350Smrg	  *) func_append rmdirs " $odir" ;;
11269ab47cfaaSmrg	esac
11270ab47cfaaSmrg      fi
11271ab47cfaaSmrg
11272ab47cfaaSmrg      # Don't error if the file doesn't exist and rm -f was used.
112736aec45a7Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
112746aec45a7Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
112756aec45a7Smrg	 test -f "$file"; then
11276ab47cfaaSmrg	:
11277ab47cfaaSmrg      elif test -d "$file"; then
11278ab47cfaaSmrg	exit_status=1
11279ab47cfaaSmrg	continue
11280300bf1aeSmrg      elif $rmforce; then
11281ab47cfaaSmrg	continue
11282ab47cfaaSmrg      fi
11283ab47cfaaSmrg
11284300bf1aeSmrg      rmfiles=$file
11285ab47cfaaSmrg
11286ab47cfaaSmrg      case $name in
11287ab47cfaaSmrg      *.la)
11288ab47cfaaSmrg	# Possibly a libtool archive, so verify it.
112896aec45a7Smrg	if func_lalib_p "$file"; then
112906aec45a7Smrg	  func_source $dir/$name
11291ab47cfaaSmrg
11292ab47cfaaSmrg	  # Delete the libtool libraries and symlinks.
11293ab47cfaaSmrg	  for n in $library_names; do
11294aa9e3350Smrg	    func_append rmfiles " $odir/$n"
11295ab47cfaaSmrg	  done
11296aa9e3350Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297ab47cfaaSmrg
11298300bf1aeSmrg	  case $opt_mode in
11299ab47cfaaSmrg	  clean)
11300aa9e3350Smrg	    case " $library_names " in
11301ab47cfaaSmrg	    *" $dlname "*) ;;
11302aa9e3350Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303ab47cfaaSmrg	    esac
11304aa9e3350Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305ab47cfaaSmrg	    ;;
11306ab47cfaaSmrg	  uninstall)
11307ab47cfaaSmrg	    if test -n "$library_names"; then
11308ab47cfaaSmrg	      # Do each command in the postuninstall commands.
11309300bf1aeSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310ab47cfaaSmrg	    fi
11311ab47cfaaSmrg
11312ab47cfaaSmrg	    if test -n "$old_library"; then
11313ab47cfaaSmrg	      # Do each command in the old_postuninstall commands.
11314300bf1aeSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315ab47cfaaSmrg	    fi
11316ab47cfaaSmrg	    # FIXME: should reinstall the best remaining shared library.
11317ab47cfaaSmrg	    ;;
11318ab47cfaaSmrg	  esac
11319ab47cfaaSmrg	fi
11320ab47cfaaSmrg	;;
11321ab47cfaaSmrg
11322ab47cfaaSmrg      *.lo)
11323ab47cfaaSmrg	# Possibly a libtool object, so verify it.
113246aec45a7Smrg	if func_lalib_p "$file"; then
11325ab47cfaaSmrg
11326ab47cfaaSmrg	  # Read the .lo file
113276aec45a7Smrg	  func_source $dir/$name
11328ab47cfaaSmrg
11329ab47cfaaSmrg	  # Add PIC object to the list of files to remove.
11330300bf1aeSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331aa9e3350Smrg	    func_append rmfiles " $dir/$pic_object"
11332ab47cfaaSmrg	  fi
11333ab47cfaaSmrg
11334ab47cfaaSmrg	  # Add non-PIC object to the list of files to remove.
11335300bf1aeSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336aa9e3350Smrg	    func_append rmfiles " $dir/$non_pic_object"
11337ab47cfaaSmrg	  fi
11338ab47cfaaSmrg	fi
11339ab47cfaaSmrg	;;
11340ab47cfaaSmrg
11341ab47cfaaSmrg      *)
11342300bf1aeSmrg	if test clean = "$opt_mode"; then
11343ab47cfaaSmrg	  noexename=$name
11344ab47cfaaSmrg	  case $file in
11345ab47cfaaSmrg	  *.exe)
113466aec45a7Smrg	    func_stripname '' '.exe' "$file"
113476aec45a7Smrg	    file=$func_stripname_result
113486aec45a7Smrg	    func_stripname '' '.exe' "$name"
113496aec45a7Smrg	    noexename=$func_stripname_result
11350ab47cfaaSmrg	    # $file with .exe has already been added to rmfiles,
11351ab47cfaaSmrg	    # add $file without .exe
11352aa9e3350Smrg	    func_append rmfiles " $file"
11353ab47cfaaSmrg	    ;;
11354ab47cfaaSmrg	  esac
11355ab47cfaaSmrg	  # Do a test to see if this is a libtool program.
113566aec45a7Smrg	  if func_ltwrapper_p "$file"; then
113576aec45a7Smrg	    if func_ltwrapper_executable_p "$file"; then
113586aec45a7Smrg	      func_ltwrapper_scriptname "$file"
113596aec45a7Smrg	      relink_command=
113606aec45a7Smrg	      func_source $func_ltwrapper_scriptname_result
11361aa9e3350Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
113626aec45a7Smrg	    else
113636aec45a7Smrg	      relink_command=
113646aec45a7Smrg	      func_source $dir/$noexename
113656aec45a7Smrg	    fi
11366ab47cfaaSmrg
11367ab47cfaaSmrg	    # note $name still contains .exe if it was in $file originally
11368ab47cfaaSmrg	    # as does the version of $file that was added into $rmfiles
11369300bf1aeSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370300bf1aeSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371aa9e3350Smrg	      func_append rmfiles " $odir/lt-$name"
11372ab47cfaaSmrg	    fi
11373300bf1aeSmrg	    if test "X$noexename" != "X$name"; then
11374300bf1aeSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375ab47cfaaSmrg	    fi
11376ab47cfaaSmrg	  fi
11377ab47cfaaSmrg	fi
11378ab47cfaaSmrg	;;
11379ab47cfaaSmrg      esac
113806aec45a7Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381ab47cfaaSmrg    done
11382ab47cfaaSmrg
11383300bf1aeSmrg    # Try to remove the $objdir's in the directories where we deleted files
11384ab47cfaaSmrg    for dir in $rmdirs; do
11385ab47cfaaSmrg      if test -d "$dir"; then
113866aec45a7Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387ab47cfaaSmrg      fi
11388ab47cfaaSmrg    done
11389ab47cfaaSmrg
11390ab47cfaaSmrg    exit $exit_status
113916aec45a7Smrg}
11392ab47cfaaSmrg
11393300bf1aeSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394300bf1aeSmrg  func_mode_uninstall ${1+"$@"}
11395300bf1aeSmrgfi
113961473d951Smrg
11397aa9e3350Smrgtest -z "$opt_mode" && {
11398300bf1aeSmrg  help=$generic_help
113996aec45a7Smrg  func_fatal_help "you must specify a MODE"
114006aec45a7Smrg}
114016aec45a7Smrg
114026aec45a7Smrgtest -z "$exec_cmd" && \
11403300bf1aeSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404ab47cfaaSmrg
11405ab47cfaaSmrgif test -n "$exec_cmd"; then
114066aec45a7Smrg  eval exec "$exec_cmd"
11407ab47cfaaSmrg  exit $EXIT_FAILURE
11408ab47cfaaSmrgfi
11409ab47cfaaSmrg
114106aec45a7Smrgexit $exit_status
114115c42550eSmrg
11412ab47cfaaSmrg
11413ab47cfaaSmrg# The TAGs below are defined such that we never get into a situation
11414300bf1aeSmrg# where we disable both kinds of libraries.  Given conflicting
11415ab47cfaaSmrg# choices, we go for a static library, that is the most portable,
11416ab47cfaaSmrg# since we can't tell whether shared libraries were disabled because
11417ab47cfaaSmrg# the user asked for that or because the platform doesn't support
11418ab47cfaaSmrg# them.  This is particularly important on AIX, because we don't
11419ab47cfaaSmrg# support having both static and shared libraries enabled at the same
11420ab47cfaaSmrg# time on that platform, so we default to a shared-only configuration.
11421ab47cfaaSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422ab47cfaaSmrg# configuration.  But we'll never go from static-only to shared-only.
11423ab47cfaaSmrg
11424ab47cfaaSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
114256aec45a7Smrgbuild_libtool_libs=no
114266aec45a7Smrgbuild_old_libs=yes
11427ab47cfaaSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428ab47cfaaSmrg
11429ab47cfaaSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
114306aec45a7Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431ab47cfaaSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432ab47cfaaSmrg
11433ab47cfaaSmrg# Local Variables:
11434ab47cfaaSmrg# mode:shell-script
11435ab47cfaaSmrg# sh-indentation:2
11436ab47cfaaSmrg# End:
11437