1ee3e8c14Smrg#! /usr/bin/env sh
2ee3e8c14Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3ee3e8c14Smrg##               by inline-source v2019-02-19.15
4b290cf36Smrg
58f9fac4aSmrg# libtool (GNU libtool) 2.5.4
6ee3e8c14Smrg# Provide generalized library-building support services.
7b290cf36Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8b290cf36Smrg
98f9fac4aSmrg# Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc.
10b290cf36Smrg# This is free software; see the source for copying conditions.  There is NO
11b290cf36Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12b290cf36Smrg
13b290cf36Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14191cded7Smrg# it under the terms of the GNU General Public License as published by
15191cded7Smrg# the Free Software Foundation; either version 2 of the License, or
16191cded7Smrg# (at your option) any later version.
17191cded7Smrg#
18b290cf36Smrg# As a special exception to the GNU General Public License,
19b290cf36Smrg# if you distribute this file as part of a program or library that
20b290cf36Smrg# is built using GNU Libtool, you may include this file under the
21b290cf36Smrg# same distribution terms that you use for the rest of that program.
22b290cf36Smrg#
23b290cf36Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24191cded7Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25191cded7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26191cded7Smrg# General Public License for more details.
27191cded7Smrg#
28191cded7Smrg# You should have received a copy of the GNU General Public License
29ee3e8c14Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30b290cf36Smrg
31ee3e8c14Smrg
32ee3e8c14SmrgPROGRAM=libtool
33ee3e8c14SmrgPACKAGE=libtool
348f9fac4aSmrgVERSION=2.5.4
358f9fac4aSmrgpackage_revision=2.5.4
36ee3e8c14Smrg
37ee3e8c14Smrg
38ee3e8c14Smrg## ------ ##
39ee3e8c14Smrg## Usage. ##
40ee3e8c14Smrg## ------ ##
41ee3e8c14Smrg
42ee3e8c14Smrg# Run './libtool --help' for help with using this script from the
43ee3e8c14Smrg# command line.
44ee3e8c14Smrg
45ee3e8c14Smrg
46ee3e8c14Smrg## ------------------------------- ##
47ee3e8c14Smrg## User overridable command paths. ##
48ee3e8c14Smrg## ------------------------------- ##
49ee3e8c14Smrg
50ee3e8c14Smrg# After configure completes, it has a better idea of some of the
51ee3e8c14Smrg# shell tools we need than the defaults used by the functions shared
52ee3e8c14Smrg# with bootstrap, so set those here where they can still be over-
53ee3e8c14Smrg# ridden by the user, but otherwise take precedence.
54ee3e8c14Smrg
55ee3e8c14Smrg: ${AUTOCONF="autoconf"}
56ee3e8c14Smrg: ${AUTOMAKE="automake"}
57ee3e8c14Smrg
58ee3e8c14Smrg
59ee3e8c14Smrg## -------------------------- ##
60ee3e8c14Smrg## Source external libraries. ##
61ee3e8c14Smrg## -------------------------- ##
62ee3e8c14Smrg
63ee3e8c14Smrg# Much of our low-level functionality needs to be sourced from external
64ee3e8c14Smrg# libraries, which are installed to $pkgauxdir.
65ee3e8c14Smrg
66ee3e8c14Smrg# Set a version string for this script.
67ee3e8c14Smrgscriptversion=2019-02-19.15; # UTC
68ee3e8c14Smrg
69ee3e8c14Smrg# General shell script boiler plate, and helper functions.
70ee3e8c14Smrg# Written by Gary V. Vaughan, 2004
71ee3e8c14Smrg
72ee3e8c14Smrg# This is free software.  There is NO warranty; not even for
73ee3e8c14Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74b290cf36Smrg#
758f9fac4aSmrg# Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors
76b290cf36Smrg#
77ee3e8c14Smrg# This file is dual licensed under the terms of the MIT license
788f9fac4aSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
798f9fac4aSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80ee3e8c14Smrg# these licenses when using or redistributing this software or any of
81ee3e8c14Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82ee3e8c14Smrg# included in the Bootstrap distribution for the full license texts.
83ee3e8c14Smrg
84ee3e8c14Smrg# Please report bugs or propose patches to:
85ee3e8c14Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86ee3e8c14Smrg
87ee3e8c14Smrg
88ee3e8c14Smrg## ------ ##
89ee3e8c14Smrg## Usage. ##
90ee3e8c14Smrg## ------ ##
91ee3e8c14Smrg
92ee3e8c14Smrg# Evaluate this file near the top of your script to gain access to
93ee3e8c14Smrg# the functions and variables defined here:
94b290cf36Smrg#
95ee3e8c14Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96b290cf36Smrg#
97ee3e8c14Smrg# If you need to override any of the default environment variable
98ee3e8c14Smrg# settings, do that before evaluating this file.
99b290cf36Smrg
100b290cf36Smrg
101ee3e8c14Smrg## -------------------- ##
102ee3e8c14Smrg## Shell normalisation. ##
103ee3e8c14Smrg## -------------------- ##
104ee3e8c14Smrg
105ee3e8c14Smrg# Some shells need a little help to be as Bourne compatible as possible.
106ee3e8c14Smrg# Before doing anything else, make sure all that help has been provided!
107ee3e8c14Smrg
108ee3e8c14SmrgDUALCASE=1; export DUALCASE # for MKS sh
109ee3e8c14Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110b290cf36Smrg  emulate sh
111b290cf36Smrg  NULLCMD=:
112ee3e8c14Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113b290cf36Smrg  # is contrary to our usage.  Disable this feature.
114b290cf36Smrg  alias -g '${1+"$@"}'='"$@"'
115b290cf36Smrg  setopt NO_GLOB_SUBST
116b290cf36Smrgelse
117ee3e8c14Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118b290cf36Smrgfi
119ba064abeSmrg
120ee3e8c14Smrg# NLS nuisances: We save the old values in case they are required later.
121ee3e8c14Smrg_G_user_locale=
122ee3e8c14Smrg_G_safe_locale=
123ee3e8c14Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124b290cf36Smrgdo
125ee3e8c14Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126ee3e8c14Smrg          save_$_G_var=\$$_G_var
127ee3e8c14Smrg          $_G_var=C
128ee3e8c14Smrg	  export $_G_var
129ee3e8c14Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130ee3e8c14Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131b290cf36Smrg	fi"
132b290cf36Smrgdone
133ee3e8c14Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134ee3e8c14Smrg# in case the environment reset is needed later and the $save_* variant is not
135ee3e8c14Smrg# defined (see the code above).
136ba064abeSmrgLC_ALL=C
137ba064abeSmrgLANGUAGE=C
138ba064abeSmrgexport LANGUAGE LC_ALL
139b290cf36Smrg
140ee3e8c14Smrg# Make sure IFS has a sensible default
141ee3e8c14Smrgsp=' '
142ee3e8c14Smrgnl='
143ee3e8c14Smrg'
144ee3e8c14SmrgIFS="$sp	$nl"
145ee3e8c14Smrg
1468f9fac4aSmrg# There are apparently some systems that use ';' as a PATH separator!
147ee3e8c14Smrgif test "${PATH_SEPARATOR+set}" != set; then
148ee3e8c14Smrg  PATH_SEPARATOR=:
149ee3e8c14Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150ee3e8c14Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151ee3e8c14Smrg      PATH_SEPARATOR=';'
152ee3e8c14Smrg  }
153ee3e8c14Smrgfi
154b290cf36Smrg
155b290cf36Smrg
156ee3e8c14Smrg# func_unset VAR
157ee3e8c14Smrg# --------------
158ee3e8c14Smrg# Portably unset VAR.
159ee3e8c14Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160ee3e8c14Smrg# status if VAR is already unset, which might be problematic if the
161ee3e8c14Smrg# statement is used at the end of a function (thus poisoning its return
162ee3e8c14Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163ee3e8c14Smrg# the script in this case).
164ee3e8c14Smrgfunc_unset ()
165ee3e8c14Smrg{
166ee3e8c14Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167ee3e8c14Smrg}
168b290cf36Smrg
169b290cf36Smrg
170ee3e8c14Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171ee3e8c14Smrgfunc_unset CDPATH
172191cded7Smrg
173ee3e8c14Smrg# Make sure ${,E,F}GREP behave sanely.
174ee3e8c14Smrgfunc_unset GREP_OPTIONS
175b290cf36Smrg
176b290cf36Smrg
177ee3e8c14Smrg## ------------------------- ##
178ee3e8c14Smrg## Locate command utilities. ##
179ee3e8c14Smrg## ------------------------- ##
180b290cf36Smrg
181b290cf36Smrg
182ee3e8c14Smrg# func_executable_p FILE
183ee3e8c14Smrg# ----------------------
184ee3e8c14Smrg# Check that FILE is an executable regular file.
185ee3e8c14Smrgfunc_executable_p ()
186d9dcd5aeSmrg{
187ee3e8c14Smrg    test -f "$1" && test -x "$1"
188ee3e8c14Smrg}
189d9dcd5aeSmrg
190d9dcd5aeSmrg
191ee3e8c14Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192ee3e8c14Smrg# --------------------------------------------
193ee3e8c14Smrg# Search for either a program that responds to --version with output
194ee3e8c14Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195ee3e8c14Smrg# trying all the directories in PATH with each of the elements of
196ee3e8c14Smrg# PROGS_LIST.
197ee3e8c14Smrg#
198ee3e8c14Smrg# CHECK_FUNC should accept the path to a candidate program, and
199ee3e8c14Smrg# set $func_check_prog_result if it truncates its output less than
200ee3e8c14Smrg# $_G_path_prog_max characters.
201ee3e8c14Smrgfunc_path_progs ()
202d9dcd5aeSmrg{
203ee3e8c14Smrg    _G_progs_list=$1
204ee3e8c14Smrg    _G_check_func=$2
205ee3e8c14Smrg    _G_PATH=${3-"$PATH"}
206ee3e8c14Smrg
207ee3e8c14Smrg    _G_path_prog_max=0
208ee3e8c14Smrg    _G_path_prog_found=false
209ee3e8c14Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210ee3e8c14Smrg    for _G_dir in $_G_PATH; do
211ee3e8c14Smrg      IFS=$_G_save_IFS
212ee3e8c14Smrg      test -z "$_G_dir" && _G_dir=.
213ee3e8c14Smrg      for _G_prog_name in $_G_progs_list; do
214ee3e8c14Smrg        for _exeext in '' .EXE; do
215ee3e8c14Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216ee3e8c14Smrg          func_executable_p "$_G_path_prog" || continue
217ee3e8c14Smrg          case `"$_G_path_prog" --version 2>&1` in
218ee3e8c14Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219ee3e8c14Smrg            *)     $_G_check_func $_G_path_prog
220ee3e8c14Smrg		   func_path_progs_result=$func_check_prog_result
221ee3e8c14Smrg		   ;;
222ee3e8c14Smrg          esac
223ee3e8c14Smrg          $_G_path_prog_found && break 3
224ee3e8c14Smrg        done
225ee3e8c14Smrg      done
226ee3e8c14Smrg    done
227ee3e8c14Smrg    IFS=$_G_save_IFS
228ee3e8c14Smrg    test -z "$func_path_progs_result" && {
229ee3e8c14Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230ee3e8c14Smrg      exit 1
231ee3e8c14Smrg    }
232ee3e8c14Smrg}
233d9dcd5aeSmrg
234d9dcd5aeSmrg
235ee3e8c14Smrg# We want to be able to use the functions in this file before configure
236ee3e8c14Smrg# has figured out where the best binaries are kept, which means we have
237ee3e8c14Smrg# to search for them ourselves - except when the results are already set
238ee3e8c14Smrg# where we skip the searches.
239d9dcd5aeSmrg
240ee3e8c14Smrg# Unless the user overrides by setting SED, search the path for either GNU
241ee3e8c14Smrg# sed, or the sed that truncates its output the least.
242ee3e8c14Smrgtest -z "$SED" && {
243ee3e8c14Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244ee3e8c14Smrg  for _G_i in 1 2 3 4 5 6 7; do
245ee3e8c14Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246ee3e8c14Smrg  done
247ee3e8c14Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248ee3e8c14Smrg  _G_sed_script=
249d9dcd5aeSmrg
250ee3e8c14Smrg  func_check_prog_sed ()
251ee3e8c14Smrg  {
252ee3e8c14Smrg    _G_path_prog=$1
253b290cf36Smrg
254ee3e8c14Smrg    _G_count=0
255ee3e8c14Smrg    printf 0123456789 >conftest.in
256ee3e8c14Smrg    while :
257ee3e8c14Smrg    do
258ee3e8c14Smrg      cat conftest.in conftest.in >conftest.tmp
259ee3e8c14Smrg      mv conftest.tmp conftest.in
260ee3e8c14Smrg      cp conftest.in conftest.nl
261ee3e8c14Smrg      echo '' >> conftest.nl
262ee3e8c14Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263ee3e8c14Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264ee3e8c14Smrg      _G_count=`expr $_G_count + 1`
265ee3e8c14Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266ee3e8c14Smrg        # Best one so far, save it but keep looking for a better one
267ee3e8c14Smrg        func_check_prog_result=$_G_path_prog
268ee3e8c14Smrg        _G_path_prog_max=$_G_count
269ee3e8c14Smrg      fi
270ee3e8c14Smrg      # 10*(2^10) chars as input seems more than enough
271ee3e8c14Smrg      test 10 -lt "$_G_count" && break
272ee3e8c14Smrg    done
273ee3e8c14Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274ee3e8c14Smrg  }
275191cded7Smrg
276ee3e8c14Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277ee3e8c14Smrg  rm -f conftest.sed
278ee3e8c14Smrg  SED=$func_path_progs_result
279ee3e8c14Smrg}
280ba064abeSmrg
281ee3e8c14Smrg
282ee3e8c14Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283ee3e8c14Smrg# grep, or the grep that truncates its output the least.
284ee3e8c14Smrgtest -z "$GREP" && {
285ee3e8c14Smrg  func_check_prog_grep ()
286ee3e8c14Smrg  {
287ee3e8c14Smrg    _G_path_prog=$1
288ee3e8c14Smrg
289ee3e8c14Smrg    _G_count=0
290ee3e8c14Smrg    _G_path_prog_max=0
291ee3e8c14Smrg    printf 0123456789 >conftest.in
292ee3e8c14Smrg    while :
293ee3e8c14Smrg    do
294ee3e8c14Smrg      cat conftest.in conftest.in >conftest.tmp
295ee3e8c14Smrg      mv conftest.tmp conftest.in
296ee3e8c14Smrg      cp conftest.in conftest.nl
297ee3e8c14Smrg      echo 'GREP' >> conftest.nl
298ee3e8c14Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299ee3e8c14Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300ee3e8c14Smrg      _G_count=`expr $_G_count + 1`
301ee3e8c14Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302ee3e8c14Smrg        # Best one so far, save it but keep looking for a better one
303ee3e8c14Smrg        func_check_prog_result=$_G_path_prog
304ee3e8c14Smrg        _G_path_prog_max=$_G_count
305ee3e8c14Smrg      fi
306ee3e8c14Smrg      # 10*(2^10) chars as input seems more than enough
307ee3e8c14Smrg      test 10 -lt "$_G_count" && break
308ee3e8c14Smrg    done
309ee3e8c14Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310ee3e8c14Smrg  }
311ee3e8c14Smrg
312ee3e8c14Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313ee3e8c14Smrg  GREP=$func_path_progs_result
314ee3e8c14Smrg}
315ee3e8c14Smrg
316ee3e8c14Smrg
317ee3e8c14Smrg## ------------------------------- ##
318ee3e8c14Smrg## User overridable command paths. ##
319ee3e8c14Smrg## ------------------------------- ##
320ee3e8c14Smrg
321ee3e8c14Smrg# All uppercase variable names are used for environment variables.  These
322ee3e8c14Smrg# variables can be overridden by the user before calling a script that
323ee3e8c14Smrg# uses them if a suitable command of that name is not already available
324ee3e8c14Smrg# in the command search PATH.
325ee3e8c14Smrg
326ee3e8c14Smrg: ${CP="cp -f"}
327ee3e8c14Smrg: ${ECHO="printf %s\n"}
328ee3e8c14Smrg: ${EGREP="$GREP -E"}
329ee3e8c14Smrg: ${FGREP="$GREP -F"}
330ee3e8c14Smrg: ${LN_S="ln -s"}
331ee3e8c14Smrg: ${MAKE="make"}
332ee3e8c14Smrg: ${MKDIR="mkdir"}
333ee3e8c14Smrg: ${MV="mv -f"}
334ee3e8c14Smrg: ${RM="rm -f"}
335ee3e8c14Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336ee3e8c14Smrg
337ee3e8c14Smrg
338ee3e8c14Smrg## -------------------- ##
339ee3e8c14Smrg## Useful sed snippets. ##
340ee3e8c14Smrg## -------------------- ##
341ee3e8c14Smrg
342ee3e8c14Smrgsed_dirname='s|/[^/]*$||'
343ee3e8c14Smrgsed_basename='s|^.*/||'
344ee3e8c14Smrg
345ee3e8c14Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346ee3e8c14Smrg# metacharacters that are still active within double-quoted strings.
347ee3e8c14Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348ee3e8c14Smrg
349ee3e8c14Smrg# Same as above, but do not quote variable references.
350ee3e8c14Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351ee3e8c14Smrg
352ee3e8c14Smrg# Sed substitution that turns a string into a regex matching for the
353ee3e8c14Smrg# string literally.
354ee3e8c14Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355ee3e8c14Smrg
356ee3e8c14Smrg# Sed substitution that converts a w32 file name or path
357ee3e8c14Smrg# that contains forward slashes, into one that contains
358ee3e8c14Smrg# (escaped) backslashes.  A very naive implementation.
359ee3e8c14Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360ee3e8c14Smrg
361ee3e8c14Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362ee3e8c14Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363ee3e8c14Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364ee3e8c14Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365ee3e8c14Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366ee3e8c14Smrg_G_bs='\\'
367ee3e8c14Smrg_G_bs2='\\\\'
368ee3e8c14Smrg_G_bs4='\\\\\\\\'
369ee3e8c14Smrg_G_dollar='\$'
370ee3e8c14Smrgsed_double_backslash="\
371ee3e8c14Smrg  s/$_G_bs4/&\\
372ee3e8c14Smrg/g
373ee3e8c14Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374ee3e8c14Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375ee3e8c14Smrg  s/\n//g"
376ee3e8c14Smrg
377ee3e8c14Smrg# require_check_ifs_backslash
378ee3e8c14Smrg# ---------------------------
379ee3e8c14Smrg# Check if we can use backslash as IFS='\' separator, and set
380ee3e8c14Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381ee3e8c14Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382ee3e8c14Smrgfunc_require_check_ifs_backslash ()
383ba064abeSmrg{
384ee3e8c14Smrg  _G_save_IFS=$IFS
385ee3e8c14Smrg  IFS='\'
386ee3e8c14Smrg  _G_check_ifs_backshlash='a\\b'
387ee3e8c14Smrg  for _G_i in $_G_check_ifs_backshlash
388ee3e8c14Smrg  do
389ee3e8c14Smrg  case $_G_i in
390ee3e8c14Smrg  a)
391ee3e8c14Smrg    check_ifs_backshlash_broken=false
392ba064abeSmrg    ;;
393ee3e8c14Smrg  '')
394ee3e8c14Smrg    break
395ba064abeSmrg    ;;
396ee3e8c14Smrg  *)
397ee3e8c14Smrg    check_ifs_backshlash_broken=:
398ee3e8c14Smrg    break
399ba064abeSmrg    ;;
400ba064abeSmrg  esac
401ba064abeSmrg  done
402ee3e8c14Smrg  IFS=$_G_save_IFS
403ee3e8c14Smrg  require_check_ifs_backslash=:
404ba064abeSmrg}
405ba064abeSmrg
406ba064abeSmrg
407ee3e8c14Smrg## ----------------- ##
408ee3e8c14Smrg## Global variables. ##
409ee3e8c14Smrg## ----------------- ##
410ba064abeSmrg
411ee3e8c14Smrg# Except for the global variables explicitly listed below, the following
412ee3e8c14Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413ee3e8c14Smrg# variables initialised in the 'Resource management' section, sourcing
414ee3e8c14Smrg# this file will not pollute your global namespace with anything
415ee3e8c14Smrg# else. There's no portable way to scope variables in Bourne shell
416ee3e8c14Smrg# though, so actually running these functions will sometimes place
417ee3e8c14Smrg# results into a variable named after the function, and often use
418ee3e8c14Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419ee3e8c14Smrg# avoid using those namespaces casually in your sourcing script, things
420ee3e8c14Smrg# should continue to work as you expect. And, of course, you can freely
421ee3e8c14Smrg# overwrite any of the functions or variables defined here before
422ee3e8c14Smrg# calling anything to customize them.
423ee3e8c14Smrg
424ee3e8c14SmrgEXIT_SUCCESS=0
425ee3e8c14SmrgEXIT_FAILURE=1
426ee3e8c14SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427ee3e8c14SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428ee3e8c14Smrg
429ee3e8c14Smrg# Allow overriding, eg assuming that you follow the convention of
430ee3e8c14Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431ee3e8c14Smrg# bash to show function call trace with:
432ee3e8c14Smrg#
433ee3e8c14Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434ee3e8c14Smrgdebug_cmd=${debug_cmd-":"}
435ee3e8c14Smrgexit_cmd=:
436ee3e8c14Smrg
437ee3e8c14Smrg# By convention, finish your script with:
438ee3e8c14Smrg#
439ee3e8c14Smrg#    exit $exit_status
440ee3e8c14Smrg#
441ee3e8c14Smrg# so that you can set exit_status to non-zero if you want to indicate
442ee3e8c14Smrg# something went wrong during execution without actually bailing out at
443ee3e8c14Smrg# the point of failure.
444ee3e8c14Smrgexit_status=$EXIT_SUCCESS
445191cded7Smrg
446ee3e8c14Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447ee3e8c14Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448ee3e8c14Smrg# the _XPG environment variable is not equal to 1 (one), the special
449ee3e8c14Smrg# positional parameter $0, within a function call, is the name of the
450ee3e8c14Smrg# function.
451ee3e8c14Smrgprogpath=$0
452ee3e8c14Smrg
453ee3e8c14Smrg# The name of this program.
454ee3e8c14Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455191cded7Smrg
456ee3e8c14Smrg# Make sure we have an absolute progpath for reexecution:
457b290cf36Smrgcase $progpath in
458b290cf36Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459b290cf36Smrg  *[\\/]*)
460ee3e8c14Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461b290cf36Smrg     progdir=`cd "$progdir" && pwd`
462ee3e8c14Smrg     progpath=$progdir/$progname
463b290cf36Smrg     ;;
464b290cf36Smrg  *)
465ee3e8c14Smrg     _G_IFS=$IFS
466d9dcd5aeSmrg     IFS=${PATH_SEPARATOR-:}
467b290cf36Smrg     for progdir in $PATH; do
468ee3e8c14Smrg       IFS=$_G_IFS
469b290cf36Smrg       test -x "$progdir/$progname" && break
470b290cf36Smrg     done
471ee3e8c14Smrg     IFS=$_G_IFS
472b290cf36Smrg     test -n "$progdir" || progdir=`pwd`
473ee3e8c14Smrg     progpath=$progdir/$progname
474b290cf36Smrg     ;;
475b290cf36Smrgesac
476191cded7Smrg
477b290cf36Smrg
478ee3e8c14Smrg## ----------------- ##
479ee3e8c14Smrg## Standard options. ##
480ee3e8c14Smrg## ----------------- ##
481d9dcd5aeSmrg
482ee3e8c14Smrg# The following options affect the operation of the functions defined
483ee3e8c14Smrg# below, and should be set appropriately depending on run-time para-
484ee3e8c14Smrg# meters passed on the command line.
485b290cf36Smrg
486b290cf36Smrgopt_dry_run=false
487b290cf36Smrgopt_quiet=false
488b290cf36Smrgopt_verbose=false
489b290cf36Smrg
490ee3e8c14Smrg# Categories 'all' and 'none' are always available.  Append any others
491ee3e8c14Smrg# you will pass as the first argument to func_warning from your own
492ee3e8c14Smrg# code.
493ee3e8c14Smrgwarning_categories=
494191cded7Smrg
495ee3e8c14Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496ee3e8c14Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497ee3e8c14Smrg# treat the next displayed warning as a fatal error.
498ee3e8c14Smrgwarning_func=func_warn_and_continue
499191cded7Smrg
500ee3e8c14Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501ee3e8c14Smrg# warnings, or a space delimited list of some subset of
502ee3e8c14Smrg# 'warning_categories' to display only the listed warnings.
503ee3e8c14Smrgopt_warning_types=all
504191cded7Smrg
505ba064abeSmrg
506ee3e8c14Smrg## -------------------- ##
507ee3e8c14Smrg## Resource management. ##
508ee3e8c14Smrg## -------------------- ##
509191cded7Smrg
510ee3e8c14Smrg# This section contains definitions for functions that each ensure a
511ee3e8c14Smrg# particular resource (a file, or a non-empty configuration variable for
512ee3e8c14Smrg# example) is available, and if appropriate to extract default values
513ee3e8c14Smrg# from pertinent package files. Call them using their associated
514ee3e8c14Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515ee3e8c14Smrg#
516ee3e8c14Smrg# It's entirely deliberate that calling these functions can set
517ee3e8c14Smrg# variables that don't obey the namespace limitations obeyed by the rest
518ee3e8c14Smrg# of this file, in order that that they be as useful as possible to
519ee3e8c14Smrg# callers.
520191cded7Smrg
521191cded7Smrg
522ee3e8c14Smrg# require_term_colors
523ee3e8c14Smrg# -------------------
524ee3e8c14Smrg# Allow display of bold text on terminals that support it.
525ee3e8c14Smrgrequire_term_colors=func_require_term_colors
526ee3e8c14Smrgfunc_require_term_colors ()
527b290cf36Smrg{
528ee3e8c14Smrg    $debug_cmd
529ee3e8c14Smrg
530ee3e8c14Smrg    test -t 1 && {
531ee3e8c14Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532ee3e8c14Smrg      # precedence, because most terminfo databases neglect to describe
533ee3e8c14Smrg      # whether color sequences are supported.
534ee3e8c14Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535ee3e8c14Smrg
536ee3e8c14Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537ee3e8c14Smrg        # Standard ANSI escape sequences
538ee3e8c14Smrg        tc_reset='[0m'
539ee3e8c14Smrg        tc_bold='[1m';   tc_standout='[7m'
540ee3e8c14Smrg        tc_red='[31m';   tc_green='[32m'
541ee3e8c14Smrg        tc_blue='[34m';  tc_cyan='[36m'
542ee3e8c14Smrg      else
543ee3e8c14Smrg        # Otherwise trust the terminfo database after all.
544ee3e8c14Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545ee3e8c14Smrg          tc_reset=`tput sgr0`
546ee3e8c14Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547ee3e8c14Smrg          tc_standout=$tc_bold
548ee3e8c14Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549ee3e8c14Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550ee3e8c14Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551ee3e8c14Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552ee3e8c14Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553ee3e8c14Smrg        }
554ee3e8c14Smrg      fi
555ee3e8c14Smrg    }
556191cded7Smrg
557ee3e8c14Smrg    require_term_colors=:
558b290cf36Smrg}
559191cded7Smrg
560191cded7Smrg
561ee3e8c14Smrg## ----------------- ##
562ee3e8c14Smrg## Function library. ##
563ee3e8c14Smrg## ----------------- ##
564b290cf36Smrg
565ee3e8c14Smrg# This section contains a variety of useful functions to call in your
566ee3e8c14Smrg# scripts. Take note of the portable wrappers for features provided by
567ee3e8c14Smrg# some modern shells, which will fall back to slower equivalents on
568ee3e8c14Smrg# less featureful shells.
569b290cf36Smrg
570ee3e8c14Smrg
571ee3e8c14Smrg# func_append VAR VALUE
572ee3e8c14Smrg# ---------------------
573ee3e8c14Smrg# Append VALUE onto the existing contents of VAR.
574ee3e8c14Smrg
575ee3e8c14Smrg  # We should try to minimise forks, especially on Windows where they are
576ee3e8c14Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577ee3e8c14Smrg  # being used:
578ee3e8c14Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579ee3e8c14Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580ee3e8c14Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581ee3e8c14Smrg    # The += operator was introduced in bash 3.1
582ee3e8c14Smrg    case $BASH_VERSION in
583ee3e8c14Smrg      [12].* | 3.0 | 3.0*) ;;
584ee3e8c14Smrg      *)
585ee3e8c14Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586ee3e8c14Smrg        ;;
587ee3e8c14Smrg    esac
588ee3e8c14Smrg  fi
589ee3e8c14Smrg
590ee3e8c14Smrg  # _G_HAVE_PLUSEQ_OP
591ee3e8c14Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
5928f9fac4aSmrg  # usable or anything else if it does not work.
593ee3e8c14Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594ee3e8c14Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595ee3e8c14Smrg    && _G_HAVE_PLUSEQ_OP=yes
596ee3e8c14Smrg
597ee3e8c14Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598ee3e8c14Smrgthen
599ee3e8c14Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600ee3e8c14Smrg  eval 'func_append ()
601ee3e8c14Smrg  {
602ee3e8c14Smrg    $debug_cmd
603ee3e8c14Smrg
604ee3e8c14Smrg    eval "$1+=\$2"
605ee3e8c14Smrg  }'
606ee3e8c14Smrgelse
607ee3e8c14Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608ee3e8c14Smrg  func_append ()
609ee3e8c14Smrg  {
610ee3e8c14Smrg    $debug_cmd
611ee3e8c14Smrg
612ee3e8c14Smrg    eval "$1=\$$1\$2"
613ee3e8c14Smrg  }
614ee3e8c14Smrgfi
615ee3e8c14Smrg
616ee3e8c14Smrg
617ee3e8c14Smrg# func_append_quoted VAR VALUE
618ee3e8c14Smrg# ----------------------------
619ee3e8c14Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620ee3e8c14Smrg# by a space.
621ee3e8c14Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622ee3e8c14Smrg  eval 'func_append_quoted ()
623ee3e8c14Smrg  {
624ee3e8c14Smrg    $debug_cmd
625ee3e8c14Smrg
626ee3e8c14Smrg    func_quote_arg pretty "$2"
627ee3e8c14Smrg    eval "$1+=\\ \$func_quote_arg_result"
628ee3e8c14Smrg  }'
629ee3e8c14Smrgelse
630ee3e8c14Smrg  func_append_quoted ()
631ee3e8c14Smrg  {
632ee3e8c14Smrg    $debug_cmd
633ee3e8c14Smrg
634ee3e8c14Smrg    func_quote_arg pretty "$2"
635ee3e8c14Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636ee3e8c14Smrg  }
637ee3e8c14Smrgfi
638ee3e8c14Smrg
639ee3e8c14Smrg
640ee3e8c14Smrg# func_append_uniq VAR VALUE
641ee3e8c14Smrg# --------------------------
642ee3e8c14Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643ee3e8c14Smrg# entries are delimited by the first character of VALUE.  For example:
644ee3e8c14Smrg#
645ee3e8c14Smrg#   func_append_uniq options " --another-option option-argument"
646ee3e8c14Smrg#
647ee3e8c14Smrg# will only append to $options if " --another-option option-argument "
648ee3e8c14Smrg# is not already present somewhere in $options already (note spaces at
649ee3e8c14Smrg# each end implied by leading space in second argument).
650ee3e8c14Smrgfunc_append_uniq ()
651ee3e8c14Smrg{
652ee3e8c14Smrg    $debug_cmd
653ee3e8c14Smrg
654ee3e8c14Smrg    eval _G_current_value='`$ECHO $'$1'`'
655ee3e8c14Smrg    _G_delim=`expr "$2" : '\(.\)'`
656ee3e8c14Smrg
657ee3e8c14Smrg    case $_G_delim$_G_current_value$_G_delim in
658ee3e8c14Smrg      *"$2$_G_delim"*) ;;
659ee3e8c14Smrg      *) func_append "$@" ;;
660ee3e8c14Smrg    esac
661ee3e8c14Smrg}
662ee3e8c14Smrg
663ee3e8c14Smrg
664ee3e8c14Smrg# func_arith TERM...
665ee3e8c14Smrg# ------------------
666ee3e8c14Smrg# Set func_arith_result to the result of evaluating TERMs.
667ee3e8c14Smrg  test -z "$_G_HAVE_ARITH_OP" \
668ee3e8c14Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669ee3e8c14Smrg    && _G_HAVE_ARITH_OP=yes
670ee3e8c14Smrg
671ee3e8c14Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672ee3e8c14Smrg  eval 'func_arith ()
673ee3e8c14Smrg  {
674ee3e8c14Smrg    $debug_cmd
675ee3e8c14Smrg
676ee3e8c14Smrg    func_arith_result=$(( $* ))
677ee3e8c14Smrg  }'
678ee3e8c14Smrgelse
679ee3e8c14Smrg  func_arith ()
680ee3e8c14Smrg  {
681ee3e8c14Smrg    $debug_cmd
682ee3e8c14Smrg
683ee3e8c14Smrg    func_arith_result=`expr "$@"`
684ee3e8c14Smrg  }
685ee3e8c14Smrgfi
686ee3e8c14Smrg
687ee3e8c14Smrg
688ee3e8c14Smrg# func_basename FILE
689ee3e8c14Smrg# ------------------
690ee3e8c14Smrg# Set func_basename_result to FILE with everything up to and including
691ee3e8c14Smrg# the last / stripped.
692ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693ee3e8c14Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694ee3e8c14Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695ee3e8c14Smrg  # on unsupported syntax...
696ee3e8c14Smrg  _b='func_basename_result=${1##*/}'
697ee3e8c14Smrg  _d='case $1 in
698ee3e8c14Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699ee3e8c14Smrg        *  ) func_dirname_result=$3        ;;
700ee3e8c14Smrg      esac'
701ee3e8c14Smrg
702ee3e8c14Smrgelse
703ee3e8c14Smrg  # ...otherwise fall back to using sed.
704ee3e8c14Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705ee3e8c14Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706ee3e8c14Smrg      if test "X$func_dirname_result" = "X$1"; then
707ee3e8c14Smrg        func_dirname_result=$3
708ee3e8c14Smrg      else
709ee3e8c14Smrg        func_append func_dirname_result "$2"
710ee3e8c14Smrg      fi'
711ee3e8c14Smrgfi
712ee3e8c14Smrg
713ee3e8c14Smrgeval 'func_basename ()
714b290cf36Smrg{
715ee3e8c14Smrg    $debug_cmd
716ee3e8c14Smrg
717ee3e8c14Smrg    '"$_b"'
718ee3e8c14Smrg}'
719b290cf36Smrg
720b290cf36Smrg
721ee3e8c14Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722ee3e8c14Smrg# -------------------------------------------
723ee3e8c14Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724ee3e8c14Smrg# otherwise set result to NONDIR_REPLACEMENT.
725ee3e8c14Smrgeval 'func_dirname ()
726ee3e8c14Smrg{
727ee3e8c14Smrg    $debug_cmd
728ee3e8c14Smrg
729ee3e8c14Smrg    '"$_d"'
730ee3e8c14Smrg}'
731ee3e8c14Smrg
732ee3e8c14Smrg
733ee3e8c14Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734ee3e8c14Smrg# --------------------------------------------------------
735ee3e8c14Smrg# Perform func_basename and func_dirname in a single function
736ee3e8c14Smrg# call:
737ee3e8c14Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738ee3e8c14Smrg#             add APPEND to the result, otherwise set result
739ee3e8c14Smrg#             to NONDIR_REPLACEMENT.
740ee3e8c14Smrg#             value returned in "$func_dirname_result"
741ee3e8c14Smrg#   basename: Compute filename of FILE.
7428f9fac4aSmrg#             value returned in "$func_basename_result"
743ee3e8c14Smrg# For efficiency, we do not delegate to the functions above but instead
744ee3e8c14Smrg# duplicate the functionality here.
745ee3e8c14Smrgeval 'func_dirname_and_basename ()
746ee3e8c14Smrg{
747ee3e8c14Smrg    $debug_cmd
748ee3e8c14Smrg
749ee3e8c14Smrg    '"$_b"'
750ee3e8c14Smrg    '"$_d"'
751ee3e8c14Smrg}'
752ee3e8c14Smrg
753ee3e8c14Smrg
754ee3e8c14Smrg# func_echo ARG...
755ee3e8c14Smrg# ----------------
756ee3e8c14Smrg# Echo program name prefixed message.
757ee3e8c14Smrgfunc_echo ()
758ee3e8c14Smrg{
759ee3e8c14Smrg    $debug_cmd
760ee3e8c14Smrg
761ee3e8c14Smrg    _G_message=$*
762ee3e8c14Smrg
763ee3e8c14Smrg    func_echo_IFS=$IFS
764ee3e8c14Smrg    IFS=$nl
765ee3e8c14Smrg    for _G_line in $_G_message; do
766ee3e8c14Smrg      IFS=$func_echo_IFS
767ee3e8c14Smrg      $ECHO "$progname: $_G_line"
768ee3e8c14Smrg    done
769ee3e8c14Smrg    IFS=$func_echo_IFS
770ee3e8c14Smrg}
771ee3e8c14Smrg
772ee3e8c14Smrg
773ee3e8c14Smrg# func_echo_all ARG...
774ee3e8c14Smrg# --------------------
775ee3e8c14Smrg# Invoke $ECHO with all args, space-separated.
776ee3e8c14Smrgfunc_echo_all ()
777ee3e8c14Smrg{
778ee3e8c14Smrg    $ECHO "$*"
779ee3e8c14Smrg}
780ee3e8c14Smrg
781ee3e8c14Smrg
782ee3e8c14Smrg# func_echo_infix_1 INFIX ARG...
783ee3e8c14Smrg# ------------------------------
784ee3e8c14Smrg# Echo program name, followed by INFIX on the first line, with any
785ee3e8c14Smrg# additional lines not showing INFIX.
786ee3e8c14Smrgfunc_echo_infix_1 ()
787ee3e8c14Smrg{
788ee3e8c14Smrg    $debug_cmd
789ee3e8c14Smrg
790ee3e8c14Smrg    $require_term_colors
791ee3e8c14Smrg
792ee3e8c14Smrg    _G_infix=$1; shift
793ee3e8c14Smrg    _G_indent=$_G_infix
794ee3e8c14Smrg    _G_prefix="$progname: $_G_infix: "
795ee3e8c14Smrg    _G_message=$*
796ee3e8c14Smrg
797ee3e8c14Smrg    # Strip color escape sequences before counting printable length
798ee3e8c14Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799ee3e8c14Smrg    do
800ee3e8c14Smrg      test -n "$_G_tc" && {
801ee3e8c14Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802ee3e8c14Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803ee3e8c14Smrg      }
804ee3e8c14Smrg    done
805ee3e8c14Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806ee3e8c14Smrg
807ee3e8c14Smrg    func_echo_infix_1_IFS=$IFS
808ee3e8c14Smrg    IFS=$nl
809ee3e8c14Smrg    for _G_line in $_G_message; do
810ee3e8c14Smrg      IFS=$func_echo_infix_1_IFS
811ee3e8c14Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812ee3e8c14Smrg      _G_prefix=$_G_indent
813ee3e8c14Smrg    done
814ee3e8c14Smrg    IFS=$func_echo_infix_1_IFS
815ee3e8c14Smrg}
816ee3e8c14Smrg
817ee3e8c14Smrg
818ee3e8c14Smrg# func_error ARG...
819ee3e8c14Smrg# -----------------
820ee3e8c14Smrg# Echo program name prefixed message to standard error.
821ee3e8c14Smrgfunc_error ()
822ee3e8c14Smrg{
823ee3e8c14Smrg    $debug_cmd
824ee3e8c14Smrg
825ee3e8c14Smrg    $require_term_colors
826ee3e8c14Smrg
827ee3e8c14Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828ee3e8c14Smrg}
829ee3e8c14Smrg
830ee3e8c14Smrg
831ee3e8c14Smrg# func_fatal_error ARG...
832ee3e8c14Smrg# -----------------------
833ee3e8c14Smrg# Echo program name prefixed message to standard error, and exit.
834ee3e8c14Smrgfunc_fatal_error ()
835ee3e8c14Smrg{
836ee3e8c14Smrg    $debug_cmd
837ee3e8c14Smrg
838ee3e8c14Smrg    func_error "$*"
839ee3e8c14Smrg    exit $EXIT_FAILURE
840ee3e8c14Smrg}
841ee3e8c14Smrg
842ee3e8c14Smrg
843ee3e8c14Smrg# func_grep EXPRESSION FILENAME
844ee3e8c14Smrg# -----------------------------
845ee3e8c14Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846ee3e8c14Smrgfunc_grep ()
847ee3e8c14Smrg{
848ee3e8c14Smrg    $debug_cmd
849ee3e8c14Smrg
850ee3e8c14Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851ee3e8c14Smrg}
852ee3e8c14Smrg
853ee3e8c14Smrg
854ee3e8c14Smrg# func_len STRING
855ee3e8c14Smrg# ---------------
856ee3e8c14Smrg# Set func_len_result to the length of STRING. STRING may not
857ee3e8c14Smrg# start with a hyphen.
858ee3e8c14Smrg  test -z "$_G_HAVE_XSI_OPS" \
859ee3e8c14Smrg    && (eval 'x=a/b/c;
860ee3e8c14Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861ee3e8c14Smrg    && _G_HAVE_XSI_OPS=yes
862ee3e8c14Smrg
863ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864ee3e8c14Smrg  eval 'func_len ()
865ee3e8c14Smrg  {
866ee3e8c14Smrg    $debug_cmd
867ee3e8c14Smrg
868ee3e8c14Smrg    func_len_result=${#1}
869ee3e8c14Smrg  }'
870ee3e8c14Smrgelse
871ee3e8c14Smrg  func_len ()
872ee3e8c14Smrg  {
873ee3e8c14Smrg    $debug_cmd
874ee3e8c14Smrg
875ee3e8c14Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876ee3e8c14Smrg  }
877ee3e8c14Smrgfi
878ee3e8c14Smrg
879ee3e8c14Smrg
880ee3e8c14Smrg# func_mkdir_p DIRECTORY-PATH
881ee3e8c14Smrg# ---------------------------
882ee3e8c14Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883ee3e8c14Smrgfunc_mkdir_p ()
884ee3e8c14Smrg{
885ee3e8c14Smrg    $debug_cmd
886ee3e8c14Smrg
887ee3e8c14Smrg    _G_directory_path=$1
888ee3e8c14Smrg    _G_dir_list=
889ee3e8c14Smrg
890ee3e8c14Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891ee3e8c14Smrg
892ee3e8c14Smrg      # Protect directory names starting with '-'
893ee3e8c14Smrg      case $_G_directory_path in
894ee3e8c14Smrg        -*) _G_directory_path=./$_G_directory_path ;;
895b290cf36Smrg      esac
896b290cf36Smrg
897b290cf36Smrg      # While some portion of DIR does not yet exist...
898ee3e8c14Smrg      while test ! -d "$_G_directory_path"; do
899b290cf36Smrg        # ...make a list in topmost first order.  Use a colon delimited
9008f9fac4aSmrg	# list in case some portion of path contains whitespace.
901ee3e8c14Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902b290cf36Smrg
903b290cf36Smrg        # If the last portion added has no slash in it, the list is done
904ee3e8c14Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
905b290cf36Smrg
906b290cf36Smrg        # ...otherwise throw away the child directory and loop
907ee3e8c14Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908b290cf36Smrg      done
909ee3e8c14Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910b290cf36Smrg
911ee3e8c14Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912ee3e8c14Smrg      for _G_dir in $_G_dir_list; do
913ee3e8c14Smrg	IFS=$func_mkdir_p_IFS
914ee3e8c14Smrg        # mkdir can fail with a 'File exist' error if two processes
915b290cf36Smrg        # try to create one of the directories concurrently.  Don't
916b290cf36Smrg        # stop in that case!
917ee3e8c14Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
918b290cf36Smrg      done
919ee3e8c14Smrg      IFS=$func_mkdir_p_IFS
920b290cf36Smrg
921b290cf36Smrg      # Bail out if we (or some other process) failed to create a directory.
922ee3e8c14Smrg      test -d "$_G_directory_path" || \
923ee3e8c14Smrg        func_fatal_error "Failed to create '$1'"
924b290cf36Smrg    fi
925b290cf36Smrg}
926191cded7Smrg
927191cded7Smrg
928ee3e8c14Smrg# func_mktempdir [BASENAME]
929ee3e8c14Smrg# -------------------------
930191cded7Smrg# Make a temporary directory that won't clash with other running
931191cded7Smrg# libtool processes, and avoids race conditions if possible.  If
932ee3e8c14Smrg# given, BASENAME is the basename for that directory.
933191cded7Smrgfunc_mktempdir ()
934191cded7Smrg{
935ee3e8c14Smrg    $debug_cmd
936191cded7Smrg
937ee3e8c14Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938ee3e8c14Smrg
939ee3e8c14Smrg    if test : = "$opt_dry_run"; then
940191cded7Smrg      # Return a directory name, but don't create it in dry-run mode
941ee3e8c14Smrg      _G_tmpdir=$_G_template-$$
942191cded7Smrg    else
943191cded7Smrg
944191cded7Smrg      # If mktemp works, use that first and foremost
945ee3e8c14Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946191cded7Smrg
947ee3e8c14Smrg      if test ! -d "$_G_tmpdir"; then
948b290cf36Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949ee3e8c14Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950191cded7Smrg
951ee3e8c14Smrg        func_mktempdir_umask=`umask`
952b290cf36Smrg        umask 0077
953ee3e8c14Smrg        $MKDIR "$_G_tmpdir"
954ee3e8c14Smrg        umask $func_mktempdir_umask
955191cded7Smrg      fi
956191cded7Smrg
957191cded7Smrg      # If we're not in dry-run mode, bomb out on failure
958ee3e8c14Smrg      test -d "$_G_tmpdir" || \
959ee3e8c14Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960191cded7Smrg    fi
961191cded7Smrg
962ee3e8c14Smrg    $ECHO "$_G_tmpdir"
963191cded7Smrg}
964191cded7Smrg
965191cded7Smrg
966ee3e8c14Smrg# func_normal_abspath PATH
967ee3e8c14Smrg# ------------------------
968ee3e8c14Smrg# Remove doubled-up and trailing slashes, "." path components,
969ee3e8c14Smrg# and cancel out any ".." path components in PATH after making
970ee3e8c14Smrg# it an absolute path.
971ee3e8c14Smrgfunc_normal_abspath ()
972191cded7Smrg{
973ee3e8c14Smrg    $debug_cmd
974ee3e8c14Smrg
975ee3e8c14Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976ee3e8c14Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977ee3e8c14Smrg    _G_pathcdr='s|^/[^/]*||'
978ee3e8c14Smrg    _G_removedotparts=':dotsl
979ee3e8c14Smrg		s|/\./|/|g
980ee3e8c14Smrg		t dotsl
981ee3e8c14Smrg		s|/\.$|/|'
982ee3e8c14Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983ee3e8c14Smrg    _G_finalslash='s|/*$|/|'
984ee3e8c14Smrg
985ee3e8c14Smrg    # Start from root dir and reassemble the path.
986ee3e8c14Smrg    func_normal_abspath_result=
987ee3e8c14Smrg    func_normal_abspath_tpath=$1
988ee3e8c14Smrg    func_normal_abspath_altnamespace=
989ee3e8c14Smrg    case $func_normal_abspath_tpath in
990ee3e8c14Smrg      "")
991ee3e8c14Smrg        # Empty path, that just means $cwd.
992ee3e8c14Smrg        func_stripname '' '/' "`pwd`"
993ee3e8c14Smrg        func_normal_abspath_result=$func_stripname_result
994ee3e8c14Smrg        return
995ee3e8c14Smrg        ;;
996ee3e8c14Smrg      # The next three entries are used to spot a run of precisely
997ee3e8c14Smrg      # two leading slashes without using negated character classes;
998ee3e8c14Smrg      # we take advantage of case's first-match behaviour.
999ee3e8c14Smrg      ///*)
1000ee3e8c14Smrg        # Unusual form of absolute path, do nothing.
1001ee3e8c14Smrg        ;;
1002ee3e8c14Smrg      //*)
1003ee3e8c14Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004ee3e8c14Smrg        # and for example Cygwin uses it to access remote file shares
1005ee3e8c14Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006ee3e8c14Smrg        func_normal_abspath_altnamespace=/
1007ee3e8c14Smrg        ;;
1008ee3e8c14Smrg      /*)
1009ee3e8c14Smrg        # Absolute path, do nothing.
1010ee3e8c14Smrg        ;;
1011b290cf36Smrg      *)
1012ee3e8c14Smrg        # Relative path, prepend $cwd.
1013ee3e8c14Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014ee3e8c14Smrg        ;;
1015b290cf36Smrg    esac
1016b290cf36Smrg
1017ee3e8c14Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018ee3e8c14Smrg    # the path to end with a slash for ease of parsing, so make sure
1019ee3e8c14Smrg    # there is one (and only one) here.
1020ee3e8c14Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021ee3e8c14Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022ee3e8c14Smrg    while :; do
1023ee3e8c14Smrg      # Processed it all yet?
1024ee3e8c14Smrg      if test / = "$func_normal_abspath_tpath"; then
1025ee3e8c14Smrg        # If we ascended to the root using ".." the result may be empty now.
1026ee3e8c14Smrg        if test -z "$func_normal_abspath_result"; then
1027ee3e8c14Smrg          func_normal_abspath_result=/
1028ee3e8c14Smrg        fi
1029ee3e8c14Smrg        break
1030ee3e8c14Smrg      fi
1031ee3e8c14Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032ee3e8c14Smrg          -e "$_G_pathcar"`
1033ee3e8c14Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034ee3e8c14Smrg          -e "$_G_pathcdr"`
1035ee3e8c14Smrg      # Figure out what to do with it
1036ee3e8c14Smrg      case $func_normal_abspath_tcomponent in
1037ee3e8c14Smrg        "")
1038ee3e8c14Smrg          # Trailing empty path component, ignore it.
1039ee3e8c14Smrg          ;;
1040ee3e8c14Smrg        ..)
1041ee3e8c14Smrg          # Parent dir; strip last assembled component from result.
1042ee3e8c14Smrg          func_dirname "$func_normal_abspath_result"
1043ee3e8c14Smrg          func_normal_abspath_result=$func_dirname_result
1044ee3e8c14Smrg          ;;
1045ee3e8c14Smrg        *)
1046ee3e8c14Smrg          # Actual path component, append it.
1047ee3e8c14Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048ee3e8c14Smrg          ;;
1049ee3e8c14Smrg      esac
1050ee3e8c14Smrg    done
1051ee3e8c14Smrg    # Restore leading double-slash if one was found on entry.
1052ee3e8c14Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053ee3e8c14Smrg}
1054ee3e8c14Smrg
1055ee3e8c14Smrg
1056ee3e8c14Smrg# func_notquiet ARG...
1057ee3e8c14Smrg# --------------------
1058ee3e8c14Smrg# Echo program name prefixed message only when not in quiet mode.
1059ee3e8c14Smrgfunc_notquiet ()
1060ee3e8c14Smrg{
1061ee3e8c14Smrg    $debug_cmd
1062ee3e8c14Smrg
1063ee3e8c14Smrg    $opt_quiet || func_echo ${1+"$@"}
1064ee3e8c14Smrg
1065ee3e8c14Smrg    # A bug in bash halts the script if the last line of a function
1066ee3e8c14Smrg    # fails when set -e is in force, so we need another command to
1067ee3e8c14Smrg    # work around that:
1068ee3e8c14Smrg    :
1069ee3e8c14Smrg}
1070ee3e8c14Smrg
1071ee3e8c14Smrg
1072ee3e8c14Smrg# func_relative_path SRCDIR DSTDIR
1073ee3e8c14Smrg# --------------------------------
1074ee3e8c14Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075ee3e8c14Smrgfunc_relative_path ()
1076ee3e8c14Smrg{
1077ee3e8c14Smrg    $debug_cmd
1078ee3e8c14Smrg
1079ee3e8c14Smrg    func_relative_path_result=
1080ee3e8c14Smrg    func_normal_abspath "$1"
1081ee3e8c14Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082ee3e8c14Smrg    func_normal_abspath "$2"
1083ee3e8c14Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084ee3e8c14Smrg
1085ee3e8c14Smrg    # Ascend the tree starting from libdir
1086ee3e8c14Smrg    while :; do
1087ee3e8c14Smrg      # check if we have found a prefix of bindir
1088ee3e8c14Smrg      case $func_relative_path_tbindir in
1089ee3e8c14Smrg        $func_relative_path_tlibdir)
1090ee3e8c14Smrg          # found an exact match
1091ee3e8c14Smrg          func_relative_path_tcancelled=
1092ee3e8c14Smrg          break
1093ee3e8c14Smrg          ;;
1094ee3e8c14Smrg        $func_relative_path_tlibdir*)
1095ee3e8c14Smrg          # found a matching prefix
1096ee3e8c14Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097ee3e8c14Smrg          func_relative_path_tcancelled=$func_stripname_result
1098ee3e8c14Smrg          if test -z "$func_relative_path_result"; then
1099ee3e8c14Smrg            func_relative_path_result=.
1100ee3e8c14Smrg          fi
1101ee3e8c14Smrg          break
1102ee3e8c14Smrg          ;;
1103ee3e8c14Smrg        *)
1104ee3e8c14Smrg          func_dirname $func_relative_path_tlibdir
1105ee3e8c14Smrg          func_relative_path_tlibdir=$func_dirname_result
1106ee3e8c14Smrg          if test -z "$func_relative_path_tlibdir"; then
1107ee3e8c14Smrg            # Have to descend all the way to the root!
1108ee3e8c14Smrg            func_relative_path_result=../$func_relative_path_result
1109ee3e8c14Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110ee3e8c14Smrg            break
1111ee3e8c14Smrg          fi
1112ee3e8c14Smrg          func_relative_path_result=../$func_relative_path_result
1113ee3e8c14Smrg          ;;
1114ee3e8c14Smrg      esac
1115ee3e8c14Smrg    done
1116ee3e8c14Smrg
1117ee3e8c14Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118ee3e8c14Smrg    func_stripname '' '/' "$func_relative_path_result"
1119ee3e8c14Smrg    func_relative_path_result=$func_stripname_result
1120ee3e8c14Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121ee3e8c14Smrg    if test -n "$func_stripname_result"; then
1122ee3e8c14Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123ee3e8c14Smrg    fi
1124ee3e8c14Smrg
1125ee3e8c14Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126ee3e8c14Smrg    if test -n "$func_relative_path_result"; then
1127ee3e8c14Smrg      func_stripname './' '' "$func_relative_path_result"
1128ee3e8c14Smrg      func_relative_path_result=$func_stripname_result
1129ee3e8c14Smrg    fi
1130ee3e8c14Smrg
1131ee3e8c14Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132ee3e8c14Smrg
1133ee3e8c14Smrg    :
1134ee3e8c14Smrg}
1135ee3e8c14Smrg
1136ee3e8c14Smrg
1137ee3e8c14Smrg# func_quote_portable EVAL ARG
1138ee3e8c14Smrg# ----------------------------
1139ee3e8c14Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140ee3e8c14Smrg# keep attention to performance here so we as much as possible try to avoid
1141ee3e8c14Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142ee3e8c14Smrgfunc_quote_portable ()
1143ee3e8c14Smrg{
1144ee3e8c14Smrg    $debug_cmd
1145ee3e8c14Smrg
1146ee3e8c14Smrg    $require_check_ifs_backslash
1147ee3e8c14Smrg
1148ee3e8c14Smrg    func_quote_portable_result=$2
1149ee3e8c14Smrg
1150ee3e8c14Smrg    # one-time-loop (easy break)
1151ee3e8c14Smrg    while true
1152ee3e8c14Smrg    do
1153ee3e8c14Smrg      if $1; then
1154ee3e8c14Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155ee3e8c14Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156ee3e8c14Smrg        break
1157ee3e8c14Smrg      fi
1158ee3e8c14Smrg
1159ee3e8c14Smrg      # Quote for eval.
1160ee3e8c14Smrg      case $func_quote_portable_result in
1161ee3e8c14Smrg        *[\\\`\"\$]*)
1162ee3e8c14Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163ee3e8c14Smrg          # contains the shell wildcard characters.
1164ee3e8c14Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165ee3e8c14Smrg            :*|*[\[\*\?]*)
1166ee3e8c14Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167ee3e8c14Smrg                  | $SED "$sed_quote_subst"`
1168ee3e8c14Smrg              break
1169ee3e8c14Smrg              ;;
1170ee3e8c14Smrg          esac
1171ee3e8c14Smrg
1172ee3e8c14Smrg          func_quote_portable_old_IFS=$IFS
1173ee3e8c14Smrg          for _G_char in '\' '`' '"' '$'
1174ee3e8c14Smrg          do
1175ee3e8c14Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176ee3e8c14Smrg            set start "" ""
1177ee3e8c14Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178ee3e8c14Smrg            IFS=$_G_char
1179ee3e8c14Smrg            for _G_part in $func_quote_portable_result
1180ee3e8c14Smrg            do
1181ee3e8c14Smrg              case $1 in
1182ee3e8c14Smrg              quote)
1183ee3e8c14Smrg                func_append func_quote_portable_result "$3$2"
1184ee3e8c14Smrg                set quote "$_G_part" "\\$_G_char"
1185ee3e8c14Smrg                ;;
1186ee3e8c14Smrg              start)
1187ee3e8c14Smrg                set first "" ""
1188ee3e8c14Smrg                func_quote_portable_result=
1189ee3e8c14Smrg                ;;
1190ee3e8c14Smrg              first)
1191ee3e8c14Smrg                set quote "$_G_part" ""
1192ee3e8c14Smrg                ;;
1193ee3e8c14Smrg              esac
1194ee3e8c14Smrg            done
1195ee3e8c14Smrg          done
1196ee3e8c14Smrg          IFS=$func_quote_portable_old_IFS
1197ee3e8c14Smrg          ;;
1198ee3e8c14Smrg        *) ;;
1199ee3e8c14Smrg      esac
1200ee3e8c14Smrg      break
1201ee3e8c14Smrg    done
1202ee3e8c14Smrg
1203ee3e8c14Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204ee3e8c14Smrg    case $func_quote_portable_result in
1205ee3e8c14Smrg      # double-quote args containing shell metacharacters to delay
1206ee3e8c14Smrg      # word splitting, command substitution and variable expansion
1207ee3e8c14Smrg      # for a subsequent eval.
1208ee3e8c14Smrg      # many bourne shells cannot handle close brackets correctly
1209b290cf36Smrg      # in scan sets, so we specify it separately.
1210b290cf36Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211ee3e8c14Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212ee3e8c14Smrg        ;;
1213ee3e8c14Smrg    esac
1214ee3e8c14Smrg}
1215ee3e8c14Smrg
1216ee3e8c14Smrg
1217ee3e8c14Smrg# func_quotefast_eval ARG
1218ee3e8c14Smrg# -----------------------
1219ee3e8c14Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220ee3e8c14Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221ee3e8c14Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222ee3e8c14Smrg  printf -v _GL_test_printf_tilde %q '~'
1223ee3e8c14Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224ee3e8c14Smrg    func_quotefast_eval ()
1225ee3e8c14Smrg    {
1226ee3e8c14Smrg      printf -v func_quotefast_eval_result %q "$1"
1227ee3e8c14Smrg    }
1228ee3e8c14Smrg  else
1229ee3e8c14Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230ee3e8c14Smrg    func_quotefast_eval ()
1231ee3e8c14Smrg    {
1232ee3e8c14Smrg      case $1 in
1233ee3e8c14Smrg        '~'*)
1234ee3e8c14Smrg          func_quote_portable false "$1"
1235ee3e8c14Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236ee3e8c14Smrg          ;;
1237ee3e8c14Smrg        *)
1238ee3e8c14Smrg          printf -v func_quotefast_eval_result %q "$1"
1239ee3e8c14Smrg          ;;
1240ee3e8c14Smrg      esac
1241ee3e8c14Smrg    }
1242ee3e8c14Smrg  fi
1243ee3e8c14Smrgelse
1244ee3e8c14Smrg  func_quotefast_eval ()
1245ee3e8c14Smrg  {
1246ee3e8c14Smrg    func_quote_portable false "$1"
1247ee3e8c14Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248ee3e8c14Smrg  }
1249ee3e8c14Smrgfi
1250ee3e8c14Smrg
1251ee3e8c14Smrg
1252ee3e8c14Smrg# func_quote_arg MODEs ARG
1253ee3e8c14Smrg# ------------------------
1254ee3e8c14Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255ee3e8c14Smrg# specifiers listed below separated by ',' character.  This function returns two
1256ee3e8c14Smrg# values:
1257ee3e8c14Smrg#   i) func_quote_arg_result
1258ee3e8c14Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259ee3e8c14Smrg#  ii) func_quote_arg_unquoted_result
1260ee3e8c14Smrg#      has all characters that are still active within double
1261ee3e8c14Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262ee3e8c14Smrg#
1263ee3e8c14Smrg# Available modes:
1264ee3e8c14Smrg# ----------------
1265ee3e8c14Smrg# 'eval' (default)
1266ee3e8c14Smrg#       - escape shell special characters
1267ee3e8c14Smrg# 'expand'
1268ee3e8c14Smrg#       - the same as 'eval';  but do not quote variable references
1269ee3e8c14Smrg# 'pretty'
1270ee3e8c14Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271ee3e8c14Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272ee3e8c14Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273ee3e8c14Smrg# 'unquoted'
1274ee3e8c14Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275ee3e8c14Smrg#         wrapping double-quotes.
1276ee3e8c14Smrg#
1277ee3e8c14Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278ee3e8c14Smrg#
1279ee3e8c14Smrg#   string      | *_result              | *_unquoted_result
1280ee3e8c14Smrg#   ------------+-----------------------+-------------------
1281ee3e8c14Smrg#   "           | \"                    | \"
1282ee3e8c14Smrg#   a b         | "a b"                 | a b
1283ee3e8c14Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284ee3e8c14Smrg#   *           | "*"                   | *
1285ee3e8c14Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286ee3e8c14Smrg#
1287ee3e8c14Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288ee3e8c14Smrg#
1289ee3e8c14Smrg#   string        |   *_result          |  *_unquoted_result
1290ee3e8c14Smrg#   --------------+---------------------+--------------------
1291ee3e8c14Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292ee3e8c14Smrgfunc_quote_arg ()
1293ee3e8c14Smrg{
1294ee3e8c14Smrg    _G_quote_expand=false
1295ee3e8c14Smrg    case ,$1, in
1296ee3e8c14Smrg      *,expand,*)
1297ee3e8c14Smrg        _G_quote_expand=:
1298ee3e8c14Smrg        ;;
1299ee3e8c14Smrg    esac
1300ee3e8c14Smrg
1301ee3e8c14Smrg    case ,$1, in
1302ee3e8c14Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303ee3e8c14Smrg        func_quote_portable $_G_quote_expand "$2"
1304ee3e8c14Smrg        func_quote_arg_result=$func_quote_portable_result
1305ee3e8c14Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306b290cf36Smrg        ;;
1307b290cf36Smrg      *)
1308ee3e8c14Smrg        # Faster quote-for-eval for some shells.
1309ee3e8c14Smrg        func_quotefast_eval "$2"
1310ee3e8c14Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311ee3e8c14Smrg        ;;
1312ee3e8c14Smrg    esac
1313ee3e8c14Smrg}
1314ee3e8c14Smrg
1315ee3e8c14Smrg
1316ee3e8c14Smrg# func_quote MODEs ARGs...
1317ee3e8c14Smrg# ------------------------
1318ee3e8c14Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319ee3e8c14Smrg# func_quote_arg's description for more info.
1320ee3e8c14Smrgfunc_quote ()
1321ee3e8c14Smrg{
1322ee3e8c14Smrg    $debug_cmd
1323ee3e8c14Smrg    _G_func_quote_mode=$1 ; shift
1324ee3e8c14Smrg    func_quote_result=
1325ee3e8c14Smrg    while test 0 -lt $#; do
1326ee3e8c14Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327ee3e8c14Smrg      if test -n "$func_quote_result"; then
1328ee3e8c14Smrg        func_append func_quote_result " $func_quote_arg_result"
1329ee3e8c14Smrg      else
1330ee3e8c14Smrg        func_append func_quote_result "$func_quote_arg_result"
1331ee3e8c14Smrg      fi
1332ee3e8c14Smrg      shift
1333ee3e8c14Smrg    done
1334ee3e8c14Smrg}
1335ee3e8c14Smrg
1336ee3e8c14Smrg
1337ee3e8c14Smrg# func_stripname PREFIX SUFFIX NAME
1338ee3e8c14Smrg# ---------------------------------
1339ee3e8c14Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340ee3e8c14Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341ee3e8c14Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342ee3e8c14Smrg# dot (in which case that matches only a dot).
1343ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344ee3e8c14Smrg  eval 'func_stripname ()
1345ee3e8c14Smrg  {
1346ee3e8c14Smrg    $debug_cmd
1347ee3e8c14Smrg
1348ee3e8c14Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349ee3e8c14Smrg    # positional parameters, so assign one to ordinary variable first.
1350ee3e8c14Smrg    func_stripname_result=$3
1351ee3e8c14Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352ee3e8c14Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353ee3e8c14Smrg  }'
1354ee3e8c14Smrgelse
1355ee3e8c14Smrg  func_stripname ()
1356ee3e8c14Smrg  {
1357ee3e8c14Smrg    $debug_cmd
1358ee3e8c14Smrg
1359ee3e8c14Smrg    case $2 in
1360ee3e8c14Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361ee3e8c14Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362ee3e8c14Smrg    esac
1363ee3e8c14Smrg  }
1364ee3e8c14Smrgfi
1365ee3e8c14Smrg
1366ee3e8c14Smrg
1367ee3e8c14Smrg# func_show_eval CMD [FAIL_EXP]
1368ee3e8c14Smrg# -----------------------------
1369ee3e8c14Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370ee3e8c14Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371ee3e8c14Smrg# is given, then evaluate it.
1372ee3e8c14Smrgfunc_show_eval ()
1373ee3e8c14Smrg{
1374ee3e8c14Smrg    $debug_cmd
1375ee3e8c14Smrg
1376ee3e8c14Smrg    _G_cmd=$1
1377ee3e8c14Smrg    _G_fail_exp=${2-':'}
1378ee3e8c14Smrg
1379ee3e8c14Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380ee3e8c14Smrg    eval "func_notquiet $func_quote_arg_result"
1381ee3e8c14Smrg
1382ee3e8c14Smrg    $opt_dry_run || {
1383ee3e8c14Smrg      eval "$_G_cmd"
1384ee3e8c14Smrg      _G_status=$?
1385ee3e8c14Smrg      if test 0 -ne "$_G_status"; then
1386ee3e8c14Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387ee3e8c14Smrg      fi
1388ee3e8c14Smrg    }
1389ee3e8c14Smrg}
1390ee3e8c14Smrg
1391ee3e8c14Smrg
1392ee3e8c14Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393ee3e8c14Smrg# ------------------------------------
1394ee3e8c14Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395ee3e8c14Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396ee3e8c14Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397ee3e8c14Smrgfunc_show_eval_locale ()
1398ee3e8c14Smrg{
1399ee3e8c14Smrg    $debug_cmd
1400ee3e8c14Smrg
1401ee3e8c14Smrg    _G_cmd=$1
1402ee3e8c14Smrg    _G_fail_exp=${2-':'}
1403ee3e8c14Smrg
1404ee3e8c14Smrg    $opt_quiet || {
1405ee3e8c14Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406ee3e8c14Smrg      eval "func_echo $func_quote_arg_result"
1407ee3e8c14Smrg    }
1408ee3e8c14Smrg
1409ee3e8c14Smrg    $opt_dry_run || {
1410ee3e8c14Smrg      eval "$_G_user_locale
1411ee3e8c14Smrg	    $_G_cmd"
1412ee3e8c14Smrg      _G_status=$?
1413ee3e8c14Smrg      eval "$_G_safe_locale"
1414ee3e8c14Smrg      if test 0 -ne "$_G_status"; then
1415ee3e8c14Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416ee3e8c14Smrg      fi
1417ee3e8c14Smrg    }
1418ee3e8c14Smrg}
1419ee3e8c14Smrg
1420ee3e8c14Smrg
1421ee3e8c14Smrg# func_tr_sh
1422ee3e8c14Smrg# ----------
1423ee3e8c14Smrg# Turn $1 into a string suitable for a shell variable name.
1424ee3e8c14Smrg# Result is stored in $func_tr_sh_result.  All characters
1425ee3e8c14Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426ee3e8c14Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427ee3e8c14Smrgfunc_tr_sh ()
1428ee3e8c14Smrg{
1429ee3e8c14Smrg    $debug_cmd
1430ee3e8c14Smrg
1431ee3e8c14Smrg    case $1 in
1432ee3e8c14Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433ee3e8c14Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434ee3e8c14Smrg      ;;
1435ee3e8c14Smrg    * )
1436ee3e8c14Smrg      func_tr_sh_result=$1
1437ee3e8c14Smrg      ;;
1438ee3e8c14Smrg    esac
1439ee3e8c14Smrg}
1440ee3e8c14Smrg
1441ee3e8c14Smrg
1442ee3e8c14Smrg# func_verbose ARG...
1443ee3e8c14Smrg# -------------------
1444ee3e8c14Smrg# Echo program name prefixed message in verbose mode only.
1445ee3e8c14Smrgfunc_verbose ()
1446ee3e8c14Smrg{
1447ee3e8c14Smrg    $debug_cmd
1448ee3e8c14Smrg
1449ee3e8c14Smrg    $opt_verbose && func_echo "$*"
1450ee3e8c14Smrg
1451ee3e8c14Smrg    :
1452ee3e8c14Smrg}
1453ee3e8c14Smrg
1454ee3e8c14Smrg
1455ee3e8c14Smrg# func_warn_and_continue ARG...
1456ee3e8c14Smrg# -----------------------------
1457ee3e8c14Smrg# Echo program name prefixed warning message to standard error.
1458ee3e8c14Smrgfunc_warn_and_continue ()
1459ee3e8c14Smrg{
1460ee3e8c14Smrg    $debug_cmd
1461ee3e8c14Smrg
1462ee3e8c14Smrg    $require_term_colors
1463ee3e8c14Smrg
1464ee3e8c14Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465ee3e8c14Smrg}
1466ee3e8c14Smrg
1467ee3e8c14Smrg
1468ee3e8c14Smrg# func_warning CATEGORY ARG...
1469ee3e8c14Smrg# ----------------------------
1470ee3e8c14Smrg# Echo program name prefixed warning message to standard error. Warning
1471ee3e8c14Smrg# messages can be filtered according to CATEGORY, where this function
1472ee3e8c14Smrg# elides messages where CATEGORY is not listed in the global variable
1473ee3e8c14Smrg# 'opt_warning_types'.
1474ee3e8c14Smrgfunc_warning ()
1475ee3e8c14Smrg{
1476ee3e8c14Smrg    $debug_cmd
1477ee3e8c14Smrg
1478ee3e8c14Smrg    # CATEGORY must be in the warning_categories list!
1479ee3e8c14Smrg    case " $warning_categories " in
1480ee3e8c14Smrg      *" $1 "*) ;;
1481ee3e8c14Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482ee3e8c14Smrg    esac
1483ee3e8c14Smrg
1484ee3e8c14Smrg    _G_category=$1
1485ee3e8c14Smrg    shift
1486ee3e8c14Smrg
1487ee3e8c14Smrg    case " $opt_warning_types " in
1488ee3e8c14Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489ee3e8c14Smrg    esac
1490ee3e8c14Smrg}
1491ee3e8c14Smrg
1492ee3e8c14Smrg
1493ee3e8c14Smrg# func_sort_ver VER1 VER2
1494ee3e8c14Smrg# -----------------------
1495ee3e8c14Smrg# 'sort -V' is not generally available.
1496ee3e8c14Smrg# Note this deviates from the version comparison in automake
1497ee3e8c14Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498ee3e8c14Smrg# but this should suffice as we won't be specifying old
1499ee3e8c14Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500ee3e8c14Smrg# If we did want full compatibility then we should probably
1501ee3e8c14Smrg# use m4_version_compare from autoconf.
1502ee3e8c14Smrgfunc_sort_ver ()
1503ee3e8c14Smrg{
1504ee3e8c14Smrg    $debug_cmd
1505ee3e8c14Smrg
1506ee3e8c14Smrg    printf '%s\n%s\n' "$1" "$2" \
1507ee3e8c14Smrg      | 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
1508ee3e8c14Smrg}
1509ee3e8c14Smrg
1510ee3e8c14Smrg# func_lt_ver PREV CURR
1511ee3e8c14Smrg# ---------------------
1512ee3e8c14Smrg# Return true if PREV and CURR are in the correct order according to
1513ee3e8c14Smrg# func_sort_ver, otherwise false.  Use it like this:
1514ee3e8c14Smrg#
1515ee3e8c14Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516ee3e8c14Smrgfunc_lt_ver ()
1517ee3e8c14Smrg{
1518ee3e8c14Smrg    $debug_cmd
1519ee3e8c14Smrg
1520ee3e8c14Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521ee3e8c14Smrg}
1522ee3e8c14Smrg
1523ee3e8c14Smrg
1524ee3e8c14Smrg# Local variables:
1525ee3e8c14Smrg# mode: shell-script
1526ee3e8c14Smrg# sh-indentation: 2
1527ee3e8c14Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528ee3e8c14Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529ee3e8c14Smrg# time-stamp-time-zone: "UTC"
1530ee3e8c14Smrg# End:
1531ee3e8c14Smrg#! /bin/sh
1532ee3e8c14Smrg
1533ee3e8c14Smrg# A portable, pluggable option parser for Bourne shell.
1534ee3e8c14Smrg# Written by Gary V. Vaughan, 2010
1535ee3e8c14Smrg
1536ee3e8c14Smrg# This is free software.  There is NO warranty; not even for
1537ee3e8c14Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538ee3e8c14Smrg#
15398f9fac4aSmrg# Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors
1540ee3e8c14Smrg#
1541ee3e8c14Smrg# This file is dual licensed under the terms of the MIT license
15428f9fac4aSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
15438f9fac4aSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544ee3e8c14Smrg# these licenses when using or redistributing this software or any of
1545ee3e8c14Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546ee3e8c14Smrg# included in the Bootstrap distribution for the full license texts.
1547ee3e8c14Smrg
1548ee3e8c14Smrg# Please report bugs or propose patches to:
1549ee3e8c14Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550ee3e8c14Smrg
1551ee3e8c14Smrg# Set a version string for this script.
1552ee3e8c14Smrgscriptversion=2019-02-19.15; # UTC
1553ee3e8c14Smrg
1554ee3e8c14Smrg
1555ee3e8c14Smrg## ------ ##
1556ee3e8c14Smrg## Usage. ##
1557ee3e8c14Smrg## ------ ##
1558ee3e8c14Smrg
1559ee3e8c14Smrg# This file is a library for parsing options in your shell scripts along
1560ee3e8c14Smrg# with assorted other useful supporting features that you can make use
1561ee3e8c14Smrg# of too.
1562ee3e8c14Smrg#
1563ee3e8c14Smrg# For the simplest scripts you might need only:
1564ee3e8c14Smrg#
1565ee3e8c14Smrg#   #!/bin/sh
1566ee3e8c14Smrg#   . relative/path/to/funclib.sh
1567ee3e8c14Smrg#   . relative/path/to/options-parser
1568ee3e8c14Smrg#   scriptversion=1.0
1569ee3e8c14Smrg#   func_options ${1+"$@"}
1570ee3e8c14Smrg#   eval set dummy "$func_options_result"; shift
1571ee3e8c14Smrg#   ...rest of your script...
1572ee3e8c14Smrg#
1573ee3e8c14Smrg# In order for the '--version' option to work, you will need to have a
1574ee3e8c14Smrg# suitably formatted comment like the one at the top of this file
1575ee3e8c14Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576ee3e8c14Smrg#
1577ee3e8c14Smrg# For '-h' and '--help' to work, you will also need a one line
1578ee3e8c14Smrg# description of your script's purpose in a comment directly above the
1579ee3e8c14Smrg# '# Written by ' line, like the one at the top of this file.
1580ee3e8c14Smrg#
1581ee3e8c14Smrg# The default options also support '--debug', which will turn on shell
1582ee3e8c14Smrg# execution tracing (see the comment above debug_cmd below for another
1583ee3e8c14Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584ee3e8c14Smrg# to display verbose messages only when your user has specified
1585ee3e8c14Smrg# '--verbose'.
1586ee3e8c14Smrg#
1587ee3e8c14Smrg# After sourcing this file, you can plug in processing for additional
1588ee3e8c14Smrg# options by amending the variables from the 'Configuration' section
1589ee3e8c14Smrg# below, and following the instructions in the 'Option parsing'
1590ee3e8c14Smrg# section further down.
1591ee3e8c14Smrg
1592ee3e8c14Smrg## -------------- ##
1593ee3e8c14Smrg## Configuration. ##
1594ee3e8c14Smrg## -------------- ##
1595ee3e8c14Smrg
1596ee3e8c14Smrg# You should override these variables in your script after sourcing this
1597ee3e8c14Smrg# file so that they reflect the customisations you have added to the
1598ee3e8c14Smrg# option parser.
1599ee3e8c14Smrg
1600ee3e8c14Smrg# The usage line for option parsing errors and the start of '-h' and
1601ee3e8c14Smrg# '--help' output messages. You can embed shell variables for delayed
1602ee3e8c14Smrg# expansion at the time the message is displayed, but you will need to
1603ee3e8c14Smrg# quote other shell meta-characters carefully to prevent them being
1604ee3e8c14Smrg# expanded when the contents are evaled.
1605ee3e8c14Smrgusage='$progpath [OPTION]...'
1606ee3e8c14Smrg
1607ee3e8c14Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608ee3e8c14Smrg# override it after sourcing this library to reflect the full set of
1609ee3e8c14Smrg# options your script accepts.
1610ee3e8c14Smrgusage_message="\
1611ee3e8c14Smrg       --debug        enable verbose shell tracing
1612ee3e8c14Smrg   -W, --warnings=CATEGORY
1613ee3e8c14Smrg                      report the warnings falling in CATEGORY [all]
1614ee3e8c14Smrg   -v, --verbose      verbosely report processing
1615ee3e8c14Smrg       --version      print version information and exit
1616ee3e8c14Smrg   -h, --help         print short or long help message and exit
1617ee3e8c14Smrg"
1618ee3e8c14Smrg
1619ee3e8c14Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620ee3e8c14Smrglong_help_message="
1621ee3e8c14SmrgWarning categories include:
1622ee3e8c14Smrg       'all'          show all warnings
1623ee3e8c14Smrg       'none'         turn off all the warnings
1624ee3e8c14Smrg       'error'        warnings are treated as fatal errors"
1625ee3e8c14Smrg
1626ee3e8c14Smrg# Help message printed before fatal option parsing errors.
1627ee3e8c14Smrgfatal_help="Try '\$progname --help' for more information."
1628ee3e8c14Smrg
1629ee3e8c14Smrg
1630ee3e8c14Smrg
1631ee3e8c14Smrg## ------------------------- ##
1632ee3e8c14Smrg## Hook function management. ##
1633ee3e8c14Smrg## ------------------------- ##
1634ee3e8c14Smrg
1635ee3e8c14Smrg# This section contains functions for adding, removing, and running hooks
1636ee3e8c14Smrg# in the main code.  A hook is just a list of function names that can be
1637ee3e8c14Smrg# run in order later on.
1638ee3e8c14Smrg
1639ee3e8c14Smrg# func_hookable FUNC_NAME
1640ee3e8c14Smrg# -----------------------
1641ee3e8c14Smrg# Declare that FUNC_NAME will run hooks added with
1642ee3e8c14Smrg# 'func_add_hook FUNC_NAME ...'.
1643ee3e8c14Smrgfunc_hookable ()
1644ee3e8c14Smrg{
1645ee3e8c14Smrg    $debug_cmd
1646ee3e8c14Smrg
1647ee3e8c14Smrg    func_append hookable_fns " $1"
1648ee3e8c14Smrg}
1649ee3e8c14Smrg
1650ee3e8c14Smrg
1651ee3e8c14Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652ee3e8c14Smrg# ---------------------------------
1653ee3e8c14Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654ee3e8c14Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655ee3e8c14Smrgfunc_add_hook ()
1656ee3e8c14Smrg{
1657ee3e8c14Smrg    $debug_cmd
1658ee3e8c14Smrg
1659ee3e8c14Smrg    case " $hookable_fns " in
1660ee3e8c14Smrg      *" $1 "*) ;;
1661ee3e8c14Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662ee3e8c14Smrg    esac
1663ee3e8c14Smrg
1664ee3e8c14Smrg    eval func_append ${1}_hooks '" $2"'
1665ee3e8c14Smrg}
1666ee3e8c14Smrg
1667ee3e8c14Smrg
1668ee3e8c14Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669ee3e8c14Smrg# ------------------------------------
1670ee3e8c14Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671ee3e8c14Smrg# FUNC_NAME.
1672ee3e8c14Smrgfunc_remove_hook ()
1673ee3e8c14Smrg{
1674ee3e8c14Smrg    $debug_cmd
1675ee3e8c14Smrg
1676ee3e8c14Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677ee3e8c14Smrg}
1678ee3e8c14Smrg
1679ee3e8c14Smrg
1680ee3e8c14Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681ee3e8c14Smrg# ---------------------------------------------
1682ee3e8c14Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683ee3e8c14Smrg# *_result variable of FUNC_NAME_B.
1684ee3e8c14Smrgfunc_propagate_result ()
1685ee3e8c14Smrg{
1686ee3e8c14Smrg    $debug_cmd
1687ee3e8c14Smrg
1688ee3e8c14Smrg    func_propagate_result_result=:
1689ee3e8c14Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690ee3e8c14Smrg    then
1691ee3e8c14Smrg      eval "${2}_result=\$${1}_result"
1692ee3e8c14Smrg    else
1693ee3e8c14Smrg      func_propagate_result_result=false
1694ee3e8c14Smrg    fi
1695ee3e8c14Smrg}
1696ee3e8c14Smrg
1697ee3e8c14Smrg
1698ee3e8c14Smrg# func_run_hooks FUNC_NAME [ARG]...
1699ee3e8c14Smrg# ---------------------------------
1700ee3e8c14Smrg# Run all hook functions registered to FUNC_NAME.
1701ee3e8c14Smrg# It's assumed that the list of hook functions contains nothing more
1702ee3e8c14Smrg# than a whitespace-delimited list of legal shell function names, and
1703ee3e8c14Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704ee3e8c14Smrg# whitespace.
1705ee3e8c14Smrgfunc_run_hooks ()
1706ee3e8c14Smrg{
1707ee3e8c14Smrg    $debug_cmd
1708ee3e8c14Smrg
1709ee3e8c14Smrg    case " $hookable_fns " in
1710ee3e8c14Smrg      *" $1 "*) ;;
1711ee3e8c14Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712191cded7Smrg    esac
1713ee3e8c14Smrg
1714ee3e8c14Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715ee3e8c14Smrg
1716ee3e8c14Smrg    for _G_hook in $_G_hook_fns; do
1717ee3e8c14Smrg      func_unset "${_G_hook}_result"
1718ee3e8c14Smrg      eval $_G_hook '${1+"$@"}'
1719ee3e8c14Smrg      func_propagate_result $_G_hook func_run_hooks
1720ee3e8c14Smrg      if $func_propagate_result_result; then
1721ee3e8c14Smrg        eval set dummy "$func_run_hooks_result"; shift
1722ee3e8c14Smrg      fi
1723ee3e8c14Smrg    done
1724ee3e8c14Smrg}
1725ee3e8c14Smrg
1726ee3e8c14Smrg
1727ee3e8c14Smrg
1728ee3e8c14Smrg## --------------- ##
1729ee3e8c14Smrg## Option parsing. ##
1730ee3e8c14Smrg## --------------- ##
1731ee3e8c14Smrg
1732ee3e8c14Smrg# In order to add your own option parsing hooks, you must accept the
1733ee3e8c14Smrg# full positional parameter list from your hook function.  You may remove
1734ee3e8c14Smrg# or edit any options that you action, and then pass back the remaining
1735ee3e8c14Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736ee3e8c14Smrg# suitably for 'eval'.
1737ee3e8c14Smrg#
1738ee3e8c14Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739ee3e8c14Smrg# before your hook gets called; for best performance, only set the
1740ee3e8c14Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741ee3e8c14Smrg# function unnecessarily because it can be an expensive operation on some
1742ee3e8c14Smrg# machines).
1743ee3e8c14Smrg#
1744ee3e8c14Smrg# Like this:
1745ee3e8c14Smrg#
1746ee3e8c14Smrg#    my_options_prep ()
1747ee3e8c14Smrg#    {
1748ee3e8c14Smrg#        $debug_cmd
1749ee3e8c14Smrg#
1750ee3e8c14Smrg#        # Extend the existing usage message.
1751ee3e8c14Smrg#        usage_message=$usage_message'
1752ee3e8c14Smrg#      -s, --silent       don'\''t print informational messages
1753ee3e8c14Smrg#    '
1754ee3e8c14Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755ee3e8c14Smrg#        # my_options_prep_result variable intact.
1756ee3e8c14Smrg#    }
1757ee3e8c14Smrg#    func_add_hook func_options_prep my_options_prep
1758ee3e8c14Smrg#
1759ee3e8c14Smrg#
1760ee3e8c14Smrg#    my_silent_option ()
1761ee3e8c14Smrg#    {
1762ee3e8c14Smrg#        $debug_cmd
1763ee3e8c14Smrg#
1764ee3e8c14Smrg#        args_changed=false
1765ee3e8c14Smrg#
1766ee3e8c14Smrg#        # Note that, for efficiency, we parse as many options as we can
1767ee3e8c14Smrg#        # recognise in a loop before passing the remainder back to the
1768ee3e8c14Smrg#        # caller on the first unrecognised argument we encounter.
1769ee3e8c14Smrg#        while test $# -gt 0; do
1770ee3e8c14Smrg#          opt=$1; shift
1771ee3e8c14Smrg#          case $opt in
1772ee3e8c14Smrg#            --silent|-s) opt_silent=:
1773ee3e8c14Smrg#                         args_changed=:
1774ee3e8c14Smrg#                         ;;
1775ee3e8c14Smrg#            # Separate non-argument short options:
1776ee3e8c14Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777ee3e8c14Smrg#                         set dummy "$func_split_short_opt_name" \
1778ee3e8c14Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779ee3e8c14Smrg#                         shift
1780ee3e8c14Smrg#                         args_changed=:
1781ee3e8c14Smrg#                         ;;
1782ee3e8c14Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783ee3e8c14Smrg#                         # is added back to "$@" in case we need it later,
1784ee3e8c14Smrg#                         # if $args_changed was set to 'true'.
1785ee3e8c14Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786ee3e8c14Smrg#          esac
1787ee3e8c14Smrg#        done
1788ee3e8c14Smrg#
1789ee3e8c14Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790ee3e8c14Smrg#        if $args_changed; then
1791ee3e8c14Smrg#          func_quote eval ${1+"$@"}
1792ee3e8c14Smrg#          my_silent_option_result=$func_quote_result
1793ee3e8c14Smrg#        fi
1794ee3e8c14Smrg#    }
1795ee3e8c14Smrg#    func_add_hook func_parse_options my_silent_option
1796ee3e8c14Smrg#
1797ee3e8c14Smrg#
1798ee3e8c14Smrg#    my_option_validation ()
1799ee3e8c14Smrg#    {
1800ee3e8c14Smrg#        $debug_cmd
1801ee3e8c14Smrg#
1802ee3e8c14Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803ee3e8c14Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804ee3e8c14Smrg#    }
1805ee3e8c14Smrg#    func_add_hook func_validate_options my_option_validation
1806ee3e8c14Smrg#
1807ee3e8c14Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808ee3e8c14Smrg# options you parse.  It's preferable to append if you can, so that
1809ee3e8c14Smrg# multiple option parsing hooks can be added safely.
1810ee3e8c14Smrg
1811ee3e8c14Smrg
1812ee3e8c14Smrg# func_options_finish [ARG]...
1813ee3e8c14Smrg# ----------------------------
1814ee3e8c14Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815ee3e8c14Smrgfunc_options_finish ()
1816ee3e8c14Smrg{
1817ee3e8c14Smrg    $debug_cmd
1818ee3e8c14Smrg
1819ee3e8c14Smrg    func_run_hooks func_options ${1+"$@"}
1820ee3e8c14Smrg    func_propagate_result func_run_hooks func_options_finish
1821ee3e8c14Smrg}
1822ee3e8c14Smrg
1823ee3e8c14Smrg
1824ee3e8c14Smrg# func_options [ARG]...
1825ee3e8c14Smrg# ---------------------
1826ee3e8c14Smrg# All the functions called inside func_options are hookable. See the
1827ee3e8c14Smrg# individual implementations for details.
1828ee3e8c14Smrgfunc_hookable func_options
1829ee3e8c14Smrgfunc_options ()
1830ee3e8c14Smrg{
1831ee3e8c14Smrg    $debug_cmd
1832ee3e8c14Smrg
1833ee3e8c14Smrg    _G_options_quoted=false
1834ee3e8c14Smrg
1835ee3e8c14Smrg    for my_func in options_prep parse_options validate_options options_finish
1836ee3e8c14Smrg    do
1837ee3e8c14Smrg      func_unset func_${my_func}_result
1838ee3e8c14Smrg      func_unset func_run_hooks_result
1839ee3e8c14Smrg      eval func_$my_func '${1+"$@"}'
1840ee3e8c14Smrg      func_propagate_result func_$my_func func_options
1841ee3e8c14Smrg      if $func_propagate_result_result; then
1842ee3e8c14Smrg        eval set dummy "$func_options_result"; shift
1843ee3e8c14Smrg        _G_options_quoted=:
1844ee3e8c14Smrg      fi
1845ee3e8c14Smrg    done
1846ee3e8c14Smrg
1847ee3e8c14Smrg    $_G_options_quoted || {
1848ee3e8c14Smrg      # As we (func_options) are top-level options-parser function and
1849ee3e8c14Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850ee3e8c14Smrg      # caller.
1851ee3e8c14Smrg      func_quote eval ${1+"$@"}
1852ee3e8c14Smrg      func_options_result=$func_quote_result
1853ee3e8c14Smrg    }
1854191cded7Smrg}
1855191cded7Smrg
1856191cded7Smrg
1857ee3e8c14Smrg# func_options_prep [ARG]...
1858ee3e8c14Smrg# --------------------------
1859ee3e8c14Smrg# All initialisations required before starting the option parse loop.
1860ee3e8c14Smrg# Note that when calling hook functions, we pass through the list of
1861ee3e8c14Smrg# positional parameters.  If a hook function modifies that list, and
1862ee3e8c14Smrg# needs to propagate that back to rest of this script, then the complete
1863ee3e8c14Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864ee3e8c14Smrgfunc_hookable func_options_prep
1865ee3e8c14Smrgfunc_options_prep ()
1866191cded7Smrg{
1867ee3e8c14Smrg    $debug_cmd
1868b290cf36Smrg
1869ee3e8c14Smrg    # Option defaults:
1870ee3e8c14Smrg    opt_verbose=false
1871ee3e8c14Smrg    opt_warning_types=
1872b290cf36Smrg
1873ee3e8c14Smrg    func_run_hooks func_options_prep ${1+"$@"}
1874ee3e8c14Smrg    func_propagate_result func_run_hooks func_options_prep
1875191cded7Smrg}
1876191cded7Smrg
1877191cded7Smrg
1878ee3e8c14Smrg# func_parse_options [ARG]...
1879ee3e8c14Smrg# ---------------------------
1880ee3e8c14Smrg# The main option parsing loop.
1881ee3e8c14Smrgfunc_hookable func_parse_options
1882ee3e8c14Smrgfunc_parse_options ()
1883191cded7Smrg{
1884ee3e8c14Smrg    $debug_cmd
1885ee3e8c14Smrg
1886ee3e8c14Smrg    _G_parse_options_requote=false
1887ee3e8c14Smrg    # this just eases exit handling
1888ee3e8c14Smrg    while test $# -gt 0; do
1889ee3e8c14Smrg      # Defer to hook functions for initial option parsing, so they
1890ee3e8c14Smrg      # get priority in the event of reusing an option name.
1891ee3e8c14Smrg      func_run_hooks func_parse_options ${1+"$@"}
1892ee3e8c14Smrg      func_propagate_result func_run_hooks func_parse_options
1893ee3e8c14Smrg      if $func_propagate_result_result; then
1894ee3e8c14Smrg        eval set dummy "$func_parse_options_result"; shift
1895ee3e8c14Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896ee3e8c14Smrg        # down into the hook and it quoted it for us (because we are in
1897ee3e8c14Smrg        # this if-branch).  No need to quote it again.
1898ee3e8c14Smrg        _G_parse_options_requote=false
1899ee3e8c14Smrg      fi
1900191cded7Smrg
1901ee3e8c14Smrg      # Break out of the loop if we already parsed every option.
1902ee3e8c14Smrg      test $# -gt 0 || break
1903ee3e8c14Smrg
1904ee3e8c14Smrg      # We expect that one of the options parsed in this function matches
1905ee3e8c14Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906ee3e8c14Smrg      _G_match_parse_options=:
1907ee3e8c14Smrg      _G_opt=$1
1908ee3e8c14Smrg      shift
1909ee3e8c14Smrg      case $_G_opt in
1910ee3e8c14Smrg        --debug|-x)   debug_cmd='set -x'
1911ee3e8c14Smrg                      func_echo "enabling shell trace mode" >&2
1912ee3e8c14Smrg                      $debug_cmd
1913ee3e8c14Smrg                      ;;
1914ee3e8c14Smrg
1915ee3e8c14Smrg        --no-warnings|--no-warning|--no-warn)
1916ee3e8c14Smrg                      set dummy --warnings none ${1+"$@"}
1917ee3e8c14Smrg                      shift
1918ee3e8c14Smrg		      ;;
1919ee3e8c14Smrg
1920ee3e8c14Smrg        --warnings|--warning|-W)
1921ee3e8c14Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922ee3e8c14Smrg                        _G_parse_options_requote=:
1923ee3e8c14Smrg                        break
1924ee3e8c14Smrg                      fi
1925ee3e8c14Smrg                      case " $warning_categories $1" in
1926ee3e8c14Smrg                        *" $1 "*)
1927ee3e8c14Smrg                          # trailing space prevents matching last $1 above
1928ee3e8c14Smrg                          func_append_uniq opt_warning_types " $1"
1929ee3e8c14Smrg                          ;;
1930ee3e8c14Smrg                        *all)
1931ee3e8c14Smrg                          opt_warning_types=$warning_categories
1932ee3e8c14Smrg                          ;;
1933ee3e8c14Smrg                        *none)
1934ee3e8c14Smrg                          opt_warning_types=none
1935ee3e8c14Smrg                          warning_func=:
1936ee3e8c14Smrg                          ;;
1937ee3e8c14Smrg                        *error)
1938ee3e8c14Smrg                          opt_warning_types=$warning_categories
1939ee3e8c14Smrg                          warning_func=func_fatal_error
1940ee3e8c14Smrg                          ;;
1941ee3e8c14Smrg                        *)
1942ee3e8c14Smrg                          func_fatal_error \
1943ee3e8c14Smrg                             "unsupported warning category: '$1'"
1944ee3e8c14Smrg                          ;;
1945ee3e8c14Smrg                      esac
1946ee3e8c14Smrg                      shift
1947ee3e8c14Smrg                      ;;
1948ee3e8c14Smrg
1949ee3e8c14Smrg        --verbose|-v) opt_verbose=: ;;
1950ee3e8c14Smrg        --version)    func_version ;;
1951ee3e8c14Smrg        -\?|-h)       func_usage ;;
1952ee3e8c14Smrg        --help)       func_help ;;
1953ee3e8c14Smrg
1954ee3e8c14Smrg	# Separate optargs to long options (plugins may need this):
1955ee3e8c14Smrg	--*=*)        func_split_equals "$_G_opt"
1956ee3e8c14Smrg	              set dummy "$func_split_equals_lhs" \
1957ee3e8c14Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958ee3e8c14Smrg                      shift
1959ee3e8c14Smrg                      ;;
1960ee3e8c14Smrg
1961ee3e8c14Smrg       # Separate optargs to short options:
1962ee3e8c14Smrg        -W*)
1963ee3e8c14Smrg                      func_split_short_opt "$_G_opt"
1964ee3e8c14Smrg                      set dummy "$func_split_short_opt_name" \
1965ee3e8c14Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966ee3e8c14Smrg                      shift
1967ee3e8c14Smrg                      ;;
1968ee3e8c14Smrg
1969ee3e8c14Smrg        # Separate non-argument short options:
1970ee3e8c14Smrg        -\?*|-h*|-v*|-x*)
1971ee3e8c14Smrg                      func_split_short_opt "$_G_opt"
1972ee3e8c14Smrg                      set dummy "$func_split_short_opt_name" \
1973ee3e8c14Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974ee3e8c14Smrg                      shift
1975ee3e8c14Smrg                      ;;
1976ee3e8c14Smrg
1977ee3e8c14Smrg        --)           _G_parse_options_requote=: ; break ;;
1978ee3e8c14Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979ee3e8c14Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980ee3e8c14Smrg                      _G_match_parse_options=false
1981ee3e8c14Smrg                      break
1982ee3e8c14Smrg                      ;;
1983ee3e8c14Smrg      esac
1984b290cf36Smrg
1985ee3e8c14Smrg      if $_G_match_parse_options; then
1986ee3e8c14Smrg        _G_parse_options_requote=:
1987b290cf36Smrg      fi
1988ee3e8c14Smrg    done
1989ee3e8c14Smrg
1990ee3e8c14Smrg    if $_G_parse_options_requote; then
1991ee3e8c14Smrg      # save modified positional parameters for caller
1992ee3e8c14Smrg      func_quote eval ${1+"$@"}
1993ee3e8c14Smrg      func_parse_options_result=$func_quote_result
1994191cded7Smrg    fi
1995191cded7Smrg}
1996191cded7Smrg
1997b290cf36Smrg
1998ee3e8c14Smrg# func_validate_options [ARG]...
1999ee3e8c14Smrg# ------------------------------
2000ee3e8c14Smrg# Perform any sanity checks on option settings and/or unconsumed
2001ee3e8c14Smrg# arguments.
2002ee3e8c14Smrgfunc_hookable func_validate_options
2003ee3e8c14Smrgfunc_validate_options ()
2004191cded7Smrg{
2005ee3e8c14Smrg    $debug_cmd
2006191cded7Smrg
2007ee3e8c14Smrg    # Display all warnings if -W was not given.
2008ee3e8c14Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009b290cf36Smrg
2010ee3e8c14Smrg    func_run_hooks func_validate_options ${1+"$@"}
2011ee3e8c14Smrg    func_propagate_result func_run_hooks func_validate_options
2012191cded7Smrg
2013ee3e8c14Smrg    # Bail if the options were screwed!
2014ee3e8c14Smrg    $exit_cmd $EXIT_FAILURE
2015d9dcd5aeSmrg}
2016d9dcd5aeSmrg
2017191cded7Smrg
2018d9dcd5aeSmrg
2019ee3e8c14Smrg## ----------------- ##
2020ee3e8c14Smrg## Helper functions. ##
2021ee3e8c14Smrg## ----------------- ##
2022b290cf36Smrg
2023ee3e8c14Smrg# This section contains the helper functions used by the rest of the
2024ee3e8c14Smrg# hookable option parser framework in ascii-betical order.
2025ee3e8c14Smrg
2026ee3e8c14Smrg
2027ee3e8c14Smrg# func_fatal_help ARG...
2028ee3e8c14Smrg# ----------------------
2029ee3e8c14Smrg# Echo program name prefixed message to standard error, followed by
2030ee3e8c14Smrg# a help hint, and exit.
2031ee3e8c14Smrgfunc_fatal_help ()
2032b290cf36Smrg{
2033ee3e8c14Smrg    $debug_cmd
2034d9dcd5aeSmrg
2035ee3e8c14Smrg    eval \$ECHO \""Usage: $usage"\"
2036ee3e8c14Smrg    eval \$ECHO \""$fatal_help"\"
2037ee3e8c14Smrg    func_error ${1+"$@"}
2038ee3e8c14Smrg    exit $EXIT_FAILURE
2039b290cf36Smrg}
2040b290cf36Smrg
2041ee3e8c14Smrg
2042ee3e8c14Smrg# func_help
2043ee3e8c14Smrg# ---------
2044ee3e8c14Smrg# Echo long help message to standard output and exit.
2045b290cf36Smrgfunc_help ()
2046b290cf36Smrg{
2047ee3e8c14Smrg    $debug_cmd
2048ee3e8c14Smrg
2049ee3e8c14Smrg    func_usage_message
2050ee3e8c14Smrg    $ECHO "$long_help_message"
2051ee3e8c14Smrg    exit 0
2052b290cf36Smrg}
2053b290cf36Smrg
2054ee3e8c14Smrg
2055ee3e8c14Smrg# func_missing_arg ARGNAME
2056ee3e8c14Smrg# ------------------------
2057b290cf36Smrg# Echo program name prefixed message to standard error and set global
2058b290cf36Smrg# exit_cmd.
2059b290cf36Smrgfunc_missing_arg ()
2060b290cf36Smrg{
2061ee3e8c14Smrg    $debug_cmd
2062d9dcd5aeSmrg
2063ee3e8c14Smrg    func_error "Missing argument for '$1'."
2064b290cf36Smrg    exit_cmd=exit
2065b290cf36Smrg}
2066b290cf36Smrg
2067b290cf36Smrg
2068ee3e8c14Smrg# func_split_equals STRING
2069ee3e8c14Smrg# ------------------------
2070ee3e8c14Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071ee3e8c14Smrg# after splitting STRING at the '=' sign.
2072ee3e8c14Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073ee3e8c14Smrg    && (eval 'x=a/b/c;
2074ee3e8c14Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075ee3e8c14Smrg    && _G_HAVE_XSI_OPS=yes
2076ee3e8c14Smrg
2077ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078ee3e8c14Smrgthen
2079ee3e8c14Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080ee3e8c14Smrg  eval 'func_split_equals ()
2081ee3e8c14Smrg  {
2082ee3e8c14Smrg      $debug_cmd
2083ee3e8c14Smrg
2084ee3e8c14Smrg      func_split_equals_lhs=${1%%=*}
2085ee3e8c14Smrg      func_split_equals_rhs=${1#*=}
2086ee3e8c14Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087ee3e8c14Smrg        func_split_equals_rhs=
2088ee3e8c14Smrg      fi
2089ee3e8c14Smrg  }'
2090ee3e8c14Smrgelse
2091ee3e8c14Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092ee3e8c14Smrg  func_split_equals ()
2093ee3e8c14Smrg  {
2094ee3e8c14Smrg      $debug_cmd
2095ee3e8c14Smrg
2096ee3e8c14Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097ee3e8c14Smrg      func_split_equals_rhs=
2098ee3e8c14Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099ee3e8c14Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100ee3e8c14Smrg  }
2101ee3e8c14Smrgfi #func_split_equals
2102ee3e8c14Smrg
2103ee3e8c14Smrg
2104ee3e8c14Smrg# func_split_short_opt SHORTOPT
2105ee3e8c14Smrg# -----------------------------
2106d9dcd5aeSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107d9dcd5aeSmrg# variables after splitting SHORTOPT after the 2nd character.
2108ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109ee3e8c14Smrgthen
2110ee3e8c14Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111ee3e8c14Smrg  eval 'func_split_short_opt ()
2112ee3e8c14Smrg  {
2113ee3e8c14Smrg      $debug_cmd
2114ee3e8c14Smrg
2115ee3e8c14Smrg      func_split_short_opt_arg=${1#??}
2116ee3e8c14Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117ee3e8c14Smrg  }'
2118ee3e8c14Smrgelse
2119ee3e8c14Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120ee3e8c14Smrg  func_split_short_opt ()
2121ee3e8c14Smrg  {
2122ee3e8c14Smrg      $debug_cmd
2123ee3e8c14Smrg
2124ee3e8c14Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125ee3e8c14Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126ee3e8c14Smrg  }
2127ee3e8c14Smrgfi #func_split_short_opt
2128ee3e8c14Smrg
2129ee3e8c14Smrg
2130ee3e8c14Smrg# func_usage
2131ee3e8c14Smrg# ----------
2132ee3e8c14Smrg# Echo short help message to standard output and exit.
2133ee3e8c14Smrgfunc_usage ()
2134d9dcd5aeSmrg{
2135ee3e8c14Smrg    $debug_cmd
2136d9dcd5aeSmrg
2137ee3e8c14Smrg    func_usage_message
2138ee3e8c14Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139ee3e8c14Smrg    exit 0
2140ee3e8c14Smrg}
2141d9dcd5aeSmrg
2142d9dcd5aeSmrg
2143ee3e8c14Smrg# func_usage_message
2144ee3e8c14Smrg# ------------------
2145ee3e8c14Smrg# Echo short help message to standard output.
2146ee3e8c14Smrgfunc_usage_message ()
2147d9dcd5aeSmrg{
2148ee3e8c14Smrg    $debug_cmd
2149ee3e8c14Smrg
2150ee3e8c14Smrg    eval \$ECHO \""Usage: $usage"\"
2151ee3e8c14Smrg    echo
2152ee3e8c14Smrg    $SED -n 's|^# ||
2153ee3e8c14Smrg        /^Written by/{
2154ee3e8c14Smrg          x;p;x
2155ee3e8c14Smrg        }
2156ee3e8c14Smrg	h
2157ee3e8c14Smrg	/^Written by/q' < "$progpath"
2158ee3e8c14Smrg    echo
2159ee3e8c14Smrg    eval \$ECHO \""$usage_message"\"
2160ee3e8c14Smrg}
2161d9dcd5aeSmrg
2162d9dcd5aeSmrg
2163ee3e8c14Smrg# func_version
2164ee3e8c14Smrg# ------------
2165ee3e8c14Smrg# Echo version message to standard output and exit.
2166ee3e8c14Smrg# The version message is extracted from the calling file's header
2167ee3e8c14Smrg# comments, with leading '# ' stripped:
2168ee3e8c14Smrg#   1. First display the progname and version
2169ee3e8c14Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170ee3e8c14Smrg#   3. Then a blank line followed by the first following line matching
2171ee3e8c14Smrg#      /^# Copyright /
2172ee3e8c14Smrg#   4. Immediately followed by any lines between the previous matches,
2173ee3e8c14Smrg#      except lines preceding the intervening completely blank line.
2174ee3e8c14Smrg# For example, see the header comments of this file.
2175ee3e8c14Smrgfunc_version ()
2176ee3e8c14Smrg{
2177ee3e8c14Smrg    $debug_cmd
2178ee3e8c14Smrg
2179ee3e8c14Smrg    printf '%s\n' "$progname $scriptversion"
2180ee3e8c14Smrg    $SED -n '
2181ee3e8c14Smrg        /^# Written by /!b
2182ee3e8c14Smrg        s|^# ||; p; n
2183b290cf36Smrg
2184ee3e8c14Smrg        :fwd2blnk
2185ee3e8c14Smrg        /./ {
2186ee3e8c14Smrg          n
2187ee3e8c14Smrg          b fwd2blnk
2188ee3e8c14Smrg        }
2189ee3e8c14Smrg        p; n
2190ee3e8c14Smrg
2191ee3e8c14Smrg        :holdwrnt
2192ee3e8c14Smrg        s|^# ||
2193ee3e8c14Smrg        s|^# *$||
2194ee3e8c14Smrg        /^Copyright /!{
2195ee3e8c14Smrg          /./H
2196ee3e8c14Smrg          n
2197ee3e8c14Smrg          b holdwrnt
2198ee3e8c14Smrg        }
2199b290cf36Smrg
2200ee3e8c14Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201ee3e8c14Smrg        G
2202ee3e8c14Smrg        s|\(\n\)\n*|\1|g
2203ee3e8c14Smrg        p; q' < "$progpath"
2204b290cf36Smrg
2205ee3e8c14Smrg    exit $?
2206ee3e8c14Smrg}
2207b290cf36Smrg
2208191cded7Smrg
2209ee3e8c14Smrg# Local variables:
2210ee3e8c14Smrg# mode: shell-script
2211ee3e8c14Smrg# sh-indentation: 2
2212ee3e8c14Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213ee3e8c14Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214ee3e8c14Smrg# time-stamp-time-zone: "UTC"
2215ee3e8c14Smrg# End:
2216191cded7Smrg
2217ee3e8c14Smrg# Set a version string.
22188f9fac4aSmrgscriptversion='(GNU libtool) 2.5.4'
22198f9fac4aSmrg
22208f9fac4aSmrg# func_version
22218f9fac4aSmrg# ------------
22228f9fac4aSmrg# Echo version message to standard output and exit.
22238f9fac4aSmrgfunc_version ()
22248f9fac4aSmrg{
22258f9fac4aSmrg    $debug_cmd
22268f9fac4aSmrg
22278f9fac4aSmrg	year=`date +%Y`
22288f9fac4aSmrg
22298f9fac4aSmrg	cat <<EOF
22308f9fac4aSmrg$progname $scriptversion
22318f9fac4aSmrgCopyright (C) $year Free Software Foundation, Inc.
22328f9fac4aSmrgLicense GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>
22338f9fac4aSmrgThis is free software: you are free to change and redistribute it.
22348f9fac4aSmrgThere is NO WARRANTY, to the extent permitted by law.
22358f9fac4aSmrg
22368f9fac4aSmrgOriginally written by Gordon Matzigkeit, 1996
22378f9fac4aSmrg(See AUTHORS for complete contributor listing)
22388f9fac4aSmrgEOF
22398f9fac4aSmrg
22408f9fac4aSmrg    exit $?
22418f9fac4aSmrg}
2242191cded7Smrg
2243191cded7Smrg
2244ee3e8c14Smrg# func_echo ARG...
2245ee3e8c14Smrg# ----------------
2246ee3e8c14Smrg# Libtool also displays the current mode in messages, so override
2247ee3e8c14Smrg# funclib.sh func_echo with this custom definition.
2248ee3e8c14Smrgfunc_echo ()
2249d9dcd5aeSmrg{
2250ee3e8c14Smrg    $debug_cmd
2251d9dcd5aeSmrg
2252ee3e8c14Smrg    _G_message=$*
2253ee3e8c14Smrg
2254ee3e8c14Smrg    func_echo_IFS=$IFS
2255ee3e8c14Smrg    IFS=$nl
2256ee3e8c14Smrg    for _G_line in $_G_message; do
2257ee3e8c14Smrg      IFS=$func_echo_IFS
2258ee3e8c14Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2259ee3e8c14Smrg    done
2260ee3e8c14Smrg    IFS=$func_echo_IFS
2261ee3e8c14Smrg}
2262d9dcd5aeSmrg
2263d9dcd5aeSmrg
2264ee3e8c14Smrg## ---------------- ##
2265ee3e8c14Smrg## Options parsing. ##
2266ee3e8c14Smrg## ---------------- ##
2267ee3e8c14Smrg
2268ee3e8c14Smrg# Hook in the functions to make sure our own options are parsed during
2269ee3e8c14Smrg# the option parsing loop.
2270ee3e8c14Smrg
2271ee3e8c14Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2272ee3e8c14Smrg
2273ee3e8c14Smrg# Short help message in response to '-h'.
2274ee3e8c14Smrgusage_message="Options:
22758f9fac4aSmrg       --config                 show all configuration variables
22768f9fac4aSmrg       --debug                  enable verbose shell tracing
22778f9fac4aSmrg   -n, --dry-run                display commands without modifying any files
22788f9fac4aSmrg       --features               display basic configuration information
22798f9fac4aSmrg       --finish                 use operation '--mode=finish'
22808f9fac4aSmrg       --mode=MODE              use operation mode MODE
22818f9fac4aSmrg       --no-finish              don't update shared library cache
22828f9fac4aSmrg       --no-quiet, --no-silent  print default informational messages
22838f9fac4aSmrg       --no-warnings            equivalent to '-Wnone'
22848f9fac4aSmrg       --preserve-dup-deps      don't remove duplicate dependency libraries
22858f9fac4aSmrg       --quiet, --silent        don't print informational messages
22868f9fac4aSmrg       --reorder-cache=DIRS     reorder shared library cache for preferred DIRS
22878f9fac4aSmrg       --tag=TAG                use configuration variables from tag TAG
22888f9fac4aSmrg   -v, --verbose                print more informational messages than default
22898f9fac4aSmrg       --version                print version information
22908f9fac4aSmrg   -W, --warnings=CATEGORY      report the warnings falling in CATEGORY [all]
22918f9fac4aSmrg   -h, --help, --help-all       print short, long, or detailed help message
2292ee3e8c14Smrg"
2293d9dcd5aeSmrg
2294ee3e8c14Smrg# Additional text appended to 'usage_message' in response to '--help'.
2295ee3e8c14Smrgfunc_help ()
2296d9dcd5aeSmrg{
2297ee3e8c14Smrg    $debug_cmd
2298ee3e8c14Smrg
2299ee3e8c14Smrg    func_usage_message
2300ee3e8c14Smrg    $ECHO "$long_help_message
2301ee3e8c14Smrg
2302ee3e8c14SmrgMODE must be one of the following:
2303ee3e8c14Smrg
2304ee3e8c14Smrg       clean           remove files from the build directory
2305ee3e8c14Smrg       compile         compile a source file into a libtool object
2306ee3e8c14Smrg       execute         automatically set library path, then run a program
2307ee3e8c14Smrg       finish          complete the installation of libtool libraries
2308ee3e8c14Smrg       install         install libraries or executables
2309ee3e8c14Smrg       link            create a library or an executable
2310ee3e8c14Smrg       uninstall       remove libraries from an installed directory
2311ee3e8c14Smrg
2312ee3e8c14SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2313ee3e8c14Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2314ee3e8c14SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2315ee3e8c14Smrg
2316ee3e8c14SmrgWhen reporting a bug, please describe a test case to reproduce it and
2317ee3e8c14Smrginclude the following information:
2318ee3e8c14Smrg
2319ee3e8c14Smrg       host-triplet:   $host
2320ee3e8c14Smrg       shell:          $SHELL
2321ee3e8c14Smrg       compiler:       $LTCC
2322ee3e8c14Smrg       compiler flags: $LTCFLAGS
2323ee3e8c14Smrg       linker:         $LD (gnu? $with_gnu_ld)
23248f9fac4aSmrg       version:        $progname $scriptversion
2325ee3e8c14Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2326ee3e8c14Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2327ee3e8c14Smrg
2328ee3e8c14SmrgReport bugs to <bug-libtool@gnu.org>.
23298f9fac4aSmrgGNU libtool home page: <https://www.gnu.org/software/libtool/>.
23308f9fac4aSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
2331ee3e8c14Smrg    exit 0
2332ee3e8c14Smrg}
2333d9dcd5aeSmrg
2334d9dcd5aeSmrg
2335ee3e8c14Smrg# func_lo2o OBJECT-NAME
2336ee3e8c14Smrg# ---------------------
2337ee3e8c14Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2338ee3e8c14Smrg# object suffix.
2339ee3e8c14Smrg
2340ee3e8c14Smrglo2o=s/\\.lo\$/.$objext/
2341ee3e8c14Smrgo2lo=s/\\.$objext\$/.lo/
2342ee3e8c14Smrg
2343ee3e8c14Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2344ee3e8c14Smrg  eval 'func_lo2o ()
2345ee3e8c14Smrg  {
2346ee3e8c14Smrg    case $1 in
2347ee3e8c14Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2348ee3e8c14Smrg      *   ) func_lo2o_result=$1               ;;
2349ee3e8c14Smrg    esac
2350ee3e8c14Smrg  }'
2351d9dcd5aeSmrg
2352ee3e8c14Smrg  # func_xform LIBOBJ-OR-SOURCE
2353ee3e8c14Smrg  # ---------------------------
2354ee3e8c14Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2355ee3e8c14Smrg  # suffix to a '.lo' libtool-object suffix.
2356ee3e8c14Smrg  eval 'func_xform ()
2357ee3e8c14Smrg  {
2358ee3e8c14Smrg    func_xform_result=${1%.*}.lo
2359ee3e8c14Smrg  }'
2360ee3e8c14Smrgelse
2361ee3e8c14Smrg  # ...otherwise fall back to using sed.
2362ee3e8c14Smrg  func_lo2o ()
2363ee3e8c14Smrg  {
2364ee3e8c14Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2365ee3e8c14Smrg  }
2366ee3e8c14Smrg
2367ee3e8c14Smrg  func_xform ()
2368ee3e8c14Smrg  {
2369ee3e8c14Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2370ee3e8c14Smrg  }
2371ee3e8c14Smrgfi
2372d9dcd5aeSmrg
2373ee3e8c14Smrg
2374ee3e8c14Smrg# func_fatal_configuration ARG...
2375ee3e8c14Smrg# -------------------------------
2376b290cf36Smrg# Echo program name prefixed message to standard error, followed by
2377b290cf36Smrg# a configuration failure hint, and exit.
2378b290cf36Smrgfunc_fatal_configuration ()
2379b290cf36Smrg{
2380ee3e8c14Smrg    func_fatal_error ${1+"$@"} \
2381ee3e8c14Smrg      "See the $PACKAGE documentation for more information." \
2382ee3e8c14Smrg      "Fatal configuration error."
2383b290cf36Smrg}
2384b290cf36Smrg
2385b290cf36Smrg
2386b290cf36Smrg# func_config
2387ee3e8c14Smrg# -----------
2388b290cf36Smrg# Display the configuration for all the tags in this script.
2389b290cf36Smrgfunc_config ()
2390b290cf36Smrg{
2391b290cf36Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2392b290cf36Smrg    re_endcf='^# ### END LIBTOOL'
2393b290cf36Smrg
2394b290cf36Smrg    # Default configuration.
2395b290cf36Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2396191cded7Smrg
2397191cded7Smrg    # Now print the configurations for the tags.
2398191cded7Smrg    for tagname in $taglist; do
2399b290cf36Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2400191cded7Smrg    done
2401191cded7Smrg
2402b290cf36Smrg    exit $?
2403b290cf36Smrg}
2404191cded7Smrg
2405ee3e8c14Smrg
2406b290cf36Smrg# func_features
2407ee3e8c14Smrg# -------------
2408b290cf36Smrg# Display the features supported by this script.
2409b290cf36Smrgfunc_features ()
2410b290cf36Smrg{
2411ba064abeSmrg    echo "host: $host"
2412ee3e8c14Smrg    if test yes = "$build_libtool_libs"; then
2413ba064abeSmrg      echo "enable shared libraries"
2414191cded7Smrg    else
2415ba064abeSmrg      echo "disable shared libraries"
2416191cded7Smrg    fi
2417ee3e8c14Smrg    if test yes = "$build_old_libs"; then
2418ba064abeSmrg      echo "enable static libraries"
2419191cded7Smrg    else
2420ba064abeSmrg      echo "disable static libraries"
2421191cded7Smrg    fi
2422b290cf36Smrg
2423191cded7Smrg    exit $?
2424b290cf36Smrg}
2425b290cf36Smrg
2426ee3e8c14Smrg
2427ee3e8c14Smrg# func_enable_tag TAGNAME
2428ee3e8c14Smrg# -----------------------
2429b290cf36Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2430b290cf36Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2431b290cf36Smrg# variable here.
2432b290cf36Smrgfunc_enable_tag ()
2433b290cf36Smrg{
2434ee3e8c14Smrg    # Global variable:
2435ee3e8c14Smrg    tagname=$1
2436191cded7Smrg
2437ee3e8c14Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2438ee3e8c14Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2439ee3e8c14Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2440191cded7Smrg
2441ee3e8c14Smrg    # Validate tagname.
2442ee3e8c14Smrg    case $tagname in
2443ee3e8c14Smrg      *[!-_A-Za-z0-9,/]*)
2444ee3e8c14Smrg        func_fatal_error "invalid tag name: $tagname"
2445ee3e8c14Smrg        ;;
2446ee3e8c14Smrg    esac
2447191cded7Smrg
2448ee3e8c14Smrg    # Don't test for the "default" C tag, as we know it's
2449ee3e8c14Smrg    # there but not specially marked.
2450ee3e8c14Smrg    case $tagname in
2451ee3e8c14Smrg        CC) ;;
2452b290cf36Smrg    *)
2453ee3e8c14Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2454ee3e8c14Smrg	  taglist="$taglist $tagname"
2455ee3e8c14Smrg
2456ee3e8c14Smrg	  # Evaluate the configuration.  Be careful to quote the path
2457ee3e8c14Smrg	  # and the sed script, to avoid splitting on whitespace, but
2458ee3e8c14Smrg	  # also don't use non-portable quotes within backquotes within
2459ee3e8c14Smrg	  # quotes we have to do it in 2 steps:
2460ee3e8c14Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2461ee3e8c14Smrg	  eval "$extractedcf"
2462ee3e8c14Smrg        else
2463ee3e8c14Smrg	  func_error "ignoring unknown tag $tagname"
2464ee3e8c14Smrg        fi
2465ee3e8c14Smrg        ;;
2466ee3e8c14Smrg    esac
2467b290cf36Smrg}
2468191cded7Smrg
2469ee3e8c14Smrg
2470d9dcd5aeSmrg# func_check_version_match
2471ee3e8c14Smrg# ------------------------
2472d9dcd5aeSmrg# Ensure that we are using m4 macros, and libtool script from the same
2473d9dcd5aeSmrg# release of libtool.
2474d9dcd5aeSmrgfunc_check_version_match ()
2475b290cf36Smrg{
2476ee3e8c14Smrg    if test "$package_revision" != "$macro_revision"; then
2477ee3e8c14Smrg      if test "$VERSION" != "$macro_version"; then
2478ee3e8c14Smrg        if test -z "$macro_version"; then
2479ee3e8c14Smrg          cat >&2 <<_LT_EOF
2480d9dcd5aeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2481d9dcd5aeSmrg$progname: definition of this LT_INIT comes from an older release.
2482d9dcd5aeSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2483d9dcd5aeSmrg$progname: and run autoconf again.
2484d9dcd5aeSmrg_LT_EOF
2485ee3e8c14Smrg        else
2486ee3e8c14Smrg          cat >&2 <<_LT_EOF
2487d9dcd5aeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2488d9dcd5aeSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2489d9dcd5aeSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2490d9dcd5aeSmrg$progname: and run autoconf again.
2491d9dcd5aeSmrg_LT_EOF
2492ee3e8c14Smrg        fi
2493ee3e8c14Smrg      else
2494ee3e8c14Smrg        cat >&2 <<_LT_EOF
2495d9dcd5aeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2496d9dcd5aeSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2497d9dcd5aeSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2498d9dcd5aeSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2499d9dcd5aeSmrg_LT_EOF
2500ee3e8c14Smrg      fi
2501d9dcd5aeSmrg
2502ee3e8c14Smrg      exit $EXIT_MISMATCH
2503ee3e8c14Smrg    fi
2504d9dcd5aeSmrg}
2505d9dcd5aeSmrg
2506d9dcd5aeSmrg
2507ee3e8c14Smrg# libtool_options_prep [ARG]...
2508ee3e8c14Smrg# -----------------------------
2509ee3e8c14Smrg# Preparation for options parsed by libtool.
2510ee3e8c14Smrglibtool_options_prep ()
2511ee3e8c14Smrg{
2512ee3e8c14Smrg    $debug_mode
2513d9dcd5aeSmrg
2514ee3e8c14Smrg    # Option defaults:
2515ee3e8c14Smrg    opt_config=false
2516ee3e8c14Smrg    opt_dlopen=
2517ee3e8c14Smrg    opt_dry_run=false
2518ee3e8c14Smrg    opt_help=false
2519ee3e8c14Smrg    opt_mode=
25208f9fac4aSmrg    opt_reorder_cache=false
2521ee3e8c14Smrg    opt_preserve_dup_deps=false
2522ee3e8c14Smrg    opt_quiet=false
25238f9fac4aSmrg    opt_finishing=true
25248f9fac4aSmrg    opt_warning=
2525d9dcd5aeSmrg
2526ee3e8c14Smrg    nonopt=
2527ee3e8c14Smrg    preserve_args=
2528191cded7Smrg
2529ee3e8c14Smrg    _G_rc_lt_options_prep=:
2530191cded7Smrg
2531ee3e8c14Smrg    # Shorthand for --mode=foo, only valid as the first argument
2532ee3e8c14Smrg    case $1 in
2533ee3e8c14Smrg    clean|clea|cle|cl)
2534ee3e8c14Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2535ee3e8c14Smrg      ;;
2536ee3e8c14Smrg    compile|compil|compi|comp|com|co|c)
2537ee3e8c14Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2538ee3e8c14Smrg      ;;
2539ee3e8c14Smrg    execute|execut|execu|exec|exe|ex|e)
2540ee3e8c14Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2541ee3e8c14Smrg      ;;
2542ee3e8c14Smrg    finish|finis|fini|fin|fi|f)
2543ee3e8c14Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2544ee3e8c14Smrg      ;;
2545ee3e8c14Smrg    install|instal|insta|inst|ins|in|i)
2546ee3e8c14Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2547ee3e8c14Smrg      ;;
2548ee3e8c14Smrg    link|lin|li|l)
2549ee3e8c14Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2550ee3e8c14Smrg      ;;
2551ee3e8c14Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2552ee3e8c14Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2553ee3e8c14Smrg      ;;
2554ee3e8c14Smrg    *)
2555ee3e8c14Smrg      _G_rc_lt_options_prep=false
2556ee3e8c14Smrg      ;;
2557b290cf36Smrg    esac
2558b290cf36Smrg
2559ee3e8c14Smrg    if $_G_rc_lt_options_prep; then
2560ee3e8c14Smrg      # Pass back the list of options.
2561ee3e8c14Smrg      func_quote eval ${1+"$@"}
2562ee3e8c14Smrg      libtool_options_prep_result=$func_quote_result
2563ee3e8c14Smrg    fi
2564ee3e8c14Smrg}
2565ee3e8c14Smrgfunc_add_hook func_options_prep libtool_options_prep
2566d9dcd5aeSmrg
2567d9dcd5aeSmrg
2568ee3e8c14Smrg# libtool_parse_options [ARG]...
2569ee3e8c14Smrg# ---------------------------------
2570ee3e8c14Smrg# Provide handling for libtool specific options.
2571ee3e8c14Smrglibtool_parse_options ()
2572ee3e8c14Smrg{
2573ee3e8c14Smrg    $debug_cmd
2574b290cf36Smrg
2575ee3e8c14Smrg    _G_rc_lt_parse_options=false
2576191cded7Smrg
2577ee3e8c14Smrg    # Perform our own loop to consume as many options as possible in
2578ee3e8c14Smrg    # each iteration.
2579ee3e8c14Smrg    while test $# -gt 0; do
2580ee3e8c14Smrg      _G_match_lt_parse_options=:
2581ee3e8c14Smrg      _G_opt=$1
2582ee3e8c14Smrg      shift
2583ee3e8c14Smrg      case $_G_opt in
2584ee3e8c14Smrg        --dry-run|--dryrun|-n)
2585ee3e8c14Smrg                        opt_dry_run=:
2586ee3e8c14Smrg                        ;;
2587ee3e8c14Smrg
2588ee3e8c14Smrg        --config)       func_config ;;
2589ee3e8c14Smrg
2590ee3e8c14Smrg        --dlopen|-dlopen)
2591ee3e8c14Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2592ee3e8c14Smrg}$1"
2593ee3e8c14Smrg                        shift
2594ee3e8c14Smrg                        ;;
2595ee3e8c14Smrg
2596ee3e8c14Smrg        --preserve-dup-deps)
2597ee3e8c14Smrg                        opt_preserve_dup_deps=: ;;
2598ee3e8c14Smrg
2599ee3e8c14Smrg        --features)     func_features ;;
2600ee3e8c14Smrg
2601ee3e8c14Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2602ee3e8c14Smrg
2603ee3e8c14Smrg        --help)         opt_help=: ;;
2604ee3e8c14Smrg
2605ee3e8c14Smrg        --help-all)     opt_help=': help-all' ;;
2606ee3e8c14Smrg
2607ee3e8c14Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2608ee3e8c14Smrg                        opt_mode=$1
2609ee3e8c14Smrg                        case $1 in
2610ee3e8c14Smrg                          # Valid mode arguments:
2611ee3e8c14Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2612ee3e8c14Smrg
2613ee3e8c14Smrg                          # Catch anything else as an error
26148f9fac4aSmrg                          *) func_error "invalid argument '$1' for $_G_opt"
2615ee3e8c14Smrg                             exit_cmd=exit
2616ee3e8c14Smrg                             ;;
2617ee3e8c14Smrg                        esac
2618ee3e8c14Smrg                        shift
2619ee3e8c14Smrg                        ;;
2620ee3e8c14Smrg
26218f9fac4aSmrg        --no-finish)
26228f9fac4aSmrg                        opt_finishing=false
26238f9fac4aSmrg                        func_append preserve_args " $_G_opt"
26248f9fac4aSmrg                        ;;
26258f9fac4aSmrg
2626ee3e8c14Smrg        --no-silent|--no-quiet)
2627ee3e8c14Smrg                        opt_quiet=false
2628ee3e8c14Smrg                        func_append preserve_args " $_G_opt"
2629ee3e8c14Smrg                        ;;
2630ee3e8c14Smrg
2631ee3e8c14Smrg        --no-warnings|--no-warning|--no-warn)
2632ee3e8c14Smrg                        opt_warning=false
2633ee3e8c14Smrg                        func_append preserve_args " $_G_opt"
2634ee3e8c14Smrg                        ;;
2635ee3e8c14Smrg
2636ee3e8c14Smrg        --no-verbose)
2637ee3e8c14Smrg                        opt_verbose=false
2638ee3e8c14Smrg                        func_append preserve_args " $_G_opt"
2639ee3e8c14Smrg                        ;;
2640ee3e8c14Smrg
26418f9fac4aSmrg        --reorder-cache)
26428f9fac4aSmrg                        opt_reorder_cache=true
26438f9fac4aSmrg                        shared_lib_dirs=$1
26448f9fac4aSmrg                        if test -n "$shared_lib_dirs"; then
26458f9fac4aSmrg                          case $1 in
26468f9fac4aSmrg                            # Must begin with /:
26478f9fac4aSmrg                            /*) ;;
26488f9fac4aSmrg
26498f9fac4aSmrg                            # Catch anything else as an error (relative paths)
26508f9fac4aSmrg                            *) func_error "invalid argument '$1' for $_G_opt"
26518f9fac4aSmrg                               func_error "absolute paths are required for $_G_opt"
26528f9fac4aSmrg                               exit_cmd=exit
26538f9fac4aSmrg                               ;;
26548f9fac4aSmrg                          esac
26558f9fac4aSmrg                        fi
26568f9fac4aSmrg                        shift
26578f9fac4aSmrg                        ;;
26588f9fac4aSmrg
2659ee3e8c14Smrg        --silent|--quiet)
2660ee3e8c14Smrg                        opt_quiet=:
2661ee3e8c14Smrg                        opt_verbose=false
2662ee3e8c14Smrg                        func_append preserve_args " $_G_opt"
2663ee3e8c14Smrg                        ;;
2664ee3e8c14Smrg
2665ee3e8c14Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2666ee3e8c14Smrg                        opt_tag=$1
2667ee3e8c14Smrg                        func_append preserve_args " $_G_opt $1"
2668ee3e8c14Smrg                        func_enable_tag "$1"
2669ee3e8c14Smrg                        shift
2670ee3e8c14Smrg                        ;;
2671ee3e8c14Smrg
2672ee3e8c14Smrg        --verbose|-v)   opt_quiet=false
2673ee3e8c14Smrg                        opt_verbose=:
2674ee3e8c14Smrg                        func_append preserve_args " $_G_opt"
2675ee3e8c14Smrg                        ;;
2676ee3e8c14Smrg
2677ee3e8c14Smrg        # An option not handled by this hook function:
2678ee3e8c14Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2679ee3e8c14Smrg                        _G_match_lt_parse_options=false
2680ee3e8c14Smrg                        break
2681ee3e8c14Smrg                        ;;
2682ee3e8c14Smrg      esac
2683ee3e8c14Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2684ee3e8c14Smrg    done
2685b290cf36Smrg
2686ee3e8c14Smrg    if $_G_rc_lt_parse_options; then
2687ee3e8c14Smrg      # save modified positional parameters for caller
2688ee3e8c14Smrg      func_quote eval ${1+"$@"}
2689ee3e8c14Smrg      libtool_parse_options_result=$func_quote_result
2690b290cf36Smrg    fi
2691ee3e8c14Smrg}
2692ee3e8c14Smrgfunc_add_hook func_parse_options libtool_parse_options
2693b290cf36Smrg
2694b290cf36Smrg
26958f9fac4aSmrg# func_warning ARG...
26968f9fac4aSmrg# -------------------
26978f9fac4aSmrg# Libtool warnings are not categorized, so override funclib.sh
26988f9fac4aSmrg# func_warning with this simpler definition.
26998f9fac4aSmrgfunc_warning ()
27008f9fac4aSmrg{
27018f9fac4aSmrg    if $opt_warning; then
27028f9fac4aSmrg        $debug_cmd
27038f9fac4aSmrg        $warning_func ${1+"$@"}
27048f9fac4aSmrg    fi
27058f9fac4aSmrg}
27068f9fac4aSmrg
2707ee3e8c14Smrg
2708ee3e8c14Smrg# libtool_validate_options [ARG]...
2709ee3e8c14Smrg# ---------------------------------
2710ee3e8c14Smrg# Perform any sanity checks on option settings and/or unconsumed
2711ee3e8c14Smrg# arguments.
2712ee3e8c14Smrglibtool_validate_options ()
2713ee3e8c14Smrg{
2714ee3e8c14Smrg    # save first non-option argument
2715ee3e8c14Smrg    if test 0 -lt $#; then
2716ee3e8c14Smrg      nonopt=$1
2717ee3e8c14Smrg      shift
2718d9dcd5aeSmrg    fi
2719b290cf36Smrg
2720ee3e8c14Smrg    # preserve --debug
2721ee3e8c14Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2722ee3e8c14Smrg
27238f9fac4aSmrg    case $host_os in
2724ee3e8c14Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2725ee3e8c14Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
27268f9fac4aSmrg      cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*)
2727ee3e8c14Smrg        # don't eliminate duplications in $postdeps and $predeps
2728ee3e8c14Smrg        opt_duplicate_compiler_generated_deps=:
2729ee3e8c14Smrg        ;;
2730ee3e8c14Smrg      *)
2731ee3e8c14Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2732ee3e8c14Smrg        ;;
2733ee3e8c14Smrg    esac
2734ee3e8c14Smrg
2735ee3e8c14Smrg    $opt_help || {
2736ee3e8c14Smrg      # Sanity checks first:
2737ee3e8c14Smrg      func_check_version_match
2738ee3e8c14Smrg
2739ee3e8c14Smrg      test yes != "$build_libtool_libs" \
2740ee3e8c14Smrg        && test yes != "$build_old_libs" \
2741ee3e8c14Smrg        && func_fatal_configuration "not configured to build any kind of library"
2742b290cf36Smrg
2743ee3e8c14Smrg      # Darwin sucks
2744ee3e8c14Smrg      eval std_shrext=\"$shrext_cmds\"
2745ee3e8c14Smrg
2746ee3e8c14Smrg      # Only execute mode is allowed to have -dlopen flags.
2747ee3e8c14Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2748ee3e8c14Smrg        func_error "unrecognized option '-dlopen'"
2749ee3e8c14Smrg        $ECHO "$help" 1>&2
2750ee3e8c14Smrg        exit $EXIT_FAILURE
2751ee3e8c14Smrg      fi
2752ee3e8c14Smrg
2753ee3e8c14Smrg      # Change the help message to a mode-specific one.
2754ee3e8c14Smrg      generic_help=$help
2755ee3e8c14Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2756ee3e8c14Smrg    }
2757b290cf36Smrg
2758ee3e8c14Smrg    # Pass back the unparsed argument list
2759ee3e8c14Smrg    func_quote eval ${1+"$@"}
2760ee3e8c14Smrg    libtool_validate_options_result=$func_quote_result
2761d9dcd5aeSmrg}
2762ee3e8c14Smrgfunc_add_hook func_validate_options libtool_validate_options
2763b290cf36Smrg
2764b290cf36Smrg
2765ee3e8c14Smrg# Process options as early as possible so that --help and --version
2766ee3e8c14Smrg# can return quickly.
2767ee3e8c14Smrgfunc_options ${1+"$@"}
2768ee3e8c14Smrgeval set dummy "$func_options_result"; shift
2769ee3e8c14Smrg
2770191cded7Smrg
2771191cded7Smrg
2772d9dcd5aeSmrg## ----------- ##
2773d9dcd5aeSmrg##    Main.    ##
2774d9dcd5aeSmrg## ----------- ##
2775191cded7Smrg
2776ee3e8c14Smrgmagic='%%%MAGIC variable%%%'
2777ee3e8c14Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2778ee3e8c14Smrg
2779ee3e8c14Smrg# Global variables.
2780ee3e8c14Smrgextracted_archives=
2781ee3e8c14Smrgextracted_serial=0
2782ee3e8c14Smrg
2783ee3e8c14Smrg# If this variable is set in any of the actions, the command in it
2784ee3e8c14Smrg# will be execed at the end.  This prevents here-documents from being
2785ee3e8c14Smrg# left over by shells.
2786ee3e8c14Smrgexec_cmd=
2787ee3e8c14Smrg
2788ee3e8c14Smrg
2789ee3e8c14Smrg# A function that is used when there is no print builtin or printf.
2790ee3e8c14Smrgfunc_fallback_echo ()
2791ee3e8c14Smrg{
2792ee3e8c14Smrg  eval 'cat <<_LTECHO_EOF
2793ee3e8c14Smrg$1
2794ee3e8c14Smrg_LTECHO_EOF'
2795ee3e8c14Smrg}
2796ee3e8c14Smrg
2797ee3e8c14Smrg# func_generated_by_libtool
2798ee3e8c14Smrg# True iff stdin has been generated by Libtool. This function is only
2799ee3e8c14Smrg# a basic sanity check; it will hardly flush out determined imposters.
2800ee3e8c14Smrgfunc_generated_by_libtool_p ()
2801ee3e8c14Smrg{
2802ee3e8c14Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2803ee3e8c14Smrg}
2804ee3e8c14Smrg
2805b290cf36Smrg# func_lalib_p file
2806ee3e8c14Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2807b290cf36Smrg# This function is only a basic sanity check; it will hardly flush out
2808b290cf36Smrg# determined imposters.
2809b290cf36Smrgfunc_lalib_p ()
2810b290cf36Smrg{
2811b290cf36Smrg    test -f "$1" &&
2812ee3e8c14Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2813b290cf36Smrg}
2814191cded7Smrg
2815b290cf36Smrg# func_lalib_unsafe_p file
2816ee3e8c14Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2817b290cf36Smrg# This function implements the same check as func_lalib_p without
2818b290cf36Smrg# resorting to external programs.  To this end, it redirects stdin and
2819b290cf36Smrg# closes it afterwards, without saving the original file descriptor.
2820b290cf36Smrg# As a safety measure, use it only where a negative result would be
2821ee3e8c14Smrg# fatal anyway.  Works if 'file' does not exist.
2822b290cf36Smrgfunc_lalib_unsafe_p ()
2823b290cf36Smrg{
2824b290cf36Smrg    lalib_p=no
2825b290cf36Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2826b290cf36Smrg	for lalib_p_l in 1 2 3 4
2827b290cf36Smrg	do
2828b290cf36Smrg	    read lalib_p_line
2829ee3e8c14Smrg	    case $lalib_p_line in
2830b290cf36Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2831b290cf36Smrg	    esac
2832b290cf36Smrg	done
2833b290cf36Smrg	exec 0<&5 5<&-
2834b290cf36Smrg    fi
2835ee3e8c14Smrg    test yes = "$lalib_p"
2836b290cf36Smrg}
2837191cded7Smrg
2838b290cf36Smrg# func_ltwrapper_script_p file
2839b290cf36Smrg# True iff FILE is a libtool wrapper script
2840b290cf36Smrg# This function is only a basic sanity check; it will hardly flush out
2841b290cf36Smrg# determined imposters.
2842b290cf36Smrgfunc_ltwrapper_script_p ()
2843b290cf36Smrg{
2844ee3e8c14Smrg    test -f "$1" &&
2845ee3e8c14Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2846b290cf36Smrg}
2847191cded7Smrg
2848b290cf36Smrg# func_ltwrapper_executable_p file
2849b290cf36Smrg# True iff FILE is a libtool wrapper executable
2850b290cf36Smrg# This function is only a basic sanity check; it will hardly flush out
2851b290cf36Smrg# determined imposters.
2852b290cf36Smrgfunc_ltwrapper_executable_p ()
2853b290cf36Smrg{
2854b290cf36Smrg    func_ltwrapper_exec_suffix=
2855b290cf36Smrg    case $1 in
2856b290cf36Smrg    *.exe) ;;
2857b290cf36Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2858b290cf36Smrg    esac
2859b290cf36Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2860b290cf36Smrg}
2861191cded7Smrg
2862b290cf36Smrg# func_ltwrapper_scriptname file
2863b290cf36Smrg# Assumes file is an ltwrapper_executable
2864b290cf36Smrg# uses $file to determine the appropriate filename for a
2865b290cf36Smrg# temporary ltwrapper_script.
2866b290cf36Smrgfunc_ltwrapper_scriptname ()
2867b290cf36Smrg{
2868d9dcd5aeSmrg    func_dirname_and_basename "$1" "" "."
2869d9dcd5aeSmrg    func_stripname '' '.exe' "$func_basename_result"
2870ee3e8c14Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2871b290cf36Smrg}
2872191cded7Smrg
2873b290cf36Smrg# func_ltwrapper_p file
2874b290cf36Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2875b290cf36Smrg# This function is only a basic sanity check; it will hardly flush out
2876b290cf36Smrg# determined imposters.
2877b290cf36Smrgfunc_ltwrapper_p ()
2878b290cf36Smrg{
2879b290cf36Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2880b290cf36Smrg}
2881191cded7Smrg
2882191cded7Smrg
2883b290cf36Smrg# func_execute_cmds commands fail_cmd
2884b290cf36Smrg# Execute tilde-delimited COMMANDS.
2885b290cf36Smrg# If FAIL_CMD is given, eval that upon failure.
2886b290cf36Smrg# FAIL_CMD may read-access the current command in variable CMD!
2887b290cf36Smrgfunc_execute_cmds ()
2888b290cf36Smrg{
2889ee3e8c14Smrg    $debug_cmd
2890ee3e8c14Smrg
2891b290cf36Smrg    save_ifs=$IFS; IFS='~'
2892b290cf36Smrg    for cmd in $1; do
2893ee3e8c14Smrg      IFS=$sp$nl
2894b290cf36Smrg      eval cmd=\"$cmd\"
2895ee3e8c14Smrg      IFS=$save_ifs
2896b290cf36Smrg      func_show_eval "$cmd" "${2-:}"
2897b290cf36Smrg    done
2898b290cf36Smrg    IFS=$save_ifs
2899b290cf36Smrg}
2900b290cf36Smrg
2901b290cf36Smrg
2902b290cf36Smrg# func_source file
2903b290cf36Smrg# Source FILE, adding directory component if necessary.
2904b290cf36Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2905b290cf36Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2906b290cf36Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2907ee3e8c14Smrg# 'FILE.' does not work on cygwin managed mounts.
2908b290cf36Smrgfunc_source ()
2909b290cf36Smrg{
2910ee3e8c14Smrg    $debug_cmd
2911ee3e8c14Smrg
2912b290cf36Smrg    case $1 in
2913b290cf36Smrg    */* | *\\*)	. "$1" ;;
2914b290cf36Smrg    *)		. "./$1" ;;
2915b290cf36Smrg    esac
2916b290cf36Smrg}
2917b290cf36Smrg
2918b290cf36Smrg
2919d9dcd5aeSmrg# func_resolve_sysroot PATH
2920d9dcd5aeSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2921d9dcd5aeSmrg# func_resolve_sysroot_result
2922d9dcd5aeSmrgfunc_resolve_sysroot ()
2923d9dcd5aeSmrg{
2924d9dcd5aeSmrg  func_resolve_sysroot_result=$1
2925d9dcd5aeSmrg  case $func_resolve_sysroot_result in
2926d9dcd5aeSmrg  =*)
2927d9dcd5aeSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2928d9dcd5aeSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2929d9dcd5aeSmrg    ;;
2930d9dcd5aeSmrg  esac
2931d9dcd5aeSmrg}
2932d9dcd5aeSmrg
2933d9dcd5aeSmrg# func_replace_sysroot PATH
2934d9dcd5aeSmrg# If PATH begins with the sysroot, replace it with = and
2935d9dcd5aeSmrg# store the result into func_replace_sysroot_result.
2936d9dcd5aeSmrgfunc_replace_sysroot ()
2937d9dcd5aeSmrg{
2938ee3e8c14Smrg  case $lt_sysroot:$1 in
2939d9dcd5aeSmrg  ?*:"$lt_sysroot"*)
2940d9dcd5aeSmrg    func_stripname "$lt_sysroot" '' "$1"
2941ee3e8c14Smrg    func_replace_sysroot_result='='$func_stripname_result
2942d9dcd5aeSmrg    ;;
2943d9dcd5aeSmrg  *)
2944d9dcd5aeSmrg    # Including no sysroot.
2945d9dcd5aeSmrg    func_replace_sysroot_result=$1
2946d9dcd5aeSmrg    ;;
2947d9dcd5aeSmrg  esac
2948d9dcd5aeSmrg}
2949d9dcd5aeSmrg
2950b290cf36Smrg# func_infer_tag arg
2951b290cf36Smrg# Infer tagged configuration to use if any are available and
2952b290cf36Smrg# if one wasn't chosen via the "--tag" command line option.
2953b290cf36Smrg# Only attempt this if the compiler in the base compile
2954b290cf36Smrg# command doesn't match the default compiler.
2955b290cf36Smrg# arg is usually of the form 'gcc ...'
2956b290cf36Smrgfunc_infer_tag ()
2957b290cf36Smrg{
2958ee3e8c14Smrg    $debug_cmd
2959ee3e8c14Smrg
2960b290cf36Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2961b290cf36Smrg      CC_quoted=
2962b290cf36Smrg      for arg in $CC; do
2963d9dcd5aeSmrg	func_append_quoted CC_quoted "$arg"
2964b290cf36Smrg      done
2965ba064abeSmrg      CC_expanded=`func_echo_all $CC`
2966ba064abeSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2967b290cf36Smrg      case $@ in
2968b290cf36Smrg      # Blanks in the command may have been stripped by the calling shell,
2969b290cf36Smrg      # but not from the CC environment variable when configure was run.
2970ba064abeSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2971ba064abeSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2972b290cf36Smrg      # Blanks at the start of $base_compile will cause this to fail
2973b290cf36Smrg      # if we don't check for them as well.
2974b290cf36Smrg      *)
2975b290cf36Smrg	for z in $available_tags; do
2976b290cf36Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2977b290cf36Smrg	    # Evaluate the configuration.
2978ee3e8c14Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2979b290cf36Smrg	    CC_quoted=
2980b290cf36Smrg	    for arg in $CC; do
2981b290cf36Smrg	      # Double-quote args containing other shell metacharacters.
2982d9dcd5aeSmrg	      func_append_quoted CC_quoted "$arg"
2983b290cf36Smrg	    done
2984ba064abeSmrg	    CC_expanded=`func_echo_all $CC`
2985ba064abeSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2986b290cf36Smrg	    case "$@ " in
2987ba064abeSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2988ba064abeSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2989b290cf36Smrg	      # The compiler in the base compile command matches
2990b290cf36Smrg	      # the one in the tagged configuration.
2991b290cf36Smrg	      # Assume this is the tagged configuration we want.
2992b290cf36Smrg	      tagname=$z
2993b290cf36Smrg	      break
2994b290cf36Smrg	      ;;
2995191cded7Smrg	    esac
2996b290cf36Smrg	  fi
2997b290cf36Smrg	done
2998b290cf36Smrg	# If $tagname still isn't set, then no tagged configuration
2999b290cf36Smrg	# was found and let the user know that the "--tag" command
3000b290cf36Smrg	# line option must be used.
3001b290cf36Smrg	if test -z "$tagname"; then
3002b290cf36Smrg	  func_echo "unable to infer tagged configuration"
3003ee3e8c14Smrg	  func_fatal_error "specify a tag with '--tag'"
3004b290cf36Smrg#	else
3005b290cf36Smrg#	  func_verbose "using $tagname tagged configuration"
3006b290cf36Smrg	fi
3007b290cf36Smrg	;;
3008b290cf36Smrg      esac
3009b290cf36Smrg    fi
3010b290cf36Smrg}
3011b290cf36Smrg
3012b290cf36Smrg
3013d9dcd5aeSmrg
3014d9dcd5aeSmrg# func_write_libtool_object output_name pic_name nonpic_name
3015d9dcd5aeSmrg# Create a libtool object file (analogous to a ".la" file),
3016d9dcd5aeSmrg# but don't create it if we're doing a dry run.
3017d9dcd5aeSmrgfunc_write_libtool_object ()
3018d9dcd5aeSmrg{
3019ee3e8c14Smrg    write_libobj=$1
3020ee3e8c14Smrg    if test yes = "$build_libtool_libs"; then
3021ee3e8c14Smrg      write_lobj=\'$2\'
3022d9dcd5aeSmrg    else
3023d9dcd5aeSmrg      write_lobj=none
3024d9dcd5aeSmrg    fi
3025d9dcd5aeSmrg
3026ee3e8c14Smrg    if test yes = "$build_old_libs"; then
3027ee3e8c14Smrg      write_oldobj=\'$3\'
3028d9dcd5aeSmrg    else
3029d9dcd5aeSmrg      write_oldobj=none
3030d9dcd5aeSmrg    fi
3031d9dcd5aeSmrg
3032d9dcd5aeSmrg    $opt_dry_run || {
3033d9dcd5aeSmrg      cat >${write_libobj}T <<EOF
3034d9dcd5aeSmrg# $write_libobj - a libtool object file
3035ee3e8c14Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
3036d9dcd5aeSmrg#
3037d9dcd5aeSmrg# Please DO NOT delete this file!
3038d9dcd5aeSmrg# It is necessary for linking the library.
3039d9dcd5aeSmrg
3040d9dcd5aeSmrg# Name of the PIC object.
3041d9dcd5aeSmrgpic_object=$write_lobj
3042d9dcd5aeSmrg
3043d9dcd5aeSmrg# Name of the non-PIC object
3044d9dcd5aeSmrgnon_pic_object=$write_oldobj
3045d9dcd5aeSmrg
3046d9dcd5aeSmrgEOF
3047ee3e8c14Smrg      $MV "${write_libobj}T" "$write_libobj"
3048d9dcd5aeSmrg    }
3049d9dcd5aeSmrg}
3050d9dcd5aeSmrg
3051d9dcd5aeSmrg
3052d9dcd5aeSmrg##################################################
3053d9dcd5aeSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3054d9dcd5aeSmrg##################################################
3055d9dcd5aeSmrg
3056d9dcd5aeSmrg# func_convert_core_file_wine_to_w32 ARG
3057d9dcd5aeSmrg# Helper function used by file name conversion functions when $build is *nix,
30588f9fac4aSmrg# and $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
3059d9dcd5aeSmrg# correctly configured wine environment available, with the winepath program
3060d9dcd5aeSmrg# in $build's $PATH.
3061d9dcd5aeSmrg#
3062d9dcd5aeSmrg# ARG is the $build file name to be converted to w32 format.
3063d9dcd5aeSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3064d9dcd5aeSmrg# be empty on error (or when ARG is empty)
3065d9dcd5aeSmrgfunc_convert_core_file_wine_to_w32 ()
3066d9dcd5aeSmrg{
3067ee3e8c14Smrg  $debug_cmd
3068ee3e8c14Smrg
3069ee3e8c14Smrg  func_convert_core_file_wine_to_w32_result=$1
3070d9dcd5aeSmrg  if test -n "$1"; then
3071d9dcd5aeSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3072d9dcd5aeSmrg    # are forced to check the contents of stdout. On the other hand, if the
3073d9dcd5aeSmrg    # command is not found, the shell will set an exit code of 127 and print
3074d9dcd5aeSmrg    # *an error message* to stdout. So we must check for both error code of
3075d9dcd5aeSmrg    # zero AND non-empty stdout, which explains the odd construction:
3076d9dcd5aeSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3077ee3e8c14Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3078d9dcd5aeSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3079ee3e8c14Smrg        $SED -e "$sed_naive_backslashify"`
3080d9dcd5aeSmrg    else
3081d9dcd5aeSmrg      func_convert_core_file_wine_to_w32_result=
3082d9dcd5aeSmrg    fi
3083d9dcd5aeSmrg  fi
3084d9dcd5aeSmrg}
3085d9dcd5aeSmrg# end: func_convert_core_file_wine_to_w32
3086d9dcd5aeSmrg
3087d9dcd5aeSmrg
3088d9dcd5aeSmrg# func_convert_core_path_wine_to_w32 ARG
3089d9dcd5aeSmrg# Helper function used by path conversion functions when $build is *nix, and
30908f9fac4aSmrg# $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
30918f9fac4aSmrg# correctly configured wine environment available, with the winepath program
30928f9fac4aSmrg# in $build's $PATH. Assumes ARG has no leading or trailing path separator
30938f9fac4aSmrg# characters.
3094d9dcd5aeSmrg#
3095d9dcd5aeSmrg# ARG is path to be converted from $build format to win32.
3096d9dcd5aeSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3097d9dcd5aeSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3098d9dcd5aeSmrg# are convertible, then the result may be empty.
3099d9dcd5aeSmrgfunc_convert_core_path_wine_to_w32 ()
3100d9dcd5aeSmrg{
3101ee3e8c14Smrg  $debug_cmd
3102ee3e8c14Smrg
3103d9dcd5aeSmrg  # unfortunately, winepath doesn't convert paths, only file names
3104ee3e8c14Smrg  func_convert_core_path_wine_to_w32_result=
3105d9dcd5aeSmrg  if test -n "$1"; then
3106d9dcd5aeSmrg    oldIFS=$IFS
3107d9dcd5aeSmrg    IFS=:
3108d9dcd5aeSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3109d9dcd5aeSmrg      IFS=$oldIFS
3110d9dcd5aeSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3111ee3e8c14Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3112d9dcd5aeSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3113ee3e8c14Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3114d9dcd5aeSmrg        else
3115d9dcd5aeSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3116d9dcd5aeSmrg        fi
3117d9dcd5aeSmrg      fi
3118d9dcd5aeSmrg    done
3119d9dcd5aeSmrg    IFS=$oldIFS
3120d9dcd5aeSmrg  fi
3121d9dcd5aeSmrg}
3122d9dcd5aeSmrg# end: func_convert_core_path_wine_to_w32
3123d9dcd5aeSmrg
3124d9dcd5aeSmrg
3125d9dcd5aeSmrg# func_cygpath ARGS...
3126d9dcd5aeSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3127d9dcd5aeSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3128d9dcd5aeSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3129d9dcd5aeSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3130d9dcd5aeSmrg# file name or path is assumed to be in w32 format, as previously converted
3131d9dcd5aeSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3132d9dcd5aeSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3133d9dcd5aeSmrg# Cygwin format). Returns an empty string on error.
3134d9dcd5aeSmrg#
3135d9dcd5aeSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3136d9dcd5aeSmrg# be converted.
3137d9dcd5aeSmrg#
3138d9dcd5aeSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3139d9dcd5aeSmrg# environment variable; do not put it in $PATH.
3140d9dcd5aeSmrgfunc_cygpath ()
3141d9dcd5aeSmrg{
3142ee3e8c14Smrg  $debug_cmd
3143ee3e8c14Smrg
3144d9dcd5aeSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3145d9dcd5aeSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3146d9dcd5aeSmrg    if test "$?" -ne 0; then
3147d9dcd5aeSmrg      # on failure, ensure result is empty
3148d9dcd5aeSmrg      func_cygpath_result=
3149d9dcd5aeSmrg    fi
3150d9dcd5aeSmrg  else
3151d9dcd5aeSmrg    func_cygpath_result=
3152ee3e8c14Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3153d9dcd5aeSmrg  fi
3154d9dcd5aeSmrg}
3155d9dcd5aeSmrg#end: func_cygpath
3156d9dcd5aeSmrg
3157d9dcd5aeSmrg
3158d9dcd5aeSmrg# func_convert_core_msys_to_w32 ARG
3159d9dcd5aeSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3160d9dcd5aeSmrg# result in func_convert_core_msys_to_w32_result.
3161d9dcd5aeSmrgfunc_convert_core_msys_to_w32 ()
3162d9dcd5aeSmrg{
3163ee3e8c14Smrg  $debug_cmd
3164ee3e8c14Smrg
3165d9dcd5aeSmrg  # awkward: cmd appends spaces to result
3166d9dcd5aeSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3167ee3e8c14Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3168d9dcd5aeSmrg}
3169d9dcd5aeSmrg#end: func_convert_core_msys_to_w32
3170d9dcd5aeSmrg
3171d9dcd5aeSmrg
3172d9dcd5aeSmrg# func_convert_file_check ARG1 ARG2
3173d9dcd5aeSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3174d9dcd5aeSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3175d9dcd5aeSmrg# func_to_host_file_result to ARG1).
3176d9dcd5aeSmrgfunc_convert_file_check ()
3177d9dcd5aeSmrg{
3178ee3e8c14Smrg  $debug_cmd
3179ee3e8c14Smrg
3180ee3e8c14Smrg  if test -z "$2" && test -n "$1"; then
3181d9dcd5aeSmrg    func_error "Could not determine host file name corresponding to"
3182ee3e8c14Smrg    func_error "  '$1'"
3183d9dcd5aeSmrg    func_error "Continuing, but uninstalled executables may not work."
3184d9dcd5aeSmrg    # Fallback:
3185ee3e8c14Smrg    func_to_host_file_result=$1
3186d9dcd5aeSmrg  fi
3187d9dcd5aeSmrg}
3188d9dcd5aeSmrg# end func_convert_file_check
3189d9dcd5aeSmrg
3190d9dcd5aeSmrg
3191d9dcd5aeSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3192d9dcd5aeSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3193d9dcd5aeSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3194d9dcd5aeSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3195d9dcd5aeSmrgfunc_convert_path_check ()
3196d9dcd5aeSmrg{
3197ee3e8c14Smrg  $debug_cmd
3198ee3e8c14Smrg
3199d9dcd5aeSmrg  if test -z "$4" && test -n "$3"; then
3200d9dcd5aeSmrg    func_error "Could not determine the host path corresponding to"
3201ee3e8c14Smrg    func_error "  '$3'"
3202d9dcd5aeSmrg    func_error "Continuing, but uninstalled executables may not work."
3203d9dcd5aeSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3204d9dcd5aeSmrg    # should not be "improved".  See libtool.info.
3205d9dcd5aeSmrg    if test "x$1" != "x$2"; then
3206d9dcd5aeSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3207d9dcd5aeSmrg      func_to_host_path_result=`echo "$3" |
3208d9dcd5aeSmrg        $SED -e "$lt_replace_pathsep_chars"`
3209d9dcd5aeSmrg    else
3210ee3e8c14Smrg      func_to_host_path_result=$3
3211d9dcd5aeSmrg    fi
3212d9dcd5aeSmrg  fi
3213d9dcd5aeSmrg}
3214d9dcd5aeSmrg# end func_convert_path_check
3215d9dcd5aeSmrg
3216d9dcd5aeSmrg
3217d9dcd5aeSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3218d9dcd5aeSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3219d9dcd5aeSmrg# and appending REPL if ORIG matches BACKPAT.
3220d9dcd5aeSmrgfunc_convert_path_front_back_pathsep ()
3221d9dcd5aeSmrg{
3222ee3e8c14Smrg  $debug_cmd
3223ee3e8c14Smrg
3224d9dcd5aeSmrg  case $4 in
3225ee3e8c14Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3226d9dcd5aeSmrg    ;;
3227d9dcd5aeSmrg  esac
3228d9dcd5aeSmrg  case $4 in
3229d9dcd5aeSmrg  $2 ) func_append func_to_host_path_result "$3"
3230d9dcd5aeSmrg    ;;
3231d9dcd5aeSmrg  esac
3232d9dcd5aeSmrg}
3233d9dcd5aeSmrg# end func_convert_path_front_back_pathsep
3234d9dcd5aeSmrg
3235d9dcd5aeSmrg
32368f9fac4aSmrg# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER
32378f9fac4aSmrg# Replaces a delimiter for a given path.
32388f9fac4aSmrgfunc_convert_delimited_path ()
32398f9fac4aSmrg{
32408f9fac4aSmrg	converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"`
32418f9fac4aSmrg}
32428f9fac4aSmrg# end func_convert_delimited_path
32438f9fac4aSmrg
32448f9fac4aSmrg
3245d9dcd5aeSmrg##################################################
3246d9dcd5aeSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3247d9dcd5aeSmrg##################################################
3248ee3e8c14Smrg# invoked via '$to_host_file_cmd ARG'
3249d9dcd5aeSmrg#
3250d9dcd5aeSmrg# In each case, ARG is the path to be converted from $build to $host format.
3251d9dcd5aeSmrg# Result will be available in $func_to_host_file_result.
3252d9dcd5aeSmrg
3253d9dcd5aeSmrg
3254d9dcd5aeSmrg# func_to_host_file ARG
3255d9dcd5aeSmrg# Converts the file name ARG from $build format to $host format. Return result
3256d9dcd5aeSmrg# in func_to_host_file_result.
3257d9dcd5aeSmrgfunc_to_host_file ()
3258d9dcd5aeSmrg{
3259ee3e8c14Smrg  $debug_cmd
3260ee3e8c14Smrg
3261d9dcd5aeSmrg  $to_host_file_cmd "$1"
3262d9dcd5aeSmrg}
3263d9dcd5aeSmrg# end func_to_host_file
3264d9dcd5aeSmrg
3265d9dcd5aeSmrg
3266d9dcd5aeSmrg# func_to_tool_file ARG LAZY
3267d9dcd5aeSmrg# converts the file name ARG from $build format to toolchain format. Return
3268d9dcd5aeSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3269d9dcd5aeSmrg# in (the comma separated) LAZY, no conversion takes place.
3270d9dcd5aeSmrgfunc_to_tool_file ()
3271d9dcd5aeSmrg{
3272ee3e8c14Smrg  $debug_cmd
3273ee3e8c14Smrg
3274d9dcd5aeSmrg  case ,$2, in
3275d9dcd5aeSmrg    *,"$to_tool_file_cmd",*)
3276d9dcd5aeSmrg      func_to_tool_file_result=$1
3277d9dcd5aeSmrg      ;;
3278d9dcd5aeSmrg    *)
3279d9dcd5aeSmrg      $to_tool_file_cmd "$1"
3280d9dcd5aeSmrg      func_to_tool_file_result=$func_to_host_file_result
3281d9dcd5aeSmrg      ;;
3282d9dcd5aeSmrg  esac
3283d9dcd5aeSmrg}
3284d9dcd5aeSmrg# end func_to_tool_file
3285d9dcd5aeSmrg
3286d9dcd5aeSmrg
3287d9dcd5aeSmrg# func_convert_file_noop ARG
3288d9dcd5aeSmrg# Copy ARG to func_to_host_file_result.
3289d9dcd5aeSmrgfunc_convert_file_noop ()
3290d9dcd5aeSmrg{
3291ee3e8c14Smrg  func_to_host_file_result=$1
3292d9dcd5aeSmrg}
3293d9dcd5aeSmrg# end func_convert_file_noop
3294d9dcd5aeSmrg
3295d9dcd5aeSmrg
3296d9dcd5aeSmrg# func_convert_file_msys_to_w32 ARG
3297d9dcd5aeSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3298d9dcd5aeSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3299d9dcd5aeSmrg# func_to_host_file_result.
3300d9dcd5aeSmrgfunc_convert_file_msys_to_w32 ()
3301d9dcd5aeSmrg{
3302ee3e8c14Smrg  $debug_cmd
3303ee3e8c14Smrg
3304ee3e8c14Smrg  func_to_host_file_result=$1
3305d9dcd5aeSmrg  if test -n "$1"; then
3306d9dcd5aeSmrg    func_convert_core_msys_to_w32 "$1"
3307ee3e8c14Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3308d9dcd5aeSmrg  fi
3309d9dcd5aeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3310d9dcd5aeSmrg}
3311d9dcd5aeSmrg# end func_convert_file_msys_to_w32
3312d9dcd5aeSmrg
3313d9dcd5aeSmrg
3314d9dcd5aeSmrg# func_convert_file_cygwin_to_w32 ARG
3315d9dcd5aeSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3316d9dcd5aeSmrg# func_to_host_file_result.
3317d9dcd5aeSmrgfunc_convert_file_cygwin_to_w32 ()
3318d9dcd5aeSmrg{
3319ee3e8c14Smrg  $debug_cmd
3320ee3e8c14Smrg
3321ee3e8c14Smrg  func_to_host_file_result=$1
3322d9dcd5aeSmrg  if test -n "$1"; then
3323d9dcd5aeSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3324d9dcd5aeSmrg    # LT_CYGPATH in this case.
3325d9dcd5aeSmrg    func_to_host_file_result=`cygpath -m "$1"`
3326d9dcd5aeSmrg  fi
3327d9dcd5aeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3328d9dcd5aeSmrg}
3329d9dcd5aeSmrg# end func_convert_file_cygwin_to_w32
3330d9dcd5aeSmrg
3331d9dcd5aeSmrg
3332d9dcd5aeSmrg# func_convert_file_nix_to_w32 ARG
3333d9dcd5aeSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3334d9dcd5aeSmrg# and a working winepath. Returns result in func_to_host_file_result.
3335d9dcd5aeSmrgfunc_convert_file_nix_to_w32 ()
3336d9dcd5aeSmrg{
3337ee3e8c14Smrg  $debug_cmd
3338ee3e8c14Smrg
3339ee3e8c14Smrg  func_to_host_file_result=$1
3340d9dcd5aeSmrg  if test -n "$1"; then
3341d9dcd5aeSmrg    func_convert_core_file_wine_to_w32 "$1"
3342ee3e8c14Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3343d9dcd5aeSmrg  fi
3344d9dcd5aeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3345d9dcd5aeSmrg}
3346d9dcd5aeSmrg# end func_convert_file_nix_to_w32
3347d9dcd5aeSmrg
3348d9dcd5aeSmrg
3349d9dcd5aeSmrg# func_convert_file_msys_to_cygwin ARG
3350d9dcd5aeSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3351d9dcd5aeSmrg# Returns result in func_to_host_file_result.
3352d9dcd5aeSmrgfunc_convert_file_msys_to_cygwin ()
3353d9dcd5aeSmrg{
3354ee3e8c14Smrg  $debug_cmd
3355ee3e8c14Smrg
3356ee3e8c14Smrg  func_to_host_file_result=$1
3357d9dcd5aeSmrg  if test -n "$1"; then
3358d9dcd5aeSmrg    func_convert_core_msys_to_w32 "$1"
3359d9dcd5aeSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3360ee3e8c14Smrg    func_to_host_file_result=$func_cygpath_result
3361d9dcd5aeSmrg  fi
3362d9dcd5aeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3363d9dcd5aeSmrg}
3364d9dcd5aeSmrg# end func_convert_file_msys_to_cygwin
3365d9dcd5aeSmrg
3366d9dcd5aeSmrg
3367d9dcd5aeSmrg# func_convert_file_nix_to_cygwin ARG
3368d9dcd5aeSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3369d9dcd5aeSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3370d9dcd5aeSmrg# in func_to_host_file_result.
3371d9dcd5aeSmrgfunc_convert_file_nix_to_cygwin ()
3372d9dcd5aeSmrg{
3373ee3e8c14Smrg  $debug_cmd
3374ee3e8c14Smrg
3375ee3e8c14Smrg  func_to_host_file_result=$1
3376d9dcd5aeSmrg  if test -n "$1"; then
3377d9dcd5aeSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3378d9dcd5aeSmrg    func_convert_core_file_wine_to_w32 "$1"
3379d9dcd5aeSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3380ee3e8c14Smrg    func_to_host_file_result=$func_cygpath_result
3381d9dcd5aeSmrg  fi
3382d9dcd5aeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3383d9dcd5aeSmrg}
3384d9dcd5aeSmrg# end func_convert_file_nix_to_cygwin
3385d9dcd5aeSmrg
3386d9dcd5aeSmrg
3387d9dcd5aeSmrg#############################################
3388d9dcd5aeSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3389d9dcd5aeSmrg#############################################
3390ee3e8c14Smrg# invoked via '$to_host_path_cmd ARG'
3391d9dcd5aeSmrg#
3392d9dcd5aeSmrg# In each case, ARG is the path to be converted from $build to $host format.
3393d9dcd5aeSmrg# The result will be available in $func_to_host_path_result.
3394d9dcd5aeSmrg#
3395d9dcd5aeSmrg# Path separators are also converted from $build format to $host format.  If
3396d9dcd5aeSmrg# ARG begins or ends with a path separator character, it is preserved (but
3397d9dcd5aeSmrg# converted to $host format) on output.
3398d9dcd5aeSmrg#
3399d9dcd5aeSmrg# All path conversion functions are named using the following convention:
3400d9dcd5aeSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3401d9dcd5aeSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3402d9dcd5aeSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3403d9dcd5aeSmrg# same.  If conversion functions are added for new $build/$host combinations,
3404d9dcd5aeSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3405d9dcd5aeSmrg# will break.
3406d9dcd5aeSmrg
3407d9dcd5aeSmrg
3408d9dcd5aeSmrg# func_init_to_host_path_cmd
3409d9dcd5aeSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3410d9dcd5aeSmrg# appropriate value, based on the value of $to_host_file_cmd.
3411d9dcd5aeSmrgto_host_path_cmd=
3412d9dcd5aeSmrgfunc_init_to_host_path_cmd ()
3413d9dcd5aeSmrg{
3414ee3e8c14Smrg  $debug_cmd
3415ee3e8c14Smrg
3416d9dcd5aeSmrg  if test -z "$to_host_path_cmd"; then
3417d9dcd5aeSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3418ee3e8c14Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3419d9dcd5aeSmrg  fi
3420d9dcd5aeSmrg}
3421d9dcd5aeSmrg
3422d9dcd5aeSmrg
3423d9dcd5aeSmrg# func_to_host_path ARG
3424d9dcd5aeSmrg# Converts the path ARG from $build format to $host format. Return result
3425d9dcd5aeSmrg# in func_to_host_path_result.
3426d9dcd5aeSmrgfunc_to_host_path ()
3427d9dcd5aeSmrg{
3428ee3e8c14Smrg  $debug_cmd
3429ee3e8c14Smrg
3430d9dcd5aeSmrg  func_init_to_host_path_cmd
3431d9dcd5aeSmrg  $to_host_path_cmd "$1"
3432d9dcd5aeSmrg}
3433d9dcd5aeSmrg# end func_to_host_path
3434d9dcd5aeSmrg
3435d9dcd5aeSmrg
3436d9dcd5aeSmrg# func_convert_path_noop ARG
3437d9dcd5aeSmrg# Copy ARG to func_to_host_path_result.
3438d9dcd5aeSmrgfunc_convert_path_noop ()
3439d9dcd5aeSmrg{
3440ee3e8c14Smrg  func_to_host_path_result=$1
3441d9dcd5aeSmrg}
3442d9dcd5aeSmrg# end func_convert_path_noop
3443d9dcd5aeSmrg
3444d9dcd5aeSmrg
3445d9dcd5aeSmrg# func_convert_path_msys_to_w32 ARG
3446d9dcd5aeSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3447d9dcd5aeSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3448d9dcd5aeSmrg# func_to_host_path_result.
3449d9dcd5aeSmrgfunc_convert_path_msys_to_w32 ()
3450d9dcd5aeSmrg{
3451ee3e8c14Smrg  $debug_cmd
3452ee3e8c14Smrg
3453ee3e8c14Smrg  func_to_host_path_result=$1
3454d9dcd5aeSmrg  if test -n "$1"; then
3455d9dcd5aeSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3456d9dcd5aeSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3457d9dcd5aeSmrg    # and winepath ignores them completely.
3458d9dcd5aeSmrg    func_stripname : : "$1"
3459d9dcd5aeSmrg    func_to_host_path_tmp1=$func_stripname_result
3460d9dcd5aeSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3461ee3e8c14Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3462d9dcd5aeSmrg    func_convert_path_check : ";" \
3463d9dcd5aeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3464d9dcd5aeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3465d9dcd5aeSmrg  fi
3466d9dcd5aeSmrg}
3467d9dcd5aeSmrg# end func_convert_path_msys_to_w32
3468d9dcd5aeSmrg
3469d9dcd5aeSmrg
3470d9dcd5aeSmrg# func_convert_path_cygwin_to_w32 ARG
3471d9dcd5aeSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3472d9dcd5aeSmrg# func_to_host_file_result.
3473d9dcd5aeSmrgfunc_convert_path_cygwin_to_w32 ()
3474d9dcd5aeSmrg{
3475ee3e8c14Smrg  $debug_cmd
3476ee3e8c14Smrg
3477ee3e8c14Smrg  func_to_host_path_result=$1
3478d9dcd5aeSmrg  if test -n "$1"; then
3479d9dcd5aeSmrg    # See func_convert_path_msys_to_w32:
3480d9dcd5aeSmrg    func_stripname : : "$1"
3481d9dcd5aeSmrg    func_to_host_path_tmp1=$func_stripname_result
3482d9dcd5aeSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3483d9dcd5aeSmrg    func_convert_path_check : ";" \
3484d9dcd5aeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3485d9dcd5aeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3486d9dcd5aeSmrg  fi
3487d9dcd5aeSmrg}
3488d9dcd5aeSmrg# end func_convert_path_cygwin_to_w32
3489d9dcd5aeSmrg
3490d9dcd5aeSmrg
3491d9dcd5aeSmrg# func_convert_path_nix_to_w32 ARG
3492d9dcd5aeSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3493d9dcd5aeSmrg# a working winepath.  Returns result in func_to_host_file_result.
3494d9dcd5aeSmrgfunc_convert_path_nix_to_w32 ()
3495b290cf36Smrg{
3496ee3e8c14Smrg  $debug_cmd
3497ee3e8c14Smrg
3498ee3e8c14Smrg  func_to_host_path_result=$1
3499d9dcd5aeSmrg  if test -n "$1"; then
3500d9dcd5aeSmrg    # See func_convert_path_msys_to_w32:
3501d9dcd5aeSmrg    func_stripname : : "$1"
3502d9dcd5aeSmrg    func_to_host_path_tmp1=$func_stripname_result
3503d9dcd5aeSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3504ee3e8c14Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3505d9dcd5aeSmrg    func_convert_path_check : ";" \
3506d9dcd5aeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3507d9dcd5aeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3508d9dcd5aeSmrg  fi
3509d9dcd5aeSmrg}
3510d9dcd5aeSmrg# end func_convert_path_nix_to_w32
3511b290cf36Smrg
3512b290cf36Smrg
3513d9dcd5aeSmrg# func_convert_path_msys_to_cygwin ARG
3514d9dcd5aeSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3515d9dcd5aeSmrg# Returns result in func_to_host_file_result.
3516d9dcd5aeSmrgfunc_convert_path_msys_to_cygwin ()
3517d9dcd5aeSmrg{
3518ee3e8c14Smrg  $debug_cmd
3519ee3e8c14Smrg
3520ee3e8c14Smrg  func_to_host_path_result=$1
3521d9dcd5aeSmrg  if test -n "$1"; then
3522d9dcd5aeSmrg    # See func_convert_path_msys_to_w32:
3523d9dcd5aeSmrg    func_stripname : : "$1"
3524d9dcd5aeSmrg    func_to_host_path_tmp1=$func_stripname_result
3525d9dcd5aeSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3526d9dcd5aeSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3527ee3e8c14Smrg    func_to_host_path_result=$func_cygpath_result
3528d9dcd5aeSmrg    func_convert_path_check : : \
3529d9dcd5aeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3530d9dcd5aeSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3531d9dcd5aeSmrg  fi
3532d9dcd5aeSmrg}
3533d9dcd5aeSmrg# end func_convert_path_msys_to_cygwin
3534b290cf36Smrg
3535b290cf36Smrg
3536d9dcd5aeSmrg# func_convert_path_nix_to_cygwin ARG
3537d9dcd5aeSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3538d9dcd5aeSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3539d9dcd5aeSmrg# func_to_host_file_result.
3540d9dcd5aeSmrgfunc_convert_path_nix_to_cygwin ()
3541d9dcd5aeSmrg{
3542ee3e8c14Smrg  $debug_cmd
3543ee3e8c14Smrg
3544ee3e8c14Smrg  func_to_host_path_result=$1
3545d9dcd5aeSmrg  if test -n "$1"; then
3546d9dcd5aeSmrg    # Remove leading and trailing path separator characters from
3547d9dcd5aeSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3548d9dcd5aeSmrg    # into '.;' and ';.', and winepath ignores them completely.
3549d9dcd5aeSmrg    func_stripname : : "$1"
3550d9dcd5aeSmrg    func_to_host_path_tmp1=$func_stripname_result
3551d9dcd5aeSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3552d9dcd5aeSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3553ee3e8c14Smrg    func_to_host_path_result=$func_cygpath_result
3554d9dcd5aeSmrg    func_convert_path_check : : \
3555d9dcd5aeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3556d9dcd5aeSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3557d9dcd5aeSmrg  fi
3558b290cf36Smrg}
3559d9dcd5aeSmrg# end func_convert_path_nix_to_cygwin
3560d9dcd5aeSmrg
3561b290cf36Smrg
3562ee3e8c14Smrg# func_dll_def_p FILE
3563ee3e8c14Smrg# True iff FILE is a Windows DLL '.def' file.
3564ee3e8c14Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3565ee3e8c14Smrgfunc_dll_def_p ()
3566ee3e8c14Smrg{
3567ee3e8c14Smrg  $debug_cmd
3568ee3e8c14Smrg
3569ee3e8c14Smrg  func_dll_def_p_tmp=`$SED -n \
3570ee3e8c14Smrg    -e 's/^[	 ]*//' \
3571ee3e8c14Smrg    -e '/^\(;.*\)*$/d' \
3572ee3e8c14Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3573ee3e8c14Smrg    -e q \
3574ee3e8c14Smrg    "$1"`
3575ee3e8c14Smrg  test DEF = "$func_dll_def_p_tmp"
3576ee3e8c14Smrg}
3577ee3e8c14Smrg
3578ee3e8c14Smrg
35798f9fac4aSmrg# func_reorder_shared_lib_cache DIRS
35808f9fac4aSmrg# Reorder the shared library cache by unconfiguring previous shared library cache
35818f9fac4aSmrg# and configuring preferred search directories before previous search directories.
35828f9fac4aSmrg# Previous shared library cache: /usr/lib /usr/local/lib
35838f9fac4aSmrg# Preferred search directories: /tmp/testing
35848f9fac4aSmrg# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib
35858f9fac4aSmrgfunc_reorder_shared_lib_cache ()
35868f9fac4aSmrg{
35878f9fac4aSmrg	$debug_cmd
35888f9fac4aSmrg
35898f9fac4aSmrg	case $host_os in
35908f9fac4aSmrg	  openbsd*)
35918f9fac4aSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
35928f9fac4aSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
35938f9fac4aSmrg	    save_search_directories=$converted_path
35948f9fac4aSmrg	    func_convert_delimited_path "$1" ':' '\ '
35958f9fac4aSmrg
35968f9fac4aSmrg	    # Ensure directories exist
35978f9fac4aSmrg	    for dir in $converted_path; do
35988f9fac4aSmrg	      # Ensure each directory is an absolute path
35998f9fac4aSmrg	      case $dir in
36008f9fac4aSmrg	        /*) ;;
36018f9fac4aSmrg	        *) func_error "Directory '$dir' is not an absolute path"
36028f9fac4aSmrg	           exit $EXIT_FAILURE ;;
36038f9fac4aSmrg	      esac
36048f9fac4aSmrg	      # Ensure no trailing slashes
36058f9fac4aSmrg	      func_stripname '' '/' "$dir"
36068f9fac4aSmrg	      dir=$func_stripname_result
36078f9fac4aSmrg	      if test -d "$dir"; then
36088f9fac4aSmrg	        if test -n "$preferred_search_directories"; then
36098f9fac4aSmrg	          preferred_search_directories="$preferred_search_directories $dir"
36108f9fac4aSmrg	        else
36118f9fac4aSmrg	          preferred_search_directories=$dir
36128f9fac4aSmrg	        fi
36138f9fac4aSmrg	      else
36148f9fac4aSmrg	        func_error "Directory '$dir' does not exist"
36158f9fac4aSmrg	        exit $EXIT_FAILURE
36168f9fac4aSmrg	      fi
36178f9fac4aSmrg	    done
36188f9fac4aSmrg
36198f9fac4aSmrg	    PATH="$PATH:/sbin" ldconfig -U $save_search_directories
36208f9fac4aSmrg	    PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories
36218f9fac4aSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
36228f9fac4aSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
36238f9fac4aSmrg	    reordered_search_directories=$converted_path
36248f9fac4aSmrg
36258f9fac4aSmrg	    $ECHO "Original: $save_search_directories"
36268f9fac4aSmrg	    $ECHO "Reordered: $reordered_search_directories"
36278f9fac4aSmrg	    exit $EXIT_SUCCESS
36288f9fac4aSmrg	  ;;
36298f9fac4aSmrg	  *)
36308f9fac4aSmrg	    func_error "--reorder-cache is not supported for host_os=$host_os."
36318f9fac4aSmrg	    exit $EXIT_FAILURE
36328f9fac4aSmrg	  ;;
36338f9fac4aSmrg	esac
36348f9fac4aSmrg}
36358f9fac4aSmrg# end func_reorder_shared_lib_cache
36368f9fac4aSmrg
36378f9fac4aSmrg
3638b290cf36Smrg# func_mode_compile arg...
3639b290cf36Smrgfunc_mode_compile ()
3640b290cf36Smrg{
3641ee3e8c14Smrg    $debug_cmd
3642ee3e8c14Smrg
3643b290cf36Smrg    # Get the compilation command and the source file.
3644b290cf36Smrg    base_compile=
3645ee3e8c14Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3646b290cf36Smrg    suppress_opt=yes
3647b290cf36Smrg    suppress_output=
3648b290cf36Smrg    arg_mode=normal
3649b290cf36Smrg    libobj=
3650b290cf36Smrg    later=
3651b290cf36Smrg    pie_flag=
3652b290cf36Smrg
3653b290cf36Smrg    for arg
3654b290cf36Smrg    do
3655b290cf36Smrg      case $arg_mode in
3656b290cf36Smrg      arg  )
3657b290cf36Smrg	# do not "continue".  Instead, add this to base_compile
3658ee3e8c14Smrg	lastarg=$arg
3659b290cf36Smrg	arg_mode=normal
3660b290cf36Smrg	;;
3661b290cf36Smrg
3662b290cf36Smrg      target )
3663ee3e8c14Smrg	libobj=$arg
3664b290cf36Smrg	arg_mode=normal
3665b290cf36Smrg	continue
3666b290cf36Smrg	;;
3667b290cf36Smrg
3668b290cf36Smrg      normal )
3669b290cf36Smrg	# Accept any command-line options.
3670b290cf36Smrg	case $arg in
3671b290cf36Smrg	-o)
3672b290cf36Smrg	  test -n "$libobj" && \
3673ee3e8c14Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3674b290cf36Smrg	  arg_mode=target
3675b290cf36Smrg	  continue
3676b290cf36Smrg	  ;;
3677b290cf36Smrg
3678b290cf36Smrg	-pie | -fpie | -fPIE)
3679d9dcd5aeSmrg          func_append pie_flag " $arg"
3680b290cf36Smrg	  continue
3681b290cf36Smrg	  ;;
3682b290cf36Smrg
3683b290cf36Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3684d9dcd5aeSmrg	  func_append later " $arg"
3685b290cf36Smrg	  continue
3686b290cf36Smrg	  ;;
3687b290cf36Smrg
3688b290cf36Smrg	-no-suppress)
3689b290cf36Smrg	  suppress_opt=no
3690b290cf36Smrg	  continue
3691b290cf36Smrg	  ;;
3692b290cf36Smrg
3693b290cf36Smrg	-Xcompiler)
3694b290cf36Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3695b290cf36Smrg	  continue      #  The current "srcfile" will either be retained or
3696b290cf36Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3697b290cf36Smrg
3698b290cf36Smrg	-Wc,*)
3699b290cf36Smrg	  func_stripname '-Wc,' '' "$arg"
3700b290cf36Smrg	  args=$func_stripname_result
3701b290cf36Smrg	  lastarg=
3702ee3e8c14Smrg	  save_ifs=$IFS; IFS=,
3703b290cf36Smrg	  for arg in $args; do
3704ee3e8c14Smrg	    IFS=$save_ifs
3705d9dcd5aeSmrg	    func_append_quoted lastarg "$arg"
3706191cded7Smrg	  done
3707ee3e8c14Smrg	  IFS=$save_ifs
3708b290cf36Smrg	  func_stripname ' ' '' "$lastarg"
3709b290cf36Smrg	  lastarg=$func_stripname_result
3710191cded7Smrg
3711191cded7Smrg	  # Add the arguments to base_compile.
3712d9dcd5aeSmrg	  func_append base_compile " $lastarg"
3713191cded7Smrg	  continue
3714191cded7Smrg	  ;;
3715191cded7Smrg
3716b290cf36Smrg	*)
3717191cded7Smrg	  # Accept the current argument as the source file.
3718191cded7Smrg	  # The previous "srcfile" becomes the current argument.
3719191cded7Smrg	  #
3720ee3e8c14Smrg	  lastarg=$srcfile
3721ee3e8c14Smrg	  srcfile=$arg
3722191cded7Smrg	  ;;
3723191cded7Smrg	esac  #  case $arg
3724191cded7Smrg	;;
3725191cded7Smrg      esac    #  case $arg_mode
3726191cded7Smrg
3727191cded7Smrg      # Aesthetically quote the previous argument.
3728d9dcd5aeSmrg      func_append_quoted base_compile "$lastarg"
3729191cded7Smrg    done # for arg
3730191cded7Smrg
3731191cded7Smrg    case $arg_mode in
3732191cded7Smrg    arg)
3733b290cf36Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3734191cded7Smrg      ;;
3735191cded7Smrg    target)
3736ee3e8c14Smrg      func_fatal_error "you must specify a target with '-o'"
3737191cded7Smrg      ;;
3738191cded7Smrg    *)
3739191cded7Smrg      # Get the name of the library object.
3740b290cf36Smrg      test -z "$libobj" && {
3741b290cf36Smrg	func_basename "$srcfile"
3742ee3e8c14Smrg	libobj=$func_basename_result
3743b290cf36Smrg      }
3744191cded7Smrg      ;;
3745191cded7Smrg    esac
3746191cded7Smrg
3747191cded7Smrg    # Recognize several different file suffixes.
3748191cded7Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3749191cded7Smrg    case $libobj in
3750b290cf36Smrg    *.[cCFSifmso] | \
3751b290cf36Smrg    *.ada | *.adb | *.ads | *.asm | \
3752b290cf36Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3753d9dcd5aeSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3754b290cf36Smrg      func_xform "$libobj"
3755b290cf36Smrg      libobj=$func_xform_result
3756b290cf36Smrg      ;;
3757191cded7Smrg    esac
3758191cded7Smrg
3759191cded7Smrg    case $libobj in
3760b290cf36Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3761191cded7Smrg    *)
3762ee3e8c14Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3763191cded7Smrg      ;;
3764191cded7Smrg    esac
3765191cded7Smrg
3766191cded7Smrg    func_infer_tag $base_compile
3767191cded7Smrg
3768191cded7Smrg    for arg in $later; do
3769191cded7Smrg      case $arg in
3770b290cf36Smrg      -shared)
3771ee3e8c14Smrg	test yes = "$build_libtool_libs" \
3772ee3e8c14Smrg	  || func_fatal_configuration "cannot build a shared library"
3773b290cf36Smrg	build_old_libs=no
3774b290cf36Smrg	continue
3775b290cf36Smrg	;;
3776b290cf36Smrg
3777191cded7Smrg      -static)
3778b290cf36Smrg	build_libtool_libs=no
3779191cded7Smrg	build_old_libs=yes
3780191cded7Smrg	continue
3781191cded7Smrg	;;
3782191cded7Smrg
3783191cded7Smrg      -prefer-pic)
3784191cded7Smrg	pic_mode=yes
3785191cded7Smrg	continue
3786191cded7Smrg	;;
3787191cded7Smrg
3788191cded7Smrg      -prefer-non-pic)
3789191cded7Smrg	pic_mode=no
3790191cded7Smrg	continue
3791191cded7Smrg	;;
3792191cded7Smrg      esac
3793191cded7Smrg    done
3794191cded7Smrg
3795ee3e8c14Smrg    func_quote_arg pretty "$libobj"
3796ee3e8c14Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3797b290cf36Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3798ee3e8c14Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3799b290cf36Smrg    func_dirname_and_basename "$obj" "/" ""
3800ee3e8c14Smrg    objname=$func_basename_result
3801ee3e8c14Smrg    xdir=$func_dirname_result
3802ee3e8c14Smrg    lobj=$xdir$objdir/$objname
3803191cded7Smrg
3804b290cf36Smrg    test -z "$base_compile" && \
3805b290cf36Smrg      func_fatal_help "you must specify a compilation command"
3806191cded7Smrg
3807191cded7Smrg    # Delete any leftover library objects.
3808ee3e8c14Smrg    if test yes = "$build_old_libs"; then
3809191cded7Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3810191cded7Smrg    else
3811191cded7Smrg      removelist="$lobj $libobj ${libobj}T"
3812191cded7Smrg    fi
3813191cded7Smrg
3814191cded7Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3815191cded7Smrg    case $host_os in
38168f9fac4aSmrg    cygwin* | mingw* | windows* | pw32* | os2* | cegcc*)
3817191cded7Smrg      pic_mode=default
3818191cded7Smrg      ;;
3819191cded7Smrg    esac
3820ee3e8c14Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3821191cded7Smrg      # non-PIC code in shared libraries is not supported
3822191cded7Smrg      pic_mode=default
3823191cded7Smrg    fi
3824191cded7Smrg
3825191cded7Smrg    # Calculate the filename of the output object if compiler does
3826191cded7Smrg    # not support -o with -c
3827ee3e8c14Smrg    if test no = "$compiler_c_o"; then
3828ee3e8c14Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3829ee3e8c14Smrg      lockfile=$output_obj.lock
3830191cded7Smrg    else
3831191cded7Smrg      output_obj=
3832191cded7Smrg      need_locks=no
3833191cded7Smrg      lockfile=
3834191cded7Smrg    fi
3835191cded7Smrg
3836191cded7Smrg    # Lock this critical section if it is needed
3837191cded7Smrg    # We use this script file to make the link, it avoids creating a new file
3838ee3e8c14Smrg    if test yes = "$need_locks"; then
3839b290cf36Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3840b290cf36Smrg	func_echo "Waiting for $lockfile to be removed"
3841191cded7Smrg	sleep 2
3842191cded7Smrg      done
3843ee3e8c14Smrg    elif test warn = "$need_locks"; then
3844191cded7Smrg      if test -f "$lockfile"; then
3845b290cf36Smrg	$ECHO "\
3846191cded7Smrg*** ERROR, $lockfile exists and contains:
3847191cded7Smrg`cat $lockfile 2>/dev/null`
3848191cded7Smrg
3849191cded7SmrgThis indicates that another process is trying to use the same
3850191cded7Smrgtemporary object file, and libtool could not work around it because
3851ee3e8c14Smrgyour compiler does not support '-c' and '-o' together.  If you
3852191cded7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3853191cded7Smrgavoid parallel builds (make -j) in this platform, or get a better
3854191cded7Smrgcompiler."
3855191cded7Smrg
3856b290cf36Smrg	$opt_dry_run || $RM $removelist
3857191cded7Smrg	exit $EXIT_FAILURE
3858191cded7Smrg      fi
3859d9dcd5aeSmrg      func_append removelist " $output_obj"
3860b290cf36Smrg      $ECHO "$srcfile" > "$lockfile"
3861191cded7Smrg    fi
3862191cded7Smrg
3863b290cf36Smrg    $opt_dry_run || $RM $removelist
3864d9dcd5aeSmrg    func_append removelist " $lockfile"
3865b290cf36Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3866b290cf36Smrg
3867d9dcd5aeSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3868d9dcd5aeSmrg    srcfile=$func_to_tool_file_result
3869ee3e8c14Smrg    func_quote_arg pretty "$srcfile"
3870ee3e8c14Smrg    qsrcfile=$func_quote_arg_result
3871191cded7Smrg
3872191cded7Smrg    # Only build a PIC object if we are building libtool libraries.
3873ee3e8c14Smrg    if test yes = "$build_libtool_libs"; then
3874191cded7Smrg      # Without this assignment, base_compile gets emptied.
3875191cded7Smrg      fbsd_hideous_sh_bug=$base_compile
3876191cded7Smrg
3877ee3e8c14Smrg      if test no != "$pic_mode"; then
3878191cded7Smrg	command="$base_compile $qsrcfile $pic_flag"
3879191cded7Smrg      else
3880191cded7Smrg	# Don't build PIC code
3881191cded7Smrg	command="$base_compile $qsrcfile"
3882191cded7Smrg      fi
3883191cded7Smrg
3884b290cf36Smrg      func_mkdir_p "$xdir$objdir"
3885191cded7Smrg
3886191cded7Smrg      if test -z "$output_obj"; then
3887191cded7Smrg	# Place PIC objects in $objdir
3888d9dcd5aeSmrg	func_append command " -o $lobj"
3889191cded7Smrg      fi
3890191cded7Smrg
3891b290cf36Smrg      func_show_eval_locale "$command"	\
3892b290cf36Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3893191cded7Smrg
3894ee3e8c14Smrg      if test warn = "$need_locks" &&
3895191cded7Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3896b290cf36Smrg	$ECHO "\
3897191cded7Smrg*** ERROR, $lockfile contains:
3898191cded7Smrg`cat $lockfile 2>/dev/null`
3899191cded7Smrg
3900191cded7Smrgbut it should contain:
3901191cded7Smrg$srcfile
3902191cded7Smrg
3903191cded7SmrgThis indicates that another process is trying to use the same
3904191cded7Smrgtemporary object file, and libtool could not work around it because
3905ee3e8c14Smrgyour compiler does not support '-c' and '-o' together.  If you
3906191cded7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3907191cded7Smrgavoid parallel builds (make -j) in this platform, or get a better
3908191cded7Smrgcompiler."
3909191cded7Smrg
3910b290cf36Smrg	$opt_dry_run || $RM $removelist
3911191cded7Smrg	exit $EXIT_FAILURE
3912191cded7Smrg      fi
3913191cded7Smrg
3914191cded7Smrg      # Just move the object if needed, then go on to compile the next one
3915191cded7Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3916b290cf36Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3917b290cf36Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3918191cded7Smrg      fi
3919191cded7Smrg
3920191cded7Smrg      # Allow error messages only from the first compilation.
3921ee3e8c14Smrg      if test yes = "$suppress_opt"; then
3922b290cf36Smrg	suppress_output=' >/dev/null 2>&1'
3923191cded7Smrg      fi
3924191cded7Smrg    fi
3925191cded7Smrg
3926191cded7Smrg    # Only build a position-dependent object if we build old libraries.
3927ee3e8c14Smrg    if test yes = "$build_old_libs"; then
3928ee3e8c14Smrg      if test yes != "$pic_mode"; then
3929191cded7Smrg	# Don't build PIC code
3930b290cf36Smrg	command="$base_compile $qsrcfile$pie_flag"
3931191cded7Smrg      else
3932191cded7Smrg	command="$base_compile $qsrcfile $pic_flag"
3933191cded7Smrg      fi
3934ee3e8c14Smrg      if test yes = "$compiler_c_o"; then
3935d9dcd5aeSmrg	func_append command " -o $obj"
3936191cded7Smrg      fi
3937191cded7Smrg
3938191cded7Smrg      # Suppress compiler output if we already did a PIC compilation.
3939d9dcd5aeSmrg      func_append command "$suppress_output"
3940b290cf36Smrg      func_show_eval_locale "$command" \
3941b290cf36Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3942191cded7Smrg
3943ee3e8c14Smrg      if test warn = "$need_locks" &&
3944191cded7Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3945b290cf36Smrg	$ECHO "\
3946191cded7Smrg*** ERROR, $lockfile contains:
3947191cded7Smrg`cat $lockfile 2>/dev/null`
3948191cded7Smrg
3949191cded7Smrgbut it should contain:
3950191cded7Smrg$srcfile
3951191cded7Smrg
3952191cded7SmrgThis indicates that another process is trying to use the same
3953191cded7Smrgtemporary object file, and libtool could not work around it because
3954ee3e8c14Smrgyour compiler does not support '-c' and '-o' together.  If you
3955191cded7Smrgrepeat this compilation, it may succeed, by chance, but you had better
3956191cded7Smrgavoid parallel builds (make -j) in this platform, or get a better
3957191cded7Smrgcompiler."
3958191cded7Smrg
3959b290cf36Smrg	$opt_dry_run || $RM $removelist
3960191cded7Smrg	exit $EXIT_FAILURE
3961191cded7Smrg      fi
3962191cded7Smrg
3963191cded7Smrg      # Just move the object if needed
3964191cded7Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3965b290cf36Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3966b290cf36Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3967191cded7Smrg      fi
3968191cded7Smrg    fi
3969191cded7Smrg
3970b290cf36Smrg    $opt_dry_run || {
3971b290cf36Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3972191cded7Smrg
3973b290cf36Smrg      # Unlock the critical section if it was locked
3974ee3e8c14Smrg      if test no != "$need_locks"; then
3975b290cf36Smrg	removelist=$lockfile
3976b290cf36Smrg        $RM "$lockfile"
3977b290cf36Smrg      fi
3978b290cf36Smrg    }
3979191cded7Smrg
3980191cded7Smrg    exit $EXIT_SUCCESS
3981b290cf36Smrg}
3982191cded7Smrg
3983b290cf36Smrg$opt_help || {
3984ee3e8c14Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3985b290cf36Smrg}
3986191cded7Smrg
3987b290cf36Smrgfunc_mode_help ()
3988b290cf36Smrg{
3989b290cf36Smrg    # We need to display help for each of the modes.
3990d9dcd5aeSmrg    case $opt_mode in
3991b290cf36Smrg      "")
3992b290cf36Smrg        # Generic help is extracted from the usage comments
3993b290cf36Smrg        # at the start of this file.
3994b290cf36Smrg        func_help
3995b290cf36Smrg        ;;
3996191cded7Smrg
3997b290cf36Smrg      clean)
3998b290cf36Smrg        $ECHO \
3999b290cf36Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
4000191cded7Smrg
4001b290cf36SmrgRemove files from the build directory.
4002191cded7Smrg
4003b290cf36SmrgRM is the name of the program to use to delete files associated with each FILE
4004ee3e8c14Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4005b290cf36Smrgto RM.
4006191cded7Smrg
4007b290cf36SmrgIf FILE is a libtool library, object or program, all the files associated
4008b290cf36Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
4009b290cf36Smrg        ;;
4010191cded7Smrg
4011b290cf36Smrg      compile)
4012b290cf36Smrg      $ECHO \
4013b290cf36Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
4014191cded7Smrg
4015b290cf36SmrgCompile a source file into a libtool library object.
4016191cded7Smrg
4017b290cf36SmrgThis mode accepts the following additional options:
4018191cded7Smrg
4019b290cf36Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
4020b290cf36Smrg  -no-suppress      do not suppress compiler output for multiple passes
4021ba064abeSmrg  -prefer-pic       try to build PIC objects only
4022ba064abeSmrg  -prefer-non-pic   try to build non-PIC objects only
4023ee3e8c14Smrg  -shared           do not build a '.o' file suitable for static linking
4024ee3e8c14Smrg  -static           only build a '.o' file suitable for static linking
4025ee3e8c14Smrg  -Wc,FLAG
4026ee3e8c14Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
4027191cded7Smrg
4028ee3e8c14SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
4029b290cf36Smrgfrom the given SOURCEFILE.
4030191cded7Smrg
4031b290cf36SmrgThe output file name is determined by removing the directory component from
4032ee3e8c14SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
4033ee3e8c14Smrglibrary object suffix, '.lo'."
4034b290cf36Smrg        ;;
4035191cded7Smrg
4036b290cf36Smrg      execute)
4037b290cf36Smrg        $ECHO \
4038b290cf36Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
4039191cded7Smrg
4040b290cf36SmrgAutomatically set library path, then run a program.
4041191cded7Smrg
4042b290cf36SmrgThis mode accepts the following additional options:
4043191cded7Smrg
4044b290cf36Smrg  -dlopen FILE      add the directory containing FILE to the library path
4045191cded7Smrg
4046ee3e8c14SmrgThis mode sets the library path environment variable according to '-dlopen'
4047b290cf36Smrgflags.
4048191cded7Smrg
4049b290cf36SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
4050b290cf36Smrginto their corresponding uninstalled binary, and any of their required library
4051b290cf36Smrgdirectories are added to the library path.
4052191cded7Smrg
4053b290cf36SmrgThen, COMMAND is executed, with ARGS as arguments."
4054b290cf36Smrg        ;;
4055191cded7Smrg
4056b290cf36Smrg      finish)
4057b290cf36Smrg        $ECHO \
4058b290cf36Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
4059191cded7Smrg
4060b290cf36SmrgComplete the installation of libtool libraries.
4061191cded7Smrg
4062b290cf36SmrgEach LIBDIR is a directory that contains libtool libraries.
4063191cded7Smrg
4064b290cf36SmrgThe commands that this mode executes may require superuser privileges.  Use
4065ee3e8c14Smrgthe '--dry-run' option if you just want to see what would be executed."
4066b290cf36Smrg        ;;
4067191cded7Smrg
4068b290cf36Smrg      install)
4069b290cf36Smrg        $ECHO \
4070b290cf36Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
4071191cded7Smrg
4072b290cf36SmrgInstall executables or libraries.
4073191cded7Smrg
4074b290cf36SmrgINSTALL-COMMAND is the installation command.  The first component should be
4075ee3e8c14Smrgeither the 'install' or 'cp' program.
4076191cded7Smrg
4077b290cf36SmrgThe following components of INSTALL-COMMAND are treated specially:
4078191cded7Smrg
4079ba064abeSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
4080191cded7Smrg
4081b290cf36SmrgThe rest of the components are interpreted as arguments to that command (only
4082b290cf36SmrgBSD-compatible install options are recognized)."
4083b290cf36Smrg        ;;
4084191cded7Smrg
4085b290cf36Smrg      link)
4086b290cf36Smrg        $ECHO \
4087b290cf36Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
4088191cded7Smrg
4089b290cf36SmrgLink object files or libraries together to form another library, or to
4090b290cf36Smrgcreate an executable program.
4091191cded7Smrg
4092b290cf36SmrgLINK-COMMAND is a command using the C compiler that you would use to create
4093b290cf36Smrga program from several object files.
4094191cded7Smrg
4095b290cf36SmrgThe following components of LINK-COMMAND are treated specially:
4096191cded7Smrg
4097b290cf36Smrg  -all-static       do not do any dynamic linking at all
4098b290cf36Smrg  -avoid-version    do not add a version suffix if possible
4099ba064abeSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
4100ba064abeSmrg                    libraries must be found in the PATH setting at runtime)
4101ee3e8c14Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
4102b290cf36Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
4103b290cf36Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
4104b290cf36Smrg  -export-symbols SYMFILE
4105b290cf36Smrg                    try to export only the symbols listed in SYMFILE
4106b290cf36Smrg  -export-symbols-regex REGEX
4107b290cf36Smrg                    try to export only the symbols matching REGEX
4108b290cf36Smrg  -LLIBDIR          search LIBDIR for required installed libraries
4109b290cf36Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
4110b290cf36Smrg  -module           build a library that can dlopened
4111b290cf36Smrg  -no-fast-install  disable the fast-install mode
4112b290cf36Smrg  -no-install       link a not-installable executable
4113b290cf36Smrg  -no-undefined     declare that a library does not refer to external symbols
4114b290cf36Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
4115ee3e8c14Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
4116ee3e8c14Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
4117b290cf36Smrg  -precious-files-regex REGEX
4118b290cf36Smrg                    don't remove output files matching REGEX
4119b290cf36Smrg  -release RELEASE  specify package release information
4120b290cf36Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4121b290cf36Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4122b290cf36Smrg  -shared           only do dynamic linking of libtool libraries
4123b290cf36Smrg  -shrext SUFFIX    override the standard shared library file extension
4124b290cf36Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4125b290cf36Smrg  -static-libtool-libs
4126b290cf36Smrg                    do not do any dynamic linking of libtool libraries
4127b290cf36Smrg  -version-info CURRENT[:REVISION[:AGE]]
4128b290cf36Smrg                    specify library version info [each variable defaults to 0]
4129b290cf36Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4130ba064abeSmrg  -Wc,FLAG
4131ba064abeSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4132ee3e8c14Smrg  -Wa,FLAG
4133ee3e8c14Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4134ba064abeSmrg  -Wl,FLAG
4135ba064abeSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4136ba064abeSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4137191cded7Smrg
4138ee3e8c14SmrgAll other options (arguments beginning with '-') are ignored.
4139191cded7Smrg
4140ee3e8c14SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4141b290cf36Smrgtreated as uninstalled libtool libraries, other files are standard or library
4142b290cf36Smrgobject files.
4143191cded7Smrg
4144ee3e8c14SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4145ee3e8c14Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4146b290cf36Smrgrequired, except when creating a convenience library.
4147191cded7Smrg
4148ee3e8c14SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4149ee3e8c14Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4150191cded7Smrg
4151ee3e8c14SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4152b290cf36Smrgis created, otherwise an executable program is created."
4153191cded7Smrg        ;;
4154191cded7Smrg
4155b290cf36Smrg      uninstall)
4156b290cf36Smrg        $ECHO \
4157b290cf36Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4158191cded7Smrg
4159b290cf36SmrgRemove libraries from an installation directory.
4160191cded7Smrg
4161b290cf36SmrgRM is the name of the program to use to delete files associated with each FILE
4162ee3e8c14Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4163b290cf36Smrgto RM.
4164191cded7Smrg
4165b290cf36SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4166b290cf36SmrgOtherwise, only FILE itself is deleted using RM."
4167b290cf36Smrg        ;;
4168191cded7Smrg
4169b290cf36Smrg      *)
4170ee3e8c14Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
4171b290cf36Smrg        ;;
4172b290cf36Smrg    esac
4173191cded7Smrg
4174ba064abeSmrg    echo
4175ee3e8c14Smrg    $ECHO "Try '$progname --help' for more information about other modes."
4176b290cf36Smrg}
4177191cded7Smrg
4178ba064abeSmrg# Now that we've collected a possible --mode arg, show help if necessary
4179ba064abeSmrgif $opt_help; then
4180ee3e8c14Smrg  if test : = "$opt_help"; then
4181ba064abeSmrg    func_mode_help
4182ba064abeSmrg  else
4183ba064abeSmrg    {
4184ba064abeSmrg      func_help noexit
4185d9dcd5aeSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4186ba064abeSmrg	func_mode_help
4187ba064abeSmrg      done
4188ee3e8c14Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4189ba064abeSmrg    {
4190ba064abeSmrg      func_help noexit
4191d9dcd5aeSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4192ba064abeSmrg	echo
4193ba064abeSmrg	func_mode_help
4194ba064abeSmrg      done
4195ba064abeSmrg    } |
4196ee3e8c14Smrg    $SED '1d
4197ba064abeSmrg      /^When reporting/,/^Report/{
4198ba064abeSmrg	H
4199ba064abeSmrg	d
4200ba064abeSmrg      }
4201ba064abeSmrg      $x
4202ba064abeSmrg      /information about other modes/d
4203ba064abeSmrg      /more detailed .*MODE/d
4204ba064abeSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4205ba064abeSmrg  fi
4206ba064abeSmrg  exit $?
4207ba064abeSmrgfi
4208191cded7Smrg
4209191cded7Smrg
42108f9fac4aSmrg# If option '--reorder-cache', reorder the shared library cache and exit.
42118f9fac4aSmrgif $opt_reorder_cache; then
42128f9fac4aSmrg    func_reorder_shared_lib_cache $shared_lib_dirs
42138f9fac4aSmrgfi
42148f9fac4aSmrg
42158f9fac4aSmrg
4216b290cf36Smrg# func_mode_execute arg...
4217b290cf36Smrgfunc_mode_execute ()
4218b290cf36Smrg{
4219ee3e8c14Smrg    $debug_cmd
4220ee3e8c14Smrg
4221b290cf36Smrg    # The first argument is the command name.
4222ee3e8c14Smrg    cmd=$nonopt
4223b290cf36Smrg    test -z "$cmd" && \
4224b290cf36Smrg      func_fatal_help "you must specify a COMMAND"
4225191cded7Smrg
4226b290cf36Smrg    # Handle -dlopen flags immediately.
4227d9dcd5aeSmrg    for file in $opt_dlopen; do
4228b290cf36Smrg      test -f "$file" \
4229ee3e8c14Smrg	|| func_fatal_help "'$file' is not a file"
4230191cded7Smrg
4231b290cf36Smrg      dir=
4232b290cf36Smrg      case $file in
4233b290cf36Smrg      *.la)
4234d9dcd5aeSmrg	func_resolve_sysroot "$file"
4235d9dcd5aeSmrg	file=$func_resolve_sysroot_result
4236d9dcd5aeSmrg
4237b290cf36Smrg	# Check to see that this really is a libtool archive.
4238b290cf36Smrg	func_lalib_unsafe_p "$file" \
4239ee3e8c14Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4240191cded7Smrg
4241b290cf36Smrg	# Read the libtool library.
4242b290cf36Smrg	dlname=
4243b290cf36Smrg	library_names=
4244b290cf36Smrg	func_source "$file"
4245191cded7Smrg
4246b290cf36Smrg	# Skip this library if it cannot be dlopened.
4247b290cf36Smrg	if test -z "$dlname"; then
4248b290cf36Smrg	  # Warn if it was a shared library.
4249b290cf36Smrg	  test -n "$library_names" && \
4250ee3e8c14Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4251b290cf36Smrg	  continue
4252b290cf36Smrg	fi
4253191cded7Smrg
4254b290cf36Smrg	func_dirname "$file" "" "."
4255ee3e8c14Smrg	dir=$func_dirname_result
4256191cded7Smrg
4257b290cf36Smrg	if test -f "$dir/$objdir/$dlname"; then
4258d9dcd5aeSmrg	  func_append dir "/$objdir"
4259b290cf36Smrg	else
4260b290cf36Smrg	  if test ! -f "$dir/$dlname"; then
4261ee3e8c14Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4262b290cf36Smrg	  fi
4263b290cf36Smrg	fi
4264191cded7Smrg	;;
4265191cded7Smrg
4266b290cf36Smrg      *.lo)
4267b290cf36Smrg	# Just add the directory containing the .lo file.
4268b290cf36Smrg	func_dirname "$file" "" "."
4269ee3e8c14Smrg	dir=$func_dirname_result
4270191cded7Smrg	;;
4271191cded7Smrg
4272b290cf36Smrg      *)
4273ee3e8c14Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4274191cded7Smrg	continue
4275191cded7Smrg	;;
4276b290cf36Smrg      esac
4277191cded7Smrg
4278b290cf36Smrg      # Get the absolute pathname.
4279b290cf36Smrg      absdir=`cd "$dir" && pwd`
4280ee3e8c14Smrg      test -n "$absdir" && dir=$absdir
4281191cded7Smrg
4282b290cf36Smrg      # Now add the directory to shlibpath_var.
4283b290cf36Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4284b290cf36Smrg	eval "$shlibpath_var=\"\$dir\""
4285b290cf36Smrg      else
4286b290cf36Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4287b290cf36Smrg      fi
4288b290cf36Smrg    done
4289191cded7Smrg
4290b290cf36Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4291b290cf36Smrg    # rather than running their programs.
4292ee3e8c14Smrg    libtool_execute_magic=$magic
4293191cded7Smrg
4294b290cf36Smrg    # Check if any of the arguments is a wrapper script.
4295b290cf36Smrg    args=
4296b290cf36Smrg    for file
4297b290cf36Smrg    do
4298b290cf36Smrg      case $file in
4299ba064abeSmrg      -* | *.la | *.lo ) ;;
4300b290cf36Smrg      *)
4301b290cf36Smrg	# Do a test to see if this is really a libtool program.
4302b290cf36Smrg	if func_ltwrapper_script_p "$file"; then
4303b290cf36Smrg	  func_source "$file"
4304b290cf36Smrg	  # Transform arg to wrapped name.
4305ee3e8c14Smrg	  file=$progdir/$program
4306b290cf36Smrg	elif func_ltwrapper_executable_p "$file"; then
4307b290cf36Smrg	  func_ltwrapper_scriptname "$file"
4308b290cf36Smrg	  func_source "$func_ltwrapper_scriptname_result"
4309b290cf36Smrg	  # Transform arg to wrapped name.
4310ee3e8c14Smrg	  file=$progdir/$program
4311b290cf36Smrg	fi
4312b290cf36Smrg	;;
4313b290cf36Smrg      esac
4314b290cf36Smrg      # Quote arguments (to preserve shell metacharacters).
4315d9dcd5aeSmrg      func_append_quoted args "$file"
4316b290cf36Smrg    done
4317191cded7Smrg
4318ee3e8c14Smrg    if $opt_dry_run; then
4319ee3e8c14Smrg      # Display what would be done.
4320ee3e8c14Smrg      if test -n "$shlibpath_var"; then
4321ee3e8c14Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4322ee3e8c14Smrg	echo "export $shlibpath_var"
4323ee3e8c14Smrg      fi
4324ee3e8c14Smrg      $ECHO "$cmd$args"
4325ee3e8c14Smrg      exit $EXIT_SUCCESS
4326ee3e8c14Smrg    else
4327b290cf36Smrg      if test -n "$shlibpath_var"; then
4328b290cf36Smrg	# Export the shlibpath_var.
4329b290cf36Smrg	eval "export $shlibpath_var"
4330b290cf36Smrg      fi
4331191cded7Smrg
4332b290cf36Smrg      # Restore saved environment variables
4333b290cf36Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4334b290cf36Smrg      do
4335b290cf36Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4336b290cf36Smrg                $lt_var=\$save_$lt_var; export $lt_var
4337b290cf36Smrg	      else
4338b290cf36Smrg		$lt_unset $lt_var
4339b290cf36Smrg	      fi"
4340b290cf36Smrg      done
4341191cded7Smrg
4342b290cf36Smrg      # Now prepare to actually exec the command.
4343ee3e8c14Smrg      exec_cmd=\$cmd$args
4344b290cf36Smrg    fi
4345b290cf36Smrg}
4346191cded7Smrg
4347ee3e8c14Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4348191cded7Smrg
4349191cded7Smrg
4350b290cf36Smrg# func_mode_finish arg...
4351b290cf36Smrgfunc_mode_finish ()
4352b290cf36Smrg{
4353ee3e8c14Smrg    $debug_cmd
4354ee3e8c14Smrg
4355d9dcd5aeSmrg    libs=
4356d9dcd5aeSmrg    libdirs=
4357b290cf36Smrg    admincmds=
4358191cded7Smrg
4359d9dcd5aeSmrg    for opt in "$nonopt" ${1+"$@"}
4360d9dcd5aeSmrg    do
4361d9dcd5aeSmrg      if test -d "$opt"; then
4362d9dcd5aeSmrg	func_append libdirs " $opt"
4363d9dcd5aeSmrg
4364d9dcd5aeSmrg      elif test -f "$opt"; then
4365d9dcd5aeSmrg	if func_lalib_unsafe_p "$opt"; then
4366d9dcd5aeSmrg	  func_append libs " $opt"
4367d9dcd5aeSmrg	else
4368ee3e8c14Smrg	  func_warning "'$opt' is not a valid libtool archive"
4369d9dcd5aeSmrg	fi
4370d9dcd5aeSmrg
4371d9dcd5aeSmrg      else
4372ee3e8c14Smrg	func_fatal_error "invalid argument '$opt'"
4373d9dcd5aeSmrg      fi
4374d9dcd5aeSmrg    done
4375d9dcd5aeSmrg
4376d9dcd5aeSmrg    if test -n "$libs"; then
4377d9dcd5aeSmrg      if test -n "$lt_sysroot"; then
4378d9dcd5aeSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4379d9dcd5aeSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4380d9dcd5aeSmrg      else
4381d9dcd5aeSmrg        sysroot_cmd=
4382d9dcd5aeSmrg      fi
4383d9dcd5aeSmrg
4384d9dcd5aeSmrg      # Remove sysroot references
4385d9dcd5aeSmrg      if $opt_dry_run; then
4386d9dcd5aeSmrg        for lib in $libs; do
4387ee3e8c14Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4388d9dcd5aeSmrg        done
4389d9dcd5aeSmrg      else
4390d9dcd5aeSmrg        tmpdir=`func_mktempdir`
4391d9dcd5aeSmrg        for lib in $libs; do
4392ee3e8c14Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4393d9dcd5aeSmrg	    > $tmpdir/tmp-la
4394d9dcd5aeSmrg	  mv -f $tmpdir/tmp-la $lib
4395d9dcd5aeSmrg	done
4396d9dcd5aeSmrg        ${RM}r "$tmpdir"
4397d9dcd5aeSmrg      fi
4398d9dcd5aeSmrg    fi
4399191cded7Smrg
44008f9fac4aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs" && $opt_finishing; then
4401b290cf36Smrg      for libdir in $libdirs; do
4402b290cf36Smrg	if test -n "$finish_cmds"; then
4403b290cf36Smrg	  # Do each command in the finish commands.
4404b290cf36Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4405b290cf36Smrg'"$cmd"'"'
4406b290cf36Smrg	fi
4407b290cf36Smrg	if test -n "$finish_eval"; then
4408b290cf36Smrg	  # Do the single finish_eval.
4409b290cf36Smrg	  eval cmds=\"$finish_eval\"
4410d9dcd5aeSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4411b290cf36Smrg       $cmds"
4412b290cf36Smrg	fi
4413b290cf36Smrg      done
4414b290cf36Smrg    fi
4415191cded7Smrg
4416b290cf36Smrg    # Exit here if they wanted silent mode.
4417ee3e8c14Smrg    $opt_quiet && exit $EXIT_SUCCESS
4418191cded7Smrg
4419d9dcd5aeSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4420d9dcd5aeSmrg      echo "----------------------------------------------------------------------"
4421d9dcd5aeSmrg      echo "Libraries have been installed in:"
4422d9dcd5aeSmrg      for libdir in $libdirs; do
4423d9dcd5aeSmrg	$ECHO "   $libdir"
4424d9dcd5aeSmrg      done
44258f9fac4aSmrg      if test "false" = "$opt_finishing"; then
44268f9fac4aSmrg        echo
44278f9fac4aSmrg        echo "NOTE: finish_cmds were not executed during testing, so you must"
44288f9fac4aSmrg        echo "manually run ldconfig to add a given test directory, LIBDIR, to"
44298f9fac4aSmrg        echo "the search path for generated executables."
44308f9fac4aSmrg      fi
4431d9dcd5aeSmrg      echo
4432d9dcd5aeSmrg      echo "If you ever happen to want to link against installed libraries"
4433d9dcd5aeSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4434ee3e8c14Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4435d9dcd5aeSmrg      echo "flag during linking and do at least one of the following:"
4436d9dcd5aeSmrg      if test -n "$shlibpath_var"; then
4437ee3e8c14Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4438d9dcd5aeSmrg	echo "     during execution"
4439d9dcd5aeSmrg      fi
4440d9dcd5aeSmrg      if test -n "$runpath_var"; then
4441ee3e8c14Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4442d9dcd5aeSmrg	echo "     during linking"
4443d9dcd5aeSmrg      fi
4444d9dcd5aeSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4445d9dcd5aeSmrg	libdir=LIBDIR
4446d9dcd5aeSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4447191cded7Smrg
4448ee3e8c14Smrg	$ECHO "   - use the '$flag' linker flag"
4449d9dcd5aeSmrg      fi
4450d9dcd5aeSmrg      if test -n "$admincmds"; then
4451d9dcd5aeSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4452d9dcd5aeSmrg      fi
4453d9dcd5aeSmrg      if test -f /etc/ld.so.conf; then
4454ee3e8c14Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4455d9dcd5aeSmrg      fi
4456d9dcd5aeSmrg      echo
4457191cded7Smrg
4458d9dcd5aeSmrg      echo "See any operating system documentation about shared libraries for"
4459d9dcd5aeSmrg      case $host in
4460d9dcd5aeSmrg	solaris2.[6789]|solaris2.1[0-9])
4461d9dcd5aeSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4462d9dcd5aeSmrg	  echo "pages."
4463d9dcd5aeSmrg	  ;;
4464d9dcd5aeSmrg	*)
4465d9dcd5aeSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4466d9dcd5aeSmrg	  ;;
4467d9dcd5aeSmrg      esac
4468d9dcd5aeSmrg      echo "----------------------------------------------------------------------"
4469d9dcd5aeSmrg    fi
4470b290cf36Smrg    exit $EXIT_SUCCESS
4471b290cf36Smrg}
4472191cded7Smrg
4473ee3e8c14Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4474191cded7Smrg
4475191cded7Smrg
4476b290cf36Smrg# func_mode_install arg...
4477b290cf36Smrgfunc_mode_install ()
4478b290cf36Smrg{
4479ee3e8c14Smrg    $debug_cmd
4480ee3e8c14Smrg
4481b290cf36Smrg    # There may be an optional sh(1) argument at the beginning of
4482b290cf36Smrg    # install_prog (especially on Windows NT).
4483ee3e8c14Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4484b290cf36Smrg       # Allow the use of GNU shtool's install command.
4485ee3e8c14Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4486ee3e8c14Smrg    then
4487b290cf36Smrg      # Aesthetically quote it.
4488ee3e8c14Smrg      func_quote_arg pretty "$nonopt"
4489ee3e8c14Smrg      install_prog="$func_quote_arg_result "
4490b290cf36Smrg      arg=$1
4491b290cf36Smrg      shift
4492b290cf36Smrg    else
4493b290cf36Smrg      install_prog=
4494b290cf36Smrg      arg=$nonopt
4495b290cf36Smrg    fi
4496191cded7Smrg
4497b290cf36Smrg    # The real first argument should be the name of the installation program.
4498b290cf36Smrg    # Aesthetically quote it.
4499ee3e8c14Smrg    func_quote_arg pretty "$arg"
4500ee3e8c14Smrg    func_append install_prog "$func_quote_arg_result"
4501ba064abeSmrg    install_shared_prog=$install_prog
4502ba064abeSmrg    case " $install_prog " in
4503ba064abeSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4504ba064abeSmrg      *) install_cp=false ;;
4505ba064abeSmrg    esac
4506b290cf36Smrg
4507b290cf36Smrg    # We need to accept at least all the BSD install flags.
4508b290cf36Smrg    dest=
4509b290cf36Smrg    files=
4510b290cf36Smrg    opts=
4511b290cf36Smrg    prev=
4512b290cf36Smrg    install_type=
4513ee3e8c14Smrg    isdir=false
4514b290cf36Smrg    stripme=
4515ba064abeSmrg    no_mode=:
4516b290cf36Smrg    for arg
4517b290cf36Smrg    do
4518ba064abeSmrg      arg2=
4519b290cf36Smrg      if test -n "$dest"; then
4520d9dcd5aeSmrg	func_append files " $dest"
4521b290cf36Smrg	dest=$arg
4522b290cf36Smrg	continue
4523191cded7Smrg      fi
4524191cded7Smrg
4525b290cf36Smrg      case $arg in
4526ee3e8c14Smrg      -d) isdir=: ;;
4527b290cf36Smrg      -f)
4528ba064abeSmrg	if $install_cp; then :; else
4529ba064abeSmrg	  prev=$arg
4530ba064abeSmrg	fi
4531b290cf36Smrg	;;
4532b290cf36Smrg      -g | -m | -o)
4533b290cf36Smrg	prev=$arg
4534b290cf36Smrg	;;
4535b290cf36Smrg      -s)
4536b290cf36Smrg	stripme=" -s"
4537b290cf36Smrg	continue
4538b290cf36Smrg	;;
4539b290cf36Smrg      -*)
4540b290cf36Smrg	;;
4541b290cf36Smrg      *)
4542b290cf36Smrg	# If the previous option needed an argument, then skip it.
4543b290cf36Smrg	if test -n "$prev"; then
4544ee3e8c14Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4545ba064abeSmrg	    arg2=$install_override_mode
4546ba064abeSmrg	    no_mode=false
4547ba064abeSmrg	  fi
4548b290cf36Smrg	  prev=
4549b290cf36Smrg	else
4550b290cf36Smrg	  dest=$arg
4551b290cf36Smrg	  continue
4552b290cf36Smrg	fi
4553b290cf36Smrg	;;
4554b290cf36Smrg      esac
4555191cded7Smrg
4556b290cf36Smrg      # Aesthetically quote the argument.
4557ee3e8c14Smrg      func_quote_arg pretty "$arg"
4558ee3e8c14Smrg      func_append install_prog " $func_quote_arg_result"
4559ba064abeSmrg      if test -n "$arg2"; then
4560ee3e8c14Smrg	func_quote_arg pretty "$arg2"
4561ba064abeSmrg      fi
4562ee3e8c14Smrg      func_append install_shared_prog " $func_quote_arg_result"
4563b290cf36Smrg    done
4564191cded7Smrg
4565b290cf36Smrg    test -z "$install_prog" && \
4566b290cf36Smrg      func_fatal_help "you must specify an install program"
4567191cded7Smrg
4568b290cf36Smrg    test -n "$prev" && \
4569ee3e8c14Smrg      func_fatal_help "the '$prev' option requires an argument"
4570191cded7Smrg
4571ba064abeSmrg    if test -n "$install_override_mode" && $no_mode; then
4572ba064abeSmrg      if $install_cp; then :; else
4573ee3e8c14Smrg	func_quote_arg pretty "$install_override_mode"
4574ee3e8c14Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4575ba064abeSmrg      fi
4576ba064abeSmrg    fi
4577ba064abeSmrg
4578b290cf36Smrg    if test -z "$files"; then
4579b290cf36Smrg      if test -z "$dest"; then
4580b290cf36Smrg	func_fatal_help "no file or destination specified"
4581b290cf36Smrg      else
4582b290cf36Smrg	func_fatal_help "you must specify a destination"
4583191cded7Smrg      fi
4584191cded7Smrg    fi
4585191cded7Smrg
4586b290cf36Smrg    # Strip any trailing slash from the destination.
4587b290cf36Smrg    func_stripname '' '/' "$dest"
4588b290cf36Smrg    dest=$func_stripname_result
4589191cded7Smrg
4590b290cf36Smrg    # Check to see that the destination is a directory.
4591ee3e8c14Smrg    test -d "$dest" && isdir=:
4592ee3e8c14Smrg    if $isdir; then
4593ee3e8c14Smrg      destdir=$dest
4594b290cf36Smrg      destname=
4595b290cf36Smrg    else
4596b290cf36Smrg      func_dirname_and_basename "$dest" "" "."
4597ee3e8c14Smrg      destdir=$func_dirname_result
4598ee3e8c14Smrg      destname=$func_basename_result
4599b290cf36Smrg
4600b290cf36Smrg      # Not a directory, so check to see that there is only one file specified.
4601b290cf36Smrg      set dummy $files; shift
4602b290cf36Smrg      test "$#" -gt 1 && \
4603ee3e8c14Smrg	func_fatal_help "'$dest' is not a directory"
4604b290cf36Smrg    fi
4605b290cf36Smrg    case $destdir in
4606b290cf36Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4607191cded7Smrg    *)
4608b290cf36Smrg      for file in $files; do
4609b290cf36Smrg	case $file in
4610b290cf36Smrg	*.lo) ;;
4611b290cf36Smrg	*)
4612ee3e8c14Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4613b290cf36Smrg	  ;;
4614b290cf36Smrg	esac
4615b290cf36Smrg      done
4616191cded7Smrg      ;;
4617191cded7Smrg    esac
4618191cded7Smrg
4619b290cf36Smrg    # This variable tells wrapper scripts just to set variables rather
4620b290cf36Smrg    # than running their programs.
4621ee3e8c14Smrg    libtool_install_magic=$magic
4622191cded7Smrg
4623b290cf36Smrg    staticlibs=
4624b290cf36Smrg    future_libdirs=
4625b290cf36Smrg    current_libdirs=
4626b290cf36Smrg    for file in $files; do
4627191cded7Smrg
4628b290cf36Smrg      # Do each installation.
4629b290cf36Smrg      case $file in
4630b290cf36Smrg      *.$libext)
4631b290cf36Smrg	# Do the static libraries later.
4632d9dcd5aeSmrg	func_append staticlibs " $file"
4633b290cf36Smrg	;;
4634b290cf36Smrg
4635b290cf36Smrg      *.la)
4636d9dcd5aeSmrg	func_resolve_sysroot "$file"
4637d9dcd5aeSmrg	file=$func_resolve_sysroot_result
4638d9dcd5aeSmrg
4639b290cf36Smrg	# Check to see that this really is a libtool archive.
4640b290cf36Smrg	func_lalib_unsafe_p "$file" \
4641ee3e8c14Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4642b290cf36Smrg
4643b290cf36Smrg	library_names=
4644b290cf36Smrg	old_library=
4645b290cf36Smrg	relink_command=
4646b290cf36Smrg	func_source "$file"
4647b290cf36Smrg
4648b290cf36Smrg	# Add the libdir to current_libdirs if it is the destination.
4649b290cf36Smrg	if test "X$destdir" = "X$libdir"; then
4650b290cf36Smrg	  case "$current_libdirs " in
4651b290cf36Smrg	  *" $libdir "*) ;;
4652d9dcd5aeSmrg	  *) func_append current_libdirs " $libdir" ;;
4653191cded7Smrg	  esac
4654b290cf36Smrg	else
4655b290cf36Smrg	  # Note the libdir as a future libdir.
4656b290cf36Smrg	  case "$future_libdirs " in
4657b290cf36Smrg	  *" $libdir "*) ;;
4658d9dcd5aeSmrg	  *) func_append future_libdirs " $libdir" ;;
4659b290cf36Smrg	  esac
4660b290cf36Smrg	fi
4661191cded7Smrg
4662b290cf36Smrg	func_dirname "$file" "/" ""
4663ee3e8c14Smrg	dir=$func_dirname_result
4664d9dcd5aeSmrg	func_append dir "$objdir"
4665b290cf36Smrg
4666b290cf36Smrg	if test -n "$relink_command"; then
46678f9fac4aSmrg	  # Strip any trailing slash from the destination.
46688f9fac4aSmrg	  func_stripname '' '/' "$libdir"
46698f9fac4aSmrg	  destlibdir=$func_stripname_result
46708f9fac4aSmrg
46718f9fac4aSmrg	  func_stripname '' '/' "$destdir"
46728f9fac4aSmrg	  s_destdir=$func_stripname_result
46738f9fac4aSmrg
4674b290cf36Smrg	  # Determine the prefix the user has applied to our future dir.
46758f9fac4aSmrg	  inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"`
4676b290cf36Smrg
4677b290cf36Smrg	  # Don't allow the user to place us outside of our expected
4678b290cf36Smrg	  # location b/c this prevents finding dependent libraries that
4679b290cf36Smrg	  # are installed to the same prefix.
4680b290cf36Smrg	  # At present, this check doesn't affect windows .dll's that
4681b290cf36Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4682b290cf36Smrg	  # but it's something to keep an eye on.
4683b290cf36Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4684ee3e8c14Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4685b290cf36Smrg
4686b290cf36Smrg	  if test -n "$inst_prefix_dir"; then
4687b290cf36Smrg	    # Stick the inst_prefix_dir data into the link command.
4688ba064abeSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4689b290cf36Smrg	  else
4690ba064abeSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4691b290cf36Smrg	  fi
4692b290cf36Smrg
4693ee3e8c14Smrg	  func_warning "relinking '$file'"
4694b290cf36Smrg	  func_show_eval "$relink_command" \
4695ee3e8c14Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4696b290cf36Smrg	fi
4697b290cf36Smrg
4698b290cf36Smrg	# See the names of the shared library.
4699b290cf36Smrg	set dummy $library_names; shift
4700b290cf36Smrg	if test -n "$1"; then
4701ee3e8c14Smrg	  realname=$1
4702b290cf36Smrg	  shift
4703b290cf36Smrg
4704ee3e8c14Smrg	  srcname=$realname
4705ee3e8c14Smrg	  test -n "$relink_command" && srcname=${realname}T
4706b290cf36Smrg
4707b290cf36Smrg	  # Install the shared library and build the symlinks.
4708ba064abeSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4709b290cf36Smrg	      'exit $?'
4710ee3e8c14Smrg	  tstripme=$stripme
4711b290cf36Smrg	  case $host_os in
47128f9fac4aSmrg	  cygwin* | mingw* | windows* | pw32* | cegcc*)
4713b290cf36Smrg	    case $realname in
4714b290cf36Smrg	    *.dll.a)
4715ee3e8c14Smrg	      tstripme=
4716ee3e8c14Smrg	      ;;
4717ee3e8c14Smrg	    esac
4718ee3e8c14Smrg	    ;;
4719ee3e8c14Smrg	  os2*)
4720ee3e8c14Smrg	    case $realname in
4721ee3e8c14Smrg	    *_dll.a)
4722ee3e8c14Smrg	      tstripme=
4723b290cf36Smrg	      ;;
4724b290cf36Smrg	    esac
4725191cded7Smrg	    ;;
4726191cded7Smrg	  esac
4727b290cf36Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4728b290cf36Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4729191cded7Smrg	  fi
4730b290cf36Smrg
4731b290cf36Smrg	  if test "$#" -gt 0; then
4732b290cf36Smrg	    # Delete the old symlinks, and create new ones.
4733ee3e8c14Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4734b290cf36Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4735b290cf36Smrg	    # so we also need to try rm && ln -s.
4736b290cf36Smrg	    for linkname
4737b290cf36Smrg	    do
4738b290cf36Smrg	      test "$linkname" != "$realname" \
4739b290cf36Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4740191cded7Smrg	    done
4741191cded7Smrg	  fi
4742191cded7Smrg
4743b290cf36Smrg	  # Do each command in the postinstall commands.
4744ee3e8c14Smrg	  lib=$destdir/$realname
4745b290cf36Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4746191cded7Smrg	fi
4747191cded7Smrg
4748b290cf36Smrg	# Install the pseudo-library for information purposes.
4749b290cf36Smrg	func_basename "$file"
4750ee3e8c14Smrg	name=$func_basename_result
4751ee3e8c14Smrg	instname=$dir/${name}i
4752b290cf36Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4753191cded7Smrg
4754b290cf36Smrg	# Maybe install the static library, too.
4755d9dcd5aeSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4756b290cf36Smrg	;;
4757191cded7Smrg
4758b290cf36Smrg      *.lo)
4759b290cf36Smrg	# Install (i.e. copy) a libtool object.
4760191cded7Smrg
4761b290cf36Smrg	# Figure out destination file name, if it wasn't already specified.
4762b290cf36Smrg	if test -n "$destname"; then
4763ee3e8c14Smrg	  destfile=$destdir/$destname
4764b290cf36Smrg	else
4765b290cf36Smrg	  func_basename "$file"
4766ee3e8c14Smrg	  destfile=$func_basename_result
4767ee3e8c14Smrg	  destfile=$destdir/$destfile
4768b290cf36Smrg	fi
4769b290cf36Smrg
4770b290cf36Smrg	# Deduce the name of the destination old-style object file.
4771b290cf36Smrg	case $destfile in
4772b290cf36Smrg	*.lo)
4773b290cf36Smrg	  func_lo2o "$destfile"
4774b290cf36Smrg	  staticdest=$func_lo2o_result
4775b290cf36Smrg	  ;;
4776b290cf36Smrg	*.$objext)
4777ee3e8c14Smrg	  staticdest=$destfile
4778b290cf36Smrg	  destfile=
4779b290cf36Smrg	  ;;
4780b290cf36Smrg	*)
4781ee3e8c14Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4782b290cf36Smrg	  ;;
4783191cded7Smrg	esac
4784191cded7Smrg
4785b290cf36Smrg	# Install the libtool object if requested.
4786b290cf36Smrg	test -n "$destfile" && \
4787b290cf36Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4788b290cf36Smrg
4789b290cf36Smrg	# Install the old object if enabled.
4790ee3e8c14Smrg	if test yes = "$build_old_libs"; then
4791b290cf36Smrg	  # Deduce the name of the old-style object file.
4792b290cf36Smrg	  func_lo2o "$file"
4793b290cf36Smrg	  staticobj=$func_lo2o_result
4794b290cf36Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4795191cded7Smrg	fi
4796b290cf36Smrg	exit $EXIT_SUCCESS
4797b290cf36Smrg	;;
4798191cded7Smrg
4799b290cf36Smrg      *)
4800b290cf36Smrg	# Figure out destination file name, if it wasn't already specified.
4801b290cf36Smrg	if test -n "$destname"; then
4802ee3e8c14Smrg	  destfile=$destdir/$destname
4803b290cf36Smrg	else
4804b290cf36Smrg	  func_basename "$file"
4805ee3e8c14Smrg	  destfile=$func_basename_result
4806ee3e8c14Smrg	  destfile=$destdir/$destfile
4807b290cf36Smrg	fi
4808b290cf36Smrg
4809b290cf36Smrg	# If the file is missing, and there is a .exe on the end, strip it
4810b290cf36Smrg	# because it is most likely a libtool script we actually want to
4811b290cf36Smrg	# install
4812ee3e8c14Smrg	stripped_ext=
4813b290cf36Smrg	case $file in
4814b290cf36Smrg	  *.exe)
4815b290cf36Smrg	    if test ! -f "$file"; then
4816b290cf36Smrg	      func_stripname '' '.exe' "$file"
4817b290cf36Smrg	      file=$func_stripname_result
4818ee3e8c14Smrg	      stripped_ext=.exe
4819191cded7Smrg	    fi
4820b290cf36Smrg	    ;;
4821b290cf36Smrg	esac
4822191cded7Smrg
4823b290cf36Smrg	# Do a test to see if this is really a libtool program.
4824b290cf36Smrg	case $host in
48258f9fac4aSmrg	*cygwin* | *mingw* | *windows*)
4826b290cf36Smrg	    if func_ltwrapper_executable_p "$file"; then
4827b290cf36Smrg	      func_ltwrapper_scriptname "$file"
4828b290cf36Smrg	      wrapper=$func_ltwrapper_scriptname_result
4829b290cf36Smrg	    else
4830b290cf36Smrg	      func_stripname '' '.exe' "$file"
4831b290cf36Smrg	      wrapper=$func_stripname_result
4832b290cf36Smrg	    fi
4833b290cf36Smrg	    ;;
4834b290cf36Smrg	*)
4835b290cf36Smrg	    wrapper=$file
4836b290cf36Smrg	    ;;
4837b290cf36Smrg	esac
4838b290cf36Smrg	if func_ltwrapper_script_p "$wrapper"; then
4839b290cf36Smrg	  notinst_deplibs=
4840b290cf36Smrg	  relink_command=
4841191cded7Smrg
4842b290cf36Smrg	  func_source "$wrapper"
4843191cded7Smrg
4844b290cf36Smrg	  # Check the variables that should have been set.
4845b290cf36Smrg	  test -z "$generated_by_libtool_version" && \
4846ee3e8c14Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4847b290cf36Smrg
4848ee3e8c14Smrg	  finalize=:
4849b290cf36Smrg	  for lib in $notinst_deplibs; do
4850b290cf36Smrg	    # Check to see that each library is installed.
4851b290cf36Smrg	    libdir=
4852b290cf36Smrg	    if test -f "$lib"; then
4853b290cf36Smrg	      func_source "$lib"
4854b290cf36Smrg	    fi
4855ee3e8c14Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4856b290cf36Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4857ee3e8c14Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4858ee3e8c14Smrg	      finalize=false
4859b290cf36Smrg	    fi
4860b290cf36Smrg	  done
4861b290cf36Smrg
4862b290cf36Smrg	  relink_command=
4863b290cf36Smrg	  func_source "$wrapper"
4864b290cf36Smrg
4865b290cf36Smrg	  outputname=
4866ee3e8c14Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4867b290cf36Smrg	    $opt_dry_run || {
4868ee3e8c14Smrg	      if $finalize; then
4869b290cf36Smrg	        tmpdir=`func_mktempdir`
4870b290cf36Smrg		func_basename "$file$stripped_ext"
4871ee3e8c14Smrg		file=$func_basename_result
4872ee3e8c14Smrg	        outputname=$tmpdir/$file
4873b290cf36Smrg	        # Replace the output file specification.
4874ba064abeSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4875b290cf36Smrg
4876ee3e8c14Smrg	        $opt_quiet || {
4877ee3e8c14Smrg	          func_quote_arg expand,pretty "$relink_command"
4878ee3e8c14Smrg		  eval "func_echo $func_quote_arg_result"
4879b290cf36Smrg	        }
4880b290cf36Smrg	        if eval "$relink_command"; then :
4881b290cf36Smrg	          else
4882ee3e8c14Smrg		  func_error "error: relink '$file' with the above command before installing it"
4883b290cf36Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4884b290cf36Smrg		  continue
4885b290cf36Smrg	        fi
4886ee3e8c14Smrg	        file=$outputname
4887b290cf36Smrg	      else
4888ee3e8c14Smrg	        func_warning "cannot relink '$file'"
4889b290cf36Smrg	      fi
4890b290cf36Smrg	    }
4891191cded7Smrg	  else
4892b290cf36Smrg	    # Install the binary that we compiled earlier.
4893ba064abeSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4894191cded7Smrg	  fi
4895b290cf36Smrg	fi
4896191cded7Smrg
4897b290cf36Smrg	# remove .exe since cygwin /usr/bin/install will append another
4898b290cf36Smrg	# one anyway
4899b290cf36Smrg	case $install_prog,$host in
4900b290cf36Smrg	*/usr/bin/install*,*cygwin*)
4901b290cf36Smrg	  case $file:$destfile in
4902b290cf36Smrg	  *.exe:*.exe)
4903b290cf36Smrg	    # this is ok
4904b290cf36Smrg	    ;;
4905b290cf36Smrg	  *.exe:*)
4906b290cf36Smrg	    destfile=$destfile.exe
4907b290cf36Smrg	    ;;
4908b290cf36Smrg	  *:*.exe)
4909b290cf36Smrg	    func_stripname '' '.exe' "$destfile"
4910b290cf36Smrg	    destfile=$func_stripname_result
4911b290cf36Smrg	    ;;
4912b290cf36Smrg	  esac
4913191cded7Smrg	  ;;
4914191cded7Smrg	esac
4915b290cf36Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4916b290cf36Smrg	$opt_dry_run || if test -n "$outputname"; then
4917b290cf36Smrg	  ${RM}r "$tmpdir"
4918b290cf36Smrg	fi
4919b290cf36Smrg	;;
4920b290cf36Smrg      esac
4921b290cf36Smrg    done
4922191cded7Smrg
4923b290cf36Smrg    for file in $staticlibs; do
4924b290cf36Smrg      func_basename "$file"
4925ee3e8c14Smrg      name=$func_basename_result
4926191cded7Smrg
4927b290cf36Smrg      # Set up the ranlib parameters.
4928ee3e8c14Smrg      oldlib=$destdir/$name
4929d9dcd5aeSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4930d9dcd5aeSmrg      tool_oldlib=$func_to_tool_file_result
4931191cded7Smrg
4932b290cf36Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4933191cded7Smrg
4934b290cf36Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4935d9dcd5aeSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4936b290cf36Smrg      fi
4937191cded7Smrg
4938b290cf36Smrg      # Do each command in the postinstall commands.
4939b290cf36Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4940b290cf36Smrg    done
4941191cded7Smrg
4942b290cf36Smrg    test -n "$future_libdirs" && \
4943ee3e8c14Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4944191cded7Smrg
4945b290cf36Smrg    if test -n "$current_libdirs"; then
4946b290cf36Smrg      # Maybe just do a dry run.
4947b290cf36Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4948ee3e8c14Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4949b290cf36Smrg    else
4950b290cf36Smrg      exit $EXIT_SUCCESS
4951b290cf36Smrg    fi
4952b290cf36Smrg}
4953191cded7Smrg
4954ee3e8c14Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4955191cded7Smrg
4956191cded7Smrg
4957b290cf36Smrg# func_generate_dlsyms outputname originator pic_p
4958b290cf36Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4959b290cf36Smrg# a dlpreopen symbol table.
4960b290cf36Smrgfunc_generate_dlsyms ()
4961b290cf36Smrg{
4962ee3e8c14Smrg    $debug_cmd
4963ee3e8c14Smrg
4964ee3e8c14Smrg    my_outputname=$1
4965ee3e8c14Smrg    my_originator=$2
4966ee3e8c14Smrg    my_pic_p=${3-false}
4967ee3e8c14Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4968b290cf36Smrg    my_dlsyms=
4969b290cf36Smrg
4970ee3e8c14Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4971b290cf36Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4972ee3e8c14Smrg	my_dlsyms=${my_outputname}S.c
4973b290cf36Smrg      else
4974b290cf36Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4975b290cf36Smrg      fi
4976b290cf36Smrg    fi
4977191cded7Smrg
4978b290cf36Smrg    if test -n "$my_dlsyms"; then
4979b290cf36Smrg      case $my_dlsyms in
4980b290cf36Smrg      "") ;;
4981b290cf36Smrg      *.c)
4982b290cf36Smrg	# Discover the nlist of each of the dlfiles.
4983ee3e8c14Smrg	nlist=$output_objdir/$my_outputname.nm
4984b290cf36Smrg
4985b290cf36Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4986b290cf36Smrg
4987b290cf36Smrg	# Parse the name list into a source file.
4988b290cf36Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4989b290cf36Smrg
4990b290cf36Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4991ee3e8c14Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4992ee3e8c14Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4993b290cf36Smrg
4994b290cf36Smrg#ifdef __cplusplus
4995b290cf36Smrgextern \"C\" {
4996b290cf36Smrg#endif
4997b290cf36Smrg
4998ee3e8c14Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4999ba064abeSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
5000ba064abeSmrg#endif
5001ba064abeSmrg
5002d9dcd5aeSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
5003ee3e8c14Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
5004ee3e8c14Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
5005d9dcd5aeSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
5006d9dcd5aeSmrg# define LT_DLSYM_CONST
5007ee3e8c14Smrg#elif defined __osf__
5008d9dcd5aeSmrg/* This system does not cope well with relocations in const data.  */
5009d9dcd5aeSmrg# define LT_DLSYM_CONST
5010d9dcd5aeSmrg#else
5011d9dcd5aeSmrg# define LT_DLSYM_CONST const
5012d9dcd5aeSmrg#endif
5013d9dcd5aeSmrg
5014ee3e8c14Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5015ee3e8c14Smrg
5016b290cf36Smrg/* External symbol declarations for the compiler. */\
5017b290cf36Smrg"
5018b290cf36Smrg
5019ee3e8c14Smrg	if test yes = "$dlself"; then
5020ee3e8c14Smrg	  func_verbose "generating symbol list for '$output'"
5021b290cf36Smrg
5022b290cf36Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
5023b290cf36Smrg
5024b290cf36Smrg	  # Add our own program objects to the symbol list.
5025ba064abeSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
5026b290cf36Smrg	  for progfile in $progfiles; do
5027d9dcd5aeSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
5028ee3e8c14Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
5029d9dcd5aeSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
5030b290cf36Smrg	  done
5031b290cf36Smrg
5032b290cf36Smrg	  if test -n "$exclude_expsyms"; then
5033b290cf36Smrg	    $opt_dry_run || {
5034b290cf36Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
5035b290cf36Smrg	      eval '$MV "$nlist"T "$nlist"'
5036b290cf36Smrg	    }
5037191cded7Smrg	  fi
5038191cded7Smrg
5039b290cf36Smrg	  if test -n "$export_symbols_regex"; then
5040b290cf36Smrg	    $opt_dry_run || {
5041b290cf36Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
5042b290cf36Smrg	      eval '$MV "$nlist"T "$nlist"'
5043b290cf36Smrg	    }
5044191cded7Smrg	  fi
5045b290cf36Smrg
5046b290cf36Smrg	  # Prepare the list of exported symbols
5047b290cf36Smrg	  if test -z "$export_symbols"; then
5048ee3e8c14Smrg	    export_symbols=$output_objdir/$outputname.exp
5049b290cf36Smrg	    $opt_dry_run || {
5050b290cf36Smrg	      $RM $export_symbols
5051ee3e8c14Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
5052b290cf36Smrg	      case $host in
50538f9fac4aSmrg	      *cygwin* | *mingw* | *windows* | *cegcc* )
5054b290cf36Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5055b290cf36Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
5056b290cf36Smrg	        ;;
5057191cded7Smrg	      esac
5058b290cf36Smrg	    }
5059b290cf36Smrg	  else
5060b290cf36Smrg	    $opt_dry_run || {
5061ee3e8c14Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
5062b290cf36Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
5063b290cf36Smrg	      eval '$MV "$nlist"T "$nlist"'
5064b290cf36Smrg	      case $host in
50658f9fac4aSmrg	        *cygwin* | *mingw* | *windows* | *cegcc* )
5066b290cf36Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
5067b290cf36Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
5068b290cf36Smrg	          ;;
5069191cded7Smrg	      esac
5070b290cf36Smrg	    }
5071191cded7Smrg	  fi
5072b290cf36Smrg	fi
5073191cded7Smrg
5074b290cf36Smrg	for dlprefile in $dlprefiles; do
5075ee3e8c14Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
5076b290cf36Smrg	  func_basename "$dlprefile"
5077ee3e8c14Smrg	  name=$func_basename_result
5078d9dcd5aeSmrg          case $host in
50798f9fac4aSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
5080d9dcd5aeSmrg	      # if an import library, we need to obtain dlname
5081d9dcd5aeSmrg	      if func_win32_import_lib_p "$dlprefile"; then
5082d9dcd5aeSmrg	        func_tr_sh "$dlprefile"
5083d9dcd5aeSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
5084ee3e8c14Smrg	        dlprefile_dlbasename=
5085d9dcd5aeSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
5086d9dcd5aeSmrg	          # Use subshell, to avoid clobbering current variable values
5087d9dcd5aeSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
5088ee3e8c14Smrg	          if test -n "$dlprefile_dlname"; then
5089d9dcd5aeSmrg	            func_basename "$dlprefile_dlname"
5090ee3e8c14Smrg	            dlprefile_dlbasename=$func_basename_result
5091d9dcd5aeSmrg	          else
5092d9dcd5aeSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
5093d9dcd5aeSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
5094d9dcd5aeSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
5095d9dcd5aeSmrg	          fi
5096d9dcd5aeSmrg	        fi
5097d9dcd5aeSmrg	        $opt_dry_run || {
5098ee3e8c14Smrg	          if test -n "$dlprefile_dlbasename"; then
5099d9dcd5aeSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
5100d9dcd5aeSmrg	          else
5101d9dcd5aeSmrg	            func_warning "Could not compute DLL name from $name"
5102d9dcd5aeSmrg	            eval '$ECHO ": $name " >> "$nlist"'
5103d9dcd5aeSmrg	          fi
5104d9dcd5aeSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
51058f9fac4aSmrg	          case $host in
51068f9fac4aSmrg	            i[3456]86-*-mingw32*)
51078f9fac4aSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51088f9fac4aSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
51098f9fac4aSmrg	            ;;
51108f9fac4aSmrg	            *)
51118f9fac4aSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
51128f9fac4aSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'"
51138f9fac4aSmrg	            ;;
51148f9fac4aSmrg	          esac
5115d9dcd5aeSmrg	        }
5116d9dcd5aeSmrg	      else # not an import lib
5117d9dcd5aeSmrg	        $opt_dry_run || {
5118d9dcd5aeSmrg	          eval '$ECHO ": $name " >> "$nlist"'
5119d9dcd5aeSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
5120d9dcd5aeSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
5121d9dcd5aeSmrg	        }
5122d9dcd5aeSmrg	      fi
5123d9dcd5aeSmrg	    ;;
5124d9dcd5aeSmrg	    *)
5125d9dcd5aeSmrg	      $opt_dry_run || {
5126d9dcd5aeSmrg	        eval '$ECHO ": $name " >> "$nlist"'
5127d9dcd5aeSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
5128d9dcd5aeSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
5129d9dcd5aeSmrg	      }
5130d9dcd5aeSmrg	    ;;
5131d9dcd5aeSmrg          esac
5132b290cf36Smrg	done
5133191cded7Smrg
5134b290cf36Smrg	$opt_dry_run || {
5135b290cf36Smrg	  # Make sure we have at least an empty file.
5136b290cf36Smrg	  test -f "$nlist" || : > "$nlist"
5137191cded7Smrg
5138b290cf36Smrg	  if test -n "$exclude_expsyms"; then
5139b290cf36Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
5140b290cf36Smrg	    $MV "$nlist"T "$nlist"
5141191cded7Smrg	  fi
5142191cded7Smrg
5143b290cf36Smrg	  # Try sorting and uniquifying the output.
5144b290cf36Smrg	  if $GREP -v "^: " < "$nlist" |
5145b290cf36Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
5146b290cf36Smrg		sort -k 3
5147191cded7Smrg	      else
5148b290cf36Smrg		sort +2
5149b290cf36Smrg	      fi |
5150b290cf36Smrg	      uniq > "$nlist"S; then
5151b290cf36Smrg	    :
5152191cded7Smrg	  else
5153b290cf36Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5154191cded7Smrg	  fi
5155191cded7Smrg
5156b290cf36Smrg	  if test -f "$nlist"S; then
5157b290cf36Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5158191cded7Smrg	  else
5159ba064abeSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5160191cded7Smrg	  fi
5161191cded7Smrg
5162ee3e8c14Smrg	  func_show_eval '$RM "${nlist}I"'
5163ee3e8c14Smrg	  if test -n "$global_symbol_to_import"; then
5164ee3e8c14Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5165ee3e8c14Smrg	  fi
5166ee3e8c14Smrg
5167ba064abeSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5168191cded7Smrg
5169b290cf36Smrg/* The mapping between symbol names and symbols.  */
5170b290cf36Smrgtypedef struct {
5171b290cf36Smrg  const char *name;
5172b290cf36Smrg  void *address;
5173b290cf36Smrg} lt_dlsymlist;
5174d9dcd5aeSmrgextern LT_DLSYM_CONST lt_dlsymlist
5175ee3e8c14Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5176ee3e8c14Smrg"
5177ee3e8c14Smrg
5178ee3e8c14Smrg	  if test -s "$nlist"I; then
5179ee3e8c14Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5180ee3e8c14Smrgstatic void lt_syminit(void)
5181ee3e8c14Smrg{
5182ee3e8c14Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5183ee3e8c14Smrg  for (; symbol->name; ++symbol)
5184ee3e8c14Smrg    {"
5185ee3e8c14Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5186ee3e8c14Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5187ee3e8c14Smrg    }
5188ee3e8c14Smrg}"
5189ee3e8c14Smrg	  fi
5190ee3e8c14Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5191d9dcd5aeSmrgLT_DLSYM_CONST lt_dlsymlist
5192b290cf36Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5193ee3e8c14Smrg{ {\"$my_originator\", (void *) 0},"
5194ee3e8c14Smrg
5195ee3e8c14Smrg	  if test -s "$nlist"I; then
5196ee3e8c14Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5197ee3e8c14Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5198ee3e8c14Smrg	  fi
5199b290cf36Smrg
5200b290cf36Smrg	  case $need_lib_prefix in
5201b290cf36Smrg	  no)
5202b290cf36Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5203b290cf36Smrg	    ;;
5204b290cf36Smrg	  *)
5205b290cf36Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5206b290cf36Smrg	    ;;
5207b290cf36Smrg	  esac
5208ba064abeSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5209b290cf36Smrg  {0, (void *) 0}
5210b290cf36Smrg};
5211b290cf36Smrg
5212b290cf36Smrg/* This works around a problem in FreeBSD linker */
5213b290cf36Smrg#ifdef FREEBSD_WORKAROUND
5214b290cf36Smrgstatic const void *lt_preloaded_setup() {
5215b290cf36Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5216b290cf36Smrg}
5217b290cf36Smrg#endif
5218b290cf36Smrg
5219b290cf36Smrg#ifdef __cplusplus
5220b290cf36Smrg}
5221b290cf36Smrg#endif\
5222b290cf36Smrg"
5223b290cf36Smrg	} # !$opt_dry_run
5224b290cf36Smrg
5225b290cf36Smrg	pic_flag_for_symtable=
5226b290cf36Smrg	case "$compile_command " in
5227b290cf36Smrg	*" -static "*) ;;
5228b290cf36Smrg	*)
5229b290cf36Smrg	  case $host in
5230b290cf36Smrg	  # compiling the symbol table file with pic_flag works around
5231b290cf36Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5232b290cf36Smrg	  # linked before any other PIC object.  But we must not use
5233b290cf36Smrg	  # pic_flag when linking with -static.  The problem exists in
5234b290cf36Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5235d9dcd5aeSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5236b290cf36Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5237b290cf36Smrg	  *-*-hpux*)
5238b290cf36Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5239b290cf36Smrg	  *)
5240ee3e8c14Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5241b290cf36Smrg	    ;;
5242b290cf36Smrg	  esac
5243b290cf36Smrg	  ;;
5244b290cf36Smrg	esac
5245b290cf36Smrg	symtab_cflags=
5246b290cf36Smrg	for arg in $LTCFLAGS; do
5247b290cf36Smrg	  case $arg in
5248b290cf36Smrg	  -pie | -fpie | -fPIE) ;;
5249d9dcd5aeSmrg	  *) func_append symtab_cflags " $arg" ;;
5250b290cf36Smrg	  esac
5251b290cf36Smrg	done
5252191cded7Smrg
5253b290cf36Smrg	# Now compile the dynamic symbol file.
5254b290cf36Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5255191cded7Smrg
5256b290cf36Smrg	# Clean up the generated files.
5257ee3e8c14Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5258b290cf36Smrg
5259b290cf36Smrg	# Transform the symbol file into the correct name.
5260ee3e8c14Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5261b290cf36Smrg	case $host in
52628f9fac4aSmrg	*cygwin* | *mingw* | *windows* | *cegcc* )
5263b290cf36Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5264ba064abeSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5265ba064abeSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5266b290cf36Smrg	  else
5267ba064abeSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5268ba064abeSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5269b290cf36Smrg	  fi
5270b290cf36Smrg	  ;;
5271b290cf36Smrg	*)
5272ba064abeSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5273ba064abeSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5274191cded7Smrg	  ;;
5275191cded7Smrg	esac
5276b290cf36Smrg	;;
5277b290cf36Smrg      *)
5278ee3e8c14Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5279b290cf36Smrg	;;
5280b290cf36Smrg      esac
5281b290cf36Smrg    else
5282b290cf36Smrg      # We keep going just in case the user didn't refer to
5283b290cf36Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5284b290cf36Smrg      # really was required.
5285b290cf36Smrg
5286b290cf36Smrg      # Nullify the symbol file.
5287ba064abeSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5288ba064abeSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5289191cded7Smrg    fi
5290b290cf36Smrg}
5291191cded7Smrg
5292ee3e8c14Smrg# func_cygming_gnu_implib_p ARG
5293ee3e8c14Smrg# This predicate returns with zero status (TRUE) if
5294ee3e8c14Smrg# ARG is a GNU/binutils-style import library. Returns
5295ee3e8c14Smrg# with nonzero status (FALSE) otherwise.
5296ee3e8c14Smrgfunc_cygming_gnu_implib_p ()
5297ee3e8c14Smrg{
5298ee3e8c14Smrg  $debug_cmd
5299ee3e8c14Smrg
5300ee3e8c14Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5301ee3e8c14Smrg  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)$'`
5302ee3e8c14Smrg  test -n "$func_cygming_gnu_implib_tmp"
5303ee3e8c14Smrg}
5304ee3e8c14Smrg
5305ee3e8c14Smrg# func_cygming_ms_implib_p ARG
5306ee3e8c14Smrg# This predicate returns with zero status (TRUE) if
5307ee3e8c14Smrg# ARG is an MS-style import library. Returns
5308ee3e8c14Smrg# with nonzero status (FALSE) otherwise.
5309ee3e8c14Smrgfunc_cygming_ms_implib_p ()
5310ee3e8c14Smrg{
5311ee3e8c14Smrg  $debug_cmd
5312ee3e8c14Smrg
5313ee3e8c14Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5314ee3e8c14Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5315ee3e8c14Smrg  test -n "$func_cygming_ms_implib_tmp"
5316ee3e8c14Smrg}
5317ee3e8c14Smrg
5318b290cf36Smrg# func_win32_libid arg
5319b290cf36Smrg# return the library type of file 'arg'
5320b290cf36Smrg#
5321b290cf36Smrg# Need a lot of goo to handle *both* DLLs and import libs
5322b290cf36Smrg# Has to be a shell function in order to 'eat' the argument
5323b290cf36Smrg# that is supplied when $file_magic_command is called.
5324ba064abeSmrg# Despite the name, also deal with 64 bit binaries.
5325b290cf36Smrgfunc_win32_libid ()
5326b290cf36Smrg{
5327ee3e8c14Smrg  $debug_cmd
5328ee3e8c14Smrg
5329ee3e8c14Smrg  win32_libid_type=unknown
5330b290cf36Smrg  win32_fileres=`file -L $1 2>/dev/null`
5331b290cf36Smrg  case $win32_fileres in
5332b290cf36Smrg  *ar\ archive\ import\ library*) # definitely import
5333b290cf36Smrg    win32_libid_type="x86 archive import"
5334b290cf36Smrg    ;;
5335b290cf36Smrg  *ar\ archive*) # could be an import, or static
5336ba064abeSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5337b290cf36Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
53388f9fac4aSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then
5339ee3e8c14Smrg      case $nm_interface in
5340ee3e8c14Smrg      "MS dumpbin")
5341ee3e8c14Smrg	if func_cygming_ms_implib_p "$1" ||
5342ee3e8c14Smrg	   func_cygming_gnu_implib_p "$1"
5343ee3e8c14Smrg	then
5344ee3e8c14Smrg	  win32_nmres=import
5345ee3e8c14Smrg	else
5346ee3e8c14Smrg	  win32_nmres=
5347ee3e8c14Smrg	fi
5348ee3e8c14Smrg	;;
5349ee3e8c14Smrg      *)
5350ee3e8c14Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5351ee3e8c14Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5352ee3e8c14Smrg	  $SED -n -e '
5353b290cf36Smrg	    1,100{
5354b290cf36Smrg		/ I /{
5355ee3e8c14Smrg		    s|.*|import|
5356b290cf36Smrg		    p
5357b290cf36Smrg		    q
5358b290cf36Smrg		}
5359b290cf36Smrg	    }'`
5360ee3e8c14Smrg	;;
5361ee3e8c14Smrg      esac
5362b290cf36Smrg      case $win32_nmres in
5363b290cf36Smrg      import*)  win32_libid_type="x86 archive import";;
5364b290cf36Smrg      *)        win32_libid_type="x86 archive static";;
5365b290cf36Smrg      esac
5366b290cf36Smrg    fi
5367b290cf36Smrg    ;;
5368b290cf36Smrg  *DLL*)
5369b290cf36Smrg    win32_libid_type="x86 DLL"
5370b290cf36Smrg    ;;
5371b290cf36Smrg  *executable*) # but shell scripts are "executable" too...
5372b290cf36Smrg    case $win32_fileres in
5373b290cf36Smrg    *MS\ Windows\ PE\ Intel*)
5374b290cf36Smrg      win32_libid_type="x86 DLL"
5375b290cf36Smrg      ;;
5376b290cf36Smrg    esac
5377b290cf36Smrg    ;;
5378b290cf36Smrg  esac
5379b290cf36Smrg  $ECHO "$win32_libid_type"
5380b290cf36Smrg}
5381191cded7Smrg
5382d9dcd5aeSmrg# func_cygming_dll_for_implib ARG
5383d9dcd5aeSmrg#
5384d9dcd5aeSmrg# Platform-specific function to extract the
5385d9dcd5aeSmrg# name of the DLL associated with the specified
5386d9dcd5aeSmrg# import library ARG.
5387d9dcd5aeSmrg# Invoked by eval'ing the libtool variable
5388d9dcd5aeSmrg#    $sharedlib_from_linklib_cmd
5389d9dcd5aeSmrg# Result is available in the variable
5390d9dcd5aeSmrg#    $sharedlib_from_linklib_result
5391d9dcd5aeSmrgfunc_cygming_dll_for_implib ()
5392d9dcd5aeSmrg{
5393ee3e8c14Smrg  $debug_cmd
5394ee3e8c14Smrg
5395d9dcd5aeSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5396d9dcd5aeSmrg}
5397d9dcd5aeSmrg
5398d9dcd5aeSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5399d9dcd5aeSmrg#
5400d9dcd5aeSmrg# The is the core of a fallback implementation of a
5401d9dcd5aeSmrg# platform-specific function to extract the name of the
5402d9dcd5aeSmrg# DLL associated with the specified import library LIBNAME.
5403d9dcd5aeSmrg#
5404d9dcd5aeSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5405d9dcd5aeSmrg# on the platform and compiler that created the implib.
5406d9dcd5aeSmrg#
5407d9dcd5aeSmrg# Echos the name of the DLL associated with the
5408d9dcd5aeSmrg# specified import library.
5409d9dcd5aeSmrgfunc_cygming_dll_for_implib_fallback_core ()
5410d9dcd5aeSmrg{
5411ee3e8c14Smrg  $debug_cmd
5412ee3e8c14Smrg
5413d9dcd5aeSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5414d9dcd5aeSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5415d9dcd5aeSmrg    $SED '/^Contents of section '"$match_literal"':/{
5416d9dcd5aeSmrg      # Place marker at beginning of archive member dllname section
5417d9dcd5aeSmrg      s/.*/====MARK====/
5418d9dcd5aeSmrg      p
5419d9dcd5aeSmrg      d
5420d9dcd5aeSmrg    }
5421d9dcd5aeSmrg    # These lines can sometimes be longer than 43 characters, but
5422d9dcd5aeSmrg    # are always uninteresting
5423d9dcd5aeSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5424d9dcd5aeSmrg    /^In archive [^:]*:/d
5425d9dcd5aeSmrg    # Ensure marker is printed
5426d9dcd5aeSmrg    /^====MARK====/p
5427d9dcd5aeSmrg    # Remove all lines with less than 43 characters
5428d9dcd5aeSmrg    /^.\{43\}/!d
5429d9dcd5aeSmrg    # From remaining lines, remove first 43 characters
5430d9dcd5aeSmrg    s/^.\{43\}//' |
5431d9dcd5aeSmrg    $SED -n '
5432d9dcd5aeSmrg      # Join marker and all lines until next marker into a single line
5433d9dcd5aeSmrg      /^====MARK====/ b para
5434d9dcd5aeSmrg      H
5435d9dcd5aeSmrg      $ b para
5436d9dcd5aeSmrg      b
5437d9dcd5aeSmrg      :para
5438d9dcd5aeSmrg      x
5439d9dcd5aeSmrg      s/\n//g
5440d9dcd5aeSmrg      # Remove the marker
5441d9dcd5aeSmrg      s/^====MARK====//
5442d9dcd5aeSmrg      # Remove trailing dots and whitespace
5443d9dcd5aeSmrg      s/[\. \t]*$//
5444d9dcd5aeSmrg      # Print
5445d9dcd5aeSmrg      /./p' |
5446d9dcd5aeSmrg    # we now have a list, one entry per line, of the stringified
5447d9dcd5aeSmrg    # contents of the appropriate section of all members of the
5448ee3e8c14Smrg    # archive that possess that section. Heuristic: eliminate
5449ee3e8c14Smrg    # all those that have a first or second character that is
5450d9dcd5aeSmrg    # a '.' (that is, objdump's representation of an unprintable
5451d9dcd5aeSmrg    # character.) This should work for all archives with less than
5452d9dcd5aeSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5453d9dcd5aeSmrg    # begins with a literal '.' or a single character followed by
5454d9dcd5aeSmrg    # a '.'.
5455d9dcd5aeSmrg    #
5456d9dcd5aeSmrg    # Of those that remain, print the first one.
5457d9dcd5aeSmrg    $SED -e '/^\./d;/^.\./d;q'
5458d9dcd5aeSmrg}
5459d9dcd5aeSmrg
5460d9dcd5aeSmrg# func_cygming_dll_for_implib_fallback ARG
5461d9dcd5aeSmrg# Platform-specific function to extract the
5462d9dcd5aeSmrg# name of the DLL associated with the specified
5463d9dcd5aeSmrg# import library ARG.
5464d9dcd5aeSmrg#
5465d9dcd5aeSmrg# This fallback implementation is for use when $DLLTOOL
5466d9dcd5aeSmrg# does not support the --identify-strict option.
5467d9dcd5aeSmrg# Invoked by eval'ing the libtool variable
5468d9dcd5aeSmrg#    $sharedlib_from_linklib_cmd
5469d9dcd5aeSmrg# Result is available in the variable
5470d9dcd5aeSmrg#    $sharedlib_from_linklib_result
5471d9dcd5aeSmrgfunc_cygming_dll_for_implib_fallback ()
5472d9dcd5aeSmrg{
5473ee3e8c14Smrg  $debug_cmd
5474ee3e8c14Smrg
5475ee3e8c14Smrg  if func_cygming_gnu_implib_p "$1"; then
5476d9dcd5aeSmrg    # binutils import library
5477d9dcd5aeSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5478ee3e8c14Smrg  elif func_cygming_ms_implib_p "$1"; then
5479d9dcd5aeSmrg    # ms-generated import library
5480d9dcd5aeSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5481d9dcd5aeSmrg  else
5482d9dcd5aeSmrg    # unknown
5483ee3e8c14Smrg    sharedlib_from_linklib_result=
5484d9dcd5aeSmrg  fi
5485d9dcd5aeSmrg}
5486191cded7Smrg
5487191cded7Smrg
5488b290cf36Smrg# func_extract_an_archive dir oldlib
5489b290cf36Smrgfunc_extract_an_archive ()
5490b290cf36Smrg{
5491ee3e8c14Smrg    $debug_cmd
5492ee3e8c14Smrg
5493ee3e8c14Smrg    f_ex_an_ar_dir=$1; shift
5494ee3e8c14Smrg    f_ex_an_ar_oldlib=$1
5495ee3e8c14Smrg    if test yes = "$lock_old_archive_extraction"; then
5496ba064abeSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5497ba064abeSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5498ba064abeSmrg	func_echo "Waiting for $lockfile to be removed"
5499ba064abeSmrg	sleep 2
5500ba064abeSmrg      done
5501ba064abeSmrg    fi
5502ba064abeSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5503ba064abeSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5504ee3e8c14Smrg    if test yes = "$lock_old_archive_extraction"; then
5505ba064abeSmrg      $opt_dry_run || rm -f "$lockfile"
5506ba064abeSmrg    fi
5507b290cf36Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5508b290cf36Smrg     :
5509b290cf36Smrg    else
5510b290cf36Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5511b290cf36Smrg    fi
5512b290cf36Smrg}
5513191cded7Smrg
5514191cded7Smrg
5515b290cf36Smrg# func_extract_archives gentop oldlib ...
5516b290cf36Smrgfunc_extract_archives ()
5517b290cf36Smrg{
5518ee3e8c14Smrg    $debug_cmd
5519ee3e8c14Smrg
5520ee3e8c14Smrg    my_gentop=$1; shift
5521b290cf36Smrg    my_oldlibs=${1+"$@"}
5522ee3e8c14Smrg    my_oldobjs=
5523ee3e8c14Smrg    my_xlib=
5524ee3e8c14Smrg    my_xabs=
5525ee3e8c14Smrg    my_xdir=
5526191cded7Smrg
5527b290cf36Smrg    for my_xlib in $my_oldlibs; do
5528b290cf36Smrg      # Extract the objects.
5529b290cf36Smrg      case $my_xlib in
5530ee3e8c14Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5531b290cf36Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5532b290cf36Smrg      esac
5533b290cf36Smrg      func_basename "$my_xlib"
5534ee3e8c14Smrg      my_xlib=$func_basename_result
5535b290cf36Smrg      my_xlib_u=$my_xlib
5536b290cf36Smrg      while :; do
5537b290cf36Smrg        case " $extracted_archives " in
5538b290cf36Smrg	*" $my_xlib_u "*)
5539b290cf36Smrg	  func_arith $extracted_serial + 1
5540b290cf36Smrg	  extracted_serial=$func_arith_result
5541b290cf36Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5542b290cf36Smrg	*) break ;;
5543b290cf36Smrg	esac
5544b290cf36Smrg      done
5545b290cf36Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5546ee3e8c14Smrg      my_xdir=$my_gentop/$my_xlib_u
5547191cded7Smrg
5548b290cf36Smrg      func_mkdir_p "$my_xdir"
5549191cded7Smrg
5550b290cf36Smrg      case $host in
5551b290cf36Smrg      *-darwin*)
5552b290cf36Smrg	func_verbose "Extracting $my_xabs"
5553b290cf36Smrg	# Do not bother doing anything if just a dry run
5554b290cf36Smrg	$opt_dry_run || {
5555b290cf36Smrg	  darwin_orig_dir=`pwd`
5556b290cf36Smrg	  cd $my_xdir || exit $?
5557b290cf36Smrg	  darwin_archive=$my_xabs
5558b290cf36Smrg	  darwin_curdir=`pwd`
5559ee3e8c14Smrg	  func_basename "$darwin_archive"
5560ee3e8c14Smrg	  darwin_base_archive=$func_basename_result
5561b290cf36Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5562b290cf36Smrg	  if test -n "$darwin_arches"; then
5563b290cf36Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5564b290cf36Smrg	    darwin_arch=
5565b290cf36Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5566ee3e8c14Smrg	    for darwin_arch in  $darwin_arches; do
5567ee3e8c14Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5568ee3e8c14Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5569ee3e8c14Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5570ee3e8c14Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5571b290cf36Smrg	      cd "$darwin_curdir"
5572ee3e8c14Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5573b290cf36Smrg	    done # $darwin_arches
5574b290cf36Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5575ee3e8c14Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5576b290cf36Smrg	    darwin_file=
5577b290cf36Smrg	    darwin_files=
5578b290cf36Smrg	    for darwin_file in $darwin_filelist; do
5579ba064abeSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5580b290cf36Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5581b290cf36Smrg	    done # $darwin_filelist
5582b290cf36Smrg	    $RM -rf unfat-$$
5583b290cf36Smrg	    cd "$darwin_orig_dir"
5584b290cf36Smrg	  else
5585b290cf36Smrg	    cd $darwin_orig_dir
5586b290cf36Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5587b290cf36Smrg	  fi # $darwin_arches
5588b290cf36Smrg	} # !$opt_dry_run
5589b290cf36Smrg	;;
5590b290cf36Smrg      *)
5591b290cf36Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5592b290cf36Smrg	;;
5593191cded7Smrg      esac
5594ba064abeSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5595b290cf36Smrg    done
5596191cded7Smrg
5597ee3e8c14Smrg    func_extract_archives_result=$my_oldobjs
5598b290cf36Smrg}
5599191cded7Smrg
5600191cded7Smrg
5601ba064abeSmrg# func_emit_wrapper [arg=no]
5602ba064abeSmrg#
5603ba064abeSmrg# Emit a libtool wrapper script on stdout.
5604ba064abeSmrg# Don't directly open a file because we may want to
56058f9fac4aSmrg# incorporate the script contents within a cygwin/mingw/windows
5606ba064abeSmrg# wrapper executable.  Must ONLY be called from within
5607ba064abeSmrg# func_mode_link because it depends on a number of variables
5608ba064abeSmrg# set therein.
5609b290cf36Smrg#
5610ba064abeSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5611ba064abeSmrg# variable will take.  If 'yes', then the emitted script
5612ee3e8c14Smrg# will assume that the directory where it is stored is
56138f9fac4aSmrg# the $objdir directory.  This is a cygwin/mingw/windows-specific
5614ba064abeSmrg# behavior.
5615ba064abeSmrgfunc_emit_wrapper ()
5616b290cf36Smrg{
5617ba064abeSmrg	func_emit_wrapper_arg1=${1-no}
5618191cded7Smrg
5619b290cf36Smrg	$ECHO "\
5620b290cf36Smrg#! $SHELL
5621191cded7Smrg
5622b290cf36Smrg# $output - temporary wrapper script for $objdir/$outputname
5623ee3e8c14Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5624b290cf36Smrg#
5625b290cf36Smrg# The $output program cannot be directly executed until all the libtool
5626b290cf36Smrg# libraries that it depends on are installed.
5627b290cf36Smrg#
5628b290cf36Smrg# This wrapper script should never be moved out of the build directory.
5629b290cf36Smrg# If it is, it will not operate correctly.
5630191cded7Smrg
5631b290cf36Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5632b290cf36Smrg# metacharacters that are still active within double-quoted strings.
5633b290cf36Smrgsed_quote_subst='$sed_quote_subst'
5634191cded7Smrg
5635b290cf36Smrg# Be Bourne compatible
5636b290cf36Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5637b290cf36Smrg  emulate sh
5638b290cf36Smrg  NULLCMD=:
5639b290cf36Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5640b290cf36Smrg  # is contrary to our usage.  Disable this feature.
5641b290cf36Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5642b290cf36Smrg  setopt NO_GLOB_SUBST
5643b290cf36Smrgelse
5644b290cf36Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5645b290cf36Smrgfi
5646b290cf36SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5647b290cf36SmrgDUALCASE=1; export DUALCASE # for MKS sh
5648191cded7Smrg
5649b290cf36Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5650b290cf36Smrg# if CDPATH is set.
5651b290cf36Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5652191cded7Smrg
5653b290cf36Smrgrelink_command=\"$relink_command\"
5654191cded7Smrg
5655b290cf36Smrg# This environment variable determines our operation mode.
5656b290cf36Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5657b290cf36Smrg  # install mode needs the following variables:
5658b290cf36Smrg  generated_by_libtool_version='$macro_version'
5659b290cf36Smrg  notinst_deplibs='$notinst_deplibs'
5660b290cf36Smrgelse
5661b290cf36Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5662b290cf36Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5663ba064abeSmrg    file=\"\$0\""
5664ba064abeSmrg
5665ee3e8c14Smrg    func_quote_arg pretty "$ECHO"
5666ee3e8c14Smrg    qECHO=$func_quote_arg_result
5667ba064abeSmrg    $ECHO "\
5668ba064abeSmrg
5669ba064abeSmrg# A function that is used when there is no print builtin or printf.
5670ba064abeSmrgfunc_fallback_echo ()
5671ba064abeSmrg{
5672ba064abeSmrg  eval 'cat <<_LTECHO_EOF
5673ba064abeSmrg\$1
5674ba064abeSmrg_LTECHO_EOF'
5675ba064abeSmrg}
5676ee3e8c14Smrg    ECHO=$qECHO
5677ba064abeSmrg  fi
5678ba064abeSmrg
5679ba064abeSmrg# Very basic option parsing. These options are (a) specific to
5680ba064abeSmrg# the libtool wrapper, (b) are identical between the wrapper
5681ee3e8c14Smrg# /script/ and the wrapper /executable/ that is used only on
5682ba064abeSmrg# windows platforms, and (c) all begin with the string "--lt-"
5683ee3e8c14Smrg# (application programs are unlikely to have options that match
5684ba064abeSmrg# this pattern).
5685ba064abeSmrg#
5686ba064abeSmrg# There are only two supported options: --lt-debug and
5687ba064abeSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5688ba064abeSmrg#
5689ba064abeSmrg# The first argument to this parsing function should be the
5690ba064abeSmrg# script's $0 value, followed by "$@".
5691ba064abeSmrglt_option_debug=
5692ba064abeSmrgfunc_parse_lt_options ()
5693ba064abeSmrg{
5694ba064abeSmrg  lt_script_arg0=\$0
5695ba064abeSmrg  shift
5696ba064abeSmrg  for lt_opt
5697ba064abeSmrg  do
5698ba064abeSmrg    case \"\$lt_opt\" in
5699ba064abeSmrg    --lt-debug) lt_option_debug=1 ;;
5700ba064abeSmrg    --lt-dump-script)
5701ba064abeSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5702ba064abeSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5703ba064abeSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5704ba064abeSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5705ba064abeSmrg        exit 0
5706ba064abeSmrg      ;;
5707ba064abeSmrg    --lt-*)
5708ba064abeSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5709ba064abeSmrg        exit 1
5710ba064abeSmrg      ;;
5711ba064abeSmrg    esac
5712ba064abeSmrg  done
5713ba064abeSmrg
5714ba064abeSmrg  # Print the debug banner immediately:
5715ba064abeSmrg  if test -n \"\$lt_option_debug\"; then
5716ee3e8c14Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5717ba064abeSmrg  fi
5718ba064abeSmrg}
5719ba064abeSmrg
5720ba064abeSmrg# Used when --lt-debug. Prints its arguments to stdout
5721ba064abeSmrg# (redirection is the responsibility of the caller)
5722ba064abeSmrgfunc_lt_dump_args ()
5723ba064abeSmrg{
5724ba064abeSmrg  lt_dump_args_N=1;
5725ba064abeSmrg  for lt_arg
5726ba064abeSmrg  do
5727ee3e8c14Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5728ba064abeSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5729ba064abeSmrg  done
5730ba064abeSmrg}
5731ba064abeSmrg
5732ba064abeSmrg# Core function for launching the target application
5733ba064abeSmrgfunc_exec_program_core ()
5734ba064abeSmrg{
5735b290cf36Smrg"
5736ba064abeSmrg  case $host in
5737ba064abeSmrg  # Backslashes separate directories on plain windows
57388f9fac4aSmrg  *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*)
5739ba064abeSmrg    $ECHO "\
5740ba064abeSmrg      if test -n \"\$lt_option_debug\"; then
5741ee3e8c14Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5742ba064abeSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5743ba064abeSmrg      fi
5744ba064abeSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5745ba064abeSmrg"
5746ba064abeSmrg    ;;
5747ba064abeSmrg
5748ba064abeSmrg  *)
5749ba064abeSmrg    $ECHO "\
5750ba064abeSmrg      if test -n \"\$lt_option_debug\"; then
5751ee3e8c14Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5752ba064abeSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5753ba064abeSmrg      fi
5754ba064abeSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5755ba064abeSmrg"
5756ba064abeSmrg    ;;
5757ba064abeSmrg  esac
5758ba064abeSmrg  $ECHO "\
5759ba064abeSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5760ba064abeSmrg      exit 1
5761ba064abeSmrg}
5762ba064abeSmrg
5763ba064abeSmrg# A function to encapsulate launching the target application
5764ba064abeSmrg# Strips options in the --lt-* namespace from \$@ and
5765ba064abeSmrg# launches target application with the remaining arguments.
5766ba064abeSmrgfunc_exec_program ()
5767ba064abeSmrg{
5768d9dcd5aeSmrg  case \" \$* \" in
5769d9dcd5aeSmrg  *\\ --lt-*)
5770d9dcd5aeSmrg    for lt_wr_arg
5771d9dcd5aeSmrg    do
5772d9dcd5aeSmrg      case \$lt_wr_arg in
5773d9dcd5aeSmrg      --lt-*) ;;
5774d9dcd5aeSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5775d9dcd5aeSmrg      esac
5776d9dcd5aeSmrg      shift
5777d9dcd5aeSmrg    done ;;
5778d9dcd5aeSmrg  esac
5779ba064abeSmrg  func_exec_program_core \${1+\"\$@\"}
5780ba064abeSmrg}
5781ba064abeSmrg
5782ba064abeSmrg  # Parse options
5783ba064abeSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5784191cded7Smrg
5785b290cf36Smrg  # Find the directory that this script lives in.
5786ba064abeSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5787b290cf36Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5788191cded7Smrg
5789b290cf36Smrg  # Follow symbolic links until we get to the real thisdir.
5790ba064abeSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5791b290cf36Smrg  while test -n \"\$file\"; do
5792ba064abeSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5793191cded7Smrg
5794b290cf36Smrg    # If there was a directory component, then change thisdir.
5795b290cf36Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5796b290cf36Smrg      case \"\$destdir\" in
5797b290cf36Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5798b290cf36Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5799b290cf36Smrg      esac
5800b290cf36Smrg    fi
5801191cded7Smrg
5802ba064abeSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5803ba064abeSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5804b290cf36Smrg  done
5805191cded7Smrg
58068f9fac4aSmrg  # Usually 'no', except on cygwin/mingw/windows when embedded into
5807b290cf36Smrg  # the cwrapper.
5808ba064abeSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5809b290cf36Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5810b290cf36Smrg    # special case for '.'
5811b290cf36Smrg    if test \"\$thisdir\" = \".\"; then
5812b290cf36Smrg      thisdir=\`pwd\`
5813b290cf36Smrg    fi
5814b290cf36Smrg    # remove .libs from thisdir
5815b290cf36Smrg    case \"\$thisdir\" in
5816ba064abeSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5817b290cf36Smrg    $objdir )   thisdir=. ;;
5818b290cf36Smrg    esac
5819b290cf36Smrg  fi
5820191cded7Smrg
5821b290cf36Smrg  # Try to get the absolute directory name.
5822b290cf36Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5823b290cf36Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5824b290cf36Smrg"
5825191cded7Smrg
5826ee3e8c14Smrg	if test yes = "$fast_install"; then
5827b290cf36Smrg	  $ECHO "\
5828b290cf36Smrg  program=lt-'$outputname'$exeext
5829b290cf36Smrg  progdir=\"\$thisdir/$objdir\"
5830191cded7Smrg
5831b290cf36Smrg  if test ! -f \"\$progdir/\$program\" ||
5832ee3e8c14Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5833b290cf36Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5834191cded7Smrg
5835b290cf36Smrg    file=\"\$\$-\$program\"
5836191cded7Smrg
5837b290cf36Smrg    if test ! -d \"\$progdir\"; then
5838b290cf36Smrg      $MKDIR \"\$progdir\"
5839b290cf36Smrg    else
5840b290cf36Smrg      $RM \"\$progdir/\$file\"
5841b290cf36Smrg    fi"
5842191cded7Smrg
5843b290cf36Smrg	  $ECHO "\
5844191cded7Smrg
5845b290cf36Smrg    # relink executable if necessary
5846b290cf36Smrg    if test -n \"\$relink_command\"; then
5847b290cf36Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5848b290cf36Smrg      else
5849ee3e8c14Smrg	\$ECHO \"\$relink_command_output\" >&2
5850b290cf36Smrg	$RM \"\$progdir/\$file\"
5851b290cf36Smrg	exit 1
5852b290cf36Smrg      fi
5853b290cf36Smrg    fi
5854191cded7Smrg
5855b290cf36Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5856b290cf36Smrg    { $RM \"\$progdir/\$program\";
5857b290cf36Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5858b290cf36Smrg    $RM \"\$progdir/\$file\"
5859b290cf36Smrg  fi"
5860b290cf36Smrg	else
5861b290cf36Smrg	  $ECHO "\
5862b290cf36Smrg  program='$outputname'
5863b290cf36Smrg  progdir=\"\$thisdir/$objdir\"
5864b290cf36Smrg"
5865b290cf36Smrg	fi
5866191cded7Smrg
5867b290cf36Smrg	$ECHO "\
5868191cded7Smrg
5869b290cf36Smrg  if test -f \"\$progdir/\$program\"; then"
5870191cded7Smrg
5871d9dcd5aeSmrg	# fixup the dll searchpath if we need to.
5872d9dcd5aeSmrg	#
5873d9dcd5aeSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5874d9dcd5aeSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5875d9dcd5aeSmrg	# libraries must come first.
5876d9dcd5aeSmrg	if test -n "$dllsearchpath"; then
5877d9dcd5aeSmrg	  $ECHO "\
5878d9dcd5aeSmrg    # Add the dll search path components to the executable PATH
5879d9dcd5aeSmrg    PATH=$dllsearchpath:\$PATH
5880d9dcd5aeSmrg"
5881d9dcd5aeSmrg	fi
5882d9dcd5aeSmrg
5883b290cf36Smrg	# Export our shlibpath_var if we have one.
5884ee3e8c14Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5885b290cf36Smrg	  $ECHO "\
5886b290cf36Smrg    # Add our own library path to $shlibpath_var
5887b290cf36Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5888191cded7Smrg
5889b290cf36Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5890b290cf36Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5891ba064abeSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5892191cded7Smrg
5893b290cf36Smrg    export $shlibpath_var
5894b290cf36Smrg"
5895191cded7Smrg	fi
5896191cded7Smrg
5897b290cf36Smrg	$ECHO "\
5898b290cf36Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5899b290cf36Smrg      # Run the actual program with our arguments.
5900ba064abeSmrg      func_exec_program \${1+\"\$@\"}
5901b290cf36Smrg    fi
5902b290cf36Smrg  else
5903b290cf36Smrg    # The program doesn't exist.
5904ee3e8c14Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5905b290cf36Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5906ba064abeSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5907b290cf36Smrg    exit 1
5908b290cf36Smrg  fi
5909b290cf36Smrgfi\
5910b290cf36Smrg"
5911b290cf36Smrg}
5912191cded7Smrg
5913191cded7Smrg
5914b290cf36Smrg# func_emit_cwrapperexe_src
5915b290cf36Smrg# emit the source code for a wrapper executable on stdout
5916b290cf36Smrg# Must ONLY be called from within func_mode_link because
5917b290cf36Smrg# it depends on a number of variable set therein.
5918b290cf36Smrgfunc_emit_cwrapperexe_src ()
5919b290cf36Smrg{
5920b290cf36Smrg	cat <<EOF
5921191cded7Smrg
5922b290cf36Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5923ee3e8c14Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5924191cded7Smrg
5925b290cf36Smrg   The $output program cannot be directly executed until all the libtool
5926b290cf36Smrg   libraries that it depends on are installed.
5927191cded7Smrg
5928b290cf36Smrg   This wrapper executable should never be moved out of the build directory.
5929b290cf36Smrg   If it is, it will not operate correctly.
5930b290cf36Smrg*/
5931b290cf36SmrgEOF
5932b290cf36Smrg	    cat <<"EOF"
5933ba064abeSmrg#ifdef _MSC_VER
5934ba064abeSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5935ba064abeSmrg#endif
5936b290cf36Smrg#include <stdio.h>
5937b290cf36Smrg#include <stdlib.h>
59388f9fac4aSmrg#if defined _WIN32 && !defined __GNUC__
5939b290cf36Smrg# include <direct.h>
5940b290cf36Smrg# include <process.h>
5941b290cf36Smrg# include <io.h>
5942b290cf36Smrg#else
5943b290cf36Smrg# include <unistd.h>
5944b290cf36Smrg# include <stdint.h>
5945b290cf36Smrg# ifdef __CYGWIN__
5946b290cf36Smrg#  include <io.h>
5947b290cf36Smrg# endif
5948b290cf36Smrg#endif
5949b290cf36Smrg#include <malloc.h>
5950b290cf36Smrg#include <stdarg.h>
5951b290cf36Smrg#include <assert.h>
5952b290cf36Smrg#include <string.h>
5953b290cf36Smrg#include <ctype.h>
5954b290cf36Smrg#include <errno.h>
5955b290cf36Smrg#include <fcntl.h>
5956b290cf36Smrg#include <sys/stat.h>
5957b290cf36Smrg
5958ee3e8c14Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5959ee3e8c14Smrg
5960ba064abeSmrg/* declarations of non-ANSI functions */
5961ee3e8c14Smrg#if defined __MINGW32__
5962ba064abeSmrg# ifdef __STRICT_ANSI__
59638f9fac4aSmrg_CRTIMP int __cdecl _putenv (const char *);
5964ba064abeSmrg# endif
5965ee3e8c14Smrg#elif defined __CYGWIN__
5966ba064abeSmrg# ifdef __STRICT_ANSI__
5967ba064abeSmrgchar *realpath (const char *, char *);
5968ba064abeSmrgint putenv (char *);
5969ba064abeSmrgint setenv (const char *, const char *, int);
5970ba064abeSmrg# endif
5971ee3e8c14Smrg/* #elif defined other_platform || defined ... */
5972ba064abeSmrg#endif
5973ba064abeSmrg
5974ba064abeSmrg/* portability defines, excluding path handling macros */
5975ee3e8c14Smrg#if defined _MSC_VER
5976ba064abeSmrg# define setmode _setmode
5977ba064abeSmrg# define stat    _stat
5978ba064abeSmrg# define chmod   _chmod
5979ba064abeSmrg# define getcwd  _getcwd
5980ba064abeSmrg# define putenv  _putenv
5981ba064abeSmrg# define S_IXUSR _S_IEXEC
5982ee3e8c14Smrg#elif defined __MINGW32__
5983ba064abeSmrg# define setmode _setmode
5984ba064abeSmrg# define stat    _stat
5985ba064abeSmrg# define chmod   _chmod
5986ba064abeSmrg# define getcwd  _getcwd
5987ba064abeSmrg# define putenv  _putenv
5988ee3e8c14Smrg#elif defined __CYGWIN__
5989ba064abeSmrg# define HAVE_SETENV
5990ba064abeSmrg# define FOPEN_WB "wb"
5991ee3e8c14Smrg/* #elif defined other platforms ... */
5992ba064abeSmrg#endif
5993ba064abeSmrg
5994ee3e8c14Smrg#if defined PATH_MAX
5995b290cf36Smrg# define LT_PATHMAX PATH_MAX
5996ee3e8c14Smrg#elif defined MAXPATHLEN
5997b290cf36Smrg# define LT_PATHMAX MAXPATHLEN
5998b290cf36Smrg#else
5999b290cf36Smrg# define LT_PATHMAX 1024
6000b290cf36Smrg#endif
6001b290cf36Smrg
6002b290cf36Smrg#ifndef S_IXOTH
6003b290cf36Smrg# define S_IXOTH 0
6004b290cf36Smrg#endif
6005b290cf36Smrg#ifndef S_IXGRP
6006b290cf36Smrg# define S_IXGRP 0
6007b290cf36Smrg#endif
6008b290cf36Smrg
6009ba064abeSmrg/* path handling portability macros */
6010b290cf36Smrg#ifndef DIR_SEPARATOR
6011b290cf36Smrg# define DIR_SEPARATOR '/'
6012b290cf36Smrg# define PATH_SEPARATOR ':'
6013b290cf36Smrg#endif
6014b290cf36Smrg
6015ee3e8c14Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
6016ee3e8c14Smrg  defined __OS2__
6017b290cf36Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
6018b290cf36Smrg# define FOPEN_WB "wb"
6019b290cf36Smrg# ifndef DIR_SEPARATOR_2
6020b290cf36Smrg#  define DIR_SEPARATOR_2 '\\'
6021b290cf36Smrg# endif
6022b290cf36Smrg# ifndef PATH_SEPARATOR_2
6023b290cf36Smrg#  define PATH_SEPARATOR_2 ';'
6024b290cf36Smrg# endif
6025b290cf36Smrg#endif
6026b290cf36Smrg
6027b290cf36Smrg#ifndef DIR_SEPARATOR_2
6028b290cf36Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
6029b290cf36Smrg#else /* DIR_SEPARATOR_2 */
6030b290cf36Smrg# define IS_DIR_SEPARATOR(ch) \
6031b290cf36Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
6032b290cf36Smrg#endif /* DIR_SEPARATOR_2 */
6033b290cf36Smrg
6034b290cf36Smrg#ifndef PATH_SEPARATOR_2
6035b290cf36Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
6036b290cf36Smrg#else /* PATH_SEPARATOR_2 */
6037b290cf36Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
6038b290cf36Smrg#endif /* PATH_SEPARATOR_2 */
6039b290cf36Smrg
6040b290cf36Smrg#ifndef FOPEN_WB
6041b290cf36Smrg# define FOPEN_WB "w"
6042b290cf36Smrg#endif
6043b290cf36Smrg#ifndef _O_BINARY
6044b290cf36Smrg# define _O_BINARY 0
6045b290cf36Smrg#endif
6046b290cf36Smrg
6047b290cf36Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
6048b290cf36Smrg#define XFREE(stale) do { \
6049ee3e8c14Smrg  if (stale) { free (stale); stale = 0; } \
6050b290cf36Smrg} while (0)
6051b290cf36Smrg
6052ee3e8c14Smrg#if defined LT_DEBUGWRAPPER
6053ba064abeSmrgstatic int lt_debug = 1;
6054b290cf36Smrg#else
6055ba064abeSmrgstatic int lt_debug = 0;
6056b290cf36Smrg#endif
6057b290cf36Smrg
6058ba064abeSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
6059b290cf36Smrg
6060b290cf36Smrgvoid *xmalloc (size_t num);
6061b290cf36Smrgchar *xstrdup (const char *string);
6062b290cf36Smrgconst char *base_name (const char *name);
6063b290cf36Smrgchar *find_executable (const char *wrapper);
6064b290cf36Smrgchar *chase_symlinks (const char *pathspec);
6065b290cf36Smrgint make_executable (const char *path);
6066b290cf36Smrgint check_executable (const char *path);
6067b290cf36Smrgchar *strendzap (char *str, const char *pat);
6068ba064abeSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
6069ba064abeSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
6070ba064abeSmrgstatic const char *nonnull (const char *s);
6071ba064abeSmrgstatic const char *nonempty (const char *s);
6072b290cf36Smrgvoid lt_setenv (const char *name, const char *value);
6073b290cf36Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
6074b290cf36Smrgvoid lt_update_exe_path (const char *name, const char *value);
6075b290cf36Smrgvoid lt_update_lib_path (const char *name, const char *value);
6076ba064abeSmrgchar **prepare_spawn (char **argv);
6077ba064abeSmrgvoid lt_dump_script (FILE *f);
6078b290cf36SmrgEOF
6079b290cf36Smrg
6080b290cf36Smrg	    cat <<EOF
6081ee3e8c14Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
6082ee3e8c14Smrg# define externally_visible volatile
6083ee3e8c14Smrg#else
6084ee3e8c14Smrg# define externally_visible __attribute__((externally_visible)) volatile
6085ee3e8c14Smrg#endif
6086ee3e8c14Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
6087b290cf36Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
6088b290cf36SmrgEOF
6089b290cf36Smrg
6090ee3e8c14Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
6091d9dcd5aeSmrg              func_to_host_path "$temp_rpath"
6092b290cf36Smrg	      cat <<EOF
6093d9dcd5aeSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
6094191cded7SmrgEOF
6095191cded7Smrg	    else
6096b290cf36Smrg	      cat <<"EOF"
6097b290cf36Smrgconst char * LIB_PATH_VALUE   = "";
6098b290cf36SmrgEOF
6099191cded7Smrg	    fi
6100b290cf36Smrg
6101b290cf36Smrg	    if test -n "$dllsearchpath"; then
6102d9dcd5aeSmrg              func_to_host_path "$dllsearchpath:"
6103b290cf36Smrg	      cat <<EOF
6104b290cf36Smrgconst char * EXE_PATH_VARNAME = "PATH";
6105d9dcd5aeSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
6106b290cf36SmrgEOF
6107191cded7Smrg	    else
6108b290cf36Smrg	      cat <<"EOF"
6109b290cf36Smrgconst char * EXE_PATH_VARNAME = "";
6110b290cf36Smrgconst char * EXE_PATH_VALUE   = "";
6111b290cf36SmrgEOF
6112191cded7Smrg	    fi
6113b290cf36Smrg
6114ee3e8c14Smrg	    if test yes = "$fast_install"; then
6115b290cf36Smrg	      cat <<EOF
6116b290cf36Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
6117b290cf36SmrgEOF
6118191cded7Smrg	    else
6119b290cf36Smrg	      cat <<EOF
6120b290cf36Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
6121b290cf36SmrgEOF
6122191cded7Smrg	    fi
6123191cded7Smrg
6124191cded7Smrg
6125b290cf36Smrg	    cat <<"EOF"
6126191cded7Smrg
6127b290cf36Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
6128191cded7Smrg
6129b290cf36Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
6130b290cf36Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
6131ba064abeSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
6132191cded7Smrg
6133b290cf36Smrgint
6134b290cf36Smrgmain (int argc, char *argv[])
6135b290cf36Smrg{
6136b290cf36Smrg  char **newargz;
6137b290cf36Smrg  int  newargc;
6138b290cf36Smrg  char *tmp_pathspec;
6139b290cf36Smrg  char *actual_cwrapper_path;
6140b290cf36Smrg  char *actual_cwrapper_name;
6141b290cf36Smrg  char *target_name;
6142b290cf36Smrg  char *lt_argv_zero;
6143ee3e8c14Smrg  int rval = 127;
6144191cded7Smrg
6145b290cf36Smrg  int i;
6146191cded7Smrg
6147b290cf36Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6148ee3e8c14Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6149191cded7Smrg
6150ba064abeSmrg  /* very simple arg parsing; don't want to rely on getopt
6151ba064abeSmrg   * also, copy all non cwrapper options to newargz, except
6152ba064abeSmrg   * argz[0], which is handled differently
6153ba064abeSmrg   */
6154ba064abeSmrg  newargc=0;
6155b290cf36Smrg  for (i = 1; i < argc; i++)
6156b290cf36Smrg    {
6157ee3e8c14Smrg      if (STREQ (argv[i], dumpscript_opt))
6158b290cf36Smrg	{
6159b290cf36SmrgEOF
6160ee3e8c14Smrg	    case $host in
61618f9fac4aSmrg	      *mingw* | *windows* | *cygwin* )
6162b290cf36Smrg		# make stdout use "unix" line endings
6163b290cf36Smrg		echo "          setmode(1,_O_BINARY);"
6164b290cf36Smrg		;;
6165b290cf36Smrg	      esac
6166191cded7Smrg
6167b290cf36Smrg	    cat <<"EOF"
6168ba064abeSmrg	  lt_dump_script (stdout);
6169b290cf36Smrg	  return 0;
6170b290cf36Smrg	}
6171ee3e8c14Smrg      if (STREQ (argv[i], debug_opt))
6172ba064abeSmrg	{
6173ba064abeSmrg          lt_debug = 1;
6174ba064abeSmrg          continue;
6175ba064abeSmrg	}
6176ee3e8c14Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6177ba064abeSmrg        {
6178ba064abeSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6179ba064abeSmrg             namespace, but it is not one of the ones we know about and
61808f9fac4aSmrg             have already dealt with, above (including dump-script), then
6181ba064abeSmrg             report an error. Otherwise, targets might begin to believe
6182ba064abeSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6183ba064abeSmrg             namespace. The first time any user complains about this, we'll
6184ba064abeSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6185ba064abeSmrg             or a configure.ac-settable value.
6186ba064abeSmrg           */
6187ba064abeSmrg          lt_fatal (__FILE__, __LINE__,
6188ba064abeSmrg		    "unrecognized %s option: '%s'",
6189ba064abeSmrg                    ltwrapper_option_prefix, argv[i]);
6190ba064abeSmrg        }
6191ba064abeSmrg      /* otherwise ... */
6192ba064abeSmrg      newargz[++newargc] = xstrdup (argv[i]);
6193b290cf36Smrg    }
6194ba064abeSmrg  newargz[++newargc] = NULL;
6195ba064abeSmrg
6196ba064abeSmrgEOF
6197ba064abeSmrg	    cat <<EOF
6198ba064abeSmrg  /* The GNU banner must be the first non-error debug message */
6199ee3e8c14Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6200ba064abeSmrgEOF
6201ba064abeSmrg	    cat <<"EOF"
6202ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6203ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6204191cded7Smrg
6205b290cf36Smrg  tmp_pathspec = find_executable (argv[0]);
6206b290cf36Smrg  if (tmp_pathspec == NULL)
6207ba064abeSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6208ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6209ba064abeSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6210ba064abeSmrg		  tmp_pathspec);
6211b290cf36Smrg
6212b290cf36Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6213ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6214ba064abeSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6215ba064abeSmrg		  actual_cwrapper_path);
6216b290cf36Smrg  XFREE (tmp_pathspec);
6217b290cf36Smrg
6218ba064abeSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6219b290cf36Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6220b290cf36Smrg
6221b290cf36Smrg  /* wrapper name transforms */
6222b290cf36Smrg  strendzap (actual_cwrapper_name, ".exe");
6223b290cf36Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6224b290cf36Smrg  XFREE (actual_cwrapper_name);
6225b290cf36Smrg  actual_cwrapper_name = tmp_pathspec;
6226b290cf36Smrg  tmp_pathspec = 0;
6227b290cf36Smrg
6228b290cf36Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6229b290cf36Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6230b290cf36Smrg  strendzap (target_name, ".exe");
6231b290cf36Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6232b290cf36Smrg  XFREE (target_name);
6233b290cf36Smrg  target_name = tmp_pathspec;
6234b290cf36Smrg  tmp_pathspec = 0;
6235b290cf36Smrg
6236ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6237ba064abeSmrg		  "(main) libtool target name: %s\n",
6238ba064abeSmrg		  target_name);
6239b290cf36SmrgEOF
6240191cded7Smrg
6241b290cf36Smrg	    cat <<EOF
6242b290cf36Smrg  newargz[0] =
6243b290cf36Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6244b290cf36Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6245b290cf36Smrg  strcpy (newargz[0], actual_cwrapper_path);
6246b290cf36Smrg  strcat (newargz[0], "$objdir");
6247b290cf36Smrg  strcat (newargz[0], "/");
6248b290cf36SmrgEOF
6249191cded7Smrg
6250b290cf36Smrg	    cat <<"EOF"
6251b290cf36Smrg  /* stop here, and copy so we don't have to do this twice */
6252b290cf36Smrg  tmp_pathspec = xstrdup (newargz[0]);
6253191cded7Smrg
6254b290cf36Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6255b290cf36Smrg  strcat (newargz[0], actual_cwrapper_name);
6256191cded7Smrg
6257b290cf36Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6258b290cf36Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6259b290cf36Smrg  XFREE (tmp_pathspec);
6260b290cf36Smrg  tmp_pathspec = NULL;
6261b290cf36SmrgEOF
6262191cded7Smrg
6263b290cf36Smrg	    case $host_os in
62648f9fac4aSmrg	      mingw* | windows*)
6265b290cf36Smrg	    cat <<"EOF"
6266b290cf36Smrg  {
6267b290cf36Smrg    char* p;
6268b290cf36Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6269b290cf36Smrg      {
6270b290cf36Smrg	*p = '/';
6271b290cf36Smrg      }
6272b290cf36Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6273b290cf36Smrg      {
6274b290cf36Smrg	*p = '/';
6275b290cf36Smrg      }
6276b290cf36Smrg  }
6277b290cf36SmrgEOF
6278b290cf36Smrg	    ;;
6279b290cf36Smrg	    esac
6280191cded7Smrg
6281b290cf36Smrg	    cat <<"EOF"
6282b290cf36Smrg  XFREE (target_name);
6283b290cf36Smrg  XFREE (actual_cwrapper_path);
6284b290cf36Smrg  XFREE (actual_cwrapper_name);
6285191cded7Smrg
6286b290cf36Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6287b290cf36Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6288d9dcd5aeSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6289d9dcd5aeSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6290d9dcd5aeSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6291d9dcd5aeSmrg     libraries must come first. */
6292b290cf36Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6293d9dcd5aeSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6294191cded7Smrg
6295ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6296ba064abeSmrg		  nonnull (lt_argv_zero));
6297b290cf36Smrg  for (i = 0; i < newargc; i++)
6298b290cf36Smrg    {
6299ba064abeSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6300ba064abeSmrg		      i, nonnull (newargz[i]));
6301b290cf36Smrg    }
6302191cded7Smrg
6303b290cf36SmrgEOF
6304191cded7Smrg
6305b290cf36Smrg	    case $host_os in
63068f9fac4aSmrg	      mingw* | windows*)
6307b290cf36Smrg		cat <<"EOF"
6308b290cf36Smrg  /* execv doesn't actually work on mingw as expected on unix */
6309ba064abeSmrg  newargz = prepare_spawn (newargz);
6310ee3e8c14Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6311b290cf36Smrg  if (rval == -1)
6312b290cf36Smrg    {
6313b290cf36Smrg      /* failed to start process */
6314ba064abeSmrg      lt_debugprintf (__FILE__, __LINE__,
6315ba064abeSmrg		      "(main) failed to launch target \"%s\": %s\n",
6316ba064abeSmrg		      lt_argv_zero, nonnull (strerror (errno)));
6317b290cf36Smrg      return 127;
6318b290cf36Smrg    }
6319b290cf36Smrg  return rval;
6320b290cf36SmrgEOF
6321b290cf36Smrg		;;
6322b290cf36Smrg	      *)
6323b290cf36Smrg		cat <<"EOF"
6324b290cf36Smrg  execv (lt_argv_zero, newargz);
6325b290cf36Smrg  return rval; /* =127, but avoids unused variable warning */
6326b290cf36SmrgEOF
6327b290cf36Smrg		;;
6328b290cf36Smrg	    esac
6329191cded7Smrg
6330b290cf36Smrg	    cat <<"EOF"
6331b290cf36Smrg}
6332191cded7Smrg
6333b290cf36Smrgvoid *
6334b290cf36Smrgxmalloc (size_t num)
6335b290cf36Smrg{
6336b290cf36Smrg  void *p = (void *) malloc (num);
6337b290cf36Smrg  if (!p)
6338ba064abeSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6339191cded7Smrg
6340b290cf36Smrg  return p;
6341b290cf36Smrg}
6342191cded7Smrg
6343b290cf36Smrgchar *
6344b290cf36Smrgxstrdup (const char *string)
6345b290cf36Smrg{
6346b290cf36Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6347b290cf36Smrg			  string) : NULL;
6348b290cf36Smrg}
6349191cded7Smrg
6350b290cf36Smrgconst char *
6351b290cf36Smrgbase_name (const char *name)
6352b290cf36Smrg{
6353b290cf36Smrg  const char *base;
6354191cded7Smrg
6355ee3e8c14Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6356b290cf36Smrg  /* Skip over the disk name in MSDOS pathnames. */
6357b290cf36Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6358b290cf36Smrg    name += 2;
6359b290cf36Smrg#endif
6360191cded7Smrg
6361b290cf36Smrg  for (base = name; *name; name++)
6362b290cf36Smrg    if (IS_DIR_SEPARATOR (*name))
6363b290cf36Smrg      base = name + 1;
6364b290cf36Smrg  return base;
6365b290cf36Smrg}
6366191cded7Smrg
6367b290cf36Smrgint
6368b290cf36Smrgcheck_executable (const char *path)
6369b290cf36Smrg{
6370b290cf36Smrg  struct stat st;
6371191cded7Smrg
6372ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6373ba064abeSmrg                  nonempty (path));
6374b290cf36Smrg  if ((!path) || (!*path))
6375b290cf36Smrg    return 0;
6376191cded7Smrg
6377b290cf36Smrg  if ((stat (path, &st) >= 0)
6378b290cf36Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6379b290cf36Smrg    return 1;
6380b290cf36Smrg  else
6381b290cf36Smrg    return 0;
6382b290cf36Smrg}
6383191cded7Smrg
6384b290cf36Smrgint
6385b290cf36Smrgmake_executable (const char *path)
6386b290cf36Smrg{
6387b290cf36Smrg  int rval = 0;
6388b290cf36Smrg  struct stat st;
6389191cded7Smrg
6390ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6391ba064abeSmrg                  nonempty (path));
6392b290cf36Smrg  if ((!path) || (!*path))
6393b290cf36Smrg    return 0;
6394191cded7Smrg
6395b290cf36Smrg  if (stat (path, &st) >= 0)
6396b290cf36Smrg    {
6397b290cf36Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6398b290cf36Smrg    }
6399b290cf36Smrg  return rval;
6400b290cf36Smrg}
6401191cded7Smrg
6402b290cf36Smrg/* Searches for the full path of the wrapper.  Returns
6403b290cf36Smrg   newly allocated full path name if found, NULL otherwise
6404b290cf36Smrg   Does not chase symlinks, even on platforms that support them.
6405b290cf36Smrg*/
6406b290cf36Smrgchar *
6407b290cf36Smrgfind_executable (const char *wrapper)
6408b290cf36Smrg{
6409b290cf36Smrg  int has_slash = 0;
6410b290cf36Smrg  const char *p;
6411b290cf36Smrg  const char *p_next;
6412b290cf36Smrg  /* static buffer for getcwd */
6413b290cf36Smrg  char tmp[LT_PATHMAX + 1];
6414ee3e8c14Smrg  size_t tmp_len;
6415b290cf36Smrg  char *concat_name;
6416191cded7Smrg
6417ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6418ba064abeSmrg                  nonempty (wrapper));
6419191cded7Smrg
6420b290cf36Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6421b290cf36Smrg    return NULL;
6422191cded7Smrg
6423b290cf36Smrg  /* Absolute path? */
6424ee3e8c14Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6425b290cf36Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6426b290cf36Smrg    {
6427b290cf36Smrg      concat_name = xstrdup (wrapper);
6428b290cf36Smrg      if (check_executable (concat_name))
6429b290cf36Smrg	return concat_name;
6430b290cf36Smrg      XFREE (concat_name);
6431b290cf36Smrg    }
6432b290cf36Smrg  else
6433b290cf36Smrg    {
6434b290cf36Smrg#endif
6435b290cf36Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6436b290cf36Smrg	{
6437b290cf36Smrg	  concat_name = xstrdup (wrapper);
6438b290cf36Smrg	  if (check_executable (concat_name))
6439b290cf36Smrg	    return concat_name;
6440b290cf36Smrg	  XFREE (concat_name);
6441b290cf36Smrg	}
6442ee3e8c14Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6443b290cf36Smrg    }
6444b290cf36Smrg#endif
6445191cded7Smrg
6446b290cf36Smrg  for (p = wrapper; *p; p++)
6447b290cf36Smrg    if (*p == '/')
6448b290cf36Smrg      {
6449b290cf36Smrg	has_slash = 1;
6450b290cf36Smrg	break;
6451b290cf36Smrg      }
6452b290cf36Smrg  if (!has_slash)
6453b290cf36Smrg    {
6454b290cf36Smrg      /* no slashes; search PATH */
6455b290cf36Smrg      const char *path = getenv ("PATH");
6456b290cf36Smrg      if (path != NULL)
6457b290cf36Smrg	{
6458b290cf36Smrg	  for (p = path; *p; p = p_next)
6459b290cf36Smrg	    {
6460b290cf36Smrg	      const char *q;
6461b290cf36Smrg	      size_t p_len;
6462b290cf36Smrg	      for (q = p; *q; q++)
6463b290cf36Smrg		if (IS_PATH_SEPARATOR (*q))
6464b290cf36Smrg		  break;
6465ee3e8c14Smrg	      p_len = (size_t) (q - p);
6466b290cf36Smrg	      p_next = (*q == '\0' ? q : q + 1);
6467b290cf36Smrg	      if (p_len == 0)
6468b290cf36Smrg		{
6469b290cf36Smrg		  /* empty path: current directory */
6470b290cf36Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6471ba064abeSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6472ba064abeSmrg                              nonnull (strerror (errno)));
6473b290cf36Smrg		  tmp_len = strlen (tmp);
6474b290cf36Smrg		  concat_name =
6475b290cf36Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6476b290cf36Smrg		  memcpy (concat_name, tmp, tmp_len);
6477b290cf36Smrg		  concat_name[tmp_len] = '/';
6478b290cf36Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6479b290cf36Smrg		}
6480b290cf36Smrg	      else
6481b290cf36Smrg		{
6482b290cf36Smrg		  concat_name =
6483b290cf36Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6484b290cf36Smrg		  memcpy (concat_name, p, p_len);
6485b290cf36Smrg		  concat_name[p_len] = '/';
6486b290cf36Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6487b290cf36Smrg		}
6488b290cf36Smrg	      if (check_executable (concat_name))
6489b290cf36Smrg		return concat_name;
6490b290cf36Smrg	      XFREE (concat_name);
6491b290cf36Smrg	    }
6492b290cf36Smrg	}
6493b290cf36Smrg      /* not found in PATH; assume curdir */
6494b290cf36Smrg    }
6495b290cf36Smrg  /* Relative path | not found in path: prepend cwd */
6496b290cf36Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6497ba064abeSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6498ba064abeSmrg              nonnull (strerror (errno)));
6499b290cf36Smrg  tmp_len = strlen (tmp);
6500b290cf36Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6501b290cf36Smrg  memcpy (concat_name, tmp, tmp_len);
6502b290cf36Smrg  concat_name[tmp_len] = '/';
6503b290cf36Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6504191cded7Smrg
6505b290cf36Smrg  if (check_executable (concat_name))
6506b290cf36Smrg    return concat_name;
6507b290cf36Smrg  XFREE (concat_name);
6508b290cf36Smrg  return NULL;
6509b290cf36Smrg}
6510191cded7Smrg
6511b290cf36Smrgchar *
6512b290cf36Smrgchase_symlinks (const char *pathspec)
6513b290cf36Smrg{
6514b290cf36Smrg#ifndef S_ISLNK
6515b290cf36Smrg  return xstrdup (pathspec);
6516b290cf36Smrg#else
6517b290cf36Smrg  char buf[LT_PATHMAX];
6518b290cf36Smrg  struct stat s;
6519b290cf36Smrg  char *tmp_pathspec = xstrdup (pathspec);
6520b290cf36Smrg  char *p;
6521b290cf36Smrg  int has_symlinks = 0;
6522b290cf36Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6523b290cf36Smrg    {
6524ba064abeSmrg      lt_debugprintf (__FILE__, __LINE__,
6525ba064abeSmrg		      "checking path component for symlinks: %s\n",
6526ba064abeSmrg		      tmp_pathspec);
6527b290cf36Smrg      if (lstat (tmp_pathspec, &s) == 0)
6528b290cf36Smrg	{
6529b290cf36Smrg	  if (S_ISLNK (s.st_mode) != 0)
6530b290cf36Smrg	    {
6531b290cf36Smrg	      has_symlinks = 1;
6532b290cf36Smrg	      break;
6533b290cf36Smrg	    }
6534191cded7Smrg
6535b290cf36Smrg	  /* search backwards for last DIR_SEPARATOR */
6536b290cf36Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6537b290cf36Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6538b290cf36Smrg	    p--;
6539b290cf36Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6540b290cf36Smrg	    {
6541b290cf36Smrg	      /* no more DIR_SEPARATORS left */
6542b290cf36Smrg	      break;
6543b290cf36Smrg	    }
6544b290cf36Smrg	  *p = '\0';
6545b290cf36Smrg	}
6546b290cf36Smrg      else
6547b290cf36Smrg	{
6548ba064abeSmrg	  lt_fatal (__FILE__, __LINE__,
6549ba064abeSmrg		    "error accessing file \"%s\": %s",
6550ba064abeSmrg		    tmp_pathspec, nonnull (strerror (errno)));
6551b290cf36Smrg	}
6552b290cf36Smrg    }
6553b290cf36Smrg  XFREE (tmp_pathspec);
6554191cded7Smrg
6555b290cf36Smrg  if (!has_symlinks)
6556b290cf36Smrg    {
6557b290cf36Smrg      return xstrdup (pathspec);
6558b290cf36Smrg    }
6559191cded7Smrg
6560b290cf36Smrg  tmp_pathspec = realpath (pathspec, buf);
6561b290cf36Smrg  if (tmp_pathspec == 0)
6562b290cf36Smrg    {
6563ba064abeSmrg      lt_fatal (__FILE__, __LINE__,
6564ba064abeSmrg		"could not follow symlinks for %s", pathspec);
6565b290cf36Smrg    }
6566b290cf36Smrg  return xstrdup (tmp_pathspec);
6567b290cf36Smrg#endif
6568b290cf36Smrg}
6569191cded7Smrg
6570b290cf36Smrgchar *
6571b290cf36Smrgstrendzap (char *str, const char *pat)
6572b290cf36Smrg{
6573b290cf36Smrg  size_t len, patlen;
6574191cded7Smrg
6575b290cf36Smrg  assert (str != NULL);
6576b290cf36Smrg  assert (pat != NULL);
6577191cded7Smrg
6578b290cf36Smrg  len = strlen (str);
6579b290cf36Smrg  patlen = strlen (pat);
6580191cded7Smrg
6581b290cf36Smrg  if (patlen <= len)
6582b290cf36Smrg    {
6583b290cf36Smrg      str += len - patlen;
6584ee3e8c14Smrg      if (STREQ (str, pat))
6585b290cf36Smrg	*str = '\0';
6586b290cf36Smrg    }
6587b290cf36Smrg  return str;
6588b290cf36Smrg}
6589191cded7Smrg
6590ba064abeSmrgvoid
6591ba064abeSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6592ba064abeSmrg{
6593ba064abeSmrg  va_list args;
6594ba064abeSmrg  if (lt_debug)
6595ba064abeSmrg    {
6596ba064abeSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6597ba064abeSmrg      va_start (args, fmt);
6598ba064abeSmrg      (void) vfprintf (stderr, fmt, args);
6599ba064abeSmrg      va_end (args);
6600ba064abeSmrg    }
6601ba064abeSmrg}
6602ba064abeSmrg
6603b290cf36Smrgstatic void
6604ba064abeSmrglt_error_core (int exit_status, const char *file,
6605ba064abeSmrg	       int line, const char *mode,
6606b290cf36Smrg	       const char *message, va_list ap)
6607b290cf36Smrg{
6608ba064abeSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6609b290cf36Smrg  vfprintf (stderr, message, ap);
6610b290cf36Smrg  fprintf (stderr, ".\n");
6611191cded7Smrg
6612b290cf36Smrg  if (exit_status >= 0)
6613b290cf36Smrg    exit (exit_status);
6614b290cf36Smrg}
6615191cded7Smrg
6616b290cf36Smrgvoid
6617ba064abeSmrglt_fatal (const char *file, int line, const char *message, ...)
6618b290cf36Smrg{
6619b290cf36Smrg  va_list ap;
6620b290cf36Smrg  va_start (ap, message);
6621ba064abeSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6622b290cf36Smrg  va_end (ap);
6623b290cf36Smrg}
6624191cded7Smrg
6625ba064abeSmrgstatic const char *
6626ba064abeSmrgnonnull (const char *s)
6627ba064abeSmrg{
6628ba064abeSmrg  return s ? s : "(null)";
6629ba064abeSmrg}
6630ba064abeSmrg
6631ba064abeSmrgstatic const char *
6632ba064abeSmrgnonempty (const char *s)
6633ba064abeSmrg{
6634ba064abeSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6635ba064abeSmrg}
6636ba064abeSmrg
6637b290cf36Smrgvoid
6638b290cf36Smrglt_setenv (const char *name, const char *value)
6639b290cf36Smrg{
6640ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6641ba064abeSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6642ba064abeSmrg                  nonnull (name), nonnull (value));
6643b290cf36Smrg  {
6644b290cf36Smrg#ifdef HAVE_SETENV
6645b290cf36Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6646b290cf36Smrg    char *str = xstrdup (value);
6647b290cf36Smrg    setenv (name, str, 1);
6648b290cf36Smrg#else
6649ee3e8c14Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6650b290cf36Smrg    char *str = XMALLOC (char, len);
6651b290cf36Smrg    sprintf (str, "%s=%s", name, value);
6652b290cf36Smrg    if (putenv (str) != EXIT_SUCCESS)
6653b290cf36Smrg      {
6654b290cf36Smrg        XFREE (str);
6655b290cf36Smrg      }
6656b290cf36Smrg#endif
6657b290cf36Smrg  }
6658b290cf36Smrg}
6659191cded7Smrg
6660b290cf36Smrgchar *
6661b290cf36Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6662b290cf36Smrg{
6663b290cf36Smrg  char *new_value;
6664b290cf36Smrg  if (orig_value && *orig_value)
6665b290cf36Smrg    {
6666ee3e8c14Smrg      size_t orig_value_len = strlen (orig_value);
6667ee3e8c14Smrg      size_t add_len = strlen (add);
6668b290cf36Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6669b290cf36Smrg      if (to_end)
6670b290cf36Smrg        {
6671b290cf36Smrg          strcpy (new_value, orig_value);
6672b290cf36Smrg          strcpy (new_value + orig_value_len, add);
6673b290cf36Smrg        }
6674b290cf36Smrg      else
6675b290cf36Smrg        {
6676b290cf36Smrg          strcpy (new_value, add);
6677b290cf36Smrg          strcpy (new_value + add_len, orig_value);
6678b290cf36Smrg        }
6679b290cf36Smrg    }
6680b290cf36Smrg  else
6681b290cf36Smrg    {
6682b290cf36Smrg      new_value = xstrdup (add);
6683b290cf36Smrg    }
6684b290cf36Smrg  return new_value;
6685b290cf36Smrg}
6686191cded7Smrg
6687b290cf36Smrgvoid
6688b290cf36Smrglt_update_exe_path (const char *name, const char *value)
6689b290cf36Smrg{
6690ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6691ba064abeSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6692ba064abeSmrg                  nonnull (name), nonnull (value));
6693191cded7Smrg
6694b290cf36Smrg  if (name && *name && value && *value)
6695b290cf36Smrg    {
6696b290cf36Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6697b290cf36Smrg      /* some systems can't cope with a ':'-terminated path #' */
6698ee3e8c14Smrg      size_t len = strlen (new_value);
6699ee3e8c14Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6700b290cf36Smrg        {
6701ee3e8c14Smrg          new_value[--len] = '\0';
6702b290cf36Smrg        }
6703b290cf36Smrg      lt_setenv (name, new_value);
6704b290cf36Smrg      XFREE (new_value);
6705b290cf36Smrg    }
6706b290cf36Smrg}
6707191cded7Smrg
6708b290cf36Smrgvoid
6709b290cf36Smrglt_update_lib_path (const char *name, const char *value)
6710b290cf36Smrg{
6711ba064abeSmrg  lt_debugprintf (__FILE__, __LINE__,
6712ba064abeSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6713ba064abeSmrg                  nonnull (name), nonnull (value));
6714191cded7Smrg
6715b290cf36Smrg  if (name && *name && value && *value)
6716b290cf36Smrg    {
6717b290cf36Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6718b290cf36Smrg      lt_setenv (name, new_value);
6719b290cf36Smrg      XFREE (new_value);
6720b290cf36Smrg    }
6721b290cf36Smrg}
6722191cded7Smrg
6723ba064abeSmrgEOF
6724ba064abeSmrg	    case $host_os in
67258f9fac4aSmrg	      mingw* | windows*)
6726ba064abeSmrg		cat <<"EOF"
6727ba064abeSmrg
6728ba064abeSmrg/* Prepares an argument vector before calling spawn().
6729ba064abeSmrg   Note that spawn() does not by itself call the command interpreter
6730ba064abeSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6731ba064abeSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6732ba064abeSmrg         GetVersionEx(&v);
6733ba064abeSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6734ba064abeSmrg      }) ? "cmd.exe" : "command.com").
6735ba064abeSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6736ba064abeSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6737ba064abeSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6738ba064abeSmrg   special way:
6739ba064abeSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6740ba064abeSmrg     delimiters if they are surrounded by double quotes: "...".
6741ba064abeSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6742ba064abeSmrg     that within double quotes, space and tab are treated like normal
6743ba064abeSmrg     characters.
6744ba064abeSmrg   - Backslashes not followed by double quotes are not special.
6745ba064abeSmrg   - But 2*n+1 backslashes followed by a double quote become
6746ba064abeSmrg     n backslashes followed by a double quote (n >= 0):
6747ba064abeSmrg       \" -> "
6748ba064abeSmrg       \\\" -> \"
6749ba064abeSmrg       \\\\\" -> \\"
6750ba064abeSmrg */
6751ba064abeSmrg#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"
6752ba064abeSmrg#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"
6753ba064abeSmrgchar **
6754ba064abeSmrgprepare_spawn (char **argv)
6755ba064abeSmrg{
6756ba064abeSmrg  size_t argc;
6757ba064abeSmrg  char **new_argv;
6758ba064abeSmrg  size_t i;
6759ba064abeSmrg
6760ba064abeSmrg  /* Count number of arguments.  */
6761ba064abeSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6762ba064abeSmrg    ;
6763ba064abeSmrg
6764ba064abeSmrg  /* Allocate new argument vector.  */
6765ba064abeSmrg  new_argv = XMALLOC (char *, argc + 1);
6766ba064abeSmrg
6767ba064abeSmrg  /* Put quoted arguments into the new argument vector.  */
6768ba064abeSmrg  for (i = 0; i < argc; i++)
6769ba064abeSmrg    {
6770ba064abeSmrg      const char *string = argv[i];
6771ba064abeSmrg
6772ba064abeSmrg      if (string[0] == '\0')
6773ba064abeSmrg	new_argv[i] = xstrdup ("\"\"");
6774ba064abeSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6775ba064abeSmrg	{
6776ba064abeSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6777ba064abeSmrg	  size_t length;
6778ba064abeSmrg	  unsigned int backslashes;
6779ba064abeSmrg	  const char *s;
6780ba064abeSmrg	  char *quoted_string;
6781ba064abeSmrg	  char *p;
6782ba064abeSmrg
6783ba064abeSmrg	  length = 0;
6784ba064abeSmrg	  backslashes = 0;
6785ba064abeSmrg	  if (quote_around)
6786ba064abeSmrg	    length++;
6787ba064abeSmrg	  for (s = string; *s != '\0'; s++)
6788ba064abeSmrg	    {
6789ba064abeSmrg	      char c = *s;
6790ba064abeSmrg	      if (c == '"')
6791ba064abeSmrg		length += backslashes + 1;
6792ba064abeSmrg	      length++;
6793ba064abeSmrg	      if (c == '\\')
6794ba064abeSmrg		backslashes++;
6795ba064abeSmrg	      else
6796ba064abeSmrg		backslashes = 0;
6797ba064abeSmrg	    }
6798ba064abeSmrg	  if (quote_around)
6799ba064abeSmrg	    length += backslashes + 1;
6800ba064abeSmrg
6801ba064abeSmrg	  quoted_string = XMALLOC (char, length + 1);
6802ba064abeSmrg
6803ba064abeSmrg	  p = quoted_string;
6804ba064abeSmrg	  backslashes = 0;
6805ba064abeSmrg	  if (quote_around)
6806ba064abeSmrg	    *p++ = '"';
6807ba064abeSmrg	  for (s = string; *s != '\0'; s++)
6808ba064abeSmrg	    {
6809ba064abeSmrg	      char c = *s;
6810ba064abeSmrg	      if (c == '"')
6811ba064abeSmrg		{
6812ba064abeSmrg		  unsigned int j;
6813ba064abeSmrg		  for (j = backslashes + 1; j > 0; j--)
6814ba064abeSmrg		    *p++ = '\\';
6815ba064abeSmrg		}
6816ba064abeSmrg	      *p++ = c;
6817ba064abeSmrg	      if (c == '\\')
6818ba064abeSmrg		backslashes++;
6819ba064abeSmrg	      else
6820ba064abeSmrg		backslashes = 0;
6821ba064abeSmrg	    }
6822ba064abeSmrg	  if (quote_around)
6823ba064abeSmrg	    {
6824ba064abeSmrg	      unsigned int j;
6825ba064abeSmrg	      for (j = backslashes; j > 0; j--)
6826ba064abeSmrg		*p++ = '\\';
6827ba064abeSmrg	      *p++ = '"';
6828ba064abeSmrg	    }
6829ba064abeSmrg	  *p = '\0';
6830ba064abeSmrg
6831ba064abeSmrg	  new_argv[i] = quoted_string;
6832ba064abeSmrg	}
6833ba064abeSmrg      else
6834ba064abeSmrg	new_argv[i] = (char *) string;
6835ba064abeSmrg    }
6836ba064abeSmrg  new_argv[argc] = NULL;
6837ba064abeSmrg
6838ba064abeSmrg  return new_argv;
6839ba064abeSmrg}
6840ba064abeSmrgEOF
6841ba064abeSmrg		;;
6842ba064abeSmrg	    esac
6843ba064abeSmrg
6844ba064abeSmrg            cat <<"EOF"
6845ba064abeSmrgvoid lt_dump_script (FILE* f)
6846ba064abeSmrg{
6847ba064abeSmrgEOF
6848ba064abeSmrg	    func_emit_wrapper yes |
6849d9dcd5aeSmrg	      $SED -n -e '
6850d9dcd5aeSmrgs/^\(.\{79\}\)\(..*\)/\1\
6851d9dcd5aeSmrg\2/
6852d9dcd5aeSmrgh
6853d9dcd5aeSmrgs/\([\\"]\)/\\\1/g
6854d9dcd5aeSmrgs/$/\\n/
6855d9dcd5aeSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6856d9dcd5aeSmrgg
6857d9dcd5aeSmrgD'
6858ba064abeSmrg            cat <<"EOF"
6859ba064abeSmrg}
6860b290cf36SmrgEOF
6861b290cf36Smrg}
6862b290cf36Smrg# end: func_emit_cwrapperexe_src
6863191cded7Smrg
6864ba064abeSmrg# func_win32_import_lib_p ARG
6865ba064abeSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6866ba064abeSmrgfunc_win32_import_lib_p ()
6867ba064abeSmrg{
6868ee3e8c14Smrg    $debug_cmd
6869ee3e8c14Smrg
6870ba064abeSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6871ba064abeSmrg    *import*) : ;;
6872ba064abeSmrg    *) false ;;
6873ba064abeSmrg    esac
6874ba064abeSmrg}
6875ba064abeSmrg
6876ee3e8c14Smrg# func_suncc_cstd_abi
6877ee3e8c14Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6878ee3e8c14Smrg# Several compiler flags select an ABI that is incompatible with the
6879ee3e8c14Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6880ee3e8c14Smrgfunc_suncc_cstd_abi ()
6881ee3e8c14Smrg{
6882ee3e8c14Smrg    $debug_cmd
6883ee3e8c14Smrg
6884ee3e8c14Smrg    case " $compile_command " in
6885ee3e8c14Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6886ee3e8c14Smrg      suncc_use_cstd_abi=no
6887ee3e8c14Smrg      ;;
6888ee3e8c14Smrg    *)
6889ee3e8c14Smrg      suncc_use_cstd_abi=yes
6890ee3e8c14Smrg      ;;
6891ee3e8c14Smrg    esac
6892ee3e8c14Smrg}
6893ee3e8c14Smrg
6894b290cf36Smrg# func_mode_link arg...
6895b290cf36Smrgfunc_mode_link ()
6896b290cf36Smrg{
6897ee3e8c14Smrg    $debug_cmd
6898ee3e8c14Smrg
6899b290cf36Smrg    case $host in
69008f9fac4aSmrg    *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
6901b290cf36Smrg      # It is impossible to link a dll without this setting, and
6902b290cf36Smrg      # we shouldn't force the makefile maintainer to figure out
6903ee3e8c14Smrg      # what system we are compiling for in order to pass an extra
6904b290cf36Smrg      # flag for every libtool invocation.
6905b290cf36Smrg      # allow_undefined=no
6906191cded7Smrg
6907b290cf36Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6908ee3e8c14Smrg      # to make a dll that has undefined symbols, in which case not
6909b290cf36Smrg      # even a static library is built.  For now, we need to specify
6910b290cf36Smrg      # -no-undefined on the libtool link line when we can be certain
6911b290cf36Smrg      # that all symbols are satisfied, otherwise we get a static library.
6912b290cf36Smrg      allow_undefined=yes
6913b290cf36Smrg      ;;
6914b290cf36Smrg    *)
6915b290cf36Smrg      allow_undefined=yes
6916b290cf36Smrg      ;;
6917b290cf36Smrg    esac
6918b290cf36Smrg    libtool_args=$nonopt
6919b290cf36Smrg    base_compile="$nonopt $@"
6920b290cf36Smrg    compile_command=$nonopt
6921b290cf36Smrg    finalize_command=$nonopt
6922191cded7Smrg
6923b290cf36Smrg    compile_rpath=
69248f9fac4aSmrg    compile_rpath_tail=
6925b290cf36Smrg    finalize_rpath=
6926b290cf36Smrg    compile_shlibpath=
6927b290cf36Smrg    finalize_shlibpath=
6928b290cf36Smrg    convenience=
6929b290cf36Smrg    old_convenience=
6930b290cf36Smrg    deplibs=
6931b290cf36Smrg    old_deplibs=
6932b290cf36Smrg    compiler_flags=
6933b290cf36Smrg    linker_flags=
6934b290cf36Smrg    dllsearchpath=
6935b290cf36Smrg    lib_search_path=`pwd`
6936b290cf36Smrg    inst_prefix_dir=
6937b290cf36Smrg    new_inherited_linker_flags=
6938191cded7Smrg
6939b290cf36Smrg    avoid_version=no
6940ba064abeSmrg    bindir=
6941b290cf36Smrg    dlfiles=
6942b290cf36Smrg    dlprefiles=
6943b290cf36Smrg    dlself=no
6944b290cf36Smrg    export_dynamic=no
6945b290cf36Smrg    export_symbols=
6946b290cf36Smrg    export_symbols_regex=
6947b290cf36Smrg    generated=
6948b290cf36Smrg    libobjs=
6949b290cf36Smrg    ltlibs=
6950b290cf36Smrg    module=no
6951b290cf36Smrg    no_install=no
6952b290cf36Smrg    objs=
6953ee3e8c14Smrg    os2dllname=
6954b290cf36Smrg    non_pic_objects=
6955b290cf36Smrg    precious_files_regex=
6956b290cf36Smrg    prefer_static_libs=no
6957ee3e8c14Smrg    preload=false
6958b290cf36Smrg    prev=
6959b290cf36Smrg    prevarg=
6960b290cf36Smrg    release=
6961b290cf36Smrg    rpath=
6962b290cf36Smrg    xrpath=
6963b290cf36Smrg    perm_rpath=
6964b290cf36Smrg    temp_rpath=
69658f9fac4aSmrg    temp_rpath_tail=
6966b290cf36Smrg    thread_safe=no
6967b290cf36Smrg    vinfo=
6968b290cf36Smrg    vinfo_number=no
6969b290cf36Smrg    weak_libs=
69708f9fac4aSmrg    rpath_arg=
6971ee3e8c14Smrg    single_module=$wl-single_module
6972b290cf36Smrg    func_infer_tag $base_compile
6973191cded7Smrg
6974b290cf36Smrg    # We need to know -static, to get the right output filenames.
6975b290cf36Smrg    for arg
6976b290cf36Smrg    do
6977b290cf36Smrg      case $arg in
6978b290cf36Smrg      -shared)
6979ee3e8c14Smrg	test yes != "$build_libtool_libs" \
6980ee3e8c14Smrg	  && func_fatal_configuration "cannot build a shared library"
6981b290cf36Smrg	build_old_libs=no
6982b290cf36Smrg	break
6983b290cf36Smrg	;;
6984b290cf36Smrg      -all-static | -static | -static-libtool-libs)
6985b290cf36Smrg	case $arg in
6986b290cf36Smrg	-all-static)
6987ee3e8c14Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6988b290cf36Smrg	    func_warning "complete static linking is impossible in this configuration"
6989191cded7Smrg	  fi
6990b290cf36Smrg	  if test -n "$link_static_flag"; then
6991b290cf36Smrg	    dlopen_self=$dlopen_self_static
6992191cded7Smrg	  fi
6993b290cf36Smrg	  prefer_static_libs=yes
6994191cded7Smrg	  ;;
6995b290cf36Smrg	-static)
6996b290cf36Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6997b290cf36Smrg	    dlopen_self=$dlopen_self_static
6998b290cf36Smrg	  fi
6999b290cf36Smrg	  prefer_static_libs=built
7000b290cf36Smrg	  ;;
7001b290cf36Smrg	-static-libtool-libs)
7002b290cf36Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
7003b290cf36Smrg	    dlopen_self=$dlopen_self_static
7004b290cf36Smrg	  fi
7005b290cf36Smrg	  prefer_static_libs=yes
7006191cded7Smrg	  ;;
7007191cded7Smrg	esac
7008b290cf36Smrg	build_libtool_libs=no
7009b290cf36Smrg	build_old_libs=yes
7010b290cf36Smrg	break
7011b290cf36Smrg	;;
7012b290cf36Smrg      esac
7013b290cf36Smrg    done
7014191cded7Smrg
7015b290cf36Smrg    # See if our shared archives depend on static archives.
7016b290cf36Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
7017191cded7Smrg
7018b290cf36Smrg    # Go through the arguments, transforming them on the way.
7019b290cf36Smrg    while test "$#" -gt 0; do
7020ee3e8c14Smrg      arg=$1
7021b290cf36Smrg      shift
7022ee3e8c14Smrg      func_quote_arg pretty,unquoted "$arg"
7023ee3e8c14Smrg      qarg=$func_quote_arg_unquoted_result
7024ee3e8c14Smrg      func_append libtool_args " $func_quote_arg_result"
7025191cded7Smrg
7026b290cf36Smrg      # If the previous option needs an argument, assign it.
7027b290cf36Smrg      if test -n "$prev"; then
7028b290cf36Smrg	case $prev in
7029b290cf36Smrg	output)
7030b290cf36Smrg	  func_append compile_command " @OUTPUT@"
7031b290cf36Smrg	  func_append finalize_command " @OUTPUT@"
7032b290cf36Smrg	  ;;
7033b290cf36Smrg	esac
7034191cded7Smrg
7035b290cf36Smrg	case $prev in
7036ba064abeSmrg	bindir)
7037ee3e8c14Smrg	  bindir=$arg
7038ba064abeSmrg	  prev=
7039ba064abeSmrg	  continue
7040ba064abeSmrg	  ;;
7041b290cf36Smrg	dlfiles|dlprefiles)
7042ee3e8c14Smrg	  $preload || {
7043b290cf36Smrg	    # Add the symbol object into the linking commands.
7044b290cf36Smrg	    func_append compile_command " @SYMFILE@"
7045b290cf36Smrg	    func_append finalize_command " @SYMFILE@"
7046ee3e8c14Smrg	    preload=:
7047ee3e8c14Smrg	  }
7048b290cf36Smrg	  case $arg in
7049b290cf36Smrg	  *.la | *.lo) ;;  # We handle these cases below.
7050b290cf36Smrg	  force)
7051ee3e8c14Smrg	    if test no = "$dlself"; then
7052b290cf36Smrg	      dlself=needless
7053b290cf36Smrg	      export_dynamic=yes
7054b290cf36Smrg	    fi
7055b290cf36Smrg	    prev=
7056b290cf36Smrg	    continue
7057b290cf36Smrg	    ;;
7058b290cf36Smrg	  self)
7059ee3e8c14Smrg	    if test dlprefiles = "$prev"; then
7060b290cf36Smrg	      dlself=yes
7061ee3e8c14Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
7062b290cf36Smrg	      dlself=yes
7063b290cf36Smrg	    else
7064b290cf36Smrg	      dlself=needless
7065b290cf36Smrg	      export_dynamic=yes
7066b290cf36Smrg	    fi
7067b290cf36Smrg	    prev=
7068b290cf36Smrg	    continue
7069191cded7Smrg	    ;;
7070191cded7Smrg	  *)
7071ee3e8c14Smrg	    if test dlfiles = "$prev"; then
7072d9dcd5aeSmrg	      func_append dlfiles " $arg"
7073b290cf36Smrg	    else
7074d9dcd5aeSmrg	      func_append dlprefiles " $arg"
7075b290cf36Smrg	    fi
7076b290cf36Smrg	    prev=
7077b290cf36Smrg	    continue
7078191cded7Smrg	    ;;
7079191cded7Smrg	  esac
7080b290cf36Smrg	  ;;
7081b290cf36Smrg	expsyms)
7082ee3e8c14Smrg	  export_symbols=$arg
7083b290cf36Smrg	  test -f "$arg" \
7084ee3e8c14Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
7085b290cf36Smrg	  prev=
7086b290cf36Smrg	  continue
7087b290cf36Smrg	  ;;
7088b290cf36Smrg	expsyms_regex)
7089ee3e8c14Smrg	  export_symbols_regex=$arg
7090b290cf36Smrg	  prev=
7091b290cf36Smrg	  continue
7092b290cf36Smrg	  ;;
7093b290cf36Smrg	framework)
7094b290cf36Smrg	  case $host in
7095b290cf36Smrg	    *-*-darwin*)
7096b290cf36Smrg	      case "$deplibs " in
7097b290cf36Smrg		*" $qarg.ltframework "*) ;;
7098d9dcd5aeSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
7099b290cf36Smrg		   ;;
7100b290cf36Smrg	      esac
7101b290cf36Smrg	      ;;
7102b290cf36Smrg	  esac
7103b290cf36Smrg	  prev=
7104b290cf36Smrg	  continue
7105b290cf36Smrg	  ;;
7106b290cf36Smrg	inst_prefix)
7107ee3e8c14Smrg	  inst_prefix_dir=$arg
7108ee3e8c14Smrg	  prev=
7109ee3e8c14Smrg	  continue
7110ee3e8c14Smrg	  ;;
7111ee3e8c14Smrg	mllvm)
7112ee3e8c14Smrg	  # Clang does not use LLVM to link, so we can simply discard any
7113ee3e8c14Smrg	  # '-mllvm $arg' options when doing the link step.
7114b290cf36Smrg	  prev=
7115b290cf36Smrg	  continue
7116b290cf36Smrg	  ;;
7117b290cf36Smrg	objectlist)
7118b290cf36Smrg	  if test -f "$arg"; then
7119b290cf36Smrg	    save_arg=$arg
7120b290cf36Smrg	    moreargs=
7121b290cf36Smrg	    for fil in `cat "$save_arg"`
7122b290cf36Smrg	    do
7123d9dcd5aeSmrg#	      func_append moreargs " $fil"
7124b290cf36Smrg	      arg=$fil
7125b290cf36Smrg	      # A libtool-controlled object.
7126191cded7Smrg
7127b290cf36Smrg	      # Check to see that this really is a libtool object.
7128b290cf36Smrg	      if func_lalib_unsafe_p "$arg"; then
7129b290cf36Smrg		pic_object=
7130b290cf36Smrg		non_pic_object=
7131191cded7Smrg
7132b290cf36Smrg		# Read the .lo file
7133b290cf36Smrg		func_source "$arg"
7134191cded7Smrg
7135b290cf36Smrg		if test -z "$pic_object" ||
7136b290cf36Smrg		   test -z "$non_pic_object" ||
7137ee3e8c14Smrg		   test none = "$pic_object" &&
7138ee3e8c14Smrg		   test none = "$non_pic_object"; then
7139ee3e8c14Smrg		  func_fatal_error "cannot find name of object for '$arg'"
7140b290cf36Smrg		fi
7141191cded7Smrg
7142b290cf36Smrg		# Extract subdirectory from the argument.
7143b290cf36Smrg		func_dirname "$arg" "/" ""
7144ee3e8c14Smrg		xdir=$func_dirname_result
7145191cded7Smrg
7146ee3e8c14Smrg		if test none != "$pic_object"; then
7147b290cf36Smrg		  # Prepend the subdirectory the object is found in.
7148ee3e8c14Smrg		  pic_object=$xdir$pic_object
7149191cded7Smrg
7150ee3e8c14Smrg		  if test dlfiles = "$prev"; then
7151ee3e8c14Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7152d9dcd5aeSmrg		      func_append dlfiles " $pic_object"
7153b290cf36Smrg		      prev=
7154b290cf36Smrg		      continue
7155b290cf36Smrg		    else
7156b290cf36Smrg		      # If libtool objects are unsupported, then we need to preload.
7157b290cf36Smrg		      prev=dlprefiles
7158b290cf36Smrg		    fi
7159b290cf36Smrg		  fi
7160191cded7Smrg
7161b290cf36Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7162ee3e8c14Smrg		  if test dlprefiles = "$prev"; then
7163b290cf36Smrg		    # Preload the old-style object.
7164d9dcd5aeSmrg		    func_append dlprefiles " $pic_object"
7165b290cf36Smrg		    prev=
7166b290cf36Smrg		  fi
7167191cded7Smrg
7168b290cf36Smrg		  # A PIC object.
7169b290cf36Smrg		  func_append libobjs " $pic_object"
7170ee3e8c14Smrg		  arg=$pic_object
7171b290cf36Smrg		fi
7172191cded7Smrg
7173b290cf36Smrg		# Non-PIC object.
7174ee3e8c14Smrg		if test none != "$non_pic_object"; then
7175b290cf36Smrg		  # Prepend the subdirectory the object is found in.
7176ee3e8c14Smrg		  non_pic_object=$xdir$non_pic_object
7177191cded7Smrg
7178b290cf36Smrg		  # A standard non-PIC object
7179b290cf36Smrg		  func_append non_pic_objects " $non_pic_object"
7180ee3e8c14Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7181ee3e8c14Smrg		    arg=$non_pic_object
7182b290cf36Smrg		  fi
7183b290cf36Smrg		else
7184b290cf36Smrg		  # If the PIC object exists, use it instead.
7185b290cf36Smrg		  # $xdir was prepended to $pic_object above.
7186ee3e8c14Smrg		  non_pic_object=$pic_object
7187b290cf36Smrg		  func_append non_pic_objects " $non_pic_object"
7188b290cf36Smrg		fi
7189b290cf36Smrg	      else
7190b290cf36Smrg		# Only an error if not doing a dry-run.
7191b290cf36Smrg		if $opt_dry_run; then
7192b290cf36Smrg		  # Extract subdirectory from the argument.
7193b290cf36Smrg		  func_dirname "$arg" "/" ""
7194ee3e8c14Smrg		  xdir=$func_dirname_result
7195b290cf36Smrg
7196b290cf36Smrg		  func_lo2o "$arg"
7197b290cf36Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7198b290cf36Smrg		  non_pic_object=$xdir$func_lo2o_result
7199b290cf36Smrg		  func_append libobjs " $pic_object"
7200b290cf36Smrg		  func_append non_pic_objects " $non_pic_object"
7201b290cf36Smrg	        else
7202ee3e8c14Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
7203b290cf36Smrg		fi
7204b290cf36Smrg	      fi
7205b290cf36Smrg	    done
7206b290cf36Smrg	  else
7207ee3e8c14Smrg	    func_fatal_error "link input file '$arg' does not exist"
7208b290cf36Smrg	  fi
7209b290cf36Smrg	  arg=$save_arg
7210b290cf36Smrg	  prev=
7211b290cf36Smrg	  continue
7212b290cf36Smrg	  ;;
7213ee3e8c14Smrg	os2dllname)
7214ee3e8c14Smrg	  os2dllname=$arg
7215ee3e8c14Smrg	  prev=
7216ee3e8c14Smrg	  continue
7217ee3e8c14Smrg	  ;;
7218b290cf36Smrg	precious_regex)
7219ee3e8c14Smrg	  precious_files_regex=$arg
7220b290cf36Smrg	  prev=
7221b290cf36Smrg	  continue
7222b290cf36Smrg	  ;;
7223b290cf36Smrg	release)
7224ee3e8c14Smrg	  release=-$arg
7225b290cf36Smrg	  prev=
7226b290cf36Smrg	  continue
7227b290cf36Smrg	  ;;
7228b290cf36Smrg	rpath | xrpath)
7229b290cf36Smrg	  # We need an absolute path.
7230b290cf36Smrg	  case $arg in
7231b290cf36Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7232b290cf36Smrg	  *)
72338f9fac4aSmrg	    func_fatal_error "argument to -rpath is not absolute: $arg"
7234b290cf36Smrg	    ;;
7235b290cf36Smrg	  esac
7236ee3e8c14Smrg	  if test rpath = "$prev"; then
7237b290cf36Smrg	    case "$rpath " in
7238b290cf36Smrg	    *" $arg "*) ;;
7239d9dcd5aeSmrg	    *) func_append rpath " $arg" ;;
7240b290cf36Smrg	    esac
7241b290cf36Smrg	  else
7242b290cf36Smrg	    case "$xrpath " in
7243b290cf36Smrg	    *" $arg "*) ;;
7244d9dcd5aeSmrg	    *) func_append xrpath " $arg" ;;
7245b290cf36Smrg	    esac
7246b290cf36Smrg	  fi
7247b290cf36Smrg	  prev=
7248b290cf36Smrg	  continue
7249b290cf36Smrg	  ;;
7250b290cf36Smrg	shrext)
7251ee3e8c14Smrg	  shrext_cmds=$arg
7252b290cf36Smrg	  prev=
7253b290cf36Smrg	  continue
7254b290cf36Smrg	  ;;
7255b290cf36Smrg	weak)
7256d9dcd5aeSmrg	  func_append weak_libs " $arg"
7257b290cf36Smrg	  prev=
7258b290cf36Smrg	  continue
7259b290cf36Smrg	  ;;
7260ee3e8c14Smrg	xassembler)
7261ee3e8c14Smrg	  func_append compiler_flags " -Xassembler $qarg"
7262ee3e8c14Smrg	  prev=
7263ee3e8c14Smrg	  func_append compile_command " -Xassembler $qarg"
7264ee3e8c14Smrg	  func_append finalize_command " -Xassembler $qarg"
7265ee3e8c14Smrg	  continue
7266ee3e8c14Smrg	  ;;
7267b290cf36Smrg	xcclinker)
7268d9dcd5aeSmrg	  func_append linker_flags " $qarg"
7269d9dcd5aeSmrg	  func_append compiler_flags " $qarg"
7270b290cf36Smrg	  prev=
7271b290cf36Smrg	  func_append compile_command " $qarg"
7272b290cf36Smrg	  func_append finalize_command " $qarg"
7273b290cf36Smrg	  continue
7274b290cf36Smrg	  ;;
7275b290cf36Smrg	xcompiler)
7276d9dcd5aeSmrg	  func_append compiler_flags " $qarg"
7277b290cf36Smrg	  prev=
7278b290cf36Smrg	  func_append compile_command " $qarg"
7279b290cf36Smrg	  func_append finalize_command " $qarg"
7280b290cf36Smrg	  continue
7281b290cf36Smrg	  ;;
7282b290cf36Smrg	xlinker)
7283d9dcd5aeSmrg	  func_append linker_flags " $qarg"
7284d9dcd5aeSmrg	  func_append compiler_flags " $wl$qarg"
7285b290cf36Smrg	  prev=
7286b290cf36Smrg	  func_append compile_command " $wl$qarg"
7287b290cf36Smrg	  func_append finalize_command " $wl$qarg"
7288b290cf36Smrg	  continue
7289b290cf36Smrg	  ;;
7290b290cf36Smrg	*)
7291b290cf36Smrg	  eval "$prev=\"\$arg\""
7292b290cf36Smrg	  prev=
7293b290cf36Smrg	  continue
7294b290cf36Smrg	  ;;
7295191cded7Smrg	esac
7296b290cf36Smrg      fi # test -n "$prev"
7297191cded7Smrg
7298ee3e8c14Smrg      prevarg=$arg
7299191cded7Smrg
7300b290cf36Smrg      case $arg in
7301b290cf36Smrg      -all-static)
7302b290cf36Smrg	if test -n "$link_static_flag"; then
7303b290cf36Smrg	  # See comment for -static flag below, for more details.
7304b290cf36Smrg	  func_append compile_command " $link_static_flag"
7305b290cf36Smrg	  func_append finalize_command " $link_static_flag"
7306b290cf36Smrg	fi
7307b290cf36Smrg	continue
7308b290cf36Smrg	;;
7309191cded7Smrg
7310b290cf36Smrg      -allow-undefined)
7311b290cf36Smrg	# FIXME: remove this flag sometime in the future.
7312ee3e8c14Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7313b290cf36Smrg	;;
7314191cded7Smrg
7315b290cf36Smrg      -avoid-version)
7316b290cf36Smrg	avoid_version=yes
7317b290cf36Smrg	continue
7318b290cf36Smrg	;;
7319191cded7Smrg
7320ba064abeSmrg      -bindir)
7321ba064abeSmrg	prev=bindir
7322ba064abeSmrg	continue
7323ba064abeSmrg	;;
7324ba064abeSmrg
7325b290cf36Smrg      -dlopen)
7326b290cf36Smrg	prev=dlfiles
7327b290cf36Smrg	continue
7328b290cf36Smrg	;;
7329191cded7Smrg
7330b290cf36Smrg      -dlpreopen)
7331b290cf36Smrg	prev=dlprefiles
7332b290cf36Smrg	continue
7333b290cf36Smrg	;;
7334191cded7Smrg
7335b290cf36Smrg      -export-dynamic)
7336b290cf36Smrg	export_dynamic=yes
7337b290cf36Smrg	continue
7338b290cf36Smrg	;;
7339191cded7Smrg
7340b290cf36Smrg      -export-symbols | -export-symbols-regex)
7341b290cf36Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7342b290cf36Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7343b290cf36Smrg	fi
7344ee3e8c14Smrg	if test X-export-symbols = "X$arg"; then
7345b290cf36Smrg	  prev=expsyms
7346b290cf36Smrg	else
7347b290cf36Smrg	  prev=expsyms_regex
7348b290cf36Smrg	fi
7349b290cf36Smrg	continue
7350b290cf36Smrg	;;
7351191cded7Smrg
7352b290cf36Smrg      -framework)
7353b290cf36Smrg	prev=framework
7354b290cf36Smrg	continue
7355b290cf36Smrg	;;
7356191cded7Smrg
7357b290cf36Smrg      -inst-prefix-dir)
7358b290cf36Smrg	prev=inst_prefix
7359b290cf36Smrg	continue
7360b290cf36Smrg	;;
7361191cded7Smrg
7362b290cf36Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7363b290cf36Smrg      # so, if we see these flags be careful not to treat them like -L
7364b290cf36Smrg      -L[A-Z][A-Z]*:*)
7365b290cf36Smrg	case $with_gcc/$host in
7366b290cf36Smrg	no/*-*-irix* | /*-*-irix*)
7367b290cf36Smrg	  func_append compile_command " $arg"
7368b290cf36Smrg	  func_append finalize_command " $arg"
7369b290cf36Smrg	  ;;
7370b290cf36Smrg	esac
7371b290cf36Smrg	continue
7372b290cf36Smrg	;;
7373191cded7Smrg
7374b290cf36Smrg      -L*)
7375d9dcd5aeSmrg	func_stripname "-L" '' "$arg"
7376d9dcd5aeSmrg	if test -z "$func_stripname_result"; then
7377b290cf36Smrg	  if test "$#" -gt 0; then
7378ee3e8c14Smrg	    func_fatal_error "require no space between '-L' and '$1'"
7379b290cf36Smrg	  else
7380ee3e8c14Smrg	    func_fatal_error "need path for '-L' option"
7381b290cf36Smrg	  fi
7382b290cf36Smrg	fi
7383d9dcd5aeSmrg	func_resolve_sysroot "$func_stripname_result"
7384d9dcd5aeSmrg	dir=$func_resolve_sysroot_result
7385b290cf36Smrg	# We need an absolute path.
7386b290cf36Smrg	case $dir in
7387b290cf36Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7388b290cf36Smrg	*)
7389b290cf36Smrg	  absdir=`cd "$dir" && pwd`
7390b290cf36Smrg	  test -z "$absdir" && \
7391ee3e8c14Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7392ee3e8c14Smrg	  dir=$absdir
7393b290cf36Smrg	  ;;
7394b290cf36Smrg	esac
7395b290cf36Smrg	case "$deplibs " in
7396d9dcd5aeSmrg	*" -L$dir "* | *" $arg "*)
7397d9dcd5aeSmrg	  # Will only happen for absolute or sysroot arguments
7398d9dcd5aeSmrg	  ;;
7399b290cf36Smrg	*)
7400d9dcd5aeSmrg	  # Preserve sysroot, but never include relative directories
7401d9dcd5aeSmrg	  case $dir in
7402d9dcd5aeSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7403d9dcd5aeSmrg	    *) func_append deplibs " -L$dir" ;;
7404d9dcd5aeSmrg	  esac
7405d9dcd5aeSmrg	  func_append lib_search_path " $dir"
7406b290cf36Smrg	  ;;
7407b290cf36Smrg	esac
7408b290cf36Smrg	case $host in
74098f9fac4aSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
7410ba064abeSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7411b290cf36Smrg	  case :$dllsearchpath: in
7412b290cf36Smrg	  *":$dir:"*) ;;
7413b290cf36Smrg	  ::) dllsearchpath=$dir;;
7414d9dcd5aeSmrg	  *) func_append dllsearchpath ":$dir";;
7415b290cf36Smrg	  esac
7416b290cf36Smrg	  case :$dllsearchpath: in
7417b290cf36Smrg	  *":$testbindir:"*) ;;
7418b290cf36Smrg	  ::) dllsearchpath=$testbindir;;
7419d9dcd5aeSmrg	  *) func_append dllsearchpath ":$testbindir";;
7420b290cf36Smrg	  esac
7421b290cf36Smrg	  ;;
7422b290cf36Smrg	esac
7423b290cf36Smrg	continue
7424b290cf36Smrg	;;
7425191cded7Smrg
7426b290cf36Smrg      -l*)
7427ee3e8c14Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7428b290cf36Smrg	  case $host in
74298f9fac4aSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7430b290cf36Smrg	    # These systems don't actually have a C or math library (as such)
7431b290cf36Smrg	    continue
7432b290cf36Smrg	    ;;
7433b290cf36Smrg	  *-*-os2*)
7434b290cf36Smrg	    # These systems don't actually have a C library (as such)
7435ee3e8c14Smrg	    test X-lc = "X$arg" && continue
7436b290cf36Smrg	    ;;
74378f9fac4aSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7438b290cf36Smrg	    # Do not include libc due to us having libc/libc_r.
7439ee3e8c14Smrg	    test X-lc = "X$arg" && continue
7440b290cf36Smrg	    ;;
7441b290cf36Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7442b290cf36Smrg	    # Rhapsody C and math libraries are in the System framework
7443d9dcd5aeSmrg	    func_append deplibs " System.ltframework"
7444b290cf36Smrg	    continue
7445b290cf36Smrg	    ;;
7446b290cf36Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7447b290cf36Smrg	    # Causes problems with __ctype
7448ee3e8c14Smrg	    test X-lc = "X$arg" && continue
7449b290cf36Smrg	    ;;
7450b290cf36Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7451b290cf36Smrg	    # Compiler inserts libc in the correct place for threads to work
7452ee3e8c14Smrg	    test X-lc = "X$arg" && continue
7453b290cf36Smrg	    ;;
7454b290cf36Smrg	  esac
7455ee3e8c14Smrg	elif test X-lc_r = "X$arg"; then
7456b290cf36Smrg	 case $host in
74578f9fac4aSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
7458b290cf36Smrg	   # Do not include libc_r directly, use -pthread flag.
7459b290cf36Smrg	   continue
7460b290cf36Smrg	   ;;
7461b290cf36Smrg	 esac
7462b290cf36Smrg	fi
7463d9dcd5aeSmrg	func_append deplibs " $arg"
7464b290cf36Smrg	continue
7465b290cf36Smrg	;;
7466191cded7Smrg
7467ee3e8c14Smrg      -mllvm)
7468ee3e8c14Smrg	prev=mllvm
7469ee3e8c14Smrg	continue
7470ee3e8c14Smrg	;;
7471ee3e8c14Smrg
7472b290cf36Smrg      -module)
7473b290cf36Smrg	module=yes
7474b290cf36Smrg	continue
7475b290cf36Smrg	;;
7476191cded7Smrg
7477b290cf36Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7478b290cf36Smrg      # classes, name mangling, and exception handling.
7479b290cf36Smrg      # Darwin uses the -arch flag to determine output architecture.
74808f9fac4aSmrg      # -q <option> for IBM XL C/C++ compiler.
74818f9fac4aSmrg      -model|-arch|-isysroot|--sysroot|-q)
7482d9dcd5aeSmrg	func_append compiler_flags " $arg"
7483b290cf36Smrg	func_append compile_command " $arg"
7484b290cf36Smrg	func_append finalize_command " $arg"
7485b290cf36Smrg	prev=xcompiler
7486b290cf36Smrg	continue
7487b290cf36Smrg	;;
7488ee3e8c14Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7489ee3e8c14Smrg     -pthread)
7490ee3e8c14Smrg	case $host in
7491ee3e8c14Smrg	  *solaris2*) ;;
7492ee3e8c14Smrg	  *)
7493ee3e8c14Smrg	    case "$new_inherited_linker_flags " in
7494ee3e8c14Smrg	        *" $arg "*) ;;
7495ee3e8c14Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7496ee3e8c14Smrg	    esac
7497ee3e8c14Smrg	  ;;
7498ee3e8c14Smrg	esac
7499ee3e8c14Smrg	continue
7500ee3e8c14Smrg	;;
7501ee3e8c14Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
75028f9fac4aSmrg      |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7503d9dcd5aeSmrg	func_append compiler_flags " $arg"
7504b290cf36Smrg	func_append compile_command " $arg"
7505b290cf36Smrg	func_append finalize_command " $arg"
7506b290cf36Smrg	case "$new_inherited_linker_flags " in
7507b290cf36Smrg	    *" $arg "*) ;;
7508d9dcd5aeSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7509b290cf36Smrg	esac
7510b290cf36Smrg	continue
7511b290cf36Smrg	;;
7512191cded7Smrg
7513b290cf36Smrg      -multi_module)
7514ee3e8c14Smrg	single_module=$wl-multi_module
7515b290cf36Smrg	continue
7516b290cf36Smrg	;;
7517191cded7Smrg
7518b290cf36Smrg      -no-fast-install)
7519b290cf36Smrg	fast_install=no
7520b290cf36Smrg	continue
7521b290cf36Smrg	;;
7522191cded7Smrg
7523b290cf36Smrg      -no-install)
7524b290cf36Smrg	case $host in
75258f9fac4aSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7526b290cf36Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7527b290cf36Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7528ee3e8c14Smrg	  func_warning "'-no-install' is ignored for $host"
7529ee3e8c14Smrg	  func_warning "assuming '-no-fast-install' instead"
7530b290cf36Smrg	  fast_install=no
7531b290cf36Smrg	  ;;
7532b290cf36Smrg	*) no_install=yes ;;
7533b290cf36Smrg	esac
7534b290cf36Smrg	continue
7535b290cf36Smrg	;;
7536191cded7Smrg
7537b290cf36Smrg      -no-undefined)
7538b290cf36Smrg	allow_undefined=no
7539b290cf36Smrg	continue
7540b290cf36Smrg	;;
7541191cded7Smrg
7542b290cf36Smrg      -objectlist)
7543b290cf36Smrg	prev=objectlist
7544b290cf36Smrg	continue
7545b290cf36Smrg	;;
7546191cded7Smrg
7547ee3e8c14Smrg      -os2dllname)
7548ee3e8c14Smrg	prev=os2dllname
7549ee3e8c14Smrg	continue
7550ee3e8c14Smrg	;;
7551ee3e8c14Smrg
7552b290cf36Smrg      -o) prev=output ;;
7553191cded7Smrg
7554b290cf36Smrg      -precious-files-regex)
7555b290cf36Smrg	prev=precious_regex
7556b290cf36Smrg	continue
7557b290cf36Smrg	;;
7558191cded7Smrg
7559b290cf36Smrg      -release)
7560b290cf36Smrg	prev=release
7561b290cf36Smrg	continue
7562b290cf36Smrg	;;
7563191cded7Smrg
7564b290cf36Smrg      -rpath)
7565b290cf36Smrg	prev=rpath
7566b290cf36Smrg	continue
7567b290cf36Smrg	;;
7568191cded7Smrg
7569b290cf36Smrg      -R)
7570b290cf36Smrg	prev=xrpath
7571b290cf36Smrg	continue
7572b290cf36Smrg	;;
7573191cded7Smrg
7574b290cf36Smrg      -R*)
7575b290cf36Smrg	func_stripname '-R' '' "$arg"
7576b290cf36Smrg	dir=$func_stripname_result
7577b290cf36Smrg	# We need an absolute path.
7578b290cf36Smrg	case $dir in
7579b290cf36Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7580d9dcd5aeSmrg	=*)
7581d9dcd5aeSmrg	  func_stripname '=' '' "$dir"
7582d9dcd5aeSmrg	  dir=$lt_sysroot$func_stripname_result
7583d9dcd5aeSmrg	  ;;
7584b290cf36Smrg	*)
75858f9fac4aSmrg	  func_fatal_error "argument ($arg) to '-R' is not an absolute path: $dir"
7586b290cf36Smrg	  ;;
7587b290cf36Smrg	esac
7588b290cf36Smrg	case "$xrpath " in
7589b290cf36Smrg	*" $dir "*) ;;
7590d9dcd5aeSmrg	*) func_append xrpath " $dir" ;;
7591b290cf36Smrg	esac
7592b290cf36Smrg	continue
7593b290cf36Smrg	;;
7594191cded7Smrg
7595b290cf36Smrg      -shared)
7596b290cf36Smrg	# The effects of -shared are defined in a previous loop.
7597b290cf36Smrg	continue
7598b290cf36Smrg	;;
7599191cded7Smrg
7600b290cf36Smrg      -shrext)
7601b290cf36Smrg	prev=shrext
7602b290cf36Smrg	continue
7603b290cf36Smrg	;;
7604191cded7Smrg
7605b290cf36Smrg      -static | -static-libtool-libs)
7606b290cf36Smrg	# The effects of -static are defined in a previous loop.
7607b290cf36Smrg	# We used to do the same as -all-static on platforms that
7608b290cf36Smrg	# didn't have a PIC flag, but the assumption that the effects
7609b290cf36Smrg	# would be equivalent was wrong.  It would break on at least
7610b290cf36Smrg	# Digital Unix and AIX.
7611b290cf36Smrg	continue
7612b290cf36Smrg	;;
7613191cded7Smrg
7614b290cf36Smrg      -thread-safe)
7615b290cf36Smrg	thread_safe=yes
7616b290cf36Smrg	continue
7617b290cf36Smrg	;;
7618191cded7Smrg
7619b290cf36Smrg      -version-info)
7620b290cf36Smrg	prev=vinfo
7621b290cf36Smrg	continue
7622b290cf36Smrg	;;
7623191cded7Smrg
7624b290cf36Smrg      -version-number)
7625b290cf36Smrg	prev=vinfo
7626b290cf36Smrg	vinfo_number=yes
7627b290cf36Smrg	continue
7628b290cf36Smrg	;;
7629191cded7Smrg
7630b290cf36Smrg      -weak)
7631b290cf36Smrg        prev=weak
7632b290cf36Smrg	continue
7633b290cf36Smrg	;;
7634191cded7Smrg
7635b290cf36Smrg      -Wc,*)
7636b290cf36Smrg	func_stripname '-Wc,' '' "$arg"
7637b290cf36Smrg	args=$func_stripname_result
7638b290cf36Smrg	arg=
7639ee3e8c14Smrg	save_ifs=$IFS; IFS=,
7640b290cf36Smrg	for flag in $args; do
7641ee3e8c14Smrg	  IFS=$save_ifs
7642ee3e8c14Smrg          func_quote_arg pretty "$flag"
7643ee3e8c14Smrg	  func_append arg " $func_quote_arg_result"
7644ee3e8c14Smrg	  func_append compiler_flags " $func_quote_arg_result"
7645b290cf36Smrg	done
7646ee3e8c14Smrg	IFS=$save_ifs
7647b290cf36Smrg	func_stripname ' ' '' "$arg"
7648b290cf36Smrg	arg=$func_stripname_result
7649b290cf36Smrg	;;
7650191cded7Smrg
7651b290cf36Smrg      -Wl,*)
7652b290cf36Smrg	func_stripname '-Wl,' '' "$arg"
7653b290cf36Smrg	args=$func_stripname_result
7654b290cf36Smrg	arg=
7655ee3e8c14Smrg	save_ifs=$IFS; IFS=,
7656b290cf36Smrg	for flag in $args; do
7657ee3e8c14Smrg	  IFS=$save_ifs
7658ee3e8c14Smrg          func_quote_arg pretty "$flag"
7659ee3e8c14Smrg	  func_append arg " $wl$func_quote_arg_result"
7660ee3e8c14Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7661ee3e8c14Smrg	  func_append linker_flags " $func_quote_arg_result"
7662b290cf36Smrg	done
7663ee3e8c14Smrg	IFS=$save_ifs
7664b290cf36Smrg	func_stripname ' ' '' "$arg"
7665b290cf36Smrg	arg=$func_stripname_result
7666b290cf36Smrg	;;
7667191cded7Smrg
7668ee3e8c14Smrg      -Xassembler)
7669ee3e8c14Smrg        prev=xassembler
7670ee3e8c14Smrg        continue
7671ee3e8c14Smrg        ;;
7672ee3e8c14Smrg
7673b290cf36Smrg      -Xcompiler)
7674b290cf36Smrg	prev=xcompiler
7675b290cf36Smrg	continue
7676b290cf36Smrg	;;
7677191cded7Smrg
7678b290cf36Smrg      -Xlinker)
7679b290cf36Smrg	prev=xlinker
7680b290cf36Smrg	continue
7681b290cf36Smrg	;;
7682191cded7Smrg
7683b290cf36Smrg      -XCClinker)
7684b290cf36Smrg	prev=xcclinker
7685b290cf36Smrg	continue
7686b290cf36Smrg	;;
7687191cded7Smrg
7688b290cf36Smrg      # -msg_* for osf cc
7689b290cf36Smrg      -msg_*)
7690ee3e8c14Smrg	func_quote_arg pretty "$arg"
7691ee3e8c14Smrg	arg=$func_quote_arg_result
7692b290cf36Smrg	;;
7693191cded7Smrg
7694ba064abeSmrg      # Flags to be passed through unchanged, with rationale:
7695ba064abeSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7696ba064abeSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7697ba064abeSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7698ba064abeSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7699ba064abeSmrg      # -q*                  compiler args for the IBM compiler
7700ba064abeSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7701ba064abeSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7702ba064abeSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7703ee3e8c14Smrg      # -fstack-protector*   stack protector flags for GCC
7704ba064abeSmrg      # @file                GCC response files
7705ba064abeSmrg      # -tp=*                Portland pgcc target processor selection
7706d9dcd5aeSmrg      # --sysroot=*          for sysroot support
7707ee3e8c14Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7708ee3e8c14Smrg      # -specs=*             GCC specs files
7709ee3e8c14Smrg      # -stdlib=*            select c++ std lib with clang
77108f9fac4aSmrg      # -fdiagnostics-color* simply affects output
77118f9fac4aSmrg      # -frecord-gcc-switches used to verify flags were respected
7712ee3e8c14Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
77138f9fac4aSmrg      # -fno-sanitize*       Clang/GCC memory and address sanitizer
77148f9fac4aSmrg      # -shared-libsan       Link with shared sanitizer runtimes (Clang)
77158f9fac4aSmrg      # -static-libsan       Link with static sanitizer runtimes (Clang)
77168f9fac4aSmrg      # -no-canonical-prefixes Do not expand any symbolic links
7717ee3e8c14Smrg      # -fuse-ld=*           Linker select flags for GCC
77188f9fac4aSmrg      # -static-*            direct GCC to link specific libraries statically
77198f9fac4aSmrg      # -fcilkplus           Cilk Plus language extension features for C/C++
77208f9fac4aSmrg      # -rtlib=*             select c runtime lib with clang
77218f9fac4aSmrg      # --unwindlib=*        select unwinder library with clang
77228f9fac4aSmrg      # -f{file|debug|macro|profile}-prefix-map=* needed for lto linking
7723ee3e8c14Smrg      # -Wa,*                Pass flags directly to the assembler
77248f9fac4aSmrg      # -Werror, -Werror=*   Report (specified) warnings as errors
7725b290cf36Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7726d9dcd5aeSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
77278f9fac4aSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
77288f9fac4aSmrg      -stdlib=*|-rtlib=*|--unwindlib=*| \
77298f9fac4aSmrg      -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
77308f9fac4aSmrg      -ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \
77318f9fac4aSmrg      -fdiagnostics-color*|-frecord-gcc-switches| \
77328f9fac4aSmrg      -fuse-ld=*|-static-*|-fcilkplus|-Wa,*|-Werror|-Werror=*)
7733ee3e8c14Smrg        func_quote_arg pretty "$arg"
7734ee3e8c14Smrg	arg=$func_quote_arg_result
7735b290cf36Smrg        func_append compile_command " $arg"
7736b290cf36Smrg        func_append finalize_command " $arg"
7737d9dcd5aeSmrg        func_append compiler_flags " $arg"
7738b290cf36Smrg        continue
7739b290cf36Smrg        ;;
7740191cded7Smrg
7741ee3e8c14Smrg      -Z*)
7742ee3e8c14Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7743ee3e8c14Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7744ee3e8c14Smrg	  compiler_flags="$compiler_flags $arg"
7745ee3e8c14Smrg	  func_append compile_command " $arg"
7746ee3e8c14Smrg	  func_append finalize_command " $arg"
7747ee3e8c14Smrg	  case $arg in
7748ee3e8c14Smrg	  -Zlinker | -Zstack)
7749ee3e8c14Smrg	    prev=xcompiler
7750ee3e8c14Smrg	    ;;
7751ee3e8c14Smrg	  esac
7752ee3e8c14Smrg	  continue
7753ee3e8c14Smrg        else
7754ee3e8c14Smrg	  # Otherwise treat like 'Some other compiler flag' below
7755ee3e8c14Smrg	  func_quote_arg pretty "$arg"
7756ee3e8c14Smrg	  arg=$func_quote_arg_result
7757ee3e8c14Smrg        fi
7758ee3e8c14Smrg	;;
7759ee3e8c14Smrg
7760b290cf36Smrg      # Some other compiler flag.
7761b290cf36Smrg      -* | +*)
7762ee3e8c14Smrg        func_quote_arg pretty "$arg"
7763ee3e8c14Smrg	arg=$func_quote_arg_result
7764b290cf36Smrg	;;
7765191cded7Smrg
7766b290cf36Smrg      *.$objext)
7767b290cf36Smrg	# A standard object.
7768d9dcd5aeSmrg	func_append objs " $arg"
7769b290cf36Smrg	;;
7770b290cf36Smrg
7771b290cf36Smrg      *.lo)
7772b290cf36Smrg	# A libtool-controlled object.
7773b290cf36Smrg
7774b290cf36Smrg	# Check to see that this really is a libtool object.
7775b290cf36Smrg	if func_lalib_unsafe_p "$arg"; then
7776b290cf36Smrg	  pic_object=
7777b290cf36Smrg	  non_pic_object=
7778b290cf36Smrg
7779b290cf36Smrg	  # Read the .lo file
7780b290cf36Smrg	  func_source "$arg"
7781b290cf36Smrg
7782b290cf36Smrg	  if test -z "$pic_object" ||
7783b290cf36Smrg	     test -z "$non_pic_object" ||
7784ee3e8c14Smrg	     test none = "$pic_object" &&
7785ee3e8c14Smrg	     test none = "$non_pic_object"; then
7786ee3e8c14Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7787b290cf36Smrg	  fi
7788b290cf36Smrg
7789b290cf36Smrg	  # Extract subdirectory from the argument.
7790b290cf36Smrg	  func_dirname "$arg" "/" ""
7791ee3e8c14Smrg	  xdir=$func_dirname_result
7792b290cf36Smrg
7793ee3e8c14Smrg	  test none = "$pic_object" || {
7794b290cf36Smrg	    # Prepend the subdirectory the object is found in.
7795ee3e8c14Smrg	    pic_object=$xdir$pic_object
7796b290cf36Smrg
7797ee3e8c14Smrg	    if test dlfiles = "$prev"; then
7798ee3e8c14Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7799d9dcd5aeSmrg		func_append dlfiles " $pic_object"
7800b290cf36Smrg		prev=
7801b290cf36Smrg		continue
7802b290cf36Smrg	      else
7803b290cf36Smrg		# If libtool objects are unsupported, then we need to preload.
7804b290cf36Smrg		prev=dlprefiles
7805b290cf36Smrg	      fi
7806b290cf36Smrg	    fi
7807b290cf36Smrg
7808b290cf36Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7809ee3e8c14Smrg	    if test dlprefiles = "$prev"; then
7810b290cf36Smrg	      # Preload the old-style object.
7811d9dcd5aeSmrg	      func_append dlprefiles " $pic_object"
7812b290cf36Smrg	      prev=
7813b290cf36Smrg	    fi
7814b290cf36Smrg
7815b290cf36Smrg	    # A PIC object.
7816b290cf36Smrg	    func_append libobjs " $pic_object"
7817ee3e8c14Smrg	    arg=$pic_object
7818ee3e8c14Smrg	  }
7819b290cf36Smrg
7820b290cf36Smrg	  # Non-PIC object.
7821ee3e8c14Smrg	  if test none != "$non_pic_object"; then
7822b290cf36Smrg	    # Prepend the subdirectory the object is found in.
7823ee3e8c14Smrg	    non_pic_object=$xdir$non_pic_object
7824b290cf36Smrg
7825b290cf36Smrg	    # A standard non-PIC object
7826b290cf36Smrg	    func_append non_pic_objects " $non_pic_object"
7827ee3e8c14Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7828ee3e8c14Smrg	      arg=$non_pic_object
7829b290cf36Smrg	    fi
7830b290cf36Smrg	  else
7831b290cf36Smrg	    # If the PIC object exists, use it instead.
7832b290cf36Smrg	    # $xdir was prepended to $pic_object above.
7833ee3e8c14Smrg	    non_pic_object=$pic_object
7834b290cf36Smrg	    func_append non_pic_objects " $non_pic_object"
7835b290cf36Smrg	  fi
7836b290cf36Smrg	else
7837b290cf36Smrg	  # Only an error if not doing a dry-run.
7838b290cf36Smrg	  if $opt_dry_run; then
7839b290cf36Smrg	    # Extract subdirectory from the argument.
7840b290cf36Smrg	    func_dirname "$arg" "/" ""
7841ee3e8c14Smrg	    xdir=$func_dirname_result
7842b290cf36Smrg
7843b290cf36Smrg	    func_lo2o "$arg"
7844b290cf36Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7845b290cf36Smrg	    non_pic_object=$xdir$func_lo2o_result
7846b290cf36Smrg	    func_append libobjs " $pic_object"
7847b290cf36Smrg	    func_append non_pic_objects " $non_pic_object"
7848b290cf36Smrg	  else
7849ee3e8c14Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7850b290cf36Smrg	  fi
7851b290cf36Smrg	fi
7852b290cf36Smrg	;;
7853b290cf36Smrg
7854b290cf36Smrg      *.$libext)
7855b290cf36Smrg	# An archive.
7856d9dcd5aeSmrg	func_append deplibs " $arg"
7857d9dcd5aeSmrg	func_append old_deplibs " $arg"
7858b290cf36Smrg	continue
7859b290cf36Smrg	;;
7860b290cf36Smrg
7861b290cf36Smrg      *.la)
7862b290cf36Smrg	# A libtool-controlled library.
7863b290cf36Smrg
7864d9dcd5aeSmrg	func_resolve_sysroot "$arg"
7865ee3e8c14Smrg	if test dlfiles = "$prev"; then
7866b290cf36Smrg	  # This library was specified with -dlopen.
7867d9dcd5aeSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7868b290cf36Smrg	  prev=
7869ee3e8c14Smrg	elif test dlprefiles = "$prev"; then
7870b290cf36Smrg	  # The library was specified with -dlpreopen.
7871d9dcd5aeSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7872b290cf36Smrg	  prev=
7873b290cf36Smrg	else
7874d9dcd5aeSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7875b290cf36Smrg	fi
7876b290cf36Smrg	continue
7877b290cf36Smrg	;;
7878b290cf36Smrg
7879b290cf36Smrg      # Some other compiler argument.
7880b290cf36Smrg      *)
7881b290cf36Smrg	# Unknown arguments in both finalize_command and compile_command need
7882b290cf36Smrg	# to be aesthetically quoted because they are evaled later.
7883ee3e8c14Smrg	func_quote_arg pretty "$arg"
7884ee3e8c14Smrg	arg=$func_quote_arg_result
7885b290cf36Smrg	;;
7886b290cf36Smrg      esac # arg
7887b290cf36Smrg
7888b290cf36Smrg      # Now actually substitute the argument into the commands.
7889b290cf36Smrg      if test -n "$arg"; then
78908f9fac4aSmrg	if test -n "$rpath_arg"; then
78918f9fac4aSmrg          func_append finalize_rpath " ${arg##*,}"
78928f9fac4aSmrg	  unset rpath_arg
78938f9fac4aSmrg	else
78948f9fac4aSmrg	  case $arg in
78958f9fac4aSmrg          -Wl,-rpath,*)
78968f9fac4aSmrg	    func_append finalize_rpath " ${arg##*,}";;
78978f9fac4aSmrg          -Wl,-rpath)
78988f9fac4aSmrg	    rpath_arg=1;;
78998f9fac4aSmrg          *)
79008f9fac4aSmrg            func_append compile_command " $arg"
79018f9fac4aSmrg	    func_append finalize_command " $arg"
79028f9fac4aSmrg	  esac
79038f9fac4aSmrg        fi
7904b290cf36Smrg      fi
7905b290cf36Smrg    done # argument parsing loop
7906b290cf36Smrg
7907b290cf36Smrg    test -n "$prev" && \
7908ee3e8c14Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7909b290cf36Smrg
7910ee3e8c14Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7911b290cf36Smrg      eval arg=\"$export_dynamic_flag_spec\"
7912b290cf36Smrg      func_append compile_command " $arg"
7913b290cf36Smrg      func_append finalize_command " $arg"
7914b290cf36Smrg    fi
7915b290cf36Smrg
7916b290cf36Smrg    oldlibs=
7917b290cf36Smrg    # calculate the name of the file, without its directory
7918b290cf36Smrg    func_basename "$output"
7919ee3e8c14Smrg    outputname=$func_basename_result
7920ee3e8c14Smrg    libobjs_save=$libobjs
7921b290cf36Smrg
7922b290cf36Smrg    if test -n "$shlibpath_var"; then
7923b290cf36Smrg      # get the directories listed in $shlibpath_var
7924ee3e8c14Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7925191cded7Smrg    else
7926b290cf36Smrg      shlib_search_path=
7927191cded7Smrg    fi
7928b290cf36Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7929b290cf36Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7930191cded7Smrg
7931ee3e8c14Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7932ee3e8c14Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7933ee3e8c14Smrg
7934b290cf36Smrg    func_dirname "$output" "/" ""
7935ee3e8c14Smrg    output_objdir=$func_dirname_result$objdir
7936d9dcd5aeSmrg    func_to_tool_file "$output_objdir/"
7937d9dcd5aeSmrg    tool_output_objdir=$func_to_tool_file_result
7938b290cf36Smrg    # Create the object directory.
7939b290cf36Smrg    func_mkdir_p "$output_objdir"
7940191cded7Smrg
7941b290cf36Smrg    # Determine the type of output
7942b290cf36Smrg    case $output in
7943b290cf36Smrg    "")
7944b290cf36Smrg      func_fatal_help "you must specify an output file"
7945b290cf36Smrg      ;;
7946b290cf36Smrg    *.$libext) linkmode=oldlib ;;
7947b290cf36Smrg    *.lo | *.$objext) linkmode=obj ;;
7948b290cf36Smrg    *.la) linkmode=lib ;;
7949b290cf36Smrg    *) linkmode=prog ;; # Anything else should be a program.
7950b290cf36Smrg    esac
7951b290cf36Smrg
7952b290cf36Smrg    specialdeplibs=
7953b290cf36Smrg
7954b290cf36Smrg    libs=
7955b290cf36Smrg    # Find all interdependent deplibs by searching for libraries
7956b290cf36Smrg    # that are linked more than once (e.g. -la -lb -la)
7957b290cf36Smrg    for deplib in $deplibs; do
7958ee3e8c14Smrg      if $opt_preserve_dup_deps; then
7959b290cf36Smrg	case "$libs " in
7960d9dcd5aeSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7961b290cf36Smrg	esac
7962b290cf36Smrg      fi
7963d9dcd5aeSmrg      func_append libs " $deplib"
7964b290cf36Smrg    done
7965b290cf36Smrg
7966ee3e8c14Smrg    if test lib = "$linkmode"; then
7967b290cf36Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7968b290cf36Smrg
7969b290cf36Smrg      # Compute libraries that are listed more than once in $predeps
7970b290cf36Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7971b290cf36Smrg      # not to be eliminated).
7972b290cf36Smrg      pre_post_deps=
7973b290cf36Smrg      if $opt_duplicate_compiler_generated_deps; then
7974b290cf36Smrg	for pre_post_dep in $predeps $postdeps; do
7975b290cf36Smrg	  case "$pre_post_deps " in
7976d9dcd5aeSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7977b290cf36Smrg	  esac
7978d9dcd5aeSmrg	  func_append pre_post_deps " $pre_post_dep"
7979b290cf36Smrg	done
7980b290cf36Smrg      fi
7981b290cf36Smrg      pre_post_deps=
7982b290cf36Smrg    fi
7983b290cf36Smrg
7984b290cf36Smrg    deplibs=
7985b290cf36Smrg    newdependency_libs=
7986b290cf36Smrg    newlib_search_path=
7987b290cf36Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7988b290cf36Smrg    notinst_deplibs= # not-installed libtool libraries
7989b290cf36Smrg    notinst_path= # paths that contain not-installed libtool libraries
7990b290cf36Smrg
7991b290cf36Smrg    case $linkmode in
7992b290cf36Smrg    lib)
7993b290cf36Smrg	passes="conv dlpreopen link"
7994b290cf36Smrg	for file in $dlfiles $dlprefiles; do
7995b290cf36Smrg	  case $file in
7996b290cf36Smrg	  *.la) ;;
7997b290cf36Smrg	  *)
7998ee3e8c14Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7999b290cf36Smrg	    ;;
8000b290cf36Smrg	  esac
8001b290cf36Smrg	done
8002b290cf36Smrg	;;
8003b290cf36Smrg    prog)
8004b290cf36Smrg	compile_deplibs=
8005b290cf36Smrg	finalize_deplibs=
8006ee3e8c14Smrg	alldeplibs=false
8007b290cf36Smrg	newdlfiles=
8008b290cf36Smrg	newdlprefiles=
8009b290cf36Smrg	passes="conv scan dlopen dlpreopen link"
8010b290cf36Smrg	;;
8011b290cf36Smrg    *)  passes="conv"
8012b290cf36Smrg	;;
8013b290cf36Smrg    esac
8014b290cf36Smrg
8015b290cf36Smrg    for pass in $passes; do
8016b290cf36Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
8017b290cf36Smrg      # so that -L comes before libs that need it for instance...
8018ee3e8c14Smrg      if test lib,link = "$linkmode,$pass"; then
8019b290cf36Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
8020b290cf36Smrg	##        order, and fix it there properly
8021b290cf36Smrg        tmp_deplibs=
8022b290cf36Smrg	for deplib in $deplibs; do
8023b290cf36Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
8024b290cf36Smrg	done
8025ee3e8c14Smrg	deplibs=$tmp_deplibs
8026b290cf36Smrg      fi
8027b290cf36Smrg
8028ee3e8c14Smrg      if test lib,link = "$linkmode,$pass" ||
8029ee3e8c14Smrg	 test prog,scan = "$linkmode,$pass"; then
8030ee3e8c14Smrg	libs=$deplibs
8031b290cf36Smrg	deplibs=
8032b290cf36Smrg      fi
8033ee3e8c14Smrg      if test prog = "$linkmode"; then
8034b290cf36Smrg	case $pass in
8035ee3e8c14Smrg	dlopen) libs=$dlfiles ;;
8036ee3e8c14Smrg	dlpreopen) libs=$dlprefiles ;;
8037b290cf36Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
8038b290cf36Smrg	esac
8039b290cf36Smrg      fi
8040ee3e8c14Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
8041b290cf36Smrg	# Collect and forward deplibs of preopened libtool libs
8042b290cf36Smrg	for lib in $dlprefiles; do
8043b290cf36Smrg	  # Ignore non-libtool-libs
8044b290cf36Smrg	  dependency_libs=
8045d9dcd5aeSmrg	  func_resolve_sysroot "$lib"
8046b290cf36Smrg	  case $lib in
8047d9dcd5aeSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
8048b290cf36Smrg	  esac
8049b290cf36Smrg
8050b290cf36Smrg	  # Collect preopened libtool deplibs, except any this library
8051b290cf36Smrg	  # has declared as weak libs
8052b290cf36Smrg	  for deplib in $dependency_libs; do
8053ba064abeSmrg	    func_basename "$deplib"
8054ba064abeSmrg            deplib_base=$func_basename_result
8055b290cf36Smrg	    case " $weak_libs " in
8056b290cf36Smrg	    *" $deplib_base "*) ;;
8057d9dcd5aeSmrg	    *) func_append deplibs " $deplib" ;;
8058b290cf36Smrg	    esac
8059b290cf36Smrg	  done
8060b290cf36Smrg	done
8061ee3e8c14Smrg	libs=$dlprefiles
8062b290cf36Smrg      fi
8063ee3e8c14Smrg      if test dlopen = "$pass"; then
8064b290cf36Smrg	# Collect dlpreopened libraries
8065ee3e8c14Smrg	save_deplibs=$deplibs
8066b290cf36Smrg	deplibs=
8067b290cf36Smrg      fi
8068b290cf36Smrg
8069b290cf36Smrg      for deplib in $libs; do
8070b290cf36Smrg	lib=
8071ee3e8c14Smrg	found=false
8072b290cf36Smrg	case $deplib in
8073d9dcd5aeSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
80748f9fac4aSmrg        |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
8075ee3e8c14Smrg	  if test prog,link = "$linkmode,$pass"; then
8076b290cf36Smrg	    compile_deplibs="$deplib $compile_deplibs"
8077b290cf36Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
8078b290cf36Smrg	  else
8079d9dcd5aeSmrg	    func_append compiler_flags " $deplib"
8080ee3e8c14Smrg	    if test lib = "$linkmode"; then
8081b290cf36Smrg		case "$new_inherited_linker_flags " in
8082b290cf36Smrg		    *" $deplib "*) ;;
8083d9dcd5aeSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8084b290cf36Smrg		esac
8085b290cf36Smrg	    fi
8086b290cf36Smrg	  fi
8087b290cf36Smrg	  continue
8088b290cf36Smrg	  ;;
8089b290cf36Smrg	-l*)
8090ee3e8c14Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
8091ee3e8c14Smrg	    func_warning "'-l' is ignored for archives/objects"
8092b290cf36Smrg	    continue
8093b290cf36Smrg	  fi
8094b290cf36Smrg	  func_stripname '-l' '' "$deplib"
8095b290cf36Smrg	  name=$func_stripname_result
8096ee3e8c14Smrg	  if test lib = "$linkmode"; then
8097b290cf36Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
8098b290cf36Smrg	  else
8099b290cf36Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
8100b290cf36Smrg	  fi
8101b290cf36Smrg	  for searchdir in $searchdirs; do
8102b290cf36Smrg	    for search_ext in .la $std_shrext .so .a; do
8103b290cf36Smrg	      # Search the libtool library
8104ee3e8c14Smrg	      lib=$searchdir/lib$name$search_ext
8105b290cf36Smrg	      if test -f "$lib"; then
8106ee3e8c14Smrg		if test .la = "$search_ext"; then
8107ee3e8c14Smrg		  found=:
8108b290cf36Smrg		else
8109ee3e8c14Smrg		  found=false
8110b290cf36Smrg		fi
8111b290cf36Smrg		break 2
8112b290cf36Smrg	      fi
8113b290cf36Smrg	    done
8114b290cf36Smrg	  done
8115ee3e8c14Smrg	  if $found; then
8116ee3e8c14Smrg	    # deplib is a libtool library
8117b290cf36Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
8118b290cf36Smrg	    # We need to do some special things here, and not later.
8119ee3e8c14Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
8120b290cf36Smrg	      case " $predeps $postdeps " in
8121b290cf36Smrg	      *" $deplib "*)
8122b290cf36Smrg		if func_lalib_p "$lib"; then
8123b290cf36Smrg		  library_names=
8124b290cf36Smrg		  old_library=
8125b290cf36Smrg		  func_source "$lib"
8126b290cf36Smrg		  for l in $old_library $library_names; do
8127ee3e8c14Smrg		    ll=$l
8128b290cf36Smrg		  done
8129ee3e8c14Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
8130ee3e8c14Smrg		    found=false
8131b290cf36Smrg		    func_dirname "$lib" "" "."
8132ee3e8c14Smrg		    ladir=$func_dirname_result
8133b290cf36Smrg		    lib=$ladir/$old_library
8134ee3e8c14Smrg		    if test prog,link = "$linkmode,$pass"; then
8135b290cf36Smrg		      compile_deplibs="$deplib $compile_deplibs"
8136b290cf36Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
8137b290cf36Smrg		    else
8138b290cf36Smrg		      deplibs="$deplib $deplibs"
8139ee3e8c14Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8140b290cf36Smrg		    fi
8141b290cf36Smrg		    continue
8142b290cf36Smrg		  fi
8143b290cf36Smrg		fi
8144b290cf36Smrg		;;
8145b290cf36Smrg	      *) ;;
8146b290cf36Smrg	      esac
8147b290cf36Smrg	    fi
8148ee3e8c14Smrg	  else
8149ee3e8c14Smrg	    # deplib doesn't seem to be a libtool library
8150ee3e8c14Smrg	    if test prog,link = "$linkmode,$pass"; then
8151ee3e8c14Smrg	      compile_deplibs="$deplib $compile_deplibs"
8152ee3e8c14Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8153ee3e8c14Smrg	    else
8154ee3e8c14Smrg	      deplibs="$deplib $deplibs"
8155ee3e8c14Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8156ee3e8c14Smrg	    fi
8157ee3e8c14Smrg	    continue
8158b290cf36Smrg	  fi
8159b290cf36Smrg	  ;; # -l
8160b290cf36Smrg	*.ltframework)
8161ee3e8c14Smrg	  if test prog,link = "$linkmode,$pass"; then
8162b290cf36Smrg	    compile_deplibs="$deplib $compile_deplibs"
8163b290cf36Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
8164b290cf36Smrg	  else
8165b290cf36Smrg	    deplibs="$deplib $deplibs"
8166ee3e8c14Smrg	    if test lib = "$linkmode"; then
8167b290cf36Smrg		case "$new_inherited_linker_flags " in
8168b290cf36Smrg		    *" $deplib "*) ;;
8169d9dcd5aeSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
8170b290cf36Smrg		esac
8171b290cf36Smrg	    fi
8172b290cf36Smrg	  fi
8173b290cf36Smrg	  continue
8174b290cf36Smrg	  ;;
8175b290cf36Smrg	-L*)
8176b290cf36Smrg	  case $linkmode in
8177b290cf36Smrg	  lib)
8178b290cf36Smrg	    deplibs="$deplib $deplibs"
8179ee3e8c14Smrg	    test conv = "$pass" && continue
8180b290cf36Smrg	    newdependency_libs="$deplib $newdependency_libs"
8181b290cf36Smrg	    func_stripname '-L' '' "$deplib"
8182d9dcd5aeSmrg	    func_resolve_sysroot "$func_stripname_result"
8183d9dcd5aeSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8184b290cf36Smrg	    ;;
8185b290cf36Smrg	  prog)
8186ee3e8c14Smrg	    if test conv = "$pass"; then
8187b290cf36Smrg	      deplibs="$deplib $deplibs"
8188b290cf36Smrg	      continue
8189b290cf36Smrg	    fi
8190ee3e8c14Smrg	    if test scan = "$pass"; then
8191b290cf36Smrg	      deplibs="$deplib $deplibs"
8192b290cf36Smrg	    else
8193b290cf36Smrg	      compile_deplibs="$deplib $compile_deplibs"
8194b290cf36Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8195b290cf36Smrg	    fi
8196b290cf36Smrg	    func_stripname '-L' '' "$deplib"
8197d9dcd5aeSmrg	    func_resolve_sysroot "$func_stripname_result"
8198d9dcd5aeSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8199b290cf36Smrg	    ;;
8200b290cf36Smrg	  *)
8201ee3e8c14Smrg	    func_warning "'-L' is ignored for archives/objects"
8202b290cf36Smrg	    ;;
8203b290cf36Smrg	  esac # linkmode
8204b290cf36Smrg	  continue
8205b290cf36Smrg	  ;; # -L
8206b290cf36Smrg	-R*)
8207ee3e8c14Smrg	  if test link = "$pass"; then
8208b290cf36Smrg	    func_stripname '-R' '' "$deplib"
8209d9dcd5aeSmrg	    func_resolve_sysroot "$func_stripname_result"
8210d9dcd5aeSmrg	    dir=$func_resolve_sysroot_result
8211b290cf36Smrg	    # Make sure the xrpath contains only unique directories.
8212b290cf36Smrg	    case "$xrpath " in
8213b290cf36Smrg	    *" $dir "*) ;;
8214d9dcd5aeSmrg	    *) func_append xrpath " $dir" ;;
8215b290cf36Smrg	    esac
8216b290cf36Smrg	  fi
8217b290cf36Smrg	  deplibs="$deplib $deplibs"
8218b290cf36Smrg	  continue
8219b290cf36Smrg	  ;;
8220d9dcd5aeSmrg	*.la)
8221d9dcd5aeSmrg	  func_resolve_sysroot "$deplib"
8222d9dcd5aeSmrg	  lib=$func_resolve_sysroot_result
8223d9dcd5aeSmrg	  ;;
8224b290cf36Smrg	*.$libext)
8225ee3e8c14Smrg	  if test conv = "$pass"; then
8226b290cf36Smrg	    deplibs="$deplib $deplibs"
8227b290cf36Smrg	    continue
8228b290cf36Smrg	  fi
8229b290cf36Smrg	  case $linkmode in
8230b290cf36Smrg	  lib)
8231b290cf36Smrg	    # Linking convenience modules into shared libraries is allowed,
8232b290cf36Smrg	    # but linking other static libraries is non-portable.
8233b290cf36Smrg	    case " $dlpreconveniencelibs " in
8234b290cf36Smrg	    *" $deplib "*) ;;
8235b290cf36Smrg	    *)
8236ee3e8c14Smrg	      valid_a_lib=false
8237b290cf36Smrg	      case $deplibs_check_method in
8238b290cf36Smrg		match_pattern*)
8239b290cf36Smrg		  set dummy $deplibs_check_method; shift
8240b290cf36Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8241ba064abeSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8242b290cf36Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8243ee3e8c14Smrg		    valid_a_lib=:
8244b290cf36Smrg		  fi
8245b290cf36Smrg		;;
8246b290cf36Smrg		pass_all)
8247ee3e8c14Smrg		  valid_a_lib=:
8248b290cf36Smrg		;;
8249b290cf36Smrg	      esac
8250ee3e8c14Smrg	      if $valid_a_lib; then
82518f9fac4aSmrg		func_warning "Linking the shared library $output against the static library $deplib is not portable!"
8252ee3e8c14Smrg		deplibs="$deplib $deplibs"
8253ee3e8c14Smrg	      else
82548f9fac4aSmrg		func_warning "Trying to link with static lib archive $deplib."
82558f9fac4aSmrg		func_warning "I have the capability to make that library automatically link in when"
82568f9fac4aSmrg		func_warning "you link to this library.  But I can only do this if you have a"
82578f9fac4aSmrg		func_warning "shared version of the library, which you do not appear to have"
82588f9fac4aSmrg		func_warning "because the file extensions .$libext of this argument makes me believe"
82598f9fac4aSmrg		func_warning "that it is just a static archive that I should not use here."
8260b290cf36Smrg	      fi
8261b290cf36Smrg	      ;;
8262b290cf36Smrg	    esac
8263b290cf36Smrg	    continue
8264b290cf36Smrg	    ;;
8265b290cf36Smrg	  prog)
8266ee3e8c14Smrg	    if test link != "$pass"; then
8267b290cf36Smrg	      deplibs="$deplib $deplibs"
8268b290cf36Smrg	    else
8269b290cf36Smrg	      compile_deplibs="$deplib $compile_deplibs"
8270b290cf36Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8271b290cf36Smrg	    fi
8272b290cf36Smrg	    continue
8273b290cf36Smrg	    ;;
8274b290cf36Smrg	  esac # linkmode
8275b290cf36Smrg	  ;; # *.$libext
8276b290cf36Smrg	*.lo | *.$objext)
8277ee3e8c14Smrg	  if test conv = "$pass"; then
8278b290cf36Smrg	    deplibs="$deplib $deplibs"
8279ee3e8c14Smrg	  elif test prog = "$linkmode"; then
8280ee3e8c14Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8281b290cf36Smrg	      # If there is no dlopen support or we're linking statically,
8282b290cf36Smrg	      # we need to preload.
8283d9dcd5aeSmrg	      func_append newdlprefiles " $deplib"
8284b290cf36Smrg	      compile_deplibs="$deplib $compile_deplibs"
8285b290cf36Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8286b290cf36Smrg	    else
8287d9dcd5aeSmrg	      func_append newdlfiles " $deplib"
8288b290cf36Smrg	    fi
8289b290cf36Smrg	  fi
8290b290cf36Smrg	  continue
8291b290cf36Smrg	  ;;
8292b290cf36Smrg	%DEPLIBS%)
8293ee3e8c14Smrg	  alldeplibs=:
8294b290cf36Smrg	  continue
8295b290cf36Smrg	  ;;
8296b290cf36Smrg	esac # case $deplib
8297b290cf36Smrg
8298ee3e8c14Smrg	$found || test -f "$lib" \
8299ee3e8c14Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8300b290cf36Smrg
8301b290cf36Smrg	# Check to see that this really is a libtool archive.
8302b290cf36Smrg	func_lalib_unsafe_p "$lib" \
8303ee3e8c14Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8304b290cf36Smrg
8305b290cf36Smrg	func_dirname "$lib" "" "."
8306ee3e8c14Smrg	ladir=$func_dirname_result
8307b290cf36Smrg
8308b290cf36Smrg	dlname=
8309b290cf36Smrg	dlopen=
8310b290cf36Smrg	dlpreopen=
8311b290cf36Smrg	libdir=
8312b290cf36Smrg	library_names=
8313b290cf36Smrg	old_library=
8314b290cf36Smrg	inherited_linker_flags=
8315b290cf36Smrg	# If the library was installed with an old release of libtool,
8316b290cf36Smrg	# it will not redefine variables installed, or shouldnotlink
8317b290cf36Smrg	installed=yes
8318b290cf36Smrg	shouldnotlink=no
8319b290cf36Smrg	avoidtemprpath=
8320b290cf36Smrg
8321b290cf36Smrg
8322b290cf36Smrg	# Read the .la file
8323b290cf36Smrg	func_source "$lib"
8324b290cf36Smrg
8325b290cf36Smrg	# Convert "-framework foo" to "foo.ltframework"
8326b290cf36Smrg	if test -n "$inherited_linker_flags"; then
8327ba064abeSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8328b290cf36Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8329b290cf36Smrg	    case " $new_inherited_linker_flags " in
8330b290cf36Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8331d9dcd5aeSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8332b290cf36Smrg	    esac
8333b290cf36Smrg	  done
8334b290cf36Smrg	fi
8335ba064abeSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8336ee3e8c14Smrg	if test lib,link = "$linkmode,$pass" ||
8337ee3e8c14Smrg	   test prog,scan = "$linkmode,$pass" ||
8338ee3e8c14Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8339d9dcd5aeSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8340d9dcd5aeSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8341b290cf36Smrg	fi
8342b290cf36Smrg
8343ee3e8c14Smrg	if test conv = "$pass"; then
8344b290cf36Smrg	  # Only check for convenience libraries
8345b290cf36Smrg	  deplibs="$lib $deplibs"
8346b290cf36Smrg	  if test -z "$libdir"; then
8347b290cf36Smrg	    if test -z "$old_library"; then
8348ee3e8c14Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
8349b290cf36Smrg	    fi
8350b290cf36Smrg	    # It is a libtool convenience library, so add in its objects.
8351d9dcd5aeSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8352d9dcd5aeSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8353ee3e8c14Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8354ee3e8c14Smrg	    func_fatal_error "'$lib' is not a convenience library"
8355b290cf36Smrg	  fi
8356b290cf36Smrg	  tmp_libs=
8357b290cf36Smrg	  for deplib in $dependency_libs; do
8358b290cf36Smrg	    deplibs="$deplib $deplibs"
8359ee3e8c14Smrg	    if $opt_preserve_dup_deps; then
8360b290cf36Smrg	      case "$tmp_libs " in
8361d9dcd5aeSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8362b290cf36Smrg	      esac
8363b290cf36Smrg	    fi
8364d9dcd5aeSmrg	    func_append tmp_libs " $deplib"
8365b290cf36Smrg	  done
8366b290cf36Smrg	  continue
8367b290cf36Smrg	fi # $pass = conv
8368b290cf36Smrg
8369b290cf36Smrg
8370b290cf36Smrg	# Get the name of the library we link against.
8371b290cf36Smrg	linklib=
8372d9dcd5aeSmrg	if test -n "$old_library" &&
8373ee3e8c14Smrg	   { test yes = "$prefer_static_libs" ||
8374ee3e8c14Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8375d9dcd5aeSmrg	  linklib=$old_library
8376d9dcd5aeSmrg	else
8377d9dcd5aeSmrg	  for l in $old_library $library_names; do
8378ee3e8c14Smrg	    linklib=$l
8379d9dcd5aeSmrg	  done
8380d9dcd5aeSmrg	fi
8381b290cf36Smrg	if test -z "$linklib"; then
8382ee3e8c14Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
8383b290cf36Smrg	fi
8384b290cf36Smrg
8385b290cf36Smrg	# This library was specified with -dlopen.
8386ee3e8c14Smrg	if test dlopen = "$pass"; then
8387ee3e8c14Smrg	  test -z "$libdir" \
8388ee3e8c14Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8389b290cf36Smrg	  if test -z "$dlname" ||
8390ee3e8c14Smrg	     test yes != "$dlopen_support" ||
8391ee3e8c14Smrg	     test no = "$build_libtool_libs"
8392ee3e8c14Smrg	  then
8393b290cf36Smrg	    # If there is no dlname, no dlopen support or we're linking
8394b290cf36Smrg	    # statically, we need to preload.  We also need to preload any
8395b290cf36Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8396b290cf36Smrg	    # bomb out in the load deplibs phase.
8397d9dcd5aeSmrg	    func_append dlprefiles " $lib $dependency_libs"
8398b290cf36Smrg	  else
8399d9dcd5aeSmrg	    func_append newdlfiles " $lib"
8400b290cf36Smrg	  fi
8401b290cf36Smrg	  continue
8402b290cf36Smrg	fi # $pass = dlopen
8403b290cf36Smrg
8404b290cf36Smrg	# We need an absolute path.
8405b290cf36Smrg	case $ladir in
8406ee3e8c14Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8407b290cf36Smrg	*)
8408b290cf36Smrg	  abs_ladir=`cd "$ladir" && pwd`
8409b290cf36Smrg	  if test -z "$abs_ladir"; then
8410ee3e8c14Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8411b290cf36Smrg	    func_warning "passing it literally to the linker, although it might fail"
8412ee3e8c14Smrg	    abs_ladir=$ladir
8413b290cf36Smrg	  fi
8414b290cf36Smrg	  ;;
8415b290cf36Smrg	esac
8416b290cf36Smrg	func_basename "$lib"
8417ee3e8c14Smrg	laname=$func_basename_result
8418b290cf36Smrg
8419b290cf36Smrg	# Find the relevant object directory and library name.
8420ee3e8c14Smrg	if test yes = "$installed"; then
8421d9dcd5aeSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8422ee3e8c14Smrg	    func_warning "library '$lib' was moved."
8423ee3e8c14Smrg	    dir=$ladir
8424ee3e8c14Smrg	    absdir=$abs_ladir
8425ee3e8c14Smrg	    libdir=$abs_ladir
8426b290cf36Smrg	  else
8427ee3e8c14Smrg	    dir=$lt_sysroot$libdir
8428ee3e8c14Smrg	    absdir=$lt_sysroot$libdir
8429b290cf36Smrg	  fi
8430ee3e8c14Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8431b290cf36Smrg	else
8432b290cf36Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8433ee3e8c14Smrg	    dir=$ladir
8434ee3e8c14Smrg	    absdir=$abs_ladir
8435b290cf36Smrg	    # Remove this search path later
8436d9dcd5aeSmrg	    func_append notinst_path " $abs_ladir"
8437b290cf36Smrg	  else
8438ee3e8c14Smrg	    dir=$ladir/$objdir
8439ee3e8c14Smrg	    absdir=$abs_ladir/$objdir
8440b290cf36Smrg	    # Remove this search path later
8441d9dcd5aeSmrg	    func_append notinst_path " $abs_ladir"
8442b290cf36Smrg	  fi
8443b290cf36Smrg	fi # $installed = yes
8444b290cf36Smrg	func_stripname 'lib' '.la' "$laname"
8445b290cf36Smrg	name=$func_stripname_result
8446b290cf36Smrg
8447b290cf36Smrg	# This library was specified with -dlpreopen.
8448ee3e8c14Smrg	if test dlpreopen = "$pass"; then
8449ee3e8c14Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8450ee3e8c14Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8451b290cf36Smrg	  fi
8452ee3e8c14Smrg	  case $host in
8453d9dcd5aeSmrg	    # special handling for platforms with PE-DLLs.
84548f9fac4aSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
8455d9dcd5aeSmrg	      # Linker will automatically link against shared library if both
8456d9dcd5aeSmrg	      # static and shared are present.  Therefore, ensure we extract
8457d9dcd5aeSmrg	      # symbols from the import library if a shared library is present
8458d9dcd5aeSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8459d9dcd5aeSmrg	      # this by putting the import library name into $newdlprefiles.
8460d9dcd5aeSmrg	      # We recover the dlopen module name by 'saving' the la file
8461d9dcd5aeSmrg	      # name in a special purpose variable, and (later) extracting the
8462d9dcd5aeSmrg	      # dlname from the la file.
8463d9dcd5aeSmrg	      if test -n "$dlname"; then
8464d9dcd5aeSmrg	        func_tr_sh "$dir/$linklib"
8465d9dcd5aeSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8466d9dcd5aeSmrg	        func_append newdlprefiles " $dir/$linklib"
8467d9dcd5aeSmrg	      else
8468d9dcd5aeSmrg	        func_append newdlprefiles " $dir/$old_library"
8469d9dcd5aeSmrg	        # Keep a list of preopened convenience libraries to check
8470d9dcd5aeSmrg	        # that they are being used correctly in the link pass.
8471d9dcd5aeSmrg	        test -z "$libdir" && \
8472d9dcd5aeSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8473d9dcd5aeSmrg	      fi
8474d9dcd5aeSmrg	    ;;
8475d9dcd5aeSmrg	    * )
8476d9dcd5aeSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8477d9dcd5aeSmrg	      # are required to link).
8478d9dcd5aeSmrg	      if test -n "$old_library"; then
8479d9dcd5aeSmrg	        func_append newdlprefiles " $dir/$old_library"
8480d9dcd5aeSmrg	        # Keep a list of preopened convenience libraries to check
8481d9dcd5aeSmrg	        # that they are being used correctly in the link pass.
8482d9dcd5aeSmrg	        test -z "$libdir" && \
8483d9dcd5aeSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8484d9dcd5aeSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8485d9dcd5aeSmrg	      elif test -n "$dlname"; then
8486d9dcd5aeSmrg	        func_append newdlprefiles " $dir/$dlname"
8487d9dcd5aeSmrg	      else
8488d9dcd5aeSmrg	        func_append newdlprefiles " $dir/$linklib"
8489d9dcd5aeSmrg	      fi
8490d9dcd5aeSmrg	    ;;
8491d9dcd5aeSmrg	  esac
8492b290cf36Smrg	fi # $pass = dlpreopen
8493b290cf36Smrg
8494b290cf36Smrg	if test -z "$libdir"; then
8495b290cf36Smrg	  # Link the convenience library
8496ee3e8c14Smrg	  if test lib = "$linkmode"; then
8497b290cf36Smrg	    deplibs="$dir/$old_library $deplibs"
8498ee3e8c14Smrg	  elif test prog,link = "$linkmode,$pass"; then
8499b290cf36Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8500b290cf36Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8501b290cf36Smrg	  else
8502b290cf36Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8503b290cf36Smrg	  fi
8504b290cf36Smrg	  continue
8505b290cf36Smrg	fi
8506b290cf36Smrg
8507b290cf36Smrg
8508ee3e8c14Smrg	if test prog = "$linkmode" && test link != "$pass"; then
8509d9dcd5aeSmrg	  func_append newlib_search_path " $ladir"
8510b290cf36Smrg	  deplibs="$lib $deplibs"
8511b290cf36Smrg
8512ee3e8c14Smrg	  linkalldeplibs=false
8513ee3e8c14Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8514ee3e8c14Smrg	     test no = "$build_libtool_libs"; then
8515ee3e8c14Smrg	    linkalldeplibs=:
8516b290cf36Smrg	  fi
8517b290cf36Smrg
8518b290cf36Smrg	  tmp_libs=
8519b290cf36Smrg	  for deplib in $dependency_libs; do
8520b290cf36Smrg	    case $deplib in
8521b290cf36Smrg	    -L*) func_stripname '-L' '' "$deplib"
8522d9dcd5aeSmrg	         func_resolve_sysroot "$func_stripname_result"
8523d9dcd5aeSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8524b290cf36Smrg		 ;;
8525b290cf36Smrg	    esac
8526b290cf36Smrg	    # Need to link against all dependency_libs?
8527ee3e8c14Smrg	    if $linkalldeplibs; then
8528b290cf36Smrg	      deplibs="$deplib $deplibs"
8529b290cf36Smrg	    else
8530b290cf36Smrg	      # Need to hardcode shared library paths
8531b290cf36Smrg	      # or/and link against static libraries
8532b290cf36Smrg	      newdependency_libs="$deplib $newdependency_libs"
8533b290cf36Smrg	    fi
8534ee3e8c14Smrg	    if $opt_preserve_dup_deps; then
8535b290cf36Smrg	      case "$tmp_libs " in
8536d9dcd5aeSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8537b290cf36Smrg	      esac
8538b290cf36Smrg	    fi
8539d9dcd5aeSmrg	    func_append tmp_libs " $deplib"
8540b290cf36Smrg	  done # for deplib
8541b290cf36Smrg	  continue
8542b290cf36Smrg	fi # $linkmode = prog...
8543b290cf36Smrg
8544ee3e8c14Smrg	if test prog,link = "$linkmode,$pass"; then
8545b290cf36Smrg	  if test -n "$library_names" &&
8546ee3e8c14Smrg	     { { test no = "$prefer_static_libs" ||
8547ee3e8c14Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8548b290cf36Smrg	       test -z "$old_library"; }; then
8549b290cf36Smrg	    # We need to hardcode the library path
8550ee3e8c14Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8551b290cf36Smrg	      # Make sure the rpath contains only unique directories.
8552ee3e8c14Smrg	      case $temp_rpath: in
8553b290cf36Smrg	      *"$absdir:"*) ;;
85548f9fac4aSmrg              *) case $absdir in
85558f9fac4aSmrg                 "$progdir/"*) func_append temp_rpath "$absdir:" ;;
85568f9fac4aSmrg                 *)            func_append temp_rpath_tail "$absdir:" ;;
85578f9fac4aSmrg                 esac
8558b290cf36Smrg	      esac
8559b290cf36Smrg	    fi
8560b290cf36Smrg
8561b290cf36Smrg	    # Hardcode the library path.
8562b290cf36Smrg	    # Skip directories that are in the system default run-time
8563b290cf36Smrg	    # search path.
8564b290cf36Smrg	    case " $sys_lib_dlsearch_path " in
8565b290cf36Smrg	    *" $absdir "*) ;;
8566b290cf36Smrg	    *)
85678f9fac4aSmrg	      case "$compile_rpath$compile_rpath_tail " in
8568b290cf36Smrg	      *" $absdir "*) ;;
85698f9fac4aSmrg	      *) case $absdir in
85708f9fac4aSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
85718f9fac4aSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
85728f9fac4aSmrg		 esac
8573b290cf36Smrg	      esac
8574b290cf36Smrg	      ;;
8575b290cf36Smrg	    esac
8576b290cf36Smrg	    case " $sys_lib_dlsearch_path " in
8577b290cf36Smrg	    *" $libdir "*) ;;
8578b290cf36Smrg	    *)
8579b290cf36Smrg	      case "$finalize_rpath " in
8580b290cf36Smrg	      *" $libdir "*) ;;
8581d9dcd5aeSmrg	      *) func_append finalize_rpath " $libdir" ;;
8582b290cf36Smrg	      esac
8583b290cf36Smrg	      ;;
8584b290cf36Smrg	    esac
8585b290cf36Smrg	  fi # $linkmode,$pass = prog,link...
8586b290cf36Smrg
8587ee3e8c14Smrg	  if $alldeplibs &&
8588ee3e8c14Smrg	     { test pass_all = "$deplibs_check_method" ||
8589ee3e8c14Smrg	       { test yes = "$build_libtool_libs" &&
8590b290cf36Smrg		 test -n "$library_names"; }; }; then
8591b290cf36Smrg	    # We only need to search for static libraries
8592b290cf36Smrg	    continue
8593b290cf36Smrg	  fi
8594b290cf36Smrg	fi
8595b290cf36Smrg
8596b290cf36Smrg	link_static=no # Whether the deplib will be linked statically
8597b290cf36Smrg	use_static_libs=$prefer_static_libs
8598ee3e8c14Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8599b290cf36Smrg	  use_static_libs=no
8600b290cf36Smrg	fi
8601b290cf36Smrg	if test -n "$library_names" &&
8602ee3e8c14Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
86038f9fac4aSmrg	  case $host_os in
86048f9fac4aSmrg	  cygwin* | mingw* | windows* | cegcc* | os2*)
8605b290cf36Smrg	      # No point in relinking DLLs because paths are not encoded
8606d9dcd5aeSmrg	      func_append notinst_deplibs " $lib"
8607b290cf36Smrg	      need_relink=no
8608b290cf36Smrg	    ;;
8609b290cf36Smrg	  *)
8610ee3e8c14Smrg	    if test no = "$installed"; then
8611d9dcd5aeSmrg	      func_append notinst_deplibs " $lib"
8612b290cf36Smrg	      need_relink=yes
8613b290cf36Smrg	    fi
8614b290cf36Smrg	    ;;
8615b290cf36Smrg	  esac
8616b290cf36Smrg	  # This is a shared library
8617b290cf36Smrg
8618b290cf36Smrg	  # Warn about portability, can't link against -module's on some
8619b290cf36Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8620ee3e8c14Smrg	  dlopenmodule=
8621b290cf36Smrg	  for dlpremoduletest in $dlprefiles; do
8622b290cf36Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8623ee3e8c14Smrg	      dlopenmodule=$dlpremoduletest
8624b290cf36Smrg	      break
8625b290cf36Smrg	    fi
8626b290cf36Smrg	  done
8627ee3e8c14Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8628ba064abeSmrg	    echo
8629ee3e8c14Smrg	    if test prog = "$linkmode"; then
86308f9fac4aSmrg	      func_warning "Linking the executable $output against the loadable module"
8631b290cf36Smrg	    else
86328f9fac4aSmrg	      func_warning "Linking the shared library $output against the loadable module"
8633b290cf36Smrg	    fi
86348f9fac4aSmrg	    func_warning "$linklib is not portable!"
8635b290cf36Smrg	  fi
8636ee3e8c14Smrg	  if test lib = "$linkmode" &&
8637ee3e8c14Smrg	     test yes = "$hardcode_into_libs"; then
8638b290cf36Smrg	    # Hardcode the library path.
8639b290cf36Smrg	    # Skip directories that are in the system default run-time
8640b290cf36Smrg	    # search path.
8641b290cf36Smrg	    case " $sys_lib_dlsearch_path " in
8642b290cf36Smrg	    *" $absdir "*) ;;
8643b290cf36Smrg	    *)
86448f9fac4aSmrg	      case "$compile_rpath$compile_rpath_tail " in
8645b290cf36Smrg	      *" $absdir "*) ;;
86468f9fac4aSmrg	      *) case $absdir in
86478f9fac4aSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
86488f9fac4aSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
86498f9fac4aSmrg		 esac
8650b290cf36Smrg	      esac
8651b290cf36Smrg	      ;;
8652b290cf36Smrg	    esac
8653b290cf36Smrg	    case " $sys_lib_dlsearch_path " in
8654b290cf36Smrg	    *" $libdir "*) ;;
8655b290cf36Smrg	    *)
8656b290cf36Smrg	      case "$finalize_rpath " in
8657b290cf36Smrg	      *" $libdir "*) ;;
8658d9dcd5aeSmrg	      *) func_append finalize_rpath " $libdir" ;;
8659b290cf36Smrg	      esac
8660b290cf36Smrg	      ;;
8661b290cf36Smrg	    esac
8662b290cf36Smrg	  fi
8663b290cf36Smrg
8664b290cf36Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8665b290cf36Smrg	    # figure out the soname
8666b290cf36Smrg	    set dummy $library_names
8667b290cf36Smrg	    shift
8668ee3e8c14Smrg	    realname=$1
8669b290cf36Smrg	    shift
8670b290cf36Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8671b290cf36Smrg	    # use dlname if we got it. it's perfectly good, no?
8672b290cf36Smrg	    if test -n "$dlname"; then
8673ee3e8c14Smrg	      soname=$dlname
8674b290cf36Smrg	    elif test -n "$soname_spec"; then
8675b290cf36Smrg	      # bleh windows
86768f9fac4aSmrg	      case $host_os in
86778f9fac4aSmrg	      cygwin* | mingw* | windows* | cegcc* | os2*)
8678b290cf36Smrg	        func_arith $current - $age
8679b290cf36Smrg		major=$func_arith_result
8680ee3e8c14Smrg		versuffix=-$major
8681b290cf36Smrg		;;
8682b290cf36Smrg	      esac
8683b290cf36Smrg	      eval soname=\"$soname_spec\"
8684b290cf36Smrg	    else
8685ee3e8c14Smrg	      soname=$realname
8686b290cf36Smrg	    fi
8687b290cf36Smrg
8688b290cf36Smrg	    # Make a new name for the extract_expsyms_cmds to use
8689ee3e8c14Smrg	    soroot=$soname
8690b290cf36Smrg	    func_basename "$soroot"
8691ee3e8c14Smrg	    soname=$func_basename_result
8692b290cf36Smrg	    func_stripname 'lib' '.dll' "$soname"
8693b290cf36Smrg	    newlib=libimp-$func_stripname_result.a
8694b290cf36Smrg
8695b290cf36Smrg	    # If the library has no export list, then create one now
8696b290cf36Smrg	    if test -f "$output_objdir/$soname-def"; then :
8697b290cf36Smrg	    else
8698ee3e8c14Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8699b290cf36Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8700b290cf36Smrg	    fi
8701b290cf36Smrg
8702b290cf36Smrg	    # Create $newlib
8703b290cf36Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8704ee3e8c14Smrg	      func_verbose "generating import library for '$soname'"
8705b290cf36Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8706b290cf36Smrg	    fi
8707b290cf36Smrg	    # make sure the library variables are pointing to the new library
8708b290cf36Smrg	    dir=$output_objdir
8709b290cf36Smrg	    linklib=$newlib
8710b290cf36Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8711b290cf36Smrg
8712ee3e8c14Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8713b290cf36Smrg	    add_shlibpath=
8714b290cf36Smrg	    add_dir=
8715b290cf36Smrg	    add=
8716b290cf36Smrg	    lib_linked=yes
8717b290cf36Smrg	    case $hardcode_action in
8718b290cf36Smrg	    immediate | unsupported)
8719ee3e8c14Smrg	      if test no = "$hardcode_direct"; then
8720ee3e8c14Smrg		add=$dir/$linklib
8721b290cf36Smrg		case $host in
8722ee3e8c14Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8723ee3e8c14Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
87248f9fac4aSmrg		  *-*-emscripten*) add_dir=-L$dir ;;
8725b290cf36Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8726ee3e8c14Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8727b290cf36Smrg		  *-*-darwin* )
8728ee3e8c14Smrg		    # if the lib is a (non-dlopened) module then we cannot
8729b290cf36Smrg		    # link against it, someone is ignoring the earlier warnings
8730b290cf36Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8731ee3e8c14Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8732b290cf36Smrg		      if test "X$dlopenmodule" != "X$lib"; then
87338f9fac4aSmrg			func_warning "lib $linklib is a module, not a shared library"
8734ee3e8c14Smrg			if test -z "$old_library"; then
87358f9fac4aSmrg			  func_warning "And there doesn't seem to be a static archive available"
87368f9fac4aSmrg			  func_warning "The link will probably fail, sorry"
8737b290cf36Smrg			else
8738ee3e8c14Smrg			  add=$dir/$old_library
8739b290cf36Smrg			fi
8740b290cf36Smrg		      elif test -n "$old_library"; then
8741ee3e8c14Smrg			add=$dir/$old_library
8742b290cf36Smrg		      fi
8743b290cf36Smrg		    fi
8744b290cf36Smrg		esac
8745ee3e8c14Smrg	      elif test no = "$hardcode_minus_L"; then
8746b290cf36Smrg		case $host in
8747ee3e8c14Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8748b290cf36Smrg		esac
8749ee3e8c14Smrg		add_dir=-L$dir
8750ee3e8c14Smrg		add=-l$name
8751ee3e8c14Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8752ee3e8c14Smrg		add_shlibpath=$dir
8753ee3e8c14Smrg		add=-l$name
8754b290cf36Smrg	      else
8755b290cf36Smrg		lib_linked=no
8756b290cf36Smrg	      fi
8757b290cf36Smrg	      ;;
8758b290cf36Smrg	    relink)
8759ee3e8c14Smrg	      if test yes = "$hardcode_direct" &&
8760ee3e8c14Smrg	         test no = "$hardcode_direct_absolute"; then
8761ee3e8c14Smrg		add=$dir/$linklib
8762ee3e8c14Smrg	      elif test yes = "$hardcode_minus_L"; then
8763ee3e8c14Smrg		add_dir=-L$absdir
8764b290cf36Smrg		# Try looking first in the location we're being installed to.
8765b290cf36Smrg		if test -n "$inst_prefix_dir"; then
8766b290cf36Smrg		  case $libdir in
8767b290cf36Smrg		    [\\/]*)
8768d9dcd5aeSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8769b290cf36Smrg		      ;;
8770b290cf36Smrg		  esac
8771b290cf36Smrg		fi
8772ee3e8c14Smrg		add=-l$name
8773ee3e8c14Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8774ee3e8c14Smrg		add_shlibpath=$dir
8775ee3e8c14Smrg		add=-l$name
8776b290cf36Smrg	      else
8777b290cf36Smrg		lib_linked=no
8778b290cf36Smrg	      fi
8779b290cf36Smrg	      ;;
8780b290cf36Smrg	    *) lib_linked=no ;;
8781b290cf36Smrg	    esac
8782b290cf36Smrg
8783ee3e8c14Smrg	    if test yes != "$lib_linked"; then
8784b290cf36Smrg	      func_fatal_configuration "unsupported hardcode properties"
8785b290cf36Smrg	    fi
8786b290cf36Smrg
8787b290cf36Smrg	    if test -n "$add_shlibpath"; then
8788b290cf36Smrg	      case :$compile_shlibpath: in
8789b290cf36Smrg	      *":$add_shlibpath:"*) ;;
8790d9dcd5aeSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8791b290cf36Smrg	      esac
8792b290cf36Smrg	    fi
8793ee3e8c14Smrg	    if test prog = "$linkmode"; then
8794b290cf36Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8795b290cf36Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8796b290cf36Smrg	    else
8797b290cf36Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8798b290cf36Smrg	      test -n "$add" && deplibs="$add $deplibs"
8799ee3e8c14Smrg	      if test yes != "$hardcode_direct" &&
8800ee3e8c14Smrg		 test yes != "$hardcode_minus_L" &&
8801ee3e8c14Smrg		 test yes = "$hardcode_shlibpath_var"; then
8802b290cf36Smrg		case :$finalize_shlibpath: in
8803b290cf36Smrg		*":$libdir:"*) ;;
8804d9dcd5aeSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8805b290cf36Smrg		esac
8806b290cf36Smrg	      fi
8807b290cf36Smrg	    fi
8808b290cf36Smrg	  fi
8809b290cf36Smrg
8810ee3e8c14Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8811b290cf36Smrg	    add_shlibpath=
8812b290cf36Smrg	    add_dir=
8813b290cf36Smrg	    add=
8814b290cf36Smrg	    # Finalize command for both is simple: just hardcode it.
8815ee3e8c14Smrg	    if test yes = "$hardcode_direct" &&
8816ee3e8c14Smrg	       test no = "$hardcode_direct_absolute"; then
8817ee3e8c14Smrg	      add=$libdir/$linklib
8818ee3e8c14Smrg	    elif test yes = "$hardcode_minus_L"; then
88198f9fac4aSmrg	      add_dir=-L$lt_sysroot$libdir
8820ee3e8c14Smrg	      add=-l$name
8821ee3e8c14Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8822b290cf36Smrg	      case :$finalize_shlibpath: in
8823b290cf36Smrg	      *":$libdir:"*) ;;
8824d9dcd5aeSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8825b290cf36Smrg	      esac
8826ee3e8c14Smrg	      add=-l$name
8827ee3e8c14Smrg	    elif test yes = "$hardcode_automatic"; then
8828b290cf36Smrg	      if test -n "$inst_prefix_dir" &&
8829ee3e8c14Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8830ee3e8c14Smrg		add=$inst_prefix_dir$libdir/$linklib
8831b290cf36Smrg	      else
8832ee3e8c14Smrg		add=$libdir/$linklib
8833b290cf36Smrg	      fi
8834b290cf36Smrg	    else
8835b290cf36Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
88368f9fac4aSmrg	      add_dir=-L$lt_sysroot$libdir
8837b290cf36Smrg	      # Try looking first in the location we're being installed to.
8838b290cf36Smrg	      if test -n "$inst_prefix_dir"; then
8839b290cf36Smrg		case $libdir in
8840b290cf36Smrg		  [\\/]*)
8841d9dcd5aeSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8842b290cf36Smrg		    ;;
8843b290cf36Smrg		esac
8844b290cf36Smrg	      fi
8845ee3e8c14Smrg	      add=-l$name
8846b290cf36Smrg	    fi
8847b290cf36Smrg
8848ee3e8c14Smrg	    if test prog = "$linkmode"; then
8849b290cf36Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8850b290cf36Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8851b290cf36Smrg	    else
8852b290cf36Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8853b290cf36Smrg	      test -n "$add" && deplibs="$add $deplibs"
8854b290cf36Smrg	    fi
8855b290cf36Smrg	  fi
8856ee3e8c14Smrg	elif test prog = "$linkmode"; then
8857b290cf36Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8858b290cf36Smrg	  # is not unsupported.  This is valid on all known static and
8859b290cf36Smrg	  # shared platforms.
8860ee3e8c14Smrg	  if test unsupported != "$hardcode_direct"; then
8861ee3e8c14Smrg	    test -n "$old_library" && linklib=$old_library
8862b290cf36Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8863b290cf36Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8864b290cf36Smrg	  else
8865b290cf36Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8866b290cf36Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8867b290cf36Smrg	  fi
8868ee3e8c14Smrg	elif test yes = "$build_libtool_libs"; then
8869b290cf36Smrg	  # Not a shared library
8870ee3e8c14Smrg	  if test pass_all != "$deplibs_check_method"; then
8871b290cf36Smrg	    # We're trying link a shared library against a static one
8872b290cf36Smrg	    # but the system doesn't support it.
8873b290cf36Smrg
8874b290cf36Smrg	    # Just print a warning and add the library to dependency_libs so
8875b290cf36Smrg	    # that the program can be linked against the static library.
88768f9fac4aSmrg	    func_warning "This system cannot link to static lib archive $lib."
88778f9fac4aSmrg	    func_warning "I have the capability to make that library automatically link in when"
88788f9fac4aSmrg	    func_warning "you link to this library.  But I can only do this if you have a"
88798f9fac4aSmrg	    func_warning "shared version of the library, which you do not appear to have."
8880ee3e8c14Smrg	    if test yes = "$module"; then
88818f9fac4aSmrg	      func_warning "But as you try to build a module library, libtool will still create "
88828f9fac4aSmrg	      func_warning "a static module, that should work as long as the dlopening application"
88838f9fac4aSmrg	      func_warning "is linked with the -dlopen flag to resolve symbols at runtime."
8884b290cf36Smrg	      if test -z "$global_symbol_pipe"; then
88858f9fac4aSmrg		func_warning "However, this would only work if libtool was able to extract symbol"
88868f9fac4aSmrg		func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
88878f9fac4aSmrg		func_warning "not find such a program.  So, this module is probably useless."
88888f9fac4aSmrg		func_warning "'nm' from GNU binutils and a full rebuild may help."
8889b290cf36Smrg	      fi
8890ee3e8c14Smrg	      if test no = "$build_old_libs"; then
8891b290cf36Smrg		build_libtool_libs=module
8892b290cf36Smrg		build_old_libs=yes
8893b290cf36Smrg	      else
8894b290cf36Smrg		build_libtool_libs=no
8895b290cf36Smrg	      fi
8896b290cf36Smrg	    fi
8897b290cf36Smrg	  else
8898b290cf36Smrg	    deplibs="$dir/$old_library $deplibs"
8899b290cf36Smrg	    link_static=yes
8900b290cf36Smrg	  fi
8901b290cf36Smrg	fi # link shared/static library?
8902b290cf36Smrg
8903ee3e8c14Smrg	if test lib = "$linkmode"; then
8904b290cf36Smrg	  if test -n "$dependency_libs" &&
8905ee3e8c14Smrg	     { test yes != "$hardcode_into_libs" ||
8906ee3e8c14Smrg	       test yes = "$build_old_libs" ||
8907ee3e8c14Smrg	       test yes = "$link_static"; }; then
8908b290cf36Smrg	    # Extract -R from dependency_libs
8909b290cf36Smrg	    temp_deplibs=
8910b290cf36Smrg	    for libdir in $dependency_libs; do
8911b290cf36Smrg	      case $libdir in
8912b290cf36Smrg	      -R*) func_stripname '-R' '' "$libdir"
8913b290cf36Smrg	           temp_xrpath=$func_stripname_result
8914b290cf36Smrg		   case " $xrpath " in
8915b290cf36Smrg		   *" $temp_xrpath "*) ;;
8916d9dcd5aeSmrg		   *) func_append xrpath " $temp_xrpath";;
8917b290cf36Smrg		   esac;;
8918d9dcd5aeSmrg	      *) func_append temp_deplibs " $libdir";;
8919b290cf36Smrg	      esac
8920b290cf36Smrg	    done
8921ee3e8c14Smrg	    dependency_libs=$temp_deplibs
8922b290cf36Smrg	  fi
8923b290cf36Smrg
8924d9dcd5aeSmrg	  func_append newlib_search_path " $absdir"
8925b290cf36Smrg	  # Link against this library
8926ee3e8c14Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8927b290cf36Smrg	  # ... and its dependency_libs
8928b290cf36Smrg	  tmp_libs=
8929b290cf36Smrg	  for deplib in $dependency_libs; do
8930b290cf36Smrg	    newdependency_libs="$deplib $newdependency_libs"
8931d9dcd5aeSmrg	    case $deplib in
8932d9dcd5aeSmrg              -L*) func_stripname '-L' '' "$deplib"
8933d9dcd5aeSmrg                   func_resolve_sysroot "$func_stripname_result";;
8934d9dcd5aeSmrg              *) func_resolve_sysroot "$deplib" ;;
8935d9dcd5aeSmrg            esac
8936ee3e8c14Smrg	    if $opt_preserve_dup_deps; then
8937b290cf36Smrg	      case "$tmp_libs " in
8938d9dcd5aeSmrg	      *" $func_resolve_sysroot_result "*)
8939d9dcd5aeSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8940b290cf36Smrg	      esac
8941b290cf36Smrg	    fi
8942d9dcd5aeSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8943b290cf36Smrg	  done
8944b290cf36Smrg
8945ee3e8c14Smrg	  if test no != "$link_all_deplibs"; then
8946b290cf36Smrg	    # Add the search paths of all dependency libraries
8947b290cf36Smrg	    for deplib in $dependency_libs; do
8948ba064abeSmrg	      path=
8949b290cf36Smrg	      case $deplib in
8950ee3e8c14Smrg	      -L*) path=$deplib ;;
8951b290cf36Smrg	      *.la)
8952d9dcd5aeSmrg	        func_resolve_sysroot "$deplib"
8953d9dcd5aeSmrg	        deplib=$func_resolve_sysroot_result
8954b290cf36Smrg	        func_dirname "$deplib" "" "."
8955d9dcd5aeSmrg		dir=$func_dirname_result
8956b290cf36Smrg		# We need an absolute path.
8957b290cf36Smrg		case $dir in
8958ee3e8c14Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8959b290cf36Smrg		*)
8960b290cf36Smrg		  absdir=`cd "$dir" && pwd`
8961b290cf36Smrg		  if test -z "$absdir"; then
8962ee3e8c14Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8963ee3e8c14Smrg		    absdir=$dir
8964b290cf36Smrg		  fi
8965b290cf36Smrg		  ;;
8966b290cf36Smrg		esac
8967b290cf36Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8968b290cf36Smrg		case $host in
8969b290cf36Smrg		*-*-darwin*)
8970b290cf36Smrg		  depdepl=
8971ee3e8c14Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8972ee3e8c14Smrg		  if test -n "$deplibrary_names"; then
8973ee3e8c14Smrg		    for tmp in $deplibrary_names; do
8974b290cf36Smrg		      depdepl=$tmp
8975b290cf36Smrg		    done
8976ee3e8c14Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8977ee3e8c14Smrg		      depdepl=$absdir/$objdir/$depdepl
8978ee3e8c14Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8979b290cf36Smrg                      if test -z "$darwin_install_name"; then
8980ee3e8c14Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8981b290cf36Smrg                      fi
8982ee3e8c14Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8983ee3e8c14Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8984b290cf36Smrg		      path=
8985b290cf36Smrg		    fi
8986b290cf36Smrg		  fi
8987b290cf36Smrg		  ;;
8988b290cf36Smrg		*)
8989ee3e8c14Smrg		  path=-L$absdir/$objdir
8990b290cf36Smrg		  ;;
8991b290cf36Smrg		esac
8992b290cf36Smrg		else
8993ee3e8c14Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8994b290cf36Smrg		  test -z "$libdir" && \
8995ee3e8c14Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8996b290cf36Smrg		  test "$absdir" != "$libdir" && \
8997ee3e8c14Smrg		    func_warning "'$deplib' seems to be moved"
8998b290cf36Smrg
8999ee3e8c14Smrg		  path=-L$absdir
9000b290cf36Smrg		fi
9001b290cf36Smrg		;;
9002b290cf36Smrg	      esac
9003b290cf36Smrg	      case " $deplibs " in
9004b290cf36Smrg	      *" $path "*) ;;
9005b290cf36Smrg	      *) deplibs="$path $deplibs" ;;
9006b290cf36Smrg	      esac
9007b290cf36Smrg	    done
9008b290cf36Smrg	  fi # link_all_deplibs != no
9009b290cf36Smrg	fi # linkmode = lib
9010b290cf36Smrg      done # for deplib in $libs
90118f9fac4aSmrg
90128f9fac4aSmrg      func_append temp_rpath "$temp_rpath_tail"
90138f9fac4aSmrg      func_append compile_rpath "$compile_rpath_tail"
90148f9fac4aSmrg
9015ee3e8c14Smrg      if test link = "$pass"; then
9016ee3e8c14Smrg	if test prog = "$linkmode"; then
9017b290cf36Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
9018b290cf36Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
9019b290cf36Smrg	else
9020ba064abeSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9021b290cf36Smrg	fi
9022b290cf36Smrg      fi
9023ee3e8c14Smrg      dependency_libs=$newdependency_libs
9024ee3e8c14Smrg      if test dlpreopen = "$pass"; then
9025b290cf36Smrg	# Link the dlpreopened libraries before other libraries
9026b290cf36Smrg	for deplib in $save_deplibs; do
9027b290cf36Smrg	  deplibs="$deplib $deplibs"
9028b290cf36Smrg	done
9029b290cf36Smrg      fi
9030ee3e8c14Smrg      if test dlopen != "$pass"; then
9031ee3e8c14Smrg	test conv = "$pass" || {
9032b290cf36Smrg	  # Make sure lib_search_path contains only unique directories.
9033b290cf36Smrg	  lib_search_path=
9034b290cf36Smrg	  for dir in $newlib_search_path; do
9035b290cf36Smrg	    case "$lib_search_path " in
9036b290cf36Smrg	    *" $dir "*) ;;
9037d9dcd5aeSmrg	    *) func_append lib_search_path " $dir" ;;
9038b290cf36Smrg	    esac
9039b290cf36Smrg	  done
9040b290cf36Smrg	  newlib_search_path=
9041ee3e8c14Smrg	}
9042b290cf36Smrg
9043ee3e8c14Smrg	if test prog,link = "$linkmode,$pass"; then
9044b290cf36Smrg	  vars="compile_deplibs finalize_deplibs"
9045ee3e8c14Smrg	else
9046ee3e8c14Smrg	  vars=deplibs
9047b290cf36Smrg	fi
9048b290cf36Smrg	for var in $vars dependency_libs; do
9049b290cf36Smrg	  # Add libraries to $var in reverse order
9050b290cf36Smrg	  eval tmp_libs=\"\$$var\"
9051b290cf36Smrg	  new_libs=
90528f9fac4aSmrg	  # FIXME: Pedantically, this is the right thing to do, so
90538f9fac4aSmrg	  #        that some nasty dependency loop isn't accidentally
90548f9fac4aSmrg	  #        broken: new_libs="$deplib $new_libs"
9055b290cf36Smrg	  for deplib in $tmp_libs; do
90568f9fac4aSmrg	    if $opt_preserve_dup_deps; then
90578f9fac4aSmrg	      new_libs="$deplib $new_libs"
90588f9fac4aSmrg	    else
90598f9fac4aSmrg	      # Pragmatically, this seems to cause very few problems in
90608f9fac4aSmrg	      # practice:
90618f9fac4aSmrg	      case $deplib in
90628f9fac4aSmrg	      -L*) new_libs="$deplib $new_libs" ;;
90638f9fac4aSmrg	      -R*) ;;
9064b290cf36Smrg	      *)
90658f9fac4aSmrg	        # And here is the reason: when a library appears more
90668f9fac4aSmrg	        # than once as an explicit dependence of a library, or
90678f9fac4aSmrg	        # is implicitly linked in more than once by the
90688f9fac4aSmrg	        # compiler, it is considered special, and multiple
90698f9fac4aSmrg	        # occurrences thereof are not removed.  Compare this
90708f9fac4aSmrg	        # with having the same library being listed as a
90718f9fac4aSmrg	        # dependency of multiple other libraries: in this case,
90728f9fac4aSmrg	        # we know (pedantically, we assume) the library does not
90738f9fac4aSmrg	        # need to be listed more than once, so we keep only the
90748f9fac4aSmrg	        # last copy.  This is not always right, but it is rare
90758f9fac4aSmrg	        # enough that we require users that really mean to play
90768f9fac4aSmrg	        # such unportable linking tricks to link the library
90778f9fac4aSmrg	        # using -Wl,-lname, so that libtool does not consider it
90788f9fac4aSmrg	        # for duplicate removal.  And if not possible for portability
90798f9fac4aSmrg	        # reasons, then --preserve-dup-deps should be used.
90808f9fac4aSmrg	        case " $specialdeplibs " in
90818f9fac4aSmrg	        *" $deplib "*) new_libs="$deplib $new_libs" ;;
90828f9fac4aSmrg	        *)
90838f9fac4aSmrg	          case " $new_libs " in
90848f9fac4aSmrg	          *" $deplib "*) ;;
90858f9fac4aSmrg	          *) new_libs="$deplib $new_libs" ;;
90868f9fac4aSmrg	          esac
90878f9fac4aSmrg	          ;;
90888f9fac4aSmrg	        esac
90898f9fac4aSmrg	        ;;
9090b290cf36Smrg	      esac
90918f9fac4aSmrg	    fi
9092b290cf36Smrg	  done
9093b290cf36Smrg	  tmp_libs=
9094b290cf36Smrg	  for deplib in $new_libs; do
9095b290cf36Smrg	    case $deplib in
9096b290cf36Smrg	    -L*)
9097b290cf36Smrg	      case " $tmp_libs " in
9098b290cf36Smrg	      *" $deplib "*) ;;
9099d9dcd5aeSmrg	      *) func_append tmp_libs " $deplib" ;;
9100b290cf36Smrg	      esac
9101b290cf36Smrg	      ;;
9102d9dcd5aeSmrg	    *) func_append tmp_libs " $deplib" ;;
9103b290cf36Smrg	    esac
9104b290cf36Smrg	  done
9105b290cf36Smrg	  eval $var=\"$tmp_libs\"
9106b290cf36Smrg	done # for var
9107b290cf36Smrg      fi
9108ee3e8c14Smrg
9109ee3e8c14Smrg      # Add Sun CC postdeps if required:
9110ee3e8c14Smrg      test CXX = "$tagname" && {
9111ee3e8c14Smrg        case $host_os in
9112ee3e8c14Smrg        linux*)
9113ee3e8c14Smrg          case `$CC -V 2>&1 | $SED 5q` in
9114ee3e8c14Smrg          *Sun\ C*) # Sun C++ 5.9
9115ee3e8c14Smrg            func_suncc_cstd_abi
9116ee3e8c14Smrg
9117ee3e8c14Smrg            if test no != "$suncc_use_cstd_abi"; then
9118ee3e8c14Smrg              func_append postdeps ' -library=Cstd -library=Crun'
9119ee3e8c14Smrg            fi
9120ee3e8c14Smrg            ;;
9121ee3e8c14Smrg          esac
9122ee3e8c14Smrg          ;;
9123ee3e8c14Smrg
9124ee3e8c14Smrg        solaris*)
9125ee3e8c14Smrg          func_cc_basename "$CC"
9126ee3e8c14Smrg          case $func_cc_basename_result in
9127ee3e8c14Smrg          CC* | sunCC*)
9128ee3e8c14Smrg            func_suncc_cstd_abi
9129ee3e8c14Smrg
9130ee3e8c14Smrg            if test no != "$suncc_use_cstd_abi"; then
9131ee3e8c14Smrg              func_append postdeps ' -library=Cstd -library=Crun'
9132ee3e8c14Smrg            fi
9133ee3e8c14Smrg            ;;
9134ee3e8c14Smrg          esac
9135ee3e8c14Smrg          ;;
9136ee3e8c14Smrg        esac
9137ee3e8c14Smrg      }
9138ee3e8c14Smrg
9139b290cf36Smrg      # Last step: remove runtime libs from dependency_libs
9140b290cf36Smrg      # (they stay in deplibs)
9141b290cf36Smrg      tmp_libs=
9142ee3e8c14Smrg      for i in $dependency_libs; do
9143b290cf36Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
9144b290cf36Smrg	*" $i "*)
9145ee3e8c14Smrg	  i=
9146b290cf36Smrg	  ;;
9147b290cf36Smrg	esac
9148ee3e8c14Smrg	if test -n "$i"; then
9149d9dcd5aeSmrg	  func_append tmp_libs " $i"
9150b290cf36Smrg	fi
9151b290cf36Smrg      done
9152b290cf36Smrg      dependency_libs=$tmp_libs
9153b290cf36Smrg    done # for pass
9154ee3e8c14Smrg    if test prog = "$linkmode"; then
9155ee3e8c14Smrg      dlfiles=$newdlfiles
9156b290cf36Smrg    fi
9157ee3e8c14Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
9158ee3e8c14Smrg      dlprefiles=$newdlprefiles
9159b290cf36Smrg    fi
9160b290cf36Smrg
9161b290cf36Smrg    case $linkmode in
9162b290cf36Smrg    oldlib)
9163ee3e8c14Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
9164ee3e8c14Smrg	func_warning "'-dlopen' is ignored for archives"
9165b290cf36Smrg      fi
9166b290cf36Smrg
9167b290cf36Smrg      case " $deplibs" in
9168b290cf36Smrg      *\ -l* | *\ -L*)
9169ee3e8c14Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
9170b290cf36Smrg      esac
9171b290cf36Smrg
9172b290cf36Smrg      test -n "$rpath" && \
9173ee3e8c14Smrg	func_warning "'-rpath' is ignored for archives"
9174b290cf36Smrg
9175b290cf36Smrg      test -n "$xrpath" && \
9176ee3e8c14Smrg	func_warning "'-R' is ignored for archives"
9177b290cf36Smrg
9178b290cf36Smrg      test -n "$vinfo" && \
9179ee3e8c14Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
9180b290cf36Smrg
9181b290cf36Smrg      test -n "$release" && \
9182ee3e8c14Smrg	func_warning "'-release' is ignored for archives"
9183b290cf36Smrg
9184b290cf36Smrg      test -n "$export_symbols$export_symbols_regex" && \
9185ee3e8c14Smrg	func_warning "'-export-symbols' is ignored for archives"
9186b290cf36Smrg
9187b290cf36Smrg      # Now set the variables for building old libraries.
9188b290cf36Smrg      build_libtool_libs=no
9189ee3e8c14Smrg      oldlibs=$output
9190d9dcd5aeSmrg      func_append objs "$old_deplibs"
9191b290cf36Smrg      ;;
9192b290cf36Smrg
9193b290cf36Smrg    lib)
9194ee3e8c14Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9195b290cf36Smrg      case $outputname in
9196b290cf36Smrg      lib*)
9197b290cf36Smrg	func_stripname 'lib' '.la' "$outputname"
9198b290cf36Smrg	name=$func_stripname_result
9199b290cf36Smrg	eval shared_ext=\"$shrext_cmds\"
9200b290cf36Smrg	eval libname=\"$libname_spec\"
9201b290cf36Smrg	;;
9202b290cf36Smrg      *)
9203ee3e8c14Smrg	test no = "$module" \
9204ee3e8c14Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9205b290cf36Smrg
9206ee3e8c14Smrg	if test no != "$need_lib_prefix"; then
9207b290cf36Smrg	  # Add the "lib" prefix for modules if required
9208b290cf36Smrg	  func_stripname '' '.la' "$outputname"
9209b290cf36Smrg	  name=$func_stripname_result
9210b290cf36Smrg	  eval shared_ext=\"$shrext_cmds\"
9211b290cf36Smrg	  eval libname=\"$libname_spec\"
9212b290cf36Smrg	else
9213b290cf36Smrg	  func_stripname '' '.la' "$outputname"
9214b290cf36Smrg	  libname=$func_stripname_result
9215b290cf36Smrg	fi
9216b290cf36Smrg	;;
9217b290cf36Smrg      esac
9218b290cf36Smrg
9219b290cf36Smrg      if test -n "$objs"; then
9220ee3e8c14Smrg	if test pass_all != "$deplibs_check_method"; then
9221ee3e8c14Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9222b290cf36Smrg	else
92238f9fac4aSmrg	  func_warning "Linking the shared library $output against the non-libtool objects $objs is not portable!"
9224d9dcd5aeSmrg	  func_append libobjs " $objs"
9225b290cf36Smrg	fi
9226b290cf36Smrg      fi
9227b290cf36Smrg
9228ee3e8c14Smrg      test no = "$dlself" \
9229ee3e8c14Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9230b290cf36Smrg
9231b290cf36Smrg      set dummy $rpath
9232b290cf36Smrg      shift
9233ee3e8c14Smrg      test 1 -lt "$#" \
9234ee3e8c14Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9235b290cf36Smrg
9236ee3e8c14Smrg      install_libdir=$1
9237b290cf36Smrg
9238b290cf36Smrg      oldlibs=
9239b290cf36Smrg      if test -z "$rpath"; then
9240ee3e8c14Smrg	if test yes = "$build_libtool_libs"; then
9241b290cf36Smrg	  # Building a libtool convenience library.
9242ee3e8c14Smrg	  # Some compilers have problems with a '.al' extension so
9243b290cf36Smrg	  # convenience libraries should have the same extension an
9244b290cf36Smrg	  # archive normally would.
9245b290cf36Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9246b290cf36Smrg	  build_libtool_libs=convenience
9247b290cf36Smrg	  build_old_libs=yes
9248b290cf36Smrg	fi
9249b290cf36Smrg
9250b290cf36Smrg	test -n "$vinfo" && \
9251ee3e8c14Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9252b290cf36Smrg
9253b290cf36Smrg	test -n "$release" && \
9254ee3e8c14Smrg	  func_warning "'-release' is ignored for convenience libraries"
9255b290cf36Smrg      else
9256b290cf36Smrg
9257b290cf36Smrg	# Parse the version information argument.
9258ee3e8c14Smrg	save_ifs=$IFS; IFS=:
9259b290cf36Smrg	set dummy $vinfo 0 0 0
9260b290cf36Smrg	shift
9261ee3e8c14Smrg	IFS=$save_ifs
9262b290cf36Smrg
9263b290cf36Smrg	test -n "$7" && \
9264ee3e8c14Smrg	  func_fatal_help "too many parameters to '-version-info'"
9265b290cf36Smrg
9266b290cf36Smrg	# convert absolute version numbers to libtool ages
9267b290cf36Smrg	# this retains compatibility with .la files and attempts
9268b290cf36Smrg	# to make the code below a bit more comprehensible
9269b290cf36Smrg
9270b290cf36Smrg	case $vinfo_number in
9271b290cf36Smrg	yes)
9272ee3e8c14Smrg	  number_major=$1
9273ee3e8c14Smrg	  number_minor=$2
9274ee3e8c14Smrg	  number_revision=$3
9275b290cf36Smrg	  #
9276b290cf36Smrg	  # There are really only two kinds -- those that
9277b290cf36Smrg	  # use the current revision as the major version
9278b290cf36Smrg	  # and those that subtract age and use age as
9279b290cf36Smrg	  # a minor version.  But, then there is irix
9280ee3e8c14Smrg	  # that has an extra 1 added just for fun
9281b290cf36Smrg	  #
9282b290cf36Smrg	  case $version_type in
9283d9dcd5aeSmrg	  # correct linux to gnu/linux during the next big refactor
92848f9fac4aSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|qnx|windows|none)
9285b290cf36Smrg	    func_arith $number_major + $number_minor
9286b290cf36Smrg	    current=$func_arith_result
9287ee3e8c14Smrg	    age=$number_minor
9288ee3e8c14Smrg	    revision=$number_revision
9289b290cf36Smrg	    ;;
92908f9fac4aSmrg	  freebsd-aout|sco|sunos)
9291ee3e8c14Smrg	    current=$number_major
9292ee3e8c14Smrg	    revision=$number_minor
9293ee3e8c14Smrg	    age=0
9294b290cf36Smrg	    ;;
9295b290cf36Smrg	  irix|nonstopux)
9296b290cf36Smrg	    func_arith $number_major + $number_minor
9297b290cf36Smrg	    current=$func_arith_result
9298ee3e8c14Smrg	    age=$number_minor
9299ee3e8c14Smrg	    revision=$number_minor
9300b290cf36Smrg	    lt_irix_increment=no
9301b290cf36Smrg	    ;;
93028f9fac4aSmrg	  *)
93038f9fac4aSmrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
93048f9fac4aSmrg	    ;;
9305b290cf36Smrg	  esac
9306b290cf36Smrg	  ;;
9307b290cf36Smrg	no)
9308ee3e8c14Smrg	  current=$1
9309ee3e8c14Smrg	  revision=$2
9310ee3e8c14Smrg	  age=$3
9311b290cf36Smrg	  ;;
9312b290cf36Smrg	esac
9313b290cf36Smrg
9314b290cf36Smrg	# Check that each of the things are valid numbers.
9315b290cf36Smrg	case $current in
9316b290cf36Smrg	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]) ;;
9317b290cf36Smrg	*)
9318ee3e8c14Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9319ee3e8c14Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9320b290cf36Smrg	  ;;
9321b290cf36Smrg	esac
9322b290cf36Smrg
9323b290cf36Smrg	case $revision in
9324b290cf36Smrg	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]) ;;
9325b290cf36Smrg	*)
9326ee3e8c14Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9327ee3e8c14Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9328b290cf36Smrg	  ;;
9329b290cf36Smrg	esac
9330b290cf36Smrg
9331b290cf36Smrg	case $age in
9332b290cf36Smrg	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]) ;;
9333b290cf36Smrg	*)
9334ee3e8c14Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9335ee3e8c14Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9336b290cf36Smrg	  ;;
9337b290cf36Smrg	esac
9338b290cf36Smrg
9339b290cf36Smrg	if test "$age" -gt "$current"; then
9340ee3e8c14Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9341ee3e8c14Smrg	  func_fatal_error "'$vinfo' is not valid version information"
9342b290cf36Smrg	fi
9343b290cf36Smrg
9344b290cf36Smrg	# Calculate the version variables.
9345b290cf36Smrg	major=
9346b290cf36Smrg	versuffix=
9347b290cf36Smrg	verstring=
9348b290cf36Smrg	case $version_type in
9349b290cf36Smrg	none) ;;
9350b290cf36Smrg
9351b290cf36Smrg	darwin)
9352b290cf36Smrg	  # Like Linux, but with the current version available in
9353b290cf36Smrg	  # verstring for coding it into the library header
9354b290cf36Smrg	  func_arith $current - $age
9355b290cf36Smrg	  major=.$func_arith_result
9356ee3e8c14Smrg	  versuffix=$major.$age.$revision
9357b290cf36Smrg	  # Darwin ld doesn't like 0 for these options...
9358b290cf36Smrg	  func_arith $current + 1
9359b290cf36Smrg	  minor_current=$func_arith_result
9360ee3e8c14Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9361b290cf36Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9362ee3e8c14Smrg          # On Darwin other compilers
9363ee3e8c14Smrg          case $CC in
9364ee3e8c14Smrg              nagfor*)
9365ee3e8c14Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9366ee3e8c14Smrg                  ;;
9367ee3e8c14Smrg              *)
9368ee3e8c14Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9369ee3e8c14Smrg                  ;;
9370ee3e8c14Smrg          esac
9371b290cf36Smrg	  ;;
9372b290cf36Smrg
9373b290cf36Smrg	freebsd-aout)
9374ee3e8c14Smrg	  major=.$current
9375ee3e8c14Smrg	  versuffix=.$current.$revision
9376b290cf36Smrg	  ;;
9377b290cf36Smrg
9378ee3e8c14Smrg	freebsd-elf | midnightbsd-elf)
9379ee3e8c14Smrg	  func_arith $current - $age
9380ee3e8c14Smrg	  major=.$func_arith_result
9381ee3e8c14Smrg	  versuffix=$major.$age.$revision
9382b290cf36Smrg	  ;;
9383b290cf36Smrg
9384b290cf36Smrg	irix | nonstopux)
9385ee3e8c14Smrg	  if test no = "$lt_irix_increment"; then
9386b290cf36Smrg	    func_arith $current - $age
9387b290cf36Smrg	  else
9388b290cf36Smrg	    func_arith $current - $age + 1
9389b290cf36Smrg	  fi
9390b290cf36Smrg	  major=$func_arith_result
9391b290cf36Smrg
9392b290cf36Smrg	  case $version_type in
9393b290cf36Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9394b290cf36Smrg	    *)         verstring_prefix=sgi ;;
9395b290cf36Smrg	  esac
9396ee3e8c14Smrg	  verstring=$verstring_prefix$major.$revision
9397b290cf36Smrg
9398b290cf36Smrg	  # Add in all the interfaces that we are compatible with.
9399b290cf36Smrg	  loop=$revision
9400ee3e8c14Smrg	  while test 0 -ne "$loop"; do
9401b290cf36Smrg	    func_arith $revision - $loop
9402b290cf36Smrg	    iface=$func_arith_result
9403b290cf36Smrg	    func_arith $loop - 1
9404b290cf36Smrg	    loop=$func_arith_result
9405ee3e8c14Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
9406b290cf36Smrg	  done
9407b290cf36Smrg
9408ee3e8c14Smrg	  # Before this point, $major must not contain '.'.
9409b290cf36Smrg	  major=.$major
9410ee3e8c14Smrg	  versuffix=$major.$revision
9411b290cf36Smrg	  ;;
9412b290cf36Smrg
9413d9dcd5aeSmrg	linux) # correct to gnu/linux during the next big refactor
9414b290cf36Smrg	  func_arith $current - $age
9415b290cf36Smrg	  major=.$func_arith_result
9416ee3e8c14Smrg	  versuffix=$major.$age.$revision
9417b290cf36Smrg	  ;;
9418b290cf36Smrg
9419b290cf36Smrg	osf)
9420b290cf36Smrg	  func_arith $current - $age
9421b290cf36Smrg	  major=.$func_arith_result
9422ee3e8c14Smrg	  versuffix=.$current.$age.$revision
9423ee3e8c14Smrg	  verstring=$current.$age.$revision
9424b290cf36Smrg
9425b290cf36Smrg	  # Add in all the interfaces that we are compatible with.
9426b290cf36Smrg	  loop=$age
9427ee3e8c14Smrg	  while test 0 -ne "$loop"; do
9428b290cf36Smrg	    func_arith $current - $loop
9429b290cf36Smrg	    iface=$func_arith_result
9430b290cf36Smrg	    func_arith $loop - 1
9431b290cf36Smrg	    loop=$func_arith_result
9432ee3e8c14Smrg	    verstring=$verstring:$iface.0
9433b290cf36Smrg	  done
9434b290cf36Smrg
9435b290cf36Smrg	  # Make executables depend on our current version.
9436ee3e8c14Smrg	  func_append verstring ":$current.0"
9437b290cf36Smrg	  ;;
9438b290cf36Smrg
9439b290cf36Smrg	qnx)
94408f9fac4aSmrg	  func_arith $current - $age
94418f9fac4aSmrg	  major=.$func_arith_result
94428f9fac4aSmrg	  versuffix=$major.$age.$revision
9443ee3e8c14Smrg	  ;;
9444ee3e8c14Smrg
9445ee3e8c14Smrg	sco)
9446ee3e8c14Smrg	  major=.$current
9447ee3e8c14Smrg	  versuffix=.$current
9448b290cf36Smrg	  ;;
9449b290cf36Smrg
9450b290cf36Smrg	sunos)
9451ee3e8c14Smrg	  major=.$current
9452ee3e8c14Smrg	  versuffix=.$current.$revision
9453b290cf36Smrg	  ;;
9454b290cf36Smrg
9455b290cf36Smrg	windows)
9456b290cf36Smrg	  # Use '-' rather than '.', since we only want one
9457ee3e8c14Smrg	  # extension on DOS 8.3 file systems.
9458b290cf36Smrg	  func_arith $current - $age
9459b290cf36Smrg	  major=$func_arith_result
9460ee3e8c14Smrg	  versuffix=-$major
9461b290cf36Smrg	  ;;
9462b290cf36Smrg
9463b290cf36Smrg	*)
9464ee3e8c14Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
9465b290cf36Smrg	  ;;
9466b290cf36Smrg	esac
9467b290cf36Smrg
9468b290cf36Smrg	# Clear the version info if we defaulted, and they specified a release.
9469b290cf36Smrg	if test -z "$vinfo" && test -n "$release"; then
9470b290cf36Smrg	  major=
9471b290cf36Smrg	  case $version_type in
9472b290cf36Smrg	  darwin)
9473b290cf36Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9474b290cf36Smrg	    # problems, so we reset it completely
9475b290cf36Smrg	    verstring=
9476b290cf36Smrg	    ;;
9477b290cf36Smrg	  *)
9478ee3e8c14Smrg	    verstring=0.0
9479b290cf36Smrg	    ;;
9480b290cf36Smrg	  esac
9481ee3e8c14Smrg	  if test no = "$need_version"; then
9482b290cf36Smrg	    versuffix=
9483b290cf36Smrg	  else
9484ee3e8c14Smrg	    versuffix=.0.0
9485b290cf36Smrg	  fi
9486b290cf36Smrg	fi
9487b290cf36Smrg
9488b290cf36Smrg	# Remove version info from name if versioning should be avoided
9489ee3e8c14Smrg	if test yes,no = "$avoid_version,$need_version"; then
9490b290cf36Smrg	  major=
9491b290cf36Smrg	  versuffix=
9492ee3e8c14Smrg	  verstring=
9493b290cf36Smrg	fi
9494b290cf36Smrg
9495b290cf36Smrg	# Check to see if the archive will have undefined symbols.
9496ee3e8c14Smrg	if test yes = "$allow_undefined"; then
9497ee3e8c14Smrg	  if test unsupported = "$allow_undefined_flag"; then
9498ee3e8c14Smrg	    if test yes = "$build_old_libs"; then
9499ee3e8c14Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9500ee3e8c14Smrg	      build_libtool_libs=no
9501ee3e8c14Smrg	    else
9502ee3e8c14Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9503ee3e8c14Smrg	    fi
9504b290cf36Smrg	  fi
9505b290cf36Smrg	else
9506b290cf36Smrg	  # Don't allow undefined symbols.
9507ee3e8c14Smrg	  allow_undefined_flag=$no_undefined_flag
9508b290cf36Smrg	fi
9509b290cf36Smrg
9510b290cf36Smrg      fi
9511b290cf36Smrg
9512ee3e8c14Smrg      func_generate_dlsyms "$libname" "$libname" :
9513d9dcd5aeSmrg      func_append libobjs " $symfileobj"
9514ee3e8c14Smrg      test " " = "$libobjs" && libobjs=
9515b290cf36Smrg
9516ee3e8c14Smrg      if test relink != "$opt_mode"; then
9517b290cf36Smrg	# Remove our outputs, but don't remove object files since they
9518b290cf36Smrg	# may have been created when compiling PIC objects.
9519b290cf36Smrg	removelist=
9520b290cf36Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9521b290cf36Smrg	for p in $tempremovelist; do
9522b290cf36Smrg	  case $p in
9523b290cf36Smrg	    *.$objext | *.gcno)
9524b290cf36Smrg	       ;;
9525ee3e8c14Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9526ee3e8c14Smrg	       if test -n "$precious_files_regex"; then
9527b290cf36Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9528b290cf36Smrg		 then
9529b290cf36Smrg		   continue
9530b290cf36Smrg		 fi
9531b290cf36Smrg	       fi
9532d9dcd5aeSmrg	       func_append removelist " $p"
9533b290cf36Smrg	       ;;
9534b290cf36Smrg	    *) ;;
9535b290cf36Smrg	  esac
9536b290cf36Smrg	done
9537b290cf36Smrg	test -n "$removelist" && \
9538b290cf36Smrg	  func_show_eval "${RM}r \$removelist"
9539b290cf36Smrg      fi
9540b290cf36Smrg
9541b290cf36Smrg      # Now set the variables for building old libraries.
9542ee3e8c14Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9543d9dcd5aeSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9544b290cf36Smrg
9545b290cf36Smrg	# Transform .lo files to .o files.
9546ee3e8c14Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9547b290cf36Smrg      fi
9548b290cf36Smrg
9549b290cf36Smrg      # Eliminate all temporary directories.
9550b290cf36Smrg      #for path in $notinst_path; do
9551ba064abeSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9552ba064abeSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9553ba064abeSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9554b290cf36Smrg      #done
9555b290cf36Smrg
9556b290cf36Smrg      if test -n "$xrpath"; then
9557b290cf36Smrg	# If the user specified any rpath flags, then add them.
9558b290cf36Smrg	temp_xrpath=
9559b290cf36Smrg	for libdir in $xrpath; do
9560d9dcd5aeSmrg	  func_replace_sysroot "$libdir"
9561d9dcd5aeSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9562b290cf36Smrg	  case "$finalize_rpath " in
9563b290cf36Smrg	  *" $libdir "*) ;;
9564d9dcd5aeSmrg	  *) func_append finalize_rpath " $libdir" ;;
9565b290cf36Smrg	  esac
9566b290cf36Smrg	done
9567ee3e8c14Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9568b290cf36Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9569b290cf36Smrg	fi
9570b290cf36Smrg      fi
9571b290cf36Smrg
9572b290cf36Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9573ee3e8c14Smrg      old_dlfiles=$dlfiles
9574b290cf36Smrg      dlfiles=
9575b290cf36Smrg      for lib in $old_dlfiles; do
9576b290cf36Smrg	case " $dlprefiles $dlfiles " in
9577b290cf36Smrg	*" $lib "*) ;;
9578d9dcd5aeSmrg	*) func_append dlfiles " $lib" ;;
9579b290cf36Smrg	esac
9580b290cf36Smrg      done
9581b290cf36Smrg
9582b290cf36Smrg      # Make sure dlprefiles contains only unique files
9583ee3e8c14Smrg      old_dlprefiles=$dlprefiles
9584b290cf36Smrg      dlprefiles=
9585b290cf36Smrg      for lib in $old_dlprefiles; do
9586b290cf36Smrg	case "$dlprefiles " in
9587b290cf36Smrg	*" $lib "*) ;;
9588d9dcd5aeSmrg	*) func_append dlprefiles " $lib" ;;
9589b290cf36Smrg	esac
9590b290cf36Smrg      done
9591b290cf36Smrg
9592ee3e8c14Smrg      if test yes = "$build_libtool_libs"; then
9593b290cf36Smrg	if test -n "$rpath"; then
9594b290cf36Smrg	  case $host in
95958f9fac4aSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9596b290cf36Smrg	    # these systems don't actually have a c library (as such)!
9597b290cf36Smrg	    ;;
9598b290cf36Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9599b290cf36Smrg	    # Rhapsody C library is in the System framework
9600d9dcd5aeSmrg	    func_append deplibs " System.ltframework"
9601b290cf36Smrg	    ;;
9602b290cf36Smrg	  *-*-netbsd*)
9603b290cf36Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9604b290cf36Smrg	    ;;
9605ee3e8c14Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9606b290cf36Smrg	    # Do not include libc due to us having libc/libc_r.
9607b290cf36Smrg	    ;;
9608b290cf36Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9609b290cf36Smrg	    # Causes problems with __ctype
9610b290cf36Smrg	    ;;
9611b290cf36Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9612b290cf36Smrg	    # Compiler inserts libc in the correct place for threads to work
9613b290cf36Smrg	    ;;
9614b290cf36Smrg	  *)
9615b290cf36Smrg	    # Add libc to deplibs on all other systems if necessary.
9616ee3e8c14Smrg	    if test yes = "$build_libtool_need_lc"; then
9617d9dcd5aeSmrg	      func_append deplibs " -lc"
9618b290cf36Smrg	    fi
9619b290cf36Smrg	    ;;
9620b290cf36Smrg	  esac
9621b290cf36Smrg	fi
9622b290cf36Smrg
9623b290cf36Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9624b290cf36Smrg	name_save=$name
9625b290cf36Smrg	libname_save=$libname
9626b290cf36Smrg	release_save=$release
9627b290cf36Smrg	versuffix_save=$versuffix
9628b290cf36Smrg	major_save=$major
9629b290cf36Smrg	# I'm not sure if I'm treating the release correctly.  I think
9630b290cf36Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9631b290cf36Smrg	# add it in twice.  Is that correct?
9632ee3e8c14Smrg	release=
9633ee3e8c14Smrg	versuffix=
9634ee3e8c14Smrg	major=
9635b290cf36Smrg	newdeplibs=
9636b290cf36Smrg	droppeddeps=no
9637b290cf36Smrg	case $deplibs_check_method in
9638b290cf36Smrg	pass_all)
9639b290cf36Smrg	  # Don't check for shared/static.  Everything works.
9640b290cf36Smrg	  # This might be a little naive.  We might want to check
9641b290cf36Smrg	  # whether the library exists or not.  But this is on
9642b290cf36Smrg	  # osf3 & osf4 and I'm not really sure... Just
9643b290cf36Smrg	  # implementing what was already the behavior.
9644b290cf36Smrg	  newdeplibs=$deplibs
9645b290cf36Smrg	  ;;
9646b290cf36Smrg	file_magic*)
9647b290cf36Smrg	  set dummy $deplibs_check_method; shift
9648b290cf36Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9649b290cf36Smrg	  for a_deplib in $deplibs; do
9650b290cf36Smrg	    case $a_deplib in
9651b290cf36Smrg	    -l*)
9652b290cf36Smrg	      func_stripname -l '' "$a_deplib"
9653b290cf36Smrg	      name=$func_stripname_result
9654ee3e8c14Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9655b290cf36Smrg		case " $predeps $postdeps " in
9656b290cf36Smrg		*" $a_deplib "*)
9657d9dcd5aeSmrg		  func_append newdeplibs " $a_deplib"
9658ee3e8c14Smrg		  a_deplib=
9659b290cf36Smrg		  ;;
9660b290cf36Smrg		esac
9661b290cf36Smrg	      fi
9662ee3e8c14Smrg	      if test -n "$a_deplib"; then
9663b290cf36Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9664d9dcd5aeSmrg		if test -n "$file_magic_glob"; then
9665d9dcd5aeSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9666d9dcd5aeSmrg		else
9667d9dcd5aeSmrg		  libnameglob=$libname
9668d9dcd5aeSmrg		fi
9669ee3e8c14Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9670b290cf36Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9671ee3e8c14Smrg		  if test yes = "$want_nocaseglob"; then
9672d9dcd5aeSmrg		    shopt -s nocaseglob
9673d9dcd5aeSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9674d9dcd5aeSmrg		    $nocaseglob
9675d9dcd5aeSmrg		  else
9676d9dcd5aeSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9677d9dcd5aeSmrg		  fi
9678b290cf36Smrg		  for potent_lib in $potential_libs; do
9679b290cf36Smrg		      # Follow soft links.
9680b290cf36Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9681b290cf36Smrg			 $GREP " -> " >/dev/null; then
9682b290cf36Smrg			continue
9683b290cf36Smrg		      fi
9684b290cf36Smrg		      # The statement above tries to avoid entering an
9685b290cf36Smrg		      # endless loop below, in case of cyclic links.
9686b290cf36Smrg		      # We might still enter an endless loop, since a link
9687b290cf36Smrg		      # loop can be closed while we follow links,
9688b290cf36Smrg		      # but so what?
9689ee3e8c14Smrg		      potlib=$potent_lib
9690b290cf36Smrg		      while test -h "$potlib" 2>/dev/null; do
9691ee3e8c14Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9692b290cf36Smrg			case $potliblink in
9693ee3e8c14Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9694ee3e8c14Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9695b290cf36Smrg			esac
9696b290cf36Smrg		      done
9697b290cf36Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9698b290cf36Smrg			 $SED -e 10q |
9699b290cf36Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9700d9dcd5aeSmrg			func_append newdeplibs " $a_deplib"
9701ee3e8c14Smrg			a_deplib=
9702b290cf36Smrg			break 2
9703b290cf36Smrg		      fi
9704b290cf36Smrg		  done
9705b290cf36Smrg		done
9706b290cf36Smrg	      fi
9707ee3e8c14Smrg	      if test -n "$a_deplib"; then
9708b290cf36Smrg		droppeddeps=yes
97098f9fac4aSmrg		func_warning "Linker path does not have real file for library $a_deplib."
97108f9fac4aSmrg		func_warning "I have the capability to make that library automatically link in when"
97118f9fac4aSmrg		func_warning "you link to this library.  But I can only do this if you have a"
97128f9fac4aSmrg		func_warning "shared version of the library, which you do not appear to have"
97138f9fac4aSmrg		func_warning "because I did check the linker path looking for a file starting"
9714ee3e8c14Smrg		if test -z "$potlib"; then
97158f9fac4aSmrg		  func_warning "with $libname but no candidates were found. (...for file magic test)"
9716b290cf36Smrg		else
97178f9fac4aSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
97188f9fac4aSmrg		  func_warning "using a file magic. Last file checked: $potlib"
9719b290cf36Smrg		fi
9720b290cf36Smrg	      fi
9721b290cf36Smrg	      ;;
9722b290cf36Smrg	    *)
9723b290cf36Smrg	      # Add a -L argument.
9724d9dcd5aeSmrg	      func_append newdeplibs " $a_deplib"
9725b290cf36Smrg	      ;;
9726b290cf36Smrg	    esac
9727b290cf36Smrg	  done # Gone through all deplibs.
9728b290cf36Smrg	  ;;
9729b290cf36Smrg	match_pattern*)
9730b290cf36Smrg	  set dummy $deplibs_check_method; shift
9731b290cf36Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9732b290cf36Smrg	  for a_deplib in $deplibs; do
9733b290cf36Smrg	    case $a_deplib in
9734b290cf36Smrg	    -l*)
9735b290cf36Smrg	      func_stripname -l '' "$a_deplib"
9736b290cf36Smrg	      name=$func_stripname_result
9737ee3e8c14Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9738b290cf36Smrg		case " $predeps $postdeps " in
9739b290cf36Smrg		*" $a_deplib "*)
9740d9dcd5aeSmrg		  func_append newdeplibs " $a_deplib"
9741ee3e8c14Smrg		  a_deplib=
9742b290cf36Smrg		  ;;
9743b290cf36Smrg		esac
9744b290cf36Smrg	      fi
9745ee3e8c14Smrg	      if test -n "$a_deplib"; then
9746b290cf36Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9747b290cf36Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9748b290cf36Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9749b290cf36Smrg		  for potent_lib in $potential_libs; do
9750ee3e8c14Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9751ba064abeSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9752b290cf36Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9753d9dcd5aeSmrg		      func_append newdeplibs " $a_deplib"
9754ee3e8c14Smrg		      a_deplib=
9755b290cf36Smrg		      break 2
9756b290cf36Smrg		    fi
9757b290cf36Smrg		  done
9758b290cf36Smrg		done
9759b290cf36Smrg	      fi
9760ee3e8c14Smrg	      if test -n "$a_deplib"; then
9761b290cf36Smrg		droppeddeps=yes
97628f9fac4aSmrg		func_warning "Linker path does not have real file for library $a_deplib."
97638f9fac4aSmrg		func_warning "I have the capability to make that library automatically link in when"
97648f9fac4aSmrg		func_warning "you link to this library.  But I can only do this if you have a"
97658f9fac4aSmrg		func_warning "shared version of the library, which you do not appear to have"
97668f9fac4aSmrg		func_warning "because I did check the linker path looking for a file starting"
9767ee3e8c14Smrg		if test -z "$potlib"; then
97688f9fac4aSmrg		  func_warning "with $libname but no candidates were found. (...for regex pattern test)"
9769b290cf36Smrg		else
97708f9fac4aSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
97718f9fac4aSmrg		  func_warning "using a regex pattern. Last file checked: $potlib"
9772b290cf36Smrg		fi
9773b290cf36Smrg	      fi
9774b290cf36Smrg	      ;;
9775b290cf36Smrg	    *)
9776b290cf36Smrg	      # Add a -L argument.
9777d9dcd5aeSmrg	      func_append newdeplibs " $a_deplib"
9778b290cf36Smrg	      ;;
9779b290cf36Smrg	    esac
9780b290cf36Smrg	  done # Gone through all deplibs.
9781b290cf36Smrg	  ;;
9782b290cf36Smrg	none | unknown | *)
9783ee3e8c14Smrg	  newdeplibs=
9784ba064abeSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9785ee3e8c14Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9786ee3e8c14Smrg	    for i in $predeps $postdeps; do
9787b290cf36Smrg	      # can't use Xsed below, because $i might contain '/'
9788ee3e8c14Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9789b290cf36Smrg	    done
9790b290cf36Smrg	  fi
9791ba064abeSmrg	  case $tmp_deplibs in
9792ba064abeSmrg	  *[!\	\ ]*)
9793ba064abeSmrg	    echo
9794ee3e8c14Smrg	    if test none = "$deplibs_check_method"; then
97958f9fac4aSmrg	      func_warning "Inter-library dependencies are not supported in this platform."
9796b290cf36Smrg	    else
97978f9fac4aSmrg	      func_warning "Inter-library dependencies are not known to be supported."
9798b290cf36Smrg	    fi
97998f9fac4aSmrg	    func_warning "All declared inter-library dependencies are being dropped."
9800b290cf36Smrg	    droppeddeps=yes
9801ba064abeSmrg	    ;;
9802ba064abeSmrg	  esac
9803b290cf36Smrg	  ;;
9804b290cf36Smrg	esac
9805b290cf36Smrg	versuffix=$versuffix_save
9806b290cf36Smrg	major=$major_save
9807b290cf36Smrg	release=$release_save
9808b290cf36Smrg	libname=$libname_save
9809b290cf36Smrg	name=$name_save
9810b290cf36Smrg
9811b290cf36Smrg	case $host in
9812b290cf36Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9813b290cf36Smrg	  # On Rhapsody replace the C library with the System framework
9814ba064abeSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9815b290cf36Smrg	  ;;
9816b290cf36Smrg	esac
9817b290cf36Smrg
9818ee3e8c14Smrg	if test yes = "$droppeddeps"; then
9819ee3e8c14Smrg	  if test yes = "$module"; then
98208f9fac4aSmrg	    func_warning "libtool could not satisfy all declared inter-library"
98218f9fac4aSmrg	    func_warning "dependencies of module $libname.  Therefore, libtool will create"
98228f9fac4aSmrg	    func_warning "a static module, that should work as long as the dlopening"
98238f9fac4aSmrg	    func_warning "application is linked with the -dlopen flag."
9824b290cf36Smrg	    if test -z "$global_symbol_pipe"; then
98258f9fac4aSmrg	      func_warning "However, this would only work if libtool was able to extract symbol"
98268f9fac4aSmrg	      func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
98278f9fac4aSmrg	      func_warning "not find such a program.  So, this module is probably useless."
98288f9fac4aSmrg	      func_warning "'nm' from GNU binutils and a full rebuild may help."
9829b290cf36Smrg	    fi
9830ee3e8c14Smrg	    if test no = "$build_old_libs"; then
9831ee3e8c14Smrg	      oldlibs=$output_objdir/$libname.$libext
9832b290cf36Smrg	      build_libtool_libs=module
9833b290cf36Smrg	      build_old_libs=yes
9834b290cf36Smrg	    else
9835b290cf36Smrg	      build_libtool_libs=no
9836b290cf36Smrg	    fi
9837b290cf36Smrg	  else
9838ba064abeSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9839ba064abeSmrg	    echo "*** automatically added whenever a program is linked with this library"
9840ba064abeSmrg	    echo "*** or is declared to -dlopen it."
9841b290cf36Smrg
9842ee3e8c14Smrg	    if test no = "$allow_undefined"; then
9843ba064abeSmrg	      echo
9844ba064abeSmrg	      echo "*** Since this library must not contain undefined symbols,"
9845ba064abeSmrg	      echo "*** because either the platform does not support them or"
9846ba064abeSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9847ba064abeSmrg	      echo "*** libtool will only create a static version of it."
9848ee3e8c14Smrg	      if test no = "$build_old_libs"; then
9849ee3e8c14Smrg		oldlibs=$output_objdir/$libname.$libext
9850b290cf36Smrg		build_libtool_libs=module
9851b290cf36Smrg		build_old_libs=yes
9852b290cf36Smrg	      else
9853b290cf36Smrg		build_libtool_libs=no
9854b290cf36Smrg	      fi
9855b290cf36Smrg	    fi
9856b290cf36Smrg	  fi
9857b290cf36Smrg	fi
9858b290cf36Smrg	# Done checking deplibs!
9859b290cf36Smrg	deplibs=$newdeplibs
9860b290cf36Smrg      fi
9861b290cf36Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9862b290cf36Smrg      case $host in
9863b290cf36Smrg	*-*-darwin*)
9864ba064abeSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9865ba064abeSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9866ba064abeSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9867b290cf36Smrg	  ;;
9868b290cf36Smrg      esac
9869b290cf36Smrg
9870b290cf36Smrg      # move library search paths that coincide with paths to not yet
9871b290cf36Smrg      # installed libraries to the beginning of the library search list
9872b290cf36Smrg      new_libs=
9873b290cf36Smrg      for path in $notinst_path; do
9874b290cf36Smrg	case " $new_libs " in
9875b290cf36Smrg	*" -L$path/$objdir "*) ;;
9876b290cf36Smrg	*)
9877b290cf36Smrg	  case " $deplibs " in
9878b290cf36Smrg	  *" -L$path/$objdir "*)
9879d9dcd5aeSmrg	    func_append new_libs " -L$path/$objdir" ;;
9880b290cf36Smrg	  esac
9881b290cf36Smrg	  ;;
9882b290cf36Smrg	esac
9883b290cf36Smrg      done
9884b290cf36Smrg      for deplib in $deplibs; do
9885b290cf36Smrg	case $deplib in
9886b290cf36Smrg	-L*)
9887b290cf36Smrg	  case " $new_libs " in
9888b290cf36Smrg	  *" $deplib "*) ;;
9889d9dcd5aeSmrg	  *) func_append new_libs " $deplib" ;;
9890b290cf36Smrg	  esac
9891b290cf36Smrg	  ;;
9892d9dcd5aeSmrg	*) func_append new_libs " $deplib" ;;
9893b290cf36Smrg	esac
9894b290cf36Smrg      done
9895ee3e8c14Smrg      deplibs=$new_libs
9896b290cf36Smrg
9897b290cf36Smrg      # All the library-specific variables (install_libdir is set above).
9898b290cf36Smrg      library_names=
9899b290cf36Smrg      old_library=
9900b290cf36Smrg      dlname=
9901b290cf36Smrg
9902b290cf36Smrg      # Test again, we may have decided not to build it any more
9903ee3e8c14Smrg      if test yes = "$build_libtool_libs"; then
9904ee3e8c14Smrg	# Remove $wl instances when linking with ld.
9905d9dcd5aeSmrg	# FIXME: should test the right _cmds variable.
9906d9dcd5aeSmrg	case $archive_cmds in
9907d9dcd5aeSmrg	  *\$LD\ *) wl= ;;
9908d9dcd5aeSmrg        esac
9909ee3e8c14Smrg	if test yes = "$hardcode_into_libs"; then
9910b290cf36Smrg	  # Hardcode the library paths
9911b290cf36Smrg	  hardcode_libdirs=
9912b290cf36Smrg	  dep_rpath=
9913ee3e8c14Smrg	  rpath=$finalize_rpath
9914ee3e8c14Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9915b290cf36Smrg	  for libdir in $rpath; do
9916b290cf36Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9917b290cf36Smrg	      if test -n "$hardcode_libdir_separator"; then
9918d9dcd5aeSmrg		func_replace_sysroot "$libdir"
9919d9dcd5aeSmrg		libdir=$func_replace_sysroot_result
9920b290cf36Smrg		if test -z "$hardcode_libdirs"; then
9921ee3e8c14Smrg		  hardcode_libdirs=$libdir
9922b290cf36Smrg		else
9923b290cf36Smrg		  # Just accumulate the unique libdirs.
9924b290cf36Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9925b290cf36Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9926b290cf36Smrg		    ;;
9927b290cf36Smrg		  *)
9928d9dcd5aeSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9929b290cf36Smrg		    ;;
9930b290cf36Smrg		  esac
9931b290cf36Smrg		fi
9932b290cf36Smrg	      else
9933b290cf36Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9934d9dcd5aeSmrg		func_append dep_rpath " $flag"
9935b290cf36Smrg	      fi
9936b290cf36Smrg	    elif test -n "$runpath_var"; then
9937b290cf36Smrg	      case "$perm_rpath " in
9938b290cf36Smrg	      *" $libdir "*) ;;
9939d9dcd5aeSmrg	      *) func_append perm_rpath " $libdir" ;;
9940b290cf36Smrg	      esac
9941b290cf36Smrg	    fi
9942b290cf36Smrg	  done
9943b290cf36Smrg	  # Substitute the hardcoded libdirs into the rpath.
9944b290cf36Smrg	  if test -n "$hardcode_libdir_separator" &&
9945b290cf36Smrg	     test -n "$hardcode_libdirs"; then
9946ee3e8c14Smrg	    libdir=$hardcode_libdirs
9947d9dcd5aeSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9948b290cf36Smrg	  fi
9949b290cf36Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9950b290cf36Smrg	    # We should set the runpath_var.
9951b290cf36Smrg	    rpath=
9952b290cf36Smrg	    for dir in $perm_rpath; do
9953d9dcd5aeSmrg	      func_append rpath "$dir:"
9954b290cf36Smrg	    done
9955b290cf36Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9956b290cf36Smrg	  fi
9957b290cf36Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9958b290cf36Smrg	fi
9959191cded7Smrg
9960ee3e8c14Smrg	shlibpath=$finalize_shlibpath
9961ee3e8c14Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9962b290cf36Smrg	if test -n "$shlibpath"; then
9963b290cf36Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9964b290cf36Smrg	fi
9965191cded7Smrg
9966b290cf36Smrg	# Get the real and link names of the library.
9967b290cf36Smrg	eval shared_ext=\"$shrext_cmds\"
9968b290cf36Smrg	eval library_names=\"$library_names_spec\"
9969b290cf36Smrg	set dummy $library_names
9970b290cf36Smrg	shift
9971ee3e8c14Smrg	realname=$1
9972b290cf36Smrg	shift
9973191cded7Smrg
9974b290cf36Smrg	if test -n "$soname_spec"; then
9975b290cf36Smrg	  eval soname=\"$soname_spec\"
9976b290cf36Smrg	else
9977ee3e8c14Smrg	  soname=$realname
9978b290cf36Smrg	fi
9979b290cf36Smrg	if test -z "$dlname"; then
9980b290cf36Smrg	  dlname=$soname
9981b290cf36Smrg	fi
9982191cded7Smrg
9983ee3e8c14Smrg	lib=$output_objdir/$realname
9984b290cf36Smrg	linknames=
9985b290cf36Smrg	for link
9986b290cf36Smrg	do
9987d9dcd5aeSmrg	  func_append linknames " $link"
9988b290cf36Smrg	done
9989191cded7Smrg
9990b290cf36Smrg	# Use standard objects if they are pic
9991ba064abeSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9992b290cf36Smrg	test "X$libobjs" = "X " && libobjs=
9993191cded7Smrg
9994b290cf36Smrg	delfiles=
9995b290cf36Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9996b290cf36Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9997ee3e8c14Smrg	  export_symbols=$output_objdir/$libname.uexp
9998d9dcd5aeSmrg	  func_append delfiles " $export_symbols"
9999b290cf36Smrg	fi
10000191cded7Smrg
10001b290cf36Smrg	orig_export_symbols=
10002b290cf36Smrg	case $host_os in
100038f9fac4aSmrg	cygwin* | mingw* | windows* | cegcc*)
10004b290cf36Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
10005b290cf36Smrg	    # exporting using user supplied symfile
10006ee3e8c14Smrg	    func_dll_def_p "$export_symbols" || {
10007b290cf36Smrg	      # and it's NOT already a .def file. Must figure out
10008b290cf36Smrg	      # which of the given symbols are data symbols and tag
10009b290cf36Smrg	      # them as such. So, trigger use of export_symbols_cmds.
10010b290cf36Smrg	      # export_symbols gets reassigned inside the "prepare
10011b290cf36Smrg	      # the list of exported symbols" if statement, so the
10012b290cf36Smrg	      # include_expsyms logic still works.
10013ee3e8c14Smrg	      orig_export_symbols=$export_symbols
10014b290cf36Smrg	      export_symbols=
10015b290cf36Smrg	      always_export_symbols=yes
10016ee3e8c14Smrg	    }
10017b290cf36Smrg	  fi
10018b290cf36Smrg	  ;;
10019b290cf36Smrg	esac
10020191cded7Smrg
10021b290cf36Smrg	# Prepare the list of exported symbols
10022b290cf36Smrg	if test -z "$export_symbols"; then
10023ee3e8c14Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
10024ee3e8c14Smrg	    func_verbose "generating symbol list for '$libname.la'"
10025ee3e8c14Smrg	    export_symbols=$output_objdir/$libname.exp
10026b290cf36Smrg	    $opt_dry_run || $RM $export_symbols
10027b290cf36Smrg	    cmds=$export_symbols_cmds
10028ee3e8c14Smrg	    save_ifs=$IFS; IFS='~'
10029d9dcd5aeSmrg	    for cmd1 in $cmds; do
10030ee3e8c14Smrg	      IFS=$save_ifs
10031d9dcd5aeSmrg	      # Take the normal branch if the nm_file_list_spec branch
10032d9dcd5aeSmrg	      # doesn't work or if tool conversion is not needed.
10033d9dcd5aeSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
10034d9dcd5aeSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
10035d9dcd5aeSmrg		  try_normal_branch=yes
10036d9dcd5aeSmrg		  eval cmd=\"$cmd1\"
10037d9dcd5aeSmrg		  func_len " $cmd"
10038d9dcd5aeSmrg		  len=$func_len_result
10039d9dcd5aeSmrg		  ;;
10040d9dcd5aeSmrg		*)
10041d9dcd5aeSmrg		  try_normal_branch=no
10042d9dcd5aeSmrg		  ;;
10043d9dcd5aeSmrg	      esac
10044ee3e8c14Smrg	      if test yes = "$try_normal_branch" \
10045d9dcd5aeSmrg		 && { test "$len" -lt "$max_cmd_len" \
10046d9dcd5aeSmrg		      || test "$max_cmd_len" -le -1; }
10047d9dcd5aeSmrg	      then
10048d9dcd5aeSmrg		func_show_eval "$cmd" 'exit $?'
10049d9dcd5aeSmrg		skipped_export=false
10050d9dcd5aeSmrg	      elif test -n "$nm_file_list_spec"; then
10051d9dcd5aeSmrg		func_basename "$output"
10052d9dcd5aeSmrg		output_la=$func_basename_result
10053d9dcd5aeSmrg		save_libobjs=$libobjs
10054d9dcd5aeSmrg		save_output=$output
10055ee3e8c14Smrg		output=$output_objdir/$output_la.nm
10056d9dcd5aeSmrg		func_to_tool_file "$output"
10057d9dcd5aeSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
10058d9dcd5aeSmrg		func_append delfiles " $output"
10059d9dcd5aeSmrg		func_verbose "creating $NM input file list: $output"
10060d9dcd5aeSmrg		for obj in $save_libobjs; do
10061d9dcd5aeSmrg		  func_to_tool_file "$obj"
10062d9dcd5aeSmrg		  $ECHO "$func_to_tool_file_result"
10063d9dcd5aeSmrg		done > "$output"
10064d9dcd5aeSmrg		eval cmd=\"$cmd1\"
10065b290cf36Smrg		func_show_eval "$cmd" 'exit $?'
10066d9dcd5aeSmrg		output=$save_output
10067d9dcd5aeSmrg		libobjs=$save_libobjs
10068b290cf36Smrg		skipped_export=false
10069b290cf36Smrg	      else
10070b290cf36Smrg		# The command line is too long to execute in one step.
10071b290cf36Smrg		func_verbose "using reloadable object file for export list..."
10072b290cf36Smrg		skipped_export=:
10073b290cf36Smrg		# Break out early, otherwise skipped_export may be
10074b290cf36Smrg		# set to false by a later but shorter cmd.
10075b290cf36Smrg		break
10076b290cf36Smrg	      fi
10077b290cf36Smrg	    done
10078ee3e8c14Smrg	    IFS=$save_ifs
10079ee3e8c14Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
10080b290cf36Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10081b290cf36Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10082b290cf36Smrg	    fi
10083b290cf36Smrg	  fi
10084b290cf36Smrg	fi
10085191cded7Smrg
10086b290cf36Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
10087ee3e8c14Smrg	  tmp_export_symbols=$export_symbols
10088ee3e8c14Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10089ba064abeSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10090b290cf36Smrg	fi
10091191cded7Smrg
10092ee3e8c14Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10093b290cf36Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10094ee3e8c14Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10095b290cf36Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10096ee3e8c14Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10097b290cf36Smrg	  # though. Also, the filter scales superlinearly with the number of
10098b290cf36Smrg	  # global variables. join(1) would be nice here, but unfortunately
10099b290cf36Smrg	  # isn't a blessed tool.
10100b290cf36Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10101d9dcd5aeSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10102b290cf36Smrg	  export_symbols=$output_objdir/$libname.def
10103b290cf36Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10104191cded7Smrg	fi
10105191cded7Smrg
10106b290cf36Smrg	tmp_deplibs=
10107b290cf36Smrg	for test_deplib in $deplibs; do
10108b290cf36Smrg	  case " $convenience " in
10109b290cf36Smrg	  *" $test_deplib "*) ;;
10110b290cf36Smrg	  *)
10111d9dcd5aeSmrg	    func_append tmp_deplibs " $test_deplib"
10112b290cf36Smrg	    ;;
10113b290cf36Smrg	  esac
10114b290cf36Smrg	done
10115ee3e8c14Smrg	deplibs=$tmp_deplibs
10116191cded7Smrg
10117b290cf36Smrg	if test -n "$convenience"; then
10118b290cf36Smrg	  if test -n "$whole_archive_flag_spec" &&
10119ee3e8c14Smrg	    test yes = "$compiler_needs_object" &&
10120b290cf36Smrg	    test -z "$libobjs"; then
10121b290cf36Smrg	    # extract the archives, so we have objects to list.
10122b290cf36Smrg	    # TODO: could optimize this to just extract one archive.
10123b290cf36Smrg	    whole_archive_flag_spec=
10124b290cf36Smrg	  fi
10125b290cf36Smrg	  if test -n "$whole_archive_flag_spec"; then
10126b290cf36Smrg	    save_libobjs=$libobjs
10127b290cf36Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10128b290cf36Smrg	    test "X$libobjs" = "X " && libobjs=
10129b290cf36Smrg	  else
10130ee3e8c14Smrg	    gentop=$output_objdir/${outputname}x
10131d9dcd5aeSmrg	    func_append generated " $gentop"
10132191cded7Smrg
10133b290cf36Smrg	    func_extract_archives $gentop $convenience
10134d9dcd5aeSmrg	    func_append libobjs " $func_extract_archives_result"
10135b290cf36Smrg	    test "X$libobjs" = "X " && libobjs=
10136b290cf36Smrg	  fi
10137b290cf36Smrg	fi
10138191cded7Smrg
10139ee3e8c14Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10140b290cf36Smrg	  eval flag=\"$thread_safe_flag_spec\"
10141d9dcd5aeSmrg	  func_append linker_flags " $flag"
10142b290cf36Smrg	fi
10143191cded7Smrg
10144b290cf36Smrg	# Make a backup of the uninstalled library when relinking
10145ee3e8c14Smrg	if test relink = "$opt_mode"; then
10146b290cf36Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10147191cded7Smrg	fi
10148191cded7Smrg
10149b290cf36Smrg	# Do each of the archive commands.
10150ee3e8c14Smrg	if test yes = "$module" && test -n "$module_cmds"; then
10151b290cf36Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10152b290cf36Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10153b290cf36Smrg	    cmds=$module_expsym_cmds
10154b290cf36Smrg	  else
10155b290cf36Smrg	    eval test_cmds=\"$module_cmds\"
10156b290cf36Smrg	    cmds=$module_cmds
10157b290cf36Smrg	  fi
10158b290cf36Smrg	else
10159b290cf36Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10160b290cf36Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10161b290cf36Smrg	    cmds=$archive_expsym_cmds
10162b290cf36Smrg	  else
10163b290cf36Smrg	    eval test_cmds=\"$archive_cmds\"
10164b290cf36Smrg	    cmds=$archive_cmds
10165b290cf36Smrg	  fi
10166191cded7Smrg	fi
10167191cded7Smrg
10168ee3e8c14Smrg	if test : != "$skipped_export" &&
10169b290cf36Smrg	   func_len " $test_cmds" &&
10170b290cf36Smrg	   len=$func_len_result &&
10171b290cf36Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10172b290cf36Smrg	  :
10173b290cf36Smrg	else
10174b290cf36Smrg	  # The command line is too long to link in one step, link piecewise
10175b290cf36Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10176b290cf36Smrg	  # script.
10177191cded7Smrg
10178b290cf36Smrg	  # Save the value of $output and $libobjs because we want to
10179b290cf36Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10180b290cf36Smrg	  # want to use save_libobjs as it was before
10181b290cf36Smrg	  # whole_archive_flag_spec was expanded, because we can't
10182b290cf36Smrg	  # assume the linker understands whole_archive_flag_spec.
10183b290cf36Smrg	  # This may have to be revisited, in case too many
10184b290cf36Smrg	  # convenience libraries get linked in and end up exceeding
10185b290cf36Smrg	  # the spec.
10186b290cf36Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10187b290cf36Smrg	    save_libobjs=$libobjs
10188b290cf36Smrg	  fi
10189b290cf36Smrg	  save_output=$output
10190ba064abeSmrg	  func_basename "$output"
10191ba064abeSmrg	  output_la=$func_basename_result
10192191cded7Smrg
10193b290cf36Smrg	  # Clear the reloadable object creation command queue and
10194b290cf36Smrg	  # initialize k to one.
10195b290cf36Smrg	  test_cmds=
10196b290cf36Smrg	  concat_cmds=
10197b290cf36Smrg	  objlist=
10198b290cf36Smrg	  last_robj=
10199b290cf36Smrg	  k=1
10200191cded7Smrg
102018f9fac4aSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10202ee3e8c14Smrg	    output=$output_objdir/$output_la.lnk
10203b290cf36Smrg	    func_verbose "creating linker input file list: $output"
10204b290cf36Smrg	    : > $output
10205b290cf36Smrg	    set x $save_libobjs
10206b290cf36Smrg	    shift
10207b290cf36Smrg	    firstobj=
10208ee3e8c14Smrg	    if test yes = "$compiler_needs_object"; then
10209b290cf36Smrg	      firstobj="$1 "
10210b290cf36Smrg	      shift
10211b290cf36Smrg	    fi
10212b290cf36Smrg	    for obj
10213b290cf36Smrg	    do
10214d9dcd5aeSmrg	      func_to_tool_file "$obj"
10215d9dcd5aeSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10216b290cf36Smrg	    done
10217d9dcd5aeSmrg	    func_append delfiles " $output"
10218d9dcd5aeSmrg	    func_to_tool_file "$output"
10219d9dcd5aeSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
102208f9fac4aSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
102218f9fac4aSmrg	    output=$output_objdir/$output_la.lnkscript
102228f9fac4aSmrg	    func_verbose "creating GNU ld script: $output"
102238f9fac4aSmrg	    echo 'INPUT (' > $output
102248f9fac4aSmrg	    for obj in $save_libobjs
102258f9fac4aSmrg	    do
102268f9fac4aSmrg	      func_to_tool_file "$obj"
102278f9fac4aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
102288f9fac4aSmrg	    done
102298f9fac4aSmrg	    echo ')' >> $output
102308f9fac4aSmrg	    func_append delfiles " $output"
102318f9fac4aSmrg	    func_to_tool_file "$output"
102328f9fac4aSmrg	    output=$func_to_tool_file_result
10233b290cf36Smrg	  else
10234b290cf36Smrg	    if test -n "$save_libobjs"; then
10235b290cf36Smrg	      func_verbose "creating reloadable object files..."
10236ee3e8c14Smrg	      output=$output_objdir/$output_la-$k.$objext
10237b290cf36Smrg	      eval test_cmds=\"$reload_cmds\"
10238b290cf36Smrg	      func_len " $test_cmds"
10239b290cf36Smrg	      len0=$func_len_result
10240b290cf36Smrg	      len=$len0
10241b290cf36Smrg
10242b290cf36Smrg	      # Loop over the list of objects to be linked.
10243b290cf36Smrg	      for obj in $save_libobjs
10244b290cf36Smrg	      do
10245b290cf36Smrg		func_len " $obj"
10246b290cf36Smrg		func_arith $len + $func_len_result
10247b290cf36Smrg		len=$func_arith_result
10248ee3e8c14Smrg		if test -z "$objlist" ||
10249b290cf36Smrg		   test "$len" -lt "$max_cmd_len"; then
10250b290cf36Smrg		  func_append objlist " $obj"
10251b290cf36Smrg		else
10252b290cf36Smrg		  # The command $test_cmds is almost too long, add a
10253b290cf36Smrg		  # command to the queue.
10254ee3e8c14Smrg		  if test 1 -eq "$k"; then
10255b290cf36Smrg		    # The first file doesn't have a previous command to add.
10256ba064abeSmrg		    reload_objs=$objlist
10257ba064abeSmrg		    eval concat_cmds=\"$reload_cmds\"
10258b290cf36Smrg		  else
10259b290cf36Smrg		    # All subsequent reloadable object files will link in
10260b290cf36Smrg		    # the last one created.
10261ba064abeSmrg		    reload_objs="$objlist $last_robj"
10262ba064abeSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10263b290cf36Smrg		  fi
10264ee3e8c14Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
10265b290cf36Smrg		  func_arith $k + 1
10266b290cf36Smrg		  k=$func_arith_result
10267ee3e8c14Smrg		  output=$output_objdir/$output_la-$k.$objext
10268ba064abeSmrg		  objlist=" $obj"
10269b290cf36Smrg		  func_len " $last_robj"
10270b290cf36Smrg		  func_arith $len0 + $func_len_result
10271b290cf36Smrg		  len=$func_arith_result
10272b290cf36Smrg		fi
10273b290cf36Smrg	      done
10274b290cf36Smrg	      # Handle the remaining objects by creating one last
10275b290cf36Smrg	      # reloadable object file.  All subsequent reloadable object
10276b290cf36Smrg	      # files will link in the last one created.
10277b290cf36Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10278ba064abeSmrg	      reload_objs="$objlist $last_robj"
10279ee3e8c14Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10280b290cf36Smrg	      if test -n "$last_robj"; then
10281ee3e8c14Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10282b290cf36Smrg	      fi
10283d9dcd5aeSmrg	      func_append delfiles " $output"
10284191cded7Smrg
10285b290cf36Smrg	    else
10286b290cf36Smrg	      output=
10287b290cf36Smrg	    fi
10288191cded7Smrg
10289ee3e8c14Smrg	    ${skipped_export-false} && {
10290ee3e8c14Smrg	      func_verbose "generating symbol list for '$libname.la'"
10291ee3e8c14Smrg	      export_symbols=$output_objdir/$libname.exp
10292b290cf36Smrg	      $opt_dry_run || $RM $export_symbols
10293b290cf36Smrg	      libobjs=$output
10294b290cf36Smrg	      # Append the command to create the export file.
10295b290cf36Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10296b290cf36Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10297b290cf36Smrg	      if test -n "$last_robj"; then
10298b290cf36Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10299b290cf36Smrg	      fi
10300ee3e8c14Smrg	    }
10301191cded7Smrg
10302b290cf36Smrg	    test -n "$save_libobjs" &&
10303b290cf36Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10304191cded7Smrg
10305b290cf36Smrg	    # Loop through the commands generated above and execute them.
10306ee3e8c14Smrg	    save_ifs=$IFS; IFS='~'
10307b290cf36Smrg	    for cmd in $concat_cmds; do
10308ee3e8c14Smrg	      IFS=$save_ifs
10309ee3e8c14Smrg	      $opt_quiet || {
10310ee3e8c14Smrg		  func_quote_arg expand,pretty "$cmd"
10311ee3e8c14Smrg		  eval "func_echo $func_quote_arg_result"
10312b290cf36Smrg	      }
10313b290cf36Smrg	      $opt_dry_run || eval "$cmd" || {
10314b290cf36Smrg		lt_exit=$?
10315b290cf36Smrg
10316b290cf36Smrg		# Restore the uninstalled library and exit
10317ee3e8c14Smrg		if test relink = "$opt_mode"; then
10318b290cf36Smrg		  ( cd "$output_objdir" && \
10319b290cf36Smrg		    $RM "${realname}T" && \
10320b290cf36Smrg		    $MV "${realname}U" "$realname" )
10321b290cf36Smrg		fi
10322191cded7Smrg
10323b290cf36Smrg		exit $lt_exit
10324b290cf36Smrg	      }
10325b290cf36Smrg	    done
10326ee3e8c14Smrg	    IFS=$save_ifs
10327b290cf36Smrg
10328b290cf36Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10329b290cf36Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10330b290cf36Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10331191cded7Smrg	    fi
10332191cded7Smrg	  fi
10333191cded7Smrg
10334ee3e8c14Smrg          ${skipped_export-false} && {
10335b290cf36Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10336ee3e8c14Smrg	      tmp_export_symbols=$export_symbols
10337ee3e8c14Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10338ba064abeSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10339b290cf36Smrg	    fi
10340191cded7Smrg
10341b290cf36Smrg	    if test -n "$orig_export_symbols"; then
10342b290cf36Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10343ee3e8c14Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10344b290cf36Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10345ee3e8c14Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10346b290cf36Smrg	      # though. Also, the filter scales superlinearly with the number of
10347b290cf36Smrg	      # global variables. join(1) would be nice here, but unfortunately
10348b290cf36Smrg	      # isn't a blessed tool.
10349b290cf36Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10350d9dcd5aeSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10351b290cf36Smrg	      export_symbols=$output_objdir/$libname.def
10352b290cf36Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10353b290cf36Smrg	    fi
10354ee3e8c14Smrg	  }
10355191cded7Smrg
10356b290cf36Smrg	  libobjs=$output
10357b290cf36Smrg	  # Restore the value of output.
10358b290cf36Smrg	  output=$save_output
10359191cded7Smrg
10360b290cf36Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10361b290cf36Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10362b290cf36Smrg	    test "X$libobjs" = "X " && libobjs=
10363b290cf36Smrg	  fi
10364b290cf36Smrg	  # Expand the library linking commands again to reset the
10365b290cf36Smrg	  # value of $libobjs for piecewise linking.
10366b290cf36Smrg
10367b290cf36Smrg	  # Do each of the archive commands.
10368ee3e8c14Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
10369b290cf36Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10370b290cf36Smrg	      cmds=$module_expsym_cmds
10371191cded7Smrg	    else
10372b290cf36Smrg	      cmds=$module_cmds
10373191cded7Smrg	    fi
10374191cded7Smrg	  else
10375b290cf36Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10376b290cf36Smrg	      cmds=$archive_expsym_cmds
10377b290cf36Smrg	    else
10378b290cf36Smrg	      cmds=$archive_cmds
10379b290cf36Smrg	    fi
10380191cded7Smrg	  fi
10381191cded7Smrg	fi
10382191cded7Smrg
10383b290cf36Smrg	if test -n "$delfiles"; then
10384b290cf36Smrg	  # Append the command to remove temporary files to $cmds.
10385b290cf36Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10386b290cf36Smrg	fi
10387191cded7Smrg
10388b290cf36Smrg	# Add any objects from preloaded convenience libraries
10389b290cf36Smrg	if test -n "$dlprefiles"; then
10390ee3e8c14Smrg	  gentop=$output_objdir/${outputname}x
10391d9dcd5aeSmrg	  func_append generated " $gentop"
10392191cded7Smrg
10393b290cf36Smrg	  func_extract_archives $gentop $dlprefiles
10394d9dcd5aeSmrg	  func_append libobjs " $func_extract_archives_result"
10395b290cf36Smrg	  test "X$libobjs" = "X " && libobjs=
10396191cded7Smrg	fi
10397191cded7Smrg
10398ee3e8c14Smrg	save_ifs=$IFS; IFS='~'
10399b290cf36Smrg	for cmd in $cmds; do
10400ee3e8c14Smrg	  IFS=$sp$nl
10401b290cf36Smrg	  eval cmd=\"$cmd\"
10402ee3e8c14Smrg	  IFS=$save_ifs
10403ee3e8c14Smrg	  $opt_quiet || {
10404ee3e8c14Smrg	    func_quote_arg expand,pretty "$cmd"
10405ee3e8c14Smrg	    eval "func_echo $func_quote_arg_result"
10406b290cf36Smrg	  }
10407b290cf36Smrg	  $opt_dry_run || eval "$cmd" || {
10408b290cf36Smrg	    lt_exit=$?
10409191cded7Smrg
10410b290cf36Smrg	    # Restore the uninstalled library and exit
10411ee3e8c14Smrg	    if test relink = "$opt_mode"; then
10412b290cf36Smrg	      ( cd "$output_objdir" && \
10413b290cf36Smrg	        $RM "${realname}T" && \
10414b290cf36Smrg		$MV "${realname}U" "$realname" )
10415b290cf36Smrg	    fi
10416b290cf36Smrg
10417b290cf36Smrg	    exit $lt_exit
10418b290cf36Smrg	  }
10419b290cf36Smrg	done
10420ee3e8c14Smrg	IFS=$save_ifs
10421b290cf36Smrg
10422b290cf36Smrg	# Restore the uninstalled library and exit
10423ee3e8c14Smrg	if test relink = "$opt_mode"; then
10424b290cf36Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10425b290cf36Smrg
10426b290cf36Smrg	  if test -n "$convenience"; then
10427b290cf36Smrg	    if test -z "$whole_archive_flag_spec"; then
10428b290cf36Smrg	      func_show_eval '${RM}r "$gentop"'
10429191cded7Smrg	    fi
10430191cded7Smrg	  fi
10431191cded7Smrg
10432b290cf36Smrg	  exit $EXIT_SUCCESS
10433b290cf36Smrg	fi
10434191cded7Smrg
10435b290cf36Smrg	# Create links to the real library.
10436b290cf36Smrg	for linkname in $linknames; do
10437b290cf36Smrg	  if test "$realname" != "$linkname"; then
10438b290cf36Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10439b290cf36Smrg	  fi
10440b290cf36Smrg	done
10441b290cf36Smrg
10442b290cf36Smrg	# If -module or -export-dynamic was specified, set the dlname.
10443ee3e8c14Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10444b290cf36Smrg	  # On all known operating systems, these are identical.
10445ee3e8c14Smrg	  dlname=$soname
10446b290cf36Smrg	fi
10447b290cf36Smrg      fi
10448b290cf36Smrg      ;;
10449b290cf36Smrg
10450b290cf36Smrg    obj)
10451ee3e8c14Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10452ee3e8c14Smrg	func_warning "'-dlopen' is ignored for objects"
10453b290cf36Smrg      fi
10454b290cf36Smrg
10455b290cf36Smrg      case " $deplibs" in
10456b290cf36Smrg      *\ -l* | *\ -L*)
10457ee3e8c14Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10458b290cf36Smrg      esac
10459b290cf36Smrg
10460b290cf36Smrg      test -n "$rpath" && \
10461ee3e8c14Smrg	func_warning "'-rpath' is ignored for objects"
10462b290cf36Smrg
10463b290cf36Smrg      test -n "$xrpath" && \
10464ee3e8c14Smrg	func_warning "'-R' is ignored for objects"
10465b290cf36Smrg
10466b290cf36Smrg      test -n "$vinfo" && \
10467ee3e8c14Smrg	func_warning "'-version-info' is ignored for objects"
10468b290cf36Smrg
10469b290cf36Smrg      test -n "$release" && \
10470ee3e8c14Smrg	func_warning "'-release' is ignored for objects"
10471b290cf36Smrg
10472b290cf36Smrg      case $output in
10473b290cf36Smrg      *.lo)
10474b290cf36Smrg	test -n "$objs$old_deplibs" && \
10475ee3e8c14Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10476b290cf36Smrg
10477b290cf36Smrg	libobj=$output
10478b290cf36Smrg	func_lo2o "$libobj"
10479b290cf36Smrg	obj=$func_lo2o_result
10480b290cf36Smrg	;;
10481b290cf36Smrg      *)
10482b290cf36Smrg	libobj=
10483ee3e8c14Smrg	obj=$output
10484b290cf36Smrg	;;
10485b290cf36Smrg      esac
10486b290cf36Smrg
10487b290cf36Smrg      # Delete the old objects.
10488b290cf36Smrg      $opt_dry_run || $RM $obj $libobj
10489b290cf36Smrg
10490b290cf36Smrg      # Objects from convenience libraries.  This assumes
10491b290cf36Smrg      # single-version convenience libraries.  Whenever we create
10492b290cf36Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10493b290cf36Smrg      # the extraction.
10494b290cf36Smrg      reload_conv_objs=
10495b290cf36Smrg      gentop=
10496ee3e8c14Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10497ee3e8c14Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10498ee3e8c14Smrg      # into space.
10499ee3e8c14Smrg      case $reload_cmds in
10500ee3e8c14Smrg        *\$LD[\ \$]*) wl= ;;
10501ee3e8c14Smrg      esac
10502b290cf36Smrg      if test -n "$convenience"; then
10503b290cf36Smrg	if test -n "$whole_archive_flag_spec"; then
10504b290cf36Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10505ee3e8c14Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10506ee3e8c14Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10507b290cf36Smrg	else
10508ee3e8c14Smrg	  gentop=$output_objdir/${obj}x
10509d9dcd5aeSmrg	  func_append generated " $gentop"
10510b290cf36Smrg
10511b290cf36Smrg	  func_extract_archives $gentop $convenience
10512b290cf36Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10513b290cf36Smrg	fi
10514b290cf36Smrg      fi
10515191cded7Smrg
10516d9dcd5aeSmrg      # If we're not building shared, we need to use non_pic_objs
10517ee3e8c14Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10518d9dcd5aeSmrg
10519b290cf36Smrg      # Create the old-style object.
10520ee3e8c14Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10521191cded7Smrg
10522ee3e8c14Smrg      output=$obj
10523b290cf36Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10524191cded7Smrg
10525b290cf36Smrg      # Exit if we aren't doing a library object file.
10526b290cf36Smrg      if test -z "$libobj"; then
10527b290cf36Smrg	if test -n "$gentop"; then
10528b290cf36Smrg	  func_show_eval '${RM}r "$gentop"'
10529b290cf36Smrg	fi
10530191cded7Smrg
10531b290cf36Smrg	exit $EXIT_SUCCESS
10532b290cf36Smrg      fi
10533191cded7Smrg
10534ee3e8c14Smrg      test yes = "$build_libtool_libs" || {
10535b290cf36Smrg	if test -n "$gentop"; then
10536b290cf36Smrg	  func_show_eval '${RM}r "$gentop"'
10537b290cf36Smrg	fi
10538191cded7Smrg
10539b290cf36Smrg	# Create an invalid libtool object if no PIC, so that we don't
10540b290cf36Smrg	# accidentally link it into a program.
10541b290cf36Smrg	# $show "echo timestamp > $libobj"
10542b290cf36Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10543b290cf36Smrg	exit $EXIT_SUCCESS
10544ee3e8c14Smrg      }
10545191cded7Smrg
10546ee3e8c14Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10547b290cf36Smrg	# Only do commands if we really have different PIC objects.
10548b290cf36Smrg	reload_objs="$libobjs $reload_conv_objs"
10549ee3e8c14Smrg	output=$libobj
10550b290cf36Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10551191cded7Smrg      fi
10552191cded7Smrg
10553b290cf36Smrg      if test -n "$gentop"; then
10554b290cf36Smrg	func_show_eval '${RM}r "$gentop"'
10555b290cf36Smrg      fi
10556191cded7Smrg
10557b290cf36Smrg      exit $EXIT_SUCCESS
10558b290cf36Smrg      ;;
10559191cded7Smrg
10560b290cf36Smrg    prog)
10561b290cf36Smrg      case $host in
10562b290cf36Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10563b290cf36Smrg	          output=$func_stripname_result.exe;;
10564191cded7Smrg      esac
10565b290cf36Smrg      test -n "$vinfo" && \
10566ee3e8c14Smrg	func_warning "'-version-info' is ignored for programs"
10567191cded7Smrg
10568b290cf36Smrg      test -n "$release" && \
10569ee3e8c14Smrg	func_warning "'-release' is ignored for programs"
10570191cded7Smrg
10571ee3e8c14Smrg      $preload \
10572ee3e8c14Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10573ee3e8c14Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10574191cded7Smrg
10575b290cf36Smrg      case $host in
10576b290cf36Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10577b290cf36Smrg	# On Rhapsody replace the C library is the System framework
10578ba064abeSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10579ba064abeSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10580191cded7Smrg	;;
10581191cded7Smrg      esac
10582191cded7Smrg
10583b290cf36Smrg      case $host in
10584b290cf36Smrg      *-*-darwin*)
10585b290cf36Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10586b290cf36Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10587ee3e8c14Smrg	if test CXX = "$tagname"; then
10588b290cf36Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10589b290cf36Smrg	    10.[0123])
10590ee3e8c14Smrg	      func_append compile_command " $wl-bind_at_load"
10591ee3e8c14Smrg	      func_append finalize_command " $wl-bind_at_load"
10592b290cf36Smrg	    ;;
10593b290cf36Smrg	  esac
10594b290cf36Smrg	fi
10595b290cf36Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10596ba064abeSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10597ba064abeSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10598191cded7Smrg	;;
10599191cded7Smrg      esac
10600191cded7Smrg
10601191cded7Smrg
10602b290cf36Smrg      # move library search paths that coincide with paths to not yet
10603b290cf36Smrg      # installed libraries to the beginning of the library search list
10604b290cf36Smrg      new_libs=
10605b290cf36Smrg      for path in $notinst_path; do
10606b290cf36Smrg	case " $new_libs " in
10607b290cf36Smrg	*" -L$path/$objdir "*) ;;
10608191cded7Smrg	*)
10609b290cf36Smrg	  case " $compile_deplibs " in
10610b290cf36Smrg	  *" -L$path/$objdir "*)
10611d9dcd5aeSmrg	    func_append new_libs " -L$path/$objdir" ;;
10612b290cf36Smrg	  esac
10613191cded7Smrg	  ;;
10614191cded7Smrg	esac
10615191cded7Smrg      done
10616b290cf36Smrg      for deplib in $compile_deplibs; do
10617b290cf36Smrg	case $deplib in
10618b290cf36Smrg	-L*)
10619b290cf36Smrg	  case " $new_libs " in
10620b290cf36Smrg	  *" $deplib "*) ;;
10621d9dcd5aeSmrg	  *) func_append new_libs " $deplib" ;;
10622b290cf36Smrg	  esac
10623b290cf36Smrg	  ;;
10624d9dcd5aeSmrg	*) func_append new_libs " $deplib" ;;
10625b290cf36Smrg	esac
10626b290cf36Smrg      done
10627ee3e8c14Smrg      compile_deplibs=$new_libs
10628191cded7Smrg
10629191cded7Smrg
10630d9dcd5aeSmrg      func_append compile_command " $compile_deplibs"
10631d9dcd5aeSmrg      func_append finalize_command " $finalize_deplibs"
10632191cded7Smrg
10633b290cf36Smrg      if test -n "$rpath$xrpath"; then
10634b290cf36Smrg	# If the user specified any rpath flags, then add them.
10635b290cf36Smrg	for libdir in $rpath $xrpath; do
10636b290cf36Smrg	  # This is the magic to use -rpath.
10637b290cf36Smrg	  case "$finalize_rpath " in
10638b290cf36Smrg	  *" $libdir "*) ;;
10639d9dcd5aeSmrg	  *) func_append finalize_rpath " $libdir" ;;
10640b290cf36Smrg	  esac
10641b290cf36Smrg	done
10642b290cf36Smrg      fi
10643191cded7Smrg
10644b290cf36Smrg      # Now hardcode the library paths
10645b290cf36Smrg      rpath=
10646b290cf36Smrg      hardcode_libdirs=
10647b290cf36Smrg      for libdir in $compile_rpath $finalize_rpath; do
10648b290cf36Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10649b290cf36Smrg	  if test -n "$hardcode_libdir_separator"; then
10650b290cf36Smrg	    if test -z "$hardcode_libdirs"; then
10651ee3e8c14Smrg	      hardcode_libdirs=$libdir
10652b290cf36Smrg	    else
10653b290cf36Smrg	      # Just accumulate the unique libdirs.
10654b290cf36Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10655b290cf36Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10656b290cf36Smrg		;;
10657b290cf36Smrg	      *)
10658d9dcd5aeSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10659b290cf36Smrg		;;
10660b290cf36Smrg	      esac
10661b290cf36Smrg	    fi
10662b290cf36Smrg	  else
10663b290cf36Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10664d9dcd5aeSmrg	    func_append rpath " $flag"
10665b290cf36Smrg	  fi
10666b290cf36Smrg	elif test -n "$runpath_var"; then
10667b290cf36Smrg	  case "$perm_rpath " in
10668191cded7Smrg	  *" $libdir "*) ;;
10669d9dcd5aeSmrg	  *) func_append perm_rpath " $libdir" ;;
10670191cded7Smrg	  esac
10671b290cf36Smrg	fi
10672b290cf36Smrg	case $host in
106738f9fac4aSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
10674ee3e8c14Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10675b290cf36Smrg	  case :$dllsearchpath: in
10676b290cf36Smrg	  *":$libdir:"*) ;;
10677b290cf36Smrg	  ::) dllsearchpath=$libdir;;
10678d9dcd5aeSmrg	  *) func_append dllsearchpath ":$libdir";;
10679b290cf36Smrg	  esac
10680b290cf36Smrg	  case :$dllsearchpath: in
10681b290cf36Smrg	  *":$testbindir:"*) ;;
10682b290cf36Smrg	  ::) dllsearchpath=$testbindir;;
10683d9dcd5aeSmrg	  *) func_append dllsearchpath ":$testbindir";;
10684b290cf36Smrg	  esac
10685b290cf36Smrg	  ;;
10686b290cf36Smrg	esac
10687b290cf36Smrg      done
10688b290cf36Smrg      # Substitute the hardcoded libdirs into the rpath.
10689b290cf36Smrg      if test -n "$hardcode_libdir_separator" &&
10690b290cf36Smrg	 test -n "$hardcode_libdirs"; then
10691ee3e8c14Smrg	libdir=$hardcode_libdirs
10692b290cf36Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10693b290cf36Smrg      fi
10694ee3e8c14Smrg      compile_rpath=$rpath
10695b290cf36Smrg
10696b290cf36Smrg      rpath=
10697b290cf36Smrg      hardcode_libdirs=
10698b290cf36Smrg      for libdir in $finalize_rpath; do
10699b290cf36Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10700b290cf36Smrg	  if test -n "$hardcode_libdir_separator"; then
10701b290cf36Smrg	    if test -z "$hardcode_libdirs"; then
10702ee3e8c14Smrg	      hardcode_libdirs=$libdir
10703b290cf36Smrg	    else
10704b290cf36Smrg	      # Just accumulate the unique libdirs.
10705b290cf36Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10706b290cf36Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10707b290cf36Smrg		;;
10708b290cf36Smrg	      *)
10709d9dcd5aeSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10710b290cf36Smrg		;;
10711b290cf36Smrg	      esac
10712b290cf36Smrg	    fi
10713b290cf36Smrg	  else
10714b290cf36Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10715d9dcd5aeSmrg	    func_append rpath " $flag"
10716b290cf36Smrg	  fi
10717b290cf36Smrg	elif test -n "$runpath_var"; then
10718b290cf36Smrg	  case "$finalize_perm_rpath " in
10719191cded7Smrg	  *" $libdir "*) ;;
10720d9dcd5aeSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10721191cded7Smrg	  esac
10722191cded7Smrg	fi
10723b290cf36Smrg      done
10724b290cf36Smrg      # Substitute the hardcoded libdirs into the rpath.
10725b290cf36Smrg      if test -n "$hardcode_libdir_separator" &&
10726b290cf36Smrg	 test -n "$hardcode_libdirs"; then
10727ee3e8c14Smrg	libdir=$hardcode_libdirs
10728b290cf36Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10729b290cf36Smrg      fi
10730ee3e8c14Smrg      finalize_rpath=$rpath
10731191cded7Smrg
10732ee3e8c14Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10733b290cf36Smrg	# Transform all the library objects into standard objects.
10734ba064abeSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10735ba064abeSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10736b290cf36Smrg      fi
10737191cded7Smrg
10738ee3e8c14Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10739191cded7Smrg
10740b290cf36Smrg      # template prelinking step
10741b290cf36Smrg      if test -n "$prelink_cmds"; then
10742b290cf36Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10743b290cf36Smrg      fi
10744191cded7Smrg
10745ee3e8c14Smrg      wrappers_required=:
10746b290cf36Smrg      case $host in
10747ba064abeSmrg      *cegcc* | *mingw32ce*)
10748ba064abeSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10749ee3e8c14Smrg        wrappers_required=false
10750ba064abeSmrg        ;;
107518f9fac4aSmrg      *cygwin* | *mingw* | *windows* )
10752ee3e8c14Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10753b290cf36Smrg        ;;
10754b290cf36Smrg      *)
10755ee3e8c14Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10756ee3e8c14Smrg          wrappers_required=false
10757b290cf36Smrg        fi
10758b290cf36Smrg        ;;
10759b290cf36Smrg      esac
10760ee3e8c14Smrg      $wrappers_required || {
10761b290cf36Smrg	# Replace the output file specification.
10762ba064abeSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10763ee3e8c14Smrg	link_command=$compile_command$compile_rpath
10764191cded7Smrg
10765b290cf36Smrg	# We have no uninstalled library dependencies, so finalize right now.
10766b290cf36Smrg	exit_status=0
10767b290cf36Smrg	func_show_eval "$link_command" 'exit_status=$?'
10768191cded7Smrg
10769d9dcd5aeSmrg	if test -n "$postlink_cmds"; then
10770d9dcd5aeSmrg	  func_to_tool_file "$output"
10771d9dcd5aeSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10772d9dcd5aeSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10773d9dcd5aeSmrg	fi
10774d9dcd5aeSmrg
10775b290cf36Smrg	# Delete the generated files.
10776ee3e8c14Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10777ee3e8c14Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10778b290cf36Smrg	fi
10779191cded7Smrg
10780b290cf36Smrg	exit $exit_status
10781ee3e8c14Smrg      }
10782191cded7Smrg
10783b290cf36Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10784b290cf36Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10785b290cf36Smrg      fi
10786b290cf36Smrg      if test -n "$finalize_shlibpath"; then
10787b290cf36Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10788b290cf36Smrg      fi
10789191cded7Smrg
10790b290cf36Smrg      compile_var=
10791b290cf36Smrg      finalize_var=
10792b290cf36Smrg      if test -n "$runpath_var"; then
10793b290cf36Smrg	if test -n "$perm_rpath"; then
10794b290cf36Smrg	  # We should set the runpath_var.
10795b290cf36Smrg	  rpath=
10796b290cf36Smrg	  for dir in $perm_rpath; do
10797d9dcd5aeSmrg	    func_append rpath "$dir:"
10798191cded7Smrg	  done
10799b290cf36Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10800191cded7Smrg	fi
10801b290cf36Smrg	if test -n "$finalize_perm_rpath"; then
10802b290cf36Smrg	  # We should set the runpath_var.
10803b290cf36Smrg	  rpath=
10804b290cf36Smrg	  for dir in $finalize_perm_rpath; do
10805d9dcd5aeSmrg	    func_append rpath "$dir:"
10806b290cf36Smrg	  done
10807b290cf36Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10808b290cf36Smrg	fi
10809b290cf36Smrg      fi
10810191cded7Smrg
10811ee3e8c14Smrg      if test yes = "$no_install"; then
10812b290cf36Smrg	# We don't need to create a wrapper script.
10813ee3e8c14Smrg	link_command=$compile_var$compile_command$compile_rpath
10814b290cf36Smrg	# Replace the output file specification.
10815ba064abeSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10816b290cf36Smrg	# Delete the old output file.
10817b290cf36Smrg	$opt_dry_run || $RM $output
10818b290cf36Smrg	# Link the executable and exit
10819b290cf36Smrg	func_show_eval "$link_command" 'exit $?'
10820d9dcd5aeSmrg
10821d9dcd5aeSmrg	if test -n "$postlink_cmds"; then
10822d9dcd5aeSmrg	  func_to_tool_file "$output"
10823d9dcd5aeSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10824d9dcd5aeSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10825d9dcd5aeSmrg	fi
10826d9dcd5aeSmrg
10827b290cf36Smrg	exit $EXIT_SUCCESS
10828b290cf36Smrg      fi
10829191cded7Smrg
10830ee3e8c14Smrg      case $hardcode_action,$fast_install in
10831ee3e8c14Smrg        relink,*)
10832ee3e8c14Smrg	  # Fast installation is not supported
10833ee3e8c14Smrg	  link_command=$compile_var$compile_command$compile_rpath
10834ee3e8c14Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10835191cded7Smrg
10836ee3e8c14Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10837ee3e8c14Smrg	  func_warning "'$output' will be relinked during installation"
10838ee3e8c14Smrg	  ;;
10839ee3e8c14Smrg        *,yes)
10840ee3e8c14Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10841ee3e8c14Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10842ee3e8c14Smrg          ;;
10843ee3e8c14Smrg	*,no)
10844ee3e8c14Smrg	  link_command=$compile_var$compile_command$compile_rpath
10845ee3e8c14Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10846ee3e8c14Smrg          ;;
10847ee3e8c14Smrg	*,needless)
10848ee3e8c14Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10849ee3e8c14Smrg	  relink_command=
10850ee3e8c14Smrg          ;;
10851ee3e8c14Smrg      esac
10852191cded7Smrg
10853b290cf36Smrg      # Replace the output file specification.
10854ba064abeSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10855191cded7Smrg
10856b290cf36Smrg      # Delete the old output files.
10857b290cf36Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10858191cded7Smrg
10859b290cf36Smrg      func_show_eval "$link_command" 'exit $?'
10860191cded7Smrg
10861d9dcd5aeSmrg      if test -n "$postlink_cmds"; then
10862d9dcd5aeSmrg	func_to_tool_file "$output_objdir/$outputname"
10863d9dcd5aeSmrg	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'`
10864d9dcd5aeSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10865d9dcd5aeSmrg      fi
10866d9dcd5aeSmrg
10867b290cf36Smrg      # Now create the wrapper script.
10868b290cf36Smrg      func_verbose "creating $output"
10869191cded7Smrg
10870b290cf36Smrg      # Quote the relink command for shipping.
10871b290cf36Smrg      if test -n "$relink_command"; then
10872b290cf36Smrg	# Preserve any variables that may affect compiler behavior
10873b290cf36Smrg	for var in $variables_saved_for_relink; do
10874b290cf36Smrg	  if eval test -z \"\${$var+set}\"; then
10875b290cf36Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10876b290cf36Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10877b290cf36Smrg	    relink_command="$var=; export $var; $relink_command"
10878b290cf36Smrg	  else
10879ee3e8c14Smrg	    func_quote_arg pretty "$var_value"
10880ee3e8c14Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10881b290cf36Smrg	  fi
10882b290cf36Smrg	done
10883ee3e8c14Smrg	func_quote eval cd "`pwd`"
10884ee3e8c14Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10885ee3e8c14Smrg	relink_command=$func_quote_arg_unquoted_result
10886b290cf36Smrg      fi
10887191cded7Smrg
10888b290cf36Smrg      # Only actually do things if not in dry run mode.
10889b290cf36Smrg      $opt_dry_run || {
10890b290cf36Smrg	# win32 will think the script is a binary if it has
10891b290cf36Smrg	# a .exe suffix, so we strip it off here.
10892b290cf36Smrg	case $output in
10893b290cf36Smrg	  *.exe) func_stripname '' '.exe' "$output"
10894b290cf36Smrg	         output=$func_stripname_result ;;
10895b290cf36Smrg	esac
10896b290cf36Smrg	# test for cygwin because mv fails w/o .exe extensions
10897191cded7Smrg	case $host in
10898b290cf36Smrg	  *cygwin*)
10899b290cf36Smrg	    exeext=.exe
10900b290cf36Smrg	    func_stripname '' '.exe' "$outputname"
10901b290cf36Smrg	    outputname=$func_stripname_result ;;
10902b290cf36Smrg	  *) exeext= ;;
10903191cded7Smrg	esac
10904b290cf36Smrg	case $host in
109058f9fac4aSmrg	  *cygwin* | *mingw* | windows* )
10906b290cf36Smrg	    func_dirname_and_basename "$output" "" "."
10907b290cf36Smrg	    output_name=$func_basename_result
10908b290cf36Smrg	    output_path=$func_dirname_result
10909ee3e8c14Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10910ee3e8c14Smrg	    cwrapper=$output_path/$output_name.exe
10911b290cf36Smrg	    $RM $cwrappersource $cwrapper
10912b290cf36Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10913b290cf36Smrg
10914b290cf36Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10915b290cf36Smrg
10916b290cf36Smrg	    # The wrapper executable is built using the $host compiler,
10917b290cf36Smrg	    # because it contains $host paths and files. If cross-
10918b290cf36Smrg	    # compiling, it, like the target executable, must be
10919b290cf36Smrg	    # executed on the $host or under an emulation environment.
10920b290cf36Smrg	    $opt_dry_run || {
10921b290cf36Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10922b290cf36Smrg	      $STRIP $cwrapper
10923b290cf36Smrg	    }
10924191cded7Smrg
10925b290cf36Smrg	    # Now, create the wrapper script for func_source use:
10926b290cf36Smrg	    func_ltwrapper_scriptname $cwrapper
10927b290cf36Smrg	    $RM $func_ltwrapper_scriptname_result
10928b290cf36Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10929b290cf36Smrg	    $opt_dry_run || {
10930b290cf36Smrg	      # note: this script will not be executed, so do not chmod.
10931ee3e8c14Smrg	      if test "x$build" = "x$host"; then
10932b290cf36Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10933191cded7Smrg	      else
10934b290cf36Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10935191cded7Smrg	      fi
10936b290cf36Smrg	    }
10937b290cf36Smrg	  ;;
10938b290cf36Smrg	  * )
10939b290cf36Smrg	    $RM $output
10940b290cf36Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10941191cded7Smrg
10942b290cf36Smrg	    func_emit_wrapper no > $output
10943b290cf36Smrg	    chmod +x $output
10944191cded7Smrg	  ;;
10945191cded7Smrg	esac
10946b290cf36Smrg      }
10947b290cf36Smrg      exit $EXIT_SUCCESS
10948b290cf36Smrg      ;;
10949b290cf36Smrg    esac
10950191cded7Smrg
10951b290cf36Smrg    # See if we need to build an old-fashioned archive.
10952b290cf36Smrg    for oldlib in $oldlibs; do
10953191cded7Smrg
10954ee3e8c14Smrg      case $build_libtool_libs in
10955ee3e8c14Smrg        convenience)
10956ee3e8c14Smrg	  oldobjs="$libobjs_save $symfileobj"
10957ee3e8c14Smrg	  addlibs=$convenience
10958b290cf36Smrg	  build_libtool_libs=no
10959ee3e8c14Smrg	  ;;
10960ee3e8c14Smrg	module)
10961ee3e8c14Smrg	  oldobjs=$libobjs_save
10962ee3e8c14Smrg	  addlibs=$old_convenience
10963ee3e8c14Smrg	  build_libtool_libs=no
10964ee3e8c14Smrg          ;;
10965ee3e8c14Smrg	*)
10966b290cf36Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10967ee3e8c14Smrg	  $preload && test -f "$symfileobj" \
10968ee3e8c14Smrg	    && func_append oldobjs " $symfileobj"
10969ee3e8c14Smrg	  addlibs=$old_convenience
10970ee3e8c14Smrg	  ;;
10971ee3e8c14Smrg      esac
10972191cded7Smrg
10973b290cf36Smrg      if test -n "$addlibs"; then
10974ee3e8c14Smrg	gentop=$output_objdir/${outputname}x
10975d9dcd5aeSmrg	func_append generated " $gentop"
10976191cded7Smrg
10977b290cf36Smrg	func_extract_archives $gentop $addlibs
10978d9dcd5aeSmrg	func_append oldobjs " $func_extract_archives_result"
10979b290cf36Smrg      fi
10980191cded7Smrg
10981b290cf36Smrg      # Do each command in the archive commands.
10982ee3e8c14Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10983b290cf36Smrg	cmds=$old_archive_from_new_cmds
10984b290cf36Smrg      else
10985191cded7Smrg
10986b290cf36Smrg	# Add any objects from preloaded convenience libraries
10987b290cf36Smrg	if test -n "$dlprefiles"; then
10988ee3e8c14Smrg	  gentop=$output_objdir/${outputname}x
10989d9dcd5aeSmrg	  func_append generated " $gentop"
10990191cded7Smrg
10991b290cf36Smrg	  func_extract_archives $gentop $dlprefiles
10992d9dcd5aeSmrg	  func_append oldobjs " $func_extract_archives_result"
10993b290cf36Smrg	fi
10994191cded7Smrg
10995b290cf36Smrg	# POSIX demands no paths to be encoded in archives.  We have
10996b290cf36Smrg	# to avoid creating archives with duplicate basenames if we
10997b290cf36Smrg	# might have to extract them afterwards, e.g., when creating a
10998b290cf36Smrg	# static archive out of a convenience library, or when linking
10999b290cf36Smrg	# the entirety of a libtool archive into another (currently
11000b290cf36Smrg	# not supported by libtool).
11001b290cf36Smrg	if (for obj in $oldobjs
11002b290cf36Smrg	    do
11003b290cf36Smrg	      func_basename "$obj"
11004b290cf36Smrg	      $ECHO "$func_basename_result"
11005b290cf36Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
11006b290cf36Smrg	  :
11007b290cf36Smrg	else
11008ba064abeSmrg	  echo "copying selected object files to avoid basename conflicts..."
11009ee3e8c14Smrg	  gentop=$output_objdir/${outputname}x
11010d9dcd5aeSmrg	  func_append generated " $gentop"
11011b290cf36Smrg	  func_mkdir_p "$gentop"
11012b290cf36Smrg	  save_oldobjs=$oldobjs
11013b290cf36Smrg	  oldobjs=
11014b290cf36Smrg	  counter=1
11015b290cf36Smrg	  for obj in $save_oldobjs
11016b290cf36Smrg	  do
11017b290cf36Smrg	    func_basename "$obj"
11018ee3e8c14Smrg	    objbase=$func_basename_result
11019b290cf36Smrg	    case " $oldobjs " in
11020b290cf36Smrg	    " ") oldobjs=$obj ;;
11021b290cf36Smrg	    *[\ /]"$objbase "*)
11022b290cf36Smrg	      while :; do
11023b290cf36Smrg		# Make sure we don't pick an alternate name that also
11024b290cf36Smrg		# overlaps.
11025b290cf36Smrg		newobj=lt$counter-$objbase
11026b290cf36Smrg		func_arith $counter + 1
11027b290cf36Smrg		counter=$func_arith_result
11028b290cf36Smrg		case " $oldobjs " in
11029b290cf36Smrg		*[\ /]"$newobj "*) ;;
11030b290cf36Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
11031b290cf36Smrg		esac
11032b290cf36Smrg	      done
11033b290cf36Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
11034d9dcd5aeSmrg	      func_append oldobjs " $gentop/$newobj"
11035b290cf36Smrg	      ;;
11036d9dcd5aeSmrg	    *) func_append oldobjs " $obj" ;;
11037b290cf36Smrg	    esac
11038191cded7Smrg	  done
11039191cded7Smrg	fi
11040d9dcd5aeSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
11041d9dcd5aeSmrg	tool_oldlib=$func_to_tool_file_result
11042b290cf36Smrg	eval cmds=\"$old_archive_cmds\"
11043191cded7Smrg
11044b290cf36Smrg	func_len " $cmds"
11045b290cf36Smrg	len=$func_len_result
11046b290cf36Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
11047b290cf36Smrg	  cmds=$old_archive_cmds
11048d9dcd5aeSmrg	elif test -n "$archiver_list_spec"; then
11049d9dcd5aeSmrg	  func_verbose "using command file archive linking..."
11050d9dcd5aeSmrg	  for obj in $oldobjs
11051d9dcd5aeSmrg	  do
11052d9dcd5aeSmrg	    func_to_tool_file "$obj"
11053d9dcd5aeSmrg	    $ECHO "$func_to_tool_file_result"
11054d9dcd5aeSmrg	  done > $output_objdir/$libname.libcmd
11055d9dcd5aeSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
11056d9dcd5aeSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
11057d9dcd5aeSmrg	  cmds=$old_archive_cmds
11058b290cf36Smrg	else
11059b290cf36Smrg	  # the command line is too long to link in one step, link in parts
11060b290cf36Smrg	  func_verbose "using piecewise archive linking..."
11061b290cf36Smrg	  save_RANLIB=$RANLIB
11062b290cf36Smrg	  RANLIB=:
11063b290cf36Smrg	  objlist=
11064b290cf36Smrg	  concat_cmds=
11065b290cf36Smrg	  save_oldobjs=$oldobjs
11066b290cf36Smrg	  oldobjs=
11067b290cf36Smrg	  # Is there a better way of finding the last object in the list?
11068b290cf36Smrg	  for obj in $save_oldobjs
11069b290cf36Smrg	  do
11070b290cf36Smrg	    last_oldobj=$obj
11071b290cf36Smrg	  done
11072b290cf36Smrg	  eval test_cmds=\"$old_archive_cmds\"
11073b290cf36Smrg	  func_len " $test_cmds"
11074b290cf36Smrg	  len0=$func_len_result
11075b290cf36Smrg	  len=$len0
11076b290cf36Smrg	  for obj in $save_oldobjs
11077b290cf36Smrg	  do
11078b290cf36Smrg	    func_len " $obj"
11079b290cf36Smrg	    func_arith $len + $func_len_result
11080b290cf36Smrg	    len=$func_arith_result
11081b290cf36Smrg	    func_append objlist " $obj"
11082b290cf36Smrg	    if test "$len" -lt "$max_cmd_len"; then
11083b290cf36Smrg	      :
11084b290cf36Smrg	    else
11085b290cf36Smrg	      # the above command should be used before it gets too long
11086b290cf36Smrg	      oldobjs=$objlist
11087ee3e8c14Smrg	      if test "$obj" = "$last_oldobj"; then
11088b290cf36Smrg		RANLIB=$save_RANLIB
11089b290cf36Smrg	      fi
11090b290cf36Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11091ee3e8c14Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11092b290cf36Smrg	      objlist=
11093b290cf36Smrg	      len=$len0
11094b290cf36Smrg	    fi
11095b290cf36Smrg	  done
11096b290cf36Smrg	  RANLIB=$save_RANLIB
11097b290cf36Smrg	  oldobjs=$objlist
11098ee3e8c14Smrg	  if test -z "$oldobjs"; then
11099b290cf36Smrg	    eval cmds=\"\$concat_cmds\"
11100b290cf36Smrg	  else
11101b290cf36Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11102b290cf36Smrg	  fi
11103b290cf36Smrg	fi
11104b290cf36Smrg      fi
11105b290cf36Smrg      func_execute_cmds "$cmds" 'exit $?'
11106191cded7Smrg    done
11107191cded7Smrg
11108b290cf36Smrg    test -n "$generated" && \
11109b290cf36Smrg      func_show_eval "${RM}r$generated"
11110191cded7Smrg
11111b290cf36Smrg    # Now create the libtool archive.
11112b290cf36Smrg    case $output in
11113b290cf36Smrg    *.la)
11114b290cf36Smrg      old_library=
11115ee3e8c14Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11116b290cf36Smrg      func_verbose "creating $output"
11117191cded7Smrg
11118b290cf36Smrg      # Preserve any variables that may affect compiler behavior
11119b290cf36Smrg      for var in $variables_saved_for_relink; do
11120b290cf36Smrg	if eval test -z \"\${$var+set}\"; then
11121b290cf36Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11122b290cf36Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11123b290cf36Smrg	  relink_command="$var=; export $var; $relink_command"
11124191cded7Smrg	else
11125ee3e8c14Smrg	  func_quote_arg pretty,unquoted "$var_value"
11126ee3e8c14Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11127191cded7Smrg	fi
11128b290cf36Smrg      done
11129b290cf36Smrg      # Quote the link command for shipping.
11130ee3e8c14Smrg      func_quote eval cd "`pwd`"
11131ee3e8c14Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11132ee3e8c14Smrg      func_quote_arg pretty,unquoted "$relink_command"
11133ee3e8c14Smrg      relink_command=$func_quote_arg_unquoted_result
11134ee3e8c14Smrg      if test yes = "$hardcode_automatic"; then
11135b290cf36Smrg	relink_command=
11136b290cf36Smrg      fi
11137191cded7Smrg
11138b290cf36Smrg      # Only create the output if not a dry run.
11139b290cf36Smrg      $opt_dry_run || {
11140b290cf36Smrg	for installed in no yes; do
11141ee3e8c14Smrg	  if test yes = "$installed"; then
11142b290cf36Smrg	    if test -z "$install_libdir"; then
11143b290cf36Smrg	      break
11144b290cf36Smrg	    fi
11145ee3e8c14Smrg	    output=$output_objdir/${outputname}i
11146b290cf36Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11147b290cf36Smrg	    newdependency_libs=
11148b290cf36Smrg	    for deplib in $dependency_libs; do
11149b290cf36Smrg	      case $deplib in
11150b290cf36Smrg	      *.la)
11151b290cf36Smrg		func_basename "$deplib"
11152ee3e8c14Smrg		name=$func_basename_result
11153d9dcd5aeSmrg		func_resolve_sysroot "$deplib"
11154ee3e8c14Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11155b290cf36Smrg		test -z "$libdir" && \
11156ee3e8c14Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11157d9dcd5aeSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11158d9dcd5aeSmrg		;;
11159d9dcd5aeSmrg	      -L*)
11160d9dcd5aeSmrg		func_stripname -L '' "$deplib"
11161d9dcd5aeSmrg		func_replace_sysroot "$func_stripname_result"
11162d9dcd5aeSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11163d9dcd5aeSmrg		;;
11164d9dcd5aeSmrg	      -R*)
11165d9dcd5aeSmrg		func_stripname -R '' "$deplib"
11166d9dcd5aeSmrg		func_replace_sysroot "$func_stripname_result"
11167d9dcd5aeSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11168b290cf36Smrg		;;
11169d9dcd5aeSmrg	      *) func_append newdependency_libs " $deplib" ;;
11170b290cf36Smrg	      esac
11171b290cf36Smrg	    done
11172ee3e8c14Smrg	    dependency_libs=$newdependency_libs
11173b290cf36Smrg	    newdlfiles=
11174b290cf36Smrg
11175b290cf36Smrg	    for lib in $dlfiles; do
11176b290cf36Smrg	      case $lib in
11177b290cf36Smrg	      *.la)
11178b290cf36Smrg	        func_basename "$lib"
11179ee3e8c14Smrg		name=$func_basename_result
11180ee3e8c14Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11181b290cf36Smrg		test -z "$libdir" && \
11182ee3e8c14Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11183d9dcd5aeSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11184b290cf36Smrg		;;
11185d9dcd5aeSmrg	      *) func_append newdlfiles " $lib" ;;
11186b290cf36Smrg	      esac
11187b290cf36Smrg	    done
11188ee3e8c14Smrg	    dlfiles=$newdlfiles
11189b290cf36Smrg	    newdlprefiles=
11190b290cf36Smrg	    for lib in $dlprefiles; do
11191b290cf36Smrg	      case $lib in
11192b290cf36Smrg	      *.la)
11193b290cf36Smrg		# Only pass preopened files to the pseudo-archive (for
11194b290cf36Smrg		# eventual linking with the app. that links it) if we
11195b290cf36Smrg		# didn't already link the preopened objects directly into
11196b290cf36Smrg		# the library:
11197b290cf36Smrg		func_basename "$lib"
11198ee3e8c14Smrg		name=$func_basename_result
11199ee3e8c14Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11200b290cf36Smrg		test -z "$libdir" && \
11201ee3e8c14Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11202d9dcd5aeSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11203b290cf36Smrg		;;
11204b290cf36Smrg	      esac
11205b290cf36Smrg	    done
11206ee3e8c14Smrg	    dlprefiles=$newdlprefiles
11207b290cf36Smrg	  else
11208b290cf36Smrg	    newdlfiles=
11209b290cf36Smrg	    for lib in $dlfiles; do
11210b290cf36Smrg	      case $lib in
11211ee3e8c14Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11212b290cf36Smrg		*) abs=`pwd`"/$lib" ;;
11213b290cf36Smrg	      esac
11214d9dcd5aeSmrg	      func_append newdlfiles " $abs"
11215b290cf36Smrg	    done
11216ee3e8c14Smrg	    dlfiles=$newdlfiles
11217b290cf36Smrg	    newdlprefiles=
11218b290cf36Smrg	    for lib in $dlprefiles; do
11219b290cf36Smrg	      case $lib in
11220ee3e8c14Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11221b290cf36Smrg		*) abs=`pwd`"/$lib" ;;
11222b290cf36Smrg	      esac
11223d9dcd5aeSmrg	      func_append newdlprefiles " $abs"
11224b290cf36Smrg	    done
11225ee3e8c14Smrg	    dlprefiles=$newdlprefiles
11226b290cf36Smrg	  fi
11227b290cf36Smrg	  $RM $output
11228b290cf36Smrg	  # place dlname in correct position for cygwin
11229ba064abeSmrg	  # In fact, it would be nice if we could use this code for all target
11230ba064abeSmrg	  # systems that can't hard-code library paths into their executables
11231ba064abeSmrg	  # and that have no shared library path variable independent of PATH,
11232ba064abeSmrg	  # but it turns out we can't easily determine that from inspecting
11233ba064abeSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11234ba064abeSmrg	  # applies here; at the moment, that means platforms that use the PE
11235ba064abeSmrg	  # object format with DLL files.  See the long comment at the top of
11236ba064abeSmrg	  # tests/bindir.at for full details.
11237b290cf36Smrg	  tdlname=$dlname
11238b290cf36Smrg	  case $host,$output,$installed,$module,$dlname in
112398f9fac4aSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *windows*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11240ba064abeSmrg	      # If a -bindir argument was supplied, place the dll there.
11241ee3e8c14Smrg	      if test -n "$bindir"; then
11242ba064abeSmrg		func_relative_path "$install_libdir" "$bindir"
11243ee3e8c14Smrg		tdlname=$func_relative_path_result/$dlname
11244ba064abeSmrg	      else
11245ba064abeSmrg		# Otherwise fall back on heuristic.
11246ba064abeSmrg		tdlname=../bin/$dlname
11247ba064abeSmrg	      fi
11248ba064abeSmrg	      ;;
11249b290cf36Smrg	  esac
11250b290cf36Smrg	  $ECHO > $output "\
11251b290cf36Smrg# $outputname - a libtool library file
11252ee3e8c14Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11253b290cf36Smrg#
11254b290cf36Smrg# Please DO NOT delete this file!
11255b290cf36Smrg# It is necessary for linking the library.
11256191cded7Smrg
11257b290cf36Smrg# The name that we can dlopen(3).
11258b290cf36Smrgdlname='$tdlname'
11259191cded7Smrg
11260b290cf36Smrg# Names of this library.
11261b290cf36Smrglibrary_names='$library_names'
11262191cded7Smrg
11263b290cf36Smrg# The name of the static archive.
11264b290cf36Smrgold_library='$old_library'
11265191cded7Smrg
11266ee3e8c14Smrg# Linker flags that cannot go in dependency_libs.
11267b290cf36Smrginherited_linker_flags='$new_inherited_linker_flags'
11268191cded7Smrg
11269b290cf36Smrg# Libraries that this one depends upon.
11270b290cf36Smrgdependency_libs='$dependency_libs'
11271191cded7Smrg
11272b290cf36Smrg# Names of additional weak libraries provided by this library
11273b290cf36Smrgweak_library_names='$weak_libs'
11274191cded7Smrg
11275b290cf36Smrg# Version information for $libname.
11276b290cf36Smrgcurrent=$current
11277b290cf36Smrgage=$age
11278b290cf36Smrgrevision=$revision
11279191cded7Smrg
11280b290cf36Smrg# Is this an already installed library?
11281b290cf36Smrginstalled=$installed
11282191cded7Smrg
11283b290cf36Smrg# Should we warn about portability when linking against -modules?
11284b290cf36Smrgshouldnotlink=$module
11285191cded7Smrg
11286b290cf36Smrg# Files to dlopen/dlpreopen
11287b290cf36Smrgdlopen='$dlfiles'
11288b290cf36Smrgdlpreopen='$dlprefiles'
11289191cded7Smrg
11290b290cf36Smrg# Directory that this library needs to be installed in:
11291b290cf36Smrglibdir='$install_libdir'"
11292ee3e8c14Smrg	  if test no,yes = "$installed,$need_relink"; then
11293b290cf36Smrg	    $ECHO >> $output "\
11294b290cf36Smrgrelink_command=\"$relink_command\""
11295b290cf36Smrg	  fi
11296b290cf36Smrg	done
11297b290cf36Smrg      }
11298191cded7Smrg
11299b290cf36Smrg      # Do a symbolic link so that the libtool archive can be found in
11300b290cf36Smrg      # LD_LIBRARY_PATH before the program is installed.
11301b290cf36Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11302b290cf36Smrg      ;;
11303b290cf36Smrg    esac
11304b290cf36Smrg    exit $EXIT_SUCCESS
11305b290cf36Smrg}
11306191cded7Smrg
11307ee3e8c14Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11308ee3e8c14Smrg  func_mode_link ${1+"$@"}
11309ee3e8c14Smrgfi
11310191cded7Smrg
11311191cded7Smrg
11312b290cf36Smrg# func_mode_uninstall arg...
11313b290cf36Smrgfunc_mode_uninstall ()
11314b290cf36Smrg{
11315ee3e8c14Smrg    $debug_cmd
11316ee3e8c14Smrg
11317ee3e8c14Smrg    RM=$nonopt
11318191cded7Smrg    files=
11319ee3e8c14Smrg    rmforce=false
11320191cded7Smrg    exit_status=0
11321191cded7Smrg
11322191cded7Smrg    # This variable tells wrapper scripts just to set variables rather
11323191cded7Smrg    # than running their programs.
11324ee3e8c14Smrg    libtool_install_magic=$magic
11325191cded7Smrg
11326191cded7Smrg    for arg
11327191cded7Smrg    do
11328191cded7Smrg      case $arg in
11329ee3e8c14Smrg      -f) func_append RM " $arg"; rmforce=: ;;
11330d9dcd5aeSmrg      -*) func_append RM " $arg" ;;
11331d9dcd5aeSmrg      *) func_append files " $arg" ;;
11332191cded7Smrg      esac
11333191cded7Smrg    done
11334191cded7Smrg
11335b290cf36Smrg    test -z "$RM" && \
11336b290cf36Smrg      func_fatal_help "you must specify an RM program"
11337191cded7Smrg
11338191cded7Smrg    rmdirs=
11339191cded7Smrg
11340191cded7Smrg    for file in $files; do
11341b290cf36Smrg      func_dirname "$file" "" "."
11342ee3e8c14Smrg      dir=$func_dirname_result
11343ee3e8c14Smrg      if test . = "$dir"; then
11344ee3e8c14Smrg	odir=$objdir
11345191cded7Smrg      else
11346ee3e8c14Smrg	odir=$dir/$objdir
11347191cded7Smrg      fi
11348b290cf36Smrg      func_basename "$file"
11349ee3e8c14Smrg      name=$func_basename_result
11350ee3e8c14Smrg      test uninstall = "$opt_mode" && odir=$dir
11351191cded7Smrg
11352d9dcd5aeSmrg      # Remember odir for removal later, being careful to avoid duplicates
11353ee3e8c14Smrg      if test clean = "$opt_mode"; then
11354191cded7Smrg	case " $rmdirs " in
11355d9dcd5aeSmrg	  *" $odir "*) ;;
11356d9dcd5aeSmrg	  *) func_append rmdirs " $odir" ;;
11357191cded7Smrg	esac
11358191cded7Smrg      fi
11359191cded7Smrg
11360191cded7Smrg      # Don't error if the file doesn't exist and rm -f was used.
11361b290cf36Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11362b290cf36Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11363b290cf36Smrg	 test -f "$file"; then
11364191cded7Smrg	:
11365191cded7Smrg      elif test -d "$file"; then
11366191cded7Smrg	exit_status=1
11367191cded7Smrg	continue
11368ee3e8c14Smrg      elif $rmforce; then
11369191cded7Smrg	continue
11370191cded7Smrg      fi
11371191cded7Smrg
11372ee3e8c14Smrg      rmfiles=$file
11373191cded7Smrg
11374191cded7Smrg      case $name in
11375191cded7Smrg      *.la)
11376191cded7Smrg	# Possibly a libtool archive, so verify it.
11377b290cf36Smrg	if func_lalib_p "$file"; then
11378b290cf36Smrg	  func_source $dir/$name
11379191cded7Smrg
11380191cded7Smrg	  # Delete the libtool libraries and symlinks.
11381191cded7Smrg	  for n in $library_names; do
11382d9dcd5aeSmrg	    func_append rmfiles " $odir/$n"
11383191cded7Smrg	  done
11384d9dcd5aeSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11385191cded7Smrg
11386ee3e8c14Smrg	  case $opt_mode in
11387191cded7Smrg	  clean)
11388d9dcd5aeSmrg	    case " $library_names " in
11389191cded7Smrg	    *" $dlname "*) ;;
11390d9dcd5aeSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11391191cded7Smrg	    esac
11392d9dcd5aeSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11393191cded7Smrg	    ;;
11394191cded7Smrg	  uninstall)
11395191cded7Smrg	    if test -n "$library_names"; then
11396191cded7Smrg	      # Do each command in the postuninstall commands.
11397ee3e8c14Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11398191cded7Smrg	    fi
11399191cded7Smrg
11400191cded7Smrg	    if test -n "$old_library"; then
11401191cded7Smrg	      # Do each command in the old_postuninstall commands.
11402ee3e8c14Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11403191cded7Smrg	    fi
11404191cded7Smrg	    # FIXME: should reinstall the best remaining shared library.
11405191cded7Smrg	    ;;
11406191cded7Smrg	  esac
11407191cded7Smrg	fi
11408191cded7Smrg	;;
11409191cded7Smrg
11410191cded7Smrg      *.lo)
11411191cded7Smrg	# Possibly a libtool object, so verify it.
11412b290cf36Smrg	if func_lalib_p "$file"; then
11413191cded7Smrg
11414191cded7Smrg	  # Read the .lo file
11415b290cf36Smrg	  func_source $dir/$name
11416191cded7Smrg
11417191cded7Smrg	  # Add PIC object to the list of files to remove.
11418ee3e8c14Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11419d9dcd5aeSmrg	    func_append rmfiles " $dir/$pic_object"
11420191cded7Smrg	  fi
11421191cded7Smrg
11422191cded7Smrg	  # Add non-PIC object to the list of files to remove.
11423ee3e8c14Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11424d9dcd5aeSmrg	    func_append rmfiles " $dir/$non_pic_object"
11425191cded7Smrg	  fi
11426191cded7Smrg	fi
11427191cded7Smrg	;;
11428191cded7Smrg
11429191cded7Smrg      *)
11430ee3e8c14Smrg	if test clean = "$opt_mode"; then
11431191cded7Smrg	  noexename=$name
11432191cded7Smrg	  case $file in
11433191cded7Smrg	  *.exe)
11434b290cf36Smrg	    func_stripname '' '.exe' "$file"
11435b290cf36Smrg	    file=$func_stripname_result
11436b290cf36Smrg	    func_stripname '' '.exe' "$name"
11437b290cf36Smrg	    noexename=$func_stripname_result
11438191cded7Smrg	    # $file with .exe has already been added to rmfiles,
11439191cded7Smrg	    # add $file without .exe
11440d9dcd5aeSmrg	    func_append rmfiles " $file"
11441191cded7Smrg	    ;;
11442191cded7Smrg	  esac
11443191cded7Smrg	  # Do a test to see if this is a libtool program.
11444b290cf36Smrg	  if func_ltwrapper_p "$file"; then
11445b290cf36Smrg	    if func_ltwrapper_executable_p "$file"; then
11446b290cf36Smrg	      func_ltwrapper_scriptname "$file"
11447b290cf36Smrg	      relink_command=
11448b290cf36Smrg	      func_source $func_ltwrapper_scriptname_result
11449d9dcd5aeSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11450b290cf36Smrg	    else
11451b290cf36Smrg	      relink_command=
11452b290cf36Smrg	      func_source $dir/$noexename
11453b290cf36Smrg	    fi
11454191cded7Smrg
11455191cded7Smrg	    # note $name still contains .exe if it was in $file originally
11456191cded7Smrg	    # as does the version of $file that was added into $rmfiles
11457ee3e8c14Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11458ee3e8c14Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11459d9dcd5aeSmrg	      func_append rmfiles " $odir/lt-$name"
11460191cded7Smrg	    fi
11461ee3e8c14Smrg	    if test "X$noexename" != "X$name"; then
11462ee3e8c14Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11463191cded7Smrg	    fi
11464191cded7Smrg	  fi
11465191cded7Smrg	fi
11466191cded7Smrg	;;
11467191cded7Smrg      esac
11468b290cf36Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11469191cded7Smrg    done
11470191cded7Smrg
11471ee3e8c14Smrg    # Try to remove the $objdir's in the directories where we deleted files
11472191cded7Smrg    for dir in $rmdirs; do
11473191cded7Smrg      if test -d "$dir"; then
11474b290cf36Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11475191cded7Smrg      fi
11476191cded7Smrg    done
11477191cded7Smrg
11478191cded7Smrg    exit $exit_status
11479b290cf36Smrg}
11480191cded7Smrg
11481ee3e8c14Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11482ee3e8c14Smrg  func_mode_uninstall ${1+"$@"}
11483ee3e8c14Smrgfi
11484191cded7Smrg
11485d9dcd5aeSmrgtest -z "$opt_mode" && {
11486ee3e8c14Smrg  help=$generic_help
11487b290cf36Smrg  func_fatal_help "you must specify a MODE"
11488b290cf36Smrg}
11489b290cf36Smrg
11490b290cf36Smrgtest -z "$exec_cmd" && \
11491ee3e8c14Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11492191cded7Smrg
11493191cded7Smrgif test -n "$exec_cmd"; then
11494b290cf36Smrg  eval exec "$exec_cmd"
11495191cded7Smrg  exit $EXIT_FAILURE
11496191cded7Smrgfi
11497191cded7Smrg
11498b290cf36Smrgexit $exit_status
11499191cded7Smrg
11500191cded7Smrg
11501191cded7Smrg# The TAGs below are defined such that we never get into a situation
11502ee3e8c14Smrg# where we disable both kinds of libraries.  Given conflicting
11503191cded7Smrg# choices, we go for a static library, that is the most portable,
11504191cded7Smrg# since we can't tell whether shared libraries were disabled because
11505191cded7Smrg# the user asked for that or because the platform doesn't support
11506191cded7Smrg# them.  This is particularly important on AIX, because we don't
11507191cded7Smrg# support having both static and shared libraries enabled at the same
11508191cded7Smrg# time on that platform, so we default to a shared-only configuration.
11509191cded7Smrg# If a disable-shared tag is given, we'll fallback to a static-only
11510191cded7Smrg# configuration.  But we'll never go from static-only to shared-only.
11511191cded7Smrg
11512191cded7Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11513b290cf36Smrgbuild_libtool_libs=no
11514b290cf36Smrgbuild_old_libs=yes
11515191cded7Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
11516191cded7Smrg
11517191cded7Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11518b290cf36Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11519191cded7Smrg# ### END LIBTOOL TAG CONFIG: disable-static
11520191cded7Smrg
11521191cded7Smrg# Local Variables:
11522191cded7Smrg# mode:shell-script
11523191cded7Smrg# sh-indentation:2
11524191cded7Smrg# End:
11525