ltmain.sh revision c30f5000
1c30f5000Smrg#! /usr/bin/env sh
2b3a827e2Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3c30f5000Smrg##               by inline-source v2019-02-19.15
4f05b35a2Smrg
5c30f5000Smrg# libtool (GNU libtool) 2.4.7
6b3a827e2Smrg# Provide generalized library-building support services.
7f05b35a2Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8f05b35a2Smrg
9c30f5000Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10f05b35a2Smrg# This is free software; see the source for copying conditions.  There is NO
11f05b35a2Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12f05b35a2Smrg
13f05b35a2Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14e0963edeSmrg# it under the terms of the GNU General Public License as published by
15e0963edeSmrg# the Free Software Foundation; either version 2 of the License, or
16e0963edeSmrg# (at your option) any later version.
17e0963edeSmrg#
18f05b35a2Smrg# As a special exception to the GNU General Public License,
19f05b35a2Smrg# if you distribute this file as part of a program or library that
20f05b35a2Smrg# is built using GNU Libtool, you may include this file under the
21f05b35a2Smrg# same distribution terms that you use for the rest of that program.
22f05b35a2Smrg#
23f05b35a2Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24e0963edeSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25e0963edeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26e0963edeSmrg# General Public License for more details.
27e0963edeSmrg#
28e0963edeSmrg# You should have received a copy of the GNU General Public License
29b3a827e2Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30e0963edeSmrg
31e0963edeSmrg
3249e108a1SmrgPROGRAM=libtool
33e0963edeSmrgPACKAGE=libtool
34c30f5000SmrgVERSION=2.4.7
35c30f5000Smrgpackage_revision=2.4.7
36e0963edeSmrg
37b3a827e2Smrg
38b3a827e2Smrg## ------ ##
39b3a827e2Smrg## Usage. ##
40b3a827e2Smrg## ------ ##
41b3a827e2Smrg
42b3a827e2Smrg# Run './libtool --help' for help with using this script from the
43b3a827e2Smrg# command line.
44b3a827e2Smrg
45b3a827e2Smrg
46b3a827e2Smrg## ------------------------------- ##
47b3a827e2Smrg## User overridable command paths. ##
48b3a827e2Smrg## ------------------------------- ##
49b3a827e2Smrg
50b3a827e2Smrg# After configure completes, it has a better idea of some of the
51b3a827e2Smrg# shell tools we need than the defaults used by the functions shared
52b3a827e2Smrg# with bootstrap, so set those here where they can still be over-
53b3a827e2Smrg# ridden by the user, but otherwise take precedence.
54b3a827e2Smrg
55b3a827e2Smrg: ${AUTOCONF="autoconf"}
56b3a827e2Smrg: ${AUTOMAKE="automake"}
57b3a827e2Smrg
58b3a827e2Smrg
59b3a827e2Smrg## -------------------------- ##
60b3a827e2Smrg## Source external libraries. ##
61b3a827e2Smrg## -------------------------- ##
62b3a827e2Smrg
63b3a827e2Smrg# Much of our low-level functionality needs to be sourced from external
64b3a827e2Smrg# libraries, which are installed to $pkgauxdir.
65b3a827e2Smrg
66b3a827e2Smrg# Set a version string for this script.
67c30f5000Smrgscriptversion=2019-02-19.15; # UTC
68b3a827e2Smrg
69b3a827e2Smrg# General shell script boiler plate, and helper functions.
70b3a827e2Smrg# Written by Gary V. Vaughan, 2004
71b3a827e2Smrg
72c30f5000Smrg# This is free software.  There is NO warranty; not even for
73c30f5000Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74c30f5000Smrg#
75c30f5000Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76c30f5000Smrg#
77c30f5000Smrg# This file is dual licensed under the terms of the MIT license
78c30f5000Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79c30f5000Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80c30f5000Smrg# these licenses when using or redistributing this software or any of
81c30f5000Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82c30f5000Smrg# included in the Bootstrap distribution for the full license texts.
83b3a827e2Smrg
84c30f5000Smrg# Please report bugs or propose patches to:
85c30f5000Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86b3a827e2Smrg
87b3a827e2Smrg
88b3a827e2Smrg## ------ ##
89b3a827e2Smrg## Usage. ##
90b3a827e2Smrg## ------ ##
91b3a827e2Smrg
92b3a827e2Smrg# Evaluate this file near the top of your script to gain access to
93b3a827e2Smrg# the functions and variables defined here:
94b3a827e2Smrg#
95b3a827e2Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96b3a827e2Smrg#
97b3a827e2Smrg# If you need to override any of the default environment variable
98b3a827e2Smrg# settings, do that before evaluating this file.
99b3a827e2Smrg
100b3a827e2Smrg
101b3a827e2Smrg## -------------------- ##
102b3a827e2Smrg## Shell normalisation. ##
103b3a827e2Smrg## -------------------- ##
104b3a827e2Smrg
105b3a827e2Smrg# Some shells need a little help to be as Bourne compatible as possible.
106b3a827e2Smrg# Before doing anything else, make sure all that help has been provided!
107b3a827e2Smrg
108b3a827e2SmrgDUALCASE=1; export DUALCASE # for MKS sh
109b3a827e2Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110e0963edeSmrg  emulate sh
111e0963edeSmrg  NULLCMD=:
112b3a827e2Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113e0963edeSmrg  # is contrary to our usage.  Disable this feature.
114e0963edeSmrg  alias -g '${1+"$@"}'='"$@"'
115e0963edeSmrg  setopt NO_GLOB_SUBST
116e0963edeSmrgelse
117b3a827e2Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118e0963edeSmrgfi
11949e108a1Smrg
120b3a827e2Smrg# NLS nuisances: We save the old values in case they are required later.
121b3a827e2Smrg_G_user_locale=
122b3a827e2Smrg_G_safe_locale=
123b3a827e2Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124e0963edeSmrgdo
125b3a827e2Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126b3a827e2Smrg          save_$_G_var=\$$_G_var
127b3a827e2Smrg          $_G_var=C
128b3a827e2Smrg	  export $_G_var
129b3a827e2Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130b3a827e2Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131e0963edeSmrg	fi"
132e0963edeSmrgdone
133c30f5000Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134c30f5000Smrg# in case the environment reset is needed later and the $save_* variant is not
135c30f5000Smrg# defined (see the code above).
136c30f5000SmrgLC_ALL=C
137c30f5000SmrgLANGUAGE=C
138c30f5000Smrgexport LANGUAGE LC_ALL
139f05b35a2Smrg
140b3a827e2Smrg# Make sure IFS has a sensible default
141b3a827e2Smrgsp=' '
142b3a827e2Smrgnl='
143b3a827e2Smrg'
144b3a827e2SmrgIFS="$sp	$nl"
145b3a827e2Smrg
146b3a827e2Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
147b3a827e2Smrgif test "${PATH_SEPARATOR+set}" != set; then
148b3a827e2Smrg  PATH_SEPARATOR=:
149b3a827e2Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150b3a827e2Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151b3a827e2Smrg      PATH_SEPARATOR=';'
152b3a827e2Smrg  }
153b3a827e2Smrgfi
154f05b35a2Smrg
155f05b35a2Smrg
156c30f5000Smrg# func_unset VAR
157c30f5000Smrg# --------------
158c30f5000Smrg# Portably unset VAR.
159c30f5000Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160c30f5000Smrg# status if VAR is already unset, which might be problematic if the
161c30f5000Smrg# statement is used at the end of a function (thus poisoning its return
162c30f5000Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163c30f5000Smrg# the script in this case).
164c30f5000Smrgfunc_unset ()
165c30f5000Smrg{
166c30f5000Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167c30f5000Smrg}
168c30f5000Smrg
169c30f5000Smrg
170c30f5000Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171c30f5000Smrgfunc_unset CDPATH
172c30f5000Smrg
173c30f5000Smrg# Make sure ${,E,F}GREP behave sanely.
174c30f5000Smrgfunc_unset GREP_OPTIONS
175c30f5000Smrg
176f05b35a2Smrg
177b3a827e2Smrg## ------------------------- ##
178b3a827e2Smrg## Locate command utilities. ##
179b3a827e2Smrg## ------------------------- ##
180b3a827e2Smrg
181b3a827e2Smrg
182b3a827e2Smrg# func_executable_p FILE
183b3a827e2Smrg# ----------------------
184b3a827e2Smrg# Check that FILE is an executable regular file.
185b3a827e2Smrgfunc_executable_p ()
186b3a827e2Smrg{
187b3a827e2Smrg    test -f "$1" && test -x "$1"
188b3a827e2Smrg}
189b3a827e2Smrg
190b3a827e2Smrg
191b3a827e2Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192b3a827e2Smrg# --------------------------------------------
193b3a827e2Smrg# Search for either a program that responds to --version with output
194b3a827e2Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195b3a827e2Smrg# trying all the directories in PATH with each of the elements of
196b3a827e2Smrg# PROGS_LIST.
197b3a827e2Smrg#
198b3a827e2Smrg# CHECK_FUNC should accept the path to a candidate program, and
199b3a827e2Smrg# set $func_check_prog_result if it truncates its output less than
200b3a827e2Smrg# $_G_path_prog_max characters.
201b3a827e2Smrgfunc_path_progs ()
202b3a827e2Smrg{
203b3a827e2Smrg    _G_progs_list=$1
204b3a827e2Smrg    _G_check_func=$2
205b3a827e2Smrg    _G_PATH=${3-"$PATH"}
206b3a827e2Smrg
207b3a827e2Smrg    _G_path_prog_max=0
208b3a827e2Smrg    _G_path_prog_found=false
209b3a827e2Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210b3a827e2Smrg    for _G_dir in $_G_PATH; do
211b3a827e2Smrg      IFS=$_G_save_IFS
212b3a827e2Smrg      test -z "$_G_dir" && _G_dir=.
213b3a827e2Smrg      for _G_prog_name in $_G_progs_list; do
214b3a827e2Smrg        for _exeext in '' .EXE; do
215b3a827e2Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216b3a827e2Smrg          func_executable_p "$_G_path_prog" || continue
217b3a827e2Smrg          case `"$_G_path_prog" --version 2>&1` in
218b3a827e2Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219b3a827e2Smrg            *)     $_G_check_func $_G_path_prog
220b3a827e2Smrg		   func_path_progs_result=$func_check_prog_result
221b3a827e2Smrg		   ;;
222b3a827e2Smrg          esac
223b3a827e2Smrg          $_G_path_prog_found && break 3
224b3a827e2Smrg        done
225b3a827e2Smrg      done
226b3a827e2Smrg    done
227b3a827e2Smrg    IFS=$_G_save_IFS
228b3a827e2Smrg    test -z "$func_path_progs_result" && {
229b3a827e2Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230b3a827e2Smrg      exit 1
231b3a827e2Smrg    }
232b3a827e2Smrg}
233b3a827e2Smrg
234b3a827e2Smrg
235b3a827e2Smrg# We want to be able to use the functions in this file before configure
236b3a827e2Smrg# has figured out where the best binaries are kept, which means we have
237b3a827e2Smrg# to search for them ourselves - except when the results are already set
238b3a827e2Smrg# where we skip the searches.
239b3a827e2Smrg
240b3a827e2Smrg# Unless the user overrides by setting SED, search the path for either GNU
241b3a827e2Smrg# sed, or the sed that truncates its output the least.
242b3a827e2Smrgtest -z "$SED" && {
243b3a827e2Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244b3a827e2Smrg  for _G_i in 1 2 3 4 5 6 7; do
245b3a827e2Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246b3a827e2Smrg  done
247b3a827e2Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248b3a827e2Smrg  _G_sed_script=
249b3a827e2Smrg
250b3a827e2Smrg  func_check_prog_sed ()
251b3a827e2Smrg  {
252b3a827e2Smrg    _G_path_prog=$1
253b3a827e2Smrg
254b3a827e2Smrg    _G_count=0
255b3a827e2Smrg    printf 0123456789 >conftest.in
256b3a827e2Smrg    while :
257b3a827e2Smrg    do
258b3a827e2Smrg      cat conftest.in conftest.in >conftest.tmp
259b3a827e2Smrg      mv conftest.tmp conftest.in
260b3a827e2Smrg      cp conftest.in conftest.nl
261b3a827e2Smrg      echo '' >> conftest.nl
262b3a827e2Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263b3a827e2Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264b3a827e2Smrg      _G_count=`expr $_G_count + 1`
265b3a827e2Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266b3a827e2Smrg        # Best one so far, save it but keep looking for a better one
267b3a827e2Smrg        func_check_prog_result=$_G_path_prog
268b3a827e2Smrg        _G_path_prog_max=$_G_count
269b3a827e2Smrg      fi
270b3a827e2Smrg      # 10*(2^10) chars as input seems more than enough
271b3a827e2Smrg      test 10 -lt "$_G_count" && break
272b3a827e2Smrg    done
273b3a827e2Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274b3a827e2Smrg  }
275b3a827e2Smrg
276c30f5000Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277b3a827e2Smrg  rm -f conftest.sed
278b3a827e2Smrg  SED=$func_path_progs_result
279b3a827e2Smrg}
280b3a827e2Smrg
281b3a827e2Smrg
282b3a827e2Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283b3a827e2Smrg# grep, or the grep that truncates its output the least.
284b3a827e2Smrgtest -z "$GREP" && {
285b3a827e2Smrg  func_check_prog_grep ()
286b3a827e2Smrg  {
287b3a827e2Smrg    _G_path_prog=$1
288b3a827e2Smrg
289b3a827e2Smrg    _G_count=0
290b3a827e2Smrg    _G_path_prog_max=0
291b3a827e2Smrg    printf 0123456789 >conftest.in
292b3a827e2Smrg    while :
293b3a827e2Smrg    do
294b3a827e2Smrg      cat conftest.in conftest.in >conftest.tmp
295b3a827e2Smrg      mv conftest.tmp conftest.in
296b3a827e2Smrg      cp conftest.in conftest.nl
297b3a827e2Smrg      echo 'GREP' >> conftest.nl
298b3a827e2Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299b3a827e2Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300b3a827e2Smrg      _G_count=`expr $_G_count + 1`
301b3a827e2Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302b3a827e2Smrg        # Best one so far, save it but keep looking for a better one
303b3a827e2Smrg        func_check_prog_result=$_G_path_prog
304b3a827e2Smrg        _G_path_prog_max=$_G_count
305b3a827e2Smrg      fi
306b3a827e2Smrg      # 10*(2^10) chars as input seems more than enough
307b3a827e2Smrg      test 10 -lt "$_G_count" && break
308b3a827e2Smrg    done
309b3a827e2Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310b3a827e2Smrg  }
311b3a827e2Smrg
312c30f5000Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313b3a827e2Smrg  GREP=$func_path_progs_result
314b3a827e2Smrg}
315b3a827e2Smrg
316b3a827e2Smrg
317b3a827e2Smrg## ------------------------------- ##
318b3a827e2Smrg## User overridable command paths. ##
319b3a827e2Smrg## ------------------------------- ##
320b3a827e2Smrg
321b3a827e2Smrg# All uppercase variable names are used for environment variables.  These
322b3a827e2Smrg# variables can be overridden by the user before calling a script that
323b3a827e2Smrg# uses them if a suitable command of that name is not already available
324b3a827e2Smrg# in the command search PATH.
325f05b35a2Smrg
326f05b35a2Smrg: ${CP="cp -f"}
327b3a827e2Smrg: ${ECHO="printf %s\n"}
328b3a827e2Smrg: ${EGREP="$GREP -E"}
329b3a827e2Smrg: ${FGREP="$GREP -F"}
330b3a827e2Smrg: ${LN_S="ln -s"}
331f05b35a2Smrg: ${MAKE="make"}
332f05b35a2Smrg: ${MKDIR="mkdir"}
333f05b35a2Smrg: ${MV="mv -f"}
334f05b35a2Smrg: ${RM="rm -f"}
335f05b35a2Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336e0963edeSmrg
337f05b35a2Smrg
338b3a827e2Smrg## -------------------- ##
339b3a827e2Smrg## Useful sed snippets. ##
340b3a827e2Smrg## -------------------- ##
34167ab2ff2Smrg
342b3a827e2Smrgsed_dirname='s|/[^/]*$||'
343b3a827e2Smrgsed_basename='s|^.*/||'
34467ab2ff2Smrg
345b3a827e2Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346b3a827e2Smrg# metacharacters that are still active within double-quoted strings.
347b3a827e2Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
34867ab2ff2Smrg
349b3a827e2Smrg# Same as above, but do not quote variable references.
350b3a827e2Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
35167ab2ff2Smrg
352b3a827e2Smrg# Sed substitution that turns a string into a regex matching for the
353b3a827e2Smrg# string literally.
354b3a827e2Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
35567ab2ff2Smrg
356b3a827e2Smrg# Sed substitution that converts a w32 file name or path
357b3a827e2Smrg# that contains forward slashes, into one that contains
358b3a827e2Smrg# (escaped) backslashes.  A very naive implementation.
359b3a827e2Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360b3a827e2Smrg
361b3a827e2Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362b3a827e2Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363b3a827e2Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364b3a827e2Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365b3a827e2Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366b3a827e2Smrg_G_bs='\\'
367b3a827e2Smrg_G_bs2='\\\\'
368b3a827e2Smrg_G_bs4='\\\\\\\\'
369b3a827e2Smrg_G_dollar='\$'
370b3a827e2Smrgsed_double_backslash="\
371b3a827e2Smrg  s/$_G_bs4/&\\
372b3a827e2Smrg/g
373b3a827e2Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374b3a827e2Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375b3a827e2Smrg  s/\n//g"
37667ab2ff2Smrg
377c30f5000Smrg# require_check_ifs_backslash
378c30f5000Smrg# ---------------------------
379c30f5000Smrg# Check if we can use backslash as IFS='\' separator, and set
380c30f5000Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381c30f5000Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382c30f5000Smrgfunc_require_check_ifs_backslash ()
383c30f5000Smrg{
384c30f5000Smrg  _G_save_IFS=$IFS
385c30f5000Smrg  IFS='\'
386c30f5000Smrg  _G_check_ifs_backshlash='a\\b'
387c30f5000Smrg  for _G_i in $_G_check_ifs_backshlash
388c30f5000Smrg  do
389c30f5000Smrg  case $_G_i in
390c30f5000Smrg  a)
391c30f5000Smrg    check_ifs_backshlash_broken=false
392c30f5000Smrg    ;;
393c30f5000Smrg  '')
394c30f5000Smrg    break
395c30f5000Smrg    ;;
396c30f5000Smrg  *)
397c30f5000Smrg    check_ifs_backshlash_broken=:
398c30f5000Smrg    break
399c30f5000Smrg    ;;
400c30f5000Smrg  esac
401c30f5000Smrg  done
402c30f5000Smrg  IFS=$_G_save_IFS
403c30f5000Smrg  require_check_ifs_backslash=:
404c30f5000Smrg}
405c30f5000Smrg
406e0963edeSmrg
407b3a827e2Smrg## ----------------- ##
408b3a827e2Smrg## Global variables. ##
409b3a827e2Smrg## ----------------- ##
410f05b35a2Smrg
411b3a827e2Smrg# Except for the global variables explicitly listed below, the following
412b3a827e2Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413b3a827e2Smrg# variables initialised in the 'Resource management' section, sourcing
414b3a827e2Smrg# this file will not pollute your global namespace with anything
415b3a827e2Smrg# else. There's no portable way to scope variables in Bourne shell
416b3a827e2Smrg# though, so actually running these functions will sometimes place
417b3a827e2Smrg# results into a variable named after the function, and often use
418b3a827e2Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419b3a827e2Smrg# avoid using those namespaces casually in your sourcing script, things
420b3a827e2Smrg# should continue to work as you expect. And, of course, you can freely
421b3a827e2Smrg# overwrite any of the functions or variables defined here before
422b3a827e2Smrg# calling anything to customize them.
42349e108a1Smrg
424b3a827e2SmrgEXIT_SUCCESS=0
425b3a827e2SmrgEXIT_FAILURE=1
426b3a827e2SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427b3a827e2SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
42849e108a1Smrg
429b3a827e2Smrg# Allow overriding, eg assuming that you follow the convention of
430b3a827e2Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431b3a827e2Smrg# bash to show function call trace with:
432b3a827e2Smrg#
433b3a827e2Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434b3a827e2Smrgdebug_cmd=${debug_cmd-":"}
435b3a827e2Smrgexit_cmd=:
43649e108a1Smrg
437b3a827e2Smrg# By convention, finish your script with:
438b3a827e2Smrg#
439b3a827e2Smrg#    exit $exit_status
440b3a827e2Smrg#
441b3a827e2Smrg# so that you can set exit_status to non-zero if you want to indicate
442b3a827e2Smrg# something went wrong during execution without actually bailing out at
443b3a827e2Smrg# the point of failure.
444b3a827e2Smrgexit_status=$EXIT_SUCCESS
44549e108a1Smrg
446b3a827e2Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447b3a827e2Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448b3a827e2Smrg# the _XPG environment variable is not equal to 1 (one), the special
449b3a827e2Smrg# positional parameter $0, within a function call, is the name of the
450b3a827e2Smrg# function.
451b3a827e2Smrgprogpath=$0
452f05b35a2Smrg
453b3a827e2Smrg# The name of this program.
454b3a827e2Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455f05b35a2Smrg
456b3a827e2Smrg# Make sure we have an absolute progpath for reexecution:
457f05b35a2Smrgcase $progpath in
458f05b35a2Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459f05b35a2Smrg  *[\\/]*)
460b3a827e2Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461f05b35a2Smrg     progdir=`cd "$progdir" && pwd`
462b3a827e2Smrg     progpath=$progdir/$progname
463f05b35a2Smrg     ;;
464f05b35a2Smrg  *)
465b3a827e2Smrg     _G_IFS=$IFS
466e494fffdSmrg     IFS=${PATH_SEPARATOR-:}
467f05b35a2Smrg     for progdir in $PATH; do
468b3a827e2Smrg       IFS=$_G_IFS
469f05b35a2Smrg       test -x "$progdir/$progname" && break
470f05b35a2Smrg     done
471b3a827e2Smrg     IFS=$_G_IFS
472f05b35a2Smrg     test -n "$progdir" || progdir=`pwd`
473b3a827e2Smrg     progpath=$progdir/$progname
474f05b35a2Smrg     ;;
475f05b35a2Smrgesac
476f05b35a2Smrg
477f05b35a2Smrg
478b3a827e2Smrg## ----------------- ##
479b3a827e2Smrg## Standard options. ##
480b3a827e2Smrg## ----------------- ##
48167ab2ff2Smrg
482b3a827e2Smrg# The following options affect the operation of the functions defined
483b3a827e2Smrg# below, and should be set appropriately depending on run-time para-
484b3a827e2Smrg# meters passed on the command line.
485f05b35a2Smrg
486f05b35a2Smrgopt_dry_run=false
487f05b35a2Smrgopt_quiet=false
488f05b35a2Smrgopt_verbose=false
489f05b35a2Smrg
490b3a827e2Smrg# Categories 'all' and 'none' are always available.  Append any others
491b3a827e2Smrg# you will pass as the first argument to func_warning from your own
492b3a827e2Smrg# code.
493b3a827e2Smrgwarning_categories=
494f05b35a2Smrg
495b3a827e2Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496b3a827e2Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497b3a827e2Smrg# treat the next displayed warning as a fatal error.
498b3a827e2Smrgwarning_func=func_warn_and_continue
499f05b35a2Smrg
500b3a827e2Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501b3a827e2Smrg# warnings, or a space delimited list of some subset of
502b3a827e2Smrg# 'warning_categories' to display only the listed warnings.
503b3a827e2Smrgopt_warning_types=all
504f05b35a2Smrg
50549e108a1Smrg
506b3a827e2Smrg## -------------------- ##
507b3a827e2Smrg## Resource management. ##
508b3a827e2Smrg## -------------------- ##
509f05b35a2Smrg
510b3a827e2Smrg# This section contains definitions for functions that each ensure a
511b3a827e2Smrg# particular resource (a file, or a non-empty configuration variable for
512b3a827e2Smrg# example) is available, and if appropriate to extract default values
513b3a827e2Smrg# from pertinent package files. Call them using their associated
514b3a827e2Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515b3a827e2Smrg#
516b3a827e2Smrg# It's entirely deliberate that calling these functions can set
517b3a827e2Smrg# variables that don't obey the namespace limitations obeyed by the rest
518b3a827e2Smrg# of this file, in order that that they be as useful as possible to
519b3a827e2Smrg# callers.
520f05b35a2Smrg
521f05b35a2Smrg
522b3a827e2Smrg# require_term_colors
523b3a827e2Smrg# -------------------
524b3a827e2Smrg# Allow display of bold text on terminals that support it.
525b3a827e2Smrgrequire_term_colors=func_require_term_colors
526b3a827e2Smrgfunc_require_term_colors ()
527f05b35a2Smrg{
528b3a827e2Smrg    $debug_cmd
529b3a827e2Smrg
530b3a827e2Smrg    test -t 1 && {
531b3a827e2Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532b3a827e2Smrg      # precedence, because most terminfo databases neglect to describe
533b3a827e2Smrg      # whether color sequences are supported.
534b3a827e2Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535b3a827e2Smrg
536b3a827e2Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537b3a827e2Smrg        # Standard ANSI escape sequences
538b3a827e2Smrg        tc_reset='[0m'
539b3a827e2Smrg        tc_bold='[1m';   tc_standout='[7m'
540b3a827e2Smrg        tc_red='[31m';   tc_green='[32m'
541b3a827e2Smrg        tc_blue='[34m';  tc_cyan='[36m'
542b3a827e2Smrg      else
543b3a827e2Smrg        # Otherwise trust the terminfo database after all.
544b3a827e2Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545b3a827e2Smrg          tc_reset=`tput sgr0`
546b3a827e2Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547b3a827e2Smrg          tc_standout=$tc_bold
548b3a827e2Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549b3a827e2Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550b3a827e2Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551b3a827e2Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552b3a827e2Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553b3a827e2Smrg        }
554b3a827e2Smrg      fi
555b3a827e2Smrg    }
556f05b35a2Smrg
557b3a827e2Smrg    require_term_colors=:
558f05b35a2Smrg}
559f05b35a2Smrg
560f05b35a2Smrg
561b3a827e2Smrg## ----------------- ##
562b3a827e2Smrg## Function library. ##
563b3a827e2Smrg## ----------------- ##
564b3a827e2Smrg
565b3a827e2Smrg# This section contains a variety of useful functions to call in your
566b3a827e2Smrg# scripts. Take note of the portable wrappers for features provided by
567b3a827e2Smrg# some modern shells, which will fall back to slower equivalents on
568b3a827e2Smrg# less featureful shells.
569b3a827e2Smrg
570b3a827e2Smrg
571b3a827e2Smrg# func_append VAR VALUE
572b3a827e2Smrg# ---------------------
573b3a827e2Smrg# Append VALUE onto the existing contents of VAR.
574b3a827e2Smrg
575b3a827e2Smrg  # We should try to minimise forks, especially on Windows where they are
576b3a827e2Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577b3a827e2Smrg  # being used:
578b3a827e2Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579b3a827e2Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580b3a827e2Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581b3a827e2Smrg    # The += operator was introduced in bash 3.1
582b3a827e2Smrg    case $BASH_VERSION in
583b3a827e2Smrg      [12].* | 3.0 | 3.0*) ;;
584b3a827e2Smrg      *)
585b3a827e2Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586b3a827e2Smrg        ;;
587b3a827e2Smrg    esac
588b3a827e2Smrg  fi
589b3a827e2Smrg
590b3a827e2Smrg  # _G_HAVE_PLUSEQ_OP
591b3a827e2Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
592b3a827e2Smrg  # useable or anything else if it does not work.
593b3a827e2Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594b3a827e2Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595b3a827e2Smrg    && _G_HAVE_PLUSEQ_OP=yes
596b3a827e2Smrg
597b3a827e2Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598b3a827e2Smrgthen
599b3a827e2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600b3a827e2Smrg  eval 'func_append ()
601b3a827e2Smrg  {
602b3a827e2Smrg    $debug_cmd
603b3a827e2Smrg
604b3a827e2Smrg    eval "$1+=\$2"
605b3a827e2Smrg  }'
606b3a827e2Smrgelse
607b3a827e2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608b3a827e2Smrg  func_append ()
609b3a827e2Smrg  {
610b3a827e2Smrg    $debug_cmd
611b3a827e2Smrg
612b3a827e2Smrg    eval "$1=\$$1\$2"
613b3a827e2Smrg  }
614b3a827e2Smrgfi
615b3a827e2Smrg
616b3a827e2Smrg
617b3a827e2Smrg# func_append_quoted VAR VALUE
618b3a827e2Smrg# ----------------------------
619b3a827e2Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620b3a827e2Smrg# by a space.
621b3a827e2Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622b3a827e2Smrg  eval 'func_append_quoted ()
623b3a827e2Smrg  {
624b3a827e2Smrg    $debug_cmd
625b3a827e2Smrg
626c30f5000Smrg    func_quote_arg pretty "$2"
627c30f5000Smrg    eval "$1+=\\ \$func_quote_arg_result"
628b3a827e2Smrg  }'
629b3a827e2Smrgelse
630b3a827e2Smrg  func_append_quoted ()
631b3a827e2Smrg  {
632b3a827e2Smrg    $debug_cmd
633b3a827e2Smrg
634c30f5000Smrg    func_quote_arg pretty "$2"
635c30f5000Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636b3a827e2Smrg  }
637b3a827e2Smrgfi
638b3a827e2Smrg
639b3a827e2Smrg
640b3a827e2Smrg# func_append_uniq VAR VALUE
641b3a827e2Smrg# --------------------------
642b3a827e2Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643b3a827e2Smrg# entries are delimited by the first character of VALUE.  For example:
644b3a827e2Smrg#
645b3a827e2Smrg#   func_append_uniq options " --another-option option-argument"
646b3a827e2Smrg#
647b3a827e2Smrg# will only append to $options if " --another-option option-argument "
648b3a827e2Smrg# is not already present somewhere in $options already (note spaces at
649b3a827e2Smrg# each end implied by leading space in second argument).
650b3a827e2Smrgfunc_append_uniq ()
651b3a827e2Smrg{
652b3a827e2Smrg    $debug_cmd
653b3a827e2Smrg
654b3a827e2Smrg    eval _G_current_value='`$ECHO $'$1'`'
655b3a827e2Smrg    _G_delim=`expr "$2" : '\(.\)'`
656b3a827e2Smrg
657b3a827e2Smrg    case $_G_delim$_G_current_value$_G_delim in
658b3a827e2Smrg      *"$2$_G_delim"*) ;;
659b3a827e2Smrg      *) func_append "$@" ;;
660b3a827e2Smrg    esac
661b3a827e2Smrg}
662b3a827e2Smrg
663b3a827e2Smrg
664b3a827e2Smrg# func_arith TERM...
665b3a827e2Smrg# ------------------
666b3a827e2Smrg# Set func_arith_result to the result of evaluating TERMs.
667b3a827e2Smrg  test -z "$_G_HAVE_ARITH_OP" \
668b3a827e2Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669b3a827e2Smrg    && _G_HAVE_ARITH_OP=yes
670b3a827e2Smrg
671b3a827e2Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672b3a827e2Smrg  eval 'func_arith ()
673b3a827e2Smrg  {
674b3a827e2Smrg    $debug_cmd
675b3a827e2Smrg
676b3a827e2Smrg    func_arith_result=$(( $* ))
677b3a827e2Smrg  }'
678b3a827e2Smrgelse
679b3a827e2Smrg  func_arith ()
680b3a827e2Smrg  {
681b3a827e2Smrg    $debug_cmd
682b3a827e2Smrg
683b3a827e2Smrg    func_arith_result=`expr "$@"`
684b3a827e2Smrg  }
685b3a827e2Smrgfi
686b3a827e2Smrg
687b3a827e2Smrg
688b3a827e2Smrg# func_basename FILE
689b3a827e2Smrg# ------------------
690b3a827e2Smrg# Set func_basename_result to FILE with everything up to and including
691b3a827e2Smrg# the last / stripped.
692b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693b3a827e2Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694b3a827e2Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695b3a827e2Smrg  # on unsupported syntax...
696b3a827e2Smrg  _b='func_basename_result=${1##*/}'
697b3a827e2Smrg  _d='case $1 in
698b3a827e2Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699b3a827e2Smrg        *  ) func_dirname_result=$3        ;;
700b3a827e2Smrg      esac'
701b3a827e2Smrg
702b3a827e2Smrgelse
703b3a827e2Smrg  # ...otherwise fall back to using sed.
704b3a827e2Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705b3a827e2Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706b3a827e2Smrg      if test "X$func_dirname_result" = "X$1"; then
707b3a827e2Smrg        func_dirname_result=$3
708b3a827e2Smrg      else
709b3a827e2Smrg        func_append func_dirname_result "$2"
710b3a827e2Smrg      fi'
711b3a827e2Smrgfi
712b3a827e2Smrg
713b3a827e2Smrgeval 'func_basename ()
714b3a827e2Smrg{
715b3a827e2Smrg    $debug_cmd
716b3a827e2Smrg
717b3a827e2Smrg    '"$_b"'
718b3a827e2Smrg}'
719b3a827e2Smrg
720b3a827e2Smrg
721b3a827e2Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722b3a827e2Smrg# -------------------------------------------
723b3a827e2Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724b3a827e2Smrg# otherwise set result to NONDIR_REPLACEMENT.
725b3a827e2Smrgeval 'func_dirname ()
726b3a827e2Smrg{
727b3a827e2Smrg    $debug_cmd
728b3a827e2Smrg
729b3a827e2Smrg    '"$_d"'
730b3a827e2Smrg}'
731b3a827e2Smrg
732b3a827e2Smrg
733b3a827e2Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734b3a827e2Smrg# --------------------------------------------------------
735b3a827e2Smrg# Perform func_basename and func_dirname in a single function
736b3a827e2Smrg# call:
737b3a827e2Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738b3a827e2Smrg#             add APPEND to the result, otherwise set result
739b3a827e2Smrg#             to NONDIR_REPLACEMENT.
740b3a827e2Smrg#             value returned in "$func_dirname_result"
741b3a827e2Smrg#   basename: Compute filename of FILE.
742b3a827e2Smrg#             value retuned in "$func_basename_result"
743b3a827e2Smrg# For efficiency, we do not delegate to the functions above but instead
744b3a827e2Smrg# duplicate the functionality here.
745b3a827e2Smrgeval 'func_dirname_and_basename ()
746b3a827e2Smrg{
747b3a827e2Smrg    $debug_cmd
748b3a827e2Smrg
749b3a827e2Smrg    '"$_b"'
750b3a827e2Smrg    '"$_d"'
751b3a827e2Smrg}'
752b3a827e2Smrg
753b3a827e2Smrg
754b3a827e2Smrg# func_echo ARG...
755b3a827e2Smrg# ----------------
756b3a827e2Smrg# Echo program name prefixed message.
757b3a827e2Smrgfunc_echo ()
758b3a827e2Smrg{
759b3a827e2Smrg    $debug_cmd
760b3a827e2Smrg
761b3a827e2Smrg    _G_message=$*
762b3a827e2Smrg
763b3a827e2Smrg    func_echo_IFS=$IFS
764b3a827e2Smrg    IFS=$nl
765b3a827e2Smrg    for _G_line in $_G_message; do
766b3a827e2Smrg      IFS=$func_echo_IFS
767b3a827e2Smrg      $ECHO "$progname: $_G_line"
768b3a827e2Smrg    done
769b3a827e2Smrg    IFS=$func_echo_IFS
770b3a827e2Smrg}
771b3a827e2Smrg
772b3a827e2Smrg
773b3a827e2Smrg# func_echo_all ARG...
774b3a827e2Smrg# --------------------
775b3a827e2Smrg# Invoke $ECHO with all args, space-separated.
776b3a827e2Smrgfunc_echo_all ()
777b3a827e2Smrg{
778b3a827e2Smrg    $ECHO "$*"
779b3a827e2Smrg}
780b3a827e2Smrg
781b3a827e2Smrg
782b3a827e2Smrg# func_echo_infix_1 INFIX ARG...
783b3a827e2Smrg# ------------------------------
784b3a827e2Smrg# Echo program name, followed by INFIX on the first line, with any
785b3a827e2Smrg# additional lines not showing INFIX.
786b3a827e2Smrgfunc_echo_infix_1 ()
787b3a827e2Smrg{
788b3a827e2Smrg    $debug_cmd
789b3a827e2Smrg
790b3a827e2Smrg    $require_term_colors
791b3a827e2Smrg
792b3a827e2Smrg    _G_infix=$1; shift
793b3a827e2Smrg    _G_indent=$_G_infix
794b3a827e2Smrg    _G_prefix="$progname: $_G_infix: "
795b3a827e2Smrg    _G_message=$*
796b3a827e2Smrg
797b3a827e2Smrg    # Strip color escape sequences before counting printable length
798b3a827e2Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799b3a827e2Smrg    do
800b3a827e2Smrg      test -n "$_G_tc" && {
801b3a827e2Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802b3a827e2Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803b3a827e2Smrg      }
804b3a827e2Smrg    done
805b3a827e2Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806b3a827e2Smrg
807b3a827e2Smrg    func_echo_infix_1_IFS=$IFS
808b3a827e2Smrg    IFS=$nl
809b3a827e2Smrg    for _G_line in $_G_message; do
810b3a827e2Smrg      IFS=$func_echo_infix_1_IFS
811b3a827e2Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812b3a827e2Smrg      _G_prefix=$_G_indent
813b3a827e2Smrg    done
814b3a827e2Smrg    IFS=$func_echo_infix_1_IFS
815b3a827e2Smrg}
816b3a827e2Smrg
817b3a827e2Smrg
818b3a827e2Smrg# func_error ARG...
819b3a827e2Smrg# -----------------
820b3a827e2Smrg# Echo program name prefixed message to standard error.
821b3a827e2Smrgfunc_error ()
822b3a827e2Smrg{
823b3a827e2Smrg    $debug_cmd
824b3a827e2Smrg
825b3a827e2Smrg    $require_term_colors
826b3a827e2Smrg
827b3a827e2Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828b3a827e2Smrg}
829b3a827e2Smrg
830b3a827e2Smrg
831b3a827e2Smrg# func_fatal_error ARG...
832b3a827e2Smrg# -----------------------
833b3a827e2Smrg# Echo program name prefixed message to standard error, and exit.
834b3a827e2Smrgfunc_fatal_error ()
835b3a827e2Smrg{
836b3a827e2Smrg    $debug_cmd
837b3a827e2Smrg
838b3a827e2Smrg    func_error "$*"
839b3a827e2Smrg    exit $EXIT_FAILURE
840b3a827e2Smrg}
841b3a827e2Smrg
842b3a827e2Smrg
843b3a827e2Smrg# func_grep EXPRESSION FILENAME
844b3a827e2Smrg# -----------------------------
845f05b35a2Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846f05b35a2Smrgfunc_grep ()
847f05b35a2Smrg{
848b3a827e2Smrg    $debug_cmd
849b3a827e2Smrg
850f05b35a2Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851f05b35a2Smrg}
852f05b35a2Smrg
853f05b35a2Smrg
854b3a827e2Smrg# func_len STRING
855b3a827e2Smrg# ---------------
856b3a827e2Smrg# Set func_len_result to the length of STRING. STRING may not
857b3a827e2Smrg# start with a hyphen.
858b3a827e2Smrg  test -z "$_G_HAVE_XSI_OPS" \
859b3a827e2Smrg    && (eval 'x=a/b/c;
860b3a827e2Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861b3a827e2Smrg    && _G_HAVE_XSI_OPS=yes
862b3a827e2Smrg
863b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864b3a827e2Smrg  eval 'func_len ()
865b3a827e2Smrg  {
866b3a827e2Smrg    $debug_cmd
867b3a827e2Smrg
868b3a827e2Smrg    func_len_result=${#1}
869b3a827e2Smrg  }'
870b3a827e2Smrgelse
871b3a827e2Smrg  func_len ()
872b3a827e2Smrg  {
873b3a827e2Smrg    $debug_cmd
874b3a827e2Smrg
875b3a827e2Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876b3a827e2Smrg  }
877b3a827e2Smrgfi
878b3a827e2Smrg
879b3a827e2Smrg
880b3a827e2Smrg# func_mkdir_p DIRECTORY-PATH
881b3a827e2Smrg# ---------------------------
882f05b35a2Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883f05b35a2Smrgfunc_mkdir_p ()
884f05b35a2Smrg{
885b3a827e2Smrg    $debug_cmd
886f05b35a2Smrg
887b3a827e2Smrg    _G_directory_path=$1
888b3a827e2Smrg    _G_dir_list=
889f05b35a2Smrg
890b3a827e2Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891b3a827e2Smrg
892b3a827e2Smrg      # Protect directory names starting with '-'
893b3a827e2Smrg      case $_G_directory_path in
894b3a827e2Smrg        -*) _G_directory_path=./$_G_directory_path ;;
895f05b35a2Smrg      esac
896f05b35a2Smrg
897f05b35a2Smrg      # While some portion of DIR does not yet exist...
898b3a827e2Smrg      while test ! -d "$_G_directory_path"; do
899f05b35a2Smrg        # ...make a list in topmost first order.  Use a colon delimited
900f05b35a2Smrg	# list incase some portion of path contains whitespace.
901b3a827e2Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902f05b35a2Smrg
903f05b35a2Smrg        # If the last portion added has no slash in it, the list is done
904b3a827e2Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
905f05b35a2Smrg
906f05b35a2Smrg        # ...otherwise throw away the child directory and loop
907b3a827e2Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908f05b35a2Smrg      done
909b3a827e2Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910f05b35a2Smrg
911b3a827e2Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912b3a827e2Smrg      for _G_dir in $_G_dir_list; do
913b3a827e2Smrg	IFS=$func_mkdir_p_IFS
914b3a827e2Smrg        # mkdir can fail with a 'File exist' error if two processes
915f05b35a2Smrg        # try to create one of the directories concurrently.  Don't
916f05b35a2Smrg        # stop in that case!
917b3a827e2Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
918f05b35a2Smrg      done
919b3a827e2Smrg      IFS=$func_mkdir_p_IFS
920f05b35a2Smrg
921f05b35a2Smrg      # Bail out if we (or some other process) failed to create a directory.
922b3a827e2Smrg      test -d "$_G_directory_path" || \
923b3a827e2Smrg        func_fatal_error "Failed to create '$1'"
924f05b35a2Smrg    fi
925f05b35a2Smrg}
926e0963edeSmrg
927e0963edeSmrg
928b3a827e2Smrg# func_mktempdir [BASENAME]
929b3a827e2Smrg# -------------------------
930e0963edeSmrg# Make a temporary directory that won't clash with other running
931e0963edeSmrg# libtool processes, and avoids race conditions if possible.  If
932b3a827e2Smrg# given, BASENAME is the basename for that directory.
933e0963edeSmrgfunc_mktempdir ()
934e0963edeSmrg{
935b3a827e2Smrg    $debug_cmd
936b3a827e2Smrg
937b3a827e2Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938e0963edeSmrg
939b3a827e2Smrg    if test : = "$opt_dry_run"; then
940e0963edeSmrg      # Return a directory name, but don't create it in dry-run mode
941b3a827e2Smrg      _G_tmpdir=$_G_template-$$
942e0963edeSmrg    else
943e0963edeSmrg
944e0963edeSmrg      # If mktemp works, use that first and foremost
945b3a827e2Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946e0963edeSmrg
947b3a827e2Smrg      if test ! -d "$_G_tmpdir"; then
948f05b35a2Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949b3a827e2Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950e0963edeSmrg
951b3a827e2Smrg        func_mktempdir_umask=`umask`
952f05b35a2Smrg        umask 0077
953b3a827e2Smrg        $MKDIR "$_G_tmpdir"
954b3a827e2Smrg        umask $func_mktempdir_umask
955e0963edeSmrg      fi
956e0963edeSmrg
957e0963edeSmrg      # If we're not in dry-run mode, bomb out on failure
958b3a827e2Smrg      test -d "$_G_tmpdir" || \
959b3a827e2Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960b3a827e2Smrg    fi
961b3a827e2Smrg
962b3a827e2Smrg    $ECHO "$_G_tmpdir"
963b3a827e2Smrg}
964b3a827e2Smrg
965b3a827e2Smrg
966b3a827e2Smrg# func_normal_abspath PATH
967b3a827e2Smrg# ------------------------
968b3a827e2Smrg# Remove doubled-up and trailing slashes, "." path components,
969b3a827e2Smrg# and cancel out any ".." path components in PATH after making
970b3a827e2Smrg# it an absolute path.
971b3a827e2Smrgfunc_normal_abspath ()
972b3a827e2Smrg{
973b3a827e2Smrg    $debug_cmd
974b3a827e2Smrg
975b3a827e2Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976b3a827e2Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977b3a827e2Smrg    _G_pathcdr='s|^/[^/]*||'
978b3a827e2Smrg    _G_removedotparts=':dotsl
979b3a827e2Smrg		s|/\./|/|g
980b3a827e2Smrg		t dotsl
981b3a827e2Smrg		s|/\.$|/|'
982b3a827e2Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983b3a827e2Smrg    _G_finalslash='s|/*$|/|'
984b3a827e2Smrg
985b3a827e2Smrg    # Start from root dir and reassemble the path.
986b3a827e2Smrg    func_normal_abspath_result=
987b3a827e2Smrg    func_normal_abspath_tpath=$1
988b3a827e2Smrg    func_normal_abspath_altnamespace=
989b3a827e2Smrg    case $func_normal_abspath_tpath in
990b3a827e2Smrg      "")
991b3a827e2Smrg        # Empty path, that just means $cwd.
992b3a827e2Smrg        func_stripname '' '/' "`pwd`"
993b3a827e2Smrg        func_normal_abspath_result=$func_stripname_result
994b3a827e2Smrg        return
995b3a827e2Smrg        ;;
996b3a827e2Smrg      # The next three entries are used to spot a run of precisely
997b3a827e2Smrg      # two leading slashes without using negated character classes;
998b3a827e2Smrg      # we take advantage of case's first-match behaviour.
999b3a827e2Smrg      ///*)
1000b3a827e2Smrg        # Unusual form of absolute path, do nothing.
1001b3a827e2Smrg        ;;
1002b3a827e2Smrg      //*)
1003b3a827e2Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004b3a827e2Smrg        # and for example Cygwin uses it to access remote file shares
1005b3a827e2Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006b3a827e2Smrg        func_normal_abspath_altnamespace=/
1007b3a827e2Smrg        ;;
1008b3a827e2Smrg      /*)
1009b3a827e2Smrg        # Absolute path, do nothing.
1010b3a827e2Smrg        ;;
1011b3a827e2Smrg      *)
1012b3a827e2Smrg        # Relative path, prepend $cwd.
1013b3a827e2Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014b3a827e2Smrg        ;;
1015b3a827e2Smrg    esac
1016b3a827e2Smrg
1017b3a827e2Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018b3a827e2Smrg    # the path to end with a slash for ease of parsing, so make sure
1019b3a827e2Smrg    # there is one (and only one) here.
1020b3a827e2Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021b3a827e2Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022b3a827e2Smrg    while :; do
1023b3a827e2Smrg      # Processed it all yet?
1024b3a827e2Smrg      if test / = "$func_normal_abspath_tpath"; then
1025b3a827e2Smrg        # If we ascended to the root using ".." the result may be empty now.
1026b3a827e2Smrg        if test -z "$func_normal_abspath_result"; then
1027b3a827e2Smrg          func_normal_abspath_result=/
1028b3a827e2Smrg        fi
1029b3a827e2Smrg        break
1030b3a827e2Smrg      fi
1031b3a827e2Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032b3a827e2Smrg          -e "$_G_pathcar"`
1033b3a827e2Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034b3a827e2Smrg          -e "$_G_pathcdr"`
1035b3a827e2Smrg      # Figure out what to do with it
1036b3a827e2Smrg      case $func_normal_abspath_tcomponent in
1037b3a827e2Smrg        "")
1038b3a827e2Smrg          # Trailing empty path component, ignore it.
1039b3a827e2Smrg          ;;
1040b3a827e2Smrg        ..)
1041b3a827e2Smrg          # Parent dir; strip last assembled component from result.
1042b3a827e2Smrg          func_dirname "$func_normal_abspath_result"
1043b3a827e2Smrg          func_normal_abspath_result=$func_dirname_result
1044b3a827e2Smrg          ;;
1045b3a827e2Smrg        *)
1046b3a827e2Smrg          # Actual path component, append it.
1047b3a827e2Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048b3a827e2Smrg          ;;
1049b3a827e2Smrg      esac
1050b3a827e2Smrg    done
1051b3a827e2Smrg    # Restore leading double-slash if one was found on entry.
1052b3a827e2Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053b3a827e2Smrg}
1054b3a827e2Smrg
1055b3a827e2Smrg
1056b3a827e2Smrg# func_notquiet ARG...
1057b3a827e2Smrg# --------------------
1058b3a827e2Smrg# Echo program name prefixed message only when not in quiet mode.
1059b3a827e2Smrgfunc_notquiet ()
1060b3a827e2Smrg{
1061b3a827e2Smrg    $debug_cmd
1062b3a827e2Smrg
1063b3a827e2Smrg    $opt_quiet || func_echo ${1+"$@"}
1064b3a827e2Smrg
1065b3a827e2Smrg    # A bug in bash halts the script if the last line of a function
1066b3a827e2Smrg    # fails when set -e is in force, so we need another command to
1067b3a827e2Smrg    # work around that:
1068b3a827e2Smrg    :
1069b3a827e2Smrg}
1070b3a827e2Smrg
1071b3a827e2Smrg
1072b3a827e2Smrg# func_relative_path SRCDIR DSTDIR
1073b3a827e2Smrg# --------------------------------
1074b3a827e2Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075b3a827e2Smrgfunc_relative_path ()
1076b3a827e2Smrg{
1077b3a827e2Smrg    $debug_cmd
1078b3a827e2Smrg
1079b3a827e2Smrg    func_relative_path_result=
1080b3a827e2Smrg    func_normal_abspath "$1"
1081b3a827e2Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082b3a827e2Smrg    func_normal_abspath "$2"
1083b3a827e2Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084b3a827e2Smrg
1085b3a827e2Smrg    # Ascend the tree starting from libdir
1086b3a827e2Smrg    while :; do
1087b3a827e2Smrg      # check if we have found a prefix of bindir
1088b3a827e2Smrg      case $func_relative_path_tbindir in
1089b3a827e2Smrg        $func_relative_path_tlibdir)
1090b3a827e2Smrg          # found an exact match
1091b3a827e2Smrg          func_relative_path_tcancelled=
1092b3a827e2Smrg          break
1093b3a827e2Smrg          ;;
1094b3a827e2Smrg        $func_relative_path_tlibdir*)
1095b3a827e2Smrg          # found a matching prefix
1096b3a827e2Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097b3a827e2Smrg          func_relative_path_tcancelled=$func_stripname_result
1098b3a827e2Smrg          if test -z "$func_relative_path_result"; then
1099b3a827e2Smrg            func_relative_path_result=.
1100b3a827e2Smrg          fi
1101b3a827e2Smrg          break
1102b3a827e2Smrg          ;;
1103b3a827e2Smrg        *)
1104b3a827e2Smrg          func_dirname $func_relative_path_tlibdir
1105b3a827e2Smrg          func_relative_path_tlibdir=$func_dirname_result
1106b3a827e2Smrg          if test -z "$func_relative_path_tlibdir"; then
1107b3a827e2Smrg            # Have to descend all the way to the root!
1108b3a827e2Smrg            func_relative_path_result=../$func_relative_path_result
1109b3a827e2Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110b3a827e2Smrg            break
1111b3a827e2Smrg          fi
1112b3a827e2Smrg          func_relative_path_result=../$func_relative_path_result
1113b3a827e2Smrg          ;;
1114b3a827e2Smrg      esac
1115b3a827e2Smrg    done
1116b3a827e2Smrg
1117b3a827e2Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118b3a827e2Smrg    func_stripname '' '/' "$func_relative_path_result"
1119b3a827e2Smrg    func_relative_path_result=$func_stripname_result
1120b3a827e2Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121b3a827e2Smrg    if test -n "$func_stripname_result"; then
1122b3a827e2Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123b3a827e2Smrg    fi
1124b3a827e2Smrg
1125b3a827e2Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126b3a827e2Smrg    if test -n "$func_relative_path_result"; then
1127b3a827e2Smrg      func_stripname './' '' "$func_relative_path_result"
1128b3a827e2Smrg      func_relative_path_result=$func_stripname_result
1129e0963edeSmrg    fi
1130e0963edeSmrg
1131b3a827e2Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132b3a827e2Smrg
1133b3a827e2Smrg    :
1134b3a827e2Smrg}
1135b3a827e2Smrg
1136b3a827e2Smrg
1137c30f5000Smrg# func_quote_portable EVAL ARG
1138c30f5000Smrg# ----------------------------
1139c30f5000Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140c30f5000Smrg# keep attention to performance here so we as much as possible try to avoid
1141c30f5000Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142c30f5000Smrgfunc_quote_portable ()
1143b3a827e2Smrg{
1144b3a827e2Smrg    $debug_cmd
1145b3a827e2Smrg
1146c30f5000Smrg    $require_check_ifs_backslash
1147c30f5000Smrg
1148c30f5000Smrg    func_quote_portable_result=$2
1149c30f5000Smrg
1150c30f5000Smrg    # one-time-loop (easy break)
1151c30f5000Smrg    while true
1152c30f5000Smrg    do
1153c30f5000Smrg      if $1; then
1154c30f5000Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155c30f5000Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156c30f5000Smrg        break
1157b3a827e2Smrg      fi
1158b3a827e2Smrg
1159c30f5000Smrg      # Quote for eval.
1160c30f5000Smrg      case $func_quote_portable_result in
1161c30f5000Smrg        *[\\\`\"\$]*)
1162c30f5000Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163c30f5000Smrg          # contains the shell wildcard characters.
1164c30f5000Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165c30f5000Smrg            :*|*[\[\*\?]*)
1166c30f5000Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167c30f5000Smrg                  | $SED "$sed_quote_subst"`
1168c30f5000Smrg              break
1169c30f5000Smrg              ;;
1170c30f5000Smrg          esac
1171c30f5000Smrg
1172c30f5000Smrg          func_quote_portable_old_IFS=$IFS
1173c30f5000Smrg          for _G_char in '\' '`' '"' '$'
1174c30f5000Smrg          do
1175c30f5000Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176c30f5000Smrg            set start "" ""
1177c30f5000Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178c30f5000Smrg            IFS=$_G_char
1179c30f5000Smrg            for _G_part in $func_quote_portable_result
1180c30f5000Smrg            do
1181c30f5000Smrg              case $1 in
1182c30f5000Smrg              quote)
1183c30f5000Smrg                func_append func_quote_portable_result "$3$2"
1184c30f5000Smrg                set quote "$_G_part" "\\$_G_char"
1185c30f5000Smrg                ;;
1186c30f5000Smrg              start)
1187c30f5000Smrg                set first "" ""
1188c30f5000Smrg                func_quote_portable_result=
1189c30f5000Smrg                ;;
1190c30f5000Smrg              first)
1191c30f5000Smrg                set quote "$_G_part" ""
1192c30f5000Smrg                ;;
1193c30f5000Smrg              esac
1194c30f5000Smrg            done
1195c30f5000Smrg          done
1196c30f5000Smrg          IFS=$func_quote_portable_old_IFS
1197b3a827e2Smrg          ;;
1198c30f5000Smrg        *) ;;
1199b3a827e2Smrg      esac
1200c30f5000Smrg      break
1201b3a827e2Smrg    done
1202c30f5000Smrg
1203c30f5000Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204c30f5000Smrg    case $func_quote_portable_result in
1205c30f5000Smrg      # double-quote args containing shell metacharacters to delay
1206c30f5000Smrg      # word splitting, command substitution and variable expansion
1207c30f5000Smrg      # for a subsequent eval.
1208c30f5000Smrg      # many bourne shells cannot handle close brackets correctly
1209c30f5000Smrg      # in scan sets, so we specify it separately.
1210c30f5000Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211c30f5000Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212c30f5000Smrg        ;;
1213c30f5000Smrg    esac
1214b3a827e2Smrg}
1215b3a827e2Smrg
1216b3a827e2Smrg
1217c30f5000Smrg# func_quotefast_eval ARG
1218c30f5000Smrg# -----------------------
1219c30f5000Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220c30f5000Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221c30f5000Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222c30f5000Smrg  printf -v _GL_test_printf_tilde %q '~'
1223c30f5000Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224c30f5000Smrg    func_quotefast_eval ()
1225c30f5000Smrg    {
1226c30f5000Smrg      printf -v func_quotefast_eval_result %q "$1"
1227c30f5000Smrg    }
1228c30f5000Smrg  else
1229c30f5000Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230c30f5000Smrg    func_quotefast_eval ()
1231c30f5000Smrg    {
1232c30f5000Smrg      case $1 in
1233c30f5000Smrg        '~'*)
1234c30f5000Smrg          func_quote_portable false "$1"
1235c30f5000Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236c30f5000Smrg          ;;
1237c30f5000Smrg        *)
1238c30f5000Smrg          printf -v func_quotefast_eval_result %q "$1"
1239c30f5000Smrg          ;;
1240c30f5000Smrg      esac
1241c30f5000Smrg    }
1242c30f5000Smrg  fi
1243c30f5000Smrgelse
1244c30f5000Smrg  func_quotefast_eval ()
1245c30f5000Smrg  {
1246c30f5000Smrg    func_quote_portable false "$1"
1247c30f5000Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248c30f5000Smrg  }
1249c30f5000Smrgfi
1250b3a827e2Smrg
1251c30f5000Smrg
1252c30f5000Smrg# func_quote_arg MODEs ARG
1253c30f5000Smrg# ------------------------
1254c30f5000Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255c30f5000Smrg# specifiers listed below separated by ',' character.  This function returns two
1256c30f5000Smrg# values:
1257c30f5000Smrg#   i) func_quote_arg_result
1258c30f5000Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259c30f5000Smrg#  ii) func_quote_arg_unquoted_result
1260c30f5000Smrg#      has all characters that are still active within double
1261c30f5000Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262c30f5000Smrg#
1263c30f5000Smrg# Available modes:
1264c30f5000Smrg# ----------------
1265c30f5000Smrg# 'eval' (default)
1266c30f5000Smrg#       - escape shell special characters
1267c30f5000Smrg# 'expand'
1268c30f5000Smrg#       - the same as 'eval';  but do not quote variable references
1269c30f5000Smrg# 'pretty'
1270c30f5000Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271c30f5000Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272c30f5000Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273c30f5000Smrg# 'unquoted'
1274c30f5000Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275c30f5000Smrg#         wrapping double-quotes.
1276c30f5000Smrg#
1277c30f5000Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278c30f5000Smrg#
1279c30f5000Smrg#   string      | *_result              | *_unquoted_result
1280c30f5000Smrg#   ------------+-----------------------+-------------------
1281c30f5000Smrg#   "           | \"                    | \"
1282c30f5000Smrg#   a b         | "a b"                 | a b
1283c30f5000Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284c30f5000Smrg#   *           | "*"                   | *
1285c30f5000Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286c30f5000Smrg#
1287c30f5000Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288c30f5000Smrg#
1289c30f5000Smrg#   string        |   *_result          |  *_unquoted_result
1290c30f5000Smrg#   --------------+---------------------+--------------------
1291c30f5000Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292c30f5000Smrgfunc_quote_arg ()
1293c30f5000Smrg{
1294c30f5000Smrg    _G_quote_expand=false
1295c30f5000Smrg    case ,$1, in
1296c30f5000Smrg      *,expand,*)
1297c30f5000Smrg        _G_quote_expand=:
1298c30f5000Smrg        ;;
1299b3a827e2Smrg    esac
1300b3a827e2Smrg
1301c30f5000Smrg    case ,$1, in
1302c30f5000Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303c30f5000Smrg        func_quote_portable $_G_quote_expand "$2"
1304c30f5000Smrg        func_quote_arg_result=$func_quote_portable_result
1305c30f5000Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306c30f5000Smrg        ;;
1307c30f5000Smrg      *)
1308c30f5000Smrg        # Faster quote-for-eval for some shells.
1309c30f5000Smrg        func_quotefast_eval "$2"
1310c30f5000Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311b3a827e2Smrg        ;;
1312b3a827e2Smrg    esac
1313c30f5000Smrg}
1314c30f5000Smrg
1315b3a827e2Smrg
1316c30f5000Smrg# func_quote MODEs ARGs...
1317c30f5000Smrg# ------------------------
1318c30f5000Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319c30f5000Smrg# func_quote_arg's description for more info.
1320c30f5000Smrgfunc_quote ()
1321c30f5000Smrg{
1322c30f5000Smrg    $debug_cmd
1323c30f5000Smrg    _G_func_quote_mode=$1 ; shift
1324c30f5000Smrg    func_quote_result=
1325c30f5000Smrg    while test 0 -lt $#; do
1326c30f5000Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327c30f5000Smrg      if test -n "$func_quote_result"; then
1328c30f5000Smrg        func_append func_quote_result " $func_quote_arg_result"
1329c30f5000Smrg      else
1330c30f5000Smrg        func_append func_quote_result "$func_quote_arg_result"
1331c30f5000Smrg      fi
1332c30f5000Smrg      shift
1333c30f5000Smrg    done
1334b3a827e2Smrg}
1335b3a827e2Smrg
1336b3a827e2Smrg
1337b3a827e2Smrg# func_stripname PREFIX SUFFIX NAME
1338b3a827e2Smrg# ---------------------------------
1339b3a827e2Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340b3a827e2Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341b3a827e2Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342b3a827e2Smrg# dot (in which case that matches only a dot).
1343b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344b3a827e2Smrg  eval 'func_stripname ()
1345b3a827e2Smrg  {
1346b3a827e2Smrg    $debug_cmd
1347b3a827e2Smrg
1348b3a827e2Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349b3a827e2Smrg    # positional parameters, so assign one to ordinary variable first.
1350b3a827e2Smrg    func_stripname_result=$3
1351b3a827e2Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352b3a827e2Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353b3a827e2Smrg  }'
1354b3a827e2Smrgelse
1355b3a827e2Smrg  func_stripname ()
1356b3a827e2Smrg  {
1357b3a827e2Smrg    $debug_cmd
1358b3a827e2Smrg
1359b3a827e2Smrg    case $2 in
1360b3a827e2Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361b3a827e2Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362b3a827e2Smrg    esac
1363b3a827e2Smrg  }
1364b3a827e2Smrgfi
1365b3a827e2Smrg
1366b3a827e2Smrg
1367b3a827e2Smrg# func_show_eval CMD [FAIL_EXP]
1368b3a827e2Smrg# -----------------------------
1369b3a827e2Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370b3a827e2Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371b3a827e2Smrg# is given, then evaluate it.
1372b3a827e2Smrgfunc_show_eval ()
1373b3a827e2Smrg{
1374b3a827e2Smrg    $debug_cmd
1375b3a827e2Smrg
1376b3a827e2Smrg    _G_cmd=$1
1377b3a827e2Smrg    _G_fail_exp=${2-':'}
1378b3a827e2Smrg
1379c30f5000Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380c30f5000Smrg    eval "func_notquiet $func_quote_arg_result"
1381b3a827e2Smrg
1382b3a827e2Smrg    $opt_dry_run || {
1383b3a827e2Smrg      eval "$_G_cmd"
1384b3a827e2Smrg      _G_status=$?
1385b3a827e2Smrg      if test 0 -ne "$_G_status"; then
1386b3a827e2Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387b3a827e2Smrg      fi
1388b3a827e2Smrg    }
1389b3a827e2Smrg}
1390b3a827e2Smrg
1391b3a827e2Smrg
1392b3a827e2Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393b3a827e2Smrg# ------------------------------------
1394b3a827e2Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395b3a827e2Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396b3a827e2Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397b3a827e2Smrgfunc_show_eval_locale ()
1398b3a827e2Smrg{
1399b3a827e2Smrg    $debug_cmd
1400b3a827e2Smrg
1401b3a827e2Smrg    _G_cmd=$1
1402b3a827e2Smrg    _G_fail_exp=${2-':'}
1403b3a827e2Smrg
1404b3a827e2Smrg    $opt_quiet || {
1405c30f5000Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406c30f5000Smrg      eval "func_echo $func_quote_arg_result"
1407b3a827e2Smrg    }
1408b3a827e2Smrg
1409b3a827e2Smrg    $opt_dry_run || {
1410b3a827e2Smrg      eval "$_G_user_locale
1411b3a827e2Smrg	    $_G_cmd"
1412b3a827e2Smrg      _G_status=$?
1413b3a827e2Smrg      eval "$_G_safe_locale"
1414b3a827e2Smrg      if test 0 -ne "$_G_status"; then
1415b3a827e2Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416b3a827e2Smrg      fi
1417b3a827e2Smrg    }
1418b3a827e2Smrg}
1419b3a827e2Smrg
1420b3a827e2Smrg
1421b3a827e2Smrg# func_tr_sh
1422b3a827e2Smrg# ----------
1423b3a827e2Smrg# Turn $1 into a string suitable for a shell variable name.
1424b3a827e2Smrg# Result is stored in $func_tr_sh_result.  All characters
1425b3a827e2Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426b3a827e2Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427b3a827e2Smrgfunc_tr_sh ()
1428b3a827e2Smrg{
1429b3a827e2Smrg    $debug_cmd
1430b3a827e2Smrg
1431b3a827e2Smrg    case $1 in
1432b3a827e2Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433b3a827e2Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434b3a827e2Smrg      ;;
1435b3a827e2Smrg    * )
1436b3a827e2Smrg      func_tr_sh_result=$1
1437b3a827e2Smrg      ;;
1438b3a827e2Smrg    esac
1439b3a827e2Smrg}
1440b3a827e2Smrg
1441b3a827e2Smrg
1442b3a827e2Smrg# func_verbose ARG...
1443b3a827e2Smrg# -------------------
1444b3a827e2Smrg# Echo program name prefixed message in verbose mode only.
1445b3a827e2Smrgfunc_verbose ()
1446b3a827e2Smrg{
1447b3a827e2Smrg    $debug_cmd
1448b3a827e2Smrg
1449b3a827e2Smrg    $opt_verbose && func_echo "$*"
1450b3a827e2Smrg
1451b3a827e2Smrg    :
1452b3a827e2Smrg}
1453b3a827e2Smrg
1454b3a827e2Smrg
1455b3a827e2Smrg# func_warn_and_continue ARG...
1456b3a827e2Smrg# -----------------------------
1457b3a827e2Smrg# Echo program name prefixed warning message to standard error.
1458b3a827e2Smrgfunc_warn_and_continue ()
1459b3a827e2Smrg{
1460b3a827e2Smrg    $debug_cmd
1461b3a827e2Smrg
1462b3a827e2Smrg    $require_term_colors
1463b3a827e2Smrg
1464b3a827e2Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465b3a827e2Smrg}
1466b3a827e2Smrg
1467b3a827e2Smrg
1468b3a827e2Smrg# func_warning CATEGORY ARG...
1469b3a827e2Smrg# ----------------------------
1470b3a827e2Smrg# Echo program name prefixed warning message to standard error. Warning
1471b3a827e2Smrg# messages can be filtered according to CATEGORY, where this function
1472b3a827e2Smrg# elides messages where CATEGORY is not listed in the global variable
1473b3a827e2Smrg# 'opt_warning_types'.
1474b3a827e2Smrgfunc_warning ()
1475b3a827e2Smrg{
1476b3a827e2Smrg    $debug_cmd
1477b3a827e2Smrg
1478b3a827e2Smrg    # CATEGORY must be in the warning_categories list!
1479b3a827e2Smrg    case " $warning_categories " in
1480b3a827e2Smrg      *" $1 "*) ;;
1481b3a827e2Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482b3a827e2Smrg    esac
1483b3a827e2Smrg
1484b3a827e2Smrg    _G_category=$1
1485b3a827e2Smrg    shift
1486b3a827e2Smrg
1487b3a827e2Smrg    case " $opt_warning_types " in
1488b3a827e2Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489b3a827e2Smrg    esac
1490b3a827e2Smrg}
1491b3a827e2Smrg
1492b3a827e2Smrg
1493b3a827e2Smrg# func_sort_ver VER1 VER2
1494b3a827e2Smrg# -----------------------
1495b3a827e2Smrg# 'sort -V' is not generally available.
1496b3a827e2Smrg# Note this deviates from the version comparison in automake
1497b3a827e2Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498b3a827e2Smrg# but this should suffice as we won't be specifying old
1499b3a827e2Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500b3a827e2Smrg# If we did want full compatibility then we should probably
1501b3a827e2Smrg# use m4_version_compare from autoconf.
1502b3a827e2Smrgfunc_sort_ver ()
1503b3a827e2Smrg{
1504b3a827e2Smrg    $debug_cmd
1505b3a827e2Smrg
1506b3a827e2Smrg    printf '%s\n%s\n' "$1" "$2" \
1507b3a827e2Smrg      | 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
1508b3a827e2Smrg}
1509b3a827e2Smrg
1510b3a827e2Smrg# func_lt_ver PREV CURR
1511b3a827e2Smrg# ---------------------
1512b3a827e2Smrg# Return true if PREV and CURR are in the correct order according to
1513b3a827e2Smrg# func_sort_ver, otherwise false.  Use it like this:
1514b3a827e2Smrg#
1515b3a827e2Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516b3a827e2Smrgfunc_lt_ver ()
1517b3a827e2Smrg{
1518b3a827e2Smrg    $debug_cmd
1519b3a827e2Smrg
1520b3a827e2Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521b3a827e2Smrg}
1522b3a827e2Smrg
1523b3a827e2Smrg
1524b3a827e2Smrg# Local variables:
1525b3a827e2Smrg# mode: shell-script
1526b3a827e2Smrg# sh-indentation: 2
1527b3a827e2Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528b3a827e2Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529b3a827e2Smrg# time-stamp-time-zone: "UTC"
1530b3a827e2Smrg# End:
1531b3a827e2Smrg#! /bin/sh
1532b3a827e2Smrg
1533b3a827e2Smrg# A portable, pluggable option parser for Bourne shell.
1534b3a827e2Smrg# Written by Gary V. Vaughan, 2010
1535b3a827e2Smrg
1536c30f5000Smrg# This is free software.  There is NO warranty; not even for
1537c30f5000Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538c30f5000Smrg#
1539c30f5000Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540c30f5000Smrg#
1541c30f5000Smrg# This file is dual licensed under the terms of the MIT license
1542c30f5000Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543c30f5000Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544c30f5000Smrg# these licenses when using or redistributing this software or any of
1545c30f5000Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546c30f5000Smrg# included in the Bootstrap distribution for the full license texts.
1547b3a827e2Smrg
1548c30f5000Smrg# Please report bugs or propose patches to:
1549c30f5000Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550b3a827e2Smrg
1551c30f5000Smrg# Set a version string for this script.
1552c30f5000Smrgscriptversion=2019-02-19.15; # UTC
1553b3a827e2Smrg
1554b3a827e2Smrg
1555b3a827e2Smrg## ------ ##
1556b3a827e2Smrg## Usage. ##
1557b3a827e2Smrg## ------ ##
1558b3a827e2Smrg
1559b3a827e2Smrg# This file is a library for parsing options in your shell scripts along
1560b3a827e2Smrg# with assorted other useful supporting features that you can make use
1561b3a827e2Smrg# of too.
1562b3a827e2Smrg#
1563b3a827e2Smrg# For the simplest scripts you might need only:
1564b3a827e2Smrg#
1565b3a827e2Smrg#   #!/bin/sh
1566b3a827e2Smrg#   . relative/path/to/funclib.sh
1567b3a827e2Smrg#   . relative/path/to/options-parser
1568b3a827e2Smrg#   scriptversion=1.0
1569b3a827e2Smrg#   func_options ${1+"$@"}
1570b3a827e2Smrg#   eval set dummy "$func_options_result"; shift
1571b3a827e2Smrg#   ...rest of your script...
1572b3a827e2Smrg#
1573b3a827e2Smrg# In order for the '--version' option to work, you will need to have a
1574b3a827e2Smrg# suitably formatted comment like the one at the top of this file
1575c30f5000Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576b3a827e2Smrg#
1577b3a827e2Smrg# For '-h' and '--help' to work, you will also need a one line
1578b3a827e2Smrg# description of your script's purpose in a comment directly above the
1579b3a827e2Smrg# '# Written by ' line, like the one at the top of this file.
1580b3a827e2Smrg#
1581b3a827e2Smrg# The default options also support '--debug', which will turn on shell
1582b3a827e2Smrg# execution tracing (see the comment above debug_cmd below for another
1583b3a827e2Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584b3a827e2Smrg# to display verbose messages only when your user has specified
1585b3a827e2Smrg# '--verbose'.
1586b3a827e2Smrg#
1587c30f5000Smrg# After sourcing this file, you can plug in processing for additional
1588b3a827e2Smrg# options by amending the variables from the 'Configuration' section
1589b3a827e2Smrg# below, and following the instructions in the 'Option parsing'
1590b3a827e2Smrg# section further down.
1591b3a827e2Smrg
1592b3a827e2Smrg## -------------- ##
1593b3a827e2Smrg## Configuration. ##
1594b3a827e2Smrg## -------------- ##
1595b3a827e2Smrg
1596b3a827e2Smrg# You should override these variables in your script after sourcing this
1597b3a827e2Smrg# file so that they reflect the customisations you have added to the
1598b3a827e2Smrg# option parser.
1599b3a827e2Smrg
1600b3a827e2Smrg# The usage line for option parsing errors and the start of '-h' and
1601b3a827e2Smrg# '--help' output messages. You can embed shell variables for delayed
1602b3a827e2Smrg# expansion at the time the message is displayed, but you will need to
1603b3a827e2Smrg# quote other shell meta-characters carefully to prevent them being
1604b3a827e2Smrg# expanded when the contents are evaled.
1605b3a827e2Smrgusage='$progpath [OPTION]...'
1606b3a827e2Smrg
1607b3a827e2Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608b3a827e2Smrg# override it after sourcing this library to reflect the full set of
1609b3a827e2Smrg# options your script accepts.
1610b3a827e2Smrgusage_message="\
1611b3a827e2Smrg       --debug        enable verbose shell tracing
1612b3a827e2Smrg   -W, --warnings=CATEGORY
1613b3a827e2Smrg                      report the warnings falling in CATEGORY [all]
1614b3a827e2Smrg   -v, --verbose      verbosely report processing
1615b3a827e2Smrg       --version      print version information and exit
1616b3a827e2Smrg   -h, --help         print short or long help message and exit
1617b3a827e2Smrg"
1618b3a827e2Smrg
1619b3a827e2Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620b3a827e2Smrglong_help_message="
1621b3a827e2SmrgWarning categories include:
1622b3a827e2Smrg       'all'          show all warnings
1623b3a827e2Smrg       'none'         turn off all the warnings
1624b3a827e2Smrg       'error'        warnings are treated as fatal errors"
1625b3a827e2Smrg
1626b3a827e2Smrg# Help message printed before fatal option parsing errors.
1627b3a827e2Smrgfatal_help="Try '\$progname --help' for more information."
1628b3a827e2Smrg
1629b3a827e2Smrg
1630b3a827e2Smrg
1631b3a827e2Smrg## ------------------------- ##
1632b3a827e2Smrg## Hook function management. ##
1633b3a827e2Smrg## ------------------------- ##
1634b3a827e2Smrg
1635b3a827e2Smrg# This section contains functions for adding, removing, and running hooks
1636c30f5000Smrg# in the main code.  A hook is just a list of function names that can be
1637c30f5000Smrg# run in order later on.
1638b3a827e2Smrg
1639b3a827e2Smrg# func_hookable FUNC_NAME
1640b3a827e2Smrg# -----------------------
1641b3a827e2Smrg# Declare that FUNC_NAME will run hooks added with
1642b3a827e2Smrg# 'func_add_hook FUNC_NAME ...'.
1643b3a827e2Smrgfunc_hookable ()
1644b3a827e2Smrg{
1645b3a827e2Smrg    $debug_cmd
1646b3a827e2Smrg
1647b3a827e2Smrg    func_append hookable_fns " $1"
1648b3a827e2Smrg}
1649b3a827e2Smrg
1650b3a827e2Smrg
1651b3a827e2Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652b3a827e2Smrg# ---------------------------------
1653b3a827e2Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654b3a827e2Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655b3a827e2Smrgfunc_add_hook ()
1656b3a827e2Smrg{
1657b3a827e2Smrg    $debug_cmd
1658b3a827e2Smrg
1659b3a827e2Smrg    case " $hookable_fns " in
1660b3a827e2Smrg      *" $1 "*) ;;
1661b3a827e2Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662b3a827e2Smrg    esac
1663b3a827e2Smrg
1664b3a827e2Smrg    eval func_append ${1}_hooks '" $2"'
1665b3a827e2Smrg}
1666b3a827e2Smrg
1667b3a827e2Smrg
1668b3a827e2Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669b3a827e2Smrg# ------------------------------------
1670c30f5000Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671c30f5000Smrg# FUNC_NAME.
1672b3a827e2Smrgfunc_remove_hook ()
1673b3a827e2Smrg{
1674b3a827e2Smrg    $debug_cmd
1675b3a827e2Smrg
1676b3a827e2Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677b3a827e2Smrg}
1678b3a827e2Smrg
1679b3a827e2Smrg
1680c30f5000Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681c30f5000Smrg# ---------------------------------------------
1682c30f5000Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683c30f5000Smrg# *_result variable of FUNC_NAME_B.
1684c30f5000Smrgfunc_propagate_result ()
1685c30f5000Smrg{
1686c30f5000Smrg    $debug_cmd
1687c30f5000Smrg
1688c30f5000Smrg    func_propagate_result_result=:
1689c30f5000Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690c30f5000Smrg    then
1691c30f5000Smrg      eval "${2}_result=\$${1}_result"
1692c30f5000Smrg    else
1693c30f5000Smrg      func_propagate_result_result=false
1694c30f5000Smrg    fi
1695c30f5000Smrg}
1696c30f5000Smrg
1697c30f5000Smrg
1698b3a827e2Smrg# func_run_hooks FUNC_NAME [ARG]...
1699b3a827e2Smrg# ---------------------------------
1700b3a827e2Smrg# Run all hook functions registered to FUNC_NAME.
1701c30f5000Smrg# It's assumed that the list of hook functions contains nothing more
1702b3a827e2Smrg# than a whitespace-delimited list of legal shell function names, and
1703b3a827e2Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704b3a827e2Smrg# whitespace.
1705b3a827e2Smrgfunc_run_hooks ()
1706b3a827e2Smrg{
1707b3a827e2Smrg    $debug_cmd
1708b3a827e2Smrg
1709b3a827e2Smrg    case " $hookable_fns " in
1710b3a827e2Smrg      *" $1 "*) ;;
1711c30f5000Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712b3a827e2Smrg    esac
1713b3a827e2Smrg
1714b3a827e2Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715b3a827e2Smrg
1716b3a827e2Smrg    for _G_hook in $_G_hook_fns; do
1717c30f5000Smrg      func_unset "${_G_hook}_result"
1718c30f5000Smrg      eval $_G_hook '${1+"$@"}'
1719c30f5000Smrg      func_propagate_result $_G_hook func_run_hooks
1720c30f5000Smrg      if $func_propagate_result_result; then
1721c30f5000Smrg        eval set dummy "$func_run_hooks_result"; shift
1722c30f5000Smrg      fi
1723b3a827e2Smrg    done
1724b3a827e2Smrg}
1725b3a827e2Smrg
1726b3a827e2Smrg
1727b3a827e2Smrg
1728b3a827e2Smrg## --------------- ##
1729b3a827e2Smrg## Option parsing. ##
1730b3a827e2Smrg## --------------- ##
1731b3a827e2Smrg
1732b3a827e2Smrg# In order to add your own option parsing hooks, you must accept the
1733c30f5000Smrg# full positional parameter list from your hook function.  You may remove
1734c30f5000Smrg# or edit any options that you action, and then pass back the remaining
1735c30f5000Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736c30f5000Smrg# suitably for 'eval'.
1737c30f5000Smrg#
1738c30f5000Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739c30f5000Smrg# before your hook gets called; for best performance, only set the
1740c30f5000Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741c30f5000Smrg# function unnecessarily because it can be an expensive operation on some
1742c30f5000Smrg# machines).
1743c30f5000Smrg#
1744c30f5000Smrg# Like this:
1745b3a827e2Smrg#
1746b3a827e2Smrg#    my_options_prep ()
1747b3a827e2Smrg#    {
1748b3a827e2Smrg#        $debug_cmd
1749b3a827e2Smrg#
1750b3a827e2Smrg#        # Extend the existing usage message.
1751b3a827e2Smrg#        usage_message=$usage_message'
1752b3a827e2Smrg#      -s, --silent       don'\''t print informational messages
1753b3a827e2Smrg#    '
1754c30f5000Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755c30f5000Smrg#        # my_options_prep_result variable intact.
1756b3a827e2Smrg#    }
1757b3a827e2Smrg#    func_add_hook func_options_prep my_options_prep
1758b3a827e2Smrg#
1759b3a827e2Smrg#
1760b3a827e2Smrg#    my_silent_option ()
1761b3a827e2Smrg#    {
1762b3a827e2Smrg#        $debug_cmd
1763b3a827e2Smrg#
1764c30f5000Smrg#        args_changed=false
1765c30f5000Smrg#
1766c30f5000Smrg#        # Note that, for efficiency, we parse as many options as we can
1767b3a827e2Smrg#        # recognise in a loop before passing the remainder back to the
1768b3a827e2Smrg#        # caller on the first unrecognised argument we encounter.
1769b3a827e2Smrg#        while test $# -gt 0; do
1770b3a827e2Smrg#          opt=$1; shift
1771b3a827e2Smrg#          case $opt in
1772c30f5000Smrg#            --silent|-s) opt_silent=:
1773c30f5000Smrg#                         args_changed=:
1774c30f5000Smrg#                         ;;
1775b3a827e2Smrg#            # Separate non-argument short options:
1776b3a827e2Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777b3a827e2Smrg#                         set dummy "$func_split_short_opt_name" \
1778b3a827e2Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779b3a827e2Smrg#                         shift
1780c30f5000Smrg#                         args_changed=:
1781b3a827e2Smrg#                         ;;
1782c30f5000Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783c30f5000Smrg#                         # is added back to "$@" in case we need it later,
1784c30f5000Smrg#                         # if $args_changed was set to 'true'.
1785c30f5000Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786b3a827e2Smrg#          esac
1787b3a827e2Smrg#        done
1788b3a827e2Smrg#
1789c30f5000Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790c30f5000Smrg#        if $args_changed; then
1791c30f5000Smrg#          func_quote eval ${1+"$@"}
1792c30f5000Smrg#          my_silent_option_result=$func_quote_result
1793c30f5000Smrg#        fi
1794b3a827e2Smrg#    }
1795b3a827e2Smrg#    func_add_hook func_parse_options my_silent_option
1796b3a827e2Smrg#
1797b3a827e2Smrg#
1798b3a827e2Smrg#    my_option_validation ()
1799b3a827e2Smrg#    {
1800b3a827e2Smrg#        $debug_cmd
1801b3a827e2Smrg#
1802b3a827e2Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803b3a827e2Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804b3a827e2Smrg#    }
1805b3a827e2Smrg#    func_add_hook func_validate_options my_option_validation
1806b3a827e2Smrg#
1807c30f5000Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808b3a827e2Smrg# options you parse.  It's preferable to append if you can, so that
1809b3a827e2Smrg# multiple option parsing hooks can be added safely.
1810b3a827e2Smrg
1811b3a827e2Smrg
1812c30f5000Smrg# func_options_finish [ARG]...
1813c30f5000Smrg# ----------------------------
1814c30f5000Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815c30f5000Smrgfunc_options_finish ()
1816c30f5000Smrg{
1817c30f5000Smrg    $debug_cmd
1818c30f5000Smrg
1819c30f5000Smrg    func_run_hooks func_options ${1+"$@"}
1820c30f5000Smrg    func_propagate_result func_run_hooks func_options_finish
1821c30f5000Smrg}
1822c30f5000Smrg
1823c30f5000Smrg
1824b3a827e2Smrg# func_options [ARG]...
1825b3a827e2Smrg# ---------------------
1826b3a827e2Smrg# All the functions called inside func_options are hookable. See the
1827b3a827e2Smrg# individual implementations for details.
1828b3a827e2Smrgfunc_hookable func_options
1829b3a827e2Smrgfunc_options ()
1830b3a827e2Smrg{
1831b3a827e2Smrg    $debug_cmd
1832b3a827e2Smrg
1833c30f5000Smrg    _G_options_quoted=false
1834b3a827e2Smrg
1835c30f5000Smrg    for my_func in options_prep parse_options validate_options options_finish
1836c30f5000Smrg    do
1837c30f5000Smrg      func_unset func_${my_func}_result
1838c30f5000Smrg      func_unset func_run_hooks_result
1839c30f5000Smrg      eval func_$my_func '${1+"$@"}'
1840c30f5000Smrg      func_propagate_result func_$my_func func_options
1841c30f5000Smrg      if $func_propagate_result_result; then
1842c30f5000Smrg        eval set dummy "$func_options_result"; shift
1843c30f5000Smrg        _G_options_quoted=:
1844c30f5000Smrg      fi
1845c30f5000Smrg    done
1846b3a827e2Smrg
1847c30f5000Smrg    $_G_options_quoted || {
1848c30f5000Smrg      # As we (func_options) are top-level options-parser function and
1849c30f5000Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850c30f5000Smrg      # caller.
1851c30f5000Smrg      func_quote eval ${1+"$@"}
1852c30f5000Smrg      func_options_result=$func_quote_result
1853c30f5000Smrg    }
1854e0963edeSmrg}
1855e0963edeSmrg
1856e0963edeSmrg
1857b3a827e2Smrg# func_options_prep [ARG]...
1858b3a827e2Smrg# --------------------------
1859b3a827e2Smrg# All initialisations required before starting the option parse loop.
1860b3a827e2Smrg# Note that when calling hook functions, we pass through the list of
1861b3a827e2Smrg# positional parameters.  If a hook function modifies that list, and
1862c30f5000Smrg# needs to propagate that back to rest of this script, then the complete
1863c30f5000Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864b3a827e2Smrgfunc_hookable func_options_prep
1865b3a827e2Smrgfunc_options_prep ()
1866e0963edeSmrg{
1867b3a827e2Smrg    $debug_cmd
1868f05b35a2Smrg
1869b3a827e2Smrg    # Option defaults:
1870b3a827e2Smrg    opt_verbose=false
1871b3a827e2Smrg    opt_warning_types=
1872b3a827e2Smrg
1873b3a827e2Smrg    func_run_hooks func_options_prep ${1+"$@"}
1874c30f5000Smrg    func_propagate_result func_run_hooks func_options_prep
1875e0963edeSmrg}
1876e0963edeSmrg
1877e0963edeSmrg
1878b3a827e2Smrg# func_parse_options [ARG]...
1879b3a827e2Smrg# ---------------------------
1880b3a827e2Smrg# The main option parsing loop.
1881b3a827e2Smrgfunc_hookable func_parse_options
1882b3a827e2Smrgfunc_parse_options ()
1883e0963edeSmrg{
1884b3a827e2Smrg    $debug_cmd
1885f05b35a2Smrg
1886c30f5000Smrg    _G_parse_options_requote=false
1887b3a827e2Smrg    # this just eases exit handling
1888b3a827e2Smrg    while test $# -gt 0; do
1889b3a827e2Smrg      # Defer to hook functions for initial option parsing, so they
1890b3a827e2Smrg      # get priority in the event of reusing an option name.
1891b3a827e2Smrg      func_run_hooks func_parse_options ${1+"$@"}
1892c30f5000Smrg      func_propagate_result func_run_hooks func_parse_options
1893c30f5000Smrg      if $func_propagate_result_result; then
1894c30f5000Smrg        eval set dummy "$func_parse_options_result"; shift
1895c30f5000Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896c30f5000Smrg        # down into the hook and it quoted it for us (because we are in
1897c30f5000Smrg        # this if-branch).  No need to quote it again.
1898c30f5000Smrg        _G_parse_options_requote=false
1899c30f5000Smrg      fi
1900e0963edeSmrg
1901b3a827e2Smrg      # Break out of the loop if we already parsed every option.
1902b3a827e2Smrg      test $# -gt 0 || break
1903e0963edeSmrg
1904c30f5000Smrg      # We expect that one of the options parsed in this function matches
1905c30f5000Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906c30f5000Smrg      _G_match_parse_options=:
1907b3a827e2Smrg      _G_opt=$1
1908b3a827e2Smrg      shift
1909b3a827e2Smrg      case $_G_opt in
1910b3a827e2Smrg        --debug|-x)   debug_cmd='set -x'
1911c30f5000Smrg                      func_echo "enabling shell trace mode" >&2
1912b3a827e2Smrg                      $debug_cmd
1913b3a827e2Smrg                      ;;
1914b3a827e2Smrg
1915b3a827e2Smrg        --no-warnings|--no-warning|--no-warn)
1916b3a827e2Smrg                      set dummy --warnings none ${1+"$@"}
1917b3a827e2Smrg                      shift
1918b3a827e2Smrg		      ;;
1919f05b35a2Smrg
1920b3a827e2Smrg        --warnings|--warning|-W)
1921c30f5000Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922c30f5000Smrg                        _G_parse_options_requote=:
1923c30f5000Smrg                        break
1924c30f5000Smrg                      fi
1925b3a827e2Smrg                      case " $warning_categories $1" in
1926b3a827e2Smrg                        *" $1 "*)
1927b3a827e2Smrg                          # trailing space prevents matching last $1 above
1928b3a827e2Smrg                          func_append_uniq opt_warning_types " $1"
1929b3a827e2Smrg                          ;;
1930b3a827e2Smrg                        *all)
1931b3a827e2Smrg                          opt_warning_types=$warning_categories
1932b3a827e2Smrg                          ;;
1933b3a827e2Smrg                        *none)
1934b3a827e2Smrg                          opt_warning_types=none
1935b3a827e2Smrg                          warning_func=:
1936b3a827e2Smrg                          ;;
1937b3a827e2Smrg                        *error)
1938b3a827e2Smrg                          opt_warning_types=$warning_categories
1939b3a827e2Smrg                          warning_func=func_fatal_error
1940b3a827e2Smrg                          ;;
1941b3a827e2Smrg                        *)
1942b3a827e2Smrg                          func_fatal_error \
1943b3a827e2Smrg                             "unsupported warning category: '$1'"
1944b3a827e2Smrg                          ;;
1945b3a827e2Smrg                      esac
1946b3a827e2Smrg                      shift
1947b3a827e2Smrg                      ;;
1948b3a827e2Smrg
1949b3a827e2Smrg        --verbose|-v) opt_verbose=: ;;
1950b3a827e2Smrg        --version)    func_version ;;
1951b3a827e2Smrg        -\?|-h)       func_usage ;;
1952b3a827e2Smrg        --help)       func_help ;;
1953b3a827e2Smrg
1954b3a827e2Smrg	# Separate optargs to long options (plugins may need this):
1955b3a827e2Smrg	--*=*)        func_split_equals "$_G_opt"
1956b3a827e2Smrg	              set dummy "$func_split_equals_lhs" \
1957b3a827e2Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958b3a827e2Smrg                      shift
1959b3a827e2Smrg                      ;;
1960b3a827e2Smrg
1961b3a827e2Smrg       # Separate optargs to short options:
1962b3a827e2Smrg        -W*)
1963b3a827e2Smrg                      func_split_short_opt "$_G_opt"
1964b3a827e2Smrg                      set dummy "$func_split_short_opt_name" \
1965b3a827e2Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966b3a827e2Smrg                      shift
1967b3a827e2Smrg                      ;;
1968b3a827e2Smrg
1969b3a827e2Smrg        # Separate non-argument short options:
1970b3a827e2Smrg        -\?*|-h*|-v*|-x*)
1971b3a827e2Smrg                      func_split_short_opt "$_G_opt"
1972b3a827e2Smrg                      set dummy "$func_split_short_opt_name" \
1973b3a827e2Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974b3a827e2Smrg                      shift
1975b3a827e2Smrg                      ;;
1976b3a827e2Smrg
1977c30f5000Smrg        --)           _G_parse_options_requote=: ; break ;;
1978b3a827e2Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979c30f5000Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980c30f5000Smrg                      _G_match_parse_options=false
1981c30f5000Smrg                      break
1982c30f5000Smrg                      ;;
1983b3a827e2Smrg      esac
1984c30f5000Smrg
1985c30f5000Smrg      if $_G_match_parse_options; then
1986c30f5000Smrg        _G_parse_options_requote=:
1987c30f5000Smrg      fi
1988b3a827e2Smrg    done
1989b3a827e2Smrg
1990c30f5000Smrg    if $_G_parse_options_requote; then
1991c30f5000Smrg      # save modified positional parameters for caller
1992c30f5000Smrg      func_quote eval ${1+"$@"}
1993c30f5000Smrg      func_parse_options_result=$func_quote_result
1994c30f5000Smrg    fi
1995e0963edeSmrg}
1996e0963edeSmrg
1997f05b35a2Smrg
1998b3a827e2Smrg# func_validate_options [ARG]...
1999b3a827e2Smrg# ------------------------------
2000b3a827e2Smrg# Perform any sanity checks on option settings and/or unconsumed
2001b3a827e2Smrg# arguments.
2002b3a827e2Smrgfunc_hookable func_validate_options
2003b3a827e2Smrgfunc_validate_options ()
2004e0963edeSmrg{
2005b3a827e2Smrg    $debug_cmd
2006f05b35a2Smrg
2007b3a827e2Smrg    # Display all warnings if -W was not given.
2008b3a827e2Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009f05b35a2Smrg
2010b3a827e2Smrg    func_run_hooks func_validate_options ${1+"$@"}
2011c30f5000Smrg    func_propagate_result func_run_hooks func_validate_options
2012e0963edeSmrg
2013b3a827e2Smrg    # Bail if the options were screwed!
2014b3a827e2Smrg    $exit_cmd $EXIT_FAILURE
201567ab2ff2Smrg}
201667ab2ff2Smrg
2017e0963edeSmrg
201867ab2ff2Smrg
2019b3a827e2Smrg## ----------------- ##
2020b3a827e2Smrg## Helper functions. ##
2021b3a827e2Smrg## ----------------- ##
2022f05b35a2Smrg
2023b3a827e2Smrg# This section contains the helper functions used by the rest of the
2024b3a827e2Smrg# hookable option parser framework in ascii-betical order.
2025b3a827e2Smrg
2026b3a827e2Smrg
2027b3a827e2Smrg# func_fatal_help ARG...
2028b3a827e2Smrg# ----------------------
2029b3a827e2Smrg# Echo program name prefixed message to standard error, followed by
2030b3a827e2Smrg# a help hint, and exit.
2031b3a827e2Smrgfunc_fatal_help ()
2032f05b35a2Smrg{
2033b3a827e2Smrg    $debug_cmd
203467ab2ff2Smrg
2035b3a827e2Smrg    eval \$ECHO \""Usage: $usage"\"
2036b3a827e2Smrg    eval \$ECHO \""$fatal_help"\"
2037b3a827e2Smrg    func_error ${1+"$@"}
2038b3a827e2Smrg    exit $EXIT_FAILURE
2039f05b35a2Smrg}
2040f05b35a2Smrg
2041b3a827e2Smrg
2042b3a827e2Smrg# func_help
2043b3a827e2Smrg# ---------
2044b3a827e2Smrg# Echo long help message to standard output and exit.
2045f05b35a2Smrgfunc_help ()
2046f05b35a2Smrg{
2047b3a827e2Smrg    $debug_cmd
2048b3a827e2Smrg
2049b3a827e2Smrg    func_usage_message
2050b3a827e2Smrg    $ECHO "$long_help_message"
2051b3a827e2Smrg    exit 0
2052f05b35a2Smrg}
2053f05b35a2Smrg
2054b3a827e2Smrg
2055b3a827e2Smrg# func_missing_arg ARGNAME
2056b3a827e2Smrg# ------------------------
2057f05b35a2Smrg# Echo program name prefixed message to standard error and set global
2058f05b35a2Smrg# exit_cmd.
2059f05b35a2Smrgfunc_missing_arg ()
2060f05b35a2Smrg{
2061b3a827e2Smrg    $debug_cmd
206267ab2ff2Smrg
2063b3a827e2Smrg    func_error "Missing argument for '$1'."
2064f05b35a2Smrg    exit_cmd=exit
2065e0963edeSmrg}
2066e0963edeSmrg
2067e0963edeSmrg
2068b3a827e2Smrg# func_split_equals STRING
2069b3a827e2Smrg# ------------------------
2070c30f5000Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071c30f5000Smrg# after splitting STRING at the '=' sign.
2072b3a827e2Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073b3a827e2Smrg    && (eval 'x=a/b/c;
2074b3a827e2Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075b3a827e2Smrg    && _G_HAVE_XSI_OPS=yes
2076b3a827e2Smrg
2077b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078b3a827e2Smrgthen
2079b3a827e2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080b3a827e2Smrg  eval 'func_split_equals ()
2081b3a827e2Smrg  {
2082b3a827e2Smrg      $debug_cmd
2083b3a827e2Smrg
2084b3a827e2Smrg      func_split_equals_lhs=${1%%=*}
2085b3a827e2Smrg      func_split_equals_rhs=${1#*=}
2086c30f5000Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087c30f5000Smrg        func_split_equals_rhs=
2088c30f5000Smrg      fi
2089b3a827e2Smrg  }'
2090b3a827e2Smrgelse
2091b3a827e2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092b3a827e2Smrg  func_split_equals ()
2093b3a827e2Smrg  {
2094b3a827e2Smrg      $debug_cmd
2095b3a827e2Smrg
2096b3a827e2Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097b3a827e2Smrg      func_split_equals_rhs=
2098c30f5000Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099b3a827e2Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100b3a827e2Smrg  }
2101b3a827e2Smrgfi #func_split_equals
2102b3a827e2Smrg
2103b3a827e2Smrg
2104b3a827e2Smrg# func_split_short_opt SHORTOPT
2105b3a827e2Smrg# -----------------------------
210667ab2ff2Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
210767ab2ff2Smrg# variables after splitting SHORTOPT after the 2nd character.
2108b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109b3a827e2Smrgthen
2110b3a827e2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111b3a827e2Smrg  eval 'func_split_short_opt ()
2112b3a827e2Smrg  {
2113b3a827e2Smrg      $debug_cmd
2114b3a827e2Smrg
2115b3a827e2Smrg      func_split_short_opt_arg=${1#??}
2116b3a827e2Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117b3a827e2Smrg  }'
2118b3a827e2Smrgelse
2119b3a827e2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120b3a827e2Smrg  func_split_short_opt ()
2121b3a827e2Smrg  {
2122b3a827e2Smrg      $debug_cmd
2123b3a827e2Smrg
2124c30f5000Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125b3a827e2Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126b3a827e2Smrg  }
2127b3a827e2Smrgfi #func_split_short_opt
2128b3a827e2Smrg
2129b3a827e2Smrg
2130b3a827e2Smrg# func_usage
2131b3a827e2Smrg# ----------
2132b3a827e2Smrg# Echo short help message to standard output and exit.
2133b3a827e2Smrgfunc_usage ()
213467ab2ff2Smrg{
2135b3a827e2Smrg    $debug_cmd
213667ab2ff2Smrg
2137b3a827e2Smrg    func_usage_message
2138b3a827e2Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139b3a827e2Smrg    exit 0
2140b3a827e2Smrg}
214167ab2ff2Smrg
214267ab2ff2Smrg
2143b3a827e2Smrg# func_usage_message
2144b3a827e2Smrg# ------------------
2145b3a827e2Smrg# Echo short help message to standard output.
2146b3a827e2Smrgfunc_usage_message ()
214767ab2ff2Smrg{
2148b3a827e2Smrg    $debug_cmd
214967ab2ff2Smrg
2150b3a827e2Smrg    eval \$ECHO \""Usage: $usage"\"
2151b3a827e2Smrg    echo
2152b3a827e2Smrg    $SED -n 's|^# ||
2153b3a827e2Smrg        /^Written by/{
2154b3a827e2Smrg          x;p;x
2155b3a827e2Smrg        }
2156b3a827e2Smrg	h
2157b3a827e2Smrg	/^Written by/q' < "$progpath"
2158b3a827e2Smrg    echo
2159b3a827e2Smrg    eval \$ECHO \""$usage_message"\"
2160b3a827e2Smrg}
216167ab2ff2Smrg
2162e0963edeSmrg
2163b3a827e2Smrg# func_version
2164b3a827e2Smrg# ------------
2165b3a827e2Smrg# Echo version message to standard output and exit.
2166c30f5000Smrg# The version message is extracted from the calling file's header
2167c30f5000Smrg# comments, with leading '# ' stripped:
2168c30f5000Smrg#   1. First display the progname and version
2169c30f5000Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170c30f5000Smrg#   3. Then a blank line followed by the first following line matching
2171c30f5000Smrg#      /^# Copyright /
2172c30f5000Smrg#   4. Immediately followed by any lines between the previous matches,
2173c30f5000Smrg#      except lines preceding the intervening completely blank line.
2174c30f5000Smrg# For example, see the header comments of this file.
2175b3a827e2Smrgfunc_version ()
2176b3a827e2Smrg{
2177b3a827e2Smrg    $debug_cmd
2178f05b35a2Smrg
2179b3a827e2Smrg    printf '%s\n' "$progname $scriptversion"
2180b3a827e2Smrg    $SED -n '
2181c30f5000Smrg        /^# Written by /!b
2182c30f5000Smrg        s|^# ||; p; n
2183c30f5000Smrg
2184c30f5000Smrg        :fwd2blnk
2185c30f5000Smrg        /./ {
2186c30f5000Smrg          n
2187c30f5000Smrg          b fwd2blnk
2188b3a827e2Smrg        }
2189c30f5000Smrg        p; n
2190c30f5000Smrg
2191c30f5000Smrg        :holdwrnt
2192c30f5000Smrg        s|^# ||
2193c30f5000Smrg        s|^# *$||
2194c30f5000Smrg        /^Copyright /!{
2195c30f5000Smrg          /./H
2196c30f5000Smrg          n
2197c30f5000Smrg          b holdwrnt
2198b3a827e2Smrg        }
2199c30f5000Smrg
2200c30f5000Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201c30f5000Smrg        G
2202c30f5000Smrg        s|\(\n\)\n*|\1|g
2203c30f5000Smrg        p; q' < "$progpath"
2204f05b35a2Smrg
2205b3a827e2Smrg    exit $?
2206b3a827e2Smrg}
2207f05b35a2Smrg
2208e0963edeSmrg
2209b3a827e2Smrg# Local variables:
2210b3a827e2Smrg# mode: shell-script
2211b3a827e2Smrg# sh-indentation: 2
2212b3a827e2Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213c30f5000Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214b3a827e2Smrg# time-stamp-time-zone: "UTC"
2215b3a827e2Smrg# End:
2216e0963edeSmrg
2217b3a827e2Smrg# Set a version string.
2218c30f5000Smrgscriptversion='(GNU libtool) 2.4.7'
2219e0963edeSmrg
2220f05b35a2Smrg
2221b3a827e2Smrg# func_echo ARG...
2222b3a827e2Smrg# ----------------
2223b3a827e2Smrg# Libtool also displays the current mode in messages, so override
2224b3a827e2Smrg# funclib.sh func_echo with this custom definition.
2225b3a827e2Smrgfunc_echo ()
222667ab2ff2Smrg{
2227b3a827e2Smrg    $debug_cmd
222867ab2ff2Smrg
2229b3a827e2Smrg    _G_message=$*
223067ab2ff2Smrg
2231b3a827e2Smrg    func_echo_IFS=$IFS
2232b3a827e2Smrg    IFS=$nl
2233b3a827e2Smrg    for _G_line in $_G_message; do
2234b3a827e2Smrg      IFS=$func_echo_IFS
2235b3a827e2Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236b3a827e2Smrg    done
2237b3a827e2Smrg    IFS=$func_echo_IFS
2238b3a827e2Smrg}
223967ab2ff2Smrg
2240b3a827e2Smrg
2241b3a827e2Smrg# func_warning ARG...
2242b3a827e2Smrg# -------------------
2243b3a827e2Smrg# Libtool warnings are not categorized, so override funclib.sh
2244b3a827e2Smrg# func_warning with this simpler definition.
2245b3a827e2Smrgfunc_warning ()
224667ab2ff2Smrg{
2247b3a827e2Smrg    $debug_cmd
224867ab2ff2Smrg
2249b3a827e2Smrg    $warning_func ${1+"$@"}
2250b3a827e2Smrg}
225167ab2ff2Smrg
225267ab2ff2Smrg
2253b3a827e2Smrg## ---------------- ##
2254b3a827e2Smrg## Options parsing. ##
2255b3a827e2Smrg## ---------------- ##
2256b3a827e2Smrg
2257b3a827e2Smrg# Hook in the functions to make sure our own options are parsed during
2258b3a827e2Smrg# the option parsing loop.
2259b3a827e2Smrg
2260b3a827e2Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261b3a827e2Smrg
2262b3a827e2Smrg# Short help message in response to '-h'.
2263b3a827e2Smrgusage_message="Options:
2264b3a827e2Smrg       --config             show all configuration variables
2265b3a827e2Smrg       --debug              enable verbose shell tracing
2266b3a827e2Smrg   -n, --dry-run            display commands without modifying any files
2267b3a827e2Smrg       --features           display basic configuration information and exit
2268b3a827e2Smrg       --mode=MODE          use operation mode MODE
2269b3a827e2Smrg       --no-warnings        equivalent to '-Wnone'
2270b3a827e2Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271b3a827e2Smrg       --quiet, --silent    don't print informational messages
2272b3a827e2Smrg       --tag=TAG            use configuration variables from tag TAG
2273b3a827e2Smrg   -v, --verbose            print more informational messages than default
2274b3a827e2Smrg       --version            print version information
2275b3a827e2Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276b3a827e2Smrg   -h, --help, --help-all   print short, long, or detailed help message
2277b3a827e2Smrg"
227867ab2ff2Smrg
2279b3a827e2Smrg# Additional text appended to 'usage_message' in response to '--help'.
2280b3a827e2Smrgfunc_help ()
228167ab2ff2Smrg{
2282b3a827e2Smrg    $debug_cmd
2283b3a827e2Smrg
2284b3a827e2Smrg    func_usage_message
2285b3a827e2Smrg    $ECHO "$long_help_message
2286b3a827e2Smrg
2287b3a827e2SmrgMODE must be one of the following:
2288b3a827e2Smrg
2289b3a827e2Smrg       clean           remove files from the build directory
2290b3a827e2Smrg       compile         compile a source file into a libtool object
2291b3a827e2Smrg       execute         automatically set library path, then run a program
2292b3a827e2Smrg       finish          complete the installation of libtool libraries
2293b3a827e2Smrg       install         install libraries or executables
2294b3a827e2Smrg       link            create a library or an executable
2295b3a827e2Smrg       uninstall       remove libraries from an installed directory
2296b3a827e2Smrg
2297b3a827e2SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298b3a827e2Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299b3a827e2SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300b3a827e2Smrg
2301b3a827e2SmrgWhen reporting a bug, please describe a test case to reproduce it and
2302b3a827e2Smrginclude the following information:
2303b3a827e2Smrg
2304b3a827e2Smrg       host-triplet:   $host
2305b3a827e2Smrg       shell:          $SHELL
2306b3a827e2Smrg       compiler:       $LTCC
2307b3a827e2Smrg       compiler flags: $LTCFLAGS
2308b3a827e2Smrg       linker:         $LD (gnu? $with_gnu_ld)
2309c30f5000Smrg       version:        $progname (GNU libtool) 2.4.7
2310b3a827e2Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311b3a827e2Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312b3a827e2Smrg
2313b3a827e2SmrgReport bugs to <bug-libtool@gnu.org>.
2314b3a827e2SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315b3a827e2SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316b3a827e2Smrg    exit 0
2317b3a827e2Smrg}
231867ab2ff2Smrg
231967ab2ff2Smrg
2320b3a827e2Smrg# func_lo2o OBJECT-NAME
2321b3a827e2Smrg# ---------------------
2322b3a827e2Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323b3a827e2Smrg# object suffix.
2324b3a827e2Smrg
2325b3a827e2Smrglo2o=s/\\.lo\$/.$objext/
2326b3a827e2Smrgo2lo=s/\\.$objext\$/.lo/
2327b3a827e2Smrg
2328b3a827e2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329b3a827e2Smrg  eval 'func_lo2o ()
2330b3a827e2Smrg  {
2331b3a827e2Smrg    case $1 in
2332b3a827e2Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333b3a827e2Smrg      *   ) func_lo2o_result=$1               ;;
2334b3a827e2Smrg    esac
2335b3a827e2Smrg  }'
2336b3a827e2Smrg
2337b3a827e2Smrg  # func_xform LIBOBJ-OR-SOURCE
2338b3a827e2Smrg  # ---------------------------
2339b3a827e2Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340b3a827e2Smrg  # suffix to a '.lo' libtool-object suffix.
2341b3a827e2Smrg  eval 'func_xform ()
2342b3a827e2Smrg  {
2343b3a827e2Smrg    func_xform_result=${1%.*}.lo
2344b3a827e2Smrg  }'
2345b3a827e2Smrgelse
2346b3a827e2Smrg  # ...otherwise fall back to using sed.
2347b3a827e2Smrg  func_lo2o ()
2348b3a827e2Smrg  {
2349b3a827e2Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350b3a827e2Smrg  }
2351b3a827e2Smrg
2352b3a827e2Smrg  func_xform ()
2353b3a827e2Smrg  {
2354b3a827e2Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355b3a827e2Smrg  }
2356b3a827e2Smrgfi
235767ab2ff2Smrg
235867ab2ff2Smrg
2359b3a827e2Smrg# func_fatal_configuration ARG...
2360b3a827e2Smrg# -------------------------------
2361f05b35a2Smrg# Echo program name prefixed message to standard error, followed by
2362f05b35a2Smrg# a configuration failure hint, and exit.
2363f05b35a2Smrgfunc_fatal_configuration ()
2364f05b35a2Smrg{
2365c30f5000Smrg    func_fatal_error ${1+"$@"} \
2366b3a827e2Smrg      "See the $PACKAGE documentation for more information." \
2367b3a827e2Smrg      "Fatal configuration error."
2368f05b35a2Smrg}
2369e0963edeSmrg
2370e0963edeSmrg
2371f05b35a2Smrg# func_config
2372b3a827e2Smrg# -----------
2373f05b35a2Smrg# Display the configuration for all the tags in this script.
2374f05b35a2Smrgfunc_config ()
2375f05b35a2Smrg{
2376f05b35a2Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377f05b35a2Smrg    re_endcf='^# ### END LIBTOOL'
2378f05b35a2Smrg
2379f05b35a2Smrg    # Default configuration.
2380f05b35a2Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2381e0963edeSmrg
2382e0963edeSmrg    # Now print the configurations for the tags.
2383e0963edeSmrg    for tagname in $taglist; do
2384f05b35a2Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385e0963edeSmrg    done
2386e0963edeSmrg
2387f05b35a2Smrg    exit $?
2388f05b35a2Smrg}
2389e0963edeSmrg
2390b3a827e2Smrg
2391f05b35a2Smrg# func_features
2392b3a827e2Smrg# -------------
2393f05b35a2Smrg# Display the features supported by this script.
2394f05b35a2Smrgfunc_features ()
2395f05b35a2Smrg{
239649e108a1Smrg    echo "host: $host"
2397b3a827e2Smrg    if test yes = "$build_libtool_libs"; then
239849e108a1Smrg      echo "enable shared libraries"
2399e0963edeSmrg    else
240049e108a1Smrg      echo "disable shared libraries"
2401e0963edeSmrg    fi
2402b3a827e2Smrg    if test yes = "$build_old_libs"; then
240349e108a1Smrg      echo "enable static libraries"
2404e0963edeSmrg    else
240549e108a1Smrg      echo "disable static libraries"
2406e0963edeSmrg    fi
2407f05b35a2Smrg
2408e0963edeSmrg    exit $?
2409f05b35a2Smrg}
2410e0963edeSmrg
2411b3a827e2Smrg
2412b3a827e2Smrg# func_enable_tag TAGNAME
2413b3a827e2Smrg# -----------------------
2414f05b35a2Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415f05b35a2Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416f05b35a2Smrg# variable here.
2417f05b35a2Smrgfunc_enable_tag ()
2418f05b35a2Smrg{
2419b3a827e2Smrg    # Global variable:
2420b3a827e2Smrg    tagname=$1
2421e0963edeSmrg
2422b3a827e2Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423b3a827e2Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424b3a827e2Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425e0963edeSmrg
2426b3a827e2Smrg    # Validate tagname.
2427b3a827e2Smrg    case $tagname in
2428b3a827e2Smrg      *[!-_A-Za-z0-9,/]*)
2429b3a827e2Smrg        func_fatal_error "invalid tag name: $tagname"
2430b3a827e2Smrg        ;;
2431b3a827e2Smrg    esac
2432e0963edeSmrg
2433b3a827e2Smrg    # Don't test for the "default" C tag, as we know it's
2434b3a827e2Smrg    # there but not specially marked.
2435b3a827e2Smrg    case $tagname in
2436b3a827e2Smrg        CC) ;;
2437f05b35a2Smrg    *)
2438b3a827e2Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439b3a827e2Smrg	  taglist="$taglist $tagname"
2440b3a827e2Smrg
2441b3a827e2Smrg	  # Evaluate the configuration.  Be careful to quote the path
2442b3a827e2Smrg	  # and the sed script, to avoid splitting on whitespace, but
2443b3a827e2Smrg	  # also don't use non-portable quotes within backquotes within
2444b3a827e2Smrg	  # quotes we have to do it in 2 steps:
2445b3a827e2Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446b3a827e2Smrg	  eval "$extractedcf"
2447b3a827e2Smrg        else
2448b3a827e2Smrg	  func_error "ignoring unknown tag $tagname"
2449b3a827e2Smrg        fi
2450b3a827e2Smrg        ;;
2451b3a827e2Smrg    esac
2452f05b35a2Smrg}
2453f05b35a2Smrg
2454b3a827e2Smrg
245567ab2ff2Smrg# func_check_version_match
2456b3a827e2Smrg# ------------------------
245767ab2ff2Smrg# Ensure that we are using m4 macros, and libtool script from the same
245867ab2ff2Smrg# release of libtool.
245967ab2ff2Smrgfunc_check_version_match ()
2460f05b35a2Smrg{
2461b3a827e2Smrg    if test "$package_revision" != "$macro_revision"; then
2462b3a827e2Smrg      if test "$VERSION" != "$macro_version"; then
2463b3a827e2Smrg        if test -z "$macro_version"; then
2464b3a827e2Smrg          cat >&2 <<_LT_EOF
246567ab2ff2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
246667ab2ff2Smrg$progname: definition of this LT_INIT comes from an older release.
246767ab2ff2Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
246867ab2ff2Smrg$progname: and run autoconf again.
246967ab2ff2Smrg_LT_EOF
2470b3a827e2Smrg        else
2471b3a827e2Smrg          cat >&2 <<_LT_EOF
247267ab2ff2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
247367ab2ff2Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
247467ab2ff2Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
247567ab2ff2Smrg$progname: and run autoconf again.
247667ab2ff2Smrg_LT_EOF
2477b3a827e2Smrg        fi
2478b3a827e2Smrg      else
2479b3a827e2Smrg        cat >&2 <<_LT_EOF
248067ab2ff2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
248167ab2ff2Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
248267ab2ff2Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
248367ab2ff2Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
248467ab2ff2Smrg_LT_EOF
2485b3a827e2Smrg      fi
2486e0963edeSmrg
2487b3a827e2Smrg      exit $EXIT_MISMATCH
2488b3a827e2Smrg    fi
248967ab2ff2Smrg}
249067ab2ff2Smrg
249167ab2ff2Smrg
2492b3a827e2Smrg# libtool_options_prep [ARG]...
2493b3a827e2Smrg# -----------------------------
2494b3a827e2Smrg# Preparation for options parsed by libtool.
2495b3a827e2Smrglibtool_options_prep ()
2496b3a827e2Smrg{
2497b3a827e2Smrg    $debug_mode
2498e0963edeSmrg
2499b3a827e2Smrg    # Option defaults:
2500b3a827e2Smrg    opt_config=false
2501b3a827e2Smrg    opt_dlopen=
2502b3a827e2Smrg    opt_dry_run=false
2503b3a827e2Smrg    opt_help=false
2504b3a827e2Smrg    opt_mode=
2505b3a827e2Smrg    opt_preserve_dup_deps=false
2506b3a827e2Smrg    opt_quiet=false
250767ab2ff2Smrg
2508b3a827e2Smrg    nonopt=
2509b3a827e2Smrg    preserve_args=
251067ab2ff2Smrg
2511c30f5000Smrg    _G_rc_lt_options_prep=:
2512c30f5000Smrg
2513b3a827e2Smrg    # Shorthand for --mode=foo, only valid as the first argument
2514b3a827e2Smrg    case $1 in
2515b3a827e2Smrg    clean|clea|cle|cl)
2516b3a827e2Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517b3a827e2Smrg      ;;
2518b3a827e2Smrg    compile|compil|compi|comp|com|co|c)
2519b3a827e2Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520b3a827e2Smrg      ;;
2521b3a827e2Smrg    execute|execut|execu|exec|exe|ex|e)
2522b3a827e2Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523b3a827e2Smrg      ;;
2524b3a827e2Smrg    finish|finis|fini|fin|fi|f)
2525b3a827e2Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526b3a827e2Smrg      ;;
2527b3a827e2Smrg    install|instal|insta|inst|ins|in|i)
2528b3a827e2Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2529b3a827e2Smrg      ;;
2530b3a827e2Smrg    link|lin|li|l)
2531b3a827e2Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2532b3a827e2Smrg      ;;
2533b3a827e2Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534b3a827e2Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535b3a827e2Smrg      ;;
2536c30f5000Smrg    *)
2537c30f5000Smrg      _G_rc_lt_options_prep=false
2538c30f5000Smrg      ;;
2539b3a827e2Smrg    esac
2540b3a827e2Smrg
2541c30f5000Smrg    if $_G_rc_lt_options_prep; then
2542c30f5000Smrg      # Pass back the list of options.
2543c30f5000Smrg      func_quote eval ${1+"$@"}
2544c30f5000Smrg      libtool_options_prep_result=$func_quote_result
2545c30f5000Smrg    fi
2546b3a827e2Smrg}
2547b3a827e2Smrgfunc_add_hook func_options_prep libtool_options_prep
254867ab2ff2Smrg
254967ab2ff2Smrg
2550b3a827e2Smrg# libtool_parse_options [ARG]...
2551b3a827e2Smrg# ---------------------------------
2552b3a827e2Smrg# Provide handling for libtool specific options.
2553b3a827e2Smrglibtool_parse_options ()
255467ab2ff2Smrg{
2555b3a827e2Smrg    $debug_cmd
2556f05b35a2Smrg
2557c30f5000Smrg    _G_rc_lt_parse_options=false
2558c30f5000Smrg
2559b3a827e2Smrg    # Perform our own loop to consume as many options as possible in
2560b3a827e2Smrg    # each iteration.
2561b3a827e2Smrg    while test $# -gt 0; do
2562c30f5000Smrg      _G_match_lt_parse_options=:
2563b3a827e2Smrg      _G_opt=$1
2564b3a827e2Smrg      shift
2565b3a827e2Smrg      case $_G_opt in
2566b3a827e2Smrg        --dry-run|--dryrun|-n)
2567b3a827e2Smrg                        opt_dry_run=:
2568b3a827e2Smrg                        ;;
2569b3a827e2Smrg
2570b3a827e2Smrg        --config)       func_config ;;
2571b3a827e2Smrg
2572b3a827e2Smrg        --dlopen|-dlopen)
2573b3a827e2Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574b3a827e2Smrg}$1"
2575b3a827e2Smrg                        shift
2576b3a827e2Smrg                        ;;
2577b3a827e2Smrg
2578b3a827e2Smrg        --preserve-dup-deps)
2579b3a827e2Smrg                        opt_preserve_dup_deps=: ;;
2580b3a827e2Smrg
2581b3a827e2Smrg        --features)     func_features ;;
2582b3a827e2Smrg
2583b3a827e2Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584b3a827e2Smrg
2585b3a827e2Smrg        --help)         opt_help=: ;;
2586b3a827e2Smrg
2587b3a827e2Smrg        --help-all)     opt_help=': help-all' ;;
2588b3a827e2Smrg
2589b3a827e2Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590b3a827e2Smrg                        opt_mode=$1
2591b3a827e2Smrg                        case $1 in
2592b3a827e2Smrg                          # Valid mode arguments:
2593b3a827e2Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594b3a827e2Smrg
2595b3a827e2Smrg                          # Catch anything else as an error
2596b3a827e2Smrg                          *) func_error "invalid argument for $_G_opt"
2597b3a827e2Smrg                             exit_cmd=exit
2598b3a827e2Smrg                             break
2599b3a827e2Smrg                             ;;
2600b3a827e2Smrg                        esac
2601b3a827e2Smrg                        shift
2602b3a827e2Smrg                        ;;
2603b3a827e2Smrg
2604b3a827e2Smrg        --no-silent|--no-quiet)
2605b3a827e2Smrg                        opt_quiet=false
2606b3a827e2Smrg                        func_append preserve_args " $_G_opt"
2607b3a827e2Smrg                        ;;
2608b3a827e2Smrg
2609b3a827e2Smrg        --no-warnings|--no-warning|--no-warn)
2610b3a827e2Smrg                        opt_warning=false
2611b3a827e2Smrg                        func_append preserve_args " $_G_opt"
2612b3a827e2Smrg                        ;;
2613b3a827e2Smrg
2614b3a827e2Smrg        --no-verbose)
2615b3a827e2Smrg                        opt_verbose=false
2616b3a827e2Smrg                        func_append preserve_args " $_G_opt"
2617b3a827e2Smrg                        ;;
2618b3a827e2Smrg
2619b3a827e2Smrg        --silent|--quiet)
2620b3a827e2Smrg                        opt_quiet=:
2621b3a827e2Smrg                        opt_verbose=false
2622b3a827e2Smrg                        func_append preserve_args " $_G_opt"
2623b3a827e2Smrg                        ;;
2624b3a827e2Smrg
2625b3a827e2Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626b3a827e2Smrg                        opt_tag=$1
2627b3a827e2Smrg                        func_append preserve_args " $_G_opt $1"
2628b3a827e2Smrg                        func_enable_tag "$1"
2629b3a827e2Smrg                        shift
2630b3a827e2Smrg                        ;;
2631b3a827e2Smrg
2632b3a827e2Smrg        --verbose|-v)   opt_quiet=false
2633b3a827e2Smrg                        opt_verbose=:
2634b3a827e2Smrg                        func_append preserve_args " $_G_opt"
2635b3a827e2Smrg                        ;;
2636b3a827e2Smrg
2637c30f5000Smrg        # An option not handled by this hook function:
2638c30f5000Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639c30f5000Smrg                        _G_match_lt_parse_options=false
2640c30f5000Smrg                        break
2641c30f5000Smrg                        ;;
2642b3a827e2Smrg      esac
2643c30f5000Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644b3a827e2Smrg    done
264567ab2ff2Smrg
2646c30f5000Smrg    if $_G_rc_lt_parse_options; then
2647c30f5000Smrg      # save modified positional parameters for caller
2648c30f5000Smrg      func_quote eval ${1+"$@"}
2649c30f5000Smrg      libtool_parse_options_result=$func_quote_result
2650c30f5000Smrg    fi
2651b3a827e2Smrg}
2652b3a827e2Smrgfunc_add_hook func_parse_options libtool_parse_options
2653f05b35a2Smrg
2654e0963edeSmrg
2655f05b35a2Smrg
2656b3a827e2Smrg# libtool_validate_options [ARG]...
2657b3a827e2Smrg# ---------------------------------
2658b3a827e2Smrg# Perform any sanity checks on option settings and/or unconsumed
2659b3a827e2Smrg# arguments.
2660b3a827e2Smrglibtool_validate_options ()
2661b3a827e2Smrg{
2662b3a827e2Smrg    # save first non-option argument
2663b3a827e2Smrg    if test 0 -lt $#; then
2664b3a827e2Smrg      nonopt=$1
2665b3a827e2Smrg      shift
2666f05b35a2Smrg    fi
2667f05b35a2Smrg
2668b3a827e2Smrg    # preserve --debug
2669b3a827e2Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2670f05b35a2Smrg
2671b3a827e2Smrg    case $host in
2672b3a827e2Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673b3a827e2Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674b3a827e2Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675b3a827e2Smrg        # don't eliminate duplications in $postdeps and $predeps
2676b3a827e2Smrg        opt_duplicate_compiler_generated_deps=:
2677b3a827e2Smrg        ;;
2678b3a827e2Smrg      *)
2679b3a827e2Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680b3a827e2Smrg        ;;
2681b3a827e2Smrg    esac
2682f05b35a2Smrg
2683b3a827e2Smrg    $opt_help || {
2684b3a827e2Smrg      # Sanity checks first:
2685b3a827e2Smrg      func_check_version_match
2686b3a827e2Smrg
2687b3a827e2Smrg      test yes != "$build_libtool_libs" \
2688b3a827e2Smrg        && test yes != "$build_old_libs" \
2689b3a827e2Smrg        && func_fatal_configuration "not configured to build any kind of library"
2690b3a827e2Smrg
2691b3a827e2Smrg      # Darwin sucks
2692b3a827e2Smrg      eval std_shrext=\"$shrext_cmds\"
2693b3a827e2Smrg
2694b3a827e2Smrg      # Only execute mode is allowed to have -dlopen flags.
2695b3a827e2Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696b3a827e2Smrg        func_error "unrecognized option '-dlopen'"
2697b3a827e2Smrg        $ECHO "$help" 1>&2
2698b3a827e2Smrg        exit $EXIT_FAILURE
2699b3a827e2Smrg      fi
2700f05b35a2Smrg
2701b3a827e2Smrg      # Change the help message to a mode-specific one.
2702b3a827e2Smrg      generic_help=$help
2703b3a827e2Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704b3a827e2Smrg    }
2705f05b35a2Smrg
2706b3a827e2Smrg    # Pass back the unparsed argument list
2707c30f5000Smrg    func_quote eval ${1+"$@"}
2708c30f5000Smrg    libtool_validate_options_result=$func_quote_result
270967ab2ff2Smrg}
2710b3a827e2Smrgfunc_add_hook func_validate_options libtool_validate_options
2711f05b35a2Smrg
2712f05b35a2Smrg
2713b3a827e2Smrg# Process options as early as possible so that --help and --version
2714b3a827e2Smrg# can return quickly.
2715b3a827e2Smrgfunc_options ${1+"$@"}
2716b3a827e2Smrgeval set dummy "$func_options_result"; shift
2717b3a827e2Smrg
2718e0963edeSmrg
2719e0963edeSmrg
272067ab2ff2Smrg## ----------- ##
272167ab2ff2Smrg##    Main.    ##
272267ab2ff2Smrg## ----------- ##
2723e0963edeSmrg
2724b3a827e2Smrgmagic='%%%MAGIC variable%%%'
2725b3a827e2Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2726b3a827e2Smrg
2727b3a827e2Smrg# Global variables.
2728b3a827e2Smrgextracted_archives=
2729b3a827e2Smrgextracted_serial=0
2730b3a827e2Smrg
2731b3a827e2Smrg# If this variable is set in any of the actions, the command in it
2732b3a827e2Smrg# will be execed at the end.  This prevents here-documents from being
2733b3a827e2Smrg# left over by shells.
2734b3a827e2Smrgexec_cmd=
2735b3a827e2Smrg
2736b3a827e2Smrg
2737b3a827e2Smrg# A function that is used when there is no print builtin or printf.
2738b3a827e2Smrgfunc_fallback_echo ()
2739b3a827e2Smrg{
2740b3a827e2Smrg  eval 'cat <<_LTECHO_EOF
2741b3a827e2Smrg$1
2742b3a827e2Smrg_LTECHO_EOF'
2743b3a827e2Smrg}
2744b3a827e2Smrg
2745b3a827e2Smrg# func_generated_by_libtool
2746b3a827e2Smrg# True iff stdin has been generated by Libtool. This function is only
2747b3a827e2Smrg# a basic sanity check; it will hardly flush out determined imposters.
2748b3a827e2Smrgfunc_generated_by_libtool_p ()
2749b3a827e2Smrg{
2750b3a827e2Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751b3a827e2Smrg}
2752b3a827e2Smrg
2753f05b35a2Smrg# func_lalib_p file
2754b3a827e2Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2755f05b35a2Smrg# This function is only a basic sanity check; it will hardly flush out
2756f05b35a2Smrg# determined imposters.
2757f05b35a2Smrgfunc_lalib_p ()
2758f05b35a2Smrg{
2759f05b35a2Smrg    test -f "$1" &&
2760b3a827e2Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2761f05b35a2Smrg}
2762e0963edeSmrg
2763f05b35a2Smrg# func_lalib_unsafe_p file
2764b3a827e2Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2765f05b35a2Smrg# This function implements the same check as func_lalib_p without
2766f05b35a2Smrg# resorting to external programs.  To this end, it redirects stdin and
2767f05b35a2Smrg# closes it afterwards, without saving the original file descriptor.
2768f05b35a2Smrg# As a safety measure, use it only where a negative result would be
2769b3a827e2Smrg# fatal anyway.  Works if 'file' does not exist.
2770f05b35a2Smrgfunc_lalib_unsafe_p ()
2771f05b35a2Smrg{
2772f05b35a2Smrg    lalib_p=no
2773f05b35a2Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2774f05b35a2Smrg	for lalib_p_l in 1 2 3 4
2775f05b35a2Smrg	do
2776f05b35a2Smrg	    read lalib_p_line
2777b3a827e2Smrg	    case $lalib_p_line in
2778f05b35a2Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2779f05b35a2Smrg	    esac
2780f05b35a2Smrg	done
2781f05b35a2Smrg	exec 0<&5 5<&-
2782f05b35a2Smrg    fi
2783b3a827e2Smrg    test yes = "$lalib_p"
2784f05b35a2Smrg}
2785e0963edeSmrg
2786f05b35a2Smrg# func_ltwrapper_script_p file
2787f05b35a2Smrg# True iff FILE is a libtool wrapper script
2788f05b35a2Smrg# This function is only a basic sanity check; it will hardly flush out
2789f05b35a2Smrg# determined imposters.
2790f05b35a2Smrgfunc_ltwrapper_script_p ()
2791f05b35a2Smrg{
2792b3a827e2Smrg    test -f "$1" &&
2793b3a827e2Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2794f05b35a2Smrg}
2795e0963edeSmrg
2796f05b35a2Smrg# func_ltwrapper_executable_p file
2797f05b35a2Smrg# True iff FILE is a libtool wrapper executable
2798f05b35a2Smrg# This function is only a basic sanity check; it will hardly flush out
2799f05b35a2Smrg# determined imposters.
2800f05b35a2Smrgfunc_ltwrapper_executable_p ()
2801f05b35a2Smrg{
2802f05b35a2Smrg    func_ltwrapper_exec_suffix=
2803f05b35a2Smrg    case $1 in
2804f05b35a2Smrg    *.exe) ;;
2805f05b35a2Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2806f05b35a2Smrg    esac
2807f05b35a2Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2808f05b35a2Smrg}
2809e0963edeSmrg
2810f05b35a2Smrg# func_ltwrapper_scriptname file
2811f05b35a2Smrg# Assumes file is an ltwrapper_executable
2812f05b35a2Smrg# uses $file to determine the appropriate filename for a
2813f05b35a2Smrg# temporary ltwrapper_script.
2814f05b35a2Smrgfunc_ltwrapper_scriptname ()
2815f05b35a2Smrg{
281667ab2ff2Smrg    func_dirname_and_basename "$1" "" "."
281767ab2ff2Smrg    func_stripname '' '.exe' "$func_basename_result"
2818b3a827e2Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2819f05b35a2Smrg}
2820f05b35a2Smrg
2821f05b35a2Smrg# func_ltwrapper_p file
2822f05b35a2Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2823f05b35a2Smrg# This function is only a basic sanity check; it will hardly flush out
2824f05b35a2Smrg# determined imposters.
2825f05b35a2Smrgfunc_ltwrapper_p ()
2826f05b35a2Smrg{
2827f05b35a2Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2828f05b35a2Smrg}
2829f05b35a2Smrg
2830f05b35a2Smrg
2831f05b35a2Smrg# func_execute_cmds commands fail_cmd
2832f05b35a2Smrg# Execute tilde-delimited COMMANDS.
2833f05b35a2Smrg# If FAIL_CMD is given, eval that upon failure.
2834f05b35a2Smrg# FAIL_CMD may read-access the current command in variable CMD!
2835f05b35a2Smrgfunc_execute_cmds ()
2836f05b35a2Smrg{
2837b3a827e2Smrg    $debug_cmd
2838b3a827e2Smrg
2839f05b35a2Smrg    save_ifs=$IFS; IFS='~'
2840f05b35a2Smrg    for cmd in $1; do
2841b3a827e2Smrg      IFS=$sp$nl
2842f05b35a2Smrg      eval cmd=\"$cmd\"
2843b3a827e2Smrg      IFS=$save_ifs
2844f05b35a2Smrg      func_show_eval "$cmd" "${2-:}"
2845f05b35a2Smrg    done
2846f05b35a2Smrg    IFS=$save_ifs
2847f05b35a2Smrg}
2848f05b35a2Smrg
2849f05b35a2Smrg
2850f05b35a2Smrg# func_source file
2851f05b35a2Smrg# Source FILE, adding directory component if necessary.
2852f05b35a2Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2853f05b35a2Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2854f05b35a2Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855b3a827e2Smrg# 'FILE.' does not work on cygwin managed mounts.
2856f05b35a2Smrgfunc_source ()
2857f05b35a2Smrg{
2858b3a827e2Smrg    $debug_cmd
2859b3a827e2Smrg
2860f05b35a2Smrg    case $1 in
2861f05b35a2Smrg    */* | *\\*)	. "$1" ;;
2862f05b35a2Smrg    *)		. "./$1" ;;
2863f05b35a2Smrg    esac
2864f05b35a2Smrg}
2865f05b35a2Smrg
2866f05b35a2Smrg
286767ab2ff2Smrg# func_resolve_sysroot PATH
286867ab2ff2Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
286967ab2ff2Smrg# func_resolve_sysroot_result
287067ab2ff2Smrgfunc_resolve_sysroot ()
287167ab2ff2Smrg{
287267ab2ff2Smrg  func_resolve_sysroot_result=$1
287367ab2ff2Smrg  case $func_resolve_sysroot_result in
287467ab2ff2Smrg  =*)
287567ab2ff2Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
287667ab2ff2Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
287767ab2ff2Smrg    ;;
287867ab2ff2Smrg  esac
287967ab2ff2Smrg}
288067ab2ff2Smrg
288167ab2ff2Smrg# func_replace_sysroot PATH
288267ab2ff2Smrg# If PATH begins with the sysroot, replace it with = and
288367ab2ff2Smrg# store the result into func_replace_sysroot_result.
288467ab2ff2Smrgfunc_replace_sysroot ()
288567ab2ff2Smrg{
2886b3a827e2Smrg  case $lt_sysroot:$1 in
288767ab2ff2Smrg  ?*:"$lt_sysroot"*)
288867ab2ff2Smrg    func_stripname "$lt_sysroot" '' "$1"
2889b3a827e2Smrg    func_replace_sysroot_result='='$func_stripname_result
289067ab2ff2Smrg    ;;
289167ab2ff2Smrg  *)
289267ab2ff2Smrg    # Including no sysroot.
289367ab2ff2Smrg    func_replace_sysroot_result=$1
289467ab2ff2Smrg    ;;
289567ab2ff2Smrg  esac
289667ab2ff2Smrg}
289767ab2ff2Smrg
2898f05b35a2Smrg# func_infer_tag arg
2899f05b35a2Smrg# Infer tagged configuration to use if any are available and
2900f05b35a2Smrg# if one wasn't chosen via the "--tag" command line option.
2901f05b35a2Smrg# Only attempt this if the compiler in the base compile
2902f05b35a2Smrg# command doesn't match the default compiler.
2903f05b35a2Smrg# arg is usually of the form 'gcc ...'
2904f05b35a2Smrgfunc_infer_tag ()
2905f05b35a2Smrg{
2906b3a827e2Smrg    $debug_cmd
2907b3a827e2Smrg
2908f05b35a2Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2909f05b35a2Smrg      CC_quoted=
2910f05b35a2Smrg      for arg in $CC; do
291167ab2ff2Smrg	func_append_quoted CC_quoted "$arg"
2912f05b35a2Smrg      done
291349e108a1Smrg      CC_expanded=`func_echo_all $CC`
291449e108a1Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2915f05b35a2Smrg      case $@ in
2916f05b35a2Smrg      # Blanks in the command may have been stripped by the calling shell,
2917f05b35a2Smrg      # but not from the CC environment variable when configure was run.
291849e108a1Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291949e108a1Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2920f05b35a2Smrg      # Blanks at the start of $base_compile will cause this to fail
2921f05b35a2Smrg      # if we don't check for them as well.
2922f05b35a2Smrg      *)
2923f05b35a2Smrg	for z in $available_tags; do
2924f05b35a2Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2925f05b35a2Smrg	    # Evaluate the configuration.
2926b3a827e2Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2927f05b35a2Smrg	    CC_quoted=
2928f05b35a2Smrg	    for arg in $CC; do
2929f05b35a2Smrg	      # Double-quote args containing other shell metacharacters.
293067ab2ff2Smrg	      func_append_quoted CC_quoted "$arg"
2931f05b35a2Smrg	    done
293249e108a1Smrg	    CC_expanded=`func_echo_all $CC`
293349e108a1Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2934f05b35a2Smrg	    case "$@ " in
293549e108a1Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
293649e108a1Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2937f05b35a2Smrg	      # The compiler in the base compile command matches
2938f05b35a2Smrg	      # the one in the tagged configuration.
2939f05b35a2Smrg	      # Assume this is the tagged configuration we want.
2940f05b35a2Smrg	      tagname=$z
2941f05b35a2Smrg	      break
2942f05b35a2Smrg	      ;;
2943f05b35a2Smrg	    esac
2944f05b35a2Smrg	  fi
2945f05b35a2Smrg	done
2946f05b35a2Smrg	# If $tagname still isn't set, then no tagged configuration
2947f05b35a2Smrg	# was found and let the user know that the "--tag" command
2948f05b35a2Smrg	# line option must be used.
2949f05b35a2Smrg	if test -z "$tagname"; then
2950f05b35a2Smrg	  func_echo "unable to infer tagged configuration"
2951b3a827e2Smrg	  func_fatal_error "specify a tag with '--tag'"
2952f05b35a2Smrg#	else
2953f05b35a2Smrg#	  func_verbose "using $tagname tagged configuration"
2954f05b35a2Smrg	fi
2955f05b35a2Smrg	;;
2956f05b35a2Smrg      esac
2957f05b35a2Smrg    fi
2958f05b35a2Smrg}
2959f05b35a2Smrg
2960f05b35a2Smrg
2961f05b35a2Smrg
296267ab2ff2Smrg# func_write_libtool_object output_name pic_name nonpic_name
296367ab2ff2Smrg# Create a libtool object file (analogous to a ".la" file),
296467ab2ff2Smrg# but don't create it if we're doing a dry run.
296567ab2ff2Smrgfunc_write_libtool_object ()
296667ab2ff2Smrg{
2967b3a827e2Smrg    write_libobj=$1
2968b3a827e2Smrg    if test yes = "$build_libtool_libs"; then
2969b3a827e2Smrg      write_lobj=\'$2\'
297067ab2ff2Smrg    else
297167ab2ff2Smrg      write_lobj=none
297267ab2ff2Smrg    fi
297367ab2ff2Smrg
2974b3a827e2Smrg    if test yes = "$build_old_libs"; then
2975b3a827e2Smrg      write_oldobj=\'$3\'
297667ab2ff2Smrg    else
297767ab2ff2Smrg      write_oldobj=none
297867ab2ff2Smrg    fi
297967ab2ff2Smrg
298067ab2ff2Smrg    $opt_dry_run || {
298167ab2ff2Smrg      cat >${write_libobj}T <<EOF
298267ab2ff2Smrg# $write_libobj - a libtool object file
2983b3a827e2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
298467ab2ff2Smrg#
298567ab2ff2Smrg# Please DO NOT delete this file!
298667ab2ff2Smrg# It is necessary for linking the library.
298767ab2ff2Smrg
298867ab2ff2Smrg# Name of the PIC object.
298967ab2ff2Smrgpic_object=$write_lobj
299067ab2ff2Smrg
299167ab2ff2Smrg# Name of the non-PIC object
299267ab2ff2Smrgnon_pic_object=$write_oldobj
299367ab2ff2Smrg
299467ab2ff2SmrgEOF
2995b3a827e2Smrg      $MV "${write_libobj}T" "$write_libobj"
299667ab2ff2Smrg    }
299767ab2ff2Smrg}
299867ab2ff2Smrg
299967ab2ff2Smrg
300067ab2ff2Smrg##################################################
300167ab2ff2Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
300267ab2ff2Smrg##################################################
300367ab2ff2Smrg
300467ab2ff2Smrg# func_convert_core_file_wine_to_w32 ARG
300567ab2ff2Smrg# Helper function used by file name conversion functions when $build is *nix,
300667ab2ff2Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
300767ab2ff2Smrg# correctly configured wine environment available, with the winepath program
300867ab2ff2Smrg# in $build's $PATH.
300967ab2ff2Smrg#
301067ab2ff2Smrg# ARG is the $build file name to be converted to w32 format.
301167ab2ff2Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
301267ab2ff2Smrg# be empty on error (or when ARG is empty)
301367ab2ff2Smrgfunc_convert_core_file_wine_to_w32 ()
301467ab2ff2Smrg{
3015b3a827e2Smrg  $debug_cmd
3016b3a827e2Smrg
3017b3a827e2Smrg  func_convert_core_file_wine_to_w32_result=$1
301867ab2ff2Smrg  if test -n "$1"; then
301967ab2ff2Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
302067ab2ff2Smrg    # are forced to check the contents of stdout. On the other hand, if the
302167ab2ff2Smrg    # command is not found, the shell will set an exit code of 127 and print
302267ab2ff2Smrg    # *an error message* to stdout. So we must check for both error code of
302367ab2ff2Smrg    # zero AND non-empty stdout, which explains the odd construction:
302467ab2ff2Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025b3a827e2Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
302667ab2ff2Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027b3a827e2Smrg        $SED -e "$sed_naive_backslashify"`
302867ab2ff2Smrg    else
302967ab2ff2Smrg      func_convert_core_file_wine_to_w32_result=
303067ab2ff2Smrg    fi
303167ab2ff2Smrg  fi
303267ab2ff2Smrg}
303367ab2ff2Smrg# end: func_convert_core_file_wine_to_w32
303467ab2ff2Smrg
303567ab2ff2Smrg
303667ab2ff2Smrg# func_convert_core_path_wine_to_w32 ARG
303767ab2ff2Smrg# Helper function used by path conversion functions when $build is *nix, and
303867ab2ff2Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
303967ab2ff2Smrg# configured wine environment available, with the winepath program in $build's
304067ab2ff2Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
304167ab2ff2Smrg#
304267ab2ff2Smrg# ARG is path to be converted from $build format to win32.
304367ab2ff2Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
304467ab2ff2Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
304567ab2ff2Smrg# are convertible, then the result may be empty.
304667ab2ff2Smrgfunc_convert_core_path_wine_to_w32 ()
304767ab2ff2Smrg{
3048b3a827e2Smrg  $debug_cmd
3049b3a827e2Smrg
305067ab2ff2Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051b3a827e2Smrg  func_convert_core_path_wine_to_w32_result=
305267ab2ff2Smrg  if test -n "$1"; then
305367ab2ff2Smrg    oldIFS=$IFS
305467ab2ff2Smrg    IFS=:
305567ab2ff2Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
305667ab2ff2Smrg      IFS=$oldIFS
305767ab2ff2Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058b3a827e2Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
305967ab2ff2Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060b3a827e2Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
306167ab2ff2Smrg        else
306267ab2ff2Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
306367ab2ff2Smrg        fi
306467ab2ff2Smrg      fi
306567ab2ff2Smrg    done
306667ab2ff2Smrg    IFS=$oldIFS
306767ab2ff2Smrg  fi
306867ab2ff2Smrg}
306967ab2ff2Smrg# end: func_convert_core_path_wine_to_w32
307067ab2ff2Smrg
307167ab2ff2Smrg
307267ab2ff2Smrg# func_cygpath ARGS...
307367ab2ff2Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
307467ab2ff2Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
307567ab2ff2Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
307667ab2ff2Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
307767ab2ff2Smrg# file name or path is assumed to be in w32 format, as previously converted
307867ab2ff2Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
307967ab2ff2Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
308067ab2ff2Smrg# Cygwin format). Returns an empty string on error.
308167ab2ff2Smrg#
308267ab2ff2Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
308367ab2ff2Smrg# be converted.
308467ab2ff2Smrg#
308567ab2ff2Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
308667ab2ff2Smrg# environment variable; do not put it in $PATH.
308767ab2ff2Smrgfunc_cygpath ()
308867ab2ff2Smrg{
3089b3a827e2Smrg  $debug_cmd
3090b3a827e2Smrg
309167ab2ff2Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
309267ab2ff2Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
309367ab2ff2Smrg    if test "$?" -ne 0; then
309467ab2ff2Smrg      # on failure, ensure result is empty
309567ab2ff2Smrg      func_cygpath_result=
309667ab2ff2Smrg    fi
309767ab2ff2Smrg  else
309867ab2ff2Smrg    func_cygpath_result=
3099b3a827e2Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
310067ab2ff2Smrg  fi
310167ab2ff2Smrg}
310267ab2ff2Smrg#end: func_cygpath
310367ab2ff2Smrg
310467ab2ff2Smrg
310567ab2ff2Smrg# func_convert_core_msys_to_w32 ARG
310667ab2ff2Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
310767ab2ff2Smrg# result in func_convert_core_msys_to_w32_result.
310867ab2ff2Smrgfunc_convert_core_msys_to_w32 ()
310967ab2ff2Smrg{
3110b3a827e2Smrg  $debug_cmd
3111b3a827e2Smrg
311267ab2ff2Smrg  # awkward: cmd appends spaces to result
311367ab2ff2Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114b3a827e2Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
311567ab2ff2Smrg}
311667ab2ff2Smrg#end: func_convert_core_msys_to_w32
311767ab2ff2Smrg
311867ab2ff2Smrg
311967ab2ff2Smrg# func_convert_file_check ARG1 ARG2
312067ab2ff2Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
312167ab2ff2Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
312267ab2ff2Smrg# func_to_host_file_result to ARG1).
312367ab2ff2Smrgfunc_convert_file_check ()
312467ab2ff2Smrg{
3125b3a827e2Smrg  $debug_cmd
3126b3a827e2Smrg
3127b3a827e2Smrg  if test -z "$2" && test -n "$1"; then
312867ab2ff2Smrg    func_error "Could not determine host file name corresponding to"
3129b3a827e2Smrg    func_error "  '$1'"
313067ab2ff2Smrg    func_error "Continuing, but uninstalled executables may not work."
313167ab2ff2Smrg    # Fallback:
3132b3a827e2Smrg    func_to_host_file_result=$1
313367ab2ff2Smrg  fi
313467ab2ff2Smrg}
313567ab2ff2Smrg# end func_convert_file_check
313667ab2ff2Smrg
313767ab2ff2Smrg
313867ab2ff2Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
313967ab2ff2Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
314067ab2ff2Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
314167ab2ff2Smrg# func_to_host_file_result to a simplistic fallback value (see below).
314267ab2ff2Smrgfunc_convert_path_check ()
314367ab2ff2Smrg{
3144b3a827e2Smrg  $debug_cmd
3145b3a827e2Smrg
314667ab2ff2Smrg  if test -z "$4" && test -n "$3"; then
314767ab2ff2Smrg    func_error "Could not determine the host path corresponding to"
3148b3a827e2Smrg    func_error "  '$3'"
314967ab2ff2Smrg    func_error "Continuing, but uninstalled executables may not work."
315067ab2ff2Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
315167ab2ff2Smrg    # should not be "improved".  See libtool.info.
315267ab2ff2Smrg    if test "x$1" != "x$2"; then
315367ab2ff2Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
315467ab2ff2Smrg      func_to_host_path_result=`echo "$3" |
315567ab2ff2Smrg        $SED -e "$lt_replace_pathsep_chars"`
315667ab2ff2Smrg    else
3157b3a827e2Smrg      func_to_host_path_result=$3
315867ab2ff2Smrg    fi
315967ab2ff2Smrg  fi
316067ab2ff2Smrg}
316167ab2ff2Smrg# end func_convert_path_check
316267ab2ff2Smrg
316367ab2ff2Smrg
316467ab2ff2Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
316567ab2ff2Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
316667ab2ff2Smrg# and appending REPL if ORIG matches BACKPAT.
316767ab2ff2Smrgfunc_convert_path_front_back_pathsep ()
316867ab2ff2Smrg{
3169b3a827e2Smrg  $debug_cmd
3170b3a827e2Smrg
317167ab2ff2Smrg  case $4 in
3172b3a827e2Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
317367ab2ff2Smrg    ;;
317467ab2ff2Smrg  esac
317567ab2ff2Smrg  case $4 in
317667ab2ff2Smrg  $2 ) func_append func_to_host_path_result "$3"
317767ab2ff2Smrg    ;;
317867ab2ff2Smrg  esac
317967ab2ff2Smrg}
318067ab2ff2Smrg# end func_convert_path_front_back_pathsep
318167ab2ff2Smrg
318267ab2ff2Smrg
318367ab2ff2Smrg##################################################
318467ab2ff2Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
318567ab2ff2Smrg##################################################
3186b3a827e2Smrg# invoked via '$to_host_file_cmd ARG'
318767ab2ff2Smrg#
318867ab2ff2Smrg# In each case, ARG is the path to be converted from $build to $host format.
318967ab2ff2Smrg# Result will be available in $func_to_host_file_result.
319067ab2ff2Smrg
319167ab2ff2Smrg
319267ab2ff2Smrg# func_to_host_file ARG
319367ab2ff2Smrg# Converts the file name ARG from $build format to $host format. Return result
319467ab2ff2Smrg# in func_to_host_file_result.
319567ab2ff2Smrgfunc_to_host_file ()
319667ab2ff2Smrg{
3197b3a827e2Smrg  $debug_cmd
3198b3a827e2Smrg
319967ab2ff2Smrg  $to_host_file_cmd "$1"
320067ab2ff2Smrg}
320167ab2ff2Smrg# end func_to_host_file
320267ab2ff2Smrg
320367ab2ff2Smrg
320467ab2ff2Smrg# func_to_tool_file ARG LAZY
320567ab2ff2Smrg# converts the file name ARG from $build format to toolchain format. Return
320667ab2ff2Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
320767ab2ff2Smrg# in (the comma separated) LAZY, no conversion takes place.
320867ab2ff2Smrgfunc_to_tool_file ()
320967ab2ff2Smrg{
3210b3a827e2Smrg  $debug_cmd
3211b3a827e2Smrg
321267ab2ff2Smrg  case ,$2, in
321367ab2ff2Smrg    *,"$to_tool_file_cmd",*)
321467ab2ff2Smrg      func_to_tool_file_result=$1
321567ab2ff2Smrg      ;;
321667ab2ff2Smrg    *)
321767ab2ff2Smrg      $to_tool_file_cmd "$1"
321867ab2ff2Smrg      func_to_tool_file_result=$func_to_host_file_result
321967ab2ff2Smrg      ;;
322067ab2ff2Smrg  esac
322167ab2ff2Smrg}
322267ab2ff2Smrg# end func_to_tool_file
322367ab2ff2Smrg
322467ab2ff2Smrg
322567ab2ff2Smrg# func_convert_file_noop ARG
322667ab2ff2Smrg# Copy ARG to func_to_host_file_result.
322767ab2ff2Smrgfunc_convert_file_noop ()
322867ab2ff2Smrg{
3229b3a827e2Smrg  func_to_host_file_result=$1
323067ab2ff2Smrg}
323167ab2ff2Smrg# end func_convert_file_noop
323267ab2ff2Smrg
323367ab2ff2Smrg
323467ab2ff2Smrg# func_convert_file_msys_to_w32 ARG
323567ab2ff2Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
323667ab2ff2Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
323767ab2ff2Smrg# func_to_host_file_result.
323867ab2ff2Smrgfunc_convert_file_msys_to_w32 ()
323967ab2ff2Smrg{
3240b3a827e2Smrg  $debug_cmd
3241b3a827e2Smrg
3242b3a827e2Smrg  func_to_host_file_result=$1
324367ab2ff2Smrg  if test -n "$1"; then
324467ab2ff2Smrg    func_convert_core_msys_to_w32 "$1"
3245b3a827e2Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
324667ab2ff2Smrg  fi
324767ab2ff2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
324867ab2ff2Smrg}
324967ab2ff2Smrg# end func_convert_file_msys_to_w32
325067ab2ff2Smrg
325167ab2ff2Smrg
325267ab2ff2Smrg# func_convert_file_cygwin_to_w32 ARG
325367ab2ff2Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
325467ab2ff2Smrg# func_to_host_file_result.
325567ab2ff2Smrgfunc_convert_file_cygwin_to_w32 ()
325667ab2ff2Smrg{
3257b3a827e2Smrg  $debug_cmd
3258b3a827e2Smrg
3259b3a827e2Smrg  func_to_host_file_result=$1
326067ab2ff2Smrg  if test -n "$1"; then
326167ab2ff2Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
326267ab2ff2Smrg    # LT_CYGPATH in this case.
326367ab2ff2Smrg    func_to_host_file_result=`cygpath -m "$1"`
326467ab2ff2Smrg  fi
326567ab2ff2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
326667ab2ff2Smrg}
326767ab2ff2Smrg# end func_convert_file_cygwin_to_w32
326867ab2ff2Smrg
326967ab2ff2Smrg
327067ab2ff2Smrg# func_convert_file_nix_to_w32 ARG
327167ab2ff2Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
327267ab2ff2Smrg# and a working winepath. Returns result in func_to_host_file_result.
327367ab2ff2Smrgfunc_convert_file_nix_to_w32 ()
327467ab2ff2Smrg{
3275b3a827e2Smrg  $debug_cmd
3276b3a827e2Smrg
3277b3a827e2Smrg  func_to_host_file_result=$1
327867ab2ff2Smrg  if test -n "$1"; then
327967ab2ff2Smrg    func_convert_core_file_wine_to_w32 "$1"
3280b3a827e2Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
328167ab2ff2Smrg  fi
328267ab2ff2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
328367ab2ff2Smrg}
328467ab2ff2Smrg# end func_convert_file_nix_to_w32
328567ab2ff2Smrg
328667ab2ff2Smrg
328767ab2ff2Smrg# func_convert_file_msys_to_cygwin ARG
328867ab2ff2Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
328967ab2ff2Smrg# Returns result in func_to_host_file_result.
329067ab2ff2Smrgfunc_convert_file_msys_to_cygwin ()
329167ab2ff2Smrg{
3292b3a827e2Smrg  $debug_cmd
3293b3a827e2Smrg
3294b3a827e2Smrg  func_to_host_file_result=$1
329567ab2ff2Smrg  if test -n "$1"; then
329667ab2ff2Smrg    func_convert_core_msys_to_w32 "$1"
329767ab2ff2Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298b3a827e2Smrg    func_to_host_file_result=$func_cygpath_result
329967ab2ff2Smrg  fi
330067ab2ff2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
330167ab2ff2Smrg}
330267ab2ff2Smrg# end func_convert_file_msys_to_cygwin
330367ab2ff2Smrg
330467ab2ff2Smrg
330567ab2ff2Smrg# func_convert_file_nix_to_cygwin ARG
330667ab2ff2Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
330767ab2ff2Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
330867ab2ff2Smrg# in func_to_host_file_result.
330967ab2ff2Smrgfunc_convert_file_nix_to_cygwin ()
331067ab2ff2Smrg{
3311b3a827e2Smrg  $debug_cmd
3312b3a827e2Smrg
3313b3a827e2Smrg  func_to_host_file_result=$1
331467ab2ff2Smrg  if test -n "$1"; then
331567ab2ff2Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
331667ab2ff2Smrg    func_convert_core_file_wine_to_w32 "$1"
331767ab2ff2Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318b3a827e2Smrg    func_to_host_file_result=$func_cygpath_result
331967ab2ff2Smrg  fi
332067ab2ff2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
332167ab2ff2Smrg}
332267ab2ff2Smrg# end func_convert_file_nix_to_cygwin
332367ab2ff2Smrg
332467ab2ff2Smrg
332567ab2ff2Smrg#############################################
332667ab2ff2Smrg# $build to $host PATH CONVERSION FUNCTIONS #
332767ab2ff2Smrg#############################################
3328b3a827e2Smrg# invoked via '$to_host_path_cmd ARG'
332967ab2ff2Smrg#
333067ab2ff2Smrg# In each case, ARG is the path to be converted from $build to $host format.
333167ab2ff2Smrg# The result will be available in $func_to_host_path_result.
333267ab2ff2Smrg#
333367ab2ff2Smrg# Path separators are also converted from $build format to $host format.  If
333467ab2ff2Smrg# ARG begins or ends with a path separator character, it is preserved (but
333567ab2ff2Smrg# converted to $host format) on output.
333667ab2ff2Smrg#
333767ab2ff2Smrg# All path conversion functions are named using the following convention:
333867ab2ff2Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
333967ab2ff2Smrg#   path conversion function         : func_convert_path_X_to_Y ()
334067ab2ff2Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
334167ab2ff2Smrg# same.  If conversion functions are added for new $build/$host combinations,
334267ab2ff2Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
334367ab2ff2Smrg# will break.
334467ab2ff2Smrg
334567ab2ff2Smrg
334667ab2ff2Smrg# func_init_to_host_path_cmd
334767ab2ff2Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
334867ab2ff2Smrg# appropriate value, based on the value of $to_host_file_cmd.
334967ab2ff2Smrgto_host_path_cmd=
335067ab2ff2Smrgfunc_init_to_host_path_cmd ()
335167ab2ff2Smrg{
3352b3a827e2Smrg  $debug_cmd
3353b3a827e2Smrg
335467ab2ff2Smrg  if test -z "$to_host_path_cmd"; then
335567ab2ff2Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356b3a827e2Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
335767ab2ff2Smrg  fi
335867ab2ff2Smrg}
335967ab2ff2Smrg
336067ab2ff2Smrg
336167ab2ff2Smrg# func_to_host_path ARG
336267ab2ff2Smrg# Converts the path ARG from $build format to $host format. Return result
336367ab2ff2Smrg# in func_to_host_path_result.
336467ab2ff2Smrgfunc_to_host_path ()
336567ab2ff2Smrg{
3366b3a827e2Smrg  $debug_cmd
3367b3a827e2Smrg
336867ab2ff2Smrg  func_init_to_host_path_cmd
336967ab2ff2Smrg  $to_host_path_cmd "$1"
337067ab2ff2Smrg}
337167ab2ff2Smrg# end func_to_host_path
337267ab2ff2Smrg
337367ab2ff2Smrg
337467ab2ff2Smrg# func_convert_path_noop ARG
337567ab2ff2Smrg# Copy ARG to func_to_host_path_result.
337667ab2ff2Smrgfunc_convert_path_noop ()
337767ab2ff2Smrg{
3378b3a827e2Smrg  func_to_host_path_result=$1
337967ab2ff2Smrg}
338067ab2ff2Smrg# end func_convert_path_noop
338167ab2ff2Smrg
338267ab2ff2Smrg
338367ab2ff2Smrg# func_convert_path_msys_to_w32 ARG
338467ab2ff2Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
338567ab2ff2Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
338667ab2ff2Smrg# func_to_host_path_result.
338767ab2ff2Smrgfunc_convert_path_msys_to_w32 ()
3388f05b35a2Smrg{
3389b3a827e2Smrg  $debug_cmd
3390b3a827e2Smrg
3391b3a827e2Smrg  func_to_host_path_result=$1
339267ab2ff2Smrg  if test -n "$1"; then
339367ab2ff2Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
339467ab2ff2Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
339567ab2ff2Smrg    # and winepath ignores them completely.
339667ab2ff2Smrg    func_stripname : : "$1"
339767ab2ff2Smrg    func_to_host_path_tmp1=$func_stripname_result
339867ab2ff2Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399b3a827e2Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
340067ab2ff2Smrg    func_convert_path_check : ";" \
340167ab2ff2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
340267ab2ff2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
340367ab2ff2Smrg  fi
340467ab2ff2Smrg}
340567ab2ff2Smrg# end func_convert_path_msys_to_w32
3406f05b35a2Smrg
3407f05b35a2Smrg
340867ab2ff2Smrg# func_convert_path_cygwin_to_w32 ARG
340967ab2ff2Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
341067ab2ff2Smrg# func_to_host_file_result.
341167ab2ff2Smrgfunc_convert_path_cygwin_to_w32 ()
341267ab2ff2Smrg{
3413b3a827e2Smrg  $debug_cmd
3414b3a827e2Smrg
3415b3a827e2Smrg  func_to_host_path_result=$1
341667ab2ff2Smrg  if test -n "$1"; then
341767ab2ff2Smrg    # See func_convert_path_msys_to_w32:
341867ab2ff2Smrg    func_stripname : : "$1"
341967ab2ff2Smrg    func_to_host_path_tmp1=$func_stripname_result
342067ab2ff2Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
342167ab2ff2Smrg    func_convert_path_check : ";" \
342267ab2ff2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
342367ab2ff2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
342467ab2ff2Smrg  fi
342567ab2ff2Smrg}
342667ab2ff2Smrg# end func_convert_path_cygwin_to_w32
3427f05b35a2Smrg
3428f05b35a2Smrg
342967ab2ff2Smrg# func_convert_path_nix_to_w32 ARG
343067ab2ff2Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
343167ab2ff2Smrg# a working winepath.  Returns result in func_to_host_file_result.
343267ab2ff2Smrgfunc_convert_path_nix_to_w32 ()
343367ab2ff2Smrg{
3434b3a827e2Smrg  $debug_cmd
3435b3a827e2Smrg
3436b3a827e2Smrg  func_to_host_path_result=$1
343767ab2ff2Smrg  if test -n "$1"; then
343867ab2ff2Smrg    # See func_convert_path_msys_to_w32:
343967ab2ff2Smrg    func_stripname : : "$1"
344067ab2ff2Smrg    func_to_host_path_tmp1=$func_stripname_result
344167ab2ff2Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442b3a827e2Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
344367ab2ff2Smrg    func_convert_path_check : ";" \
344467ab2ff2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
344567ab2ff2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
344667ab2ff2Smrg  fi
344767ab2ff2Smrg}
344867ab2ff2Smrg# end func_convert_path_nix_to_w32
3449f05b35a2Smrg
345067ab2ff2Smrg
345167ab2ff2Smrg# func_convert_path_msys_to_cygwin ARG
345267ab2ff2Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
345367ab2ff2Smrg# Returns result in func_to_host_file_result.
345467ab2ff2Smrgfunc_convert_path_msys_to_cygwin ()
345567ab2ff2Smrg{
3456b3a827e2Smrg  $debug_cmd
3457b3a827e2Smrg
3458b3a827e2Smrg  func_to_host_path_result=$1
345967ab2ff2Smrg  if test -n "$1"; then
346067ab2ff2Smrg    # See func_convert_path_msys_to_w32:
346167ab2ff2Smrg    func_stripname : : "$1"
346267ab2ff2Smrg    func_to_host_path_tmp1=$func_stripname_result
346367ab2ff2Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
346467ab2ff2Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465b3a827e2Smrg    func_to_host_path_result=$func_cygpath_result
346667ab2ff2Smrg    func_convert_path_check : : \
346767ab2ff2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
346867ab2ff2Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
346967ab2ff2Smrg  fi
347067ab2ff2Smrg}
347167ab2ff2Smrg# end func_convert_path_msys_to_cygwin
347267ab2ff2Smrg
347367ab2ff2Smrg
347467ab2ff2Smrg# func_convert_path_nix_to_cygwin ARG
347567ab2ff2Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
347667ab2ff2Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
347767ab2ff2Smrg# func_to_host_file_result.
347867ab2ff2Smrgfunc_convert_path_nix_to_cygwin ()
347967ab2ff2Smrg{
3480b3a827e2Smrg  $debug_cmd
3481b3a827e2Smrg
3482b3a827e2Smrg  func_to_host_path_result=$1
348367ab2ff2Smrg  if test -n "$1"; then
348467ab2ff2Smrg    # Remove leading and trailing path separator characters from
348567ab2ff2Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
348667ab2ff2Smrg    # into '.;' and ';.', and winepath ignores them completely.
348767ab2ff2Smrg    func_stripname : : "$1"
348867ab2ff2Smrg    func_to_host_path_tmp1=$func_stripname_result
348967ab2ff2Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
349067ab2ff2Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491b3a827e2Smrg    func_to_host_path_result=$func_cygpath_result
349267ab2ff2Smrg    func_convert_path_check : : \
349367ab2ff2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
349467ab2ff2Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
349567ab2ff2Smrg  fi
3496f05b35a2Smrg}
349767ab2ff2Smrg# end func_convert_path_nix_to_cygwin
349867ab2ff2Smrg
3499f05b35a2Smrg
3500b3a827e2Smrg# func_dll_def_p FILE
3501b3a827e2Smrg# True iff FILE is a Windows DLL '.def' file.
3502b3a827e2Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503b3a827e2Smrgfunc_dll_def_p ()
3504b3a827e2Smrg{
3505b3a827e2Smrg  $debug_cmd
3506b3a827e2Smrg
3507b3a827e2Smrg  func_dll_def_p_tmp=`$SED -n \
3508b3a827e2Smrg    -e 's/^[	 ]*//' \
3509b3a827e2Smrg    -e '/^\(;.*\)*$/d' \
3510b3a827e2Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511b3a827e2Smrg    -e q \
3512b3a827e2Smrg    "$1"`
3513b3a827e2Smrg  test DEF = "$func_dll_def_p_tmp"
3514b3a827e2Smrg}
3515b3a827e2Smrg
3516b3a827e2Smrg
3517f05b35a2Smrg# func_mode_compile arg...
3518f05b35a2Smrgfunc_mode_compile ()
3519f05b35a2Smrg{
3520b3a827e2Smrg    $debug_cmd
3521b3a827e2Smrg
3522f05b35a2Smrg    # Get the compilation command and the source file.
3523f05b35a2Smrg    base_compile=
3524b3a827e2Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3525f05b35a2Smrg    suppress_opt=yes
3526f05b35a2Smrg    suppress_output=
3527f05b35a2Smrg    arg_mode=normal
3528f05b35a2Smrg    libobj=
3529f05b35a2Smrg    later=
3530f05b35a2Smrg    pie_flag=
3531f05b35a2Smrg
3532f05b35a2Smrg    for arg
3533f05b35a2Smrg    do
3534f05b35a2Smrg      case $arg_mode in
3535f05b35a2Smrg      arg  )
3536f05b35a2Smrg	# do not "continue".  Instead, add this to base_compile
3537b3a827e2Smrg	lastarg=$arg
3538f05b35a2Smrg	arg_mode=normal
3539f05b35a2Smrg	;;
3540f05b35a2Smrg
3541f05b35a2Smrg      target )
3542b3a827e2Smrg	libobj=$arg
3543f05b35a2Smrg	arg_mode=normal
3544f05b35a2Smrg	continue
3545f05b35a2Smrg	;;
3546f05b35a2Smrg
3547f05b35a2Smrg      normal )
3548f05b35a2Smrg	# Accept any command-line options.
3549f05b35a2Smrg	case $arg in
3550f05b35a2Smrg	-o)
3551f05b35a2Smrg	  test -n "$libobj" && \
3552b3a827e2Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3553f05b35a2Smrg	  arg_mode=target
3554f05b35a2Smrg	  continue
3555f05b35a2Smrg	  ;;
3556f05b35a2Smrg
3557f05b35a2Smrg	-pie | -fpie | -fPIE)
355867ab2ff2Smrg          func_append pie_flag " $arg"
3559f05b35a2Smrg	  continue
3560f05b35a2Smrg	  ;;
3561f05b35a2Smrg
3562f05b35a2Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
356367ab2ff2Smrg	  func_append later " $arg"
3564f05b35a2Smrg	  continue
3565f05b35a2Smrg	  ;;
3566f05b35a2Smrg
3567f05b35a2Smrg	-no-suppress)
3568e0963edeSmrg	  suppress_opt=no
3569e0963edeSmrg	  continue
3570e0963edeSmrg	  ;;
3571e0963edeSmrg
3572e0963edeSmrg	-Xcompiler)
3573e0963edeSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574e0963edeSmrg	  continue      #  The current "srcfile" will either be retained or
3575e0963edeSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576e0963edeSmrg
3577e0963edeSmrg	-Wc,*)
3578f05b35a2Smrg	  func_stripname '-Wc,' '' "$arg"
3579f05b35a2Smrg	  args=$func_stripname_result
3580e0963edeSmrg	  lastarg=
3581b3a827e2Smrg	  save_ifs=$IFS; IFS=,
3582f05b35a2Smrg	  for arg in $args; do
3583b3a827e2Smrg	    IFS=$save_ifs
358467ab2ff2Smrg	    func_append_quoted lastarg "$arg"
3585e0963edeSmrg	  done
3586b3a827e2Smrg	  IFS=$save_ifs
3587f05b35a2Smrg	  func_stripname ' ' '' "$lastarg"
3588f05b35a2Smrg	  lastarg=$func_stripname_result
3589e0963edeSmrg
3590e0963edeSmrg	  # Add the arguments to base_compile.
359167ab2ff2Smrg	  func_append base_compile " $lastarg"
3592e0963edeSmrg	  continue
3593e0963edeSmrg	  ;;
3594e0963edeSmrg
3595f05b35a2Smrg	*)
3596e0963edeSmrg	  # Accept the current argument as the source file.
3597e0963edeSmrg	  # The previous "srcfile" becomes the current argument.
3598e0963edeSmrg	  #
3599b3a827e2Smrg	  lastarg=$srcfile
3600b3a827e2Smrg	  srcfile=$arg
3601e0963edeSmrg	  ;;
3602e0963edeSmrg	esac  #  case $arg
3603e0963edeSmrg	;;
3604e0963edeSmrg      esac    #  case $arg_mode
3605e0963edeSmrg
3606e0963edeSmrg      # Aesthetically quote the previous argument.
360767ab2ff2Smrg      func_append_quoted base_compile "$lastarg"
3608e0963edeSmrg    done # for arg
3609e0963edeSmrg
3610e0963edeSmrg    case $arg_mode in
3611e0963edeSmrg    arg)
3612f05b35a2Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613e0963edeSmrg      ;;
3614e0963edeSmrg    target)
3615b3a827e2Smrg      func_fatal_error "you must specify a target with '-o'"
3616e0963edeSmrg      ;;
3617e0963edeSmrg    *)
3618e0963edeSmrg      # Get the name of the library object.
3619f05b35a2Smrg      test -z "$libobj" && {
3620f05b35a2Smrg	func_basename "$srcfile"
3621b3a827e2Smrg	libobj=$func_basename_result
3622f05b35a2Smrg      }
3623e0963edeSmrg      ;;
3624e0963edeSmrg    esac
3625e0963edeSmrg
3626e0963edeSmrg    # Recognize several different file suffixes.
3627e0963edeSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3628e0963edeSmrg    case $libobj in
3629f05b35a2Smrg    *.[cCFSifmso] | \
3630f05b35a2Smrg    *.ada | *.adb | *.ads | *.asm | \
3631f05b35a2Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632e494fffdSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3633f05b35a2Smrg      func_xform "$libobj"
3634f05b35a2Smrg      libobj=$func_xform_result
3635f05b35a2Smrg      ;;
3636e0963edeSmrg    esac
3637e0963edeSmrg
3638e0963edeSmrg    case $libobj in
3639f05b35a2Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640e0963edeSmrg    *)
3641b3a827e2Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642e0963edeSmrg      ;;
3643e0963edeSmrg    esac
3644e0963edeSmrg
3645e0963edeSmrg    func_infer_tag $base_compile
3646e0963edeSmrg
3647e0963edeSmrg    for arg in $later; do
3648e0963edeSmrg      case $arg in
3649f05b35a2Smrg      -shared)
3650b3a827e2Smrg	test yes = "$build_libtool_libs" \
3651b3a827e2Smrg	  || func_fatal_configuration "cannot build a shared library"
3652f05b35a2Smrg	build_old_libs=no
3653f05b35a2Smrg	continue
3654f05b35a2Smrg	;;
3655f05b35a2Smrg
3656e0963edeSmrg      -static)
3657f05b35a2Smrg	build_libtool_libs=no
3658e0963edeSmrg	build_old_libs=yes
3659e0963edeSmrg	continue
3660e0963edeSmrg	;;
3661e0963edeSmrg
3662e0963edeSmrg      -prefer-pic)
3663e0963edeSmrg	pic_mode=yes
3664e0963edeSmrg	continue
3665e0963edeSmrg	;;
3666e0963edeSmrg
3667e0963edeSmrg      -prefer-non-pic)
3668e0963edeSmrg	pic_mode=no
3669e0963edeSmrg	continue
3670e0963edeSmrg	;;
3671e0963edeSmrg      esac
3672e0963edeSmrg    done
3673e0963edeSmrg
3674c30f5000Smrg    func_quote_arg pretty "$libobj"
3675c30f5000Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3676f05b35a2Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677b3a827e2Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3678f05b35a2Smrg    func_dirname_and_basename "$obj" "/" ""
3679b3a827e2Smrg    objname=$func_basename_result
3680b3a827e2Smrg    xdir=$func_dirname_result
3681b3a827e2Smrg    lobj=$xdir$objdir/$objname
3682e0963edeSmrg
3683f05b35a2Smrg    test -z "$base_compile" && \
3684f05b35a2Smrg      func_fatal_help "you must specify a compilation command"
3685e0963edeSmrg
3686e0963edeSmrg    # Delete any leftover library objects.
3687b3a827e2Smrg    if test yes = "$build_old_libs"; then
3688e0963edeSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3689e0963edeSmrg    else
3690e0963edeSmrg      removelist="$lobj $libobj ${libobj}T"
3691e0963edeSmrg    fi
3692e0963edeSmrg
3693e0963edeSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694e0963edeSmrg    case $host_os in
3695f05b35a2Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696e0963edeSmrg      pic_mode=default
3697e0963edeSmrg      ;;
3698e0963edeSmrg    esac
3699b3a827e2Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700e0963edeSmrg      # non-PIC code in shared libraries is not supported
3701e0963edeSmrg      pic_mode=default
3702e0963edeSmrg    fi
3703e0963edeSmrg
3704e0963edeSmrg    # Calculate the filename of the output object if compiler does
3705e0963edeSmrg    # not support -o with -c
3706b3a827e2Smrg    if test no = "$compiler_c_o"; then
3707b3a827e2Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708b3a827e2Smrg      lockfile=$output_obj.lock
3709e0963edeSmrg    else
3710e0963edeSmrg      output_obj=
3711e0963edeSmrg      need_locks=no
3712e0963edeSmrg      lockfile=
3713e0963edeSmrg    fi
3714e0963edeSmrg
3715e0963edeSmrg    # Lock this critical section if it is needed
3716e0963edeSmrg    # We use this script file to make the link, it avoids creating a new file
3717b3a827e2Smrg    if test yes = "$need_locks"; then
3718f05b35a2Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3719f05b35a2Smrg	func_echo "Waiting for $lockfile to be removed"
3720e0963edeSmrg	sleep 2
3721e0963edeSmrg      done
3722b3a827e2Smrg    elif test warn = "$need_locks"; then
3723e0963edeSmrg      if test -f "$lockfile"; then
3724f05b35a2Smrg	$ECHO "\
3725e0963edeSmrg*** ERROR, $lockfile exists and contains:
3726e0963edeSmrg`cat $lockfile 2>/dev/null`
3727e0963edeSmrg
3728e0963edeSmrgThis indicates that another process is trying to use the same
3729e0963edeSmrgtemporary object file, and libtool could not work around it because
3730b3a827e2Smrgyour compiler does not support '-c' and '-o' together.  If you
3731e0963edeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3732e0963edeSmrgavoid parallel builds (make -j) in this platform, or get a better
3733e0963edeSmrgcompiler."
3734e0963edeSmrg
3735f05b35a2Smrg	$opt_dry_run || $RM $removelist
3736e0963edeSmrg	exit $EXIT_FAILURE
3737e0963edeSmrg      fi
373867ab2ff2Smrg      func_append removelist " $output_obj"
3739f05b35a2Smrg      $ECHO "$srcfile" > "$lockfile"
3740e0963edeSmrg    fi
3741e0963edeSmrg
3742f05b35a2Smrg    $opt_dry_run || $RM $removelist
374367ab2ff2Smrg    func_append removelist " $lockfile"
3744f05b35a2Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3745f05b35a2Smrg
374667ab2ff2Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
374767ab2ff2Smrg    srcfile=$func_to_tool_file_result
3748c30f5000Smrg    func_quote_arg pretty "$srcfile"
3749c30f5000Smrg    qsrcfile=$func_quote_arg_result
3750e0963edeSmrg
3751e0963edeSmrg    # Only build a PIC object if we are building libtool libraries.
3752b3a827e2Smrg    if test yes = "$build_libtool_libs"; then
3753e0963edeSmrg      # Without this assignment, base_compile gets emptied.
3754e0963edeSmrg      fbsd_hideous_sh_bug=$base_compile
3755e0963edeSmrg
3756b3a827e2Smrg      if test no != "$pic_mode"; then
3757e0963edeSmrg	command="$base_compile $qsrcfile $pic_flag"
3758e0963edeSmrg      else
3759e0963edeSmrg	# Don't build PIC code
3760e0963edeSmrg	command="$base_compile $qsrcfile"
3761e0963edeSmrg      fi
3762e0963edeSmrg
3763f05b35a2Smrg      func_mkdir_p "$xdir$objdir"
3764e0963edeSmrg
3765e0963edeSmrg      if test -z "$output_obj"; then
3766e0963edeSmrg	# Place PIC objects in $objdir
376767ab2ff2Smrg	func_append command " -o $lobj"
3768e0963edeSmrg      fi
3769e0963edeSmrg
3770f05b35a2Smrg      func_show_eval_locale "$command"	\
3771f05b35a2Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772e0963edeSmrg
3773b3a827e2Smrg      if test warn = "$need_locks" &&
3774e0963edeSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3775f05b35a2Smrg	$ECHO "\
3776e0963edeSmrg*** ERROR, $lockfile contains:
3777e0963edeSmrg`cat $lockfile 2>/dev/null`
3778e0963edeSmrg
3779e0963edeSmrgbut it should contain:
3780e0963edeSmrg$srcfile
3781e0963edeSmrg
3782e0963edeSmrgThis indicates that another process is trying to use the same
3783e0963edeSmrgtemporary object file, and libtool could not work around it because
3784b3a827e2Smrgyour compiler does not support '-c' and '-o' together.  If you
3785e0963edeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3786e0963edeSmrgavoid parallel builds (make -j) in this platform, or get a better
3787e0963edeSmrgcompiler."
3788e0963edeSmrg
3789f05b35a2Smrg	$opt_dry_run || $RM $removelist
3790e0963edeSmrg	exit $EXIT_FAILURE
3791e0963edeSmrg      fi
3792e0963edeSmrg
3793e0963edeSmrg      # Just move the object if needed, then go on to compile the next one
3794e0963edeSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3795f05b35a2Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3796f05b35a2Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797e0963edeSmrg      fi
3798e0963edeSmrg
3799e0963edeSmrg      # Allow error messages only from the first compilation.
3800b3a827e2Smrg      if test yes = "$suppress_opt"; then
3801f05b35a2Smrg	suppress_output=' >/dev/null 2>&1'
3802e0963edeSmrg      fi
3803e0963edeSmrg    fi
3804e0963edeSmrg
3805e0963edeSmrg    # Only build a position-dependent object if we build old libraries.
3806b3a827e2Smrg    if test yes = "$build_old_libs"; then
3807b3a827e2Smrg      if test yes != "$pic_mode"; then
3808e0963edeSmrg	# Don't build PIC code
3809f05b35a2Smrg	command="$base_compile $qsrcfile$pie_flag"
3810e0963edeSmrg      else
3811e0963edeSmrg	command="$base_compile $qsrcfile $pic_flag"
3812e0963edeSmrg      fi
3813b3a827e2Smrg      if test yes = "$compiler_c_o"; then
381467ab2ff2Smrg	func_append command " -o $obj"
3815e0963edeSmrg      fi
3816e0963edeSmrg
3817e0963edeSmrg      # Suppress compiler output if we already did a PIC compilation.
381867ab2ff2Smrg      func_append command "$suppress_output"
3819f05b35a2Smrg      func_show_eval_locale "$command" \
3820f05b35a2Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821e0963edeSmrg
3822b3a827e2Smrg      if test warn = "$need_locks" &&
3823e0963edeSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3824f05b35a2Smrg	$ECHO "\
3825e0963edeSmrg*** ERROR, $lockfile contains:
3826e0963edeSmrg`cat $lockfile 2>/dev/null`
3827e0963edeSmrg
3828e0963edeSmrgbut it should contain:
3829e0963edeSmrg$srcfile
3830e0963edeSmrg
3831e0963edeSmrgThis indicates that another process is trying to use the same
3832e0963edeSmrgtemporary object file, and libtool could not work around it because
3833b3a827e2Smrgyour compiler does not support '-c' and '-o' together.  If you
3834e0963edeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3835e0963edeSmrgavoid parallel builds (make -j) in this platform, or get a better
3836e0963edeSmrgcompiler."
3837e0963edeSmrg
3838f05b35a2Smrg	$opt_dry_run || $RM $removelist
3839e0963edeSmrg	exit $EXIT_FAILURE
3840e0963edeSmrg      fi
3841e0963edeSmrg
3842e0963edeSmrg      # Just move the object if needed
3843e0963edeSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3844f05b35a2Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3845f05b35a2Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846e0963edeSmrg      fi
3847e0963edeSmrg    fi
3848e0963edeSmrg
3849f05b35a2Smrg    $opt_dry_run || {
3850f05b35a2Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851e0963edeSmrg
3852f05b35a2Smrg      # Unlock the critical section if it was locked
3853b3a827e2Smrg      if test no != "$need_locks"; then
3854f05b35a2Smrg	removelist=$lockfile
3855f05b35a2Smrg        $RM "$lockfile"
3856f05b35a2Smrg      fi
3857f05b35a2Smrg    }
3858e0963edeSmrg
3859e0963edeSmrg    exit $EXIT_SUCCESS
3860f05b35a2Smrg}
3861e0963edeSmrg
3862f05b35a2Smrg$opt_help || {
3863b3a827e2Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3864f05b35a2Smrg}
3865e0963edeSmrg
3866f05b35a2Smrgfunc_mode_help ()
3867f05b35a2Smrg{
3868f05b35a2Smrg    # We need to display help for each of the modes.
386967ab2ff2Smrg    case $opt_mode in
3870f05b35a2Smrg      "")
3871f05b35a2Smrg        # Generic help is extracted from the usage comments
3872f05b35a2Smrg        # at the start of this file.
3873f05b35a2Smrg        func_help
3874f05b35a2Smrg        ;;
3875e0963edeSmrg
3876f05b35a2Smrg      clean)
3877f05b35a2Smrg        $ECHO \
3878f05b35a2Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879e0963edeSmrg
3880f05b35a2SmrgRemove files from the build directory.
3881e0963edeSmrg
3882f05b35a2SmrgRM is the name of the program to use to delete files associated with each FILE
3883b3a827e2Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3884f05b35a2Smrgto RM.
3885e0963edeSmrg
3886f05b35a2SmrgIf FILE is a libtool library, object or program, all the files associated
3887f05b35a2Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3888f05b35a2Smrg        ;;
3889e0963edeSmrg
3890f05b35a2Smrg      compile)
3891f05b35a2Smrg      $ECHO \
3892f05b35a2Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893e0963edeSmrg
3894f05b35a2SmrgCompile a source file into a libtool library object.
3895e0963edeSmrg
3896f05b35a2SmrgThis mode accepts the following additional options:
3897e0963edeSmrg
3898f05b35a2Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3899f05b35a2Smrg  -no-suppress      do not suppress compiler output for multiple passes
390049e108a1Smrg  -prefer-pic       try to build PIC objects only
390149e108a1Smrg  -prefer-non-pic   try to build non-PIC objects only
3902b3a827e2Smrg  -shared           do not build a '.o' file suitable for static linking
3903b3a827e2Smrg  -static           only build a '.o' file suitable for static linking
3904c30f5000Smrg  -Wc,FLAG
3905c30f5000Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906e0963edeSmrg
3907b3a827e2SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3908f05b35a2Smrgfrom the given SOURCEFILE.
3909e0963edeSmrg
3910f05b35a2SmrgThe output file name is determined by removing the directory component from
3911b3a827e2SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912b3a827e2Smrglibrary object suffix, '.lo'."
3913f05b35a2Smrg        ;;
3914e0963edeSmrg
3915f05b35a2Smrg      execute)
3916f05b35a2Smrg        $ECHO \
3917f05b35a2Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918e0963edeSmrg
3919f05b35a2SmrgAutomatically set library path, then run a program.
3920e0963edeSmrg
3921f05b35a2SmrgThis mode accepts the following additional options:
3922e0963edeSmrg
3923f05b35a2Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924e0963edeSmrg
3925b3a827e2SmrgThis mode sets the library path environment variable according to '-dlopen'
3926f05b35a2Smrgflags.
3927e0963edeSmrg
3928f05b35a2SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3929f05b35a2Smrginto their corresponding uninstalled binary, and any of their required library
3930f05b35a2Smrgdirectories are added to the library path.
3931e0963edeSmrg
3932f05b35a2SmrgThen, COMMAND is executed, with ARGS as arguments."
3933f05b35a2Smrg        ;;
3934e0963edeSmrg
3935f05b35a2Smrg      finish)
3936f05b35a2Smrg        $ECHO \
3937f05b35a2Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938e0963edeSmrg
3939f05b35a2SmrgComplete the installation of libtool libraries.
3940e0963edeSmrg
3941f05b35a2SmrgEach LIBDIR is a directory that contains libtool libraries.
3942e0963edeSmrg
3943f05b35a2SmrgThe commands that this mode executes may require superuser privileges.  Use
3944b3a827e2Smrgthe '--dry-run' option if you just want to see what would be executed."
3945f05b35a2Smrg        ;;
3946e0963edeSmrg
3947f05b35a2Smrg      install)
3948f05b35a2Smrg        $ECHO \
3949f05b35a2Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950e0963edeSmrg
3951f05b35a2SmrgInstall executables or libraries.
3952e0963edeSmrg
3953f05b35a2SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954b3a827e2Smrgeither the 'install' or 'cp' program.
3955e0963edeSmrg
3956f05b35a2SmrgThe following components of INSTALL-COMMAND are treated specially:
3957e0963edeSmrg
395849e108a1Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959e0963edeSmrg
3960f05b35a2SmrgThe rest of the components are interpreted as arguments to that command (only
3961f05b35a2SmrgBSD-compatible install options are recognized)."
3962f05b35a2Smrg        ;;
3963e0963edeSmrg
3964f05b35a2Smrg      link)
3965f05b35a2Smrg        $ECHO \
3966f05b35a2Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967e0963edeSmrg
3968f05b35a2SmrgLink object files or libraries together to form another library, or to
3969f05b35a2Smrgcreate an executable program.
3970e0963edeSmrg
3971f05b35a2SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3972f05b35a2Smrga program from several object files.
3973e0963edeSmrg
3974f05b35a2SmrgThe following components of LINK-COMMAND are treated specially:
3975e0963edeSmrg
3976f05b35a2Smrg  -all-static       do not do any dynamic linking at all
3977f05b35a2Smrg  -avoid-version    do not add a version suffix if possible
397849e108a1Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397949e108a1Smrg                    libraries must be found in the PATH setting at runtime)
3980b3a827e2Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3981f05b35a2Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3982f05b35a2Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3983f05b35a2Smrg  -export-symbols SYMFILE
3984f05b35a2Smrg                    try to export only the symbols listed in SYMFILE
3985f05b35a2Smrg  -export-symbols-regex REGEX
3986f05b35a2Smrg                    try to export only the symbols matching REGEX
3987f05b35a2Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3988f05b35a2Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3989f05b35a2Smrg  -module           build a library that can dlopened
3990f05b35a2Smrg  -no-fast-install  disable the fast-install mode
3991f05b35a2Smrg  -no-install       link a not-installable executable
3992f05b35a2Smrg  -no-undefined     declare that a library does not refer to external symbols
3993f05b35a2Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994b3a827e2Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995b3a827e2Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3996f05b35a2Smrg  -precious-files-regex REGEX
3997f05b35a2Smrg                    don't remove output files matching REGEX
3998f05b35a2Smrg  -release RELEASE  specify package release information
3999f05b35a2Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4000f05b35a2Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4001f05b35a2Smrg  -shared           only do dynamic linking of libtool libraries
4002f05b35a2Smrg  -shrext SUFFIX    override the standard shared library file extension
4003f05b35a2Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4004f05b35a2Smrg  -static-libtool-libs
4005f05b35a2Smrg                    do not do any dynamic linking of libtool libraries
4006f05b35a2Smrg  -version-info CURRENT[:REVISION[:AGE]]
4007f05b35a2Smrg                    specify library version info [each variable defaults to 0]
4008f05b35a2Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400949e108a1Smrg  -Wc,FLAG
401049e108a1Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011c30f5000Smrg  -Wa,FLAG
4012c30f5000Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
401349e108a1Smrg  -Wl,FLAG
401449e108a1Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
401549e108a1Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016e0963edeSmrg
4017b3a827e2SmrgAll other options (arguments beginning with '-') are ignored.
4018e0963edeSmrg
4019b3a827e2SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4020f05b35a2Smrgtreated as uninstalled libtool libraries, other files are standard or library
4021f05b35a2Smrgobject files.
4022e0963edeSmrg
4023b3a827e2SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024b3a827e2Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4025f05b35a2Smrgrequired, except when creating a convenience library.
4026e0963edeSmrg
4027b3a827e2SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028b3a827e2Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4029e0963edeSmrg
4030b3a827e2SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4031f05b35a2Smrgis created, otherwise an executable program is created."
4032e0963edeSmrg        ;;
4033e0963edeSmrg
4034f05b35a2Smrg      uninstall)
4035f05b35a2Smrg        $ECHO \
4036f05b35a2Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037e0963edeSmrg
4038f05b35a2SmrgRemove libraries from an installation directory.
4039e0963edeSmrg
4040f05b35a2SmrgRM is the name of the program to use to delete files associated with each FILE
4041b3a827e2Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4042f05b35a2Smrgto RM.
4043e0963edeSmrg
4044f05b35a2SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4045f05b35a2SmrgOtherwise, only FILE itself is deleted using RM."
4046f05b35a2Smrg        ;;
4047e0963edeSmrg
4048f05b35a2Smrg      *)
4049b3a827e2Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
4050f05b35a2Smrg        ;;
4051f05b35a2Smrg    esac
4052e0963edeSmrg
405349e108a1Smrg    echo
4054b3a827e2Smrg    $ECHO "Try '$progname --help' for more information about other modes."
4055f05b35a2Smrg}
4056e0963edeSmrg
405749e108a1Smrg# Now that we've collected a possible --mode arg, show help if necessary
405849e108a1Smrgif $opt_help; then
4059b3a827e2Smrg  if test : = "$opt_help"; then
406049e108a1Smrg    func_mode_help
406149e108a1Smrg  else
406249e108a1Smrg    {
406349e108a1Smrg      func_help noexit
406467ab2ff2Smrg      for opt_mode in compile link execute install finish uninstall clean; do
406549e108a1Smrg	func_mode_help
406649e108a1Smrg      done
4067b3a827e2Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406849e108a1Smrg    {
406949e108a1Smrg      func_help noexit
407067ab2ff2Smrg      for opt_mode in compile link execute install finish uninstall clean; do
407149e108a1Smrg	echo
407249e108a1Smrg	func_mode_help
407349e108a1Smrg      done
407449e108a1Smrg    } |
4075b3a827e2Smrg    $SED '1d
407649e108a1Smrg      /^When reporting/,/^Report/{
407749e108a1Smrg	H
407849e108a1Smrg	d
407949e108a1Smrg      }
408049e108a1Smrg      $x
408149e108a1Smrg      /information about other modes/d
408249e108a1Smrg      /more detailed .*MODE/d
408349e108a1Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
408449e108a1Smrg  fi
408549e108a1Smrg  exit $?
408649e108a1Smrgfi
4087e0963edeSmrg
4088e0963edeSmrg
4089f05b35a2Smrg# func_mode_execute arg...
4090f05b35a2Smrgfunc_mode_execute ()
4091f05b35a2Smrg{
4092b3a827e2Smrg    $debug_cmd
4093b3a827e2Smrg
4094f05b35a2Smrg    # The first argument is the command name.
4095b3a827e2Smrg    cmd=$nonopt
4096f05b35a2Smrg    test -z "$cmd" && \
4097f05b35a2Smrg      func_fatal_help "you must specify a COMMAND"
4098e0963edeSmrg
4099f05b35a2Smrg    # Handle -dlopen flags immediately.
410067ab2ff2Smrg    for file in $opt_dlopen; do
4101f05b35a2Smrg      test -f "$file" \
4102b3a827e2Smrg	|| func_fatal_help "'$file' is not a file"
4103e0963edeSmrg
4104f05b35a2Smrg      dir=
4105f05b35a2Smrg      case $file in
4106f05b35a2Smrg      *.la)
410767ab2ff2Smrg	func_resolve_sysroot "$file"
410867ab2ff2Smrg	file=$func_resolve_sysroot_result
410967ab2ff2Smrg
4110f05b35a2Smrg	# Check to see that this really is a libtool archive.
4111f05b35a2Smrg	func_lalib_unsafe_p "$file" \
4112b3a827e2Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113e0963edeSmrg
4114f05b35a2Smrg	# Read the libtool library.
4115f05b35a2Smrg	dlname=
4116f05b35a2Smrg	library_names=
4117f05b35a2Smrg	func_source "$file"
4118e0963edeSmrg
4119f05b35a2Smrg	# Skip this library if it cannot be dlopened.
4120f05b35a2Smrg	if test -z "$dlname"; then
4121f05b35a2Smrg	  # Warn if it was a shared library.
4122f05b35a2Smrg	  test -n "$library_names" && \
4123b3a827e2Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4124f05b35a2Smrg	  continue
4125f05b35a2Smrg	fi
4126e0963edeSmrg
4127f05b35a2Smrg	func_dirname "$file" "" "."
4128b3a827e2Smrg	dir=$func_dirname_result
4129e0963edeSmrg
4130f05b35a2Smrg	if test -f "$dir/$objdir/$dlname"; then
413167ab2ff2Smrg	  func_append dir "/$objdir"
4132f05b35a2Smrg	else
4133f05b35a2Smrg	  if test ! -f "$dir/$dlname"; then
4134b3a827e2Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4135f05b35a2Smrg	  fi
4136f05b35a2Smrg	fi
4137e0963edeSmrg	;;
4138e0963edeSmrg
4139f05b35a2Smrg      *.lo)
4140f05b35a2Smrg	# Just add the directory containing the .lo file.
4141f05b35a2Smrg	func_dirname "$file" "" "."
4142b3a827e2Smrg	dir=$func_dirname_result
4143e0963edeSmrg	;;
4144e0963edeSmrg
4145f05b35a2Smrg      *)
4146b3a827e2Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147e0963edeSmrg	continue
4148e0963edeSmrg	;;
4149f05b35a2Smrg      esac
4150e0963edeSmrg
4151f05b35a2Smrg      # Get the absolute pathname.
4152f05b35a2Smrg      absdir=`cd "$dir" && pwd`
4153b3a827e2Smrg      test -n "$absdir" && dir=$absdir
4154e0963edeSmrg
4155f05b35a2Smrg      # Now add the directory to shlibpath_var.
4156f05b35a2Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4157f05b35a2Smrg	eval "$shlibpath_var=\"\$dir\""
4158f05b35a2Smrg      else
4159f05b35a2Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160f05b35a2Smrg      fi
4161f05b35a2Smrg    done
4162e0963edeSmrg
4163f05b35a2Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4164f05b35a2Smrg    # rather than running their programs.
4165b3a827e2Smrg    libtool_execute_magic=$magic
4166e0963edeSmrg
4167f05b35a2Smrg    # Check if any of the arguments is a wrapper script.
4168f05b35a2Smrg    args=
4169f05b35a2Smrg    for file
4170f05b35a2Smrg    do
4171f05b35a2Smrg      case $file in
417249e108a1Smrg      -* | *.la | *.lo ) ;;
4173f05b35a2Smrg      *)
4174f05b35a2Smrg	# Do a test to see if this is really a libtool program.
4175f05b35a2Smrg	if func_ltwrapper_script_p "$file"; then
4176f05b35a2Smrg	  func_source "$file"
4177f05b35a2Smrg	  # Transform arg to wrapped name.
4178b3a827e2Smrg	  file=$progdir/$program
4179f05b35a2Smrg	elif func_ltwrapper_executable_p "$file"; then
4180f05b35a2Smrg	  func_ltwrapper_scriptname "$file"
4181f05b35a2Smrg	  func_source "$func_ltwrapper_scriptname_result"
4182f05b35a2Smrg	  # Transform arg to wrapped name.
4183b3a827e2Smrg	  file=$progdir/$program
4184f05b35a2Smrg	fi
4185f05b35a2Smrg	;;
4186f05b35a2Smrg      esac
4187f05b35a2Smrg      # Quote arguments (to preserve shell metacharacters).
418867ab2ff2Smrg      func_append_quoted args "$file"
4189f05b35a2Smrg    done
4190e0963edeSmrg
4191b3a827e2Smrg    if $opt_dry_run; then
4192b3a827e2Smrg      # Display what would be done.
4193b3a827e2Smrg      if test -n "$shlibpath_var"; then
4194b3a827e2Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195b3a827e2Smrg	echo "export $shlibpath_var"
4196b3a827e2Smrg      fi
4197b3a827e2Smrg      $ECHO "$cmd$args"
4198b3a827e2Smrg      exit $EXIT_SUCCESS
4199b3a827e2Smrg    else
4200f05b35a2Smrg      if test -n "$shlibpath_var"; then
4201f05b35a2Smrg	# Export the shlibpath_var.
4202f05b35a2Smrg	eval "export $shlibpath_var"
4203f05b35a2Smrg      fi
4204e0963edeSmrg
4205f05b35a2Smrg      # Restore saved environment variables
4206f05b35a2Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4207f05b35a2Smrg      do
4208f05b35a2Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4209f05b35a2Smrg                $lt_var=\$save_$lt_var; export $lt_var
4210e0963edeSmrg	      else
4211f05b35a2Smrg		$lt_unset $lt_var
4212f05b35a2Smrg	      fi"
4213f05b35a2Smrg      done
4214e0963edeSmrg
4215f05b35a2Smrg      # Now prepare to actually exec the command.
4216b3a827e2Smrg      exec_cmd=\$cmd$args
4217f05b35a2Smrg    fi
4218f05b35a2Smrg}
4219e0963edeSmrg
4220b3a827e2Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221e0963edeSmrg
4222e0963edeSmrg
4223f05b35a2Smrg# func_mode_finish arg...
4224f05b35a2Smrgfunc_mode_finish ()
4225f05b35a2Smrg{
4226b3a827e2Smrg    $debug_cmd
4227b3a827e2Smrg
422867ab2ff2Smrg    libs=
422967ab2ff2Smrg    libdirs=
4230f05b35a2Smrg    admincmds=
4231e0963edeSmrg
423267ab2ff2Smrg    for opt in "$nonopt" ${1+"$@"}
423367ab2ff2Smrg    do
423467ab2ff2Smrg      if test -d "$opt"; then
423567ab2ff2Smrg	func_append libdirs " $opt"
423667ab2ff2Smrg
423767ab2ff2Smrg      elif test -f "$opt"; then
423867ab2ff2Smrg	if func_lalib_unsafe_p "$opt"; then
423967ab2ff2Smrg	  func_append libs " $opt"
424067ab2ff2Smrg	else
4241b3a827e2Smrg	  func_warning "'$opt' is not a valid libtool archive"
424267ab2ff2Smrg	fi
424367ab2ff2Smrg
424467ab2ff2Smrg      else
4245b3a827e2Smrg	func_fatal_error "invalid argument '$opt'"
424667ab2ff2Smrg      fi
424767ab2ff2Smrg    done
424867ab2ff2Smrg
424967ab2ff2Smrg    if test -n "$libs"; then
425067ab2ff2Smrg      if test -n "$lt_sysroot"; then
425167ab2ff2Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
425267ab2ff2Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
425367ab2ff2Smrg      else
425467ab2ff2Smrg        sysroot_cmd=
425567ab2ff2Smrg      fi
425667ab2ff2Smrg
425767ab2ff2Smrg      # Remove sysroot references
425867ab2ff2Smrg      if $opt_dry_run; then
425967ab2ff2Smrg        for lib in $libs; do
4260b3a827e2Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
426167ab2ff2Smrg        done
426267ab2ff2Smrg      else
426367ab2ff2Smrg        tmpdir=`func_mktempdir`
426467ab2ff2Smrg        for lib in $libs; do
4265b3a827e2Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
426667ab2ff2Smrg	    > $tmpdir/tmp-la
426767ab2ff2Smrg	  mv -f $tmpdir/tmp-la $lib
426867ab2ff2Smrg	done
426967ab2ff2Smrg        ${RM}r "$tmpdir"
427067ab2ff2Smrg      fi
427167ab2ff2Smrg    fi
4272e0963edeSmrg
427367ab2ff2Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4274f05b35a2Smrg      for libdir in $libdirs; do
4275f05b35a2Smrg	if test -n "$finish_cmds"; then
4276f05b35a2Smrg	  # Do each command in the finish commands.
4277f05b35a2Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4278f05b35a2Smrg'"$cmd"'"'
4279e0963edeSmrg	fi
4280f05b35a2Smrg	if test -n "$finish_eval"; then
4281f05b35a2Smrg	  # Do the single finish_eval.
4282f05b35a2Smrg	  eval cmds=\"$finish_eval\"
428367ab2ff2Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4284f05b35a2Smrg       $cmds"
4285f05b35a2Smrg	fi
4286f05b35a2Smrg      done
4287f05b35a2Smrg    fi
4288e0963edeSmrg
4289f05b35a2Smrg    # Exit here if they wanted silent mode.
4290b3a827e2Smrg    $opt_quiet && exit $EXIT_SUCCESS
4291e0963edeSmrg
429267ab2ff2Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
429367ab2ff2Smrg      echo "----------------------------------------------------------------------"
429467ab2ff2Smrg      echo "Libraries have been installed in:"
429567ab2ff2Smrg      for libdir in $libdirs; do
429667ab2ff2Smrg	$ECHO "   $libdir"
429767ab2ff2Smrg      done
429867ab2ff2Smrg      echo
429967ab2ff2Smrg      echo "If you ever happen to want to link against installed libraries"
430067ab2ff2Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301b3a827e2Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
430267ab2ff2Smrg      echo "flag during linking and do at least one of the following:"
430367ab2ff2Smrg      if test -n "$shlibpath_var"; then
4304b3a827e2Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
430567ab2ff2Smrg	echo "     during execution"
430667ab2ff2Smrg      fi
430767ab2ff2Smrg      if test -n "$runpath_var"; then
4308b3a827e2Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
430967ab2ff2Smrg	echo "     during linking"
431067ab2ff2Smrg      fi
431167ab2ff2Smrg      if test -n "$hardcode_libdir_flag_spec"; then
431267ab2ff2Smrg	libdir=LIBDIR
431367ab2ff2Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314e0963edeSmrg
4315b3a827e2Smrg	$ECHO "   - use the '$flag' linker flag"
431667ab2ff2Smrg      fi
431767ab2ff2Smrg      if test -n "$admincmds"; then
431867ab2ff2Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
431967ab2ff2Smrg      fi
432067ab2ff2Smrg      if test -f /etc/ld.so.conf; then
4321b3a827e2Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
432267ab2ff2Smrg      fi
432367ab2ff2Smrg      echo
4324f05b35a2Smrg
432567ab2ff2Smrg      echo "See any operating system documentation about shared libraries for"
432667ab2ff2Smrg      case $host in
432767ab2ff2Smrg	solaris2.[6789]|solaris2.1[0-9])
432867ab2ff2Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
432967ab2ff2Smrg	  echo "pages."
433067ab2ff2Smrg	  ;;
433167ab2ff2Smrg	*)
433267ab2ff2Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
433367ab2ff2Smrg	  ;;
433467ab2ff2Smrg      esac
433567ab2ff2Smrg      echo "----------------------------------------------------------------------"
433667ab2ff2Smrg    fi
4337f05b35a2Smrg    exit $EXIT_SUCCESS
4338f05b35a2Smrg}
4339f05b35a2Smrg
4340b3a827e2Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341f05b35a2Smrg
4342f05b35a2Smrg
4343f05b35a2Smrg# func_mode_install arg...
4344f05b35a2Smrgfunc_mode_install ()
4345f05b35a2Smrg{
4346b3a827e2Smrg    $debug_cmd
4347b3a827e2Smrg
4348f05b35a2Smrg    # There may be an optional sh(1) argument at the beginning of
4349f05b35a2Smrg    # install_prog (especially on Windows NT).
4350b3a827e2Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4351f05b35a2Smrg       # Allow the use of GNU shtool's install command.
4352b3a827e2Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4353b3a827e2Smrg    then
4354f05b35a2Smrg      # Aesthetically quote it.
4355c30f5000Smrg      func_quote_arg pretty "$nonopt"
4356c30f5000Smrg      install_prog="$func_quote_arg_result "
4357f05b35a2Smrg      arg=$1
4358f05b35a2Smrg      shift
4359f05b35a2Smrg    else
4360f05b35a2Smrg      install_prog=
4361f05b35a2Smrg      arg=$nonopt
4362f05b35a2Smrg    fi
4363f05b35a2Smrg
4364f05b35a2Smrg    # The real first argument should be the name of the installation program.
4365f05b35a2Smrg    # Aesthetically quote it.
4366c30f5000Smrg    func_quote_arg pretty "$arg"
4367c30f5000Smrg    func_append install_prog "$func_quote_arg_result"
436849e108a1Smrg    install_shared_prog=$install_prog
436949e108a1Smrg    case " $install_prog " in
437049e108a1Smrg      *[\\\ /]cp\ *) install_cp=: ;;
437149e108a1Smrg      *) install_cp=false ;;
437249e108a1Smrg    esac
4373f05b35a2Smrg
4374f05b35a2Smrg    # We need to accept at least all the BSD install flags.
4375f05b35a2Smrg    dest=
4376f05b35a2Smrg    files=
4377f05b35a2Smrg    opts=
4378f05b35a2Smrg    prev=
4379f05b35a2Smrg    install_type=
4380b3a827e2Smrg    isdir=false
4381f05b35a2Smrg    stripme=
438249e108a1Smrg    no_mode=:
4383f05b35a2Smrg    for arg
4384f05b35a2Smrg    do
438549e108a1Smrg      arg2=
4386f05b35a2Smrg      if test -n "$dest"; then
438767ab2ff2Smrg	func_append files " $dest"
4388f05b35a2Smrg	dest=$arg
4389f05b35a2Smrg	continue
4390f05b35a2Smrg      fi
4391f05b35a2Smrg
4392f05b35a2Smrg      case $arg in
4393b3a827e2Smrg      -d) isdir=: ;;
4394f05b35a2Smrg      -f)
439549e108a1Smrg	if $install_cp; then :; else
439649e108a1Smrg	  prev=$arg
439749e108a1Smrg	fi
4398f05b35a2Smrg	;;
4399f05b35a2Smrg      -g | -m | -o)
4400f05b35a2Smrg	prev=$arg
4401f05b35a2Smrg	;;
4402f05b35a2Smrg      -s)
4403f05b35a2Smrg	stripme=" -s"
4404f05b35a2Smrg	continue
4405f05b35a2Smrg	;;
4406f05b35a2Smrg      -*)
4407f05b35a2Smrg	;;
4408f05b35a2Smrg      *)
4409f05b35a2Smrg	# If the previous option needed an argument, then skip it.
4410f05b35a2Smrg	if test -n "$prev"; then
4411b3a827e2Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
441249e108a1Smrg	    arg2=$install_override_mode
441349e108a1Smrg	    no_mode=false
441449e108a1Smrg	  fi
4415e0963edeSmrg	  prev=
4416e0963edeSmrg	else
4417f05b35a2Smrg	  dest=$arg
4418f05b35a2Smrg	  continue
4419e0963edeSmrg	fi
4420e0963edeSmrg	;;
4421f05b35a2Smrg      esac
4422e0963edeSmrg
4423f05b35a2Smrg      # Aesthetically quote the argument.
4424c30f5000Smrg      func_quote_arg pretty "$arg"
4425c30f5000Smrg      func_append install_prog " $func_quote_arg_result"
442649e108a1Smrg      if test -n "$arg2"; then
4427c30f5000Smrg	func_quote_arg pretty "$arg2"
442849e108a1Smrg      fi
4429c30f5000Smrg      func_append install_shared_prog " $func_quote_arg_result"
4430f05b35a2Smrg    done
4431e0963edeSmrg
4432f05b35a2Smrg    test -z "$install_prog" && \
4433f05b35a2Smrg      func_fatal_help "you must specify an install program"
4434e0963edeSmrg
4435f05b35a2Smrg    test -n "$prev" && \
4436b3a827e2Smrg      func_fatal_help "the '$prev' option requires an argument"
4437e0963edeSmrg
443849e108a1Smrg    if test -n "$install_override_mode" && $no_mode; then
443949e108a1Smrg      if $install_cp; then :; else
4440c30f5000Smrg	func_quote_arg pretty "$install_override_mode"
4441c30f5000Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
444249e108a1Smrg      fi
444349e108a1Smrg    fi
444449e108a1Smrg
4445f05b35a2Smrg    if test -z "$files"; then
4446f05b35a2Smrg      if test -z "$dest"; then
4447f05b35a2Smrg	func_fatal_help "no file or destination specified"
4448f05b35a2Smrg      else
4449f05b35a2Smrg	func_fatal_help "you must specify a destination"
4450f05b35a2Smrg      fi
4451e0963edeSmrg    fi
4452e0963edeSmrg
4453f05b35a2Smrg    # Strip any trailing slash from the destination.
4454f05b35a2Smrg    func_stripname '' '/' "$dest"
4455f05b35a2Smrg    dest=$func_stripname_result
4456e0963edeSmrg
4457f05b35a2Smrg    # Check to see that the destination is a directory.
4458b3a827e2Smrg    test -d "$dest" && isdir=:
4459b3a827e2Smrg    if $isdir; then
4460b3a827e2Smrg      destdir=$dest
4461f05b35a2Smrg      destname=
4462e0963edeSmrg    else
4463f05b35a2Smrg      func_dirname_and_basename "$dest" "" "."
4464b3a827e2Smrg      destdir=$func_dirname_result
4465b3a827e2Smrg      destname=$func_basename_result
4466e0963edeSmrg
4467f05b35a2Smrg      # Not a directory, so check to see that there is only one file specified.
4468f05b35a2Smrg      set dummy $files; shift
4469f05b35a2Smrg      test "$#" -gt 1 && \
4470b3a827e2Smrg	func_fatal_help "'$dest' is not a directory"
4471e0963edeSmrg    fi
4472f05b35a2Smrg    case $destdir in
4473f05b35a2Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474e0963edeSmrg    *)
4475f05b35a2Smrg      for file in $files; do
4476f05b35a2Smrg	case $file in
4477f05b35a2Smrg	*.lo) ;;
4478f05b35a2Smrg	*)
4479b3a827e2Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4480f05b35a2Smrg	  ;;
4481f05b35a2Smrg	esac
4482f05b35a2Smrg      done
4483e0963edeSmrg      ;;
4484e0963edeSmrg    esac
4485e0963edeSmrg
4486f05b35a2Smrg    # This variable tells wrapper scripts just to set variables rather
4487f05b35a2Smrg    # than running their programs.
4488b3a827e2Smrg    libtool_install_magic=$magic
4489e0963edeSmrg
4490f05b35a2Smrg    staticlibs=
4491f05b35a2Smrg    future_libdirs=
4492f05b35a2Smrg    current_libdirs=
4493f05b35a2Smrg    for file in $files; do
4494e0963edeSmrg
4495f05b35a2Smrg      # Do each installation.
4496f05b35a2Smrg      case $file in
4497f05b35a2Smrg      *.$libext)
4498f05b35a2Smrg	# Do the static libraries later.
449967ab2ff2Smrg	func_append staticlibs " $file"
4500f05b35a2Smrg	;;
4501f05b35a2Smrg
4502f05b35a2Smrg      *.la)
450367ab2ff2Smrg	func_resolve_sysroot "$file"
450467ab2ff2Smrg	file=$func_resolve_sysroot_result
450567ab2ff2Smrg
4506f05b35a2Smrg	# Check to see that this really is a libtool archive.
4507f05b35a2Smrg	func_lalib_unsafe_p "$file" \
4508b3a827e2Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4509f05b35a2Smrg
4510f05b35a2Smrg	library_names=
4511f05b35a2Smrg	old_library=
4512f05b35a2Smrg	relink_command=
4513f05b35a2Smrg	func_source "$file"
4514f05b35a2Smrg
4515f05b35a2Smrg	# Add the libdir to current_libdirs if it is the destination.
4516f05b35a2Smrg	if test "X$destdir" = "X$libdir"; then
4517f05b35a2Smrg	  case "$current_libdirs " in
4518f05b35a2Smrg	  *" $libdir "*) ;;
451967ab2ff2Smrg	  *) func_append current_libdirs " $libdir" ;;
4520e0963edeSmrg	  esac
4521f05b35a2Smrg	else
4522f05b35a2Smrg	  # Note the libdir as a future libdir.
4523f05b35a2Smrg	  case "$future_libdirs " in
4524f05b35a2Smrg	  *" $libdir "*) ;;
452567ab2ff2Smrg	  *) func_append future_libdirs " $libdir" ;;
4526f05b35a2Smrg	  esac
4527f05b35a2Smrg	fi
4528e0963edeSmrg
4529f05b35a2Smrg	func_dirname "$file" "/" ""
4530b3a827e2Smrg	dir=$func_dirname_result
453167ab2ff2Smrg	func_append dir "$objdir"
4532f05b35a2Smrg
4533f05b35a2Smrg	if test -n "$relink_command"; then
4534f05b35a2Smrg	  # Determine the prefix the user has applied to our future dir.
453549e108a1Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536f05b35a2Smrg
4537f05b35a2Smrg	  # Don't allow the user to place us outside of our expected
4538f05b35a2Smrg	  # location b/c this prevents finding dependent libraries that
4539f05b35a2Smrg	  # are installed to the same prefix.
4540f05b35a2Smrg	  # At present, this check doesn't affect windows .dll's that
4541f05b35a2Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4542f05b35a2Smrg	  # but it's something to keep an eye on.
4543f05b35a2Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544b3a827e2Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4545f05b35a2Smrg
4546f05b35a2Smrg	  if test -n "$inst_prefix_dir"; then
4547f05b35a2Smrg	    # Stick the inst_prefix_dir data into the link command.
454849e108a1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549f05b35a2Smrg	  else
455049e108a1Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551f05b35a2Smrg	  fi
4552f05b35a2Smrg
4553b3a827e2Smrg	  func_warning "relinking '$file'"
4554f05b35a2Smrg	  func_show_eval "$relink_command" \
4555b3a827e2Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4556f05b35a2Smrg	fi
4557f05b35a2Smrg
4558f05b35a2Smrg	# See the names of the shared library.
4559f05b35a2Smrg	set dummy $library_names; shift
4560f05b35a2Smrg	if test -n "$1"; then
4561b3a827e2Smrg	  realname=$1
4562f05b35a2Smrg	  shift
4563f05b35a2Smrg
4564b3a827e2Smrg	  srcname=$realname
4565b3a827e2Smrg	  test -n "$relink_command" && srcname=${realname}T
4566f05b35a2Smrg
4567f05b35a2Smrg	  # Install the shared library and build the symlinks.
456849e108a1Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4569f05b35a2Smrg	      'exit $?'
4570b3a827e2Smrg	  tstripme=$stripme
4571f05b35a2Smrg	  case $host_os in
4572f05b35a2Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4573f05b35a2Smrg	    case $realname in
4574f05b35a2Smrg	    *.dll.a)
4575b3a827e2Smrg	      tstripme=
4576b3a827e2Smrg	      ;;
4577b3a827e2Smrg	    esac
4578b3a827e2Smrg	    ;;
4579b3a827e2Smrg	  os2*)
4580b3a827e2Smrg	    case $realname in
4581b3a827e2Smrg	    *_dll.a)
4582b3a827e2Smrg	      tstripme=
4583f05b35a2Smrg	      ;;
4584f05b35a2Smrg	    esac
4585e0963edeSmrg	    ;;
4586e0963edeSmrg	  esac
4587f05b35a2Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4588f05b35a2Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589e0963edeSmrg	  fi
4590f05b35a2Smrg
4591f05b35a2Smrg	  if test "$#" -gt 0; then
4592f05b35a2Smrg	    # Delete the old symlinks, and create new ones.
4593b3a827e2Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4594f05b35a2Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4595f05b35a2Smrg	    # so we also need to try rm && ln -s.
4596f05b35a2Smrg	    for linkname
4597f05b35a2Smrg	    do
4598f05b35a2Smrg	      test "$linkname" != "$realname" \
4599f05b35a2Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600e0963edeSmrg	    done
4601e0963edeSmrg	  fi
4602e0963edeSmrg
4603f05b35a2Smrg	  # Do each command in the postinstall commands.
4604b3a827e2Smrg	  lib=$destdir/$realname
4605f05b35a2Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606e0963edeSmrg	fi
4607e0963edeSmrg
4608f05b35a2Smrg	# Install the pseudo-library for information purposes.
4609f05b35a2Smrg	func_basename "$file"
4610b3a827e2Smrg	name=$func_basename_result
4611b3a827e2Smrg	instname=$dir/${name}i
4612f05b35a2Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613e0963edeSmrg
4614f05b35a2Smrg	# Maybe install the static library, too.
461567ab2ff2Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616f05b35a2Smrg	;;
4617e0963edeSmrg
4618f05b35a2Smrg      *.lo)
4619f05b35a2Smrg	# Install (i.e. copy) a libtool object.
4620e0963edeSmrg
4621f05b35a2Smrg	# Figure out destination file name, if it wasn't already specified.
4622f05b35a2Smrg	if test -n "$destname"; then
4623b3a827e2Smrg	  destfile=$destdir/$destname
4624f05b35a2Smrg	else
4625f05b35a2Smrg	  func_basename "$file"
4626b3a827e2Smrg	  destfile=$func_basename_result
4627b3a827e2Smrg	  destfile=$destdir/$destfile
4628e0963edeSmrg	fi
4629e0963edeSmrg
4630f05b35a2Smrg	# Deduce the name of the destination old-style object file.
4631f05b35a2Smrg	case $destfile in
4632f05b35a2Smrg	*.lo)
4633f05b35a2Smrg	  func_lo2o "$destfile"
4634f05b35a2Smrg	  staticdest=$func_lo2o_result
4635f05b35a2Smrg	  ;;
4636f05b35a2Smrg	*.$objext)
4637b3a827e2Smrg	  staticdest=$destfile
4638f05b35a2Smrg	  destfile=
4639f05b35a2Smrg	  ;;
4640f05b35a2Smrg	*)
4641b3a827e2Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642f05b35a2Smrg	  ;;
4643f05b35a2Smrg	esac
4644e0963edeSmrg
4645f05b35a2Smrg	# Install the libtool object if requested.
4646f05b35a2Smrg	test -n "$destfile" && \
4647f05b35a2Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4648e0963edeSmrg
4649f05b35a2Smrg	# Install the old object if enabled.
4650b3a827e2Smrg	if test yes = "$build_old_libs"; then
4651f05b35a2Smrg	  # Deduce the name of the old-style object file.
4652f05b35a2Smrg	  func_lo2o "$file"
4653f05b35a2Smrg	  staticobj=$func_lo2o_result
4654f05b35a2Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655e0963edeSmrg	fi
4656f05b35a2Smrg	exit $EXIT_SUCCESS
4657f05b35a2Smrg	;;
4658e0963edeSmrg
4659f05b35a2Smrg      *)
4660f05b35a2Smrg	# Figure out destination file name, if it wasn't already specified.
4661f05b35a2Smrg	if test -n "$destname"; then
4662b3a827e2Smrg	  destfile=$destdir/$destname
4663f05b35a2Smrg	else
4664f05b35a2Smrg	  func_basename "$file"
4665b3a827e2Smrg	  destfile=$func_basename_result
4666b3a827e2Smrg	  destfile=$destdir/$destfile
4667f05b35a2Smrg	fi
4668e0963edeSmrg
4669f05b35a2Smrg	# If the file is missing, and there is a .exe on the end, strip it
4670f05b35a2Smrg	# because it is most likely a libtool script we actually want to
4671f05b35a2Smrg	# install
4672b3a827e2Smrg	stripped_ext=
4673f05b35a2Smrg	case $file in
4674f05b35a2Smrg	  *.exe)
4675f05b35a2Smrg	    if test ! -f "$file"; then
4676f05b35a2Smrg	      func_stripname '' '.exe' "$file"
4677f05b35a2Smrg	      file=$func_stripname_result
4678b3a827e2Smrg	      stripped_ext=.exe
4679f05b35a2Smrg	    fi
4680f05b35a2Smrg	    ;;
4681f05b35a2Smrg	esac
4682f05b35a2Smrg
4683f05b35a2Smrg	# Do a test to see if this is really a libtool program.
4684f05b35a2Smrg	case $host in
4685f05b35a2Smrg	*cygwin* | *mingw*)
4686f05b35a2Smrg	    if func_ltwrapper_executable_p "$file"; then
4687f05b35a2Smrg	      func_ltwrapper_scriptname "$file"
4688f05b35a2Smrg	      wrapper=$func_ltwrapper_scriptname_result
4689f05b35a2Smrg	    else
4690f05b35a2Smrg	      func_stripname '' '.exe' "$file"
4691f05b35a2Smrg	      wrapper=$func_stripname_result
4692f05b35a2Smrg	    fi
4693f05b35a2Smrg	    ;;
4694e0963edeSmrg	*)
4695f05b35a2Smrg	    wrapper=$file
4696f05b35a2Smrg	    ;;
4697f05b35a2Smrg	esac
4698f05b35a2Smrg	if func_ltwrapper_script_p "$wrapper"; then
4699f05b35a2Smrg	  notinst_deplibs=
4700f05b35a2Smrg	  relink_command=
4701f05b35a2Smrg
4702f05b35a2Smrg	  func_source "$wrapper"
4703f05b35a2Smrg
4704f05b35a2Smrg	  # Check the variables that should have been set.
4705f05b35a2Smrg	  test -z "$generated_by_libtool_version" && \
4706b3a827e2Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707f05b35a2Smrg
4708b3a827e2Smrg	  finalize=:
4709f05b35a2Smrg	  for lib in $notinst_deplibs; do
4710f05b35a2Smrg	    # Check to see that each library is installed.
4711f05b35a2Smrg	    libdir=
4712f05b35a2Smrg	    if test -f "$lib"; then
4713f05b35a2Smrg	      func_source "$lib"
4714f05b35a2Smrg	    fi
4715b3a827e2Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4716f05b35a2Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717b3a827e2Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718b3a827e2Smrg	      finalize=false
4719f05b35a2Smrg	    fi
4720f05b35a2Smrg	  done
4721f05b35a2Smrg
4722f05b35a2Smrg	  relink_command=
4723f05b35a2Smrg	  func_source "$wrapper"
4724f05b35a2Smrg
4725f05b35a2Smrg	  outputname=
4726b3a827e2Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4727f05b35a2Smrg	    $opt_dry_run || {
4728b3a827e2Smrg	      if $finalize; then
4729f05b35a2Smrg	        tmpdir=`func_mktempdir`
4730f05b35a2Smrg		func_basename "$file$stripped_ext"
4731b3a827e2Smrg		file=$func_basename_result
4732b3a827e2Smrg	        outputname=$tmpdir/$file
4733f05b35a2Smrg	        # Replace the output file specification.
473449e108a1Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4735f05b35a2Smrg
4736b3a827e2Smrg	        $opt_quiet || {
4737c30f5000Smrg	          func_quote_arg expand,pretty "$relink_command"
4738c30f5000Smrg		  eval "func_echo $func_quote_arg_result"
4739f05b35a2Smrg	        }
4740f05b35a2Smrg	        if eval "$relink_command"; then :
4741f05b35a2Smrg	          else
4742b3a827e2Smrg		  func_error "error: relink '$file' with the above command before installing it"
4743f05b35a2Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4744f05b35a2Smrg		  continue
4745f05b35a2Smrg	        fi
4746b3a827e2Smrg	        file=$outputname
4747f05b35a2Smrg	      else
4748b3a827e2Smrg	        func_warning "cannot relink '$file'"
4749f05b35a2Smrg	      fi
4750f05b35a2Smrg	    }
4751f05b35a2Smrg	  else
4752f05b35a2Smrg	    # Install the binary that we compiled earlier.
475349e108a1Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754e0963edeSmrg	  fi
4755f05b35a2Smrg	fi
4756f05b35a2Smrg
4757f05b35a2Smrg	# remove .exe since cygwin /usr/bin/install will append another
4758f05b35a2Smrg	# one anyway
4759f05b35a2Smrg	case $install_prog,$host in
4760f05b35a2Smrg	*/usr/bin/install*,*cygwin*)
4761f05b35a2Smrg	  case $file:$destfile in
4762f05b35a2Smrg	  *.exe:*.exe)
4763f05b35a2Smrg	    # this is ok
4764f05b35a2Smrg	    ;;
4765f05b35a2Smrg	  *.exe:*)
4766f05b35a2Smrg	    destfile=$destfile.exe
4767f05b35a2Smrg	    ;;
4768f05b35a2Smrg	  *:*.exe)
4769f05b35a2Smrg	    func_stripname '' '.exe' "$destfile"
4770f05b35a2Smrg	    destfile=$func_stripname_result
4771f05b35a2Smrg	    ;;
4772f05b35a2Smrg	  esac
4773e0963edeSmrg	  ;;
4774e0963edeSmrg	esac
4775f05b35a2Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4776f05b35a2Smrg	$opt_dry_run || if test -n "$outputname"; then
4777f05b35a2Smrg	  ${RM}r "$tmpdir"
4778f05b35a2Smrg	fi
4779f05b35a2Smrg	;;
4780f05b35a2Smrg      esac
4781f05b35a2Smrg    done
4782e0963edeSmrg
4783f05b35a2Smrg    for file in $staticlibs; do
4784f05b35a2Smrg      func_basename "$file"
4785b3a827e2Smrg      name=$func_basename_result
4786f05b35a2Smrg
4787f05b35a2Smrg      # Set up the ranlib parameters.
4788b3a827e2Smrg      oldlib=$destdir/$name
4789e494fffdSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790e494fffdSmrg      tool_oldlib=$func_to_tool_file_result
4791f05b35a2Smrg
4792f05b35a2Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4793f05b35a2Smrg
4794f05b35a2Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795e494fffdSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796f05b35a2Smrg      fi
4797f05b35a2Smrg
4798f05b35a2Smrg      # Do each command in the postinstall commands.
4799f05b35a2Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4800f05b35a2Smrg    done
4801f05b35a2Smrg
4802f05b35a2Smrg    test -n "$future_libdirs" && \
4803b3a827e2Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804f05b35a2Smrg
4805f05b35a2Smrg    if test -n "$current_libdirs"; then
4806f05b35a2Smrg      # Maybe just do a dry run.
4807f05b35a2Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808b3a827e2Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4809f05b35a2Smrg    else
4810f05b35a2Smrg      exit $EXIT_SUCCESS
4811f05b35a2Smrg    fi
4812f05b35a2Smrg}
4813f05b35a2Smrg
4814b3a827e2Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815f05b35a2Smrg
4816f05b35a2Smrg
4817f05b35a2Smrg# func_generate_dlsyms outputname originator pic_p
4818f05b35a2Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4819f05b35a2Smrg# a dlpreopen symbol table.
4820f05b35a2Smrgfunc_generate_dlsyms ()
4821f05b35a2Smrg{
4822b3a827e2Smrg    $debug_cmd
4823b3a827e2Smrg
4824b3a827e2Smrg    my_outputname=$1
4825b3a827e2Smrg    my_originator=$2
4826b3a827e2Smrg    my_pic_p=${3-false}
4827b3a827e2Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4828f05b35a2Smrg    my_dlsyms=
4829f05b35a2Smrg
4830b3a827e2Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4831f05b35a2Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832b3a827e2Smrg	my_dlsyms=${my_outputname}S.c
4833f05b35a2Smrg      else
4834f05b35a2Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4835f05b35a2Smrg      fi
4836f05b35a2Smrg    fi
4837f05b35a2Smrg
4838f05b35a2Smrg    if test -n "$my_dlsyms"; then
4839f05b35a2Smrg      case $my_dlsyms in
4840f05b35a2Smrg      "") ;;
4841f05b35a2Smrg      *.c)
4842f05b35a2Smrg	# Discover the nlist of each of the dlfiles.
4843b3a827e2Smrg	nlist=$output_objdir/$my_outputname.nm
4844f05b35a2Smrg
4845f05b35a2Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846f05b35a2Smrg
4847f05b35a2Smrg	# Parse the name list into a source file.
4848f05b35a2Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849f05b35a2Smrg
4850f05b35a2Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851b3a827e2Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852b3a827e2Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853f05b35a2Smrg
4854f05b35a2Smrg#ifdef __cplusplus
4855f05b35a2Smrgextern \"C\" {
4856f05b35a2Smrg#endif
4857f05b35a2Smrg
4858b3a827e2Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485949e108a1Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
486049e108a1Smrg#endif
486149e108a1Smrg
486267ab2ff2Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863b3a827e2Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864b3a827e2Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
486567ab2ff2Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
486667ab2ff2Smrg# define LT_DLSYM_CONST
4867b3a827e2Smrg#elif defined __osf__
486867ab2ff2Smrg/* This system does not cope well with relocations in const data.  */
486967ab2ff2Smrg# define LT_DLSYM_CONST
487067ab2ff2Smrg#else
487167ab2ff2Smrg# define LT_DLSYM_CONST const
487267ab2ff2Smrg#endif
487367ab2ff2Smrg
4874b3a827e2Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875b3a827e2Smrg
4876f05b35a2Smrg/* External symbol declarations for the compiler. */\
4877f05b35a2Smrg"
4878f05b35a2Smrg
4879b3a827e2Smrg	if test yes = "$dlself"; then
4880b3a827e2Smrg	  func_verbose "generating symbol list for '$output'"
4881f05b35a2Smrg
4882f05b35a2Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4883f05b35a2Smrg
4884f05b35a2Smrg	  # Add our own program objects to the symbol list.
488549e108a1Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4886f05b35a2Smrg	  for progfile in $progfiles; do
488767ab2ff2Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888b3a827e2Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
488967ab2ff2Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890f05b35a2Smrg	  done
4891f05b35a2Smrg
4892f05b35a2Smrg	  if test -n "$exclude_expsyms"; then
4893f05b35a2Smrg	    $opt_dry_run || {
4894f05b35a2Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4895f05b35a2Smrg	      eval '$MV "$nlist"T "$nlist"'
4896f05b35a2Smrg	    }
4897e0963edeSmrg	  fi
4898f05b35a2Smrg
4899f05b35a2Smrg	  if test -n "$export_symbols_regex"; then
4900f05b35a2Smrg	    $opt_dry_run || {
4901f05b35a2Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4902f05b35a2Smrg	      eval '$MV "$nlist"T "$nlist"'
4903f05b35a2Smrg	    }
4904f05b35a2Smrg	  fi
4905f05b35a2Smrg
4906f05b35a2Smrg	  # Prepare the list of exported symbols
4907f05b35a2Smrg	  if test -z "$export_symbols"; then
4908b3a827e2Smrg	    export_symbols=$output_objdir/$outputname.exp
4909f05b35a2Smrg	    $opt_dry_run || {
4910f05b35a2Smrg	      $RM $export_symbols
4911b3a827e2Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4912f05b35a2Smrg	      case $host in
4913f05b35a2Smrg	      *cygwin* | *mingw* | *cegcc* )
4914f05b35a2Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4915f05b35a2Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4916f05b35a2Smrg	        ;;
4917f05b35a2Smrg	      esac
4918f05b35a2Smrg	    }
4919e0963edeSmrg	  else
4920f05b35a2Smrg	    $opt_dry_run || {
4921b3a827e2Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4922f05b35a2Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4923f05b35a2Smrg	      eval '$MV "$nlist"T "$nlist"'
4924f05b35a2Smrg	      case $host in
492549e108a1Smrg	        *cygwin* | *mingw* | *cegcc* )
4926f05b35a2Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4927f05b35a2Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4928f05b35a2Smrg	          ;;
4929f05b35a2Smrg	      esac
4930f05b35a2Smrg	    }
4931e0963edeSmrg	  fi
4932f05b35a2Smrg	fi
4933e0963edeSmrg
4934f05b35a2Smrg	for dlprefile in $dlprefiles; do
4935b3a827e2Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4936f05b35a2Smrg	  func_basename "$dlprefile"
4937b3a827e2Smrg	  name=$func_basename_result
493867ab2ff2Smrg          case $host in
493967ab2ff2Smrg	    *cygwin* | *mingw* | *cegcc* )
494067ab2ff2Smrg	      # if an import library, we need to obtain dlname
494167ab2ff2Smrg	      if func_win32_import_lib_p "$dlprefile"; then
494267ab2ff2Smrg	        func_tr_sh "$dlprefile"
494367ab2ff2Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944b3a827e2Smrg	        dlprefile_dlbasename=
494567ab2ff2Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
494667ab2ff2Smrg	          # Use subshell, to avoid clobbering current variable values
494767ab2ff2Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948b3a827e2Smrg	          if test -n "$dlprefile_dlname"; then
494967ab2ff2Smrg	            func_basename "$dlprefile_dlname"
4950b3a827e2Smrg	            dlprefile_dlbasename=$func_basename_result
495167ab2ff2Smrg	          else
495267ab2ff2Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
495367ab2ff2Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
495467ab2ff2Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
495567ab2ff2Smrg	          fi
495667ab2ff2Smrg	        fi
495767ab2ff2Smrg	        $opt_dry_run || {
4958b3a827e2Smrg	          if test -n "$dlprefile_dlbasename"; then
495967ab2ff2Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
496067ab2ff2Smrg	          else
496167ab2ff2Smrg	            func_warning "Could not compute DLL name from $name"
496267ab2ff2Smrg	            eval '$ECHO ": $name " >> "$nlist"'
496367ab2ff2Smrg	          fi
496467ab2ff2Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
496567ab2ff2Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
496667ab2ff2Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
496767ab2ff2Smrg	        }
496867ab2ff2Smrg	      else # not an import lib
496967ab2ff2Smrg	        $opt_dry_run || {
497067ab2ff2Smrg	          eval '$ECHO ": $name " >> "$nlist"'
497167ab2ff2Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
497267ab2ff2Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
497367ab2ff2Smrg	        }
497467ab2ff2Smrg	      fi
497567ab2ff2Smrg	    ;;
497667ab2ff2Smrg	    *)
497767ab2ff2Smrg	      $opt_dry_run || {
497867ab2ff2Smrg	        eval '$ECHO ": $name " >> "$nlist"'
497967ab2ff2Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
498067ab2ff2Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
498167ab2ff2Smrg	      }
498267ab2ff2Smrg	    ;;
498367ab2ff2Smrg          esac
4984f05b35a2Smrg	done
4985f05b35a2Smrg
4986f05b35a2Smrg	$opt_dry_run || {
4987f05b35a2Smrg	  # Make sure we have at least an empty file.
4988f05b35a2Smrg	  test -f "$nlist" || : > "$nlist"
4989f05b35a2Smrg
4990f05b35a2Smrg	  if test -n "$exclude_expsyms"; then
4991f05b35a2Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4992f05b35a2Smrg	    $MV "$nlist"T "$nlist"
4993e0963edeSmrg	  fi
4994f05b35a2Smrg
4995f05b35a2Smrg	  # Try sorting and uniquifying the output.
4996f05b35a2Smrg	  if $GREP -v "^: " < "$nlist" |
4997f05b35a2Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4998f05b35a2Smrg		sort -k 3
4999f05b35a2Smrg	      else
5000f05b35a2Smrg		sort +2
5001f05b35a2Smrg	      fi |
5002f05b35a2Smrg	      uniq > "$nlist"S; then
5003f05b35a2Smrg	    :
5004e0963edeSmrg	  else
5005f05b35a2Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006e0963edeSmrg	  fi
5007e0963edeSmrg
5008f05b35a2Smrg	  if test -f "$nlist"S; then
5009f05b35a2Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010e0963edeSmrg	  else
501149e108a1Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012e0963edeSmrg	  fi
5013e0963edeSmrg
5014b3a827e2Smrg	  func_show_eval '$RM "${nlist}I"'
5015b3a827e2Smrg	  if test -n "$global_symbol_to_import"; then
5016b3a827e2Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017b3a827e2Smrg	  fi
5018b3a827e2Smrg
501949e108a1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020e0963edeSmrg
5021f05b35a2Smrg/* The mapping between symbol names and symbols.  */
5022f05b35a2Smrgtypedef struct {
5023f05b35a2Smrg  const char *name;
5024f05b35a2Smrg  void *address;
5025f05b35a2Smrg} lt_dlsymlist;
502667ab2ff2Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027b3a827e2Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028b3a827e2Smrg"
5029b3a827e2Smrg
5030b3a827e2Smrg	  if test -s "$nlist"I; then
5031b3a827e2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032b3a827e2Smrgstatic void lt_syminit(void)
5033b3a827e2Smrg{
5034b3a827e2Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035b3a827e2Smrg  for (; symbol->name; ++symbol)
5036b3a827e2Smrg    {"
5037b3a827e2Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038b3a827e2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039b3a827e2Smrg    }
5040b3a827e2Smrg}"
5041b3a827e2Smrg	  fi
5042b3a827e2Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
504367ab2ff2SmrgLT_DLSYM_CONST lt_dlsymlist
5044f05b35a2Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045b3a827e2Smrg{ {\"$my_originator\", (void *) 0},"
5046b3a827e2Smrg
5047b3a827e2Smrg	  if test -s "$nlist"I; then
5048b3a827e2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049b3a827e2Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5050b3a827e2Smrg	  fi
5051e0963edeSmrg
5052f05b35a2Smrg	  case $need_lib_prefix in
5053f05b35a2Smrg	  no)
5054f05b35a2Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055f05b35a2Smrg	    ;;
5056f05b35a2Smrg	  *)
5057f05b35a2Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058f05b35a2Smrg	    ;;
5059f05b35a2Smrg	  esac
506049e108a1Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5061f05b35a2Smrg  {0, (void *) 0}
5062f05b35a2Smrg};
5063e0963edeSmrg
5064f05b35a2Smrg/* This works around a problem in FreeBSD linker */
5065f05b35a2Smrg#ifdef FREEBSD_WORKAROUND
5066f05b35a2Smrgstatic const void *lt_preloaded_setup() {
5067f05b35a2Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5068f05b35a2Smrg}
5069f05b35a2Smrg#endif
5070e0963edeSmrg
5071f05b35a2Smrg#ifdef __cplusplus
5072f05b35a2Smrg}
5073f05b35a2Smrg#endif\
5074f05b35a2Smrg"
5075f05b35a2Smrg	} # !$opt_dry_run
5076e0963edeSmrg
5077f05b35a2Smrg	pic_flag_for_symtable=
5078f05b35a2Smrg	case "$compile_command " in
5079f05b35a2Smrg	*" -static "*) ;;
5080f05b35a2Smrg	*)
5081f05b35a2Smrg	  case $host in
5082f05b35a2Smrg	  # compiling the symbol table file with pic_flag works around
5083f05b35a2Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5084f05b35a2Smrg	  # linked before any other PIC object.  But we must not use
5085f05b35a2Smrg	  # pic_flag when linking with -static.  The problem exists in
5086f05b35a2Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087e494fffdSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5088f05b35a2Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5089f05b35a2Smrg	  *-*-hpux*)
5090f05b35a2Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5091f05b35a2Smrg	  *)
5092b3a827e2Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5093f05b35a2Smrg	    ;;
5094f05b35a2Smrg	  esac
5095f05b35a2Smrg	  ;;
5096f05b35a2Smrg	esac
5097f05b35a2Smrg	symtab_cflags=
5098f05b35a2Smrg	for arg in $LTCFLAGS; do
5099f05b35a2Smrg	  case $arg in
5100f05b35a2Smrg	  -pie | -fpie | -fPIE) ;;
510167ab2ff2Smrg	  *) func_append symtab_cflags " $arg" ;;
5102f05b35a2Smrg	  esac
5103f05b35a2Smrg	done
5104e0963edeSmrg
5105f05b35a2Smrg	# Now compile the dynamic symbol file.
5106f05b35a2Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107e0963edeSmrg
5108f05b35a2Smrg	# Clean up the generated files.
5109b3a827e2Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110e0963edeSmrg
5111f05b35a2Smrg	# Transform the symbol file into the correct name.
5112b3a827e2Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5113f05b35a2Smrg	case $host in
5114f05b35a2Smrg	*cygwin* | *mingw* | *cegcc* )
5115f05b35a2Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
511649e108a1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511749e108a1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5118f05b35a2Smrg	  else
511949e108a1Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512049e108a1Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121f05b35a2Smrg	  fi
5122f05b35a2Smrg	  ;;
5123f05b35a2Smrg	*)
512449e108a1Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512549e108a1Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5126f05b35a2Smrg	  ;;
5127f05b35a2Smrg	esac
5128f05b35a2Smrg	;;
5129f05b35a2Smrg      *)
5130b3a827e2Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5131f05b35a2Smrg	;;
5132f05b35a2Smrg      esac
5133f05b35a2Smrg    else
5134f05b35a2Smrg      # We keep going just in case the user didn't refer to
5135f05b35a2Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5136f05b35a2Smrg      # really was required.
5137e0963edeSmrg
5138f05b35a2Smrg      # Nullify the symbol file.
513949e108a1Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
514049e108a1Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5141f05b35a2Smrg    fi
5142f05b35a2Smrg}
5143e0963edeSmrg
5144b3a827e2Smrg# func_cygming_gnu_implib_p ARG
5145b3a827e2Smrg# This predicate returns with zero status (TRUE) if
5146b3a827e2Smrg# ARG is a GNU/binutils-style import library. Returns
5147b3a827e2Smrg# with nonzero status (FALSE) otherwise.
5148b3a827e2Smrgfunc_cygming_gnu_implib_p ()
5149b3a827e2Smrg{
5150b3a827e2Smrg  $debug_cmd
5151b3a827e2Smrg
5152b3a827e2Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153b3a827e2Smrg  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)$'`
5154b3a827e2Smrg  test -n "$func_cygming_gnu_implib_tmp"
5155b3a827e2Smrg}
5156b3a827e2Smrg
5157b3a827e2Smrg# func_cygming_ms_implib_p ARG
5158b3a827e2Smrg# This predicate returns with zero status (TRUE) if
5159b3a827e2Smrg# ARG is an MS-style import library. Returns
5160b3a827e2Smrg# with nonzero status (FALSE) otherwise.
5161b3a827e2Smrgfunc_cygming_ms_implib_p ()
5162b3a827e2Smrg{
5163b3a827e2Smrg  $debug_cmd
5164b3a827e2Smrg
5165b3a827e2Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166b3a827e2Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167b3a827e2Smrg  test -n "$func_cygming_ms_implib_tmp"
5168b3a827e2Smrg}
5169b3a827e2Smrg
5170f05b35a2Smrg# func_win32_libid arg
5171f05b35a2Smrg# return the library type of file 'arg'
5172f05b35a2Smrg#
5173f05b35a2Smrg# Need a lot of goo to handle *both* DLLs and import libs
5174f05b35a2Smrg# Has to be a shell function in order to 'eat' the argument
5175f05b35a2Smrg# that is supplied when $file_magic_command is called.
517649e108a1Smrg# Despite the name, also deal with 64 bit binaries.
5177f05b35a2Smrgfunc_win32_libid ()
5178f05b35a2Smrg{
5179b3a827e2Smrg  $debug_cmd
5180b3a827e2Smrg
5181b3a827e2Smrg  win32_libid_type=unknown
5182f05b35a2Smrg  win32_fileres=`file -L $1 2>/dev/null`
5183f05b35a2Smrg  case $win32_fileres in
5184f05b35a2Smrg  *ar\ archive\ import\ library*) # definitely import
5185f05b35a2Smrg    win32_libid_type="x86 archive import"
5186f05b35a2Smrg    ;;
5187f05b35a2Smrg  *ar\ archive*) # could be an import, or static
518849e108a1Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5189f05b35a2Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
519049e108a1Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191b3a827e2Smrg      case $nm_interface in
5192b3a827e2Smrg      "MS dumpbin")
5193b3a827e2Smrg	if func_cygming_ms_implib_p "$1" ||
5194b3a827e2Smrg	   func_cygming_gnu_implib_p "$1"
5195b3a827e2Smrg	then
5196b3a827e2Smrg	  win32_nmres=import
5197b3a827e2Smrg	else
5198b3a827e2Smrg	  win32_nmres=
5199b3a827e2Smrg	fi
5200b3a827e2Smrg	;;
5201b3a827e2Smrg      *)
5202b3a827e2Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203b3a827e2Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204b3a827e2Smrg	  $SED -n -e '
5205f05b35a2Smrg	    1,100{
5206f05b35a2Smrg		/ I /{
5207b3a827e2Smrg		    s|.*|import|
5208f05b35a2Smrg		    p
5209f05b35a2Smrg		    q
5210f05b35a2Smrg		}
5211f05b35a2Smrg	    }'`
5212b3a827e2Smrg	;;
5213b3a827e2Smrg      esac
5214f05b35a2Smrg      case $win32_nmres in
5215f05b35a2Smrg      import*)  win32_libid_type="x86 archive import";;
5216f05b35a2Smrg      *)        win32_libid_type="x86 archive static";;
5217f05b35a2Smrg      esac
5218f05b35a2Smrg    fi
5219f05b35a2Smrg    ;;
5220f05b35a2Smrg  *DLL*)
5221f05b35a2Smrg    win32_libid_type="x86 DLL"
5222f05b35a2Smrg    ;;
5223f05b35a2Smrg  *executable*) # but shell scripts are "executable" too...
5224f05b35a2Smrg    case $win32_fileres in
5225f05b35a2Smrg    *MS\ Windows\ PE\ Intel*)
5226f05b35a2Smrg      win32_libid_type="x86 DLL"
5227f05b35a2Smrg      ;;
5228f05b35a2Smrg    esac
5229f05b35a2Smrg    ;;
5230f05b35a2Smrg  esac
5231f05b35a2Smrg  $ECHO "$win32_libid_type"
5232f05b35a2Smrg}
5233e0963edeSmrg
523467ab2ff2Smrg# func_cygming_dll_for_implib ARG
523567ab2ff2Smrg#
523667ab2ff2Smrg# Platform-specific function to extract the
523767ab2ff2Smrg# name of the DLL associated with the specified
523867ab2ff2Smrg# import library ARG.
523967ab2ff2Smrg# Invoked by eval'ing the libtool variable
524067ab2ff2Smrg#    $sharedlib_from_linklib_cmd
524167ab2ff2Smrg# Result is available in the variable
524267ab2ff2Smrg#    $sharedlib_from_linklib_result
524367ab2ff2Smrgfunc_cygming_dll_for_implib ()
524467ab2ff2Smrg{
5245b3a827e2Smrg  $debug_cmd
5246b3a827e2Smrg
524767ab2ff2Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
524867ab2ff2Smrg}
524967ab2ff2Smrg
525067ab2ff2Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
525167ab2ff2Smrg#
525267ab2ff2Smrg# The is the core of a fallback implementation of a
525367ab2ff2Smrg# platform-specific function to extract the name of the
525467ab2ff2Smrg# DLL associated with the specified import library LIBNAME.
525567ab2ff2Smrg#
525667ab2ff2Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
525767ab2ff2Smrg# on the platform and compiler that created the implib.
525867ab2ff2Smrg#
525967ab2ff2Smrg# Echos the name of the DLL associated with the
526067ab2ff2Smrg# specified import library.
526167ab2ff2Smrgfunc_cygming_dll_for_implib_fallback_core ()
526267ab2ff2Smrg{
5263b3a827e2Smrg  $debug_cmd
5264b3a827e2Smrg
526567ab2ff2Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
526667ab2ff2Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
526767ab2ff2Smrg    $SED '/^Contents of section '"$match_literal"':/{
526867ab2ff2Smrg      # Place marker at beginning of archive member dllname section
526967ab2ff2Smrg      s/.*/====MARK====/
527067ab2ff2Smrg      p
527167ab2ff2Smrg      d
527267ab2ff2Smrg    }
527367ab2ff2Smrg    # These lines can sometimes be longer than 43 characters, but
527467ab2ff2Smrg    # are always uninteresting
527567ab2ff2Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
527667ab2ff2Smrg    /^In archive [^:]*:/d
527767ab2ff2Smrg    # Ensure marker is printed
527867ab2ff2Smrg    /^====MARK====/p
527967ab2ff2Smrg    # Remove all lines with less than 43 characters
528067ab2ff2Smrg    /^.\{43\}/!d
528167ab2ff2Smrg    # From remaining lines, remove first 43 characters
528267ab2ff2Smrg    s/^.\{43\}//' |
528367ab2ff2Smrg    $SED -n '
528467ab2ff2Smrg      # Join marker and all lines until next marker into a single line
528567ab2ff2Smrg      /^====MARK====/ b para
528667ab2ff2Smrg      H
528767ab2ff2Smrg      $ b para
528867ab2ff2Smrg      b
528967ab2ff2Smrg      :para
529067ab2ff2Smrg      x
529167ab2ff2Smrg      s/\n//g
529267ab2ff2Smrg      # Remove the marker
529367ab2ff2Smrg      s/^====MARK====//
529467ab2ff2Smrg      # Remove trailing dots and whitespace
529567ab2ff2Smrg      s/[\. \t]*$//
529667ab2ff2Smrg      # Print
529767ab2ff2Smrg      /./p' |
529867ab2ff2Smrg    # we now have a list, one entry per line, of the stringified
529967ab2ff2Smrg    # contents of the appropriate section of all members of the
5300b3a827e2Smrg    # archive that possess that section. Heuristic: eliminate
5301b3a827e2Smrg    # all those that have a first or second character that is
530267ab2ff2Smrg    # a '.' (that is, objdump's representation of an unprintable
530367ab2ff2Smrg    # character.) This should work for all archives with less than
530467ab2ff2Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
530567ab2ff2Smrg    # begins with a literal '.' or a single character followed by
530667ab2ff2Smrg    # a '.'.
530767ab2ff2Smrg    #
530867ab2ff2Smrg    # Of those that remain, print the first one.
530967ab2ff2Smrg    $SED -e '/^\./d;/^.\./d;q'
531067ab2ff2Smrg}
531167ab2ff2Smrg
531267ab2ff2Smrg# func_cygming_dll_for_implib_fallback ARG
531367ab2ff2Smrg# Platform-specific function to extract the
531467ab2ff2Smrg# name of the DLL associated with the specified
531567ab2ff2Smrg# import library ARG.
531667ab2ff2Smrg#
531767ab2ff2Smrg# This fallback implementation is for use when $DLLTOOL
531867ab2ff2Smrg# does not support the --identify-strict option.
531967ab2ff2Smrg# Invoked by eval'ing the libtool variable
532067ab2ff2Smrg#    $sharedlib_from_linklib_cmd
532167ab2ff2Smrg# Result is available in the variable
532267ab2ff2Smrg#    $sharedlib_from_linklib_result
532367ab2ff2Smrgfunc_cygming_dll_for_implib_fallback ()
532467ab2ff2Smrg{
5325b3a827e2Smrg  $debug_cmd
5326b3a827e2Smrg
5327b3a827e2Smrg  if func_cygming_gnu_implib_p "$1"; then
532867ab2ff2Smrg    # binutils import library
532967ab2ff2Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330b3a827e2Smrg  elif func_cygming_ms_implib_p "$1"; then
533167ab2ff2Smrg    # ms-generated import library
533267ab2ff2Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
533367ab2ff2Smrg  else
533467ab2ff2Smrg    # unknown
5335b3a827e2Smrg    sharedlib_from_linklib_result=
533667ab2ff2Smrg  fi
533767ab2ff2Smrg}
5338e0963edeSmrg
5339e0963edeSmrg
5340f05b35a2Smrg# func_extract_an_archive dir oldlib
5341f05b35a2Smrgfunc_extract_an_archive ()
5342f05b35a2Smrg{
5343b3a827e2Smrg    $debug_cmd
5344b3a827e2Smrg
5345b3a827e2Smrg    f_ex_an_ar_dir=$1; shift
5346b3a827e2Smrg    f_ex_an_ar_oldlib=$1
5347b3a827e2Smrg    if test yes = "$lock_old_archive_extraction"; then
534849e108a1Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534949e108a1Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
535049e108a1Smrg	func_echo "Waiting for $lockfile to be removed"
535149e108a1Smrg	sleep 2
535249e108a1Smrg      done
535349e108a1Smrg    fi
535449e108a1Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
535549e108a1Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356b3a827e2Smrg    if test yes = "$lock_old_archive_extraction"; then
535749e108a1Smrg      $opt_dry_run || rm -f "$lockfile"
535849e108a1Smrg    fi
5359f05b35a2Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5360f05b35a2Smrg     :
5361f05b35a2Smrg    else
5362f05b35a2Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5363f05b35a2Smrg    fi
5364f05b35a2Smrg}
5365e0963edeSmrg
5366e0963edeSmrg
5367f05b35a2Smrg# func_extract_archives gentop oldlib ...
5368f05b35a2Smrgfunc_extract_archives ()
5369f05b35a2Smrg{
5370b3a827e2Smrg    $debug_cmd
5371b3a827e2Smrg
5372b3a827e2Smrg    my_gentop=$1; shift
5373f05b35a2Smrg    my_oldlibs=${1+"$@"}
5374b3a827e2Smrg    my_oldobjs=
5375b3a827e2Smrg    my_xlib=
5376b3a827e2Smrg    my_xabs=
5377b3a827e2Smrg    my_xdir=
5378e0963edeSmrg
5379f05b35a2Smrg    for my_xlib in $my_oldlibs; do
5380f05b35a2Smrg      # Extract the objects.
5381f05b35a2Smrg      case $my_xlib in
5382b3a827e2Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5383f05b35a2Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5384f05b35a2Smrg      esac
5385f05b35a2Smrg      func_basename "$my_xlib"
5386b3a827e2Smrg      my_xlib=$func_basename_result
5387f05b35a2Smrg      my_xlib_u=$my_xlib
5388f05b35a2Smrg      while :; do
5389f05b35a2Smrg        case " $extracted_archives " in
5390f05b35a2Smrg	*" $my_xlib_u "*)
5391f05b35a2Smrg	  func_arith $extracted_serial + 1
5392f05b35a2Smrg	  extracted_serial=$func_arith_result
5393f05b35a2Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5394f05b35a2Smrg	*) break ;;
5395f05b35a2Smrg	esac
5396f05b35a2Smrg      done
5397f05b35a2Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398b3a827e2Smrg      my_xdir=$my_gentop/$my_xlib_u
5399e0963edeSmrg
5400f05b35a2Smrg      func_mkdir_p "$my_xdir"
5401f05b35a2Smrg
5402f05b35a2Smrg      case $host in
5403f05b35a2Smrg      *-darwin*)
5404f05b35a2Smrg	func_verbose "Extracting $my_xabs"
5405f05b35a2Smrg	# Do not bother doing anything if just a dry run
5406f05b35a2Smrg	$opt_dry_run || {
5407f05b35a2Smrg	  darwin_orig_dir=`pwd`
5408f05b35a2Smrg	  cd $my_xdir || exit $?
5409f05b35a2Smrg	  darwin_archive=$my_xabs
5410f05b35a2Smrg	  darwin_curdir=`pwd`
5411b3a827e2Smrg	  func_basename "$darwin_archive"
5412b3a827e2Smrg	  darwin_base_archive=$func_basename_result
5413f05b35a2Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5414f05b35a2Smrg	  if test -n "$darwin_arches"; then
5415f05b35a2Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5416f05b35a2Smrg	    darwin_arch=
5417f05b35a2Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418b3a827e2Smrg	    for darwin_arch in  $darwin_arches; do
5419b3a827e2Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420b3a827e2Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421b3a827e2Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422b3a827e2Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5423f05b35a2Smrg	      cd "$darwin_curdir"
5424b3a827e2Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5425f05b35a2Smrg	    done # $darwin_arches
5426f05b35a2Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427b3a827e2Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5428f05b35a2Smrg	    darwin_file=
5429f05b35a2Smrg	    darwin_files=
5430f05b35a2Smrg	    for darwin_file in $darwin_filelist; do
543149e108a1Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5432f05b35a2Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5433f05b35a2Smrg	    done # $darwin_filelist
5434f05b35a2Smrg	    $RM -rf unfat-$$
5435f05b35a2Smrg	    cd "$darwin_orig_dir"
5436e0963edeSmrg	  else
5437f05b35a2Smrg	    cd $darwin_orig_dir
5438f05b35a2Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5439f05b35a2Smrg	  fi # $darwin_arches
5440f05b35a2Smrg	} # !$opt_dry_run
5441f05b35a2Smrg	;;
5442f05b35a2Smrg      *)
5443f05b35a2Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5444f05b35a2Smrg	;;
5445f05b35a2Smrg      esac
544649e108a1Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5447f05b35a2Smrg    done
5448e0963edeSmrg
5449b3a827e2Smrg    func_extract_archives_result=$my_oldobjs
5450f05b35a2Smrg}
5451e0963edeSmrg
5452e0963edeSmrg
545349e108a1Smrg# func_emit_wrapper [arg=no]
545449e108a1Smrg#
545549e108a1Smrg# Emit a libtool wrapper script on stdout.
545649e108a1Smrg# Don't directly open a file because we may want to
545749e108a1Smrg# incorporate the script contents within a cygwin/mingw
545849e108a1Smrg# wrapper executable.  Must ONLY be called from within
545949e108a1Smrg# func_mode_link because it depends on a number of variables
546049e108a1Smrg# set therein.
5461f05b35a2Smrg#
546249e108a1Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
546349e108a1Smrg# variable will take.  If 'yes', then the emitted script
5464b3a827e2Smrg# will assume that the directory where it is stored is
546549e108a1Smrg# the $objdir directory.  This is a cygwin/mingw-specific
546649e108a1Smrg# behavior.
546749e108a1Smrgfunc_emit_wrapper ()
5468f05b35a2Smrg{
546949e108a1Smrg	func_emit_wrapper_arg1=${1-no}
5470e0963edeSmrg
5471f05b35a2Smrg	$ECHO "\
5472f05b35a2Smrg#! $SHELL
5473e0963edeSmrg
5474f05b35a2Smrg# $output - temporary wrapper script for $objdir/$outputname
5475b3a827e2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5476f05b35a2Smrg#
5477f05b35a2Smrg# The $output program cannot be directly executed until all the libtool
5478f05b35a2Smrg# libraries that it depends on are installed.
5479f05b35a2Smrg#
5480f05b35a2Smrg# This wrapper script should never be moved out of the build directory.
5481f05b35a2Smrg# If it is, it will not operate correctly.
5482e0963edeSmrg
5483f05b35a2Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5484f05b35a2Smrg# metacharacters that are still active within double-quoted strings.
5485f05b35a2Smrgsed_quote_subst='$sed_quote_subst'
5486e0963edeSmrg
5487f05b35a2Smrg# Be Bourne compatible
5488f05b35a2Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5489f05b35a2Smrg  emulate sh
5490f05b35a2Smrg  NULLCMD=:
5491f05b35a2Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5492f05b35a2Smrg  # is contrary to our usage.  Disable this feature.
5493f05b35a2Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5494f05b35a2Smrg  setopt NO_GLOB_SUBST
5495f05b35a2Smrgelse
5496f05b35a2Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5497f05b35a2Smrgfi
5498f05b35a2SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5499f05b35a2SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500e0963edeSmrg
5501f05b35a2Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5502f05b35a2Smrg# if CDPATH is set.
5503f05b35a2Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504e0963edeSmrg
5505f05b35a2Smrgrelink_command=\"$relink_command\"
5506e0963edeSmrg
5507f05b35a2Smrg# This environment variable determines our operation mode.
5508f05b35a2Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5509f05b35a2Smrg  # install mode needs the following variables:
5510f05b35a2Smrg  generated_by_libtool_version='$macro_version'
5511f05b35a2Smrg  notinst_deplibs='$notinst_deplibs'
5512f05b35a2Smrgelse
5513f05b35a2Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5514f05b35a2Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
551549e108a1Smrg    file=\"\$0\""
551649e108a1Smrg
5517c30f5000Smrg    func_quote_arg pretty "$ECHO"
5518c30f5000Smrg    qECHO=$func_quote_arg_result
551949e108a1Smrg    $ECHO "\
552049e108a1Smrg
552149e108a1Smrg# A function that is used when there is no print builtin or printf.
552249e108a1Smrgfunc_fallback_echo ()
552349e108a1Smrg{
552449e108a1Smrg  eval 'cat <<_LTECHO_EOF
552549e108a1Smrg\$1
552649e108a1Smrg_LTECHO_EOF'
552749e108a1Smrg}
5528c30f5000Smrg    ECHO=$qECHO
552949e108a1Smrg  fi
553049e108a1Smrg
553149e108a1Smrg# Very basic option parsing. These options are (a) specific to
553249e108a1Smrg# the libtool wrapper, (b) are identical between the wrapper
5533b3a827e2Smrg# /script/ and the wrapper /executable/ that is used only on
553449e108a1Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535b3a827e2Smrg# (application programs are unlikely to have options that match
553649e108a1Smrg# this pattern).
553749e108a1Smrg#
553849e108a1Smrg# There are only two supported options: --lt-debug and
553949e108a1Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
554049e108a1Smrg#
554149e108a1Smrg# The first argument to this parsing function should be the
554249e108a1Smrg# script's $0 value, followed by "$@".
554349e108a1Smrglt_option_debug=
554449e108a1Smrgfunc_parse_lt_options ()
554549e108a1Smrg{
554649e108a1Smrg  lt_script_arg0=\$0
554749e108a1Smrg  shift
554849e108a1Smrg  for lt_opt
554949e108a1Smrg  do
555049e108a1Smrg    case \"\$lt_opt\" in
555149e108a1Smrg    --lt-debug) lt_option_debug=1 ;;
555249e108a1Smrg    --lt-dump-script)
555349e108a1Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
555449e108a1Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
555549e108a1Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
555649e108a1Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555749e108a1Smrg        exit 0
555849e108a1Smrg      ;;
555949e108a1Smrg    --lt-*)
556049e108a1Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
556149e108a1Smrg        exit 1
556249e108a1Smrg      ;;
556349e108a1Smrg    esac
556449e108a1Smrg  done
556549e108a1Smrg
556649e108a1Smrg  # Print the debug banner immediately:
556749e108a1Smrg  if test -n \"\$lt_option_debug\"; then
5568b3a827e2Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556949e108a1Smrg  fi
557049e108a1Smrg}
557149e108a1Smrg
557249e108a1Smrg# Used when --lt-debug. Prints its arguments to stdout
557349e108a1Smrg# (redirection is the responsibility of the caller)
557449e108a1Smrgfunc_lt_dump_args ()
557549e108a1Smrg{
557649e108a1Smrg  lt_dump_args_N=1;
557749e108a1Smrg  for lt_arg
557849e108a1Smrg  do
5579b3a827e2Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
558049e108a1Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
558149e108a1Smrg  done
558249e108a1Smrg}
558349e108a1Smrg
558449e108a1Smrg# Core function for launching the target application
558549e108a1Smrgfunc_exec_program_core ()
558649e108a1Smrg{
5587f05b35a2Smrg"
558849e108a1Smrg  case $host in
558949e108a1Smrg  # Backslashes separate directories on plain windows
559049e108a1Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
559149e108a1Smrg    $ECHO "\
559249e108a1Smrg      if test -n \"\$lt_option_debug\"; then
5593b3a827e2Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
559449e108a1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
559549e108a1Smrg      fi
559649e108a1Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559749e108a1Smrg"
559849e108a1Smrg    ;;
559949e108a1Smrg
560049e108a1Smrg  *)
560149e108a1Smrg    $ECHO "\
560249e108a1Smrg      if test -n \"\$lt_option_debug\"; then
5603b3a827e2Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
560449e108a1Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
560549e108a1Smrg      fi
560649e108a1Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560749e108a1Smrg"
560849e108a1Smrg    ;;
560949e108a1Smrg  esac
561049e108a1Smrg  $ECHO "\
561149e108a1Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
561249e108a1Smrg      exit 1
561349e108a1Smrg}
561449e108a1Smrg
561549e108a1Smrg# A function to encapsulate launching the target application
561649e108a1Smrg# Strips options in the --lt-* namespace from \$@ and
561749e108a1Smrg# launches target application with the remaining arguments.
561849e108a1Smrgfunc_exec_program ()
561949e108a1Smrg{
5620e494fffdSmrg  case \" \$* \" in
5621e494fffdSmrg  *\\ --lt-*)
5622e494fffdSmrg    for lt_wr_arg
5623e494fffdSmrg    do
5624e494fffdSmrg      case \$lt_wr_arg in
5625e494fffdSmrg      --lt-*) ;;
5626e494fffdSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627e494fffdSmrg      esac
5628e494fffdSmrg      shift
5629e494fffdSmrg    done ;;
5630e494fffdSmrg  esac
563149e108a1Smrg  func_exec_program_core \${1+\"\$@\"}
563249e108a1Smrg}
563349e108a1Smrg
563449e108a1Smrg  # Parse options
563549e108a1Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636e0963edeSmrg
5637f05b35a2Smrg  # Find the directory that this script lives in.
563849e108a1Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5639f05b35a2Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640e0963edeSmrg
5641f05b35a2Smrg  # Follow symbolic links until we get to the real thisdir.
564249e108a1Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5643f05b35a2Smrg  while test -n \"\$file\"; do
564449e108a1Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645f05b35a2Smrg
5646f05b35a2Smrg    # If there was a directory component, then change thisdir.
5647f05b35a2Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5648f05b35a2Smrg      case \"\$destdir\" in
5649f05b35a2Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5650f05b35a2Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651e0963edeSmrg      esac
5652f05b35a2Smrg    fi
5653e0963edeSmrg
565449e108a1Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
565549e108a1Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5656f05b35a2Smrg  done
5657e0963edeSmrg
5658f05b35a2Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5659f05b35a2Smrg  # the cwrapper.
566049e108a1Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5661f05b35a2Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5662f05b35a2Smrg    # special case for '.'
5663f05b35a2Smrg    if test \"\$thisdir\" = \".\"; then
5664f05b35a2Smrg      thisdir=\`pwd\`
5665f05b35a2Smrg    fi
5666f05b35a2Smrg    # remove .libs from thisdir
5667f05b35a2Smrg    case \"\$thisdir\" in
566849e108a1Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5669f05b35a2Smrg    $objdir )   thisdir=. ;;
5670f05b35a2Smrg    esac
5671f05b35a2Smrg  fi
5672f05b35a2Smrg
5673f05b35a2Smrg  # Try to get the absolute directory name.
5674f05b35a2Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5675f05b35a2Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5676f05b35a2Smrg"
5677f05b35a2Smrg
5678b3a827e2Smrg	if test yes = "$fast_install"; then
5679f05b35a2Smrg	  $ECHO "\
5680f05b35a2Smrg  program=lt-'$outputname'$exeext
5681f05b35a2Smrg  progdir=\"\$thisdir/$objdir\"
5682f05b35a2Smrg
5683f05b35a2Smrg  if test ! -f \"\$progdir/\$program\" ||
5684b3a827e2Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5685f05b35a2Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686f05b35a2Smrg
5687f05b35a2Smrg    file=\"\$\$-\$program\"
5688f05b35a2Smrg
5689f05b35a2Smrg    if test ! -d \"\$progdir\"; then
5690f05b35a2Smrg      $MKDIR \"\$progdir\"
5691f05b35a2Smrg    else
5692f05b35a2Smrg      $RM \"\$progdir/\$file\"
5693f05b35a2Smrg    fi"
5694f05b35a2Smrg
5695f05b35a2Smrg	  $ECHO "\
5696f05b35a2Smrg
5697f05b35a2Smrg    # relink executable if necessary
5698f05b35a2Smrg    if test -n \"\$relink_command\"; then
5699f05b35a2Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5700f05b35a2Smrg      else
5701b3a827e2Smrg	\$ECHO \"\$relink_command_output\" >&2
5702f05b35a2Smrg	$RM \"\$progdir/\$file\"
5703f05b35a2Smrg	exit 1
5704e0963edeSmrg      fi
5705f05b35a2Smrg    fi
5706e0963edeSmrg
5707f05b35a2Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5708f05b35a2Smrg    { $RM \"\$progdir/\$program\";
5709f05b35a2Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5710f05b35a2Smrg    $RM \"\$progdir/\$file\"
5711f05b35a2Smrg  fi"
5712f05b35a2Smrg	else
5713f05b35a2Smrg	  $ECHO "\
5714f05b35a2Smrg  program='$outputname'
5715f05b35a2Smrg  progdir=\"\$thisdir/$objdir\"
5716f05b35a2Smrg"
5717e0963edeSmrg	fi
5718e0963edeSmrg
5719f05b35a2Smrg	$ECHO "\
5720f05b35a2Smrg
5721f05b35a2Smrg  if test -f \"\$progdir/\$program\"; then"
5722f05b35a2Smrg
572367ab2ff2Smrg	# fixup the dll searchpath if we need to.
572467ab2ff2Smrg	#
572567ab2ff2Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
572667ab2ff2Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
572767ab2ff2Smrg	# libraries must come first.
572867ab2ff2Smrg	if test -n "$dllsearchpath"; then
572967ab2ff2Smrg	  $ECHO "\
573067ab2ff2Smrg    # Add the dll search path components to the executable PATH
573167ab2ff2Smrg    PATH=$dllsearchpath:\$PATH
573267ab2ff2Smrg"
573367ab2ff2Smrg	fi
573467ab2ff2Smrg
5735f05b35a2Smrg	# Export our shlibpath_var if we have one.
5736b3a827e2Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5737f05b35a2Smrg	  $ECHO "\
5738f05b35a2Smrg    # Add our own library path to $shlibpath_var
5739f05b35a2Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740f05b35a2Smrg
5741f05b35a2Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5742f05b35a2Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
574349e108a1Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744f05b35a2Smrg
5745f05b35a2Smrg    export $shlibpath_var
5746f05b35a2Smrg"
5747e0963edeSmrg	fi
5748e0963edeSmrg
5749f05b35a2Smrg	$ECHO "\
5750f05b35a2Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5751f05b35a2Smrg      # Run the actual program with our arguments.
575249e108a1Smrg      func_exec_program \${1+\"\$@\"}
5753f05b35a2Smrg    fi
5754f05b35a2Smrg  else
5755f05b35a2Smrg    # The program doesn't exist.
5756b3a827e2Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5757f05b35a2Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575849e108a1Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5759f05b35a2Smrg    exit 1
5760f05b35a2Smrg  fi
5761f05b35a2Smrgfi\
5762f05b35a2Smrg"
5763f05b35a2Smrg}
5764e0963edeSmrg
5765e0963edeSmrg
5766f05b35a2Smrg# func_emit_cwrapperexe_src
5767f05b35a2Smrg# emit the source code for a wrapper executable on stdout
5768f05b35a2Smrg# Must ONLY be called from within func_mode_link because
5769f05b35a2Smrg# it depends on a number of variable set therein.
5770f05b35a2Smrgfunc_emit_cwrapperexe_src ()
5771f05b35a2Smrg{
5772f05b35a2Smrg	cat <<EOF
5773e0963edeSmrg
5774f05b35a2Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775b3a827e2Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776e0963edeSmrg
5777f05b35a2Smrg   The $output program cannot be directly executed until all the libtool
5778f05b35a2Smrg   libraries that it depends on are installed.
5779e0963edeSmrg
5780f05b35a2Smrg   This wrapper executable should never be moved out of the build directory.
5781f05b35a2Smrg   If it is, it will not operate correctly.
5782f05b35a2Smrg*/
5783f05b35a2SmrgEOF
5784f05b35a2Smrg	    cat <<"EOF"
578549e108a1Smrg#ifdef _MSC_VER
578649e108a1Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578749e108a1Smrg#endif
5788f05b35a2Smrg#include <stdio.h>
5789f05b35a2Smrg#include <stdlib.h>
5790f05b35a2Smrg#ifdef _MSC_VER
5791f05b35a2Smrg# include <direct.h>
5792f05b35a2Smrg# include <process.h>
5793f05b35a2Smrg# include <io.h>
5794f05b35a2Smrg#else
5795f05b35a2Smrg# include <unistd.h>
5796f05b35a2Smrg# include <stdint.h>
5797f05b35a2Smrg# ifdef __CYGWIN__
5798f05b35a2Smrg#  include <io.h>
5799f05b35a2Smrg# endif
5800f05b35a2Smrg#endif
5801f05b35a2Smrg#include <malloc.h>
5802f05b35a2Smrg#include <stdarg.h>
5803f05b35a2Smrg#include <assert.h>
5804f05b35a2Smrg#include <string.h>
5805f05b35a2Smrg#include <ctype.h>
5806f05b35a2Smrg#include <errno.h>
5807f05b35a2Smrg#include <fcntl.h>
5808f05b35a2Smrg#include <sys/stat.h>
5809e0963edeSmrg
5810b3a827e2Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811b3a827e2Smrg
581249e108a1Smrg/* declarations of non-ANSI functions */
5813b3a827e2Smrg#if defined __MINGW32__
581449e108a1Smrg# ifdef __STRICT_ANSI__
581549e108a1Smrgint _putenv (const char *);
581649e108a1Smrg# endif
5817b3a827e2Smrg#elif defined __CYGWIN__
581849e108a1Smrg# ifdef __STRICT_ANSI__
581949e108a1Smrgchar *realpath (const char *, char *);
582049e108a1Smrgint putenv (char *);
582149e108a1Smrgint setenv (const char *, const char *, int);
582249e108a1Smrg# endif
5823b3a827e2Smrg/* #elif defined other_platform || defined ... */
582449e108a1Smrg#endif
582549e108a1Smrg
582649e108a1Smrg/* portability defines, excluding path handling macros */
5827b3a827e2Smrg#if defined _MSC_VER
582849e108a1Smrg# define setmode _setmode
582949e108a1Smrg# define stat    _stat
583049e108a1Smrg# define chmod   _chmod
583149e108a1Smrg# define getcwd  _getcwd
583249e108a1Smrg# define putenv  _putenv
583349e108a1Smrg# define S_IXUSR _S_IEXEC
5834b3a827e2Smrg#elif defined __MINGW32__
583549e108a1Smrg# define setmode _setmode
583649e108a1Smrg# define stat    _stat
583749e108a1Smrg# define chmod   _chmod
583849e108a1Smrg# define getcwd  _getcwd
583949e108a1Smrg# define putenv  _putenv
5840b3a827e2Smrg#elif defined __CYGWIN__
584149e108a1Smrg# define HAVE_SETENV
584249e108a1Smrg# define FOPEN_WB "wb"
5843b3a827e2Smrg/* #elif defined other platforms ... */
584449e108a1Smrg#endif
584549e108a1Smrg
5846b3a827e2Smrg#if defined PATH_MAX
5847f05b35a2Smrg# define LT_PATHMAX PATH_MAX
5848b3a827e2Smrg#elif defined MAXPATHLEN
5849f05b35a2Smrg# define LT_PATHMAX MAXPATHLEN
5850f05b35a2Smrg#else
5851f05b35a2Smrg# define LT_PATHMAX 1024
5852f05b35a2Smrg#endif
5853e0963edeSmrg
5854f05b35a2Smrg#ifndef S_IXOTH
5855f05b35a2Smrg# define S_IXOTH 0
5856f05b35a2Smrg#endif
5857f05b35a2Smrg#ifndef S_IXGRP
5858f05b35a2Smrg# define S_IXGRP 0
5859f05b35a2Smrg#endif
5860e0963edeSmrg
586149e108a1Smrg/* path handling portability macros */
5862f05b35a2Smrg#ifndef DIR_SEPARATOR
5863f05b35a2Smrg# define DIR_SEPARATOR '/'
5864f05b35a2Smrg# define PATH_SEPARATOR ':'
5865f05b35a2Smrg#endif
5866e0963edeSmrg
5867b3a827e2Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868b3a827e2Smrg  defined __OS2__
5869f05b35a2Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5870f05b35a2Smrg# define FOPEN_WB "wb"
5871f05b35a2Smrg# ifndef DIR_SEPARATOR_2
5872f05b35a2Smrg#  define DIR_SEPARATOR_2 '\\'
5873f05b35a2Smrg# endif
5874f05b35a2Smrg# ifndef PATH_SEPARATOR_2
5875f05b35a2Smrg#  define PATH_SEPARATOR_2 ';'
5876f05b35a2Smrg# endif
5877f05b35a2Smrg#endif
5878e0963edeSmrg
5879f05b35a2Smrg#ifndef DIR_SEPARATOR_2
5880f05b35a2Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5881f05b35a2Smrg#else /* DIR_SEPARATOR_2 */
5882f05b35a2Smrg# define IS_DIR_SEPARATOR(ch) \
5883f05b35a2Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5884f05b35a2Smrg#endif /* DIR_SEPARATOR_2 */
5885e0963edeSmrg
5886f05b35a2Smrg#ifndef PATH_SEPARATOR_2
5887f05b35a2Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5888f05b35a2Smrg#else /* PATH_SEPARATOR_2 */
5889f05b35a2Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5890f05b35a2Smrg#endif /* PATH_SEPARATOR_2 */
5891e0963edeSmrg
5892f05b35a2Smrg#ifndef FOPEN_WB
5893f05b35a2Smrg# define FOPEN_WB "w"
5894f05b35a2Smrg#endif
5895f05b35a2Smrg#ifndef _O_BINARY
5896f05b35a2Smrg# define _O_BINARY 0
5897f05b35a2Smrg#endif
5898e0963edeSmrg
5899f05b35a2Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5900f05b35a2Smrg#define XFREE(stale) do { \
5901b3a827e2Smrg  if (stale) { free (stale); stale = 0; } \
5902f05b35a2Smrg} while (0)
5903e0963edeSmrg
5904b3a827e2Smrg#if defined LT_DEBUGWRAPPER
590549e108a1Smrgstatic int lt_debug = 1;
5906f05b35a2Smrg#else
590749e108a1Smrgstatic int lt_debug = 0;
5908f05b35a2Smrg#endif
5909e0963edeSmrg
591049e108a1Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5911e0963edeSmrg
5912f05b35a2Smrgvoid *xmalloc (size_t num);
5913f05b35a2Smrgchar *xstrdup (const char *string);
5914f05b35a2Smrgconst char *base_name (const char *name);
5915f05b35a2Smrgchar *find_executable (const char *wrapper);
5916f05b35a2Smrgchar *chase_symlinks (const char *pathspec);
5917f05b35a2Smrgint make_executable (const char *path);
5918f05b35a2Smrgint check_executable (const char *path);
5919f05b35a2Smrgchar *strendzap (char *str, const char *pat);
592049e108a1Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
592149e108a1Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
592249e108a1Smrgstatic const char *nonnull (const char *s);
592349e108a1Smrgstatic const char *nonempty (const char *s);
5924f05b35a2Smrgvoid lt_setenv (const char *name, const char *value);
5925f05b35a2Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5926f05b35a2Smrgvoid lt_update_exe_path (const char *name, const char *value);
5927f05b35a2Smrgvoid lt_update_lib_path (const char *name, const char *value);
592849e108a1Smrgchar **prepare_spawn (char **argv);
592949e108a1Smrgvoid lt_dump_script (FILE *f);
5930f05b35a2SmrgEOF
5931f05b35a2Smrg
5932f05b35a2Smrg	    cat <<EOF
5933b3a827e2Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934b3a827e2Smrg# define externally_visible volatile
5935b3a827e2Smrg#else
5936b3a827e2Smrg# define externally_visible __attribute__((externally_visible)) volatile
5937b3a827e2Smrg#endif
5938b3a827e2Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5939f05b35a2Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5940f05b35a2SmrgEOF
5941e0963edeSmrg
5942b3a827e2Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
594367ab2ff2Smrg              func_to_host_path "$temp_rpath"
5944f05b35a2Smrg	      cat <<EOF
594567ab2ff2Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946f05b35a2SmrgEOF
5947f05b35a2Smrg	    else
5948f05b35a2Smrg	      cat <<"EOF"
5949f05b35a2Smrgconst char * LIB_PATH_VALUE   = "";
5950f05b35a2SmrgEOF
5951f05b35a2Smrg	    fi
5952e0963edeSmrg
5953f05b35a2Smrg	    if test -n "$dllsearchpath"; then
595467ab2ff2Smrg              func_to_host_path "$dllsearchpath:"
5955f05b35a2Smrg	      cat <<EOF
5956f05b35a2Smrgconst char * EXE_PATH_VARNAME = "PATH";
595767ab2ff2Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958f05b35a2SmrgEOF
5959f05b35a2Smrg	    else
5960f05b35a2Smrg	      cat <<"EOF"
5961f05b35a2Smrgconst char * EXE_PATH_VARNAME = "";
5962f05b35a2Smrgconst char * EXE_PATH_VALUE   = "";
5963f05b35a2SmrgEOF
5964f05b35a2Smrg	    fi
5965e0963edeSmrg
5966b3a827e2Smrg	    if test yes = "$fast_install"; then
5967f05b35a2Smrg	      cat <<EOF
5968f05b35a2Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5969f05b35a2SmrgEOF
5970f05b35a2Smrg	    else
5971f05b35a2Smrg	      cat <<EOF
5972f05b35a2Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5973f05b35a2SmrgEOF
5974f05b35a2Smrg	    fi
5975e0963edeSmrg
5976e0963edeSmrg
5977f05b35a2Smrg	    cat <<"EOF"
5978e0963edeSmrg
5979f05b35a2Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980e0963edeSmrg
5981f05b35a2Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5982f05b35a2Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
598349e108a1Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984f05b35a2Smrg
5985f05b35a2Smrgint
5986f05b35a2Smrgmain (int argc, char *argv[])
5987f05b35a2Smrg{
5988f05b35a2Smrg  char **newargz;
5989f05b35a2Smrg  int  newargc;
5990f05b35a2Smrg  char *tmp_pathspec;
5991f05b35a2Smrg  char *actual_cwrapper_path;
5992f05b35a2Smrg  char *actual_cwrapper_name;
5993f05b35a2Smrg  char *target_name;
5994f05b35a2Smrg  char *lt_argv_zero;
5995b3a827e2Smrg  int rval = 127;
5996f05b35a2Smrg
5997f05b35a2Smrg  int i;
5998f05b35a2Smrg
5999f05b35a2Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000b3a827e2Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001f05b35a2Smrg
600249e108a1Smrg  /* very simple arg parsing; don't want to rely on getopt
600349e108a1Smrg   * also, copy all non cwrapper options to newargz, except
600449e108a1Smrg   * argz[0], which is handled differently
600549e108a1Smrg   */
600649e108a1Smrg  newargc=0;
6007f05b35a2Smrg  for (i = 1; i < argc; i++)
6008f05b35a2Smrg    {
6009b3a827e2Smrg      if (STREQ (argv[i], dumpscript_opt))
6010f05b35a2Smrg	{
6011f05b35a2SmrgEOF
6012b3a827e2Smrg	    case $host in
6013f05b35a2Smrg	      *mingw* | *cygwin* )
6014f05b35a2Smrg		# make stdout use "unix" line endings
6015f05b35a2Smrg		echo "          setmode(1,_O_BINARY);"
6016f05b35a2Smrg		;;
6017f05b35a2Smrg	      esac
6018f05b35a2Smrg
6019f05b35a2Smrg	    cat <<"EOF"
602049e108a1Smrg	  lt_dump_script (stdout);
6021f05b35a2Smrg	  return 0;
6022f05b35a2Smrg	}
6023b3a827e2Smrg      if (STREQ (argv[i], debug_opt))
602449e108a1Smrg	{
602549e108a1Smrg          lt_debug = 1;
602649e108a1Smrg          continue;
602749e108a1Smrg	}
6028b3a827e2Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602949e108a1Smrg        {
603049e108a1Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
603149e108a1Smrg             namespace, but it is not one of the ones we know about and
603249e108a1Smrg             have already dealt with, above (inluding dump-script), then
603349e108a1Smrg             report an error. Otherwise, targets might begin to believe
603449e108a1Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
603549e108a1Smrg             namespace. The first time any user complains about this, we'll
603649e108a1Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603749e108a1Smrg             or a configure.ac-settable value.
603849e108a1Smrg           */
603949e108a1Smrg          lt_fatal (__FILE__, __LINE__,
604049e108a1Smrg		    "unrecognized %s option: '%s'",
604149e108a1Smrg                    ltwrapper_option_prefix, argv[i]);
604249e108a1Smrg        }
604349e108a1Smrg      /* otherwise ... */
604449e108a1Smrg      newargz[++newargc] = xstrdup (argv[i]);
6045f05b35a2Smrg    }
604649e108a1Smrg  newargz[++newargc] = NULL;
604749e108a1Smrg
604849e108a1SmrgEOF
604949e108a1Smrg	    cat <<EOF
605049e108a1Smrg  /* The GNU banner must be the first non-error debug message */
6051b3a827e2Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
605249e108a1SmrgEOF
605349e108a1Smrg	    cat <<"EOF"
605449e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
605549e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6056f05b35a2Smrg
6057f05b35a2Smrg  tmp_pathspec = find_executable (argv[0]);
6058f05b35a2Smrg  if (tmp_pathspec == NULL)
605949e108a1Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
606049e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
606149e108a1Smrg                  "(main) found exe (before symlink chase) at: %s\n",
606249e108a1Smrg		  tmp_pathspec);
6063f05b35a2Smrg
6064f05b35a2Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
606549e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
606649e108a1Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606749e108a1Smrg		  actual_cwrapper_path);
6068f05b35a2Smrg  XFREE (tmp_pathspec);
6069f05b35a2Smrg
607049e108a1Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6071f05b35a2Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6072f05b35a2Smrg
6073f05b35a2Smrg  /* wrapper name transforms */
6074f05b35a2Smrg  strendzap (actual_cwrapper_name, ".exe");
6075f05b35a2Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6076f05b35a2Smrg  XFREE (actual_cwrapper_name);
6077f05b35a2Smrg  actual_cwrapper_name = tmp_pathspec;
6078f05b35a2Smrg  tmp_pathspec = 0;
6079f05b35a2Smrg
6080f05b35a2Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6081f05b35a2Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6082f05b35a2Smrg  strendzap (target_name, ".exe");
6083f05b35a2Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6084f05b35a2Smrg  XFREE (target_name);
6085f05b35a2Smrg  target_name = tmp_pathspec;
6086f05b35a2Smrg  tmp_pathspec = 0;
6087f05b35a2Smrg
608849e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
608949e108a1Smrg		  "(main) libtool target name: %s\n",
609049e108a1Smrg		  target_name);
6091f05b35a2SmrgEOF
6092f05b35a2Smrg
6093f05b35a2Smrg	    cat <<EOF
6094f05b35a2Smrg  newargz[0] =
6095f05b35a2Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6096f05b35a2Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6097f05b35a2Smrg  strcpy (newargz[0], actual_cwrapper_path);
6098f05b35a2Smrg  strcat (newargz[0], "$objdir");
6099f05b35a2Smrg  strcat (newargz[0], "/");
6100f05b35a2SmrgEOF
6101f05b35a2Smrg
6102f05b35a2Smrg	    cat <<"EOF"
6103f05b35a2Smrg  /* stop here, and copy so we don't have to do this twice */
6104f05b35a2Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105f05b35a2Smrg
6106f05b35a2Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6107f05b35a2Smrg  strcat (newargz[0], actual_cwrapper_name);
6108f05b35a2Smrg
6109f05b35a2Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6110f05b35a2Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6111f05b35a2Smrg  XFREE (tmp_pathspec);
6112f05b35a2Smrg  tmp_pathspec = NULL;
6113f05b35a2SmrgEOF
6114f05b35a2Smrg
6115f05b35a2Smrg	    case $host_os in
6116f05b35a2Smrg	      mingw*)
6117f05b35a2Smrg	    cat <<"EOF"
6118f05b35a2Smrg  {
6119f05b35a2Smrg    char* p;
6120f05b35a2Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6121f05b35a2Smrg      {
6122f05b35a2Smrg	*p = '/';
6123f05b35a2Smrg      }
6124f05b35a2Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6125f05b35a2Smrg      {
6126f05b35a2Smrg	*p = '/';
6127f05b35a2Smrg      }
6128f05b35a2Smrg  }
6129f05b35a2SmrgEOF
6130e0963edeSmrg	    ;;
6131f05b35a2Smrg	    esac
6132f05b35a2Smrg
6133f05b35a2Smrg	    cat <<"EOF"
6134f05b35a2Smrg  XFREE (target_name);
6135f05b35a2Smrg  XFREE (actual_cwrapper_path);
6136f05b35a2Smrg  XFREE (actual_cwrapper_name);
6137f05b35a2Smrg
6138f05b35a2Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6139f05b35a2Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
614067ab2ff2Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
614167ab2ff2Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
614267ab2ff2Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
614367ab2ff2Smrg     libraries must come first. */
6144f05b35a2Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
614567ab2ff2Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146f05b35a2Smrg
614749e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614849e108a1Smrg		  nonnull (lt_argv_zero));
6149f05b35a2Smrg  for (i = 0; i < newargc; i++)
6150f05b35a2Smrg    {
615149e108a1Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
615249e108a1Smrg		      i, nonnull (newargz[i]));
6153f05b35a2Smrg    }
6154e0963edeSmrg
6155e0963edeSmrgEOF
6156e0963edeSmrg
6157f05b35a2Smrg	    case $host_os in
6158f05b35a2Smrg	      mingw*)
6159f05b35a2Smrg		cat <<"EOF"
6160f05b35a2Smrg  /* execv doesn't actually work on mingw as expected on unix */
616149e108a1Smrg  newargz = prepare_spawn (newargz);
6162b3a827e2Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6163f05b35a2Smrg  if (rval == -1)
6164f05b35a2Smrg    {
6165f05b35a2Smrg      /* failed to start process */
616649e108a1Smrg      lt_debugprintf (__FILE__, __LINE__,
616749e108a1Smrg		      "(main) failed to launch target \"%s\": %s\n",
616849e108a1Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6169f05b35a2Smrg      return 127;
6170f05b35a2Smrg    }
6171f05b35a2Smrg  return rval;
6172f05b35a2SmrgEOF
6173f05b35a2Smrg		;;
6174f05b35a2Smrg	      *)
6175f05b35a2Smrg		cat <<"EOF"
6176f05b35a2Smrg  execv (lt_argv_zero, newargz);
6177f05b35a2Smrg  return rval; /* =127, but avoids unused variable warning */
6178f05b35a2SmrgEOF
6179f05b35a2Smrg		;;
6180f05b35a2Smrg	    esac
6181e0963edeSmrg
6182f05b35a2Smrg	    cat <<"EOF"
6183f05b35a2Smrg}
6184e0963edeSmrg
6185f05b35a2Smrgvoid *
6186f05b35a2Smrgxmalloc (size_t num)
6187f05b35a2Smrg{
6188f05b35a2Smrg  void *p = (void *) malloc (num);
6189f05b35a2Smrg  if (!p)
619049e108a1Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191e0963edeSmrg
6192f05b35a2Smrg  return p;
6193f05b35a2Smrg}
6194e0963edeSmrg
6195f05b35a2Smrgchar *
6196f05b35a2Smrgxstrdup (const char *string)
6197f05b35a2Smrg{
6198f05b35a2Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6199f05b35a2Smrg			  string) : NULL;
6200f05b35a2Smrg}
6201e0963edeSmrg
6202f05b35a2Smrgconst char *
6203f05b35a2Smrgbase_name (const char *name)
6204f05b35a2Smrg{
6205f05b35a2Smrg  const char *base;
6206e0963edeSmrg
6207b3a827e2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6208f05b35a2Smrg  /* Skip over the disk name in MSDOS pathnames. */
6209f05b35a2Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6210f05b35a2Smrg    name += 2;
6211f05b35a2Smrg#endif
6212e0963edeSmrg
6213f05b35a2Smrg  for (base = name; *name; name++)
6214f05b35a2Smrg    if (IS_DIR_SEPARATOR (*name))
6215f05b35a2Smrg      base = name + 1;
6216f05b35a2Smrg  return base;
6217f05b35a2Smrg}
6218e0963edeSmrg
6219f05b35a2Smrgint
6220f05b35a2Smrgcheck_executable (const char *path)
6221f05b35a2Smrg{
6222f05b35a2Smrg  struct stat st;
6223e0963edeSmrg
622449e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
622549e108a1Smrg                  nonempty (path));
6226f05b35a2Smrg  if ((!path) || (!*path))
6227f05b35a2Smrg    return 0;
6228e0963edeSmrg
6229f05b35a2Smrg  if ((stat (path, &st) >= 0)
6230f05b35a2Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6231f05b35a2Smrg    return 1;
6232f05b35a2Smrg  else
6233f05b35a2Smrg    return 0;
6234f05b35a2Smrg}
6235e0963edeSmrg
6236f05b35a2Smrgint
6237f05b35a2Smrgmake_executable (const char *path)
6238f05b35a2Smrg{
6239f05b35a2Smrg  int rval = 0;
6240f05b35a2Smrg  struct stat st;
6241e0963edeSmrg
624249e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
624349e108a1Smrg                  nonempty (path));
6244f05b35a2Smrg  if ((!path) || (!*path))
6245f05b35a2Smrg    return 0;
6246e0963edeSmrg
6247f05b35a2Smrg  if (stat (path, &st) >= 0)
6248f05b35a2Smrg    {
6249f05b35a2Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6250f05b35a2Smrg    }
6251f05b35a2Smrg  return rval;
6252f05b35a2Smrg}
6253e0963edeSmrg
6254f05b35a2Smrg/* Searches for the full path of the wrapper.  Returns
6255f05b35a2Smrg   newly allocated full path name if found, NULL otherwise
6256f05b35a2Smrg   Does not chase symlinks, even on platforms that support them.
6257f05b35a2Smrg*/
6258f05b35a2Smrgchar *
6259f05b35a2Smrgfind_executable (const char *wrapper)
6260f05b35a2Smrg{
6261f05b35a2Smrg  int has_slash = 0;
6262f05b35a2Smrg  const char *p;
6263f05b35a2Smrg  const char *p_next;
6264f05b35a2Smrg  /* static buffer for getcwd */
6265f05b35a2Smrg  char tmp[LT_PATHMAX + 1];
6266b3a827e2Smrg  size_t tmp_len;
6267f05b35a2Smrg  char *concat_name;
6268e0963edeSmrg
626949e108a1Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
627049e108a1Smrg                  nonempty (wrapper));
6271e0963edeSmrg
6272f05b35a2Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6273f05b35a2Smrg    return NULL;
6274e0963edeSmrg
6275f05b35a2Smrg  /* Absolute path? */
6276b3a827e2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6277f05b35a2Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6278f05b35a2Smrg    {
6279f05b35a2Smrg      concat_name = xstrdup (wrapper);
6280f05b35a2Smrg      if (check_executable (concat_name))
6281f05b35a2Smrg	return concat_name;
6282f05b35a2Smrg      XFREE (concat_name);
6283f05b35a2Smrg    }
6284f05b35a2Smrg  else
6285f05b35a2Smrg    {
6286f05b35a2Smrg#endif
6287f05b35a2Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6288f05b35a2Smrg	{
6289f05b35a2Smrg	  concat_name = xstrdup (wrapper);
6290f05b35a2Smrg	  if (check_executable (concat_name))
6291f05b35a2Smrg	    return concat_name;
6292f05b35a2Smrg	  XFREE (concat_name);
6293f05b35a2Smrg	}
6294b3a827e2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6295f05b35a2Smrg    }
6296f05b35a2Smrg#endif
6297e0963edeSmrg
6298f05b35a2Smrg  for (p = wrapper; *p; p++)
6299f05b35a2Smrg    if (*p == '/')
6300f05b35a2Smrg      {
6301f05b35a2Smrg	has_slash = 1;
6302f05b35a2Smrg	break;
6303f05b35a2Smrg      }
6304f05b35a2Smrg  if (!has_slash)
6305f05b35a2Smrg    {
6306f05b35a2Smrg      /* no slashes; search PATH */
6307f05b35a2Smrg      const char *path = getenv ("PATH");
6308f05b35a2Smrg      if (path != NULL)
6309f05b35a2Smrg	{
6310f05b35a2Smrg	  for (p = path; *p; p = p_next)
6311f05b35a2Smrg	    {
6312f05b35a2Smrg	      const char *q;
6313f05b35a2Smrg	      size_t p_len;
6314f05b35a2Smrg	      for (q = p; *q; q++)
6315f05b35a2Smrg		if (IS_PATH_SEPARATOR (*q))
6316f05b35a2Smrg		  break;
6317b3a827e2Smrg	      p_len = (size_t) (q - p);
6318f05b35a2Smrg	      p_next = (*q == '\0' ? q : q + 1);
6319f05b35a2Smrg	      if (p_len == 0)
6320f05b35a2Smrg		{
6321f05b35a2Smrg		  /* empty path: current directory */
6322f05b35a2Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
632349e108a1Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
632449e108a1Smrg                              nonnull (strerror (errno)));
6325f05b35a2Smrg		  tmp_len = strlen (tmp);
6326f05b35a2Smrg		  concat_name =
6327f05b35a2Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6328f05b35a2Smrg		  memcpy (concat_name, tmp, tmp_len);
6329f05b35a2Smrg		  concat_name[tmp_len] = '/';
6330f05b35a2Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6331f05b35a2Smrg		}
6332f05b35a2Smrg	      else
6333f05b35a2Smrg		{
6334f05b35a2Smrg		  concat_name =
6335f05b35a2Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6336f05b35a2Smrg		  memcpy (concat_name, p, p_len);
6337f05b35a2Smrg		  concat_name[p_len] = '/';
6338f05b35a2Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6339f05b35a2Smrg		}
6340f05b35a2Smrg	      if (check_executable (concat_name))
6341f05b35a2Smrg		return concat_name;
6342f05b35a2Smrg	      XFREE (concat_name);
6343f05b35a2Smrg	    }
6344f05b35a2Smrg	}
6345f05b35a2Smrg      /* not found in PATH; assume curdir */
6346f05b35a2Smrg    }
6347f05b35a2Smrg  /* Relative path | not found in path: prepend cwd */
6348f05b35a2Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634949e108a1Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
635049e108a1Smrg              nonnull (strerror (errno)));
6351f05b35a2Smrg  tmp_len = strlen (tmp);
6352f05b35a2Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6353f05b35a2Smrg  memcpy (concat_name, tmp, tmp_len);
6354f05b35a2Smrg  concat_name[tmp_len] = '/';
6355f05b35a2Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356e0963edeSmrg
6357f05b35a2Smrg  if (check_executable (concat_name))
6358f05b35a2Smrg    return concat_name;
6359f05b35a2Smrg  XFREE (concat_name);
6360f05b35a2Smrg  return NULL;
6361f05b35a2Smrg}
6362e0963edeSmrg
6363f05b35a2Smrgchar *
6364f05b35a2Smrgchase_symlinks (const char *pathspec)
6365f05b35a2Smrg{
6366f05b35a2Smrg#ifndef S_ISLNK
6367f05b35a2Smrg  return xstrdup (pathspec);
6368f05b35a2Smrg#else
6369f05b35a2Smrg  char buf[LT_PATHMAX];
6370f05b35a2Smrg  struct stat s;
6371f05b35a2Smrg  char *tmp_pathspec = xstrdup (pathspec);
6372f05b35a2Smrg  char *p;
6373f05b35a2Smrg  int has_symlinks = 0;
6374f05b35a2Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6375f05b35a2Smrg    {
637649e108a1Smrg      lt_debugprintf (__FILE__, __LINE__,
637749e108a1Smrg		      "checking path component for symlinks: %s\n",
637849e108a1Smrg		      tmp_pathspec);
6379f05b35a2Smrg      if (lstat (tmp_pathspec, &s) == 0)
6380f05b35a2Smrg	{
6381f05b35a2Smrg	  if (S_ISLNK (s.st_mode) != 0)
6382f05b35a2Smrg	    {
6383f05b35a2Smrg	      has_symlinks = 1;
6384f05b35a2Smrg	      break;
6385f05b35a2Smrg	    }
6386e0963edeSmrg
6387f05b35a2Smrg	  /* search backwards for last DIR_SEPARATOR */
6388f05b35a2Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6389f05b35a2Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6390f05b35a2Smrg	    p--;
6391f05b35a2Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6392f05b35a2Smrg	    {
6393f05b35a2Smrg	      /* no more DIR_SEPARATORS left */
6394f05b35a2Smrg	      break;
6395f05b35a2Smrg	    }
6396f05b35a2Smrg	  *p = '\0';
6397f05b35a2Smrg	}
6398f05b35a2Smrg      else
6399f05b35a2Smrg	{
640049e108a1Smrg	  lt_fatal (__FILE__, __LINE__,
640149e108a1Smrg		    "error accessing file \"%s\": %s",
640249e108a1Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6403f05b35a2Smrg	}
6404f05b35a2Smrg    }
6405f05b35a2Smrg  XFREE (tmp_pathspec);
6406e0963edeSmrg
6407f05b35a2Smrg  if (!has_symlinks)
6408f05b35a2Smrg    {
6409f05b35a2Smrg      return xstrdup (pathspec);
6410f05b35a2Smrg    }
6411e0963edeSmrg
6412f05b35a2Smrg  tmp_pathspec = realpath (pathspec, buf);
6413f05b35a2Smrg  if (tmp_pathspec == 0)
6414f05b35a2Smrg    {
641549e108a1Smrg      lt_fatal (__FILE__, __LINE__,
641649e108a1Smrg		"could not follow symlinks for %s", pathspec);
6417f05b35a2Smrg    }
6418f05b35a2Smrg  return xstrdup (tmp_pathspec);
6419f05b35a2Smrg#endif
6420f05b35a2Smrg}
6421e0963edeSmrg
6422f05b35a2Smrgchar *
6423f05b35a2Smrgstrendzap (char *str, const char *pat)
6424f05b35a2Smrg{
6425f05b35a2Smrg  size_t len, patlen;
6426e0963edeSmrg
6427f05b35a2Smrg  assert (str != NULL);
6428f05b35a2Smrg  assert (pat != NULL);
6429e0963edeSmrg
6430f05b35a2Smrg  len = strlen (str);
6431f05b35a2Smrg  patlen = strlen (pat);
6432e0963edeSmrg
6433f05b35a2Smrg  if (patlen <= len)
6434f05b35a2Smrg    {
6435f05b35a2Smrg      str += len - patlen;
6436b3a827e2Smrg      if (STREQ (str, pat))
6437f05b35a2Smrg	*str = '\0';
6438f05b35a2Smrg    }
6439f05b35a2Smrg  return str;
6440f05b35a2Smrg}
6441e0963edeSmrg
644249e108a1Smrgvoid
644349e108a1Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
644449e108a1Smrg{
644549e108a1Smrg  va_list args;
644649e108a1Smrg  if (lt_debug)
644749e108a1Smrg    {
644849e108a1Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644949e108a1Smrg      va_start (args, fmt);
645049e108a1Smrg      (void) vfprintf (stderr, fmt, args);
645149e108a1Smrg      va_end (args);
645249e108a1Smrg    }
645349e108a1Smrg}
645449e108a1Smrg
6455f05b35a2Smrgstatic void
645649e108a1Smrglt_error_core (int exit_status, const char *file,
645749e108a1Smrg	       int line, const char *mode,
6458f05b35a2Smrg	       const char *message, va_list ap)
6459f05b35a2Smrg{
646049e108a1Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6461f05b35a2Smrg  vfprintf (stderr, message, ap);
6462f05b35a2Smrg  fprintf (stderr, ".\n");
6463e0963edeSmrg
6464f05b35a2Smrg  if (exit_status >= 0)
6465f05b35a2Smrg    exit (exit_status);
6466f05b35a2Smrg}
6467e0963edeSmrg
6468f05b35a2Smrgvoid
646949e108a1Smrglt_fatal (const char *file, int line, const char *message, ...)
6470f05b35a2Smrg{
6471f05b35a2Smrg  va_list ap;
6472f05b35a2Smrg  va_start (ap, message);
647349e108a1Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6474f05b35a2Smrg  va_end (ap);
6475f05b35a2Smrg}
6476e0963edeSmrg
647749e108a1Smrgstatic const char *
647849e108a1Smrgnonnull (const char *s)
647949e108a1Smrg{
648049e108a1Smrg  return s ? s : "(null)";
648149e108a1Smrg}
648249e108a1Smrg
648349e108a1Smrgstatic const char *
648449e108a1Smrgnonempty (const char *s)
648549e108a1Smrg{
648649e108a1Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648749e108a1Smrg}
648849e108a1Smrg
6489f05b35a2Smrgvoid
6490f05b35a2Smrglt_setenv (const char *name, const char *value)
6491f05b35a2Smrg{
649249e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
649349e108a1Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
649449e108a1Smrg                  nonnull (name), nonnull (value));
6495f05b35a2Smrg  {
6496f05b35a2Smrg#ifdef HAVE_SETENV
6497f05b35a2Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6498f05b35a2Smrg    char *str = xstrdup (value);
6499f05b35a2Smrg    setenv (name, str, 1);
6500f05b35a2Smrg#else
6501b3a827e2Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6502f05b35a2Smrg    char *str = XMALLOC (char, len);
6503f05b35a2Smrg    sprintf (str, "%s=%s", name, value);
6504f05b35a2Smrg    if (putenv (str) != EXIT_SUCCESS)
6505f05b35a2Smrg      {
6506f05b35a2Smrg        XFREE (str);
6507f05b35a2Smrg      }
6508f05b35a2Smrg#endif
6509f05b35a2Smrg  }
6510f05b35a2Smrg}
6511e0963edeSmrg
6512f05b35a2Smrgchar *
6513f05b35a2Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6514f05b35a2Smrg{
6515f05b35a2Smrg  char *new_value;
6516f05b35a2Smrg  if (orig_value && *orig_value)
6517f05b35a2Smrg    {
6518b3a827e2Smrg      size_t orig_value_len = strlen (orig_value);
6519b3a827e2Smrg      size_t add_len = strlen (add);
6520f05b35a2Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6521f05b35a2Smrg      if (to_end)
6522f05b35a2Smrg        {
6523f05b35a2Smrg          strcpy (new_value, orig_value);
6524f05b35a2Smrg          strcpy (new_value + orig_value_len, add);
6525f05b35a2Smrg        }
6526f05b35a2Smrg      else
6527f05b35a2Smrg        {
6528f05b35a2Smrg          strcpy (new_value, add);
6529f05b35a2Smrg          strcpy (new_value + add_len, orig_value);
6530f05b35a2Smrg        }
6531f05b35a2Smrg    }
6532f05b35a2Smrg  else
6533f05b35a2Smrg    {
6534f05b35a2Smrg      new_value = xstrdup (add);
6535f05b35a2Smrg    }
6536f05b35a2Smrg  return new_value;
6537f05b35a2Smrg}
6538e0963edeSmrg
6539f05b35a2Smrgvoid
6540f05b35a2Smrglt_update_exe_path (const char *name, const char *value)
6541f05b35a2Smrg{
654249e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
654349e108a1Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
654449e108a1Smrg                  nonnull (name), nonnull (value));
6545e0963edeSmrg
6546f05b35a2Smrg  if (name && *name && value && *value)
6547f05b35a2Smrg    {
6548f05b35a2Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6549f05b35a2Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550b3a827e2Smrg      size_t len = strlen (new_value);
6551b3a827e2Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6552f05b35a2Smrg        {
6553b3a827e2Smrg          new_value[--len] = '\0';
6554f05b35a2Smrg        }
6555f05b35a2Smrg      lt_setenv (name, new_value);
6556f05b35a2Smrg      XFREE (new_value);
6557f05b35a2Smrg    }
6558f05b35a2Smrg}
6559e0963edeSmrg
6560f05b35a2Smrgvoid
6561f05b35a2Smrglt_update_lib_path (const char *name, const char *value)
6562f05b35a2Smrg{
656349e108a1Smrg  lt_debugprintf (__FILE__, __LINE__,
656449e108a1Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
656549e108a1Smrg                  nonnull (name), nonnull (value));
6566e0963edeSmrg
6567f05b35a2Smrg  if (name && *name && value && *value)
6568f05b35a2Smrg    {
6569f05b35a2Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6570f05b35a2Smrg      lt_setenv (name, new_value);
6571f05b35a2Smrg      XFREE (new_value);
6572f05b35a2Smrg    }
6573f05b35a2Smrg}
6574e0963edeSmrg
657549e108a1SmrgEOF
657649e108a1Smrg	    case $host_os in
657749e108a1Smrg	      mingw*)
657849e108a1Smrg		cat <<"EOF"
657949e108a1Smrg
658049e108a1Smrg/* Prepares an argument vector before calling spawn().
658149e108a1Smrg   Note that spawn() does not by itself call the command interpreter
658249e108a1Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
658349e108a1Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
658449e108a1Smrg         GetVersionEx(&v);
658549e108a1Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
658649e108a1Smrg      }) ? "cmd.exe" : "command.com").
658749e108a1Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658849e108a1Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658949e108a1Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
659049e108a1Smrg   special way:
659149e108a1Smrg   - Space and tab are interpreted as delimiters. They are not treated as
659249e108a1Smrg     delimiters if they are surrounded by double quotes: "...".
659349e108a1Smrg   - Unescaped double quotes are removed from the input. Their only effect is
659449e108a1Smrg     that within double quotes, space and tab are treated like normal
659549e108a1Smrg     characters.
659649e108a1Smrg   - Backslashes not followed by double quotes are not special.
659749e108a1Smrg   - But 2*n+1 backslashes followed by a double quote become
659849e108a1Smrg     n backslashes followed by a double quote (n >= 0):
659949e108a1Smrg       \" -> "
660049e108a1Smrg       \\\" -> \"
660149e108a1Smrg       \\\\\" -> \\"
660249e108a1Smrg */
660349e108a1Smrg#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"
660449e108a1Smrg#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"
660549e108a1Smrgchar **
660649e108a1Smrgprepare_spawn (char **argv)
660749e108a1Smrg{
660849e108a1Smrg  size_t argc;
660949e108a1Smrg  char **new_argv;
661049e108a1Smrg  size_t i;
661149e108a1Smrg
661249e108a1Smrg  /* Count number of arguments.  */
661349e108a1Smrg  for (argc = 0; argv[argc] != NULL; argc++)
661449e108a1Smrg    ;
661549e108a1Smrg
661649e108a1Smrg  /* Allocate new argument vector.  */
661749e108a1Smrg  new_argv = XMALLOC (char *, argc + 1);
661849e108a1Smrg
661949e108a1Smrg  /* Put quoted arguments into the new argument vector.  */
662049e108a1Smrg  for (i = 0; i < argc; i++)
662149e108a1Smrg    {
662249e108a1Smrg      const char *string = argv[i];
662349e108a1Smrg
662449e108a1Smrg      if (string[0] == '\0')
662549e108a1Smrg	new_argv[i] = xstrdup ("\"\"");
662649e108a1Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662749e108a1Smrg	{
662849e108a1Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662949e108a1Smrg	  size_t length;
663049e108a1Smrg	  unsigned int backslashes;
663149e108a1Smrg	  const char *s;
663249e108a1Smrg	  char *quoted_string;
663349e108a1Smrg	  char *p;
663449e108a1Smrg
663549e108a1Smrg	  length = 0;
663649e108a1Smrg	  backslashes = 0;
663749e108a1Smrg	  if (quote_around)
663849e108a1Smrg	    length++;
663949e108a1Smrg	  for (s = string; *s != '\0'; s++)
664049e108a1Smrg	    {
664149e108a1Smrg	      char c = *s;
664249e108a1Smrg	      if (c == '"')
664349e108a1Smrg		length += backslashes + 1;
664449e108a1Smrg	      length++;
664549e108a1Smrg	      if (c == '\\')
664649e108a1Smrg		backslashes++;
664749e108a1Smrg	      else
664849e108a1Smrg		backslashes = 0;
664949e108a1Smrg	    }
665049e108a1Smrg	  if (quote_around)
665149e108a1Smrg	    length += backslashes + 1;
665249e108a1Smrg
665349e108a1Smrg	  quoted_string = XMALLOC (char, length + 1);
665449e108a1Smrg
665549e108a1Smrg	  p = quoted_string;
665649e108a1Smrg	  backslashes = 0;
665749e108a1Smrg	  if (quote_around)
665849e108a1Smrg	    *p++ = '"';
665949e108a1Smrg	  for (s = string; *s != '\0'; s++)
666049e108a1Smrg	    {
666149e108a1Smrg	      char c = *s;
666249e108a1Smrg	      if (c == '"')
666349e108a1Smrg		{
666449e108a1Smrg		  unsigned int j;
666549e108a1Smrg		  for (j = backslashes + 1; j > 0; j--)
666649e108a1Smrg		    *p++ = '\\';
666749e108a1Smrg		}
666849e108a1Smrg	      *p++ = c;
666949e108a1Smrg	      if (c == '\\')
667049e108a1Smrg		backslashes++;
667149e108a1Smrg	      else
667249e108a1Smrg		backslashes = 0;
667349e108a1Smrg	    }
667449e108a1Smrg	  if (quote_around)
667549e108a1Smrg	    {
667649e108a1Smrg	      unsigned int j;
667749e108a1Smrg	      for (j = backslashes; j > 0; j--)
667849e108a1Smrg		*p++ = '\\';
667949e108a1Smrg	      *p++ = '"';
668049e108a1Smrg	    }
668149e108a1Smrg	  *p = '\0';
668249e108a1Smrg
668349e108a1Smrg	  new_argv[i] = quoted_string;
668449e108a1Smrg	}
668549e108a1Smrg      else
668649e108a1Smrg	new_argv[i] = (char *) string;
668749e108a1Smrg    }
668849e108a1Smrg  new_argv[argc] = NULL;
668949e108a1Smrg
669049e108a1Smrg  return new_argv;
669149e108a1Smrg}
669249e108a1SmrgEOF
669349e108a1Smrg		;;
669449e108a1Smrg	    esac
669549e108a1Smrg
669649e108a1Smrg            cat <<"EOF"
669749e108a1Smrgvoid lt_dump_script (FILE* f)
669849e108a1Smrg{
669949e108a1SmrgEOF
670049e108a1Smrg	    func_emit_wrapper yes |
6701e494fffdSmrg	      $SED -n -e '
6702e494fffdSmrgs/^\(.\{79\}\)\(..*\)/\1\
6703e494fffdSmrg\2/
6704e494fffdSmrgh
6705e494fffdSmrgs/\([\\"]\)/\\\1/g
6706e494fffdSmrgs/$/\\n/
6707e494fffdSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708e494fffdSmrgg
6709e494fffdSmrgD'
671049e108a1Smrg            cat <<"EOF"
671149e108a1Smrg}
6712f05b35a2SmrgEOF
6713f05b35a2Smrg}
6714f05b35a2Smrg# end: func_emit_cwrapperexe_src
6715e0963edeSmrg
671649e108a1Smrg# func_win32_import_lib_p ARG
671749e108a1Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671849e108a1Smrgfunc_win32_import_lib_p ()
671949e108a1Smrg{
6720b3a827e2Smrg    $debug_cmd
6721b3a827e2Smrg
672249e108a1Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
672349e108a1Smrg    *import*) : ;;
672449e108a1Smrg    *) false ;;
672549e108a1Smrg    esac
672649e108a1Smrg}
672749e108a1Smrg
6728b3a827e2Smrg# func_suncc_cstd_abi
6729b3a827e2Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730b3a827e2Smrg# Several compiler flags select an ABI that is incompatible with the
6731b3a827e2Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732b3a827e2Smrgfunc_suncc_cstd_abi ()
6733b3a827e2Smrg{
6734b3a827e2Smrg    $debug_cmd
6735b3a827e2Smrg
6736b3a827e2Smrg    case " $compile_command " in
6737b3a827e2Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738b3a827e2Smrg      suncc_use_cstd_abi=no
6739b3a827e2Smrg      ;;
6740b3a827e2Smrg    *)
6741b3a827e2Smrg      suncc_use_cstd_abi=yes
6742b3a827e2Smrg      ;;
6743b3a827e2Smrg    esac
6744b3a827e2Smrg}
6745b3a827e2Smrg
6746f05b35a2Smrg# func_mode_link arg...
6747f05b35a2Smrgfunc_mode_link ()
6748f05b35a2Smrg{
6749b3a827e2Smrg    $debug_cmd
6750b3a827e2Smrg
6751f05b35a2Smrg    case $host in
6752f05b35a2Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6753f05b35a2Smrg      # It is impossible to link a dll without this setting, and
6754f05b35a2Smrg      # we shouldn't force the makefile maintainer to figure out
6755b3a827e2Smrg      # what system we are compiling for in order to pass an extra
6756f05b35a2Smrg      # flag for every libtool invocation.
6757f05b35a2Smrg      # allow_undefined=no
6758e0963edeSmrg
6759f05b35a2Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760b3a827e2Smrg      # to make a dll that has undefined symbols, in which case not
6761f05b35a2Smrg      # even a static library is built.  For now, we need to specify
6762f05b35a2Smrg      # -no-undefined on the libtool link line when we can be certain
6763f05b35a2Smrg      # that all symbols are satisfied, otherwise we get a static library.
6764f05b35a2Smrg      allow_undefined=yes
6765f05b35a2Smrg      ;;
6766f05b35a2Smrg    *)
6767f05b35a2Smrg      allow_undefined=yes
6768f05b35a2Smrg      ;;
6769f05b35a2Smrg    esac
6770f05b35a2Smrg    libtool_args=$nonopt
6771f05b35a2Smrg    base_compile="$nonopt $@"
6772f05b35a2Smrg    compile_command=$nonopt
6773f05b35a2Smrg    finalize_command=$nonopt
6774e0963edeSmrg
6775f05b35a2Smrg    compile_rpath=
6776f05b35a2Smrg    finalize_rpath=
6777f05b35a2Smrg    compile_shlibpath=
6778f05b35a2Smrg    finalize_shlibpath=
6779f05b35a2Smrg    convenience=
6780f05b35a2Smrg    old_convenience=
6781f05b35a2Smrg    deplibs=
6782f05b35a2Smrg    old_deplibs=
6783f05b35a2Smrg    compiler_flags=
6784f05b35a2Smrg    linker_flags=
6785f05b35a2Smrg    dllsearchpath=
6786f05b35a2Smrg    lib_search_path=`pwd`
6787f05b35a2Smrg    inst_prefix_dir=
6788f05b35a2Smrg    new_inherited_linker_flags=
6789e0963edeSmrg
6790f05b35a2Smrg    avoid_version=no
679149e108a1Smrg    bindir=
6792f05b35a2Smrg    dlfiles=
6793f05b35a2Smrg    dlprefiles=
6794f05b35a2Smrg    dlself=no
6795f05b35a2Smrg    export_dynamic=no
6796f05b35a2Smrg    export_symbols=
6797f05b35a2Smrg    export_symbols_regex=
6798f05b35a2Smrg    generated=
6799f05b35a2Smrg    libobjs=
6800f05b35a2Smrg    ltlibs=
6801f05b35a2Smrg    module=no
6802f05b35a2Smrg    no_install=no
6803f05b35a2Smrg    objs=
6804b3a827e2Smrg    os2dllname=
6805f05b35a2Smrg    non_pic_objects=
6806f05b35a2Smrg    precious_files_regex=
6807f05b35a2Smrg    prefer_static_libs=no
6808b3a827e2Smrg    preload=false
6809f05b35a2Smrg    prev=
6810f05b35a2Smrg    prevarg=
6811f05b35a2Smrg    release=
6812f05b35a2Smrg    rpath=
6813f05b35a2Smrg    xrpath=
6814f05b35a2Smrg    perm_rpath=
6815f05b35a2Smrg    temp_rpath=
6816f05b35a2Smrg    thread_safe=no
6817f05b35a2Smrg    vinfo=
6818f05b35a2Smrg    vinfo_number=no
6819f05b35a2Smrg    weak_libs=
6820b3a827e2Smrg    single_module=$wl-single_module
6821f05b35a2Smrg    func_infer_tag $base_compile
6822e0963edeSmrg
6823f05b35a2Smrg    # We need to know -static, to get the right output filenames.
6824f05b35a2Smrg    for arg
6825f05b35a2Smrg    do
6826f05b35a2Smrg      case $arg in
6827f05b35a2Smrg      -shared)
6828b3a827e2Smrg	test yes != "$build_libtool_libs" \
6829b3a827e2Smrg	  && func_fatal_configuration "cannot build a shared library"
6830f05b35a2Smrg	build_old_libs=no
6831f05b35a2Smrg	break
6832f05b35a2Smrg	;;
6833f05b35a2Smrg      -all-static | -static | -static-libtool-libs)
6834f05b35a2Smrg	case $arg in
6835f05b35a2Smrg	-all-static)
6836b3a827e2Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6837f05b35a2Smrg	    func_warning "complete static linking is impossible in this configuration"
6838f05b35a2Smrg	  fi
6839f05b35a2Smrg	  if test -n "$link_static_flag"; then
6840f05b35a2Smrg	    dlopen_self=$dlopen_self_static
6841f05b35a2Smrg	  fi
6842f05b35a2Smrg	  prefer_static_libs=yes
6843f05b35a2Smrg	  ;;
6844f05b35a2Smrg	-static)
6845f05b35a2Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6846f05b35a2Smrg	    dlopen_self=$dlopen_self_static
6847f05b35a2Smrg	  fi
6848f05b35a2Smrg	  prefer_static_libs=built
6849f05b35a2Smrg	  ;;
6850f05b35a2Smrg	-static-libtool-libs)
6851f05b35a2Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6852f05b35a2Smrg	    dlopen_self=$dlopen_self_static
6853f05b35a2Smrg	  fi
6854f05b35a2Smrg	  prefer_static_libs=yes
6855f05b35a2Smrg	  ;;
6856f05b35a2Smrg	esac
6857f05b35a2Smrg	build_libtool_libs=no
6858f05b35a2Smrg	build_old_libs=yes
6859f05b35a2Smrg	break
6860e0963edeSmrg	;;
6861e0963edeSmrg      esac
6862f05b35a2Smrg    done
6863e0963edeSmrg
6864f05b35a2Smrg    # See if our shared archives depend on static archives.
6865f05b35a2Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866e0963edeSmrg
6867f05b35a2Smrg    # Go through the arguments, transforming them on the way.
6868f05b35a2Smrg    while test "$#" -gt 0; do
6869b3a827e2Smrg      arg=$1
6870f05b35a2Smrg      shift
6871c30f5000Smrg      func_quote_arg pretty,unquoted "$arg"
6872c30f5000Smrg      qarg=$func_quote_arg_unquoted_result
6873c30f5000Smrg      func_append libtool_args " $func_quote_arg_result"
6874e0963edeSmrg
6875f05b35a2Smrg      # If the previous option needs an argument, assign it.
6876f05b35a2Smrg      if test -n "$prev"; then
6877f05b35a2Smrg	case $prev in
6878f05b35a2Smrg	output)
6879f05b35a2Smrg	  func_append compile_command " @OUTPUT@"
6880f05b35a2Smrg	  func_append finalize_command " @OUTPUT@"
6881e0963edeSmrg	  ;;
6882e0963edeSmrg	esac
6883e0963edeSmrg
6884f05b35a2Smrg	case $prev in
688549e108a1Smrg	bindir)
6886b3a827e2Smrg	  bindir=$arg
688749e108a1Smrg	  prev=
688849e108a1Smrg	  continue
688949e108a1Smrg	  ;;
6890f05b35a2Smrg	dlfiles|dlprefiles)
6891b3a827e2Smrg	  $preload || {
6892f05b35a2Smrg	    # Add the symbol object into the linking commands.
6893f05b35a2Smrg	    func_append compile_command " @SYMFILE@"
6894f05b35a2Smrg	    func_append finalize_command " @SYMFILE@"
6895b3a827e2Smrg	    preload=:
6896b3a827e2Smrg	  }
6897f05b35a2Smrg	  case $arg in
6898f05b35a2Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6899f05b35a2Smrg	  force)
6900b3a827e2Smrg	    if test no = "$dlself"; then
6901f05b35a2Smrg	      dlself=needless
6902f05b35a2Smrg	      export_dynamic=yes
6903f05b35a2Smrg	    fi
6904f05b35a2Smrg	    prev=
6905f05b35a2Smrg	    continue
6906f05b35a2Smrg	    ;;
6907f05b35a2Smrg	  self)
6908b3a827e2Smrg	    if test dlprefiles = "$prev"; then
6909f05b35a2Smrg	      dlself=yes
6910b3a827e2Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6911f05b35a2Smrg	      dlself=yes
6912e0963edeSmrg	    else
6913f05b35a2Smrg	      dlself=needless
6914f05b35a2Smrg	      export_dynamic=yes
6915e0963edeSmrg	    fi
6916f05b35a2Smrg	    prev=
6917f05b35a2Smrg	    continue
6918f05b35a2Smrg	    ;;
6919f05b35a2Smrg	  *)
6920b3a827e2Smrg	    if test dlfiles = "$prev"; then
692167ab2ff2Smrg	      func_append dlfiles " $arg"
6922f05b35a2Smrg	    else
692367ab2ff2Smrg	      func_append dlprefiles " $arg"
6924f05b35a2Smrg	    fi
6925f05b35a2Smrg	    prev=
6926f05b35a2Smrg	    continue
6927f05b35a2Smrg	    ;;
6928e0963edeSmrg	  esac
6929e0963edeSmrg	  ;;
6930f05b35a2Smrg	expsyms)
6931b3a827e2Smrg	  export_symbols=$arg
6932f05b35a2Smrg	  test -f "$arg" \
6933b3a827e2Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
6934f05b35a2Smrg	  prev=
6935f05b35a2Smrg	  continue
6936f05b35a2Smrg	  ;;
6937f05b35a2Smrg	expsyms_regex)
6938b3a827e2Smrg	  export_symbols_regex=$arg
6939f05b35a2Smrg	  prev=
6940f05b35a2Smrg	  continue
6941f05b35a2Smrg	  ;;
6942f05b35a2Smrg	framework)
6943f05b35a2Smrg	  case $host in
6944f05b35a2Smrg	    *-*-darwin*)
6945f05b35a2Smrg	      case "$deplibs " in
6946f05b35a2Smrg		*" $qarg.ltframework "*) ;;
694767ab2ff2Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6948f05b35a2Smrg		   ;;
6949e0963edeSmrg	      esac
6950f05b35a2Smrg	      ;;
6951e0963edeSmrg	  esac
6952f05b35a2Smrg	  prev=
6953f05b35a2Smrg	  continue
6954f05b35a2Smrg	  ;;
6955f05b35a2Smrg	inst_prefix)
6956b3a827e2Smrg	  inst_prefix_dir=$arg
6957b3a827e2Smrg	  prev=
6958b3a827e2Smrg	  continue
6959b3a827e2Smrg	  ;;
6960b3a827e2Smrg	mllvm)
6961b3a827e2Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6962b3a827e2Smrg	  # '-mllvm $arg' options when doing the link step.
6963f05b35a2Smrg	  prev=
6964f05b35a2Smrg	  continue
6965f05b35a2Smrg	  ;;
6966f05b35a2Smrg	objectlist)
6967f05b35a2Smrg	  if test -f "$arg"; then
6968f05b35a2Smrg	    save_arg=$arg
6969f05b35a2Smrg	    moreargs=
6970f05b35a2Smrg	    for fil in `cat "$save_arg"`
6971f05b35a2Smrg	    do
697267ab2ff2Smrg#	      func_append moreargs " $fil"
6973f05b35a2Smrg	      arg=$fil
6974f05b35a2Smrg	      # A libtool-controlled object.
6975e0963edeSmrg
6976f05b35a2Smrg	      # Check to see that this really is a libtool object.
6977f05b35a2Smrg	      if func_lalib_unsafe_p "$arg"; then
6978f05b35a2Smrg		pic_object=
6979f05b35a2Smrg		non_pic_object=
6980e0963edeSmrg
6981f05b35a2Smrg		# Read the .lo file
6982f05b35a2Smrg		func_source "$arg"
6983e0963edeSmrg
6984f05b35a2Smrg		if test -z "$pic_object" ||
6985f05b35a2Smrg		   test -z "$non_pic_object" ||
6986b3a827e2Smrg		   test none = "$pic_object" &&
6987b3a827e2Smrg		   test none = "$non_pic_object"; then
6988b3a827e2Smrg		  func_fatal_error "cannot find name of object for '$arg'"
6989f05b35a2Smrg		fi
6990e0963edeSmrg
6991f05b35a2Smrg		# Extract subdirectory from the argument.
6992f05b35a2Smrg		func_dirname "$arg" "/" ""
6993b3a827e2Smrg		xdir=$func_dirname_result
6994e0963edeSmrg
6995b3a827e2Smrg		if test none != "$pic_object"; then
6996f05b35a2Smrg		  # Prepend the subdirectory the object is found in.
6997b3a827e2Smrg		  pic_object=$xdir$pic_object
6998e0963edeSmrg
6999b3a827e2Smrg		  if test dlfiles = "$prev"; then
7000b3a827e2Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
700167ab2ff2Smrg		      func_append dlfiles " $pic_object"
7002f05b35a2Smrg		      prev=
7003f05b35a2Smrg		      continue
7004f05b35a2Smrg		    else
7005f05b35a2Smrg		      # If libtool objects are unsupported, then we need to preload.
7006f05b35a2Smrg		      prev=dlprefiles
7007f05b35a2Smrg		    fi
7008f05b35a2Smrg		  fi
7009e0963edeSmrg
7010f05b35a2Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011b3a827e2Smrg		  if test dlprefiles = "$prev"; then
7012f05b35a2Smrg		    # Preload the old-style object.
701367ab2ff2Smrg		    func_append dlprefiles " $pic_object"
7014f05b35a2Smrg		    prev=
7015f05b35a2Smrg		  fi
7016e0963edeSmrg
7017f05b35a2Smrg		  # A PIC object.
7018f05b35a2Smrg		  func_append libobjs " $pic_object"
7019b3a827e2Smrg		  arg=$pic_object
7020f05b35a2Smrg		fi
7021e0963edeSmrg
7022f05b35a2Smrg		# Non-PIC object.
7023b3a827e2Smrg		if test none != "$non_pic_object"; then
7024f05b35a2Smrg		  # Prepend the subdirectory the object is found in.
7025b3a827e2Smrg		  non_pic_object=$xdir$non_pic_object
7026e0963edeSmrg
7027f05b35a2Smrg		  # A standard non-PIC object
7028f05b35a2Smrg		  func_append non_pic_objects " $non_pic_object"
7029b3a827e2Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030b3a827e2Smrg		    arg=$non_pic_object
7031f05b35a2Smrg		  fi
7032f05b35a2Smrg		else
7033f05b35a2Smrg		  # If the PIC object exists, use it instead.
7034f05b35a2Smrg		  # $xdir was prepended to $pic_object above.
7035b3a827e2Smrg		  non_pic_object=$pic_object
7036f05b35a2Smrg		  func_append non_pic_objects " $non_pic_object"
7037f05b35a2Smrg		fi
7038f05b35a2Smrg	      else
7039f05b35a2Smrg		# Only an error if not doing a dry-run.
7040f05b35a2Smrg		if $opt_dry_run; then
7041f05b35a2Smrg		  # Extract subdirectory from the argument.
7042f05b35a2Smrg		  func_dirname "$arg" "/" ""
7043b3a827e2Smrg		  xdir=$func_dirname_result
7044f05b35a2Smrg
7045f05b35a2Smrg		  func_lo2o "$arg"
7046f05b35a2Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7047f05b35a2Smrg		  non_pic_object=$xdir$func_lo2o_result
7048f05b35a2Smrg		  func_append libobjs " $pic_object"
7049f05b35a2Smrg		  func_append non_pic_objects " $non_pic_object"
7050f05b35a2Smrg	        else
7051b3a827e2Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
7052f05b35a2Smrg		fi
7053f05b35a2Smrg	      fi
7054e0963edeSmrg	    done
7055f05b35a2Smrg	  else
7056b3a827e2Smrg	    func_fatal_error "link input file '$arg' does not exist"
7057e0963edeSmrg	  fi
7058f05b35a2Smrg	  arg=$save_arg
7059f05b35a2Smrg	  prev=
7060f05b35a2Smrg	  continue
7061f05b35a2Smrg	  ;;
7062b3a827e2Smrg	os2dllname)
7063b3a827e2Smrg	  os2dllname=$arg
7064b3a827e2Smrg	  prev=
7065b3a827e2Smrg	  continue
7066b3a827e2Smrg	  ;;
7067f05b35a2Smrg	precious_regex)
7068b3a827e2Smrg	  precious_files_regex=$arg
7069f05b35a2Smrg	  prev=
7070f05b35a2Smrg	  continue
7071f05b35a2Smrg	  ;;
7072f05b35a2Smrg	release)
7073b3a827e2Smrg	  release=-$arg
7074f05b35a2Smrg	  prev=
7075f05b35a2Smrg	  continue
7076f05b35a2Smrg	  ;;
7077f05b35a2Smrg	rpath | xrpath)
7078f05b35a2Smrg	  # We need an absolute path.
7079f05b35a2Smrg	  case $arg in
7080f05b35a2Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7081f05b35a2Smrg	  *)
7082f05b35a2Smrg	    func_fatal_error "only absolute run-paths are allowed"
7083f05b35a2Smrg	    ;;
7084e0963edeSmrg	  esac
7085b3a827e2Smrg	  if test rpath = "$prev"; then
7086f05b35a2Smrg	    case "$rpath " in
7087f05b35a2Smrg	    *" $arg "*) ;;
708867ab2ff2Smrg	    *) func_append rpath " $arg" ;;
7089f05b35a2Smrg	    esac
7090f05b35a2Smrg	  else
7091f05b35a2Smrg	    case "$xrpath " in
7092f05b35a2Smrg	    *" $arg "*) ;;
709367ab2ff2Smrg	    *) func_append xrpath " $arg" ;;
7094f05b35a2Smrg	    esac
7095f05b35a2Smrg	  fi
7096f05b35a2Smrg	  prev=
7097f05b35a2Smrg	  continue
7098f05b35a2Smrg	  ;;
7099f05b35a2Smrg	shrext)
7100b3a827e2Smrg	  shrext_cmds=$arg
7101f05b35a2Smrg	  prev=
7102f05b35a2Smrg	  continue
7103f05b35a2Smrg	  ;;
7104f05b35a2Smrg	weak)
710567ab2ff2Smrg	  func_append weak_libs " $arg"
7106f05b35a2Smrg	  prev=
7107f05b35a2Smrg	  continue
7108f05b35a2Smrg	  ;;
7109c30f5000Smrg	xassembler)
7110c30f5000Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111c30f5000Smrg	  prev=
7112c30f5000Smrg	  func_append compile_command " -Xassembler $qarg"
7113c30f5000Smrg	  func_append finalize_command " -Xassembler $qarg"
7114c30f5000Smrg	  continue
7115c30f5000Smrg	  ;;
7116f05b35a2Smrg	xcclinker)
711767ab2ff2Smrg	  func_append linker_flags " $qarg"
711867ab2ff2Smrg	  func_append compiler_flags " $qarg"
7119f05b35a2Smrg	  prev=
7120f05b35a2Smrg	  func_append compile_command " $qarg"
7121f05b35a2Smrg	  func_append finalize_command " $qarg"
7122f05b35a2Smrg	  continue
7123f05b35a2Smrg	  ;;
7124f05b35a2Smrg	xcompiler)
712567ab2ff2Smrg	  func_append compiler_flags " $qarg"
7126f05b35a2Smrg	  prev=
7127f05b35a2Smrg	  func_append compile_command " $qarg"
7128f05b35a2Smrg	  func_append finalize_command " $qarg"
7129f05b35a2Smrg	  continue
7130f05b35a2Smrg	  ;;
7131f05b35a2Smrg	xlinker)
713267ab2ff2Smrg	  func_append linker_flags " $qarg"
713367ab2ff2Smrg	  func_append compiler_flags " $wl$qarg"
7134f05b35a2Smrg	  prev=
7135f05b35a2Smrg	  func_append compile_command " $wl$qarg"
7136f05b35a2Smrg	  func_append finalize_command " $wl$qarg"
7137f05b35a2Smrg	  continue
7138e0963edeSmrg	  ;;
7139e0963edeSmrg	*)
7140f05b35a2Smrg	  eval "$prev=\"\$arg\""
7141f05b35a2Smrg	  prev=
7142f05b35a2Smrg	  continue
7143e0963edeSmrg	  ;;
7144e0963edeSmrg	esac
7145f05b35a2Smrg      fi # test -n "$prev"
7146e0963edeSmrg
7147b3a827e2Smrg      prevarg=$arg
7148e0963edeSmrg
7149f05b35a2Smrg      case $arg in
7150f05b35a2Smrg      -all-static)
7151f05b35a2Smrg	if test -n "$link_static_flag"; then
7152f05b35a2Smrg	  # See comment for -static flag below, for more details.
7153f05b35a2Smrg	  func_append compile_command " $link_static_flag"
7154f05b35a2Smrg	  func_append finalize_command " $link_static_flag"
7155e0963edeSmrg	fi
7156f05b35a2Smrg	continue
7157f05b35a2Smrg	;;
7158e0963edeSmrg
7159f05b35a2Smrg      -allow-undefined)
7160f05b35a2Smrg	# FIXME: remove this flag sometime in the future.
7161b3a827e2Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7162f05b35a2Smrg	;;
7163e0963edeSmrg
7164f05b35a2Smrg      -avoid-version)
7165f05b35a2Smrg	avoid_version=yes
7166f05b35a2Smrg	continue
7167f05b35a2Smrg	;;
7168e0963edeSmrg
716949e108a1Smrg      -bindir)
717049e108a1Smrg	prev=bindir
717149e108a1Smrg	continue
717249e108a1Smrg	;;
717349e108a1Smrg
7174f05b35a2Smrg      -dlopen)
7175f05b35a2Smrg	prev=dlfiles
7176f05b35a2Smrg	continue
7177f05b35a2Smrg	;;
7178e0963edeSmrg
7179f05b35a2Smrg      -dlpreopen)
7180f05b35a2Smrg	prev=dlprefiles
7181f05b35a2Smrg	continue
7182f05b35a2Smrg	;;
7183e0963edeSmrg
7184f05b35a2Smrg      -export-dynamic)
7185f05b35a2Smrg	export_dynamic=yes
7186f05b35a2Smrg	continue
7187f05b35a2Smrg	;;
7188e0963edeSmrg
7189f05b35a2Smrg      -export-symbols | -export-symbols-regex)
7190f05b35a2Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7191f05b35a2Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7192f05b35a2Smrg	fi
7193b3a827e2Smrg	if test X-export-symbols = "X$arg"; then
7194f05b35a2Smrg	  prev=expsyms
7195e0963edeSmrg	else
7196f05b35a2Smrg	  prev=expsyms_regex
7197e0963edeSmrg	fi
7198f05b35a2Smrg	continue
7199f05b35a2Smrg	;;
7200e0963edeSmrg
7201f05b35a2Smrg      -framework)
7202f05b35a2Smrg	prev=framework
7203f05b35a2Smrg	continue
7204f05b35a2Smrg	;;
7205e0963edeSmrg
7206f05b35a2Smrg      -inst-prefix-dir)
7207f05b35a2Smrg	prev=inst_prefix
7208f05b35a2Smrg	continue
7209f05b35a2Smrg	;;
7210e0963edeSmrg
7211f05b35a2Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7212f05b35a2Smrg      # so, if we see these flags be careful not to treat them like -L
7213f05b35a2Smrg      -L[A-Z][A-Z]*:*)
7214f05b35a2Smrg	case $with_gcc/$host in
7215f05b35a2Smrg	no/*-*-irix* | /*-*-irix*)
7216f05b35a2Smrg	  func_append compile_command " $arg"
7217f05b35a2Smrg	  func_append finalize_command " $arg"
7218f05b35a2Smrg	  ;;
7219f05b35a2Smrg	esac
7220f05b35a2Smrg	continue
7221f05b35a2Smrg	;;
7222e0963edeSmrg
7223f05b35a2Smrg      -L*)
722467ab2ff2Smrg	func_stripname "-L" '' "$arg"
722567ab2ff2Smrg	if test -z "$func_stripname_result"; then
7226f05b35a2Smrg	  if test "$#" -gt 0; then
7227b3a827e2Smrg	    func_fatal_error "require no space between '-L' and '$1'"
7228e0963edeSmrg	  else
7229b3a827e2Smrg	    func_fatal_error "need path for '-L' option"
7230e0963edeSmrg	  fi
7231f05b35a2Smrg	fi
723267ab2ff2Smrg	func_resolve_sysroot "$func_stripname_result"
723367ab2ff2Smrg	dir=$func_resolve_sysroot_result
7234f05b35a2Smrg	# We need an absolute path.
7235f05b35a2Smrg	case $dir in
7236f05b35a2Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7237f05b35a2Smrg	*)
7238f05b35a2Smrg	  absdir=`cd "$dir" && pwd`
7239f05b35a2Smrg	  test -z "$absdir" && \
7240b3a827e2Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241b3a827e2Smrg	  dir=$absdir
7242f05b35a2Smrg	  ;;
7243e0963edeSmrg	esac
7244f05b35a2Smrg	case "$deplibs " in
724567ab2ff2Smrg	*" -L$dir "* | *" $arg "*)
724667ab2ff2Smrg	  # Will only happen for absolute or sysroot arguments
724767ab2ff2Smrg	  ;;
7248f05b35a2Smrg	*)
724967ab2ff2Smrg	  # Preserve sysroot, but never include relative directories
725067ab2ff2Smrg	  case $dir in
725167ab2ff2Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
725267ab2ff2Smrg	    *) func_append deplibs " -L$dir" ;;
725367ab2ff2Smrg	  esac
725467ab2ff2Smrg	  func_append lib_search_path " $dir"
7255f05b35a2Smrg	  ;;
7256e0963edeSmrg	esac
7257e0963edeSmrg	case $host in
7258f05b35a2Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725949e108a1Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7260f05b35a2Smrg	  case :$dllsearchpath: in
7261f05b35a2Smrg	  *":$dir:"*) ;;
7262f05b35a2Smrg	  ::) dllsearchpath=$dir;;
726367ab2ff2Smrg	  *) func_append dllsearchpath ":$dir";;
7264f05b35a2Smrg	  esac
7265f05b35a2Smrg	  case :$dllsearchpath: in
7266f05b35a2Smrg	  *":$testbindir:"*) ;;
7267f05b35a2Smrg	  ::) dllsearchpath=$testbindir;;
726867ab2ff2Smrg	  *) func_append dllsearchpath ":$testbindir";;
7269f05b35a2Smrg	  esac
7270f05b35a2Smrg	  ;;
7271e0963edeSmrg	esac
7272f05b35a2Smrg	continue
7273f05b35a2Smrg	;;
7274e0963edeSmrg
7275f05b35a2Smrg      -l*)
7276b3a827e2Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7277f05b35a2Smrg	  case $host in
727849e108a1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7279f05b35a2Smrg	    # These systems don't actually have a C or math library (as such)
7280f05b35a2Smrg	    continue
7281f05b35a2Smrg	    ;;
7282f05b35a2Smrg	  *-*-os2*)
7283f05b35a2Smrg	    # These systems don't actually have a C library (as such)
7284b3a827e2Smrg	    test X-lc = "X$arg" && continue
7285f05b35a2Smrg	    ;;
7286c30f5000Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7287f05b35a2Smrg	    # Do not include libc due to us having libc/libc_r.
7288b3a827e2Smrg	    test X-lc = "X$arg" && continue
7289f05b35a2Smrg	    ;;
7290f05b35a2Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7291f05b35a2Smrg	    # Rhapsody C and math libraries are in the System framework
729267ab2ff2Smrg	    func_append deplibs " System.ltframework"
7293f05b35a2Smrg	    continue
7294f05b35a2Smrg	    ;;
7295f05b35a2Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7296f05b35a2Smrg	    # Causes problems with __ctype
7297b3a827e2Smrg	    test X-lc = "X$arg" && continue
7298f05b35a2Smrg	    ;;
7299f05b35a2Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7300f05b35a2Smrg	    # Compiler inserts libc in the correct place for threads to work
7301b3a827e2Smrg	    test X-lc = "X$arg" && continue
7302f05b35a2Smrg	    ;;
7303f05b35a2Smrg	  esac
7304b3a827e2Smrg	elif test X-lc_r = "X$arg"; then
7305f05b35a2Smrg	 case $host in
7306c30f5000Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7307f05b35a2Smrg	   # Do not include libc_r directly, use -pthread flag.
7308f05b35a2Smrg	   continue
7309f05b35a2Smrg	   ;;
7310f05b35a2Smrg	 esac
7311f05b35a2Smrg	fi
731267ab2ff2Smrg	func_append deplibs " $arg"
7313f05b35a2Smrg	continue
7314f05b35a2Smrg	;;
7315e0963edeSmrg
7316b3a827e2Smrg      -mllvm)
7317b3a827e2Smrg	prev=mllvm
7318b3a827e2Smrg	continue
7319b3a827e2Smrg	;;
7320b3a827e2Smrg
7321f05b35a2Smrg      -module)
7322f05b35a2Smrg	module=yes
7323f05b35a2Smrg	continue
7324f05b35a2Smrg	;;
7325e0963edeSmrg
7326f05b35a2Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7327f05b35a2Smrg      # classes, name mangling, and exception handling.
7328f05b35a2Smrg      # Darwin uses the -arch flag to determine output architecture.
732967ab2ff2Smrg      -model|-arch|-isysroot|--sysroot)
733067ab2ff2Smrg	func_append compiler_flags " $arg"
7331f05b35a2Smrg	func_append compile_command " $arg"
7332f05b35a2Smrg	func_append finalize_command " $arg"
7333f05b35a2Smrg	prev=xcompiler
7334f05b35a2Smrg	continue
7335f05b35a2Smrg	;;
7336c30f5000Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337c30f5000Smrg     -pthread)
7338c30f5000Smrg	case $host in
7339c30f5000Smrg	  *solaris2*) ;;
7340c30f5000Smrg	  *)
7341c30f5000Smrg	    case "$new_inherited_linker_flags " in
7342c30f5000Smrg	        *" $arg "*) ;;
7343c30f5000Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344c30f5000Smrg	    esac
7345c30f5000Smrg	  ;;
7346c30f5000Smrg	esac
7347c30f5000Smrg	continue
7348c30f5000Smrg	;;
7349c30f5000Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350e494fffdSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
735167ab2ff2Smrg	func_append compiler_flags " $arg"
7352f05b35a2Smrg	func_append compile_command " $arg"
7353f05b35a2Smrg	func_append finalize_command " $arg"
7354f05b35a2Smrg	case "$new_inherited_linker_flags " in
7355f05b35a2Smrg	    *" $arg "*) ;;
735667ab2ff2Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7357f05b35a2Smrg	esac
7358f05b35a2Smrg	continue
7359f05b35a2Smrg	;;
7360e0963edeSmrg
7361f05b35a2Smrg      -multi_module)
7362b3a827e2Smrg	single_module=$wl-multi_module
7363f05b35a2Smrg	continue
7364f05b35a2Smrg	;;
7365e0963edeSmrg
7366f05b35a2Smrg      -no-fast-install)
7367f05b35a2Smrg	fast_install=no
7368f05b35a2Smrg	continue
7369f05b35a2Smrg	;;
7370e0963edeSmrg
7371f05b35a2Smrg      -no-install)
7372f05b35a2Smrg	case $host in
7373f05b35a2Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7374f05b35a2Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7375f05b35a2Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376b3a827e2Smrg	  func_warning "'-no-install' is ignored for $host"
7377b3a827e2Smrg	  func_warning "assuming '-no-fast-install' instead"
7378f05b35a2Smrg	  fast_install=no
7379f05b35a2Smrg	  ;;
7380f05b35a2Smrg	*) no_install=yes ;;
7381f05b35a2Smrg	esac
7382f05b35a2Smrg	continue
7383f05b35a2Smrg	;;
7384e0963edeSmrg
7385f05b35a2Smrg      -no-undefined)
7386f05b35a2Smrg	allow_undefined=no
7387f05b35a2Smrg	continue
7388f05b35a2Smrg	;;
7389e0963edeSmrg
7390f05b35a2Smrg      -objectlist)
7391f05b35a2Smrg	prev=objectlist
7392f05b35a2Smrg	continue
7393f05b35a2Smrg	;;
7394e0963edeSmrg
7395b3a827e2Smrg      -os2dllname)
7396b3a827e2Smrg	prev=os2dllname
7397b3a827e2Smrg	continue
7398b3a827e2Smrg	;;
7399b3a827e2Smrg
7400f05b35a2Smrg      -o) prev=output ;;
7401e0963edeSmrg
7402f05b35a2Smrg      -precious-files-regex)
7403f05b35a2Smrg	prev=precious_regex
7404f05b35a2Smrg	continue
7405f05b35a2Smrg	;;
7406e0963edeSmrg
7407f05b35a2Smrg      -release)
7408f05b35a2Smrg	prev=release
7409f05b35a2Smrg	continue
7410f05b35a2Smrg	;;
7411e0963edeSmrg
7412f05b35a2Smrg      -rpath)
7413f05b35a2Smrg	prev=rpath
7414f05b35a2Smrg	continue
7415f05b35a2Smrg	;;
7416e0963edeSmrg
7417f05b35a2Smrg      -R)
7418f05b35a2Smrg	prev=xrpath
7419f05b35a2Smrg	continue
7420f05b35a2Smrg	;;
7421e0963edeSmrg
7422f05b35a2Smrg      -R*)
7423f05b35a2Smrg	func_stripname '-R' '' "$arg"
7424f05b35a2Smrg	dir=$func_stripname_result
7425f05b35a2Smrg	# We need an absolute path.
7426f05b35a2Smrg	case $dir in
7427f05b35a2Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
742867ab2ff2Smrg	=*)
742967ab2ff2Smrg	  func_stripname '=' '' "$dir"
743067ab2ff2Smrg	  dir=$lt_sysroot$func_stripname_result
743167ab2ff2Smrg	  ;;
7432f05b35a2Smrg	*)
7433f05b35a2Smrg	  func_fatal_error "only absolute run-paths are allowed"
7434f05b35a2Smrg	  ;;
7435f05b35a2Smrg	esac
7436f05b35a2Smrg	case "$xrpath " in
7437f05b35a2Smrg	*" $dir "*) ;;
743867ab2ff2Smrg	*) func_append xrpath " $dir" ;;
7439f05b35a2Smrg	esac
7440f05b35a2Smrg	continue
7441f05b35a2Smrg	;;
7442e0963edeSmrg
7443f05b35a2Smrg      -shared)
7444f05b35a2Smrg	# The effects of -shared are defined in a previous loop.
7445f05b35a2Smrg	continue
7446f05b35a2Smrg	;;
7447e0963edeSmrg
7448f05b35a2Smrg      -shrext)
7449f05b35a2Smrg	prev=shrext
7450f05b35a2Smrg	continue
7451f05b35a2Smrg	;;
7452e0963edeSmrg
7453f05b35a2Smrg      -static | -static-libtool-libs)
7454f05b35a2Smrg	# The effects of -static are defined in a previous loop.
7455f05b35a2Smrg	# We used to do the same as -all-static on platforms that
7456f05b35a2Smrg	# didn't have a PIC flag, but the assumption that the effects
7457f05b35a2Smrg	# would be equivalent was wrong.  It would break on at least
7458f05b35a2Smrg	# Digital Unix and AIX.
7459f05b35a2Smrg	continue
7460f05b35a2Smrg	;;
7461e0963edeSmrg
7462f05b35a2Smrg      -thread-safe)
7463f05b35a2Smrg	thread_safe=yes
7464f05b35a2Smrg	continue
7465f05b35a2Smrg	;;
7466e0963edeSmrg
7467f05b35a2Smrg      -version-info)
7468f05b35a2Smrg	prev=vinfo
7469f05b35a2Smrg	continue
7470f05b35a2Smrg	;;
7471e0963edeSmrg
7472f05b35a2Smrg      -version-number)
7473f05b35a2Smrg	prev=vinfo
7474f05b35a2Smrg	vinfo_number=yes
7475f05b35a2Smrg	continue
7476f05b35a2Smrg	;;
7477e0963edeSmrg
7478f05b35a2Smrg      -weak)
7479f05b35a2Smrg        prev=weak
7480f05b35a2Smrg	continue
7481f05b35a2Smrg	;;
7482e0963edeSmrg
7483f05b35a2Smrg      -Wc,*)
7484f05b35a2Smrg	func_stripname '-Wc,' '' "$arg"
7485f05b35a2Smrg	args=$func_stripname_result
7486f05b35a2Smrg	arg=
7487b3a827e2Smrg	save_ifs=$IFS; IFS=,
7488f05b35a2Smrg	for flag in $args; do
7489b3a827e2Smrg	  IFS=$save_ifs
7490c30f5000Smrg          func_quote_arg pretty "$flag"
7491c30f5000Smrg	  func_append arg " $func_quote_arg_result"
7492c30f5000Smrg	  func_append compiler_flags " $func_quote_arg_result"
7493f05b35a2Smrg	done
7494b3a827e2Smrg	IFS=$save_ifs
7495f05b35a2Smrg	func_stripname ' ' '' "$arg"
7496f05b35a2Smrg	arg=$func_stripname_result
7497f05b35a2Smrg	;;
7498e0963edeSmrg
7499f05b35a2Smrg      -Wl,*)
7500f05b35a2Smrg	func_stripname '-Wl,' '' "$arg"
7501f05b35a2Smrg	args=$func_stripname_result
7502f05b35a2Smrg	arg=
7503b3a827e2Smrg	save_ifs=$IFS; IFS=,
7504f05b35a2Smrg	for flag in $args; do
7505b3a827e2Smrg	  IFS=$save_ifs
7506c30f5000Smrg          func_quote_arg pretty "$flag"
7507c30f5000Smrg	  func_append arg " $wl$func_quote_arg_result"
7508c30f5000Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509c30f5000Smrg	  func_append linker_flags " $func_quote_arg_result"
7510f05b35a2Smrg	done
7511b3a827e2Smrg	IFS=$save_ifs
7512f05b35a2Smrg	func_stripname ' ' '' "$arg"
7513f05b35a2Smrg	arg=$func_stripname_result
7514f05b35a2Smrg	;;
7515e0963edeSmrg
7516c30f5000Smrg      -Xassembler)
7517c30f5000Smrg        prev=xassembler
7518c30f5000Smrg        continue
7519c30f5000Smrg        ;;
7520c30f5000Smrg
7521f05b35a2Smrg      -Xcompiler)
7522f05b35a2Smrg	prev=xcompiler
7523f05b35a2Smrg	continue
7524f05b35a2Smrg	;;
7525e0963edeSmrg
7526f05b35a2Smrg      -Xlinker)
7527f05b35a2Smrg	prev=xlinker
7528f05b35a2Smrg	continue
7529f05b35a2Smrg	;;
7530e0963edeSmrg
7531f05b35a2Smrg      -XCClinker)
7532f05b35a2Smrg	prev=xcclinker
7533f05b35a2Smrg	continue
7534f05b35a2Smrg	;;
7535e0963edeSmrg
7536f05b35a2Smrg      # -msg_* for osf cc
7537f05b35a2Smrg      -msg_*)
7538c30f5000Smrg	func_quote_arg pretty "$arg"
7539c30f5000Smrg	arg=$func_quote_arg_result
7540f05b35a2Smrg	;;
7541e0963edeSmrg
754249e108a1Smrg      # Flags to be passed through unchanged, with rationale:
754349e108a1Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
754449e108a1Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
754549e108a1Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
754649e108a1Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754749e108a1Smrg      # -q*                  compiler args for the IBM compiler
754849e108a1Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754949e108a1Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
755049e108a1Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551b3a827e2Smrg      # -fstack-protector*   stack protector flags for GCC
755249e108a1Smrg      # @file                GCC response files
755349e108a1Smrg      # -tp=*                Portland pgcc target processor selection
755467ab2ff2Smrg      # --sysroot=*          for sysroot support
7555b3a827e2Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556b3a827e2Smrg      # -specs=*             GCC specs files
7557b3a827e2Smrg      # -stdlib=*            select c++ std lib with clang
7558c30f5000Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559c30f5000Smrg      # -fuse-ld=*           Linker select flags for GCC
7560c30f5000Smrg      # -Wa,*                Pass flags directly to the assembler
7561f05b35a2Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
756267ab2ff2Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563b3a827e2Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564c30f5000Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565c30f5000Smrg        func_quote_arg pretty "$arg"
7566c30f5000Smrg	arg=$func_quote_arg_result
7567f05b35a2Smrg        func_append compile_command " $arg"
7568f05b35a2Smrg        func_append finalize_command " $arg"
756967ab2ff2Smrg        func_append compiler_flags " $arg"
7570f05b35a2Smrg        continue
7571f05b35a2Smrg        ;;
7572e0963edeSmrg
7573b3a827e2Smrg      -Z*)
7574b3a827e2Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575b3a827e2Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576b3a827e2Smrg	  compiler_flags="$compiler_flags $arg"
7577b3a827e2Smrg	  func_append compile_command " $arg"
7578b3a827e2Smrg	  func_append finalize_command " $arg"
7579b3a827e2Smrg	  case $arg in
7580b3a827e2Smrg	  -Zlinker | -Zstack)
7581b3a827e2Smrg	    prev=xcompiler
7582b3a827e2Smrg	    ;;
7583b3a827e2Smrg	  esac
7584b3a827e2Smrg	  continue
7585b3a827e2Smrg        else
7586b3a827e2Smrg	  # Otherwise treat like 'Some other compiler flag' below
7587c30f5000Smrg	  func_quote_arg pretty "$arg"
7588c30f5000Smrg	  arg=$func_quote_arg_result
7589b3a827e2Smrg        fi
7590b3a827e2Smrg	;;
7591b3a827e2Smrg
7592f05b35a2Smrg      # Some other compiler flag.
7593f05b35a2Smrg      -* | +*)
7594c30f5000Smrg        func_quote_arg pretty "$arg"
7595c30f5000Smrg	arg=$func_quote_arg_result
7596f05b35a2Smrg	;;
7597e0963edeSmrg
7598f05b35a2Smrg      *.$objext)
7599f05b35a2Smrg	# A standard object.
760067ab2ff2Smrg	func_append objs " $arg"
7601f05b35a2Smrg	;;
7602e0963edeSmrg
7603f05b35a2Smrg      *.lo)
7604f05b35a2Smrg	# A libtool-controlled object.
7605e0963edeSmrg
7606f05b35a2Smrg	# Check to see that this really is a libtool object.
7607f05b35a2Smrg	if func_lalib_unsafe_p "$arg"; then
7608f05b35a2Smrg	  pic_object=
7609f05b35a2Smrg	  non_pic_object=
7610e0963edeSmrg
7611f05b35a2Smrg	  # Read the .lo file
7612f05b35a2Smrg	  func_source "$arg"
7613e0963edeSmrg
7614f05b35a2Smrg	  if test -z "$pic_object" ||
7615f05b35a2Smrg	     test -z "$non_pic_object" ||
7616b3a827e2Smrg	     test none = "$pic_object" &&
7617b3a827e2Smrg	     test none = "$non_pic_object"; then
7618b3a827e2Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7619f05b35a2Smrg	  fi
7620e0963edeSmrg
7621f05b35a2Smrg	  # Extract subdirectory from the argument.
7622f05b35a2Smrg	  func_dirname "$arg" "/" ""
7623b3a827e2Smrg	  xdir=$func_dirname_result
7624e0963edeSmrg
7625b3a827e2Smrg	  test none = "$pic_object" || {
7626f05b35a2Smrg	    # Prepend the subdirectory the object is found in.
7627b3a827e2Smrg	    pic_object=$xdir$pic_object
7628e0963edeSmrg
7629b3a827e2Smrg	    if test dlfiles = "$prev"; then
7630b3a827e2Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
763167ab2ff2Smrg		func_append dlfiles " $pic_object"
7632f05b35a2Smrg		prev=
7633f05b35a2Smrg		continue
7634f05b35a2Smrg	      else
7635f05b35a2Smrg		# If libtool objects are unsupported, then we need to preload.
7636f05b35a2Smrg		prev=dlprefiles
7637f05b35a2Smrg	      fi
7638f05b35a2Smrg	    fi
7639e0963edeSmrg
7640f05b35a2Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641b3a827e2Smrg	    if test dlprefiles = "$prev"; then
7642f05b35a2Smrg	      # Preload the old-style object.
764367ab2ff2Smrg	      func_append dlprefiles " $pic_object"
7644f05b35a2Smrg	      prev=
7645f05b35a2Smrg	    fi
7646e0963edeSmrg
7647f05b35a2Smrg	    # A PIC object.
7648f05b35a2Smrg	    func_append libobjs " $pic_object"
7649b3a827e2Smrg	    arg=$pic_object
7650b3a827e2Smrg	  }
7651e0963edeSmrg
7652f05b35a2Smrg	  # Non-PIC object.
7653b3a827e2Smrg	  if test none != "$non_pic_object"; then
7654f05b35a2Smrg	    # Prepend the subdirectory the object is found in.
7655b3a827e2Smrg	    non_pic_object=$xdir$non_pic_object
7656e0963edeSmrg
7657f05b35a2Smrg	    # A standard non-PIC object
7658f05b35a2Smrg	    func_append non_pic_objects " $non_pic_object"
7659b3a827e2Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660b3a827e2Smrg	      arg=$non_pic_object
7661f05b35a2Smrg	    fi
7662f05b35a2Smrg	  else
7663f05b35a2Smrg	    # If the PIC object exists, use it instead.
7664f05b35a2Smrg	    # $xdir was prepended to $pic_object above.
7665b3a827e2Smrg	    non_pic_object=$pic_object
7666f05b35a2Smrg	    func_append non_pic_objects " $non_pic_object"
7667f05b35a2Smrg	  fi
7668f05b35a2Smrg	else
7669f05b35a2Smrg	  # Only an error if not doing a dry-run.
7670f05b35a2Smrg	  if $opt_dry_run; then
7671f05b35a2Smrg	    # Extract subdirectory from the argument.
7672f05b35a2Smrg	    func_dirname "$arg" "/" ""
7673b3a827e2Smrg	    xdir=$func_dirname_result
7674f05b35a2Smrg
7675f05b35a2Smrg	    func_lo2o "$arg"
7676f05b35a2Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7677f05b35a2Smrg	    non_pic_object=$xdir$func_lo2o_result
7678f05b35a2Smrg	    func_append libobjs " $pic_object"
7679f05b35a2Smrg	    func_append non_pic_objects " $non_pic_object"
7680f05b35a2Smrg	  else
7681b3a827e2Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7682f05b35a2Smrg	  fi
7683f05b35a2Smrg	fi
7684f05b35a2Smrg	;;
7685e0963edeSmrg
7686f05b35a2Smrg      *.$libext)
7687f05b35a2Smrg	# An archive.
768867ab2ff2Smrg	func_append deplibs " $arg"
768967ab2ff2Smrg	func_append old_deplibs " $arg"
7690f05b35a2Smrg	continue
7691f05b35a2Smrg	;;
7692e0963edeSmrg
7693f05b35a2Smrg      *.la)
7694f05b35a2Smrg	# A libtool-controlled library.
7695e0963edeSmrg
769667ab2ff2Smrg	func_resolve_sysroot "$arg"
7697b3a827e2Smrg	if test dlfiles = "$prev"; then
7698f05b35a2Smrg	  # This library was specified with -dlopen.
769967ab2ff2Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7700f05b35a2Smrg	  prev=
7701b3a827e2Smrg	elif test dlprefiles = "$prev"; then
7702f05b35a2Smrg	  # The library was specified with -dlpreopen.
770367ab2ff2Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7704f05b35a2Smrg	  prev=
7705f05b35a2Smrg	else
770667ab2ff2Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7707f05b35a2Smrg	fi
7708f05b35a2Smrg	continue
7709f05b35a2Smrg	;;
7710e0963edeSmrg
7711f05b35a2Smrg      # Some other compiler argument.
7712f05b35a2Smrg      *)
7713f05b35a2Smrg	# Unknown arguments in both finalize_command and compile_command need
7714f05b35a2Smrg	# to be aesthetically quoted because they are evaled later.
7715c30f5000Smrg	func_quote_arg pretty "$arg"
7716c30f5000Smrg	arg=$func_quote_arg_result
7717f05b35a2Smrg	;;
7718f05b35a2Smrg      esac # arg
7719e0963edeSmrg
7720f05b35a2Smrg      # Now actually substitute the argument into the commands.
7721f05b35a2Smrg      if test -n "$arg"; then
7722f05b35a2Smrg	func_append compile_command " $arg"
7723f05b35a2Smrg	func_append finalize_command " $arg"
7724f05b35a2Smrg      fi
7725f05b35a2Smrg    done # argument parsing loop
7726e0963edeSmrg
7727f05b35a2Smrg    test -n "$prev" && \
7728b3a827e2Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7729e0963edeSmrg
7730b3a827e2Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7731f05b35a2Smrg      eval arg=\"$export_dynamic_flag_spec\"
7732f05b35a2Smrg      func_append compile_command " $arg"
7733f05b35a2Smrg      func_append finalize_command " $arg"
7734f05b35a2Smrg    fi
7735e0963edeSmrg
7736f05b35a2Smrg    oldlibs=
7737f05b35a2Smrg    # calculate the name of the file, without its directory
7738f05b35a2Smrg    func_basename "$output"
7739b3a827e2Smrg    outputname=$func_basename_result
7740b3a827e2Smrg    libobjs_save=$libobjs
7741f05b35a2Smrg
7742f05b35a2Smrg    if test -n "$shlibpath_var"; then
7743f05b35a2Smrg      # get the directories listed in $shlibpath_var
7744b3a827e2Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745e0963edeSmrg    else
7746f05b35a2Smrg      shlib_search_path=
7747e0963edeSmrg    fi
7748f05b35a2Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7749f05b35a2Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750e0963edeSmrg
7751b3a827e2Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7752b3a827e2Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753b3a827e2Smrg
7754f05b35a2Smrg    func_dirname "$output" "/" ""
7755b3a827e2Smrg    output_objdir=$func_dirname_result$objdir
775667ab2ff2Smrg    func_to_tool_file "$output_objdir/"
775767ab2ff2Smrg    tool_output_objdir=$func_to_tool_file_result
7758f05b35a2Smrg    # Create the object directory.
7759f05b35a2Smrg    func_mkdir_p "$output_objdir"
7760e0963edeSmrg
7761f05b35a2Smrg    # Determine the type of output
7762f05b35a2Smrg    case $output in
7763f05b35a2Smrg    "")
7764f05b35a2Smrg      func_fatal_help "you must specify an output file"
7765f05b35a2Smrg      ;;
7766f05b35a2Smrg    *.$libext) linkmode=oldlib ;;
7767f05b35a2Smrg    *.lo | *.$objext) linkmode=obj ;;
7768f05b35a2Smrg    *.la) linkmode=lib ;;
7769f05b35a2Smrg    *) linkmode=prog ;; # Anything else should be a program.
7770f05b35a2Smrg    esac
7771f05b35a2Smrg
7772f05b35a2Smrg    specialdeplibs=
7773f05b35a2Smrg
7774f05b35a2Smrg    libs=
7775f05b35a2Smrg    # Find all interdependent deplibs by searching for libraries
7776f05b35a2Smrg    # that are linked more than once (e.g. -la -lb -la)
7777f05b35a2Smrg    for deplib in $deplibs; do
7778b3a827e2Smrg      if $opt_preserve_dup_deps; then
7779f05b35a2Smrg	case "$libs " in
778067ab2ff2Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7781f05b35a2Smrg	esac
7782f05b35a2Smrg      fi
778367ab2ff2Smrg      func_append libs " $deplib"
7784f05b35a2Smrg    done
7785f05b35a2Smrg
7786b3a827e2Smrg    if test lib = "$linkmode"; then
7787f05b35a2Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7788f05b35a2Smrg
7789f05b35a2Smrg      # Compute libraries that are listed more than once in $predeps
7790f05b35a2Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7791f05b35a2Smrg      # not to be eliminated).
7792f05b35a2Smrg      pre_post_deps=
7793f05b35a2Smrg      if $opt_duplicate_compiler_generated_deps; then
7794f05b35a2Smrg	for pre_post_dep in $predeps $postdeps; do
7795f05b35a2Smrg	  case "$pre_post_deps " in
779667ab2ff2Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7797f05b35a2Smrg	  esac
779867ab2ff2Smrg	  func_append pre_post_deps " $pre_post_dep"
7799f05b35a2Smrg	done
7800f05b35a2Smrg      fi
7801f05b35a2Smrg      pre_post_deps=
7802f05b35a2Smrg    fi
7803f05b35a2Smrg
7804f05b35a2Smrg    deplibs=
7805f05b35a2Smrg    newdependency_libs=
7806f05b35a2Smrg    newlib_search_path=
7807f05b35a2Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7808f05b35a2Smrg    notinst_deplibs= # not-installed libtool libraries
7809f05b35a2Smrg    notinst_path= # paths that contain not-installed libtool libraries
7810f05b35a2Smrg
7811f05b35a2Smrg    case $linkmode in
7812f05b35a2Smrg    lib)
7813f05b35a2Smrg	passes="conv dlpreopen link"
7814f05b35a2Smrg	for file in $dlfiles $dlprefiles; do
7815f05b35a2Smrg	  case $file in
7816f05b35a2Smrg	  *.la) ;;
7817f05b35a2Smrg	  *)
7818b3a827e2Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7819f05b35a2Smrg	    ;;
7820f05b35a2Smrg	  esac
7821f05b35a2Smrg	done
7822f05b35a2Smrg	;;
7823f05b35a2Smrg    prog)
7824f05b35a2Smrg	compile_deplibs=
7825f05b35a2Smrg	finalize_deplibs=
7826b3a827e2Smrg	alldeplibs=false
7827f05b35a2Smrg	newdlfiles=
7828f05b35a2Smrg	newdlprefiles=
7829f05b35a2Smrg	passes="conv scan dlopen dlpreopen link"
7830f05b35a2Smrg	;;
7831f05b35a2Smrg    *)  passes="conv"
7832f05b35a2Smrg	;;
7833f05b35a2Smrg    esac
7834f05b35a2Smrg
7835f05b35a2Smrg    for pass in $passes; do
7836f05b35a2Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7837f05b35a2Smrg      # so that -L comes before libs that need it for instance...
7838b3a827e2Smrg      if test lib,link = "$linkmode,$pass"; then
7839f05b35a2Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7840f05b35a2Smrg	##        order, and fix it there properly
7841f05b35a2Smrg        tmp_deplibs=
7842f05b35a2Smrg	for deplib in $deplibs; do
7843f05b35a2Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7844f05b35a2Smrg	done
7845b3a827e2Smrg	deplibs=$tmp_deplibs
7846f05b35a2Smrg      fi
7847f05b35a2Smrg
7848b3a827e2Smrg      if test lib,link = "$linkmode,$pass" ||
7849b3a827e2Smrg	 test prog,scan = "$linkmode,$pass"; then
7850b3a827e2Smrg	libs=$deplibs
7851f05b35a2Smrg	deplibs=
7852f05b35a2Smrg      fi
7853b3a827e2Smrg      if test prog = "$linkmode"; then
7854f05b35a2Smrg	case $pass in
7855b3a827e2Smrg	dlopen) libs=$dlfiles ;;
7856b3a827e2Smrg	dlpreopen) libs=$dlprefiles ;;
7857f05b35a2Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7858f05b35a2Smrg	esac
7859f05b35a2Smrg      fi
7860b3a827e2Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7861f05b35a2Smrg	# Collect and forward deplibs of preopened libtool libs
7862f05b35a2Smrg	for lib in $dlprefiles; do
7863f05b35a2Smrg	  # Ignore non-libtool-libs
7864f05b35a2Smrg	  dependency_libs=
786567ab2ff2Smrg	  func_resolve_sysroot "$lib"
7866f05b35a2Smrg	  case $lib in
786767ab2ff2Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7868f05b35a2Smrg	  esac
7869f05b35a2Smrg
7870f05b35a2Smrg	  # Collect preopened libtool deplibs, except any this library
7871f05b35a2Smrg	  # has declared as weak libs
7872f05b35a2Smrg	  for deplib in $dependency_libs; do
787349e108a1Smrg	    func_basename "$deplib"
787449e108a1Smrg            deplib_base=$func_basename_result
7875f05b35a2Smrg	    case " $weak_libs " in
7876f05b35a2Smrg	    *" $deplib_base "*) ;;
787767ab2ff2Smrg	    *) func_append deplibs " $deplib" ;;
7878f05b35a2Smrg	    esac
7879f05b35a2Smrg	  done
7880f05b35a2Smrg	done
7881b3a827e2Smrg	libs=$dlprefiles
7882f05b35a2Smrg      fi
7883b3a827e2Smrg      if test dlopen = "$pass"; then
7884f05b35a2Smrg	# Collect dlpreopened libraries
7885b3a827e2Smrg	save_deplibs=$deplibs
7886f05b35a2Smrg	deplibs=
7887f05b35a2Smrg      fi
7888f05b35a2Smrg
7889f05b35a2Smrg      for deplib in $libs; do
7890f05b35a2Smrg	lib=
7891b3a827e2Smrg	found=false
7892f05b35a2Smrg	case $deplib in
7893e494fffdSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894e494fffdSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895b3a827e2Smrg	  if test prog,link = "$linkmode,$pass"; then
7896f05b35a2Smrg	    compile_deplibs="$deplib $compile_deplibs"
7897f05b35a2Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7898f05b35a2Smrg	  else
789967ab2ff2Smrg	    func_append compiler_flags " $deplib"
7900b3a827e2Smrg	    if test lib = "$linkmode"; then
7901f05b35a2Smrg		case "$new_inherited_linker_flags " in
7902f05b35a2Smrg		    *" $deplib "*) ;;
790367ab2ff2Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7904f05b35a2Smrg		esac
7905f05b35a2Smrg	    fi
7906f05b35a2Smrg	  fi
7907f05b35a2Smrg	  continue
7908f05b35a2Smrg	  ;;
7909f05b35a2Smrg	-l*)
7910b3a827e2Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911b3a827e2Smrg	    func_warning "'-l' is ignored for archives/objects"
7912f05b35a2Smrg	    continue
7913f05b35a2Smrg	  fi
7914f05b35a2Smrg	  func_stripname '-l' '' "$deplib"
7915f05b35a2Smrg	  name=$func_stripname_result
7916b3a827e2Smrg	  if test lib = "$linkmode"; then
7917f05b35a2Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7918f05b35a2Smrg	  else
7919f05b35a2Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7920f05b35a2Smrg	  fi
7921f05b35a2Smrg	  for searchdir in $searchdirs; do
7922f05b35a2Smrg	    for search_ext in .la $std_shrext .so .a; do
7923f05b35a2Smrg	      # Search the libtool library
7924b3a827e2Smrg	      lib=$searchdir/lib$name$search_ext
7925f05b35a2Smrg	      if test -f "$lib"; then
7926b3a827e2Smrg		if test .la = "$search_ext"; then
7927b3a827e2Smrg		  found=:
7928f05b35a2Smrg		else
7929b3a827e2Smrg		  found=false
7930f05b35a2Smrg		fi
7931f05b35a2Smrg		break 2
7932f05b35a2Smrg	      fi
7933f05b35a2Smrg	    done
7934f05b35a2Smrg	  done
7935b3a827e2Smrg	  if $found; then
7936b3a827e2Smrg	    # deplib is a libtool library
7937f05b35a2Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7938f05b35a2Smrg	    # We need to do some special things here, and not later.
7939b3a827e2Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7940f05b35a2Smrg	      case " $predeps $postdeps " in
7941f05b35a2Smrg	      *" $deplib "*)
7942f05b35a2Smrg		if func_lalib_p "$lib"; then
7943f05b35a2Smrg		  library_names=
7944f05b35a2Smrg		  old_library=
7945f05b35a2Smrg		  func_source "$lib"
7946f05b35a2Smrg		  for l in $old_library $library_names; do
7947b3a827e2Smrg		    ll=$l
7948f05b35a2Smrg		  done
7949b3a827e2Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950b3a827e2Smrg		    found=false
7951f05b35a2Smrg		    func_dirname "$lib" "" "."
7952b3a827e2Smrg		    ladir=$func_dirname_result
7953f05b35a2Smrg		    lib=$ladir/$old_library
7954b3a827e2Smrg		    if test prog,link = "$linkmode,$pass"; then
7955f05b35a2Smrg		      compile_deplibs="$deplib $compile_deplibs"
7956f05b35a2Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7957f05b35a2Smrg		    else
7958f05b35a2Smrg		      deplibs="$deplib $deplibs"
7959b3a827e2Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7960f05b35a2Smrg		    fi
7961f05b35a2Smrg		    continue
7962f05b35a2Smrg		  fi
7963f05b35a2Smrg		fi
7964f05b35a2Smrg		;;
7965f05b35a2Smrg	      *) ;;
7966f05b35a2Smrg	      esac
7967f05b35a2Smrg	    fi
7968b3a827e2Smrg	  else
7969b3a827e2Smrg	    # deplib doesn't seem to be a libtool library
7970b3a827e2Smrg	    if test prog,link = "$linkmode,$pass"; then
7971b3a827e2Smrg	      compile_deplibs="$deplib $compile_deplibs"
7972b3a827e2Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973b3a827e2Smrg	    else
7974b3a827e2Smrg	      deplibs="$deplib $deplibs"
7975b3a827e2Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976b3a827e2Smrg	    fi
7977b3a827e2Smrg	    continue
7978f05b35a2Smrg	  fi
7979f05b35a2Smrg	  ;; # -l
7980f05b35a2Smrg	*.ltframework)
7981b3a827e2Smrg	  if test prog,link = "$linkmode,$pass"; then
7982f05b35a2Smrg	    compile_deplibs="$deplib $compile_deplibs"
7983f05b35a2Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7984f05b35a2Smrg	  else
7985f05b35a2Smrg	    deplibs="$deplib $deplibs"
7986b3a827e2Smrg	    if test lib = "$linkmode"; then
7987f05b35a2Smrg		case "$new_inherited_linker_flags " in
7988f05b35a2Smrg		    *" $deplib "*) ;;
798967ab2ff2Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7990f05b35a2Smrg		esac
7991f05b35a2Smrg	    fi
7992f05b35a2Smrg	  fi
7993f05b35a2Smrg	  continue
7994f05b35a2Smrg	  ;;
7995f05b35a2Smrg	-L*)
7996f05b35a2Smrg	  case $linkmode in
7997f05b35a2Smrg	  lib)
7998f05b35a2Smrg	    deplibs="$deplib $deplibs"
7999b3a827e2Smrg	    test conv = "$pass" && continue
8000f05b35a2Smrg	    newdependency_libs="$deplib $newdependency_libs"
8001f05b35a2Smrg	    func_stripname '-L' '' "$deplib"
800267ab2ff2Smrg	    func_resolve_sysroot "$func_stripname_result"
800367ab2ff2Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8004f05b35a2Smrg	    ;;
8005f05b35a2Smrg	  prog)
8006b3a827e2Smrg	    if test conv = "$pass"; then
8007f05b35a2Smrg	      deplibs="$deplib $deplibs"
8008f05b35a2Smrg	      continue
8009f05b35a2Smrg	    fi
8010b3a827e2Smrg	    if test scan = "$pass"; then
8011f05b35a2Smrg	      deplibs="$deplib $deplibs"
8012f05b35a2Smrg	    else
8013f05b35a2Smrg	      compile_deplibs="$deplib $compile_deplibs"
8014f05b35a2Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8015f05b35a2Smrg	    fi
8016f05b35a2Smrg	    func_stripname '-L' '' "$deplib"
801767ab2ff2Smrg	    func_resolve_sysroot "$func_stripname_result"
801867ab2ff2Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8019f05b35a2Smrg	    ;;
8020f05b35a2Smrg	  *)
8021b3a827e2Smrg	    func_warning "'-L' is ignored for archives/objects"
8022f05b35a2Smrg	    ;;
8023f05b35a2Smrg	  esac # linkmode
8024f05b35a2Smrg	  continue
8025f05b35a2Smrg	  ;; # -L
8026f05b35a2Smrg	-R*)
8027b3a827e2Smrg	  if test link = "$pass"; then
8028f05b35a2Smrg	    func_stripname '-R' '' "$deplib"
802967ab2ff2Smrg	    func_resolve_sysroot "$func_stripname_result"
803067ab2ff2Smrg	    dir=$func_resolve_sysroot_result
8031f05b35a2Smrg	    # Make sure the xrpath contains only unique directories.
8032f05b35a2Smrg	    case "$xrpath " in
8033f05b35a2Smrg	    *" $dir "*) ;;
803467ab2ff2Smrg	    *) func_append xrpath " $dir" ;;
8035f05b35a2Smrg	    esac
8036f05b35a2Smrg	  fi
8037f05b35a2Smrg	  deplibs="$deplib $deplibs"
8038f05b35a2Smrg	  continue
8039f05b35a2Smrg	  ;;
804067ab2ff2Smrg	*.la)
804167ab2ff2Smrg	  func_resolve_sysroot "$deplib"
804267ab2ff2Smrg	  lib=$func_resolve_sysroot_result
804367ab2ff2Smrg	  ;;
8044f05b35a2Smrg	*.$libext)
8045b3a827e2Smrg	  if test conv = "$pass"; then
8046f05b35a2Smrg	    deplibs="$deplib $deplibs"
8047f05b35a2Smrg	    continue
8048f05b35a2Smrg	  fi
8049f05b35a2Smrg	  case $linkmode in
8050f05b35a2Smrg	  lib)
8051f05b35a2Smrg	    # Linking convenience modules into shared libraries is allowed,
8052f05b35a2Smrg	    # but linking other static libraries is non-portable.
8053f05b35a2Smrg	    case " $dlpreconveniencelibs " in
8054f05b35a2Smrg	    *" $deplib "*) ;;
8055f05b35a2Smrg	    *)
8056b3a827e2Smrg	      valid_a_lib=false
8057f05b35a2Smrg	      case $deplibs_check_method in
8058f05b35a2Smrg		match_pattern*)
8059f05b35a2Smrg		  set dummy $deplibs_check_method; shift
8060f05b35a2Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
806149e108a1Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8062f05b35a2Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063b3a827e2Smrg		    valid_a_lib=:
8064f05b35a2Smrg		  fi
8065f05b35a2Smrg		;;
8066f05b35a2Smrg		pass_all)
8067b3a827e2Smrg		  valid_a_lib=:
8068f05b35a2Smrg		;;
8069f05b35a2Smrg	      esac
8070b3a827e2Smrg	      if $valid_a_lib; then
8071b3a827e2Smrg		echo
8072b3a827e2Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073b3a827e2Smrg		$ECHO "*** static library $deplib is not portable!"
8074b3a827e2Smrg		deplibs="$deplib $deplibs"
8075b3a827e2Smrg	      else
807649e108a1Smrg		echo
8077f05b35a2Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807849e108a1Smrg		echo "*** I have the capability to make that library automatically link in when"
807949e108a1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
808049e108a1Smrg		echo "*** shared version of the library, which you do not appear to have"
808149e108a1Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
808249e108a1Smrg		echo "*** that it is just a static archive that I should not use here."
8083f05b35a2Smrg	      fi
8084f05b35a2Smrg	      ;;
8085f05b35a2Smrg	    esac
8086f05b35a2Smrg	    continue
8087f05b35a2Smrg	    ;;
8088f05b35a2Smrg	  prog)
8089b3a827e2Smrg	    if test link != "$pass"; then
8090f05b35a2Smrg	      deplibs="$deplib $deplibs"
8091f05b35a2Smrg	    else
8092f05b35a2Smrg	      compile_deplibs="$deplib $compile_deplibs"
8093f05b35a2Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8094f05b35a2Smrg	    fi
8095f05b35a2Smrg	    continue
8096f05b35a2Smrg	    ;;
8097f05b35a2Smrg	  esac # linkmode
8098f05b35a2Smrg	  ;; # *.$libext
8099f05b35a2Smrg	*.lo | *.$objext)
8100b3a827e2Smrg	  if test conv = "$pass"; then
8101f05b35a2Smrg	    deplibs="$deplib $deplibs"
8102b3a827e2Smrg	  elif test prog = "$linkmode"; then
8103b3a827e2Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8104f05b35a2Smrg	      # If there is no dlopen support or we're linking statically,
8105f05b35a2Smrg	      # we need to preload.
810667ab2ff2Smrg	      func_append newdlprefiles " $deplib"
8107f05b35a2Smrg	      compile_deplibs="$deplib $compile_deplibs"
8108f05b35a2Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8109f05b35a2Smrg	    else
811067ab2ff2Smrg	      func_append newdlfiles " $deplib"
8111f05b35a2Smrg	    fi
8112f05b35a2Smrg	  fi
8113f05b35a2Smrg	  continue
8114f05b35a2Smrg	  ;;
8115f05b35a2Smrg	%DEPLIBS%)
8116b3a827e2Smrg	  alldeplibs=:
8117f05b35a2Smrg	  continue
8118f05b35a2Smrg	  ;;
8119f05b35a2Smrg	esac # case $deplib
8120f05b35a2Smrg
8121b3a827e2Smrg	$found || test -f "$lib" \
8122b3a827e2Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8123f05b35a2Smrg
8124f05b35a2Smrg	# Check to see that this really is a libtool archive.
8125f05b35a2Smrg	func_lalib_unsafe_p "$lib" \
8126b3a827e2Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8127f05b35a2Smrg
8128f05b35a2Smrg	func_dirname "$lib" "" "."
8129b3a827e2Smrg	ladir=$func_dirname_result
8130f05b35a2Smrg
8131f05b35a2Smrg	dlname=
8132f05b35a2Smrg	dlopen=
8133f05b35a2Smrg	dlpreopen=
8134f05b35a2Smrg	libdir=
8135f05b35a2Smrg	library_names=
8136f05b35a2Smrg	old_library=
8137f05b35a2Smrg	inherited_linker_flags=
8138f05b35a2Smrg	# If the library was installed with an old release of libtool,
8139f05b35a2Smrg	# it will not redefine variables installed, or shouldnotlink
8140f05b35a2Smrg	installed=yes
8141f05b35a2Smrg	shouldnotlink=no
8142f05b35a2Smrg	avoidtemprpath=
8143f05b35a2Smrg
8144f05b35a2Smrg
8145f05b35a2Smrg	# Read the .la file
8146f05b35a2Smrg	func_source "$lib"
8147f05b35a2Smrg
8148f05b35a2Smrg	# Convert "-framework foo" to "foo.ltframework"
8149f05b35a2Smrg	if test -n "$inherited_linker_flags"; then
815049e108a1Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8151f05b35a2Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8152f05b35a2Smrg	    case " $new_inherited_linker_flags " in
8153f05b35a2Smrg	      *" $tmp_inherited_linker_flag "*) ;;
815467ab2ff2Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8155f05b35a2Smrg	    esac
8156f05b35a2Smrg	  done
8157f05b35a2Smrg	fi
815849e108a1Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159b3a827e2Smrg	if test lib,link = "$linkmode,$pass" ||
8160b3a827e2Smrg	   test prog,scan = "$linkmode,$pass" ||
8161b3a827e2Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
816267ab2ff2Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
816367ab2ff2Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8164f05b35a2Smrg	fi
8165f05b35a2Smrg
8166b3a827e2Smrg	if test conv = "$pass"; then
8167f05b35a2Smrg	  # Only check for convenience libraries
8168f05b35a2Smrg	  deplibs="$lib $deplibs"
8169f05b35a2Smrg	  if test -z "$libdir"; then
8170f05b35a2Smrg	    if test -z "$old_library"; then
8171b3a827e2Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
8172f05b35a2Smrg	    fi
8173f05b35a2Smrg	    # It is a libtool convenience library, so add in its objects.
817467ab2ff2Smrg	    func_append convenience " $ladir/$objdir/$old_library"
817567ab2ff2Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176b3a827e2Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177b3a827e2Smrg	    func_fatal_error "'$lib' is not a convenience library"
8178f05b35a2Smrg	  fi
8179f05b35a2Smrg	  tmp_libs=
8180f05b35a2Smrg	  for deplib in $dependency_libs; do
8181f05b35a2Smrg	    deplibs="$deplib $deplibs"
8182b3a827e2Smrg	    if $opt_preserve_dup_deps; then
8183f05b35a2Smrg	      case "$tmp_libs " in
818467ab2ff2Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185f05b35a2Smrg	      esac
8186f05b35a2Smrg	    fi
818767ab2ff2Smrg	    func_append tmp_libs " $deplib"
8188f05b35a2Smrg	  done
8189f05b35a2Smrg	  continue
8190f05b35a2Smrg	fi # $pass = conv
8191f05b35a2Smrg
8192f05b35a2Smrg
8193f05b35a2Smrg	# Get the name of the library we link against.
8194f05b35a2Smrg	linklib=
819567ab2ff2Smrg	if test -n "$old_library" &&
8196b3a827e2Smrg	   { test yes = "$prefer_static_libs" ||
8197b3a827e2Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
819867ab2ff2Smrg	  linklib=$old_library
819967ab2ff2Smrg	else
820067ab2ff2Smrg	  for l in $old_library $library_names; do
8201b3a827e2Smrg	    linklib=$l
820267ab2ff2Smrg	  done
820367ab2ff2Smrg	fi
8204f05b35a2Smrg	if test -z "$linklib"; then
8205b3a827e2Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
8206f05b35a2Smrg	fi
8207f05b35a2Smrg
8208f05b35a2Smrg	# This library was specified with -dlopen.
8209b3a827e2Smrg	if test dlopen = "$pass"; then
8210b3a827e2Smrg	  test -z "$libdir" \
8211b3a827e2Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8212f05b35a2Smrg	  if test -z "$dlname" ||
8213b3a827e2Smrg	     test yes != "$dlopen_support" ||
8214b3a827e2Smrg	     test no = "$build_libtool_libs"
8215b3a827e2Smrg	  then
8216f05b35a2Smrg	    # If there is no dlname, no dlopen support or we're linking
8217f05b35a2Smrg	    # statically, we need to preload.  We also need to preload any
8218f05b35a2Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8219f05b35a2Smrg	    # bomb out in the load deplibs phase.
822067ab2ff2Smrg	    func_append dlprefiles " $lib $dependency_libs"
8221f05b35a2Smrg	  else
822267ab2ff2Smrg	    func_append newdlfiles " $lib"
8223f05b35a2Smrg	  fi
8224f05b35a2Smrg	  continue
8225f05b35a2Smrg	fi # $pass = dlopen
8226f05b35a2Smrg
8227f05b35a2Smrg	# We need an absolute path.
8228f05b35a2Smrg	case $ladir in
8229b3a827e2Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8230f05b35a2Smrg	*)
8231f05b35a2Smrg	  abs_ladir=`cd "$ladir" && pwd`
8232f05b35a2Smrg	  if test -z "$abs_ladir"; then
8233b3a827e2Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8234f05b35a2Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235b3a827e2Smrg	    abs_ladir=$ladir
8236f05b35a2Smrg	  fi
8237f05b35a2Smrg	  ;;
8238f05b35a2Smrg	esac
8239f05b35a2Smrg	func_basename "$lib"
8240b3a827e2Smrg	laname=$func_basename_result
8241f05b35a2Smrg
8242f05b35a2Smrg	# Find the relevant object directory and library name.
8243b3a827e2Smrg	if test yes = "$installed"; then
824467ab2ff2Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245b3a827e2Smrg	    func_warning "library '$lib' was moved."
8246b3a827e2Smrg	    dir=$ladir
8247b3a827e2Smrg	    absdir=$abs_ladir
8248b3a827e2Smrg	    libdir=$abs_ladir
8249f05b35a2Smrg	  else
8250b3a827e2Smrg	    dir=$lt_sysroot$libdir
8251b3a827e2Smrg	    absdir=$lt_sysroot$libdir
8252f05b35a2Smrg	  fi
8253b3a827e2Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8254f05b35a2Smrg	else
8255f05b35a2Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256b3a827e2Smrg	    dir=$ladir
8257b3a827e2Smrg	    absdir=$abs_ladir
8258f05b35a2Smrg	    # Remove this search path later
825967ab2ff2Smrg	    func_append notinst_path " $abs_ladir"
8260f05b35a2Smrg	  else
8261b3a827e2Smrg	    dir=$ladir/$objdir
8262b3a827e2Smrg	    absdir=$abs_ladir/$objdir
8263f05b35a2Smrg	    # Remove this search path later
826467ab2ff2Smrg	    func_append notinst_path " $abs_ladir"
8265f05b35a2Smrg	  fi
8266f05b35a2Smrg	fi # $installed = yes
8267f05b35a2Smrg	func_stripname 'lib' '.la' "$laname"
8268f05b35a2Smrg	name=$func_stripname_result
8269f05b35a2Smrg
8270f05b35a2Smrg	# This library was specified with -dlpreopen.
8271b3a827e2Smrg	if test dlpreopen = "$pass"; then
8272b3a827e2Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273b3a827e2Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8274f05b35a2Smrg	  fi
8275b3a827e2Smrg	  case $host in
827667ab2ff2Smrg	    # special handling for platforms with PE-DLLs.
827767ab2ff2Smrg	    *cygwin* | *mingw* | *cegcc* )
827867ab2ff2Smrg	      # Linker will automatically link against shared library if both
827967ab2ff2Smrg	      # static and shared are present.  Therefore, ensure we extract
828067ab2ff2Smrg	      # symbols from the import library if a shared library is present
828167ab2ff2Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
828267ab2ff2Smrg	      # this by putting the import library name into $newdlprefiles.
828367ab2ff2Smrg	      # We recover the dlopen module name by 'saving' the la file
828467ab2ff2Smrg	      # name in a special purpose variable, and (later) extracting the
828567ab2ff2Smrg	      # dlname from the la file.
828667ab2ff2Smrg	      if test -n "$dlname"; then
828767ab2ff2Smrg	        func_tr_sh "$dir/$linklib"
828867ab2ff2Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
828967ab2ff2Smrg	        func_append newdlprefiles " $dir/$linklib"
829067ab2ff2Smrg	      else
829167ab2ff2Smrg	        func_append newdlprefiles " $dir/$old_library"
829267ab2ff2Smrg	        # Keep a list of preopened convenience libraries to check
829367ab2ff2Smrg	        # that they are being used correctly in the link pass.
829467ab2ff2Smrg	        test -z "$libdir" && \
829567ab2ff2Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
829667ab2ff2Smrg	      fi
829767ab2ff2Smrg	    ;;
829867ab2ff2Smrg	    * )
829967ab2ff2Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
830067ab2ff2Smrg	      # are required to link).
830167ab2ff2Smrg	      if test -n "$old_library"; then
830267ab2ff2Smrg	        func_append newdlprefiles " $dir/$old_library"
830367ab2ff2Smrg	        # Keep a list of preopened convenience libraries to check
830467ab2ff2Smrg	        # that they are being used correctly in the link pass.
830567ab2ff2Smrg	        test -z "$libdir" && \
830667ab2ff2Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
830767ab2ff2Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
830867ab2ff2Smrg	      elif test -n "$dlname"; then
830967ab2ff2Smrg	        func_append newdlprefiles " $dir/$dlname"
831067ab2ff2Smrg	      else
831167ab2ff2Smrg	        func_append newdlprefiles " $dir/$linklib"
831267ab2ff2Smrg	      fi
831367ab2ff2Smrg	    ;;
831467ab2ff2Smrg	  esac
8315f05b35a2Smrg	fi # $pass = dlpreopen
8316f05b35a2Smrg
8317f05b35a2Smrg	if test -z "$libdir"; then
8318f05b35a2Smrg	  # Link the convenience library
8319b3a827e2Smrg	  if test lib = "$linkmode"; then
8320f05b35a2Smrg	    deplibs="$dir/$old_library $deplibs"
8321b3a827e2Smrg	  elif test prog,link = "$linkmode,$pass"; then
8322f05b35a2Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8323f05b35a2Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8324f05b35a2Smrg	  else
8325f05b35a2Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8326f05b35a2Smrg	  fi
8327f05b35a2Smrg	  continue
8328f05b35a2Smrg	fi
8329f05b35a2Smrg
8330f05b35a2Smrg
8331b3a827e2Smrg	if test prog = "$linkmode" && test link != "$pass"; then
833267ab2ff2Smrg	  func_append newlib_search_path " $ladir"
8333f05b35a2Smrg	  deplibs="$lib $deplibs"
8334f05b35a2Smrg
8335b3a827e2Smrg	  linkalldeplibs=false
8336b3a827e2Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337b3a827e2Smrg	     test no = "$build_libtool_libs"; then
8338b3a827e2Smrg	    linkalldeplibs=:
8339f05b35a2Smrg	  fi
8340f05b35a2Smrg
8341f05b35a2Smrg	  tmp_libs=
8342f05b35a2Smrg	  for deplib in $dependency_libs; do
8343f05b35a2Smrg	    case $deplib in
8344f05b35a2Smrg	    -L*) func_stripname '-L' '' "$deplib"
834567ab2ff2Smrg	         func_resolve_sysroot "$func_stripname_result"
834667ab2ff2Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8347f05b35a2Smrg		 ;;
8348f05b35a2Smrg	    esac
8349f05b35a2Smrg	    # Need to link against all dependency_libs?
8350b3a827e2Smrg	    if $linkalldeplibs; then
8351f05b35a2Smrg	      deplibs="$deplib $deplibs"
8352f05b35a2Smrg	    else
8353f05b35a2Smrg	      # Need to hardcode shared library paths
8354f05b35a2Smrg	      # or/and link against static libraries
8355f05b35a2Smrg	      newdependency_libs="$deplib $newdependency_libs"
8356f05b35a2Smrg	    fi
8357b3a827e2Smrg	    if $opt_preserve_dup_deps; then
8358f05b35a2Smrg	      case "$tmp_libs " in
835967ab2ff2Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8360f05b35a2Smrg	      esac
8361f05b35a2Smrg	    fi
836267ab2ff2Smrg	    func_append tmp_libs " $deplib"
8363f05b35a2Smrg	  done # for deplib
8364f05b35a2Smrg	  continue
8365f05b35a2Smrg	fi # $linkmode = prog...
8366f05b35a2Smrg
8367b3a827e2Smrg	if test prog,link = "$linkmode,$pass"; then
8368f05b35a2Smrg	  if test -n "$library_names" &&
8369b3a827e2Smrg	     { { test no = "$prefer_static_libs" ||
8370b3a827e2Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8371f05b35a2Smrg	       test -z "$old_library"; }; then
8372f05b35a2Smrg	    # We need to hardcode the library path
8373b3a827e2Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8374f05b35a2Smrg	      # Make sure the rpath contains only unique directories.
8375b3a827e2Smrg	      case $temp_rpath: in
8376f05b35a2Smrg	      *"$absdir:"*) ;;
837767ab2ff2Smrg	      *) func_append temp_rpath "$absdir:" ;;
8378f05b35a2Smrg	      esac
8379f05b35a2Smrg	    fi
8380f05b35a2Smrg
8381f05b35a2Smrg	    # Hardcode the library path.
8382f05b35a2Smrg	    # Skip directories that are in the system default run-time
8383f05b35a2Smrg	    # search path.
8384f05b35a2Smrg	    case " $sys_lib_dlsearch_path " in
8385f05b35a2Smrg	    *" $absdir "*) ;;
8386f05b35a2Smrg	    *)
8387f05b35a2Smrg	      case "$compile_rpath " in
8388f05b35a2Smrg	      *" $absdir "*) ;;
838967ab2ff2Smrg	      *) func_append compile_rpath " $absdir" ;;
8390f05b35a2Smrg	      esac
8391f05b35a2Smrg	      ;;
8392f05b35a2Smrg	    esac
8393f05b35a2Smrg	    case " $sys_lib_dlsearch_path " in
8394f05b35a2Smrg	    *" $libdir "*) ;;
8395f05b35a2Smrg	    *)
8396f05b35a2Smrg	      case "$finalize_rpath " in
8397f05b35a2Smrg	      *" $libdir "*) ;;
839867ab2ff2Smrg	      *) func_append finalize_rpath " $libdir" ;;
8399f05b35a2Smrg	      esac
8400f05b35a2Smrg	      ;;
8401f05b35a2Smrg	    esac
8402f05b35a2Smrg	  fi # $linkmode,$pass = prog,link...
8403f05b35a2Smrg
8404b3a827e2Smrg	  if $alldeplibs &&
8405b3a827e2Smrg	     { test pass_all = "$deplibs_check_method" ||
8406b3a827e2Smrg	       { test yes = "$build_libtool_libs" &&
8407f05b35a2Smrg		 test -n "$library_names"; }; }; then
8408f05b35a2Smrg	    # We only need to search for static libraries
8409f05b35a2Smrg	    continue
8410f05b35a2Smrg	  fi
8411f05b35a2Smrg	fi
8412f05b35a2Smrg
8413f05b35a2Smrg	link_static=no # Whether the deplib will be linked statically
8414f05b35a2Smrg	use_static_libs=$prefer_static_libs
8415b3a827e2Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8416f05b35a2Smrg	  use_static_libs=no
8417f05b35a2Smrg	fi
8418f05b35a2Smrg	if test -n "$library_names" &&
8419b3a827e2Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8420f05b35a2Smrg	  case $host in
8421b3a827e2Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8422f05b35a2Smrg	      # No point in relinking DLLs because paths are not encoded
842367ab2ff2Smrg	      func_append notinst_deplibs " $lib"
8424f05b35a2Smrg	      need_relink=no
8425f05b35a2Smrg	    ;;
8426f05b35a2Smrg	  *)
8427b3a827e2Smrg	    if test no = "$installed"; then
842867ab2ff2Smrg	      func_append notinst_deplibs " $lib"
8429f05b35a2Smrg	      need_relink=yes
8430f05b35a2Smrg	    fi
8431f05b35a2Smrg	    ;;
8432f05b35a2Smrg	  esac
8433f05b35a2Smrg	  # This is a shared library
8434f05b35a2Smrg
8435f05b35a2Smrg	  # Warn about portability, can't link against -module's on some
8436f05b35a2Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437b3a827e2Smrg	  dlopenmodule=
8438f05b35a2Smrg	  for dlpremoduletest in $dlprefiles; do
8439f05b35a2Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440b3a827e2Smrg	      dlopenmodule=$dlpremoduletest
8441f05b35a2Smrg	      break
8442f05b35a2Smrg	    fi
8443f05b35a2Smrg	  done
8444b3a827e2Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
844549e108a1Smrg	    echo
8446b3a827e2Smrg	    if test prog = "$linkmode"; then
8447f05b35a2Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8448f05b35a2Smrg	    else
8449f05b35a2Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8450f05b35a2Smrg	    fi
8451f05b35a2Smrg	    $ECHO "*** $linklib is not portable!"
8452f05b35a2Smrg	  fi
8453b3a827e2Smrg	  if test lib = "$linkmode" &&
8454b3a827e2Smrg	     test yes = "$hardcode_into_libs"; then
8455f05b35a2Smrg	    # Hardcode the library path.
8456f05b35a2Smrg	    # Skip directories that are in the system default run-time
8457f05b35a2Smrg	    # search path.
8458f05b35a2Smrg	    case " $sys_lib_dlsearch_path " in
8459f05b35a2Smrg	    *" $absdir "*) ;;
8460f05b35a2Smrg	    *)
8461f05b35a2Smrg	      case "$compile_rpath " in
8462f05b35a2Smrg	      *" $absdir "*) ;;
846367ab2ff2Smrg	      *) func_append compile_rpath " $absdir" ;;
8464f05b35a2Smrg	      esac
8465f05b35a2Smrg	      ;;
8466f05b35a2Smrg	    esac
8467f05b35a2Smrg	    case " $sys_lib_dlsearch_path " in
8468f05b35a2Smrg	    *" $libdir "*) ;;
8469f05b35a2Smrg	    *)
8470f05b35a2Smrg	      case "$finalize_rpath " in
8471f05b35a2Smrg	      *" $libdir "*) ;;
847267ab2ff2Smrg	      *) func_append finalize_rpath " $libdir" ;;
8473f05b35a2Smrg	      esac
8474f05b35a2Smrg	      ;;
8475f05b35a2Smrg	    esac
8476f05b35a2Smrg	  fi
8477f05b35a2Smrg
8478f05b35a2Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8479f05b35a2Smrg	    # figure out the soname
8480f05b35a2Smrg	    set dummy $library_names
8481f05b35a2Smrg	    shift
8482b3a827e2Smrg	    realname=$1
8483f05b35a2Smrg	    shift
8484f05b35a2Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8485f05b35a2Smrg	    # use dlname if we got it. it's perfectly good, no?
8486f05b35a2Smrg	    if test -n "$dlname"; then
8487b3a827e2Smrg	      soname=$dlname
8488f05b35a2Smrg	    elif test -n "$soname_spec"; then
8489f05b35a2Smrg	      # bleh windows
8490f05b35a2Smrg	      case $host in
8491b3a827e2Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8492f05b35a2Smrg	        func_arith $current - $age
8493f05b35a2Smrg		major=$func_arith_result
8494b3a827e2Smrg		versuffix=-$major
8495f05b35a2Smrg		;;
8496f05b35a2Smrg	      esac
8497f05b35a2Smrg	      eval soname=\"$soname_spec\"
8498f05b35a2Smrg	    else
8499b3a827e2Smrg	      soname=$realname
8500f05b35a2Smrg	    fi
8501f05b35a2Smrg
8502f05b35a2Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503b3a827e2Smrg	    soroot=$soname
8504f05b35a2Smrg	    func_basename "$soroot"
8505b3a827e2Smrg	    soname=$func_basename_result
8506f05b35a2Smrg	    func_stripname 'lib' '.dll' "$soname"
8507f05b35a2Smrg	    newlib=libimp-$func_stripname_result.a
8508f05b35a2Smrg
8509f05b35a2Smrg	    # If the library has no export list, then create one now
8510f05b35a2Smrg	    if test -f "$output_objdir/$soname-def"; then :
8511f05b35a2Smrg	    else
8512b3a827e2Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8513f05b35a2Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8514f05b35a2Smrg	    fi
8515f05b35a2Smrg
8516f05b35a2Smrg	    # Create $newlib
8517f05b35a2Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518b3a827e2Smrg	      func_verbose "generating import library for '$soname'"
8519f05b35a2Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8520f05b35a2Smrg	    fi
8521f05b35a2Smrg	    # make sure the library variables are pointing to the new library
8522f05b35a2Smrg	    dir=$output_objdir
8523f05b35a2Smrg	    linklib=$newlib
8524f05b35a2Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8525f05b35a2Smrg
8526b3a827e2Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8527f05b35a2Smrg	    add_shlibpath=
8528f05b35a2Smrg	    add_dir=
8529f05b35a2Smrg	    add=
8530f05b35a2Smrg	    lib_linked=yes
8531f05b35a2Smrg	    case $hardcode_action in
8532f05b35a2Smrg	    immediate | unsupported)
8533b3a827e2Smrg	      if test no = "$hardcode_direct"; then
8534b3a827e2Smrg		add=$dir/$linklib
8535f05b35a2Smrg		case $host in
8536b3a827e2Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537b3a827e2Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8538f05b35a2Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539b3a827e2Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8540f05b35a2Smrg		  *-*-darwin* )
8541b3a827e2Smrg		    # if the lib is a (non-dlopened) module then we cannot
8542f05b35a2Smrg		    # link against it, someone is ignoring the earlier warnings
8543f05b35a2Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544b3a827e2Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8545f05b35a2Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8546f05b35a2Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547b3a827e2Smrg			if test -z "$old_library"; then
854849e108a1Smrg			  echo
854949e108a1Smrg			  echo "*** And there doesn't seem to be a static archive available"
855049e108a1Smrg			  echo "*** The link will probably fail, sorry"
8551f05b35a2Smrg			else
8552b3a827e2Smrg			  add=$dir/$old_library
8553f05b35a2Smrg			fi
8554f05b35a2Smrg		      elif test -n "$old_library"; then
8555b3a827e2Smrg			add=$dir/$old_library
8556f05b35a2Smrg		      fi
8557f05b35a2Smrg		    fi
8558f05b35a2Smrg		esac
8559b3a827e2Smrg	      elif test no = "$hardcode_minus_L"; then
8560f05b35a2Smrg		case $host in
8561b3a827e2Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8562f05b35a2Smrg		esac
8563b3a827e2Smrg		add_dir=-L$dir
8564b3a827e2Smrg		add=-l$name
8565b3a827e2Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8566b3a827e2Smrg		add_shlibpath=$dir
8567b3a827e2Smrg		add=-l$name
8568f05b35a2Smrg	      else
8569f05b35a2Smrg		lib_linked=no
8570f05b35a2Smrg	      fi
8571f05b35a2Smrg	      ;;
8572f05b35a2Smrg	    relink)
8573b3a827e2Smrg	      if test yes = "$hardcode_direct" &&
8574b3a827e2Smrg	         test no = "$hardcode_direct_absolute"; then
8575b3a827e2Smrg		add=$dir/$linklib
8576b3a827e2Smrg	      elif test yes = "$hardcode_minus_L"; then
8577b3a827e2Smrg		add_dir=-L$absdir
8578f05b35a2Smrg		# Try looking first in the location we're being installed to.
8579f05b35a2Smrg		if test -n "$inst_prefix_dir"; then
8580f05b35a2Smrg		  case $libdir in
8581f05b35a2Smrg		    [\\/]*)
858267ab2ff2Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8583f05b35a2Smrg		      ;;
8584f05b35a2Smrg		  esac
8585f05b35a2Smrg		fi
8586b3a827e2Smrg		add=-l$name
8587b3a827e2Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588b3a827e2Smrg		add_shlibpath=$dir
8589b3a827e2Smrg		add=-l$name
8590f05b35a2Smrg	      else
8591f05b35a2Smrg		lib_linked=no
8592f05b35a2Smrg	      fi
8593f05b35a2Smrg	      ;;
8594f05b35a2Smrg	    *) lib_linked=no ;;
8595f05b35a2Smrg	    esac
8596f05b35a2Smrg
8597b3a827e2Smrg	    if test yes != "$lib_linked"; then
8598f05b35a2Smrg	      func_fatal_configuration "unsupported hardcode properties"
8599f05b35a2Smrg	    fi
8600f05b35a2Smrg
8601f05b35a2Smrg	    if test -n "$add_shlibpath"; then
8602f05b35a2Smrg	      case :$compile_shlibpath: in
8603f05b35a2Smrg	      *":$add_shlibpath:"*) ;;
860467ab2ff2Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8605f05b35a2Smrg	      esac
8606f05b35a2Smrg	    fi
8607b3a827e2Smrg	    if test prog = "$linkmode"; then
8608f05b35a2Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8609f05b35a2Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8610f05b35a2Smrg	    else
8611f05b35a2Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8612f05b35a2Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613b3a827e2Smrg	      if test yes != "$hardcode_direct" &&
8614b3a827e2Smrg		 test yes != "$hardcode_minus_L" &&
8615b3a827e2Smrg		 test yes = "$hardcode_shlibpath_var"; then
8616f05b35a2Smrg		case :$finalize_shlibpath: in
8617f05b35a2Smrg		*":$libdir:"*) ;;
861867ab2ff2Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8619f05b35a2Smrg		esac
8620f05b35a2Smrg	      fi
8621f05b35a2Smrg	    fi
8622f05b35a2Smrg	  fi
8623f05b35a2Smrg
8624b3a827e2Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8625f05b35a2Smrg	    add_shlibpath=
8626f05b35a2Smrg	    add_dir=
8627f05b35a2Smrg	    add=
8628f05b35a2Smrg	    # Finalize command for both is simple: just hardcode it.
8629b3a827e2Smrg	    if test yes = "$hardcode_direct" &&
8630b3a827e2Smrg	       test no = "$hardcode_direct_absolute"; then
8631b3a827e2Smrg	      add=$libdir/$linklib
8632b3a827e2Smrg	    elif test yes = "$hardcode_minus_L"; then
8633b3a827e2Smrg	      add_dir=-L$libdir
8634b3a827e2Smrg	      add=-l$name
8635b3a827e2Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8636f05b35a2Smrg	      case :$finalize_shlibpath: in
8637f05b35a2Smrg	      *":$libdir:"*) ;;
863867ab2ff2Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8639f05b35a2Smrg	      esac
8640b3a827e2Smrg	      add=-l$name
8641b3a827e2Smrg	    elif test yes = "$hardcode_automatic"; then
8642f05b35a2Smrg	      if test -n "$inst_prefix_dir" &&
8643b3a827e2Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644b3a827e2Smrg		add=$inst_prefix_dir$libdir/$linklib
8645f05b35a2Smrg	      else
8646b3a827e2Smrg		add=$libdir/$linklib
8647f05b35a2Smrg	      fi
8648f05b35a2Smrg	    else
8649f05b35a2Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650b3a827e2Smrg	      add_dir=-L$libdir
8651f05b35a2Smrg	      # Try looking first in the location we're being installed to.
8652f05b35a2Smrg	      if test -n "$inst_prefix_dir"; then
8653f05b35a2Smrg		case $libdir in
8654f05b35a2Smrg		  [\\/]*)
865567ab2ff2Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8656f05b35a2Smrg		    ;;
8657f05b35a2Smrg		esac
8658f05b35a2Smrg	      fi
8659b3a827e2Smrg	      add=-l$name
8660f05b35a2Smrg	    fi
8661f05b35a2Smrg
8662b3a827e2Smrg	    if test prog = "$linkmode"; then
8663f05b35a2Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8664f05b35a2Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8665f05b35a2Smrg	    else
8666f05b35a2Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8667f05b35a2Smrg	      test -n "$add" && deplibs="$add $deplibs"
8668f05b35a2Smrg	    fi
8669f05b35a2Smrg	  fi
8670b3a827e2Smrg	elif test prog = "$linkmode"; then
8671f05b35a2Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8672f05b35a2Smrg	  # is not unsupported.  This is valid on all known static and
8673f05b35a2Smrg	  # shared platforms.
8674b3a827e2Smrg	  if test unsupported != "$hardcode_direct"; then
8675b3a827e2Smrg	    test -n "$old_library" && linklib=$old_library
8676f05b35a2Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8677f05b35a2Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8678f05b35a2Smrg	  else
8679f05b35a2Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8680f05b35a2Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8681f05b35a2Smrg	  fi
8682b3a827e2Smrg	elif test yes = "$build_libtool_libs"; then
8683f05b35a2Smrg	  # Not a shared library
8684b3a827e2Smrg	  if test pass_all != "$deplibs_check_method"; then
8685f05b35a2Smrg	    # We're trying link a shared library against a static one
8686f05b35a2Smrg	    # but the system doesn't support it.
8687f05b35a2Smrg
8688f05b35a2Smrg	    # Just print a warning and add the library to dependency_libs so
8689f05b35a2Smrg	    # that the program can be linked against the static library.
869049e108a1Smrg	    echo
8691b3a827e2Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
869249e108a1Smrg	    echo "*** I have the capability to make that library automatically link in when"
869349e108a1Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
869449e108a1Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695b3a827e2Smrg	    if test yes = "$module"; then
869649e108a1Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869749e108a1Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869849e108a1Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8699f05b35a2Smrg	      if test -z "$global_symbol_pipe"; then
870049e108a1Smrg		echo
870149e108a1Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702b3a827e2Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
870349e108a1Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704b3a827e2Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8705f05b35a2Smrg	      fi
8706b3a827e2Smrg	      if test no = "$build_old_libs"; then
8707f05b35a2Smrg		build_libtool_libs=module
8708f05b35a2Smrg		build_old_libs=yes
8709f05b35a2Smrg	      else
8710f05b35a2Smrg		build_libtool_libs=no
8711f05b35a2Smrg	      fi
8712f05b35a2Smrg	    fi
8713f05b35a2Smrg	  else
8714f05b35a2Smrg	    deplibs="$dir/$old_library $deplibs"
8715f05b35a2Smrg	    link_static=yes
8716f05b35a2Smrg	  fi
8717f05b35a2Smrg	fi # link shared/static library?
8718f05b35a2Smrg
8719b3a827e2Smrg	if test lib = "$linkmode"; then
8720f05b35a2Smrg	  if test -n "$dependency_libs" &&
8721b3a827e2Smrg	     { test yes != "$hardcode_into_libs" ||
8722b3a827e2Smrg	       test yes = "$build_old_libs" ||
8723b3a827e2Smrg	       test yes = "$link_static"; }; then
8724f05b35a2Smrg	    # Extract -R from dependency_libs
8725f05b35a2Smrg	    temp_deplibs=
8726f05b35a2Smrg	    for libdir in $dependency_libs; do
8727f05b35a2Smrg	      case $libdir in
8728f05b35a2Smrg	      -R*) func_stripname '-R' '' "$libdir"
8729f05b35a2Smrg	           temp_xrpath=$func_stripname_result
8730f05b35a2Smrg		   case " $xrpath " in
8731f05b35a2Smrg		   *" $temp_xrpath "*) ;;
873267ab2ff2Smrg		   *) func_append xrpath " $temp_xrpath";;
8733f05b35a2Smrg		   esac;;
873467ab2ff2Smrg	      *) func_append temp_deplibs " $libdir";;
8735f05b35a2Smrg	      esac
8736f05b35a2Smrg	    done
8737b3a827e2Smrg	    dependency_libs=$temp_deplibs
8738f05b35a2Smrg	  fi
8739f05b35a2Smrg
874067ab2ff2Smrg	  func_append newlib_search_path " $absdir"
8741f05b35a2Smrg	  # Link against this library
8742b3a827e2Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8743f05b35a2Smrg	  # ... and its dependency_libs
8744f05b35a2Smrg	  tmp_libs=
8745f05b35a2Smrg	  for deplib in $dependency_libs; do
8746f05b35a2Smrg	    newdependency_libs="$deplib $newdependency_libs"
874767ab2ff2Smrg	    case $deplib in
874867ab2ff2Smrg              -L*) func_stripname '-L' '' "$deplib"
874967ab2ff2Smrg                   func_resolve_sysroot "$func_stripname_result";;
875067ab2ff2Smrg              *) func_resolve_sysroot "$deplib" ;;
875167ab2ff2Smrg            esac
8752b3a827e2Smrg	    if $opt_preserve_dup_deps; then
8753f05b35a2Smrg	      case "$tmp_libs " in
875467ab2ff2Smrg	      *" $func_resolve_sysroot_result "*)
875567ab2ff2Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8756f05b35a2Smrg	      esac
8757f05b35a2Smrg	    fi
875867ab2ff2Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8759f05b35a2Smrg	  done
8760f05b35a2Smrg
8761b3a827e2Smrg	  if test no != "$link_all_deplibs"; then
8762f05b35a2Smrg	    # Add the search paths of all dependency libraries
8763f05b35a2Smrg	    for deplib in $dependency_libs; do
876449e108a1Smrg	      path=
8765f05b35a2Smrg	      case $deplib in
8766b3a827e2Smrg	      -L*) path=$deplib ;;
8767f05b35a2Smrg	      *.la)
876867ab2ff2Smrg	        func_resolve_sysroot "$deplib"
876967ab2ff2Smrg	        deplib=$func_resolve_sysroot_result
8770f05b35a2Smrg	        func_dirname "$deplib" "" "."
877167ab2ff2Smrg		dir=$func_dirname_result
8772f05b35a2Smrg		# We need an absolute path.
8773f05b35a2Smrg		case $dir in
8774b3a827e2Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8775f05b35a2Smrg		*)
8776f05b35a2Smrg		  absdir=`cd "$dir" && pwd`
8777f05b35a2Smrg		  if test -z "$absdir"; then
8778b3a827e2Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779b3a827e2Smrg		    absdir=$dir
8780f05b35a2Smrg		  fi
8781f05b35a2Smrg		  ;;
8782f05b35a2Smrg		esac
8783f05b35a2Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8784f05b35a2Smrg		case $host in
8785f05b35a2Smrg		*-*-darwin*)
8786f05b35a2Smrg		  depdepl=
8787b3a827e2Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788b3a827e2Smrg		  if test -n "$deplibrary_names"; then
8789b3a827e2Smrg		    for tmp in $deplibrary_names; do
8790f05b35a2Smrg		      depdepl=$tmp
8791f05b35a2Smrg		    done
8792b3a827e2Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793b3a827e2Smrg		      depdepl=$absdir/$objdir/$depdepl
8794b3a827e2Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8795f05b35a2Smrg                      if test -z "$darwin_install_name"; then
8796b3a827e2Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8797f05b35a2Smrg                      fi
8798b3a827e2Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799b3a827e2Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8800f05b35a2Smrg		      path=
8801f05b35a2Smrg		    fi
8802f05b35a2Smrg		  fi
8803f05b35a2Smrg		  ;;
8804f05b35a2Smrg		*)
8805b3a827e2Smrg		  path=-L$absdir/$objdir
8806f05b35a2Smrg		  ;;
8807f05b35a2Smrg		esac
8808f05b35a2Smrg		else
8809b3a827e2Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8810f05b35a2Smrg		  test -z "$libdir" && \
8811b3a827e2Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8812f05b35a2Smrg		  test "$absdir" != "$libdir" && \
8813b3a827e2Smrg		    func_warning "'$deplib' seems to be moved"
8814f05b35a2Smrg
8815b3a827e2Smrg		  path=-L$absdir
8816f05b35a2Smrg		fi
8817f05b35a2Smrg		;;
8818f05b35a2Smrg	      esac
8819f05b35a2Smrg	      case " $deplibs " in
8820f05b35a2Smrg	      *" $path "*) ;;
8821f05b35a2Smrg	      *) deplibs="$path $deplibs" ;;
8822f05b35a2Smrg	      esac
8823f05b35a2Smrg	    done
8824f05b35a2Smrg	  fi # link_all_deplibs != no
8825f05b35a2Smrg	fi # linkmode = lib
8826f05b35a2Smrg      done # for deplib in $libs
8827b3a827e2Smrg      if test link = "$pass"; then
8828b3a827e2Smrg	if test prog = "$linkmode"; then
8829f05b35a2Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8830f05b35a2Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8831f05b35a2Smrg	else
883249e108a1Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8833f05b35a2Smrg	fi
8834f05b35a2Smrg      fi
8835b3a827e2Smrg      dependency_libs=$newdependency_libs
8836b3a827e2Smrg      if test dlpreopen = "$pass"; then
8837f05b35a2Smrg	# Link the dlpreopened libraries before other libraries
8838f05b35a2Smrg	for deplib in $save_deplibs; do
8839f05b35a2Smrg	  deplibs="$deplib $deplibs"
8840f05b35a2Smrg	done
8841f05b35a2Smrg      fi
8842b3a827e2Smrg      if test dlopen != "$pass"; then
8843b3a827e2Smrg	test conv = "$pass" || {
8844f05b35a2Smrg	  # Make sure lib_search_path contains only unique directories.
8845f05b35a2Smrg	  lib_search_path=
8846f05b35a2Smrg	  for dir in $newlib_search_path; do
8847f05b35a2Smrg	    case "$lib_search_path " in
8848f05b35a2Smrg	    *" $dir "*) ;;
884967ab2ff2Smrg	    *) func_append lib_search_path " $dir" ;;
8850f05b35a2Smrg	    esac
8851f05b35a2Smrg	  done
8852f05b35a2Smrg	  newlib_search_path=
8853b3a827e2Smrg	}
8854f05b35a2Smrg
8855b3a827e2Smrg	if test prog,link = "$linkmode,$pass"; then
8856f05b35a2Smrg	  vars="compile_deplibs finalize_deplibs"
8857b3a827e2Smrg	else
8858b3a827e2Smrg	  vars=deplibs
8859f05b35a2Smrg	fi
8860f05b35a2Smrg	for var in $vars dependency_libs; do
8861f05b35a2Smrg	  # Add libraries to $var in reverse order
8862f05b35a2Smrg	  eval tmp_libs=\"\$$var\"
8863f05b35a2Smrg	  new_libs=
8864f05b35a2Smrg	  for deplib in $tmp_libs; do
8865f05b35a2Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8866f05b35a2Smrg	    #        that some nasty dependency loop isn't accidentally
8867f05b35a2Smrg	    #        broken:
8868f05b35a2Smrg	    #new_libs="$deplib $new_libs"
8869f05b35a2Smrg	    # Pragmatically, this seems to cause very few problems in
8870f05b35a2Smrg	    # practice:
8871f05b35a2Smrg	    case $deplib in
8872f05b35a2Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8873f05b35a2Smrg	    -R*) ;;
8874f05b35a2Smrg	    *)
8875f05b35a2Smrg	      # And here is the reason: when a library appears more
8876f05b35a2Smrg	      # than once as an explicit dependence of a library, or
8877f05b35a2Smrg	      # is implicitly linked in more than once by the
8878f05b35a2Smrg	      # compiler, it is considered special, and multiple
8879f05b35a2Smrg	      # occurrences thereof are not removed.  Compare this
8880f05b35a2Smrg	      # with having the same library being listed as a
8881f05b35a2Smrg	      # dependency of multiple other libraries: in this case,
8882f05b35a2Smrg	      # we know (pedantically, we assume) the library does not
8883f05b35a2Smrg	      # need to be listed more than once, so we keep only the
8884f05b35a2Smrg	      # last copy.  This is not always right, but it is rare
8885f05b35a2Smrg	      # enough that we require users that really mean to play
8886f05b35a2Smrg	      # such unportable linking tricks to link the library
8887f05b35a2Smrg	      # using -Wl,-lname, so that libtool does not consider it
8888f05b35a2Smrg	      # for duplicate removal.
8889f05b35a2Smrg	      case " $specialdeplibs " in
8890f05b35a2Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8891f05b35a2Smrg	      *)
8892f05b35a2Smrg		case " $new_libs " in
8893f05b35a2Smrg		*" $deplib "*) ;;
8894f05b35a2Smrg		*) new_libs="$deplib $new_libs" ;;
8895f05b35a2Smrg		esac
8896f05b35a2Smrg		;;
8897f05b35a2Smrg	      esac
8898f05b35a2Smrg	      ;;
8899f05b35a2Smrg	    esac
8900f05b35a2Smrg	  done
8901f05b35a2Smrg	  tmp_libs=
8902f05b35a2Smrg	  for deplib in $new_libs; do
8903f05b35a2Smrg	    case $deplib in
8904f05b35a2Smrg	    -L*)
8905f05b35a2Smrg	      case " $tmp_libs " in
8906f05b35a2Smrg	      *" $deplib "*) ;;
890767ab2ff2Smrg	      *) func_append tmp_libs " $deplib" ;;
8908f05b35a2Smrg	      esac
8909f05b35a2Smrg	      ;;
891067ab2ff2Smrg	    *) func_append tmp_libs " $deplib" ;;
8911f05b35a2Smrg	    esac
8912f05b35a2Smrg	  done
8913f05b35a2Smrg	  eval $var=\"$tmp_libs\"
8914f05b35a2Smrg	done # for var
8915f05b35a2Smrg      fi
8916b3a827e2Smrg
8917b3a827e2Smrg      # Add Sun CC postdeps if required:
8918b3a827e2Smrg      test CXX = "$tagname" && {
8919b3a827e2Smrg        case $host_os in
8920b3a827e2Smrg        linux*)
8921c30f5000Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922b3a827e2Smrg          *Sun\ C*) # Sun C++ 5.9
8923b3a827e2Smrg            func_suncc_cstd_abi
8924b3a827e2Smrg
8925b3a827e2Smrg            if test no != "$suncc_use_cstd_abi"; then
8926b3a827e2Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8927b3a827e2Smrg            fi
8928b3a827e2Smrg            ;;
8929b3a827e2Smrg          esac
8930b3a827e2Smrg          ;;
8931b3a827e2Smrg
8932b3a827e2Smrg        solaris*)
8933b3a827e2Smrg          func_cc_basename "$CC"
8934b3a827e2Smrg          case $func_cc_basename_result in
8935b3a827e2Smrg          CC* | sunCC*)
8936b3a827e2Smrg            func_suncc_cstd_abi
8937b3a827e2Smrg
8938b3a827e2Smrg            if test no != "$suncc_use_cstd_abi"; then
8939b3a827e2Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8940b3a827e2Smrg            fi
8941b3a827e2Smrg            ;;
8942b3a827e2Smrg          esac
8943b3a827e2Smrg          ;;
8944b3a827e2Smrg        esac
8945b3a827e2Smrg      }
8946b3a827e2Smrg
8947f05b35a2Smrg      # Last step: remove runtime libs from dependency_libs
8948f05b35a2Smrg      # (they stay in deplibs)
8949f05b35a2Smrg      tmp_libs=
8950b3a827e2Smrg      for i in $dependency_libs; do
8951f05b35a2Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8952f05b35a2Smrg	*" $i "*)
8953b3a827e2Smrg	  i=
8954f05b35a2Smrg	  ;;
8955f05b35a2Smrg	esac
8956b3a827e2Smrg	if test -n "$i"; then
895767ab2ff2Smrg	  func_append tmp_libs " $i"
8958f05b35a2Smrg	fi
8959f05b35a2Smrg      done
8960f05b35a2Smrg      dependency_libs=$tmp_libs
8961f05b35a2Smrg    done # for pass
8962b3a827e2Smrg    if test prog = "$linkmode"; then
8963b3a827e2Smrg      dlfiles=$newdlfiles
8964f05b35a2Smrg    fi
8965b3a827e2Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966b3a827e2Smrg      dlprefiles=$newdlprefiles
8967f05b35a2Smrg    fi
8968f05b35a2Smrg
8969f05b35a2Smrg    case $linkmode in
8970f05b35a2Smrg    oldlib)
8971b3a827e2Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972b3a827e2Smrg	func_warning "'-dlopen' is ignored for archives"
8973f05b35a2Smrg      fi
8974f05b35a2Smrg
8975f05b35a2Smrg      case " $deplibs" in
8976f05b35a2Smrg      *\ -l* | *\ -L*)
8977b3a827e2Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8978f05b35a2Smrg      esac
8979f05b35a2Smrg
8980f05b35a2Smrg      test -n "$rpath" && \
8981b3a827e2Smrg	func_warning "'-rpath' is ignored for archives"
8982f05b35a2Smrg
8983f05b35a2Smrg      test -n "$xrpath" && \
8984b3a827e2Smrg	func_warning "'-R' is ignored for archives"
8985f05b35a2Smrg
8986f05b35a2Smrg      test -n "$vinfo" && \
8987b3a827e2Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
8988f05b35a2Smrg
8989f05b35a2Smrg      test -n "$release" && \
8990b3a827e2Smrg	func_warning "'-release' is ignored for archives"
8991f05b35a2Smrg
8992f05b35a2Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993b3a827e2Smrg	func_warning "'-export-symbols' is ignored for archives"
8994f05b35a2Smrg
8995f05b35a2Smrg      # Now set the variables for building old libraries.
8996f05b35a2Smrg      build_libtool_libs=no
8997b3a827e2Smrg      oldlibs=$output
899867ab2ff2Smrg      func_append objs "$old_deplibs"
8999f05b35a2Smrg      ;;
9000f05b35a2Smrg
9001f05b35a2Smrg    lib)
9002b3a827e2Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9003f05b35a2Smrg      case $outputname in
9004f05b35a2Smrg      lib*)
9005f05b35a2Smrg	func_stripname 'lib' '.la' "$outputname"
9006f05b35a2Smrg	name=$func_stripname_result
9007f05b35a2Smrg	eval shared_ext=\"$shrext_cmds\"
9008f05b35a2Smrg	eval libname=\"$libname_spec\"
9009f05b35a2Smrg	;;
9010f05b35a2Smrg      *)
9011b3a827e2Smrg	test no = "$module" \
9012b3a827e2Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9013f05b35a2Smrg
9014b3a827e2Smrg	if test no != "$need_lib_prefix"; then
9015f05b35a2Smrg	  # Add the "lib" prefix for modules if required
9016f05b35a2Smrg	  func_stripname '' '.la' "$outputname"
9017f05b35a2Smrg	  name=$func_stripname_result
9018f05b35a2Smrg	  eval shared_ext=\"$shrext_cmds\"
9019f05b35a2Smrg	  eval libname=\"$libname_spec\"
9020f05b35a2Smrg	else
9021f05b35a2Smrg	  func_stripname '' '.la' "$outputname"
9022f05b35a2Smrg	  libname=$func_stripname_result
9023f05b35a2Smrg	fi
9024f05b35a2Smrg	;;
9025f05b35a2Smrg      esac
9026f05b35a2Smrg
9027f05b35a2Smrg      if test -n "$objs"; then
9028b3a827e2Smrg	if test pass_all != "$deplibs_check_method"; then
9029b3a827e2Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9030f05b35a2Smrg	else
903149e108a1Smrg	  echo
9032f05b35a2Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9033f05b35a2Smrg	  $ECHO "*** objects $objs is not portable!"
903467ab2ff2Smrg	  func_append libobjs " $objs"
9035f05b35a2Smrg	fi
9036f05b35a2Smrg      fi
9037f05b35a2Smrg
9038b3a827e2Smrg      test no = "$dlself" \
9039b3a827e2Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9040f05b35a2Smrg
9041f05b35a2Smrg      set dummy $rpath
9042f05b35a2Smrg      shift
9043b3a827e2Smrg      test 1 -lt "$#" \
9044b3a827e2Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9045f05b35a2Smrg
9046b3a827e2Smrg      install_libdir=$1
9047f05b35a2Smrg
9048f05b35a2Smrg      oldlibs=
9049f05b35a2Smrg      if test -z "$rpath"; then
9050b3a827e2Smrg	if test yes = "$build_libtool_libs"; then
9051f05b35a2Smrg	  # Building a libtool convenience library.
9052b3a827e2Smrg	  # Some compilers have problems with a '.al' extension so
9053f05b35a2Smrg	  # convenience libraries should have the same extension an
9054f05b35a2Smrg	  # archive normally would.
9055f05b35a2Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9056f05b35a2Smrg	  build_libtool_libs=convenience
9057f05b35a2Smrg	  build_old_libs=yes
9058f05b35a2Smrg	fi
9059f05b35a2Smrg
9060f05b35a2Smrg	test -n "$vinfo" && \
9061b3a827e2Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9062f05b35a2Smrg
9063f05b35a2Smrg	test -n "$release" && \
9064b3a827e2Smrg	  func_warning "'-release' is ignored for convenience libraries"
9065f05b35a2Smrg      else
9066f05b35a2Smrg
9067f05b35a2Smrg	# Parse the version information argument.
9068b3a827e2Smrg	save_ifs=$IFS; IFS=:
9069f05b35a2Smrg	set dummy $vinfo 0 0 0
9070f05b35a2Smrg	shift
9071b3a827e2Smrg	IFS=$save_ifs
9072f05b35a2Smrg
9073f05b35a2Smrg	test -n "$7" && \
9074b3a827e2Smrg	  func_fatal_help "too many parameters to '-version-info'"
9075f05b35a2Smrg
9076f05b35a2Smrg	# convert absolute version numbers to libtool ages
9077f05b35a2Smrg	# this retains compatibility with .la files and attempts
9078f05b35a2Smrg	# to make the code below a bit more comprehensible
9079f05b35a2Smrg
9080f05b35a2Smrg	case $vinfo_number in
9081f05b35a2Smrg	yes)
9082b3a827e2Smrg	  number_major=$1
9083b3a827e2Smrg	  number_minor=$2
9084b3a827e2Smrg	  number_revision=$3
9085f05b35a2Smrg	  #
9086f05b35a2Smrg	  # There are really only two kinds -- those that
9087f05b35a2Smrg	  # use the current revision as the major version
9088f05b35a2Smrg	  # and those that subtract age and use age as
9089f05b35a2Smrg	  # a minor version.  But, then there is irix
9090b3a827e2Smrg	  # that has an extra 1 added just for fun
9091f05b35a2Smrg	  #
9092f05b35a2Smrg	  case $version_type in
9093e494fffdSmrg	  # correct linux to gnu/linux during the next big refactor
9094c30f5000Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9095f05b35a2Smrg	    func_arith $number_major + $number_minor
9096f05b35a2Smrg	    current=$func_arith_result
9097b3a827e2Smrg	    age=$number_minor
9098b3a827e2Smrg	    revision=$number_revision
9099f05b35a2Smrg	    ;;
9100b3a827e2Smrg	  freebsd-aout|qnx|sunos)
9101b3a827e2Smrg	    current=$number_major
9102b3a827e2Smrg	    revision=$number_minor
9103b3a827e2Smrg	    age=0
9104f05b35a2Smrg	    ;;
9105f05b35a2Smrg	  irix|nonstopux)
9106f05b35a2Smrg	    func_arith $number_major + $number_minor
9107f05b35a2Smrg	    current=$func_arith_result
9108b3a827e2Smrg	    age=$number_minor
9109b3a827e2Smrg	    revision=$number_minor
9110f05b35a2Smrg	    lt_irix_increment=no
9111f05b35a2Smrg	    ;;
9112f05b35a2Smrg	  esac
9113f05b35a2Smrg	  ;;
9114f05b35a2Smrg	no)
9115b3a827e2Smrg	  current=$1
9116b3a827e2Smrg	  revision=$2
9117b3a827e2Smrg	  age=$3
9118f05b35a2Smrg	  ;;
9119f05b35a2Smrg	esac
9120f05b35a2Smrg
9121f05b35a2Smrg	# Check that each of the things are valid numbers.
9122f05b35a2Smrg	case $current in
9123f05b35a2Smrg	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]) ;;
9124f05b35a2Smrg	*)
9125b3a827e2Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126b3a827e2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9127f05b35a2Smrg	  ;;
9128f05b35a2Smrg	esac
9129f05b35a2Smrg
9130f05b35a2Smrg	case $revision in
9131f05b35a2Smrg	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]) ;;
9132f05b35a2Smrg	*)
9133b3a827e2Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134b3a827e2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9135f05b35a2Smrg	  ;;
9136f05b35a2Smrg	esac
9137f05b35a2Smrg
9138f05b35a2Smrg	case $age in
9139f05b35a2Smrg	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]) ;;
9140f05b35a2Smrg	*)
9141b3a827e2Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9142b3a827e2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9143f05b35a2Smrg	  ;;
9144f05b35a2Smrg	esac
9145f05b35a2Smrg
9146f05b35a2Smrg	if test "$age" -gt "$current"; then
9147b3a827e2Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148b3a827e2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9149f05b35a2Smrg	fi
9150f05b35a2Smrg
9151f05b35a2Smrg	# Calculate the version variables.
9152f05b35a2Smrg	major=
9153f05b35a2Smrg	versuffix=
9154f05b35a2Smrg	verstring=
9155f05b35a2Smrg	case $version_type in
9156f05b35a2Smrg	none) ;;
9157f05b35a2Smrg
9158f05b35a2Smrg	darwin)
9159f05b35a2Smrg	  # Like Linux, but with the current version available in
9160f05b35a2Smrg	  # verstring for coding it into the library header
9161f05b35a2Smrg	  func_arith $current - $age
9162f05b35a2Smrg	  major=.$func_arith_result
9163b3a827e2Smrg	  versuffix=$major.$age.$revision
9164f05b35a2Smrg	  # Darwin ld doesn't like 0 for these options...
9165f05b35a2Smrg	  func_arith $current + 1
9166f05b35a2Smrg	  minor_current=$func_arith_result
9167b3a827e2Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168f05b35a2Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169b3a827e2Smrg          # On Darwin other compilers
9170b3a827e2Smrg          case $CC in
9171b3a827e2Smrg              nagfor*)
9172b3a827e2Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173b3a827e2Smrg                  ;;
9174b3a827e2Smrg              *)
9175b3a827e2Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176b3a827e2Smrg                  ;;
9177b3a827e2Smrg          esac
9178f05b35a2Smrg	  ;;
9179f05b35a2Smrg
9180f05b35a2Smrg	freebsd-aout)
9181b3a827e2Smrg	  major=.$current
9182b3a827e2Smrg	  versuffix=.$current.$revision
9183f05b35a2Smrg	  ;;
9184f05b35a2Smrg
9185c30f5000Smrg	freebsd-elf | midnightbsd-elf)
9186b3a827e2Smrg	  func_arith $current - $age
9187b3a827e2Smrg	  major=.$func_arith_result
9188b3a827e2Smrg	  versuffix=$major.$age.$revision
9189f05b35a2Smrg	  ;;
9190f05b35a2Smrg
9191f05b35a2Smrg	irix | nonstopux)
9192b3a827e2Smrg	  if test no = "$lt_irix_increment"; then
9193f05b35a2Smrg	    func_arith $current - $age
9194f05b35a2Smrg	  else
9195f05b35a2Smrg	    func_arith $current - $age + 1
9196f05b35a2Smrg	  fi
9197f05b35a2Smrg	  major=$func_arith_result
9198f05b35a2Smrg
9199f05b35a2Smrg	  case $version_type in
9200f05b35a2Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9201f05b35a2Smrg	    *)         verstring_prefix=sgi ;;
9202f05b35a2Smrg	  esac
9203b3a827e2Smrg	  verstring=$verstring_prefix$major.$revision
9204f05b35a2Smrg
9205f05b35a2Smrg	  # Add in all the interfaces that we are compatible with.
9206f05b35a2Smrg	  loop=$revision
9207b3a827e2Smrg	  while test 0 -ne "$loop"; do
9208f05b35a2Smrg	    func_arith $revision - $loop
9209f05b35a2Smrg	    iface=$func_arith_result
9210f05b35a2Smrg	    func_arith $loop - 1
9211f05b35a2Smrg	    loop=$func_arith_result
9212b3a827e2Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213f05b35a2Smrg	  done
9214f05b35a2Smrg
9215b3a827e2Smrg	  # Before this point, $major must not contain '.'.
9216f05b35a2Smrg	  major=.$major
9217b3a827e2Smrg	  versuffix=$major.$revision
9218f05b35a2Smrg	  ;;
9219f05b35a2Smrg
9220e494fffdSmrg	linux) # correct to gnu/linux during the next big refactor
9221f05b35a2Smrg	  func_arith $current - $age
9222f05b35a2Smrg	  major=.$func_arith_result
9223b3a827e2Smrg	  versuffix=$major.$age.$revision
9224f05b35a2Smrg	  ;;
9225f05b35a2Smrg
9226f05b35a2Smrg	osf)
9227f05b35a2Smrg	  func_arith $current - $age
9228f05b35a2Smrg	  major=.$func_arith_result
9229b3a827e2Smrg	  versuffix=.$current.$age.$revision
9230b3a827e2Smrg	  verstring=$current.$age.$revision
9231f05b35a2Smrg
9232f05b35a2Smrg	  # Add in all the interfaces that we are compatible with.
9233f05b35a2Smrg	  loop=$age
9234b3a827e2Smrg	  while test 0 -ne "$loop"; do
9235f05b35a2Smrg	    func_arith $current - $loop
9236f05b35a2Smrg	    iface=$func_arith_result
9237f05b35a2Smrg	    func_arith $loop - 1
9238f05b35a2Smrg	    loop=$func_arith_result
9239b3a827e2Smrg	    verstring=$verstring:$iface.0
9240f05b35a2Smrg	  done
9241f05b35a2Smrg
9242f05b35a2Smrg	  # Make executables depend on our current version.
9243b3a827e2Smrg	  func_append verstring ":$current.0"
9244f05b35a2Smrg	  ;;
9245f05b35a2Smrg
9246f05b35a2Smrg	qnx)
9247b3a827e2Smrg	  major=.$current
9248b3a827e2Smrg	  versuffix=.$current
9249b3a827e2Smrg	  ;;
9250b3a827e2Smrg
9251b3a827e2Smrg	sco)
9252b3a827e2Smrg	  major=.$current
9253b3a827e2Smrg	  versuffix=.$current
9254f05b35a2Smrg	  ;;
9255f05b35a2Smrg
9256f05b35a2Smrg	sunos)
9257b3a827e2Smrg	  major=.$current
9258b3a827e2Smrg	  versuffix=.$current.$revision
9259f05b35a2Smrg	  ;;
9260f05b35a2Smrg
9261f05b35a2Smrg	windows)
9262f05b35a2Smrg	  # Use '-' rather than '.', since we only want one
9263b3a827e2Smrg	  # extension on DOS 8.3 file systems.
9264f05b35a2Smrg	  func_arith $current - $age
9265f05b35a2Smrg	  major=$func_arith_result
9266b3a827e2Smrg	  versuffix=-$major
9267f05b35a2Smrg	  ;;
9268f05b35a2Smrg
9269f05b35a2Smrg	*)
9270b3a827e2Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271f05b35a2Smrg	  ;;
9272f05b35a2Smrg	esac
9273f05b35a2Smrg
9274f05b35a2Smrg	# Clear the version info if we defaulted, and they specified a release.
9275f05b35a2Smrg	if test -z "$vinfo" && test -n "$release"; then
9276f05b35a2Smrg	  major=
9277f05b35a2Smrg	  case $version_type in
9278f05b35a2Smrg	  darwin)
9279f05b35a2Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280f05b35a2Smrg	    # problems, so we reset it completely
9281f05b35a2Smrg	    verstring=
9282f05b35a2Smrg	    ;;
9283f05b35a2Smrg	  *)
9284b3a827e2Smrg	    verstring=0.0
9285f05b35a2Smrg	    ;;
9286f05b35a2Smrg	  esac
9287b3a827e2Smrg	  if test no = "$need_version"; then
9288f05b35a2Smrg	    versuffix=
9289f05b35a2Smrg	  else
9290b3a827e2Smrg	    versuffix=.0.0
9291f05b35a2Smrg	  fi
9292f05b35a2Smrg	fi
9293f05b35a2Smrg
9294f05b35a2Smrg	# Remove version info from name if versioning should be avoided
9295b3a827e2Smrg	if test yes,no = "$avoid_version,$need_version"; then
9296f05b35a2Smrg	  major=
9297f05b35a2Smrg	  versuffix=
9298b3a827e2Smrg	  verstring=
9299f05b35a2Smrg	fi
9300f05b35a2Smrg
9301f05b35a2Smrg	# Check to see if the archive will have undefined symbols.
9302b3a827e2Smrg	if test yes = "$allow_undefined"; then
9303b3a827e2Smrg	  if test unsupported = "$allow_undefined_flag"; then
9304b3a827e2Smrg	    if test yes = "$build_old_libs"; then
9305b3a827e2Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306b3a827e2Smrg	      build_libtool_libs=no
9307b3a827e2Smrg	    else
9308b3a827e2Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309b3a827e2Smrg	    fi
9310f05b35a2Smrg	  fi
9311f05b35a2Smrg	else
9312f05b35a2Smrg	  # Don't allow undefined symbols.
9313b3a827e2Smrg	  allow_undefined_flag=$no_undefined_flag
9314f05b35a2Smrg	fi
9315f05b35a2Smrg
9316f05b35a2Smrg      fi
9317f05b35a2Smrg
9318b3a827e2Smrg      func_generate_dlsyms "$libname" "$libname" :
931967ab2ff2Smrg      func_append libobjs " $symfileobj"
9320b3a827e2Smrg      test " " = "$libobjs" && libobjs=
9321f05b35a2Smrg
9322b3a827e2Smrg      if test relink != "$opt_mode"; then
9323f05b35a2Smrg	# Remove our outputs, but don't remove object files since they
9324f05b35a2Smrg	# may have been created when compiling PIC objects.
9325f05b35a2Smrg	removelist=
9326f05b35a2Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327f05b35a2Smrg	for p in $tempremovelist; do
9328f05b35a2Smrg	  case $p in
9329f05b35a2Smrg	    *.$objext | *.gcno)
9330f05b35a2Smrg	       ;;
9331b3a827e2Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332b3a827e2Smrg	       if test -n "$precious_files_regex"; then
9333f05b35a2Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334f05b35a2Smrg		 then
9335f05b35a2Smrg		   continue
9336f05b35a2Smrg		 fi
9337f05b35a2Smrg	       fi
933867ab2ff2Smrg	       func_append removelist " $p"
9339f05b35a2Smrg	       ;;
9340f05b35a2Smrg	    *) ;;
9341f05b35a2Smrg	  esac
9342f05b35a2Smrg	done
9343f05b35a2Smrg	test -n "$removelist" && \
9344f05b35a2Smrg	  func_show_eval "${RM}r \$removelist"
9345f05b35a2Smrg      fi
9346f05b35a2Smrg
9347f05b35a2Smrg      # Now set the variables for building old libraries.
9348b3a827e2Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
934967ab2ff2Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350f05b35a2Smrg
9351f05b35a2Smrg	# Transform .lo files to .o files.
9352b3a827e2Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353f05b35a2Smrg      fi
9354f05b35a2Smrg
9355f05b35a2Smrg      # Eliminate all temporary directories.
9356f05b35a2Smrg      #for path in $notinst_path; do
935749e108a1Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935849e108a1Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935949e108a1Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360f05b35a2Smrg      #done
9361f05b35a2Smrg
9362f05b35a2Smrg      if test -n "$xrpath"; then
9363f05b35a2Smrg	# If the user specified any rpath flags, then add them.
9364f05b35a2Smrg	temp_xrpath=
9365f05b35a2Smrg	for libdir in $xrpath; do
936667ab2ff2Smrg	  func_replace_sysroot "$libdir"
936767ab2ff2Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368f05b35a2Smrg	  case "$finalize_rpath " in
9369f05b35a2Smrg	  *" $libdir "*) ;;
937067ab2ff2Smrg	  *) func_append finalize_rpath " $libdir" ;;
9371f05b35a2Smrg	  esac
9372f05b35a2Smrg	done
9373b3a827e2Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374f05b35a2Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375f05b35a2Smrg	fi
9376f05b35a2Smrg      fi
9377f05b35a2Smrg
9378f05b35a2Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379b3a827e2Smrg      old_dlfiles=$dlfiles
9380f05b35a2Smrg      dlfiles=
9381f05b35a2Smrg      for lib in $old_dlfiles; do
9382f05b35a2Smrg	case " $dlprefiles $dlfiles " in
9383f05b35a2Smrg	*" $lib "*) ;;
938467ab2ff2Smrg	*) func_append dlfiles " $lib" ;;
9385f05b35a2Smrg	esac
9386f05b35a2Smrg      done
9387f05b35a2Smrg
9388f05b35a2Smrg      # Make sure dlprefiles contains only unique files
9389b3a827e2Smrg      old_dlprefiles=$dlprefiles
9390f05b35a2Smrg      dlprefiles=
9391f05b35a2Smrg      for lib in $old_dlprefiles; do
9392f05b35a2Smrg	case "$dlprefiles " in
9393f05b35a2Smrg	*" $lib "*) ;;
939467ab2ff2Smrg	*) func_append dlprefiles " $lib" ;;
9395f05b35a2Smrg	esac
9396f05b35a2Smrg      done
9397f05b35a2Smrg
9398b3a827e2Smrg      if test yes = "$build_libtool_libs"; then
9399f05b35a2Smrg	if test -n "$rpath"; then
9400f05b35a2Smrg	  case $host in
940149e108a1Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402f05b35a2Smrg	    # these systems don't actually have a c library (as such)!
9403f05b35a2Smrg	    ;;
9404f05b35a2Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405f05b35a2Smrg	    # Rhapsody C library is in the System framework
940667ab2ff2Smrg	    func_append deplibs " System.ltframework"
9407f05b35a2Smrg	    ;;
9408f05b35a2Smrg	  *-*-netbsd*)
9409f05b35a2Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9410f05b35a2Smrg	    ;;
9411c30f5000Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412f05b35a2Smrg	    # Do not include libc due to us having libc/libc_r.
9413f05b35a2Smrg	    ;;
9414f05b35a2Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415f05b35a2Smrg	    # Causes problems with __ctype
9416f05b35a2Smrg	    ;;
9417f05b35a2Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418f05b35a2Smrg	    # Compiler inserts libc in the correct place for threads to work
9419f05b35a2Smrg	    ;;
9420f05b35a2Smrg	  *)
9421f05b35a2Smrg	    # Add libc to deplibs on all other systems if necessary.
9422b3a827e2Smrg	    if test yes = "$build_libtool_need_lc"; then
942367ab2ff2Smrg	      func_append deplibs " -lc"
9424f05b35a2Smrg	    fi
9425f05b35a2Smrg	    ;;
9426f05b35a2Smrg	  esac
9427f05b35a2Smrg	fi
9428f05b35a2Smrg
9429f05b35a2Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9430f05b35a2Smrg	name_save=$name
9431f05b35a2Smrg	libname_save=$libname
9432f05b35a2Smrg	release_save=$release
9433f05b35a2Smrg	versuffix_save=$versuffix
9434f05b35a2Smrg	major_save=$major
9435f05b35a2Smrg	# I'm not sure if I'm treating the release correctly.  I think
9436f05b35a2Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437f05b35a2Smrg	# add it in twice.  Is that correct?
9438b3a827e2Smrg	release=
9439b3a827e2Smrg	versuffix=
9440b3a827e2Smrg	major=
9441f05b35a2Smrg	newdeplibs=
9442f05b35a2Smrg	droppeddeps=no
9443f05b35a2Smrg	case $deplibs_check_method in
9444f05b35a2Smrg	pass_all)
9445f05b35a2Smrg	  # Don't check for shared/static.  Everything works.
9446f05b35a2Smrg	  # This might be a little naive.  We might want to check
9447f05b35a2Smrg	  # whether the library exists or not.  But this is on
9448f05b35a2Smrg	  # osf3 & osf4 and I'm not really sure... Just
9449f05b35a2Smrg	  # implementing what was already the behavior.
9450f05b35a2Smrg	  newdeplibs=$deplibs
9451f05b35a2Smrg	  ;;
9452f05b35a2Smrg	test_compile)
9453f05b35a2Smrg	  # This code stresses the "libraries are programs" paradigm to its
9454f05b35a2Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455f05b35a2Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9456f05b35a2Smrg	  # whether they linked in statically or dynamically with ldd.
9457f05b35a2Smrg	  $opt_dry_run || $RM conftest.c
9458f05b35a2Smrg	  cat > conftest.c <<EOF
9459f05b35a2Smrg	  int main() { return 0; }
9460f05b35a2SmrgEOF
9461f05b35a2Smrg	  $opt_dry_run || $RM conftest
9462f05b35a2Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463f05b35a2Smrg	    ldd_output=`ldd conftest`
9464f05b35a2Smrg	    for i in $deplibs; do
9465f05b35a2Smrg	      case $i in
9466f05b35a2Smrg	      -l*)
9467f05b35a2Smrg		func_stripname -l '' "$i"
9468f05b35a2Smrg		name=$func_stripname_result
9469b3a827e2Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470f05b35a2Smrg		  case " $predeps $postdeps " in
9471f05b35a2Smrg		  *" $i "*)
947267ab2ff2Smrg		    func_append newdeplibs " $i"
9473b3a827e2Smrg		    i=
9474f05b35a2Smrg		    ;;
9475f05b35a2Smrg		  esac
9476f05b35a2Smrg		fi
9477b3a827e2Smrg		if test -n "$i"; then
9478f05b35a2Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479f05b35a2Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480f05b35a2Smrg		  set dummy $deplib_matches; shift
9481f05b35a2Smrg		  deplib_match=$1
9482b3a827e2Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
948367ab2ff2Smrg		    func_append newdeplibs " $i"
9484f05b35a2Smrg		  else
9485f05b35a2Smrg		    droppeddeps=yes
948649e108a1Smrg		    echo
9487f05b35a2Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948849e108a1Smrg		    echo "*** I have the capability to make that library automatically link in when"
948949e108a1Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
949049e108a1Smrg		    echo "*** shared version of the library, which I believe you do not have"
949149e108a1Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
949249e108a1Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493f05b35a2Smrg		  fi
9494f05b35a2Smrg		fi
9495f05b35a2Smrg		;;
9496f05b35a2Smrg	      *)
949767ab2ff2Smrg		func_append newdeplibs " $i"
9498f05b35a2Smrg		;;
9499f05b35a2Smrg	      esac
9500f05b35a2Smrg	    done
9501f05b35a2Smrg	  else
9502f05b35a2Smrg	    # Error occurred in the first compile.  Let's try to salvage
9503f05b35a2Smrg	    # the situation: Compile a separate program for each library.
9504f05b35a2Smrg	    for i in $deplibs; do
9505f05b35a2Smrg	      case $i in
9506f05b35a2Smrg	      -l*)
9507f05b35a2Smrg		func_stripname -l '' "$i"
9508f05b35a2Smrg		name=$func_stripname_result
9509f05b35a2Smrg		$opt_dry_run || $RM conftest
9510f05b35a2Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511f05b35a2Smrg		  ldd_output=`ldd conftest`
9512b3a827e2Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513f05b35a2Smrg		    case " $predeps $postdeps " in
9514f05b35a2Smrg		    *" $i "*)
951567ab2ff2Smrg		      func_append newdeplibs " $i"
9516b3a827e2Smrg		      i=
9517f05b35a2Smrg		      ;;
9518f05b35a2Smrg		    esac
9519f05b35a2Smrg		  fi
9520b3a827e2Smrg		  if test -n "$i"; then
9521f05b35a2Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522f05b35a2Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523f05b35a2Smrg		    set dummy $deplib_matches; shift
9524f05b35a2Smrg		    deplib_match=$1
9525b3a827e2Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
952667ab2ff2Smrg		      func_append newdeplibs " $i"
9527f05b35a2Smrg		    else
9528f05b35a2Smrg		      droppeddeps=yes
952949e108a1Smrg		      echo
9530f05b35a2Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
953149e108a1Smrg		      echo "*** I have the capability to make that library automatically link in when"
953249e108a1Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
953349e108a1Smrg		      echo "*** shared version of the library, which you do not appear to have"
953449e108a1Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
953549e108a1Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536f05b35a2Smrg		    fi
9537f05b35a2Smrg		  fi
9538f05b35a2Smrg		else
9539f05b35a2Smrg		  droppeddeps=yes
954049e108a1Smrg		  echo
9541f05b35a2Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
954249e108a1Smrg		  echo "*** make it link in!  You will probably need to install it or some"
954349e108a1Smrg		  echo "*** library that it depends on before this library will be fully"
954449e108a1Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9545f05b35a2Smrg		fi
9546f05b35a2Smrg		;;
9547f05b35a2Smrg	      *)
954867ab2ff2Smrg		func_append newdeplibs " $i"
9549f05b35a2Smrg		;;
9550f05b35a2Smrg	      esac
9551f05b35a2Smrg	    done
9552f05b35a2Smrg	  fi
9553f05b35a2Smrg	  ;;
9554f05b35a2Smrg	file_magic*)
9555f05b35a2Smrg	  set dummy $deplibs_check_method; shift
9556f05b35a2Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557f05b35a2Smrg	  for a_deplib in $deplibs; do
9558f05b35a2Smrg	    case $a_deplib in
9559f05b35a2Smrg	    -l*)
9560f05b35a2Smrg	      func_stripname -l '' "$a_deplib"
9561f05b35a2Smrg	      name=$func_stripname_result
9562b3a827e2Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563f05b35a2Smrg		case " $predeps $postdeps " in
9564f05b35a2Smrg		*" $a_deplib "*)
956567ab2ff2Smrg		  func_append newdeplibs " $a_deplib"
9566b3a827e2Smrg		  a_deplib=
9567f05b35a2Smrg		  ;;
9568f05b35a2Smrg		esac
9569f05b35a2Smrg	      fi
9570b3a827e2Smrg	      if test -n "$a_deplib"; then
9571f05b35a2Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
957267ab2ff2Smrg		if test -n "$file_magic_glob"; then
957367ab2ff2Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
957467ab2ff2Smrg		else
957567ab2ff2Smrg		  libnameglob=$libname
957667ab2ff2Smrg		fi
9577b3a827e2Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578f05b35a2Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579b3a827e2Smrg		  if test yes = "$want_nocaseglob"; then
958067ab2ff2Smrg		    shopt -s nocaseglob
958167ab2ff2Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958267ab2ff2Smrg		    $nocaseglob
958367ab2ff2Smrg		  else
958467ab2ff2Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958567ab2ff2Smrg		  fi
9586f05b35a2Smrg		  for potent_lib in $potential_libs; do
9587f05b35a2Smrg		      # Follow soft links.
9588f05b35a2Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589f05b35a2Smrg			 $GREP " -> " >/dev/null; then
9590f05b35a2Smrg			continue
9591f05b35a2Smrg		      fi
9592f05b35a2Smrg		      # The statement above tries to avoid entering an
9593f05b35a2Smrg		      # endless loop below, in case of cyclic links.
9594f05b35a2Smrg		      # We might still enter an endless loop, since a link
9595f05b35a2Smrg		      # loop can be closed while we follow links,
9596f05b35a2Smrg		      # but so what?
9597b3a827e2Smrg		      potlib=$potent_lib
9598f05b35a2Smrg		      while test -h "$potlib" 2>/dev/null; do
9599b3a827e2Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600f05b35a2Smrg			case $potliblink in
9601b3a827e2Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602b3a827e2Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603f05b35a2Smrg			esac
9604f05b35a2Smrg		      done
9605f05b35a2Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606f05b35a2Smrg			 $SED -e 10q |
9607f05b35a2Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
960867ab2ff2Smrg			func_append newdeplibs " $a_deplib"
9609b3a827e2Smrg			a_deplib=
9610f05b35a2Smrg			break 2
9611f05b35a2Smrg		      fi
9612f05b35a2Smrg		  done
9613f05b35a2Smrg		done
9614f05b35a2Smrg	      fi
9615b3a827e2Smrg	      if test -n "$a_deplib"; then
9616f05b35a2Smrg		droppeddeps=yes
961749e108a1Smrg		echo
9618f05b35a2Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961949e108a1Smrg		echo "*** I have the capability to make that library automatically link in when"
962049e108a1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
962149e108a1Smrg		echo "*** shared version of the library, which you do not appear to have"
962249e108a1Smrg		echo "*** because I did check the linker path looking for a file starting"
9623b3a827e2Smrg		if test -z "$potlib"; then
9624f05b35a2Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625f05b35a2Smrg		else
9626f05b35a2Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627f05b35a2Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628f05b35a2Smrg		fi
9629f05b35a2Smrg	      fi
9630f05b35a2Smrg	      ;;
9631f05b35a2Smrg	    *)
9632f05b35a2Smrg	      # Add a -L argument.
963367ab2ff2Smrg	      func_append newdeplibs " $a_deplib"
9634f05b35a2Smrg	      ;;
9635f05b35a2Smrg	    esac
9636f05b35a2Smrg	  done # Gone through all deplibs.
9637f05b35a2Smrg	  ;;
9638f05b35a2Smrg	match_pattern*)
9639f05b35a2Smrg	  set dummy $deplibs_check_method; shift
9640f05b35a2Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641f05b35a2Smrg	  for a_deplib in $deplibs; do
9642f05b35a2Smrg	    case $a_deplib in
9643f05b35a2Smrg	    -l*)
9644f05b35a2Smrg	      func_stripname -l '' "$a_deplib"
9645f05b35a2Smrg	      name=$func_stripname_result
9646b3a827e2Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647f05b35a2Smrg		case " $predeps $postdeps " in
9648f05b35a2Smrg		*" $a_deplib "*)
964967ab2ff2Smrg		  func_append newdeplibs " $a_deplib"
9650b3a827e2Smrg		  a_deplib=
9651f05b35a2Smrg		  ;;
9652f05b35a2Smrg		esac
9653f05b35a2Smrg	      fi
9654b3a827e2Smrg	      if test -n "$a_deplib"; then
9655f05b35a2Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656f05b35a2Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657f05b35a2Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658f05b35a2Smrg		  for potent_lib in $potential_libs; do
9659b3a827e2Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
966049e108a1Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661f05b35a2Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
966267ab2ff2Smrg		      func_append newdeplibs " $a_deplib"
9663b3a827e2Smrg		      a_deplib=
9664f05b35a2Smrg		      break 2
9665f05b35a2Smrg		    fi
9666f05b35a2Smrg		  done
9667f05b35a2Smrg		done
9668f05b35a2Smrg	      fi
9669b3a827e2Smrg	      if test -n "$a_deplib"; then
9670f05b35a2Smrg		droppeddeps=yes
967149e108a1Smrg		echo
9672f05b35a2Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
967349e108a1Smrg		echo "*** I have the capability to make that library automatically link in when"
967449e108a1Smrg		echo "*** you link to this library.  But I can only do this if you have a"
967549e108a1Smrg		echo "*** shared version of the library, which you do not appear to have"
967649e108a1Smrg		echo "*** because I did check the linker path looking for a file starting"
9677b3a827e2Smrg		if test -z "$potlib"; then
9678f05b35a2Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679f05b35a2Smrg		else
9680f05b35a2Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681f05b35a2Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682f05b35a2Smrg		fi
9683f05b35a2Smrg	      fi
9684f05b35a2Smrg	      ;;
9685f05b35a2Smrg	    *)
9686f05b35a2Smrg	      # Add a -L argument.
968767ab2ff2Smrg	      func_append newdeplibs " $a_deplib"
9688f05b35a2Smrg	      ;;
9689f05b35a2Smrg	    esac
9690f05b35a2Smrg	  done # Gone through all deplibs.
9691f05b35a2Smrg	  ;;
9692f05b35a2Smrg	none | unknown | *)
9693b3a827e2Smrg	  newdeplibs=
969449e108a1Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695b3a827e2Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696b3a827e2Smrg	    for i in $predeps $postdeps; do
9697f05b35a2Smrg	      # can't use Xsed below, because $i might contain '/'
9698b3a827e2Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699f05b35a2Smrg	    done
9700f05b35a2Smrg	  fi
970149e108a1Smrg	  case $tmp_deplibs in
970249e108a1Smrg	  *[!\	\ ]*)
970349e108a1Smrg	    echo
9704b3a827e2Smrg	    if test none = "$deplibs_check_method"; then
970549e108a1Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706f05b35a2Smrg	    else
970749e108a1Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708f05b35a2Smrg	    fi
970949e108a1Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9710f05b35a2Smrg	    droppeddeps=yes
971149e108a1Smrg	    ;;
971249e108a1Smrg	  esac
9713f05b35a2Smrg	  ;;
9714f05b35a2Smrg	esac
9715f05b35a2Smrg	versuffix=$versuffix_save
9716f05b35a2Smrg	major=$major_save
9717f05b35a2Smrg	release=$release_save
9718f05b35a2Smrg	libname=$libname_save
9719f05b35a2Smrg	name=$name_save
9720f05b35a2Smrg
9721f05b35a2Smrg	case $host in
9722f05b35a2Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9723f05b35a2Smrg	  # On Rhapsody replace the C library with the System framework
972449e108a1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725f05b35a2Smrg	  ;;
9726f05b35a2Smrg	esac
9727f05b35a2Smrg
9728b3a827e2Smrg	if test yes = "$droppeddeps"; then
9729b3a827e2Smrg	  if test yes = "$module"; then
973049e108a1Smrg	    echo
973149e108a1Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732f05b35a2Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
973349e108a1Smrg	    echo "*** a static module, that should work as long as the dlopening"
973449e108a1Smrg	    echo "*** application is linked with the -dlopen flag."
9735f05b35a2Smrg	    if test -z "$global_symbol_pipe"; then
973649e108a1Smrg	      echo
973749e108a1Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738b3a827e2Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973949e108a1Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740b3a827e2Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741f05b35a2Smrg	    fi
9742b3a827e2Smrg	    if test no = "$build_old_libs"; then
9743b3a827e2Smrg	      oldlibs=$output_objdir/$libname.$libext
9744f05b35a2Smrg	      build_libtool_libs=module
9745f05b35a2Smrg	      build_old_libs=yes
9746f05b35a2Smrg	    else
9747f05b35a2Smrg	      build_libtool_libs=no
9748f05b35a2Smrg	    fi
9749f05b35a2Smrg	  else
975049e108a1Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
975149e108a1Smrg	    echo "*** automatically added whenever a program is linked with this library"
975249e108a1Smrg	    echo "*** or is declared to -dlopen it."
9753f05b35a2Smrg
9754b3a827e2Smrg	    if test no = "$allow_undefined"; then
975549e108a1Smrg	      echo
975649e108a1Smrg	      echo "*** Since this library must not contain undefined symbols,"
975749e108a1Smrg	      echo "*** because either the platform does not support them or"
975849e108a1Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975949e108a1Smrg	      echo "*** libtool will only create a static version of it."
9760b3a827e2Smrg	      if test no = "$build_old_libs"; then
9761b3a827e2Smrg		oldlibs=$output_objdir/$libname.$libext
9762f05b35a2Smrg		build_libtool_libs=module
9763f05b35a2Smrg		build_old_libs=yes
9764f05b35a2Smrg	      else
9765f05b35a2Smrg		build_libtool_libs=no
9766f05b35a2Smrg	      fi
9767f05b35a2Smrg	    fi
9768f05b35a2Smrg	  fi
9769f05b35a2Smrg	fi
9770f05b35a2Smrg	# Done checking deplibs!
9771f05b35a2Smrg	deplibs=$newdeplibs
9772f05b35a2Smrg      fi
9773f05b35a2Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774f05b35a2Smrg      case $host in
9775f05b35a2Smrg	*-*-darwin*)
977649e108a1Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977749e108a1Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977849e108a1Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779f05b35a2Smrg	  ;;
9780f05b35a2Smrg      esac
9781f05b35a2Smrg
9782f05b35a2Smrg      # move library search paths that coincide with paths to not yet
9783f05b35a2Smrg      # installed libraries to the beginning of the library search list
9784f05b35a2Smrg      new_libs=
9785f05b35a2Smrg      for path in $notinst_path; do
9786f05b35a2Smrg	case " $new_libs " in
9787f05b35a2Smrg	*" -L$path/$objdir "*) ;;
9788f05b35a2Smrg	*)
9789f05b35a2Smrg	  case " $deplibs " in
9790f05b35a2Smrg	  *" -L$path/$objdir "*)
979167ab2ff2Smrg	    func_append new_libs " -L$path/$objdir" ;;
9792f05b35a2Smrg	  esac
9793f05b35a2Smrg	  ;;
9794f05b35a2Smrg	esac
9795f05b35a2Smrg      done
9796f05b35a2Smrg      for deplib in $deplibs; do
9797f05b35a2Smrg	case $deplib in
9798f05b35a2Smrg	-L*)
9799f05b35a2Smrg	  case " $new_libs " in
9800f05b35a2Smrg	  *" $deplib "*) ;;
980167ab2ff2Smrg	  *) func_append new_libs " $deplib" ;;
9802f05b35a2Smrg	  esac
9803f05b35a2Smrg	  ;;
980467ab2ff2Smrg	*) func_append new_libs " $deplib" ;;
9805f05b35a2Smrg	esac
9806f05b35a2Smrg      done
9807b3a827e2Smrg      deplibs=$new_libs
9808f05b35a2Smrg
9809f05b35a2Smrg      # All the library-specific variables (install_libdir is set above).
9810f05b35a2Smrg      library_names=
9811f05b35a2Smrg      old_library=
9812f05b35a2Smrg      dlname=
9813f05b35a2Smrg
9814f05b35a2Smrg      # Test again, we may have decided not to build it any more
9815b3a827e2Smrg      if test yes = "$build_libtool_libs"; then
9816b3a827e2Smrg	# Remove $wl instances when linking with ld.
9817e494fffdSmrg	# FIXME: should test the right _cmds variable.
9818e494fffdSmrg	case $archive_cmds in
9819e494fffdSmrg	  *\$LD\ *) wl= ;;
9820e494fffdSmrg        esac
9821b3a827e2Smrg	if test yes = "$hardcode_into_libs"; then
9822f05b35a2Smrg	  # Hardcode the library paths
9823f05b35a2Smrg	  hardcode_libdirs=
9824f05b35a2Smrg	  dep_rpath=
9825b3a827e2Smrg	  rpath=$finalize_rpath
9826b3a827e2Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827f05b35a2Smrg	  for libdir in $rpath; do
9828f05b35a2Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829f05b35a2Smrg	      if test -n "$hardcode_libdir_separator"; then
983067ab2ff2Smrg		func_replace_sysroot "$libdir"
983167ab2ff2Smrg		libdir=$func_replace_sysroot_result
9832f05b35a2Smrg		if test -z "$hardcode_libdirs"; then
9833b3a827e2Smrg		  hardcode_libdirs=$libdir
9834f05b35a2Smrg		else
9835f05b35a2Smrg		  # Just accumulate the unique libdirs.
9836f05b35a2Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837f05b35a2Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838f05b35a2Smrg		    ;;
9839f05b35a2Smrg		  *)
984067ab2ff2Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841f05b35a2Smrg		    ;;
9842f05b35a2Smrg		  esac
9843f05b35a2Smrg		fi
9844f05b35a2Smrg	      else
9845f05b35a2Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
984667ab2ff2Smrg		func_append dep_rpath " $flag"
9847f05b35a2Smrg	      fi
9848f05b35a2Smrg	    elif test -n "$runpath_var"; then
9849f05b35a2Smrg	      case "$perm_rpath " in
9850f05b35a2Smrg	      *" $libdir "*) ;;
9851e494fffdSmrg	      *) func_append perm_rpath " $libdir" ;;
9852f05b35a2Smrg	      esac
9853f05b35a2Smrg	    fi
9854f05b35a2Smrg	  done
9855f05b35a2Smrg	  # Substitute the hardcoded libdirs into the rpath.
9856f05b35a2Smrg	  if test -n "$hardcode_libdir_separator" &&
9857f05b35a2Smrg	     test -n "$hardcode_libdirs"; then
9858b3a827e2Smrg	    libdir=$hardcode_libdirs
9859e494fffdSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860f05b35a2Smrg	  fi
9861f05b35a2Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862f05b35a2Smrg	    # We should set the runpath_var.
9863f05b35a2Smrg	    rpath=
9864f05b35a2Smrg	    for dir in $perm_rpath; do
986567ab2ff2Smrg	      func_append rpath "$dir:"
9866f05b35a2Smrg	    done
9867f05b35a2Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868f05b35a2Smrg	  fi
9869f05b35a2Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870f05b35a2Smrg	fi
9871e0963edeSmrg
9872b3a827e2Smrg	shlibpath=$finalize_shlibpath
9873b3a827e2Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874f05b35a2Smrg	if test -n "$shlibpath"; then
9875f05b35a2Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876f05b35a2Smrg	fi
9877e0963edeSmrg
9878f05b35a2Smrg	# Get the real and link names of the library.
9879f05b35a2Smrg	eval shared_ext=\"$shrext_cmds\"
9880f05b35a2Smrg	eval library_names=\"$library_names_spec\"
9881f05b35a2Smrg	set dummy $library_names
9882f05b35a2Smrg	shift
9883b3a827e2Smrg	realname=$1
9884f05b35a2Smrg	shift
9885e0963edeSmrg
9886f05b35a2Smrg	if test -n "$soname_spec"; then
9887f05b35a2Smrg	  eval soname=\"$soname_spec\"
9888f05b35a2Smrg	else
9889b3a827e2Smrg	  soname=$realname
9890f05b35a2Smrg	fi
9891f05b35a2Smrg	if test -z "$dlname"; then
9892f05b35a2Smrg	  dlname=$soname
9893f05b35a2Smrg	fi
9894e0963edeSmrg
9895b3a827e2Smrg	lib=$output_objdir/$realname
9896f05b35a2Smrg	linknames=
9897f05b35a2Smrg	for link
9898f05b35a2Smrg	do
989967ab2ff2Smrg	  func_append linknames " $link"
9900f05b35a2Smrg	done
9901e0963edeSmrg
9902f05b35a2Smrg	# Use standard objects if they are pic
990349e108a1Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904f05b35a2Smrg	test "X$libobjs" = "X " && libobjs=
9905e0963edeSmrg
9906f05b35a2Smrg	delfiles=
9907f05b35a2Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908f05b35a2Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909b3a827e2Smrg	  export_symbols=$output_objdir/$libname.uexp
991067ab2ff2Smrg	  func_append delfiles " $export_symbols"
9911f05b35a2Smrg	fi
9912e0963edeSmrg
9913f05b35a2Smrg	orig_export_symbols=
9914f05b35a2Smrg	case $host_os in
9915f05b35a2Smrg	cygwin* | mingw* | cegcc*)
9916f05b35a2Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917f05b35a2Smrg	    # exporting using user supplied symfile
9918b3a827e2Smrg	    func_dll_def_p "$export_symbols" || {
9919f05b35a2Smrg	      # and it's NOT already a .def file. Must figure out
9920f05b35a2Smrg	      # which of the given symbols are data symbols and tag
9921f05b35a2Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9922f05b35a2Smrg	      # export_symbols gets reassigned inside the "prepare
9923f05b35a2Smrg	      # the list of exported symbols" if statement, so the
9924f05b35a2Smrg	      # include_expsyms logic still works.
9925b3a827e2Smrg	      orig_export_symbols=$export_symbols
9926f05b35a2Smrg	      export_symbols=
9927f05b35a2Smrg	      always_export_symbols=yes
9928b3a827e2Smrg	    }
9929f05b35a2Smrg	  fi
9930f05b35a2Smrg	  ;;
9931f05b35a2Smrg	esac
9932e0963edeSmrg
9933f05b35a2Smrg	# Prepare the list of exported symbols
9934f05b35a2Smrg	if test -z "$export_symbols"; then
9935b3a827e2Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936b3a827e2Smrg	    func_verbose "generating symbol list for '$libname.la'"
9937b3a827e2Smrg	    export_symbols=$output_objdir/$libname.exp
9938f05b35a2Smrg	    $opt_dry_run || $RM $export_symbols
9939f05b35a2Smrg	    cmds=$export_symbols_cmds
9940b3a827e2Smrg	    save_ifs=$IFS; IFS='~'
994167ab2ff2Smrg	    for cmd1 in $cmds; do
9942b3a827e2Smrg	      IFS=$save_ifs
994367ab2ff2Smrg	      # Take the normal branch if the nm_file_list_spec branch
994467ab2ff2Smrg	      # doesn't work or if tool conversion is not needed.
994567ab2ff2Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
994667ab2ff2Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
994767ab2ff2Smrg		  try_normal_branch=yes
994867ab2ff2Smrg		  eval cmd=\"$cmd1\"
994967ab2ff2Smrg		  func_len " $cmd"
995067ab2ff2Smrg		  len=$func_len_result
995167ab2ff2Smrg		  ;;
995267ab2ff2Smrg		*)
995367ab2ff2Smrg		  try_normal_branch=no
995467ab2ff2Smrg		  ;;
995567ab2ff2Smrg	      esac
9956b3a827e2Smrg	      if test yes = "$try_normal_branch" \
995767ab2ff2Smrg		 && { test "$len" -lt "$max_cmd_len" \
995867ab2ff2Smrg		      || test "$max_cmd_len" -le -1; }
995967ab2ff2Smrg	      then
996067ab2ff2Smrg		func_show_eval "$cmd" 'exit $?'
996167ab2ff2Smrg		skipped_export=false
996267ab2ff2Smrg	      elif test -n "$nm_file_list_spec"; then
996367ab2ff2Smrg		func_basename "$output"
996467ab2ff2Smrg		output_la=$func_basename_result
996567ab2ff2Smrg		save_libobjs=$libobjs
996667ab2ff2Smrg		save_output=$output
9967b3a827e2Smrg		output=$output_objdir/$output_la.nm
996867ab2ff2Smrg		func_to_tool_file "$output"
996967ab2ff2Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
997067ab2ff2Smrg		func_append delfiles " $output"
997167ab2ff2Smrg		func_verbose "creating $NM input file list: $output"
997267ab2ff2Smrg		for obj in $save_libobjs; do
997367ab2ff2Smrg		  func_to_tool_file "$obj"
997467ab2ff2Smrg		  $ECHO "$func_to_tool_file_result"
997567ab2ff2Smrg		done > "$output"
997667ab2ff2Smrg		eval cmd=\"$cmd1\"
9977f05b35a2Smrg		func_show_eval "$cmd" 'exit $?'
997867ab2ff2Smrg		output=$save_output
997967ab2ff2Smrg		libobjs=$save_libobjs
9980f05b35a2Smrg		skipped_export=false
9981f05b35a2Smrg	      else
9982f05b35a2Smrg		# The command line is too long to execute in one step.
9983f05b35a2Smrg		func_verbose "using reloadable object file for export list..."
9984f05b35a2Smrg		skipped_export=:
9985f05b35a2Smrg		# Break out early, otherwise skipped_export may be
9986f05b35a2Smrg		# set to false by a later but shorter cmd.
9987f05b35a2Smrg		break
9988f05b35a2Smrg	      fi
9989f05b35a2Smrg	    done
9990b3a827e2Smrg	    IFS=$save_ifs
9991b3a827e2Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992f05b35a2Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993f05b35a2Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994f05b35a2Smrg	    fi
9995f05b35a2Smrg	  fi
9996f05b35a2Smrg	fi
9997e0963edeSmrg
9998f05b35a2Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999b3a827e2Smrg	  tmp_export_symbols=$export_symbols
10000b3a827e2Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1000149e108a1Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002f05b35a2Smrg	fi
10003e0963edeSmrg
10004b3a827e2Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005f05b35a2Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006b3a827e2Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007f05b35a2Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008b3a827e2Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009f05b35a2Smrg	  # though. Also, the filter scales superlinearly with the number of
10010f05b35a2Smrg	  # global variables. join(1) would be nice here, but unfortunately
10011f05b35a2Smrg	  # isn't a blessed tool.
10012f05b35a2Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1001367ab2ff2Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014f05b35a2Smrg	  export_symbols=$output_objdir/$libname.def
10015f05b35a2Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016e0963edeSmrg	fi
10017e0963edeSmrg
10018f05b35a2Smrg	tmp_deplibs=
10019f05b35a2Smrg	for test_deplib in $deplibs; do
10020f05b35a2Smrg	  case " $convenience " in
10021f05b35a2Smrg	  *" $test_deplib "*) ;;
10022f05b35a2Smrg	  *)
1002367ab2ff2Smrg	    func_append tmp_deplibs " $test_deplib"
10024f05b35a2Smrg	    ;;
10025f05b35a2Smrg	  esac
10026f05b35a2Smrg	done
10027b3a827e2Smrg	deplibs=$tmp_deplibs
10028e0963edeSmrg
10029f05b35a2Smrg	if test -n "$convenience"; then
10030f05b35a2Smrg	  if test -n "$whole_archive_flag_spec" &&
10031b3a827e2Smrg	    test yes = "$compiler_needs_object" &&
10032f05b35a2Smrg	    test -z "$libobjs"; then
10033f05b35a2Smrg	    # extract the archives, so we have objects to list.
10034f05b35a2Smrg	    # TODO: could optimize this to just extract one archive.
10035f05b35a2Smrg	    whole_archive_flag_spec=
10036f05b35a2Smrg	  fi
10037f05b35a2Smrg	  if test -n "$whole_archive_flag_spec"; then
10038f05b35a2Smrg	    save_libobjs=$libobjs
10039f05b35a2Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040f05b35a2Smrg	    test "X$libobjs" = "X " && libobjs=
10041f05b35a2Smrg	  else
10042b3a827e2Smrg	    gentop=$output_objdir/${outputname}x
1004367ab2ff2Smrg	    func_append generated " $gentop"
10044e0963edeSmrg
10045f05b35a2Smrg	    func_extract_archives $gentop $convenience
1004667ab2ff2Smrg	    func_append libobjs " $func_extract_archives_result"
10047f05b35a2Smrg	    test "X$libobjs" = "X " && libobjs=
10048f05b35a2Smrg	  fi
10049f05b35a2Smrg	fi
10050e0963edeSmrg
10051b3a827e2Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052f05b35a2Smrg	  eval flag=\"$thread_safe_flag_spec\"
1005367ab2ff2Smrg	  func_append linker_flags " $flag"
10054f05b35a2Smrg	fi
10055e0963edeSmrg
10056f05b35a2Smrg	# Make a backup of the uninstalled library when relinking
10057b3a827e2Smrg	if test relink = "$opt_mode"; then
10058f05b35a2Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059e0963edeSmrg	fi
10060e0963edeSmrg
10061f05b35a2Smrg	# Do each of the archive commands.
10062b3a827e2Smrg	if test yes = "$module" && test -n "$module_cmds"; then
10063f05b35a2Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064f05b35a2Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10065f05b35a2Smrg	    cmds=$module_expsym_cmds
10066f05b35a2Smrg	  else
10067f05b35a2Smrg	    eval test_cmds=\"$module_cmds\"
10068f05b35a2Smrg	    cmds=$module_cmds
10069f05b35a2Smrg	  fi
10070f05b35a2Smrg	else
10071f05b35a2Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072f05b35a2Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073f05b35a2Smrg	    cmds=$archive_expsym_cmds
10074f05b35a2Smrg	  else
10075f05b35a2Smrg	    eval test_cmds=\"$archive_cmds\"
10076f05b35a2Smrg	    cmds=$archive_cmds
10077f05b35a2Smrg	  fi
10078e0963edeSmrg	fi
10079e0963edeSmrg
10080b3a827e2Smrg	if test : != "$skipped_export" &&
10081f05b35a2Smrg	   func_len " $test_cmds" &&
10082f05b35a2Smrg	   len=$func_len_result &&
10083f05b35a2Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084f05b35a2Smrg	  :
10085f05b35a2Smrg	else
10086f05b35a2Smrg	  # The command line is too long to link in one step, link piecewise
10087f05b35a2Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088f05b35a2Smrg	  # script.
10089e0963edeSmrg
10090f05b35a2Smrg	  # Save the value of $output and $libobjs because we want to
10091f05b35a2Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10092f05b35a2Smrg	  # want to use save_libobjs as it was before
10093f05b35a2Smrg	  # whole_archive_flag_spec was expanded, because we can't
10094f05b35a2Smrg	  # assume the linker understands whole_archive_flag_spec.
10095f05b35a2Smrg	  # This may have to be revisited, in case too many
10096f05b35a2Smrg	  # convenience libraries get linked in and end up exceeding
10097f05b35a2Smrg	  # the spec.
10098f05b35a2Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099f05b35a2Smrg	    save_libobjs=$libobjs
10100f05b35a2Smrg	  fi
10101f05b35a2Smrg	  save_output=$output
1010249e108a1Smrg	  func_basename "$output"
1010349e108a1Smrg	  output_la=$func_basename_result
10104e0963edeSmrg
10105f05b35a2Smrg	  # Clear the reloadable object creation command queue and
10106f05b35a2Smrg	  # initialize k to one.
10107f05b35a2Smrg	  test_cmds=
10108f05b35a2Smrg	  concat_cmds=
10109f05b35a2Smrg	  objlist=
10110f05b35a2Smrg	  last_robj=
10111f05b35a2Smrg	  k=1
10112e0963edeSmrg
10113b3a827e2Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114b3a827e2Smrg	    output=$output_objdir/$output_la.lnkscript
10115f05b35a2Smrg	    func_verbose "creating GNU ld script: $output"
1011649e108a1Smrg	    echo 'INPUT (' > $output
10117f05b35a2Smrg	    for obj in $save_libobjs
10118f05b35a2Smrg	    do
1011967ab2ff2Smrg	      func_to_tool_file "$obj"
1012067ab2ff2Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10121f05b35a2Smrg	    done
1012249e108a1Smrg	    echo ')' >> $output
1012367ab2ff2Smrg	    func_append delfiles " $output"
1012467ab2ff2Smrg	    func_to_tool_file "$output"
1012567ab2ff2Smrg	    output=$func_to_tool_file_result
10126b3a827e2Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127b3a827e2Smrg	    output=$output_objdir/$output_la.lnk
10128f05b35a2Smrg	    func_verbose "creating linker input file list: $output"
10129f05b35a2Smrg	    : > $output
10130f05b35a2Smrg	    set x $save_libobjs
10131f05b35a2Smrg	    shift
10132f05b35a2Smrg	    firstobj=
10133b3a827e2Smrg	    if test yes = "$compiler_needs_object"; then
10134f05b35a2Smrg	      firstobj="$1 "
10135f05b35a2Smrg	      shift
10136f05b35a2Smrg	    fi
10137f05b35a2Smrg	    for obj
10138f05b35a2Smrg	    do
1013967ab2ff2Smrg	      func_to_tool_file "$obj"
1014067ab2ff2Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10141f05b35a2Smrg	    done
1014267ab2ff2Smrg	    func_append delfiles " $output"
1014367ab2ff2Smrg	    func_to_tool_file "$output"
1014467ab2ff2Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145f05b35a2Smrg	  else
10146f05b35a2Smrg	    if test -n "$save_libobjs"; then
10147f05b35a2Smrg	      func_verbose "creating reloadable object files..."
10148b3a827e2Smrg	      output=$output_objdir/$output_la-$k.$objext
10149f05b35a2Smrg	      eval test_cmds=\"$reload_cmds\"
10150f05b35a2Smrg	      func_len " $test_cmds"
10151f05b35a2Smrg	      len0=$func_len_result
10152f05b35a2Smrg	      len=$len0
10153f05b35a2Smrg
10154f05b35a2Smrg	      # Loop over the list of objects to be linked.
10155f05b35a2Smrg	      for obj in $save_libobjs
10156f05b35a2Smrg	      do
10157f05b35a2Smrg		func_len " $obj"
10158f05b35a2Smrg		func_arith $len + $func_len_result
10159f05b35a2Smrg		len=$func_arith_result
10160b3a827e2Smrg		if test -z "$objlist" ||
10161f05b35a2Smrg		   test "$len" -lt "$max_cmd_len"; then
10162f05b35a2Smrg		  func_append objlist " $obj"
10163f05b35a2Smrg		else
10164f05b35a2Smrg		  # The command $test_cmds is almost too long, add a
10165f05b35a2Smrg		  # command to the queue.
10166b3a827e2Smrg		  if test 1 -eq "$k"; then
10167f05b35a2Smrg		    # The first file doesn't have a previous command to add.
1016849e108a1Smrg		    reload_objs=$objlist
1016949e108a1Smrg		    eval concat_cmds=\"$reload_cmds\"
10170f05b35a2Smrg		  else
10171f05b35a2Smrg		    # All subsequent reloadable object files will link in
10172f05b35a2Smrg		    # the last one created.
1017349e108a1Smrg		    reload_objs="$objlist $last_robj"
1017449e108a1Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175f05b35a2Smrg		  fi
10176b3a827e2Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177f05b35a2Smrg		  func_arith $k + 1
10178f05b35a2Smrg		  k=$func_arith_result
10179b3a827e2Smrg		  output=$output_objdir/$output_la-$k.$objext
1018049e108a1Smrg		  objlist=" $obj"
10181f05b35a2Smrg		  func_len " $last_robj"
10182f05b35a2Smrg		  func_arith $len0 + $func_len_result
10183f05b35a2Smrg		  len=$func_arith_result
10184f05b35a2Smrg		fi
10185f05b35a2Smrg	      done
10186f05b35a2Smrg	      # Handle the remaining objects by creating one last
10187f05b35a2Smrg	      # reloadable object file.  All subsequent reloadable object
10188f05b35a2Smrg	      # files will link in the last one created.
10189f05b35a2Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1019049e108a1Smrg	      reload_objs="$objlist $last_robj"
10191b3a827e2Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192f05b35a2Smrg	      if test -n "$last_robj"; then
10193b3a827e2Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194f05b35a2Smrg	      fi
1019567ab2ff2Smrg	      func_append delfiles " $output"
10196e0963edeSmrg
10197f05b35a2Smrg	    else
10198f05b35a2Smrg	      output=
10199f05b35a2Smrg	    fi
10200f05b35a2Smrg
10201b3a827e2Smrg	    ${skipped_export-false} && {
10202b3a827e2Smrg	      func_verbose "generating symbol list for '$libname.la'"
10203b3a827e2Smrg	      export_symbols=$output_objdir/$libname.exp
10204f05b35a2Smrg	      $opt_dry_run || $RM $export_symbols
10205f05b35a2Smrg	      libobjs=$output
10206f05b35a2Smrg	      # Append the command to create the export file.
10207f05b35a2Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208f05b35a2Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209f05b35a2Smrg	      if test -n "$last_robj"; then
10210f05b35a2Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211f05b35a2Smrg	      fi
10212b3a827e2Smrg	    }
10213e0963edeSmrg
10214f05b35a2Smrg	    test -n "$save_libobjs" &&
10215f05b35a2Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216e0963edeSmrg
10217f05b35a2Smrg	    # Loop through the commands generated above and execute them.
10218b3a827e2Smrg	    save_ifs=$IFS; IFS='~'
10219f05b35a2Smrg	    for cmd in $concat_cmds; do
10220b3a827e2Smrg	      IFS=$save_ifs
10221b3a827e2Smrg	      $opt_quiet || {
10222c30f5000Smrg		  func_quote_arg expand,pretty "$cmd"
10223c30f5000Smrg		  eval "func_echo $func_quote_arg_result"
10224f05b35a2Smrg	      }
10225f05b35a2Smrg	      $opt_dry_run || eval "$cmd" || {
10226f05b35a2Smrg		lt_exit=$?
10227f05b35a2Smrg
10228f05b35a2Smrg		# Restore the uninstalled library and exit
10229b3a827e2Smrg		if test relink = "$opt_mode"; then
10230f05b35a2Smrg		  ( cd "$output_objdir" && \
10231f05b35a2Smrg		    $RM "${realname}T" && \
10232f05b35a2Smrg		    $MV "${realname}U" "$realname" )
10233f05b35a2Smrg		fi
10234e0963edeSmrg
10235f05b35a2Smrg		exit $lt_exit
10236f05b35a2Smrg	      }
10237f05b35a2Smrg	    done
10238b3a827e2Smrg	    IFS=$save_ifs
10239e0963edeSmrg
10240f05b35a2Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241f05b35a2Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242f05b35a2Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243e0963edeSmrg	    fi
10244e0963edeSmrg	  fi
10245e0963edeSmrg
10246b3a827e2Smrg          ${skipped_export-false} && {
10247f05b35a2Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248b3a827e2Smrg	      tmp_export_symbols=$export_symbols
10249b3a827e2Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1025049e108a1Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251f05b35a2Smrg	    fi
10252e0963edeSmrg
10253f05b35a2Smrg	    if test -n "$orig_export_symbols"; then
10254f05b35a2Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255b3a827e2Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256f05b35a2Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257b3a827e2Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258f05b35a2Smrg	      # though. Also, the filter scales superlinearly with the number of
10259f05b35a2Smrg	      # global variables. join(1) would be nice here, but unfortunately
10260f05b35a2Smrg	      # isn't a blessed tool.
10261f05b35a2Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1026267ab2ff2Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263f05b35a2Smrg	      export_symbols=$output_objdir/$libname.def
10264f05b35a2Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265f05b35a2Smrg	    fi
10266b3a827e2Smrg	  }
10267e0963edeSmrg
10268f05b35a2Smrg	  libobjs=$output
10269f05b35a2Smrg	  # Restore the value of output.
10270f05b35a2Smrg	  output=$save_output
10271e0963edeSmrg
10272f05b35a2Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273f05b35a2Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274f05b35a2Smrg	    test "X$libobjs" = "X " && libobjs=
10275f05b35a2Smrg	  fi
10276f05b35a2Smrg	  # Expand the library linking commands again to reset the
10277f05b35a2Smrg	  # value of $libobjs for piecewise linking.
10278f05b35a2Smrg
10279f05b35a2Smrg	  # Do each of the archive commands.
10280b3a827e2Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281f05b35a2Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282f05b35a2Smrg	      cmds=$module_expsym_cmds
10283e0963edeSmrg	    else
10284f05b35a2Smrg	      cmds=$module_cmds
10285e0963edeSmrg	    fi
10286e0963edeSmrg	  else
10287f05b35a2Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288f05b35a2Smrg	      cmds=$archive_expsym_cmds
10289f05b35a2Smrg	    else
10290f05b35a2Smrg	      cmds=$archive_cmds
10291f05b35a2Smrg	    fi
10292e0963edeSmrg	  fi
10293e0963edeSmrg	fi
10294e0963edeSmrg
10295f05b35a2Smrg	if test -n "$delfiles"; then
10296f05b35a2Smrg	  # Append the command to remove temporary files to $cmds.
10297f05b35a2Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298f05b35a2Smrg	fi
10299e0963edeSmrg
10300f05b35a2Smrg	# Add any objects from preloaded convenience libraries
10301f05b35a2Smrg	if test -n "$dlprefiles"; then
10302b3a827e2Smrg	  gentop=$output_objdir/${outputname}x
1030367ab2ff2Smrg	  func_append generated " $gentop"
10304e0963edeSmrg
10305f05b35a2Smrg	  func_extract_archives $gentop $dlprefiles
1030667ab2ff2Smrg	  func_append libobjs " $func_extract_archives_result"
10307f05b35a2Smrg	  test "X$libobjs" = "X " && libobjs=
10308e0963edeSmrg	fi
10309e0963edeSmrg
10310b3a827e2Smrg	save_ifs=$IFS; IFS='~'
10311f05b35a2Smrg	for cmd in $cmds; do
10312b3a827e2Smrg	  IFS=$sp$nl
10313f05b35a2Smrg	  eval cmd=\"$cmd\"
10314b3a827e2Smrg	  IFS=$save_ifs
10315b3a827e2Smrg	  $opt_quiet || {
10316c30f5000Smrg	    func_quote_arg expand,pretty "$cmd"
10317c30f5000Smrg	    eval "func_echo $func_quote_arg_result"
10318f05b35a2Smrg	  }
10319f05b35a2Smrg	  $opt_dry_run || eval "$cmd" || {
10320f05b35a2Smrg	    lt_exit=$?
10321e0963edeSmrg
10322f05b35a2Smrg	    # Restore the uninstalled library and exit
10323b3a827e2Smrg	    if test relink = "$opt_mode"; then
10324f05b35a2Smrg	      ( cd "$output_objdir" && \
10325f05b35a2Smrg	        $RM "${realname}T" && \
10326f05b35a2Smrg		$MV "${realname}U" "$realname" )
10327e0963edeSmrg	    fi
10328e0963edeSmrg
10329f05b35a2Smrg	    exit $lt_exit
10330f05b35a2Smrg	  }
10331f05b35a2Smrg	done
10332b3a827e2Smrg	IFS=$save_ifs
10333e0963edeSmrg
10334f05b35a2Smrg	# Restore the uninstalled library and exit
10335b3a827e2Smrg	if test relink = "$opt_mode"; then
10336f05b35a2Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337e0963edeSmrg
10338f05b35a2Smrg	  if test -n "$convenience"; then
10339f05b35a2Smrg	    if test -z "$whole_archive_flag_spec"; then
10340f05b35a2Smrg	      func_show_eval '${RM}r "$gentop"'
10341f05b35a2Smrg	    fi
10342f05b35a2Smrg	  fi
10343e0963edeSmrg
10344f05b35a2Smrg	  exit $EXIT_SUCCESS
10345f05b35a2Smrg	fi
10346e0963edeSmrg
10347f05b35a2Smrg	# Create links to the real library.
10348f05b35a2Smrg	for linkname in $linknames; do
10349f05b35a2Smrg	  if test "$realname" != "$linkname"; then
10350f05b35a2Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351e0963edeSmrg	  fi
10352e0963edeSmrg	done
10353e0963edeSmrg
10354f05b35a2Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355b3a827e2Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356f05b35a2Smrg	  # On all known operating systems, these are identical.
10357b3a827e2Smrg	  dlname=$soname
10358f05b35a2Smrg	fi
10359f05b35a2Smrg      fi
10360e0963edeSmrg      ;;
10361e0963edeSmrg
10362f05b35a2Smrg    obj)
10363b3a827e2Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364b3a827e2Smrg	func_warning "'-dlopen' is ignored for objects"
10365f05b35a2Smrg      fi
10366e0963edeSmrg
10367f05b35a2Smrg      case " $deplibs" in
10368f05b35a2Smrg      *\ -l* | *\ -L*)
10369b3a827e2Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370e0963edeSmrg      esac
10371e0963edeSmrg
10372f05b35a2Smrg      test -n "$rpath" && \
10373b3a827e2Smrg	func_warning "'-rpath' is ignored for objects"
10374e0963edeSmrg
10375f05b35a2Smrg      test -n "$xrpath" && \
10376b3a827e2Smrg	func_warning "'-R' is ignored for objects"
10377e0963edeSmrg
10378f05b35a2Smrg      test -n "$vinfo" && \
10379b3a827e2Smrg	func_warning "'-version-info' is ignored for objects"
10380f05b35a2Smrg
10381f05b35a2Smrg      test -n "$release" && \
10382b3a827e2Smrg	func_warning "'-release' is ignored for objects"
10383f05b35a2Smrg
10384f05b35a2Smrg      case $output in
10385f05b35a2Smrg      *.lo)
10386f05b35a2Smrg	test -n "$objs$old_deplibs" && \
10387b3a827e2Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388f05b35a2Smrg
10389f05b35a2Smrg	libobj=$output
10390f05b35a2Smrg	func_lo2o "$libobj"
10391f05b35a2Smrg	obj=$func_lo2o_result
10392e0963edeSmrg	;;
10393e0963edeSmrg      *)
10394f05b35a2Smrg	libobj=
10395b3a827e2Smrg	obj=$output
10396e0963edeSmrg	;;
10397e0963edeSmrg      esac
10398e0963edeSmrg
10399f05b35a2Smrg      # Delete the old objects.
10400f05b35a2Smrg      $opt_dry_run || $RM $obj $libobj
10401e0963edeSmrg
10402f05b35a2Smrg      # Objects from convenience libraries.  This assumes
10403f05b35a2Smrg      # single-version convenience libraries.  Whenever we create
10404f05b35a2Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405f05b35a2Smrg      # the extraction.
10406f05b35a2Smrg      reload_conv_objs=
10407f05b35a2Smrg      gentop=
10408b3a827e2Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409b3a827e2Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410b3a827e2Smrg      # into space.
10411b3a827e2Smrg      case $reload_cmds in
10412b3a827e2Smrg        *\$LD[\ \$]*) wl= ;;
10413b3a827e2Smrg      esac
10414f05b35a2Smrg      if test -n "$convenience"; then
10415f05b35a2Smrg	if test -n "$whole_archive_flag_spec"; then
10416f05b35a2Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417b3a827e2Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418b3a827e2Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419f05b35a2Smrg	else
10420b3a827e2Smrg	  gentop=$output_objdir/${obj}x
1042167ab2ff2Smrg	  func_append generated " $gentop"
10422e0963edeSmrg
10423f05b35a2Smrg	  func_extract_archives $gentop $convenience
10424f05b35a2Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425f05b35a2Smrg	fi
10426e0963edeSmrg      fi
10427e0963edeSmrg
1042867ab2ff2Smrg      # If we're not building shared, we need to use non_pic_objs
10429b3a827e2Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
1043067ab2ff2Smrg
10431f05b35a2Smrg      # Create the old-style object.
10432b3a827e2Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433e0963edeSmrg
10434b3a827e2Smrg      output=$obj
10435f05b35a2Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436e0963edeSmrg
10437f05b35a2Smrg      # Exit if we aren't doing a library object file.
10438f05b35a2Smrg      if test -z "$libobj"; then
10439f05b35a2Smrg	if test -n "$gentop"; then
10440f05b35a2Smrg	  func_show_eval '${RM}r "$gentop"'
10441f05b35a2Smrg	fi
10442f05b35a2Smrg
10443f05b35a2Smrg	exit $EXIT_SUCCESS
10444e0963edeSmrg      fi
10445f05b35a2Smrg
10446b3a827e2Smrg      test yes = "$build_libtool_libs" || {
10447f05b35a2Smrg	if test -n "$gentop"; then
10448f05b35a2Smrg	  func_show_eval '${RM}r "$gentop"'
10449f05b35a2Smrg	fi
10450f05b35a2Smrg
10451f05b35a2Smrg	# Create an invalid libtool object if no PIC, so that we don't
10452f05b35a2Smrg	# accidentally link it into a program.
10453f05b35a2Smrg	# $show "echo timestamp > $libobj"
10454f05b35a2Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455f05b35a2Smrg	exit $EXIT_SUCCESS
10456b3a827e2Smrg      }
10457f05b35a2Smrg
10458b3a827e2Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459f05b35a2Smrg	# Only do commands if we really have different PIC objects.
10460f05b35a2Smrg	reload_objs="$libobjs $reload_conv_objs"
10461b3a827e2Smrg	output=$libobj
10462f05b35a2Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463f05b35a2Smrg      fi
10464f05b35a2Smrg
10465f05b35a2Smrg      if test -n "$gentop"; then
10466f05b35a2Smrg	func_show_eval '${RM}r "$gentop"'
10467f05b35a2Smrg      fi
10468f05b35a2Smrg
10469f05b35a2Smrg      exit $EXIT_SUCCESS
10470e0963edeSmrg      ;;
10471e0963edeSmrg
10472f05b35a2Smrg    prog)
10473f05b35a2Smrg      case $host in
10474f05b35a2Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10475f05b35a2Smrg	          output=$func_stripname_result.exe;;
10476f05b35a2Smrg      esac
10477f05b35a2Smrg      test -n "$vinfo" && \
10478b3a827e2Smrg	func_warning "'-version-info' is ignored for programs"
10479e0963edeSmrg
10480f05b35a2Smrg      test -n "$release" && \
10481b3a827e2Smrg	func_warning "'-release' is ignored for programs"
10482e0963edeSmrg
10483b3a827e2Smrg      $preload \
10484b3a827e2Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485b3a827e2Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10486f05b35a2Smrg
10487f05b35a2Smrg      case $host in
10488f05b35a2Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10489f05b35a2Smrg	# On Rhapsody replace the C library is the System framework
1049049e108a1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1049149e108a1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492e0963edeSmrg	;;
10493f05b35a2Smrg      esac
10494e0963edeSmrg
10495f05b35a2Smrg      case $host in
10496f05b35a2Smrg      *-*-darwin*)
10497f05b35a2Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10498f05b35a2Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499b3a827e2Smrg	if test CXX = "$tagname"; then
10500f05b35a2Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501f05b35a2Smrg	    10.[0123])
10502b3a827e2Smrg	      func_append compile_command " $wl-bind_at_load"
10503b3a827e2Smrg	      func_append finalize_command " $wl-bind_at_load"
10504f05b35a2Smrg	    ;;
10505f05b35a2Smrg	  esac
10506e0963edeSmrg	fi
10507f05b35a2Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050849e108a1Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050949e108a1Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10510f05b35a2Smrg	;;
10511f05b35a2Smrg      esac
10512e0963edeSmrg
10513e0963edeSmrg
10514f05b35a2Smrg      # move library search paths that coincide with paths to not yet
10515f05b35a2Smrg      # installed libraries to the beginning of the library search list
10516f05b35a2Smrg      new_libs=
10517f05b35a2Smrg      for path in $notinst_path; do
10518f05b35a2Smrg	case " $new_libs " in
10519f05b35a2Smrg	*" -L$path/$objdir "*) ;;
10520f05b35a2Smrg	*)
10521f05b35a2Smrg	  case " $compile_deplibs " in
10522f05b35a2Smrg	  *" -L$path/$objdir "*)
1052367ab2ff2Smrg	    func_append new_libs " -L$path/$objdir" ;;
10524e0963edeSmrg	  esac
10525f05b35a2Smrg	  ;;
10526f05b35a2Smrg	esac
10527f05b35a2Smrg      done
10528f05b35a2Smrg      for deplib in $compile_deplibs; do
10529f05b35a2Smrg	case $deplib in
10530f05b35a2Smrg	-L*)
10531f05b35a2Smrg	  case " $new_libs " in
10532f05b35a2Smrg	  *" $deplib "*) ;;
1053367ab2ff2Smrg	  *) func_append new_libs " $deplib" ;;
10534e0963edeSmrg	  esac
10535f05b35a2Smrg	  ;;
1053667ab2ff2Smrg	*) func_append new_libs " $deplib" ;;
10537f05b35a2Smrg	esac
10538f05b35a2Smrg      done
10539b3a827e2Smrg      compile_deplibs=$new_libs
10540e0963edeSmrg
10541e0963edeSmrg
1054267ab2ff2Smrg      func_append compile_command " $compile_deplibs"
1054367ab2ff2Smrg      func_append finalize_command " $finalize_deplibs"
10544e0963edeSmrg
10545f05b35a2Smrg      if test -n "$rpath$xrpath"; then
10546f05b35a2Smrg	# If the user specified any rpath flags, then add them.
10547f05b35a2Smrg	for libdir in $rpath $xrpath; do
10548f05b35a2Smrg	  # This is the magic to use -rpath.
10549f05b35a2Smrg	  case "$finalize_rpath " in
10550f05b35a2Smrg	  *" $libdir "*) ;;
1055167ab2ff2Smrg	  *) func_append finalize_rpath " $libdir" ;;
10552f05b35a2Smrg	  esac
10553f05b35a2Smrg	done
10554f05b35a2Smrg      fi
10555e0963edeSmrg
10556f05b35a2Smrg      # Now hardcode the library paths
10557f05b35a2Smrg      rpath=
10558f05b35a2Smrg      hardcode_libdirs=
10559f05b35a2Smrg      for libdir in $compile_rpath $finalize_rpath; do
10560f05b35a2Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10561f05b35a2Smrg	  if test -n "$hardcode_libdir_separator"; then
10562f05b35a2Smrg	    if test -z "$hardcode_libdirs"; then
10563b3a827e2Smrg	      hardcode_libdirs=$libdir
10564f05b35a2Smrg	    else
10565f05b35a2Smrg	      # Just accumulate the unique libdirs.
10566f05b35a2Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567f05b35a2Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568f05b35a2Smrg		;;
10569f05b35a2Smrg	      *)
1057067ab2ff2Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571f05b35a2Smrg		;;
10572f05b35a2Smrg	      esac
10573f05b35a2Smrg	    fi
10574e0963edeSmrg	  else
10575f05b35a2Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1057667ab2ff2Smrg	    func_append rpath " $flag"
10577e0963edeSmrg	  fi
10578f05b35a2Smrg	elif test -n "$runpath_var"; then
10579f05b35a2Smrg	  case "$perm_rpath " in
10580f05b35a2Smrg	  *" $libdir "*) ;;
1058167ab2ff2Smrg	  *) func_append perm_rpath " $libdir" ;;
10582f05b35a2Smrg	  esac
10583f05b35a2Smrg	fi
10584f05b35a2Smrg	case $host in
10585f05b35a2Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586b3a827e2Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587f05b35a2Smrg	  case :$dllsearchpath: in
10588f05b35a2Smrg	  *":$libdir:"*) ;;
10589f05b35a2Smrg	  ::) dllsearchpath=$libdir;;
1059067ab2ff2Smrg	  *) func_append dllsearchpath ":$libdir";;
10591f05b35a2Smrg	  esac
10592f05b35a2Smrg	  case :$dllsearchpath: in
10593f05b35a2Smrg	  *":$testbindir:"*) ;;
10594f05b35a2Smrg	  ::) dllsearchpath=$testbindir;;
1059567ab2ff2Smrg	  *) func_append dllsearchpath ":$testbindir";;
10596f05b35a2Smrg	  esac
10597f05b35a2Smrg	  ;;
10598f05b35a2Smrg	esac
10599f05b35a2Smrg      done
10600f05b35a2Smrg      # Substitute the hardcoded libdirs into the rpath.
10601f05b35a2Smrg      if test -n "$hardcode_libdir_separator" &&
10602f05b35a2Smrg	 test -n "$hardcode_libdirs"; then
10603b3a827e2Smrg	libdir=$hardcode_libdirs
10604f05b35a2Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605f05b35a2Smrg      fi
10606b3a827e2Smrg      compile_rpath=$rpath
10607e0963edeSmrg
10608f05b35a2Smrg      rpath=
10609f05b35a2Smrg      hardcode_libdirs=
10610f05b35a2Smrg      for libdir in $finalize_rpath; do
10611f05b35a2Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10612f05b35a2Smrg	  if test -n "$hardcode_libdir_separator"; then
10613f05b35a2Smrg	    if test -z "$hardcode_libdirs"; then
10614b3a827e2Smrg	      hardcode_libdirs=$libdir
10615f05b35a2Smrg	    else
10616f05b35a2Smrg	      # Just accumulate the unique libdirs.
10617f05b35a2Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618f05b35a2Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619f05b35a2Smrg		;;
10620f05b35a2Smrg	      *)
1062167ab2ff2Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622f05b35a2Smrg		;;
10623f05b35a2Smrg	      esac
10624f05b35a2Smrg	    fi
10625e0963edeSmrg	  else
10626f05b35a2Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1062767ab2ff2Smrg	    func_append rpath " $flag"
10628e0963edeSmrg	  fi
10629f05b35a2Smrg	elif test -n "$runpath_var"; then
10630f05b35a2Smrg	  case "$finalize_perm_rpath " in
10631f05b35a2Smrg	  *" $libdir "*) ;;
1063267ab2ff2Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10633f05b35a2Smrg	  esac
10634e0963edeSmrg	fi
10635f05b35a2Smrg      done
10636f05b35a2Smrg      # Substitute the hardcoded libdirs into the rpath.
10637f05b35a2Smrg      if test -n "$hardcode_libdir_separator" &&
10638f05b35a2Smrg	 test -n "$hardcode_libdirs"; then
10639b3a827e2Smrg	libdir=$hardcode_libdirs
10640f05b35a2Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641f05b35a2Smrg      fi
10642b3a827e2Smrg      finalize_rpath=$rpath
10643e0963edeSmrg
10644b3a827e2Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645f05b35a2Smrg	# Transform all the library objects into standard objects.
1064649e108a1Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064749e108a1Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648f05b35a2Smrg      fi
10649e0963edeSmrg
10650b3a827e2Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651e0963edeSmrg
10652f05b35a2Smrg      # template prelinking step
10653f05b35a2Smrg      if test -n "$prelink_cmds"; then
10654f05b35a2Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655f05b35a2Smrg      fi
10656e0963edeSmrg
10657b3a827e2Smrg      wrappers_required=:
10658f05b35a2Smrg      case $host in
1065949e108a1Smrg      *cegcc* | *mingw32ce*)
1066049e108a1Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661b3a827e2Smrg        wrappers_required=false
1066249e108a1Smrg        ;;
10663f05b35a2Smrg      *cygwin* | *mingw* )
10664b3a827e2Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665f05b35a2Smrg        ;;
10666f05b35a2Smrg      *)
10667b3a827e2Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668b3a827e2Smrg          wrappers_required=false
10669f05b35a2Smrg        fi
10670f05b35a2Smrg        ;;
10671f05b35a2Smrg      esac
10672b3a827e2Smrg      $wrappers_required || {
10673f05b35a2Smrg	# Replace the output file specification.
1067449e108a1Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675b3a827e2Smrg	link_command=$compile_command$compile_rpath
10676e0963edeSmrg
10677f05b35a2Smrg	# We have no uninstalled library dependencies, so finalize right now.
10678f05b35a2Smrg	exit_status=0
10679f05b35a2Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680e0963edeSmrg
1068167ab2ff2Smrg	if test -n "$postlink_cmds"; then
1068267ab2ff2Smrg	  func_to_tool_file "$output"
1068367ab2ff2Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1068467ab2ff2Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1068567ab2ff2Smrg	fi
1068667ab2ff2Smrg
10687f05b35a2Smrg	# Delete the generated files.
10688b3a827e2Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689b3a827e2Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690e0963edeSmrg	fi
10691e0963edeSmrg
10692f05b35a2Smrg	exit $exit_status
10693b3a827e2Smrg      }
10694e0963edeSmrg
10695f05b35a2Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696f05b35a2Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697f05b35a2Smrg      fi
10698f05b35a2Smrg      if test -n "$finalize_shlibpath"; then
10699f05b35a2Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700f05b35a2Smrg      fi
10701e0963edeSmrg
10702f05b35a2Smrg      compile_var=
10703f05b35a2Smrg      finalize_var=
10704f05b35a2Smrg      if test -n "$runpath_var"; then
10705f05b35a2Smrg	if test -n "$perm_rpath"; then
10706f05b35a2Smrg	  # We should set the runpath_var.
10707f05b35a2Smrg	  rpath=
10708f05b35a2Smrg	  for dir in $perm_rpath; do
1070967ab2ff2Smrg	    func_append rpath "$dir:"
10710f05b35a2Smrg	  done
10711f05b35a2Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712e0963edeSmrg	fi
10713f05b35a2Smrg	if test -n "$finalize_perm_rpath"; then
10714f05b35a2Smrg	  # We should set the runpath_var.
10715f05b35a2Smrg	  rpath=
10716f05b35a2Smrg	  for dir in $finalize_perm_rpath; do
1071767ab2ff2Smrg	    func_append rpath "$dir:"
10718f05b35a2Smrg	  done
10719f05b35a2Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720e0963edeSmrg	fi
10721f05b35a2Smrg      fi
10722e0963edeSmrg
10723b3a827e2Smrg      if test yes = "$no_install"; then
10724f05b35a2Smrg	# We don't need to create a wrapper script.
10725b3a827e2Smrg	link_command=$compile_var$compile_command$compile_rpath
10726f05b35a2Smrg	# Replace the output file specification.
1072749e108a1Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728f05b35a2Smrg	# Delete the old output file.
10729f05b35a2Smrg	$opt_dry_run || $RM $output
10730f05b35a2Smrg	# Link the executable and exit
10731f05b35a2Smrg	func_show_eval "$link_command" 'exit $?'
1073267ab2ff2Smrg
1073367ab2ff2Smrg	if test -n "$postlink_cmds"; then
1073467ab2ff2Smrg	  func_to_tool_file "$output"
1073567ab2ff2Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1073667ab2ff2Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1073767ab2ff2Smrg	fi
1073867ab2ff2Smrg
10739e0963edeSmrg	exit $EXIT_SUCCESS
10740f05b35a2Smrg      fi
10741e0963edeSmrg
10742b3a827e2Smrg      case $hardcode_action,$fast_install in
10743b3a827e2Smrg        relink,*)
10744b3a827e2Smrg	  # Fast installation is not supported
10745b3a827e2Smrg	  link_command=$compile_var$compile_command$compile_rpath
10746b3a827e2Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10747f05b35a2Smrg
10748b3a827e2Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10749b3a827e2Smrg	  func_warning "'$output' will be relinked during installation"
10750b3a827e2Smrg	  ;;
10751b3a827e2Smrg        *,yes)
10752b3a827e2Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753b3a827e2Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754b3a827e2Smrg          ;;
10755b3a827e2Smrg	*,no)
10756b3a827e2Smrg	  link_command=$compile_var$compile_command$compile_rpath
10757b3a827e2Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758b3a827e2Smrg          ;;
10759b3a827e2Smrg	*,needless)
10760b3a827e2Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761b3a827e2Smrg	  relink_command=
10762b3a827e2Smrg          ;;
10763b3a827e2Smrg      esac
10764e0963edeSmrg
10765f05b35a2Smrg      # Replace the output file specification.
1076649e108a1Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767e0963edeSmrg
10768f05b35a2Smrg      # Delete the old output files.
10769f05b35a2Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770e0963edeSmrg
10771f05b35a2Smrg      func_show_eval "$link_command" 'exit $?'
10772e0963edeSmrg
1077367ab2ff2Smrg      if test -n "$postlink_cmds"; then
1077467ab2ff2Smrg	func_to_tool_file "$output_objdir/$outputname"
1077567ab2ff2Smrg	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'`
1077667ab2ff2Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1077767ab2ff2Smrg      fi
1077867ab2ff2Smrg
10779f05b35a2Smrg      # Now create the wrapper script.
10780f05b35a2Smrg      func_verbose "creating $output"
10781e0963edeSmrg
10782f05b35a2Smrg      # Quote the relink command for shipping.
10783f05b35a2Smrg      if test -n "$relink_command"; then
10784f05b35a2Smrg	# Preserve any variables that may affect compiler behavior
10785f05b35a2Smrg	for var in $variables_saved_for_relink; do
10786f05b35a2Smrg	  if eval test -z \"\${$var+set}\"; then
10787f05b35a2Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788f05b35a2Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789f05b35a2Smrg	    relink_command="$var=; export $var; $relink_command"
10790e0963edeSmrg	  else
10791c30f5000Smrg	    func_quote_arg pretty "$var_value"
10792c30f5000Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793e0963edeSmrg	  fi
10794f05b35a2Smrg	done
10795c30f5000Smrg	func_quote eval cd "`pwd`"
10796c30f5000Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797c30f5000Smrg	relink_command=$func_quote_arg_unquoted_result
10798f05b35a2Smrg      fi
10799f05b35a2Smrg
10800f05b35a2Smrg      # Only actually do things if not in dry run mode.
10801f05b35a2Smrg      $opt_dry_run || {
10802f05b35a2Smrg	# win32 will think the script is a binary if it has
10803f05b35a2Smrg	# a .exe suffix, so we strip it off here.
10804f05b35a2Smrg	case $output in
10805f05b35a2Smrg	  *.exe) func_stripname '' '.exe' "$output"
10806f05b35a2Smrg	         output=$func_stripname_result ;;
10807f05b35a2Smrg	esac
10808f05b35a2Smrg	# test for cygwin because mv fails w/o .exe extensions
10809f05b35a2Smrg	case $host in
10810f05b35a2Smrg	  *cygwin*)
10811f05b35a2Smrg	    exeext=.exe
10812f05b35a2Smrg	    func_stripname '' '.exe' "$outputname"
10813f05b35a2Smrg	    outputname=$func_stripname_result ;;
10814f05b35a2Smrg	  *) exeext= ;;
10815e0963edeSmrg	esac
10816f05b35a2Smrg	case $host in
10817f05b35a2Smrg	  *cygwin* | *mingw* )
10818f05b35a2Smrg	    func_dirname_and_basename "$output" "" "."
10819f05b35a2Smrg	    output_name=$func_basename_result
10820f05b35a2Smrg	    output_path=$func_dirname_result
10821b3a827e2Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822b3a827e2Smrg	    cwrapper=$output_path/$output_name.exe
10823f05b35a2Smrg	    $RM $cwrappersource $cwrapper
10824f05b35a2Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825f05b35a2Smrg
10826f05b35a2Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10827f05b35a2Smrg
10828f05b35a2Smrg	    # The wrapper executable is built using the $host compiler,
10829f05b35a2Smrg	    # because it contains $host paths and files. If cross-
10830f05b35a2Smrg	    # compiling, it, like the target executable, must be
10831f05b35a2Smrg	    # executed on the $host or under an emulation environment.
10832f05b35a2Smrg	    $opt_dry_run || {
10833f05b35a2Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834f05b35a2Smrg	      $STRIP $cwrapper
10835f05b35a2Smrg	    }
10836e0963edeSmrg
10837f05b35a2Smrg	    # Now, create the wrapper script for func_source use:
10838f05b35a2Smrg	    func_ltwrapper_scriptname $cwrapper
10839f05b35a2Smrg	    $RM $func_ltwrapper_scriptname_result
10840f05b35a2Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841f05b35a2Smrg	    $opt_dry_run || {
10842f05b35a2Smrg	      # note: this script will not be executed, so do not chmod.
10843b3a827e2Smrg	      if test "x$build" = "x$host"; then
10844f05b35a2Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10845f05b35a2Smrg	      else
10846f05b35a2Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10847f05b35a2Smrg	      fi
10848f05b35a2Smrg	    }
10849f05b35a2Smrg	  ;;
10850f05b35a2Smrg	  * )
10851f05b35a2Smrg	    $RM $output
10852f05b35a2Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853e0963edeSmrg
10854f05b35a2Smrg	    func_emit_wrapper no > $output
10855f05b35a2Smrg	    chmod +x $output
10856f05b35a2Smrg	  ;;
10857f05b35a2Smrg	esac
10858f05b35a2Smrg      }
10859f05b35a2Smrg      exit $EXIT_SUCCESS
10860f05b35a2Smrg      ;;
10861f05b35a2Smrg    esac
10862e0963edeSmrg
10863f05b35a2Smrg    # See if we need to build an old-fashioned archive.
10864f05b35a2Smrg    for oldlib in $oldlibs; do
10865e0963edeSmrg
10866b3a827e2Smrg      case $build_libtool_libs in
10867b3a827e2Smrg        convenience)
10868b3a827e2Smrg	  oldobjs="$libobjs_save $symfileobj"
10869b3a827e2Smrg	  addlibs=$convenience
10870f05b35a2Smrg	  build_libtool_libs=no
10871b3a827e2Smrg	  ;;
10872b3a827e2Smrg	module)
10873b3a827e2Smrg	  oldobjs=$libobjs_save
10874b3a827e2Smrg	  addlibs=$old_convenience
10875b3a827e2Smrg	  build_libtool_libs=no
10876b3a827e2Smrg          ;;
10877b3a827e2Smrg	*)
10878f05b35a2Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879b3a827e2Smrg	  $preload && test -f "$symfileobj" \
10880b3a827e2Smrg	    && func_append oldobjs " $symfileobj"
10881b3a827e2Smrg	  addlibs=$old_convenience
10882b3a827e2Smrg	  ;;
10883b3a827e2Smrg      esac
10884e0963edeSmrg
10885f05b35a2Smrg      if test -n "$addlibs"; then
10886b3a827e2Smrg	gentop=$output_objdir/${outputname}x
1088767ab2ff2Smrg	func_append generated " $gentop"
10888e0963edeSmrg
10889f05b35a2Smrg	func_extract_archives $gentop $addlibs
1089067ab2ff2Smrg	func_append oldobjs " $func_extract_archives_result"
10891f05b35a2Smrg      fi
10892e0963edeSmrg
10893f05b35a2Smrg      # Do each command in the archive commands.
10894b3a827e2Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895f05b35a2Smrg	cmds=$old_archive_from_new_cmds
10896f05b35a2Smrg      else
10897e0963edeSmrg
10898f05b35a2Smrg	# Add any objects from preloaded convenience libraries
10899f05b35a2Smrg	if test -n "$dlprefiles"; then
10900b3a827e2Smrg	  gentop=$output_objdir/${outputname}x
1090167ab2ff2Smrg	  func_append generated " $gentop"
10902e0963edeSmrg
10903f05b35a2Smrg	  func_extract_archives $gentop $dlprefiles
1090467ab2ff2Smrg	  func_append oldobjs " $func_extract_archives_result"
10905f05b35a2Smrg	fi
10906e0963edeSmrg
10907f05b35a2Smrg	# POSIX demands no paths to be encoded in archives.  We have
10908f05b35a2Smrg	# to avoid creating archives with duplicate basenames if we
10909f05b35a2Smrg	# might have to extract them afterwards, e.g., when creating a
10910f05b35a2Smrg	# static archive out of a convenience library, or when linking
10911f05b35a2Smrg	# the entirety of a libtool archive into another (currently
10912f05b35a2Smrg	# not supported by libtool).
10913f05b35a2Smrg	if (for obj in $oldobjs
10914f05b35a2Smrg	    do
10915f05b35a2Smrg	      func_basename "$obj"
10916f05b35a2Smrg	      $ECHO "$func_basename_result"
10917f05b35a2Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918f05b35a2Smrg	  :
10919f05b35a2Smrg	else
1092049e108a1Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921b3a827e2Smrg	  gentop=$output_objdir/${outputname}x
1092267ab2ff2Smrg	  func_append generated " $gentop"
10923f05b35a2Smrg	  func_mkdir_p "$gentop"
10924f05b35a2Smrg	  save_oldobjs=$oldobjs
10925f05b35a2Smrg	  oldobjs=
10926f05b35a2Smrg	  counter=1
10927f05b35a2Smrg	  for obj in $save_oldobjs
10928f05b35a2Smrg	  do
10929f05b35a2Smrg	    func_basename "$obj"
10930b3a827e2Smrg	    objbase=$func_basename_result
10931f05b35a2Smrg	    case " $oldobjs " in
10932f05b35a2Smrg	    " ") oldobjs=$obj ;;
10933f05b35a2Smrg	    *[\ /]"$objbase "*)
10934f05b35a2Smrg	      while :; do
10935f05b35a2Smrg		# Make sure we don't pick an alternate name that also
10936f05b35a2Smrg		# overlaps.
10937f05b35a2Smrg		newobj=lt$counter-$objbase
10938f05b35a2Smrg		func_arith $counter + 1
10939f05b35a2Smrg		counter=$func_arith_result
10940f05b35a2Smrg		case " $oldobjs " in
10941f05b35a2Smrg		*[\ /]"$newobj "*) ;;
10942f05b35a2Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943f05b35a2Smrg		esac
10944f05b35a2Smrg	      done
10945f05b35a2Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1094667ab2ff2Smrg	      func_append oldobjs " $gentop/$newobj"
10947f05b35a2Smrg	      ;;
1094867ab2ff2Smrg	    *) func_append oldobjs " $obj" ;;
10949f05b35a2Smrg	    esac
10950e0963edeSmrg	  done
10951e0963edeSmrg	fi
10952e494fffdSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953e494fffdSmrg	tool_oldlib=$func_to_tool_file_result
10954f05b35a2Smrg	eval cmds=\"$old_archive_cmds\"
10955e0963edeSmrg
10956f05b35a2Smrg	func_len " $cmds"
10957f05b35a2Smrg	len=$func_len_result
10958f05b35a2Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959f05b35a2Smrg	  cmds=$old_archive_cmds
1096067ab2ff2Smrg	elif test -n "$archiver_list_spec"; then
1096167ab2ff2Smrg	  func_verbose "using command file archive linking..."
1096267ab2ff2Smrg	  for obj in $oldobjs
1096367ab2ff2Smrg	  do
1096467ab2ff2Smrg	    func_to_tool_file "$obj"
1096567ab2ff2Smrg	    $ECHO "$func_to_tool_file_result"
1096667ab2ff2Smrg	  done > $output_objdir/$libname.libcmd
1096767ab2ff2Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1096867ab2ff2Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1096967ab2ff2Smrg	  cmds=$old_archive_cmds
10970f05b35a2Smrg	else
10971f05b35a2Smrg	  # the command line is too long to link in one step, link in parts
10972f05b35a2Smrg	  func_verbose "using piecewise archive linking..."
10973f05b35a2Smrg	  save_RANLIB=$RANLIB
10974f05b35a2Smrg	  RANLIB=:
10975f05b35a2Smrg	  objlist=
10976f05b35a2Smrg	  concat_cmds=
10977f05b35a2Smrg	  save_oldobjs=$oldobjs
10978f05b35a2Smrg	  oldobjs=
10979f05b35a2Smrg	  # Is there a better way of finding the last object in the list?
10980f05b35a2Smrg	  for obj in $save_oldobjs
10981f05b35a2Smrg	  do
10982f05b35a2Smrg	    last_oldobj=$obj
10983f05b35a2Smrg	  done
10984f05b35a2Smrg	  eval test_cmds=\"$old_archive_cmds\"
10985f05b35a2Smrg	  func_len " $test_cmds"
10986f05b35a2Smrg	  len0=$func_len_result
10987f05b35a2Smrg	  len=$len0
10988f05b35a2Smrg	  for obj in $save_oldobjs
10989f05b35a2Smrg	  do
10990f05b35a2Smrg	    func_len " $obj"
10991f05b35a2Smrg	    func_arith $len + $func_len_result
10992f05b35a2Smrg	    len=$func_arith_result
10993f05b35a2Smrg	    func_append objlist " $obj"
10994f05b35a2Smrg	    if test "$len" -lt "$max_cmd_len"; then
10995f05b35a2Smrg	      :
10996f05b35a2Smrg	    else
10997f05b35a2Smrg	      # the above command should be used before it gets too long
10998f05b35a2Smrg	      oldobjs=$objlist
10999b3a827e2Smrg	      if test "$obj" = "$last_oldobj"; then
11000f05b35a2Smrg		RANLIB=$save_RANLIB
11001f05b35a2Smrg	      fi
11002f05b35a2Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003b3a827e2Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004f05b35a2Smrg	      objlist=
11005f05b35a2Smrg	      len=$len0
11006f05b35a2Smrg	    fi
11007f05b35a2Smrg	  done
11008f05b35a2Smrg	  RANLIB=$save_RANLIB
11009f05b35a2Smrg	  oldobjs=$objlist
11010b3a827e2Smrg	  if test -z "$oldobjs"; then
11011f05b35a2Smrg	    eval cmds=\"\$concat_cmds\"
11012f05b35a2Smrg	  else
11013f05b35a2Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014f05b35a2Smrg	  fi
11015f05b35a2Smrg	fi
11016f05b35a2Smrg      fi
11017f05b35a2Smrg      func_execute_cmds "$cmds" 'exit $?'
11018e0963edeSmrg    done
11019e0963edeSmrg
11020f05b35a2Smrg    test -n "$generated" && \
11021f05b35a2Smrg      func_show_eval "${RM}r$generated"
11022e0963edeSmrg
11023f05b35a2Smrg    # Now create the libtool archive.
11024f05b35a2Smrg    case $output in
11025f05b35a2Smrg    *.la)
11026f05b35a2Smrg      old_library=
11027b3a827e2Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028f05b35a2Smrg      func_verbose "creating $output"
11029e0963edeSmrg
11030f05b35a2Smrg      # Preserve any variables that may affect compiler behavior
11031f05b35a2Smrg      for var in $variables_saved_for_relink; do
11032f05b35a2Smrg	if eval test -z \"\${$var+set}\"; then
11033f05b35a2Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034f05b35a2Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035f05b35a2Smrg	  relink_command="$var=; export $var; $relink_command"
11036e0963edeSmrg	else
11037c30f5000Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038c30f5000Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039e0963edeSmrg	fi
11040f05b35a2Smrg      done
11041f05b35a2Smrg      # Quote the link command for shipping.
11042c30f5000Smrg      func_quote eval cd "`pwd`"
11043c30f5000Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044c30f5000Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045c30f5000Smrg      relink_command=$func_quote_arg_unquoted_result
11046b3a827e2Smrg      if test yes = "$hardcode_automatic"; then
11047f05b35a2Smrg	relink_command=
11048f05b35a2Smrg      fi
11049e0963edeSmrg
11050f05b35a2Smrg      # Only create the output if not a dry run.
11051f05b35a2Smrg      $opt_dry_run || {
11052f05b35a2Smrg	for installed in no yes; do
11053b3a827e2Smrg	  if test yes = "$installed"; then
11054f05b35a2Smrg	    if test -z "$install_libdir"; then
11055f05b35a2Smrg	      break
11056f05b35a2Smrg	    fi
11057b3a827e2Smrg	    output=$output_objdir/${outputname}i
11058f05b35a2Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11059f05b35a2Smrg	    newdependency_libs=
11060f05b35a2Smrg	    for deplib in $dependency_libs; do
11061f05b35a2Smrg	      case $deplib in
11062f05b35a2Smrg	      *.la)
11063f05b35a2Smrg		func_basename "$deplib"
11064b3a827e2Smrg		name=$func_basename_result
11065e494fffdSmrg		func_resolve_sysroot "$deplib"
11066b3a827e2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067f05b35a2Smrg		test -z "$libdir" && \
11068b3a827e2Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1106967ab2ff2Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1107067ab2ff2Smrg		;;
1107167ab2ff2Smrg	      -L*)
1107267ab2ff2Smrg		func_stripname -L '' "$deplib"
1107367ab2ff2Smrg		func_replace_sysroot "$func_stripname_result"
1107467ab2ff2Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1107567ab2ff2Smrg		;;
1107667ab2ff2Smrg	      -R*)
1107767ab2ff2Smrg		func_stripname -R '' "$deplib"
1107867ab2ff2Smrg		func_replace_sysroot "$func_stripname_result"
1107967ab2ff2Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080f05b35a2Smrg		;;
1108167ab2ff2Smrg	      *) func_append newdependency_libs " $deplib" ;;
11082f05b35a2Smrg	      esac
11083f05b35a2Smrg	    done
11084b3a827e2Smrg	    dependency_libs=$newdependency_libs
11085f05b35a2Smrg	    newdlfiles=
11086f05b35a2Smrg
11087f05b35a2Smrg	    for lib in $dlfiles; do
11088f05b35a2Smrg	      case $lib in
11089f05b35a2Smrg	      *.la)
11090f05b35a2Smrg	        func_basename "$lib"
11091b3a827e2Smrg		name=$func_basename_result
11092b3a827e2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093f05b35a2Smrg		test -z "$libdir" && \
11094b3a827e2Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1109567ab2ff2Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096f05b35a2Smrg		;;
1109767ab2ff2Smrg	      *) func_append newdlfiles " $lib" ;;
11098f05b35a2Smrg	      esac
11099f05b35a2Smrg	    done
11100b3a827e2Smrg	    dlfiles=$newdlfiles
11101f05b35a2Smrg	    newdlprefiles=
11102f05b35a2Smrg	    for lib in $dlprefiles; do
11103f05b35a2Smrg	      case $lib in
11104f05b35a2Smrg	      *.la)
11105f05b35a2Smrg		# Only pass preopened files to the pseudo-archive (for
11106f05b35a2Smrg		# eventual linking with the app. that links it) if we
11107f05b35a2Smrg		# didn't already link the preopened objects directly into
11108f05b35a2Smrg		# the library:
11109f05b35a2Smrg		func_basename "$lib"
11110b3a827e2Smrg		name=$func_basename_result
11111b3a827e2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112f05b35a2Smrg		test -z "$libdir" && \
11113b3a827e2Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1111467ab2ff2Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115f05b35a2Smrg		;;
11116f05b35a2Smrg	      esac
11117f05b35a2Smrg	    done
11118b3a827e2Smrg	    dlprefiles=$newdlprefiles
11119f05b35a2Smrg	  else
11120f05b35a2Smrg	    newdlfiles=
11121f05b35a2Smrg	    for lib in $dlfiles; do
11122f05b35a2Smrg	      case $lib in
11123b3a827e2Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124f05b35a2Smrg		*) abs=`pwd`"/$lib" ;;
11125f05b35a2Smrg	      esac
1112667ab2ff2Smrg	      func_append newdlfiles " $abs"
11127f05b35a2Smrg	    done
11128b3a827e2Smrg	    dlfiles=$newdlfiles
11129f05b35a2Smrg	    newdlprefiles=
11130f05b35a2Smrg	    for lib in $dlprefiles; do
11131f05b35a2Smrg	      case $lib in
11132b3a827e2Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133f05b35a2Smrg		*) abs=`pwd`"/$lib" ;;
11134f05b35a2Smrg	      esac
1113567ab2ff2Smrg	      func_append newdlprefiles " $abs"
11136f05b35a2Smrg	    done
11137b3a827e2Smrg	    dlprefiles=$newdlprefiles
11138f05b35a2Smrg	  fi
11139f05b35a2Smrg	  $RM $output
11140f05b35a2Smrg	  # place dlname in correct position for cygwin
1114149e108a1Smrg	  # In fact, it would be nice if we could use this code for all target
1114249e108a1Smrg	  # systems that can't hard-code library paths into their executables
1114349e108a1Smrg	  # and that have no shared library path variable independent of PATH,
1114449e108a1Smrg	  # but it turns out we can't easily determine that from inspecting
1114549e108a1Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1114649e108a1Smrg	  # applies here; at the moment, that means platforms that use the PE
1114749e108a1Smrg	  # object format with DLL files.  See the long comment at the top of
1114849e108a1Smrg	  # tests/bindir.at for full details.
11149f05b35a2Smrg	  tdlname=$dlname
11150f05b35a2Smrg	  case $host,$output,$installed,$module,$dlname in
1115149e108a1Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1115249e108a1Smrg	      # If a -bindir argument was supplied, place the dll there.
11153b3a827e2Smrg	      if test -n "$bindir"; then
1115449e108a1Smrg		func_relative_path "$install_libdir" "$bindir"
11155b3a827e2Smrg		tdlname=$func_relative_path_result/$dlname
1115649e108a1Smrg	      else
1115749e108a1Smrg		# Otherwise fall back on heuristic.
1115849e108a1Smrg		tdlname=../bin/$dlname
1115949e108a1Smrg	      fi
1116049e108a1Smrg	      ;;
11161f05b35a2Smrg	  esac
11162f05b35a2Smrg	  $ECHO > $output "\
11163f05b35a2Smrg# $outputname - a libtool library file
11164b3a827e2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165f05b35a2Smrg#
11166f05b35a2Smrg# Please DO NOT delete this file!
11167f05b35a2Smrg# It is necessary for linking the library.
11168e0963edeSmrg
11169f05b35a2Smrg# The name that we can dlopen(3).
11170f05b35a2Smrgdlname='$tdlname'
11171e0963edeSmrg
11172f05b35a2Smrg# Names of this library.
11173f05b35a2Smrglibrary_names='$library_names'
11174e0963edeSmrg
11175f05b35a2Smrg# The name of the static archive.
11176f05b35a2Smrgold_library='$old_library'
11177e0963edeSmrg
11178b3a827e2Smrg# Linker flags that cannot go in dependency_libs.
11179f05b35a2Smrginherited_linker_flags='$new_inherited_linker_flags'
11180e0963edeSmrg
11181f05b35a2Smrg# Libraries that this one depends upon.
11182f05b35a2Smrgdependency_libs='$dependency_libs'
11183e0963edeSmrg
11184f05b35a2Smrg# Names of additional weak libraries provided by this library
11185f05b35a2Smrgweak_library_names='$weak_libs'
11186e0963edeSmrg
11187f05b35a2Smrg# Version information for $libname.
11188f05b35a2Smrgcurrent=$current
11189f05b35a2Smrgage=$age
11190f05b35a2Smrgrevision=$revision
11191e0963edeSmrg
11192f05b35a2Smrg# Is this an already installed library?
11193f05b35a2Smrginstalled=$installed
11194e0963edeSmrg
11195f05b35a2Smrg# Should we warn about portability when linking against -modules?
11196f05b35a2Smrgshouldnotlink=$module
11197e0963edeSmrg
11198f05b35a2Smrg# Files to dlopen/dlpreopen
11199f05b35a2Smrgdlopen='$dlfiles'
11200f05b35a2Smrgdlpreopen='$dlprefiles'
11201e0963edeSmrg
11202f05b35a2Smrg# Directory that this library needs to be installed in:
11203f05b35a2Smrglibdir='$install_libdir'"
11204b3a827e2Smrg	  if test no,yes = "$installed,$need_relink"; then
11205f05b35a2Smrg	    $ECHO >> $output "\
11206f05b35a2Smrgrelink_command=\"$relink_command\""
11207f05b35a2Smrg	  fi
11208f05b35a2Smrg	done
11209f05b35a2Smrg      }
11210e0963edeSmrg
11211f05b35a2Smrg      # Do a symbolic link so that the libtool archive can be found in
11212f05b35a2Smrg      # LD_LIBRARY_PATH before the program is installed.
11213f05b35a2Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214f05b35a2Smrg      ;;
11215f05b35a2Smrg    esac
11216f05b35a2Smrg    exit $EXIT_SUCCESS
11217f05b35a2Smrg}
11218e0963edeSmrg
11219b3a827e2Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220b3a827e2Smrg  func_mode_link ${1+"$@"}
11221b3a827e2Smrgfi
11222e0963edeSmrg
11223e0963edeSmrg
11224f05b35a2Smrg# func_mode_uninstall arg...
11225f05b35a2Smrgfunc_mode_uninstall ()
11226f05b35a2Smrg{
11227b3a827e2Smrg    $debug_cmd
11228b3a827e2Smrg
11229b3a827e2Smrg    RM=$nonopt
11230e0963edeSmrg    files=
11231b3a827e2Smrg    rmforce=false
11232e0963edeSmrg    exit_status=0
11233e0963edeSmrg
11234e0963edeSmrg    # This variable tells wrapper scripts just to set variables rather
11235e0963edeSmrg    # than running their programs.
11236b3a827e2Smrg    libtool_install_magic=$magic
11237e0963edeSmrg
11238e0963edeSmrg    for arg
11239e0963edeSmrg    do
11240e0963edeSmrg      case $arg in
11241b3a827e2Smrg      -f) func_append RM " $arg"; rmforce=: ;;
1124267ab2ff2Smrg      -*) func_append RM " $arg" ;;
1124367ab2ff2Smrg      *) func_append files " $arg" ;;
11244e0963edeSmrg      esac
11245e0963edeSmrg    done
11246e0963edeSmrg
11247f05b35a2Smrg    test -z "$RM" && \
11248f05b35a2Smrg      func_fatal_help "you must specify an RM program"
11249e0963edeSmrg
11250e0963edeSmrg    rmdirs=
11251e0963edeSmrg
11252e0963edeSmrg    for file in $files; do
11253f05b35a2Smrg      func_dirname "$file" "" "."
11254b3a827e2Smrg      dir=$func_dirname_result
11255b3a827e2Smrg      if test . = "$dir"; then
11256b3a827e2Smrg	odir=$objdir
11257e0963edeSmrg      else
11258b3a827e2Smrg	odir=$dir/$objdir
11259e0963edeSmrg      fi
11260f05b35a2Smrg      func_basename "$file"
11261b3a827e2Smrg      name=$func_basename_result
11262b3a827e2Smrg      test uninstall = "$opt_mode" && odir=$dir
11263e0963edeSmrg
1126467ab2ff2Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265b3a827e2Smrg      if test clean = "$opt_mode"; then
11266e0963edeSmrg	case " $rmdirs " in
1126767ab2ff2Smrg	  *" $odir "*) ;;
1126867ab2ff2Smrg	  *) func_append rmdirs " $odir" ;;
11269e0963edeSmrg	esac
11270e0963edeSmrg      fi
11271e0963edeSmrg
11272e0963edeSmrg      # Don't error if the file doesn't exist and rm -f was used.
11273f05b35a2Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274f05b35a2Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275f05b35a2Smrg	 test -f "$file"; then
11276e0963edeSmrg	:
11277e0963edeSmrg      elif test -d "$file"; then
11278e0963edeSmrg	exit_status=1
11279e0963edeSmrg	continue
11280b3a827e2Smrg      elif $rmforce; then
11281e0963edeSmrg	continue
11282e0963edeSmrg      fi
11283e0963edeSmrg
11284b3a827e2Smrg      rmfiles=$file
11285e0963edeSmrg
11286e0963edeSmrg      case $name in
11287e0963edeSmrg      *.la)
11288e0963edeSmrg	# Possibly a libtool archive, so verify it.
11289f05b35a2Smrg	if func_lalib_p "$file"; then
11290f05b35a2Smrg	  func_source $dir/$name
11291e0963edeSmrg
11292e0963edeSmrg	  # Delete the libtool libraries and symlinks.
11293e0963edeSmrg	  for n in $library_names; do
1129467ab2ff2Smrg	    func_append rmfiles " $odir/$n"
11295e0963edeSmrg	  done
1129667ab2ff2Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297e0963edeSmrg
11298b3a827e2Smrg	  case $opt_mode in
11299e0963edeSmrg	  clean)
1130067ab2ff2Smrg	    case " $library_names " in
11301e0963edeSmrg	    *" $dlname "*) ;;
1130267ab2ff2Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303e0963edeSmrg	    esac
1130467ab2ff2Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305e0963edeSmrg	    ;;
11306e0963edeSmrg	  uninstall)
11307e0963edeSmrg	    if test -n "$library_names"; then
11308e0963edeSmrg	      # Do each command in the postuninstall commands.
11309b3a827e2Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310e0963edeSmrg	    fi
11311e0963edeSmrg
11312e0963edeSmrg	    if test -n "$old_library"; then
11313e0963edeSmrg	      # Do each command in the old_postuninstall commands.
11314b3a827e2Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315e0963edeSmrg	    fi
11316e0963edeSmrg	    # FIXME: should reinstall the best remaining shared library.
11317e0963edeSmrg	    ;;
11318e0963edeSmrg	  esac
11319e0963edeSmrg	fi
11320e0963edeSmrg	;;
11321e0963edeSmrg
11322e0963edeSmrg      *.lo)
11323e0963edeSmrg	# Possibly a libtool object, so verify it.
11324f05b35a2Smrg	if func_lalib_p "$file"; then
11325e0963edeSmrg
11326e0963edeSmrg	  # Read the .lo file
11327f05b35a2Smrg	  func_source $dir/$name
11328e0963edeSmrg
11329e0963edeSmrg	  # Add PIC object to the list of files to remove.
11330b3a827e2Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1133167ab2ff2Smrg	    func_append rmfiles " $dir/$pic_object"
11332e0963edeSmrg	  fi
11333e0963edeSmrg
11334e0963edeSmrg	  # Add non-PIC object to the list of files to remove.
11335b3a827e2Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1133667ab2ff2Smrg	    func_append rmfiles " $dir/$non_pic_object"
11337e0963edeSmrg	  fi
11338e0963edeSmrg	fi
11339e0963edeSmrg	;;
11340e0963edeSmrg
11341e0963edeSmrg      *)
11342b3a827e2Smrg	if test clean = "$opt_mode"; then
11343e0963edeSmrg	  noexename=$name
11344e0963edeSmrg	  case $file in
11345e0963edeSmrg	  *.exe)
11346f05b35a2Smrg	    func_stripname '' '.exe' "$file"
11347f05b35a2Smrg	    file=$func_stripname_result
11348f05b35a2Smrg	    func_stripname '' '.exe' "$name"
11349f05b35a2Smrg	    noexename=$func_stripname_result
11350e0963edeSmrg	    # $file with .exe has already been added to rmfiles,
11351e0963edeSmrg	    # add $file without .exe
1135267ab2ff2Smrg	    func_append rmfiles " $file"
11353e0963edeSmrg	    ;;
11354e0963edeSmrg	  esac
11355e0963edeSmrg	  # Do a test to see if this is a libtool program.
11356f05b35a2Smrg	  if func_ltwrapper_p "$file"; then
11357f05b35a2Smrg	    if func_ltwrapper_executable_p "$file"; then
11358f05b35a2Smrg	      func_ltwrapper_scriptname "$file"
11359f05b35a2Smrg	      relink_command=
11360f05b35a2Smrg	      func_source $func_ltwrapper_scriptname_result
1136167ab2ff2Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362f05b35a2Smrg	    else
11363f05b35a2Smrg	      relink_command=
11364f05b35a2Smrg	      func_source $dir/$noexename
11365f05b35a2Smrg	    fi
11366e0963edeSmrg
11367e0963edeSmrg	    # note $name still contains .exe if it was in $file originally
11368e0963edeSmrg	    # as does the version of $file that was added into $rmfiles
11369b3a827e2Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370b3a827e2Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1137167ab2ff2Smrg	      func_append rmfiles " $odir/lt-$name"
11372e0963edeSmrg	    fi
11373b3a827e2Smrg	    if test "X$noexename" != "X$name"; then
11374b3a827e2Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375e0963edeSmrg	    fi
11376e0963edeSmrg	  fi
11377e0963edeSmrg	fi
11378e0963edeSmrg	;;
11379e0963edeSmrg      esac
11380f05b35a2Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381e0963edeSmrg    done
11382e0963edeSmrg
11383b3a827e2Smrg    # Try to remove the $objdir's in the directories where we deleted files
11384e0963edeSmrg    for dir in $rmdirs; do
11385e0963edeSmrg      if test -d "$dir"; then
11386f05b35a2Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387e0963edeSmrg      fi
11388e0963edeSmrg    done
11389e0963edeSmrg
11390e0963edeSmrg    exit $exit_status
11391f05b35a2Smrg}
11392e0963edeSmrg
11393b3a827e2Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394b3a827e2Smrg  func_mode_uninstall ${1+"$@"}
11395b3a827e2Smrgfi
11396e0963edeSmrg
1139767ab2ff2Smrgtest -z "$opt_mode" && {
11398b3a827e2Smrg  help=$generic_help
11399f05b35a2Smrg  func_fatal_help "you must specify a MODE"
11400f05b35a2Smrg}
11401f05b35a2Smrg
11402f05b35a2Smrgtest -z "$exec_cmd" && \
11403b3a827e2Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404e0963edeSmrg
11405e0963edeSmrgif test -n "$exec_cmd"; then
11406f05b35a2Smrg  eval exec "$exec_cmd"
11407e0963edeSmrg  exit $EXIT_FAILURE
11408e0963edeSmrgfi
11409e0963edeSmrg
11410f05b35a2Smrgexit $exit_status
11411e0963edeSmrg
11412e0963edeSmrg
11413e0963edeSmrg# The TAGs below are defined such that we never get into a situation
11414b3a827e2Smrg# where we disable both kinds of libraries.  Given conflicting
11415e0963edeSmrg# choices, we go for a static library, that is the most portable,
11416e0963edeSmrg# since we can't tell whether shared libraries were disabled because
11417e0963edeSmrg# the user asked for that or because the platform doesn't support
11418e0963edeSmrg# them.  This is particularly important on AIX, because we don't
11419e0963edeSmrg# support having both static and shared libraries enabled at the same
11420e0963edeSmrg# time on that platform, so we default to a shared-only configuration.
11421e0963edeSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422e0963edeSmrg# configuration.  But we'll never go from static-only to shared-only.
11423e0963edeSmrg
11424e0963edeSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425f05b35a2Smrgbuild_libtool_libs=no
11426f05b35a2Smrgbuild_old_libs=yes
11427e0963edeSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428e0963edeSmrg
11429e0963edeSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430f05b35a2Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431e0963edeSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432e0963edeSmrg
11433e0963edeSmrg# Local Variables:
11434e0963edeSmrg# mode:shell-script
11435e0963edeSmrg# sh-indentation:2
11436e0963edeSmrg# End:
11437