ltmain.sh revision 6bea0e4f
13fb97780Smrg#! /usr/bin/env sh
2300346aeSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
33fb97780Smrg##               by inline-source v2019-02-19.15
4d656433aSmrg
56bea0e4fSmrg# libtool (GNU libtool) 2.5.4
6300346aeSmrg# Provide generalized library-building support services.
7d656433aSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8d656433aSmrg
96bea0e4fSmrg# Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc.
10d656433aSmrg# This is free software; see the source for copying conditions.  There is NO
11d656433aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12d656433aSmrg
13d656433aSmrg# GNU Libtool is free software; you can redistribute it and/or modify
14126a8a12Smrg# it under the terms of the GNU General Public License as published by
15126a8a12Smrg# the Free Software Foundation; either version 2 of the License, or
16126a8a12Smrg# (at your option) any later version.
17126a8a12Smrg#
18d656433aSmrg# As a special exception to the GNU General Public License,
19d656433aSmrg# if you distribute this file as part of a program or library that
20d656433aSmrg# is built using GNU Libtool, you may include this file under the
21d656433aSmrg# same distribution terms that you use for the rest of that program.
22d656433aSmrg#
23d656433aSmrg# GNU Libtool is distributed in the hope that it will be useful, but
24126a8a12Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25126a8a12Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26126a8a12Smrg# General Public License for more details.
27126a8a12Smrg#
28126a8a12Smrg# You should have received a copy of the GNU General Public License
29300346aeSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30d656433aSmrg
31d656433aSmrg
32555991fdSmrgPROGRAM=libtool
33d656433aSmrgPACKAGE=libtool
346bea0e4fSmrgVERSION=2.5.4
356bea0e4fSmrgpackage_revision=2.5.4
36d656433aSmrg
37300346aeSmrg
38300346aeSmrg## ------ ##
39300346aeSmrg## Usage. ##
40300346aeSmrg## ------ ##
41300346aeSmrg
42300346aeSmrg# Run './libtool --help' for help with using this script from the
43300346aeSmrg# command line.
44300346aeSmrg
45300346aeSmrg
46300346aeSmrg## ------------------------------- ##
47300346aeSmrg## User overridable command paths. ##
48300346aeSmrg## ------------------------------- ##
49300346aeSmrg
50300346aeSmrg# After configure completes, it has a better idea of some of the
51300346aeSmrg# shell tools we need than the defaults used by the functions shared
52300346aeSmrg# with bootstrap, so set those here where they can still be over-
53300346aeSmrg# ridden by the user, but otherwise take precedence.
54300346aeSmrg
55300346aeSmrg: ${AUTOCONF="autoconf"}
56300346aeSmrg: ${AUTOMAKE="automake"}
57300346aeSmrg
58300346aeSmrg
59300346aeSmrg## -------------------------- ##
60300346aeSmrg## Source external libraries. ##
61300346aeSmrg## -------------------------- ##
62300346aeSmrg
63300346aeSmrg# Much of our low-level functionality needs to be sourced from external
64300346aeSmrg# libraries, which are installed to $pkgauxdir.
65300346aeSmrg
66300346aeSmrg# Set a version string for this script.
673fb97780Smrgscriptversion=2019-02-19.15; # UTC
68300346aeSmrg
69300346aeSmrg# General shell script boiler plate, and helper functions.
70300346aeSmrg# Written by Gary V. Vaughan, 2004
71300346aeSmrg
723fb97780Smrg# This is free software.  There is NO warranty; not even for
733fb97780Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
743fb97780Smrg#
756bea0e4fSmrg# Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors
763fb97780Smrg#
773fb97780Smrg# This file is dual licensed under the terms of the MIT license
786bea0e4fSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
796bea0e4fSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
803fb97780Smrg# these licenses when using or redistributing this software or any of
813fb97780Smrg# the files within it.  See the URLs above, or the file `LICENSE`
823fb97780Smrg# included in the Bootstrap distribution for the full license texts.
83300346aeSmrg
843fb97780Smrg# Please report bugs or propose patches to:
853fb97780Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86300346aeSmrg
87300346aeSmrg
88300346aeSmrg## ------ ##
89300346aeSmrg## Usage. ##
90300346aeSmrg## ------ ##
91300346aeSmrg
92300346aeSmrg# Evaluate this file near the top of your script to gain access to
93300346aeSmrg# the functions and variables defined here:
94300346aeSmrg#
95300346aeSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96300346aeSmrg#
97300346aeSmrg# If you need to override any of the default environment variable
98300346aeSmrg# settings, do that before evaluating this file.
99300346aeSmrg
100300346aeSmrg
101300346aeSmrg## -------------------- ##
102300346aeSmrg## Shell normalisation. ##
103300346aeSmrg## -------------------- ##
104300346aeSmrg
105300346aeSmrg# Some shells need a little help to be as Bourne compatible as possible.
106300346aeSmrg# Before doing anything else, make sure all that help has been provided!
107300346aeSmrg
108300346aeSmrgDUALCASE=1; export DUALCASE # for MKS sh
109300346aeSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110d656433aSmrg  emulate sh
111d656433aSmrg  NULLCMD=:
112300346aeSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113d656433aSmrg  # is contrary to our usage.  Disable this feature.
114d656433aSmrg  alias -g '${1+"$@"}'='"$@"'
115d656433aSmrg  setopt NO_GLOB_SUBST
116d656433aSmrgelse
117300346aeSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118d656433aSmrgfi
119555991fdSmrg
120300346aeSmrg# NLS nuisances: We save the old values in case they are required later.
121300346aeSmrg_G_user_locale=
122300346aeSmrg_G_safe_locale=
123300346aeSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124d656433aSmrgdo
125300346aeSmrg  eval "if test set = \"\${$_G_var+set}\"; then
126300346aeSmrg          save_$_G_var=\$$_G_var
127300346aeSmrg          $_G_var=C
128300346aeSmrg	  export $_G_var
129300346aeSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130300346aeSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131d656433aSmrg	fi"
132d656433aSmrgdone
1333fb97780Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1343fb97780Smrg# in case the environment reset is needed later and the $save_* variant is not
1353fb97780Smrg# defined (see the code above).
1363fb97780SmrgLC_ALL=C
1373fb97780SmrgLANGUAGE=C
1383fb97780Smrgexport LANGUAGE LC_ALL
139d656433aSmrg
140300346aeSmrg# Make sure IFS has a sensible default
141300346aeSmrgsp=' '
142300346aeSmrgnl='
143300346aeSmrg'
144300346aeSmrgIFS="$sp	$nl"
145300346aeSmrg
1466bea0e4fSmrg# There are apparently some systems that use ';' as a PATH separator!
147300346aeSmrgif test "${PATH_SEPARATOR+set}" != set; then
148300346aeSmrg  PATH_SEPARATOR=:
149300346aeSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150300346aeSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151300346aeSmrg      PATH_SEPARATOR=';'
152300346aeSmrg  }
153300346aeSmrgfi
154d656433aSmrg
155d656433aSmrg
1563fb97780Smrg# func_unset VAR
1573fb97780Smrg# --------------
1583fb97780Smrg# Portably unset VAR.
1593fb97780Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1603fb97780Smrg# status if VAR is already unset, which might be problematic if the
1613fb97780Smrg# statement is used at the end of a function (thus poisoning its return
1623fb97780Smrg# value) or when 'set -e' is active (causing even a spurious abort of
1633fb97780Smrg# the script in this case).
1643fb97780Smrgfunc_unset ()
1653fb97780Smrg{
1663fb97780Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1673fb97780Smrg}
1683fb97780Smrg
1693fb97780Smrg
1703fb97780Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1713fb97780Smrgfunc_unset CDPATH
1723fb97780Smrg
1733fb97780Smrg# Make sure ${,E,F}GREP behave sanely.
1743fb97780Smrgfunc_unset GREP_OPTIONS
1753fb97780Smrg
176d656433aSmrg
177300346aeSmrg## ------------------------- ##
178300346aeSmrg## Locate command utilities. ##
179300346aeSmrg## ------------------------- ##
180300346aeSmrg
181300346aeSmrg
182300346aeSmrg# func_executable_p FILE
183300346aeSmrg# ----------------------
184300346aeSmrg# Check that FILE is an executable regular file.
185300346aeSmrgfunc_executable_p ()
186300346aeSmrg{
187300346aeSmrg    test -f "$1" && test -x "$1"
188300346aeSmrg}
189300346aeSmrg
190300346aeSmrg
191300346aeSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192300346aeSmrg# --------------------------------------------
193300346aeSmrg# Search for either a program that responds to --version with output
194300346aeSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195300346aeSmrg# trying all the directories in PATH with each of the elements of
196300346aeSmrg# PROGS_LIST.
197300346aeSmrg#
198300346aeSmrg# CHECK_FUNC should accept the path to a candidate program, and
199300346aeSmrg# set $func_check_prog_result if it truncates its output less than
200300346aeSmrg# $_G_path_prog_max characters.
201300346aeSmrgfunc_path_progs ()
202300346aeSmrg{
203300346aeSmrg    _G_progs_list=$1
204300346aeSmrg    _G_check_func=$2
205300346aeSmrg    _G_PATH=${3-"$PATH"}
206300346aeSmrg
207300346aeSmrg    _G_path_prog_max=0
208300346aeSmrg    _G_path_prog_found=false
209300346aeSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210300346aeSmrg    for _G_dir in $_G_PATH; do
211300346aeSmrg      IFS=$_G_save_IFS
212300346aeSmrg      test -z "$_G_dir" && _G_dir=.
213300346aeSmrg      for _G_prog_name in $_G_progs_list; do
214300346aeSmrg        for _exeext in '' .EXE; do
215300346aeSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216300346aeSmrg          func_executable_p "$_G_path_prog" || continue
217300346aeSmrg          case `"$_G_path_prog" --version 2>&1` in
218300346aeSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219300346aeSmrg            *)     $_G_check_func $_G_path_prog
220300346aeSmrg		   func_path_progs_result=$func_check_prog_result
221300346aeSmrg		   ;;
222300346aeSmrg          esac
223300346aeSmrg          $_G_path_prog_found && break 3
224300346aeSmrg        done
225300346aeSmrg      done
226300346aeSmrg    done
227300346aeSmrg    IFS=$_G_save_IFS
228300346aeSmrg    test -z "$func_path_progs_result" && {
229300346aeSmrg      echo "no acceptable sed could be found in \$PATH" >&2
230300346aeSmrg      exit 1
231300346aeSmrg    }
232300346aeSmrg}
233300346aeSmrg
234300346aeSmrg
235300346aeSmrg# We want to be able to use the functions in this file before configure
236300346aeSmrg# has figured out where the best binaries are kept, which means we have
237300346aeSmrg# to search for them ourselves - except when the results are already set
238300346aeSmrg# where we skip the searches.
239300346aeSmrg
240300346aeSmrg# Unless the user overrides by setting SED, search the path for either GNU
241300346aeSmrg# sed, or the sed that truncates its output the least.
242300346aeSmrgtest -z "$SED" && {
243300346aeSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244300346aeSmrg  for _G_i in 1 2 3 4 5 6 7; do
245300346aeSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246300346aeSmrg  done
247300346aeSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248300346aeSmrg  _G_sed_script=
249300346aeSmrg
250300346aeSmrg  func_check_prog_sed ()
251300346aeSmrg  {
252300346aeSmrg    _G_path_prog=$1
253300346aeSmrg
254300346aeSmrg    _G_count=0
255300346aeSmrg    printf 0123456789 >conftest.in
256300346aeSmrg    while :
257300346aeSmrg    do
258300346aeSmrg      cat conftest.in conftest.in >conftest.tmp
259300346aeSmrg      mv conftest.tmp conftest.in
260300346aeSmrg      cp conftest.in conftest.nl
261300346aeSmrg      echo '' >> conftest.nl
262300346aeSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263300346aeSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264300346aeSmrg      _G_count=`expr $_G_count + 1`
265300346aeSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266300346aeSmrg        # Best one so far, save it but keep looking for a better one
267300346aeSmrg        func_check_prog_result=$_G_path_prog
268300346aeSmrg        _G_path_prog_max=$_G_count
269300346aeSmrg      fi
270300346aeSmrg      # 10*(2^10) chars as input seems more than enough
271300346aeSmrg      test 10 -lt "$_G_count" && break
272300346aeSmrg    done
273300346aeSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274300346aeSmrg  }
275300346aeSmrg
2763fb97780Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277300346aeSmrg  rm -f conftest.sed
278300346aeSmrg  SED=$func_path_progs_result
279300346aeSmrg}
280300346aeSmrg
281300346aeSmrg
282300346aeSmrg# Unless the user overrides by setting GREP, search the path for either GNU
283300346aeSmrg# grep, or the grep that truncates its output the least.
284300346aeSmrgtest -z "$GREP" && {
285300346aeSmrg  func_check_prog_grep ()
286300346aeSmrg  {
287300346aeSmrg    _G_path_prog=$1
288300346aeSmrg
289300346aeSmrg    _G_count=0
290300346aeSmrg    _G_path_prog_max=0
291300346aeSmrg    printf 0123456789 >conftest.in
292300346aeSmrg    while :
293300346aeSmrg    do
294300346aeSmrg      cat conftest.in conftest.in >conftest.tmp
295300346aeSmrg      mv conftest.tmp conftest.in
296300346aeSmrg      cp conftest.in conftest.nl
297300346aeSmrg      echo 'GREP' >> conftest.nl
298300346aeSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299300346aeSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300300346aeSmrg      _G_count=`expr $_G_count + 1`
301300346aeSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302300346aeSmrg        # Best one so far, save it but keep looking for a better one
303300346aeSmrg        func_check_prog_result=$_G_path_prog
304300346aeSmrg        _G_path_prog_max=$_G_count
305300346aeSmrg      fi
306300346aeSmrg      # 10*(2^10) chars as input seems more than enough
307300346aeSmrg      test 10 -lt "$_G_count" && break
308300346aeSmrg    done
309300346aeSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310300346aeSmrg  }
311300346aeSmrg
3123fb97780Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313300346aeSmrg  GREP=$func_path_progs_result
314300346aeSmrg}
315300346aeSmrg
316300346aeSmrg
317300346aeSmrg## ------------------------------- ##
318300346aeSmrg## User overridable command paths. ##
319300346aeSmrg## ------------------------------- ##
320300346aeSmrg
321300346aeSmrg# All uppercase variable names are used for environment variables.  These
322300346aeSmrg# variables can be overridden by the user before calling a script that
323300346aeSmrg# uses them if a suitable command of that name is not already available
324300346aeSmrg# in the command search PATH.
325d656433aSmrg
326d656433aSmrg: ${CP="cp -f"}
327300346aeSmrg: ${ECHO="printf %s\n"}
328300346aeSmrg: ${EGREP="$GREP -E"}
329300346aeSmrg: ${FGREP="$GREP -F"}
330300346aeSmrg: ${LN_S="ln -s"}
331d656433aSmrg: ${MAKE="make"}
332d656433aSmrg: ${MKDIR="mkdir"}
333d656433aSmrg: ${MV="mv -f"}
334d656433aSmrg: ${RM="rm -f"}
335d656433aSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336d656433aSmrg
337d656433aSmrg
338300346aeSmrg## -------------------- ##
339300346aeSmrg## Useful sed snippets. ##
340300346aeSmrg## -------------------- ##
3413c15da26Smrg
342300346aeSmrgsed_dirname='s|/[^/]*$||'
343300346aeSmrgsed_basename='s|^.*/||'
3443c15da26Smrg
345300346aeSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
346300346aeSmrg# metacharacters that are still active within double-quoted strings.
347300346aeSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3483c15da26Smrg
349300346aeSmrg# Same as above, but do not quote variable references.
350300346aeSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3513c15da26Smrg
352300346aeSmrg# Sed substitution that turns a string into a regex matching for the
353300346aeSmrg# string literally.
354300346aeSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3553c15da26Smrg
356300346aeSmrg# Sed substitution that converts a w32 file name or path
357300346aeSmrg# that contains forward slashes, into one that contains
358300346aeSmrg# (escaped) backslashes.  A very naive implementation.
359300346aeSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360300346aeSmrg
361300346aeSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362300346aeSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363300346aeSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364300346aeSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
365300346aeSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366300346aeSmrg_G_bs='\\'
367300346aeSmrg_G_bs2='\\\\'
368300346aeSmrg_G_bs4='\\\\\\\\'
369300346aeSmrg_G_dollar='\$'
370300346aeSmrgsed_double_backslash="\
371300346aeSmrg  s/$_G_bs4/&\\
372300346aeSmrg/g
373300346aeSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374300346aeSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375300346aeSmrg  s/\n//g"
3763c15da26Smrg
3773fb97780Smrg# require_check_ifs_backslash
3783fb97780Smrg# ---------------------------
3793fb97780Smrg# Check if we can use backslash as IFS='\' separator, and set
3803fb97780Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
3813fb97780Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3823fb97780Smrgfunc_require_check_ifs_backslash ()
3833fb97780Smrg{
3843fb97780Smrg  _G_save_IFS=$IFS
3853fb97780Smrg  IFS='\'
3863fb97780Smrg  _G_check_ifs_backshlash='a\\b'
3873fb97780Smrg  for _G_i in $_G_check_ifs_backshlash
3883fb97780Smrg  do
3893fb97780Smrg  case $_G_i in
3903fb97780Smrg  a)
3913fb97780Smrg    check_ifs_backshlash_broken=false
3923fb97780Smrg    ;;
3933fb97780Smrg  '')
3943fb97780Smrg    break
3953fb97780Smrg    ;;
3963fb97780Smrg  *)
3973fb97780Smrg    check_ifs_backshlash_broken=:
3983fb97780Smrg    break
3993fb97780Smrg    ;;
4003fb97780Smrg  esac
4013fb97780Smrg  done
4023fb97780Smrg  IFS=$_G_save_IFS
4033fb97780Smrg  require_check_ifs_backslash=:
4043fb97780Smrg}
4053fb97780Smrg
406d656433aSmrg
407300346aeSmrg## ----------------- ##
408300346aeSmrg## Global variables. ##
409300346aeSmrg## ----------------- ##
410126a8a12Smrg
411300346aeSmrg# Except for the global variables explicitly listed below, the following
412300346aeSmrg# functions in the '^func_' namespace, and the '^require_' namespace
413300346aeSmrg# variables initialised in the 'Resource management' section, sourcing
414300346aeSmrg# this file will not pollute your global namespace with anything
415300346aeSmrg# else. There's no portable way to scope variables in Bourne shell
416300346aeSmrg# though, so actually running these functions will sometimes place
417300346aeSmrg# results into a variable named after the function, and often use
418300346aeSmrg# temporary variables in the '^_G_' namespace. If you are careful to
419300346aeSmrg# avoid using those namespaces casually in your sourcing script, things
420300346aeSmrg# should continue to work as you expect. And, of course, you can freely
421300346aeSmrg# overwrite any of the functions or variables defined here before
422300346aeSmrg# calling anything to customize them.
423555991fdSmrg
424300346aeSmrgEXIT_SUCCESS=0
425300346aeSmrgEXIT_FAILURE=1
426300346aeSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427300346aeSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428555991fdSmrg
429300346aeSmrg# Allow overriding, eg assuming that you follow the convention of
430300346aeSmrg# putting '$debug_cmd' at the start of all your functions, you can get
431300346aeSmrg# bash to show function call trace with:
432300346aeSmrg#
433300346aeSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434300346aeSmrgdebug_cmd=${debug_cmd-":"}
435300346aeSmrgexit_cmd=:
436555991fdSmrg
437300346aeSmrg# By convention, finish your script with:
438300346aeSmrg#
439300346aeSmrg#    exit $exit_status
440300346aeSmrg#
441300346aeSmrg# so that you can set exit_status to non-zero if you want to indicate
442300346aeSmrg# something went wrong during execution without actually bailing out at
443300346aeSmrg# the point of failure.
444300346aeSmrgexit_status=$EXIT_SUCCESS
445555991fdSmrg
446300346aeSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447300346aeSmrg# is ksh but when the shell is invoked as "sh" and the current value of
448300346aeSmrg# the _XPG environment variable is not equal to 1 (one), the special
449300346aeSmrg# positional parameter $0, within a function call, is the name of the
450300346aeSmrg# function.
451300346aeSmrgprogpath=$0
452126a8a12Smrg
453300346aeSmrg# The name of this program.
454300346aeSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455126a8a12Smrg
456300346aeSmrg# Make sure we have an absolute progpath for reexecution:
457d656433aSmrgcase $progpath in
458d656433aSmrg  [\\/]*|[A-Za-z]:\\*) ;;
459d656433aSmrg  *[\\/]*)
460300346aeSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461d656433aSmrg     progdir=`cd "$progdir" && pwd`
462300346aeSmrg     progpath=$progdir/$progname
463d656433aSmrg     ;;
464d656433aSmrg  *)
465300346aeSmrg     _G_IFS=$IFS
4660a6b08f8Smrg     IFS=${PATH_SEPARATOR-:}
467d656433aSmrg     for progdir in $PATH; do
468300346aeSmrg       IFS=$_G_IFS
469d656433aSmrg       test -x "$progdir/$progname" && break
470d656433aSmrg     done
471300346aeSmrg     IFS=$_G_IFS
472d656433aSmrg     test -n "$progdir" || progdir=`pwd`
473300346aeSmrg     progpath=$progdir/$progname
474d656433aSmrg     ;;
475d656433aSmrgesac
476126a8a12Smrg
477d656433aSmrg
478300346aeSmrg## ----------------- ##
479300346aeSmrg## Standard options. ##
480300346aeSmrg## ----------------- ##
4813c15da26Smrg
482300346aeSmrg# The following options affect the operation of the functions defined
483300346aeSmrg# below, and should be set appropriately depending on run-time para-
484300346aeSmrg# meters passed on the command line.
485d656433aSmrg
486d656433aSmrgopt_dry_run=false
487d656433aSmrgopt_quiet=false
488d656433aSmrgopt_verbose=false
489d656433aSmrg
490300346aeSmrg# Categories 'all' and 'none' are always available.  Append any others
491300346aeSmrg# you will pass as the first argument to func_warning from your own
492300346aeSmrg# code.
493300346aeSmrgwarning_categories=
494126a8a12Smrg
495300346aeSmrg# By default, display warnings according to 'opt_warning_types'.  Set
496300346aeSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497300346aeSmrg# treat the next displayed warning as a fatal error.
498300346aeSmrgwarning_func=func_warn_and_continue
499126a8a12Smrg
500300346aeSmrg# Set to 'all' to display all warnings, 'none' to suppress all
501300346aeSmrg# warnings, or a space delimited list of some subset of
502300346aeSmrg# 'warning_categories' to display only the listed warnings.
503300346aeSmrgopt_warning_types=all
504126a8a12Smrg
505555991fdSmrg
506300346aeSmrg## -------------------- ##
507300346aeSmrg## Resource management. ##
508300346aeSmrg## -------------------- ##
509126a8a12Smrg
510300346aeSmrg# This section contains definitions for functions that each ensure a
511300346aeSmrg# particular resource (a file, or a non-empty configuration variable for
512300346aeSmrg# example) is available, and if appropriate to extract default values
513300346aeSmrg# from pertinent package files. Call them using their associated
514300346aeSmrg# 'require_*' variable to ensure that they are executed, at most, once.
515300346aeSmrg#
516300346aeSmrg# It's entirely deliberate that calling these functions can set
517300346aeSmrg# variables that don't obey the namespace limitations obeyed by the rest
518300346aeSmrg# of this file, in order that that they be as useful as possible to
519300346aeSmrg# callers.
520126a8a12Smrg
521126a8a12Smrg
522300346aeSmrg# require_term_colors
523300346aeSmrg# -------------------
524300346aeSmrg# Allow display of bold text on terminals that support it.
525300346aeSmrgrequire_term_colors=func_require_term_colors
526300346aeSmrgfunc_require_term_colors ()
527d656433aSmrg{
528300346aeSmrg    $debug_cmd
529300346aeSmrg
530300346aeSmrg    test -t 1 && {
531300346aeSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532300346aeSmrg      # precedence, because most terminfo databases neglect to describe
533300346aeSmrg      # whether color sequences are supported.
534300346aeSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535300346aeSmrg
536300346aeSmrg      if test 1 = "$USE_ANSI_COLORS"; then
537300346aeSmrg        # Standard ANSI escape sequences
538300346aeSmrg        tc_reset='[0m'
539300346aeSmrg        tc_bold='[1m';   tc_standout='[7m'
540300346aeSmrg        tc_red='[31m';   tc_green='[32m'
541300346aeSmrg        tc_blue='[34m';  tc_cyan='[36m'
542300346aeSmrg      else
543300346aeSmrg        # Otherwise trust the terminfo database after all.
544300346aeSmrg        test -n "`tput sgr0 2>/dev/null`" && {
545300346aeSmrg          tc_reset=`tput sgr0`
546300346aeSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547300346aeSmrg          tc_standout=$tc_bold
548300346aeSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549300346aeSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550300346aeSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551300346aeSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552300346aeSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553300346aeSmrg        }
554300346aeSmrg      fi
555300346aeSmrg    }
556126a8a12Smrg
557300346aeSmrg    require_term_colors=:
558d656433aSmrg}
559126a8a12Smrg
560126a8a12Smrg
561300346aeSmrg## ----------------- ##
562300346aeSmrg## Function library. ##
563300346aeSmrg## ----------------- ##
564300346aeSmrg
565300346aeSmrg# This section contains a variety of useful functions to call in your
566300346aeSmrg# scripts. Take note of the portable wrappers for features provided by
567300346aeSmrg# some modern shells, which will fall back to slower equivalents on
568300346aeSmrg# less featureful shells.
569300346aeSmrg
570300346aeSmrg
571300346aeSmrg# func_append VAR VALUE
572300346aeSmrg# ---------------------
573300346aeSmrg# Append VALUE onto the existing contents of VAR.
574300346aeSmrg
575300346aeSmrg  # We should try to minimise forks, especially on Windows where they are
576300346aeSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577300346aeSmrg  # being used:
578300346aeSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579300346aeSmrg    : ${_G_HAVE_ARITH_OP="yes"}
580300346aeSmrg    : ${_G_HAVE_XSI_OPS="yes"}
581300346aeSmrg    # The += operator was introduced in bash 3.1
582300346aeSmrg    case $BASH_VERSION in
583300346aeSmrg      [12].* | 3.0 | 3.0*) ;;
584300346aeSmrg      *)
585300346aeSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586300346aeSmrg        ;;
587300346aeSmrg    esac
588300346aeSmrg  fi
589300346aeSmrg
590300346aeSmrg  # _G_HAVE_PLUSEQ_OP
591300346aeSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5926bea0e4fSmrg  # usable or anything else if it does not work.
593300346aeSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594300346aeSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595300346aeSmrg    && _G_HAVE_PLUSEQ_OP=yes
596300346aeSmrg
597300346aeSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598300346aeSmrgthen
599300346aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
600300346aeSmrg  eval 'func_append ()
601300346aeSmrg  {
602300346aeSmrg    $debug_cmd
603300346aeSmrg
604300346aeSmrg    eval "$1+=\$2"
605300346aeSmrg  }'
606300346aeSmrgelse
607300346aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608300346aeSmrg  func_append ()
609300346aeSmrg  {
610300346aeSmrg    $debug_cmd
611300346aeSmrg
612300346aeSmrg    eval "$1=\$$1\$2"
613300346aeSmrg  }
614300346aeSmrgfi
615300346aeSmrg
616300346aeSmrg
617300346aeSmrg# func_append_quoted VAR VALUE
618300346aeSmrg# ----------------------------
619300346aeSmrg# Quote VALUE and append to the end of shell variable VAR, separated
620300346aeSmrg# by a space.
621300346aeSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622300346aeSmrg  eval 'func_append_quoted ()
623300346aeSmrg  {
624300346aeSmrg    $debug_cmd
625300346aeSmrg
6263fb97780Smrg    func_quote_arg pretty "$2"
6273fb97780Smrg    eval "$1+=\\ \$func_quote_arg_result"
628300346aeSmrg  }'
629300346aeSmrgelse
630300346aeSmrg  func_append_quoted ()
631300346aeSmrg  {
632300346aeSmrg    $debug_cmd
633300346aeSmrg
6343fb97780Smrg    func_quote_arg pretty "$2"
6353fb97780Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636300346aeSmrg  }
637300346aeSmrgfi
638300346aeSmrg
639300346aeSmrg
640300346aeSmrg# func_append_uniq VAR VALUE
641300346aeSmrg# --------------------------
642300346aeSmrg# Append unique VALUE onto the existing contents of VAR, assuming
643300346aeSmrg# entries are delimited by the first character of VALUE.  For example:
644300346aeSmrg#
645300346aeSmrg#   func_append_uniq options " --another-option option-argument"
646300346aeSmrg#
647300346aeSmrg# will only append to $options if " --another-option option-argument "
648300346aeSmrg# is not already present somewhere in $options already (note spaces at
649300346aeSmrg# each end implied by leading space in second argument).
650300346aeSmrgfunc_append_uniq ()
651300346aeSmrg{
652300346aeSmrg    $debug_cmd
653300346aeSmrg
654300346aeSmrg    eval _G_current_value='`$ECHO $'$1'`'
655300346aeSmrg    _G_delim=`expr "$2" : '\(.\)'`
656300346aeSmrg
657300346aeSmrg    case $_G_delim$_G_current_value$_G_delim in
658300346aeSmrg      *"$2$_G_delim"*) ;;
659300346aeSmrg      *) func_append "$@" ;;
660300346aeSmrg    esac
661300346aeSmrg}
662300346aeSmrg
663300346aeSmrg
664300346aeSmrg# func_arith TERM...
665300346aeSmrg# ------------------
666300346aeSmrg# Set func_arith_result to the result of evaluating TERMs.
667300346aeSmrg  test -z "$_G_HAVE_ARITH_OP" \
668300346aeSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669300346aeSmrg    && _G_HAVE_ARITH_OP=yes
670300346aeSmrg
671300346aeSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
672300346aeSmrg  eval 'func_arith ()
673300346aeSmrg  {
674300346aeSmrg    $debug_cmd
675300346aeSmrg
676300346aeSmrg    func_arith_result=$(( $* ))
677300346aeSmrg  }'
678300346aeSmrgelse
679300346aeSmrg  func_arith ()
680300346aeSmrg  {
681300346aeSmrg    $debug_cmd
682300346aeSmrg
683300346aeSmrg    func_arith_result=`expr "$@"`
684300346aeSmrg  }
685300346aeSmrgfi
686300346aeSmrg
687300346aeSmrg
688300346aeSmrg# func_basename FILE
689300346aeSmrg# ------------------
690300346aeSmrg# Set func_basename_result to FILE with everything up to and including
691300346aeSmrg# the last / stripped.
692300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
693300346aeSmrg  # If this shell supports suffix pattern removal, then use it to avoid
694300346aeSmrg  # forking. Hide the definitions single quotes in case the shell chokes
695300346aeSmrg  # on unsupported syntax...
696300346aeSmrg  _b='func_basename_result=${1##*/}'
697300346aeSmrg  _d='case $1 in
698300346aeSmrg        */*) func_dirname_result=${1%/*}$2 ;;
699300346aeSmrg        *  ) func_dirname_result=$3        ;;
700300346aeSmrg      esac'
701300346aeSmrg
702300346aeSmrgelse
703300346aeSmrg  # ...otherwise fall back to using sed.
704300346aeSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705300346aeSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706300346aeSmrg      if test "X$func_dirname_result" = "X$1"; then
707300346aeSmrg        func_dirname_result=$3
708300346aeSmrg      else
709300346aeSmrg        func_append func_dirname_result "$2"
710300346aeSmrg      fi'
711300346aeSmrgfi
712300346aeSmrg
713300346aeSmrgeval 'func_basename ()
714300346aeSmrg{
715300346aeSmrg    $debug_cmd
716300346aeSmrg
717300346aeSmrg    '"$_b"'
718300346aeSmrg}'
719300346aeSmrg
720300346aeSmrg
721300346aeSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722300346aeSmrg# -------------------------------------------
723300346aeSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724300346aeSmrg# otherwise set result to NONDIR_REPLACEMENT.
725300346aeSmrgeval 'func_dirname ()
726300346aeSmrg{
727300346aeSmrg    $debug_cmd
728300346aeSmrg
729300346aeSmrg    '"$_d"'
730300346aeSmrg}'
731300346aeSmrg
732300346aeSmrg
733300346aeSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734300346aeSmrg# --------------------------------------------------------
735300346aeSmrg# Perform func_basename and func_dirname in a single function
736300346aeSmrg# call:
737300346aeSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738300346aeSmrg#             add APPEND to the result, otherwise set result
739300346aeSmrg#             to NONDIR_REPLACEMENT.
740300346aeSmrg#             value returned in "$func_dirname_result"
741300346aeSmrg#   basename: Compute filename of FILE.
7426bea0e4fSmrg#             value returned in "$func_basename_result"
743300346aeSmrg# For efficiency, we do not delegate to the functions above but instead
744300346aeSmrg# duplicate the functionality here.
745300346aeSmrgeval 'func_dirname_and_basename ()
746300346aeSmrg{
747300346aeSmrg    $debug_cmd
748300346aeSmrg
749300346aeSmrg    '"$_b"'
750300346aeSmrg    '"$_d"'
751300346aeSmrg}'
752300346aeSmrg
753300346aeSmrg
754300346aeSmrg# func_echo ARG...
755300346aeSmrg# ----------------
756300346aeSmrg# Echo program name prefixed message.
757300346aeSmrgfunc_echo ()
758300346aeSmrg{
759300346aeSmrg    $debug_cmd
760300346aeSmrg
761300346aeSmrg    _G_message=$*
762300346aeSmrg
763300346aeSmrg    func_echo_IFS=$IFS
764300346aeSmrg    IFS=$nl
765300346aeSmrg    for _G_line in $_G_message; do
766300346aeSmrg      IFS=$func_echo_IFS
767300346aeSmrg      $ECHO "$progname: $_G_line"
768300346aeSmrg    done
769300346aeSmrg    IFS=$func_echo_IFS
770300346aeSmrg}
771300346aeSmrg
772300346aeSmrg
773300346aeSmrg# func_echo_all ARG...
774300346aeSmrg# --------------------
775300346aeSmrg# Invoke $ECHO with all args, space-separated.
776300346aeSmrgfunc_echo_all ()
777300346aeSmrg{
778300346aeSmrg    $ECHO "$*"
779300346aeSmrg}
780300346aeSmrg
781300346aeSmrg
782300346aeSmrg# func_echo_infix_1 INFIX ARG...
783300346aeSmrg# ------------------------------
784300346aeSmrg# Echo program name, followed by INFIX on the first line, with any
785300346aeSmrg# additional lines not showing INFIX.
786300346aeSmrgfunc_echo_infix_1 ()
787300346aeSmrg{
788300346aeSmrg    $debug_cmd
789300346aeSmrg
790300346aeSmrg    $require_term_colors
791300346aeSmrg
792300346aeSmrg    _G_infix=$1; shift
793300346aeSmrg    _G_indent=$_G_infix
794300346aeSmrg    _G_prefix="$progname: $_G_infix: "
795300346aeSmrg    _G_message=$*
796300346aeSmrg
797300346aeSmrg    # Strip color escape sequences before counting printable length
798300346aeSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799300346aeSmrg    do
800300346aeSmrg      test -n "$_G_tc" && {
801300346aeSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802300346aeSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803300346aeSmrg      }
804300346aeSmrg    done
805300346aeSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806300346aeSmrg
807300346aeSmrg    func_echo_infix_1_IFS=$IFS
808300346aeSmrg    IFS=$nl
809300346aeSmrg    for _G_line in $_G_message; do
810300346aeSmrg      IFS=$func_echo_infix_1_IFS
811300346aeSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812300346aeSmrg      _G_prefix=$_G_indent
813300346aeSmrg    done
814300346aeSmrg    IFS=$func_echo_infix_1_IFS
815300346aeSmrg}
816300346aeSmrg
817300346aeSmrg
818300346aeSmrg# func_error ARG...
819300346aeSmrg# -----------------
820300346aeSmrg# Echo program name prefixed message to standard error.
821300346aeSmrgfunc_error ()
822300346aeSmrg{
823300346aeSmrg    $debug_cmd
824300346aeSmrg
825300346aeSmrg    $require_term_colors
826300346aeSmrg
827300346aeSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828300346aeSmrg}
829300346aeSmrg
830300346aeSmrg
831300346aeSmrg# func_fatal_error ARG...
832300346aeSmrg# -----------------------
833300346aeSmrg# Echo program name prefixed message to standard error, and exit.
834300346aeSmrgfunc_fatal_error ()
835300346aeSmrg{
836300346aeSmrg    $debug_cmd
837300346aeSmrg
838300346aeSmrg    func_error "$*"
839300346aeSmrg    exit $EXIT_FAILURE
840300346aeSmrg}
841300346aeSmrg
842300346aeSmrg
843300346aeSmrg# func_grep EXPRESSION FILENAME
844300346aeSmrg# -----------------------------
845d656433aSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846d656433aSmrgfunc_grep ()
847d656433aSmrg{
848300346aeSmrg    $debug_cmd
849300346aeSmrg
850d656433aSmrg    $GREP "$1" "$2" >/dev/null 2>&1
851d656433aSmrg}
852d656433aSmrg
853d656433aSmrg
854300346aeSmrg# func_len STRING
855300346aeSmrg# ---------------
856300346aeSmrg# Set func_len_result to the length of STRING. STRING may not
857300346aeSmrg# start with a hyphen.
858300346aeSmrg  test -z "$_G_HAVE_XSI_OPS" \
859300346aeSmrg    && (eval 'x=a/b/c;
860300346aeSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861300346aeSmrg    && _G_HAVE_XSI_OPS=yes
862300346aeSmrg
863300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
864300346aeSmrg  eval 'func_len ()
865300346aeSmrg  {
866300346aeSmrg    $debug_cmd
867300346aeSmrg
868300346aeSmrg    func_len_result=${#1}
869300346aeSmrg  }'
870300346aeSmrgelse
871300346aeSmrg  func_len ()
872300346aeSmrg  {
873300346aeSmrg    $debug_cmd
874300346aeSmrg
875300346aeSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876300346aeSmrg  }
877300346aeSmrgfi
878300346aeSmrg
879300346aeSmrg
880300346aeSmrg# func_mkdir_p DIRECTORY-PATH
881300346aeSmrg# ---------------------------
882d656433aSmrg# Make sure the entire path to DIRECTORY-PATH is available.
883d656433aSmrgfunc_mkdir_p ()
884d656433aSmrg{
885300346aeSmrg    $debug_cmd
886300346aeSmrg
887300346aeSmrg    _G_directory_path=$1
888300346aeSmrg    _G_dir_list=
889d656433aSmrg
890300346aeSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891d656433aSmrg
892300346aeSmrg      # Protect directory names starting with '-'
893300346aeSmrg      case $_G_directory_path in
894300346aeSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895d656433aSmrg      esac
896d656433aSmrg
897d656433aSmrg      # While some portion of DIR does not yet exist...
898300346aeSmrg      while test ! -d "$_G_directory_path"; do
899d656433aSmrg        # ...make a list in topmost first order.  Use a colon delimited
9006bea0e4fSmrg	# list in case some portion of path contains whitespace.
901300346aeSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902d656433aSmrg
903d656433aSmrg        # If the last portion added has no slash in it, the list is done
904300346aeSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905d656433aSmrg
906d656433aSmrg        # ...otherwise throw away the child directory and loop
907300346aeSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908d656433aSmrg      done
909300346aeSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910d656433aSmrg
911300346aeSmrg      func_mkdir_p_IFS=$IFS; IFS=:
912300346aeSmrg      for _G_dir in $_G_dir_list; do
913300346aeSmrg	IFS=$func_mkdir_p_IFS
914300346aeSmrg        # mkdir can fail with a 'File exist' error if two processes
915d656433aSmrg        # try to create one of the directories concurrently.  Don't
916d656433aSmrg        # stop in that case!
917300346aeSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918d656433aSmrg      done
919300346aeSmrg      IFS=$func_mkdir_p_IFS
920d656433aSmrg
921d656433aSmrg      # Bail out if we (or some other process) failed to create a directory.
922300346aeSmrg      test -d "$_G_directory_path" || \
923300346aeSmrg        func_fatal_error "Failed to create '$1'"
924d656433aSmrg    fi
925d656433aSmrg}
926126a8a12Smrg
927126a8a12Smrg
928300346aeSmrg# func_mktempdir [BASENAME]
929300346aeSmrg# -------------------------
930126a8a12Smrg# Make a temporary directory that won't clash with other running
931126a8a12Smrg# libtool processes, and avoids race conditions if possible.  If
932300346aeSmrg# given, BASENAME is the basename for that directory.
933126a8a12Smrgfunc_mktempdir ()
934126a8a12Smrg{
935300346aeSmrg    $debug_cmd
936300346aeSmrg
937300346aeSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938126a8a12Smrg
939300346aeSmrg    if test : = "$opt_dry_run"; then
940126a8a12Smrg      # Return a directory name, but don't create it in dry-run mode
941300346aeSmrg      _G_tmpdir=$_G_template-$$
942126a8a12Smrg    else
943126a8a12Smrg
944126a8a12Smrg      # If mktemp works, use that first and foremost
945300346aeSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946126a8a12Smrg
947300346aeSmrg      if test ! -d "$_G_tmpdir"; then
948d656433aSmrg        # Failing that, at least try and use $RANDOM to avoid a race
949300346aeSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950126a8a12Smrg
951300346aeSmrg        func_mktempdir_umask=`umask`
952d656433aSmrg        umask 0077
953300346aeSmrg        $MKDIR "$_G_tmpdir"
954300346aeSmrg        umask $func_mktempdir_umask
955126a8a12Smrg      fi
956126a8a12Smrg
957126a8a12Smrg      # If we're not in dry-run mode, bomb out on failure
958300346aeSmrg      test -d "$_G_tmpdir" || \
959300346aeSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960126a8a12Smrg    fi
961126a8a12Smrg
962300346aeSmrg    $ECHO "$_G_tmpdir"
963126a8a12Smrg}
964126a8a12Smrg
965126a8a12Smrg
966300346aeSmrg# func_normal_abspath PATH
967300346aeSmrg# ------------------------
968300346aeSmrg# Remove doubled-up and trailing slashes, "." path components,
969300346aeSmrg# and cancel out any ".." path components in PATH after making
970300346aeSmrg# it an absolute path.
971300346aeSmrgfunc_normal_abspath ()
972126a8a12Smrg{
973300346aeSmrg    $debug_cmd
974d656433aSmrg
975300346aeSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
976300346aeSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977300346aeSmrg    _G_pathcdr='s|^/[^/]*||'
978300346aeSmrg    _G_removedotparts=':dotsl
979300346aeSmrg		s|/\./|/|g
980300346aeSmrg		t dotsl
981300346aeSmrg		s|/\.$|/|'
982300346aeSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
983300346aeSmrg    _G_finalslash='s|/*$|/|'
984300346aeSmrg
985300346aeSmrg    # Start from root dir and reassemble the path.
986300346aeSmrg    func_normal_abspath_result=
987300346aeSmrg    func_normal_abspath_tpath=$1
988300346aeSmrg    func_normal_abspath_altnamespace=
989300346aeSmrg    case $func_normal_abspath_tpath in
990300346aeSmrg      "")
991300346aeSmrg        # Empty path, that just means $cwd.
992300346aeSmrg        func_stripname '' '/' "`pwd`"
993300346aeSmrg        func_normal_abspath_result=$func_stripname_result
994300346aeSmrg        return
995300346aeSmrg        ;;
996300346aeSmrg      # The next three entries are used to spot a run of precisely
997300346aeSmrg      # two leading slashes without using negated character classes;
998300346aeSmrg      # we take advantage of case's first-match behaviour.
999300346aeSmrg      ///*)
1000300346aeSmrg        # Unusual form of absolute path, do nothing.
1001300346aeSmrg        ;;
1002300346aeSmrg      //*)
1003300346aeSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004300346aeSmrg        # and for example Cygwin uses it to access remote file shares
1005300346aeSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006300346aeSmrg        func_normal_abspath_altnamespace=/
1007300346aeSmrg        ;;
1008300346aeSmrg      /*)
1009300346aeSmrg        # Absolute path, do nothing.
1010d656433aSmrg        ;;
1011d656433aSmrg      *)
1012300346aeSmrg        # Relative path, prepend $cwd.
1013300346aeSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014300346aeSmrg        ;;
1015126a8a12Smrg    esac
1016300346aeSmrg
1017300346aeSmrg    # Cancel out all the simple stuff to save iterations.  We also want
1018300346aeSmrg    # the path to end with a slash for ease of parsing, so make sure
1019300346aeSmrg    # there is one (and only one) here.
1020300346aeSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021300346aeSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022300346aeSmrg    while :; do
1023300346aeSmrg      # Processed it all yet?
1024300346aeSmrg      if test / = "$func_normal_abspath_tpath"; then
1025300346aeSmrg        # If we ascended to the root using ".." the result may be empty now.
1026300346aeSmrg        if test -z "$func_normal_abspath_result"; then
1027300346aeSmrg          func_normal_abspath_result=/
1028300346aeSmrg        fi
1029300346aeSmrg        break
1030300346aeSmrg      fi
1031300346aeSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032300346aeSmrg          -e "$_G_pathcar"`
1033300346aeSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034300346aeSmrg          -e "$_G_pathcdr"`
1035300346aeSmrg      # Figure out what to do with it
1036300346aeSmrg      case $func_normal_abspath_tcomponent in
1037300346aeSmrg        "")
1038300346aeSmrg          # Trailing empty path component, ignore it.
1039300346aeSmrg          ;;
1040300346aeSmrg        ..)
1041300346aeSmrg          # Parent dir; strip last assembled component from result.
1042300346aeSmrg          func_dirname "$func_normal_abspath_result"
1043300346aeSmrg          func_normal_abspath_result=$func_dirname_result
1044300346aeSmrg          ;;
1045300346aeSmrg        *)
1046300346aeSmrg          # Actual path component, append it.
1047300346aeSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048300346aeSmrg          ;;
1049300346aeSmrg      esac
1050300346aeSmrg    done
1051300346aeSmrg    # Restore leading double-slash if one was found on entry.
1052300346aeSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053300346aeSmrg}
1054300346aeSmrg
1055300346aeSmrg
1056300346aeSmrg# func_notquiet ARG...
1057300346aeSmrg# --------------------
1058300346aeSmrg# Echo program name prefixed message only when not in quiet mode.
1059300346aeSmrgfunc_notquiet ()
1060300346aeSmrg{
1061300346aeSmrg    $debug_cmd
1062300346aeSmrg
1063300346aeSmrg    $opt_quiet || func_echo ${1+"$@"}
1064300346aeSmrg
1065300346aeSmrg    # A bug in bash halts the script if the last line of a function
1066300346aeSmrg    # fails when set -e is in force, so we need another command to
1067300346aeSmrg    # work around that:
1068300346aeSmrg    :
1069300346aeSmrg}
1070300346aeSmrg
1071300346aeSmrg
1072300346aeSmrg# func_relative_path SRCDIR DSTDIR
1073300346aeSmrg# --------------------------------
1074300346aeSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075300346aeSmrgfunc_relative_path ()
1076300346aeSmrg{
1077300346aeSmrg    $debug_cmd
1078300346aeSmrg
1079300346aeSmrg    func_relative_path_result=
1080300346aeSmrg    func_normal_abspath "$1"
1081300346aeSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082300346aeSmrg    func_normal_abspath "$2"
1083300346aeSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1084300346aeSmrg
1085300346aeSmrg    # Ascend the tree starting from libdir
1086300346aeSmrg    while :; do
1087300346aeSmrg      # check if we have found a prefix of bindir
1088300346aeSmrg      case $func_relative_path_tbindir in
1089300346aeSmrg        $func_relative_path_tlibdir)
1090300346aeSmrg          # found an exact match
1091300346aeSmrg          func_relative_path_tcancelled=
1092300346aeSmrg          break
1093300346aeSmrg          ;;
1094300346aeSmrg        $func_relative_path_tlibdir*)
1095300346aeSmrg          # found a matching prefix
1096300346aeSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097300346aeSmrg          func_relative_path_tcancelled=$func_stripname_result
1098300346aeSmrg          if test -z "$func_relative_path_result"; then
1099300346aeSmrg            func_relative_path_result=.
1100300346aeSmrg          fi
1101300346aeSmrg          break
1102300346aeSmrg          ;;
1103300346aeSmrg        *)
1104300346aeSmrg          func_dirname $func_relative_path_tlibdir
1105300346aeSmrg          func_relative_path_tlibdir=$func_dirname_result
1106300346aeSmrg          if test -z "$func_relative_path_tlibdir"; then
1107300346aeSmrg            # Have to descend all the way to the root!
1108300346aeSmrg            func_relative_path_result=../$func_relative_path_result
1109300346aeSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110300346aeSmrg            break
1111300346aeSmrg          fi
1112300346aeSmrg          func_relative_path_result=../$func_relative_path_result
1113300346aeSmrg          ;;
1114300346aeSmrg      esac
1115300346aeSmrg    done
1116300346aeSmrg
1117300346aeSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1118300346aeSmrg    func_stripname '' '/' "$func_relative_path_result"
1119300346aeSmrg    func_relative_path_result=$func_stripname_result
1120300346aeSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121300346aeSmrg    if test -n "$func_stripname_result"; then
1122300346aeSmrg      func_append func_relative_path_result "/$func_stripname_result"
1123300346aeSmrg    fi
1124300346aeSmrg
1125300346aeSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126300346aeSmrg    if test -n "$func_relative_path_result"; then
1127300346aeSmrg      func_stripname './' '' "$func_relative_path_result"
1128300346aeSmrg      func_relative_path_result=$func_stripname_result
1129300346aeSmrg    fi
1130300346aeSmrg
1131300346aeSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132300346aeSmrg
1133300346aeSmrg    :
1134126a8a12Smrg}
1135126a8a12Smrg
1136126a8a12Smrg
11373fb97780Smrg# func_quote_portable EVAL ARG
11383fb97780Smrg# ----------------------------
11393fb97780Smrg# Internal function to portably implement func_quote_arg.  Note that we still
11403fb97780Smrg# keep attention to performance here so we as much as possible try to avoid
11413fb97780Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11423fb97780Smrgfunc_quote_portable ()
1143300346aeSmrg{
1144300346aeSmrg    $debug_cmd
1145300346aeSmrg
11463fb97780Smrg    $require_check_ifs_backslash
11473fb97780Smrg
11483fb97780Smrg    func_quote_portable_result=$2
11493fb97780Smrg
11503fb97780Smrg    # one-time-loop (easy break)
11513fb97780Smrg    while true
11523fb97780Smrg    do
11533fb97780Smrg      if $1; then
11543fb97780Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11553fb97780Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11563fb97780Smrg        break
1157300346aeSmrg      fi
1158300346aeSmrg
11593fb97780Smrg      # Quote for eval.
11603fb97780Smrg      case $func_quote_portable_result in
11613fb97780Smrg        *[\\\`\"\$]*)
11623fb97780Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11633fb97780Smrg          # contains the shell wildcard characters.
11643fb97780Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11653fb97780Smrg            :*|*[\[\*\?]*)
11663fb97780Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11673fb97780Smrg                  | $SED "$sed_quote_subst"`
11683fb97780Smrg              break
11693fb97780Smrg              ;;
11703fb97780Smrg          esac
11713fb97780Smrg
11723fb97780Smrg          func_quote_portable_old_IFS=$IFS
11733fb97780Smrg          for _G_char in '\' '`' '"' '$'
11743fb97780Smrg          do
11753fb97780Smrg            # STATE($1) PREV($2) SEPARATOR($3)
11763fb97780Smrg            set start "" ""
11773fb97780Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11783fb97780Smrg            IFS=$_G_char
11793fb97780Smrg            for _G_part in $func_quote_portable_result
11803fb97780Smrg            do
11813fb97780Smrg              case $1 in
11823fb97780Smrg              quote)
11833fb97780Smrg                func_append func_quote_portable_result "$3$2"
11843fb97780Smrg                set quote "$_G_part" "\\$_G_char"
11853fb97780Smrg                ;;
11863fb97780Smrg              start)
11873fb97780Smrg                set first "" ""
11883fb97780Smrg                func_quote_portable_result=
11893fb97780Smrg                ;;
11903fb97780Smrg              first)
11913fb97780Smrg                set quote "$_G_part" ""
11923fb97780Smrg                ;;
11933fb97780Smrg              esac
11943fb97780Smrg            done
11953fb97780Smrg          done
11963fb97780Smrg          IFS=$func_quote_portable_old_IFS
1197300346aeSmrg          ;;
11983fb97780Smrg        *) ;;
1199300346aeSmrg      esac
12003fb97780Smrg      break
1201300346aeSmrg    done
12023fb97780Smrg
12033fb97780Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12043fb97780Smrg    case $func_quote_portable_result in
12053fb97780Smrg      # double-quote args containing shell metacharacters to delay
12063fb97780Smrg      # word splitting, command substitution and variable expansion
12073fb97780Smrg      # for a subsequent eval.
12083fb97780Smrg      # many bourne shells cannot handle close brackets correctly
12093fb97780Smrg      # in scan sets, so we specify it separately.
12103fb97780Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12113fb97780Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
12123fb97780Smrg        ;;
12133fb97780Smrg    esac
1214300346aeSmrg}
1215300346aeSmrg
1216300346aeSmrg
12173fb97780Smrg# func_quotefast_eval ARG
12183fb97780Smrg# -----------------------
12193fb97780Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12203fb97780Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12213fb97780Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12223fb97780Smrg  printf -v _GL_test_printf_tilde %q '~'
12233fb97780Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
12243fb97780Smrg    func_quotefast_eval ()
12253fb97780Smrg    {
12263fb97780Smrg      printf -v func_quotefast_eval_result %q "$1"
12273fb97780Smrg    }
12283fb97780Smrg  else
12293fb97780Smrg    # Broken older Bash implementations.  Make those faster too if possible.
12303fb97780Smrg    func_quotefast_eval ()
12313fb97780Smrg    {
12323fb97780Smrg      case $1 in
12333fb97780Smrg        '~'*)
12343fb97780Smrg          func_quote_portable false "$1"
12353fb97780Smrg          func_quotefast_eval_result=$func_quote_portable_result
12363fb97780Smrg          ;;
12373fb97780Smrg        *)
12383fb97780Smrg          printf -v func_quotefast_eval_result %q "$1"
12393fb97780Smrg          ;;
12403fb97780Smrg      esac
12413fb97780Smrg    }
12423fb97780Smrg  fi
12433fb97780Smrgelse
12443fb97780Smrg  func_quotefast_eval ()
12453fb97780Smrg  {
12463fb97780Smrg    func_quote_portable false "$1"
12473fb97780Smrg    func_quotefast_eval_result=$func_quote_portable_result
12483fb97780Smrg  }
12493fb97780Smrgfi
1250300346aeSmrg
12513fb97780Smrg
12523fb97780Smrg# func_quote_arg MODEs ARG
12533fb97780Smrg# ------------------------
12543fb97780Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12553fb97780Smrg# specifiers listed below separated by ',' character.  This function returns two
12563fb97780Smrg# values:
12573fb97780Smrg#   i) func_quote_arg_result
12583fb97780Smrg#      double-quoted (when needed), suitable for a subsequent eval
12593fb97780Smrg#  ii) func_quote_arg_unquoted_result
12603fb97780Smrg#      has all characters that are still active within double
12613fb97780Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12623fb97780Smrg#
12633fb97780Smrg# Available modes:
12643fb97780Smrg# ----------------
12653fb97780Smrg# 'eval' (default)
12663fb97780Smrg#       - escape shell special characters
12673fb97780Smrg# 'expand'
12683fb97780Smrg#       - the same as 'eval';  but do not quote variable references
12693fb97780Smrg# 'pretty'
12703fb97780Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12713fb97780Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12723fb97780Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
12733fb97780Smrg# 'unquoted'
12743fb97780Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12753fb97780Smrg#         wrapping double-quotes.
12763fb97780Smrg#
12773fb97780Smrg# Examples for 'func_quote_arg pretty,unquoted string':
12783fb97780Smrg#
12793fb97780Smrg#   string      | *_result              | *_unquoted_result
12803fb97780Smrg#   ------------+-----------------------+-------------------
12813fb97780Smrg#   "           | \"                    | \"
12823fb97780Smrg#   a b         | "a b"                 | a b
12833fb97780Smrg#   "a b"       | "\"a b\""             | \"a b\"
12843fb97780Smrg#   *           | "*"                   | *
12853fb97780Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12863fb97780Smrg#
12873fb97780Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12883fb97780Smrg#
12893fb97780Smrg#   string        |   *_result          |  *_unquoted_result
12903fb97780Smrg#   --------------+---------------------+--------------------
12913fb97780Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12923fb97780Smrgfunc_quote_arg ()
12933fb97780Smrg{
12943fb97780Smrg    _G_quote_expand=false
12953fb97780Smrg    case ,$1, in
12963fb97780Smrg      *,expand,*)
12973fb97780Smrg        _G_quote_expand=:
12983fb97780Smrg        ;;
1299d656433aSmrg    esac
1300d656433aSmrg
13013fb97780Smrg    case ,$1, in
13023fb97780Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
13033fb97780Smrg        func_quote_portable $_G_quote_expand "$2"
13043fb97780Smrg        func_quote_arg_result=$func_quote_portable_result
13053fb97780Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13063fb97780Smrg        ;;
13073fb97780Smrg      *)
13083fb97780Smrg        # Faster quote-for-eval for some shells.
13093fb97780Smrg        func_quotefast_eval "$2"
13103fb97780Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311d656433aSmrg        ;;
1312d656433aSmrg    esac
13133fb97780Smrg}
13143fb97780Smrg
1315d656433aSmrg
13163fb97780Smrg# func_quote MODEs ARGs...
13173fb97780Smrg# ------------------------
13183fb97780Smrg# Quote all ARGs to be evaled later and join them into single command.  See
13193fb97780Smrg# func_quote_arg's description for more info.
13203fb97780Smrgfunc_quote ()
13213fb97780Smrg{
13223fb97780Smrg    $debug_cmd
13233fb97780Smrg    _G_func_quote_mode=$1 ; shift
13243fb97780Smrg    func_quote_result=
13253fb97780Smrg    while test 0 -lt $#; do
13263fb97780Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
13273fb97780Smrg      if test -n "$func_quote_result"; then
13283fb97780Smrg        func_append func_quote_result " $func_quote_arg_result"
13293fb97780Smrg      else
13303fb97780Smrg        func_append func_quote_result "$func_quote_arg_result"
13313fb97780Smrg      fi
13323fb97780Smrg      shift
13333fb97780Smrg    done
1334300346aeSmrg}
1335300346aeSmrg
1336300346aeSmrg
1337300346aeSmrg# func_stripname PREFIX SUFFIX NAME
1338300346aeSmrg# ---------------------------------
1339300346aeSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340300346aeSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1341300346aeSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342300346aeSmrg# dot (in which case that matches only a dot).
1343300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344300346aeSmrg  eval 'func_stripname ()
1345300346aeSmrg  {
1346300346aeSmrg    $debug_cmd
1347300346aeSmrg
1348300346aeSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349300346aeSmrg    # positional parameters, so assign one to ordinary variable first.
1350300346aeSmrg    func_stripname_result=$3
1351300346aeSmrg    func_stripname_result=${func_stripname_result#"$1"}
1352300346aeSmrg    func_stripname_result=${func_stripname_result%"$2"}
1353300346aeSmrg  }'
1354300346aeSmrgelse
1355300346aeSmrg  func_stripname ()
1356300346aeSmrg  {
1357300346aeSmrg    $debug_cmd
1358300346aeSmrg
1359300346aeSmrg    case $2 in
1360300346aeSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361300346aeSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362300346aeSmrg    esac
1363300346aeSmrg  }
1364300346aeSmrgfi
1365300346aeSmrg
1366300346aeSmrg
1367300346aeSmrg# func_show_eval CMD [FAIL_EXP]
1368300346aeSmrg# -----------------------------
1369300346aeSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370300346aeSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371300346aeSmrg# is given, then evaluate it.
1372300346aeSmrgfunc_show_eval ()
1373300346aeSmrg{
1374300346aeSmrg    $debug_cmd
1375300346aeSmrg
1376300346aeSmrg    _G_cmd=$1
1377300346aeSmrg    _G_fail_exp=${2-':'}
1378300346aeSmrg
13793fb97780Smrg    func_quote_arg pretty,expand "$_G_cmd"
13803fb97780Smrg    eval "func_notquiet $func_quote_arg_result"
1381300346aeSmrg
1382300346aeSmrg    $opt_dry_run || {
1383300346aeSmrg      eval "$_G_cmd"
1384300346aeSmrg      _G_status=$?
1385300346aeSmrg      if test 0 -ne "$_G_status"; then
1386300346aeSmrg	eval "(exit $_G_status); $_G_fail_exp"
1387300346aeSmrg      fi
1388300346aeSmrg    }
1389300346aeSmrg}
1390300346aeSmrg
1391300346aeSmrg
1392300346aeSmrg# func_show_eval_locale CMD [FAIL_EXP]
1393300346aeSmrg# ------------------------------------
1394300346aeSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395300346aeSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396300346aeSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397300346aeSmrgfunc_show_eval_locale ()
1398300346aeSmrg{
1399300346aeSmrg    $debug_cmd
1400300346aeSmrg
1401300346aeSmrg    _G_cmd=$1
1402300346aeSmrg    _G_fail_exp=${2-':'}
1403300346aeSmrg
1404300346aeSmrg    $opt_quiet || {
14053fb97780Smrg      func_quote_arg expand,pretty "$_G_cmd"
14063fb97780Smrg      eval "func_echo $func_quote_arg_result"
1407300346aeSmrg    }
1408300346aeSmrg
1409300346aeSmrg    $opt_dry_run || {
1410300346aeSmrg      eval "$_G_user_locale
1411300346aeSmrg	    $_G_cmd"
1412300346aeSmrg      _G_status=$?
1413300346aeSmrg      eval "$_G_safe_locale"
1414300346aeSmrg      if test 0 -ne "$_G_status"; then
1415300346aeSmrg	eval "(exit $_G_status); $_G_fail_exp"
1416300346aeSmrg      fi
1417300346aeSmrg    }
1418300346aeSmrg}
1419300346aeSmrg
1420300346aeSmrg
1421300346aeSmrg# func_tr_sh
1422300346aeSmrg# ----------
1423300346aeSmrg# Turn $1 into a string suitable for a shell variable name.
1424300346aeSmrg# Result is stored in $func_tr_sh_result.  All characters
1425300346aeSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426300346aeSmrg# if $1 begins with a digit, a '_' is prepended as well.
1427300346aeSmrgfunc_tr_sh ()
1428300346aeSmrg{
1429300346aeSmrg    $debug_cmd
1430300346aeSmrg
1431300346aeSmrg    case $1 in
1432300346aeSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433300346aeSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434300346aeSmrg      ;;
1435300346aeSmrg    * )
1436300346aeSmrg      func_tr_sh_result=$1
1437300346aeSmrg      ;;
1438300346aeSmrg    esac
1439300346aeSmrg}
1440300346aeSmrg
1441300346aeSmrg
1442300346aeSmrg# func_verbose ARG...
1443300346aeSmrg# -------------------
1444300346aeSmrg# Echo program name prefixed message in verbose mode only.
1445300346aeSmrgfunc_verbose ()
1446300346aeSmrg{
1447300346aeSmrg    $debug_cmd
1448300346aeSmrg
1449300346aeSmrg    $opt_verbose && func_echo "$*"
1450300346aeSmrg
1451300346aeSmrg    :
1452300346aeSmrg}
1453300346aeSmrg
1454300346aeSmrg
1455300346aeSmrg# func_warn_and_continue ARG...
1456300346aeSmrg# -----------------------------
1457300346aeSmrg# Echo program name prefixed warning message to standard error.
1458300346aeSmrgfunc_warn_and_continue ()
1459300346aeSmrg{
1460300346aeSmrg    $debug_cmd
1461300346aeSmrg
1462300346aeSmrg    $require_term_colors
1463300346aeSmrg
1464300346aeSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465300346aeSmrg}
1466300346aeSmrg
1467300346aeSmrg
1468300346aeSmrg# func_warning CATEGORY ARG...
1469300346aeSmrg# ----------------------------
1470300346aeSmrg# Echo program name prefixed warning message to standard error. Warning
1471300346aeSmrg# messages can be filtered according to CATEGORY, where this function
1472300346aeSmrg# elides messages where CATEGORY is not listed in the global variable
1473300346aeSmrg# 'opt_warning_types'.
1474300346aeSmrgfunc_warning ()
1475300346aeSmrg{
1476300346aeSmrg    $debug_cmd
1477300346aeSmrg
1478300346aeSmrg    # CATEGORY must be in the warning_categories list!
1479300346aeSmrg    case " $warning_categories " in
1480300346aeSmrg      *" $1 "*) ;;
1481300346aeSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1482300346aeSmrg    esac
1483300346aeSmrg
1484300346aeSmrg    _G_category=$1
1485300346aeSmrg    shift
1486300346aeSmrg
1487300346aeSmrg    case " $opt_warning_types " in
1488300346aeSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489300346aeSmrg    esac
1490126a8a12Smrg}
1491126a8a12Smrg
1492126a8a12Smrg
1493300346aeSmrg# func_sort_ver VER1 VER2
1494300346aeSmrg# -----------------------
1495300346aeSmrg# 'sort -V' is not generally available.
1496300346aeSmrg# Note this deviates from the version comparison in automake
1497300346aeSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498300346aeSmrg# but this should suffice as we won't be specifying old
1499300346aeSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1500300346aeSmrg# If we did want full compatibility then we should probably
1501300346aeSmrg# use m4_version_compare from autoconf.
1502300346aeSmrgfunc_sort_ver ()
1503300346aeSmrg{
1504300346aeSmrg    $debug_cmd
1505300346aeSmrg
1506300346aeSmrg    printf '%s\n%s\n' "$1" "$2" \
1507300346aeSmrg      | 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
1508300346aeSmrg}
1509300346aeSmrg
1510300346aeSmrg# func_lt_ver PREV CURR
1511300346aeSmrg# ---------------------
1512300346aeSmrg# Return true if PREV and CURR are in the correct order according to
1513300346aeSmrg# func_sort_ver, otherwise false.  Use it like this:
1514300346aeSmrg#
1515300346aeSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516300346aeSmrgfunc_lt_ver ()
1517300346aeSmrg{
1518300346aeSmrg    $debug_cmd
1519300346aeSmrg
1520300346aeSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521300346aeSmrg}
1522300346aeSmrg
1523300346aeSmrg
1524300346aeSmrg# Local variables:
1525300346aeSmrg# mode: shell-script
1526300346aeSmrg# sh-indentation: 2
1527300346aeSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528300346aeSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529300346aeSmrg# time-stamp-time-zone: "UTC"
1530300346aeSmrg# End:
1531300346aeSmrg#! /bin/sh
1532300346aeSmrg
1533300346aeSmrg# A portable, pluggable option parser for Bourne shell.
1534300346aeSmrg# Written by Gary V. Vaughan, 2010
1535300346aeSmrg
15363fb97780Smrg# This is free software.  There is NO warranty; not even for
15373fb97780Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15383fb97780Smrg#
15396bea0e4fSmrg# Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors
15403fb97780Smrg#
15413fb97780Smrg# This file is dual licensed under the terms of the MIT license
15426bea0e4fSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
15436bea0e4fSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15443fb97780Smrg# these licenses when using or redistributing this software or any of
15453fb97780Smrg# the files within it.  See the URLs above, or the file `LICENSE`
15463fb97780Smrg# included in the Bootstrap distribution for the full license texts.
1547300346aeSmrg
15483fb97780Smrg# Please report bugs or propose patches to:
15493fb97780Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550300346aeSmrg
15513fb97780Smrg# Set a version string for this script.
15523fb97780Smrgscriptversion=2019-02-19.15; # UTC
1553300346aeSmrg
1554300346aeSmrg
1555300346aeSmrg## ------ ##
1556300346aeSmrg## Usage. ##
1557300346aeSmrg## ------ ##
1558300346aeSmrg
1559300346aeSmrg# This file is a library for parsing options in your shell scripts along
1560300346aeSmrg# with assorted other useful supporting features that you can make use
1561300346aeSmrg# of too.
1562300346aeSmrg#
1563300346aeSmrg# For the simplest scripts you might need only:
1564300346aeSmrg#
1565300346aeSmrg#   #!/bin/sh
1566300346aeSmrg#   . relative/path/to/funclib.sh
1567300346aeSmrg#   . relative/path/to/options-parser
1568300346aeSmrg#   scriptversion=1.0
1569300346aeSmrg#   func_options ${1+"$@"}
1570300346aeSmrg#   eval set dummy "$func_options_result"; shift
1571300346aeSmrg#   ...rest of your script...
1572300346aeSmrg#
1573300346aeSmrg# In order for the '--version' option to work, you will need to have a
1574300346aeSmrg# suitably formatted comment like the one at the top of this file
15753fb97780Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576300346aeSmrg#
1577300346aeSmrg# For '-h' and '--help' to work, you will also need a one line
1578300346aeSmrg# description of your script's purpose in a comment directly above the
1579300346aeSmrg# '# Written by ' line, like the one at the top of this file.
1580300346aeSmrg#
1581300346aeSmrg# The default options also support '--debug', which will turn on shell
1582300346aeSmrg# execution tracing (see the comment above debug_cmd below for another
1583300346aeSmrg# use), and '--verbose' and the func_verbose function to allow your script
1584300346aeSmrg# to display verbose messages only when your user has specified
1585300346aeSmrg# '--verbose'.
1586300346aeSmrg#
15873fb97780Smrg# After sourcing this file, you can plug in processing for additional
1588300346aeSmrg# options by amending the variables from the 'Configuration' section
1589300346aeSmrg# below, and following the instructions in the 'Option parsing'
1590300346aeSmrg# section further down.
1591300346aeSmrg
1592300346aeSmrg## -------------- ##
1593300346aeSmrg## Configuration. ##
1594300346aeSmrg## -------------- ##
1595300346aeSmrg
1596300346aeSmrg# You should override these variables in your script after sourcing this
1597300346aeSmrg# file so that they reflect the customisations you have added to the
1598300346aeSmrg# option parser.
1599300346aeSmrg
1600300346aeSmrg# The usage line for option parsing errors and the start of '-h' and
1601300346aeSmrg# '--help' output messages. You can embed shell variables for delayed
1602300346aeSmrg# expansion at the time the message is displayed, but you will need to
1603300346aeSmrg# quote other shell meta-characters carefully to prevent them being
1604300346aeSmrg# expanded when the contents are evaled.
1605300346aeSmrgusage='$progpath [OPTION]...'
1606300346aeSmrg
1607300346aeSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1608300346aeSmrg# override it after sourcing this library to reflect the full set of
1609300346aeSmrg# options your script accepts.
1610300346aeSmrgusage_message="\
1611300346aeSmrg       --debug        enable verbose shell tracing
1612300346aeSmrg   -W, --warnings=CATEGORY
1613300346aeSmrg                      report the warnings falling in CATEGORY [all]
1614300346aeSmrg   -v, --verbose      verbosely report processing
1615300346aeSmrg       --version      print version information and exit
1616300346aeSmrg   -h, --help         print short or long help message and exit
1617300346aeSmrg"
1618300346aeSmrg
1619300346aeSmrg# Additional text appended to 'usage_message' in response to '--help'.
1620300346aeSmrglong_help_message="
1621300346aeSmrgWarning categories include:
1622300346aeSmrg       'all'          show all warnings
1623300346aeSmrg       'none'         turn off all the warnings
1624300346aeSmrg       'error'        warnings are treated as fatal errors"
1625300346aeSmrg
1626300346aeSmrg# Help message printed before fatal option parsing errors.
1627300346aeSmrgfatal_help="Try '\$progname --help' for more information."
1628300346aeSmrg
1629300346aeSmrg
1630300346aeSmrg
1631300346aeSmrg## ------------------------- ##
1632300346aeSmrg## Hook function management. ##
1633300346aeSmrg## ------------------------- ##
1634300346aeSmrg
1635300346aeSmrg# This section contains functions for adding, removing, and running hooks
16363fb97780Smrg# in the main code.  A hook is just a list of function names that can be
16373fb97780Smrg# run in order later on.
1638300346aeSmrg
1639300346aeSmrg# func_hookable FUNC_NAME
1640300346aeSmrg# -----------------------
1641300346aeSmrg# Declare that FUNC_NAME will run hooks added with
1642300346aeSmrg# 'func_add_hook FUNC_NAME ...'.
1643300346aeSmrgfunc_hookable ()
1644300346aeSmrg{
1645300346aeSmrg    $debug_cmd
1646300346aeSmrg
1647300346aeSmrg    func_append hookable_fns " $1"
1648300346aeSmrg}
1649300346aeSmrg
1650300346aeSmrg
1651300346aeSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1652300346aeSmrg# ---------------------------------
1653300346aeSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654300346aeSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1655300346aeSmrgfunc_add_hook ()
1656300346aeSmrg{
1657300346aeSmrg    $debug_cmd
1658300346aeSmrg
1659300346aeSmrg    case " $hookable_fns " in
1660300346aeSmrg      *" $1 "*) ;;
1661300346aeSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662300346aeSmrg    esac
1663300346aeSmrg
1664300346aeSmrg    eval func_append ${1}_hooks '" $2"'
1665300346aeSmrg}
1666300346aeSmrg
1667300346aeSmrg
1668300346aeSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669300346aeSmrg# ------------------------------------
16703fb97780Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
16713fb97780Smrg# FUNC_NAME.
1672300346aeSmrgfunc_remove_hook ()
1673300346aeSmrg{
1674300346aeSmrg    $debug_cmd
1675300346aeSmrg
1676300346aeSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677300346aeSmrg}
1678300346aeSmrg
1679300346aeSmrg
16803fb97780Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16813fb97780Smrg# ---------------------------------------------
16823fb97780Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16833fb97780Smrg# *_result variable of FUNC_NAME_B.
16843fb97780Smrgfunc_propagate_result ()
16853fb97780Smrg{
16863fb97780Smrg    $debug_cmd
16873fb97780Smrg
16883fb97780Smrg    func_propagate_result_result=:
16893fb97780Smrg    if eval "test \"\${${1}_result+set}\" = set"
16903fb97780Smrg    then
16913fb97780Smrg      eval "${2}_result=\$${1}_result"
16923fb97780Smrg    else
16933fb97780Smrg      func_propagate_result_result=false
16943fb97780Smrg    fi
16953fb97780Smrg}
16963fb97780Smrg
16973fb97780Smrg
1698300346aeSmrg# func_run_hooks FUNC_NAME [ARG]...
1699300346aeSmrg# ---------------------------------
1700300346aeSmrg# Run all hook functions registered to FUNC_NAME.
17013fb97780Smrg# It's assumed that the list of hook functions contains nothing more
1702300346aeSmrg# than a whitespace-delimited list of legal shell function names, and
1703300346aeSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1704300346aeSmrg# whitespace.
1705300346aeSmrgfunc_run_hooks ()
1706300346aeSmrg{
1707300346aeSmrg    $debug_cmd
1708300346aeSmrg
1709300346aeSmrg    case " $hookable_fns " in
1710300346aeSmrg      *" $1 "*) ;;
17113fb97780Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712300346aeSmrg    esac
1713300346aeSmrg
1714300346aeSmrg    eval _G_hook_fns=\$$1_hooks; shift
1715300346aeSmrg
1716300346aeSmrg    for _G_hook in $_G_hook_fns; do
17173fb97780Smrg      func_unset "${_G_hook}_result"
17183fb97780Smrg      eval $_G_hook '${1+"$@"}'
17193fb97780Smrg      func_propagate_result $_G_hook func_run_hooks
17203fb97780Smrg      if $func_propagate_result_result; then
17213fb97780Smrg        eval set dummy "$func_run_hooks_result"; shift
17223fb97780Smrg      fi
1723300346aeSmrg    done
1724300346aeSmrg}
1725300346aeSmrg
1726300346aeSmrg
1727300346aeSmrg
1728300346aeSmrg## --------------- ##
1729300346aeSmrg## Option parsing. ##
1730300346aeSmrg## --------------- ##
1731300346aeSmrg
1732300346aeSmrg# In order to add your own option parsing hooks, you must accept the
17333fb97780Smrg# full positional parameter list from your hook function.  You may remove
17343fb97780Smrg# or edit any options that you action, and then pass back the remaining
17353fb97780Smrg# unprocessed options in '<hooked_function_name>_result', escaped
17363fb97780Smrg# suitably for 'eval'.
17373fb97780Smrg#
17383fb97780Smrg# The '<hooked_function_name>_result' variable is automatically unset
17393fb97780Smrg# before your hook gets called; for best performance, only set the
17403fb97780Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17413fb97780Smrg# function unnecessarily because it can be an expensive operation on some
17423fb97780Smrg# machines).
17433fb97780Smrg#
17443fb97780Smrg# Like this:
1745300346aeSmrg#
1746300346aeSmrg#    my_options_prep ()
1747300346aeSmrg#    {
1748300346aeSmrg#        $debug_cmd
1749300346aeSmrg#
1750300346aeSmrg#        # Extend the existing usage message.
1751300346aeSmrg#        usage_message=$usage_message'
1752300346aeSmrg#      -s, --silent       don'\''t print informational messages
1753300346aeSmrg#    '
17543fb97780Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
17553fb97780Smrg#        # my_options_prep_result variable intact.
1756300346aeSmrg#    }
1757300346aeSmrg#    func_add_hook func_options_prep my_options_prep
1758300346aeSmrg#
1759300346aeSmrg#
1760300346aeSmrg#    my_silent_option ()
1761300346aeSmrg#    {
1762300346aeSmrg#        $debug_cmd
1763300346aeSmrg#
17643fb97780Smrg#        args_changed=false
17653fb97780Smrg#
17663fb97780Smrg#        # Note that, for efficiency, we parse as many options as we can
1767300346aeSmrg#        # recognise in a loop before passing the remainder back to the
1768300346aeSmrg#        # caller on the first unrecognised argument we encounter.
1769300346aeSmrg#        while test $# -gt 0; do
1770300346aeSmrg#          opt=$1; shift
1771300346aeSmrg#          case $opt in
17723fb97780Smrg#            --silent|-s) opt_silent=:
17733fb97780Smrg#                         args_changed=:
17743fb97780Smrg#                         ;;
1775300346aeSmrg#            # Separate non-argument short options:
1776300346aeSmrg#            -s*)         func_split_short_opt "$_G_opt"
1777300346aeSmrg#                         set dummy "$func_split_short_opt_name" \
1778300346aeSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779300346aeSmrg#                         shift
17803fb97780Smrg#                         args_changed=:
1781300346aeSmrg#                         ;;
17823fb97780Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17833fb97780Smrg#                         # is added back to "$@" in case we need it later,
17843fb97780Smrg#                         # if $args_changed was set to 'true'.
17853fb97780Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786300346aeSmrg#          esac
1787300346aeSmrg#        done
1788300346aeSmrg#
17893fb97780Smrg#        # Only call 'func_quote' here if we processed at least one argument.
17903fb97780Smrg#        if $args_changed; then
17913fb97780Smrg#          func_quote eval ${1+"$@"}
17923fb97780Smrg#          my_silent_option_result=$func_quote_result
17933fb97780Smrg#        fi
1794300346aeSmrg#    }
1795300346aeSmrg#    func_add_hook func_parse_options my_silent_option
1796300346aeSmrg#
1797300346aeSmrg#
1798300346aeSmrg#    my_option_validation ()
1799300346aeSmrg#    {
1800300346aeSmrg#        $debug_cmd
1801300346aeSmrg#
1802300346aeSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803300346aeSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1804300346aeSmrg#    }
1805300346aeSmrg#    func_add_hook func_validate_options my_option_validation
1806300346aeSmrg#
18073fb97780Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808300346aeSmrg# options you parse.  It's preferable to append if you can, so that
1809300346aeSmrg# multiple option parsing hooks can be added safely.
1810300346aeSmrg
1811300346aeSmrg
18123fb97780Smrg# func_options_finish [ARG]...
18133fb97780Smrg# ----------------------------
18143fb97780Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18153fb97780Smrgfunc_options_finish ()
18163fb97780Smrg{
18173fb97780Smrg    $debug_cmd
18183fb97780Smrg
18193fb97780Smrg    func_run_hooks func_options ${1+"$@"}
18203fb97780Smrg    func_propagate_result func_run_hooks func_options_finish
18213fb97780Smrg}
18223fb97780Smrg
18233fb97780Smrg
1824300346aeSmrg# func_options [ARG]...
1825300346aeSmrg# ---------------------
1826300346aeSmrg# All the functions called inside func_options are hookable. See the
1827300346aeSmrg# individual implementations for details.
1828300346aeSmrgfunc_hookable func_options
1829300346aeSmrgfunc_options ()
1830126a8a12Smrg{
1831300346aeSmrg    $debug_cmd
1832126a8a12Smrg
18333fb97780Smrg    _G_options_quoted=false
1834d656433aSmrg
18353fb97780Smrg    for my_func in options_prep parse_options validate_options options_finish
18363fb97780Smrg    do
18373fb97780Smrg      func_unset func_${my_func}_result
18383fb97780Smrg      func_unset func_run_hooks_result
18393fb97780Smrg      eval func_$my_func '${1+"$@"}'
18403fb97780Smrg      func_propagate_result func_$my_func func_options
18413fb97780Smrg      if $func_propagate_result_result; then
18423fb97780Smrg        eval set dummy "$func_options_result"; shift
18433fb97780Smrg        _G_options_quoted=:
18443fb97780Smrg      fi
18453fb97780Smrg    done
1846300346aeSmrg
18473fb97780Smrg    $_G_options_quoted || {
18483fb97780Smrg      # As we (func_options) are top-level options-parser function and
18493fb97780Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18503fb97780Smrg      # caller.
18513fb97780Smrg      func_quote eval ${1+"$@"}
18523fb97780Smrg      func_options_result=$func_quote_result
18533fb97780Smrg    }
1854126a8a12Smrg}
1855126a8a12Smrg
1856d656433aSmrg
1857300346aeSmrg# func_options_prep [ARG]...
1858300346aeSmrg# --------------------------
1859300346aeSmrg# All initialisations required before starting the option parse loop.
1860300346aeSmrg# Note that when calling hook functions, we pass through the list of
1861300346aeSmrg# positional parameters.  If a hook function modifies that list, and
18623fb97780Smrg# needs to propagate that back to rest of this script, then the complete
18633fb97780Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864300346aeSmrgfunc_hookable func_options_prep
1865300346aeSmrgfunc_options_prep ()
1866126a8a12Smrg{
1867300346aeSmrg    $debug_cmd
1868126a8a12Smrg
1869300346aeSmrg    # Option defaults:
1870300346aeSmrg    opt_verbose=false
1871300346aeSmrg    opt_warning_types=
1872d656433aSmrg
1873300346aeSmrg    func_run_hooks func_options_prep ${1+"$@"}
18743fb97780Smrg    func_propagate_result func_run_hooks func_options_prep
1875126a8a12Smrg}
1876126a8a12Smrg
1877300346aeSmrg
1878300346aeSmrg# func_parse_options [ARG]...
1879300346aeSmrg# ---------------------------
1880300346aeSmrg# The main option parsing loop.
1881300346aeSmrgfunc_hookable func_parse_options
1882300346aeSmrgfunc_parse_options ()
18833c15da26Smrg{
1884300346aeSmrg    $debug_cmd
1885300346aeSmrg
18863fb97780Smrg    _G_parse_options_requote=false
1887300346aeSmrg    # this just eases exit handling
1888300346aeSmrg    while test $# -gt 0; do
1889300346aeSmrg      # Defer to hook functions for initial option parsing, so they
1890300346aeSmrg      # get priority in the event of reusing an option name.
1891300346aeSmrg      func_run_hooks func_parse_options ${1+"$@"}
18923fb97780Smrg      func_propagate_result func_run_hooks func_parse_options
18933fb97780Smrg      if $func_propagate_result_result; then
18943fb97780Smrg        eval set dummy "$func_parse_options_result"; shift
18953fb97780Smrg        # Even though we may have changed "$@", we passed the "$@" array
18963fb97780Smrg        # down into the hook and it quoted it for us (because we are in
18973fb97780Smrg        # this if-branch).  No need to quote it again.
18983fb97780Smrg        _G_parse_options_requote=false
18993fb97780Smrg      fi
1900300346aeSmrg
1901300346aeSmrg      # Break out of the loop if we already parsed every option.
1902300346aeSmrg      test $# -gt 0 || break
1903300346aeSmrg
19043fb97780Smrg      # We expect that one of the options parsed in this function matches
19053fb97780Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19063fb97780Smrg      _G_match_parse_options=:
1907300346aeSmrg      _G_opt=$1
1908300346aeSmrg      shift
1909300346aeSmrg      case $_G_opt in
1910300346aeSmrg        --debug|-x)   debug_cmd='set -x'
19113fb97780Smrg                      func_echo "enabling shell trace mode" >&2
1912300346aeSmrg                      $debug_cmd
1913300346aeSmrg                      ;;
1914300346aeSmrg
1915300346aeSmrg        --no-warnings|--no-warning|--no-warn)
1916300346aeSmrg                      set dummy --warnings none ${1+"$@"}
1917300346aeSmrg                      shift
1918300346aeSmrg		      ;;
1919300346aeSmrg
1920300346aeSmrg        --warnings|--warning|-W)
19213fb97780Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19223fb97780Smrg                        _G_parse_options_requote=:
19233fb97780Smrg                        break
19243fb97780Smrg                      fi
1925300346aeSmrg                      case " $warning_categories $1" in
1926300346aeSmrg                        *" $1 "*)
1927300346aeSmrg                          # trailing space prevents matching last $1 above
1928300346aeSmrg                          func_append_uniq opt_warning_types " $1"
1929300346aeSmrg                          ;;
1930300346aeSmrg                        *all)
1931300346aeSmrg                          opt_warning_types=$warning_categories
1932300346aeSmrg                          ;;
1933300346aeSmrg                        *none)
1934300346aeSmrg                          opt_warning_types=none
1935300346aeSmrg                          warning_func=:
1936300346aeSmrg                          ;;
1937300346aeSmrg                        *error)
1938300346aeSmrg                          opt_warning_types=$warning_categories
1939300346aeSmrg                          warning_func=func_fatal_error
1940300346aeSmrg                          ;;
1941300346aeSmrg                        *)
1942300346aeSmrg                          func_fatal_error \
1943300346aeSmrg                             "unsupported warning category: '$1'"
1944300346aeSmrg                          ;;
1945300346aeSmrg                      esac
1946300346aeSmrg                      shift
1947300346aeSmrg                      ;;
1948300346aeSmrg
1949300346aeSmrg        --verbose|-v) opt_verbose=: ;;
1950300346aeSmrg        --version)    func_version ;;
1951300346aeSmrg        -\?|-h)       func_usage ;;
1952300346aeSmrg        --help)       func_help ;;
1953300346aeSmrg
1954300346aeSmrg	# Separate optargs to long options (plugins may need this):
1955300346aeSmrg	--*=*)        func_split_equals "$_G_opt"
1956300346aeSmrg	              set dummy "$func_split_equals_lhs" \
1957300346aeSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1958300346aeSmrg                      shift
1959300346aeSmrg                      ;;
1960300346aeSmrg
1961300346aeSmrg       # Separate optargs to short options:
1962300346aeSmrg        -W*)
1963300346aeSmrg                      func_split_short_opt "$_G_opt"
1964300346aeSmrg                      set dummy "$func_split_short_opt_name" \
1965300346aeSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966300346aeSmrg                      shift
1967300346aeSmrg                      ;;
1968300346aeSmrg
1969300346aeSmrg        # Separate non-argument short options:
1970300346aeSmrg        -\?*|-h*|-v*|-x*)
1971300346aeSmrg                      func_split_short_opt "$_G_opt"
1972300346aeSmrg                      set dummy "$func_split_short_opt_name" \
1973300346aeSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974300346aeSmrg                      shift
1975300346aeSmrg                      ;;
1976300346aeSmrg
19773fb97780Smrg        --)           _G_parse_options_requote=: ; break ;;
1978300346aeSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19793fb97780Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19803fb97780Smrg                      _G_match_parse_options=false
19813fb97780Smrg                      break
19823fb97780Smrg                      ;;
1983300346aeSmrg      esac
19843fb97780Smrg
19853fb97780Smrg      if $_G_match_parse_options; then
19863fb97780Smrg        _G_parse_options_requote=:
19873fb97780Smrg      fi
1988300346aeSmrg    done
1989300346aeSmrg
19903fb97780Smrg    if $_G_parse_options_requote; then
19913fb97780Smrg      # save modified positional parameters for caller
19923fb97780Smrg      func_quote eval ${1+"$@"}
19933fb97780Smrg      func_parse_options_result=$func_quote_result
19943fb97780Smrg    fi
19953c15da26Smrg}
19963c15da26Smrg
1997126a8a12Smrg
1998300346aeSmrg# func_validate_options [ARG]...
1999300346aeSmrg# ------------------------------
2000300346aeSmrg# Perform any sanity checks on option settings and/or unconsumed
2001300346aeSmrg# arguments.
2002300346aeSmrgfunc_hookable func_validate_options
2003300346aeSmrgfunc_validate_options ()
2004d656433aSmrg{
2005300346aeSmrg    $debug_cmd
20063c15da26Smrg
2007300346aeSmrg    # Display all warnings if -W was not given.
2008300346aeSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009300346aeSmrg
2010300346aeSmrg    func_run_hooks func_validate_options ${1+"$@"}
20113fb97780Smrg    func_propagate_result func_run_hooks func_validate_options
2012300346aeSmrg
2013300346aeSmrg    # Bail if the options were screwed!
2014300346aeSmrg    $exit_cmd $EXIT_FAILURE
2015d656433aSmrg}
2016d656433aSmrg
2017300346aeSmrg
2018300346aeSmrg
2019300346aeSmrg## ----------------- ##
2020300346aeSmrg## Helper functions. ##
2021300346aeSmrg## ----------------- ##
2022300346aeSmrg
2023300346aeSmrg# This section contains the helper functions used by the rest of the
2024300346aeSmrg# hookable option parser framework in ascii-betical order.
2025300346aeSmrg
2026300346aeSmrg
2027300346aeSmrg# func_fatal_help ARG...
2028300346aeSmrg# ----------------------
2029300346aeSmrg# Echo program name prefixed message to standard error, followed by
2030300346aeSmrg# a help hint, and exit.
2031300346aeSmrgfunc_fatal_help ()
2032d656433aSmrg{
2033300346aeSmrg    $debug_cmd
20343c15da26Smrg
2035300346aeSmrg    eval \$ECHO \""Usage: $usage"\"
2036300346aeSmrg    eval \$ECHO \""$fatal_help"\"
2037300346aeSmrg    func_error ${1+"$@"}
2038300346aeSmrg    exit $EXIT_FAILURE
2039d656433aSmrg}
2040d656433aSmrg
2041300346aeSmrg
2042300346aeSmrg# func_help
2043300346aeSmrg# ---------
2044300346aeSmrg# Echo long help message to standard output and exit.
2045d656433aSmrgfunc_help ()
2046d656433aSmrg{
2047300346aeSmrg    $debug_cmd
2048300346aeSmrg
2049300346aeSmrg    func_usage_message
2050300346aeSmrg    $ECHO "$long_help_message"
2051300346aeSmrg    exit 0
2052d656433aSmrg}
2053d656433aSmrg
2054300346aeSmrg
2055300346aeSmrg# func_missing_arg ARGNAME
2056300346aeSmrg# ------------------------
2057d656433aSmrg# Echo program name prefixed message to standard error and set global
2058d656433aSmrg# exit_cmd.
2059d656433aSmrgfunc_missing_arg ()
2060d656433aSmrg{
2061300346aeSmrg    $debug_cmd
20623c15da26Smrg
2063300346aeSmrg    func_error "Missing argument for '$1'."
2064d656433aSmrg    exit_cmd=exit
2065d656433aSmrg}
2066d656433aSmrg
2067d656433aSmrg
2068300346aeSmrg# func_split_equals STRING
2069300346aeSmrg# ------------------------
20703fb97780Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20713fb97780Smrg# after splitting STRING at the '=' sign.
2072300346aeSmrgtest -z "$_G_HAVE_XSI_OPS" \
2073300346aeSmrg    && (eval 'x=a/b/c;
2074300346aeSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075300346aeSmrg    && _G_HAVE_XSI_OPS=yes
2076300346aeSmrg
2077300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"
2078300346aeSmrgthen
2079300346aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2080300346aeSmrg  eval 'func_split_equals ()
2081300346aeSmrg  {
2082300346aeSmrg      $debug_cmd
2083300346aeSmrg
2084300346aeSmrg      func_split_equals_lhs=${1%%=*}
2085300346aeSmrg      func_split_equals_rhs=${1#*=}
20863fb97780Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
20873fb97780Smrg        func_split_equals_rhs=
20883fb97780Smrg      fi
2089300346aeSmrg  }'
2090300346aeSmrgelse
2091300346aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092300346aeSmrg  func_split_equals ()
2093300346aeSmrg  {
2094300346aeSmrg      $debug_cmd
2095300346aeSmrg
2096300346aeSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097300346aeSmrg      func_split_equals_rhs=
20983fb97780Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099300346aeSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100300346aeSmrg  }
2101300346aeSmrgfi #func_split_equals
2102300346aeSmrg
2103300346aeSmrg
2104300346aeSmrg# func_split_short_opt SHORTOPT
2105300346aeSmrg# -----------------------------
21063c15da26Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
21073c15da26Smrg# variables after splitting SHORTOPT after the 2nd character.
2108300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"
2109300346aeSmrgthen
2110300346aeSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2111300346aeSmrg  eval 'func_split_short_opt ()
2112300346aeSmrg  {
2113300346aeSmrg      $debug_cmd
2114300346aeSmrg
2115300346aeSmrg      func_split_short_opt_arg=${1#??}
2116300346aeSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117300346aeSmrg  }'
2118300346aeSmrgelse
2119300346aeSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120300346aeSmrg  func_split_short_opt ()
2121300346aeSmrg  {
2122300346aeSmrg      $debug_cmd
2123300346aeSmrg
21243fb97780Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125300346aeSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126300346aeSmrg  }
2127300346aeSmrgfi #func_split_short_opt
2128300346aeSmrg
2129300346aeSmrg
2130300346aeSmrg# func_usage
2131300346aeSmrg# ----------
2132300346aeSmrg# Echo short help message to standard output and exit.
2133300346aeSmrgfunc_usage ()
21343c15da26Smrg{
2135300346aeSmrg    $debug_cmd
21363c15da26Smrg
2137300346aeSmrg    func_usage_message
2138300346aeSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139300346aeSmrg    exit 0
2140300346aeSmrg}
21413c15da26Smrg
21423c15da26Smrg
2143300346aeSmrg# func_usage_message
2144300346aeSmrg# ------------------
2145300346aeSmrg# Echo short help message to standard output.
2146300346aeSmrgfunc_usage_message ()
21473c15da26Smrg{
2148300346aeSmrg    $debug_cmd
21493c15da26Smrg
2150300346aeSmrg    eval \$ECHO \""Usage: $usage"\"
2151300346aeSmrg    echo
2152300346aeSmrg    $SED -n 's|^# ||
2153300346aeSmrg        /^Written by/{
2154300346aeSmrg          x;p;x
2155300346aeSmrg        }
2156300346aeSmrg	h
2157300346aeSmrg	/^Written by/q' < "$progpath"
2158300346aeSmrg    echo
2159300346aeSmrg    eval \$ECHO \""$usage_message"\"
2160300346aeSmrg}
21613c15da26Smrg
2162d656433aSmrg
2163300346aeSmrg# func_version
2164300346aeSmrg# ------------
2165300346aeSmrg# Echo version message to standard output and exit.
21663fb97780Smrg# The version message is extracted from the calling file's header
21673fb97780Smrg# comments, with leading '# ' stripped:
21683fb97780Smrg#   1. First display the progname and version
21693fb97780Smrg#   2. Followed by the header comment line matching  /^# Written by /
21703fb97780Smrg#   3. Then a blank line followed by the first following line matching
21713fb97780Smrg#      /^# Copyright /
21723fb97780Smrg#   4. Immediately followed by any lines between the previous matches,
21733fb97780Smrg#      except lines preceding the intervening completely blank line.
21743fb97780Smrg# For example, see the header comments of this file.
2175300346aeSmrgfunc_version ()
2176300346aeSmrg{
2177300346aeSmrg    $debug_cmd
2178d656433aSmrg
2179300346aeSmrg    printf '%s\n' "$progname $scriptversion"
2180300346aeSmrg    $SED -n '
21813fb97780Smrg        /^# Written by /!b
21823fb97780Smrg        s|^# ||; p; n
21833fb97780Smrg
21843fb97780Smrg        :fwd2blnk
21853fb97780Smrg        /./ {
21863fb97780Smrg          n
21873fb97780Smrg          b fwd2blnk
2188300346aeSmrg        }
21893fb97780Smrg        p; n
21903fb97780Smrg
21913fb97780Smrg        :holdwrnt
21923fb97780Smrg        s|^# ||
21933fb97780Smrg        s|^# *$||
21943fb97780Smrg        /^Copyright /!{
21953fb97780Smrg          /./H
21963fb97780Smrg          n
21973fb97780Smrg          b holdwrnt
2198300346aeSmrg        }
21993fb97780Smrg
22003fb97780Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22013fb97780Smrg        G
22023fb97780Smrg        s|\(\n\)\n*|\1|g
22033fb97780Smrg        p; q' < "$progpath"
2204d656433aSmrg
2205300346aeSmrg    exit $?
2206300346aeSmrg}
2207d656433aSmrg
2208126a8a12Smrg
2209300346aeSmrg# Local variables:
2210300346aeSmrg# mode: shell-script
2211300346aeSmrg# sh-indentation: 2
2212300346aeSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
22133fb97780Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214300346aeSmrg# time-stamp-time-zone: "UTC"
2215300346aeSmrg# End:
2216126a8a12Smrg
2217300346aeSmrg# Set a version string.
22186bea0e4fSmrgscriptversion='(GNU libtool) 2.5.4'
22196bea0e4fSmrg
22206bea0e4fSmrg# func_version
22216bea0e4fSmrg# ------------
22226bea0e4fSmrg# Echo version message to standard output and exit.
22236bea0e4fSmrgfunc_version ()
22246bea0e4fSmrg{
22256bea0e4fSmrg    $debug_cmd
22266bea0e4fSmrg
22276bea0e4fSmrg	year=`date +%Y`
22286bea0e4fSmrg
22296bea0e4fSmrg	cat <<EOF
22306bea0e4fSmrg$progname $scriptversion
22316bea0e4fSmrgCopyright (C) $year Free Software Foundation, Inc.
22326bea0e4fSmrgLicense GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>
22336bea0e4fSmrgThis is free software: you are free to change and redistribute it.
22346bea0e4fSmrgThere is NO WARRANTY, to the extent permitted by law.
22356bea0e4fSmrg
22366bea0e4fSmrgOriginally written by Gordon Matzigkeit, 1996
22376bea0e4fSmrg(See AUTHORS for complete contributor listing)
22386bea0e4fSmrgEOF
22396bea0e4fSmrg
22406bea0e4fSmrg    exit $?
22416bea0e4fSmrg}
2242126a8a12Smrg
2243126a8a12Smrg
2244300346aeSmrg# func_echo ARG...
2245300346aeSmrg# ----------------
2246300346aeSmrg# Libtool also displays the current mode in messages, so override
2247300346aeSmrg# funclib.sh func_echo with this custom definition.
2248300346aeSmrgfunc_echo ()
22493c15da26Smrg{
2250300346aeSmrg    $debug_cmd
22513c15da26Smrg
2252300346aeSmrg    _G_message=$*
2253300346aeSmrg
2254300346aeSmrg    func_echo_IFS=$IFS
2255300346aeSmrg    IFS=$nl
2256300346aeSmrg    for _G_line in $_G_message; do
2257300346aeSmrg      IFS=$func_echo_IFS
2258300346aeSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2259300346aeSmrg    done
2260300346aeSmrg    IFS=$func_echo_IFS
2261300346aeSmrg}
22623c15da26Smrg
22633c15da26Smrg
2264300346aeSmrg## ---------------- ##
2265300346aeSmrg## Options parsing. ##
2266300346aeSmrg## ---------------- ##
2267300346aeSmrg
2268300346aeSmrg# Hook in the functions to make sure our own options are parsed during
2269300346aeSmrg# the option parsing loop.
2270300346aeSmrg
2271300346aeSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2272300346aeSmrg
2273300346aeSmrg# Short help message in response to '-h'.
2274300346aeSmrgusage_message="Options:
22756bea0e4fSmrg       --config                 show all configuration variables
22766bea0e4fSmrg       --debug                  enable verbose shell tracing
22776bea0e4fSmrg   -n, --dry-run                display commands without modifying any files
22786bea0e4fSmrg       --features               display basic configuration information
22796bea0e4fSmrg       --finish                 use operation '--mode=finish'
22806bea0e4fSmrg       --mode=MODE              use operation mode MODE
22816bea0e4fSmrg       --no-finish              don't update shared library cache
22826bea0e4fSmrg       --no-quiet, --no-silent  print default informational messages
22836bea0e4fSmrg       --no-warnings            equivalent to '-Wnone'
22846bea0e4fSmrg       --preserve-dup-deps      don't remove duplicate dependency libraries
22856bea0e4fSmrg       --quiet, --silent        don't print informational messages
22866bea0e4fSmrg       --reorder-cache=DIRS     reorder shared library cache for preferred DIRS
22876bea0e4fSmrg       --tag=TAG                use configuration variables from tag TAG
22886bea0e4fSmrg   -v, --verbose                print more informational messages than default
22896bea0e4fSmrg       --version                print version information
22906bea0e4fSmrg   -W, --warnings=CATEGORY      report the warnings falling in CATEGORY [all]
22916bea0e4fSmrg   -h, --help, --help-all       print short, long, or detailed help message
2292300346aeSmrg"
22933c15da26Smrg
2294300346aeSmrg# Additional text appended to 'usage_message' in response to '--help'.
2295300346aeSmrgfunc_help ()
22963c15da26Smrg{
2297300346aeSmrg    $debug_cmd
2298300346aeSmrg
2299300346aeSmrg    func_usage_message
2300300346aeSmrg    $ECHO "$long_help_message
2301300346aeSmrg
2302300346aeSmrgMODE must be one of the following:
2303300346aeSmrg
2304300346aeSmrg       clean           remove files from the build directory
2305300346aeSmrg       compile         compile a source file into a libtool object
2306300346aeSmrg       execute         automatically set library path, then run a program
2307300346aeSmrg       finish          complete the installation of libtool libraries
2308300346aeSmrg       install         install libraries or executables
2309300346aeSmrg       link            create a library or an executable
2310300346aeSmrg       uninstall       remove libraries from an installed directory
2311300346aeSmrg
2312300346aeSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2313300346aeSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2314300346aeSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2315300346aeSmrg
2316300346aeSmrgWhen reporting a bug, please describe a test case to reproduce it and
2317300346aeSmrginclude the following information:
2318300346aeSmrg
2319300346aeSmrg       host-triplet:   $host
2320300346aeSmrg       shell:          $SHELL
2321300346aeSmrg       compiler:       $LTCC
2322300346aeSmrg       compiler flags: $LTCFLAGS
2323300346aeSmrg       linker:         $LD (gnu? $with_gnu_ld)
23246bea0e4fSmrg       version:        $progname $scriptversion
2325300346aeSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2326300346aeSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2327300346aeSmrg
2328300346aeSmrgReport bugs to <bug-libtool@gnu.org>.
23296bea0e4fSmrgGNU libtool home page: <https://www.gnu.org/software/libtool/>.
23306bea0e4fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
2331300346aeSmrg    exit 0
2332300346aeSmrg}
23333c15da26Smrg
23343c15da26Smrg
2335300346aeSmrg# func_lo2o OBJECT-NAME
2336300346aeSmrg# ---------------------
2337300346aeSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2338300346aeSmrg# object suffix.
23393c15da26Smrg
2340300346aeSmrglo2o=s/\\.lo\$/.$objext/
2341300346aeSmrgo2lo=s/\\.$objext\$/.lo/
23423c15da26Smrg
2343300346aeSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2344300346aeSmrg  eval 'func_lo2o ()
2345300346aeSmrg  {
2346300346aeSmrg    case $1 in
2347300346aeSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2348300346aeSmrg      *   ) func_lo2o_result=$1               ;;
2349300346aeSmrg    esac
2350300346aeSmrg  }'
2351300346aeSmrg
2352300346aeSmrg  # func_xform LIBOBJ-OR-SOURCE
2353300346aeSmrg  # ---------------------------
2354300346aeSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2355300346aeSmrg  # suffix to a '.lo' libtool-object suffix.
2356300346aeSmrg  eval 'func_xform ()
2357300346aeSmrg  {
2358300346aeSmrg    func_xform_result=${1%.*}.lo
2359300346aeSmrg  }'
2360300346aeSmrgelse
2361300346aeSmrg  # ...otherwise fall back to using sed.
2362300346aeSmrg  func_lo2o ()
2363300346aeSmrg  {
2364300346aeSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2365300346aeSmrg  }
2366300346aeSmrg
2367300346aeSmrg  func_xform ()
2368300346aeSmrg  {
2369300346aeSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2370300346aeSmrg  }
2371300346aeSmrgfi
23723c15da26Smrg
23733c15da26Smrg
2374300346aeSmrg# func_fatal_configuration ARG...
2375300346aeSmrg# -------------------------------
2376d656433aSmrg# Echo program name prefixed message to standard error, followed by
2377d656433aSmrg# a configuration failure hint, and exit.
2378d656433aSmrgfunc_fatal_configuration ()
2379d656433aSmrg{
23803fb97780Smrg    func_fatal_error ${1+"$@"} \
2381300346aeSmrg      "See the $PACKAGE documentation for more information." \
2382300346aeSmrg      "Fatal configuration error."
2383d656433aSmrg}
2384d656433aSmrg
2385d656433aSmrg
2386d656433aSmrg# func_config
2387300346aeSmrg# -----------
2388d656433aSmrg# Display the configuration for all the tags in this script.
2389d656433aSmrgfunc_config ()
2390d656433aSmrg{
2391d656433aSmrg    re_begincf='^# ### BEGIN LIBTOOL'
2392d656433aSmrg    re_endcf='^# ### END LIBTOOL'
2393d656433aSmrg
2394d656433aSmrg    # Default configuration.
2395d656433aSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2396126a8a12Smrg
2397126a8a12Smrg    # Now print the configurations for the tags.
2398126a8a12Smrg    for tagname in $taglist; do
2399d656433aSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2400126a8a12Smrg    done
2401126a8a12Smrg
2402d656433aSmrg    exit $?
2403d656433aSmrg}
2404126a8a12Smrg
2405300346aeSmrg
2406d656433aSmrg# func_features
2407300346aeSmrg# -------------
2408d656433aSmrg# Display the features supported by this script.
2409d656433aSmrgfunc_features ()
2410d656433aSmrg{
2411555991fdSmrg    echo "host: $host"
2412300346aeSmrg    if test yes = "$build_libtool_libs"; then
2413555991fdSmrg      echo "enable shared libraries"
2414126a8a12Smrg    else
2415555991fdSmrg      echo "disable shared libraries"
2416126a8a12Smrg    fi
2417300346aeSmrg    if test yes = "$build_old_libs"; then
2418555991fdSmrg      echo "enable static libraries"
2419126a8a12Smrg    else
2420555991fdSmrg      echo "disable static libraries"
2421126a8a12Smrg    fi
2422d656433aSmrg
2423126a8a12Smrg    exit $?
2424d656433aSmrg}
2425126a8a12Smrg
2426300346aeSmrg
2427300346aeSmrg# func_enable_tag TAGNAME
2428300346aeSmrg# -----------------------
2429d656433aSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2430d656433aSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2431d656433aSmrg# variable here.
2432d656433aSmrgfunc_enable_tag ()
2433d656433aSmrg{
2434300346aeSmrg    # Global variable:
2435300346aeSmrg    tagname=$1
2436126a8a12Smrg
2437300346aeSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2438300346aeSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2439300346aeSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2440126a8a12Smrg
2441300346aeSmrg    # Validate tagname.
2442300346aeSmrg    case $tagname in
2443300346aeSmrg      *[!-_A-Za-z0-9,/]*)
2444300346aeSmrg        func_fatal_error "invalid tag name: $tagname"
2445300346aeSmrg        ;;
2446300346aeSmrg    esac
2447126a8a12Smrg
2448300346aeSmrg    # Don't test for the "default" C tag, as we know it's
2449300346aeSmrg    # there but not specially marked.
2450300346aeSmrg    case $tagname in
2451300346aeSmrg        CC) ;;
2452d656433aSmrg    *)
2453300346aeSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2454300346aeSmrg	  taglist="$taglist $tagname"
2455300346aeSmrg
2456300346aeSmrg	  # Evaluate the configuration.  Be careful to quote the path
2457300346aeSmrg	  # and the sed script, to avoid splitting on whitespace, but
2458300346aeSmrg	  # also don't use non-portable quotes within backquotes within
2459300346aeSmrg	  # quotes we have to do it in 2 steps:
2460300346aeSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2461300346aeSmrg	  eval "$extractedcf"
2462300346aeSmrg        else
2463300346aeSmrg	  func_error "ignoring unknown tag $tagname"
2464300346aeSmrg        fi
2465300346aeSmrg        ;;
2466300346aeSmrg    esac
2467d656433aSmrg}
2468d656433aSmrg
2469300346aeSmrg
24703c15da26Smrg# func_check_version_match
2471300346aeSmrg# ------------------------
24723c15da26Smrg# Ensure that we are using m4 macros, and libtool script from the same
24733c15da26Smrg# release of libtool.
24743c15da26Smrgfunc_check_version_match ()
2475d656433aSmrg{
2476300346aeSmrg    if test "$package_revision" != "$macro_revision"; then
2477300346aeSmrg      if test "$VERSION" != "$macro_version"; then
2478300346aeSmrg        if test -z "$macro_version"; then
2479300346aeSmrg          cat >&2 <<_LT_EOF
24803c15da26Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24813c15da26Smrg$progname: definition of this LT_INIT comes from an older release.
24823c15da26Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24833c15da26Smrg$progname: and run autoconf again.
24843c15da26Smrg_LT_EOF
2485300346aeSmrg        else
2486300346aeSmrg          cat >&2 <<_LT_EOF
24873c15da26Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24883c15da26Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
24893c15da26Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24903c15da26Smrg$progname: and run autoconf again.
24913c15da26Smrg_LT_EOF
2492300346aeSmrg        fi
2493300346aeSmrg      else
2494300346aeSmrg        cat >&2 <<_LT_EOF
24953c15da26Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
24963c15da26Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
24973c15da26Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
24983c15da26Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
24993c15da26Smrg_LT_EOF
2500300346aeSmrg      fi
2501126a8a12Smrg
2502300346aeSmrg      exit $EXIT_MISMATCH
2503300346aeSmrg    fi
25043c15da26Smrg}
25053c15da26Smrg
25063c15da26Smrg
2507300346aeSmrg# libtool_options_prep [ARG]...
2508300346aeSmrg# -----------------------------
2509300346aeSmrg# Preparation for options parsed by libtool.
2510300346aeSmrglibtool_options_prep ()
2511300346aeSmrg{
2512300346aeSmrg    $debug_mode
2513126a8a12Smrg
2514300346aeSmrg    # Option defaults:
2515300346aeSmrg    opt_config=false
2516300346aeSmrg    opt_dlopen=
2517300346aeSmrg    opt_dry_run=false
2518300346aeSmrg    opt_help=false
2519300346aeSmrg    opt_mode=
25206bea0e4fSmrg    opt_reorder_cache=false
2521300346aeSmrg    opt_preserve_dup_deps=false
2522300346aeSmrg    opt_quiet=false
25236bea0e4fSmrg    opt_finishing=true
25246bea0e4fSmrg    opt_warning=
25253c15da26Smrg
2526300346aeSmrg    nonopt=
2527300346aeSmrg    preserve_args=
25283c15da26Smrg
25293fb97780Smrg    _G_rc_lt_options_prep=:
25303fb97780Smrg
2531300346aeSmrg    # Shorthand for --mode=foo, only valid as the first argument
2532300346aeSmrg    case $1 in
2533300346aeSmrg    clean|clea|cle|cl)
2534300346aeSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2535300346aeSmrg      ;;
2536300346aeSmrg    compile|compil|compi|comp|com|co|c)
2537300346aeSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2538300346aeSmrg      ;;
2539300346aeSmrg    execute|execut|execu|exec|exe|ex|e)
2540300346aeSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2541300346aeSmrg      ;;
2542300346aeSmrg    finish|finis|fini|fin|fi|f)
2543300346aeSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2544300346aeSmrg      ;;
2545300346aeSmrg    install|instal|insta|inst|ins|in|i)
2546300346aeSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2547300346aeSmrg      ;;
2548300346aeSmrg    link|lin|li|l)
2549300346aeSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2550300346aeSmrg      ;;
2551300346aeSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2552300346aeSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2553300346aeSmrg      ;;
25543fb97780Smrg    *)
25553fb97780Smrg      _G_rc_lt_options_prep=false
25563fb97780Smrg      ;;
2557300346aeSmrg    esac
2558300346aeSmrg
25593fb97780Smrg    if $_G_rc_lt_options_prep; then
25603fb97780Smrg      # Pass back the list of options.
25613fb97780Smrg      func_quote eval ${1+"$@"}
25623fb97780Smrg      libtool_options_prep_result=$func_quote_result
25633fb97780Smrg    fi
2564300346aeSmrg}
2565300346aeSmrgfunc_add_hook func_options_prep libtool_options_prep
25663c15da26Smrg
25673c15da26Smrg
2568300346aeSmrg# libtool_parse_options [ARG]...
2569300346aeSmrg# ---------------------------------
2570300346aeSmrg# Provide handling for libtool specific options.
2571300346aeSmrglibtool_parse_options ()
25723c15da26Smrg{
2573300346aeSmrg    $debug_cmd
2574d656433aSmrg
25753fb97780Smrg    _G_rc_lt_parse_options=false
25763fb97780Smrg
2577300346aeSmrg    # Perform our own loop to consume as many options as possible in
2578300346aeSmrg    # each iteration.
2579300346aeSmrg    while test $# -gt 0; do
25803fb97780Smrg      _G_match_lt_parse_options=:
2581300346aeSmrg      _G_opt=$1
2582300346aeSmrg      shift
2583300346aeSmrg      case $_G_opt in
2584300346aeSmrg        --dry-run|--dryrun|-n)
2585300346aeSmrg                        opt_dry_run=:
2586300346aeSmrg                        ;;
2587300346aeSmrg
2588300346aeSmrg        --config)       func_config ;;
2589300346aeSmrg
2590300346aeSmrg        --dlopen|-dlopen)
2591300346aeSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2592300346aeSmrg}$1"
2593300346aeSmrg                        shift
2594300346aeSmrg                        ;;
2595300346aeSmrg
2596300346aeSmrg        --preserve-dup-deps)
2597300346aeSmrg                        opt_preserve_dup_deps=: ;;
2598300346aeSmrg
2599300346aeSmrg        --features)     func_features ;;
2600300346aeSmrg
2601300346aeSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2602300346aeSmrg
2603300346aeSmrg        --help)         opt_help=: ;;
2604300346aeSmrg
2605300346aeSmrg        --help-all)     opt_help=': help-all' ;;
2606300346aeSmrg
2607300346aeSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2608300346aeSmrg                        opt_mode=$1
2609300346aeSmrg                        case $1 in
2610300346aeSmrg                          # Valid mode arguments:
2611300346aeSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2612300346aeSmrg
2613300346aeSmrg                          # Catch anything else as an error
26146bea0e4fSmrg                          *) func_error "invalid argument '$1' for $_G_opt"
2615300346aeSmrg                             exit_cmd=exit
2616300346aeSmrg                             ;;
2617300346aeSmrg                        esac
2618300346aeSmrg                        shift
2619300346aeSmrg                        ;;
2620300346aeSmrg
26216bea0e4fSmrg        --no-finish)
26226bea0e4fSmrg                        opt_finishing=false
26236bea0e4fSmrg                        func_append preserve_args " $_G_opt"
26246bea0e4fSmrg                        ;;
26256bea0e4fSmrg
2626300346aeSmrg        --no-silent|--no-quiet)
2627300346aeSmrg                        opt_quiet=false
2628300346aeSmrg                        func_append preserve_args " $_G_opt"
2629300346aeSmrg                        ;;
2630300346aeSmrg
2631300346aeSmrg        --no-warnings|--no-warning|--no-warn)
2632300346aeSmrg                        opt_warning=false
2633300346aeSmrg                        func_append preserve_args " $_G_opt"
2634300346aeSmrg                        ;;
2635300346aeSmrg
2636300346aeSmrg        --no-verbose)
2637300346aeSmrg                        opt_verbose=false
2638300346aeSmrg                        func_append preserve_args " $_G_opt"
2639300346aeSmrg                        ;;
2640300346aeSmrg
26416bea0e4fSmrg        --reorder-cache)
26426bea0e4fSmrg                        opt_reorder_cache=true
26436bea0e4fSmrg                        shared_lib_dirs=$1
26446bea0e4fSmrg                        if test -n "$shared_lib_dirs"; then
26456bea0e4fSmrg                          case $1 in
26466bea0e4fSmrg                            # Must begin with /:
26476bea0e4fSmrg                            /*) ;;
26486bea0e4fSmrg
26496bea0e4fSmrg                            # Catch anything else as an error (relative paths)
26506bea0e4fSmrg                            *) func_error "invalid argument '$1' for $_G_opt"
26516bea0e4fSmrg                               func_error "absolute paths are required for $_G_opt"
26526bea0e4fSmrg                               exit_cmd=exit
26536bea0e4fSmrg                               ;;
26546bea0e4fSmrg                          esac
26556bea0e4fSmrg                        fi
26566bea0e4fSmrg                        shift
26576bea0e4fSmrg                        ;;
26586bea0e4fSmrg
2659300346aeSmrg        --silent|--quiet)
2660300346aeSmrg                        opt_quiet=:
2661300346aeSmrg                        opt_verbose=false
2662300346aeSmrg                        func_append preserve_args " $_G_opt"
2663300346aeSmrg                        ;;
2664300346aeSmrg
2665300346aeSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2666300346aeSmrg                        opt_tag=$1
2667300346aeSmrg                        func_append preserve_args " $_G_opt $1"
2668300346aeSmrg                        func_enable_tag "$1"
2669300346aeSmrg                        shift
2670300346aeSmrg                        ;;
2671300346aeSmrg
2672300346aeSmrg        --verbose|-v)   opt_quiet=false
2673300346aeSmrg                        opt_verbose=:
2674300346aeSmrg                        func_append preserve_args " $_G_opt"
2675300346aeSmrg                        ;;
2676300346aeSmrg
26773fb97780Smrg        # An option not handled by this hook function:
26783fb97780Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26793fb97780Smrg                        _G_match_lt_parse_options=false
26803fb97780Smrg                        break
26813fb97780Smrg                        ;;
2682300346aeSmrg      esac
26833fb97780Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2684300346aeSmrg    done
26853c15da26Smrg
26863fb97780Smrg    if $_G_rc_lt_parse_options; then
26873fb97780Smrg      # save modified positional parameters for caller
26883fb97780Smrg      func_quote eval ${1+"$@"}
26893fb97780Smrg      libtool_parse_options_result=$func_quote_result
26903fb97780Smrg    fi
2691300346aeSmrg}
2692300346aeSmrgfunc_add_hook func_parse_options libtool_parse_options
2693d656433aSmrg
2694126a8a12Smrg
26956bea0e4fSmrg# func_warning ARG...
26966bea0e4fSmrg# -------------------
26976bea0e4fSmrg# Libtool warnings are not categorized, so override funclib.sh
26986bea0e4fSmrg# func_warning with this simpler definition.
26996bea0e4fSmrgfunc_warning ()
27006bea0e4fSmrg{
27016bea0e4fSmrg    if $opt_warning; then
27026bea0e4fSmrg        $debug_cmd
27036bea0e4fSmrg        $warning_func ${1+"$@"}
27046bea0e4fSmrg    fi
27056bea0e4fSmrg}
27066bea0e4fSmrg
2707d656433aSmrg
2708300346aeSmrg# libtool_validate_options [ARG]...
2709300346aeSmrg# ---------------------------------
2710300346aeSmrg# Perform any sanity checks on option settings and/or unconsumed
2711300346aeSmrg# arguments.
2712300346aeSmrglibtool_validate_options ()
2713300346aeSmrg{
2714300346aeSmrg    # save first non-option argument
2715300346aeSmrg    if test 0 -lt $#; then
2716300346aeSmrg      nonopt=$1
2717300346aeSmrg      shift
2718d656433aSmrg    fi
2719d656433aSmrg
2720300346aeSmrg    # preserve --debug
2721300346aeSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2722d656433aSmrg
27236bea0e4fSmrg    case $host_os in
2724300346aeSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2725300346aeSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
27266bea0e4fSmrg      cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*)
2727300346aeSmrg        # don't eliminate duplications in $postdeps and $predeps
2728300346aeSmrg        opt_duplicate_compiler_generated_deps=:
2729300346aeSmrg        ;;
2730300346aeSmrg      *)
2731300346aeSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2732300346aeSmrg        ;;
2733300346aeSmrg    esac
2734d656433aSmrg
2735300346aeSmrg    $opt_help || {
2736300346aeSmrg      # Sanity checks first:
2737300346aeSmrg      func_check_version_match
2738d656433aSmrg
2739300346aeSmrg      test yes != "$build_libtool_libs" \
2740300346aeSmrg        && test yes != "$build_old_libs" \
2741300346aeSmrg        && func_fatal_configuration "not configured to build any kind of library"
2742d656433aSmrg
2743300346aeSmrg      # Darwin sucks
2744300346aeSmrg      eval std_shrext=\"$shrext_cmds\"
2745300346aeSmrg
2746300346aeSmrg      # Only execute mode is allowed to have -dlopen flags.
2747300346aeSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2748300346aeSmrg        func_error "unrecognized option '-dlopen'"
2749300346aeSmrg        $ECHO "$help" 1>&2
2750300346aeSmrg        exit $EXIT_FAILURE
2751300346aeSmrg      fi
2752300346aeSmrg
2753300346aeSmrg      # Change the help message to a mode-specific one.
2754300346aeSmrg      generic_help=$help
2755300346aeSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2756300346aeSmrg    }
2757300346aeSmrg
2758300346aeSmrg    # Pass back the unparsed argument list
27593fb97780Smrg    func_quote eval ${1+"$@"}
27603fb97780Smrg    libtool_validate_options_result=$func_quote_result
27613c15da26Smrg}
2762300346aeSmrgfunc_add_hook func_validate_options libtool_validate_options
2763300346aeSmrg
2764d656433aSmrg
2765300346aeSmrg# Process options as early as possible so that --help and --version
2766300346aeSmrg# can return quickly.
2767300346aeSmrgfunc_options ${1+"$@"}
2768300346aeSmrgeval set dummy "$func_options_result"; shift
2769126a8a12Smrg
2770126a8a12Smrg
2771126a8a12Smrg
27723c15da26Smrg## ----------- ##
27733c15da26Smrg##    Main.    ##
27743c15da26Smrg## ----------- ##
2775126a8a12Smrg
2776300346aeSmrgmagic='%%%MAGIC variable%%%'
2777300346aeSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2778300346aeSmrg
2779300346aeSmrg# Global variables.
2780300346aeSmrgextracted_archives=
2781300346aeSmrgextracted_serial=0
2782300346aeSmrg
2783300346aeSmrg# If this variable is set in any of the actions, the command in it
2784300346aeSmrg# will be execed at the end.  This prevents here-documents from being
2785300346aeSmrg# left over by shells.
2786300346aeSmrgexec_cmd=
2787300346aeSmrg
2788300346aeSmrg
2789300346aeSmrg# A function that is used when there is no print builtin or printf.
2790300346aeSmrgfunc_fallback_echo ()
2791300346aeSmrg{
2792300346aeSmrg  eval 'cat <<_LTECHO_EOF
2793300346aeSmrg$1
2794300346aeSmrg_LTECHO_EOF'
2795300346aeSmrg}
2796300346aeSmrg
2797300346aeSmrg# func_generated_by_libtool
2798300346aeSmrg# True iff stdin has been generated by Libtool. This function is only
2799300346aeSmrg# a basic sanity check; it will hardly flush out determined imposters.
2800300346aeSmrgfunc_generated_by_libtool_p ()
2801300346aeSmrg{
2802300346aeSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2803300346aeSmrg}
2804300346aeSmrg
2805d656433aSmrg# func_lalib_p file
2806300346aeSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2807d656433aSmrg# This function is only a basic sanity check; it will hardly flush out
2808d656433aSmrg# determined imposters.
2809d656433aSmrgfunc_lalib_p ()
2810d656433aSmrg{
2811d656433aSmrg    test -f "$1" &&
2812300346aeSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2813d656433aSmrg}
2814126a8a12Smrg
2815d656433aSmrg# func_lalib_unsafe_p file
2816300346aeSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2817d656433aSmrg# This function implements the same check as func_lalib_p without
2818d656433aSmrg# resorting to external programs.  To this end, it redirects stdin and
2819d656433aSmrg# closes it afterwards, without saving the original file descriptor.
2820d656433aSmrg# As a safety measure, use it only where a negative result would be
2821300346aeSmrg# fatal anyway.  Works if 'file' does not exist.
2822d656433aSmrgfunc_lalib_unsafe_p ()
2823d656433aSmrg{
2824d656433aSmrg    lalib_p=no
2825d656433aSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2826d656433aSmrg	for lalib_p_l in 1 2 3 4
2827d656433aSmrg	do
2828d656433aSmrg	    read lalib_p_line
2829300346aeSmrg	    case $lalib_p_line in
2830d656433aSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2831d656433aSmrg	    esac
2832d656433aSmrg	done
2833d656433aSmrg	exec 0<&5 5<&-
2834d656433aSmrg    fi
2835300346aeSmrg    test yes = "$lalib_p"
2836d656433aSmrg}
2837126a8a12Smrg
2838d656433aSmrg# func_ltwrapper_script_p file
2839d656433aSmrg# True iff FILE is a libtool wrapper script
2840d656433aSmrg# This function is only a basic sanity check; it will hardly flush out
2841d656433aSmrg# determined imposters.
2842d656433aSmrgfunc_ltwrapper_script_p ()
2843d656433aSmrg{
2844300346aeSmrg    test -f "$1" &&
2845300346aeSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2846d656433aSmrg}
2847126a8a12Smrg
2848d656433aSmrg# func_ltwrapper_executable_p file
2849d656433aSmrg# True iff FILE is a libtool wrapper executable
2850d656433aSmrg# This function is only a basic sanity check; it will hardly flush out
2851d656433aSmrg# determined imposters.
2852d656433aSmrgfunc_ltwrapper_executable_p ()
2853d656433aSmrg{
2854d656433aSmrg    func_ltwrapper_exec_suffix=
2855d656433aSmrg    case $1 in
2856d656433aSmrg    *.exe) ;;
2857d656433aSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
2858d656433aSmrg    esac
2859d656433aSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2860d656433aSmrg}
2861126a8a12Smrg
2862d656433aSmrg# func_ltwrapper_scriptname file
2863d656433aSmrg# Assumes file is an ltwrapper_executable
2864d656433aSmrg# uses $file to determine the appropriate filename for a
2865d656433aSmrg# temporary ltwrapper_script.
2866d656433aSmrgfunc_ltwrapper_scriptname ()
2867d656433aSmrg{
28683c15da26Smrg    func_dirname_and_basename "$1" "" "."
28693c15da26Smrg    func_stripname '' '.exe' "$func_basename_result"
2870300346aeSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2871d656433aSmrg}
2872126a8a12Smrg
2873d656433aSmrg# func_ltwrapper_p file
2874d656433aSmrg# True iff FILE is a libtool wrapper script or wrapper executable
2875d656433aSmrg# This function is only a basic sanity check; it will hardly flush out
2876d656433aSmrg# determined imposters.
2877d656433aSmrgfunc_ltwrapper_p ()
2878d656433aSmrg{
2879d656433aSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2880d656433aSmrg}
2881126a8a12Smrg
2882126a8a12Smrg
2883d656433aSmrg# func_execute_cmds commands fail_cmd
2884d656433aSmrg# Execute tilde-delimited COMMANDS.
2885d656433aSmrg# If FAIL_CMD is given, eval that upon failure.
2886d656433aSmrg# FAIL_CMD may read-access the current command in variable CMD!
2887d656433aSmrgfunc_execute_cmds ()
2888d656433aSmrg{
2889300346aeSmrg    $debug_cmd
2890300346aeSmrg
2891d656433aSmrg    save_ifs=$IFS; IFS='~'
2892d656433aSmrg    for cmd in $1; do
2893300346aeSmrg      IFS=$sp$nl
2894d656433aSmrg      eval cmd=\"$cmd\"
2895300346aeSmrg      IFS=$save_ifs
2896d656433aSmrg      func_show_eval "$cmd" "${2-:}"
2897d656433aSmrg    done
2898d656433aSmrg    IFS=$save_ifs
2899d656433aSmrg}
2900d656433aSmrg
2901d656433aSmrg
2902d656433aSmrg# func_source file
2903d656433aSmrg# Source FILE, adding directory component if necessary.
2904d656433aSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
2905d656433aSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2906d656433aSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2907300346aeSmrg# 'FILE.' does not work on cygwin managed mounts.
2908d656433aSmrgfunc_source ()
2909d656433aSmrg{
2910300346aeSmrg    $debug_cmd
2911300346aeSmrg
2912d656433aSmrg    case $1 in
2913d656433aSmrg    */* | *\\*)	. "$1" ;;
2914d656433aSmrg    *)		. "./$1" ;;
2915d656433aSmrg    esac
2916d656433aSmrg}
2917d656433aSmrg
2918d656433aSmrg
29193c15da26Smrg# func_resolve_sysroot PATH
29203c15da26Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
29213c15da26Smrg# func_resolve_sysroot_result
29223c15da26Smrgfunc_resolve_sysroot ()
29233c15da26Smrg{
29243c15da26Smrg  func_resolve_sysroot_result=$1
29253c15da26Smrg  case $func_resolve_sysroot_result in
29263c15da26Smrg  =*)
29273c15da26Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
29283c15da26Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
29293c15da26Smrg    ;;
29303c15da26Smrg  esac
29313c15da26Smrg}
29323c15da26Smrg
29333c15da26Smrg# func_replace_sysroot PATH
29343c15da26Smrg# If PATH begins with the sysroot, replace it with = and
29353c15da26Smrg# store the result into func_replace_sysroot_result.
29363c15da26Smrgfunc_replace_sysroot ()
29373c15da26Smrg{
2938300346aeSmrg  case $lt_sysroot:$1 in
29393c15da26Smrg  ?*:"$lt_sysroot"*)
29403c15da26Smrg    func_stripname "$lt_sysroot" '' "$1"
2941300346aeSmrg    func_replace_sysroot_result='='$func_stripname_result
29423c15da26Smrg    ;;
29433c15da26Smrg  *)
29443c15da26Smrg    # Including no sysroot.
29453c15da26Smrg    func_replace_sysroot_result=$1
29463c15da26Smrg    ;;
29473c15da26Smrg  esac
29483c15da26Smrg}
29493c15da26Smrg
2950d656433aSmrg# func_infer_tag arg
2951d656433aSmrg# Infer tagged configuration to use if any are available and
2952d656433aSmrg# if one wasn't chosen via the "--tag" command line option.
2953d656433aSmrg# Only attempt this if the compiler in the base compile
2954d656433aSmrg# command doesn't match the default compiler.
2955d656433aSmrg# arg is usually of the form 'gcc ...'
2956d656433aSmrgfunc_infer_tag ()
2957d656433aSmrg{
2958300346aeSmrg    $debug_cmd
2959300346aeSmrg
2960d656433aSmrg    if test -n "$available_tags" && test -z "$tagname"; then
2961d656433aSmrg      CC_quoted=
2962d656433aSmrg      for arg in $CC; do
29633c15da26Smrg	func_append_quoted CC_quoted "$arg"
2964d656433aSmrg      done
2965555991fdSmrg      CC_expanded=`func_echo_all $CC`
2966555991fdSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2967d656433aSmrg      case $@ in
2968d656433aSmrg      # Blanks in the command may have been stripped by the calling shell,
2969d656433aSmrg      # but not from the CC environment variable when configure was run.
2970555991fdSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2971555991fdSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2972d656433aSmrg      # Blanks at the start of $base_compile will cause this to fail
2973d656433aSmrg      # if we don't check for them as well.
2974d656433aSmrg      *)
2975d656433aSmrg	for z in $available_tags; do
2976d656433aSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2977d656433aSmrg	    # Evaluate the configuration.
2978300346aeSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2979d656433aSmrg	    CC_quoted=
2980d656433aSmrg	    for arg in $CC; do
2981d656433aSmrg	      # Double-quote args containing other shell metacharacters.
29823c15da26Smrg	      func_append_quoted CC_quoted "$arg"
2983d656433aSmrg	    done
2984555991fdSmrg	    CC_expanded=`func_echo_all $CC`
2985555991fdSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2986d656433aSmrg	    case "$@ " in
2987555991fdSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2988555991fdSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2989d656433aSmrg	      # The compiler in the base compile command matches
2990d656433aSmrg	      # the one in the tagged configuration.
2991d656433aSmrg	      # Assume this is the tagged configuration we want.
2992d656433aSmrg	      tagname=$z
2993d656433aSmrg	      break
2994126a8a12Smrg	      ;;
2995126a8a12Smrg	    esac
2996d656433aSmrg	  fi
2997d656433aSmrg	done
2998d656433aSmrg	# If $tagname still isn't set, then no tagged configuration
2999d656433aSmrg	# was found and let the user know that the "--tag" command
3000d656433aSmrg	# line option must be used.
3001d656433aSmrg	if test -z "$tagname"; then
3002d656433aSmrg	  func_echo "unable to infer tagged configuration"
3003300346aeSmrg	  func_fatal_error "specify a tag with '--tag'"
3004d656433aSmrg#	else
3005d656433aSmrg#	  func_verbose "using $tagname tagged configuration"
3006d656433aSmrg	fi
3007d656433aSmrg	;;
3008d656433aSmrg      esac
3009d656433aSmrg    fi
3010d656433aSmrg}
3011d656433aSmrg
3012d656433aSmrg
3013d656433aSmrg
30143c15da26Smrg# func_write_libtool_object output_name pic_name nonpic_name
30153c15da26Smrg# Create a libtool object file (analogous to a ".la" file),
30163c15da26Smrg# but don't create it if we're doing a dry run.
30173c15da26Smrgfunc_write_libtool_object ()
30183c15da26Smrg{
3019300346aeSmrg    write_libobj=$1
3020300346aeSmrg    if test yes = "$build_libtool_libs"; then
3021300346aeSmrg      write_lobj=\'$2\'
30223c15da26Smrg    else
30233c15da26Smrg      write_lobj=none
30243c15da26Smrg    fi
30253c15da26Smrg
3026300346aeSmrg    if test yes = "$build_old_libs"; then
3027300346aeSmrg      write_oldobj=\'$3\'
30283c15da26Smrg    else
30293c15da26Smrg      write_oldobj=none
30303c15da26Smrg    fi
30313c15da26Smrg
30323c15da26Smrg    $opt_dry_run || {
30333c15da26Smrg      cat >${write_libobj}T <<EOF
30343c15da26Smrg# $write_libobj - a libtool object file
3035300346aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
30363c15da26Smrg#
30373c15da26Smrg# Please DO NOT delete this file!
30383c15da26Smrg# It is necessary for linking the library.
30393c15da26Smrg
30403c15da26Smrg# Name of the PIC object.
30413c15da26Smrgpic_object=$write_lobj
30423c15da26Smrg
30433c15da26Smrg# Name of the non-PIC object
30443c15da26Smrgnon_pic_object=$write_oldobj
30453c15da26Smrg
30463c15da26SmrgEOF
3047300346aeSmrg      $MV "${write_libobj}T" "$write_libobj"
30483c15da26Smrg    }
30493c15da26Smrg}
30503c15da26Smrg
30513c15da26Smrg
30523c15da26Smrg##################################################
30533c15da26Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
30543c15da26Smrg##################################################
30553c15da26Smrg
30563c15da26Smrg# func_convert_core_file_wine_to_w32 ARG
30573c15da26Smrg# Helper function used by file name conversion functions when $build is *nix,
30586bea0e4fSmrg# and $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
30593c15da26Smrg# correctly configured wine environment available, with the winepath program
30603c15da26Smrg# in $build's $PATH.
30613c15da26Smrg#
30623c15da26Smrg# ARG is the $build file name to be converted to w32 format.
30633c15da26Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
30643c15da26Smrg# be empty on error (or when ARG is empty)
30653c15da26Smrgfunc_convert_core_file_wine_to_w32 ()
30663c15da26Smrg{
3067300346aeSmrg  $debug_cmd
3068300346aeSmrg
3069300346aeSmrg  func_convert_core_file_wine_to_w32_result=$1
30703c15da26Smrg  if test -n "$1"; then
30713c15da26Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
30723c15da26Smrg    # are forced to check the contents of stdout. On the other hand, if the
30733c15da26Smrg    # command is not found, the shell will set an exit code of 127 and print
30743c15da26Smrg    # *an error message* to stdout. So we must check for both error code of
30753c15da26Smrg    # zero AND non-empty stdout, which explains the odd construction:
30763c15da26Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3077300346aeSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
30783c15da26Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3079300346aeSmrg        $SED -e "$sed_naive_backslashify"`
30803c15da26Smrg    else
30813c15da26Smrg      func_convert_core_file_wine_to_w32_result=
30823c15da26Smrg    fi
30833c15da26Smrg  fi
30843c15da26Smrg}
30853c15da26Smrg# end: func_convert_core_file_wine_to_w32
30863c15da26Smrg
30873c15da26Smrg
30883c15da26Smrg# func_convert_core_path_wine_to_w32 ARG
30893c15da26Smrg# Helper function used by path conversion functions when $build is *nix, and
30906bea0e4fSmrg# $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
30916bea0e4fSmrg# correctly configured wine environment available, with the winepath program
30926bea0e4fSmrg# in $build's $PATH. Assumes ARG has no leading or trailing path separator
30936bea0e4fSmrg# characters.
30943c15da26Smrg#
30953c15da26Smrg# ARG is path to be converted from $build format to win32.
30963c15da26Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
30973c15da26Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
30983c15da26Smrg# are convertible, then the result may be empty.
30993c15da26Smrgfunc_convert_core_path_wine_to_w32 ()
31003c15da26Smrg{
3101300346aeSmrg  $debug_cmd
3102300346aeSmrg
31033c15da26Smrg  # unfortunately, winepath doesn't convert paths, only file names
3104300346aeSmrg  func_convert_core_path_wine_to_w32_result=
31053c15da26Smrg  if test -n "$1"; then
31063c15da26Smrg    oldIFS=$IFS
31073c15da26Smrg    IFS=:
31083c15da26Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
31093c15da26Smrg      IFS=$oldIFS
31103c15da26Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3111300346aeSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
31123c15da26Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3113300346aeSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
31143c15da26Smrg        else
31153c15da26Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
31163c15da26Smrg        fi
31173c15da26Smrg      fi
31183c15da26Smrg    done
31193c15da26Smrg    IFS=$oldIFS
31203c15da26Smrg  fi
31213c15da26Smrg}
31223c15da26Smrg# end: func_convert_core_path_wine_to_w32
31233c15da26Smrg
31243c15da26Smrg
31253c15da26Smrg# func_cygpath ARGS...
31263c15da26Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
31273c15da26Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
31283c15da26Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
31293c15da26Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
31303c15da26Smrg# file name or path is assumed to be in w32 format, as previously converted
31313c15da26Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
31323c15da26Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
31333c15da26Smrg# Cygwin format). Returns an empty string on error.
31343c15da26Smrg#
31353c15da26Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
31363c15da26Smrg# be converted.
31373c15da26Smrg#
31383c15da26Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
31393c15da26Smrg# environment variable; do not put it in $PATH.
31403c15da26Smrgfunc_cygpath ()
31413c15da26Smrg{
3142300346aeSmrg  $debug_cmd
3143300346aeSmrg
31443c15da26Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
31453c15da26Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
31463c15da26Smrg    if test "$?" -ne 0; then
31473c15da26Smrg      # on failure, ensure result is empty
31483c15da26Smrg      func_cygpath_result=
31493c15da26Smrg    fi
31503c15da26Smrg  else
31513c15da26Smrg    func_cygpath_result=
3152300346aeSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
31533c15da26Smrg  fi
31543c15da26Smrg}
31553c15da26Smrg#end: func_cygpath
31563c15da26Smrg
31573c15da26Smrg
31583c15da26Smrg# func_convert_core_msys_to_w32 ARG
31593c15da26Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
31603c15da26Smrg# result in func_convert_core_msys_to_w32_result.
31613c15da26Smrgfunc_convert_core_msys_to_w32 ()
31623c15da26Smrg{
3163300346aeSmrg  $debug_cmd
3164300346aeSmrg
31653c15da26Smrg  # awkward: cmd appends spaces to result
31663c15da26Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3167300346aeSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
31683c15da26Smrg}
31693c15da26Smrg#end: func_convert_core_msys_to_w32
31703c15da26Smrg
31713c15da26Smrg
31723c15da26Smrg# func_convert_file_check ARG1 ARG2
31733c15da26Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
31743c15da26Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
31753c15da26Smrg# func_to_host_file_result to ARG1).
31763c15da26Smrgfunc_convert_file_check ()
31773c15da26Smrg{
3178300346aeSmrg  $debug_cmd
3179300346aeSmrg
3180300346aeSmrg  if test -z "$2" && test -n "$1"; then
31813c15da26Smrg    func_error "Could not determine host file name corresponding to"
3182300346aeSmrg    func_error "  '$1'"
31833c15da26Smrg    func_error "Continuing, but uninstalled executables may not work."
31843c15da26Smrg    # Fallback:
3185300346aeSmrg    func_to_host_file_result=$1
31863c15da26Smrg  fi
31873c15da26Smrg}
31883c15da26Smrg# end func_convert_file_check
31893c15da26Smrg
31903c15da26Smrg
31913c15da26Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
31923c15da26Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
31933c15da26Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
31943c15da26Smrg# func_to_host_file_result to a simplistic fallback value (see below).
31953c15da26Smrgfunc_convert_path_check ()
31963c15da26Smrg{
3197300346aeSmrg  $debug_cmd
3198300346aeSmrg
31993c15da26Smrg  if test -z "$4" && test -n "$3"; then
32003c15da26Smrg    func_error "Could not determine the host path corresponding to"
3201300346aeSmrg    func_error "  '$3'"
32023c15da26Smrg    func_error "Continuing, but uninstalled executables may not work."
32033c15da26Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
32043c15da26Smrg    # should not be "improved".  See libtool.info.
32053c15da26Smrg    if test "x$1" != "x$2"; then
32063c15da26Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
32073c15da26Smrg      func_to_host_path_result=`echo "$3" |
32083c15da26Smrg        $SED -e "$lt_replace_pathsep_chars"`
32093c15da26Smrg    else
3210300346aeSmrg      func_to_host_path_result=$3
32113c15da26Smrg    fi
32123c15da26Smrg  fi
32133c15da26Smrg}
32143c15da26Smrg# end func_convert_path_check
32153c15da26Smrg
32163c15da26Smrg
32173c15da26Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
32183c15da26Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
32193c15da26Smrg# and appending REPL if ORIG matches BACKPAT.
32203c15da26Smrgfunc_convert_path_front_back_pathsep ()
32213c15da26Smrg{
3222300346aeSmrg  $debug_cmd
3223300346aeSmrg
32243c15da26Smrg  case $4 in
3225300346aeSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
32263c15da26Smrg    ;;
32273c15da26Smrg  esac
32283c15da26Smrg  case $4 in
32293c15da26Smrg  $2 ) func_append func_to_host_path_result "$3"
32303c15da26Smrg    ;;
32313c15da26Smrg  esac
32323c15da26Smrg}
32333c15da26Smrg# end func_convert_path_front_back_pathsep
32343c15da26Smrg
32353c15da26Smrg
32366bea0e4fSmrg# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER
32376bea0e4fSmrg# Replaces a delimiter for a given path.
32386bea0e4fSmrgfunc_convert_delimited_path ()
32396bea0e4fSmrg{
32406bea0e4fSmrg	converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"`
32416bea0e4fSmrg}
32426bea0e4fSmrg# end func_convert_delimited_path
32436bea0e4fSmrg
32446bea0e4fSmrg
32453c15da26Smrg##################################################
32463c15da26Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
32473c15da26Smrg##################################################
3248300346aeSmrg# invoked via '$to_host_file_cmd ARG'
32493c15da26Smrg#
32503c15da26Smrg# In each case, ARG is the path to be converted from $build to $host format.
32513c15da26Smrg# Result will be available in $func_to_host_file_result.
32523c15da26Smrg
32533c15da26Smrg
32543c15da26Smrg# func_to_host_file ARG
32553c15da26Smrg# Converts the file name ARG from $build format to $host format. Return result
32563c15da26Smrg# in func_to_host_file_result.
32573c15da26Smrgfunc_to_host_file ()
32583c15da26Smrg{
3259300346aeSmrg  $debug_cmd
3260300346aeSmrg
32613c15da26Smrg  $to_host_file_cmd "$1"
32623c15da26Smrg}
32633c15da26Smrg# end func_to_host_file
32643c15da26Smrg
32653c15da26Smrg
32663c15da26Smrg# func_to_tool_file ARG LAZY
32673c15da26Smrg# converts the file name ARG from $build format to toolchain format. Return
32683c15da26Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
32693c15da26Smrg# in (the comma separated) LAZY, no conversion takes place.
32703c15da26Smrgfunc_to_tool_file ()
32713c15da26Smrg{
3272300346aeSmrg  $debug_cmd
3273300346aeSmrg
32743c15da26Smrg  case ,$2, in
32753c15da26Smrg    *,"$to_tool_file_cmd",*)
32763c15da26Smrg      func_to_tool_file_result=$1
32773c15da26Smrg      ;;
32783c15da26Smrg    *)
32793c15da26Smrg      $to_tool_file_cmd "$1"
32803c15da26Smrg      func_to_tool_file_result=$func_to_host_file_result
32813c15da26Smrg      ;;
32823c15da26Smrg  esac
32833c15da26Smrg}
32843c15da26Smrg# end func_to_tool_file
32853c15da26Smrg
32863c15da26Smrg
32873c15da26Smrg# func_convert_file_noop ARG
32883c15da26Smrg# Copy ARG to func_to_host_file_result.
32893c15da26Smrgfunc_convert_file_noop ()
32903c15da26Smrg{
3291300346aeSmrg  func_to_host_file_result=$1
32923c15da26Smrg}
32933c15da26Smrg# end func_convert_file_noop
32943c15da26Smrg
32953c15da26Smrg
32963c15da26Smrg# func_convert_file_msys_to_w32 ARG
32973c15da26Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
32983c15da26Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
32993c15da26Smrg# func_to_host_file_result.
33003c15da26Smrgfunc_convert_file_msys_to_w32 ()
33013c15da26Smrg{
3302300346aeSmrg  $debug_cmd
3303300346aeSmrg
3304300346aeSmrg  func_to_host_file_result=$1
33053c15da26Smrg  if test -n "$1"; then
33063c15da26Smrg    func_convert_core_msys_to_w32 "$1"
3307300346aeSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
33083c15da26Smrg  fi
33093c15da26Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33103c15da26Smrg}
33113c15da26Smrg# end func_convert_file_msys_to_w32
33123c15da26Smrg
33133c15da26Smrg
33143c15da26Smrg# func_convert_file_cygwin_to_w32 ARG
33153c15da26Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
33163c15da26Smrg# func_to_host_file_result.
33173c15da26Smrgfunc_convert_file_cygwin_to_w32 ()
33183c15da26Smrg{
3319300346aeSmrg  $debug_cmd
3320300346aeSmrg
3321300346aeSmrg  func_to_host_file_result=$1
33223c15da26Smrg  if test -n "$1"; then
33233c15da26Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
33243c15da26Smrg    # LT_CYGPATH in this case.
33253c15da26Smrg    func_to_host_file_result=`cygpath -m "$1"`
33263c15da26Smrg  fi
33273c15da26Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33283c15da26Smrg}
33293c15da26Smrg# end func_convert_file_cygwin_to_w32
33303c15da26Smrg
33313c15da26Smrg
33323c15da26Smrg# func_convert_file_nix_to_w32 ARG
33333c15da26Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
33343c15da26Smrg# and a working winepath. Returns result in func_to_host_file_result.
33353c15da26Smrgfunc_convert_file_nix_to_w32 ()
33363c15da26Smrg{
3337300346aeSmrg  $debug_cmd
3338300346aeSmrg
3339300346aeSmrg  func_to_host_file_result=$1
33403c15da26Smrg  if test -n "$1"; then
33413c15da26Smrg    func_convert_core_file_wine_to_w32 "$1"
3342300346aeSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
33433c15da26Smrg  fi
33443c15da26Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33453c15da26Smrg}
33463c15da26Smrg# end func_convert_file_nix_to_w32
33473c15da26Smrg
33483c15da26Smrg
33493c15da26Smrg# func_convert_file_msys_to_cygwin ARG
33503c15da26Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
33513c15da26Smrg# Returns result in func_to_host_file_result.
33523c15da26Smrgfunc_convert_file_msys_to_cygwin ()
33533c15da26Smrg{
3354300346aeSmrg  $debug_cmd
3355300346aeSmrg
3356300346aeSmrg  func_to_host_file_result=$1
33573c15da26Smrg  if test -n "$1"; then
33583c15da26Smrg    func_convert_core_msys_to_w32 "$1"
33593c15da26Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3360300346aeSmrg    func_to_host_file_result=$func_cygpath_result
33613c15da26Smrg  fi
33623c15da26Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33633c15da26Smrg}
33643c15da26Smrg# end func_convert_file_msys_to_cygwin
33653c15da26Smrg
33663c15da26Smrg
33673c15da26Smrg# func_convert_file_nix_to_cygwin ARG
33683c15da26Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
33693c15da26Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
33703c15da26Smrg# in func_to_host_file_result.
33713c15da26Smrgfunc_convert_file_nix_to_cygwin ()
33723c15da26Smrg{
3373300346aeSmrg  $debug_cmd
3374300346aeSmrg
3375300346aeSmrg  func_to_host_file_result=$1
33763c15da26Smrg  if test -n "$1"; then
33773c15da26Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
33783c15da26Smrg    func_convert_core_file_wine_to_w32 "$1"
33793c15da26Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3380300346aeSmrg    func_to_host_file_result=$func_cygpath_result
33813c15da26Smrg  fi
33823c15da26Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33833c15da26Smrg}
33843c15da26Smrg# end func_convert_file_nix_to_cygwin
33853c15da26Smrg
33863c15da26Smrg
33873c15da26Smrg#############################################
33883c15da26Smrg# $build to $host PATH CONVERSION FUNCTIONS #
33893c15da26Smrg#############################################
3390300346aeSmrg# invoked via '$to_host_path_cmd ARG'
33913c15da26Smrg#
33923c15da26Smrg# In each case, ARG is the path to be converted from $build to $host format.
33933c15da26Smrg# The result will be available in $func_to_host_path_result.
33943c15da26Smrg#
33953c15da26Smrg# Path separators are also converted from $build format to $host format.  If
33963c15da26Smrg# ARG begins or ends with a path separator character, it is preserved (but
33973c15da26Smrg# converted to $host format) on output.
33983c15da26Smrg#
33993c15da26Smrg# All path conversion functions are named using the following convention:
34003c15da26Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
34013c15da26Smrg#   path conversion function         : func_convert_path_X_to_Y ()
34023c15da26Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
34033c15da26Smrg# same.  If conversion functions are added for new $build/$host combinations,
34043c15da26Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
34053c15da26Smrg# will break.
34063c15da26Smrg
34073c15da26Smrg
34083c15da26Smrg# func_init_to_host_path_cmd
34093c15da26Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
34103c15da26Smrg# appropriate value, based on the value of $to_host_file_cmd.
34113c15da26Smrgto_host_path_cmd=
34123c15da26Smrgfunc_init_to_host_path_cmd ()
34133c15da26Smrg{
3414300346aeSmrg  $debug_cmd
3415300346aeSmrg
34163c15da26Smrg  if test -z "$to_host_path_cmd"; then
34173c15da26Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3418300346aeSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
34193c15da26Smrg  fi
34203c15da26Smrg}
34213c15da26Smrg
34223c15da26Smrg
34233c15da26Smrg# func_to_host_path ARG
34243c15da26Smrg# Converts the path ARG from $build format to $host format. Return result
34253c15da26Smrg# in func_to_host_path_result.
34263c15da26Smrgfunc_to_host_path ()
34273c15da26Smrg{
3428300346aeSmrg  $debug_cmd
3429300346aeSmrg
34303c15da26Smrg  func_init_to_host_path_cmd
34313c15da26Smrg  $to_host_path_cmd "$1"
34323c15da26Smrg}
34333c15da26Smrg# end func_to_host_path
34343c15da26Smrg
34353c15da26Smrg
34363c15da26Smrg# func_convert_path_noop ARG
34373c15da26Smrg# Copy ARG to func_to_host_path_result.
34383c15da26Smrgfunc_convert_path_noop ()
34393c15da26Smrg{
3440300346aeSmrg  func_to_host_path_result=$1
34413c15da26Smrg}
34423c15da26Smrg# end func_convert_path_noop
34433c15da26Smrg
34443c15da26Smrg
34453c15da26Smrg# func_convert_path_msys_to_w32 ARG
34463c15da26Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
34473c15da26Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
34483c15da26Smrg# func_to_host_path_result.
34493c15da26Smrgfunc_convert_path_msys_to_w32 ()
3450d656433aSmrg{
3451300346aeSmrg  $debug_cmd
3452300346aeSmrg
3453300346aeSmrg  func_to_host_path_result=$1
34543c15da26Smrg  if test -n "$1"; then
34553c15da26Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
34563c15da26Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
34573c15da26Smrg    # and winepath ignores them completely.
34583c15da26Smrg    func_stripname : : "$1"
34593c15da26Smrg    func_to_host_path_tmp1=$func_stripname_result
34603c15da26Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3461300346aeSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
34623c15da26Smrg    func_convert_path_check : ";" \
34633c15da26Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34643c15da26Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34653c15da26Smrg  fi
34663c15da26Smrg}
34673c15da26Smrg# end func_convert_path_msys_to_w32
3468d656433aSmrg
3469d656433aSmrg
34703c15da26Smrg# func_convert_path_cygwin_to_w32 ARG
34713c15da26Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
34723c15da26Smrg# func_to_host_file_result.
34733c15da26Smrgfunc_convert_path_cygwin_to_w32 ()
34743c15da26Smrg{
3475300346aeSmrg  $debug_cmd
3476300346aeSmrg
3477300346aeSmrg  func_to_host_path_result=$1
34783c15da26Smrg  if test -n "$1"; then
34793c15da26Smrg    # See func_convert_path_msys_to_w32:
34803c15da26Smrg    func_stripname : : "$1"
34813c15da26Smrg    func_to_host_path_tmp1=$func_stripname_result
34823c15da26Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
34833c15da26Smrg    func_convert_path_check : ";" \
34843c15da26Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34853c15da26Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34863c15da26Smrg  fi
34873c15da26Smrg}
34883c15da26Smrg# end func_convert_path_cygwin_to_w32
3489d656433aSmrg
3490d656433aSmrg
34913c15da26Smrg# func_convert_path_nix_to_w32 ARG
34923c15da26Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
34933c15da26Smrg# a working winepath.  Returns result in func_to_host_file_result.
34943c15da26Smrgfunc_convert_path_nix_to_w32 ()
34953c15da26Smrg{
3496300346aeSmrg  $debug_cmd
3497300346aeSmrg
3498300346aeSmrg  func_to_host_path_result=$1
34993c15da26Smrg  if test -n "$1"; then
35003c15da26Smrg    # See func_convert_path_msys_to_w32:
35013c15da26Smrg    func_stripname : : "$1"
35023c15da26Smrg    func_to_host_path_tmp1=$func_stripname_result
35033c15da26Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3504300346aeSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
35053c15da26Smrg    func_convert_path_check : ";" \
35063c15da26Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35073c15da26Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
35083c15da26Smrg  fi
35093c15da26Smrg}
35103c15da26Smrg# end func_convert_path_nix_to_w32
3511d656433aSmrg
35123c15da26Smrg
35133c15da26Smrg# func_convert_path_msys_to_cygwin ARG
35143c15da26Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
35153c15da26Smrg# Returns result in func_to_host_file_result.
35163c15da26Smrgfunc_convert_path_msys_to_cygwin ()
35173c15da26Smrg{
3518300346aeSmrg  $debug_cmd
3519300346aeSmrg
3520300346aeSmrg  func_to_host_path_result=$1
35213c15da26Smrg  if test -n "$1"; then
35223c15da26Smrg    # See func_convert_path_msys_to_w32:
35233c15da26Smrg    func_stripname : : "$1"
35243c15da26Smrg    func_to_host_path_tmp1=$func_stripname_result
35253c15da26Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
35263c15da26Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3527300346aeSmrg    func_to_host_path_result=$func_cygpath_result
35283c15da26Smrg    func_convert_path_check : : \
35293c15da26Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35303c15da26Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
35313c15da26Smrg  fi
35323c15da26Smrg}
35333c15da26Smrg# end func_convert_path_msys_to_cygwin
35343c15da26Smrg
35353c15da26Smrg
35363c15da26Smrg# func_convert_path_nix_to_cygwin ARG
35373c15da26Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
35383c15da26Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
35393c15da26Smrg# func_to_host_file_result.
35403c15da26Smrgfunc_convert_path_nix_to_cygwin ()
35413c15da26Smrg{
3542300346aeSmrg  $debug_cmd
3543300346aeSmrg
3544300346aeSmrg  func_to_host_path_result=$1
35453c15da26Smrg  if test -n "$1"; then
35463c15da26Smrg    # Remove leading and trailing path separator characters from
35473c15da26Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
35483c15da26Smrg    # into '.;' and ';.', and winepath ignores them completely.
35493c15da26Smrg    func_stripname : : "$1"
35503c15da26Smrg    func_to_host_path_tmp1=$func_stripname_result
35513c15da26Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
35523c15da26Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3553300346aeSmrg    func_to_host_path_result=$func_cygpath_result
35543c15da26Smrg    func_convert_path_check : : \
35553c15da26Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35563c15da26Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
35573c15da26Smrg  fi
3558d656433aSmrg}
35593c15da26Smrg# end func_convert_path_nix_to_cygwin
35603c15da26Smrg
3561d656433aSmrg
3562300346aeSmrg# func_dll_def_p FILE
3563300346aeSmrg# True iff FILE is a Windows DLL '.def' file.
3564300346aeSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3565300346aeSmrgfunc_dll_def_p ()
3566300346aeSmrg{
3567300346aeSmrg  $debug_cmd
3568300346aeSmrg
3569300346aeSmrg  func_dll_def_p_tmp=`$SED -n \
3570300346aeSmrg    -e 's/^[	 ]*//' \
3571300346aeSmrg    -e '/^\(;.*\)*$/d' \
3572300346aeSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3573300346aeSmrg    -e q \
3574300346aeSmrg    "$1"`
3575300346aeSmrg  test DEF = "$func_dll_def_p_tmp"
3576300346aeSmrg}
3577300346aeSmrg
3578300346aeSmrg
35796bea0e4fSmrg# func_reorder_shared_lib_cache DIRS
35806bea0e4fSmrg# Reorder the shared library cache by unconfiguring previous shared library cache
35816bea0e4fSmrg# and configuring preferred search directories before previous search directories.
35826bea0e4fSmrg# Previous shared library cache: /usr/lib /usr/local/lib
35836bea0e4fSmrg# Preferred search directories: /tmp/testing
35846bea0e4fSmrg# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib
35856bea0e4fSmrgfunc_reorder_shared_lib_cache ()
35866bea0e4fSmrg{
35876bea0e4fSmrg	$debug_cmd
35886bea0e4fSmrg
35896bea0e4fSmrg	case $host_os in
35906bea0e4fSmrg	  openbsd*)
35916bea0e4fSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
35926bea0e4fSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
35936bea0e4fSmrg	    save_search_directories=$converted_path
35946bea0e4fSmrg	    func_convert_delimited_path "$1" ':' '\ '
35956bea0e4fSmrg
35966bea0e4fSmrg	    # Ensure directories exist
35976bea0e4fSmrg	    for dir in $converted_path; do
35986bea0e4fSmrg	      # Ensure each directory is an absolute path
35996bea0e4fSmrg	      case $dir in
36006bea0e4fSmrg	        /*) ;;
36016bea0e4fSmrg	        *) func_error "Directory '$dir' is not an absolute path"
36026bea0e4fSmrg	           exit $EXIT_FAILURE ;;
36036bea0e4fSmrg	      esac
36046bea0e4fSmrg	      # Ensure no trailing slashes
36056bea0e4fSmrg	      func_stripname '' '/' "$dir"
36066bea0e4fSmrg	      dir=$func_stripname_result
36076bea0e4fSmrg	      if test -d "$dir"; then
36086bea0e4fSmrg	        if test -n "$preferred_search_directories"; then
36096bea0e4fSmrg	          preferred_search_directories="$preferred_search_directories $dir"
36106bea0e4fSmrg	        else
36116bea0e4fSmrg	          preferred_search_directories=$dir
36126bea0e4fSmrg	        fi
36136bea0e4fSmrg	      else
36146bea0e4fSmrg	        func_error "Directory '$dir' does not exist"
36156bea0e4fSmrg	        exit $EXIT_FAILURE
36166bea0e4fSmrg	      fi
36176bea0e4fSmrg	    done
36186bea0e4fSmrg
36196bea0e4fSmrg	    PATH="$PATH:/sbin" ldconfig -U $save_search_directories
36206bea0e4fSmrg	    PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories
36216bea0e4fSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
36226bea0e4fSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
36236bea0e4fSmrg	    reordered_search_directories=$converted_path
36246bea0e4fSmrg
36256bea0e4fSmrg	    $ECHO "Original: $save_search_directories"
36266bea0e4fSmrg	    $ECHO "Reordered: $reordered_search_directories"
36276bea0e4fSmrg	    exit $EXIT_SUCCESS
36286bea0e4fSmrg	  ;;
36296bea0e4fSmrg	  *)
36306bea0e4fSmrg	    func_error "--reorder-cache is not supported for host_os=$host_os."
36316bea0e4fSmrg	    exit $EXIT_FAILURE
36326bea0e4fSmrg	  ;;
36336bea0e4fSmrg	esac
36346bea0e4fSmrg}
36356bea0e4fSmrg# end func_reorder_shared_lib_cache
36366bea0e4fSmrg
36376bea0e4fSmrg
3638d656433aSmrg# func_mode_compile arg...
3639d656433aSmrgfunc_mode_compile ()
3640d656433aSmrg{
3641300346aeSmrg    $debug_cmd
3642300346aeSmrg
3643d656433aSmrg    # Get the compilation command and the source file.
3644d656433aSmrg    base_compile=
3645300346aeSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3646d656433aSmrg    suppress_opt=yes
3647d656433aSmrg    suppress_output=
3648d656433aSmrg    arg_mode=normal
3649d656433aSmrg    libobj=
3650d656433aSmrg    later=
3651d656433aSmrg    pie_flag=
3652d656433aSmrg
3653d656433aSmrg    for arg
3654d656433aSmrg    do
3655d656433aSmrg      case $arg_mode in
3656d656433aSmrg      arg  )
3657d656433aSmrg	# do not "continue".  Instead, add this to base_compile
3658300346aeSmrg	lastarg=$arg
3659d656433aSmrg	arg_mode=normal
3660d656433aSmrg	;;
3661d656433aSmrg
3662d656433aSmrg      target )
3663300346aeSmrg	libobj=$arg
3664d656433aSmrg	arg_mode=normal
3665d656433aSmrg	continue
3666d656433aSmrg	;;
3667d656433aSmrg
3668d656433aSmrg      normal )
3669d656433aSmrg	# Accept any command-line options.
3670d656433aSmrg	case $arg in
3671d656433aSmrg	-o)
3672d656433aSmrg	  test -n "$libobj" && \
3673300346aeSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3674d656433aSmrg	  arg_mode=target
3675d656433aSmrg	  continue
3676d656433aSmrg	  ;;
3677d656433aSmrg
3678d656433aSmrg	-pie | -fpie | -fPIE)
36793c15da26Smrg          func_append pie_flag " $arg"
3680d656433aSmrg	  continue
3681d656433aSmrg	  ;;
3682d656433aSmrg
3683d656433aSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
36843c15da26Smrg	  func_append later " $arg"
3685d656433aSmrg	  continue
3686d656433aSmrg	  ;;
3687d656433aSmrg
3688d656433aSmrg	-no-suppress)
3689d656433aSmrg	  suppress_opt=no
3690d656433aSmrg	  continue
3691d656433aSmrg	  ;;
3692d656433aSmrg
3693d656433aSmrg	-Xcompiler)
3694d656433aSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3695d656433aSmrg	  continue      #  The current "srcfile" will either be retained or
3696d656433aSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3697d656433aSmrg
3698d656433aSmrg	-Wc,*)
3699d656433aSmrg	  func_stripname '-Wc,' '' "$arg"
3700d656433aSmrg	  args=$func_stripname_result
3701d656433aSmrg	  lastarg=
3702300346aeSmrg	  save_ifs=$IFS; IFS=,
3703d656433aSmrg	  for arg in $args; do
3704300346aeSmrg	    IFS=$save_ifs
37053c15da26Smrg	    func_append_quoted lastarg "$arg"
3706126a8a12Smrg	  done
3707300346aeSmrg	  IFS=$save_ifs
3708d656433aSmrg	  func_stripname ' ' '' "$lastarg"
3709d656433aSmrg	  lastarg=$func_stripname_result
3710126a8a12Smrg
3711126a8a12Smrg	  # Add the arguments to base_compile.
37123c15da26Smrg	  func_append base_compile " $lastarg"
3713126a8a12Smrg	  continue
3714126a8a12Smrg	  ;;
3715126a8a12Smrg
3716d656433aSmrg	*)
3717126a8a12Smrg	  # Accept the current argument as the source file.
3718126a8a12Smrg	  # The previous "srcfile" becomes the current argument.
3719126a8a12Smrg	  #
3720300346aeSmrg	  lastarg=$srcfile
3721300346aeSmrg	  srcfile=$arg
3722126a8a12Smrg	  ;;
3723126a8a12Smrg	esac  #  case $arg
3724126a8a12Smrg	;;
3725126a8a12Smrg      esac    #  case $arg_mode
3726126a8a12Smrg
3727126a8a12Smrg      # Aesthetically quote the previous argument.
37283c15da26Smrg      func_append_quoted base_compile "$lastarg"
3729126a8a12Smrg    done # for arg
3730126a8a12Smrg
3731126a8a12Smrg    case $arg_mode in
3732126a8a12Smrg    arg)
3733d656433aSmrg      func_fatal_error "you must specify an argument for -Xcompile"
3734126a8a12Smrg      ;;
3735126a8a12Smrg    target)
3736300346aeSmrg      func_fatal_error "you must specify a target with '-o'"
3737126a8a12Smrg      ;;
3738126a8a12Smrg    *)
3739126a8a12Smrg      # Get the name of the library object.
3740d656433aSmrg      test -z "$libobj" && {
3741d656433aSmrg	func_basename "$srcfile"
3742300346aeSmrg	libobj=$func_basename_result
3743d656433aSmrg      }
3744126a8a12Smrg      ;;
3745126a8a12Smrg    esac
3746126a8a12Smrg
3747126a8a12Smrg    # Recognize several different file suffixes.
3748126a8a12Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3749126a8a12Smrg    case $libobj in
3750d656433aSmrg    *.[cCFSifmso] | \
3751d656433aSmrg    *.ada | *.adb | *.ads | *.asm | \
3752d656433aSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
37530a6b08f8Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3754d656433aSmrg      func_xform "$libobj"
3755d656433aSmrg      libobj=$func_xform_result
3756d656433aSmrg      ;;
3757126a8a12Smrg    esac
3758126a8a12Smrg
3759126a8a12Smrg    case $libobj in
3760d656433aSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3761126a8a12Smrg    *)
3762300346aeSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3763126a8a12Smrg      ;;
3764126a8a12Smrg    esac
3765126a8a12Smrg
3766126a8a12Smrg    func_infer_tag $base_compile
3767126a8a12Smrg
3768126a8a12Smrg    for arg in $later; do
3769126a8a12Smrg      case $arg in
3770d656433aSmrg      -shared)
3771300346aeSmrg	test yes = "$build_libtool_libs" \
3772300346aeSmrg	  || func_fatal_configuration "cannot build a shared library"
3773d656433aSmrg	build_old_libs=no
3774d656433aSmrg	continue
3775d656433aSmrg	;;
3776d656433aSmrg
3777126a8a12Smrg      -static)
3778d656433aSmrg	build_libtool_libs=no
3779126a8a12Smrg	build_old_libs=yes
3780126a8a12Smrg	continue
3781126a8a12Smrg	;;
3782126a8a12Smrg
3783126a8a12Smrg      -prefer-pic)
3784126a8a12Smrg	pic_mode=yes
3785126a8a12Smrg	continue
3786126a8a12Smrg	;;
3787126a8a12Smrg
3788126a8a12Smrg      -prefer-non-pic)
3789126a8a12Smrg	pic_mode=no
3790126a8a12Smrg	continue
3791126a8a12Smrg	;;
3792126a8a12Smrg      esac
3793126a8a12Smrg    done
3794126a8a12Smrg
37953fb97780Smrg    func_quote_arg pretty "$libobj"
37963fb97780Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3797d656433aSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3798300346aeSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3799d656433aSmrg    func_dirname_and_basename "$obj" "/" ""
3800300346aeSmrg    objname=$func_basename_result
3801300346aeSmrg    xdir=$func_dirname_result
3802300346aeSmrg    lobj=$xdir$objdir/$objname
3803126a8a12Smrg
3804d656433aSmrg    test -z "$base_compile" && \
3805d656433aSmrg      func_fatal_help "you must specify a compilation command"
3806126a8a12Smrg
3807126a8a12Smrg    # Delete any leftover library objects.
3808300346aeSmrg    if test yes = "$build_old_libs"; then
3809126a8a12Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3810126a8a12Smrg    else
3811126a8a12Smrg      removelist="$lobj $libobj ${libobj}T"
3812126a8a12Smrg    fi
3813126a8a12Smrg
3814126a8a12Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3815126a8a12Smrg    case $host_os in
38166bea0e4fSmrg    cygwin* | mingw* | windows* | pw32* | os2* | cegcc*)
3817126a8a12Smrg      pic_mode=default
3818126a8a12Smrg      ;;
3819126a8a12Smrg    esac
3820300346aeSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3821126a8a12Smrg      # non-PIC code in shared libraries is not supported
3822126a8a12Smrg      pic_mode=default
3823126a8a12Smrg    fi
3824126a8a12Smrg
3825126a8a12Smrg    # Calculate the filename of the output object if compiler does
3826126a8a12Smrg    # not support -o with -c
3827300346aeSmrg    if test no = "$compiler_c_o"; then
3828300346aeSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3829300346aeSmrg      lockfile=$output_obj.lock
3830126a8a12Smrg    else
3831126a8a12Smrg      output_obj=
3832126a8a12Smrg      need_locks=no
3833126a8a12Smrg      lockfile=
3834126a8a12Smrg    fi
3835126a8a12Smrg
3836126a8a12Smrg    # Lock this critical section if it is needed
3837126a8a12Smrg    # We use this script file to make the link, it avoids creating a new file
3838300346aeSmrg    if test yes = "$need_locks"; then
3839d656433aSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3840d656433aSmrg	func_echo "Waiting for $lockfile to be removed"
3841126a8a12Smrg	sleep 2
3842126a8a12Smrg      done
3843300346aeSmrg    elif test warn = "$need_locks"; then
3844126a8a12Smrg      if test -f "$lockfile"; then
3845d656433aSmrg	$ECHO "\
3846126a8a12Smrg*** ERROR, $lockfile exists and contains:
3847126a8a12Smrg`cat $lockfile 2>/dev/null`
3848126a8a12Smrg
3849126a8a12SmrgThis indicates that another process is trying to use the same
3850126a8a12Smrgtemporary object file, and libtool could not work around it because
3851300346aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3852126a8a12Smrgrepeat this compilation, it may succeed, by chance, but you had better
3853126a8a12Smrgavoid parallel builds (make -j) in this platform, or get a better
3854126a8a12Smrgcompiler."
3855126a8a12Smrg
3856d656433aSmrg	$opt_dry_run || $RM $removelist
3857126a8a12Smrg	exit $EXIT_FAILURE
3858126a8a12Smrg      fi
38593c15da26Smrg      func_append removelist " $output_obj"
3860d656433aSmrg      $ECHO "$srcfile" > "$lockfile"
3861126a8a12Smrg    fi
3862126a8a12Smrg
3863d656433aSmrg    $opt_dry_run || $RM $removelist
38643c15da26Smrg    func_append removelist " $lockfile"
3865d656433aSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3866d656433aSmrg
38673c15da26Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
38683c15da26Smrg    srcfile=$func_to_tool_file_result
38693fb97780Smrg    func_quote_arg pretty "$srcfile"
38703fb97780Smrg    qsrcfile=$func_quote_arg_result
3871126a8a12Smrg
3872126a8a12Smrg    # Only build a PIC object if we are building libtool libraries.
3873300346aeSmrg    if test yes = "$build_libtool_libs"; then
3874126a8a12Smrg      # Without this assignment, base_compile gets emptied.
3875126a8a12Smrg      fbsd_hideous_sh_bug=$base_compile
3876126a8a12Smrg
3877300346aeSmrg      if test no != "$pic_mode"; then
3878126a8a12Smrg	command="$base_compile $qsrcfile $pic_flag"
3879126a8a12Smrg      else
3880126a8a12Smrg	# Don't build PIC code
3881126a8a12Smrg	command="$base_compile $qsrcfile"
3882126a8a12Smrg      fi
3883126a8a12Smrg
3884d656433aSmrg      func_mkdir_p "$xdir$objdir"
3885126a8a12Smrg
3886126a8a12Smrg      if test -z "$output_obj"; then
3887126a8a12Smrg	# Place PIC objects in $objdir
38883c15da26Smrg	func_append command " -o $lobj"
3889126a8a12Smrg      fi
3890126a8a12Smrg
3891d656433aSmrg      func_show_eval_locale "$command"	\
3892d656433aSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3893126a8a12Smrg
3894300346aeSmrg      if test warn = "$need_locks" &&
3895126a8a12Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3896d656433aSmrg	$ECHO "\
3897126a8a12Smrg*** ERROR, $lockfile contains:
3898126a8a12Smrg`cat $lockfile 2>/dev/null`
3899126a8a12Smrg
3900126a8a12Smrgbut it should contain:
3901126a8a12Smrg$srcfile
3902126a8a12Smrg
3903126a8a12SmrgThis indicates that another process is trying to use the same
3904126a8a12Smrgtemporary object file, and libtool could not work around it because
3905300346aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3906126a8a12Smrgrepeat this compilation, it may succeed, by chance, but you had better
3907126a8a12Smrgavoid parallel builds (make -j) in this platform, or get a better
3908126a8a12Smrgcompiler."
3909126a8a12Smrg
3910d656433aSmrg	$opt_dry_run || $RM $removelist
3911126a8a12Smrg	exit $EXIT_FAILURE
3912126a8a12Smrg      fi
3913126a8a12Smrg
3914126a8a12Smrg      # Just move the object if needed, then go on to compile the next one
3915126a8a12Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3916d656433aSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3917d656433aSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3918126a8a12Smrg      fi
3919126a8a12Smrg
3920126a8a12Smrg      # Allow error messages only from the first compilation.
3921300346aeSmrg      if test yes = "$suppress_opt"; then
3922d656433aSmrg	suppress_output=' >/dev/null 2>&1'
3923126a8a12Smrg      fi
3924126a8a12Smrg    fi
3925126a8a12Smrg
3926126a8a12Smrg    # Only build a position-dependent object if we build old libraries.
3927300346aeSmrg    if test yes = "$build_old_libs"; then
3928300346aeSmrg      if test yes != "$pic_mode"; then
3929126a8a12Smrg	# Don't build PIC code
3930d656433aSmrg	command="$base_compile $qsrcfile$pie_flag"
3931126a8a12Smrg      else
3932126a8a12Smrg	command="$base_compile $qsrcfile $pic_flag"
3933126a8a12Smrg      fi
3934300346aeSmrg      if test yes = "$compiler_c_o"; then
39353c15da26Smrg	func_append command " -o $obj"
3936126a8a12Smrg      fi
3937126a8a12Smrg
3938126a8a12Smrg      # Suppress compiler output if we already did a PIC compilation.
39393c15da26Smrg      func_append command "$suppress_output"
3940d656433aSmrg      func_show_eval_locale "$command" \
3941d656433aSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3942126a8a12Smrg
3943300346aeSmrg      if test warn = "$need_locks" &&
3944126a8a12Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3945d656433aSmrg	$ECHO "\
3946126a8a12Smrg*** ERROR, $lockfile contains:
3947126a8a12Smrg`cat $lockfile 2>/dev/null`
3948126a8a12Smrg
3949126a8a12Smrgbut it should contain:
3950126a8a12Smrg$srcfile
3951126a8a12Smrg
3952126a8a12SmrgThis indicates that another process is trying to use the same
3953126a8a12Smrgtemporary object file, and libtool could not work around it because
3954300346aeSmrgyour compiler does not support '-c' and '-o' together.  If you
3955126a8a12Smrgrepeat this compilation, it may succeed, by chance, but you had better
3956126a8a12Smrgavoid parallel builds (make -j) in this platform, or get a better
3957126a8a12Smrgcompiler."
3958126a8a12Smrg
3959d656433aSmrg	$opt_dry_run || $RM $removelist
3960126a8a12Smrg	exit $EXIT_FAILURE
3961126a8a12Smrg      fi
3962126a8a12Smrg
3963126a8a12Smrg      # Just move the object if needed
3964126a8a12Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3965d656433aSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
3966d656433aSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3967126a8a12Smrg      fi
3968126a8a12Smrg    fi
3969126a8a12Smrg
3970d656433aSmrg    $opt_dry_run || {
3971d656433aSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3972126a8a12Smrg
3973d656433aSmrg      # Unlock the critical section if it was locked
3974300346aeSmrg      if test no != "$need_locks"; then
3975d656433aSmrg	removelist=$lockfile
3976d656433aSmrg        $RM "$lockfile"
3977d656433aSmrg      fi
3978d656433aSmrg    }
3979126a8a12Smrg
3980126a8a12Smrg    exit $EXIT_SUCCESS
3981d656433aSmrg}
3982126a8a12Smrg
3983d656433aSmrg$opt_help || {
3984300346aeSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3985d656433aSmrg}
3986126a8a12Smrg
3987d656433aSmrgfunc_mode_help ()
3988d656433aSmrg{
3989d656433aSmrg    # We need to display help for each of the modes.
39903c15da26Smrg    case $opt_mode in
3991d656433aSmrg      "")
3992d656433aSmrg        # Generic help is extracted from the usage comments
3993d656433aSmrg        # at the start of this file.
3994d656433aSmrg        func_help
3995d656433aSmrg        ;;
3996126a8a12Smrg
3997d656433aSmrg      clean)
3998d656433aSmrg        $ECHO \
3999d656433aSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
4000126a8a12Smrg
4001d656433aSmrgRemove files from the build directory.
4002126a8a12Smrg
4003d656433aSmrgRM is the name of the program to use to delete files associated with each FILE
4004300346aeSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4005d656433aSmrgto RM.
4006126a8a12Smrg
4007d656433aSmrgIf FILE is a libtool library, object or program, all the files associated
4008d656433aSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
4009d656433aSmrg        ;;
4010126a8a12Smrg
4011d656433aSmrg      compile)
4012d656433aSmrg      $ECHO \
4013d656433aSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
4014126a8a12Smrg
4015d656433aSmrgCompile a source file into a libtool library object.
4016126a8a12Smrg
4017d656433aSmrgThis mode accepts the following additional options:
4018126a8a12Smrg
4019d656433aSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
4020d656433aSmrg  -no-suppress      do not suppress compiler output for multiple passes
4021555991fdSmrg  -prefer-pic       try to build PIC objects only
4022555991fdSmrg  -prefer-non-pic   try to build non-PIC objects only
4023300346aeSmrg  -shared           do not build a '.o' file suitable for static linking
4024300346aeSmrg  -static           only build a '.o' file suitable for static linking
40253fb97780Smrg  -Wc,FLAG
40263fb97780Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
4027126a8a12Smrg
4028300346aeSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
4029d656433aSmrgfrom the given SOURCEFILE.
4030126a8a12Smrg
4031d656433aSmrgThe output file name is determined by removing the directory component from
4032300346aeSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
4033300346aeSmrglibrary object suffix, '.lo'."
4034d656433aSmrg        ;;
4035126a8a12Smrg
4036d656433aSmrg      execute)
4037d656433aSmrg        $ECHO \
4038d656433aSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
4039126a8a12Smrg
4040d656433aSmrgAutomatically set library path, then run a program.
4041126a8a12Smrg
4042d656433aSmrgThis mode accepts the following additional options:
4043126a8a12Smrg
4044d656433aSmrg  -dlopen FILE      add the directory containing FILE to the library path
4045126a8a12Smrg
4046300346aeSmrgThis mode sets the library path environment variable according to '-dlopen'
4047d656433aSmrgflags.
4048126a8a12Smrg
4049d656433aSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
4050d656433aSmrginto their corresponding uninstalled binary, and any of their required library
4051d656433aSmrgdirectories are added to the library path.
4052126a8a12Smrg
4053d656433aSmrgThen, COMMAND is executed, with ARGS as arguments."
4054d656433aSmrg        ;;
4055126a8a12Smrg
4056d656433aSmrg      finish)
4057d656433aSmrg        $ECHO \
4058d656433aSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
4059126a8a12Smrg
4060d656433aSmrgComplete the installation of libtool libraries.
4061126a8a12Smrg
4062d656433aSmrgEach LIBDIR is a directory that contains libtool libraries.
4063126a8a12Smrg
4064d656433aSmrgThe commands that this mode executes may require superuser privileges.  Use
4065300346aeSmrgthe '--dry-run' option if you just want to see what would be executed."
4066d656433aSmrg        ;;
4067126a8a12Smrg
4068d656433aSmrg      install)
4069d656433aSmrg        $ECHO \
4070d656433aSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
4071126a8a12Smrg
4072d656433aSmrgInstall executables or libraries.
4073126a8a12Smrg
4074d656433aSmrgINSTALL-COMMAND is the installation command.  The first component should be
4075300346aeSmrgeither the 'install' or 'cp' program.
4076126a8a12Smrg
4077d656433aSmrgThe following components of INSTALL-COMMAND are treated specially:
4078126a8a12Smrg
4079555991fdSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
4080126a8a12Smrg
4081d656433aSmrgThe rest of the components are interpreted as arguments to that command (only
4082d656433aSmrgBSD-compatible install options are recognized)."
4083d656433aSmrg        ;;
4084126a8a12Smrg
4085d656433aSmrg      link)
4086d656433aSmrg        $ECHO \
4087d656433aSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
4088126a8a12Smrg
4089d656433aSmrgLink object files or libraries together to form another library, or to
4090d656433aSmrgcreate an executable program.
4091126a8a12Smrg
4092d656433aSmrgLINK-COMMAND is a command using the C compiler that you would use to create
4093d656433aSmrga program from several object files.
4094126a8a12Smrg
4095d656433aSmrgThe following components of LINK-COMMAND are treated specially:
4096126a8a12Smrg
4097d656433aSmrg  -all-static       do not do any dynamic linking at all
4098d656433aSmrg  -avoid-version    do not add a version suffix if possible
4099555991fdSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
4100555991fdSmrg                    libraries must be found in the PATH setting at runtime)
4101300346aeSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
4102d656433aSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
4103d656433aSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
4104d656433aSmrg  -export-symbols SYMFILE
4105d656433aSmrg                    try to export only the symbols listed in SYMFILE
4106d656433aSmrg  -export-symbols-regex REGEX
4107d656433aSmrg                    try to export only the symbols matching REGEX
4108d656433aSmrg  -LLIBDIR          search LIBDIR for required installed libraries
4109d656433aSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
4110d656433aSmrg  -module           build a library that can dlopened
4111d656433aSmrg  -no-fast-install  disable the fast-install mode
4112d656433aSmrg  -no-install       link a not-installable executable
4113d656433aSmrg  -no-undefined     declare that a library does not refer to external symbols
4114d656433aSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
4115300346aeSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
4116300346aeSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
4117d656433aSmrg  -precious-files-regex REGEX
4118d656433aSmrg                    don't remove output files matching REGEX
4119d656433aSmrg  -release RELEASE  specify package release information
4120d656433aSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4121d656433aSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4122d656433aSmrg  -shared           only do dynamic linking of libtool libraries
4123d656433aSmrg  -shrext SUFFIX    override the standard shared library file extension
4124d656433aSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4125d656433aSmrg  -static-libtool-libs
4126d656433aSmrg                    do not do any dynamic linking of libtool libraries
4127d656433aSmrg  -version-info CURRENT[:REVISION[:AGE]]
4128d656433aSmrg                    specify library version info [each variable defaults to 0]
4129d656433aSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4130555991fdSmrg  -Wc,FLAG
4131555991fdSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
41323fb97780Smrg  -Wa,FLAG
41333fb97780Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4134555991fdSmrg  -Wl,FLAG
4135555991fdSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4136555991fdSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4137126a8a12Smrg
4138300346aeSmrgAll other options (arguments beginning with '-') are ignored.
4139126a8a12Smrg
4140300346aeSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4141d656433aSmrgtreated as uninstalled libtool libraries, other files are standard or library
4142d656433aSmrgobject files.
4143126a8a12Smrg
4144300346aeSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4145300346aeSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4146d656433aSmrgrequired, except when creating a convenience library.
4147126a8a12Smrg
4148300346aeSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4149300346aeSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4150126a8a12Smrg
4151300346aeSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4152d656433aSmrgis created, otherwise an executable program is created."
4153126a8a12Smrg        ;;
4154126a8a12Smrg
4155d656433aSmrg      uninstall)
4156d656433aSmrg        $ECHO \
4157d656433aSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4158126a8a12Smrg
4159d656433aSmrgRemove libraries from an installation directory.
4160126a8a12Smrg
4161d656433aSmrgRM is the name of the program to use to delete files associated with each FILE
4162300346aeSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4163d656433aSmrgto RM.
4164126a8a12Smrg
4165d656433aSmrgIf FILE is a libtool library, all the files associated with it are deleted.
4166d656433aSmrgOtherwise, only FILE itself is deleted using RM."
4167d656433aSmrg        ;;
4168126a8a12Smrg
4169d656433aSmrg      *)
4170300346aeSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4171d656433aSmrg        ;;
4172d656433aSmrg    esac
4173126a8a12Smrg
4174555991fdSmrg    echo
4175300346aeSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4176d656433aSmrg}
4177126a8a12Smrg
4178555991fdSmrg# Now that we've collected a possible --mode arg, show help if necessary
4179555991fdSmrgif $opt_help; then
4180300346aeSmrg  if test : = "$opt_help"; then
4181555991fdSmrg    func_mode_help
4182555991fdSmrg  else
4183555991fdSmrg    {
4184555991fdSmrg      func_help noexit
41853c15da26Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4186555991fdSmrg	func_mode_help
4187555991fdSmrg      done
4188300346aeSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4189555991fdSmrg    {
4190555991fdSmrg      func_help noexit
41913c15da26Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4192555991fdSmrg	echo
4193555991fdSmrg	func_mode_help
4194555991fdSmrg      done
4195555991fdSmrg    } |
4196300346aeSmrg    $SED '1d
4197555991fdSmrg      /^When reporting/,/^Report/{
4198555991fdSmrg	H
4199555991fdSmrg	d
4200555991fdSmrg      }
4201555991fdSmrg      $x
4202555991fdSmrg      /information about other modes/d
4203555991fdSmrg      /more detailed .*MODE/d
4204555991fdSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4205555991fdSmrg  fi
4206555991fdSmrg  exit $?
4207555991fdSmrgfi
4208126a8a12Smrg
4209126a8a12Smrg
42106bea0e4fSmrg# If option '--reorder-cache', reorder the shared library cache and exit.
42116bea0e4fSmrgif $opt_reorder_cache; then
42126bea0e4fSmrg    func_reorder_shared_lib_cache $shared_lib_dirs
42136bea0e4fSmrgfi
42146bea0e4fSmrg
42156bea0e4fSmrg
4216d656433aSmrg# func_mode_execute arg...
4217d656433aSmrgfunc_mode_execute ()
4218d656433aSmrg{
4219300346aeSmrg    $debug_cmd
4220300346aeSmrg
4221d656433aSmrg    # The first argument is the command name.
4222300346aeSmrg    cmd=$nonopt
4223d656433aSmrg    test -z "$cmd" && \
4224d656433aSmrg      func_fatal_help "you must specify a COMMAND"
4225126a8a12Smrg
4226d656433aSmrg    # Handle -dlopen flags immediately.
42273c15da26Smrg    for file in $opt_dlopen; do
4228d656433aSmrg      test -f "$file" \
4229300346aeSmrg	|| func_fatal_help "'$file' is not a file"
4230126a8a12Smrg
4231d656433aSmrg      dir=
4232d656433aSmrg      case $file in
4233d656433aSmrg      *.la)
42343c15da26Smrg	func_resolve_sysroot "$file"
42353c15da26Smrg	file=$func_resolve_sysroot_result
42363c15da26Smrg
4237d656433aSmrg	# Check to see that this really is a libtool archive.
4238d656433aSmrg	func_lalib_unsafe_p "$file" \
4239300346aeSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4240126a8a12Smrg
4241d656433aSmrg	# Read the libtool library.
4242d656433aSmrg	dlname=
4243d656433aSmrg	library_names=
4244d656433aSmrg	func_source "$file"
4245126a8a12Smrg
4246d656433aSmrg	# Skip this library if it cannot be dlopened.
4247d656433aSmrg	if test -z "$dlname"; then
4248d656433aSmrg	  # Warn if it was a shared library.
4249d656433aSmrg	  test -n "$library_names" && \
4250300346aeSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4251d656433aSmrg	  continue
4252d656433aSmrg	fi
4253126a8a12Smrg
4254d656433aSmrg	func_dirname "$file" "" "."
4255300346aeSmrg	dir=$func_dirname_result
4256126a8a12Smrg
4257d656433aSmrg	if test -f "$dir/$objdir/$dlname"; then
42583c15da26Smrg	  func_append dir "/$objdir"
4259d656433aSmrg	else
4260d656433aSmrg	  if test ! -f "$dir/$dlname"; then
4261300346aeSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4262d656433aSmrg	  fi
4263d656433aSmrg	fi
4264126a8a12Smrg	;;
4265126a8a12Smrg
4266d656433aSmrg      *.lo)
4267d656433aSmrg	# Just add the directory containing the .lo file.
4268d656433aSmrg	func_dirname "$file" "" "."
4269300346aeSmrg	dir=$func_dirname_result
4270126a8a12Smrg	;;
4271126a8a12Smrg
4272d656433aSmrg      *)
4273300346aeSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4274126a8a12Smrg	continue
4275126a8a12Smrg	;;
4276d656433aSmrg      esac
4277126a8a12Smrg
4278d656433aSmrg      # Get the absolute pathname.
4279d656433aSmrg      absdir=`cd "$dir" && pwd`
4280300346aeSmrg      test -n "$absdir" && dir=$absdir
4281126a8a12Smrg
4282d656433aSmrg      # Now add the directory to shlibpath_var.
4283d656433aSmrg      if eval "test -z \"\$$shlibpath_var\""; then
4284d656433aSmrg	eval "$shlibpath_var=\"\$dir\""
4285d656433aSmrg      else
4286d656433aSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4287d656433aSmrg      fi
4288d656433aSmrg    done
4289126a8a12Smrg
4290d656433aSmrg    # This variable tells wrapper scripts just to set shlibpath_var
4291d656433aSmrg    # rather than running their programs.
4292300346aeSmrg    libtool_execute_magic=$magic
4293126a8a12Smrg
4294d656433aSmrg    # Check if any of the arguments is a wrapper script.
4295d656433aSmrg    args=
4296d656433aSmrg    for file
4297d656433aSmrg    do
4298d656433aSmrg      case $file in
4299555991fdSmrg      -* | *.la | *.lo ) ;;
4300d656433aSmrg      *)
4301d656433aSmrg	# Do a test to see if this is really a libtool program.
4302d656433aSmrg	if func_ltwrapper_script_p "$file"; then
4303d656433aSmrg	  func_source "$file"
4304d656433aSmrg	  # Transform arg to wrapped name.
4305300346aeSmrg	  file=$progdir/$program
4306d656433aSmrg	elif func_ltwrapper_executable_p "$file"; then
4307d656433aSmrg	  func_ltwrapper_scriptname "$file"
4308d656433aSmrg	  func_source "$func_ltwrapper_scriptname_result"
4309d656433aSmrg	  # Transform arg to wrapped name.
4310300346aeSmrg	  file=$progdir/$program
4311d656433aSmrg	fi
4312d656433aSmrg	;;
4313d656433aSmrg      esac
4314d656433aSmrg      # Quote arguments (to preserve shell metacharacters).
43153c15da26Smrg      func_append_quoted args "$file"
4316d656433aSmrg    done
4317126a8a12Smrg
4318300346aeSmrg    if $opt_dry_run; then
4319300346aeSmrg      # Display what would be done.
4320300346aeSmrg      if test -n "$shlibpath_var"; then
4321300346aeSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4322300346aeSmrg	echo "export $shlibpath_var"
4323300346aeSmrg      fi
4324300346aeSmrg      $ECHO "$cmd$args"
4325300346aeSmrg      exit $EXIT_SUCCESS
4326300346aeSmrg    else
4327d656433aSmrg      if test -n "$shlibpath_var"; then
4328d656433aSmrg	# Export the shlibpath_var.
4329d656433aSmrg	eval "export $shlibpath_var"
4330d656433aSmrg      fi
4331126a8a12Smrg
4332d656433aSmrg      # Restore saved environment variables
4333d656433aSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4334d656433aSmrg      do
4335d656433aSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4336d656433aSmrg                $lt_var=\$save_$lt_var; export $lt_var
4337d656433aSmrg	      else
4338d656433aSmrg		$lt_unset $lt_var
4339d656433aSmrg	      fi"
4340d656433aSmrg      done
4341126a8a12Smrg
4342d656433aSmrg      # Now prepare to actually exec the command.
4343300346aeSmrg      exec_cmd=\$cmd$args
4344d656433aSmrg    fi
4345d656433aSmrg}
4346126a8a12Smrg
4347300346aeSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4348126a8a12Smrg
4349126a8a12Smrg
4350d656433aSmrg# func_mode_finish arg...
4351d656433aSmrgfunc_mode_finish ()
4352d656433aSmrg{
4353300346aeSmrg    $debug_cmd
4354300346aeSmrg
43553c15da26Smrg    libs=
43563c15da26Smrg    libdirs=
4357d656433aSmrg    admincmds=
4358126a8a12Smrg
43593c15da26Smrg    for opt in "$nonopt" ${1+"$@"}
43603c15da26Smrg    do
43613c15da26Smrg      if test -d "$opt"; then
43623c15da26Smrg	func_append libdirs " $opt"
43633c15da26Smrg
43643c15da26Smrg      elif test -f "$opt"; then
43653c15da26Smrg	if func_lalib_unsafe_p "$opt"; then
43663c15da26Smrg	  func_append libs " $opt"
43673c15da26Smrg	else
4368300346aeSmrg	  func_warning "'$opt' is not a valid libtool archive"
43693c15da26Smrg	fi
43703c15da26Smrg
43713c15da26Smrg      else
4372300346aeSmrg	func_fatal_error "invalid argument '$opt'"
43733c15da26Smrg      fi
43743c15da26Smrg    done
43753c15da26Smrg
43763c15da26Smrg    if test -n "$libs"; then
43773c15da26Smrg      if test -n "$lt_sysroot"; then
43783c15da26Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
43793c15da26Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
43803c15da26Smrg      else
43813c15da26Smrg        sysroot_cmd=
43823c15da26Smrg      fi
43833c15da26Smrg
43843c15da26Smrg      # Remove sysroot references
43853c15da26Smrg      if $opt_dry_run; then
43863c15da26Smrg        for lib in $libs; do
4387300346aeSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
43883c15da26Smrg        done
43893c15da26Smrg      else
43903c15da26Smrg        tmpdir=`func_mktempdir`
43913c15da26Smrg        for lib in $libs; do
4392300346aeSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
43933c15da26Smrg	    > $tmpdir/tmp-la
43943c15da26Smrg	  mv -f $tmpdir/tmp-la $lib
43953c15da26Smrg	done
43963c15da26Smrg        ${RM}r "$tmpdir"
43973c15da26Smrg      fi
43983c15da26Smrg    fi
4399126a8a12Smrg
44006bea0e4fSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs" && $opt_finishing; then
4401d656433aSmrg      for libdir in $libdirs; do
4402d656433aSmrg	if test -n "$finish_cmds"; then
4403d656433aSmrg	  # Do each command in the finish commands.
4404d656433aSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4405d656433aSmrg'"$cmd"'"'
4406d656433aSmrg	fi
4407d656433aSmrg	if test -n "$finish_eval"; then
4408d656433aSmrg	  # Do the single finish_eval.
4409d656433aSmrg	  eval cmds=\"$finish_eval\"
44103c15da26Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4411d656433aSmrg       $cmds"
4412d656433aSmrg	fi
4413d656433aSmrg      done
4414d656433aSmrg    fi
4415126a8a12Smrg
4416d656433aSmrg    # Exit here if they wanted silent mode.
4417300346aeSmrg    $opt_quiet && exit $EXIT_SUCCESS
4418126a8a12Smrg
44193c15da26Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
44203c15da26Smrg      echo "----------------------------------------------------------------------"
44213c15da26Smrg      echo "Libraries have been installed in:"
44223c15da26Smrg      for libdir in $libdirs; do
44233c15da26Smrg	$ECHO "   $libdir"
44243c15da26Smrg      done
44256bea0e4fSmrg      if test "false" = "$opt_finishing"; then
44266bea0e4fSmrg        echo
44276bea0e4fSmrg        echo "NOTE: finish_cmds were not executed during testing, so you must"
44286bea0e4fSmrg        echo "manually run ldconfig to add a given test directory, LIBDIR, to"
44296bea0e4fSmrg        echo "the search path for generated executables."
44306bea0e4fSmrg      fi
44313c15da26Smrg      echo
44323c15da26Smrg      echo "If you ever happen to want to link against installed libraries"
44333c15da26Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4434300346aeSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
44353c15da26Smrg      echo "flag during linking and do at least one of the following:"
44363c15da26Smrg      if test -n "$shlibpath_var"; then
4437300346aeSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
44383c15da26Smrg	echo "     during execution"
44393c15da26Smrg      fi
44403c15da26Smrg      if test -n "$runpath_var"; then
4441300346aeSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
44423c15da26Smrg	echo "     during linking"
44433c15da26Smrg      fi
44443c15da26Smrg      if test -n "$hardcode_libdir_flag_spec"; then
44453c15da26Smrg	libdir=LIBDIR
44463c15da26Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4447126a8a12Smrg
4448300346aeSmrg	$ECHO "   - use the '$flag' linker flag"
44493c15da26Smrg      fi
44503c15da26Smrg      if test -n "$admincmds"; then
44513c15da26Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
44523c15da26Smrg      fi
44533c15da26Smrg      if test -f /etc/ld.so.conf; then
4454300346aeSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
44553c15da26Smrg      fi
44563c15da26Smrg      echo
4457126a8a12Smrg
44583c15da26Smrg      echo "See any operating system documentation about shared libraries for"
44593c15da26Smrg      case $host in
44603c15da26Smrg	solaris2.[6789]|solaris2.1[0-9])
44613c15da26Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
44623c15da26Smrg	  echo "pages."
44633c15da26Smrg	  ;;
44643c15da26Smrg	*)
44653c15da26Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
44663c15da26Smrg	  ;;
44673c15da26Smrg      esac
44683c15da26Smrg      echo "----------------------------------------------------------------------"
44693c15da26Smrg    fi
4470d656433aSmrg    exit $EXIT_SUCCESS
4471d656433aSmrg}
4472126a8a12Smrg
4473300346aeSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4474126a8a12Smrg
4475126a8a12Smrg
4476d656433aSmrg# func_mode_install arg...
4477d656433aSmrgfunc_mode_install ()
4478d656433aSmrg{
4479300346aeSmrg    $debug_cmd
4480300346aeSmrg
4481d656433aSmrg    # There may be an optional sh(1) argument at the beginning of
4482d656433aSmrg    # install_prog (especially on Windows NT).
4483300346aeSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4484d656433aSmrg       # Allow the use of GNU shtool's install command.
4485300346aeSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4486300346aeSmrg    then
4487d656433aSmrg      # Aesthetically quote it.
44883fb97780Smrg      func_quote_arg pretty "$nonopt"
44893fb97780Smrg      install_prog="$func_quote_arg_result "
4490d656433aSmrg      arg=$1
4491d656433aSmrg      shift
4492d656433aSmrg    else
4493d656433aSmrg      install_prog=
4494d656433aSmrg      arg=$nonopt
4495d656433aSmrg    fi
4496126a8a12Smrg
4497d656433aSmrg    # The real first argument should be the name of the installation program.
4498d656433aSmrg    # Aesthetically quote it.
44993fb97780Smrg    func_quote_arg pretty "$arg"
45003fb97780Smrg    func_append install_prog "$func_quote_arg_result"
4501555991fdSmrg    install_shared_prog=$install_prog
4502555991fdSmrg    case " $install_prog " in
4503555991fdSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4504555991fdSmrg      *) install_cp=false ;;
4505555991fdSmrg    esac
4506d656433aSmrg
4507d656433aSmrg    # We need to accept at least all the BSD install flags.
4508d656433aSmrg    dest=
4509d656433aSmrg    files=
4510d656433aSmrg    opts=
4511d656433aSmrg    prev=
4512d656433aSmrg    install_type=
4513300346aeSmrg    isdir=false
4514d656433aSmrg    stripme=
4515555991fdSmrg    no_mode=:
4516d656433aSmrg    for arg
4517d656433aSmrg    do
4518555991fdSmrg      arg2=
4519d656433aSmrg      if test -n "$dest"; then
45203c15da26Smrg	func_append files " $dest"
4521d656433aSmrg	dest=$arg
4522d656433aSmrg	continue
4523126a8a12Smrg      fi
4524126a8a12Smrg
4525d656433aSmrg      case $arg in
4526300346aeSmrg      -d) isdir=: ;;
4527d656433aSmrg      -f)
4528555991fdSmrg	if $install_cp; then :; else
4529555991fdSmrg	  prev=$arg
4530555991fdSmrg	fi
4531d656433aSmrg	;;
4532d656433aSmrg      -g | -m | -o)
4533d656433aSmrg	prev=$arg
4534d656433aSmrg	;;
4535d656433aSmrg      -s)
4536d656433aSmrg	stripme=" -s"
4537d656433aSmrg	continue
4538d656433aSmrg	;;
4539d656433aSmrg      -*)
4540d656433aSmrg	;;
4541d656433aSmrg      *)
4542d656433aSmrg	# If the previous option needed an argument, then skip it.
4543d656433aSmrg	if test -n "$prev"; then
4544300346aeSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4545555991fdSmrg	    arg2=$install_override_mode
4546555991fdSmrg	    no_mode=false
4547555991fdSmrg	  fi
4548d656433aSmrg	  prev=
4549d656433aSmrg	else
4550d656433aSmrg	  dest=$arg
4551d656433aSmrg	  continue
4552d656433aSmrg	fi
4553d656433aSmrg	;;
4554d656433aSmrg      esac
4555126a8a12Smrg
4556d656433aSmrg      # Aesthetically quote the argument.
45573fb97780Smrg      func_quote_arg pretty "$arg"
45583fb97780Smrg      func_append install_prog " $func_quote_arg_result"
4559555991fdSmrg      if test -n "$arg2"; then
45603fb97780Smrg	func_quote_arg pretty "$arg2"
4561555991fdSmrg      fi
45623fb97780Smrg      func_append install_shared_prog " $func_quote_arg_result"
4563d656433aSmrg    done
4564126a8a12Smrg
4565d656433aSmrg    test -z "$install_prog" && \
4566d656433aSmrg      func_fatal_help "you must specify an install program"
4567126a8a12Smrg
4568d656433aSmrg    test -n "$prev" && \
4569300346aeSmrg      func_fatal_help "the '$prev' option requires an argument"
4570126a8a12Smrg
4571555991fdSmrg    if test -n "$install_override_mode" && $no_mode; then
4572555991fdSmrg      if $install_cp; then :; else
45733fb97780Smrg	func_quote_arg pretty "$install_override_mode"
45743fb97780Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4575555991fdSmrg      fi
4576555991fdSmrg    fi
4577555991fdSmrg
4578d656433aSmrg    if test -z "$files"; then
4579d656433aSmrg      if test -z "$dest"; then
4580d656433aSmrg	func_fatal_help "no file or destination specified"
4581d656433aSmrg      else
4582d656433aSmrg	func_fatal_help "you must specify a destination"
4583126a8a12Smrg      fi
4584126a8a12Smrg    fi
4585126a8a12Smrg
4586d656433aSmrg    # Strip any trailing slash from the destination.
4587d656433aSmrg    func_stripname '' '/' "$dest"
4588d656433aSmrg    dest=$func_stripname_result
4589126a8a12Smrg
4590d656433aSmrg    # Check to see that the destination is a directory.
4591300346aeSmrg    test -d "$dest" && isdir=:
4592300346aeSmrg    if $isdir; then
4593300346aeSmrg      destdir=$dest
4594d656433aSmrg      destname=
4595d656433aSmrg    else
4596d656433aSmrg      func_dirname_and_basename "$dest" "" "."
4597300346aeSmrg      destdir=$func_dirname_result
4598300346aeSmrg      destname=$func_basename_result
4599d656433aSmrg
4600d656433aSmrg      # Not a directory, so check to see that there is only one file specified.
4601d656433aSmrg      set dummy $files; shift
4602d656433aSmrg      test "$#" -gt 1 && \
4603300346aeSmrg	func_fatal_help "'$dest' is not a directory"
4604d656433aSmrg    fi
4605d656433aSmrg    case $destdir in
4606d656433aSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4607126a8a12Smrg    *)
4608d656433aSmrg      for file in $files; do
4609d656433aSmrg	case $file in
4610d656433aSmrg	*.lo) ;;
4611d656433aSmrg	*)
4612300346aeSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4613d656433aSmrg	  ;;
4614d656433aSmrg	esac
4615d656433aSmrg      done
4616126a8a12Smrg      ;;
4617126a8a12Smrg    esac
4618126a8a12Smrg
4619d656433aSmrg    # This variable tells wrapper scripts just to set variables rather
4620d656433aSmrg    # than running their programs.
4621300346aeSmrg    libtool_install_magic=$magic
4622126a8a12Smrg
4623d656433aSmrg    staticlibs=
4624d656433aSmrg    future_libdirs=
4625d656433aSmrg    current_libdirs=
4626d656433aSmrg    for file in $files; do
4627126a8a12Smrg
4628d656433aSmrg      # Do each installation.
4629d656433aSmrg      case $file in
4630d656433aSmrg      *.$libext)
4631d656433aSmrg	# Do the static libraries later.
46323c15da26Smrg	func_append staticlibs " $file"
4633d656433aSmrg	;;
4634d656433aSmrg
4635d656433aSmrg      *.la)
46363c15da26Smrg	func_resolve_sysroot "$file"
46373c15da26Smrg	file=$func_resolve_sysroot_result
46383c15da26Smrg
4639d656433aSmrg	# Check to see that this really is a libtool archive.
4640d656433aSmrg	func_lalib_unsafe_p "$file" \
4641300346aeSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4642d656433aSmrg
4643d656433aSmrg	library_names=
4644d656433aSmrg	old_library=
4645d656433aSmrg	relink_command=
4646d656433aSmrg	func_source "$file"
4647d656433aSmrg
4648d656433aSmrg	# Add the libdir to current_libdirs if it is the destination.
4649d656433aSmrg	if test "X$destdir" = "X$libdir"; then
4650d656433aSmrg	  case "$current_libdirs " in
4651d656433aSmrg	  *" $libdir "*) ;;
46523c15da26Smrg	  *) func_append current_libdirs " $libdir" ;;
4653126a8a12Smrg	  esac
4654d656433aSmrg	else
4655d656433aSmrg	  # Note the libdir as a future libdir.
4656d656433aSmrg	  case "$future_libdirs " in
4657d656433aSmrg	  *" $libdir "*) ;;
46583c15da26Smrg	  *) func_append future_libdirs " $libdir" ;;
4659d656433aSmrg	  esac
4660d656433aSmrg	fi
4661126a8a12Smrg
4662d656433aSmrg	func_dirname "$file" "/" ""
4663300346aeSmrg	dir=$func_dirname_result
46643c15da26Smrg	func_append dir "$objdir"
4665d656433aSmrg
4666d656433aSmrg	if test -n "$relink_command"; then
46676bea0e4fSmrg	  # Strip any trailing slash from the destination.
46686bea0e4fSmrg	  func_stripname '' '/' "$libdir"
46696bea0e4fSmrg	  destlibdir=$func_stripname_result
46706bea0e4fSmrg
46716bea0e4fSmrg	  func_stripname '' '/' "$destdir"
46726bea0e4fSmrg	  s_destdir=$func_stripname_result
46736bea0e4fSmrg
4674d656433aSmrg	  # Determine the prefix the user has applied to our future dir.
46756bea0e4fSmrg	  inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"`
4676d656433aSmrg
4677d656433aSmrg	  # Don't allow the user to place us outside of our expected
4678d656433aSmrg	  # location b/c this prevents finding dependent libraries that
4679d656433aSmrg	  # are installed to the same prefix.
4680d656433aSmrg	  # At present, this check doesn't affect windows .dll's that
4681d656433aSmrg	  # are installed into $libdir/../bin (currently, that works fine)
4682d656433aSmrg	  # but it's something to keep an eye on.
4683d656433aSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4684300346aeSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4685d656433aSmrg
4686d656433aSmrg	  if test -n "$inst_prefix_dir"; then
4687d656433aSmrg	    # Stick the inst_prefix_dir data into the link command.
4688555991fdSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4689d656433aSmrg	  else
4690555991fdSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4691d656433aSmrg	  fi
4692d656433aSmrg
4693300346aeSmrg	  func_warning "relinking '$file'"
4694d656433aSmrg	  func_show_eval "$relink_command" \
4695300346aeSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4696d656433aSmrg	fi
4697d656433aSmrg
4698d656433aSmrg	# See the names of the shared library.
4699d656433aSmrg	set dummy $library_names; shift
4700d656433aSmrg	if test -n "$1"; then
4701300346aeSmrg	  realname=$1
4702d656433aSmrg	  shift
4703d656433aSmrg
4704300346aeSmrg	  srcname=$realname
4705300346aeSmrg	  test -n "$relink_command" && srcname=${realname}T
4706d656433aSmrg
4707d656433aSmrg	  # Install the shared library and build the symlinks.
4708555991fdSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4709d656433aSmrg	      'exit $?'
4710300346aeSmrg	  tstripme=$stripme
4711d656433aSmrg	  case $host_os in
47126bea0e4fSmrg	  cygwin* | mingw* | windows* | pw32* | cegcc*)
4713d656433aSmrg	    case $realname in
4714d656433aSmrg	    *.dll.a)
4715300346aeSmrg	      tstripme=
4716300346aeSmrg	      ;;
4717300346aeSmrg	    esac
4718300346aeSmrg	    ;;
4719300346aeSmrg	  os2*)
4720300346aeSmrg	    case $realname in
4721300346aeSmrg	    *_dll.a)
4722300346aeSmrg	      tstripme=
4723d656433aSmrg	      ;;
4724d656433aSmrg	    esac
4725126a8a12Smrg	    ;;
4726126a8a12Smrg	  esac
4727d656433aSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
4728d656433aSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4729126a8a12Smrg	  fi
4730d656433aSmrg
4731d656433aSmrg	  if test "$#" -gt 0; then
4732d656433aSmrg	    # Delete the old symlinks, and create new ones.
4733300346aeSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4734d656433aSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4735d656433aSmrg	    # so we also need to try rm && ln -s.
4736d656433aSmrg	    for linkname
4737d656433aSmrg	    do
4738d656433aSmrg	      test "$linkname" != "$realname" \
4739d656433aSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4740126a8a12Smrg	    done
4741126a8a12Smrg	  fi
4742126a8a12Smrg
4743d656433aSmrg	  # Do each command in the postinstall commands.
4744300346aeSmrg	  lib=$destdir/$realname
4745d656433aSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4746126a8a12Smrg	fi
4747126a8a12Smrg
4748d656433aSmrg	# Install the pseudo-library for information purposes.
4749d656433aSmrg	func_basename "$file"
4750300346aeSmrg	name=$func_basename_result
4751300346aeSmrg	instname=$dir/${name}i
4752d656433aSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4753126a8a12Smrg
4754d656433aSmrg	# Maybe install the static library, too.
47553c15da26Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4756d656433aSmrg	;;
4757126a8a12Smrg
4758d656433aSmrg      *.lo)
4759d656433aSmrg	# Install (i.e. copy) a libtool object.
4760126a8a12Smrg
4761d656433aSmrg	# Figure out destination file name, if it wasn't already specified.
4762d656433aSmrg	if test -n "$destname"; then
4763300346aeSmrg	  destfile=$destdir/$destname
4764d656433aSmrg	else
4765d656433aSmrg	  func_basename "$file"
4766300346aeSmrg	  destfile=$func_basename_result
4767300346aeSmrg	  destfile=$destdir/$destfile
4768d656433aSmrg	fi
4769d656433aSmrg
4770d656433aSmrg	# Deduce the name of the destination old-style object file.
4771d656433aSmrg	case $destfile in
4772d656433aSmrg	*.lo)
4773d656433aSmrg	  func_lo2o "$destfile"
4774d656433aSmrg	  staticdest=$func_lo2o_result
4775d656433aSmrg	  ;;
4776d656433aSmrg	*.$objext)
4777300346aeSmrg	  staticdest=$destfile
4778d656433aSmrg	  destfile=
4779d656433aSmrg	  ;;
4780d656433aSmrg	*)
4781300346aeSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4782d656433aSmrg	  ;;
4783126a8a12Smrg	esac
4784126a8a12Smrg
4785d656433aSmrg	# Install the libtool object if requested.
4786d656433aSmrg	test -n "$destfile" && \
4787d656433aSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4788d656433aSmrg
4789d656433aSmrg	# Install the old object if enabled.
4790300346aeSmrg	if test yes = "$build_old_libs"; then
4791d656433aSmrg	  # Deduce the name of the old-style object file.
4792d656433aSmrg	  func_lo2o "$file"
4793d656433aSmrg	  staticobj=$func_lo2o_result
4794d656433aSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4795126a8a12Smrg	fi
4796d656433aSmrg	exit $EXIT_SUCCESS
4797d656433aSmrg	;;
4798126a8a12Smrg
4799d656433aSmrg      *)
4800d656433aSmrg	# Figure out destination file name, if it wasn't already specified.
4801d656433aSmrg	if test -n "$destname"; then
4802300346aeSmrg	  destfile=$destdir/$destname
4803d656433aSmrg	else
4804d656433aSmrg	  func_basename "$file"
4805300346aeSmrg	  destfile=$func_basename_result
4806300346aeSmrg	  destfile=$destdir/$destfile
4807d656433aSmrg	fi
4808d656433aSmrg
4809d656433aSmrg	# If the file is missing, and there is a .exe on the end, strip it
4810d656433aSmrg	# because it is most likely a libtool script we actually want to
4811d656433aSmrg	# install
4812300346aeSmrg	stripped_ext=
4813d656433aSmrg	case $file in
4814d656433aSmrg	  *.exe)
4815d656433aSmrg	    if test ! -f "$file"; then
4816d656433aSmrg	      func_stripname '' '.exe' "$file"
4817d656433aSmrg	      file=$func_stripname_result
4818300346aeSmrg	      stripped_ext=.exe
4819126a8a12Smrg	    fi
4820d656433aSmrg	    ;;
4821d656433aSmrg	esac
4822126a8a12Smrg
4823d656433aSmrg	# Do a test to see if this is really a libtool program.
4824d656433aSmrg	case $host in
48256bea0e4fSmrg	*cygwin* | *mingw* | *windows*)
4826d656433aSmrg	    if func_ltwrapper_executable_p "$file"; then
4827d656433aSmrg	      func_ltwrapper_scriptname "$file"
4828d656433aSmrg	      wrapper=$func_ltwrapper_scriptname_result
4829d656433aSmrg	    else
4830d656433aSmrg	      func_stripname '' '.exe' "$file"
4831d656433aSmrg	      wrapper=$func_stripname_result
4832d656433aSmrg	    fi
4833d656433aSmrg	    ;;
4834d656433aSmrg	*)
4835d656433aSmrg	    wrapper=$file
4836d656433aSmrg	    ;;
4837d656433aSmrg	esac
4838d656433aSmrg	if func_ltwrapper_script_p "$wrapper"; then
4839d656433aSmrg	  notinst_deplibs=
4840d656433aSmrg	  relink_command=
4841126a8a12Smrg
4842d656433aSmrg	  func_source "$wrapper"
4843126a8a12Smrg
4844d656433aSmrg	  # Check the variables that should have been set.
4845d656433aSmrg	  test -z "$generated_by_libtool_version" && \
4846300346aeSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4847d656433aSmrg
4848300346aeSmrg	  finalize=:
4849d656433aSmrg	  for lib in $notinst_deplibs; do
4850d656433aSmrg	    # Check to see that each library is installed.
4851d656433aSmrg	    libdir=
4852d656433aSmrg	    if test -f "$lib"; then
4853d656433aSmrg	      func_source "$lib"
4854d656433aSmrg	    fi
4855300346aeSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4856d656433aSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4857300346aeSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4858300346aeSmrg	      finalize=false
4859d656433aSmrg	    fi
4860d656433aSmrg	  done
4861d656433aSmrg
4862d656433aSmrg	  relink_command=
4863d656433aSmrg	  func_source "$wrapper"
4864d656433aSmrg
4865d656433aSmrg	  outputname=
4866300346aeSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4867d656433aSmrg	    $opt_dry_run || {
4868300346aeSmrg	      if $finalize; then
4869d656433aSmrg	        tmpdir=`func_mktempdir`
4870d656433aSmrg		func_basename "$file$stripped_ext"
4871300346aeSmrg		file=$func_basename_result
4872300346aeSmrg	        outputname=$tmpdir/$file
4873d656433aSmrg	        # Replace the output file specification.
4874555991fdSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4875d656433aSmrg
4876300346aeSmrg	        $opt_quiet || {
48773fb97780Smrg	          func_quote_arg expand,pretty "$relink_command"
48783fb97780Smrg		  eval "func_echo $func_quote_arg_result"
4879d656433aSmrg	        }
4880d656433aSmrg	        if eval "$relink_command"; then :
4881d656433aSmrg	          else
4882300346aeSmrg		  func_error "error: relink '$file' with the above command before installing it"
4883d656433aSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
4884d656433aSmrg		  continue
4885d656433aSmrg	        fi
4886300346aeSmrg	        file=$outputname
4887d656433aSmrg	      else
4888300346aeSmrg	        func_warning "cannot relink '$file'"
4889d656433aSmrg	      fi
4890d656433aSmrg	    }
4891126a8a12Smrg	  else
4892d656433aSmrg	    # Install the binary that we compiled earlier.
4893555991fdSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4894126a8a12Smrg	  fi
4895d656433aSmrg	fi
4896126a8a12Smrg
4897d656433aSmrg	# remove .exe since cygwin /usr/bin/install will append another
4898d656433aSmrg	# one anyway
4899d656433aSmrg	case $install_prog,$host in
4900d656433aSmrg	*/usr/bin/install*,*cygwin*)
4901d656433aSmrg	  case $file:$destfile in
4902d656433aSmrg	  *.exe:*.exe)
4903d656433aSmrg	    # this is ok
4904d656433aSmrg	    ;;
4905d656433aSmrg	  *.exe:*)
4906d656433aSmrg	    destfile=$destfile.exe
4907d656433aSmrg	    ;;
4908d656433aSmrg	  *:*.exe)
4909d656433aSmrg	    func_stripname '' '.exe' "$destfile"
4910d656433aSmrg	    destfile=$func_stripname_result
4911d656433aSmrg	    ;;
4912d656433aSmrg	  esac
4913126a8a12Smrg	  ;;
4914126a8a12Smrg	esac
4915d656433aSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4916d656433aSmrg	$opt_dry_run || if test -n "$outputname"; then
4917d656433aSmrg	  ${RM}r "$tmpdir"
4918d656433aSmrg	fi
4919d656433aSmrg	;;
4920d656433aSmrg      esac
4921d656433aSmrg    done
4922126a8a12Smrg
4923d656433aSmrg    for file in $staticlibs; do
4924d656433aSmrg      func_basename "$file"
4925300346aeSmrg      name=$func_basename_result
4926126a8a12Smrg
4927d656433aSmrg      # Set up the ranlib parameters.
4928300346aeSmrg      oldlib=$destdir/$name
49290a6b08f8Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
49300a6b08f8Smrg      tool_oldlib=$func_to_tool_file_result
4931126a8a12Smrg
4932d656433aSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4933126a8a12Smrg
4934d656433aSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
49350a6b08f8Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4936d656433aSmrg      fi
4937126a8a12Smrg
4938d656433aSmrg      # Do each command in the postinstall commands.
4939d656433aSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4940d656433aSmrg    done
4941126a8a12Smrg
4942d656433aSmrg    test -n "$future_libdirs" && \
4943300346aeSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4944126a8a12Smrg
4945d656433aSmrg    if test -n "$current_libdirs"; then
4946d656433aSmrg      # Maybe just do a dry run.
4947d656433aSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4948300346aeSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4949d656433aSmrg    else
4950d656433aSmrg      exit $EXIT_SUCCESS
4951d656433aSmrg    fi
4952d656433aSmrg}
4953126a8a12Smrg
4954300346aeSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4955126a8a12Smrg
4956126a8a12Smrg
4957d656433aSmrg# func_generate_dlsyms outputname originator pic_p
4958d656433aSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4959d656433aSmrg# a dlpreopen symbol table.
4960d656433aSmrgfunc_generate_dlsyms ()
4961d656433aSmrg{
4962300346aeSmrg    $debug_cmd
4963300346aeSmrg
4964300346aeSmrg    my_outputname=$1
4965300346aeSmrg    my_originator=$2
4966300346aeSmrg    my_pic_p=${3-false}
4967300346aeSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4968d656433aSmrg    my_dlsyms=
4969d656433aSmrg
4970300346aeSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4971d656433aSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4972300346aeSmrg	my_dlsyms=${my_outputname}S.c
4973d656433aSmrg      else
4974d656433aSmrg	func_error "not configured to extract global symbols from dlpreopened files"
4975d656433aSmrg      fi
4976d656433aSmrg    fi
4977126a8a12Smrg
4978d656433aSmrg    if test -n "$my_dlsyms"; then
4979d656433aSmrg      case $my_dlsyms in
4980d656433aSmrg      "") ;;
4981d656433aSmrg      *.c)
4982d656433aSmrg	# Discover the nlist of each of the dlfiles.
4983300346aeSmrg	nlist=$output_objdir/$my_outputname.nm
4984d656433aSmrg
4985d656433aSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4986d656433aSmrg
4987d656433aSmrg	# Parse the name list into a source file.
4988d656433aSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
4989d656433aSmrg
4990d656433aSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4991300346aeSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4992300346aeSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4993d656433aSmrg
4994d656433aSmrg#ifdef __cplusplus
4995d656433aSmrgextern \"C\" {
4996d656433aSmrg#endif
4997d656433aSmrg
4998300346aeSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4999555991fdSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
5000555991fdSmrg#endif
5001555991fdSmrg
50023c15da26Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
5003300346aeSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
5004300346aeSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
50053c15da26Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
50063c15da26Smrg# define LT_DLSYM_CONST
5007300346aeSmrg#elif defined __osf__
50083c15da26Smrg/* This system does not cope well with relocations in const data.  */
50093c15da26Smrg# define LT_DLSYM_CONST
50103c15da26Smrg#else
50113c15da26Smrg# define LT_DLSYM_CONST const
50123c15da26Smrg#endif
50133c15da26Smrg
5014300346aeSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5015300346aeSmrg
5016d656433aSmrg/* External symbol declarations for the compiler. */\
5017d656433aSmrg"
5018d656433aSmrg
5019300346aeSmrg	if test yes = "$dlself"; then
5020300346aeSmrg	  func_verbose "generating symbol list for '$output'"
5021d656433aSmrg
5022d656433aSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
5023d656433aSmrg
5024d656433aSmrg	  # Add our own program objects to the symbol list.
5025555991fdSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
5026d656433aSmrg	  for progfile in $progfiles; do
50273c15da26Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
5028300346aeSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
50293c15da26Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
5030d656433aSmrg	  done
5031d656433aSmrg
5032d656433aSmrg	  if test -n "$exclude_expsyms"; then
5033d656433aSmrg	    $opt_dry_run || {
5034d656433aSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
5035d656433aSmrg	      eval '$MV "$nlist"T "$nlist"'
5036d656433aSmrg	    }
5037126a8a12Smrg	  fi
5038126a8a12Smrg
5039d656433aSmrg	  if test -n "$export_symbols_regex"; then
5040d656433aSmrg	    $opt_dry_run || {
5041d656433aSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
5042d656433aSmrg	      eval '$MV "$nlist"T "$nlist"'
5043d656433aSmrg	    }
5044126a8a12Smrg	  fi
5045d656433aSmrg
5046d656433aSmrg	  # Prepare the list of exported symbols
5047d656433aSmrg	  if test -z "$export_symbols"; then
5048300346aeSmrg	    export_symbols=$output_objdir/$outputname.exp
5049d656433aSmrg	    $opt_dry_run || {
5050d656433aSmrg	      $RM $export_symbols
5051300346aeSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
5052d656433aSmrg	      case $host in
50536bea0e4fSmrg	      *cygwin* | *mingw* | *windows* | *cegcc* )
5054d656433aSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5055d656433aSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
5056d656433aSmrg	        ;;
5057126a8a12Smrg	      esac
5058d656433aSmrg	    }
5059d656433aSmrg	  else
5060d656433aSmrg	    $opt_dry_run || {
5061300346aeSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
5062d656433aSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
5063d656433aSmrg	      eval '$MV "$nlist"T "$nlist"'
5064d656433aSmrg	      case $host in
50656bea0e4fSmrg	        *cygwin* | *mingw* | *windows* | *cegcc* )
5066d656433aSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5067d656433aSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
5068d656433aSmrg	          ;;
5069126a8a12Smrg	      esac
5070d656433aSmrg	    }
5071126a8a12Smrg	  fi
5072d656433aSmrg	fi
5073126a8a12Smrg
5074d656433aSmrg	for dlprefile in $dlprefiles; do
5075300346aeSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
5076d656433aSmrg	  func_basename "$dlprefile"
5077300346aeSmrg	  name=$func_basename_result
50783c15da26Smrg          case $host in
50796bea0e4fSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
50803c15da26Smrg	      # if an import library, we need to obtain dlname
50813c15da26Smrg	      if func_win32_import_lib_p "$dlprefile"; then
50823c15da26Smrg	        func_tr_sh "$dlprefile"
50833c15da26Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
5084300346aeSmrg	        dlprefile_dlbasename=
50853c15da26Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
50863c15da26Smrg	          # Use subshell, to avoid clobbering current variable values
50873c15da26Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
5088300346aeSmrg	          if test -n "$dlprefile_dlname"; then
50893c15da26Smrg	            func_basename "$dlprefile_dlname"
5090300346aeSmrg	            dlprefile_dlbasename=$func_basename_result
50913c15da26Smrg	          else
50923c15da26Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
50933c15da26Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
50943c15da26Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
50953c15da26Smrg	          fi
50963c15da26Smrg	        fi
50973c15da26Smrg	        $opt_dry_run || {
5098300346aeSmrg	          if test -n "$dlprefile_dlbasename"; then
50993c15da26Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
51003c15da26Smrg	          else
51013c15da26Smrg	            func_warning "Could not compute DLL name from $name"
51023c15da26Smrg	            eval '$ECHO ": $name " >> "$nlist"'
51033c15da26Smrg	          fi
51043c15da26Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51056bea0e4fSmrg	          case $host in
51066bea0e4fSmrg	            i[3456]86-*-mingw32*)
51076bea0e4fSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51086bea0e4fSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
51096bea0e4fSmrg	            ;;
51106bea0e4fSmrg	            *)
51116bea0e4fSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51126bea0e4fSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'"
51136bea0e4fSmrg	            ;;
51146bea0e4fSmrg	          esac
51153c15da26Smrg	        }
51163c15da26Smrg	      else # not an import lib
51173c15da26Smrg	        $opt_dry_run || {
51183c15da26Smrg	          eval '$ECHO ": $name " >> "$nlist"'
51193c15da26Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51203c15da26Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
51213c15da26Smrg	        }
51223c15da26Smrg	      fi
51233c15da26Smrg	    ;;
51243c15da26Smrg	    *)
51253c15da26Smrg	      $opt_dry_run || {
51263c15da26Smrg	        eval '$ECHO ": $name " >> "$nlist"'
51273c15da26Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51283c15da26Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
51293c15da26Smrg	      }
51303c15da26Smrg	    ;;
51313c15da26Smrg          esac
5132d656433aSmrg	done
5133126a8a12Smrg
5134d656433aSmrg	$opt_dry_run || {
5135d656433aSmrg	  # Make sure we have at least an empty file.
5136d656433aSmrg	  test -f "$nlist" || : > "$nlist"
5137126a8a12Smrg
5138d656433aSmrg	  if test -n "$exclude_expsyms"; then
5139d656433aSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
5140d656433aSmrg	    $MV "$nlist"T "$nlist"
5141126a8a12Smrg	  fi
5142126a8a12Smrg
5143d656433aSmrg	  # Try sorting and uniquifying the output.
5144d656433aSmrg	  if $GREP -v "^: " < "$nlist" |
5145d656433aSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
5146d656433aSmrg		sort -k 3
5147126a8a12Smrg	      else
5148d656433aSmrg		sort +2
5149d656433aSmrg	      fi |
5150d656433aSmrg	      uniq > "$nlist"S; then
5151d656433aSmrg	    :
5152126a8a12Smrg	  else
5153d656433aSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5154126a8a12Smrg	  fi
5155126a8a12Smrg
5156d656433aSmrg	  if test -f "$nlist"S; then
5157d656433aSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5158126a8a12Smrg	  else
5159555991fdSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5160126a8a12Smrg	  fi
5161126a8a12Smrg
5162300346aeSmrg	  func_show_eval '$RM "${nlist}I"'
5163300346aeSmrg	  if test -n "$global_symbol_to_import"; then
5164300346aeSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5165300346aeSmrg	  fi
5166300346aeSmrg
5167555991fdSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5168126a8a12Smrg
5169d656433aSmrg/* The mapping between symbol names and symbols.  */
5170d656433aSmrgtypedef struct {
5171d656433aSmrg  const char *name;
5172d656433aSmrg  void *address;
5173d656433aSmrg} lt_dlsymlist;
51743c15da26Smrgextern LT_DLSYM_CONST lt_dlsymlist
5175300346aeSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5176300346aeSmrg"
5177300346aeSmrg
5178300346aeSmrg	  if test -s "$nlist"I; then
5179300346aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5180300346aeSmrgstatic void lt_syminit(void)
5181300346aeSmrg{
5182300346aeSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5183300346aeSmrg  for (; symbol->name; ++symbol)
5184300346aeSmrg    {"
5185300346aeSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5186300346aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5187300346aeSmrg    }
5188300346aeSmrg}"
5189300346aeSmrg	  fi
5190300346aeSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
51913c15da26SmrgLT_DLSYM_CONST lt_dlsymlist
5192d656433aSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5193300346aeSmrg{ {\"$my_originator\", (void *) 0},"
5194300346aeSmrg
5195300346aeSmrg	  if test -s "$nlist"I; then
5196300346aeSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5197300346aeSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5198300346aeSmrg	  fi
5199d656433aSmrg
5200d656433aSmrg	  case $need_lib_prefix in
5201d656433aSmrg	  no)
5202d656433aSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5203d656433aSmrg	    ;;
5204d656433aSmrg	  *)
5205d656433aSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5206d656433aSmrg	    ;;
5207d656433aSmrg	  esac
5208555991fdSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5209d656433aSmrg  {0, (void *) 0}
5210d656433aSmrg};
5211d656433aSmrg
5212d656433aSmrg/* This works around a problem in FreeBSD linker */
5213d656433aSmrg#ifdef FREEBSD_WORKAROUND
5214d656433aSmrgstatic const void *lt_preloaded_setup() {
5215d656433aSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5216d656433aSmrg}
5217d656433aSmrg#endif
5218d656433aSmrg
5219d656433aSmrg#ifdef __cplusplus
5220d656433aSmrg}
5221d656433aSmrg#endif\
5222d656433aSmrg"
5223d656433aSmrg	} # !$opt_dry_run
5224d656433aSmrg
5225d656433aSmrg	pic_flag_for_symtable=
5226d656433aSmrg	case "$compile_command " in
5227d656433aSmrg	*" -static "*) ;;
5228d656433aSmrg	*)
5229d656433aSmrg	  case $host in
5230d656433aSmrg	  # compiling the symbol table file with pic_flag works around
5231d656433aSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
5232d656433aSmrg	  # linked before any other PIC object.  But we must not use
5233d656433aSmrg	  # pic_flag when linking with -static.  The problem exists in
5234d656433aSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
52350a6b08f8Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5236d656433aSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5237d656433aSmrg	  *-*-hpux*)
5238d656433aSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5239d656433aSmrg	  *)
5240300346aeSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5241d656433aSmrg	    ;;
5242d656433aSmrg	  esac
5243d656433aSmrg	  ;;
5244d656433aSmrg	esac
5245d656433aSmrg	symtab_cflags=
5246d656433aSmrg	for arg in $LTCFLAGS; do
5247d656433aSmrg	  case $arg in
5248d656433aSmrg	  -pie | -fpie | -fPIE) ;;
52493c15da26Smrg	  *) func_append symtab_cflags " $arg" ;;
5250d656433aSmrg	  esac
5251d656433aSmrg	done
5252126a8a12Smrg
5253d656433aSmrg	# Now compile the dynamic symbol file.
5254d656433aSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5255126a8a12Smrg
5256d656433aSmrg	# Clean up the generated files.
5257300346aeSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5258d656433aSmrg
5259d656433aSmrg	# Transform the symbol file into the correct name.
5260300346aeSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5261d656433aSmrg	case $host in
52626bea0e4fSmrg	*cygwin* | *mingw* | *windows* | *cegcc* )
5263d656433aSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
5264555991fdSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5265555991fdSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5266d656433aSmrg	  else
5267555991fdSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5268555991fdSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5269d656433aSmrg	  fi
5270d656433aSmrg	  ;;
5271d656433aSmrg	*)
5272555991fdSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5273555991fdSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5274126a8a12Smrg	  ;;
5275126a8a12Smrg	esac
5276d656433aSmrg	;;
5277d656433aSmrg      *)
5278300346aeSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5279d656433aSmrg	;;
5280d656433aSmrg      esac
5281d656433aSmrg    else
5282d656433aSmrg      # We keep going just in case the user didn't refer to
5283d656433aSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5284d656433aSmrg      # really was required.
5285d656433aSmrg
5286d656433aSmrg      # Nullify the symbol file.
5287555991fdSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5288555991fdSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5289126a8a12Smrg    fi
5290d656433aSmrg}
5291126a8a12Smrg
5292300346aeSmrg# func_cygming_gnu_implib_p ARG
5293300346aeSmrg# This predicate returns with zero status (TRUE) if
5294300346aeSmrg# ARG is a GNU/binutils-style import library. Returns
5295300346aeSmrg# with nonzero status (FALSE) otherwise.
5296300346aeSmrgfunc_cygming_gnu_implib_p ()
5297300346aeSmrg{
5298300346aeSmrg  $debug_cmd
5299300346aeSmrg
5300300346aeSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5301300346aeSmrg  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)$'`
5302300346aeSmrg  test -n "$func_cygming_gnu_implib_tmp"
5303300346aeSmrg}
5304300346aeSmrg
5305300346aeSmrg# func_cygming_ms_implib_p ARG
5306300346aeSmrg# This predicate returns with zero status (TRUE) if
5307300346aeSmrg# ARG is an MS-style import library. Returns
5308300346aeSmrg# with nonzero status (FALSE) otherwise.
5309300346aeSmrgfunc_cygming_ms_implib_p ()
5310300346aeSmrg{
5311300346aeSmrg  $debug_cmd
5312300346aeSmrg
5313300346aeSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5314300346aeSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5315300346aeSmrg  test -n "$func_cygming_ms_implib_tmp"
5316300346aeSmrg}
5317300346aeSmrg
5318d656433aSmrg# func_win32_libid arg
5319d656433aSmrg# return the library type of file 'arg'
5320d656433aSmrg#
5321d656433aSmrg# Need a lot of goo to handle *both* DLLs and import libs
5322d656433aSmrg# Has to be a shell function in order to 'eat' the argument
5323d656433aSmrg# that is supplied when $file_magic_command is called.
5324555991fdSmrg# Despite the name, also deal with 64 bit binaries.
5325d656433aSmrgfunc_win32_libid ()
5326d656433aSmrg{
5327300346aeSmrg  $debug_cmd
5328300346aeSmrg
5329300346aeSmrg  win32_libid_type=unknown
5330d656433aSmrg  win32_fileres=`file -L $1 2>/dev/null`
5331d656433aSmrg  case $win32_fileres in
5332d656433aSmrg  *ar\ archive\ import\ library*) # definitely import
5333d656433aSmrg    win32_libid_type="x86 archive import"
5334d656433aSmrg    ;;
5335d656433aSmrg  *ar\ archive*) # could be an import, or static
5336555991fdSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5337d656433aSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
53386bea0e4fSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then
5339300346aeSmrg      case $nm_interface in
5340300346aeSmrg      "MS dumpbin")
5341300346aeSmrg	if func_cygming_ms_implib_p "$1" ||
5342300346aeSmrg	   func_cygming_gnu_implib_p "$1"
5343300346aeSmrg	then
5344300346aeSmrg	  win32_nmres=import
5345300346aeSmrg	else
5346300346aeSmrg	  win32_nmres=
5347300346aeSmrg	fi
5348300346aeSmrg	;;
5349300346aeSmrg      *)
5350300346aeSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5351300346aeSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5352300346aeSmrg	  $SED -n -e '
5353d656433aSmrg	    1,100{
5354d656433aSmrg		/ I /{
5355300346aeSmrg		    s|.*|import|
5356d656433aSmrg		    p
5357d656433aSmrg		    q
5358d656433aSmrg		}
5359d656433aSmrg	    }'`
5360300346aeSmrg	;;
5361300346aeSmrg      esac
5362d656433aSmrg      case $win32_nmres in
5363d656433aSmrg      import*)  win32_libid_type="x86 archive import";;
5364d656433aSmrg      *)        win32_libid_type="x86 archive static";;
5365d656433aSmrg      esac
5366d656433aSmrg    fi
5367d656433aSmrg    ;;
5368d656433aSmrg  *DLL*)
5369d656433aSmrg    win32_libid_type="x86 DLL"
5370d656433aSmrg    ;;
5371d656433aSmrg  *executable*) # but shell scripts are "executable" too...
5372d656433aSmrg    case $win32_fileres in
5373d656433aSmrg    *MS\ Windows\ PE\ Intel*)
5374d656433aSmrg      win32_libid_type="x86 DLL"
5375d656433aSmrg      ;;
5376d656433aSmrg    esac
5377d656433aSmrg    ;;
5378d656433aSmrg  esac
5379d656433aSmrg  $ECHO "$win32_libid_type"
5380d656433aSmrg}
5381126a8a12Smrg
53823c15da26Smrg# func_cygming_dll_for_implib ARG
53833c15da26Smrg#
53843c15da26Smrg# Platform-specific function to extract the
53853c15da26Smrg# name of the DLL associated with the specified
53863c15da26Smrg# import library ARG.
53873c15da26Smrg# Invoked by eval'ing the libtool variable
53883c15da26Smrg#    $sharedlib_from_linklib_cmd
53893c15da26Smrg# Result is available in the variable
53903c15da26Smrg#    $sharedlib_from_linklib_result
53913c15da26Smrgfunc_cygming_dll_for_implib ()
53923c15da26Smrg{
5393300346aeSmrg  $debug_cmd
5394300346aeSmrg
53953c15da26Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
53963c15da26Smrg}
53973c15da26Smrg
53983c15da26Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
53993c15da26Smrg#
54003c15da26Smrg# The is the core of a fallback implementation of a
54013c15da26Smrg# platform-specific function to extract the name of the
54023c15da26Smrg# DLL associated with the specified import library LIBNAME.
54033c15da26Smrg#
54043c15da26Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
54053c15da26Smrg# on the platform and compiler that created the implib.
54063c15da26Smrg#
54073c15da26Smrg# Echos the name of the DLL associated with the
54083c15da26Smrg# specified import library.
54093c15da26Smrgfunc_cygming_dll_for_implib_fallback_core ()
54103c15da26Smrg{
5411300346aeSmrg  $debug_cmd
5412300346aeSmrg
54133c15da26Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
54143c15da26Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
54153c15da26Smrg    $SED '/^Contents of section '"$match_literal"':/{
54163c15da26Smrg      # Place marker at beginning of archive member dllname section
54173c15da26Smrg      s/.*/====MARK====/
54183c15da26Smrg      p
54193c15da26Smrg      d
54203c15da26Smrg    }
54213c15da26Smrg    # These lines can sometimes be longer than 43 characters, but
54223c15da26Smrg    # are always uninteresting
54233c15da26Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
54243c15da26Smrg    /^In archive [^:]*:/d
54253c15da26Smrg    # Ensure marker is printed
54263c15da26Smrg    /^====MARK====/p
54273c15da26Smrg    # Remove all lines with less than 43 characters
54283c15da26Smrg    /^.\{43\}/!d
54293c15da26Smrg    # From remaining lines, remove first 43 characters
54303c15da26Smrg    s/^.\{43\}//' |
54313c15da26Smrg    $SED -n '
54323c15da26Smrg      # Join marker and all lines until next marker into a single line
54333c15da26Smrg      /^====MARK====/ b para
54343c15da26Smrg      H
54353c15da26Smrg      $ b para
54363c15da26Smrg      b
54373c15da26Smrg      :para
54383c15da26Smrg      x
54393c15da26Smrg      s/\n//g
54403c15da26Smrg      # Remove the marker
54413c15da26Smrg      s/^====MARK====//
54423c15da26Smrg      # Remove trailing dots and whitespace
54433c15da26Smrg      s/[\. \t]*$//
54443c15da26Smrg      # Print
54453c15da26Smrg      /./p' |
54463c15da26Smrg    # we now have a list, one entry per line, of the stringified
54473c15da26Smrg    # contents of the appropriate section of all members of the
5448300346aeSmrg    # archive that possess that section. Heuristic: eliminate
5449300346aeSmrg    # all those that have a first or second character that is
54503c15da26Smrg    # a '.' (that is, objdump's representation of an unprintable
54513c15da26Smrg    # character.) This should work for all archives with less than
54523c15da26Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
54533c15da26Smrg    # begins with a literal '.' or a single character followed by
54543c15da26Smrg    # a '.'.
54553c15da26Smrg    #
54563c15da26Smrg    # Of those that remain, print the first one.
54573c15da26Smrg    $SED -e '/^\./d;/^.\./d;q'
54583c15da26Smrg}
54593c15da26Smrg
54603c15da26Smrg# func_cygming_dll_for_implib_fallback ARG
54613c15da26Smrg# Platform-specific function to extract the
54623c15da26Smrg# name of the DLL associated with the specified
54633c15da26Smrg# import library ARG.
54643c15da26Smrg#
54653c15da26Smrg# This fallback implementation is for use when $DLLTOOL
54663c15da26Smrg# does not support the --identify-strict option.
54673c15da26Smrg# Invoked by eval'ing the libtool variable
54683c15da26Smrg#    $sharedlib_from_linklib_cmd
54693c15da26Smrg# Result is available in the variable
54703c15da26Smrg#    $sharedlib_from_linklib_result
54713c15da26Smrgfunc_cygming_dll_for_implib_fallback ()
54723c15da26Smrg{
5473300346aeSmrg  $debug_cmd
5474300346aeSmrg
5475300346aeSmrg  if func_cygming_gnu_implib_p "$1"; then
54763c15da26Smrg    # binutils import library
54773c15da26Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5478300346aeSmrg  elif func_cygming_ms_implib_p "$1"; then
54793c15da26Smrg    # ms-generated import library
54803c15da26Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
54813c15da26Smrg  else
54823c15da26Smrg    # unknown
5483300346aeSmrg    sharedlib_from_linklib_result=
54843c15da26Smrg  fi
54853c15da26Smrg}
5486126a8a12Smrg
5487126a8a12Smrg
5488d656433aSmrg# func_extract_an_archive dir oldlib
5489d656433aSmrgfunc_extract_an_archive ()
5490d656433aSmrg{
5491300346aeSmrg    $debug_cmd
5492300346aeSmrg
5493300346aeSmrg    f_ex_an_ar_dir=$1; shift
5494300346aeSmrg    f_ex_an_ar_oldlib=$1
5495300346aeSmrg    if test yes = "$lock_old_archive_extraction"; then
5496555991fdSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5497555991fdSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5498555991fdSmrg	func_echo "Waiting for $lockfile to be removed"
5499555991fdSmrg	sleep 2
5500555991fdSmrg      done
5501555991fdSmrg    fi
5502555991fdSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5503555991fdSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5504300346aeSmrg    if test yes = "$lock_old_archive_extraction"; then
5505555991fdSmrg      $opt_dry_run || rm -f "$lockfile"
5506555991fdSmrg    fi
5507d656433aSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5508d656433aSmrg     :
5509d656433aSmrg    else
5510d656433aSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5511d656433aSmrg    fi
5512d656433aSmrg}
5513126a8a12Smrg
5514126a8a12Smrg
5515d656433aSmrg# func_extract_archives gentop oldlib ...
5516d656433aSmrgfunc_extract_archives ()
5517d656433aSmrg{
5518300346aeSmrg    $debug_cmd
5519300346aeSmrg
5520300346aeSmrg    my_gentop=$1; shift
5521d656433aSmrg    my_oldlibs=${1+"$@"}
5522300346aeSmrg    my_oldobjs=
5523300346aeSmrg    my_xlib=
5524300346aeSmrg    my_xabs=
5525300346aeSmrg    my_xdir=
5526126a8a12Smrg
5527d656433aSmrg    for my_xlib in $my_oldlibs; do
5528d656433aSmrg      # Extract the objects.
5529d656433aSmrg      case $my_xlib in
5530300346aeSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5531d656433aSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5532d656433aSmrg      esac
5533d656433aSmrg      func_basename "$my_xlib"
5534300346aeSmrg      my_xlib=$func_basename_result
5535d656433aSmrg      my_xlib_u=$my_xlib
5536d656433aSmrg      while :; do
5537d656433aSmrg        case " $extracted_archives " in
5538d656433aSmrg	*" $my_xlib_u "*)
5539d656433aSmrg	  func_arith $extracted_serial + 1
5540d656433aSmrg	  extracted_serial=$func_arith_result
5541d656433aSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5542d656433aSmrg	*) break ;;
5543d656433aSmrg	esac
5544d656433aSmrg      done
5545d656433aSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5546300346aeSmrg      my_xdir=$my_gentop/$my_xlib_u
5547126a8a12Smrg
5548d656433aSmrg      func_mkdir_p "$my_xdir"
5549126a8a12Smrg
5550d656433aSmrg      case $host in
5551d656433aSmrg      *-darwin*)
5552d656433aSmrg	func_verbose "Extracting $my_xabs"
5553d656433aSmrg	# Do not bother doing anything if just a dry run
5554d656433aSmrg	$opt_dry_run || {
5555d656433aSmrg	  darwin_orig_dir=`pwd`
5556d656433aSmrg	  cd $my_xdir || exit $?
5557d656433aSmrg	  darwin_archive=$my_xabs
5558d656433aSmrg	  darwin_curdir=`pwd`
5559300346aeSmrg	  func_basename "$darwin_archive"
5560300346aeSmrg	  darwin_base_archive=$func_basename_result
5561d656433aSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5562d656433aSmrg	  if test -n "$darwin_arches"; then
5563d656433aSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5564d656433aSmrg	    darwin_arch=
5565d656433aSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5566300346aeSmrg	    for darwin_arch in  $darwin_arches; do
5567300346aeSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5568300346aeSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5569300346aeSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5570300346aeSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5571d656433aSmrg	      cd "$darwin_curdir"
5572300346aeSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5573d656433aSmrg	    done # $darwin_arches
5574d656433aSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5575300346aeSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5576d656433aSmrg	    darwin_file=
5577d656433aSmrg	    darwin_files=
5578d656433aSmrg	    for darwin_file in $darwin_filelist; do
5579555991fdSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5580d656433aSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
5581d656433aSmrg	    done # $darwin_filelist
5582d656433aSmrg	    $RM -rf unfat-$$
5583d656433aSmrg	    cd "$darwin_orig_dir"
5584d656433aSmrg	  else
5585d656433aSmrg	    cd $darwin_orig_dir
5586d656433aSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5587d656433aSmrg	  fi # $darwin_arches
5588d656433aSmrg	} # !$opt_dry_run
5589d656433aSmrg	;;
5590d656433aSmrg      *)
5591d656433aSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5592d656433aSmrg	;;
5593126a8a12Smrg      esac
5594555991fdSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5595d656433aSmrg    done
5596126a8a12Smrg
5597300346aeSmrg    func_extract_archives_result=$my_oldobjs
5598d656433aSmrg}
5599126a8a12Smrg
5600126a8a12Smrg
5601555991fdSmrg# func_emit_wrapper [arg=no]
5602d656433aSmrg#
5603555991fdSmrg# Emit a libtool wrapper script on stdout.
5604555991fdSmrg# Don't directly open a file because we may want to
56056bea0e4fSmrg# incorporate the script contents within a cygwin/mingw/windows
5606555991fdSmrg# wrapper executable.  Must ONLY be called from within
5607555991fdSmrg# func_mode_link because it depends on a number of variables
5608555991fdSmrg# set therein.
5609555991fdSmrg#
5610555991fdSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5611555991fdSmrg# variable will take.  If 'yes', then the emitted script
5612300346aeSmrg# will assume that the directory where it is stored is
56136bea0e4fSmrg# the $objdir directory.  This is a cygwin/mingw/windows-specific
5614555991fdSmrg# behavior.
5615555991fdSmrgfunc_emit_wrapper ()
5616d656433aSmrg{
5617555991fdSmrg	func_emit_wrapper_arg1=${1-no}
5618126a8a12Smrg
5619d656433aSmrg	$ECHO "\
5620d656433aSmrg#! $SHELL
5621126a8a12Smrg
5622d656433aSmrg# $output - temporary wrapper script for $objdir/$outputname
5623300346aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5624d656433aSmrg#
5625d656433aSmrg# The $output program cannot be directly executed until all the libtool
5626d656433aSmrg# libraries that it depends on are installed.
5627d656433aSmrg#
5628d656433aSmrg# This wrapper script should never be moved out of the build directory.
5629d656433aSmrg# If it is, it will not operate correctly.
5630126a8a12Smrg
5631d656433aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
5632d656433aSmrg# metacharacters that are still active within double-quoted strings.
5633d656433aSmrgsed_quote_subst='$sed_quote_subst'
5634126a8a12Smrg
5635d656433aSmrg# Be Bourne compatible
5636d656433aSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5637d656433aSmrg  emulate sh
5638d656433aSmrg  NULLCMD=:
5639d656433aSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5640d656433aSmrg  # is contrary to our usage.  Disable this feature.
5641d656433aSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5642d656433aSmrg  setopt NO_GLOB_SUBST
5643d656433aSmrgelse
5644d656433aSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5645d656433aSmrgfi
5646d656433aSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5647d656433aSmrgDUALCASE=1; export DUALCASE # for MKS sh
5648126a8a12Smrg
5649d656433aSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5650d656433aSmrg# if CDPATH is set.
5651d656433aSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5652126a8a12Smrg
5653d656433aSmrgrelink_command=\"$relink_command\"
5654126a8a12Smrg
5655d656433aSmrg# This environment variable determines our operation mode.
5656d656433aSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5657d656433aSmrg  # install mode needs the following variables:
5658d656433aSmrg  generated_by_libtool_version='$macro_version'
5659d656433aSmrg  notinst_deplibs='$notinst_deplibs'
5660d656433aSmrgelse
5661d656433aSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5662d656433aSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5663555991fdSmrg    file=\"\$0\""
5664555991fdSmrg
56653fb97780Smrg    func_quote_arg pretty "$ECHO"
56663fb97780Smrg    qECHO=$func_quote_arg_result
5667555991fdSmrg    $ECHO "\
5668555991fdSmrg
5669555991fdSmrg# A function that is used when there is no print builtin or printf.
5670555991fdSmrgfunc_fallback_echo ()
5671555991fdSmrg{
5672555991fdSmrg  eval 'cat <<_LTECHO_EOF
5673555991fdSmrg\$1
5674555991fdSmrg_LTECHO_EOF'
5675555991fdSmrg}
56763fb97780Smrg    ECHO=$qECHO
5677555991fdSmrg  fi
5678555991fdSmrg
5679555991fdSmrg# Very basic option parsing. These options are (a) specific to
5680555991fdSmrg# the libtool wrapper, (b) are identical between the wrapper
5681300346aeSmrg# /script/ and the wrapper /executable/ that is used only on
5682555991fdSmrg# windows platforms, and (c) all begin with the string "--lt-"
5683300346aeSmrg# (application programs are unlikely to have options that match
5684555991fdSmrg# this pattern).
5685555991fdSmrg#
5686555991fdSmrg# There are only two supported options: --lt-debug and
5687555991fdSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5688555991fdSmrg#
5689555991fdSmrg# The first argument to this parsing function should be the
5690555991fdSmrg# script's $0 value, followed by "$@".
5691555991fdSmrglt_option_debug=
5692555991fdSmrgfunc_parse_lt_options ()
5693555991fdSmrg{
5694555991fdSmrg  lt_script_arg0=\$0
5695555991fdSmrg  shift
5696555991fdSmrg  for lt_opt
5697555991fdSmrg  do
5698555991fdSmrg    case \"\$lt_opt\" in
5699555991fdSmrg    --lt-debug) lt_option_debug=1 ;;
5700555991fdSmrg    --lt-dump-script)
5701555991fdSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5702555991fdSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5703555991fdSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5704555991fdSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5705555991fdSmrg        exit 0
5706555991fdSmrg      ;;
5707555991fdSmrg    --lt-*)
5708555991fdSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5709555991fdSmrg        exit 1
5710555991fdSmrg      ;;
5711555991fdSmrg    esac
5712555991fdSmrg  done
5713555991fdSmrg
5714555991fdSmrg  # Print the debug banner immediately:
5715555991fdSmrg  if test -n \"\$lt_option_debug\"; then
5716300346aeSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5717555991fdSmrg  fi
5718555991fdSmrg}
5719555991fdSmrg
5720555991fdSmrg# Used when --lt-debug. Prints its arguments to stdout
5721555991fdSmrg# (redirection is the responsibility of the caller)
5722555991fdSmrgfunc_lt_dump_args ()
5723555991fdSmrg{
5724555991fdSmrg  lt_dump_args_N=1;
5725555991fdSmrg  for lt_arg
5726555991fdSmrg  do
5727300346aeSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5728555991fdSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5729555991fdSmrg  done
5730555991fdSmrg}
5731555991fdSmrg
5732555991fdSmrg# Core function for launching the target application
5733555991fdSmrgfunc_exec_program_core ()
5734555991fdSmrg{
5735d656433aSmrg"
5736555991fdSmrg  case $host in
5737555991fdSmrg  # Backslashes separate directories on plain windows
57386bea0e4fSmrg  *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*)
5739555991fdSmrg    $ECHO "\
5740555991fdSmrg      if test -n \"\$lt_option_debug\"; then
5741300346aeSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5742555991fdSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5743555991fdSmrg      fi
5744555991fdSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5745555991fdSmrg"
5746555991fdSmrg    ;;
5747555991fdSmrg
5748555991fdSmrg  *)
5749555991fdSmrg    $ECHO "\
5750555991fdSmrg      if test -n \"\$lt_option_debug\"; then
5751300346aeSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5752555991fdSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5753555991fdSmrg      fi
5754555991fdSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5755555991fdSmrg"
5756555991fdSmrg    ;;
5757555991fdSmrg  esac
5758555991fdSmrg  $ECHO "\
5759555991fdSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5760555991fdSmrg      exit 1
5761555991fdSmrg}
5762555991fdSmrg
5763555991fdSmrg# A function to encapsulate launching the target application
5764555991fdSmrg# Strips options in the --lt-* namespace from \$@ and
5765555991fdSmrg# launches target application with the remaining arguments.
5766555991fdSmrgfunc_exec_program ()
5767555991fdSmrg{
57680a6b08f8Smrg  case \" \$* \" in
57690a6b08f8Smrg  *\\ --lt-*)
57700a6b08f8Smrg    for lt_wr_arg
57710a6b08f8Smrg    do
57720a6b08f8Smrg      case \$lt_wr_arg in
57730a6b08f8Smrg      --lt-*) ;;
57740a6b08f8Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
57750a6b08f8Smrg      esac
57760a6b08f8Smrg      shift
57770a6b08f8Smrg    done ;;
57780a6b08f8Smrg  esac
5779555991fdSmrg  func_exec_program_core \${1+\"\$@\"}
5780555991fdSmrg}
5781555991fdSmrg
5782555991fdSmrg  # Parse options
5783555991fdSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5784126a8a12Smrg
5785d656433aSmrg  # Find the directory that this script lives in.
5786555991fdSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5787d656433aSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5788126a8a12Smrg
5789d656433aSmrg  # Follow symbolic links until we get to the real thisdir.
5790555991fdSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5791d656433aSmrg  while test -n \"\$file\"; do
5792555991fdSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5793126a8a12Smrg
5794d656433aSmrg    # If there was a directory component, then change thisdir.
5795d656433aSmrg    if test \"x\$destdir\" != \"x\$file\"; then
5796d656433aSmrg      case \"\$destdir\" in
5797d656433aSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5798d656433aSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5799d656433aSmrg      esac
5800d656433aSmrg    fi
5801126a8a12Smrg
5802555991fdSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5803555991fdSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5804d656433aSmrg  done
5805126a8a12Smrg
58066bea0e4fSmrg  # Usually 'no', except on cygwin/mingw/windows when embedded into
5807d656433aSmrg  # the cwrapper.
5808555991fdSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5809d656433aSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5810d656433aSmrg    # special case for '.'
5811d656433aSmrg    if test \"\$thisdir\" = \".\"; then
5812d656433aSmrg      thisdir=\`pwd\`
5813d656433aSmrg    fi
5814d656433aSmrg    # remove .libs from thisdir
5815d656433aSmrg    case \"\$thisdir\" in
5816555991fdSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5817d656433aSmrg    $objdir )   thisdir=. ;;
5818d656433aSmrg    esac
5819d656433aSmrg  fi
5820126a8a12Smrg
5821d656433aSmrg  # Try to get the absolute directory name.
5822d656433aSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
5823d656433aSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5824d656433aSmrg"
5825126a8a12Smrg
5826300346aeSmrg	if test yes = "$fast_install"; then
5827d656433aSmrg	  $ECHO "\
5828d656433aSmrg  program=lt-'$outputname'$exeext
5829d656433aSmrg  progdir=\"\$thisdir/$objdir\"
5830126a8a12Smrg
5831d656433aSmrg  if test ! -f \"\$progdir/\$program\" ||
5832300346aeSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5833d656433aSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5834126a8a12Smrg
5835d656433aSmrg    file=\"\$\$-\$program\"
5836126a8a12Smrg
5837d656433aSmrg    if test ! -d \"\$progdir\"; then
5838d656433aSmrg      $MKDIR \"\$progdir\"
5839d656433aSmrg    else
5840d656433aSmrg      $RM \"\$progdir/\$file\"
5841d656433aSmrg    fi"
5842126a8a12Smrg
5843d656433aSmrg	  $ECHO "\
5844126a8a12Smrg
5845d656433aSmrg    # relink executable if necessary
5846d656433aSmrg    if test -n \"\$relink_command\"; then
5847d656433aSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5848d656433aSmrg      else
5849300346aeSmrg	\$ECHO \"\$relink_command_output\" >&2
5850d656433aSmrg	$RM \"\$progdir/\$file\"
5851d656433aSmrg	exit 1
5852d656433aSmrg      fi
5853d656433aSmrg    fi
5854126a8a12Smrg
5855d656433aSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5856d656433aSmrg    { $RM \"\$progdir/\$program\";
5857d656433aSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5858d656433aSmrg    $RM \"\$progdir/\$file\"
5859d656433aSmrg  fi"
5860d656433aSmrg	else
5861d656433aSmrg	  $ECHO "\
5862d656433aSmrg  program='$outputname'
5863d656433aSmrg  progdir=\"\$thisdir/$objdir\"
5864d656433aSmrg"
5865d656433aSmrg	fi
5866126a8a12Smrg
5867d656433aSmrg	$ECHO "\
5868126a8a12Smrg
5869d656433aSmrg  if test -f \"\$progdir/\$program\"; then"
5870126a8a12Smrg
58713c15da26Smrg	# fixup the dll searchpath if we need to.
58723c15da26Smrg	#
58733c15da26Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
58743c15da26Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
58753c15da26Smrg	# libraries must come first.
58763c15da26Smrg	if test -n "$dllsearchpath"; then
58773c15da26Smrg	  $ECHO "\
58783c15da26Smrg    # Add the dll search path components to the executable PATH
58793c15da26Smrg    PATH=$dllsearchpath:\$PATH
58803c15da26Smrg"
58813c15da26Smrg	fi
58823c15da26Smrg
5883d656433aSmrg	# Export our shlibpath_var if we have one.
5884300346aeSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5885d656433aSmrg	  $ECHO "\
5886d656433aSmrg    # Add our own library path to $shlibpath_var
5887d656433aSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5888126a8a12Smrg
5889d656433aSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5890d656433aSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
5891555991fdSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5892126a8a12Smrg
5893d656433aSmrg    export $shlibpath_var
5894d656433aSmrg"
5895126a8a12Smrg	fi
5896126a8a12Smrg
5897d656433aSmrg	$ECHO "\
5898d656433aSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5899d656433aSmrg      # Run the actual program with our arguments.
5900555991fdSmrg      func_exec_program \${1+\"\$@\"}
5901d656433aSmrg    fi
5902d656433aSmrg  else
5903d656433aSmrg    # The program doesn't exist.
5904300346aeSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5905d656433aSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5906555991fdSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5907d656433aSmrg    exit 1
5908d656433aSmrg  fi
5909d656433aSmrgfi\
5910d656433aSmrg"
5911d656433aSmrg}
5912126a8a12Smrg
5913126a8a12Smrg
5914d656433aSmrg# func_emit_cwrapperexe_src
5915d656433aSmrg# emit the source code for a wrapper executable on stdout
5916d656433aSmrg# Must ONLY be called from within func_mode_link because
5917d656433aSmrg# it depends on a number of variable set therein.
5918d656433aSmrgfunc_emit_cwrapperexe_src ()
5919d656433aSmrg{
5920d656433aSmrg	cat <<EOF
5921126a8a12Smrg
5922d656433aSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5923300346aeSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5924126a8a12Smrg
5925d656433aSmrg   The $output program cannot be directly executed until all the libtool
5926d656433aSmrg   libraries that it depends on are installed.
5927126a8a12Smrg
5928d656433aSmrg   This wrapper executable should never be moved out of the build directory.
5929d656433aSmrg   If it is, it will not operate correctly.
5930d656433aSmrg*/
5931d656433aSmrgEOF
5932d656433aSmrg	    cat <<"EOF"
5933555991fdSmrg#ifdef _MSC_VER
5934555991fdSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5935555991fdSmrg#endif
5936d656433aSmrg#include <stdio.h>
5937d656433aSmrg#include <stdlib.h>
59386bea0e4fSmrg#if defined _WIN32 && !defined __GNUC__
5939d656433aSmrg# include <direct.h>
5940d656433aSmrg# include <process.h>
5941d656433aSmrg# include <io.h>
5942d656433aSmrg#else
5943d656433aSmrg# include <unistd.h>
5944d656433aSmrg# include <stdint.h>
5945d656433aSmrg# ifdef __CYGWIN__
5946d656433aSmrg#  include <io.h>
5947d656433aSmrg# endif
5948d656433aSmrg#endif
5949d656433aSmrg#include <malloc.h>
5950d656433aSmrg#include <stdarg.h>
5951d656433aSmrg#include <assert.h>
5952d656433aSmrg#include <string.h>
5953d656433aSmrg#include <ctype.h>
5954d656433aSmrg#include <errno.h>
5955d656433aSmrg#include <fcntl.h>
5956d656433aSmrg#include <sys/stat.h>
5957d656433aSmrg
5958300346aeSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5959300346aeSmrg
5960555991fdSmrg/* declarations of non-ANSI functions */
5961300346aeSmrg#if defined __MINGW32__
5962555991fdSmrg# ifdef __STRICT_ANSI__
59636bea0e4fSmrg_CRTIMP int __cdecl _putenv (const char *);
5964555991fdSmrg# endif
5965300346aeSmrg#elif defined __CYGWIN__
5966555991fdSmrg# ifdef __STRICT_ANSI__
5967555991fdSmrgchar *realpath (const char *, char *);
5968555991fdSmrgint putenv (char *);
5969555991fdSmrgint setenv (const char *, const char *, int);
5970555991fdSmrg# endif
5971300346aeSmrg/* #elif defined other_platform || defined ... */
5972555991fdSmrg#endif
5973555991fdSmrg
5974555991fdSmrg/* portability defines, excluding path handling macros */
5975300346aeSmrg#if defined _MSC_VER
5976555991fdSmrg# define setmode _setmode
5977555991fdSmrg# define stat    _stat
5978555991fdSmrg# define chmod   _chmod
5979555991fdSmrg# define getcwd  _getcwd
5980555991fdSmrg# define putenv  _putenv
5981555991fdSmrg# define S_IXUSR _S_IEXEC
5982300346aeSmrg#elif defined __MINGW32__
5983555991fdSmrg# define setmode _setmode
5984555991fdSmrg# define stat    _stat
5985555991fdSmrg# define chmod   _chmod
5986555991fdSmrg# define getcwd  _getcwd
5987555991fdSmrg# define putenv  _putenv
5988300346aeSmrg#elif defined __CYGWIN__
5989555991fdSmrg# define HAVE_SETENV
5990555991fdSmrg# define FOPEN_WB "wb"
5991300346aeSmrg/* #elif defined other platforms ... */
5992555991fdSmrg#endif
5993555991fdSmrg
5994300346aeSmrg#if defined PATH_MAX
5995d656433aSmrg# define LT_PATHMAX PATH_MAX
5996300346aeSmrg#elif defined MAXPATHLEN
5997d656433aSmrg# define LT_PATHMAX MAXPATHLEN
5998d656433aSmrg#else
5999d656433aSmrg# define LT_PATHMAX 1024
6000d656433aSmrg#endif
6001d656433aSmrg
6002d656433aSmrg#ifndef S_IXOTH
6003d656433aSmrg# define S_IXOTH 0
6004d656433aSmrg#endif
6005d656433aSmrg#ifndef S_IXGRP
6006d656433aSmrg# define S_IXGRP 0
6007d656433aSmrg#endif
6008d656433aSmrg
6009555991fdSmrg/* path handling portability macros */
6010d656433aSmrg#ifndef DIR_SEPARATOR
6011d656433aSmrg# define DIR_SEPARATOR '/'
6012d656433aSmrg# define PATH_SEPARATOR ':'
6013d656433aSmrg#endif
6014d656433aSmrg
6015300346aeSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
6016300346aeSmrg  defined __OS2__
6017d656433aSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
6018d656433aSmrg# define FOPEN_WB "wb"
6019d656433aSmrg# ifndef DIR_SEPARATOR_2
6020d656433aSmrg#  define DIR_SEPARATOR_2 '\\'
6021d656433aSmrg# endif
6022d656433aSmrg# ifndef PATH_SEPARATOR_2
6023d656433aSmrg#  define PATH_SEPARATOR_2 ';'
6024d656433aSmrg# endif
6025d656433aSmrg#endif
6026d656433aSmrg
6027d656433aSmrg#ifndef DIR_SEPARATOR_2
6028d656433aSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
6029d656433aSmrg#else /* DIR_SEPARATOR_2 */
6030d656433aSmrg# define IS_DIR_SEPARATOR(ch) \
6031d656433aSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
6032d656433aSmrg#endif /* DIR_SEPARATOR_2 */
6033d656433aSmrg
6034d656433aSmrg#ifndef PATH_SEPARATOR_2
6035d656433aSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
6036d656433aSmrg#else /* PATH_SEPARATOR_2 */
6037d656433aSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
6038d656433aSmrg#endif /* PATH_SEPARATOR_2 */
6039d656433aSmrg
6040d656433aSmrg#ifndef FOPEN_WB
6041d656433aSmrg# define FOPEN_WB "w"
6042d656433aSmrg#endif
6043d656433aSmrg#ifndef _O_BINARY
6044d656433aSmrg# define _O_BINARY 0
6045d656433aSmrg#endif
6046d656433aSmrg
6047d656433aSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
6048d656433aSmrg#define XFREE(stale) do { \
6049300346aeSmrg  if (stale) { free (stale); stale = 0; } \
6050d656433aSmrg} while (0)
6051d656433aSmrg
6052300346aeSmrg#if defined LT_DEBUGWRAPPER
6053555991fdSmrgstatic int lt_debug = 1;
6054d656433aSmrg#else
6055555991fdSmrgstatic int lt_debug = 0;
6056d656433aSmrg#endif
6057d656433aSmrg
6058555991fdSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
6059d656433aSmrg
6060d656433aSmrgvoid *xmalloc (size_t num);
6061d656433aSmrgchar *xstrdup (const char *string);
6062d656433aSmrgconst char *base_name (const char *name);
6063d656433aSmrgchar *find_executable (const char *wrapper);
6064d656433aSmrgchar *chase_symlinks (const char *pathspec);
6065d656433aSmrgint make_executable (const char *path);
6066d656433aSmrgint check_executable (const char *path);
6067d656433aSmrgchar *strendzap (char *str, const char *pat);
6068555991fdSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
6069555991fdSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
6070555991fdSmrgstatic const char *nonnull (const char *s);
6071555991fdSmrgstatic const char *nonempty (const char *s);
6072d656433aSmrgvoid lt_setenv (const char *name, const char *value);
6073d656433aSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
6074d656433aSmrgvoid lt_update_exe_path (const char *name, const char *value);
6075d656433aSmrgvoid lt_update_lib_path (const char *name, const char *value);
6076555991fdSmrgchar **prepare_spawn (char **argv);
6077555991fdSmrgvoid lt_dump_script (FILE *f);
6078d656433aSmrgEOF
6079d656433aSmrg
6080d656433aSmrg	    cat <<EOF
6081300346aeSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
6082300346aeSmrg# define externally_visible volatile
6083300346aeSmrg#else
6084300346aeSmrg# define externally_visible __attribute__((externally_visible)) volatile
6085300346aeSmrg#endif
6086300346aeSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
6087d656433aSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
6088d656433aSmrgEOF
6089d656433aSmrg
6090300346aeSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
60913c15da26Smrg              func_to_host_path "$temp_rpath"
6092d656433aSmrg	      cat <<EOF
60933c15da26Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
6094126a8a12SmrgEOF
6095126a8a12Smrg	    else
6096d656433aSmrg	      cat <<"EOF"
6097d656433aSmrgconst char * LIB_PATH_VALUE   = "";
6098d656433aSmrgEOF
6099126a8a12Smrg	    fi
6100d656433aSmrg
6101d656433aSmrg	    if test -n "$dllsearchpath"; then
61023c15da26Smrg              func_to_host_path "$dllsearchpath:"
6103d656433aSmrg	      cat <<EOF
6104d656433aSmrgconst char * EXE_PATH_VARNAME = "PATH";
61053c15da26Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
6106d656433aSmrgEOF
6107126a8a12Smrg	    else
6108d656433aSmrg	      cat <<"EOF"
6109d656433aSmrgconst char * EXE_PATH_VARNAME = "";
6110d656433aSmrgconst char * EXE_PATH_VALUE   = "";
6111d656433aSmrgEOF
6112126a8a12Smrg	    fi
6113d656433aSmrg
6114300346aeSmrg	    if test yes = "$fast_install"; then
6115d656433aSmrg	      cat <<EOF
6116d656433aSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
6117d656433aSmrgEOF
6118126a8a12Smrg	    else
6119d656433aSmrg	      cat <<EOF
6120d656433aSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
6121d656433aSmrgEOF
6122126a8a12Smrg	    fi
6123126a8a12Smrg
6124126a8a12Smrg
6125d656433aSmrg	    cat <<"EOF"
6126126a8a12Smrg
6127d656433aSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
6128126a8a12Smrg
6129d656433aSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
6130d656433aSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
6131555991fdSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
6132126a8a12Smrg
6133d656433aSmrgint
6134d656433aSmrgmain (int argc, char *argv[])
6135d656433aSmrg{
6136d656433aSmrg  char **newargz;
6137d656433aSmrg  int  newargc;
6138d656433aSmrg  char *tmp_pathspec;
6139d656433aSmrg  char *actual_cwrapper_path;
6140d656433aSmrg  char *actual_cwrapper_name;
6141d656433aSmrg  char *target_name;
6142d656433aSmrg  char *lt_argv_zero;
6143300346aeSmrg  int rval = 127;
6144126a8a12Smrg
6145d656433aSmrg  int i;
6146126a8a12Smrg
6147d656433aSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6148300346aeSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6149126a8a12Smrg
6150555991fdSmrg  /* very simple arg parsing; don't want to rely on getopt
6151555991fdSmrg   * also, copy all non cwrapper options to newargz, except
6152555991fdSmrg   * argz[0], which is handled differently
6153555991fdSmrg   */
6154555991fdSmrg  newargc=0;
6155d656433aSmrg  for (i = 1; i < argc; i++)
6156d656433aSmrg    {
6157300346aeSmrg      if (STREQ (argv[i], dumpscript_opt))
6158d656433aSmrg	{
6159d656433aSmrgEOF
6160300346aeSmrg	    case $host in
61616bea0e4fSmrg	      *mingw* | *windows* | *cygwin* )
6162d656433aSmrg		# make stdout use "unix" line endings
6163d656433aSmrg		echo "          setmode(1,_O_BINARY);"
6164d656433aSmrg		;;
6165d656433aSmrg	      esac
6166126a8a12Smrg
6167d656433aSmrg	    cat <<"EOF"
6168555991fdSmrg	  lt_dump_script (stdout);
6169d656433aSmrg	  return 0;
6170d656433aSmrg	}
6171300346aeSmrg      if (STREQ (argv[i], debug_opt))
6172555991fdSmrg	{
6173555991fdSmrg          lt_debug = 1;
6174555991fdSmrg          continue;
6175555991fdSmrg	}
6176300346aeSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6177555991fdSmrg        {
6178555991fdSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6179555991fdSmrg             namespace, but it is not one of the ones we know about and
61806bea0e4fSmrg             have already dealt with, above (including dump-script), then
6181555991fdSmrg             report an error. Otherwise, targets might begin to believe
6182555991fdSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6183555991fdSmrg             namespace. The first time any user complains about this, we'll
6184555991fdSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6185555991fdSmrg             or a configure.ac-settable value.
6186555991fdSmrg           */
6187555991fdSmrg          lt_fatal (__FILE__, __LINE__,
6188555991fdSmrg		    "unrecognized %s option: '%s'",
6189555991fdSmrg                    ltwrapper_option_prefix, argv[i]);
6190555991fdSmrg        }
6191555991fdSmrg      /* otherwise ... */
6192555991fdSmrg      newargz[++newargc] = xstrdup (argv[i]);
6193d656433aSmrg    }
6194555991fdSmrg  newargz[++newargc] = NULL;
6195555991fdSmrg
6196555991fdSmrgEOF
6197555991fdSmrg	    cat <<EOF
6198555991fdSmrg  /* The GNU banner must be the first non-error debug message */
6199300346aeSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6200555991fdSmrgEOF
6201555991fdSmrg	    cat <<"EOF"
6202555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6203555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6204126a8a12Smrg
6205d656433aSmrg  tmp_pathspec = find_executable (argv[0]);
6206d656433aSmrg  if (tmp_pathspec == NULL)
6207555991fdSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6208555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6209555991fdSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6210555991fdSmrg		  tmp_pathspec);
6211d656433aSmrg
6212d656433aSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6213555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6214555991fdSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6215555991fdSmrg		  actual_cwrapper_path);
6216d656433aSmrg  XFREE (tmp_pathspec);
6217d656433aSmrg
6218555991fdSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6219d656433aSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6220d656433aSmrg
6221d656433aSmrg  /* wrapper name transforms */
6222d656433aSmrg  strendzap (actual_cwrapper_name, ".exe");
6223d656433aSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6224d656433aSmrg  XFREE (actual_cwrapper_name);
6225d656433aSmrg  actual_cwrapper_name = tmp_pathspec;
6226d656433aSmrg  tmp_pathspec = 0;
6227d656433aSmrg
6228d656433aSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6229d656433aSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6230d656433aSmrg  strendzap (target_name, ".exe");
6231d656433aSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6232d656433aSmrg  XFREE (target_name);
6233d656433aSmrg  target_name = tmp_pathspec;
6234d656433aSmrg  tmp_pathspec = 0;
6235d656433aSmrg
6236555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6237555991fdSmrg		  "(main) libtool target name: %s\n",
6238555991fdSmrg		  target_name);
6239d656433aSmrgEOF
6240126a8a12Smrg
6241d656433aSmrg	    cat <<EOF
6242d656433aSmrg  newargz[0] =
6243d656433aSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6244d656433aSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6245d656433aSmrg  strcpy (newargz[0], actual_cwrapper_path);
6246d656433aSmrg  strcat (newargz[0], "$objdir");
6247d656433aSmrg  strcat (newargz[0], "/");
6248d656433aSmrgEOF
6249126a8a12Smrg
6250d656433aSmrg	    cat <<"EOF"
6251d656433aSmrg  /* stop here, and copy so we don't have to do this twice */
6252d656433aSmrg  tmp_pathspec = xstrdup (newargz[0]);
6253126a8a12Smrg
6254d656433aSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6255d656433aSmrg  strcat (newargz[0], actual_cwrapper_name);
6256126a8a12Smrg
6257d656433aSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
6258d656433aSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6259d656433aSmrg  XFREE (tmp_pathspec);
6260d656433aSmrg  tmp_pathspec = NULL;
6261d656433aSmrgEOF
6262126a8a12Smrg
6263d656433aSmrg	    case $host_os in
62646bea0e4fSmrg	      mingw* | windows*)
6265d656433aSmrg	    cat <<"EOF"
6266d656433aSmrg  {
6267d656433aSmrg    char* p;
6268d656433aSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6269d656433aSmrg      {
6270d656433aSmrg	*p = '/';
6271d656433aSmrg      }
6272d656433aSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6273d656433aSmrg      {
6274d656433aSmrg	*p = '/';
6275d656433aSmrg      }
6276d656433aSmrg  }
6277d656433aSmrgEOF
6278d656433aSmrg	    ;;
6279d656433aSmrg	    esac
6280126a8a12Smrg
6281d656433aSmrg	    cat <<"EOF"
6282d656433aSmrg  XFREE (target_name);
6283d656433aSmrg  XFREE (actual_cwrapper_path);
6284d656433aSmrg  XFREE (actual_cwrapper_name);
6285126a8a12Smrg
6286d656433aSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6287d656433aSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
62883c15da26Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
62893c15da26Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
62903c15da26Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
62913c15da26Smrg     libraries must come first. */
6292d656433aSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
62933c15da26Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6294126a8a12Smrg
6295555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6296555991fdSmrg		  nonnull (lt_argv_zero));
6297d656433aSmrg  for (i = 0; i < newargc; i++)
6298d656433aSmrg    {
6299555991fdSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6300555991fdSmrg		      i, nonnull (newargz[i]));
6301d656433aSmrg    }
6302126a8a12Smrg
6303d656433aSmrgEOF
6304126a8a12Smrg
6305d656433aSmrg	    case $host_os in
63066bea0e4fSmrg	      mingw* | windows*)
6307d656433aSmrg		cat <<"EOF"
6308d656433aSmrg  /* execv doesn't actually work on mingw as expected on unix */
6309555991fdSmrg  newargz = prepare_spawn (newargz);
6310300346aeSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6311d656433aSmrg  if (rval == -1)
6312d656433aSmrg    {
6313d656433aSmrg      /* failed to start process */
6314555991fdSmrg      lt_debugprintf (__FILE__, __LINE__,
6315555991fdSmrg		      "(main) failed to launch target \"%s\": %s\n",
6316555991fdSmrg		      lt_argv_zero, nonnull (strerror (errno)));
6317d656433aSmrg      return 127;
6318d656433aSmrg    }
6319d656433aSmrg  return rval;
6320d656433aSmrgEOF
6321d656433aSmrg		;;
6322d656433aSmrg	      *)
6323d656433aSmrg		cat <<"EOF"
6324d656433aSmrg  execv (lt_argv_zero, newargz);
6325d656433aSmrg  return rval; /* =127, but avoids unused variable warning */
6326d656433aSmrgEOF
6327d656433aSmrg		;;
6328d656433aSmrg	    esac
6329126a8a12Smrg
6330d656433aSmrg	    cat <<"EOF"
6331d656433aSmrg}
6332126a8a12Smrg
6333d656433aSmrgvoid *
6334d656433aSmrgxmalloc (size_t num)
6335d656433aSmrg{
6336d656433aSmrg  void *p = (void *) malloc (num);
6337d656433aSmrg  if (!p)
6338555991fdSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6339126a8a12Smrg
6340d656433aSmrg  return p;
6341d656433aSmrg}
6342126a8a12Smrg
6343d656433aSmrgchar *
6344d656433aSmrgxstrdup (const char *string)
6345d656433aSmrg{
6346d656433aSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6347d656433aSmrg			  string) : NULL;
6348d656433aSmrg}
6349126a8a12Smrg
6350d656433aSmrgconst char *
6351d656433aSmrgbase_name (const char *name)
6352d656433aSmrg{
6353d656433aSmrg  const char *base;
6354126a8a12Smrg
6355300346aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6356d656433aSmrg  /* Skip over the disk name in MSDOS pathnames. */
6357d656433aSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6358d656433aSmrg    name += 2;
6359d656433aSmrg#endif
6360126a8a12Smrg
6361d656433aSmrg  for (base = name; *name; name++)
6362d656433aSmrg    if (IS_DIR_SEPARATOR (*name))
6363d656433aSmrg      base = name + 1;
6364d656433aSmrg  return base;
6365d656433aSmrg}
6366126a8a12Smrg
6367d656433aSmrgint
6368d656433aSmrgcheck_executable (const char *path)
6369d656433aSmrg{
6370d656433aSmrg  struct stat st;
6371126a8a12Smrg
6372555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6373555991fdSmrg                  nonempty (path));
6374d656433aSmrg  if ((!path) || (!*path))
6375d656433aSmrg    return 0;
6376126a8a12Smrg
6377d656433aSmrg  if ((stat (path, &st) >= 0)
6378d656433aSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6379d656433aSmrg    return 1;
6380d656433aSmrg  else
6381d656433aSmrg    return 0;
6382d656433aSmrg}
6383126a8a12Smrg
6384d656433aSmrgint
6385d656433aSmrgmake_executable (const char *path)
6386d656433aSmrg{
6387d656433aSmrg  int rval = 0;
6388d656433aSmrg  struct stat st;
6389126a8a12Smrg
6390555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6391555991fdSmrg                  nonempty (path));
6392d656433aSmrg  if ((!path) || (!*path))
6393d656433aSmrg    return 0;
6394126a8a12Smrg
6395d656433aSmrg  if (stat (path, &st) >= 0)
6396d656433aSmrg    {
6397d656433aSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6398d656433aSmrg    }
6399d656433aSmrg  return rval;
6400d656433aSmrg}
6401126a8a12Smrg
6402d656433aSmrg/* Searches for the full path of the wrapper.  Returns
6403d656433aSmrg   newly allocated full path name if found, NULL otherwise
6404d656433aSmrg   Does not chase symlinks, even on platforms that support them.
6405d656433aSmrg*/
6406d656433aSmrgchar *
6407d656433aSmrgfind_executable (const char *wrapper)
6408d656433aSmrg{
6409d656433aSmrg  int has_slash = 0;
6410d656433aSmrg  const char *p;
6411d656433aSmrg  const char *p_next;
6412d656433aSmrg  /* static buffer for getcwd */
6413d656433aSmrg  char tmp[LT_PATHMAX + 1];
6414300346aeSmrg  size_t tmp_len;
6415d656433aSmrg  char *concat_name;
6416126a8a12Smrg
6417555991fdSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6418555991fdSmrg                  nonempty (wrapper));
6419126a8a12Smrg
6420d656433aSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6421d656433aSmrg    return NULL;
6422126a8a12Smrg
6423d656433aSmrg  /* Absolute path? */
6424300346aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6425d656433aSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6426d656433aSmrg    {
6427d656433aSmrg      concat_name = xstrdup (wrapper);
6428d656433aSmrg      if (check_executable (concat_name))
6429d656433aSmrg	return concat_name;
6430d656433aSmrg      XFREE (concat_name);
6431d656433aSmrg    }
6432d656433aSmrg  else
6433d656433aSmrg    {
6434d656433aSmrg#endif
6435d656433aSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6436d656433aSmrg	{
6437d656433aSmrg	  concat_name = xstrdup (wrapper);
6438d656433aSmrg	  if (check_executable (concat_name))
6439d656433aSmrg	    return concat_name;
6440d656433aSmrg	  XFREE (concat_name);
6441d656433aSmrg	}
6442300346aeSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6443d656433aSmrg    }
6444d656433aSmrg#endif
6445126a8a12Smrg
6446d656433aSmrg  for (p = wrapper; *p; p++)
6447d656433aSmrg    if (*p == '/')
6448d656433aSmrg      {
6449d656433aSmrg	has_slash = 1;
6450d656433aSmrg	break;
6451d656433aSmrg      }
6452d656433aSmrg  if (!has_slash)
6453d656433aSmrg    {
6454d656433aSmrg      /* no slashes; search PATH */
6455d656433aSmrg      const char *path = getenv ("PATH");
6456d656433aSmrg      if (path != NULL)
6457d656433aSmrg	{
6458d656433aSmrg	  for (p = path; *p; p = p_next)
6459d656433aSmrg	    {
6460d656433aSmrg	      const char *q;
6461d656433aSmrg	      size_t p_len;
6462d656433aSmrg	      for (q = p; *q; q++)
6463d656433aSmrg		if (IS_PATH_SEPARATOR (*q))
6464d656433aSmrg		  break;
6465300346aeSmrg	      p_len = (size_t) (q - p);
6466d656433aSmrg	      p_next = (*q == '\0' ? q : q + 1);
6467d656433aSmrg	      if (p_len == 0)
6468d656433aSmrg		{
6469d656433aSmrg		  /* empty path: current directory */
6470d656433aSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6471555991fdSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6472555991fdSmrg                              nonnull (strerror (errno)));
6473d656433aSmrg		  tmp_len = strlen (tmp);
6474d656433aSmrg		  concat_name =
6475d656433aSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6476d656433aSmrg		  memcpy (concat_name, tmp, tmp_len);
6477d656433aSmrg		  concat_name[tmp_len] = '/';
6478d656433aSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6479d656433aSmrg		}
6480d656433aSmrg	      else
6481d656433aSmrg		{
6482d656433aSmrg		  concat_name =
6483d656433aSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6484d656433aSmrg		  memcpy (concat_name, p, p_len);
6485d656433aSmrg		  concat_name[p_len] = '/';
6486d656433aSmrg		  strcpy (concat_name + p_len + 1, wrapper);
6487d656433aSmrg		}
6488d656433aSmrg	      if (check_executable (concat_name))
6489d656433aSmrg		return concat_name;
6490d656433aSmrg	      XFREE (concat_name);
6491d656433aSmrg	    }
6492d656433aSmrg	}
6493d656433aSmrg      /* not found in PATH; assume curdir */
6494d656433aSmrg    }
6495d656433aSmrg  /* Relative path | not found in path: prepend cwd */
6496d656433aSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6497555991fdSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6498555991fdSmrg              nonnull (strerror (errno)));
6499d656433aSmrg  tmp_len = strlen (tmp);
6500d656433aSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6501d656433aSmrg  memcpy (concat_name, tmp, tmp_len);
6502d656433aSmrg  concat_name[tmp_len] = '/';
6503d656433aSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
6504126a8a12Smrg
6505d656433aSmrg  if (check_executable (concat_name))
6506d656433aSmrg    return concat_name;
6507d656433aSmrg  XFREE (concat_name);
6508d656433aSmrg  return NULL;
6509d656433aSmrg}
6510126a8a12Smrg
6511d656433aSmrgchar *
6512d656433aSmrgchase_symlinks (const char *pathspec)
6513d656433aSmrg{
6514d656433aSmrg#ifndef S_ISLNK
6515d656433aSmrg  return xstrdup (pathspec);
6516d656433aSmrg#else
6517d656433aSmrg  char buf[LT_PATHMAX];
6518d656433aSmrg  struct stat s;
6519d656433aSmrg  char *tmp_pathspec = xstrdup (pathspec);
6520d656433aSmrg  char *p;
6521d656433aSmrg  int has_symlinks = 0;
6522d656433aSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
6523d656433aSmrg    {
6524555991fdSmrg      lt_debugprintf (__FILE__, __LINE__,
6525555991fdSmrg		      "checking path component for symlinks: %s\n",
6526555991fdSmrg		      tmp_pathspec);
6527d656433aSmrg      if (lstat (tmp_pathspec, &s) == 0)
6528d656433aSmrg	{
6529d656433aSmrg	  if (S_ISLNK (s.st_mode) != 0)
6530d656433aSmrg	    {
6531d656433aSmrg	      has_symlinks = 1;
6532d656433aSmrg	      break;
6533d656433aSmrg	    }
6534126a8a12Smrg
6535d656433aSmrg	  /* search backwards for last DIR_SEPARATOR */
6536d656433aSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6537d656433aSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6538d656433aSmrg	    p--;
6539d656433aSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6540d656433aSmrg	    {
6541d656433aSmrg	      /* no more DIR_SEPARATORS left */
6542d656433aSmrg	      break;
6543d656433aSmrg	    }
6544d656433aSmrg	  *p = '\0';
6545d656433aSmrg	}
6546d656433aSmrg      else
6547d656433aSmrg	{
6548555991fdSmrg	  lt_fatal (__FILE__, __LINE__,
6549555991fdSmrg		    "error accessing file \"%s\": %s",
6550555991fdSmrg		    tmp_pathspec, nonnull (strerror (errno)));
6551d656433aSmrg	}
6552d656433aSmrg    }
6553d656433aSmrg  XFREE (tmp_pathspec);
6554126a8a12Smrg
6555d656433aSmrg  if (!has_symlinks)
6556d656433aSmrg    {
6557d656433aSmrg      return xstrdup (pathspec);
6558d656433aSmrg    }
6559126a8a12Smrg
6560d656433aSmrg  tmp_pathspec = realpath (pathspec, buf);
6561d656433aSmrg  if (tmp_pathspec == 0)
6562d656433aSmrg    {
6563555991fdSmrg      lt_fatal (__FILE__, __LINE__,
6564555991fdSmrg		"could not follow symlinks for %s", pathspec);
6565d656433aSmrg    }
6566d656433aSmrg  return xstrdup (tmp_pathspec);
6567d656433aSmrg#endif
6568d656433aSmrg}
6569126a8a12Smrg
6570d656433aSmrgchar *
6571d656433aSmrgstrendzap (char *str, const char *pat)
6572d656433aSmrg{
6573d656433aSmrg  size_t len, patlen;
6574126a8a12Smrg
6575d656433aSmrg  assert (str != NULL);
6576d656433aSmrg  assert (pat != NULL);
6577126a8a12Smrg
6578d656433aSmrg  len = strlen (str);
6579d656433aSmrg  patlen = strlen (pat);
6580126a8a12Smrg
6581d656433aSmrg  if (patlen <= len)
6582d656433aSmrg    {
6583d656433aSmrg      str += len - patlen;
6584300346aeSmrg      if (STREQ (str, pat))
6585d656433aSmrg	*str = '\0';
6586d656433aSmrg    }
6587d656433aSmrg  return str;
6588d656433aSmrg}
6589126a8a12Smrg
6590555991fdSmrgvoid
6591555991fdSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6592555991fdSmrg{
6593555991fdSmrg  va_list args;
6594555991fdSmrg  if (lt_debug)
6595555991fdSmrg    {
6596555991fdSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6597555991fdSmrg      va_start (args, fmt);
6598555991fdSmrg      (void) vfprintf (stderr, fmt, args);
6599555991fdSmrg      va_end (args);
6600555991fdSmrg    }
6601555991fdSmrg}
6602555991fdSmrg
6603d656433aSmrgstatic void
6604555991fdSmrglt_error_core (int exit_status, const char *file,
6605555991fdSmrg	       int line, const char *mode,
6606d656433aSmrg	       const char *message, va_list ap)
6607d656433aSmrg{
6608555991fdSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6609d656433aSmrg  vfprintf (stderr, message, ap);
6610d656433aSmrg  fprintf (stderr, ".\n");
6611126a8a12Smrg
6612d656433aSmrg  if (exit_status >= 0)
6613d656433aSmrg    exit (exit_status);
6614d656433aSmrg}
6615126a8a12Smrg
6616d656433aSmrgvoid
6617555991fdSmrglt_fatal (const char *file, int line, const char *message, ...)
6618d656433aSmrg{
6619d656433aSmrg  va_list ap;
6620d656433aSmrg  va_start (ap, message);
6621555991fdSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6622d656433aSmrg  va_end (ap);
6623d656433aSmrg}
6624126a8a12Smrg
6625555991fdSmrgstatic const char *
6626555991fdSmrgnonnull (const char *s)
6627555991fdSmrg{
6628555991fdSmrg  return s ? s : "(null)";
6629555991fdSmrg}
6630555991fdSmrg
6631555991fdSmrgstatic const char *
6632555991fdSmrgnonempty (const char *s)
6633555991fdSmrg{
6634555991fdSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6635555991fdSmrg}
6636555991fdSmrg
6637d656433aSmrgvoid
6638d656433aSmrglt_setenv (const char *name, const char *value)
6639d656433aSmrg{
6640555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6641555991fdSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6642555991fdSmrg                  nonnull (name), nonnull (value));
6643d656433aSmrg  {
6644d656433aSmrg#ifdef HAVE_SETENV
6645d656433aSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
6646d656433aSmrg    char *str = xstrdup (value);
6647d656433aSmrg    setenv (name, str, 1);
6648d656433aSmrg#else
6649300346aeSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6650d656433aSmrg    char *str = XMALLOC (char, len);
6651d656433aSmrg    sprintf (str, "%s=%s", name, value);
6652d656433aSmrg    if (putenv (str) != EXIT_SUCCESS)
6653d656433aSmrg      {
6654d656433aSmrg        XFREE (str);
6655d656433aSmrg      }
6656d656433aSmrg#endif
6657d656433aSmrg  }
6658d656433aSmrg}
6659126a8a12Smrg
6660d656433aSmrgchar *
6661d656433aSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
6662d656433aSmrg{
6663d656433aSmrg  char *new_value;
6664d656433aSmrg  if (orig_value && *orig_value)
6665d656433aSmrg    {
6666300346aeSmrg      size_t orig_value_len = strlen (orig_value);
6667300346aeSmrg      size_t add_len = strlen (add);
6668d656433aSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6669d656433aSmrg      if (to_end)
6670d656433aSmrg        {
6671d656433aSmrg          strcpy (new_value, orig_value);
6672d656433aSmrg          strcpy (new_value + orig_value_len, add);
6673d656433aSmrg        }
6674d656433aSmrg      else
6675d656433aSmrg        {
6676d656433aSmrg          strcpy (new_value, add);
6677d656433aSmrg          strcpy (new_value + add_len, orig_value);
6678d656433aSmrg        }
6679d656433aSmrg    }
6680d656433aSmrg  else
6681d656433aSmrg    {
6682d656433aSmrg      new_value = xstrdup (add);
6683d656433aSmrg    }
6684d656433aSmrg  return new_value;
6685d656433aSmrg}
6686126a8a12Smrg
6687d656433aSmrgvoid
6688d656433aSmrglt_update_exe_path (const char *name, const char *value)
6689d656433aSmrg{
6690555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6691555991fdSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6692555991fdSmrg                  nonnull (name), nonnull (value));
6693126a8a12Smrg
6694d656433aSmrg  if (name && *name && value && *value)
6695d656433aSmrg    {
6696d656433aSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6697d656433aSmrg      /* some systems can't cope with a ':'-terminated path #' */
6698300346aeSmrg      size_t len = strlen (new_value);
6699300346aeSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6700d656433aSmrg        {
6701300346aeSmrg          new_value[--len] = '\0';
6702d656433aSmrg        }
6703d656433aSmrg      lt_setenv (name, new_value);
6704d656433aSmrg      XFREE (new_value);
6705d656433aSmrg    }
6706d656433aSmrg}
6707126a8a12Smrg
6708d656433aSmrgvoid
6709d656433aSmrglt_update_lib_path (const char *name, const char *value)
6710d656433aSmrg{
6711555991fdSmrg  lt_debugprintf (__FILE__, __LINE__,
6712555991fdSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6713555991fdSmrg                  nonnull (name), nonnull (value));
6714126a8a12Smrg
6715d656433aSmrg  if (name && *name && value && *value)
6716d656433aSmrg    {
6717d656433aSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6718d656433aSmrg      lt_setenv (name, new_value);
6719d656433aSmrg      XFREE (new_value);
6720d656433aSmrg    }
6721d656433aSmrg}
6722126a8a12Smrg
6723555991fdSmrgEOF
6724555991fdSmrg	    case $host_os in
67256bea0e4fSmrg	      mingw* | windows*)
6726555991fdSmrg		cat <<"EOF"
6727555991fdSmrg
6728555991fdSmrg/* Prepares an argument vector before calling spawn().
6729555991fdSmrg   Note that spawn() does not by itself call the command interpreter
6730555991fdSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6731555991fdSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6732555991fdSmrg         GetVersionEx(&v);
6733555991fdSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6734555991fdSmrg      }) ? "cmd.exe" : "command.com").
6735555991fdSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6736555991fdSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6737555991fdSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6738555991fdSmrg   special way:
6739555991fdSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6740555991fdSmrg     delimiters if they are surrounded by double quotes: "...".
6741555991fdSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6742555991fdSmrg     that within double quotes, space and tab are treated like normal
6743555991fdSmrg     characters.
6744555991fdSmrg   - Backslashes not followed by double quotes are not special.
6745555991fdSmrg   - But 2*n+1 backslashes followed by a double quote become
6746555991fdSmrg     n backslashes followed by a double quote (n >= 0):
6747555991fdSmrg       \" -> "
6748555991fdSmrg       \\\" -> \"
6749555991fdSmrg       \\\\\" -> \\"
6750555991fdSmrg */
6751555991fdSmrg#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"
6752555991fdSmrg#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"
6753555991fdSmrgchar **
6754555991fdSmrgprepare_spawn (char **argv)
6755555991fdSmrg{
6756555991fdSmrg  size_t argc;
6757555991fdSmrg  char **new_argv;
6758555991fdSmrg  size_t i;
6759555991fdSmrg
6760555991fdSmrg  /* Count number of arguments.  */
6761555991fdSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6762555991fdSmrg    ;
6763555991fdSmrg
6764555991fdSmrg  /* Allocate new argument vector.  */
6765555991fdSmrg  new_argv = XMALLOC (char *, argc + 1);
6766555991fdSmrg
6767555991fdSmrg  /* Put quoted arguments into the new argument vector.  */
6768555991fdSmrg  for (i = 0; i < argc; i++)
6769555991fdSmrg    {
6770555991fdSmrg      const char *string = argv[i];
6771555991fdSmrg
6772555991fdSmrg      if (string[0] == '\0')
6773555991fdSmrg	new_argv[i] = xstrdup ("\"\"");
6774555991fdSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6775555991fdSmrg	{
6776555991fdSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6777555991fdSmrg	  size_t length;
6778555991fdSmrg	  unsigned int backslashes;
6779555991fdSmrg	  const char *s;
6780555991fdSmrg	  char *quoted_string;
6781555991fdSmrg	  char *p;
6782555991fdSmrg
6783555991fdSmrg	  length = 0;
6784555991fdSmrg	  backslashes = 0;
6785555991fdSmrg	  if (quote_around)
6786555991fdSmrg	    length++;
6787555991fdSmrg	  for (s = string; *s != '\0'; s++)
6788555991fdSmrg	    {
6789555991fdSmrg	      char c = *s;
6790555991fdSmrg	      if (c == '"')
6791555991fdSmrg		length += backslashes + 1;
6792555991fdSmrg	      length++;
6793555991fdSmrg	      if (c == '\\')
6794555991fdSmrg		backslashes++;
6795555991fdSmrg	      else
6796555991fdSmrg		backslashes = 0;
6797555991fdSmrg	    }
6798555991fdSmrg	  if (quote_around)
6799555991fdSmrg	    length += backslashes + 1;
6800555991fdSmrg
6801555991fdSmrg	  quoted_string = XMALLOC (char, length + 1);
6802555991fdSmrg
6803555991fdSmrg	  p = quoted_string;
6804555991fdSmrg	  backslashes = 0;
6805555991fdSmrg	  if (quote_around)
6806555991fdSmrg	    *p++ = '"';
6807555991fdSmrg	  for (s = string; *s != '\0'; s++)
6808555991fdSmrg	    {
6809555991fdSmrg	      char c = *s;
6810555991fdSmrg	      if (c == '"')
6811555991fdSmrg		{
6812555991fdSmrg		  unsigned int j;
6813555991fdSmrg		  for (j = backslashes + 1; j > 0; j--)
6814555991fdSmrg		    *p++ = '\\';
6815555991fdSmrg		}
6816555991fdSmrg	      *p++ = c;
6817555991fdSmrg	      if (c == '\\')
6818555991fdSmrg		backslashes++;
6819555991fdSmrg	      else
6820555991fdSmrg		backslashes = 0;
6821555991fdSmrg	    }
6822555991fdSmrg	  if (quote_around)
6823555991fdSmrg	    {
6824555991fdSmrg	      unsigned int j;
6825555991fdSmrg	      for (j = backslashes; j > 0; j--)
6826555991fdSmrg		*p++ = '\\';
6827555991fdSmrg	      *p++ = '"';
6828555991fdSmrg	    }
6829555991fdSmrg	  *p = '\0';
6830555991fdSmrg
6831555991fdSmrg	  new_argv[i] = quoted_string;
6832555991fdSmrg	}
6833555991fdSmrg      else
6834555991fdSmrg	new_argv[i] = (char *) string;
6835555991fdSmrg    }
6836555991fdSmrg  new_argv[argc] = NULL;
6837555991fdSmrg
6838555991fdSmrg  return new_argv;
6839555991fdSmrg}
6840555991fdSmrgEOF
6841555991fdSmrg		;;
6842555991fdSmrg	    esac
6843555991fdSmrg
6844555991fdSmrg            cat <<"EOF"
6845555991fdSmrgvoid lt_dump_script (FILE* f)
6846555991fdSmrg{
6847555991fdSmrgEOF
6848555991fdSmrg	    func_emit_wrapper yes |
68490a6b08f8Smrg	      $SED -n -e '
68500a6b08f8Smrgs/^\(.\{79\}\)\(..*\)/\1\
68510a6b08f8Smrg\2/
68520a6b08f8Smrgh
68530a6b08f8Smrgs/\([\\"]\)/\\\1/g
68540a6b08f8Smrgs/$/\\n/
68550a6b08f8Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
68560a6b08f8Smrgg
68570a6b08f8SmrgD'
6858555991fdSmrg            cat <<"EOF"
6859555991fdSmrg}
6860d656433aSmrgEOF
6861d656433aSmrg}
6862d656433aSmrg# end: func_emit_cwrapperexe_src
6863126a8a12Smrg
6864555991fdSmrg# func_win32_import_lib_p ARG
6865555991fdSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6866555991fdSmrgfunc_win32_import_lib_p ()
6867555991fdSmrg{
6868300346aeSmrg    $debug_cmd
6869300346aeSmrg
6870555991fdSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6871555991fdSmrg    *import*) : ;;
6872555991fdSmrg    *) false ;;
6873555991fdSmrg    esac
6874555991fdSmrg}
6875555991fdSmrg
6876300346aeSmrg# func_suncc_cstd_abi
6877300346aeSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6878300346aeSmrg# Several compiler flags select an ABI that is incompatible with the
6879300346aeSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6880300346aeSmrgfunc_suncc_cstd_abi ()
6881300346aeSmrg{
6882300346aeSmrg    $debug_cmd
6883300346aeSmrg
6884300346aeSmrg    case " $compile_command " in
6885300346aeSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6886300346aeSmrg      suncc_use_cstd_abi=no
6887300346aeSmrg      ;;
6888300346aeSmrg    *)
6889300346aeSmrg      suncc_use_cstd_abi=yes
6890300346aeSmrg      ;;
6891300346aeSmrg    esac
6892300346aeSmrg}
6893300346aeSmrg
6894d656433aSmrg# func_mode_link arg...
6895d656433aSmrgfunc_mode_link ()
6896d656433aSmrg{
6897300346aeSmrg    $debug_cmd
6898300346aeSmrg
6899d656433aSmrg    case $host in
69006bea0e4fSmrg    *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
6901d656433aSmrg      # It is impossible to link a dll without this setting, and
6902d656433aSmrg      # we shouldn't force the makefile maintainer to figure out
6903300346aeSmrg      # what system we are compiling for in order to pass an extra
6904d656433aSmrg      # flag for every libtool invocation.
6905d656433aSmrg      # allow_undefined=no
6906126a8a12Smrg
6907d656433aSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6908300346aeSmrg      # to make a dll that has undefined symbols, in which case not
6909d656433aSmrg      # even a static library is built.  For now, we need to specify
6910d656433aSmrg      # -no-undefined on the libtool link line when we can be certain
6911d656433aSmrg      # that all symbols are satisfied, otherwise we get a static library.
6912d656433aSmrg      allow_undefined=yes
6913d656433aSmrg      ;;
6914d656433aSmrg    *)
6915d656433aSmrg      allow_undefined=yes
6916d656433aSmrg      ;;
6917d656433aSmrg    esac
6918d656433aSmrg    libtool_args=$nonopt
6919d656433aSmrg    base_compile="$nonopt $@"
6920d656433aSmrg    compile_command=$nonopt
6921d656433aSmrg    finalize_command=$nonopt
6922126a8a12Smrg
6923d656433aSmrg    compile_rpath=
69246bea0e4fSmrg    compile_rpath_tail=
6925d656433aSmrg    finalize_rpath=
6926d656433aSmrg    compile_shlibpath=
6927d656433aSmrg    finalize_shlibpath=
6928d656433aSmrg    convenience=
6929d656433aSmrg    old_convenience=
6930d656433aSmrg    deplibs=
6931d656433aSmrg    old_deplibs=
6932d656433aSmrg    compiler_flags=
6933d656433aSmrg    linker_flags=
6934d656433aSmrg    dllsearchpath=
6935d656433aSmrg    lib_search_path=`pwd`
6936d656433aSmrg    inst_prefix_dir=
6937d656433aSmrg    new_inherited_linker_flags=
6938126a8a12Smrg
6939d656433aSmrg    avoid_version=no
6940555991fdSmrg    bindir=
6941d656433aSmrg    dlfiles=
6942d656433aSmrg    dlprefiles=
6943d656433aSmrg    dlself=no
6944d656433aSmrg    export_dynamic=no
6945d656433aSmrg    export_symbols=
6946d656433aSmrg    export_symbols_regex=
6947d656433aSmrg    generated=
6948d656433aSmrg    libobjs=
6949d656433aSmrg    ltlibs=
6950d656433aSmrg    module=no
6951d656433aSmrg    no_install=no
6952d656433aSmrg    objs=
6953300346aeSmrg    os2dllname=
6954d656433aSmrg    non_pic_objects=
6955d656433aSmrg    precious_files_regex=
6956d656433aSmrg    prefer_static_libs=no
6957300346aeSmrg    preload=false
6958d656433aSmrg    prev=
6959d656433aSmrg    prevarg=
6960d656433aSmrg    release=
6961d656433aSmrg    rpath=
6962d656433aSmrg    xrpath=
6963d656433aSmrg    perm_rpath=
6964d656433aSmrg    temp_rpath=
69656bea0e4fSmrg    temp_rpath_tail=
6966d656433aSmrg    thread_safe=no
6967d656433aSmrg    vinfo=
6968d656433aSmrg    vinfo_number=no
6969d656433aSmrg    weak_libs=
69706bea0e4fSmrg    rpath_arg=
6971300346aeSmrg    single_module=$wl-single_module
6972d656433aSmrg    func_infer_tag $base_compile
6973126a8a12Smrg
6974d656433aSmrg    # We need to know -static, to get the right output filenames.
6975d656433aSmrg    for arg
6976d656433aSmrg    do
6977d656433aSmrg      case $arg in
6978d656433aSmrg      -shared)
6979300346aeSmrg	test yes != "$build_libtool_libs" \
6980300346aeSmrg	  && func_fatal_configuration "cannot build a shared library"
6981d656433aSmrg	build_old_libs=no
6982d656433aSmrg	break
6983d656433aSmrg	;;
6984d656433aSmrg      -all-static | -static | -static-libtool-libs)
6985d656433aSmrg	case $arg in
6986d656433aSmrg	-all-static)
6987300346aeSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6988d656433aSmrg	    func_warning "complete static linking is impossible in this configuration"
6989126a8a12Smrg	  fi
6990d656433aSmrg	  if test -n "$link_static_flag"; then
6991d656433aSmrg	    dlopen_self=$dlopen_self_static
6992126a8a12Smrg	  fi
6993d656433aSmrg	  prefer_static_libs=yes
6994126a8a12Smrg	  ;;
6995d656433aSmrg	-static)
6996d656433aSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6997d656433aSmrg	    dlopen_self=$dlopen_self_static
6998d656433aSmrg	  fi
6999d656433aSmrg	  prefer_static_libs=built
7000d656433aSmrg	  ;;
7001d656433aSmrg	-static-libtool-libs)
7002d656433aSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
7003d656433aSmrg	    dlopen_self=$dlopen_self_static
7004d656433aSmrg	  fi
7005d656433aSmrg	  prefer_static_libs=yes
7006126a8a12Smrg	  ;;
7007126a8a12Smrg	esac
7008d656433aSmrg	build_libtool_libs=no
7009d656433aSmrg	build_old_libs=yes
7010d656433aSmrg	break
7011d656433aSmrg	;;
7012d656433aSmrg      esac
7013d656433aSmrg    done
7014126a8a12Smrg
7015d656433aSmrg    # See if our shared archives depend on static archives.
7016d656433aSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
7017126a8a12Smrg
7018d656433aSmrg    # Go through the arguments, transforming them on the way.
7019d656433aSmrg    while test "$#" -gt 0; do
7020300346aeSmrg      arg=$1
7021d656433aSmrg      shift
70223fb97780Smrg      func_quote_arg pretty,unquoted "$arg"
70233fb97780Smrg      qarg=$func_quote_arg_unquoted_result
70243fb97780Smrg      func_append libtool_args " $func_quote_arg_result"
7025126a8a12Smrg
7026d656433aSmrg      # If the previous option needs an argument, assign it.
7027d656433aSmrg      if test -n "$prev"; then
7028d656433aSmrg	case $prev in
7029d656433aSmrg	output)
7030d656433aSmrg	  func_append compile_command " @OUTPUT@"
7031d656433aSmrg	  func_append finalize_command " @OUTPUT@"
7032d656433aSmrg	  ;;
7033d656433aSmrg	esac
7034126a8a12Smrg
7035d656433aSmrg	case $prev in
7036555991fdSmrg	bindir)
7037300346aeSmrg	  bindir=$arg
7038555991fdSmrg	  prev=
7039555991fdSmrg	  continue
7040555991fdSmrg	  ;;
7041d656433aSmrg	dlfiles|dlprefiles)
7042300346aeSmrg	  $preload || {
7043d656433aSmrg	    # Add the symbol object into the linking commands.
7044d656433aSmrg	    func_append compile_command " @SYMFILE@"
7045d656433aSmrg	    func_append finalize_command " @SYMFILE@"
7046300346aeSmrg	    preload=:
7047300346aeSmrg	  }
7048d656433aSmrg	  case $arg in
7049d656433aSmrg	  *.la | *.lo) ;;  # We handle these cases below.
7050d656433aSmrg	  force)
7051300346aeSmrg	    if test no = "$dlself"; then
7052d656433aSmrg	      dlself=needless
7053d656433aSmrg	      export_dynamic=yes
7054d656433aSmrg	    fi
7055d656433aSmrg	    prev=
7056d656433aSmrg	    continue
7057d656433aSmrg	    ;;
7058d656433aSmrg	  self)
7059300346aeSmrg	    if test dlprefiles = "$prev"; then
7060d656433aSmrg	      dlself=yes
7061300346aeSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
7062d656433aSmrg	      dlself=yes
7063d656433aSmrg	    else
7064d656433aSmrg	      dlself=needless
7065d656433aSmrg	      export_dynamic=yes
7066d656433aSmrg	    fi
7067d656433aSmrg	    prev=
7068d656433aSmrg	    continue
7069126a8a12Smrg	    ;;
7070126a8a12Smrg	  *)
7071300346aeSmrg	    if test dlfiles = "$prev"; then
70723c15da26Smrg	      func_append dlfiles " $arg"
7073d656433aSmrg	    else
70743c15da26Smrg	      func_append dlprefiles " $arg"
7075d656433aSmrg	    fi
7076d656433aSmrg	    prev=
7077d656433aSmrg	    continue
7078126a8a12Smrg	    ;;
7079126a8a12Smrg	  esac
7080d656433aSmrg	  ;;
7081d656433aSmrg	expsyms)
7082300346aeSmrg	  export_symbols=$arg
7083d656433aSmrg	  test -f "$arg" \
7084300346aeSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
7085d656433aSmrg	  prev=
7086d656433aSmrg	  continue
7087d656433aSmrg	  ;;
7088d656433aSmrg	expsyms_regex)
7089300346aeSmrg	  export_symbols_regex=$arg
7090d656433aSmrg	  prev=
7091d656433aSmrg	  continue
7092d656433aSmrg	  ;;
7093d656433aSmrg	framework)
7094d656433aSmrg	  case $host in
7095d656433aSmrg	    *-*-darwin*)
7096d656433aSmrg	      case "$deplibs " in
7097d656433aSmrg		*" $qarg.ltframework "*) ;;
70983c15da26Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
7099d656433aSmrg		   ;;
7100d656433aSmrg	      esac
7101d656433aSmrg	      ;;
7102d656433aSmrg	  esac
7103d656433aSmrg	  prev=
7104d656433aSmrg	  continue
7105d656433aSmrg	  ;;
7106d656433aSmrg	inst_prefix)
7107300346aeSmrg	  inst_prefix_dir=$arg
7108300346aeSmrg	  prev=
7109300346aeSmrg	  continue
7110300346aeSmrg	  ;;
7111300346aeSmrg	mllvm)
7112300346aeSmrg	  # Clang does not use LLVM to link, so we can simply discard any
7113300346aeSmrg	  # '-mllvm $arg' options when doing the link step.
7114d656433aSmrg	  prev=
7115d656433aSmrg	  continue
7116d656433aSmrg	  ;;
7117d656433aSmrg	objectlist)
7118d656433aSmrg	  if test -f "$arg"; then
7119d656433aSmrg	    save_arg=$arg
7120d656433aSmrg	    moreargs=
7121d656433aSmrg	    for fil in `cat "$save_arg"`
7122d656433aSmrg	    do
71233c15da26Smrg#	      func_append moreargs " $fil"
7124d656433aSmrg	      arg=$fil
7125d656433aSmrg	      # A libtool-controlled object.
7126126a8a12Smrg
7127d656433aSmrg	      # Check to see that this really is a libtool object.
7128d656433aSmrg	      if func_lalib_unsafe_p "$arg"; then
7129d656433aSmrg		pic_object=
7130d656433aSmrg		non_pic_object=
7131126a8a12Smrg
7132d656433aSmrg		# Read the .lo file
7133d656433aSmrg		func_source "$arg"
7134126a8a12Smrg
7135d656433aSmrg		if test -z "$pic_object" ||
7136d656433aSmrg		   test -z "$non_pic_object" ||
7137300346aeSmrg		   test none = "$pic_object" &&
7138300346aeSmrg		   test none = "$non_pic_object"; then
7139300346aeSmrg		  func_fatal_error "cannot find name of object for '$arg'"
7140d656433aSmrg		fi
7141126a8a12Smrg
7142d656433aSmrg		# Extract subdirectory from the argument.
7143d656433aSmrg		func_dirname "$arg" "/" ""
7144300346aeSmrg		xdir=$func_dirname_result
7145126a8a12Smrg
7146300346aeSmrg		if test none != "$pic_object"; then
7147d656433aSmrg		  # Prepend the subdirectory the object is found in.
7148300346aeSmrg		  pic_object=$xdir$pic_object
7149126a8a12Smrg
7150300346aeSmrg		  if test dlfiles = "$prev"; then
7151300346aeSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
71523c15da26Smrg		      func_append dlfiles " $pic_object"
7153d656433aSmrg		      prev=
7154d656433aSmrg		      continue
7155d656433aSmrg		    else
7156d656433aSmrg		      # If libtool objects are unsupported, then we need to preload.
7157d656433aSmrg		      prev=dlprefiles
7158d656433aSmrg		    fi
7159d656433aSmrg		  fi
7160126a8a12Smrg
7161d656433aSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7162300346aeSmrg		  if test dlprefiles = "$prev"; then
7163d656433aSmrg		    # Preload the old-style object.
71643c15da26Smrg		    func_append dlprefiles " $pic_object"
7165d656433aSmrg		    prev=
7166d656433aSmrg		  fi
7167126a8a12Smrg
7168d656433aSmrg		  # A PIC object.
7169d656433aSmrg		  func_append libobjs " $pic_object"
7170300346aeSmrg		  arg=$pic_object
7171d656433aSmrg		fi
7172126a8a12Smrg
7173d656433aSmrg		# Non-PIC object.
7174300346aeSmrg		if test none != "$non_pic_object"; then
7175d656433aSmrg		  # Prepend the subdirectory the object is found in.
7176300346aeSmrg		  non_pic_object=$xdir$non_pic_object
7177126a8a12Smrg
7178d656433aSmrg		  # A standard non-PIC object
7179d656433aSmrg		  func_append non_pic_objects " $non_pic_object"
7180300346aeSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7181300346aeSmrg		    arg=$non_pic_object
7182d656433aSmrg		  fi
7183d656433aSmrg		else
7184d656433aSmrg		  # If the PIC object exists, use it instead.
7185d656433aSmrg		  # $xdir was prepended to $pic_object above.
7186300346aeSmrg		  non_pic_object=$pic_object
7187d656433aSmrg		  func_append non_pic_objects " $non_pic_object"
7188d656433aSmrg		fi
7189d656433aSmrg	      else
7190d656433aSmrg		# Only an error if not doing a dry-run.
7191d656433aSmrg		if $opt_dry_run; then
7192d656433aSmrg		  # Extract subdirectory from the argument.
7193d656433aSmrg		  func_dirname "$arg" "/" ""
7194300346aeSmrg		  xdir=$func_dirname_result
7195d656433aSmrg
7196d656433aSmrg		  func_lo2o "$arg"
7197d656433aSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
7198d656433aSmrg		  non_pic_object=$xdir$func_lo2o_result
7199d656433aSmrg		  func_append libobjs " $pic_object"
7200d656433aSmrg		  func_append non_pic_objects " $non_pic_object"
7201d656433aSmrg	        else
7202300346aeSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7203d656433aSmrg		fi
7204d656433aSmrg	      fi
7205d656433aSmrg	    done
7206d656433aSmrg	  else
7207300346aeSmrg	    func_fatal_error "link input file '$arg' does not exist"
7208d656433aSmrg	  fi
7209d656433aSmrg	  arg=$save_arg
7210d656433aSmrg	  prev=
7211d656433aSmrg	  continue
7212d656433aSmrg	  ;;
7213300346aeSmrg	os2dllname)
7214300346aeSmrg	  os2dllname=$arg
7215300346aeSmrg	  prev=
7216300346aeSmrg	  continue
7217300346aeSmrg	  ;;
7218d656433aSmrg	precious_regex)
7219300346aeSmrg	  precious_files_regex=$arg
7220d656433aSmrg	  prev=
7221d656433aSmrg	  continue
7222d656433aSmrg	  ;;
7223d656433aSmrg	release)
7224300346aeSmrg	  release=-$arg
7225d656433aSmrg	  prev=
7226d656433aSmrg	  continue
7227d656433aSmrg	  ;;
7228d656433aSmrg	rpath | xrpath)
7229d656433aSmrg	  # We need an absolute path.
7230d656433aSmrg	  case $arg in
7231d656433aSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7232d656433aSmrg	  *)
72336bea0e4fSmrg	    func_fatal_error "argument to -rpath is not absolute: $arg"
7234d656433aSmrg	    ;;
7235d656433aSmrg	  esac
7236300346aeSmrg	  if test rpath = "$prev"; then
7237d656433aSmrg	    case "$rpath " in
7238d656433aSmrg	    *" $arg "*) ;;
72393c15da26Smrg	    *) func_append rpath " $arg" ;;
7240d656433aSmrg	    esac
7241d656433aSmrg	  else
7242d656433aSmrg	    case "$xrpath " in
7243d656433aSmrg	    *" $arg "*) ;;
72443c15da26Smrg	    *) func_append xrpath " $arg" ;;
7245d656433aSmrg	    esac
7246d656433aSmrg	  fi
7247d656433aSmrg	  prev=
7248d656433aSmrg	  continue
7249d656433aSmrg	  ;;
7250d656433aSmrg	shrext)
7251300346aeSmrg	  shrext_cmds=$arg
7252d656433aSmrg	  prev=
7253d656433aSmrg	  continue
7254d656433aSmrg	  ;;
7255d656433aSmrg	weak)
72563c15da26Smrg	  func_append weak_libs " $arg"
7257d656433aSmrg	  prev=
7258d656433aSmrg	  continue
7259d656433aSmrg	  ;;
72603fb97780Smrg	xassembler)
72613fb97780Smrg	  func_append compiler_flags " -Xassembler $qarg"
72623fb97780Smrg	  prev=
72633fb97780Smrg	  func_append compile_command " -Xassembler $qarg"
72643fb97780Smrg	  func_append finalize_command " -Xassembler $qarg"
72653fb97780Smrg	  continue
72663fb97780Smrg	  ;;
7267d656433aSmrg	xcclinker)
72683c15da26Smrg	  func_append linker_flags " $qarg"
72693c15da26Smrg	  func_append compiler_flags " $qarg"
7270d656433aSmrg	  prev=
7271d656433aSmrg	  func_append compile_command " $qarg"
7272d656433aSmrg	  func_append finalize_command " $qarg"
7273d656433aSmrg	  continue
7274d656433aSmrg	  ;;
7275d656433aSmrg	xcompiler)
72763c15da26Smrg	  func_append compiler_flags " $qarg"
7277d656433aSmrg	  prev=
7278d656433aSmrg	  func_append compile_command " $qarg"
7279d656433aSmrg	  func_append finalize_command " $qarg"
7280d656433aSmrg	  continue
7281d656433aSmrg	  ;;
7282d656433aSmrg	xlinker)
72833c15da26Smrg	  func_append linker_flags " $qarg"
72843c15da26Smrg	  func_append compiler_flags " $wl$qarg"
7285d656433aSmrg	  prev=
7286d656433aSmrg	  func_append compile_command " $wl$qarg"
7287d656433aSmrg	  func_append finalize_command " $wl$qarg"
7288d656433aSmrg	  continue
7289d656433aSmrg	  ;;
7290d656433aSmrg	*)
7291d656433aSmrg	  eval "$prev=\"\$arg\""
7292d656433aSmrg	  prev=
7293d656433aSmrg	  continue
7294d656433aSmrg	  ;;
7295126a8a12Smrg	esac
7296d656433aSmrg      fi # test -n "$prev"
7297126a8a12Smrg
7298300346aeSmrg      prevarg=$arg
7299126a8a12Smrg
7300d656433aSmrg      case $arg in
7301d656433aSmrg      -all-static)
7302d656433aSmrg	if test -n "$link_static_flag"; then
7303d656433aSmrg	  # See comment for -static flag below, for more details.
7304d656433aSmrg	  func_append compile_command " $link_static_flag"
7305d656433aSmrg	  func_append finalize_command " $link_static_flag"
7306d656433aSmrg	fi
7307d656433aSmrg	continue
7308d656433aSmrg	;;
7309126a8a12Smrg
7310d656433aSmrg      -allow-undefined)
7311d656433aSmrg	# FIXME: remove this flag sometime in the future.
7312300346aeSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7313d656433aSmrg	;;
7314126a8a12Smrg
7315d656433aSmrg      -avoid-version)
7316d656433aSmrg	avoid_version=yes
7317d656433aSmrg	continue
7318d656433aSmrg	;;
7319126a8a12Smrg
7320555991fdSmrg      -bindir)
7321555991fdSmrg	prev=bindir
7322555991fdSmrg	continue
7323555991fdSmrg	;;
7324555991fdSmrg
7325d656433aSmrg      -dlopen)
7326d656433aSmrg	prev=dlfiles
7327d656433aSmrg	continue
7328d656433aSmrg	;;
7329126a8a12Smrg
7330d656433aSmrg      -dlpreopen)
7331d656433aSmrg	prev=dlprefiles
7332d656433aSmrg	continue
7333d656433aSmrg	;;
7334126a8a12Smrg
7335d656433aSmrg      -export-dynamic)
7336d656433aSmrg	export_dynamic=yes
7337d656433aSmrg	continue
7338d656433aSmrg	;;
7339126a8a12Smrg
7340d656433aSmrg      -export-symbols | -export-symbols-regex)
7341d656433aSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7342d656433aSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7343d656433aSmrg	fi
7344300346aeSmrg	if test X-export-symbols = "X$arg"; then
7345d656433aSmrg	  prev=expsyms
7346d656433aSmrg	else
7347d656433aSmrg	  prev=expsyms_regex
7348d656433aSmrg	fi
7349d656433aSmrg	continue
7350d656433aSmrg	;;
7351126a8a12Smrg
7352d656433aSmrg      -framework)
7353d656433aSmrg	prev=framework
7354d656433aSmrg	continue
7355d656433aSmrg	;;
7356126a8a12Smrg
7357d656433aSmrg      -inst-prefix-dir)
7358d656433aSmrg	prev=inst_prefix
7359d656433aSmrg	continue
7360d656433aSmrg	;;
7361126a8a12Smrg
7362d656433aSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7363d656433aSmrg      # so, if we see these flags be careful not to treat them like -L
7364d656433aSmrg      -L[A-Z][A-Z]*:*)
7365d656433aSmrg	case $with_gcc/$host in
7366d656433aSmrg	no/*-*-irix* | /*-*-irix*)
7367d656433aSmrg	  func_append compile_command " $arg"
7368d656433aSmrg	  func_append finalize_command " $arg"
7369d656433aSmrg	  ;;
7370d656433aSmrg	esac
7371d656433aSmrg	continue
7372d656433aSmrg	;;
7373126a8a12Smrg
7374d656433aSmrg      -L*)
73753c15da26Smrg	func_stripname "-L" '' "$arg"
73763c15da26Smrg	if test -z "$func_stripname_result"; then
7377d656433aSmrg	  if test "$#" -gt 0; then
7378300346aeSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7379d656433aSmrg	  else
7380300346aeSmrg	    func_fatal_error "need path for '-L' option"
7381d656433aSmrg	  fi
7382d656433aSmrg	fi
73833c15da26Smrg	func_resolve_sysroot "$func_stripname_result"
73843c15da26Smrg	dir=$func_resolve_sysroot_result
7385d656433aSmrg	# We need an absolute path.
7386d656433aSmrg	case $dir in
7387d656433aSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7388d656433aSmrg	*)
7389d656433aSmrg	  absdir=`cd "$dir" && pwd`
7390d656433aSmrg	  test -z "$absdir" && \
7391300346aeSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7392300346aeSmrg	  dir=$absdir
7393d656433aSmrg	  ;;
7394d656433aSmrg	esac
7395d656433aSmrg	case "$deplibs " in
73963c15da26Smrg	*" -L$dir "* | *" $arg "*)
73973c15da26Smrg	  # Will only happen for absolute or sysroot arguments
73983c15da26Smrg	  ;;
7399d656433aSmrg	*)
74003c15da26Smrg	  # Preserve sysroot, but never include relative directories
74013c15da26Smrg	  case $dir in
74023c15da26Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
74033c15da26Smrg	    *) func_append deplibs " -L$dir" ;;
74043c15da26Smrg	  esac
74053c15da26Smrg	  func_append lib_search_path " $dir"
7406d656433aSmrg	  ;;
7407d656433aSmrg	esac
7408d656433aSmrg	case $host in
74096bea0e4fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
7410555991fdSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7411d656433aSmrg	  case :$dllsearchpath: in
7412d656433aSmrg	  *":$dir:"*) ;;
7413d656433aSmrg	  ::) dllsearchpath=$dir;;
74143c15da26Smrg	  *) func_append dllsearchpath ":$dir";;
7415d656433aSmrg	  esac
7416d656433aSmrg	  case :$dllsearchpath: in
7417d656433aSmrg	  *":$testbindir:"*) ;;
7418d656433aSmrg	  ::) dllsearchpath=$testbindir;;
74193c15da26Smrg	  *) func_append dllsearchpath ":$testbindir";;
7420d656433aSmrg	  esac
7421d656433aSmrg	  ;;
7422d656433aSmrg	esac
7423d656433aSmrg	continue
7424d656433aSmrg	;;
7425126a8a12Smrg
7426d656433aSmrg      -l*)
7427300346aeSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7428d656433aSmrg	  case $host in
74296bea0e4fSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7430d656433aSmrg	    # These systems don't actually have a C or math library (as such)
7431d656433aSmrg	    continue
7432d656433aSmrg	    ;;
7433d656433aSmrg	  *-*-os2*)
7434d656433aSmrg	    # These systems don't actually have a C library (as such)
7435300346aeSmrg	    test X-lc = "X$arg" && continue
7436d656433aSmrg	    ;;
74376bea0e4fSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7438d656433aSmrg	    # Do not include libc due to us having libc/libc_r.
7439300346aeSmrg	    test X-lc = "X$arg" && continue
7440d656433aSmrg	    ;;
7441d656433aSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
7442d656433aSmrg	    # Rhapsody C and math libraries are in the System framework
74433c15da26Smrg	    func_append deplibs " System.ltframework"
7444d656433aSmrg	    continue
7445d656433aSmrg	    ;;
7446d656433aSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7447d656433aSmrg	    # Causes problems with __ctype
7448300346aeSmrg	    test X-lc = "X$arg" && continue
7449d656433aSmrg	    ;;
7450d656433aSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7451d656433aSmrg	    # Compiler inserts libc in the correct place for threads to work
7452300346aeSmrg	    test X-lc = "X$arg" && continue
7453d656433aSmrg	    ;;
7454d656433aSmrg	  esac
7455300346aeSmrg	elif test X-lc_r = "X$arg"; then
7456d656433aSmrg	 case $host in
74576bea0e4fSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7458d656433aSmrg	   # Do not include libc_r directly, use -pthread flag.
7459d656433aSmrg	   continue
7460d656433aSmrg	   ;;
7461d656433aSmrg	 esac
7462d656433aSmrg	fi
74633c15da26Smrg	func_append deplibs " $arg"
7464d656433aSmrg	continue
7465d656433aSmrg	;;
7466126a8a12Smrg
7467300346aeSmrg      -mllvm)
7468300346aeSmrg	prev=mllvm
7469300346aeSmrg	continue
7470300346aeSmrg	;;
7471300346aeSmrg
7472d656433aSmrg      -module)
7473d656433aSmrg	module=yes
7474d656433aSmrg	continue
7475d656433aSmrg	;;
7476126a8a12Smrg
7477d656433aSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7478d656433aSmrg      # classes, name mangling, and exception handling.
7479d656433aSmrg      # Darwin uses the -arch flag to determine output architecture.
74806bea0e4fSmrg      # -q <option> for IBM XL C/C++ compiler.
74816bea0e4fSmrg      -model|-arch|-isysroot|--sysroot|-q)
74823c15da26Smrg	func_append compiler_flags " $arg"
7483d656433aSmrg	func_append compile_command " $arg"
7484d656433aSmrg	func_append finalize_command " $arg"
7485d656433aSmrg	prev=xcompiler
7486d656433aSmrg	continue
7487d656433aSmrg	;;
74883fb97780Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
74893fb97780Smrg     -pthread)
74903fb97780Smrg	case $host in
74913fb97780Smrg	  *solaris2*) ;;
74923fb97780Smrg	  *)
74933fb97780Smrg	    case "$new_inherited_linker_flags " in
74943fb97780Smrg	        *" $arg "*) ;;
74953fb97780Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
74963fb97780Smrg	    esac
74973fb97780Smrg	  ;;
74983fb97780Smrg	esac
74993fb97780Smrg	continue
75003fb97780Smrg	;;
75013fb97780Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
75026bea0e4fSmrg      |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
75033c15da26Smrg	func_append compiler_flags " $arg"
7504d656433aSmrg	func_append compile_command " $arg"
7505d656433aSmrg	func_append finalize_command " $arg"
7506d656433aSmrg	case "$new_inherited_linker_flags " in
7507d656433aSmrg	    *" $arg "*) ;;
75083c15da26Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7509d656433aSmrg	esac
7510d656433aSmrg	continue
7511d656433aSmrg	;;
7512126a8a12Smrg
7513d656433aSmrg      -multi_module)
7514300346aeSmrg	single_module=$wl-multi_module
7515d656433aSmrg	continue
7516d656433aSmrg	;;
7517126a8a12Smrg
7518d656433aSmrg      -no-fast-install)
7519d656433aSmrg	fast_install=no
7520d656433aSmrg	continue
7521d656433aSmrg	;;
7522126a8a12Smrg
7523d656433aSmrg      -no-install)
7524d656433aSmrg	case $host in
75256bea0e4fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7526d656433aSmrg	  # The PATH hackery in wrapper scripts is required on Windows
7527d656433aSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7528300346aeSmrg	  func_warning "'-no-install' is ignored for $host"
7529300346aeSmrg	  func_warning "assuming '-no-fast-install' instead"
7530d656433aSmrg	  fast_install=no
7531d656433aSmrg	  ;;
7532d656433aSmrg	*) no_install=yes ;;
7533d656433aSmrg	esac
7534d656433aSmrg	continue
7535d656433aSmrg	;;
7536126a8a12Smrg
7537d656433aSmrg      -no-undefined)
7538d656433aSmrg	allow_undefined=no
7539d656433aSmrg	continue
7540d656433aSmrg	;;
7541126a8a12Smrg
7542d656433aSmrg      -objectlist)
7543d656433aSmrg	prev=objectlist
7544d656433aSmrg	continue
7545d656433aSmrg	;;
7546126a8a12Smrg
7547300346aeSmrg      -os2dllname)
7548300346aeSmrg	prev=os2dllname
7549300346aeSmrg	continue
7550300346aeSmrg	;;
7551300346aeSmrg
7552d656433aSmrg      -o) prev=output ;;
7553126a8a12Smrg
7554d656433aSmrg      -precious-files-regex)
7555d656433aSmrg	prev=precious_regex
7556d656433aSmrg	continue
7557d656433aSmrg	;;
7558126a8a12Smrg
7559d656433aSmrg      -release)
7560d656433aSmrg	prev=release
7561d656433aSmrg	continue
7562d656433aSmrg	;;
7563126a8a12Smrg
7564d656433aSmrg      -rpath)
7565d656433aSmrg	prev=rpath
7566d656433aSmrg	continue
7567d656433aSmrg	;;
7568126a8a12Smrg
7569d656433aSmrg      -R)
7570d656433aSmrg	prev=xrpath
7571d656433aSmrg	continue
7572d656433aSmrg	;;
7573126a8a12Smrg
7574d656433aSmrg      -R*)
7575d656433aSmrg	func_stripname '-R' '' "$arg"
7576d656433aSmrg	dir=$func_stripname_result
7577d656433aSmrg	# We need an absolute path.
7578d656433aSmrg	case $dir in
7579d656433aSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
75803c15da26Smrg	=*)
75813c15da26Smrg	  func_stripname '=' '' "$dir"
75823c15da26Smrg	  dir=$lt_sysroot$func_stripname_result
75833c15da26Smrg	  ;;
7584d656433aSmrg	*)
75856bea0e4fSmrg	  func_fatal_error "argument ($arg) to '-R' is not an absolute path: $dir"
7586d656433aSmrg	  ;;
7587d656433aSmrg	esac
7588d656433aSmrg	case "$xrpath " in
7589d656433aSmrg	*" $dir "*) ;;
75903c15da26Smrg	*) func_append xrpath " $dir" ;;
7591d656433aSmrg	esac
7592d656433aSmrg	continue
7593d656433aSmrg	;;
7594126a8a12Smrg
7595d656433aSmrg      -shared)
7596d656433aSmrg	# The effects of -shared are defined in a previous loop.
7597d656433aSmrg	continue
7598d656433aSmrg	;;
7599126a8a12Smrg
7600d656433aSmrg      -shrext)
7601d656433aSmrg	prev=shrext
7602d656433aSmrg	continue
7603d656433aSmrg	;;
7604126a8a12Smrg
7605d656433aSmrg      -static | -static-libtool-libs)
7606d656433aSmrg	# The effects of -static are defined in a previous loop.
7607d656433aSmrg	# We used to do the same as -all-static on platforms that
7608d656433aSmrg	# didn't have a PIC flag, but the assumption that the effects
7609d656433aSmrg	# would be equivalent was wrong.  It would break on at least
7610d656433aSmrg	# Digital Unix and AIX.
7611d656433aSmrg	continue
7612d656433aSmrg	;;
7613126a8a12Smrg
7614d656433aSmrg      -thread-safe)
7615d656433aSmrg	thread_safe=yes
7616d656433aSmrg	continue
7617d656433aSmrg	;;
7618126a8a12Smrg
7619d656433aSmrg      -version-info)
7620d656433aSmrg	prev=vinfo
7621d656433aSmrg	continue
7622d656433aSmrg	;;
7623126a8a12Smrg
7624d656433aSmrg      -version-number)
7625d656433aSmrg	prev=vinfo
7626d656433aSmrg	vinfo_number=yes
7627d656433aSmrg	continue
7628d656433aSmrg	;;
7629126a8a12Smrg
7630d656433aSmrg      -weak)
7631d656433aSmrg        prev=weak
7632d656433aSmrg	continue
7633d656433aSmrg	;;
7634126a8a12Smrg
7635d656433aSmrg      -Wc,*)
7636d656433aSmrg	func_stripname '-Wc,' '' "$arg"
7637d656433aSmrg	args=$func_stripname_result
7638d656433aSmrg	arg=
7639300346aeSmrg	save_ifs=$IFS; IFS=,
7640d656433aSmrg	for flag in $args; do
7641300346aeSmrg	  IFS=$save_ifs
76423fb97780Smrg          func_quote_arg pretty "$flag"
76433fb97780Smrg	  func_append arg " $func_quote_arg_result"
76443fb97780Smrg	  func_append compiler_flags " $func_quote_arg_result"
7645d656433aSmrg	done
7646300346aeSmrg	IFS=$save_ifs
7647d656433aSmrg	func_stripname ' ' '' "$arg"
7648d656433aSmrg	arg=$func_stripname_result
7649d656433aSmrg	;;
7650126a8a12Smrg
7651d656433aSmrg      -Wl,*)
7652d656433aSmrg	func_stripname '-Wl,' '' "$arg"
7653d656433aSmrg	args=$func_stripname_result
7654d656433aSmrg	arg=
7655300346aeSmrg	save_ifs=$IFS; IFS=,
7656d656433aSmrg	for flag in $args; do
7657300346aeSmrg	  IFS=$save_ifs
76583fb97780Smrg          func_quote_arg pretty "$flag"
76593fb97780Smrg	  func_append arg " $wl$func_quote_arg_result"
76603fb97780Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
76613fb97780Smrg	  func_append linker_flags " $func_quote_arg_result"
7662d656433aSmrg	done
7663300346aeSmrg	IFS=$save_ifs
7664d656433aSmrg	func_stripname ' ' '' "$arg"
7665d656433aSmrg	arg=$func_stripname_result
7666d656433aSmrg	;;
7667126a8a12Smrg
76683fb97780Smrg      -Xassembler)
76693fb97780Smrg        prev=xassembler
76703fb97780Smrg        continue
76713fb97780Smrg        ;;
76723fb97780Smrg
7673d656433aSmrg      -Xcompiler)
7674d656433aSmrg	prev=xcompiler
7675d656433aSmrg	continue
7676d656433aSmrg	;;
7677126a8a12Smrg
7678d656433aSmrg      -Xlinker)
7679d656433aSmrg	prev=xlinker
7680d656433aSmrg	continue
7681d656433aSmrg	;;
7682126a8a12Smrg
7683d656433aSmrg      -XCClinker)
7684d656433aSmrg	prev=xcclinker
7685d656433aSmrg	continue
7686d656433aSmrg	;;
7687126a8a12Smrg
7688d656433aSmrg      # -msg_* for osf cc
7689d656433aSmrg      -msg_*)
76903fb97780Smrg	func_quote_arg pretty "$arg"
76913fb97780Smrg	arg=$func_quote_arg_result
7692d656433aSmrg	;;
7693126a8a12Smrg
7694555991fdSmrg      # Flags to be passed through unchanged, with rationale:
7695555991fdSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7696555991fdSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7697555991fdSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7698555991fdSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7699555991fdSmrg      # -q*                  compiler args for the IBM compiler
7700555991fdSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7701555991fdSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7702555991fdSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7703300346aeSmrg      # -fstack-protector*   stack protector flags for GCC
7704555991fdSmrg      # @file                GCC response files
7705555991fdSmrg      # -tp=*                Portland pgcc target processor selection
77063c15da26Smrg      # --sysroot=*          for sysroot support
7707300346aeSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7708300346aeSmrg      # -specs=*             GCC specs files
7709300346aeSmrg      # -stdlib=*            select c++ std lib with clang
77106bea0e4fSmrg      # -fdiagnostics-color* simply affects output
77116bea0e4fSmrg      # -frecord-gcc-switches used to verify flags were respected
7712300346aeSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
77136bea0e4fSmrg      # -fno-sanitize*       Clang/GCC memory and address sanitizer
77146bea0e4fSmrg      # -shared-libsan       Link with shared sanitizer runtimes (Clang)
77156bea0e4fSmrg      # -static-libsan       Link with static sanitizer runtimes (Clang)
77166bea0e4fSmrg      # -no-canonical-prefixes Do not expand any symbolic links
77173fb97780Smrg      # -fuse-ld=*           Linker select flags for GCC
77186bea0e4fSmrg      # -static-*            direct GCC to link specific libraries statically
77196bea0e4fSmrg      # -fcilkplus           Cilk Plus language extension features for C/C++
77206bea0e4fSmrg      # -rtlib=*             select c runtime lib with clang
77216bea0e4fSmrg      # --unwindlib=*        select unwinder library with clang
77226bea0e4fSmrg      # -f{file|debug|macro|profile}-prefix-map=* needed for lto linking
77233fb97780Smrg      # -Wa,*                Pass flags directly to the assembler
77246bea0e4fSmrg      # -Werror, -Werror=*   Report (specified) warnings as errors
7725d656433aSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
77263c15da26Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
77276bea0e4fSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
77286bea0e4fSmrg      -stdlib=*|-rtlib=*|--unwindlib=*| \
77296bea0e4fSmrg      -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
77306bea0e4fSmrg      -ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \
77316bea0e4fSmrg      -fdiagnostics-color*|-frecord-gcc-switches| \
77326bea0e4fSmrg      -fuse-ld=*|-static-*|-fcilkplus|-Wa,*|-Werror|-Werror=*)
77333fb97780Smrg        func_quote_arg pretty "$arg"
77343fb97780Smrg	arg=$func_quote_arg_result
7735d656433aSmrg        func_append compile_command " $arg"
7736d656433aSmrg        func_append finalize_command " $arg"
77373c15da26Smrg        func_append compiler_flags " $arg"
7738d656433aSmrg        continue
7739d656433aSmrg        ;;
7740126a8a12Smrg
7741300346aeSmrg      -Z*)
7742300346aeSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7743300346aeSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7744300346aeSmrg	  compiler_flags="$compiler_flags $arg"
7745300346aeSmrg	  func_append compile_command " $arg"
7746300346aeSmrg	  func_append finalize_command " $arg"
7747300346aeSmrg	  case $arg in
7748300346aeSmrg	  -Zlinker | -Zstack)
7749300346aeSmrg	    prev=xcompiler
7750300346aeSmrg	    ;;
7751300346aeSmrg	  esac
7752300346aeSmrg	  continue
7753300346aeSmrg        else
7754300346aeSmrg	  # Otherwise treat like 'Some other compiler flag' below
77553fb97780Smrg	  func_quote_arg pretty "$arg"
77563fb97780Smrg	  arg=$func_quote_arg_result
7757300346aeSmrg        fi
7758300346aeSmrg	;;
7759300346aeSmrg
7760d656433aSmrg      # Some other compiler flag.
7761d656433aSmrg      -* | +*)
77623fb97780Smrg        func_quote_arg pretty "$arg"
77633fb97780Smrg	arg=$func_quote_arg_result
7764d656433aSmrg	;;
7765126a8a12Smrg
7766d656433aSmrg      *.$objext)
7767d656433aSmrg	# A standard object.
77683c15da26Smrg	func_append objs " $arg"
7769d656433aSmrg	;;
7770d656433aSmrg
7771d656433aSmrg      *.lo)
7772d656433aSmrg	# A libtool-controlled object.
7773d656433aSmrg
7774d656433aSmrg	# Check to see that this really is a libtool object.
7775d656433aSmrg	if func_lalib_unsafe_p "$arg"; then
7776d656433aSmrg	  pic_object=
7777d656433aSmrg	  non_pic_object=
7778d656433aSmrg
7779d656433aSmrg	  # Read the .lo file
7780d656433aSmrg	  func_source "$arg"
7781d656433aSmrg
7782d656433aSmrg	  if test -z "$pic_object" ||
7783d656433aSmrg	     test -z "$non_pic_object" ||
7784300346aeSmrg	     test none = "$pic_object" &&
7785300346aeSmrg	     test none = "$non_pic_object"; then
7786300346aeSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7787d656433aSmrg	  fi
7788d656433aSmrg
7789d656433aSmrg	  # Extract subdirectory from the argument.
7790d656433aSmrg	  func_dirname "$arg" "/" ""
7791300346aeSmrg	  xdir=$func_dirname_result
7792d656433aSmrg
7793300346aeSmrg	  test none = "$pic_object" || {
7794d656433aSmrg	    # Prepend the subdirectory the object is found in.
7795300346aeSmrg	    pic_object=$xdir$pic_object
7796d656433aSmrg
7797300346aeSmrg	    if test dlfiles = "$prev"; then
7798300346aeSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
77993c15da26Smrg		func_append dlfiles " $pic_object"
7800d656433aSmrg		prev=
7801d656433aSmrg		continue
7802d656433aSmrg	      else
7803d656433aSmrg		# If libtool objects are unsupported, then we need to preload.
7804d656433aSmrg		prev=dlprefiles
7805d656433aSmrg	      fi
7806d656433aSmrg	    fi
7807d656433aSmrg
7808d656433aSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7809300346aeSmrg	    if test dlprefiles = "$prev"; then
7810d656433aSmrg	      # Preload the old-style object.
78113c15da26Smrg	      func_append dlprefiles " $pic_object"
7812d656433aSmrg	      prev=
7813d656433aSmrg	    fi
7814d656433aSmrg
7815d656433aSmrg	    # A PIC object.
7816d656433aSmrg	    func_append libobjs " $pic_object"
7817300346aeSmrg	    arg=$pic_object
7818300346aeSmrg	  }
7819d656433aSmrg
7820d656433aSmrg	  # Non-PIC object.
7821300346aeSmrg	  if test none != "$non_pic_object"; then
7822d656433aSmrg	    # Prepend the subdirectory the object is found in.
7823300346aeSmrg	    non_pic_object=$xdir$non_pic_object
7824d656433aSmrg
7825d656433aSmrg	    # A standard non-PIC object
7826d656433aSmrg	    func_append non_pic_objects " $non_pic_object"
7827300346aeSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7828300346aeSmrg	      arg=$non_pic_object
7829d656433aSmrg	    fi
7830d656433aSmrg	  else
7831d656433aSmrg	    # If the PIC object exists, use it instead.
7832d656433aSmrg	    # $xdir was prepended to $pic_object above.
7833300346aeSmrg	    non_pic_object=$pic_object
7834d656433aSmrg	    func_append non_pic_objects " $non_pic_object"
7835d656433aSmrg	  fi
7836d656433aSmrg	else
7837d656433aSmrg	  # Only an error if not doing a dry-run.
7838d656433aSmrg	  if $opt_dry_run; then
7839d656433aSmrg	    # Extract subdirectory from the argument.
7840d656433aSmrg	    func_dirname "$arg" "/" ""
7841300346aeSmrg	    xdir=$func_dirname_result
7842d656433aSmrg
7843d656433aSmrg	    func_lo2o "$arg"
7844d656433aSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
7845d656433aSmrg	    non_pic_object=$xdir$func_lo2o_result
7846d656433aSmrg	    func_append libobjs " $pic_object"
7847d656433aSmrg	    func_append non_pic_objects " $non_pic_object"
7848d656433aSmrg	  else
7849300346aeSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7850d656433aSmrg	  fi
7851d656433aSmrg	fi
7852d656433aSmrg	;;
7853d656433aSmrg
7854d656433aSmrg      *.$libext)
7855d656433aSmrg	# An archive.
78563c15da26Smrg	func_append deplibs " $arg"
78573c15da26Smrg	func_append old_deplibs " $arg"
7858d656433aSmrg	continue
7859d656433aSmrg	;;
7860d656433aSmrg
7861d656433aSmrg      *.la)
7862d656433aSmrg	# A libtool-controlled library.
7863d656433aSmrg
78643c15da26Smrg	func_resolve_sysroot "$arg"
7865300346aeSmrg	if test dlfiles = "$prev"; then
7866d656433aSmrg	  # This library was specified with -dlopen.
78673c15da26Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7868d656433aSmrg	  prev=
7869300346aeSmrg	elif test dlprefiles = "$prev"; then
7870d656433aSmrg	  # The library was specified with -dlpreopen.
78713c15da26Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7872d656433aSmrg	  prev=
7873d656433aSmrg	else
78743c15da26Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7875d656433aSmrg	fi
7876d656433aSmrg	continue
7877d656433aSmrg	;;
7878d656433aSmrg
7879d656433aSmrg      # Some other compiler argument.
7880d656433aSmrg      *)
7881d656433aSmrg	# Unknown arguments in both finalize_command and compile_command need
7882d656433aSmrg	# to be aesthetically quoted because they are evaled later.
78833fb97780Smrg	func_quote_arg pretty "$arg"
78843fb97780Smrg	arg=$func_quote_arg_result
7885d656433aSmrg	;;
7886d656433aSmrg      esac # arg
7887d656433aSmrg
7888d656433aSmrg      # Now actually substitute the argument into the commands.
7889d656433aSmrg      if test -n "$arg"; then
78906bea0e4fSmrg	if test -n "$rpath_arg"; then
78916bea0e4fSmrg          func_append finalize_rpath " ${arg##*,}"
78926bea0e4fSmrg	  unset rpath_arg
78936bea0e4fSmrg	else
78946bea0e4fSmrg	  case $arg in
78956bea0e4fSmrg          -Wl,-rpath,*)
78966bea0e4fSmrg	    func_append finalize_rpath " ${arg##*,}";;
78976bea0e4fSmrg          -Wl,-rpath)
78986bea0e4fSmrg	    rpath_arg=1;;
78996bea0e4fSmrg          *)
79006bea0e4fSmrg            func_append compile_command " $arg"
79016bea0e4fSmrg	    func_append finalize_command " $arg"
79026bea0e4fSmrg	  esac
79036bea0e4fSmrg        fi
7904d656433aSmrg      fi
7905d656433aSmrg    done # argument parsing loop
7906d656433aSmrg
7907d656433aSmrg    test -n "$prev" && \
7908300346aeSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7909d656433aSmrg
7910300346aeSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7911d656433aSmrg      eval arg=\"$export_dynamic_flag_spec\"
7912d656433aSmrg      func_append compile_command " $arg"
7913d656433aSmrg      func_append finalize_command " $arg"
7914d656433aSmrg    fi
7915d656433aSmrg
7916d656433aSmrg    oldlibs=
7917d656433aSmrg    # calculate the name of the file, without its directory
7918d656433aSmrg    func_basename "$output"
7919300346aeSmrg    outputname=$func_basename_result
7920300346aeSmrg    libobjs_save=$libobjs
7921d656433aSmrg
7922d656433aSmrg    if test -n "$shlibpath_var"; then
7923d656433aSmrg      # get the directories listed in $shlibpath_var
7924300346aeSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7925126a8a12Smrg    else
7926d656433aSmrg      shlib_search_path=
7927126a8a12Smrg    fi
7928d656433aSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7929d656433aSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7930126a8a12Smrg
7931300346aeSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7932300346aeSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7933300346aeSmrg
7934d656433aSmrg    func_dirname "$output" "/" ""
7935300346aeSmrg    output_objdir=$func_dirname_result$objdir
79363c15da26Smrg    func_to_tool_file "$output_objdir/"
79373c15da26Smrg    tool_output_objdir=$func_to_tool_file_result
7938d656433aSmrg    # Create the object directory.
7939d656433aSmrg    func_mkdir_p "$output_objdir"
7940126a8a12Smrg
7941d656433aSmrg    # Determine the type of output
7942d656433aSmrg    case $output in
7943d656433aSmrg    "")
7944d656433aSmrg      func_fatal_help "you must specify an output file"
7945d656433aSmrg      ;;
7946d656433aSmrg    *.$libext) linkmode=oldlib ;;
7947d656433aSmrg    *.lo | *.$objext) linkmode=obj ;;
7948d656433aSmrg    *.la) linkmode=lib ;;
7949d656433aSmrg    *) linkmode=prog ;; # Anything else should be a program.
7950d656433aSmrg    esac
7951d656433aSmrg
7952d656433aSmrg    specialdeplibs=
7953d656433aSmrg
7954d656433aSmrg    libs=
7955d656433aSmrg    # Find all interdependent deplibs by searching for libraries
7956d656433aSmrg    # that are linked more than once (e.g. -la -lb -la)
7957d656433aSmrg    for deplib in $deplibs; do
7958300346aeSmrg      if $opt_preserve_dup_deps; then
7959d656433aSmrg	case "$libs " in
79603c15da26Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7961d656433aSmrg	esac
7962d656433aSmrg      fi
79633c15da26Smrg      func_append libs " $deplib"
7964d656433aSmrg    done
7965d656433aSmrg
7966300346aeSmrg    if test lib = "$linkmode"; then
7967d656433aSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7968d656433aSmrg
7969d656433aSmrg      # Compute libraries that are listed more than once in $predeps
7970d656433aSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
7971d656433aSmrg      # not to be eliminated).
7972d656433aSmrg      pre_post_deps=
7973d656433aSmrg      if $opt_duplicate_compiler_generated_deps; then
7974d656433aSmrg	for pre_post_dep in $predeps $postdeps; do
7975d656433aSmrg	  case "$pre_post_deps " in
79763c15da26Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7977d656433aSmrg	  esac
79783c15da26Smrg	  func_append pre_post_deps " $pre_post_dep"
7979d656433aSmrg	done
7980d656433aSmrg      fi
7981d656433aSmrg      pre_post_deps=
7982d656433aSmrg    fi
7983d656433aSmrg
7984d656433aSmrg    deplibs=
7985d656433aSmrg    newdependency_libs=
7986d656433aSmrg    newlib_search_path=
7987d656433aSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7988d656433aSmrg    notinst_deplibs= # not-installed libtool libraries
7989d656433aSmrg    notinst_path= # paths that contain not-installed libtool libraries
7990d656433aSmrg
7991d656433aSmrg    case $linkmode in
7992d656433aSmrg    lib)
7993d656433aSmrg	passes="conv dlpreopen link"
7994d656433aSmrg	for file in $dlfiles $dlprefiles; do
7995d656433aSmrg	  case $file in
7996d656433aSmrg	  *.la) ;;
7997d656433aSmrg	  *)
7998300346aeSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7999d656433aSmrg	    ;;
8000d656433aSmrg	  esac
8001d656433aSmrg	done
8002d656433aSmrg	;;
8003d656433aSmrg    prog)
8004d656433aSmrg	compile_deplibs=
8005d656433aSmrg	finalize_deplibs=
8006300346aeSmrg	alldeplibs=false
8007d656433aSmrg	newdlfiles=
8008d656433aSmrg	newdlprefiles=
8009d656433aSmrg	passes="conv scan dlopen dlpreopen link"
8010d656433aSmrg	;;
8011d656433aSmrg    *)  passes="conv"
8012d656433aSmrg	;;
8013d656433aSmrg    esac
8014d656433aSmrg
8015d656433aSmrg    for pass in $passes; do
8016d656433aSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
8017d656433aSmrg      # so that -L comes before libs that need it for instance...
8018300346aeSmrg      if test lib,link = "$linkmode,$pass"; then
8019d656433aSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
8020d656433aSmrg	##        order, and fix it there properly
8021d656433aSmrg        tmp_deplibs=
8022d656433aSmrg	for deplib in $deplibs; do
8023d656433aSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
8024d656433aSmrg	done
8025300346aeSmrg	deplibs=$tmp_deplibs
8026d656433aSmrg      fi
8027d656433aSmrg
8028300346aeSmrg      if test lib,link = "$linkmode,$pass" ||
8029300346aeSmrg	 test prog,scan = "$linkmode,$pass"; then
8030300346aeSmrg	libs=$deplibs
8031d656433aSmrg	deplibs=
8032d656433aSmrg      fi
8033300346aeSmrg      if test prog = "$linkmode"; then
8034d656433aSmrg	case $pass in
8035300346aeSmrg	dlopen) libs=$dlfiles ;;
8036300346aeSmrg	dlpreopen) libs=$dlprefiles ;;
80373fb97780Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
8038d656433aSmrg	esac
8039d656433aSmrg      fi
8040300346aeSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
8041d656433aSmrg	# Collect and forward deplibs of preopened libtool libs
8042d656433aSmrg	for lib in $dlprefiles; do
8043d656433aSmrg	  # Ignore non-libtool-libs
8044d656433aSmrg	  dependency_libs=
80453c15da26Smrg	  func_resolve_sysroot "$lib"
8046d656433aSmrg	  case $lib in
80473c15da26Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
8048d656433aSmrg	  esac
8049d656433aSmrg
8050d656433aSmrg	  # Collect preopened libtool deplibs, except any this library
8051d656433aSmrg	  # has declared as weak libs
8052d656433aSmrg	  for deplib in $dependency_libs; do
8053555991fdSmrg	    func_basename "$deplib"
8054555991fdSmrg            deplib_base=$func_basename_result
8055d656433aSmrg	    case " $weak_libs " in
8056d656433aSmrg	    *" $deplib_base "*) ;;
80573c15da26Smrg	    *) func_append deplibs " $deplib" ;;
8058d656433aSmrg	    esac
8059d656433aSmrg	  done
8060d656433aSmrg	done
8061300346aeSmrg	libs=$dlprefiles
8062d656433aSmrg      fi
8063300346aeSmrg      if test dlopen = "$pass"; then
8064d656433aSmrg	# Collect dlpreopened libraries
8065300346aeSmrg	save_deplibs=$deplibs
8066d656433aSmrg	deplibs=
8067d656433aSmrg      fi
8068d656433aSmrg
8069d656433aSmrg      for deplib in $libs; do
8070d656433aSmrg	lib=
8071300346aeSmrg	found=false
8072d656433aSmrg	case $deplib in
80730a6b08f8Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
80746bea0e4fSmrg        |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
8075300346aeSmrg	  if test prog,link = "$linkmode,$pass"; then
8076d656433aSmrg	    compile_deplibs="$deplib $compile_deplibs"
8077d656433aSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
8078d656433aSmrg	  else
80793c15da26Smrg	    func_append compiler_flags " $deplib"
8080300346aeSmrg	    if test lib = "$linkmode"; then
8081d656433aSmrg		case "$new_inherited_linker_flags " in
8082d656433aSmrg		    *" $deplib "*) ;;
80833c15da26Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8084d656433aSmrg		esac
8085d656433aSmrg	    fi
8086d656433aSmrg	  fi
8087d656433aSmrg	  continue
8088d656433aSmrg	  ;;
8089d656433aSmrg	-l*)
8090300346aeSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
8091300346aeSmrg	    func_warning "'-l' is ignored for archives/objects"
8092d656433aSmrg	    continue
8093d656433aSmrg	  fi
8094d656433aSmrg	  func_stripname '-l' '' "$deplib"
8095d656433aSmrg	  name=$func_stripname_result
8096300346aeSmrg	  if test lib = "$linkmode"; then
8097d656433aSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
8098d656433aSmrg	  else
8099d656433aSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
8100d656433aSmrg	  fi
8101d656433aSmrg	  for searchdir in $searchdirs; do
8102d656433aSmrg	    for search_ext in .la $std_shrext .so .a; do
8103d656433aSmrg	      # Search the libtool library
8104300346aeSmrg	      lib=$searchdir/lib$name$search_ext
8105d656433aSmrg	      if test -f "$lib"; then
8106300346aeSmrg		if test .la = "$search_ext"; then
8107300346aeSmrg		  found=:
8108d656433aSmrg		else
8109300346aeSmrg		  found=false
8110d656433aSmrg		fi
8111d656433aSmrg		break 2
8112d656433aSmrg	      fi
8113d656433aSmrg	    done
8114d656433aSmrg	  done
8115300346aeSmrg	  if $found; then
8116300346aeSmrg	    # deplib is a libtool library
8117d656433aSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
8118d656433aSmrg	    # We need to do some special things here, and not later.
8119300346aeSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
8120d656433aSmrg	      case " $predeps $postdeps " in
8121d656433aSmrg	      *" $deplib "*)
8122d656433aSmrg		if func_lalib_p "$lib"; then
8123d656433aSmrg		  library_names=
8124d656433aSmrg		  old_library=
8125d656433aSmrg		  func_source "$lib"
8126d656433aSmrg		  for l in $old_library $library_names; do
8127300346aeSmrg		    ll=$l
8128d656433aSmrg		  done
8129300346aeSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
8130300346aeSmrg		    found=false
8131d656433aSmrg		    func_dirname "$lib" "" "."
8132300346aeSmrg		    ladir=$func_dirname_result
8133d656433aSmrg		    lib=$ladir/$old_library
8134300346aeSmrg		    if test prog,link = "$linkmode,$pass"; then
8135d656433aSmrg		      compile_deplibs="$deplib $compile_deplibs"
8136d656433aSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
8137d656433aSmrg		    else
8138d656433aSmrg		      deplibs="$deplib $deplibs"
8139300346aeSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8140d656433aSmrg		    fi
8141d656433aSmrg		    continue
8142d656433aSmrg		  fi
8143d656433aSmrg		fi
8144d656433aSmrg		;;
8145d656433aSmrg	      *) ;;
8146d656433aSmrg	      esac
8147d656433aSmrg	    fi
8148300346aeSmrg	  else
8149300346aeSmrg	    # deplib doesn't seem to be a libtool library
8150300346aeSmrg	    if test prog,link = "$linkmode,$pass"; then
8151300346aeSmrg	      compile_deplibs="$deplib $compile_deplibs"
8152300346aeSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8153300346aeSmrg	    else
8154300346aeSmrg	      deplibs="$deplib $deplibs"
8155300346aeSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8156300346aeSmrg	    fi
8157300346aeSmrg	    continue
8158d656433aSmrg	  fi
8159d656433aSmrg	  ;; # -l
8160d656433aSmrg	*.ltframework)
8161300346aeSmrg	  if test prog,link = "$linkmode,$pass"; then
8162d656433aSmrg	    compile_deplibs="$deplib $compile_deplibs"
8163d656433aSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
8164d656433aSmrg	  else
8165d656433aSmrg	    deplibs="$deplib $deplibs"
8166300346aeSmrg	    if test lib = "$linkmode"; then
8167d656433aSmrg		case "$new_inherited_linker_flags " in
8168d656433aSmrg		    *" $deplib "*) ;;
81693c15da26Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8170d656433aSmrg		esac
8171d656433aSmrg	    fi
8172d656433aSmrg	  fi
8173d656433aSmrg	  continue
8174d656433aSmrg	  ;;
8175d656433aSmrg	-L*)
8176d656433aSmrg	  case $linkmode in
8177d656433aSmrg	  lib)
8178d656433aSmrg	    deplibs="$deplib $deplibs"
8179300346aeSmrg	    test conv = "$pass" && continue
8180d656433aSmrg	    newdependency_libs="$deplib $newdependency_libs"
8181d656433aSmrg	    func_stripname '-L' '' "$deplib"
81823c15da26Smrg	    func_resolve_sysroot "$func_stripname_result"
81833c15da26Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8184d656433aSmrg	    ;;
8185d656433aSmrg	  prog)
8186300346aeSmrg	    if test conv = "$pass"; then
8187d656433aSmrg	      deplibs="$deplib $deplibs"
8188d656433aSmrg	      continue
8189d656433aSmrg	    fi
8190300346aeSmrg	    if test scan = "$pass"; then
8191d656433aSmrg	      deplibs="$deplib $deplibs"
8192d656433aSmrg	    else
8193d656433aSmrg	      compile_deplibs="$deplib $compile_deplibs"
8194d656433aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8195d656433aSmrg	    fi
8196d656433aSmrg	    func_stripname '-L' '' "$deplib"
81973c15da26Smrg	    func_resolve_sysroot "$func_stripname_result"
81983c15da26Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8199d656433aSmrg	    ;;
8200d656433aSmrg	  *)
8201300346aeSmrg	    func_warning "'-L' is ignored for archives/objects"
8202d656433aSmrg	    ;;
8203d656433aSmrg	  esac # linkmode
8204d656433aSmrg	  continue
8205d656433aSmrg	  ;; # -L
8206d656433aSmrg	-R*)
8207300346aeSmrg	  if test link = "$pass"; then
8208d656433aSmrg	    func_stripname '-R' '' "$deplib"
82093c15da26Smrg	    func_resolve_sysroot "$func_stripname_result"
82103c15da26Smrg	    dir=$func_resolve_sysroot_result
8211d656433aSmrg	    # Make sure the xrpath contains only unique directories.
8212d656433aSmrg	    case "$xrpath " in
8213d656433aSmrg	    *" $dir "*) ;;
82143c15da26Smrg	    *) func_append xrpath " $dir" ;;
8215d656433aSmrg	    esac
8216d656433aSmrg	  fi
8217d656433aSmrg	  deplibs="$deplib $deplibs"
8218d656433aSmrg	  continue
8219d656433aSmrg	  ;;
82203c15da26Smrg	*.la)
82213c15da26Smrg	  func_resolve_sysroot "$deplib"
82223c15da26Smrg	  lib=$func_resolve_sysroot_result
82233c15da26Smrg	  ;;
8224d656433aSmrg	*.$libext)
8225300346aeSmrg	  if test conv = "$pass"; then
8226d656433aSmrg	    deplibs="$deplib $deplibs"
8227d656433aSmrg	    continue
8228d656433aSmrg	  fi
8229d656433aSmrg	  case $linkmode in
8230d656433aSmrg	  lib)
8231d656433aSmrg	    # Linking convenience modules into shared libraries is allowed,
8232d656433aSmrg	    # but linking other static libraries is non-portable.
8233d656433aSmrg	    case " $dlpreconveniencelibs " in
8234d656433aSmrg	    *" $deplib "*) ;;
8235d656433aSmrg	    *)
8236300346aeSmrg	      valid_a_lib=false
8237d656433aSmrg	      case $deplibs_check_method in
8238d656433aSmrg		match_pattern*)
8239d656433aSmrg		  set dummy $deplibs_check_method; shift
8240d656433aSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8241555991fdSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8242d656433aSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8243300346aeSmrg		    valid_a_lib=:
8244d656433aSmrg		  fi
8245d656433aSmrg		;;
8246d656433aSmrg		pass_all)
8247300346aeSmrg		  valid_a_lib=:
8248d656433aSmrg		;;
8249d656433aSmrg	      esac
8250300346aeSmrg	      if $valid_a_lib; then
82516bea0e4fSmrg		func_warning "Linking the shared library $output against the static library $deplib is not portable!"
8252300346aeSmrg		deplibs="$deplib $deplibs"
8253300346aeSmrg	      else
82546bea0e4fSmrg		func_warning "Trying to link with static lib archive $deplib."
82556bea0e4fSmrg		func_warning "I have the capability to make that library automatically link in when"
82566bea0e4fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
82576bea0e4fSmrg		func_warning "shared version of the library, which you do not appear to have"
82586bea0e4fSmrg		func_warning "because the file extensions .$libext of this argument makes me believe"
82596bea0e4fSmrg		func_warning "that it is just a static archive that I should not use here."
8260d656433aSmrg	      fi
8261d656433aSmrg	      ;;
8262d656433aSmrg	    esac
8263d656433aSmrg	    continue
8264d656433aSmrg	    ;;
8265d656433aSmrg	  prog)
8266300346aeSmrg	    if test link != "$pass"; then
8267d656433aSmrg	      deplibs="$deplib $deplibs"
8268d656433aSmrg	    else
8269d656433aSmrg	      compile_deplibs="$deplib $compile_deplibs"
8270d656433aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8271d656433aSmrg	    fi
8272d656433aSmrg	    continue
8273d656433aSmrg	    ;;
8274d656433aSmrg	  esac # linkmode
8275d656433aSmrg	  ;; # *.$libext
8276d656433aSmrg	*.lo | *.$objext)
8277300346aeSmrg	  if test conv = "$pass"; then
8278d656433aSmrg	    deplibs="$deplib $deplibs"
8279300346aeSmrg	  elif test prog = "$linkmode"; then
8280300346aeSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8281d656433aSmrg	      # If there is no dlopen support or we're linking statically,
8282d656433aSmrg	      # we need to preload.
82833c15da26Smrg	      func_append newdlprefiles " $deplib"
8284d656433aSmrg	      compile_deplibs="$deplib $compile_deplibs"
8285d656433aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8286d656433aSmrg	    else
82873c15da26Smrg	      func_append newdlfiles " $deplib"
8288d656433aSmrg	    fi
8289d656433aSmrg	  fi
8290d656433aSmrg	  continue
8291d656433aSmrg	  ;;
8292d656433aSmrg	%DEPLIBS%)
8293300346aeSmrg	  alldeplibs=:
8294d656433aSmrg	  continue
8295d656433aSmrg	  ;;
8296d656433aSmrg	esac # case $deplib
8297d656433aSmrg
8298300346aeSmrg	$found || test -f "$lib" \
8299300346aeSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8300d656433aSmrg
8301d656433aSmrg	# Check to see that this really is a libtool archive.
8302d656433aSmrg	func_lalib_unsafe_p "$lib" \
8303300346aeSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8304d656433aSmrg
8305d656433aSmrg	func_dirname "$lib" "" "."
8306300346aeSmrg	ladir=$func_dirname_result
8307d656433aSmrg
8308d656433aSmrg	dlname=
8309d656433aSmrg	dlopen=
8310d656433aSmrg	dlpreopen=
8311d656433aSmrg	libdir=
8312d656433aSmrg	library_names=
8313d656433aSmrg	old_library=
8314d656433aSmrg	inherited_linker_flags=
8315d656433aSmrg	# If the library was installed with an old release of libtool,
8316d656433aSmrg	# it will not redefine variables installed, or shouldnotlink
8317d656433aSmrg	installed=yes
8318d656433aSmrg	shouldnotlink=no
8319d656433aSmrg	avoidtemprpath=
8320d656433aSmrg
8321d656433aSmrg
8322d656433aSmrg	# Read the .la file
8323d656433aSmrg	func_source "$lib"
8324d656433aSmrg
8325d656433aSmrg	# Convert "-framework foo" to "foo.ltframework"
8326d656433aSmrg	if test -n "$inherited_linker_flags"; then
8327555991fdSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8328d656433aSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8329d656433aSmrg	    case " $new_inherited_linker_flags " in
8330d656433aSmrg	      *" $tmp_inherited_linker_flag "*) ;;
83313c15da26Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8332d656433aSmrg	    esac
8333d656433aSmrg	  done
8334d656433aSmrg	fi
8335555991fdSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8336300346aeSmrg	if test lib,link = "$linkmode,$pass" ||
8337300346aeSmrg	   test prog,scan = "$linkmode,$pass" ||
8338300346aeSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
83393c15da26Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
83403c15da26Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8341d656433aSmrg	fi
8342d656433aSmrg
8343300346aeSmrg	if test conv = "$pass"; then
8344d656433aSmrg	  # Only check for convenience libraries
8345d656433aSmrg	  deplibs="$lib $deplibs"
8346d656433aSmrg	  if test -z "$libdir"; then
8347d656433aSmrg	    if test -z "$old_library"; then
8348300346aeSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8349d656433aSmrg	    fi
8350d656433aSmrg	    # It is a libtool convenience library, so add in its objects.
83513c15da26Smrg	    func_append convenience " $ladir/$objdir/$old_library"
83523c15da26Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8353300346aeSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8354300346aeSmrg	    func_fatal_error "'$lib' is not a convenience library"
8355d656433aSmrg	  fi
83563fb97780Smrg	  tmp_libs=
83573fb97780Smrg	  for deplib in $dependency_libs; do
83583fb97780Smrg	    deplibs="$deplib $deplibs"
83593fb97780Smrg	    if $opt_preserve_dup_deps; then
83603fb97780Smrg	      case "$tmp_libs " in
83613fb97780Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83623fb97780Smrg	      esac
83633fb97780Smrg	    fi
83643fb97780Smrg	    func_append tmp_libs " $deplib"
83653fb97780Smrg	  done
8366d656433aSmrg	  continue
8367d656433aSmrg	fi # $pass = conv
8368d656433aSmrg
8369d656433aSmrg
8370d656433aSmrg	# Get the name of the library we link against.
8371d656433aSmrg	linklib=
83723c15da26Smrg	if test -n "$old_library" &&
8373300346aeSmrg	   { test yes = "$prefer_static_libs" ||
8374300346aeSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
83753c15da26Smrg	  linklib=$old_library
83763c15da26Smrg	else
83773c15da26Smrg	  for l in $old_library $library_names; do
8378300346aeSmrg	    linklib=$l
83793c15da26Smrg	  done
83803c15da26Smrg	fi
8381d656433aSmrg	if test -z "$linklib"; then
8382300346aeSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8383d656433aSmrg	fi
8384d656433aSmrg
8385d656433aSmrg	# This library was specified with -dlopen.
8386300346aeSmrg	if test dlopen = "$pass"; then
8387300346aeSmrg	  test -z "$libdir" \
8388300346aeSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8389d656433aSmrg	  if test -z "$dlname" ||
8390300346aeSmrg	     test yes != "$dlopen_support" ||
8391300346aeSmrg	     test no = "$build_libtool_libs"
8392300346aeSmrg	  then
8393d656433aSmrg	    # If there is no dlname, no dlopen support or we're linking
8394d656433aSmrg	    # statically, we need to preload.  We also need to preload any
8395d656433aSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
8396d656433aSmrg	    # bomb out in the load deplibs phase.
83973c15da26Smrg	    func_append dlprefiles " $lib $dependency_libs"
8398d656433aSmrg	  else
83993c15da26Smrg	    func_append newdlfiles " $lib"
8400d656433aSmrg	  fi
8401d656433aSmrg	  continue
8402d656433aSmrg	fi # $pass = dlopen
8403d656433aSmrg
8404d656433aSmrg	# We need an absolute path.
8405d656433aSmrg	case $ladir in
8406300346aeSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8407d656433aSmrg	*)
8408d656433aSmrg	  abs_ladir=`cd "$ladir" && pwd`
8409d656433aSmrg	  if test -z "$abs_ladir"; then
8410300346aeSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8411d656433aSmrg	    func_warning "passing it literally to the linker, although it might fail"
8412300346aeSmrg	    abs_ladir=$ladir
8413d656433aSmrg	  fi
8414d656433aSmrg	  ;;
8415d656433aSmrg	esac
8416d656433aSmrg	func_basename "$lib"
8417300346aeSmrg	laname=$func_basename_result
8418d656433aSmrg
8419d656433aSmrg	# Find the relevant object directory and library name.
8420300346aeSmrg	if test yes = "$installed"; then
84213c15da26Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8422300346aeSmrg	    func_warning "library '$lib' was moved."
8423300346aeSmrg	    dir=$ladir
8424300346aeSmrg	    absdir=$abs_ladir
8425300346aeSmrg	    libdir=$abs_ladir
8426d656433aSmrg	  else
8427300346aeSmrg	    dir=$lt_sysroot$libdir
8428300346aeSmrg	    absdir=$lt_sysroot$libdir
8429d656433aSmrg	  fi
8430300346aeSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8431d656433aSmrg	else
8432d656433aSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8433300346aeSmrg	    dir=$ladir
8434300346aeSmrg	    absdir=$abs_ladir
8435d656433aSmrg	    # Remove this search path later
84363c15da26Smrg	    func_append notinst_path " $abs_ladir"
8437d656433aSmrg	  else
8438300346aeSmrg	    dir=$ladir/$objdir
8439300346aeSmrg	    absdir=$abs_ladir/$objdir
8440d656433aSmrg	    # Remove this search path later
84413c15da26Smrg	    func_append notinst_path " $abs_ladir"
8442d656433aSmrg	  fi
8443d656433aSmrg	fi # $installed = yes
8444d656433aSmrg	func_stripname 'lib' '.la' "$laname"
8445d656433aSmrg	name=$func_stripname_result
8446d656433aSmrg
8447d656433aSmrg	# This library was specified with -dlpreopen.
8448300346aeSmrg	if test dlpreopen = "$pass"; then
8449300346aeSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8450300346aeSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8451d656433aSmrg	  fi
8452300346aeSmrg	  case $host in
84533c15da26Smrg	    # special handling for platforms with PE-DLLs.
84546bea0e4fSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
84553c15da26Smrg	      # Linker will automatically link against shared library if both
84563c15da26Smrg	      # static and shared are present.  Therefore, ensure we extract
84573c15da26Smrg	      # symbols from the import library if a shared library is present
84583c15da26Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
84593c15da26Smrg	      # this by putting the import library name into $newdlprefiles.
84603c15da26Smrg	      # We recover the dlopen module name by 'saving' the la file
84613c15da26Smrg	      # name in a special purpose variable, and (later) extracting the
84623c15da26Smrg	      # dlname from the la file.
84633c15da26Smrg	      if test -n "$dlname"; then
84643c15da26Smrg	        func_tr_sh "$dir/$linklib"
84653c15da26Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
84663c15da26Smrg	        func_append newdlprefiles " $dir/$linklib"
84673c15da26Smrg	      else
84683c15da26Smrg	        func_append newdlprefiles " $dir/$old_library"
84693c15da26Smrg	        # Keep a list of preopened convenience libraries to check
84703c15da26Smrg	        # that they are being used correctly in the link pass.
84713c15da26Smrg	        test -z "$libdir" && \
84723c15da26Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
84733c15da26Smrg	      fi
84743c15da26Smrg	    ;;
84753c15da26Smrg	    * )
84763c15da26Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
84773c15da26Smrg	      # are required to link).
84783c15da26Smrg	      if test -n "$old_library"; then
84793c15da26Smrg	        func_append newdlprefiles " $dir/$old_library"
84803c15da26Smrg	        # Keep a list of preopened convenience libraries to check
84813c15da26Smrg	        # that they are being used correctly in the link pass.
84823c15da26Smrg	        test -z "$libdir" && \
84833c15da26Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
84843c15da26Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
84853c15da26Smrg	      elif test -n "$dlname"; then
84863c15da26Smrg	        func_append newdlprefiles " $dir/$dlname"
84873c15da26Smrg	      else
84883c15da26Smrg	        func_append newdlprefiles " $dir/$linklib"
84893c15da26Smrg	      fi
84903c15da26Smrg	    ;;
84913c15da26Smrg	  esac
8492d656433aSmrg	fi # $pass = dlpreopen
8493d656433aSmrg
8494d656433aSmrg	if test -z "$libdir"; then
8495d656433aSmrg	  # Link the convenience library
8496300346aeSmrg	  if test lib = "$linkmode"; then
8497d656433aSmrg	    deplibs="$dir/$old_library $deplibs"
8498300346aeSmrg	  elif test prog,link = "$linkmode,$pass"; then
8499d656433aSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8500d656433aSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8501d656433aSmrg	  else
8502d656433aSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8503d656433aSmrg	  fi
8504d656433aSmrg	  continue
8505d656433aSmrg	fi
8506d656433aSmrg
8507d656433aSmrg
8508300346aeSmrg	if test prog = "$linkmode" && test link != "$pass"; then
85093c15da26Smrg	  func_append newlib_search_path " $ladir"
8510d656433aSmrg	  deplibs="$lib $deplibs"
8511d656433aSmrg
8512300346aeSmrg	  linkalldeplibs=false
8513300346aeSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8514300346aeSmrg	     test no = "$build_libtool_libs"; then
8515300346aeSmrg	    linkalldeplibs=:
8516d656433aSmrg	  fi
8517d656433aSmrg
8518d656433aSmrg	  tmp_libs=
8519d656433aSmrg	  for deplib in $dependency_libs; do
8520d656433aSmrg	    case $deplib in
8521d656433aSmrg	    -L*) func_stripname '-L' '' "$deplib"
85223c15da26Smrg	         func_resolve_sysroot "$func_stripname_result"
85233c15da26Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8524d656433aSmrg		 ;;
8525d656433aSmrg	    esac
8526d656433aSmrg	    # Need to link against all dependency_libs?
8527300346aeSmrg	    if $linkalldeplibs; then
8528d656433aSmrg	      deplibs="$deplib $deplibs"
8529d656433aSmrg	    else
8530d656433aSmrg	      # Need to hardcode shared library paths
8531d656433aSmrg	      # or/and link against static libraries
8532d656433aSmrg	      newdependency_libs="$deplib $newdependency_libs"
8533d656433aSmrg	    fi
8534300346aeSmrg	    if $opt_preserve_dup_deps; then
8535d656433aSmrg	      case "$tmp_libs " in
85363c15da26Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8537d656433aSmrg	      esac
8538d656433aSmrg	    fi
85393c15da26Smrg	    func_append tmp_libs " $deplib"
8540d656433aSmrg	  done # for deplib
8541d656433aSmrg	  continue
8542d656433aSmrg	fi # $linkmode = prog...
8543d656433aSmrg
8544300346aeSmrg	if test prog,link = "$linkmode,$pass"; then
8545d656433aSmrg	  if test -n "$library_names" &&
8546300346aeSmrg	     { { test no = "$prefer_static_libs" ||
8547300346aeSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8548d656433aSmrg	       test -z "$old_library"; }; then
8549d656433aSmrg	    # We need to hardcode the library path
8550300346aeSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8551d656433aSmrg	      # Make sure the rpath contains only unique directories.
8552300346aeSmrg	      case $temp_rpath: in
8553d656433aSmrg	      *"$absdir:"*) ;;
85546bea0e4fSmrg              *) case $absdir in
85556bea0e4fSmrg                 "$progdir/"*) func_append temp_rpath "$absdir:" ;;
85566bea0e4fSmrg                 *)            func_append temp_rpath_tail "$absdir:" ;;
85576bea0e4fSmrg                 esac
8558d656433aSmrg	      esac
8559d656433aSmrg	    fi
8560d656433aSmrg
8561d656433aSmrg	    # Hardcode the library path.
8562d656433aSmrg	    # Skip directories that are in the system default run-time
8563d656433aSmrg	    # search path.
8564d656433aSmrg	    case " $sys_lib_dlsearch_path " in
8565d656433aSmrg	    *" $absdir "*) ;;
8566d656433aSmrg	    *)
85676bea0e4fSmrg	      case "$compile_rpath$compile_rpath_tail " in
8568d656433aSmrg	      *" $absdir "*) ;;
85696bea0e4fSmrg	      *) case $absdir in
85706bea0e4fSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
85716bea0e4fSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
85726bea0e4fSmrg		 esac
8573d656433aSmrg	      esac
8574d656433aSmrg	      ;;
8575d656433aSmrg	    esac
8576d656433aSmrg	    case " $sys_lib_dlsearch_path " in
8577d656433aSmrg	    *" $libdir "*) ;;
8578d656433aSmrg	    *)
8579d656433aSmrg	      case "$finalize_rpath " in
8580d656433aSmrg	      *" $libdir "*) ;;
85813c15da26Smrg	      *) func_append finalize_rpath " $libdir" ;;
8582d656433aSmrg	      esac
8583d656433aSmrg	      ;;
8584d656433aSmrg	    esac
8585d656433aSmrg	  fi # $linkmode,$pass = prog,link...
8586d656433aSmrg
8587300346aeSmrg	  if $alldeplibs &&
8588300346aeSmrg	     { test pass_all = "$deplibs_check_method" ||
8589300346aeSmrg	       { test yes = "$build_libtool_libs" &&
8590d656433aSmrg		 test -n "$library_names"; }; }; then
8591d656433aSmrg	    # We only need to search for static libraries
8592d656433aSmrg	    continue
8593d656433aSmrg	  fi
8594d656433aSmrg	fi
8595d656433aSmrg
8596d656433aSmrg	link_static=no # Whether the deplib will be linked statically
8597d656433aSmrg	use_static_libs=$prefer_static_libs
8598300346aeSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8599d656433aSmrg	  use_static_libs=no
8600d656433aSmrg	fi
8601d656433aSmrg	if test -n "$library_names" &&
8602300346aeSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
86036bea0e4fSmrg	  case $host_os in
86046bea0e4fSmrg	  cygwin* | mingw* | windows* | cegcc* | os2*)
8605d656433aSmrg	      # No point in relinking DLLs because paths are not encoded
86063c15da26Smrg	      func_append notinst_deplibs " $lib"
8607d656433aSmrg	      need_relink=no
8608d656433aSmrg	    ;;
8609d656433aSmrg	  *)
8610300346aeSmrg	    if test no = "$installed"; then
86113c15da26Smrg	      func_append notinst_deplibs " $lib"
8612d656433aSmrg	      need_relink=yes
8613d656433aSmrg	    fi
8614d656433aSmrg	    ;;
8615d656433aSmrg	  esac
8616d656433aSmrg	  # This is a shared library
8617d656433aSmrg
8618d656433aSmrg	  # Warn about portability, can't link against -module's on some
8619d656433aSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8620300346aeSmrg	  dlopenmodule=
8621d656433aSmrg	  for dlpremoduletest in $dlprefiles; do
8622d656433aSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8623300346aeSmrg	      dlopenmodule=$dlpremoduletest
8624d656433aSmrg	      break
8625d656433aSmrg	    fi
8626d656433aSmrg	  done
8627300346aeSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8628555991fdSmrg	    echo
8629300346aeSmrg	    if test prog = "$linkmode"; then
86306bea0e4fSmrg	      func_warning "Linking the executable $output against the loadable module"
8631d656433aSmrg	    else
86326bea0e4fSmrg	      func_warning "Linking the shared library $output against the loadable module"
8633d656433aSmrg	    fi
86346bea0e4fSmrg	    func_warning "$linklib is not portable!"
8635d656433aSmrg	  fi
8636300346aeSmrg	  if test lib = "$linkmode" &&
8637300346aeSmrg	     test yes = "$hardcode_into_libs"; then
8638d656433aSmrg	    # Hardcode the library path.
8639d656433aSmrg	    # Skip directories that are in the system default run-time
8640d656433aSmrg	    # search path.
8641d656433aSmrg	    case " $sys_lib_dlsearch_path " in
8642d656433aSmrg	    *" $absdir "*) ;;
8643d656433aSmrg	    *)
86446bea0e4fSmrg	      case "$compile_rpath$compile_rpath_tail " in
8645d656433aSmrg	      *" $absdir "*) ;;
86466bea0e4fSmrg	      *) case $absdir in
86476bea0e4fSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
86486bea0e4fSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
86496bea0e4fSmrg		 esac
8650d656433aSmrg	      esac
8651d656433aSmrg	      ;;
8652d656433aSmrg	    esac
8653d656433aSmrg	    case " $sys_lib_dlsearch_path " in
8654d656433aSmrg	    *" $libdir "*) ;;
8655d656433aSmrg	    *)
8656d656433aSmrg	      case "$finalize_rpath " in
8657d656433aSmrg	      *" $libdir "*) ;;
86583c15da26Smrg	      *) func_append finalize_rpath " $libdir" ;;
8659d656433aSmrg	      esac
8660d656433aSmrg	      ;;
8661d656433aSmrg	    esac
8662d656433aSmrg	  fi
8663d656433aSmrg
8664d656433aSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8665d656433aSmrg	    # figure out the soname
8666d656433aSmrg	    set dummy $library_names
8667d656433aSmrg	    shift
8668300346aeSmrg	    realname=$1
8669d656433aSmrg	    shift
8670d656433aSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8671d656433aSmrg	    # use dlname if we got it. it's perfectly good, no?
8672d656433aSmrg	    if test -n "$dlname"; then
8673300346aeSmrg	      soname=$dlname
8674d656433aSmrg	    elif test -n "$soname_spec"; then
8675d656433aSmrg	      # bleh windows
86766bea0e4fSmrg	      case $host_os in
86776bea0e4fSmrg	      cygwin* | mingw* | windows* | cegcc* | os2*)
8678d656433aSmrg	        func_arith $current - $age
8679d656433aSmrg		major=$func_arith_result
8680300346aeSmrg		versuffix=-$major
8681d656433aSmrg		;;
8682d656433aSmrg	      esac
8683d656433aSmrg	      eval soname=\"$soname_spec\"
8684d656433aSmrg	    else
8685300346aeSmrg	      soname=$realname
8686d656433aSmrg	    fi
8687d656433aSmrg
8688d656433aSmrg	    # Make a new name for the extract_expsyms_cmds to use
8689300346aeSmrg	    soroot=$soname
8690d656433aSmrg	    func_basename "$soroot"
8691300346aeSmrg	    soname=$func_basename_result
8692d656433aSmrg	    func_stripname 'lib' '.dll' "$soname"
8693d656433aSmrg	    newlib=libimp-$func_stripname_result.a
8694d656433aSmrg
8695d656433aSmrg	    # If the library has no export list, then create one now
8696d656433aSmrg	    if test -f "$output_objdir/$soname-def"; then :
8697d656433aSmrg	    else
8698300346aeSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8699d656433aSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8700d656433aSmrg	    fi
8701d656433aSmrg
8702d656433aSmrg	    # Create $newlib
8703d656433aSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8704300346aeSmrg	      func_verbose "generating import library for '$soname'"
8705d656433aSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8706d656433aSmrg	    fi
8707d656433aSmrg	    # make sure the library variables are pointing to the new library
8708d656433aSmrg	    dir=$output_objdir
8709d656433aSmrg	    linklib=$newlib
8710d656433aSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8711d656433aSmrg
8712300346aeSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8713d656433aSmrg	    add_shlibpath=
8714d656433aSmrg	    add_dir=
8715d656433aSmrg	    add=
8716d656433aSmrg	    lib_linked=yes
8717d656433aSmrg	    case $hardcode_action in
8718d656433aSmrg	    immediate | unsupported)
8719300346aeSmrg	      if test no = "$hardcode_direct"; then
8720300346aeSmrg		add=$dir/$linklib
8721d656433aSmrg		case $host in
8722300346aeSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8723300346aeSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
87246bea0e4fSmrg		  *-*-emscripten*) add_dir=-L$dir ;;
8725d656433aSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8726300346aeSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8727d656433aSmrg		  *-*-darwin* )
8728300346aeSmrg		    # if the lib is a (non-dlopened) module then we cannot
8729d656433aSmrg		    # link against it, someone is ignoring the earlier warnings
8730d656433aSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8731300346aeSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8732d656433aSmrg		      if test "X$dlopenmodule" != "X$lib"; then
87336bea0e4fSmrg			func_warning "lib $linklib is a module, not a shared library"
8734300346aeSmrg			if test -z "$old_library"; then
87356bea0e4fSmrg			  func_warning "And there doesn't seem to be a static archive available"
87366bea0e4fSmrg			  func_warning "The link will probably fail, sorry"
8737d656433aSmrg			else
8738300346aeSmrg			  add=$dir/$old_library
8739d656433aSmrg			fi
8740d656433aSmrg		      elif test -n "$old_library"; then
8741300346aeSmrg			add=$dir/$old_library
8742d656433aSmrg		      fi
8743d656433aSmrg		    fi
8744d656433aSmrg		esac
8745300346aeSmrg	      elif test no = "$hardcode_minus_L"; then
8746d656433aSmrg		case $host in
8747300346aeSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8748d656433aSmrg		esac
8749300346aeSmrg		add_dir=-L$dir
8750300346aeSmrg		add=-l$name
8751300346aeSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8752300346aeSmrg		add_shlibpath=$dir
8753300346aeSmrg		add=-l$name
8754d656433aSmrg	      else
8755d656433aSmrg		lib_linked=no
8756d656433aSmrg	      fi
8757d656433aSmrg	      ;;
8758d656433aSmrg	    relink)
8759300346aeSmrg	      if test yes = "$hardcode_direct" &&
8760300346aeSmrg	         test no = "$hardcode_direct_absolute"; then
8761300346aeSmrg		add=$dir/$linklib
8762300346aeSmrg	      elif test yes = "$hardcode_minus_L"; then
8763300346aeSmrg		add_dir=-L$absdir
8764d656433aSmrg		# Try looking first in the location we're being installed to.
8765d656433aSmrg		if test -n "$inst_prefix_dir"; then
8766d656433aSmrg		  case $libdir in
8767d656433aSmrg		    [\\/]*)
87683c15da26Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8769d656433aSmrg		      ;;
8770d656433aSmrg		  esac
8771d656433aSmrg		fi
8772300346aeSmrg		add=-l$name
8773300346aeSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8774300346aeSmrg		add_shlibpath=$dir
8775300346aeSmrg		add=-l$name
8776d656433aSmrg	      else
8777d656433aSmrg		lib_linked=no
8778d656433aSmrg	      fi
8779d656433aSmrg	      ;;
8780d656433aSmrg	    *) lib_linked=no ;;
8781d656433aSmrg	    esac
8782d656433aSmrg
8783300346aeSmrg	    if test yes != "$lib_linked"; then
8784d656433aSmrg	      func_fatal_configuration "unsupported hardcode properties"
8785d656433aSmrg	    fi
8786d656433aSmrg
8787d656433aSmrg	    if test -n "$add_shlibpath"; then
8788d656433aSmrg	      case :$compile_shlibpath: in
8789d656433aSmrg	      *":$add_shlibpath:"*) ;;
87903c15da26Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8791d656433aSmrg	      esac
8792d656433aSmrg	    fi
8793300346aeSmrg	    if test prog = "$linkmode"; then
8794d656433aSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8795d656433aSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8796d656433aSmrg	    else
8797d656433aSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8798d656433aSmrg	      test -n "$add" && deplibs="$add $deplibs"
8799300346aeSmrg	      if test yes != "$hardcode_direct" &&
8800300346aeSmrg		 test yes != "$hardcode_minus_L" &&
8801300346aeSmrg		 test yes = "$hardcode_shlibpath_var"; then
8802d656433aSmrg		case :$finalize_shlibpath: in
8803d656433aSmrg		*":$libdir:"*) ;;
88043c15da26Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8805d656433aSmrg		esac
8806d656433aSmrg	      fi
8807d656433aSmrg	    fi
8808d656433aSmrg	  fi
8809d656433aSmrg
8810300346aeSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8811d656433aSmrg	    add_shlibpath=
8812d656433aSmrg	    add_dir=
8813d656433aSmrg	    add=
8814d656433aSmrg	    # Finalize command for both is simple: just hardcode it.
8815300346aeSmrg	    if test yes = "$hardcode_direct" &&
8816300346aeSmrg	       test no = "$hardcode_direct_absolute"; then
8817300346aeSmrg	      add=$libdir/$linklib
8818300346aeSmrg	    elif test yes = "$hardcode_minus_L"; then
88196bea0e4fSmrg	      add_dir=-L$lt_sysroot$libdir
8820300346aeSmrg	      add=-l$name
8821300346aeSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8822d656433aSmrg	      case :$finalize_shlibpath: in
8823d656433aSmrg	      *":$libdir:"*) ;;
88243c15da26Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8825d656433aSmrg	      esac
8826300346aeSmrg	      add=-l$name
8827300346aeSmrg	    elif test yes = "$hardcode_automatic"; then
8828d656433aSmrg	      if test -n "$inst_prefix_dir" &&
8829300346aeSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8830300346aeSmrg		add=$inst_prefix_dir$libdir/$linklib
8831d656433aSmrg	      else
8832300346aeSmrg		add=$libdir/$linklib
8833d656433aSmrg	      fi
8834d656433aSmrg	    else
8835d656433aSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
88366bea0e4fSmrg	      add_dir=-L$lt_sysroot$libdir
8837d656433aSmrg	      # Try looking first in the location we're being installed to.
8838d656433aSmrg	      if test -n "$inst_prefix_dir"; then
8839d656433aSmrg		case $libdir in
8840d656433aSmrg		  [\\/]*)
88413c15da26Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8842d656433aSmrg		    ;;
8843d656433aSmrg		esac
8844d656433aSmrg	      fi
8845300346aeSmrg	      add=-l$name
8846d656433aSmrg	    fi
8847d656433aSmrg
8848300346aeSmrg	    if test prog = "$linkmode"; then
8849d656433aSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8850d656433aSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8851d656433aSmrg	    else
8852d656433aSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8853d656433aSmrg	      test -n "$add" && deplibs="$add $deplibs"
8854d656433aSmrg	    fi
8855d656433aSmrg	  fi
8856300346aeSmrg	elif test prog = "$linkmode"; then
8857d656433aSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8858d656433aSmrg	  # is not unsupported.  This is valid on all known static and
8859d656433aSmrg	  # shared platforms.
8860300346aeSmrg	  if test unsupported != "$hardcode_direct"; then
8861300346aeSmrg	    test -n "$old_library" && linklib=$old_library
8862d656433aSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8863d656433aSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8864d656433aSmrg	  else
8865d656433aSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8866d656433aSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8867d656433aSmrg	  fi
8868300346aeSmrg	elif test yes = "$build_libtool_libs"; then
8869d656433aSmrg	  # Not a shared library
8870300346aeSmrg	  if test pass_all != "$deplibs_check_method"; then
8871d656433aSmrg	    # We're trying link a shared library against a static one
8872d656433aSmrg	    # but the system doesn't support it.
8873d656433aSmrg
8874d656433aSmrg	    # Just print a warning and add the library to dependency_libs so
8875d656433aSmrg	    # that the program can be linked against the static library.
88766bea0e4fSmrg	    func_warning "This system cannot link to static lib archive $lib."
88776bea0e4fSmrg	    func_warning "I have the capability to make that library automatically link in when"
88786bea0e4fSmrg	    func_warning "you link to this library.  But I can only do this if you have a"
88796bea0e4fSmrg	    func_warning "shared version of the library, which you do not appear to have."
8880300346aeSmrg	    if test yes = "$module"; then
88816bea0e4fSmrg	      func_warning "But as you try to build a module library, libtool will still create "
88826bea0e4fSmrg	      func_warning "a static module, that should work as long as the dlopening application"
88836bea0e4fSmrg	      func_warning "is linked with the -dlopen flag to resolve symbols at runtime."
8884d656433aSmrg	      if test -z "$global_symbol_pipe"; then
88856bea0e4fSmrg		func_warning "However, this would only work if libtool was able to extract symbol"
88866bea0e4fSmrg		func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
88876bea0e4fSmrg		func_warning "not find such a program.  So, this module is probably useless."
88886bea0e4fSmrg		func_warning "'nm' from GNU binutils and a full rebuild may help."
8889d656433aSmrg	      fi
8890300346aeSmrg	      if test no = "$build_old_libs"; then
8891d656433aSmrg		build_libtool_libs=module
8892d656433aSmrg		build_old_libs=yes
8893d656433aSmrg	      else
8894d656433aSmrg		build_libtool_libs=no
8895d656433aSmrg	      fi
8896d656433aSmrg	    fi
8897d656433aSmrg	  else
8898d656433aSmrg	    deplibs="$dir/$old_library $deplibs"
8899d656433aSmrg	    link_static=yes
8900d656433aSmrg	  fi
8901d656433aSmrg	fi # link shared/static library?
8902d656433aSmrg
8903300346aeSmrg	if test lib = "$linkmode"; then
8904d656433aSmrg	  if test -n "$dependency_libs" &&
8905300346aeSmrg	     { test yes != "$hardcode_into_libs" ||
8906300346aeSmrg	       test yes = "$build_old_libs" ||
8907300346aeSmrg	       test yes = "$link_static"; }; then
8908d656433aSmrg	    # Extract -R from dependency_libs
8909d656433aSmrg	    temp_deplibs=
8910d656433aSmrg	    for libdir in $dependency_libs; do
8911d656433aSmrg	      case $libdir in
8912d656433aSmrg	      -R*) func_stripname '-R' '' "$libdir"
8913d656433aSmrg	           temp_xrpath=$func_stripname_result
8914d656433aSmrg		   case " $xrpath " in
8915d656433aSmrg		   *" $temp_xrpath "*) ;;
89163c15da26Smrg		   *) func_append xrpath " $temp_xrpath";;
8917d656433aSmrg		   esac;;
89183c15da26Smrg	      *) func_append temp_deplibs " $libdir";;
8919d656433aSmrg	      esac
8920d656433aSmrg	    done
8921300346aeSmrg	    dependency_libs=$temp_deplibs
8922d656433aSmrg	  fi
8923d656433aSmrg
89243c15da26Smrg	  func_append newlib_search_path " $absdir"
8925d656433aSmrg	  # Link against this library
8926300346aeSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8927d656433aSmrg	  # ... and its dependency_libs
8928d656433aSmrg	  tmp_libs=
8929d656433aSmrg	  for deplib in $dependency_libs; do
8930d656433aSmrg	    newdependency_libs="$deplib $newdependency_libs"
89313c15da26Smrg	    case $deplib in
89323c15da26Smrg              -L*) func_stripname '-L' '' "$deplib"
89333c15da26Smrg                   func_resolve_sysroot "$func_stripname_result";;
89343c15da26Smrg              *) func_resolve_sysroot "$deplib" ;;
89353c15da26Smrg            esac
8936300346aeSmrg	    if $opt_preserve_dup_deps; then
8937d656433aSmrg	      case "$tmp_libs " in
89383c15da26Smrg	      *" $func_resolve_sysroot_result "*)
89393c15da26Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8940d656433aSmrg	      esac
8941d656433aSmrg	    fi
89423c15da26Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8943d656433aSmrg	  done
8944d656433aSmrg
8945300346aeSmrg	  if test no != "$link_all_deplibs"; then
8946d656433aSmrg	    # Add the search paths of all dependency libraries
8947d656433aSmrg	    for deplib in $dependency_libs; do
8948555991fdSmrg	      path=
8949d656433aSmrg	      case $deplib in
8950300346aeSmrg	      -L*) path=$deplib ;;
8951d656433aSmrg	      *.la)
89523c15da26Smrg	        func_resolve_sysroot "$deplib"
89533c15da26Smrg	        deplib=$func_resolve_sysroot_result
8954d656433aSmrg	        func_dirname "$deplib" "" "."
89553c15da26Smrg		dir=$func_dirname_result
8956d656433aSmrg		# We need an absolute path.
8957d656433aSmrg		case $dir in
8958300346aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8959d656433aSmrg		*)
8960d656433aSmrg		  absdir=`cd "$dir" && pwd`
8961d656433aSmrg		  if test -z "$absdir"; then
8962300346aeSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8963300346aeSmrg		    absdir=$dir
8964d656433aSmrg		  fi
8965d656433aSmrg		  ;;
8966d656433aSmrg		esac
8967d656433aSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
8968d656433aSmrg		case $host in
8969d656433aSmrg		*-*-darwin*)
8970d656433aSmrg		  depdepl=
8971300346aeSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8972300346aeSmrg		  if test -n "$deplibrary_names"; then
8973300346aeSmrg		    for tmp in $deplibrary_names; do
8974d656433aSmrg		      depdepl=$tmp
8975d656433aSmrg		    done
8976300346aeSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8977300346aeSmrg		      depdepl=$absdir/$objdir/$depdepl
8978300346aeSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8979d656433aSmrg                      if test -z "$darwin_install_name"; then
8980300346aeSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8981d656433aSmrg                      fi
8982300346aeSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8983300346aeSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8984d656433aSmrg		      path=
8985d656433aSmrg		    fi
8986d656433aSmrg		  fi
8987d656433aSmrg		  ;;
8988d656433aSmrg		*)
8989300346aeSmrg		  path=-L$absdir/$objdir
8990d656433aSmrg		  ;;
8991d656433aSmrg		esac
8992d656433aSmrg		else
8993300346aeSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8994d656433aSmrg		  test -z "$libdir" && \
8995300346aeSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8996d656433aSmrg		  test "$absdir" != "$libdir" && \
8997300346aeSmrg		    func_warning "'$deplib' seems to be moved"
8998d656433aSmrg
8999300346aeSmrg		  path=-L$absdir
9000d656433aSmrg		fi
9001d656433aSmrg		;;
9002d656433aSmrg	      esac
9003d656433aSmrg	      case " $deplibs " in
9004d656433aSmrg	      *" $path "*) ;;
9005d656433aSmrg	      *) deplibs="$path $deplibs" ;;
9006d656433aSmrg	      esac
9007d656433aSmrg	    done
9008d656433aSmrg	  fi # link_all_deplibs != no
9009d656433aSmrg	fi # linkmode = lib
9010d656433aSmrg      done # for deplib in $libs
90116bea0e4fSmrg
90126bea0e4fSmrg      func_append temp_rpath "$temp_rpath_tail"
90136bea0e4fSmrg      func_append compile_rpath "$compile_rpath_tail"
90146bea0e4fSmrg
9015300346aeSmrg      if test link = "$pass"; then
9016300346aeSmrg	if test prog = "$linkmode"; then
9017d656433aSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
9018d656433aSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
9019d656433aSmrg	else
9020555991fdSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9021d656433aSmrg	fi
9022d656433aSmrg      fi
9023300346aeSmrg      dependency_libs=$newdependency_libs
9024300346aeSmrg      if test dlpreopen = "$pass"; then
9025d656433aSmrg	# Link the dlpreopened libraries before other libraries
9026d656433aSmrg	for deplib in $save_deplibs; do
9027d656433aSmrg	  deplibs="$deplib $deplibs"
9028d656433aSmrg	done
9029d656433aSmrg      fi
9030300346aeSmrg      if test dlopen != "$pass"; then
9031300346aeSmrg	test conv = "$pass" || {
9032d656433aSmrg	  # Make sure lib_search_path contains only unique directories.
9033d656433aSmrg	  lib_search_path=
9034d656433aSmrg	  for dir in $newlib_search_path; do
9035d656433aSmrg	    case "$lib_search_path " in
9036d656433aSmrg	    *" $dir "*) ;;
90373c15da26Smrg	    *) func_append lib_search_path " $dir" ;;
9038d656433aSmrg	    esac
9039d656433aSmrg	  done
9040d656433aSmrg	  newlib_search_path=
9041300346aeSmrg	}
9042d656433aSmrg
9043300346aeSmrg	if test prog,link = "$linkmode,$pass"; then
9044d656433aSmrg	  vars="compile_deplibs finalize_deplibs"
9045300346aeSmrg	else
9046300346aeSmrg	  vars=deplibs
9047d656433aSmrg	fi
9048d656433aSmrg	for var in $vars dependency_libs; do
9049d656433aSmrg	  # Add libraries to $var in reverse order
9050d656433aSmrg	  eval tmp_libs=\"\$$var\"
9051d656433aSmrg	  new_libs=
90526bea0e4fSmrg	  # FIXME: Pedantically, this is the right thing to do, so
90536bea0e4fSmrg	  #        that some nasty dependency loop isn't accidentally
90546bea0e4fSmrg	  #        broken: new_libs="$deplib $new_libs"
9055d656433aSmrg	  for deplib in $tmp_libs; do
90566bea0e4fSmrg	    if $opt_preserve_dup_deps; then
90576bea0e4fSmrg	      new_libs="$deplib $new_libs"
90586bea0e4fSmrg	    else
90596bea0e4fSmrg	      # Pragmatically, this seems to cause very few problems in
90606bea0e4fSmrg	      # practice:
90616bea0e4fSmrg	      case $deplib in
90626bea0e4fSmrg	      -L*) new_libs="$deplib $new_libs" ;;
90636bea0e4fSmrg	      -R*) ;;
9064d656433aSmrg	      *)
90656bea0e4fSmrg	        # And here is the reason: when a library appears more
90666bea0e4fSmrg	        # than once as an explicit dependence of a library, or
90676bea0e4fSmrg	        # is implicitly linked in more than once by the
90686bea0e4fSmrg	        # compiler, it is considered special, and multiple
90696bea0e4fSmrg	        # occurrences thereof are not removed.  Compare this
90706bea0e4fSmrg	        # with having the same library being listed as a
90716bea0e4fSmrg	        # dependency of multiple other libraries: in this case,
90726bea0e4fSmrg	        # we know (pedantically, we assume) the library does not
90736bea0e4fSmrg	        # need to be listed more than once, so we keep only the
90746bea0e4fSmrg	        # last copy.  This is not always right, but it is rare
90756bea0e4fSmrg	        # enough that we require users that really mean to play
90766bea0e4fSmrg	        # such unportable linking tricks to link the library
90776bea0e4fSmrg	        # using -Wl,-lname, so that libtool does not consider it
90786bea0e4fSmrg	        # for duplicate removal.  And if not possible for portability
90796bea0e4fSmrg	        # reasons, then --preserve-dup-deps should be used.
90806bea0e4fSmrg	        case " $specialdeplibs " in
90816bea0e4fSmrg	        *" $deplib "*) new_libs="$deplib $new_libs" ;;
90826bea0e4fSmrg	        *)
90836bea0e4fSmrg	          case " $new_libs " in
90846bea0e4fSmrg	          *" $deplib "*) ;;
90856bea0e4fSmrg	          *) new_libs="$deplib $new_libs" ;;
90866bea0e4fSmrg	          esac
90876bea0e4fSmrg	          ;;
90886bea0e4fSmrg	        esac
90896bea0e4fSmrg	        ;;
9090d656433aSmrg	      esac
90916bea0e4fSmrg	    fi
9092d656433aSmrg	  done
9093d656433aSmrg	  tmp_libs=
9094d656433aSmrg	  for deplib in $new_libs; do
9095d656433aSmrg	    case $deplib in
9096d656433aSmrg	    -L*)
9097d656433aSmrg	      case " $tmp_libs " in
9098d656433aSmrg	      *" $deplib "*) ;;
90993c15da26Smrg	      *) func_append tmp_libs " $deplib" ;;
9100d656433aSmrg	      esac
9101d656433aSmrg	      ;;
91023c15da26Smrg	    *) func_append tmp_libs " $deplib" ;;
9103d656433aSmrg	    esac
9104d656433aSmrg	  done
9105d656433aSmrg	  eval $var=\"$tmp_libs\"
9106d656433aSmrg	done # for var
9107d656433aSmrg      fi
9108300346aeSmrg
9109300346aeSmrg      # Add Sun CC postdeps if required:
9110300346aeSmrg      test CXX = "$tagname" && {
9111300346aeSmrg        case $host_os in
9112300346aeSmrg        linux*)
91133fb97780Smrg          case `$CC -V 2>&1 | $SED 5q` in
9114300346aeSmrg          *Sun\ C*) # Sun C++ 5.9
9115300346aeSmrg            func_suncc_cstd_abi
9116300346aeSmrg
9117300346aeSmrg            if test no != "$suncc_use_cstd_abi"; then
9118300346aeSmrg              func_append postdeps ' -library=Cstd -library=Crun'
9119300346aeSmrg            fi
9120300346aeSmrg            ;;
9121300346aeSmrg          esac
9122300346aeSmrg          ;;
9123300346aeSmrg
9124300346aeSmrg        solaris*)
9125300346aeSmrg          func_cc_basename "$CC"
9126300346aeSmrg          case $func_cc_basename_result in
9127300346aeSmrg          CC* | sunCC*)
9128300346aeSmrg            func_suncc_cstd_abi
9129300346aeSmrg
9130300346aeSmrg            if test no != "$suncc_use_cstd_abi"; then
9131300346aeSmrg              func_append postdeps ' -library=Cstd -library=Crun'
9132300346aeSmrg            fi
9133300346aeSmrg            ;;
9134300346aeSmrg          esac
9135300346aeSmrg          ;;
9136300346aeSmrg        esac
9137300346aeSmrg      }
9138300346aeSmrg
9139d656433aSmrg      # Last step: remove runtime libs from dependency_libs
9140d656433aSmrg      # (they stay in deplibs)
9141d656433aSmrg      tmp_libs=
9142300346aeSmrg      for i in $dependency_libs; do
9143d656433aSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
9144d656433aSmrg	*" $i "*)
9145300346aeSmrg	  i=
9146d656433aSmrg	  ;;
9147d656433aSmrg	esac
9148300346aeSmrg	if test -n "$i"; then
91493c15da26Smrg	  func_append tmp_libs " $i"
9150d656433aSmrg	fi
9151d656433aSmrg      done
9152d656433aSmrg      dependency_libs=$tmp_libs
9153d656433aSmrg    done # for pass
9154300346aeSmrg    if test prog = "$linkmode"; then
9155300346aeSmrg      dlfiles=$newdlfiles
9156d656433aSmrg    fi
9157300346aeSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
9158300346aeSmrg      dlprefiles=$newdlprefiles
9159d656433aSmrg    fi
9160d656433aSmrg
9161d656433aSmrg    case $linkmode in
9162d656433aSmrg    oldlib)
9163300346aeSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
9164300346aeSmrg	func_warning "'-dlopen' is ignored for archives"
9165d656433aSmrg      fi
9166d656433aSmrg
9167d656433aSmrg      case " $deplibs" in
9168d656433aSmrg      *\ -l* | *\ -L*)
9169300346aeSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
9170d656433aSmrg      esac
9171d656433aSmrg
9172d656433aSmrg      test -n "$rpath" && \
9173300346aeSmrg	func_warning "'-rpath' is ignored for archives"
9174d656433aSmrg
9175d656433aSmrg      test -n "$xrpath" && \
9176300346aeSmrg	func_warning "'-R' is ignored for archives"
9177d656433aSmrg
9178d656433aSmrg      test -n "$vinfo" && \
9179300346aeSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
9180d656433aSmrg
9181d656433aSmrg      test -n "$release" && \
9182300346aeSmrg	func_warning "'-release' is ignored for archives"
9183d656433aSmrg
9184d656433aSmrg      test -n "$export_symbols$export_symbols_regex" && \
9185300346aeSmrg	func_warning "'-export-symbols' is ignored for archives"
9186d656433aSmrg
9187d656433aSmrg      # Now set the variables for building old libraries.
9188d656433aSmrg      build_libtool_libs=no
9189300346aeSmrg      oldlibs=$output
91903c15da26Smrg      func_append objs "$old_deplibs"
9191d656433aSmrg      ;;
9192d656433aSmrg
9193d656433aSmrg    lib)
9194300346aeSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9195d656433aSmrg      case $outputname in
9196d656433aSmrg      lib*)
9197d656433aSmrg	func_stripname 'lib' '.la' "$outputname"
9198d656433aSmrg	name=$func_stripname_result
9199d656433aSmrg	eval shared_ext=\"$shrext_cmds\"
9200d656433aSmrg	eval libname=\"$libname_spec\"
9201d656433aSmrg	;;
9202d656433aSmrg      *)
9203300346aeSmrg	test no = "$module" \
9204300346aeSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9205d656433aSmrg
9206300346aeSmrg	if test no != "$need_lib_prefix"; then
9207d656433aSmrg	  # Add the "lib" prefix for modules if required
9208d656433aSmrg	  func_stripname '' '.la' "$outputname"
9209d656433aSmrg	  name=$func_stripname_result
9210d656433aSmrg	  eval shared_ext=\"$shrext_cmds\"
9211d656433aSmrg	  eval libname=\"$libname_spec\"
9212d656433aSmrg	else
9213d656433aSmrg	  func_stripname '' '.la' "$outputname"
9214d656433aSmrg	  libname=$func_stripname_result
9215d656433aSmrg	fi
9216d656433aSmrg	;;
9217d656433aSmrg      esac
9218d656433aSmrg
9219d656433aSmrg      if test -n "$objs"; then
9220300346aeSmrg	if test pass_all != "$deplibs_check_method"; then
9221300346aeSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9222d656433aSmrg	else
92236bea0e4fSmrg	  func_warning "Linking the shared library $output against the non-libtool objects $objs is not portable!"
92243c15da26Smrg	  func_append libobjs " $objs"
9225d656433aSmrg	fi
9226d656433aSmrg      fi
9227d656433aSmrg
9228300346aeSmrg      test no = "$dlself" \
9229300346aeSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9230d656433aSmrg
9231d656433aSmrg      set dummy $rpath
9232d656433aSmrg      shift
9233300346aeSmrg      test 1 -lt "$#" \
9234300346aeSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9235d656433aSmrg
9236300346aeSmrg      install_libdir=$1
9237d656433aSmrg
9238d656433aSmrg      oldlibs=
9239d656433aSmrg      if test -z "$rpath"; then
9240300346aeSmrg	if test yes = "$build_libtool_libs"; then
9241d656433aSmrg	  # Building a libtool convenience library.
9242300346aeSmrg	  # Some compilers have problems with a '.al' extension so
9243d656433aSmrg	  # convenience libraries should have the same extension an
9244d656433aSmrg	  # archive normally would.
9245d656433aSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9246d656433aSmrg	  build_libtool_libs=convenience
9247d656433aSmrg	  build_old_libs=yes
9248d656433aSmrg	fi
9249d656433aSmrg
9250d656433aSmrg	test -n "$vinfo" && \
9251300346aeSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9252d656433aSmrg
9253d656433aSmrg	test -n "$release" && \
9254300346aeSmrg	  func_warning "'-release' is ignored for convenience libraries"
9255d656433aSmrg      else
9256d656433aSmrg
9257d656433aSmrg	# Parse the version information argument.
9258300346aeSmrg	save_ifs=$IFS; IFS=:
9259d656433aSmrg	set dummy $vinfo 0 0 0
9260d656433aSmrg	shift
9261300346aeSmrg	IFS=$save_ifs
9262d656433aSmrg
9263d656433aSmrg	test -n "$7" && \
9264300346aeSmrg	  func_fatal_help "too many parameters to '-version-info'"
9265d656433aSmrg
9266d656433aSmrg	# convert absolute version numbers to libtool ages
9267d656433aSmrg	# this retains compatibility with .la files and attempts
9268d656433aSmrg	# to make the code below a bit more comprehensible
9269d656433aSmrg
9270d656433aSmrg	case $vinfo_number in
9271d656433aSmrg	yes)
9272300346aeSmrg	  number_major=$1
9273300346aeSmrg	  number_minor=$2
9274300346aeSmrg	  number_revision=$3
9275d656433aSmrg	  #
9276d656433aSmrg	  # There are really only two kinds -- those that
9277d656433aSmrg	  # use the current revision as the major version
9278d656433aSmrg	  # and those that subtract age and use age as
9279d656433aSmrg	  # a minor version.  But, then there is irix
9280300346aeSmrg	  # that has an extra 1 added just for fun
9281d656433aSmrg	  #
9282d656433aSmrg	  case $version_type in
92830a6b08f8Smrg	  # correct linux to gnu/linux during the next big refactor
92846bea0e4fSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|qnx|windows|none)
9285d656433aSmrg	    func_arith $number_major + $number_minor
9286d656433aSmrg	    current=$func_arith_result
9287300346aeSmrg	    age=$number_minor
9288300346aeSmrg	    revision=$number_revision
9289d656433aSmrg	    ;;
92906bea0e4fSmrg	  freebsd-aout|sco|sunos)
9291300346aeSmrg	    current=$number_major
9292300346aeSmrg	    revision=$number_minor
9293300346aeSmrg	    age=0
9294d656433aSmrg	    ;;
9295d656433aSmrg	  irix|nonstopux)
9296d656433aSmrg	    func_arith $number_major + $number_minor
9297d656433aSmrg	    current=$func_arith_result
9298300346aeSmrg	    age=$number_minor
9299300346aeSmrg	    revision=$number_minor
9300d656433aSmrg	    lt_irix_increment=no
9301d656433aSmrg	    ;;
93026bea0e4fSmrg	  *)
93036bea0e4fSmrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
93046bea0e4fSmrg	    ;;
9305d656433aSmrg	  esac
9306d656433aSmrg	  ;;
9307d656433aSmrg	no)
9308300346aeSmrg	  current=$1
9309300346aeSmrg	  revision=$2
9310300346aeSmrg	  age=$3
9311d656433aSmrg	  ;;
9312d656433aSmrg	esac
9313d656433aSmrg
9314d656433aSmrg	# Check that each of the things are valid numbers.
9315d656433aSmrg	case $current in
9316d656433aSmrg	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]) ;;
9317d656433aSmrg	*)
9318300346aeSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9319300346aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9320d656433aSmrg	  ;;
9321d656433aSmrg	esac
9322d656433aSmrg
9323d656433aSmrg	case $revision in
9324d656433aSmrg	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]) ;;
9325d656433aSmrg	*)
9326300346aeSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9327300346aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9328d656433aSmrg	  ;;
9329d656433aSmrg	esac
9330d656433aSmrg
9331d656433aSmrg	case $age in
9332d656433aSmrg	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]) ;;
9333d656433aSmrg	*)
9334300346aeSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9335300346aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9336d656433aSmrg	  ;;
9337d656433aSmrg	esac
9338d656433aSmrg
9339d656433aSmrg	if test "$age" -gt "$current"; then
9340300346aeSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9341300346aeSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9342d656433aSmrg	fi
9343d656433aSmrg
9344d656433aSmrg	# Calculate the version variables.
9345d656433aSmrg	major=
9346d656433aSmrg	versuffix=
9347d656433aSmrg	verstring=
9348d656433aSmrg	case $version_type in
9349d656433aSmrg	none) ;;
9350d656433aSmrg
9351d656433aSmrg	darwin)
9352d656433aSmrg	  # Like Linux, but with the current version available in
9353d656433aSmrg	  # verstring for coding it into the library header
9354d656433aSmrg	  func_arith $current - $age
9355d656433aSmrg	  major=.$func_arith_result
9356300346aeSmrg	  versuffix=$major.$age.$revision
9357d656433aSmrg	  # Darwin ld doesn't like 0 for these options...
9358d656433aSmrg	  func_arith $current + 1
9359d656433aSmrg	  minor_current=$func_arith_result
9360300346aeSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9361d656433aSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9362300346aeSmrg          # On Darwin other compilers
9363300346aeSmrg          case $CC in
9364300346aeSmrg              nagfor*)
9365300346aeSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9366300346aeSmrg                  ;;
9367300346aeSmrg              *)
9368300346aeSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9369300346aeSmrg                  ;;
9370300346aeSmrg          esac
9371d656433aSmrg	  ;;
9372d656433aSmrg
9373d656433aSmrg	freebsd-aout)
9374300346aeSmrg	  major=.$current
9375300346aeSmrg	  versuffix=.$current.$revision
9376d656433aSmrg	  ;;
9377d656433aSmrg
93783fb97780Smrg	freebsd-elf | midnightbsd-elf)
9379300346aeSmrg	  func_arith $current - $age
9380300346aeSmrg	  major=.$func_arith_result
9381300346aeSmrg	  versuffix=$major.$age.$revision
9382d656433aSmrg	  ;;
9383d656433aSmrg
9384d656433aSmrg	irix | nonstopux)
9385300346aeSmrg	  if test no = "$lt_irix_increment"; then
9386d656433aSmrg	    func_arith $current - $age
9387d656433aSmrg	  else
9388d656433aSmrg	    func_arith $current - $age + 1
9389d656433aSmrg	  fi
9390d656433aSmrg	  major=$func_arith_result
9391d656433aSmrg
9392d656433aSmrg	  case $version_type in
9393d656433aSmrg	    nonstopux) verstring_prefix=nonstopux ;;
9394d656433aSmrg	    *)         verstring_prefix=sgi ;;
9395d656433aSmrg	  esac
9396300346aeSmrg	  verstring=$verstring_prefix$major.$revision
9397d656433aSmrg
9398d656433aSmrg	  # Add in all the interfaces that we are compatible with.
9399d656433aSmrg	  loop=$revision
9400300346aeSmrg	  while test 0 -ne "$loop"; do
9401d656433aSmrg	    func_arith $revision - $loop
9402d656433aSmrg	    iface=$func_arith_result
9403d656433aSmrg	    func_arith $loop - 1
9404d656433aSmrg	    loop=$func_arith_result
9405300346aeSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9406d656433aSmrg	  done
9407d656433aSmrg
9408300346aeSmrg	  # Before this point, $major must not contain '.'.
9409d656433aSmrg	  major=.$major
9410300346aeSmrg	  versuffix=$major.$revision
9411d656433aSmrg	  ;;
9412d656433aSmrg
94130a6b08f8Smrg	linux) # correct to gnu/linux during the next big refactor
9414d656433aSmrg	  func_arith $current - $age
9415d656433aSmrg	  major=.$func_arith_result
9416300346aeSmrg	  versuffix=$major.$age.$revision
9417d656433aSmrg	  ;;
9418d656433aSmrg
9419d656433aSmrg	osf)
9420d656433aSmrg	  func_arith $current - $age
9421d656433aSmrg	  major=.$func_arith_result
9422300346aeSmrg	  versuffix=.$current.$age.$revision
9423300346aeSmrg	  verstring=$current.$age.$revision
9424d656433aSmrg
9425d656433aSmrg	  # Add in all the interfaces that we are compatible with.
9426d656433aSmrg	  loop=$age
9427300346aeSmrg	  while test 0 -ne "$loop"; do
9428d656433aSmrg	    func_arith $current - $loop
9429d656433aSmrg	    iface=$func_arith_result
9430d656433aSmrg	    func_arith $loop - 1
9431d656433aSmrg	    loop=$func_arith_result
9432300346aeSmrg	    verstring=$verstring:$iface.0
9433d656433aSmrg	  done
9434d656433aSmrg
9435d656433aSmrg	  # Make executables depend on our current version.
9436300346aeSmrg	  func_append verstring ":$current.0"
9437d656433aSmrg	  ;;
9438d656433aSmrg
9439d656433aSmrg	qnx)
94406bea0e4fSmrg	  func_arith $current - $age
94416bea0e4fSmrg	  major=.$func_arith_result
94426bea0e4fSmrg	  versuffix=$major.$age.$revision
9443300346aeSmrg	  ;;
9444300346aeSmrg
9445300346aeSmrg	sco)
9446300346aeSmrg	  major=.$current
9447300346aeSmrg	  versuffix=.$current
9448d656433aSmrg	  ;;
9449d656433aSmrg
9450d656433aSmrg	sunos)
9451300346aeSmrg	  major=.$current
9452300346aeSmrg	  versuffix=.$current.$revision
9453d656433aSmrg	  ;;
9454d656433aSmrg
9455d656433aSmrg	windows)
9456d656433aSmrg	  # Use '-' rather than '.', since we only want one
9457300346aeSmrg	  # extension on DOS 8.3 file systems.
9458d656433aSmrg	  func_arith $current - $age
9459d656433aSmrg	  major=$func_arith_result
9460300346aeSmrg	  versuffix=-$major
9461d656433aSmrg	  ;;
9462d656433aSmrg
9463d656433aSmrg	*)
9464300346aeSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9465d656433aSmrg	  ;;
9466d656433aSmrg	esac
9467d656433aSmrg
9468d656433aSmrg	# Clear the version info if we defaulted, and they specified a release.
9469d656433aSmrg	if test -z "$vinfo" && test -n "$release"; then
9470d656433aSmrg	  major=
9471d656433aSmrg	  case $version_type in
9472d656433aSmrg	  darwin)
9473d656433aSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
9474d656433aSmrg	    # problems, so we reset it completely
9475d656433aSmrg	    verstring=
9476d656433aSmrg	    ;;
9477d656433aSmrg	  *)
9478300346aeSmrg	    verstring=0.0
9479d656433aSmrg	    ;;
9480d656433aSmrg	  esac
9481300346aeSmrg	  if test no = "$need_version"; then
9482d656433aSmrg	    versuffix=
9483d656433aSmrg	  else
9484300346aeSmrg	    versuffix=.0.0
9485d656433aSmrg	  fi
9486d656433aSmrg	fi
9487d656433aSmrg
9488d656433aSmrg	# Remove version info from name if versioning should be avoided
9489300346aeSmrg	if test yes,no = "$avoid_version,$need_version"; then
9490d656433aSmrg	  major=
9491d656433aSmrg	  versuffix=
9492300346aeSmrg	  verstring=
9493d656433aSmrg	fi
9494d656433aSmrg
9495d656433aSmrg	# Check to see if the archive will have undefined symbols.
9496300346aeSmrg	if test yes = "$allow_undefined"; then
9497300346aeSmrg	  if test unsupported = "$allow_undefined_flag"; then
9498300346aeSmrg	    if test yes = "$build_old_libs"; then
9499300346aeSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9500300346aeSmrg	      build_libtool_libs=no
9501300346aeSmrg	    else
9502300346aeSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9503300346aeSmrg	    fi
9504d656433aSmrg	  fi
9505d656433aSmrg	else
9506d656433aSmrg	  # Don't allow undefined symbols.
9507300346aeSmrg	  allow_undefined_flag=$no_undefined_flag
9508d656433aSmrg	fi
9509d656433aSmrg
9510d656433aSmrg      fi
9511d656433aSmrg
9512300346aeSmrg      func_generate_dlsyms "$libname" "$libname" :
95133c15da26Smrg      func_append libobjs " $symfileobj"
9514300346aeSmrg      test " " = "$libobjs" && libobjs=
9515d656433aSmrg
9516300346aeSmrg      if test relink != "$opt_mode"; then
9517d656433aSmrg	# Remove our outputs, but don't remove object files since they
9518d656433aSmrg	# may have been created when compiling PIC objects.
9519d656433aSmrg	removelist=
9520d656433aSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
9521d656433aSmrg	for p in $tempremovelist; do
9522d656433aSmrg	  case $p in
9523d656433aSmrg	    *.$objext | *.gcno)
9524d656433aSmrg	       ;;
9525300346aeSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9526300346aeSmrg	       if test -n "$precious_files_regex"; then
9527d656433aSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9528d656433aSmrg		 then
9529d656433aSmrg		   continue
9530d656433aSmrg		 fi
9531d656433aSmrg	       fi
95323c15da26Smrg	       func_append removelist " $p"
9533d656433aSmrg	       ;;
9534d656433aSmrg	    *) ;;
9535d656433aSmrg	  esac
9536d656433aSmrg	done
9537d656433aSmrg	test -n "$removelist" && \
9538d656433aSmrg	  func_show_eval "${RM}r \$removelist"
9539d656433aSmrg      fi
9540d656433aSmrg
9541d656433aSmrg      # Now set the variables for building old libraries.
9542300346aeSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
95433c15da26Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9544d656433aSmrg
9545d656433aSmrg	# Transform .lo files to .o files.
9546300346aeSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9547d656433aSmrg      fi
9548d656433aSmrg
9549d656433aSmrg      # Eliminate all temporary directories.
9550d656433aSmrg      #for path in $notinst_path; do
9551555991fdSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9552555991fdSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9553555991fdSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9554d656433aSmrg      #done
9555d656433aSmrg
9556d656433aSmrg      if test -n "$xrpath"; then
9557d656433aSmrg	# If the user specified any rpath flags, then add them.
9558d656433aSmrg	temp_xrpath=
9559d656433aSmrg	for libdir in $xrpath; do
95603c15da26Smrg	  func_replace_sysroot "$libdir"
95613c15da26Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9562d656433aSmrg	  case "$finalize_rpath " in
9563d656433aSmrg	  *" $libdir "*) ;;
95643c15da26Smrg	  *) func_append finalize_rpath " $libdir" ;;
9565d656433aSmrg	  esac
9566d656433aSmrg	done
9567300346aeSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9568d656433aSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
9569d656433aSmrg	fi
9570d656433aSmrg      fi
9571d656433aSmrg
9572d656433aSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9573300346aeSmrg      old_dlfiles=$dlfiles
9574d656433aSmrg      dlfiles=
9575d656433aSmrg      for lib in $old_dlfiles; do
9576d656433aSmrg	case " $dlprefiles $dlfiles " in
9577d656433aSmrg	*" $lib "*) ;;
95783c15da26Smrg	*) func_append dlfiles " $lib" ;;
9579d656433aSmrg	esac
9580d656433aSmrg      done
9581d656433aSmrg
9582d656433aSmrg      # Make sure dlprefiles contains only unique files
9583300346aeSmrg      old_dlprefiles=$dlprefiles
9584d656433aSmrg      dlprefiles=
9585d656433aSmrg      for lib in $old_dlprefiles; do
9586d656433aSmrg	case "$dlprefiles " in
9587d656433aSmrg	*" $lib "*) ;;
95883c15da26Smrg	*) func_append dlprefiles " $lib" ;;
9589d656433aSmrg	esac
9590d656433aSmrg      done
9591d656433aSmrg
9592300346aeSmrg      if test yes = "$build_libtool_libs"; then
9593d656433aSmrg	if test -n "$rpath"; then
9594d656433aSmrg	  case $host in
95956bea0e4fSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9596d656433aSmrg	    # these systems don't actually have a c library (as such)!
9597d656433aSmrg	    ;;
9598d656433aSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
9599d656433aSmrg	    # Rhapsody C library is in the System framework
96003c15da26Smrg	    func_append deplibs " System.ltframework"
9601d656433aSmrg	    ;;
9602d656433aSmrg	  *-*-netbsd*)
9603d656433aSmrg	    # Don't link with libc until the a.out ld.so is fixed.
9604d656433aSmrg	    ;;
96053fb97780Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9606d656433aSmrg	    # Do not include libc due to us having libc/libc_r.
9607d656433aSmrg	    ;;
9608d656433aSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9609d656433aSmrg	    # Causes problems with __ctype
9610d656433aSmrg	    ;;
9611d656433aSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9612d656433aSmrg	    # Compiler inserts libc in the correct place for threads to work
9613d656433aSmrg	    ;;
9614d656433aSmrg	  *)
9615d656433aSmrg	    # Add libc to deplibs on all other systems if necessary.
9616300346aeSmrg	    if test yes = "$build_libtool_need_lc"; then
96173c15da26Smrg	      func_append deplibs " -lc"
9618d656433aSmrg	    fi
9619d656433aSmrg	    ;;
9620d656433aSmrg	  esac
9621d656433aSmrg	fi
9622d656433aSmrg
9623d656433aSmrg	# Transform deplibs into only deplibs that can be linked in shared.
9624d656433aSmrg	name_save=$name
9625d656433aSmrg	libname_save=$libname
9626d656433aSmrg	release_save=$release
9627d656433aSmrg	versuffix_save=$versuffix
9628d656433aSmrg	major_save=$major
9629d656433aSmrg	# I'm not sure if I'm treating the release correctly.  I think
9630d656433aSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9631d656433aSmrg	# add it in twice.  Is that correct?
9632300346aeSmrg	release=
9633300346aeSmrg	versuffix=
9634300346aeSmrg	major=
9635d656433aSmrg	newdeplibs=
9636d656433aSmrg	droppeddeps=no
9637d656433aSmrg	case $deplibs_check_method in
9638d656433aSmrg	pass_all)
9639d656433aSmrg	  # Don't check for shared/static.  Everything works.
9640d656433aSmrg	  # This might be a little naive.  We might want to check
9641d656433aSmrg	  # whether the library exists or not.  But this is on
9642d656433aSmrg	  # osf3 & osf4 and I'm not really sure... Just
9643d656433aSmrg	  # implementing what was already the behavior.
9644d656433aSmrg	  newdeplibs=$deplibs
9645d656433aSmrg	  ;;
9646d656433aSmrg	file_magic*)
9647d656433aSmrg	  set dummy $deplibs_check_method; shift
9648d656433aSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9649d656433aSmrg	  for a_deplib in $deplibs; do
9650d656433aSmrg	    case $a_deplib in
9651d656433aSmrg	    -l*)
9652d656433aSmrg	      func_stripname -l '' "$a_deplib"
9653d656433aSmrg	      name=$func_stripname_result
9654300346aeSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9655d656433aSmrg		case " $predeps $postdeps " in
9656d656433aSmrg		*" $a_deplib "*)
96573c15da26Smrg		  func_append newdeplibs " $a_deplib"
9658300346aeSmrg		  a_deplib=
9659d656433aSmrg		  ;;
9660d656433aSmrg		esac
9661d656433aSmrg	      fi
9662300346aeSmrg	      if test -n "$a_deplib"; then
9663d656433aSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96643c15da26Smrg		if test -n "$file_magic_glob"; then
96653c15da26Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
96663c15da26Smrg		else
96673c15da26Smrg		  libnameglob=$libname
96683c15da26Smrg		fi
9669300346aeSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9670d656433aSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9671300346aeSmrg		  if test yes = "$want_nocaseglob"; then
96723c15da26Smrg		    shopt -s nocaseglob
96733c15da26Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
96743c15da26Smrg		    $nocaseglob
96753c15da26Smrg		  else
96763c15da26Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
96773c15da26Smrg		  fi
9678d656433aSmrg		  for potent_lib in $potential_libs; do
9679d656433aSmrg		      # Follow soft links.
9680d656433aSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9681d656433aSmrg			 $GREP " -> " >/dev/null; then
9682d656433aSmrg			continue
9683d656433aSmrg		      fi
9684d656433aSmrg		      # The statement above tries to avoid entering an
9685d656433aSmrg		      # endless loop below, in case of cyclic links.
9686d656433aSmrg		      # We might still enter an endless loop, since a link
9687d656433aSmrg		      # loop can be closed while we follow links,
9688d656433aSmrg		      # but so what?
9689300346aeSmrg		      potlib=$potent_lib
9690d656433aSmrg		      while test -h "$potlib" 2>/dev/null; do
9691300346aeSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9692d656433aSmrg			case $potliblink in
9693300346aeSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9694300346aeSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9695d656433aSmrg			esac
9696d656433aSmrg		      done
9697d656433aSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9698d656433aSmrg			 $SED -e 10q |
9699d656433aSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
97003c15da26Smrg			func_append newdeplibs " $a_deplib"
9701300346aeSmrg			a_deplib=
9702d656433aSmrg			break 2
9703d656433aSmrg		      fi
9704d656433aSmrg		  done
9705d656433aSmrg		done
9706d656433aSmrg	      fi
9707300346aeSmrg	      if test -n "$a_deplib"; then
9708d656433aSmrg		droppeddeps=yes
97096bea0e4fSmrg		func_warning "Linker path does not have real file for library $a_deplib."
97106bea0e4fSmrg		func_warning "I have the capability to make that library automatically link in when"
97116bea0e4fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
97126bea0e4fSmrg		func_warning "shared version of the library, which you do not appear to have"
97136bea0e4fSmrg		func_warning "because I did check the linker path looking for a file starting"
9714300346aeSmrg		if test -z "$potlib"; then
97156bea0e4fSmrg		  func_warning "with $libname but no candidates were found. (...for file magic test)"
9716d656433aSmrg		else
97176bea0e4fSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
97186bea0e4fSmrg		  func_warning "using a file magic. Last file checked: $potlib"
9719d656433aSmrg		fi
9720d656433aSmrg	      fi
9721d656433aSmrg	      ;;
9722d656433aSmrg	    *)
9723d656433aSmrg	      # Add a -L argument.
97243c15da26Smrg	      func_append newdeplibs " $a_deplib"
9725d656433aSmrg	      ;;
9726d656433aSmrg	    esac
9727d656433aSmrg	  done # Gone through all deplibs.
9728d656433aSmrg	  ;;
9729d656433aSmrg	match_pattern*)
9730d656433aSmrg	  set dummy $deplibs_check_method; shift
9731d656433aSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9732d656433aSmrg	  for a_deplib in $deplibs; do
9733d656433aSmrg	    case $a_deplib in
9734d656433aSmrg	    -l*)
9735d656433aSmrg	      func_stripname -l '' "$a_deplib"
9736d656433aSmrg	      name=$func_stripname_result
9737300346aeSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9738d656433aSmrg		case " $predeps $postdeps " in
9739d656433aSmrg		*" $a_deplib "*)
97403c15da26Smrg		  func_append newdeplibs " $a_deplib"
9741300346aeSmrg		  a_deplib=
9742d656433aSmrg		  ;;
9743d656433aSmrg		esac
9744d656433aSmrg	      fi
9745300346aeSmrg	      if test -n "$a_deplib"; then
9746d656433aSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9747d656433aSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9748d656433aSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9749d656433aSmrg		  for potent_lib in $potential_libs; do
9750300346aeSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9751555991fdSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9752d656433aSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
97533c15da26Smrg		      func_append newdeplibs " $a_deplib"
9754300346aeSmrg		      a_deplib=
9755d656433aSmrg		      break 2
9756d656433aSmrg		    fi
9757d656433aSmrg		  done
9758d656433aSmrg		done
9759d656433aSmrg	      fi
9760300346aeSmrg	      if test -n "$a_deplib"; then
9761d656433aSmrg		droppeddeps=yes
97626bea0e4fSmrg		func_warning "Linker path does not have real file for library $a_deplib."
97636bea0e4fSmrg		func_warning "I have the capability to make that library automatically link in when"
97646bea0e4fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
97656bea0e4fSmrg		func_warning "shared version of the library, which you do not appear to have"
97666bea0e4fSmrg		func_warning "because I did check the linker path looking for a file starting"
9767300346aeSmrg		if test -z "$potlib"; then
97686bea0e4fSmrg		  func_warning "with $libname but no candidates were found. (...for regex pattern test)"
9769d656433aSmrg		else
97706bea0e4fSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
97716bea0e4fSmrg		  func_warning "using a regex pattern. Last file checked: $potlib"
9772d656433aSmrg		fi
9773d656433aSmrg	      fi
9774d656433aSmrg	      ;;
9775d656433aSmrg	    *)
9776d656433aSmrg	      # Add a -L argument.
97773c15da26Smrg	      func_append newdeplibs " $a_deplib"
9778d656433aSmrg	      ;;
9779d656433aSmrg	    esac
9780d656433aSmrg	  done # Gone through all deplibs.
9781d656433aSmrg	  ;;
9782d656433aSmrg	none | unknown | *)
9783300346aeSmrg	  newdeplibs=
9784555991fdSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9785300346aeSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9786300346aeSmrg	    for i in $predeps $postdeps; do
9787d656433aSmrg	      # can't use Xsed below, because $i might contain '/'
9788300346aeSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9789d656433aSmrg	    done
9790d656433aSmrg	  fi
9791555991fdSmrg	  case $tmp_deplibs in
9792555991fdSmrg	  *[!\	\ ]*)
9793555991fdSmrg	    echo
9794300346aeSmrg	    if test none = "$deplibs_check_method"; then
97956bea0e4fSmrg	      func_warning "Inter-library dependencies are not supported in this platform."
9796d656433aSmrg	    else
97976bea0e4fSmrg	      func_warning "Inter-library dependencies are not known to be supported."
9798d656433aSmrg	    fi
97996bea0e4fSmrg	    func_warning "All declared inter-library dependencies are being dropped."
9800d656433aSmrg	    droppeddeps=yes
9801555991fdSmrg	    ;;
9802555991fdSmrg	  esac
9803d656433aSmrg	  ;;
9804d656433aSmrg	esac
9805d656433aSmrg	versuffix=$versuffix_save
9806d656433aSmrg	major=$major_save
9807d656433aSmrg	release=$release_save
9808d656433aSmrg	libname=$libname_save
9809d656433aSmrg	name=$name_save
9810d656433aSmrg
9811d656433aSmrg	case $host in
9812d656433aSmrg	*-*-rhapsody* | *-*-darwin1.[012])
9813d656433aSmrg	  # On Rhapsody replace the C library with the System framework
9814555991fdSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9815d656433aSmrg	  ;;
9816d656433aSmrg	esac
9817d656433aSmrg
9818300346aeSmrg	if test yes = "$droppeddeps"; then
9819300346aeSmrg	  if test yes = "$module"; then
98206bea0e4fSmrg	    func_warning "libtool could not satisfy all declared inter-library"
98216bea0e4fSmrg	    func_warning "dependencies of module $libname.  Therefore, libtool will create"
98226bea0e4fSmrg	    func_warning "a static module, that should work as long as the dlopening"
98236bea0e4fSmrg	    func_warning "application is linked with the -dlopen flag."
9824d656433aSmrg	    if test -z "$global_symbol_pipe"; then
98256bea0e4fSmrg	      func_warning "However, this would only work if libtool was able to extract symbol"
98266bea0e4fSmrg	      func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
98276bea0e4fSmrg	      func_warning "not find such a program.  So, this module is probably useless."
98286bea0e4fSmrg	      func_warning "'nm' from GNU binutils and a full rebuild may help."
9829d656433aSmrg	    fi
9830300346aeSmrg	    if test no = "$build_old_libs"; then
9831300346aeSmrg	      oldlibs=$output_objdir/$libname.$libext
9832d656433aSmrg	      build_libtool_libs=module
9833d656433aSmrg	      build_old_libs=yes
9834d656433aSmrg	    else
9835d656433aSmrg	      build_libtool_libs=no
9836d656433aSmrg	    fi
9837d656433aSmrg	  else
9838555991fdSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9839555991fdSmrg	    echo "*** automatically added whenever a program is linked with this library"
9840555991fdSmrg	    echo "*** or is declared to -dlopen it."
9841d656433aSmrg
9842300346aeSmrg	    if test no = "$allow_undefined"; then
9843555991fdSmrg	      echo
9844555991fdSmrg	      echo "*** Since this library must not contain undefined symbols,"
9845555991fdSmrg	      echo "*** because either the platform does not support them or"
9846555991fdSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9847555991fdSmrg	      echo "*** libtool will only create a static version of it."
9848300346aeSmrg	      if test no = "$build_old_libs"; then
9849300346aeSmrg		oldlibs=$output_objdir/$libname.$libext
9850d656433aSmrg		build_libtool_libs=module
9851d656433aSmrg		build_old_libs=yes
9852d656433aSmrg	      else
9853d656433aSmrg		build_libtool_libs=no
9854d656433aSmrg	      fi
9855d656433aSmrg	    fi
9856d656433aSmrg	  fi
9857d656433aSmrg	fi
9858d656433aSmrg	# Done checking deplibs!
9859d656433aSmrg	deplibs=$newdeplibs
9860d656433aSmrg      fi
9861d656433aSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9862d656433aSmrg      case $host in
9863d656433aSmrg	*-*-darwin*)
9864555991fdSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9865555991fdSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9866555991fdSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9867d656433aSmrg	  ;;
9868d656433aSmrg      esac
9869d656433aSmrg
9870d656433aSmrg      # move library search paths that coincide with paths to not yet
9871d656433aSmrg      # installed libraries to the beginning of the library search list
9872d656433aSmrg      new_libs=
9873d656433aSmrg      for path in $notinst_path; do
9874d656433aSmrg	case " $new_libs " in
9875d656433aSmrg	*" -L$path/$objdir "*) ;;
9876d656433aSmrg	*)
9877d656433aSmrg	  case " $deplibs " in
9878d656433aSmrg	  *" -L$path/$objdir "*)
98793c15da26Smrg	    func_append new_libs " -L$path/$objdir" ;;
9880d656433aSmrg	  esac
9881d656433aSmrg	  ;;
9882d656433aSmrg	esac
9883d656433aSmrg      done
9884d656433aSmrg      for deplib in $deplibs; do
9885d656433aSmrg	case $deplib in
9886d656433aSmrg	-L*)
9887d656433aSmrg	  case " $new_libs " in
9888d656433aSmrg	  *" $deplib "*) ;;
98893c15da26Smrg	  *) func_append new_libs " $deplib" ;;
9890d656433aSmrg	  esac
9891d656433aSmrg	  ;;
98923c15da26Smrg	*) func_append new_libs " $deplib" ;;
9893d656433aSmrg	esac
9894d656433aSmrg      done
9895300346aeSmrg      deplibs=$new_libs
9896d656433aSmrg
9897d656433aSmrg      # All the library-specific variables (install_libdir is set above).
9898d656433aSmrg      library_names=
9899d656433aSmrg      old_library=
9900d656433aSmrg      dlname=
9901d656433aSmrg
9902d656433aSmrg      # Test again, we may have decided not to build it any more
9903300346aeSmrg      if test yes = "$build_libtool_libs"; then
9904300346aeSmrg	# Remove $wl instances when linking with ld.
99050a6b08f8Smrg	# FIXME: should test the right _cmds variable.
99060a6b08f8Smrg	case $archive_cmds in
99070a6b08f8Smrg	  *\$LD\ *) wl= ;;
99080a6b08f8Smrg        esac
9909300346aeSmrg	if test yes = "$hardcode_into_libs"; then
9910d656433aSmrg	  # Hardcode the library paths
9911d656433aSmrg	  hardcode_libdirs=
9912d656433aSmrg	  dep_rpath=
9913300346aeSmrg	  rpath=$finalize_rpath
9914300346aeSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9915d656433aSmrg	  for libdir in $rpath; do
9916d656433aSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
9917d656433aSmrg	      if test -n "$hardcode_libdir_separator"; then
99183c15da26Smrg		func_replace_sysroot "$libdir"
99193c15da26Smrg		libdir=$func_replace_sysroot_result
9920d656433aSmrg		if test -z "$hardcode_libdirs"; then
9921300346aeSmrg		  hardcode_libdirs=$libdir
9922d656433aSmrg		else
9923d656433aSmrg		  # Just accumulate the unique libdirs.
9924d656433aSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9925d656433aSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9926d656433aSmrg		    ;;
9927d656433aSmrg		  *)
99283c15da26Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9929d656433aSmrg		    ;;
9930d656433aSmrg		  esac
9931d656433aSmrg		fi
9932d656433aSmrg	      else
9933d656433aSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
99343c15da26Smrg		func_append dep_rpath " $flag"
9935d656433aSmrg	      fi
9936d656433aSmrg	    elif test -n "$runpath_var"; then
9937d656433aSmrg	      case "$perm_rpath " in
9938d656433aSmrg	      *" $libdir "*) ;;
99390a6b08f8Smrg	      *) func_append perm_rpath " $libdir" ;;
9940d656433aSmrg	      esac
9941d656433aSmrg	    fi
9942d656433aSmrg	  done
9943d656433aSmrg	  # Substitute the hardcoded libdirs into the rpath.
9944d656433aSmrg	  if test -n "$hardcode_libdir_separator" &&
9945d656433aSmrg	     test -n "$hardcode_libdirs"; then
9946300346aeSmrg	    libdir=$hardcode_libdirs
99470a6b08f8Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9948d656433aSmrg	  fi
9949d656433aSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9950d656433aSmrg	    # We should set the runpath_var.
9951d656433aSmrg	    rpath=
9952d656433aSmrg	    for dir in $perm_rpath; do
99533c15da26Smrg	      func_append rpath "$dir:"
9954d656433aSmrg	    done
9955d656433aSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9956d656433aSmrg	  fi
9957d656433aSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9958d656433aSmrg	fi
9959126a8a12Smrg
9960300346aeSmrg	shlibpath=$finalize_shlibpath
9961300346aeSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9962d656433aSmrg	if test -n "$shlibpath"; then
9963d656433aSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9964d656433aSmrg	fi
9965126a8a12Smrg
9966d656433aSmrg	# Get the real and link names of the library.
9967d656433aSmrg	eval shared_ext=\"$shrext_cmds\"
9968d656433aSmrg	eval library_names=\"$library_names_spec\"
9969d656433aSmrg	set dummy $library_names
9970d656433aSmrg	shift
9971300346aeSmrg	realname=$1
9972d656433aSmrg	shift
9973126a8a12Smrg
9974d656433aSmrg	if test -n "$soname_spec"; then
9975d656433aSmrg	  eval soname=\"$soname_spec\"
9976d656433aSmrg	else
9977300346aeSmrg	  soname=$realname
9978d656433aSmrg	fi
9979d656433aSmrg	if test -z "$dlname"; then
9980d656433aSmrg	  dlname=$soname
9981d656433aSmrg	fi
9982126a8a12Smrg
9983300346aeSmrg	lib=$output_objdir/$realname
9984d656433aSmrg	linknames=
9985d656433aSmrg	for link
9986d656433aSmrg	do
99873c15da26Smrg	  func_append linknames " $link"
9988d656433aSmrg	done
9989126a8a12Smrg
9990d656433aSmrg	# Use standard objects if they are pic
9991555991fdSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9992d656433aSmrg	test "X$libobjs" = "X " && libobjs=
9993126a8a12Smrg
9994d656433aSmrg	delfiles=
9995d656433aSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9996d656433aSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9997300346aeSmrg	  export_symbols=$output_objdir/$libname.uexp
99983c15da26Smrg	  func_append delfiles " $export_symbols"
9999d656433aSmrg	fi
10000126a8a12Smrg
10001d656433aSmrg	orig_export_symbols=
10002d656433aSmrg	case $host_os in
100036bea0e4fSmrg	cygwin* | mingw* | windows* | cegcc*)
10004d656433aSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
10005d656433aSmrg	    # exporting using user supplied symfile
10006300346aeSmrg	    func_dll_def_p "$export_symbols" || {
10007d656433aSmrg	      # and it's NOT already a .def file. Must figure out
10008d656433aSmrg	      # which of the given symbols are data symbols and tag
10009d656433aSmrg	      # them as such. So, trigger use of export_symbols_cmds.
10010d656433aSmrg	      # export_symbols gets reassigned inside the "prepare
10011d656433aSmrg	      # the list of exported symbols" if statement, so the
10012d656433aSmrg	      # include_expsyms logic still works.
10013300346aeSmrg	      orig_export_symbols=$export_symbols
10014d656433aSmrg	      export_symbols=
10015d656433aSmrg	      always_export_symbols=yes
10016300346aeSmrg	    }
10017d656433aSmrg	  fi
10018d656433aSmrg	  ;;
10019d656433aSmrg	esac
10020126a8a12Smrg
10021d656433aSmrg	# Prepare the list of exported symbols
10022d656433aSmrg	if test -z "$export_symbols"; then
10023300346aeSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
10024300346aeSmrg	    func_verbose "generating symbol list for '$libname.la'"
10025300346aeSmrg	    export_symbols=$output_objdir/$libname.exp
10026d656433aSmrg	    $opt_dry_run || $RM $export_symbols
10027d656433aSmrg	    cmds=$export_symbols_cmds
10028300346aeSmrg	    save_ifs=$IFS; IFS='~'
100293c15da26Smrg	    for cmd1 in $cmds; do
10030300346aeSmrg	      IFS=$save_ifs
100313c15da26Smrg	      # Take the normal branch if the nm_file_list_spec branch
100323c15da26Smrg	      # doesn't work or if tool conversion is not needed.
100333c15da26Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
100343c15da26Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
100353c15da26Smrg		  try_normal_branch=yes
100363c15da26Smrg		  eval cmd=\"$cmd1\"
100373c15da26Smrg		  func_len " $cmd"
100383c15da26Smrg		  len=$func_len_result
100393c15da26Smrg		  ;;
100403c15da26Smrg		*)
100413c15da26Smrg		  try_normal_branch=no
100423c15da26Smrg		  ;;
100433c15da26Smrg	      esac
10044300346aeSmrg	      if test yes = "$try_normal_branch" \
100453c15da26Smrg		 && { test "$len" -lt "$max_cmd_len" \
100463c15da26Smrg		      || test "$max_cmd_len" -le -1; }
100473c15da26Smrg	      then
100483c15da26Smrg		func_show_eval "$cmd" 'exit $?'
100493c15da26Smrg		skipped_export=false
100503c15da26Smrg	      elif test -n "$nm_file_list_spec"; then
100513c15da26Smrg		func_basename "$output"
100523c15da26Smrg		output_la=$func_basename_result
100533c15da26Smrg		save_libobjs=$libobjs
100543c15da26Smrg		save_output=$output
10055300346aeSmrg		output=$output_objdir/$output_la.nm
100563c15da26Smrg		func_to_tool_file "$output"
100573c15da26Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
100583c15da26Smrg		func_append delfiles " $output"
100593c15da26Smrg		func_verbose "creating $NM input file list: $output"
100603c15da26Smrg		for obj in $save_libobjs; do
100613c15da26Smrg		  func_to_tool_file "$obj"
100623c15da26Smrg		  $ECHO "$func_to_tool_file_result"
100633c15da26Smrg		done > "$output"
100643c15da26Smrg		eval cmd=\"$cmd1\"
10065d656433aSmrg		func_show_eval "$cmd" 'exit $?'
100663c15da26Smrg		output=$save_output
100673c15da26Smrg		libobjs=$save_libobjs
10068d656433aSmrg		skipped_export=false
10069d656433aSmrg	      else
10070d656433aSmrg		# The command line is too long to execute in one step.
10071d656433aSmrg		func_verbose "using reloadable object file for export list..."
10072d656433aSmrg		skipped_export=:
10073d656433aSmrg		# Break out early, otherwise skipped_export may be
10074d656433aSmrg		# set to false by a later but shorter cmd.
10075d656433aSmrg		break
10076d656433aSmrg	      fi
10077d656433aSmrg	    done
10078300346aeSmrg	    IFS=$save_ifs
10079300346aeSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
10080d656433aSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10081d656433aSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10082d656433aSmrg	    fi
10083d656433aSmrg	  fi
10084d656433aSmrg	fi
10085126a8a12Smrg
10086d656433aSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
10087300346aeSmrg	  tmp_export_symbols=$export_symbols
10088300346aeSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10089555991fdSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10090d656433aSmrg	fi
10091126a8a12Smrg
10092300346aeSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10093d656433aSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10094300346aeSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10095d656433aSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10096300346aeSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10097d656433aSmrg	  # though. Also, the filter scales superlinearly with the number of
10098d656433aSmrg	  # global variables. join(1) would be nice here, but unfortunately
10099d656433aSmrg	  # isn't a blessed tool.
10100d656433aSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
101013c15da26Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10102d656433aSmrg	  export_symbols=$output_objdir/$libname.def
10103d656433aSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10104126a8a12Smrg	fi
10105126a8a12Smrg
10106d656433aSmrg	tmp_deplibs=
10107d656433aSmrg	for test_deplib in $deplibs; do
10108d656433aSmrg	  case " $convenience " in
10109d656433aSmrg	  *" $test_deplib "*) ;;
10110d656433aSmrg	  *)
101113c15da26Smrg	    func_append tmp_deplibs " $test_deplib"
10112d656433aSmrg	    ;;
10113d656433aSmrg	  esac
10114d656433aSmrg	done
10115300346aeSmrg	deplibs=$tmp_deplibs
10116126a8a12Smrg
10117d656433aSmrg	if test -n "$convenience"; then
10118d656433aSmrg	  if test -n "$whole_archive_flag_spec" &&
10119300346aeSmrg	    test yes = "$compiler_needs_object" &&
10120d656433aSmrg	    test -z "$libobjs"; then
10121d656433aSmrg	    # extract the archives, so we have objects to list.
10122d656433aSmrg	    # TODO: could optimize this to just extract one archive.
10123d656433aSmrg	    whole_archive_flag_spec=
10124d656433aSmrg	  fi
10125d656433aSmrg	  if test -n "$whole_archive_flag_spec"; then
10126d656433aSmrg	    save_libobjs=$libobjs
10127d656433aSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10128d656433aSmrg	    test "X$libobjs" = "X " && libobjs=
10129d656433aSmrg	  else
10130300346aeSmrg	    gentop=$output_objdir/${outputname}x
101313c15da26Smrg	    func_append generated " $gentop"
10132126a8a12Smrg
10133d656433aSmrg	    func_extract_archives $gentop $convenience
101343c15da26Smrg	    func_append libobjs " $func_extract_archives_result"
10135d656433aSmrg	    test "X$libobjs" = "X " && libobjs=
10136d656433aSmrg	  fi
10137d656433aSmrg	fi
10138126a8a12Smrg
10139300346aeSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10140d656433aSmrg	  eval flag=\"$thread_safe_flag_spec\"
101413c15da26Smrg	  func_append linker_flags " $flag"
10142d656433aSmrg	fi
10143126a8a12Smrg
10144d656433aSmrg	# Make a backup of the uninstalled library when relinking
10145300346aeSmrg	if test relink = "$opt_mode"; then
10146d656433aSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10147126a8a12Smrg	fi
10148126a8a12Smrg
10149d656433aSmrg	# Do each of the archive commands.
10150300346aeSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10151d656433aSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10152d656433aSmrg	    eval test_cmds=\"$module_expsym_cmds\"
10153d656433aSmrg	    cmds=$module_expsym_cmds
10154d656433aSmrg	  else
10155d656433aSmrg	    eval test_cmds=\"$module_cmds\"
10156d656433aSmrg	    cmds=$module_cmds
10157d656433aSmrg	  fi
10158d656433aSmrg	else
10159d656433aSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10160d656433aSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
10161d656433aSmrg	    cmds=$archive_expsym_cmds
10162d656433aSmrg	  else
10163d656433aSmrg	    eval test_cmds=\"$archive_cmds\"
10164d656433aSmrg	    cmds=$archive_cmds
10165d656433aSmrg	  fi
10166126a8a12Smrg	fi
10167126a8a12Smrg
10168300346aeSmrg	if test : != "$skipped_export" &&
10169d656433aSmrg	   func_len " $test_cmds" &&
10170d656433aSmrg	   len=$func_len_result &&
10171d656433aSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10172d656433aSmrg	  :
10173d656433aSmrg	else
10174d656433aSmrg	  # The command line is too long to link in one step, link piecewise
10175d656433aSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10176d656433aSmrg	  # script.
10177126a8a12Smrg
10178d656433aSmrg	  # Save the value of $output and $libobjs because we want to
10179d656433aSmrg	  # use them later.  If we have whole_archive_flag_spec, we
10180d656433aSmrg	  # want to use save_libobjs as it was before
10181d656433aSmrg	  # whole_archive_flag_spec was expanded, because we can't
10182d656433aSmrg	  # assume the linker understands whole_archive_flag_spec.
10183d656433aSmrg	  # This may have to be revisited, in case too many
10184d656433aSmrg	  # convenience libraries get linked in and end up exceeding
10185d656433aSmrg	  # the spec.
10186d656433aSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10187d656433aSmrg	    save_libobjs=$libobjs
10188d656433aSmrg	  fi
10189d656433aSmrg	  save_output=$output
10190555991fdSmrg	  func_basename "$output"
10191555991fdSmrg	  output_la=$func_basename_result
10192126a8a12Smrg
10193d656433aSmrg	  # Clear the reloadable object creation command queue and
10194d656433aSmrg	  # initialize k to one.
10195d656433aSmrg	  test_cmds=
10196d656433aSmrg	  concat_cmds=
10197d656433aSmrg	  objlist=
10198d656433aSmrg	  last_robj=
10199d656433aSmrg	  k=1
10200126a8a12Smrg
102016bea0e4fSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10202300346aeSmrg	    output=$output_objdir/$output_la.lnk
10203d656433aSmrg	    func_verbose "creating linker input file list: $output"
10204d656433aSmrg	    : > $output
10205d656433aSmrg	    set x $save_libobjs
10206d656433aSmrg	    shift
10207d656433aSmrg	    firstobj=
10208300346aeSmrg	    if test yes = "$compiler_needs_object"; then
10209d656433aSmrg	      firstobj="$1 "
10210d656433aSmrg	      shift
10211d656433aSmrg	    fi
10212d656433aSmrg	    for obj
10213d656433aSmrg	    do
102143c15da26Smrg	      func_to_tool_file "$obj"
102153c15da26Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10216d656433aSmrg	    done
102173c15da26Smrg	    func_append delfiles " $output"
102183c15da26Smrg	    func_to_tool_file "$output"
102193c15da26Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
102206bea0e4fSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
102216bea0e4fSmrg	    output=$output_objdir/$output_la.lnkscript
102226bea0e4fSmrg	    func_verbose "creating GNU ld script: $output"
102236bea0e4fSmrg	    echo 'INPUT (' > $output
102246bea0e4fSmrg	    for obj in $save_libobjs
102256bea0e4fSmrg	    do
102266bea0e4fSmrg	      func_to_tool_file "$obj"
102276bea0e4fSmrg	      $ECHO "$func_to_tool_file_result" >> $output
102286bea0e4fSmrg	    done
102296bea0e4fSmrg	    echo ')' >> $output
102306bea0e4fSmrg	    func_append delfiles " $output"
102316bea0e4fSmrg	    func_to_tool_file "$output"
102326bea0e4fSmrg	    output=$func_to_tool_file_result
10233d656433aSmrg	  else
10234d656433aSmrg	    if test -n "$save_libobjs"; then
10235d656433aSmrg	      func_verbose "creating reloadable object files..."
10236300346aeSmrg	      output=$output_objdir/$output_la-$k.$objext
10237d656433aSmrg	      eval test_cmds=\"$reload_cmds\"
10238d656433aSmrg	      func_len " $test_cmds"
10239d656433aSmrg	      len0=$func_len_result
10240d656433aSmrg	      len=$len0
10241d656433aSmrg
10242d656433aSmrg	      # Loop over the list of objects to be linked.
10243d656433aSmrg	      for obj in $save_libobjs
10244d656433aSmrg	      do
10245d656433aSmrg		func_len " $obj"
10246d656433aSmrg		func_arith $len + $func_len_result
10247d656433aSmrg		len=$func_arith_result
10248300346aeSmrg		if test -z "$objlist" ||
10249d656433aSmrg		   test "$len" -lt "$max_cmd_len"; then
10250d656433aSmrg		  func_append objlist " $obj"
10251d656433aSmrg		else
10252d656433aSmrg		  # The command $test_cmds is almost too long, add a
10253d656433aSmrg		  # command to the queue.
10254300346aeSmrg		  if test 1 -eq "$k"; then
10255d656433aSmrg		    # The first file doesn't have a previous command to add.
10256555991fdSmrg		    reload_objs=$objlist
10257555991fdSmrg		    eval concat_cmds=\"$reload_cmds\"
10258d656433aSmrg		  else
10259d656433aSmrg		    # All subsequent reloadable object files will link in
10260d656433aSmrg		    # the last one created.
10261555991fdSmrg		    reload_objs="$objlist $last_robj"
10262555991fdSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10263d656433aSmrg		  fi
10264300346aeSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10265d656433aSmrg		  func_arith $k + 1
10266d656433aSmrg		  k=$func_arith_result
10267300346aeSmrg		  output=$output_objdir/$output_la-$k.$objext
10268555991fdSmrg		  objlist=" $obj"
10269d656433aSmrg		  func_len " $last_robj"
10270d656433aSmrg		  func_arith $len0 + $func_len_result
10271d656433aSmrg		  len=$func_arith_result
10272d656433aSmrg		fi
10273d656433aSmrg	      done
10274d656433aSmrg	      # Handle the remaining objects by creating one last
10275d656433aSmrg	      # reloadable object file.  All subsequent reloadable object
10276d656433aSmrg	      # files will link in the last one created.
10277d656433aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10278555991fdSmrg	      reload_objs="$objlist $last_robj"
10279300346aeSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10280d656433aSmrg	      if test -n "$last_robj"; then
10281300346aeSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10282d656433aSmrg	      fi
102833c15da26Smrg	      func_append delfiles " $output"
10284126a8a12Smrg
10285d656433aSmrg	    else
10286d656433aSmrg	      output=
10287d656433aSmrg	    fi
10288d656433aSmrg
10289300346aeSmrg	    ${skipped_export-false} && {
10290300346aeSmrg	      func_verbose "generating symbol list for '$libname.la'"
10291300346aeSmrg	      export_symbols=$output_objdir/$libname.exp
10292d656433aSmrg	      $opt_dry_run || $RM $export_symbols
10293d656433aSmrg	      libobjs=$output
10294d656433aSmrg	      # Append the command to create the export file.
10295d656433aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10296d656433aSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10297d656433aSmrg	      if test -n "$last_robj"; then
10298d656433aSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10299d656433aSmrg	      fi
10300300346aeSmrg	    }
10301126a8a12Smrg
10302d656433aSmrg	    test -n "$save_libobjs" &&
10303d656433aSmrg	      func_verbose "creating a temporary reloadable object file: $output"
10304126a8a12Smrg
10305d656433aSmrg	    # Loop through the commands generated above and execute them.
10306300346aeSmrg	    save_ifs=$IFS; IFS='~'
10307d656433aSmrg	    for cmd in $concat_cmds; do
10308300346aeSmrg	      IFS=$save_ifs
10309300346aeSmrg	      $opt_quiet || {
103103fb97780Smrg		  func_quote_arg expand,pretty "$cmd"
103113fb97780Smrg		  eval "func_echo $func_quote_arg_result"
10312d656433aSmrg	      }
10313d656433aSmrg	      $opt_dry_run || eval "$cmd" || {
10314d656433aSmrg		lt_exit=$?
10315d656433aSmrg
10316d656433aSmrg		# Restore the uninstalled library and exit
10317300346aeSmrg		if test relink = "$opt_mode"; then
10318d656433aSmrg		  ( cd "$output_objdir" && \
10319d656433aSmrg		    $RM "${realname}T" && \
10320d656433aSmrg		    $MV "${realname}U" "$realname" )
10321d656433aSmrg		fi
10322126a8a12Smrg
10323d656433aSmrg		exit $lt_exit
10324d656433aSmrg	      }
10325d656433aSmrg	    done
10326300346aeSmrg	    IFS=$save_ifs
10327126a8a12Smrg
10328d656433aSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10329d656433aSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10330d656433aSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10331126a8a12Smrg	    fi
10332126a8a12Smrg	  fi
10333126a8a12Smrg
10334300346aeSmrg          ${skipped_export-false} && {
10335d656433aSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10336300346aeSmrg	      tmp_export_symbols=$export_symbols
10337300346aeSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10338555991fdSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10339d656433aSmrg	    fi
10340126a8a12Smrg
10341d656433aSmrg	    if test -n "$orig_export_symbols"; then
10342d656433aSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10343300346aeSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10344d656433aSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10345300346aeSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10346d656433aSmrg	      # though. Also, the filter scales superlinearly with the number of
10347d656433aSmrg	      # global variables. join(1) would be nice here, but unfortunately
10348d656433aSmrg	      # isn't a blessed tool.
10349d656433aSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
103503c15da26Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10351d656433aSmrg	      export_symbols=$output_objdir/$libname.def
10352d656433aSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10353d656433aSmrg	    fi
10354300346aeSmrg	  }
10355126a8a12Smrg
10356d656433aSmrg	  libobjs=$output
10357d656433aSmrg	  # Restore the value of output.
10358d656433aSmrg	  output=$save_output
10359126a8a12Smrg
10360d656433aSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10361d656433aSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10362d656433aSmrg	    test "X$libobjs" = "X " && libobjs=
10363d656433aSmrg	  fi
10364d656433aSmrg	  # Expand the library linking commands again to reset the
10365d656433aSmrg	  # value of $libobjs for piecewise linking.
10366d656433aSmrg
10367d656433aSmrg	  # Do each of the archive commands.
10368300346aeSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10369d656433aSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10370d656433aSmrg	      cmds=$module_expsym_cmds
10371126a8a12Smrg	    else
10372d656433aSmrg	      cmds=$module_cmds
10373126a8a12Smrg	    fi
10374126a8a12Smrg	  else
10375d656433aSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10376d656433aSmrg	      cmds=$archive_expsym_cmds
10377d656433aSmrg	    else
10378d656433aSmrg	      cmds=$archive_cmds
10379d656433aSmrg	    fi
10380126a8a12Smrg	  fi
10381126a8a12Smrg	fi
10382126a8a12Smrg
10383d656433aSmrg	if test -n "$delfiles"; then
10384d656433aSmrg	  # Append the command to remove temporary files to $cmds.
10385d656433aSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10386d656433aSmrg	fi
10387126a8a12Smrg
10388d656433aSmrg	# Add any objects from preloaded convenience libraries
10389d656433aSmrg	if test -n "$dlprefiles"; then
10390300346aeSmrg	  gentop=$output_objdir/${outputname}x
103913c15da26Smrg	  func_append generated " $gentop"
10392126a8a12Smrg
10393d656433aSmrg	  func_extract_archives $gentop $dlprefiles
103943c15da26Smrg	  func_append libobjs " $func_extract_archives_result"
10395d656433aSmrg	  test "X$libobjs" = "X " && libobjs=
10396126a8a12Smrg	fi
10397126a8a12Smrg
10398300346aeSmrg	save_ifs=$IFS; IFS='~'
10399d656433aSmrg	for cmd in $cmds; do
10400300346aeSmrg	  IFS=$sp$nl
10401d656433aSmrg	  eval cmd=\"$cmd\"
10402300346aeSmrg	  IFS=$save_ifs
10403300346aeSmrg	  $opt_quiet || {
104043fb97780Smrg	    func_quote_arg expand,pretty "$cmd"
104053fb97780Smrg	    eval "func_echo $func_quote_arg_result"
10406d656433aSmrg	  }
10407d656433aSmrg	  $opt_dry_run || eval "$cmd" || {
10408d656433aSmrg	    lt_exit=$?
10409126a8a12Smrg
10410d656433aSmrg	    # Restore the uninstalled library and exit
10411300346aeSmrg	    if test relink = "$opt_mode"; then
10412d656433aSmrg	      ( cd "$output_objdir" && \
10413d656433aSmrg	        $RM "${realname}T" && \
10414d656433aSmrg		$MV "${realname}U" "$realname" )
10415126a8a12Smrg	    fi
10416126a8a12Smrg
10417d656433aSmrg	    exit $lt_exit
10418d656433aSmrg	  }
10419d656433aSmrg	done
10420300346aeSmrg	IFS=$save_ifs
10421126a8a12Smrg
10422d656433aSmrg	# Restore the uninstalled library and exit
10423300346aeSmrg	if test relink = "$opt_mode"; then
10424d656433aSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10425126a8a12Smrg
10426d656433aSmrg	  if test -n "$convenience"; then
10427d656433aSmrg	    if test -z "$whole_archive_flag_spec"; then
10428d656433aSmrg	      func_show_eval '${RM}r "$gentop"'
10429d656433aSmrg	    fi
10430d656433aSmrg	  fi
10431126a8a12Smrg
10432d656433aSmrg	  exit $EXIT_SUCCESS
10433d656433aSmrg	fi
10434126a8a12Smrg
10435d656433aSmrg	# Create links to the real library.
10436d656433aSmrg	for linkname in $linknames; do
10437d656433aSmrg	  if test "$realname" != "$linkname"; then
10438d656433aSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10439126a8a12Smrg	  fi
10440126a8a12Smrg	done
10441126a8a12Smrg
10442d656433aSmrg	# If -module or -export-dynamic was specified, set the dlname.
10443300346aeSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10444d656433aSmrg	  # On all known operating systems, these are identical.
10445300346aeSmrg	  dlname=$soname
10446d656433aSmrg	fi
10447d656433aSmrg      fi
10448126a8a12Smrg      ;;
10449126a8a12Smrg
10450d656433aSmrg    obj)
10451300346aeSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10452300346aeSmrg	func_warning "'-dlopen' is ignored for objects"
10453d656433aSmrg      fi
10454126a8a12Smrg
10455d656433aSmrg      case " $deplibs" in
10456d656433aSmrg      *\ -l* | *\ -L*)
10457300346aeSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10458126a8a12Smrg      esac
10459126a8a12Smrg
10460d656433aSmrg      test -n "$rpath" && \
10461300346aeSmrg	func_warning "'-rpath' is ignored for objects"
10462126a8a12Smrg
10463d656433aSmrg      test -n "$xrpath" && \
10464300346aeSmrg	func_warning "'-R' is ignored for objects"
10465126a8a12Smrg
10466d656433aSmrg      test -n "$vinfo" && \
10467300346aeSmrg	func_warning "'-version-info' is ignored for objects"
10468d656433aSmrg
10469d656433aSmrg      test -n "$release" && \
10470300346aeSmrg	func_warning "'-release' is ignored for objects"
10471d656433aSmrg
10472d656433aSmrg      case $output in
10473d656433aSmrg      *.lo)
10474d656433aSmrg	test -n "$objs$old_deplibs" && \
10475300346aeSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10476d656433aSmrg
10477d656433aSmrg	libobj=$output
10478d656433aSmrg	func_lo2o "$libobj"
10479d656433aSmrg	obj=$func_lo2o_result
10480126a8a12Smrg	;;
10481126a8a12Smrg      *)
10482d656433aSmrg	libobj=
10483300346aeSmrg	obj=$output
10484126a8a12Smrg	;;
10485126a8a12Smrg      esac
10486126a8a12Smrg
10487d656433aSmrg      # Delete the old objects.
10488d656433aSmrg      $opt_dry_run || $RM $obj $libobj
10489126a8a12Smrg
10490d656433aSmrg      # Objects from convenience libraries.  This assumes
10491d656433aSmrg      # single-version convenience libraries.  Whenever we create
10492d656433aSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10493d656433aSmrg      # the extraction.
10494d656433aSmrg      reload_conv_objs=
10495d656433aSmrg      gentop=
10496300346aeSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10497300346aeSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10498300346aeSmrg      # into space.
10499300346aeSmrg      case $reload_cmds in
10500300346aeSmrg        *\$LD[\ \$]*) wl= ;;
10501300346aeSmrg      esac
10502d656433aSmrg      if test -n "$convenience"; then
10503d656433aSmrg	if test -n "$whole_archive_flag_spec"; then
10504d656433aSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10505300346aeSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10506300346aeSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10507d656433aSmrg	else
10508300346aeSmrg	  gentop=$output_objdir/${obj}x
105093c15da26Smrg	  func_append generated " $gentop"
10510126a8a12Smrg
10511d656433aSmrg	  func_extract_archives $gentop $convenience
10512d656433aSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10513d656433aSmrg	fi
10514126a8a12Smrg      fi
10515126a8a12Smrg
105163c15da26Smrg      # If we're not building shared, we need to use non_pic_objs
10517300346aeSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
105183c15da26Smrg
10519d656433aSmrg      # Create the old-style object.
10520300346aeSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10521126a8a12Smrg
10522300346aeSmrg      output=$obj
10523d656433aSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10524126a8a12Smrg
10525d656433aSmrg      # Exit if we aren't doing a library object file.
10526d656433aSmrg      if test -z "$libobj"; then
10527d656433aSmrg	if test -n "$gentop"; then
10528d656433aSmrg	  func_show_eval '${RM}r "$gentop"'
10529d656433aSmrg	fi
10530d656433aSmrg
10531d656433aSmrg	exit $EXIT_SUCCESS
10532126a8a12Smrg      fi
10533d656433aSmrg
10534300346aeSmrg      test yes = "$build_libtool_libs" || {
10535d656433aSmrg	if test -n "$gentop"; then
10536d656433aSmrg	  func_show_eval '${RM}r "$gentop"'
10537d656433aSmrg	fi
10538d656433aSmrg
10539d656433aSmrg	# Create an invalid libtool object if no PIC, so that we don't
10540d656433aSmrg	# accidentally link it into a program.
10541d656433aSmrg	# $show "echo timestamp > $libobj"
10542d656433aSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10543d656433aSmrg	exit $EXIT_SUCCESS
10544300346aeSmrg      }
10545d656433aSmrg
10546300346aeSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10547d656433aSmrg	# Only do commands if we really have different PIC objects.
10548d656433aSmrg	reload_objs="$libobjs $reload_conv_objs"
10549300346aeSmrg	output=$libobj
10550d656433aSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
10551d656433aSmrg      fi
10552d656433aSmrg
10553d656433aSmrg      if test -n "$gentop"; then
10554d656433aSmrg	func_show_eval '${RM}r "$gentop"'
10555d656433aSmrg      fi
10556d656433aSmrg
10557d656433aSmrg      exit $EXIT_SUCCESS
10558126a8a12Smrg      ;;
10559126a8a12Smrg
10560d656433aSmrg    prog)
10561d656433aSmrg      case $host in
10562d656433aSmrg	*cygwin*) func_stripname '' '.exe' "$output"
10563d656433aSmrg	          output=$func_stripname_result.exe;;
10564d656433aSmrg      esac
10565d656433aSmrg      test -n "$vinfo" && \
10566300346aeSmrg	func_warning "'-version-info' is ignored for programs"
10567126a8a12Smrg
10568d656433aSmrg      test -n "$release" && \
10569300346aeSmrg	func_warning "'-release' is ignored for programs"
10570126a8a12Smrg
10571300346aeSmrg      $preload \
10572300346aeSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10573300346aeSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10574d656433aSmrg
10575d656433aSmrg      case $host in
10576d656433aSmrg      *-*-rhapsody* | *-*-darwin1.[012])
10577d656433aSmrg	# On Rhapsody replace the C library is the System framework
10578555991fdSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10579555991fdSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10580126a8a12Smrg	;;
10581d656433aSmrg      esac
10582126a8a12Smrg
10583d656433aSmrg      case $host in
10584d656433aSmrg      *-*-darwin*)
10585d656433aSmrg	# Don't allow lazy linking, it breaks C++ global constructors
10586d656433aSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10587300346aeSmrg	if test CXX = "$tagname"; then
10588d656433aSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10589d656433aSmrg	    10.[0123])
10590300346aeSmrg	      func_append compile_command " $wl-bind_at_load"
10591300346aeSmrg	      func_append finalize_command " $wl-bind_at_load"
10592d656433aSmrg	    ;;
10593d656433aSmrg	  esac
10594126a8a12Smrg	fi
10595d656433aSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10596555991fdSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10597555991fdSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10598d656433aSmrg	;;
10599d656433aSmrg      esac
10600126a8a12Smrg
10601126a8a12Smrg
10602d656433aSmrg      # move library search paths that coincide with paths to not yet
10603d656433aSmrg      # installed libraries to the beginning of the library search list
10604d656433aSmrg      new_libs=
10605d656433aSmrg      for path in $notinst_path; do
10606d656433aSmrg	case " $new_libs " in
10607d656433aSmrg	*" -L$path/$objdir "*) ;;
10608d656433aSmrg	*)
10609d656433aSmrg	  case " $compile_deplibs " in
10610d656433aSmrg	  *" -L$path/$objdir "*)
106113c15da26Smrg	    func_append new_libs " -L$path/$objdir" ;;
10612126a8a12Smrg	  esac
10613d656433aSmrg	  ;;
10614d656433aSmrg	esac
10615d656433aSmrg      done
10616d656433aSmrg      for deplib in $compile_deplibs; do
10617d656433aSmrg	case $deplib in
10618d656433aSmrg	-L*)
10619d656433aSmrg	  case " $new_libs " in
10620d656433aSmrg	  *" $deplib "*) ;;
106213c15da26Smrg	  *) func_append new_libs " $deplib" ;;
10622126a8a12Smrg	  esac
10623d656433aSmrg	  ;;
106243c15da26Smrg	*) func_append new_libs " $deplib" ;;
10625d656433aSmrg	esac
10626d656433aSmrg      done
10627300346aeSmrg      compile_deplibs=$new_libs
10628126a8a12Smrg
10629126a8a12Smrg
106303c15da26Smrg      func_append compile_command " $compile_deplibs"
106313c15da26Smrg      func_append finalize_command " $finalize_deplibs"
10632126a8a12Smrg
10633d656433aSmrg      if test -n "$rpath$xrpath"; then
10634d656433aSmrg	# If the user specified any rpath flags, then add them.
10635d656433aSmrg	for libdir in $rpath $xrpath; do
10636d656433aSmrg	  # This is the magic to use -rpath.
10637d656433aSmrg	  case "$finalize_rpath " in
10638d656433aSmrg	  *" $libdir "*) ;;
106393c15da26Smrg	  *) func_append finalize_rpath " $libdir" ;;
10640d656433aSmrg	  esac
10641d656433aSmrg	done
10642d656433aSmrg      fi
10643126a8a12Smrg
10644d656433aSmrg      # Now hardcode the library paths
10645d656433aSmrg      rpath=
10646d656433aSmrg      hardcode_libdirs=
10647d656433aSmrg      for libdir in $compile_rpath $finalize_rpath; do
10648d656433aSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10649d656433aSmrg	  if test -n "$hardcode_libdir_separator"; then
10650d656433aSmrg	    if test -z "$hardcode_libdirs"; then
10651300346aeSmrg	      hardcode_libdirs=$libdir
10652d656433aSmrg	    else
10653d656433aSmrg	      # Just accumulate the unique libdirs.
10654d656433aSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10655d656433aSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10656d656433aSmrg		;;
10657d656433aSmrg	      *)
106583c15da26Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10659d656433aSmrg		;;
10660d656433aSmrg	      esac
10661d656433aSmrg	    fi
10662126a8a12Smrg	  else
10663d656433aSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
106643c15da26Smrg	    func_append rpath " $flag"
10665126a8a12Smrg	  fi
10666d656433aSmrg	elif test -n "$runpath_var"; then
10667d656433aSmrg	  case "$perm_rpath " in
10668d656433aSmrg	  *" $libdir "*) ;;
106693c15da26Smrg	  *) func_append perm_rpath " $libdir" ;;
10670d656433aSmrg	  esac
10671d656433aSmrg	fi
10672d656433aSmrg	case $host in
106736bea0e4fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
10674300346aeSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10675d656433aSmrg	  case :$dllsearchpath: in
10676d656433aSmrg	  *":$libdir:"*) ;;
10677d656433aSmrg	  ::) dllsearchpath=$libdir;;
106783c15da26Smrg	  *) func_append dllsearchpath ":$libdir";;
10679d656433aSmrg	  esac
10680d656433aSmrg	  case :$dllsearchpath: in
10681d656433aSmrg	  *":$testbindir:"*) ;;
10682d656433aSmrg	  ::) dllsearchpath=$testbindir;;
106833c15da26Smrg	  *) func_append dllsearchpath ":$testbindir";;
10684d656433aSmrg	  esac
10685d656433aSmrg	  ;;
10686d656433aSmrg	esac
10687d656433aSmrg      done
10688d656433aSmrg      # Substitute the hardcoded libdirs into the rpath.
10689d656433aSmrg      if test -n "$hardcode_libdir_separator" &&
10690d656433aSmrg	 test -n "$hardcode_libdirs"; then
10691300346aeSmrg	libdir=$hardcode_libdirs
10692d656433aSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10693d656433aSmrg      fi
10694300346aeSmrg      compile_rpath=$rpath
10695126a8a12Smrg
10696d656433aSmrg      rpath=
10697d656433aSmrg      hardcode_libdirs=
10698d656433aSmrg      for libdir in $finalize_rpath; do
10699d656433aSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10700d656433aSmrg	  if test -n "$hardcode_libdir_separator"; then
10701d656433aSmrg	    if test -z "$hardcode_libdirs"; then
10702300346aeSmrg	      hardcode_libdirs=$libdir
10703d656433aSmrg	    else
10704d656433aSmrg	      # Just accumulate the unique libdirs.
10705d656433aSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10706d656433aSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10707d656433aSmrg		;;
10708d656433aSmrg	      *)
107093c15da26Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10710d656433aSmrg		;;
10711d656433aSmrg	      esac
10712d656433aSmrg	    fi
10713126a8a12Smrg	  else
10714d656433aSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
107153c15da26Smrg	    func_append rpath " $flag"
10716126a8a12Smrg	  fi
10717d656433aSmrg	elif test -n "$runpath_var"; then
10718d656433aSmrg	  case "$finalize_perm_rpath " in
10719d656433aSmrg	  *" $libdir "*) ;;
107203c15da26Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10721d656433aSmrg	  esac
10722126a8a12Smrg	fi
10723d656433aSmrg      done
10724d656433aSmrg      # Substitute the hardcoded libdirs into the rpath.
10725d656433aSmrg      if test -n "$hardcode_libdir_separator" &&
10726d656433aSmrg	 test -n "$hardcode_libdirs"; then
10727300346aeSmrg	libdir=$hardcode_libdirs
10728d656433aSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10729d656433aSmrg      fi
10730300346aeSmrg      finalize_rpath=$rpath
10731126a8a12Smrg
10732300346aeSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10733d656433aSmrg	# Transform all the library objects into standard objects.
10734555991fdSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10735555991fdSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10736d656433aSmrg      fi
10737126a8a12Smrg
10738300346aeSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10739126a8a12Smrg
10740d656433aSmrg      # template prelinking step
10741d656433aSmrg      if test -n "$prelink_cmds"; then
10742d656433aSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10743d656433aSmrg      fi
10744126a8a12Smrg
10745300346aeSmrg      wrappers_required=:
10746d656433aSmrg      case $host in
10747555991fdSmrg      *cegcc* | *mingw32ce*)
10748555991fdSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10749300346aeSmrg        wrappers_required=false
10750555991fdSmrg        ;;
107516bea0e4fSmrg      *cygwin* | *mingw* | *windows* )
10752300346aeSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10753d656433aSmrg        ;;
10754d656433aSmrg      *)
10755300346aeSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10756300346aeSmrg          wrappers_required=false
10757d656433aSmrg        fi
10758d656433aSmrg        ;;
10759d656433aSmrg      esac
10760300346aeSmrg      $wrappers_required || {
10761d656433aSmrg	# Replace the output file specification.
10762555991fdSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10763300346aeSmrg	link_command=$compile_command$compile_rpath
10764126a8a12Smrg
10765d656433aSmrg	# We have no uninstalled library dependencies, so finalize right now.
10766d656433aSmrg	exit_status=0
10767d656433aSmrg	func_show_eval "$link_command" 'exit_status=$?'
10768126a8a12Smrg
107693c15da26Smrg	if test -n "$postlink_cmds"; then
107703c15da26Smrg	  func_to_tool_file "$output"
107713c15da26Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
107723c15da26Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
107733c15da26Smrg	fi
107743c15da26Smrg
10775d656433aSmrg	# Delete the generated files.
10776300346aeSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10777300346aeSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10778126a8a12Smrg	fi
10779126a8a12Smrg
10780d656433aSmrg	exit $exit_status
10781300346aeSmrg      }
10782126a8a12Smrg
10783d656433aSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10784d656433aSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10785d656433aSmrg      fi
10786d656433aSmrg      if test -n "$finalize_shlibpath"; then
10787d656433aSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10788d656433aSmrg      fi
10789126a8a12Smrg
10790d656433aSmrg      compile_var=
10791d656433aSmrg      finalize_var=
10792d656433aSmrg      if test -n "$runpath_var"; then
10793d656433aSmrg	if test -n "$perm_rpath"; then
10794d656433aSmrg	  # We should set the runpath_var.
10795d656433aSmrg	  rpath=
10796d656433aSmrg	  for dir in $perm_rpath; do
107973c15da26Smrg	    func_append rpath "$dir:"
10798d656433aSmrg	  done
10799d656433aSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10800126a8a12Smrg	fi
10801d656433aSmrg	if test -n "$finalize_perm_rpath"; then
10802d656433aSmrg	  # We should set the runpath_var.
10803d656433aSmrg	  rpath=
10804d656433aSmrg	  for dir in $finalize_perm_rpath; do
108053c15da26Smrg	    func_append rpath "$dir:"
10806d656433aSmrg	  done
10807d656433aSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10808126a8a12Smrg	fi
10809d656433aSmrg      fi
10810126a8a12Smrg
10811300346aeSmrg      if test yes = "$no_install"; then
10812d656433aSmrg	# We don't need to create a wrapper script.
10813300346aeSmrg	link_command=$compile_var$compile_command$compile_rpath
10814d656433aSmrg	# Replace the output file specification.
10815555991fdSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10816d656433aSmrg	# Delete the old output file.
10817d656433aSmrg	$opt_dry_run || $RM $output
10818d656433aSmrg	# Link the executable and exit
10819d656433aSmrg	func_show_eval "$link_command" 'exit $?'
108203c15da26Smrg
108213c15da26Smrg	if test -n "$postlink_cmds"; then
108223c15da26Smrg	  func_to_tool_file "$output"
108233c15da26Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
108243c15da26Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
108253c15da26Smrg	fi
108263c15da26Smrg
10827126a8a12Smrg	exit $EXIT_SUCCESS
10828d656433aSmrg      fi
10829126a8a12Smrg
10830300346aeSmrg      case $hardcode_action,$fast_install in
10831300346aeSmrg        relink,*)
10832300346aeSmrg	  # Fast installation is not supported
10833300346aeSmrg	  link_command=$compile_var$compile_command$compile_rpath
10834300346aeSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10835d656433aSmrg
10836300346aeSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10837300346aeSmrg	  func_warning "'$output' will be relinked during installation"
10838300346aeSmrg	  ;;
10839300346aeSmrg        *,yes)
10840300346aeSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10841300346aeSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10842300346aeSmrg          ;;
10843300346aeSmrg	*,no)
10844300346aeSmrg	  link_command=$compile_var$compile_command$compile_rpath
10845300346aeSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10846300346aeSmrg          ;;
10847300346aeSmrg	*,needless)
10848300346aeSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10849300346aeSmrg	  relink_command=
10850300346aeSmrg          ;;
10851300346aeSmrg      esac
10852126a8a12Smrg
10853d656433aSmrg      # Replace the output file specification.
10854555991fdSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10855126a8a12Smrg
10856d656433aSmrg      # Delete the old output files.
10857d656433aSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10858126a8a12Smrg
10859d656433aSmrg      func_show_eval "$link_command" 'exit $?'
10860126a8a12Smrg
108613c15da26Smrg      if test -n "$postlink_cmds"; then
108623c15da26Smrg	func_to_tool_file "$output_objdir/$outputname"
108633c15da26Smrg	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'`
108643c15da26Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
108653c15da26Smrg      fi
108663c15da26Smrg
10867d656433aSmrg      # Now create the wrapper script.
10868d656433aSmrg      func_verbose "creating $output"
10869126a8a12Smrg
10870d656433aSmrg      # Quote the relink command for shipping.
10871d656433aSmrg      if test -n "$relink_command"; then
10872d656433aSmrg	# Preserve any variables that may affect compiler behavior
10873d656433aSmrg	for var in $variables_saved_for_relink; do
10874d656433aSmrg	  if eval test -z \"\${$var+set}\"; then
10875d656433aSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10876d656433aSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10877d656433aSmrg	    relink_command="$var=; export $var; $relink_command"
10878126a8a12Smrg	  else
108793fb97780Smrg	    func_quote_arg pretty "$var_value"
108803fb97780Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10881126a8a12Smrg	  fi
10882d656433aSmrg	done
108833fb97780Smrg	func_quote eval cd "`pwd`"
108843fb97780Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
108853fb97780Smrg	relink_command=$func_quote_arg_unquoted_result
10886d656433aSmrg      fi
10887d656433aSmrg
10888d656433aSmrg      # Only actually do things if not in dry run mode.
10889d656433aSmrg      $opt_dry_run || {
10890d656433aSmrg	# win32 will think the script is a binary if it has
10891d656433aSmrg	# a .exe suffix, so we strip it off here.
10892d656433aSmrg	case $output in
10893d656433aSmrg	  *.exe) func_stripname '' '.exe' "$output"
10894d656433aSmrg	         output=$func_stripname_result ;;
10895d656433aSmrg	esac
10896d656433aSmrg	# test for cygwin because mv fails w/o .exe extensions
10897d656433aSmrg	case $host in
10898d656433aSmrg	  *cygwin*)
10899d656433aSmrg	    exeext=.exe
10900d656433aSmrg	    func_stripname '' '.exe' "$outputname"
10901d656433aSmrg	    outputname=$func_stripname_result ;;
10902d656433aSmrg	  *) exeext= ;;
10903126a8a12Smrg	esac
10904d656433aSmrg	case $host in
109056bea0e4fSmrg	  *cygwin* | *mingw* | windows* )
10906d656433aSmrg	    func_dirname_and_basename "$output" "" "."
10907d656433aSmrg	    output_name=$func_basename_result
10908d656433aSmrg	    output_path=$func_dirname_result
10909300346aeSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10910300346aeSmrg	    cwrapper=$output_path/$output_name.exe
10911d656433aSmrg	    $RM $cwrappersource $cwrapper
10912d656433aSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10913d656433aSmrg
10914d656433aSmrg	    func_emit_cwrapperexe_src > $cwrappersource
10915d656433aSmrg
10916d656433aSmrg	    # The wrapper executable is built using the $host compiler,
10917d656433aSmrg	    # because it contains $host paths and files. If cross-
10918d656433aSmrg	    # compiling, it, like the target executable, must be
10919d656433aSmrg	    # executed on the $host or under an emulation environment.
10920d656433aSmrg	    $opt_dry_run || {
10921d656433aSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10922d656433aSmrg	      $STRIP $cwrapper
10923d656433aSmrg	    }
10924126a8a12Smrg
10925d656433aSmrg	    # Now, create the wrapper script for func_source use:
10926d656433aSmrg	    func_ltwrapper_scriptname $cwrapper
10927d656433aSmrg	    $RM $func_ltwrapper_scriptname_result
10928d656433aSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10929d656433aSmrg	    $opt_dry_run || {
10930d656433aSmrg	      # note: this script will not be executed, so do not chmod.
10931300346aeSmrg	      if test "x$build" = "x$host"; then
10932d656433aSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10933d656433aSmrg	      else
10934d656433aSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10935d656433aSmrg	      fi
10936d656433aSmrg	    }
10937d656433aSmrg	  ;;
10938d656433aSmrg	  * )
10939d656433aSmrg	    $RM $output
10940d656433aSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10941126a8a12Smrg
10942d656433aSmrg	    func_emit_wrapper no > $output
10943d656433aSmrg	    chmod +x $output
10944d656433aSmrg	  ;;
10945d656433aSmrg	esac
10946d656433aSmrg      }
10947d656433aSmrg      exit $EXIT_SUCCESS
10948d656433aSmrg      ;;
10949d656433aSmrg    esac
10950126a8a12Smrg
10951d656433aSmrg    # See if we need to build an old-fashioned archive.
10952d656433aSmrg    for oldlib in $oldlibs; do
10953126a8a12Smrg
10954300346aeSmrg      case $build_libtool_libs in
10955300346aeSmrg        convenience)
10956300346aeSmrg	  oldobjs="$libobjs_save $symfileobj"
10957300346aeSmrg	  addlibs=$convenience
10958d656433aSmrg	  build_libtool_libs=no
10959300346aeSmrg	  ;;
10960300346aeSmrg	module)
10961300346aeSmrg	  oldobjs=$libobjs_save
10962300346aeSmrg	  addlibs=$old_convenience
10963300346aeSmrg	  build_libtool_libs=no
10964300346aeSmrg          ;;
10965300346aeSmrg	*)
10966d656433aSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10967300346aeSmrg	  $preload && test -f "$symfileobj" \
10968300346aeSmrg	    && func_append oldobjs " $symfileobj"
10969300346aeSmrg	  addlibs=$old_convenience
10970300346aeSmrg	  ;;
10971300346aeSmrg      esac
10972126a8a12Smrg
10973d656433aSmrg      if test -n "$addlibs"; then
10974300346aeSmrg	gentop=$output_objdir/${outputname}x
109753c15da26Smrg	func_append generated " $gentop"
10976126a8a12Smrg
10977d656433aSmrg	func_extract_archives $gentop $addlibs
109783c15da26Smrg	func_append oldobjs " $func_extract_archives_result"
10979d656433aSmrg      fi
10980126a8a12Smrg
10981d656433aSmrg      # Do each command in the archive commands.
10982300346aeSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10983d656433aSmrg	cmds=$old_archive_from_new_cmds
10984d656433aSmrg      else
10985126a8a12Smrg
10986d656433aSmrg	# Add any objects from preloaded convenience libraries
10987d656433aSmrg	if test -n "$dlprefiles"; then
10988300346aeSmrg	  gentop=$output_objdir/${outputname}x
109893c15da26Smrg	  func_append generated " $gentop"
10990126a8a12Smrg
10991d656433aSmrg	  func_extract_archives $gentop $dlprefiles
109923c15da26Smrg	  func_append oldobjs " $func_extract_archives_result"
10993d656433aSmrg	fi
10994126a8a12Smrg
10995d656433aSmrg	# POSIX demands no paths to be encoded in archives.  We have
10996d656433aSmrg	# to avoid creating archives with duplicate basenames if we
10997d656433aSmrg	# might have to extract them afterwards, e.g., when creating a
10998d656433aSmrg	# static archive out of a convenience library, or when linking
10999d656433aSmrg	# the entirety of a libtool archive into another (currently
11000d656433aSmrg	# not supported by libtool).
11001d656433aSmrg	if (for obj in $oldobjs
11002d656433aSmrg	    do
11003d656433aSmrg	      func_basename "$obj"
11004d656433aSmrg	      $ECHO "$func_basename_result"
11005d656433aSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
11006d656433aSmrg	  :
11007d656433aSmrg	else
11008555991fdSmrg	  echo "copying selected object files to avoid basename conflicts..."
11009300346aeSmrg	  gentop=$output_objdir/${outputname}x
110103c15da26Smrg	  func_append generated " $gentop"
11011d656433aSmrg	  func_mkdir_p "$gentop"
11012d656433aSmrg	  save_oldobjs=$oldobjs
11013d656433aSmrg	  oldobjs=
11014d656433aSmrg	  counter=1
11015d656433aSmrg	  for obj in $save_oldobjs
11016d656433aSmrg	  do
11017d656433aSmrg	    func_basename "$obj"
11018300346aeSmrg	    objbase=$func_basename_result
11019d656433aSmrg	    case " $oldobjs " in
11020d656433aSmrg	    " ") oldobjs=$obj ;;
11021d656433aSmrg	    *[\ /]"$objbase "*)
11022d656433aSmrg	      while :; do
11023d656433aSmrg		# Make sure we don't pick an alternate name that also
11024d656433aSmrg		# overlaps.
11025d656433aSmrg		newobj=lt$counter-$objbase
11026d656433aSmrg		func_arith $counter + 1
11027d656433aSmrg		counter=$func_arith_result
11028d656433aSmrg		case " $oldobjs " in
11029d656433aSmrg		*[\ /]"$newobj "*) ;;
11030d656433aSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
11031d656433aSmrg		esac
11032d656433aSmrg	      done
11033d656433aSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
110343c15da26Smrg	      func_append oldobjs " $gentop/$newobj"
11035d656433aSmrg	      ;;
110363c15da26Smrg	    *) func_append oldobjs " $obj" ;;
11037d656433aSmrg	    esac
11038126a8a12Smrg	  done
11039126a8a12Smrg	fi
110400a6b08f8Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
110410a6b08f8Smrg	tool_oldlib=$func_to_tool_file_result
11042d656433aSmrg	eval cmds=\"$old_archive_cmds\"
11043126a8a12Smrg
11044d656433aSmrg	func_len " $cmds"
11045d656433aSmrg	len=$func_len_result
11046d656433aSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
11047d656433aSmrg	  cmds=$old_archive_cmds
110483c15da26Smrg	elif test -n "$archiver_list_spec"; then
110493c15da26Smrg	  func_verbose "using command file archive linking..."
110503c15da26Smrg	  for obj in $oldobjs
110513c15da26Smrg	  do
110523c15da26Smrg	    func_to_tool_file "$obj"
110533c15da26Smrg	    $ECHO "$func_to_tool_file_result"
110543c15da26Smrg	  done > $output_objdir/$libname.libcmd
110553c15da26Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
110563c15da26Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
110573c15da26Smrg	  cmds=$old_archive_cmds
11058d656433aSmrg	else
11059d656433aSmrg	  # the command line is too long to link in one step, link in parts
11060d656433aSmrg	  func_verbose "using piecewise archive linking..."
11061d656433aSmrg	  save_RANLIB=$RANLIB
11062d656433aSmrg	  RANLIB=:
11063d656433aSmrg	  objlist=
11064d656433aSmrg	  concat_cmds=
11065d656433aSmrg	  save_oldobjs=$oldobjs
11066d656433aSmrg	  oldobjs=
11067d656433aSmrg	  # Is there a better way of finding the last object in the list?
11068d656433aSmrg	  for obj in $save_oldobjs
11069d656433aSmrg	  do
11070d656433aSmrg	    last_oldobj=$obj
11071d656433aSmrg	  done
11072d656433aSmrg	  eval test_cmds=\"$old_archive_cmds\"
11073d656433aSmrg	  func_len " $test_cmds"
11074d656433aSmrg	  len0=$func_len_result
11075d656433aSmrg	  len=$len0
11076d656433aSmrg	  for obj in $save_oldobjs
11077d656433aSmrg	  do
11078d656433aSmrg	    func_len " $obj"
11079d656433aSmrg	    func_arith $len + $func_len_result
11080d656433aSmrg	    len=$func_arith_result
11081d656433aSmrg	    func_append objlist " $obj"
11082d656433aSmrg	    if test "$len" -lt "$max_cmd_len"; then
11083d656433aSmrg	      :
11084d656433aSmrg	    else
11085d656433aSmrg	      # the above command should be used before it gets too long
11086d656433aSmrg	      oldobjs=$objlist
11087300346aeSmrg	      if test "$obj" = "$last_oldobj"; then
11088d656433aSmrg		RANLIB=$save_RANLIB
11089d656433aSmrg	      fi
11090d656433aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11091300346aeSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11092d656433aSmrg	      objlist=
11093d656433aSmrg	      len=$len0
11094d656433aSmrg	    fi
11095d656433aSmrg	  done
11096d656433aSmrg	  RANLIB=$save_RANLIB
11097d656433aSmrg	  oldobjs=$objlist
11098300346aeSmrg	  if test -z "$oldobjs"; then
11099d656433aSmrg	    eval cmds=\"\$concat_cmds\"
11100d656433aSmrg	  else
11101d656433aSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11102d656433aSmrg	  fi
11103d656433aSmrg	fi
11104d656433aSmrg      fi
11105d656433aSmrg      func_execute_cmds "$cmds" 'exit $?'
11106126a8a12Smrg    done
11107126a8a12Smrg
11108d656433aSmrg    test -n "$generated" && \
11109d656433aSmrg      func_show_eval "${RM}r$generated"
11110126a8a12Smrg
11111d656433aSmrg    # Now create the libtool archive.
11112d656433aSmrg    case $output in
11113d656433aSmrg    *.la)
11114d656433aSmrg      old_library=
11115300346aeSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11116d656433aSmrg      func_verbose "creating $output"
11117126a8a12Smrg
11118d656433aSmrg      # Preserve any variables that may affect compiler behavior
11119d656433aSmrg      for var in $variables_saved_for_relink; do
11120d656433aSmrg	if eval test -z \"\${$var+set}\"; then
11121d656433aSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11122d656433aSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
11123d656433aSmrg	  relink_command="$var=; export $var; $relink_command"
11124126a8a12Smrg	else
111253fb97780Smrg	  func_quote_arg pretty,unquoted "$var_value"
111263fb97780Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11127126a8a12Smrg	fi
11128d656433aSmrg      done
11129d656433aSmrg      # Quote the link command for shipping.
111303fb97780Smrg      func_quote eval cd "`pwd`"
111313fb97780Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
111323fb97780Smrg      func_quote_arg pretty,unquoted "$relink_command"
111333fb97780Smrg      relink_command=$func_quote_arg_unquoted_result
11134300346aeSmrg      if test yes = "$hardcode_automatic"; then
11135d656433aSmrg	relink_command=
11136d656433aSmrg      fi
11137126a8a12Smrg
11138d656433aSmrg      # Only create the output if not a dry run.
11139d656433aSmrg      $opt_dry_run || {
11140d656433aSmrg	for installed in no yes; do
11141300346aeSmrg	  if test yes = "$installed"; then
11142d656433aSmrg	    if test -z "$install_libdir"; then
11143d656433aSmrg	      break
11144d656433aSmrg	    fi
11145300346aeSmrg	    output=$output_objdir/${outputname}i
11146d656433aSmrg	    # Replace all uninstalled libtool libraries with the installed ones
11147d656433aSmrg	    newdependency_libs=
11148d656433aSmrg	    for deplib in $dependency_libs; do
11149d656433aSmrg	      case $deplib in
11150d656433aSmrg	      *.la)
11151d656433aSmrg		func_basename "$deplib"
11152300346aeSmrg		name=$func_basename_result
111530a6b08f8Smrg		func_resolve_sysroot "$deplib"
11154300346aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11155d656433aSmrg		test -z "$libdir" && \
11156300346aeSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
111573c15da26Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
111583c15da26Smrg		;;
111593c15da26Smrg	      -L*)
111603c15da26Smrg		func_stripname -L '' "$deplib"
111613c15da26Smrg		func_replace_sysroot "$func_stripname_result"
111623c15da26Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
111633c15da26Smrg		;;
111643c15da26Smrg	      -R*)
111653c15da26Smrg		func_stripname -R '' "$deplib"
111663c15da26Smrg		func_replace_sysroot "$func_stripname_result"
111673c15da26Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11168d656433aSmrg		;;
111693c15da26Smrg	      *) func_append newdependency_libs " $deplib" ;;
11170d656433aSmrg	      esac
11171d656433aSmrg	    done
11172300346aeSmrg	    dependency_libs=$newdependency_libs
11173d656433aSmrg	    newdlfiles=
11174d656433aSmrg
11175d656433aSmrg	    for lib in $dlfiles; do
11176d656433aSmrg	      case $lib in
11177d656433aSmrg	      *.la)
11178d656433aSmrg	        func_basename "$lib"
11179300346aeSmrg		name=$func_basename_result
11180300346aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11181d656433aSmrg		test -z "$libdir" && \
11182300346aeSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
111833c15da26Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11184d656433aSmrg		;;
111853c15da26Smrg	      *) func_append newdlfiles " $lib" ;;
11186d656433aSmrg	      esac
11187d656433aSmrg	    done
11188300346aeSmrg	    dlfiles=$newdlfiles
11189d656433aSmrg	    newdlprefiles=
11190d656433aSmrg	    for lib in $dlprefiles; do
11191d656433aSmrg	      case $lib in
11192d656433aSmrg	      *.la)
11193d656433aSmrg		# Only pass preopened files to the pseudo-archive (for
11194d656433aSmrg		# eventual linking with the app. that links it) if we
11195d656433aSmrg		# didn't already link the preopened objects directly into
11196d656433aSmrg		# the library:
11197d656433aSmrg		func_basename "$lib"
11198300346aeSmrg		name=$func_basename_result
11199300346aeSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11200d656433aSmrg		test -z "$libdir" && \
11201300346aeSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
112023c15da26Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11203d656433aSmrg		;;
11204d656433aSmrg	      esac
11205d656433aSmrg	    done
11206300346aeSmrg	    dlprefiles=$newdlprefiles
11207d656433aSmrg	  else
11208d656433aSmrg	    newdlfiles=
11209d656433aSmrg	    for lib in $dlfiles; do
11210d656433aSmrg	      case $lib in
11211300346aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11212d656433aSmrg		*) abs=`pwd`"/$lib" ;;
11213d656433aSmrg	      esac
112143c15da26Smrg	      func_append newdlfiles " $abs"
11215d656433aSmrg	    done
11216300346aeSmrg	    dlfiles=$newdlfiles
11217d656433aSmrg	    newdlprefiles=
11218d656433aSmrg	    for lib in $dlprefiles; do
11219d656433aSmrg	      case $lib in
11220300346aeSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11221d656433aSmrg		*) abs=`pwd`"/$lib" ;;
11222d656433aSmrg	      esac
112233c15da26Smrg	      func_append newdlprefiles " $abs"
11224d656433aSmrg	    done
11225300346aeSmrg	    dlprefiles=$newdlprefiles
11226d656433aSmrg	  fi
11227d656433aSmrg	  $RM $output
11228d656433aSmrg	  # place dlname in correct position for cygwin
11229555991fdSmrg	  # In fact, it would be nice if we could use this code for all target
11230555991fdSmrg	  # systems that can't hard-code library paths into their executables
11231555991fdSmrg	  # and that have no shared library path variable independent of PATH,
11232555991fdSmrg	  # but it turns out we can't easily determine that from inspecting
11233555991fdSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11234555991fdSmrg	  # applies here; at the moment, that means platforms that use the PE
11235555991fdSmrg	  # object format with DLL files.  See the long comment at the top of
11236555991fdSmrg	  # tests/bindir.at for full details.
11237d656433aSmrg	  tdlname=$dlname
11238d656433aSmrg	  case $host,$output,$installed,$module,$dlname in
112396bea0e4fSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *windows*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11240555991fdSmrg	      # If a -bindir argument was supplied, place the dll there.
11241300346aeSmrg	      if test -n "$bindir"; then
11242555991fdSmrg		func_relative_path "$install_libdir" "$bindir"
11243300346aeSmrg		tdlname=$func_relative_path_result/$dlname
11244555991fdSmrg	      else
11245555991fdSmrg		# Otherwise fall back on heuristic.
11246555991fdSmrg		tdlname=../bin/$dlname
11247555991fdSmrg	      fi
11248555991fdSmrg	      ;;
11249d656433aSmrg	  esac
11250d656433aSmrg	  $ECHO > $output "\
11251d656433aSmrg# $outputname - a libtool library file
11252300346aeSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11253d656433aSmrg#
11254d656433aSmrg# Please DO NOT delete this file!
11255d656433aSmrg# It is necessary for linking the library.
11256126a8a12Smrg
11257d656433aSmrg# The name that we can dlopen(3).
11258d656433aSmrgdlname='$tdlname'
11259126a8a12Smrg
11260d656433aSmrg# Names of this library.
11261d656433aSmrglibrary_names='$library_names'
11262126a8a12Smrg
11263d656433aSmrg# The name of the static archive.
11264d656433aSmrgold_library='$old_library'
11265126a8a12Smrg
11266300346aeSmrg# Linker flags that cannot go in dependency_libs.
11267d656433aSmrginherited_linker_flags='$new_inherited_linker_flags'
11268126a8a12Smrg
11269d656433aSmrg# Libraries that this one depends upon.
11270d656433aSmrgdependency_libs='$dependency_libs'
11271126a8a12Smrg
11272d656433aSmrg# Names of additional weak libraries provided by this library
11273d656433aSmrgweak_library_names='$weak_libs'
11274126a8a12Smrg
11275d656433aSmrg# Version information for $libname.
11276d656433aSmrgcurrent=$current
11277d656433aSmrgage=$age
11278d656433aSmrgrevision=$revision
11279126a8a12Smrg
11280d656433aSmrg# Is this an already installed library?
11281d656433aSmrginstalled=$installed
11282126a8a12Smrg
11283d656433aSmrg# Should we warn about portability when linking against -modules?
11284d656433aSmrgshouldnotlink=$module
11285126a8a12Smrg
11286d656433aSmrg# Files to dlopen/dlpreopen
11287d656433aSmrgdlopen='$dlfiles'
11288d656433aSmrgdlpreopen='$dlprefiles'
11289126a8a12Smrg
11290d656433aSmrg# Directory that this library needs to be installed in:
11291d656433aSmrglibdir='$install_libdir'"
11292300346aeSmrg	  if test no,yes = "$installed,$need_relink"; then
11293d656433aSmrg	    $ECHO >> $output "\
11294d656433aSmrgrelink_command=\"$relink_command\""
11295d656433aSmrg	  fi
11296d656433aSmrg	done
11297d656433aSmrg      }
11298126a8a12Smrg
11299d656433aSmrg      # Do a symbolic link so that the libtool archive can be found in
11300d656433aSmrg      # LD_LIBRARY_PATH before the program is installed.
11301d656433aSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11302d656433aSmrg      ;;
11303d656433aSmrg    esac
11304d656433aSmrg    exit $EXIT_SUCCESS
11305d656433aSmrg}
11306126a8a12Smrg
11307300346aeSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11308300346aeSmrg  func_mode_link ${1+"$@"}
11309300346aeSmrgfi
11310126a8a12Smrg
11311126a8a12Smrg
11312d656433aSmrg# func_mode_uninstall arg...
11313d656433aSmrgfunc_mode_uninstall ()
11314d656433aSmrg{
11315300346aeSmrg    $debug_cmd
11316300346aeSmrg
11317300346aeSmrg    RM=$nonopt
11318126a8a12Smrg    files=
11319300346aeSmrg    rmforce=false
11320126a8a12Smrg    exit_status=0
11321126a8a12Smrg
11322126a8a12Smrg    # This variable tells wrapper scripts just to set variables rather
11323126a8a12Smrg    # than running their programs.
11324300346aeSmrg    libtool_install_magic=$magic
11325126a8a12Smrg
11326126a8a12Smrg    for arg
11327126a8a12Smrg    do
11328126a8a12Smrg      case $arg in
11329300346aeSmrg      -f) func_append RM " $arg"; rmforce=: ;;
113303c15da26Smrg      -*) func_append RM " $arg" ;;
113313c15da26Smrg      *) func_append files " $arg" ;;
11332126a8a12Smrg      esac
11333126a8a12Smrg    done
11334126a8a12Smrg
11335d656433aSmrg    test -z "$RM" && \
11336d656433aSmrg      func_fatal_help "you must specify an RM program"
11337126a8a12Smrg
11338126a8a12Smrg    rmdirs=
11339126a8a12Smrg
11340126a8a12Smrg    for file in $files; do
11341d656433aSmrg      func_dirname "$file" "" "."
11342300346aeSmrg      dir=$func_dirname_result
11343300346aeSmrg      if test . = "$dir"; then
11344300346aeSmrg	odir=$objdir
11345126a8a12Smrg      else
11346300346aeSmrg	odir=$dir/$objdir
11347126a8a12Smrg      fi
11348d656433aSmrg      func_basename "$file"
11349300346aeSmrg      name=$func_basename_result
11350300346aeSmrg      test uninstall = "$opt_mode" && odir=$dir
11351126a8a12Smrg
113523c15da26Smrg      # Remember odir for removal later, being careful to avoid duplicates
11353300346aeSmrg      if test clean = "$opt_mode"; then
11354126a8a12Smrg	case " $rmdirs " in
113553c15da26Smrg	  *" $odir "*) ;;
113563c15da26Smrg	  *) func_append rmdirs " $odir" ;;
11357126a8a12Smrg	esac
11358126a8a12Smrg      fi
11359126a8a12Smrg
11360126a8a12Smrg      # Don't error if the file doesn't exist and rm -f was used.
11361d656433aSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11362d656433aSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11363d656433aSmrg	 test -f "$file"; then
11364126a8a12Smrg	:
11365126a8a12Smrg      elif test -d "$file"; then
11366126a8a12Smrg	exit_status=1
11367126a8a12Smrg	continue
11368300346aeSmrg      elif $rmforce; then
11369126a8a12Smrg	continue
11370126a8a12Smrg      fi
11371126a8a12Smrg
11372300346aeSmrg      rmfiles=$file
11373126a8a12Smrg
11374126a8a12Smrg      case $name in
11375126a8a12Smrg      *.la)
11376126a8a12Smrg	# Possibly a libtool archive, so verify it.
11377d656433aSmrg	if func_lalib_p "$file"; then
11378d656433aSmrg	  func_source $dir/$name
11379126a8a12Smrg
11380126a8a12Smrg	  # Delete the libtool libraries and symlinks.
11381126a8a12Smrg	  for n in $library_names; do
113823c15da26Smrg	    func_append rmfiles " $odir/$n"
11383126a8a12Smrg	  done
113843c15da26Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11385126a8a12Smrg
11386300346aeSmrg	  case $opt_mode in
11387126a8a12Smrg	  clean)
113883c15da26Smrg	    case " $library_names " in
11389126a8a12Smrg	    *" $dlname "*) ;;
113903c15da26Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11391126a8a12Smrg	    esac
113923c15da26Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11393126a8a12Smrg	    ;;
11394126a8a12Smrg	  uninstall)
11395126a8a12Smrg	    if test -n "$library_names"; then
11396126a8a12Smrg	      # Do each command in the postuninstall commands.
11397300346aeSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11398126a8a12Smrg	    fi
11399126a8a12Smrg
11400126a8a12Smrg	    if test -n "$old_library"; then
11401126a8a12Smrg	      # Do each command in the old_postuninstall commands.
11402300346aeSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11403126a8a12Smrg	    fi
11404126a8a12Smrg	    # FIXME: should reinstall the best remaining shared library.
11405126a8a12Smrg	    ;;
11406126a8a12Smrg	  esac
11407126a8a12Smrg	fi
11408126a8a12Smrg	;;
11409126a8a12Smrg
11410126a8a12Smrg      *.lo)
11411126a8a12Smrg	# Possibly a libtool object, so verify it.
11412d656433aSmrg	if func_lalib_p "$file"; then
11413126a8a12Smrg
11414126a8a12Smrg	  # Read the .lo file
11415d656433aSmrg	  func_source $dir/$name
11416126a8a12Smrg
11417126a8a12Smrg	  # Add PIC object to the list of files to remove.
11418300346aeSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
114193c15da26Smrg	    func_append rmfiles " $dir/$pic_object"
11420126a8a12Smrg	  fi
11421126a8a12Smrg
11422126a8a12Smrg	  # Add non-PIC object to the list of files to remove.
11423300346aeSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
114243c15da26Smrg	    func_append rmfiles " $dir/$non_pic_object"
11425126a8a12Smrg	  fi
11426126a8a12Smrg	fi
11427126a8a12Smrg	;;
11428126a8a12Smrg
11429126a8a12Smrg      *)
11430300346aeSmrg	if test clean = "$opt_mode"; then
11431126a8a12Smrg	  noexename=$name
11432126a8a12Smrg	  case $file in
11433126a8a12Smrg	  *.exe)
11434d656433aSmrg	    func_stripname '' '.exe' "$file"
11435d656433aSmrg	    file=$func_stripname_result
11436d656433aSmrg	    func_stripname '' '.exe' "$name"
11437d656433aSmrg	    noexename=$func_stripname_result
11438126a8a12Smrg	    # $file with .exe has already been added to rmfiles,
11439126a8a12Smrg	    # add $file without .exe
114403c15da26Smrg	    func_append rmfiles " $file"
11441126a8a12Smrg	    ;;
11442126a8a12Smrg	  esac
11443126a8a12Smrg	  # Do a test to see if this is a libtool program.
11444d656433aSmrg	  if func_ltwrapper_p "$file"; then
11445d656433aSmrg	    if func_ltwrapper_executable_p "$file"; then
11446d656433aSmrg	      func_ltwrapper_scriptname "$file"
11447d656433aSmrg	      relink_command=
11448d656433aSmrg	      func_source $func_ltwrapper_scriptname_result
114493c15da26Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11450d656433aSmrg	    else
11451d656433aSmrg	      relink_command=
11452d656433aSmrg	      func_source $dir/$noexename
11453d656433aSmrg	    fi
11454126a8a12Smrg
11455126a8a12Smrg	    # note $name still contains .exe if it was in $file originally
11456126a8a12Smrg	    # as does the version of $file that was added into $rmfiles
11457300346aeSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11458300346aeSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
114593c15da26Smrg	      func_append rmfiles " $odir/lt-$name"
11460126a8a12Smrg	    fi
11461300346aeSmrg	    if test "X$noexename" != "X$name"; then
11462300346aeSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
11463126a8a12Smrg	    fi
11464126a8a12Smrg	  fi
11465126a8a12Smrg	fi
11466126a8a12Smrg	;;
11467126a8a12Smrg      esac
11468d656433aSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11469126a8a12Smrg    done
11470126a8a12Smrg
11471300346aeSmrg    # Try to remove the $objdir's in the directories where we deleted files
11472126a8a12Smrg    for dir in $rmdirs; do
11473126a8a12Smrg      if test -d "$dir"; then
11474d656433aSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11475126a8a12Smrg      fi
11476126a8a12Smrg    done
11477126a8a12Smrg
11478126a8a12Smrg    exit $exit_status
11479d656433aSmrg}
11480126a8a12Smrg
11481300346aeSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11482300346aeSmrg  func_mode_uninstall ${1+"$@"}
11483300346aeSmrgfi
11484126a8a12Smrg
114853c15da26Smrgtest -z "$opt_mode" && {
11486300346aeSmrg  help=$generic_help
11487d656433aSmrg  func_fatal_help "you must specify a MODE"
11488d656433aSmrg}
11489d656433aSmrg
11490d656433aSmrgtest -z "$exec_cmd" && \
11491300346aeSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
11492126a8a12Smrg
11493126a8a12Smrgif test -n "$exec_cmd"; then
11494d656433aSmrg  eval exec "$exec_cmd"
11495126a8a12Smrg  exit $EXIT_FAILURE
11496126a8a12Smrgfi
11497126a8a12Smrg
11498d656433aSmrgexit $exit_status
11499126a8a12Smrg
11500126a8a12Smrg
11501126a8a12Smrg# The TAGs below are defined such that we never get into a situation
11502300346aeSmrg# where we disable both kinds of libraries.  Given conflicting
11503126a8a12Smrg# choices, we go for a static library, that is the most portable,
11504126a8a12Smrg# since we can't tell whether shared libraries were disabled because
11505126a8a12Smrg# the user asked for that or because the platform doesn't support
11506126a8a12Smrg# them.  This is particularly important on AIX, because we don't
11507126a8a12Smrg# support having both static and shared libraries enabled at the same
11508126a8a12Smrg# time on that platform, so we default to a shared-only configuration.
11509126a8a12Smrg# If a disable-shared tag is given, we'll fallback to a static-only
11510126a8a12Smrg# configuration.  But we'll never go from static-only to shared-only.
11511126a8a12Smrg
11512126a8a12Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11513d656433aSmrgbuild_libtool_libs=no
11514d656433aSmrgbuild_old_libs=yes
11515126a8a12Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
11516126a8a12Smrg
11517126a8a12Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11518d656433aSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11519126a8a12Smrg# ### END LIBTOOL TAG CONFIG: disable-static
11520126a8a12Smrg
11521126a8a12Smrg# Local Variables:
11522126a8a12Smrg# mode:shell-script
11523126a8a12Smrg# sh-indentation:2
11524126a8a12Smrg# End:
11525