11009a292Smrg#! /usr/bin/env sh
2a3129944Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
31009a292Smrg##               by inline-source v2019-02-19.15
4698f425bSmrg
53bf3b463Smrg# libtool (GNU libtool) 2.5.4
6a3129944Smrg# Provide generalized library-building support services.
7698f425bSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8698f425bSmrg
93bf3b463Smrg# Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc.
10698f425bSmrg# This is free software; see the source for copying conditions.  There is NO
11698f425bSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12698f425bSmrg
13698f425bSmrg# GNU Libtool is free software; you can redistribute it and/or modify
14266e564dSmrg# it under the terms of the GNU General Public License as published by
15266e564dSmrg# the Free Software Foundation; either version 2 of the License, or
16266e564dSmrg# (at your option) any later version.
17266e564dSmrg#
18698f425bSmrg# As a special exception to the GNU General Public License,
19698f425bSmrg# if you distribute this file as part of a program or library that
20698f425bSmrg# is built using GNU Libtool, you may include this file under the
21698f425bSmrg# same distribution terms that you use for the rest of that program.
22698f425bSmrg#
23698f425bSmrg# GNU Libtool is distributed in the hope that it will be useful, but
24266e564dSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25266e564dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26266e564dSmrg# General Public License for more details.
27266e564dSmrg#
28266e564dSmrg# You should have received a copy of the GNU General Public License
29a3129944Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30c5629e66Smrg
31266e564dSmrg
329ef0b394SmrgPROGRAM=libtool
33266e564dSmrgPACKAGE=libtool
343bf3b463SmrgVERSION=2.5.4
353bf3b463Smrgpackage_revision=2.5.4
36c5629e66Smrg
37a3129944Smrg
38a3129944Smrg## ------ ##
39a3129944Smrg## Usage. ##
40a3129944Smrg## ------ ##
41a3129944Smrg
42a3129944Smrg# Run './libtool --help' for help with using this script from the
43a3129944Smrg# command line.
44a3129944Smrg
45a3129944Smrg
46a3129944Smrg## ------------------------------- ##
47a3129944Smrg## User overridable command paths. ##
48a3129944Smrg## ------------------------------- ##
49a3129944Smrg
50a3129944Smrg# After configure completes, it has a better idea of some of the
51a3129944Smrg# shell tools we need than the defaults used by the functions shared
52a3129944Smrg# with bootstrap, so set those here where they can still be over-
53a3129944Smrg# ridden by the user, but otherwise take precedence.
54a3129944Smrg
55a3129944Smrg: ${AUTOCONF="autoconf"}
56a3129944Smrg: ${AUTOMAKE="automake"}
57a3129944Smrg
58a3129944Smrg
59a3129944Smrg## -------------------------- ##
60a3129944Smrg## Source external libraries. ##
61a3129944Smrg## -------------------------- ##
62a3129944Smrg
63a3129944Smrg# Much of our low-level functionality needs to be sourced from external
64a3129944Smrg# libraries, which are installed to $pkgauxdir.
65a3129944Smrg
66a3129944Smrg# Set a version string for this script.
671009a292Smrgscriptversion=2019-02-19.15; # UTC
68a3129944Smrg
69a3129944Smrg# General shell script boiler plate, and helper functions.
70a3129944Smrg# Written by Gary V. Vaughan, 2004
71a3129944Smrg
721009a292Smrg# This is free software.  There is NO warranty; not even for
731009a292Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
741009a292Smrg#
753bf3b463Smrg# Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors
761009a292Smrg#
771009a292Smrg# This file is dual licensed under the terms of the MIT license
783bf3b463Smrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
793bf3b463Smrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
801009a292Smrg# these licenses when using or redistributing this software or any of
811009a292Smrg# the files within it.  See the URLs above, or the file `LICENSE`
821009a292Smrg# included in the Bootstrap distribution for the full license texts.
83a3129944Smrg
841009a292Smrg# Please report bugs or propose patches to:
851009a292Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86a3129944Smrg
87a3129944Smrg
88a3129944Smrg## ------ ##
89a3129944Smrg## Usage. ##
90a3129944Smrg## ------ ##
91a3129944Smrg
92a3129944Smrg# Evaluate this file near the top of your script to gain access to
93a3129944Smrg# the functions and variables defined here:
94a3129944Smrg#
95a3129944Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96a3129944Smrg#
97a3129944Smrg# If you need to override any of the default environment variable
98a3129944Smrg# settings, do that before evaluating this file.
99a3129944Smrg
100a3129944Smrg
101a3129944Smrg## -------------------- ##
102a3129944Smrg## Shell normalisation. ##
103a3129944Smrg## -------------------- ##
104a3129944Smrg
105a3129944Smrg# Some shells need a little help to be as Bourne compatible as possible.
106a3129944Smrg# Before doing anything else, make sure all that help has been provided!
107a3129944Smrg
108a3129944SmrgDUALCASE=1; export DUALCASE # for MKS sh
109a3129944Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110c5629e66Smrg  emulate sh
111c5629e66Smrg  NULLCMD=:
112a3129944Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113c5629e66Smrg  # is contrary to our usage.  Disable this feature.
114c5629e66Smrg  alias -g '${1+"$@"}'='"$@"'
115266e564dSmrg  setopt NO_GLOB_SUBST
116c5629e66Smrgelse
117a3129944Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118266e564dSmrgfi
1199ef0b394Smrg
120a3129944Smrg# NLS nuisances: We save the old values in case they are required later.
121a3129944Smrg_G_user_locale=
122a3129944Smrg_G_safe_locale=
123a3129944Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124c5629e66Smrgdo
125a3129944Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126a3129944Smrg          save_$_G_var=\$$_G_var
127a3129944Smrg          $_G_var=C
128a3129944Smrg	  export $_G_var
129a3129944Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130a3129944Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131c5629e66Smrg	fi"
132c5629e66Smrgdone
1331009a292Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1341009a292Smrg# in case the environment reset is needed later and the $save_* variant is not
1351009a292Smrg# defined (see the code above).
1361009a292SmrgLC_ALL=C
1371009a292SmrgLANGUAGE=C
1381009a292Smrgexport LANGUAGE LC_ALL
139698f425bSmrg
140a3129944Smrg# Make sure IFS has a sensible default
141a3129944Smrgsp=' '
142a3129944Smrgnl='
143a3129944Smrg'
144a3129944SmrgIFS="$sp	$nl"
145a3129944Smrg
1463bf3b463Smrg# There are apparently some systems that use ';' as a PATH separator!
147a3129944Smrgif test "${PATH_SEPARATOR+set}" != set; then
148a3129944Smrg  PATH_SEPARATOR=:
149a3129944Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150a3129944Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151a3129944Smrg      PATH_SEPARATOR=';'
152a3129944Smrg  }
153a3129944Smrgfi
154698f425bSmrg
155698f425bSmrg
1561009a292Smrg# func_unset VAR
1571009a292Smrg# --------------
1581009a292Smrg# Portably unset VAR.
1591009a292Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1601009a292Smrg# status if VAR is already unset, which might be problematic if the
1611009a292Smrg# statement is used at the end of a function (thus poisoning its return
1621009a292Smrg# value) or when 'set -e' is active (causing even a spurious abort of
1631009a292Smrg# the script in this case).
1641009a292Smrgfunc_unset ()
1651009a292Smrg{
1661009a292Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1671009a292Smrg}
1681009a292Smrg
1691009a292Smrg
1701009a292Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1711009a292Smrgfunc_unset CDPATH
1721009a292Smrg
1731009a292Smrg# Make sure ${,E,F}GREP behave sanely.
1741009a292Smrgfunc_unset GREP_OPTIONS
1751009a292Smrg
176698f425bSmrg
177a3129944Smrg## ------------------------- ##
178a3129944Smrg## Locate command utilities. ##
179a3129944Smrg## ------------------------- ##
180a3129944Smrg
181a3129944Smrg
182a3129944Smrg# func_executable_p FILE
183a3129944Smrg# ----------------------
184a3129944Smrg# Check that FILE is an executable regular file.
185a3129944Smrgfunc_executable_p ()
186a3129944Smrg{
187a3129944Smrg    test -f "$1" && test -x "$1"
188a3129944Smrg}
189a3129944Smrg
190a3129944Smrg
191a3129944Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192a3129944Smrg# --------------------------------------------
193a3129944Smrg# Search for either a program that responds to --version with output
194a3129944Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195a3129944Smrg# trying all the directories in PATH with each of the elements of
196a3129944Smrg# PROGS_LIST.
197a3129944Smrg#
198a3129944Smrg# CHECK_FUNC should accept the path to a candidate program, and
199a3129944Smrg# set $func_check_prog_result if it truncates its output less than
200a3129944Smrg# $_G_path_prog_max characters.
201a3129944Smrgfunc_path_progs ()
202a3129944Smrg{
203a3129944Smrg    _G_progs_list=$1
204a3129944Smrg    _G_check_func=$2
205a3129944Smrg    _G_PATH=${3-"$PATH"}
206a3129944Smrg
207a3129944Smrg    _G_path_prog_max=0
208a3129944Smrg    _G_path_prog_found=false
209a3129944Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210a3129944Smrg    for _G_dir in $_G_PATH; do
211a3129944Smrg      IFS=$_G_save_IFS
212a3129944Smrg      test -z "$_G_dir" && _G_dir=.
213a3129944Smrg      for _G_prog_name in $_G_progs_list; do
214a3129944Smrg        for _exeext in '' .EXE; do
215a3129944Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216a3129944Smrg          func_executable_p "$_G_path_prog" || continue
217a3129944Smrg          case `"$_G_path_prog" --version 2>&1` in
218a3129944Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219a3129944Smrg            *)     $_G_check_func $_G_path_prog
220a3129944Smrg		   func_path_progs_result=$func_check_prog_result
221a3129944Smrg		   ;;
222a3129944Smrg          esac
223a3129944Smrg          $_G_path_prog_found && break 3
224a3129944Smrg        done
225a3129944Smrg      done
226a3129944Smrg    done
227a3129944Smrg    IFS=$_G_save_IFS
228a3129944Smrg    test -z "$func_path_progs_result" && {
229a3129944Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230a3129944Smrg      exit 1
231a3129944Smrg    }
232a3129944Smrg}
233a3129944Smrg
234a3129944Smrg
235a3129944Smrg# We want to be able to use the functions in this file before configure
236a3129944Smrg# has figured out where the best binaries are kept, which means we have
237a3129944Smrg# to search for them ourselves - except when the results are already set
238a3129944Smrg# where we skip the searches.
239a3129944Smrg
240a3129944Smrg# Unless the user overrides by setting SED, search the path for either GNU
241a3129944Smrg# sed, or the sed that truncates its output the least.
242a3129944Smrgtest -z "$SED" && {
243a3129944Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244a3129944Smrg  for _G_i in 1 2 3 4 5 6 7; do
245a3129944Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246a3129944Smrg  done
247a3129944Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248a3129944Smrg  _G_sed_script=
249a3129944Smrg
250a3129944Smrg  func_check_prog_sed ()
251a3129944Smrg  {
252a3129944Smrg    _G_path_prog=$1
253a3129944Smrg
254a3129944Smrg    _G_count=0
255a3129944Smrg    printf 0123456789 >conftest.in
256a3129944Smrg    while :
257a3129944Smrg    do
258a3129944Smrg      cat conftest.in conftest.in >conftest.tmp
259a3129944Smrg      mv conftest.tmp conftest.in
260a3129944Smrg      cp conftest.in conftest.nl
261a3129944Smrg      echo '' >> conftest.nl
262a3129944Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263a3129944Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264a3129944Smrg      _G_count=`expr $_G_count + 1`
265a3129944Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266a3129944Smrg        # Best one so far, save it but keep looking for a better one
267a3129944Smrg        func_check_prog_result=$_G_path_prog
268a3129944Smrg        _G_path_prog_max=$_G_count
269a3129944Smrg      fi
270a3129944Smrg      # 10*(2^10) chars as input seems more than enough
271a3129944Smrg      test 10 -lt "$_G_count" && break
272a3129944Smrg    done
273a3129944Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274a3129944Smrg  }
275a3129944Smrg
2761009a292Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277a3129944Smrg  rm -f conftest.sed
278a3129944Smrg  SED=$func_path_progs_result
279a3129944Smrg}
280a3129944Smrg
281a3129944Smrg
282a3129944Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283a3129944Smrg# grep, or the grep that truncates its output the least.
284a3129944Smrgtest -z "$GREP" && {
285a3129944Smrg  func_check_prog_grep ()
286a3129944Smrg  {
287a3129944Smrg    _G_path_prog=$1
288a3129944Smrg
289a3129944Smrg    _G_count=0
290a3129944Smrg    _G_path_prog_max=0
291a3129944Smrg    printf 0123456789 >conftest.in
292a3129944Smrg    while :
293a3129944Smrg    do
294a3129944Smrg      cat conftest.in conftest.in >conftest.tmp
295a3129944Smrg      mv conftest.tmp conftest.in
296a3129944Smrg      cp conftest.in conftest.nl
297a3129944Smrg      echo 'GREP' >> conftest.nl
298a3129944Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299a3129944Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300a3129944Smrg      _G_count=`expr $_G_count + 1`
301a3129944Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302a3129944Smrg        # Best one so far, save it but keep looking for a better one
303a3129944Smrg        func_check_prog_result=$_G_path_prog
304a3129944Smrg        _G_path_prog_max=$_G_count
305a3129944Smrg      fi
306a3129944Smrg      # 10*(2^10) chars as input seems more than enough
307a3129944Smrg      test 10 -lt "$_G_count" && break
308a3129944Smrg    done
309a3129944Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310a3129944Smrg  }
311a3129944Smrg
3121009a292Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313a3129944Smrg  GREP=$func_path_progs_result
314a3129944Smrg}
315a3129944Smrg
316a3129944Smrg
317a3129944Smrg## ------------------------------- ##
318a3129944Smrg## User overridable command paths. ##
319a3129944Smrg## ------------------------------- ##
320a3129944Smrg
321a3129944Smrg# All uppercase variable names are used for environment variables.  These
322a3129944Smrg# variables can be overridden by the user before calling a script that
323a3129944Smrg# uses them if a suitable command of that name is not already available
324a3129944Smrg# in the command search PATH.
325698f425bSmrg
326698f425bSmrg: ${CP="cp -f"}
327a3129944Smrg: ${ECHO="printf %s\n"}
328a3129944Smrg: ${EGREP="$GREP -E"}
329a3129944Smrg: ${FGREP="$GREP -F"}
330a3129944Smrg: ${LN_S="ln -s"}
331698f425bSmrg: ${MAKE="make"}
332698f425bSmrg: ${MKDIR="mkdir"}
333698f425bSmrg: ${MV="mv -f"}
334698f425bSmrg: ${RM="rm -f"}
335698f425bSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336266e564dSmrg
337698f425bSmrg
338a3129944Smrg## -------------------- ##
339a3129944Smrg## Useful sed snippets. ##
340a3129944Smrg## -------------------- ##
3419ef0b394Smrg
342a3129944Smrgsed_dirname='s|/[^/]*$||'
343a3129944Smrgsed_basename='s|^.*/||'
3449ef0b394Smrg
345a3129944Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346a3129944Smrg# metacharacters that are still active within double-quoted strings.
347a3129944Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3489ef0b394Smrg
349a3129944Smrg# Same as above, but do not quote variable references.
350a3129944Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3519ef0b394Smrg
352a3129944Smrg# Sed substitution that turns a string into a regex matching for the
353a3129944Smrg# string literally.
354a3129944Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3559ef0b394Smrg
356a3129944Smrg# Sed substitution that converts a w32 file name or path
357a3129944Smrg# that contains forward slashes, into one that contains
358a3129944Smrg# (escaped) backslashes.  A very naive implementation.
359a3129944Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360a3129944Smrg
361a3129944Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362a3129944Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363a3129944Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364a3129944Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365a3129944Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366a3129944Smrg_G_bs='\\'
367a3129944Smrg_G_bs2='\\\\'
368a3129944Smrg_G_bs4='\\\\\\\\'
369a3129944Smrg_G_dollar='\$'
370a3129944Smrgsed_double_backslash="\
371a3129944Smrg  s/$_G_bs4/&\\
372a3129944Smrg/g
373a3129944Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374a3129944Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375a3129944Smrg  s/\n//g"
3769ef0b394Smrg
3771009a292Smrg# require_check_ifs_backslash
3781009a292Smrg# ---------------------------
3791009a292Smrg# Check if we can use backslash as IFS='\' separator, and set
3801009a292Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
3811009a292Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3821009a292Smrgfunc_require_check_ifs_backslash ()
3831009a292Smrg{
3841009a292Smrg  _G_save_IFS=$IFS
3851009a292Smrg  IFS='\'
3861009a292Smrg  _G_check_ifs_backshlash='a\\b'
3871009a292Smrg  for _G_i in $_G_check_ifs_backshlash
3881009a292Smrg  do
3891009a292Smrg  case $_G_i in
3901009a292Smrg  a)
3911009a292Smrg    check_ifs_backshlash_broken=false
3921009a292Smrg    ;;
3931009a292Smrg  '')
3941009a292Smrg    break
3951009a292Smrg    ;;
3961009a292Smrg  *)
3971009a292Smrg    check_ifs_backshlash_broken=:
3981009a292Smrg    break
3991009a292Smrg    ;;
4001009a292Smrg  esac
4011009a292Smrg  done
4021009a292Smrg  IFS=$_G_save_IFS
4031009a292Smrg  require_check_ifs_backslash=:
4041009a292Smrg}
4051009a292Smrg
4069ef0b394Smrg
407a3129944Smrg## ----------------- ##
408a3129944Smrg## Global variables. ##
409a3129944Smrg## ----------------- ##
4109ef0b394Smrg
411a3129944Smrg# Except for the global variables explicitly listed below, the following
412a3129944Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413a3129944Smrg# variables initialised in the 'Resource management' section, sourcing
414a3129944Smrg# this file will not pollute your global namespace with anything
415a3129944Smrg# else. There's no portable way to scope variables in Bourne shell
416a3129944Smrg# though, so actually running these functions will sometimes place
417a3129944Smrg# results into a variable named after the function, and often use
418a3129944Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419a3129944Smrg# avoid using those namespaces casually in your sourcing script, things
420a3129944Smrg# should continue to work as you expect. And, of course, you can freely
421a3129944Smrg# overwrite any of the functions or variables defined here before
422a3129944Smrg# calling anything to customize them.
4239ef0b394Smrg
424a3129944SmrgEXIT_SUCCESS=0
425a3129944SmrgEXIT_FAILURE=1
426a3129944SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427a3129944SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428266e564dSmrg
429a3129944Smrg# Allow overriding, eg assuming that you follow the convention of
430a3129944Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431a3129944Smrg# bash to show function call trace with:
432a3129944Smrg#
433a3129944Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434a3129944Smrgdebug_cmd=${debug_cmd-":"}
435a3129944Smrgexit_cmd=:
436698f425bSmrg
437a3129944Smrg# By convention, finish your script with:
438a3129944Smrg#
439a3129944Smrg#    exit $exit_status
440a3129944Smrg#
441a3129944Smrg# so that you can set exit_status to non-zero if you want to indicate
442a3129944Smrg# something went wrong during execution without actually bailing out at
443a3129944Smrg# the point of failure.
444a3129944Smrgexit_status=$EXIT_SUCCESS
4459ef0b394Smrg
446a3129944Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447a3129944Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448a3129944Smrg# the _XPG environment variable is not equal to 1 (one), the special
449a3129944Smrg# positional parameter $0, within a function call, is the name of the
450a3129944Smrg# function.
451a3129944Smrgprogpath=$0
452698f425bSmrg
453a3129944Smrg# The name of this program.
454a3129944Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455698f425bSmrg
456a3129944Smrg# Make sure we have an absolute progpath for reexecution:
457698f425bSmrgcase $progpath in
458698f425bSmrg  [\\/]*|[A-Za-z]:\\*) ;;
459698f425bSmrg  *[\\/]*)
460a3129944Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461698f425bSmrg     progdir=`cd "$progdir" && pwd`
462a3129944Smrg     progpath=$progdir/$progname
463698f425bSmrg     ;;
464698f425bSmrg  *)
465a3129944Smrg     _G_IFS=$IFS
466fb5e8d76Smrg     IFS=${PATH_SEPARATOR-:}
467698f425bSmrg     for progdir in $PATH; do
468a3129944Smrg       IFS=$_G_IFS
469698f425bSmrg       test -x "$progdir/$progname" && break
470698f425bSmrg     done
471a3129944Smrg     IFS=$_G_IFS
472698f425bSmrg     test -n "$progdir" || progdir=`pwd`
473a3129944Smrg     progpath=$progdir/$progname
474698f425bSmrg     ;;
475698f425bSmrgesac
476698f425bSmrg
477698f425bSmrg
478a3129944Smrg## ----------------- ##
479a3129944Smrg## Standard options. ##
480a3129944Smrg## ----------------- ##
4819ef0b394Smrg
482a3129944Smrg# The following options affect the operation of the functions defined
483a3129944Smrg# below, and should be set appropriately depending on run-time para-
484a3129944Smrg# meters passed on the command line.
485698f425bSmrg
486698f425bSmrgopt_dry_run=false
487698f425bSmrgopt_quiet=false
488698f425bSmrgopt_verbose=false
489698f425bSmrg
490a3129944Smrg# Categories 'all' and 'none' are always available.  Append any others
491a3129944Smrg# you will pass as the first argument to func_warning from your own
492a3129944Smrg# code.
493a3129944Smrgwarning_categories=
494698f425bSmrg
495a3129944Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496a3129944Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497a3129944Smrg# treat the next displayed warning as a fatal error.
498a3129944Smrgwarning_func=func_warn_and_continue
499698f425bSmrg
500a3129944Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501a3129944Smrg# warnings, or a space delimited list of some subset of
502a3129944Smrg# 'warning_categories' to display only the listed warnings.
503a3129944Smrgopt_warning_types=all
504698f425bSmrg
5059ef0b394Smrg
506a3129944Smrg## -------------------- ##
507a3129944Smrg## Resource management. ##
508a3129944Smrg## -------------------- ##
509698f425bSmrg
510a3129944Smrg# This section contains definitions for functions that each ensure a
511a3129944Smrg# particular resource (a file, or a non-empty configuration variable for
512a3129944Smrg# example) is available, and if appropriate to extract default values
513a3129944Smrg# from pertinent package files. Call them using their associated
514a3129944Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515a3129944Smrg#
516a3129944Smrg# It's entirely deliberate that calling these functions can set
517a3129944Smrg# variables that don't obey the namespace limitations obeyed by the rest
518a3129944Smrg# of this file, in order that that they be as useful as possible to
519a3129944Smrg# callers.
520698f425bSmrg
521698f425bSmrg
522a3129944Smrg# require_term_colors
523a3129944Smrg# -------------------
524a3129944Smrg# Allow display of bold text on terminals that support it.
525a3129944Smrgrequire_term_colors=func_require_term_colors
526a3129944Smrgfunc_require_term_colors ()
527698f425bSmrg{
528a3129944Smrg    $debug_cmd
529a3129944Smrg
530a3129944Smrg    test -t 1 && {
531a3129944Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532a3129944Smrg      # precedence, because most terminfo databases neglect to describe
533a3129944Smrg      # whether color sequences are supported.
534a3129944Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535a3129944Smrg
536a3129944Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537a3129944Smrg        # Standard ANSI escape sequences
538a3129944Smrg        tc_reset='[0m'
539a3129944Smrg        tc_bold='[1m';   tc_standout='[7m'
540a3129944Smrg        tc_red='[31m';   tc_green='[32m'
541a3129944Smrg        tc_blue='[34m';  tc_cyan='[36m'
542a3129944Smrg      else
543a3129944Smrg        # Otherwise trust the terminfo database after all.
544a3129944Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545a3129944Smrg          tc_reset=`tput sgr0`
546a3129944Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547a3129944Smrg          tc_standout=$tc_bold
548a3129944Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549a3129944Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550a3129944Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551a3129944Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552a3129944Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553a3129944Smrg        }
554a3129944Smrg      fi
555a3129944Smrg    }
556698f425bSmrg
557a3129944Smrg    require_term_colors=:
558698f425bSmrg}
559698f425bSmrg
560698f425bSmrg
561a3129944Smrg## ----------------- ##
562a3129944Smrg## Function library. ##
563a3129944Smrg## ----------------- ##
564a3129944Smrg
565a3129944Smrg# This section contains a variety of useful functions to call in your
566a3129944Smrg# scripts. Take note of the portable wrappers for features provided by
567a3129944Smrg# some modern shells, which will fall back to slower equivalents on
568a3129944Smrg# less featureful shells.
569a3129944Smrg
570a3129944Smrg
571a3129944Smrg# func_append VAR VALUE
572a3129944Smrg# ---------------------
573a3129944Smrg# Append VALUE onto the existing contents of VAR.
574a3129944Smrg
575a3129944Smrg  # We should try to minimise forks, especially on Windows where they are
576a3129944Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577a3129944Smrg  # being used:
578a3129944Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579a3129944Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580a3129944Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581a3129944Smrg    # The += operator was introduced in bash 3.1
582a3129944Smrg    case $BASH_VERSION in
583a3129944Smrg      [12].* | 3.0 | 3.0*) ;;
584a3129944Smrg      *)
585a3129944Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586a3129944Smrg        ;;
587a3129944Smrg    esac
588a3129944Smrg  fi
589a3129944Smrg
590a3129944Smrg  # _G_HAVE_PLUSEQ_OP
591a3129944Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
5923bf3b463Smrg  # usable or anything else if it does not work.
593a3129944Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594a3129944Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595a3129944Smrg    && _G_HAVE_PLUSEQ_OP=yes
596a3129944Smrg
597a3129944Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598a3129944Smrgthen
599a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600a3129944Smrg  eval 'func_append ()
601a3129944Smrg  {
602a3129944Smrg    $debug_cmd
603a3129944Smrg
604a3129944Smrg    eval "$1+=\$2"
605a3129944Smrg  }'
606a3129944Smrgelse
607a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608a3129944Smrg  func_append ()
609a3129944Smrg  {
610a3129944Smrg    $debug_cmd
611a3129944Smrg
612a3129944Smrg    eval "$1=\$$1\$2"
613a3129944Smrg  }
614a3129944Smrgfi
615a3129944Smrg
616a3129944Smrg
617a3129944Smrg# func_append_quoted VAR VALUE
618a3129944Smrg# ----------------------------
619a3129944Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620a3129944Smrg# by a space.
621a3129944Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622a3129944Smrg  eval 'func_append_quoted ()
623a3129944Smrg  {
624a3129944Smrg    $debug_cmd
625a3129944Smrg
6261009a292Smrg    func_quote_arg pretty "$2"
6271009a292Smrg    eval "$1+=\\ \$func_quote_arg_result"
628a3129944Smrg  }'
629a3129944Smrgelse
630a3129944Smrg  func_append_quoted ()
631a3129944Smrg  {
632a3129944Smrg    $debug_cmd
633a3129944Smrg
6341009a292Smrg    func_quote_arg pretty "$2"
6351009a292Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636a3129944Smrg  }
637a3129944Smrgfi
638a3129944Smrg
639a3129944Smrg
640a3129944Smrg# func_append_uniq VAR VALUE
641a3129944Smrg# --------------------------
642a3129944Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643a3129944Smrg# entries are delimited by the first character of VALUE.  For example:
644a3129944Smrg#
645a3129944Smrg#   func_append_uniq options " --another-option option-argument"
646a3129944Smrg#
647a3129944Smrg# will only append to $options if " --another-option option-argument "
648a3129944Smrg# is not already present somewhere in $options already (note spaces at
649a3129944Smrg# each end implied by leading space in second argument).
650a3129944Smrgfunc_append_uniq ()
651a3129944Smrg{
652a3129944Smrg    $debug_cmd
653a3129944Smrg
654a3129944Smrg    eval _G_current_value='`$ECHO $'$1'`'
655a3129944Smrg    _G_delim=`expr "$2" : '\(.\)'`
656a3129944Smrg
657a3129944Smrg    case $_G_delim$_G_current_value$_G_delim in
658a3129944Smrg      *"$2$_G_delim"*) ;;
659a3129944Smrg      *) func_append "$@" ;;
660a3129944Smrg    esac
661a3129944Smrg}
662a3129944Smrg
663a3129944Smrg
664a3129944Smrg# func_arith TERM...
665a3129944Smrg# ------------------
666a3129944Smrg# Set func_arith_result to the result of evaluating TERMs.
667a3129944Smrg  test -z "$_G_HAVE_ARITH_OP" \
668a3129944Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669a3129944Smrg    && _G_HAVE_ARITH_OP=yes
670a3129944Smrg
671a3129944Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672a3129944Smrg  eval 'func_arith ()
673a3129944Smrg  {
674a3129944Smrg    $debug_cmd
675a3129944Smrg
676a3129944Smrg    func_arith_result=$(( $* ))
677a3129944Smrg  }'
678a3129944Smrgelse
679a3129944Smrg  func_arith ()
680a3129944Smrg  {
681a3129944Smrg    $debug_cmd
682a3129944Smrg
683a3129944Smrg    func_arith_result=`expr "$@"`
684a3129944Smrg  }
685a3129944Smrgfi
686a3129944Smrg
687a3129944Smrg
688a3129944Smrg# func_basename FILE
689a3129944Smrg# ------------------
690a3129944Smrg# Set func_basename_result to FILE with everything up to and including
691a3129944Smrg# the last / stripped.
692a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693a3129944Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694a3129944Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695a3129944Smrg  # on unsupported syntax...
696a3129944Smrg  _b='func_basename_result=${1##*/}'
697a3129944Smrg  _d='case $1 in
698a3129944Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699a3129944Smrg        *  ) func_dirname_result=$3        ;;
700a3129944Smrg      esac'
701a3129944Smrg
702a3129944Smrgelse
703a3129944Smrg  # ...otherwise fall back to using sed.
704a3129944Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705a3129944Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706a3129944Smrg      if test "X$func_dirname_result" = "X$1"; then
707a3129944Smrg        func_dirname_result=$3
708a3129944Smrg      else
709a3129944Smrg        func_append func_dirname_result "$2"
710a3129944Smrg      fi'
711a3129944Smrgfi
712a3129944Smrg
713a3129944Smrgeval 'func_basename ()
714a3129944Smrg{
715a3129944Smrg    $debug_cmd
716a3129944Smrg
717a3129944Smrg    '"$_b"'
718a3129944Smrg}'
719a3129944Smrg
720a3129944Smrg
721a3129944Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722a3129944Smrg# -------------------------------------------
723a3129944Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724a3129944Smrg# otherwise set result to NONDIR_REPLACEMENT.
725a3129944Smrgeval 'func_dirname ()
726a3129944Smrg{
727a3129944Smrg    $debug_cmd
728a3129944Smrg
729a3129944Smrg    '"$_d"'
730a3129944Smrg}'
731a3129944Smrg
732a3129944Smrg
733a3129944Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734a3129944Smrg# --------------------------------------------------------
735a3129944Smrg# Perform func_basename and func_dirname in a single function
736a3129944Smrg# call:
737a3129944Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738a3129944Smrg#             add APPEND to the result, otherwise set result
739a3129944Smrg#             to NONDIR_REPLACEMENT.
740a3129944Smrg#             value returned in "$func_dirname_result"
741a3129944Smrg#   basename: Compute filename of FILE.
7423bf3b463Smrg#             value returned in "$func_basename_result"
743a3129944Smrg# For efficiency, we do not delegate to the functions above but instead
744a3129944Smrg# duplicate the functionality here.
745a3129944Smrgeval 'func_dirname_and_basename ()
746a3129944Smrg{
747a3129944Smrg    $debug_cmd
748a3129944Smrg
749a3129944Smrg    '"$_b"'
750a3129944Smrg    '"$_d"'
751a3129944Smrg}'
752a3129944Smrg
753a3129944Smrg
754a3129944Smrg# func_echo ARG...
755a3129944Smrg# ----------------
756a3129944Smrg# Echo program name prefixed message.
757a3129944Smrgfunc_echo ()
758a3129944Smrg{
759a3129944Smrg    $debug_cmd
760a3129944Smrg
761a3129944Smrg    _G_message=$*
762a3129944Smrg
763a3129944Smrg    func_echo_IFS=$IFS
764a3129944Smrg    IFS=$nl
765a3129944Smrg    for _G_line in $_G_message; do
766a3129944Smrg      IFS=$func_echo_IFS
767a3129944Smrg      $ECHO "$progname: $_G_line"
768a3129944Smrg    done
769a3129944Smrg    IFS=$func_echo_IFS
770a3129944Smrg}
771a3129944Smrg
772a3129944Smrg
773a3129944Smrg# func_echo_all ARG...
774a3129944Smrg# --------------------
775a3129944Smrg# Invoke $ECHO with all args, space-separated.
776a3129944Smrgfunc_echo_all ()
777a3129944Smrg{
778a3129944Smrg    $ECHO "$*"
779a3129944Smrg}
780a3129944Smrg
781a3129944Smrg
782a3129944Smrg# func_echo_infix_1 INFIX ARG...
783a3129944Smrg# ------------------------------
784a3129944Smrg# Echo program name, followed by INFIX on the first line, with any
785a3129944Smrg# additional lines not showing INFIX.
786a3129944Smrgfunc_echo_infix_1 ()
787a3129944Smrg{
788a3129944Smrg    $debug_cmd
789a3129944Smrg
790a3129944Smrg    $require_term_colors
791a3129944Smrg
792a3129944Smrg    _G_infix=$1; shift
793a3129944Smrg    _G_indent=$_G_infix
794a3129944Smrg    _G_prefix="$progname: $_G_infix: "
795a3129944Smrg    _G_message=$*
796a3129944Smrg
797a3129944Smrg    # Strip color escape sequences before counting printable length
798a3129944Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799a3129944Smrg    do
800a3129944Smrg      test -n "$_G_tc" && {
801a3129944Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802a3129944Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803a3129944Smrg      }
804a3129944Smrg    done
805a3129944Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806a3129944Smrg
807a3129944Smrg    func_echo_infix_1_IFS=$IFS
808a3129944Smrg    IFS=$nl
809a3129944Smrg    for _G_line in $_G_message; do
810a3129944Smrg      IFS=$func_echo_infix_1_IFS
811a3129944Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812a3129944Smrg      _G_prefix=$_G_indent
813a3129944Smrg    done
814a3129944Smrg    IFS=$func_echo_infix_1_IFS
815a3129944Smrg}
816a3129944Smrg
817a3129944Smrg
818a3129944Smrg# func_error ARG...
819a3129944Smrg# -----------------
820a3129944Smrg# Echo program name prefixed message to standard error.
821a3129944Smrgfunc_error ()
822a3129944Smrg{
823a3129944Smrg    $debug_cmd
824a3129944Smrg
825a3129944Smrg    $require_term_colors
826a3129944Smrg
827a3129944Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828a3129944Smrg}
829a3129944Smrg
830a3129944Smrg
831a3129944Smrg# func_fatal_error ARG...
832a3129944Smrg# -----------------------
833a3129944Smrg# Echo program name prefixed message to standard error, and exit.
834a3129944Smrgfunc_fatal_error ()
835a3129944Smrg{
836a3129944Smrg    $debug_cmd
837a3129944Smrg
838a3129944Smrg    func_error "$*"
839a3129944Smrg    exit $EXIT_FAILURE
840a3129944Smrg}
841a3129944Smrg
842a3129944Smrg
843a3129944Smrg# func_grep EXPRESSION FILENAME
844a3129944Smrg# -----------------------------
845698f425bSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846698f425bSmrgfunc_grep ()
847698f425bSmrg{
848a3129944Smrg    $debug_cmd
849a3129944Smrg
850698f425bSmrg    $GREP "$1" "$2" >/dev/null 2>&1
851698f425bSmrg}
852698f425bSmrg
853698f425bSmrg
854a3129944Smrg# func_len STRING
855a3129944Smrg# ---------------
856a3129944Smrg# Set func_len_result to the length of STRING. STRING may not
857a3129944Smrg# start with a hyphen.
858a3129944Smrg  test -z "$_G_HAVE_XSI_OPS" \
859a3129944Smrg    && (eval 'x=a/b/c;
860a3129944Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861a3129944Smrg    && _G_HAVE_XSI_OPS=yes
862a3129944Smrg
863a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864a3129944Smrg  eval 'func_len ()
865a3129944Smrg  {
866a3129944Smrg    $debug_cmd
867a3129944Smrg
868a3129944Smrg    func_len_result=${#1}
869a3129944Smrg  }'
870a3129944Smrgelse
871a3129944Smrg  func_len ()
872a3129944Smrg  {
873a3129944Smrg    $debug_cmd
874a3129944Smrg
875a3129944Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876a3129944Smrg  }
877a3129944Smrgfi
878a3129944Smrg
879a3129944Smrg
880a3129944Smrg# func_mkdir_p DIRECTORY-PATH
881a3129944Smrg# ---------------------------
882698f425bSmrg# Make sure the entire path to DIRECTORY-PATH is available.
883698f425bSmrgfunc_mkdir_p ()
884698f425bSmrg{
885a3129944Smrg    $debug_cmd
886698f425bSmrg
887a3129944Smrg    _G_directory_path=$1
888a3129944Smrg    _G_dir_list=
889698f425bSmrg
890a3129944Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891a3129944Smrg
892a3129944Smrg      # Protect directory names starting with '-'
893a3129944Smrg      case $_G_directory_path in
894a3129944Smrg        -*) _G_directory_path=./$_G_directory_path ;;
895698f425bSmrg      esac
896698f425bSmrg
897698f425bSmrg      # While some portion of DIR does not yet exist...
898a3129944Smrg      while test ! -d "$_G_directory_path"; do
899698f425bSmrg        # ...make a list in topmost first order.  Use a colon delimited
9003bf3b463Smrg	# list in case some portion of path contains whitespace.
901a3129944Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902698f425bSmrg
903698f425bSmrg        # If the last portion added has no slash in it, the list is done
904a3129944Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
905698f425bSmrg
906698f425bSmrg        # ...otherwise throw away the child directory and loop
907a3129944Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908698f425bSmrg      done
909a3129944Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910698f425bSmrg
911a3129944Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912a3129944Smrg      for _G_dir in $_G_dir_list; do
913a3129944Smrg	IFS=$func_mkdir_p_IFS
914a3129944Smrg        # mkdir can fail with a 'File exist' error if two processes
915698f425bSmrg        # try to create one of the directories concurrently.  Don't
916698f425bSmrg        # stop in that case!
917a3129944Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
918698f425bSmrg      done
919a3129944Smrg      IFS=$func_mkdir_p_IFS
920698f425bSmrg
921698f425bSmrg      # Bail out if we (or some other process) failed to create a directory.
922a3129944Smrg      test -d "$_G_directory_path" || \
923a3129944Smrg        func_fatal_error "Failed to create '$1'"
924698f425bSmrg    fi
925698f425bSmrg}
926266e564dSmrg
927266e564dSmrg
928a3129944Smrg# func_mktempdir [BASENAME]
929a3129944Smrg# -------------------------
930266e564dSmrg# Make a temporary directory that won't clash with other running
931266e564dSmrg# libtool processes, and avoids race conditions if possible.  If
932a3129944Smrg# given, BASENAME is the basename for that directory.
933266e564dSmrgfunc_mktempdir ()
934266e564dSmrg{
935a3129944Smrg    $debug_cmd
936a3129944Smrg
937a3129944Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938266e564dSmrg
939a3129944Smrg    if test : = "$opt_dry_run"; then
940266e564dSmrg      # Return a directory name, but don't create it in dry-run mode
941a3129944Smrg      _G_tmpdir=$_G_template-$$
942266e564dSmrg    else
943266e564dSmrg
944266e564dSmrg      # If mktemp works, use that first and foremost
945a3129944Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946266e564dSmrg
947a3129944Smrg      if test ! -d "$_G_tmpdir"; then
948698f425bSmrg        # Failing that, at least try and use $RANDOM to avoid a race
949a3129944Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950266e564dSmrg
951a3129944Smrg        func_mktempdir_umask=`umask`
952698f425bSmrg        umask 0077
953a3129944Smrg        $MKDIR "$_G_tmpdir"
954a3129944Smrg        umask $func_mktempdir_umask
955266e564dSmrg      fi
956266e564dSmrg
957266e564dSmrg      # If we're not in dry-run mode, bomb out on failure
958a3129944Smrg      test -d "$_G_tmpdir" || \
959a3129944Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960a3129944Smrg    fi
961a3129944Smrg
962a3129944Smrg    $ECHO "$_G_tmpdir"
963a3129944Smrg}
964a3129944Smrg
965a3129944Smrg
966a3129944Smrg# func_normal_abspath PATH
967a3129944Smrg# ------------------------
968a3129944Smrg# Remove doubled-up and trailing slashes, "." path components,
969a3129944Smrg# and cancel out any ".." path components in PATH after making
970a3129944Smrg# it an absolute path.
971a3129944Smrgfunc_normal_abspath ()
972a3129944Smrg{
973a3129944Smrg    $debug_cmd
974a3129944Smrg
975a3129944Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976a3129944Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977a3129944Smrg    _G_pathcdr='s|^/[^/]*||'
978a3129944Smrg    _G_removedotparts=':dotsl
979a3129944Smrg		s|/\./|/|g
980a3129944Smrg		t dotsl
981a3129944Smrg		s|/\.$|/|'
982a3129944Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983a3129944Smrg    _G_finalslash='s|/*$|/|'
984a3129944Smrg
985a3129944Smrg    # Start from root dir and reassemble the path.
986a3129944Smrg    func_normal_abspath_result=
987a3129944Smrg    func_normal_abspath_tpath=$1
988a3129944Smrg    func_normal_abspath_altnamespace=
989a3129944Smrg    case $func_normal_abspath_tpath in
990a3129944Smrg      "")
991a3129944Smrg        # Empty path, that just means $cwd.
992a3129944Smrg        func_stripname '' '/' "`pwd`"
993a3129944Smrg        func_normal_abspath_result=$func_stripname_result
994a3129944Smrg        return
995a3129944Smrg        ;;
996a3129944Smrg      # The next three entries are used to spot a run of precisely
997a3129944Smrg      # two leading slashes without using negated character classes;
998a3129944Smrg      # we take advantage of case's first-match behaviour.
999a3129944Smrg      ///*)
1000a3129944Smrg        # Unusual form of absolute path, do nothing.
1001a3129944Smrg        ;;
1002a3129944Smrg      //*)
1003a3129944Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004a3129944Smrg        # and for example Cygwin uses it to access remote file shares
1005a3129944Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006a3129944Smrg        func_normal_abspath_altnamespace=/
1007a3129944Smrg        ;;
1008a3129944Smrg      /*)
1009a3129944Smrg        # Absolute path, do nothing.
1010a3129944Smrg        ;;
1011a3129944Smrg      *)
1012a3129944Smrg        # Relative path, prepend $cwd.
1013a3129944Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014a3129944Smrg        ;;
1015a3129944Smrg    esac
1016a3129944Smrg
1017a3129944Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018a3129944Smrg    # the path to end with a slash for ease of parsing, so make sure
1019a3129944Smrg    # there is one (and only one) here.
1020a3129944Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021a3129944Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022a3129944Smrg    while :; do
1023a3129944Smrg      # Processed it all yet?
1024a3129944Smrg      if test / = "$func_normal_abspath_tpath"; then
1025a3129944Smrg        # If we ascended to the root using ".." the result may be empty now.
1026a3129944Smrg        if test -z "$func_normal_abspath_result"; then
1027a3129944Smrg          func_normal_abspath_result=/
1028a3129944Smrg        fi
1029a3129944Smrg        break
1030a3129944Smrg      fi
1031a3129944Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032a3129944Smrg          -e "$_G_pathcar"`
1033a3129944Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034a3129944Smrg          -e "$_G_pathcdr"`
1035a3129944Smrg      # Figure out what to do with it
1036a3129944Smrg      case $func_normal_abspath_tcomponent in
1037a3129944Smrg        "")
1038a3129944Smrg          # Trailing empty path component, ignore it.
1039a3129944Smrg          ;;
1040a3129944Smrg        ..)
1041a3129944Smrg          # Parent dir; strip last assembled component from result.
1042a3129944Smrg          func_dirname "$func_normal_abspath_result"
1043a3129944Smrg          func_normal_abspath_result=$func_dirname_result
1044a3129944Smrg          ;;
1045a3129944Smrg        *)
1046a3129944Smrg          # Actual path component, append it.
1047a3129944Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048a3129944Smrg          ;;
1049a3129944Smrg      esac
1050a3129944Smrg    done
1051a3129944Smrg    # Restore leading double-slash if one was found on entry.
1052a3129944Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053a3129944Smrg}
1054a3129944Smrg
1055a3129944Smrg
1056a3129944Smrg# func_notquiet ARG...
1057a3129944Smrg# --------------------
1058a3129944Smrg# Echo program name prefixed message only when not in quiet mode.
1059a3129944Smrgfunc_notquiet ()
1060a3129944Smrg{
1061a3129944Smrg    $debug_cmd
1062a3129944Smrg
1063a3129944Smrg    $opt_quiet || func_echo ${1+"$@"}
1064a3129944Smrg
1065a3129944Smrg    # A bug in bash halts the script if the last line of a function
1066a3129944Smrg    # fails when set -e is in force, so we need another command to
1067a3129944Smrg    # work around that:
1068a3129944Smrg    :
1069a3129944Smrg}
1070a3129944Smrg
1071a3129944Smrg
1072a3129944Smrg# func_relative_path SRCDIR DSTDIR
1073a3129944Smrg# --------------------------------
1074a3129944Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075a3129944Smrgfunc_relative_path ()
1076a3129944Smrg{
1077a3129944Smrg    $debug_cmd
1078a3129944Smrg
1079a3129944Smrg    func_relative_path_result=
1080a3129944Smrg    func_normal_abspath "$1"
1081a3129944Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082a3129944Smrg    func_normal_abspath "$2"
1083a3129944Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084a3129944Smrg
1085a3129944Smrg    # Ascend the tree starting from libdir
1086a3129944Smrg    while :; do
1087a3129944Smrg      # check if we have found a prefix of bindir
1088a3129944Smrg      case $func_relative_path_tbindir in
1089a3129944Smrg        $func_relative_path_tlibdir)
1090a3129944Smrg          # found an exact match
1091a3129944Smrg          func_relative_path_tcancelled=
1092a3129944Smrg          break
1093a3129944Smrg          ;;
1094a3129944Smrg        $func_relative_path_tlibdir*)
1095a3129944Smrg          # found a matching prefix
1096a3129944Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097a3129944Smrg          func_relative_path_tcancelled=$func_stripname_result
1098a3129944Smrg          if test -z "$func_relative_path_result"; then
1099a3129944Smrg            func_relative_path_result=.
1100a3129944Smrg          fi
1101a3129944Smrg          break
1102a3129944Smrg          ;;
1103a3129944Smrg        *)
1104a3129944Smrg          func_dirname $func_relative_path_tlibdir
1105a3129944Smrg          func_relative_path_tlibdir=$func_dirname_result
1106a3129944Smrg          if test -z "$func_relative_path_tlibdir"; then
1107a3129944Smrg            # Have to descend all the way to the root!
1108a3129944Smrg            func_relative_path_result=../$func_relative_path_result
1109a3129944Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110a3129944Smrg            break
1111a3129944Smrg          fi
1112a3129944Smrg          func_relative_path_result=../$func_relative_path_result
1113a3129944Smrg          ;;
1114a3129944Smrg      esac
1115a3129944Smrg    done
1116a3129944Smrg
1117a3129944Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118a3129944Smrg    func_stripname '' '/' "$func_relative_path_result"
1119a3129944Smrg    func_relative_path_result=$func_stripname_result
1120a3129944Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121a3129944Smrg    if test -n "$func_stripname_result"; then
1122a3129944Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123a3129944Smrg    fi
1124a3129944Smrg
1125a3129944Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126a3129944Smrg    if test -n "$func_relative_path_result"; then
1127a3129944Smrg      func_stripname './' '' "$func_relative_path_result"
1128a3129944Smrg      func_relative_path_result=$func_stripname_result
1129266e564dSmrg    fi
1130266e564dSmrg
1131a3129944Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132a3129944Smrg
1133a3129944Smrg    :
1134a3129944Smrg}
1135a3129944Smrg
1136a3129944Smrg
11371009a292Smrg# func_quote_portable EVAL ARG
11381009a292Smrg# ----------------------------
11391009a292Smrg# Internal function to portably implement func_quote_arg.  Note that we still
11401009a292Smrg# keep attention to performance here so we as much as possible try to avoid
11411009a292Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11421009a292Smrgfunc_quote_portable ()
1143a3129944Smrg{
1144a3129944Smrg    $debug_cmd
1145a3129944Smrg
11461009a292Smrg    $require_check_ifs_backslash
11471009a292Smrg
11481009a292Smrg    func_quote_portable_result=$2
11491009a292Smrg
11501009a292Smrg    # one-time-loop (easy break)
11511009a292Smrg    while true
11521009a292Smrg    do
11531009a292Smrg      if $1; then
11541009a292Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11551009a292Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11561009a292Smrg        break
1157a3129944Smrg      fi
1158a3129944Smrg
11591009a292Smrg      # Quote for eval.
11601009a292Smrg      case $func_quote_portable_result in
11611009a292Smrg        *[\\\`\"\$]*)
11621009a292Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11631009a292Smrg          # contains the shell wildcard characters.
11641009a292Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11651009a292Smrg            :*|*[\[\*\?]*)
11661009a292Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11671009a292Smrg                  | $SED "$sed_quote_subst"`
11681009a292Smrg              break
11691009a292Smrg              ;;
11701009a292Smrg          esac
11711009a292Smrg
11721009a292Smrg          func_quote_portable_old_IFS=$IFS
11731009a292Smrg          for _G_char in '\' '`' '"' '$'
11741009a292Smrg          do
11751009a292Smrg            # STATE($1) PREV($2) SEPARATOR($3)
11761009a292Smrg            set start "" ""
11771009a292Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11781009a292Smrg            IFS=$_G_char
11791009a292Smrg            for _G_part in $func_quote_portable_result
11801009a292Smrg            do
11811009a292Smrg              case $1 in
11821009a292Smrg              quote)
11831009a292Smrg                func_append func_quote_portable_result "$3$2"
11841009a292Smrg                set quote "$_G_part" "\\$_G_char"
11851009a292Smrg                ;;
11861009a292Smrg              start)
11871009a292Smrg                set first "" ""
11881009a292Smrg                func_quote_portable_result=
11891009a292Smrg                ;;
11901009a292Smrg              first)
11911009a292Smrg                set quote "$_G_part" ""
11921009a292Smrg                ;;
11931009a292Smrg              esac
11941009a292Smrg            done
11951009a292Smrg          done
11961009a292Smrg          IFS=$func_quote_portable_old_IFS
1197a3129944Smrg          ;;
11981009a292Smrg        *) ;;
1199a3129944Smrg      esac
12001009a292Smrg      break
1201a3129944Smrg    done
12021009a292Smrg
12031009a292Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12041009a292Smrg    case $func_quote_portable_result in
12051009a292Smrg      # double-quote args containing shell metacharacters to delay
12061009a292Smrg      # word splitting, command substitution and variable expansion
12071009a292Smrg      # for a subsequent eval.
12081009a292Smrg      # many bourne shells cannot handle close brackets correctly
12091009a292Smrg      # in scan sets, so we specify it separately.
12101009a292Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12111009a292Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
12121009a292Smrg        ;;
12131009a292Smrg    esac
1214a3129944Smrg}
1215a3129944Smrg
1216a3129944Smrg
12171009a292Smrg# func_quotefast_eval ARG
12181009a292Smrg# -----------------------
12191009a292Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12201009a292Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12211009a292Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12221009a292Smrg  printf -v _GL_test_printf_tilde %q '~'
12231009a292Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
12241009a292Smrg    func_quotefast_eval ()
12251009a292Smrg    {
12261009a292Smrg      printf -v func_quotefast_eval_result %q "$1"
12271009a292Smrg    }
12281009a292Smrg  else
12291009a292Smrg    # Broken older Bash implementations.  Make those faster too if possible.
12301009a292Smrg    func_quotefast_eval ()
12311009a292Smrg    {
12321009a292Smrg      case $1 in
12331009a292Smrg        '~'*)
12341009a292Smrg          func_quote_portable false "$1"
12351009a292Smrg          func_quotefast_eval_result=$func_quote_portable_result
12361009a292Smrg          ;;
12371009a292Smrg        *)
12381009a292Smrg          printf -v func_quotefast_eval_result %q "$1"
12391009a292Smrg          ;;
12401009a292Smrg      esac
12411009a292Smrg    }
12421009a292Smrg  fi
12431009a292Smrgelse
12441009a292Smrg  func_quotefast_eval ()
12451009a292Smrg  {
12461009a292Smrg    func_quote_portable false "$1"
12471009a292Smrg    func_quotefast_eval_result=$func_quote_portable_result
12481009a292Smrg  }
12491009a292Smrgfi
1250a3129944Smrg
12511009a292Smrg
12521009a292Smrg# func_quote_arg MODEs ARG
12531009a292Smrg# ------------------------
12541009a292Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12551009a292Smrg# specifiers listed below separated by ',' character.  This function returns two
12561009a292Smrg# values:
12571009a292Smrg#   i) func_quote_arg_result
12581009a292Smrg#      double-quoted (when needed), suitable for a subsequent eval
12591009a292Smrg#  ii) func_quote_arg_unquoted_result
12601009a292Smrg#      has all characters that are still active within double
12611009a292Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12621009a292Smrg#
12631009a292Smrg# Available modes:
12641009a292Smrg# ----------------
12651009a292Smrg# 'eval' (default)
12661009a292Smrg#       - escape shell special characters
12671009a292Smrg# 'expand'
12681009a292Smrg#       - the same as 'eval';  but do not quote variable references
12691009a292Smrg# 'pretty'
12701009a292Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12711009a292Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12721009a292Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
12731009a292Smrg# 'unquoted'
12741009a292Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12751009a292Smrg#         wrapping double-quotes.
12761009a292Smrg#
12771009a292Smrg# Examples for 'func_quote_arg pretty,unquoted string':
12781009a292Smrg#
12791009a292Smrg#   string      | *_result              | *_unquoted_result
12801009a292Smrg#   ------------+-----------------------+-------------------
12811009a292Smrg#   "           | \"                    | \"
12821009a292Smrg#   a b         | "a b"                 | a b
12831009a292Smrg#   "a b"       | "\"a b\""             | \"a b\"
12841009a292Smrg#   *           | "*"                   | *
12851009a292Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12861009a292Smrg#
12871009a292Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12881009a292Smrg#
12891009a292Smrg#   string        |   *_result          |  *_unquoted_result
12901009a292Smrg#   --------------+---------------------+--------------------
12911009a292Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12921009a292Smrgfunc_quote_arg ()
12931009a292Smrg{
12941009a292Smrg    _G_quote_expand=false
12951009a292Smrg    case ,$1, in
12961009a292Smrg      *,expand,*)
12971009a292Smrg        _G_quote_expand=:
12981009a292Smrg        ;;
1299a3129944Smrg    esac
1300a3129944Smrg
13011009a292Smrg    case ,$1, in
13021009a292Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
13031009a292Smrg        func_quote_portable $_G_quote_expand "$2"
13041009a292Smrg        func_quote_arg_result=$func_quote_portable_result
13051009a292Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13061009a292Smrg        ;;
13071009a292Smrg      *)
13081009a292Smrg        # Faster quote-for-eval for some shells.
13091009a292Smrg        func_quotefast_eval "$2"
13101009a292Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311a3129944Smrg        ;;
1312a3129944Smrg    esac
13131009a292Smrg}
1314a3129944Smrg
13151009a292Smrg
13161009a292Smrg# func_quote MODEs ARGs...
13171009a292Smrg# ------------------------
13181009a292Smrg# Quote all ARGs to be evaled later and join them into single command.  See
13191009a292Smrg# func_quote_arg's description for more info.
13201009a292Smrgfunc_quote ()
13211009a292Smrg{
13221009a292Smrg    $debug_cmd
13231009a292Smrg    _G_func_quote_mode=$1 ; shift
13241009a292Smrg    func_quote_result=
13251009a292Smrg    while test 0 -lt $#; do
13261009a292Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
13271009a292Smrg      if test -n "$func_quote_result"; then
13281009a292Smrg        func_append func_quote_result " $func_quote_arg_result"
13291009a292Smrg      else
13301009a292Smrg        func_append func_quote_result "$func_quote_arg_result"
13311009a292Smrg      fi
13321009a292Smrg      shift
13331009a292Smrg    done
1334a3129944Smrg}
1335a3129944Smrg
1336a3129944Smrg
1337a3129944Smrg# func_stripname PREFIX SUFFIX NAME
1338a3129944Smrg# ---------------------------------
1339a3129944Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340a3129944Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341a3129944Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342a3129944Smrg# dot (in which case that matches only a dot).
1343a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344a3129944Smrg  eval 'func_stripname ()
1345a3129944Smrg  {
1346a3129944Smrg    $debug_cmd
1347a3129944Smrg
1348a3129944Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349a3129944Smrg    # positional parameters, so assign one to ordinary variable first.
1350a3129944Smrg    func_stripname_result=$3
1351a3129944Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352a3129944Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353a3129944Smrg  }'
1354a3129944Smrgelse
1355a3129944Smrg  func_stripname ()
1356a3129944Smrg  {
1357a3129944Smrg    $debug_cmd
1358a3129944Smrg
1359a3129944Smrg    case $2 in
1360a3129944Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361a3129944Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362a3129944Smrg    esac
1363a3129944Smrg  }
1364a3129944Smrgfi
1365a3129944Smrg
1366a3129944Smrg
1367a3129944Smrg# func_show_eval CMD [FAIL_EXP]
1368a3129944Smrg# -----------------------------
1369a3129944Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370a3129944Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371a3129944Smrg# is given, then evaluate it.
1372a3129944Smrgfunc_show_eval ()
1373a3129944Smrg{
1374a3129944Smrg    $debug_cmd
1375a3129944Smrg
1376a3129944Smrg    _G_cmd=$1
1377a3129944Smrg    _G_fail_exp=${2-':'}
1378a3129944Smrg
13791009a292Smrg    func_quote_arg pretty,expand "$_G_cmd"
13801009a292Smrg    eval "func_notquiet $func_quote_arg_result"
1381a3129944Smrg
1382a3129944Smrg    $opt_dry_run || {
1383a3129944Smrg      eval "$_G_cmd"
1384a3129944Smrg      _G_status=$?
1385a3129944Smrg      if test 0 -ne "$_G_status"; then
1386a3129944Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387a3129944Smrg      fi
1388a3129944Smrg    }
1389a3129944Smrg}
1390a3129944Smrg
1391a3129944Smrg
1392a3129944Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393a3129944Smrg# ------------------------------------
1394a3129944Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395a3129944Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396a3129944Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397a3129944Smrgfunc_show_eval_locale ()
1398a3129944Smrg{
1399a3129944Smrg    $debug_cmd
1400a3129944Smrg
1401a3129944Smrg    _G_cmd=$1
1402a3129944Smrg    _G_fail_exp=${2-':'}
1403a3129944Smrg
1404a3129944Smrg    $opt_quiet || {
14051009a292Smrg      func_quote_arg expand,pretty "$_G_cmd"
14061009a292Smrg      eval "func_echo $func_quote_arg_result"
1407a3129944Smrg    }
1408a3129944Smrg
1409a3129944Smrg    $opt_dry_run || {
1410a3129944Smrg      eval "$_G_user_locale
1411a3129944Smrg	    $_G_cmd"
1412a3129944Smrg      _G_status=$?
1413a3129944Smrg      eval "$_G_safe_locale"
1414a3129944Smrg      if test 0 -ne "$_G_status"; then
1415a3129944Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416a3129944Smrg      fi
1417a3129944Smrg    }
1418a3129944Smrg}
1419a3129944Smrg
1420a3129944Smrg
1421a3129944Smrg# func_tr_sh
1422a3129944Smrg# ----------
1423a3129944Smrg# Turn $1 into a string suitable for a shell variable name.
1424a3129944Smrg# Result is stored in $func_tr_sh_result.  All characters
1425a3129944Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426a3129944Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427a3129944Smrgfunc_tr_sh ()
1428a3129944Smrg{
1429a3129944Smrg    $debug_cmd
1430a3129944Smrg
1431a3129944Smrg    case $1 in
1432a3129944Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433a3129944Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434a3129944Smrg      ;;
1435a3129944Smrg    * )
1436a3129944Smrg      func_tr_sh_result=$1
1437a3129944Smrg      ;;
1438a3129944Smrg    esac
1439a3129944Smrg}
1440a3129944Smrg
1441a3129944Smrg
1442a3129944Smrg# func_verbose ARG...
1443a3129944Smrg# -------------------
1444a3129944Smrg# Echo program name prefixed message in verbose mode only.
1445a3129944Smrgfunc_verbose ()
1446a3129944Smrg{
1447a3129944Smrg    $debug_cmd
1448a3129944Smrg
1449a3129944Smrg    $opt_verbose && func_echo "$*"
1450a3129944Smrg
1451a3129944Smrg    :
1452a3129944Smrg}
1453a3129944Smrg
1454a3129944Smrg
1455a3129944Smrg# func_warn_and_continue ARG...
1456a3129944Smrg# -----------------------------
1457a3129944Smrg# Echo program name prefixed warning message to standard error.
1458a3129944Smrgfunc_warn_and_continue ()
1459a3129944Smrg{
1460a3129944Smrg    $debug_cmd
1461a3129944Smrg
1462a3129944Smrg    $require_term_colors
1463a3129944Smrg
1464a3129944Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465a3129944Smrg}
1466a3129944Smrg
1467a3129944Smrg
1468a3129944Smrg# func_warning CATEGORY ARG...
1469a3129944Smrg# ----------------------------
1470a3129944Smrg# Echo program name prefixed warning message to standard error. Warning
1471a3129944Smrg# messages can be filtered according to CATEGORY, where this function
1472a3129944Smrg# elides messages where CATEGORY is not listed in the global variable
1473a3129944Smrg# 'opt_warning_types'.
1474a3129944Smrgfunc_warning ()
1475a3129944Smrg{
1476a3129944Smrg    $debug_cmd
1477a3129944Smrg
1478a3129944Smrg    # CATEGORY must be in the warning_categories list!
1479a3129944Smrg    case " $warning_categories " in
1480a3129944Smrg      *" $1 "*) ;;
1481a3129944Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482a3129944Smrg    esac
1483a3129944Smrg
1484a3129944Smrg    _G_category=$1
1485a3129944Smrg    shift
1486a3129944Smrg
1487a3129944Smrg    case " $opt_warning_types " in
1488a3129944Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489a3129944Smrg    esac
1490a3129944Smrg}
1491a3129944Smrg
1492a3129944Smrg
1493a3129944Smrg# func_sort_ver VER1 VER2
1494a3129944Smrg# -----------------------
1495a3129944Smrg# 'sort -V' is not generally available.
1496a3129944Smrg# Note this deviates from the version comparison in automake
1497a3129944Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498a3129944Smrg# but this should suffice as we won't be specifying old
1499a3129944Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500a3129944Smrg# If we did want full compatibility then we should probably
1501a3129944Smrg# use m4_version_compare from autoconf.
1502a3129944Smrgfunc_sort_ver ()
1503a3129944Smrg{
1504a3129944Smrg    $debug_cmd
1505a3129944Smrg
1506a3129944Smrg    printf '%s\n%s\n' "$1" "$2" \
1507a3129944Smrg      | 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
1508a3129944Smrg}
1509a3129944Smrg
1510a3129944Smrg# func_lt_ver PREV CURR
1511a3129944Smrg# ---------------------
1512a3129944Smrg# Return true if PREV and CURR are in the correct order according to
1513a3129944Smrg# func_sort_ver, otherwise false.  Use it like this:
1514a3129944Smrg#
1515a3129944Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516a3129944Smrgfunc_lt_ver ()
1517a3129944Smrg{
1518a3129944Smrg    $debug_cmd
1519a3129944Smrg
1520a3129944Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521a3129944Smrg}
1522a3129944Smrg
1523a3129944Smrg
1524a3129944Smrg# Local variables:
1525a3129944Smrg# mode: shell-script
1526a3129944Smrg# sh-indentation: 2
1527a3129944Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528a3129944Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529a3129944Smrg# time-stamp-time-zone: "UTC"
1530a3129944Smrg# End:
1531a3129944Smrg#! /bin/sh
1532a3129944Smrg
1533a3129944Smrg# A portable, pluggable option parser for Bourne shell.
1534a3129944Smrg# Written by Gary V. Vaughan, 2010
1535a3129944Smrg
15361009a292Smrg# This is free software.  There is NO warranty; not even for
15371009a292Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15381009a292Smrg#
15393bf3b463Smrg# Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors
15401009a292Smrg#
15411009a292Smrg# This file is dual licensed under the terms of the MIT license
15423bf3b463Smrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
15433bf3b463Smrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15441009a292Smrg# these licenses when using or redistributing this software or any of
15451009a292Smrg# the files within it.  See the URLs above, or the file `LICENSE`
15461009a292Smrg# included in the Bootstrap distribution for the full license texts.
1547a3129944Smrg
15481009a292Smrg# Please report bugs or propose patches to:
15491009a292Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550a3129944Smrg
15511009a292Smrg# Set a version string for this script.
15521009a292Smrgscriptversion=2019-02-19.15; # UTC
1553a3129944Smrg
1554a3129944Smrg
1555a3129944Smrg## ------ ##
1556a3129944Smrg## Usage. ##
1557a3129944Smrg## ------ ##
1558a3129944Smrg
1559a3129944Smrg# This file is a library for parsing options in your shell scripts along
1560a3129944Smrg# with assorted other useful supporting features that you can make use
1561a3129944Smrg# of too.
1562a3129944Smrg#
1563a3129944Smrg# For the simplest scripts you might need only:
1564a3129944Smrg#
1565a3129944Smrg#   #!/bin/sh
1566a3129944Smrg#   . relative/path/to/funclib.sh
1567a3129944Smrg#   . relative/path/to/options-parser
1568a3129944Smrg#   scriptversion=1.0
1569a3129944Smrg#   func_options ${1+"$@"}
1570a3129944Smrg#   eval set dummy "$func_options_result"; shift
1571a3129944Smrg#   ...rest of your script...
1572a3129944Smrg#
1573a3129944Smrg# In order for the '--version' option to work, you will need to have a
1574a3129944Smrg# suitably formatted comment like the one at the top of this file
15751009a292Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576a3129944Smrg#
1577a3129944Smrg# For '-h' and '--help' to work, you will also need a one line
1578a3129944Smrg# description of your script's purpose in a comment directly above the
1579a3129944Smrg# '# Written by ' line, like the one at the top of this file.
1580a3129944Smrg#
1581a3129944Smrg# The default options also support '--debug', which will turn on shell
1582a3129944Smrg# execution tracing (see the comment above debug_cmd below for another
1583a3129944Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584a3129944Smrg# to display verbose messages only when your user has specified
1585a3129944Smrg# '--verbose'.
1586a3129944Smrg#
15871009a292Smrg# After sourcing this file, you can plug in processing for additional
1588a3129944Smrg# options by amending the variables from the 'Configuration' section
1589a3129944Smrg# below, and following the instructions in the 'Option parsing'
1590a3129944Smrg# section further down.
1591a3129944Smrg
1592a3129944Smrg## -------------- ##
1593a3129944Smrg## Configuration. ##
1594a3129944Smrg## -------------- ##
1595a3129944Smrg
1596a3129944Smrg# You should override these variables in your script after sourcing this
1597a3129944Smrg# file so that they reflect the customisations you have added to the
1598a3129944Smrg# option parser.
1599a3129944Smrg
1600a3129944Smrg# The usage line for option parsing errors and the start of '-h' and
1601a3129944Smrg# '--help' output messages. You can embed shell variables for delayed
1602a3129944Smrg# expansion at the time the message is displayed, but you will need to
1603a3129944Smrg# quote other shell meta-characters carefully to prevent them being
1604a3129944Smrg# expanded when the contents are evaled.
1605a3129944Smrgusage='$progpath [OPTION]...'
1606a3129944Smrg
1607a3129944Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608a3129944Smrg# override it after sourcing this library to reflect the full set of
1609a3129944Smrg# options your script accepts.
1610a3129944Smrgusage_message="\
1611a3129944Smrg       --debug        enable verbose shell tracing
1612a3129944Smrg   -W, --warnings=CATEGORY
1613a3129944Smrg                      report the warnings falling in CATEGORY [all]
1614a3129944Smrg   -v, --verbose      verbosely report processing
1615a3129944Smrg       --version      print version information and exit
1616a3129944Smrg   -h, --help         print short or long help message and exit
1617a3129944Smrg"
1618a3129944Smrg
1619a3129944Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620a3129944Smrglong_help_message="
1621a3129944SmrgWarning categories include:
1622a3129944Smrg       'all'          show all warnings
1623a3129944Smrg       'none'         turn off all the warnings
1624a3129944Smrg       'error'        warnings are treated as fatal errors"
1625a3129944Smrg
1626a3129944Smrg# Help message printed before fatal option parsing errors.
1627a3129944Smrgfatal_help="Try '\$progname --help' for more information."
1628a3129944Smrg
1629a3129944Smrg
1630a3129944Smrg
1631a3129944Smrg## ------------------------- ##
1632a3129944Smrg## Hook function management. ##
1633a3129944Smrg## ------------------------- ##
1634a3129944Smrg
1635a3129944Smrg# This section contains functions for adding, removing, and running hooks
16361009a292Smrg# in the main code.  A hook is just a list of function names that can be
16371009a292Smrg# run in order later on.
1638a3129944Smrg
1639a3129944Smrg# func_hookable FUNC_NAME
1640a3129944Smrg# -----------------------
1641a3129944Smrg# Declare that FUNC_NAME will run hooks added with
1642a3129944Smrg# 'func_add_hook FUNC_NAME ...'.
1643a3129944Smrgfunc_hookable ()
1644a3129944Smrg{
1645a3129944Smrg    $debug_cmd
1646a3129944Smrg
1647a3129944Smrg    func_append hookable_fns " $1"
1648a3129944Smrg}
1649a3129944Smrg
1650a3129944Smrg
1651a3129944Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652a3129944Smrg# ---------------------------------
1653a3129944Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654a3129944Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655a3129944Smrgfunc_add_hook ()
1656a3129944Smrg{
1657a3129944Smrg    $debug_cmd
1658a3129944Smrg
1659a3129944Smrg    case " $hookable_fns " in
1660a3129944Smrg      *" $1 "*) ;;
1661a3129944Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662a3129944Smrg    esac
1663a3129944Smrg
1664a3129944Smrg    eval func_append ${1}_hooks '" $2"'
1665a3129944Smrg}
1666a3129944Smrg
1667a3129944Smrg
1668a3129944Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669a3129944Smrg# ------------------------------------
16701009a292Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
16711009a292Smrg# FUNC_NAME.
1672a3129944Smrgfunc_remove_hook ()
1673a3129944Smrg{
1674a3129944Smrg    $debug_cmd
1675a3129944Smrg
1676a3129944Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677a3129944Smrg}
1678a3129944Smrg
1679a3129944Smrg
16801009a292Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16811009a292Smrg# ---------------------------------------------
16821009a292Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16831009a292Smrg# *_result variable of FUNC_NAME_B.
16841009a292Smrgfunc_propagate_result ()
16851009a292Smrg{
16861009a292Smrg    $debug_cmd
16871009a292Smrg
16881009a292Smrg    func_propagate_result_result=:
16891009a292Smrg    if eval "test \"\${${1}_result+set}\" = set"
16901009a292Smrg    then
16911009a292Smrg      eval "${2}_result=\$${1}_result"
16921009a292Smrg    else
16931009a292Smrg      func_propagate_result_result=false
16941009a292Smrg    fi
16951009a292Smrg}
16961009a292Smrg
16971009a292Smrg
1698a3129944Smrg# func_run_hooks FUNC_NAME [ARG]...
1699a3129944Smrg# ---------------------------------
1700a3129944Smrg# Run all hook functions registered to FUNC_NAME.
17011009a292Smrg# It's assumed that the list of hook functions contains nothing more
1702a3129944Smrg# than a whitespace-delimited list of legal shell function names, and
1703a3129944Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704a3129944Smrg# whitespace.
1705a3129944Smrgfunc_run_hooks ()
1706a3129944Smrg{
1707a3129944Smrg    $debug_cmd
1708a3129944Smrg
1709a3129944Smrg    case " $hookable_fns " in
1710a3129944Smrg      *" $1 "*) ;;
17111009a292Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712a3129944Smrg    esac
1713a3129944Smrg
1714a3129944Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715a3129944Smrg
1716a3129944Smrg    for _G_hook in $_G_hook_fns; do
17171009a292Smrg      func_unset "${_G_hook}_result"
17181009a292Smrg      eval $_G_hook '${1+"$@"}'
17191009a292Smrg      func_propagate_result $_G_hook func_run_hooks
17201009a292Smrg      if $func_propagate_result_result; then
17211009a292Smrg        eval set dummy "$func_run_hooks_result"; shift
17221009a292Smrg      fi
1723a3129944Smrg    done
1724a3129944Smrg}
1725a3129944Smrg
1726a3129944Smrg
1727a3129944Smrg
1728a3129944Smrg## --------------- ##
1729a3129944Smrg## Option parsing. ##
1730a3129944Smrg## --------------- ##
1731a3129944Smrg
1732a3129944Smrg# In order to add your own option parsing hooks, you must accept the
17331009a292Smrg# full positional parameter list from your hook function.  You may remove
17341009a292Smrg# or edit any options that you action, and then pass back the remaining
17351009a292Smrg# unprocessed options in '<hooked_function_name>_result', escaped
17361009a292Smrg# suitably for 'eval'.
17371009a292Smrg#
17381009a292Smrg# The '<hooked_function_name>_result' variable is automatically unset
17391009a292Smrg# before your hook gets called; for best performance, only set the
17401009a292Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17411009a292Smrg# function unnecessarily because it can be an expensive operation on some
17421009a292Smrg# machines).
17431009a292Smrg#
17441009a292Smrg# Like this:
1745a3129944Smrg#
1746a3129944Smrg#    my_options_prep ()
1747a3129944Smrg#    {
1748a3129944Smrg#        $debug_cmd
1749a3129944Smrg#
1750a3129944Smrg#        # Extend the existing usage message.
1751a3129944Smrg#        usage_message=$usage_message'
1752a3129944Smrg#      -s, --silent       don'\''t print informational messages
1753a3129944Smrg#    '
17541009a292Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
17551009a292Smrg#        # my_options_prep_result variable intact.
1756a3129944Smrg#    }
1757a3129944Smrg#    func_add_hook func_options_prep my_options_prep
1758a3129944Smrg#
1759a3129944Smrg#
1760a3129944Smrg#    my_silent_option ()
1761a3129944Smrg#    {
1762a3129944Smrg#        $debug_cmd
1763a3129944Smrg#
17641009a292Smrg#        args_changed=false
17651009a292Smrg#
17661009a292Smrg#        # Note that, for efficiency, we parse as many options as we can
1767a3129944Smrg#        # recognise in a loop before passing the remainder back to the
1768a3129944Smrg#        # caller on the first unrecognised argument we encounter.
1769a3129944Smrg#        while test $# -gt 0; do
1770a3129944Smrg#          opt=$1; shift
1771a3129944Smrg#          case $opt in
17721009a292Smrg#            --silent|-s) opt_silent=:
17731009a292Smrg#                         args_changed=:
17741009a292Smrg#                         ;;
1775a3129944Smrg#            # Separate non-argument short options:
1776a3129944Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777a3129944Smrg#                         set dummy "$func_split_short_opt_name" \
1778a3129944Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779a3129944Smrg#                         shift
17801009a292Smrg#                         args_changed=:
1781a3129944Smrg#                         ;;
17821009a292Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17831009a292Smrg#                         # is added back to "$@" in case we need it later,
17841009a292Smrg#                         # if $args_changed was set to 'true'.
17851009a292Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786a3129944Smrg#          esac
1787a3129944Smrg#        done
1788a3129944Smrg#
17891009a292Smrg#        # Only call 'func_quote' here if we processed at least one argument.
17901009a292Smrg#        if $args_changed; then
17911009a292Smrg#          func_quote eval ${1+"$@"}
17921009a292Smrg#          my_silent_option_result=$func_quote_result
17931009a292Smrg#        fi
1794a3129944Smrg#    }
1795a3129944Smrg#    func_add_hook func_parse_options my_silent_option
1796a3129944Smrg#
1797a3129944Smrg#
1798a3129944Smrg#    my_option_validation ()
1799a3129944Smrg#    {
1800a3129944Smrg#        $debug_cmd
1801a3129944Smrg#
1802a3129944Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803a3129944Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804a3129944Smrg#    }
1805a3129944Smrg#    func_add_hook func_validate_options my_option_validation
1806a3129944Smrg#
18071009a292Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808a3129944Smrg# options you parse.  It's preferable to append if you can, so that
1809a3129944Smrg# multiple option parsing hooks can be added safely.
1810a3129944Smrg
1811a3129944Smrg
18121009a292Smrg# func_options_finish [ARG]...
18131009a292Smrg# ----------------------------
18141009a292Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18151009a292Smrgfunc_options_finish ()
18161009a292Smrg{
18171009a292Smrg    $debug_cmd
18181009a292Smrg
18191009a292Smrg    func_run_hooks func_options ${1+"$@"}
18201009a292Smrg    func_propagate_result func_run_hooks func_options_finish
18211009a292Smrg}
18221009a292Smrg
18231009a292Smrg
1824a3129944Smrg# func_options [ARG]...
1825a3129944Smrg# ---------------------
1826a3129944Smrg# All the functions called inside func_options are hookable. See the
1827a3129944Smrg# individual implementations for details.
1828a3129944Smrgfunc_hookable func_options
1829a3129944Smrgfunc_options ()
1830a3129944Smrg{
1831a3129944Smrg    $debug_cmd
1832a3129944Smrg
18331009a292Smrg    _G_options_quoted=false
1834a3129944Smrg
18351009a292Smrg    for my_func in options_prep parse_options validate_options options_finish
18361009a292Smrg    do
18371009a292Smrg      func_unset func_${my_func}_result
18381009a292Smrg      func_unset func_run_hooks_result
18391009a292Smrg      eval func_$my_func '${1+"$@"}'
18401009a292Smrg      func_propagate_result func_$my_func func_options
18411009a292Smrg      if $func_propagate_result_result; then
18421009a292Smrg        eval set dummy "$func_options_result"; shift
18431009a292Smrg        _G_options_quoted=:
18441009a292Smrg      fi
18451009a292Smrg    done
1846a3129944Smrg
18471009a292Smrg    $_G_options_quoted || {
18481009a292Smrg      # As we (func_options) are top-level options-parser function and
18491009a292Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18501009a292Smrg      # caller.
18511009a292Smrg      func_quote eval ${1+"$@"}
18521009a292Smrg      func_options_result=$func_quote_result
18531009a292Smrg    }
1854266e564dSmrg}
1855266e564dSmrg
1856266e564dSmrg
1857a3129944Smrg# func_options_prep [ARG]...
1858a3129944Smrg# --------------------------
1859a3129944Smrg# All initialisations required before starting the option parse loop.
1860a3129944Smrg# Note that when calling hook functions, we pass through the list of
1861a3129944Smrg# positional parameters.  If a hook function modifies that list, and
18621009a292Smrg# needs to propagate that back to rest of this script, then the complete
18631009a292Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864a3129944Smrgfunc_hookable func_options_prep
1865a3129944Smrgfunc_options_prep ()
1866266e564dSmrg{
1867a3129944Smrg    $debug_cmd
1868698f425bSmrg
1869a3129944Smrg    # Option defaults:
1870a3129944Smrg    opt_verbose=false
1871a3129944Smrg    opt_warning_types=
1872a3129944Smrg
1873a3129944Smrg    func_run_hooks func_options_prep ${1+"$@"}
18741009a292Smrg    func_propagate_result func_run_hooks func_options_prep
1875266e564dSmrg}
1876266e564dSmrg
1877266e564dSmrg
1878a3129944Smrg# func_parse_options [ARG]...
1879a3129944Smrg# ---------------------------
1880a3129944Smrg# The main option parsing loop.
1881a3129944Smrgfunc_hookable func_parse_options
1882a3129944Smrgfunc_parse_options ()
1883266e564dSmrg{
1884a3129944Smrg    $debug_cmd
1885698f425bSmrg
18861009a292Smrg    _G_parse_options_requote=false
1887a3129944Smrg    # this just eases exit handling
1888a3129944Smrg    while test $# -gt 0; do
1889a3129944Smrg      # Defer to hook functions for initial option parsing, so they
1890a3129944Smrg      # get priority in the event of reusing an option name.
1891a3129944Smrg      func_run_hooks func_parse_options ${1+"$@"}
18921009a292Smrg      func_propagate_result func_run_hooks func_parse_options
18931009a292Smrg      if $func_propagate_result_result; then
18941009a292Smrg        eval set dummy "$func_parse_options_result"; shift
18951009a292Smrg        # Even though we may have changed "$@", we passed the "$@" array
18961009a292Smrg        # down into the hook and it quoted it for us (because we are in
18971009a292Smrg        # this if-branch).  No need to quote it again.
18981009a292Smrg        _G_parse_options_requote=false
18991009a292Smrg      fi
1900266e564dSmrg
1901a3129944Smrg      # Break out of the loop if we already parsed every option.
1902a3129944Smrg      test $# -gt 0 || break
1903266e564dSmrg
19041009a292Smrg      # We expect that one of the options parsed in this function matches
19051009a292Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19061009a292Smrg      _G_match_parse_options=:
1907a3129944Smrg      _G_opt=$1
1908a3129944Smrg      shift
1909a3129944Smrg      case $_G_opt in
1910a3129944Smrg        --debug|-x)   debug_cmd='set -x'
19111009a292Smrg                      func_echo "enabling shell trace mode" >&2
1912a3129944Smrg                      $debug_cmd
1913a3129944Smrg                      ;;
1914a3129944Smrg
1915a3129944Smrg        --no-warnings|--no-warning|--no-warn)
1916a3129944Smrg                      set dummy --warnings none ${1+"$@"}
1917a3129944Smrg                      shift
1918a3129944Smrg		      ;;
1919698f425bSmrg
1920a3129944Smrg        --warnings|--warning|-W)
19211009a292Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19221009a292Smrg                        _G_parse_options_requote=:
19231009a292Smrg                        break
19241009a292Smrg                      fi
1925a3129944Smrg                      case " $warning_categories $1" in
1926a3129944Smrg                        *" $1 "*)
1927a3129944Smrg                          # trailing space prevents matching last $1 above
1928a3129944Smrg                          func_append_uniq opt_warning_types " $1"
1929a3129944Smrg                          ;;
1930a3129944Smrg                        *all)
1931a3129944Smrg                          opt_warning_types=$warning_categories
1932a3129944Smrg                          ;;
1933a3129944Smrg                        *none)
1934a3129944Smrg                          opt_warning_types=none
1935a3129944Smrg                          warning_func=:
1936a3129944Smrg                          ;;
1937a3129944Smrg                        *error)
1938a3129944Smrg                          opt_warning_types=$warning_categories
1939a3129944Smrg                          warning_func=func_fatal_error
1940a3129944Smrg                          ;;
1941a3129944Smrg                        *)
1942a3129944Smrg                          func_fatal_error \
1943a3129944Smrg                             "unsupported warning category: '$1'"
1944a3129944Smrg                          ;;
1945a3129944Smrg                      esac
1946a3129944Smrg                      shift
1947a3129944Smrg                      ;;
1948a3129944Smrg
1949a3129944Smrg        --verbose|-v) opt_verbose=: ;;
1950a3129944Smrg        --version)    func_version ;;
1951a3129944Smrg        -\?|-h)       func_usage ;;
1952a3129944Smrg        --help)       func_help ;;
1953a3129944Smrg
1954a3129944Smrg	# Separate optargs to long options (plugins may need this):
1955a3129944Smrg	--*=*)        func_split_equals "$_G_opt"
1956a3129944Smrg	              set dummy "$func_split_equals_lhs" \
1957a3129944Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958a3129944Smrg                      shift
1959a3129944Smrg                      ;;
1960a3129944Smrg
1961a3129944Smrg       # Separate optargs to short options:
1962a3129944Smrg        -W*)
1963a3129944Smrg                      func_split_short_opt "$_G_opt"
1964a3129944Smrg                      set dummy "$func_split_short_opt_name" \
1965a3129944Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966a3129944Smrg                      shift
1967a3129944Smrg                      ;;
1968a3129944Smrg
1969a3129944Smrg        # Separate non-argument short options:
1970a3129944Smrg        -\?*|-h*|-v*|-x*)
1971a3129944Smrg                      func_split_short_opt "$_G_opt"
1972a3129944Smrg                      set dummy "$func_split_short_opt_name" \
1973a3129944Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974a3129944Smrg                      shift
1975a3129944Smrg                      ;;
1976a3129944Smrg
19771009a292Smrg        --)           _G_parse_options_requote=: ; break ;;
1978a3129944Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19791009a292Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19801009a292Smrg                      _G_match_parse_options=false
19811009a292Smrg                      break
19821009a292Smrg                      ;;
1983a3129944Smrg      esac
19841009a292Smrg
19851009a292Smrg      if $_G_match_parse_options; then
19861009a292Smrg        _G_parse_options_requote=:
19871009a292Smrg      fi
1988a3129944Smrg    done
1989a3129944Smrg
19901009a292Smrg    if $_G_parse_options_requote; then
19911009a292Smrg      # save modified positional parameters for caller
19921009a292Smrg      func_quote eval ${1+"$@"}
19931009a292Smrg      func_parse_options_result=$func_quote_result
19941009a292Smrg    fi
1995266e564dSmrg}
1996266e564dSmrg
1997698f425bSmrg
1998a3129944Smrg# func_validate_options [ARG]...
1999a3129944Smrg# ------------------------------
2000a3129944Smrg# Perform any sanity checks on option settings and/or unconsumed
2001a3129944Smrg# arguments.
2002a3129944Smrgfunc_hookable func_validate_options
2003a3129944Smrgfunc_validate_options ()
2004266e564dSmrg{
2005a3129944Smrg    $debug_cmd
2006698f425bSmrg
2007a3129944Smrg    # Display all warnings if -W was not given.
2008a3129944Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009698f425bSmrg
2010a3129944Smrg    func_run_hooks func_validate_options ${1+"$@"}
20111009a292Smrg    func_propagate_result func_run_hooks func_validate_options
2012266e564dSmrg
2013a3129944Smrg    # Bail if the options were screwed!
2014a3129944Smrg    $exit_cmd $EXIT_FAILURE
20159ef0b394Smrg}
2016698f425bSmrg
2017698f425bSmrg
20189ef0b394Smrg
2019a3129944Smrg## ----------------- ##
2020a3129944Smrg## Helper functions. ##
2021a3129944Smrg## ----------------- ##
2022266e564dSmrg
2023a3129944Smrg# This section contains the helper functions used by the rest of the
2024a3129944Smrg# hookable option parser framework in ascii-betical order.
2025a3129944Smrg
2026a3129944Smrg
2027a3129944Smrg# func_fatal_help ARG...
2028a3129944Smrg# ----------------------
2029a3129944Smrg# Echo program name prefixed message to standard error, followed by
2030a3129944Smrg# a help hint, and exit.
2031a3129944Smrgfunc_fatal_help ()
2032698f425bSmrg{
2033a3129944Smrg    $debug_cmd
20349ef0b394Smrg
2035a3129944Smrg    eval \$ECHO \""Usage: $usage"\"
2036a3129944Smrg    eval \$ECHO \""$fatal_help"\"
2037a3129944Smrg    func_error ${1+"$@"}
2038a3129944Smrg    exit $EXIT_FAILURE
2039698f425bSmrg}
2040266e564dSmrg
2041a3129944Smrg
2042a3129944Smrg# func_help
2043a3129944Smrg# ---------
2044a3129944Smrg# Echo long help message to standard output and exit.
2045698f425bSmrgfunc_help ()
2046698f425bSmrg{
2047a3129944Smrg    $debug_cmd
2048a3129944Smrg
2049a3129944Smrg    func_usage_message
2050a3129944Smrg    $ECHO "$long_help_message"
2051a3129944Smrg    exit 0
2052698f425bSmrg}
2053266e564dSmrg
2054a3129944Smrg
2055a3129944Smrg# func_missing_arg ARGNAME
2056a3129944Smrg# ------------------------
2057698f425bSmrg# Echo program name prefixed message to standard error and set global
2058698f425bSmrg# exit_cmd.
2059698f425bSmrgfunc_missing_arg ()
2060698f425bSmrg{
2061a3129944Smrg    $debug_cmd
20629ef0b394Smrg
2063a3129944Smrg    func_error "Missing argument for '$1'."
2064698f425bSmrg    exit_cmd=exit
2065698f425bSmrg}
2066698f425bSmrg
2067698f425bSmrg
2068a3129944Smrg# func_split_equals STRING
2069a3129944Smrg# ------------------------
20701009a292Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20711009a292Smrg# after splitting STRING at the '=' sign.
2072a3129944Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073a3129944Smrg    && (eval 'x=a/b/c;
2074a3129944Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075a3129944Smrg    && _G_HAVE_XSI_OPS=yes
2076a3129944Smrg
2077a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078a3129944Smrgthen
2079a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080a3129944Smrg  eval 'func_split_equals ()
2081a3129944Smrg  {
2082a3129944Smrg      $debug_cmd
2083a3129944Smrg
2084a3129944Smrg      func_split_equals_lhs=${1%%=*}
2085a3129944Smrg      func_split_equals_rhs=${1#*=}
20861009a292Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
20871009a292Smrg        func_split_equals_rhs=
20881009a292Smrg      fi
2089a3129944Smrg  }'
2090a3129944Smrgelse
2091a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092a3129944Smrg  func_split_equals ()
2093a3129944Smrg  {
2094a3129944Smrg      $debug_cmd
2095a3129944Smrg
2096a3129944Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097a3129944Smrg      func_split_equals_rhs=
20981009a292Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099a3129944Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100a3129944Smrg  }
2101a3129944Smrgfi #func_split_equals
2102a3129944Smrg
2103a3129944Smrg
2104a3129944Smrg# func_split_short_opt SHORTOPT
2105a3129944Smrg# -----------------------------
21069ef0b394Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
21079ef0b394Smrg# variables after splitting SHORTOPT after the 2nd character.
2108a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109a3129944Smrgthen
2110a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111a3129944Smrg  eval 'func_split_short_opt ()
2112a3129944Smrg  {
2113a3129944Smrg      $debug_cmd
2114a3129944Smrg
2115a3129944Smrg      func_split_short_opt_arg=${1#??}
2116a3129944Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117a3129944Smrg  }'
2118a3129944Smrgelse
2119a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120a3129944Smrg  func_split_short_opt ()
2121a3129944Smrg  {
2122a3129944Smrg      $debug_cmd
2123a3129944Smrg
21241009a292Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125a3129944Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126a3129944Smrg  }
2127a3129944Smrgfi #func_split_short_opt
2128a3129944Smrg
2129a3129944Smrg
2130a3129944Smrg# func_usage
2131a3129944Smrg# ----------
2132a3129944Smrg# Echo short help message to standard output and exit.
2133a3129944Smrgfunc_usage ()
21349ef0b394Smrg{
2135a3129944Smrg    $debug_cmd
2136698f425bSmrg
2137a3129944Smrg    func_usage_message
2138a3129944Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139a3129944Smrg    exit 0
2140a3129944Smrg}
21419ef0b394Smrg
21429ef0b394Smrg
2143a3129944Smrg# func_usage_message
2144a3129944Smrg# ------------------
2145a3129944Smrg# Echo short help message to standard output.
2146a3129944Smrgfunc_usage_message ()
21479ef0b394Smrg{
2148a3129944Smrg    $debug_cmd
21499ef0b394Smrg
2150a3129944Smrg    eval \$ECHO \""Usage: $usage"\"
2151a3129944Smrg    echo
2152a3129944Smrg    $SED -n 's|^# ||
2153a3129944Smrg        /^Written by/{
2154a3129944Smrg          x;p;x
2155a3129944Smrg        }
2156a3129944Smrg	h
2157a3129944Smrg	/^Written by/q' < "$progpath"
2158a3129944Smrg    echo
2159a3129944Smrg    eval \$ECHO \""$usage_message"\"
2160a3129944Smrg}
21619ef0b394Smrg
2162698f425bSmrg
2163a3129944Smrg# func_version
2164a3129944Smrg# ------------
2165a3129944Smrg# Echo version message to standard output and exit.
21661009a292Smrg# The version message is extracted from the calling file's header
21671009a292Smrg# comments, with leading '# ' stripped:
21681009a292Smrg#   1. First display the progname and version
21691009a292Smrg#   2. Followed by the header comment line matching  /^# Written by /
21701009a292Smrg#   3. Then a blank line followed by the first following line matching
21711009a292Smrg#      /^# Copyright /
21721009a292Smrg#   4. Immediately followed by any lines between the previous matches,
21731009a292Smrg#      except lines preceding the intervening completely blank line.
21741009a292Smrg# For example, see the header comments of this file.
2175a3129944Smrgfunc_version ()
2176a3129944Smrg{
2177a3129944Smrg    $debug_cmd
2178698f425bSmrg
2179a3129944Smrg    printf '%s\n' "$progname $scriptversion"
2180a3129944Smrg    $SED -n '
21811009a292Smrg        /^# Written by /!b
21821009a292Smrg        s|^# ||; p; n
21831009a292Smrg
21841009a292Smrg        :fwd2blnk
21851009a292Smrg        /./ {
21861009a292Smrg          n
21871009a292Smrg          b fwd2blnk
2188a3129944Smrg        }
21891009a292Smrg        p; n
21901009a292Smrg
21911009a292Smrg        :holdwrnt
21921009a292Smrg        s|^# ||
21931009a292Smrg        s|^# *$||
21941009a292Smrg        /^Copyright /!{
21951009a292Smrg          /./H
21961009a292Smrg          n
21971009a292Smrg          b holdwrnt
2198a3129944Smrg        }
21991009a292Smrg
22001009a292Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22011009a292Smrg        G
22021009a292Smrg        s|\(\n\)\n*|\1|g
22031009a292Smrg        p; q' < "$progpath"
2204698f425bSmrg
2205a3129944Smrg    exit $?
2206a3129944Smrg}
2207266e564dSmrg
2208266e564dSmrg
2209a3129944Smrg# Local variables:
2210a3129944Smrg# mode: shell-script
2211a3129944Smrg# sh-indentation: 2
2212a3129944Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
22131009a292Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214a3129944Smrg# time-stamp-time-zone: "UTC"
2215a3129944Smrg# End:
2216266e564dSmrg
2217a3129944Smrg# Set a version string.
22183bf3b463Smrgscriptversion='(GNU libtool) 2.5.4'
22193bf3b463Smrg
22203bf3b463Smrg# func_version
22213bf3b463Smrg# ------------
22223bf3b463Smrg# Echo version message to standard output and exit.
22233bf3b463Smrgfunc_version ()
22243bf3b463Smrg{
22253bf3b463Smrg    $debug_cmd
22263bf3b463Smrg
22273bf3b463Smrg	year=`date +%Y`
22283bf3b463Smrg
22293bf3b463Smrg	cat <<EOF
22303bf3b463Smrg$progname $scriptversion
22313bf3b463SmrgCopyright (C) $year Free Software Foundation, Inc.
22323bf3b463SmrgLicense GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>
22333bf3b463SmrgThis is free software: you are free to change and redistribute it.
22343bf3b463SmrgThere is NO WARRANTY, to the extent permitted by law.
22353bf3b463Smrg
22363bf3b463SmrgOriginally written by Gordon Matzigkeit, 1996
22373bf3b463Smrg(See AUTHORS for complete contributor listing)
22383bf3b463SmrgEOF
22393bf3b463Smrg
22403bf3b463Smrg    exit $?
22413bf3b463Smrg}
2242266e564dSmrg
2243698f425bSmrg
2244a3129944Smrg# func_echo ARG...
2245a3129944Smrg# ----------------
2246a3129944Smrg# Libtool also displays the current mode in messages, so override
2247a3129944Smrg# funclib.sh func_echo with this custom definition.
2248a3129944Smrgfunc_echo ()
22499ef0b394Smrg{
2250a3129944Smrg    $debug_cmd
22519ef0b394Smrg
2252a3129944Smrg    _G_message=$*
22539ef0b394Smrg
2254a3129944Smrg    func_echo_IFS=$IFS
2255a3129944Smrg    IFS=$nl
2256a3129944Smrg    for _G_line in $_G_message; do
2257a3129944Smrg      IFS=$func_echo_IFS
2258a3129944Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2259a3129944Smrg    done
2260a3129944Smrg    IFS=$func_echo_IFS
2261a3129944Smrg}
22629ef0b394Smrg
2263a3129944Smrg
2264a3129944Smrg## ---------------- ##
2265a3129944Smrg## Options parsing. ##
2266a3129944Smrg## ---------------- ##
2267a3129944Smrg
2268a3129944Smrg# Hook in the functions to make sure our own options are parsed during
2269a3129944Smrg# the option parsing loop.
2270a3129944Smrg
2271a3129944Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2272a3129944Smrg
2273a3129944Smrg# Short help message in response to '-h'.
2274a3129944Smrgusage_message="Options:
22753bf3b463Smrg       --config                 show all configuration variables
22763bf3b463Smrg       --debug                  enable verbose shell tracing
22773bf3b463Smrg   -n, --dry-run                display commands without modifying any files
22783bf3b463Smrg       --features               display basic configuration information
22793bf3b463Smrg       --finish                 use operation '--mode=finish'
22803bf3b463Smrg       --mode=MODE              use operation mode MODE
22813bf3b463Smrg       --no-finish              don't update shared library cache
22823bf3b463Smrg       --no-quiet, --no-silent  print default informational messages
22833bf3b463Smrg       --no-warnings            equivalent to '-Wnone'
22843bf3b463Smrg       --preserve-dup-deps      don't remove duplicate dependency libraries
22853bf3b463Smrg       --quiet, --silent        don't print informational messages
22863bf3b463Smrg       --reorder-cache=DIRS     reorder shared library cache for preferred DIRS
22873bf3b463Smrg       --tag=TAG                use configuration variables from tag TAG
22883bf3b463Smrg   -v, --verbose                print more informational messages than default
22893bf3b463Smrg       --version                print version information
22903bf3b463Smrg   -W, --warnings=CATEGORY      report the warnings falling in CATEGORY [all]
22913bf3b463Smrg   -h, --help, --help-all       print short, long, or detailed help message
2292a3129944Smrg"
22939ef0b394Smrg
2294a3129944Smrg# Additional text appended to 'usage_message' in response to '--help'.
2295a3129944Smrgfunc_help ()
22969ef0b394Smrg{
2297a3129944Smrg    $debug_cmd
2298a3129944Smrg
2299a3129944Smrg    func_usage_message
2300a3129944Smrg    $ECHO "$long_help_message
2301a3129944Smrg
2302a3129944SmrgMODE must be one of the following:
2303a3129944Smrg
2304a3129944Smrg       clean           remove files from the build directory
2305a3129944Smrg       compile         compile a source file into a libtool object
2306a3129944Smrg       execute         automatically set library path, then run a program
2307a3129944Smrg       finish          complete the installation of libtool libraries
2308a3129944Smrg       install         install libraries or executables
2309a3129944Smrg       link            create a library or an executable
2310a3129944Smrg       uninstall       remove libraries from an installed directory
2311a3129944Smrg
2312a3129944SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2313a3129944Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2314a3129944SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2315a3129944Smrg
2316a3129944SmrgWhen reporting a bug, please describe a test case to reproduce it and
2317a3129944Smrginclude the following information:
2318a3129944Smrg
2319a3129944Smrg       host-triplet:   $host
2320a3129944Smrg       shell:          $SHELL
2321a3129944Smrg       compiler:       $LTCC
2322a3129944Smrg       compiler flags: $LTCFLAGS
2323a3129944Smrg       linker:         $LD (gnu? $with_gnu_ld)
23243bf3b463Smrg       version:        $progname $scriptversion
2325a3129944Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2326a3129944Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2327a3129944Smrg
2328a3129944SmrgReport bugs to <bug-libtool@gnu.org>.
23293bf3b463SmrgGNU libtool home page: <https://www.gnu.org/software/libtool/>.
23303bf3b463SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
2331a3129944Smrg    exit 0
2332a3129944Smrg}
23339ef0b394Smrg
23349ef0b394Smrg
2335a3129944Smrg# func_lo2o OBJECT-NAME
2336a3129944Smrg# ---------------------
2337a3129944Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2338a3129944Smrg# object suffix.
2339a3129944Smrg
2340a3129944Smrglo2o=s/\\.lo\$/.$objext/
2341a3129944Smrgo2lo=s/\\.$objext\$/.lo/
2342a3129944Smrg
2343a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2344a3129944Smrg  eval 'func_lo2o ()
2345a3129944Smrg  {
2346a3129944Smrg    case $1 in
2347a3129944Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2348a3129944Smrg      *   ) func_lo2o_result=$1               ;;
2349a3129944Smrg    esac
2350a3129944Smrg  }'
2351a3129944Smrg
2352a3129944Smrg  # func_xform LIBOBJ-OR-SOURCE
2353a3129944Smrg  # ---------------------------
2354a3129944Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2355a3129944Smrg  # suffix to a '.lo' libtool-object suffix.
2356a3129944Smrg  eval 'func_xform ()
2357a3129944Smrg  {
2358a3129944Smrg    func_xform_result=${1%.*}.lo
2359a3129944Smrg  }'
2360a3129944Smrgelse
2361a3129944Smrg  # ...otherwise fall back to using sed.
2362a3129944Smrg  func_lo2o ()
2363a3129944Smrg  {
2364a3129944Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2365a3129944Smrg  }
2366a3129944Smrg
2367a3129944Smrg  func_xform ()
2368a3129944Smrg  {
2369a3129944Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2370a3129944Smrg  }
2371a3129944Smrgfi
23729ef0b394Smrg
23739ef0b394Smrg
2374a3129944Smrg# func_fatal_configuration ARG...
2375a3129944Smrg# -------------------------------
2376698f425bSmrg# Echo program name prefixed message to standard error, followed by
2377698f425bSmrg# a configuration failure hint, and exit.
2378698f425bSmrgfunc_fatal_configuration ()
2379698f425bSmrg{
23801009a292Smrg    func_fatal_error ${1+"$@"} \
2381a3129944Smrg      "See the $PACKAGE documentation for more information." \
2382a3129944Smrg      "Fatal configuration error."
2383698f425bSmrg}
2384266e564dSmrg
2385c5629e66Smrg
2386698f425bSmrg# func_config
2387a3129944Smrg# -----------
2388698f425bSmrg# Display the configuration for all the tags in this script.
2389698f425bSmrgfunc_config ()
2390698f425bSmrg{
2391698f425bSmrg    re_begincf='^# ### BEGIN LIBTOOL'
2392698f425bSmrg    re_endcf='^# ### END LIBTOOL'
2393698f425bSmrg
2394698f425bSmrg    # Default configuration.
2395698f425bSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2396266e564dSmrg
2397266e564dSmrg    # Now print the configurations for the tags.
2398266e564dSmrg    for tagname in $taglist; do
2399698f425bSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2400266e564dSmrg    done
2401266e564dSmrg
2402698f425bSmrg    exit $?
2403698f425bSmrg}
2404266e564dSmrg
2405a3129944Smrg
2406698f425bSmrg# func_features
2407a3129944Smrg# -------------
2408698f425bSmrg# Display the features supported by this script.
2409698f425bSmrgfunc_features ()
2410698f425bSmrg{
24119ef0b394Smrg    echo "host: $host"
2412a3129944Smrg    if test yes = "$build_libtool_libs"; then
24139ef0b394Smrg      echo "enable shared libraries"
2414266e564dSmrg    else
24159ef0b394Smrg      echo "disable shared libraries"
2416266e564dSmrg    fi
2417a3129944Smrg    if test yes = "$build_old_libs"; then
24189ef0b394Smrg      echo "enable static libraries"
2419266e564dSmrg    else
24209ef0b394Smrg      echo "disable static libraries"
2421266e564dSmrg    fi
2422698f425bSmrg
2423266e564dSmrg    exit $?
2424698f425bSmrg}
2425266e564dSmrg
2426a3129944Smrg
2427a3129944Smrg# func_enable_tag TAGNAME
2428a3129944Smrg# -----------------------
2429698f425bSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2430698f425bSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2431698f425bSmrg# variable here.
2432698f425bSmrgfunc_enable_tag ()
2433698f425bSmrg{
2434a3129944Smrg    # Global variable:
2435a3129944Smrg    tagname=$1
2436266e564dSmrg
2437a3129944Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2438a3129944Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2439a3129944Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2440266e564dSmrg
2441a3129944Smrg    # Validate tagname.
2442a3129944Smrg    case $tagname in
2443a3129944Smrg      *[!-_A-Za-z0-9,/]*)
2444a3129944Smrg        func_fatal_error "invalid tag name: $tagname"
2445a3129944Smrg        ;;
2446a3129944Smrg    esac
2447266e564dSmrg
2448a3129944Smrg    # Don't test for the "default" C tag, as we know it's
2449a3129944Smrg    # there but not specially marked.
2450a3129944Smrg    case $tagname in
2451a3129944Smrg        CC) ;;
2452698f425bSmrg    *)
2453a3129944Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2454a3129944Smrg	  taglist="$taglist $tagname"
2455a3129944Smrg
2456a3129944Smrg	  # Evaluate the configuration.  Be careful to quote the path
2457a3129944Smrg	  # and the sed script, to avoid splitting on whitespace, but
2458a3129944Smrg	  # also don't use non-portable quotes within backquotes within
2459a3129944Smrg	  # quotes we have to do it in 2 steps:
2460a3129944Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2461a3129944Smrg	  eval "$extractedcf"
2462a3129944Smrg        else
2463a3129944Smrg	  func_error "ignoring unknown tag $tagname"
2464a3129944Smrg        fi
2465a3129944Smrg        ;;
2466a3129944Smrg    esac
2467698f425bSmrg}
2468698f425bSmrg
2469a3129944Smrg
24709ef0b394Smrg# func_check_version_match
2471a3129944Smrg# ------------------------
24729ef0b394Smrg# Ensure that we are using m4 macros, and libtool script from the same
24739ef0b394Smrg# release of libtool.
24749ef0b394Smrgfunc_check_version_match ()
2475698f425bSmrg{
2476a3129944Smrg    if test "$package_revision" != "$macro_revision"; then
2477a3129944Smrg      if test "$VERSION" != "$macro_version"; then
2478a3129944Smrg        if test -z "$macro_version"; then
2479a3129944Smrg          cat >&2 <<_LT_EOF
24809ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24819ef0b394Smrg$progname: definition of this LT_INIT comes from an older release.
24829ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24839ef0b394Smrg$progname: and run autoconf again.
24849ef0b394Smrg_LT_EOF
2485a3129944Smrg        else
2486a3129944Smrg          cat >&2 <<_LT_EOF
24879ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
24889ef0b394Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
24899ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
24909ef0b394Smrg$progname: and run autoconf again.
24919ef0b394Smrg_LT_EOF
2492a3129944Smrg        fi
2493a3129944Smrg      else
2494a3129944Smrg        cat >&2 <<_LT_EOF
24959ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
24969ef0b394Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
24979ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
24989ef0b394Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
24999ef0b394Smrg_LT_EOF
2500a3129944Smrg      fi
2501266e564dSmrg
2502a3129944Smrg      exit $EXIT_MISMATCH
2503a3129944Smrg    fi
25049ef0b394Smrg}
25059ef0b394Smrg
25069ef0b394Smrg
2507a3129944Smrg# libtool_options_prep [ARG]...
2508a3129944Smrg# -----------------------------
2509a3129944Smrg# Preparation for options parsed by libtool.
2510a3129944Smrglibtool_options_prep ()
2511a3129944Smrg{
2512a3129944Smrg    $debug_mode
25139ef0b394Smrg
2514a3129944Smrg    # Option defaults:
2515a3129944Smrg    opt_config=false
2516a3129944Smrg    opt_dlopen=
2517a3129944Smrg    opt_dry_run=false
2518a3129944Smrg    opt_help=false
2519a3129944Smrg    opt_mode=
25203bf3b463Smrg    opt_reorder_cache=false
2521a3129944Smrg    opt_preserve_dup_deps=false
2522a3129944Smrg    opt_quiet=false
25233bf3b463Smrg    opt_finishing=true
25243bf3b463Smrg    opt_warning=
25259ef0b394Smrg
2526a3129944Smrg    nonopt=
2527a3129944Smrg    preserve_args=
25289ef0b394Smrg
25291009a292Smrg    _G_rc_lt_options_prep=:
25301009a292Smrg
2531a3129944Smrg    # Shorthand for --mode=foo, only valid as the first argument
2532a3129944Smrg    case $1 in
2533a3129944Smrg    clean|clea|cle|cl)
2534a3129944Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2535a3129944Smrg      ;;
2536a3129944Smrg    compile|compil|compi|comp|com|co|c)
2537a3129944Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2538a3129944Smrg      ;;
2539a3129944Smrg    execute|execut|execu|exec|exe|ex|e)
2540a3129944Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2541a3129944Smrg      ;;
2542a3129944Smrg    finish|finis|fini|fin|fi|f)
2543a3129944Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2544a3129944Smrg      ;;
2545a3129944Smrg    install|instal|insta|inst|ins|in|i)
2546a3129944Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2547a3129944Smrg      ;;
2548a3129944Smrg    link|lin|li|l)
2549a3129944Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2550a3129944Smrg      ;;
2551a3129944Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2552a3129944Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2553a3129944Smrg      ;;
25541009a292Smrg    *)
25551009a292Smrg      _G_rc_lt_options_prep=false
25561009a292Smrg      ;;
2557a3129944Smrg    esac
2558a3129944Smrg
25591009a292Smrg    if $_G_rc_lt_options_prep; then
25601009a292Smrg      # Pass back the list of options.
25611009a292Smrg      func_quote eval ${1+"$@"}
25621009a292Smrg      libtool_options_prep_result=$func_quote_result
25631009a292Smrg    fi
2564a3129944Smrg}
2565a3129944Smrgfunc_add_hook func_options_prep libtool_options_prep
2566266e564dSmrg
25679ef0b394Smrg
2568a3129944Smrg# libtool_parse_options [ARG]...
2569a3129944Smrg# ---------------------------------
2570a3129944Smrg# Provide handling for libtool specific options.
2571a3129944Smrglibtool_parse_options ()
25729ef0b394Smrg{
2573a3129944Smrg    $debug_cmd
2574698f425bSmrg
25751009a292Smrg    _G_rc_lt_parse_options=false
25761009a292Smrg
2577a3129944Smrg    # Perform our own loop to consume as many options as possible in
2578a3129944Smrg    # each iteration.
2579a3129944Smrg    while test $# -gt 0; do
25801009a292Smrg      _G_match_lt_parse_options=:
2581a3129944Smrg      _G_opt=$1
2582a3129944Smrg      shift
2583a3129944Smrg      case $_G_opt in
2584a3129944Smrg        --dry-run|--dryrun|-n)
2585a3129944Smrg                        opt_dry_run=:
2586a3129944Smrg                        ;;
2587a3129944Smrg
2588a3129944Smrg        --config)       func_config ;;
2589a3129944Smrg
2590a3129944Smrg        --dlopen|-dlopen)
2591a3129944Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2592a3129944Smrg}$1"
2593a3129944Smrg                        shift
2594a3129944Smrg                        ;;
2595a3129944Smrg
2596a3129944Smrg        --preserve-dup-deps)
2597a3129944Smrg                        opt_preserve_dup_deps=: ;;
2598a3129944Smrg
2599a3129944Smrg        --features)     func_features ;;
2600a3129944Smrg
2601a3129944Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2602a3129944Smrg
2603a3129944Smrg        --help)         opt_help=: ;;
2604a3129944Smrg
2605a3129944Smrg        --help-all)     opt_help=': help-all' ;;
2606a3129944Smrg
2607a3129944Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2608a3129944Smrg                        opt_mode=$1
2609a3129944Smrg                        case $1 in
2610a3129944Smrg                          # Valid mode arguments:
2611a3129944Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2612a3129944Smrg
2613a3129944Smrg                          # Catch anything else as an error
26143bf3b463Smrg                          *) func_error "invalid argument '$1' for $_G_opt"
2615a3129944Smrg                             exit_cmd=exit
2616a3129944Smrg                             ;;
2617a3129944Smrg                        esac
2618a3129944Smrg                        shift
2619a3129944Smrg                        ;;
2620a3129944Smrg
26213bf3b463Smrg        --no-finish)
26223bf3b463Smrg                        opt_finishing=false
26233bf3b463Smrg                        func_append preserve_args " $_G_opt"
26243bf3b463Smrg                        ;;
26253bf3b463Smrg
2626a3129944Smrg        --no-silent|--no-quiet)
2627a3129944Smrg                        opt_quiet=false
2628a3129944Smrg                        func_append preserve_args " $_G_opt"
2629a3129944Smrg                        ;;
2630a3129944Smrg
2631a3129944Smrg        --no-warnings|--no-warning|--no-warn)
2632a3129944Smrg                        opt_warning=false
2633a3129944Smrg                        func_append preserve_args " $_G_opt"
2634a3129944Smrg                        ;;
2635a3129944Smrg
2636a3129944Smrg        --no-verbose)
2637a3129944Smrg                        opt_verbose=false
2638a3129944Smrg                        func_append preserve_args " $_G_opt"
2639a3129944Smrg                        ;;
2640a3129944Smrg
26413bf3b463Smrg        --reorder-cache)
26423bf3b463Smrg                        opt_reorder_cache=true
26433bf3b463Smrg                        shared_lib_dirs=$1
26443bf3b463Smrg                        if test -n "$shared_lib_dirs"; then
26453bf3b463Smrg                          case $1 in
26463bf3b463Smrg                            # Must begin with /:
26473bf3b463Smrg                            /*) ;;
26483bf3b463Smrg
26493bf3b463Smrg                            # Catch anything else as an error (relative paths)
26503bf3b463Smrg                            *) func_error "invalid argument '$1' for $_G_opt"
26513bf3b463Smrg                               func_error "absolute paths are required for $_G_opt"
26523bf3b463Smrg                               exit_cmd=exit
26533bf3b463Smrg                               ;;
26543bf3b463Smrg                          esac
26553bf3b463Smrg                        fi
26563bf3b463Smrg                        shift
26573bf3b463Smrg                        ;;
26583bf3b463Smrg
2659a3129944Smrg        --silent|--quiet)
2660a3129944Smrg                        opt_quiet=:
2661a3129944Smrg                        opt_verbose=false
2662a3129944Smrg                        func_append preserve_args " $_G_opt"
2663a3129944Smrg                        ;;
2664a3129944Smrg
2665a3129944Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2666a3129944Smrg                        opt_tag=$1
2667a3129944Smrg                        func_append preserve_args " $_G_opt $1"
2668a3129944Smrg                        func_enable_tag "$1"
2669a3129944Smrg                        shift
2670a3129944Smrg                        ;;
2671a3129944Smrg
2672a3129944Smrg        --verbose|-v)   opt_quiet=false
2673a3129944Smrg                        opt_verbose=:
2674a3129944Smrg                        func_append preserve_args " $_G_opt"
2675a3129944Smrg                        ;;
2676a3129944Smrg
26771009a292Smrg        # An option not handled by this hook function:
26781009a292Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26791009a292Smrg                        _G_match_lt_parse_options=false
26801009a292Smrg                        break
26811009a292Smrg                        ;;
2682a3129944Smrg      esac
26831009a292Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2684a3129944Smrg    done
26859ef0b394Smrg
26861009a292Smrg    if $_G_rc_lt_parse_options; then
26871009a292Smrg      # save modified positional parameters for caller
26881009a292Smrg      func_quote eval ${1+"$@"}
26891009a292Smrg      libtool_parse_options_result=$func_quote_result
26901009a292Smrg    fi
2691a3129944Smrg}
2692a3129944Smrgfunc_add_hook func_parse_options libtool_parse_options
2693698f425bSmrg
2694266e564dSmrg
26953bf3b463Smrg# func_warning ARG...
26963bf3b463Smrg# -------------------
26973bf3b463Smrg# Libtool warnings are not categorized, so override funclib.sh
26983bf3b463Smrg# func_warning with this simpler definition.
26993bf3b463Smrgfunc_warning ()
27003bf3b463Smrg{
27013bf3b463Smrg    if $opt_warning; then
27023bf3b463Smrg        $debug_cmd
27033bf3b463Smrg        $warning_func ${1+"$@"}
27043bf3b463Smrg    fi
27053bf3b463Smrg}
27063bf3b463Smrg
2707698f425bSmrg
2708a3129944Smrg# libtool_validate_options [ARG]...
2709a3129944Smrg# ---------------------------------
2710a3129944Smrg# Perform any sanity checks on option settings and/or unconsumed
2711a3129944Smrg# arguments.
2712a3129944Smrglibtool_validate_options ()
2713a3129944Smrg{
2714a3129944Smrg    # save first non-option argument
2715a3129944Smrg    if test 0 -lt $#; then
2716a3129944Smrg      nonopt=$1
2717a3129944Smrg      shift
2718698f425bSmrg    fi
2719698f425bSmrg
2720a3129944Smrg    # preserve --debug
2721a3129944Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2722698f425bSmrg
27233bf3b463Smrg    case $host_os in
2724a3129944Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2725a3129944Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
27263bf3b463Smrg      cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*)
2727a3129944Smrg        # don't eliminate duplications in $postdeps and $predeps
2728a3129944Smrg        opt_duplicate_compiler_generated_deps=:
2729a3129944Smrg        ;;
2730a3129944Smrg      *)
2731a3129944Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2732a3129944Smrg        ;;
2733a3129944Smrg    esac
2734698f425bSmrg
2735a3129944Smrg    $opt_help || {
2736a3129944Smrg      # Sanity checks first:
2737a3129944Smrg      func_check_version_match
2738a3129944Smrg
2739a3129944Smrg      test yes != "$build_libtool_libs" \
2740a3129944Smrg        && test yes != "$build_old_libs" \
2741a3129944Smrg        && func_fatal_configuration "not configured to build any kind of library"
2742a3129944Smrg
2743a3129944Smrg      # Darwin sucks
2744a3129944Smrg      eval std_shrext=\"$shrext_cmds\"
2745a3129944Smrg
2746a3129944Smrg      # Only execute mode is allowed to have -dlopen flags.
2747a3129944Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2748a3129944Smrg        func_error "unrecognized option '-dlopen'"
2749a3129944Smrg        $ECHO "$help" 1>&2
2750a3129944Smrg        exit $EXIT_FAILURE
2751a3129944Smrg      fi
2752698f425bSmrg
2753a3129944Smrg      # Change the help message to a mode-specific one.
2754a3129944Smrg      generic_help=$help
2755a3129944Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2756a3129944Smrg    }
2757698f425bSmrg
2758a3129944Smrg    # Pass back the unparsed argument list
27591009a292Smrg    func_quote eval ${1+"$@"}
27601009a292Smrg    libtool_validate_options_result=$func_quote_result
27619ef0b394Smrg}
2762a3129944Smrgfunc_add_hook func_validate_options libtool_validate_options
2763698f425bSmrg
2764266e564dSmrg
2765a3129944Smrg# Process options as early as possible so that --help and --version
2766a3129944Smrg# can return quickly.
2767a3129944Smrgfunc_options ${1+"$@"}
2768a3129944Smrgeval set dummy "$func_options_result"; shift
2769a3129944Smrg
2770266e564dSmrg
2771266e564dSmrg
27729ef0b394Smrg## ----------- ##
27739ef0b394Smrg##    Main.    ##
27749ef0b394Smrg## ----------- ##
2775266e564dSmrg
2776a3129944Smrgmagic='%%%MAGIC variable%%%'
2777a3129944Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2778a3129944Smrg
2779a3129944Smrg# Global variables.
2780a3129944Smrgextracted_archives=
2781a3129944Smrgextracted_serial=0
2782a3129944Smrg
2783a3129944Smrg# If this variable is set in any of the actions, the command in it
2784a3129944Smrg# will be execed at the end.  This prevents here-documents from being
2785a3129944Smrg# left over by shells.
2786a3129944Smrgexec_cmd=
2787a3129944Smrg
2788a3129944Smrg
2789a3129944Smrg# A function that is used when there is no print builtin or printf.
2790a3129944Smrgfunc_fallback_echo ()
2791a3129944Smrg{
2792a3129944Smrg  eval 'cat <<_LTECHO_EOF
2793a3129944Smrg$1
2794a3129944Smrg_LTECHO_EOF'
2795a3129944Smrg}
2796a3129944Smrg
2797a3129944Smrg# func_generated_by_libtool
2798a3129944Smrg# True iff stdin has been generated by Libtool. This function is only
2799a3129944Smrg# a basic sanity check; it will hardly flush out determined imposters.
2800a3129944Smrgfunc_generated_by_libtool_p ()
2801a3129944Smrg{
2802a3129944Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2803a3129944Smrg}
2804a3129944Smrg
2805698f425bSmrg# func_lalib_p file
2806a3129944Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2807698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2808698f425bSmrg# determined imposters.
2809698f425bSmrgfunc_lalib_p ()
2810698f425bSmrg{
2811698f425bSmrg    test -f "$1" &&
2812a3129944Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2813698f425bSmrg}
2814266e564dSmrg
2815698f425bSmrg# func_lalib_unsafe_p file
2816a3129944Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2817698f425bSmrg# This function implements the same check as func_lalib_p without
2818698f425bSmrg# resorting to external programs.  To this end, it redirects stdin and
2819698f425bSmrg# closes it afterwards, without saving the original file descriptor.
2820698f425bSmrg# As a safety measure, use it only where a negative result would be
2821a3129944Smrg# fatal anyway.  Works if 'file' does not exist.
2822698f425bSmrgfunc_lalib_unsafe_p ()
2823698f425bSmrg{
2824698f425bSmrg    lalib_p=no
2825698f425bSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2826698f425bSmrg	for lalib_p_l in 1 2 3 4
2827698f425bSmrg	do
2828698f425bSmrg	    read lalib_p_line
2829a3129944Smrg	    case $lalib_p_line in
2830698f425bSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2831698f425bSmrg	    esac
2832698f425bSmrg	done
2833698f425bSmrg	exec 0<&5 5<&-
2834698f425bSmrg    fi
2835a3129944Smrg    test yes = "$lalib_p"
2836698f425bSmrg}
2837266e564dSmrg
2838698f425bSmrg# func_ltwrapper_script_p file
2839698f425bSmrg# True iff FILE is a libtool wrapper script
2840698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2841698f425bSmrg# determined imposters.
2842698f425bSmrgfunc_ltwrapper_script_p ()
2843698f425bSmrg{
2844a3129944Smrg    test -f "$1" &&
2845a3129944Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2846698f425bSmrg}
2847266e564dSmrg
2848698f425bSmrg# func_ltwrapper_executable_p file
2849698f425bSmrg# True iff FILE is a libtool wrapper executable
2850698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2851698f425bSmrg# determined imposters.
2852698f425bSmrgfunc_ltwrapper_executable_p ()
2853698f425bSmrg{
2854698f425bSmrg    func_ltwrapper_exec_suffix=
2855698f425bSmrg    case $1 in
2856698f425bSmrg    *.exe) ;;
2857698f425bSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
2858698f425bSmrg    esac
2859698f425bSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2860698f425bSmrg}
2861698f425bSmrg
2862698f425bSmrg# func_ltwrapper_scriptname file
2863698f425bSmrg# Assumes file is an ltwrapper_executable
2864698f425bSmrg# uses $file to determine the appropriate filename for a
2865698f425bSmrg# temporary ltwrapper_script.
2866698f425bSmrgfunc_ltwrapper_scriptname ()
2867698f425bSmrg{
28689ef0b394Smrg    func_dirname_and_basename "$1" "" "."
28699ef0b394Smrg    func_stripname '' '.exe' "$func_basename_result"
2870a3129944Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2871698f425bSmrg}
2872698f425bSmrg
2873698f425bSmrg# func_ltwrapper_p file
2874698f425bSmrg# True iff FILE is a libtool wrapper script or wrapper executable
2875698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2876698f425bSmrg# determined imposters.
2877698f425bSmrgfunc_ltwrapper_p ()
2878698f425bSmrg{
2879698f425bSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2880698f425bSmrg}
2881698f425bSmrg
2882698f425bSmrg
2883698f425bSmrg# func_execute_cmds commands fail_cmd
2884698f425bSmrg# Execute tilde-delimited COMMANDS.
2885698f425bSmrg# If FAIL_CMD is given, eval that upon failure.
2886698f425bSmrg# FAIL_CMD may read-access the current command in variable CMD!
2887698f425bSmrgfunc_execute_cmds ()
2888698f425bSmrg{
2889a3129944Smrg    $debug_cmd
2890a3129944Smrg
2891698f425bSmrg    save_ifs=$IFS; IFS='~'
2892698f425bSmrg    for cmd in $1; do
2893a3129944Smrg      IFS=$sp$nl
2894698f425bSmrg      eval cmd=\"$cmd\"
2895a3129944Smrg      IFS=$save_ifs
2896698f425bSmrg      func_show_eval "$cmd" "${2-:}"
2897698f425bSmrg    done
2898698f425bSmrg    IFS=$save_ifs
2899698f425bSmrg}
2900698f425bSmrg
2901698f425bSmrg
2902698f425bSmrg# func_source file
2903698f425bSmrg# Source FILE, adding directory component if necessary.
2904698f425bSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
2905698f425bSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2906698f425bSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2907a3129944Smrg# 'FILE.' does not work on cygwin managed mounts.
2908698f425bSmrgfunc_source ()
2909698f425bSmrg{
2910a3129944Smrg    $debug_cmd
2911a3129944Smrg
2912698f425bSmrg    case $1 in
2913698f425bSmrg    */* | *\\*)	. "$1" ;;
2914698f425bSmrg    *)		. "./$1" ;;
2915698f425bSmrg    esac
2916698f425bSmrg}
2917698f425bSmrg
2918698f425bSmrg
29199ef0b394Smrg# func_resolve_sysroot PATH
29209ef0b394Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
29219ef0b394Smrg# func_resolve_sysroot_result
29229ef0b394Smrgfunc_resolve_sysroot ()
29239ef0b394Smrg{
29249ef0b394Smrg  func_resolve_sysroot_result=$1
29259ef0b394Smrg  case $func_resolve_sysroot_result in
29269ef0b394Smrg  =*)
29279ef0b394Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
29289ef0b394Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
29299ef0b394Smrg    ;;
29309ef0b394Smrg  esac
29319ef0b394Smrg}
29329ef0b394Smrg
29339ef0b394Smrg# func_replace_sysroot PATH
29349ef0b394Smrg# If PATH begins with the sysroot, replace it with = and
29359ef0b394Smrg# store the result into func_replace_sysroot_result.
29369ef0b394Smrgfunc_replace_sysroot ()
29379ef0b394Smrg{
2938a3129944Smrg  case $lt_sysroot:$1 in
29399ef0b394Smrg  ?*:"$lt_sysroot"*)
29409ef0b394Smrg    func_stripname "$lt_sysroot" '' "$1"
2941a3129944Smrg    func_replace_sysroot_result='='$func_stripname_result
29429ef0b394Smrg    ;;
29439ef0b394Smrg  *)
29449ef0b394Smrg    # Including no sysroot.
29459ef0b394Smrg    func_replace_sysroot_result=$1
29469ef0b394Smrg    ;;
29479ef0b394Smrg  esac
29489ef0b394Smrg}
29499ef0b394Smrg
2950698f425bSmrg# func_infer_tag arg
2951698f425bSmrg# Infer tagged configuration to use if any are available and
2952698f425bSmrg# if one wasn't chosen via the "--tag" command line option.
2953698f425bSmrg# Only attempt this if the compiler in the base compile
2954698f425bSmrg# command doesn't match the default compiler.
2955698f425bSmrg# arg is usually of the form 'gcc ...'
2956698f425bSmrgfunc_infer_tag ()
2957698f425bSmrg{
2958a3129944Smrg    $debug_cmd
2959a3129944Smrg
2960698f425bSmrg    if test -n "$available_tags" && test -z "$tagname"; then
2961698f425bSmrg      CC_quoted=
2962698f425bSmrg      for arg in $CC; do
29639ef0b394Smrg	func_append_quoted CC_quoted "$arg"
2964698f425bSmrg      done
29659ef0b394Smrg      CC_expanded=`func_echo_all $CC`
29669ef0b394Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2967698f425bSmrg      case $@ in
2968698f425bSmrg      # Blanks in the command may have been stripped by the calling shell,
2969698f425bSmrg      # but not from the CC environment variable when configure was run.
29709ef0b394Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29719ef0b394Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2972698f425bSmrg      # Blanks at the start of $base_compile will cause this to fail
2973698f425bSmrg      # if we don't check for them as well.
2974698f425bSmrg      *)
2975698f425bSmrg	for z in $available_tags; do
2976698f425bSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2977698f425bSmrg	    # Evaluate the configuration.
2978a3129944Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2979698f425bSmrg	    CC_quoted=
2980698f425bSmrg	    for arg in $CC; do
2981698f425bSmrg	      # Double-quote args containing other shell metacharacters.
29829ef0b394Smrg	      func_append_quoted CC_quoted "$arg"
2983698f425bSmrg	    done
29849ef0b394Smrg	    CC_expanded=`func_echo_all $CC`
29859ef0b394Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2986698f425bSmrg	    case "$@ " in
29879ef0b394Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29889ef0b394Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2989698f425bSmrg	      # The compiler in the base compile command matches
2990698f425bSmrg	      # the one in the tagged configuration.
2991698f425bSmrg	      # Assume this is the tagged configuration we want.
2992698f425bSmrg	      tagname=$z
2993698f425bSmrg	      break
2994698f425bSmrg	      ;;
2995698f425bSmrg	    esac
2996698f425bSmrg	  fi
2997698f425bSmrg	done
2998698f425bSmrg	# If $tagname still isn't set, then no tagged configuration
2999698f425bSmrg	# was found and let the user know that the "--tag" command
3000698f425bSmrg	# line option must be used.
3001698f425bSmrg	if test -z "$tagname"; then
3002698f425bSmrg	  func_echo "unable to infer tagged configuration"
3003a3129944Smrg	  func_fatal_error "specify a tag with '--tag'"
3004698f425bSmrg#	else
3005698f425bSmrg#	  func_verbose "using $tagname tagged configuration"
3006698f425bSmrg	fi
3007698f425bSmrg	;;
3008698f425bSmrg      esac
3009698f425bSmrg    fi
3010698f425bSmrg}
3011698f425bSmrg
3012698f425bSmrg
3013698f425bSmrg
3014698f425bSmrg# func_write_libtool_object output_name pic_name nonpic_name
3015698f425bSmrg# Create a libtool object file (analogous to a ".la" file),
3016698f425bSmrg# but don't create it if we're doing a dry run.
3017698f425bSmrgfunc_write_libtool_object ()
3018698f425bSmrg{
3019a3129944Smrg    write_libobj=$1
3020a3129944Smrg    if test yes = "$build_libtool_libs"; then
3021a3129944Smrg      write_lobj=\'$2\'
3022698f425bSmrg    else
3023698f425bSmrg      write_lobj=none
3024698f425bSmrg    fi
3025698f425bSmrg
3026a3129944Smrg    if test yes = "$build_old_libs"; then
3027a3129944Smrg      write_oldobj=\'$3\'
3028698f425bSmrg    else
3029698f425bSmrg      write_oldobj=none
3030698f425bSmrg    fi
3031698f425bSmrg
3032698f425bSmrg    $opt_dry_run || {
3033698f425bSmrg      cat >${write_libobj}T <<EOF
3034698f425bSmrg# $write_libobj - a libtool object file
3035a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
3036698f425bSmrg#
3037698f425bSmrg# Please DO NOT delete this file!
3038698f425bSmrg# It is necessary for linking the library.
3039698f425bSmrg
3040698f425bSmrg# Name of the PIC object.
3041698f425bSmrgpic_object=$write_lobj
3042698f425bSmrg
3043698f425bSmrg# Name of the non-PIC object
3044698f425bSmrgnon_pic_object=$write_oldobj
3045698f425bSmrg
3046698f425bSmrgEOF
3047a3129944Smrg      $MV "${write_libobj}T" "$write_libobj"
3048698f425bSmrg    }
3049698f425bSmrg}
3050698f425bSmrg
30519ef0b394Smrg
30529ef0b394Smrg##################################################
30539ef0b394Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
30549ef0b394Smrg##################################################
30559ef0b394Smrg
30569ef0b394Smrg# func_convert_core_file_wine_to_w32 ARG
30579ef0b394Smrg# Helper function used by file name conversion functions when $build is *nix,
30583bf3b463Smrg# and $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
30599ef0b394Smrg# correctly configured wine environment available, with the winepath program
30609ef0b394Smrg# in $build's $PATH.
30619ef0b394Smrg#
30629ef0b394Smrg# ARG is the $build file name to be converted to w32 format.
30639ef0b394Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
30649ef0b394Smrg# be empty on error (or when ARG is empty)
30659ef0b394Smrgfunc_convert_core_file_wine_to_w32 ()
30669ef0b394Smrg{
3067a3129944Smrg  $debug_cmd
3068a3129944Smrg
3069a3129944Smrg  func_convert_core_file_wine_to_w32_result=$1
30709ef0b394Smrg  if test -n "$1"; then
30719ef0b394Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
30729ef0b394Smrg    # are forced to check the contents of stdout. On the other hand, if the
30739ef0b394Smrg    # command is not found, the shell will set an exit code of 127 and print
30749ef0b394Smrg    # *an error message* to stdout. So we must check for both error code of
30759ef0b394Smrg    # zero AND non-empty stdout, which explains the odd construction:
30769ef0b394Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3077a3129944Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
30789ef0b394Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3079a3129944Smrg        $SED -e "$sed_naive_backslashify"`
30809ef0b394Smrg    else
30819ef0b394Smrg      func_convert_core_file_wine_to_w32_result=
30829ef0b394Smrg    fi
30839ef0b394Smrg  fi
30849ef0b394Smrg}
30859ef0b394Smrg# end: func_convert_core_file_wine_to_w32
30869ef0b394Smrg
30879ef0b394Smrg
30889ef0b394Smrg# func_convert_core_path_wine_to_w32 ARG
30899ef0b394Smrg# Helper function used by path conversion functions when $build is *nix, and
30903bf3b463Smrg# $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
30913bf3b463Smrg# correctly configured wine environment available, with the winepath program
30923bf3b463Smrg# in $build's $PATH. Assumes ARG has no leading or trailing path separator
30933bf3b463Smrg# characters.
30949ef0b394Smrg#
30959ef0b394Smrg# ARG is path to be converted from $build format to win32.
30969ef0b394Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
30979ef0b394Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
30989ef0b394Smrg# are convertible, then the result may be empty.
30999ef0b394Smrgfunc_convert_core_path_wine_to_w32 ()
31009ef0b394Smrg{
3101a3129944Smrg  $debug_cmd
3102a3129944Smrg
31039ef0b394Smrg  # unfortunately, winepath doesn't convert paths, only file names
3104a3129944Smrg  func_convert_core_path_wine_to_w32_result=
31059ef0b394Smrg  if test -n "$1"; then
31069ef0b394Smrg    oldIFS=$IFS
31079ef0b394Smrg    IFS=:
31089ef0b394Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
31099ef0b394Smrg      IFS=$oldIFS
31109ef0b394Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3111a3129944Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
31129ef0b394Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3113a3129944Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
31149ef0b394Smrg        else
31159ef0b394Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
31169ef0b394Smrg        fi
31179ef0b394Smrg      fi
31189ef0b394Smrg    done
31199ef0b394Smrg    IFS=$oldIFS
31209ef0b394Smrg  fi
31219ef0b394Smrg}
31229ef0b394Smrg# end: func_convert_core_path_wine_to_w32
31239ef0b394Smrg
31249ef0b394Smrg
31259ef0b394Smrg# func_cygpath ARGS...
31269ef0b394Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
31279ef0b394Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
31289ef0b394Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
31299ef0b394Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
31309ef0b394Smrg# file name or path is assumed to be in w32 format, as previously converted
31319ef0b394Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
31329ef0b394Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
31339ef0b394Smrg# Cygwin format). Returns an empty string on error.
31349ef0b394Smrg#
31359ef0b394Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
31369ef0b394Smrg# be converted.
31379ef0b394Smrg#
31389ef0b394Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
31399ef0b394Smrg# environment variable; do not put it in $PATH.
31409ef0b394Smrgfunc_cygpath ()
31419ef0b394Smrg{
3142a3129944Smrg  $debug_cmd
3143a3129944Smrg
31449ef0b394Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
31459ef0b394Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
31469ef0b394Smrg    if test "$?" -ne 0; then
31479ef0b394Smrg      # on failure, ensure result is empty
31489ef0b394Smrg      func_cygpath_result=
31499ef0b394Smrg    fi
31509ef0b394Smrg  else
31519ef0b394Smrg    func_cygpath_result=
3152a3129944Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
31539ef0b394Smrg  fi
31549ef0b394Smrg}
31559ef0b394Smrg#end: func_cygpath
31569ef0b394Smrg
31579ef0b394Smrg
31589ef0b394Smrg# func_convert_core_msys_to_w32 ARG
31599ef0b394Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
31609ef0b394Smrg# result in func_convert_core_msys_to_w32_result.
31619ef0b394Smrgfunc_convert_core_msys_to_w32 ()
31629ef0b394Smrg{
3163a3129944Smrg  $debug_cmd
3164a3129944Smrg
31659ef0b394Smrg  # awkward: cmd appends spaces to result
31669ef0b394Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3167a3129944Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
31689ef0b394Smrg}
31699ef0b394Smrg#end: func_convert_core_msys_to_w32
31709ef0b394Smrg
31719ef0b394Smrg
31729ef0b394Smrg# func_convert_file_check ARG1 ARG2
31739ef0b394Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
31749ef0b394Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
31759ef0b394Smrg# func_to_host_file_result to ARG1).
31769ef0b394Smrgfunc_convert_file_check ()
31779ef0b394Smrg{
3178a3129944Smrg  $debug_cmd
3179a3129944Smrg
3180a3129944Smrg  if test -z "$2" && test -n "$1"; then
31819ef0b394Smrg    func_error "Could not determine host file name corresponding to"
3182a3129944Smrg    func_error "  '$1'"
31839ef0b394Smrg    func_error "Continuing, but uninstalled executables may not work."
31849ef0b394Smrg    # Fallback:
3185a3129944Smrg    func_to_host_file_result=$1
31869ef0b394Smrg  fi
31879ef0b394Smrg}
31889ef0b394Smrg# end func_convert_file_check
31899ef0b394Smrg
31909ef0b394Smrg
31919ef0b394Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
31929ef0b394Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
31939ef0b394Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
31949ef0b394Smrg# func_to_host_file_result to a simplistic fallback value (see below).
31959ef0b394Smrgfunc_convert_path_check ()
31969ef0b394Smrg{
3197a3129944Smrg  $debug_cmd
3198a3129944Smrg
31999ef0b394Smrg  if test -z "$4" && test -n "$3"; then
32009ef0b394Smrg    func_error "Could not determine the host path corresponding to"
3201a3129944Smrg    func_error "  '$3'"
32029ef0b394Smrg    func_error "Continuing, but uninstalled executables may not work."
32039ef0b394Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
32049ef0b394Smrg    # should not be "improved".  See libtool.info.
32059ef0b394Smrg    if test "x$1" != "x$2"; then
32069ef0b394Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
32079ef0b394Smrg      func_to_host_path_result=`echo "$3" |
32089ef0b394Smrg        $SED -e "$lt_replace_pathsep_chars"`
32099ef0b394Smrg    else
3210a3129944Smrg      func_to_host_path_result=$3
32119ef0b394Smrg    fi
32129ef0b394Smrg  fi
32139ef0b394Smrg}
32149ef0b394Smrg# end func_convert_path_check
32159ef0b394Smrg
32169ef0b394Smrg
32179ef0b394Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
32189ef0b394Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
32199ef0b394Smrg# and appending REPL if ORIG matches BACKPAT.
32209ef0b394Smrgfunc_convert_path_front_back_pathsep ()
32219ef0b394Smrg{
3222a3129944Smrg  $debug_cmd
3223a3129944Smrg
32249ef0b394Smrg  case $4 in
3225a3129944Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
32269ef0b394Smrg    ;;
32279ef0b394Smrg  esac
32289ef0b394Smrg  case $4 in
32299ef0b394Smrg  $2 ) func_append func_to_host_path_result "$3"
32309ef0b394Smrg    ;;
32319ef0b394Smrg  esac
32329ef0b394Smrg}
32339ef0b394Smrg# end func_convert_path_front_back_pathsep
32349ef0b394Smrg
32359ef0b394Smrg
32363bf3b463Smrg# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER
32373bf3b463Smrg# Replaces a delimiter for a given path.
32383bf3b463Smrgfunc_convert_delimited_path ()
32393bf3b463Smrg{
32403bf3b463Smrg	converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"`
32413bf3b463Smrg}
32423bf3b463Smrg# end func_convert_delimited_path
32433bf3b463Smrg
32443bf3b463Smrg
32459ef0b394Smrg##################################################
32469ef0b394Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
32479ef0b394Smrg##################################################
3248a3129944Smrg# invoked via '$to_host_file_cmd ARG'
32499ef0b394Smrg#
32509ef0b394Smrg# In each case, ARG is the path to be converted from $build to $host format.
32519ef0b394Smrg# Result will be available in $func_to_host_file_result.
32529ef0b394Smrg
32539ef0b394Smrg
32549ef0b394Smrg# func_to_host_file ARG
32559ef0b394Smrg# Converts the file name ARG from $build format to $host format. Return result
32569ef0b394Smrg# in func_to_host_file_result.
32579ef0b394Smrgfunc_to_host_file ()
32589ef0b394Smrg{
3259a3129944Smrg  $debug_cmd
3260a3129944Smrg
32619ef0b394Smrg  $to_host_file_cmd "$1"
32629ef0b394Smrg}
32639ef0b394Smrg# end func_to_host_file
32649ef0b394Smrg
32659ef0b394Smrg
32669ef0b394Smrg# func_to_tool_file ARG LAZY
32679ef0b394Smrg# converts the file name ARG from $build format to toolchain format. Return
32689ef0b394Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
32699ef0b394Smrg# in (the comma separated) LAZY, no conversion takes place.
32709ef0b394Smrgfunc_to_tool_file ()
32719ef0b394Smrg{
3272a3129944Smrg  $debug_cmd
3273a3129944Smrg
32749ef0b394Smrg  case ,$2, in
32759ef0b394Smrg    *,"$to_tool_file_cmd",*)
32769ef0b394Smrg      func_to_tool_file_result=$1
32779ef0b394Smrg      ;;
32789ef0b394Smrg    *)
32799ef0b394Smrg      $to_tool_file_cmd "$1"
32809ef0b394Smrg      func_to_tool_file_result=$func_to_host_file_result
32819ef0b394Smrg      ;;
32829ef0b394Smrg  esac
32839ef0b394Smrg}
32849ef0b394Smrg# end func_to_tool_file
32859ef0b394Smrg
32869ef0b394Smrg
32879ef0b394Smrg# func_convert_file_noop ARG
32889ef0b394Smrg# Copy ARG to func_to_host_file_result.
32899ef0b394Smrgfunc_convert_file_noop ()
32909ef0b394Smrg{
3291a3129944Smrg  func_to_host_file_result=$1
32929ef0b394Smrg}
32939ef0b394Smrg# end func_convert_file_noop
32949ef0b394Smrg
32959ef0b394Smrg
32969ef0b394Smrg# func_convert_file_msys_to_w32 ARG
32979ef0b394Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
32989ef0b394Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
32999ef0b394Smrg# func_to_host_file_result.
33009ef0b394Smrgfunc_convert_file_msys_to_w32 ()
33019ef0b394Smrg{
3302a3129944Smrg  $debug_cmd
3303a3129944Smrg
3304a3129944Smrg  func_to_host_file_result=$1
33059ef0b394Smrg  if test -n "$1"; then
33069ef0b394Smrg    func_convert_core_msys_to_w32 "$1"
3307a3129944Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
33089ef0b394Smrg  fi
33099ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33109ef0b394Smrg}
33119ef0b394Smrg# end func_convert_file_msys_to_w32
33129ef0b394Smrg
33139ef0b394Smrg
33149ef0b394Smrg# func_convert_file_cygwin_to_w32 ARG
33159ef0b394Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
33169ef0b394Smrg# func_to_host_file_result.
33179ef0b394Smrgfunc_convert_file_cygwin_to_w32 ()
33189ef0b394Smrg{
3319a3129944Smrg  $debug_cmd
3320a3129944Smrg
3321a3129944Smrg  func_to_host_file_result=$1
33229ef0b394Smrg  if test -n "$1"; then
33239ef0b394Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
33249ef0b394Smrg    # LT_CYGPATH in this case.
33259ef0b394Smrg    func_to_host_file_result=`cygpath -m "$1"`
33269ef0b394Smrg  fi
33279ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33289ef0b394Smrg}
33299ef0b394Smrg# end func_convert_file_cygwin_to_w32
33309ef0b394Smrg
33319ef0b394Smrg
33329ef0b394Smrg# func_convert_file_nix_to_w32 ARG
33339ef0b394Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
33349ef0b394Smrg# and a working winepath. Returns result in func_to_host_file_result.
33359ef0b394Smrgfunc_convert_file_nix_to_w32 ()
33369ef0b394Smrg{
3337a3129944Smrg  $debug_cmd
3338a3129944Smrg
3339a3129944Smrg  func_to_host_file_result=$1
33409ef0b394Smrg  if test -n "$1"; then
33419ef0b394Smrg    func_convert_core_file_wine_to_w32 "$1"
3342a3129944Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
33439ef0b394Smrg  fi
33449ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33459ef0b394Smrg}
33469ef0b394Smrg# end func_convert_file_nix_to_w32
33479ef0b394Smrg
33489ef0b394Smrg
33499ef0b394Smrg# func_convert_file_msys_to_cygwin ARG
33509ef0b394Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
33519ef0b394Smrg# Returns result in func_to_host_file_result.
33529ef0b394Smrgfunc_convert_file_msys_to_cygwin ()
33539ef0b394Smrg{
3354a3129944Smrg  $debug_cmd
3355a3129944Smrg
3356a3129944Smrg  func_to_host_file_result=$1
33579ef0b394Smrg  if test -n "$1"; then
33589ef0b394Smrg    func_convert_core_msys_to_w32 "$1"
33599ef0b394Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3360a3129944Smrg    func_to_host_file_result=$func_cygpath_result
33619ef0b394Smrg  fi
33629ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33639ef0b394Smrg}
33649ef0b394Smrg# end func_convert_file_msys_to_cygwin
33659ef0b394Smrg
33669ef0b394Smrg
33679ef0b394Smrg# func_convert_file_nix_to_cygwin ARG
33689ef0b394Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
33699ef0b394Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
33709ef0b394Smrg# in func_to_host_file_result.
33719ef0b394Smrgfunc_convert_file_nix_to_cygwin ()
33729ef0b394Smrg{
3373a3129944Smrg  $debug_cmd
3374a3129944Smrg
3375a3129944Smrg  func_to_host_file_result=$1
33769ef0b394Smrg  if test -n "$1"; then
33779ef0b394Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
33789ef0b394Smrg    func_convert_core_file_wine_to_w32 "$1"
33799ef0b394Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3380a3129944Smrg    func_to_host_file_result=$func_cygpath_result
33819ef0b394Smrg  fi
33829ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
33839ef0b394Smrg}
33849ef0b394Smrg# end func_convert_file_nix_to_cygwin
33859ef0b394Smrg
33869ef0b394Smrg
33879ef0b394Smrg#############################################
33889ef0b394Smrg# $build to $host PATH CONVERSION FUNCTIONS #
33899ef0b394Smrg#############################################
3390a3129944Smrg# invoked via '$to_host_path_cmd ARG'
33919ef0b394Smrg#
33929ef0b394Smrg# In each case, ARG is the path to be converted from $build to $host format.
33939ef0b394Smrg# The result will be available in $func_to_host_path_result.
33949ef0b394Smrg#
33959ef0b394Smrg# Path separators are also converted from $build format to $host format.  If
33969ef0b394Smrg# ARG begins or ends with a path separator character, it is preserved (but
33979ef0b394Smrg# converted to $host format) on output.
33989ef0b394Smrg#
33999ef0b394Smrg# All path conversion functions are named using the following convention:
34009ef0b394Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
34019ef0b394Smrg#   path conversion function         : func_convert_path_X_to_Y ()
34029ef0b394Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
34039ef0b394Smrg# same.  If conversion functions are added for new $build/$host combinations,
34049ef0b394Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
34059ef0b394Smrg# will break.
34069ef0b394Smrg
34079ef0b394Smrg
34089ef0b394Smrg# func_init_to_host_path_cmd
34099ef0b394Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
34109ef0b394Smrg# appropriate value, based on the value of $to_host_file_cmd.
34119ef0b394Smrgto_host_path_cmd=
34129ef0b394Smrgfunc_init_to_host_path_cmd ()
34139ef0b394Smrg{
3414a3129944Smrg  $debug_cmd
3415a3129944Smrg
34169ef0b394Smrg  if test -z "$to_host_path_cmd"; then
34179ef0b394Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3418a3129944Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
34199ef0b394Smrg  fi
34209ef0b394Smrg}
34219ef0b394Smrg
34229ef0b394Smrg
34239ef0b394Smrg# func_to_host_path ARG
34249ef0b394Smrg# Converts the path ARG from $build format to $host format. Return result
34259ef0b394Smrg# in func_to_host_path_result.
34269ef0b394Smrgfunc_to_host_path ()
34279ef0b394Smrg{
3428a3129944Smrg  $debug_cmd
3429a3129944Smrg
34309ef0b394Smrg  func_init_to_host_path_cmd
34319ef0b394Smrg  $to_host_path_cmd "$1"
34329ef0b394Smrg}
34339ef0b394Smrg# end func_to_host_path
34349ef0b394Smrg
34359ef0b394Smrg
34369ef0b394Smrg# func_convert_path_noop ARG
34379ef0b394Smrg# Copy ARG to func_to_host_path_result.
34389ef0b394Smrgfunc_convert_path_noop ()
34399ef0b394Smrg{
3440a3129944Smrg  func_to_host_path_result=$1
34419ef0b394Smrg}
34429ef0b394Smrg# end func_convert_path_noop
34439ef0b394Smrg
34449ef0b394Smrg
34459ef0b394Smrg# func_convert_path_msys_to_w32 ARG
34469ef0b394Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
34479ef0b394Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
34489ef0b394Smrg# func_to_host_path_result.
34499ef0b394Smrgfunc_convert_path_msys_to_w32 ()
34509ef0b394Smrg{
3451a3129944Smrg  $debug_cmd
3452a3129944Smrg
3453a3129944Smrg  func_to_host_path_result=$1
34549ef0b394Smrg  if test -n "$1"; then
34559ef0b394Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
34569ef0b394Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
34579ef0b394Smrg    # and winepath ignores them completely.
34589ef0b394Smrg    func_stripname : : "$1"
34599ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
34609ef0b394Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3461a3129944Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
34629ef0b394Smrg    func_convert_path_check : ";" \
34639ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34649ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34659ef0b394Smrg  fi
34669ef0b394Smrg}
34679ef0b394Smrg# end func_convert_path_msys_to_w32
34689ef0b394Smrg
34699ef0b394Smrg
34709ef0b394Smrg# func_convert_path_cygwin_to_w32 ARG
34719ef0b394Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
34729ef0b394Smrg# func_to_host_file_result.
34739ef0b394Smrgfunc_convert_path_cygwin_to_w32 ()
34749ef0b394Smrg{
3475a3129944Smrg  $debug_cmd
3476a3129944Smrg
3477a3129944Smrg  func_to_host_path_result=$1
34789ef0b394Smrg  if test -n "$1"; then
34799ef0b394Smrg    # See func_convert_path_msys_to_w32:
34809ef0b394Smrg    func_stripname : : "$1"
34819ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
34829ef0b394Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
34839ef0b394Smrg    func_convert_path_check : ";" \
34849ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
34859ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
34869ef0b394Smrg  fi
34879ef0b394Smrg}
34889ef0b394Smrg# end func_convert_path_cygwin_to_w32
34899ef0b394Smrg
34909ef0b394Smrg
34919ef0b394Smrg# func_convert_path_nix_to_w32 ARG
34929ef0b394Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
34939ef0b394Smrg# a working winepath.  Returns result in func_to_host_file_result.
34949ef0b394Smrgfunc_convert_path_nix_to_w32 ()
34959ef0b394Smrg{
3496a3129944Smrg  $debug_cmd
3497a3129944Smrg
3498a3129944Smrg  func_to_host_path_result=$1
34999ef0b394Smrg  if test -n "$1"; then
35009ef0b394Smrg    # See func_convert_path_msys_to_w32:
35019ef0b394Smrg    func_stripname : : "$1"
35029ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
35039ef0b394Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3504a3129944Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
35059ef0b394Smrg    func_convert_path_check : ";" \
35069ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35079ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
35089ef0b394Smrg  fi
35099ef0b394Smrg}
35109ef0b394Smrg# end func_convert_path_nix_to_w32
35119ef0b394Smrg
35129ef0b394Smrg
35139ef0b394Smrg# func_convert_path_msys_to_cygwin ARG
35149ef0b394Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
35159ef0b394Smrg# Returns result in func_to_host_file_result.
35169ef0b394Smrgfunc_convert_path_msys_to_cygwin ()
35179ef0b394Smrg{
3518a3129944Smrg  $debug_cmd
3519a3129944Smrg
3520a3129944Smrg  func_to_host_path_result=$1
35219ef0b394Smrg  if test -n "$1"; then
35229ef0b394Smrg    # See func_convert_path_msys_to_w32:
35239ef0b394Smrg    func_stripname : : "$1"
35249ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
35259ef0b394Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
35269ef0b394Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3527a3129944Smrg    func_to_host_path_result=$func_cygpath_result
35289ef0b394Smrg    func_convert_path_check : : \
35299ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35309ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
35319ef0b394Smrg  fi
35329ef0b394Smrg}
35339ef0b394Smrg# end func_convert_path_msys_to_cygwin
35349ef0b394Smrg
35359ef0b394Smrg
35369ef0b394Smrg# func_convert_path_nix_to_cygwin ARG
35379ef0b394Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
35389ef0b394Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
35399ef0b394Smrg# func_to_host_file_result.
35409ef0b394Smrgfunc_convert_path_nix_to_cygwin ()
35419ef0b394Smrg{
3542a3129944Smrg  $debug_cmd
3543a3129944Smrg
3544a3129944Smrg  func_to_host_path_result=$1
35459ef0b394Smrg  if test -n "$1"; then
35469ef0b394Smrg    # Remove leading and trailing path separator characters from
35479ef0b394Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
35489ef0b394Smrg    # into '.;' and ';.', and winepath ignores them completely.
35499ef0b394Smrg    func_stripname : : "$1"
35509ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
35519ef0b394Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
35529ef0b394Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3553a3129944Smrg    func_to_host_path_result=$func_cygpath_result
35549ef0b394Smrg    func_convert_path_check : : \
35559ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
35569ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
35579ef0b394Smrg  fi
35589ef0b394Smrg}
35599ef0b394Smrg# end func_convert_path_nix_to_cygwin
35609ef0b394Smrg
35619ef0b394Smrg
3562a3129944Smrg# func_dll_def_p FILE
3563a3129944Smrg# True iff FILE is a Windows DLL '.def' file.
3564a3129944Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3565a3129944Smrgfunc_dll_def_p ()
3566a3129944Smrg{
3567a3129944Smrg  $debug_cmd
3568a3129944Smrg
3569a3129944Smrg  func_dll_def_p_tmp=`$SED -n \
3570a3129944Smrg    -e 's/^[	 ]*//' \
3571a3129944Smrg    -e '/^\(;.*\)*$/d' \
3572a3129944Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3573a3129944Smrg    -e q \
3574a3129944Smrg    "$1"`
3575a3129944Smrg  test DEF = "$func_dll_def_p_tmp"
3576a3129944Smrg}
3577a3129944Smrg
3578a3129944Smrg
35793bf3b463Smrg# func_reorder_shared_lib_cache DIRS
35803bf3b463Smrg# Reorder the shared library cache by unconfiguring previous shared library cache
35813bf3b463Smrg# and configuring preferred search directories before previous search directories.
35823bf3b463Smrg# Previous shared library cache: /usr/lib /usr/local/lib
35833bf3b463Smrg# Preferred search directories: /tmp/testing
35843bf3b463Smrg# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib
35853bf3b463Smrgfunc_reorder_shared_lib_cache ()
35863bf3b463Smrg{
35873bf3b463Smrg	$debug_cmd
35883bf3b463Smrg
35893bf3b463Smrg	case $host_os in
35903bf3b463Smrg	  openbsd*)
35913bf3b463Smrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
35923bf3b463Smrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
35933bf3b463Smrg	    save_search_directories=$converted_path
35943bf3b463Smrg	    func_convert_delimited_path "$1" ':' '\ '
35953bf3b463Smrg
35963bf3b463Smrg	    # Ensure directories exist
35973bf3b463Smrg	    for dir in $converted_path; do
35983bf3b463Smrg	      # Ensure each directory is an absolute path
35993bf3b463Smrg	      case $dir in
36003bf3b463Smrg	        /*) ;;
36013bf3b463Smrg	        *) func_error "Directory '$dir' is not an absolute path"
36023bf3b463Smrg	           exit $EXIT_FAILURE ;;
36033bf3b463Smrg	      esac
36043bf3b463Smrg	      # Ensure no trailing slashes
36053bf3b463Smrg	      func_stripname '' '/' "$dir"
36063bf3b463Smrg	      dir=$func_stripname_result
36073bf3b463Smrg	      if test -d "$dir"; then
36083bf3b463Smrg	        if test -n "$preferred_search_directories"; then
36093bf3b463Smrg	          preferred_search_directories="$preferred_search_directories $dir"
36103bf3b463Smrg	        else
36113bf3b463Smrg	          preferred_search_directories=$dir
36123bf3b463Smrg	        fi
36133bf3b463Smrg	      else
36143bf3b463Smrg	        func_error "Directory '$dir' does not exist"
36153bf3b463Smrg	        exit $EXIT_FAILURE
36163bf3b463Smrg	      fi
36173bf3b463Smrg	    done
36183bf3b463Smrg
36193bf3b463Smrg	    PATH="$PATH:/sbin" ldconfig -U $save_search_directories
36203bf3b463Smrg	    PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories
36213bf3b463Smrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
36223bf3b463Smrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
36233bf3b463Smrg	    reordered_search_directories=$converted_path
36243bf3b463Smrg
36253bf3b463Smrg	    $ECHO "Original: $save_search_directories"
36263bf3b463Smrg	    $ECHO "Reordered: $reordered_search_directories"
36273bf3b463Smrg	    exit $EXIT_SUCCESS
36283bf3b463Smrg	  ;;
36293bf3b463Smrg	  *)
36303bf3b463Smrg	    func_error "--reorder-cache is not supported for host_os=$host_os."
36313bf3b463Smrg	    exit $EXIT_FAILURE
36323bf3b463Smrg	  ;;
36333bf3b463Smrg	esac
36343bf3b463Smrg}
36353bf3b463Smrg# end func_reorder_shared_lib_cache
36363bf3b463Smrg
36373bf3b463Smrg
3638698f425bSmrg# func_mode_compile arg...
3639698f425bSmrgfunc_mode_compile ()
3640698f425bSmrg{
3641a3129944Smrg    $debug_cmd
3642a3129944Smrg
3643698f425bSmrg    # Get the compilation command and the source file.
3644698f425bSmrg    base_compile=
3645a3129944Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3646698f425bSmrg    suppress_opt=yes
3647698f425bSmrg    suppress_output=
3648698f425bSmrg    arg_mode=normal
3649698f425bSmrg    libobj=
3650698f425bSmrg    later=
3651698f425bSmrg    pie_flag=
3652698f425bSmrg
3653698f425bSmrg    for arg
3654698f425bSmrg    do
3655698f425bSmrg      case $arg_mode in
3656698f425bSmrg      arg  )
3657698f425bSmrg	# do not "continue".  Instead, add this to base_compile
3658a3129944Smrg	lastarg=$arg
3659698f425bSmrg	arg_mode=normal
3660698f425bSmrg	;;
3661698f425bSmrg
3662698f425bSmrg      target )
3663a3129944Smrg	libobj=$arg
3664698f425bSmrg	arg_mode=normal
3665698f425bSmrg	continue
3666698f425bSmrg	;;
3667698f425bSmrg
3668698f425bSmrg      normal )
3669698f425bSmrg	# Accept any command-line options.
3670698f425bSmrg	case $arg in
3671698f425bSmrg	-o)
3672698f425bSmrg	  test -n "$libobj" && \
3673a3129944Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3674698f425bSmrg	  arg_mode=target
3675698f425bSmrg	  continue
3676698f425bSmrg	  ;;
3677698f425bSmrg
3678698f425bSmrg	-pie | -fpie | -fPIE)
36799ef0b394Smrg          func_append pie_flag " $arg"
3680698f425bSmrg	  continue
3681698f425bSmrg	  ;;
3682698f425bSmrg
3683698f425bSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
36849ef0b394Smrg	  func_append later " $arg"
3685698f425bSmrg	  continue
3686698f425bSmrg	  ;;
3687266e564dSmrg
3688266e564dSmrg	-no-suppress)
3689266e564dSmrg	  suppress_opt=no
3690266e564dSmrg	  continue
3691266e564dSmrg	  ;;
3692266e564dSmrg
3693266e564dSmrg	-Xcompiler)
3694266e564dSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3695266e564dSmrg	  continue      #  The current "srcfile" will either be retained or
3696266e564dSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3697266e564dSmrg
3698266e564dSmrg	-Wc,*)
3699698f425bSmrg	  func_stripname '-Wc,' '' "$arg"
3700698f425bSmrg	  args=$func_stripname_result
3701266e564dSmrg	  lastarg=
3702a3129944Smrg	  save_ifs=$IFS; IFS=,
3703698f425bSmrg	  for arg in $args; do
3704a3129944Smrg	    IFS=$save_ifs
37059ef0b394Smrg	    func_append_quoted lastarg "$arg"
3706266e564dSmrg	  done
3707a3129944Smrg	  IFS=$save_ifs
3708698f425bSmrg	  func_stripname ' ' '' "$lastarg"
3709698f425bSmrg	  lastarg=$func_stripname_result
3710266e564dSmrg
3711266e564dSmrg	  # Add the arguments to base_compile.
37129ef0b394Smrg	  func_append base_compile " $lastarg"
3713266e564dSmrg	  continue
3714266e564dSmrg	  ;;
3715266e564dSmrg
3716698f425bSmrg	*)
3717266e564dSmrg	  # Accept the current argument as the source file.
3718266e564dSmrg	  # The previous "srcfile" becomes the current argument.
3719266e564dSmrg	  #
3720a3129944Smrg	  lastarg=$srcfile
3721a3129944Smrg	  srcfile=$arg
3722266e564dSmrg	  ;;
3723266e564dSmrg	esac  #  case $arg
3724266e564dSmrg	;;
3725266e564dSmrg      esac    #  case $arg_mode
3726266e564dSmrg
3727266e564dSmrg      # Aesthetically quote the previous argument.
37289ef0b394Smrg      func_append_quoted base_compile "$lastarg"
3729266e564dSmrg    done # for arg
3730266e564dSmrg
3731266e564dSmrg    case $arg_mode in
3732266e564dSmrg    arg)
3733698f425bSmrg      func_fatal_error "you must specify an argument for -Xcompile"
3734266e564dSmrg      ;;
3735266e564dSmrg    target)
3736a3129944Smrg      func_fatal_error "you must specify a target with '-o'"
3737266e564dSmrg      ;;
3738266e564dSmrg    *)
3739266e564dSmrg      # Get the name of the library object.
3740698f425bSmrg      test -z "$libobj" && {
3741698f425bSmrg	func_basename "$srcfile"
3742a3129944Smrg	libobj=$func_basename_result
3743698f425bSmrg      }
3744266e564dSmrg      ;;
3745266e564dSmrg    esac
3746266e564dSmrg
3747266e564dSmrg    # Recognize several different file suffixes.
3748266e564dSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3749266e564dSmrg    case $libobj in
3750698f425bSmrg    *.[cCFSifmso] | \
3751698f425bSmrg    *.ada | *.adb | *.ads | *.asm | \
3752698f425bSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3753fb5e8d76Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3754698f425bSmrg      func_xform "$libobj"
3755698f425bSmrg      libobj=$func_xform_result
3756698f425bSmrg      ;;
3757266e564dSmrg    esac
3758266e564dSmrg
3759266e564dSmrg    case $libobj in
3760698f425bSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3761266e564dSmrg    *)
3762a3129944Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3763266e564dSmrg      ;;
3764266e564dSmrg    esac
3765266e564dSmrg
3766266e564dSmrg    func_infer_tag $base_compile
3767266e564dSmrg
3768266e564dSmrg    for arg in $later; do
3769266e564dSmrg      case $arg in
3770698f425bSmrg      -shared)
3771a3129944Smrg	test yes = "$build_libtool_libs" \
3772a3129944Smrg	  || func_fatal_configuration "cannot build a shared library"
3773698f425bSmrg	build_old_libs=no
3774698f425bSmrg	continue
3775698f425bSmrg	;;
3776698f425bSmrg
3777266e564dSmrg      -static)
3778698f425bSmrg	build_libtool_libs=no
3779266e564dSmrg	build_old_libs=yes
3780266e564dSmrg	continue
3781266e564dSmrg	;;
3782266e564dSmrg
3783266e564dSmrg      -prefer-pic)
3784266e564dSmrg	pic_mode=yes
3785266e564dSmrg	continue
3786266e564dSmrg	;;
3787266e564dSmrg
3788266e564dSmrg      -prefer-non-pic)
3789266e564dSmrg	pic_mode=no
3790266e564dSmrg	continue
3791266e564dSmrg	;;
3792266e564dSmrg      esac
3793266e564dSmrg    done
3794266e564dSmrg
37951009a292Smrg    func_quote_arg pretty "$libobj"
37961009a292Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3797698f425bSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3798a3129944Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3799698f425bSmrg    func_dirname_and_basename "$obj" "/" ""
3800a3129944Smrg    objname=$func_basename_result
3801a3129944Smrg    xdir=$func_dirname_result
3802a3129944Smrg    lobj=$xdir$objdir/$objname
3803266e564dSmrg
3804698f425bSmrg    test -z "$base_compile" && \
3805698f425bSmrg      func_fatal_help "you must specify a compilation command"
3806266e564dSmrg
3807266e564dSmrg    # Delete any leftover library objects.
3808a3129944Smrg    if test yes = "$build_old_libs"; then
3809266e564dSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3810266e564dSmrg    else
3811266e564dSmrg      removelist="$lobj $libobj ${libobj}T"
3812266e564dSmrg    fi
3813266e564dSmrg
3814266e564dSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3815266e564dSmrg    case $host_os in
38163bf3b463Smrg    cygwin* | mingw* | windows* | pw32* | os2* | cegcc*)
3817266e564dSmrg      pic_mode=default
3818266e564dSmrg      ;;
3819266e564dSmrg    esac
3820a3129944Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3821266e564dSmrg      # non-PIC code in shared libraries is not supported
3822266e564dSmrg      pic_mode=default
3823266e564dSmrg    fi
3824266e564dSmrg
3825266e564dSmrg    # Calculate the filename of the output object if compiler does
3826266e564dSmrg    # not support -o with -c
3827a3129944Smrg    if test no = "$compiler_c_o"; then
3828a3129944Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3829a3129944Smrg      lockfile=$output_obj.lock
3830266e564dSmrg    else
3831266e564dSmrg      output_obj=
3832266e564dSmrg      need_locks=no
3833266e564dSmrg      lockfile=
3834266e564dSmrg    fi
3835266e564dSmrg
3836266e564dSmrg    # Lock this critical section if it is needed
3837266e564dSmrg    # We use this script file to make the link, it avoids creating a new file
3838a3129944Smrg    if test yes = "$need_locks"; then
3839698f425bSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3840698f425bSmrg	func_echo "Waiting for $lockfile to be removed"
3841266e564dSmrg	sleep 2
3842266e564dSmrg      done
3843a3129944Smrg    elif test warn = "$need_locks"; then
3844266e564dSmrg      if test -f "$lockfile"; then
3845698f425bSmrg	$ECHO "\
3846266e564dSmrg*** ERROR, $lockfile exists and contains:
3847266e564dSmrg`cat $lockfile 2>/dev/null`
3848266e564dSmrg
3849266e564dSmrgThis indicates that another process is trying to use the same
3850266e564dSmrgtemporary object file, and libtool could not work around it because
3851a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3852266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3853266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3854266e564dSmrgcompiler."
3855266e564dSmrg
3856698f425bSmrg	$opt_dry_run || $RM $removelist
3857266e564dSmrg	exit $EXIT_FAILURE
3858266e564dSmrg      fi
38599ef0b394Smrg      func_append removelist " $output_obj"
3860698f425bSmrg      $ECHO "$srcfile" > "$lockfile"
3861266e564dSmrg    fi
3862266e564dSmrg
3863698f425bSmrg    $opt_dry_run || $RM $removelist
38649ef0b394Smrg    func_append removelist " $lockfile"
3865698f425bSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3866698f425bSmrg
38679ef0b394Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
38689ef0b394Smrg    srcfile=$func_to_tool_file_result
38691009a292Smrg    func_quote_arg pretty "$srcfile"
38701009a292Smrg    qsrcfile=$func_quote_arg_result
3871266e564dSmrg
3872266e564dSmrg    # Only build a PIC object if we are building libtool libraries.
3873a3129944Smrg    if test yes = "$build_libtool_libs"; then
3874266e564dSmrg      # Without this assignment, base_compile gets emptied.
3875266e564dSmrg      fbsd_hideous_sh_bug=$base_compile
3876266e564dSmrg
3877a3129944Smrg      if test no != "$pic_mode"; then
3878266e564dSmrg	command="$base_compile $qsrcfile $pic_flag"
3879266e564dSmrg      else
3880266e564dSmrg	# Don't build PIC code
3881266e564dSmrg	command="$base_compile $qsrcfile"
3882266e564dSmrg      fi
3883266e564dSmrg
3884698f425bSmrg      func_mkdir_p "$xdir$objdir"
3885266e564dSmrg
3886266e564dSmrg      if test -z "$output_obj"; then
3887266e564dSmrg	# Place PIC objects in $objdir
38889ef0b394Smrg	func_append command " -o $lobj"
3889266e564dSmrg      fi
3890266e564dSmrg
3891698f425bSmrg      func_show_eval_locale "$command"	\
3892698f425bSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3893266e564dSmrg
3894a3129944Smrg      if test warn = "$need_locks" &&
3895266e564dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3896698f425bSmrg	$ECHO "\
3897266e564dSmrg*** ERROR, $lockfile contains:
3898266e564dSmrg`cat $lockfile 2>/dev/null`
3899266e564dSmrg
3900266e564dSmrgbut it should contain:
3901266e564dSmrg$srcfile
3902266e564dSmrg
3903266e564dSmrgThis indicates that another process is trying to use the same
3904266e564dSmrgtemporary object file, and libtool could not work around it because
3905a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3906266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3907266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3908266e564dSmrgcompiler."
3909266e564dSmrg
3910698f425bSmrg	$opt_dry_run || $RM $removelist
3911266e564dSmrg	exit $EXIT_FAILURE
3912266e564dSmrg      fi
3913266e564dSmrg
3914266e564dSmrg      # Just move the object if needed, then go on to compile the next one
3915266e564dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3916698f425bSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3917698f425bSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3918266e564dSmrg      fi
3919266e564dSmrg
3920266e564dSmrg      # Allow error messages only from the first compilation.
3921a3129944Smrg      if test yes = "$suppress_opt"; then
3922698f425bSmrg	suppress_output=' >/dev/null 2>&1'
3923266e564dSmrg      fi
3924266e564dSmrg    fi
3925266e564dSmrg
3926266e564dSmrg    # Only build a position-dependent object if we build old libraries.
3927a3129944Smrg    if test yes = "$build_old_libs"; then
3928a3129944Smrg      if test yes != "$pic_mode"; then
3929266e564dSmrg	# Don't build PIC code
3930698f425bSmrg	command="$base_compile $qsrcfile$pie_flag"
3931266e564dSmrg      else
3932266e564dSmrg	command="$base_compile $qsrcfile $pic_flag"
3933266e564dSmrg      fi
3934a3129944Smrg      if test yes = "$compiler_c_o"; then
39359ef0b394Smrg	func_append command " -o $obj"
3936266e564dSmrg      fi
3937266e564dSmrg
3938266e564dSmrg      # Suppress compiler output if we already did a PIC compilation.
39399ef0b394Smrg      func_append command "$suppress_output"
3940698f425bSmrg      func_show_eval_locale "$command" \
3941698f425bSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3942266e564dSmrg
3943a3129944Smrg      if test warn = "$need_locks" &&
3944266e564dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3945698f425bSmrg	$ECHO "\
3946266e564dSmrg*** ERROR, $lockfile contains:
3947266e564dSmrg`cat $lockfile 2>/dev/null`
3948266e564dSmrg
3949266e564dSmrgbut it should contain:
3950266e564dSmrg$srcfile
3951266e564dSmrg
3952266e564dSmrgThis indicates that another process is trying to use the same
3953266e564dSmrgtemporary object file, and libtool could not work around it because
3954a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3955266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3956266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3957266e564dSmrgcompiler."
3958266e564dSmrg
3959698f425bSmrg	$opt_dry_run || $RM $removelist
3960266e564dSmrg	exit $EXIT_FAILURE
3961266e564dSmrg      fi
3962266e564dSmrg
3963266e564dSmrg      # Just move the object if needed
3964266e564dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3965698f425bSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
3966698f425bSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3967266e564dSmrg      fi
3968266e564dSmrg    fi
3969266e564dSmrg
3970698f425bSmrg    $opt_dry_run || {
3971698f425bSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3972266e564dSmrg
3973698f425bSmrg      # Unlock the critical section if it was locked
3974a3129944Smrg      if test no != "$need_locks"; then
3975698f425bSmrg	removelist=$lockfile
3976698f425bSmrg        $RM "$lockfile"
3977698f425bSmrg      fi
3978698f425bSmrg    }
3979266e564dSmrg
3980266e564dSmrg    exit $EXIT_SUCCESS
3981698f425bSmrg}
3982266e564dSmrg
3983698f425bSmrg$opt_help || {
3984a3129944Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3985698f425bSmrg}
3986266e564dSmrg
3987698f425bSmrgfunc_mode_help ()
3988698f425bSmrg{
3989698f425bSmrg    # We need to display help for each of the modes.
39909ef0b394Smrg    case $opt_mode in
3991698f425bSmrg      "")
3992698f425bSmrg        # Generic help is extracted from the usage comments
3993698f425bSmrg        # at the start of this file.
3994698f425bSmrg        func_help
3995698f425bSmrg        ;;
3996266e564dSmrg
3997698f425bSmrg      clean)
3998698f425bSmrg        $ECHO \
3999698f425bSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
4000266e564dSmrg
4001698f425bSmrgRemove files from the build directory.
4002266e564dSmrg
4003698f425bSmrgRM is the name of the program to use to delete files associated with each FILE
4004a3129944Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4005698f425bSmrgto RM.
4006266e564dSmrg
4007698f425bSmrgIf FILE is a libtool library, object or program, all the files associated
4008698f425bSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
4009698f425bSmrg        ;;
4010266e564dSmrg
4011698f425bSmrg      compile)
4012698f425bSmrg      $ECHO \
4013698f425bSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
4014266e564dSmrg
4015698f425bSmrgCompile a source file into a libtool library object.
4016266e564dSmrg
4017698f425bSmrgThis mode accepts the following additional options:
4018266e564dSmrg
4019698f425bSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
4020698f425bSmrg  -no-suppress      do not suppress compiler output for multiple passes
40219ef0b394Smrg  -prefer-pic       try to build PIC objects only
40229ef0b394Smrg  -prefer-non-pic   try to build non-PIC objects only
4023a3129944Smrg  -shared           do not build a '.o' file suitable for static linking
4024a3129944Smrg  -static           only build a '.o' file suitable for static linking
40251009a292Smrg  -Wc,FLAG
40261009a292Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
4027266e564dSmrg
4028a3129944SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
4029698f425bSmrgfrom the given SOURCEFILE.
4030266e564dSmrg
4031698f425bSmrgThe output file name is determined by removing the directory component from
4032a3129944SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
4033a3129944Smrglibrary object suffix, '.lo'."
4034698f425bSmrg        ;;
4035266e564dSmrg
4036698f425bSmrg      execute)
4037698f425bSmrg        $ECHO \
4038698f425bSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
4039266e564dSmrg
4040698f425bSmrgAutomatically set library path, then run a program.
4041266e564dSmrg
4042698f425bSmrgThis mode accepts the following additional options:
4043266e564dSmrg
4044698f425bSmrg  -dlopen FILE      add the directory containing FILE to the library path
4045266e564dSmrg
4046a3129944SmrgThis mode sets the library path environment variable according to '-dlopen'
4047698f425bSmrgflags.
4048266e564dSmrg
4049698f425bSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
4050698f425bSmrginto their corresponding uninstalled binary, and any of their required library
4051698f425bSmrgdirectories are added to the library path.
4052266e564dSmrg
4053698f425bSmrgThen, COMMAND is executed, with ARGS as arguments."
4054698f425bSmrg        ;;
4055266e564dSmrg
4056698f425bSmrg      finish)
4057698f425bSmrg        $ECHO \
4058698f425bSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
4059266e564dSmrg
4060698f425bSmrgComplete the installation of libtool libraries.
4061266e564dSmrg
4062698f425bSmrgEach LIBDIR is a directory that contains libtool libraries.
4063266e564dSmrg
4064698f425bSmrgThe commands that this mode executes may require superuser privileges.  Use
4065a3129944Smrgthe '--dry-run' option if you just want to see what would be executed."
4066698f425bSmrg        ;;
4067266e564dSmrg
4068698f425bSmrg      install)
4069698f425bSmrg        $ECHO \
4070698f425bSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
4071266e564dSmrg
4072698f425bSmrgInstall executables or libraries.
4073266e564dSmrg
4074698f425bSmrgINSTALL-COMMAND is the installation command.  The first component should be
4075a3129944Smrgeither the 'install' or 'cp' program.
4076266e564dSmrg
4077698f425bSmrgThe following components of INSTALL-COMMAND are treated specially:
4078266e564dSmrg
40799ef0b394Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
4080266e564dSmrg
4081698f425bSmrgThe rest of the components are interpreted as arguments to that command (only
4082698f425bSmrgBSD-compatible install options are recognized)."
4083698f425bSmrg        ;;
4084266e564dSmrg
4085698f425bSmrg      link)
4086698f425bSmrg        $ECHO \
4087698f425bSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
4088266e564dSmrg
4089698f425bSmrgLink object files or libraries together to form another library, or to
4090698f425bSmrgcreate an executable program.
4091266e564dSmrg
4092698f425bSmrgLINK-COMMAND is a command using the C compiler that you would use to create
4093698f425bSmrga program from several object files.
4094266e564dSmrg
4095698f425bSmrgThe following components of LINK-COMMAND are treated specially:
4096266e564dSmrg
4097698f425bSmrg  -all-static       do not do any dynamic linking at all
4098698f425bSmrg  -avoid-version    do not add a version suffix if possible
40999ef0b394Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
41009ef0b394Smrg                    libraries must be found in the PATH setting at runtime)
4101a3129944Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
4102698f425bSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
4103698f425bSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
4104698f425bSmrg  -export-symbols SYMFILE
4105698f425bSmrg                    try to export only the symbols listed in SYMFILE
4106698f425bSmrg  -export-symbols-regex REGEX
4107698f425bSmrg                    try to export only the symbols matching REGEX
4108698f425bSmrg  -LLIBDIR          search LIBDIR for required installed libraries
4109698f425bSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
4110698f425bSmrg  -module           build a library that can dlopened
4111698f425bSmrg  -no-fast-install  disable the fast-install mode
4112698f425bSmrg  -no-install       link a not-installable executable
4113698f425bSmrg  -no-undefined     declare that a library does not refer to external symbols
4114698f425bSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
4115a3129944Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
4116a3129944Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
4117698f425bSmrg  -precious-files-regex REGEX
4118698f425bSmrg                    don't remove output files matching REGEX
4119698f425bSmrg  -release RELEASE  specify package release information
4120698f425bSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4121698f425bSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4122698f425bSmrg  -shared           only do dynamic linking of libtool libraries
4123698f425bSmrg  -shrext SUFFIX    override the standard shared library file extension
4124698f425bSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4125698f425bSmrg  -static-libtool-libs
4126698f425bSmrg                    do not do any dynamic linking of libtool libraries
4127698f425bSmrg  -version-info CURRENT[:REVISION[:AGE]]
4128698f425bSmrg                    specify library version info [each variable defaults to 0]
4129698f425bSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
41309ef0b394Smrg  -Wc,FLAG
41319ef0b394Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
41321009a292Smrg  -Wa,FLAG
41331009a292Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
41349ef0b394Smrg  -Wl,FLAG
41359ef0b394Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
41369ef0b394Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4137266e564dSmrg
4138a3129944SmrgAll other options (arguments beginning with '-') are ignored.
4139266e564dSmrg
4140a3129944SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4141698f425bSmrgtreated as uninstalled libtool libraries, other files are standard or library
4142698f425bSmrgobject files.
4143c5629e66Smrg
4144a3129944SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4145a3129944Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4146698f425bSmrgrequired, except when creating a convenience library.
4147266e564dSmrg
4148a3129944SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4149a3129944Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4150266e564dSmrg
4151a3129944SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4152698f425bSmrgis created, otherwise an executable program is created."
4153266e564dSmrg        ;;
4154266e564dSmrg
4155698f425bSmrg      uninstall)
4156698f425bSmrg        $ECHO \
4157698f425bSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4158266e564dSmrg
4159698f425bSmrgRemove libraries from an installation directory.
4160266e564dSmrg
4161698f425bSmrgRM is the name of the program to use to delete files associated with each FILE
4162a3129944Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4163698f425bSmrgto RM.
4164266e564dSmrg
4165698f425bSmrgIf FILE is a libtool library, all the files associated with it are deleted.
4166698f425bSmrgOtherwise, only FILE itself is deleted using RM."
4167698f425bSmrg        ;;
4168266e564dSmrg
4169698f425bSmrg      *)
4170a3129944Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
4171698f425bSmrg        ;;
4172698f425bSmrg    esac
4173266e564dSmrg
41749ef0b394Smrg    echo
4175a3129944Smrg    $ECHO "Try '$progname --help' for more information about other modes."
4176698f425bSmrg}
4177266e564dSmrg
41789ef0b394Smrg# Now that we've collected a possible --mode arg, show help if necessary
41799ef0b394Smrgif $opt_help; then
4180a3129944Smrg  if test : = "$opt_help"; then
41819ef0b394Smrg    func_mode_help
41829ef0b394Smrg  else
41839ef0b394Smrg    {
41849ef0b394Smrg      func_help noexit
41859ef0b394Smrg      for opt_mode in compile link execute install finish uninstall clean; do
41869ef0b394Smrg	func_mode_help
41879ef0b394Smrg      done
4188a3129944Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
41899ef0b394Smrg    {
41909ef0b394Smrg      func_help noexit
41919ef0b394Smrg      for opt_mode in compile link execute install finish uninstall clean; do
41929ef0b394Smrg	echo
41939ef0b394Smrg	func_mode_help
41949ef0b394Smrg      done
41959ef0b394Smrg    } |
4196a3129944Smrg    $SED '1d
41979ef0b394Smrg      /^When reporting/,/^Report/{
41989ef0b394Smrg	H
41999ef0b394Smrg	d
42009ef0b394Smrg      }
42019ef0b394Smrg      $x
42029ef0b394Smrg      /information about other modes/d
42039ef0b394Smrg      /more detailed .*MODE/d
42049ef0b394Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
42059ef0b394Smrg  fi
42069ef0b394Smrg  exit $?
42079ef0b394Smrgfi
4208266e564dSmrg
4209266e564dSmrg
42103bf3b463Smrg# If option '--reorder-cache', reorder the shared library cache and exit.
42113bf3b463Smrgif $opt_reorder_cache; then
42123bf3b463Smrg    func_reorder_shared_lib_cache $shared_lib_dirs
42133bf3b463Smrgfi
42143bf3b463Smrg
42153bf3b463Smrg
4216698f425bSmrg# func_mode_execute arg...
4217698f425bSmrgfunc_mode_execute ()
4218698f425bSmrg{
4219a3129944Smrg    $debug_cmd
4220a3129944Smrg
4221698f425bSmrg    # The first argument is the command name.
4222a3129944Smrg    cmd=$nonopt
4223698f425bSmrg    test -z "$cmd" && \
4224698f425bSmrg      func_fatal_help "you must specify a COMMAND"
4225266e564dSmrg
4226698f425bSmrg    # Handle -dlopen flags immediately.
42279ef0b394Smrg    for file in $opt_dlopen; do
4228698f425bSmrg      test -f "$file" \
4229a3129944Smrg	|| func_fatal_help "'$file' is not a file"
4230266e564dSmrg
4231698f425bSmrg      dir=
4232698f425bSmrg      case $file in
4233698f425bSmrg      *.la)
42349ef0b394Smrg	func_resolve_sysroot "$file"
42359ef0b394Smrg	file=$func_resolve_sysroot_result
42369ef0b394Smrg
4237698f425bSmrg	# Check to see that this really is a libtool archive.
4238698f425bSmrg	func_lalib_unsafe_p "$file" \
4239a3129944Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4240266e564dSmrg
4241698f425bSmrg	# Read the libtool library.
4242698f425bSmrg	dlname=
4243698f425bSmrg	library_names=
4244698f425bSmrg	func_source "$file"
4245266e564dSmrg
4246698f425bSmrg	# Skip this library if it cannot be dlopened.
4247698f425bSmrg	if test -z "$dlname"; then
4248698f425bSmrg	  # Warn if it was a shared library.
4249698f425bSmrg	  test -n "$library_names" && \
4250a3129944Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4251698f425bSmrg	  continue
4252698f425bSmrg	fi
4253266e564dSmrg
4254698f425bSmrg	func_dirname "$file" "" "."
4255a3129944Smrg	dir=$func_dirname_result
4256266e564dSmrg
4257698f425bSmrg	if test -f "$dir/$objdir/$dlname"; then
42589ef0b394Smrg	  func_append dir "/$objdir"
4259698f425bSmrg	else
4260698f425bSmrg	  if test ! -f "$dir/$dlname"; then
4261a3129944Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4262698f425bSmrg	  fi
4263698f425bSmrg	fi
4264266e564dSmrg	;;
4265266e564dSmrg
4266698f425bSmrg      *.lo)
4267698f425bSmrg	# Just add the directory containing the .lo file.
4268698f425bSmrg	func_dirname "$file" "" "."
4269a3129944Smrg	dir=$func_dirname_result
4270266e564dSmrg	;;
4271266e564dSmrg
4272698f425bSmrg      *)
4273a3129944Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4274266e564dSmrg	continue
4275266e564dSmrg	;;
4276698f425bSmrg      esac
4277266e564dSmrg
4278698f425bSmrg      # Get the absolute pathname.
4279698f425bSmrg      absdir=`cd "$dir" && pwd`
4280a3129944Smrg      test -n "$absdir" && dir=$absdir
4281266e564dSmrg
4282698f425bSmrg      # Now add the directory to shlibpath_var.
4283698f425bSmrg      if eval "test -z \"\$$shlibpath_var\""; then
4284698f425bSmrg	eval "$shlibpath_var=\"\$dir\""
4285698f425bSmrg      else
4286698f425bSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4287698f425bSmrg      fi
4288698f425bSmrg    done
4289266e564dSmrg
4290698f425bSmrg    # This variable tells wrapper scripts just to set shlibpath_var
4291698f425bSmrg    # rather than running their programs.
4292a3129944Smrg    libtool_execute_magic=$magic
4293266e564dSmrg
4294698f425bSmrg    # Check if any of the arguments is a wrapper script.
4295698f425bSmrg    args=
4296698f425bSmrg    for file
4297698f425bSmrg    do
4298698f425bSmrg      case $file in
42999ef0b394Smrg      -* | *.la | *.lo ) ;;
4300698f425bSmrg      *)
4301698f425bSmrg	# Do a test to see if this is really a libtool program.
4302698f425bSmrg	if func_ltwrapper_script_p "$file"; then
4303698f425bSmrg	  func_source "$file"
4304698f425bSmrg	  # Transform arg to wrapped name.
4305a3129944Smrg	  file=$progdir/$program
4306698f425bSmrg	elif func_ltwrapper_executable_p "$file"; then
4307698f425bSmrg	  func_ltwrapper_scriptname "$file"
4308698f425bSmrg	  func_source "$func_ltwrapper_scriptname_result"
4309698f425bSmrg	  # Transform arg to wrapped name.
4310a3129944Smrg	  file=$progdir/$program
4311698f425bSmrg	fi
4312698f425bSmrg	;;
4313698f425bSmrg      esac
4314698f425bSmrg      # Quote arguments (to preserve shell metacharacters).
43159ef0b394Smrg      func_append_quoted args "$file"
4316698f425bSmrg    done
4317266e564dSmrg
4318a3129944Smrg    if $opt_dry_run; then
4319a3129944Smrg      # Display what would be done.
4320a3129944Smrg      if test -n "$shlibpath_var"; then
4321a3129944Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4322a3129944Smrg	echo "export $shlibpath_var"
4323a3129944Smrg      fi
4324a3129944Smrg      $ECHO "$cmd$args"
4325a3129944Smrg      exit $EXIT_SUCCESS
4326a3129944Smrg    else
4327698f425bSmrg      if test -n "$shlibpath_var"; then
4328698f425bSmrg	# Export the shlibpath_var.
4329698f425bSmrg	eval "export $shlibpath_var"
4330698f425bSmrg      fi
4331266e564dSmrg
4332698f425bSmrg      # Restore saved environment variables
4333698f425bSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4334698f425bSmrg      do
4335698f425bSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4336698f425bSmrg                $lt_var=\$save_$lt_var; export $lt_var
4337266e564dSmrg	      else
4338698f425bSmrg		$lt_unset $lt_var
4339698f425bSmrg	      fi"
4340698f425bSmrg      done
4341266e564dSmrg
4342698f425bSmrg      # Now prepare to actually exec the command.
4343a3129944Smrg      exec_cmd=\$cmd$args
4344698f425bSmrg    fi
4345698f425bSmrg}
4346266e564dSmrg
4347a3129944Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
43489ef0b394Smrg
43499ef0b394Smrg
43509ef0b394Smrg# func_mode_finish arg...
43519ef0b394Smrgfunc_mode_finish ()
43529ef0b394Smrg{
4353a3129944Smrg    $debug_cmd
4354a3129944Smrg
43559ef0b394Smrg    libs=
43569ef0b394Smrg    libdirs=
43579ef0b394Smrg    admincmds=
43589ef0b394Smrg
43599ef0b394Smrg    for opt in "$nonopt" ${1+"$@"}
43609ef0b394Smrg    do
43619ef0b394Smrg      if test -d "$opt"; then
43629ef0b394Smrg	func_append libdirs " $opt"
43639ef0b394Smrg
43649ef0b394Smrg      elif test -f "$opt"; then
43659ef0b394Smrg	if func_lalib_unsafe_p "$opt"; then
43669ef0b394Smrg	  func_append libs " $opt"
43679ef0b394Smrg	else
4368a3129944Smrg	  func_warning "'$opt' is not a valid libtool archive"
43699ef0b394Smrg	fi
43709ef0b394Smrg
43719ef0b394Smrg      else
4372a3129944Smrg	func_fatal_error "invalid argument '$opt'"
43739ef0b394Smrg      fi
43749ef0b394Smrg    done
4375266e564dSmrg
43769ef0b394Smrg    if test -n "$libs"; then
43779ef0b394Smrg      if test -n "$lt_sysroot"; then
43789ef0b394Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
43799ef0b394Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
43809ef0b394Smrg      else
43819ef0b394Smrg        sysroot_cmd=
43829ef0b394Smrg      fi
4383266e564dSmrg
43849ef0b394Smrg      # Remove sysroot references
43859ef0b394Smrg      if $opt_dry_run; then
43869ef0b394Smrg        for lib in $libs; do
4387a3129944Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
43889ef0b394Smrg        done
43899ef0b394Smrg      else
43909ef0b394Smrg        tmpdir=`func_mktempdir`
43919ef0b394Smrg        for lib in $libs; do
4392a3129944Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
43939ef0b394Smrg	    > $tmpdir/tmp-la
43949ef0b394Smrg	  mv -f $tmpdir/tmp-la $lib
43959ef0b394Smrg	done
43969ef0b394Smrg        ${RM}r "$tmpdir"
43979ef0b394Smrg      fi
43989ef0b394Smrg    fi
4399266e564dSmrg
44003bf3b463Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs" && $opt_finishing; then
4401698f425bSmrg      for libdir in $libdirs; do
4402698f425bSmrg	if test -n "$finish_cmds"; then
4403698f425bSmrg	  # Do each command in the finish commands.
4404698f425bSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4405698f425bSmrg'"$cmd"'"'
4406266e564dSmrg	fi
4407698f425bSmrg	if test -n "$finish_eval"; then
4408698f425bSmrg	  # Do the single finish_eval.
4409698f425bSmrg	  eval cmds=\"$finish_eval\"
44109ef0b394Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4411698f425bSmrg       $cmds"
4412698f425bSmrg	fi
4413698f425bSmrg      done
4414698f425bSmrg    fi
4415266e564dSmrg
4416698f425bSmrg    # Exit here if they wanted silent mode.
4417a3129944Smrg    $opt_quiet && exit $EXIT_SUCCESS
4418266e564dSmrg
44199ef0b394Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
44209ef0b394Smrg      echo "----------------------------------------------------------------------"
44219ef0b394Smrg      echo "Libraries have been installed in:"
44229ef0b394Smrg      for libdir in $libdirs; do
44239ef0b394Smrg	$ECHO "   $libdir"
44249ef0b394Smrg      done
44253bf3b463Smrg      if test "false" = "$opt_finishing"; then
44263bf3b463Smrg        echo
44273bf3b463Smrg        echo "NOTE: finish_cmds were not executed during testing, so you must"
44283bf3b463Smrg        echo "manually run ldconfig to add a given test directory, LIBDIR, to"
44293bf3b463Smrg        echo "the search path for generated executables."
44303bf3b463Smrg      fi
44319ef0b394Smrg      echo
44329ef0b394Smrg      echo "If you ever happen to want to link against installed libraries"
44339ef0b394Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4434a3129944Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
44359ef0b394Smrg      echo "flag during linking and do at least one of the following:"
44369ef0b394Smrg      if test -n "$shlibpath_var"; then
4437a3129944Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
44389ef0b394Smrg	echo "     during execution"
44399ef0b394Smrg      fi
44409ef0b394Smrg      if test -n "$runpath_var"; then
4441a3129944Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
44429ef0b394Smrg	echo "     during linking"
44439ef0b394Smrg      fi
44449ef0b394Smrg      if test -n "$hardcode_libdir_flag_spec"; then
44459ef0b394Smrg	libdir=LIBDIR
44469ef0b394Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4447266e564dSmrg
4448a3129944Smrg	$ECHO "   - use the '$flag' linker flag"
44499ef0b394Smrg      fi
44509ef0b394Smrg      if test -n "$admincmds"; then
44519ef0b394Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
44529ef0b394Smrg      fi
44539ef0b394Smrg      if test -f /etc/ld.so.conf; then
4454a3129944Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
44559ef0b394Smrg      fi
44569ef0b394Smrg      echo
4457698f425bSmrg
44589ef0b394Smrg      echo "See any operating system documentation about shared libraries for"
44599ef0b394Smrg      case $host in
44609ef0b394Smrg	solaris2.[6789]|solaris2.1[0-9])
44619ef0b394Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
44629ef0b394Smrg	  echo "pages."
44639ef0b394Smrg	  ;;
44649ef0b394Smrg	*)
44659ef0b394Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
44669ef0b394Smrg	  ;;
44679ef0b394Smrg      esac
44689ef0b394Smrg      echo "----------------------------------------------------------------------"
44699ef0b394Smrg    fi
4470698f425bSmrg    exit $EXIT_SUCCESS
4471698f425bSmrg}
4472266e564dSmrg
4473a3129944Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4474266e564dSmrg
4475c5629e66Smrg
4476698f425bSmrg# func_mode_install arg...
4477698f425bSmrgfunc_mode_install ()
4478698f425bSmrg{
4479a3129944Smrg    $debug_cmd
4480a3129944Smrg
4481698f425bSmrg    # There may be an optional sh(1) argument at the beginning of
4482698f425bSmrg    # install_prog (especially on Windows NT).
4483a3129944Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4484698f425bSmrg       # Allow the use of GNU shtool's install command.
4485a3129944Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4486a3129944Smrg    then
4487698f425bSmrg      # Aesthetically quote it.
44881009a292Smrg      func_quote_arg pretty "$nonopt"
44891009a292Smrg      install_prog="$func_quote_arg_result "
4490698f425bSmrg      arg=$1
4491698f425bSmrg      shift
4492698f425bSmrg    else
4493698f425bSmrg      install_prog=
4494698f425bSmrg      arg=$nonopt
4495266e564dSmrg    fi
4496266e564dSmrg
4497698f425bSmrg    # The real first argument should be the name of the installation program.
4498698f425bSmrg    # Aesthetically quote it.
44991009a292Smrg    func_quote_arg pretty "$arg"
45001009a292Smrg    func_append install_prog "$func_quote_arg_result"
45019ef0b394Smrg    install_shared_prog=$install_prog
45029ef0b394Smrg    case " $install_prog " in
45039ef0b394Smrg      *[\\\ /]cp\ *) install_cp=: ;;
45049ef0b394Smrg      *) install_cp=false ;;
45059ef0b394Smrg    esac
4506266e564dSmrg
4507698f425bSmrg    # We need to accept at least all the BSD install flags.
4508698f425bSmrg    dest=
4509698f425bSmrg    files=
4510698f425bSmrg    opts=
4511698f425bSmrg    prev=
4512698f425bSmrg    install_type=
4513a3129944Smrg    isdir=false
4514698f425bSmrg    stripme=
45159ef0b394Smrg    no_mode=:
4516698f425bSmrg    for arg
4517698f425bSmrg    do
45189ef0b394Smrg      arg2=
4519698f425bSmrg      if test -n "$dest"; then
45209ef0b394Smrg	func_append files " $dest"
4521698f425bSmrg	dest=$arg
4522698f425bSmrg	continue
4523698f425bSmrg      fi
4524266e564dSmrg
4525698f425bSmrg      case $arg in
4526a3129944Smrg      -d) isdir=: ;;
4527698f425bSmrg      -f)
45289ef0b394Smrg	if $install_cp; then :; else
45299ef0b394Smrg	  prev=$arg
45309ef0b394Smrg	fi
4531698f425bSmrg	;;
4532698f425bSmrg      -g | -m | -o)
4533698f425bSmrg	prev=$arg
4534698f425bSmrg	;;
4535698f425bSmrg      -s)
4536698f425bSmrg	stripme=" -s"
4537698f425bSmrg	continue
4538698f425bSmrg	;;
4539698f425bSmrg      -*)
4540698f425bSmrg	;;
4541698f425bSmrg      *)
4542698f425bSmrg	# If the previous option needed an argument, then skip it.
4543698f425bSmrg	if test -n "$prev"; then
4544a3129944Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
45459ef0b394Smrg	    arg2=$install_override_mode
45469ef0b394Smrg	    no_mode=false
45479ef0b394Smrg	  fi
4548698f425bSmrg	  prev=
4549698f425bSmrg	else
4550698f425bSmrg	  dest=$arg
4551698f425bSmrg	  continue
4552698f425bSmrg	fi
4553698f425bSmrg	;;
4554698f425bSmrg      esac
4555266e564dSmrg
4556698f425bSmrg      # Aesthetically quote the argument.
45571009a292Smrg      func_quote_arg pretty "$arg"
45581009a292Smrg      func_append install_prog " $func_quote_arg_result"
45599ef0b394Smrg      if test -n "$arg2"; then
45601009a292Smrg	func_quote_arg pretty "$arg2"
45619ef0b394Smrg      fi
45621009a292Smrg      func_append install_shared_prog " $func_quote_arg_result"
4563698f425bSmrg    done
4564698f425bSmrg
4565698f425bSmrg    test -z "$install_prog" && \
4566698f425bSmrg      func_fatal_help "you must specify an install program"
4567698f425bSmrg
4568698f425bSmrg    test -n "$prev" && \
4569a3129944Smrg      func_fatal_help "the '$prev' option requires an argument"
4570698f425bSmrg
45719ef0b394Smrg    if test -n "$install_override_mode" && $no_mode; then
45729ef0b394Smrg      if $install_cp; then :; else
45731009a292Smrg	func_quote_arg pretty "$install_override_mode"
45741009a292Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
45759ef0b394Smrg      fi
45769ef0b394Smrg    fi
45779ef0b394Smrg
4578698f425bSmrg    if test -z "$files"; then
4579698f425bSmrg      if test -z "$dest"; then
4580698f425bSmrg	func_fatal_help "no file or destination specified"
4581698f425bSmrg      else
4582698f425bSmrg	func_fatal_help "you must specify a destination"
4583266e564dSmrg      fi
4584266e564dSmrg    fi
4585266e564dSmrg
4586698f425bSmrg    # Strip any trailing slash from the destination.
4587698f425bSmrg    func_stripname '' '/' "$dest"
4588698f425bSmrg    dest=$func_stripname_result
4589266e564dSmrg
4590698f425bSmrg    # Check to see that the destination is a directory.
4591a3129944Smrg    test -d "$dest" && isdir=:
4592a3129944Smrg    if $isdir; then
4593a3129944Smrg      destdir=$dest
4594698f425bSmrg      destname=
4595698f425bSmrg    else
4596698f425bSmrg      func_dirname_and_basename "$dest" "" "."
4597a3129944Smrg      destdir=$func_dirname_result
4598a3129944Smrg      destname=$func_basename_result
4599698f425bSmrg
4600698f425bSmrg      # Not a directory, so check to see that there is only one file specified.
4601698f425bSmrg      set dummy $files; shift
4602698f425bSmrg      test "$#" -gt 1 && \
4603a3129944Smrg	func_fatal_help "'$dest' is not a directory"
4604698f425bSmrg    fi
4605698f425bSmrg    case $destdir in
4606698f425bSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4607266e564dSmrg    *)
4608698f425bSmrg      for file in $files; do
4609698f425bSmrg	case $file in
4610698f425bSmrg	*.lo) ;;
4611698f425bSmrg	*)
4612a3129944Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4613698f425bSmrg	  ;;
4614698f425bSmrg	esac
4615698f425bSmrg      done
4616266e564dSmrg      ;;
4617266e564dSmrg    esac
4618266e564dSmrg
4619698f425bSmrg    # This variable tells wrapper scripts just to set variables rather
4620698f425bSmrg    # than running their programs.
4621a3129944Smrg    libtool_install_magic=$magic
4622266e564dSmrg
4623698f425bSmrg    staticlibs=
4624698f425bSmrg    future_libdirs=
4625698f425bSmrg    current_libdirs=
4626698f425bSmrg    for file in $files; do
4627266e564dSmrg
4628698f425bSmrg      # Do each installation.
4629698f425bSmrg      case $file in
4630698f425bSmrg      *.$libext)
4631698f425bSmrg	# Do the static libraries later.
46329ef0b394Smrg	func_append staticlibs " $file"
4633698f425bSmrg	;;
4634698f425bSmrg
4635698f425bSmrg      *.la)
46369ef0b394Smrg	func_resolve_sysroot "$file"
46379ef0b394Smrg	file=$func_resolve_sysroot_result
46389ef0b394Smrg
4639698f425bSmrg	# Check to see that this really is a libtool archive.
4640698f425bSmrg	func_lalib_unsafe_p "$file" \
4641a3129944Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4642698f425bSmrg
4643698f425bSmrg	library_names=
4644698f425bSmrg	old_library=
4645698f425bSmrg	relink_command=
4646698f425bSmrg	func_source "$file"
4647698f425bSmrg
4648698f425bSmrg	# Add the libdir to current_libdirs if it is the destination.
4649698f425bSmrg	if test "X$destdir" = "X$libdir"; then
4650698f425bSmrg	  case "$current_libdirs " in
4651698f425bSmrg	  *" $libdir "*) ;;
46529ef0b394Smrg	  *) func_append current_libdirs " $libdir" ;;
4653266e564dSmrg	  esac
4654698f425bSmrg	else
4655698f425bSmrg	  # Note the libdir as a future libdir.
4656698f425bSmrg	  case "$future_libdirs " in
4657698f425bSmrg	  *" $libdir "*) ;;
46589ef0b394Smrg	  *) func_append future_libdirs " $libdir" ;;
4659698f425bSmrg	  esac
4660698f425bSmrg	fi
4661266e564dSmrg
4662698f425bSmrg	func_dirname "$file" "/" ""
4663a3129944Smrg	dir=$func_dirname_result
46649ef0b394Smrg	func_append dir "$objdir"
4665698f425bSmrg
4666698f425bSmrg	if test -n "$relink_command"; then
46673bf3b463Smrg	  # Strip any trailing slash from the destination.
46683bf3b463Smrg	  func_stripname '' '/' "$libdir"
46693bf3b463Smrg	  destlibdir=$func_stripname_result
46703bf3b463Smrg
46713bf3b463Smrg	  func_stripname '' '/' "$destdir"
46723bf3b463Smrg	  s_destdir=$func_stripname_result
46733bf3b463Smrg
4674698f425bSmrg	  # Determine the prefix the user has applied to our future dir.
46753bf3b463Smrg	  inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"`
4676698f425bSmrg
4677698f425bSmrg	  # Don't allow the user to place us outside of our expected
4678698f425bSmrg	  # location b/c this prevents finding dependent libraries that
4679698f425bSmrg	  # are installed to the same prefix.
4680698f425bSmrg	  # At present, this check doesn't affect windows .dll's that
4681698f425bSmrg	  # are installed into $libdir/../bin (currently, that works fine)
4682698f425bSmrg	  # but it's something to keep an eye on.
4683698f425bSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4684a3129944Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4685698f425bSmrg
4686698f425bSmrg	  if test -n "$inst_prefix_dir"; then
4687698f425bSmrg	    # Stick the inst_prefix_dir data into the link command.
46889ef0b394Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4689698f425bSmrg	  else
46909ef0b394Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4691698f425bSmrg	  fi
4692698f425bSmrg
4693a3129944Smrg	  func_warning "relinking '$file'"
4694698f425bSmrg	  func_show_eval "$relink_command" \
4695a3129944Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4696698f425bSmrg	fi
4697698f425bSmrg
4698698f425bSmrg	# See the names of the shared library.
4699698f425bSmrg	set dummy $library_names; shift
4700698f425bSmrg	if test -n "$1"; then
4701a3129944Smrg	  realname=$1
4702698f425bSmrg	  shift
4703698f425bSmrg
4704a3129944Smrg	  srcname=$realname
4705a3129944Smrg	  test -n "$relink_command" && srcname=${realname}T
4706698f425bSmrg
4707698f425bSmrg	  # Install the shared library and build the symlinks.
47089ef0b394Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4709698f425bSmrg	      'exit $?'
4710a3129944Smrg	  tstripme=$stripme
4711698f425bSmrg	  case $host_os in
47123bf3b463Smrg	  cygwin* | mingw* | windows* | pw32* | cegcc*)
4713698f425bSmrg	    case $realname in
4714698f425bSmrg	    *.dll.a)
4715a3129944Smrg	      tstripme=
4716a3129944Smrg	      ;;
4717a3129944Smrg	    esac
4718a3129944Smrg	    ;;
4719a3129944Smrg	  os2*)
4720a3129944Smrg	    case $realname in
4721a3129944Smrg	    *_dll.a)
4722a3129944Smrg	      tstripme=
4723698f425bSmrg	      ;;
4724698f425bSmrg	    esac
4725266e564dSmrg	    ;;
4726266e564dSmrg	  esac
4727698f425bSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
4728698f425bSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4729c5629e66Smrg	  fi
4730698f425bSmrg
4731698f425bSmrg	  if test "$#" -gt 0; then
4732698f425bSmrg	    # Delete the old symlinks, and create new ones.
4733a3129944Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4734698f425bSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4735698f425bSmrg	    # so we also need to try rm && ln -s.
4736698f425bSmrg	    for linkname
4737698f425bSmrg	    do
4738698f425bSmrg	      test "$linkname" != "$realname" \
4739698f425bSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4740266e564dSmrg	    done
4741266e564dSmrg	  fi
4742266e564dSmrg
4743698f425bSmrg	  # Do each command in the postinstall commands.
4744a3129944Smrg	  lib=$destdir/$realname
4745698f425bSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4746266e564dSmrg	fi
4747266e564dSmrg
4748698f425bSmrg	# Install the pseudo-library for information purposes.
4749698f425bSmrg	func_basename "$file"
4750a3129944Smrg	name=$func_basename_result
4751a3129944Smrg	instname=$dir/${name}i
4752698f425bSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4753266e564dSmrg
4754698f425bSmrg	# Maybe install the static library, too.
47559ef0b394Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4756698f425bSmrg	;;
4757266e564dSmrg
4758698f425bSmrg      *.lo)
4759698f425bSmrg	# Install (i.e. copy) a libtool object.
4760266e564dSmrg
4761698f425bSmrg	# Figure out destination file name, if it wasn't already specified.
4762698f425bSmrg	if test -n "$destname"; then
4763a3129944Smrg	  destfile=$destdir/$destname
4764698f425bSmrg	else
4765698f425bSmrg	  func_basename "$file"
4766a3129944Smrg	  destfile=$func_basename_result
4767a3129944Smrg	  destfile=$destdir/$destfile
4768698f425bSmrg	fi
4769698f425bSmrg
4770698f425bSmrg	# Deduce the name of the destination old-style object file.
4771698f425bSmrg	case $destfile in
4772698f425bSmrg	*.lo)
4773698f425bSmrg	  func_lo2o "$destfile"
4774698f425bSmrg	  staticdest=$func_lo2o_result
4775698f425bSmrg	  ;;
4776698f425bSmrg	*.$objext)
4777a3129944Smrg	  staticdest=$destfile
4778698f425bSmrg	  destfile=
4779698f425bSmrg	  ;;
4780698f425bSmrg	*)
4781a3129944Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4782698f425bSmrg	  ;;
4783266e564dSmrg	esac
4784266e564dSmrg
4785698f425bSmrg	# Install the libtool object if requested.
4786698f425bSmrg	test -n "$destfile" && \
4787698f425bSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4788698f425bSmrg
4789698f425bSmrg	# Install the old object if enabled.
4790a3129944Smrg	if test yes = "$build_old_libs"; then
4791698f425bSmrg	  # Deduce the name of the old-style object file.
4792698f425bSmrg	  func_lo2o "$file"
4793698f425bSmrg	  staticobj=$func_lo2o_result
4794698f425bSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4795266e564dSmrg	fi
4796698f425bSmrg	exit $EXIT_SUCCESS
4797698f425bSmrg	;;
4798266e564dSmrg
4799698f425bSmrg      *)
4800698f425bSmrg	# Figure out destination file name, if it wasn't already specified.
4801698f425bSmrg	if test -n "$destname"; then
4802a3129944Smrg	  destfile=$destdir/$destname
4803698f425bSmrg	else
4804698f425bSmrg	  func_basename "$file"
4805a3129944Smrg	  destfile=$func_basename_result
4806a3129944Smrg	  destfile=$destdir/$destfile
4807698f425bSmrg	fi
4808266e564dSmrg
4809698f425bSmrg	# If the file is missing, and there is a .exe on the end, strip it
4810698f425bSmrg	# because it is most likely a libtool script we actually want to
4811698f425bSmrg	# install
4812a3129944Smrg	stripped_ext=
4813698f425bSmrg	case $file in
4814698f425bSmrg	  *.exe)
4815698f425bSmrg	    if test ! -f "$file"; then
4816698f425bSmrg	      func_stripname '' '.exe' "$file"
4817698f425bSmrg	      file=$func_stripname_result
4818a3129944Smrg	      stripped_ext=.exe
4819698f425bSmrg	    fi
4820698f425bSmrg	    ;;
4821698f425bSmrg	esac
4822266e564dSmrg
4823698f425bSmrg	# Do a test to see if this is really a libtool program.
4824698f425bSmrg	case $host in
48253bf3b463Smrg	*cygwin* | *mingw* | *windows*)
4826698f425bSmrg	    if func_ltwrapper_executable_p "$file"; then
4827698f425bSmrg	      func_ltwrapper_scriptname "$file"
4828698f425bSmrg	      wrapper=$func_ltwrapper_scriptname_result
4829698f425bSmrg	    else
4830698f425bSmrg	      func_stripname '' '.exe' "$file"
4831698f425bSmrg	      wrapper=$func_stripname_result
4832698f425bSmrg	    fi
4833698f425bSmrg	    ;;
4834698f425bSmrg	*)
4835698f425bSmrg	    wrapper=$file
4836698f425bSmrg	    ;;
4837698f425bSmrg	esac
4838698f425bSmrg	if func_ltwrapper_script_p "$wrapper"; then
4839698f425bSmrg	  notinst_deplibs=
4840698f425bSmrg	  relink_command=
4841266e564dSmrg
4842698f425bSmrg	  func_source "$wrapper"
4843698f425bSmrg
4844698f425bSmrg	  # Check the variables that should have been set.
4845698f425bSmrg	  test -z "$generated_by_libtool_version" && \
4846a3129944Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4847698f425bSmrg
4848a3129944Smrg	  finalize=:
4849698f425bSmrg	  for lib in $notinst_deplibs; do
4850698f425bSmrg	    # Check to see that each library is installed.
4851698f425bSmrg	    libdir=
4852698f425bSmrg	    if test -f "$lib"; then
4853698f425bSmrg	      func_source "$lib"
4854698f425bSmrg	    fi
4855a3129944Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4856698f425bSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4857a3129944Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4858a3129944Smrg	      finalize=false
4859698f425bSmrg	    fi
4860698f425bSmrg	  done
4861698f425bSmrg
4862698f425bSmrg	  relink_command=
4863698f425bSmrg	  func_source "$wrapper"
4864698f425bSmrg
4865698f425bSmrg	  outputname=
4866a3129944Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4867698f425bSmrg	    $opt_dry_run || {
4868a3129944Smrg	      if $finalize; then
4869698f425bSmrg	        tmpdir=`func_mktempdir`
4870698f425bSmrg		func_basename "$file$stripped_ext"
4871a3129944Smrg		file=$func_basename_result
4872a3129944Smrg	        outputname=$tmpdir/$file
4873698f425bSmrg	        # Replace the output file specification.
48749ef0b394Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4875698f425bSmrg
4876a3129944Smrg	        $opt_quiet || {
48771009a292Smrg	          func_quote_arg expand,pretty "$relink_command"
48781009a292Smrg		  eval "func_echo $func_quote_arg_result"
4879698f425bSmrg	        }
4880698f425bSmrg	        if eval "$relink_command"; then :
4881698f425bSmrg	          else
4882a3129944Smrg		  func_error "error: relink '$file' with the above command before installing it"
4883698f425bSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
4884698f425bSmrg		  continue
4885698f425bSmrg	        fi
4886a3129944Smrg	        file=$outputname
4887698f425bSmrg	      else
4888a3129944Smrg	        func_warning "cannot relink '$file'"
4889698f425bSmrg	      fi
4890698f425bSmrg	    }
4891266e564dSmrg	  else
4892698f425bSmrg	    # Install the binary that we compiled earlier.
48939ef0b394Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4894266e564dSmrg	  fi
4895698f425bSmrg	fi
4896266e564dSmrg
4897698f425bSmrg	# remove .exe since cygwin /usr/bin/install will append another
4898698f425bSmrg	# one anyway
4899698f425bSmrg	case $install_prog,$host in
4900698f425bSmrg	*/usr/bin/install*,*cygwin*)
4901698f425bSmrg	  case $file:$destfile in
4902698f425bSmrg	  *.exe:*.exe)
4903698f425bSmrg	    # this is ok
4904698f425bSmrg	    ;;
4905698f425bSmrg	  *.exe:*)
4906698f425bSmrg	    destfile=$destfile.exe
4907698f425bSmrg	    ;;
4908698f425bSmrg	  *:*.exe)
4909698f425bSmrg	    func_stripname '' '.exe' "$destfile"
4910698f425bSmrg	    destfile=$func_stripname_result
4911698f425bSmrg	    ;;
4912698f425bSmrg	  esac
4913266e564dSmrg	  ;;
4914266e564dSmrg	esac
4915698f425bSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4916698f425bSmrg	$opt_dry_run || if test -n "$outputname"; then
4917698f425bSmrg	  ${RM}r "$tmpdir"
4918698f425bSmrg	fi
4919698f425bSmrg	;;
4920698f425bSmrg      esac
4921698f425bSmrg    done
4922266e564dSmrg
4923698f425bSmrg    for file in $staticlibs; do
4924698f425bSmrg      func_basename "$file"
4925a3129944Smrg      name=$func_basename_result
4926698f425bSmrg
4927698f425bSmrg      # Set up the ranlib parameters.
4928a3129944Smrg      oldlib=$destdir/$name
4929fb5e8d76Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4930fb5e8d76Smrg      tool_oldlib=$func_to_tool_file_result
4931698f425bSmrg
4932698f425bSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4933698f425bSmrg
4934698f425bSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4935fb5e8d76Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4936698f425bSmrg      fi
4937698f425bSmrg
4938698f425bSmrg      # Do each command in the postinstall commands.
4939698f425bSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4940698f425bSmrg    done
4941698f425bSmrg
4942698f425bSmrg    test -n "$future_libdirs" && \
4943a3129944Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4944698f425bSmrg
4945698f425bSmrg    if test -n "$current_libdirs"; then
4946698f425bSmrg      # Maybe just do a dry run.
4947698f425bSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4948a3129944Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4949698f425bSmrg    else
4950698f425bSmrg      exit $EXIT_SUCCESS
4951698f425bSmrg    fi
4952698f425bSmrg}
4953698f425bSmrg
4954a3129944Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4955698f425bSmrg
4956698f425bSmrg
4957698f425bSmrg# func_generate_dlsyms outputname originator pic_p
4958698f425bSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4959698f425bSmrg# a dlpreopen symbol table.
4960698f425bSmrgfunc_generate_dlsyms ()
4961698f425bSmrg{
4962a3129944Smrg    $debug_cmd
4963a3129944Smrg
4964a3129944Smrg    my_outputname=$1
4965a3129944Smrg    my_originator=$2
4966a3129944Smrg    my_pic_p=${3-false}
4967a3129944Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4968698f425bSmrg    my_dlsyms=
4969698f425bSmrg
4970a3129944Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4971698f425bSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4972a3129944Smrg	my_dlsyms=${my_outputname}S.c
4973698f425bSmrg      else
4974698f425bSmrg	func_error "not configured to extract global symbols from dlpreopened files"
4975698f425bSmrg      fi
4976698f425bSmrg    fi
4977698f425bSmrg
4978698f425bSmrg    if test -n "$my_dlsyms"; then
4979698f425bSmrg      case $my_dlsyms in
4980698f425bSmrg      "") ;;
4981698f425bSmrg      *.c)
4982698f425bSmrg	# Discover the nlist of each of the dlfiles.
4983a3129944Smrg	nlist=$output_objdir/$my_outputname.nm
4984698f425bSmrg
4985698f425bSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4986698f425bSmrg
4987698f425bSmrg	# Parse the name list into a source file.
4988698f425bSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
4989698f425bSmrg
4990698f425bSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4991a3129944Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4992a3129944Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4993698f425bSmrg
4994698f425bSmrg#ifdef __cplusplus
4995698f425bSmrgextern \"C\" {
4996698f425bSmrg#endif
4997698f425bSmrg
4998a3129944Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
49999ef0b394Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
50009ef0b394Smrg#endif
50019ef0b394Smrg
50029ef0b394Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
5003a3129944Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
5004a3129944Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
50059ef0b394Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
50069ef0b394Smrg# define LT_DLSYM_CONST
5007a3129944Smrg#elif defined __osf__
50089ef0b394Smrg/* This system does not cope well with relocations in const data.  */
50099ef0b394Smrg# define LT_DLSYM_CONST
50109ef0b394Smrg#else
50119ef0b394Smrg# define LT_DLSYM_CONST const
50129ef0b394Smrg#endif
50139ef0b394Smrg
5014a3129944Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5015a3129944Smrg
5016698f425bSmrg/* External symbol declarations for the compiler. */\
5017698f425bSmrg"
5018698f425bSmrg
5019a3129944Smrg	if test yes = "$dlself"; then
5020a3129944Smrg	  func_verbose "generating symbol list for '$output'"
5021698f425bSmrg
5022698f425bSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
5023698f425bSmrg
5024698f425bSmrg	  # Add our own program objects to the symbol list.
50259ef0b394Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
5026698f425bSmrg	  for progfile in $progfiles; do
50279ef0b394Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
5028a3129944Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
50299ef0b394Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
5030698f425bSmrg	  done
5031698f425bSmrg
5032698f425bSmrg	  if test -n "$exclude_expsyms"; then
5033698f425bSmrg	    $opt_dry_run || {
5034698f425bSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
5035698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
5036698f425bSmrg	    }
5037266e564dSmrg	  fi
5038698f425bSmrg
5039698f425bSmrg	  if test -n "$export_symbols_regex"; then
5040698f425bSmrg	    $opt_dry_run || {
5041698f425bSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
5042698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
5043698f425bSmrg	    }
5044698f425bSmrg	  fi
5045698f425bSmrg
5046698f425bSmrg	  # Prepare the list of exported symbols
5047698f425bSmrg	  if test -z "$export_symbols"; then
5048a3129944Smrg	    export_symbols=$output_objdir/$outputname.exp
5049698f425bSmrg	    $opt_dry_run || {
5050698f425bSmrg	      $RM $export_symbols
5051a3129944Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
5052698f425bSmrg	      case $host in
50533bf3b463Smrg	      *cygwin* | *mingw* | *windows* | *cegcc* )
5054698f425bSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5055698f425bSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
5056698f425bSmrg	        ;;
5057698f425bSmrg	      esac
5058698f425bSmrg	    }
5059266e564dSmrg	  else
5060698f425bSmrg	    $opt_dry_run || {
5061a3129944Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
5062698f425bSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
5063698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
5064698f425bSmrg	      case $host in
50653bf3b463Smrg	        *cygwin* | *mingw* | *windows* | *cegcc* )
5066698f425bSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5067698f425bSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
5068698f425bSmrg	          ;;
5069698f425bSmrg	      esac
5070698f425bSmrg	    }
5071266e564dSmrg	  fi
5072698f425bSmrg	fi
5073266e564dSmrg
5074698f425bSmrg	for dlprefile in $dlprefiles; do
5075a3129944Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
5076698f425bSmrg	  func_basename "$dlprefile"
5077a3129944Smrg	  name=$func_basename_result
50789ef0b394Smrg          case $host in
50793bf3b463Smrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
50809ef0b394Smrg	      # if an import library, we need to obtain dlname
50819ef0b394Smrg	      if func_win32_import_lib_p "$dlprefile"; then
50829ef0b394Smrg	        func_tr_sh "$dlprefile"
50839ef0b394Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
5084a3129944Smrg	        dlprefile_dlbasename=
50859ef0b394Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
50869ef0b394Smrg	          # Use subshell, to avoid clobbering current variable values
50879ef0b394Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
5088a3129944Smrg	          if test -n "$dlprefile_dlname"; then
50899ef0b394Smrg	            func_basename "$dlprefile_dlname"
5090a3129944Smrg	            dlprefile_dlbasename=$func_basename_result
50919ef0b394Smrg	          else
50929ef0b394Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
50939ef0b394Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
50949ef0b394Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
50959ef0b394Smrg	          fi
50969ef0b394Smrg	        fi
50979ef0b394Smrg	        $opt_dry_run || {
5098a3129944Smrg	          if test -n "$dlprefile_dlbasename"; then
50999ef0b394Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
51009ef0b394Smrg	          else
51019ef0b394Smrg	            func_warning "Could not compute DLL name from $name"
51029ef0b394Smrg	            eval '$ECHO ": $name " >> "$nlist"'
51039ef0b394Smrg	          fi
51049ef0b394Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51053bf3b463Smrg	          case $host in
51063bf3b463Smrg	            i[3456]86-*-mingw32*)
51073bf3b463Smrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51083bf3b463Smrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
51093bf3b463Smrg	            ;;
51103bf3b463Smrg	            *)
51113bf3b463Smrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51123bf3b463Smrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'"
51133bf3b463Smrg	            ;;
51143bf3b463Smrg	          esac
51159ef0b394Smrg	        }
51169ef0b394Smrg	      else # not an import lib
51179ef0b394Smrg	        $opt_dry_run || {
51189ef0b394Smrg	          eval '$ECHO ": $name " >> "$nlist"'
51199ef0b394Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51209ef0b394Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
51219ef0b394Smrg	        }
51229ef0b394Smrg	      fi
51239ef0b394Smrg	    ;;
51249ef0b394Smrg	    *)
51259ef0b394Smrg	      $opt_dry_run || {
51269ef0b394Smrg	        eval '$ECHO ": $name " >> "$nlist"'
51279ef0b394Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51289ef0b394Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
51299ef0b394Smrg	      }
51309ef0b394Smrg	    ;;
51319ef0b394Smrg          esac
5132698f425bSmrg	done
5133698f425bSmrg
5134698f425bSmrg	$opt_dry_run || {
5135698f425bSmrg	  # Make sure we have at least an empty file.
5136698f425bSmrg	  test -f "$nlist" || : > "$nlist"
5137698f425bSmrg
5138698f425bSmrg	  if test -n "$exclude_expsyms"; then
5139698f425bSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
5140698f425bSmrg	    $MV "$nlist"T "$nlist"
5141266e564dSmrg	  fi
5142698f425bSmrg
5143698f425bSmrg	  # Try sorting and uniquifying the output.
5144698f425bSmrg	  if $GREP -v "^: " < "$nlist" |
5145698f425bSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
5146698f425bSmrg		sort -k 3
5147698f425bSmrg	      else
5148698f425bSmrg		sort +2
5149698f425bSmrg	      fi |
5150698f425bSmrg	      uniq > "$nlist"S; then
5151698f425bSmrg	    :
5152266e564dSmrg	  else
5153698f425bSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5154266e564dSmrg	  fi
5155266e564dSmrg
5156698f425bSmrg	  if test -f "$nlist"S; then
5157698f425bSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5158266e564dSmrg	  else
51599ef0b394Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5160266e564dSmrg	  fi
5161266e564dSmrg
5162a3129944Smrg	  func_show_eval '$RM "${nlist}I"'
5163a3129944Smrg	  if test -n "$global_symbol_to_import"; then
5164a3129944Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5165a3129944Smrg	  fi
5166a3129944Smrg
51679ef0b394Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5168266e564dSmrg
5169698f425bSmrg/* The mapping between symbol names and symbols.  */
5170698f425bSmrgtypedef struct {
5171698f425bSmrg  const char *name;
5172698f425bSmrg  void *address;
5173698f425bSmrg} lt_dlsymlist;
51749ef0b394Smrgextern LT_DLSYM_CONST lt_dlsymlist
5175a3129944Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5176a3129944Smrg"
5177a3129944Smrg
5178a3129944Smrg	  if test -s "$nlist"I; then
5179a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5180a3129944Smrgstatic void lt_syminit(void)
5181a3129944Smrg{
5182a3129944Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5183a3129944Smrg  for (; symbol->name; ++symbol)
5184a3129944Smrg    {"
5185a3129944Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5186a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5187a3129944Smrg    }
5188a3129944Smrg}"
5189a3129944Smrg	  fi
5190a3129944Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
51919ef0b394SmrgLT_DLSYM_CONST lt_dlsymlist
5192698f425bSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5193a3129944Smrg{ {\"$my_originator\", (void *) 0},"
5194a3129944Smrg
5195a3129944Smrg	  if test -s "$nlist"I; then
5196a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5197a3129944Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5198a3129944Smrg	  fi
5199266e564dSmrg
5200698f425bSmrg	  case $need_lib_prefix in
5201698f425bSmrg	  no)
5202698f425bSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5203698f425bSmrg	    ;;
5204698f425bSmrg	  *)
5205698f425bSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5206698f425bSmrg	    ;;
5207698f425bSmrg	  esac
52089ef0b394Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5209698f425bSmrg  {0, (void *) 0}
5210698f425bSmrg};
5211266e564dSmrg
5212698f425bSmrg/* This works around a problem in FreeBSD linker */
5213698f425bSmrg#ifdef FREEBSD_WORKAROUND
5214698f425bSmrgstatic const void *lt_preloaded_setup() {
5215698f425bSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5216698f425bSmrg}
5217698f425bSmrg#endif
5218698f425bSmrg
5219698f425bSmrg#ifdef __cplusplus
5220698f425bSmrg}
5221698f425bSmrg#endif\
5222698f425bSmrg"
5223698f425bSmrg	} # !$opt_dry_run
5224698f425bSmrg
5225698f425bSmrg	pic_flag_for_symtable=
5226698f425bSmrg	case "$compile_command " in
5227698f425bSmrg	*" -static "*) ;;
5228698f425bSmrg	*)
5229698f425bSmrg	  case $host in
5230698f425bSmrg	  # compiling the symbol table file with pic_flag works around
5231698f425bSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
5232698f425bSmrg	  # linked before any other PIC object.  But we must not use
5233698f425bSmrg	  # pic_flag when linking with -static.  The problem exists in
5234698f425bSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5235fb5e8d76Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5236698f425bSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5237698f425bSmrg	  *-*-hpux*)
5238698f425bSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5239698f425bSmrg	  *)
5240a3129944Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5241698f425bSmrg	    ;;
5242698f425bSmrg	  esac
5243698f425bSmrg	  ;;
5244698f425bSmrg	esac
5245698f425bSmrg	symtab_cflags=
5246698f425bSmrg	for arg in $LTCFLAGS; do
5247698f425bSmrg	  case $arg in
5248698f425bSmrg	  -pie | -fpie | -fPIE) ;;
52499ef0b394Smrg	  *) func_append symtab_cflags " $arg" ;;
5250698f425bSmrg	  esac
5251698f425bSmrg	done
5252266e564dSmrg
5253698f425bSmrg	# Now compile the dynamic symbol file.
5254698f425bSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5255266e564dSmrg
5256698f425bSmrg	# Clean up the generated files.
5257a3129944Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5258266e564dSmrg
5259698f425bSmrg	# Transform the symbol file into the correct name.
5260a3129944Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5261698f425bSmrg	case $host in
52623bf3b463Smrg	*cygwin* | *mingw* | *windows* | *cegcc* )
5263698f425bSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
52649ef0b394Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
52659ef0b394Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5266698f425bSmrg	  else
52679ef0b394Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
52689ef0b394Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5269266e564dSmrg	  fi
5270698f425bSmrg	  ;;
5271698f425bSmrg	*)
52729ef0b394Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
52739ef0b394Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5274698f425bSmrg	  ;;
5275698f425bSmrg	esac
5276698f425bSmrg	;;
5277698f425bSmrg      *)
5278a3129944Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5279698f425bSmrg	;;
5280698f425bSmrg      esac
5281698f425bSmrg    else
5282698f425bSmrg      # We keep going just in case the user didn't refer to
5283698f425bSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5284698f425bSmrg      # really was required.
5285266e564dSmrg
5286698f425bSmrg      # Nullify the symbol file.
52879ef0b394Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
52889ef0b394Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5289698f425bSmrg    fi
5290698f425bSmrg}
5291266e564dSmrg
5292a3129944Smrg# func_cygming_gnu_implib_p ARG
5293a3129944Smrg# This predicate returns with zero status (TRUE) if
5294a3129944Smrg# ARG is a GNU/binutils-style import library. Returns
5295a3129944Smrg# with nonzero status (FALSE) otherwise.
5296a3129944Smrgfunc_cygming_gnu_implib_p ()
5297a3129944Smrg{
5298a3129944Smrg  $debug_cmd
5299a3129944Smrg
5300a3129944Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5301a3129944Smrg  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)$'`
5302a3129944Smrg  test -n "$func_cygming_gnu_implib_tmp"
5303a3129944Smrg}
5304a3129944Smrg
5305a3129944Smrg# func_cygming_ms_implib_p ARG
5306a3129944Smrg# This predicate returns with zero status (TRUE) if
5307a3129944Smrg# ARG is an MS-style import library. Returns
5308a3129944Smrg# with nonzero status (FALSE) otherwise.
5309a3129944Smrgfunc_cygming_ms_implib_p ()
5310a3129944Smrg{
5311a3129944Smrg  $debug_cmd
5312a3129944Smrg
5313a3129944Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5314a3129944Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5315a3129944Smrg  test -n "$func_cygming_ms_implib_tmp"
5316a3129944Smrg}
5317a3129944Smrg
5318698f425bSmrg# func_win32_libid arg
5319698f425bSmrg# return the library type of file 'arg'
5320698f425bSmrg#
5321698f425bSmrg# Need a lot of goo to handle *both* DLLs and import libs
5322698f425bSmrg# Has to be a shell function in order to 'eat' the argument
5323698f425bSmrg# that is supplied when $file_magic_command is called.
53249ef0b394Smrg# Despite the name, also deal with 64 bit binaries.
5325698f425bSmrgfunc_win32_libid ()
5326698f425bSmrg{
5327a3129944Smrg  $debug_cmd
5328a3129944Smrg
5329a3129944Smrg  win32_libid_type=unknown
5330698f425bSmrg  win32_fileres=`file -L $1 2>/dev/null`
5331698f425bSmrg  case $win32_fileres in
5332698f425bSmrg  *ar\ archive\ import\ library*) # definitely import
5333698f425bSmrg    win32_libid_type="x86 archive import"
5334698f425bSmrg    ;;
5335698f425bSmrg  *ar\ archive*) # could be an import, or static
53369ef0b394Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5337698f425bSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
53383bf3b463Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then
5339a3129944Smrg      case $nm_interface in
5340a3129944Smrg      "MS dumpbin")
5341a3129944Smrg	if func_cygming_ms_implib_p "$1" ||
5342a3129944Smrg	   func_cygming_gnu_implib_p "$1"
5343a3129944Smrg	then
5344a3129944Smrg	  win32_nmres=import
5345a3129944Smrg	else
5346a3129944Smrg	  win32_nmres=
5347a3129944Smrg	fi
5348a3129944Smrg	;;
5349a3129944Smrg      *)
5350a3129944Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5351a3129944Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5352a3129944Smrg	  $SED -n -e '
5353698f425bSmrg	    1,100{
5354698f425bSmrg		/ I /{
5355a3129944Smrg		    s|.*|import|
5356698f425bSmrg		    p
5357698f425bSmrg		    q
5358698f425bSmrg		}
5359698f425bSmrg	    }'`
5360a3129944Smrg	;;
5361a3129944Smrg      esac
5362698f425bSmrg      case $win32_nmres in
5363698f425bSmrg      import*)  win32_libid_type="x86 archive import";;
5364698f425bSmrg      *)        win32_libid_type="x86 archive static";;
5365698f425bSmrg      esac
5366698f425bSmrg    fi
5367698f425bSmrg    ;;
5368698f425bSmrg  *DLL*)
5369698f425bSmrg    win32_libid_type="x86 DLL"
5370698f425bSmrg    ;;
5371698f425bSmrg  *executable*) # but shell scripts are "executable" too...
5372698f425bSmrg    case $win32_fileres in
5373698f425bSmrg    *MS\ Windows\ PE\ Intel*)
5374698f425bSmrg      win32_libid_type="x86 DLL"
5375698f425bSmrg      ;;
5376698f425bSmrg    esac
5377698f425bSmrg    ;;
5378698f425bSmrg  esac
5379698f425bSmrg  $ECHO "$win32_libid_type"
5380698f425bSmrg}
5381266e564dSmrg
53829ef0b394Smrg# func_cygming_dll_for_implib ARG
53839ef0b394Smrg#
53849ef0b394Smrg# Platform-specific function to extract the
53859ef0b394Smrg# name of the DLL associated with the specified
53869ef0b394Smrg# import library ARG.
53879ef0b394Smrg# Invoked by eval'ing the libtool variable
53889ef0b394Smrg#    $sharedlib_from_linklib_cmd
53899ef0b394Smrg# Result is available in the variable
53909ef0b394Smrg#    $sharedlib_from_linklib_result
53919ef0b394Smrgfunc_cygming_dll_for_implib ()
53929ef0b394Smrg{
5393a3129944Smrg  $debug_cmd
5394a3129944Smrg
53959ef0b394Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
53969ef0b394Smrg}
53979ef0b394Smrg
53989ef0b394Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
53999ef0b394Smrg#
54009ef0b394Smrg# The is the core of a fallback implementation of a
54019ef0b394Smrg# platform-specific function to extract the name of the
54029ef0b394Smrg# DLL associated with the specified import library LIBNAME.
54039ef0b394Smrg#
54049ef0b394Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
54059ef0b394Smrg# on the platform and compiler that created the implib.
54069ef0b394Smrg#
54079ef0b394Smrg# Echos the name of the DLL associated with the
54089ef0b394Smrg# specified import library.
54099ef0b394Smrgfunc_cygming_dll_for_implib_fallback_core ()
54109ef0b394Smrg{
5411a3129944Smrg  $debug_cmd
5412a3129944Smrg
54139ef0b394Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
54149ef0b394Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
54159ef0b394Smrg    $SED '/^Contents of section '"$match_literal"':/{
54169ef0b394Smrg      # Place marker at beginning of archive member dllname section
54179ef0b394Smrg      s/.*/====MARK====/
54189ef0b394Smrg      p
54199ef0b394Smrg      d
54209ef0b394Smrg    }
54219ef0b394Smrg    # These lines can sometimes be longer than 43 characters, but
54229ef0b394Smrg    # are always uninteresting
54239ef0b394Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
54249ef0b394Smrg    /^In archive [^:]*:/d
54259ef0b394Smrg    # Ensure marker is printed
54269ef0b394Smrg    /^====MARK====/p
54279ef0b394Smrg    # Remove all lines with less than 43 characters
54289ef0b394Smrg    /^.\{43\}/!d
54299ef0b394Smrg    # From remaining lines, remove first 43 characters
54309ef0b394Smrg    s/^.\{43\}//' |
54319ef0b394Smrg    $SED -n '
54329ef0b394Smrg      # Join marker and all lines until next marker into a single line
54339ef0b394Smrg      /^====MARK====/ b para
54349ef0b394Smrg      H
54359ef0b394Smrg      $ b para
54369ef0b394Smrg      b
54379ef0b394Smrg      :para
54389ef0b394Smrg      x
54399ef0b394Smrg      s/\n//g
54409ef0b394Smrg      # Remove the marker
54419ef0b394Smrg      s/^====MARK====//
54429ef0b394Smrg      # Remove trailing dots and whitespace
54439ef0b394Smrg      s/[\. \t]*$//
54449ef0b394Smrg      # Print
54459ef0b394Smrg      /./p' |
54469ef0b394Smrg    # we now have a list, one entry per line, of the stringified
54479ef0b394Smrg    # contents of the appropriate section of all members of the
5448a3129944Smrg    # archive that possess that section. Heuristic: eliminate
5449a3129944Smrg    # all those that have a first or second character that is
54509ef0b394Smrg    # a '.' (that is, objdump's representation of an unprintable
54519ef0b394Smrg    # character.) This should work for all archives with less than
54529ef0b394Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
54539ef0b394Smrg    # begins with a literal '.' or a single character followed by
54549ef0b394Smrg    # a '.'.
54559ef0b394Smrg    #
54569ef0b394Smrg    # Of those that remain, print the first one.
54579ef0b394Smrg    $SED -e '/^\./d;/^.\./d;q'
54589ef0b394Smrg}
54599ef0b394Smrg
54609ef0b394Smrg# func_cygming_dll_for_implib_fallback ARG
54619ef0b394Smrg# Platform-specific function to extract the
54629ef0b394Smrg# name of the DLL associated with the specified
54639ef0b394Smrg# import library ARG.
54649ef0b394Smrg#
54659ef0b394Smrg# This fallback implementation is for use when $DLLTOOL
54669ef0b394Smrg# does not support the --identify-strict option.
54679ef0b394Smrg# Invoked by eval'ing the libtool variable
54689ef0b394Smrg#    $sharedlib_from_linklib_cmd
54699ef0b394Smrg# Result is available in the variable
54709ef0b394Smrg#    $sharedlib_from_linklib_result
54719ef0b394Smrgfunc_cygming_dll_for_implib_fallback ()
54729ef0b394Smrg{
5473a3129944Smrg  $debug_cmd
5474a3129944Smrg
5475a3129944Smrg  if func_cygming_gnu_implib_p "$1"; then
54769ef0b394Smrg    # binutils import library
54779ef0b394Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5478a3129944Smrg  elif func_cygming_ms_implib_p "$1"; then
54799ef0b394Smrg    # ms-generated import library
54809ef0b394Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
54819ef0b394Smrg  else
54829ef0b394Smrg    # unknown
5483a3129944Smrg    sharedlib_from_linklib_result=
54849ef0b394Smrg  fi
54859ef0b394Smrg}
5486266e564dSmrg
5487266e564dSmrg
5488698f425bSmrg# func_extract_an_archive dir oldlib
5489698f425bSmrgfunc_extract_an_archive ()
5490698f425bSmrg{
5491a3129944Smrg    $debug_cmd
5492a3129944Smrg
5493a3129944Smrg    f_ex_an_ar_dir=$1; shift
5494a3129944Smrg    f_ex_an_ar_oldlib=$1
5495a3129944Smrg    if test yes = "$lock_old_archive_extraction"; then
54969ef0b394Smrg      lockfile=$f_ex_an_ar_oldlib.lock
54979ef0b394Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
54989ef0b394Smrg	func_echo "Waiting for $lockfile to be removed"
54999ef0b394Smrg	sleep 2
55009ef0b394Smrg      done
55019ef0b394Smrg    fi
55029ef0b394Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
55039ef0b394Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5504a3129944Smrg    if test yes = "$lock_old_archive_extraction"; then
55059ef0b394Smrg      $opt_dry_run || rm -f "$lockfile"
55069ef0b394Smrg    fi
5507698f425bSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5508698f425bSmrg     :
5509698f425bSmrg    else
5510698f425bSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5511698f425bSmrg    fi
5512698f425bSmrg}
5513266e564dSmrg
5514266e564dSmrg
5515698f425bSmrg# func_extract_archives gentop oldlib ...
5516698f425bSmrgfunc_extract_archives ()
5517698f425bSmrg{
5518a3129944Smrg    $debug_cmd
5519a3129944Smrg
5520a3129944Smrg    my_gentop=$1; shift
5521698f425bSmrg    my_oldlibs=${1+"$@"}
5522a3129944Smrg    my_oldobjs=
5523a3129944Smrg    my_xlib=
5524a3129944Smrg    my_xabs=
5525a3129944Smrg    my_xdir=
5526266e564dSmrg
5527698f425bSmrg    for my_xlib in $my_oldlibs; do
5528698f425bSmrg      # Extract the objects.
5529698f425bSmrg      case $my_xlib in
5530a3129944Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5531698f425bSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5532698f425bSmrg      esac
5533698f425bSmrg      func_basename "$my_xlib"
5534a3129944Smrg      my_xlib=$func_basename_result
5535698f425bSmrg      my_xlib_u=$my_xlib
5536698f425bSmrg      while :; do
5537698f425bSmrg        case " $extracted_archives " in
5538698f425bSmrg	*" $my_xlib_u "*)
5539698f425bSmrg	  func_arith $extracted_serial + 1
5540698f425bSmrg	  extracted_serial=$func_arith_result
5541698f425bSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5542698f425bSmrg	*) break ;;
5543698f425bSmrg	esac
5544698f425bSmrg      done
5545698f425bSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5546a3129944Smrg      my_xdir=$my_gentop/$my_xlib_u
5547266e564dSmrg
5548698f425bSmrg      func_mkdir_p "$my_xdir"
5549266e564dSmrg
5550698f425bSmrg      case $host in
5551698f425bSmrg      *-darwin*)
5552698f425bSmrg	func_verbose "Extracting $my_xabs"
5553698f425bSmrg	# Do not bother doing anything if just a dry run
5554698f425bSmrg	$opt_dry_run || {
5555698f425bSmrg	  darwin_orig_dir=`pwd`
5556698f425bSmrg	  cd $my_xdir || exit $?
5557698f425bSmrg	  darwin_archive=$my_xabs
5558698f425bSmrg	  darwin_curdir=`pwd`
5559a3129944Smrg	  func_basename "$darwin_archive"
5560a3129944Smrg	  darwin_base_archive=$func_basename_result
5561698f425bSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5562698f425bSmrg	  if test -n "$darwin_arches"; then
5563698f425bSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5564698f425bSmrg	    darwin_arch=
5565698f425bSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5566a3129944Smrg	    for darwin_arch in  $darwin_arches; do
5567a3129944Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5568a3129944Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5569a3129944Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5570a3129944Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5571698f425bSmrg	      cd "$darwin_curdir"
5572a3129944Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5573698f425bSmrg	    done # $darwin_arches
5574698f425bSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5575a3129944Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5576698f425bSmrg	    darwin_file=
5577698f425bSmrg	    darwin_files=
5578698f425bSmrg	    for darwin_file in $darwin_filelist; do
55799ef0b394Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5580698f425bSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
5581698f425bSmrg	    done # $darwin_filelist
5582698f425bSmrg	    $RM -rf unfat-$$
5583698f425bSmrg	    cd "$darwin_orig_dir"
5584266e564dSmrg	  else
5585698f425bSmrg	    cd $darwin_orig_dir
5586698f425bSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5587698f425bSmrg	  fi # $darwin_arches
5588698f425bSmrg	} # !$opt_dry_run
5589698f425bSmrg	;;
5590698f425bSmrg      *)
5591698f425bSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5592698f425bSmrg	;;
5593698f425bSmrg      esac
55949ef0b394Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5595698f425bSmrg    done
5596266e564dSmrg
5597a3129944Smrg    func_extract_archives_result=$my_oldobjs
5598698f425bSmrg}
5599266e564dSmrg
5600266e564dSmrg
56019ef0b394Smrg# func_emit_wrapper [arg=no]
56029ef0b394Smrg#
56039ef0b394Smrg# Emit a libtool wrapper script on stdout.
56049ef0b394Smrg# Don't directly open a file because we may want to
56053bf3b463Smrg# incorporate the script contents within a cygwin/mingw/windows
56069ef0b394Smrg# wrapper executable.  Must ONLY be called from within
56079ef0b394Smrg# func_mode_link because it depends on a number of variables
56089ef0b394Smrg# set therein.
5609698f425bSmrg#
56109ef0b394Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
56119ef0b394Smrg# variable will take.  If 'yes', then the emitted script
5612a3129944Smrg# will assume that the directory where it is stored is
56133bf3b463Smrg# the $objdir directory.  This is a cygwin/mingw/windows-specific
56149ef0b394Smrg# behavior.
56159ef0b394Smrgfunc_emit_wrapper ()
5616698f425bSmrg{
56179ef0b394Smrg	func_emit_wrapper_arg1=${1-no}
5618266e564dSmrg
5619698f425bSmrg	$ECHO "\
5620698f425bSmrg#! $SHELL
5621266e564dSmrg
5622698f425bSmrg# $output - temporary wrapper script for $objdir/$outputname
5623a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5624698f425bSmrg#
5625698f425bSmrg# The $output program cannot be directly executed until all the libtool
5626698f425bSmrg# libraries that it depends on are installed.
5627698f425bSmrg#
5628698f425bSmrg# This wrapper script should never be moved out of the build directory.
5629698f425bSmrg# If it is, it will not operate correctly.
5630266e564dSmrg
5631698f425bSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
5632698f425bSmrg# metacharacters that are still active within double-quoted strings.
5633698f425bSmrgsed_quote_subst='$sed_quote_subst'
5634266e564dSmrg
5635698f425bSmrg# Be Bourne compatible
5636698f425bSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5637698f425bSmrg  emulate sh
5638698f425bSmrg  NULLCMD=:
5639698f425bSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5640698f425bSmrg  # is contrary to our usage.  Disable this feature.
5641698f425bSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5642698f425bSmrg  setopt NO_GLOB_SUBST
5643698f425bSmrgelse
5644698f425bSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5645698f425bSmrgfi
5646698f425bSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5647698f425bSmrgDUALCASE=1; export DUALCASE # for MKS sh
5648266e564dSmrg
5649698f425bSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5650698f425bSmrg# if CDPATH is set.
5651698f425bSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5652266e564dSmrg
5653698f425bSmrgrelink_command=\"$relink_command\"
5654266e564dSmrg
5655698f425bSmrg# This environment variable determines our operation mode.
5656698f425bSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5657698f425bSmrg  # install mode needs the following variables:
5658698f425bSmrg  generated_by_libtool_version='$macro_version'
5659698f425bSmrg  notinst_deplibs='$notinst_deplibs'
5660698f425bSmrgelse
5661698f425bSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5662698f425bSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
56639ef0b394Smrg    file=\"\$0\""
56649ef0b394Smrg
56651009a292Smrg    func_quote_arg pretty "$ECHO"
56661009a292Smrg    qECHO=$func_quote_arg_result
56679ef0b394Smrg    $ECHO "\
56689ef0b394Smrg
56699ef0b394Smrg# A function that is used when there is no print builtin or printf.
56709ef0b394Smrgfunc_fallback_echo ()
56719ef0b394Smrg{
56729ef0b394Smrg  eval 'cat <<_LTECHO_EOF
56739ef0b394Smrg\$1
56749ef0b394Smrg_LTECHO_EOF'
56759ef0b394Smrg}
56761009a292Smrg    ECHO=$qECHO
56779ef0b394Smrg  fi
56789ef0b394Smrg
56799ef0b394Smrg# Very basic option parsing. These options are (a) specific to
56809ef0b394Smrg# the libtool wrapper, (b) are identical between the wrapper
5681a3129944Smrg# /script/ and the wrapper /executable/ that is used only on
56829ef0b394Smrg# windows platforms, and (c) all begin with the string "--lt-"
5683a3129944Smrg# (application programs are unlikely to have options that match
56849ef0b394Smrg# this pattern).
56859ef0b394Smrg#
56869ef0b394Smrg# There are only two supported options: --lt-debug and
56879ef0b394Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
56889ef0b394Smrg#
56899ef0b394Smrg# The first argument to this parsing function should be the
56909ef0b394Smrg# script's $0 value, followed by "$@".
56919ef0b394Smrglt_option_debug=
56929ef0b394Smrgfunc_parse_lt_options ()
56939ef0b394Smrg{
56949ef0b394Smrg  lt_script_arg0=\$0
56959ef0b394Smrg  shift
56969ef0b394Smrg  for lt_opt
56979ef0b394Smrg  do
56989ef0b394Smrg    case \"\$lt_opt\" in
56999ef0b394Smrg    --lt-debug) lt_option_debug=1 ;;
57009ef0b394Smrg    --lt-dump-script)
57019ef0b394Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
57029ef0b394Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
57039ef0b394Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
57049ef0b394Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
57059ef0b394Smrg        exit 0
57069ef0b394Smrg      ;;
57079ef0b394Smrg    --lt-*)
57089ef0b394Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
57099ef0b394Smrg        exit 1
57109ef0b394Smrg      ;;
57119ef0b394Smrg    esac
57129ef0b394Smrg  done
57139ef0b394Smrg
57149ef0b394Smrg  # Print the debug banner immediately:
57159ef0b394Smrg  if test -n \"\$lt_option_debug\"; then
5716a3129944Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
57179ef0b394Smrg  fi
57189ef0b394Smrg}
57199ef0b394Smrg
57209ef0b394Smrg# Used when --lt-debug. Prints its arguments to stdout
57219ef0b394Smrg# (redirection is the responsibility of the caller)
57229ef0b394Smrgfunc_lt_dump_args ()
57239ef0b394Smrg{
57249ef0b394Smrg  lt_dump_args_N=1;
57259ef0b394Smrg  for lt_arg
57269ef0b394Smrg  do
5727a3129944Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
57289ef0b394Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
57299ef0b394Smrg  done
57309ef0b394Smrg}
57319ef0b394Smrg
57329ef0b394Smrg# Core function for launching the target application
57339ef0b394Smrgfunc_exec_program_core ()
57349ef0b394Smrg{
5735698f425bSmrg"
57369ef0b394Smrg  case $host in
57379ef0b394Smrg  # Backslashes separate directories on plain windows
57383bf3b463Smrg  *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*)
57399ef0b394Smrg    $ECHO "\
57409ef0b394Smrg      if test -n \"\$lt_option_debug\"; then
5741a3129944Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
57429ef0b394Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
57439ef0b394Smrg      fi
57449ef0b394Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
57459ef0b394Smrg"
57469ef0b394Smrg    ;;
57479ef0b394Smrg
57489ef0b394Smrg  *)
57499ef0b394Smrg    $ECHO "\
57509ef0b394Smrg      if test -n \"\$lt_option_debug\"; then
5751a3129944Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
57529ef0b394Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
57539ef0b394Smrg      fi
57549ef0b394Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
57559ef0b394Smrg"
57569ef0b394Smrg    ;;
57579ef0b394Smrg  esac
57589ef0b394Smrg  $ECHO "\
57599ef0b394Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
57609ef0b394Smrg      exit 1
57619ef0b394Smrg}
57629ef0b394Smrg
57639ef0b394Smrg# A function to encapsulate launching the target application
57649ef0b394Smrg# Strips options in the --lt-* namespace from \$@ and
57659ef0b394Smrg# launches target application with the remaining arguments.
57669ef0b394Smrgfunc_exec_program ()
57679ef0b394Smrg{
5768fb5e8d76Smrg  case \" \$* \" in
5769fb5e8d76Smrg  *\\ --lt-*)
5770fb5e8d76Smrg    for lt_wr_arg
5771fb5e8d76Smrg    do
5772fb5e8d76Smrg      case \$lt_wr_arg in
5773fb5e8d76Smrg      --lt-*) ;;
5774fb5e8d76Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5775fb5e8d76Smrg      esac
5776fb5e8d76Smrg      shift
5777fb5e8d76Smrg    done ;;
5778fb5e8d76Smrg  esac
57799ef0b394Smrg  func_exec_program_core \${1+\"\$@\"}
57809ef0b394Smrg}
57819ef0b394Smrg
57829ef0b394Smrg  # Parse options
57839ef0b394Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5784266e564dSmrg
5785698f425bSmrg  # Find the directory that this script lives in.
57869ef0b394Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5787698f425bSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5788266e564dSmrg
5789698f425bSmrg  # Follow symbolic links until we get to the real thisdir.
57909ef0b394Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5791698f425bSmrg  while test -n \"\$file\"; do
57929ef0b394Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5793266e564dSmrg
5794698f425bSmrg    # If there was a directory component, then change thisdir.
5795698f425bSmrg    if test \"x\$destdir\" != \"x\$file\"; then
5796698f425bSmrg      case \"\$destdir\" in
5797698f425bSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5798698f425bSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5799266e564dSmrg      esac
5800698f425bSmrg    fi
5801266e564dSmrg
58029ef0b394Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
58039ef0b394Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5804698f425bSmrg  done
5805266e564dSmrg
58063bf3b463Smrg  # Usually 'no', except on cygwin/mingw/windows when embedded into
5807698f425bSmrg  # the cwrapper.
58089ef0b394Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5809698f425bSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5810698f425bSmrg    # special case for '.'
5811698f425bSmrg    if test \"\$thisdir\" = \".\"; then
5812698f425bSmrg      thisdir=\`pwd\`
5813698f425bSmrg    fi
5814698f425bSmrg    # remove .libs from thisdir
5815698f425bSmrg    case \"\$thisdir\" in
58169ef0b394Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5817698f425bSmrg    $objdir )   thisdir=. ;;
5818698f425bSmrg    esac
5819698f425bSmrg  fi
5820698f425bSmrg
5821698f425bSmrg  # Try to get the absolute directory name.
5822698f425bSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
5823698f425bSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5824698f425bSmrg"
5825698f425bSmrg
5826a3129944Smrg	if test yes = "$fast_install"; then
5827698f425bSmrg	  $ECHO "\
5828698f425bSmrg  program=lt-'$outputname'$exeext
5829698f425bSmrg  progdir=\"\$thisdir/$objdir\"
5830698f425bSmrg
5831698f425bSmrg  if test ! -f \"\$progdir/\$program\" ||
5832a3129944Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5833698f425bSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5834698f425bSmrg
5835698f425bSmrg    file=\"\$\$-\$program\"
5836698f425bSmrg
5837698f425bSmrg    if test ! -d \"\$progdir\"; then
5838698f425bSmrg      $MKDIR \"\$progdir\"
5839698f425bSmrg    else
5840698f425bSmrg      $RM \"\$progdir/\$file\"
5841698f425bSmrg    fi"
5842698f425bSmrg
5843698f425bSmrg	  $ECHO "\
5844698f425bSmrg
5845698f425bSmrg    # relink executable if necessary
5846698f425bSmrg    if test -n \"\$relink_command\"; then
5847698f425bSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5848698f425bSmrg      else
5849a3129944Smrg	\$ECHO \"\$relink_command_output\" >&2
5850698f425bSmrg	$RM \"\$progdir/\$file\"
5851698f425bSmrg	exit 1
5852266e564dSmrg      fi
5853698f425bSmrg    fi
5854266e564dSmrg
5855698f425bSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5856698f425bSmrg    { $RM \"\$progdir/\$program\";
5857698f425bSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5858698f425bSmrg    $RM \"\$progdir/\$file\"
5859698f425bSmrg  fi"
5860698f425bSmrg	else
5861698f425bSmrg	  $ECHO "\
5862698f425bSmrg  program='$outputname'
5863698f425bSmrg  progdir=\"\$thisdir/$objdir\"
5864698f425bSmrg"
5865266e564dSmrg	fi
5866266e564dSmrg
5867698f425bSmrg	$ECHO "\
5868266e564dSmrg
5869698f425bSmrg  if test -f \"\$progdir/\$program\"; then"
5870266e564dSmrg
58719ef0b394Smrg	# fixup the dll searchpath if we need to.
58729ef0b394Smrg	#
58739ef0b394Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
58749ef0b394Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
58759ef0b394Smrg	# libraries must come first.
58769ef0b394Smrg	if test -n "$dllsearchpath"; then
58779ef0b394Smrg	  $ECHO "\
58789ef0b394Smrg    # Add the dll search path components to the executable PATH
58799ef0b394Smrg    PATH=$dllsearchpath:\$PATH
58809ef0b394Smrg"
58819ef0b394Smrg	fi
58829ef0b394Smrg
5883698f425bSmrg	# Export our shlibpath_var if we have one.
5884a3129944Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5885698f425bSmrg	  $ECHO "\
5886698f425bSmrg    # Add our own library path to $shlibpath_var
5887698f425bSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5888266e564dSmrg
5889698f425bSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5890698f425bSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
58919ef0b394Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5892698f425bSmrg
5893698f425bSmrg    export $shlibpath_var
5894698f425bSmrg"
5895266e564dSmrg	fi
5896266e564dSmrg
5897698f425bSmrg	$ECHO "\
5898698f425bSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5899698f425bSmrg      # Run the actual program with our arguments.
59009ef0b394Smrg      func_exec_program \${1+\"\$@\"}
5901698f425bSmrg    fi
5902698f425bSmrg  else
5903698f425bSmrg    # The program doesn't exist.
5904a3129944Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5905698f425bSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
59069ef0b394Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5907698f425bSmrg    exit 1
5908698f425bSmrg  fi
5909698f425bSmrgfi\
5910698f425bSmrg"
5911698f425bSmrg}
5912266e564dSmrg
5913266e564dSmrg
5914698f425bSmrg# func_emit_cwrapperexe_src
5915698f425bSmrg# emit the source code for a wrapper executable on stdout
5916698f425bSmrg# Must ONLY be called from within func_mode_link because
5917698f425bSmrg# it depends on a number of variable set therein.
5918698f425bSmrgfunc_emit_cwrapperexe_src ()
5919698f425bSmrg{
5920698f425bSmrg	cat <<EOF
5921266e564dSmrg
5922698f425bSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5923a3129944Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5924266e564dSmrg
5925698f425bSmrg   The $output program cannot be directly executed until all the libtool
5926698f425bSmrg   libraries that it depends on are installed.
5927266e564dSmrg
5928698f425bSmrg   This wrapper executable should never be moved out of the build directory.
5929698f425bSmrg   If it is, it will not operate correctly.
5930698f425bSmrg*/
5931698f425bSmrgEOF
5932698f425bSmrg	    cat <<"EOF"
59339ef0b394Smrg#ifdef _MSC_VER
59349ef0b394Smrg# define _CRT_SECURE_NO_DEPRECATE 1
59359ef0b394Smrg#endif
5936698f425bSmrg#include <stdio.h>
5937698f425bSmrg#include <stdlib.h>
59383bf3b463Smrg#if defined _WIN32 && !defined __GNUC__
5939698f425bSmrg# include <direct.h>
5940698f425bSmrg# include <process.h>
5941698f425bSmrg# include <io.h>
5942698f425bSmrg#else
5943698f425bSmrg# include <unistd.h>
5944698f425bSmrg# include <stdint.h>
5945698f425bSmrg# ifdef __CYGWIN__
5946698f425bSmrg#  include <io.h>
5947698f425bSmrg# endif
5948698f425bSmrg#endif
5949698f425bSmrg#include <malloc.h>
5950698f425bSmrg#include <stdarg.h>
5951698f425bSmrg#include <assert.h>
5952698f425bSmrg#include <string.h>
5953698f425bSmrg#include <ctype.h>
5954698f425bSmrg#include <errno.h>
5955698f425bSmrg#include <fcntl.h>
5956698f425bSmrg#include <sys/stat.h>
5957266e564dSmrg
5958a3129944Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5959a3129944Smrg
59609ef0b394Smrg/* declarations of non-ANSI functions */
5961a3129944Smrg#if defined __MINGW32__
59629ef0b394Smrg# ifdef __STRICT_ANSI__
59633bf3b463Smrg_CRTIMP int __cdecl _putenv (const char *);
59649ef0b394Smrg# endif
5965a3129944Smrg#elif defined __CYGWIN__
59669ef0b394Smrg# ifdef __STRICT_ANSI__
59679ef0b394Smrgchar *realpath (const char *, char *);
59689ef0b394Smrgint putenv (char *);
59699ef0b394Smrgint setenv (const char *, const char *, int);
59709ef0b394Smrg# endif
5971a3129944Smrg/* #elif defined other_platform || defined ... */
59729ef0b394Smrg#endif
59739ef0b394Smrg
59749ef0b394Smrg/* portability defines, excluding path handling macros */
5975a3129944Smrg#if defined _MSC_VER
59769ef0b394Smrg# define setmode _setmode
59779ef0b394Smrg# define stat    _stat
59789ef0b394Smrg# define chmod   _chmod
59799ef0b394Smrg# define getcwd  _getcwd
59809ef0b394Smrg# define putenv  _putenv
59819ef0b394Smrg# define S_IXUSR _S_IEXEC
5982a3129944Smrg#elif defined __MINGW32__
59839ef0b394Smrg# define setmode _setmode
59849ef0b394Smrg# define stat    _stat
59859ef0b394Smrg# define chmod   _chmod
59869ef0b394Smrg# define getcwd  _getcwd
59879ef0b394Smrg# define putenv  _putenv
5988a3129944Smrg#elif defined __CYGWIN__
59899ef0b394Smrg# define HAVE_SETENV
59909ef0b394Smrg# define FOPEN_WB "wb"
5991a3129944Smrg/* #elif defined other platforms ... */
59929ef0b394Smrg#endif
59939ef0b394Smrg
5994a3129944Smrg#if defined PATH_MAX
5995698f425bSmrg# define LT_PATHMAX PATH_MAX
5996a3129944Smrg#elif defined MAXPATHLEN
5997698f425bSmrg# define LT_PATHMAX MAXPATHLEN
5998698f425bSmrg#else
5999698f425bSmrg# define LT_PATHMAX 1024
6000698f425bSmrg#endif
6001266e564dSmrg
6002698f425bSmrg#ifndef S_IXOTH
6003698f425bSmrg# define S_IXOTH 0
6004698f425bSmrg#endif
6005698f425bSmrg#ifndef S_IXGRP
6006698f425bSmrg# define S_IXGRP 0
6007698f425bSmrg#endif
6008266e564dSmrg
60099ef0b394Smrg/* path handling portability macros */
6010698f425bSmrg#ifndef DIR_SEPARATOR
6011698f425bSmrg# define DIR_SEPARATOR '/'
6012698f425bSmrg# define PATH_SEPARATOR ':'
6013698f425bSmrg#endif
6014266e564dSmrg
6015a3129944Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
6016a3129944Smrg  defined __OS2__
6017698f425bSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
6018698f425bSmrg# define FOPEN_WB "wb"
6019698f425bSmrg# ifndef DIR_SEPARATOR_2
6020698f425bSmrg#  define DIR_SEPARATOR_2 '\\'
6021698f425bSmrg# endif
6022698f425bSmrg# ifndef PATH_SEPARATOR_2
6023698f425bSmrg#  define PATH_SEPARATOR_2 ';'
6024698f425bSmrg# endif
6025698f425bSmrg#endif
6026266e564dSmrg
6027698f425bSmrg#ifndef DIR_SEPARATOR_2
6028698f425bSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
6029698f425bSmrg#else /* DIR_SEPARATOR_2 */
6030698f425bSmrg# define IS_DIR_SEPARATOR(ch) \
6031698f425bSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
6032698f425bSmrg#endif /* DIR_SEPARATOR_2 */
6033266e564dSmrg
6034698f425bSmrg#ifndef PATH_SEPARATOR_2
6035698f425bSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
6036698f425bSmrg#else /* PATH_SEPARATOR_2 */
6037698f425bSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
6038698f425bSmrg#endif /* PATH_SEPARATOR_2 */
6039266e564dSmrg
6040698f425bSmrg#ifndef FOPEN_WB
6041698f425bSmrg# define FOPEN_WB "w"
6042698f425bSmrg#endif
6043698f425bSmrg#ifndef _O_BINARY
6044698f425bSmrg# define _O_BINARY 0
6045698f425bSmrg#endif
6046266e564dSmrg
6047698f425bSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
6048698f425bSmrg#define XFREE(stale) do { \
6049a3129944Smrg  if (stale) { free (stale); stale = 0; } \
6050698f425bSmrg} while (0)
6051266e564dSmrg
6052a3129944Smrg#if defined LT_DEBUGWRAPPER
60539ef0b394Smrgstatic int lt_debug = 1;
6054698f425bSmrg#else
60559ef0b394Smrgstatic int lt_debug = 0;
6056698f425bSmrg#endif
6057266e564dSmrg
60589ef0b394Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
6059266e564dSmrg
6060698f425bSmrgvoid *xmalloc (size_t num);
6061698f425bSmrgchar *xstrdup (const char *string);
6062698f425bSmrgconst char *base_name (const char *name);
6063698f425bSmrgchar *find_executable (const char *wrapper);
6064698f425bSmrgchar *chase_symlinks (const char *pathspec);
6065698f425bSmrgint make_executable (const char *path);
6066698f425bSmrgint check_executable (const char *path);
6067698f425bSmrgchar *strendzap (char *str, const char *pat);
60689ef0b394Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
60699ef0b394Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
60709ef0b394Smrgstatic const char *nonnull (const char *s);
60719ef0b394Smrgstatic const char *nonempty (const char *s);
6072698f425bSmrgvoid lt_setenv (const char *name, const char *value);
6073698f425bSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
6074698f425bSmrgvoid lt_update_exe_path (const char *name, const char *value);
6075698f425bSmrgvoid lt_update_lib_path (const char *name, const char *value);
60769ef0b394Smrgchar **prepare_spawn (char **argv);
60779ef0b394Smrgvoid lt_dump_script (FILE *f);
6078698f425bSmrgEOF
6079698f425bSmrg
6080698f425bSmrg	    cat <<EOF
6081a3129944Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
6082a3129944Smrg# define externally_visible volatile
6083a3129944Smrg#else
6084a3129944Smrg# define externally_visible __attribute__((externally_visible)) volatile
6085a3129944Smrg#endif
6086a3129944Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
6087698f425bSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
6088698f425bSmrgEOF
6089266e564dSmrg
6090a3129944Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
60919ef0b394Smrg              func_to_host_path "$temp_rpath"
6092698f425bSmrg	      cat <<EOF
60939ef0b394Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
6094698f425bSmrgEOF
6095698f425bSmrg	    else
6096698f425bSmrg	      cat <<"EOF"
6097698f425bSmrgconst char * LIB_PATH_VALUE   = "";
6098698f425bSmrgEOF
6099266e564dSmrg	    fi
6100266e564dSmrg
6101698f425bSmrg	    if test -n "$dllsearchpath"; then
61029ef0b394Smrg              func_to_host_path "$dllsearchpath:"
6103698f425bSmrg	      cat <<EOF
6104698f425bSmrgconst char * EXE_PATH_VARNAME = "PATH";
61059ef0b394Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
6106266e564dSmrgEOF
6107266e564dSmrg	    else
6108698f425bSmrg	      cat <<"EOF"
6109698f425bSmrgconst char * EXE_PATH_VARNAME = "";
6110698f425bSmrgconst char * EXE_PATH_VALUE   = "";
6111698f425bSmrgEOF
6112266e564dSmrg	    fi
6113698f425bSmrg
6114a3129944Smrg	    if test yes = "$fast_install"; then
6115698f425bSmrg	      cat <<EOF
6116698f425bSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
6117698f425bSmrgEOF
6118266e564dSmrg	    else
6119698f425bSmrg	      cat <<EOF
6120698f425bSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
6121698f425bSmrgEOF
6122266e564dSmrg	    fi
6123266e564dSmrg
6124266e564dSmrg
6125698f425bSmrg	    cat <<"EOF"
6126266e564dSmrg
6127698f425bSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
6128266e564dSmrg
6129698f425bSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
6130698f425bSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
61319ef0b394Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
6132266e564dSmrg
6133698f425bSmrgint
6134698f425bSmrgmain (int argc, char *argv[])
6135698f425bSmrg{
6136698f425bSmrg  char **newargz;
6137698f425bSmrg  int  newargc;
6138698f425bSmrg  char *tmp_pathspec;
6139698f425bSmrg  char *actual_cwrapper_path;
6140698f425bSmrg  char *actual_cwrapper_name;
6141698f425bSmrg  char *target_name;
6142698f425bSmrg  char *lt_argv_zero;
6143a3129944Smrg  int rval = 127;
6144266e564dSmrg
6145698f425bSmrg  int i;
6146266e564dSmrg
6147698f425bSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6148a3129944Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6149266e564dSmrg
61509ef0b394Smrg  /* very simple arg parsing; don't want to rely on getopt
61519ef0b394Smrg   * also, copy all non cwrapper options to newargz, except
61529ef0b394Smrg   * argz[0], which is handled differently
61539ef0b394Smrg   */
61549ef0b394Smrg  newargc=0;
6155698f425bSmrg  for (i = 1; i < argc; i++)
6156698f425bSmrg    {
6157a3129944Smrg      if (STREQ (argv[i], dumpscript_opt))
6158698f425bSmrg	{
6159698f425bSmrgEOF
6160a3129944Smrg	    case $host in
61613bf3b463Smrg	      *mingw* | *windows* | *cygwin* )
6162698f425bSmrg		# make stdout use "unix" line endings
6163698f425bSmrg		echo "          setmode(1,_O_BINARY);"
6164698f425bSmrg		;;
6165698f425bSmrg	      esac
6166266e564dSmrg
6167698f425bSmrg	    cat <<"EOF"
61689ef0b394Smrg	  lt_dump_script (stdout);
6169698f425bSmrg	  return 0;
6170698f425bSmrg	}
6171a3129944Smrg      if (STREQ (argv[i], debug_opt))
61729ef0b394Smrg	{
61739ef0b394Smrg          lt_debug = 1;
61749ef0b394Smrg          continue;
61759ef0b394Smrg	}
6176a3129944Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
61779ef0b394Smrg        {
61789ef0b394Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
61799ef0b394Smrg             namespace, but it is not one of the ones we know about and
61803bf3b463Smrg             have already dealt with, above (including dump-script), then
61819ef0b394Smrg             report an error. Otherwise, targets might begin to believe
61829ef0b394Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
61839ef0b394Smrg             namespace. The first time any user complains about this, we'll
61849ef0b394Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
61859ef0b394Smrg             or a configure.ac-settable value.
61869ef0b394Smrg           */
61879ef0b394Smrg          lt_fatal (__FILE__, __LINE__,
61889ef0b394Smrg		    "unrecognized %s option: '%s'",
61899ef0b394Smrg                    ltwrapper_option_prefix, argv[i]);
61909ef0b394Smrg        }
61919ef0b394Smrg      /* otherwise ... */
61929ef0b394Smrg      newargz[++newargc] = xstrdup (argv[i]);
6193698f425bSmrg    }
61949ef0b394Smrg  newargz[++newargc] = NULL;
61959ef0b394Smrg
61969ef0b394SmrgEOF
61979ef0b394Smrg	    cat <<EOF
61989ef0b394Smrg  /* The GNU banner must be the first non-error debug message */
6199a3129944Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
62009ef0b394SmrgEOF
62019ef0b394Smrg	    cat <<"EOF"
62029ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
62039ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6204266e564dSmrg
6205698f425bSmrg  tmp_pathspec = find_executable (argv[0]);
6206698f425bSmrg  if (tmp_pathspec == NULL)
62079ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
62089ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
62099ef0b394Smrg                  "(main) found exe (before symlink chase) at: %s\n",
62109ef0b394Smrg		  tmp_pathspec);
6211698f425bSmrg
6212698f425bSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
62139ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
62149ef0b394Smrg                  "(main) found exe (after symlink chase) at: %s\n",
62159ef0b394Smrg		  actual_cwrapper_path);
6216698f425bSmrg  XFREE (tmp_pathspec);
6217698f425bSmrg
62189ef0b394Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6219698f425bSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6220698f425bSmrg
6221698f425bSmrg  /* wrapper name transforms */
6222698f425bSmrg  strendzap (actual_cwrapper_name, ".exe");
6223698f425bSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6224698f425bSmrg  XFREE (actual_cwrapper_name);
6225698f425bSmrg  actual_cwrapper_name = tmp_pathspec;
6226698f425bSmrg  tmp_pathspec = 0;
6227698f425bSmrg
6228698f425bSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6229698f425bSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6230698f425bSmrg  strendzap (target_name, ".exe");
6231698f425bSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6232698f425bSmrg  XFREE (target_name);
6233698f425bSmrg  target_name = tmp_pathspec;
6234698f425bSmrg  tmp_pathspec = 0;
6235698f425bSmrg
62369ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
62379ef0b394Smrg		  "(main) libtool target name: %s\n",
62389ef0b394Smrg		  target_name);
6239698f425bSmrgEOF
6240266e564dSmrg
6241698f425bSmrg	    cat <<EOF
6242698f425bSmrg  newargz[0] =
6243698f425bSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6244698f425bSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6245698f425bSmrg  strcpy (newargz[0], actual_cwrapper_path);
6246698f425bSmrg  strcat (newargz[0], "$objdir");
6247698f425bSmrg  strcat (newargz[0], "/");
6248698f425bSmrgEOF
6249266e564dSmrg
6250698f425bSmrg	    cat <<"EOF"
6251698f425bSmrg  /* stop here, and copy so we don't have to do this twice */
6252698f425bSmrg  tmp_pathspec = xstrdup (newargz[0]);
6253266e564dSmrg
6254698f425bSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6255698f425bSmrg  strcat (newargz[0], actual_cwrapper_name);
6256266e564dSmrg
6257698f425bSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
6258698f425bSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6259698f425bSmrg  XFREE (tmp_pathspec);
6260698f425bSmrg  tmp_pathspec = NULL;
6261698f425bSmrgEOF
6262266e564dSmrg
6263698f425bSmrg	    case $host_os in
62643bf3b463Smrg	      mingw* | windows*)
6265698f425bSmrg	    cat <<"EOF"
6266698f425bSmrg  {
6267698f425bSmrg    char* p;
6268698f425bSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6269698f425bSmrg      {
6270698f425bSmrg	*p = '/';
6271698f425bSmrg      }
6272698f425bSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6273698f425bSmrg      {
6274698f425bSmrg	*p = '/';
6275698f425bSmrg      }
6276698f425bSmrg  }
6277698f425bSmrgEOF
6278698f425bSmrg	    ;;
6279698f425bSmrg	    esac
6280266e564dSmrg
6281698f425bSmrg	    cat <<"EOF"
6282698f425bSmrg  XFREE (target_name);
6283698f425bSmrg  XFREE (actual_cwrapper_path);
6284698f425bSmrg  XFREE (actual_cwrapper_name);
6285266e564dSmrg
6286698f425bSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6287698f425bSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
62889ef0b394Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
62899ef0b394Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
62909ef0b394Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
62919ef0b394Smrg     libraries must come first. */
6292698f425bSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
62939ef0b394Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6294266e564dSmrg
62959ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
62969ef0b394Smrg		  nonnull (lt_argv_zero));
6297698f425bSmrg  for (i = 0; i < newargc; i++)
6298698f425bSmrg    {
62999ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
63009ef0b394Smrg		      i, nonnull (newargz[i]));
6301698f425bSmrg    }
6302266e564dSmrg
6303698f425bSmrgEOF
6304266e564dSmrg
6305698f425bSmrg	    case $host_os in
63063bf3b463Smrg	      mingw* | windows*)
6307698f425bSmrg		cat <<"EOF"
6308698f425bSmrg  /* execv doesn't actually work on mingw as expected on unix */
63099ef0b394Smrg  newargz = prepare_spawn (newargz);
6310a3129944Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6311698f425bSmrg  if (rval == -1)
6312698f425bSmrg    {
6313698f425bSmrg      /* failed to start process */
63149ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__,
63159ef0b394Smrg		      "(main) failed to launch target \"%s\": %s\n",
63169ef0b394Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6317698f425bSmrg      return 127;
6318698f425bSmrg    }
6319698f425bSmrg  return rval;
6320698f425bSmrgEOF
6321698f425bSmrg		;;
6322698f425bSmrg	      *)
6323698f425bSmrg		cat <<"EOF"
6324698f425bSmrg  execv (lt_argv_zero, newargz);
6325698f425bSmrg  return rval; /* =127, but avoids unused variable warning */
6326698f425bSmrgEOF
6327698f425bSmrg		;;
6328698f425bSmrg	    esac
6329266e564dSmrg
6330698f425bSmrg	    cat <<"EOF"
6331698f425bSmrg}
6332266e564dSmrg
6333698f425bSmrgvoid *
6334698f425bSmrgxmalloc (size_t num)
6335698f425bSmrg{
6336698f425bSmrg  void *p = (void *) malloc (num);
6337698f425bSmrg  if (!p)
63389ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6339266e564dSmrg
6340698f425bSmrg  return p;
6341698f425bSmrg}
6342266e564dSmrg
6343698f425bSmrgchar *
6344698f425bSmrgxstrdup (const char *string)
6345698f425bSmrg{
6346698f425bSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6347698f425bSmrg			  string) : NULL;
6348698f425bSmrg}
6349266e564dSmrg
6350698f425bSmrgconst char *
6351698f425bSmrgbase_name (const char *name)
6352698f425bSmrg{
6353698f425bSmrg  const char *base;
6354266e564dSmrg
6355a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6356698f425bSmrg  /* Skip over the disk name in MSDOS pathnames. */
6357698f425bSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6358698f425bSmrg    name += 2;
6359698f425bSmrg#endif
6360266e564dSmrg
6361698f425bSmrg  for (base = name; *name; name++)
6362698f425bSmrg    if (IS_DIR_SEPARATOR (*name))
6363698f425bSmrg      base = name + 1;
6364698f425bSmrg  return base;
6365698f425bSmrg}
6366266e564dSmrg
6367698f425bSmrgint
6368698f425bSmrgcheck_executable (const char *path)
6369698f425bSmrg{
6370698f425bSmrg  struct stat st;
6371266e564dSmrg
63729ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
63739ef0b394Smrg                  nonempty (path));
6374698f425bSmrg  if ((!path) || (!*path))
6375698f425bSmrg    return 0;
6376266e564dSmrg
6377698f425bSmrg  if ((stat (path, &st) >= 0)
6378698f425bSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6379698f425bSmrg    return 1;
6380698f425bSmrg  else
6381698f425bSmrg    return 0;
6382698f425bSmrg}
6383266e564dSmrg
6384698f425bSmrgint
6385698f425bSmrgmake_executable (const char *path)
6386698f425bSmrg{
6387698f425bSmrg  int rval = 0;
6388698f425bSmrg  struct stat st;
6389266e564dSmrg
63909ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
63919ef0b394Smrg                  nonempty (path));
6392698f425bSmrg  if ((!path) || (!*path))
6393698f425bSmrg    return 0;
6394266e564dSmrg
6395698f425bSmrg  if (stat (path, &st) >= 0)
6396698f425bSmrg    {
6397698f425bSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6398698f425bSmrg    }
6399698f425bSmrg  return rval;
6400698f425bSmrg}
6401266e564dSmrg
6402698f425bSmrg/* Searches for the full path of the wrapper.  Returns
6403698f425bSmrg   newly allocated full path name if found, NULL otherwise
6404698f425bSmrg   Does not chase symlinks, even on platforms that support them.
6405698f425bSmrg*/
6406698f425bSmrgchar *
6407698f425bSmrgfind_executable (const char *wrapper)
6408698f425bSmrg{
6409698f425bSmrg  int has_slash = 0;
6410698f425bSmrg  const char *p;
6411698f425bSmrg  const char *p_next;
6412698f425bSmrg  /* static buffer for getcwd */
6413698f425bSmrg  char tmp[LT_PATHMAX + 1];
6414a3129944Smrg  size_t tmp_len;
6415698f425bSmrg  char *concat_name;
6416266e564dSmrg
64179ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
64189ef0b394Smrg                  nonempty (wrapper));
6419266e564dSmrg
6420698f425bSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6421698f425bSmrg    return NULL;
6422266e564dSmrg
6423698f425bSmrg  /* Absolute path? */
6424a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6425698f425bSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6426698f425bSmrg    {
6427698f425bSmrg      concat_name = xstrdup (wrapper);
6428698f425bSmrg      if (check_executable (concat_name))
6429698f425bSmrg	return concat_name;
6430698f425bSmrg      XFREE (concat_name);
6431698f425bSmrg    }
6432698f425bSmrg  else
6433698f425bSmrg    {
6434698f425bSmrg#endif
6435698f425bSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6436698f425bSmrg	{
6437698f425bSmrg	  concat_name = xstrdup (wrapper);
6438698f425bSmrg	  if (check_executable (concat_name))
6439698f425bSmrg	    return concat_name;
6440698f425bSmrg	  XFREE (concat_name);
6441698f425bSmrg	}
6442a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6443698f425bSmrg    }
6444698f425bSmrg#endif
6445266e564dSmrg
6446698f425bSmrg  for (p = wrapper; *p; p++)
6447698f425bSmrg    if (*p == '/')
6448698f425bSmrg      {
6449698f425bSmrg	has_slash = 1;
6450698f425bSmrg	break;
6451698f425bSmrg      }
6452698f425bSmrg  if (!has_slash)
6453698f425bSmrg    {
6454698f425bSmrg      /* no slashes; search PATH */
6455698f425bSmrg      const char *path = getenv ("PATH");
6456698f425bSmrg      if (path != NULL)
6457698f425bSmrg	{
6458698f425bSmrg	  for (p = path; *p; p = p_next)
6459698f425bSmrg	    {
6460698f425bSmrg	      const char *q;
6461698f425bSmrg	      size_t p_len;
6462698f425bSmrg	      for (q = p; *q; q++)
6463698f425bSmrg		if (IS_PATH_SEPARATOR (*q))
6464698f425bSmrg		  break;
6465a3129944Smrg	      p_len = (size_t) (q - p);
6466698f425bSmrg	      p_next = (*q == '\0' ? q : q + 1);
6467698f425bSmrg	      if (p_len == 0)
6468698f425bSmrg		{
6469698f425bSmrg		  /* empty path: current directory */
6470698f425bSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
64719ef0b394Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
64729ef0b394Smrg                              nonnull (strerror (errno)));
6473698f425bSmrg		  tmp_len = strlen (tmp);
6474698f425bSmrg		  concat_name =
6475698f425bSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6476698f425bSmrg		  memcpy (concat_name, tmp, tmp_len);
6477698f425bSmrg		  concat_name[tmp_len] = '/';
6478698f425bSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6479698f425bSmrg		}
6480698f425bSmrg	      else
6481698f425bSmrg		{
6482698f425bSmrg		  concat_name =
6483698f425bSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6484698f425bSmrg		  memcpy (concat_name, p, p_len);
6485698f425bSmrg		  concat_name[p_len] = '/';
6486698f425bSmrg		  strcpy (concat_name + p_len + 1, wrapper);
6487698f425bSmrg		}
6488698f425bSmrg	      if (check_executable (concat_name))
6489698f425bSmrg		return concat_name;
6490698f425bSmrg	      XFREE (concat_name);
6491698f425bSmrg	    }
6492698f425bSmrg	}
6493698f425bSmrg      /* not found in PATH; assume curdir */
6494698f425bSmrg    }
6495698f425bSmrg  /* Relative path | not found in path: prepend cwd */
6496698f425bSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
64979ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
64989ef0b394Smrg              nonnull (strerror (errno)));
6499698f425bSmrg  tmp_len = strlen (tmp);
6500698f425bSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6501698f425bSmrg  memcpy (concat_name, tmp, tmp_len);
6502698f425bSmrg  concat_name[tmp_len] = '/';
6503698f425bSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
6504266e564dSmrg
6505698f425bSmrg  if (check_executable (concat_name))
6506698f425bSmrg    return concat_name;
6507698f425bSmrg  XFREE (concat_name);
6508698f425bSmrg  return NULL;
6509698f425bSmrg}
6510266e564dSmrg
6511698f425bSmrgchar *
6512698f425bSmrgchase_symlinks (const char *pathspec)
6513698f425bSmrg{
6514698f425bSmrg#ifndef S_ISLNK
6515698f425bSmrg  return xstrdup (pathspec);
6516698f425bSmrg#else
6517698f425bSmrg  char buf[LT_PATHMAX];
6518698f425bSmrg  struct stat s;
6519698f425bSmrg  char *tmp_pathspec = xstrdup (pathspec);
6520698f425bSmrg  char *p;
6521698f425bSmrg  int has_symlinks = 0;
6522698f425bSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
6523698f425bSmrg    {
65249ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__,
65259ef0b394Smrg		      "checking path component for symlinks: %s\n",
65269ef0b394Smrg		      tmp_pathspec);
6527698f425bSmrg      if (lstat (tmp_pathspec, &s) == 0)
6528698f425bSmrg	{
6529698f425bSmrg	  if (S_ISLNK (s.st_mode) != 0)
6530698f425bSmrg	    {
6531698f425bSmrg	      has_symlinks = 1;
6532698f425bSmrg	      break;
6533698f425bSmrg	    }
6534266e564dSmrg
6535698f425bSmrg	  /* search backwards for last DIR_SEPARATOR */
6536698f425bSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6537698f425bSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6538698f425bSmrg	    p--;
6539698f425bSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6540698f425bSmrg	    {
6541698f425bSmrg	      /* no more DIR_SEPARATORS left */
6542698f425bSmrg	      break;
6543698f425bSmrg	    }
6544698f425bSmrg	  *p = '\0';
6545698f425bSmrg	}
6546698f425bSmrg      else
6547698f425bSmrg	{
65489ef0b394Smrg	  lt_fatal (__FILE__, __LINE__,
65499ef0b394Smrg		    "error accessing file \"%s\": %s",
65509ef0b394Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6551698f425bSmrg	}
6552698f425bSmrg    }
6553698f425bSmrg  XFREE (tmp_pathspec);
6554266e564dSmrg
6555698f425bSmrg  if (!has_symlinks)
6556698f425bSmrg    {
6557698f425bSmrg      return xstrdup (pathspec);
6558698f425bSmrg    }
6559266e564dSmrg
6560698f425bSmrg  tmp_pathspec = realpath (pathspec, buf);
6561698f425bSmrg  if (tmp_pathspec == 0)
6562698f425bSmrg    {
65639ef0b394Smrg      lt_fatal (__FILE__, __LINE__,
65649ef0b394Smrg		"could not follow symlinks for %s", pathspec);
6565698f425bSmrg    }
6566698f425bSmrg  return xstrdup (tmp_pathspec);
6567698f425bSmrg#endif
6568698f425bSmrg}
6569266e564dSmrg
6570698f425bSmrgchar *
6571698f425bSmrgstrendzap (char *str, const char *pat)
6572698f425bSmrg{
6573698f425bSmrg  size_t len, patlen;
6574266e564dSmrg
6575698f425bSmrg  assert (str != NULL);
6576698f425bSmrg  assert (pat != NULL);
6577266e564dSmrg
6578698f425bSmrg  len = strlen (str);
6579698f425bSmrg  patlen = strlen (pat);
6580266e564dSmrg
6581698f425bSmrg  if (patlen <= len)
6582698f425bSmrg    {
6583698f425bSmrg      str += len - patlen;
6584a3129944Smrg      if (STREQ (str, pat))
6585698f425bSmrg	*str = '\0';
6586698f425bSmrg    }
6587698f425bSmrg  return str;
6588698f425bSmrg}
6589266e564dSmrg
65909ef0b394Smrgvoid
65919ef0b394Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
65929ef0b394Smrg{
65939ef0b394Smrg  va_list args;
65949ef0b394Smrg  if (lt_debug)
65959ef0b394Smrg    {
65969ef0b394Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
65979ef0b394Smrg      va_start (args, fmt);
65989ef0b394Smrg      (void) vfprintf (stderr, fmt, args);
65999ef0b394Smrg      va_end (args);
66009ef0b394Smrg    }
66019ef0b394Smrg}
66029ef0b394Smrg
6603698f425bSmrgstatic void
66049ef0b394Smrglt_error_core (int exit_status, const char *file,
66059ef0b394Smrg	       int line, const char *mode,
6606698f425bSmrg	       const char *message, va_list ap)
6607698f425bSmrg{
66089ef0b394Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6609698f425bSmrg  vfprintf (stderr, message, ap);
6610698f425bSmrg  fprintf (stderr, ".\n");
6611266e564dSmrg
6612698f425bSmrg  if (exit_status >= 0)
6613698f425bSmrg    exit (exit_status);
6614698f425bSmrg}
6615266e564dSmrg
6616698f425bSmrgvoid
66179ef0b394Smrglt_fatal (const char *file, int line, const char *message, ...)
6618698f425bSmrg{
6619698f425bSmrg  va_list ap;
6620698f425bSmrg  va_start (ap, message);
66219ef0b394Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6622698f425bSmrg  va_end (ap);
6623698f425bSmrg}
6624266e564dSmrg
66259ef0b394Smrgstatic const char *
66269ef0b394Smrgnonnull (const char *s)
66279ef0b394Smrg{
66289ef0b394Smrg  return s ? s : "(null)";
66299ef0b394Smrg}
66309ef0b394Smrg
66319ef0b394Smrgstatic const char *
66329ef0b394Smrgnonempty (const char *s)
66339ef0b394Smrg{
66349ef0b394Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
66359ef0b394Smrg}
66369ef0b394Smrg
6637698f425bSmrgvoid
6638698f425bSmrglt_setenv (const char *name, const char *value)
6639698f425bSmrg{
66409ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
66419ef0b394Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
66429ef0b394Smrg                  nonnull (name), nonnull (value));
6643698f425bSmrg  {
6644698f425bSmrg#ifdef HAVE_SETENV
6645698f425bSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
6646698f425bSmrg    char *str = xstrdup (value);
6647698f425bSmrg    setenv (name, str, 1);
6648698f425bSmrg#else
6649a3129944Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6650698f425bSmrg    char *str = XMALLOC (char, len);
6651698f425bSmrg    sprintf (str, "%s=%s", name, value);
6652698f425bSmrg    if (putenv (str) != EXIT_SUCCESS)
6653698f425bSmrg      {
6654698f425bSmrg        XFREE (str);
6655698f425bSmrg      }
6656698f425bSmrg#endif
6657698f425bSmrg  }
6658698f425bSmrg}
6659266e564dSmrg
6660698f425bSmrgchar *
6661698f425bSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
6662698f425bSmrg{
6663698f425bSmrg  char *new_value;
6664698f425bSmrg  if (orig_value && *orig_value)
6665698f425bSmrg    {
6666a3129944Smrg      size_t orig_value_len = strlen (orig_value);
6667a3129944Smrg      size_t add_len = strlen (add);
6668698f425bSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6669698f425bSmrg      if (to_end)
6670698f425bSmrg        {
6671698f425bSmrg          strcpy (new_value, orig_value);
6672698f425bSmrg          strcpy (new_value + orig_value_len, add);
6673698f425bSmrg        }
6674698f425bSmrg      else
6675698f425bSmrg        {
6676698f425bSmrg          strcpy (new_value, add);
6677698f425bSmrg          strcpy (new_value + add_len, orig_value);
6678698f425bSmrg        }
6679698f425bSmrg    }
6680698f425bSmrg  else
6681698f425bSmrg    {
6682698f425bSmrg      new_value = xstrdup (add);
6683698f425bSmrg    }
6684698f425bSmrg  return new_value;
6685698f425bSmrg}
6686266e564dSmrg
6687698f425bSmrgvoid
6688698f425bSmrglt_update_exe_path (const char *name, const char *value)
6689698f425bSmrg{
66909ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
66919ef0b394Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
66929ef0b394Smrg                  nonnull (name), nonnull (value));
6693266e564dSmrg
6694698f425bSmrg  if (name && *name && value && *value)
6695698f425bSmrg    {
6696698f425bSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6697698f425bSmrg      /* some systems can't cope with a ':'-terminated path #' */
6698a3129944Smrg      size_t len = strlen (new_value);
6699a3129944Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6700698f425bSmrg        {
6701a3129944Smrg          new_value[--len] = '\0';
6702698f425bSmrg        }
6703698f425bSmrg      lt_setenv (name, new_value);
6704698f425bSmrg      XFREE (new_value);
6705698f425bSmrg    }
6706698f425bSmrg}
6707266e564dSmrg
6708698f425bSmrgvoid
6709698f425bSmrglt_update_lib_path (const char *name, const char *value)
6710698f425bSmrg{
67119ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
67129ef0b394Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
67139ef0b394Smrg                  nonnull (name), nonnull (value));
6714266e564dSmrg
6715698f425bSmrg  if (name && *name && value && *value)
6716698f425bSmrg    {
6717698f425bSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6718698f425bSmrg      lt_setenv (name, new_value);
6719698f425bSmrg      XFREE (new_value);
6720698f425bSmrg    }
6721698f425bSmrg}
6722266e564dSmrg
67239ef0b394SmrgEOF
67249ef0b394Smrg	    case $host_os in
67253bf3b463Smrg	      mingw* | windows*)
67269ef0b394Smrg		cat <<"EOF"
67279ef0b394Smrg
67289ef0b394Smrg/* Prepares an argument vector before calling spawn().
67299ef0b394Smrg   Note that spawn() does not by itself call the command interpreter
67309ef0b394Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
67319ef0b394Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
67329ef0b394Smrg         GetVersionEx(&v);
67339ef0b394Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
67349ef0b394Smrg      }) ? "cmd.exe" : "command.com").
67359ef0b394Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
67369ef0b394Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
67379ef0b394Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
67389ef0b394Smrg   special way:
67399ef0b394Smrg   - Space and tab are interpreted as delimiters. They are not treated as
67409ef0b394Smrg     delimiters if they are surrounded by double quotes: "...".
67419ef0b394Smrg   - Unescaped double quotes are removed from the input. Their only effect is
67429ef0b394Smrg     that within double quotes, space and tab are treated like normal
67439ef0b394Smrg     characters.
67449ef0b394Smrg   - Backslashes not followed by double quotes are not special.
67459ef0b394Smrg   - But 2*n+1 backslashes followed by a double quote become
67469ef0b394Smrg     n backslashes followed by a double quote (n >= 0):
67479ef0b394Smrg       \" -> "
67489ef0b394Smrg       \\\" -> \"
67499ef0b394Smrg       \\\\\" -> \\"
67509ef0b394Smrg */
67519ef0b394Smrg#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"
67529ef0b394Smrg#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"
67539ef0b394Smrgchar **
67549ef0b394Smrgprepare_spawn (char **argv)
67559ef0b394Smrg{
67569ef0b394Smrg  size_t argc;
67579ef0b394Smrg  char **new_argv;
67589ef0b394Smrg  size_t i;
67599ef0b394Smrg
67609ef0b394Smrg  /* Count number of arguments.  */
67619ef0b394Smrg  for (argc = 0; argv[argc] != NULL; argc++)
67629ef0b394Smrg    ;
67639ef0b394Smrg
67649ef0b394Smrg  /* Allocate new argument vector.  */
67659ef0b394Smrg  new_argv = XMALLOC (char *, argc + 1);
67669ef0b394Smrg
67679ef0b394Smrg  /* Put quoted arguments into the new argument vector.  */
67689ef0b394Smrg  for (i = 0; i < argc; i++)
67699ef0b394Smrg    {
67709ef0b394Smrg      const char *string = argv[i];
67719ef0b394Smrg
67729ef0b394Smrg      if (string[0] == '\0')
67739ef0b394Smrg	new_argv[i] = xstrdup ("\"\"");
67749ef0b394Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
67759ef0b394Smrg	{
67769ef0b394Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
67779ef0b394Smrg	  size_t length;
67789ef0b394Smrg	  unsigned int backslashes;
67799ef0b394Smrg	  const char *s;
67809ef0b394Smrg	  char *quoted_string;
67819ef0b394Smrg	  char *p;
67829ef0b394Smrg
67839ef0b394Smrg	  length = 0;
67849ef0b394Smrg	  backslashes = 0;
67859ef0b394Smrg	  if (quote_around)
67869ef0b394Smrg	    length++;
67879ef0b394Smrg	  for (s = string; *s != '\0'; s++)
67889ef0b394Smrg	    {
67899ef0b394Smrg	      char c = *s;
67909ef0b394Smrg	      if (c == '"')
67919ef0b394Smrg		length += backslashes + 1;
67929ef0b394Smrg	      length++;
67939ef0b394Smrg	      if (c == '\\')
67949ef0b394Smrg		backslashes++;
67959ef0b394Smrg	      else
67969ef0b394Smrg		backslashes = 0;
67979ef0b394Smrg	    }
67989ef0b394Smrg	  if (quote_around)
67999ef0b394Smrg	    length += backslashes + 1;
68009ef0b394Smrg
68019ef0b394Smrg	  quoted_string = XMALLOC (char, length + 1);
68029ef0b394Smrg
68039ef0b394Smrg	  p = quoted_string;
68049ef0b394Smrg	  backslashes = 0;
68059ef0b394Smrg	  if (quote_around)
68069ef0b394Smrg	    *p++ = '"';
68079ef0b394Smrg	  for (s = string; *s != '\0'; s++)
68089ef0b394Smrg	    {
68099ef0b394Smrg	      char c = *s;
68109ef0b394Smrg	      if (c == '"')
68119ef0b394Smrg		{
68129ef0b394Smrg		  unsigned int j;
68139ef0b394Smrg		  for (j = backslashes + 1; j > 0; j--)
68149ef0b394Smrg		    *p++ = '\\';
68159ef0b394Smrg		}
68169ef0b394Smrg	      *p++ = c;
68179ef0b394Smrg	      if (c == '\\')
68189ef0b394Smrg		backslashes++;
68199ef0b394Smrg	      else
68209ef0b394Smrg		backslashes = 0;
68219ef0b394Smrg	    }
68229ef0b394Smrg	  if (quote_around)
68239ef0b394Smrg	    {
68249ef0b394Smrg	      unsigned int j;
68259ef0b394Smrg	      for (j = backslashes; j > 0; j--)
68269ef0b394Smrg		*p++ = '\\';
68279ef0b394Smrg	      *p++ = '"';
68289ef0b394Smrg	    }
68299ef0b394Smrg	  *p = '\0';
68309ef0b394Smrg
68319ef0b394Smrg	  new_argv[i] = quoted_string;
68329ef0b394Smrg	}
68339ef0b394Smrg      else
68349ef0b394Smrg	new_argv[i] = (char *) string;
68359ef0b394Smrg    }
68369ef0b394Smrg  new_argv[argc] = NULL;
68379ef0b394Smrg
68389ef0b394Smrg  return new_argv;
68399ef0b394Smrg}
68409ef0b394SmrgEOF
68419ef0b394Smrg		;;
68429ef0b394Smrg	    esac
68439ef0b394Smrg
68449ef0b394Smrg            cat <<"EOF"
68459ef0b394Smrgvoid lt_dump_script (FILE* f)
68469ef0b394Smrg{
68479ef0b394SmrgEOF
68489ef0b394Smrg	    func_emit_wrapper yes |
6849fb5e8d76Smrg	      $SED -n -e '
6850fb5e8d76Smrgs/^\(.\{79\}\)\(..*\)/\1\
6851fb5e8d76Smrg\2/
6852fb5e8d76Smrgh
6853fb5e8d76Smrgs/\([\\"]\)/\\\1/g
6854fb5e8d76Smrgs/$/\\n/
6855fb5e8d76Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6856fb5e8d76Smrgg
6857fb5e8d76SmrgD'
68589ef0b394Smrg            cat <<"EOF"
68599ef0b394Smrg}
6860698f425bSmrgEOF
6861698f425bSmrg}
6862698f425bSmrg# end: func_emit_cwrapperexe_src
6863266e564dSmrg
68649ef0b394Smrg# func_win32_import_lib_p ARG
68659ef0b394Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
68669ef0b394Smrgfunc_win32_import_lib_p ()
68679ef0b394Smrg{
6868a3129944Smrg    $debug_cmd
6869a3129944Smrg
68709ef0b394Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
68719ef0b394Smrg    *import*) : ;;
68729ef0b394Smrg    *) false ;;
68739ef0b394Smrg    esac
68749ef0b394Smrg}
68759ef0b394Smrg
6876a3129944Smrg# func_suncc_cstd_abi
6877a3129944Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6878a3129944Smrg# Several compiler flags select an ABI that is incompatible with the
6879a3129944Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6880a3129944Smrgfunc_suncc_cstd_abi ()
6881a3129944Smrg{
6882a3129944Smrg    $debug_cmd
6883a3129944Smrg
6884a3129944Smrg    case " $compile_command " in
6885a3129944Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6886a3129944Smrg      suncc_use_cstd_abi=no
6887a3129944Smrg      ;;
6888a3129944Smrg    *)
6889a3129944Smrg      suncc_use_cstd_abi=yes
6890a3129944Smrg      ;;
6891a3129944Smrg    esac
6892a3129944Smrg}
6893a3129944Smrg
6894698f425bSmrg# func_mode_link arg...
6895698f425bSmrgfunc_mode_link ()
6896698f425bSmrg{
6897a3129944Smrg    $debug_cmd
6898a3129944Smrg
6899698f425bSmrg    case $host in
69003bf3b463Smrg    *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
6901698f425bSmrg      # It is impossible to link a dll without this setting, and
6902698f425bSmrg      # we shouldn't force the makefile maintainer to figure out
6903a3129944Smrg      # what system we are compiling for in order to pass an extra
6904698f425bSmrg      # flag for every libtool invocation.
6905698f425bSmrg      # allow_undefined=no
6906266e564dSmrg
6907698f425bSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6908a3129944Smrg      # to make a dll that has undefined symbols, in which case not
6909698f425bSmrg      # even a static library is built.  For now, we need to specify
6910698f425bSmrg      # -no-undefined on the libtool link line when we can be certain
6911698f425bSmrg      # that all symbols are satisfied, otherwise we get a static library.
6912698f425bSmrg      allow_undefined=yes
6913698f425bSmrg      ;;
6914698f425bSmrg    *)
6915698f425bSmrg      allow_undefined=yes
6916698f425bSmrg      ;;
6917698f425bSmrg    esac
6918698f425bSmrg    libtool_args=$nonopt
6919698f425bSmrg    base_compile="$nonopt $@"
6920698f425bSmrg    compile_command=$nonopt
6921698f425bSmrg    finalize_command=$nonopt
6922266e564dSmrg
6923698f425bSmrg    compile_rpath=
69243bf3b463Smrg    compile_rpath_tail=
6925698f425bSmrg    finalize_rpath=
6926698f425bSmrg    compile_shlibpath=
6927698f425bSmrg    finalize_shlibpath=
6928698f425bSmrg    convenience=
6929698f425bSmrg    old_convenience=
6930698f425bSmrg    deplibs=
6931698f425bSmrg    old_deplibs=
6932698f425bSmrg    compiler_flags=
6933698f425bSmrg    linker_flags=
6934698f425bSmrg    dllsearchpath=
6935698f425bSmrg    lib_search_path=`pwd`
6936698f425bSmrg    inst_prefix_dir=
6937698f425bSmrg    new_inherited_linker_flags=
6938266e564dSmrg
6939698f425bSmrg    avoid_version=no
69409ef0b394Smrg    bindir=
6941698f425bSmrg    dlfiles=
6942698f425bSmrg    dlprefiles=
6943698f425bSmrg    dlself=no
6944698f425bSmrg    export_dynamic=no
6945698f425bSmrg    export_symbols=
6946698f425bSmrg    export_symbols_regex=
6947698f425bSmrg    generated=
6948698f425bSmrg    libobjs=
6949698f425bSmrg    ltlibs=
6950698f425bSmrg    module=no
6951698f425bSmrg    no_install=no
6952698f425bSmrg    objs=
6953a3129944Smrg    os2dllname=
6954698f425bSmrg    non_pic_objects=
6955698f425bSmrg    precious_files_regex=
6956698f425bSmrg    prefer_static_libs=no
6957a3129944Smrg    preload=false
6958698f425bSmrg    prev=
6959698f425bSmrg    prevarg=
6960698f425bSmrg    release=
6961698f425bSmrg    rpath=
6962698f425bSmrg    xrpath=
6963698f425bSmrg    perm_rpath=
6964698f425bSmrg    temp_rpath=
69653bf3b463Smrg    temp_rpath_tail=
6966698f425bSmrg    thread_safe=no
6967698f425bSmrg    vinfo=
6968698f425bSmrg    vinfo_number=no
6969698f425bSmrg    weak_libs=
69703bf3b463Smrg    rpath_arg=
6971a3129944Smrg    single_module=$wl-single_module
6972698f425bSmrg    func_infer_tag $base_compile
6973266e564dSmrg
6974698f425bSmrg    # We need to know -static, to get the right output filenames.
6975698f425bSmrg    for arg
6976698f425bSmrg    do
6977698f425bSmrg      case $arg in
6978698f425bSmrg      -shared)
6979a3129944Smrg	test yes != "$build_libtool_libs" \
6980a3129944Smrg	  && func_fatal_configuration "cannot build a shared library"
6981698f425bSmrg	build_old_libs=no
6982698f425bSmrg	break
6983698f425bSmrg	;;
6984698f425bSmrg      -all-static | -static | -static-libtool-libs)
6985698f425bSmrg	case $arg in
6986698f425bSmrg	-all-static)
6987a3129944Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6988698f425bSmrg	    func_warning "complete static linking is impossible in this configuration"
6989698f425bSmrg	  fi
6990698f425bSmrg	  if test -n "$link_static_flag"; then
6991698f425bSmrg	    dlopen_self=$dlopen_self_static
6992698f425bSmrg	  fi
6993698f425bSmrg	  prefer_static_libs=yes
6994698f425bSmrg	  ;;
6995698f425bSmrg	-static)
6996698f425bSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6997698f425bSmrg	    dlopen_self=$dlopen_self_static
6998698f425bSmrg	  fi
6999698f425bSmrg	  prefer_static_libs=built
7000698f425bSmrg	  ;;
7001698f425bSmrg	-static-libtool-libs)
7002698f425bSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
7003698f425bSmrg	    dlopen_self=$dlopen_self_static
7004698f425bSmrg	  fi
7005698f425bSmrg	  prefer_static_libs=yes
7006698f425bSmrg	  ;;
7007698f425bSmrg	esac
7008698f425bSmrg	build_libtool_libs=no
7009698f425bSmrg	build_old_libs=yes
7010698f425bSmrg	break
7011698f425bSmrg	;;
7012698f425bSmrg      esac
7013698f425bSmrg    done
7014266e564dSmrg
7015698f425bSmrg    # See if our shared archives depend on static archives.
7016698f425bSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
7017266e564dSmrg
7018698f425bSmrg    # Go through the arguments, transforming them on the way.
7019698f425bSmrg    while test "$#" -gt 0; do
7020a3129944Smrg      arg=$1
7021698f425bSmrg      shift
70221009a292Smrg      func_quote_arg pretty,unquoted "$arg"
70231009a292Smrg      qarg=$func_quote_arg_unquoted_result
70241009a292Smrg      func_append libtool_args " $func_quote_arg_result"
7025266e564dSmrg
7026698f425bSmrg      # If the previous option needs an argument, assign it.
7027698f425bSmrg      if test -n "$prev"; then
7028698f425bSmrg	case $prev in
7029698f425bSmrg	output)
7030698f425bSmrg	  func_append compile_command " @OUTPUT@"
7031698f425bSmrg	  func_append finalize_command " @OUTPUT@"
7032698f425bSmrg	  ;;
7033698f425bSmrg	esac
7034266e564dSmrg
7035698f425bSmrg	case $prev in
70369ef0b394Smrg	bindir)
7037a3129944Smrg	  bindir=$arg
70389ef0b394Smrg	  prev=
70399ef0b394Smrg	  continue
70409ef0b394Smrg	  ;;
7041698f425bSmrg	dlfiles|dlprefiles)
7042a3129944Smrg	  $preload || {
7043698f425bSmrg	    # Add the symbol object into the linking commands.
7044698f425bSmrg	    func_append compile_command " @SYMFILE@"
7045698f425bSmrg	    func_append finalize_command " @SYMFILE@"
7046a3129944Smrg	    preload=:
7047a3129944Smrg	  }
7048698f425bSmrg	  case $arg in
7049698f425bSmrg	  *.la | *.lo) ;;  # We handle these cases below.
7050698f425bSmrg	  force)
7051a3129944Smrg	    if test no = "$dlself"; then
7052698f425bSmrg	      dlself=needless
7053698f425bSmrg	      export_dynamic=yes
7054698f425bSmrg	    fi
7055698f425bSmrg	    prev=
7056698f425bSmrg	    continue
7057698f425bSmrg	    ;;
7058698f425bSmrg	  self)
7059a3129944Smrg	    if test dlprefiles = "$prev"; then
7060698f425bSmrg	      dlself=yes
7061a3129944Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
7062698f425bSmrg	      dlself=yes
7063698f425bSmrg	    else
7064698f425bSmrg	      dlself=needless
7065698f425bSmrg	      export_dynamic=yes
7066698f425bSmrg	    fi
7067698f425bSmrg	    prev=
7068698f425bSmrg	    continue
7069698f425bSmrg	    ;;
7070698f425bSmrg	  *)
7071a3129944Smrg	    if test dlfiles = "$prev"; then
70729ef0b394Smrg	      func_append dlfiles " $arg"
7073698f425bSmrg	    else
70749ef0b394Smrg	      func_append dlprefiles " $arg"
7075698f425bSmrg	    fi
7076698f425bSmrg	    prev=
7077698f425bSmrg	    continue
7078698f425bSmrg	    ;;
7079698f425bSmrg	  esac
7080698f425bSmrg	  ;;
7081698f425bSmrg	expsyms)
7082a3129944Smrg	  export_symbols=$arg
7083698f425bSmrg	  test -f "$arg" \
7084a3129944Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
7085698f425bSmrg	  prev=
7086698f425bSmrg	  continue
7087698f425bSmrg	  ;;
7088698f425bSmrg	expsyms_regex)
7089a3129944Smrg	  export_symbols_regex=$arg
7090698f425bSmrg	  prev=
7091698f425bSmrg	  continue
7092698f425bSmrg	  ;;
7093698f425bSmrg	framework)
7094266e564dSmrg	  case $host in
7095698f425bSmrg	    *-*-darwin*)
7096698f425bSmrg	      case "$deplibs " in
7097698f425bSmrg		*" $qarg.ltframework "*) ;;
70989ef0b394Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
7099698f425bSmrg		   ;;
7100698f425bSmrg	      esac
7101698f425bSmrg	      ;;
7102266e564dSmrg	  esac
7103698f425bSmrg	  prev=
7104698f425bSmrg	  continue
7105266e564dSmrg	  ;;
7106698f425bSmrg	inst_prefix)
7107a3129944Smrg	  inst_prefix_dir=$arg
7108a3129944Smrg	  prev=
7109a3129944Smrg	  continue
7110a3129944Smrg	  ;;
7111a3129944Smrg	mllvm)
7112a3129944Smrg	  # Clang does not use LLVM to link, so we can simply discard any
7113a3129944Smrg	  # '-mllvm $arg' options when doing the link step.
7114698f425bSmrg	  prev=
7115698f425bSmrg	  continue
7116266e564dSmrg	  ;;
7117698f425bSmrg	objectlist)
7118698f425bSmrg	  if test -f "$arg"; then
7119698f425bSmrg	    save_arg=$arg
7120698f425bSmrg	    moreargs=
7121698f425bSmrg	    for fil in `cat "$save_arg"`
7122698f425bSmrg	    do
71239ef0b394Smrg#	      func_append moreargs " $fil"
7124698f425bSmrg	      arg=$fil
7125698f425bSmrg	      # A libtool-controlled object.
7126266e564dSmrg
7127698f425bSmrg	      # Check to see that this really is a libtool object.
7128698f425bSmrg	      if func_lalib_unsafe_p "$arg"; then
7129698f425bSmrg		pic_object=
7130698f425bSmrg		non_pic_object=
7131266e564dSmrg
7132698f425bSmrg		# Read the .lo file
7133698f425bSmrg		func_source "$arg"
7134266e564dSmrg
7135698f425bSmrg		if test -z "$pic_object" ||
7136698f425bSmrg		   test -z "$non_pic_object" ||
7137a3129944Smrg		   test none = "$pic_object" &&
7138a3129944Smrg		   test none = "$non_pic_object"; then
7139a3129944Smrg		  func_fatal_error "cannot find name of object for '$arg'"
7140698f425bSmrg		fi
7141266e564dSmrg
7142698f425bSmrg		# Extract subdirectory from the argument.
7143698f425bSmrg		func_dirname "$arg" "/" ""
7144a3129944Smrg		xdir=$func_dirname_result
7145266e564dSmrg
7146a3129944Smrg		if test none != "$pic_object"; then
7147698f425bSmrg		  # Prepend the subdirectory the object is found in.
7148a3129944Smrg		  pic_object=$xdir$pic_object
7149266e564dSmrg
7150a3129944Smrg		  if test dlfiles = "$prev"; then
7151a3129944Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
71529ef0b394Smrg		      func_append dlfiles " $pic_object"
7153698f425bSmrg		      prev=
7154698f425bSmrg		      continue
7155698f425bSmrg		    else
7156698f425bSmrg		      # If libtool objects are unsupported, then we need to preload.
7157698f425bSmrg		      prev=dlprefiles
7158698f425bSmrg		    fi
7159698f425bSmrg		  fi
7160266e564dSmrg
7161698f425bSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7162a3129944Smrg		  if test dlprefiles = "$prev"; then
7163698f425bSmrg		    # Preload the old-style object.
71649ef0b394Smrg		    func_append dlprefiles " $pic_object"
7165698f425bSmrg		    prev=
7166698f425bSmrg		  fi
7167266e564dSmrg
7168698f425bSmrg		  # A PIC object.
7169698f425bSmrg		  func_append libobjs " $pic_object"
7170a3129944Smrg		  arg=$pic_object
7171698f425bSmrg		fi
7172266e564dSmrg
7173698f425bSmrg		# Non-PIC object.
7174a3129944Smrg		if test none != "$non_pic_object"; then
7175698f425bSmrg		  # Prepend the subdirectory the object is found in.
7176a3129944Smrg		  non_pic_object=$xdir$non_pic_object
7177698f425bSmrg
7178698f425bSmrg		  # A standard non-PIC object
7179698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
7180a3129944Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7181a3129944Smrg		    arg=$non_pic_object
7182698f425bSmrg		  fi
7183698f425bSmrg		else
7184698f425bSmrg		  # If the PIC object exists, use it instead.
7185698f425bSmrg		  # $xdir was prepended to $pic_object above.
7186a3129944Smrg		  non_pic_object=$pic_object
7187698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
7188698f425bSmrg		fi
7189698f425bSmrg	      else
7190698f425bSmrg		# Only an error if not doing a dry-run.
7191698f425bSmrg		if $opt_dry_run; then
7192698f425bSmrg		  # Extract subdirectory from the argument.
7193698f425bSmrg		  func_dirname "$arg" "/" ""
7194a3129944Smrg		  xdir=$func_dirname_result
7195698f425bSmrg
7196698f425bSmrg		  func_lo2o "$arg"
7197698f425bSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
7198698f425bSmrg		  non_pic_object=$xdir$func_lo2o_result
7199698f425bSmrg		  func_append libobjs " $pic_object"
7200698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
7201698f425bSmrg	        else
7202a3129944Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
7203698f425bSmrg		fi
7204698f425bSmrg	      fi
7205698f425bSmrg	    done
7206266e564dSmrg	  else
7207a3129944Smrg	    func_fatal_error "link input file '$arg' does not exist"
7208266e564dSmrg	  fi
7209698f425bSmrg	  arg=$save_arg
7210698f425bSmrg	  prev=
7211698f425bSmrg	  continue
7212698f425bSmrg	  ;;
7213a3129944Smrg	os2dllname)
7214a3129944Smrg	  os2dllname=$arg
7215a3129944Smrg	  prev=
7216a3129944Smrg	  continue
7217a3129944Smrg	  ;;
7218698f425bSmrg	precious_regex)
7219a3129944Smrg	  precious_files_regex=$arg
7220698f425bSmrg	  prev=
7221698f425bSmrg	  continue
7222698f425bSmrg	  ;;
7223698f425bSmrg	release)
7224a3129944Smrg	  release=-$arg
7225698f425bSmrg	  prev=
7226698f425bSmrg	  continue
7227698f425bSmrg	  ;;
7228698f425bSmrg	rpath | xrpath)
7229698f425bSmrg	  # We need an absolute path.
7230698f425bSmrg	  case $arg in
7231698f425bSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7232698f425bSmrg	  *)
72333bf3b463Smrg	    func_fatal_error "argument to -rpath is not absolute: $arg"
7234698f425bSmrg	    ;;
7235698f425bSmrg	  esac
7236a3129944Smrg	  if test rpath = "$prev"; then
7237698f425bSmrg	    case "$rpath " in
7238698f425bSmrg	    *" $arg "*) ;;
72399ef0b394Smrg	    *) func_append rpath " $arg" ;;
7240698f425bSmrg	    esac
7241266e564dSmrg	  else
7242698f425bSmrg	    case "$xrpath " in
7243698f425bSmrg	    *" $arg "*) ;;
72449ef0b394Smrg	    *) func_append xrpath " $arg" ;;
7245698f425bSmrg	    esac
7246266e564dSmrg	  fi
7247698f425bSmrg	  prev=
7248698f425bSmrg	  continue
7249698f425bSmrg	  ;;
7250698f425bSmrg	shrext)
7251a3129944Smrg	  shrext_cmds=$arg
7252698f425bSmrg	  prev=
7253698f425bSmrg	  continue
7254698f425bSmrg	  ;;
7255698f425bSmrg	weak)
72569ef0b394Smrg	  func_append weak_libs " $arg"
7257698f425bSmrg	  prev=
7258698f425bSmrg	  continue
7259698f425bSmrg	  ;;
72601009a292Smrg	xassembler)
72611009a292Smrg	  func_append compiler_flags " -Xassembler $qarg"
72621009a292Smrg	  prev=
72631009a292Smrg	  func_append compile_command " -Xassembler $qarg"
72641009a292Smrg	  func_append finalize_command " -Xassembler $qarg"
72651009a292Smrg	  continue
72661009a292Smrg	  ;;
7267698f425bSmrg	xcclinker)
72689ef0b394Smrg	  func_append linker_flags " $qarg"
72699ef0b394Smrg	  func_append compiler_flags " $qarg"
7270698f425bSmrg	  prev=
7271698f425bSmrg	  func_append compile_command " $qarg"
7272698f425bSmrg	  func_append finalize_command " $qarg"
7273698f425bSmrg	  continue
7274698f425bSmrg	  ;;
7275698f425bSmrg	xcompiler)
72769ef0b394Smrg	  func_append compiler_flags " $qarg"
7277698f425bSmrg	  prev=
7278698f425bSmrg	  func_append compile_command " $qarg"
7279698f425bSmrg	  func_append finalize_command " $qarg"
7280698f425bSmrg	  continue
7281698f425bSmrg	  ;;
7282698f425bSmrg	xlinker)
72839ef0b394Smrg	  func_append linker_flags " $qarg"
72849ef0b394Smrg	  func_append compiler_flags " $wl$qarg"
7285698f425bSmrg	  prev=
7286698f425bSmrg	  func_append compile_command " $wl$qarg"
7287698f425bSmrg	  func_append finalize_command " $wl$qarg"
7288698f425bSmrg	  continue
7289698f425bSmrg	  ;;
7290698f425bSmrg	*)
7291698f425bSmrg	  eval "$prev=\"\$arg\""
7292698f425bSmrg	  prev=
7293698f425bSmrg	  continue
7294698f425bSmrg	  ;;
7295266e564dSmrg	esac
7296698f425bSmrg      fi # test -n "$prev"
7297266e564dSmrg
7298a3129944Smrg      prevarg=$arg
7299266e564dSmrg
7300698f425bSmrg      case $arg in
7301698f425bSmrg      -all-static)
7302698f425bSmrg	if test -n "$link_static_flag"; then
7303698f425bSmrg	  # See comment for -static flag below, for more details.
7304698f425bSmrg	  func_append compile_command " $link_static_flag"
7305698f425bSmrg	  func_append finalize_command " $link_static_flag"
7306698f425bSmrg	fi
7307698f425bSmrg	continue
7308698f425bSmrg	;;
7309266e564dSmrg
7310698f425bSmrg      -allow-undefined)
7311698f425bSmrg	# FIXME: remove this flag sometime in the future.
7312a3129944Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7313698f425bSmrg	;;
7314266e564dSmrg
7315698f425bSmrg      -avoid-version)
7316698f425bSmrg	avoid_version=yes
7317698f425bSmrg	continue
7318698f425bSmrg	;;
7319266e564dSmrg
73209ef0b394Smrg      -bindir)
73219ef0b394Smrg	prev=bindir
73229ef0b394Smrg	continue
73239ef0b394Smrg	;;
73249ef0b394Smrg
7325698f425bSmrg      -dlopen)
7326698f425bSmrg	prev=dlfiles
7327698f425bSmrg	continue
7328698f425bSmrg	;;
7329266e564dSmrg
7330698f425bSmrg      -dlpreopen)
7331698f425bSmrg	prev=dlprefiles
7332698f425bSmrg	continue
7333698f425bSmrg	;;
7334266e564dSmrg
7335698f425bSmrg      -export-dynamic)
7336698f425bSmrg	export_dynamic=yes
7337698f425bSmrg	continue
7338698f425bSmrg	;;
7339266e564dSmrg
7340698f425bSmrg      -export-symbols | -export-symbols-regex)
7341698f425bSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7342698f425bSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7343698f425bSmrg	fi
7344a3129944Smrg	if test X-export-symbols = "X$arg"; then
7345698f425bSmrg	  prev=expsyms
7346698f425bSmrg	else
7347698f425bSmrg	  prev=expsyms_regex
7348698f425bSmrg	fi
7349698f425bSmrg	continue
7350698f425bSmrg	;;
7351266e564dSmrg
7352698f425bSmrg      -framework)
7353698f425bSmrg	prev=framework
7354698f425bSmrg	continue
7355698f425bSmrg	;;
7356266e564dSmrg
7357698f425bSmrg      -inst-prefix-dir)
7358698f425bSmrg	prev=inst_prefix
7359698f425bSmrg	continue
7360698f425bSmrg	;;
7361266e564dSmrg
7362698f425bSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7363698f425bSmrg      # so, if we see these flags be careful not to treat them like -L
7364698f425bSmrg      -L[A-Z][A-Z]*:*)
7365698f425bSmrg	case $with_gcc/$host in
7366698f425bSmrg	no/*-*-irix* | /*-*-irix*)
7367698f425bSmrg	  func_append compile_command " $arg"
7368698f425bSmrg	  func_append finalize_command " $arg"
7369698f425bSmrg	  ;;
7370698f425bSmrg	esac
7371698f425bSmrg	continue
7372698f425bSmrg	;;
7373266e564dSmrg
7374698f425bSmrg      -L*)
73759ef0b394Smrg	func_stripname "-L" '' "$arg"
73769ef0b394Smrg	if test -z "$func_stripname_result"; then
7377698f425bSmrg	  if test "$#" -gt 0; then
7378a3129944Smrg	    func_fatal_error "require no space between '-L' and '$1'"
7379698f425bSmrg	  else
7380a3129944Smrg	    func_fatal_error "need path for '-L' option"
7381698f425bSmrg	  fi
7382698f425bSmrg	fi
73839ef0b394Smrg	func_resolve_sysroot "$func_stripname_result"
73849ef0b394Smrg	dir=$func_resolve_sysroot_result
7385698f425bSmrg	# We need an absolute path.
7386698f425bSmrg	case $dir in
7387698f425bSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7388698f425bSmrg	*)
7389698f425bSmrg	  absdir=`cd "$dir" && pwd`
7390698f425bSmrg	  test -z "$absdir" && \
7391a3129944Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7392a3129944Smrg	  dir=$absdir
7393698f425bSmrg	  ;;
7394698f425bSmrg	esac
7395698f425bSmrg	case "$deplibs " in
73969ef0b394Smrg	*" -L$dir "* | *" $arg "*)
73979ef0b394Smrg	  # Will only happen for absolute or sysroot arguments
73989ef0b394Smrg	  ;;
7399698f425bSmrg	*)
74009ef0b394Smrg	  # Preserve sysroot, but never include relative directories
74019ef0b394Smrg	  case $dir in
74029ef0b394Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
74039ef0b394Smrg	    *) func_append deplibs " -L$dir" ;;
74049ef0b394Smrg	  esac
74059ef0b394Smrg	  func_append lib_search_path " $dir"
7406698f425bSmrg	  ;;
7407698f425bSmrg	esac
7408698f425bSmrg	case $host in
74093bf3b463Smrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
74109ef0b394Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7411698f425bSmrg	  case :$dllsearchpath: in
7412698f425bSmrg	  *":$dir:"*) ;;
7413698f425bSmrg	  ::) dllsearchpath=$dir;;
74149ef0b394Smrg	  *) func_append dllsearchpath ":$dir";;
7415698f425bSmrg	  esac
7416698f425bSmrg	  case :$dllsearchpath: in
7417698f425bSmrg	  *":$testbindir:"*) ;;
7418698f425bSmrg	  ::) dllsearchpath=$testbindir;;
74199ef0b394Smrg	  *) func_append dllsearchpath ":$testbindir";;
7420698f425bSmrg	  esac
7421698f425bSmrg	  ;;
7422698f425bSmrg	esac
7423698f425bSmrg	continue
7424698f425bSmrg	;;
7425266e564dSmrg
7426698f425bSmrg      -l*)
7427a3129944Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7428698f425bSmrg	  case $host in
74293bf3b463Smrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7430698f425bSmrg	    # These systems don't actually have a C or math library (as such)
7431698f425bSmrg	    continue
7432698f425bSmrg	    ;;
7433698f425bSmrg	  *-*-os2*)
7434698f425bSmrg	    # These systems don't actually have a C library (as such)
7435a3129944Smrg	    test X-lc = "X$arg" && continue
7436698f425bSmrg	    ;;
74373bf3b463Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7438698f425bSmrg	    # Do not include libc due to us having libc/libc_r.
7439a3129944Smrg	    test X-lc = "X$arg" && continue
7440698f425bSmrg	    ;;
7441698f425bSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
7442698f425bSmrg	    # Rhapsody C and math libraries are in the System framework
74439ef0b394Smrg	    func_append deplibs " System.ltframework"
7444698f425bSmrg	    continue
7445698f425bSmrg	    ;;
7446698f425bSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7447698f425bSmrg	    # Causes problems with __ctype
7448a3129944Smrg	    test X-lc = "X$arg" && continue
7449698f425bSmrg	    ;;
7450698f425bSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7451698f425bSmrg	    # Compiler inserts libc in the correct place for threads to work
7452a3129944Smrg	    test X-lc = "X$arg" && continue
7453698f425bSmrg	    ;;
7454698f425bSmrg	  esac
7455a3129944Smrg	elif test X-lc_r = "X$arg"; then
7456698f425bSmrg	 case $host in
74573bf3b463Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7458698f425bSmrg	   # Do not include libc_r directly, use -pthread flag.
7459698f425bSmrg	   continue
7460698f425bSmrg	   ;;
7461698f425bSmrg	 esac
7462698f425bSmrg	fi
74639ef0b394Smrg	func_append deplibs " $arg"
7464698f425bSmrg	continue
7465698f425bSmrg	;;
7466266e564dSmrg
7467a3129944Smrg      -mllvm)
7468a3129944Smrg	prev=mllvm
7469a3129944Smrg	continue
7470a3129944Smrg	;;
7471a3129944Smrg
7472698f425bSmrg      -module)
7473698f425bSmrg	module=yes
7474698f425bSmrg	continue
7475698f425bSmrg	;;
7476266e564dSmrg
7477698f425bSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7478698f425bSmrg      # classes, name mangling, and exception handling.
7479698f425bSmrg      # Darwin uses the -arch flag to determine output architecture.
74803bf3b463Smrg      # -q <option> for IBM XL C/C++ compiler.
74813bf3b463Smrg      -model|-arch|-isysroot|--sysroot|-q)
74829ef0b394Smrg	func_append compiler_flags " $arg"
7483698f425bSmrg	func_append compile_command " $arg"
7484698f425bSmrg	func_append finalize_command " $arg"
7485698f425bSmrg	prev=xcompiler
7486698f425bSmrg	continue
7487698f425bSmrg	;;
74881009a292Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
74891009a292Smrg     -pthread)
74901009a292Smrg	case $host in
74911009a292Smrg	  *solaris2*) ;;
74921009a292Smrg	  *)
74931009a292Smrg	    case "$new_inherited_linker_flags " in
74941009a292Smrg	        *" $arg "*) ;;
74951009a292Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
74961009a292Smrg	    esac
74971009a292Smrg	  ;;
74981009a292Smrg	esac
74991009a292Smrg	continue
75001009a292Smrg	;;
75011009a292Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
75023bf3b463Smrg      |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
75039ef0b394Smrg	func_append compiler_flags " $arg"
7504698f425bSmrg	func_append compile_command " $arg"
7505698f425bSmrg	func_append finalize_command " $arg"
7506698f425bSmrg	case "$new_inherited_linker_flags " in
7507698f425bSmrg	    *" $arg "*) ;;
75089ef0b394Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7509698f425bSmrg	esac
7510698f425bSmrg	continue
7511698f425bSmrg	;;
7512266e564dSmrg
7513698f425bSmrg      -multi_module)
7514a3129944Smrg	single_module=$wl-multi_module
7515698f425bSmrg	continue
7516698f425bSmrg	;;
7517266e564dSmrg
7518698f425bSmrg      -no-fast-install)
7519698f425bSmrg	fast_install=no
7520698f425bSmrg	continue
7521698f425bSmrg	;;
7522266e564dSmrg
7523698f425bSmrg      -no-install)
7524698f425bSmrg	case $host in
75253bf3b463Smrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7526698f425bSmrg	  # The PATH hackery in wrapper scripts is required on Windows
7527698f425bSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7528a3129944Smrg	  func_warning "'-no-install' is ignored for $host"
7529a3129944Smrg	  func_warning "assuming '-no-fast-install' instead"
7530698f425bSmrg	  fast_install=no
7531698f425bSmrg	  ;;
7532698f425bSmrg	*) no_install=yes ;;
7533698f425bSmrg	esac
7534698f425bSmrg	continue
7535698f425bSmrg	;;
7536266e564dSmrg
7537698f425bSmrg      -no-undefined)
7538698f425bSmrg	allow_undefined=no
7539698f425bSmrg	continue
7540698f425bSmrg	;;
7541266e564dSmrg
7542698f425bSmrg      -objectlist)
7543698f425bSmrg	prev=objectlist
7544698f425bSmrg	continue
7545698f425bSmrg	;;
7546266e564dSmrg
7547a3129944Smrg      -os2dllname)
7548a3129944Smrg	prev=os2dllname
7549a3129944Smrg	continue
7550a3129944Smrg	;;
7551a3129944Smrg
7552698f425bSmrg      -o) prev=output ;;
7553266e564dSmrg
7554698f425bSmrg      -precious-files-regex)
7555698f425bSmrg	prev=precious_regex
7556698f425bSmrg	continue
7557698f425bSmrg	;;
7558266e564dSmrg
7559698f425bSmrg      -release)
7560698f425bSmrg	prev=release
7561698f425bSmrg	continue
7562698f425bSmrg	;;
7563266e564dSmrg
7564698f425bSmrg      -rpath)
7565698f425bSmrg	prev=rpath
7566698f425bSmrg	continue
7567698f425bSmrg	;;
7568266e564dSmrg
7569698f425bSmrg      -R)
7570698f425bSmrg	prev=xrpath
7571698f425bSmrg	continue
7572698f425bSmrg	;;
7573266e564dSmrg
7574698f425bSmrg      -R*)
7575698f425bSmrg	func_stripname '-R' '' "$arg"
7576698f425bSmrg	dir=$func_stripname_result
7577698f425bSmrg	# We need an absolute path.
7578698f425bSmrg	case $dir in
7579698f425bSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
75809ef0b394Smrg	=*)
75819ef0b394Smrg	  func_stripname '=' '' "$dir"
75829ef0b394Smrg	  dir=$lt_sysroot$func_stripname_result
75839ef0b394Smrg	  ;;
7584698f425bSmrg	*)
75853bf3b463Smrg	  func_fatal_error "argument ($arg) to '-R' is not an absolute path: $dir"
7586698f425bSmrg	  ;;
7587698f425bSmrg	esac
7588698f425bSmrg	case "$xrpath " in
7589698f425bSmrg	*" $dir "*) ;;
75909ef0b394Smrg	*) func_append xrpath " $dir" ;;
7591698f425bSmrg	esac
7592698f425bSmrg	continue
7593698f425bSmrg	;;
7594266e564dSmrg
7595698f425bSmrg      -shared)
7596698f425bSmrg	# The effects of -shared are defined in a previous loop.
7597698f425bSmrg	continue
7598698f425bSmrg	;;
7599266e564dSmrg
7600698f425bSmrg      -shrext)
7601698f425bSmrg	prev=shrext
7602698f425bSmrg	continue
7603698f425bSmrg	;;
7604266e564dSmrg
7605698f425bSmrg      -static | -static-libtool-libs)
7606698f425bSmrg	# The effects of -static are defined in a previous loop.
7607698f425bSmrg	# We used to do the same as -all-static on platforms that
7608698f425bSmrg	# didn't have a PIC flag, but the assumption that the effects
7609698f425bSmrg	# would be equivalent was wrong.  It would break on at least
7610698f425bSmrg	# Digital Unix and AIX.
7611698f425bSmrg	continue
7612698f425bSmrg	;;
7613266e564dSmrg
7614698f425bSmrg      -thread-safe)
7615698f425bSmrg	thread_safe=yes
7616698f425bSmrg	continue
7617698f425bSmrg	;;
7618266e564dSmrg
7619698f425bSmrg      -version-info)
7620698f425bSmrg	prev=vinfo
7621698f425bSmrg	continue
7622698f425bSmrg	;;
7623266e564dSmrg
7624698f425bSmrg      -version-number)
7625698f425bSmrg	prev=vinfo
7626698f425bSmrg	vinfo_number=yes
7627698f425bSmrg	continue
7628698f425bSmrg	;;
7629266e564dSmrg
7630698f425bSmrg      -weak)
7631698f425bSmrg        prev=weak
7632698f425bSmrg	continue
7633698f425bSmrg	;;
7634266e564dSmrg
7635698f425bSmrg      -Wc,*)
7636698f425bSmrg	func_stripname '-Wc,' '' "$arg"
7637698f425bSmrg	args=$func_stripname_result
7638698f425bSmrg	arg=
7639a3129944Smrg	save_ifs=$IFS; IFS=,
7640698f425bSmrg	for flag in $args; do
7641a3129944Smrg	  IFS=$save_ifs
76421009a292Smrg          func_quote_arg pretty "$flag"
76431009a292Smrg	  func_append arg " $func_quote_arg_result"
76441009a292Smrg	  func_append compiler_flags " $func_quote_arg_result"
7645698f425bSmrg	done
7646a3129944Smrg	IFS=$save_ifs
7647698f425bSmrg	func_stripname ' ' '' "$arg"
7648698f425bSmrg	arg=$func_stripname_result
7649698f425bSmrg	;;
7650266e564dSmrg
7651698f425bSmrg      -Wl,*)
7652698f425bSmrg	func_stripname '-Wl,' '' "$arg"
7653698f425bSmrg	args=$func_stripname_result
7654698f425bSmrg	arg=
7655a3129944Smrg	save_ifs=$IFS; IFS=,
7656698f425bSmrg	for flag in $args; do
7657a3129944Smrg	  IFS=$save_ifs
76581009a292Smrg          func_quote_arg pretty "$flag"
76591009a292Smrg	  func_append arg " $wl$func_quote_arg_result"
76601009a292Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
76611009a292Smrg	  func_append linker_flags " $func_quote_arg_result"
7662698f425bSmrg	done
7663a3129944Smrg	IFS=$save_ifs
7664698f425bSmrg	func_stripname ' ' '' "$arg"
7665698f425bSmrg	arg=$func_stripname_result
7666698f425bSmrg	;;
7667266e564dSmrg
76681009a292Smrg      -Xassembler)
76691009a292Smrg        prev=xassembler
76701009a292Smrg        continue
76711009a292Smrg        ;;
76721009a292Smrg
7673698f425bSmrg      -Xcompiler)
7674698f425bSmrg	prev=xcompiler
7675698f425bSmrg	continue
7676698f425bSmrg	;;
7677266e564dSmrg
7678698f425bSmrg      -Xlinker)
7679698f425bSmrg	prev=xlinker
7680698f425bSmrg	continue
7681698f425bSmrg	;;
7682266e564dSmrg
7683698f425bSmrg      -XCClinker)
7684698f425bSmrg	prev=xcclinker
7685698f425bSmrg	continue
7686698f425bSmrg	;;
7687266e564dSmrg
7688698f425bSmrg      # -msg_* for osf cc
7689698f425bSmrg      -msg_*)
76901009a292Smrg	func_quote_arg pretty "$arg"
76911009a292Smrg	arg=$func_quote_arg_result
7692698f425bSmrg	;;
7693266e564dSmrg
76949ef0b394Smrg      # Flags to be passed through unchanged, with rationale:
76959ef0b394Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
76969ef0b394Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
76979ef0b394Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
76989ef0b394Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
76999ef0b394Smrg      # -q*                  compiler args for the IBM compiler
77009ef0b394Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
77019ef0b394Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
77029ef0b394Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7703a3129944Smrg      # -fstack-protector*   stack protector flags for GCC
77049ef0b394Smrg      # @file                GCC response files
77059ef0b394Smrg      # -tp=*                Portland pgcc target processor selection
77069ef0b394Smrg      # --sysroot=*          for sysroot support
7707a3129944Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
77081009a292Smrg      # -specs=*             GCC specs files
7709a3129944Smrg      # -stdlib=*            select c++ std lib with clang
77103bf3b463Smrg      # -fdiagnostics-color* simply affects output
77113bf3b463Smrg      # -frecord-gcc-switches used to verify flags were respected
77121009a292Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
77133bf3b463Smrg      # -fno-sanitize*       Clang/GCC memory and address sanitizer
77143bf3b463Smrg      # -shared-libsan       Link with shared sanitizer runtimes (Clang)
77153bf3b463Smrg      # -static-libsan       Link with static sanitizer runtimes (Clang)
77163bf3b463Smrg      # -no-canonical-prefixes Do not expand any symbolic links
77171009a292Smrg      # -fuse-ld=*           Linker select flags for GCC
77183bf3b463Smrg      # -static-*            direct GCC to link specific libraries statically
77193bf3b463Smrg      # -fcilkplus           Cilk Plus language extension features for C/C++
77203bf3b463Smrg      # -rtlib=*             select c runtime lib with clang
77213bf3b463Smrg      # --unwindlib=*        select unwinder library with clang
77223bf3b463Smrg      # -f{file|debug|macro|profile}-prefix-map=* needed for lto linking
77231009a292Smrg      # -Wa,*                Pass flags directly to the assembler
77243bf3b463Smrg      # -Werror, -Werror=*   Report (specified) warnings as errors
7725698f425bSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
77269ef0b394Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
77273bf3b463Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
77283bf3b463Smrg      -stdlib=*|-rtlib=*|--unwindlib=*| \
77293bf3b463Smrg      -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
77303bf3b463Smrg      -ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \
77313bf3b463Smrg      -fdiagnostics-color*|-frecord-gcc-switches| \
77323bf3b463Smrg      -fuse-ld=*|-static-*|-fcilkplus|-Wa,*|-Werror|-Werror=*)
77331009a292Smrg        func_quote_arg pretty "$arg"
77341009a292Smrg	arg=$func_quote_arg_result
7735698f425bSmrg        func_append compile_command " $arg"
7736698f425bSmrg        func_append finalize_command " $arg"
77379ef0b394Smrg        func_append compiler_flags " $arg"
7738698f425bSmrg        continue
7739698f425bSmrg        ;;
7740266e564dSmrg
7741a3129944Smrg      -Z*)
7742a3129944Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7743a3129944Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7744a3129944Smrg	  compiler_flags="$compiler_flags $arg"
7745a3129944Smrg	  func_append compile_command " $arg"
7746a3129944Smrg	  func_append finalize_command " $arg"
7747a3129944Smrg	  case $arg in
7748a3129944Smrg	  -Zlinker | -Zstack)
7749a3129944Smrg	    prev=xcompiler
7750a3129944Smrg	    ;;
7751a3129944Smrg	  esac
7752a3129944Smrg	  continue
7753a3129944Smrg        else
7754a3129944Smrg	  # Otherwise treat like 'Some other compiler flag' below
77551009a292Smrg	  func_quote_arg pretty "$arg"
77561009a292Smrg	  arg=$func_quote_arg_result
7757a3129944Smrg        fi
7758a3129944Smrg	;;
7759a3129944Smrg
7760698f425bSmrg      # Some other compiler flag.
7761698f425bSmrg      -* | +*)
77621009a292Smrg        func_quote_arg pretty "$arg"
77631009a292Smrg	arg=$func_quote_arg_result
7764698f425bSmrg	;;
7765266e564dSmrg
7766698f425bSmrg      *.$objext)
7767698f425bSmrg	# A standard object.
77689ef0b394Smrg	func_append objs " $arg"
7769698f425bSmrg	;;
7770266e564dSmrg
7771698f425bSmrg      *.lo)
7772698f425bSmrg	# A libtool-controlled object.
7773266e564dSmrg
7774698f425bSmrg	# Check to see that this really is a libtool object.
7775698f425bSmrg	if func_lalib_unsafe_p "$arg"; then
7776698f425bSmrg	  pic_object=
7777698f425bSmrg	  non_pic_object=
7778266e564dSmrg
7779698f425bSmrg	  # Read the .lo file
7780698f425bSmrg	  func_source "$arg"
7781266e564dSmrg
7782698f425bSmrg	  if test -z "$pic_object" ||
7783698f425bSmrg	     test -z "$non_pic_object" ||
7784a3129944Smrg	     test none = "$pic_object" &&
7785a3129944Smrg	     test none = "$non_pic_object"; then
7786a3129944Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7787698f425bSmrg	  fi
7788c5629e66Smrg
7789698f425bSmrg	  # Extract subdirectory from the argument.
7790698f425bSmrg	  func_dirname "$arg" "/" ""
7791a3129944Smrg	  xdir=$func_dirname_result
7792266e564dSmrg
7793a3129944Smrg	  test none = "$pic_object" || {
7794698f425bSmrg	    # Prepend the subdirectory the object is found in.
7795a3129944Smrg	    pic_object=$xdir$pic_object
7796266e564dSmrg
7797a3129944Smrg	    if test dlfiles = "$prev"; then
7798a3129944Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
77999ef0b394Smrg		func_append dlfiles " $pic_object"
7800698f425bSmrg		prev=
7801698f425bSmrg		continue
7802698f425bSmrg	      else
7803698f425bSmrg		# If libtool objects are unsupported, then we need to preload.
7804698f425bSmrg		prev=dlprefiles
7805698f425bSmrg	      fi
7806698f425bSmrg	    fi
7807266e564dSmrg
7808698f425bSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7809a3129944Smrg	    if test dlprefiles = "$prev"; then
7810698f425bSmrg	      # Preload the old-style object.
78119ef0b394Smrg	      func_append dlprefiles " $pic_object"
7812698f425bSmrg	      prev=
7813698f425bSmrg	    fi
7814266e564dSmrg
7815698f425bSmrg	    # A PIC object.
7816698f425bSmrg	    func_append libobjs " $pic_object"
7817a3129944Smrg	    arg=$pic_object
7818a3129944Smrg	  }
7819266e564dSmrg
7820698f425bSmrg	  # Non-PIC object.
7821a3129944Smrg	  if test none != "$non_pic_object"; then
7822698f425bSmrg	    # Prepend the subdirectory the object is found in.
7823a3129944Smrg	    non_pic_object=$xdir$non_pic_object
7824266e564dSmrg
7825698f425bSmrg	    # A standard non-PIC object
7826698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7827a3129944Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7828a3129944Smrg	      arg=$non_pic_object
7829698f425bSmrg	    fi
7830698f425bSmrg	  else
7831698f425bSmrg	    # If the PIC object exists, use it instead.
7832698f425bSmrg	    # $xdir was prepended to $pic_object above.
7833a3129944Smrg	    non_pic_object=$pic_object
7834698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7835698f425bSmrg	  fi
7836698f425bSmrg	else
7837698f425bSmrg	  # Only an error if not doing a dry-run.
7838698f425bSmrg	  if $opt_dry_run; then
7839698f425bSmrg	    # Extract subdirectory from the argument.
7840698f425bSmrg	    func_dirname "$arg" "/" ""
7841a3129944Smrg	    xdir=$func_dirname_result
7842698f425bSmrg
7843698f425bSmrg	    func_lo2o "$arg"
7844698f425bSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
7845698f425bSmrg	    non_pic_object=$xdir$func_lo2o_result
7846698f425bSmrg	    func_append libobjs " $pic_object"
7847698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7848698f425bSmrg	  else
7849a3129944Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7850698f425bSmrg	  fi
7851698f425bSmrg	fi
7852698f425bSmrg	;;
7853698f425bSmrg
7854698f425bSmrg      *.$libext)
7855698f425bSmrg	# An archive.
78569ef0b394Smrg	func_append deplibs " $arg"
78579ef0b394Smrg	func_append old_deplibs " $arg"
7858698f425bSmrg	continue
7859698f425bSmrg	;;
7860698f425bSmrg
7861698f425bSmrg      *.la)
7862698f425bSmrg	# A libtool-controlled library.
7863698f425bSmrg
78649ef0b394Smrg	func_resolve_sysroot "$arg"
7865a3129944Smrg	if test dlfiles = "$prev"; then
7866698f425bSmrg	  # This library was specified with -dlopen.
78679ef0b394Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7868698f425bSmrg	  prev=
7869a3129944Smrg	elif test dlprefiles = "$prev"; then
7870698f425bSmrg	  # The library was specified with -dlpreopen.
78719ef0b394Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7872698f425bSmrg	  prev=
7873698f425bSmrg	else
78749ef0b394Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7875698f425bSmrg	fi
7876698f425bSmrg	continue
7877698f425bSmrg	;;
7878698f425bSmrg
7879698f425bSmrg      # Some other compiler argument.
7880698f425bSmrg      *)
7881698f425bSmrg	# Unknown arguments in both finalize_command and compile_command need
7882698f425bSmrg	# to be aesthetically quoted because they are evaled later.
78831009a292Smrg	func_quote_arg pretty "$arg"
78841009a292Smrg	arg=$func_quote_arg_result
7885698f425bSmrg	;;
7886698f425bSmrg      esac # arg
7887698f425bSmrg
7888698f425bSmrg      # Now actually substitute the argument into the commands.
7889698f425bSmrg      if test -n "$arg"; then
78903bf3b463Smrg	if test -n "$rpath_arg"; then
78913bf3b463Smrg          func_append finalize_rpath " ${arg##*,}"
78923bf3b463Smrg	  unset rpath_arg
78933bf3b463Smrg	else
78943bf3b463Smrg	  case $arg in
78953bf3b463Smrg          -Wl,-rpath,*)
78963bf3b463Smrg	    func_append finalize_rpath " ${arg##*,}";;
78973bf3b463Smrg          -Wl,-rpath)
78983bf3b463Smrg	    rpath_arg=1;;
78993bf3b463Smrg          *)
79003bf3b463Smrg            func_append compile_command " $arg"
79013bf3b463Smrg	    func_append finalize_command " $arg"
79023bf3b463Smrg	  esac
79033bf3b463Smrg        fi
7904698f425bSmrg      fi
7905698f425bSmrg    done # argument parsing loop
7906698f425bSmrg
7907698f425bSmrg    test -n "$prev" && \
7908a3129944Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7909698f425bSmrg
7910a3129944Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7911698f425bSmrg      eval arg=\"$export_dynamic_flag_spec\"
7912698f425bSmrg      func_append compile_command " $arg"
7913698f425bSmrg      func_append finalize_command " $arg"
7914698f425bSmrg    fi
7915698f425bSmrg
7916698f425bSmrg    oldlibs=
7917698f425bSmrg    # calculate the name of the file, without its directory
7918698f425bSmrg    func_basename "$output"
7919a3129944Smrg    outputname=$func_basename_result
7920a3129944Smrg    libobjs_save=$libobjs
7921698f425bSmrg
7922698f425bSmrg    if test -n "$shlibpath_var"; then
7923698f425bSmrg      # get the directories listed in $shlibpath_var
7924a3129944Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7925698f425bSmrg    else
7926698f425bSmrg      shlib_search_path=
7927698f425bSmrg    fi
7928698f425bSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7929698f425bSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7930698f425bSmrg
7931a3129944Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7932a3129944Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7933a3129944Smrg
7934698f425bSmrg    func_dirname "$output" "/" ""
7935a3129944Smrg    output_objdir=$func_dirname_result$objdir
79369ef0b394Smrg    func_to_tool_file "$output_objdir/"
79379ef0b394Smrg    tool_output_objdir=$func_to_tool_file_result
7938698f425bSmrg    # Create the object directory.
7939698f425bSmrg    func_mkdir_p "$output_objdir"
7940698f425bSmrg
7941698f425bSmrg    # Determine the type of output
7942698f425bSmrg    case $output in
7943698f425bSmrg    "")
7944698f425bSmrg      func_fatal_help "you must specify an output file"
7945698f425bSmrg      ;;
7946698f425bSmrg    *.$libext) linkmode=oldlib ;;
7947698f425bSmrg    *.lo | *.$objext) linkmode=obj ;;
7948698f425bSmrg    *.la) linkmode=lib ;;
7949698f425bSmrg    *) linkmode=prog ;; # Anything else should be a program.
7950698f425bSmrg    esac
7951698f425bSmrg
7952698f425bSmrg    specialdeplibs=
7953698f425bSmrg
7954698f425bSmrg    libs=
7955698f425bSmrg    # Find all interdependent deplibs by searching for libraries
7956698f425bSmrg    # that are linked more than once (e.g. -la -lb -la)
7957698f425bSmrg    for deplib in $deplibs; do
7958a3129944Smrg      if $opt_preserve_dup_deps; then
7959698f425bSmrg	case "$libs " in
79609ef0b394Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7961698f425bSmrg	esac
7962698f425bSmrg      fi
79639ef0b394Smrg      func_append libs " $deplib"
7964698f425bSmrg    done
7965698f425bSmrg
7966a3129944Smrg    if test lib = "$linkmode"; then
7967698f425bSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7968698f425bSmrg
7969698f425bSmrg      # Compute libraries that are listed more than once in $predeps
7970698f425bSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
7971698f425bSmrg      # not to be eliminated).
7972698f425bSmrg      pre_post_deps=
7973698f425bSmrg      if $opt_duplicate_compiler_generated_deps; then
7974698f425bSmrg	for pre_post_dep in $predeps $postdeps; do
7975698f425bSmrg	  case "$pre_post_deps " in
79769ef0b394Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7977698f425bSmrg	  esac
79789ef0b394Smrg	  func_append pre_post_deps " $pre_post_dep"
7979698f425bSmrg	done
7980698f425bSmrg      fi
7981698f425bSmrg      pre_post_deps=
7982698f425bSmrg    fi
7983698f425bSmrg
7984698f425bSmrg    deplibs=
7985698f425bSmrg    newdependency_libs=
7986698f425bSmrg    newlib_search_path=
7987698f425bSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7988698f425bSmrg    notinst_deplibs= # not-installed libtool libraries
7989698f425bSmrg    notinst_path= # paths that contain not-installed libtool libraries
7990698f425bSmrg
7991698f425bSmrg    case $linkmode in
7992698f425bSmrg    lib)
7993698f425bSmrg	passes="conv dlpreopen link"
7994698f425bSmrg	for file in $dlfiles $dlprefiles; do
7995698f425bSmrg	  case $file in
7996698f425bSmrg	  *.la) ;;
7997698f425bSmrg	  *)
7998a3129944Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7999698f425bSmrg	    ;;
8000698f425bSmrg	  esac
8001698f425bSmrg	done
8002698f425bSmrg	;;
8003698f425bSmrg    prog)
8004698f425bSmrg	compile_deplibs=
8005698f425bSmrg	finalize_deplibs=
8006a3129944Smrg	alldeplibs=false
8007698f425bSmrg	newdlfiles=
8008698f425bSmrg	newdlprefiles=
8009698f425bSmrg	passes="conv scan dlopen dlpreopen link"
8010698f425bSmrg	;;
8011698f425bSmrg    *)  passes="conv"
8012698f425bSmrg	;;
8013698f425bSmrg    esac
8014698f425bSmrg
8015698f425bSmrg    for pass in $passes; do
8016698f425bSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
8017698f425bSmrg      # so that -L comes before libs that need it for instance...
8018a3129944Smrg      if test lib,link = "$linkmode,$pass"; then
8019698f425bSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
8020698f425bSmrg	##        order, and fix it there properly
8021698f425bSmrg        tmp_deplibs=
8022698f425bSmrg	for deplib in $deplibs; do
8023698f425bSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
8024698f425bSmrg	done
8025a3129944Smrg	deplibs=$tmp_deplibs
8026698f425bSmrg      fi
8027698f425bSmrg
8028a3129944Smrg      if test lib,link = "$linkmode,$pass" ||
8029a3129944Smrg	 test prog,scan = "$linkmode,$pass"; then
8030a3129944Smrg	libs=$deplibs
8031698f425bSmrg	deplibs=
8032698f425bSmrg      fi
8033a3129944Smrg      if test prog = "$linkmode"; then
8034698f425bSmrg	case $pass in
8035a3129944Smrg	dlopen) libs=$dlfiles ;;
8036a3129944Smrg	dlpreopen) libs=$dlprefiles ;;
8037698f425bSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
8038698f425bSmrg	esac
8039698f425bSmrg      fi
8040a3129944Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
8041698f425bSmrg	# Collect and forward deplibs of preopened libtool libs
8042698f425bSmrg	for lib in $dlprefiles; do
8043698f425bSmrg	  # Ignore non-libtool-libs
8044698f425bSmrg	  dependency_libs=
80459ef0b394Smrg	  func_resolve_sysroot "$lib"
8046698f425bSmrg	  case $lib in
80479ef0b394Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
8048698f425bSmrg	  esac
8049698f425bSmrg
8050698f425bSmrg	  # Collect preopened libtool deplibs, except any this library
8051698f425bSmrg	  # has declared as weak libs
8052698f425bSmrg	  for deplib in $dependency_libs; do
80539ef0b394Smrg	    func_basename "$deplib"
80549ef0b394Smrg            deplib_base=$func_basename_result
8055698f425bSmrg	    case " $weak_libs " in
8056698f425bSmrg	    *" $deplib_base "*) ;;
80579ef0b394Smrg	    *) func_append deplibs " $deplib" ;;
8058698f425bSmrg	    esac
8059698f425bSmrg	  done
8060698f425bSmrg	done
8061a3129944Smrg	libs=$dlprefiles
8062698f425bSmrg      fi
8063a3129944Smrg      if test dlopen = "$pass"; then
8064698f425bSmrg	# Collect dlpreopened libraries
8065a3129944Smrg	save_deplibs=$deplibs
8066698f425bSmrg	deplibs=
8067698f425bSmrg      fi
8068698f425bSmrg
8069698f425bSmrg      for deplib in $libs; do
8070698f425bSmrg	lib=
8071a3129944Smrg	found=false
8072698f425bSmrg	case $deplib in
8073fb5e8d76Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
80743bf3b463Smrg        |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
8075a3129944Smrg	  if test prog,link = "$linkmode,$pass"; then
8076698f425bSmrg	    compile_deplibs="$deplib $compile_deplibs"
8077698f425bSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
8078698f425bSmrg	  else
80799ef0b394Smrg	    func_append compiler_flags " $deplib"
8080a3129944Smrg	    if test lib = "$linkmode"; then
8081698f425bSmrg		case "$new_inherited_linker_flags " in
8082698f425bSmrg		    *" $deplib "*) ;;
80839ef0b394Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8084698f425bSmrg		esac
8085698f425bSmrg	    fi
8086698f425bSmrg	  fi
8087698f425bSmrg	  continue
8088698f425bSmrg	  ;;
8089698f425bSmrg	-l*)
8090a3129944Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
8091a3129944Smrg	    func_warning "'-l' is ignored for archives/objects"
8092698f425bSmrg	    continue
8093698f425bSmrg	  fi
8094698f425bSmrg	  func_stripname '-l' '' "$deplib"
8095698f425bSmrg	  name=$func_stripname_result
8096a3129944Smrg	  if test lib = "$linkmode"; then
8097698f425bSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
8098698f425bSmrg	  else
8099698f425bSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
8100698f425bSmrg	  fi
8101698f425bSmrg	  for searchdir in $searchdirs; do
8102698f425bSmrg	    for search_ext in .la $std_shrext .so .a; do
8103698f425bSmrg	      # Search the libtool library
8104a3129944Smrg	      lib=$searchdir/lib$name$search_ext
8105698f425bSmrg	      if test -f "$lib"; then
8106a3129944Smrg		if test .la = "$search_ext"; then
8107a3129944Smrg		  found=:
8108698f425bSmrg		else
8109a3129944Smrg		  found=false
8110698f425bSmrg		fi
8111698f425bSmrg		break 2
8112698f425bSmrg	      fi
8113698f425bSmrg	    done
8114698f425bSmrg	  done
8115a3129944Smrg	  if $found; then
8116a3129944Smrg	    # deplib is a libtool library
8117698f425bSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
8118698f425bSmrg	    # We need to do some special things here, and not later.
8119a3129944Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
8120698f425bSmrg	      case " $predeps $postdeps " in
8121698f425bSmrg	      *" $deplib "*)
8122698f425bSmrg		if func_lalib_p "$lib"; then
8123698f425bSmrg		  library_names=
8124698f425bSmrg		  old_library=
8125698f425bSmrg		  func_source "$lib"
8126698f425bSmrg		  for l in $old_library $library_names; do
8127a3129944Smrg		    ll=$l
8128698f425bSmrg		  done
8129a3129944Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
8130a3129944Smrg		    found=false
8131698f425bSmrg		    func_dirname "$lib" "" "."
8132a3129944Smrg		    ladir=$func_dirname_result
8133698f425bSmrg		    lib=$ladir/$old_library
8134a3129944Smrg		    if test prog,link = "$linkmode,$pass"; then
8135698f425bSmrg		      compile_deplibs="$deplib $compile_deplibs"
8136698f425bSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
8137698f425bSmrg		    else
8138698f425bSmrg		      deplibs="$deplib $deplibs"
8139a3129944Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8140698f425bSmrg		    fi
8141698f425bSmrg		    continue
8142698f425bSmrg		  fi
8143698f425bSmrg		fi
8144698f425bSmrg		;;
8145698f425bSmrg	      *) ;;
8146698f425bSmrg	      esac
8147698f425bSmrg	    fi
8148a3129944Smrg	  else
8149a3129944Smrg	    # deplib doesn't seem to be a libtool library
8150a3129944Smrg	    if test prog,link = "$linkmode,$pass"; then
8151a3129944Smrg	      compile_deplibs="$deplib $compile_deplibs"
8152a3129944Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8153a3129944Smrg	    else
8154a3129944Smrg	      deplibs="$deplib $deplibs"
8155a3129944Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8156a3129944Smrg	    fi
8157a3129944Smrg	    continue
8158698f425bSmrg	  fi
8159698f425bSmrg	  ;; # -l
8160698f425bSmrg	*.ltframework)
8161a3129944Smrg	  if test prog,link = "$linkmode,$pass"; then
8162698f425bSmrg	    compile_deplibs="$deplib $compile_deplibs"
8163698f425bSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
8164698f425bSmrg	  else
8165698f425bSmrg	    deplibs="$deplib $deplibs"
8166a3129944Smrg	    if test lib = "$linkmode"; then
8167698f425bSmrg		case "$new_inherited_linker_flags " in
8168698f425bSmrg		    *" $deplib "*) ;;
81699ef0b394Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8170698f425bSmrg		esac
8171698f425bSmrg	    fi
8172698f425bSmrg	  fi
8173698f425bSmrg	  continue
8174698f425bSmrg	  ;;
8175698f425bSmrg	-L*)
8176698f425bSmrg	  case $linkmode in
8177698f425bSmrg	  lib)
8178698f425bSmrg	    deplibs="$deplib $deplibs"
8179a3129944Smrg	    test conv = "$pass" && continue
8180698f425bSmrg	    newdependency_libs="$deplib $newdependency_libs"
8181698f425bSmrg	    func_stripname '-L' '' "$deplib"
81829ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
81839ef0b394Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8184698f425bSmrg	    ;;
8185698f425bSmrg	  prog)
8186a3129944Smrg	    if test conv = "$pass"; then
8187698f425bSmrg	      deplibs="$deplib $deplibs"
8188698f425bSmrg	      continue
8189698f425bSmrg	    fi
8190a3129944Smrg	    if test scan = "$pass"; then
8191698f425bSmrg	      deplibs="$deplib $deplibs"
8192698f425bSmrg	    else
8193698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
8194698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8195698f425bSmrg	    fi
8196698f425bSmrg	    func_stripname '-L' '' "$deplib"
81979ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
81989ef0b394Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8199698f425bSmrg	    ;;
8200698f425bSmrg	  *)
8201a3129944Smrg	    func_warning "'-L' is ignored for archives/objects"
8202698f425bSmrg	    ;;
8203698f425bSmrg	  esac # linkmode
8204698f425bSmrg	  continue
8205698f425bSmrg	  ;; # -L
8206698f425bSmrg	-R*)
8207a3129944Smrg	  if test link = "$pass"; then
8208698f425bSmrg	    func_stripname '-R' '' "$deplib"
82099ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
82109ef0b394Smrg	    dir=$func_resolve_sysroot_result
8211698f425bSmrg	    # Make sure the xrpath contains only unique directories.
8212698f425bSmrg	    case "$xrpath " in
8213698f425bSmrg	    *" $dir "*) ;;
82149ef0b394Smrg	    *) func_append xrpath " $dir" ;;
8215698f425bSmrg	    esac
8216698f425bSmrg	  fi
8217698f425bSmrg	  deplibs="$deplib $deplibs"
8218698f425bSmrg	  continue
8219698f425bSmrg	  ;;
82209ef0b394Smrg	*.la)
82219ef0b394Smrg	  func_resolve_sysroot "$deplib"
82229ef0b394Smrg	  lib=$func_resolve_sysroot_result
82239ef0b394Smrg	  ;;
8224698f425bSmrg	*.$libext)
8225a3129944Smrg	  if test conv = "$pass"; then
8226698f425bSmrg	    deplibs="$deplib $deplibs"
8227698f425bSmrg	    continue
8228698f425bSmrg	  fi
8229698f425bSmrg	  case $linkmode in
8230698f425bSmrg	  lib)
8231698f425bSmrg	    # Linking convenience modules into shared libraries is allowed,
8232698f425bSmrg	    # but linking other static libraries is non-portable.
8233698f425bSmrg	    case " $dlpreconveniencelibs " in
8234698f425bSmrg	    *" $deplib "*) ;;
8235698f425bSmrg	    *)
8236a3129944Smrg	      valid_a_lib=false
8237698f425bSmrg	      case $deplibs_check_method in
8238698f425bSmrg		match_pattern*)
8239698f425bSmrg		  set dummy $deplibs_check_method; shift
8240698f425bSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
82419ef0b394Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8242698f425bSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8243a3129944Smrg		    valid_a_lib=:
8244698f425bSmrg		  fi
8245698f425bSmrg		;;
8246698f425bSmrg		pass_all)
8247a3129944Smrg		  valid_a_lib=:
8248698f425bSmrg		;;
8249698f425bSmrg	      esac
8250a3129944Smrg	      if $valid_a_lib; then
82513bf3b463Smrg		func_warning "Linking the shared library $output against the static library $deplib is not portable!"
8252a3129944Smrg		deplibs="$deplib $deplibs"
8253a3129944Smrg	      else
82543bf3b463Smrg		func_warning "Trying to link with static lib archive $deplib."
82553bf3b463Smrg		func_warning "I have the capability to make that library automatically link in when"
82563bf3b463Smrg		func_warning "you link to this library.  But I can only do this if you have a"
82573bf3b463Smrg		func_warning "shared version of the library, which you do not appear to have"
82583bf3b463Smrg		func_warning "because the file extensions .$libext of this argument makes me believe"
82593bf3b463Smrg		func_warning "that it is just a static archive that I should not use here."
8260698f425bSmrg	      fi
8261698f425bSmrg	      ;;
8262698f425bSmrg	    esac
8263698f425bSmrg	    continue
8264698f425bSmrg	    ;;
8265698f425bSmrg	  prog)
8266a3129944Smrg	    if test link != "$pass"; then
8267698f425bSmrg	      deplibs="$deplib $deplibs"
8268698f425bSmrg	    else
8269698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
8270698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8271698f425bSmrg	    fi
8272698f425bSmrg	    continue
8273698f425bSmrg	    ;;
8274698f425bSmrg	  esac # linkmode
8275698f425bSmrg	  ;; # *.$libext
8276698f425bSmrg	*.lo | *.$objext)
8277a3129944Smrg	  if test conv = "$pass"; then
8278698f425bSmrg	    deplibs="$deplib $deplibs"
8279a3129944Smrg	  elif test prog = "$linkmode"; then
8280a3129944Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8281698f425bSmrg	      # If there is no dlopen support or we're linking statically,
8282698f425bSmrg	      # we need to preload.
82839ef0b394Smrg	      func_append newdlprefiles " $deplib"
8284698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
8285698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8286698f425bSmrg	    else
82879ef0b394Smrg	      func_append newdlfiles " $deplib"
8288698f425bSmrg	    fi
8289698f425bSmrg	  fi
8290698f425bSmrg	  continue
8291698f425bSmrg	  ;;
8292698f425bSmrg	%DEPLIBS%)
8293a3129944Smrg	  alldeplibs=:
8294698f425bSmrg	  continue
8295698f425bSmrg	  ;;
8296698f425bSmrg	esac # case $deplib
8297698f425bSmrg
8298a3129944Smrg	$found || test -f "$lib" \
8299a3129944Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8300698f425bSmrg
8301698f425bSmrg	# Check to see that this really is a libtool archive.
8302698f425bSmrg	func_lalib_unsafe_p "$lib" \
8303a3129944Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8304698f425bSmrg
8305698f425bSmrg	func_dirname "$lib" "" "."
8306a3129944Smrg	ladir=$func_dirname_result
8307698f425bSmrg
8308698f425bSmrg	dlname=
8309698f425bSmrg	dlopen=
8310698f425bSmrg	dlpreopen=
8311698f425bSmrg	libdir=
8312698f425bSmrg	library_names=
8313698f425bSmrg	old_library=
8314698f425bSmrg	inherited_linker_flags=
8315698f425bSmrg	# If the library was installed with an old release of libtool,
8316698f425bSmrg	# it will not redefine variables installed, or shouldnotlink
8317698f425bSmrg	installed=yes
8318698f425bSmrg	shouldnotlink=no
8319698f425bSmrg	avoidtemprpath=
8320698f425bSmrg
8321698f425bSmrg
8322698f425bSmrg	# Read the .la file
8323698f425bSmrg	func_source "$lib"
8324698f425bSmrg
8325698f425bSmrg	# Convert "-framework foo" to "foo.ltframework"
8326698f425bSmrg	if test -n "$inherited_linker_flags"; then
83279ef0b394Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8328698f425bSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8329698f425bSmrg	    case " $new_inherited_linker_flags " in
8330698f425bSmrg	      *" $tmp_inherited_linker_flag "*) ;;
83319ef0b394Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8332698f425bSmrg	    esac
8333698f425bSmrg	  done
8334698f425bSmrg	fi
83359ef0b394Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8336a3129944Smrg	if test lib,link = "$linkmode,$pass" ||
8337a3129944Smrg	   test prog,scan = "$linkmode,$pass" ||
8338a3129944Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
83399ef0b394Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
83409ef0b394Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8341698f425bSmrg	fi
8342698f425bSmrg
8343a3129944Smrg	if test conv = "$pass"; then
8344698f425bSmrg	  # Only check for convenience libraries
8345698f425bSmrg	  deplibs="$lib $deplibs"
8346698f425bSmrg	  if test -z "$libdir"; then
8347698f425bSmrg	    if test -z "$old_library"; then
8348a3129944Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
8349698f425bSmrg	    fi
8350698f425bSmrg	    # It is a libtool convenience library, so add in its objects.
83519ef0b394Smrg	    func_append convenience " $ladir/$objdir/$old_library"
83529ef0b394Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8353a3129944Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8354a3129944Smrg	    func_fatal_error "'$lib' is not a convenience library"
8355698f425bSmrg	  fi
8356698f425bSmrg	  tmp_libs=
8357698f425bSmrg	  for deplib in $dependency_libs; do
8358698f425bSmrg	    deplibs="$deplib $deplibs"
8359a3129944Smrg	    if $opt_preserve_dup_deps; then
8360698f425bSmrg	      case "$tmp_libs " in
83619ef0b394Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8362698f425bSmrg	      esac
8363698f425bSmrg	    fi
83649ef0b394Smrg	    func_append tmp_libs " $deplib"
8365698f425bSmrg	  done
8366698f425bSmrg	  continue
8367698f425bSmrg	fi # $pass = conv
8368698f425bSmrg
8369698f425bSmrg
8370698f425bSmrg	# Get the name of the library we link against.
8371698f425bSmrg	linklib=
83729ef0b394Smrg	if test -n "$old_library" &&
8373a3129944Smrg	   { test yes = "$prefer_static_libs" ||
8374a3129944Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
83759ef0b394Smrg	  linklib=$old_library
83769ef0b394Smrg	else
83779ef0b394Smrg	  for l in $old_library $library_names; do
8378a3129944Smrg	    linklib=$l
83799ef0b394Smrg	  done
83809ef0b394Smrg	fi
8381698f425bSmrg	if test -z "$linklib"; then
8382a3129944Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
8383698f425bSmrg	fi
8384698f425bSmrg
8385698f425bSmrg	# This library was specified with -dlopen.
8386a3129944Smrg	if test dlopen = "$pass"; then
8387a3129944Smrg	  test -z "$libdir" \
8388a3129944Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8389698f425bSmrg	  if test -z "$dlname" ||
8390a3129944Smrg	     test yes != "$dlopen_support" ||
8391a3129944Smrg	     test no = "$build_libtool_libs"
8392a3129944Smrg	  then
8393698f425bSmrg	    # If there is no dlname, no dlopen support or we're linking
8394698f425bSmrg	    # statically, we need to preload.  We also need to preload any
8395698f425bSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
8396698f425bSmrg	    # bomb out in the load deplibs phase.
83979ef0b394Smrg	    func_append dlprefiles " $lib $dependency_libs"
8398698f425bSmrg	  else
83999ef0b394Smrg	    func_append newdlfiles " $lib"
8400698f425bSmrg	  fi
8401698f425bSmrg	  continue
8402698f425bSmrg	fi # $pass = dlopen
8403698f425bSmrg
8404698f425bSmrg	# We need an absolute path.
8405698f425bSmrg	case $ladir in
8406a3129944Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8407698f425bSmrg	*)
8408698f425bSmrg	  abs_ladir=`cd "$ladir" && pwd`
8409698f425bSmrg	  if test -z "$abs_ladir"; then
8410a3129944Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8411698f425bSmrg	    func_warning "passing it literally to the linker, although it might fail"
8412a3129944Smrg	    abs_ladir=$ladir
8413698f425bSmrg	  fi
8414698f425bSmrg	  ;;
8415698f425bSmrg	esac
8416698f425bSmrg	func_basename "$lib"
8417a3129944Smrg	laname=$func_basename_result
8418698f425bSmrg
8419698f425bSmrg	# Find the relevant object directory and library name.
8420a3129944Smrg	if test yes = "$installed"; then
84219ef0b394Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8422a3129944Smrg	    func_warning "library '$lib' was moved."
8423a3129944Smrg	    dir=$ladir
8424a3129944Smrg	    absdir=$abs_ladir
8425a3129944Smrg	    libdir=$abs_ladir
8426698f425bSmrg	  else
8427a3129944Smrg	    dir=$lt_sysroot$libdir
8428a3129944Smrg	    absdir=$lt_sysroot$libdir
8429698f425bSmrg	  fi
8430a3129944Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8431698f425bSmrg	else
8432698f425bSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8433a3129944Smrg	    dir=$ladir
8434a3129944Smrg	    absdir=$abs_ladir
8435698f425bSmrg	    # Remove this search path later
84369ef0b394Smrg	    func_append notinst_path " $abs_ladir"
8437698f425bSmrg	  else
8438a3129944Smrg	    dir=$ladir/$objdir
8439a3129944Smrg	    absdir=$abs_ladir/$objdir
8440698f425bSmrg	    # Remove this search path later
84419ef0b394Smrg	    func_append notinst_path " $abs_ladir"
8442698f425bSmrg	  fi
8443698f425bSmrg	fi # $installed = yes
8444698f425bSmrg	func_stripname 'lib' '.la' "$laname"
8445698f425bSmrg	name=$func_stripname_result
8446698f425bSmrg
8447698f425bSmrg	# This library was specified with -dlpreopen.
8448a3129944Smrg	if test dlpreopen = "$pass"; then
8449a3129944Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8450a3129944Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8451698f425bSmrg	  fi
8452a3129944Smrg	  case $host in
84539ef0b394Smrg	    # special handling for platforms with PE-DLLs.
84543bf3b463Smrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
84559ef0b394Smrg	      # Linker will automatically link against shared library if both
84569ef0b394Smrg	      # static and shared are present.  Therefore, ensure we extract
84579ef0b394Smrg	      # symbols from the import library if a shared library is present
84589ef0b394Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
84599ef0b394Smrg	      # this by putting the import library name into $newdlprefiles.
84609ef0b394Smrg	      # We recover the dlopen module name by 'saving' the la file
84619ef0b394Smrg	      # name in a special purpose variable, and (later) extracting the
84629ef0b394Smrg	      # dlname from the la file.
84639ef0b394Smrg	      if test -n "$dlname"; then
84649ef0b394Smrg	        func_tr_sh "$dir/$linklib"
84659ef0b394Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
84669ef0b394Smrg	        func_append newdlprefiles " $dir/$linklib"
84679ef0b394Smrg	      else
84689ef0b394Smrg	        func_append newdlprefiles " $dir/$old_library"
84699ef0b394Smrg	        # Keep a list of preopened convenience libraries to check
84709ef0b394Smrg	        # that they are being used correctly in the link pass.
84719ef0b394Smrg	        test -z "$libdir" && \
84729ef0b394Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
84739ef0b394Smrg	      fi
84749ef0b394Smrg	    ;;
84759ef0b394Smrg	    * )
84769ef0b394Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
84779ef0b394Smrg	      # are required to link).
84789ef0b394Smrg	      if test -n "$old_library"; then
84799ef0b394Smrg	        func_append newdlprefiles " $dir/$old_library"
84809ef0b394Smrg	        # Keep a list of preopened convenience libraries to check
84819ef0b394Smrg	        # that they are being used correctly in the link pass.
84829ef0b394Smrg	        test -z "$libdir" && \
84839ef0b394Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
84849ef0b394Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
84859ef0b394Smrg	      elif test -n "$dlname"; then
84869ef0b394Smrg	        func_append newdlprefiles " $dir/$dlname"
84879ef0b394Smrg	      else
84889ef0b394Smrg	        func_append newdlprefiles " $dir/$linklib"
84899ef0b394Smrg	      fi
84909ef0b394Smrg	    ;;
84919ef0b394Smrg	  esac
8492698f425bSmrg	fi # $pass = dlpreopen
8493698f425bSmrg
8494698f425bSmrg	if test -z "$libdir"; then
8495698f425bSmrg	  # Link the convenience library
8496a3129944Smrg	  if test lib = "$linkmode"; then
8497698f425bSmrg	    deplibs="$dir/$old_library $deplibs"
8498a3129944Smrg	  elif test prog,link = "$linkmode,$pass"; then
8499698f425bSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8500698f425bSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8501698f425bSmrg	  else
8502698f425bSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8503698f425bSmrg	  fi
8504698f425bSmrg	  continue
8505698f425bSmrg	fi
8506698f425bSmrg
8507698f425bSmrg
8508a3129944Smrg	if test prog = "$linkmode" && test link != "$pass"; then
85099ef0b394Smrg	  func_append newlib_search_path " $ladir"
8510698f425bSmrg	  deplibs="$lib $deplibs"
8511698f425bSmrg
8512a3129944Smrg	  linkalldeplibs=false
8513a3129944Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8514a3129944Smrg	     test no = "$build_libtool_libs"; then
8515a3129944Smrg	    linkalldeplibs=:
8516698f425bSmrg	  fi
8517698f425bSmrg
8518698f425bSmrg	  tmp_libs=
8519698f425bSmrg	  for deplib in $dependency_libs; do
8520698f425bSmrg	    case $deplib in
8521698f425bSmrg	    -L*) func_stripname '-L' '' "$deplib"
85229ef0b394Smrg	         func_resolve_sysroot "$func_stripname_result"
85239ef0b394Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8524698f425bSmrg		 ;;
8525698f425bSmrg	    esac
8526698f425bSmrg	    # Need to link against all dependency_libs?
8527a3129944Smrg	    if $linkalldeplibs; then
8528698f425bSmrg	      deplibs="$deplib $deplibs"
8529698f425bSmrg	    else
8530698f425bSmrg	      # Need to hardcode shared library paths
8531698f425bSmrg	      # or/and link against static libraries
8532698f425bSmrg	      newdependency_libs="$deplib $newdependency_libs"
8533698f425bSmrg	    fi
8534a3129944Smrg	    if $opt_preserve_dup_deps; then
8535698f425bSmrg	      case "$tmp_libs " in
85369ef0b394Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8537698f425bSmrg	      esac
8538698f425bSmrg	    fi
85399ef0b394Smrg	    func_append tmp_libs " $deplib"
8540698f425bSmrg	  done # for deplib
8541698f425bSmrg	  continue
8542698f425bSmrg	fi # $linkmode = prog...
8543698f425bSmrg
8544a3129944Smrg	if test prog,link = "$linkmode,$pass"; then
8545698f425bSmrg	  if test -n "$library_names" &&
8546a3129944Smrg	     { { test no = "$prefer_static_libs" ||
8547a3129944Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8548698f425bSmrg	       test -z "$old_library"; }; then
8549698f425bSmrg	    # We need to hardcode the library path
8550a3129944Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8551698f425bSmrg	      # Make sure the rpath contains only unique directories.
8552a3129944Smrg	      case $temp_rpath: in
8553698f425bSmrg	      *"$absdir:"*) ;;
85543bf3b463Smrg              *) case $absdir in
85553bf3b463Smrg                 "$progdir/"*) func_append temp_rpath "$absdir:" ;;
85563bf3b463Smrg                 *)            func_append temp_rpath_tail "$absdir:" ;;
85573bf3b463Smrg                 esac
8558698f425bSmrg	      esac
8559698f425bSmrg	    fi
8560698f425bSmrg
8561698f425bSmrg	    # Hardcode the library path.
8562698f425bSmrg	    # Skip directories that are in the system default run-time
8563698f425bSmrg	    # search path.
8564698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8565698f425bSmrg	    *" $absdir "*) ;;
8566698f425bSmrg	    *)
85673bf3b463Smrg	      case "$compile_rpath$compile_rpath_tail " in
8568698f425bSmrg	      *" $absdir "*) ;;
85693bf3b463Smrg	      *) case $absdir in
85703bf3b463Smrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
85713bf3b463Smrg                 *) func_append compile_rpath_tail " $absdir" ;;
85723bf3b463Smrg		 esac
8573698f425bSmrg	      esac
8574698f425bSmrg	      ;;
8575698f425bSmrg	    esac
8576698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8577698f425bSmrg	    *" $libdir "*) ;;
8578698f425bSmrg	    *)
8579698f425bSmrg	      case "$finalize_rpath " in
8580698f425bSmrg	      *" $libdir "*) ;;
85819ef0b394Smrg	      *) func_append finalize_rpath " $libdir" ;;
8582698f425bSmrg	      esac
8583698f425bSmrg	      ;;
8584698f425bSmrg	    esac
8585698f425bSmrg	  fi # $linkmode,$pass = prog,link...
8586698f425bSmrg
8587a3129944Smrg	  if $alldeplibs &&
8588a3129944Smrg	     { test pass_all = "$deplibs_check_method" ||
8589a3129944Smrg	       { test yes = "$build_libtool_libs" &&
8590698f425bSmrg		 test -n "$library_names"; }; }; then
8591698f425bSmrg	    # We only need to search for static libraries
8592698f425bSmrg	    continue
8593698f425bSmrg	  fi
8594698f425bSmrg	fi
8595698f425bSmrg
8596698f425bSmrg	link_static=no # Whether the deplib will be linked statically
8597698f425bSmrg	use_static_libs=$prefer_static_libs
8598a3129944Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8599698f425bSmrg	  use_static_libs=no
8600698f425bSmrg	fi
8601698f425bSmrg	if test -n "$library_names" &&
8602a3129944Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
86033bf3b463Smrg	  case $host_os in
86043bf3b463Smrg	  cygwin* | mingw* | windows* | cegcc* | os2*)
8605698f425bSmrg	      # No point in relinking DLLs because paths are not encoded
86069ef0b394Smrg	      func_append notinst_deplibs " $lib"
8607698f425bSmrg	      need_relink=no
8608698f425bSmrg	    ;;
8609698f425bSmrg	  *)
8610a3129944Smrg	    if test no = "$installed"; then
86119ef0b394Smrg	      func_append notinst_deplibs " $lib"
8612698f425bSmrg	      need_relink=yes
8613698f425bSmrg	    fi
8614698f425bSmrg	    ;;
8615698f425bSmrg	  esac
8616698f425bSmrg	  # This is a shared library
8617698f425bSmrg
8618698f425bSmrg	  # Warn about portability, can't link against -module's on some
8619698f425bSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8620a3129944Smrg	  dlopenmodule=
8621698f425bSmrg	  for dlpremoduletest in $dlprefiles; do
8622698f425bSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8623a3129944Smrg	      dlopenmodule=$dlpremoduletest
8624698f425bSmrg	      break
8625698f425bSmrg	    fi
8626698f425bSmrg	  done
8627a3129944Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
86289ef0b394Smrg	    echo
8629a3129944Smrg	    if test prog = "$linkmode"; then
86303bf3b463Smrg	      func_warning "Linking the executable $output against the loadable module"
8631698f425bSmrg	    else
86323bf3b463Smrg	      func_warning "Linking the shared library $output against the loadable module"
8633698f425bSmrg	    fi
86343bf3b463Smrg	    func_warning "$linklib is not portable!"
8635698f425bSmrg	  fi
8636a3129944Smrg	  if test lib = "$linkmode" &&
8637a3129944Smrg	     test yes = "$hardcode_into_libs"; then
8638698f425bSmrg	    # Hardcode the library path.
8639698f425bSmrg	    # Skip directories that are in the system default run-time
8640698f425bSmrg	    # search path.
8641698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8642698f425bSmrg	    *" $absdir "*) ;;
8643698f425bSmrg	    *)
86443bf3b463Smrg	      case "$compile_rpath$compile_rpath_tail " in
8645698f425bSmrg	      *" $absdir "*) ;;
86463bf3b463Smrg	      *) case $absdir in
86473bf3b463Smrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
86483bf3b463Smrg                 *) func_append compile_rpath_tail " $absdir" ;;
86493bf3b463Smrg		 esac
8650698f425bSmrg	      esac
8651698f425bSmrg	      ;;
8652698f425bSmrg	    esac
8653698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8654698f425bSmrg	    *" $libdir "*) ;;
8655698f425bSmrg	    *)
8656698f425bSmrg	      case "$finalize_rpath " in
8657698f425bSmrg	      *" $libdir "*) ;;
86589ef0b394Smrg	      *) func_append finalize_rpath " $libdir" ;;
8659698f425bSmrg	      esac
8660698f425bSmrg	      ;;
8661698f425bSmrg	    esac
8662698f425bSmrg	  fi
8663698f425bSmrg
8664698f425bSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8665698f425bSmrg	    # figure out the soname
8666698f425bSmrg	    set dummy $library_names
8667698f425bSmrg	    shift
8668a3129944Smrg	    realname=$1
8669698f425bSmrg	    shift
8670698f425bSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8671698f425bSmrg	    # use dlname if we got it. it's perfectly good, no?
8672698f425bSmrg	    if test -n "$dlname"; then
8673a3129944Smrg	      soname=$dlname
8674698f425bSmrg	    elif test -n "$soname_spec"; then
8675698f425bSmrg	      # bleh windows
86763bf3b463Smrg	      case $host_os in
86773bf3b463Smrg	      cygwin* | mingw* | windows* | cegcc* | os2*)
8678698f425bSmrg	        func_arith $current - $age
8679698f425bSmrg		major=$func_arith_result
8680a3129944Smrg		versuffix=-$major
8681698f425bSmrg		;;
8682698f425bSmrg	      esac
8683698f425bSmrg	      eval soname=\"$soname_spec\"
8684698f425bSmrg	    else
8685a3129944Smrg	      soname=$realname
8686698f425bSmrg	    fi
8687698f425bSmrg
8688698f425bSmrg	    # Make a new name for the extract_expsyms_cmds to use
8689a3129944Smrg	    soroot=$soname
8690698f425bSmrg	    func_basename "$soroot"
8691a3129944Smrg	    soname=$func_basename_result
8692698f425bSmrg	    func_stripname 'lib' '.dll' "$soname"
8693698f425bSmrg	    newlib=libimp-$func_stripname_result.a
8694698f425bSmrg
8695698f425bSmrg	    # If the library has no export list, then create one now
8696698f425bSmrg	    if test -f "$output_objdir/$soname-def"; then :
8697698f425bSmrg	    else
8698a3129944Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8699698f425bSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8700698f425bSmrg	    fi
8701698f425bSmrg
8702698f425bSmrg	    # Create $newlib
8703698f425bSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8704a3129944Smrg	      func_verbose "generating import library for '$soname'"
8705698f425bSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8706698f425bSmrg	    fi
8707698f425bSmrg	    # make sure the library variables are pointing to the new library
8708698f425bSmrg	    dir=$output_objdir
8709698f425bSmrg	    linklib=$newlib
8710698f425bSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8711698f425bSmrg
8712a3129944Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8713698f425bSmrg	    add_shlibpath=
8714698f425bSmrg	    add_dir=
8715698f425bSmrg	    add=
8716698f425bSmrg	    lib_linked=yes
8717698f425bSmrg	    case $hardcode_action in
8718698f425bSmrg	    immediate | unsupported)
8719a3129944Smrg	      if test no = "$hardcode_direct"; then
8720a3129944Smrg		add=$dir/$linklib
8721698f425bSmrg		case $host in
8722a3129944Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8723a3129944Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
87243bf3b463Smrg		  *-*-emscripten*) add_dir=-L$dir ;;
8725698f425bSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8726a3129944Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8727698f425bSmrg		  *-*-darwin* )
8728a3129944Smrg		    # if the lib is a (non-dlopened) module then we cannot
8729698f425bSmrg		    # link against it, someone is ignoring the earlier warnings
8730698f425bSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8731a3129944Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8732698f425bSmrg		      if test "X$dlopenmodule" != "X$lib"; then
87333bf3b463Smrg			func_warning "lib $linklib is a module, not a shared library"
8734a3129944Smrg			if test -z "$old_library"; then
87353bf3b463Smrg			  func_warning "And there doesn't seem to be a static archive available"
87363bf3b463Smrg			  func_warning "The link will probably fail, sorry"
8737698f425bSmrg			else
8738a3129944Smrg			  add=$dir/$old_library
8739698f425bSmrg			fi
8740698f425bSmrg		      elif test -n "$old_library"; then
8741a3129944Smrg			add=$dir/$old_library
8742698f425bSmrg		      fi
8743698f425bSmrg		    fi
8744698f425bSmrg		esac
8745a3129944Smrg	      elif test no = "$hardcode_minus_L"; then
8746698f425bSmrg		case $host in
8747a3129944Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8748698f425bSmrg		esac
8749a3129944Smrg		add_dir=-L$dir
8750a3129944Smrg		add=-l$name
8751a3129944Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8752a3129944Smrg		add_shlibpath=$dir
8753a3129944Smrg		add=-l$name
8754698f425bSmrg	      else
8755698f425bSmrg		lib_linked=no
8756698f425bSmrg	      fi
8757698f425bSmrg	      ;;
8758698f425bSmrg	    relink)
8759a3129944Smrg	      if test yes = "$hardcode_direct" &&
8760a3129944Smrg	         test no = "$hardcode_direct_absolute"; then
8761a3129944Smrg		add=$dir/$linklib
8762a3129944Smrg	      elif test yes = "$hardcode_minus_L"; then
8763a3129944Smrg		add_dir=-L$absdir
8764698f425bSmrg		# Try looking first in the location we're being installed to.
8765698f425bSmrg		if test -n "$inst_prefix_dir"; then
8766698f425bSmrg		  case $libdir in
8767698f425bSmrg		    [\\/]*)
87689ef0b394Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8769698f425bSmrg		      ;;
8770698f425bSmrg		  esac
8771698f425bSmrg		fi
8772a3129944Smrg		add=-l$name
8773a3129944Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8774a3129944Smrg		add_shlibpath=$dir
8775a3129944Smrg		add=-l$name
8776698f425bSmrg	      else
8777698f425bSmrg		lib_linked=no
8778698f425bSmrg	      fi
8779698f425bSmrg	      ;;
8780698f425bSmrg	    *) lib_linked=no ;;
8781698f425bSmrg	    esac
8782698f425bSmrg
8783a3129944Smrg	    if test yes != "$lib_linked"; then
8784698f425bSmrg	      func_fatal_configuration "unsupported hardcode properties"
8785698f425bSmrg	    fi
8786698f425bSmrg
8787698f425bSmrg	    if test -n "$add_shlibpath"; then
8788698f425bSmrg	      case :$compile_shlibpath: in
8789698f425bSmrg	      *":$add_shlibpath:"*) ;;
87909ef0b394Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8791698f425bSmrg	      esac
8792698f425bSmrg	    fi
8793a3129944Smrg	    if test prog = "$linkmode"; then
8794698f425bSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8795698f425bSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8796698f425bSmrg	    else
8797698f425bSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8798698f425bSmrg	      test -n "$add" && deplibs="$add $deplibs"
8799a3129944Smrg	      if test yes != "$hardcode_direct" &&
8800a3129944Smrg		 test yes != "$hardcode_minus_L" &&
8801a3129944Smrg		 test yes = "$hardcode_shlibpath_var"; then
8802698f425bSmrg		case :$finalize_shlibpath: in
8803698f425bSmrg		*":$libdir:"*) ;;
88049ef0b394Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8805698f425bSmrg		esac
8806698f425bSmrg	      fi
8807698f425bSmrg	    fi
8808698f425bSmrg	  fi
8809698f425bSmrg
8810a3129944Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8811698f425bSmrg	    add_shlibpath=
8812698f425bSmrg	    add_dir=
8813698f425bSmrg	    add=
8814698f425bSmrg	    # Finalize command for both is simple: just hardcode it.
8815a3129944Smrg	    if test yes = "$hardcode_direct" &&
8816a3129944Smrg	       test no = "$hardcode_direct_absolute"; then
8817a3129944Smrg	      add=$libdir/$linklib
8818a3129944Smrg	    elif test yes = "$hardcode_minus_L"; then
88193bf3b463Smrg	      add_dir=-L$lt_sysroot$libdir
8820a3129944Smrg	      add=-l$name
8821a3129944Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8822698f425bSmrg	      case :$finalize_shlibpath: in
8823698f425bSmrg	      *":$libdir:"*) ;;
88249ef0b394Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8825698f425bSmrg	      esac
8826a3129944Smrg	      add=-l$name
8827a3129944Smrg	    elif test yes = "$hardcode_automatic"; then
8828698f425bSmrg	      if test -n "$inst_prefix_dir" &&
8829a3129944Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8830a3129944Smrg		add=$inst_prefix_dir$libdir/$linklib
8831698f425bSmrg	      else
8832a3129944Smrg		add=$libdir/$linklib
8833698f425bSmrg	      fi
8834698f425bSmrg	    else
8835698f425bSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
88363bf3b463Smrg	      add_dir=-L$lt_sysroot$libdir
8837698f425bSmrg	      # Try looking first in the location we're being installed to.
8838698f425bSmrg	      if test -n "$inst_prefix_dir"; then
8839698f425bSmrg		case $libdir in
8840698f425bSmrg		  [\\/]*)
88419ef0b394Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8842698f425bSmrg		    ;;
8843698f425bSmrg		esac
8844698f425bSmrg	      fi
8845a3129944Smrg	      add=-l$name
8846698f425bSmrg	    fi
8847698f425bSmrg
8848a3129944Smrg	    if test prog = "$linkmode"; then
8849698f425bSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8850698f425bSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8851698f425bSmrg	    else
8852698f425bSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8853698f425bSmrg	      test -n "$add" && deplibs="$add $deplibs"
8854698f425bSmrg	    fi
8855698f425bSmrg	  fi
8856a3129944Smrg	elif test prog = "$linkmode"; then
8857698f425bSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8858698f425bSmrg	  # is not unsupported.  This is valid on all known static and
8859698f425bSmrg	  # shared platforms.
8860a3129944Smrg	  if test unsupported != "$hardcode_direct"; then
8861a3129944Smrg	    test -n "$old_library" && linklib=$old_library
8862698f425bSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8863698f425bSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8864698f425bSmrg	  else
8865698f425bSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8866698f425bSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8867698f425bSmrg	  fi
8868a3129944Smrg	elif test yes = "$build_libtool_libs"; then
8869698f425bSmrg	  # Not a shared library
8870a3129944Smrg	  if test pass_all != "$deplibs_check_method"; then
8871698f425bSmrg	    # We're trying link a shared library against a static one
8872698f425bSmrg	    # but the system doesn't support it.
8873698f425bSmrg
8874698f425bSmrg	    # Just print a warning and add the library to dependency_libs so
8875698f425bSmrg	    # that the program can be linked against the static library.
88763bf3b463Smrg	    func_warning "This system cannot link to static lib archive $lib."
88773bf3b463Smrg	    func_warning "I have the capability to make that library automatically link in when"
88783bf3b463Smrg	    func_warning "you link to this library.  But I can only do this if you have a"
88793bf3b463Smrg	    func_warning "shared version of the library, which you do not appear to have."
8880a3129944Smrg	    if test yes = "$module"; then
88813bf3b463Smrg	      func_warning "But as you try to build a module library, libtool will still create "
88823bf3b463Smrg	      func_warning "a static module, that should work as long as the dlopening application"
88833bf3b463Smrg	      func_warning "is linked with the -dlopen flag to resolve symbols at runtime."
8884698f425bSmrg	      if test -z "$global_symbol_pipe"; then
88853bf3b463Smrg		func_warning "However, this would only work if libtool was able to extract symbol"
88863bf3b463Smrg		func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
88873bf3b463Smrg		func_warning "not find such a program.  So, this module is probably useless."
88883bf3b463Smrg		func_warning "'nm' from GNU binutils and a full rebuild may help."
8889698f425bSmrg	      fi
8890a3129944Smrg	      if test no = "$build_old_libs"; then
8891698f425bSmrg		build_libtool_libs=module
8892698f425bSmrg		build_old_libs=yes
8893698f425bSmrg	      else
8894698f425bSmrg		build_libtool_libs=no
8895698f425bSmrg	      fi
8896698f425bSmrg	    fi
8897698f425bSmrg	  else
8898698f425bSmrg	    deplibs="$dir/$old_library $deplibs"
8899698f425bSmrg	    link_static=yes
8900698f425bSmrg	  fi
8901698f425bSmrg	fi # link shared/static library?
8902698f425bSmrg
8903a3129944Smrg	if test lib = "$linkmode"; then
8904698f425bSmrg	  if test -n "$dependency_libs" &&
8905a3129944Smrg	     { test yes != "$hardcode_into_libs" ||
8906a3129944Smrg	       test yes = "$build_old_libs" ||
8907a3129944Smrg	       test yes = "$link_static"; }; then
8908698f425bSmrg	    # Extract -R from dependency_libs
8909698f425bSmrg	    temp_deplibs=
8910698f425bSmrg	    for libdir in $dependency_libs; do
8911698f425bSmrg	      case $libdir in
8912698f425bSmrg	      -R*) func_stripname '-R' '' "$libdir"
8913698f425bSmrg	           temp_xrpath=$func_stripname_result
8914698f425bSmrg		   case " $xrpath " in
8915698f425bSmrg		   *" $temp_xrpath "*) ;;
89169ef0b394Smrg		   *) func_append xrpath " $temp_xrpath";;
8917698f425bSmrg		   esac;;
89189ef0b394Smrg	      *) func_append temp_deplibs " $libdir";;
8919698f425bSmrg	      esac
8920698f425bSmrg	    done
8921a3129944Smrg	    dependency_libs=$temp_deplibs
8922698f425bSmrg	  fi
8923698f425bSmrg
89249ef0b394Smrg	  func_append newlib_search_path " $absdir"
8925698f425bSmrg	  # Link against this library
8926a3129944Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8927698f425bSmrg	  # ... and its dependency_libs
8928698f425bSmrg	  tmp_libs=
8929698f425bSmrg	  for deplib in $dependency_libs; do
8930698f425bSmrg	    newdependency_libs="$deplib $newdependency_libs"
89319ef0b394Smrg	    case $deplib in
89329ef0b394Smrg              -L*) func_stripname '-L' '' "$deplib"
89339ef0b394Smrg                   func_resolve_sysroot "$func_stripname_result";;
89349ef0b394Smrg              *) func_resolve_sysroot "$deplib" ;;
89359ef0b394Smrg            esac
8936a3129944Smrg	    if $opt_preserve_dup_deps; then
8937698f425bSmrg	      case "$tmp_libs " in
89389ef0b394Smrg	      *" $func_resolve_sysroot_result "*)
89399ef0b394Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8940698f425bSmrg	      esac
8941698f425bSmrg	    fi
89429ef0b394Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8943698f425bSmrg	  done
8944698f425bSmrg
8945a3129944Smrg	  if test no != "$link_all_deplibs"; then
8946698f425bSmrg	    # Add the search paths of all dependency libraries
8947698f425bSmrg	    for deplib in $dependency_libs; do
89489ef0b394Smrg	      path=
8949698f425bSmrg	      case $deplib in
8950a3129944Smrg	      -L*) path=$deplib ;;
8951698f425bSmrg	      *.la)
89529ef0b394Smrg	        func_resolve_sysroot "$deplib"
89539ef0b394Smrg	        deplib=$func_resolve_sysroot_result
8954698f425bSmrg	        func_dirname "$deplib" "" "."
89559ef0b394Smrg		dir=$func_dirname_result
8956698f425bSmrg		# We need an absolute path.
8957698f425bSmrg		case $dir in
8958a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8959698f425bSmrg		*)
8960698f425bSmrg		  absdir=`cd "$dir" && pwd`
8961698f425bSmrg		  if test -z "$absdir"; then
8962a3129944Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8963a3129944Smrg		    absdir=$dir
8964698f425bSmrg		  fi
8965698f425bSmrg		  ;;
8966698f425bSmrg		esac
8967698f425bSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
8968698f425bSmrg		case $host in
8969698f425bSmrg		*-*-darwin*)
8970698f425bSmrg		  depdepl=
8971a3129944Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8972a3129944Smrg		  if test -n "$deplibrary_names"; then
8973a3129944Smrg		    for tmp in $deplibrary_names; do
8974698f425bSmrg		      depdepl=$tmp
8975698f425bSmrg		    done
8976a3129944Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8977a3129944Smrg		      depdepl=$absdir/$objdir/$depdepl
8978a3129944Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8979698f425bSmrg                      if test -z "$darwin_install_name"; then
8980a3129944Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8981698f425bSmrg                      fi
8982a3129944Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8983a3129944Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8984698f425bSmrg		      path=
8985698f425bSmrg		    fi
8986698f425bSmrg		  fi
8987698f425bSmrg		  ;;
8988698f425bSmrg		*)
8989a3129944Smrg		  path=-L$absdir/$objdir
8990698f425bSmrg		  ;;
8991698f425bSmrg		esac
8992698f425bSmrg		else
8993a3129944Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8994698f425bSmrg		  test -z "$libdir" && \
8995a3129944Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8996698f425bSmrg		  test "$absdir" != "$libdir" && \
8997a3129944Smrg		    func_warning "'$deplib' seems to be moved"
8998698f425bSmrg
8999a3129944Smrg		  path=-L$absdir
9000698f425bSmrg		fi
9001698f425bSmrg		;;
9002698f425bSmrg	      esac
9003698f425bSmrg	      case " $deplibs " in
9004698f425bSmrg	      *" $path "*) ;;
9005698f425bSmrg	      *) deplibs="$path $deplibs" ;;
9006698f425bSmrg	      esac
9007698f425bSmrg	    done
9008698f425bSmrg	  fi # link_all_deplibs != no
9009698f425bSmrg	fi # linkmode = lib
9010698f425bSmrg      done # for deplib in $libs
90113bf3b463Smrg
90123bf3b463Smrg      func_append temp_rpath "$temp_rpath_tail"
90133bf3b463Smrg      func_append compile_rpath "$compile_rpath_tail"
90143bf3b463Smrg
9015a3129944Smrg      if test link = "$pass"; then
9016a3129944Smrg	if test prog = "$linkmode"; then
9017698f425bSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
9018698f425bSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
9019698f425bSmrg	else
90209ef0b394Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9021698f425bSmrg	fi
9022698f425bSmrg      fi
9023a3129944Smrg      dependency_libs=$newdependency_libs
9024a3129944Smrg      if test dlpreopen = "$pass"; then
9025698f425bSmrg	# Link the dlpreopened libraries before other libraries
9026698f425bSmrg	for deplib in $save_deplibs; do
9027698f425bSmrg	  deplibs="$deplib $deplibs"
9028698f425bSmrg	done
9029698f425bSmrg      fi
9030a3129944Smrg      if test dlopen != "$pass"; then
9031a3129944Smrg	test conv = "$pass" || {
9032698f425bSmrg	  # Make sure lib_search_path contains only unique directories.
9033698f425bSmrg	  lib_search_path=
9034698f425bSmrg	  for dir in $newlib_search_path; do
9035698f425bSmrg	    case "$lib_search_path " in
9036698f425bSmrg	    *" $dir "*) ;;
90379ef0b394Smrg	    *) func_append lib_search_path " $dir" ;;
9038698f425bSmrg	    esac
9039698f425bSmrg	  done
9040698f425bSmrg	  newlib_search_path=
9041a3129944Smrg	}
9042698f425bSmrg
9043a3129944Smrg	if test prog,link = "$linkmode,$pass"; then
9044698f425bSmrg	  vars="compile_deplibs finalize_deplibs"
9045a3129944Smrg	else
9046a3129944Smrg	  vars=deplibs
9047698f425bSmrg	fi
9048698f425bSmrg	for var in $vars dependency_libs; do
9049698f425bSmrg	  # Add libraries to $var in reverse order
9050698f425bSmrg	  eval tmp_libs=\"\$$var\"
9051698f425bSmrg	  new_libs=
90523bf3b463Smrg	  # FIXME: Pedantically, this is the right thing to do, so
90533bf3b463Smrg	  #        that some nasty dependency loop isn't accidentally
90543bf3b463Smrg	  #        broken: new_libs="$deplib $new_libs"
9055698f425bSmrg	  for deplib in $tmp_libs; do
90563bf3b463Smrg	    if $opt_preserve_dup_deps; then
90573bf3b463Smrg	      new_libs="$deplib $new_libs"
90583bf3b463Smrg	    else
90593bf3b463Smrg	      # Pragmatically, this seems to cause very few problems in
90603bf3b463Smrg	      # practice:
90613bf3b463Smrg	      case $deplib in
90623bf3b463Smrg	      -L*) new_libs="$deplib $new_libs" ;;
90633bf3b463Smrg	      -R*) ;;
9064698f425bSmrg	      *)
90653bf3b463Smrg	        # And here is the reason: when a library appears more
90663bf3b463Smrg	        # than once as an explicit dependence of a library, or
90673bf3b463Smrg	        # is implicitly linked in more than once by the
90683bf3b463Smrg	        # compiler, it is considered special, and multiple
90693bf3b463Smrg	        # occurrences thereof are not removed.  Compare this
90703bf3b463Smrg	        # with having the same library being listed as a
90713bf3b463Smrg	        # dependency of multiple other libraries: in this case,
90723bf3b463Smrg	        # we know (pedantically, we assume) the library does not
90733bf3b463Smrg	        # need to be listed more than once, so we keep only the
90743bf3b463Smrg	        # last copy.  This is not always right, but it is rare
90753bf3b463Smrg	        # enough that we require users that really mean to play
90763bf3b463Smrg	        # such unportable linking tricks to link the library
90773bf3b463Smrg	        # using -Wl,-lname, so that libtool does not consider it
90783bf3b463Smrg	        # for duplicate removal.  And if not possible for portability
90793bf3b463Smrg	        # reasons, then --preserve-dup-deps should be used.
90803bf3b463Smrg	        case " $specialdeplibs " in
90813bf3b463Smrg	        *" $deplib "*) new_libs="$deplib $new_libs" ;;
90823bf3b463Smrg	        *)
90833bf3b463Smrg	          case " $new_libs " in
90843bf3b463Smrg	          *" $deplib "*) ;;
90853bf3b463Smrg	          *) new_libs="$deplib $new_libs" ;;
90863bf3b463Smrg	          esac
90873bf3b463Smrg	          ;;
90883bf3b463Smrg	        esac
90893bf3b463Smrg	        ;;
9090698f425bSmrg	      esac
90913bf3b463Smrg	    fi
9092698f425bSmrg	  done
9093698f425bSmrg	  tmp_libs=
9094698f425bSmrg	  for deplib in $new_libs; do
9095698f425bSmrg	    case $deplib in
9096698f425bSmrg	    -L*)
9097698f425bSmrg	      case " $tmp_libs " in
9098698f425bSmrg	      *" $deplib "*) ;;
90999ef0b394Smrg	      *) func_append tmp_libs " $deplib" ;;
9100698f425bSmrg	      esac
9101698f425bSmrg	      ;;
91029ef0b394Smrg	    *) func_append tmp_libs " $deplib" ;;
9103698f425bSmrg	    esac
9104698f425bSmrg	  done
9105698f425bSmrg	  eval $var=\"$tmp_libs\"
9106698f425bSmrg	done # for var
9107698f425bSmrg      fi
9108a3129944Smrg
9109a3129944Smrg      # Add Sun CC postdeps if required:
9110a3129944Smrg      test CXX = "$tagname" && {
9111a3129944Smrg        case $host_os in
9112a3129944Smrg        linux*)
91131009a292Smrg          case `$CC -V 2>&1 | $SED 5q` in
9114a3129944Smrg          *Sun\ C*) # Sun C++ 5.9
9115a3129944Smrg            func_suncc_cstd_abi
9116a3129944Smrg
9117a3129944Smrg            if test no != "$suncc_use_cstd_abi"; then
9118a3129944Smrg              func_append postdeps ' -library=Cstd -library=Crun'
9119a3129944Smrg            fi
9120a3129944Smrg            ;;
9121a3129944Smrg          esac
9122a3129944Smrg          ;;
9123a3129944Smrg
9124a3129944Smrg        solaris*)
9125a3129944Smrg          func_cc_basename "$CC"
9126a3129944Smrg          case $func_cc_basename_result in
9127a3129944Smrg          CC* | sunCC*)
9128a3129944Smrg            func_suncc_cstd_abi
9129a3129944Smrg
9130a3129944Smrg            if test no != "$suncc_use_cstd_abi"; then
9131a3129944Smrg              func_append postdeps ' -library=Cstd -library=Crun'
9132a3129944Smrg            fi
9133a3129944Smrg            ;;
9134a3129944Smrg          esac
9135a3129944Smrg          ;;
9136a3129944Smrg        esac
9137a3129944Smrg      }
9138a3129944Smrg
9139698f425bSmrg      # Last step: remove runtime libs from dependency_libs
9140698f425bSmrg      # (they stay in deplibs)
9141698f425bSmrg      tmp_libs=
9142a3129944Smrg      for i in $dependency_libs; do
9143698f425bSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
9144698f425bSmrg	*" $i "*)
9145a3129944Smrg	  i=
9146698f425bSmrg	  ;;
9147698f425bSmrg	esac
9148a3129944Smrg	if test -n "$i"; then
91499ef0b394Smrg	  func_append tmp_libs " $i"
9150698f425bSmrg	fi
9151698f425bSmrg      done
9152698f425bSmrg      dependency_libs=$tmp_libs
9153698f425bSmrg    done # for pass
9154a3129944Smrg    if test prog = "$linkmode"; then
9155a3129944Smrg      dlfiles=$newdlfiles
9156698f425bSmrg    fi
9157a3129944Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
9158a3129944Smrg      dlprefiles=$newdlprefiles
9159698f425bSmrg    fi
9160698f425bSmrg
9161698f425bSmrg    case $linkmode in
9162698f425bSmrg    oldlib)
9163a3129944Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
9164a3129944Smrg	func_warning "'-dlopen' is ignored for archives"
9165698f425bSmrg      fi
9166698f425bSmrg
9167698f425bSmrg      case " $deplibs" in
9168698f425bSmrg      *\ -l* | *\ -L*)
9169a3129944Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
9170698f425bSmrg      esac
9171698f425bSmrg
9172698f425bSmrg      test -n "$rpath" && \
9173a3129944Smrg	func_warning "'-rpath' is ignored for archives"
9174698f425bSmrg
9175698f425bSmrg      test -n "$xrpath" && \
9176a3129944Smrg	func_warning "'-R' is ignored for archives"
9177698f425bSmrg
9178698f425bSmrg      test -n "$vinfo" && \
9179a3129944Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
9180698f425bSmrg
9181698f425bSmrg      test -n "$release" && \
9182a3129944Smrg	func_warning "'-release' is ignored for archives"
9183698f425bSmrg
9184698f425bSmrg      test -n "$export_symbols$export_symbols_regex" && \
9185a3129944Smrg	func_warning "'-export-symbols' is ignored for archives"
9186698f425bSmrg
9187698f425bSmrg      # Now set the variables for building old libraries.
9188698f425bSmrg      build_libtool_libs=no
9189a3129944Smrg      oldlibs=$output
91909ef0b394Smrg      func_append objs "$old_deplibs"
9191698f425bSmrg      ;;
9192698f425bSmrg
9193698f425bSmrg    lib)
9194a3129944Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9195698f425bSmrg      case $outputname in
9196698f425bSmrg      lib*)
9197698f425bSmrg	func_stripname 'lib' '.la' "$outputname"
9198698f425bSmrg	name=$func_stripname_result
9199698f425bSmrg	eval shared_ext=\"$shrext_cmds\"
9200698f425bSmrg	eval libname=\"$libname_spec\"
9201698f425bSmrg	;;
9202698f425bSmrg      *)
9203a3129944Smrg	test no = "$module" \
9204a3129944Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9205698f425bSmrg
9206a3129944Smrg	if test no != "$need_lib_prefix"; then
9207698f425bSmrg	  # Add the "lib" prefix for modules if required
9208698f425bSmrg	  func_stripname '' '.la' "$outputname"
9209698f425bSmrg	  name=$func_stripname_result
9210698f425bSmrg	  eval shared_ext=\"$shrext_cmds\"
9211698f425bSmrg	  eval libname=\"$libname_spec\"
9212698f425bSmrg	else
9213698f425bSmrg	  func_stripname '' '.la' "$outputname"
9214698f425bSmrg	  libname=$func_stripname_result
9215698f425bSmrg	fi
9216698f425bSmrg	;;
9217698f425bSmrg      esac
9218698f425bSmrg
9219698f425bSmrg      if test -n "$objs"; then
9220a3129944Smrg	if test pass_all != "$deplibs_check_method"; then
9221a3129944Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9222698f425bSmrg	else
92233bf3b463Smrg	  func_warning "Linking the shared library $output against the non-libtool objects $objs is not portable!"
92249ef0b394Smrg	  func_append libobjs " $objs"
9225698f425bSmrg	fi
9226698f425bSmrg      fi
9227698f425bSmrg
9228a3129944Smrg      test no = "$dlself" \
9229a3129944Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9230698f425bSmrg
9231698f425bSmrg      set dummy $rpath
9232698f425bSmrg      shift
9233a3129944Smrg      test 1 -lt "$#" \
9234a3129944Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9235698f425bSmrg
9236a3129944Smrg      install_libdir=$1
9237698f425bSmrg
9238698f425bSmrg      oldlibs=
9239698f425bSmrg      if test -z "$rpath"; then
9240a3129944Smrg	if test yes = "$build_libtool_libs"; then
9241698f425bSmrg	  # Building a libtool convenience library.
9242a3129944Smrg	  # Some compilers have problems with a '.al' extension so
9243698f425bSmrg	  # convenience libraries should have the same extension an
9244698f425bSmrg	  # archive normally would.
9245698f425bSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9246698f425bSmrg	  build_libtool_libs=convenience
9247698f425bSmrg	  build_old_libs=yes
9248698f425bSmrg	fi
9249698f425bSmrg
9250698f425bSmrg	test -n "$vinfo" && \
9251a3129944Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9252698f425bSmrg
9253698f425bSmrg	test -n "$release" && \
9254a3129944Smrg	  func_warning "'-release' is ignored for convenience libraries"
9255698f425bSmrg      else
9256698f425bSmrg
9257698f425bSmrg	# Parse the version information argument.
9258a3129944Smrg	save_ifs=$IFS; IFS=:
9259698f425bSmrg	set dummy $vinfo 0 0 0
9260698f425bSmrg	shift
9261a3129944Smrg	IFS=$save_ifs
9262698f425bSmrg
9263698f425bSmrg	test -n "$7" && \
9264a3129944Smrg	  func_fatal_help "too many parameters to '-version-info'"
9265698f425bSmrg
9266698f425bSmrg	# convert absolute version numbers to libtool ages
9267698f425bSmrg	# this retains compatibility with .la files and attempts
9268698f425bSmrg	# to make the code below a bit more comprehensible
9269698f425bSmrg
9270698f425bSmrg	case $vinfo_number in
9271698f425bSmrg	yes)
9272a3129944Smrg	  number_major=$1
9273a3129944Smrg	  number_minor=$2
9274a3129944Smrg	  number_revision=$3
9275698f425bSmrg	  #
9276698f425bSmrg	  # There are really only two kinds -- those that
9277698f425bSmrg	  # use the current revision as the major version
9278698f425bSmrg	  # and those that subtract age and use age as
9279698f425bSmrg	  # a minor version.  But, then there is irix
9280a3129944Smrg	  # that has an extra 1 added just for fun
9281698f425bSmrg	  #
9282698f425bSmrg	  case $version_type in
9283fb5e8d76Smrg	  # correct linux to gnu/linux during the next big refactor
92843bf3b463Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|qnx|windows|none)
9285698f425bSmrg	    func_arith $number_major + $number_minor
9286698f425bSmrg	    current=$func_arith_result
9287a3129944Smrg	    age=$number_minor
9288a3129944Smrg	    revision=$number_revision
9289698f425bSmrg	    ;;
92903bf3b463Smrg	  freebsd-aout|sco|sunos)
9291a3129944Smrg	    current=$number_major
9292a3129944Smrg	    revision=$number_minor
9293a3129944Smrg	    age=0
9294698f425bSmrg	    ;;
9295698f425bSmrg	  irix|nonstopux)
9296698f425bSmrg	    func_arith $number_major + $number_minor
9297698f425bSmrg	    current=$func_arith_result
9298a3129944Smrg	    age=$number_minor
9299a3129944Smrg	    revision=$number_minor
9300698f425bSmrg	    lt_irix_increment=no
9301698f425bSmrg	    ;;
93023bf3b463Smrg	  *)
93033bf3b463Smrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
93043bf3b463Smrg	    ;;
9305698f425bSmrg	  esac
9306698f425bSmrg	  ;;
9307698f425bSmrg	no)
9308a3129944Smrg	  current=$1
9309a3129944Smrg	  revision=$2
9310a3129944Smrg	  age=$3
9311698f425bSmrg	  ;;
9312698f425bSmrg	esac
9313698f425bSmrg
9314698f425bSmrg	# Check that each of the things are valid numbers.
9315698f425bSmrg	case $current in
9316698f425bSmrg	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]) ;;
9317698f425bSmrg	*)
9318a3129944Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9319a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9320698f425bSmrg	  ;;
9321698f425bSmrg	esac
9322698f425bSmrg
9323698f425bSmrg	case $revision in
9324698f425bSmrg	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]) ;;
9325698f425bSmrg	*)
9326a3129944Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9327a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9328698f425bSmrg	  ;;
9329698f425bSmrg	esac
9330698f425bSmrg
9331698f425bSmrg	case $age in
9332698f425bSmrg	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]) ;;
9333698f425bSmrg	*)
9334a3129944Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9335a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9336698f425bSmrg	  ;;
9337698f425bSmrg	esac
9338698f425bSmrg
9339698f425bSmrg	if test "$age" -gt "$current"; then
9340a3129944Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9341a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9342698f425bSmrg	fi
9343698f425bSmrg
9344698f425bSmrg	# Calculate the version variables.
9345698f425bSmrg	major=
9346698f425bSmrg	versuffix=
9347698f425bSmrg	verstring=
9348698f425bSmrg	case $version_type in
9349698f425bSmrg	none) ;;
9350698f425bSmrg
9351698f425bSmrg	darwin)
9352698f425bSmrg	  # Like Linux, but with the current version available in
9353698f425bSmrg	  # verstring for coding it into the library header
9354698f425bSmrg	  func_arith $current - $age
9355698f425bSmrg	  major=.$func_arith_result
9356a3129944Smrg	  versuffix=$major.$age.$revision
9357698f425bSmrg	  # Darwin ld doesn't like 0 for these options...
9358698f425bSmrg	  func_arith $current + 1
9359698f425bSmrg	  minor_current=$func_arith_result
9360a3129944Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9361698f425bSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9362a3129944Smrg          # On Darwin other compilers
9363a3129944Smrg          case $CC in
9364a3129944Smrg              nagfor*)
9365a3129944Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9366a3129944Smrg                  ;;
9367a3129944Smrg              *)
9368a3129944Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9369a3129944Smrg                  ;;
9370a3129944Smrg          esac
9371698f425bSmrg	  ;;
9372698f425bSmrg
9373698f425bSmrg	freebsd-aout)
9374a3129944Smrg	  major=.$current
9375a3129944Smrg	  versuffix=.$current.$revision
9376698f425bSmrg	  ;;
9377698f425bSmrg
93781009a292Smrg	freebsd-elf | midnightbsd-elf)
9379a3129944Smrg	  func_arith $current - $age
9380a3129944Smrg	  major=.$func_arith_result
9381a3129944Smrg	  versuffix=$major.$age.$revision
9382698f425bSmrg	  ;;
9383698f425bSmrg
9384698f425bSmrg	irix | nonstopux)
9385a3129944Smrg	  if test no = "$lt_irix_increment"; then
9386698f425bSmrg	    func_arith $current - $age
9387698f425bSmrg	  else
9388698f425bSmrg	    func_arith $current - $age + 1
9389698f425bSmrg	  fi
9390698f425bSmrg	  major=$func_arith_result
9391698f425bSmrg
9392698f425bSmrg	  case $version_type in
9393698f425bSmrg	    nonstopux) verstring_prefix=nonstopux ;;
9394698f425bSmrg	    *)         verstring_prefix=sgi ;;
9395698f425bSmrg	  esac
9396a3129944Smrg	  verstring=$verstring_prefix$major.$revision
9397698f425bSmrg
9398698f425bSmrg	  # Add in all the interfaces that we are compatible with.
9399698f425bSmrg	  loop=$revision
9400a3129944Smrg	  while test 0 -ne "$loop"; do
9401698f425bSmrg	    func_arith $revision - $loop
9402698f425bSmrg	    iface=$func_arith_result
9403698f425bSmrg	    func_arith $loop - 1
9404698f425bSmrg	    loop=$func_arith_result
9405a3129944Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
9406698f425bSmrg	  done
9407698f425bSmrg
9408a3129944Smrg	  # Before this point, $major must not contain '.'.
9409698f425bSmrg	  major=.$major
9410a3129944Smrg	  versuffix=$major.$revision
9411698f425bSmrg	  ;;
9412698f425bSmrg
9413fb5e8d76Smrg	linux) # correct to gnu/linux during the next big refactor
9414698f425bSmrg	  func_arith $current - $age
9415698f425bSmrg	  major=.$func_arith_result
9416a3129944Smrg	  versuffix=$major.$age.$revision
9417698f425bSmrg	  ;;
9418698f425bSmrg
9419698f425bSmrg	osf)
9420698f425bSmrg	  func_arith $current - $age
9421698f425bSmrg	  major=.$func_arith_result
9422a3129944Smrg	  versuffix=.$current.$age.$revision
9423a3129944Smrg	  verstring=$current.$age.$revision
9424698f425bSmrg
9425698f425bSmrg	  # Add in all the interfaces that we are compatible with.
9426698f425bSmrg	  loop=$age
9427a3129944Smrg	  while test 0 -ne "$loop"; do
9428698f425bSmrg	    func_arith $current - $loop
9429698f425bSmrg	    iface=$func_arith_result
9430698f425bSmrg	    func_arith $loop - 1
9431698f425bSmrg	    loop=$func_arith_result
9432a3129944Smrg	    verstring=$verstring:$iface.0
9433698f425bSmrg	  done
9434698f425bSmrg
9435698f425bSmrg	  # Make executables depend on our current version.
9436a3129944Smrg	  func_append verstring ":$current.0"
9437698f425bSmrg	  ;;
9438698f425bSmrg
9439698f425bSmrg	qnx)
94403bf3b463Smrg	  func_arith $current - $age
94413bf3b463Smrg	  major=.$func_arith_result
94423bf3b463Smrg	  versuffix=$major.$age.$revision
9443a3129944Smrg	  ;;
9444a3129944Smrg
9445a3129944Smrg	sco)
9446a3129944Smrg	  major=.$current
9447a3129944Smrg	  versuffix=.$current
9448698f425bSmrg	  ;;
9449698f425bSmrg
9450698f425bSmrg	sunos)
9451a3129944Smrg	  major=.$current
9452a3129944Smrg	  versuffix=.$current.$revision
9453698f425bSmrg	  ;;
9454698f425bSmrg
9455698f425bSmrg	windows)
9456698f425bSmrg	  # Use '-' rather than '.', since we only want one
9457a3129944Smrg	  # extension on DOS 8.3 file systems.
9458698f425bSmrg	  func_arith $current - $age
9459698f425bSmrg	  major=$func_arith_result
9460a3129944Smrg	  versuffix=-$major
9461698f425bSmrg	  ;;
9462698f425bSmrg
9463698f425bSmrg	*)
9464a3129944Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
9465698f425bSmrg	  ;;
9466698f425bSmrg	esac
9467698f425bSmrg
9468698f425bSmrg	# Clear the version info if we defaulted, and they specified a release.
9469698f425bSmrg	if test -z "$vinfo" && test -n "$release"; then
9470698f425bSmrg	  major=
9471698f425bSmrg	  case $version_type in
9472698f425bSmrg	  darwin)
9473698f425bSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
9474698f425bSmrg	    # problems, so we reset it completely
9475698f425bSmrg	    verstring=
9476698f425bSmrg	    ;;
9477698f425bSmrg	  *)
9478a3129944Smrg	    verstring=0.0
9479698f425bSmrg	    ;;
9480698f425bSmrg	  esac
9481a3129944Smrg	  if test no = "$need_version"; then
9482698f425bSmrg	    versuffix=
9483698f425bSmrg	  else
9484a3129944Smrg	    versuffix=.0.0
9485698f425bSmrg	  fi
9486698f425bSmrg	fi
9487698f425bSmrg
9488698f425bSmrg	# Remove version info from name if versioning should be avoided
9489a3129944Smrg	if test yes,no = "$avoid_version,$need_version"; then
9490698f425bSmrg	  major=
9491698f425bSmrg	  versuffix=
9492a3129944Smrg	  verstring=
9493698f425bSmrg	fi
9494698f425bSmrg
9495698f425bSmrg	# Check to see if the archive will have undefined symbols.
9496a3129944Smrg	if test yes = "$allow_undefined"; then
9497a3129944Smrg	  if test unsupported = "$allow_undefined_flag"; then
9498a3129944Smrg	    if test yes = "$build_old_libs"; then
9499a3129944Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9500a3129944Smrg	      build_libtool_libs=no
9501a3129944Smrg	    else
9502a3129944Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9503a3129944Smrg	    fi
9504698f425bSmrg	  fi
9505698f425bSmrg	else
9506698f425bSmrg	  # Don't allow undefined symbols.
9507a3129944Smrg	  allow_undefined_flag=$no_undefined_flag
9508698f425bSmrg	fi
9509698f425bSmrg
9510698f425bSmrg      fi
9511698f425bSmrg
9512a3129944Smrg      func_generate_dlsyms "$libname" "$libname" :
95139ef0b394Smrg      func_append libobjs " $symfileobj"
9514a3129944Smrg      test " " = "$libobjs" && libobjs=
9515698f425bSmrg
9516a3129944Smrg      if test relink != "$opt_mode"; then
9517698f425bSmrg	# Remove our outputs, but don't remove object files since they
9518698f425bSmrg	# may have been created when compiling PIC objects.
9519698f425bSmrg	removelist=
9520698f425bSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
9521698f425bSmrg	for p in $tempremovelist; do
9522698f425bSmrg	  case $p in
9523698f425bSmrg	    *.$objext | *.gcno)
9524698f425bSmrg	       ;;
9525a3129944Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9526a3129944Smrg	       if test -n "$precious_files_regex"; then
9527698f425bSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9528698f425bSmrg		 then
9529698f425bSmrg		   continue
9530698f425bSmrg		 fi
9531698f425bSmrg	       fi
95329ef0b394Smrg	       func_append removelist " $p"
9533698f425bSmrg	       ;;
9534698f425bSmrg	    *) ;;
9535698f425bSmrg	  esac
9536698f425bSmrg	done
9537698f425bSmrg	test -n "$removelist" && \
9538698f425bSmrg	  func_show_eval "${RM}r \$removelist"
9539698f425bSmrg      fi
9540698f425bSmrg
9541698f425bSmrg      # Now set the variables for building old libraries.
9542a3129944Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
95439ef0b394Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9544698f425bSmrg
9545698f425bSmrg	# Transform .lo files to .o files.
9546a3129944Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9547698f425bSmrg      fi
9548698f425bSmrg
9549698f425bSmrg      # Eliminate all temporary directories.
9550698f425bSmrg      #for path in $notinst_path; do
95519ef0b394Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
95529ef0b394Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
95539ef0b394Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9554698f425bSmrg      #done
9555698f425bSmrg
9556698f425bSmrg      if test -n "$xrpath"; then
9557698f425bSmrg	# If the user specified any rpath flags, then add them.
9558698f425bSmrg	temp_xrpath=
9559698f425bSmrg	for libdir in $xrpath; do
95609ef0b394Smrg	  func_replace_sysroot "$libdir"
95619ef0b394Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9562698f425bSmrg	  case "$finalize_rpath " in
9563698f425bSmrg	  *" $libdir "*) ;;
95649ef0b394Smrg	  *) func_append finalize_rpath " $libdir" ;;
9565698f425bSmrg	  esac
9566698f425bSmrg	done
9567a3129944Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9568698f425bSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
9569698f425bSmrg	fi
9570698f425bSmrg      fi
9571698f425bSmrg
9572698f425bSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9573a3129944Smrg      old_dlfiles=$dlfiles
9574698f425bSmrg      dlfiles=
9575698f425bSmrg      for lib in $old_dlfiles; do
9576698f425bSmrg	case " $dlprefiles $dlfiles " in
9577698f425bSmrg	*" $lib "*) ;;
95789ef0b394Smrg	*) func_append dlfiles " $lib" ;;
9579698f425bSmrg	esac
9580698f425bSmrg      done
9581698f425bSmrg
9582698f425bSmrg      # Make sure dlprefiles contains only unique files
9583a3129944Smrg      old_dlprefiles=$dlprefiles
9584698f425bSmrg      dlprefiles=
9585698f425bSmrg      for lib in $old_dlprefiles; do
9586698f425bSmrg	case "$dlprefiles " in
9587698f425bSmrg	*" $lib "*) ;;
95889ef0b394Smrg	*) func_append dlprefiles " $lib" ;;
9589698f425bSmrg	esac
9590698f425bSmrg      done
9591698f425bSmrg
9592a3129944Smrg      if test yes = "$build_libtool_libs"; then
9593698f425bSmrg	if test -n "$rpath"; then
9594698f425bSmrg	  case $host in
95953bf3b463Smrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9596698f425bSmrg	    # these systems don't actually have a c library (as such)!
9597698f425bSmrg	    ;;
9598698f425bSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
9599698f425bSmrg	    # Rhapsody C library is in the System framework
96009ef0b394Smrg	    func_append deplibs " System.ltframework"
9601698f425bSmrg	    ;;
9602698f425bSmrg	  *-*-netbsd*)
9603698f425bSmrg	    # Don't link with libc until the a.out ld.so is fixed.
9604698f425bSmrg	    ;;
96051009a292Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9606698f425bSmrg	    # Do not include libc due to us having libc/libc_r.
9607698f425bSmrg	    ;;
9608698f425bSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9609698f425bSmrg	    # Causes problems with __ctype
9610698f425bSmrg	    ;;
9611698f425bSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9612698f425bSmrg	    # Compiler inserts libc in the correct place for threads to work
9613698f425bSmrg	    ;;
9614698f425bSmrg	  *)
9615698f425bSmrg	    # Add libc to deplibs on all other systems if necessary.
9616a3129944Smrg	    if test yes = "$build_libtool_need_lc"; then
96179ef0b394Smrg	      func_append deplibs " -lc"
9618698f425bSmrg	    fi
9619698f425bSmrg	    ;;
9620698f425bSmrg	  esac
9621698f425bSmrg	fi
9622698f425bSmrg
9623698f425bSmrg	# Transform deplibs into only deplibs that can be linked in shared.
9624698f425bSmrg	name_save=$name
9625698f425bSmrg	libname_save=$libname
9626698f425bSmrg	release_save=$release
9627698f425bSmrg	versuffix_save=$versuffix
9628698f425bSmrg	major_save=$major
9629698f425bSmrg	# I'm not sure if I'm treating the release correctly.  I think
9630698f425bSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9631698f425bSmrg	# add it in twice.  Is that correct?
9632a3129944Smrg	release=
9633a3129944Smrg	versuffix=
9634a3129944Smrg	major=
9635698f425bSmrg	newdeplibs=
9636698f425bSmrg	droppeddeps=no
9637698f425bSmrg	case $deplibs_check_method in
9638698f425bSmrg	pass_all)
9639698f425bSmrg	  # Don't check for shared/static.  Everything works.
9640698f425bSmrg	  # This might be a little naive.  We might want to check
9641698f425bSmrg	  # whether the library exists or not.  But this is on
9642698f425bSmrg	  # osf3 & osf4 and I'm not really sure... Just
9643698f425bSmrg	  # implementing what was already the behavior.
9644698f425bSmrg	  newdeplibs=$deplibs
9645698f425bSmrg	  ;;
9646698f425bSmrg	file_magic*)
9647698f425bSmrg	  set dummy $deplibs_check_method; shift
9648698f425bSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9649698f425bSmrg	  for a_deplib in $deplibs; do
9650698f425bSmrg	    case $a_deplib in
9651698f425bSmrg	    -l*)
9652698f425bSmrg	      func_stripname -l '' "$a_deplib"
9653698f425bSmrg	      name=$func_stripname_result
9654a3129944Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9655698f425bSmrg		case " $predeps $postdeps " in
9656698f425bSmrg		*" $a_deplib "*)
96579ef0b394Smrg		  func_append newdeplibs " $a_deplib"
9658a3129944Smrg		  a_deplib=
9659698f425bSmrg		  ;;
9660698f425bSmrg		esac
9661698f425bSmrg	      fi
9662a3129944Smrg	      if test -n "$a_deplib"; then
9663698f425bSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96649ef0b394Smrg		if test -n "$file_magic_glob"; then
96659ef0b394Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
96669ef0b394Smrg		else
96679ef0b394Smrg		  libnameglob=$libname
96689ef0b394Smrg		fi
9669a3129944Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9670698f425bSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9671a3129944Smrg		  if test yes = "$want_nocaseglob"; then
96729ef0b394Smrg		    shopt -s nocaseglob
96739ef0b394Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
96749ef0b394Smrg		    $nocaseglob
96759ef0b394Smrg		  else
96769ef0b394Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
96779ef0b394Smrg		  fi
9678698f425bSmrg		  for potent_lib in $potential_libs; do
9679698f425bSmrg		      # Follow soft links.
9680698f425bSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9681698f425bSmrg			 $GREP " -> " >/dev/null; then
9682698f425bSmrg			continue
9683698f425bSmrg		      fi
9684698f425bSmrg		      # The statement above tries to avoid entering an
9685698f425bSmrg		      # endless loop below, in case of cyclic links.
9686698f425bSmrg		      # We might still enter an endless loop, since a link
9687698f425bSmrg		      # loop can be closed while we follow links,
9688698f425bSmrg		      # but so what?
9689a3129944Smrg		      potlib=$potent_lib
9690698f425bSmrg		      while test -h "$potlib" 2>/dev/null; do
9691a3129944Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9692698f425bSmrg			case $potliblink in
9693a3129944Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9694a3129944Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9695698f425bSmrg			esac
9696698f425bSmrg		      done
9697698f425bSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9698698f425bSmrg			 $SED -e 10q |
9699698f425bSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
97009ef0b394Smrg			func_append newdeplibs " $a_deplib"
9701a3129944Smrg			a_deplib=
9702698f425bSmrg			break 2
9703698f425bSmrg		      fi
9704698f425bSmrg		  done
9705698f425bSmrg		done
9706698f425bSmrg	      fi
9707a3129944Smrg	      if test -n "$a_deplib"; then
9708698f425bSmrg		droppeddeps=yes
97093bf3b463Smrg		func_warning "Linker path does not have real file for library $a_deplib."
97103bf3b463Smrg		func_warning "I have the capability to make that library automatically link in when"
97113bf3b463Smrg		func_warning "you link to this library.  But I can only do this if you have a"
97123bf3b463Smrg		func_warning "shared version of the library, which you do not appear to have"
97133bf3b463Smrg		func_warning "because I did check the linker path looking for a file starting"
9714a3129944Smrg		if test -z "$potlib"; then
97153bf3b463Smrg		  func_warning "with $libname but no candidates were found. (...for file magic test)"
9716698f425bSmrg		else
97173bf3b463Smrg		  func_warning "with $libname and none of the candidates passed a file format test"
97183bf3b463Smrg		  func_warning "using a file magic. Last file checked: $potlib"
9719698f425bSmrg		fi
9720698f425bSmrg	      fi
9721698f425bSmrg	      ;;
9722698f425bSmrg	    *)
9723698f425bSmrg	      # Add a -L argument.
97249ef0b394Smrg	      func_append newdeplibs " $a_deplib"
9725698f425bSmrg	      ;;
9726698f425bSmrg	    esac
9727698f425bSmrg	  done # Gone through all deplibs.
9728698f425bSmrg	  ;;
9729698f425bSmrg	match_pattern*)
9730698f425bSmrg	  set dummy $deplibs_check_method; shift
9731698f425bSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9732698f425bSmrg	  for a_deplib in $deplibs; do
9733698f425bSmrg	    case $a_deplib in
9734698f425bSmrg	    -l*)
9735698f425bSmrg	      func_stripname -l '' "$a_deplib"
9736698f425bSmrg	      name=$func_stripname_result
9737a3129944Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9738698f425bSmrg		case " $predeps $postdeps " in
9739698f425bSmrg		*" $a_deplib "*)
97409ef0b394Smrg		  func_append newdeplibs " $a_deplib"
9741a3129944Smrg		  a_deplib=
9742698f425bSmrg		  ;;
9743698f425bSmrg		esac
9744698f425bSmrg	      fi
9745a3129944Smrg	      if test -n "$a_deplib"; then
9746698f425bSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9747698f425bSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9748698f425bSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9749698f425bSmrg		  for potent_lib in $potential_libs; do
9750a3129944Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
97519ef0b394Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9752698f425bSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
97539ef0b394Smrg		      func_append newdeplibs " $a_deplib"
9754a3129944Smrg		      a_deplib=
9755698f425bSmrg		      break 2
9756698f425bSmrg		    fi
9757698f425bSmrg		  done
9758698f425bSmrg		done
9759698f425bSmrg	      fi
9760a3129944Smrg	      if test -n "$a_deplib"; then
9761698f425bSmrg		droppeddeps=yes
97623bf3b463Smrg		func_warning "Linker path does not have real file for library $a_deplib."
97633bf3b463Smrg		func_warning "I have the capability to make that library automatically link in when"
97643bf3b463Smrg		func_warning "you link to this library.  But I can only do this if you have a"
97653bf3b463Smrg		func_warning "shared version of the library, which you do not appear to have"
97663bf3b463Smrg		func_warning "because I did check the linker path looking for a file starting"
9767a3129944Smrg		if test -z "$potlib"; then
97683bf3b463Smrg		  func_warning "with $libname but no candidates were found. (...for regex pattern test)"
9769698f425bSmrg		else
97703bf3b463Smrg		  func_warning "with $libname and none of the candidates passed a file format test"
97713bf3b463Smrg		  func_warning "using a regex pattern. Last file checked: $potlib"
9772698f425bSmrg		fi
9773698f425bSmrg	      fi
9774698f425bSmrg	      ;;
9775698f425bSmrg	    *)
9776698f425bSmrg	      # Add a -L argument.
97779ef0b394Smrg	      func_append newdeplibs " $a_deplib"
9778698f425bSmrg	      ;;
9779698f425bSmrg	    esac
9780698f425bSmrg	  done # Gone through all deplibs.
9781698f425bSmrg	  ;;
9782698f425bSmrg	none | unknown | *)
9783a3129944Smrg	  newdeplibs=
97849ef0b394Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9785a3129944Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9786a3129944Smrg	    for i in $predeps $postdeps; do
9787698f425bSmrg	      # can't use Xsed below, because $i might contain '/'
9788a3129944Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9789698f425bSmrg	    done
9790698f425bSmrg	  fi
97919ef0b394Smrg	  case $tmp_deplibs in
97929ef0b394Smrg	  *[!\	\ ]*)
97939ef0b394Smrg	    echo
9794a3129944Smrg	    if test none = "$deplibs_check_method"; then
97953bf3b463Smrg	      func_warning "Inter-library dependencies are not supported in this platform."
9796698f425bSmrg	    else
97973bf3b463Smrg	      func_warning "Inter-library dependencies are not known to be supported."
9798698f425bSmrg	    fi
97993bf3b463Smrg	    func_warning "All declared inter-library dependencies are being dropped."
9800698f425bSmrg	    droppeddeps=yes
98019ef0b394Smrg	    ;;
98029ef0b394Smrg	  esac
9803698f425bSmrg	  ;;
9804698f425bSmrg	esac
9805698f425bSmrg	versuffix=$versuffix_save
9806698f425bSmrg	major=$major_save
9807698f425bSmrg	release=$release_save
9808698f425bSmrg	libname=$libname_save
9809698f425bSmrg	name=$name_save
9810698f425bSmrg
9811698f425bSmrg	case $host in
9812698f425bSmrg	*-*-rhapsody* | *-*-darwin1.[012])
9813698f425bSmrg	  # On Rhapsody replace the C library with the System framework
98149ef0b394Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9815698f425bSmrg	  ;;
9816698f425bSmrg	esac
9817698f425bSmrg
9818a3129944Smrg	if test yes = "$droppeddeps"; then
9819a3129944Smrg	  if test yes = "$module"; then
98203bf3b463Smrg	    func_warning "libtool could not satisfy all declared inter-library"
98213bf3b463Smrg	    func_warning "dependencies of module $libname.  Therefore, libtool will create"
98223bf3b463Smrg	    func_warning "a static module, that should work as long as the dlopening"
98233bf3b463Smrg	    func_warning "application is linked with the -dlopen flag."
9824698f425bSmrg	    if test -z "$global_symbol_pipe"; then
98253bf3b463Smrg	      func_warning "However, this would only work if libtool was able to extract symbol"
98263bf3b463Smrg	      func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
98273bf3b463Smrg	      func_warning "not find such a program.  So, this module is probably useless."
98283bf3b463Smrg	      func_warning "'nm' from GNU binutils and a full rebuild may help."
9829698f425bSmrg	    fi
9830a3129944Smrg	    if test no = "$build_old_libs"; then
9831a3129944Smrg	      oldlibs=$output_objdir/$libname.$libext
9832698f425bSmrg	      build_libtool_libs=module
9833698f425bSmrg	      build_old_libs=yes
9834698f425bSmrg	    else
9835698f425bSmrg	      build_libtool_libs=no
9836698f425bSmrg	    fi
9837698f425bSmrg	  else
98389ef0b394Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
98399ef0b394Smrg	    echo "*** automatically added whenever a program is linked with this library"
98409ef0b394Smrg	    echo "*** or is declared to -dlopen it."
9841698f425bSmrg
9842a3129944Smrg	    if test no = "$allow_undefined"; then
98439ef0b394Smrg	      echo
98449ef0b394Smrg	      echo "*** Since this library must not contain undefined symbols,"
98459ef0b394Smrg	      echo "*** because either the platform does not support them or"
98469ef0b394Smrg	      echo "*** it was explicitly requested with -no-undefined,"
98479ef0b394Smrg	      echo "*** libtool will only create a static version of it."
9848a3129944Smrg	      if test no = "$build_old_libs"; then
9849a3129944Smrg		oldlibs=$output_objdir/$libname.$libext
9850698f425bSmrg		build_libtool_libs=module
9851698f425bSmrg		build_old_libs=yes
9852698f425bSmrg	      else
9853698f425bSmrg		build_libtool_libs=no
9854698f425bSmrg	      fi
9855698f425bSmrg	    fi
9856698f425bSmrg	  fi
9857698f425bSmrg	fi
9858698f425bSmrg	# Done checking deplibs!
9859698f425bSmrg	deplibs=$newdeplibs
9860698f425bSmrg      fi
9861698f425bSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9862698f425bSmrg      case $host in
9863698f425bSmrg	*-*-darwin*)
98649ef0b394Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
98659ef0b394Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
98669ef0b394Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9867698f425bSmrg	  ;;
9868698f425bSmrg      esac
9869698f425bSmrg
9870698f425bSmrg      # move library search paths that coincide with paths to not yet
9871698f425bSmrg      # installed libraries to the beginning of the library search list
9872698f425bSmrg      new_libs=
9873698f425bSmrg      for path in $notinst_path; do
9874698f425bSmrg	case " $new_libs " in
9875698f425bSmrg	*" -L$path/$objdir "*) ;;
9876698f425bSmrg	*)
9877698f425bSmrg	  case " $deplibs " in
9878698f425bSmrg	  *" -L$path/$objdir "*)
98799ef0b394Smrg	    func_append new_libs " -L$path/$objdir" ;;
9880698f425bSmrg	  esac
9881698f425bSmrg	  ;;
9882698f425bSmrg	esac
9883698f425bSmrg      done
9884698f425bSmrg      for deplib in $deplibs; do
9885698f425bSmrg	case $deplib in
9886698f425bSmrg	-L*)
9887698f425bSmrg	  case " $new_libs " in
9888698f425bSmrg	  *" $deplib "*) ;;
98899ef0b394Smrg	  *) func_append new_libs " $deplib" ;;
9890698f425bSmrg	  esac
9891698f425bSmrg	  ;;
98929ef0b394Smrg	*) func_append new_libs " $deplib" ;;
9893698f425bSmrg	esac
9894698f425bSmrg      done
9895a3129944Smrg      deplibs=$new_libs
9896698f425bSmrg
9897698f425bSmrg      # All the library-specific variables (install_libdir is set above).
9898698f425bSmrg      library_names=
9899698f425bSmrg      old_library=
9900698f425bSmrg      dlname=
9901698f425bSmrg
9902698f425bSmrg      # Test again, we may have decided not to build it any more
9903a3129944Smrg      if test yes = "$build_libtool_libs"; then
9904a3129944Smrg	# Remove $wl instances when linking with ld.
9905fb5e8d76Smrg	# FIXME: should test the right _cmds variable.
9906fb5e8d76Smrg	case $archive_cmds in
9907fb5e8d76Smrg	  *\$LD\ *) wl= ;;
9908fb5e8d76Smrg        esac
9909a3129944Smrg	if test yes = "$hardcode_into_libs"; then
9910698f425bSmrg	  # Hardcode the library paths
9911698f425bSmrg	  hardcode_libdirs=
9912698f425bSmrg	  dep_rpath=
9913a3129944Smrg	  rpath=$finalize_rpath
9914a3129944Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9915698f425bSmrg	  for libdir in $rpath; do
9916698f425bSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
9917698f425bSmrg	      if test -n "$hardcode_libdir_separator"; then
99189ef0b394Smrg		func_replace_sysroot "$libdir"
99199ef0b394Smrg		libdir=$func_replace_sysroot_result
9920698f425bSmrg		if test -z "$hardcode_libdirs"; then
9921a3129944Smrg		  hardcode_libdirs=$libdir
9922698f425bSmrg		else
9923698f425bSmrg		  # Just accumulate the unique libdirs.
9924698f425bSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9925698f425bSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9926698f425bSmrg		    ;;
9927698f425bSmrg		  *)
99289ef0b394Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9929698f425bSmrg		    ;;
9930698f425bSmrg		  esac
9931698f425bSmrg		fi
9932698f425bSmrg	      else
9933698f425bSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
99349ef0b394Smrg		func_append dep_rpath " $flag"
9935698f425bSmrg	      fi
9936698f425bSmrg	    elif test -n "$runpath_var"; then
9937698f425bSmrg	      case "$perm_rpath " in
9938698f425bSmrg	      *" $libdir "*) ;;
9939fb5e8d76Smrg	      *) func_append perm_rpath " $libdir" ;;
9940698f425bSmrg	      esac
9941698f425bSmrg	    fi
9942698f425bSmrg	  done
9943698f425bSmrg	  # Substitute the hardcoded libdirs into the rpath.
9944698f425bSmrg	  if test -n "$hardcode_libdir_separator" &&
9945698f425bSmrg	     test -n "$hardcode_libdirs"; then
9946a3129944Smrg	    libdir=$hardcode_libdirs
9947fb5e8d76Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9948698f425bSmrg	  fi
9949698f425bSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9950698f425bSmrg	    # We should set the runpath_var.
9951698f425bSmrg	    rpath=
9952698f425bSmrg	    for dir in $perm_rpath; do
99539ef0b394Smrg	      func_append rpath "$dir:"
9954698f425bSmrg	    done
9955698f425bSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9956698f425bSmrg	  fi
9957698f425bSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9958698f425bSmrg	fi
9959266e564dSmrg
9960a3129944Smrg	shlibpath=$finalize_shlibpath
9961a3129944Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9962698f425bSmrg	if test -n "$shlibpath"; then
9963698f425bSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9964698f425bSmrg	fi
9965266e564dSmrg
9966698f425bSmrg	# Get the real and link names of the library.
9967698f425bSmrg	eval shared_ext=\"$shrext_cmds\"
9968698f425bSmrg	eval library_names=\"$library_names_spec\"
9969698f425bSmrg	set dummy $library_names
9970698f425bSmrg	shift
9971a3129944Smrg	realname=$1
9972698f425bSmrg	shift
9973266e564dSmrg
9974698f425bSmrg	if test -n "$soname_spec"; then
9975698f425bSmrg	  eval soname=\"$soname_spec\"
9976698f425bSmrg	else
9977a3129944Smrg	  soname=$realname
9978698f425bSmrg	fi
9979698f425bSmrg	if test -z "$dlname"; then
9980698f425bSmrg	  dlname=$soname
9981698f425bSmrg	fi
9982266e564dSmrg
9983a3129944Smrg	lib=$output_objdir/$realname
9984698f425bSmrg	linknames=
9985698f425bSmrg	for link
9986698f425bSmrg	do
99879ef0b394Smrg	  func_append linknames " $link"
9988698f425bSmrg	done
9989266e564dSmrg
9990698f425bSmrg	# Use standard objects if they are pic
99919ef0b394Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9992698f425bSmrg	test "X$libobjs" = "X " && libobjs=
9993266e564dSmrg
9994698f425bSmrg	delfiles=
9995698f425bSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9996698f425bSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9997a3129944Smrg	  export_symbols=$output_objdir/$libname.uexp
99989ef0b394Smrg	  func_append delfiles " $export_symbols"
9999698f425bSmrg	fi
10000266e564dSmrg
10001698f425bSmrg	orig_export_symbols=
10002698f425bSmrg	case $host_os in
100033bf3b463Smrg	cygwin* | mingw* | windows* | cegcc*)
10004698f425bSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
10005698f425bSmrg	    # exporting using user supplied symfile
10006a3129944Smrg	    func_dll_def_p "$export_symbols" || {
10007698f425bSmrg	      # and it's NOT already a .def file. Must figure out
10008698f425bSmrg	      # which of the given symbols are data symbols and tag
10009698f425bSmrg	      # them as such. So, trigger use of export_symbols_cmds.
10010698f425bSmrg	      # export_symbols gets reassigned inside the "prepare
10011698f425bSmrg	      # the list of exported symbols" if statement, so the
10012698f425bSmrg	      # include_expsyms logic still works.
10013a3129944Smrg	      orig_export_symbols=$export_symbols
10014698f425bSmrg	      export_symbols=
10015698f425bSmrg	      always_export_symbols=yes
10016a3129944Smrg	    }
10017698f425bSmrg	  fi
10018698f425bSmrg	  ;;
10019698f425bSmrg	esac
10020266e564dSmrg
10021698f425bSmrg	# Prepare the list of exported symbols
10022698f425bSmrg	if test -z "$export_symbols"; then
10023a3129944Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
10024a3129944Smrg	    func_verbose "generating symbol list for '$libname.la'"
10025a3129944Smrg	    export_symbols=$output_objdir/$libname.exp
10026698f425bSmrg	    $opt_dry_run || $RM $export_symbols
10027698f425bSmrg	    cmds=$export_symbols_cmds
10028a3129944Smrg	    save_ifs=$IFS; IFS='~'
100299ef0b394Smrg	    for cmd1 in $cmds; do
10030a3129944Smrg	      IFS=$save_ifs
100319ef0b394Smrg	      # Take the normal branch if the nm_file_list_spec branch
100329ef0b394Smrg	      # doesn't work or if tool conversion is not needed.
100339ef0b394Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
100349ef0b394Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
100359ef0b394Smrg		  try_normal_branch=yes
100369ef0b394Smrg		  eval cmd=\"$cmd1\"
100379ef0b394Smrg		  func_len " $cmd"
100389ef0b394Smrg		  len=$func_len_result
100399ef0b394Smrg		  ;;
100409ef0b394Smrg		*)
100419ef0b394Smrg		  try_normal_branch=no
100429ef0b394Smrg		  ;;
100439ef0b394Smrg	      esac
10044a3129944Smrg	      if test yes = "$try_normal_branch" \
100459ef0b394Smrg		 && { test "$len" -lt "$max_cmd_len" \
100469ef0b394Smrg		      || test "$max_cmd_len" -le -1; }
100479ef0b394Smrg	      then
100489ef0b394Smrg		func_show_eval "$cmd" 'exit $?'
100499ef0b394Smrg		skipped_export=false
100509ef0b394Smrg	      elif test -n "$nm_file_list_spec"; then
100519ef0b394Smrg		func_basename "$output"
100529ef0b394Smrg		output_la=$func_basename_result
100539ef0b394Smrg		save_libobjs=$libobjs
100549ef0b394Smrg		save_output=$output
10055a3129944Smrg		output=$output_objdir/$output_la.nm
100569ef0b394Smrg		func_to_tool_file "$output"
100579ef0b394Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
100589ef0b394Smrg		func_append delfiles " $output"
100599ef0b394Smrg		func_verbose "creating $NM input file list: $output"
100609ef0b394Smrg		for obj in $save_libobjs; do
100619ef0b394Smrg		  func_to_tool_file "$obj"
100629ef0b394Smrg		  $ECHO "$func_to_tool_file_result"
100639ef0b394Smrg		done > "$output"
100649ef0b394Smrg		eval cmd=\"$cmd1\"
10065698f425bSmrg		func_show_eval "$cmd" 'exit $?'
100669ef0b394Smrg		output=$save_output
100679ef0b394Smrg		libobjs=$save_libobjs
10068698f425bSmrg		skipped_export=false
10069698f425bSmrg	      else
10070698f425bSmrg		# The command line is too long to execute in one step.
10071698f425bSmrg		func_verbose "using reloadable object file for export list..."
10072698f425bSmrg		skipped_export=:
10073698f425bSmrg		# Break out early, otherwise skipped_export may be
10074698f425bSmrg		# set to false by a later but shorter cmd.
10075698f425bSmrg		break
10076698f425bSmrg	      fi
10077698f425bSmrg	    done
10078a3129944Smrg	    IFS=$save_ifs
10079a3129944Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
10080698f425bSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10081698f425bSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10082698f425bSmrg	    fi
10083698f425bSmrg	  fi
10084266e564dSmrg	fi
10085266e564dSmrg
10086698f425bSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
10087a3129944Smrg	  tmp_export_symbols=$export_symbols
10088a3129944Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
100899ef0b394Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10090698f425bSmrg	fi
10091266e564dSmrg
10092a3129944Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10093698f425bSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10094a3129944Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10095698f425bSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10096a3129944Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10097698f425bSmrg	  # though. Also, the filter scales superlinearly with the number of
10098698f425bSmrg	  # global variables. join(1) would be nice here, but unfortunately
10099698f425bSmrg	  # isn't a blessed tool.
10100698f425bSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
101019ef0b394Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10102698f425bSmrg	  export_symbols=$output_objdir/$libname.def
10103698f425bSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10104698f425bSmrg	fi
10105266e564dSmrg
10106698f425bSmrg	tmp_deplibs=
10107698f425bSmrg	for test_deplib in $deplibs; do
10108698f425bSmrg	  case " $convenience " in
10109698f425bSmrg	  *" $test_deplib "*) ;;
10110698f425bSmrg	  *)
101119ef0b394Smrg	    func_append tmp_deplibs " $test_deplib"
10112698f425bSmrg	    ;;
10113698f425bSmrg	  esac
10114698f425bSmrg	done
10115a3129944Smrg	deplibs=$tmp_deplibs
10116266e564dSmrg
10117698f425bSmrg	if test -n "$convenience"; then
10118698f425bSmrg	  if test -n "$whole_archive_flag_spec" &&
10119a3129944Smrg	    test yes = "$compiler_needs_object" &&
10120698f425bSmrg	    test -z "$libobjs"; then
10121698f425bSmrg	    # extract the archives, so we have objects to list.
10122698f425bSmrg	    # TODO: could optimize this to just extract one archive.
10123698f425bSmrg	    whole_archive_flag_spec=
10124698f425bSmrg	  fi
10125698f425bSmrg	  if test -n "$whole_archive_flag_spec"; then
10126698f425bSmrg	    save_libobjs=$libobjs
10127698f425bSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10128698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
10129698f425bSmrg	  else
10130a3129944Smrg	    gentop=$output_objdir/${outputname}x
101319ef0b394Smrg	    func_append generated " $gentop"
10132266e564dSmrg
10133698f425bSmrg	    func_extract_archives $gentop $convenience
101349ef0b394Smrg	    func_append libobjs " $func_extract_archives_result"
10135698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
10136698f425bSmrg	  fi
10137266e564dSmrg	fi
10138266e564dSmrg
10139a3129944Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10140698f425bSmrg	  eval flag=\"$thread_safe_flag_spec\"
101419ef0b394Smrg	  func_append linker_flags " $flag"
10142266e564dSmrg	fi
10143266e564dSmrg
10144698f425bSmrg	# Make a backup of the uninstalled library when relinking
10145a3129944Smrg	if test relink = "$opt_mode"; then
10146698f425bSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10147698f425bSmrg	fi
10148266e564dSmrg
10149698f425bSmrg	# Do each of the archive commands.
10150a3129944Smrg	if test yes = "$module" && test -n "$module_cmds"; then
10151698f425bSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10152698f425bSmrg	    eval test_cmds=\"$module_expsym_cmds\"
10153698f425bSmrg	    cmds=$module_expsym_cmds
10154698f425bSmrg	  else
10155698f425bSmrg	    eval test_cmds=\"$module_cmds\"
10156698f425bSmrg	    cmds=$module_cmds
10157698f425bSmrg	  fi
10158266e564dSmrg	else
10159698f425bSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10160698f425bSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
10161698f425bSmrg	    cmds=$archive_expsym_cmds
10162698f425bSmrg	  else
10163698f425bSmrg	    eval test_cmds=\"$archive_cmds\"
10164698f425bSmrg	    cmds=$archive_cmds
10165698f425bSmrg	  fi
10166266e564dSmrg	fi
10167266e564dSmrg
10168a3129944Smrg	if test : != "$skipped_export" &&
10169698f425bSmrg	   func_len " $test_cmds" &&
10170698f425bSmrg	   len=$func_len_result &&
10171698f425bSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10172698f425bSmrg	  :
10173698f425bSmrg	else
10174698f425bSmrg	  # The command line is too long to link in one step, link piecewise
10175698f425bSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10176698f425bSmrg	  # script.
10177266e564dSmrg
10178698f425bSmrg	  # Save the value of $output and $libobjs because we want to
10179698f425bSmrg	  # use them later.  If we have whole_archive_flag_spec, we
10180698f425bSmrg	  # want to use save_libobjs as it was before
10181698f425bSmrg	  # whole_archive_flag_spec was expanded, because we can't
10182698f425bSmrg	  # assume the linker understands whole_archive_flag_spec.
10183698f425bSmrg	  # This may have to be revisited, in case too many
10184698f425bSmrg	  # convenience libraries get linked in and end up exceeding
10185698f425bSmrg	  # the spec.
10186698f425bSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10187698f425bSmrg	    save_libobjs=$libobjs
10188698f425bSmrg	  fi
10189698f425bSmrg	  save_output=$output
101909ef0b394Smrg	  func_basename "$output"
101919ef0b394Smrg	  output_la=$func_basename_result
10192266e564dSmrg
10193698f425bSmrg	  # Clear the reloadable object creation command queue and
10194698f425bSmrg	  # initialize k to one.
10195698f425bSmrg	  test_cmds=
10196698f425bSmrg	  concat_cmds=
10197698f425bSmrg	  objlist=
10198698f425bSmrg	  last_robj=
10199698f425bSmrg	  k=1
10200698f425bSmrg
102013bf3b463Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10202a3129944Smrg	    output=$output_objdir/$output_la.lnk
10203698f425bSmrg	    func_verbose "creating linker input file list: $output"
10204698f425bSmrg	    : > $output
10205698f425bSmrg	    set x $save_libobjs
10206698f425bSmrg	    shift
10207698f425bSmrg	    firstobj=
10208a3129944Smrg	    if test yes = "$compiler_needs_object"; then
10209698f425bSmrg	      firstobj="$1 "
10210698f425bSmrg	      shift
10211698f425bSmrg	    fi
10212698f425bSmrg	    for obj
10213698f425bSmrg	    do
102149ef0b394Smrg	      func_to_tool_file "$obj"
102159ef0b394Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10216698f425bSmrg	    done
102179ef0b394Smrg	    func_append delfiles " $output"
102189ef0b394Smrg	    func_to_tool_file "$output"
102199ef0b394Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
102203bf3b463Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
102213bf3b463Smrg	    output=$output_objdir/$output_la.lnkscript
102223bf3b463Smrg	    func_verbose "creating GNU ld script: $output"
102233bf3b463Smrg	    echo 'INPUT (' > $output
102243bf3b463Smrg	    for obj in $save_libobjs
102253bf3b463Smrg	    do
102263bf3b463Smrg	      func_to_tool_file "$obj"
102273bf3b463Smrg	      $ECHO "$func_to_tool_file_result" >> $output
102283bf3b463Smrg	    done
102293bf3b463Smrg	    echo ')' >> $output
102303bf3b463Smrg	    func_append delfiles " $output"
102313bf3b463Smrg	    func_to_tool_file "$output"
102323bf3b463Smrg	    output=$func_to_tool_file_result
10233698f425bSmrg	  else
10234698f425bSmrg	    if test -n "$save_libobjs"; then
10235698f425bSmrg	      func_verbose "creating reloadable object files..."
10236a3129944Smrg	      output=$output_objdir/$output_la-$k.$objext
10237698f425bSmrg	      eval test_cmds=\"$reload_cmds\"
10238698f425bSmrg	      func_len " $test_cmds"
10239698f425bSmrg	      len0=$func_len_result
10240698f425bSmrg	      len=$len0
10241698f425bSmrg
10242698f425bSmrg	      # Loop over the list of objects to be linked.
10243698f425bSmrg	      for obj in $save_libobjs
10244698f425bSmrg	      do
10245698f425bSmrg		func_len " $obj"
10246698f425bSmrg		func_arith $len + $func_len_result
10247698f425bSmrg		len=$func_arith_result
10248a3129944Smrg		if test -z "$objlist" ||
10249698f425bSmrg		   test "$len" -lt "$max_cmd_len"; then
10250698f425bSmrg		  func_append objlist " $obj"
10251698f425bSmrg		else
10252698f425bSmrg		  # The command $test_cmds is almost too long, add a
10253698f425bSmrg		  # command to the queue.
10254a3129944Smrg		  if test 1 -eq "$k"; then
10255698f425bSmrg		    # The first file doesn't have a previous command to add.
102569ef0b394Smrg		    reload_objs=$objlist
102579ef0b394Smrg		    eval concat_cmds=\"$reload_cmds\"
10258698f425bSmrg		  else
10259698f425bSmrg		    # All subsequent reloadable object files will link in
10260698f425bSmrg		    # the last one created.
102619ef0b394Smrg		    reload_objs="$objlist $last_robj"
102629ef0b394Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10263698f425bSmrg		  fi
10264a3129944Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
10265698f425bSmrg		  func_arith $k + 1
10266698f425bSmrg		  k=$func_arith_result
10267a3129944Smrg		  output=$output_objdir/$output_la-$k.$objext
102689ef0b394Smrg		  objlist=" $obj"
10269698f425bSmrg		  func_len " $last_robj"
10270698f425bSmrg		  func_arith $len0 + $func_len_result
10271698f425bSmrg		  len=$func_arith_result
10272698f425bSmrg		fi
10273698f425bSmrg	      done
10274698f425bSmrg	      # Handle the remaining objects by creating one last
10275698f425bSmrg	      # reloadable object file.  All subsequent reloadable object
10276698f425bSmrg	      # files will link in the last one created.
10277698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102789ef0b394Smrg	      reload_objs="$objlist $last_robj"
10279a3129944Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10280698f425bSmrg	      if test -n "$last_robj"; then
10281a3129944Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10282698f425bSmrg	      fi
102839ef0b394Smrg	      func_append delfiles " $output"
10284266e564dSmrg
10285698f425bSmrg	    else
10286698f425bSmrg	      output=
10287698f425bSmrg	    fi
10288266e564dSmrg
10289a3129944Smrg	    ${skipped_export-false} && {
10290a3129944Smrg	      func_verbose "generating symbol list for '$libname.la'"
10291a3129944Smrg	      export_symbols=$output_objdir/$libname.exp
10292698f425bSmrg	      $opt_dry_run || $RM $export_symbols
10293698f425bSmrg	      libobjs=$output
10294698f425bSmrg	      # Append the command to create the export file.
10295698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10296698f425bSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10297698f425bSmrg	      if test -n "$last_robj"; then
10298698f425bSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10299698f425bSmrg	      fi
10300a3129944Smrg	    }
10301266e564dSmrg
10302698f425bSmrg	    test -n "$save_libobjs" &&
10303698f425bSmrg	      func_verbose "creating a temporary reloadable object file: $output"
10304266e564dSmrg
10305698f425bSmrg	    # Loop through the commands generated above and execute them.
10306a3129944Smrg	    save_ifs=$IFS; IFS='~'
10307698f425bSmrg	    for cmd in $concat_cmds; do
10308a3129944Smrg	      IFS=$save_ifs
10309a3129944Smrg	      $opt_quiet || {
103101009a292Smrg		  func_quote_arg expand,pretty "$cmd"
103111009a292Smrg		  eval "func_echo $func_quote_arg_result"
10312698f425bSmrg	      }
10313698f425bSmrg	      $opt_dry_run || eval "$cmd" || {
10314698f425bSmrg		lt_exit=$?
10315698f425bSmrg
10316698f425bSmrg		# Restore the uninstalled library and exit
10317a3129944Smrg		if test relink = "$opt_mode"; then
10318698f425bSmrg		  ( cd "$output_objdir" && \
10319698f425bSmrg		    $RM "${realname}T" && \
10320698f425bSmrg		    $MV "${realname}U" "$realname" )
10321698f425bSmrg		fi
10322266e564dSmrg
10323698f425bSmrg		exit $lt_exit
10324698f425bSmrg	      }
10325698f425bSmrg	    done
10326a3129944Smrg	    IFS=$save_ifs
10327266e564dSmrg
10328698f425bSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10329698f425bSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10330698f425bSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10331266e564dSmrg	    fi
10332266e564dSmrg	  fi
10333266e564dSmrg
10334a3129944Smrg          ${skipped_export-false} && {
10335698f425bSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10336a3129944Smrg	      tmp_export_symbols=$export_symbols
10337a3129944Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
103389ef0b394Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10339698f425bSmrg	    fi
10340266e564dSmrg
10341698f425bSmrg	    if test -n "$orig_export_symbols"; then
10342698f425bSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10343a3129944Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10344698f425bSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10345a3129944Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10346698f425bSmrg	      # though. Also, the filter scales superlinearly with the number of
10347698f425bSmrg	      # global variables. join(1) would be nice here, but unfortunately
10348698f425bSmrg	      # isn't a blessed tool.
10349698f425bSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
103509ef0b394Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10351698f425bSmrg	      export_symbols=$output_objdir/$libname.def
10352698f425bSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10353698f425bSmrg	    fi
10354a3129944Smrg	  }
10355266e564dSmrg
10356698f425bSmrg	  libobjs=$output
10357698f425bSmrg	  # Restore the value of output.
10358698f425bSmrg	  output=$save_output
10359266e564dSmrg
10360698f425bSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10361698f425bSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10362698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
10363698f425bSmrg	  fi
10364698f425bSmrg	  # Expand the library linking commands again to reset the
10365698f425bSmrg	  # value of $libobjs for piecewise linking.
10366266e564dSmrg
10367698f425bSmrg	  # Do each of the archive commands.
10368a3129944Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
10369698f425bSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10370698f425bSmrg	      cmds=$module_expsym_cmds
10371698f425bSmrg	    else
10372698f425bSmrg	      cmds=$module_cmds
10373266e564dSmrg	    fi
10374266e564dSmrg	  else
10375698f425bSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10376698f425bSmrg	      cmds=$archive_expsym_cmds
10377698f425bSmrg	    else
10378698f425bSmrg	      cmds=$archive_cmds
10379698f425bSmrg	    fi
10380266e564dSmrg	  fi
10381698f425bSmrg	fi
10382266e564dSmrg
10383698f425bSmrg	if test -n "$delfiles"; then
10384698f425bSmrg	  # Append the command to remove temporary files to $cmds.
10385698f425bSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10386698f425bSmrg	fi
10387266e564dSmrg
10388698f425bSmrg	# Add any objects from preloaded convenience libraries
10389698f425bSmrg	if test -n "$dlprefiles"; then
10390a3129944Smrg	  gentop=$output_objdir/${outputname}x
103919ef0b394Smrg	  func_append generated " $gentop"
10392266e564dSmrg
10393698f425bSmrg	  func_extract_archives $gentop $dlprefiles
103949ef0b394Smrg	  func_append libobjs " $func_extract_archives_result"
10395698f425bSmrg	  test "X$libobjs" = "X " && libobjs=
10396698f425bSmrg	fi
10397266e564dSmrg
10398a3129944Smrg	save_ifs=$IFS; IFS='~'
10399698f425bSmrg	for cmd in $cmds; do
10400a3129944Smrg	  IFS=$sp$nl
10401698f425bSmrg	  eval cmd=\"$cmd\"
10402a3129944Smrg	  IFS=$save_ifs
10403a3129944Smrg	  $opt_quiet || {
104041009a292Smrg	    func_quote_arg expand,pretty "$cmd"
104051009a292Smrg	    eval "func_echo $func_quote_arg_result"
10406698f425bSmrg	  }
10407698f425bSmrg	  $opt_dry_run || eval "$cmd" || {
10408698f425bSmrg	    lt_exit=$?
10409266e564dSmrg
10410698f425bSmrg	    # Restore the uninstalled library and exit
10411a3129944Smrg	    if test relink = "$opt_mode"; then
10412698f425bSmrg	      ( cd "$output_objdir" && \
10413698f425bSmrg	        $RM "${realname}T" && \
10414698f425bSmrg		$MV "${realname}U" "$realname" )
10415698f425bSmrg	    fi
10416266e564dSmrg
10417698f425bSmrg	    exit $lt_exit
10418698f425bSmrg	  }
10419698f425bSmrg	done
10420a3129944Smrg	IFS=$save_ifs
10421266e564dSmrg
10422698f425bSmrg	# Restore the uninstalled library and exit
10423a3129944Smrg	if test relink = "$opt_mode"; then
10424698f425bSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10425266e564dSmrg
10426698f425bSmrg	  if test -n "$convenience"; then
10427698f425bSmrg	    if test -z "$whole_archive_flag_spec"; then
10428698f425bSmrg	      func_show_eval '${RM}r "$gentop"'
10429698f425bSmrg	    fi
10430698f425bSmrg	  fi
10431266e564dSmrg
10432698f425bSmrg	  exit $EXIT_SUCCESS
10433698f425bSmrg	fi
10434698f425bSmrg
10435698f425bSmrg	# Create links to the real library.
10436698f425bSmrg	for linkname in $linknames; do
10437698f425bSmrg	  if test "$realname" != "$linkname"; then
10438698f425bSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10439266e564dSmrg	  fi
10440266e564dSmrg	done
10441266e564dSmrg
10442698f425bSmrg	# If -module or -export-dynamic was specified, set the dlname.
10443a3129944Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10444698f425bSmrg	  # On all known operating systems, these are identical.
10445a3129944Smrg	  dlname=$soname
10446698f425bSmrg	fi
10447698f425bSmrg      fi
10448266e564dSmrg      ;;
10449266e564dSmrg
10450698f425bSmrg    obj)
10451a3129944Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10452a3129944Smrg	func_warning "'-dlopen' is ignored for objects"
10453698f425bSmrg      fi
10454266e564dSmrg
10455698f425bSmrg      case " $deplibs" in
10456698f425bSmrg      *\ -l* | *\ -L*)
10457a3129944Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10458266e564dSmrg      esac
10459266e564dSmrg
10460698f425bSmrg      test -n "$rpath" && \
10461a3129944Smrg	func_warning "'-rpath' is ignored for objects"
10462698f425bSmrg
10463698f425bSmrg      test -n "$xrpath" && \
10464a3129944Smrg	func_warning "'-R' is ignored for objects"
10465266e564dSmrg
10466698f425bSmrg      test -n "$vinfo" && \
10467a3129944Smrg	func_warning "'-version-info' is ignored for objects"
10468266e564dSmrg
10469698f425bSmrg      test -n "$release" && \
10470a3129944Smrg	func_warning "'-release' is ignored for objects"
10471698f425bSmrg
10472698f425bSmrg      case $output in
10473698f425bSmrg      *.lo)
10474698f425bSmrg	test -n "$objs$old_deplibs" && \
10475a3129944Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10476698f425bSmrg
10477698f425bSmrg	libobj=$output
10478698f425bSmrg	func_lo2o "$libobj"
10479698f425bSmrg	obj=$func_lo2o_result
10480266e564dSmrg	;;
10481266e564dSmrg      *)
10482698f425bSmrg	libobj=
10483a3129944Smrg	obj=$output
10484266e564dSmrg	;;
10485266e564dSmrg      esac
10486266e564dSmrg
10487698f425bSmrg      # Delete the old objects.
10488698f425bSmrg      $opt_dry_run || $RM $obj $libobj
10489266e564dSmrg
10490698f425bSmrg      # Objects from convenience libraries.  This assumes
10491698f425bSmrg      # single-version convenience libraries.  Whenever we create
10492698f425bSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10493698f425bSmrg      # the extraction.
10494698f425bSmrg      reload_conv_objs=
10495698f425bSmrg      gentop=
10496a3129944Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10497a3129944Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10498a3129944Smrg      # into space.
10499a3129944Smrg      case $reload_cmds in
10500a3129944Smrg        *\$LD[\ \$]*) wl= ;;
10501a3129944Smrg      esac
10502698f425bSmrg      if test -n "$convenience"; then
10503698f425bSmrg	if test -n "$whole_archive_flag_spec"; then
10504698f425bSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10505a3129944Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10506a3129944Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10507698f425bSmrg	else
10508a3129944Smrg	  gentop=$output_objdir/${obj}x
105099ef0b394Smrg	  func_append generated " $gentop"
10510266e564dSmrg
10511698f425bSmrg	  func_extract_archives $gentop $convenience
10512698f425bSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10513698f425bSmrg	fi
10514266e564dSmrg      fi
10515266e564dSmrg
105169ef0b394Smrg      # If we're not building shared, we need to use non_pic_objs
10517a3129944Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
105189ef0b394Smrg
10519698f425bSmrg      # Create the old-style object.
10520a3129944Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10521266e564dSmrg
10522a3129944Smrg      output=$obj
10523698f425bSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10524266e564dSmrg
10525698f425bSmrg      # Exit if we aren't doing a library object file.
10526698f425bSmrg      if test -z "$libobj"; then
10527698f425bSmrg	if test -n "$gentop"; then
10528698f425bSmrg	  func_show_eval '${RM}r "$gentop"'
10529698f425bSmrg	fi
10530698f425bSmrg
10531698f425bSmrg	exit $EXIT_SUCCESS
10532266e564dSmrg      fi
10533698f425bSmrg
10534a3129944Smrg      test yes = "$build_libtool_libs" || {
10535698f425bSmrg	if test -n "$gentop"; then
10536698f425bSmrg	  func_show_eval '${RM}r "$gentop"'
10537698f425bSmrg	fi
10538698f425bSmrg
10539698f425bSmrg	# Create an invalid libtool object if no PIC, so that we don't
10540698f425bSmrg	# accidentally link it into a program.
10541698f425bSmrg	# $show "echo timestamp > $libobj"
10542698f425bSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10543698f425bSmrg	exit $EXIT_SUCCESS
10544a3129944Smrg      }
10545698f425bSmrg
10546a3129944Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10547698f425bSmrg	# Only do commands if we really have different PIC objects.
10548698f425bSmrg	reload_objs="$libobjs $reload_conv_objs"
10549a3129944Smrg	output=$libobj
10550698f425bSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
10551698f425bSmrg      fi
10552698f425bSmrg
10553698f425bSmrg      if test -n "$gentop"; then
10554698f425bSmrg	func_show_eval '${RM}r "$gentop"'
10555698f425bSmrg      fi
10556698f425bSmrg
10557698f425bSmrg      exit $EXIT_SUCCESS
10558266e564dSmrg      ;;
10559266e564dSmrg
10560698f425bSmrg    prog)
10561698f425bSmrg      case $host in
10562698f425bSmrg	*cygwin*) func_stripname '' '.exe' "$output"
10563698f425bSmrg	          output=$func_stripname_result.exe;;
10564698f425bSmrg      esac
10565698f425bSmrg      test -n "$vinfo" && \
10566a3129944Smrg	func_warning "'-version-info' is ignored for programs"
10567266e564dSmrg
10568698f425bSmrg      test -n "$release" && \
10569a3129944Smrg	func_warning "'-release' is ignored for programs"
10570266e564dSmrg
10571a3129944Smrg      $preload \
10572a3129944Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10573a3129944Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10574698f425bSmrg
10575698f425bSmrg      case $host in
10576698f425bSmrg      *-*-rhapsody* | *-*-darwin1.[012])
10577698f425bSmrg	# On Rhapsody replace the C library is the System framework
105789ef0b394Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
105799ef0b394Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10580266e564dSmrg	;;
10581698f425bSmrg      esac
10582266e564dSmrg
10583698f425bSmrg      case $host in
10584698f425bSmrg      *-*-darwin*)
10585698f425bSmrg	# Don't allow lazy linking, it breaks C++ global constructors
10586698f425bSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10587a3129944Smrg	if test CXX = "$tagname"; then
10588698f425bSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10589698f425bSmrg	    10.[0123])
10590a3129944Smrg	      func_append compile_command " $wl-bind_at_load"
10591a3129944Smrg	      func_append finalize_command " $wl-bind_at_load"
10592698f425bSmrg	    ;;
10593698f425bSmrg	  esac
10594266e564dSmrg	fi
10595698f425bSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
105969ef0b394Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105979ef0b394Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10598698f425bSmrg	;;
10599698f425bSmrg      esac
10600266e564dSmrg
10601266e564dSmrg
10602698f425bSmrg      # move library search paths that coincide with paths to not yet
10603698f425bSmrg      # installed libraries to the beginning of the library search list
10604698f425bSmrg      new_libs=
10605698f425bSmrg      for path in $notinst_path; do
10606698f425bSmrg	case " $new_libs " in
10607698f425bSmrg	*" -L$path/$objdir "*) ;;
10608698f425bSmrg	*)
10609698f425bSmrg	  case " $compile_deplibs " in
10610698f425bSmrg	  *" -L$path/$objdir "*)
106119ef0b394Smrg	    func_append new_libs " -L$path/$objdir" ;;
10612266e564dSmrg	  esac
10613698f425bSmrg	  ;;
10614698f425bSmrg	esac
10615698f425bSmrg      done
10616698f425bSmrg      for deplib in $compile_deplibs; do
10617698f425bSmrg	case $deplib in
10618698f425bSmrg	-L*)
10619698f425bSmrg	  case " $new_libs " in
10620698f425bSmrg	  *" $deplib "*) ;;
106219ef0b394Smrg	  *) func_append new_libs " $deplib" ;;
10622266e564dSmrg	  esac
10623698f425bSmrg	  ;;
106249ef0b394Smrg	*) func_append new_libs " $deplib" ;;
10625698f425bSmrg	esac
10626698f425bSmrg      done
10627a3129944Smrg      compile_deplibs=$new_libs
10628266e564dSmrg
10629266e564dSmrg
106309ef0b394Smrg      func_append compile_command " $compile_deplibs"
106319ef0b394Smrg      func_append finalize_command " $finalize_deplibs"
10632266e564dSmrg
10633698f425bSmrg      if test -n "$rpath$xrpath"; then
10634698f425bSmrg	# If the user specified any rpath flags, then add them.
10635698f425bSmrg	for libdir in $rpath $xrpath; do
10636698f425bSmrg	  # This is the magic to use -rpath.
10637698f425bSmrg	  case "$finalize_rpath " in
10638698f425bSmrg	  *" $libdir "*) ;;
106399ef0b394Smrg	  *) func_append finalize_rpath " $libdir" ;;
10640698f425bSmrg	  esac
10641698f425bSmrg	done
10642698f425bSmrg      fi
10643266e564dSmrg
10644698f425bSmrg      # Now hardcode the library paths
10645698f425bSmrg      rpath=
10646698f425bSmrg      hardcode_libdirs=
10647698f425bSmrg      for libdir in $compile_rpath $finalize_rpath; do
10648698f425bSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10649698f425bSmrg	  if test -n "$hardcode_libdir_separator"; then
10650698f425bSmrg	    if test -z "$hardcode_libdirs"; then
10651a3129944Smrg	      hardcode_libdirs=$libdir
10652698f425bSmrg	    else
10653698f425bSmrg	      # Just accumulate the unique libdirs.
10654698f425bSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10655698f425bSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10656698f425bSmrg		;;
10657698f425bSmrg	      *)
106589ef0b394Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10659698f425bSmrg		;;
10660698f425bSmrg	      esac
10661698f425bSmrg	    fi
10662266e564dSmrg	  else
10663698f425bSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
106649ef0b394Smrg	    func_append rpath " $flag"
10665266e564dSmrg	  fi
10666698f425bSmrg	elif test -n "$runpath_var"; then
10667698f425bSmrg	  case "$perm_rpath " in
10668698f425bSmrg	  *" $libdir "*) ;;
106699ef0b394Smrg	  *) func_append perm_rpath " $libdir" ;;
10670698f425bSmrg	  esac
10671698f425bSmrg	fi
10672698f425bSmrg	case $host in
106733bf3b463Smrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
10674a3129944Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10675698f425bSmrg	  case :$dllsearchpath: in
10676698f425bSmrg	  *":$libdir:"*) ;;
10677698f425bSmrg	  ::) dllsearchpath=$libdir;;
106789ef0b394Smrg	  *) func_append dllsearchpath ":$libdir";;
10679698f425bSmrg	  esac
10680698f425bSmrg	  case :$dllsearchpath: in
10681698f425bSmrg	  *":$testbindir:"*) ;;
10682698f425bSmrg	  ::) dllsearchpath=$testbindir;;
106839ef0b394Smrg	  *) func_append dllsearchpath ":$testbindir";;
10684698f425bSmrg	  esac
10685698f425bSmrg	  ;;
10686698f425bSmrg	esac
10687698f425bSmrg      done
10688698f425bSmrg      # Substitute the hardcoded libdirs into the rpath.
10689698f425bSmrg      if test -n "$hardcode_libdir_separator" &&
10690698f425bSmrg	 test -n "$hardcode_libdirs"; then
10691a3129944Smrg	libdir=$hardcode_libdirs
10692698f425bSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10693698f425bSmrg      fi
10694a3129944Smrg      compile_rpath=$rpath
10695266e564dSmrg
10696698f425bSmrg      rpath=
10697698f425bSmrg      hardcode_libdirs=
10698698f425bSmrg      for libdir in $finalize_rpath; do
10699698f425bSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10700698f425bSmrg	  if test -n "$hardcode_libdir_separator"; then
10701698f425bSmrg	    if test -z "$hardcode_libdirs"; then
10702a3129944Smrg	      hardcode_libdirs=$libdir
10703698f425bSmrg	    else
10704698f425bSmrg	      # Just accumulate the unique libdirs.
10705698f425bSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10706698f425bSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10707698f425bSmrg		;;
10708698f425bSmrg	      *)
107099ef0b394Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10710698f425bSmrg		;;
10711698f425bSmrg	      esac
10712698f425bSmrg	    fi
10713266e564dSmrg	  else
10714698f425bSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
107159ef0b394Smrg	    func_append rpath " $flag"
10716266e564dSmrg	  fi
10717698f425bSmrg	elif test -n "$runpath_var"; then
10718698f425bSmrg	  case "$finalize_perm_rpath " in
10719698f425bSmrg	  *" $libdir "*) ;;
107209ef0b394Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10721698f425bSmrg	  esac
10722266e564dSmrg	fi
10723698f425bSmrg      done
10724698f425bSmrg      # Substitute the hardcoded libdirs into the rpath.
10725698f425bSmrg      if test -n "$hardcode_libdir_separator" &&
10726698f425bSmrg	 test -n "$hardcode_libdirs"; then
10727a3129944Smrg	libdir=$hardcode_libdirs
10728698f425bSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10729698f425bSmrg      fi
10730a3129944Smrg      finalize_rpath=$rpath
10731266e564dSmrg
10732a3129944Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10733698f425bSmrg	# Transform all the library objects into standard objects.
107349ef0b394Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
107359ef0b394Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10736698f425bSmrg      fi
10737266e564dSmrg
10738a3129944Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10739266e564dSmrg
10740698f425bSmrg      # template prelinking step
10741698f425bSmrg      if test -n "$prelink_cmds"; then
10742698f425bSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10743698f425bSmrg      fi
10744266e564dSmrg
10745a3129944Smrg      wrappers_required=:
10746698f425bSmrg      case $host in
107479ef0b394Smrg      *cegcc* | *mingw32ce*)
107489ef0b394Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10749a3129944Smrg        wrappers_required=false
107509ef0b394Smrg        ;;
107513bf3b463Smrg      *cygwin* | *mingw* | *windows* )
10752a3129944Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10753698f425bSmrg        ;;
10754698f425bSmrg      *)
10755a3129944Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10756a3129944Smrg          wrappers_required=false
10757698f425bSmrg        fi
10758698f425bSmrg        ;;
10759698f425bSmrg      esac
10760a3129944Smrg      $wrappers_required || {
10761698f425bSmrg	# Replace the output file specification.
107629ef0b394Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10763a3129944Smrg	link_command=$compile_command$compile_rpath
10764266e564dSmrg
10765698f425bSmrg	# We have no uninstalled library dependencies, so finalize right now.
10766698f425bSmrg	exit_status=0
10767698f425bSmrg	func_show_eval "$link_command" 'exit_status=$?'
10768266e564dSmrg
107699ef0b394Smrg	if test -n "$postlink_cmds"; then
107709ef0b394Smrg	  func_to_tool_file "$output"
107719ef0b394Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
107729ef0b394Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
107739ef0b394Smrg	fi
107749ef0b394Smrg
10775698f425bSmrg	# Delete the generated files.
10776a3129944Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10777a3129944Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10778266e564dSmrg	fi
10779266e564dSmrg
10780698f425bSmrg	exit $exit_status
10781a3129944Smrg      }
10782266e564dSmrg
10783698f425bSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10784698f425bSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10785698f425bSmrg      fi
10786698f425bSmrg      if test -n "$finalize_shlibpath"; then
10787698f425bSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10788698f425bSmrg      fi
10789266e564dSmrg
10790698f425bSmrg      compile_var=
10791698f425bSmrg      finalize_var=
10792698f425bSmrg      if test -n "$runpath_var"; then
10793698f425bSmrg	if test -n "$perm_rpath"; then
10794698f425bSmrg	  # We should set the runpath_var.
10795698f425bSmrg	  rpath=
10796698f425bSmrg	  for dir in $perm_rpath; do
107979ef0b394Smrg	    func_append rpath "$dir:"
10798698f425bSmrg	  done
10799698f425bSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10800266e564dSmrg	fi
10801698f425bSmrg	if test -n "$finalize_perm_rpath"; then
10802698f425bSmrg	  # We should set the runpath_var.
10803698f425bSmrg	  rpath=
10804698f425bSmrg	  for dir in $finalize_perm_rpath; do
108059ef0b394Smrg	    func_append rpath "$dir:"
10806698f425bSmrg	  done
10807698f425bSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10808266e564dSmrg	fi
10809698f425bSmrg      fi
10810266e564dSmrg
10811a3129944Smrg      if test yes = "$no_install"; then
10812698f425bSmrg	# We don't need to create a wrapper script.
10813a3129944Smrg	link_command=$compile_var$compile_command$compile_rpath
10814698f425bSmrg	# Replace the output file specification.
108159ef0b394Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10816698f425bSmrg	# Delete the old output file.
10817698f425bSmrg	$opt_dry_run || $RM $output
10818698f425bSmrg	# Link the executable and exit
10819698f425bSmrg	func_show_eval "$link_command" 'exit $?'
108209ef0b394Smrg
108219ef0b394Smrg	if test -n "$postlink_cmds"; then
108229ef0b394Smrg	  func_to_tool_file "$output"
108239ef0b394Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
108249ef0b394Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
108259ef0b394Smrg	fi
108269ef0b394Smrg
10827266e564dSmrg	exit $EXIT_SUCCESS
10828698f425bSmrg      fi
10829266e564dSmrg
10830a3129944Smrg      case $hardcode_action,$fast_install in
10831a3129944Smrg        relink,*)
10832a3129944Smrg	  # Fast installation is not supported
10833a3129944Smrg	  link_command=$compile_var$compile_command$compile_rpath
10834a3129944Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10835698f425bSmrg
10836a3129944Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10837a3129944Smrg	  func_warning "'$output' will be relinked during installation"
10838a3129944Smrg	  ;;
10839a3129944Smrg        *,yes)
10840a3129944Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10841a3129944Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10842a3129944Smrg          ;;
10843a3129944Smrg	*,no)
10844a3129944Smrg	  link_command=$compile_var$compile_command$compile_rpath
10845a3129944Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10846a3129944Smrg          ;;
10847a3129944Smrg	*,needless)
10848a3129944Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10849a3129944Smrg	  relink_command=
10850a3129944Smrg          ;;
10851a3129944Smrg      esac
10852266e564dSmrg
10853698f425bSmrg      # Replace the output file specification.
108549ef0b394Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10855266e564dSmrg
10856698f425bSmrg      # Delete the old output files.
10857698f425bSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10858266e564dSmrg
10859698f425bSmrg      func_show_eval "$link_command" 'exit $?'
10860266e564dSmrg
108619ef0b394Smrg      if test -n "$postlink_cmds"; then
108629ef0b394Smrg	func_to_tool_file "$output_objdir/$outputname"
108639ef0b394Smrg	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'`
108649ef0b394Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
108659ef0b394Smrg      fi
108669ef0b394Smrg
10867698f425bSmrg      # Now create the wrapper script.
10868698f425bSmrg      func_verbose "creating $output"
10869266e564dSmrg
10870698f425bSmrg      # Quote the relink command for shipping.
10871698f425bSmrg      if test -n "$relink_command"; then
10872698f425bSmrg	# Preserve any variables that may affect compiler behavior
10873698f425bSmrg	for var in $variables_saved_for_relink; do
10874698f425bSmrg	  if eval test -z \"\${$var+set}\"; then
10875698f425bSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10876698f425bSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10877698f425bSmrg	    relink_command="$var=; export $var; $relink_command"
10878266e564dSmrg	  else
108791009a292Smrg	    func_quote_arg pretty "$var_value"
108801009a292Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10881266e564dSmrg	  fi
10882698f425bSmrg	done
108831009a292Smrg	func_quote eval cd "`pwd`"
108841009a292Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
108851009a292Smrg	relink_command=$func_quote_arg_unquoted_result
10886698f425bSmrg      fi
10887698f425bSmrg
10888698f425bSmrg      # Only actually do things if not in dry run mode.
10889698f425bSmrg      $opt_dry_run || {
10890698f425bSmrg	# win32 will think the script is a binary if it has
10891698f425bSmrg	# a .exe suffix, so we strip it off here.
10892698f425bSmrg	case $output in
10893698f425bSmrg	  *.exe) func_stripname '' '.exe' "$output"
10894698f425bSmrg	         output=$func_stripname_result ;;
10895698f425bSmrg	esac
10896698f425bSmrg	# test for cygwin because mv fails w/o .exe extensions
10897698f425bSmrg	case $host in
10898698f425bSmrg	  *cygwin*)
10899698f425bSmrg	    exeext=.exe
10900698f425bSmrg	    func_stripname '' '.exe' "$outputname"
10901698f425bSmrg	    outputname=$func_stripname_result ;;
10902698f425bSmrg	  *) exeext= ;;
10903266e564dSmrg	esac
10904698f425bSmrg	case $host in
109053bf3b463Smrg	  *cygwin* | *mingw* | windows* )
10906698f425bSmrg	    func_dirname_and_basename "$output" "" "."
10907698f425bSmrg	    output_name=$func_basename_result
10908698f425bSmrg	    output_path=$func_dirname_result
10909a3129944Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10910a3129944Smrg	    cwrapper=$output_path/$output_name.exe
10911698f425bSmrg	    $RM $cwrappersource $cwrapper
10912698f425bSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10913698f425bSmrg
10914698f425bSmrg	    func_emit_cwrapperexe_src > $cwrappersource
10915698f425bSmrg
10916698f425bSmrg	    # The wrapper executable is built using the $host compiler,
10917698f425bSmrg	    # because it contains $host paths and files. If cross-
10918698f425bSmrg	    # compiling, it, like the target executable, must be
10919698f425bSmrg	    # executed on the $host or under an emulation environment.
10920698f425bSmrg	    $opt_dry_run || {
10921698f425bSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10922698f425bSmrg	      $STRIP $cwrapper
10923698f425bSmrg	    }
10924266e564dSmrg
10925698f425bSmrg	    # Now, create the wrapper script for func_source use:
10926698f425bSmrg	    func_ltwrapper_scriptname $cwrapper
10927698f425bSmrg	    $RM $func_ltwrapper_scriptname_result
10928698f425bSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10929698f425bSmrg	    $opt_dry_run || {
10930698f425bSmrg	      # note: this script will not be executed, so do not chmod.
10931a3129944Smrg	      if test "x$build" = "x$host"; then
10932698f425bSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10933698f425bSmrg	      else
10934698f425bSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10935698f425bSmrg	      fi
10936698f425bSmrg	    }
10937698f425bSmrg	  ;;
10938698f425bSmrg	  * )
10939698f425bSmrg	    $RM $output
10940698f425bSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10941266e564dSmrg
10942698f425bSmrg	    func_emit_wrapper no > $output
10943698f425bSmrg	    chmod +x $output
10944698f425bSmrg	  ;;
10945698f425bSmrg	esac
10946698f425bSmrg      }
10947698f425bSmrg      exit $EXIT_SUCCESS
10948698f425bSmrg      ;;
10949698f425bSmrg    esac
10950266e564dSmrg
10951698f425bSmrg    # See if we need to build an old-fashioned archive.
10952698f425bSmrg    for oldlib in $oldlibs; do
10953266e564dSmrg
10954a3129944Smrg      case $build_libtool_libs in
10955a3129944Smrg        convenience)
10956a3129944Smrg	  oldobjs="$libobjs_save $symfileobj"
10957a3129944Smrg	  addlibs=$convenience
10958698f425bSmrg	  build_libtool_libs=no
10959a3129944Smrg	  ;;
10960a3129944Smrg	module)
10961a3129944Smrg	  oldobjs=$libobjs_save
10962a3129944Smrg	  addlibs=$old_convenience
10963a3129944Smrg	  build_libtool_libs=no
10964a3129944Smrg          ;;
10965a3129944Smrg	*)
10966698f425bSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10967a3129944Smrg	  $preload && test -f "$symfileobj" \
10968a3129944Smrg	    && func_append oldobjs " $symfileobj"
10969a3129944Smrg	  addlibs=$old_convenience
10970a3129944Smrg	  ;;
10971a3129944Smrg      esac
10972266e564dSmrg
10973698f425bSmrg      if test -n "$addlibs"; then
10974a3129944Smrg	gentop=$output_objdir/${outputname}x
109759ef0b394Smrg	func_append generated " $gentop"
10976266e564dSmrg
10977698f425bSmrg	func_extract_archives $gentop $addlibs
109789ef0b394Smrg	func_append oldobjs " $func_extract_archives_result"
10979698f425bSmrg      fi
10980266e564dSmrg
10981698f425bSmrg      # Do each command in the archive commands.
10982a3129944Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10983698f425bSmrg	cmds=$old_archive_from_new_cmds
10984698f425bSmrg      else
10985266e564dSmrg
10986698f425bSmrg	# Add any objects from preloaded convenience libraries
10987698f425bSmrg	if test -n "$dlprefiles"; then
10988a3129944Smrg	  gentop=$output_objdir/${outputname}x
109899ef0b394Smrg	  func_append generated " $gentop"
10990266e564dSmrg
10991698f425bSmrg	  func_extract_archives $gentop $dlprefiles
109929ef0b394Smrg	  func_append oldobjs " $func_extract_archives_result"
10993698f425bSmrg	fi
10994266e564dSmrg
10995698f425bSmrg	# POSIX demands no paths to be encoded in archives.  We have
10996698f425bSmrg	# to avoid creating archives with duplicate basenames if we
10997698f425bSmrg	# might have to extract them afterwards, e.g., when creating a
10998698f425bSmrg	# static archive out of a convenience library, or when linking
10999698f425bSmrg	# the entirety of a libtool archive into another (currently
11000698f425bSmrg	# not supported by libtool).
11001698f425bSmrg	if (for obj in $oldobjs
11002698f425bSmrg	    do
11003698f425bSmrg	      func_basename "$obj"
11004698f425bSmrg	      $ECHO "$func_basename_result"
11005698f425bSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
11006698f425bSmrg	  :
11007698f425bSmrg	else
110089ef0b394Smrg	  echo "copying selected object files to avoid basename conflicts..."
11009a3129944Smrg	  gentop=$output_objdir/${outputname}x
110109ef0b394Smrg	  func_append generated " $gentop"
11011698f425bSmrg	  func_mkdir_p "$gentop"
11012698f425bSmrg	  save_oldobjs=$oldobjs
11013698f425bSmrg	  oldobjs=
11014698f425bSmrg	  counter=1
11015698f425bSmrg	  for obj in $save_oldobjs
11016698f425bSmrg	  do
11017698f425bSmrg	    func_basename "$obj"
11018a3129944Smrg	    objbase=$func_basename_result
11019698f425bSmrg	    case " $oldobjs " in
11020698f425bSmrg	    " ") oldobjs=$obj ;;
11021698f425bSmrg	    *[\ /]"$objbase "*)
11022698f425bSmrg	      while :; do
11023698f425bSmrg		# Make sure we don't pick an alternate name that also
11024698f425bSmrg		# overlaps.
11025698f425bSmrg		newobj=lt$counter-$objbase
11026698f425bSmrg		func_arith $counter + 1
11027698f425bSmrg		counter=$func_arith_result
11028698f425bSmrg		case " $oldobjs " in
11029698f425bSmrg		*[\ /]"$newobj "*) ;;
11030698f425bSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
11031698f425bSmrg		esac
11032698f425bSmrg	      done
11033698f425bSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
110349ef0b394Smrg	      func_append oldobjs " $gentop/$newobj"
11035698f425bSmrg	      ;;
110369ef0b394Smrg	    *) func_append oldobjs " $obj" ;;
11037698f425bSmrg	    esac
11038266e564dSmrg	  done
11039266e564dSmrg	fi
11040fb5e8d76Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
11041fb5e8d76Smrg	tool_oldlib=$func_to_tool_file_result
11042698f425bSmrg	eval cmds=\"$old_archive_cmds\"
11043266e564dSmrg
11044698f425bSmrg	func_len " $cmds"
11045698f425bSmrg	len=$func_len_result
11046698f425bSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
11047698f425bSmrg	  cmds=$old_archive_cmds
110489ef0b394Smrg	elif test -n "$archiver_list_spec"; then
110499ef0b394Smrg	  func_verbose "using command file archive linking..."
110509ef0b394Smrg	  for obj in $oldobjs
110519ef0b394Smrg	  do
110529ef0b394Smrg	    func_to_tool_file "$obj"
110539ef0b394Smrg	    $ECHO "$func_to_tool_file_result"
110549ef0b394Smrg	  done > $output_objdir/$libname.libcmd
110559ef0b394Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
110569ef0b394Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
110579ef0b394Smrg	  cmds=$old_archive_cmds
11058698f425bSmrg	else
11059698f425bSmrg	  # the command line is too long to link in one step, link in parts
11060698f425bSmrg	  func_verbose "using piecewise archive linking..."
11061698f425bSmrg	  save_RANLIB=$RANLIB
11062698f425bSmrg	  RANLIB=:
11063698f425bSmrg	  objlist=
11064698f425bSmrg	  concat_cmds=
11065698f425bSmrg	  save_oldobjs=$oldobjs
11066698f425bSmrg	  oldobjs=
11067698f425bSmrg	  # Is there a better way of finding the last object in the list?
11068698f425bSmrg	  for obj in $save_oldobjs
11069698f425bSmrg	  do
11070698f425bSmrg	    last_oldobj=$obj
11071698f425bSmrg	  done
11072698f425bSmrg	  eval test_cmds=\"$old_archive_cmds\"
11073698f425bSmrg	  func_len " $test_cmds"
11074698f425bSmrg	  len0=$func_len_result
11075698f425bSmrg	  len=$len0
11076698f425bSmrg	  for obj in $save_oldobjs
11077698f425bSmrg	  do
11078698f425bSmrg	    func_len " $obj"
11079698f425bSmrg	    func_arith $len + $func_len_result
11080698f425bSmrg	    len=$func_arith_result
11081698f425bSmrg	    func_append objlist " $obj"
11082698f425bSmrg	    if test "$len" -lt "$max_cmd_len"; then
11083698f425bSmrg	      :
11084698f425bSmrg	    else
11085698f425bSmrg	      # the above command should be used before it gets too long
11086698f425bSmrg	      oldobjs=$objlist
11087a3129944Smrg	      if test "$obj" = "$last_oldobj"; then
11088698f425bSmrg		RANLIB=$save_RANLIB
11089698f425bSmrg	      fi
11090698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11091a3129944Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11092698f425bSmrg	      objlist=
11093698f425bSmrg	      len=$len0
11094698f425bSmrg	    fi
11095698f425bSmrg	  done
11096698f425bSmrg	  RANLIB=$save_RANLIB
11097698f425bSmrg	  oldobjs=$objlist
11098a3129944Smrg	  if test -z "$oldobjs"; then
11099698f425bSmrg	    eval cmds=\"\$concat_cmds\"
11100698f425bSmrg	  else
11101698f425bSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11102698f425bSmrg	  fi
11103698f425bSmrg	fi
11104698f425bSmrg      fi
11105698f425bSmrg      func_execute_cmds "$cmds" 'exit $?'
11106266e564dSmrg    done
11107266e564dSmrg
11108698f425bSmrg    test -n "$generated" && \
11109698f425bSmrg      func_show_eval "${RM}r$generated"
11110266e564dSmrg
11111698f425bSmrg    # Now create the libtool archive.
11112698f425bSmrg    case $output in
11113698f425bSmrg    *.la)
11114698f425bSmrg      old_library=
11115a3129944Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11116698f425bSmrg      func_verbose "creating $output"
11117266e564dSmrg
11118698f425bSmrg      # Preserve any variables that may affect compiler behavior
11119698f425bSmrg      for var in $variables_saved_for_relink; do
11120698f425bSmrg	if eval test -z \"\${$var+set}\"; then
11121698f425bSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11122698f425bSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
11123698f425bSmrg	  relink_command="$var=; export $var; $relink_command"
11124266e564dSmrg	else
111251009a292Smrg	  func_quote_arg pretty,unquoted "$var_value"
111261009a292Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11127266e564dSmrg	fi
11128698f425bSmrg      done
11129698f425bSmrg      # Quote the link command for shipping.
111301009a292Smrg      func_quote eval cd "`pwd`"
111311009a292Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
111321009a292Smrg      func_quote_arg pretty,unquoted "$relink_command"
111331009a292Smrg      relink_command=$func_quote_arg_unquoted_result
11134a3129944Smrg      if test yes = "$hardcode_automatic"; then
11135698f425bSmrg	relink_command=
11136698f425bSmrg      fi
11137266e564dSmrg
11138698f425bSmrg      # Only create the output if not a dry run.
11139698f425bSmrg      $opt_dry_run || {
11140698f425bSmrg	for installed in no yes; do
11141a3129944Smrg	  if test yes = "$installed"; then
11142698f425bSmrg	    if test -z "$install_libdir"; then
11143698f425bSmrg	      break
11144698f425bSmrg	    fi
11145a3129944Smrg	    output=$output_objdir/${outputname}i
11146698f425bSmrg	    # Replace all uninstalled libtool libraries with the installed ones
11147698f425bSmrg	    newdependency_libs=
11148698f425bSmrg	    for deplib in $dependency_libs; do
11149698f425bSmrg	      case $deplib in
11150698f425bSmrg	      *.la)
11151698f425bSmrg		func_basename "$deplib"
11152a3129944Smrg		name=$func_basename_result
11153fb5e8d76Smrg		func_resolve_sysroot "$deplib"
11154a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11155698f425bSmrg		test -z "$libdir" && \
11156a3129944Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
111579ef0b394Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
111589ef0b394Smrg		;;
111599ef0b394Smrg	      -L*)
111609ef0b394Smrg		func_stripname -L '' "$deplib"
111619ef0b394Smrg		func_replace_sysroot "$func_stripname_result"
111629ef0b394Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11163698f425bSmrg		;;
111649ef0b394Smrg	      -R*)
111659ef0b394Smrg		func_stripname -R '' "$deplib"
111669ef0b394Smrg		func_replace_sysroot "$func_stripname_result"
111679ef0b394Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
111689ef0b394Smrg		;;
111699ef0b394Smrg	      *) func_append newdependency_libs " $deplib" ;;
11170698f425bSmrg	      esac
11171698f425bSmrg	    done
11172a3129944Smrg	    dependency_libs=$newdependency_libs
11173698f425bSmrg	    newdlfiles=
11174698f425bSmrg
11175698f425bSmrg	    for lib in $dlfiles; do
11176698f425bSmrg	      case $lib in
11177698f425bSmrg	      *.la)
11178698f425bSmrg	        func_basename "$lib"
11179a3129944Smrg		name=$func_basename_result
11180a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11181698f425bSmrg		test -z "$libdir" && \
11182a3129944Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
111839ef0b394Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11184698f425bSmrg		;;
111859ef0b394Smrg	      *) func_append newdlfiles " $lib" ;;
11186698f425bSmrg	      esac
11187698f425bSmrg	    done
11188a3129944Smrg	    dlfiles=$newdlfiles
11189698f425bSmrg	    newdlprefiles=
11190698f425bSmrg	    for lib in $dlprefiles; do
11191698f425bSmrg	      case $lib in
11192698f425bSmrg	      *.la)
11193698f425bSmrg		# Only pass preopened files to the pseudo-archive (for
11194698f425bSmrg		# eventual linking with the app. that links it) if we
11195698f425bSmrg		# didn't already link the preopened objects directly into
11196698f425bSmrg		# the library:
11197698f425bSmrg		func_basename "$lib"
11198a3129944Smrg		name=$func_basename_result
11199a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11200698f425bSmrg		test -z "$libdir" && \
11201a3129944Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
112029ef0b394Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11203698f425bSmrg		;;
11204698f425bSmrg	      esac
11205698f425bSmrg	    done
11206a3129944Smrg	    dlprefiles=$newdlprefiles
11207698f425bSmrg	  else
11208698f425bSmrg	    newdlfiles=
11209698f425bSmrg	    for lib in $dlfiles; do
11210698f425bSmrg	      case $lib in
11211a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11212698f425bSmrg		*) abs=`pwd`"/$lib" ;;
11213698f425bSmrg	      esac
112149ef0b394Smrg	      func_append newdlfiles " $abs"
11215698f425bSmrg	    done
11216a3129944Smrg	    dlfiles=$newdlfiles
11217698f425bSmrg	    newdlprefiles=
11218698f425bSmrg	    for lib in $dlprefiles; do
11219698f425bSmrg	      case $lib in
11220a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11221698f425bSmrg		*) abs=`pwd`"/$lib" ;;
11222698f425bSmrg	      esac
112239ef0b394Smrg	      func_append newdlprefiles " $abs"
11224698f425bSmrg	    done
11225a3129944Smrg	    dlprefiles=$newdlprefiles
11226698f425bSmrg	  fi
11227698f425bSmrg	  $RM $output
11228698f425bSmrg	  # place dlname in correct position for cygwin
112299ef0b394Smrg	  # In fact, it would be nice if we could use this code for all target
112309ef0b394Smrg	  # systems that can't hard-code library paths into their executables
112319ef0b394Smrg	  # and that have no shared library path variable independent of PATH,
112329ef0b394Smrg	  # but it turns out we can't easily determine that from inspecting
112339ef0b394Smrg	  # libtool variables, so we have to hard-code the OSs to which it
112349ef0b394Smrg	  # applies here; at the moment, that means platforms that use the PE
112359ef0b394Smrg	  # object format with DLL files.  See the long comment at the top of
112369ef0b394Smrg	  # tests/bindir.at for full details.
11237698f425bSmrg	  tdlname=$dlname
11238698f425bSmrg	  case $host,$output,$installed,$module,$dlname in
112393bf3b463Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *windows*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
112409ef0b394Smrg	      # If a -bindir argument was supplied, place the dll there.
11241a3129944Smrg	      if test -n "$bindir"; then
112429ef0b394Smrg		func_relative_path "$install_libdir" "$bindir"
11243a3129944Smrg		tdlname=$func_relative_path_result/$dlname
112449ef0b394Smrg	      else
112459ef0b394Smrg		# Otherwise fall back on heuristic.
112469ef0b394Smrg		tdlname=../bin/$dlname
112479ef0b394Smrg	      fi
112489ef0b394Smrg	      ;;
11249698f425bSmrg	  esac
11250698f425bSmrg	  $ECHO > $output "\
11251698f425bSmrg# $outputname - a libtool library file
11252a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11253698f425bSmrg#
11254698f425bSmrg# Please DO NOT delete this file!
11255698f425bSmrg# It is necessary for linking the library.
11256266e564dSmrg
11257698f425bSmrg# The name that we can dlopen(3).
11258698f425bSmrgdlname='$tdlname'
11259266e564dSmrg
11260698f425bSmrg# Names of this library.
11261698f425bSmrglibrary_names='$library_names'
11262266e564dSmrg
11263698f425bSmrg# The name of the static archive.
11264698f425bSmrgold_library='$old_library'
11265266e564dSmrg
11266a3129944Smrg# Linker flags that cannot go in dependency_libs.
11267698f425bSmrginherited_linker_flags='$new_inherited_linker_flags'
11268266e564dSmrg
11269698f425bSmrg# Libraries that this one depends upon.
11270698f425bSmrgdependency_libs='$dependency_libs'
11271266e564dSmrg
11272698f425bSmrg# Names of additional weak libraries provided by this library
11273698f425bSmrgweak_library_names='$weak_libs'
11274266e564dSmrg
11275698f425bSmrg# Version information for $libname.
11276698f425bSmrgcurrent=$current
11277698f425bSmrgage=$age
11278698f425bSmrgrevision=$revision
11279266e564dSmrg
11280698f425bSmrg# Is this an already installed library?
11281698f425bSmrginstalled=$installed
11282266e564dSmrg
11283698f425bSmrg# Should we warn about portability when linking against -modules?
11284698f425bSmrgshouldnotlink=$module
11285266e564dSmrg
11286698f425bSmrg# Files to dlopen/dlpreopen
11287698f425bSmrgdlopen='$dlfiles'
11288698f425bSmrgdlpreopen='$dlprefiles'
11289266e564dSmrg
11290698f425bSmrg# Directory that this library needs to be installed in:
11291698f425bSmrglibdir='$install_libdir'"
11292a3129944Smrg	  if test no,yes = "$installed,$need_relink"; then
11293698f425bSmrg	    $ECHO >> $output "\
11294698f425bSmrgrelink_command=\"$relink_command\""
11295698f425bSmrg	  fi
11296698f425bSmrg	done
11297698f425bSmrg      }
11298266e564dSmrg
11299698f425bSmrg      # Do a symbolic link so that the libtool archive can be found in
11300698f425bSmrg      # LD_LIBRARY_PATH before the program is installed.
11301698f425bSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11302698f425bSmrg      ;;
11303698f425bSmrg    esac
11304698f425bSmrg    exit $EXIT_SUCCESS
11305698f425bSmrg}
11306266e564dSmrg
11307a3129944Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11308a3129944Smrg  func_mode_link ${1+"$@"}
11309a3129944Smrgfi
11310266e564dSmrg
11311266e564dSmrg
11312698f425bSmrg# func_mode_uninstall arg...
11313698f425bSmrgfunc_mode_uninstall ()
11314698f425bSmrg{
11315a3129944Smrg    $debug_cmd
11316a3129944Smrg
11317a3129944Smrg    RM=$nonopt
11318266e564dSmrg    files=
11319a3129944Smrg    rmforce=false
11320266e564dSmrg    exit_status=0
11321266e564dSmrg
11322266e564dSmrg    # This variable tells wrapper scripts just to set variables rather
11323266e564dSmrg    # than running their programs.
11324a3129944Smrg    libtool_install_magic=$magic
11325266e564dSmrg
11326266e564dSmrg    for arg
11327266e564dSmrg    do
11328266e564dSmrg      case $arg in
11329a3129944Smrg      -f) func_append RM " $arg"; rmforce=: ;;
113309ef0b394Smrg      -*) func_append RM " $arg" ;;
113319ef0b394Smrg      *) func_append files " $arg" ;;
11332266e564dSmrg      esac
11333266e564dSmrg    done
11334266e564dSmrg
11335698f425bSmrg    test -z "$RM" && \
11336698f425bSmrg      func_fatal_help "you must specify an RM program"
11337266e564dSmrg
11338266e564dSmrg    rmdirs=
11339266e564dSmrg
11340266e564dSmrg    for file in $files; do
11341698f425bSmrg      func_dirname "$file" "" "."
11342a3129944Smrg      dir=$func_dirname_result
11343a3129944Smrg      if test . = "$dir"; then
11344a3129944Smrg	odir=$objdir
11345266e564dSmrg      else
11346a3129944Smrg	odir=$dir/$objdir
11347266e564dSmrg      fi
11348698f425bSmrg      func_basename "$file"
11349a3129944Smrg      name=$func_basename_result
11350a3129944Smrg      test uninstall = "$opt_mode" && odir=$dir
11351266e564dSmrg
113529ef0b394Smrg      # Remember odir for removal later, being careful to avoid duplicates
11353a3129944Smrg      if test clean = "$opt_mode"; then
11354266e564dSmrg	case " $rmdirs " in
113559ef0b394Smrg	  *" $odir "*) ;;
113569ef0b394Smrg	  *) func_append rmdirs " $odir" ;;
11357266e564dSmrg	esac
11358266e564dSmrg      fi
11359266e564dSmrg
11360266e564dSmrg      # Don't error if the file doesn't exist and rm -f was used.
11361698f425bSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11362698f425bSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11363698f425bSmrg	 test -f "$file"; then
11364266e564dSmrg	:
11365266e564dSmrg      elif test -d "$file"; then
11366266e564dSmrg	exit_status=1
11367266e564dSmrg	continue
11368a3129944Smrg      elif $rmforce; then
11369266e564dSmrg	continue
11370266e564dSmrg      fi
11371266e564dSmrg
11372a3129944Smrg      rmfiles=$file
11373266e564dSmrg
11374266e564dSmrg      case $name in
11375266e564dSmrg      *.la)
11376266e564dSmrg	# Possibly a libtool archive, so verify it.
11377698f425bSmrg	if func_lalib_p "$file"; then
11378698f425bSmrg	  func_source $dir/$name
11379266e564dSmrg
11380266e564dSmrg	  # Delete the libtool libraries and symlinks.
11381266e564dSmrg	  for n in $library_names; do
113829ef0b394Smrg	    func_append rmfiles " $odir/$n"
11383266e564dSmrg	  done
113849ef0b394Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11385266e564dSmrg
11386a3129944Smrg	  case $opt_mode in
11387266e564dSmrg	  clean)
113889ef0b394Smrg	    case " $library_names " in
11389266e564dSmrg	    *" $dlname "*) ;;
113909ef0b394Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11391266e564dSmrg	    esac
113929ef0b394Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11393266e564dSmrg	    ;;
11394266e564dSmrg	  uninstall)
11395266e564dSmrg	    if test -n "$library_names"; then
11396266e564dSmrg	      # Do each command in the postuninstall commands.
11397a3129944Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11398266e564dSmrg	    fi
11399266e564dSmrg
11400266e564dSmrg	    if test -n "$old_library"; then
11401266e564dSmrg	      # Do each command in the old_postuninstall commands.
11402a3129944Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11403266e564dSmrg	    fi
11404266e564dSmrg	    # FIXME: should reinstall the best remaining shared library.
11405266e564dSmrg	    ;;
11406266e564dSmrg	  esac
11407266e564dSmrg	fi
11408266e564dSmrg	;;
11409266e564dSmrg
11410266e564dSmrg      *.lo)
11411266e564dSmrg	# Possibly a libtool object, so verify it.
11412698f425bSmrg	if func_lalib_p "$file"; then
11413266e564dSmrg
11414266e564dSmrg	  # Read the .lo file
11415698f425bSmrg	  func_source $dir/$name
11416266e564dSmrg
11417266e564dSmrg	  # Add PIC object to the list of files to remove.
11418a3129944Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
114199ef0b394Smrg	    func_append rmfiles " $dir/$pic_object"
11420266e564dSmrg	  fi
11421266e564dSmrg
11422266e564dSmrg	  # Add non-PIC object to the list of files to remove.
11423a3129944Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
114249ef0b394Smrg	    func_append rmfiles " $dir/$non_pic_object"
11425266e564dSmrg	  fi
11426266e564dSmrg	fi
11427266e564dSmrg	;;
11428266e564dSmrg
11429266e564dSmrg      *)
11430a3129944Smrg	if test clean = "$opt_mode"; then
11431266e564dSmrg	  noexename=$name
11432266e564dSmrg	  case $file in
11433266e564dSmrg	  *.exe)
11434698f425bSmrg	    func_stripname '' '.exe' "$file"
11435698f425bSmrg	    file=$func_stripname_result
11436698f425bSmrg	    func_stripname '' '.exe' "$name"
11437698f425bSmrg	    noexename=$func_stripname_result
11438266e564dSmrg	    # $file with .exe has already been added to rmfiles,
11439266e564dSmrg	    # add $file without .exe
114409ef0b394Smrg	    func_append rmfiles " $file"
11441266e564dSmrg	    ;;
11442266e564dSmrg	  esac
11443266e564dSmrg	  # Do a test to see if this is a libtool program.
11444698f425bSmrg	  if func_ltwrapper_p "$file"; then
11445698f425bSmrg	    if func_ltwrapper_executable_p "$file"; then
11446698f425bSmrg	      func_ltwrapper_scriptname "$file"
11447698f425bSmrg	      relink_command=
11448698f425bSmrg	      func_source $func_ltwrapper_scriptname_result
114499ef0b394Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11450698f425bSmrg	    else
11451698f425bSmrg	      relink_command=
11452698f425bSmrg	      func_source $dir/$noexename
11453698f425bSmrg	    fi
11454266e564dSmrg
11455266e564dSmrg	    # note $name still contains .exe if it was in $file originally
11456266e564dSmrg	    # as does the version of $file that was added into $rmfiles
11457a3129944Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11458a3129944Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
114599ef0b394Smrg	      func_append rmfiles " $odir/lt-$name"
11460266e564dSmrg	    fi
11461a3129944Smrg	    if test "X$noexename" != "X$name"; then
11462a3129944Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11463266e564dSmrg	    fi
11464266e564dSmrg	  fi
11465266e564dSmrg	fi
11466266e564dSmrg	;;
11467266e564dSmrg      esac
11468698f425bSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11469266e564dSmrg    done
11470266e564dSmrg
11471a3129944Smrg    # Try to remove the $objdir's in the directories where we deleted files
11472266e564dSmrg    for dir in $rmdirs; do
11473266e564dSmrg      if test -d "$dir"; then
11474698f425bSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11475266e564dSmrg      fi
11476266e564dSmrg    done
11477266e564dSmrg
11478266e564dSmrg    exit $exit_status
11479698f425bSmrg}
11480266e564dSmrg
11481a3129944Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11482a3129944Smrg  func_mode_uninstall ${1+"$@"}
11483a3129944Smrgfi
11484266e564dSmrg
114859ef0b394Smrgtest -z "$opt_mode" && {
11486a3129944Smrg  help=$generic_help
11487698f425bSmrg  func_fatal_help "you must specify a MODE"
11488698f425bSmrg}
11489698f425bSmrg
11490698f425bSmrgtest -z "$exec_cmd" && \
11491a3129944Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11492266e564dSmrg
11493266e564dSmrgif test -n "$exec_cmd"; then
11494698f425bSmrg  eval exec "$exec_cmd"
11495266e564dSmrg  exit $EXIT_FAILURE
11496266e564dSmrgfi
11497266e564dSmrg
11498698f425bSmrgexit $exit_status
11499266e564dSmrg
11500266e564dSmrg
11501266e564dSmrg# The TAGs below are defined such that we never get into a situation
11502a3129944Smrg# where we disable both kinds of libraries.  Given conflicting
11503266e564dSmrg# choices, we go for a static library, that is the most portable,
11504266e564dSmrg# since we can't tell whether shared libraries were disabled because
11505266e564dSmrg# the user asked for that or because the platform doesn't support
11506266e564dSmrg# them.  This is particularly important on AIX, because we don't
11507266e564dSmrg# support having both static and shared libraries enabled at the same
11508266e564dSmrg# time on that platform, so we default to a shared-only configuration.
11509266e564dSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11510266e564dSmrg# configuration.  But we'll never go from static-only to shared-only.
11511266e564dSmrg
11512266e564dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11513698f425bSmrgbuild_libtool_libs=no
11514698f425bSmrgbuild_old_libs=yes
11515266e564dSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11516266e564dSmrg
11517266e564dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11518698f425bSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11519266e564dSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11520266e564dSmrg
11521266e564dSmrg# Local Variables:
11522266e564dSmrg# mode:shell-script
11523266e564dSmrg# sh-indentation:2
11524266e564dSmrg# End:
11525