1a392d4f3Smrg#! /usr/bin/env sh
2e6d2e958Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3a392d4f3Smrg##               by inline-source v2019-02-19.15
447e89262Smrg
5a392d4f3Smrg# libtool (GNU libtool) 2.4.7
6e6d2e958Smrg# Provide generalized library-building support services.
747e89262Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
847e89262Smrg
9a392d4f3Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
1047e89262Smrg# This is free software; see the source for copying conditions.  There is NO
1147e89262Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1247e89262Smrg
1347e89262Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14bd1da9d7Smrg# it under the terms of the GNU General Public License as published by
15bd1da9d7Smrg# the Free Software Foundation; either version 2 of the License, or
16bd1da9d7Smrg# (at your option) any later version.
17bd1da9d7Smrg#
1847e89262Smrg# As a special exception to the GNU General Public License,
1947e89262Smrg# if you distribute this file as part of a program or library that
2047e89262Smrg# is built using GNU Libtool, you may include this file under the
2147e89262Smrg# same distribution terms that you use for the rest of that program.
2247e89262Smrg#
2347e89262Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24bd1da9d7Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25bd1da9d7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26bd1da9d7Smrg# General Public License for more details.
27bd1da9d7Smrg#
28bd1da9d7Smrg# You should have received a copy of the GNU General Public License
29e6d2e958Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30bd1da9d7Smrg
31bd1da9d7Smrg
3247e89262SmrgPROGRAM=libtool
33bd1da9d7SmrgPACKAGE=libtool
34a392d4f3SmrgVERSION=2.4.7
35a392d4f3Smrgpackage_revision=2.4.7
365bcb6992Smrg
37e6d2e958Smrg
38e6d2e958Smrg## ------ ##
39e6d2e958Smrg## Usage. ##
40e6d2e958Smrg## ------ ##
41e6d2e958Smrg
42e6d2e958Smrg# Run './libtool --help' for help with using this script from the
43e6d2e958Smrg# command line.
44e6d2e958Smrg
45e6d2e958Smrg
46e6d2e958Smrg## ------------------------------- ##
47e6d2e958Smrg## User overridable command paths. ##
48e6d2e958Smrg## ------------------------------- ##
49e6d2e958Smrg
50e6d2e958Smrg# After configure completes, it has a better idea of some of the
51e6d2e958Smrg# shell tools we need than the defaults used by the functions shared
52e6d2e958Smrg# with bootstrap, so set those here where they can still be over-
53e6d2e958Smrg# ridden by the user, but otherwise take precedence.
54e6d2e958Smrg
55e6d2e958Smrg: ${AUTOCONF="autoconf"}
56e6d2e958Smrg: ${AUTOMAKE="automake"}
57e6d2e958Smrg
58e6d2e958Smrg
59e6d2e958Smrg## -------------------------- ##
60e6d2e958Smrg## Source external libraries. ##
61e6d2e958Smrg## -------------------------- ##
62e6d2e958Smrg
63e6d2e958Smrg# Much of our low-level functionality needs to be sourced from external
64e6d2e958Smrg# libraries, which are installed to $pkgauxdir.
65e6d2e958Smrg
66e6d2e958Smrg# Set a version string for this script.
67a392d4f3Smrgscriptversion=2019-02-19.15; # UTC
68e6d2e958Smrg
69e6d2e958Smrg# General shell script boiler plate, and helper functions.
70e6d2e958Smrg# Written by Gary V. Vaughan, 2004
71e6d2e958Smrg
72a392d4f3Smrg# This is free software.  There is NO warranty; not even for
73a392d4f3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74a392d4f3Smrg#
75a392d4f3Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76a392d4f3Smrg#
77a392d4f3Smrg# This file is dual licensed under the terms of the MIT license
78a392d4f3Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79a392d4f3Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80a392d4f3Smrg# these licenses when using or redistributing this software or any of
81a392d4f3Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82a392d4f3Smrg# included in the Bootstrap distribution for the full license texts.
83e6d2e958Smrg
84a392d4f3Smrg# Please report bugs or propose patches to:
85a392d4f3Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86e6d2e958Smrg
87e6d2e958Smrg
88e6d2e958Smrg## ------ ##
89e6d2e958Smrg## Usage. ##
90e6d2e958Smrg## ------ ##
91e6d2e958Smrg
92e6d2e958Smrg# Evaluate this file near the top of your script to gain access to
93e6d2e958Smrg# the functions and variables defined here:
94e6d2e958Smrg#
95e6d2e958Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96e6d2e958Smrg#
97e6d2e958Smrg# If you need to override any of the default environment variable
98e6d2e958Smrg# settings, do that before evaluating this file.
99e6d2e958Smrg
100e6d2e958Smrg
101e6d2e958Smrg## -------------------- ##
102e6d2e958Smrg## Shell normalisation. ##
103e6d2e958Smrg## -------------------- ##
104e6d2e958Smrg
105e6d2e958Smrg# Some shells need a little help to be as Bourne compatible as possible.
106e6d2e958Smrg# Before doing anything else, make sure all that help has been provided!
107e6d2e958Smrg
108e6d2e958SmrgDUALCASE=1; export DUALCASE # for MKS sh
109e6d2e958Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1105bcb6992Smrg  emulate sh
1115bcb6992Smrg  NULLCMD=:
112e6d2e958Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1135bcb6992Smrg  # is contrary to our usage.  Disable this feature.
1145bcb6992Smrg  alias -g '${1+"$@"}'='"$@"'
115bd1da9d7Smrg  setopt NO_GLOB_SUBST
1165bcb6992Smrgelse
117e6d2e958Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118bd1da9d7Smrgfi
119bd1da9d7Smrg
120e6d2e958Smrg# NLS nuisances: We save the old values in case they are required later.
121e6d2e958Smrg_G_user_locale=
122e6d2e958Smrg_G_safe_locale=
123e6d2e958Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1245bcb6992Smrgdo
125e6d2e958Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126e6d2e958Smrg          save_$_G_var=\$$_G_var
127e6d2e958Smrg          $_G_var=C
128e6d2e958Smrg	  export $_G_var
129e6d2e958Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130e6d2e958Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1315bcb6992Smrg	fi"
1325bcb6992Smrgdone
133a392d4f3Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134a392d4f3Smrg# in case the environment reset is needed later and the $save_* variant is not
135a392d4f3Smrg# defined (see the code above).
136a392d4f3SmrgLC_ALL=C
137a392d4f3SmrgLANGUAGE=C
138a392d4f3Smrgexport LANGUAGE LC_ALL
13947e89262Smrg
140e6d2e958Smrg# Make sure IFS has a sensible default
141e6d2e958Smrgsp=' '
142e6d2e958Smrgnl='
143e6d2e958Smrg'
144e6d2e958SmrgIFS="$sp	$nl"
145e6d2e958Smrg
146e6d2e958Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
147e6d2e958Smrgif test "${PATH_SEPARATOR+set}" != set; then
148e6d2e958Smrg  PATH_SEPARATOR=:
149e6d2e958Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150e6d2e958Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151e6d2e958Smrg      PATH_SEPARATOR=';'
152e6d2e958Smrg  }
153e6d2e958Smrgfi
15447e89262Smrg
15547e89262Smrg
156a392d4f3Smrg# func_unset VAR
157a392d4f3Smrg# --------------
158a392d4f3Smrg# Portably unset VAR.
159a392d4f3Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160a392d4f3Smrg# status if VAR is already unset, which might be problematic if the
161a392d4f3Smrg# statement is used at the end of a function (thus poisoning its return
162a392d4f3Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163a392d4f3Smrg# the script in this case).
164a392d4f3Smrgfunc_unset ()
165a392d4f3Smrg{
166a392d4f3Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167a392d4f3Smrg}
168a392d4f3Smrg
169a392d4f3Smrg
170a392d4f3Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171a392d4f3Smrgfunc_unset CDPATH
172a392d4f3Smrg
173a392d4f3Smrg# Make sure ${,E,F}GREP behave sanely.
174a392d4f3Smrgfunc_unset GREP_OPTIONS
175a392d4f3Smrg
17647e89262Smrg
177e6d2e958Smrg## ------------------------- ##
178e6d2e958Smrg## Locate command utilities. ##
179e6d2e958Smrg## ------------------------- ##
180e6d2e958Smrg
181e6d2e958Smrg
182e6d2e958Smrg# func_executable_p FILE
183e6d2e958Smrg# ----------------------
184e6d2e958Smrg# Check that FILE is an executable regular file.
185e6d2e958Smrgfunc_executable_p ()
186e6d2e958Smrg{
187e6d2e958Smrg    test -f "$1" && test -x "$1"
188e6d2e958Smrg}
189e6d2e958Smrg
190e6d2e958Smrg
191e6d2e958Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192e6d2e958Smrg# --------------------------------------------
193e6d2e958Smrg# Search for either a program that responds to --version with output
194e6d2e958Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195e6d2e958Smrg# trying all the directories in PATH with each of the elements of
196e6d2e958Smrg# PROGS_LIST.
197e6d2e958Smrg#
198e6d2e958Smrg# CHECK_FUNC should accept the path to a candidate program, and
199e6d2e958Smrg# set $func_check_prog_result if it truncates its output less than
200e6d2e958Smrg# $_G_path_prog_max characters.
201e6d2e958Smrgfunc_path_progs ()
202e6d2e958Smrg{
203e6d2e958Smrg    _G_progs_list=$1
204e6d2e958Smrg    _G_check_func=$2
205e6d2e958Smrg    _G_PATH=${3-"$PATH"}
206e6d2e958Smrg
207e6d2e958Smrg    _G_path_prog_max=0
208e6d2e958Smrg    _G_path_prog_found=false
209e6d2e958Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210e6d2e958Smrg    for _G_dir in $_G_PATH; do
211e6d2e958Smrg      IFS=$_G_save_IFS
212e6d2e958Smrg      test -z "$_G_dir" && _G_dir=.
213e6d2e958Smrg      for _G_prog_name in $_G_progs_list; do
214e6d2e958Smrg        for _exeext in '' .EXE; do
215e6d2e958Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216e6d2e958Smrg          func_executable_p "$_G_path_prog" || continue
217e6d2e958Smrg          case `"$_G_path_prog" --version 2>&1` in
218e6d2e958Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219e6d2e958Smrg            *)     $_G_check_func $_G_path_prog
220e6d2e958Smrg		   func_path_progs_result=$func_check_prog_result
221e6d2e958Smrg		   ;;
222e6d2e958Smrg          esac
223e6d2e958Smrg          $_G_path_prog_found && break 3
224e6d2e958Smrg        done
225e6d2e958Smrg      done
226e6d2e958Smrg    done
227e6d2e958Smrg    IFS=$_G_save_IFS
228e6d2e958Smrg    test -z "$func_path_progs_result" && {
229e6d2e958Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230e6d2e958Smrg      exit 1
231e6d2e958Smrg    }
232e6d2e958Smrg}
233e6d2e958Smrg
234e6d2e958Smrg
235e6d2e958Smrg# We want to be able to use the functions in this file before configure
236e6d2e958Smrg# has figured out where the best binaries are kept, which means we have
237e6d2e958Smrg# to search for them ourselves - except when the results are already set
238e6d2e958Smrg# where we skip the searches.
239e6d2e958Smrg
240e6d2e958Smrg# Unless the user overrides by setting SED, search the path for either GNU
241e6d2e958Smrg# sed, or the sed that truncates its output the least.
242e6d2e958Smrgtest -z "$SED" && {
243e6d2e958Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244e6d2e958Smrg  for _G_i in 1 2 3 4 5 6 7; do
245e6d2e958Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246e6d2e958Smrg  done
247e6d2e958Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248e6d2e958Smrg  _G_sed_script=
249e6d2e958Smrg
250e6d2e958Smrg  func_check_prog_sed ()
251e6d2e958Smrg  {
252e6d2e958Smrg    _G_path_prog=$1
253e6d2e958Smrg
254e6d2e958Smrg    _G_count=0
255e6d2e958Smrg    printf 0123456789 >conftest.in
256e6d2e958Smrg    while :
257e6d2e958Smrg    do
258e6d2e958Smrg      cat conftest.in conftest.in >conftest.tmp
259e6d2e958Smrg      mv conftest.tmp conftest.in
260e6d2e958Smrg      cp conftest.in conftest.nl
261e6d2e958Smrg      echo '' >> conftest.nl
262e6d2e958Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263e6d2e958Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264e6d2e958Smrg      _G_count=`expr $_G_count + 1`
265e6d2e958Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266e6d2e958Smrg        # Best one so far, save it but keep looking for a better one
267e6d2e958Smrg        func_check_prog_result=$_G_path_prog
268e6d2e958Smrg        _G_path_prog_max=$_G_count
269e6d2e958Smrg      fi
270e6d2e958Smrg      # 10*(2^10) chars as input seems more than enough
271e6d2e958Smrg      test 10 -lt "$_G_count" && break
272e6d2e958Smrg    done
273e6d2e958Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274e6d2e958Smrg  }
275e6d2e958Smrg
276a392d4f3Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277e6d2e958Smrg  rm -f conftest.sed
278e6d2e958Smrg  SED=$func_path_progs_result
279e6d2e958Smrg}
280e6d2e958Smrg
281e6d2e958Smrg
282e6d2e958Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283e6d2e958Smrg# grep, or the grep that truncates its output the least.
284e6d2e958Smrgtest -z "$GREP" && {
285e6d2e958Smrg  func_check_prog_grep ()
286e6d2e958Smrg  {
287e6d2e958Smrg    _G_path_prog=$1
288e6d2e958Smrg
289e6d2e958Smrg    _G_count=0
290e6d2e958Smrg    _G_path_prog_max=0
291e6d2e958Smrg    printf 0123456789 >conftest.in
292e6d2e958Smrg    while :
293e6d2e958Smrg    do
294e6d2e958Smrg      cat conftest.in conftest.in >conftest.tmp
295e6d2e958Smrg      mv conftest.tmp conftest.in
296e6d2e958Smrg      cp conftest.in conftest.nl
297e6d2e958Smrg      echo 'GREP' >> conftest.nl
298e6d2e958Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299e6d2e958Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300e6d2e958Smrg      _G_count=`expr $_G_count + 1`
301e6d2e958Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302e6d2e958Smrg        # Best one so far, save it but keep looking for a better one
303e6d2e958Smrg        func_check_prog_result=$_G_path_prog
304e6d2e958Smrg        _G_path_prog_max=$_G_count
305e6d2e958Smrg      fi
306e6d2e958Smrg      # 10*(2^10) chars as input seems more than enough
307e6d2e958Smrg      test 10 -lt "$_G_count" && break
308e6d2e958Smrg    done
309e6d2e958Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310e6d2e958Smrg  }
311e6d2e958Smrg
312a392d4f3Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313e6d2e958Smrg  GREP=$func_path_progs_result
314e6d2e958Smrg}
315e6d2e958Smrg
316e6d2e958Smrg
317e6d2e958Smrg## ------------------------------- ##
318e6d2e958Smrg## User overridable command paths. ##
319e6d2e958Smrg## ------------------------------- ##
320e6d2e958Smrg
321e6d2e958Smrg# All uppercase variable names are used for environment variables.  These
322e6d2e958Smrg# variables can be overridden by the user before calling a script that
323e6d2e958Smrg# uses them if a suitable command of that name is not already available
324e6d2e958Smrg# in the command search PATH.
32547e89262Smrg
32647e89262Smrg: ${CP="cp -f"}
327e6d2e958Smrg: ${ECHO="printf %s\n"}
328e6d2e958Smrg: ${EGREP="$GREP -E"}
329e6d2e958Smrg: ${FGREP="$GREP -F"}
330e6d2e958Smrg: ${LN_S="ln -s"}
33147e89262Smrg: ${MAKE="make"}
33247e89262Smrg: ${MKDIR="mkdir"}
33347e89262Smrg: ${MV="mv -f"}
33447e89262Smrg: ${RM="rm -f"}
33547e89262Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336bd1da9d7Smrg
33747e89262Smrg
338e6d2e958Smrg## -------------------- ##
339e6d2e958Smrg## Useful sed snippets. ##
340e6d2e958Smrg## -------------------- ##
341899129b3Smrg
342e6d2e958Smrgsed_dirname='s|/[^/]*$||'
343e6d2e958Smrgsed_basename='s|^.*/||'
344899129b3Smrg
345e6d2e958Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346e6d2e958Smrg# metacharacters that are still active within double-quoted strings.
347e6d2e958Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348899129b3Smrg
349e6d2e958Smrg# Same as above, but do not quote variable references.
350e6d2e958Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351899129b3Smrg
352e6d2e958Smrg# Sed substitution that turns a string into a regex matching for the
353e6d2e958Smrg# string literally.
354e6d2e958Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355899129b3Smrg
356e6d2e958Smrg# Sed substitution that converts a w32 file name or path
357e6d2e958Smrg# that contains forward slashes, into one that contains
358e6d2e958Smrg# (escaped) backslashes.  A very naive implementation.
359e6d2e958Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360e6d2e958Smrg
361e6d2e958Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362e6d2e958Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363e6d2e958Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364e6d2e958Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365e6d2e958Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366e6d2e958Smrg_G_bs='\\'
367e6d2e958Smrg_G_bs2='\\\\'
368e6d2e958Smrg_G_bs4='\\\\\\\\'
369e6d2e958Smrg_G_dollar='\$'
370e6d2e958Smrgsed_double_backslash="\
371e6d2e958Smrg  s/$_G_bs4/&\\
372e6d2e958Smrg/g
373e6d2e958Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374e6d2e958Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375e6d2e958Smrg  s/\n//g"
376899129b3Smrg
377a392d4f3Smrg# require_check_ifs_backslash
378a392d4f3Smrg# ---------------------------
379a392d4f3Smrg# Check if we can use backslash as IFS='\' separator, and set
380a392d4f3Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381a392d4f3Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382a392d4f3Smrgfunc_require_check_ifs_backslash ()
383a392d4f3Smrg{
384a392d4f3Smrg  _G_save_IFS=$IFS
385a392d4f3Smrg  IFS='\'
386a392d4f3Smrg  _G_check_ifs_backshlash='a\\b'
387a392d4f3Smrg  for _G_i in $_G_check_ifs_backshlash
388a392d4f3Smrg  do
389a392d4f3Smrg  case $_G_i in
390a392d4f3Smrg  a)
391a392d4f3Smrg    check_ifs_backshlash_broken=false
392a392d4f3Smrg    ;;
393a392d4f3Smrg  '')
394a392d4f3Smrg    break
395a392d4f3Smrg    ;;
396a392d4f3Smrg  *)
397a392d4f3Smrg    check_ifs_backshlash_broken=:
398a392d4f3Smrg    break
399a392d4f3Smrg    ;;
400a392d4f3Smrg  esac
401a392d4f3Smrg  done
402a392d4f3Smrg  IFS=$_G_save_IFS
403a392d4f3Smrg  require_check_ifs_backslash=:
404a392d4f3Smrg}
405a392d4f3Smrg
406bd1da9d7Smrg
407e6d2e958Smrg## ----------------- ##
408e6d2e958Smrg## Global variables. ##
409e6d2e958Smrg## ----------------- ##
41047e89262Smrg
411e6d2e958Smrg# Except for the global variables explicitly listed below, the following
412e6d2e958Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413e6d2e958Smrg# variables initialised in the 'Resource management' section, sourcing
414e6d2e958Smrg# this file will not pollute your global namespace with anything
415e6d2e958Smrg# else. There's no portable way to scope variables in Bourne shell
416e6d2e958Smrg# though, so actually running these functions will sometimes place
417e6d2e958Smrg# results into a variable named after the function, and often use
418e6d2e958Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419e6d2e958Smrg# avoid using those namespaces casually in your sourcing script, things
420e6d2e958Smrg# should continue to work as you expect. And, of course, you can freely
421e6d2e958Smrg# overwrite any of the functions or variables defined here before
422e6d2e958Smrg# calling anything to customize them.
42347e89262Smrg
424e6d2e958SmrgEXIT_SUCCESS=0
425e6d2e958SmrgEXIT_FAILURE=1
426e6d2e958SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427e6d2e958SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
42847e89262Smrg
429e6d2e958Smrg# Allow overriding, eg assuming that you follow the convention of
430e6d2e958Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431e6d2e958Smrg# bash to show function call trace with:
432e6d2e958Smrg#
433a392d4f3Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434e6d2e958Smrgdebug_cmd=${debug_cmd-":"}
435e6d2e958Smrgexit_cmd=:
43647e89262Smrg
437e6d2e958Smrg# By convention, finish your script with:
438e6d2e958Smrg#
439e6d2e958Smrg#    exit $exit_status
440e6d2e958Smrg#
441e6d2e958Smrg# so that you can set exit_status to non-zero if you want to indicate
442e6d2e958Smrg# something went wrong during execution without actually bailing out at
443e6d2e958Smrg# the point of failure.
444e6d2e958Smrgexit_status=$EXIT_SUCCESS
44547e89262Smrg
446e6d2e958Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447e6d2e958Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448e6d2e958Smrg# the _XPG environment variable is not equal to 1 (one), the special
449e6d2e958Smrg# positional parameter $0, within a function call, is the name of the
450e6d2e958Smrg# function.
451e6d2e958Smrgprogpath=$0
45247e89262Smrg
453e6d2e958Smrg# The name of this program.
454e6d2e958Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
45547e89262Smrg
456e6d2e958Smrg# Make sure we have an absolute progpath for reexecution:
45747e89262Smrgcase $progpath in
45847e89262Smrg  [\\/]*|[A-Za-z]:\\*) ;;
45947e89262Smrg  *[\\/]*)
460e6d2e958Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
46147e89262Smrg     progdir=`cd "$progdir" && pwd`
462e6d2e958Smrg     progpath=$progdir/$progname
46347e89262Smrg     ;;
46447e89262Smrg  *)
465e6d2e958Smrg     _G_IFS=$IFS
466899129b3Smrg     IFS=${PATH_SEPARATOR-:}
46747e89262Smrg     for progdir in $PATH; do
468e6d2e958Smrg       IFS=$_G_IFS
46947e89262Smrg       test -x "$progdir/$progname" && break
47047e89262Smrg     done
471e6d2e958Smrg     IFS=$_G_IFS
47247e89262Smrg     test -n "$progdir" || progdir=`pwd`
473e6d2e958Smrg     progpath=$progdir/$progname
47447e89262Smrg     ;;
47547e89262Smrgesac
47647e89262Smrg
47747e89262Smrg
478e6d2e958Smrg## ----------------- ##
479e6d2e958Smrg## Standard options. ##
480e6d2e958Smrg## ----------------- ##
481899129b3Smrg
482e6d2e958Smrg# The following options affect the operation of the functions defined
483e6d2e958Smrg# below, and should be set appropriately depending on run-time para-
484e6d2e958Smrg# meters passed on the command line.
48547e89262Smrg
48647e89262Smrgopt_dry_run=false
48747e89262Smrgopt_quiet=false
48847e89262Smrgopt_verbose=false
48947e89262Smrg
490e6d2e958Smrg# Categories 'all' and 'none' are always available.  Append any others
491e6d2e958Smrg# you will pass as the first argument to func_warning from your own
492e6d2e958Smrg# code.
493e6d2e958Smrgwarning_categories=
49447e89262Smrg
495e6d2e958Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496e6d2e958Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497e6d2e958Smrg# treat the next displayed warning as a fatal error.
498e6d2e958Smrgwarning_func=func_warn_and_continue
49947e89262Smrg
500e6d2e958Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501e6d2e958Smrg# warnings, or a space delimited list of some subset of
502e6d2e958Smrg# 'warning_categories' to display only the listed warnings.
503e6d2e958Smrgopt_warning_types=all
50447e89262Smrg
50547e89262Smrg
506e6d2e958Smrg## -------------------- ##
507e6d2e958Smrg## Resource management. ##
508e6d2e958Smrg## -------------------- ##
50947e89262Smrg
510e6d2e958Smrg# This section contains definitions for functions that each ensure a
511e6d2e958Smrg# particular resource (a file, or a non-empty configuration variable for
512e6d2e958Smrg# example) is available, and if appropriate to extract default values
513e6d2e958Smrg# from pertinent package files. Call them using their associated
514e6d2e958Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515e6d2e958Smrg#
516e6d2e958Smrg# It's entirely deliberate that calling these functions can set
517e6d2e958Smrg# variables that don't obey the namespace limitations obeyed by the rest
518e6d2e958Smrg# of this file, in order that that they be as useful as possible to
519e6d2e958Smrg# callers.
52047e89262Smrg
52147e89262Smrg
522e6d2e958Smrg# require_term_colors
523e6d2e958Smrg# -------------------
524e6d2e958Smrg# Allow display of bold text on terminals that support it.
525e6d2e958Smrgrequire_term_colors=func_require_term_colors
526e6d2e958Smrgfunc_require_term_colors ()
52747e89262Smrg{
528e6d2e958Smrg    $debug_cmd
529e6d2e958Smrg
530e6d2e958Smrg    test -t 1 && {
531e6d2e958Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532e6d2e958Smrg      # precedence, because most terminfo databases neglect to describe
533e6d2e958Smrg      # whether color sequences are supported.
534e6d2e958Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535e6d2e958Smrg
536e6d2e958Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537e6d2e958Smrg        # Standard ANSI escape sequences
538e6d2e958Smrg        tc_reset='[0m'
539e6d2e958Smrg        tc_bold='[1m';   tc_standout='[7m'
540e6d2e958Smrg        tc_red='[31m';   tc_green='[32m'
541e6d2e958Smrg        tc_blue='[34m';  tc_cyan='[36m'
542e6d2e958Smrg      else
543e6d2e958Smrg        # Otherwise trust the terminfo database after all.
544e6d2e958Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545e6d2e958Smrg          tc_reset=`tput sgr0`
546e6d2e958Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547e6d2e958Smrg          tc_standout=$tc_bold
548e6d2e958Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549e6d2e958Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550e6d2e958Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551e6d2e958Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552e6d2e958Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553e6d2e958Smrg        }
554e6d2e958Smrg      fi
555e6d2e958Smrg    }
55647e89262Smrg
557e6d2e958Smrg    require_term_colors=:
55847e89262Smrg}
55947e89262Smrg
56047e89262Smrg
561e6d2e958Smrg## ----------------- ##
562e6d2e958Smrg## Function library. ##
563e6d2e958Smrg## ----------------- ##
564e6d2e958Smrg
565e6d2e958Smrg# This section contains a variety of useful functions to call in your
566e6d2e958Smrg# scripts. Take note of the portable wrappers for features provided by
567e6d2e958Smrg# some modern shells, which will fall back to slower equivalents on
568e6d2e958Smrg# less featureful shells.
569e6d2e958Smrg
570e6d2e958Smrg
571e6d2e958Smrg# func_append VAR VALUE
572e6d2e958Smrg# ---------------------
573e6d2e958Smrg# Append VALUE onto the existing contents of VAR.
574e6d2e958Smrg
575e6d2e958Smrg  # We should try to minimise forks, especially on Windows where they are
576e6d2e958Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577e6d2e958Smrg  # being used:
578e6d2e958Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579e6d2e958Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580e6d2e958Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581e6d2e958Smrg    # The += operator was introduced in bash 3.1
582e6d2e958Smrg    case $BASH_VERSION in
583e6d2e958Smrg      [12].* | 3.0 | 3.0*) ;;
584e6d2e958Smrg      *)
585e6d2e958Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586e6d2e958Smrg        ;;
587e6d2e958Smrg    esac
588e6d2e958Smrg  fi
589e6d2e958Smrg
590e6d2e958Smrg  # _G_HAVE_PLUSEQ_OP
591e6d2e958Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
592e6d2e958Smrg  # useable or anything else if it does not work.
593e6d2e958Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594e6d2e958Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595e6d2e958Smrg    && _G_HAVE_PLUSEQ_OP=yes
596e6d2e958Smrg
597e6d2e958Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598e6d2e958Smrgthen
599e6d2e958Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600e6d2e958Smrg  eval 'func_append ()
601e6d2e958Smrg  {
602e6d2e958Smrg    $debug_cmd
603e6d2e958Smrg
604e6d2e958Smrg    eval "$1+=\$2"
605e6d2e958Smrg  }'
606e6d2e958Smrgelse
607e6d2e958Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608e6d2e958Smrg  func_append ()
609e6d2e958Smrg  {
610e6d2e958Smrg    $debug_cmd
611e6d2e958Smrg
612e6d2e958Smrg    eval "$1=\$$1\$2"
613e6d2e958Smrg  }
614e6d2e958Smrgfi
615e6d2e958Smrg
616e6d2e958Smrg
617e6d2e958Smrg# func_append_quoted VAR VALUE
618e6d2e958Smrg# ----------------------------
619e6d2e958Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620e6d2e958Smrg# by a space.
621e6d2e958Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622e6d2e958Smrg  eval 'func_append_quoted ()
623e6d2e958Smrg  {
624e6d2e958Smrg    $debug_cmd
625e6d2e958Smrg
626a392d4f3Smrg    func_quote_arg pretty "$2"
627a392d4f3Smrg    eval "$1+=\\ \$func_quote_arg_result"
628e6d2e958Smrg  }'
629e6d2e958Smrgelse
630e6d2e958Smrg  func_append_quoted ()
631e6d2e958Smrg  {
632e6d2e958Smrg    $debug_cmd
633e6d2e958Smrg
634a392d4f3Smrg    func_quote_arg pretty "$2"
635a392d4f3Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636e6d2e958Smrg  }
637e6d2e958Smrgfi
638e6d2e958Smrg
639e6d2e958Smrg
640e6d2e958Smrg# func_append_uniq VAR VALUE
641e6d2e958Smrg# --------------------------
642e6d2e958Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643e6d2e958Smrg# entries are delimited by the first character of VALUE.  For example:
644e6d2e958Smrg#
645e6d2e958Smrg#   func_append_uniq options " --another-option option-argument"
646e6d2e958Smrg#
647e6d2e958Smrg# will only append to $options if " --another-option option-argument "
648e6d2e958Smrg# is not already present somewhere in $options already (note spaces at
649e6d2e958Smrg# each end implied by leading space in second argument).
650e6d2e958Smrgfunc_append_uniq ()
651e6d2e958Smrg{
652e6d2e958Smrg    $debug_cmd
653e6d2e958Smrg
654e6d2e958Smrg    eval _G_current_value='`$ECHO $'$1'`'
655e6d2e958Smrg    _G_delim=`expr "$2" : '\(.\)'`
656e6d2e958Smrg
657e6d2e958Smrg    case $_G_delim$_G_current_value$_G_delim in
658e6d2e958Smrg      *"$2$_G_delim"*) ;;
659e6d2e958Smrg      *) func_append "$@" ;;
660e6d2e958Smrg    esac
661e6d2e958Smrg}
662e6d2e958Smrg
663e6d2e958Smrg
664e6d2e958Smrg# func_arith TERM...
665e6d2e958Smrg# ------------------
666e6d2e958Smrg# Set func_arith_result to the result of evaluating TERMs.
667e6d2e958Smrg  test -z "$_G_HAVE_ARITH_OP" \
668e6d2e958Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669e6d2e958Smrg    && _G_HAVE_ARITH_OP=yes
670e6d2e958Smrg
671e6d2e958Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672e6d2e958Smrg  eval 'func_arith ()
673e6d2e958Smrg  {
674e6d2e958Smrg    $debug_cmd
675e6d2e958Smrg
676e6d2e958Smrg    func_arith_result=$(( $* ))
677e6d2e958Smrg  }'
678e6d2e958Smrgelse
679e6d2e958Smrg  func_arith ()
680e6d2e958Smrg  {
681e6d2e958Smrg    $debug_cmd
682e6d2e958Smrg
683e6d2e958Smrg    func_arith_result=`expr "$@"`
684e6d2e958Smrg  }
685e6d2e958Smrgfi
686e6d2e958Smrg
687e6d2e958Smrg
688e6d2e958Smrg# func_basename FILE
689e6d2e958Smrg# ------------------
690e6d2e958Smrg# Set func_basename_result to FILE with everything up to and including
691e6d2e958Smrg# the last / stripped.
692e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693e6d2e958Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694e6d2e958Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695e6d2e958Smrg  # on unsupported syntax...
696e6d2e958Smrg  _b='func_basename_result=${1##*/}'
697e6d2e958Smrg  _d='case $1 in
698e6d2e958Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699e6d2e958Smrg        *  ) func_dirname_result=$3        ;;
700e6d2e958Smrg      esac'
701e6d2e958Smrg
702e6d2e958Smrgelse
703e6d2e958Smrg  # ...otherwise fall back to using sed.
704e6d2e958Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705e6d2e958Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706e6d2e958Smrg      if test "X$func_dirname_result" = "X$1"; then
707e6d2e958Smrg        func_dirname_result=$3
708e6d2e958Smrg      else
709e6d2e958Smrg        func_append func_dirname_result "$2"
710e6d2e958Smrg      fi'
711e6d2e958Smrgfi
712e6d2e958Smrg
713e6d2e958Smrgeval 'func_basename ()
714e6d2e958Smrg{
715e6d2e958Smrg    $debug_cmd
716e6d2e958Smrg
717e6d2e958Smrg    '"$_b"'
718e6d2e958Smrg}'
719e6d2e958Smrg
720e6d2e958Smrg
721e6d2e958Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722e6d2e958Smrg# -------------------------------------------
723e6d2e958Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724e6d2e958Smrg# otherwise set result to NONDIR_REPLACEMENT.
725e6d2e958Smrgeval 'func_dirname ()
726e6d2e958Smrg{
727e6d2e958Smrg    $debug_cmd
728e6d2e958Smrg
729e6d2e958Smrg    '"$_d"'
730e6d2e958Smrg}'
731e6d2e958Smrg
732e6d2e958Smrg
733e6d2e958Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734e6d2e958Smrg# --------------------------------------------------------
735e6d2e958Smrg# Perform func_basename and func_dirname in a single function
736e6d2e958Smrg# call:
737e6d2e958Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738e6d2e958Smrg#             add APPEND to the result, otherwise set result
739e6d2e958Smrg#             to NONDIR_REPLACEMENT.
740e6d2e958Smrg#             value returned in "$func_dirname_result"
741e6d2e958Smrg#   basename: Compute filename of FILE.
742e6d2e958Smrg#             value retuned in "$func_basename_result"
743e6d2e958Smrg# For efficiency, we do not delegate to the functions above but instead
744e6d2e958Smrg# duplicate the functionality here.
745e6d2e958Smrgeval 'func_dirname_and_basename ()
746e6d2e958Smrg{
747e6d2e958Smrg    $debug_cmd
748e6d2e958Smrg
749e6d2e958Smrg    '"$_b"'
750e6d2e958Smrg    '"$_d"'
751e6d2e958Smrg}'
752e6d2e958Smrg
753e6d2e958Smrg
754e6d2e958Smrg# func_echo ARG...
755e6d2e958Smrg# ----------------
756e6d2e958Smrg# Echo program name prefixed message.
757e6d2e958Smrgfunc_echo ()
758e6d2e958Smrg{
759e6d2e958Smrg    $debug_cmd
760e6d2e958Smrg
761e6d2e958Smrg    _G_message=$*
762e6d2e958Smrg
763e6d2e958Smrg    func_echo_IFS=$IFS
764e6d2e958Smrg    IFS=$nl
765e6d2e958Smrg    for _G_line in $_G_message; do
766e6d2e958Smrg      IFS=$func_echo_IFS
767e6d2e958Smrg      $ECHO "$progname: $_G_line"
768e6d2e958Smrg    done
769e6d2e958Smrg    IFS=$func_echo_IFS
770e6d2e958Smrg}
771e6d2e958Smrg
772e6d2e958Smrg
773e6d2e958Smrg# func_echo_all ARG...
774e6d2e958Smrg# --------------------
775e6d2e958Smrg# Invoke $ECHO with all args, space-separated.
776e6d2e958Smrgfunc_echo_all ()
777e6d2e958Smrg{
778e6d2e958Smrg    $ECHO "$*"
779e6d2e958Smrg}
780e6d2e958Smrg
781e6d2e958Smrg
782e6d2e958Smrg# func_echo_infix_1 INFIX ARG...
783e6d2e958Smrg# ------------------------------
784e6d2e958Smrg# Echo program name, followed by INFIX on the first line, with any
785e6d2e958Smrg# additional lines not showing INFIX.
786e6d2e958Smrgfunc_echo_infix_1 ()
787e6d2e958Smrg{
788e6d2e958Smrg    $debug_cmd
789e6d2e958Smrg
790e6d2e958Smrg    $require_term_colors
791e6d2e958Smrg
792e6d2e958Smrg    _G_infix=$1; shift
793e6d2e958Smrg    _G_indent=$_G_infix
794e6d2e958Smrg    _G_prefix="$progname: $_G_infix: "
795e6d2e958Smrg    _G_message=$*
796e6d2e958Smrg
797e6d2e958Smrg    # Strip color escape sequences before counting printable length
798e6d2e958Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799e6d2e958Smrg    do
800e6d2e958Smrg      test -n "$_G_tc" && {
801e6d2e958Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802e6d2e958Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803e6d2e958Smrg      }
804e6d2e958Smrg    done
805e6d2e958Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806e6d2e958Smrg
807e6d2e958Smrg    func_echo_infix_1_IFS=$IFS
808e6d2e958Smrg    IFS=$nl
809e6d2e958Smrg    for _G_line in $_G_message; do
810e6d2e958Smrg      IFS=$func_echo_infix_1_IFS
811e6d2e958Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812e6d2e958Smrg      _G_prefix=$_G_indent
813e6d2e958Smrg    done
814e6d2e958Smrg    IFS=$func_echo_infix_1_IFS
815e6d2e958Smrg}
816e6d2e958Smrg
817e6d2e958Smrg
818e6d2e958Smrg# func_error ARG...
819e6d2e958Smrg# -----------------
820e6d2e958Smrg# Echo program name prefixed message to standard error.
821e6d2e958Smrgfunc_error ()
822e6d2e958Smrg{
823e6d2e958Smrg    $debug_cmd
824e6d2e958Smrg
825e6d2e958Smrg    $require_term_colors
826e6d2e958Smrg
827e6d2e958Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828e6d2e958Smrg}
829e6d2e958Smrg
830e6d2e958Smrg
831e6d2e958Smrg# func_fatal_error ARG...
832e6d2e958Smrg# -----------------------
833e6d2e958Smrg# Echo program name prefixed message to standard error, and exit.
834e6d2e958Smrgfunc_fatal_error ()
835e6d2e958Smrg{
836e6d2e958Smrg    $debug_cmd
837e6d2e958Smrg
838e6d2e958Smrg    func_error "$*"
839e6d2e958Smrg    exit $EXIT_FAILURE
840e6d2e958Smrg}
841e6d2e958Smrg
842e6d2e958Smrg
843e6d2e958Smrg# func_grep EXPRESSION FILENAME
844e6d2e958Smrg# -----------------------------
84547e89262Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
84647e89262Smrgfunc_grep ()
84747e89262Smrg{
848e6d2e958Smrg    $debug_cmd
849e6d2e958Smrg
85047e89262Smrg    $GREP "$1" "$2" >/dev/null 2>&1
85147e89262Smrg}
85247e89262Smrg
85347e89262Smrg
854e6d2e958Smrg# func_len STRING
855e6d2e958Smrg# ---------------
856e6d2e958Smrg# Set func_len_result to the length of STRING. STRING may not
857e6d2e958Smrg# start with a hyphen.
858e6d2e958Smrg  test -z "$_G_HAVE_XSI_OPS" \
859e6d2e958Smrg    && (eval 'x=a/b/c;
860e6d2e958Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861e6d2e958Smrg    && _G_HAVE_XSI_OPS=yes
862e6d2e958Smrg
863e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864e6d2e958Smrg  eval 'func_len ()
865e6d2e958Smrg  {
866e6d2e958Smrg    $debug_cmd
867e6d2e958Smrg
868e6d2e958Smrg    func_len_result=${#1}
869e6d2e958Smrg  }'
870e6d2e958Smrgelse
871e6d2e958Smrg  func_len ()
872e6d2e958Smrg  {
873e6d2e958Smrg    $debug_cmd
874e6d2e958Smrg
875e6d2e958Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876e6d2e958Smrg  }
877e6d2e958Smrgfi
878e6d2e958Smrg
879e6d2e958Smrg
880e6d2e958Smrg# func_mkdir_p DIRECTORY-PATH
881e6d2e958Smrg# ---------------------------
88247e89262Smrg# Make sure the entire path to DIRECTORY-PATH is available.
88347e89262Smrgfunc_mkdir_p ()
88447e89262Smrg{
885e6d2e958Smrg    $debug_cmd
88647e89262Smrg
887e6d2e958Smrg    _G_directory_path=$1
888e6d2e958Smrg    _G_dir_list=
88947e89262Smrg
890e6d2e958Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891e6d2e958Smrg
892e6d2e958Smrg      # Protect directory names starting with '-'
893e6d2e958Smrg      case $_G_directory_path in
894e6d2e958Smrg        -*) _G_directory_path=./$_G_directory_path ;;
89547e89262Smrg      esac
89647e89262Smrg
89747e89262Smrg      # While some portion of DIR does not yet exist...
898e6d2e958Smrg      while test ! -d "$_G_directory_path"; do
89947e89262Smrg        # ...make a list in topmost first order.  Use a colon delimited
90047e89262Smrg	# list incase some portion of path contains whitespace.
901e6d2e958Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
90247e89262Smrg
90347e89262Smrg        # If the last portion added has no slash in it, the list is done
904e6d2e958Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
90547e89262Smrg
90647e89262Smrg        # ...otherwise throw away the child directory and loop
907e6d2e958Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
90847e89262Smrg      done
909e6d2e958Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
91047e89262Smrg
911e6d2e958Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912e6d2e958Smrg      for _G_dir in $_G_dir_list; do
913e6d2e958Smrg	IFS=$func_mkdir_p_IFS
914e6d2e958Smrg        # mkdir can fail with a 'File exist' error if two processes
91547e89262Smrg        # try to create one of the directories concurrently.  Don't
91647e89262Smrg        # stop in that case!
917e6d2e958Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
91847e89262Smrg      done
919e6d2e958Smrg      IFS=$func_mkdir_p_IFS
92047e89262Smrg
92147e89262Smrg      # Bail out if we (or some other process) failed to create a directory.
922e6d2e958Smrg      test -d "$_G_directory_path" || \
923e6d2e958Smrg        func_fatal_error "Failed to create '$1'"
92447e89262Smrg    fi
92547e89262Smrg}
926bd1da9d7Smrg
927bd1da9d7Smrg
928e6d2e958Smrg# func_mktempdir [BASENAME]
929e6d2e958Smrg# -------------------------
930bd1da9d7Smrg# Make a temporary directory that won't clash with other running
931bd1da9d7Smrg# libtool processes, and avoids race conditions if possible.  If
932e6d2e958Smrg# given, BASENAME is the basename for that directory.
933bd1da9d7Smrgfunc_mktempdir ()
934bd1da9d7Smrg{
935e6d2e958Smrg    $debug_cmd
936e6d2e958Smrg
937e6d2e958Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938bd1da9d7Smrg
939e6d2e958Smrg    if test : = "$opt_dry_run"; then
940bd1da9d7Smrg      # Return a directory name, but don't create it in dry-run mode
941e6d2e958Smrg      _G_tmpdir=$_G_template-$$
942bd1da9d7Smrg    else
943bd1da9d7Smrg
944bd1da9d7Smrg      # If mktemp works, use that first and foremost
945e6d2e958Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946bd1da9d7Smrg
947e6d2e958Smrg      if test ! -d "$_G_tmpdir"; then
94847e89262Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949e6d2e958Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950bd1da9d7Smrg
951e6d2e958Smrg        func_mktempdir_umask=`umask`
95247e89262Smrg        umask 0077
953e6d2e958Smrg        $MKDIR "$_G_tmpdir"
954e6d2e958Smrg        umask $func_mktempdir_umask
955bd1da9d7Smrg      fi
956bd1da9d7Smrg
957bd1da9d7Smrg      # If we're not in dry-run mode, bomb out on failure
958e6d2e958Smrg      test -d "$_G_tmpdir" || \
959e6d2e958Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960e6d2e958Smrg    fi
961e6d2e958Smrg
962e6d2e958Smrg    $ECHO "$_G_tmpdir"
963e6d2e958Smrg}
964e6d2e958Smrg
965e6d2e958Smrg
966e6d2e958Smrg# func_normal_abspath PATH
967e6d2e958Smrg# ------------------------
968e6d2e958Smrg# Remove doubled-up and trailing slashes, "." path components,
969e6d2e958Smrg# and cancel out any ".." path components in PATH after making
970e6d2e958Smrg# it an absolute path.
971e6d2e958Smrgfunc_normal_abspath ()
972e6d2e958Smrg{
973e6d2e958Smrg    $debug_cmd
974e6d2e958Smrg
975e6d2e958Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976e6d2e958Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977e6d2e958Smrg    _G_pathcdr='s|^/[^/]*||'
978e6d2e958Smrg    _G_removedotparts=':dotsl
979e6d2e958Smrg		s|/\./|/|g
980e6d2e958Smrg		t dotsl
981e6d2e958Smrg		s|/\.$|/|'
982e6d2e958Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983e6d2e958Smrg    _G_finalslash='s|/*$|/|'
984e6d2e958Smrg
985e6d2e958Smrg    # Start from root dir and reassemble the path.
986e6d2e958Smrg    func_normal_abspath_result=
987e6d2e958Smrg    func_normal_abspath_tpath=$1
988e6d2e958Smrg    func_normal_abspath_altnamespace=
989e6d2e958Smrg    case $func_normal_abspath_tpath in
990e6d2e958Smrg      "")
991e6d2e958Smrg        # Empty path, that just means $cwd.
992e6d2e958Smrg        func_stripname '' '/' "`pwd`"
993e6d2e958Smrg        func_normal_abspath_result=$func_stripname_result
994e6d2e958Smrg        return
995e6d2e958Smrg        ;;
996e6d2e958Smrg      # The next three entries are used to spot a run of precisely
997e6d2e958Smrg      # two leading slashes without using negated character classes;
998e6d2e958Smrg      # we take advantage of case's first-match behaviour.
999e6d2e958Smrg      ///*)
1000e6d2e958Smrg        # Unusual form of absolute path, do nothing.
1001e6d2e958Smrg        ;;
1002e6d2e958Smrg      //*)
1003e6d2e958Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004e6d2e958Smrg        # and for example Cygwin uses it to access remote file shares
1005e6d2e958Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006e6d2e958Smrg        func_normal_abspath_altnamespace=/
1007e6d2e958Smrg        ;;
1008e6d2e958Smrg      /*)
1009e6d2e958Smrg        # Absolute path, do nothing.
1010e6d2e958Smrg        ;;
1011e6d2e958Smrg      *)
1012e6d2e958Smrg        # Relative path, prepend $cwd.
1013e6d2e958Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014e6d2e958Smrg        ;;
1015e6d2e958Smrg    esac
1016e6d2e958Smrg
1017e6d2e958Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018e6d2e958Smrg    # the path to end with a slash for ease of parsing, so make sure
1019e6d2e958Smrg    # there is one (and only one) here.
1020e6d2e958Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021e6d2e958Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022e6d2e958Smrg    while :; do
1023e6d2e958Smrg      # Processed it all yet?
1024e6d2e958Smrg      if test / = "$func_normal_abspath_tpath"; then
1025e6d2e958Smrg        # If we ascended to the root using ".." the result may be empty now.
1026e6d2e958Smrg        if test -z "$func_normal_abspath_result"; then
1027e6d2e958Smrg          func_normal_abspath_result=/
1028e6d2e958Smrg        fi
1029e6d2e958Smrg        break
1030e6d2e958Smrg      fi
1031e6d2e958Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032e6d2e958Smrg          -e "$_G_pathcar"`
1033e6d2e958Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034e6d2e958Smrg          -e "$_G_pathcdr"`
1035e6d2e958Smrg      # Figure out what to do with it
1036e6d2e958Smrg      case $func_normal_abspath_tcomponent in
1037e6d2e958Smrg        "")
1038e6d2e958Smrg          # Trailing empty path component, ignore it.
1039e6d2e958Smrg          ;;
1040e6d2e958Smrg        ..)
1041e6d2e958Smrg          # Parent dir; strip last assembled component from result.
1042e6d2e958Smrg          func_dirname "$func_normal_abspath_result"
1043e6d2e958Smrg          func_normal_abspath_result=$func_dirname_result
1044e6d2e958Smrg          ;;
1045e6d2e958Smrg        *)
1046e6d2e958Smrg          # Actual path component, append it.
1047e6d2e958Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048e6d2e958Smrg          ;;
1049e6d2e958Smrg      esac
1050e6d2e958Smrg    done
1051e6d2e958Smrg    # Restore leading double-slash if one was found on entry.
1052e6d2e958Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053e6d2e958Smrg}
1054e6d2e958Smrg
1055e6d2e958Smrg
1056e6d2e958Smrg# func_notquiet ARG...
1057e6d2e958Smrg# --------------------
1058e6d2e958Smrg# Echo program name prefixed message only when not in quiet mode.
1059e6d2e958Smrgfunc_notquiet ()
1060e6d2e958Smrg{
1061e6d2e958Smrg    $debug_cmd
1062e6d2e958Smrg
1063e6d2e958Smrg    $opt_quiet || func_echo ${1+"$@"}
1064e6d2e958Smrg
1065e6d2e958Smrg    # A bug in bash halts the script if the last line of a function
1066e6d2e958Smrg    # fails when set -e is in force, so we need another command to
1067e6d2e958Smrg    # work around that:
1068e6d2e958Smrg    :
1069e6d2e958Smrg}
1070e6d2e958Smrg
1071e6d2e958Smrg
1072e6d2e958Smrg# func_relative_path SRCDIR DSTDIR
1073e6d2e958Smrg# --------------------------------
1074e6d2e958Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075e6d2e958Smrgfunc_relative_path ()
1076e6d2e958Smrg{
1077e6d2e958Smrg    $debug_cmd
1078e6d2e958Smrg
1079e6d2e958Smrg    func_relative_path_result=
1080e6d2e958Smrg    func_normal_abspath "$1"
1081e6d2e958Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082e6d2e958Smrg    func_normal_abspath "$2"
1083e6d2e958Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084e6d2e958Smrg
1085e6d2e958Smrg    # Ascend the tree starting from libdir
1086e6d2e958Smrg    while :; do
1087e6d2e958Smrg      # check if we have found a prefix of bindir
1088e6d2e958Smrg      case $func_relative_path_tbindir in
1089e6d2e958Smrg        $func_relative_path_tlibdir)
1090e6d2e958Smrg          # found an exact match
1091e6d2e958Smrg          func_relative_path_tcancelled=
1092e6d2e958Smrg          break
1093e6d2e958Smrg          ;;
1094e6d2e958Smrg        $func_relative_path_tlibdir*)
1095e6d2e958Smrg          # found a matching prefix
1096e6d2e958Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097e6d2e958Smrg          func_relative_path_tcancelled=$func_stripname_result
1098e6d2e958Smrg          if test -z "$func_relative_path_result"; then
1099e6d2e958Smrg            func_relative_path_result=.
1100e6d2e958Smrg          fi
1101e6d2e958Smrg          break
1102e6d2e958Smrg          ;;
1103e6d2e958Smrg        *)
1104e6d2e958Smrg          func_dirname $func_relative_path_tlibdir
1105e6d2e958Smrg          func_relative_path_tlibdir=$func_dirname_result
1106e6d2e958Smrg          if test -z "$func_relative_path_tlibdir"; then
1107e6d2e958Smrg            # Have to descend all the way to the root!
1108e6d2e958Smrg            func_relative_path_result=../$func_relative_path_result
1109e6d2e958Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110e6d2e958Smrg            break
1111e6d2e958Smrg          fi
1112e6d2e958Smrg          func_relative_path_result=../$func_relative_path_result
1113e6d2e958Smrg          ;;
1114e6d2e958Smrg      esac
1115e6d2e958Smrg    done
1116e6d2e958Smrg
1117e6d2e958Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118e6d2e958Smrg    func_stripname '' '/' "$func_relative_path_result"
1119e6d2e958Smrg    func_relative_path_result=$func_stripname_result
1120e6d2e958Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121e6d2e958Smrg    if test -n "$func_stripname_result"; then
1122e6d2e958Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123e6d2e958Smrg    fi
1124e6d2e958Smrg
1125e6d2e958Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126e6d2e958Smrg    if test -n "$func_relative_path_result"; then
1127e6d2e958Smrg      func_stripname './' '' "$func_relative_path_result"
1128e6d2e958Smrg      func_relative_path_result=$func_stripname_result
1129bd1da9d7Smrg    fi
1130bd1da9d7Smrg
1131e6d2e958Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132e6d2e958Smrg
1133e6d2e958Smrg    :
1134e6d2e958Smrg}
1135e6d2e958Smrg
1136e6d2e958Smrg
1137a392d4f3Smrg# func_quote_portable EVAL ARG
1138a392d4f3Smrg# ----------------------------
1139a392d4f3Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140a392d4f3Smrg# keep attention to performance here so we as much as possible try to avoid
1141a392d4f3Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142a392d4f3Smrgfunc_quote_portable ()
1143e6d2e958Smrg{
1144e6d2e958Smrg    $debug_cmd
1145e6d2e958Smrg
1146a392d4f3Smrg    $require_check_ifs_backslash
1147a392d4f3Smrg
1148a392d4f3Smrg    func_quote_portable_result=$2
1149a392d4f3Smrg
1150a392d4f3Smrg    # one-time-loop (easy break)
1151a392d4f3Smrg    while true
1152a392d4f3Smrg    do
1153a392d4f3Smrg      if $1; then
1154a392d4f3Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155a392d4f3Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156a392d4f3Smrg        break
1157e6d2e958Smrg      fi
1158e6d2e958Smrg
1159a392d4f3Smrg      # Quote for eval.
1160a392d4f3Smrg      case $func_quote_portable_result in
1161a392d4f3Smrg        *[\\\`\"\$]*)
1162a392d4f3Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163a392d4f3Smrg          # contains the shell wildcard characters.
1164a392d4f3Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165a392d4f3Smrg            :*|*[\[\*\?]*)
1166a392d4f3Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167a392d4f3Smrg                  | $SED "$sed_quote_subst"`
1168a392d4f3Smrg              break
1169a392d4f3Smrg              ;;
1170a392d4f3Smrg          esac
1171a392d4f3Smrg
1172a392d4f3Smrg          func_quote_portable_old_IFS=$IFS
1173a392d4f3Smrg          for _G_char in '\' '`' '"' '$'
1174a392d4f3Smrg          do
1175a392d4f3Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176a392d4f3Smrg            set start "" ""
1177a392d4f3Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178a392d4f3Smrg            IFS=$_G_char
1179a392d4f3Smrg            for _G_part in $func_quote_portable_result
1180a392d4f3Smrg            do
1181a392d4f3Smrg              case $1 in
1182a392d4f3Smrg              quote)
1183a392d4f3Smrg                func_append func_quote_portable_result "$3$2"
1184a392d4f3Smrg                set quote "$_G_part" "\\$_G_char"
1185a392d4f3Smrg                ;;
1186a392d4f3Smrg              start)
1187a392d4f3Smrg                set first "" ""
1188a392d4f3Smrg                func_quote_portable_result=
1189a392d4f3Smrg                ;;
1190a392d4f3Smrg              first)
1191a392d4f3Smrg                set quote "$_G_part" ""
1192a392d4f3Smrg                ;;
1193a392d4f3Smrg              esac
1194a392d4f3Smrg            done
1195a392d4f3Smrg          done
1196a392d4f3Smrg          IFS=$func_quote_portable_old_IFS
1197e6d2e958Smrg          ;;
1198a392d4f3Smrg        *) ;;
1199e6d2e958Smrg      esac
1200a392d4f3Smrg      break
1201e6d2e958Smrg    done
1202a392d4f3Smrg
1203a392d4f3Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204a392d4f3Smrg    case $func_quote_portable_result in
1205a392d4f3Smrg      # double-quote args containing shell metacharacters to delay
1206a392d4f3Smrg      # word splitting, command substitution and variable expansion
1207a392d4f3Smrg      # for a subsequent eval.
1208a392d4f3Smrg      # many bourne shells cannot handle close brackets correctly
1209a392d4f3Smrg      # in scan sets, so we specify it separately.
1210a392d4f3Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211a392d4f3Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212a392d4f3Smrg        ;;
1213a392d4f3Smrg    esac
1214e6d2e958Smrg}
1215e6d2e958Smrg
1216e6d2e958Smrg
1217a392d4f3Smrg# func_quotefast_eval ARG
1218a392d4f3Smrg# -----------------------
1219a392d4f3Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220a392d4f3Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221a392d4f3Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222a392d4f3Smrg  printf -v _GL_test_printf_tilde %q '~'
1223a392d4f3Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224a392d4f3Smrg    func_quotefast_eval ()
1225a392d4f3Smrg    {
1226a392d4f3Smrg      printf -v func_quotefast_eval_result %q "$1"
1227a392d4f3Smrg    }
1228a392d4f3Smrg  else
1229a392d4f3Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230a392d4f3Smrg    func_quotefast_eval ()
1231a392d4f3Smrg    {
1232a392d4f3Smrg      case $1 in
1233a392d4f3Smrg        '~'*)
1234a392d4f3Smrg          func_quote_portable false "$1"
1235a392d4f3Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236a392d4f3Smrg          ;;
1237a392d4f3Smrg        *)
1238a392d4f3Smrg          printf -v func_quotefast_eval_result %q "$1"
1239a392d4f3Smrg          ;;
1240a392d4f3Smrg      esac
1241a392d4f3Smrg    }
1242a392d4f3Smrg  fi
1243a392d4f3Smrgelse
1244a392d4f3Smrg  func_quotefast_eval ()
1245a392d4f3Smrg  {
1246a392d4f3Smrg    func_quote_portable false "$1"
1247a392d4f3Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248a392d4f3Smrg  }
1249a392d4f3Smrgfi
1250e6d2e958Smrg
1251a392d4f3Smrg
1252a392d4f3Smrg# func_quote_arg MODEs ARG
1253a392d4f3Smrg# ------------------------
1254a392d4f3Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255a392d4f3Smrg# specifiers listed below separated by ',' character.  This function returns two
1256a392d4f3Smrg# values:
1257a392d4f3Smrg#   i) func_quote_arg_result
1258a392d4f3Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259a392d4f3Smrg#  ii) func_quote_arg_unquoted_result
1260a392d4f3Smrg#      has all characters that are still active within double
1261a392d4f3Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262a392d4f3Smrg#
1263a392d4f3Smrg# Available modes:
1264a392d4f3Smrg# ----------------
1265a392d4f3Smrg# 'eval' (default)
1266a392d4f3Smrg#       - escape shell special characters
1267a392d4f3Smrg# 'expand'
1268a392d4f3Smrg#       - the same as 'eval';  but do not quote variable references
1269a392d4f3Smrg# 'pretty'
1270a392d4f3Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271a392d4f3Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272a392d4f3Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273a392d4f3Smrg# 'unquoted'
1274a392d4f3Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275a392d4f3Smrg#         wrapping double-quotes.
1276a392d4f3Smrg#
1277a392d4f3Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278a392d4f3Smrg#
1279a392d4f3Smrg#   string      | *_result              | *_unquoted_result
1280a392d4f3Smrg#   ------------+-----------------------+-------------------
1281a392d4f3Smrg#   "           | \"                    | \"
1282a392d4f3Smrg#   a b         | "a b"                 | a b
1283a392d4f3Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284a392d4f3Smrg#   *           | "*"                   | *
1285a392d4f3Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286a392d4f3Smrg#
1287a392d4f3Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288a392d4f3Smrg#
1289a392d4f3Smrg#   string        |   *_result          |  *_unquoted_result
1290a392d4f3Smrg#   --------------+---------------------+--------------------
1291a392d4f3Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292a392d4f3Smrgfunc_quote_arg ()
1293a392d4f3Smrg{
1294a392d4f3Smrg    _G_quote_expand=false
1295a392d4f3Smrg    case ,$1, in
1296a392d4f3Smrg      *,expand,*)
1297a392d4f3Smrg        _G_quote_expand=:
1298a392d4f3Smrg        ;;
1299e6d2e958Smrg    esac
1300e6d2e958Smrg
1301a392d4f3Smrg    case ,$1, in
1302a392d4f3Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303a392d4f3Smrg        func_quote_portable $_G_quote_expand "$2"
1304a392d4f3Smrg        func_quote_arg_result=$func_quote_portable_result
1305a392d4f3Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306a392d4f3Smrg        ;;
1307a392d4f3Smrg      *)
1308a392d4f3Smrg        # Faster quote-for-eval for some shells.
1309a392d4f3Smrg        func_quotefast_eval "$2"
1310a392d4f3Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311e6d2e958Smrg        ;;
1312e6d2e958Smrg    esac
1313a392d4f3Smrg}
1314a392d4f3Smrg
1315e6d2e958Smrg
1316a392d4f3Smrg# func_quote MODEs ARGs...
1317a392d4f3Smrg# ------------------------
1318a392d4f3Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319a392d4f3Smrg# func_quote_arg's description for more info.
1320a392d4f3Smrgfunc_quote ()
1321a392d4f3Smrg{
1322a392d4f3Smrg    $debug_cmd
1323a392d4f3Smrg    _G_func_quote_mode=$1 ; shift
1324a392d4f3Smrg    func_quote_result=
1325a392d4f3Smrg    while test 0 -lt $#; do
1326a392d4f3Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327a392d4f3Smrg      if test -n "$func_quote_result"; then
1328a392d4f3Smrg        func_append func_quote_result " $func_quote_arg_result"
1329a392d4f3Smrg      else
1330a392d4f3Smrg        func_append func_quote_result "$func_quote_arg_result"
1331a392d4f3Smrg      fi
1332a392d4f3Smrg      shift
1333a392d4f3Smrg    done
1334e6d2e958Smrg}
1335e6d2e958Smrg
1336e6d2e958Smrg
1337e6d2e958Smrg# func_stripname PREFIX SUFFIX NAME
1338e6d2e958Smrg# ---------------------------------
1339e6d2e958Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340e6d2e958Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341e6d2e958Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342e6d2e958Smrg# dot (in which case that matches only a dot).
1343e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344e6d2e958Smrg  eval 'func_stripname ()
1345e6d2e958Smrg  {
1346e6d2e958Smrg    $debug_cmd
1347e6d2e958Smrg
1348e6d2e958Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349e6d2e958Smrg    # positional parameters, so assign one to ordinary variable first.
1350e6d2e958Smrg    func_stripname_result=$3
1351e6d2e958Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352e6d2e958Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353e6d2e958Smrg  }'
1354e6d2e958Smrgelse
1355e6d2e958Smrg  func_stripname ()
1356e6d2e958Smrg  {
1357e6d2e958Smrg    $debug_cmd
1358e6d2e958Smrg
1359e6d2e958Smrg    case $2 in
1360e6d2e958Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361e6d2e958Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362e6d2e958Smrg    esac
1363e6d2e958Smrg  }
1364e6d2e958Smrgfi
1365e6d2e958Smrg
1366e6d2e958Smrg
1367e6d2e958Smrg# func_show_eval CMD [FAIL_EXP]
1368e6d2e958Smrg# -----------------------------
1369e6d2e958Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370e6d2e958Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371e6d2e958Smrg# is given, then evaluate it.
1372e6d2e958Smrgfunc_show_eval ()
1373e6d2e958Smrg{
1374e6d2e958Smrg    $debug_cmd
1375e6d2e958Smrg
1376e6d2e958Smrg    _G_cmd=$1
1377e6d2e958Smrg    _G_fail_exp=${2-':'}
1378e6d2e958Smrg
1379a392d4f3Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380a392d4f3Smrg    eval "func_notquiet $func_quote_arg_result"
1381e6d2e958Smrg
1382e6d2e958Smrg    $opt_dry_run || {
1383e6d2e958Smrg      eval "$_G_cmd"
1384e6d2e958Smrg      _G_status=$?
1385e6d2e958Smrg      if test 0 -ne "$_G_status"; then
1386e6d2e958Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387e6d2e958Smrg      fi
1388e6d2e958Smrg    }
1389e6d2e958Smrg}
1390e6d2e958Smrg
1391e6d2e958Smrg
1392e6d2e958Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393e6d2e958Smrg# ------------------------------------
1394e6d2e958Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395e6d2e958Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396e6d2e958Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397e6d2e958Smrgfunc_show_eval_locale ()
1398e6d2e958Smrg{
1399e6d2e958Smrg    $debug_cmd
1400e6d2e958Smrg
1401e6d2e958Smrg    _G_cmd=$1
1402e6d2e958Smrg    _G_fail_exp=${2-':'}
1403e6d2e958Smrg
1404e6d2e958Smrg    $opt_quiet || {
1405a392d4f3Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406a392d4f3Smrg      eval "func_echo $func_quote_arg_result"
1407e6d2e958Smrg    }
1408e6d2e958Smrg
1409e6d2e958Smrg    $opt_dry_run || {
1410e6d2e958Smrg      eval "$_G_user_locale
1411e6d2e958Smrg	    $_G_cmd"
1412e6d2e958Smrg      _G_status=$?
1413e6d2e958Smrg      eval "$_G_safe_locale"
1414e6d2e958Smrg      if test 0 -ne "$_G_status"; then
1415e6d2e958Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416e6d2e958Smrg      fi
1417e6d2e958Smrg    }
1418e6d2e958Smrg}
1419e6d2e958Smrg
1420e6d2e958Smrg
1421e6d2e958Smrg# func_tr_sh
1422e6d2e958Smrg# ----------
1423e6d2e958Smrg# Turn $1 into a string suitable for a shell variable name.
1424e6d2e958Smrg# Result is stored in $func_tr_sh_result.  All characters
1425e6d2e958Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426e6d2e958Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427e6d2e958Smrgfunc_tr_sh ()
1428e6d2e958Smrg{
1429e6d2e958Smrg    $debug_cmd
1430e6d2e958Smrg
1431e6d2e958Smrg    case $1 in
1432e6d2e958Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433e6d2e958Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434e6d2e958Smrg      ;;
1435e6d2e958Smrg    * )
1436e6d2e958Smrg      func_tr_sh_result=$1
1437e6d2e958Smrg      ;;
1438e6d2e958Smrg    esac
1439e6d2e958Smrg}
1440e6d2e958Smrg
1441e6d2e958Smrg
1442e6d2e958Smrg# func_verbose ARG...
1443e6d2e958Smrg# -------------------
1444e6d2e958Smrg# Echo program name prefixed message in verbose mode only.
1445e6d2e958Smrgfunc_verbose ()
1446e6d2e958Smrg{
1447e6d2e958Smrg    $debug_cmd
1448e6d2e958Smrg
1449e6d2e958Smrg    $opt_verbose && func_echo "$*"
1450e6d2e958Smrg
1451e6d2e958Smrg    :
1452e6d2e958Smrg}
1453e6d2e958Smrg
1454e6d2e958Smrg
1455e6d2e958Smrg# func_warn_and_continue ARG...
1456e6d2e958Smrg# -----------------------------
1457e6d2e958Smrg# Echo program name prefixed warning message to standard error.
1458e6d2e958Smrgfunc_warn_and_continue ()
1459e6d2e958Smrg{
1460e6d2e958Smrg    $debug_cmd
1461e6d2e958Smrg
1462e6d2e958Smrg    $require_term_colors
1463e6d2e958Smrg
1464e6d2e958Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465e6d2e958Smrg}
1466e6d2e958Smrg
1467e6d2e958Smrg
1468e6d2e958Smrg# func_warning CATEGORY ARG...
1469e6d2e958Smrg# ----------------------------
1470e6d2e958Smrg# Echo program name prefixed warning message to standard error. Warning
1471e6d2e958Smrg# messages can be filtered according to CATEGORY, where this function
1472e6d2e958Smrg# elides messages where CATEGORY is not listed in the global variable
1473e6d2e958Smrg# 'opt_warning_types'.
1474e6d2e958Smrgfunc_warning ()
1475e6d2e958Smrg{
1476e6d2e958Smrg    $debug_cmd
1477e6d2e958Smrg
1478e6d2e958Smrg    # CATEGORY must be in the warning_categories list!
1479e6d2e958Smrg    case " $warning_categories " in
1480e6d2e958Smrg      *" $1 "*) ;;
1481e6d2e958Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482e6d2e958Smrg    esac
1483e6d2e958Smrg
1484e6d2e958Smrg    _G_category=$1
1485e6d2e958Smrg    shift
1486e6d2e958Smrg
1487e6d2e958Smrg    case " $opt_warning_types " in
1488e6d2e958Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489e6d2e958Smrg    esac
1490e6d2e958Smrg}
1491e6d2e958Smrg
1492e6d2e958Smrg
1493e6d2e958Smrg# func_sort_ver VER1 VER2
1494e6d2e958Smrg# -----------------------
1495e6d2e958Smrg# 'sort -V' is not generally available.
1496e6d2e958Smrg# Note this deviates from the version comparison in automake
1497e6d2e958Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498e6d2e958Smrg# but this should suffice as we won't be specifying old
1499e6d2e958Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500e6d2e958Smrg# If we did want full compatibility then we should probably
1501e6d2e958Smrg# use m4_version_compare from autoconf.
1502e6d2e958Smrgfunc_sort_ver ()
1503e6d2e958Smrg{
1504e6d2e958Smrg    $debug_cmd
1505e6d2e958Smrg
1506e6d2e958Smrg    printf '%s\n%s\n' "$1" "$2" \
1507e6d2e958Smrg      | 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
1508e6d2e958Smrg}
1509e6d2e958Smrg
1510e6d2e958Smrg# func_lt_ver PREV CURR
1511e6d2e958Smrg# ---------------------
1512e6d2e958Smrg# Return true if PREV and CURR are in the correct order according to
1513e6d2e958Smrg# func_sort_ver, otherwise false.  Use it like this:
1514e6d2e958Smrg#
1515e6d2e958Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516e6d2e958Smrgfunc_lt_ver ()
1517e6d2e958Smrg{
1518e6d2e958Smrg    $debug_cmd
1519e6d2e958Smrg
1520e6d2e958Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521e6d2e958Smrg}
1522e6d2e958Smrg
1523e6d2e958Smrg
1524e6d2e958Smrg# Local variables:
1525e6d2e958Smrg# mode: shell-script
1526e6d2e958Smrg# sh-indentation: 2
1527e6d2e958Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528e6d2e958Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529e6d2e958Smrg# time-stamp-time-zone: "UTC"
1530e6d2e958Smrg# End:
1531e6d2e958Smrg#! /bin/sh
1532e6d2e958Smrg
1533e6d2e958Smrg# A portable, pluggable option parser for Bourne shell.
1534e6d2e958Smrg# Written by Gary V. Vaughan, 2010
1535e6d2e958Smrg
1536a392d4f3Smrg# This is free software.  There is NO warranty; not even for
1537a392d4f3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538a392d4f3Smrg#
1539a392d4f3Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540a392d4f3Smrg#
1541a392d4f3Smrg# This file is dual licensed under the terms of the MIT license
1542a392d4f3Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543a392d4f3Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544a392d4f3Smrg# these licenses when using or redistributing this software or any of
1545a392d4f3Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546a392d4f3Smrg# included in the Bootstrap distribution for the full license texts.
1547e6d2e958Smrg
1548a392d4f3Smrg# Please report bugs or propose patches to:
1549a392d4f3Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550e6d2e958Smrg
1551a392d4f3Smrg# Set a version string for this script.
1552a392d4f3Smrgscriptversion=2019-02-19.15; # UTC
1553e6d2e958Smrg
1554e6d2e958Smrg
1555e6d2e958Smrg## ------ ##
1556e6d2e958Smrg## Usage. ##
1557e6d2e958Smrg## ------ ##
1558e6d2e958Smrg
1559e6d2e958Smrg# This file is a library for parsing options in your shell scripts along
1560e6d2e958Smrg# with assorted other useful supporting features that you can make use
1561e6d2e958Smrg# of too.
1562e6d2e958Smrg#
1563e6d2e958Smrg# For the simplest scripts you might need only:
1564e6d2e958Smrg#
1565e6d2e958Smrg#   #!/bin/sh
1566e6d2e958Smrg#   . relative/path/to/funclib.sh
1567e6d2e958Smrg#   . relative/path/to/options-parser
1568e6d2e958Smrg#   scriptversion=1.0
1569e6d2e958Smrg#   func_options ${1+"$@"}
1570e6d2e958Smrg#   eval set dummy "$func_options_result"; shift
1571e6d2e958Smrg#   ...rest of your script...
1572e6d2e958Smrg#
1573e6d2e958Smrg# In order for the '--version' option to work, you will need to have a
1574e6d2e958Smrg# suitably formatted comment like the one at the top of this file
1575a392d4f3Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576e6d2e958Smrg#
1577e6d2e958Smrg# For '-h' and '--help' to work, you will also need a one line
1578e6d2e958Smrg# description of your script's purpose in a comment directly above the
1579e6d2e958Smrg# '# Written by ' line, like the one at the top of this file.
1580e6d2e958Smrg#
1581e6d2e958Smrg# The default options also support '--debug', which will turn on shell
1582e6d2e958Smrg# execution tracing (see the comment above debug_cmd below for another
1583e6d2e958Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584e6d2e958Smrg# to display verbose messages only when your user has specified
1585e6d2e958Smrg# '--verbose'.
1586e6d2e958Smrg#
1587a392d4f3Smrg# After sourcing this file, you can plug in processing for additional
1588e6d2e958Smrg# options by amending the variables from the 'Configuration' section
1589e6d2e958Smrg# below, and following the instructions in the 'Option parsing'
1590e6d2e958Smrg# section further down.
1591e6d2e958Smrg
1592e6d2e958Smrg## -------------- ##
1593e6d2e958Smrg## Configuration. ##
1594e6d2e958Smrg## -------------- ##
1595e6d2e958Smrg
1596e6d2e958Smrg# You should override these variables in your script after sourcing this
1597e6d2e958Smrg# file so that they reflect the customisations you have added to the
1598e6d2e958Smrg# option parser.
1599e6d2e958Smrg
1600e6d2e958Smrg# The usage line for option parsing errors and the start of '-h' and
1601e6d2e958Smrg# '--help' output messages. You can embed shell variables for delayed
1602e6d2e958Smrg# expansion at the time the message is displayed, but you will need to
1603e6d2e958Smrg# quote other shell meta-characters carefully to prevent them being
1604e6d2e958Smrg# expanded when the contents are evaled.
1605e6d2e958Smrgusage='$progpath [OPTION]...'
1606e6d2e958Smrg
1607e6d2e958Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608e6d2e958Smrg# override it after sourcing this library to reflect the full set of
1609e6d2e958Smrg# options your script accepts.
1610e6d2e958Smrgusage_message="\
1611e6d2e958Smrg       --debug        enable verbose shell tracing
1612e6d2e958Smrg   -W, --warnings=CATEGORY
1613e6d2e958Smrg                      report the warnings falling in CATEGORY [all]
1614e6d2e958Smrg   -v, --verbose      verbosely report processing
1615e6d2e958Smrg       --version      print version information and exit
1616e6d2e958Smrg   -h, --help         print short or long help message and exit
1617e6d2e958Smrg"
1618e6d2e958Smrg
1619e6d2e958Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620e6d2e958Smrglong_help_message="
1621e6d2e958SmrgWarning categories include:
1622e6d2e958Smrg       'all'          show all warnings
1623e6d2e958Smrg       'none'         turn off all the warnings
1624e6d2e958Smrg       'error'        warnings are treated as fatal errors"
1625e6d2e958Smrg
1626e6d2e958Smrg# Help message printed before fatal option parsing errors.
1627e6d2e958Smrgfatal_help="Try '\$progname --help' for more information."
1628e6d2e958Smrg
1629e6d2e958Smrg
1630e6d2e958Smrg
1631e6d2e958Smrg## ------------------------- ##
1632e6d2e958Smrg## Hook function management. ##
1633e6d2e958Smrg## ------------------------- ##
1634e6d2e958Smrg
1635e6d2e958Smrg# This section contains functions for adding, removing, and running hooks
1636a392d4f3Smrg# in the main code.  A hook is just a list of function names that can be
1637a392d4f3Smrg# run in order later on.
1638e6d2e958Smrg
1639e6d2e958Smrg# func_hookable FUNC_NAME
1640e6d2e958Smrg# -----------------------
1641e6d2e958Smrg# Declare that FUNC_NAME will run hooks added with
1642e6d2e958Smrg# 'func_add_hook FUNC_NAME ...'.
1643e6d2e958Smrgfunc_hookable ()
1644e6d2e958Smrg{
1645e6d2e958Smrg    $debug_cmd
1646e6d2e958Smrg
1647e6d2e958Smrg    func_append hookable_fns " $1"
1648e6d2e958Smrg}
1649e6d2e958Smrg
1650e6d2e958Smrg
1651e6d2e958Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652e6d2e958Smrg# ---------------------------------
1653e6d2e958Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654e6d2e958Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655e6d2e958Smrgfunc_add_hook ()
1656e6d2e958Smrg{
1657e6d2e958Smrg    $debug_cmd
1658e6d2e958Smrg
1659e6d2e958Smrg    case " $hookable_fns " in
1660e6d2e958Smrg      *" $1 "*) ;;
1661e6d2e958Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662e6d2e958Smrg    esac
1663e6d2e958Smrg
1664e6d2e958Smrg    eval func_append ${1}_hooks '" $2"'
1665e6d2e958Smrg}
1666e6d2e958Smrg
1667e6d2e958Smrg
1668e6d2e958Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669e6d2e958Smrg# ------------------------------------
1670a392d4f3Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671a392d4f3Smrg# FUNC_NAME.
1672e6d2e958Smrgfunc_remove_hook ()
1673e6d2e958Smrg{
1674e6d2e958Smrg    $debug_cmd
1675e6d2e958Smrg
1676e6d2e958Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677e6d2e958Smrg}
1678e6d2e958Smrg
1679e6d2e958Smrg
1680a392d4f3Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681a392d4f3Smrg# ---------------------------------------------
1682a392d4f3Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683a392d4f3Smrg# *_result variable of FUNC_NAME_B.
1684a392d4f3Smrgfunc_propagate_result ()
1685a392d4f3Smrg{
1686a392d4f3Smrg    $debug_cmd
1687a392d4f3Smrg
1688a392d4f3Smrg    func_propagate_result_result=:
1689a392d4f3Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690a392d4f3Smrg    then
1691a392d4f3Smrg      eval "${2}_result=\$${1}_result"
1692a392d4f3Smrg    else
1693a392d4f3Smrg      func_propagate_result_result=false
1694a392d4f3Smrg    fi
1695a392d4f3Smrg}
1696a392d4f3Smrg
1697a392d4f3Smrg
1698e6d2e958Smrg# func_run_hooks FUNC_NAME [ARG]...
1699e6d2e958Smrg# ---------------------------------
1700e6d2e958Smrg# Run all hook functions registered to FUNC_NAME.
1701a392d4f3Smrg# It's assumed that the list of hook functions contains nothing more
1702e6d2e958Smrg# than a whitespace-delimited list of legal shell function names, and
1703e6d2e958Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704e6d2e958Smrg# whitespace.
1705e6d2e958Smrgfunc_run_hooks ()
1706e6d2e958Smrg{
1707e6d2e958Smrg    $debug_cmd
1708e6d2e958Smrg
1709e6d2e958Smrg    case " $hookable_fns " in
1710e6d2e958Smrg      *" $1 "*) ;;
1711a392d4f3Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712e6d2e958Smrg    esac
1713e6d2e958Smrg
1714e6d2e958Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715e6d2e958Smrg
1716e6d2e958Smrg    for _G_hook in $_G_hook_fns; do
1717a392d4f3Smrg      func_unset "${_G_hook}_result"
1718a392d4f3Smrg      eval $_G_hook '${1+"$@"}'
1719a392d4f3Smrg      func_propagate_result $_G_hook func_run_hooks
1720a392d4f3Smrg      if $func_propagate_result_result; then
1721a392d4f3Smrg        eval set dummy "$func_run_hooks_result"; shift
17226ad5a0e2Smrg      fi
1723e6d2e958Smrg    done
1724e6d2e958Smrg}
1725e6d2e958Smrg
1726e6d2e958Smrg
1727e6d2e958Smrg
1728e6d2e958Smrg## --------------- ##
1729e6d2e958Smrg## Option parsing. ##
1730e6d2e958Smrg## --------------- ##
1731e6d2e958Smrg
1732e6d2e958Smrg# In order to add your own option parsing hooks, you must accept the
1733a392d4f3Smrg# full positional parameter list from your hook function.  You may remove
1734a392d4f3Smrg# or edit any options that you action, and then pass back the remaining
1735a392d4f3Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736a392d4f3Smrg# suitably for 'eval'.
1737a392d4f3Smrg#
1738a392d4f3Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739a392d4f3Smrg# before your hook gets called; for best performance, only set the
1740a392d4f3Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741a392d4f3Smrg# function unnecessarily because it can be an expensive operation on some
1742a392d4f3Smrg# machines).
17436ad5a0e2Smrg#
17446ad5a0e2Smrg# Like this:
1745e6d2e958Smrg#
1746e6d2e958Smrg#    my_options_prep ()
1747e6d2e958Smrg#    {
1748e6d2e958Smrg#        $debug_cmd
1749e6d2e958Smrg#
1750e6d2e958Smrg#        # Extend the existing usage message.
1751e6d2e958Smrg#        usage_message=$usage_message'
1752e6d2e958Smrg#      -s, --silent       don'\''t print informational messages
1753e6d2e958Smrg#    '
1754a392d4f3Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755a392d4f3Smrg#        # my_options_prep_result variable intact.
1756e6d2e958Smrg#    }
1757e6d2e958Smrg#    func_add_hook func_options_prep my_options_prep
1758e6d2e958Smrg#
1759e6d2e958Smrg#
1760e6d2e958Smrg#    my_silent_option ()
1761e6d2e958Smrg#    {
1762e6d2e958Smrg#        $debug_cmd
1763e6d2e958Smrg#
17646ad5a0e2Smrg#        args_changed=false
17656ad5a0e2Smrg#
1766a392d4f3Smrg#        # Note that, for efficiency, we parse as many options as we can
1767e6d2e958Smrg#        # recognise in a loop before passing the remainder back to the
1768e6d2e958Smrg#        # caller on the first unrecognised argument we encounter.
1769e6d2e958Smrg#        while test $# -gt 0; do
1770e6d2e958Smrg#          opt=$1; shift
1771e6d2e958Smrg#          case $opt in
17726ad5a0e2Smrg#            --silent|-s) opt_silent=:
17736ad5a0e2Smrg#                         args_changed=:
17746ad5a0e2Smrg#                         ;;
1775e6d2e958Smrg#            # Separate non-argument short options:
1776e6d2e958Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777e6d2e958Smrg#                         set dummy "$func_split_short_opt_name" \
1778e6d2e958Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779e6d2e958Smrg#                         shift
17806ad5a0e2Smrg#                         args_changed=:
1781e6d2e958Smrg#                         ;;
17826ad5a0e2Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783a392d4f3Smrg#                         # is added back to "$@" in case we need it later,
1784a392d4f3Smrg#                         # if $args_changed was set to 'true'.
17856ad5a0e2Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786e6d2e958Smrg#          esac
1787e6d2e958Smrg#        done
1788e6d2e958Smrg#
1789a392d4f3Smrg#        # Only call 'func_quote' here if we processed at least one argument.
17906ad5a0e2Smrg#        if $args_changed; then
1791a392d4f3Smrg#          func_quote eval ${1+"$@"}
1792a392d4f3Smrg#          my_silent_option_result=$func_quote_result
17936ad5a0e2Smrg#        fi
1794e6d2e958Smrg#    }
1795e6d2e958Smrg#    func_add_hook func_parse_options my_silent_option
1796e6d2e958Smrg#
1797e6d2e958Smrg#
1798e6d2e958Smrg#    my_option_validation ()
1799e6d2e958Smrg#    {
1800e6d2e958Smrg#        $debug_cmd
1801e6d2e958Smrg#
1802e6d2e958Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803e6d2e958Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804e6d2e958Smrg#    }
1805e6d2e958Smrg#    func_add_hook func_validate_options my_option_validation
1806e6d2e958Smrg#
18076ad5a0e2Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808e6d2e958Smrg# options you parse.  It's preferable to append if you can, so that
1809e6d2e958Smrg# multiple option parsing hooks can be added safely.
1810e6d2e958Smrg
1811e6d2e958Smrg
18126ad5a0e2Smrg# func_options_finish [ARG]...
18136ad5a0e2Smrg# ----------------------------
18146ad5a0e2Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18156ad5a0e2Smrgfunc_options_finish ()
18166ad5a0e2Smrg{
18176ad5a0e2Smrg    $debug_cmd
18186ad5a0e2Smrg
1819a392d4f3Smrg    func_run_hooks func_options ${1+"$@"}
1820a392d4f3Smrg    func_propagate_result func_run_hooks func_options_finish
18216ad5a0e2Smrg}
18226ad5a0e2Smrg
18236ad5a0e2Smrg
1824e6d2e958Smrg# func_options [ARG]...
1825e6d2e958Smrg# ---------------------
1826e6d2e958Smrg# All the functions called inside func_options are hookable. See the
1827e6d2e958Smrg# individual implementations for details.
1828e6d2e958Smrgfunc_hookable func_options
1829e6d2e958Smrgfunc_options ()
1830e6d2e958Smrg{
1831e6d2e958Smrg    $debug_cmd
1832e6d2e958Smrg
1833a392d4f3Smrg    _G_options_quoted=false
18346ad5a0e2Smrg
18356ad5a0e2Smrg    for my_func in options_prep parse_options validate_options options_finish
18366ad5a0e2Smrg    do
1837a392d4f3Smrg      func_unset func_${my_func}_result
1838a392d4f3Smrg      func_unset func_run_hooks_result
1839a392d4f3Smrg      eval func_$my_func '${1+"$@"}'
1840a392d4f3Smrg      func_propagate_result func_$my_func func_options
1841a392d4f3Smrg      if $func_propagate_result_result; then
1842a392d4f3Smrg        eval set dummy "$func_options_result"; shift
1843a392d4f3Smrg        _G_options_quoted=:
18446ad5a0e2Smrg      fi
18456ad5a0e2Smrg    done
1846e6d2e958Smrg
1847a392d4f3Smrg    $_G_options_quoted || {
1848a392d4f3Smrg      # As we (func_options) are top-level options-parser function and
1849a392d4f3Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850a392d4f3Smrg      # caller.
1851a392d4f3Smrg      func_quote eval ${1+"$@"}
1852a392d4f3Smrg      func_options_result=$func_quote_result
1853a392d4f3Smrg    }
1854bd1da9d7Smrg}
1855bd1da9d7Smrg
1856bd1da9d7Smrg
1857e6d2e958Smrg# func_options_prep [ARG]...
1858e6d2e958Smrg# --------------------------
1859e6d2e958Smrg# All initialisations required before starting the option parse loop.
1860e6d2e958Smrg# Note that when calling hook functions, we pass through the list of
1861e6d2e958Smrg# positional parameters.  If a hook function modifies that list, and
18626ad5a0e2Smrg# needs to propagate that back to rest of this script, then the complete
1863a392d4f3Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864e6d2e958Smrgfunc_hookable func_options_prep
1865e6d2e958Smrgfunc_options_prep ()
1866bd1da9d7Smrg{
1867e6d2e958Smrg    $debug_cmd
186847e89262Smrg
1869e6d2e958Smrg    # Option defaults:
1870e6d2e958Smrg    opt_verbose=false
1871e6d2e958Smrg    opt_warning_types=
1872e6d2e958Smrg
1873a392d4f3Smrg    func_run_hooks func_options_prep ${1+"$@"}
1874a392d4f3Smrg    func_propagate_result func_run_hooks func_options_prep
1875bd1da9d7Smrg}
1876bd1da9d7Smrg
1877bd1da9d7Smrg
1878e6d2e958Smrg# func_parse_options [ARG]...
1879e6d2e958Smrg# ---------------------------
1880e6d2e958Smrg# The main option parsing loop.
1881e6d2e958Smrgfunc_hookable func_parse_options
1882e6d2e958Smrgfunc_parse_options ()
1883bd1da9d7Smrg{
1884e6d2e958Smrg    $debug_cmd
188547e89262Smrg
1886a392d4f3Smrg    _G_parse_options_requote=false
1887e6d2e958Smrg    # this just eases exit handling
1888e6d2e958Smrg    while test $# -gt 0; do
1889e6d2e958Smrg      # Defer to hook functions for initial option parsing, so they
1890e6d2e958Smrg      # get priority in the event of reusing an option name.
1891a392d4f3Smrg      func_run_hooks func_parse_options ${1+"$@"}
1892a392d4f3Smrg      func_propagate_result func_run_hooks func_parse_options
1893a392d4f3Smrg      if $func_propagate_result_result; then
1894a392d4f3Smrg        eval set dummy "$func_parse_options_result"; shift
1895a392d4f3Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896a392d4f3Smrg        # down into the hook and it quoted it for us (because we are in
1897a392d4f3Smrg        # this if-branch).  No need to quote it again.
1898a392d4f3Smrg        _G_parse_options_requote=false
18996ad5a0e2Smrg      fi
1900bd1da9d7Smrg
1901e6d2e958Smrg      # Break out of the loop if we already parsed every option.
1902e6d2e958Smrg      test $# -gt 0 || break
1903bd1da9d7Smrg
1904a392d4f3Smrg      # We expect that one of the options parsed in this function matches
1905a392d4f3Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19066ad5a0e2Smrg      _G_match_parse_options=:
1907e6d2e958Smrg      _G_opt=$1
1908e6d2e958Smrg      shift
1909e6d2e958Smrg      case $_G_opt in
1910e6d2e958Smrg        --debug|-x)   debug_cmd='set -x'
1911a392d4f3Smrg                      func_echo "enabling shell trace mode" >&2
1912e6d2e958Smrg                      $debug_cmd
1913e6d2e958Smrg                      ;;
1914e6d2e958Smrg
1915e6d2e958Smrg        --no-warnings|--no-warning|--no-warn)
1916e6d2e958Smrg                      set dummy --warnings none ${1+"$@"}
1917e6d2e958Smrg                      shift
1918e6d2e958Smrg		      ;;
191947e89262Smrg
1920e6d2e958Smrg        --warnings|--warning|-W)
19216ad5a0e2Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922a392d4f3Smrg                        _G_parse_options_requote=:
19236ad5a0e2Smrg                        break
19246ad5a0e2Smrg                      fi
1925e6d2e958Smrg                      case " $warning_categories $1" in
1926e6d2e958Smrg                        *" $1 "*)
1927e6d2e958Smrg                          # trailing space prevents matching last $1 above
1928e6d2e958Smrg                          func_append_uniq opt_warning_types " $1"
1929e6d2e958Smrg                          ;;
1930e6d2e958Smrg                        *all)
1931e6d2e958Smrg                          opt_warning_types=$warning_categories
1932e6d2e958Smrg                          ;;
1933e6d2e958Smrg                        *none)
1934e6d2e958Smrg                          opt_warning_types=none
1935e6d2e958Smrg                          warning_func=:
1936e6d2e958Smrg                          ;;
1937e6d2e958Smrg                        *error)
1938e6d2e958Smrg                          opt_warning_types=$warning_categories
1939e6d2e958Smrg                          warning_func=func_fatal_error
1940e6d2e958Smrg                          ;;
1941e6d2e958Smrg                        *)
1942e6d2e958Smrg                          func_fatal_error \
1943e6d2e958Smrg                             "unsupported warning category: '$1'"
1944e6d2e958Smrg                          ;;
1945e6d2e958Smrg                      esac
1946e6d2e958Smrg                      shift
1947e6d2e958Smrg                      ;;
1948e6d2e958Smrg
1949e6d2e958Smrg        --verbose|-v) opt_verbose=: ;;
1950e6d2e958Smrg        --version)    func_version ;;
1951e6d2e958Smrg        -\?|-h)       func_usage ;;
1952e6d2e958Smrg        --help)       func_help ;;
1953e6d2e958Smrg
1954e6d2e958Smrg	# Separate optargs to long options (plugins may need this):
1955e6d2e958Smrg	--*=*)        func_split_equals "$_G_opt"
1956e6d2e958Smrg	              set dummy "$func_split_equals_lhs" \
1957e6d2e958Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958e6d2e958Smrg                      shift
1959e6d2e958Smrg                      ;;
1960e6d2e958Smrg
1961e6d2e958Smrg       # Separate optargs to short options:
1962e6d2e958Smrg        -W*)
1963e6d2e958Smrg                      func_split_short_opt "$_G_opt"
1964e6d2e958Smrg                      set dummy "$func_split_short_opt_name" \
1965e6d2e958Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966e6d2e958Smrg                      shift
1967e6d2e958Smrg                      ;;
1968e6d2e958Smrg
1969e6d2e958Smrg        # Separate non-argument short options:
1970e6d2e958Smrg        -\?*|-h*|-v*|-x*)
1971e6d2e958Smrg                      func_split_short_opt "$_G_opt"
1972e6d2e958Smrg                      set dummy "$func_split_short_opt_name" \
1973e6d2e958Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974e6d2e958Smrg                      shift
1975e6d2e958Smrg                      ;;
1976e6d2e958Smrg
1977a392d4f3Smrg        --)           _G_parse_options_requote=: ; break ;;
1978e6d2e958Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19796ad5a0e2Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19806ad5a0e2Smrg                      _G_match_parse_options=false
19816ad5a0e2Smrg                      break
19826ad5a0e2Smrg                      ;;
1983e6d2e958Smrg      esac
19846ad5a0e2Smrg
1985a392d4f3Smrg      if $_G_match_parse_options; then
1986a392d4f3Smrg        _G_parse_options_requote=:
1987a392d4f3Smrg      fi
1988e6d2e958Smrg    done
1989e6d2e958Smrg
1990a392d4f3Smrg    if $_G_parse_options_requote; then
19916ad5a0e2Smrg      # save modified positional parameters for caller
1992a392d4f3Smrg      func_quote eval ${1+"$@"}
1993a392d4f3Smrg      func_parse_options_result=$func_quote_result
19946ad5a0e2Smrg    fi
1995bd1da9d7Smrg}
1996bd1da9d7Smrg
199747e89262Smrg
1998e6d2e958Smrg# func_validate_options [ARG]...
1999e6d2e958Smrg# ------------------------------
2000e6d2e958Smrg# Perform any sanity checks on option settings and/or unconsumed
2001e6d2e958Smrg# arguments.
2002e6d2e958Smrgfunc_hookable func_validate_options
2003e6d2e958Smrgfunc_validate_options ()
2004bd1da9d7Smrg{
2005e6d2e958Smrg    $debug_cmd
2006bd1da9d7Smrg
2007e6d2e958Smrg    # Display all warnings if -W was not given.
2008e6d2e958Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009bd1da9d7Smrg
2010a392d4f3Smrg    func_run_hooks func_validate_options ${1+"$@"}
2011a392d4f3Smrg    func_propagate_result func_run_hooks func_validate_options
2012bd1da9d7Smrg
2013e6d2e958Smrg    # Bail if the options were screwed!
2014e6d2e958Smrg    $exit_cmd $EXIT_FAILURE
2015899129b3Smrg}
2016899129b3Smrg
2017bd1da9d7Smrg
2018899129b3Smrg
2019e6d2e958Smrg## ----------------- ##
2020e6d2e958Smrg## Helper functions. ##
2021e6d2e958Smrg## ----------------- ##
2022bd1da9d7Smrg
2023e6d2e958Smrg# This section contains the helper functions used by the rest of the
2024e6d2e958Smrg# hookable option parser framework in ascii-betical order.
2025e6d2e958Smrg
2026e6d2e958Smrg
2027e6d2e958Smrg# func_fatal_help ARG...
2028e6d2e958Smrg# ----------------------
2029e6d2e958Smrg# Echo program name prefixed message to standard error, followed by
2030e6d2e958Smrg# a help hint, and exit.
2031e6d2e958Smrgfunc_fatal_help ()
203247e89262Smrg{
2033e6d2e958Smrg    $debug_cmd
2034899129b3Smrg
2035e6d2e958Smrg    eval \$ECHO \""Usage: $usage"\"
2036e6d2e958Smrg    eval \$ECHO \""$fatal_help"\"
2037e6d2e958Smrg    func_error ${1+"$@"}
2038e6d2e958Smrg    exit $EXIT_FAILURE
203947e89262Smrg}
2040bd1da9d7Smrg
2041e6d2e958Smrg
2042e6d2e958Smrg# func_help
2043e6d2e958Smrg# ---------
2044e6d2e958Smrg# Echo long help message to standard output and exit.
204547e89262Smrgfunc_help ()
204647e89262Smrg{
2047e6d2e958Smrg    $debug_cmd
2048e6d2e958Smrg
2049e6d2e958Smrg    func_usage_message
2050e6d2e958Smrg    $ECHO "$long_help_message"
2051e6d2e958Smrg    exit 0
205247e89262Smrg}
2053bd1da9d7Smrg
2054e6d2e958Smrg
2055e6d2e958Smrg# func_missing_arg ARGNAME
2056e6d2e958Smrg# ------------------------
205747e89262Smrg# Echo program name prefixed message to standard error and set global
205847e89262Smrg# exit_cmd.
205947e89262Smrgfunc_missing_arg ()
206047e89262Smrg{
2061e6d2e958Smrg    $debug_cmd
2062899129b3Smrg
2063e6d2e958Smrg    func_error "Missing argument for '$1'."
206447e89262Smrg    exit_cmd=exit
206547e89262Smrg}
2066bd1da9d7Smrg
2067bd1da9d7Smrg
2068e6d2e958Smrg# func_split_equals STRING
2069e6d2e958Smrg# ------------------------
2070a392d4f3Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071a392d4f3Smrg# after splitting STRING at the '=' sign.
2072e6d2e958Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073e6d2e958Smrg    && (eval 'x=a/b/c;
2074e6d2e958Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075e6d2e958Smrg    && _G_HAVE_XSI_OPS=yes
2076e6d2e958Smrg
2077e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078e6d2e958Smrgthen
2079e6d2e958Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080e6d2e958Smrg  eval 'func_split_equals ()
2081e6d2e958Smrg  {
2082e6d2e958Smrg      $debug_cmd
2083e6d2e958Smrg
2084e6d2e958Smrg      func_split_equals_lhs=${1%%=*}
2085e6d2e958Smrg      func_split_equals_rhs=${1#*=}
2086a392d4f3Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087a392d4f3Smrg        func_split_equals_rhs=
2088a392d4f3Smrg      fi
2089e6d2e958Smrg  }'
2090e6d2e958Smrgelse
2091e6d2e958Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092e6d2e958Smrg  func_split_equals ()
2093e6d2e958Smrg  {
2094e6d2e958Smrg      $debug_cmd
2095e6d2e958Smrg
2096e6d2e958Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097e6d2e958Smrg      func_split_equals_rhs=
2098a392d4f3Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099e6d2e958Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100e6d2e958Smrg  }
2101e6d2e958Smrgfi #func_split_equals
2102e6d2e958Smrg
2103e6d2e958Smrg
2104e6d2e958Smrg# func_split_short_opt SHORTOPT
2105e6d2e958Smrg# -----------------------------
2106899129b3Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107899129b3Smrg# variables after splitting SHORTOPT after the 2nd character.
2108e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109e6d2e958Smrgthen
2110e6d2e958Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111e6d2e958Smrg  eval 'func_split_short_opt ()
2112e6d2e958Smrg  {
2113e6d2e958Smrg      $debug_cmd
2114e6d2e958Smrg
2115e6d2e958Smrg      func_split_short_opt_arg=${1#??}
2116e6d2e958Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117e6d2e958Smrg  }'
2118e6d2e958Smrgelse
2119e6d2e958Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120e6d2e958Smrg  func_split_short_opt ()
2121e6d2e958Smrg  {
2122e6d2e958Smrg      $debug_cmd
2123e6d2e958Smrg
2124a392d4f3Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125e6d2e958Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126e6d2e958Smrg  }
2127e6d2e958Smrgfi #func_split_short_opt
2128e6d2e958Smrg
2129e6d2e958Smrg
2130e6d2e958Smrg# func_usage
2131e6d2e958Smrg# ----------
2132e6d2e958Smrg# Echo short help message to standard output and exit.
2133e6d2e958Smrgfunc_usage ()
2134899129b3Smrg{
2135e6d2e958Smrg    $debug_cmd
2136899129b3Smrg
2137e6d2e958Smrg    func_usage_message
2138e6d2e958Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139e6d2e958Smrg    exit 0
2140e6d2e958Smrg}
2141899129b3Smrg
2142899129b3Smrg
2143e6d2e958Smrg# func_usage_message
2144e6d2e958Smrg# ------------------
2145e6d2e958Smrg# Echo short help message to standard output.
2146e6d2e958Smrgfunc_usage_message ()
2147899129b3Smrg{
2148e6d2e958Smrg    $debug_cmd
2149899129b3Smrg
2150e6d2e958Smrg    eval \$ECHO \""Usage: $usage"\"
2151e6d2e958Smrg    echo
2152e6d2e958Smrg    $SED -n 's|^# ||
2153e6d2e958Smrg        /^Written by/{
2154e6d2e958Smrg          x;p;x
2155e6d2e958Smrg        }
2156e6d2e958Smrg	h
2157e6d2e958Smrg	/^Written by/q' < "$progpath"
2158e6d2e958Smrg    echo
2159e6d2e958Smrg    eval \$ECHO \""$usage_message"\"
2160e6d2e958Smrg}
2161899129b3Smrg
2162bd1da9d7Smrg
2163e6d2e958Smrg# func_version
2164e6d2e958Smrg# ------------
2165e6d2e958Smrg# Echo version message to standard output and exit.
2166a392d4f3Smrg# The version message is extracted from the calling file's header
2167a392d4f3Smrg# comments, with leading '# ' stripped:
2168a392d4f3Smrg#   1. First display the progname and version
2169a392d4f3Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170a392d4f3Smrg#   3. Then a blank line followed by the first following line matching
2171a392d4f3Smrg#      /^# Copyright /
2172a392d4f3Smrg#   4. Immediately followed by any lines between the previous matches,
2173a392d4f3Smrg#      except lines preceding the intervening completely blank line.
2174a392d4f3Smrg# For example, see the header comments of this file.
2175e6d2e958Smrgfunc_version ()
2176e6d2e958Smrg{
2177e6d2e958Smrg    $debug_cmd
2178bd1da9d7Smrg
2179e6d2e958Smrg    printf '%s\n' "$progname $scriptversion"
2180e6d2e958Smrg    $SED -n '
2181a392d4f3Smrg        /^# Written by /!b
2182a392d4f3Smrg        s|^# ||; p; n
2183a392d4f3Smrg
2184a392d4f3Smrg        :fwd2blnk
2185a392d4f3Smrg        /./ {
2186a392d4f3Smrg          n
2187a392d4f3Smrg          b fwd2blnk
2188e6d2e958Smrg        }
2189a392d4f3Smrg        p; n
2190a392d4f3Smrg
2191a392d4f3Smrg        :holdwrnt
2192a392d4f3Smrg        s|^# ||
2193a392d4f3Smrg        s|^# *$||
2194a392d4f3Smrg        /^Copyright /!{
2195a392d4f3Smrg          /./H
2196a392d4f3Smrg          n
2197a392d4f3Smrg          b holdwrnt
2198e6d2e958Smrg        }
2199a392d4f3Smrg
2200a392d4f3Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201a392d4f3Smrg        G
2202a392d4f3Smrg        s|\(\n\)\n*|\1|g
2203a392d4f3Smrg        p; q' < "$progpath"
22045bcb6992Smrg
2205e6d2e958Smrg    exit $?
2206e6d2e958Smrg}
2207bd1da9d7Smrg
220847e89262Smrg
2209e6d2e958Smrg# Local variables:
2210e6d2e958Smrg# mode: shell-script
2211e6d2e958Smrg# sh-indentation: 2
2212e6d2e958Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213a392d4f3Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214e6d2e958Smrg# time-stamp-time-zone: "UTC"
2215e6d2e958Smrg# End:
221647e89262Smrg
2217e6d2e958Smrg# Set a version string.
2218a392d4f3Smrgscriptversion='(GNU libtool) 2.4.7'
221947e89262Smrg
222047e89262Smrg
2221e6d2e958Smrg# func_echo ARG...
2222e6d2e958Smrg# ----------------
2223e6d2e958Smrg# Libtool also displays the current mode in messages, so override
2224e6d2e958Smrg# funclib.sh func_echo with this custom definition.
2225e6d2e958Smrgfunc_echo ()
2226899129b3Smrg{
2227e6d2e958Smrg    $debug_cmd
2228899129b3Smrg
2229e6d2e958Smrg    _G_message=$*
2230899129b3Smrg
2231e6d2e958Smrg    func_echo_IFS=$IFS
2232e6d2e958Smrg    IFS=$nl
2233e6d2e958Smrg    for _G_line in $_G_message; do
2234e6d2e958Smrg      IFS=$func_echo_IFS
2235e6d2e958Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236e6d2e958Smrg    done
2237e6d2e958Smrg    IFS=$func_echo_IFS
2238e6d2e958Smrg}
2239899129b3Smrg
2240e6d2e958Smrg
2241e6d2e958Smrg# func_warning ARG...
2242e6d2e958Smrg# -------------------
2243e6d2e958Smrg# Libtool warnings are not categorized, so override funclib.sh
2244e6d2e958Smrg# func_warning with this simpler definition.
2245e6d2e958Smrgfunc_warning ()
2246899129b3Smrg{
2247e6d2e958Smrg    $debug_cmd
2248899129b3Smrg
2249e6d2e958Smrg    $warning_func ${1+"$@"}
2250e6d2e958Smrg}
2251899129b3Smrg
2252899129b3Smrg
2253e6d2e958Smrg## ---------------- ##
2254e6d2e958Smrg## Options parsing. ##
2255e6d2e958Smrg## ---------------- ##
2256e6d2e958Smrg
2257e6d2e958Smrg# Hook in the functions to make sure our own options are parsed during
2258e6d2e958Smrg# the option parsing loop.
2259e6d2e958Smrg
2260e6d2e958Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261e6d2e958Smrg
2262e6d2e958Smrg# Short help message in response to '-h'.
2263e6d2e958Smrgusage_message="Options:
2264e6d2e958Smrg       --config             show all configuration variables
2265e6d2e958Smrg       --debug              enable verbose shell tracing
2266e6d2e958Smrg   -n, --dry-run            display commands without modifying any files
2267e6d2e958Smrg       --features           display basic configuration information and exit
2268e6d2e958Smrg       --mode=MODE          use operation mode MODE
2269e6d2e958Smrg       --no-warnings        equivalent to '-Wnone'
2270e6d2e958Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271e6d2e958Smrg       --quiet, --silent    don't print informational messages
2272e6d2e958Smrg       --tag=TAG            use configuration variables from tag TAG
2273e6d2e958Smrg   -v, --verbose            print more informational messages than default
2274e6d2e958Smrg       --version            print version information
2275e6d2e958Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276e6d2e958Smrg   -h, --help, --help-all   print short, long, or detailed help message
2277e6d2e958Smrg"
2278899129b3Smrg
2279e6d2e958Smrg# Additional text appended to 'usage_message' in response to '--help'.
2280e6d2e958Smrgfunc_help ()
2281899129b3Smrg{
2282e6d2e958Smrg    $debug_cmd
2283e6d2e958Smrg
2284e6d2e958Smrg    func_usage_message
2285e6d2e958Smrg    $ECHO "$long_help_message
2286e6d2e958Smrg
2287e6d2e958SmrgMODE must be one of the following:
2288e6d2e958Smrg
2289e6d2e958Smrg       clean           remove files from the build directory
2290e6d2e958Smrg       compile         compile a source file into a libtool object
2291e6d2e958Smrg       execute         automatically set library path, then run a program
2292e6d2e958Smrg       finish          complete the installation of libtool libraries
2293e6d2e958Smrg       install         install libraries or executables
2294e6d2e958Smrg       link            create a library or an executable
2295e6d2e958Smrg       uninstall       remove libraries from an installed directory
2296e6d2e958Smrg
2297e6d2e958SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298e6d2e958Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299e6d2e958SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300e6d2e958Smrg
2301e6d2e958SmrgWhen reporting a bug, please describe a test case to reproduce it and
2302e6d2e958Smrginclude the following information:
2303e6d2e958Smrg
2304e6d2e958Smrg       host-triplet:   $host
2305e6d2e958Smrg       shell:          $SHELL
2306e6d2e958Smrg       compiler:       $LTCC
2307e6d2e958Smrg       compiler flags: $LTCFLAGS
2308e6d2e958Smrg       linker:         $LD (gnu? $with_gnu_ld)
2309a392d4f3Smrg       version:        $progname (GNU libtool) 2.4.7
2310e6d2e958Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311e6d2e958Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312e6d2e958Smrg
2313e6d2e958SmrgReport bugs to <bug-libtool@gnu.org>.
2314a392d4f3SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315e6d2e958SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316e6d2e958Smrg    exit 0
2317e6d2e958Smrg}
2318899129b3Smrg
2319899129b3Smrg
2320e6d2e958Smrg# func_lo2o OBJECT-NAME
2321e6d2e958Smrg# ---------------------
2322e6d2e958Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323e6d2e958Smrg# object suffix.
2324e6d2e958Smrg
2325e6d2e958Smrglo2o=s/\\.lo\$/.$objext/
2326e6d2e958Smrgo2lo=s/\\.$objext\$/.lo/
2327e6d2e958Smrg
2328e6d2e958Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329e6d2e958Smrg  eval 'func_lo2o ()
2330e6d2e958Smrg  {
2331e6d2e958Smrg    case $1 in
2332e6d2e958Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333e6d2e958Smrg      *   ) func_lo2o_result=$1               ;;
2334e6d2e958Smrg    esac
2335e6d2e958Smrg  }'
2336e6d2e958Smrg
2337e6d2e958Smrg  # func_xform LIBOBJ-OR-SOURCE
2338e6d2e958Smrg  # ---------------------------
2339e6d2e958Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340e6d2e958Smrg  # suffix to a '.lo' libtool-object suffix.
2341e6d2e958Smrg  eval 'func_xform ()
2342e6d2e958Smrg  {
2343e6d2e958Smrg    func_xform_result=${1%.*}.lo
2344e6d2e958Smrg  }'
2345e6d2e958Smrgelse
2346e6d2e958Smrg  # ...otherwise fall back to using sed.
2347e6d2e958Smrg  func_lo2o ()
2348e6d2e958Smrg  {
2349e6d2e958Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350e6d2e958Smrg  }
2351e6d2e958Smrg
2352e6d2e958Smrg  func_xform ()
2353e6d2e958Smrg  {
2354e6d2e958Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355e6d2e958Smrg  }
2356e6d2e958Smrgfi
2357899129b3Smrg
2358899129b3Smrg
2359e6d2e958Smrg# func_fatal_configuration ARG...
2360e6d2e958Smrg# -------------------------------
236147e89262Smrg# Echo program name prefixed message to standard error, followed by
236247e89262Smrg# a configuration failure hint, and exit.
236347e89262Smrgfunc_fatal_configuration ()
236447e89262Smrg{
2365a392d4f3Smrg    func_fatal_error ${1+"$@"} \
2366e6d2e958Smrg      "See the $PACKAGE documentation for more information." \
2367e6d2e958Smrg      "Fatal configuration error."
236847e89262Smrg}
236947e89262Smrg
237047e89262Smrg
237147e89262Smrg# func_config
2372e6d2e958Smrg# -----------
237347e89262Smrg# Display the configuration for all the tags in this script.
237447e89262Smrgfunc_config ()
237547e89262Smrg{
237647e89262Smrg    re_begincf='^# ### BEGIN LIBTOOL'
237747e89262Smrg    re_endcf='^# ### END LIBTOOL'
237847e89262Smrg
237947e89262Smrg    # Default configuration.
238047e89262Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
238147e89262Smrg
2382bd1da9d7Smrg    # Now print the configurations for the tags.
2383bd1da9d7Smrg    for tagname in $taglist; do
238447e89262Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385bd1da9d7Smrg    done
2386bd1da9d7Smrg
238747e89262Smrg    exit $?
238847e89262Smrg}
2389bd1da9d7Smrg
2390e6d2e958Smrg
239147e89262Smrg# func_features
2392e6d2e958Smrg# -------------
239347e89262Smrg# Display the features supported by this script.
239447e89262Smrgfunc_features ()
239547e89262Smrg{
239647e89262Smrg    echo "host: $host"
2397e6d2e958Smrg    if test yes = "$build_libtool_libs"; then
239847e89262Smrg      echo "enable shared libraries"
2399bd1da9d7Smrg    else
240047e89262Smrg      echo "disable shared libraries"
2401bd1da9d7Smrg    fi
2402e6d2e958Smrg    if test yes = "$build_old_libs"; then
240347e89262Smrg      echo "enable static libraries"
2404bd1da9d7Smrg    else
240547e89262Smrg      echo "disable static libraries"
2406bd1da9d7Smrg    fi
240747e89262Smrg
2408bd1da9d7Smrg    exit $?
240947e89262Smrg}
2410bd1da9d7Smrg
2411e6d2e958Smrg
2412e6d2e958Smrg# func_enable_tag TAGNAME
2413e6d2e958Smrg# -----------------------
241447e89262Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
241547e89262Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
241647e89262Smrg# variable here.
241747e89262Smrgfunc_enable_tag ()
241847e89262Smrg{
2419e6d2e958Smrg    # Global variable:
2420e6d2e958Smrg    tagname=$1
2421bd1da9d7Smrg
2422e6d2e958Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423e6d2e958Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424e6d2e958Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425bd1da9d7Smrg
2426e6d2e958Smrg    # Validate tagname.
2427e6d2e958Smrg    case $tagname in
2428e6d2e958Smrg      *[!-_A-Za-z0-9,/]*)
2429e6d2e958Smrg        func_fatal_error "invalid tag name: $tagname"
2430e6d2e958Smrg        ;;
2431e6d2e958Smrg    esac
2432bd1da9d7Smrg
2433e6d2e958Smrg    # Don't test for the "default" C tag, as we know it's
2434e6d2e958Smrg    # there but not specially marked.
2435e6d2e958Smrg    case $tagname in
2436e6d2e958Smrg        CC) ;;
243747e89262Smrg    *)
2438e6d2e958Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439e6d2e958Smrg	  taglist="$taglist $tagname"
2440e6d2e958Smrg
2441e6d2e958Smrg	  # Evaluate the configuration.  Be careful to quote the path
2442e6d2e958Smrg	  # and the sed script, to avoid splitting on whitespace, but
2443e6d2e958Smrg	  # also don't use non-portable quotes within backquotes within
2444e6d2e958Smrg	  # quotes we have to do it in 2 steps:
2445e6d2e958Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446e6d2e958Smrg	  eval "$extractedcf"
2447e6d2e958Smrg        else
2448e6d2e958Smrg	  func_error "ignoring unknown tag $tagname"
2449e6d2e958Smrg        fi
2450e6d2e958Smrg        ;;
2451e6d2e958Smrg    esac
245247e89262Smrg}
245347e89262Smrg
2454e6d2e958Smrg
2455899129b3Smrg# func_check_version_match
2456e6d2e958Smrg# ------------------------
2457899129b3Smrg# Ensure that we are using m4 macros, and libtool script from the same
2458899129b3Smrg# release of libtool.
2459899129b3Smrgfunc_check_version_match ()
246047e89262Smrg{
2461e6d2e958Smrg    if test "$package_revision" != "$macro_revision"; then
2462e6d2e958Smrg      if test "$VERSION" != "$macro_version"; then
2463e6d2e958Smrg        if test -z "$macro_version"; then
2464e6d2e958Smrg          cat >&2 <<_LT_EOF
2465899129b3Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466899129b3Smrg$progname: definition of this LT_INIT comes from an older release.
2467899129b3Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468899129b3Smrg$progname: and run autoconf again.
2469899129b3Smrg_LT_EOF
2470e6d2e958Smrg        else
2471e6d2e958Smrg          cat >&2 <<_LT_EOF
2472899129b3Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473899129b3Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474899129b3Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475899129b3Smrg$progname: and run autoconf again.
2476899129b3Smrg_LT_EOF
2477e6d2e958Smrg        fi
2478e6d2e958Smrg      else
2479e6d2e958Smrg        cat >&2 <<_LT_EOF
2480899129b3Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481899129b3Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482899129b3Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483899129b3Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484899129b3Smrg_LT_EOF
2485e6d2e958Smrg      fi
2486899129b3Smrg
2487e6d2e958Smrg      exit $EXIT_MISMATCH
2488e6d2e958Smrg    fi
2489899129b3Smrg}
2490899129b3Smrg
2491899129b3Smrg
2492e6d2e958Smrg# libtool_options_prep [ARG]...
2493e6d2e958Smrg# -----------------------------
2494e6d2e958Smrg# Preparation for options parsed by libtool.
2495e6d2e958Smrglibtool_options_prep ()
2496e6d2e958Smrg{
2497e6d2e958Smrg    $debug_mode
2498899129b3Smrg
2499e6d2e958Smrg    # Option defaults:
2500e6d2e958Smrg    opt_config=false
2501e6d2e958Smrg    opt_dlopen=
2502e6d2e958Smrg    opt_dry_run=false
2503e6d2e958Smrg    opt_help=false
2504e6d2e958Smrg    opt_mode=
2505e6d2e958Smrg    opt_preserve_dup_deps=false
2506e6d2e958Smrg    opt_quiet=false
2507899129b3Smrg
2508e6d2e958Smrg    nonopt=
2509e6d2e958Smrg    preserve_args=
2510899129b3Smrg
25116ad5a0e2Smrg    _G_rc_lt_options_prep=:
25126ad5a0e2Smrg
2513e6d2e958Smrg    # Shorthand for --mode=foo, only valid as the first argument
2514e6d2e958Smrg    case $1 in
2515e6d2e958Smrg    clean|clea|cle|cl)
2516e6d2e958Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517e6d2e958Smrg      ;;
2518e6d2e958Smrg    compile|compil|compi|comp|com|co|c)
2519e6d2e958Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520e6d2e958Smrg      ;;
2521e6d2e958Smrg    execute|execut|execu|exec|exe|ex|e)
2522e6d2e958Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523e6d2e958Smrg      ;;
2524e6d2e958Smrg    finish|finis|fini|fin|fi|f)
2525e6d2e958Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526e6d2e958Smrg      ;;
2527e6d2e958Smrg    install|instal|insta|inst|ins|in|i)
2528e6d2e958Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2529e6d2e958Smrg      ;;
2530e6d2e958Smrg    link|lin|li|l)
2531e6d2e958Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2532e6d2e958Smrg      ;;
2533e6d2e958Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534e6d2e958Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535e6d2e958Smrg      ;;
25366ad5a0e2Smrg    *)
25376ad5a0e2Smrg      _G_rc_lt_options_prep=false
25386ad5a0e2Smrg      ;;
2539e6d2e958Smrg    esac
2540e6d2e958Smrg
25416ad5a0e2Smrg    if $_G_rc_lt_options_prep; then
25426ad5a0e2Smrg      # Pass back the list of options.
2543a392d4f3Smrg      func_quote eval ${1+"$@"}
2544a392d4f3Smrg      libtool_options_prep_result=$func_quote_result
25456ad5a0e2Smrg    fi
2546e6d2e958Smrg}
2547e6d2e958Smrgfunc_add_hook func_options_prep libtool_options_prep
2548bd1da9d7Smrg
2549bd1da9d7Smrg
2550e6d2e958Smrg# libtool_parse_options [ARG]...
2551e6d2e958Smrg# ---------------------------------
2552e6d2e958Smrg# Provide handling for libtool specific options.
2553e6d2e958Smrglibtool_parse_options ()
2554899129b3Smrg{
2555e6d2e958Smrg    $debug_cmd
255647e89262Smrg
25576ad5a0e2Smrg    _G_rc_lt_parse_options=false
25586ad5a0e2Smrg
2559e6d2e958Smrg    # Perform our own loop to consume as many options as possible in
2560e6d2e958Smrg    # each iteration.
2561e6d2e958Smrg    while test $# -gt 0; do
25626ad5a0e2Smrg      _G_match_lt_parse_options=:
2563e6d2e958Smrg      _G_opt=$1
2564e6d2e958Smrg      shift
2565e6d2e958Smrg      case $_G_opt in
2566e6d2e958Smrg        --dry-run|--dryrun|-n)
2567e6d2e958Smrg                        opt_dry_run=:
2568e6d2e958Smrg                        ;;
2569e6d2e958Smrg
2570e6d2e958Smrg        --config)       func_config ;;
2571e6d2e958Smrg
2572e6d2e958Smrg        --dlopen|-dlopen)
2573e6d2e958Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574e6d2e958Smrg}$1"
2575e6d2e958Smrg                        shift
2576e6d2e958Smrg                        ;;
2577e6d2e958Smrg
2578e6d2e958Smrg        --preserve-dup-deps)
2579e6d2e958Smrg                        opt_preserve_dup_deps=: ;;
2580e6d2e958Smrg
2581e6d2e958Smrg        --features)     func_features ;;
2582e6d2e958Smrg
2583e6d2e958Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584e6d2e958Smrg
2585e6d2e958Smrg        --help)         opt_help=: ;;
2586e6d2e958Smrg
2587e6d2e958Smrg        --help-all)     opt_help=': help-all' ;;
2588e6d2e958Smrg
2589e6d2e958Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590e6d2e958Smrg                        opt_mode=$1
2591e6d2e958Smrg                        case $1 in
2592e6d2e958Smrg                          # Valid mode arguments:
2593e6d2e958Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594e6d2e958Smrg
2595e6d2e958Smrg                          # Catch anything else as an error
2596e6d2e958Smrg                          *) func_error "invalid argument for $_G_opt"
2597e6d2e958Smrg                             exit_cmd=exit
2598e6d2e958Smrg                             break
2599e6d2e958Smrg                             ;;
2600e6d2e958Smrg                        esac
2601e6d2e958Smrg                        shift
2602e6d2e958Smrg                        ;;
2603e6d2e958Smrg
2604e6d2e958Smrg        --no-silent|--no-quiet)
2605e6d2e958Smrg                        opt_quiet=false
2606e6d2e958Smrg                        func_append preserve_args " $_G_opt"
2607e6d2e958Smrg                        ;;
2608e6d2e958Smrg
2609e6d2e958Smrg        --no-warnings|--no-warning|--no-warn)
2610e6d2e958Smrg                        opt_warning=false
2611e6d2e958Smrg                        func_append preserve_args " $_G_opt"
2612e6d2e958Smrg                        ;;
2613e6d2e958Smrg
2614e6d2e958Smrg        --no-verbose)
2615e6d2e958Smrg                        opt_verbose=false
2616e6d2e958Smrg                        func_append preserve_args " $_G_opt"
2617e6d2e958Smrg                        ;;
2618e6d2e958Smrg
2619e6d2e958Smrg        --silent|--quiet)
2620e6d2e958Smrg                        opt_quiet=:
2621e6d2e958Smrg                        opt_verbose=false
2622e6d2e958Smrg                        func_append preserve_args " $_G_opt"
2623e6d2e958Smrg                        ;;
2624e6d2e958Smrg
2625e6d2e958Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626e6d2e958Smrg                        opt_tag=$1
2627e6d2e958Smrg                        func_append preserve_args " $_G_opt $1"
2628e6d2e958Smrg                        func_enable_tag "$1"
2629e6d2e958Smrg                        shift
2630e6d2e958Smrg                        ;;
2631e6d2e958Smrg
2632e6d2e958Smrg        --verbose|-v)   opt_quiet=false
2633e6d2e958Smrg                        opt_verbose=:
2634e6d2e958Smrg                        func_append preserve_args " $_G_opt"
2635e6d2e958Smrg                        ;;
2636e6d2e958Smrg
26376ad5a0e2Smrg        # An option not handled by this hook function:
26386ad5a0e2Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26396ad5a0e2Smrg                        _G_match_lt_parse_options=false
26406ad5a0e2Smrg                        break
26416ad5a0e2Smrg                        ;;
2642e6d2e958Smrg      esac
26436ad5a0e2Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644e6d2e958Smrg    done
2645899129b3Smrg
26466ad5a0e2Smrg    if $_G_rc_lt_parse_options; then
26476ad5a0e2Smrg      # save modified positional parameters for caller
2648a392d4f3Smrg      func_quote eval ${1+"$@"}
2649a392d4f3Smrg      libtool_parse_options_result=$func_quote_result
26506ad5a0e2Smrg    fi
2651e6d2e958Smrg}
2652e6d2e958Smrgfunc_add_hook func_parse_options libtool_parse_options
265347e89262Smrg
2654bd1da9d7Smrg
265547e89262Smrg
2656e6d2e958Smrg# libtool_validate_options [ARG]...
2657e6d2e958Smrg# ---------------------------------
2658e6d2e958Smrg# Perform any sanity checks on option settings and/or unconsumed
2659e6d2e958Smrg# arguments.
2660e6d2e958Smrglibtool_validate_options ()
2661e6d2e958Smrg{
2662e6d2e958Smrg    # save first non-option argument
2663e6d2e958Smrg    if test 0 -lt $#; then
2664e6d2e958Smrg      nonopt=$1
2665e6d2e958Smrg      shift
266647e89262Smrg    fi
266747e89262Smrg
2668e6d2e958Smrg    # preserve --debug
2669e6d2e958Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
267047e89262Smrg
2671e6d2e958Smrg    case $host in
2672e6d2e958Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673e6d2e958Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674e6d2e958Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675e6d2e958Smrg        # don't eliminate duplications in $postdeps and $predeps
2676e6d2e958Smrg        opt_duplicate_compiler_generated_deps=:
2677e6d2e958Smrg        ;;
2678e6d2e958Smrg      *)
2679e6d2e958Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680e6d2e958Smrg        ;;
2681e6d2e958Smrg    esac
268247e89262Smrg
2683e6d2e958Smrg    $opt_help || {
2684e6d2e958Smrg      # Sanity checks first:
2685e6d2e958Smrg      func_check_version_match
2686e6d2e958Smrg
2687e6d2e958Smrg      test yes != "$build_libtool_libs" \
2688e6d2e958Smrg        && test yes != "$build_old_libs" \
2689e6d2e958Smrg        && func_fatal_configuration "not configured to build any kind of library"
2690e6d2e958Smrg
2691e6d2e958Smrg      # Darwin sucks
2692e6d2e958Smrg      eval std_shrext=\"$shrext_cmds\"
2693e6d2e958Smrg
2694e6d2e958Smrg      # Only execute mode is allowed to have -dlopen flags.
2695e6d2e958Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696e6d2e958Smrg        func_error "unrecognized option '-dlopen'"
2697e6d2e958Smrg        $ECHO "$help" 1>&2
2698e6d2e958Smrg        exit $EXIT_FAILURE
2699e6d2e958Smrg      fi
270047e89262Smrg
2701e6d2e958Smrg      # Change the help message to a mode-specific one.
2702e6d2e958Smrg      generic_help=$help
2703e6d2e958Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704e6d2e958Smrg    }
270547e89262Smrg
2706e6d2e958Smrg    # Pass back the unparsed argument list
2707a392d4f3Smrg    func_quote eval ${1+"$@"}
2708a392d4f3Smrg    libtool_validate_options_result=$func_quote_result
2709899129b3Smrg}
2710e6d2e958Smrgfunc_add_hook func_validate_options libtool_validate_options
271147e89262Smrg
271247e89262Smrg
2713e6d2e958Smrg# Process options as early as possible so that --help and --version
2714e6d2e958Smrg# can return quickly.
2715e6d2e958Smrgfunc_options ${1+"$@"}
2716e6d2e958Smrgeval set dummy "$func_options_result"; shift
2717e6d2e958Smrg
2718bd1da9d7Smrg
2719bd1da9d7Smrg
2720899129b3Smrg## ----------- ##
2721899129b3Smrg##    Main.    ##
2722899129b3Smrg## ----------- ##
2723bd1da9d7Smrg
2724e6d2e958Smrgmagic='%%%MAGIC variable%%%'
2725e6d2e958Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2726e6d2e958Smrg
2727e6d2e958Smrg# Global variables.
2728e6d2e958Smrgextracted_archives=
2729e6d2e958Smrgextracted_serial=0
2730e6d2e958Smrg
2731e6d2e958Smrg# If this variable is set in any of the actions, the command in it
2732e6d2e958Smrg# will be execed at the end.  This prevents here-documents from being
2733e6d2e958Smrg# left over by shells.
2734e6d2e958Smrgexec_cmd=
2735e6d2e958Smrg
2736e6d2e958Smrg
2737e6d2e958Smrg# A function that is used when there is no print builtin or printf.
2738e6d2e958Smrgfunc_fallback_echo ()
2739e6d2e958Smrg{
2740e6d2e958Smrg  eval 'cat <<_LTECHO_EOF
2741e6d2e958Smrg$1
2742e6d2e958Smrg_LTECHO_EOF'
2743e6d2e958Smrg}
2744e6d2e958Smrg
2745e6d2e958Smrg# func_generated_by_libtool
2746e6d2e958Smrg# True iff stdin has been generated by Libtool. This function is only
2747e6d2e958Smrg# a basic sanity check; it will hardly flush out determined imposters.
2748e6d2e958Smrgfunc_generated_by_libtool_p ()
2749e6d2e958Smrg{
2750e6d2e958Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751e6d2e958Smrg}
2752e6d2e958Smrg
275347e89262Smrg# func_lalib_p file
2754e6d2e958Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
275547e89262Smrg# This function is only a basic sanity check; it will hardly flush out
275647e89262Smrg# determined imposters.
275747e89262Smrgfunc_lalib_p ()
275847e89262Smrg{
275947e89262Smrg    test -f "$1" &&
2760e6d2e958Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
276147e89262Smrg}
2762bd1da9d7Smrg
276347e89262Smrg# func_lalib_unsafe_p file
2764e6d2e958Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
276547e89262Smrg# This function implements the same check as func_lalib_p without
276647e89262Smrg# resorting to external programs.  To this end, it redirects stdin and
276747e89262Smrg# closes it afterwards, without saving the original file descriptor.
276847e89262Smrg# As a safety measure, use it only where a negative result would be
2769e6d2e958Smrg# fatal anyway.  Works if 'file' does not exist.
277047e89262Smrgfunc_lalib_unsafe_p ()
277147e89262Smrg{
277247e89262Smrg    lalib_p=no
277347e89262Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
277447e89262Smrg	for lalib_p_l in 1 2 3 4
277547e89262Smrg	do
277647e89262Smrg	    read lalib_p_line
2777e6d2e958Smrg	    case $lalib_p_line in
277847e89262Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
277947e89262Smrg	    esac
278047e89262Smrg	done
278147e89262Smrg	exec 0<&5 5<&-
278247e89262Smrg    fi
2783e6d2e958Smrg    test yes = "$lalib_p"
278447e89262Smrg}
2785bd1da9d7Smrg
278647e89262Smrg# func_ltwrapper_script_p file
278747e89262Smrg# True iff FILE is a libtool wrapper script
278847e89262Smrg# This function is only a basic sanity check; it will hardly flush out
278947e89262Smrg# determined imposters.
279047e89262Smrgfunc_ltwrapper_script_p ()
279147e89262Smrg{
2792e6d2e958Smrg    test -f "$1" &&
2793e6d2e958Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
279447e89262Smrg}
2795bd1da9d7Smrg
279647e89262Smrg# func_ltwrapper_executable_p file
279747e89262Smrg# True iff FILE is a libtool wrapper executable
279847e89262Smrg# This function is only a basic sanity check; it will hardly flush out
279947e89262Smrg# determined imposters.
280047e89262Smrgfunc_ltwrapper_executable_p ()
280147e89262Smrg{
280247e89262Smrg    func_ltwrapper_exec_suffix=
280347e89262Smrg    case $1 in
280447e89262Smrg    *.exe) ;;
280547e89262Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
280647e89262Smrg    esac
280747e89262Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
280847e89262Smrg}
280947e89262Smrg
281047e89262Smrg# func_ltwrapper_scriptname file
281147e89262Smrg# Assumes file is an ltwrapper_executable
281247e89262Smrg# uses $file to determine the appropriate filename for a
281347e89262Smrg# temporary ltwrapper_script.
281447e89262Smrgfunc_ltwrapper_scriptname ()
281547e89262Smrg{
2816899129b3Smrg    func_dirname_and_basename "$1" "" "."
2817899129b3Smrg    func_stripname '' '.exe' "$func_basename_result"
2818e6d2e958Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
281947e89262Smrg}
282047e89262Smrg
282147e89262Smrg# func_ltwrapper_p file
282247e89262Smrg# True iff FILE is a libtool wrapper script or wrapper executable
282347e89262Smrg# This function is only a basic sanity check; it will hardly flush out
282447e89262Smrg# determined imposters.
282547e89262Smrgfunc_ltwrapper_p ()
282647e89262Smrg{
282747e89262Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
282847e89262Smrg}
282947e89262Smrg
283047e89262Smrg
283147e89262Smrg# func_execute_cmds commands fail_cmd
283247e89262Smrg# Execute tilde-delimited COMMANDS.
283347e89262Smrg# If FAIL_CMD is given, eval that upon failure.
283447e89262Smrg# FAIL_CMD may read-access the current command in variable CMD!
283547e89262Smrgfunc_execute_cmds ()
283647e89262Smrg{
2837e6d2e958Smrg    $debug_cmd
2838e6d2e958Smrg
283947e89262Smrg    save_ifs=$IFS; IFS='~'
284047e89262Smrg    for cmd in $1; do
2841e6d2e958Smrg      IFS=$sp$nl
284247e89262Smrg      eval cmd=\"$cmd\"
2843e6d2e958Smrg      IFS=$save_ifs
284447e89262Smrg      func_show_eval "$cmd" "${2-:}"
284547e89262Smrg    done
284647e89262Smrg    IFS=$save_ifs
284747e89262Smrg}
284847e89262Smrg
284947e89262Smrg
285047e89262Smrg# func_source file
285147e89262Smrg# Source FILE, adding directory component if necessary.
285247e89262Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
285347e89262Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
285447e89262Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855e6d2e958Smrg# 'FILE.' does not work on cygwin managed mounts.
285647e89262Smrgfunc_source ()
285747e89262Smrg{
2858e6d2e958Smrg    $debug_cmd
2859e6d2e958Smrg
286047e89262Smrg    case $1 in
286147e89262Smrg    */* | *\\*)	. "$1" ;;
286247e89262Smrg    *)		. "./$1" ;;
286347e89262Smrg    esac
286447e89262Smrg}
286547e89262Smrg
286647e89262Smrg
2867899129b3Smrg# func_resolve_sysroot PATH
2868899129b3Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869899129b3Smrg# func_resolve_sysroot_result
2870899129b3Smrgfunc_resolve_sysroot ()
2871899129b3Smrg{
2872899129b3Smrg  func_resolve_sysroot_result=$1
2873899129b3Smrg  case $func_resolve_sysroot_result in
2874899129b3Smrg  =*)
2875899129b3Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876899129b3Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877899129b3Smrg    ;;
2878899129b3Smrg  esac
2879899129b3Smrg}
2880899129b3Smrg
2881899129b3Smrg# func_replace_sysroot PATH
2882899129b3Smrg# If PATH begins with the sysroot, replace it with = and
2883899129b3Smrg# store the result into func_replace_sysroot_result.
2884899129b3Smrgfunc_replace_sysroot ()
2885899129b3Smrg{
2886e6d2e958Smrg  case $lt_sysroot:$1 in
2887899129b3Smrg  ?*:"$lt_sysroot"*)
2888899129b3Smrg    func_stripname "$lt_sysroot" '' "$1"
2889e6d2e958Smrg    func_replace_sysroot_result='='$func_stripname_result
2890899129b3Smrg    ;;
2891899129b3Smrg  *)
2892899129b3Smrg    # Including no sysroot.
2893899129b3Smrg    func_replace_sysroot_result=$1
2894899129b3Smrg    ;;
2895899129b3Smrg  esac
2896899129b3Smrg}
2897899129b3Smrg
289847e89262Smrg# func_infer_tag arg
289947e89262Smrg# Infer tagged configuration to use if any are available and
290047e89262Smrg# if one wasn't chosen via the "--tag" command line option.
290147e89262Smrg# Only attempt this if the compiler in the base compile
290247e89262Smrg# command doesn't match the default compiler.
290347e89262Smrg# arg is usually of the form 'gcc ...'
290447e89262Smrgfunc_infer_tag ()
290547e89262Smrg{
2906e6d2e958Smrg    $debug_cmd
2907e6d2e958Smrg
290847e89262Smrg    if test -n "$available_tags" && test -z "$tagname"; then
290947e89262Smrg      CC_quoted=
291047e89262Smrg      for arg in $CC; do
2911899129b3Smrg	func_append_quoted CC_quoted "$arg"
291247e89262Smrg      done
291347e89262Smrg      CC_expanded=`func_echo_all $CC`
291447e89262Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
291547e89262Smrg      case $@ in
291647e89262Smrg      # Blanks in the command may have been stripped by the calling shell,
291747e89262Smrg      # but not from the CC environment variable when configure was run.
291847e89262Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291947e89262Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
292047e89262Smrg      # Blanks at the start of $base_compile will cause this to fail
292147e89262Smrg      # if we don't check for them as well.
292247e89262Smrg      *)
292347e89262Smrg	for z in $available_tags; do
292447e89262Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
292547e89262Smrg	    # Evaluate the configuration.
2926e6d2e958Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
292747e89262Smrg	    CC_quoted=
292847e89262Smrg	    for arg in $CC; do
292947e89262Smrg	      # Double-quote args containing other shell metacharacters.
2930899129b3Smrg	      func_append_quoted CC_quoted "$arg"
293147e89262Smrg	    done
293247e89262Smrg	    CC_expanded=`func_echo_all $CC`
293347e89262Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
293447e89262Smrg	    case "$@ " in
293547e89262Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
293647e89262Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
293747e89262Smrg	      # The compiler in the base compile command matches
293847e89262Smrg	      # the one in the tagged configuration.
293947e89262Smrg	      # Assume this is the tagged configuration we want.
294047e89262Smrg	      tagname=$z
294147e89262Smrg	      break
294247e89262Smrg	      ;;
294347e89262Smrg	    esac
294447e89262Smrg	  fi
294547e89262Smrg	done
294647e89262Smrg	# If $tagname still isn't set, then no tagged configuration
294747e89262Smrg	# was found and let the user know that the "--tag" command
294847e89262Smrg	# line option must be used.
294947e89262Smrg	if test -z "$tagname"; then
295047e89262Smrg	  func_echo "unable to infer tagged configuration"
2951e6d2e958Smrg	  func_fatal_error "specify a tag with '--tag'"
295247e89262Smrg#	else
295347e89262Smrg#	  func_verbose "using $tagname tagged configuration"
295447e89262Smrg	fi
295547e89262Smrg	;;
295647e89262Smrg      esac
295747e89262Smrg    fi
295847e89262Smrg}
295947e89262Smrg
296047e89262Smrg
2961899129b3Smrg
2962899129b3Smrg# func_write_libtool_object output_name pic_name nonpic_name
2963899129b3Smrg# Create a libtool object file (analogous to a ".la" file),
2964899129b3Smrg# but don't create it if we're doing a dry run.
2965899129b3Smrgfunc_write_libtool_object ()
2966899129b3Smrg{
2967e6d2e958Smrg    write_libobj=$1
2968e6d2e958Smrg    if test yes = "$build_libtool_libs"; then
2969e6d2e958Smrg      write_lobj=\'$2\'
2970899129b3Smrg    else
2971899129b3Smrg      write_lobj=none
2972899129b3Smrg    fi
2973899129b3Smrg
2974e6d2e958Smrg    if test yes = "$build_old_libs"; then
2975e6d2e958Smrg      write_oldobj=\'$3\'
2976899129b3Smrg    else
2977899129b3Smrg      write_oldobj=none
2978899129b3Smrg    fi
2979899129b3Smrg
2980899129b3Smrg    $opt_dry_run || {
2981899129b3Smrg      cat >${write_libobj}T <<EOF
2982899129b3Smrg# $write_libobj - a libtool object file
2983e6d2e958Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984899129b3Smrg#
2985899129b3Smrg# Please DO NOT delete this file!
2986899129b3Smrg# It is necessary for linking the library.
2987899129b3Smrg
2988899129b3Smrg# Name of the PIC object.
2989899129b3Smrgpic_object=$write_lobj
2990899129b3Smrg
2991899129b3Smrg# Name of the non-PIC object
2992899129b3Smrgnon_pic_object=$write_oldobj
2993899129b3Smrg
2994899129b3SmrgEOF
2995e6d2e958Smrg      $MV "${write_libobj}T" "$write_libobj"
2996899129b3Smrg    }
2997899129b3Smrg}
2998899129b3Smrg
2999899129b3Smrg
3000899129b3Smrg##################################################
3001899129b3Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002899129b3Smrg##################################################
3003899129b3Smrg
3004899129b3Smrg# func_convert_core_file_wine_to_w32 ARG
3005899129b3Smrg# Helper function used by file name conversion functions when $build is *nix,
3006899129b3Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007899129b3Smrg# correctly configured wine environment available, with the winepath program
3008899129b3Smrg# in $build's $PATH.
3009899129b3Smrg#
3010899129b3Smrg# ARG is the $build file name to be converted to w32 format.
3011899129b3Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012899129b3Smrg# be empty on error (or when ARG is empty)
3013899129b3Smrgfunc_convert_core_file_wine_to_w32 ()
3014899129b3Smrg{
3015e6d2e958Smrg  $debug_cmd
3016e6d2e958Smrg
3017e6d2e958Smrg  func_convert_core_file_wine_to_w32_result=$1
3018899129b3Smrg  if test -n "$1"; then
3019899129b3Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020899129b3Smrg    # are forced to check the contents of stdout. On the other hand, if the
3021899129b3Smrg    # command is not found, the shell will set an exit code of 127 and print
3022899129b3Smrg    # *an error message* to stdout. So we must check for both error code of
3023899129b3Smrg    # zero AND non-empty stdout, which explains the odd construction:
3024899129b3Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025e6d2e958Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026899129b3Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027e6d2e958Smrg        $SED -e "$sed_naive_backslashify"`
3028899129b3Smrg    else
3029899129b3Smrg      func_convert_core_file_wine_to_w32_result=
3030899129b3Smrg    fi
3031899129b3Smrg  fi
3032899129b3Smrg}
3033899129b3Smrg# end: func_convert_core_file_wine_to_w32
3034899129b3Smrg
3035899129b3Smrg
3036899129b3Smrg# func_convert_core_path_wine_to_w32 ARG
3037899129b3Smrg# Helper function used by path conversion functions when $build is *nix, and
3038899129b3Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039899129b3Smrg# configured wine environment available, with the winepath program in $build's
3040899129b3Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041899129b3Smrg#
3042899129b3Smrg# ARG is path to be converted from $build format to win32.
3043899129b3Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044899129b3Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045899129b3Smrg# are convertible, then the result may be empty.
3046899129b3Smrgfunc_convert_core_path_wine_to_w32 ()
3047899129b3Smrg{
3048e6d2e958Smrg  $debug_cmd
3049e6d2e958Smrg
3050899129b3Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051e6d2e958Smrg  func_convert_core_path_wine_to_w32_result=
3052899129b3Smrg  if test -n "$1"; then
3053899129b3Smrg    oldIFS=$IFS
3054899129b3Smrg    IFS=:
3055899129b3Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056899129b3Smrg      IFS=$oldIFS
3057899129b3Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058e6d2e958Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059899129b3Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060e6d2e958Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061899129b3Smrg        else
3062899129b3Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063899129b3Smrg        fi
3064899129b3Smrg      fi
3065899129b3Smrg    done
3066899129b3Smrg    IFS=$oldIFS
3067899129b3Smrg  fi
3068899129b3Smrg}
3069899129b3Smrg# end: func_convert_core_path_wine_to_w32
3070899129b3Smrg
3071899129b3Smrg
3072899129b3Smrg# func_cygpath ARGS...
3073899129b3Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074899129b3Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075899129b3Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076899129b3Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077899129b3Smrg# file name or path is assumed to be in w32 format, as previously converted
3078899129b3Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079899129b3Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080899129b3Smrg# Cygwin format). Returns an empty string on error.
3081899129b3Smrg#
3082899129b3Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083899129b3Smrg# be converted.
3084899129b3Smrg#
3085899129b3Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086899129b3Smrg# environment variable; do not put it in $PATH.
3087899129b3Smrgfunc_cygpath ()
3088899129b3Smrg{
3089e6d2e958Smrg  $debug_cmd
3090e6d2e958Smrg
3091899129b3Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092899129b3Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093899129b3Smrg    if test "$?" -ne 0; then
3094899129b3Smrg      # on failure, ensure result is empty
3095899129b3Smrg      func_cygpath_result=
3096899129b3Smrg    fi
3097899129b3Smrg  else
3098899129b3Smrg    func_cygpath_result=
3099e6d2e958Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100899129b3Smrg  fi
3101899129b3Smrg}
3102899129b3Smrg#end: func_cygpath
3103899129b3Smrg
3104899129b3Smrg
3105899129b3Smrg# func_convert_core_msys_to_w32 ARG
3106899129b3Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107899129b3Smrg# result in func_convert_core_msys_to_w32_result.
3108899129b3Smrgfunc_convert_core_msys_to_w32 ()
3109899129b3Smrg{
3110e6d2e958Smrg  $debug_cmd
3111e6d2e958Smrg
3112899129b3Smrg  # awkward: cmd appends spaces to result
3113899129b3Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114e6d2e958Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115899129b3Smrg}
3116899129b3Smrg#end: func_convert_core_msys_to_w32
3117899129b3Smrg
3118899129b3Smrg
3119899129b3Smrg# func_convert_file_check ARG1 ARG2
3120899129b3Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121899129b3Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122899129b3Smrg# func_to_host_file_result to ARG1).
3123899129b3Smrgfunc_convert_file_check ()
3124899129b3Smrg{
3125e6d2e958Smrg  $debug_cmd
3126e6d2e958Smrg
3127e6d2e958Smrg  if test -z "$2" && test -n "$1"; then
3128899129b3Smrg    func_error "Could not determine host file name corresponding to"
3129e6d2e958Smrg    func_error "  '$1'"
3130899129b3Smrg    func_error "Continuing, but uninstalled executables may not work."
3131899129b3Smrg    # Fallback:
3132e6d2e958Smrg    func_to_host_file_result=$1
3133899129b3Smrg  fi
3134899129b3Smrg}
3135899129b3Smrg# end func_convert_file_check
3136899129b3Smrg
3137899129b3Smrg
3138899129b3Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139899129b3Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140899129b3Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141899129b3Smrg# func_to_host_file_result to a simplistic fallback value (see below).
3142899129b3Smrgfunc_convert_path_check ()
3143899129b3Smrg{
3144e6d2e958Smrg  $debug_cmd
3145e6d2e958Smrg
3146899129b3Smrg  if test -z "$4" && test -n "$3"; then
3147899129b3Smrg    func_error "Could not determine the host path corresponding to"
3148e6d2e958Smrg    func_error "  '$3'"
3149899129b3Smrg    func_error "Continuing, but uninstalled executables may not work."
3150899129b3Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151899129b3Smrg    # should not be "improved".  See libtool.info.
3152899129b3Smrg    if test "x$1" != "x$2"; then
3153899129b3Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154899129b3Smrg      func_to_host_path_result=`echo "$3" |
3155899129b3Smrg        $SED -e "$lt_replace_pathsep_chars"`
3156899129b3Smrg    else
3157e6d2e958Smrg      func_to_host_path_result=$3
3158899129b3Smrg    fi
3159899129b3Smrg  fi
3160899129b3Smrg}
3161899129b3Smrg# end func_convert_path_check
3162899129b3Smrg
3163899129b3Smrg
3164899129b3Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165899129b3Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166899129b3Smrg# and appending REPL if ORIG matches BACKPAT.
3167899129b3Smrgfunc_convert_path_front_back_pathsep ()
3168899129b3Smrg{
3169e6d2e958Smrg  $debug_cmd
3170e6d2e958Smrg
3171899129b3Smrg  case $4 in
3172e6d2e958Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173899129b3Smrg    ;;
3174899129b3Smrg  esac
3175899129b3Smrg  case $4 in
3176899129b3Smrg  $2 ) func_append func_to_host_path_result "$3"
3177899129b3Smrg    ;;
3178899129b3Smrg  esac
3179899129b3Smrg}
3180899129b3Smrg# end func_convert_path_front_back_pathsep
3181899129b3Smrg
3182899129b3Smrg
3183899129b3Smrg##################################################
3184899129b3Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185899129b3Smrg##################################################
3186e6d2e958Smrg# invoked via '$to_host_file_cmd ARG'
3187899129b3Smrg#
3188899129b3Smrg# In each case, ARG is the path to be converted from $build to $host format.
3189899129b3Smrg# Result will be available in $func_to_host_file_result.
3190899129b3Smrg
3191899129b3Smrg
3192899129b3Smrg# func_to_host_file ARG
3193899129b3Smrg# Converts the file name ARG from $build format to $host format. Return result
3194899129b3Smrg# in func_to_host_file_result.
3195899129b3Smrgfunc_to_host_file ()
3196899129b3Smrg{
3197e6d2e958Smrg  $debug_cmd
3198e6d2e958Smrg
3199899129b3Smrg  $to_host_file_cmd "$1"
3200899129b3Smrg}
3201899129b3Smrg# end func_to_host_file
3202899129b3Smrg
3203899129b3Smrg
3204899129b3Smrg# func_to_tool_file ARG LAZY
3205899129b3Smrg# converts the file name ARG from $build format to toolchain format. Return
3206899129b3Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207899129b3Smrg# in (the comma separated) LAZY, no conversion takes place.
3208899129b3Smrgfunc_to_tool_file ()
3209899129b3Smrg{
3210e6d2e958Smrg  $debug_cmd
3211e6d2e958Smrg
3212899129b3Smrg  case ,$2, in
3213899129b3Smrg    *,"$to_tool_file_cmd",*)
3214899129b3Smrg      func_to_tool_file_result=$1
3215899129b3Smrg      ;;
3216899129b3Smrg    *)
3217899129b3Smrg      $to_tool_file_cmd "$1"
3218899129b3Smrg      func_to_tool_file_result=$func_to_host_file_result
3219899129b3Smrg      ;;
3220899129b3Smrg  esac
3221899129b3Smrg}
3222899129b3Smrg# end func_to_tool_file
3223899129b3Smrg
3224899129b3Smrg
3225899129b3Smrg# func_convert_file_noop ARG
3226899129b3Smrg# Copy ARG to func_to_host_file_result.
3227899129b3Smrgfunc_convert_file_noop ()
3228899129b3Smrg{
3229e6d2e958Smrg  func_to_host_file_result=$1
3230899129b3Smrg}
3231899129b3Smrg# end func_convert_file_noop
3232899129b3Smrg
3233899129b3Smrg
3234899129b3Smrg# func_convert_file_msys_to_w32 ARG
3235899129b3Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236899129b3Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237899129b3Smrg# func_to_host_file_result.
3238899129b3Smrgfunc_convert_file_msys_to_w32 ()
3239899129b3Smrg{
3240e6d2e958Smrg  $debug_cmd
3241e6d2e958Smrg
3242e6d2e958Smrg  func_to_host_file_result=$1
3243899129b3Smrg  if test -n "$1"; then
3244899129b3Smrg    func_convert_core_msys_to_w32 "$1"
3245e6d2e958Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246899129b3Smrg  fi
3247899129b3Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248899129b3Smrg}
3249899129b3Smrg# end func_convert_file_msys_to_w32
3250899129b3Smrg
3251899129b3Smrg
3252899129b3Smrg# func_convert_file_cygwin_to_w32 ARG
3253899129b3Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254899129b3Smrg# func_to_host_file_result.
3255899129b3Smrgfunc_convert_file_cygwin_to_w32 ()
3256899129b3Smrg{
3257e6d2e958Smrg  $debug_cmd
3258e6d2e958Smrg
3259e6d2e958Smrg  func_to_host_file_result=$1
3260899129b3Smrg  if test -n "$1"; then
3261899129b3Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262899129b3Smrg    # LT_CYGPATH in this case.
3263899129b3Smrg    func_to_host_file_result=`cygpath -m "$1"`
3264899129b3Smrg  fi
3265899129b3Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266899129b3Smrg}
3267899129b3Smrg# end func_convert_file_cygwin_to_w32
3268899129b3Smrg
3269899129b3Smrg
3270899129b3Smrg# func_convert_file_nix_to_w32 ARG
3271899129b3Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272899129b3Smrg# and a working winepath. Returns result in func_to_host_file_result.
3273899129b3Smrgfunc_convert_file_nix_to_w32 ()
3274899129b3Smrg{
3275e6d2e958Smrg  $debug_cmd
3276e6d2e958Smrg
3277e6d2e958Smrg  func_to_host_file_result=$1
3278899129b3Smrg  if test -n "$1"; then
3279899129b3Smrg    func_convert_core_file_wine_to_w32 "$1"
3280e6d2e958Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281899129b3Smrg  fi
3282899129b3Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283899129b3Smrg}
3284899129b3Smrg# end func_convert_file_nix_to_w32
3285899129b3Smrg
3286899129b3Smrg
3287899129b3Smrg# func_convert_file_msys_to_cygwin ARG
3288899129b3Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289899129b3Smrg# Returns result in func_to_host_file_result.
3290899129b3Smrgfunc_convert_file_msys_to_cygwin ()
3291899129b3Smrg{
3292e6d2e958Smrg  $debug_cmd
3293e6d2e958Smrg
3294e6d2e958Smrg  func_to_host_file_result=$1
3295899129b3Smrg  if test -n "$1"; then
3296899129b3Smrg    func_convert_core_msys_to_w32 "$1"
3297899129b3Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298e6d2e958Smrg    func_to_host_file_result=$func_cygpath_result
3299899129b3Smrg  fi
3300899129b3Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301899129b3Smrg}
3302899129b3Smrg# end func_convert_file_msys_to_cygwin
3303899129b3Smrg
3304899129b3Smrg
3305899129b3Smrg# func_convert_file_nix_to_cygwin ARG
3306899129b3Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307899129b3Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308899129b3Smrg# in func_to_host_file_result.
3309899129b3Smrgfunc_convert_file_nix_to_cygwin ()
3310899129b3Smrg{
3311e6d2e958Smrg  $debug_cmd
3312e6d2e958Smrg
3313e6d2e958Smrg  func_to_host_file_result=$1
3314899129b3Smrg  if test -n "$1"; then
3315899129b3Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316899129b3Smrg    func_convert_core_file_wine_to_w32 "$1"
3317899129b3Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318e6d2e958Smrg    func_to_host_file_result=$func_cygpath_result
3319899129b3Smrg  fi
3320899129b3Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321899129b3Smrg}
3322899129b3Smrg# end func_convert_file_nix_to_cygwin
3323899129b3Smrg
3324899129b3Smrg
3325899129b3Smrg#############################################
3326899129b3Smrg# $build to $host PATH CONVERSION FUNCTIONS #
3327899129b3Smrg#############################################
3328e6d2e958Smrg# invoked via '$to_host_path_cmd ARG'
3329899129b3Smrg#
3330899129b3Smrg# In each case, ARG is the path to be converted from $build to $host format.
3331899129b3Smrg# The result will be available in $func_to_host_path_result.
3332899129b3Smrg#
3333899129b3Smrg# Path separators are also converted from $build format to $host format.  If
3334899129b3Smrg# ARG begins or ends with a path separator character, it is preserved (but
3335899129b3Smrg# converted to $host format) on output.
3336899129b3Smrg#
3337899129b3Smrg# All path conversion functions are named using the following convention:
3338899129b3Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339899129b3Smrg#   path conversion function         : func_convert_path_X_to_Y ()
3340899129b3Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341899129b3Smrg# same.  If conversion functions are added for new $build/$host combinations,
3342899129b3Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343899129b3Smrg# will break.
3344899129b3Smrg
3345899129b3Smrg
3346899129b3Smrg# func_init_to_host_path_cmd
3347899129b3Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348899129b3Smrg# appropriate value, based on the value of $to_host_file_cmd.
3349899129b3Smrgto_host_path_cmd=
3350899129b3Smrgfunc_init_to_host_path_cmd ()
3351899129b3Smrg{
3352e6d2e958Smrg  $debug_cmd
3353e6d2e958Smrg
3354899129b3Smrg  if test -z "$to_host_path_cmd"; then
3355899129b3Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356e6d2e958Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357899129b3Smrg  fi
3358899129b3Smrg}
3359899129b3Smrg
3360899129b3Smrg
3361899129b3Smrg# func_to_host_path ARG
3362899129b3Smrg# Converts the path ARG from $build format to $host format. Return result
3363899129b3Smrg# in func_to_host_path_result.
3364899129b3Smrgfunc_to_host_path ()
3365899129b3Smrg{
3366e6d2e958Smrg  $debug_cmd
3367e6d2e958Smrg
3368899129b3Smrg  func_init_to_host_path_cmd
3369899129b3Smrg  $to_host_path_cmd "$1"
3370899129b3Smrg}
3371899129b3Smrg# end func_to_host_path
3372899129b3Smrg
3373899129b3Smrg
3374899129b3Smrg# func_convert_path_noop ARG
3375899129b3Smrg# Copy ARG to func_to_host_path_result.
3376899129b3Smrgfunc_convert_path_noop ()
3377899129b3Smrg{
3378e6d2e958Smrg  func_to_host_path_result=$1
3379899129b3Smrg}
3380899129b3Smrg# end func_convert_path_noop
3381899129b3Smrg
3382899129b3Smrg
3383899129b3Smrg# func_convert_path_msys_to_w32 ARG
3384899129b3Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385899129b3Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386899129b3Smrg# func_to_host_path_result.
3387899129b3Smrgfunc_convert_path_msys_to_w32 ()
3388899129b3Smrg{
3389e6d2e958Smrg  $debug_cmd
3390e6d2e958Smrg
3391e6d2e958Smrg  func_to_host_path_result=$1
3392899129b3Smrg  if test -n "$1"; then
3393899129b3Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394899129b3Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395899129b3Smrg    # and winepath ignores them completely.
3396899129b3Smrg    func_stripname : : "$1"
3397899129b3Smrg    func_to_host_path_tmp1=$func_stripname_result
3398899129b3Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399e6d2e958Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400899129b3Smrg    func_convert_path_check : ";" \
3401899129b3Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402899129b3Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403899129b3Smrg  fi
3404899129b3Smrg}
3405899129b3Smrg# end func_convert_path_msys_to_w32
3406899129b3Smrg
3407899129b3Smrg
3408899129b3Smrg# func_convert_path_cygwin_to_w32 ARG
3409899129b3Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410899129b3Smrg# func_to_host_file_result.
3411899129b3Smrgfunc_convert_path_cygwin_to_w32 ()
3412899129b3Smrg{
3413e6d2e958Smrg  $debug_cmd
3414e6d2e958Smrg
3415e6d2e958Smrg  func_to_host_path_result=$1
3416899129b3Smrg  if test -n "$1"; then
3417899129b3Smrg    # See func_convert_path_msys_to_w32:
3418899129b3Smrg    func_stripname : : "$1"
3419899129b3Smrg    func_to_host_path_tmp1=$func_stripname_result
3420899129b3Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421899129b3Smrg    func_convert_path_check : ";" \
3422899129b3Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423899129b3Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424899129b3Smrg  fi
3425899129b3Smrg}
3426899129b3Smrg# end func_convert_path_cygwin_to_w32
3427899129b3Smrg
3428899129b3Smrg
3429899129b3Smrg# func_convert_path_nix_to_w32 ARG
3430899129b3Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431899129b3Smrg# a working winepath.  Returns result in func_to_host_file_result.
3432899129b3Smrgfunc_convert_path_nix_to_w32 ()
343347e89262Smrg{
3434e6d2e958Smrg  $debug_cmd
3435e6d2e958Smrg
3436e6d2e958Smrg  func_to_host_path_result=$1
3437899129b3Smrg  if test -n "$1"; then
3438899129b3Smrg    # See func_convert_path_msys_to_w32:
3439899129b3Smrg    func_stripname : : "$1"
3440899129b3Smrg    func_to_host_path_tmp1=$func_stripname_result
3441899129b3Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442e6d2e958Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443899129b3Smrg    func_convert_path_check : ";" \
3444899129b3Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445899129b3Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446899129b3Smrg  fi
3447899129b3Smrg}
3448899129b3Smrg# end func_convert_path_nix_to_w32
344947e89262Smrg
345047e89262Smrg
3451899129b3Smrg# func_convert_path_msys_to_cygwin ARG
3452899129b3Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453899129b3Smrg# Returns result in func_to_host_file_result.
3454899129b3Smrgfunc_convert_path_msys_to_cygwin ()
3455899129b3Smrg{
3456e6d2e958Smrg  $debug_cmd
3457e6d2e958Smrg
3458e6d2e958Smrg  func_to_host_path_result=$1
3459899129b3Smrg  if test -n "$1"; then
3460899129b3Smrg    # See func_convert_path_msys_to_w32:
3461899129b3Smrg    func_stripname : : "$1"
3462899129b3Smrg    func_to_host_path_tmp1=$func_stripname_result
3463899129b3Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464899129b3Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465e6d2e958Smrg    func_to_host_path_result=$func_cygpath_result
3466899129b3Smrg    func_convert_path_check : : \
3467899129b3Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468899129b3Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469899129b3Smrg  fi
3470899129b3Smrg}
3471899129b3Smrg# end func_convert_path_msys_to_cygwin
347247e89262Smrg
347347e89262Smrg
3474899129b3Smrg# func_convert_path_nix_to_cygwin ARG
3475899129b3Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476899129b3Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477899129b3Smrg# func_to_host_file_result.
3478899129b3Smrgfunc_convert_path_nix_to_cygwin ()
3479899129b3Smrg{
3480e6d2e958Smrg  $debug_cmd
3481e6d2e958Smrg
3482e6d2e958Smrg  func_to_host_path_result=$1
3483899129b3Smrg  if test -n "$1"; then
3484899129b3Smrg    # Remove leading and trailing path separator characters from
3485899129b3Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486899129b3Smrg    # into '.;' and ';.', and winepath ignores them completely.
3487899129b3Smrg    func_stripname : : "$1"
3488899129b3Smrg    func_to_host_path_tmp1=$func_stripname_result
3489899129b3Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490899129b3Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491e6d2e958Smrg    func_to_host_path_result=$func_cygpath_result
3492899129b3Smrg    func_convert_path_check : : \
3493899129b3Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494899129b3Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495899129b3Smrg  fi
349647e89262Smrg}
3497899129b3Smrg# end func_convert_path_nix_to_cygwin
3498899129b3Smrg
349947e89262Smrg
3500e6d2e958Smrg# func_dll_def_p FILE
3501e6d2e958Smrg# True iff FILE is a Windows DLL '.def' file.
3502e6d2e958Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503e6d2e958Smrgfunc_dll_def_p ()
3504e6d2e958Smrg{
3505e6d2e958Smrg  $debug_cmd
3506e6d2e958Smrg
3507e6d2e958Smrg  func_dll_def_p_tmp=`$SED -n \
3508e6d2e958Smrg    -e 's/^[	 ]*//' \
3509e6d2e958Smrg    -e '/^\(;.*\)*$/d' \
3510e6d2e958Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511e6d2e958Smrg    -e q \
3512e6d2e958Smrg    "$1"`
3513e6d2e958Smrg  test DEF = "$func_dll_def_p_tmp"
3514e6d2e958Smrg}
3515e6d2e958Smrg
3516e6d2e958Smrg
351747e89262Smrg# func_mode_compile arg...
351847e89262Smrgfunc_mode_compile ()
351947e89262Smrg{
3520e6d2e958Smrg    $debug_cmd
3521e6d2e958Smrg
352247e89262Smrg    # Get the compilation command and the source file.
352347e89262Smrg    base_compile=
3524e6d2e958Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
352547e89262Smrg    suppress_opt=yes
352647e89262Smrg    suppress_output=
352747e89262Smrg    arg_mode=normal
352847e89262Smrg    libobj=
352947e89262Smrg    later=
353047e89262Smrg    pie_flag=
353147e89262Smrg
353247e89262Smrg    for arg
353347e89262Smrg    do
353447e89262Smrg      case $arg_mode in
353547e89262Smrg      arg  )
353647e89262Smrg	# do not "continue".  Instead, add this to base_compile
3537e6d2e958Smrg	lastarg=$arg
353847e89262Smrg	arg_mode=normal
353947e89262Smrg	;;
354047e89262Smrg
354147e89262Smrg      target )
3542e6d2e958Smrg	libobj=$arg
354347e89262Smrg	arg_mode=normal
354447e89262Smrg	continue
354547e89262Smrg	;;
354647e89262Smrg
354747e89262Smrg      normal )
354847e89262Smrg	# Accept any command-line options.
354947e89262Smrg	case $arg in
355047e89262Smrg	-o)
355147e89262Smrg	  test -n "$libobj" && \
3552e6d2e958Smrg	    func_fatal_error "you cannot specify '-o' more than once"
355347e89262Smrg	  arg_mode=target
355447e89262Smrg	  continue
355547e89262Smrg	  ;;
355647e89262Smrg
355747e89262Smrg	-pie | -fpie | -fPIE)
3558899129b3Smrg          func_append pie_flag " $arg"
355947e89262Smrg	  continue
356047e89262Smrg	  ;;
356147e89262Smrg
356247e89262Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563899129b3Smrg	  func_append later " $arg"
356447e89262Smrg	  continue
356547e89262Smrg	  ;;
3566bd1da9d7Smrg
3567bd1da9d7Smrg	-no-suppress)
3568bd1da9d7Smrg	  suppress_opt=no
3569bd1da9d7Smrg	  continue
3570bd1da9d7Smrg	  ;;
3571bd1da9d7Smrg
3572bd1da9d7Smrg	-Xcompiler)
3573bd1da9d7Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574bd1da9d7Smrg	  continue      #  The current "srcfile" will either be retained or
3575bd1da9d7Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576bd1da9d7Smrg
3577bd1da9d7Smrg	-Wc,*)
357847e89262Smrg	  func_stripname '-Wc,' '' "$arg"
357947e89262Smrg	  args=$func_stripname_result
3580bd1da9d7Smrg	  lastarg=
3581e6d2e958Smrg	  save_ifs=$IFS; IFS=,
358247e89262Smrg	  for arg in $args; do
3583e6d2e958Smrg	    IFS=$save_ifs
3584899129b3Smrg	    func_append_quoted lastarg "$arg"
3585bd1da9d7Smrg	  done
3586e6d2e958Smrg	  IFS=$save_ifs
358747e89262Smrg	  func_stripname ' ' '' "$lastarg"
358847e89262Smrg	  lastarg=$func_stripname_result
3589bd1da9d7Smrg
3590bd1da9d7Smrg	  # Add the arguments to base_compile.
3591899129b3Smrg	  func_append base_compile " $lastarg"
3592bd1da9d7Smrg	  continue
3593bd1da9d7Smrg	  ;;
3594bd1da9d7Smrg
359547e89262Smrg	*)
3596bd1da9d7Smrg	  # Accept the current argument as the source file.
3597bd1da9d7Smrg	  # The previous "srcfile" becomes the current argument.
3598bd1da9d7Smrg	  #
3599e6d2e958Smrg	  lastarg=$srcfile
3600e6d2e958Smrg	  srcfile=$arg
3601bd1da9d7Smrg	  ;;
3602bd1da9d7Smrg	esac  #  case $arg
3603bd1da9d7Smrg	;;
3604bd1da9d7Smrg      esac    #  case $arg_mode
3605bd1da9d7Smrg
3606bd1da9d7Smrg      # Aesthetically quote the previous argument.
3607899129b3Smrg      func_append_quoted base_compile "$lastarg"
3608bd1da9d7Smrg    done # for arg
3609bd1da9d7Smrg
3610bd1da9d7Smrg    case $arg_mode in
3611bd1da9d7Smrg    arg)
361247e89262Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613bd1da9d7Smrg      ;;
3614bd1da9d7Smrg    target)
3615e6d2e958Smrg      func_fatal_error "you must specify a target with '-o'"
3616bd1da9d7Smrg      ;;
3617bd1da9d7Smrg    *)
3618bd1da9d7Smrg      # Get the name of the library object.
361947e89262Smrg      test -z "$libobj" && {
362047e89262Smrg	func_basename "$srcfile"
3621e6d2e958Smrg	libobj=$func_basename_result
362247e89262Smrg      }
3623bd1da9d7Smrg      ;;
3624bd1da9d7Smrg    esac
3625bd1da9d7Smrg
3626bd1da9d7Smrg    # Recognize several different file suffixes.
3627bd1da9d7Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3628bd1da9d7Smrg    case $libobj in
362947e89262Smrg    *.[cCFSifmso] | \
363047e89262Smrg    *.ada | *.adb | *.ads | *.asm | \
363147e89262Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632899129b3Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
363347e89262Smrg      func_xform "$libobj"
363447e89262Smrg      libobj=$func_xform_result
363547e89262Smrg      ;;
3636bd1da9d7Smrg    esac
3637bd1da9d7Smrg
3638bd1da9d7Smrg    case $libobj in
363947e89262Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640bd1da9d7Smrg    *)
3641e6d2e958Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642bd1da9d7Smrg      ;;
3643bd1da9d7Smrg    esac
3644bd1da9d7Smrg
3645bd1da9d7Smrg    func_infer_tag $base_compile
3646bd1da9d7Smrg
3647bd1da9d7Smrg    for arg in $later; do
3648bd1da9d7Smrg      case $arg in
364947e89262Smrg      -shared)
3650e6d2e958Smrg	test yes = "$build_libtool_libs" \
3651e6d2e958Smrg	  || func_fatal_configuration "cannot build a shared library"
365247e89262Smrg	build_old_libs=no
365347e89262Smrg	continue
365447e89262Smrg	;;
365547e89262Smrg
3656bd1da9d7Smrg      -static)
365747e89262Smrg	build_libtool_libs=no
3658bd1da9d7Smrg	build_old_libs=yes
3659bd1da9d7Smrg	continue
3660bd1da9d7Smrg	;;
3661bd1da9d7Smrg
3662bd1da9d7Smrg      -prefer-pic)
3663bd1da9d7Smrg	pic_mode=yes
3664bd1da9d7Smrg	continue
3665bd1da9d7Smrg	;;
3666bd1da9d7Smrg
3667bd1da9d7Smrg      -prefer-non-pic)
3668bd1da9d7Smrg	pic_mode=no
3669bd1da9d7Smrg	continue
3670bd1da9d7Smrg	;;
3671bd1da9d7Smrg      esac
3672bd1da9d7Smrg    done
3673bd1da9d7Smrg
3674a392d4f3Smrg    func_quote_arg pretty "$libobj"
3675a392d4f3Smrg    test "X$libobj" != "X$func_quote_arg_result" \
367647e89262Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677e6d2e958Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
367847e89262Smrg    func_dirname_and_basename "$obj" "/" ""
3679e6d2e958Smrg    objname=$func_basename_result
3680e6d2e958Smrg    xdir=$func_dirname_result
3681e6d2e958Smrg    lobj=$xdir$objdir/$objname
3682bd1da9d7Smrg
368347e89262Smrg    test -z "$base_compile" && \
368447e89262Smrg      func_fatal_help "you must specify a compilation command"
3685bd1da9d7Smrg
3686bd1da9d7Smrg    # Delete any leftover library objects.
3687e6d2e958Smrg    if test yes = "$build_old_libs"; then
3688bd1da9d7Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3689bd1da9d7Smrg    else
3690bd1da9d7Smrg      removelist="$lobj $libobj ${libobj}T"
3691bd1da9d7Smrg    fi
3692bd1da9d7Smrg
3693bd1da9d7Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694bd1da9d7Smrg    case $host_os in
369547e89262Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696bd1da9d7Smrg      pic_mode=default
3697bd1da9d7Smrg      ;;
3698bd1da9d7Smrg    esac
3699e6d2e958Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700bd1da9d7Smrg      # non-PIC code in shared libraries is not supported
3701bd1da9d7Smrg      pic_mode=default
3702bd1da9d7Smrg    fi
3703bd1da9d7Smrg
3704bd1da9d7Smrg    # Calculate the filename of the output object if compiler does
3705bd1da9d7Smrg    # not support -o with -c
3706e6d2e958Smrg    if test no = "$compiler_c_o"; then
3707e6d2e958Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708e6d2e958Smrg      lockfile=$output_obj.lock
3709bd1da9d7Smrg    else
3710bd1da9d7Smrg      output_obj=
3711bd1da9d7Smrg      need_locks=no
3712bd1da9d7Smrg      lockfile=
3713bd1da9d7Smrg    fi
3714bd1da9d7Smrg
3715bd1da9d7Smrg    # Lock this critical section if it is needed
3716bd1da9d7Smrg    # We use this script file to make the link, it avoids creating a new file
3717e6d2e958Smrg    if test yes = "$need_locks"; then
371847e89262Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
371947e89262Smrg	func_echo "Waiting for $lockfile to be removed"
3720bd1da9d7Smrg	sleep 2
3721bd1da9d7Smrg      done
3722e6d2e958Smrg    elif test warn = "$need_locks"; then
3723bd1da9d7Smrg      if test -f "$lockfile"; then
372447e89262Smrg	$ECHO "\
3725bd1da9d7Smrg*** ERROR, $lockfile exists and contains:
3726bd1da9d7Smrg`cat $lockfile 2>/dev/null`
3727bd1da9d7Smrg
3728bd1da9d7SmrgThis indicates that another process is trying to use the same
3729bd1da9d7Smrgtemporary object file, and libtool could not work around it because
3730e6d2e958Smrgyour compiler does not support '-c' and '-o' together.  If you
3731bd1da9d7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3732bd1da9d7Smrgavoid parallel builds (make -j) in this platform, or get a better
3733bd1da9d7Smrgcompiler."
3734bd1da9d7Smrg
373547e89262Smrg	$opt_dry_run || $RM $removelist
3736bd1da9d7Smrg	exit $EXIT_FAILURE
3737bd1da9d7Smrg      fi
3738899129b3Smrg      func_append removelist " $output_obj"
373947e89262Smrg      $ECHO "$srcfile" > "$lockfile"
3740bd1da9d7Smrg    fi
3741bd1da9d7Smrg
374247e89262Smrg    $opt_dry_run || $RM $removelist
3743899129b3Smrg    func_append removelist " $lockfile"
374447e89262Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
374547e89262Smrg
3746899129b3Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747899129b3Smrg    srcfile=$func_to_tool_file_result
3748a392d4f3Smrg    func_quote_arg pretty "$srcfile"
3749a392d4f3Smrg    qsrcfile=$func_quote_arg_result
3750bd1da9d7Smrg
3751bd1da9d7Smrg    # Only build a PIC object if we are building libtool libraries.
3752e6d2e958Smrg    if test yes = "$build_libtool_libs"; then
3753bd1da9d7Smrg      # Without this assignment, base_compile gets emptied.
3754bd1da9d7Smrg      fbsd_hideous_sh_bug=$base_compile
3755bd1da9d7Smrg
3756e6d2e958Smrg      if test no != "$pic_mode"; then
3757bd1da9d7Smrg	command="$base_compile $qsrcfile $pic_flag"
3758bd1da9d7Smrg      else
3759bd1da9d7Smrg	# Don't build PIC code
3760bd1da9d7Smrg	command="$base_compile $qsrcfile"
3761bd1da9d7Smrg      fi
3762bd1da9d7Smrg
376347e89262Smrg      func_mkdir_p "$xdir$objdir"
3764bd1da9d7Smrg
3765bd1da9d7Smrg      if test -z "$output_obj"; then
3766bd1da9d7Smrg	# Place PIC objects in $objdir
3767899129b3Smrg	func_append command " -o $lobj"
3768bd1da9d7Smrg      fi
3769bd1da9d7Smrg
377047e89262Smrg      func_show_eval_locale "$command"	\
377147e89262Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772bd1da9d7Smrg
3773e6d2e958Smrg      if test warn = "$need_locks" &&
3774bd1da9d7Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
377547e89262Smrg	$ECHO "\
3776bd1da9d7Smrg*** ERROR, $lockfile contains:
3777bd1da9d7Smrg`cat $lockfile 2>/dev/null`
3778bd1da9d7Smrg
3779bd1da9d7Smrgbut it should contain:
3780bd1da9d7Smrg$srcfile
3781bd1da9d7Smrg
3782bd1da9d7SmrgThis indicates that another process is trying to use the same
3783bd1da9d7Smrgtemporary object file, and libtool could not work around it because
3784e6d2e958Smrgyour compiler does not support '-c' and '-o' together.  If you
3785bd1da9d7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3786bd1da9d7Smrgavoid parallel builds (make -j) in this platform, or get a better
3787bd1da9d7Smrgcompiler."
3788bd1da9d7Smrg
378947e89262Smrg	$opt_dry_run || $RM $removelist
3790bd1da9d7Smrg	exit $EXIT_FAILURE
3791bd1da9d7Smrg      fi
3792bd1da9d7Smrg
3793bd1da9d7Smrg      # Just move the object if needed, then go on to compile the next one
3794bd1da9d7Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
379547e89262Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
379647e89262Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797bd1da9d7Smrg      fi
3798bd1da9d7Smrg
3799bd1da9d7Smrg      # Allow error messages only from the first compilation.
3800e6d2e958Smrg      if test yes = "$suppress_opt"; then
380147e89262Smrg	suppress_output=' >/dev/null 2>&1'
3802bd1da9d7Smrg      fi
3803bd1da9d7Smrg    fi
3804bd1da9d7Smrg
3805bd1da9d7Smrg    # Only build a position-dependent object if we build old libraries.
3806e6d2e958Smrg    if test yes = "$build_old_libs"; then
3807e6d2e958Smrg      if test yes != "$pic_mode"; then
3808bd1da9d7Smrg	# Don't build PIC code
380947e89262Smrg	command="$base_compile $qsrcfile$pie_flag"
3810bd1da9d7Smrg      else
3811bd1da9d7Smrg	command="$base_compile $qsrcfile $pic_flag"
3812bd1da9d7Smrg      fi
3813e6d2e958Smrg      if test yes = "$compiler_c_o"; then
3814899129b3Smrg	func_append command " -o $obj"
3815bd1da9d7Smrg      fi
3816bd1da9d7Smrg
3817bd1da9d7Smrg      # Suppress compiler output if we already did a PIC compilation.
3818899129b3Smrg      func_append command "$suppress_output"
381947e89262Smrg      func_show_eval_locale "$command" \
382047e89262Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821bd1da9d7Smrg
3822e6d2e958Smrg      if test warn = "$need_locks" &&
3823bd1da9d7Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
382447e89262Smrg	$ECHO "\
3825bd1da9d7Smrg*** ERROR, $lockfile contains:
3826bd1da9d7Smrg`cat $lockfile 2>/dev/null`
3827bd1da9d7Smrg
3828bd1da9d7Smrgbut it should contain:
3829bd1da9d7Smrg$srcfile
3830bd1da9d7Smrg
3831bd1da9d7SmrgThis indicates that another process is trying to use the same
3832bd1da9d7Smrgtemporary object file, and libtool could not work around it because
3833e6d2e958Smrgyour compiler does not support '-c' and '-o' together.  If you
3834bd1da9d7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3835bd1da9d7Smrgavoid parallel builds (make -j) in this platform, or get a better
3836bd1da9d7Smrgcompiler."
3837bd1da9d7Smrg
383847e89262Smrg	$opt_dry_run || $RM $removelist
3839bd1da9d7Smrg	exit $EXIT_FAILURE
3840bd1da9d7Smrg      fi
3841bd1da9d7Smrg
3842bd1da9d7Smrg      # Just move the object if needed
3843bd1da9d7Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
384447e89262Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
384547e89262Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846bd1da9d7Smrg      fi
3847bd1da9d7Smrg    fi
3848bd1da9d7Smrg
384947e89262Smrg    $opt_dry_run || {
385047e89262Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851bd1da9d7Smrg
385247e89262Smrg      # Unlock the critical section if it was locked
3853e6d2e958Smrg      if test no != "$need_locks"; then
385447e89262Smrg	removelist=$lockfile
385547e89262Smrg        $RM "$lockfile"
385647e89262Smrg      fi
385747e89262Smrg    }
3858bd1da9d7Smrg
3859bd1da9d7Smrg    exit $EXIT_SUCCESS
386047e89262Smrg}
3861bd1da9d7Smrg
386247e89262Smrg$opt_help || {
3863e6d2e958Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
386447e89262Smrg}
3865bd1da9d7Smrg
386647e89262Smrgfunc_mode_help ()
386747e89262Smrg{
386847e89262Smrg    # We need to display help for each of the modes.
3869899129b3Smrg    case $opt_mode in
387047e89262Smrg      "")
387147e89262Smrg        # Generic help is extracted from the usage comments
387247e89262Smrg        # at the start of this file.
387347e89262Smrg        func_help
387447e89262Smrg        ;;
3875bd1da9d7Smrg
387647e89262Smrg      clean)
387747e89262Smrg        $ECHO \
387847e89262Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879bd1da9d7Smrg
388047e89262SmrgRemove files from the build directory.
3881bd1da9d7Smrg
388247e89262SmrgRM is the name of the program to use to delete files associated with each FILE
3883e6d2e958Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
388447e89262Smrgto RM.
3885bd1da9d7Smrg
388647e89262SmrgIf FILE is a libtool library, object or program, all the files associated
388747e89262Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
388847e89262Smrg        ;;
3889bd1da9d7Smrg
389047e89262Smrg      compile)
389147e89262Smrg      $ECHO \
389247e89262Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893bd1da9d7Smrg
389447e89262SmrgCompile a source file into a libtool library object.
3895bd1da9d7Smrg
389647e89262SmrgThis mode accepts the following additional options:
3897bd1da9d7Smrg
389847e89262Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
389947e89262Smrg  -no-suppress      do not suppress compiler output for multiple passes
390047e89262Smrg  -prefer-pic       try to build PIC objects only
390147e89262Smrg  -prefer-non-pic   try to build non-PIC objects only
3902e6d2e958Smrg  -shared           do not build a '.o' file suitable for static linking
3903e6d2e958Smrg  -static           only build a '.o' file suitable for static linking
3904a392d4f3Smrg  -Wc,FLAG
3905a392d4f3Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906bd1da9d7Smrg
3907e6d2e958SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
390847e89262Smrgfrom the given SOURCEFILE.
3909bd1da9d7Smrg
391047e89262SmrgThe output file name is determined by removing the directory component from
3911e6d2e958SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912e6d2e958Smrglibrary object suffix, '.lo'."
391347e89262Smrg        ;;
3914bd1da9d7Smrg
391547e89262Smrg      execute)
391647e89262Smrg        $ECHO \
391747e89262Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918bd1da9d7Smrg
391947e89262SmrgAutomatically set library path, then run a program.
3920bd1da9d7Smrg
392147e89262SmrgThis mode accepts the following additional options:
3922bd1da9d7Smrg
392347e89262Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924bd1da9d7Smrg
3925e6d2e958SmrgThis mode sets the library path environment variable according to '-dlopen'
392647e89262Smrgflags.
3927bd1da9d7Smrg
392847e89262SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
392947e89262Smrginto their corresponding uninstalled binary, and any of their required library
393047e89262Smrgdirectories are added to the library path.
3931bd1da9d7Smrg
393247e89262SmrgThen, COMMAND is executed, with ARGS as arguments."
393347e89262Smrg        ;;
3934bd1da9d7Smrg
393547e89262Smrg      finish)
393647e89262Smrg        $ECHO \
393747e89262Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938bd1da9d7Smrg
393947e89262SmrgComplete the installation of libtool libraries.
3940bd1da9d7Smrg
394147e89262SmrgEach LIBDIR is a directory that contains libtool libraries.
3942bd1da9d7Smrg
394347e89262SmrgThe commands that this mode executes may require superuser privileges.  Use
3944e6d2e958Smrgthe '--dry-run' option if you just want to see what would be executed."
394547e89262Smrg        ;;
3946bd1da9d7Smrg
394747e89262Smrg      install)
394847e89262Smrg        $ECHO \
394947e89262Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950bd1da9d7Smrg
395147e89262SmrgInstall executables or libraries.
3952bd1da9d7Smrg
395347e89262SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954e6d2e958Smrgeither the 'install' or 'cp' program.
3955bd1da9d7Smrg
395647e89262SmrgThe following components of INSTALL-COMMAND are treated specially:
3957bd1da9d7Smrg
395847e89262Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959bd1da9d7Smrg
396047e89262SmrgThe rest of the components are interpreted as arguments to that command (only
396147e89262SmrgBSD-compatible install options are recognized)."
396247e89262Smrg        ;;
3963bd1da9d7Smrg
396447e89262Smrg      link)
396547e89262Smrg        $ECHO \
396647e89262Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967bd1da9d7Smrg
396847e89262SmrgLink object files or libraries together to form another library, or to
396947e89262Smrgcreate an executable program.
3970bd1da9d7Smrg
397147e89262SmrgLINK-COMMAND is a command using the C compiler that you would use to create
397247e89262Smrga program from several object files.
3973bd1da9d7Smrg
397447e89262SmrgThe following components of LINK-COMMAND are treated specially:
3975bd1da9d7Smrg
397647e89262Smrg  -all-static       do not do any dynamic linking at all
397747e89262Smrg  -avoid-version    do not add a version suffix if possible
397847e89262Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397947e89262Smrg                    libraries must be found in the PATH setting at runtime)
3980e6d2e958Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
398147e89262Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
398247e89262Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
398347e89262Smrg  -export-symbols SYMFILE
398447e89262Smrg                    try to export only the symbols listed in SYMFILE
398547e89262Smrg  -export-symbols-regex REGEX
398647e89262Smrg                    try to export only the symbols matching REGEX
398747e89262Smrg  -LLIBDIR          search LIBDIR for required installed libraries
398847e89262Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
398947e89262Smrg  -module           build a library that can dlopened
399047e89262Smrg  -no-fast-install  disable the fast-install mode
399147e89262Smrg  -no-install       link a not-installable executable
399247e89262Smrg  -no-undefined     declare that a library does not refer to external symbols
399347e89262Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994e6d2e958Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995e6d2e958Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
399647e89262Smrg  -precious-files-regex REGEX
399747e89262Smrg                    don't remove output files matching REGEX
399847e89262Smrg  -release RELEASE  specify package release information
399947e89262Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
400047e89262Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
400147e89262Smrg  -shared           only do dynamic linking of libtool libraries
400247e89262Smrg  -shrext SUFFIX    override the standard shared library file extension
400347e89262Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
400447e89262Smrg  -static-libtool-libs
400547e89262Smrg                    do not do any dynamic linking of libtool libraries
400647e89262Smrg  -version-info CURRENT[:REVISION[:AGE]]
400747e89262Smrg                    specify library version info [each variable defaults to 0]
400847e89262Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400947e89262Smrg  -Wc,FLAG
401047e89262Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011a392d4f3Smrg  -Wa,FLAG
4012a392d4f3Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
401347e89262Smrg  -Wl,FLAG
401447e89262Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
401547e89262Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016bd1da9d7Smrg
4017e6d2e958SmrgAll other options (arguments beginning with '-') are ignored.
4018bd1da9d7Smrg
4019e6d2e958SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
402047e89262Smrgtreated as uninstalled libtool libraries, other files are standard or library
402147e89262Smrgobject files.
4022bd1da9d7Smrg
4023e6d2e958SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024e6d2e958Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
402547e89262Smrgrequired, except when creating a convenience library.
4026bd1da9d7Smrg
4027e6d2e958SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028e6d2e958Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40295bcb6992Smrg
4030e6d2e958SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
403147e89262Smrgis created, otherwise an executable program is created."
403247e89262Smrg        ;;
4033bd1da9d7Smrg
403447e89262Smrg      uninstall)
403547e89262Smrg        $ECHO \
403647e89262Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037bd1da9d7Smrg
403847e89262SmrgRemove libraries from an installation directory.
4039bd1da9d7Smrg
404047e89262SmrgRM is the name of the program to use to delete files associated with each FILE
4041e6d2e958Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
404247e89262Smrgto RM.
4043bd1da9d7Smrg
404447e89262SmrgIf FILE is a libtool library, all the files associated with it are deleted.
404547e89262SmrgOtherwise, only FILE itself is deleted using RM."
404647e89262Smrg        ;;
4047bd1da9d7Smrg
404847e89262Smrg      *)
4049e6d2e958Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
405047e89262Smrg        ;;
405147e89262Smrg    esac
4052bd1da9d7Smrg
405347e89262Smrg    echo
4054e6d2e958Smrg    $ECHO "Try '$progname --help' for more information about other modes."
405547e89262Smrg}
4056bd1da9d7Smrg
405747e89262Smrg# Now that we've collected a possible --mode arg, show help if necessary
405847e89262Smrgif $opt_help; then
4059e6d2e958Smrg  if test : = "$opt_help"; then
406047e89262Smrg    func_mode_help
406147e89262Smrg  else
406247e89262Smrg    {
406347e89262Smrg      func_help noexit
4064899129b3Smrg      for opt_mode in compile link execute install finish uninstall clean; do
406547e89262Smrg	func_mode_help
406647e89262Smrg      done
4067e6d2e958Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406847e89262Smrg    {
406947e89262Smrg      func_help noexit
4070899129b3Smrg      for opt_mode in compile link execute install finish uninstall clean; do
407147e89262Smrg	echo
407247e89262Smrg	func_mode_help
407347e89262Smrg      done
407447e89262Smrg    } |
4075e6d2e958Smrg    $SED '1d
407647e89262Smrg      /^When reporting/,/^Report/{
407747e89262Smrg	H
407847e89262Smrg	d
407947e89262Smrg      }
408047e89262Smrg      $x
408147e89262Smrg      /information about other modes/d
408247e89262Smrg      /more detailed .*MODE/d
408347e89262Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
408447e89262Smrg  fi
408547e89262Smrg  exit $?
408647e89262Smrgfi
4087bd1da9d7Smrg
4088bd1da9d7Smrg
408947e89262Smrg# func_mode_execute arg...
409047e89262Smrgfunc_mode_execute ()
409147e89262Smrg{
4092e6d2e958Smrg    $debug_cmd
4093e6d2e958Smrg
409447e89262Smrg    # The first argument is the command name.
4095e6d2e958Smrg    cmd=$nonopt
409647e89262Smrg    test -z "$cmd" && \
409747e89262Smrg      func_fatal_help "you must specify a COMMAND"
4098bd1da9d7Smrg
409947e89262Smrg    # Handle -dlopen flags immediately.
4100899129b3Smrg    for file in $opt_dlopen; do
410147e89262Smrg      test -f "$file" \
4102e6d2e958Smrg	|| func_fatal_help "'$file' is not a file"
4103bd1da9d7Smrg
410447e89262Smrg      dir=
410547e89262Smrg      case $file in
410647e89262Smrg      *.la)
4107899129b3Smrg	func_resolve_sysroot "$file"
4108899129b3Smrg	file=$func_resolve_sysroot_result
4109899129b3Smrg
411047e89262Smrg	# Check to see that this really is a libtool archive.
411147e89262Smrg	func_lalib_unsafe_p "$file" \
4112e6d2e958Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113bd1da9d7Smrg
411447e89262Smrg	# Read the libtool library.
411547e89262Smrg	dlname=
411647e89262Smrg	library_names=
411747e89262Smrg	func_source "$file"
4118bd1da9d7Smrg
411947e89262Smrg	# Skip this library if it cannot be dlopened.
412047e89262Smrg	if test -z "$dlname"; then
412147e89262Smrg	  # Warn if it was a shared library.
412247e89262Smrg	  test -n "$library_names" && \
4123e6d2e958Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
412447e89262Smrg	  continue
412547e89262Smrg	fi
4126bd1da9d7Smrg
412747e89262Smrg	func_dirname "$file" "" "."
4128e6d2e958Smrg	dir=$func_dirname_result
4129bd1da9d7Smrg
413047e89262Smrg	if test -f "$dir/$objdir/$dlname"; then
4131899129b3Smrg	  func_append dir "/$objdir"
413247e89262Smrg	else
413347e89262Smrg	  if test ! -f "$dir/$dlname"; then
4134e6d2e958Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
413547e89262Smrg	  fi
413647e89262Smrg	fi
4137bd1da9d7Smrg	;;
4138bd1da9d7Smrg
413947e89262Smrg      *.lo)
414047e89262Smrg	# Just add the directory containing the .lo file.
414147e89262Smrg	func_dirname "$file" "" "."
4142e6d2e958Smrg	dir=$func_dirname_result
4143bd1da9d7Smrg	;;
414447e89262Smrg
414547e89262Smrg      *)
4146e6d2e958Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147bd1da9d7Smrg	continue
4148bd1da9d7Smrg	;;
414947e89262Smrg      esac
4150bd1da9d7Smrg
415147e89262Smrg      # Get the absolute pathname.
415247e89262Smrg      absdir=`cd "$dir" && pwd`
4153e6d2e958Smrg      test -n "$absdir" && dir=$absdir
4154bd1da9d7Smrg
415547e89262Smrg      # Now add the directory to shlibpath_var.
415647e89262Smrg      if eval "test -z \"\$$shlibpath_var\""; then
415747e89262Smrg	eval "$shlibpath_var=\"\$dir\""
415847e89262Smrg      else
415947e89262Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
416047e89262Smrg      fi
416147e89262Smrg    done
4162bd1da9d7Smrg
416347e89262Smrg    # This variable tells wrapper scripts just to set shlibpath_var
416447e89262Smrg    # rather than running their programs.
4165e6d2e958Smrg    libtool_execute_magic=$magic
4166bd1da9d7Smrg
416747e89262Smrg    # Check if any of the arguments is a wrapper script.
416847e89262Smrg    args=
416947e89262Smrg    for file
417047e89262Smrg    do
417147e89262Smrg      case $file in
417247e89262Smrg      -* | *.la | *.lo ) ;;
417347e89262Smrg      *)
417447e89262Smrg	# Do a test to see if this is really a libtool program.
417547e89262Smrg	if func_ltwrapper_script_p "$file"; then
417647e89262Smrg	  func_source "$file"
417747e89262Smrg	  # Transform arg to wrapped name.
4178e6d2e958Smrg	  file=$progdir/$program
417947e89262Smrg	elif func_ltwrapper_executable_p "$file"; then
418047e89262Smrg	  func_ltwrapper_scriptname "$file"
418147e89262Smrg	  func_source "$func_ltwrapper_scriptname_result"
418247e89262Smrg	  # Transform arg to wrapped name.
4183e6d2e958Smrg	  file=$progdir/$program
418447e89262Smrg	fi
4185bd1da9d7Smrg	;;
418647e89262Smrg      esac
418747e89262Smrg      # Quote arguments (to preserve shell metacharacters).
4188899129b3Smrg      func_append_quoted args "$file"
418947e89262Smrg    done
4190bd1da9d7Smrg
4191e6d2e958Smrg    if $opt_dry_run; then
4192e6d2e958Smrg      # Display what would be done.
4193e6d2e958Smrg      if test -n "$shlibpath_var"; then
4194e6d2e958Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195e6d2e958Smrg	echo "export $shlibpath_var"
4196e6d2e958Smrg      fi
4197e6d2e958Smrg      $ECHO "$cmd$args"
4198e6d2e958Smrg      exit $EXIT_SUCCESS
4199e6d2e958Smrg    else
420047e89262Smrg      if test -n "$shlibpath_var"; then
420147e89262Smrg	# Export the shlibpath_var.
420247e89262Smrg	eval "export $shlibpath_var"
420347e89262Smrg      fi
4204bd1da9d7Smrg
420547e89262Smrg      # Restore saved environment variables
420647e89262Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
420747e89262Smrg      do
420847e89262Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
420947e89262Smrg                $lt_var=\$save_$lt_var; export $lt_var
421047e89262Smrg	      else
421147e89262Smrg		$lt_unset $lt_var
421247e89262Smrg	      fi"
421347e89262Smrg      done
4214bd1da9d7Smrg
421547e89262Smrg      # Now prepare to actually exec the command.
4216e6d2e958Smrg      exec_cmd=\$cmd$args
421747e89262Smrg    fi
421847e89262Smrg}
4219bd1da9d7Smrg
4220e6d2e958Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221bd1da9d7Smrg
4222bd1da9d7Smrg
422347e89262Smrg# func_mode_finish arg...
422447e89262Smrgfunc_mode_finish ()
422547e89262Smrg{
4226e6d2e958Smrg    $debug_cmd
4227e6d2e958Smrg
4228899129b3Smrg    libs=
4229899129b3Smrg    libdirs=
423047e89262Smrg    admincmds=
4231bd1da9d7Smrg
4232899129b3Smrg    for opt in "$nonopt" ${1+"$@"}
4233899129b3Smrg    do
4234899129b3Smrg      if test -d "$opt"; then
4235899129b3Smrg	func_append libdirs " $opt"
4236899129b3Smrg
4237899129b3Smrg      elif test -f "$opt"; then
4238899129b3Smrg	if func_lalib_unsafe_p "$opt"; then
4239899129b3Smrg	  func_append libs " $opt"
4240899129b3Smrg	else
4241e6d2e958Smrg	  func_warning "'$opt' is not a valid libtool archive"
4242899129b3Smrg	fi
4243899129b3Smrg
4244899129b3Smrg      else
4245e6d2e958Smrg	func_fatal_error "invalid argument '$opt'"
4246899129b3Smrg      fi
4247899129b3Smrg    done
4248899129b3Smrg
4249899129b3Smrg    if test -n "$libs"; then
4250899129b3Smrg      if test -n "$lt_sysroot"; then
4251899129b3Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252899129b3Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253899129b3Smrg      else
4254899129b3Smrg        sysroot_cmd=
4255899129b3Smrg      fi
4256899129b3Smrg
4257899129b3Smrg      # Remove sysroot references
4258899129b3Smrg      if $opt_dry_run; then
4259899129b3Smrg        for lib in $libs; do
4260e6d2e958Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261899129b3Smrg        done
4262899129b3Smrg      else
4263899129b3Smrg        tmpdir=`func_mktempdir`
4264899129b3Smrg        for lib in $libs; do
4265e6d2e958Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266899129b3Smrg	    > $tmpdir/tmp-la
4267899129b3Smrg	  mv -f $tmpdir/tmp-la $lib
4268899129b3Smrg	done
4269899129b3Smrg        ${RM}r "$tmpdir"
4270899129b3Smrg      fi
4271899129b3Smrg    fi
4272bd1da9d7Smrg
4273899129b3Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
427447e89262Smrg      for libdir in $libdirs; do
427547e89262Smrg	if test -n "$finish_cmds"; then
427647e89262Smrg	  # Do each command in the finish commands.
427747e89262Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
427847e89262Smrg'"$cmd"'"'
427947e89262Smrg	fi
428047e89262Smrg	if test -n "$finish_eval"; then
428147e89262Smrg	  # Do the single finish_eval.
428247e89262Smrg	  eval cmds=\"$finish_eval\"
4283899129b3Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
428447e89262Smrg       $cmds"
428547e89262Smrg	fi
428647e89262Smrg      done
428747e89262Smrg    fi
4288bd1da9d7Smrg
428947e89262Smrg    # Exit here if they wanted silent mode.
4290e6d2e958Smrg    $opt_quiet && exit $EXIT_SUCCESS
4291bd1da9d7Smrg
4292899129b3Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293899129b3Smrg      echo "----------------------------------------------------------------------"
4294899129b3Smrg      echo "Libraries have been installed in:"
4295899129b3Smrg      for libdir in $libdirs; do
4296899129b3Smrg	$ECHO "   $libdir"
4297899129b3Smrg      done
4298899129b3Smrg      echo
4299899129b3Smrg      echo "If you ever happen to want to link against installed libraries"
4300899129b3Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301e6d2e958Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302899129b3Smrg      echo "flag during linking and do at least one of the following:"
4303899129b3Smrg      if test -n "$shlibpath_var"; then
4304e6d2e958Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305899129b3Smrg	echo "     during execution"
4306899129b3Smrg      fi
4307899129b3Smrg      if test -n "$runpath_var"; then
4308e6d2e958Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309899129b3Smrg	echo "     during linking"
4310899129b3Smrg      fi
4311899129b3Smrg      if test -n "$hardcode_libdir_flag_spec"; then
4312899129b3Smrg	libdir=LIBDIR
4313899129b3Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314bd1da9d7Smrg
4315e6d2e958Smrg	$ECHO "   - use the '$flag' linker flag"
4316899129b3Smrg      fi
4317899129b3Smrg      if test -n "$admincmds"; then
4318899129b3Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319899129b3Smrg      fi
4320899129b3Smrg      if test -f /etc/ld.so.conf; then
4321e6d2e958Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322899129b3Smrg      fi
4323899129b3Smrg      echo
4324bd1da9d7Smrg
4325899129b3Smrg      echo "See any operating system documentation about shared libraries for"
4326899129b3Smrg      case $host in
4327899129b3Smrg	solaris2.[6789]|solaris2.1[0-9])
4328899129b3Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329899129b3Smrg	  echo "pages."
4330899129b3Smrg	  ;;
4331899129b3Smrg	*)
4332899129b3Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333899129b3Smrg	  ;;
4334899129b3Smrg      esac
4335899129b3Smrg      echo "----------------------------------------------------------------------"
4336899129b3Smrg    fi
433747e89262Smrg    exit $EXIT_SUCCESS
433847e89262Smrg}
4339bd1da9d7Smrg
4340e6d2e958Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341bd1da9d7Smrg
4342bd1da9d7Smrg
434347e89262Smrg# func_mode_install arg...
434447e89262Smrgfunc_mode_install ()
434547e89262Smrg{
4346e6d2e958Smrg    $debug_cmd
4347e6d2e958Smrg
434847e89262Smrg    # There may be an optional sh(1) argument at the beginning of
434947e89262Smrg    # install_prog (especially on Windows NT).
4350e6d2e958Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
435147e89262Smrg       # Allow the use of GNU shtool's install command.
4352e6d2e958Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4353e6d2e958Smrg    then
435447e89262Smrg      # Aesthetically quote it.
4355a392d4f3Smrg      func_quote_arg pretty "$nonopt"
4356a392d4f3Smrg      install_prog="$func_quote_arg_result "
435747e89262Smrg      arg=$1
435847e89262Smrg      shift
435947e89262Smrg    else
436047e89262Smrg      install_prog=
436147e89262Smrg      arg=$nonopt
436247e89262Smrg    fi
4363bd1da9d7Smrg
436447e89262Smrg    # The real first argument should be the name of the installation program.
436547e89262Smrg    # Aesthetically quote it.
4366a392d4f3Smrg    func_quote_arg pretty "$arg"
4367a392d4f3Smrg    func_append install_prog "$func_quote_arg_result"
436847e89262Smrg    install_shared_prog=$install_prog
436947e89262Smrg    case " $install_prog " in
437047e89262Smrg      *[\\\ /]cp\ *) install_cp=: ;;
437147e89262Smrg      *) install_cp=false ;;
437247e89262Smrg    esac
4373bd1da9d7Smrg
437447e89262Smrg    # We need to accept at least all the BSD install flags.
437547e89262Smrg    dest=
437647e89262Smrg    files=
437747e89262Smrg    opts=
437847e89262Smrg    prev=
437947e89262Smrg    install_type=
4380e6d2e958Smrg    isdir=false
438147e89262Smrg    stripme=
438247e89262Smrg    no_mode=:
438347e89262Smrg    for arg
438447e89262Smrg    do
438547e89262Smrg      arg2=
438647e89262Smrg      if test -n "$dest"; then
4387899129b3Smrg	func_append files " $dest"
438847e89262Smrg	dest=$arg
4389bd1da9d7Smrg	continue
439047e89262Smrg      fi
4391bd1da9d7Smrg
439247e89262Smrg      case $arg in
4393e6d2e958Smrg      -d) isdir=: ;;
439447e89262Smrg      -f)
439547e89262Smrg	if $install_cp; then :; else
439647e89262Smrg	  prev=$arg
4397bd1da9d7Smrg	fi
439847e89262Smrg	;;
439947e89262Smrg      -g | -m | -o)
440047e89262Smrg	prev=$arg
440147e89262Smrg	;;
440247e89262Smrg      -s)
440347e89262Smrg	stripme=" -s"
4404bd1da9d7Smrg	continue
4405bd1da9d7Smrg	;;
440647e89262Smrg      -*)
440747e89262Smrg	;;
4408bd1da9d7Smrg      *)
440947e89262Smrg	# If the previous option needed an argument, then skip it.
441047e89262Smrg	if test -n "$prev"; then
4411e6d2e958Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
441247e89262Smrg	    arg2=$install_override_mode
441347e89262Smrg	    no_mode=false
441447e89262Smrg	  fi
441547e89262Smrg	  prev=
441647e89262Smrg	else
441747e89262Smrg	  dest=$arg
441847e89262Smrg	  continue
441947e89262Smrg	fi
4420bd1da9d7Smrg	;;
442147e89262Smrg      esac
4422bd1da9d7Smrg
442347e89262Smrg      # Aesthetically quote the argument.
4424a392d4f3Smrg      func_quote_arg pretty "$arg"
4425a392d4f3Smrg      func_append install_prog " $func_quote_arg_result"
442647e89262Smrg      if test -n "$arg2"; then
4427a392d4f3Smrg	func_quote_arg pretty "$arg2"
4428bd1da9d7Smrg      fi
4429a392d4f3Smrg      func_append install_shared_prog " $func_quote_arg_result"
443047e89262Smrg    done
4431bd1da9d7Smrg
443247e89262Smrg    test -z "$install_prog" && \
443347e89262Smrg      func_fatal_help "you must specify an install program"
4434bd1da9d7Smrg
443547e89262Smrg    test -n "$prev" && \
4436e6d2e958Smrg      func_fatal_help "the '$prev' option requires an argument"
4437bd1da9d7Smrg
443847e89262Smrg    if test -n "$install_override_mode" && $no_mode; then
443947e89262Smrg      if $install_cp; then :; else
4440a392d4f3Smrg	func_quote_arg pretty "$install_override_mode"
4441a392d4f3Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
444247e89262Smrg      fi
4443bd1da9d7Smrg    fi
4444bd1da9d7Smrg
444547e89262Smrg    if test -z "$files"; then
444647e89262Smrg      if test -z "$dest"; then
444747e89262Smrg	func_fatal_help "no file or destination specified"
444847e89262Smrg      else
444947e89262Smrg	func_fatal_help "you must specify a destination"
4450bd1da9d7Smrg      fi
4451bd1da9d7Smrg    fi
4452bd1da9d7Smrg
445347e89262Smrg    # Strip any trailing slash from the destination.
445447e89262Smrg    func_stripname '' '/' "$dest"
445547e89262Smrg    dest=$func_stripname_result
4456bd1da9d7Smrg
445747e89262Smrg    # Check to see that the destination is a directory.
4458e6d2e958Smrg    test -d "$dest" && isdir=:
4459e6d2e958Smrg    if $isdir; then
4460e6d2e958Smrg      destdir=$dest
446147e89262Smrg      destname=
446247e89262Smrg    else
446347e89262Smrg      func_dirname_and_basename "$dest" "" "."
4464e6d2e958Smrg      destdir=$func_dirname_result
4465e6d2e958Smrg      destname=$func_basename_result
446647e89262Smrg
446747e89262Smrg      # Not a directory, so check to see that there is only one file specified.
446847e89262Smrg      set dummy $files; shift
446947e89262Smrg      test "$#" -gt 1 && \
4470e6d2e958Smrg	func_fatal_help "'$dest' is not a directory"
447147e89262Smrg    fi
447247e89262Smrg    case $destdir in
447347e89262Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474bd1da9d7Smrg    *)
447547e89262Smrg      for file in $files; do
447647e89262Smrg	case $file in
447747e89262Smrg	*.lo) ;;
447847e89262Smrg	*)
4479e6d2e958Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
448047e89262Smrg	  ;;
448147e89262Smrg	esac
448247e89262Smrg      done
4483bd1da9d7Smrg      ;;
4484bd1da9d7Smrg    esac
4485bd1da9d7Smrg
448647e89262Smrg    # This variable tells wrapper scripts just to set variables rather
448747e89262Smrg    # than running their programs.
4488e6d2e958Smrg    libtool_install_magic=$magic
4489bd1da9d7Smrg
449047e89262Smrg    staticlibs=
449147e89262Smrg    future_libdirs=
449247e89262Smrg    current_libdirs=
449347e89262Smrg    for file in $files; do
4494bd1da9d7Smrg
449547e89262Smrg      # Do each installation.
449647e89262Smrg      case $file in
449747e89262Smrg      *.$libext)
449847e89262Smrg	# Do the static libraries later.
4499899129b3Smrg	func_append staticlibs " $file"
450047e89262Smrg	;;
450147e89262Smrg
450247e89262Smrg      *.la)
4503899129b3Smrg	func_resolve_sysroot "$file"
4504899129b3Smrg	file=$func_resolve_sysroot_result
4505899129b3Smrg
450647e89262Smrg	# Check to see that this really is a libtool archive.
450747e89262Smrg	func_lalib_unsafe_p "$file" \
4508e6d2e958Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
450947e89262Smrg
451047e89262Smrg	library_names=
451147e89262Smrg	old_library=
451247e89262Smrg	relink_command=
451347e89262Smrg	func_source "$file"
451447e89262Smrg
451547e89262Smrg	# Add the libdir to current_libdirs if it is the destination.
451647e89262Smrg	if test "X$destdir" = "X$libdir"; then
451747e89262Smrg	  case "$current_libdirs " in
451847e89262Smrg	  *" $libdir "*) ;;
4519899129b3Smrg	  *) func_append current_libdirs " $libdir" ;;
4520bd1da9d7Smrg	  esac
452147e89262Smrg	else
452247e89262Smrg	  # Note the libdir as a future libdir.
452347e89262Smrg	  case "$future_libdirs " in
452447e89262Smrg	  *" $libdir "*) ;;
4525899129b3Smrg	  *) func_append future_libdirs " $libdir" ;;
452647e89262Smrg	  esac
452747e89262Smrg	fi
4528bd1da9d7Smrg
452947e89262Smrg	func_dirname "$file" "/" ""
4530e6d2e958Smrg	dir=$func_dirname_result
4531899129b3Smrg	func_append dir "$objdir"
453247e89262Smrg
453347e89262Smrg	if test -n "$relink_command"; then
453447e89262Smrg	  # Determine the prefix the user has applied to our future dir.
453547e89262Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
453647e89262Smrg
453747e89262Smrg	  # Don't allow the user to place us outside of our expected
453847e89262Smrg	  # location b/c this prevents finding dependent libraries that
453947e89262Smrg	  # are installed to the same prefix.
454047e89262Smrg	  # At present, this check doesn't affect windows .dll's that
454147e89262Smrg	  # are installed into $libdir/../bin (currently, that works fine)
454247e89262Smrg	  # but it's something to keep an eye on.
454347e89262Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544e6d2e958Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
454547e89262Smrg
454647e89262Smrg	  if test -n "$inst_prefix_dir"; then
454747e89262Smrg	    # Stick the inst_prefix_dir data into the link command.
454847e89262Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
454947e89262Smrg	  else
455047e89262Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
455147e89262Smrg	  fi
455247e89262Smrg
4553e6d2e958Smrg	  func_warning "relinking '$file'"
455447e89262Smrg	  func_show_eval "$relink_command" \
4555e6d2e958Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
455647e89262Smrg	fi
455747e89262Smrg
455847e89262Smrg	# See the names of the shared library.
455947e89262Smrg	set dummy $library_names; shift
456047e89262Smrg	if test -n "$1"; then
4561e6d2e958Smrg	  realname=$1
456247e89262Smrg	  shift
456347e89262Smrg
4564e6d2e958Smrg	  srcname=$realname
4565e6d2e958Smrg	  test -n "$relink_command" && srcname=${realname}T
456647e89262Smrg
456747e89262Smrg	  # Install the shared library and build the symlinks.
456847e89262Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
456947e89262Smrg	      'exit $?'
4570e6d2e958Smrg	  tstripme=$stripme
457147e89262Smrg	  case $host_os in
457247e89262Smrg	  cygwin* | mingw* | pw32* | cegcc*)
457347e89262Smrg	    case $realname in
457447e89262Smrg	    *.dll.a)
4575e6d2e958Smrg	      tstripme=
4576e6d2e958Smrg	      ;;
4577e6d2e958Smrg	    esac
4578e6d2e958Smrg	    ;;
4579e6d2e958Smrg	  os2*)
4580e6d2e958Smrg	    case $realname in
4581e6d2e958Smrg	    *_dll.a)
4582e6d2e958Smrg	      tstripme=
458347e89262Smrg	      ;;
458447e89262Smrg	    esac
4585bd1da9d7Smrg	    ;;
4586bd1da9d7Smrg	  esac
458747e89262Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
458847e89262Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
458947e89262Smrg	  fi
459047e89262Smrg
459147e89262Smrg	  if test "$#" -gt 0; then
459247e89262Smrg	    # Delete the old symlinks, and create new ones.
4593e6d2e958Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
459447e89262Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
459547e89262Smrg	    # so we also need to try rm && ln -s.
459647e89262Smrg	    for linkname
459747e89262Smrg	    do
459847e89262Smrg	      test "$linkname" != "$realname" \
459947e89262Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
460047e89262Smrg	    done
460147e89262Smrg	  fi
460247e89262Smrg
460347e89262Smrg	  # Do each command in the postinstall commands.
4604e6d2e958Smrg	  lib=$destdir/$realname
460547e89262Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
460647e89262Smrg	fi
460747e89262Smrg
460847e89262Smrg	# Install the pseudo-library for information purposes.
460947e89262Smrg	func_basename "$file"
4610e6d2e958Smrg	name=$func_basename_result
4611e6d2e958Smrg	instname=$dir/${name}i
461247e89262Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
461347e89262Smrg
461447e89262Smrg	# Maybe install the static library, too.
4615899129b3Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616bd1da9d7Smrg	;;
461747e89262Smrg
461847e89262Smrg      *.lo)
461947e89262Smrg	# Install (i.e. copy) a libtool object.
462047e89262Smrg
462147e89262Smrg	# Figure out destination file name, if it wasn't already specified.
462247e89262Smrg	if test -n "$destname"; then
4623e6d2e958Smrg	  destfile=$destdir/$destname
462447e89262Smrg	else
462547e89262Smrg	  func_basename "$file"
4626e6d2e958Smrg	  destfile=$func_basename_result
4627e6d2e958Smrg	  destfile=$destdir/$destfile
462847e89262Smrg	fi
462947e89262Smrg
463047e89262Smrg	# Deduce the name of the destination old-style object file.
463147e89262Smrg	case $destfile in
463247e89262Smrg	*.lo)
463347e89262Smrg	  func_lo2o "$destfile"
463447e89262Smrg	  staticdest=$func_lo2o_result
4635bd1da9d7Smrg	  ;;
463647e89262Smrg	*.$objext)
4637e6d2e958Smrg	  staticdest=$destfile
463847e89262Smrg	  destfile=
4639bd1da9d7Smrg	  ;;
464047e89262Smrg	*)
4641e6d2e958Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642bd1da9d7Smrg	  ;;
464347e89262Smrg	esac
464447e89262Smrg
464547e89262Smrg	# Install the libtool object if requested.
464647e89262Smrg	test -n "$destfile" && \
464747e89262Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
464847e89262Smrg
464947e89262Smrg	# Install the old object if enabled.
4650e6d2e958Smrg	if test yes = "$build_old_libs"; then
465147e89262Smrg	  # Deduce the name of the old-style object file.
465247e89262Smrg	  func_lo2o "$file"
465347e89262Smrg	  staticobj=$func_lo2o_result
465447e89262Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655bd1da9d7Smrg	fi
465647e89262Smrg	exit $EXIT_SUCCESS
465747e89262Smrg	;;
4658bd1da9d7Smrg
465947e89262Smrg      *)
466047e89262Smrg	# Figure out destination file name, if it wasn't already specified.
466147e89262Smrg	if test -n "$destname"; then
4662e6d2e958Smrg	  destfile=$destdir/$destname
4663bd1da9d7Smrg	else
466447e89262Smrg	  func_basename "$file"
4665e6d2e958Smrg	  destfile=$func_basename_result
4666e6d2e958Smrg	  destfile=$destdir/$destfile
4667bd1da9d7Smrg	fi
4668bd1da9d7Smrg
466947e89262Smrg	# If the file is missing, and there is a .exe on the end, strip it
467047e89262Smrg	# because it is most likely a libtool script we actually want to
467147e89262Smrg	# install
4672e6d2e958Smrg	stripped_ext=
467347e89262Smrg	case $file in
467447e89262Smrg	  *.exe)
467547e89262Smrg	    if test ! -f "$file"; then
467647e89262Smrg	      func_stripname '' '.exe' "$file"
467747e89262Smrg	      file=$func_stripname_result
4678e6d2e958Smrg	      stripped_ext=.exe
467947e89262Smrg	    fi
468047e89262Smrg	    ;;
468147e89262Smrg	esac
4682bd1da9d7Smrg
468347e89262Smrg	# Do a test to see if this is really a libtool program.
468447e89262Smrg	case $host in
468547e89262Smrg	*cygwin* | *mingw*)
468647e89262Smrg	    if func_ltwrapper_executable_p "$file"; then
468747e89262Smrg	      func_ltwrapper_scriptname "$file"
468847e89262Smrg	      wrapper=$func_ltwrapper_scriptname_result
468947e89262Smrg	    else
469047e89262Smrg	      func_stripname '' '.exe' "$file"
469147e89262Smrg	      wrapper=$func_stripname_result
469247e89262Smrg	    fi
469347e89262Smrg	    ;;
469447e89262Smrg	*)
469547e89262Smrg	    wrapper=$file
469647e89262Smrg	    ;;
469747e89262Smrg	esac
469847e89262Smrg	if func_ltwrapper_script_p "$wrapper"; then
469947e89262Smrg	  notinst_deplibs=
470047e89262Smrg	  relink_command=
4701bd1da9d7Smrg
470247e89262Smrg	  func_source "$wrapper"
4703bd1da9d7Smrg
470447e89262Smrg	  # Check the variables that should have been set.
470547e89262Smrg	  test -z "$generated_by_libtool_version" && \
4706e6d2e958Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707bd1da9d7Smrg
4708e6d2e958Smrg	  finalize=:
470947e89262Smrg	  for lib in $notinst_deplibs; do
471047e89262Smrg	    # Check to see that each library is installed.
471147e89262Smrg	    libdir=
471247e89262Smrg	    if test -f "$lib"; then
471347e89262Smrg	      func_source "$lib"
4714bd1da9d7Smrg	    fi
4715e6d2e958Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
471647e89262Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717e6d2e958Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718e6d2e958Smrg	      finalize=false
471947e89262Smrg	    fi
472047e89262Smrg	  done
4721bd1da9d7Smrg
472247e89262Smrg	  relink_command=
472347e89262Smrg	  func_source "$wrapper"
4724bd1da9d7Smrg
472547e89262Smrg	  outputname=
4726e6d2e958Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
472747e89262Smrg	    $opt_dry_run || {
4728e6d2e958Smrg	      if $finalize; then
472947e89262Smrg	        tmpdir=`func_mktempdir`
473047e89262Smrg		func_basename "$file$stripped_ext"
4731e6d2e958Smrg		file=$func_basename_result
4732e6d2e958Smrg	        outputname=$tmpdir/$file
473347e89262Smrg	        # Replace the output file specification.
473447e89262Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
473547e89262Smrg
4736e6d2e958Smrg	        $opt_quiet || {
4737a392d4f3Smrg	          func_quote_arg expand,pretty "$relink_command"
4738a392d4f3Smrg		  eval "func_echo $func_quote_arg_result"
473947e89262Smrg	        }
474047e89262Smrg	        if eval "$relink_command"; then :
474147e89262Smrg	          else
4742e6d2e958Smrg		  func_error "error: relink '$file' with the above command before installing it"
474347e89262Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
474447e89262Smrg		  continue
474547e89262Smrg	        fi
4746e6d2e958Smrg	        file=$outputname
474747e89262Smrg	      else
4748e6d2e958Smrg	        func_warning "cannot relink '$file'"
474947e89262Smrg	      fi
475047e89262Smrg	    }
4751bd1da9d7Smrg	  else
475247e89262Smrg	    # Install the binary that we compiled earlier.
475347e89262Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754bd1da9d7Smrg	  fi
475547e89262Smrg	fi
4756bd1da9d7Smrg
475747e89262Smrg	# remove .exe since cygwin /usr/bin/install will append another
475847e89262Smrg	# one anyway
475947e89262Smrg	case $install_prog,$host in
476047e89262Smrg	*/usr/bin/install*,*cygwin*)
476147e89262Smrg	  case $file:$destfile in
476247e89262Smrg	  *.exe:*.exe)
476347e89262Smrg	    # this is ok
476447e89262Smrg	    ;;
476547e89262Smrg	  *.exe:*)
476647e89262Smrg	    destfile=$destfile.exe
476747e89262Smrg	    ;;
476847e89262Smrg	  *:*.exe)
476947e89262Smrg	    func_stripname '' '.exe' "$destfile"
477047e89262Smrg	    destfile=$func_stripname_result
477147e89262Smrg	    ;;
477247e89262Smrg	  esac
4773bd1da9d7Smrg	  ;;
4774bd1da9d7Smrg	esac
477547e89262Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
477647e89262Smrg	$opt_dry_run || if test -n "$outputname"; then
477747e89262Smrg	  ${RM}r "$tmpdir"
477847e89262Smrg	fi
477947e89262Smrg	;;
478047e89262Smrg      esac
478147e89262Smrg    done
4782bd1da9d7Smrg
478347e89262Smrg    for file in $staticlibs; do
478447e89262Smrg      func_basename "$file"
4785e6d2e958Smrg      name=$func_basename_result
478647e89262Smrg
478747e89262Smrg      # Set up the ranlib parameters.
4788e6d2e958Smrg      oldlib=$destdir/$name
4789899129b3Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790899129b3Smrg      tool_oldlib=$func_to_tool_file_result
479147e89262Smrg
479247e89262Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
479347e89262Smrg
479447e89262Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795899129b3Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
479647e89262Smrg      fi
479747e89262Smrg
479847e89262Smrg      # Do each command in the postinstall commands.
479947e89262Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
480047e89262Smrg    done
480147e89262Smrg
480247e89262Smrg    test -n "$future_libdirs" && \
4803e6d2e958Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
480447e89262Smrg
480547e89262Smrg    if test -n "$current_libdirs"; then
480647e89262Smrg      # Maybe just do a dry run.
480747e89262Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808e6d2e958Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
480947e89262Smrg    else
481047e89262Smrg      exit $EXIT_SUCCESS
481147e89262Smrg    fi
481247e89262Smrg}
481347e89262Smrg
4814e6d2e958Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
481547e89262Smrg
481647e89262Smrg
481747e89262Smrg# func_generate_dlsyms outputname originator pic_p
481847e89262Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
481947e89262Smrg# a dlpreopen symbol table.
482047e89262Smrgfunc_generate_dlsyms ()
482147e89262Smrg{
4822e6d2e958Smrg    $debug_cmd
4823e6d2e958Smrg
4824e6d2e958Smrg    my_outputname=$1
4825e6d2e958Smrg    my_originator=$2
4826e6d2e958Smrg    my_pic_p=${3-false}
4827e6d2e958Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
482847e89262Smrg    my_dlsyms=
482947e89262Smrg
4830e6d2e958Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
483147e89262Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832e6d2e958Smrg	my_dlsyms=${my_outputname}S.c
483347e89262Smrg      else
483447e89262Smrg	func_error "not configured to extract global symbols from dlpreopened files"
483547e89262Smrg      fi
483647e89262Smrg    fi
483747e89262Smrg
483847e89262Smrg    if test -n "$my_dlsyms"; then
483947e89262Smrg      case $my_dlsyms in
484047e89262Smrg      "") ;;
484147e89262Smrg      *.c)
484247e89262Smrg	# Discover the nlist of each of the dlfiles.
4843e6d2e958Smrg	nlist=$output_objdir/$my_outputname.nm
484447e89262Smrg
484547e89262Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
484647e89262Smrg
484747e89262Smrg	# Parse the name list into a source file.
484847e89262Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
484947e89262Smrg
485047e89262Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851e6d2e958Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852e6d2e958Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
485347e89262Smrg
485447e89262Smrg#ifdef __cplusplus
485547e89262Smrgextern \"C\" {
485647e89262Smrg#endif
485747e89262Smrg
4858e6d2e958Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485947e89262Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
486047e89262Smrg#endif
486147e89262Smrg
4862899129b3Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863e6d2e958Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864e6d2e958Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865899129b3Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866899129b3Smrg# define LT_DLSYM_CONST
4867e6d2e958Smrg#elif defined __osf__
4868899129b3Smrg/* This system does not cope well with relocations in const data.  */
4869899129b3Smrg# define LT_DLSYM_CONST
4870899129b3Smrg#else
4871899129b3Smrg# define LT_DLSYM_CONST const
4872899129b3Smrg#endif
4873899129b3Smrg
4874e6d2e958Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875e6d2e958Smrg
487647e89262Smrg/* External symbol declarations for the compiler. */\
487747e89262Smrg"
487847e89262Smrg
4879e6d2e958Smrg	if test yes = "$dlself"; then
4880e6d2e958Smrg	  func_verbose "generating symbol list for '$output'"
488147e89262Smrg
488247e89262Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
488347e89262Smrg
488447e89262Smrg	  # Add our own program objects to the symbol list.
488547e89262Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
488647e89262Smrg	  for progfile in $progfiles; do
4887899129b3Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888e6d2e958Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889899129b3Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
489047e89262Smrg	  done
489147e89262Smrg
489247e89262Smrg	  if test -n "$exclude_expsyms"; then
489347e89262Smrg	    $opt_dry_run || {
489447e89262Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
489547e89262Smrg	      eval '$MV "$nlist"T "$nlist"'
489647e89262Smrg	    }
4897bd1da9d7Smrg	  fi
489847e89262Smrg
489947e89262Smrg	  if test -n "$export_symbols_regex"; then
490047e89262Smrg	    $opt_dry_run || {
490147e89262Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
490247e89262Smrg	      eval '$MV "$nlist"T "$nlist"'
490347e89262Smrg	    }
490447e89262Smrg	  fi
490547e89262Smrg
490647e89262Smrg	  # Prepare the list of exported symbols
490747e89262Smrg	  if test -z "$export_symbols"; then
4908e6d2e958Smrg	    export_symbols=$output_objdir/$outputname.exp
490947e89262Smrg	    $opt_dry_run || {
491047e89262Smrg	      $RM $export_symbols
4911e6d2e958Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
491247e89262Smrg	      case $host in
491347e89262Smrg	      *cygwin* | *mingw* | *cegcc* )
491447e89262Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
491547e89262Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
491647e89262Smrg	        ;;
491747e89262Smrg	      esac
491847e89262Smrg	    }
4919bd1da9d7Smrg	  else
492047e89262Smrg	    $opt_dry_run || {
4921e6d2e958Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
492247e89262Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
492347e89262Smrg	      eval '$MV "$nlist"T "$nlist"'
492447e89262Smrg	      case $host in
492547e89262Smrg	        *cygwin* | *mingw* | *cegcc* )
492647e89262Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
492747e89262Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
492847e89262Smrg	          ;;
492947e89262Smrg	      esac
493047e89262Smrg	    }
4931bd1da9d7Smrg	  fi
493247e89262Smrg	fi
4933bd1da9d7Smrg
493447e89262Smrg	for dlprefile in $dlprefiles; do
4935e6d2e958Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
493647e89262Smrg	  func_basename "$dlprefile"
4937e6d2e958Smrg	  name=$func_basename_result
4938899129b3Smrg          case $host in
4939899129b3Smrg	    *cygwin* | *mingw* | *cegcc* )
4940899129b3Smrg	      # if an import library, we need to obtain dlname
4941899129b3Smrg	      if func_win32_import_lib_p "$dlprefile"; then
4942899129b3Smrg	        func_tr_sh "$dlprefile"
4943899129b3Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944e6d2e958Smrg	        dlprefile_dlbasename=
4945899129b3Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946899129b3Smrg	          # Use subshell, to avoid clobbering current variable values
4947899129b3Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948e6d2e958Smrg	          if test -n "$dlprefile_dlname"; then
4949899129b3Smrg	            func_basename "$dlprefile_dlname"
4950e6d2e958Smrg	            dlprefile_dlbasename=$func_basename_result
4951899129b3Smrg	          else
4952899129b3Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953899129b3Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954899129b3Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955899129b3Smrg	          fi
4956899129b3Smrg	        fi
4957899129b3Smrg	        $opt_dry_run || {
4958e6d2e958Smrg	          if test -n "$dlprefile_dlbasename"; then
4959899129b3Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960899129b3Smrg	          else
4961899129b3Smrg	            func_warning "Could not compute DLL name from $name"
4962899129b3Smrg	            eval '$ECHO ": $name " >> "$nlist"'
4963899129b3Smrg	          fi
4964899129b3Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965899129b3Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966899129b3Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967899129b3Smrg	        }
4968899129b3Smrg	      else # not an import lib
4969899129b3Smrg	        $opt_dry_run || {
4970899129b3Smrg	          eval '$ECHO ": $name " >> "$nlist"'
4971899129b3Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972899129b3Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973899129b3Smrg	        }
4974899129b3Smrg	      fi
4975899129b3Smrg	    ;;
4976899129b3Smrg	    *)
4977899129b3Smrg	      $opt_dry_run || {
4978899129b3Smrg	        eval '$ECHO ": $name " >> "$nlist"'
4979899129b3Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980899129b3Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981899129b3Smrg	      }
4982899129b3Smrg	    ;;
4983899129b3Smrg          esac
498447e89262Smrg	done
498547e89262Smrg
498647e89262Smrg	$opt_dry_run || {
498747e89262Smrg	  # Make sure we have at least an empty file.
498847e89262Smrg	  test -f "$nlist" || : > "$nlist"
498947e89262Smrg
499047e89262Smrg	  if test -n "$exclude_expsyms"; then
499147e89262Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
499247e89262Smrg	    $MV "$nlist"T "$nlist"
4993bd1da9d7Smrg	  fi
499447e89262Smrg
499547e89262Smrg	  # Try sorting and uniquifying the output.
499647e89262Smrg	  if $GREP -v "^: " < "$nlist" |
499747e89262Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
499847e89262Smrg		sort -k 3
499947e89262Smrg	      else
500047e89262Smrg		sort +2
500147e89262Smrg	      fi |
500247e89262Smrg	      uniq > "$nlist"S; then
500347e89262Smrg	    :
5004bd1da9d7Smrg	  else
500547e89262Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006bd1da9d7Smrg	  fi
5007bd1da9d7Smrg
500847e89262Smrg	  if test -f "$nlist"S; then
500947e89262Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010bd1da9d7Smrg	  else
501147e89262Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012bd1da9d7Smrg	  fi
5013bd1da9d7Smrg
5014e6d2e958Smrg	  func_show_eval '$RM "${nlist}I"'
5015e6d2e958Smrg	  if test -n "$global_symbol_to_import"; then
5016e6d2e958Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017e6d2e958Smrg	  fi
5018e6d2e958Smrg
501947e89262Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020bd1da9d7Smrg
502147e89262Smrg/* The mapping between symbol names and symbols.  */
502247e89262Smrgtypedef struct {
502347e89262Smrg  const char *name;
502447e89262Smrg  void *address;
502547e89262Smrg} lt_dlsymlist;
5026899129b3Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027e6d2e958Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028e6d2e958Smrg"
5029e6d2e958Smrg
5030e6d2e958Smrg	  if test -s "$nlist"I; then
5031e6d2e958Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032e6d2e958Smrgstatic void lt_syminit(void)
5033e6d2e958Smrg{
5034e6d2e958Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035e6d2e958Smrg  for (; symbol->name; ++symbol)
5036e6d2e958Smrg    {"
5037e6d2e958Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038e6d2e958Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039e6d2e958Smrg    }
5040e6d2e958Smrg}"
5041e6d2e958Smrg	  fi
5042e6d2e958Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043899129b3SmrgLT_DLSYM_CONST lt_dlsymlist
504447e89262Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045e6d2e958Smrg{ {\"$my_originator\", (void *) 0},"
5046e6d2e958Smrg
5047e6d2e958Smrg	  if test -s "$nlist"I; then
5048e6d2e958Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049e6d2e958Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5050e6d2e958Smrg	  fi
5051bd1da9d7Smrg
505247e89262Smrg	  case $need_lib_prefix in
505347e89262Smrg	  no)
505447e89262Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
505547e89262Smrg	    ;;
505647e89262Smrg	  *)
505747e89262Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
505847e89262Smrg	    ;;
505947e89262Smrg	  esac
506047e89262Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
506147e89262Smrg  {0, (void *) 0}
506247e89262Smrg};
5063bd1da9d7Smrg
506447e89262Smrg/* This works around a problem in FreeBSD linker */
506547e89262Smrg#ifdef FREEBSD_WORKAROUND
506647e89262Smrgstatic const void *lt_preloaded_setup() {
506747e89262Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
506847e89262Smrg}
506947e89262Smrg#endif
5070bd1da9d7Smrg
507147e89262Smrg#ifdef __cplusplus
507247e89262Smrg}
507347e89262Smrg#endif\
507447e89262Smrg"
507547e89262Smrg	} # !$opt_dry_run
5076bd1da9d7Smrg
507747e89262Smrg	pic_flag_for_symtable=
507847e89262Smrg	case "$compile_command " in
507947e89262Smrg	*" -static "*) ;;
508047e89262Smrg	*)
508147e89262Smrg	  case $host in
508247e89262Smrg	  # compiling the symbol table file with pic_flag works around
508347e89262Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
508447e89262Smrg	  # linked before any other PIC object.  But we must not use
508547e89262Smrg	  # pic_flag when linking with -static.  The problem exists in
508647e89262Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087899129b3Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
508847e89262Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
508947e89262Smrg	  *-*-hpux*)
509047e89262Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
509147e89262Smrg	  *)
5092e6d2e958Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
509347e89262Smrg	    ;;
509447e89262Smrg	  esac
509547e89262Smrg	  ;;
509647e89262Smrg	esac
509747e89262Smrg	symtab_cflags=
509847e89262Smrg	for arg in $LTCFLAGS; do
509947e89262Smrg	  case $arg in
510047e89262Smrg	  -pie | -fpie | -fPIE) ;;
5101899129b3Smrg	  *) func_append symtab_cflags " $arg" ;;
510247e89262Smrg	  esac
510347e89262Smrg	done
5104bd1da9d7Smrg
510547e89262Smrg	# Now compile the dynamic symbol file.
510647e89262Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107bd1da9d7Smrg
510847e89262Smrg	# Clean up the generated files.
5109e6d2e958Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110bd1da9d7Smrg
511147e89262Smrg	# Transform the symbol file into the correct name.
5112e6d2e958Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
511347e89262Smrg	case $host in
511447e89262Smrg	*cygwin* | *mingw* | *cegcc* )
511547e89262Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
511647e89262Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511747e89262Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511847e89262Smrg	  else
511947e89262Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512047e89262Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512147e89262Smrg	  fi
512247e89262Smrg	  ;;
512347e89262Smrg	*)
512447e89262Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512547e89262Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512647e89262Smrg	  ;;
512747e89262Smrg	esac
512847e89262Smrg	;;
512947e89262Smrg      *)
5130e6d2e958Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
513147e89262Smrg	;;
513247e89262Smrg      esac
513347e89262Smrg    else
513447e89262Smrg      # We keep going just in case the user didn't refer to
513547e89262Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
513647e89262Smrg      # really was required.
5137bd1da9d7Smrg
513847e89262Smrg      # Nullify the symbol file.
513947e89262Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
514047e89262Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
514147e89262Smrg    fi
514247e89262Smrg}
5143bd1da9d7Smrg
5144e6d2e958Smrg# func_cygming_gnu_implib_p ARG
5145e6d2e958Smrg# This predicate returns with zero status (TRUE) if
5146e6d2e958Smrg# ARG is a GNU/binutils-style import library. Returns
5147e6d2e958Smrg# with nonzero status (FALSE) otherwise.
5148e6d2e958Smrgfunc_cygming_gnu_implib_p ()
5149e6d2e958Smrg{
5150e6d2e958Smrg  $debug_cmd
5151e6d2e958Smrg
5152e6d2e958Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153e6d2e958Smrg  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)$'`
5154e6d2e958Smrg  test -n "$func_cygming_gnu_implib_tmp"
5155e6d2e958Smrg}
5156e6d2e958Smrg
5157e6d2e958Smrg# func_cygming_ms_implib_p ARG
5158e6d2e958Smrg# This predicate returns with zero status (TRUE) if
5159e6d2e958Smrg# ARG is an MS-style import library. Returns
5160e6d2e958Smrg# with nonzero status (FALSE) otherwise.
5161e6d2e958Smrgfunc_cygming_ms_implib_p ()
5162e6d2e958Smrg{
5163e6d2e958Smrg  $debug_cmd
5164e6d2e958Smrg
5165e6d2e958Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166e6d2e958Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167e6d2e958Smrg  test -n "$func_cygming_ms_implib_tmp"
5168e6d2e958Smrg}
5169e6d2e958Smrg
517047e89262Smrg# func_win32_libid arg
517147e89262Smrg# return the library type of file 'arg'
517247e89262Smrg#
517347e89262Smrg# Need a lot of goo to handle *both* DLLs and import libs
517447e89262Smrg# Has to be a shell function in order to 'eat' the argument
517547e89262Smrg# that is supplied when $file_magic_command is called.
517647e89262Smrg# Despite the name, also deal with 64 bit binaries.
517747e89262Smrgfunc_win32_libid ()
517847e89262Smrg{
5179e6d2e958Smrg  $debug_cmd
5180e6d2e958Smrg
5181e6d2e958Smrg  win32_libid_type=unknown
518247e89262Smrg  win32_fileres=`file -L $1 2>/dev/null`
518347e89262Smrg  case $win32_fileres in
518447e89262Smrg  *ar\ archive\ import\ library*) # definitely import
518547e89262Smrg    win32_libid_type="x86 archive import"
518647e89262Smrg    ;;
518747e89262Smrg  *ar\ archive*) # could be an import, or static
518847e89262Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
518947e89262Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
519047e89262Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191e6d2e958Smrg      case $nm_interface in
5192e6d2e958Smrg      "MS dumpbin")
5193e6d2e958Smrg	if func_cygming_ms_implib_p "$1" ||
5194e6d2e958Smrg	   func_cygming_gnu_implib_p "$1"
5195e6d2e958Smrg	then
5196e6d2e958Smrg	  win32_nmres=import
5197e6d2e958Smrg	else
5198e6d2e958Smrg	  win32_nmres=
5199e6d2e958Smrg	fi
5200e6d2e958Smrg	;;
5201e6d2e958Smrg      *)
5202e6d2e958Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203e6d2e958Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204e6d2e958Smrg	  $SED -n -e '
520547e89262Smrg	    1,100{
520647e89262Smrg		/ I /{
5207e6d2e958Smrg		    s|.*|import|
520847e89262Smrg		    p
520947e89262Smrg		    q
521047e89262Smrg		}
521147e89262Smrg	    }'`
5212e6d2e958Smrg	;;
5213e6d2e958Smrg      esac
521447e89262Smrg      case $win32_nmres in
521547e89262Smrg      import*)  win32_libid_type="x86 archive import";;
521647e89262Smrg      *)        win32_libid_type="x86 archive static";;
521747e89262Smrg      esac
521847e89262Smrg    fi
521947e89262Smrg    ;;
522047e89262Smrg  *DLL*)
522147e89262Smrg    win32_libid_type="x86 DLL"
522247e89262Smrg    ;;
522347e89262Smrg  *executable*) # but shell scripts are "executable" too...
522447e89262Smrg    case $win32_fileres in
522547e89262Smrg    *MS\ Windows\ PE\ Intel*)
522647e89262Smrg      win32_libid_type="x86 DLL"
522747e89262Smrg      ;;
522847e89262Smrg    esac
522947e89262Smrg    ;;
523047e89262Smrg  esac
523147e89262Smrg  $ECHO "$win32_libid_type"
523247e89262Smrg}
5233bd1da9d7Smrg
5234899129b3Smrg# func_cygming_dll_for_implib ARG
5235899129b3Smrg#
5236899129b3Smrg# Platform-specific function to extract the
5237899129b3Smrg# name of the DLL associated with the specified
5238899129b3Smrg# import library ARG.
5239899129b3Smrg# Invoked by eval'ing the libtool variable
5240899129b3Smrg#    $sharedlib_from_linklib_cmd
5241899129b3Smrg# Result is available in the variable
5242899129b3Smrg#    $sharedlib_from_linklib_result
5243899129b3Smrgfunc_cygming_dll_for_implib ()
5244899129b3Smrg{
5245e6d2e958Smrg  $debug_cmd
5246e6d2e958Smrg
5247899129b3Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248899129b3Smrg}
5249899129b3Smrg
5250899129b3Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251899129b3Smrg#
5252899129b3Smrg# The is the core of a fallback implementation of a
5253899129b3Smrg# platform-specific function to extract the name of the
5254899129b3Smrg# DLL associated with the specified import library LIBNAME.
5255899129b3Smrg#
5256899129b3Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257899129b3Smrg# on the platform and compiler that created the implib.
5258899129b3Smrg#
5259899129b3Smrg# Echos the name of the DLL associated with the
5260899129b3Smrg# specified import library.
5261899129b3Smrgfunc_cygming_dll_for_implib_fallback_core ()
5262899129b3Smrg{
5263e6d2e958Smrg  $debug_cmd
5264e6d2e958Smrg
5265899129b3Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266899129b3Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267899129b3Smrg    $SED '/^Contents of section '"$match_literal"':/{
5268899129b3Smrg      # Place marker at beginning of archive member dllname section
5269899129b3Smrg      s/.*/====MARK====/
5270899129b3Smrg      p
5271899129b3Smrg      d
5272899129b3Smrg    }
5273899129b3Smrg    # These lines can sometimes be longer than 43 characters, but
5274899129b3Smrg    # are always uninteresting
5275899129b3Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276899129b3Smrg    /^In archive [^:]*:/d
5277899129b3Smrg    # Ensure marker is printed
5278899129b3Smrg    /^====MARK====/p
5279899129b3Smrg    # Remove all lines with less than 43 characters
5280899129b3Smrg    /^.\{43\}/!d
5281899129b3Smrg    # From remaining lines, remove first 43 characters
5282899129b3Smrg    s/^.\{43\}//' |
5283899129b3Smrg    $SED -n '
5284899129b3Smrg      # Join marker and all lines until next marker into a single line
5285899129b3Smrg      /^====MARK====/ b para
5286899129b3Smrg      H
5287899129b3Smrg      $ b para
5288899129b3Smrg      b
5289899129b3Smrg      :para
5290899129b3Smrg      x
5291899129b3Smrg      s/\n//g
5292899129b3Smrg      # Remove the marker
5293899129b3Smrg      s/^====MARK====//
5294899129b3Smrg      # Remove trailing dots and whitespace
5295899129b3Smrg      s/[\. \t]*$//
5296899129b3Smrg      # Print
5297899129b3Smrg      /./p' |
5298899129b3Smrg    # we now have a list, one entry per line, of the stringified
5299899129b3Smrg    # contents of the appropriate section of all members of the
5300e6d2e958Smrg    # archive that possess that section. Heuristic: eliminate
5301e6d2e958Smrg    # all those that have a first or second character that is
5302899129b3Smrg    # a '.' (that is, objdump's representation of an unprintable
5303899129b3Smrg    # character.) This should work for all archives with less than
5304899129b3Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305899129b3Smrg    # begins with a literal '.' or a single character followed by
5306899129b3Smrg    # a '.'.
5307899129b3Smrg    #
5308899129b3Smrg    # Of those that remain, print the first one.
5309899129b3Smrg    $SED -e '/^\./d;/^.\./d;q'
5310899129b3Smrg}
5311899129b3Smrg
5312899129b3Smrg# func_cygming_dll_for_implib_fallback ARG
5313899129b3Smrg# Platform-specific function to extract the
5314899129b3Smrg# name of the DLL associated with the specified
5315899129b3Smrg# import library ARG.
5316899129b3Smrg#
5317899129b3Smrg# This fallback implementation is for use when $DLLTOOL
5318899129b3Smrg# does not support the --identify-strict option.
5319899129b3Smrg# Invoked by eval'ing the libtool variable
5320899129b3Smrg#    $sharedlib_from_linklib_cmd
5321899129b3Smrg# Result is available in the variable
5322899129b3Smrg#    $sharedlib_from_linklib_result
5323899129b3Smrgfunc_cygming_dll_for_implib_fallback ()
5324899129b3Smrg{
5325e6d2e958Smrg  $debug_cmd
5326e6d2e958Smrg
5327e6d2e958Smrg  if func_cygming_gnu_implib_p "$1"; then
5328899129b3Smrg    # binutils import library
5329899129b3Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330e6d2e958Smrg  elif func_cygming_ms_implib_p "$1"; then
5331899129b3Smrg    # ms-generated import library
5332899129b3Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333899129b3Smrg  else
5334899129b3Smrg    # unknown
5335e6d2e958Smrg    sharedlib_from_linklib_result=
5336899129b3Smrg  fi
5337899129b3Smrg}
5338bd1da9d7Smrg
5339bd1da9d7Smrg
534047e89262Smrg# func_extract_an_archive dir oldlib
534147e89262Smrgfunc_extract_an_archive ()
534247e89262Smrg{
5343e6d2e958Smrg    $debug_cmd
5344e6d2e958Smrg
5345e6d2e958Smrg    f_ex_an_ar_dir=$1; shift
5346e6d2e958Smrg    f_ex_an_ar_oldlib=$1
5347e6d2e958Smrg    if test yes = "$lock_old_archive_extraction"; then
534847e89262Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534947e89262Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
535047e89262Smrg	func_echo "Waiting for $lockfile to be removed"
535147e89262Smrg	sleep 2
535247e89262Smrg      done
535347e89262Smrg    fi
535447e89262Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
535547e89262Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356e6d2e958Smrg    if test yes = "$lock_old_archive_extraction"; then
535747e89262Smrg      $opt_dry_run || rm -f "$lockfile"
535847e89262Smrg    fi
535947e89262Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
536047e89262Smrg     :
536147e89262Smrg    else
536247e89262Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
536347e89262Smrg    fi
536447e89262Smrg}
5365bd1da9d7Smrg
5366bd1da9d7Smrg
536747e89262Smrg# func_extract_archives gentop oldlib ...
536847e89262Smrgfunc_extract_archives ()
536947e89262Smrg{
5370e6d2e958Smrg    $debug_cmd
5371e6d2e958Smrg
5372e6d2e958Smrg    my_gentop=$1; shift
537347e89262Smrg    my_oldlibs=${1+"$@"}
5374e6d2e958Smrg    my_oldobjs=
5375e6d2e958Smrg    my_xlib=
5376e6d2e958Smrg    my_xabs=
5377e6d2e958Smrg    my_xdir=
5378bd1da9d7Smrg
537947e89262Smrg    for my_xlib in $my_oldlibs; do
538047e89262Smrg      # Extract the objects.
538147e89262Smrg      case $my_xlib in
5382e6d2e958Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
538347e89262Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
538447e89262Smrg      esac
538547e89262Smrg      func_basename "$my_xlib"
5386e6d2e958Smrg      my_xlib=$func_basename_result
538747e89262Smrg      my_xlib_u=$my_xlib
538847e89262Smrg      while :; do
538947e89262Smrg        case " $extracted_archives " in
539047e89262Smrg	*" $my_xlib_u "*)
539147e89262Smrg	  func_arith $extracted_serial + 1
539247e89262Smrg	  extracted_serial=$func_arith_result
539347e89262Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
539447e89262Smrg	*) break ;;
539547e89262Smrg	esac
539647e89262Smrg      done
539747e89262Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398e6d2e958Smrg      my_xdir=$my_gentop/$my_xlib_u
5399bd1da9d7Smrg
540047e89262Smrg      func_mkdir_p "$my_xdir"
540147e89262Smrg
540247e89262Smrg      case $host in
540347e89262Smrg      *-darwin*)
540447e89262Smrg	func_verbose "Extracting $my_xabs"
540547e89262Smrg	# Do not bother doing anything if just a dry run
540647e89262Smrg	$opt_dry_run || {
540747e89262Smrg	  darwin_orig_dir=`pwd`
540847e89262Smrg	  cd $my_xdir || exit $?
540947e89262Smrg	  darwin_archive=$my_xabs
541047e89262Smrg	  darwin_curdir=`pwd`
5411e6d2e958Smrg	  func_basename "$darwin_archive"
5412e6d2e958Smrg	  darwin_base_archive=$func_basename_result
541347e89262Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
541447e89262Smrg	  if test -n "$darwin_arches"; then
541547e89262Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
541647e89262Smrg	    darwin_arch=
541747e89262Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418e6d2e958Smrg	    for darwin_arch in  $darwin_arches; do
5419e6d2e958Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420e6d2e958Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421e6d2e958Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422e6d2e958Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
542347e89262Smrg	      cd "$darwin_curdir"
5424e6d2e958Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
542547e89262Smrg	    done # $darwin_arches
542647e89262Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427e6d2e958Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
542847e89262Smrg	    darwin_file=
542947e89262Smrg	    darwin_files=
543047e89262Smrg	    for darwin_file in $darwin_filelist; do
543147e89262Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
543247e89262Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
543347e89262Smrg	    done # $darwin_filelist
543447e89262Smrg	    $RM -rf unfat-$$
543547e89262Smrg	    cd "$darwin_orig_dir"
5436bd1da9d7Smrg	  else
543747e89262Smrg	    cd $darwin_orig_dir
543847e89262Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
543947e89262Smrg	  fi # $darwin_arches
544047e89262Smrg	} # !$opt_dry_run
544147e89262Smrg	;;
544247e89262Smrg      *)
544347e89262Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
544447e89262Smrg	;;
544547e89262Smrg      esac
544647e89262Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
544747e89262Smrg    done
5448bd1da9d7Smrg
5449e6d2e958Smrg    func_extract_archives_result=$my_oldobjs
545047e89262Smrg}
5451bd1da9d7Smrg
5452bd1da9d7Smrg
545347e89262Smrg# func_emit_wrapper [arg=no]
545447e89262Smrg#
545547e89262Smrg# Emit a libtool wrapper script on stdout.
545647e89262Smrg# Don't directly open a file because we may want to
545747e89262Smrg# incorporate the script contents within a cygwin/mingw
545847e89262Smrg# wrapper executable.  Must ONLY be called from within
545947e89262Smrg# func_mode_link because it depends on a number of variables
546047e89262Smrg# set therein.
546147e89262Smrg#
546247e89262Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
546347e89262Smrg# variable will take.  If 'yes', then the emitted script
5464e6d2e958Smrg# will assume that the directory where it is stored is
546547e89262Smrg# the $objdir directory.  This is a cygwin/mingw-specific
546647e89262Smrg# behavior.
546747e89262Smrgfunc_emit_wrapper ()
546847e89262Smrg{
546947e89262Smrg	func_emit_wrapper_arg1=${1-no}
5470bd1da9d7Smrg
547147e89262Smrg	$ECHO "\
547247e89262Smrg#! $SHELL
5473bd1da9d7Smrg
547447e89262Smrg# $output - temporary wrapper script for $objdir/$outputname
5475e6d2e958Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
547647e89262Smrg#
547747e89262Smrg# The $output program cannot be directly executed until all the libtool
547847e89262Smrg# libraries that it depends on are installed.
547947e89262Smrg#
548047e89262Smrg# This wrapper script should never be moved out of the build directory.
548147e89262Smrg# If it is, it will not operate correctly.
5482bd1da9d7Smrg
548347e89262Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
548447e89262Smrg# metacharacters that are still active within double-quoted strings.
548547e89262Smrgsed_quote_subst='$sed_quote_subst'
5486bd1da9d7Smrg
548747e89262Smrg# Be Bourne compatible
548847e89262Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
548947e89262Smrg  emulate sh
549047e89262Smrg  NULLCMD=:
549147e89262Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
549247e89262Smrg  # is contrary to our usage.  Disable this feature.
549347e89262Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
549447e89262Smrg  setopt NO_GLOB_SUBST
549547e89262Smrgelse
549647e89262Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
549747e89262Smrgfi
549847e89262SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
549947e89262SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500bd1da9d7Smrg
550147e89262Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
550247e89262Smrg# if CDPATH is set.
550347e89262Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504bd1da9d7Smrg
550547e89262Smrgrelink_command=\"$relink_command\"
5506bd1da9d7Smrg
550747e89262Smrg# This environment variable determines our operation mode.
550847e89262Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
550947e89262Smrg  # install mode needs the following variables:
551047e89262Smrg  generated_by_libtool_version='$macro_version'
551147e89262Smrg  notinst_deplibs='$notinst_deplibs'
551247e89262Smrgelse
551347e89262Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
551447e89262Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
551547e89262Smrg    file=\"\$0\""
5516bd1da9d7Smrg
5517a392d4f3Smrg    func_quote_arg pretty "$ECHO"
5518a392d4f3Smrg    qECHO=$func_quote_arg_result
551947e89262Smrg    $ECHO "\
5520bd1da9d7Smrg
552147e89262Smrg# A function that is used when there is no print builtin or printf.
552247e89262Smrgfunc_fallback_echo ()
552347e89262Smrg{
552447e89262Smrg  eval 'cat <<_LTECHO_EOF
552547e89262Smrg\$1
552647e89262Smrg_LTECHO_EOF'
552747e89262Smrg}
5528a392d4f3Smrg    ECHO=$qECHO
552947e89262Smrg  fi
553047e89262Smrg
553147e89262Smrg# Very basic option parsing. These options are (a) specific to
553247e89262Smrg# the libtool wrapper, (b) are identical between the wrapper
5533e6d2e958Smrg# /script/ and the wrapper /executable/ that is used only on
553447e89262Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535e6d2e958Smrg# (application programs are unlikely to have options that match
553647e89262Smrg# this pattern).
553747e89262Smrg#
553847e89262Smrg# There are only two supported options: --lt-debug and
553947e89262Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
554047e89262Smrg#
554147e89262Smrg# The first argument to this parsing function should be the
554247e89262Smrg# script's $0 value, followed by "$@".
554347e89262Smrglt_option_debug=
554447e89262Smrgfunc_parse_lt_options ()
554547e89262Smrg{
554647e89262Smrg  lt_script_arg0=\$0
554747e89262Smrg  shift
554847e89262Smrg  for lt_opt
554947e89262Smrg  do
555047e89262Smrg    case \"\$lt_opt\" in
555147e89262Smrg    --lt-debug) lt_option_debug=1 ;;
555247e89262Smrg    --lt-dump-script)
555347e89262Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
555447e89262Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
555547e89262Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
555647e89262Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555747e89262Smrg        exit 0
555847e89262Smrg      ;;
555947e89262Smrg    --lt-*)
556047e89262Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
556147e89262Smrg        exit 1
5562bd1da9d7Smrg      ;;
556347e89262Smrg    esac
556447e89262Smrg  done
5565bd1da9d7Smrg
556647e89262Smrg  # Print the debug banner immediately:
556747e89262Smrg  if test -n \"\$lt_option_debug\"; then
5568e6d2e958Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556947e89262Smrg  fi
557047e89262Smrg}
5571bd1da9d7Smrg
557247e89262Smrg# Used when --lt-debug. Prints its arguments to stdout
557347e89262Smrg# (redirection is the responsibility of the caller)
557447e89262Smrgfunc_lt_dump_args ()
557547e89262Smrg{
557647e89262Smrg  lt_dump_args_N=1;
557747e89262Smrg  for lt_arg
557847e89262Smrg  do
5579e6d2e958Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
558047e89262Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
558147e89262Smrg  done
558247e89262Smrg}
5583bd1da9d7Smrg
558447e89262Smrg# Core function for launching the target application
558547e89262Smrgfunc_exec_program_core ()
558647e89262Smrg{
558747e89262Smrg"
558847e89262Smrg  case $host in
558947e89262Smrg  # Backslashes separate directories on plain windows
559047e89262Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
559147e89262Smrg    $ECHO "\
559247e89262Smrg      if test -n \"\$lt_option_debug\"; then
5593e6d2e958Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
559447e89262Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595bd1da9d7Smrg      fi
559647e89262Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559747e89262Smrg"
559847e89262Smrg    ;;
5599bd1da9d7Smrg
560047e89262Smrg  *)
560147e89262Smrg    $ECHO "\
560247e89262Smrg      if test -n \"\$lt_option_debug\"; then
5603e6d2e958Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
560447e89262Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605bd1da9d7Smrg      fi
560647e89262Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560747e89262Smrg"
560847e89262Smrg    ;;
560947e89262Smrg  esac
561047e89262Smrg  $ECHO "\
561147e89262Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
561247e89262Smrg      exit 1
561347e89262Smrg}
5614bd1da9d7Smrg
561547e89262Smrg# A function to encapsulate launching the target application
561647e89262Smrg# Strips options in the --lt-* namespace from \$@ and
561747e89262Smrg# launches target application with the remaining arguments.
561847e89262Smrgfunc_exec_program ()
561947e89262Smrg{
5620899129b3Smrg  case \" \$* \" in
5621899129b3Smrg  *\\ --lt-*)
5622899129b3Smrg    for lt_wr_arg
5623899129b3Smrg    do
5624899129b3Smrg      case \$lt_wr_arg in
5625899129b3Smrg      --lt-*) ;;
5626899129b3Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627899129b3Smrg      esac
5628899129b3Smrg      shift
5629899129b3Smrg    done ;;
5630899129b3Smrg  esac
563147e89262Smrg  func_exec_program_core \${1+\"\$@\"}
563247e89262Smrg}
5633bd1da9d7Smrg
563447e89262Smrg  # Parse options
563547e89262Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636bd1da9d7Smrg
563747e89262Smrg  # Find the directory that this script lives in.
563847e89262Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
563947e89262Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640bd1da9d7Smrg
564147e89262Smrg  # Follow symbolic links until we get to the real thisdir.
564247e89262Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
564347e89262Smrg  while test -n \"\$file\"; do
564447e89262Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645bd1da9d7Smrg
564647e89262Smrg    # If there was a directory component, then change thisdir.
564747e89262Smrg    if test \"x\$destdir\" != \"x\$file\"; then
564847e89262Smrg      case \"\$destdir\" in
564947e89262Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
565047e89262Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
565147e89262Smrg      esac
565247e89262Smrg    fi
5653bd1da9d7Smrg
565447e89262Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
565547e89262Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
565647e89262Smrg  done
5657bd1da9d7Smrg
565847e89262Smrg  # Usually 'no', except on cygwin/mingw when embedded into
565947e89262Smrg  # the cwrapper.
566047e89262Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
566147e89262Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
566247e89262Smrg    # special case for '.'
566347e89262Smrg    if test \"\$thisdir\" = \".\"; then
566447e89262Smrg      thisdir=\`pwd\`
566547e89262Smrg    fi
566647e89262Smrg    # remove .libs from thisdir
566747e89262Smrg    case \"\$thisdir\" in
566847e89262Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
566947e89262Smrg    $objdir )   thisdir=. ;;
567047e89262Smrg    esac
567147e89262Smrg  fi
5672bd1da9d7Smrg
567347e89262Smrg  # Try to get the absolute directory name.
567447e89262Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
567547e89262Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
567647e89262Smrg"
5677bd1da9d7Smrg
5678e6d2e958Smrg	if test yes = "$fast_install"; then
567947e89262Smrg	  $ECHO "\
568047e89262Smrg  program=lt-'$outputname'$exeext
568147e89262Smrg  progdir=\"\$thisdir/$objdir\"
5682bd1da9d7Smrg
568347e89262Smrg  if test ! -f \"\$progdir/\$program\" ||
5684e6d2e958Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
568547e89262Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686bd1da9d7Smrg
568747e89262Smrg    file=\"\$\$-\$program\"
5688bd1da9d7Smrg
568947e89262Smrg    if test ! -d \"\$progdir\"; then
569047e89262Smrg      $MKDIR \"\$progdir\"
569147e89262Smrg    else
569247e89262Smrg      $RM \"\$progdir/\$file\"
569347e89262Smrg    fi"
5694bd1da9d7Smrg
569547e89262Smrg	  $ECHO "\
5696bd1da9d7Smrg
569747e89262Smrg    # relink executable if necessary
569847e89262Smrg    if test -n \"\$relink_command\"; then
569947e89262Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
570047e89262Smrg      else
5701e6d2e958Smrg	\$ECHO \"\$relink_command_output\" >&2
570247e89262Smrg	$RM \"\$progdir/\$file\"
570347e89262Smrg	exit 1
570447e89262Smrg      fi
570547e89262Smrg    fi
5706bd1da9d7Smrg
570747e89262Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
570847e89262Smrg    { $RM \"\$progdir/\$program\";
570947e89262Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
571047e89262Smrg    $RM \"\$progdir/\$file\"
571147e89262Smrg  fi"
571247e89262Smrg	else
571347e89262Smrg	  $ECHO "\
571447e89262Smrg  program='$outputname'
571547e89262Smrg  progdir=\"\$thisdir/$objdir\"
571647e89262Smrg"
571747e89262Smrg	fi
5718bd1da9d7Smrg
571947e89262Smrg	$ECHO "\
5720bd1da9d7Smrg
572147e89262Smrg  if test -f \"\$progdir/\$program\"; then"
5722bd1da9d7Smrg
5723899129b3Smrg	# fixup the dll searchpath if we need to.
5724899129b3Smrg	#
5725899129b3Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726899129b3Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727899129b3Smrg	# libraries must come first.
5728899129b3Smrg	if test -n "$dllsearchpath"; then
5729899129b3Smrg	  $ECHO "\
5730899129b3Smrg    # Add the dll search path components to the executable PATH
5731899129b3Smrg    PATH=$dllsearchpath:\$PATH
5732899129b3Smrg"
5733899129b3Smrg	fi
5734899129b3Smrg
573547e89262Smrg	# Export our shlibpath_var if we have one.
5736e6d2e958Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
573747e89262Smrg	  $ECHO "\
573847e89262Smrg    # Add our own library path to $shlibpath_var
573947e89262Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740bd1da9d7Smrg
574147e89262Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
574247e89262Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
574347e89262Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744bd1da9d7Smrg
574547e89262Smrg    export $shlibpath_var
574647e89262Smrg"
574747e89262Smrg	fi
5748bd1da9d7Smrg
574947e89262Smrg	$ECHO "\
575047e89262Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
575147e89262Smrg      # Run the actual program with our arguments.
575247e89262Smrg      func_exec_program \${1+\"\$@\"}
575347e89262Smrg    fi
575447e89262Smrg  else
575547e89262Smrg    # The program doesn't exist.
5756e6d2e958Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
575747e89262Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575847e89262Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
575947e89262Smrg    exit 1
576047e89262Smrg  fi
576147e89262Smrgfi\
576247e89262Smrg"
576347e89262Smrg}
5764bd1da9d7Smrg
5765bd1da9d7Smrg
576647e89262Smrg# func_emit_cwrapperexe_src
576747e89262Smrg# emit the source code for a wrapper executable on stdout
576847e89262Smrg# Must ONLY be called from within func_mode_link because
576947e89262Smrg# it depends on a number of variable set therein.
577047e89262Smrgfunc_emit_cwrapperexe_src ()
577147e89262Smrg{
577247e89262Smrg	cat <<EOF
5773bd1da9d7Smrg
577447e89262Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775e6d2e958Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776bd1da9d7Smrg
577747e89262Smrg   The $output program cannot be directly executed until all the libtool
577847e89262Smrg   libraries that it depends on are installed.
5779bd1da9d7Smrg
578047e89262Smrg   This wrapper executable should never be moved out of the build directory.
578147e89262Smrg   If it is, it will not operate correctly.
578247e89262Smrg*/
578347e89262SmrgEOF
578447e89262Smrg	    cat <<"EOF"
578547e89262Smrg#ifdef _MSC_VER
578647e89262Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578747e89262Smrg#endif
578847e89262Smrg#include <stdio.h>
578947e89262Smrg#include <stdlib.h>
579047e89262Smrg#ifdef _MSC_VER
579147e89262Smrg# include <direct.h>
579247e89262Smrg# include <process.h>
579347e89262Smrg# include <io.h>
579447e89262Smrg#else
579547e89262Smrg# include <unistd.h>
579647e89262Smrg# include <stdint.h>
579747e89262Smrg# ifdef __CYGWIN__
579847e89262Smrg#  include <io.h>
579947e89262Smrg# endif
580047e89262Smrg#endif
580147e89262Smrg#include <malloc.h>
580247e89262Smrg#include <stdarg.h>
580347e89262Smrg#include <assert.h>
580447e89262Smrg#include <string.h>
580547e89262Smrg#include <ctype.h>
580647e89262Smrg#include <errno.h>
580747e89262Smrg#include <fcntl.h>
580847e89262Smrg#include <sys/stat.h>
5809bd1da9d7Smrg
5810e6d2e958Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811e6d2e958Smrg
581247e89262Smrg/* declarations of non-ANSI functions */
5813e6d2e958Smrg#if defined __MINGW32__
581447e89262Smrg# ifdef __STRICT_ANSI__
581547e89262Smrgint _putenv (const char *);
581647e89262Smrg# endif
5817e6d2e958Smrg#elif defined __CYGWIN__
581847e89262Smrg# ifdef __STRICT_ANSI__
581947e89262Smrgchar *realpath (const char *, char *);
582047e89262Smrgint putenv (char *);
582147e89262Smrgint setenv (const char *, const char *, int);
582247e89262Smrg# endif
5823e6d2e958Smrg/* #elif defined other_platform || defined ... */
582447e89262Smrg#endif
5825bd1da9d7Smrg
582647e89262Smrg/* portability defines, excluding path handling macros */
5827e6d2e958Smrg#if defined _MSC_VER
582847e89262Smrg# define setmode _setmode
582947e89262Smrg# define stat    _stat
583047e89262Smrg# define chmod   _chmod
583147e89262Smrg# define getcwd  _getcwd
583247e89262Smrg# define putenv  _putenv
583347e89262Smrg# define S_IXUSR _S_IEXEC
5834e6d2e958Smrg#elif defined __MINGW32__
583547e89262Smrg# define setmode _setmode
583647e89262Smrg# define stat    _stat
583747e89262Smrg# define chmod   _chmod
583847e89262Smrg# define getcwd  _getcwd
583947e89262Smrg# define putenv  _putenv
5840e6d2e958Smrg#elif defined __CYGWIN__
584147e89262Smrg# define HAVE_SETENV
584247e89262Smrg# define FOPEN_WB "wb"
5843e6d2e958Smrg/* #elif defined other platforms ... */
584447e89262Smrg#endif
5845bd1da9d7Smrg
5846e6d2e958Smrg#if defined PATH_MAX
584747e89262Smrg# define LT_PATHMAX PATH_MAX
5848e6d2e958Smrg#elif defined MAXPATHLEN
584947e89262Smrg# define LT_PATHMAX MAXPATHLEN
585047e89262Smrg#else
585147e89262Smrg# define LT_PATHMAX 1024
585247e89262Smrg#endif
5853bd1da9d7Smrg
585447e89262Smrg#ifndef S_IXOTH
585547e89262Smrg# define S_IXOTH 0
585647e89262Smrg#endif
585747e89262Smrg#ifndef S_IXGRP
585847e89262Smrg# define S_IXGRP 0
585947e89262Smrg#endif
5860bd1da9d7Smrg
586147e89262Smrg/* path handling portability macros */
586247e89262Smrg#ifndef DIR_SEPARATOR
586347e89262Smrg# define DIR_SEPARATOR '/'
586447e89262Smrg# define PATH_SEPARATOR ':'
586547e89262Smrg#endif
5866bd1da9d7Smrg
5867e6d2e958Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868e6d2e958Smrg  defined __OS2__
586947e89262Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
587047e89262Smrg# define FOPEN_WB "wb"
587147e89262Smrg# ifndef DIR_SEPARATOR_2
587247e89262Smrg#  define DIR_SEPARATOR_2 '\\'
587347e89262Smrg# endif
587447e89262Smrg# ifndef PATH_SEPARATOR_2
587547e89262Smrg#  define PATH_SEPARATOR_2 ';'
587647e89262Smrg# endif
587747e89262Smrg#endif
5878bd1da9d7Smrg
587947e89262Smrg#ifndef DIR_SEPARATOR_2
588047e89262Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
588147e89262Smrg#else /* DIR_SEPARATOR_2 */
588247e89262Smrg# define IS_DIR_SEPARATOR(ch) \
588347e89262Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
588447e89262Smrg#endif /* DIR_SEPARATOR_2 */
5885bd1da9d7Smrg
588647e89262Smrg#ifndef PATH_SEPARATOR_2
588747e89262Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
588847e89262Smrg#else /* PATH_SEPARATOR_2 */
588947e89262Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
589047e89262Smrg#endif /* PATH_SEPARATOR_2 */
589147e89262Smrg
589247e89262Smrg#ifndef FOPEN_WB
589347e89262Smrg# define FOPEN_WB "w"
589447e89262Smrg#endif
589547e89262Smrg#ifndef _O_BINARY
589647e89262Smrg# define _O_BINARY 0
589747e89262Smrg#endif
589847e89262Smrg
589947e89262Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
590047e89262Smrg#define XFREE(stale) do { \
5901e6d2e958Smrg  if (stale) { free (stale); stale = 0; } \
590247e89262Smrg} while (0)
590347e89262Smrg
5904e6d2e958Smrg#if defined LT_DEBUGWRAPPER
590547e89262Smrgstatic int lt_debug = 1;
590647e89262Smrg#else
590747e89262Smrgstatic int lt_debug = 0;
590847e89262Smrg#endif
590947e89262Smrg
591047e89262Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
591147e89262Smrg
591247e89262Smrgvoid *xmalloc (size_t num);
591347e89262Smrgchar *xstrdup (const char *string);
591447e89262Smrgconst char *base_name (const char *name);
591547e89262Smrgchar *find_executable (const char *wrapper);
591647e89262Smrgchar *chase_symlinks (const char *pathspec);
591747e89262Smrgint make_executable (const char *path);
591847e89262Smrgint check_executable (const char *path);
591947e89262Smrgchar *strendzap (char *str, const char *pat);
592047e89262Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
592147e89262Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
592247e89262Smrgstatic const char *nonnull (const char *s);
592347e89262Smrgstatic const char *nonempty (const char *s);
592447e89262Smrgvoid lt_setenv (const char *name, const char *value);
592547e89262Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
592647e89262Smrgvoid lt_update_exe_path (const char *name, const char *value);
592747e89262Smrgvoid lt_update_lib_path (const char *name, const char *value);
592847e89262Smrgchar **prepare_spawn (char **argv);
592947e89262Smrgvoid lt_dump_script (FILE *f);
593047e89262SmrgEOF
593147e89262Smrg
593247e89262Smrg	    cat <<EOF
5933e6d2e958Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934e6d2e958Smrg# define externally_visible volatile
5935e6d2e958Smrg#else
5936e6d2e958Smrg# define externally_visible __attribute__((externally_visible)) volatile
5937e6d2e958Smrg#endif
5938e6d2e958Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
593947e89262Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
594047e89262SmrgEOF
594147e89262Smrg
5942e6d2e958Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943899129b3Smrg              func_to_host_path "$temp_rpath"
594447e89262Smrg	      cat <<EOF
5945899129b3Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946bd1da9d7SmrgEOF
5947bd1da9d7Smrg	    else
594847e89262Smrg	      cat <<"EOF"
594947e89262Smrgconst char * LIB_PATH_VALUE   = "";
595047e89262SmrgEOF
5951bd1da9d7Smrg	    fi
595247e89262Smrg
595347e89262Smrg	    if test -n "$dllsearchpath"; then
5954899129b3Smrg              func_to_host_path "$dllsearchpath:"
595547e89262Smrg	      cat <<EOF
595647e89262Smrgconst char * EXE_PATH_VARNAME = "PATH";
5957899129b3Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
595847e89262SmrgEOF
5959bd1da9d7Smrg	    else
596047e89262Smrg	      cat <<"EOF"
596147e89262Smrgconst char * EXE_PATH_VARNAME = "";
596247e89262Smrgconst char * EXE_PATH_VALUE   = "";
596347e89262SmrgEOF
5964bd1da9d7Smrg	    fi
596547e89262Smrg
5966e6d2e958Smrg	    if test yes = "$fast_install"; then
596747e89262Smrg	      cat <<EOF
596847e89262Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
596947e89262SmrgEOF
5970bd1da9d7Smrg	    else
597147e89262Smrg	      cat <<EOF
597247e89262Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
597347e89262SmrgEOF
5974bd1da9d7Smrg	    fi
5975bd1da9d7Smrg
5976bd1da9d7Smrg
597747e89262Smrg	    cat <<"EOF"
5978bd1da9d7Smrg
597947e89262Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980bd1da9d7Smrg
598147e89262Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
598247e89262Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
598347e89262Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984bd1da9d7Smrg
598547e89262Smrgint
598647e89262Smrgmain (int argc, char *argv[])
598747e89262Smrg{
598847e89262Smrg  char **newargz;
598947e89262Smrg  int  newargc;
599047e89262Smrg  char *tmp_pathspec;
599147e89262Smrg  char *actual_cwrapper_path;
599247e89262Smrg  char *actual_cwrapper_name;
599347e89262Smrg  char *target_name;
599447e89262Smrg  char *lt_argv_zero;
5995e6d2e958Smrg  int rval = 127;
5996bd1da9d7Smrg
599747e89262Smrg  int i;
5998bd1da9d7Smrg
599947e89262Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000e6d2e958Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001bd1da9d7Smrg
600247e89262Smrg  /* very simple arg parsing; don't want to rely on getopt
600347e89262Smrg   * also, copy all non cwrapper options to newargz, except
600447e89262Smrg   * argz[0], which is handled differently
600547e89262Smrg   */
600647e89262Smrg  newargc=0;
600747e89262Smrg  for (i = 1; i < argc; i++)
600847e89262Smrg    {
6009e6d2e958Smrg      if (STREQ (argv[i], dumpscript_opt))
601047e89262Smrg	{
601147e89262SmrgEOF
6012e6d2e958Smrg	    case $host in
601347e89262Smrg	      *mingw* | *cygwin* )
601447e89262Smrg		# make stdout use "unix" line endings
601547e89262Smrg		echo "          setmode(1,_O_BINARY);"
601647e89262Smrg		;;
60175bcb6992Smrg	      esac
6018bd1da9d7Smrg
601947e89262Smrg	    cat <<"EOF"
602047e89262Smrg	  lt_dump_script (stdout);
602147e89262Smrg	  return 0;
602247e89262Smrg	}
6023e6d2e958Smrg      if (STREQ (argv[i], debug_opt))
602447e89262Smrg	{
602547e89262Smrg          lt_debug = 1;
602647e89262Smrg          continue;
602747e89262Smrg	}
6028e6d2e958Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602947e89262Smrg        {
603047e89262Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
603147e89262Smrg             namespace, but it is not one of the ones we know about and
603247e89262Smrg             have already dealt with, above (inluding dump-script), then
603347e89262Smrg             report an error. Otherwise, targets might begin to believe
603447e89262Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
603547e89262Smrg             namespace. The first time any user complains about this, we'll
603647e89262Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603747e89262Smrg             or a configure.ac-settable value.
603847e89262Smrg           */
603947e89262Smrg          lt_fatal (__FILE__, __LINE__,
604047e89262Smrg		    "unrecognized %s option: '%s'",
604147e89262Smrg                    ltwrapper_option_prefix, argv[i]);
604247e89262Smrg        }
604347e89262Smrg      /* otherwise ... */
604447e89262Smrg      newargz[++newargc] = xstrdup (argv[i]);
604547e89262Smrg    }
604647e89262Smrg  newargz[++newargc] = NULL;
6047bd1da9d7Smrg
604847e89262SmrgEOF
604947e89262Smrg	    cat <<EOF
605047e89262Smrg  /* The GNU banner must be the first non-error debug message */
6051e6d2e958Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
605247e89262SmrgEOF
605347e89262Smrg	    cat <<"EOF"
605447e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
605547e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
605647e89262Smrg
605747e89262Smrg  tmp_pathspec = find_executable (argv[0]);
605847e89262Smrg  if (tmp_pathspec == NULL)
605947e89262Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
606047e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
606147e89262Smrg                  "(main) found exe (before symlink chase) at: %s\n",
606247e89262Smrg		  tmp_pathspec);
606347e89262Smrg
606447e89262Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
606547e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
606647e89262Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606747e89262Smrg		  actual_cwrapper_path);
606847e89262Smrg  XFREE (tmp_pathspec);
606947e89262Smrg
607047e89262Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
607147e89262Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
607247e89262Smrg
607347e89262Smrg  /* wrapper name transforms */
607447e89262Smrg  strendzap (actual_cwrapper_name, ".exe");
607547e89262Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
607647e89262Smrg  XFREE (actual_cwrapper_name);
607747e89262Smrg  actual_cwrapper_name = tmp_pathspec;
607847e89262Smrg  tmp_pathspec = 0;
607947e89262Smrg
608047e89262Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
608147e89262Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
608247e89262Smrg  strendzap (target_name, ".exe");
608347e89262Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
608447e89262Smrg  XFREE (target_name);
608547e89262Smrg  target_name = tmp_pathspec;
608647e89262Smrg  tmp_pathspec = 0;
608747e89262Smrg
608847e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
608947e89262Smrg		  "(main) libtool target name: %s\n",
609047e89262Smrg		  target_name);
609147e89262SmrgEOF
6092bd1da9d7Smrg
609347e89262Smrg	    cat <<EOF
609447e89262Smrg  newargz[0] =
609547e89262Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
609647e89262Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
609747e89262Smrg  strcpy (newargz[0], actual_cwrapper_path);
609847e89262Smrg  strcat (newargz[0], "$objdir");
609947e89262Smrg  strcat (newargz[0], "/");
610047e89262SmrgEOF
6101bd1da9d7Smrg
610247e89262Smrg	    cat <<"EOF"
610347e89262Smrg  /* stop here, and copy so we don't have to do this twice */
610447e89262Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105bd1da9d7Smrg
610647e89262Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
610747e89262Smrg  strcat (newargz[0], actual_cwrapper_name);
6108bd1da9d7Smrg
610947e89262Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
611047e89262Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
611147e89262Smrg  XFREE (tmp_pathspec);
611247e89262Smrg  tmp_pathspec = NULL;
611347e89262SmrgEOF
6114bd1da9d7Smrg
611547e89262Smrg	    case $host_os in
611647e89262Smrg	      mingw*)
611747e89262Smrg	    cat <<"EOF"
611847e89262Smrg  {
611947e89262Smrg    char* p;
612047e89262Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
612147e89262Smrg      {
612247e89262Smrg	*p = '/';
612347e89262Smrg      }
612447e89262Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
612547e89262Smrg      {
612647e89262Smrg	*p = '/';
612747e89262Smrg      }
612847e89262Smrg  }
612947e89262SmrgEOF
613047e89262Smrg	    ;;
613147e89262Smrg	    esac
6132bd1da9d7Smrg
613347e89262Smrg	    cat <<"EOF"
613447e89262Smrg  XFREE (target_name);
613547e89262Smrg  XFREE (actual_cwrapper_path);
613647e89262Smrg  XFREE (actual_cwrapper_name);
6137bd1da9d7Smrg
613847e89262Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
613947e89262Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140899129b3Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141899129b3Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142899129b3Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143899129b3Smrg     libraries must come first. */
614447e89262Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145899129b3Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146bd1da9d7Smrg
614747e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614847e89262Smrg		  nonnull (lt_argv_zero));
614947e89262Smrg  for (i = 0; i < newargc; i++)
615047e89262Smrg    {
615147e89262Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
615247e89262Smrg		      i, nonnull (newargz[i]));
615347e89262Smrg    }
6154bd1da9d7Smrg
615547e89262SmrgEOF
6156bd1da9d7Smrg
615747e89262Smrg	    case $host_os in
615847e89262Smrg	      mingw*)
615947e89262Smrg		cat <<"EOF"
616047e89262Smrg  /* execv doesn't actually work on mingw as expected on unix */
616147e89262Smrg  newargz = prepare_spawn (newargz);
6162e6d2e958Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
616347e89262Smrg  if (rval == -1)
616447e89262Smrg    {
616547e89262Smrg      /* failed to start process */
616647e89262Smrg      lt_debugprintf (__FILE__, __LINE__,
616747e89262Smrg		      "(main) failed to launch target \"%s\": %s\n",
616847e89262Smrg		      lt_argv_zero, nonnull (strerror (errno)));
616947e89262Smrg      return 127;
617047e89262Smrg    }
617147e89262Smrg  return rval;
617247e89262SmrgEOF
617347e89262Smrg		;;
617447e89262Smrg	      *)
617547e89262Smrg		cat <<"EOF"
617647e89262Smrg  execv (lt_argv_zero, newargz);
617747e89262Smrg  return rval; /* =127, but avoids unused variable warning */
617847e89262SmrgEOF
617947e89262Smrg		;;
618047e89262Smrg	    esac
6181bd1da9d7Smrg
618247e89262Smrg	    cat <<"EOF"
618347e89262Smrg}
6184bd1da9d7Smrg
618547e89262Smrgvoid *
618647e89262Smrgxmalloc (size_t num)
618747e89262Smrg{
618847e89262Smrg  void *p = (void *) malloc (num);
618947e89262Smrg  if (!p)
619047e89262Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191bd1da9d7Smrg
619247e89262Smrg  return p;
619347e89262Smrg}
6194bd1da9d7Smrg
619547e89262Smrgchar *
619647e89262Smrgxstrdup (const char *string)
619747e89262Smrg{
619847e89262Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
619947e89262Smrg			  string) : NULL;
620047e89262Smrg}
6201bd1da9d7Smrg
620247e89262Smrgconst char *
620347e89262Smrgbase_name (const char *name)
620447e89262Smrg{
620547e89262Smrg  const char *base;
6206bd1da9d7Smrg
6207e6d2e958Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
620847e89262Smrg  /* Skip over the disk name in MSDOS pathnames. */
620947e89262Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
621047e89262Smrg    name += 2;
621147e89262Smrg#endif
6212bd1da9d7Smrg
621347e89262Smrg  for (base = name; *name; name++)
621447e89262Smrg    if (IS_DIR_SEPARATOR (*name))
621547e89262Smrg      base = name + 1;
621647e89262Smrg  return base;
621747e89262Smrg}
6218bd1da9d7Smrg
621947e89262Smrgint
622047e89262Smrgcheck_executable (const char *path)
622147e89262Smrg{
622247e89262Smrg  struct stat st;
6223bd1da9d7Smrg
622447e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
622547e89262Smrg                  nonempty (path));
622647e89262Smrg  if ((!path) || (!*path))
622747e89262Smrg    return 0;
6228bd1da9d7Smrg
622947e89262Smrg  if ((stat (path, &st) >= 0)
623047e89262Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
623147e89262Smrg    return 1;
623247e89262Smrg  else
623347e89262Smrg    return 0;
623447e89262Smrg}
6235bd1da9d7Smrg
623647e89262Smrgint
623747e89262Smrgmake_executable (const char *path)
623847e89262Smrg{
623947e89262Smrg  int rval = 0;
624047e89262Smrg  struct stat st;
6241bd1da9d7Smrg
624247e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
624347e89262Smrg                  nonempty (path));
624447e89262Smrg  if ((!path) || (!*path))
624547e89262Smrg    return 0;
6246bd1da9d7Smrg
624747e89262Smrg  if (stat (path, &st) >= 0)
624847e89262Smrg    {
624947e89262Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
625047e89262Smrg    }
625147e89262Smrg  return rval;
625247e89262Smrg}
6253bd1da9d7Smrg
625447e89262Smrg/* Searches for the full path of the wrapper.  Returns
625547e89262Smrg   newly allocated full path name if found, NULL otherwise
625647e89262Smrg   Does not chase symlinks, even on platforms that support them.
625747e89262Smrg*/
625847e89262Smrgchar *
625947e89262Smrgfind_executable (const char *wrapper)
626047e89262Smrg{
626147e89262Smrg  int has_slash = 0;
626247e89262Smrg  const char *p;
626347e89262Smrg  const char *p_next;
626447e89262Smrg  /* static buffer for getcwd */
626547e89262Smrg  char tmp[LT_PATHMAX + 1];
6266e6d2e958Smrg  size_t tmp_len;
626747e89262Smrg  char *concat_name;
6268bd1da9d7Smrg
626947e89262Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
627047e89262Smrg                  nonempty (wrapper));
6271bd1da9d7Smrg
627247e89262Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
627347e89262Smrg    return NULL;
6274bd1da9d7Smrg
627547e89262Smrg  /* Absolute path? */
6276e6d2e958Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
627747e89262Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
627847e89262Smrg    {
627947e89262Smrg      concat_name = xstrdup (wrapper);
628047e89262Smrg      if (check_executable (concat_name))
628147e89262Smrg	return concat_name;
628247e89262Smrg      XFREE (concat_name);
628347e89262Smrg    }
628447e89262Smrg  else
628547e89262Smrg    {
628647e89262Smrg#endif
628747e89262Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
628847e89262Smrg	{
628947e89262Smrg	  concat_name = xstrdup (wrapper);
629047e89262Smrg	  if (check_executable (concat_name))
629147e89262Smrg	    return concat_name;
629247e89262Smrg	  XFREE (concat_name);
629347e89262Smrg	}
6294e6d2e958Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
629547e89262Smrg    }
629647e89262Smrg#endif
6297bd1da9d7Smrg
629847e89262Smrg  for (p = wrapper; *p; p++)
629947e89262Smrg    if (*p == '/')
630047e89262Smrg      {
630147e89262Smrg	has_slash = 1;
630247e89262Smrg	break;
630347e89262Smrg      }
630447e89262Smrg  if (!has_slash)
630547e89262Smrg    {
630647e89262Smrg      /* no slashes; search PATH */
630747e89262Smrg      const char *path = getenv ("PATH");
630847e89262Smrg      if (path != NULL)
630947e89262Smrg	{
631047e89262Smrg	  for (p = path; *p; p = p_next)
631147e89262Smrg	    {
631247e89262Smrg	      const char *q;
631347e89262Smrg	      size_t p_len;
631447e89262Smrg	      for (q = p; *q; q++)
631547e89262Smrg		if (IS_PATH_SEPARATOR (*q))
631647e89262Smrg		  break;
6317e6d2e958Smrg	      p_len = (size_t) (q - p);
631847e89262Smrg	      p_next = (*q == '\0' ? q : q + 1);
631947e89262Smrg	      if (p_len == 0)
632047e89262Smrg		{
632147e89262Smrg		  /* empty path: current directory */
632247e89262Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
632347e89262Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
632447e89262Smrg                              nonnull (strerror (errno)));
632547e89262Smrg		  tmp_len = strlen (tmp);
632647e89262Smrg		  concat_name =
632747e89262Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
632847e89262Smrg		  memcpy (concat_name, tmp, tmp_len);
632947e89262Smrg		  concat_name[tmp_len] = '/';
633047e89262Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
633147e89262Smrg		}
633247e89262Smrg	      else
633347e89262Smrg		{
633447e89262Smrg		  concat_name =
633547e89262Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
633647e89262Smrg		  memcpy (concat_name, p, p_len);
633747e89262Smrg		  concat_name[p_len] = '/';
633847e89262Smrg		  strcpy (concat_name + p_len + 1, wrapper);
633947e89262Smrg		}
634047e89262Smrg	      if (check_executable (concat_name))
634147e89262Smrg		return concat_name;
634247e89262Smrg	      XFREE (concat_name);
634347e89262Smrg	    }
634447e89262Smrg	}
634547e89262Smrg      /* not found in PATH; assume curdir */
634647e89262Smrg    }
634747e89262Smrg  /* Relative path | not found in path: prepend cwd */
634847e89262Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634947e89262Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
635047e89262Smrg              nonnull (strerror (errno)));
635147e89262Smrg  tmp_len = strlen (tmp);
635247e89262Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
635347e89262Smrg  memcpy (concat_name, tmp, tmp_len);
635447e89262Smrg  concat_name[tmp_len] = '/';
635547e89262Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356bd1da9d7Smrg
635747e89262Smrg  if (check_executable (concat_name))
635847e89262Smrg    return concat_name;
635947e89262Smrg  XFREE (concat_name);
636047e89262Smrg  return NULL;
636147e89262Smrg}
6362bd1da9d7Smrg
636347e89262Smrgchar *
636447e89262Smrgchase_symlinks (const char *pathspec)
636547e89262Smrg{
636647e89262Smrg#ifndef S_ISLNK
636747e89262Smrg  return xstrdup (pathspec);
636847e89262Smrg#else
636947e89262Smrg  char buf[LT_PATHMAX];
637047e89262Smrg  struct stat s;
637147e89262Smrg  char *tmp_pathspec = xstrdup (pathspec);
637247e89262Smrg  char *p;
637347e89262Smrg  int has_symlinks = 0;
637447e89262Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
637547e89262Smrg    {
637647e89262Smrg      lt_debugprintf (__FILE__, __LINE__,
637747e89262Smrg		      "checking path component for symlinks: %s\n",
637847e89262Smrg		      tmp_pathspec);
637947e89262Smrg      if (lstat (tmp_pathspec, &s) == 0)
638047e89262Smrg	{
638147e89262Smrg	  if (S_ISLNK (s.st_mode) != 0)
638247e89262Smrg	    {
638347e89262Smrg	      has_symlinks = 1;
638447e89262Smrg	      break;
638547e89262Smrg	    }
6386bd1da9d7Smrg
638747e89262Smrg	  /* search backwards for last DIR_SEPARATOR */
638847e89262Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
638947e89262Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639047e89262Smrg	    p--;
639147e89262Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639247e89262Smrg	    {
639347e89262Smrg	      /* no more DIR_SEPARATORS left */
639447e89262Smrg	      break;
639547e89262Smrg	    }
639647e89262Smrg	  *p = '\0';
639747e89262Smrg	}
639847e89262Smrg      else
639947e89262Smrg	{
640047e89262Smrg	  lt_fatal (__FILE__, __LINE__,
640147e89262Smrg		    "error accessing file \"%s\": %s",
640247e89262Smrg		    tmp_pathspec, nonnull (strerror (errno)));
640347e89262Smrg	}
640447e89262Smrg    }
640547e89262Smrg  XFREE (tmp_pathspec);
6406bd1da9d7Smrg
640747e89262Smrg  if (!has_symlinks)
640847e89262Smrg    {
640947e89262Smrg      return xstrdup (pathspec);
641047e89262Smrg    }
6411bd1da9d7Smrg
641247e89262Smrg  tmp_pathspec = realpath (pathspec, buf);
641347e89262Smrg  if (tmp_pathspec == 0)
641447e89262Smrg    {
641547e89262Smrg      lt_fatal (__FILE__, __LINE__,
641647e89262Smrg		"could not follow symlinks for %s", pathspec);
641747e89262Smrg    }
641847e89262Smrg  return xstrdup (tmp_pathspec);
641947e89262Smrg#endif
642047e89262Smrg}
6421bd1da9d7Smrg
642247e89262Smrgchar *
642347e89262Smrgstrendzap (char *str, const char *pat)
642447e89262Smrg{
642547e89262Smrg  size_t len, patlen;
6426bd1da9d7Smrg
642747e89262Smrg  assert (str != NULL);
642847e89262Smrg  assert (pat != NULL);
6429bd1da9d7Smrg
643047e89262Smrg  len = strlen (str);
643147e89262Smrg  patlen = strlen (pat);
6432bd1da9d7Smrg
643347e89262Smrg  if (patlen <= len)
643447e89262Smrg    {
643547e89262Smrg      str += len - patlen;
6436e6d2e958Smrg      if (STREQ (str, pat))
643747e89262Smrg	*str = '\0';
643847e89262Smrg    }
643947e89262Smrg  return str;
644047e89262Smrg}
6441bd1da9d7Smrg
644247e89262Smrgvoid
644347e89262Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
644447e89262Smrg{
644547e89262Smrg  va_list args;
644647e89262Smrg  if (lt_debug)
644747e89262Smrg    {
644847e89262Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644947e89262Smrg      va_start (args, fmt);
645047e89262Smrg      (void) vfprintf (stderr, fmt, args);
645147e89262Smrg      va_end (args);
645247e89262Smrg    }
645347e89262Smrg}
6454bd1da9d7Smrg
645547e89262Smrgstatic void
645647e89262Smrglt_error_core (int exit_status, const char *file,
645747e89262Smrg	       int line, const char *mode,
645847e89262Smrg	       const char *message, va_list ap)
645947e89262Smrg{
646047e89262Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
646147e89262Smrg  vfprintf (stderr, message, ap);
646247e89262Smrg  fprintf (stderr, ".\n");
6463bd1da9d7Smrg
646447e89262Smrg  if (exit_status >= 0)
646547e89262Smrg    exit (exit_status);
646647e89262Smrg}
6467bd1da9d7Smrg
646847e89262Smrgvoid
646947e89262Smrglt_fatal (const char *file, int line, const char *message, ...)
647047e89262Smrg{
647147e89262Smrg  va_list ap;
647247e89262Smrg  va_start (ap, message);
647347e89262Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
647447e89262Smrg  va_end (ap);
647547e89262Smrg}
6476bd1da9d7Smrg
647747e89262Smrgstatic const char *
647847e89262Smrgnonnull (const char *s)
647947e89262Smrg{
648047e89262Smrg  return s ? s : "(null)";
648147e89262Smrg}
6482bd1da9d7Smrg
648347e89262Smrgstatic const char *
648447e89262Smrgnonempty (const char *s)
648547e89262Smrg{
648647e89262Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648747e89262Smrg}
6488bd1da9d7Smrg
648947e89262Smrgvoid
649047e89262Smrglt_setenv (const char *name, const char *value)
649147e89262Smrg{
649247e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
649347e89262Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
649447e89262Smrg                  nonnull (name), nonnull (value));
649547e89262Smrg  {
649647e89262Smrg#ifdef HAVE_SETENV
649747e89262Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
649847e89262Smrg    char *str = xstrdup (value);
649947e89262Smrg    setenv (name, str, 1);
650047e89262Smrg#else
6501e6d2e958Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
650247e89262Smrg    char *str = XMALLOC (char, len);
650347e89262Smrg    sprintf (str, "%s=%s", name, value);
650447e89262Smrg    if (putenv (str) != EXIT_SUCCESS)
650547e89262Smrg      {
650647e89262Smrg        XFREE (str);
650747e89262Smrg      }
650847e89262Smrg#endif
650947e89262Smrg  }
651047e89262Smrg}
6511bd1da9d7Smrg
651247e89262Smrgchar *
651347e89262Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
651447e89262Smrg{
651547e89262Smrg  char *new_value;
651647e89262Smrg  if (orig_value && *orig_value)
651747e89262Smrg    {
6518e6d2e958Smrg      size_t orig_value_len = strlen (orig_value);
6519e6d2e958Smrg      size_t add_len = strlen (add);
652047e89262Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
652147e89262Smrg      if (to_end)
652247e89262Smrg        {
652347e89262Smrg          strcpy (new_value, orig_value);
652447e89262Smrg          strcpy (new_value + orig_value_len, add);
652547e89262Smrg        }
652647e89262Smrg      else
652747e89262Smrg        {
652847e89262Smrg          strcpy (new_value, add);
652947e89262Smrg          strcpy (new_value + add_len, orig_value);
653047e89262Smrg        }
653147e89262Smrg    }
653247e89262Smrg  else
653347e89262Smrg    {
653447e89262Smrg      new_value = xstrdup (add);
653547e89262Smrg    }
653647e89262Smrg  return new_value;
653747e89262Smrg}
6538bd1da9d7Smrg
653947e89262Smrgvoid
654047e89262Smrglt_update_exe_path (const char *name, const char *value)
654147e89262Smrg{
654247e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
654347e89262Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
654447e89262Smrg                  nonnull (name), nonnull (value));
6545bd1da9d7Smrg
654647e89262Smrg  if (name && *name && value && *value)
654747e89262Smrg    {
654847e89262Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
654947e89262Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550e6d2e958Smrg      size_t len = strlen (new_value);
6551e6d2e958Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
655247e89262Smrg        {
6553e6d2e958Smrg          new_value[--len] = '\0';
655447e89262Smrg        }
655547e89262Smrg      lt_setenv (name, new_value);
655647e89262Smrg      XFREE (new_value);
655747e89262Smrg    }
655847e89262Smrg}
6559bd1da9d7Smrg
656047e89262Smrgvoid
656147e89262Smrglt_update_lib_path (const char *name, const char *value)
656247e89262Smrg{
656347e89262Smrg  lt_debugprintf (__FILE__, __LINE__,
656447e89262Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
656547e89262Smrg                  nonnull (name), nonnull (value));
6566bd1da9d7Smrg
656747e89262Smrg  if (name && *name && value && *value)
656847e89262Smrg    {
656947e89262Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
657047e89262Smrg      lt_setenv (name, new_value);
657147e89262Smrg      XFREE (new_value);
657247e89262Smrg    }
657347e89262Smrg}
6574bd1da9d7Smrg
657547e89262SmrgEOF
657647e89262Smrg	    case $host_os in
657747e89262Smrg	      mingw*)
657847e89262Smrg		cat <<"EOF"
657947e89262Smrg
658047e89262Smrg/* Prepares an argument vector before calling spawn().
658147e89262Smrg   Note that spawn() does not by itself call the command interpreter
658247e89262Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
658347e89262Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
658447e89262Smrg         GetVersionEx(&v);
658547e89262Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
658647e89262Smrg      }) ? "cmd.exe" : "command.com").
658747e89262Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658847e89262Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658947e89262Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
659047e89262Smrg   special way:
659147e89262Smrg   - Space and tab are interpreted as delimiters. They are not treated as
659247e89262Smrg     delimiters if they are surrounded by double quotes: "...".
659347e89262Smrg   - Unescaped double quotes are removed from the input. Their only effect is
659447e89262Smrg     that within double quotes, space and tab are treated like normal
659547e89262Smrg     characters.
659647e89262Smrg   - Backslashes not followed by double quotes are not special.
659747e89262Smrg   - But 2*n+1 backslashes followed by a double quote become
659847e89262Smrg     n backslashes followed by a double quote (n >= 0):
659947e89262Smrg       \" -> "
660047e89262Smrg       \\\" -> \"
660147e89262Smrg       \\\\\" -> \\"
660247e89262Smrg */
660347e89262Smrg#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"
660447e89262Smrg#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"
660547e89262Smrgchar **
660647e89262Smrgprepare_spawn (char **argv)
660747e89262Smrg{
660847e89262Smrg  size_t argc;
660947e89262Smrg  char **new_argv;
661047e89262Smrg  size_t i;
6611bd1da9d7Smrg
661247e89262Smrg  /* Count number of arguments.  */
661347e89262Smrg  for (argc = 0; argv[argc] != NULL; argc++)
661447e89262Smrg    ;
6615bd1da9d7Smrg
661647e89262Smrg  /* Allocate new argument vector.  */
661747e89262Smrg  new_argv = XMALLOC (char *, argc + 1);
6618bd1da9d7Smrg
661947e89262Smrg  /* Put quoted arguments into the new argument vector.  */
662047e89262Smrg  for (i = 0; i < argc; i++)
662147e89262Smrg    {
662247e89262Smrg      const char *string = argv[i];
662347e89262Smrg
662447e89262Smrg      if (string[0] == '\0')
662547e89262Smrg	new_argv[i] = xstrdup ("\"\"");
662647e89262Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662747e89262Smrg	{
662847e89262Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662947e89262Smrg	  size_t length;
663047e89262Smrg	  unsigned int backslashes;
663147e89262Smrg	  const char *s;
663247e89262Smrg	  char *quoted_string;
663347e89262Smrg	  char *p;
663447e89262Smrg
663547e89262Smrg	  length = 0;
663647e89262Smrg	  backslashes = 0;
663747e89262Smrg	  if (quote_around)
663847e89262Smrg	    length++;
663947e89262Smrg	  for (s = string; *s != '\0'; s++)
664047e89262Smrg	    {
664147e89262Smrg	      char c = *s;
664247e89262Smrg	      if (c == '"')
664347e89262Smrg		length += backslashes + 1;
664447e89262Smrg	      length++;
664547e89262Smrg	      if (c == '\\')
664647e89262Smrg		backslashes++;
664747e89262Smrg	      else
664847e89262Smrg		backslashes = 0;
664947e89262Smrg	    }
665047e89262Smrg	  if (quote_around)
665147e89262Smrg	    length += backslashes + 1;
665247e89262Smrg
665347e89262Smrg	  quoted_string = XMALLOC (char, length + 1);
665447e89262Smrg
665547e89262Smrg	  p = quoted_string;
665647e89262Smrg	  backslashes = 0;
665747e89262Smrg	  if (quote_around)
665847e89262Smrg	    *p++ = '"';
665947e89262Smrg	  for (s = string; *s != '\0'; s++)
666047e89262Smrg	    {
666147e89262Smrg	      char c = *s;
666247e89262Smrg	      if (c == '"')
666347e89262Smrg		{
666447e89262Smrg		  unsigned int j;
666547e89262Smrg		  for (j = backslashes + 1; j > 0; j--)
666647e89262Smrg		    *p++ = '\\';
666747e89262Smrg		}
666847e89262Smrg	      *p++ = c;
666947e89262Smrg	      if (c == '\\')
667047e89262Smrg		backslashes++;
667147e89262Smrg	      else
667247e89262Smrg		backslashes = 0;
667347e89262Smrg	    }
667447e89262Smrg	  if (quote_around)
667547e89262Smrg	    {
667647e89262Smrg	      unsigned int j;
667747e89262Smrg	      for (j = backslashes; j > 0; j--)
667847e89262Smrg		*p++ = '\\';
667947e89262Smrg	      *p++ = '"';
668047e89262Smrg	    }
668147e89262Smrg	  *p = '\0';
6682bd1da9d7Smrg
668347e89262Smrg	  new_argv[i] = quoted_string;
668447e89262Smrg	}
668547e89262Smrg      else
668647e89262Smrg	new_argv[i] = (char *) string;
668747e89262Smrg    }
668847e89262Smrg  new_argv[argc] = NULL;
6689bd1da9d7Smrg
669047e89262Smrg  return new_argv;
669147e89262Smrg}
669247e89262SmrgEOF
6693bd1da9d7Smrg		;;
669447e89262Smrg	    esac
6695bd1da9d7Smrg
669647e89262Smrg            cat <<"EOF"
669747e89262Smrgvoid lt_dump_script (FILE* f)
669847e89262Smrg{
669947e89262SmrgEOF
670047e89262Smrg	    func_emit_wrapper yes |
6701899129b3Smrg	      $SED -n -e '
6702899129b3Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703899129b3Smrg\2/
6704899129b3Smrgh
6705899129b3Smrgs/\([\\"]\)/\\\1/g
6706899129b3Smrgs/$/\\n/
6707899129b3Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708899129b3Smrgg
6709899129b3SmrgD'
671047e89262Smrg            cat <<"EOF"
671147e89262Smrg}
671247e89262SmrgEOF
671347e89262Smrg}
671447e89262Smrg# end: func_emit_cwrapperexe_src
6715bd1da9d7Smrg
671647e89262Smrg# func_win32_import_lib_p ARG
671747e89262Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671847e89262Smrgfunc_win32_import_lib_p ()
671947e89262Smrg{
6720e6d2e958Smrg    $debug_cmd
6721e6d2e958Smrg
672247e89262Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
672347e89262Smrg    *import*) : ;;
672447e89262Smrg    *) false ;;
672547e89262Smrg    esac
672647e89262Smrg}
6727bd1da9d7Smrg
6728e6d2e958Smrg# func_suncc_cstd_abi
6729e6d2e958Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730e6d2e958Smrg# Several compiler flags select an ABI that is incompatible with the
6731e6d2e958Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732e6d2e958Smrgfunc_suncc_cstd_abi ()
6733e6d2e958Smrg{
6734e6d2e958Smrg    $debug_cmd
6735e6d2e958Smrg
6736e6d2e958Smrg    case " $compile_command " in
6737e6d2e958Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738e6d2e958Smrg      suncc_use_cstd_abi=no
6739e6d2e958Smrg      ;;
6740e6d2e958Smrg    *)
6741e6d2e958Smrg      suncc_use_cstd_abi=yes
6742e6d2e958Smrg      ;;
6743e6d2e958Smrg    esac
6744e6d2e958Smrg}
6745e6d2e958Smrg
674647e89262Smrg# func_mode_link arg...
674747e89262Smrgfunc_mode_link ()
674847e89262Smrg{
6749e6d2e958Smrg    $debug_cmd
6750e6d2e958Smrg
675147e89262Smrg    case $host in
675247e89262Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
675347e89262Smrg      # It is impossible to link a dll without this setting, and
675447e89262Smrg      # we shouldn't force the makefile maintainer to figure out
6755e6d2e958Smrg      # what system we are compiling for in order to pass an extra
675647e89262Smrg      # flag for every libtool invocation.
675747e89262Smrg      # allow_undefined=no
6758bd1da9d7Smrg
675947e89262Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760e6d2e958Smrg      # to make a dll that has undefined symbols, in which case not
676147e89262Smrg      # even a static library is built.  For now, we need to specify
676247e89262Smrg      # -no-undefined on the libtool link line when we can be certain
676347e89262Smrg      # that all symbols are satisfied, otherwise we get a static library.
676447e89262Smrg      allow_undefined=yes
676547e89262Smrg      ;;
676647e89262Smrg    *)
676747e89262Smrg      allow_undefined=yes
676847e89262Smrg      ;;
676947e89262Smrg    esac
677047e89262Smrg    libtool_args=$nonopt
677147e89262Smrg    base_compile="$nonopt $@"
677247e89262Smrg    compile_command=$nonopt
677347e89262Smrg    finalize_command=$nonopt
6774bd1da9d7Smrg
677547e89262Smrg    compile_rpath=
677647e89262Smrg    finalize_rpath=
677747e89262Smrg    compile_shlibpath=
677847e89262Smrg    finalize_shlibpath=
677947e89262Smrg    convenience=
678047e89262Smrg    old_convenience=
678147e89262Smrg    deplibs=
678247e89262Smrg    old_deplibs=
678347e89262Smrg    compiler_flags=
678447e89262Smrg    linker_flags=
678547e89262Smrg    dllsearchpath=
678647e89262Smrg    lib_search_path=`pwd`
678747e89262Smrg    inst_prefix_dir=
678847e89262Smrg    new_inherited_linker_flags=
6789bd1da9d7Smrg
679047e89262Smrg    avoid_version=no
679147e89262Smrg    bindir=
679247e89262Smrg    dlfiles=
679347e89262Smrg    dlprefiles=
679447e89262Smrg    dlself=no
679547e89262Smrg    export_dynamic=no
679647e89262Smrg    export_symbols=
679747e89262Smrg    export_symbols_regex=
679847e89262Smrg    generated=
679947e89262Smrg    libobjs=
680047e89262Smrg    ltlibs=
680147e89262Smrg    module=no
680247e89262Smrg    no_install=no
680347e89262Smrg    objs=
6804e6d2e958Smrg    os2dllname=
680547e89262Smrg    non_pic_objects=
680647e89262Smrg    precious_files_regex=
680747e89262Smrg    prefer_static_libs=no
6808e6d2e958Smrg    preload=false
680947e89262Smrg    prev=
681047e89262Smrg    prevarg=
681147e89262Smrg    release=
681247e89262Smrg    rpath=
681347e89262Smrg    xrpath=
681447e89262Smrg    perm_rpath=
681547e89262Smrg    temp_rpath=
681647e89262Smrg    thread_safe=no
681747e89262Smrg    vinfo=
681847e89262Smrg    vinfo_number=no
681947e89262Smrg    weak_libs=
6820e6d2e958Smrg    single_module=$wl-single_module
682147e89262Smrg    func_infer_tag $base_compile
6822bd1da9d7Smrg
682347e89262Smrg    # We need to know -static, to get the right output filenames.
682447e89262Smrg    for arg
682547e89262Smrg    do
682647e89262Smrg      case $arg in
682747e89262Smrg      -shared)
6828e6d2e958Smrg	test yes != "$build_libtool_libs" \
6829e6d2e958Smrg	  && func_fatal_configuration "cannot build a shared library"
683047e89262Smrg	build_old_libs=no
683147e89262Smrg	break
683247e89262Smrg	;;
683347e89262Smrg      -all-static | -static | -static-libtool-libs)
683447e89262Smrg	case $arg in
683547e89262Smrg	-all-static)
6836e6d2e958Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
683747e89262Smrg	    func_warning "complete static linking is impossible in this configuration"
683847e89262Smrg	  fi
683947e89262Smrg	  if test -n "$link_static_flag"; then
684047e89262Smrg	    dlopen_self=$dlopen_self_static
684147e89262Smrg	  fi
684247e89262Smrg	  prefer_static_libs=yes
684347e89262Smrg	  ;;
684447e89262Smrg	-static)
684547e89262Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
684647e89262Smrg	    dlopen_self=$dlopen_self_static
684747e89262Smrg	  fi
684847e89262Smrg	  prefer_static_libs=built
684947e89262Smrg	  ;;
685047e89262Smrg	-static-libtool-libs)
685147e89262Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
685247e89262Smrg	    dlopen_self=$dlopen_self_static
685347e89262Smrg	  fi
685447e89262Smrg	  prefer_static_libs=yes
685547e89262Smrg	  ;;
685647e89262Smrg	esac
685747e89262Smrg	build_libtool_libs=no
685847e89262Smrg	build_old_libs=yes
685947e89262Smrg	break
686047e89262Smrg	;;
686147e89262Smrg      esac
686247e89262Smrg    done
6863bd1da9d7Smrg
686447e89262Smrg    # See if our shared archives depend on static archives.
686547e89262Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866bd1da9d7Smrg
686747e89262Smrg    # Go through the arguments, transforming them on the way.
686847e89262Smrg    while test "$#" -gt 0; do
6869e6d2e958Smrg      arg=$1
687047e89262Smrg      shift
6871a392d4f3Smrg      func_quote_arg pretty,unquoted "$arg"
6872a392d4f3Smrg      qarg=$func_quote_arg_unquoted_result
6873a392d4f3Smrg      func_append libtool_args " $func_quote_arg_result"
6874bd1da9d7Smrg
687547e89262Smrg      # If the previous option needs an argument, assign it.
687647e89262Smrg      if test -n "$prev"; then
687747e89262Smrg	case $prev in
687847e89262Smrg	output)
687947e89262Smrg	  func_append compile_command " @OUTPUT@"
688047e89262Smrg	  func_append finalize_command " @OUTPUT@"
688147e89262Smrg	  ;;
688247e89262Smrg	esac
6883bd1da9d7Smrg
688447e89262Smrg	case $prev in
688547e89262Smrg	bindir)
6886e6d2e958Smrg	  bindir=$arg
688747e89262Smrg	  prev=
688847e89262Smrg	  continue
688947e89262Smrg	  ;;
689047e89262Smrg	dlfiles|dlprefiles)
6891e6d2e958Smrg	  $preload || {
689247e89262Smrg	    # Add the symbol object into the linking commands.
689347e89262Smrg	    func_append compile_command " @SYMFILE@"
689447e89262Smrg	    func_append finalize_command " @SYMFILE@"
6895e6d2e958Smrg	    preload=:
6896e6d2e958Smrg	  }
689747e89262Smrg	  case $arg in
689847e89262Smrg	  *.la | *.lo) ;;  # We handle these cases below.
689947e89262Smrg	  force)
6900e6d2e958Smrg	    if test no = "$dlself"; then
690147e89262Smrg	      dlself=needless
690247e89262Smrg	      export_dynamic=yes
6903bd1da9d7Smrg	    fi
690447e89262Smrg	    prev=
690547e89262Smrg	    continue
690647e89262Smrg	    ;;
690747e89262Smrg	  self)
6908e6d2e958Smrg	    if test dlprefiles = "$prev"; then
690947e89262Smrg	      dlself=yes
6910e6d2e958Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
691147e89262Smrg	      dlself=yes
6912bd1da9d7Smrg	    else
691347e89262Smrg	      dlself=needless
691447e89262Smrg	      export_dynamic=yes
6915bd1da9d7Smrg	    fi
691647e89262Smrg	    prev=
691747e89262Smrg	    continue
691847e89262Smrg	    ;;
691947e89262Smrg	  *)
6920e6d2e958Smrg	    if test dlfiles = "$prev"; then
6921899129b3Smrg	      func_append dlfiles " $arg"
6922bd1da9d7Smrg	    else
6923899129b3Smrg	      func_append dlprefiles " $arg"
6924bd1da9d7Smrg	    fi
692547e89262Smrg	    prev=
692647e89262Smrg	    continue
692747e89262Smrg	    ;;
692847e89262Smrg	  esac
692947e89262Smrg	  ;;
693047e89262Smrg	expsyms)
6931e6d2e958Smrg	  export_symbols=$arg
693247e89262Smrg	  test -f "$arg" \
6933e6d2e958Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
693447e89262Smrg	  prev=
693547e89262Smrg	  continue
693647e89262Smrg	  ;;
693747e89262Smrg	expsyms_regex)
6938e6d2e958Smrg	  export_symbols_regex=$arg
693947e89262Smrg	  prev=
694047e89262Smrg	  continue
694147e89262Smrg	  ;;
694247e89262Smrg	framework)
6943bd1da9d7Smrg	  case $host in
694447e89262Smrg	    *-*-darwin*)
694547e89262Smrg	      case "$deplibs " in
694647e89262Smrg		*" $qarg.ltframework "*) ;;
6947899129b3Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
694847e89262Smrg		   ;;
694947e89262Smrg	      esac
695047e89262Smrg	      ;;
6951bd1da9d7Smrg	  esac
695247e89262Smrg	  prev=
695347e89262Smrg	  continue
6954bd1da9d7Smrg	  ;;
695547e89262Smrg	inst_prefix)
6956e6d2e958Smrg	  inst_prefix_dir=$arg
6957e6d2e958Smrg	  prev=
6958e6d2e958Smrg	  continue
6959e6d2e958Smrg	  ;;
6960e6d2e958Smrg	mllvm)
6961e6d2e958Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6962e6d2e958Smrg	  # '-mllvm $arg' options when doing the link step.
696347e89262Smrg	  prev=
696447e89262Smrg	  continue
6965bd1da9d7Smrg	  ;;
696647e89262Smrg	objectlist)
696747e89262Smrg	  if test -f "$arg"; then
696847e89262Smrg	    save_arg=$arg
696947e89262Smrg	    moreargs=
697047e89262Smrg	    for fil in `cat "$save_arg"`
697147e89262Smrg	    do
6972899129b3Smrg#	      func_append moreargs " $fil"
697347e89262Smrg	      arg=$fil
697447e89262Smrg	      # A libtool-controlled object.
6975bd1da9d7Smrg
697647e89262Smrg	      # Check to see that this really is a libtool object.
697747e89262Smrg	      if func_lalib_unsafe_p "$arg"; then
697847e89262Smrg		pic_object=
697947e89262Smrg		non_pic_object=
6980bd1da9d7Smrg
698147e89262Smrg		# Read the .lo file
698247e89262Smrg		func_source "$arg"
6983bd1da9d7Smrg
698447e89262Smrg		if test -z "$pic_object" ||
698547e89262Smrg		   test -z "$non_pic_object" ||
6986e6d2e958Smrg		   test none = "$pic_object" &&
6987e6d2e958Smrg		   test none = "$non_pic_object"; then
6988e6d2e958Smrg		  func_fatal_error "cannot find name of object for '$arg'"
698947e89262Smrg		fi
6990bd1da9d7Smrg
699147e89262Smrg		# Extract subdirectory from the argument.
699247e89262Smrg		func_dirname "$arg" "/" ""
6993e6d2e958Smrg		xdir=$func_dirname_result
6994bd1da9d7Smrg
6995e6d2e958Smrg		if test none != "$pic_object"; then
699647e89262Smrg		  # Prepend the subdirectory the object is found in.
6997e6d2e958Smrg		  pic_object=$xdir$pic_object
6998bd1da9d7Smrg
6999e6d2e958Smrg		  if test dlfiles = "$prev"; then
7000e6d2e958Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001899129b3Smrg		      func_append dlfiles " $pic_object"
700247e89262Smrg		      prev=
700347e89262Smrg		      continue
700447e89262Smrg		    else
700547e89262Smrg		      # If libtool objects are unsupported, then we need to preload.
700647e89262Smrg		      prev=dlprefiles
700747e89262Smrg		    fi
700847e89262Smrg		  fi
7009bd1da9d7Smrg
701047e89262Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011e6d2e958Smrg		  if test dlprefiles = "$prev"; then
701247e89262Smrg		    # Preload the old-style object.
7013899129b3Smrg		    func_append dlprefiles " $pic_object"
701447e89262Smrg		    prev=
701547e89262Smrg		  fi
7016bd1da9d7Smrg
701747e89262Smrg		  # A PIC object.
701847e89262Smrg		  func_append libobjs " $pic_object"
7019e6d2e958Smrg		  arg=$pic_object
702047e89262Smrg		fi
7021bd1da9d7Smrg
702247e89262Smrg		# Non-PIC object.
7023e6d2e958Smrg		if test none != "$non_pic_object"; then
702447e89262Smrg		  # Prepend the subdirectory the object is found in.
7025e6d2e958Smrg		  non_pic_object=$xdir$non_pic_object
7026bd1da9d7Smrg
702747e89262Smrg		  # A standard non-PIC object
702847e89262Smrg		  func_append non_pic_objects " $non_pic_object"
7029e6d2e958Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030e6d2e958Smrg		    arg=$non_pic_object
703147e89262Smrg		  fi
703247e89262Smrg		else
703347e89262Smrg		  # If the PIC object exists, use it instead.
703447e89262Smrg		  # $xdir was prepended to $pic_object above.
7035e6d2e958Smrg		  non_pic_object=$pic_object
703647e89262Smrg		  func_append non_pic_objects " $non_pic_object"
703747e89262Smrg		fi
703847e89262Smrg	      else
703947e89262Smrg		# Only an error if not doing a dry-run.
704047e89262Smrg		if $opt_dry_run; then
704147e89262Smrg		  # Extract subdirectory from the argument.
704247e89262Smrg		  func_dirname "$arg" "/" ""
7043e6d2e958Smrg		  xdir=$func_dirname_result
704447e89262Smrg
704547e89262Smrg		  func_lo2o "$arg"
704647e89262Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
704747e89262Smrg		  non_pic_object=$xdir$func_lo2o_result
704847e89262Smrg		  func_append libobjs " $pic_object"
704947e89262Smrg		  func_append non_pic_objects " $non_pic_object"
705047e89262Smrg	        else
7051e6d2e958Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
705247e89262Smrg		fi
705347e89262Smrg	      fi
705447e89262Smrg	    done
7055bd1da9d7Smrg	  else
7056e6d2e958Smrg	    func_fatal_error "link input file '$arg' does not exist"
7057bd1da9d7Smrg	  fi
705847e89262Smrg	  arg=$save_arg
705947e89262Smrg	  prev=
706047e89262Smrg	  continue
706147e89262Smrg	  ;;
7062e6d2e958Smrg	os2dllname)
7063e6d2e958Smrg	  os2dllname=$arg
7064e6d2e958Smrg	  prev=
7065e6d2e958Smrg	  continue
7066e6d2e958Smrg	  ;;
706747e89262Smrg	precious_regex)
7068e6d2e958Smrg	  precious_files_regex=$arg
706947e89262Smrg	  prev=
707047e89262Smrg	  continue
707147e89262Smrg	  ;;
707247e89262Smrg	release)
7073e6d2e958Smrg	  release=-$arg
707447e89262Smrg	  prev=
707547e89262Smrg	  continue
707647e89262Smrg	  ;;
707747e89262Smrg	rpath | xrpath)
707847e89262Smrg	  # We need an absolute path.
707947e89262Smrg	  case $arg in
708047e89262Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
708147e89262Smrg	  *)
708247e89262Smrg	    func_fatal_error "only absolute run-paths are allowed"
708347e89262Smrg	    ;;
708447e89262Smrg	  esac
7085e6d2e958Smrg	  if test rpath = "$prev"; then
708647e89262Smrg	    case "$rpath " in
708747e89262Smrg	    *" $arg "*) ;;
7088899129b3Smrg	    *) func_append rpath " $arg" ;;
708947e89262Smrg	    esac
7090bd1da9d7Smrg	  else
709147e89262Smrg	    case "$xrpath " in
709247e89262Smrg	    *" $arg "*) ;;
7093899129b3Smrg	    *) func_append xrpath " $arg" ;;
709447e89262Smrg	    esac
7095bd1da9d7Smrg	  fi
709647e89262Smrg	  prev=
709747e89262Smrg	  continue
709847e89262Smrg	  ;;
709947e89262Smrg	shrext)
7100e6d2e958Smrg	  shrext_cmds=$arg
710147e89262Smrg	  prev=
710247e89262Smrg	  continue
710347e89262Smrg	  ;;
710447e89262Smrg	weak)
7105899129b3Smrg	  func_append weak_libs " $arg"
710647e89262Smrg	  prev=
710747e89262Smrg	  continue
710847e89262Smrg	  ;;
7109a392d4f3Smrg	xassembler)
7110a392d4f3Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111a392d4f3Smrg	  prev=
7112a392d4f3Smrg	  func_append compile_command " -Xassembler $qarg"
7113a392d4f3Smrg	  func_append finalize_command " -Xassembler $qarg"
7114a392d4f3Smrg	  continue
7115a392d4f3Smrg	  ;;
711647e89262Smrg	xcclinker)
7117899129b3Smrg	  func_append linker_flags " $qarg"
7118899129b3Smrg	  func_append compiler_flags " $qarg"
711947e89262Smrg	  prev=
712047e89262Smrg	  func_append compile_command " $qarg"
712147e89262Smrg	  func_append finalize_command " $qarg"
712247e89262Smrg	  continue
712347e89262Smrg	  ;;
712447e89262Smrg	xcompiler)
7125899129b3Smrg	  func_append compiler_flags " $qarg"
712647e89262Smrg	  prev=
712747e89262Smrg	  func_append compile_command " $qarg"
712847e89262Smrg	  func_append finalize_command " $qarg"
712947e89262Smrg	  continue
713047e89262Smrg	  ;;
713147e89262Smrg	xlinker)
7132899129b3Smrg	  func_append linker_flags " $qarg"
7133899129b3Smrg	  func_append compiler_flags " $wl$qarg"
713447e89262Smrg	  prev=
713547e89262Smrg	  func_append compile_command " $wl$qarg"
713647e89262Smrg	  func_append finalize_command " $wl$qarg"
713747e89262Smrg	  continue
713847e89262Smrg	  ;;
713947e89262Smrg	*)
714047e89262Smrg	  eval "$prev=\"\$arg\""
714147e89262Smrg	  prev=
714247e89262Smrg	  continue
714347e89262Smrg	  ;;
7144bd1da9d7Smrg	esac
714547e89262Smrg      fi # test -n "$prev"
7146bd1da9d7Smrg
7147e6d2e958Smrg      prevarg=$arg
7148bd1da9d7Smrg
714947e89262Smrg      case $arg in
715047e89262Smrg      -all-static)
715147e89262Smrg	if test -n "$link_static_flag"; then
715247e89262Smrg	  # See comment for -static flag below, for more details.
715347e89262Smrg	  func_append compile_command " $link_static_flag"
715447e89262Smrg	  func_append finalize_command " $link_static_flag"
715547e89262Smrg	fi
715647e89262Smrg	continue
715747e89262Smrg	;;
7158bd1da9d7Smrg
715947e89262Smrg      -allow-undefined)
716047e89262Smrg	# FIXME: remove this flag sometime in the future.
7161e6d2e958Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
716247e89262Smrg	;;
7163bd1da9d7Smrg
716447e89262Smrg      -avoid-version)
716547e89262Smrg	avoid_version=yes
716647e89262Smrg	continue
716747e89262Smrg	;;
7168bd1da9d7Smrg
716947e89262Smrg      -bindir)
717047e89262Smrg	prev=bindir
717147e89262Smrg	continue
717247e89262Smrg	;;
7173bd1da9d7Smrg
717447e89262Smrg      -dlopen)
717547e89262Smrg	prev=dlfiles
717647e89262Smrg	continue
717747e89262Smrg	;;
7178bd1da9d7Smrg
717947e89262Smrg      -dlpreopen)
718047e89262Smrg	prev=dlprefiles
718147e89262Smrg	continue
718247e89262Smrg	;;
7183bd1da9d7Smrg
718447e89262Smrg      -export-dynamic)
718547e89262Smrg	export_dynamic=yes
718647e89262Smrg	continue
718747e89262Smrg	;;
7188bd1da9d7Smrg
718947e89262Smrg      -export-symbols | -export-symbols-regex)
719047e89262Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
719147e89262Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
719247e89262Smrg	fi
7193e6d2e958Smrg	if test X-export-symbols = "X$arg"; then
719447e89262Smrg	  prev=expsyms
719547e89262Smrg	else
719647e89262Smrg	  prev=expsyms_regex
719747e89262Smrg	fi
719847e89262Smrg	continue
719947e89262Smrg	;;
7200bd1da9d7Smrg
720147e89262Smrg      -framework)
720247e89262Smrg	prev=framework
720347e89262Smrg	continue
720447e89262Smrg	;;
7205bd1da9d7Smrg
720647e89262Smrg      -inst-prefix-dir)
720747e89262Smrg	prev=inst_prefix
720847e89262Smrg	continue
720947e89262Smrg	;;
7210bd1da9d7Smrg
721147e89262Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
721247e89262Smrg      # so, if we see these flags be careful not to treat them like -L
721347e89262Smrg      -L[A-Z][A-Z]*:*)
721447e89262Smrg	case $with_gcc/$host in
721547e89262Smrg	no/*-*-irix* | /*-*-irix*)
721647e89262Smrg	  func_append compile_command " $arg"
721747e89262Smrg	  func_append finalize_command " $arg"
721847e89262Smrg	  ;;
721947e89262Smrg	esac
722047e89262Smrg	continue
722147e89262Smrg	;;
7222bd1da9d7Smrg
722347e89262Smrg      -L*)
7224899129b3Smrg	func_stripname "-L" '' "$arg"
7225899129b3Smrg	if test -z "$func_stripname_result"; then
722647e89262Smrg	  if test "$#" -gt 0; then
7227e6d2e958Smrg	    func_fatal_error "require no space between '-L' and '$1'"
722847e89262Smrg	  else
7229e6d2e958Smrg	    func_fatal_error "need path for '-L' option"
723047e89262Smrg	  fi
723147e89262Smrg	fi
7232899129b3Smrg	func_resolve_sysroot "$func_stripname_result"
7233899129b3Smrg	dir=$func_resolve_sysroot_result
723447e89262Smrg	# We need an absolute path.
723547e89262Smrg	case $dir in
723647e89262Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
723747e89262Smrg	*)
723847e89262Smrg	  absdir=`cd "$dir" && pwd`
723947e89262Smrg	  test -z "$absdir" && \
7240e6d2e958Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241e6d2e958Smrg	  dir=$absdir
724247e89262Smrg	  ;;
724347e89262Smrg	esac
724447e89262Smrg	case "$deplibs " in
7245899129b3Smrg	*" -L$dir "* | *" $arg "*)
7246899129b3Smrg	  # Will only happen for absolute or sysroot arguments
7247899129b3Smrg	  ;;
724847e89262Smrg	*)
7249899129b3Smrg	  # Preserve sysroot, but never include relative directories
7250899129b3Smrg	  case $dir in
7251899129b3Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252899129b3Smrg	    *) func_append deplibs " -L$dir" ;;
7253899129b3Smrg	  esac
7254899129b3Smrg	  func_append lib_search_path " $dir"
725547e89262Smrg	  ;;
725647e89262Smrg	esac
725747e89262Smrg	case $host in
725847e89262Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725947e89262Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
726047e89262Smrg	  case :$dllsearchpath: in
726147e89262Smrg	  *":$dir:"*) ;;
726247e89262Smrg	  ::) dllsearchpath=$dir;;
7263899129b3Smrg	  *) func_append dllsearchpath ":$dir";;
726447e89262Smrg	  esac
726547e89262Smrg	  case :$dllsearchpath: in
726647e89262Smrg	  *":$testbindir:"*) ;;
726747e89262Smrg	  ::) dllsearchpath=$testbindir;;
7268899129b3Smrg	  *) func_append dllsearchpath ":$testbindir";;
726947e89262Smrg	  esac
727047e89262Smrg	  ;;
727147e89262Smrg	esac
727247e89262Smrg	continue
727347e89262Smrg	;;
7274bd1da9d7Smrg
727547e89262Smrg      -l*)
7276e6d2e958Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
727747e89262Smrg	  case $host in
727847e89262Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
727947e89262Smrg	    # These systems don't actually have a C or math library (as such)
728047e89262Smrg	    continue
728147e89262Smrg	    ;;
728247e89262Smrg	  *-*-os2*)
728347e89262Smrg	    # These systems don't actually have a C library (as such)
7284e6d2e958Smrg	    test X-lc = "X$arg" && continue
728547e89262Smrg	    ;;
7286a392d4f3Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
728747e89262Smrg	    # Do not include libc due to us having libc/libc_r.
7288e6d2e958Smrg	    test X-lc = "X$arg" && continue
728947e89262Smrg	    ;;
729047e89262Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
729147e89262Smrg	    # Rhapsody C and math libraries are in the System framework
7292899129b3Smrg	    func_append deplibs " System.ltframework"
729347e89262Smrg	    continue
729447e89262Smrg	    ;;
729547e89262Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
729647e89262Smrg	    # Causes problems with __ctype
7297e6d2e958Smrg	    test X-lc = "X$arg" && continue
729847e89262Smrg	    ;;
729947e89262Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
730047e89262Smrg	    # Compiler inserts libc in the correct place for threads to work
7301e6d2e958Smrg	    test X-lc = "X$arg" && continue
730247e89262Smrg	    ;;
730347e89262Smrg	  esac
7304e6d2e958Smrg	elif test X-lc_r = "X$arg"; then
730547e89262Smrg	 case $host in
7306a392d4f3Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
730747e89262Smrg	   # Do not include libc_r directly, use -pthread flag.
730847e89262Smrg	   continue
730947e89262Smrg	   ;;
731047e89262Smrg	 esac
731147e89262Smrg	fi
7312899129b3Smrg	func_append deplibs " $arg"
731347e89262Smrg	continue
731447e89262Smrg	;;
7315bd1da9d7Smrg
7316e6d2e958Smrg      -mllvm)
7317e6d2e958Smrg	prev=mllvm
7318e6d2e958Smrg	continue
7319e6d2e958Smrg	;;
7320e6d2e958Smrg
732147e89262Smrg      -module)
732247e89262Smrg	module=yes
732347e89262Smrg	continue
732447e89262Smrg	;;
7325bd1da9d7Smrg
732647e89262Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
732747e89262Smrg      # classes, name mangling, and exception handling.
732847e89262Smrg      # Darwin uses the -arch flag to determine output architecture.
7329899129b3Smrg      -model|-arch|-isysroot|--sysroot)
7330899129b3Smrg	func_append compiler_flags " $arg"
733147e89262Smrg	func_append compile_command " $arg"
733247e89262Smrg	func_append finalize_command " $arg"
733347e89262Smrg	prev=xcompiler
733447e89262Smrg	continue
733547e89262Smrg	;;
7336a392d4f3Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337a392d4f3Smrg     -pthread)
7338a392d4f3Smrg	case $host in
7339a392d4f3Smrg	  *solaris2*) ;;
7340a392d4f3Smrg	  *)
7341a392d4f3Smrg	    case "$new_inherited_linker_flags " in
7342a392d4f3Smrg	        *" $arg "*) ;;
7343a392d4f3Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344a392d4f3Smrg	    esac
7345a392d4f3Smrg	  ;;
7346a392d4f3Smrg	esac
7347a392d4f3Smrg	continue
7348a392d4f3Smrg	;;
7349a392d4f3Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350899129b3Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351899129b3Smrg	func_append compiler_flags " $arg"
735247e89262Smrg	func_append compile_command " $arg"
735347e89262Smrg	func_append finalize_command " $arg"
735447e89262Smrg	case "$new_inherited_linker_flags " in
735547e89262Smrg	    *" $arg "*) ;;
7356899129b3Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
735747e89262Smrg	esac
735847e89262Smrg	continue
735947e89262Smrg	;;
7360bd1da9d7Smrg
736147e89262Smrg      -multi_module)
7362e6d2e958Smrg	single_module=$wl-multi_module
736347e89262Smrg	continue
736447e89262Smrg	;;
7365bd1da9d7Smrg
736647e89262Smrg      -no-fast-install)
736747e89262Smrg	fast_install=no
736847e89262Smrg	continue
736947e89262Smrg	;;
7370bd1da9d7Smrg
737147e89262Smrg      -no-install)
737247e89262Smrg	case $host in
737347e89262Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
737447e89262Smrg	  # The PATH hackery in wrapper scripts is required on Windows
737547e89262Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376e6d2e958Smrg	  func_warning "'-no-install' is ignored for $host"
7377e6d2e958Smrg	  func_warning "assuming '-no-fast-install' instead"
737847e89262Smrg	  fast_install=no
737947e89262Smrg	  ;;
738047e89262Smrg	*) no_install=yes ;;
738147e89262Smrg	esac
738247e89262Smrg	continue
738347e89262Smrg	;;
7384bd1da9d7Smrg
738547e89262Smrg      -no-undefined)
738647e89262Smrg	allow_undefined=no
738747e89262Smrg	continue
738847e89262Smrg	;;
7389bd1da9d7Smrg
739047e89262Smrg      -objectlist)
739147e89262Smrg	prev=objectlist
739247e89262Smrg	continue
739347e89262Smrg	;;
7394bd1da9d7Smrg
7395e6d2e958Smrg      -os2dllname)
7396e6d2e958Smrg	prev=os2dllname
7397e6d2e958Smrg	continue
7398e6d2e958Smrg	;;
7399e6d2e958Smrg
740047e89262Smrg      -o) prev=output ;;
7401bd1da9d7Smrg
740247e89262Smrg      -precious-files-regex)
740347e89262Smrg	prev=precious_regex
740447e89262Smrg	continue
740547e89262Smrg	;;
7406bd1da9d7Smrg
740747e89262Smrg      -release)
740847e89262Smrg	prev=release
740947e89262Smrg	continue
741047e89262Smrg	;;
7411bd1da9d7Smrg
741247e89262Smrg      -rpath)
741347e89262Smrg	prev=rpath
741447e89262Smrg	continue
741547e89262Smrg	;;
7416bd1da9d7Smrg
741747e89262Smrg      -R)
741847e89262Smrg	prev=xrpath
741947e89262Smrg	continue
742047e89262Smrg	;;
7421bd1da9d7Smrg
742247e89262Smrg      -R*)
742347e89262Smrg	func_stripname '-R' '' "$arg"
742447e89262Smrg	dir=$func_stripname_result
742547e89262Smrg	# We need an absolute path.
742647e89262Smrg	case $dir in
742747e89262Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428899129b3Smrg	=*)
7429899129b3Smrg	  func_stripname '=' '' "$dir"
7430899129b3Smrg	  dir=$lt_sysroot$func_stripname_result
7431899129b3Smrg	  ;;
743247e89262Smrg	*)
743347e89262Smrg	  func_fatal_error "only absolute run-paths are allowed"
743447e89262Smrg	  ;;
743547e89262Smrg	esac
743647e89262Smrg	case "$xrpath " in
743747e89262Smrg	*" $dir "*) ;;
7438899129b3Smrg	*) func_append xrpath " $dir" ;;
743947e89262Smrg	esac
744047e89262Smrg	continue
744147e89262Smrg	;;
7442bd1da9d7Smrg
744347e89262Smrg      -shared)
744447e89262Smrg	# The effects of -shared are defined in a previous loop.
744547e89262Smrg	continue
744647e89262Smrg	;;
7447bd1da9d7Smrg
744847e89262Smrg      -shrext)
744947e89262Smrg	prev=shrext
745047e89262Smrg	continue
745147e89262Smrg	;;
7452bd1da9d7Smrg
745347e89262Smrg      -static | -static-libtool-libs)
745447e89262Smrg	# The effects of -static are defined in a previous loop.
745547e89262Smrg	# We used to do the same as -all-static on platforms that
745647e89262Smrg	# didn't have a PIC flag, but the assumption that the effects
745747e89262Smrg	# would be equivalent was wrong.  It would break on at least
745847e89262Smrg	# Digital Unix and AIX.
745947e89262Smrg	continue
746047e89262Smrg	;;
7461bd1da9d7Smrg
746247e89262Smrg      -thread-safe)
746347e89262Smrg	thread_safe=yes
746447e89262Smrg	continue
746547e89262Smrg	;;
7466bd1da9d7Smrg
746747e89262Smrg      -version-info)
746847e89262Smrg	prev=vinfo
746947e89262Smrg	continue
747047e89262Smrg	;;
7471bd1da9d7Smrg
747247e89262Smrg      -version-number)
747347e89262Smrg	prev=vinfo
747447e89262Smrg	vinfo_number=yes
747547e89262Smrg	continue
747647e89262Smrg	;;
7477bd1da9d7Smrg
747847e89262Smrg      -weak)
747947e89262Smrg        prev=weak
748047e89262Smrg	continue
748147e89262Smrg	;;
7482bd1da9d7Smrg
748347e89262Smrg      -Wc,*)
748447e89262Smrg	func_stripname '-Wc,' '' "$arg"
748547e89262Smrg	args=$func_stripname_result
748647e89262Smrg	arg=
7487e6d2e958Smrg	save_ifs=$IFS; IFS=,
748847e89262Smrg	for flag in $args; do
7489e6d2e958Smrg	  IFS=$save_ifs
7490a392d4f3Smrg          func_quote_arg pretty "$flag"
7491a392d4f3Smrg	  func_append arg " $func_quote_arg_result"
7492a392d4f3Smrg	  func_append compiler_flags " $func_quote_arg_result"
749347e89262Smrg	done
7494e6d2e958Smrg	IFS=$save_ifs
749547e89262Smrg	func_stripname ' ' '' "$arg"
749647e89262Smrg	arg=$func_stripname_result
749747e89262Smrg	;;
7498bd1da9d7Smrg
749947e89262Smrg      -Wl,*)
750047e89262Smrg	func_stripname '-Wl,' '' "$arg"
750147e89262Smrg	args=$func_stripname_result
750247e89262Smrg	arg=
7503e6d2e958Smrg	save_ifs=$IFS; IFS=,
750447e89262Smrg	for flag in $args; do
7505e6d2e958Smrg	  IFS=$save_ifs
7506a392d4f3Smrg          func_quote_arg pretty "$flag"
7507a392d4f3Smrg	  func_append arg " $wl$func_quote_arg_result"
7508a392d4f3Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509a392d4f3Smrg	  func_append linker_flags " $func_quote_arg_result"
751047e89262Smrg	done
7511e6d2e958Smrg	IFS=$save_ifs
751247e89262Smrg	func_stripname ' ' '' "$arg"
751347e89262Smrg	arg=$func_stripname_result
751447e89262Smrg	;;
7515bd1da9d7Smrg
7516a392d4f3Smrg      -Xassembler)
7517a392d4f3Smrg        prev=xassembler
7518a392d4f3Smrg        continue
7519a392d4f3Smrg        ;;
7520a392d4f3Smrg
752147e89262Smrg      -Xcompiler)
752247e89262Smrg	prev=xcompiler
752347e89262Smrg	continue
752447e89262Smrg	;;
7525bd1da9d7Smrg
752647e89262Smrg      -Xlinker)
752747e89262Smrg	prev=xlinker
752847e89262Smrg	continue
752947e89262Smrg	;;
7530bd1da9d7Smrg
753147e89262Smrg      -XCClinker)
753247e89262Smrg	prev=xcclinker
753347e89262Smrg	continue
753447e89262Smrg	;;
7535bd1da9d7Smrg
753647e89262Smrg      # -msg_* for osf cc
753747e89262Smrg      -msg_*)
7538a392d4f3Smrg	func_quote_arg pretty "$arg"
7539a392d4f3Smrg	arg=$func_quote_arg_result
754047e89262Smrg	;;
7541bd1da9d7Smrg
754247e89262Smrg      # Flags to be passed through unchanged, with rationale:
754347e89262Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
754447e89262Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
754547e89262Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
754647e89262Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754747e89262Smrg      # -q*                  compiler args for the IBM compiler
754847e89262Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754947e89262Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
755047e89262Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551e6d2e958Smrg      # -fstack-protector*   stack protector flags for GCC
755247e89262Smrg      # @file                GCC response files
755347e89262Smrg      # -tp=*                Portland pgcc target processor selection
7554899129b3Smrg      # --sysroot=*          for sysroot support
7555e6d2e958Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75566ad5a0e2Smrg      # -specs=*             GCC specs files
7557e6d2e958Smrg      # -stdlib=*            select c++ std lib with clang
75586ad5a0e2Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75596ad5a0e2Smrg      # -fuse-ld=*           Linker select flags for GCC
7560a392d4f3Smrg      # -Wa,*                Pass flags directly to the assembler
756147e89262Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562899129b3Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75636ad5a0e2Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564a392d4f3Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565a392d4f3Smrg        func_quote_arg pretty "$arg"
7566a392d4f3Smrg	arg=$func_quote_arg_result
756747e89262Smrg        func_append compile_command " $arg"
756847e89262Smrg        func_append finalize_command " $arg"
7569899129b3Smrg        func_append compiler_flags " $arg"
757047e89262Smrg        continue
757147e89262Smrg        ;;
7572bd1da9d7Smrg
7573e6d2e958Smrg      -Z*)
7574e6d2e958Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575e6d2e958Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576e6d2e958Smrg	  compiler_flags="$compiler_flags $arg"
7577e6d2e958Smrg	  func_append compile_command " $arg"
7578e6d2e958Smrg	  func_append finalize_command " $arg"
7579e6d2e958Smrg	  case $arg in
7580e6d2e958Smrg	  -Zlinker | -Zstack)
7581e6d2e958Smrg	    prev=xcompiler
7582e6d2e958Smrg	    ;;
7583e6d2e958Smrg	  esac
7584e6d2e958Smrg	  continue
7585e6d2e958Smrg        else
7586e6d2e958Smrg	  # Otherwise treat like 'Some other compiler flag' below
7587a392d4f3Smrg	  func_quote_arg pretty "$arg"
7588a392d4f3Smrg	  arg=$func_quote_arg_result
7589e6d2e958Smrg        fi
7590e6d2e958Smrg	;;
7591e6d2e958Smrg
759247e89262Smrg      # Some other compiler flag.
759347e89262Smrg      -* | +*)
7594a392d4f3Smrg        func_quote_arg pretty "$arg"
7595a392d4f3Smrg	arg=$func_quote_arg_result
759647e89262Smrg	;;
7597bd1da9d7Smrg
759847e89262Smrg      *.$objext)
759947e89262Smrg	# A standard object.
7600899129b3Smrg	func_append objs " $arg"
760147e89262Smrg	;;
7602bd1da9d7Smrg
760347e89262Smrg      *.lo)
760447e89262Smrg	# A libtool-controlled object.
7605bd1da9d7Smrg
760647e89262Smrg	# Check to see that this really is a libtool object.
760747e89262Smrg	if func_lalib_unsafe_p "$arg"; then
760847e89262Smrg	  pic_object=
760947e89262Smrg	  non_pic_object=
7610bd1da9d7Smrg
761147e89262Smrg	  # Read the .lo file
761247e89262Smrg	  func_source "$arg"
7613bd1da9d7Smrg
761447e89262Smrg	  if test -z "$pic_object" ||
761547e89262Smrg	     test -z "$non_pic_object" ||
7616e6d2e958Smrg	     test none = "$pic_object" &&
7617e6d2e958Smrg	     test none = "$non_pic_object"; then
7618e6d2e958Smrg	    func_fatal_error "cannot find name of object for '$arg'"
761947e89262Smrg	  fi
76205bcb6992Smrg
762147e89262Smrg	  # Extract subdirectory from the argument.
762247e89262Smrg	  func_dirname "$arg" "/" ""
7623e6d2e958Smrg	  xdir=$func_dirname_result
7624bd1da9d7Smrg
7625e6d2e958Smrg	  test none = "$pic_object" || {
762647e89262Smrg	    # Prepend the subdirectory the object is found in.
7627e6d2e958Smrg	    pic_object=$xdir$pic_object
7628bd1da9d7Smrg
7629e6d2e958Smrg	    if test dlfiles = "$prev"; then
7630e6d2e958Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631899129b3Smrg		func_append dlfiles " $pic_object"
763247e89262Smrg		prev=
763347e89262Smrg		continue
763447e89262Smrg	      else
763547e89262Smrg		# If libtool objects are unsupported, then we need to preload.
763647e89262Smrg		prev=dlprefiles
763747e89262Smrg	      fi
763847e89262Smrg	    fi
763947e89262Smrg
764047e89262Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641e6d2e958Smrg	    if test dlprefiles = "$prev"; then
764247e89262Smrg	      # Preload the old-style object.
7643899129b3Smrg	      func_append dlprefiles " $pic_object"
764447e89262Smrg	      prev=
764547e89262Smrg	    fi
764647e89262Smrg
764747e89262Smrg	    # A PIC object.
764847e89262Smrg	    func_append libobjs " $pic_object"
7649e6d2e958Smrg	    arg=$pic_object
7650e6d2e958Smrg	  }
765147e89262Smrg
765247e89262Smrg	  # Non-PIC object.
7653e6d2e958Smrg	  if test none != "$non_pic_object"; then
765447e89262Smrg	    # Prepend the subdirectory the object is found in.
7655e6d2e958Smrg	    non_pic_object=$xdir$non_pic_object
765647e89262Smrg
765747e89262Smrg	    # A standard non-PIC object
765847e89262Smrg	    func_append non_pic_objects " $non_pic_object"
7659e6d2e958Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660e6d2e958Smrg	      arg=$non_pic_object
766147e89262Smrg	    fi
766247e89262Smrg	  else
766347e89262Smrg	    # If the PIC object exists, use it instead.
766447e89262Smrg	    # $xdir was prepended to $pic_object above.
7665e6d2e958Smrg	    non_pic_object=$pic_object
766647e89262Smrg	    func_append non_pic_objects " $non_pic_object"
766747e89262Smrg	  fi
766847e89262Smrg	else
766947e89262Smrg	  # Only an error if not doing a dry-run.
767047e89262Smrg	  if $opt_dry_run; then
767147e89262Smrg	    # Extract subdirectory from the argument.
767247e89262Smrg	    func_dirname "$arg" "/" ""
7673e6d2e958Smrg	    xdir=$func_dirname_result
767447e89262Smrg
767547e89262Smrg	    func_lo2o "$arg"
767647e89262Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
767747e89262Smrg	    non_pic_object=$xdir$func_lo2o_result
767847e89262Smrg	    func_append libobjs " $pic_object"
767947e89262Smrg	    func_append non_pic_objects " $non_pic_object"
768047e89262Smrg	  else
7681e6d2e958Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
768247e89262Smrg	  fi
768347e89262Smrg	fi
768447e89262Smrg	;;
768547e89262Smrg
768647e89262Smrg      *.$libext)
768747e89262Smrg	# An archive.
7688899129b3Smrg	func_append deplibs " $arg"
7689899129b3Smrg	func_append old_deplibs " $arg"
769047e89262Smrg	continue
769147e89262Smrg	;;
769247e89262Smrg
769347e89262Smrg      *.la)
769447e89262Smrg	# A libtool-controlled library.
769547e89262Smrg
7696899129b3Smrg	func_resolve_sysroot "$arg"
7697e6d2e958Smrg	if test dlfiles = "$prev"; then
769847e89262Smrg	  # This library was specified with -dlopen.
7699899129b3Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
770047e89262Smrg	  prev=
7701e6d2e958Smrg	elif test dlprefiles = "$prev"; then
770247e89262Smrg	  # The library was specified with -dlpreopen.
7703899129b3Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
770447e89262Smrg	  prev=
770547e89262Smrg	else
7706899129b3Smrg	  func_append deplibs " $func_resolve_sysroot_result"
770747e89262Smrg	fi
770847e89262Smrg	continue
770947e89262Smrg	;;
771047e89262Smrg
771147e89262Smrg      # Some other compiler argument.
771247e89262Smrg      *)
771347e89262Smrg	# Unknown arguments in both finalize_command and compile_command need
771447e89262Smrg	# to be aesthetically quoted because they are evaled later.
7715a392d4f3Smrg	func_quote_arg pretty "$arg"
7716a392d4f3Smrg	arg=$func_quote_arg_result
771747e89262Smrg	;;
771847e89262Smrg      esac # arg
771947e89262Smrg
772047e89262Smrg      # Now actually substitute the argument into the commands.
772147e89262Smrg      if test -n "$arg"; then
772247e89262Smrg	func_append compile_command " $arg"
772347e89262Smrg	func_append finalize_command " $arg"
772447e89262Smrg      fi
772547e89262Smrg    done # argument parsing loop
772647e89262Smrg
772747e89262Smrg    test -n "$prev" && \
7728e6d2e958Smrg      func_fatal_help "the '$prevarg' option requires an argument"
772947e89262Smrg
7730e6d2e958Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
773147e89262Smrg      eval arg=\"$export_dynamic_flag_spec\"
773247e89262Smrg      func_append compile_command " $arg"
773347e89262Smrg      func_append finalize_command " $arg"
773447e89262Smrg    fi
773547e89262Smrg
773647e89262Smrg    oldlibs=
773747e89262Smrg    # calculate the name of the file, without its directory
773847e89262Smrg    func_basename "$output"
7739e6d2e958Smrg    outputname=$func_basename_result
7740e6d2e958Smrg    libobjs_save=$libobjs
774147e89262Smrg
774247e89262Smrg    if test -n "$shlibpath_var"; then
774347e89262Smrg      # get the directories listed in $shlibpath_var
7744e6d2e958Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745bd1da9d7Smrg    else
774647e89262Smrg      shlib_search_path=
7747bd1da9d7Smrg    fi
774847e89262Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
774947e89262Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750bd1da9d7Smrg
7751e6d2e958Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7752e6d2e958Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753e6d2e958Smrg
775447e89262Smrg    func_dirname "$output" "/" ""
7755e6d2e958Smrg    output_objdir=$func_dirname_result$objdir
7756899129b3Smrg    func_to_tool_file "$output_objdir/"
7757899129b3Smrg    tool_output_objdir=$func_to_tool_file_result
775847e89262Smrg    # Create the object directory.
775947e89262Smrg    func_mkdir_p "$output_objdir"
7760bd1da9d7Smrg
776147e89262Smrg    # Determine the type of output
776247e89262Smrg    case $output in
776347e89262Smrg    "")
776447e89262Smrg      func_fatal_help "you must specify an output file"
776547e89262Smrg      ;;
776647e89262Smrg    *.$libext) linkmode=oldlib ;;
776747e89262Smrg    *.lo | *.$objext) linkmode=obj ;;
776847e89262Smrg    *.la) linkmode=lib ;;
776947e89262Smrg    *) linkmode=prog ;; # Anything else should be a program.
777047e89262Smrg    esac
777147e89262Smrg
777247e89262Smrg    specialdeplibs=
777347e89262Smrg
777447e89262Smrg    libs=
777547e89262Smrg    # Find all interdependent deplibs by searching for libraries
777647e89262Smrg    # that are linked more than once (e.g. -la -lb -la)
777747e89262Smrg    for deplib in $deplibs; do
7778e6d2e958Smrg      if $opt_preserve_dup_deps; then
777947e89262Smrg	case "$libs " in
7780899129b3Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
778147e89262Smrg	esac
778247e89262Smrg      fi
7783899129b3Smrg      func_append libs " $deplib"
778447e89262Smrg    done
778547e89262Smrg
7786e6d2e958Smrg    if test lib = "$linkmode"; then
778747e89262Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
778847e89262Smrg
778947e89262Smrg      # Compute libraries that are listed more than once in $predeps
779047e89262Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
779147e89262Smrg      # not to be eliminated).
779247e89262Smrg      pre_post_deps=
779347e89262Smrg      if $opt_duplicate_compiler_generated_deps; then
779447e89262Smrg	for pre_post_dep in $predeps $postdeps; do
779547e89262Smrg	  case "$pre_post_deps " in
7796899129b3Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
779747e89262Smrg	  esac
7798899129b3Smrg	  func_append pre_post_deps " $pre_post_dep"
779947e89262Smrg	done
780047e89262Smrg      fi
780147e89262Smrg      pre_post_deps=
780247e89262Smrg    fi
780347e89262Smrg
780447e89262Smrg    deplibs=
780547e89262Smrg    newdependency_libs=
780647e89262Smrg    newlib_search_path=
780747e89262Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
780847e89262Smrg    notinst_deplibs= # not-installed libtool libraries
780947e89262Smrg    notinst_path= # paths that contain not-installed libtool libraries
781047e89262Smrg
781147e89262Smrg    case $linkmode in
781247e89262Smrg    lib)
781347e89262Smrg	passes="conv dlpreopen link"
781447e89262Smrg	for file in $dlfiles $dlprefiles; do
781547e89262Smrg	  case $file in
781647e89262Smrg	  *.la) ;;
781747e89262Smrg	  *)
7818e6d2e958Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
781947e89262Smrg	    ;;
782047e89262Smrg	  esac
782147e89262Smrg	done
782247e89262Smrg	;;
782347e89262Smrg    prog)
782447e89262Smrg	compile_deplibs=
782547e89262Smrg	finalize_deplibs=
7826e6d2e958Smrg	alldeplibs=false
782747e89262Smrg	newdlfiles=
782847e89262Smrg	newdlprefiles=
782947e89262Smrg	passes="conv scan dlopen dlpreopen link"
783047e89262Smrg	;;
783147e89262Smrg    *)  passes="conv"
783247e89262Smrg	;;
783347e89262Smrg    esac
783447e89262Smrg
783547e89262Smrg    for pass in $passes; do
783647e89262Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
783747e89262Smrg      # so that -L comes before libs that need it for instance...
7838e6d2e958Smrg      if test lib,link = "$linkmode,$pass"; then
783947e89262Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
784047e89262Smrg	##        order, and fix it there properly
784147e89262Smrg        tmp_deplibs=
784247e89262Smrg	for deplib in $deplibs; do
784347e89262Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
784447e89262Smrg	done
7845e6d2e958Smrg	deplibs=$tmp_deplibs
784647e89262Smrg      fi
784747e89262Smrg
7848e6d2e958Smrg      if test lib,link = "$linkmode,$pass" ||
7849e6d2e958Smrg	 test prog,scan = "$linkmode,$pass"; then
7850e6d2e958Smrg	libs=$deplibs
785147e89262Smrg	deplibs=
785247e89262Smrg      fi
7853e6d2e958Smrg      if test prog = "$linkmode"; then
785447e89262Smrg	case $pass in
7855e6d2e958Smrg	dlopen) libs=$dlfiles ;;
7856e6d2e958Smrg	dlpreopen) libs=$dlprefiles ;;
7857a392d4f3Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
785847e89262Smrg	esac
785947e89262Smrg      fi
7860e6d2e958Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
786147e89262Smrg	# Collect and forward deplibs of preopened libtool libs
786247e89262Smrg	for lib in $dlprefiles; do
786347e89262Smrg	  # Ignore non-libtool-libs
786447e89262Smrg	  dependency_libs=
7865899129b3Smrg	  func_resolve_sysroot "$lib"
786647e89262Smrg	  case $lib in
7867899129b3Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
786847e89262Smrg	  esac
786947e89262Smrg
787047e89262Smrg	  # Collect preopened libtool deplibs, except any this library
787147e89262Smrg	  # has declared as weak libs
787247e89262Smrg	  for deplib in $dependency_libs; do
787347e89262Smrg	    func_basename "$deplib"
787447e89262Smrg            deplib_base=$func_basename_result
787547e89262Smrg	    case " $weak_libs " in
787647e89262Smrg	    *" $deplib_base "*) ;;
7877899129b3Smrg	    *) func_append deplibs " $deplib" ;;
787847e89262Smrg	    esac
787947e89262Smrg	  done
788047e89262Smrg	done
7881e6d2e958Smrg	libs=$dlprefiles
788247e89262Smrg      fi
7883e6d2e958Smrg      if test dlopen = "$pass"; then
788447e89262Smrg	# Collect dlpreopened libraries
7885e6d2e958Smrg	save_deplibs=$deplibs
788647e89262Smrg	deplibs=
788747e89262Smrg      fi
788847e89262Smrg
788947e89262Smrg      for deplib in $libs; do
789047e89262Smrg	lib=
7891e6d2e958Smrg	found=false
789247e89262Smrg	case $deplib in
7893899129b3Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894899129b3Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895e6d2e958Smrg	  if test prog,link = "$linkmode,$pass"; then
789647e89262Smrg	    compile_deplibs="$deplib $compile_deplibs"
789747e89262Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
789847e89262Smrg	  else
7899899129b3Smrg	    func_append compiler_flags " $deplib"
7900e6d2e958Smrg	    if test lib = "$linkmode"; then
790147e89262Smrg		case "$new_inherited_linker_flags " in
790247e89262Smrg		    *" $deplib "*) ;;
7903899129b3Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
790447e89262Smrg		esac
790547e89262Smrg	    fi
790647e89262Smrg	  fi
790747e89262Smrg	  continue
790847e89262Smrg	  ;;
790947e89262Smrg	-l*)
7910e6d2e958Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911e6d2e958Smrg	    func_warning "'-l' is ignored for archives/objects"
791247e89262Smrg	    continue
791347e89262Smrg	  fi
791447e89262Smrg	  func_stripname '-l' '' "$deplib"
791547e89262Smrg	  name=$func_stripname_result
7916e6d2e958Smrg	  if test lib = "$linkmode"; then
791747e89262Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
791847e89262Smrg	  else
791947e89262Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
792047e89262Smrg	  fi
792147e89262Smrg	  for searchdir in $searchdirs; do
792247e89262Smrg	    for search_ext in .la $std_shrext .so .a; do
792347e89262Smrg	      # Search the libtool library
7924e6d2e958Smrg	      lib=$searchdir/lib$name$search_ext
792547e89262Smrg	      if test -f "$lib"; then
7926e6d2e958Smrg		if test .la = "$search_ext"; then
7927e6d2e958Smrg		  found=:
792847e89262Smrg		else
7929e6d2e958Smrg		  found=false
793047e89262Smrg		fi
793147e89262Smrg		break 2
793247e89262Smrg	      fi
793347e89262Smrg	    done
793447e89262Smrg	  done
7935e6d2e958Smrg	  if $found; then
7936e6d2e958Smrg	    # deplib is a libtool library
793747e89262Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
793847e89262Smrg	    # We need to do some special things here, and not later.
7939e6d2e958Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
794047e89262Smrg	      case " $predeps $postdeps " in
794147e89262Smrg	      *" $deplib "*)
794247e89262Smrg		if func_lalib_p "$lib"; then
794347e89262Smrg		  library_names=
794447e89262Smrg		  old_library=
794547e89262Smrg		  func_source "$lib"
794647e89262Smrg		  for l in $old_library $library_names; do
7947e6d2e958Smrg		    ll=$l
794847e89262Smrg		  done
7949e6d2e958Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950e6d2e958Smrg		    found=false
795147e89262Smrg		    func_dirname "$lib" "" "."
7952e6d2e958Smrg		    ladir=$func_dirname_result
795347e89262Smrg		    lib=$ladir/$old_library
7954e6d2e958Smrg		    if test prog,link = "$linkmode,$pass"; then
795547e89262Smrg		      compile_deplibs="$deplib $compile_deplibs"
795647e89262Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
795747e89262Smrg		    else
795847e89262Smrg		      deplibs="$deplib $deplibs"
7959e6d2e958Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
796047e89262Smrg		    fi
796147e89262Smrg		    continue
796247e89262Smrg		  fi
796347e89262Smrg		fi
796447e89262Smrg		;;
796547e89262Smrg	      *) ;;
796647e89262Smrg	      esac
796747e89262Smrg	    fi
7968e6d2e958Smrg	  else
7969e6d2e958Smrg	    # deplib doesn't seem to be a libtool library
7970e6d2e958Smrg	    if test prog,link = "$linkmode,$pass"; then
7971e6d2e958Smrg	      compile_deplibs="$deplib $compile_deplibs"
7972e6d2e958Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973e6d2e958Smrg	    else
7974e6d2e958Smrg	      deplibs="$deplib $deplibs"
7975e6d2e958Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976e6d2e958Smrg	    fi
7977e6d2e958Smrg	    continue
797847e89262Smrg	  fi
797947e89262Smrg	  ;; # -l
798047e89262Smrg	*.ltframework)
7981e6d2e958Smrg	  if test prog,link = "$linkmode,$pass"; then
798247e89262Smrg	    compile_deplibs="$deplib $compile_deplibs"
798347e89262Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
798447e89262Smrg	  else
798547e89262Smrg	    deplibs="$deplib $deplibs"
7986e6d2e958Smrg	    if test lib = "$linkmode"; then
798747e89262Smrg		case "$new_inherited_linker_flags " in
798847e89262Smrg		    *" $deplib "*) ;;
7989899129b3Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
799047e89262Smrg		esac
799147e89262Smrg	    fi
799247e89262Smrg	  fi
799347e89262Smrg	  continue
799447e89262Smrg	  ;;
799547e89262Smrg	-L*)
799647e89262Smrg	  case $linkmode in
799747e89262Smrg	  lib)
799847e89262Smrg	    deplibs="$deplib $deplibs"
7999e6d2e958Smrg	    test conv = "$pass" && continue
800047e89262Smrg	    newdependency_libs="$deplib $newdependency_libs"
800147e89262Smrg	    func_stripname '-L' '' "$deplib"
8002899129b3Smrg	    func_resolve_sysroot "$func_stripname_result"
8003899129b3Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
800447e89262Smrg	    ;;
800547e89262Smrg	  prog)
8006e6d2e958Smrg	    if test conv = "$pass"; then
800747e89262Smrg	      deplibs="$deplib $deplibs"
800847e89262Smrg	      continue
800947e89262Smrg	    fi
8010e6d2e958Smrg	    if test scan = "$pass"; then
801147e89262Smrg	      deplibs="$deplib $deplibs"
801247e89262Smrg	    else
801347e89262Smrg	      compile_deplibs="$deplib $compile_deplibs"
801447e89262Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
801547e89262Smrg	    fi
801647e89262Smrg	    func_stripname '-L' '' "$deplib"
8017899129b3Smrg	    func_resolve_sysroot "$func_stripname_result"
8018899129b3Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
801947e89262Smrg	    ;;
802047e89262Smrg	  *)
8021e6d2e958Smrg	    func_warning "'-L' is ignored for archives/objects"
802247e89262Smrg	    ;;
802347e89262Smrg	  esac # linkmode
802447e89262Smrg	  continue
802547e89262Smrg	  ;; # -L
802647e89262Smrg	-R*)
8027e6d2e958Smrg	  if test link = "$pass"; then
802847e89262Smrg	    func_stripname '-R' '' "$deplib"
8029899129b3Smrg	    func_resolve_sysroot "$func_stripname_result"
8030899129b3Smrg	    dir=$func_resolve_sysroot_result
803147e89262Smrg	    # Make sure the xrpath contains only unique directories.
803247e89262Smrg	    case "$xrpath " in
803347e89262Smrg	    *" $dir "*) ;;
8034899129b3Smrg	    *) func_append xrpath " $dir" ;;
803547e89262Smrg	    esac
803647e89262Smrg	  fi
803747e89262Smrg	  deplibs="$deplib $deplibs"
803847e89262Smrg	  continue
803947e89262Smrg	  ;;
8040899129b3Smrg	*.la)
8041899129b3Smrg	  func_resolve_sysroot "$deplib"
8042899129b3Smrg	  lib=$func_resolve_sysroot_result
8043899129b3Smrg	  ;;
804447e89262Smrg	*.$libext)
8045e6d2e958Smrg	  if test conv = "$pass"; then
804647e89262Smrg	    deplibs="$deplib $deplibs"
804747e89262Smrg	    continue
804847e89262Smrg	  fi
804947e89262Smrg	  case $linkmode in
805047e89262Smrg	  lib)
805147e89262Smrg	    # Linking convenience modules into shared libraries is allowed,
805247e89262Smrg	    # but linking other static libraries is non-portable.
805347e89262Smrg	    case " $dlpreconveniencelibs " in
805447e89262Smrg	    *" $deplib "*) ;;
805547e89262Smrg	    *)
8056e6d2e958Smrg	      valid_a_lib=false
805747e89262Smrg	      case $deplibs_check_method in
805847e89262Smrg		match_pattern*)
805947e89262Smrg		  set dummy $deplibs_check_method; shift
806047e89262Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
806147e89262Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
806247e89262Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063e6d2e958Smrg		    valid_a_lib=:
806447e89262Smrg		  fi
806547e89262Smrg		;;
806647e89262Smrg		pass_all)
8067e6d2e958Smrg		  valid_a_lib=:
806847e89262Smrg		;;
806947e89262Smrg	      esac
8070e6d2e958Smrg	      if $valid_a_lib; then
8071e6d2e958Smrg		echo
8072e6d2e958Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073e6d2e958Smrg		$ECHO "*** static library $deplib is not portable!"
8074e6d2e958Smrg		deplibs="$deplib $deplibs"
8075e6d2e958Smrg	      else
807647e89262Smrg		echo
807747e89262Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807847e89262Smrg		echo "*** I have the capability to make that library automatically link in when"
807947e89262Smrg		echo "*** you link to this library.  But I can only do this if you have a"
808047e89262Smrg		echo "*** shared version of the library, which you do not appear to have"
808147e89262Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
808247e89262Smrg		echo "*** that it is just a static archive that I should not use here."
808347e89262Smrg	      fi
808447e89262Smrg	      ;;
808547e89262Smrg	    esac
808647e89262Smrg	    continue
808747e89262Smrg	    ;;
808847e89262Smrg	  prog)
8089e6d2e958Smrg	    if test link != "$pass"; then
809047e89262Smrg	      deplibs="$deplib $deplibs"
809147e89262Smrg	    else
809247e89262Smrg	      compile_deplibs="$deplib $compile_deplibs"
809347e89262Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
809447e89262Smrg	    fi
809547e89262Smrg	    continue
809647e89262Smrg	    ;;
809747e89262Smrg	  esac # linkmode
809847e89262Smrg	  ;; # *.$libext
809947e89262Smrg	*.lo | *.$objext)
8100e6d2e958Smrg	  if test conv = "$pass"; then
810147e89262Smrg	    deplibs="$deplib $deplibs"
8102e6d2e958Smrg	  elif test prog = "$linkmode"; then
8103e6d2e958Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
810447e89262Smrg	      # If there is no dlopen support or we're linking statically,
810547e89262Smrg	      # we need to preload.
8106899129b3Smrg	      func_append newdlprefiles " $deplib"
810747e89262Smrg	      compile_deplibs="$deplib $compile_deplibs"
810847e89262Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
810947e89262Smrg	    else
8110899129b3Smrg	      func_append newdlfiles " $deplib"
811147e89262Smrg	    fi
811247e89262Smrg	  fi
811347e89262Smrg	  continue
811447e89262Smrg	  ;;
811547e89262Smrg	%DEPLIBS%)
8116e6d2e958Smrg	  alldeplibs=:
811747e89262Smrg	  continue
811847e89262Smrg	  ;;
811947e89262Smrg	esac # case $deplib
812047e89262Smrg
8121e6d2e958Smrg	$found || test -f "$lib" \
8122e6d2e958Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
812347e89262Smrg
812447e89262Smrg	# Check to see that this really is a libtool archive.
812547e89262Smrg	func_lalib_unsafe_p "$lib" \
8126e6d2e958Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
812747e89262Smrg
812847e89262Smrg	func_dirname "$lib" "" "."
8129e6d2e958Smrg	ladir=$func_dirname_result
813047e89262Smrg
813147e89262Smrg	dlname=
813247e89262Smrg	dlopen=
813347e89262Smrg	dlpreopen=
813447e89262Smrg	libdir=
813547e89262Smrg	library_names=
813647e89262Smrg	old_library=
813747e89262Smrg	inherited_linker_flags=
813847e89262Smrg	# If the library was installed with an old release of libtool,
813947e89262Smrg	# it will not redefine variables installed, or shouldnotlink
814047e89262Smrg	installed=yes
814147e89262Smrg	shouldnotlink=no
814247e89262Smrg	avoidtemprpath=
814347e89262Smrg
814447e89262Smrg
814547e89262Smrg	# Read the .la file
814647e89262Smrg	func_source "$lib"
814747e89262Smrg
814847e89262Smrg	# Convert "-framework foo" to "foo.ltframework"
814947e89262Smrg	if test -n "$inherited_linker_flags"; then
815047e89262Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
815147e89262Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
815247e89262Smrg	    case " $new_inherited_linker_flags " in
815347e89262Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8154899129b3Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
815547e89262Smrg	    esac
815647e89262Smrg	  done
815747e89262Smrg	fi
815847e89262Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159e6d2e958Smrg	if test lib,link = "$linkmode,$pass" ||
8160e6d2e958Smrg	   test prog,scan = "$linkmode,$pass" ||
8161e6d2e958Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162899129b3Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163899129b3Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
816447e89262Smrg	fi
816547e89262Smrg
8166e6d2e958Smrg	if test conv = "$pass"; then
816747e89262Smrg	  # Only check for convenience libraries
816847e89262Smrg	  deplibs="$lib $deplibs"
816947e89262Smrg	  if test -z "$libdir"; then
817047e89262Smrg	    if test -z "$old_library"; then
8171e6d2e958Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
817247e89262Smrg	    fi
817347e89262Smrg	    # It is a libtool convenience library, so add in its objects.
8174899129b3Smrg	    func_append convenience " $ladir/$objdir/$old_library"
8175899129b3Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176e6d2e958Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177e6d2e958Smrg	    func_fatal_error "'$lib' is not a convenience library"
817847e89262Smrg	  fi
8179a392d4f3Smrg	  tmp_libs=
8180a392d4f3Smrg	  for deplib in $dependency_libs; do
8181a392d4f3Smrg	    deplibs="$deplib $deplibs"
8182a392d4f3Smrg	    if $opt_preserve_dup_deps; then
8183a392d4f3Smrg	      case "$tmp_libs " in
8184a392d4f3Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185a392d4f3Smrg	      esac
8186a392d4f3Smrg	    fi
8187a392d4f3Smrg	    func_append tmp_libs " $deplib"
8188a392d4f3Smrg	  done
818947e89262Smrg	  continue
819047e89262Smrg	fi # $pass = conv
819147e89262Smrg
819247e89262Smrg
819347e89262Smrg	# Get the name of the library we link against.
819447e89262Smrg	linklib=
8195899129b3Smrg	if test -n "$old_library" &&
8196e6d2e958Smrg	   { test yes = "$prefer_static_libs" ||
8197e6d2e958Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198899129b3Smrg	  linklib=$old_library
8199899129b3Smrg	else
8200899129b3Smrg	  for l in $old_library $library_names; do
8201e6d2e958Smrg	    linklib=$l
8202899129b3Smrg	  done
8203899129b3Smrg	fi
820447e89262Smrg	if test -z "$linklib"; then
8205e6d2e958Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
820647e89262Smrg	fi
820747e89262Smrg
820847e89262Smrg	# This library was specified with -dlopen.
8209e6d2e958Smrg	if test dlopen = "$pass"; then
8210e6d2e958Smrg	  test -z "$libdir" \
8211e6d2e958Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
821247e89262Smrg	  if test -z "$dlname" ||
8213e6d2e958Smrg	     test yes != "$dlopen_support" ||
8214e6d2e958Smrg	     test no = "$build_libtool_libs"
8215e6d2e958Smrg	  then
821647e89262Smrg	    # If there is no dlname, no dlopen support or we're linking
821747e89262Smrg	    # statically, we need to preload.  We also need to preload any
821847e89262Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
821947e89262Smrg	    # bomb out in the load deplibs phase.
8220899129b3Smrg	    func_append dlprefiles " $lib $dependency_libs"
822147e89262Smrg	  else
8222899129b3Smrg	    func_append newdlfiles " $lib"
822347e89262Smrg	  fi
822447e89262Smrg	  continue
822547e89262Smrg	fi # $pass = dlopen
822647e89262Smrg
822747e89262Smrg	# We need an absolute path.
822847e89262Smrg	case $ladir in
8229e6d2e958Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
823047e89262Smrg	*)
823147e89262Smrg	  abs_ladir=`cd "$ladir" && pwd`
823247e89262Smrg	  if test -z "$abs_ladir"; then
8233e6d2e958Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
823447e89262Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235e6d2e958Smrg	    abs_ladir=$ladir
823647e89262Smrg	  fi
823747e89262Smrg	  ;;
823847e89262Smrg	esac
823947e89262Smrg	func_basename "$lib"
8240e6d2e958Smrg	laname=$func_basename_result
824147e89262Smrg
824247e89262Smrg	# Find the relevant object directory and library name.
8243e6d2e958Smrg	if test yes = "$installed"; then
8244899129b3Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245e6d2e958Smrg	    func_warning "library '$lib' was moved."
8246e6d2e958Smrg	    dir=$ladir
8247e6d2e958Smrg	    absdir=$abs_ladir
8248e6d2e958Smrg	    libdir=$abs_ladir
824947e89262Smrg	  else
8250e6d2e958Smrg	    dir=$lt_sysroot$libdir
8251e6d2e958Smrg	    absdir=$lt_sysroot$libdir
825247e89262Smrg	  fi
8253e6d2e958Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
825447e89262Smrg	else
825547e89262Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256e6d2e958Smrg	    dir=$ladir
8257e6d2e958Smrg	    absdir=$abs_ladir
825847e89262Smrg	    # Remove this search path later
8259899129b3Smrg	    func_append notinst_path " $abs_ladir"
826047e89262Smrg	  else
8261e6d2e958Smrg	    dir=$ladir/$objdir
8262e6d2e958Smrg	    absdir=$abs_ladir/$objdir
826347e89262Smrg	    # Remove this search path later
8264899129b3Smrg	    func_append notinst_path " $abs_ladir"
826547e89262Smrg	  fi
826647e89262Smrg	fi # $installed = yes
826747e89262Smrg	func_stripname 'lib' '.la' "$laname"
826847e89262Smrg	name=$func_stripname_result
826947e89262Smrg
827047e89262Smrg	# This library was specified with -dlpreopen.
8271e6d2e958Smrg	if test dlpreopen = "$pass"; then
8272e6d2e958Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273e6d2e958Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
827447e89262Smrg	  fi
8275e6d2e958Smrg	  case $host in
8276899129b3Smrg	    # special handling for platforms with PE-DLLs.
8277899129b3Smrg	    *cygwin* | *mingw* | *cegcc* )
8278899129b3Smrg	      # Linker will automatically link against shared library if both
8279899129b3Smrg	      # static and shared are present.  Therefore, ensure we extract
8280899129b3Smrg	      # symbols from the import library if a shared library is present
8281899129b3Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282899129b3Smrg	      # this by putting the import library name into $newdlprefiles.
8283899129b3Smrg	      # We recover the dlopen module name by 'saving' the la file
8284899129b3Smrg	      # name in a special purpose variable, and (later) extracting the
8285899129b3Smrg	      # dlname from the la file.
8286899129b3Smrg	      if test -n "$dlname"; then
8287899129b3Smrg	        func_tr_sh "$dir/$linklib"
8288899129b3Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289899129b3Smrg	        func_append newdlprefiles " $dir/$linklib"
8290899129b3Smrg	      else
8291899129b3Smrg	        func_append newdlprefiles " $dir/$old_library"
8292899129b3Smrg	        # Keep a list of preopened convenience libraries to check
8293899129b3Smrg	        # that they are being used correctly in the link pass.
8294899129b3Smrg	        test -z "$libdir" && \
8295899129b3Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296899129b3Smrg	      fi
8297899129b3Smrg	    ;;
8298899129b3Smrg	    * )
8299899129b3Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300899129b3Smrg	      # are required to link).
8301899129b3Smrg	      if test -n "$old_library"; then
8302899129b3Smrg	        func_append newdlprefiles " $dir/$old_library"
8303899129b3Smrg	        # Keep a list of preopened convenience libraries to check
8304899129b3Smrg	        # that they are being used correctly in the link pass.
8305899129b3Smrg	        test -z "$libdir" && \
8306899129b3Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307899129b3Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308899129b3Smrg	      elif test -n "$dlname"; then
8309899129b3Smrg	        func_append newdlprefiles " $dir/$dlname"
8310899129b3Smrg	      else
8311899129b3Smrg	        func_append newdlprefiles " $dir/$linklib"
8312899129b3Smrg	      fi
8313899129b3Smrg	    ;;
8314899129b3Smrg	  esac
831547e89262Smrg	fi # $pass = dlpreopen
831647e89262Smrg
831747e89262Smrg	if test -z "$libdir"; then
831847e89262Smrg	  # Link the convenience library
8319e6d2e958Smrg	  if test lib = "$linkmode"; then
832047e89262Smrg	    deplibs="$dir/$old_library $deplibs"
8321e6d2e958Smrg	  elif test prog,link = "$linkmode,$pass"; then
832247e89262Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
832347e89262Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
832447e89262Smrg	  else
832547e89262Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
832647e89262Smrg	  fi
832747e89262Smrg	  continue
832847e89262Smrg	fi
832947e89262Smrg
833047e89262Smrg
8331e6d2e958Smrg	if test prog = "$linkmode" && test link != "$pass"; then
8332899129b3Smrg	  func_append newlib_search_path " $ladir"
833347e89262Smrg	  deplibs="$lib $deplibs"
833447e89262Smrg
8335e6d2e958Smrg	  linkalldeplibs=false
8336e6d2e958Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337e6d2e958Smrg	     test no = "$build_libtool_libs"; then
8338e6d2e958Smrg	    linkalldeplibs=:
833947e89262Smrg	  fi
834047e89262Smrg
834147e89262Smrg	  tmp_libs=
834247e89262Smrg	  for deplib in $dependency_libs; do
834347e89262Smrg	    case $deplib in
834447e89262Smrg	    -L*) func_stripname '-L' '' "$deplib"
8345899129b3Smrg	         func_resolve_sysroot "$func_stripname_result"
8346899129b3Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
834747e89262Smrg		 ;;
834847e89262Smrg	    esac
834947e89262Smrg	    # Need to link against all dependency_libs?
8350e6d2e958Smrg	    if $linkalldeplibs; then
835147e89262Smrg	      deplibs="$deplib $deplibs"
835247e89262Smrg	    else
835347e89262Smrg	      # Need to hardcode shared library paths
835447e89262Smrg	      # or/and link against static libraries
835547e89262Smrg	      newdependency_libs="$deplib $newdependency_libs"
835647e89262Smrg	    fi
8357e6d2e958Smrg	    if $opt_preserve_dup_deps; then
835847e89262Smrg	      case "$tmp_libs " in
8359899129b3Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
836047e89262Smrg	      esac
836147e89262Smrg	    fi
8362899129b3Smrg	    func_append tmp_libs " $deplib"
836347e89262Smrg	  done # for deplib
836447e89262Smrg	  continue
836547e89262Smrg	fi # $linkmode = prog...
836647e89262Smrg
8367e6d2e958Smrg	if test prog,link = "$linkmode,$pass"; then
836847e89262Smrg	  if test -n "$library_names" &&
8369e6d2e958Smrg	     { { test no = "$prefer_static_libs" ||
8370e6d2e958Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
837147e89262Smrg	       test -z "$old_library"; }; then
837247e89262Smrg	    # We need to hardcode the library path
8373e6d2e958Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
837447e89262Smrg	      # Make sure the rpath contains only unique directories.
8375e6d2e958Smrg	      case $temp_rpath: in
837647e89262Smrg	      *"$absdir:"*) ;;
8377899129b3Smrg	      *) func_append temp_rpath "$absdir:" ;;
837847e89262Smrg	      esac
837947e89262Smrg	    fi
838047e89262Smrg
838147e89262Smrg	    # Hardcode the library path.
838247e89262Smrg	    # Skip directories that are in the system default run-time
838347e89262Smrg	    # search path.
838447e89262Smrg	    case " $sys_lib_dlsearch_path " in
838547e89262Smrg	    *" $absdir "*) ;;
838647e89262Smrg	    *)
838747e89262Smrg	      case "$compile_rpath " in
838847e89262Smrg	      *" $absdir "*) ;;
8389899129b3Smrg	      *) func_append compile_rpath " $absdir" ;;
839047e89262Smrg	      esac
839147e89262Smrg	      ;;
839247e89262Smrg	    esac
839347e89262Smrg	    case " $sys_lib_dlsearch_path " in
839447e89262Smrg	    *" $libdir "*) ;;
839547e89262Smrg	    *)
839647e89262Smrg	      case "$finalize_rpath " in
839747e89262Smrg	      *" $libdir "*) ;;
8398899129b3Smrg	      *) func_append finalize_rpath " $libdir" ;;
839947e89262Smrg	      esac
840047e89262Smrg	      ;;
840147e89262Smrg	    esac
840247e89262Smrg	  fi # $linkmode,$pass = prog,link...
840347e89262Smrg
8404e6d2e958Smrg	  if $alldeplibs &&
8405e6d2e958Smrg	     { test pass_all = "$deplibs_check_method" ||
8406e6d2e958Smrg	       { test yes = "$build_libtool_libs" &&
840747e89262Smrg		 test -n "$library_names"; }; }; then
840847e89262Smrg	    # We only need to search for static libraries
840947e89262Smrg	    continue
841047e89262Smrg	  fi
841147e89262Smrg	fi
841247e89262Smrg
841347e89262Smrg	link_static=no # Whether the deplib will be linked statically
841447e89262Smrg	use_static_libs=$prefer_static_libs
8415e6d2e958Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
841647e89262Smrg	  use_static_libs=no
841747e89262Smrg	fi
841847e89262Smrg	if test -n "$library_names" &&
8419e6d2e958Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
842047e89262Smrg	  case $host in
8421e6d2e958Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
842247e89262Smrg	      # No point in relinking DLLs because paths are not encoded
8423899129b3Smrg	      func_append notinst_deplibs " $lib"
842447e89262Smrg	      need_relink=no
842547e89262Smrg	    ;;
842647e89262Smrg	  *)
8427e6d2e958Smrg	    if test no = "$installed"; then
8428899129b3Smrg	      func_append notinst_deplibs " $lib"
842947e89262Smrg	      need_relink=yes
843047e89262Smrg	    fi
843147e89262Smrg	    ;;
843247e89262Smrg	  esac
843347e89262Smrg	  # This is a shared library
843447e89262Smrg
843547e89262Smrg	  # Warn about portability, can't link against -module's on some
843647e89262Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437e6d2e958Smrg	  dlopenmodule=
843847e89262Smrg	  for dlpremoduletest in $dlprefiles; do
843947e89262Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440e6d2e958Smrg	      dlopenmodule=$dlpremoduletest
844147e89262Smrg	      break
844247e89262Smrg	    fi
844347e89262Smrg	  done
8444e6d2e958Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
844547e89262Smrg	    echo
8446e6d2e958Smrg	    if test prog = "$linkmode"; then
844747e89262Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
844847e89262Smrg	    else
844947e89262Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
845047e89262Smrg	    fi
845147e89262Smrg	    $ECHO "*** $linklib is not portable!"
845247e89262Smrg	  fi
8453e6d2e958Smrg	  if test lib = "$linkmode" &&
8454e6d2e958Smrg	     test yes = "$hardcode_into_libs"; then
845547e89262Smrg	    # Hardcode the library path.
845647e89262Smrg	    # Skip directories that are in the system default run-time
845747e89262Smrg	    # search path.
845847e89262Smrg	    case " $sys_lib_dlsearch_path " in
845947e89262Smrg	    *" $absdir "*) ;;
846047e89262Smrg	    *)
846147e89262Smrg	      case "$compile_rpath " in
846247e89262Smrg	      *" $absdir "*) ;;
8463899129b3Smrg	      *) func_append compile_rpath " $absdir" ;;
846447e89262Smrg	      esac
846547e89262Smrg	      ;;
846647e89262Smrg	    esac
846747e89262Smrg	    case " $sys_lib_dlsearch_path " in
846847e89262Smrg	    *" $libdir "*) ;;
846947e89262Smrg	    *)
847047e89262Smrg	      case "$finalize_rpath " in
847147e89262Smrg	      *" $libdir "*) ;;
8472899129b3Smrg	      *) func_append finalize_rpath " $libdir" ;;
847347e89262Smrg	      esac
847447e89262Smrg	      ;;
847547e89262Smrg	    esac
847647e89262Smrg	  fi
847747e89262Smrg
847847e89262Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
847947e89262Smrg	    # figure out the soname
848047e89262Smrg	    set dummy $library_names
848147e89262Smrg	    shift
8482e6d2e958Smrg	    realname=$1
848347e89262Smrg	    shift
848447e89262Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
848547e89262Smrg	    # use dlname if we got it. it's perfectly good, no?
848647e89262Smrg	    if test -n "$dlname"; then
8487e6d2e958Smrg	      soname=$dlname
848847e89262Smrg	    elif test -n "$soname_spec"; then
848947e89262Smrg	      # bleh windows
849047e89262Smrg	      case $host in
8491e6d2e958Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
849247e89262Smrg	        func_arith $current - $age
849347e89262Smrg		major=$func_arith_result
8494e6d2e958Smrg		versuffix=-$major
849547e89262Smrg		;;
849647e89262Smrg	      esac
849747e89262Smrg	      eval soname=\"$soname_spec\"
849847e89262Smrg	    else
8499e6d2e958Smrg	      soname=$realname
850047e89262Smrg	    fi
850147e89262Smrg
850247e89262Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503e6d2e958Smrg	    soroot=$soname
850447e89262Smrg	    func_basename "$soroot"
8505e6d2e958Smrg	    soname=$func_basename_result
850647e89262Smrg	    func_stripname 'lib' '.dll' "$soname"
850747e89262Smrg	    newlib=libimp-$func_stripname_result.a
850847e89262Smrg
850947e89262Smrg	    # If the library has no export list, then create one now
851047e89262Smrg	    if test -f "$output_objdir/$soname-def"; then :
851147e89262Smrg	    else
8512e6d2e958Smrg	      func_verbose "extracting exported symbol list from '$soname'"
851347e89262Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
851447e89262Smrg	    fi
851547e89262Smrg
851647e89262Smrg	    # Create $newlib
851747e89262Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518e6d2e958Smrg	      func_verbose "generating import library for '$soname'"
851947e89262Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
852047e89262Smrg	    fi
852147e89262Smrg	    # make sure the library variables are pointing to the new library
852247e89262Smrg	    dir=$output_objdir
852347e89262Smrg	    linklib=$newlib
852447e89262Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
852547e89262Smrg
8526e6d2e958Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
852747e89262Smrg	    add_shlibpath=
852847e89262Smrg	    add_dir=
852947e89262Smrg	    add=
853047e89262Smrg	    lib_linked=yes
853147e89262Smrg	    case $hardcode_action in
853247e89262Smrg	    immediate | unsupported)
8533e6d2e958Smrg	      if test no = "$hardcode_direct"; then
8534e6d2e958Smrg		add=$dir/$linklib
853547e89262Smrg		case $host in
8536e6d2e958Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537e6d2e958Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
853847e89262Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539e6d2e958Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
854047e89262Smrg		  *-*-darwin* )
8541e6d2e958Smrg		    # if the lib is a (non-dlopened) module then we cannot
854247e89262Smrg		    # link against it, someone is ignoring the earlier warnings
854347e89262Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544e6d2e958Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
854547e89262Smrg		      if test "X$dlopenmodule" != "X$lib"; then
854647e89262Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547e6d2e958Smrg			if test -z "$old_library"; then
854847e89262Smrg			  echo
854947e89262Smrg			  echo "*** And there doesn't seem to be a static archive available"
855047e89262Smrg			  echo "*** The link will probably fail, sorry"
855147e89262Smrg			else
8552e6d2e958Smrg			  add=$dir/$old_library
855347e89262Smrg			fi
855447e89262Smrg		      elif test -n "$old_library"; then
8555e6d2e958Smrg			add=$dir/$old_library
855647e89262Smrg		      fi
855747e89262Smrg		    fi
855847e89262Smrg		esac
8559e6d2e958Smrg	      elif test no = "$hardcode_minus_L"; then
856047e89262Smrg		case $host in
8561e6d2e958Smrg		*-*-sunos*) add_shlibpath=$dir ;;
856247e89262Smrg		esac
8563e6d2e958Smrg		add_dir=-L$dir
8564e6d2e958Smrg		add=-l$name
8565e6d2e958Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8566e6d2e958Smrg		add_shlibpath=$dir
8567e6d2e958Smrg		add=-l$name
856847e89262Smrg	      else
856947e89262Smrg		lib_linked=no
857047e89262Smrg	      fi
857147e89262Smrg	      ;;
857247e89262Smrg	    relink)
8573e6d2e958Smrg	      if test yes = "$hardcode_direct" &&
8574e6d2e958Smrg	         test no = "$hardcode_direct_absolute"; then
8575e6d2e958Smrg		add=$dir/$linklib
8576e6d2e958Smrg	      elif test yes = "$hardcode_minus_L"; then
8577e6d2e958Smrg		add_dir=-L$absdir
857847e89262Smrg		# Try looking first in the location we're being installed to.
857947e89262Smrg		if test -n "$inst_prefix_dir"; then
858047e89262Smrg		  case $libdir in
858147e89262Smrg		    [\\/]*)
8582899129b3Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
858347e89262Smrg		      ;;
858447e89262Smrg		  esac
858547e89262Smrg		fi
8586e6d2e958Smrg		add=-l$name
8587e6d2e958Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588e6d2e958Smrg		add_shlibpath=$dir
8589e6d2e958Smrg		add=-l$name
859047e89262Smrg	      else
859147e89262Smrg		lib_linked=no
859247e89262Smrg	      fi
859347e89262Smrg	      ;;
859447e89262Smrg	    *) lib_linked=no ;;
859547e89262Smrg	    esac
859647e89262Smrg
8597e6d2e958Smrg	    if test yes != "$lib_linked"; then
859847e89262Smrg	      func_fatal_configuration "unsupported hardcode properties"
859947e89262Smrg	    fi
860047e89262Smrg
860147e89262Smrg	    if test -n "$add_shlibpath"; then
860247e89262Smrg	      case :$compile_shlibpath: in
860347e89262Smrg	      *":$add_shlibpath:"*) ;;
8604899129b3Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
860547e89262Smrg	      esac
860647e89262Smrg	    fi
8607e6d2e958Smrg	    if test prog = "$linkmode"; then
860847e89262Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
860947e89262Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
861047e89262Smrg	    else
861147e89262Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
861247e89262Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613e6d2e958Smrg	      if test yes != "$hardcode_direct" &&
8614e6d2e958Smrg		 test yes != "$hardcode_minus_L" &&
8615e6d2e958Smrg		 test yes = "$hardcode_shlibpath_var"; then
861647e89262Smrg		case :$finalize_shlibpath: in
861747e89262Smrg		*":$libdir:"*) ;;
8618899129b3Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
861947e89262Smrg		esac
862047e89262Smrg	      fi
862147e89262Smrg	    fi
862247e89262Smrg	  fi
862347e89262Smrg
8624e6d2e958Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
862547e89262Smrg	    add_shlibpath=
862647e89262Smrg	    add_dir=
862747e89262Smrg	    add=
862847e89262Smrg	    # Finalize command for both is simple: just hardcode it.
8629e6d2e958Smrg	    if test yes = "$hardcode_direct" &&
8630e6d2e958Smrg	       test no = "$hardcode_direct_absolute"; then
8631e6d2e958Smrg	      add=$libdir/$linklib
8632e6d2e958Smrg	    elif test yes = "$hardcode_minus_L"; then
8633e6d2e958Smrg	      add_dir=-L$libdir
8634e6d2e958Smrg	      add=-l$name
8635e6d2e958Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
863647e89262Smrg	      case :$finalize_shlibpath: in
863747e89262Smrg	      *":$libdir:"*) ;;
8638899129b3Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
863947e89262Smrg	      esac
8640e6d2e958Smrg	      add=-l$name
8641e6d2e958Smrg	    elif test yes = "$hardcode_automatic"; then
864247e89262Smrg	      if test -n "$inst_prefix_dir" &&
8643e6d2e958Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644e6d2e958Smrg		add=$inst_prefix_dir$libdir/$linklib
864547e89262Smrg	      else
8646e6d2e958Smrg		add=$libdir/$linklib
864747e89262Smrg	      fi
864847e89262Smrg	    else
864947e89262Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650e6d2e958Smrg	      add_dir=-L$libdir
865147e89262Smrg	      # Try looking first in the location we're being installed to.
865247e89262Smrg	      if test -n "$inst_prefix_dir"; then
865347e89262Smrg		case $libdir in
865447e89262Smrg		  [\\/]*)
8655899129b3Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
865647e89262Smrg		    ;;
865747e89262Smrg		esac
865847e89262Smrg	      fi
8659e6d2e958Smrg	      add=-l$name
866047e89262Smrg	    fi
866147e89262Smrg
8662e6d2e958Smrg	    if test prog = "$linkmode"; then
866347e89262Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
866447e89262Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
866547e89262Smrg	    else
866647e89262Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
866747e89262Smrg	      test -n "$add" && deplibs="$add $deplibs"
866847e89262Smrg	    fi
866947e89262Smrg	  fi
8670e6d2e958Smrg	elif test prog = "$linkmode"; then
867147e89262Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
867247e89262Smrg	  # is not unsupported.  This is valid on all known static and
867347e89262Smrg	  # shared platforms.
8674e6d2e958Smrg	  if test unsupported != "$hardcode_direct"; then
8675e6d2e958Smrg	    test -n "$old_library" && linklib=$old_library
867647e89262Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
867747e89262Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
867847e89262Smrg	  else
867947e89262Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
868047e89262Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
868147e89262Smrg	  fi
8682e6d2e958Smrg	elif test yes = "$build_libtool_libs"; then
868347e89262Smrg	  # Not a shared library
8684e6d2e958Smrg	  if test pass_all != "$deplibs_check_method"; then
868547e89262Smrg	    # We're trying link a shared library against a static one
868647e89262Smrg	    # but the system doesn't support it.
868747e89262Smrg
868847e89262Smrg	    # Just print a warning and add the library to dependency_libs so
868947e89262Smrg	    # that the program can be linked against the static library.
869047e89262Smrg	    echo
8691e6d2e958Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
869247e89262Smrg	    echo "*** I have the capability to make that library automatically link in when"
869347e89262Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
869447e89262Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695e6d2e958Smrg	    if test yes = "$module"; then
869647e89262Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869747e89262Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869847e89262Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
869947e89262Smrg	      if test -z "$global_symbol_pipe"; then
870047e89262Smrg		echo
870147e89262Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702e6d2e958Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
870347e89262Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704e6d2e958Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
870547e89262Smrg	      fi
8706e6d2e958Smrg	      if test no = "$build_old_libs"; then
870747e89262Smrg		build_libtool_libs=module
870847e89262Smrg		build_old_libs=yes
870947e89262Smrg	      else
871047e89262Smrg		build_libtool_libs=no
871147e89262Smrg	      fi
871247e89262Smrg	    fi
871347e89262Smrg	  else
871447e89262Smrg	    deplibs="$dir/$old_library $deplibs"
871547e89262Smrg	    link_static=yes
871647e89262Smrg	  fi
871747e89262Smrg	fi # link shared/static library?
871847e89262Smrg
8719e6d2e958Smrg	if test lib = "$linkmode"; then
872047e89262Smrg	  if test -n "$dependency_libs" &&
8721e6d2e958Smrg	     { test yes != "$hardcode_into_libs" ||
8722e6d2e958Smrg	       test yes = "$build_old_libs" ||
8723e6d2e958Smrg	       test yes = "$link_static"; }; then
872447e89262Smrg	    # Extract -R from dependency_libs
872547e89262Smrg	    temp_deplibs=
872647e89262Smrg	    for libdir in $dependency_libs; do
872747e89262Smrg	      case $libdir in
872847e89262Smrg	      -R*) func_stripname '-R' '' "$libdir"
872947e89262Smrg	           temp_xrpath=$func_stripname_result
873047e89262Smrg		   case " $xrpath " in
873147e89262Smrg		   *" $temp_xrpath "*) ;;
8732899129b3Smrg		   *) func_append xrpath " $temp_xrpath";;
873347e89262Smrg		   esac;;
8734899129b3Smrg	      *) func_append temp_deplibs " $libdir";;
873547e89262Smrg	      esac
873647e89262Smrg	    done
8737e6d2e958Smrg	    dependency_libs=$temp_deplibs
873847e89262Smrg	  fi
873947e89262Smrg
8740899129b3Smrg	  func_append newlib_search_path " $absdir"
874147e89262Smrg	  # Link against this library
8742e6d2e958Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
874347e89262Smrg	  # ... and its dependency_libs
874447e89262Smrg	  tmp_libs=
874547e89262Smrg	  for deplib in $dependency_libs; do
874647e89262Smrg	    newdependency_libs="$deplib $newdependency_libs"
8747899129b3Smrg	    case $deplib in
8748899129b3Smrg              -L*) func_stripname '-L' '' "$deplib"
8749899129b3Smrg                   func_resolve_sysroot "$func_stripname_result";;
8750899129b3Smrg              *) func_resolve_sysroot "$deplib" ;;
8751899129b3Smrg            esac
8752e6d2e958Smrg	    if $opt_preserve_dup_deps; then
875347e89262Smrg	      case "$tmp_libs " in
8754899129b3Smrg	      *" $func_resolve_sysroot_result "*)
8755899129b3Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
875647e89262Smrg	      esac
875747e89262Smrg	    fi
8758899129b3Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
875947e89262Smrg	  done
876047e89262Smrg
8761e6d2e958Smrg	  if test no != "$link_all_deplibs"; then
876247e89262Smrg	    # Add the search paths of all dependency libraries
876347e89262Smrg	    for deplib in $dependency_libs; do
876447e89262Smrg	      path=
876547e89262Smrg	      case $deplib in
8766e6d2e958Smrg	      -L*) path=$deplib ;;
876747e89262Smrg	      *.la)
8768899129b3Smrg	        func_resolve_sysroot "$deplib"
8769899129b3Smrg	        deplib=$func_resolve_sysroot_result
877047e89262Smrg	        func_dirname "$deplib" "" "."
8771899129b3Smrg		dir=$func_dirname_result
877247e89262Smrg		# We need an absolute path.
877347e89262Smrg		case $dir in
8774e6d2e958Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
877547e89262Smrg		*)
877647e89262Smrg		  absdir=`cd "$dir" && pwd`
877747e89262Smrg		  if test -z "$absdir"; then
8778e6d2e958Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779e6d2e958Smrg		    absdir=$dir
878047e89262Smrg		  fi
878147e89262Smrg		  ;;
878247e89262Smrg		esac
878347e89262Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
878447e89262Smrg		case $host in
878547e89262Smrg		*-*-darwin*)
878647e89262Smrg		  depdepl=
8787e6d2e958Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788e6d2e958Smrg		  if test -n "$deplibrary_names"; then
8789e6d2e958Smrg		    for tmp in $deplibrary_names; do
879047e89262Smrg		      depdepl=$tmp
879147e89262Smrg		    done
8792e6d2e958Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793e6d2e958Smrg		      depdepl=$absdir/$objdir/$depdepl
8794e6d2e958Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
879547e89262Smrg                      if test -z "$darwin_install_name"; then
8796e6d2e958Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
879747e89262Smrg                      fi
8798e6d2e958Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799e6d2e958Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
880047e89262Smrg		      path=
880147e89262Smrg		    fi
880247e89262Smrg		  fi
880347e89262Smrg		  ;;
880447e89262Smrg		*)
8805e6d2e958Smrg		  path=-L$absdir/$objdir
880647e89262Smrg		  ;;
880747e89262Smrg		esac
880847e89262Smrg		else
8809e6d2e958Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
881047e89262Smrg		  test -z "$libdir" && \
8811e6d2e958Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
881247e89262Smrg		  test "$absdir" != "$libdir" && \
8813e6d2e958Smrg		    func_warning "'$deplib' seems to be moved"
881447e89262Smrg
8815e6d2e958Smrg		  path=-L$absdir
881647e89262Smrg		fi
881747e89262Smrg		;;
881847e89262Smrg	      esac
881947e89262Smrg	      case " $deplibs " in
882047e89262Smrg	      *" $path "*) ;;
882147e89262Smrg	      *) deplibs="$path $deplibs" ;;
882247e89262Smrg	      esac
882347e89262Smrg	    done
882447e89262Smrg	  fi # link_all_deplibs != no
882547e89262Smrg	fi # linkmode = lib
882647e89262Smrg      done # for deplib in $libs
8827e6d2e958Smrg      if test link = "$pass"; then
8828e6d2e958Smrg	if test prog = "$linkmode"; then
882947e89262Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
883047e89262Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
883147e89262Smrg	else
883247e89262Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
883347e89262Smrg	fi
883447e89262Smrg      fi
8835e6d2e958Smrg      dependency_libs=$newdependency_libs
8836e6d2e958Smrg      if test dlpreopen = "$pass"; then
883747e89262Smrg	# Link the dlpreopened libraries before other libraries
883847e89262Smrg	for deplib in $save_deplibs; do
883947e89262Smrg	  deplibs="$deplib $deplibs"
884047e89262Smrg	done
884147e89262Smrg      fi
8842e6d2e958Smrg      if test dlopen != "$pass"; then
8843e6d2e958Smrg	test conv = "$pass" || {
884447e89262Smrg	  # Make sure lib_search_path contains only unique directories.
884547e89262Smrg	  lib_search_path=
884647e89262Smrg	  for dir in $newlib_search_path; do
884747e89262Smrg	    case "$lib_search_path " in
884847e89262Smrg	    *" $dir "*) ;;
8849899129b3Smrg	    *) func_append lib_search_path " $dir" ;;
885047e89262Smrg	    esac
885147e89262Smrg	  done
885247e89262Smrg	  newlib_search_path=
8853e6d2e958Smrg	}
885447e89262Smrg
8855e6d2e958Smrg	if test prog,link = "$linkmode,$pass"; then
885647e89262Smrg	  vars="compile_deplibs finalize_deplibs"
8857e6d2e958Smrg	else
8858e6d2e958Smrg	  vars=deplibs
885947e89262Smrg	fi
886047e89262Smrg	for var in $vars dependency_libs; do
886147e89262Smrg	  # Add libraries to $var in reverse order
886247e89262Smrg	  eval tmp_libs=\"\$$var\"
886347e89262Smrg	  new_libs=
886447e89262Smrg	  for deplib in $tmp_libs; do
886547e89262Smrg	    # FIXME: Pedantically, this is the right thing to do, so
886647e89262Smrg	    #        that some nasty dependency loop isn't accidentally
886747e89262Smrg	    #        broken:
886847e89262Smrg	    #new_libs="$deplib $new_libs"
886947e89262Smrg	    # Pragmatically, this seems to cause very few problems in
887047e89262Smrg	    # practice:
887147e89262Smrg	    case $deplib in
887247e89262Smrg	    -L*) new_libs="$deplib $new_libs" ;;
887347e89262Smrg	    -R*) ;;
887447e89262Smrg	    *)
887547e89262Smrg	      # And here is the reason: when a library appears more
887647e89262Smrg	      # than once as an explicit dependence of a library, or
887747e89262Smrg	      # is implicitly linked in more than once by the
887847e89262Smrg	      # compiler, it is considered special, and multiple
887947e89262Smrg	      # occurrences thereof are not removed.  Compare this
888047e89262Smrg	      # with having the same library being listed as a
888147e89262Smrg	      # dependency of multiple other libraries: in this case,
888247e89262Smrg	      # we know (pedantically, we assume) the library does not
888347e89262Smrg	      # need to be listed more than once, so we keep only the
888447e89262Smrg	      # last copy.  This is not always right, but it is rare
888547e89262Smrg	      # enough that we require users that really mean to play
888647e89262Smrg	      # such unportable linking tricks to link the library
888747e89262Smrg	      # using -Wl,-lname, so that libtool does not consider it
888847e89262Smrg	      # for duplicate removal.
888947e89262Smrg	      case " $specialdeplibs " in
889047e89262Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
889147e89262Smrg	      *)
889247e89262Smrg		case " $new_libs " in
889347e89262Smrg		*" $deplib "*) ;;
889447e89262Smrg		*) new_libs="$deplib $new_libs" ;;
889547e89262Smrg		esac
889647e89262Smrg		;;
889747e89262Smrg	      esac
889847e89262Smrg	      ;;
889947e89262Smrg	    esac
890047e89262Smrg	  done
890147e89262Smrg	  tmp_libs=
890247e89262Smrg	  for deplib in $new_libs; do
890347e89262Smrg	    case $deplib in
890447e89262Smrg	    -L*)
890547e89262Smrg	      case " $tmp_libs " in
890647e89262Smrg	      *" $deplib "*) ;;
8907899129b3Smrg	      *) func_append tmp_libs " $deplib" ;;
890847e89262Smrg	      esac
890947e89262Smrg	      ;;
8910899129b3Smrg	    *) func_append tmp_libs " $deplib" ;;
891147e89262Smrg	    esac
891247e89262Smrg	  done
891347e89262Smrg	  eval $var=\"$tmp_libs\"
891447e89262Smrg	done # for var
891547e89262Smrg      fi
8916e6d2e958Smrg
8917e6d2e958Smrg      # Add Sun CC postdeps if required:
8918e6d2e958Smrg      test CXX = "$tagname" && {
8919e6d2e958Smrg        case $host_os in
8920e6d2e958Smrg        linux*)
8921a392d4f3Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922e6d2e958Smrg          *Sun\ C*) # Sun C++ 5.9
8923e6d2e958Smrg            func_suncc_cstd_abi
8924e6d2e958Smrg
8925e6d2e958Smrg            if test no != "$suncc_use_cstd_abi"; then
8926e6d2e958Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8927e6d2e958Smrg            fi
8928e6d2e958Smrg            ;;
8929e6d2e958Smrg          esac
8930e6d2e958Smrg          ;;
8931e6d2e958Smrg
8932e6d2e958Smrg        solaris*)
8933e6d2e958Smrg          func_cc_basename "$CC"
8934e6d2e958Smrg          case $func_cc_basename_result in
8935e6d2e958Smrg          CC* | sunCC*)
8936e6d2e958Smrg            func_suncc_cstd_abi
8937e6d2e958Smrg
8938e6d2e958Smrg            if test no != "$suncc_use_cstd_abi"; then
8939e6d2e958Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8940e6d2e958Smrg            fi
8941e6d2e958Smrg            ;;
8942e6d2e958Smrg          esac
8943e6d2e958Smrg          ;;
8944e6d2e958Smrg        esac
8945e6d2e958Smrg      }
8946e6d2e958Smrg
894747e89262Smrg      # Last step: remove runtime libs from dependency_libs
894847e89262Smrg      # (they stay in deplibs)
894947e89262Smrg      tmp_libs=
8950e6d2e958Smrg      for i in $dependency_libs; do
895147e89262Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
895247e89262Smrg	*" $i "*)
8953e6d2e958Smrg	  i=
895447e89262Smrg	  ;;
895547e89262Smrg	esac
8956e6d2e958Smrg	if test -n "$i"; then
8957899129b3Smrg	  func_append tmp_libs " $i"
895847e89262Smrg	fi
895947e89262Smrg      done
896047e89262Smrg      dependency_libs=$tmp_libs
896147e89262Smrg    done # for pass
8962e6d2e958Smrg    if test prog = "$linkmode"; then
8963e6d2e958Smrg      dlfiles=$newdlfiles
896447e89262Smrg    fi
8965e6d2e958Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966e6d2e958Smrg      dlprefiles=$newdlprefiles
896747e89262Smrg    fi
896847e89262Smrg
896947e89262Smrg    case $linkmode in
897047e89262Smrg    oldlib)
8971e6d2e958Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972e6d2e958Smrg	func_warning "'-dlopen' is ignored for archives"
897347e89262Smrg      fi
897447e89262Smrg
897547e89262Smrg      case " $deplibs" in
897647e89262Smrg      *\ -l* | *\ -L*)
8977e6d2e958Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
897847e89262Smrg      esac
897947e89262Smrg
898047e89262Smrg      test -n "$rpath" && \
8981e6d2e958Smrg	func_warning "'-rpath' is ignored for archives"
898247e89262Smrg
898347e89262Smrg      test -n "$xrpath" && \
8984e6d2e958Smrg	func_warning "'-R' is ignored for archives"
898547e89262Smrg
898647e89262Smrg      test -n "$vinfo" && \
8987e6d2e958Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
898847e89262Smrg
898947e89262Smrg      test -n "$release" && \
8990e6d2e958Smrg	func_warning "'-release' is ignored for archives"
899147e89262Smrg
899247e89262Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993e6d2e958Smrg	func_warning "'-export-symbols' is ignored for archives"
899447e89262Smrg
899547e89262Smrg      # Now set the variables for building old libraries.
899647e89262Smrg      build_libtool_libs=no
8997e6d2e958Smrg      oldlibs=$output
8998899129b3Smrg      func_append objs "$old_deplibs"
899947e89262Smrg      ;;
900047e89262Smrg
900147e89262Smrg    lib)
9002e6d2e958Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
900347e89262Smrg      case $outputname in
900447e89262Smrg      lib*)
900547e89262Smrg	func_stripname 'lib' '.la' "$outputname"
900647e89262Smrg	name=$func_stripname_result
900747e89262Smrg	eval shared_ext=\"$shrext_cmds\"
900847e89262Smrg	eval libname=\"$libname_spec\"
900947e89262Smrg	;;
901047e89262Smrg      *)
9011e6d2e958Smrg	test no = "$module" \
9012e6d2e958Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
901347e89262Smrg
9014e6d2e958Smrg	if test no != "$need_lib_prefix"; then
901547e89262Smrg	  # Add the "lib" prefix for modules if required
901647e89262Smrg	  func_stripname '' '.la' "$outputname"
901747e89262Smrg	  name=$func_stripname_result
901847e89262Smrg	  eval shared_ext=\"$shrext_cmds\"
901947e89262Smrg	  eval libname=\"$libname_spec\"
902047e89262Smrg	else
902147e89262Smrg	  func_stripname '' '.la' "$outputname"
902247e89262Smrg	  libname=$func_stripname_result
902347e89262Smrg	fi
902447e89262Smrg	;;
902547e89262Smrg      esac
902647e89262Smrg
902747e89262Smrg      if test -n "$objs"; then
9028e6d2e958Smrg	if test pass_all != "$deplibs_check_method"; then
9029e6d2e958Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
903047e89262Smrg	else
903147e89262Smrg	  echo
903247e89262Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
903347e89262Smrg	  $ECHO "*** objects $objs is not portable!"
9034899129b3Smrg	  func_append libobjs " $objs"
903547e89262Smrg	fi
903647e89262Smrg      fi
903747e89262Smrg
9038e6d2e958Smrg      test no = "$dlself" \
9039e6d2e958Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
904047e89262Smrg
904147e89262Smrg      set dummy $rpath
904247e89262Smrg      shift
9043e6d2e958Smrg      test 1 -lt "$#" \
9044e6d2e958Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
904547e89262Smrg
9046e6d2e958Smrg      install_libdir=$1
904747e89262Smrg
904847e89262Smrg      oldlibs=
904947e89262Smrg      if test -z "$rpath"; then
9050e6d2e958Smrg	if test yes = "$build_libtool_libs"; then
905147e89262Smrg	  # Building a libtool convenience library.
9052e6d2e958Smrg	  # Some compilers have problems with a '.al' extension so
905347e89262Smrg	  # convenience libraries should have the same extension an
905447e89262Smrg	  # archive normally would.
905547e89262Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
905647e89262Smrg	  build_libtool_libs=convenience
905747e89262Smrg	  build_old_libs=yes
905847e89262Smrg	fi
905947e89262Smrg
906047e89262Smrg	test -n "$vinfo" && \
9061e6d2e958Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
906247e89262Smrg
906347e89262Smrg	test -n "$release" && \
9064e6d2e958Smrg	  func_warning "'-release' is ignored for convenience libraries"
906547e89262Smrg      else
906647e89262Smrg
906747e89262Smrg	# Parse the version information argument.
9068e6d2e958Smrg	save_ifs=$IFS; IFS=:
906947e89262Smrg	set dummy $vinfo 0 0 0
907047e89262Smrg	shift
9071e6d2e958Smrg	IFS=$save_ifs
907247e89262Smrg
907347e89262Smrg	test -n "$7" && \
9074e6d2e958Smrg	  func_fatal_help "too many parameters to '-version-info'"
907547e89262Smrg
907647e89262Smrg	# convert absolute version numbers to libtool ages
907747e89262Smrg	# this retains compatibility with .la files and attempts
907847e89262Smrg	# to make the code below a bit more comprehensible
907947e89262Smrg
908047e89262Smrg	case $vinfo_number in
908147e89262Smrg	yes)
9082e6d2e958Smrg	  number_major=$1
9083e6d2e958Smrg	  number_minor=$2
9084e6d2e958Smrg	  number_revision=$3
908547e89262Smrg	  #
908647e89262Smrg	  # There are really only two kinds -- those that
908747e89262Smrg	  # use the current revision as the major version
908847e89262Smrg	  # and those that subtract age and use age as
908947e89262Smrg	  # a minor version.  But, then there is irix
9090e6d2e958Smrg	  # that has an extra 1 added just for fun
909147e89262Smrg	  #
909247e89262Smrg	  case $version_type in
9093899129b3Smrg	  # correct linux to gnu/linux during the next big refactor
9094a392d4f3Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
909547e89262Smrg	    func_arith $number_major + $number_minor
909647e89262Smrg	    current=$func_arith_result
9097e6d2e958Smrg	    age=$number_minor
9098e6d2e958Smrg	    revision=$number_revision
909947e89262Smrg	    ;;
9100e6d2e958Smrg	  freebsd-aout|qnx|sunos)
9101e6d2e958Smrg	    current=$number_major
9102e6d2e958Smrg	    revision=$number_minor
9103e6d2e958Smrg	    age=0
910447e89262Smrg	    ;;
910547e89262Smrg	  irix|nonstopux)
910647e89262Smrg	    func_arith $number_major + $number_minor
910747e89262Smrg	    current=$func_arith_result
9108e6d2e958Smrg	    age=$number_minor
9109e6d2e958Smrg	    revision=$number_minor
911047e89262Smrg	    lt_irix_increment=no
911147e89262Smrg	    ;;
911247e89262Smrg	  esac
911347e89262Smrg	  ;;
911447e89262Smrg	no)
9115e6d2e958Smrg	  current=$1
9116e6d2e958Smrg	  revision=$2
9117e6d2e958Smrg	  age=$3
911847e89262Smrg	  ;;
911947e89262Smrg	esac
912047e89262Smrg
912147e89262Smrg	# Check that each of the things are valid numbers.
912247e89262Smrg	case $current in
912347e89262Smrg	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]) ;;
912447e89262Smrg	*)
9125e6d2e958Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126e6d2e958Smrg	  func_fatal_error "'$vinfo' is not valid version information"
912747e89262Smrg	  ;;
912847e89262Smrg	esac
912947e89262Smrg
913047e89262Smrg	case $revision in
913147e89262Smrg	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]) ;;
913247e89262Smrg	*)
9133e6d2e958Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134e6d2e958Smrg	  func_fatal_error "'$vinfo' is not valid version information"
913547e89262Smrg	  ;;
913647e89262Smrg	esac
913747e89262Smrg
913847e89262Smrg	case $age in
913947e89262Smrg	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]) ;;
914047e89262Smrg	*)
9141e6d2e958Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9142e6d2e958Smrg	  func_fatal_error "'$vinfo' is not valid version information"
914347e89262Smrg	  ;;
914447e89262Smrg	esac
914547e89262Smrg
914647e89262Smrg	if test "$age" -gt "$current"; then
9147e6d2e958Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148e6d2e958Smrg	  func_fatal_error "'$vinfo' is not valid version information"
914947e89262Smrg	fi
915047e89262Smrg
915147e89262Smrg	# Calculate the version variables.
915247e89262Smrg	major=
915347e89262Smrg	versuffix=
915447e89262Smrg	verstring=
915547e89262Smrg	case $version_type in
915647e89262Smrg	none) ;;
915747e89262Smrg
915847e89262Smrg	darwin)
915947e89262Smrg	  # Like Linux, but with the current version available in
916047e89262Smrg	  # verstring for coding it into the library header
916147e89262Smrg	  func_arith $current - $age
916247e89262Smrg	  major=.$func_arith_result
9163e6d2e958Smrg	  versuffix=$major.$age.$revision
916447e89262Smrg	  # Darwin ld doesn't like 0 for these options...
916547e89262Smrg	  func_arith $current + 1
916647e89262Smrg	  minor_current=$func_arith_result
9167e6d2e958Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
916847e89262Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169e6d2e958Smrg          # On Darwin other compilers
9170e6d2e958Smrg          case $CC in
9171e6d2e958Smrg              nagfor*)
9172e6d2e958Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173e6d2e958Smrg                  ;;
9174e6d2e958Smrg              *)
9175e6d2e958Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176e6d2e958Smrg                  ;;
9177e6d2e958Smrg          esac
917847e89262Smrg	  ;;
917947e89262Smrg
918047e89262Smrg	freebsd-aout)
9181e6d2e958Smrg	  major=.$current
9182e6d2e958Smrg	  versuffix=.$current.$revision
918347e89262Smrg	  ;;
918447e89262Smrg
9185a392d4f3Smrg	freebsd-elf | midnightbsd-elf)
9186e6d2e958Smrg	  func_arith $current - $age
9187e6d2e958Smrg	  major=.$func_arith_result
9188e6d2e958Smrg	  versuffix=$major.$age.$revision
918947e89262Smrg	  ;;
919047e89262Smrg
919147e89262Smrg	irix | nonstopux)
9192e6d2e958Smrg	  if test no = "$lt_irix_increment"; then
919347e89262Smrg	    func_arith $current - $age
919447e89262Smrg	  else
919547e89262Smrg	    func_arith $current - $age + 1
919647e89262Smrg	  fi
919747e89262Smrg	  major=$func_arith_result
919847e89262Smrg
919947e89262Smrg	  case $version_type in
920047e89262Smrg	    nonstopux) verstring_prefix=nonstopux ;;
920147e89262Smrg	    *)         verstring_prefix=sgi ;;
920247e89262Smrg	  esac
9203e6d2e958Smrg	  verstring=$verstring_prefix$major.$revision
920447e89262Smrg
920547e89262Smrg	  # Add in all the interfaces that we are compatible with.
920647e89262Smrg	  loop=$revision
9207e6d2e958Smrg	  while test 0 -ne "$loop"; do
920847e89262Smrg	    func_arith $revision - $loop
920947e89262Smrg	    iface=$func_arith_result
921047e89262Smrg	    func_arith $loop - 1
921147e89262Smrg	    loop=$func_arith_result
9212e6d2e958Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
921347e89262Smrg	  done
921447e89262Smrg
9215e6d2e958Smrg	  # Before this point, $major must not contain '.'.
921647e89262Smrg	  major=.$major
9217e6d2e958Smrg	  versuffix=$major.$revision
921847e89262Smrg	  ;;
921947e89262Smrg
9220899129b3Smrg	linux) # correct to gnu/linux during the next big refactor
922147e89262Smrg	  func_arith $current - $age
922247e89262Smrg	  major=.$func_arith_result
9223e6d2e958Smrg	  versuffix=$major.$age.$revision
922447e89262Smrg	  ;;
922547e89262Smrg
922647e89262Smrg	osf)
922747e89262Smrg	  func_arith $current - $age
922847e89262Smrg	  major=.$func_arith_result
9229e6d2e958Smrg	  versuffix=.$current.$age.$revision
9230e6d2e958Smrg	  verstring=$current.$age.$revision
923147e89262Smrg
923247e89262Smrg	  # Add in all the interfaces that we are compatible with.
923347e89262Smrg	  loop=$age
9234e6d2e958Smrg	  while test 0 -ne "$loop"; do
923547e89262Smrg	    func_arith $current - $loop
923647e89262Smrg	    iface=$func_arith_result
923747e89262Smrg	    func_arith $loop - 1
923847e89262Smrg	    loop=$func_arith_result
9239e6d2e958Smrg	    verstring=$verstring:$iface.0
924047e89262Smrg	  done
924147e89262Smrg
924247e89262Smrg	  # Make executables depend on our current version.
9243e6d2e958Smrg	  func_append verstring ":$current.0"
924447e89262Smrg	  ;;
924547e89262Smrg
924647e89262Smrg	qnx)
9247e6d2e958Smrg	  major=.$current
9248e6d2e958Smrg	  versuffix=.$current
9249e6d2e958Smrg	  ;;
9250e6d2e958Smrg
9251e6d2e958Smrg	sco)
9252e6d2e958Smrg	  major=.$current
9253e6d2e958Smrg	  versuffix=.$current
925447e89262Smrg	  ;;
925547e89262Smrg
925647e89262Smrg	sunos)
9257e6d2e958Smrg	  major=.$current
9258e6d2e958Smrg	  versuffix=.$current.$revision
925947e89262Smrg	  ;;
926047e89262Smrg
926147e89262Smrg	windows)
926247e89262Smrg	  # Use '-' rather than '.', since we only want one
9263e6d2e958Smrg	  # extension on DOS 8.3 file systems.
926447e89262Smrg	  func_arith $current - $age
926547e89262Smrg	  major=$func_arith_result
9266e6d2e958Smrg	  versuffix=-$major
926747e89262Smrg	  ;;
926847e89262Smrg
926947e89262Smrg	*)
9270e6d2e958Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
927147e89262Smrg	  ;;
927247e89262Smrg	esac
927347e89262Smrg
927447e89262Smrg	# Clear the version info if we defaulted, and they specified a release.
927547e89262Smrg	if test -z "$vinfo" && test -n "$release"; then
927647e89262Smrg	  major=
927747e89262Smrg	  case $version_type in
927847e89262Smrg	  darwin)
927947e89262Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
928047e89262Smrg	    # problems, so we reset it completely
928147e89262Smrg	    verstring=
928247e89262Smrg	    ;;
928347e89262Smrg	  *)
9284e6d2e958Smrg	    verstring=0.0
928547e89262Smrg	    ;;
928647e89262Smrg	  esac
9287e6d2e958Smrg	  if test no = "$need_version"; then
928847e89262Smrg	    versuffix=
928947e89262Smrg	  else
9290e6d2e958Smrg	    versuffix=.0.0
929147e89262Smrg	  fi
929247e89262Smrg	fi
929347e89262Smrg
929447e89262Smrg	# Remove version info from name if versioning should be avoided
9295e6d2e958Smrg	if test yes,no = "$avoid_version,$need_version"; then
929647e89262Smrg	  major=
929747e89262Smrg	  versuffix=
9298e6d2e958Smrg	  verstring=
929947e89262Smrg	fi
930047e89262Smrg
930147e89262Smrg	# Check to see if the archive will have undefined symbols.
9302e6d2e958Smrg	if test yes = "$allow_undefined"; then
9303e6d2e958Smrg	  if test unsupported = "$allow_undefined_flag"; then
9304e6d2e958Smrg	    if test yes = "$build_old_libs"; then
9305e6d2e958Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306e6d2e958Smrg	      build_libtool_libs=no
9307e6d2e958Smrg	    else
9308e6d2e958Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309e6d2e958Smrg	    fi
931047e89262Smrg	  fi
931147e89262Smrg	else
931247e89262Smrg	  # Don't allow undefined symbols.
9313e6d2e958Smrg	  allow_undefined_flag=$no_undefined_flag
931447e89262Smrg	fi
931547e89262Smrg
931647e89262Smrg      fi
931747e89262Smrg
9318e6d2e958Smrg      func_generate_dlsyms "$libname" "$libname" :
9319899129b3Smrg      func_append libobjs " $symfileobj"
9320e6d2e958Smrg      test " " = "$libobjs" && libobjs=
932147e89262Smrg
9322e6d2e958Smrg      if test relink != "$opt_mode"; then
932347e89262Smrg	# Remove our outputs, but don't remove object files since they
932447e89262Smrg	# may have been created when compiling PIC objects.
932547e89262Smrg	removelist=
932647e89262Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
932747e89262Smrg	for p in $tempremovelist; do
932847e89262Smrg	  case $p in
932947e89262Smrg	    *.$objext | *.gcno)
933047e89262Smrg	       ;;
9331e6d2e958Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332e6d2e958Smrg	       if test -n "$precious_files_regex"; then
933347e89262Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
933447e89262Smrg		 then
933547e89262Smrg		   continue
933647e89262Smrg		 fi
933747e89262Smrg	       fi
9338899129b3Smrg	       func_append removelist " $p"
933947e89262Smrg	       ;;
934047e89262Smrg	    *) ;;
934147e89262Smrg	  esac
934247e89262Smrg	done
934347e89262Smrg	test -n "$removelist" && \
934447e89262Smrg	  func_show_eval "${RM}r \$removelist"
934547e89262Smrg      fi
934647e89262Smrg
934747e89262Smrg      # Now set the variables for building old libraries.
9348e6d2e958Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349899129b3Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
935047e89262Smrg
935147e89262Smrg	# Transform .lo files to .o files.
9352e6d2e958Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
935347e89262Smrg      fi
935447e89262Smrg
935547e89262Smrg      # Eliminate all temporary directories.
935647e89262Smrg      #for path in $notinst_path; do
935747e89262Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935847e89262Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935947e89262Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
936047e89262Smrg      #done
936147e89262Smrg
936247e89262Smrg      if test -n "$xrpath"; then
936347e89262Smrg	# If the user specified any rpath flags, then add them.
936447e89262Smrg	temp_xrpath=
936547e89262Smrg	for libdir in $xrpath; do
9366899129b3Smrg	  func_replace_sysroot "$libdir"
9367899129b3Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
936847e89262Smrg	  case "$finalize_rpath " in
936947e89262Smrg	  *" $libdir "*) ;;
9370899129b3Smrg	  *) func_append finalize_rpath " $libdir" ;;
937147e89262Smrg	  esac
937247e89262Smrg	done
9373e6d2e958Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
937447e89262Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
937547e89262Smrg	fi
937647e89262Smrg      fi
937747e89262Smrg
937847e89262Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379e6d2e958Smrg      old_dlfiles=$dlfiles
938047e89262Smrg      dlfiles=
938147e89262Smrg      for lib in $old_dlfiles; do
938247e89262Smrg	case " $dlprefiles $dlfiles " in
938347e89262Smrg	*" $lib "*) ;;
9384899129b3Smrg	*) func_append dlfiles " $lib" ;;
938547e89262Smrg	esac
938647e89262Smrg      done
938747e89262Smrg
938847e89262Smrg      # Make sure dlprefiles contains only unique files
9389e6d2e958Smrg      old_dlprefiles=$dlprefiles
939047e89262Smrg      dlprefiles=
939147e89262Smrg      for lib in $old_dlprefiles; do
939247e89262Smrg	case "$dlprefiles " in
939347e89262Smrg	*" $lib "*) ;;
9394899129b3Smrg	*) func_append dlprefiles " $lib" ;;
939547e89262Smrg	esac
939647e89262Smrg      done
939747e89262Smrg
9398e6d2e958Smrg      if test yes = "$build_libtool_libs"; then
939947e89262Smrg	if test -n "$rpath"; then
940047e89262Smrg	  case $host in
940147e89262Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
940247e89262Smrg	    # these systems don't actually have a c library (as such)!
940347e89262Smrg	    ;;
940447e89262Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
940547e89262Smrg	    # Rhapsody C library is in the System framework
9406899129b3Smrg	    func_append deplibs " System.ltframework"
940747e89262Smrg	    ;;
940847e89262Smrg	  *-*-netbsd*)
940947e89262Smrg	    # Don't link with libc until the a.out ld.so is fixed.
941047e89262Smrg	    ;;
9411a392d4f3Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
941247e89262Smrg	    # Do not include libc due to us having libc/libc_r.
941347e89262Smrg	    ;;
941447e89262Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
941547e89262Smrg	    # Causes problems with __ctype
941647e89262Smrg	    ;;
941747e89262Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
941847e89262Smrg	    # Compiler inserts libc in the correct place for threads to work
941947e89262Smrg	    ;;
942047e89262Smrg	  *)
942147e89262Smrg	    # Add libc to deplibs on all other systems if necessary.
9422e6d2e958Smrg	    if test yes = "$build_libtool_need_lc"; then
9423899129b3Smrg	      func_append deplibs " -lc"
942447e89262Smrg	    fi
942547e89262Smrg	    ;;
942647e89262Smrg	  esac
942747e89262Smrg	fi
942847e89262Smrg
942947e89262Smrg	# Transform deplibs into only deplibs that can be linked in shared.
943047e89262Smrg	name_save=$name
943147e89262Smrg	libname_save=$libname
943247e89262Smrg	release_save=$release
943347e89262Smrg	versuffix_save=$versuffix
943447e89262Smrg	major_save=$major
943547e89262Smrg	# I'm not sure if I'm treating the release correctly.  I think
943647e89262Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
943747e89262Smrg	# add it in twice.  Is that correct?
9438e6d2e958Smrg	release=
9439e6d2e958Smrg	versuffix=
9440e6d2e958Smrg	major=
944147e89262Smrg	newdeplibs=
944247e89262Smrg	droppeddeps=no
944347e89262Smrg	case $deplibs_check_method in
944447e89262Smrg	pass_all)
944547e89262Smrg	  # Don't check for shared/static.  Everything works.
944647e89262Smrg	  # This might be a little naive.  We might want to check
944747e89262Smrg	  # whether the library exists or not.  But this is on
944847e89262Smrg	  # osf3 & osf4 and I'm not really sure... Just
944947e89262Smrg	  # implementing what was already the behavior.
945047e89262Smrg	  newdeplibs=$deplibs
945147e89262Smrg	  ;;
945247e89262Smrg	test_compile)
945347e89262Smrg	  # This code stresses the "libraries are programs" paradigm to its
945447e89262Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
945547e89262Smrg	  # against the deplibs as a proxy for the library.  Then we can check
945647e89262Smrg	  # whether they linked in statically or dynamically with ldd.
945747e89262Smrg	  $opt_dry_run || $RM conftest.c
945847e89262Smrg	  cat > conftest.c <<EOF
945947e89262Smrg	  int main() { return 0; }
946047e89262SmrgEOF
946147e89262Smrg	  $opt_dry_run || $RM conftest
946247e89262Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
946347e89262Smrg	    ldd_output=`ldd conftest`
946447e89262Smrg	    for i in $deplibs; do
946547e89262Smrg	      case $i in
946647e89262Smrg	      -l*)
946747e89262Smrg		func_stripname -l '' "$i"
946847e89262Smrg		name=$func_stripname_result
9469e6d2e958Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
947047e89262Smrg		  case " $predeps $postdeps " in
947147e89262Smrg		  *" $i "*)
9472899129b3Smrg		    func_append newdeplibs " $i"
9473e6d2e958Smrg		    i=
947447e89262Smrg		    ;;
947547e89262Smrg		  esac
947647e89262Smrg		fi
9477e6d2e958Smrg		if test -n "$i"; then
947847e89262Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
947947e89262Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
948047e89262Smrg		  set dummy $deplib_matches; shift
948147e89262Smrg		  deplib_match=$1
9482e6d2e958Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483899129b3Smrg		    func_append newdeplibs " $i"
948447e89262Smrg		  else
948547e89262Smrg		    droppeddeps=yes
948647e89262Smrg		    echo
948747e89262Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948847e89262Smrg		    echo "*** I have the capability to make that library automatically link in when"
948947e89262Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
949047e89262Smrg		    echo "*** shared version of the library, which I believe you do not have"
949147e89262Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
949247e89262Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
949347e89262Smrg		  fi
949447e89262Smrg		fi
949547e89262Smrg		;;
949647e89262Smrg	      *)
9497899129b3Smrg		func_append newdeplibs " $i"
949847e89262Smrg		;;
949947e89262Smrg	      esac
950047e89262Smrg	    done
950147e89262Smrg	  else
950247e89262Smrg	    # Error occurred in the first compile.  Let's try to salvage
950347e89262Smrg	    # the situation: Compile a separate program for each library.
950447e89262Smrg	    for i in $deplibs; do
950547e89262Smrg	      case $i in
950647e89262Smrg	      -l*)
950747e89262Smrg		func_stripname -l '' "$i"
950847e89262Smrg		name=$func_stripname_result
950947e89262Smrg		$opt_dry_run || $RM conftest
951047e89262Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
951147e89262Smrg		  ldd_output=`ldd conftest`
9512e6d2e958Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
951347e89262Smrg		    case " $predeps $postdeps " in
951447e89262Smrg		    *" $i "*)
9515899129b3Smrg		      func_append newdeplibs " $i"
9516e6d2e958Smrg		      i=
951747e89262Smrg		      ;;
951847e89262Smrg		    esac
951947e89262Smrg		  fi
9520e6d2e958Smrg		  if test -n "$i"; then
952147e89262Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
952247e89262Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
952347e89262Smrg		    set dummy $deplib_matches; shift
952447e89262Smrg		    deplib_match=$1
9525e6d2e958Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526899129b3Smrg		      func_append newdeplibs " $i"
952747e89262Smrg		    else
952847e89262Smrg		      droppeddeps=yes
952947e89262Smrg		      echo
953047e89262Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
953147e89262Smrg		      echo "*** I have the capability to make that library automatically link in when"
953247e89262Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
953347e89262Smrg		      echo "*** shared version of the library, which you do not appear to have"
953447e89262Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
953547e89262Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
953647e89262Smrg		    fi
953747e89262Smrg		  fi
953847e89262Smrg		else
953947e89262Smrg		  droppeddeps=yes
954047e89262Smrg		  echo
954147e89262Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
954247e89262Smrg		  echo "*** make it link in!  You will probably need to install it or some"
954347e89262Smrg		  echo "*** library that it depends on before this library will be fully"
954447e89262Smrg		  echo "*** functional.  Installing it before continuing would be even better."
954547e89262Smrg		fi
954647e89262Smrg		;;
954747e89262Smrg	      *)
9548899129b3Smrg		func_append newdeplibs " $i"
954947e89262Smrg		;;
955047e89262Smrg	      esac
955147e89262Smrg	    done
955247e89262Smrg	  fi
955347e89262Smrg	  ;;
955447e89262Smrg	file_magic*)
955547e89262Smrg	  set dummy $deplibs_check_method; shift
955647e89262Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
955747e89262Smrg	  for a_deplib in $deplibs; do
955847e89262Smrg	    case $a_deplib in
955947e89262Smrg	    -l*)
956047e89262Smrg	      func_stripname -l '' "$a_deplib"
956147e89262Smrg	      name=$func_stripname_result
9562e6d2e958Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
956347e89262Smrg		case " $predeps $postdeps " in
956447e89262Smrg		*" $a_deplib "*)
9565899129b3Smrg		  func_append newdeplibs " $a_deplib"
9566e6d2e958Smrg		  a_deplib=
956747e89262Smrg		  ;;
956847e89262Smrg		esac
956947e89262Smrg	      fi
9570e6d2e958Smrg	      if test -n "$a_deplib"; then
957147e89262Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572899129b3Smrg		if test -n "$file_magic_glob"; then
9573899129b3Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574899129b3Smrg		else
9575899129b3Smrg		  libnameglob=$libname
9576899129b3Smrg		fi
9577e6d2e958Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
957847e89262Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579e6d2e958Smrg		  if test yes = "$want_nocaseglob"; then
9580899129b3Smrg		    shopt -s nocaseglob
9581899129b3Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582899129b3Smrg		    $nocaseglob
9583899129b3Smrg		  else
9584899129b3Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585899129b3Smrg		  fi
958647e89262Smrg		  for potent_lib in $potential_libs; do
958747e89262Smrg		      # Follow soft links.
958847e89262Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
958947e89262Smrg			 $GREP " -> " >/dev/null; then
959047e89262Smrg			continue
959147e89262Smrg		      fi
959247e89262Smrg		      # The statement above tries to avoid entering an
959347e89262Smrg		      # endless loop below, in case of cyclic links.
959447e89262Smrg		      # We might still enter an endless loop, since a link
959547e89262Smrg		      # loop can be closed while we follow links,
959647e89262Smrg		      # but so what?
9597e6d2e958Smrg		      potlib=$potent_lib
959847e89262Smrg		      while test -h "$potlib" 2>/dev/null; do
9599e6d2e958Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
960047e89262Smrg			case $potliblink in
9601e6d2e958Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602e6d2e958Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
960347e89262Smrg			esac
960447e89262Smrg		      done
960547e89262Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
960647e89262Smrg			 $SED -e 10q |
960747e89262Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608899129b3Smrg			func_append newdeplibs " $a_deplib"
9609e6d2e958Smrg			a_deplib=
961047e89262Smrg			break 2
961147e89262Smrg		      fi
961247e89262Smrg		  done
961347e89262Smrg		done
961447e89262Smrg	      fi
9615e6d2e958Smrg	      if test -n "$a_deplib"; then
961647e89262Smrg		droppeddeps=yes
961747e89262Smrg		echo
961847e89262Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961947e89262Smrg		echo "*** I have the capability to make that library automatically link in when"
962047e89262Smrg		echo "*** you link to this library.  But I can only do this if you have a"
962147e89262Smrg		echo "*** shared version of the library, which you do not appear to have"
962247e89262Smrg		echo "*** because I did check the linker path looking for a file starting"
9623e6d2e958Smrg		if test -z "$potlib"; then
962447e89262Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
962547e89262Smrg		else
962647e89262Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
962747e89262Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
962847e89262Smrg		fi
962947e89262Smrg	      fi
963047e89262Smrg	      ;;
963147e89262Smrg	    *)
963247e89262Smrg	      # Add a -L argument.
9633899129b3Smrg	      func_append newdeplibs " $a_deplib"
963447e89262Smrg	      ;;
963547e89262Smrg	    esac
963647e89262Smrg	  done # Gone through all deplibs.
963747e89262Smrg	  ;;
963847e89262Smrg	match_pattern*)
963947e89262Smrg	  set dummy $deplibs_check_method; shift
964047e89262Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
964147e89262Smrg	  for a_deplib in $deplibs; do
964247e89262Smrg	    case $a_deplib in
964347e89262Smrg	    -l*)
964447e89262Smrg	      func_stripname -l '' "$a_deplib"
964547e89262Smrg	      name=$func_stripname_result
9646e6d2e958Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
964747e89262Smrg		case " $predeps $postdeps " in
964847e89262Smrg		*" $a_deplib "*)
9649899129b3Smrg		  func_append newdeplibs " $a_deplib"
9650e6d2e958Smrg		  a_deplib=
965147e89262Smrg		  ;;
965247e89262Smrg		esac
965347e89262Smrg	      fi
9654e6d2e958Smrg	      if test -n "$a_deplib"; then
965547e89262Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
965647e89262Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
965747e89262Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
965847e89262Smrg		  for potent_lib in $potential_libs; do
9659e6d2e958Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
966047e89262Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
966147e89262Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662899129b3Smrg		      func_append newdeplibs " $a_deplib"
9663e6d2e958Smrg		      a_deplib=
966447e89262Smrg		      break 2
966547e89262Smrg		    fi
966647e89262Smrg		  done
966747e89262Smrg		done
966847e89262Smrg	      fi
9669e6d2e958Smrg	      if test -n "$a_deplib"; then
967047e89262Smrg		droppeddeps=yes
967147e89262Smrg		echo
967247e89262Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
967347e89262Smrg		echo "*** I have the capability to make that library automatically link in when"
967447e89262Smrg		echo "*** you link to this library.  But I can only do this if you have a"
967547e89262Smrg		echo "*** shared version of the library, which you do not appear to have"
967647e89262Smrg		echo "*** because I did check the linker path looking for a file starting"
9677e6d2e958Smrg		if test -z "$potlib"; then
967847e89262Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
967947e89262Smrg		else
968047e89262Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
968147e89262Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
968247e89262Smrg		fi
968347e89262Smrg	      fi
968447e89262Smrg	      ;;
968547e89262Smrg	    *)
968647e89262Smrg	      # Add a -L argument.
9687899129b3Smrg	      func_append newdeplibs " $a_deplib"
968847e89262Smrg	      ;;
968947e89262Smrg	    esac
969047e89262Smrg	  done # Gone through all deplibs.
969147e89262Smrg	  ;;
969247e89262Smrg	none | unknown | *)
9693e6d2e958Smrg	  newdeplibs=
969447e89262Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695e6d2e958Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696e6d2e958Smrg	    for i in $predeps $postdeps; do
969747e89262Smrg	      # can't use Xsed below, because $i might contain '/'
9698e6d2e958Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
969947e89262Smrg	    done
970047e89262Smrg	  fi
970147e89262Smrg	  case $tmp_deplibs in
970247e89262Smrg	  *[!\	\ ]*)
970347e89262Smrg	    echo
9704e6d2e958Smrg	    if test none = "$deplibs_check_method"; then
970547e89262Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
970647e89262Smrg	    else
970747e89262Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
970847e89262Smrg	    fi
970947e89262Smrg	    echo "*** All declared inter-library dependencies are being dropped."
971047e89262Smrg	    droppeddeps=yes
971147e89262Smrg	    ;;
971247e89262Smrg	  esac
971347e89262Smrg	  ;;
971447e89262Smrg	esac
971547e89262Smrg	versuffix=$versuffix_save
971647e89262Smrg	major=$major_save
971747e89262Smrg	release=$release_save
971847e89262Smrg	libname=$libname_save
971947e89262Smrg	name=$name_save
972047e89262Smrg
972147e89262Smrg	case $host in
972247e89262Smrg	*-*-rhapsody* | *-*-darwin1.[012])
972347e89262Smrg	  # On Rhapsody replace the C library with the System framework
972447e89262Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
972547e89262Smrg	  ;;
972647e89262Smrg	esac
972747e89262Smrg
9728e6d2e958Smrg	if test yes = "$droppeddeps"; then
9729e6d2e958Smrg	  if test yes = "$module"; then
973047e89262Smrg	    echo
973147e89262Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
973247e89262Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
973347e89262Smrg	    echo "*** a static module, that should work as long as the dlopening"
973447e89262Smrg	    echo "*** application is linked with the -dlopen flag."
973547e89262Smrg	    if test -z "$global_symbol_pipe"; then
973647e89262Smrg	      echo
973747e89262Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738e6d2e958Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973947e89262Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740e6d2e958Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
974147e89262Smrg	    fi
9742e6d2e958Smrg	    if test no = "$build_old_libs"; then
9743e6d2e958Smrg	      oldlibs=$output_objdir/$libname.$libext
974447e89262Smrg	      build_libtool_libs=module
974547e89262Smrg	      build_old_libs=yes
974647e89262Smrg	    else
974747e89262Smrg	      build_libtool_libs=no
974847e89262Smrg	    fi
974947e89262Smrg	  else
975047e89262Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
975147e89262Smrg	    echo "*** automatically added whenever a program is linked with this library"
975247e89262Smrg	    echo "*** or is declared to -dlopen it."
975347e89262Smrg
9754e6d2e958Smrg	    if test no = "$allow_undefined"; then
975547e89262Smrg	      echo
975647e89262Smrg	      echo "*** Since this library must not contain undefined symbols,"
975747e89262Smrg	      echo "*** because either the platform does not support them or"
975847e89262Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975947e89262Smrg	      echo "*** libtool will only create a static version of it."
9760e6d2e958Smrg	      if test no = "$build_old_libs"; then
9761e6d2e958Smrg		oldlibs=$output_objdir/$libname.$libext
976247e89262Smrg		build_libtool_libs=module
976347e89262Smrg		build_old_libs=yes
976447e89262Smrg	      else
976547e89262Smrg		build_libtool_libs=no
976647e89262Smrg	      fi
976747e89262Smrg	    fi
976847e89262Smrg	  fi
976947e89262Smrg	fi
977047e89262Smrg	# Done checking deplibs!
977147e89262Smrg	deplibs=$newdeplibs
977247e89262Smrg      fi
977347e89262Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
977447e89262Smrg      case $host in
977547e89262Smrg	*-*-darwin*)
977647e89262Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977747e89262Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977847e89262Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977947e89262Smrg	  ;;
978047e89262Smrg      esac
978147e89262Smrg
978247e89262Smrg      # move library search paths that coincide with paths to not yet
978347e89262Smrg      # installed libraries to the beginning of the library search list
978447e89262Smrg      new_libs=
978547e89262Smrg      for path in $notinst_path; do
978647e89262Smrg	case " $new_libs " in
978747e89262Smrg	*" -L$path/$objdir "*) ;;
978847e89262Smrg	*)
978947e89262Smrg	  case " $deplibs " in
979047e89262Smrg	  *" -L$path/$objdir "*)
9791899129b3Smrg	    func_append new_libs " -L$path/$objdir" ;;
979247e89262Smrg	  esac
979347e89262Smrg	  ;;
979447e89262Smrg	esac
979547e89262Smrg      done
979647e89262Smrg      for deplib in $deplibs; do
979747e89262Smrg	case $deplib in
979847e89262Smrg	-L*)
979947e89262Smrg	  case " $new_libs " in
980047e89262Smrg	  *" $deplib "*) ;;
9801899129b3Smrg	  *) func_append new_libs " $deplib" ;;
980247e89262Smrg	  esac
980347e89262Smrg	  ;;
9804899129b3Smrg	*) func_append new_libs " $deplib" ;;
980547e89262Smrg	esac
980647e89262Smrg      done
9807e6d2e958Smrg      deplibs=$new_libs
980847e89262Smrg
980947e89262Smrg      # All the library-specific variables (install_libdir is set above).
981047e89262Smrg      library_names=
981147e89262Smrg      old_library=
981247e89262Smrg      dlname=
981347e89262Smrg
981447e89262Smrg      # Test again, we may have decided not to build it any more
9815e6d2e958Smrg      if test yes = "$build_libtool_libs"; then
9816e6d2e958Smrg	# Remove $wl instances when linking with ld.
9817899129b3Smrg	# FIXME: should test the right _cmds variable.
9818899129b3Smrg	case $archive_cmds in
9819899129b3Smrg	  *\$LD\ *) wl= ;;
9820899129b3Smrg        esac
9821e6d2e958Smrg	if test yes = "$hardcode_into_libs"; then
982247e89262Smrg	  # Hardcode the library paths
982347e89262Smrg	  hardcode_libdirs=
982447e89262Smrg	  dep_rpath=
9825e6d2e958Smrg	  rpath=$finalize_rpath
9826e6d2e958Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
982747e89262Smrg	  for libdir in $rpath; do
982847e89262Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
982947e89262Smrg	      if test -n "$hardcode_libdir_separator"; then
9830899129b3Smrg		func_replace_sysroot "$libdir"
9831899129b3Smrg		libdir=$func_replace_sysroot_result
983247e89262Smrg		if test -z "$hardcode_libdirs"; then
9833e6d2e958Smrg		  hardcode_libdirs=$libdir
983447e89262Smrg		else
983547e89262Smrg		  # Just accumulate the unique libdirs.
983647e89262Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
983747e89262Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
983847e89262Smrg		    ;;
983947e89262Smrg		  *)
9840899129b3Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
984147e89262Smrg		    ;;
984247e89262Smrg		  esac
984347e89262Smrg		fi
984447e89262Smrg	      else
984547e89262Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846899129b3Smrg		func_append dep_rpath " $flag"
984747e89262Smrg	      fi
984847e89262Smrg	    elif test -n "$runpath_var"; then
984947e89262Smrg	      case "$perm_rpath " in
985047e89262Smrg	      *" $libdir "*) ;;
9851899129b3Smrg	      *) func_append perm_rpath " $libdir" ;;
985247e89262Smrg	      esac
985347e89262Smrg	    fi
985447e89262Smrg	  done
985547e89262Smrg	  # Substitute the hardcoded libdirs into the rpath.
985647e89262Smrg	  if test -n "$hardcode_libdir_separator" &&
985747e89262Smrg	     test -n "$hardcode_libdirs"; then
9858e6d2e958Smrg	    libdir=$hardcode_libdirs
9859899129b3Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
986047e89262Smrg	  fi
986147e89262Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
986247e89262Smrg	    # We should set the runpath_var.
986347e89262Smrg	    rpath=
986447e89262Smrg	    for dir in $perm_rpath; do
9865899129b3Smrg	      func_append rpath "$dir:"
986647e89262Smrg	    done
986747e89262Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
986847e89262Smrg	  fi
986947e89262Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
987047e89262Smrg	fi
9871bd1da9d7Smrg
9872e6d2e958Smrg	shlibpath=$finalize_shlibpath
9873e6d2e958Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
987447e89262Smrg	if test -n "$shlibpath"; then
987547e89262Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
987647e89262Smrg	fi
9877bd1da9d7Smrg
987847e89262Smrg	# Get the real and link names of the library.
987947e89262Smrg	eval shared_ext=\"$shrext_cmds\"
988047e89262Smrg	eval library_names=\"$library_names_spec\"
988147e89262Smrg	set dummy $library_names
988247e89262Smrg	shift
9883e6d2e958Smrg	realname=$1
988447e89262Smrg	shift
9885bd1da9d7Smrg
988647e89262Smrg	if test -n "$soname_spec"; then
988747e89262Smrg	  eval soname=\"$soname_spec\"
988847e89262Smrg	else
9889e6d2e958Smrg	  soname=$realname
989047e89262Smrg	fi
989147e89262Smrg	if test -z "$dlname"; then
989247e89262Smrg	  dlname=$soname
989347e89262Smrg	fi
9894bd1da9d7Smrg
9895e6d2e958Smrg	lib=$output_objdir/$realname
989647e89262Smrg	linknames=
989747e89262Smrg	for link
989847e89262Smrg	do
9899899129b3Smrg	  func_append linknames " $link"
990047e89262Smrg	done
9901bd1da9d7Smrg
990247e89262Smrg	# Use standard objects if they are pic
990347e89262Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
990447e89262Smrg	test "X$libobjs" = "X " && libobjs=
9905bd1da9d7Smrg
990647e89262Smrg	delfiles=
990747e89262Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
990847e89262Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909e6d2e958Smrg	  export_symbols=$output_objdir/$libname.uexp
9910899129b3Smrg	  func_append delfiles " $export_symbols"
991147e89262Smrg	fi
9912bd1da9d7Smrg
991347e89262Smrg	orig_export_symbols=
991447e89262Smrg	case $host_os in
991547e89262Smrg	cygwin* | mingw* | cegcc*)
991647e89262Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
991747e89262Smrg	    # exporting using user supplied symfile
9918e6d2e958Smrg	    func_dll_def_p "$export_symbols" || {
991947e89262Smrg	      # and it's NOT already a .def file. Must figure out
992047e89262Smrg	      # which of the given symbols are data symbols and tag
992147e89262Smrg	      # them as such. So, trigger use of export_symbols_cmds.
992247e89262Smrg	      # export_symbols gets reassigned inside the "prepare
992347e89262Smrg	      # the list of exported symbols" if statement, so the
992447e89262Smrg	      # include_expsyms logic still works.
9925e6d2e958Smrg	      orig_export_symbols=$export_symbols
992647e89262Smrg	      export_symbols=
992747e89262Smrg	      always_export_symbols=yes
9928e6d2e958Smrg	    }
992947e89262Smrg	  fi
993047e89262Smrg	  ;;
993147e89262Smrg	esac
9932bd1da9d7Smrg
993347e89262Smrg	# Prepare the list of exported symbols
993447e89262Smrg	if test -z "$export_symbols"; then
9935e6d2e958Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936e6d2e958Smrg	    func_verbose "generating symbol list for '$libname.la'"
9937e6d2e958Smrg	    export_symbols=$output_objdir/$libname.exp
993847e89262Smrg	    $opt_dry_run || $RM $export_symbols
993947e89262Smrg	    cmds=$export_symbols_cmds
9940e6d2e958Smrg	    save_ifs=$IFS; IFS='~'
9941899129b3Smrg	    for cmd1 in $cmds; do
9942e6d2e958Smrg	      IFS=$save_ifs
9943899129b3Smrg	      # Take the normal branch if the nm_file_list_spec branch
9944899129b3Smrg	      # doesn't work or if tool conversion is not needed.
9945899129b3Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946899129b3Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947899129b3Smrg		  try_normal_branch=yes
9948899129b3Smrg		  eval cmd=\"$cmd1\"
9949899129b3Smrg		  func_len " $cmd"
9950899129b3Smrg		  len=$func_len_result
9951899129b3Smrg		  ;;
9952899129b3Smrg		*)
9953899129b3Smrg		  try_normal_branch=no
9954899129b3Smrg		  ;;
9955899129b3Smrg	      esac
9956e6d2e958Smrg	      if test yes = "$try_normal_branch" \
9957899129b3Smrg		 && { test "$len" -lt "$max_cmd_len" \
9958899129b3Smrg		      || test "$max_cmd_len" -le -1; }
9959899129b3Smrg	      then
9960899129b3Smrg		func_show_eval "$cmd" 'exit $?'
9961899129b3Smrg		skipped_export=false
9962899129b3Smrg	      elif test -n "$nm_file_list_spec"; then
9963899129b3Smrg		func_basename "$output"
9964899129b3Smrg		output_la=$func_basename_result
9965899129b3Smrg		save_libobjs=$libobjs
9966899129b3Smrg		save_output=$output
9967e6d2e958Smrg		output=$output_objdir/$output_la.nm
9968899129b3Smrg		func_to_tool_file "$output"
9969899129b3Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970899129b3Smrg		func_append delfiles " $output"
9971899129b3Smrg		func_verbose "creating $NM input file list: $output"
9972899129b3Smrg		for obj in $save_libobjs; do
9973899129b3Smrg		  func_to_tool_file "$obj"
9974899129b3Smrg		  $ECHO "$func_to_tool_file_result"
9975899129b3Smrg		done > "$output"
9976899129b3Smrg		eval cmd=\"$cmd1\"
997747e89262Smrg		func_show_eval "$cmd" 'exit $?'
9978899129b3Smrg		output=$save_output
9979899129b3Smrg		libobjs=$save_libobjs
998047e89262Smrg		skipped_export=false
998147e89262Smrg	      else
998247e89262Smrg		# The command line is too long to execute in one step.
998347e89262Smrg		func_verbose "using reloadable object file for export list..."
998447e89262Smrg		skipped_export=:
998547e89262Smrg		# Break out early, otherwise skipped_export may be
998647e89262Smrg		# set to false by a later but shorter cmd.
998747e89262Smrg		break
998847e89262Smrg	      fi
998947e89262Smrg	    done
9990e6d2e958Smrg	    IFS=$save_ifs
9991e6d2e958Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
999247e89262Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
999347e89262Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
999447e89262Smrg	    fi
999547e89262Smrg	  fi
999647e89262Smrg	fi
9997bd1da9d7Smrg
999847e89262Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999e6d2e958Smrg	  tmp_export_symbols=$export_symbols
10000e6d2e958Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1000147e89262Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1000247e89262Smrg	fi
10003bd1da9d7Smrg
10004e6d2e958Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
1000547e89262Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006e6d2e958Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1000747e89262Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008e6d2e958Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
1000947e89262Smrg	  # though. Also, the filter scales superlinearly with the number of
1001047e89262Smrg	  # global variables. join(1) would be nice here, but unfortunately
1001147e89262Smrg	  # isn't a blessed tool.
1001247e89262Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013899129b3Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1001447e89262Smrg	  export_symbols=$output_objdir/$libname.def
1001547e89262Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016bd1da9d7Smrg	fi
10017bd1da9d7Smrg
1001847e89262Smrg	tmp_deplibs=
1001947e89262Smrg	for test_deplib in $deplibs; do
1002047e89262Smrg	  case " $convenience " in
1002147e89262Smrg	  *" $test_deplib "*) ;;
1002247e89262Smrg	  *)
10023899129b3Smrg	    func_append tmp_deplibs " $test_deplib"
1002447e89262Smrg	    ;;
1002547e89262Smrg	  esac
1002647e89262Smrg	done
10027e6d2e958Smrg	deplibs=$tmp_deplibs
10028bd1da9d7Smrg
1002947e89262Smrg	if test -n "$convenience"; then
1003047e89262Smrg	  if test -n "$whole_archive_flag_spec" &&
10031e6d2e958Smrg	    test yes = "$compiler_needs_object" &&
1003247e89262Smrg	    test -z "$libobjs"; then
1003347e89262Smrg	    # extract the archives, so we have objects to list.
1003447e89262Smrg	    # TODO: could optimize this to just extract one archive.
1003547e89262Smrg	    whole_archive_flag_spec=
1003647e89262Smrg	  fi
1003747e89262Smrg	  if test -n "$whole_archive_flag_spec"; then
1003847e89262Smrg	    save_libobjs=$libobjs
1003947e89262Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1004047e89262Smrg	    test "X$libobjs" = "X " && libobjs=
1004147e89262Smrg	  else
10042e6d2e958Smrg	    gentop=$output_objdir/${outputname}x
10043899129b3Smrg	    func_append generated " $gentop"
10044bd1da9d7Smrg
1004547e89262Smrg	    func_extract_archives $gentop $convenience
10046899129b3Smrg	    func_append libobjs " $func_extract_archives_result"
1004747e89262Smrg	    test "X$libobjs" = "X " && libobjs=
1004847e89262Smrg	  fi
1004947e89262Smrg	fi
10050bd1da9d7Smrg
10051e6d2e958Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
1005247e89262Smrg	  eval flag=\"$thread_safe_flag_spec\"
10053899129b3Smrg	  func_append linker_flags " $flag"
1005447e89262Smrg	fi
10055bd1da9d7Smrg
1005647e89262Smrg	# Make a backup of the uninstalled library when relinking
10057e6d2e958Smrg	if test relink = "$opt_mode"; then
1005847e89262Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059bd1da9d7Smrg	fi
10060bd1da9d7Smrg
1006147e89262Smrg	# Do each of the archive commands.
10062e6d2e958Smrg	if test yes = "$module" && test -n "$module_cmds"; then
1006347e89262Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1006447e89262Smrg	    eval test_cmds=\"$module_expsym_cmds\"
1006547e89262Smrg	    cmds=$module_expsym_cmds
1006647e89262Smrg	  else
1006747e89262Smrg	    eval test_cmds=\"$module_cmds\"
1006847e89262Smrg	    cmds=$module_cmds
1006947e89262Smrg	  fi
1007047e89262Smrg	else
1007147e89262Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1007247e89262Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
1007347e89262Smrg	    cmds=$archive_expsym_cmds
1007447e89262Smrg	  else
1007547e89262Smrg	    eval test_cmds=\"$archive_cmds\"
1007647e89262Smrg	    cmds=$archive_cmds
1007747e89262Smrg	  fi
10078bd1da9d7Smrg	fi
10079bd1da9d7Smrg
10080e6d2e958Smrg	if test : != "$skipped_export" &&
1008147e89262Smrg	   func_len " $test_cmds" &&
1008247e89262Smrg	   len=$func_len_result &&
1008347e89262Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1008447e89262Smrg	  :
1008547e89262Smrg	else
1008647e89262Smrg	  # The command line is too long to link in one step, link piecewise
1008747e89262Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
1008847e89262Smrg	  # script.
10089bd1da9d7Smrg
1009047e89262Smrg	  # Save the value of $output and $libobjs because we want to
1009147e89262Smrg	  # use them later.  If we have whole_archive_flag_spec, we
1009247e89262Smrg	  # want to use save_libobjs as it was before
1009347e89262Smrg	  # whole_archive_flag_spec was expanded, because we can't
1009447e89262Smrg	  # assume the linker understands whole_archive_flag_spec.
1009547e89262Smrg	  # This may have to be revisited, in case too many
1009647e89262Smrg	  # convenience libraries get linked in and end up exceeding
1009747e89262Smrg	  # the spec.
1009847e89262Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
1009947e89262Smrg	    save_libobjs=$libobjs
1010047e89262Smrg	  fi
1010147e89262Smrg	  save_output=$output
1010247e89262Smrg	  func_basename "$output"
1010347e89262Smrg	  output_la=$func_basename_result
10104bd1da9d7Smrg
1010547e89262Smrg	  # Clear the reloadable object creation command queue and
1010647e89262Smrg	  # initialize k to one.
1010747e89262Smrg	  test_cmds=
1010847e89262Smrg	  concat_cmds=
1010947e89262Smrg	  objlist=
1011047e89262Smrg	  last_robj=
1011147e89262Smrg	  k=1
10112bd1da9d7Smrg
10113e6d2e958Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114e6d2e958Smrg	    output=$output_objdir/$output_la.lnkscript
1011547e89262Smrg	    func_verbose "creating GNU ld script: $output"
1011647e89262Smrg	    echo 'INPUT (' > $output
1011747e89262Smrg	    for obj in $save_libobjs
1011847e89262Smrg	    do
10119899129b3Smrg	      func_to_tool_file "$obj"
10120899129b3Smrg	      $ECHO "$func_to_tool_file_result" >> $output
1012147e89262Smrg	    done
1012247e89262Smrg	    echo ')' >> $output
10123899129b3Smrg	    func_append delfiles " $output"
10124899129b3Smrg	    func_to_tool_file "$output"
10125899129b3Smrg	    output=$func_to_tool_file_result
10126e6d2e958Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127e6d2e958Smrg	    output=$output_objdir/$output_la.lnk
1012847e89262Smrg	    func_verbose "creating linker input file list: $output"
1012947e89262Smrg	    : > $output
1013047e89262Smrg	    set x $save_libobjs
1013147e89262Smrg	    shift
1013247e89262Smrg	    firstobj=
10133e6d2e958Smrg	    if test yes = "$compiler_needs_object"; then
1013447e89262Smrg	      firstobj="$1 "
1013547e89262Smrg	      shift
1013647e89262Smrg	    fi
1013747e89262Smrg	    for obj
1013847e89262Smrg	    do
10139899129b3Smrg	      func_to_tool_file "$obj"
10140899129b3Smrg	      $ECHO "$func_to_tool_file_result" >> $output
1014147e89262Smrg	    done
10142899129b3Smrg	    func_append delfiles " $output"
10143899129b3Smrg	    func_to_tool_file "$output"
10144899129b3Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
1014547e89262Smrg	  else
1014647e89262Smrg	    if test -n "$save_libobjs"; then
1014747e89262Smrg	      func_verbose "creating reloadable object files..."
10148e6d2e958Smrg	      output=$output_objdir/$output_la-$k.$objext
1014947e89262Smrg	      eval test_cmds=\"$reload_cmds\"
1015047e89262Smrg	      func_len " $test_cmds"
1015147e89262Smrg	      len0=$func_len_result
1015247e89262Smrg	      len=$len0
1015347e89262Smrg
1015447e89262Smrg	      # Loop over the list of objects to be linked.
1015547e89262Smrg	      for obj in $save_libobjs
1015647e89262Smrg	      do
1015747e89262Smrg		func_len " $obj"
1015847e89262Smrg		func_arith $len + $func_len_result
1015947e89262Smrg		len=$func_arith_result
10160e6d2e958Smrg		if test -z "$objlist" ||
1016147e89262Smrg		   test "$len" -lt "$max_cmd_len"; then
1016247e89262Smrg		  func_append objlist " $obj"
1016347e89262Smrg		else
1016447e89262Smrg		  # The command $test_cmds is almost too long, add a
1016547e89262Smrg		  # command to the queue.
10166e6d2e958Smrg		  if test 1 -eq "$k"; then
1016747e89262Smrg		    # The first file doesn't have a previous command to add.
1016847e89262Smrg		    reload_objs=$objlist
1016947e89262Smrg		    eval concat_cmds=\"$reload_cmds\"
1017047e89262Smrg		  else
1017147e89262Smrg		    # All subsequent reloadable object files will link in
1017247e89262Smrg		    # the last one created.
1017347e89262Smrg		    reload_objs="$objlist $last_robj"
1017447e89262Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
1017547e89262Smrg		  fi
10176e6d2e958Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
1017747e89262Smrg		  func_arith $k + 1
1017847e89262Smrg		  k=$func_arith_result
10179e6d2e958Smrg		  output=$output_objdir/$output_la-$k.$objext
1018047e89262Smrg		  objlist=" $obj"
1018147e89262Smrg		  func_len " $last_robj"
1018247e89262Smrg		  func_arith $len0 + $func_len_result
1018347e89262Smrg		  len=$func_arith_result
1018447e89262Smrg		fi
1018547e89262Smrg	      done
1018647e89262Smrg	      # Handle the remaining objects by creating one last
1018747e89262Smrg	      # reloadable object file.  All subsequent reloadable object
1018847e89262Smrg	      # files will link in the last one created.
1018947e89262Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1019047e89262Smrg	      reload_objs="$objlist $last_robj"
10191e6d2e958Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
1019247e89262Smrg	      if test -n "$last_robj"; then
10193e6d2e958Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1019447e89262Smrg	      fi
10195899129b3Smrg	      func_append delfiles " $output"
1019647e89262Smrg
1019747e89262Smrg	    else
1019847e89262Smrg	      output=
1019947e89262Smrg	    fi
10200bd1da9d7Smrg
10201e6d2e958Smrg	    ${skipped_export-false} && {
10202e6d2e958Smrg	      func_verbose "generating symbol list for '$libname.la'"
10203e6d2e958Smrg	      export_symbols=$output_objdir/$libname.exp
1020447e89262Smrg	      $opt_dry_run || $RM $export_symbols
1020547e89262Smrg	      libobjs=$output
1020647e89262Smrg	      # Append the command to create the export file.
1020747e89262Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1020847e89262Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
1020947e89262Smrg	      if test -n "$last_robj"; then
1021047e89262Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1021147e89262Smrg	      fi
10212e6d2e958Smrg	    }
10213bd1da9d7Smrg
1021447e89262Smrg	    test -n "$save_libobjs" &&
1021547e89262Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216bd1da9d7Smrg
1021747e89262Smrg	    # Loop through the commands generated above and execute them.
10218e6d2e958Smrg	    save_ifs=$IFS; IFS='~'
1021947e89262Smrg	    for cmd in $concat_cmds; do
10220e6d2e958Smrg	      IFS=$save_ifs
10221e6d2e958Smrg	      $opt_quiet || {
10222a392d4f3Smrg		  func_quote_arg expand,pretty "$cmd"
10223a392d4f3Smrg		  eval "func_echo $func_quote_arg_result"
1022447e89262Smrg	      }
1022547e89262Smrg	      $opt_dry_run || eval "$cmd" || {
1022647e89262Smrg		lt_exit=$?
1022747e89262Smrg
1022847e89262Smrg		# Restore the uninstalled library and exit
10229e6d2e958Smrg		if test relink = "$opt_mode"; then
1023047e89262Smrg		  ( cd "$output_objdir" && \
1023147e89262Smrg		    $RM "${realname}T" && \
1023247e89262Smrg		    $MV "${realname}U" "$realname" )
1023347e89262Smrg		fi
10234bd1da9d7Smrg
1023547e89262Smrg		exit $lt_exit
1023647e89262Smrg	      }
1023747e89262Smrg	    done
10238e6d2e958Smrg	    IFS=$save_ifs
10239bd1da9d7Smrg
1024047e89262Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
1024147e89262Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
1024247e89262Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243bd1da9d7Smrg	    fi
10244bd1da9d7Smrg	  fi
10245bd1da9d7Smrg
10246e6d2e958Smrg          ${skipped_export-false} && {
1024747e89262Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248e6d2e958Smrg	      tmp_export_symbols=$export_symbols
10249e6d2e958Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1025047e89262Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1025147e89262Smrg	    fi
10252bd1da9d7Smrg
1025347e89262Smrg	    if test -n "$orig_export_symbols"; then
1025447e89262Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255e6d2e958Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1025647e89262Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257e6d2e958Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
1025847e89262Smrg	      # though. Also, the filter scales superlinearly with the number of
1025947e89262Smrg	      # global variables. join(1) would be nice here, but unfortunately
1026047e89262Smrg	      # isn't a blessed tool.
1026147e89262Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262899129b3Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1026347e89262Smrg	      export_symbols=$output_objdir/$libname.def
1026447e89262Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1026547e89262Smrg	    fi
10266e6d2e958Smrg	  }
10267bd1da9d7Smrg
1026847e89262Smrg	  libobjs=$output
1026947e89262Smrg	  # Restore the value of output.
1027047e89262Smrg	  output=$save_output
10271bd1da9d7Smrg
1027247e89262Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
1027347e89262Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1027447e89262Smrg	    test "X$libobjs" = "X " && libobjs=
1027547e89262Smrg	  fi
1027647e89262Smrg	  # Expand the library linking commands again to reset the
1027747e89262Smrg	  # value of $libobjs for piecewise linking.
1027847e89262Smrg
1027947e89262Smrg	  # Do each of the archive commands.
10280e6d2e958Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
1028147e89262Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1028247e89262Smrg	      cmds=$module_expsym_cmds
10283bd1da9d7Smrg	    else
1028447e89262Smrg	      cmds=$module_cmds
10285bd1da9d7Smrg	    fi
10286bd1da9d7Smrg	  else
1028747e89262Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1028847e89262Smrg	      cmds=$archive_expsym_cmds
1028947e89262Smrg	    else
1029047e89262Smrg	      cmds=$archive_cmds
1029147e89262Smrg	    fi
10292bd1da9d7Smrg	  fi
10293bd1da9d7Smrg	fi
10294bd1da9d7Smrg
1029547e89262Smrg	if test -n "$delfiles"; then
1029647e89262Smrg	  # Append the command to remove temporary files to $cmds.
1029747e89262Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1029847e89262Smrg	fi
10299bd1da9d7Smrg
1030047e89262Smrg	# Add any objects from preloaded convenience libraries
1030147e89262Smrg	if test -n "$dlprefiles"; then
10302e6d2e958Smrg	  gentop=$output_objdir/${outputname}x
10303899129b3Smrg	  func_append generated " $gentop"
10304bd1da9d7Smrg
1030547e89262Smrg	  func_extract_archives $gentop $dlprefiles
10306899129b3Smrg	  func_append libobjs " $func_extract_archives_result"
1030747e89262Smrg	  test "X$libobjs" = "X " && libobjs=
10308bd1da9d7Smrg	fi
10309bd1da9d7Smrg
10310e6d2e958Smrg	save_ifs=$IFS; IFS='~'
1031147e89262Smrg	for cmd in $cmds; do
10312e6d2e958Smrg	  IFS=$sp$nl
1031347e89262Smrg	  eval cmd=\"$cmd\"
10314e6d2e958Smrg	  IFS=$save_ifs
10315e6d2e958Smrg	  $opt_quiet || {
10316a392d4f3Smrg	    func_quote_arg expand,pretty "$cmd"
10317a392d4f3Smrg	    eval "func_echo $func_quote_arg_result"
1031847e89262Smrg	  }
1031947e89262Smrg	  $opt_dry_run || eval "$cmd" || {
1032047e89262Smrg	    lt_exit=$?
10321bd1da9d7Smrg
1032247e89262Smrg	    # Restore the uninstalled library and exit
10323e6d2e958Smrg	    if test relink = "$opt_mode"; then
1032447e89262Smrg	      ( cd "$output_objdir" && \
1032547e89262Smrg	        $RM "${realname}T" && \
1032647e89262Smrg		$MV "${realname}U" "$realname" )
10327bd1da9d7Smrg	    fi
10328bd1da9d7Smrg
1032947e89262Smrg	    exit $lt_exit
1033047e89262Smrg	  }
1033147e89262Smrg	done
10332e6d2e958Smrg	IFS=$save_ifs
10333bd1da9d7Smrg
1033447e89262Smrg	# Restore the uninstalled library and exit
10335e6d2e958Smrg	if test relink = "$opt_mode"; then
1033647e89262Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337bd1da9d7Smrg
1033847e89262Smrg	  if test -n "$convenience"; then
1033947e89262Smrg	    if test -z "$whole_archive_flag_spec"; then
1034047e89262Smrg	      func_show_eval '${RM}r "$gentop"'
1034147e89262Smrg	    fi
1034247e89262Smrg	  fi
10343bd1da9d7Smrg
1034447e89262Smrg	  exit $EXIT_SUCCESS
1034547e89262Smrg	fi
10346bd1da9d7Smrg
1034747e89262Smrg	# Create links to the real library.
1034847e89262Smrg	for linkname in $linknames; do
1034947e89262Smrg	  if test "$realname" != "$linkname"; then
1035047e89262Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
1035147e89262Smrg	  fi
1035247e89262Smrg	done
10353bd1da9d7Smrg
1035447e89262Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355e6d2e958Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1035647e89262Smrg	  # On all known operating systems, these are identical.
10357e6d2e958Smrg	  dlname=$soname
1035847e89262Smrg	fi
1035947e89262Smrg      fi
1036047e89262Smrg      ;;
10361bd1da9d7Smrg
1036247e89262Smrg    obj)
10363e6d2e958Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364e6d2e958Smrg	func_warning "'-dlopen' is ignored for objects"
1036547e89262Smrg      fi
10366bd1da9d7Smrg
1036747e89262Smrg      case " $deplibs" in
1036847e89262Smrg      *\ -l* | *\ -L*)
10369e6d2e958Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
1037047e89262Smrg      esac
10371bd1da9d7Smrg
1037247e89262Smrg      test -n "$rpath" && \
10373e6d2e958Smrg	func_warning "'-rpath' is ignored for objects"
10374bd1da9d7Smrg
1037547e89262Smrg      test -n "$xrpath" && \
10376e6d2e958Smrg	func_warning "'-R' is ignored for objects"
1037747e89262Smrg
1037847e89262Smrg      test -n "$vinfo" && \
10379e6d2e958Smrg	func_warning "'-version-info' is ignored for objects"
10380bd1da9d7Smrg
1038147e89262Smrg      test -n "$release" && \
10382e6d2e958Smrg	func_warning "'-release' is ignored for objects"
10383bd1da9d7Smrg
1038447e89262Smrg      case $output in
1038547e89262Smrg      *.lo)
1038647e89262Smrg	test -n "$objs$old_deplibs" && \
10387e6d2e958Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1038847e89262Smrg
1038947e89262Smrg	libobj=$output
1039047e89262Smrg	func_lo2o "$libobj"
1039147e89262Smrg	obj=$func_lo2o_result
1039247e89262Smrg	;;
1039347e89262Smrg      *)
1039447e89262Smrg	libobj=
10395e6d2e958Smrg	obj=$output
10396bd1da9d7Smrg	;;
10397bd1da9d7Smrg      esac
10398bd1da9d7Smrg
1039947e89262Smrg      # Delete the old objects.
1040047e89262Smrg      $opt_dry_run || $RM $obj $libobj
10401bd1da9d7Smrg
1040247e89262Smrg      # Objects from convenience libraries.  This assumes
1040347e89262Smrg      # single-version convenience libraries.  Whenever we create
1040447e89262Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1040547e89262Smrg      # the extraction.
1040647e89262Smrg      reload_conv_objs=
1040747e89262Smrg      gentop=
10408e6d2e958Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409e6d2e958Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410e6d2e958Smrg      # into space.
10411e6d2e958Smrg      case $reload_cmds in
10412e6d2e958Smrg        *\$LD[\ \$]*) wl= ;;
10413e6d2e958Smrg      esac
1041447e89262Smrg      if test -n "$convenience"; then
1041547e89262Smrg	if test -n "$whole_archive_flag_spec"; then
1041647e89262Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417e6d2e958Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418e6d2e958Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419bd1da9d7Smrg	else
10420e6d2e958Smrg	  gentop=$output_objdir/${obj}x
10421899129b3Smrg	  func_append generated " $gentop"
1042247e89262Smrg
1042347e89262Smrg	  func_extract_archives $gentop $convenience
1042447e89262Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425bd1da9d7Smrg	fi
1042647e89262Smrg      fi
10427bd1da9d7Smrg
10428899129b3Smrg      # If we're not building shared, we need to use non_pic_objs
10429e6d2e958Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430899129b3Smrg
1043147e89262Smrg      # Create the old-style object.
10432e6d2e958Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433bd1da9d7Smrg
10434e6d2e958Smrg      output=$obj
1043547e89262Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436bd1da9d7Smrg
1043747e89262Smrg      # Exit if we aren't doing a library object file.
1043847e89262Smrg      if test -z "$libobj"; then
1043947e89262Smrg	if test -n "$gentop"; then
1044047e89262Smrg	  func_show_eval '${RM}r "$gentop"'
1044147e89262Smrg	fi
10442bd1da9d7Smrg
1044347e89262Smrg	exit $EXIT_SUCCESS
10444bd1da9d7Smrg      fi
10445bd1da9d7Smrg
10446e6d2e958Smrg      test yes = "$build_libtool_libs" || {
1044747e89262Smrg	if test -n "$gentop"; then
1044847e89262Smrg	  func_show_eval '${RM}r "$gentop"'
1044947e89262Smrg	fi
10450bd1da9d7Smrg
1045147e89262Smrg	# Create an invalid libtool object if no PIC, so that we don't
1045247e89262Smrg	# accidentally link it into a program.
1045347e89262Smrg	# $show "echo timestamp > $libobj"
1045447e89262Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1045547e89262Smrg	exit $EXIT_SUCCESS
10456e6d2e958Smrg      }
10457bd1da9d7Smrg
10458e6d2e958Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1045947e89262Smrg	# Only do commands if we really have different PIC objects.
1046047e89262Smrg	reload_objs="$libobjs $reload_conv_objs"
10461e6d2e958Smrg	output=$libobj
1046247e89262Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463bd1da9d7Smrg      fi
1046447e89262Smrg
1046547e89262Smrg      if test -n "$gentop"; then
1046647e89262Smrg	func_show_eval '${RM}r "$gentop"'
1046747e89262Smrg      fi
1046847e89262Smrg
1046947e89262Smrg      exit $EXIT_SUCCESS
10470bd1da9d7Smrg      ;;
10471bd1da9d7Smrg
1047247e89262Smrg    prog)
1047347e89262Smrg      case $host in
1047447e89262Smrg	*cygwin*) func_stripname '' '.exe' "$output"
1047547e89262Smrg	          output=$func_stripname_result.exe;;
1047647e89262Smrg      esac
1047747e89262Smrg      test -n "$vinfo" && \
10478e6d2e958Smrg	func_warning "'-version-info' is ignored for programs"
10479bd1da9d7Smrg
1048047e89262Smrg      test -n "$release" && \
10481e6d2e958Smrg	func_warning "'-release' is ignored for programs"
10482bd1da9d7Smrg
10483e6d2e958Smrg      $preload \
10484e6d2e958Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485e6d2e958Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1048647e89262Smrg
1048747e89262Smrg      case $host in
1048847e89262Smrg      *-*-rhapsody* | *-*-darwin1.[012])
1048947e89262Smrg	# On Rhapsody replace the C library is the System framework
1049047e89262Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1049147e89262Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492bd1da9d7Smrg	;;
1049347e89262Smrg      esac
10494bd1da9d7Smrg
1049547e89262Smrg      case $host in
1049647e89262Smrg      *-*-darwin*)
1049747e89262Smrg	# Don't allow lazy linking, it breaks C++ global constructors
1049847e89262Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499e6d2e958Smrg	if test CXX = "$tagname"; then
1050047e89262Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1050147e89262Smrg	    10.[0123])
10502e6d2e958Smrg	      func_append compile_command " $wl-bind_at_load"
10503e6d2e958Smrg	      func_append finalize_command " $wl-bind_at_load"
1050447e89262Smrg	    ;;
1050547e89262Smrg	  esac
10506bd1da9d7Smrg	fi
1050747e89262Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050847e89262Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050947e89262Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1051047e89262Smrg	;;
1051147e89262Smrg      esac
10512bd1da9d7Smrg
10513bd1da9d7Smrg
1051447e89262Smrg      # move library search paths that coincide with paths to not yet
1051547e89262Smrg      # installed libraries to the beginning of the library search list
1051647e89262Smrg      new_libs=
1051747e89262Smrg      for path in $notinst_path; do
1051847e89262Smrg	case " $new_libs " in
1051947e89262Smrg	*" -L$path/$objdir "*) ;;
1052047e89262Smrg	*)
1052147e89262Smrg	  case " $compile_deplibs " in
1052247e89262Smrg	  *" -L$path/$objdir "*)
10523899129b3Smrg	    func_append new_libs " -L$path/$objdir" ;;
10524bd1da9d7Smrg	  esac
1052547e89262Smrg	  ;;
1052647e89262Smrg	esac
1052747e89262Smrg      done
1052847e89262Smrg      for deplib in $compile_deplibs; do
1052947e89262Smrg	case $deplib in
1053047e89262Smrg	-L*)
1053147e89262Smrg	  case " $new_libs " in
1053247e89262Smrg	  *" $deplib "*) ;;
10533899129b3Smrg	  *) func_append new_libs " $deplib" ;;
10534bd1da9d7Smrg	  esac
1053547e89262Smrg	  ;;
10536899129b3Smrg	*) func_append new_libs " $deplib" ;;
1053747e89262Smrg	esac
1053847e89262Smrg      done
10539e6d2e958Smrg      compile_deplibs=$new_libs
10540bd1da9d7Smrg
10541bd1da9d7Smrg
10542899129b3Smrg      func_append compile_command " $compile_deplibs"
10543899129b3Smrg      func_append finalize_command " $finalize_deplibs"
10544bd1da9d7Smrg
1054547e89262Smrg      if test -n "$rpath$xrpath"; then
1054647e89262Smrg	# If the user specified any rpath flags, then add them.
1054747e89262Smrg	for libdir in $rpath $xrpath; do
1054847e89262Smrg	  # This is the magic to use -rpath.
1054947e89262Smrg	  case "$finalize_rpath " in
1055047e89262Smrg	  *" $libdir "*) ;;
10551899129b3Smrg	  *) func_append finalize_rpath " $libdir" ;;
1055247e89262Smrg	  esac
1055347e89262Smrg	done
1055447e89262Smrg      fi
10555bd1da9d7Smrg
1055647e89262Smrg      # Now hardcode the library paths
1055747e89262Smrg      rpath=
1055847e89262Smrg      hardcode_libdirs=
1055947e89262Smrg      for libdir in $compile_rpath $finalize_rpath; do
1056047e89262Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1056147e89262Smrg	  if test -n "$hardcode_libdir_separator"; then
1056247e89262Smrg	    if test -z "$hardcode_libdirs"; then
10563e6d2e958Smrg	      hardcode_libdirs=$libdir
1056447e89262Smrg	    else
1056547e89262Smrg	      # Just accumulate the unique libdirs.
1056647e89262Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1056747e89262Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1056847e89262Smrg		;;
1056947e89262Smrg	      *)
10570899129b3Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1057147e89262Smrg		;;
1057247e89262Smrg	      esac
1057347e89262Smrg	    fi
10574bd1da9d7Smrg	  else
1057547e89262Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576899129b3Smrg	    func_append rpath " $flag"
10577bd1da9d7Smrg	  fi
1057847e89262Smrg	elif test -n "$runpath_var"; then
1057947e89262Smrg	  case "$perm_rpath " in
1058047e89262Smrg	  *" $libdir "*) ;;
10581899129b3Smrg	  *) func_append perm_rpath " $libdir" ;;
1058247e89262Smrg	  esac
1058347e89262Smrg	fi
1058447e89262Smrg	case $host in
1058547e89262Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586e6d2e958Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1058747e89262Smrg	  case :$dllsearchpath: in
1058847e89262Smrg	  *":$libdir:"*) ;;
1058947e89262Smrg	  ::) dllsearchpath=$libdir;;
10590899129b3Smrg	  *) func_append dllsearchpath ":$libdir";;
1059147e89262Smrg	  esac
1059247e89262Smrg	  case :$dllsearchpath: in
1059347e89262Smrg	  *":$testbindir:"*) ;;
1059447e89262Smrg	  ::) dllsearchpath=$testbindir;;
10595899129b3Smrg	  *) func_append dllsearchpath ":$testbindir";;
1059647e89262Smrg	  esac
1059747e89262Smrg	  ;;
1059847e89262Smrg	esac
1059947e89262Smrg      done
1060047e89262Smrg      # Substitute the hardcoded libdirs into the rpath.
1060147e89262Smrg      if test -n "$hardcode_libdir_separator" &&
1060247e89262Smrg	 test -n "$hardcode_libdirs"; then
10603e6d2e958Smrg	libdir=$hardcode_libdirs
1060447e89262Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1060547e89262Smrg      fi
10606e6d2e958Smrg      compile_rpath=$rpath
10607bd1da9d7Smrg
1060847e89262Smrg      rpath=
1060947e89262Smrg      hardcode_libdirs=
1061047e89262Smrg      for libdir in $finalize_rpath; do
1061147e89262Smrg	if test -n "$hardcode_libdir_flag_spec"; then
1061247e89262Smrg	  if test -n "$hardcode_libdir_separator"; then
1061347e89262Smrg	    if test -z "$hardcode_libdirs"; then
10614e6d2e958Smrg	      hardcode_libdirs=$libdir
1061547e89262Smrg	    else
1061647e89262Smrg	      # Just accumulate the unique libdirs.
1061747e89262Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1061847e89262Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1061947e89262Smrg		;;
1062047e89262Smrg	      *)
10621899129b3Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1062247e89262Smrg		;;
1062347e89262Smrg	      esac
1062447e89262Smrg	    fi
10625bd1da9d7Smrg	  else
1062647e89262Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627899129b3Smrg	    func_append rpath " $flag"
10628bd1da9d7Smrg	  fi
1062947e89262Smrg	elif test -n "$runpath_var"; then
1063047e89262Smrg	  case "$finalize_perm_rpath " in
1063147e89262Smrg	  *" $libdir "*) ;;
10632899129b3Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1063347e89262Smrg	  esac
10634bd1da9d7Smrg	fi
1063547e89262Smrg      done
1063647e89262Smrg      # Substitute the hardcoded libdirs into the rpath.
1063747e89262Smrg      if test -n "$hardcode_libdir_separator" &&
1063847e89262Smrg	 test -n "$hardcode_libdirs"; then
10639e6d2e958Smrg	libdir=$hardcode_libdirs
1064047e89262Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1064147e89262Smrg      fi
10642e6d2e958Smrg      finalize_rpath=$rpath
10643bd1da9d7Smrg
10644e6d2e958Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1064547e89262Smrg	# Transform all the library objects into standard objects.
1064647e89262Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064747e89262Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064847e89262Smrg      fi
10649bd1da9d7Smrg
10650e6d2e958Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651bd1da9d7Smrg
1065247e89262Smrg      # template prelinking step
1065347e89262Smrg      if test -n "$prelink_cmds"; then
1065447e89262Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1065547e89262Smrg      fi
10656bd1da9d7Smrg
10657e6d2e958Smrg      wrappers_required=:
1065847e89262Smrg      case $host in
1065947e89262Smrg      *cegcc* | *mingw32ce*)
1066047e89262Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661e6d2e958Smrg        wrappers_required=false
1066247e89262Smrg        ;;
1066347e89262Smrg      *cygwin* | *mingw* )
10664e6d2e958Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
1066547e89262Smrg        ;;
1066647e89262Smrg      *)
10667e6d2e958Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668e6d2e958Smrg          wrappers_required=false
1066947e89262Smrg        fi
1067047e89262Smrg        ;;
1067147e89262Smrg      esac
10672e6d2e958Smrg      $wrappers_required || {
1067347e89262Smrg	# Replace the output file specification.
1067447e89262Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675e6d2e958Smrg	link_command=$compile_command$compile_rpath
10676bd1da9d7Smrg
1067747e89262Smrg	# We have no uninstalled library dependencies, so finalize right now.
1067847e89262Smrg	exit_status=0
1067947e89262Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680bd1da9d7Smrg
10681899129b3Smrg	if test -n "$postlink_cmds"; then
10682899129b3Smrg	  func_to_tool_file "$output"
10683899129b3Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684899129b3Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685899129b3Smrg	fi
10686899129b3Smrg
1068747e89262Smrg	# Delete the generated files.
10688e6d2e958Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689e6d2e958Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690bd1da9d7Smrg	fi
10691bd1da9d7Smrg
1069247e89262Smrg	exit $exit_status
10693e6d2e958Smrg      }
10694bd1da9d7Smrg
1069547e89262Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1069647e89262Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1069747e89262Smrg      fi
1069847e89262Smrg      if test -n "$finalize_shlibpath"; then
1069947e89262Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1070047e89262Smrg      fi
10701bd1da9d7Smrg
1070247e89262Smrg      compile_var=
1070347e89262Smrg      finalize_var=
1070447e89262Smrg      if test -n "$runpath_var"; then
1070547e89262Smrg	if test -n "$perm_rpath"; then
1070647e89262Smrg	  # We should set the runpath_var.
1070747e89262Smrg	  rpath=
1070847e89262Smrg	  for dir in $perm_rpath; do
10709899129b3Smrg	    func_append rpath "$dir:"
1071047e89262Smrg	  done
1071147e89262Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712bd1da9d7Smrg	fi
1071347e89262Smrg	if test -n "$finalize_perm_rpath"; then
1071447e89262Smrg	  # We should set the runpath_var.
1071547e89262Smrg	  rpath=
1071647e89262Smrg	  for dir in $finalize_perm_rpath; do
10717899129b3Smrg	    func_append rpath "$dir:"
1071847e89262Smrg	  done
1071947e89262Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720bd1da9d7Smrg	fi
1072147e89262Smrg      fi
10722bd1da9d7Smrg
10723e6d2e958Smrg      if test yes = "$no_install"; then
1072447e89262Smrg	# We don't need to create a wrapper script.
10725e6d2e958Smrg	link_command=$compile_var$compile_command$compile_rpath
1072647e89262Smrg	# Replace the output file specification.
1072747e89262Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1072847e89262Smrg	# Delete the old output file.
1072947e89262Smrg	$opt_dry_run || $RM $output
1073047e89262Smrg	# Link the executable and exit
1073147e89262Smrg	func_show_eval "$link_command" 'exit $?'
10732899129b3Smrg
10733899129b3Smrg	if test -n "$postlink_cmds"; then
10734899129b3Smrg	  func_to_tool_file "$output"
10735899129b3Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736899129b3Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737899129b3Smrg	fi
10738899129b3Smrg
10739bd1da9d7Smrg	exit $EXIT_SUCCESS
1074047e89262Smrg      fi
10741bd1da9d7Smrg
10742e6d2e958Smrg      case $hardcode_action,$fast_install in
10743e6d2e958Smrg        relink,*)
10744e6d2e958Smrg	  # Fast installation is not supported
10745e6d2e958Smrg	  link_command=$compile_var$compile_command$compile_rpath
10746e6d2e958Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1074747e89262Smrg
10748e6d2e958Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10749e6d2e958Smrg	  func_warning "'$output' will be relinked during installation"
10750e6d2e958Smrg	  ;;
10751e6d2e958Smrg        *,yes)
10752e6d2e958Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753e6d2e958Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754e6d2e958Smrg          ;;
10755e6d2e958Smrg	*,no)
10756e6d2e958Smrg	  link_command=$compile_var$compile_command$compile_rpath
10757e6d2e958Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758e6d2e958Smrg          ;;
10759e6d2e958Smrg	*,needless)
10760e6d2e958Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761e6d2e958Smrg	  relink_command=
10762e6d2e958Smrg          ;;
10763e6d2e958Smrg      esac
10764bd1da9d7Smrg
1076547e89262Smrg      # Replace the output file specification.
1076647e89262Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767bd1da9d7Smrg
1076847e89262Smrg      # Delete the old output files.
1076947e89262Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770bd1da9d7Smrg
1077147e89262Smrg      func_show_eval "$link_command" 'exit $?'
10772bd1da9d7Smrg
10773899129b3Smrg      if test -n "$postlink_cmds"; then
10774899129b3Smrg	func_to_tool_file "$output_objdir/$outputname"
10775899129b3Smrg	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'`
10776899129b3Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777899129b3Smrg      fi
10778899129b3Smrg
1077947e89262Smrg      # Now create the wrapper script.
1078047e89262Smrg      func_verbose "creating $output"
10781bd1da9d7Smrg
1078247e89262Smrg      # Quote the relink command for shipping.
1078347e89262Smrg      if test -n "$relink_command"; then
1078447e89262Smrg	# Preserve any variables that may affect compiler behavior
1078547e89262Smrg	for var in $variables_saved_for_relink; do
1078647e89262Smrg	  if eval test -z \"\${$var+set}\"; then
1078747e89262Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1078847e89262Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1078947e89262Smrg	    relink_command="$var=; export $var; $relink_command"
10790bd1da9d7Smrg	  else
10791a392d4f3Smrg	    func_quote_arg pretty "$var_value"
10792a392d4f3Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793bd1da9d7Smrg	  fi
1079447e89262Smrg	done
10795a392d4f3Smrg	func_quote eval cd "`pwd`"
10796a392d4f3Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797a392d4f3Smrg	relink_command=$func_quote_arg_unquoted_result
1079847e89262Smrg      fi
10799bd1da9d7Smrg
1080047e89262Smrg      # Only actually do things if not in dry run mode.
1080147e89262Smrg      $opt_dry_run || {
1080247e89262Smrg	# win32 will think the script is a binary if it has
1080347e89262Smrg	# a .exe suffix, so we strip it off here.
1080447e89262Smrg	case $output in
1080547e89262Smrg	  *.exe) func_stripname '' '.exe' "$output"
1080647e89262Smrg	         output=$func_stripname_result ;;
1080747e89262Smrg	esac
1080847e89262Smrg	# test for cygwin because mv fails w/o .exe extensions
1080947e89262Smrg	case $host in
1081047e89262Smrg	  *cygwin*)
1081147e89262Smrg	    exeext=.exe
1081247e89262Smrg	    func_stripname '' '.exe' "$outputname"
1081347e89262Smrg	    outputname=$func_stripname_result ;;
1081447e89262Smrg	  *) exeext= ;;
10815bd1da9d7Smrg	esac
1081647e89262Smrg	case $host in
1081747e89262Smrg	  *cygwin* | *mingw* )
1081847e89262Smrg	    func_dirname_and_basename "$output" "" "."
1081947e89262Smrg	    output_name=$func_basename_result
1082047e89262Smrg	    output_path=$func_dirname_result
10821e6d2e958Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822e6d2e958Smrg	    cwrapper=$output_path/$output_name.exe
1082347e89262Smrg	    $RM $cwrappersource $cwrapper
1082447e89262Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1082547e89262Smrg
1082647e89262Smrg	    func_emit_cwrapperexe_src > $cwrappersource
1082747e89262Smrg
1082847e89262Smrg	    # The wrapper executable is built using the $host compiler,
1082947e89262Smrg	    # because it contains $host paths and files. If cross-
1083047e89262Smrg	    # compiling, it, like the target executable, must be
1083147e89262Smrg	    # executed on the $host or under an emulation environment.
1083247e89262Smrg	    $opt_dry_run || {
1083347e89262Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1083447e89262Smrg	      $STRIP $cwrapper
1083547e89262Smrg	    }
10836bd1da9d7Smrg
1083747e89262Smrg	    # Now, create the wrapper script for func_source use:
1083847e89262Smrg	    func_ltwrapper_scriptname $cwrapper
1083947e89262Smrg	    $RM $func_ltwrapper_scriptname_result
1084047e89262Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1084147e89262Smrg	    $opt_dry_run || {
1084247e89262Smrg	      # note: this script will not be executed, so do not chmod.
10843e6d2e958Smrg	      if test "x$build" = "x$host"; then
1084447e89262Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1084547e89262Smrg	      else
1084647e89262Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1084747e89262Smrg	      fi
1084847e89262Smrg	    }
1084947e89262Smrg	  ;;
1085047e89262Smrg	  * )
1085147e89262Smrg	    $RM $output
1085247e89262Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853bd1da9d7Smrg
1085447e89262Smrg	    func_emit_wrapper no > $output
1085547e89262Smrg	    chmod +x $output
1085647e89262Smrg	  ;;
1085747e89262Smrg	esac
1085847e89262Smrg      }
1085947e89262Smrg      exit $EXIT_SUCCESS
1086047e89262Smrg      ;;
1086147e89262Smrg    esac
10862bd1da9d7Smrg
1086347e89262Smrg    # See if we need to build an old-fashioned archive.
1086447e89262Smrg    for oldlib in $oldlibs; do
10865bd1da9d7Smrg
10866e6d2e958Smrg      case $build_libtool_libs in
10867e6d2e958Smrg        convenience)
10868e6d2e958Smrg	  oldobjs="$libobjs_save $symfileobj"
10869e6d2e958Smrg	  addlibs=$convenience
1087047e89262Smrg	  build_libtool_libs=no
10871e6d2e958Smrg	  ;;
10872e6d2e958Smrg	module)
10873e6d2e958Smrg	  oldobjs=$libobjs_save
10874e6d2e958Smrg	  addlibs=$old_convenience
10875e6d2e958Smrg	  build_libtool_libs=no
10876e6d2e958Smrg          ;;
10877e6d2e958Smrg	*)
1087847e89262Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879e6d2e958Smrg	  $preload && test -f "$symfileobj" \
10880e6d2e958Smrg	    && func_append oldobjs " $symfileobj"
10881e6d2e958Smrg	  addlibs=$old_convenience
10882e6d2e958Smrg	  ;;
10883e6d2e958Smrg      esac
10884bd1da9d7Smrg
1088547e89262Smrg      if test -n "$addlibs"; then
10886e6d2e958Smrg	gentop=$output_objdir/${outputname}x
10887899129b3Smrg	func_append generated " $gentop"
10888bd1da9d7Smrg
1088947e89262Smrg	func_extract_archives $gentop $addlibs
10890899129b3Smrg	func_append oldobjs " $func_extract_archives_result"
1089147e89262Smrg      fi
10892bd1da9d7Smrg
1089347e89262Smrg      # Do each command in the archive commands.
10894e6d2e958Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1089547e89262Smrg	cmds=$old_archive_from_new_cmds
1089647e89262Smrg      else
10897bd1da9d7Smrg
1089847e89262Smrg	# Add any objects from preloaded convenience libraries
1089947e89262Smrg	if test -n "$dlprefiles"; then
10900e6d2e958Smrg	  gentop=$output_objdir/${outputname}x
10901899129b3Smrg	  func_append generated " $gentop"
10902bd1da9d7Smrg
1090347e89262Smrg	  func_extract_archives $gentop $dlprefiles
10904899129b3Smrg	  func_append oldobjs " $func_extract_archives_result"
1090547e89262Smrg	fi
10906bd1da9d7Smrg
1090747e89262Smrg	# POSIX demands no paths to be encoded in archives.  We have
1090847e89262Smrg	# to avoid creating archives with duplicate basenames if we
1090947e89262Smrg	# might have to extract them afterwards, e.g., when creating a
1091047e89262Smrg	# static archive out of a convenience library, or when linking
1091147e89262Smrg	# the entirety of a libtool archive into another (currently
1091247e89262Smrg	# not supported by libtool).
1091347e89262Smrg	if (for obj in $oldobjs
1091447e89262Smrg	    do
1091547e89262Smrg	      func_basename "$obj"
1091647e89262Smrg	      $ECHO "$func_basename_result"
1091747e89262Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
1091847e89262Smrg	  :
1091947e89262Smrg	else
1092047e89262Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921e6d2e958Smrg	  gentop=$output_objdir/${outputname}x
10922899129b3Smrg	  func_append generated " $gentop"
1092347e89262Smrg	  func_mkdir_p "$gentop"
1092447e89262Smrg	  save_oldobjs=$oldobjs
1092547e89262Smrg	  oldobjs=
1092647e89262Smrg	  counter=1
1092747e89262Smrg	  for obj in $save_oldobjs
1092847e89262Smrg	  do
1092947e89262Smrg	    func_basename "$obj"
10930e6d2e958Smrg	    objbase=$func_basename_result
1093147e89262Smrg	    case " $oldobjs " in
1093247e89262Smrg	    " ") oldobjs=$obj ;;
1093347e89262Smrg	    *[\ /]"$objbase "*)
1093447e89262Smrg	      while :; do
1093547e89262Smrg		# Make sure we don't pick an alternate name that also
1093647e89262Smrg		# overlaps.
1093747e89262Smrg		newobj=lt$counter-$objbase
1093847e89262Smrg		func_arith $counter + 1
1093947e89262Smrg		counter=$func_arith_result
1094047e89262Smrg		case " $oldobjs " in
1094147e89262Smrg		*[\ /]"$newobj "*) ;;
1094247e89262Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1094347e89262Smrg		esac
1094447e89262Smrg	      done
1094547e89262Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946899129b3Smrg	      func_append oldobjs " $gentop/$newobj"
1094747e89262Smrg	      ;;
10948899129b3Smrg	    *) func_append oldobjs " $obj" ;;
1094947e89262Smrg	    esac
10950bd1da9d7Smrg	  done
10951bd1da9d7Smrg	fi
10952899129b3Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953899129b3Smrg	tool_oldlib=$func_to_tool_file_result
1095447e89262Smrg	eval cmds=\"$old_archive_cmds\"
10955bd1da9d7Smrg
1095647e89262Smrg	func_len " $cmds"
1095747e89262Smrg	len=$func_len_result
1095847e89262Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1095947e89262Smrg	  cmds=$old_archive_cmds
10960899129b3Smrg	elif test -n "$archiver_list_spec"; then
10961899129b3Smrg	  func_verbose "using command file archive linking..."
10962899129b3Smrg	  for obj in $oldobjs
10963899129b3Smrg	  do
10964899129b3Smrg	    func_to_tool_file "$obj"
10965899129b3Smrg	    $ECHO "$func_to_tool_file_result"
10966899129b3Smrg	  done > $output_objdir/$libname.libcmd
10967899129b3Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968899129b3Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969899129b3Smrg	  cmds=$old_archive_cmds
1097047e89262Smrg	else
1097147e89262Smrg	  # the command line is too long to link in one step, link in parts
1097247e89262Smrg	  func_verbose "using piecewise archive linking..."
1097347e89262Smrg	  save_RANLIB=$RANLIB
1097447e89262Smrg	  RANLIB=:
1097547e89262Smrg	  objlist=
1097647e89262Smrg	  concat_cmds=
1097747e89262Smrg	  save_oldobjs=$oldobjs
1097847e89262Smrg	  oldobjs=
1097947e89262Smrg	  # Is there a better way of finding the last object in the list?
1098047e89262Smrg	  for obj in $save_oldobjs
1098147e89262Smrg	  do
1098247e89262Smrg	    last_oldobj=$obj
1098347e89262Smrg	  done
1098447e89262Smrg	  eval test_cmds=\"$old_archive_cmds\"
1098547e89262Smrg	  func_len " $test_cmds"
1098647e89262Smrg	  len0=$func_len_result
1098747e89262Smrg	  len=$len0
1098847e89262Smrg	  for obj in $save_oldobjs
1098947e89262Smrg	  do
1099047e89262Smrg	    func_len " $obj"
1099147e89262Smrg	    func_arith $len + $func_len_result
1099247e89262Smrg	    len=$func_arith_result
1099347e89262Smrg	    func_append objlist " $obj"
1099447e89262Smrg	    if test "$len" -lt "$max_cmd_len"; then
1099547e89262Smrg	      :
1099647e89262Smrg	    else
1099747e89262Smrg	      # the above command should be used before it gets too long
1099847e89262Smrg	      oldobjs=$objlist
10999e6d2e958Smrg	      if test "$obj" = "$last_oldobj"; then
1100047e89262Smrg		RANLIB=$save_RANLIB
1100147e89262Smrg	      fi
1100247e89262Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003e6d2e958Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1100447e89262Smrg	      objlist=
1100547e89262Smrg	      len=$len0
1100647e89262Smrg	    fi
1100747e89262Smrg	  done
1100847e89262Smrg	  RANLIB=$save_RANLIB
1100947e89262Smrg	  oldobjs=$objlist
11010e6d2e958Smrg	  if test -z "$oldobjs"; then
1101147e89262Smrg	    eval cmds=\"\$concat_cmds\"
1101247e89262Smrg	  else
1101347e89262Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1101447e89262Smrg	  fi
1101547e89262Smrg	fi
1101647e89262Smrg      fi
1101747e89262Smrg      func_execute_cmds "$cmds" 'exit $?'
11018bd1da9d7Smrg    done
11019bd1da9d7Smrg
1102047e89262Smrg    test -n "$generated" && \
1102147e89262Smrg      func_show_eval "${RM}r$generated"
11022bd1da9d7Smrg
1102347e89262Smrg    # Now create the libtool archive.
1102447e89262Smrg    case $output in
1102547e89262Smrg    *.la)
1102647e89262Smrg      old_library=
11027e6d2e958Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1102847e89262Smrg      func_verbose "creating $output"
11029bd1da9d7Smrg
1103047e89262Smrg      # Preserve any variables that may affect compiler behavior
1103147e89262Smrg      for var in $variables_saved_for_relink; do
1103247e89262Smrg	if eval test -z \"\${$var+set}\"; then
1103347e89262Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1103447e89262Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
1103547e89262Smrg	  relink_command="$var=; export $var; $relink_command"
11036bd1da9d7Smrg	else
11037a392d4f3Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038a392d4f3Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039bd1da9d7Smrg	fi
1104047e89262Smrg      done
1104147e89262Smrg      # Quote the link command for shipping.
11042a392d4f3Smrg      func_quote eval cd "`pwd`"
11043a392d4f3Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044a392d4f3Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045a392d4f3Smrg      relink_command=$func_quote_arg_unquoted_result
11046e6d2e958Smrg      if test yes = "$hardcode_automatic"; then
1104747e89262Smrg	relink_command=
1104847e89262Smrg      fi
11049bd1da9d7Smrg
1105047e89262Smrg      # Only create the output if not a dry run.
1105147e89262Smrg      $opt_dry_run || {
1105247e89262Smrg	for installed in no yes; do
11053e6d2e958Smrg	  if test yes = "$installed"; then
1105447e89262Smrg	    if test -z "$install_libdir"; then
1105547e89262Smrg	      break
1105647e89262Smrg	    fi
11057e6d2e958Smrg	    output=$output_objdir/${outputname}i
1105847e89262Smrg	    # Replace all uninstalled libtool libraries with the installed ones
1105947e89262Smrg	    newdependency_libs=
1106047e89262Smrg	    for deplib in $dependency_libs; do
1106147e89262Smrg	      case $deplib in
1106247e89262Smrg	      *.la)
1106347e89262Smrg		func_basename "$deplib"
11064e6d2e958Smrg		name=$func_basename_result
11065899129b3Smrg		func_resolve_sysroot "$deplib"
11066e6d2e958Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1106747e89262Smrg		test -z "$libdir" && \
11068e6d2e958Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069899129b3Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070899129b3Smrg		;;
11071899129b3Smrg	      -L*)
11072899129b3Smrg		func_stripname -L '' "$deplib"
11073899129b3Smrg		func_replace_sysroot "$func_stripname_result"
11074899129b3Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11075899129b3Smrg		;;
11076899129b3Smrg	      -R*)
11077899129b3Smrg		func_stripname -R '' "$deplib"
11078899129b3Smrg		func_replace_sysroot "$func_stripname_result"
11079899129b3Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
1108047e89262Smrg		;;
11081899129b3Smrg	      *) func_append newdependency_libs " $deplib" ;;
1108247e89262Smrg	      esac
1108347e89262Smrg	    done
11084e6d2e958Smrg	    dependency_libs=$newdependency_libs
1108547e89262Smrg	    newdlfiles=
1108647e89262Smrg
1108747e89262Smrg	    for lib in $dlfiles; do
1108847e89262Smrg	      case $lib in
1108947e89262Smrg	      *.la)
1109047e89262Smrg	        func_basename "$lib"
11091e6d2e958Smrg		name=$func_basename_result
11092e6d2e958Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1109347e89262Smrg		test -z "$libdir" && \
11094e6d2e958Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095899129b3Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1109647e89262Smrg		;;
11097899129b3Smrg	      *) func_append newdlfiles " $lib" ;;
1109847e89262Smrg	      esac
1109947e89262Smrg	    done
11100e6d2e958Smrg	    dlfiles=$newdlfiles
1110147e89262Smrg	    newdlprefiles=
1110247e89262Smrg	    for lib in $dlprefiles; do
1110347e89262Smrg	      case $lib in
1110447e89262Smrg	      *.la)
1110547e89262Smrg		# Only pass preopened files to the pseudo-archive (for
1110647e89262Smrg		# eventual linking with the app. that links it) if we
1110747e89262Smrg		# didn't already link the preopened objects directly into
1110847e89262Smrg		# the library:
1110947e89262Smrg		func_basename "$lib"
11110e6d2e958Smrg		name=$func_basename_result
11111e6d2e958Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1111247e89262Smrg		test -z "$libdir" && \
11113e6d2e958Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114899129b3Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1111547e89262Smrg		;;
1111647e89262Smrg	      esac
1111747e89262Smrg	    done
11118e6d2e958Smrg	    dlprefiles=$newdlprefiles
1111947e89262Smrg	  else
1112047e89262Smrg	    newdlfiles=
1112147e89262Smrg	    for lib in $dlfiles; do
1112247e89262Smrg	      case $lib in
11123e6d2e958Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1112447e89262Smrg		*) abs=`pwd`"/$lib" ;;
1112547e89262Smrg	      esac
11126899129b3Smrg	      func_append newdlfiles " $abs"
1112747e89262Smrg	    done
11128e6d2e958Smrg	    dlfiles=$newdlfiles
1112947e89262Smrg	    newdlprefiles=
1113047e89262Smrg	    for lib in $dlprefiles; do
1113147e89262Smrg	      case $lib in
11132e6d2e958Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1113347e89262Smrg		*) abs=`pwd`"/$lib" ;;
1113447e89262Smrg	      esac
11135899129b3Smrg	      func_append newdlprefiles " $abs"
1113647e89262Smrg	    done
11137e6d2e958Smrg	    dlprefiles=$newdlprefiles
1113847e89262Smrg	  fi
1113947e89262Smrg	  $RM $output
1114047e89262Smrg	  # place dlname in correct position for cygwin
1114147e89262Smrg	  # In fact, it would be nice if we could use this code for all target
1114247e89262Smrg	  # systems that can't hard-code library paths into their executables
1114347e89262Smrg	  # and that have no shared library path variable independent of PATH,
1114447e89262Smrg	  # but it turns out we can't easily determine that from inspecting
1114547e89262Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1114647e89262Smrg	  # applies here; at the moment, that means platforms that use the PE
1114747e89262Smrg	  # object format with DLL files.  See the long comment at the top of
1114847e89262Smrg	  # tests/bindir.at for full details.
1114947e89262Smrg	  tdlname=$dlname
1115047e89262Smrg	  case $host,$output,$installed,$module,$dlname in
1115147e89262Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1115247e89262Smrg	      # If a -bindir argument was supplied, place the dll there.
11153e6d2e958Smrg	      if test -n "$bindir"; then
1115447e89262Smrg		func_relative_path "$install_libdir" "$bindir"
11155e6d2e958Smrg		tdlname=$func_relative_path_result/$dlname
1115647e89262Smrg	      else
1115747e89262Smrg		# Otherwise fall back on heuristic.
1115847e89262Smrg		tdlname=../bin/$dlname
1115947e89262Smrg	      fi
1116047e89262Smrg	      ;;
1116147e89262Smrg	  esac
1116247e89262Smrg	  $ECHO > $output "\
1116347e89262Smrg# $outputname - a libtool library file
11164e6d2e958Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1116547e89262Smrg#
1116647e89262Smrg# Please DO NOT delete this file!
1116747e89262Smrg# It is necessary for linking the library.
11168bd1da9d7Smrg
1116947e89262Smrg# The name that we can dlopen(3).
1117047e89262Smrgdlname='$tdlname'
11171bd1da9d7Smrg
1117247e89262Smrg# Names of this library.
1117347e89262Smrglibrary_names='$library_names'
11174bd1da9d7Smrg
1117547e89262Smrg# The name of the static archive.
1117647e89262Smrgold_library='$old_library'
11177bd1da9d7Smrg
11178e6d2e958Smrg# Linker flags that cannot go in dependency_libs.
1117947e89262Smrginherited_linker_flags='$new_inherited_linker_flags'
11180bd1da9d7Smrg
1118147e89262Smrg# Libraries that this one depends upon.
1118247e89262Smrgdependency_libs='$dependency_libs'
11183bd1da9d7Smrg
1118447e89262Smrg# Names of additional weak libraries provided by this library
1118547e89262Smrgweak_library_names='$weak_libs'
11186bd1da9d7Smrg
1118747e89262Smrg# Version information for $libname.
1118847e89262Smrgcurrent=$current
1118947e89262Smrgage=$age
1119047e89262Smrgrevision=$revision
11191bd1da9d7Smrg
1119247e89262Smrg# Is this an already installed library?
1119347e89262Smrginstalled=$installed
11194bd1da9d7Smrg
1119547e89262Smrg# Should we warn about portability when linking against -modules?
1119647e89262Smrgshouldnotlink=$module
11197bd1da9d7Smrg
1119847e89262Smrg# Files to dlopen/dlpreopen
1119947e89262Smrgdlopen='$dlfiles'
1120047e89262Smrgdlpreopen='$dlprefiles'
11201bd1da9d7Smrg
1120247e89262Smrg# Directory that this library needs to be installed in:
1120347e89262Smrglibdir='$install_libdir'"
11204e6d2e958Smrg	  if test no,yes = "$installed,$need_relink"; then
1120547e89262Smrg	    $ECHO >> $output "\
1120647e89262Smrgrelink_command=\"$relink_command\""
1120747e89262Smrg	  fi
1120847e89262Smrg	done
1120947e89262Smrg      }
11210bd1da9d7Smrg
1121147e89262Smrg      # Do a symbolic link so that the libtool archive can be found in
1121247e89262Smrg      # LD_LIBRARY_PATH before the program is installed.
1121347e89262Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1121447e89262Smrg      ;;
1121547e89262Smrg    esac
1121647e89262Smrg    exit $EXIT_SUCCESS
1121747e89262Smrg}
11218bd1da9d7Smrg
11219e6d2e958Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220e6d2e958Smrg  func_mode_link ${1+"$@"}
11221e6d2e958Smrgfi
11222bd1da9d7Smrg
11223bd1da9d7Smrg
1122447e89262Smrg# func_mode_uninstall arg...
1122547e89262Smrgfunc_mode_uninstall ()
1122647e89262Smrg{
11227e6d2e958Smrg    $debug_cmd
11228e6d2e958Smrg
11229e6d2e958Smrg    RM=$nonopt
11230bd1da9d7Smrg    files=
11231e6d2e958Smrg    rmforce=false
11232bd1da9d7Smrg    exit_status=0
11233bd1da9d7Smrg
11234bd1da9d7Smrg    # This variable tells wrapper scripts just to set variables rather
11235bd1da9d7Smrg    # than running their programs.
11236e6d2e958Smrg    libtool_install_magic=$magic
11237bd1da9d7Smrg
11238bd1da9d7Smrg    for arg
11239bd1da9d7Smrg    do
11240bd1da9d7Smrg      case $arg in
11241e6d2e958Smrg      -f) func_append RM " $arg"; rmforce=: ;;
11242899129b3Smrg      -*) func_append RM " $arg" ;;
11243899129b3Smrg      *) func_append files " $arg" ;;
11244bd1da9d7Smrg      esac
11245bd1da9d7Smrg    done
11246bd1da9d7Smrg
1124747e89262Smrg    test -z "$RM" && \
1124847e89262Smrg      func_fatal_help "you must specify an RM program"
11249bd1da9d7Smrg
11250bd1da9d7Smrg    rmdirs=
11251bd1da9d7Smrg
11252bd1da9d7Smrg    for file in $files; do
1125347e89262Smrg      func_dirname "$file" "" "."
11254e6d2e958Smrg      dir=$func_dirname_result
11255e6d2e958Smrg      if test . = "$dir"; then
11256e6d2e958Smrg	odir=$objdir
11257bd1da9d7Smrg      else
11258e6d2e958Smrg	odir=$dir/$objdir
11259bd1da9d7Smrg      fi
1126047e89262Smrg      func_basename "$file"
11261e6d2e958Smrg      name=$func_basename_result
11262e6d2e958Smrg      test uninstall = "$opt_mode" && odir=$dir
11263bd1da9d7Smrg
11264899129b3Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265e6d2e958Smrg      if test clean = "$opt_mode"; then
11266bd1da9d7Smrg	case " $rmdirs " in
11267899129b3Smrg	  *" $odir "*) ;;
11268899129b3Smrg	  *) func_append rmdirs " $odir" ;;
11269bd1da9d7Smrg	esac
11270bd1da9d7Smrg      fi
11271bd1da9d7Smrg
11272bd1da9d7Smrg      # Don't error if the file doesn't exist and rm -f was used.
1127347e89262Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1127447e89262Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1127547e89262Smrg	 test -f "$file"; then
11276bd1da9d7Smrg	:
11277bd1da9d7Smrg      elif test -d "$file"; then
11278bd1da9d7Smrg	exit_status=1
11279bd1da9d7Smrg	continue
11280e6d2e958Smrg      elif $rmforce; then
11281bd1da9d7Smrg	continue
11282bd1da9d7Smrg      fi
11283bd1da9d7Smrg
11284e6d2e958Smrg      rmfiles=$file
11285bd1da9d7Smrg
11286bd1da9d7Smrg      case $name in
11287bd1da9d7Smrg      *.la)
11288bd1da9d7Smrg	# Possibly a libtool archive, so verify it.
1128947e89262Smrg	if func_lalib_p "$file"; then
1129047e89262Smrg	  func_source $dir/$name
11291bd1da9d7Smrg
11292bd1da9d7Smrg	  # Delete the libtool libraries and symlinks.
11293bd1da9d7Smrg	  for n in $library_names; do
11294899129b3Smrg	    func_append rmfiles " $odir/$n"
11295bd1da9d7Smrg	  done
11296899129b3Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297bd1da9d7Smrg
11298e6d2e958Smrg	  case $opt_mode in
11299bd1da9d7Smrg	  clean)
11300899129b3Smrg	    case " $library_names " in
11301bd1da9d7Smrg	    *" $dlname "*) ;;
11302899129b3Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303bd1da9d7Smrg	    esac
11304899129b3Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305bd1da9d7Smrg	    ;;
11306bd1da9d7Smrg	  uninstall)
11307bd1da9d7Smrg	    if test -n "$library_names"; then
11308bd1da9d7Smrg	      # Do each command in the postuninstall commands.
11309e6d2e958Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310bd1da9d7Smrg	    fi
11311bd1da9d7Smrg
11312bd1da9d7Smrg	    if test -n "$old_library"; then
11313bd1da9d7Smrg	      # Do each command in the old_postuninstall commands.
11314e6d2e958Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315bd1da9d7Smrg	    fi
11316bd1da9d7Smrg	    # FIXME: should reinstall the best remaining shared library.
11317bd1da9d7Smrg	    ;;
11318bd1da9d7Smrg	  esac
11319bd1da9d7Smrg	fi
11320bd1da9d7Smrg	;;
11321bd1da9d7Smrg
11322bd1da9d7Smrg      *.lo)
11323bd1da9d7Smrg	# Possibly a libtool object, so verify it.
1132447e89262Smrg	if func_lalib_p "$file"; then
11325bd1da9d7Smrg
11326bd1da9d7Smrg	  # Read the .lo file
1132747e89262Smrg	  func_source $dir/$name
11328bd1da9d7Smrg
11329bd1da9d7Smrg	  # Add PIC object to the list of files to remove.
11330e6d2e958Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331899129b3Smrg	    func_append rmfiles " $dir/$pic_object"
11332bd1da9d7Smrg	  fi
11333bd1da9d7Smrg
11334bd1da9d7Smrg	  # Add non-PIC object to the list of files to remove.
11335e6d2e958Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336899129b3Smrg	    func_append rmfiles " $dir/$non_pic_object"
11337bd1da9d7Smrg	  fi
11338bd1da9d7Smrg	fi
11339bd1da9d7Smrg	;;
11340bd1da9d7Smrg
11341bd1da9d7Smrg      *)
11342e6d2e958Smrg	if test clean = "$opt_mode"; then
11343bd1da9d7Smrg	  noexename=$name
11344bd1da9d7Smrg	  case $file in
11345bd1da9d7Smrg	  *.exe)
1134647e89262Smrg	    func_stripname '' '.exe' "$file"
1134747e89262Smrg	    file=$func_stripname_result
1134847e89262Smrg	    func_stripname '' '.exe' "$name"
1134947e89262Smrg	    noexename=$func_stripname_result
11350bd1da9d7Smrg	    # $file with .exe has already been added to rmfiles,
11351bd1da9d7Smrg	    # add $file without .exe
11352899129b3Smrg	    func_append rmfiles " $file"
11353bd1da9d7Smrg	    ;;
11354bd1da9d7Smrg	  esac
11355bd1da9d7Smrg	  # Do a test to see if this is a libtool program.
1135647e89262Smrg	  if func_ltwrapper_p "$file"; then
1135747e89262Smrg	    if func_ltwrapper_executable_p "$file"; then
1135847e89262Smrg	      func_ltwrapper_scriptname "$file"
1135947e89262Smrg	      relink_command=
1136047e89262Smrg	      func_source $func_ltwrapper_scriptname_result
11361899129b3Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1136247e89262Smrg	    else
1136347e89262Smrg	      relink_command=
1136447e89262Smrg	      func_source $dir/$noexename
1136547e89262Smrg	    fi
11366bd1da9d7Smrg
11367bd1da9d7Smrg	    # note $name still contains .exe if it was in $file originally
11368bd1da9d7Smrg	    # as does the version of $file that was added into $rmfiles
11369e6d2e958Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370e6d2e958Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371899129b3Smrg	      func_append rmfiles " $odir/lt-$name"
11372bd1da9d7Smrg	    fi
11373e6d2e958Smrg	    if test "X$noexename" != "X$name"; then
11374e6d2e958Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375bd1da9d7Smrg	    fi
11376bd1da9d7Smrg	  fi
11377bd1da9d7Smrg	fi
11378bd1da9d7Smrg	;;
11379bd1da9d7Smrg      esac
1138047e89262Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381bd1da9d7Smrg    done
11382bd1da9d7Smrg
11383e6d2e958Smrg    # Try to remove the $objdir's in the directories where we deleted files
11384bd1da9d7Smrg    for dir in $rmdirs; do
11385bd1da9d7Smrg      if test -d "$dir"; then
1138647e89262Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387bd1da9d7Smrg      fi
11388bd1da9d7Smrg    done
11389bd1da9d7Smrg
11390bd1da9d7Smrg    exit $exit_status
1139147e89262Smrg}
11392bd1da9d7Smrg
11393e6d2e958Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394e6d2e958Smrg  func_mode_uninstall ${1+"$@"}
11395e6d2e958Smrgfi
11396bd1da9d7Smrg
11397899129b3Smrgtest -z "$opt_mode" && {
11398e6d2e958Smrg  help=$generic_help
1139947e89262Smrg  func_fatal_help "you must specify a MODE"
1140047e89262Smrg}
1140147e89262Smrg
1140247e89262Smrgtest -z "$exec_cmd" && \
11403e6d2e958Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404bd1da9d7Smrg
11405bd1da9d7Smrgif test -n "$exec_cmd"; then
1140647e89262Smrg  eval exec "$exec_cmd"
11407bd1da9d7Smrg  exit $EXIT_FAILURE
11408bd1da9d7Smrgfi
11409bd1da9d7Smrg
1141047e89262Smrgexit $exit_status
11411bd1da9d7Smrg
11412bd1da9d7Smrg
11413bd1da9d7Smrg# The TAGs below are defined such that we never get into a situation
11414e6d2e958Smrg# where we disable both kinds of libraries.  Given conflicting
11415bd1da9d7Smrg# choices, we go for a static library, that is the most portable,
11416bd1da9d7Smrg# since we can't tell whether shared libraries were disabled because
11417bd1da9d7Smrg# the user asked for that or because the platform doesn't support
11418bd1da9d7Smrg# them.  This is particularly important on AIX, because we don't
11419bd1da9d7Smrg# support having both static and shared libraries enabled at the same
11420bd1da9d7Smrg# time on that platform, so we default to a shared-only configuration.
11421bd1da9d7Smrg# If a disable-shared tag is given, we'll fallback to a static-only
11422bd1da9d7Smrg# configuration.  But we'll never go from static-only to shared-only.
11423bd1da9d7Smrg
11424bd1da9d7Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1142547e89262Smrgbuild_libtool_libs=no
1142647e89262Smrgbuild_old_libs=yes
11427bd1da9d7Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428bd1da9d7Smrg
11429bd1da9d7Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1143047e89262Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431bd1da9d7Smrg# ### END LIBTOOL TAG CONFIG: disable-static
11432bd1da9d7Smrg
11433bd1da9d7Smrg# Local Variables:
11434bd1da9d7Smrg# mode:shell-script
11435bd1da9d7Smrg# sh-indentation:2
11436bd1da9d7Smrg# End:
11437