ltmain.sh revision 07fb9b8f
17d2c738bSmrg#! /usr/bin/env sh
2862bcd1aSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
37d2c738bSmrg##               by inline-source v2019-02-19.15
488de56ccSmrg
507fb9b8fSmrg# libtool (GNU libtool) 2.5.4
6862bcd1aSmrg# Provide generalized library-building support services.
788de56ccSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
888de56ccSmrg
907fb9b8fSmrg# Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc.
1088de56ccSmrg# This is free software; see the source for copying conditions.  There is NO
1188de56ccSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1288de56ccSmrg
1388de56ccSmrg# GNU Libtool is free software; you can redistribute it and/or modify
141ab64890Smrg# it under the terms of the GNU General Public License as published by
151ab64890Smrg# the Free Software Foundation; either version 2 of the License, or
161ab64890Smrg# (at your option) any later version.
171ab64890Smrg#
1888de56ccSmrg# As a special exception to the GNU General Public License,
1988de56ccSmrg# if you distribute this file as part of a program or library that
2088de56ccSmrg# is built using GNU Libtool, you may include this file under the
2188de56ccSmrg# same distribution terms that you use for the rest of that program.
2288de56ccSmrg#
2388de56ccSmrg# GNU Libtool is distributed in the hope that it will be useful, but
241ab64890Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
251ab64890Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
261ab64890Smrg# General Public License for more details.
271ab64890Smrg#
281ab64890Smrg# You should have received a copy of the GNU General Public License
29862bcd1aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30b4ee4795Smrg
311ab64890Smrg
32e9fcaa8aSmrgPROGRAM=libtool
331ab64890SmrgPACKAGE=libtool
3407fb9b8fSmrgVERSION=2.5.4
3507fb9b8fSmrgpackage_revision=2.5.4
361ab64890Smrg
37862bcd1aSmrg
38862bcd1aSmrg## ------ ##
39862bcd1aSmrg## Usage. ##
40862bcd1aSmrg## ------ ##
41862bcd1aSmrg
42862bcd1aSmrg# Run './libtool --help' for help with using this script from the
43862bcd1aSmrg# command line.
44862bcd1aSmrg
45862bcd1aSmrg
46862bcd1aSmrg## ------------------------------- ##
47862bcd1aSmrg## User overridable command paths. ##
48862bcd1aSmrg## ------------------------------- ##
49862bcd1aSmrg
50862bcd1aSmrg# After configure completes, it has a better idea of some of the
51862bcd1aSmrg# shell tools we need than the defaults used by the functions shared
52862bcd1aSmrg# with bootstrap, so set those here where they can still be over-
53862bcd1aSmrg# ridden by the user, but otherwise take precedence.
54862bcd1aSmrg
55862bcd1aSmrg: ${AUTOCONF="autoconf"}
56862bcd1aSmrg: ${AUTOMAKE="automake"}
57862bcd1aSmrg
58862bcd1aSmrg
59862bcd1aSmrg## -------------------------- ##
60862bcd1aSmrg## Source external libraries. ##
61862bcd1aSmrg## -------------------------- ##
62862bcd1aSmrg
63862bcd1aSmrg# Much of our low-level functionality needs to be sourced from external
64862bcd1aSmrg# libraries, which are installed to $pkgauxdir.
65862bcd1aSmrg
66862bcd1aSmrg# Set a version string for this script.
677d2c738bSmrgscriptversion=2019-02-19.15; # UTC
68862bcd1aSmrg
69862bcd1aSmrg# General shell script boiler plate, and helper functions.
70862bcd1aSmrg# Written by Gary V. Vaughan, 2004
71862bcd1aSmrg
727d2c738bSmrg# This is free software.  There is NO warranty; not even for
737d2c738bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
747d2c738bSmrg#
7507fb9b8fSmrg# Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors
767d2c738bSmrg#
777d2c738bSmrg# This file is dual licensed under the terms of the MIT license
7807fb9b8fSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
7907fb9b8fSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
807d2c738bSmrg# these licenses when using or redistributing this software or any of
817d2c738bSmrg# the files within it.  See the URLs above, or the file `LICENSE`
827d2c738bSmrg# included in the Bootstrap distribution for the full license texts.
8314db512dSmrg
847d2c738bSmrg# Please report bugs or propose patches to:
857d2c738bSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
86862bcd1aSmrg
87862bcd1aSmrg
88862bcd1aSmrg## ------ ##
89862bcd1aSmrg## Usage. ##
90862bcd1aSmrg## ------ ##
91862bcd1aSmrg
92862bcd1aSmrg# Evaluate this file near the top of your script to gain access to
93862bcd1aSmrg# the functions and variables defined here:
94862bcd1aSmrg#
95862bcd1aSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96862bcd1aSmrg#
97862bcd1aSmrg# If you need to override any of the default environment variable
98862bcd1aSmrg# settings, do that before evaluating this file.
99862bcd1aSmrg
100862bcd1aSmrg
101862bcd1aSmrg## -------------------- ##
102862bcd1aSmrg## Shell normalisation. ##
103862bcd1aSmrg## -------------------- ##
104862bcd1aSmrg
105862bcd1aSmrg# Some shells need a little help to be as Bourne compatible as possible.
106862bcd1aSmrg# Before doing anything else, make sure all that help has been provided!
107862bcd1aSmrg
108862bcd1aSmrgDUALCASE=1; export DUALCASE # for MKS sh
109862bcd1aSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1101ab64890Smrg  emulate sh
1111ab64890Smrg  NULLCMD=:
112862bcd1aSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1131ab64890Smrg  # is contrary to our usage.  Disable this feature.
1141ab64890Smrg  alias -g '${1+"$@"}'='"$@"'
1151ab64890Smrg  setopt NO_GLOB_SUBST
1161ab64890Smrgelse
117862bcd1aSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1181ab64890Smrgfi
119e9fcaa8aSmrg
120862bcd1aSmrg# NLS nuisances: We save the old values in case they are required later.
121862bcd1aSmrg_G_user_locale=
122862bcd1aSmrg_G_safe_locale=
123862bcd1aSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1241ab64890Smrgdo
125862bcd1aSmrg  eval "if test set = \"\${$_G_var+set}\"; then
126862bcd1aSmrg          save_$_G_var=\$$_G_var
127862bcd1aSmrg          $_G_var=C
128862bcd1aSmrg	  export $_G_var
129862bcd1aSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130862bcd1aSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1311ab64890Smrg	fi"
1321ab64890Smrgdone
1337d2c738bSmrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
1347d2c738bSmrg# in case the environment reset is needed later and the $save_* variant is not
1357d2c738bSmrg# defined (see the code above).
1367d2c738bSmrgLC_ALL=C
1377d2c738bSmrgLANGUAGE=C
1387d2c738bSmrgexport LANGUAGE LC_ALL
13988de56ccSmrg
140862bcd1aSmrg# Make sure IFS has a sensible default
141862bcd1aSmrgsp=' '
142862bcd1aSmrgnl='
143862bcd1aSmrg'
144862bcd1aSmrgIFS="$sp	$nl"
145862bcd1aSmrg
14607fb9b8fSmrg# There are apparently some systems that use ';' as a PATH separator!
147862bcd1aSmrgif test "${PATH_SEPARATOR+set}" != set; then
148862bcd1aSmrg  PATH_SEPARATOR=:
149862bcd1aSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150862bcd1aSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151862bcd1aSmrg      PATH_SEPARATOR=';'
152862bcd1aSmrg  }
153862bcd1aSmrgfi
15488de56ccSmrg
15588de56ccSmrg
1567d2c738bSmrg# func_unset VAR
1577d2c738bSmrg# --------------
1587d2c738bSmrg# Portably unset VAR.
1597d2c738bSmrg# In some shells, an 'unset VAR' statement leaves a non-zero return
1607d2c738bSmrg# status if VAR is already unset, which might be problematic if the
1617d2c738bSmrg# statement is used at the end of a function (thus poisoning its return
1627d2c738bSmrg# value) or when 'set -e' is active (causing even a spurious abort of
1637d2c738bSmrg# the script in this case).
1647d2c738bSmrgfunc_unset ()
1657d2c738bSmrg{
1667d2c738bSmrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
1677d2c738bSmrg}
1687d2c738bSmrg
1697d2c738bSmrg
1707d2c738bSmrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
1717d2c738bSmrgfunc_unset CDPATH
1727d2c738bSmrg
1737d2c738bSmrg# Make sure ${,E,F}GREP behave sanely.
1747d2c738bSmrgfunc_unset GREP_OPTIONS
1757d2c738bSmrg
17688de56ccSmrg
177862bcd1aSmrg## ------------------------- ##
178862bcd1aSmrg## Locate command utilities. ##
179862bcd1aSmrg## ------------------------- ##
180862bcd1aSmrg
181862bcd1aSmrg
182862bcd1aSmrg# func_executable_p FILE
183862bcd1aSmrg# ----------------------
184862bcd1aSmrg# Check that FILE is an executable regular file.
185862bcd1aSmrgfunc_executable_p ()
186862bcd1aSmrg{
187862bcd1aSmrg    test -f "$1" && test -x "$1"
188862bcd1aSmrg}
189862bcd1aSmrg
190862bcd1aSmrg
191862bcd1aSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192862bcd1aSmrg# --------------------------------------------
193862bcd1aSmrg# Search for either a program that responds to --version with output
194862bcd1aSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195862bcd1aSmrg# trying all the directories in PATH with each of the elements of
196862bcd1aSmrg# PROGS_LIST.
197862bcd1aSmrg#
198862bcd1aSmrg# CHECK_FUNC should accept the path to a candidate program, and
199862bcd1aSmrg# set $func_check_prog_result if it truncates its output less than
200862bcd1aSmrg# $_G_path_prog_max characters.
201862bcd1aSmrgfunc_path_progs ()
202862bcd1aSmrg{
203862bcd1aSmrg    _G_progs_list=$1
204862bcd1aSmrg    _G_check_func=$2
205862bcd1aSmrg    _G_PATH=${3-"$PATH"}
206862bcd1aSmrg
207862bcd1aSmrg    _G_path_prog_max=0
208862bcd1aSmrg    _G_path_prog_found=false
209862bcd1aSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210862bcd1aSmrg    for _G_dir in $_G_PATH; do
211862bcd1aSmrg      IFS=$_G_save_IFS
212862bcd1aSmrg      test -z "$_G_dir" && _G_dir=.
213862bcd1aSmrg      for _G_prog_name in $_G_progs_list; do
214862bcd1aSmrg        for _exeext in '' .EXE; do
215862bcd1aSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216862bcd1aSmrg          func_executable_p "$_G_path_prog" || continue
217862bcd1aSmrg          case `"$_G_path_prog" --version 2>&1` in
218862bcd1aSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219862bcd1aSmrg            *)     $_G_check_func $_G_path_prog
220862bcd1aSmrg		   func_path_progs_result=$func_check_prog_result
221862bcd1aSmrg		   ;;
222862bcd1aSmrg          esac
223862bcd1aSmrg          $_G_path_prog_found && break 3
224862bcd1aSmrg        done
225862bcd1aSmrg      done
226862bcd1aSmrg    done
227862bcd1aSmrg    IFS=$_G_save_IFS
228862bcd1aSmrg    test -z "$func_path_progs_result" && {
229862bcd1aSmrg      echo "no acceptable sed could be found in \$PATH" >&2
230862bcd1aSmrg      exit 1
231862bcd1aSmrg    }
232862bcd1aSmrg}
233862bcd1aSmrg
234862bcd1aSmrg
235862bcd1aSmrg# We want to be able to use the functions in this file before configure
236862bcd1aSmrg# has figured out where the best binaries are kept, which means we have
237862bcd1aSmrg# to search for them ourselves - except when the results are already set
238862bcd1aSmrg# where we skip the searches.
239862bcd1aSmrg
240862bcd1aSmrg# Unless the user overrides by setting SED, search the path for either GNU
241862bcd1aSmrg# sed, or the sed that truncates its output the least.
242862bcd1aSmrgtest -z "$SED" && {
243862bcd1aSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244862bcd1aSmrg  for _G_i in 1 2 3 4 5 6 7; do
245862bcd1aSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246862bcd1aSmrg  done
247862bcd1aSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248862bcd1aSmrg  _G_sed_script=
249862bcd1aSmrg
250862bcd1aSmrg  func_check_prog_sed ()
251862bcd1aSmrg  {
252862bcd1aSmrg    _G_path_prog=$1
253862bcd1aSmrg
254862bcd1aSmrg    _G_count=0
255862bcd1aSmrg    printf 0123456789 >conftest.in
256862bcd1aSmrg    while :
257862bcd1aSmrg    do
258862bcd1aSmrg      cat conftest.in conftest.in >conftest.tmp
259862bcd1aSmrg      mv conftest.tmp conftest.in
260862bcd1aSmrg      cp conftest.in conftest.nl
261862bcd1aSmrg      echo '' >> conftest.nl
262862bcd1aSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263862bcd1aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264862bcd1aSmrg      _G_count=`expr $_G_count + 1`
265862bcd1aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266862bcd1aSmrg        # Best one so far, save it but keep looking for a better one
267862bcd1aSmrg        func_check_prog_result=$_G_path_prog
268862bcd1aSmrg        _G_path_prog_max=$_G_count
269862bcd1aSmrg      fi
270862bcd1aSmrg      # 10*(2^10) chars as input seems more than enough
271862bcd1aSmrg      test 10 -lt "$_G_count" && break
272862bcd1aSmrg    done
273862bcd1aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274862bcd1aSmrg  }
275862bcd1aSmrg
2767d2c738bSmrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277862bcd1aSmrg  rm -f conftest.sed
278862bcd1aSmrg  SED=$func_path_progs_result
279862bcd1aSmrg}
280862bcd1aSmrg
281862bcd1aSmrg
282862bcd1aSmrg# Unless the user overrides by setting GREP, search the path for either GNU
283862bcd1aSmrg# grep, or the grep that truncates its output the least.
284862bcd1aSmrgtest -z "$GREP" && {
285862bcd1aSmrg  func_check_prog_grep ()
286862bcd1aSmrg  {
287862bcd1aSmrg    _G_path_prog=$1
288862bcd1aSmrg
289862bcd1aSmrg    _G_count=0
290862bcd1aSmrg    _G_path_prog_max=0
291862bcd1aSmrg    printf 0123456789 >conftest.in
292862bcd1aSmrg    while :
293862bcd1aSmrg    do
294862bcd1aSmrg      cat conftest.in conftest.in >conftest.tmp
295862bcd1aSmrg      mv conftest.tmp conftest.in
296862bcd1aSmrg      cp conftest.in conftest.nl
297862bcd1aSmrg      echo 'GREP' >> conftest.nl
298862bcd1aSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299862bcd1aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300862bcd1aSmrg      _G_count=`expr $_G_count + 1`
301862bcd1aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302862bcd1aSmrg        # Best one so far, save it but keep looking for a better one
303862bcd1aSmrg        func_check_prog_result=$_G_path_prog
304862bcd1aSmrg        _G_path_prog_max=$_G_count
305862bcd1aSmrg      fi
306862bcd1aSmrg      # 10*(2^10) chars as input seems more than enough
307862bcd1aSmrg      test 10 -lt "$_G_count" && break
308862bcd1aSmrg    done
309862bcd1aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310862bcd1aSmrg  }
311862bcd1aSmrg
3127d2c738bSmrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313862bcd1aSmrg  GREP=$func_path_progs_result
314862bcd1aSmrg}
315862bcd1aSmrg
316862bcd1aSmrg
317862bcd1aSmrg## ------------------------------- ##
318862bcd1aSmrg## User overridable command paths. ##
319862bcd1aSmrg## ------------------------------- ##
320862bcd1aSmrg
321862bcd1aSmrg# All uppercase variable names are used for environment variables.  These
322862bcd1aSmrg# variables can be overridden by the user before calling a script that
323862bcd1aSmrg# uses them if a suitable command of that name is not already available
324862bcd1aSmrg# in the command search PATH.
32588de56ccSmrg
32688de56ccSmrg: ${CP="cp -f"}
327862bcd1aSmrg: ${ECHO="printf %s\n"}
328862bcd1aSmrg: ${EGREP="$GREP -E"}
329862bcd1aSmrg: ${FGREP="$GREP -F"}
330862bcd1aSmrg: ${LN_S="ln -s"}
33188de56ccSmrg: ${MAKE="make"}
33288de56ccSmrg: ${MKDIR="mkdir"}
33388de56ccSmrg: ${MV="mv -f"}
33488de56ccSmrg: ${RM="rm -f"}
33588de56ccSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3361ab64890Smrg
33788de56ccSmrg
338862bcd1aSmrg## -------------------- ##
339862bcd1aSmrg## Useful sed snippets. ##
340862bcd1aSmrg## -------------------- ##
341e9fcaa8aSmrg
342862bcd1aSmrgsed_dirname='s|/[^/]*$||'
343862bcd1aSmrgsed_basename='s|^.*/||'
344e9fcaa8aSmrg
345862bcd1aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
346862bcd1aSmrg# metacharacters that are still active within double-quoted strings.
347862bcd1aSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348e9fcaa8aSmrg
349862bcd1aSmrg# Same as above, but do not quote variable references.
350862bcd1aSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351e9fcaa8aSmrg
352862bcd1aSmrg# Sed substitution that turns a string into a regex matching for the
353862bcd1aSmrg# string literally.
354862bcd1aSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355e9fcaa8aSmrg
356862bcd1aSmrg# Sed substitution that converts a w32 file name or path
357862bcd1aSmrg# that contains forward slashes, into one that contains
358862bcd1aSmrg# (escaped) backslashes.  A very naive implementation.
359862bcd1aSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360862bcd1aSmrg
361862bcd1aSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362862bcd1aSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363862bcd1aSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364862bcd1aSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
365862bcd1aSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366862bcd1aSmrg_G_bs='\\'
367862bcd1aSmrg_G_bs2='\\\\'
368862bcd1aSmrg_G_bs4='\\\\\\\\'
369862bcd1aSmrg_G_dollar='\$'
370862bcd1aSmrgsed_double_backslash="\
371862bcd1aSmrg  s/$_G_bs4/&\\
372862bcd1aSmrg/g
373862bcd1aSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374862bcd1aSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375862bcd1aSmrg  s/\n//g"
376e9fcaa8aSmrg
3777d2c738bSmrg# require_check_ifs_backslash
3787d2c738bSmrg# ---------------------------
3797d2c738bSmrg# Check if we can use backslash as IFS='\' separator, and set
3807d2c738bSmrg# $check_ifs_backshlash_broken to ':' or 'false'.
3817d2c738bSmrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
3827d2c738bSmrgfunc_require_check_ifs_backslash ()
3837d2c738bSmrg{
3847d2c738bSmrg  _G_save_IFS=$IFS
3857d2c738bSmrg  IFS='\'
3867d2c738bSmrg  _G_check_ifs_backshlash='a\\b'
3877d2c738bSmrg  for _G_i in $_G_check_ifs_backshlash
3887d2c738bSmrg  do
3897d2c738bSmrg  case $_G_i in
3907d2c738bSmrg  a)
3917d2c738bSmrg    check_ifs_backshlash_broken=false
3927d2c738bSmrg    ;;
3937d2c738bSmrg  '')
3947d2c738bSmrg    break
3957d2c738bSmrg    ;;
3967d2c738bSmrg  *)
3977d2c738bSmrg    check_ifs_backshlash_broken=:
3987d2c738bSmrg    break
3997d2c738bSmrg    ;;
4007d2c738bSmrg  esac
4017d2c738bSmrg  done
4027d2c738bSmrg  IFS=$_G_save_IFS
4037d2c738bSmrg  require_check_ifs_backslash=:
4047d2c738bSmrg}
4057d2c738bSmrg
406e9fcaa8aSmrg
407862bcd1aSmrg## ----------------- ##
408862bcd1aSmrg## Global variables. ##
409862bcd1aSmrg## ----------------- ##
410e9fcaa8aSmrg
411862bcd1aSmrg# Except for the global variables explicitly listed below, the following
412862bcd1aSmrg# functions in the '^func_' namespace, and the '^require_' namespace
413862bcd1aSmrg# variables initialised in the 'Resource management' section, sourcing
414862bcd1aSmrg# this file will not pollute your global namespace with anything
415862bcd1aSmrg# else. There's no portable way to scope variables in Bourne shell
416862bcd1aSmrg# though, so actually running these functions will sometimes place
417862bcd1aSmrg# results into a variable named after the function, and often use
418862bcd1aSmrg# temporary variables in the '^_G_' namespace. If you are careful to
419862bcd1aSmrg# avoid using those namespaces casually in your sourcing script, things
420862bcd1aSmrg# should continue to work as you expect. And, of course, you can freely
421862bcd1aSmrg# overwrite any of the functions or variables defined here before
422862bcd1aSmrg# calling anything to customize them.
423e9fcaa8aSmrg
424862bcd1aSmrgEXIT_SUCCESS=0
425862bcd1aSmrgEXIT_FAILURE=1
426862bcd1aSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427862bcd1aSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4282e9c7c8cSmrg
429862bcd1aSmrg# Allow overriding, eg assuming that you follow the convention of
430862bcd1aSmrg# putting '$debug_cmd' at the start of all your functions, you can get
431862bcd1aSmrg# bash to show function call trace with:
432862bcd1aSmrg#
43303ea5dc6Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434862bcd1aSmrgdebug_cmd=${debug_cmd-":"}
435862bcd1aSmrgexit_cmd=:
43688de56ccSmrg
437862bcd1aSmrg# By convention, finish your script with:
438862bcd1aSmrg#
439862bcd1aSmrg#    exit $exit_status
440862bcd1aSmrg#
441862bcd1aSmrg# so that you can set exit_status to non-zero if you want to indicate
442862bcd1aSmrg# something went wrong during execution without actually bailing out at
443862bcd1aSmrg# the point of failure.
444862bcd1aSmrgexit_status=$EXIT_SUCCESS
445e9fcaa8aSmrg
446862bcd1aSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447862bcd1aSmrg# is ksh but when the shell is invoked as "sh" and the current value of
448862bcd1aSmrg# the _XPG environment variable is not equal to 1 (one), the special
449862bcd1aSmrg# positional parameter $0, within a function call, is the name of the
450862bcd1aSmrg# function.
451862bcd1aSmrgprogpath=$0
45288de56ccSmrg
453862bcd1aSmrg# The name of this program.
454862bcd1aSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
45588de56ccSmrg
456862bcd1aSmrg# Make sure we have an absolute progpath for reexecution:
45788de56ccSmrgcase $progpath in
45888de56ccSmrg  [\\/]*|[A-Za-z]:\\*) ;;
45988de56ccSmrg  *[\\/]*)
460862bcd1aSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
46188de56ccSmrg     progdir=`cd "$progdir" && pwd`
462862bcd1aSmrg     progpath=$progdir/$progname
46388de56ccSmrg     ;;
46488de56ccSmrg  *)
465862bcd1aSmrg     _G_IFS=$IFS
466eb411b4bSmrg     IFS=${PATH_SEPARATOR-:}
46788de56ccSmrg     for progdir in $PATH; do
468862bcd1aSmrg       IFS=$_G_IFS
46988de56ccSmrg       test -x "$progdir/$progname" && break
47088de56ccSmrg     done
471862bcd1aSmrg     IFS=$_G_IFS
47288de56ccSmrg     test -n "$progdir" || progdir=`pwd`
473862bcd1aSmrg     progpath=$progdir/$progname
47488de56ccSmrg     ;;
47588de56ccSmrgesac
47688de56ccSmrg
47788de56ccSmrg
478862bcd1aSmrg## ----------------- ##
479862bcd1aSmrg## Standard options. ##
480862bcd1aSmrg## ----------------- ##
481e9fcaa8aSmrg
482862bcd1aSmrg# The following options affect the operation of the functions defined
483862bcd1aSmrg# below, and should be set appropriately depending on run-time para-
484862bcd1aSmrg# meters passed on the command line.
48588de56ccSmrg
48688de56ccSmrgopt_dry_run=false
48788de56ccSmrgopt_quiet=false
48888de56ccSmrgopt_verbose=false
48988de56ccSmrg
490862bcd1aSmrg# Categories 'all' and 'none' are always available.  Append any others
491862bcd1aSmrg# you will pass as the first argument to func_warning from your own
492862bcd1aSmrg# code.
493862bcd1aSmrgwarning_categories=
49488de56ccSmrg
495862bcd1aSmrg# By default, display warnings according to 'opt_warning_types'.  Set
496862bcd1aSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497862bcd1aSmrg# treat the next displayed warning as a fatal error.
498862bcd1aSmrgwarning_func=func_warn_and_continue
49988de56ccSmrg
500862bcd1aSmrg# Set to 'all' to display all warnings, 'none' to suppress all
501862bcd1aSmrg# warnings, or a space delimited list of some subset of
502862bcd1aSmrg# 'warning_categories' to display only the listed warnings.
503862bcd1aSmrgopt_warning_types=all
50488de56ccSmrg
505e9fcaa8aSmrg
506862bcd1aSmrg## -------------------- ##
507862bcd1aSmrg## Resource management. ##
508862bcd1aSmrg## -------------------- ##
50988de56ccSmrg
510862bcd1aSmrg# This section contains definitions for functions that each ensure a
511862bcd1aSmrg# particular resource (a file, or a non-empty configuration variable for
512862bcd1aSmrg# example) is available, and if appropriate to extract default values
513862bcd1aSmrg# from pertinent package files. Call them using their associated
514862bcd1aSmrg# 'require_*' variable to ensure that they are executed, at most, once.
515862bcd1aSmrg#
516862bcd1aSmrg# It's entirely deliberate that calling these functions can set
517862bcd1aSmrg# variables that don't obey the namespace limitations obeyed by the rest
518862bcd1aSmrg# of this file, in order that that they be as useful as possible to
519862bcd1aSmrg# callers.
52088de56ccSmrg
52188de56ccSmrg
522862bcd1aSmrg# require_term_colors
523862bcd1aSmrg# -------------------
524862bcd1aSmrg# Allow display of bold text on terminals that support it.
525862bcd1aSmrgrequire_term_colors=func_require_term_colors
526862bcd1aSmrgfunc_require_term_colors ()
52788de56ccSmrg{
528862bcd1aSmrg    $debug_cmd
529862bcd1aSmrg
530862bcd1aSmrg    test -t 1 && {
531862bcd1aSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532862bcd1aSmrg      # precedence, because most terminfo databases neglect to describe
533862bcd1aSmrg      # whether color sequences are supported.
534862bcd1aSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535862bcd1aSmrg
536862bcd1aSmrg      if test 1 = "$USE_ANSI_COLORS"; then
537862bcd1aSmrg        # Standard ANSI escape sequences
538862bcd1aSmrg        tc_reset='[0m'
539862bcd1aSmrg        tc_bold='[1m';   tc_standout='[7m'
540862bcd1aSmrg        tc_red='[31m';   tc_green='[32m'
541862bcd1aSmrg        tc_blue='[34m';  tc_cyan='[36m'
542862bcd1aSmrg      else
543862bcd1aSmrg        # Otherwise trust the terminfo database after all.
544862bcd1aSmrg        test -n "`tput sgr0 2>/dev/null`" && {
545862bcd1aSmrg          tc_reset=`tput sgr0`
546862bcd1aSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547862bcd1aSmrg          tc_standout=$tc_bold
548862bcd1aSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549862bcd1aSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550862bcd1aSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551862bcd1aSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552862bcd1aSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553862bcd1aSmrg        }
554862bcd1aSmrg      fi
555862bcd1aSmrg    }
55688de56ccSmrg
557862bcd1aSmrg    require_term_colors=:
55888de56ccSmrg}
55988de56ccSmrg
56088de56ccSmrg
561862bcd1aSmrg## ----------------- ##
562862bcd1aSmrg## Function library. ##
563862bcd1aSmrg## ----------------- ##
564862bcd1aSmrg
565862bcd1aSmrg# This section contains a variety of useful functions to call in your
566862bcd1aSmrg# scripts. Take note of the portable wrappers for features provided by
567862bcd1aSmrg# some modern shells, which will fall back to slower equivalents on
568862bcd1aSmrg# less featureful shells.
569862bcd1aSmrg
570862bcd1aSmrg
571862bcd1aSmrg# func_append VAR VALUE
572862bcd1aSmrg# ---------------------
573862bcd1aSmrg# Append VALUE onto the existing contents of VAR.
574862bcd1aSmrg
575862bcd1aSmrg  # We should try to minimise forks, especially on Windows where they are
576862bcd1aSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577862bcd1aSmrg  # being used:
578862bcd1aSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579862bcd1aSmrg    : ${_G_HAVE_ARITH_OP="yes"}
580862bcd1aSmrg    : ${_G_HAVE_XSI_OPS="yes"}
581862bcd1aSmrg    # The += operator was introduced in bash 3.1
582862bcd1aSmrg    case $BASH_VERSION in
583862bcd1aSmrg      [12].* | 3.0 | 3.0*) ;;
584862bcd1aSmrg      *)
585862bcd1aSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586862bcd1aSmrg        ;;
587862bcd1aSmrg    esac
588862bcd1aSmrg  fi
589862bcd1aSmrg
590862bcd1aSmrg  # _G_HAVE_PLUSEQ_OP
591862bcd1aSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
59207fb9b8fSmrg  # usable or anything else if it does not work.
593862bcd1aSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594862bcd1aSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595862bcd1aSmrg    && _G_HAVE_PLUSEQ_OP=yes
596862bcd1aSmrg
597862bcd1aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598862bcd1aSmrgthen
599862bcd1aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
600862bcd1aSmrg  eval 'func_append ()
601862bcd1aSmrg  {
602862bcd1aSmrg    $debug_cmd
603862bcd1aSmrg
604862bcd1aSmrg    eval "$1+=\$2"
605862bcd1aSmrg  }'
606862bcd1aSmrgelse
607862bcd1aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608862bcd1aSmrg  func_append ()
609862bcd1aSmrg  {
610862bcd1aSmrg    $debug_cmd
611862bcd1aSmrg
612862bcd1aSmrg    eval "$1=\$$1\$2"
613862bcd1aSmrg  }
614862bcd1aSmrgfi
615862bcd1aSmrg
616862bcd1aSmrg
617862bcd1aSmrg# func_append_quoted VAR VALUE
618862bcd1aSmrg# ----------------------------
619862bcd1aSmrg# Quote VALUE and append to the end of shell variable VAR, separated
620862bcd1aSmrg# by a space.
621862bcd1aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622862bcd1aSmrg  eval 'func_append_quoted ()
623862bcd1aSmrg  {
624862bcd1aSmrg    $debug_cmd
625862bcd1aSmrg
6267d2c738bSmrg    func_quote_arg pretty "$2"
6277d2c738bSmrg    eval "$1+=\\ \$func_quote_arg_result"
628862bcd1aSmrg  }'
629862bcd1aSmrgelse
630862bcd1aSmrg  func_append_quoted ()
631862bcd1aSmrg  {
632862bcd1aSmrg    $debug_cmd
633862bcd1aSmrg
6347d2c738bSmrg    func_quote_arg pretty "$2"
6357d2c738bSmrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636862bcd1aSmrg  }
637862bcd1aSmrgfi
638862bcd1aSmrg
639862bcd1aSmrg
640862bcd1aSmrg# func_append_uniq VAR VALUE
641862bcd1aSmrg# --------------------------
642862bcd1aSmrg# Append unique VALUE onto the existing contents of VAR, assuming
643862bcd1aSmrg# entries are delimited by the first character of VALUE.  For example:
644862bcd1aSmrg#
645862bcd1aSmrg#   func_append_uniq options " --another-option option-argument"
646862bcd1aSmrg#
647862bcd1aSmrg# will only append to $options if " --another-option option-argument "
648862bcd1aSmrg# is not already present somewhere in $options already (note spaces at
649862bcd1aSmrg# each end implied by leading space in second argument).
650862bcd1aSmrgfunc_append_uniq ()
651862bcd1aSmrg{
652862bcd1aSmrg    $debug_cmd
653862bcd1aSmrg
654862bcd1aSmrg    eval _G_current_value='`$ECHO $'$1'`'
655862bcd1aSmrg    _G_delim=`expr "$2" : '\(.\)'`
656862bcd1aSmrg
657862bcd1aSmrg    case $_G_delim$_G_current_value$_G_delim in
658862bcd1aSmrg      *"$2$_G_delim"*) ;;
659862bcd1aSmrg      *) func_append "$@" ;;
660862bcd1aSmrg    esac
661862bcd1aSmrg}
662862bcd1aSmrg
663862bcd1aSmrg
664862bcd1aSmrg# func_arith TERM...
665862bcd1aSmrg# ------------------
666862bcd1aSmrg# Set func_arith_result to the result of evaluating TERMs.
667862bcd1aSmrg  test -z "$_G_HAVE_ARITH_OP" \
668862bcd1aSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669862bcd1aSmrg    && _G_HAVE_ARITH_OP=yes
670862bcd1aSmrg
671862bcd1aSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
672862bcd1aSmrg  eval 'func_arith ()
673862bcd1aSmrg  {
674862bcd1aSmrg    $debug_cmd
675862bcd1aSmrg
676862bcd1aSmrg    func_arith_result=$(( $* ))
677862bcd1aSmrg  }'
678862bcd1aSmrgelse
679862bcd1aSmrg  func_arith ()
680862bcd1aSmrg  {
681862bcd1aSmrg    $debug_cmd
682862bcd1aSmrg
683862bcd1aSmrg    func_arith_result=`expr "$@"`
684862bcd1aSmrg  }
685862bcd1aSmrgfi
686862bcd1aSmrg
687862bcd1aSmrg
688862bcd1aSmrg# func_basename FILE
689862bcd1aSmrg# ------------------
690862bcd1aSmrg# Set func_basename_result to FILE with everything up to and including
691862bcd1aSmrg# the last / stripped.
692862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
693862bcd1aSmrg  # If this shell supports suffix pattern removal, then use it to avoid
694862bcd1aSmrg  # forking. Hide the definitions single quotes in case the shell chokes
695862bcd1aSmrg  # on unsupported syntax...
696862bcd1aSmrg  _b='func_basename_result=${1##*/}'
697862bcd1aSmrg  _d='case $1 in
698862bcd1aSmrg        */*) func_dirname_result=${1%/*}$2 ;;
699862bcd1aSmrg        *  ) func_dirname_result=$3        ;;
700862bcd1aSmrg      esac'
701862bcd1aSmrg
702862bcd1aSmrgelse
703862bcd1aSmrg  # ...otherwise fall back to using sed.
704862bcd1aSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705862bcd1aSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706862bcd1aSmrg      if test "X$func_dirname_result" = "X$1"; then
707862bcd1aSmrg        func_dirname_result=$3
708862bcd1aSmrg      else
709862bcd1aSmrg        func_append func_dirname_result "$2"
710862bcd1aSmrg      fi'
711862bcd1aSmrgfi
712862bcd1aSmrg
713862bcd1aSmrgeval 'func_basename ()
714862bcd1aSmrg{
715862bcd1aSmrg    $debug_cmd
716862bcd1aSmrg
717862bcd1aSmrg    '"$_b"'
718862bcd1aSmrg}'
719862bcd1aSmrg
720862bcd1aSmrg
721862bcd1aSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722862bcd1aSmrg# -------------------------------------------
723862bcd1aSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724862bcd1aSmrg# otherwise set result to NONDIR_REPLACEMENT.
725862bcd1aSmrgeval 'func_dirname ()
726862bcd1aSmrg{
727862bcd1aSmrg    $debug_cmd
728862bcd1aSmrg
729862bcd1aSmrg    '"$_d"'
730862bcd1aSmrg}'
731862bcd1aSmrg
732862bcd1aSmrg
733862bcd1aSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734862bcd1aSmrg# --------------------------------------------------------
735862bcd1aSmrg# Perform func_basename and func_dirname in a single function
736862bcd1aSmrg# call:
737862bcd1aSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738862bcd1aSmrg#             add APPEND to the result, otherwise set result
739862bcd1aSmrg#             to NONDIR_REPLACEMENT.
740862bcd1aSmrg#             value returned in "$func_dirname_result"
741862bcd1aSmrg#   basename: Compute filename of FILE.
74207fb9b8fSmrg#             value returned in "$func_basename_result"
743862bcd1aSmrg# For efficiency, we do not delegate to the functions above but instead
744862bcd1aSmrg# duplicate the functionality here.
745862bcd1aSmrgeval 'func_dirname_and_basename ()
746862bcd1aSmrg{
747862bcd1aSmrg    $debug_cmd
748862bcd1aSmrg
749862bcd1aSmrg    '"$_b"'
750862bcd1aSmrg    '"$_d"'
751862bcd1aSmrg}'
752862bcd1aSmrg
753862bcd1aSmrg
754862bcd1aSmrg# func_echo ARG...
755862bcd1aSmrg# ----------------
756862bcd1aSmrg# Echo program name prefixed message.
757862bcd1aSmrgfunc_echo ()
758862bcd1aSmrg{
759862bcd1aSmrg    $debug_cmd
760862bcd1aSmrg
761862bcd1aSmrg    _G_message=$*
762862bcd1aSmrg
763862bcd1aSmrg    func_echo_IFS=$IFS
764862bcd1aSmrg    IFS=$nl
765862bcd1aSmrg    for _G_line in $_G_message; do
766862bcd1aSmrg      IFS=$func_echo_IFS
767862bcd1aSmrg      $ECHO "$progname: $_G_line"
768862bcd1aSmrg    done
769862bcd1aSmrg    IFS=$func_echo_IFS
770862bcd1aSmrg}
771862bcd1aSmrg
772862bcd1aSmrg
773862bcd1aSmrg# func_echo_all ARG...
774862bcd1aSmrg# --------------------
775862bcd1aSmrg# Invoke $ECHO with all args, space-separated.
776862bcd1aSmrgfunc_echo_all ()
777862bcd1aSmrg{
778862bcd1aSmrg    $ECHO "$*"
779862bcd1aSmrg}
780862bcd1aSmrg
781862bcd1aSmrg
782862bcd1aSmrg# func_echo_infix_1 INFIX ARG...
783862bcd1aSmrg# ------------------------------
784862bcd1aSmrg# Echo program name, followed by INFIX on the first line, with any
785862bcd1aSmrg# additional lines not showing INFIX.
786862bcd1aSmrgfunc_echo_infix_1 ()
787862bcd1aSmrg{
788862bcd1aSmrg    $debug_cmd
789862bcd1aSmrg
790862bcd1aSmrg    $require_term_colors
791862bcd1aSmrg
792862bcd1aSmrg    _G_infix=$1; shift
793862bcd1aSmrg    _G_indent=$_G_infix
794862bcd1aSmrg    _G_prefix="$progname: $_G_infix: "
795862bcd1aSmrg    _G_message=$*
796862bcd1aSmrg
797862bcd1aSmrg    # Strip color escape sequences before counting printable length
798862bcd1aSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799862bcd1aSmrg    do
800862bcd1aSmrg      test -n "$_G_tc" && {
801862bcd1aSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802862bcd1aSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803862bcd1aSmrg      }
804862bcd1aSmrg    done
805862bcd1aSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806862bcd1aSmrg
807862bcd1aSmrg    func_echo_infix_1_IFS=$IFS
808862bcd1aSmrg    IFS=$nl
809862bcd1aSmrg    for _G_line in $_G_message; do
810862bcd1aSmrg      IFS=$func_echo_infix_1_IFS
811862bcd1aSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812862bcd1aSmrg      _G_prefix=$_G_indent
813862bcd1aSmrg    done
814862bcd1aSmrg    IFS=$func_echo_infix_1_IFS
815862bcd1aSmrg}
816862bcd1aSmrg
817862bcd1aSmrg
818862bcd1aSmrg# func_error ARG...
819862bcd1aSmrg# -----------------
820862bcd1aSmrg# Echo program name prefixed message to standard error.
821862bcd1aSmrgfunc_error ()
822862bcd1aSmrg{
823862bcd1aSmrg    $debug_cmd
824862bcd1aSmrg
825862bcd1aSmrg    $require_term_colors
826862bcd1aSmrg
827862bcd1aSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828862bcd1aSmrg}
829862bcd1aSmrg
830862bcd1aSmrg
831862bcd1aSmrg# func_fatal_error ARG...
832862bcd1aSmrg# -----------------------
833862bcd1aSmrg# Echo program name prefixed message to standard error, and exit.
834862bcd1aSmrgfunc_fatal_error ()
835862bcd1aSmrg{
836862bcd1aSmrg    $debug_cmd
837862bcd1aSmrg
838862bcd1aSmrg    func_error "$*"
839862bcd1aSmrg    exit $EXIT_FAILURE
840862bcd1aSmrg}
841862bcd1aSmrg
842862bcd1aSmrg
843862bcd1aSmrg# func_grep EXPRESSION FILENAME
844862bcd1aSmrg# -----------------------------
84588de56ccSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
84688de56ccSmrgfunc_grep ()
84788de56ccSmrg{
848862bcd1aSmrg    $debug_cmd
849862bcd1aSmrg
85088de56ccSmrg    $GREP "$1" "$2" >/dev/null 2>&1
85188de56ccSmrg}
85288de56ccSmrg
85388de56ccSmrg
854862bcd1aSmrg# func_len STRING
855862bcd1aSmrg# ---------------
856862bcd1aSmrg# Set func_len_result to the length of STRING. STRING may not
857862bcd1aSmrg# start with a hyphen.
858862bcd1aSmrg  test -z "$_G_HAVE_XSI_OPS" \
859862bcd1aSmrg    && (eval 'x=a/b/c;
860862bcd1aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861862bcd1aSmrg    && _G_HAVE_XSI_OPS=yes
862862bcd1aSmrg
863862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
864862bcd1aSmrg  eval 'func_len ()
865862bcd1aSmrg  {
866862bcd1aSmrg    $debug_cmd
867862bcd1aSmrg
868862bcd1aSmrg    func_len_result=${#1}
869862bcd1aSmrg  }'
870862bcd1aSmrgelse
871862bcd1aSmrg  func_len ()
872862bcd1aSmrg  {
873862bcd1aSmrg    $debug_cmd
874862bcd1aSmrg
875862bcd1aSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876862bcd1aSmrg  }
877862bcd1aSmrgfi
878862bcd1aSmrg
879862bcd1aSmrg
880862bcd1aSmrg# func_mkdir_p DIRECTORY-PATH
881862bcd1aSmrg# ---------------------------
88288de56ccSmrg# Make sure the entire path to DIRECTORY-PATH is available.
88388de56ccSmrgfunc_mkdir_p ()
88488de56ccSmrg{
885862bcd1aSmrg    $debug_cmd
886862bcd1aSmrg
887862bcd1aSmrg    _G_directory_path=$1
888862bcd1aSmrg    _G_dir_list=
88988de56ccSmrg
890862bcd1aSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
89188de56ccSmrg
892862bcd1aSmrg      # Protect directory names starting with '-'
893862bcd1aSmrg      case $_G_directory_path in
894862bcd1aSmrg        -*) _G_directory_path=./$_G_directory_path ;;
89588de56ccSmrg      esac
89688de56ccSmrg
89788de56ccSmrg      # While some portion of DIR does not yet exist...
898862bcd1aSmrg      while test ! -d "$_G_directory_path"; do
89988de56ccSmrg        # ...make a list in topmost first order.  Use a colon delimited
90007fb9b8fSmrg	# list in case some portion of path contains whitespace.
901862bcd1aSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
90288de56ccSmrg
90388de56ccSmrg        # If the last portion added has no slash in it, the list is done
904862bcd1aSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
90588de56ccSmrg
90688de56ccSmrg        # ...otherwise throw away the child directory and loop
907862bcd1aSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
90888de56ccSmrg      done
909862bcd1aSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
91088de56ccSmrg
911862bcd1aSmrg      func_mkdir_p_IFS=$IFS; IFS=:
912862bcd1aSmrg      for _G_dir in $_G_dir_list; do
913862bcd1aSmrg	IFS=$func_mkdir_p_IFS
914862bcd1aSmrg        # mkdir can fail with a 'File exist' error if two processes
91588de56ccSmrg        # try to create one of the directories concurrently.  Don't
91688de56ccSmrg        # stop in that case!
917862bcd1aSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
91888de56ccSmrg      done
919862bcd1aSmrg      IFS=$func_mkdir_p_IFS
92088de56ccSmrg
92188de56ccSmrg      # Bail out if we (or some other process) failed to create a directory.
922862bcd1aSmrg      test -d "$_G_directory_path" || \
923862bcd1aSmrg        func_fatal_error "Failed to create '$1'"
92488de56ccSmrg    fi
92588de56ccSmrg}
9261ab64890Smrg
9271ab64890Smrg
928862bcd1aSmrg# func_mktempdir [BASENAME]
929862bcd1aSmrg# -------------------------
9301ab64890Smrg# Make a temporary directory that won't clash with other running
9311ab64890Smrg# libtool processes, and avoids race conditions if possible.  If
932862bcd1aSmrg# given, BASENAME is the basename for that directory.
9331ab64890Smrgfunc_mktempdir ()
9341ab64890Smrg{
935862bcd1aSmrg    $debug_cmd
936862bcd1aSmrg
937862bcd1aSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
9381ab64890Smrg
939862bcd1aSmrg    if test : = "$opt_dry_run"; then
9401ab64890Smrg      # Return a directory name, but don't create it in dry-run mode
941862bcd1aSmrg      _G_tmpdir=$_G_template-$$
9421ab64890Smrg    else
9431ab64890Smrg
9441ab64890Smrg      # If mktemp works, use that first and foremost
945862bcd1aSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9461ab64890Smrg
947862bcd1aSmrg      if test ! -d "$_G_tmpdir"; then
94888de56ccSmrg        # Failing that, at least try and use $RANDOM to avoid a race
949862bcd1aSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9501ab64890Smrg
951862bcd1aSmrg        func_mktempdir_umask=`umask`
95288de56ccSmrg        umask 0077
953862bcd1aSmrg        $MKDIR "$_G_tmpdir"
954862bcd1aSmrg        umask $func_mktempdir_umask
9551ab64890Smrg      fi
9561ab64890Smrg
9571ab64890Smrg      # If we're not in dry-run mode, bomb out on failure
958862bcd1aSmrg      test -d "$_G_tmpdir" || \
959862bcd1aSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9601ab64890Smrg    fi
9611ab64890Smrg
962862bcd1aSmrg    $ECHO "$_G_tmpdir"
9631ab64890Smrg}
9641ab64890Smrg
9651ab64890Smrg
966862bcd1aSmrg# func_normal_abspath PATH
967862bcd1aSmrg# ------------------------
968862bcd1aSmrg# Remove doubled-up and trailing slashes, "." path components,
969862bcd1aSmrg# and cancel out any ".." path components in PATH after making
970862bcd1aSmrg# it an absolute path.
971862bcd1aSmrgfunc_normal_abspath ()
9721ab64890Smrg{
973862bcd1aSmrg    $debug_cmd
97488de56ccSmrg
975862bcd1aSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
976862bcd1aSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977862bcd1aSmrg    _G_pathcdr='s|^/[^/]*||'
978862bcd1aSmrg    _G_removedotparts=':dotsl
979862bcd1aSmrg		s|/\./|/|g
980862bcd1aSmrg		t dotsl
981862bcd1aSmrg		s|/\.$|/|'
982862bcd1aSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
983862bcd1aSmrg    _G_finalslash='s|/*$|/|'
984862bcd1aSmrg
985862bcd1aSmrg    # Start from root dir and reassemble the path.
986862bcd1aSmrg    func_normal_abspath_result=
987862bcd1aSmrg    func_normal_abspath_tpath=$1
988862bcd1aSmrg    func_normal_abspath_altnamespace=
989862bcd1aSmrg    case $func_normal_abspath_tpath in
990862bcd1aSmrg      "")
991862bcd1aSmrg        # Empty path, that just means $cwd.
992862bcd1aSmrg        func_stripname '' '/' "`pwd`"
993862bcd1aSmrg        func_normal_abspath_result=$func_stripname_result
994862bcd1aSmrg        return
995862bcd1aSmrg        ;;
996862bcd1aSmrg      # The next three entries are used to spot a run of precisely
997862bcd1aSmrg      # two leading slashes without using negated character classes;
998862bcd1aSmrg      # we take advantage of case's first-match behaviour.
999862bcd1aSmrg      ///*)
1000862bcd1aSmrg        # Unusual form of absolute path, do nothing.
1001862bcd1aSmrg        ;;
1002862bcd1aSmrg      //*)
1003862bcd1aSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004862bcd1aSmrg        # and for example Cygwin uses it to access remote file shares
1005862bcd1aSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006862bcd1aSmrg        func_normal_abspath_altnamespace=/
1007862bcd1aSmrg        ;;
1008862bcd1aSmrg      /*)
1009862bcd1aSmrg        # Absolute path, do nothing.
101088de56ccSmrg        ;;
101188de56ccSmrg      *)
1012862bcd1aSmrg        # Relative path, prepend $cwd.
1013862bcd1aSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014862bcd1aSmrg        ;;
10151ab64890Smrg    esac
1016862bcd1aSmrg
1017862bcd1aSmrg    # Cancel out all the simple stuff to save iterations.  We also want
1018862bcd1aSmrg    # the path to end with a slash for ease of parsing, so make sure
1019862bcd1aSmrg    # there is one (and only one) here.
1020862bcd1aSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021862bcd1aSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022862bcd1aSmrg    while :; do
1023862bcd1aSmrg      # Processed it all yet?
1024862bcd1aSmrg      if test / = "$func_normal_abspath_tpath"; then
1025862bcd1aSmrg        # If we ascended to the root using ".." the result may be empty now.
1026862bcd1aSmrg        if test -z "$func_normal_abspath_result"; then
1027862bcd1aSmrg          func_normal_abspath_result=/
1028862bcd1aSmrg        fi
1029862bcd1aSmrg        break
1030862bcd1aSmrg      fi
1031862bcd1aSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032862bcd1aSmrg          -e "$_G_pathcar"`
1033862bcd1aSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034862bcd1aSmrg          -e "$_G_pathcdr"`
1035862bcd1aSmrg      # Figure out what to do with it
1036862bcd1aSmrg      case $func_normal_abspath_tcomponent in
1037862bcd1aSmrg        "")
1038862bcd1aSmrg          # Trailing empty path component, ignore it.
1039862bcd1aSmrg          ;;
1040862bcd1aSmrg        ..)
1041862bcd1aSmrg          # Parent dir; strip last assembled component from result.
1042862bcd1aSmrg          func_dirname "$func_normal_abspath_result"
1043862bcd1aSmrg          func_normal_abspath_result=$func_dirname_result
1044862bcd1aSmrg          ;;
1045862bcd1aSmrg        *)
1046862bcd1aSmrg          # Actual path component, append it.
1047862bcd1aSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048862bcd1aSmrg          ;;
1049862bcd1aSmrg      esac
1050862bcd1aSmrg    done
1051862bcd1aSmrg    # Restore leading double-slash if one was found on entry.
1052862bcd1aSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053862bcd1aSmrg}
1054862bcd1aSmrg
1055862bcd1aSmrg
1056862bcd1aSmrg# func_notquiet ARG...
1057862bcd1aSmrg# --------------------
1058862bcd1aSmrg# Echo program name prefixed message only when not in quiet mode.
1059862bcd1aSmrgfunc_notquiet ()
1060862bcd1aSmrg{
1061862bcd1aSmrg    $debug_cmd
1062862bcd1aSmrg
1063862bcd1aSmrg    $opt_quiet || func_echo ${1+"$@"}
1064862bcd1aSmrg
1065862bcd1aSmrg    # A bug in bash halts the script if the last line of a function
1066862bcd1aSmrg    # fails when set -e is in force, so we need another command to
1067862bcd1aSmrg    # work around that:
1068862bcd1aSmrg    :
1069862bcd1aSmrg}
1070862bcd1aSmrg
1071862bcd1aSmrg
1072862bcd1aSmrg# func_relative_path SRCDIR DSTDIR
1073862bcd1aSmrg# --------------------------------
1074862bcd1aSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075862bcd1aSmrgfunc_relative_path ()
1076862bcd1aSmrg{
1077862bcd1aSmrg    $debug_cmd
1078862bcd1aSmrg
1079862bcd1aSmrg    func_relative_path_result=
1080862bcd1aSmrg    func_normal_abspath "$1"
1081862bcd1aSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082862bcd1aSmrg    func_normal_abspath "$2"
1083862bcd1aSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1084862bcd1aSmrg
1085862bcd1aSmrg    # Ascend the tree starting from libdir
1086862bcd1aSmrg    while :; do
1087862bcd1aSmrg      # check if we have found a prefix of bindir
1088862bcd1aSmrg      case $func_relative_path_tbindir in
1089862bcd1aSmrg        $func_relative_path_tlibdir)
1090862bcd1aSmrg          # found an exact match
1091862bcd1aSmrg          func_relative_path_tcancelled=
1092862bcd1aSmrg          break
1093862bcd1aSmrg          ;;
1094862bcd1aSmrg        $func_relative_path_tlibdir*)
1095862bcd1aSmrg          # found a matching prefix
1096862bcd1aSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097862bcd1aSmrg          func_relative_path_tcancelled=$func_stripname_result
1098862bcd1aSmrg          if test -z "$func_relative_path_result"; then
1099862bcd1aSmrg            func_relative_path_result=.
1100862bcd1aSmrg          fi
1101862bcd1aSmrg          break
1102862bcd1aSmrg          ;;
1103862bcd1aSmrg        *)
1104862bcd1aSmrg          func_dirname $func_relative_path_tlibdir
1105862bcd1aSmrg          func_relative_path_tlibdir=$func_dirname_result
1106862bcd1aSmrg          if test -z "$func_relative_path_tlibdir"; then
1107862bcd1aSmrg            # Have to descend all the way to the root!
1108862bcd1aSmrg            func_relative_path_result=../$func_relative_path_result
1109862bcd1aSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110862bcd1aSmrg            break
1111862bcd1aSmrg          fi
1112862bcd1aSmrg          func_relative_path_result=../$func_relative_path_result
1113862bcd1aSmrg          ;;
1114862bcd1aSmrg      esac
1115862bcd1aSmrg    done
1116862bcd1aSmrg
1117862bcd1aSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1118862bcd1aSmrg    func_stripname '' '/' "$func_relative_path_result"
1119862bcd1aSmrg    func_relative_path_result=$func_stripname_result
1120862bcd1aSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121862bcd1aSmrg    if test -n "$func_stripname_result"; then
1122862bcd1aSmrg      func_append func_relative_path_result "/$func_stripname_result"
1123862bcd1aSmrg    fi
1124862bcd1aSmrg
1125862bcd1aSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126862bcd1aSmrg    if test -n "$func_relative_path_result"; then
1127862bcd1aSmrg      func_stripname './' '' "$func_relative_path_result"
1128862bcd1aSmrg      func_relative_path_result=$func_stripname_result
1129862bcd1aSmrg    fi
1130862bcd1aSmrg
1131862bcd1aSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132862bcd1aSmrg
1133862bcd1aSmrg    :
11341ab64890Smrg}
11351ab64890Smrg
11361ab64890Smrg
11377d2c738bSmrg# func_quote_portable EVAL ARG
11387d2c738bSmrg# ----------------------------
11397d2c738bSmrg# Internal function to portably implement func_quote_arg.  Note that we still
11407d2c738bSmrg# keep attention to performance here so we as much as possible try to avoid
11417d2c738bSmrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
11427d2c738bSmrgfunc_quote_portable ()
1143862bcd1aSmrg{
1144862bcd1aSmrg    $debug_cmd
1145862bcd1aSmrg
11467d2c738bSmrg    $require_check_ifs_backslash
11477d2c738bSmrg
11487d2c738bSmrg    func_quote_portable_result=$2
11497d2c738bSmrg
11507d2c738bSmrg    # one-time-loop (easy break)
11517d2c738bSmrg    while true
11527d2c738bSmrg    do
11537d2c738bSmrg      if $1; then
11547d2c738bSmrg        func_quote_portable_result=`$ECHO "$2" | $SED \
11557d2c738bSmrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
11567d2c738bSmrg        break
115714db512dSmrg      fi
1158e9628295Smrg
11597d2c738bSmrg      # Quote for eval.
11607d2c738bSmrg      case $func_quote_portable_result in
11617d2c738bSmrg        *[\\\`\"\$]*)
11627d2c738bSmrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
11637d2c738bSmrg          # contains the shell wildcard characters.
11647d2c738bSmrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
11657d2c738bSmrg            :*|*[\[\*\?]*)
11667d2c738bSmrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
11677d2c738bSmrg                  | $SED "$sed_quote_subst"`
11687d2c738bSmrg              break
11697d2c738bSmrg              ;;
11707d2c738bSmrg          esac
11717d2c738bSmrg
11727d2c738bSmrg          func_quote_portable_old_IFS=$IFS
11737d2c738bSmrg          for _G_char in '\' '`' '"' '$'
11747d2c738bSmrg          do
11757d2c738bSmrg            # STATE($1) PREV($2) SEPARATOR($3)
11767d2c738bSmrg            set start "" ""
11777d2c738bSmrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
11787d2c738bSmrg            IFS=$_G_char
11797d2c738bSmrg            for _G_part in $func_quote_portable_result
11807d2c738bSmrg            do
11817d2c738bSmrg              case $1 in
11827d2c738bSmrg              quote)
11837d2c738bSmrg                func_append func_quote_portable_result "$3$2"
11847d2c738bSmrg                set quote "$_G_part" "\\$_G_char"
11857d2c738bSmrg                ;;
11867d2c738bSmrg              start)
11877d2c738bSmrg                set first "" ""
11887d2c738bSmrg                func_quote_portable_result=
11897d2c738bSmrg                ;;
11907d2c738bSmrg              first)
11917d2c738bSmrg                set quote "$_G_part" ""
11927d2c738bSmrg                ;;
11937d2c738bSmrg              esac
11947d2c738bSmrg            done
11957d2c738bSmrg          done
11967d2c738bSmrg          IFS=$func_quote_portable_old_IFS
1197862bcd1aSmrg          ;;
11987d2c738bSmrg        *) ;;
1199862bcd1aSmrg      esac
12007d2c738bSmrg      break
120114db512dSmrg    done
12027d2c738bSmrg
12037d2c738bSmrg    func_quote_portable_unquoted_result=$func_quote_portable_result
12047d2c738bSmrg    case $func_quote_portable_result in
12057d2c738bSmrg      # double-quote args containing shell metacharacters to delay
12067d2c738bSmrg      # word splitting, command substitution and variable expansion
12077d2c738bSmrg      # for a subsequent eval.
12087d2c738bSmrg      # many bourne shells cannot handle close brackets correctly
12097d2c738bSmrg      # in scan sets, so we specify it separately.
12107d2c738bSmrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
12117d2c738bSmrg        func_quote_portable_result=\"$func_quote_portable_result\"
12127d2c738bSmrg        ;;
12137d2c738bSmrg    esac
1214862bcd1aSmrg}
1215862bcd1aSmrg
1216862bcd1aSmrg
12177d2c738bSmrg# func_quotefast_eval ARG
12187d2c738bSmrg# -----------------------
12197d2c738bSmrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
12207d2c738bSmrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
12217d2c738bSmrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
12227d2c738bSmrg  printf -v _GL_test_printf_tilde %q '~'
12237d2c738bSmrg  if test '\~' = "$_GL_test_printf_tilde"; then
12247d2c738bSmrg    func_quotefast_eval ()
12257d2c738bSmrg    {
12267d2c738bSmrg      printf -v func_quotefast_eval_result %q "$1"
12277d2c738bSmrg    }
12287d2c738bSmrg  else
12297d2c738bSmrg    # Broken older Bash implementations.  Make those faster too if possible.
12307d2c738bSmrg    func_quotefast_eval ()
12317d2c738bSmrg    {
12327d2c738bSmrg      case $1 in
12337d2c738bSmrg        '~'*)
12347d2c738bSmrg          func_quote_portable false "$1"
12357d2c738bSmrg          func_quotefast_eval_result=$func_quote_portable_result
12367d2c738bSmrg          ;;
12377d2c738bSmrg        *)
12387d2c738bSmrg          printf -v func_quotefast_eval_result %q "$1"
12397d2c738bSmrg          ;;
12407d2c738bSmrg      esac
12417d2c738bSmrg    }
12427d2c738bSmrg  fi
12437d2c738bSmrgelse
12447d2c738bSmrg  func_quotefast_eval ()
12457d2c738bSmrg  {
12467d2c738bSmrg    func_quote_portable false "$1"
12477d2c738bSmrg    func_quotefast_eval_result=$func_quote_portable_result
12487d2c738bSmrg  }
12497d2c738bSmrgfi
1250e9628295Smrg
12517d2c738bSmrg
12527d2c738bSmrg# func_quote_arg MODEs ARG
12537d2c738bSmrg# ------------------------
12547d2c738bSmrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
12557d2c738bSmrg# specifiers listed below separated by ',' character.  This function returns two
12567d2c738bSmrg# values:
12577d2c738bSmrg#   i) func_quote_arg_result
12587d2c738bSmrg#      double-quoted (when needed), suitable for a subsequent eval
12597d2c738bSmrg#  ii) func_quote_arg_unquoted_result
12607d2c738bSmrg#      has all characters that are still active within double
12617d2c738bSmrg#      quotes backslashified.  Available only if 'unquoted' is specified.
12627d2c738bSmrg#
12637d2c738bSmrg# Available modes:
12647d2c738bSmrg# ----------------
12657d2c738bSmrg# 'eval' (default)
12667d2c738bSmrg#       - escape shell special characters
12677d2c738bSmrg# 'expand'
12687d2c738bSmrg#       - the same as 'eval';  but do not quote variable references
12697d2c738bSmrg# 'pretty'
12707d2c738bSmrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
12717d2c738bSmrg#         be used later in func_quote to get output like: 'echo "a b"' instead
12727d2c738bSmrg#         of 'echo a\ b'.  This is slower than default on some shells.
12737d2c738bSmrg# 'unquoted'
12747d2c738bSmrg#       - produce also $func_quote_arg_unquoted_result which does not contain
12757d2c738bSmrg#         wrapping double-quotes.
12767d2c738bSmrg#
12777d2c738bSmrg# Examples for 'func_quote_arg pretty,unquoted string':
12787d2c738bSmrg#
12797d2c738bSmrg#   string      | *_result              | *_unquoted_result
12807d2c738bSmrg#   ------------+-----------------------+-------------------
12817d2c738bSmrg#   "           | \"                    | \"
12827d2c738bSmrg#   a b         | "a b"                 | a b
12837d2c738bSmrg#   "a b"       | "\"a b\""             | \"a b\"
12847d2c738bSmrg#   *           | "*"                   | *
12857d2c738bSmrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
12867d2c738bSmrg#
12877d2c738bSmrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
12887d2c738bSmrg#
12897d2c738bSmrg#   string        |   *_result          |  *_unquoted_result
12907d2c738bSmrg#   --------------+---------------------+--------------------
12917d2c738bSmrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
12927d2c738bSmrgfunc_quote_arg ()
12937d2c738bSmrg{
12947d2c738bSmrg    _G_quote_expand=false
12957d2c738bSmrg    case ,$1, in
12967d2c738bSmrg      *,expand,*)
12977d2c738bSmrg        _G_quote_expand=:
12987d2c738bSmrg        ;;
129988de56ccSmrg    esac
130088de56ccSmrg
13017d2c738bSmrg    case ,$1, in
13027d2c738bSmrg      *,pretty,*|*,expand,*|*,unquoted,*)
13037d2c738bSmrg        func_quote_portable $_G_quote_expand "$2"
13047d2c738bSmrg        func_quote_arg_result=$func_quote_portable_result
13057d2c738bSmrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
13067d2c738bSmrg        ;;
13077d2c738bSmrg      *)
13087d2c738bSmrg        # Faster quote-for-eval for some shells.
13097d2c738bSmrg        func_quotefast_eval "$2"
13107d2c738bSmrg        func_quote_arg_result=$func_quotefast_eval_result
131188de56ccSmrg        ;;
131288de56ccSmrg    esac
13137d2c738bSmrg}
13147d2c738bSmrg
131588de56ccSmrg
13167d2c738bSmrg# func_quote MODEs ARGs...
13177d2c738bSmrg# ------------------------
13187d2c738bSmrg# Quote all ARGs to be evaled later and join them into single command.  See
13197d2c738bSmrg# func_quote_arg's description for more info.
13207d2c738bSmrgfunc_quote ()
13217d2c738bSmrg{
13227d2c738bSmrg    $debug_cmd
13237d2c738bSmrg    _G_func_quote_mode=$1 ; shift
13247d2c738bSmrg    func_quote_result=
13257d2c738bSmrg    while test 0 -lt $#; do
13267d2c738bSmrg      func_quote_arg "$_G_func_quote_mode" "$1"
13277d2c738bSmrg      if test -n "$func_quote_result"; then
13287d2c738bSmrg        func_append func_quote_result " $func_quote_arg_result"
13297d2c738bSmrg      else
13307d2c738bSmrg        func_append func_quote_result "$func_quote_arg_result"
13317d2c738bSmrg      fi
13327d2c738bSmrg      shift
13337d2c738bSmrg    done
1334862bcd1aSmrg}
1335862bcd1aSmrg
1336862bcd1aSmrg
1337862bcd1aSmrg# func_stripname PREFIX SUFFIX NAME
1338862bcd1aSmrg# ---------------------------------
1339862bcd1aSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340862bcd1aSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1341862bcd1aSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342862bcd1aSmrg# dot (in which case that matches only a dot).
1343862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344862bcd1aSmrg  eval 'func_stripname ()
1345862bcd1aSmrg  {
1346862bcd1aSmrg    $debug_cmd
1347862bcd1aSmrg
1348862bcd1aSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349862bcd1aSmrg    # positional parameters, so assign one to ordinary variable first.
1350862bcd1aSmrg    func_stripname_result=$3
1351862bcd1aSmrg    func_stripname_result=${func_stripname_result#"$1"}
1352862bcd1aSmrg    func_stripname_result=${func_stripname_result%"$2"}
1353862bcd1aSmrg  }'
1354862bcd1aSmrgelse
1355862bcd1aSmrg  func_stripname ()
1356862bcd1aSmrg  {
1357862bcd1aSmrg    $debug_cmd
1358862bcd1aSmrg
1359862bcd1aSmrg    case $2 in
1360862bcd1aSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361862bcd1aSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362862bcd1aSmrg    esac
1363862bcd1aSmrg  }
1364862bcd1aSmrgfi
1365862bcd1aSmrg
1366862bcd1aSmrg
1367862bcd1aSmrg# func_show_eval CMD [FAIL_EXP]
1368862bcd1aSmrg# -----------------------------
1369862bcd1aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370862bcd1aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371862bcd1aSmrg# is given, then evaluate it.
1372862bcd1aSmrgfunc_show_eval ()
1373862bcd1aSmrg{
1374862bcd1aSmrg    $debug_cmd
1375862bcd1aSmrg
1376862bcd1aSmrg    _G_cmd=$1
1377862bcd1aSmrg    _G_fail_exp=${2-':'}
1378862bcd1aSmrg
13797d2c738bSmrg    func_quote_arg pretty,expand "$_G_cmd"
13807d2c738bSmrg    eval "func_notquiet $func_quote_arg_result"
1381862bcd1aSmrg
1382862bcd1aSmrg    $opt_dry_run || {
1383862bcd1aSmrg      eval "$_G_cmd"
1384862bcd1aSmrg      _G_status=$?
1385862bcd1aSmrg      if test 0 -ne "$_G_status"; then
1386862bcd1aSmrg	eval "(exit $_G_status); $_G_fail_exp"
1387862bcd1aSmrg      fi
1388862bcd1aSmrg    }
1389862bcd1aSmrg}
1390862bcd1aSmrg
1391862bcd1aSmrg
1392862bcd1aSmrg# func_show_eval_locale CMD [FAIL_EXP]
1393862bcd1aSmrg# ------------------------------------
1394862bcd1aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395862bcd1aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396862bcd1aSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397862bcd1aSmrgfunc_show_eval_locale ()
1398862bcd1aSmrg{
1399862bcd1aSmrg    $debug_cmd
1400862bcd1aSmrg
1401862bcd1aSmrg    _G_cmd=$1
1402862bcd1aSmrg    _G_fail_exp=${2-':'}
1403862bcd1aSmrg
1404862bcd1aSmrg    $opt_quiet || {
14057d2c738bSmrg      func_quote_arg expand,pretty "$_G_cmd"
14067d2c738bSmrg      eval "func_echo $func_quote_arg_result"
1407862bcd1aSmrg    }
1408862bcd1aSmrg
1409862bcd1aSmrg    $opt_dry_run || {
1410862bcd1aSmrg      eval "$_G_user_locale
1411862bcd1aSmrg	    $_G_cmd"
1412862bcd1aSmrg      _G_status=$?
1413862bcd1aSmrg      eval "$_G_safe_locale"
1414862bcd1aSmrg      if test 0 -ne "$_G_status"; then
1415862bcd1aSmrg	eval "(exit $_G_status); $_G_fail_exp"
1416862bcd1aSmrg      fi
1417862bcd1aSmrg    }
1418862bcd1aSmrg}
1419862bcd1aSmrg
1420862bcd1aSmrg
1421862bcd1aSmrg# func_tr_sh
1422862bcd1aSmrg# ----------
1423862bcd1aSmrg# Turn $1 into a string suitable for a shell variable name.
1424862bcd1aSmrg# Result is stored in $func_tr_sh_result.  All characters
1425862bcd1aSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426862bcd1aSmrg# if $1 begins with a digit, a '_' is prepended as well.
1427862bcd1aSmrgfunc_tr_sh ()
1428862bcd1aSmrg{
1429862bcd1aSmrg    $debug_cmd
1430862bcd1aSmrg
1431862bcd1aSmrg    case $1 in
1432862bcd1aSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433862bcd1aSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434862bcd1aSmrg      ;;
1435862bcd1aSmrg    * )
1436862bcd1aSmrg      func_tr_sh_result=$1
1437862bcd1aSmrg      ;;
1438862bcd1aSmrg    esac
1439862bcd1aSmrg}
1440862bcd1aSmrg
1441862bcd1aSmrg
1442862bcd1aSmrg# func_verbose ARG...
1443862bcd1aSmrg# -------------------
1444862bcd1aSmrg# Echo program name prefixed message in verbose mode only.
1445862bcd1aSmrgfunc_verbose ()
1446862bcd1aSmrg{
1447862bcd1aSmrg    $debug_cmd
1448862bcd1aSmrg
1449862bcd1aSmrg    $opt_verbose && func_echo "$*"
1450862bcd1aSmrg
1451862bcd1aSmrg    :
1452862bcd1aSmrg}
1453862bcd1aSmrg
1454862bcd1aSmrg
1455862bcd1aSmrg# func_warn_and_continue ARG...
1456862bcd1aSmrg# -----------------------------
1457862bcd1aSmrg# Echo program name prefixed warning message to standard error.
1458862bcd1aSmrgfunc_warn_and_continue ()
1459862bcd1aSmrg{
1460862bcd1aSmrg    $debug_cmd
1461862bcd1aSmrg
1462862bcd1aSmrg    $require_term_colors
1463862bcd1aSmrg
1464862bcd1aSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465862bcd1aSmrg}
1466862bcd1aSmrg
1467862bcd1aSmrg
1468862bcd1aSmrg# func_warning CATEGORY ARG...
1469862bcd1aSmrg# ----------------------------
1470862bcd1aSmrg# Echo program name prefixed warning message to standard error. Warning
1471862bcd1aSmrg# messages can be filtered according to CATEGORY, where this function
1472862bcd1aSmrg# elides messages where CATEGORY is not listed in the global variable
1473862bcd1aSmrg# 'opt_warning_types'.
1474862bcd1aSmrgfunc_warning ()
1475862bcd1aSmrg{
1476862bcd1aSmrg    $debug_cmd
1477862bcd1aSmrg
1478862bcd1aSmrg    # CATEGORY must be in the warning_categories list!
1479862bcd1aSmrg    case " $warning_categories " in
1480862bcd1aSmrg      *" $1 "*) ;;
1481862bcd1aSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1482862bcd1aSmrg    esac
1483862bcd1aSmrg
1484862bcd1aSmrg    _G_category=$1
1485862bcd1aSmrg    shift
1486862bcd1aSmrg
1487862bcd1aSmrg    case " $opt_warning_types " in
1488862bcd1aSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489862bcd1aSmrg    esac
14901ab64890Smrg}
14911ab64890Smrg
14921ab64890Smrg
1493862bcd1aSmrg# func_sort_ver VER1 VER2
1494862bcd1aSmrg# -----------------------
1495862bcd1aSmrg# 'sort -V' is not generally available.
1496862bcd1aSmrg# Note this deviates from the version comparison in automake
1497862bcd1aSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498862bcd1aSmrg# but this should suffice as we won't be specifying old
1499862bcd1aSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1500862bcd1aSmrg# If we did want full compatibility then we should probably
1501862bcd1aSmrg# use m4_version_compare from autoconf.
1502862bcd1aSmrgfunc_sort_ver ()
1503862bcd1aSmrg{
1504862bcd1aSmrg    $debug_cmd
1505862bcd1aSmrg
1506862bcd1aSmrg    printf '%s\n%s\n' "$1" "$2" \
1507862bcd1aSmrg      | 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
1508862bcd1aSmrg}
1509862bcd1aSmrg
1510862bcd1aSmrg# func_lt_ver PREV CURR
1511862bcd1aSmrg# ---------------------
1512862bcd1aSmrg# Return true if PREV and CURR are in the correct order according to
1513862bcd1aSmrg# func_sort_ver, otherwise false.  Use it like this:
1514862bcd1aSmrg#
1515862bcd1aSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516862bcd1aSmrgfunc_lt_ver ()
1517862bcd1aSmrg{
1518862bcd1aSmrg    $debug_cmd
1519862bcd1aSmrg
1520862bcd1aSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521862bcd1aSmrg}
1522862bcd1aSmrg
1523862bcd1aSmrg
1524862bcd1aSmrg# Local variables:
1525862bcd1aSmrg# mode: shell-script
1526862bcd1aSmrg# sh-indentation: 2
1527862bcd1aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528862bcd1aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529862bcd1aSmrg# time-stamp-time-zone: "UTC"
1530862bcd1aSmrg# End:
1531862bcd1aSmrg#! /bin/sh
1532862bcd1aSmrg
1533862bcd1aSmrg# A portable, pluggable option parser for Bourne shell.
1534862bcd1aSmrg# Written by Gary V. Vaughan, 2010
1535862bcd1aSmrg
15367d2c738bSmrg# This is free software.  There is NO warranty; not even for
15377d2c738bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15387d2c738bSmrg#
153907fb9b8fSmrg# Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors
15407d2c738bSmrg#
15417d2c738bSmrg# This file is dual licensed under the terms of the MIT license
154207fb9b8fSmrg# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
154307fb9b8fSmrg# <https://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
15447d2c738bSmrg# these licenses when using or redistributing this software or any of
15457d2c738bSmrg# the files within it.  See the URLs above, or the file `LICENSE`
15467d2c738bSmrg# included in the Bootstrap distribution for the full license texts.
154714db512dSmrg
15487d2c738bSmrg# Please report bugs or propose patches to:
15497d2c738bSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
155014db512dSmrg
15517d2c738bSmrg# Set a version string for this script.
15527d2c738bSmrgscriptversion=2019-02-19.15; # UTC
1553862bcd1aSmrg
1554862bcd1aSmrg
1555862bcd1aSmrg## ------ ##
1556862bcd1aSmrg## Usage. ##
1557862bcd1aSmrg## ------ ##
1558862bcd1aSmrg
1559862bcd1aSmrg# This file is a library for parsing options in your shell scripts along
1560862bcd1aSmrg# with assorted other useful supporting features that you can make use
1561862bcd1aSmrg# of too.
1562862bcd1aSmrg#
1563862bcd1aSmrg# For the simplest scripts you might need only:
1564862bcd1aSmrg#
1565862bcd1aSmrg#   #!/bin/sh
1566862bcd1aSmrg#   . relative/path/to/funclib.sh
1567862bcd1aSmrg#   . relative/path/to/options-parser
1568862bcd1aSmrg#   scriptversion=1.0
1569862bcd1aSmrg#   func_options ${1+"$@"}
1570862bcd1aSmrg#   eval set dummy "$func_options_result"; shift
1571862bcd1aSmrg#   ...rest of your script...
1572862bcd1aSmrg#
1573862bcd1aSmrg# In order for the '--version' option to work, you will need to have a
1574862bcd1aSmrg# suitably formatted comment like the one at the top of this file
15757d2c738bSmrg# starting with '# Written by ' and ending with '# Copyright'.
1576862bcd1aSmrg#
1577862bcd1aSmrg# For '-h' and '--help' to work, you will also need a one line
1578862bcd1aSmrg# description of your script's purpose in a comment directly above the
1579862bcd1aSmrg# '# Written by ' line, like the one at the top of this file.
1580862bcd1aSmrg#
1581862bcd1aSmrg# The default options also support '--debug', which will turn on shell
1582862bcd1aSmrg# execution tracing (see the comment above debug_cmd below for another
1583862bcd1aSmrg# use), and '--verbose' and the func_verbose function to allow your script
1584862bcd1aSmrg# to display verbose messages only when your user has specified
1585862bcd1aSmrg# '--verbose'.
1586862bcd1aSmrg#
15877d2c738bSmrg# After sourcing this file, you can plug in processing for additional
1588862bcd1aSmrg# options by amending the variables from the 'Configuration' section
1589862bcd1aSmrg# below, and following the instructions in the 'Option parsing'
1590862bcd1aSmrg# section further down.
1591862bcd1aSmrg
1592862bcd1aSmrg## -------------- ##
1593862bcd1aSmrg## Configuration. ##
1594862bcd1aSmrg## -------------- ##
1595862bcd1aSmrg
1596862bcd1aSmrg# You should override these variables in your script after sourcing this
1597862bcd1aSmrg# file so that they reflect the customisations you have added to the
1598862bcd1aSmrg# option parser.
1599862bcd1aSmrg
1600862bcd1aSmrg# The usage line for option parsing errors and the start of '-h' and
1601862bcd1aSmrg# '--help' output messages. You can embed shell variables for delayed
1602862bcd1aSmrg# expansion at the time the message is displayed, but you will need to
1603862bcd1aSmrg# quote other shell meta-characters carefully to prevent them being
1604862bcd1aSmrg# expanded when the contents are evaled.
1605862bcd1aSmrgusage='$progpath [OPTION]...'
1606862bcd1aSmrg
1607862bcd1aSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1608862bcd1aSmrg# override it after sourcing this library to reflect the full set of
1609862bcd1aSmrg# options your script accepts.
1610862bcd1aSmrgusage_message="\
1611862bcd1aSmrg       --debug        enable verbose shell tracing
1612862bcd1aSmrg   -W, --warnings=CATEGORY
1613862bcd1aSmrg                      report the warnings falling in CATEGORY [all]
1614862bcd1aSmrg   -v, --verbose      verbosely report processing
1615862bcd1aSmrg       --version      print version information and exit
1616862bcd1aSmrg   -h, --help         print short or long help message and exit
1617862bcd1aSmrg"
1618862bcd1aSmrg
1619862bcd1aSmrg# Additional text appended to 'usage_message' in response to '--help'.
1620862bcd1aSmrglong_help_message="
1621862bcd1aSmrgWarning categories include:
1622862bcd1aSmrg       'all'          show all warnings
1623862bcd1aSmrg       'none'         turn off all the warnings
1624862bcd1aSmrg       'error'        warnings are treated as fatal errors"
1625862bcd1aSmrg
1626862bcd1aSmrg# Help message printed before fatal option parsing errors.
1627862bcd1aSmrgfatal_help="Try '\$progname --help' for more information."
1628862bcd1aSmrg
1629862bcd1aSmrg
1630862bcd1aSmrg
1631862bcd1aSmrg## ------------------------- ##
1632862bcd1aSmrg## Hook function management. ##
1633862bcd1aSmrg## ------------------------- ##
1634862bcd1aSmrg
1635862bcd1aSmrg# This section contains functions for adding, removing, and running hooks
16367d2c738bSmrg# in the main code.  A hook is just a list of function names that can be
16377d2c738bSmrg# run in order later on.
1638862bcd1aSmrg
1639862bcd1aSmrg# func_hookable FUNC_NAME
1640862bcd1aSmrg# -----------------------
1641862bcd1aSmrg# Declare that FUNC_NAME will run hooks added with
1642862bcd1aSmrg# 'func_add_hook FUNC_NAME ...'.
1643862bcd1aSmrgfunc_hookable ()
1644862bcd1aSmrg{
1645862bcd1aSmrg    $debug_cmd
1646862bcd1aSmrg
1647862bcd1aSmrg    func_append hookable_fns " $1"
1648862bcd1aSmrg}
1649862bcd1aSmrg
1650862bcd1aSmrg
1651862bcd1aSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1652862bcd1aSmrg# ---------------------------------
1653862bcd1aSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654862bcd1aSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1655862bcd1aSmrgfunc_add_hook ()
1656862bcd1aSmrg{
1657862bcd1aSmrg    $debug_cmd
1658862bcd1aSmrg
1659862bcd1aSmrg    case " $hookable_fns " in
1660862bcd1aSmrg      *" $1 "*) ;;
1661862bcd1aSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662862bcd1aSmrg    esac
1663862bcd1aSmrg
1664862bcd1aSmrg    eval func_append ${1}_hooks '" $2"'
1665862bcd1aSmrg}
1666862bcd1aSmrg
1667862bcd1aSmrg
1668862bcd1aSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669862bcd1aSmrg# ------------------------------------
16707d2c738bSmrg# Remove HOOK_FUNC from the list of hook functions to be called by
16717d2c738bSmrg# FUNC_NAME.
1672862bcd1aSmrgfunc_remove_hook ()
1673862bcd1aSmrg{
1674862bcd1aSmrg    $debug_cmd
1675862bcd1aSmrg
1676862bcd1aSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677862bcd1aSmrg}
1678862bcd1aSmrg
1679862bcd1aSmrg
16807d2c738bSmrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
16817d2c738bSmrg# ---------------------------------------------
16827d2c738bSmrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
16837d2c738bSmrg# *_result variable of FUNC_NAME_B.
16847d2c738bSmrgfunc_propagate_result ()
16857d2c738bSmrg{
16867d2c738bSmrg    $debug_cmd
16877d2c738bSmrg
16887d2c738bSmrg    func_propagate_result_result=:
16897d2c738bSmrg    if eval "test \"\${${1}_result+set}\" = set"
16907d2c738bSmrg    then
16917d2c738bSmrg      eval "${2}_result=\$${1}_result"
16927d2c738bSmrg    else
16937d2c738bSmrg      func_propagate_result_result=false
16947d2c738bSmrg    fi
16957d2c738bSmrg}
16967d2c738bSmrg
16977d2c738bSmrg
1698862bcd1aSmrg# func_run_hooks FUNC_NAME [ARG]...
1699862bcd1aSmrg# ---------------------------------
1700862bcd1aSmrg# Run all hook functions registered to FUNC_NAME.
17017d2c738bSmrg# It's assumed that the list of hook functions contains nothing more
1702862bcd1aSmrg# than a whitespace-delimited list of legal shell function names, and
1703862bcd1aSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1704862bcd1aSmrg# whitespace.
1705862bcd1aSmrgfunc_run_hooks ()
1706862bcd1aSmrg{
1707862bcd1aSmrg    $debug_cmd
1708862bcd1aSmrg
1709862bcd1aSmrg    case " $hookable_fns " in
1710862bcd1aSmrg      *" $1 "*) ;;
17117d2c738bSmrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712862bcd1aSmrg    esac
1713862bcd1aSmrg
1714862bcd1aSmrg    eval _G_hook_fns=\$$1_hooks; shift
1715862bcd1aSmrg
1716862bcd1aSmrg    for _G_hook in $_G_hook_fns; do
17177d2c738bSmrg      func_unset "${_G_hook}_result"
17187d2c738bSmrg      eval $_G_hook '${1+"$@"}'
17197d2c738bSmrg      func_propagate_result $_G_hook func_run_hooks
17207d2c738bSmrg      if $func_propagate_result_result; then
17217d2c738bSmrg        eval set dummy "$func_run_hooks_result"; shift
17227d2c738bSmrg      fi
1723862bcd1aSmrg    done
1724862bcd1aSmrg}
1725862bcd1aSmrg
1726862bcd1aSmrg
1727862bcd1aSmrg
1728862bcd1aSmrg## --------------- ##
1729862bcd1aSmrg## Option parsing. ##
1730862bcd1aSmrg## --------------- ##
1731862bcd1aSmrg
1732862bcd1aSmrg# In order to add your own option parsing hooks, you must accept the
17337d2c738bSmrg# full positional parameter list from your hook function.  You may remove
17347d2c738bSmrg# or edit any options that you action, and then pass back the remaining
17357d2c738bSmrg# unprocessed options in '<hooked_function_name>_result', escaped
17367d2c738bSmrg# suitably for 'eval'.
17377d2c738bSmrg#
17387d2c738bSmrg# The '<hooked_function_name>_result' variable is automatically unset
17397d2c738bSmrg# before your hook gets called; for best performance, only set the
17407d2c738bSmrg# *_result variable when necessary (i.e. don't call the 'func_quote'
17417d2c738bSmrg# function unnecessarily because it can be an expensive operation on some
17427d2c738bSmrg# machines).
17437d2c738bSmrg#
17447d2c738bSmrg# Like this:
1745862bcd1aSmrg#
1746862bcd1aSmrg#    my_options_prep ()
1747862bcd1aSmrg#    {
1748862bcd1aSmrg#        $debug_cmd
1749862bcd1aSmrg#
1750862bcd1aSmrg#        # Extend the existing usage message.
1751862bcd1aSmrg#        usage_message=$usage_message'
1752862bcd1aSmrg#      -s, --silent       don'\''t print informational messages
1753862bcd1aSmrg#    '
17547d2c738bSmrg#        # No change in '$@' (ignored completely by this hook).  Leave
17557d2c738bSmrg#        # my_options_prep_result variable intact.
1756862bcd1aSmrg#    }
1757862bcd1aSmrg#    func_add_hook func_options_prep my_options_prep
1758862bcd1aSmrg#
1759862bcd1aSmrg#
1760862bcd1aSmrg#    my_silent_option ()
1761862bcd1aSmrg#    {
1762862bcd1aSmrg#        $debug_cmd
1763862bcd1aSmrg#
17647d2c738bSmrg#        args_changed=false
17657d2c738bSmrg#
17667d2c738bSmrg#        # Note that, for efficiency, we parse as many options as we can
1767862bcd1aSmrg#        # recognise in a loop before passing the remainder back to the
1768862bcd1aSmrg#        # caller on the first unrecognised argument we encounter.
1769862bcd1aSmrg#        while test $# -gt 0; do
1770862bcd1aSmrg#          opt=$1; shift
1771862bcd1aSmrg#          case $opt in
17727d2c738bSmrg#            --silent|-s) opt_silent=:
17737d2c738bSmrg#                         args_changed=:
17747d2c738bSmrg#                         ;;
1775862bcd1aSmrg#            # Separate non-argument short options:
1776862bcd1aSmrg#            -s*)         func_split_short_opt "$_G_opt"
1777862bcd1aSmrg#                         set dummy "$func_split_short_opt_name" \
1778862bcd1aSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779862bcd1aSmrg#                         shift
17807d2c738bSmrg#                         args_changed=:
1781862bcd1aSmrg#                         ;;
17827d2c738bSmrg#            *)           # Make sure the first unrecognised option "$_G_opt"
17837d2c738bSmrg#                         # is added back to "$@" in case we need it later,
17847d2c738bSmrg#                         # if $args_changed was set to 'true'.
17857d2c738bSmrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786862bcd1aSmrg#          esac
1787862bcd1aSmrg#        done
1788862bcd1aSmrg#
17897d2c738bSmrg#        # Only call 'func_quote' here if we processed at least one argument.
17907d2c738bSmrg#        if $args_changed; then
17917d2c738bSmrg#          func_quote eval ${1+"$@"}
17927d2c738bSmrg#          my_silent_option_result=$func_quote_result
17937d2c738bSmrg#        fi
1794862bcd1aSmrg#    }
1795862bcd1aSmrg#    func_add_hook func_parse_options my_silent_option
1796862bcd1aSmrg#
1797862bcd1aSmrg#
1798862bcd1aSmrg#    my_option_validation ()
1799862bcd1aSmrg#    {
1800862bcd1aSmrg#        $debug_cmd
1801862bcd1aSmrg#
1802862bcd1aSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803862bcd1aSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1804862bcd1aSmrg#    }
1805862bcd1aSmrg#    func_add_hook func_validate_options my_option_validation
1806862bcd1aSmrg#
18077d2c738bSmrg# You'll also need to manually amend $usage_message to reflect the extra
1808862bcd1aSmrg# options you parse.  It's preferable to append if you can, so that
1809862bcd1aSmrg# multiple option parsing hooks can be added safely.
1810862bcd1aSmrg
1811862bcd1aSmrg
18127d2c738bSmrg# func_options_finish [ARG]...
18137d2c738bSmrg# ----------------------------
18147d2c738bSmrg# Finishing the option parse loop (call 'func_options' hooks ATM).
18157d2c738bSmrgfunc_options_finish ()
18167d2c738bSmrg{
18177d2c738bSmrg    $debug_cmd
18187d2c738bSmrg
18197d2c738bSmrg    func_run_hooks func_options ${1+"$@"}
18207d2c738bSmrg    func_propagate_result func_run_hooks func_options_finish
18217d2c738bSmrg}
18227d2c738bSmrg
18237d2c738bSmrg
1824862bcd1aSmrg# func_options [ARG]...
1825862bcd1aSmrg# ---------------------
1826862bcd1aSmrg# All the functions called inside func_options are hookable. See the
1827862bcd1aSmrg# individual implementations for details.
1828862bcd1aSmrgfunc_hookable func_options
1829862bcd1aSmrgfunc_options ()
18301ab64890Smrg{
1831862bcd1aSmrg    $debug_cmd
18322e9c7c8cSmrg
18337d2c738bSmrg    _G_options_quoted=false
1834862bcd1aSmrg
18357d2c738bSmrg    for my_func in options_prep parse_options validate_options options_finish
18367d2c738bSmrg    do
18377d2c738bSmrg      func_unset func_${my_func}_result
18387d2c738bSmrg      func_unset func_run_hooks_result
18397d2c738bSmrg      eval func_$my_func '${1+"$@"}'
18407d2c738bSmrg      func_propagate_result func_$my_func func_options
18417d2c738bSmrg      if $func_propagate_result_result; then
18427d2c738bSmrg        eval set dummy "$func_options_result"; shift
18437d2c738bSmrg        _G_options_quoted=:
18447d2c738bSmrg      fi
18457d2c738bSmrg    done
1846d4a3aaf4Smrg
18477d2c738bSmrg    $_G_options_quoted || {
18487d2c738bSmrg      # As we (func_options) are top-level options-parser function and
18497d2c738bSmrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
18507d2c738bSmrg      # caller.
18517d2c738bSmrg      func_quote eval ${1+"$@"}
18527d2c738bSmrg      func_options_result=$func_quote_result
18537d2c738bSmrg    }
18541ab64890Smrg}
18551ab64890Smrg
185688de56ccSmrg
1857862bcd1aSmrg# func_options_prep [ARG]...
1858862bcd1aSmrg# --------------------------
1859862bcd1aSmrg# All initialisations required before starting the option parse loop.
1860862bcd1aSmrg# Note that when calling hook functions, we pass through the list of
1861862bcd1aSmrg# positional parameters.  If a hook function modifies that list, and
18627d2c738bSmrg# needs to propagate that back to rest of this script, then the complete
18637d2c738bSmrg# modified list must be put in 'func_run_hooks_result' before returning.
1864862bcd1aSmrgfunc_hookable func_options_prep
1865862bcd1aSmrgfunc_options_prep ()
18661ab64890Smrg{
1867862bcd1aSmrg    $debug_cmd
186888de56ccSmrg
1869862bcd1aSmrg    # Option defaults:
1870862bcd1aSmrg    opt_verbose=false
1871862bcd1aSmrg    opt_warning_types=
187288de56ccSmrg
187303ea5dc6Smrg    func_run_hooks func_options_prep ${1+"$@"}
18747d2c738bSmrg    func_propagate_result func_run_hooks func_options_prep
187588de56ccSmrg}
18761ab64890Smrg
1877862bcd1aSmrg
1878862bcd1aSmrg# func_parse_options [ARG]...
1879862bcd1aSmrg# ---------------------------
1880862bcd1aSmrg# The main option parsing loop.
1881862bcd1aSmrgfunc_hookable func_parse_options
1882862bcd1aSmrgfunc_parse_options ()
1883e9fcaa8aSmrg{
1884862bcd1aSmrg    $debug_cmd
1885862bcd1aSmrg
18867d2c738bSmrg    _G_parse_options_requote=false
1887862bcd1aSmrg    # this just eases exit handling
1888862bcd1aSmrg    while test $# -gt 0; do
1889862bcd1aSmrg      # Defer to hook functions for initial option parsing, so they
1890862bcd1aSmrg      # get priority in the event of reusing an option name.
189103ea5dc6Smrg      func_run_hooks func_parse_options ${1+"$@"}
18927d2c738bSmrg      func_propagate_result func_run_hooks func_parse_options
18937d2c738bSmrg      if $func_propagate_result_result; then
18947d2c738bSmrg        eval set dummy "$func_parse_options_result"; shift
18957d2c738bSmrg        # Even though we may have changed "$@", we passed the "$@" array
18967d2c738bSmrg        # down into the hook and it quoted it for us (because we are in
18977d2c738bSmrg        # this if-branch).  No need to quote it again.
18987d2c738bSmrg        _G_parse_options_requote=false
18997d2c738bSmrg      fi
1900862bcd1aSmrg
1901862bcd1aSmrg      # Break out of the loop if we already parsed every option.
1902862bcd1aSmrg      test $# -gt 0 || break
1903862bcd1aSmrg
19047d2c738bSmrg      # We expect that one of the options parsed in this function matches
19057d2c738bSmrg      # and thus we remove _G_opt from "$@" and need to re-quote.
19067d2c738bSmrg      _G_match_parse_options=:
1907862bcd1aSmrg      _G_opt=$1
1908862bcd1aSmrg      shift
1909862bcd1aSmrg      case $_G_opt in
1910862bcd1aSmrg        --debug|-x)   debug_cmd='set -x'
19117d2c738bSmrg                      func_echo "enabling shell trace mode" >&2
1912862bcd1aSmrg                      $debug_cmd
1913862bcd1aSmrg                      ;;
1914862bcd1aSmrg
1915862bcd1aSmrg        --no-warnings|--no-warning|--no-warn)
1916862bcd1aSmrg                      set dummy --warnings none ${1+"$@"}
1917862bcd1aSmrg                      shift
1918862bcd1aSmrg		      ;;
1919862bcd1aSmrg
1920862bcd1aSmrg        --warnings|--warning|-W)
19217d2c738bSmrg                      if test $# = 0 && func_missing_arg $_G_opt; then
19227d2c738bSmrg                        _G_parse_options_requote=:
19237d2c738bSmrg                        break
19247d2c738bSmrg                      fi
1925862bcd1aSmrg                      case " $warning_categories $1" in
1926862bcd1aSmrg                        *" $1 "*)
1927862bcd1aSmrg                          # trailing space prevents matching last $1 above
1928862bcd1aSmrg                          func_append_uniq opt_warning_types " $1"
1929862bcd1aSmrg                          ;;
1930862bcd1aSmrg                        *all)
1931862bcd1aSmrg                          opt_warning_types=$warning_categories
1932862bcd1aSmrg                          ;;
1933862bcd1aSmrg                        *none)
1934862bcd1aSmrg                          opt_warning_types=none
1935862bcd1aSmrg                          warning_func=:
1936862bcd1aSmrg                          ;;
1937862bcd1aSmrg                        *error)
1938862bcd1aSmrg                          opt_warning_types=$warning_categories
1939862bcd1aSmrg                          warning_func=func_fatal_error
1940862bcd1aSmrg                          ;;
1941862bcd1aSmrg                        *)
1942862bcd1aSmrg                          func_fatal_error \
1943862bcd1aSmrg                             "unsupported warning category: '$1'"
1944862bcd1aSmrg                          ;;
1945862bcd1aSmrg                      esac
1946862bcd1aSmrg                      shift
1947862bcd1aSmrg                      ;;
1948862bcd1aSmrg
1949862bcd1aSmrg        --verbose|-v) opt_verbose=: ;;
1950862bcd1aSmrg        --version)    func_version ;;
1951862bcd1aSmrg        -\?|-h)       func_usage ;;
1952862bcd1aSmrg        --help)       func_help ;;
1953862bcd1aSmrg
1954862bcd1aSmrg	# Separate optargs to long options (plugins may need this):
1955862bcd1aSmrg	--*=*)        func_split_equals "$_G_opt"
1956862bcd1aSmrg	              set dummy "$func_split_equals_lhs" \
1957862bcd1aSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1958862bcd1aSmrg                      shift
1959862bcd1aSmrg                      ;;
1960862bcd1aSmrg
1961862bcd1aSmrg       # Separate optargs to short options:
1962862bcd1aSmrg        -W*)
1963862bcd1aSmrg                      func_split_short_opt "$_G_opt"
1964862bcd1aSmrg                      set dummy "$func_split_short_opt_name" \
1965862bcd1aSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966862bcd1aSmrg                      shift
1967862bcd1aSmrg                      ;;
1968862bcd1aSmrg
1969862bcd1aSmrg        # Separate non-argument short options:
1970862bcd1aSmrg        -\?*|-h*|-v*|-x*)
1971862bcd1aSmrg                      func_split_short_opt "$_G_opt"
1972862bcd1aSmrg                      set dummy "$func_split_short_opt_name" \
1973862bcd1aSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974862bcd1aSmrg                      shift
1975862bcd1aSmrg                      ;;
1976862bcd1aSmrg
19777d2c738bSmrg        --)           _G_parse_options_requote=: ; break ;;
1978862bcd1aSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
19797d2c738bSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
19807d2c738bSmrg                      _G_match_parse_options=false
19817d2c738bSmrg                      break
19827d2c738bSmrg                      ;;
1983862bcd1aSmrg      esac
19847d2c738bSmrg
19857d2c738bSmrg      if $_G_match_parse_options; then
19867d2c738bSmrg        _G_parse_options_requote=:
19877d2c738bSmrg      fi
1988862bcd1aSmrg    done
1989862bcd1aSmrg
19907d2c738bSmrg    if $_G_parse_options_requote; then
19917d2c738bSmrg      # save modified positional parameters for caller
19927d2c738bSmrg      func_quote eval ${1+"$@"}
19937d2c738bSmrg      func_parse_options_result=$func_quote_result
19947d2c738bSmrg    fi
1995e9fcaa8aSmrg}
199688de56ccSmrg
199788de56ccSmrg
1998862bcd1aSmrg# func_validate_options [ARG]...
1999862bcd1aSmrg# ------------------------------
2000862bcd1aSmrg# Perform any sanity checks on option settings and/or unconsumed
2001862bcd1aSmrg# arguments.
2002862bcd1aSmrgfunc_hookable func_validate_options
2003862bcd1aSmrgfunc_validate_options ()
200488de56ccSmrg{
2005862bcd1aSmrg    $debug_cmd
2006e9fcaa8aSmrg
2007862bcd1aSmrg    # Display all warnings if -W was not given.
2008862bcd1aSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009862bcd1aSmrg
201003ea5dc6Smrg    func_run_hooks func_validate_options ${1+"$@"}
20117d2c738bSmrg    func_propagate_result func_run_hooks func_validate_options
2012862bcd1aSmrg
2013862bcd1aSmrg    # Bail if the options were screwed!
2014862bcd1aSmrg    $exit_cmd $EXIT_FAILURE
201588de56ccSmrg}
201688de56ccSmrg
2017862bcd1aSmrg
2018862bcd1aSmrg
2019862bcd1aSmrg## ----------------- ##
2020862bcd1aSmrg## Helper functions. ##
2021862bcd1aSmrg## ----------------- ##
2022862bcd1aSmrg
2023862bcd1aSmrg# This section contains the helper functions used by the rest of the
2024862bcd1aSmrg# hookable option parser framework in ascii-betical order.
2025862bcd1aSmrg
2026862bcd1aSmrg
2027862bcd1aSmrg# func_fatal_help ARG...
2028862bcd1aSmrg# ----------------------
2029862bcd1aSmrg# Echo program name prefixed message to standard error, followed by
2030862bcd1aSmrg# a help hint, and exit.
2031862bcd1aSmrgfunc_fatal_help ()
203288de56ccSmrg{
2033862bcd1aSmrg    $debug_cmd
2034e9fcaa8aSmrg
2035862bcd1aSmrg    eval \$ECHO \""Usage: $usage"\"
2036862bcd1aSmrg    eval \$ECHO \""$fatal_help"\"
2037862bcd1aSmrg    func_error ${1+"$@"}
2038862bcd1aSmrg    exit $EXIT_FAILURE
203988de56ccSmrg}
204088de56ccSmrg
2041862bcd1aSmrg
2042862bcd1aSmrg# func_help
2043862bcd1aSmrg# ---------
2044862bcd1aSmrg# Echo long help message to standard output and exit.
204588de56ccSmrgfunc_help ()
204688de56ccSmrg{
2047862bcd1aSmrg    $debug_cmd
2048862bcd1aSmrg
2049862bcd1aSmrg    func_usage_message
2050862bcd1aSmrg    $ECHO "$long_help_message"
2051862bcd1aSmrg    exit 0
205288de56ccSmrg}
205388de56ccSmrg
2054862bcd1aSmrg
2055862bcd1aSmrg# func_missing_arg ARGNAME
2056862bcd1aSmrg# ------------------------
205788de56ccSmrg# Echo program name prefixed message to standard error and set global
205888de56ccSmrg# exit_cmd.
205988de56ccSmrgfunc_missing_arg ()
206088de56ccSmrg{
2061862bcd1aSmrg    $debug_cmd
2062e9fcaa8aSmrg
2063862bcd1aSmrg    func_error "Missing argument for '$1'."
206488de56ccSmrg    exit_cmd=exit
20651ab64890Smrg}
20661ab64890Smrg
20672e9c7c8cSmrg
2068862bcd1aSmrg# func_split_equals STRING
2069862bcd1aSmrg# ------------------------
20707d2c738bSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
20717d2c738bSmrg# after splitting STRING at the '=' sign.
2072862bcd1aSmrgtest -z "$_G_HAVE_XSI_OPS" \
2073862bcd1aSmrg    && (eval 'x=a/b/c;
2074862bcd1aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075862bcd1aSmrg    && _G_HAVE_XSI_OPS=yes
2076862bcd1aSmrg
2077862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"
2078862bcd1aSmrgthen
2079862bcd1aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2080862bcd1aSmrg  eval 'func_split_equals ()
2081862bcd1aSmrg  {
2082862bcd1aSmrg      $debug_cmd
2083862bcd1aSmrg
2084862bcd1aSmrg      func_split_equals_lhs=${1%%=*}
2085862bcd1aSmrg      func_split_equals_rhs=${1#*=}
20867d2c738bSmrg      if test "x$func_split_equals_lhs" = "x$1"; then
20877d2c738bSmrg        func_split_equals_rhs=
20887d2c738bSmrg      fi
2089862bcd1aSmrg  }'
2090862bcd1aSmrgelse
2091862bcd1aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092862bcd1aSmrg  func_split_equals ()
2093862bcd1aSmrg  {
2094862bcd1aSmrg      $debug_cmd
2095862bcd1aSmrg
2096862bcd1aSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097862bcd1aSmrg      func_split_equals_rhs=
20987d2c738bSmrg      test "x$func_split_equals_lhs=" = "x$1" \
2099862bcd1aSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100862bcd1aSmrg  }
2101862bcd1aSmrgfi #func_split_equals
2102862bcd1aSmrg
2103862bcd1aSmrg
2104862bcd1aSmrg# func_split_short_opt SHORTOPT
2105862bcd1aSmrg# -----------------------------
2106e9fcaa8aSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107e9fcaa8aSmrg# variables after splitting SHORTOPT after the 2nd character.
2108862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"
2109862bcd1aSmrgthen
2110862bcd1aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2111862bcd1aSmrg  eval 'func_split_short_opt ()
2112862bcd1aSmrg  {
2113862bcd1aSmrg      $debug_cmd
2114862bcd1aSmrg
2115862bcd1aSmrg      func_split_short_opt_arg=${1#??}
2116862bcd1aSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117862bcd1aSmrg  }'
2118862bcd1aSmrgelse
2119862bcd1aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120862bcd1aSmrg  func_split_short_opt ()
2121862bcd1aSmrg  {
2122862bcd1aSmrg      $debug_cmd
2123862bcd1aSmrg
21247d2c738bSmrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125862bcd1aSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126862bcd1aSmrg  }
2127862bcd1aSmrgfi #func_split_short_opt
2128862bcd1aSmrg
2129862bcd1aSmrg
2130862bcd1aSmrg# func_usage
2131862bcd1aSmrg# ----------
2132862bcd1aSmrg# Echo short help message to standard output and exit.
2133862bcd1aSmrgfunc_usage ()
2134e9fcaa8aSmrg{
2135862bcd1aSmrg    $debug_cmd
2136e9fcaa8aSmrg
2137862bcd1aSmrg    func_usage_message
2138862bcd1aSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139862bcd1aSmrg    exit 0
2140862bcd1aSmrg}
21412e9c7c8cSmrg
214288de56ccSmrg
2143862bcd1aSmrg# func_usage_message
2144862bcd1aSmrg# ------------------
2145862bcd1aSmrg# Echo short help message to standard output.
2146862bcd1aSmrgfunc_usage_message ()
2147e9fcaa8aSmrg{
2148862bcd1aSmrg    $debug_cmd
2149e9fcaa8aSmrg
2150862bcd1aSmrg    eval \$ECHO \""Usage: $usage"\"
2151862bcd1aSmrg    echo
2152862bcd1aSmrg    $SED -n 's|^# ||
2153862bcd1aSmrg        /^Written by/{
2154862bcd1aSmrg          x;p;x
2155862bcd1aSmrg        }
2156862bcd1aSmrg	h
2157862bcd1aSmrg	/^Written by/q' < "$progpath"
2158862bcd1aSmrg    echo
2159862bcd1aSmrg    eval \$ECHO \""$usage_message"\"
2160862bcd1aSmrg}
2161e9fcaa8aSmrg
2162e9fcaa8aSmrg
2163862bcd1aSmrg# func_version
2164862bcd1aSmrg# ------------
2165862bcd1aSmrg# Echo version message to standard output and exit.
21667d2c738bSmrg# The version message is extracted from the calling file's header
21677d2c738bSmrg# comments, with leading '# ' stripped:
21687d2c738bSmrg#   1. First display the progname and version
21697d2c738bSmrg#   2. Followed by the header comment line matching  /^# Written by /
21707d2c738bSmrg#   3. Then a blank line followed by the first following line matching
21717d2c738bSmrg#      /^# Copyright /
21727d2c738bSmrg#   4. Immediately followed by any lines between the previous matches,
21737d2c738bSmrg#      except lines preceding the intervening completely blank line.
21747d2c738bSmrg# For example, see the header comments of this file.
2175862bcd1aSmrgfunc_version ()
2176862bcd1aSmrg{
2177862bcd1aSmrg    $debug_cmd
217888de56ccSmrg
2179862bcd1aSmrg    printf '%s\n' "$progname $scriptversion"
2180862bcd1aSmrg    $SED -n '
21817d2c738bSmrg        /^# Written by /!b
21827d2c738bSmrg        s|^# ||; p; n
21837d2c738bSmrg
21847d2c738bSmrg        :fwd2blnk
21857d2c738bSmrg        /./ {
21867d2c738bSmrg          n
21877d2c738bSmrg          b fwd2blnk
2188862bcd1aSmrg        }
21897d2c738bSmrg        p; n
21907d2c738bSmrg
21917d2c738bSmrg        :holdwrnt
21927d2c738bSmrg        s|^# ||
21937d2c738bSmrg        s|^# *$||
21947d2c738bSmrg        /^Copyright /!{
21957d2c738bSmrg          /./H
21967d2c738bSmrg          n
21977d2c738bSmrg          b holdwrnt
219814db512dSmrg        }
21997d2c738bSmrg
22007d2c738bSmrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
22017d2c738bSmrg        G
22027d2c738bSmrg        s|\(\n\)\n*|\1|g
22037d2c738bSmrg        p; q' < "$progpath"
220488de56ccSmrg
2205862bcd1aSmrg    exit $?
2206862bcd1aSmrg}
22071ab64890Smrg
22081ab64890Smrg
2209862bcd1aSmrg# Local variables:
2210862bcd1aSmrg# mode: shell-script
2211862bcd1aSmrg# sh-indentation: 2
2212862bcd1aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
22137d2c738bSmrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214862bcd1aSmrg# time-stamp-time-zone: "UTC"
2215862bcd1aSmrg# End:
22161ab64890Smrg
2217862bcd1aSmrg# Set a version string.
221807fb9b8fSmrgscriptversion='(GNU libtool) 2.5.4'
221907fb9b8fSmrg
222007fb9b8fSmrg# func_version
222107fb9b8fSmrg# ------------
222207fb9b8fSmrg# Echo version message to standard output and exit.
222307fb9b8fSmrgfunc_version ()
222407fb9b8fSmrg{
222507fb9b8fSmrg    $debug_cmd
222607fb9b8fSmrg
222707fb9b8fSmrg	year=`date +%Y`
222807fb9b8fSmrg
222907fb9b8fSmrg	cat <<EOF
223007fb9b8fSmrg$progname $scriptversion
223107fb9b8fSmrgCopyright (C) $year Free Software Foundation, Inc.
223207fb9b8fSmrgLicense GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>
223307fb9b8fSmrgThis is free software: you are free to change and redistribute it.
223407fb9b8fSmrgThere is NO WARRANTY, to the extent permitted by law.
223507fb9b8fSmrg
223607fb9b8fSmrgOriginally written by Gordon Matzigkeit, 1996
223707fb9b8fSmrg(See AUTHORS for complete contributor listing)
223807fb9b8fSmrgEOF
223907fb9b8fSmrg
224007fb9b8fSmrg    exit $?
224107fb9b8fSmrg}
22422e9c7c8cSmrg
224388de56ccSmrg
2244862bcd1aSmrg# func_echo ARG...
2245862bcd1aSmrg# ----------------
2246862bcd1aSmrg# Libtool also displays the current mode in messages, so override
2247862bcd1aSmrg# funclib.sh func_echo with this custom definition.
2248862bcd1aSmrgfunc_echo ()
2249e9fcaa8aSmrg{
2250862bcd1aSmrg    $debug_cmd
2251e9fcaa8aSmrg
2252862bcd1aSmrg    _G_message=$*
2253862bcd1aSmrg
2254862bcd1aSmrg    func_echo_IFS=$IFS
2255862bcd1aSmrg    IFS=$nl
2256862bcd1aSmrg    for _G_line in $_G_message; do
2257862bcd1aSmrg      IFS=$func_echo_IFS
2258862bcd1aSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2259862bcd1aSmrg    done
2260862bcd1aSmrg    IFS=$func_echo_IFS
2261862bcd1aSmrg}
2262e9fcaa8aSmrg
2263e9fcaa8aSmrg
2264862bcd1aSmrg## ---------------- ##
2265862bcd1aSmrg## Options parsing. ##
2266862bcd1aSmrg## ---------------- ##
2267862bcd1aSmrg
2268862bcd1aSmrg# Hook in the functions to make sure our own options are parsed during
2269862bcd1aSmrg# the option parsing loop.
2270862bcd1aSmrg
2271862bcd1aSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2272862bcd1aSmrg
2273862bcd1aSmrg# Short help message in response to '-h'.
2274862bcd1aSmrgusage_message="Options:
227507fb9b8fSmrg       --config                 show all configuration variables
227607fb9b8fSmrg       --debug                  enable verbose shell tracing
227707fb9b8fSmrg   -n, --dry-run                display commands without modifying any files
227807fb9b8fSmrg       --features               display basic configuration information
227907fb9b8fSmrg       --finish                 use operation '--mode=finish'
228007fb9b8fSmrg       --mode=MODE              use operation mode MODE
228107fb9b8fSmrg       --no-finish              don't update shared library cache
228207fb9b8fSmrg       --no-quiet, --no-silent  print default informational messages
228307fb9b8fSmrg       --no-warnings            equivalent to '-Wnone'
228407fb9b8fSmrg       --preserve-dup-deps      don't remove duplicate dependency libraries
228507fb9b8fSmrg       --quiet, --silent        don't print informational messages
228607fb9b8fSmrg       --reorder-cache=DIRS     reorder shared library cache for preferred DIRS
228707fb9b8fSmrg       --tag=TAG                use configuration variables from tag TAG
228807fb9b8fSmrg   -v, --verbose                print more informational messages than default
228907fb9b8fSmrg       --version                print version information
229007fb9b8fSmrg   -W, --warnings=CATEGORY      report the warnings falling in CATEGORY [all]
229107fb9b8fSmrg   -h, --help, --help-all       print short, long, or detailed help message
2292862bcd1aSmrg"
2293e9fcaa8aSmrg
2294862bcd1aSmrg# Additional text appended to 'usage_message' in response to '--help'.
2295862bcd1aSmrgfunc_help ()
2296e9fcaa8aSmrg{
2297862bcd1aSmrg    $debug_cmd
2298862bcd1aSmrg
2299862bcd1aSmrg    func_usage_message
2300862bcd1aSmrg    $ECHO "$long_help_message
2301862bcd1aSmrg
2302862bcd1aSmrgMODE must be one of the following:
2303862bcd1aSmrg
2304862bcd1aSmrg       clean           remove files from the build directory
2305862bcd1aSmrg       compile         compile a source file into a libtool object
2306862bcd1aSmrg       execute         automatically set library path, then run a program
2307862bcd1aSmrg       finish          complete the installation of libtool libraries
2308862bcd1aSmrg       install         install libraries or executables
2309862bcd1aSmrg       link            create a library or an executable
2310862bcd1aSmrg       uninstall       remove libraries from an installed directory
2311862bcd1aSmrg
2312862bcd1aSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2313862bcd1aSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2314862bcd1aSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2315862bcd1aSmrg
2316862bcd1aSmrgWhen reporting a bug, please describe a test case to reproduce it and
2317862bcd1aSmrginclude the following information:
2318862bcd1aSmrg
2319862bcd1aSmrg       host-triplet:   $host
2320862bcd1aSmrg       shell:          $SHELL
2321862bcd1aSmrg       compiler:       $LTCC
2322862bcd1aSmrg       compiler flags: $LTCFLAGS
2323862bcd1aSmrg       linker:         $LD (gnu? $with_gnu_ld)
232407fb9b8fSmrg       version:        $progname $scriptversion
2325862bcd1aSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2326862bcd1aSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2327862bcd1aSmrg
2328862bcd1aSmrgReport bugs to <bug-libtool@gnu.org>.
232907fb9b8fSmrgGNU libtool home page: <https://www.gnu.org/software/libtool/>.
233007fb9b8fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
2331862bcd1aSmrg    exit 0
2332862bcd1aSmrg}
2333e9fcaa8aSmrg
2334e9fcaa8aSmrg
2335862bcd1aSmrg# func_lo2o OBJECT-NAME
2336862bcd1aSmrg# ---------------------
2337862bcd1aSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2338862bcd1aSmrg# object suffix.
2339e9fcaa8aSmrg
2340862bcd1aSmrglo2o=s/\\.lo\$/.$objext/
2341862bcd1aSmrgo2lo=s/\\.$objext\$/.lo/
2342e9fcaa8aSmrg
2343862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2344862bcd1aSmrg  eval 'func_lo2o ()
2345862bcd1aSmrg  {
2346862bcd1aSmrg    case $1 in
2347862bcd1aSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2348862bcd1aSmrg      *   ) func_lo2o_result=$1               ;;
2349862bcd1aSmrg    esac
2350862bcd1aSmrg  }'
2351862bcd1aSmrg
2352862bcd1aSmrg  # func_xform LIBOBJ-OR-SOURCE
2353862bcd1aSmrg  # ---------------------------
2354862bcd1aSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2355862bcd1aSmrg  # suffix to a '.lo' libtool-object suffix.
2356862bcd1aSmrg  eval 'func_xform ()
2357862bcd1aSmrg  {
2358862bcd1aSmrg    func_xform_result=${1%.*}.lo
2359862bcd1aSmrg  }'
2360862bcd1aSmrgelse
2361862bcd1aSmrg  # ...otherwise fall back to using sed.
2362862bcd1aSmrg  func_lo2o ()
2363862bcd1aSmrg  {
2364862bcd1aSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2365862bcd1aSmrg  }
2366862bcd1aSmrg
2367862bcd1aSmrg  func_xform ()
2368862bcd1aSmrg  {
2369862bcd1aSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2370862bcd1aSmrg  }
2371862bcd1aSmrgfi
2372e9fcaa8aSmrg
2373e9fcaa8aSmrg
2374862bcd1aSmrg# func_fatal_configuration ARG...
2375862bcd1aSmrg# -------------------------------
237688de56ccSmrg# Echo program name prefixed message to standard error, followed by
237788de56ccSmrg# a configuration failure hint, and exit.
237888de56ccSmrgfunc_fatal_configuration ()
237988de56ccSmrg{
23807d2c738bSmrg    func_fatal_error ${1+"$@"} \
2381862bcd1aSmrg      "See the $PACKAGE documentation for more information." \
2382862bcd1aSmrg      "Fatal configuration error."
238388de56ccSmrg}
23841ab64890Smrg
23852e9c7c8cSmrg
238688de56ccSmrg# func_config
2387862bcd1aSmrg# -----------
238888de56ccSmrg# Display the configuration for all the tags in this script.
238988de56ccSmrgfunc_config ()
239088de56ccSmrg{
239188de56ccSmrg    re_begincf='^# ### BEGIN LIBTOOL'
239288de56ccSmrg    re_endcf='^# ### END LIBTOOL'
239388de56ccSmrg
239488de56ccSmrg    # Default configuration.
239588de56ccSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23961ab64890Smrg
23971ab64890Smrg    # Now print the configurations for the tags.
23981ab64890Smrg    for tagname in $taglist; do
239988de56ccSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
24001ab64890Smrg    done
2401b4ee4795Smrg
240288de56ccSmrg    exit $?
240388de56ccSmrg}
2404b4ee4795Smrg
2405862bcd1aSmrg
240688de56ccSmrg# func_features
2407862bcd1aSmrg# -------------
240888de56ccSmrg# Display the features supported by this script.
240988de56ccSmrgfunc_features ()
241088de56ccSmrg{
2411e9fcaa8aSmrg    echo "host: $host"
2412862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
2413e9fcaa8aSmrg      echo "enable shared libraries"
24141ab64890Smrg    else
2415e9fcaa8aSmrg      echo "disable shared libraries"
24161ab64890Smrg    fi
2417862bcd1aSmrg    if test yes = "$build_old_libs"; then
2418e9fcaa8aSmrg      echo "enable static libraries"
24191ab64890Smrg    else
2420e9fcaa8aSmrg      echo "disable static libraries"
24211ab64890Smrg    fi
242288de56ccSmrg
24231ab64890Smrg    exit $?
242488de56ccSmrg}
24251ab64890Smrg
2426862bcd1aSmrg
2427862bcd1aSmrg# func_enable_tag TAGNAME
2428862bcd1aSmrg# -----------------------
242988de56ccSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
243088de56ccSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
243188de56ccSmrg# variable here.
243288de56ccSmrgfunc_enable_tag ()
243388de56ccSmrg{
2434862bcd1aSmrg    # Global variable:
2435862bcd1aSmrg    tagname=$1
24361ab64890Smrg
2437862bcd1aSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2438862bcd1aSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2439862bcd1aSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24402e9c7c8cSmrg
2441862bcd1aSmrg    # Validate tagname.
2442862bcd1aSmrg    case $tagname in
2443862bcd1aSmrg      *[!-_A-Za-z0-9,/]*)
2444862bcd1aSmrg        func_fatal_error "invalid tag name: $tagname"
2445862bcd1aSmrg        ;;
2446862bcd1aSmrg    esac
24471ab64890Smrg
2448862bcd1aSmrg    # Don't test for the "default" C tag, as we know it's
2449862bcd1aSmrg    # there but not specially marked.
2450862bcd1aSmrg    case $tagname in
2451862bcd1aSmrg        CC) ;;
245288de56ccSmrg    *)
2453862bcd1aSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2454862bcd1aSmrg	  taglist="$taglist $tagname"
2455862bcd1aSmrg
2456862bcd1aSmrg	  # Evaluate the configuration.  Be careful to quote the path
2457862bcd1aSmrg	  # and the sed script, to avoid splitting on whitespace, but
2458862bcd1aSmrg	  # also don't use non-portable quotes within backquotes within
2459862bcd1aSmrg	  # quotes we have to do it in 2 steps:
2460862bcd1aSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2461862bcd1aSmrg	  eval "$extractedcf"
2462862bcd1aSmrg        else
2463862bcd1aSmrg	  func_error "ignoring unknown tag $tagname"
2464862bcd1aSmrg        fi
2465862bcd1aSmrg        ;;
2466862bcd1aSmrg    esac
246788de56ccSmrg}
246888de56ccSmrg
2469862bcd1aSmrg
2470e9fcaa8aSmrg# func_check_version_match
2471862bcd1aSmrg# ------------------------
2472e9fcaa8aSmrg# Ensure that we are using m4 macros, and libtool script from the same
2473e9fcaa8aSmrg# release of libtool.
2474e9fcaa8aSmrgfunc_check_version_match ()
247588de56ccSmrg{
2476862bcd1aSmrg    if test "$package_revision" != "$macro_revision"; then
2477862bcd1aSmrg      if test "$VERSION" != "$macro_version"; then
2478862bcd1aSmrg        if test -z "$macro_version"; then
2479862bcd1aSmrg          cat >&2 <<_LT_EOF
2480e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2481e9fcaa8aSmrg$progname: definition of this LT_INIT comes from an older release.
2482e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2483e9fcaa8aSmrg$progname: and run autoconf again.
2484e9fcaa8aSmrg_LT_EOF
2485862bcd1aSmrg        else
2486862bcd1aSmrg          cat >&2 <<_LT_EOF
2487e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2488e9fcaa8aSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2489e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2490e9fcaa8aSmrg$progname: and run autoconf again.
2491e9fcaa8aSmrg_LT_EOF
2492862bcd1aSmrg        fi
2493862bcd1aSmrg      else
2494862bcd1aSmrg        cat >&2 <<_LT_EOF
2495e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2496e9fcaa8aSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2497e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2498e9fcaa8aSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2499e9fcaa8aSmrg_LT_EOF
2500862bcd1aSmrg      fi
2501e9fcaa8aSmrg
2502862bcd1aSmrg      exit $EXIT_MISMATCH
2503862bcd1aSmrg    fi
2504e9fcaa8aSmrg}
2505e9fcaa8aSmrg
2506e9fcaa8aSmrg
2507862bcd1aSmrg# libtool_options_prep [ARG]...
2508862bcd1aSmrg# -----------------------------
2509862bcd1aSmrg# Preparation for options parsed by libtool.
2510862bcd1aSmrglibtool_options_prep ()
2511862bcd1aSmrg{
2512862bcd1aSmrg    $debug_mode
2513b4ee4795Smrg
2514862bcd1aSmrg    # Option defaults:
2515862bcd1aSmrg    opt_config=false
2516862bcd1aSmrg    opt_dlopen=
2517862bcd1aSmrg    opt_dry_run=false
2518862bcd1aSmrg    opt_help=false
2519862bcd1aSmrg    opt_mode=
252007fb9b8fSmrg    opt_reorder_cache=false
2521862bcd1aSmrg    opt_preserve_dup_deps=false
2522862bcd1aSmrg    opt_quiet=false
252307fb9b8fSmrg    opt_finishing=true
252407fb9b8fSmrg    opt_warning=
25251ab64890Smrg
2526862bcd1aSmrg    nonopt=
2527862bcd1aSmrg    preserve_args=
2528e9fcaa8aSmrg
25297d2c738bSmrg    _G_rc_lt_options_prep=:
25307d2c738bSmrg
2531862bcd1aSmrg    # Shorthand for --mode=foo, only valid as the first argument
2532862bcd1aSmrg    case $1 in
2533862bcd1aSmrg    clean|clea|cle|cl)
2534862bcd1aSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2535862bcd1aSmrg      ;;
2536862bcd1aSmrg    compile|compil|compi|comp|com|co|c)
2537862bcd1aSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2538862bcd1aSmrg      ;;
2539862bcd1aSmrg    execute|execut|execu|exec|exe|ex|e)
2540862bcd1aSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2541862bcd1aSmrg      ;;
2542862bcd1aSmrg    finish|finis|fini|fin|fi|f)
2543862bcd1aSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2544862bcd1aSmrg      ;;
2545862bcd1aSmrg    install|instal|insta|inst|ins|in|i)
2546862bcd1aSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2547862bcd1aSmrg      ;;
2548862bcd1aSmrg    link|lin|li|l)
2549862bcd1aSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2550862bcd1aSmrg      ;;
2551862bcd1aSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2552862bcd1aSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2553862bcd1aSmrg      ;;
25547d2c738bSmrg    *)
25557d2c738bSmrg      _G_rc_lt_options_prep=false
25567d2c738bSmrg      ;;
2557862bcd1aSmrg    esac
2558862bcd1aSmrg
25597d2c738bSmrg    if $_G_rc_lt_options_prep; then
25607d2c738bSmrg      # Pass back the list of options.
25617d2c738bSmrg      func_quote eval ${1+"$@"}
25627d2c738bSmrg      libtool_options_prep_result=$func_quote_result
25637d2c738bSmrg    fi
2564862bcd1aSmrg}
2565862bcd1aSmrgfunc_add_hook func_options_prep libtool_options_prep
2566e9fcaa8aSmrg
2567e9fcaa8aSmrg
2568862bcd1aSmrg# libtool_parse_options [ARG]...
2569862bcd1aSmrg# ---------------------------------
2570862bcd1aSmrg# Provide handling for libtool specific options.
2571862bcd1aSmrglibtool_parse_options ()
2572e9fcaa8aSmrg{
2573862bcd1aSmrg    $debug_cmd
257488de56ccSmrg
25757d2c738bSmrg    _G_rc_lt_parse_options=false
25767d2c738bSmrg
2577862bcd1aSmrg    # Perform our own loop to consume as many options as possible in
2578862bcd1aSmrg    # each iteration.
2579862bcd1aSmrg    while test $# -gt 0; do
25807d2c738bSmrg      _G_match_lt_parse_options=:
2581862bcd1aSmrg      _G_opt=$1
2582862bcd1aSmrg      shift
2583862bcd1aSmrg      case $_G_opt in
2584862bcd1aSmrg        --dry-run|--dryrun|-n)
2585862bcd1aSmrg                        opt_dry_run=:
2586862bcd1aSmrg                        ;;
2587862bcd1aSmrg
2588862bcd1aSmrg        --config)       func_config ;;
2589862bcd1aSmrg
2590862bcd1aSmrg        --dlopen|-dlopen)
2591862bcd1aSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2592862bcd1aSmrg}$1"
2593862bcd1aSmrg                        shift
2594862bcd1aSmrg                        ;;
2595862bcd1aSmrg
2596862bcd1aSmrg        --preserve-dup-deps)
2597862bcd1aSmrg                        opt_preserve_dup_deps=: ;;
2598862bcd1aSmrg
2599862bcd1aSmrg        --features)     func_features ;;
2600862bcd1aSmrg
2601862bcd1aSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2602862bcd1aSmrg
2603862bcd1aSmrg        --help)         opt_help=: ;;
2604862bcd1aSmrg
2605862bcd1aSmrg        --help-all)     opt_help=': help-all' ;;
2606862bcd1aSmrg
2607862bcd1aSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2608862bcd1aSmrg                        opt_mode=$1
2609862bcd1aSmrg                        case $1 in
2610862bcd1aSmrg                          # Valid mode arguments:
2611862bcd1aSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2612862bcd1aSmrg
2613862bcd1aSmrg                          # Catch anything else as an error
261407fb9b8fSmrg                          *) func_error "invalid argument '$1' for $_G_opt"
2615862bcd1aSmrg                             exit_cmd=exit
2616862bcd1aSmrg                             ;;
2617862bcd1aSmrg                        esac
2618862bcd1aSmrg                        shift
2619862bcd1aSmrg                        ;;
2620862bcd1aSmrg
262107fb9b8fSmrg        --no-finish)
262207fb9b8fSmrg                        opt_finishing=false
262307fb9b8fSmrg                        func_append preserve_args " $_G_opt"
262407fb9b8fSmrg                        ;;
262507fb9b8fSmrg
2626862bcd1aSmrg        --no-silent|--no-quiet)
2627862bcd1aSmrg                        opt_quiet=false
2628862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2629862bcd1aSmrg                        ;;
2630862bcd1aSmrg
2631862bcd1aSmrg        --no-warnings|--no-warning|--no-warn)
2632862bcd1aSmrg                        opt_warning=false
2633862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2634862bcd1aSmrg                        ;;
2635862bcd1aSmrg
2636862bcd1aSmrg        --no-verbose)
2637862bcd1aSmrg                        opt_verbose=false
2638862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2639862bcd1aSmrg                        ;;
2640862bcd1aSmrg
264107fb9b8fSmrg        --reorder-cache)
264207fb9b8fSmrg                        opt_reorder_cache=true
264307fb9b8fSmrg                        shared_lib_dirs=$1
264407fb9b8fSmrg                        if test -n "$shared_lib_dirs"; then
264507fb9b8fSmrg                          case $1 in
264607fb9b8fSmrg                            # Must begin with /:
264707fb9b8fSmrg                            /*) ;;
264807fb9b8fSmrg
264907fb9b8fSmrg                            # Catch anything else as an error (relative paths)
265007fb9b8fSmrg                            *) func_error "invalid argument '$1' for $_G_opt"
265107fb9b8fSmrg                               func_error "absolute paths are required for $_G_opt"
265207fb9b8fSmrg                               exit_cmd=exit
265307fb9b8fSmrg                               ;;
265407fb9b8fSmrg                          esac
265507fb9b8fSmrg                        fi
265607fb9b8fSmrg                        shift
265707fb9b8fSmrg                        ;;
265807fb9b8fSmrg
2659862bcd1aSmrg        --silent|--quiet)
2660862bcd1aSmrg                        opt_quiet=:
2661862bcd1aSmrg                        opt_verbose=false
2662862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2663862bcd1aSmrg                        ;;
2664862bcd1aSmrg
2665862bcd1aSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2666862bcd1aSmrg                        opt_tag=$1
2667862bcd1aSmrg                        func_append preserve_args " $_G_opt $1"
2668862bcd1aSmrg                        func_enable_tag "$1"
2669862bcd1aSmrg                        shift
2670862bcd1aSmrg                        ;;
2671862bcd1aSmrg
2672862bcd1aSmrg        --verbose|-v)   opt_quiet=false
2673862bcd1aSmrg                        opt_verbose=:
2674862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2675862bcd1aSmrg                        ;;
2676862bcd1aSmrg
26777d2c738bSmrg        # An option not handled by this hook function:
26787d2c738bSmrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
26797d2c738bSmrg                        _G_match_lt_parse_options=false
26807d2c738bSmrg                        break
26817d2c738bSmrg                        ;;
2682862bcd1aSmrg      esac
26837d2c738bSmrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2684862bcd1aSmrg    done
2685e9fcaa8aSmrg
26867d2c738bSmrg    if $_G_rc_lt_parse_options; then
26877d2c738bSmrg      # save modified positional parameters for caller
26887d2c738bSmrg      func_quote eval ${1+"$@"}
26897d2c738bSmrg      libtool_parse_options_result=$func_quote_result
26907d2c738bSmrg    fi
2691862bcd1aSmrg}
2692862bcd1aSmrgfunc_add_hook func_parse_options libtool_parse_options
269388de56ccSmrg
26942e9c7c8cSmrg
269507fb9b8fSmrg# func_warning ARG...
269607fb9b8fSmrg# -------------------
269707fb9b8fSmrg# Libtool warnings are not categorized, so override funclib.sh
269807fb9b8fSmrg# func_warning with this simpler definition.
269907fb9b8fSmrgfunc_warning ()
270007fb9b8fSmrg{
270107fb9b8fSmrg    if $opt_warning; then
270207fb9b8fSmrg        $debug_cmd
270307fb9b8fSmrg        $warning_func ${1+"$@"}
270407fb9b8fSmrg    fi
270507fb9b8fSmrg}
270607fb9b8fSmrg
270788de56ccSmrg
2708862bcd1aSmrg# libtool_validate_options [ARG]...
2709862bcd1aSmrg# ---------------------------------
2710862bcd1aSmrg# Perform any sanity checks on option settings and/or unconsumed
2711862bcd1aSmrg# arguments.
2712862bcd1aSmrglibtool_validate_options ()
2713862bcd1aSmrg{
2714862bcd1aSmrg    # save first non-option argument
2715862bcd1aSmrg    if test 0 -lt $#; then
2716862bcd1aSmrg      nonopt=$1
2717862bcd1aSmrg      shift
271888de56ccSmrg    fi
271988de56ccSmrg
2720862bcd1aSmrg    # preserve --debug
2721862bcd1aSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
272288de56ccSmrg
272307fb9b8fSmrg    case $host_os in
2724862bcd1aSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2725862bcd1aSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
272607fb9b8fSmrg      cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*)
2727862bcd1aSmrg        # don't eliminate duplications in $postdeps and $predeps
2728862bcd1aSmrg        opt_duplicate_compiler_generated_deps=:
2729862bcd1aSmrg        ;;
2730862bcd1aSmrg      *)
2731862bcd1aSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2732862bcd1aSmrg        ;;
2733862bcd1aSmrg    esac
27341ab64890Smrg
2735862bcd1aSmrg    $opt_help || {
2736862bcd1aSmrg      # Sanity checks first:
2737862bcd1aSmrg      func_check_version_match
273888de56ccSmrg
2739862bcd1aSmrg      test yes != "$build_libtool_libs" \
2740862bcd1aSmrg        && test yes != "$build_old_libs" \
2741862bcd1aSmrg        && func_fatal_configuration "not configured to build any kind of library"
274288de56ccSmrg
2743862bcd1aSmrg      # Darwin sucks
2744862bcd1aSmrg      eval std_shrext=\"$shrext_cmds\"
2745862bcd1aSmrg
2746862bcd1aSmrg      # Only execute mode is allowed to have -dlopen flags.
2747862bcd1aSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2748862bcd1aSmrg        func_error "unrecognized option '-dlopen'"
2749862bcd1aSmrg        $ECHO "$help" 1>&2
2750862bcd1aSmrg        exit $EXIT_FAILURE
2751862bcd1aSmrg      fi
2752862bcd1aSmrg
2753862bcd1aSmrg      # Change the help message to a mode-specific one.
2754862bcd1aSmrg      generic_help=$help
2755862bcd1aSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2756862bcd1aSmrg    }
2757862bcd1aSmrg
2758862bcd1aSmrg    # Pass back the unparsed argument list
27597d2c738bSmrg    func_quote eval ${1+"$@"}
27607d2c738bSmrg    libtool_validate_options_result=$func_quote_result
2761e9fcaa8aSmrg}
2762862bcd1aSmrgfunc_add_hook func_validate_options libtool_validate_options
2763862bcd1aSmrg
276488de56ccSmrg
2765862bcd1aSmrg# Process options as early as possible so that --help and --version
2766862bcd1aSmrg# can return quickly.
2767862bcd1aSmrgfunc_options ${1+"$@"}
2768862bcd1aSmrgeval set dummy "$func_options_result"; shift
276988de56ccSmrg
27701ab64890Smrg
27711ab64890Smrg
2772e9fcaa8aSmrg## ----------- ##
2773e9fcaa8aSmrg##    Main.    ##
2774e9fcaa8aSmrg## ----------- ##
27751ab64890Smrg
2776862bcd1aSmrgmagic='%%%MAGIC variable%%%'
2777862bcd1aSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2778862bcd1aSmrg
2779862bcd1aSmrg# Global variables.
2780862bcd1aSmrgextracted_archives=
2781862bcd1aSmrgextracted_serial=0
2782862bcd1aSmrg
2783862bcd1aSmrg# If this variable is set in any of the actions, the command in it
2784862bcd1aSmrg# will be execed at the end.  This prevents here-documents from being
2785862bcd1aSmrg# left over by shells.
2786862bcd1aSmrgexec_cmd=
2787862bcd1aSmrg
2788862bcd1aSmrg
2789862bcd1aSmrg# A function that is used when there is no print builtin or printf.
2790862bcd1aSmrgfunc_fallback_echo ()
2791862bcd1aSmrg{
2792862bcd1aSmrg  eval 'cat <<_LTECHO_EOF
2793862bcd1aSmrg$1
2794862bcd1aSmrg_LTECHO_EOF'
2795862bcd1aSmrg}
2796862bcd1aSmrg
2797862bcd1aSmrg# func_generated_by_libtool
2798862bcd1aSmrg# True iff stdin has been generated by Libtool. This function is only
2799862bcd1aSmrg# a basic sanity check; it will hardly flush out determined imposters.
2800862bcd1aSmrgfunc_generated_by_libtool_p ()
2801862bcd1aSmrg{
2802862bcd1aSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2803862bcd1aSmrg}
2804862bcd1aSmrg
280588de56ccSmrg# func_lalib_p file
2806862bcd1aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
280788de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
280888de56ccSmrg# determined imposters.
280988de56ccSmrgfunc_lalib_p ()
281088de56ccSmrg{
281188de56ccSmrg    test -f "$1" &&
2812862bcd1aSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
281388de56ccSmrg}
28141ab64890Smrg
281588de56ccSmrg# func_lalib_unsafe_p file
2816862bcd1aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
281788de56ccSmrg# This function implements the same check as func_lalib_p without
281888de56ccSmrg# resorting to external programs.  To this end, it redirects stdin and
281988de56ccSmrg# closes it afterwards, without saving the original file descriptor.
282088de56ccSmrg# As a safety measure, use it only where a negative result would be
2821862bcd1aSmrg# fatal anyway.  Works if 'file' does not exist.
282288de56ccSmrgfunc_lalib_unsafe_p ()
282388de56ccSmrg{
282488de56ccSmrg    lalib_p=no
282588de56ccSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
282688de56ccSmrg	for lalib_p_l in 1 2 3 4
282788de56ccSmrg	do
282888de56ccSmrg	    read lalib_p_line
2829862bcd1aSmrg	    case $lalib_p_line in
283088de56ccSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
283188de56ccSmrg	    esac
283288de56ccSmrg	done
283388de56ccSmrg	exec 0<&5 5<&-
283488de56ccSmrg    fi
2835862bcd1aSmrg    test yes = "$lalib_p"
283688de56ccSmrg}
28371ab64890Smrg
283888de56ccSmrg# func_ltwrapper_script_p file
283988de56ccSmrg# True iff FILE is a libtool wrapper script
284088de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
284188de56ccSmrg# determined imposters.
284288de56ccSmrgfunc_ltwrapper_script_p ()
284388de56ccSmrg{
2844862bcd1aSmrg    test -f "$1" &&
2845862bcd1aSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
284688de56ccSmrg}
28471ab64890Smrg
284888de56ccSmrg# func_ltwrapper_executable_p file
284988de56ccSmrg# True iff FILE is a libtool wrapper executable
285088de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
285188de56ccSmrg# determined imposters.
285288de56ccSmrgfunc_ltwrapper_executable_p ()
285388de56ccSmrg{
285488de56ccSmrg    func_ltwrapper_exec_suffix=
285588de56ccSmrg    case $1 in
285688de56ccSmrg    *.exe) ;;
285788de56ccSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
285888de56ccSmrg    esac
285988de56ccSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
286088de56ccSmrg}
28612e9c7c8cSmrg
286288de56ccSmrg# func_ltwrapper_scriptname file
286388de56ccSmrg# Assumes file is an ltwrapper_executable
286488de56ccSmrg# uses $file to determine the appropriate filename for a
286588de56ccSmrg# temporary ltwrapper_script.
286688de56ccSmrgfunc_ltwrapper_scriptname ()
286788de56ccSmrg{
2868e9fcaa8aSmrg    func_dirname_and_basename "$1" "" "."
2869e9fcaa8aSmrg    func_stripname '' '.exe' "$func_basename_result"
2870862bcd1aSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
287188de56ccSmrg}
287288de56ccSmrg
287388de56ccSmrg# func_ltwrapper_p file
287488de56ccSmrg# True iff FILE is a libtool wrapper script or wrapper executable
287588de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
287688de56ccSmrg# determined imposters.
287788de56ccSmrgfunc_ltwrapper_p ()
287888de56ccSmrg{
287988de56ccSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
288088de56ccSmrg}
288188de56ccSmrg
288288de56ccSmrg
288388de56ccSmrg# func_execute_cmds commands fail_cmd
288488de56ccSmrg# Execute tilde-delimited COMMANDS.
288588de56ccSmrg# If FAIL_CMD is given, eval that upon failure.
288688de56ccSmrg# FAIL_CMD may read-access the current command in variable CMD!
288788de56ccSmrgfunc_execute_cmds ()
288888de56ccSmrg{
2889862bcd1aSmrg    $debug_cmd
2890862bcd1aSmrg
289188de56ccSmrg    save_ifs=$IFS; IFS='~'
289288de56ccSmrg    for cmd in $1; do
2893862bcd1aSmrg      IFS=$sp$nl
289488de56ccSmrg      eval cmd=\"$cmd\"
2895862bcd1aSmrg      IFS=$save_ifs
289688de56ccSmrg      func_show_eval "$cmd" "${2-:}"
289788de56ccSmrg    done
289888de56ccSmrg    IFS=$save_ifs
289988de56ccSmrg}
290088de56ccSmrg
290188de56ccSmrg
290288de56ccSmrg# func_source file
290388de56ccSmrg# Source FILE, adding directory component if necessary.
290488de56ccSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
290588de56ccSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
290688de56ccSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2907862bcd1aSmrg# 'FILE.' does not work on cygwin managed mounts.
290888de56ccSmrgfunc_source ()
290988de56ccSmrg{
2910862bcd1aSmrg    $debug_cmd
2911862bcd1aSmrg
291288de56ccSmrg    case $1 in
291388de56ccSmrg    */* | *\\*)	. "$1" ;;
291488de56ccSmrg    *)		. "./$1" ;;
291588de56ccSmrg    esac
291688de56ccSmrg}
291788de56ccSmrg
291888de56ccSmrg
2919e9fcaa8aSmrg# func_resolve_sysroot PATH
2920e9fcaa8aSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2921e9fcaa8aSmrg# func_resolve_sysroot_result
2922e9fcaa8aSmrgfunc_resolve_sysroot ()
2923e9fcaa8aSmrg{
2924e9fcaa8aSmrg  func_resolve_sysroot_result=$1
2925e9fcaa8aSmrg  case $func_resolve_sysroot_result in
2926e9fcaa8aSmrg  =*)
2927e9fcaa8aSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2928e9fcaa8aSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2929e9fcaa8aSmrg    ;;
2930e9fcaa8aSmrg  esac
2931e9fcaa8aSmrg}
2932e9fcaa8aSmrg
2933e9fcaa8aSmrg# func_replace_sysroot PATH
2934e9fcaa8aSmrg# If PATH begins with the sysroot, replace it with = and
2935e9fcaa8aSmrg# store the result into func_replace_sysroot_result.
2936e9fcaa8aSmrgfunc_replace_sysroot ()
2937e9fcaa8aSmrg{
2938862bcd1aSmrg  case $lt_sysroot:$1 in
2939e9fcaa8aSmrg  ?*:"$lt_sysroot"*)
2940e9fcaa8aSmrg    func_stripname "$lt_sysroot" '' "$1"
2941862bcd1aSmrg    func_replace_sysroot_result='='$func_stripname_result
2942e9fcaa8aSmrg    ;;
2943e9fcaa8aSmrg  *)
2944e9fcaa8aSmrg    # Including no sysroot.
2945e9fcaa8aSmrg    func_replace_sysroot_result=$1
2946e9fcaa8aSmrg    ;;
2947e9fcaa8aSmrg  esac
2948e9fcaa8aSmrg}
2949e9fcaa8aSmrg
295088de56ccSmrg# func_infer_tag arg
295188de56ccSmrg# Infer tagged configuration to use if any are available and
295288de56ccSmrg# if one wasn't chosen via the "--tag" command line option.
295388de56ccSmrg# Only attempt this if the compiler in the base compile
295488de56ccSmrg# command doesn't match the default compiler.
295588de56ccSmrg# arg is usually of the form 'gcc ...'
295688de56ccSmrgfunc_infer_tag ()
295788de56ccSmrg{
2958862bcd1aSmrg    $debug_cmd
2959862bcd1aSmrg
296088de56ccSmrg    if test -n "$available_tags" && test -z "$tagname"; then
296188de56ccSmrg      CC_quoted=
296288de56ccSmrg      for arg in $CC; do
2963e9fcaa8aSmrg	func_append_quoted CC_quoted "$arg"
296488de56ccSmrg      done
2965e9fcaa8aSmrg      CC_expanded=`func_echo_all $CC`
2966e9fcaa8aSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
296788de56ccSmrg      case $@ in
296888de56ccSmrg      # Blanks in the command may have been stripped by the calling shell,
296988de56ccSmrg      # but not from the CC environment variable when configure was run.
2970e9fcaa8aSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2971e9fcaa8aSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
297288de56ccSmrg      # Blanks at the start of $base_compile will cause this to fail
297388de56ccSmrg      # if we don't check for them as well.
297488de56ccSmrg      *)
297588de56ccSmrg	for z in $available_tags; do
297688de56ccSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
297788de56ccSmrg	    # Evaluate the configuration.
2978862bcd1aSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
297988de56ccSmrg	    CC_quoted=
298088de56ccSmrg	    for arg in $CC; do
298188de56ccSmrg	      # Double-quote args containing other shell metacharacters.
2982e9fcaa8aSmrg	      func_append_quoted CC_quoted "$arg"
298388de56ccSmrg	    done
2984e9fcaa8aSmrg	    CC_expanded=`func_echo_all $CC`
2985e9fcaa8aSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
298688de56ccSmrg	    case "$@ " in
2987e9fcaa8aSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2988e9fcaa8aSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
298988de56ccSmrg	      # The compiler in the base compile command matches
299088de56ccSmrg	      # the one in the tagged configuration.
299188de56ccSmrg	      # Assume this is the tagged configuration we want.
299288de56ccSmrg	      tagname=$z
299388de56ccSmrg	      break
299488de56ccSmrg	      ;;
299588de56ccSmrg	    esac
299688de56ccSmrg	  fi
299788de56ccSmrg	done
299888de56ccSmrg	# If $tagname still isn't set, then no tagged configuration
299988de56ccSmrg	# was found and let the user know that the "--tag" command
300088de56ccSmrg	# line option must be used.
300188de56ccSmrg	if test -z "$tagname"; then
300288de56ccSmrg	  func_echo "unable to infer tagged configuration"
3003862bcd1aSmrg	  func_fatal_error "specify a tag with '--tag'"
300488de56ccSmrg#	else
300588de56ccSmrg#	  func_verbose "using $tagname tagged configuration"
300688de56ccSmrg	fi
300788de56ccSmrg	;;
300888de56ccSmrg      esac
300988de56ccSmrg    fi
301088de56ccSmrg}
301188de56ccSmrg
301288de56ccSmrg
301388de56ccSmrg
301488de56ccSmrg# func_write_libtool_object output_name pic_name nonpic_name
301588de56ccSmrg# Create a libtool object file (analogous to a ".la" file),
301688de56ccSmrg# but don't create it if we're doing a dry run.
301788de56ccSmrgfunc_write_libtool_object ()
301888de56ccSmrg{
3019862bcd1aSmrg    write_libobj=$1
3020862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
3021862bcd1aSmrg      write_lobj=\'$2\'
302288de56ccSmrg    else
302388de56ccSmrg      write_lobj=none
302488de56ccSmrg    fi
302588de56ccSmrg
3026862bcd1aSmrg    if test yes = "$build_old_libs"; then
3027862bcd1aSmrg      write_oldobj=\'$3\'
302888de56ccSmrg    else
302988de56ccSmrg      write_oldobj=none
303088de56ccSmrg    fi
303188de56ccSmrg
303288de56ccSmrg    $opt_dry_run || {
303388de56ccSmrg      cat >${write_libobj}T <<EOF
303488de56ccSmrg# $write_libobj - a libtool object file
3035862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
303688de56ccSmrg#
303788de56ccSmrg# Please DO NOT delete this file!
303888de56ccSmrg# It is necessary for linking the library.
303988de56ccSmrg
304088de56ccSmrg# Name of the PIC object.
304188de56ccSmrgpic_object=$write_lobj
304288de56ccSmrg
304388de56ccSmrg# Name of the non-PIC object
304488de56ccSmrgnon_pic_object=$write_oldobj
304588de56ccSmrg
304688de56ccSmrgEOF
3047862bcd1aSmrg      $MV "${write_libobj}T" "$write_libobj"
304888de56ccSmrg    }
304988de56ccSmrg}
305088de56ccSmrg
3051e9fcaa8aSmrg
3052e9fcaa8aSmrg##################################################
3053e9fcaa8aSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3054e9fcaa8aSmrg##################################################
3055e9fcaa8aSmrg
3056e9fcaa8aSmrg# func_convert_core_file_wine_to_w32 ARG
3057e9fcaa8aSmrg# Helper function used by file name conversion functions when $build is *nix,
305807fb9b8fSmrg# and $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
3059e9fcaa8aSmrg# correctly configured wine environment available, with the winepath program
3060e9fcaa8aSmrg# in $build's $PATH.
3061e9fcaa8aSmrg#
3062e9fcaa8aSmrg# ARG is the $build file name to be converted to w32 format.
3063e9fcaa8aSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3064e9fcaa8aSmrg# be empty on error (or when ARG is empty)
3065e9fcaa8aSmrgfunc_convert_core_file_wine_to_w32 ()
3066e9fcaa8aSmrg{
3067862bcd1aSmrg  $debug_cmd
3068862bcd1aSmrg
3069862bcd1aSmrg  func_convert_core_file_wine_to_w32_result=$1
3070e9fcaa8aSmrg  if test -n "$1"; then
3071e9fcaa8aSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3072e9fcaa8aSmrg    # are forced to check the contents of stdout. On the other hand, if the
3073e9fcaa8aSmrg    # command is not found, the shell will set an exit code of 127 and print
3074e9fcaa8aSmrg    # *an error message* to stdout. So we must check for both error code of
3075e9fcaa8aSmrg    # zero AND non-empty stdout, which explains the odd construction:
3076e9fcaa8aSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3077862bcd1aSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3078e9fcaa8aSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3079862bcd1aSmrg        $SED -e "$sed_naive_backslashify"`
3080e9fcaa8aSmrg    else
3081e9fcaa8aSmrg      func_convert_core_file_wine_to_w32_result=
3082e9fcaa8aSmrg    fi
3083e9fcaa8aSmrg  fi
3084e9fcaa8aSmrg}
3085e9fcaa8aSmrg# end: func_convert_core_file_wine_to_w32
3086e9fcaa8aSmrg
3087e9fcaa8aSmrg
3088e9fcaa8aSmrg# func_convert_core_path_wine_to_w32 ARG
3089e9fcaa8aSmrg# Helper function used by path conversion functions when $build is *nix, and
309007fb9b8fSmrg# $host is mingw, windows, cygwin, or some other w32 environment. Relies on a
309107fb9b8fSmrg# correctly configured wine environment available, with the winepath program
309207fb9b8fSmrg# in $build's $PATH. Assumes ARG has no leading or trailing path separator
309307fb9b8fSmrg# characters.
3094e9fcaa8aSmrg#
3095e9fcaa8aSmrg# ARG is path to be converted from $build format to win32.
3096e9fcaa8aSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3097e9fcaa8aSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3098e9fcaa8aSmrg# are convertible, then the result may be empty.
3099e9fcaa8aSmrgfunc_convert_core_path_wine_to_w32 ()
3100e9fcaa8aSmrg{
3101862bcd1aSmrg  $debug_cmd
3102862bcd1aSmrg
3103e9fcaa8aSmrg  # unfortunately, winepath doesn't convert paths, only file names
3104862bcd1aSmrg  func_convert_core_path_wine_to_w32_result=
3105e9fcaa8aSmrg  if test -n "$1"; then
3106e9fcaa8aSmrg    oldIFS=$IFS
3107e9fcaa8aSmrg    IFS=:
3108e9fcaa8aSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3109e9fcaa8aSmrg      IFS=$oldIFS
3110e9fcaa8aSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3111862bcd1aSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3112e9fcaa8aSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3113862bcd1aSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3114e9fcaa8aSmrg        else
3115e9fcaa8aSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3116e9fcaa8aSmrg        fi
3117e9fcaa8aSmrg      fi
3118e9fcaa8aSmrg    done
3119e9fcaa8aSmrg    IFS=$oldIFS
3120e9fcaa8aSmrg  fi
3121e9fcaa8aSmrg}
3122e9fcaa8aSmrg# end: func_convert_core_path_wine_to_w32
3123e9fcaa8aSmrg
3124e9fcaa8aSmrg
3125e9fcaa8aSmrg# func_cygpath ARGS...
3126e9fcaa8aSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3127e9fcaa8aSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3128e9fcaa8aSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3129e9fcaa8aSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3130e9fcaa8aSmrg# file name or path is assumed to be in w32 format, as previously converted
3131e9fcaa8aSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3132e9fcaa8aSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3133e9fcaa8aSmrg# Cygwin format). Returns an empty string on error.
3134e9fcaa8aSmrg#
3135e9fcaa8aSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3136e9fcaa8aSmrg# be converted.
3137e9fcaa8aSmrg#
3138e9fcaa8aSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3139e9fcaa8aSmrg# environment variable; do not put it in $PATH.
3140e9fcaa8aSmrgfunc_cygpath ()
3141e9fcaa8aSmrg{
3142862bcd1aSmrg  $debug_cmd
3143862bcd1aSmrg
3144e9fcaa8aSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3145e9fcaa8aSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3146e9fcaa8aSmrg    if test "$?" -ne 0; then
3147e9fcaa8aSmrg      # on failure, ensure result is empty
3148e9fcaa8aSmrg      func_cygpath_result=
3149e9fcaa8aSmrg    fi
3150e9fcaa8aSmrg  else
3151e9fcaa8aSmrg    func_cygpath_result=
3152862bcd1aSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3153e9fcaa8aSmrg  fi
3154e9fcaa8aSmrg}
3155e9fcaa8aSmrg#end: func_cygpath
3156e9fcaa8aSmrg
3157e9fcaa8aSmrg
3158e9fcaa8aSmrg# func_convert_core_msys_to_w32 ARG
3159e9fcaa8aSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3160e9fcaa8aSmrg# result in func_convert_core_msys_to_w32_result.
3161e9fcaa8aSmrgfunc_convert_core_msys_to_w32 ()
3162e9fcaa8aSmrg{
3163862bcd1aSmrg  $debug_cmd
3164862bcd1aSmrg
3165e9fcaa8aSmrg  # awkward: cmd appends spaces to result
3166e9fcaa8aSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3167862bcd1aSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3168e9fcaa8aSmrg}
3169e9fcaa8aSmrg#end: func_convert_core_msys_to_w32
3170e9fcaa8aSmrg
3171e9fcaa8aSmrg
3172e9fcaa8aSmrg# func_convert_file_check ARG1 ARG2
3173e9fcaa8aSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3174e9fcaa8aSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3175e9fcaa8aSmrg# func_to_host_file_result to ARG1).
3176e9fcaa8aSmrgfunc_convert_file_check ()
3177e9fcaa8aSmrg{
3178862bcd1aSmrg  $debug_cmd
3179862bcd1aSmrg
3180862bcd1aSmrg  if test -z "$2" && test -n "$1"; then
3181e9fcaa8aSmrg    func_error "Could not determine host file name corresponding to"
3182862bcd1aSmrg    func_error "  '$1'"
3183e9fcaa8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3184e9fcaa8aSmrg    # Fallback:
3185862bcd1aSmrg    func_to_host_file_result=$1
3186e9fcaa8aSmrg  fi
3187e9fcaa8aSmrg}
3188e9fcaa8aSmrg# end func_convert_file_check
3189e9fcaa8aSmrg
3190e9fcaa8aSmrg
3191e9fcaa8aSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3192e9fcaa8aSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3193e9fcaa8aSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3194e9fcaa8aSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3195e9fcaa8aSmrgfunc_convert_path_check ()
3196e9fcaa8aSmrg{
3197862bcd1aSmrg  $debug_cmd
3198862bcd1aSmrg
3199e9fcaa8aSmrg  if test -z "$4" && test -n "$3"; then
3200e9fcaa8aSmrg    func_error "Could not determine the host path corresponding to"
3201862bcd1aSmrg    func_error "  '$3'"
3202e9fcaa8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3203e9fcaa8aSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3204e9fcaa8aSmrg    # should not be "improved".  See libtool.info.
3205e9fcaa8aSmrg    if test "x$1" != "x$2"; then
3206e9fcaa8aSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3207e9fcaa8aSmrg      func_to_host_path_result=`echo "$3" |
3208e9fcaa8aSmrg        $SED -e "$lt_replace_pathsep_chars"`
3209e9fcaa8aSmrg    else
3210862bcd1aSmrg      func_to_host_path_result=$3
3211e9fcaa8aSmrg    fi
3212e9fcaa8aSmrg  fi
3213e9fcaa8aSmrg}
3214e9fcaa8aSmrg# end func_convert_path_check
3215e9fcaa8aSmrg
3216e9fcaa8aSmrg
3217e9fcaa8aSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3218e9fcaa8aSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3219e9fcaa8aSmrg# and appending REPL if ORIG matches BACKPAT.
3220e9fcaa8aSmrgfunc_convert_path_front_back_pathsep ()
3221e9fcaa8aSmrg{
3222862bcd1aSmrg  $debug_cmd
3223862bcd1aSmrg
3224e9fcaa8aSmrg  case $4 in
3225862bcd1aSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3226e9fcaa8aSmrg    ;;
3227e9fcaa8aSmrg  esac
3228e9fcaa8aSmrg  case $4 in
3229e9fcaa8aSmrg  $2 ) func_append func_to_host_path_result "$3"
3230e9fcaa8aSmrg    ;;
3231e9fcaa8aSmrg  esac
3232e9fcaa8aSmrg}
3233e9fcaa8aSmrg# end func_convert_path_front_back_pathsep
3234e9fcaa8aSmrg
3235e9fcaa8aSmrg
323607fb9b8fSmrg# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER
323707fb9b8fSmrg# Replaces a delimiter for a given path.
323807fb9b8fSmrgfunc_convert_delimited_path ()
323907fb9b8fSmrg{
324007fb9b8fSmrg	converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"`
324107fb9b8fSmrg}
324207fb9b8fSmrg# end func_convert_delimited_path
324307fb9b8fSmrg
324407fb9b8fSmrg
3245e9fcaa8aSmrg##################################################
3246e9fcaa8aSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3247e9fcaa8aSmrg##################################################
3248862bcd1aSmrg# invoked via '$to_host_file_cmd ARG'
3249e9fcaa8aSmrg#
3250e9fcaa8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3251e9fcaa8aSmrg# Result will be available in $func_to_host_file_result.
3252e9fcaa8aSmrg
3253e9fcaa8aSmrg
3254e9fcaa8aSmrg# func_to_host_file ARG
3255e9fcaa8aSmrg# Converts the file name ARG from $build format to $host format. Return result
3256e9fcaa8aSmrg# in func_to_host_file_result.
3257e9fcaa8aSmrgfunc_to_host_file ()
3258e9fcaa8aSmrg{
3259862bcd1aSmrg  $debug_cmd
3260862bcd1aSmrg
3261e9fcaa8aSmrg  $to_host_file_cmd "$1"
3262e9fcaa8aSmrg}
3263e9fcaa8aSmrg# end func_to_host_file
3264e9fcaa8aSmrg
3265e9fcaa8aSmrg
3266e9fcaa8aSmrg# func_to_tool_file ARG LAZY
3267e9fcaa8aSmrg# converts the file name ARG from $build format to toolchain format. Return
3268e9fcaa8aSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3269e9fcaa8aSmrg# in (the comma separated) LAZY, no conversion takes place.
3270e9fcaa8aSmrgfunc_to_tool_file ()
3271e9fcaa8aSmrg{
3272862bcd1aSmrg  $debug_cmd
3273862bcd1aSmrg
3274e9fcaa8aSmrg  case ,$2, in
3275e9fcaa8aSmrg    *,"$to_tool_file_cmd",*)
3276e9fcaa8aSmrg      func_to_tool_file_result=$1
3277e9fcaa8aSmrg      ;;
3278e9fcaa8aSmrg    *)
3279e9fcaa8aSmrg      $to_tool_file_cmd "$1"
3280e9fcaa8aSmrg      func_to_tool_file_result=$func_to_host_file_result
3281e9fcaa8aSmrg      ;;
3282e9fcaa8aSmrg  esac
3283e9fcaa8aSmrg}
3284e9fcaa8aSmrg# end func_to_tool_file
3285e9fcaa8aSmrg
3286e9fcaa8aSmrg
3287e9fcaa8aSmrg# func_convert_file_noop ARG
3288e9fcaa8aSmrg# Copy ARG to func_to_host_file_result.
3289e9fcaa8aSmrgfunc_convert_file_noop ()
3290e9fcaa8aSmrg{
3291862bcd1aSmrg  func_to_host_file_result=$1
3292e9fcaa8aSmrg}
3293e9fcaa8aSmrg# end func_convert_file_noop
3294e9fcaa8aSmrg
3295e9fcaa8aSmrg
3296e9fcaa8aSmrg# func_convert_file_msys_to_w32 ARG
3297e9fcaa8aSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3298e9fcaa8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3299e9fcaa8aSmrg# func_to_host_file_result.
3300e9fcaa8aSmrgfunc_convert_file_msys_to_w32 ()
3301e9fcaa8aSmrg{
3302862bcd1aSmrg  $debug_cmd
3303862bcd1aSmrg
3304862bcd1aSmrg  func_to_host_file_result=$1
3305e9fcaa8aSmrg  if test -n "$1"; then
3306e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$1"
3307862bcd1aSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3308e9fcaa8aSmrg  fi
3309e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3310e9fcaa8aSmrg}
3311e9fcaa8aSmrg# end func_convert_file_msys_to_w32
3312e9fcaa8aSmrg
3313e9fcaa8aSmrg
3314e9fcaa8aSmrg# func_convert_file_cygwin_to_w32 ARG
3315e9fcaa8aSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3316e9fcaa8aSmrg# func_to_host_file_result.
3317e9fcaa8aSmrgfunc_convert_file_cygwin_to_w32 ()
3318e9fcaa8aSmrg{
3319862bcd1aSmrg  $debug_cmd
3320862bcd1aSmrg
3321862bcd1aSmrg  func_to_host_file_result=$1
3322e9fcaa8aSmrg  if test -n "$1"; then
3323e9fcaa8aSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3324e9fcaa8aSmrg    # LT_CYGPATH in this case.
3325e9fcaa8aSmrg    func_to_host_file_result=`cygpath -m "$1"`
3326e9fcaa8aSmrg  fi
3327e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3328e9fcaa8aSmrg}
3329e9fcaa8aSmrg# end func_convert_file_cygwin_to_w32
3330e9fcaa8aSmrg
3331e9fcaa8aSmrg
3332e9fcaa8aSmrg# func_convert_file_nix_to_w32 ARG
3333e9fcaa8aSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3334e9fcaa8aSmrg# and a working winepath. Returns result in func_to_host_file_result.
3335e9fcaa8aSmrgfunc_convert_file_nix_to_w32 ()
3336e9fcaa8aSmrg{
3337862bcd1aSmrg  $debug_cmd
3338862bcd1aSmrg
3339862bcd1aSmrg  func_to_host_file_result=$1
3340e9fcaa8aSmrg  if test -n "$1"; then
3341e9fcaa8aSmrg    func_convert_core_file_wine_to_w32 "$1"
3342862bcd1aSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3343e9fcaa8aSmrg  fi
3344e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3345e9fcaa8aSmrg}
3346e9fcaa8aSmrg# end func_convert_file_nix_to_w32
3347e9fcaa8aSmrg
3348e9fcaa8aSmrg
3349e9fcaa8aSmrg# func_convert_file_msys_to_cygwin ARG
3350e9fcaa8aSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3351e9fcaa8aSmrg# Returns result in func_to_host_file_result.
3352e9fcaa8aSmrgfunc_convert_file_msys_to_cygwin ()
3353e9fcaa8aSmrg{
3354862bcd1aSmrg  $debug_cmd
3355862bcd1aSmrg
3356862bcd1aSmrg  func_to_host_file_result=$1
3357e9fcaa8aSmrg  if test -n "$1"; then
3358e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$1"
3359e9fcaa8aSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3360862bcd1aSmrg    func_to_host_file_result=$func_cygpath_result
3361e9fcaa8aSmrg  fi
3362e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3363e9fcaa8aSmrg}
3364e9fcaa8aSmrg# end func_convert_file_msys_to_cygwin
3365e9fcaa8aSmrg
3366e9fcaa8aSmrg
3367e9fcaa8aSmrg# func_convert_file_nix_to_cygwin ARG
3368e9fcaa8aSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3369e9fcaa8aSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3370e9fcaa8aSmrg# in func_to_host_file_result.
3371e9fcaa8aSmrgfunc_convert_file_nix_to_cygwin ()
3372e9fcaa8aSmrg{
3373862bcd1aSmrg  $debug_cmd
3374862bcd1aSmrg
3375862bcd1aSmrg  func_to_host_file_result=$1
3376e9fcaa8aSmrg  if test -n "$1"; then
3377e9fcaa8aSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3378e9fcaa8aSmrg    func_convert_core_file_wine_to_w32 "$1"
3379e9fcaa8aSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3380862bcd1aSmrg    func_to_host_file_result=$func_cygpath_result
3381e9fcaa8aSmrg  fi
3382e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3383e9fcaa8aSmrg}
3384e9fcaa8aSmrg# end func_convert_file_nix_to_cygwin
3385e9fcaa8aSmrg
3386e9fcaa8aSmrg
3387e9fcaa8aSmrg#############################################
3388e9fcaa8aSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3389e9fcaa8aSmrg#############################################
3390862bcd1aSmrg# invoked via '$to_host_path_cmd ARG'
3391e9fcaa8aSmrg#
3392e9fcaa8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3393e9fcaa8aSmrg# The result will be available in $func_to_host_path_result.
3394e9fcaa8aSmrg#
3395e9fcaa8aSmrg# Path separators are also converted from $build format to $host format.  If
3396e9fcaa8aSmrg# ARG begins or ends with a path separator character, it is preserved (but
3397e9fcaa8aSmrg# converted to $host format) on output.
3398e9fcaa8aSmrg#
3399e9fcaa8aSmrg# All path conversion functions are named using the following convention:
3400e9fcaa8aSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3401e9fcaa8aSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3402e9fcaa8aSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3403e9fcaa8aSmrg# same.  If conversion functions are added for new $build/$host combinations,
3404e9fcaa8aSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3405e9fcaa8aSmrg# will break.
3406e9fcaa8aSmrg
3407e9fcaa8aSmrg
3408e9fcaa8aSmrg# func_init_to_host_path_cmd
3409e9fcaa8aSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3410e9fcaa8aSmrg# appropriate value, based on the value of $to_host_file_cmd.
3411e9fcaa8aSmrgto_host_path_cmd=
3412e9fcaa8aSmrgfunc_init_to_host_path_cmd ()
3413e9fcaa8aSmrg{
3414862bcd1aSmrg  $debug_cmd
3415862bcd1aSmrg
3416e9fcaa8aSmrg  if test -z "$to_host_path_cmd"; then
3417e9fcaa8aSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3418862bcd1aSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3419e9fcaa8aSmrg  fi
3420e9fcaa8aSmrg}
3421e9fcaa8aSmrg
3422e9fcaa8aSmrg
3423e9fcaa8aSmrg# func_to_host_path ARG
3424e9fcaa8aSmrg# Converts the path ARG from $build format to $host format. Return result
3425e9fcaa8aSmrg# in func_to_host_path_result.
3426e9fcaa8aSmrgfunc_to_host_path ()
3427e9fcaa8aSmrg{
3428862bcd1aSmrg  $debug_cmd
3429862bcd1aSmrg
3430e9fcaa8aSmrg  func_init_to_host_path_cmd
3431e9fcaa8aSmrg  $to_host_path_cmd "$1"
3432e9fcaa8aSmrg}
3433e9fcaa8aSmrg# end func_to_host_path
3434e9fcaa8aSmrg
3435e9fcaa8aSmrg
3436e9fcaa8aSmrg# func_convert_path_noop ARG
3437e9fcaa8aSmrg# Copy ARG to func_to_host_path_result.
3438e9fcaa8aSmrgfunc_convert_path_noop ()
3439e9fcaa8aSmrg{
3440862bcd1aSmrg  func_to_host_path_result=$1
3441e9fcaa8aSmrg}
3442e9fcaa8aSmrg# end func_convert_path_noop
3443e9fcaa8aSmrg
3444e9fcaa8aSmrg
3445e9fcaa8aSmrg# func_convert_path_msys_to_w32 ARG
3446e9fcaa8aSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3447e9fcaa8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3448e9fcaa8aSmrg# func_to_host_path_result.
3449e9fcaa8aSmrgfunc_convert_path_msys_to_w32 ()
3450e9fcaa8aSmrg{
3451862bcd1aSmrg  $debug_cmd
3452862bcd1aSmrg
3453862bcd1aSmrg  func_to_host_path_result=$1
3454e9fcaa8aSmrg  if test -n "$1"; then
3455e9fcaa8aSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3456e9fcaa8aSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3457e9fcaa8aSmrg    # and winepath ignores them completely.
3458e9fcaa8aSmrg    func_stripname : : "$1"
3459e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3460e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3461862bcd1aSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3462e9fcaa8aSmrg    func_convert_path_check : ";" \
3463e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3464e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3465e9fcaa8aSmrg  fi
3466e9fcaa8aSmrg}
3467e9fcaa8aSmrg# end func_convert_path_msys_to_w32
3468e9fcaa8aSmrg
3469e9fcaa8aSmrg
3470e9fcaa8aSmrg# func_convert_path_cygwin_to_w32 ARG
3471e9fcaa8aSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3472e9fcaa8aSmrg# func_to_host_file_result.
3473e9fcaa8aSmrgfunc_convert_path_cygwin_to_w32 ()
3474e9fcaa8aSmrg{
3475862bcd1aSmrg  $debug_cmd
3476862bcd1aSmrg
3477862bcd1aSmrg  func_to_host_path_result=$1
3478e9fcaa8aSmrg  if test -n "$1"; then
3479e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3480e9fcaa8aSmrg    func_stripname : : "$1"
3481e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3482e9fcaa8aSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3483e9fcaa8aSmrg    func_convert_path_check : ";" \
3484e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3485e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3486e9fcaa8aSmrg  fi
3487e9fcaa8aSmrg}
3488e9fcaa8aSmrg# end func_convert_path_cygwin_to_w32
3489e9fcaa8aSmrg
3490e9fcaa8aSmrg
3491e9fcaa8aSmrg# func_convert_path_nix_to_w32 ARG
3492e9fcaa8aSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3493e9fcaa8aSmrg# a working winepath.  Returns result in func_to_host_file_result.
3494e9fcaa8aSmrgfunc_convert_path_nix_to_w32 ()
3495e9fcaa8aSmrg{
3496862bcd1aSmrg  $debug_cmd
3497862bcd1aSmrg
3498862bcd1aSmrg  func_to_host_path_result=$1
3499e9fcaa8aSmrg  if test -n "$1"; then
3500e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3501e9fcaa8aSmrg    func_stripname : : "$1"
3502e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3503e9fcaa8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3504862bcd1aSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3505e9fcaa8aSmrg    func_convert_path_check : ";" \
3506e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3507e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3508e9fcaa8aSmrg  fi
3509e9fcaa8aSmrg}
3510e9fcaa8aSmrg# end func_convert_path_nix_to_w32
3511e9fcaa8aSmrg
3512e9fcaa8aSmrg
3513e9fcaa8aSmrg# func_convert_path_msys_to_cygwin ARG
3514e9fcaa8aSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3515e9fcaa8aSmrg# Returns result in func_to_host_file_result.
3516e9fcaa8aSmrgfunc_convert_path_msys_to_cygwin ()
3517e9fcaa8aSmrg{
3518862bcd1aSmrg  $debug_cmd
3519862bcd1aSmrg
3520862bcd1aSmrg  func_to_host_path_result=$1
3521e9fcaa8aSmrg  if test -n "$1"; then
3522e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3523e9fcaa8aSmrg    func_stripname : : "$1"
3524e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3525e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3526e9fcaa8aSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3527862bcd1aSmrg    func_to_host_path_result=$func_cygpath_result
3528e9fcaa8aSmrg    func_convert_path_check : : \
3529e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3530e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3531e9fcaa8aSmrg  fi
3532e9fcaa8aSmrg}
3533e9fcaa8aSmrg# end func_convert_path_msys_to_cygwin
3534e9fcaa8aSmrg
3535e9fcaa8aSmrg
3536e9fcaa8aSmrg# func_convert_path_nix_to_cygwin ARG
3537e9fcaa8aSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3538e9fcaa8aSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3539e9fcaa8aSmrg# func_to_host_file_result.
3540e9fcaa8aSmrgfunc_convert_path_nix_to_cygwin ()
3541e9fcaa8aSmrg{
3542862bcd1aSmrg  $debug_cmd
3543862bcd1aSmrg
3544862bcd1aSmrg  func_to_host_path_result=$1
3545e9fcaa8aSmrg  if test -n "$1"; then
3546e9fcaa8aSmrg    # Remove leading and trailing path separator characters from
3547e9fcaa8aSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3548e9fcaa8aSmrg    # into '.;' and ';.', and winepath ignores them completely.
3549e9fcaa8aSmrg    func_stripname : : "$1"
3550e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3551e9fcaa8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3552e9fcaa8aSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3553862bcd1aSmrg    func_to_host_path_result=$func_cygpath_result
3554e9fcaa8aSmrg    func_convert_path_check : : \
3555e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3556e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3557e9fcaa8aSmrg  fi
3558e9fcaa8aSmrg}
3559e9fcaa8aSmrg# end func_convert_path_nix_to_cygwin
3560e9fcaa8aSmrg
3561e9fcaa8aSmrg
3562862bcd1aSmrg# func_dll_def_p FILE
3563862bcd1aSmrg# True iff FILE is a Windows DLL '.def' file.
3564862bcd1aSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3565862bcd1aSmrgfunc_dll_def_p ()
3566862bcd1aSmrg{
3567862bcd1aSmrg  $debug_cmd
3568862bcd1aSmrg
3569862bcd1aSmrg  func_dll_def_p_tmp=`$SED -n \
3570862bcd1aSmrg    -e 's/^[	 ]*//' \
3571862bcd1aSmrg    -e '/^\(;.*\)*$/d' \
3572862bcd1aSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3573862bcd1aSmrg    -e q \
3574862bcd1aSmrg    "$1"`
3575862bcd1aSmrg  test DEF = "$func_dll_def_p_tmp"
3576862bcd1aSmrg}
3577862bcd1aSmrg
3578862bcd1aSmrg
357907fb9b8fSmrg# func_reorder_shared_lib_cache DIRS
358007fb9b8fSmrg# Reorder the shared library cache by unconfiguring previous shared library cache
358107fb9b8fSmrg# and configuring preferred search directories before previous search directories.
358207fb9b8fSmrg# Previous shared library cache: /usr/lib /usr/local/lib
358307fb9b8fSmrg# Preferred search directories: /tmp/testing
358407fb9b8fSmrg# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib
358507fb9b8fSmrgfunc_reorder_shared_lib_cache ()
358607fb9b8fSmrg{
358707fb9b8fSmrg	$debug_cmd
358807fb9b8fSmrg
358907fb9b8fSmrg	case $host_os in
359007fb9b8fSmrg	  openbsd*)
359107fb9b8fSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
359207fb9b8fSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
359307fb9b8fSmrg	    save_search_directories=$converted_path
359407fb9b8fSmrg	    func_convert_delimited_path "$1" ':' '\ '
359507fb9b8fSmrg
359607fb9b8fSmrg	    # Ensure directories exist
359707fb9b8fSmrg	    for dir in $converted_path; do
359807fb9b8fSmrg	      # Ensure each directory is an absolute path
359907fb9b8fSmrg	      case $dir in
360007fb9b8fSmrg	        /*) ;;
360107fb9b8fSmrg	        *) func_error "Directory '$dir' is not an absolute path"
360207fb9b8fSmrg	           exit $EXIT_FAILURE ;;
360307fb9b8fSmrg	      esac
360407fb9b8fSmrg	      # Ensure no trailing slashes
360507fb9b8fSmrg	      func_stripname '' '/' "$dir"
360607fb9b8fSmrg	      dir=$func_stripname_result
360707fb9b8fSmrg	      if test -d "$dir"; then
360807fb9b8fSmrg	        if test -n "$preferred_search_directories"; then
360907fb9b8fSmrg	          preferred_search_directories="$preferred_search_directories $dir"
361007fb9b8fSmrg	        else
361107fb9b8fSmrg	          preferred_search_directories=$dir
361207fb9b8fSmrg	        fi
361307fb9b8fSmrg	      else
361407fb9b8fSmrg	        func_error "Directory '$dir' does not exist"
361507fb9b8fSmrg	        exit $EXIT_FAILURE
361607fb9b8fSmrg	      fi
361707fb9b8fSmrg	    done
361807fb9b8fSmrg
361907fb9b8fSmrg	    PATH="$PATH:/sbin" ldconfig -U $save_search_directories
362007fb9b8fSmrg	    PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories
362107fb9b8fSmrg	    get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
362207fb9b8fSmrg	    func_convert_delimited_path "$get_search_directories" ':' '\ '
362307fb9b8fSmrg	    reordered_search_directories=$converted_path
362407fb9b8fSmrg
362507fb9b8fSmrg	    $ECHO "Original: $save_search_directories"
362607fb9b8fSmrg	    $ECHO "Reordered: $reordered_search_directories"
362707fb9b8fSmrg	    exit $EXIT_SUCCESS
362807fb9b8fSmrg	  ;;
362907fb9b8fSmrg	  *)
363007fb9b8fSmrg	    func_error "--reorder-cache is not supported for host_os=$host_os."
363107fb9b8fSmrg	    exit $EXIT_FAILURE
363207fb9b8fSmrg	  ;;
363307fb9b8fSmrg	esac
363407fb9b8fSmrg}
363507fb9b8fSmrg# end func_reorder_shared_lib_cache
363607fb9b8fSmrg
363707fb9b8fSmrg
363888de56ccSmrg# func_mode_compile arg...
363988de56ccSmrgfunc_mode_compile ()
364088de56ccSmrg{
3641862bcd1aSmrg    $debug_cmd
3642862bcd1aSmrg
364388de56ccSmrg    # Get the compilation command and the source file.
364488de56ccSmrg    base_compile=
3645862bcd1aSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
364688de56ccSmrg    suppress_opt=yes
364788de56ccSmrg    suppress_output=
364888de56ccSmrg    arg_mode=normal
364988de56ccSmrg    libobj=
365088de56ccSmrg    later=
365188de56ccSmrg    pie_flag=
365288de56ccSmrg
365388de56ccSmrg    for arg
365488de56ccSmrg    do
365588de56ccSmrg      case $arg_mode in
365688de56ccSmrg      arg  )
365788de56ccSmrg	# do not "continue".  Instead, add this to base_compile
3658862bcd1aSmrg	lastarg=$arg
365988de56ccSmrg	arg_mode=normal
366088de56ccSmrg	;;
366188de56ccSmrg
366288de56ccSmrg      target )
3663862bcd1aSmrg	libobj=$arg
366488de56ccSmrg	arg_mode=normal
366588de56ccSmrg	continue
366688de56ccSmrg	;;
366788de56ccSmrg
366888de56ccSmrg      normal )
366988de56ccSmrg	# Accept any command-line options.
367088de56ccSmrg	case $arg in
367188de56ccSmrg	-o)
367288de56ccSmrg	  test -n "$libobj" && \
3673862bcd1aSmrg	    func_fatal_error "you cannot specify '-o' more than once"
367488de56ccSmrg	  arg_mode=target
367588de56ccSmrg	  continue
367688de56ccSmrg	  ;;
367788de56ccSmrg
367888de56ccSmrg	-pie | -fpie | -fPIE)
3679e9fcaa8aSmrg          func_append pie_flag " $arg"
368088de56ccSmrg	  continue
368188de56ccSmrg	  ;;
368288de56ccSmrg
368388de56ccSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3684e9fcaa8aSmrg	  func_append later " $arg"
368588de56ccSmrg	  continue
368688de56ccSmrg	  ;;
368788de56ccSmrg
368888de56ccSmrg	-no-suppress)
36891ab64890Smrg	  suppress_opt=no
36901ab64890Smrg	  continue
36911ab64890Smrg	  ;;
36921ab64890Smrg
36931ab64890Smrg	-Xcompiler)
36941ab64890Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
36951ab64890Smrg	  continue      #  The current "srcfile" will either be retained or
36961ab64890Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
36971ab64890Smrg
36981ab64890Smrg	-Wc,*)
369988de56ccSmrg	  func_stripname '-Wc,' '' "$arg"
370088de56ccSmrg	  args=$func_stripname_result
37011ab64890Smrg	  lastarg=
3702862bcd1aSmrg	  save_ifs=$IFS; IFS=,
370388de56ccSmrg	  for arg in $args; do
3704862bcd1aSmrg	    IFS=$save_ifs
3705e9fcaa8aSmrg	    func_append_quoted lastarg "$arg"
37061ab64890Smrg	  done
3707862bcd1aSmrg	  IFS=$save_ifs
370888de56ccSmrg	  func_stripname ' ' '' "$lastarg"
370988de56ccSmrg	  lastarg=$func_stripname_result
37101ab64890Smrg
37111ab64890Smrg	  # Add the arguments to base_compile.
3712e9fcaa8aSmrg	  func_append base_compile " $lastarg"
37131ab64890Smrg	  continue
37141ab64890Smrg	  ;;
37151ab64890Smrg
371688de56ccSmrg	*)
37171ab64890Smrg	  # Accept the current argument as the source file.
37181ab64890Smrg	  # The previous "srcfile" becomes the current argument.
37191ab64890Smrg	  #
3720862bcd1aSmrg	  lastarg=$srcfile
3721862bcd1aSmrg	  srcfile=$arg
37221ab64890Smrg	  ;;
37231ab64890Smrg	esac  #  case $arg
37241ab64890Smrg	;;
37251ab64890Smrg      esac    #  case $arg_mode
37261ab64890Smrg
37271ab64890Smrg      # Aesthetically quote the previous argument.
3728e9fcaa8aSmrg      func_append_quoted base_compile "$lastarg"
37291ab64890Smrg    done # for arg
37301ab64890Smrg
37311ab64890Smrg    case $arg_mode in
37321ab64890Smrg    arg)
373388de56ccSmrg      func_fatal_error "you must specify an argument for -Xcompile"
37341ab64890Smrg      ;;
37351ab64890Smrg    target)
3736862bcd1aSmrg      func_fatal_error "you must specify a target with '-o'"
37371ab64890Smrg      ;;
37381ab64890Smrg    *)
37391ab64890Smrg      # Get the name of the library object.
374088de56ccSmrg      test -z "$libobj" && {
374188de56ccSmrg	func_basename "$srcfile"
3742862bcd1aSmrg	libobj=$func_basename_result
374388de56ccSmrg      }
37441ab64890Smrg      ;;
37451ab64890Smrg    esac
37461ab64890Smrg
37471ab64890Smrg    # Recognize several different file suffixes.
37481ab64890Smrg    # If the user specifies -o file.o, it is replaced with file.lo
37491ab64890Smrg    case $libobj in
375088de56ccSmrg    *.[cCFSifmso] | \
375188de56ccSmrg    *.ada | *.adb | *.ads | *.asm | \
375288de56ccSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3753eb411b4bSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
375488de56ccSmrg      func_xform "$libobj"
375588de56ccSmrg      libobj=$func_xform_result
375688de56ccSmrg      ;;
37571ab64890Smrg    esac
37581ab64890Smrg
37591ab64890Smrg    case $libobj in
376088de56ccSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
37611ab64890Smrg    *)
3762862bcd1aSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
37631ab64890Smrg      ;;
37641ab64890Smrg    esac
37651ab64890Smrg
37661ab64890Smrg    func_infer_tag $base_compile
37671ab64890Smrg
37681ab64890Smrg    for arg in $later; do
37691ab64890Smrg      case $arg in
377088de56ccSmrg      -shared)
3771862bcd1aSmrg	test yes = "$build_libtool_libs" \
3772862bcd1aSmrg	  || func_fatal_configuration "cannot build a shared library"
377388de56ccSmrg	build_old_libs=no
377488de56ccSmrg	continue
377588de56ccSmrg	;;
377688de56ccSmrg
37771ab64890Smrg      -static)
377888de56ccSmrg	build_libtool_libs=no
37791ab64890Smrg	build_old_libs=yes
37801ab64890Smrg	continue
37811ab64890Smrg	;;
37821ab64890Smrg
37831ab64890Smrg      -prefer-pic)
37841ab64890Smrg	pic_mode=yes
37851ab64890Smrg	continue
37861ab64890Smrg	;;
37871ab64890Smrg
37881ab64890Smrg      -prefer-non-pic)
37891ab64890Smrg	pic_mode=no
37901ab64890Smrg	continue
37911ab64890Smrg	;;
37921ab64890Smrg      esac
37931ab64890Smrg    done
37941ab64890Smrg
37957d2c738bSmrg    func_quote_arg pretty "$libobj"
37967d2c738bSmrg    test "X$libobj" != "X$func_quote_arg_result" \
379788de56ccSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3798862bcd1aSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
379988de56ccSmrg    func_dirname_and_basename "$obj" "/" ""
3800862bcd1aSmrg    objname=$func_basename_result
3801862bcd1aSmrg    xdir=$func_dirname_result
3802862bcd1aSmrg    lobj=$xdir$objdir/$objname
38031ab64890Smrg
380488de56ccSmrg    test -z "$base_compile" && \
380588de56ccSmrg      func_fatal_help "you must specify a compilation command"
38061ab64890Smrg
38071ab64890Smrg    # Delete any leftover library objects.
3808862bcd1aSmrg    if test yes = "$build_old_libs"; then
38091ab64890Smrg      removelist="$obj $lobj $libobj ${libobj}T"
38101ab64890Smrg    else
38111ab64890Smrg      removelist="$lobj $libobj ${libobj}T"
38121ab64890Smrg    fi
38131ab64890Smrg
38141ab64890Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
38151ab64890Smrg    case $host_os in
381607fb9b8fSmrg    cygwin* | mingw* | windows* | pw32* | os2* | cegcc*)
38171ab64890Smrg      pic_mode=default
38181ab64890Smrg      ;;
38191ab64890Smrg    esac
3820862bcd1aSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
38211ab64890Smrg      # non-PIC code in shared libraries is not supported
38221ab64890Smrg      pic_mode=default
38231ab64890Smrg    fi
38241ab64890Smrg
38251ab64890Smrg    # Calculate the filename of the output object if compiler does
38261ab64890Smrg    # not support -o with -c
3827862bcd1aSmrg    if test no = "$compiler_c_o"; then
3828862bcd1aSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3829862bcd1aSmrg      lockfile=$output_obj.lock
38301ab64890Smrg    else
38311ab64890Smrg      output_obj=
38321ab64890Smrg      need_locks=no
38331ab64890Smrg      lockfile=
38341ab64890Smrg    fi
38351ab64890Smrg
38361ab64890Smrg    # Lock this critical section if it is needed
38371ab64890Smrg    # We use this script file to make the link, it avoids creating a new file
3838862bcd1aSmrg    if test yes = "$need_locks"; then
383988de56ccSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
384088de56ccSmrg	func_echo "Waiting for $lockfile to be removed"
38411ab64890Smrg	sleep 2
38421ab64890Smrg      done
3843862bcd1aSmrg    elif test warn = "$need_locks"; then
38441ab64890Smrg      if test -f "$lockfile"; then
384588de56ccSmrg	$ECHO "\
38461ab64890Smrg*** ERROR, $lockfile exists and contains:
38471ab64890Smrg`cat $lockfile 2>/dev/null`
38481ab64890Smrg
38491ab64890SmrgThis indicates that another process is trying to use the same
38501ab64890Smrgtemporary object file, and libtool could not work around it because
3851862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
38521ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
38531ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
38541ab64890Smrgcompiler."
38551ab64890Smrg
385688de56ccSmrg	$opt_dry_run || $RM $removelist
38571ab64890Smrg	exit $EXIT_FAILURE
38581ab64890Smrg      fi
3859e9fcaa8aSmrg      func_append removelist " $output_obj"
386088de56ccSmrg      $ECHO "$srcfile" > "$lockfile"
38611ab64890Smrg    fi
38621ab64890Smrg
386388de56ccSmrg    $opt_dry_run || $RM $removelist
3864e9fcaa8aSmrg    func_append removelist " $lockfile"
386588de56ccSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
386688de56ccSmrg
3867e9fcaa8aSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3868e9fcaa8aSmrg    srcfile=$func_to_tool_file_result
38697d2c738bSmrg    func_quote_arg pretty "$srcfile"
38707d2c738bSmrg    qsrcfile=$func_quote_arg_result
38711ab64890Smrg
38721ab64890Smrg    # Only build a PIC object if we are building libtool libraries.
3873862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
38741ab64890Smrg      # Without this assignment, base_compile gets emptied.
38751ab64890Smrg      fbsd_hideous_sh_bug=$base_compile
38761ab64890Smrg
3877862bcd1aSmrg      if test no != "$pic_mode"; then
38781ab64890Smrg	command="$base_compile $qsrcfile $pic_flag"
38791ab64890Smrg      else
38801ab64890Smrg	# Don't build PIC code
38811ab64890Smrg	command="$base_compile $qsrcfile"
38821ab64890Smrg      fi
38831ab64890Smrg
388488de56ccSmrg      func_mkdir_p "$xdir$objdir"
38851ab64890Smrg
38861ab64890Smrg      if test -z "$output_obj"; then
38871ab64890Smrg	# Place PIC objects in $objdir
3888e9fcaa8aSmrg	func_append command " -o $lobj"
38891ab64890Smrg      fi
38901ab64890Smrg
389188de56ccSmrg      func_show_eval_locale "$command"	\
389288de56ccSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
38931ab64890Smrg
3894862bcd1aSmrg      if test warn = "$need_locks" &&
38951ab64890Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
389688de56ccSmrg	$ECHO "\
38971ab64890Smrg*** ERROR, $lockfile contains:
38981ab64890Smrg`cat $lockfile 2>/dev/null`
38991ab64890Smrg
39001ab64890Smrgbut it should contain:
39011ab64890Smrg$srcfile
39021ab64890Smrg
39031ab64890SmrgThis indicates that another process is trying to use the same
39041ab64890Smrgtemporary object file, and libtool could not work around it because
3905862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
39061ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
39071ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
39081ab64890Smrgcompiler."
39091ab64890Smrg
391088de56ccSmrg	$opt_dry_run || $RM $removelist
39111ab64890Smrg	exit $EXIT_FAILURE
39121ab64890Smrg      fi
39131ab64890Smrg
39141ab64890Smrg      # Just move the object if needed, then go on to compile the next one
39151ab64890Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
391688de56ccSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
391788de56ccSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
39181ab64890Smrg      fi
39191ab64890Smrg
39201ab64890Smrg      # Allow error messages only from the first compilation.
3921862bcd1aSmrg      if test yes = "$suppress_opt"; then
392288de56ccSmrg	suppress_output=' >/dev/null 2>&1'
39231ab64890Smrg      fi
39241ab64890Smrg    fi
39251ab64890Smrg
39261ab64890Smrg    # Only build a position-dependent object if we build old libraries.
3927862bcd1aSmrg    if test yes = "$build_old_libs"; then
3928862bcd1aSmrg      if test yes != "$pic_mode"; then
39291ab64890Smrg	# Don't build PIC code
393088de56ccSmrg	command="$base_compile $qsrcfile$pie_flag"
39311ab64890Smrg      else
39321ab64890Smrg	command="$base_compile $qsrcfile $pic_flag"
39331ab64890Smrg      fi
3934862bcd1aSmrg      if test yes = "$compiler_c_o"; then
3935e9fcaa8aSmrg	func_append command " -o $obj"
39361ab64890Smrg      fi
39371ab64890Smrg
39381ab64890Smrg      # Suppress compiler output if we already did a PIC compilation.
3939e9fcaa8aSmrg      func_append command "$suppress_output"
394088de56ccSmrg      func_show_eval_locale "$command" \
394188de56ccSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
39421ab64890Smrg
3943862bcd1aSmrg      if test warn = "$need_locks" &&
39441ab64890Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
394588de56ccSmrg	$ECHO "\
39461ab64890Smrg*** ERROR, $lockfile contains:
39471ab64890Smrg`cat $lockfile 2>/dev/null`
39481ab64890Smrg
39491ab64890Smrgbut it should contain:
39501ab64890Smrg$srcfile
39511ab64890Smrg
39521ab64890SmrgThis indicates that another process is trying to use the same
39531ab64890Smrgtemporary object file, and libtool could not work around it because
3954862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
39551ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
39561ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
39571ab64890Smrgcompiler."
39581ab64890Smrg
395988de56ccSmrg	$opt_dry_run || $RM $removelist
39601ab64890Smrg	exit $EXIT_FAILURE
39611ab64890Smrg      fi
39621ab64890Smrg
39631ab64890Smrg      # Just move the object if needed
39641ab64890Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
396588de56ccSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
396688de56ccSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
39671ab64890Smrg      fi
39681ab64890Smrg    fi
39691ab64890Smrg
397088de56ccSmrg    $opt_dry_run || {
397188de56ccSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
39721ab64890Smrg
397388de56ccSmrg      # Unlock the critical section if it was locked
3974862bcd1aSmrg      if test no != "$need_locks"; then
397588de56ccSmrg	removelist=$lockfile
397688de56ccSmrg        $RM "$lockfile"
397788de56ccSmrg      fi
397888de56ccSmrg    }
39791ab64890Smrg
39801ab64890Smrg    exit $EXIT_SUCCESS
398188de56ccSmrg}
39821ab64890Smrg
398388de56ccSmrg$opt_help || {
3984862bcd1aSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
398588de56ccSmrg}
39861ab64890Smrg
398788de56ccSmrgfunc_mode_help ()
398888de56ccSmrg{
398988de56ccSmrg    # We need to display help for each of the modes.
3990e9fcaa8aSmrg    case $opt_mode in
399188de56ccSmrg      "")
399288de56ccSmrg        # Generic help is extracted from the usage comments
399388de56ccSmrg        # at the start of this file.
399488de56ccSmrg        func_help
399588de56ccSmrg        ;;
39961ab64890Smrg
399788de56ccSmrg      clean)
399888de56ccSmrg        $ECHO \
399988de56ccSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
40001ab64890Smrg
400188de56ccSmrgRemove files from the build directory.
40021ab64890Smrg
400388de56ccSmrgRM is the name of the program to use to delete files associated with each FILE
4004862bcd1aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
400588de56ccSmrgto RM.
40061ab64890Smrg
400788de56ccSmrgIf FILE is a libtool library, object or program, all the files associated
400888de56ccSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
400988de56ccSmrg        ;;
40101ab64890Smrg
401188de56ccSmrg      compile)
401288de56ccSmrg      $ECHO \
401388de56ccSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
40141ab64890Smrg
401588de56ccSmrgCompile a source file into a libtool library object.
40161ab64890Smrg
401788de56ccSmrgThis mode accepts the following additional options:
40181ab64890Smrg
401988de56ccSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
402088de56ccSmrg  -no-suppress      do not suppress compiler output for multiple passes
4021e9fcaa8aSmrg  -prefer-pic       try to build PIC objects only
4022e9fcaa8aSmrg  -prefer-non-pic   try to build non-PIC objects only
4023862bcd1aSmrg  -shared           do not build a '.o' file suitable for static linking
4024862bcd1aSmrg  -static           only build a '.o' file suitable for static linking
40257d2c738bSmrg  -Wc,FLAG
40267d2c738bSmrg  -Xcompiler FLAG   pass FLAG directly to the compiler
40271ab64890Smrg
4028862bcd1aSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
402988de56ccSmrgfrom the given SOURCEFILE.
40301ab64890Smrg
403188de56ccSmrgThe output file name is determined by removing the directory component from
4032862bcd1aSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
4033862bcd1aSmrglibrary object suffix, '.lo'."
403488de56ccSmrg        ;;
40351ab64890Smrg
403688de56ccSmrg      execute)
403788de56ccSmrg        $ECHO \
403888de56ccSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
40391ab64890Smrg
404088de56ccSmrgAutomatically set library path, then run a program.
40411ab64890Smrg
404288de56ccSmrgThis mode accepts the following additional options:
40431ab64890Smrg
404488de56ccSmrg  -dlopen FILE      add the directory containing FILE to the library path
40451ab64890Smrg
4046862bcd1aSmrgThis mode sets the library path environment variable according to '-dlopen'
404788de56ccSmrgflags.
40481ab64890Smrg
404988de56ccSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
405088de56ccSmrginto their corresponding uninstalled binary, and any of their required library
405188de56ccSmrgdirectories are added to the library path.
40521ab64890Smrg
405388de56ccSmrgThen, COMMAND is executed, with ARGS as arguments."
405488de56ccSmrg        ;;
40551ab64890Smrg
405688de56ccSmrg      finish)
405788de56ccSmrg        $ECHO \
405888de56ccSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
40591ab64890Smrg
406088de56ccSmrgComplete the installation of libtool libraries.
40611ab64890Smrg
406288de56ccSmrgEach LIBDIR is a directory that contains libtool libraries.
40631ab64890Smrg
406488de56ccSmrgThe commands that this mode executes may require superuser privileges.  Use
4065862bcd1aSmrgthe '--dry-run' option if you just want to see what would be executed."
406688de56ccSmrg        ;;
40671ab64890Smrg
406888de56ccSmrg      install)
406988de56ccSmrg        $ECHO \
407088de56ccSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
40711ab64890Smrg
407288de56ccSmrgInstall executables or libraries.
40731ab64890Smrg
407488de56ccSmrgINSTALL-COMMAND is the installation command.  The first component should be
4075862bcd1aSmrgeither the 'install' or 'cp' program.
40761ab64890Smrg
407788de56ccSmrgThe following components of INSTALL-COMMAND are treated specially:
40781ab64890Smrg
4079e9fcaa8aSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
40801ab64890Smrg
408188de56ccSmrgThe rest of the components are interpreted as arguments to that command (only
408288de56ccSmrgBSD-compatible install options are recognized)."
408388de56ccSmrg        ;;
40841ab64890Smrg
408588de56ccSmrg      link)
408688de56ccSmrg        $ECHO \
408788de56ccSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
40881ab64890Smrg
408988de56ccSmrgLink object files or libraries together to form another library, or to
409088de56ccSmrgcreate an executable program.
40911ab64890Smrg
409288de56ccSmrgLINK-COMMAND is a command using the C compiler that you would use to create
409388de56ccSmrga program from several object files.
40941ab64890Smrg
409588de56ccSmrgThe following components of LINK-COMMAND are treated specially:
40961ab64890Smrg
409788de56ccSmrg  -all-static       do not do any dynamic linking at all
409888de56ccSmrg  -avoid-version    do not add a version suffix if possible
4099e9fcaa8aSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
4100e9fcaa8aSmrg                    libraries must be found in the PATH setting at runtime)
4101862bcd1aSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
410288de56ccSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
410388de56ccSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
410488de56ccSmrg  -export-symbols SYMFILE
410588de56ccSmrg                    try to export only the symbols listed in SYMFILE
410688de56ccSmrg  -export-symbols-regex REGEX
410788de56ccSmrg                    try to export only the symbols matching REGEX
410888de56ccSmrg  -LLIBDIR          search LIBDIR for required installed libraries
410988de56ccSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
411088de56ccSmrg  -module           build a library that can dlopened
411188de56ccSmrg  -no-fast-install  disable the fast-install mode
411288de56ccSmrg  -no-install       link a not-installable executable
411388de56ccSmrg  -no-undefined     declare that a library does not refer to external symbols
411488de56ccSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
4115862bcd1aSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
4116862bcd1aSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
411788de56ccSmrg  -precious-files-regex REGEX
411888de56ccSmrg                    don't remove output files matching REGEX
411988de56ccSmrg  -release RELEASE  specify package release information
412088de56ccSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
412188de56ccSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
412288de56ccSmrg  -shared           only do dynamic linking of libtool libraries
412388de56ccSmrg  -shrext SUFFIX    override the standard shared library file extension
412488de56ccSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
412588de56ccSmrg  -static-libtool-libs
412688de56ccSmrg                    do not do any dynamic linking of libtool libraries
412788de56ccSmrg  -version-info CURRENT[:REVISION[:AGE]]
412888de56ccSmrg                    specify library version info [each variable defaults to 0]
412988de56ccSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4130e9fcaa8aSmrg  -Wc,FLAG
4131e9fcaa8aSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
41327d2c738bSmrg  -Wa,FLAG
41337d2c738bSmrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4134e9fcaa8aSmrg  -Wl,FLAG
4135e9fcaa8aSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4136e9fcaa8aSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
41371ab64890Smrg
4138862bcd1aSmrgAll other options (arguments beginning with '-') are ignored.
41391ab64890Smrg
4140862bcd1aSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
414188de56ccSmrgtreated as uninstalled libtool libraries, other files are standard or library
414288de56ccSmrgobject files.
41431ab64890Smrg
4144862bcd1aSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4145862bcd1aSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
414688de56ccSmrgrequired, except when creating a convenience library.
41471ab64890Smrg
4148862bcd1aSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4149862bcd1aSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
41501ab64890Smrg
4151862bcd1aSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
415288de56ccSmrgis created, otherwise an executable program is created."
4153b4ee4795Smrg        ;;
41541ab64890Smrg
415588de56ccSmrg      uninstall)
415688de56ccSmrg        $ECHO \
415788de56ccSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
41581ab64890Smrg
415988de56ccSmrgRemove libraries from an installation directory.
41601ab64890Smrg
416188de56ccSmrgRM is the name of the program to use to delete files associated with each FILE
4162862bcd1aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
416388de56ccSmrgto RM.
41642e9c7c8cSmrg
416588de56ccSmrgIf FILE is a libtool library, all the files associated with it are deleted.
416688de56ccSmrgOtherwise, only FILE itself is deleted using RM."
416788de56ccSmrg        ;;
41682e9c7c8cSmrg
416988de56ccSmrg      *)
4170862bcd1aSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
417188de56ccSmrg        ;;
417288de56ccSmrg    esac
41732e9c7c8cSmrg
4174e9fcaa8aSmrg    echo
4175862bcd1aSmrg    $ECHO "Try '$progname --help' for more information about other modes."
417688de56ccSmrg}
41772e9c7c8cSmrg
4178e9fcaa8aSmrg# Now that we've collected a possible --mode arg, show help if necessary
4179e9fcaa8aSmrgif $opt_help; then
4180862bcd1aSmrg  if test : = "$opt_help"; then
4181e9fcaa8aSmrg    func_mode_help
4182e9fcaa8aSmrg  else
4183e9fcaa8aSmrg    {
4184e9fcaa8aSmrg      func_help noexit
4185e9fcaa8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4186e9fcaa8aSmrg	func_mode_help
4187e9fcaa8aSmrg      done
4188862bcd1aSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4189e9fcaa8aSmrg    {
4190e9fcaa8aSmrg      func_help noexit
4191e9fcaa8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4192e9fcaa8aSmrg	echo
4193e9fcaa8aSmrg	func_mode_help
4194e9fcaa8aSmrg      done
4195e9fcaa8aSmrg    } |
4196862bcd1aSmrg    $SED '1d
4197e9fcaa8aSmrg      /^When reporting/,/^Report/{
4198e9fcaa8aSmrg	H
4199e9fcaa8aSmrg	d
4200e9fcaa8aSmrg      }
4201e9fcaa8aSmrg      $x
4202e9fcaa8aSmrg      /information about other modes/d
4203e9fcaa8aSmrg      /more detailed .*MODE/d
4204e9fcaa8aSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4205e9fcaa8aSmrg  fi
4206e9fcaa8aSmrg  exit $?
4207e9fcaa8aSmrgfi
42082e9c7c8cSmrg
42092e9c7c8cSmrg
421007fb9b8fSmrg# If option '--reorder-cache', reorder the shared library cache and exit.
421107fb9b8fSmrgif $opt_reorder_cache; then
421207fb9b8fSmrg    func_reorder_shared_lib_cache $shared_lib_dirs
421307fb9b8fSmrgfi
421407fb9b8fSmrg
421507fb9b8fSmrg
421688de56ccSmrg# func_mode_execute arg...
421788de56ccSmrgfunc_mode_execute ()
421888de56ccSmrg{
4219862bcd1aSmrg    $debug_cmd
4220862bcd1aSmrg
422188de56ccSmrg    # The first argument is the command name.
4222862bcd1aSmrg    cmd=$nonopt
422388de56ccSmrg    test -z "$cmd" && \
422488de56ccSmrg      func_fatal_help "you must specify a COMMAND"
4225b4ee4795Smrg
422688de56ccSmrg    # Handle -dlopen flags immediately.
4227e9fcaa8aSmrg    for file in $opt_dlopen; do
422888de56ccSmrg      test -f "$file" \
4229862bcd1aSmrg	|| func_fatal_help "'$file' is not a file"
4230b4ee4795Smrg
423188de56ccSmrg      dir=
423288de56ccSmrg      case $file in
423388de56ccSmrg      *.la)
4234e9fcaa8aSmrg	func_resolve_sysroot "$file"
4235e9fcaa8aSmrg	file=$func_resolve_sysroot_result
4236e9fcaa8aSmrg
423788de56ccSmrg	# Check to see that this really is a libtool archive.
423888de56ccSmrg	func_lalib_unsafe_p "$file" \
4239862bcd1aSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4240b4ee4795Smrg
424188de56ccSmrg	# Read the libtool library.
424288de56ccSmrg	dlname=
424388de56ccSmrg	library_names=
424488de56ccSmrg	func_source "$file"
42451ab64890Smrg
424688de56ccSmrg	# Skip this library if it cannot be dlopened.
424788de56ccSmrg	if test -z "$dlname"; then
424888de56ccSmrg	  # Warn if it was a shared library.
424988de56ccSmrg	  test -n "$library_names" && \
4250862bcd1aSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
425188de56ccSmrg	  continue
425288de56ccSmrg	fi
42531ab64890Smrg
425488de56ccSmrg	func_dirname "$file" "" "."
4255862bcd1aSmrg	dir=$func_dirname_result
42561ab64890Smrg
425788de56ccSmrg	if test -f "$dir/$objdir/$dlname"; then
4258e9fcaa8aSmrg	  func_append dir "/$objdir"
425988de56ccSmrg	else
426088de56ccSmrg	  if test ! -f "$dir/$dlname"; then
4261862bcd1aSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
426288de56ccSmrg	  fi
426388de56ccSmrg	fi
4264b4ee4795Smrg	;;
42651ab64890Smrg
426688de56ccSmrg      *.lo)
426788de56ccSmrg	# Just add the directory containing the .lo file.
426888de56ccSmrg	func_dirname "$file" "" "."
4269862bcd1aSmrg	dir=$func_dirname_result
4270b4ee4795Smrg	;;
42711ab64890Smrg
427288de56ccSmrg      *)
4273862bcd1aSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4274b4ee4795Smrg	continue
4275b4ee4795Smrg	;;
427688de56ccSmrg      esac
42771ab64890Smrg
427888de56ccSmrg      # Get the absolute pathname.
427988de56ccSmrg      absdir=`cd "$dir" && pwd`
4280862bcd1aSmrg      test -n "$absdir" && dir=$absdir
42812e9c7c8cSmrg
428288de56ccSmrg      # Now add the directory to shlibpath_var.
428388de56ccSmrg      if eval "test -z \"\$$shlibpath_var\""; then
428488de56ccSmrg	eval "$shlibpath_var=\"\$dir\""
428588de56ccSmrg      else
428688de56ccSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
428788de56ccSmrg      fi
428888de56ccSmrg    done
42892e9c7c8cSmrg
429088de56ccSmrg    # This variable tells wrapper scripts just to set shlibpath_var
429188de56ccSmrg    # rather than running their programs.
4292862bcd1aSmrg    libtool_execute_magic=$magic
42932e9c7c8cSmrg
429488de56ccSmrg    # Check if any of the arguments is a wrapper script.
429588de56ccSmrg    args=
429688de56ccSmrg    for file
429788de56ccSmrg    do
429888de56ccSmrg      case $file in
4299e9fcaa8aSmrg      -* | *.la | *.lo ) ;;
430088de56ccSmrg      *)
430188de56ccSmrg	# Do a test to see if this is really a libtool program.
430288de56ccSmrg	if func_ltwrapper_script_p "$file"; then
430388de56ccSmrg	  func_source "$file"
430488de56ccSmrg	  # Transform arg to wrapped name.
4305862bcd1aSmrg	  file=$progdir/$program
430688de56ccSmrg	elif func_ltwrapper_executable_p "$file"; then
430788de56ccSmrg	  func_ltwrapper_scriptname "$file"
430888de56ccSmrg	  func_source "$func_ltwrapper_scriptname_result"
430988de56ccSmrg	  # Transform arg to wrapped name.
4310862bcd1aSmrg	  file=$progdir/$program
431188de56ccSmrg	fi
431288de56ccSmrg	;;
431388de56ccSmrg      esac
431488de56ccSmrg      # Quote arguments (to preserve shell metacharacters).
4315e9fcaa8aSmrg      func_append_quoted args "$file"
431688de56ccSmrg    done
43172e9c7c8cSmrg
4318862bcd1aSmrg    if $opt_dry_run; then
4319862bcd1aSmrg      # Display what would be done.
4320862bcd1aSmrg      if test -n "$shlibpath_var"; then
4321862bcd1aSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4322862bcd1aSmrg	echo "export $shlibpath_var"
4323862bcd1aSmrg      fi
4324862bcd1aSmrg      $ECHO "$cmd$args"
4325862bcd1aSmrg      exit $EXIT_SUCCESS
4326862bcd1aSmrg    else
432788de56ccSmrg      if test -n "$shlibpath_var"; then
432888de56ccSmrg	# Export the shlibpath_var.
432988de56ccSmrg	eval "export $shlibpath_var"
433088de56ccSmrg      fi
43312e9c7c8cSmrg
433288de56ccSmrg      # Restore saved environment variables
433388de56ccSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
433488de56ccSmrg      do
433588de56ccSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
433688de56ccSmrg                $lt_var=\$save_$lt_var; export $lt_var
4337b4ee4795Smrg	      else
433888de56ccSmrg		$lt_unset $lt_var
433988de56ccSmrg	      fi"
434088de56ccSmrg      done
43412e9c7c8cSmrg
434288de56ccSmrg      # Now prepare to actually exec the command.
4343862bcd1aSmrg      exec_cmd=\$cmd$args
434488de56ccSmrg    fi
434588de56ccSmrg}
43462e9c7c8cSmrg
4347862bcd1aSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
43482e9c7c8cSmrg
4349b4ee4795Smrg
435088de56ccSmrg# func_mode_finish arg...
435188de56ccSmrgfunc_mode_finish ()
435288de56ccSmrg{
4353862bcd1aSmrg    $debug_cmd
4354862bcd1aSmrg
4355e9fcaa8aSmrg    libs=
4356e9fcaa8aSmrg    libdirs=
435788de56ccSmrg    admincmds=
43581ab64890Smrg
4359e9fcaa8aSmrg    for opt in "$nonopt" ${1+"$@"}
4360e9fcaa8aSmrg    do
4361e9fcaa8aSmrg      if test -d "$opt"; then
4362e9fcaa8aSmrg	func_append libdirs " $opt"
4363e9fcaa8aSmrg
4364e9fcaa8aSmrg      elif test -f "$opt"; then
4365e9fcaa8aSmrg	if func_lalib_unsafe_p "$opt"; then
4366e9fcaa8aSmrg	  func_append libs " $opt"
4367e9fcaa8aSmrg	else
4368862bcd1aSmrg	  func_warning "'$opt' is not a valid libtool archive"
4369e9fcaa8aSmrg	fi
4370e9fcaa8aSmrg
4371e9fcaa8aSmrg      else
4372862bcd1aSmrg	func_fatal_error "invalid argument '$opt'"
4373e9fcaa8aSmrg      fi
4374e9fcaa8aSmrg    done
4375e9fcaa8aSmrg
4376e9fcaa8aSmrg    if test -n "$libs"; then
4377e9fcaa8aSmrg      if test -n "$lt_sysroot"; then
4378e9fcaa8aSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4379e9fcaa8aSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4380e9fcaa8aSmrg      else
4381e9fcaa8aSmrg        sysroot_cmd=
4382e9fcaa8aSmrg      fi
43831ab64890Smrg
4384e9fcaa8aSmrg      # Remove sysroot references
4385e9fcaa8aSmrg      if $opt_dry_run; then
4386e9fcaa8aSmrg        for lib in $libs; do
4387862bcd1aSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4388e9fcaa8aSmrg        done
4389e9fcaa8aSmrg      else
4390e9fcaa8aSmrg        tmpdir=`func_mktempdir`
4391e9fcaa8aSmrg        for lib in $libs; do
4392862bcd1aSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4393e9fcaa8aSmrg	    > $tmpdir/tmp-la
4394e9fcaa8aSmrg	  mv -f $tmpdir/tmp-la $lib
4395e9fcaa8aSmrg	done
4396e9fcaa8aSmrg        ${RM}r "$tmpdir"
4397e9fcaa8aSmrg      fi
4398e9fcaa8aSmrg    fi
4399e9fcaa8aSmrg
440007fb9b8fSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs" && $opt_finishing; then
440188de56ccSmrg      for libdir in $libdirs; do
440288de56ccSmrg	if test -n "$finish_cmds"; then
440388de56ccSmrg	  # Do each command in the finish commands.
440488de56ccSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
440588de56ccSmrg'"$cmd"'"'
4406b4ee4795Smrg	fi
440788de56ccSmrg	if test -n "$finish_eval"; then
440888de56ccSmrg	  # Do the single finish_eval.
440988de56ccSmrg	  eval cmds=\"$finish_eval\"
4410e9fcaa8aSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
441188de56ccSmrg       $cmds"
441288de56ccSmrg	fi
441388de56ccSmrg      done
441488de56ccSmrg    fi
44151ab64890Smrg
441688de56ccSmrg    # Exit here if they wanted silent mode.
4417862bcd1aSmrg    $opt_quiet && exit $EXIT_SUCCESS
44181ab64890Smrg
4419e9fcaa8aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4420e9fcaa8aSmrg      echo "----------------------------------------------------------------------"
4421e9fcaa8aSmrg      echo "Libraries have been installed in:"
4422e9fcaa8aSmrg      for libdir in $libdirs; do
4423e9fcaa8aSmrg	$ECHO "   $libdir"
4424e9fcaa8aSmrg      done
442507fb9b8fSmrg      if test "false" = "$opt_finishing"; then
442607fb9b8fSmrg        echo
442707fb9b8fSmrg        echo "NOTE: finish_cmds were not executed during testing, so you must"
442807fb9b8fSmrg        echo "manually run ldconfig to add a given test directory, LIBDIR, to"
442907fb9b8fSmrg        echo "the search path for generated executables."
443007fb9b8fSmrg      fi
4431e9fcaa8aSmrg      echo
4432e9fcaa8aSmrg      echo "If you ever happen to want to link against installed libraries"
4433e9fcaa8aSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4434862bcd1aSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4435e9fcaa8aSmrg      echo "flag during linking and do at least one of the following:"
4436e9fcaa8aSmrg      if test -n "$shlibpath_var"; then
4437862bcd1aSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4438e9fcaa8aSmrg	echo "     during execution"
4439e9fcaa8aSmrg      fi
4440e9fcaa8aSmrg      if test -n "$runpath_var"; then
4441862bcd1aSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4442e9fcaa8aSmrg	echo "     during linking"
4443e9fcaa8aSmrg      fi
4444e9fcaa8aSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4445e9fcaa8aSmrg	libdir=LIBDIR
4446e9fcaa8aSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
444788de56ccSmrg
4448862bcd1aSmrg	$ECHO "   - use the '$flag' linker flag"
4449e9fcaa8aSmrg      fi
4450e9fcaa8aSmrg      if test -n "$admincmds"; then
4451e9fcaa8aSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4452e9fcaa8aSmrg      fi
4453e9fcaa8aSmrg      if test -f /etc/ld.so.conf; then
4454862bcd1aSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4455e9fcaa8aSmrg      fi
4456e9fcaa8aSmrg      echo
445788de56ccSmrg
4458e9fcaa8aSmrg      echo "See any operating system documentation about shared libraries for"
4459e9fcaa8aSmrg      case $host in
4460e9fcaa8aSmrg	solaris2.[6789]|solaris2.1[0-9])
4461e9fcaa8aSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4462e9fcaa8aSmrg	  echo "pages."
4463e9fcaa8aSmrg	  ;;
4464e9fcaa8aSmrg	*)
4465e9fcaa8aSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4466e9fcaa8aSmrg	  ;;
4467e9fcaa8aSmrg      esac
4468e9fcaa8aSmrg      echo "----------------------------------------------------------------------"
4469e9fcaa8aSmrg    fi
447088de56ccSmrg    exit $EXIT_SUCCESS
447188de56ccSmrg}
447288de56ccSmrg
4473862bcd1aSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
447488de56ccSmrg
447588de56ccSmrg
447688de56ccSmrg# func_mode_install arg...
447788de56ccSmrgfunc_mode_install ()
447888de56ccSmrg{
4479862bcd1aSmrg    $debug_cmd
4480862bcd1aSmrg
448188de56ccSmrg    # There may be an optional sh(1) argument at the beginning of
448288de56ccSmrg    # install_prog (especially on Windows NT).
4483862bcd1aSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
448488de56ccSmrg       # Allow the use of GNU shtool's install command.
4485862bcd1aSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4486862bcd1aSmrg    then
448788de56ccSmrg      # Aesthetically quote it.
44887d2c738bSmrg      func_quote_arg pretty "$nonopt"
44897d2c738bSmrg      install_prog="$func_quote_arg_result "
449088de56ccSmrg      arg=$1
449188de56ccSmrg      shift
449288de56ccSmrg    else
449388de56ccSmrg      install_prog=
449488de56ccSmrg      arg=$nonopt
449588de56ccSmrg    fi
449688de56ccSmrg
449788de56ccSmrg    # The real first argument should be the name of the installation program.
449888de56ccSmrg    # Aesthetically quote it.
44997d2c738bSmrg    func_quote_arg pretty "$arg"
45007d2c738bSmrg    func_append install_prog "$func_quote_arg_result"
4501e9fcaa8aSmrg    install_shared_prog=$install_prog
4502e9fcaa8aSmrg    case " $install_prog " in
4503e9fcaa8aSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4504e9fcaa8aSmrg      *) install_cp=false ;;
4505e9fcaa8aSmrg    esac
450688de56ccSmrg
450788de56ccSmrg    # We need to accept at least all the BSD install flags.
450888de56ccSmrg    dest=
450988de56ccSmrg    files=
451088de56ccSmrg    opts=
451188de56ccSmrg    prev=
451288de56ccSmrg    install_type=
4513862bcd1aSmrg    isdir=false
451488de56ccSmrg    stripme=
4515e9fcaa8aSmrg    no_mode=:
451688de56ccSmrg    for arg
451788de56ccSmrg    do
4518e9fcaa8aSmrg      arg2=
451988de56ccSmrg      if test -n "$dest"; then
4520e9fcaa8aSmrg	func_append files " $dest"
452188de56ccSmrg	dest=$arg
452288de56ccSmrg	continue
452388de56ccSmrg      fi
452488de56ccSmrg
452588de56ccSmrg      case $arg in
4526862bcd1aSmrg      -d) isdir=: ;;
452788de56ccSmrg      -f)
4528e9fcaa8aSmrg	if $install_cp; then :; else
4529e9fcaa8aSmrg	  prev=$arg
4530e9fcaa8aSmrg	fi
453188de56ccSmrg	;;
453288de56ccSmrg      -g | -m | -o)
453388de56ccSmrg	prev=$arg
453488de56ccSmrg	;;
453588de56ccSmrg      -s)
453688de56ccSmrg	stripme=" -s"
453788de56ccSmrg	continue
453888de56ccSmrg	;;
453988de56ccSmrg      -*)
454088de56ccSmrg	;;
454188de56ccSmrg      *)
454288de56ccSmrg	# If the previous option needed an argument, then skip it.
454388de56ccSmrg	if test -n "$prev"; then
4544862bcd1aSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4545e9fcaa8aSmrg	    arg2=$install_override_mode
4546e9fcaa8aSmrg	    no_mode=false
4547e9fcaa8aSmrg	  fi
4548b4ee4795Smrg	  prev=
45492e9c7c8cSmrg	else
455088de56ccSmrg	  dest=$arg
455188de56ccSmrg	  continue
45521ab64890Smrg	fi
4553b4ee4795Smrg	;;
455488de56ccSmrg      esac
45551ab64890Smrg
455688de56ccSmrg      # Aesthetically quote the argument.
45577d2c738bSmrg      func_quote_arg pretty "$arg"
45587d2c738bSmrg      func_append install_prog " $func_quote_arg_result"
4559e9fcaa8aSmrg      if test -n "$arg2"; then
45607d2c738bSmrg	func_quote_arg pretty "$arg2"
4561e9fcaa8aSmrg      fi
45627d2c738bSmrg      func_append install_shared_prog " $func_quote_arg_result"
456388de56ccSmrg    done
45641ab64890Smrg
456588de56ccSmrg    test -z "$install_prog" && \
456688de56ccSmrg      func_fatal_help "you must specify an install program"
45671ab64890Smrg
456888de56ccSmrg    test -n "$prev" && \
4569862bcd1aSmrg      func_fatal_help "the '$prev' option requires an argument"
45702e9c7c8cSmrg
4571e9fcaa8aSmrg    if test -n "$install_override_mode" && $no_mode; then
4572e9fcaa8aSmrg      if $install_cp; then :; else
45737d2c738bSmrg	func_quote_arg pretty "$install_override_mode"
45747d2c738bSmrg	func_append install_shared_prog " -m $func_quote_arg_result"
4575e9fcaa8aSmrg      fi
4576e9fcaa8aSmrg    fi
4577e9fcaa8aSmrg
457888de56ccSmrg    if test -z "$files"; then
457988de56ccSmrg      if test -z "$dest"; then
458088de56ccSmrg	func_fatal_help "no file or destination specified"
458188de56ccSmrg      else
458288de56ccSmrg	func_fatal_help "you must specify a destination"
458388de56ccSmrg      fi
4584b4ee4795Smrg    fi
45852e9c7c8cSmrg
458688de56ccSmrg    # Strip any trailing slash from the destination.
458788de56ccSmrg    func_stripname '' '/' "$dest"
458888de56ccSmrg    dest=$func_stripname_result
45892e9c7c8cSmrg
459088de56ccSmrg    # Check to see that the destination is a directory.
4591862bcd1aSmrg    test -d "$dest" && isdir=:
4592862bcd1aSmrg    if $isdir; then
4593862bcd1aSmrg      destdir=$dest
459488de56ccSmrg      destname=
4595b4ee4795Smrg    else
459688de56ccSmrg      func_dirname_and_basename "$dest" "" "."
4597862bcd1aSmrg      destdir=$func_dirname_result
4598862bcd1aSmrg      destname=$func_basename_result
45992e9c7c8cSmrg
460088de56ccSmrg      # Not a directory, so check to see that there is only one file specified.
460188de56ccSmrg      set dummy $files; shift
460288de56ccSmrg      test "$#" -gt 1 && \
4603862bcd1aSmrg	func_fatal_help "'$dest' is not a directory"
46042e9c7c8cSmrg    fi
460588de56ccSmrg    case $destdir in
460688de56ccSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4607b4ee4795Smrg    *)
460888de56ccSmrg      for file in $files; do
460988de56ccSmrg	case $file in
461088de56ccSmrg	*.lo) ;;
461188de56ccSmrg	*)
4612862bcd1aSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
461388de56ccSmrg	  ;;
461488de56ccSmrg	esac
461588de56ccSmrg      done
4616b4ee4795Smrg      ;;
4617b4ee4795Smrg    esac
46181ab64890Smrg
461988de56ccSmrg    # This variable tells wrapper scripts just to set variables rather
462088de56ccSmrg    # than running their programs.
4621862bcd1aSmrg    libtool_install_magic=$magic
46221ab64890Smrg
462388de56ccSmrg    staticlibs=
462488de56ccSmrg    future_libdirs=
462588de56ccSmrg    current_libdirs=
462688de56ccSmrg    for file in $files; do
46271ab64890Smrg
462888de56ccSmrg      # Do each installation.
462988de56ccSmrg      case $file in
463088de56ccSmrg      *.$libext)
463188de56ccSmrg	# Do the static libraries later.
4632e9fcaa8aSmrg	func_append staticlibs " $file"
463388de56ccSmrg	;;
463488de56ccSmrg
463588de56ccSmrg      *.la)
4636e9fcaa8aSmrg	func_resolve_sysroot "$file"
4637e9fcaa8aSmrg	file=$func_resolve_sysroot_result
4638e9fcaa8aSmrg
463988de56ccSmrg	# Check to see that this really is a libtool archive.
464088de56ccSmrg	func_lalib_unsafe_p "$file" \
4641862bcd1aSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
464288de56ccSmrg
464388de56ccSmrg	library_names=
464488de56ccSmrg	old_library=
464588de56ccSmrg	relink_command=
464688de56ccSmrg	func_source "$file"
464788de56ccSmrg
464888de56ccSmrg	# Add the libdir to current_libdirs if it is the destination.
464988de56ccSmrg	if test "X$destdir" = "X$libdir"; then
465088de56ccSmrg	  case "$current_libdirs " in
465188de56ccSmrg	  *" $libdir "*) ;;
4652e9fcaa8aSmrg	  *) func_append current_libdirs " $libdir" ;;
46532e9c7c8cSmrg	  esac
465488de56ccSmrg	else
465588de56ccSmrg	  # Note the libdir as a future libdir.
465688de56ccSmrg	  case "$future_libdirs " in
465788de56ccSmrg	  *" $libdir "*) ;;
4658e9fcaa8aSmrg	  *) func_append future_libdirs " $libdir" ;;
465988de56ccSmrg	  esac
466088de56ccSmrg	fi
46612e9c7c8cSmrg
466288de56ccSmrg	func_dirname "$file" "/" ""
4663862bcd1aSmrg	dir=$func_dirname_result
4664e9fcaa8aSmrg	func_append dir "$objdir"
466588de56ccSmrg
466688de56ccSmrg	if test -n "$relink_command"; then
466707fb9b8fSmrg	  # Strip any trailing slash from the destination.
466807fb9b8fSmrg	  func_stripname '' '/' "$libdir"
466907fb9b8fSmrg	  destlibdir=$func_stripname_result
467007fb9b8fSmrg
467107fb9b8fSmrg	  func_stripname '' '/' "$destdir"
467207fb9b8fSmrg	  s_destdir=$func_stripname_result
467307fb9b8fSmrg
467488de56ccSmrg	  # Determine the prefix the user has applied to our future dir.
467507fb9b8fSmrg	  inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"`
467688de56ccSmrg
467788de56ccSmrg	  # Don't allow the user to place us outside of our expected
467888de56ccSmrg	  # location b/c this prevents finding dependent libraries that
467988de56ccSmrg	  # are installed to the same prefix.
468088de56ccSmrg	  # At present, this check doesn't affect windows .dll's that
468188de56ccSmrg	  # are installed into $libdir/../bin (currently, that works fine)
468288de56ccSmrg	  # but it's something to keep an eye on.
468388de56ccSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4684862bcd1aSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
468588de56ccSmrg
468688de56ccSmrg	  if test -n "$inst_prefix_dir"; then
468788de56ccSmrg	    # Stick the inst_prefix_dir data into the link command.
4688e9fcaa8aSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
468988de56ccSmrg	  else
4690e9fcaa8aSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
469188de56ccSmrg	  fi
469288de56ccSmrg
4693862bcd1aSmrg	  func_warning "relinking '$file'"
469488de56ccSmrg	  func_show_eval "$relink_command" \
4695862bcd1aSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
469688de56ccSmrg	fi
469788de56ccSmrg
469888de56ccSmrg	# See the names of the shared library.
469988de56ccSmrg	set dummy $library_names; shift
470088de56ccSmrg	if test -n "$1"; then
4701862bcd1aSmrg	  realname=$1
470288de56ccSmrg	  shift
470388de56ccSmrg
4704862bcd1aSmrg	  srcname=$realname
4705862bcd1aSmrg	  test -n "$relink_command" && srcname=${realname}T
470688de56ccSmrg
470788de56ccSmrg	  # Install the shared library and build the symlinks.
4708e9fcaa8aSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
470988de56ccSmrg	      'exit $?'
4710862bcd1aSmrg	  tstripme=$stripme
471188de56ccSmrg	  case $host_os in
471207fb9b8fSmrg	  cygwin* | mingw* | windows* | pw32* | cegcc*)
471388de56ccSmrg	    case $realname in
471488de56ccSmrg	    *.dll.a)
4715862bcd1aSmrg	      tstripme=
4716862bcd1aSmrg	      ;;
4717862bcd1aSmrg	    esac
4718862bcd1aSmrg	    ;;
4719862bcd1aSmrg	  os2*)
4720862bcd1aSmrg	    case $realname in
4721862bcd1aSmrg	    *_dll.a)
4722862bcd1aSmrg	      tstripme=
472388de56ccSmrg	      ;;
472488de56ccSmrg	    esac
47252e9c7c8cSmrg	    ;;
47262e9c7c8cSmrg	  esac
472788de56ccSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
472888de56ccSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4729b4ee4795Smrg	  fi
473088de56ccSmrg
473188de56ccSmrg	  if test "$#" -gt 0; then
473288de56ccSmrg	    # Delete the old symlinks, and create new ones.
4733862bcd1aSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
473488de56ccSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
473588de56ccSmrg	    # so we also need to try rm && ln -s.
473688de56ccSmrg	    for linkname
473788de56ccSmrg	    do
473888de56ccSmrg	      test "$linkname" != "$realname" \
473988de56ccSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4740b4ee4795Smrg	    done
4741b4ee4795Smrg	  fi
47421ab64890Smrg
474388de56ccSmrg	  # Do each command in the postinstall commands.
4744862bcd1aSmrg	  lib=$destdir/$realname
474588de56ccSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4746b4ee4795Smrg	fi
47471ab64890Smrg
474888de56ccSmrg	# Install the pseudo-library for information purposes.
474988de56ccSmrg	func_basename "$file"
4750862bcd1aSmrg	name=$func_basename_result
4751862bcd1aSmrg	instname=$dir/${name}i
475288de56ccSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
47531ab64890Smrg
475488de56ccSmrg	# Maybe install the static library, too.
4755e9fcaa8aSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
475688de56ccSmrg	;;
47571ab64890Smrg
475888de56ccSmrg      *.lo)
475988de56ccSmrg	# Install (i.e. copy) a libtool object.
47601ab64890Smrg
476188de56ccSmrg	# Figure out destination file name, if it wasn't already specified.
476288de56ccSmrg	if test -n "$destname"; then
4763862bcd1aSmrg	  destfile=$destdir/$destname
476488de56ccSmrg	else
476588de56ccSmrg	  func_basename "$file"
4766862bcd1aSmrg	  destfile=$func_basename_result
4767862bcd1aSmrg	  destfile=$destdir/$destfile
4768b4ee4795Smrg	fi
47691ab64890Smrg
477088de56ccSmrg	# Deduce the name of the destination old-style object file.
477188de56ccSmrg	case $destfile in
477288de56ccSmrg	*.lo)
477388de56ccSmrg	  func_lo2o "$destfile"
477488de56ccSmrg	  staticdest=$func_lo2o_result
477588de56ccSmrg	  ;;
477688de56ccSmrg	*.$objext)
4777862bcd1aSmrg	  staticdest=$destfile
477888de56ccSmrg	  destfile=
477988de56ccSmrg	  ;;
478088de56ccSmrg	*)
4781862bcd1aSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
478288de56ccSmrg	  ;;
478388de56ccSmrg	esac
47841ab64890Smrg
478588de56ccSmrg	# Install the libtool object if requested.
478688de56ccSmrg	test -n "$destfile" && \
478788de56ccSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
47881ab64890Smrg
478988de56ccSmrg	# Install the old object if enabled.
4790862bcd1aSmrg	if test yes = "$build_old_libs"; then
479188de56ccSmrg	  # Deduce the name of the old-style object file.
479288de56ccSmrg	  func_lo2o "$file"
479388de56ccSmrg	  staticobj=$func_lo2o_result
479488de56ccSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
47951ab64890Smrg	fi
479688de56ccSmrg	exit $EXIT_SUCCESS
479788de56ccSmrg	;;
47981ab64890Smrg
479988de56ccSmrg      *)
480088de56ccSmrg	# Figure out destination file name, if it wasn't already specified.
480188de56ccSmrg	if test -n "$destname"; then
4802862bcd1aSmrg	  destfile=$destdir/$destname
480388de56ccSmrg	else
480488de56ccSmrg	  func_basename "$file"
4805862bcd1aSmrg	  destfile=$func_basename_result
4806862bcd1aSmrg	  destfile=$destdir/$destfile
480788de56ccSmrg	fi
48081ab64890Smrg
480988de56ccSmrg	# If the file is missing, and there is a .exe on the end, strip it
481088de56ccSmrg	# because it is most likely a libtool script we actually want to
481188de56ccSmrg	# install
4812862bcd1aSmrg	stripped_ext=
481388de56ccSmrg	case $file in
481488de56ccSmrg	  *.exe)
481588de56ccSmrg	    if test ! -f "$file"; then
481688de56ccSmrg	      func_stripname '' '.exe' "$file"
481788de56ccSmrg	      file=$func_stripname_result
4818862bcd1aSmrg	      stripped_ext=.exe
481988de56ccSmrg	    fi
482088de56ccSmrg	    ;;
482188de56ccSmrg	esac
482288de56ccSmrg
482388de56ccSmrg	# Do a test to see if this is really a libtool program.
482488de56ccSmrg	case $host in
482507fb9b8fSmrg	*cygwin* | *mingw* | *windows*)
482688de56ccSmrg	    if func_ltwrapper_executable_p "$file"; then
482788de56ccSmrg	      func_ltwrapper_scriptname "$file"
482888de56ccSmrg	      wrapper=$func_ltwrapper_scriptname_result
482988de56ccSmrg	    else
483088de56ccSmrg	      func_stripname '' '.exe' "$file"
483188de56ccSmrg	      wrapper=$func_stripname_result
483288de56ccSmrg	    fi
483388de56ccSmrg	    ;;
4834b4ee4795Smrg	*)
483588de56ccSmrg	    wrapper=$file
483688de56ccSmrg	    ;;
483788de56ccSmrg	esac
483888de56ccSmrg	if func_ltwrapper_script_p "$wrapper"; then
483988de56ccSmrg	  notinst_deplibs=
484088de56ccSmrg	  relink_command=
484188de56ccSmrg
484288de56ccSmrg	  func_source "$wrapper"
484388de56ccSmrg
484488de56ccSmrg	  # Check the variables that should have been set.
484588de56ccSmrg	  test -z "$generated_by_libtool_version" && \
4846862bcd1aSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
484788de56ccSmrg
4848862bcd1aSmrg	  finalize=:
484988de56ccSmrg	  for lib in $notinst_deplibs; do
485088de56ccSmrg	    # Check to see that each library is installed.
485188de56ccSmrg	    libdir=
485288de56ccSmrg	    if test -f "$lib"; then
485388de56ccSmrg	      func_source "$lib"
485488de56ccSmrg	    fi
4855862bcd1aSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
485688de56ccSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4857862bcd1aSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4858862bcd1aSmrg	      finalize=false
485988de56ccSmrg	    fi
486088de56ccSmrg	  done
486188de56ccSmrg
486288de56ccSmrg	  relink_command=
486388de56ccSmrg	  func_source "$wrapper"
486488de56ccSmrg
486588de56ccSmrg	  outputname=
4866862bcd1aSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
486788de56ccSmrg	    $opt_dry_run || {
4868862bcd1aSmrg	      if $finalize; then
486988de56ccSmrg	        tmpdir=`func_mktempdir`
487088de56ccSmrg		func_basename "$file$stripped_ext"
4871862bcd1aSmrg		file=$func_basename_result
4872862bcd1aSmrg	        outputname=$tmpdir/$file
487388de56ccSmrg	        # Replace the output file specification.
4874e9fcaa8aSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
487588de56ccSmrg
4876862bcd1aSmrg	        $opt_quiet || {
48777d2c738bSmrg	          func_quote_arg expand,pretty "$relink_command"
48787d2c738bSmrg		  eval "func_echo $func_quote_arg_result"
487988de56ccSmrg	        }
488088de56ccSmrg	        if eval "$relink_command"; then :
488188de56ccSmrg	          else
4882862bcd1aSmrg		  func_error "error: relink '$file' with the above command before installing it"
488388de56ccSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
488488de56ccSmrg		  continue
488588de56ccSmrg	        fi
4886862bcd1aSmrg	        file=$outputname
488788de56ccSmrg	      else
4888862bcd1aSmrg	        func_warning "cannot relink '$file'"
488988de56ccSmrg	      fi
489088de56ccSmrg	    }
489188de56ccSmrg	  else
489288de56ccSmrg	    # Install the binary that we compiled earlier.
4893e9fcaa8aSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4894b4ee4795Smrg	  fi
489588de56ccSmrg	fi
489688de56ccSmrg
489788de56ccSmrg	# remove .exe since cygwin /usr/bin/install will append another
489888de56ccSmrg	# one anyway
489988de56ccSmrg	case $install_prog,$host in
490088de56ccSmrg	*/usr/bin/install*,*cygwin*)
490188de56ccSmrg	  case $file:$destfile in
490288de56ccSmrg	  *.exe:*.exe)
490388de56ccSmrg	    # this is ok
490488de56ccSmrg	    ;;
490588de56ccSmrg	  *.exe:*)
490688de56ccSmrg	    destfile=$destfile.exe
490788de56ccSmrg	    ;;
490888de56ccSmrg	  *:*.exe)
490988de56ccSmrg	    func_stripname '' '.exe' "$destfile"
491088de56ccSmrg	    destfile=$func_stripname_result
491188de56ccSmrg	    ;;
491288de56ccSmrg	  esac
4913b4ee4795Smrg	  ;;
4914b4ee4795Smrg	esac
491588de56ccSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
491688de56ccSmrg	$opt_dry_run || if test -n "$outputname"; then
491788de56ccSmrg	  ${RM}r "$tmpdir"
491888de56ccSmrg	fi
491988de56ccSmrg	;;
492088de56ccSmrg      esac
492188de56ccSmrg    done
49221ab64890Smrg
492388de56ccSmrg    for file in $staticlibs; do
492488de56ccSmrg      func_basename "$file"
4925862bcd1aSmrg      name=$func_basename_result
492688de56ccSmrg
492788de56ccSmrg      # Set up the ranlib parameters.
4928862bcd1aSmrg      oldlib=$destdir/$name
4929eb411b4bSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4930eb411b4bSmrg      tool_oldlib=$func_to_tool_file_result
493188de56ccSmrg
493288de56ccSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
493388de56ccSmrg
493488de56ccSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4935eb411b4bSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
493688de56ccSmrg      fi
493788de56ccSmrg
493888de56ccSmrg      # Do each command in the postinstall commands.
493988de56ccSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
494088de56ccSmrg    done
494188de56ccSmrg
494288de56ccSmrg    test -n "$future_libdirs" && \
4943862bcd1aSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
494488de56ccSmrg
494588de56ccSmrg    if test -n "$current_libdirs"; then
494688de56ccSmrg      # Maybe just do a dry run.
494788de56ccSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4948862bcd1aSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
494988de56ccSmrg    else
495088de56ccSmrg      exit $EXIT_SUCCESS
495188de56ccSmrg    fi
495288de56ccSmrg}
495388de56ccSmrg
4954862bcd1aSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
495588de56ccSmrg
495688de56ccSmrg
495788de56ccSmrg# func_generate_dlsyms outputname originator pic_p
495888de56ccSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
495988de56ccSmrg# a dlpreopen symbol table.
496088de56ccSmrgfunc_generate_dlsyms ()
496188de56ccSmrg{
4962862bcd1aSmrg    $debug_cmd
4963862bcd1aSmrg
4964862bcd1aSmrg    my_outputname=$1
4965862bcd1aSmrg    my_originator=$2
4966862bcd1aSmrg    my_pic_p=${3-false}
4967862bcd1aSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
496888de56ccSmrg    my_dlsyms=
496988de56ccSmrg
4970862bcd1aSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
497188de56ccSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4972862bcd1aSmrg	my_dlsyms=${my_outputname}S.c
497388de56ccSmrg      else
497488de56ccSmrg	func_error "not configured to extract global symbols from dlpreopened files"
497588de56ccSmrg      fi
497688de56ccSmrg    fi
497788de56ccSmrg
497888de56ccSmrg    if test -n "$my_dlsyms"; then
497988de56ccSmrg      case $my_dlsyms in
498088de56ccSmrg      "") ;;
498188de56ccSmrg      *.c)
498288de56ccSmrg	# Discover the nlist of each of the dlfiles.
4983862bcd1aSmrg	nlist=$output_objdir/$my_outputname.nm
498488de56ccSmrg
498588de56ccSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
498688de56ccSmrg
498788de56ccSmrg	# Parse the name list into a source file.
498888de56ccSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
498988de56ccSmrg
499088de56ccSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4991862bcd1aSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4992862bcd1aSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
499388de56ccSmrg
499488de56ccSmrg#ifdef __cplusplus
499588de56ccSmrgextern \"C\" {
499688de56ccSmrg#endif
499788de56ccSmrg
4998862bcd1aSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4999e9fcaa8aSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
5000e9fcaa8aSmrg#endif
5001e9fcaa8aSmrg
5002e9fcaa8aSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
5003862bcd1aSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
5004862bcd1aSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
5005e9fcaa8aSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
5006e9fcaa8aSmrg# define LT_DLSYM_CONST
5007862bcd1aSmrg#elif defined __osf__
5008e9fcaa8aSmrg/* This system does not cope well with relocations in const data.  */
5009e9fcaa8aSmrg# define LT_DLSYM_CONST
5010e9fcaa8aSmrg#else
5011e9fcaa8aSmrg# define LT_DLSYM_CONST const
5012e9fcaa8aSmrg#endif
5013e9fcaa8aSmrg
5014862bcd1aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5015862bcd1aSmrg
501688de56ccSmrg/* External symbol declarations for the compiler. */\
501788de56ccSmrg"
501888de56ccSmrg
5019862bcd1aSmrg	if test yes = "$dlself"; then
5020862bcd1aSmrg	  func_verbose "generating symbol list for '$output'"
502188de56ccSmrg
502288de56ccSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
502388de56ccSmrg
502488de56ccSmrg	  # Add our own program objects to the symbol list.
5025e9fcaa8aSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
502688de56ccSmrg	  for progfile in $progfiles; do
5027e9fcaa8aSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
5028862bcd1aSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
5029e9fcaa8aSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
503088de56ccSmrg	  done
503188de56ccSmrg
503288de56ccSmrg	  if test -n "$exclude_expsyms"; then
503388de56ccSmrg	    $opt_dry_run || {
503488de56ccSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
503588de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
503688de56ccSmrg	    }
5037b4ee4795Smrg	  fi
503888de56ccSmrg
503988de56ccSmrg	  if test -n "$export_symbols_regex"; then
504088de56ccSmrg	    $opt_dry_run || {
504188de56ccSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
504288de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
504388de56ccSmrg	    }
504488de56ccSmrg	  fi
504588de56ccSmrg
504688de56ccSmrg	  # Prepare the list of exported symbols
504788de56ccSmrg	  if test -z "$export_symbols"; then
5048862bcd1aSmrg	    export_symbols=$output_objdir/$outputname.exp
504988de56ccSmrg	    $opt_dry_run || {
505088de56ccSmrg	      $RM $export_symbols
5051862bcd1aSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
505288de56ccSmrg	      case $host in
505307fb9b8fSmrg	      *cygwin* | *mingw* | *windows* | *cegcc* )
505488de56ccSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
505588de56ccSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
505688de56ccSmrg	        ;;
505788de56ccSmrg	      esac
505888de56ccSmrg	    }
5059b4ee4795Smrg	  else
506088de56ccSmrg	    $opt_dry_run || {
5061862bcd1aSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
506288de56ccSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
506388de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
506488de56ccSmrg	      case $host in
506507fb9b8fSmrg	        *cygwin* | *mingw* | *windows* | *cegcc* )
506688de56ccSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
506788de56ccSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
506888de56ccSmrg	          ;;
506988de56ccSmrg	      esac
507088de56ccSmrg	    }
5071b4ee4795Smrg	  fi
507288de56ccSmrg	fi
50731ab64890Smrg
507488de56ccSmrg	for dlprefile in $dlprefiles; do
5075862bcd1aSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
507688de56ccSmrg	  func_basename "$dlprefile"
5077862bcd1aSmrg	  name=$func_basename_result
5078e9fcaa8aSmrg          case $host in
507907fb9b8fSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
5080e9fcaa8aSmrg	      # if an import library, we need to obtain dlname
5081e9fcaa8aSmrg	      if func_win32_import_lib_p "$dlprefile"; then
5082e9fcaa8aSmrg	        func_tr_sh "$dlprefile"
5083e9fcaa8aSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
5084862bcd1aSmrg	        dlprefile_dlbasename=
5085e9fcaa8aSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
5086e9fcaa8aSmrg	          # Use subshell, to avoid clobbering current variable values
5087e9fcaa8aSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
5088862bcd1aSmrg	          if test -n "$dlprefile_dlname"; then
5089e9fcaa8aSmrg	            func_basename "$dlprefile_dlname"
5090862bcd1aSmrg	            dlprefile_dlbasename=$func_basename_result
5091e9fcaa8aSmrg	          else
5092e9fcaa8aSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
5093e9fcaa8aSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
5094e9fcaa8aSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
5095e9fcaa8aSmrg	          fi
5096e9fcaa8aSmrg	        fi
5097e9fcaa8aSmrg	        $opt_dry_run || {
5098862bcd1aSmrg	          if test -n "$dlprefile_dlbasename"; then
5099e9fcaa8aSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
5100e9fcaa8aSmrg	          else
5101e9fcaa8aSmrg	            func_warning "Could not compute DLL name from $name"
5102e9fcaa8aSmrg	            eval '$ECHO ": $name " >> "$nlist"'
5103e9fcaa8aSmrg	          fi
5104e9fcaa8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
510507fb9b8fSmrg	          case $host in
510607fb9b8fSmrg	            i[3456]86-*-mingw32*)
510707fb9b8fSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
510807fb9b8fSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
510907fb9b8fSmrg	            ;;
511007fb9b8fSmrg	            *)
511107fb9b8fSmrg	              eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
511207fb9b8fSmrg	                $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'"
511307fb9b8fSmrg	            ;;
511407fb9b8fSmrg	          esac
5115e9fcaa8aSmrg	        }
5116e9fcaa8aSmrg	      else # not an import lib
5117e9fcaa8aSmrg	        $opt_dry_run || {
5118e9fcaa8aSmrg	          eval '$ECHO ": $name " >> "$nlist"'
5119e9fcaa8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
5120e9fcaa8aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
5121e9fcaa8aSmrg	        }
5122e9fcaa8aSmrg	      fi
5123e9fcaa8aSmrg	    ;;
5124e9fcaa8aSmrg	    *)
5125e9fcaa8aSmrg	      $opt_dry_run || {
5126e9fcaa8aSmrg	        eval '$ECHO ": $name " >> "$nlist"'
5127e9fcaa8aSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
5128e9fcaa8aSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
5129e9fcaa8aSmrg	      }
5130e9fcaa8aSmrg	    ;;
5131e9fcaa8aSmrg          esac
513288de56ccSmrg	done
513388de56ccSmrg
513488de56ccSmrg	$opt_dry_run || {
513588de56ccSmrg	  # Make sure we have at least an empty file.
513688de56ccSmrg	  test -f "$nlist" || : > "$nlist"
513788de56ccSmrg
513888de56ccSmrg	  if test -n "$exclude_expsyms"; then
513988de56ccSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
514088de56ccSmrg	    $MV "$nlist"T "$nlist"
5141b4ee4795Smrg	  fi
514288de56ccSmrg
514388de56ccSmrg	  # Try sorting and uniquifying the output.
514488de56ccSmrg	  if $GREP -v "^: " < "$nlist" |
514588de56ccSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
514688de56ccSmrg		sort -k 3
514788de56ccSmrg	      else
514888de56ccSmrg		sort +2
514988de56ccSmrg	      fi |
515088de56ccSmrg	      uniq > "$nlist"S; then
515188de56ccSmrg	    :
5152b4ee4795Smrg	  else
515388de56ccSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5154b4ee4795Smrg	  fi
51551ab64890Smrg
515688de56ccSmrg	  if test -f "$nlist"S; then
515788de56ccSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5158b4ee4795Smrg	  else
5159e9fcaa8aSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5160b4ee4795Smrg	  fi
51611ab64890Smrg
5162862bcd1aSmrg	  func_show_eval '$RM "${nlist}I"'
5163862bcd1aSmrg	  if test -n "$global_symbol_to_import"; then
5164862bcd1aSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5165862bcd1aSmrg	  fi
5166862bcd1aSmrg
5167e9fcaa8aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
51681ab64890Smrg
516988de56ccSmrg/* The mapping between symbol names and symbols.  */
517088de56ccSmrgtypedef struct {
517188de56ccSmrg  const char *name;
517288de56ccSmrg  void *address;
517388de56ccSmrg} lt_dlsymlist;
5174e9fcaa8aSmrgextern LT_DLSYM_CONST lt_dlsymlist
5175862bcd1aSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5176862bcd1aSmrg"
5177862bcd1aSmrg
5178862bcd1aSmrg	  if test -s "$nlist"I; then
5179862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5180862bcd1aSmrgstatic void lt_syminit(void)
5181862bcd1aSmrg{
5182862bcd1aSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5183862bcd1aSmrg  for (; symbol->name; ++symbol)
5184862bcd1aSmrg    {"
5185862bcd1aSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5186862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5187862bcd1aSmrg    }
5188862bcd1aSmrg}"
5189862bcd1aSmrg	  fi
5190862bcd1aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5191e9fcaa8aSmrgLT_DLSYM_CONST lt_dlsymlist
519288de56ccSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5193862bcd1aSmrg{ {\"$my_originator\", (void *) 0},"
5194862bcd1aSmrg
5195862bcd1aSmrg	  if test -s "$nlist"I; then
5196862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5197862bcd1aSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5198862bcd1aSmrg	  fi
51991ab64890Smrg
520088de56ccSmrg	  case $need_lib_prefix in
520188de56ccSmrg	  no)
520288de56ccSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
520388de56ccSmrg	    ;;
520488de56ccSmrg	  *)
520588de56ccSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
520688de56ccSmrg	    ;;
520788de56ccSmrg	  esac
5208e9fcaa8aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
520988de56ccSmrg  {0, (void *) 0}
521088de56ccSmrg};
52111ab64890Smrg
521288de56ccSmrg/* This works around a problem in FreeBSD linker */
521388de56ccSmrg#ifdef FREEBSD_WORKAROUND
521488de56ccSmrgstatic const void *lt_preloaded_setup() {
521588de56ccSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
521688de56ccSmrg}
521788de56ccSmrg#endif
521888de56ccSmrg
521988de56ccSmrg#ifdef __cplusplus
522088de56ccSmrg}
522188de56ccSmrg#endif\
522288de56ccSmrg"
522388de56ccSmrg	} # !$opt_dry_run
522488de56ccSmrg
522588de56ccSmrg	pic_flag_for_symtable=
522688de56ccSmrg	case "$compile_command " in
522788de56ccSmrg	*" -static "*) ;;
522888de56ccSmrg	*)
522988de56ccSmrg	  case $host in
523088de56ccSmrg	  # compiling the symbol table file with pic_flag works around
523188de56ccSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
523288de56ccSmrg	  # linked before any other PIC object.  But we must not use
523388de56ccSmrg	  # pic_flag when linking with -static.  The problem exists in
523488de56ccSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5235eb411b4bSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
523688de56ccSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
523788de56ccSmrg	  *-*-hpux*)
523888de56ccSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
523988de56ccSmrg	  *)
5240862bcd1aSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
524188de56ccSmrg	    ;;
524288de56ccSmrg	  esac
524388de56ccSmrg	  ;;
524488de56ccSmrg	esac
524588de56ccSmrg	symtab_cflags=
524688de56ccSmrg	for arg in $LTCFLAGS; do
524788de56ccSmrg	  case $arg in
524888de56ccSmrg	  -pie | -fpie | -fPIE) ;;
5249e9fcaa8aSmrg	  *) func_append symtab_cflags " $arg" ;;
525088de56ccSmrg	  esac
525188de56ccSmrg	done
52521ab64890Smrg
525388de56ccSmrg	# Now compile the dynamic symbol file.
525488de56ccSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
52552e9c7c8cSmrg
525688de56ccSmrg	# Clean up the generated files.
5257862bcd1aSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
52581ab64890Smrg
525988de56ccSmrg	# Transform the symbol file into the correct name.
5260862bcd1aSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
526188de56ccSmrg	case $host in
526207fb9b8fSmrg	*cygwin* | *mingw* | *windows* | *cegcc* )
526388de56ccSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
5264e9fcaa8aSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5265e9fcaa8aSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
526688de56ccSmrg	  else
5267e9fcaa8aSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5268e9fcaa8aSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5269b4ee4795Smrg	  fi
527088de56ccSmrg	  ;;
527188de56ccSmrg	*)
5272e9fcaa8aSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5273e9fcaa8aSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
527488de56ccSmrg	  ;;
527588de56ccSmrg	esac
527688de56ccSmrg	;;
527788de56ccSmrg      *)
5278862bcd1aSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
527988de56ccSmrg	;;
528088de56ccSmrg      esac
528188de56ccSmrg    else
528288de56ccSmrg      # We keep going just in case the user didn't refer to
528388de56ccSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
528488de56ccSmrg      # really was required.
52851ab64890Smrg
528688de56ccSmrg      # Nullify the symbol file.
5287e9fcaa8aSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5288e9fcaa8aSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
528988de56ccSmrg    fi
529088de56ccSmrg}
52912e9c7c8cSmrg
5292862bcd1aSmrg# func_cygming_gnu_implib_p ARG
5293862bcd1aSmrg# This predicate returns with zero status (TRUE) if
5294862bcd1aSmrg# ARG is a GNU/binutils-style import library. Returns
5295862bcd1aSmrg# with nonzero status (FALSE) otherwise.
5296862bcd1aSmrgfunc_cygming_gnu_implib_p ()
5297862bcd1aSmrg{
5298862bcd1aSmrg  $debug_cmd
5299862bcd1aSmrg
5300862bcd1aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5301862bcd1aSmrg  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)$'`
5302862bcd1aSmrg  test -n "$func_cygming_gnu_implib_tmp"
5303862bcd1aSmrg}
5304862bcd1aSmrg
5305862bcd1aSmrg# func_cygming_ms_implib_p ARG
5306862bcd1aSmrg# This predicate returns with zero status (TRUE) if
5307862bcd1aSmrg# ARG is an MS-style import library. Returns
5308862bcd1aSmrg# with nonzero status (FALSE) otherwise.
5309862bcd1aSmrgfunc_cygming_ms_implib_p ()
5310862bcd1aSmrg{
5311862bcd1aSmrg  $debug_cmd
5312862bcd1aSmrg
5313862bcd1aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5314862bcd1aSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5315862bcd1aSmrg  test -n "$func_cygming_ms_implib_tmp"
5316862bcd1aSmrg}
5317862bcd1aSmrg
531888de56ccSmrg# func_win32_libid arg
531988de56ccSmrg# return the library type of file 'arg'
532088de56ccSmrg#
532188de56ccSmrg# Need a lot of goo to handle *both* DLLs and import libs
532288de56ccSmrg# Has to be a shell function in order to 'eat' the argument
532388de56ccSmrg# that is supplied when $file_magic_command is called.
5324e9fcaa8aSmrg# Despite the name, also deal with 64 bit binaries.
532588de56ccSmrgfunc_win32_libid ()
532688de56ccSmrg{
5327862bcd1aSmrg  $debug_cmd
5328862bcd1aSmrg
5329862bcd1aSmrg  win32_libid_type=unknown
533088de56ccSmrg  win32_fileres=`file -L $1 2>/dev/null`
533188de56ccSmrg  case $win32_fileres in
533288de56ccSmrg  *ar\ archive\ import\ library*) # definitely import
533388de56ccSmrg    win32_libid_type="x86 archive import"
533488de56ccSmrg    ;;
533588de56ccSmrg  *ar\ archive*) # could be an import, or static
5336e9fcaa8aSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
533788de56ccSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
533807fb9b8fSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then
5339862bcd1aSmrg      case $nm_interface in
5340862bcd1aSmrg      "MS dumpbin")
5341862bcd1aSmrg	if func_cygming_ms_implib_p "$1" ||
5342862bcd1aSmrg	   func_cygming_gnu_implib_p "$1"
5343862bcd1aSmrg	then
5344862bcd1aSmrg	  win32_nmres=import
5345862bcd1aSmrg	else
5346862bcd1aSmrg	  win32_nmres=
5347862bcd1aSmrg	fi
5348862bcd1aSmrg	;;
5349862bcd1aSmrg      *)
5350862bcd1aSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5351862bcd1aSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5352862bcd1aSmrg	  $SED -n -e '
535388de56ccSmrg	    1,100{
535488de56ccSmrg		/ I /{
5355862bcd1aSmrg		    s|.*|import|
535688de56ccSmrg		    p
535788de56ccSmrg		    q
535888de56ccSmrg		}
535988de56ccSmrg	    }'`
5360862bcd1aSmrg	;;
5361862bcd1aSmrg      esac
536288de56ccSmrg      case $win32_nmres in
536388de56ccSmrg      import*)  win32_libid_type="x86 archive import";;
536488de56ccSmrg      *)        win32_libid_type="x86 archive static";;
536588de56ccSmrg      esac
536688de56ccSmrg    fi
536788de56ccSmrg    ;;
536888de56ccSmrg  *DLL*)
536988de56ccSmrg    win32_libid_type="x86 DLL"
537088de56ccSmrg    ;;
537188de56ccSmrg  *executable*) # but shell scripts are "executable" too...
537288de56ccSmrg    case $win32_fileres in
537388de56ccSmrg    *MS\ Windows\ PE\ Intel*)
537488de56ccSmrg      win32_libid_type="x86 DLL"
537588de56ccSmrg      ;;
537688de56ccSmrg    esac
537788de56ccSmrg    ;;
537888de56ccSmrg  esac
537988de56ccSmrg  $ECHO "$win32_libid_type"
538088de56ccSmrg}
53812e9c7c8cSmrg
5382e9fcaa8aSmrg# func_cygming_dll_for_implib ARG
5383e9fcaa8aSmrg#
5384e9fcaa8aSmrg# Platform-specific function to extract the
5385e9fcaa8aSmrg# name of the DLL associated with the specified
5386e9fcaa8aSmrg# import library ARG.
5387e9fcaa8aSmrg# Invoked by eval'ing the libtool variable
5388e9fcaa8aSmrg#    $sharedlib_from_linklib_cmd
5389e9fcaa8aSmrg# Result is available in the variable
5390e9fcaa8aSmrg#    $sharedlib_from_linklib_result
5391e9fcaa8aSmrgfunc_cygming_dll_for_implib ()
5392e9fcaa8aSmrg{
5393862bcd1aSmrg  $debug_cmd
5394862bcd1aSmrg
5395e9fcaa8aSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5396e9fcaa8aSmrg}
5397e9fcaa8aSmrg
5398e9fcaa8aSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5399e9fcaa8aSmrg#
5400e9fcaa8aSmrg# The is the core of a fallback implementation of a
5401e9fcaa8aSmrg# platform-specific function to extract the name of the
5402e9fcaa8aSmrg# DLL associated with the specified import library LIBNAME.
5403e9fcaa8aSmrg#
5404e9fcaa8aSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5405e9fcaa8aSmrg# on the platform and compiler that created the implib.
5406e9fcaa8aSmrg#
5407e9fcaa8aSmrg# Echos the name of the DLL associated with the
5408e9fcaa8aSmrg# specified import library.
5409e9fcaa8aSmrgfunc_cygming_dll_for_implib_fallback_core ()
5410e9fcaa8aSmrg{
5411862bcd1aSmrg  $debug_cmd
5412862bcd1aSmrg
5413e9fcaa8aSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5414e9fcaa8aSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5415e9fcaa8aSmrg    $SED '/^Contents of section '"$match_literal"':/{
5416e9fcaa8aSmrg      # Place marker at beginning of archive member dllname section
5417e9fcaa8aSmrg      s/.*/====MARK====/
5418e9fcaa8aSmrg      p
5419e9fcaa8aSmrg      d
5420e9fcaa8aSmrg    }
5421e9fcaa8aSmrg    # These lines can sometimes be longer than 43 characters, but
5422e9fcaa8aSmrg    # are always uninteresting
5423e9fcaa8aSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5424e9fcaa8aSmrg    /^In archive [^:]*:/d
5425e9fcaa8aSmrg    # Ensure marker is printed
5426e9fcaa8aSmrg    /^====MARK====/p
5427e9fcaa8aSmrg    # Remove all lines with less than 43 characters
5428e9fcaa8aSmrg    /^.\{43\}/!d
5429e9fcaa8aSmrg    # From remaining lines, remove first 43 characters
5430e9fcaa8aSmrg    s/^.\{43\}//' |
5431e9fcaa8aSmrg    $SED -n '
5432e9fcaa8aSmrg      # Join marker and all lines until next marker into a single line
5433e9fcaa8aSmrg      /^====MARK====/ b para
5434e9fcaa8aSmrg      H
5435e9fcaa8aSmrg      $ b para
5436e9fcaa8aSmrg      b
5437e9fcaa8aSmrg      :para
5438e9fcaa8aSmrg      x
5439e9fcaa8aSmrg      s/\n//g
5440e9fcaa8aSmrg      # Remove the marker
5441e9fcaa8aSmrg      s/^====MARK====//
5442e9fcaa8aSmrg      # Remove trailing dots and whitespace
5443e9fcaa8aSmrg      s/[\. \t]*$//
5444e9fcaa8aSmrg      # Print
5445e9fcaa8aSmrg      /./p' |
5446e9fcaa8aSmrg    # we now have a list, one entry per line, of the stringified
5447e9fcaa8aSmrg    # contents of the appropriate section of all members of the
5448862bcd1aSmrg    # archive that possess that section. Heuristic: eliminate
5449862bcd1aSmrg    # all those that have a first or second character that is
5450e9fcaa8aSmrg    # a '.' (that is, objdump's representation of an unprintable
5451e9fcaa8aSmrg    # character.) This should work for all archives with less than
5452e9fcaa8aSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5453e9fcaa8aSmrg    # begins with a literal '.' or a single character followed by
5454e9fcaa8aSmrg    # a '.'.
5455e9fcaa8aSmrg    #
5456e9fcaa8aSmrg    # Of those that remain, print the first one.
5457e9fcaa8aSmrg    $SED -e '/^\./d;/^.\./d;q'
5458e9fcaa8aSmrg}
5459e9fcaa8aSmrg
5460e9fcaa8aSmrg# func_cygming_dll_for_implib_fallback ARG
5461e9fcaa8aSmrg# Platform-specific function to extract the
5462e9fcaa8aSmrg# name of the DLL associated with the specified
5463e9fcaa8aSmrg# import library ARG.
5464e9fcaa8aSmrg#
5465e9fcaa8aSmrg# This fallback implementation is for use when $DLLTOOL
5466e9fcaa8aSmrg# does not support the --identify-strict option.
5467e9fcaa8aSmrg# Invoked by eval'ing the libtool variable
5468e9fcaa8aSmrg#    $sharedlib_from_linklib_cmd
5469e9fcaa8aSmrg# Result is available in the variable
5470e9fcaa8aSmrg#    $sharedlib_from_linklib_result
5471e9fcaa8aSmrgfunc_cygming_dll_for_implib_fallback ()
5472e9fcaa8aSmrg{
5473862bcd1aSmrg  $debug_cmd
5474862bcd1aSmrg
5475862bcd1aSmrg  if func_cygming_gnu_implib_p "$1"; then
5476e9fcaa8aSmrg    # binutils import library
5477e9fcaa8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5478862bcd1aSmrg  elif func_cygming_ms_implib_p "$1"; then
5479e9fcaa8aSmrg    # ms-generated import library
5480e9fcaa8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5481e9fcaa8aSmrg  else
5482e9fcaa8aSmrg    # unknown
5483862bcd1aSmrg    sharedlib_from_linklib_result=
5484e9fcaa8aSmrg  fi
5485e9fcaa8aSmrg}
54862e9c7c8cSmrg
54872e9c7c8cSmrg
548888de56ccSmrg# func_extract_an_archive dir oldlib
548988de56ccSmrgfunc_extract_an_archive ()
549088de56ccSmrg{
5491862bcd1aSmrg    $debug_cmd
5492862bcd1aSmrg
5493862bcd1aSmrg    f_ex_an_ar_dir=$1; shift
5494862bcd1aSmrg    f_ex_an_ar_oldlib=$1
5495862bcd1aSmrg    if test yes = "$lock_old_archive_extraction"; then
5496e9fcaa8aSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5497e9fcaa8aSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5498e9fcaa8aSmrg	func_echo "Waiting for $lockfile to be removed"
5499e9fcaa8aSmrg	sleep 2
5500e9fcaa8aSmrg      done
5501e9fcaa8aSmrg    fi
5502e9fcaa8aSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5503e9fcaa8aSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5504862bcd1aSmrg    if test yes = "$lock_old_archive_extraction"; then
5505e9fcaa8aSmrg      $opt_dry_run || rm -f "$lockfile"
5506e9fcaa8aSmrg    fi
550788de56ccSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
550888de56ccSmrg     :
550988de56ccSmrg    else
551088de56ccSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
551188de56ccSmrg    fi
551288de56ccSmrg}
55131ab64890Smrg
55141ab64890Smrg
551588de56ccSmrg# func_extract_archives gentop oldlib ...
551688de56ccSmrgfunc_extract_archives ()
551788de56ccSmrg{
5518862bcd1aSmrg    $debug_cmd
5519862bcd1aSmrg
5520862bcd1aSmrg    my_gentop=$1; shift
552188de56ccSmrg    my_oldlibs=${1+"$@"}
5522862bcd1aSmrg    my_oldobjs=
5523862bcd1aSmrg    my_xlib=
5524862bcd1aSmrg    my_xabs=
5525862bcd1aSmrg    my_xdir=
55261ab64890Smrg
552788de56ccSmrg    for my_xlib in $my_oldlibs; do
552888de56ccSmrg      # Extract the objects.
552988de56ccSmrg      case $my_xlib in
5530862bcd1aSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
553188de56ccSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
553288de56ccSmrg      esac
553388de56ccSmrg      func_basename "$my_xlib"
5534862bcd1aSmrg      my_xlib=$func_basename_result
553588de56ccSmrg      my_xlib_u=$my_xlib
553688de56ccSmrg      while :; do
553788de56ccSmrg        case " $extracted_archives " in
553888de56ccSmrg	*" $my_xlib_u "*)
553988de56ccSmrg	  func_arith $extracted_serial + 1
554088de56ccSmrg	  extracted_serial=$func_arith_result
554188de56ccSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
554288de56ccSmrg	*) break ;;
554388de56ccSmrg	esac
554488de56ccSmrg      done
554588de56ccSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5546862bcd1aSmrg      my_xdir=$my_gentop/$my_xlib_u
55471ab64890Smrg
554888de56ccSmrg      func_mkdir_p "$my_xdir"
55492e9c7c8cSmrg
555088de56ccSmrg      case $host in
555188de56ccSmrg      *-darwin*)
555288de56ccSmrg	func_verbose "Extracting $my_xabs"
555388de56ccSmrg	# Do not bother doing anything if just a dry run
555488de56ccSmrg	$opt_dry_run || {
555588de56ccSmrg	  darwin_orig_dir=`pwd`
555688de56ccSmrg	  cd $my_xdir || exit $?
555788de56ccSmrg	  darwin_archive=$my_xabs
555888de56ccSmrg	  darwin_curdir=`pwd`
5559862bcd1aSmrg	  func_basename "$darwin_archive"
5560862bcd1aSmrg	  darwin_base_archive=$func_basename_result
556188de56ccSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
556288de56ccSmrg	  if test -n "$darwin_arches"; then
556388de56ccSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
556488de56ccSmrg	    darwin_arch=
556588de56ccSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5566862bcd1aSmrg	    for darwin_arch in  $darwin_arches; do
5567862bcd1aSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5568862bcd1aSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5569862bcd1aSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5570862bcd1aSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
557188de56ccSmrg	      cd "$darwin_curdir"
5572862bcd1aSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
557388de56ccSmrg	    done # $darwin_arches
557488de56ccSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5575862bcd1aSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
557688de56ccSmrg	    darwin_file=
557788de56ccSmrg	    darwin_files=
557888de56ccSmrg	    for darwin_file in $darwin_filelist; do
5579e9fcaa8aSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
558088de56ccSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
558188de56ccSmrg	    done # $darwin_filelist
558288de56ccSmrg	    $RM -rf unfat-$$
558388de56ccSmrg	    cd "$darwin_orig_dir"
5584b4ee4795Smrg	  else
558588de56ccSmrg	    cd $darwin_orig_dir
558688de56ccSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
558788de56ccSmrg	  fi # $darwin_arches
558888de56ccSmrg	} # !$opt_dry_run
558988de56ccSmrg	;;
559088de56ccSmrg      *)
559188de56ccSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
559288de56ccSmrg	;;
559388de56ccSmrg      esac
5594e9fcaa8aSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
559588de56ccSmrg    done
55961ab64890Smrg
5597862bcd1aSmrg    func_extract_archives_result=$my_oldobjs
559888de56ccSmrg}
55991ab64890Smrg
56001ab64890Smrg
5601e9fcaa8aSmrg# func_emit_wrapper [arg=no]
5602e9fcaa8aSmrg#
5603e9fcaa8aSmrg# Emit a libtool wrapper script on stdout.
5604e9fcaa8aSmrg# Don't directly open a file because we may want to
560507fb9b8fSmrg# incorporate the script contents within a cygwin/mingw/windows
5606e9fcaa8aSmrg# wrapper executable.  Must ONLY be called from within
5607e9fcaa8aSmrg# func_mode_link because it depends on a number of variables
5608e9fcaa8aSmrg# set therein.
560988de56ccSmrg#
5610e9fcaa8aSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5611e9fcaa8aSmrg# variable will take.  If 'yes', then the emitted script
5612862bcd1aSmrg# will assume that the directory where it is stored is
561307fb9b8fSmrg# the $objdir directory.  This is a cygwin/mingw/windows-specific
5614e9fcaa8aSmrg# behavior.
5615e9fcaa8aSmrgfunc_emit_wrapper ()
561688de56ccSmrg{
5617e9fcaa8aSmrg	func_emit_wrapper_arg1=${1-no}
5618b4ee4795Smrg
561988de56ccSmrg	$ECHO "\
562088de56ccSmrg#! $SHELL
56211ab64890Smrg
562288de56ccSmrg# $output - temporary wrapper script for $objdir/$outputname
5623862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
562488de56ccSmrg#
562588de56ccSmrg# The $output program cannot be directly executed until all the libtool
562688de56ccSmrg# libraries that it depends on are installed.
562788de56ccSmrg#
562888de56ccSmrg# This wrapper script should never be moved out of the build directory.
562988de56ccSmrg# If it is, it will not operate correctly.
56301ab64890Smrg
563188de56ccSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
563288de56ccSmrg# metacharacters that are still active within double-quoted strings.
563388de56ccSmrgsed_quote_subst='$sed_quote_subst'
56341ab64890Smrg
563588de56ccSmrg# Be Bourne compatible
563688de56ccSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
563788de56ccSmrg  emulate sh
563888de56ccSmrg  NULLCMD=:
563988de56ccSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
564088de56ccSmrg  # is contrary to our usage.  Disable this feature.
564188de56ccSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
564288de56ccSmrg  setopt NO_GLOB_SUBST
564388de56ccSmrgelse
564488de56ccSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
564588de56ccSmrgfi
564688de56ccSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
564788de56ccSmrgDUALCASE=1; export DUALCASE # for MKS sh
56481ab64890Smrg
564988de56ccSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
565088de56ccSmrg# if CDPATH is set.
565188de56ccSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
56521ab64890Smrg
565388de56ccSmrgrelink_command=\"$relink_command\"
56541ab64890Smrg
565588de56ccSmrg# This environment variable determines our operation mode.
565688de56ccSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
565788de56ccSmrg  # install mode needs the following variables:
565888de56ccSmrg  generated_by_libtool_version='$macro_version'
565988de56ccSmrg  notinst_deplibs='$notinst_deplibs'
566088de56ccSmrgelse
566188de56ccSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
566288de56ccSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5663e9fcaa8aSmrg    file=\"\$0\""
5664e9fcaa8aSmrg
56657d2c738bSmrg    func_quote_arg pretty "$ECHO"
56667d2c738bSmrg    qECHO=$func_quote_arg_result
5667e9fcaa8aSmrg    $ECHO "\
5668e9fcaa8aSmrg
5669e9fcaa8aSmrg# A function that is used when there is no print builtin or printf.
5670e9fcaa8aSmrgfunc_fallback_echo ()
5671e9fcaa8aSmrg{
5672e9fcaa8aSmrg  eval 'cat <<_LTECHO_EOF
5673e9fcaa8aSmrg\$1
5674e9fcaa8aSmrg_LTECHO_EOF'
5675e9fcaa8aSmrg}
56767d2c738bSmrg    ECHO=$qECHO
5677e9fcaa8aSmrg  fi
5678e9fcaa8aSmrg
5679e9fcaa8aSmrg# Very basic option parsing. These options are (a) specific to
5680e9fcaa8aSmrg# the libtool wrapper, (b) are identical between the wrapper
5681862bcd1aSmrg# /script/ and the wrapper /executable/ that is used only on
5682e9fcaa8aSmrg# windows platforms, and (c) all begin with the string "--lt-"
5683862bcd1aSmrg# (application programs are unlikely to have options that match
5684e9fcaa8aSmrg# this pattern).
5685e9fcaa8aSmrg#
5686e9fcaa8aSmrg# There are only two supported options: --lt-debug and
5687e9fcaa8aSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5688e9fcaa8aSmrg#
5689e9fcaa8aSmrg# The first argument to this parsing function should be the
5690e9fcaa8aSmrg# script's $0 value, followed by "$@".
5691e9fcaa8aSmrglt_option_debug=
5692e9fcaa8aSmrgfunc_parse_lt_options ()
5693e9fcaa8aSmrg{
5694e9fcaa8aSmrg  lt_script_arg0=\$0
5695e9fcaa8aSmrg  shift
5696e9fcaa8aSmrg  for lt_opt
5697e9fcaa8aSmrg  do
5698e9fcaa8aSmrg    case \"\$lt_opt\" in
5699e9fcaa8aSmrg    --lt-debug) lt_option_debug=1 ;;
5700e9fcaa8aSmrg    --lt-dump-script)
5701e9fcaa8aSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5702e9fcaa8aSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5703e9fcaa8aSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5704e9fcaa8aSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5705e9fcaa8aSmrg        exit 0
5706e9fcaa8aSmrg      ;;
5707e9fcaa8aSmrg    --lt-*)
5708e9fcaa8aSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5709e9fcaa8aSmrg        exit 1
5710e9fcaa8aSmrg      ;;
5711e9fcaa8aSmrg    esac
5712e9fcaa8aSmrg  done
5713e9fcaa8aSmrg
5714e9fcaa8aSmrg  # Print the debug banner immediately:
5715e9fcaa8aSmrg  if test -n \"\$lt_option_debug\"; then
5716862bcd1aSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5717e9fcaa8aSmrg  fi
5718e9fcaa8aSmrg}
5719e9fcaa8aSmrg
5720e9fcaa8aSmrg# Used when --lt-debug. Prints its arguments to stdout
5721e9fcaa8aSmrg# (redirection is the responsibility of the caller)
5722e9fcaa8aSmrgfunc_lt_dump_args ()
5723e9fcaa8aSmrg{
5724e9fcaa8aSmrg  lt_dump_args_N=1;
5725e9fcaa8aSmrg  for lt_arg
5726e9fcaa8aSmrg  do
5727862bcd1aSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5728e9fcaa8aSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5729e9fcaa8aSmrg  done
5730e9fcaa8aSmrg}
5731e9fcaa8aSmrg
5732e9fcaa8aSmrg# Core function for launching the target application
5733e9fcaa8aSmrgfunc_exec_program_core ()
5734e9fcaa8aSmrg{
573588de56ccSmrg"
5736e9fcaa8aSmrg  case $host in
5737e9fcaa8aSmrg  # Backslashes separate directories on plain windows
573807fb9b8fSmrg  *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*)
5739e9fcaa8aSmrg    $ECHO "\
5740e9fcaa8aSmrg      if test -n \"\$lt_option_debug\"; then
5741862bcd1aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5742e9fcaa8aSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5743e9fcaa8aSmrg      fi
5744e9fcaa8aSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5745e9fcaa8aSmrg"
5746e9fcaa8aSmrg    ;;
5747e9fcaa8aSmrg
5748e9fcaa8aSmrg  *)
5749e9fcaa8aSmrg    $ECHO "\
5750e9fcaa8aSmrg      if test -n \"\$lt_option_debug\"; then
5751862bcd1aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5752e9fcaa8aSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5753e9fcaa8aSmrg      fi
5754e9fcaa8aSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5755e9fcaa8aSmrg"
5756e9fcaa8aSmrg    ;;
5757e9fcaa8aSmrg  esac
5758e9fcaa8aSmrg  $ECHO "\
5759e9fcaa8aSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5760e9fcaa8aSmrg      exit 1
5761e9fcaa8aSmrg}
5762e9fcaa8aSmrg
5763e9fcaa8aSmrg# A function to encapsulate launching the target application
5764e9fcaa8aSmrg# Strips options in the --lt-* namespace from \$@ and
5765e9fcaa8aSmrg# launches target application with the remaining arguments.
5766e9fcaa8aSmrgfunc_exec_program ()
5767e9fcaa8aSmrg{
5768eb411b4bSmrg  case \" \$* \" in
5769eb411b4bSmrg  *\\ --lt-*)
5770eb411b4bSmrg    for lt_wr_arg
5771eb411b4bSmrg    do
5772eb411b4bSmrg      case \$lt_wr_arg in
5773eb411b4bSmrg      --lt-*) ;;
5774eb411b4bSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5775eb411b4bSmrg      esac
5776eb411b4bSmrg      shift
5777eb411b4bSmrg    done ;;
5778eb411b4bSmrg  esac
5779e9fcaa8aSmrg  func_exec_program_core \${1+\"\$@\"}
5780e9fcaa8aSmrg}
5781e9fcaa8aSmrg
5782e9fcaa8aSmrg  # Parse options
5783e9fcaa8aSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
57841ab64890Smrg
578588de56ccSmrg  # Find the directory that this script lives in.
5786e9fcaa8aSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
578788de56ccSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
57881ab64890Smrg
578988de56ccSmrg  # Follow symbolic links until we get to the real thisdir.
5790e9fcaa8aSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
579188de56ccSmrg  while test -n \"\$file\"; do
5792e9fcaa8aSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
57931ab64890Smrg
579488de56ccSmrg    # If there was a directory component, then change thisdir.
579588de56ccSmrg    if test \"x\$destdir\" != \"x\$file\"; then
579688de56ccSmrg      case \"\$destdir\" in
579788de56ccSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
579888de56ccSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5799b4ee4795Smrg      esac
580088de56ccSmrg    fi
58011ab64890Smrg
5802e9fcaa8aSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5803e9fcaa8aSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
580488de56ccSmrg  done
58051ab64890Smrg
580607fb9b8fSmrg  # Usually 'no', except on cygwin/mingw/windows when embedded into
580788de56ccSmrg  # the cwrapper.
5808e9fcaa8aSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
580988de56ccSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
581088de56ccSmrg    # special case for '.'
581188de56ccSmrg    if test \"\$thisdir\" = \".\"; then
581288de56ccSmrg      thisdir=\`pwd\`
581388de56ccSmrg    fi
581488de56ccSmrg    # remove .libs from thisdir
581588de56ccSmrg    case \"\$thisdir\" in
5816e9fcaa8aSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
581788de56ccSmrg    $objdir )   thisdir=. ;;
581888de56ccSmrg    esac
581988de56ccSmrg  fi
582088de56ccSmrg
582188de56ccSmrg  # Try to get the absolute directory name.
582288de56ccSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
582388de56ccSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
582488de56ccSmrg"
582588de56ccSmrg
5826862bcd1aSmrg	if test yes = "$fast_install"; then
582788de56ccSmrg	  $ECHO "\
582888de56ccSmrg  program=lt-'$outputname'$exeext
582988de56ccSmrg  progdir=\"\$thisdir/$objdir\"
583088de56ccSmrg
583188de56ccSmrg  if test ! -f \"\$progdir/\$program\" ||
5832862bcd1aSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
583388de56ccSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
583488de56ccSmrg
583588de56ccSmrg    file=\"\$\$-\$program\"
583688de56ccSmrg
583788de56ccSmrg    if test ! -d \"\$progdir\"; then
583888de56ccSmrg      $MKDIR \"\$progdir\"
583988de56ccSmrg    else
584088de56ccSmrg      $RM \"\$progdir/\$file\"
584188de56ccSmrg    fi"
584288de56ccSmrg
584388de56ccSmrg	  $ECHO "\
584488de56ccSmrg
584588de56ccSmrg    # relink executable if necessary
584688de56ccSmrg    if test -n \"\$relink_command\"; then
584788de56ccSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
584888de56ccSmrg      else
5849862bcd1aSmrg	\$ECHO \"\$relink_command_output\" >&2
585088de56ccSmrg	$RM \"\$progdir/\$file\"
585188de56ccSmrg	exit 1
5852b4ee4795Smrg      fi
585388de56ccSmrg    fi
58541ab64890Smrg
585588de56ccSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
585688de56ccSmrg    { $RM \"\$progdir/\$program\";
585788de56ccSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
585888de56ccSmrg    $RM \"\$progdir/\$file\"
585988de56ccSmrg  fi"
586088de56ccSmrg	else
586188de56ccSmrg	  $ECHO "\
586288de56ccSmrg  program='$outputname'
586388de56ccSmrg  progdir=\"\$thisdir/$objdir\"
586488de56ccSmrg"
5865b4ee4795Smrg	fi
58661ab64890Smrg
586788de56ccSmrg	$ECHO "\
58681ab64890Smrg
586988de56ccSmrg  if test -f \"\$progdir/\$program\"; then"
58701ab64890Smrg
5871e9fcaa8aSmrg	# fixup the dll searchpath if we need to.
5872e9fcaa8aSmrg	#
5873e9fcaa8aSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5874e9fcaa8aSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5875e9fcaa8aSmrg	# libraries must come first.
5876e9fcaa8aSmrg	if test -n "$dllsearchpath"; then
5877e9fcaa8aSmrg	  $ECHO "\
5878e9fcaa8aSmrg    # Add the dll search path components to the executable PATH
5879e9fcaa8aSmrg    PATH=$dllsearchpath:\$PATH
5880e9fcaa8aSmrg"
5881e9fcaa8aSmrg	fi
5882e9fcaa8aSmrg
588388de56ccSmrg	# Export our shlibpath_var if we have one.
5884862bcd1aSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
588588de56ccSmrg	  $ECHO "\
588688de56ccSmrg    # Add our own library path to $shlibpath_var
588788de56ccSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
588888de56ccSmrg
588988de56ccSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
589088de56ccSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
5891e9fcaa8aSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
58921ab64890Smrg
589388de56ccSmrg    export $shlibpath_var
589488de56ccSmrg"
5895b4ee4795Smrg	fi
58961ab64890Smrg
589788de56ccSmrg	$ECHO "\
589888de56ccSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
589988de56ccSmrg      # Run the actual program with our arguments.
5900e9fcaa8aSmrg      func_exec_program \${1+\"\$@\"}
590188de56ccSmrg    fi
590288de56ccSmrg  else
590388de56ccSmrg    # The program doesn't exist.
5904862bcd1aSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
590588de56ccSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5906e9fcaa8aSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
590788de56ccSmrg    exit 1
590888de56ccSmrg  fi
590988de56ccSmrgfi\
591088de56ccSmrg"
591188de56ccSmrg}
59121ab64890Smrg
59131ab64890Smrg
591488de56ccSmrg# func_emit_cwrapperexe_src
591588de56ccSmrg# emit the source code for a wrapper executable on stdout
591688de56ccSmrg# Must ONLY be called from within func_mode_link because
591788de56ccSmrg# it depends on a number of variable set therein.
591888de56ccSmrgfunc_emit_cwrapperexe_src ()
591988de56ccSmrg{
592088de56ccSmrg	cat <<EOF
59211ab64890Smrg
592288de56ccSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5923862bcd1aSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
59241ab64890Smrg
592588de56ccSmrg   The $output program cannot be directly executed until all the libtool
592688de56ccSmrg   libraries that it depends on are installed.
59271ab64890Smrg
592888de56ccSmrg   This wrapper executable should never be moved out of the build directory.
592988de56ccSmrg   If it is, it will not operate correctly.
593088de56ccSmrg*/
593188de56ccSmrgEOF
593288de56ccSmrg	    cat <<"EOF"
5933e9fcaa8aSmrg#ifdef _MSC_VER
5934e9fcaa8aSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5935e9fcaa8aSmrg#endif
593688de56ccSmrg#include <stdio.h>
593788de56ccSmrg#include <stdlib.h>
593807fb9b8fSmrg#if defined _WIN32 && !defined __GNUC__
593988de56ccSmrg# include <direct.h>
594088de56ccSmrg# include <process.h>
594188de56ccSmrg# include <io.h>
594288de56ccSmrg#else
594388de56ccSmrg# include <unistd.h>
594488de56ccSmrg# include <stdint.h>
594588de56ccSmrg# ifdef __CYGWIN__
594688de56ccSmrg#  include <io.h>
5947e9fcaa8aSmrg# endif
5948e9fcaa8aSmrg#endif
5949e9fcaa8aSmrg#include <malloc.h>
5950e9fcaa8aSmrg#include <stdarg.h>
5951e9fcaa8aSmrg#include <assert.h>
5952e9fcaa8aSmrg#include <string.h>
5953e9fcaa8aSmrg#include <ctype.h>
5954e9fcaa8aSmrg#include <errno.h>
5955e9fcaa8aSmrg#include <fcntl.h>
5956e9fcaa8aSmrg#include <sys/stat.h>
5957e9fcaa8aSmrg
5958862bcd1aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5959862bcd1aSmrg
5960e9fcaa8aSmrg/* declarations of non-ANSI functions */
5961862bcd1aSmrg#if defined __MINGW32__
5962e9fcaa8aSmrg# ifdef __STRICT_ANSI__
596307fb9b8fSmrg_CRTIMP int __cdecl _putenv (const char *);
5964e9fcaa8aSmrg# endif
5965862bcd1aSmrg#elif defined __CYGWIN__
5966e9fcaa8aSmrg# ifdef __STRICT_ANSI__
596788de56ccSmrgchar *realpath (const char *, char *);
596888de56ccSmrgint putenv (char *);
596988de56ccSmrgint setenv (const char *, const char *, int);
597088de56ccSmrg# endif
5971862bcd1aSmrg/* #elif defined other_platform || defined ... */
5972e9fcaa8aSmrg#endif
5973e9fcaa8aSmrg
5974e9fcaa8aSmrg/* portability defines, excluding path handling macros */
5975862bcd1aSmrg#if defined _MSC_VER
5976e9fcaa8aSmrg# define setmode _setmode
5977e9fcaa8aSmrg# define stat    _stat
5978e9fcaa8aSmrg# define chmod   _chmod
5979e9fcaa8aSmrg# define getcwd  _getcwd
5980e9fcaa8aSmrg# define putenv  _putenv
5981e9fcaa8aSmrg# define S_IXUSR _S_IEXEC
5982862bcd1aSmrg#elif defined __MINGW32__
5983e9fcaa8aSmrg# define setmode _setmode
5984e9fcaa8aSmrg# define stat    _stat
5985e9fcaa8aSmrg# define chmod   _chmod
5986e9fcaa8aSmrg# define getcwd  _getcwd
5987e9fcaa8aSmrg# define putenv  _putenv
5988862bcd1aSmrg#elif defined __CYGWIN__
5989e9fcaa8aSmrg# define HAVE_SETENV
5990e9fcaa8aSmrg# define FOPEN_WB "wb"
5991862bcd1aSmrg/* #elif defined other platforms ... */
599288de56ccSmrg#endif
59931ab64890Smrg
5994862bcd1aSmrg#if defined PATH_MAX
599588de56ccSmrg# define LT_PATHMAX PATH_MAX
5996862bcd1aSmrg#elif defined MAXPATHLEN
599788de56ccSmrg# define LT_PATHMAX MAXPATHLEN
599888de56ccSmrg#else
599988de56ccSmrg# define LT_PATHMAX 1024
600088de56ccSmrg#endif
60011ab64890Smrg
600288de56ccSmrg#ifndef S_IXOTH
600388de56ccSmrg# define S_IXOTH 0
600488de56ccSmrg#endif
600588de56ccSmrg#ifndef S_IXGRP
600688de56ccSmrg# define S_IXGRP 0
600788de56ccSmrg#endif
60081ab64890Smrg
6009e9fcaa8aSmrg/* path handling portability macros */
601088de56ccSmrg#ifndef DIR_SEPARATOR
601188de56ccSmrg# define DIR_SEPARATOR '/'
601288de56ccSmrg# define PATH_SEPARATOR ':'
601388de56ccSmrg#endif
60141ab64890Smrg
6015862bcd1aSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
6016862bcd1aSmrg  defined __OS2__
601788de56ccSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
601888de56ccSmrg# define FOPEN_WB "wb"
601988de56ccSmrg# ifndef DIR_SEPARATOR_2
602088de56ccSmrg#  define DIR_SEPARATOR_2 '\\'
602188de56ccSmrg# endif
602288de56ccSmrg# ifndef PATH_SEPARATOR_2
602388de56ccSmrg#  define PATH_SEPARATOR_2 ';'
602488de56ccSmrg# endif
602588de56ccSmrg#endif
60261ab64890Smrg
602788de56ccSmrg#ifndef DIR_SEPARATOR_2
602888de56ccSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
602988de56ccSmrg#else /* DIR_SEPARATOR_2 */
603088de56ccSmrg# define IS_DIR_SEPARATOR(ch) \
603188de56ccSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
603288de56ccSmrg#endif /* DIR_SEPARATOR_2 */
60331ab64890Smrg
603488de56ccSmrg#ifndef PATH_SEPARATOR_2
603588de56ccSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
603688de56ccSmrg#else /* PATH_SEPARATOR_2 */
603788de56ccSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
603888de56ccSmrg#endif /* PATH_SEPARATOR_2 */
60391ab64890Smrg
604088de56ccSmrg#ifndef FOPEN_WB
604188de56ccSmrg# define FOPEN_WB "w"
604288de56ccSmrg#endif
604388de56ccSmrg#ifndef _O_BINARY
604488de56ccSmrg# define _O_BINARY 0
604588de56ccSmrg#endif
60461ab64890Smrg
604788de56ccSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
604888de56ccSmrg#define XFREE(stale) do { \
6049862bcd1aSmrg  if (stale) { free (stale); stale = 0; } \
605088de56ccSmrg} while (0)
60511ab64890Smrg
6052862bcd1aSmrg#if defined LT_DEBUGWRAPPER
6053e9fcaa8aSmrgstatic int lt_debug = 1;
605488de56ccSmrg#else
6055e9fcaa8aSmrgstatic int lt_debug = 0;
605688de56ccSmrg#endif
60571ab64890Smrg
6058e9fcaa8aSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
60591ab64890Smrg
606088de56ccSmrgvoid *xmalloc (size_t num);
606188de56ccSmrgchar *xstrdup (const char *string);
606288de56ccSmrgconst char *base_name (const char *name);
606388de56ccSmrgchar *find_executable (const char *wrapper);
606488de56ccSmrgchar *chase_symlinks (const char *pathspec);
606588de56ccSmrgint make_executable (const char *path);
606688de56ccSmrgint check_executable (const char *path);
606788de56ccSmrgchar *strendzap (char *str, const char *pat);
6068e9fcaa8aSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
6069e9fcaa8aSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
6070e9fcaa8aSmrgstatic const char *nonnull (const char *s);
6071e9fcaa8aSmrgstatic const char *nonempty (const char *s);
607288de56ccSmrgvoid lt_setenv (const char *name, const char *value);
607388de56ccSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
607488de56ccSmrgvoid lt_update_exe_path (const char *name, const char *value);
607588de56ccSmrgvoid lt_update_lib_path (const char *name, const char *value);
6076e9fcaa8aSmrgchar **prepare_spawn (char **argv);
6077e9fcaa8aSmrgvoid lt_dump_script (FILE *f);
607888de56ccSmrgEOF
607988de56ccSmrg
608088de56ccSmrg	    cat <<EOF
6081862bcd1aSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
6082862bcd1aSmrg# define externally_visible volatile
6083862bcd1aSmrg#else
6084862bcd1aSmrg# define externally_visible __attribute__((externally_visible)) volatile
6085862bcd1aSmrg#endif
6086862bcd1aSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
608788de56ccSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
608888de56ccSmrgEOF
60891ab64890Smrg
6090862bcd1aSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
6091e9fcaa8aSmrg              func_to_host_path "$temp_rpath"
609288de56ccSmrg	      cat <<EOF
6093e9fcaa8aSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
609488de56ccSmrgEOF
609588de56ccSmrg	    else
609688de56ccSmrg	      cat <<"EOF"
609788de56ccSmrgconst char * LIB_PATH_VALUE   = "";
609888de56ccSmrgEOF
6099b4ee4795Smrg	    fi
61001ab64890Smrg
610188de56ccSmrg	    if test -n "$dllsearchpath"; then
6102e9fcaa8aSmrg              func_to_host_path "$dllsearchpath:"
610388de56ccSmrg	      cat <<EOF
610488de56ccSmrgconst char * EXE_PATH_VARNAME = "PATH";
6105e9fcaa8aSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
6106b4ee4795SmrgEOF
6107b4ee4795Smrg	    else
610888de56ccSmrg	      cat <<"EOF"
610988de56ccSmrgconst char * EXE_PATH_VARNAME = "";
611088de56ccSmrgconst char * EXE_PATH_VALUE   = "";
611188de56ccSmrgEOF
6112b4ee4795Smrg	    fi
611388de56ccSmrg
6114862bcd1aSmrg	    if test yes = "$fast_install"; then
611588de56ccSmrg	      cat <<EOF
611688de56ccSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
611788de56ccSmrgEOF
6118b4ee4795Smrg	    else
611988de56ccSmrg	      cat <<EOF
612088de56ccSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
612188de56ccSmrgEOF
6122b4ee4795Smrg	    fi
61231ab64890Smrg
61241ab64890Smrg
612588de56ccSmrg	    cat <<"EOF"
61261ab64890Smrg
612788de56ccSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
61281ab64890Smrg
612988de56ccSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
613088de56ccSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
6131e9fcaa8aSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
61321ab64890Smrg
613388de56ccSmrgint
613488de56ccSmrgmain (int argc, char *argv[])
613588de56ccSmrg{
613688de56ccSmrg  char **newargz;
613788de56ccSmrg  int  newargc;
613888de56ccSmrg  char *tmp_pathspec;
613988de56ccSmrg  char *actual_cwrapper_path;
614088de56ccSmrg  char *actual_cwrapper_name;
614188de56ccSmrg  char *target_name;
614288de56ccSmrg  char *lt_argv_zero;
6143862bcd1aSmrg  int rval = 127;
61441ab64890Smrg
614588de56ccSmrg  int i;
61461ab64890Smrg
614788de56ccSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6148862bcd1aSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
61491ab64890Smrg
6150e9fcaa8aSmrg  /* very simple arg parsing; don't want to rely on getopt
6151e9fcaa8aSmrg   * also, copy all non cwrapper options to newargz, except
6152e9fcaa8aSmrg   * argz[0], which is handled differently
6153e9fcaa8aSmrg   */
6154e9fcaa8aSmrg  newargc=0;
615588de56ccSmrg  for (i = 1; i < argc; i++)
615688de56ccSmrg    {
6157862bcd1aSmrg      if (STREQ (argv[i], dumpscript_opt))
615888de56ccSmrg	{
615988de56ccSmrgEOF
6160862bcd1aSmrg	    case $host in
616107fb9b8fSmrg	      *mingw* | *windows* | *cygwin* )
616288de56ccSmrg		# make stdout use "unix" line endings
616388de56ccSmrg		echo "          setmode(1,_O_BINARY);"
616488de56ccSmrg		;;
616588de56ccSmrg	      esac
61661ab64890Smrg
616788de56ccSmrg	    cat <<"EOF"
6168e9fcaa8aSmrg	  lt_dump_script (stdout);
616988de56ccSmrg	  return 0;
617088de56ccSmrg	}
6171862bcd1aSmrg      if (STREQ (argv[i], debug_opt))
6172e9fcaa8aSmrg	{
6173e9fcaa8aSmrg          lt_debug = 1;
6174e9fcaa8aSmrg          continue;
6175e9fcaa8aSmrg	}
6176862bcd1aSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6177e9fcaa8aSmrg        {
6178e9fcaa8aSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6179e9fcaa8aSmrg             namespace, but it is not one of the ones we know about and
618007fb9b8fSmrg             have already dealt with, above (including dump-script), then
6181e9fcaa8aSmrg             report an error. Otherwise, targets might begin to believe
6182e9fcaa8aSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6183e9fcaa8aSmrg             namespace. The first time any user complains about this, we'll
6184e9fcaa8aSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6185e9fcaa8aSmrg             or a configure.ac-settable value.
6186e9fcaa8aSmrg           */
6187e9fcaa8aSmrg          lt_fatal (__FILE__, __LINE__,
6188e9fcaa8aSmrg		    "unrecognized %s option: '%s'",
6189e9fcaa8aSmrg                    ltwrapper_option_prefix, argv[i]);
6190e9fcaa8aSmrg        }
6191e9fcaa8aSmrg      /* otherwise ... */
6192e9fcaa8aSmrg      newargz[++newargc] = xstrdup (argv[i]);
619388de56ccSmrg    }
6194e9fcaa8aSmrg  newargz[++newargc] = NULL;
6195e9fcaa8aSmrg
6196e9fcaa8aSmrgEOF
6197e9fcaa8aSmrg	    cat <<EOF
6198e9fcaa8aSmrg  /* The GNU banner must be the first non-error debug message */
6199862bcd1aSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6200e9fcaa8aSmrgEOF
6201e9fcaa8aSmrg	    cat <<"EOF"
6202e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6203e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
62041ab64890Smrg
620588de56ccSmrg  tmp_pathspec = find_executable (argv[0]);
620688de56ccSmrg  if (tmp_pathspec == NULL)
6207e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6208e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6209e9fcaa8aSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6210e9fcaa8aSmrg		  tmp_pathspec);
621188de56ccSmrg
621288de56ccSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6213e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6214e9fcaa8aSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6215e9fcaa8aSmrg		  actual_cwrapper_path);
621688de56ccSmrg  XFREE (tmp_pathspec);
621788de56ccSmrg
6218e9fcaa8aSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
621988de56ccSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
622088de56ccSmrg
622188de56ccSmrg  /* wrapper name transforms */
622288de56ccSmrg  strendzap (actual_cwrapper_name, ".exe");
622388de56ccSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
622488de56ccSmrg  XFREE (actual_cwrapper_name);
622588de56ccSmrg  actual_cwrapper_name = tmp_pathspec;
622688de56ccSmrg  tmp_pathspec = 0;
622788de56ccSmrg
622888de56ccSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
622988de56ccSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
623088de56ccSmrg  strendzap (target_name, ".exe");
623188de56ccSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
623288de56ccSmrg  XFREE (target_name);
623388de56ccSmrg  target_name = tmp_pathspec;
623488de56ccSmrg  tmp_pathspec = 0;
623588de56ccSmrg
6236e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6237e9fcaa8aSmrg		  "(main) libtool target name: %s\n",
6238e9fcaa8aSmrg		  target_name);
623988de56ccSmrgEOF
62401ab64890Smrg
624188de56ccSmrg	    cat <<EOF
624288de56ccSmrg  newargz[0] =
624388de56ccSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
624488de56ccSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
624588de56ccSmrg  strcpy (newargz[0], actual_cwrapper_path);
624688de56ccSmrg  strcat (newargz[0], "$objdir");
624788de56ccSmrg  strcat (newargz[0], "/");
624888de56ccSmrgEOF
62491ab64890Smrg
625088de56ccSmrg	    cat <<"EOF"
625188de56ccSmrg  /* stop here, and copy so we don't have to do this twice */
625288de56ccSmrg  tmp_pathspec = xstrdup (newargz[0]);
62531ab64890Smrg
625488de56ccSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
625588de56ccSmrg  strcat (newargz[0], actual_cwrapper_name);
62561ab64890Smrg
625788de56ccSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
625888de56ccSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
625988de56ccSmrg  XFREE (tmp_pathspec);
626088de56ccSmrg  tmp_pathspec = NULL;
626188de56ccSmrgEOF
62621ab64890Smrg
626388de56ccSmrg	    case $host_os in
626407fb9b8fSmrg	      mingw* | windows*)
626588de56ccSmrg	    cat <<"EOF"
626688de56ccSmrg  {
626788de56ccSmrg    char* p;
626888de56ccSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
626988de56ccSmrg      {
627088de56ccSmrg	*p = '/';
627188de56ccSmrg      }
627288de56ccSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
627388de56ccSmrg      {
627488de56ccSmrg	*p = '/';
627588de56ccSmrg      }
627688de56ccSmrg  }
627788de56ccSmrgEOF
627888de56ccSmrg	    ;;
627988de56ccSmrg	    esac
62801ab64890Smrg
628188de56ccSmrg	    cat <<"EOF"
628288de56ccSmrg  XFREE (target_name);
628388de56ccSmrg  XFREE (actual_cwrapper_path);
628488de56ccSmrg  XFREE (actual_cwrapper_name);
62851ab64890Smrg
628688de56ccSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
628788de56ccSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6288e9fcaa8aSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6289e9fcaa8aSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6290e9fcaa8aSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6291e9fcaa8aSmrg     libraries must come first. */
629288de56ccSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6293e9fcaa8aSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
62941ab64890Smrg
6295e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6296e9fcaa8aSmrg		  nonnull (lt_argv_zero));
629788de56ccSmrg  for (i = 0; i < newargc; i++)
629888de56ccSmrg    {
6299e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6300e9fcaa8aSmrg		      i, nonnull (newargz[i]));
630188de56ccSmrg    }
63021ab64890Smrg
630388de56ccSmrgEOF
63041ab64890Smrg
630588de56ccSmrg	    case $host_os in
630607fb9b8fSmrg	      mingw* | windows*)
630788de56ccSmrg		cat <<"EOF"
630888de56ccSmrg  /* execv doesn't actually work on mingw as expected on unix */
6309e9fcaa8aSmrg  newargz = prepare_spawn (newargz);
6310862bcd1aSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
631188de56ccSmrg  if (rval == -1)
631288de56ccSmrg    {
631388de56ccSmrg      /* failed to start process */
6314e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__,
6315e9fcaa8aSmrg		      "(main) failed to launch target \"%s\": %s\n",
6316e9fcaa8aSmrg		      lt_argv_zero, nonnull (strerror (errno)));
631788de56ccSmrg      return 127;
631888de56ccSmrg    }
631988de56ccSmrg  return rval;
632088de56ccSmrgEOF
632188de56ccSmrg		;;
632288de56ccSmrg	      *)
632388de56ccSmrg		cat <<"EOF"
632488de56ccSmrg  execv (lt_argv_zero, newargz);
632588de56ccSmrg  return rval; /* =127, but avoids unused variable warning */
632688de56ccSmrgEOF
632788de56ccSmrg		;;
632888de56ccSmrg	    esac
63291ab64890Smrg
633088de56ccSmrg	    cat <<"EOF"
633188de56ccSmrg}
63321ab64890Smrg
633388de56ccSmrgvoid *
633488de56ccSmrgxmalloc (size_t num)
633588de56ccSmrg{
633688de56ccSmrg  void *p = (void *) malloc (num);
633788de56ccSmrg  if (!p)
6338e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
63391ab64890Smrg
634088de56ccSmrg  return p;
634188de56ccSmrg}
63421ab64890Smrg
634388de56ccSmrgchar *
634488de56ccSmrgxstrdup (const char *string)
634588de56ccSmrg{
634688de56ccSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
634788de56ccSmrg			  string) : NULL;
634888de56ccSmrg}
63491ab64890Smrg
635088de56ccSmrgconst char *
635188de56ccSmrgbase_name (const char *name)
635288de56ccSmrg{
635388de56ccSmrg  const char *base;
6354b4ee4795Smrg
6355862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
635688de56ccSmrg  /* Skip over the disk name in MSDOS pathnames. */
635788de56ccSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
635888de56ccSmrg    name += 2;
635988de56ccSmrg#endif
6360b4ee4795Smrg
636188de56ccSmrg  for (base = name; *name; name++)
636288de56ccSmrg    if (IS_DIR_SEPARATOR (*name))
636388de56ccSmrg      base = name + 1;
636488de56ccSmrg  return base;
636588de56ccSmrg}
6366b4ee4795Smrg
636788de56ccSmrgint
636888de56ccSmrgcheck_executable (const char *path)
636988de56ccSmrg{
637088de56ccSmrg  struct stat st;
6371b4ee4795Smrg
6372e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6373e9fcaa8aSmrg                  nonempty (path));
637488de56ccSmrg  if ((!path) || (!*path))
637588de56ccSmrg    return 0;
6376b4ee4795Smrg
637788de56ccSmrg  if ((stat (path, &st) >= 0)
637888de56ccSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
637988de56ccSmrg    return 1;
638088de56ccSmrg  else
638188de56ccSmrg    return 0;
638288de56ccSmrg}
63831ab64890Smrg
638488de56ccSmrgint
638588de56ccSmrgmake_executable (const char *path)
638688de56ccSmrg{
638788de56ccSmrg  int rval = 0;
638888de56ccSmrg  struct stat st;
63891ab64890Smrg
6390e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6391e9fcaa8aSmrg                  nonempty (path));
639288de56ccSmrg  if ((!path) || (!*path))
639388de56ccSmrg    return 0;
63941ab64890Smrg
639588de56ccSmrg  if (stat (path, &st) >= 0)
639688de56ccSmrg    {
639788de56ccSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
639888de56ccSmrg    }
639988de56ccSmrg  return rval;
640088de56ccSmrg}
6401b4ee4795Smrg
640288de56ccSmrg/* Searches for the full path of the wrapper.  Returns
640388de56ccSmrg   newly allocated full path name if found, NULL otherwise
640488de56ccSmrg   Does not chase symlinks, even on platforms that support them.
640588de56ccSmrg*/
640688de56ccSmrgchar *
640788de56ccSmrgfind_executable (const char *wrapper)
640888de56ccSmrg{
640988de56ccSmrg  int has_slash = 0;
641088de56ccSmrg  const char *p;
641188de56ccSmrg  const char *p_next;
641288de56ccSmrg  /* static buffer for getcwd */
641388de56ccSmrg  char tmp[LT_PATHMAX + 1];
6414862bcd1aSmrg  size_t tmp_len;
641588de56ccSmrg  char *concat_name;
6416b4ee4795Smrg
6417e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6418e9fcaa8aSmrg                  nonempty (wrapper));
6419b4ee4795Smrg
642088de56ccSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
642188de56ccSmrg    return NULL;
6422b4ee4795Smrg
642388de56ccSmrg  /* Absolute path? */
6424862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
642588de56ccSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
642688de56ccSmrg    {
642788de56ccSmrg      concat_name = xstrdup (wrapper);
642888de56ccSmrg      if (check_executable (concat_name))
642988de56ccSmrg	return concat_name;
643088de56ccSmrg      XFREE (concat_name);
643188de56ccSmrg    }
643288de56ccSmrg  else
643388de56ccSmrg    {
643488de56ccSmrg#endif
643588de56ccSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
643688de56ccSmrg	{
643788de56ccSmrg	  concat_name = xstrdup (wrapper);
643888de56ccSmrg	  if (check_executable (concat_name))
643988de56ccSmrg	    return concat_name;
644088de56ccSmrg	  XFREE (concat_name);
644188de56ccSmrg	}
6442862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
644388de56ccSmrg    }
644488de56ccSmrg#endif
64451ab64890Smrg
644688de56ccSmrg  for (p = wrapper; *p; p++)
644788de56ccSmrg    if (*p == '/')
644888de56ccSmrg      {
644988de56ccSmrg	has_slash = 1;
645088de56ccSmrg	break;
645188de56ccSmrg      }
645288de56ccSmrg  if (!has_slash)
645388de56ccSmrg    {
645488de56ccSmrg      /* no slashes; search PATH */
645588de56ccSmrg      const char *path = getenv ("PATH");
645688de56ccSmrg      if (path != NULL)
645788de56ccSmrg	{
645888de56ccSmrg	  for (p = path; *p; p = p_next)
645988de56ccSmrg	    {
646088de56ccSmrg	      const char *q;
646188de56ccSmrg	      size_t p_len;
646288de56ccSmrg	      for (q = p; *q; q++)
646388de56ccSmrg		if (IS_PATH_SEPARATOR (*q))
646488de56ccSmrg		  break;
6465862bcd1aSmrg	      p_len = (size_t) (q - p);
646688de56ccSmrg	      p_next = (*q == '\0' ? q : q + 1);
646788de56ccSmrg	      if (p_len == 0)
646888de56ccSmrg		{
646988de56ccSmrg		  /* empty path: current directory */
647088de56ccSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6471e9fcaa8aSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6472e9fcaa8aSmrg                              nonnull (strerror (errno)));
647388de56ccSmrg		  tmp_len = strlen (tmp);
647488de56ccSmrg		  concat_name =
647588de56ccSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
647688de56ccSmrg		  memcpy (concat_name, tmp, tmp_len);
647788de56ccSmrg		  concat_name[tmp_len] = '/';
647888de56ccSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
647988de56ccSmrg		}
648088de56ccSmrg	      else
648188de56ccSmrg		{
648288de56ccSmrg		  concat_name =
648388de56ccSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
648488de56ccSmrg		  memcpy (concat_name, p, p_len);
648588de56ccSmrg		  concat_name[p_len] = '/';
648688de56ccSmrg		  strcpy (concat_name + p_len + 1, wrapper);
648788de56ccSmrg		}
648888de56ccSmrg	      if (check_executable (concat_name))
648988de56ccSmrg		return concat_name;
649088de56ccSmrg	      XFREE (concat_name);
649188de56ccSmrg	    }
649288de56ccSmrg	}
649388de56ccSmrg      /* not found in PATH; assume curdir */
649488de56ccSmrg    }
649588de56ccSmrg  /* Relative path | not found in path: prepend cwd */
649688de56ccSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6497e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6498e9fcaa8aSmrg              nonnull (strerror (errno)));
649988de56ccSmrg  tmp_len = strlen (tmp);
650088de56ccSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
650188de56ccSmrg  memcpy (concat_name, tmp, tmp_len);
650288de56ccSmrg  concat_name[tmp_len] = '/';
650388de56ccSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
65041ab64890Smrg
650588de56ccSmrg  if (check_executable (concat_name))
650688de56ccSmrg    return concat_name;
650788de56ccSmrg  XFREE (concat_name);
650888de56ccSmrg  return NULL;
650988de56ccSmrg}
65101ab64890Smrg
651188de56ccSmrgchar *
651288de56ccSmrgchase_symlinks (const char *pathspec)
651388de56ccSmrg{
651488de56ccSmrg#ifndef S_ISLNK
651588de56ccSmrg  return xstrdup (pathspec);
651688de56ccSmrg#else
651788de56ccSmrg  char buf[LT_PATHMAX];
651888de56ccSmrg  struct stat s;
651988de56ccSmrg  char *tmp_pathspec = xstrdup (pathspec);
652088de56ccSmrg  char *p;
652188de56ccSmrg  int has_symlinks = 0;
652288de56ccSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
652388de56ccSmrg    {
6524e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__,
6525e9fcaa8aSmrg		      "checking path component for symlinks: %s\n",
6526e9fcaa8aSmrg		      tmp_pathspec);
652788de56ccSmrg      if (lstat (tmp_pathspec, &s) == 0)
652888de56ccSmrg	{
652988de56ccSmrg	  if (S_ISLNK (s.st_mode) != 0)
653088de56ccSmrg	    {
653188de56ccSmrg	      has_symlinks = 1;
653288de56ccSmrg	      break;
653388de56ccSmrg	    }
65341ab64890Smrg
653588de56ccSmrg	  /* search backwards for last DIR_SEPARATOR */
653688de56ccSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
653788de56ccSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
653888de56ccSmrg	    p--;
653988de56ccSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
654088de56ccSmrg	    {
654188de56ccSmrg	      /* no more DIR_SEPARATORS left */
654288de56ccSmrg	      break;
654388de56ccSmrg	    }
654488de56ccSmrg	  *p = '\0';
654588de56ccSmrg	}
654688de56ccSmrg      else
654788de56ccSmrg	{
6548e9fcaa8aSmrg	  lt_fatal (__FILE__, __LINE__,
6549e9fcaa8aSmrg		    "error accessing file \"%s\": %s",
6550e9fcaa8aSmrg		    tmp_pathspec, nonnull (strerror (errno)));
655188de56ccSmrg	}
655288de56ccSmrg    }
655388de56ccSmrg  XFREE (tmp_pathspec);
65541ab64890Smrg
655588de56ccSmrg  if (!has_symlinks)
655688de56ccSmrg    {
655788de56ccSmrg      return xstrdup (pathspec);
655888de56ccSmrg    }
65591ab64890Smrg
656088de56ccSmrg  tmp_pathspec = realpath (pathspec, buf);
656188de56ccSmrg  if (tmp_pathspec == 0)
656288de56ccSmrg    {
6563e9fcaa8aSmrg      lt_fatal (__FILE__, __LINE__,
6564e9fcaa8aSmrg		"could not follow symlinks for %s", pathspec);
656588de56ccSmrg    }
656688de56ccSmrg  return xstrdup (tmp_pathspec);
656788de56ccSmrg#endif
656888de56ccSmrg}
65691ab64890Smrg
657088de56ccSmrgchar *
657188de56ccSmrgstrendzap (char *str, const char *pat)
657288de56ccSmrg{
657388de56ccSmrg  size_t len, patlen;
65741ab64890Smrg
657588de56ccSmrg  assert (str != NULL);
657688de56ccSmrg  assert (pat != NULL);
65771ab64890Smrg
657888de56ccSmrg  len = strlen (str);
657988de56ccSmrg  patlen = strlen (pat);
65801ab64890Smrg
658188de56ccSmrg  if (patlen <= len)
658288de56ccSmrg    {
658388de56ccSmrg      str += len - patlen;
6584862bcd1aSmrg      if (STREQ (str, pat))
658588de56ccSmrg	*str = '\0';
658688de56ccSmrg    }
658788de56ccSmrg  return str;
658888de56ccSmrg}
65891ab64890Smrg
6590e9fcaa8aSmrgvoid
6591e9fcaa8aSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6592e9fcaa8aSmrg{
6593e9fcaa8aSmrg  va_list args;
6594e9fcaa8aSmrg  if (lt_debug)
6595e9fcaa8aSmrg    {
6596e9fcaa8aSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6597e9fcaa8aSmrg      va_start (args, fmt);
6598e9fcaa8aSmrg      (void) vfprintf (stderr, fmt, args);
6599e9fcaa8aSmrg      va_end (args);
6600e9fcaa8aSmrg    }
6601e9fcaa8aSmrg}
6602e9fcaa8aSmrg
660388de56ccSmrgstatic void
6604e9fcaa8aSmrglt_error_core (int exit_status, const char *file,
6605e9fcaa8aSmrg	       int line, const char *mode,
660688de56ccSmrg	       const char *message, va_list ap)
660788de56ccSmrg{
6608e9fcaa8aSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
660988de56ccSmrg  vfprintf (stderr, message, ap);
661088de56ccSmrg  fprintf (stderr, ".\n");
66111ab64890Smrg
661288de56ccSmrg  if (exit_status >= 0)
661388de56ccSmrg    exit (exit_status);
661488de56ccSmrg}
66151ab64890Smrg
661688de56ccSmrgvoid
6617e9fcaa8aSmrglt_fatal (const char *file, int line, const char *message, ...)
661888de56ccSmrg{
661988de56ccSmrg  va_list ap;
662088de56ccSmrg  va_start (ap, message);
6621e9fcaa8aSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
662288de56ccSmrg  va_end (ap);
662388de56ccSmrg}
66242e9c7c8cSmrg
6625e9fcaa8aSmrgstatic const char *
6626e9fcaa8aSmrgnonnull (const char *s)
6627e9fcaa8aSmrg{
6628e9fcaa8aSmrg  return s ? s : "(null)";
6629e9fcaa8aSmrg}
6630e9fcaa8aSmrg
6631e9fcaa8aSmrgstatic const char *
6632e9fcaa8aSmrgnonempty (const char *s)
6633e9fcaa8aSmrg{
6634e9fcaa8aSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6635e9fcaa8aSmrg}
6636e9fcaa8aSmrg
663788de56ccSmrgvoid
663888de56ccSmrglt_setenv (const char *name, const char *value)
663988de56ccSmrg{
6640e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6641e9fcaa8aSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6642e9fcaa8aSmrg                  nonnull (name), nonnull (value));
664388de56ccSmrg  {
664488de56ccSmrg#ifdef HAVE_SETENV
664588de56ccSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
664688de56ccSmrg    char *str = xstrdup (value);
664788de56ccSmrg    setenv (name, str, 1);
664888de56ccSmrg#else
6649862bcd1aSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
665088de56ccSmrg    char *str = XMALLOC (char, len);
665188de56ccSmrg    sprintf (str, "%s=%s", name, value);
665288de56ccSmrg    if (putenv (str) != EXIT_SUCCESS)
665388de56ccSmrg      {
665488de56ccSmrg        XFREE (str);
665588de56ccSmrg      }
665688de56ccSmrg#endif
665788de56ccSmrg  }
665888de56ccSmrg}
66591ab64890Smrg
666088de56ccSmrgchar *
666188de56ccSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
666288de56ccSmrg{
666388de56ccSmrg  char *new_value;
666488de56ccSmrg  if (orig_value && *orig_value)
666588de56ccSmrg    {
6666862bcd1aSmrg      size_t orig_value_len = strlen (orig_value);
6667862bcd1aSmrg      size_t add_len = strlen (add);
666888de56ccSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
666988de56ccSmrg      if (to_end)
667088de56ccSmrg        {
667188de56ccSmrg          strcpy (new_value, orig_value);
667288de56ccSmrg          strcpy (new_value + orig_value_len, add);
667388de56ccSmrg        }
667488de56ccSmrg      else
667588de56ccSmrg        {
667688de56ccSmrg          strcpy (new_value, add);
667788de56ccSmrg          strcpy (new_value + add_len, orig_value);
667888de56ccSmrg        }
667988de56ccSmrg    }
668088de56ccSmrg  else
668188de56ccSmrg    {
668288de56ccSmrg      new_value = xstrdup (add);
668388de56ccSmrg    }
668488de56ccSmrg  return new_value;
668588de56ccSmrg}
66861ab64890Smrg
668788de56ccSmrgvoid
668888de56ccSmrglt_update_exe_path (const char *name, const char *value)
668988de56ccSmrg{
6690e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6691e9fcaa8aSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6692e9fcaa8aSmrg                  nonnull (name), nonnull (value));
66931ab64890Smrg
669488de56ccSmrg  if (name && *name && value && *value)
669588de56ccSmrg    {
669688de56ccSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
669788de56ccSmrg      /* some systems can't cope with a ':'-terminated path #' */
6698862bcd1aSmrg      size_t len = strlen (new_value);
6699862bcd1aSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
670088de56ccSmrg        {
6701862bcd1aSmrg          new_value[--len] = '\0';
670288de56ccSmrg        }
670388de56ccSmrg      lt_setenv (name, new_value);
670488de56ccSmrg      XFREE (new_value);
670588de56ccSmrg    }
670688de56ccSmrg}
67071ab64890Smrg
670888de56ccSmrgvoid
670988de56ccSmrglt_update_lib_path (const char *name, const char *value)
671088de56ccSmrg{
6711e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6712e9fcaa8aSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6713e9fcaa8aSmrg                  nonnull (name), nonnull (value));
67141ab64890Smrg
671588de56ccSmrg  if (name && *name && value && *value)
671688de56ccSmrg    {
671788de56ccSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
671888de56ccSmrg      lt_setenv (name, new_value);
671988de56ccSmrg      XFREE (new_value);
672088de56ccSmrg    }
672188de56ccSmrg}
67221ab64890Smrg
6723e9fcaa8aSmrgEOF
6724e9fcaa8aSmrg	    case $host_os in
672507fb9b8fSmrg	      mingw* | windows*)
6726e9fcaa8aSmrg		cat <<"EOF"
6727e9fcaa8aSmrg
6728e9fcaa8aSmrg/* Prepares an argument vector before calling spawn().
6729e9fcaa8aSmrg   Note that spawn() does not by itself call the command interpreter
6730e9fcaa8aSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6731e9fcaa8aSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6732e9fcaa8aSmrg         GetVersionEx(&v);
6733e9fcaa8aSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6734e9fcaa8aSmrg      }) ? "cmd.exe" : "command.com").
6735e9fcaa8aSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6736e9fcaa8aSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6737e9fcaa8aSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6738e9fcaa8aSmrg   special way:
6739e9fcaa8aSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6740e9fcaa8aSmrg     delimiters if they are surrounded by double quotes: "...".
6741e9fcaa8aSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6742e9fcaa8aSmrg     that within double quotes, space and tab are treated like normal
6743e9fcaa8aSmrg     characters.
6744e9fcaa8aSmrg   - Backslashes not followed by double quotes are not special.
6745e9fcaa8aSmrg   - But 2*n+1 backslashes followed by a double quote become
6746e9fcaa8aSmrg     n backslashes followed by a double quote (n >= 0):
6747e9fcaa8aSmrg       \" -> "
6748e9fcaa8aSmrg       \\\" -> \"
6749e9fcaa8aSmrg       \\\\\" -> \\"
6750e9fcaa8aSmrg */
6751e9fcaa8aSmrg#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"
6752e9fcaa8aSmrg#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"
6753e9fcaa8aSmrgchar **
6754e9fcaa8aSmrgprepare_spawn (char **argv)
6755e9fcaa8aSmrg{
6756e9fcaa8aSmrg  size_t argc;
6757e9fcaa8aSmrg  char **new_argv;
6758e9fcaa8aSmrg  size_t i;
6759e9fcaa8aSmrg
6760e9fcaa8aSmrg  /* Count number of arguments.  */
6761e9fcaa8aSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6762e9fcaa8aSmrg    ;
6763e9fcaa8aSmrg
6764e9fcaa8aSmrg  /* Allocate new argument vector.  */
6765e9fcaa8aSmrg  new_argv = XMALLOC (char *, argc + 1);
6766e9fcaa8aSmrg
6767e9fcaa8aSmrg  /* Put quoted arguments into the new argument vector.  */
6768e9fcaa8aSmrg  for (i = 0; i < argc; i++)
6769e9fcaa8aSmrg    {
6770e9fcaa8aSmrg      const char *string = argv[i];
6771e9fcaa8aSmrg
6772e9fcaa8aSmrg      if (string[0] == '\0')
6773e9fcaa8aSmrg	new_argv[i] = xstrdup ("\"\"");
6774e9fcaa8aSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6775e9fcaa8aSmrg	{
6776e9fcaa8aSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6777e9fcaa8aSmrg	  size_t length;
6778e9fcaa8aSmrg	  unsigned int backslashes;
6779e9fcaa8aSmrg	  const char *s;
6780e9fcaa8aSmrg	  char *quoted_string;
6781e9fcaa8aSmrg	  char *p;
6782e9fcaa8aSmrg
6783e9fcaa8aSmrg	  length = 0;
6784e9fcaa8aSmrg	  backslashes = 0;
6785e9fcaa8aSmrg	  if (quote_around)
6786e9fcaa8aSmrg	    length++;
6787e9fcaa8aSmrg	  for (s = string; *s != '\0'; s++)
6788e9fcaa8aSmrg	    {
6789e9fcaa8aSmrg	      char c = *s;
6790e9fcaa8aSmrg	      if (c == '"')
6791e9fcaa8aSmrg		length += backslashes + 1;
6792e9fcaa8aSmrg	      length++;
6793e9fcaa8aSmrg	      if (c == '\\')
6794e9fcaa8aSmrg		backslashes++;
6795e9fcaa8aSmrg	      else
6796e9fcaa8aSmrg		backslashes = 0;
6797e9fcaa8aSmrg	    }
6798e9fcaa8aSmrg	  if (quote_around)
6799e9fcaa8aSmrg	    length += backslashes + 1;
6800e9fcaa8aSmrg
6801e9fcaa8aSmrg	  quoted_string = XMALLOC (char, length + 1);
6802e9fcaa8aSmrg
6803e9fcaa8aSmrg	  p = quoted_string;
6804e9fcaa8aSmrg	  backslashes = 0;
6805e9fcaa8aSmrg	  if (quote_around)
6806e9fcaa8aSmrg	    *p++ = '"';
6807e9fcaa8aSmrg	  for (s = string; *s != '\0'; s++)
6808e9fcaa8aSmrg	    {
6809e9fcaa8aSmrg	      char c = *s;
6810e9fcaa8aSmrg	      if (c == '"')
6811e9fcaa8aSmrg		{
6812e9fcaa8aSmrg		  unsigned int j;
6813e9fcaa8aSmrg		  for (j = backslashes + 1; j > 0; j--)
6814e9fcaa8aSmrg		    *p++ = '\\';
6815e9fcaa8aSmrg		}
6816e9fcaa8aSmrg	      *p++ = c;
6817e9fcaa8aSmrg	      if (c == '\\')
6818e9fcaa8aSmrg		backslashes++;
6819e9fcaa8aSmrg	      else
6820e9fcaa8aSmrg		backslashes = 0;
6821e9fcaa8aSmrg	    }
6822e9fcaa8aSmrg	  if (quote_around)
6823e9fcaa8aSmrg	    {
6824e9fcaa8aSmrg	      unsigned int j;
6825e9fcaa8aSmrg	      for (j = backslashes; j > 0; j--)
6826e9fcaa8aSmrg		*p++ = '\\';
6827e9fcaa8aSmrg	      *p++ = '"';
6828e9fcaa8aSmrg	    }
6829e9fcaa8aSmrg	  *p = '\0';
6830e9fcaa8aSmrg
6831e9fcaa8aSmrg	  new_argv[i] = quoted_string;
6832e9fcaa8aSmrg	}
6833e9fcaa8aSmrg      else
6834e9fcaa8aSmrg	new_argv[i] = (char *) string;
6835e9fcaa8aSmrg    }
6836e9fcaa8aSmrg  new_argv[argc] = NULL;
6837e9fcaa8aSmrg
6838e9fcaa8aSmrg  return new_argv;
6839e9fcaa8aSmrg}
6840e9fcaa8aSmrgEOF
6841e9fcaa8aSmrg		;;
6842e9fcaa8aSmrg	    esac
6843e9fcaa8aSmrg
6844e9fcaa8aSmrg            cat <<"EOF"
6845e9fcaa8aSmrgvoid lt_dump_script (FILE* f)
6846e9fcaa8aSmrg{
6847e9fcaa8aSmrgEOF
6848e9fcaa8aSmrg	    func_emit_wrapper yes |
6849eb411b4bSmrg	      $SED -n -e '
6850eb411b4bSmrgs/^\(.\{79\}\)\(..*\)/\1\
6851eb411b4bSmrg\2/
6852eb411b4bSmrgh
6853eb411b4bSmrgs/\([\\"]\)/\\\1/g
6854eb411b4bSmrgs/$/\\n/
6855eb411b4bSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6856eb411b4bSmrgg
6857eb411b4bSmrgD'
6858e9fcaa8aSmrg            cat <<"EOF"
6859e9fcaa8aSmrg}
686088de56ccSmrgEOF
686188de56ccSmrg}
686288de56ccSmrg# end: func_emit_cwrapperexe_src
68631ab64890Smrg
6864e9fcaa8aSmrg# func_win32_import_lib_p ARG
6865e9fcaa8aSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6866e9fcaa8aSmrgfunc_win32_import_lib_p ()
6867e9fcaa8aSmrg{
6868862bcd1aSmrg    $debug_cmd
6869862bcd1aSmrg
6870e9fcaa8aSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6871e9fcaa8aSmrg    *import*) : ;;
6872e9fcaa8aSmrg    *) false ;;
6873e9fcaa8aSmrg    esac
6874e9fcaa8aSmrg}
6875e9fcaa8aSmrg
6876862bcd1aSmrg# func_suncc_cstd_abi
6877862bcd1aSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6878862bcd1aSmrg# Several compiler flags select an ABI that is incompatible with the
6879862bcd1aSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6880862bcd1aSmrgfunc_suncc_cstd_abi ()
6881862bcd1aSmrg{
6882862bcd1aSmrg    $debug_cmd
6883862bcd1aSmrg
6884862bcd1aSmrg    case " $compile_command " in
6885862bcd1aSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6886862bcd1aSmrg      suncc_use_cstd_abi=no
6887862bcd1aSmrg      ;;
6888862bcd1aSmrg    *)
6889862bcd1aSmrg      suncc_use_cstd_abi=yes
6890862bcd1aSmrg      ;;
6891862bcd1aSmrg    esac
6892862bcd1aSmrg}
6893862bcd1aSmrg
689488de56ccSmrg# func_mode_link arg...
689588de56ccSmrgfunc_mode_link ()
689688de56ccSmrg{
6897862bcd1aSmrg    $debug_cmd
6898862bcd1aSmrg
689988de56ccSmrg    case $host in
690007fb9b8fSmrg    *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
690188de56ccSmrg      # It is impossible to link a dll without this setting, and
690288de56ccSmrg      # we shouldn't force the makefile maintainer to figure out
6903862bcd1aSmrg      # what system we are compiling for in order to pass an extra
690488de56ccSmrg      # flag for every libtool invocation.
690588de56ccSmrg      # allow_undefined=no
69061ab64890Smrg
690788de56ccSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6908862bcd1aSmrg      # to make a dll that has undefined symbols, in which case not
690988de56ccSmrg      # even a static library is built.  For now, we need to specify
691088de56ccSmrg      # -no-undefined on the libtool link line when we can be certain
691188de56ccSmrg      # that all symbols are satisfied, otherwise we get a static library.
691288de56ccSmrg      allow_undefined=yes
691388de56ccSmrg      ;;
691488de56ccSmrg    *)
691588de56ccSmrg      allow_undefined=yes
691688de56ccSmrg      ;;
691788de56ccSmrg    esac
691888de56ccSmrg    libtool_args=$nonopt
691988de56ccSmrg    base_compile="$nonopt $@"
692088de56ccSmrg    compile_command=$nonopt
692188de56ccSmrg    finalize_command=$nonopt
69221ab64890Smrg
692388de56ccSmrg    compile_rpath=
692407fb9b8fSmrg    compile_rpath_tail=
692588de56ccSmrg    finalize_rpath=
692688de56ccSmrg    compile_shlibpath=
692788de56ccSmrg    finalize_shlibpath=
692888de56ccSmrg    convenience=
692988de56ccSmrg    old_convenience=
693088de56ccSmrg    deplibs=
693188de56ccSmrg    old_deplibs=
693288de56ccSmrg    compiler_flags=
693388de56ccSmrg    linker_flags=
693488de56ccSmrg    dllsearchpath=
693588de56ccSmrg    lib_search_path=`pwd`
693688de56ccSmrg    inst_prefix_dir=
693788de56ccSmrg    new_inherited_linker_flags=
69381ab64890Smrg
693988de56ccSmrg    avoid_version=no
6940e9fcaa8aSmrg    bindir=
694188de56ccSmrg    dlfiles=
694288de56ccSmrg    dlprefiles=
694388de56ccSmrg    dlself=no
694488de56ccSmrg    export_dynamic=no
694588de56ccSmrg    export_symbols=
694688de56ccSmrg    export_symbols_regex=
694788de56ccSmrg    generated=
694888de56ccSmrg    libobjs=
694988de56ccSmrg    ltlibs=
695088de56ccSmrg    module=no
695188de56ccSmrg    no_install=no
695288de56ccSmrg    objs=
6953862bcd1aSmrg    os2dllname=
695488de56ccSmrg    non_pic_objects=
695588de56ccSmrg    precious_files_regex=
695688de56ccSmrg    prefer_static_libs=no
6957862bcd1aSmrg    preload=false
695888de56ccSmrg    prev=
695988de56ccSmrg    prevarg=
696088de56ccSmrg    release=
696188de56ccSmrg    rpath=
696288de56ccSmrg    xrpath=
696388de56ccSmrg    perm_rpath=
696488de56ccSmrg    temp_rpath=
696507fb9b8fSmrg    temp_rpath_tail=
696688de56ccSmrg    thread_safe=no
696788de56ccSmrg    vinfo=
696888de56ccSmrg    vinfo_number=no
696988de56ccSmrg    weak_libs=
697007fb9b8fSmrg    rpath_arg=
6971862bcd1aSmrg    single_module=$wl-single_module
697288de56ccSmrg    func_infer_tag $base_compile
697388de56ccSmrg
697488de56ccSmrg    # We need to know -static, to get the right output filenames.
697588de56ccSmrg    for arg
697688de56ccSmrg    do
697788de56ccSmrg      case $arg in
697888de56ccSmrg      -shared)
6979862bcd1aSmrg	test yes != "$build_libtool_libs" \
6980862bcd1aSmrg	  && func_fatal_configuration "cannot build a shared library"
698188de56ccSmrg	build_old_libs=no
698288de56ccSmrg	break
698388de56ccSmrg	;;
698488de56ccSmrg      -all-static | -static | -static-libtool-libs)
698588de56ccSmrg	case $arg in
698688de56ccSmrg	-all-static)
6987862bcd1aSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
698888de56ccSmrg	    func_warning "complete static linking is impossible in this configuration"
698988de56ccSmrg	  fi
699088de56ccSmrg	  if test -n "$link_static_flag"; then
699188de56ccSmrg	    dlopen_self=$dlopen_self_static
699288de56ccSmrg	  fi
699388de56ccSmrg	  prefer_static_libs=yes
699488de56ccSmrg	  ;;
699588de56ccSmrg	-static)
699688de56ccSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
699788de56ccSmrg	    dlopen_self=$dlopen_self_static
699888de56ccSmrg	  fi
699988de56ccSmrg	  prefer_static_libs=built
700088de56ccSmrg	  ;;
700188de56ccSmrg	-static-libtool-libs)
700288de56ccSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
700388de56ccSmrg	    dlopen_self=$dlopen_self_static
7004b4ee4795Smrg	  fi
700588de56ccSmrg	  prefer_static_libs=yes
700688de56ccSmrg	  ;;
700788de56ccSmrg	esac
700888de56ccSmrg	build_libtool_libs=no
700988de56ccSmrg	build_old_libs=yes
701088de56ccSmrg	break
701188de56ccSmrg	;;
701288de56ccSmrg      esac
701388de56ccSmrg    done
70141ab64890Smrg
701588de56ccSmrg    # See if our shared archives depend on static archives.
701688de56ccSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
70171ab64890Smrg
701888de56ccSmrg    # Go through the arguments, transforming them on the way.
701988de56ccSmrg    while test "$#" -gt 0; do
7020862bcd1aSmrg      arg=$1
702188de56ccSmrg      shift
70227d2c738bSmrg      func_quote_arg pretty,unquoted "$arg"
70237d2c738bSmrg      qarg=$func_quote_arg_unquoted_result
70247d2c738bSmrg      func_append libtool_args " $func_quote_arg_result"
70251ab64890Smrg
702688de56ccSmrg      # If the previous option needs an argument, assign it.
702788de56ccSmrg      if test -n "$prev"; then
702888de56ccSmrg	case $prev in
702988de56ccSmrg	output)
703088de56ccSmrg	  func_append compile_command " @OUTPUT@"
703188de56ccSmrg	  func_append finalize_command " @OUTPUT@"
703288de56ccSmrg	  ;;
703388de56ccSmrg	esac
70341ab64890Smrg
703588de56ccSmrg	case $prev in
7036e9fcaa8aSmrg	bindir)
7037862bcd1aSmrg	  bindir=$arg
7038e9fcaa8aSmrg	  prev=
7039e9fcaa8aSmrg	  continue
7040e9fcaa8aSmrg	  ;;
704188de56ccSmrg	dlfiles|dlprefiles)
7042862bcd1aSmrg	  $preload || {
704388de56ccSmrg	    # Add the symbol object into the linking commands.
704488de56ccSmrg	    func_append compile_command " @SYMFILE@"
704588de56ccSmrg	    func_append finalize_command " @SYMFILE@"
7046862bcd1aSmrg	    preload=:
7047862bcd1aSmrg	  }
704888de56ccSmrg	  case $arg in
704988de56ccSmrg	  *.la | *.lo) ;;  # We handle these cases below.
705088de56ccSmrg	  force)
7051862bcd1aSmrg	    if test no = "$dlself"; then
705288de56ccSmrg	      dlself=needless
705388de56ccSmrg	      export_dynamic=yes
705488de56ccSmrg	    fi
705588de56ccSmrg	    prev=
705688de56ccSmrg	    continue
705788de56ccSmrg	    ;;
705888de56ccSmrg	  self)
7059862bcd1aSmrg	    if test dlprefiles = "$prev"; then
706088de56ccSmrg	      dlself=yes
7061862bcd1aSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
706288de56ccSmrg	      dlself=yes
7063b4ee4795Smrg	    else
706488de56ccSmrg	      dlself=needless
706588de56ccSmrg	      export_dynamic=yes
7066b4ee4795Smrg	    fi
706788de56ccSmrg	    prev=
706888de56ccSmrg	    continue
706988de56ccSmrg	    ;;
707088de56ccSmrg	  *)
7071862bcd1aSmrg	    if test dlfiles = "$prev"; then
7072e9fcaa8aSmrg	      func_append dlfiles " $arg"
7073b4ee4795Smrg	    else
7074e9fcaa8aSmrg	      func_append dlprefiles " $arg"
7075b4ee4795Smrg	    fi
707688de56ccSmrg	    prev=
707788de56ccSmrg	    continue
707888de56ccSmrg	    ;;
707988de56ccSmrg	  esac
708088de56ccSmrg	  ;;
708188de56ccSmrg	expsyms)
7082862bcd1aSmrg	  export_symbols=$arg
708388de56ccSmrg	  test -f "$arg" \
7084862bcd1aSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
708588de56ccSmrg	  prev=
708688de56ccSmrg	  continue
708788de56ccSmrg	  ;;
708888de56ccSmrg	expsyms_regex)
7089862bcd1aSmrg	  export_symbols_regex=$arg
709088de56ccSmrg	  prev=
709188de56ccSmrg	  continue
709288de56ccSmrg	  ;;
709388de56ccSmrg	framework)
7094b4ee4795Smrg	  case $host in
709588de56ccSmrg	    *-*-darwin*)
709688de56ccSmrg	      case "$deplibs " in
709788de56ccSmrg		*" $qarg.ltframework "*) ;;
7098e9fcaa8aSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
709988de56ccSmrg		   ;;
710088de56ccSmrg	      esac
710188de56ccSmrg	      ;;
7102b4ee4795Smrg	  esac
710388de56ccSmrg	  prev=
710488de56ccSmrg	  continue
7105b4ee4795Smrg	  ;;
710688de56ccSmrg	inst_prefix)
7107862bcd1aSmrg	  inst_prefix_dir=$arg
7108862bcd1aSmrg	  prev=
7109862bcd1aSmrg	  continue
7110862bcd1aSmrg	  ;;
7111862bcd1aSmrg	mllvm)
7112862bcd1aSmrg	  # Clang does not use LLVM to link, so we can simply discard any
7113862bcd1aSmrg	  # '-mllvm $arg' options when doing the link step.
711488de56ccSmrg	  prev=
711588de56ccSmrg	  continue
7116b4ee4795Smrg	  ;;
711788de56ccSmrg	objectlist)
711888de56ccSmrg	  if test -f "$arg"; then
711988de56ccSmrg	    save_arg=$arg
712088de56ccSmrg	    moreargs=
712188de56ccSmrg	    for fil in `cat "$save_arg"`
712288de56ccSmrg	    do
7123e9fcaa8aSmrg#	      func_append moreargs " $fil"
712488de56ccSmrg	      arg=$fil
712588de56ccSmrg	      # A libtool-controlled object.
71262e9c7c8cSmrg
712788de56ccSmrg	      # Check to see that this really is a libtool object.
712888de56ccSmrg	      if func_lalib_unsafe_p "$arg"; then
712988de56ccSmrg		pic_object=
713088de56ccSmrg		non_pic_object=
71312e9c7c8cSmrg
713288de56ccSmrg		# Read the .lo file
713388de56ccSmrg		func_source "$arg"
71342e9c7c8cSmrg
713588de56ccSmrg		if test -z "$pic_object" ||
713688de56ccSmrg		   test -z "$non_pic_object" ||
7137862bcd1aSmrg		   test none = "$pic_object" &&
7138862bcd1aSmrg		   test none = "$non_pic_object"; then
7139862bcd1aSmrg		  func_fatal_error "cannot find name of object for '$arg'"
714088de56ccSmrg		fi
71412e9c7c8cSmrg
714288de56ccSmrg		# Extract subdirectory from the argument.
714388de56ccSmrg		func_dirname "$arg" "/" ""
7144862bcd1aSmrg		xdir=$func_dirname_result
71452e9c7c8cSmrg
7146862bcd1aSmrg		if test none != "$pic_object"; then
714788de56ccSmrg		  # Prepend the subdirectory the object is found in.
7148862bcd1aSmrg		  pic_object=$xdir$pic_object
71492e9c7c8cSmrg
7150862bcd1aSmrg		  if test dlfiles = "$prev"; then
7151862bcd1aSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7152e9fcaa8aSmrg		      func_append dlfiles " $pic_object"
715388de56ccSmrg		      prev=
715488de56ccSmrg		      continue
715588de56ccSmrg		    else
715688de56ccSmrg		      # If libtool objects are unsupported, then we need to preload.
715788de56ccSmrg		      prev=dlprefiles
715888de56ccSmrg		    fi
715988de56ccSmrg		  fi
71602e9c7c8cSmrg
716188de56ccSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7162862bcd1aSmrg		  if test dlprefiles = "$prev"; then
716388de56ccSmrg		    # Preload the old-style object.
7164e9fcaa8aSmrg		    func_append dlprefiles " $pic_object"
716588de56ccSmrg		    prev=
716688de56ccSmrg		  fi
71672e9c7c8cSmrg
716888de56ccSmrg		  # A PIC object.
716988de56ccSmrg		  func_append libobjs " $pic_object"
7170862bcd1aSmrg		  arg=$pic_object
717188de56ccSmrg		fi
71722e9c7c8cSmrg
717388de56ccSmrg		# Non-PIC object.
7174862bcd1aSmrg		if test none != "$non_pic_object"; then
717588de56ccSmrg		  # Prepend the subdirectory the object is found in.
7176862bcd1aSmrg		  non_pic_object=$xdir$non_pic_object
71772e9c7c8cSmrg
717888de56ccSmrg		  # A standard non-PIC object
717988de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
7180862bcd1aSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7181862bcd1aSmrg		    arg=$non_pic_object
718288de56ccSmrg		  fi
718388de56ccSmrg		else
718488de56ccSmrg		  # If the PIC object exists, use it instead.
718588de56ccSmrg		  # $xdir was prepended to $pic_object above.
7186862bcd1aSmrg		  non_pic_object=$pic_object
718788de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
718888de56ccSmrg		fi
718988de56ccSmrg	      else
719088de56ccSmrg		# Only an error if not doing a dry-run.
719188de56ccSmrg		if $opt_dry_run; then
719288de56ccSmrg		  # Extract subdirectory from the argument.
719388de56ccSmrg		  func_dirname "$arg" "/" ""
7194862bcd1aSmrg		  xdir=$func_dirname_result
719588de56ccSmrg
719688de56ccSmrg		  func_lo2o "$arg"
719788de56ccSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
719888de56ccSmrg		  non_pic_object=$xdir$func_lo2o_result
719988de56ccSmrg		  func_append libobjs " $pic_object"
720088de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
720188de56ccSmrg	        else
7202862bcd1aSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
720388de56ccSmrg		fi
720488de56ccSmrg	      fi
720588de56ccSmrg	    done
7206b4ee4795Smrg	  else
7207862bcd1aSmrg	    func_fatal_error "link input file '$arg' does not exist"
7208b4ee4795Smrg	  fi
720988de56ccSmrg	  arg=$save_arg
721088de56ccSmrg	  prev=
721188de56ccSmrg	  continue
721288de56ccSmrg	  ;;
7213862bcd1aSmrg	os2dllname)
7214862bcd1aSmrg	  os2dllname=$arg
7215862bcd1aSmrg	  prev=
7216862bcd1aSmrg	  continue
7217862bcd1aSmrg	  ;;
721888de56ccSmrg	precious_regex)
7219862bcd1aSmrg	  precious_files_regex=$arg
722088de56ccSmrg	  prev=
722188de56ccSmrg	  continue
722288de56ccSmrg	  ;;
722388de56ccSmrg	release)
7224862bcd1aSmrg	  release=-$arg
722588de56ccSmrg	  prev=
722688de56ccSmrg	  continue
722788de56ccSmrg	  ;;
722888de56ccSmrg	rpath | xrpath)
722988de56ccSmrg	  # We need an absolute path.
723088de56ccSmrg	  case $arg in
723188de56ccSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
723288de56ccSmrg	  *)
723307fb9b8fSmrg	    func_fatal_error "argument to -rpath is not absolute: $arg"
723488de56ccSmrg	    ;;
723588de56ccSmrg	  esac
7236862bcd1aSmrg	  if test rpath = "$prev"; then
723788de56ccSmrg	    case "$rpath " in
723888de56ccSmrg	    *" $arg "*) ;;
7239e9fcaa8aSmrg	    *) func_append rpath " $arg" ;;
724088de56ccSmrg	    esac
7241b4ee4795Smrg	  else
724288de56ccSmrg	    case "$xrpath " in
724388de56ccSmrg	    *" $arg "*) ;;
7244e9fcaa8aSmrg	    *) func_append xrpath " $arg" ;;
724588de56ccSmrg	    esac
7246b4ee4795Smrg	  fi
724788de56ccSmrg	  prev=
724888de56ccSmrg	  continue
724988de56ccSmrg	  ;;
725088de56ccSmrg	shrext)
7251862bcd1aSmrg	  shrext_cmds=$arg
725288de56ccSmrg	  prev=
725388de56ccSmrg	  continue
725488de56ccSmrg	  ;;
725588de56ccSmrg	weak)
7256e9fcaa8aSmrg	  func_append weak_libs " $arg"
725788de56ccSmrg	  prev=
725888de56ccSmrg	  continue
725988de56ccSmrg	  ;;
72607d2c738bSmrg	xassembler)
72617d2c738bSmrg	  func_append compiler_flags " -Xassembler $qarg"
72627d2c738bSmrg	  prev=
72637d2c738bSmrg	  func_append compile_command " -Xassembler $qarg"
72647d2c738bSmrg	  func_append finalize_command " -Xassembler $qarg"
72657d2c738bSmrg	  continue
72667d2c738bSmrg	  ;;
726788de56ccSmrg	xcclinker)
7268e9fcaa8aSmrg	  func_append linker_flags " $qarg"
7269e9fcaa8aSmrg	  func_append compiler_flags " $qarg"
727088de56ccSmrg	  prev=
727188de56ccSmrg	  func_append compile_command " $qarg"
727288de56ccSmrg	  func_append finalize_command " $qarg"
727388de56ccSmrg	  continue
727488de56ccSmrg	  ;;
727588de56ccSmrg	xcompiler)
7276e9fcaa8aSmrg	  func_append compiler_flags " $qarg"
727788de56ccSmrg	  prev=
727888de56ccSmrg	  func_append compile_command " $qarg"
727988de56ccSmrg	  func_append finalize_command " $qarg"
728088de56ccSmrg	  continue
728188de56ccSmrg	  ;;
728288de56ccSmrg	xlinker)
7283e9fcaa8aSmrg	  func_append linker_flags " $qarg"
7284e9fcaa8aSmrg	  func_append compiler_flags " $wl$qarg"
728588de56ccSmrg	  prev=
728688de56ccSmrg	  func_append compile_command " $wl$qarg"
728788de56ccSmrg	  func_append finalize_command " $wl$qarg"
728888de56ccSmrg	  continue
728988de56ccSmrg	  ;;
729088de56ccSmrg	*)
729188de56ccSmrg	  eval "$prev=\"\$arg\""
729288de56ccSmrg	  prev=
729388de56ccSmrg	  continue
729488de56ccSmrg	  ;;
72952e9c7c8cSmrg	esac
729688de56ccSmrg      fi # test -n "$prev"
72972e9c7c8cSmrg
7298862bcd1aSmrg      prevarg=$arg
72992e9c7c8cSmrg
730088de56ccSmrg      case $arg in
730188de56ccSmrg      -all-static)
730288de56ccSmrg	if test -n "$link_static_flag"; then
730388de56ccSmrg	  # See comment for -static flag below, for more details.
730488de56ccSmrg	  func_append compile_command " $link_static_flag"
730588de56ccSmrg	  func_append finalize_command " $link_static_flag"
730688de56ccSmrg	fi
730788de56ccSmrg	continue
730888de56ccSmrg	;;
73092e9c7c8cSmrg
731088de56ccSmrg      -allow-undefined)
731188de56ccSmrg	# FIXME: remove this flag sometime in the future.
7312862bcd1aSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
731388de56ccSmrg	;;
73142e9c7c8cSmrg
731588de56ccSmrg      -avoid-version)
731688de56ccSmrg	avoid_version=yes
731788de56ccSmrg	continue
731888de56ccSmrg	;;
73192e9c7c8cSmrg
7320e9fcaa8aSmrg      -bindir)
7321e9fcaa8aSmrg	prev=bindir
7322e9fcaa8aSmrg	continue
7323e9fcaa8aSmrg	;;
7324e9fcaa8aSmrg
732588de56ccSmrg      -dlopen)
732688de56ccSmrg	prev=dlfiles
732788de56ccSmrg	continue
732888de56ccSmrg	;;
73292e9c7c8cSmrg
733088de56ccSmrg      -dlpreopen)
733188de56ccSmrg	prev=dlprefiles
733288de56ccSmrg	continue
733388de56ccSmrg	;;
73342e9c7c8cSmrg
733588de56ccSmrg      -export-dynamic)
733688de56ccSmrg	export_dynamic=yes
733788de56ccSmrg	continue
733888de56ccSmrg	;;
73392e9c7c8cSmrg
734088de56ccSmrg      -export-symbols | -export-symbols-regex)
734188de56ccSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
734288de56ccSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
734388de56ccSmrg	fi
7344862bcd1aSmrg	if test X-export-symbols = "X$arg"; then
734588de56ccSmrg	  prev=expsyms
734688de56ccSmrg	else
734788de56ccSmrg	  prev=expsyms_regex
734888de56ccSmrg	fi
734988de56ccSmrg	continue
735088de56ccSmrg	;;
73512e9c7c8cSmrg
735288de56ccSmrg      -framework)
735388de56ccSmrg	prev=framework
735488de56ccSmrg	continue
735588de56ccSmrg	;;
73562e9c7c8cSmrg
735788de56ccSmrg      -inst-prefix-dir)
735888de56ccSmrg	prev=inst_prefix
735988de56ccSmrg	continue
736088de56ccSmrg	;;
73612e9c7c8cSmrg
736288de56ccSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
736388de56ccSmrg      # so, if we see these flags be careful not to treat them like -L
736488de56ccSmrg      -L[A-Z][A-Z]*:*)
736588de56ccSmrg	case $with_gcc/$host in
736688de56ccSmrg	no/*-*-irix* | /*-*-irix*)
736788de56ccSmrg	  func_append compile_command " $arg"
736888de56ccSmrg	  func_append finalize_command " $arg"
736988de56ccSmrg	  ;;
737088de56ccSmrg	esac
737188de56ccSmrg	continue
737288de56ccSmrg	;;
73732e9c7c8cSmrg
737488de56ccSmrg      -L*)
7375e9fcaa8aSmrg	func_stripname "-L" '' "$arg"
7376e9fcaa8aSmrg	if test -z "$func_stripname_result"; then
737788de56ccSmrg	  if test "$#" -gt 0; then
7378862bcd1aSmrg	    func_fatal_error "require no space between '-L' and '$1'"
737988de56ccSmrg	  else
7380862bcd1aSmrg	    func_fatal_error "need path for '-L' option"
738188de56ccSmrg	  fi
738288de56ccSmrg	fi
7383e9fcaa8aSmrg	func_resolve_sysroot "$func_stripname_result"
7384e9fcaa8aSmrg	dir=$func_resolve_sysroot_result
738588de56ccSmrg	# We need an absolute path.
738688de56ccSmrg	case $dir in
738788de56ccSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
738888de56ccSmrg	*)
738988de56ccSmrg	  absdir=`cd "$dir" && pwd`
739088de56ccSmrg	  test -z "$absdir" && \
7391862bcd1aSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7392862bcd1aSmrg	  dir=$absdir
739388de56ccSmrg	  ;;
739488de56ccSmrg	esac
739588de56ccSmrg	case "$deplibs " in
7396e9fcaa8aSmrg	*" -L$dir "* | *" $arg "*)
7397e9fcaa8aSmrg	  # Will only happen for absolute or sysroot arguments
7398e9fcaa8aSmrg	  ;;
739988de56ccSmrg	*)
7400e9fcaa8aSmrg	  # Preserve sysroot, but never include relative directories
7401e9fcaa8aSmrg	  case $dir in
7402e9fcaa8aSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7403e9fcaa8aSmrg	    *) func_append deplibs " -L$dir" ;;
7404e9fcaa8aSmrg	  esac
7405e9fcaa8aSmrg	  func_append lib_search_path " $dir"
740688de56ccSmrg	  ;;
740788de56ccSmrg	esac
740888de56ccSmrg	case $host in
740907fb9b8fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
7410e9fcaa8aSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
741188de56ccSmrg	  case :$dllsearchpath: in
741288de56ccSmrg	  *":$dir:"*) ;;
741388de56ccSmrg	  ::) dllsearchpath=$dir;;
7414e9fcaa8aSmrg	  *) func_append dllsearchpath ":$dir";;
741588de56ccSmrg	  esac
741688de56ccSmrg	  case :$dllsearchpath: in
741788de56ccSmrg	  *":$testbindir:"*) ;;
741888de56ccSmrg	  ::) dllsearchpath=$testbindir;;
7419e9fcaa8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
742088de56ccSmrg	  esac
742188de56ccSmrg	  ;;
742288de56ccSmrg	esac
742388de56ccSmrg	continue
742488de56ccSmrg	;;
74252e9c7c8cSmrg
742688de56ccSmrg      -l*)
7427862bcd1aSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
742888de56ccSmrg	  case $host in
742907fb9b8fSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
743088de56ccSmrg	    # These systems don't actually have a C or math library (as such)
743188de56ccSmrg	    continue
743288de56ccSmrg	    ;;
743388de56ccSmrg	  *-*-os2*)
743488de56ccSmrg	    # These systems don't actually have a C library (as such)
7435862bcd1aSmrg	    test X-lc = "X$arg" && continue
743688de56ccSmrg	    ;;
743707fb9b8fSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
743888de56ccSmrg	    # Do not include libc due to us having libc/libc_r.
7439862bcd1aSmrg	    test X-lc = "X$arg" && continue
744088de56ccSmrg	    ;;
744188de56ccSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
744288de56ccSmrg	    # Rhapsody C and math libraries are in the System framework
7443e9fcaa8aSmrg	    func_append deplibs " System.ltframework"
744488de56ccSmrg	    continue
744588de56ccSmrg	    ;;
744688de56ccSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
744788de56ccSmrg	    # Causes problems with __ctype
7448862bcd1aSmrg	    test X-lc = "X$arg" && continue
744988de56ccSmrg	    ;;
745088de56ccSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
745188de56ccSmrg	    # Compiler inserts libc in the correct place for threads to work
7452862bcd1aSmrg	    test X-lc = "X$arg" && continue
745388de56ccSmrg	    ;;
745488de56ccSmrg	  esac
7455862bcd1aSmrg	elif test X-lc_r = "X$arg"; then
745688de56ccSmrg	 case $host in
745707fb9b8fSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
745888de56ccSmrg	   # Do not include libc_r directly, use -pthread flag.
745988de56ccSmrg	   continue
746088de56ccSmrg	   ;;
746188de56ccSmrg	 esac
746288de56ccSmrg	fi
7463e9fcaa8aSmrg	func_append deplibs " $arg"
746488de56ccSmrg	continue
746588de56ccSmrg	;;
74662e9c7c8cSmrg
7467862bcd1aSmrg      -mllvm)
7468862bcd1aSmrg	prev=mllvm
7469862bcd1aSmrg	continue
7470862bcd1aSmrg	;;
7471862bcd1aSmrg
747288de56ccSmrg      -module)
747388de56ccSmrg	module=yes
747488de56ccSmrg	continue
747588de56ccSmrg	;;
74762e9c7c8cSmrg
747788de56ccSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
747888de56ccSmrg      # classes, name mangling, and exception handling.
747988de56ccSmrg      # Darwin uses the -arch flag to determine output architecture.
748007fb9b8fSmrg      # -q <option> for IBM XL C/C++ compiler.
748107fb9b8fSmrg      -model|-arch|-isysroot|--sysroot|-q)
7482e9fcaa8aSmrg	func_append compiler_flags " $arg"
748388de56ccSmrg	func_append compile_command " $arg"
748488de56ccSmrg	func_append finalize_command " $arg"
748588de56ccSmrg	prev=xcompiler
748688de56ccSmrg	continue
748788de56ccSmrg	;;
74887d2c738bSmrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
74897d2c738bSmrg     -pthread)
74907d2c738bSmrg	case $host in
74917d2c738bSmrg	  *solaris2*) ;;
74927d2c738bSmrg	  *)
74937d2c738bSmrg	    case "$new_inherited_linker_flags " in
74947d2c738bSmrg	        *" $arg "*) ;;
74957d2c738bSmrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
74967d2c738bSmrg	    esac
74977d2c738bSmrg	  ;;
74987d2c738bSmrg	esac
74997d2c738bSmrg	continue
75007d2c738bSmrg	;;
75017d2c738bSmrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
750207fb9b8fSmrg      |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7503e9fcaa8aSmrg	func_append compiler_flags " $arg"
750488de56ccSmrg	func_append compile_command " $arg"
750588de56ccSmrg	func_append finalize_command " $arg"
750688de56ccSmrg	case "$new_inherited_linker_flags " in
750788de56ccSmrg	    *" $arg "*) ;;
7508e9fcaa8aSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
750988de56ccSmrg	esac
751088de56ccSmrg	continue
751188de56ccSmrg	;;
75122e9c7c8cSmrg
751388de56ccSmrg      -multi_module)
7514862bcd1aSmrg	single_module=$wl-multi_module
751588de56ccSmrg	continue
751688de56ccSmrg	;;
75172e9c7c8cSmrg
751888de56ccSmrg      -no-fast-install)
751988de56ccSmrg	fast_install=no
752088de56ccSmrg	continue
752188de56ccSmrg	;;
75222e9c7c8cSmrg
752388de56ccSmrg      -no-install)
752488de56ccSmrg	case $host in
752507fb9b8fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
752688de56ccSmrg	  # The PATH hackery in wrapper scripts is required on Windows
752788de56ccSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7528862bcd1aSmrg	  func_warning "'-no-install' is ignored for $host"
7529862bcd1aSmrg	  func_warning "assuming '-no-fast-install' instead"
753088de56ccSmrg	  fast_install=no
753188de56ccSmrg	  ;;
753288de56ccSmrg	*) no_install=yes ;;
753388de56ccSmrg	esac
753488de56ccSmrg	continue
753588de56ccSmrg	;;
75362e9c7c8cSmrg
753788de56ccSmrg      -no-undefined)
753888de56ccSmrg	allow_undefined=no
753988de56ccSmrg	continue
754088de56ccSmrg	;;
75412e9c7c8cSmrg
754288de56ccSmrg      -objectlist)
754388de56ccSmrg	prev=objectlist
754488de56ccSmrg	continue
754588de56ccSmrg	;;
75462e9c7c8cSmrg
7547862bcd1aSmrg      -os2dllname)
7548862bcd1aSmrg	prev=os2dllname
7549862bcd1aSmrg	continue
7550862bcd1aSmrg	;;
7551862bcd1aSmrg
755288de56ccSmrg      -o) prev=output ;;
75532e9c7c8cSmrg
755488de56ccSmrg      -precious-files-regex)
755588de56ccSmrg	prev=precious_regex
755688de56ccSmrg	continue
755788de56ccSmrg	;;
75582e9c7c8cSmrg
755988de56ccSmrg      -release)
756088de56ccSmrg	prev=release
756188de56ccSmrg	continue
756288de56ccSmrg	;;
75632e9c7c8cSmrg
756488de56ccSmrg      -rpath)
756588de56ccSmrg	prev=rpath
756688de56ccSmrg	continue
756788de56ccSmrg	;;
75682e9c7c8cSmrg
756988de56ccSmrg      -R)
757088de56ccSmrg	prev=xrpath
757188de56ccSmrg	continue
757288de56ccSmrg	;;
75732e9c7c8cSmrg
757488de56ccSmrg      -R*)
757588de56ccSmrg	func_stripname '-R' '' "$arg"
757688de56ccSmrg	dir=$func_stripname_result
757788de56ccSmrg	# We need an absolute path.
757888de56ccSmrg	case $dir in
757988de56ccSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7580e9fcaa8aSmrg	=*)
7581e9fcaa8aSmrg	  func_stripname '=' '' "$dir"
7582e9fcaa8aSmrg	  dir=$lt_sysroot$func_stripname_result
7583e9fcaa8aSmrg	  ;;
758488de56ccSmrg	*)
758507fb9b8fSmrg	  func_fatal_error "argument ($arg) to '-R' is not an absolute path: $dir"
758688de56ccSmrg	  ;;
758788de56ccSmrg	esac
758888de56ccSmrg	case "$xrpath " in
758988de56ccSmrg	*" $dir "*) ;;
7590e9fcaa8aSmrg	*) func_append xrpath " $dir" ;;
759188de56ccSmrg	esac
759288de56ccSmrg	continue
759388de56ccSmrg	;;
75942e9c7c8cSmrg
759588de56ccSmrg      -shared)
759688de56ccSmrg	# The effects of -shared are defined in a previous loop.
759788de56ccSmrg	continue
759888de56ccSmrg	;;
75992e9c7c8cSmrg
760088de56ccSmrg      -shrext)
760188de56ccSmrg	prev=shrext
760288de56ccSmrg	continue
760388de56ccSmrg	;;
76042e9c7c8cSmrg
760588de56ccSmrg      -static | -static-libtool-libs)
760688de56ccSmrg	# The effects of -static are defined in a previous loop.
760788de56ccSmrg	# We used to do the same as -all-static on platforms that
760888de56ccSmrg	# didn't have a PIC flag, but the assumption that the effects
760988de56ccSmrg	# would be equivalent was wrong.  It would break on at least
761088de56ccSmrg	# Digital Unix and AIX.
761188de56ccSmrg	continue
761288de56ccSmrg	;;
76132e9c7c8cSmrg
761488de56ccSmrg      -thread-safe)
761588de56ccSmrg	thread_safe=yes
761688de56ccSmrg	continue
761788de56ccSmrg	;;
76182e9c7c8cSmrg
761988de56ccSmrg      -version-info)
762088de56ccSmrg	prev=vinfo
762188de56ccSmrg	continue
762288de56ccSmrg	;;
76232e9c7c8cSmrg
762488de56ccSmrg      -version-number)
762588de56ccSmrg	prev=vinfo
762688de56ccSmrg	vinfo_number=yes
762788de56ccSmrg	continue
762888de56ccSmrg	;;
76292e9c7c8cSmrg
763088de56ccSmrg      -weak)
763188de56ccSmrg        prev=weak
763288de56ccSmrg	continue
763388de56ccSmrg	;;
76341ab64890Smrg
763588de56ccSmrg      -Wc,*)
763688de56ccSmrg	func_stripname '-Wc,' '' "$arg"
763788de56ccSmrg	args=$func_stripname_result
763888de56ccSmrg	arg=
7639862bcd1aSmrg	save_ifs=$IFS; IFS=,
764088de56ccSmrg	for flag in $args; do
7641862bcd1aSmrg	  IFS=$save_ifs
76427d2c738bSmrg          func_quote_arg pretty "$flag"
76437d2c738bSmrg	  func_append arg " $func_quote_arg_result"
76447d2c738bSmrg	  func_append compiler_flags " $func_quote_arg_result"
764588de56ccSmrg	done
7646862bcd1aSmrg	IFS=$save_ifs
764788de56ccSmrg	func_stripname ' ' '' "$arg"
764888de56ccSmrg	arg=$func_stripname_result
764988de56ccSmrg	;;
7650b4ee4795Smrg
765188de56ccSmrg      -Wl,*)
765288de56ccSmrg	func_stripname '-Wl,' '' "$arg"
765388de56ccSmrg	args=$func_stripname_result
765488de56ccSmrg	arg=
7655862bcd1aSmrg	save_ifs=$IFS; IFS=,
765688de56ccSmrg	for flag in $args; do
7657862bcd1aSmrg	  IFS=$save_ifs
76587d2c738bSmrg          func_quote_arg pretty "$flag"
76597d2c738bSmrg	  func_append arg " $wl$func_quote_arg_result"
76607d2c738bSmrg	  func_append compiler_flags " $wl$func_quote_arg_result"
76617d2c738bSmrg	  func_append linker_flags " $func_quote_arg_result"
766288de56ccSmrg	done
7663862bcd1aSmrg	IFS=$save_ifs
766488de56ccSmrg	func_stripname ' ' '' "$arg"
766588de56ccSmrg	arg=$func_stripname_result
766688de56ccSmrg	;;
7667b4ee4795Smrg
76687d2c738bSmrg      -Xassembler)
76697d2c738bSmrg        prev=xassembler
76707d2c738bSmrg        continue
76717d2c738bSmrg        ;;
76727d2c738bSmrg
767388de56ccSmrg      -Xcompiler)
767488de56ccSmrg	prev=xcompiler
767588de56ccSmrg	continue
767688de56ccSmrg	;;
7677b4ee4795Smrg
767888de56ccSmrg      -Xlinker)
767988de56ccSmrg	prev=xlinker
768088de56ccSmrg	continue
768188de56ccSmrg	;;
7682b4ee4795Smrg
768388de56ccSmrg      -XCClinker)
768488de56ccSmrg	prev=xcclinker
768588de56ccSmrg	continue
768688de56ccSmrg	;;
7687b4ee4795Smrg
768888de56ccSmrg      # -msg_* for osf cc
768988de56ccSmrg      -msg_*)
76907d2c738bSmrg	func_quote_arg pretty "$arg"
76917d2c738bSmrg	arg=$func_quote_arg_result
769288de56ccSmrg	;;
7693b4ee4795Smrg
7694e9fcaa8aSmrg      # Flags to be passed through unchanged, with rationale:
7695e9fcaa8aSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7696e9fcaa8aSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7697e9fcaa8aSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7698e9fcaa8aSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7699e9fcaa8aSmrg      # -q*                  compiler args for the IBM compiler
7700e9fcaa8aSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7701e9fcaa8aSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7702e9fcaa8aSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7703862bcd1aSmrg      # -fstack-protector*   stack protector flags for GCC
7704e9fcaa8aSmrg      # @file                GCC response files
7705e9fcaa8aSmrg      # -tp=*                Portland pgcc target processor selection
7706e9fcaa8aSmrg      # --sysroot=*          for sysroot support
7707862bcd1aSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
77087d2c738bSmrg      # -specs=*             GCC specs files
7709862bcd1aSmrg      # -stdlib=*            select c++ std lib with clang
771007fb9b8fSmrg      # -fdiagnostics-color* simply affects output
771107fb9b8fSmrg      # -frecord-gcc-switches used to verify flags were respected
77127d2c738bSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
771307fb9b8fSmrg      # -fno-sanitize*       Clang/GCC memory and address sanitizer
771407fb9b8fSmrg      # -shared-libsan       Link with shared sanitizer runtimes (Clang)
771507fb9b8fSmrg      # -static-libsan       Link with static sanitizer runtimes (Clang)
771607fb9b8fSmrg      # -no-canonical-prefixes Do not expand any symbolic links
77177d2c738bSmrg      # -fuse-ld=*           Linker select flags for GCC
771807fb9b8fSmrg      # -static-*            direct GCC to link specific libraries statically
771907fb9b8fSmrg      # -fcilkplus           Cilk Plus language extension features for C/C++
772007fb9b8fSmrg      # -rtlib=*             select c runtime lib with clang
772107fb9b8fSmrg      # --unwindlib=*        select unwinder library with clang
772207fb9b8fSmrg      # -f{file|debug|macro|profile}-prefix-map=* needed for lto linking
77237d2c738bSmrg      # -Wa,*                Pass flags directly to the assembler
772407fb9b8fSmrg      # -Werror, -Werror=*   Report (specified) warnings as errors
772588de56ccSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7726e9fcaa8aSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
772707fb9b8fSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
772807fb9b8fSmrg      -stdlib=*|-rtlib=*|--unwindlib=*| \
772907fb9b8fSmrg      -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
773007fb9b8fSmrg      -ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \
773107fb9b8fSmrg      -fdiagnostics-color*|-frecord-gcc-switches| \
773207fb9b8fSmrg      -fuse-ld=*|-static-*|-fcilkplus|-Wa,*|-Werror|-Werror=*)
77337d2c738bSmrg        func_quote_arg pretty "$arg"
77347d2c738bSmrg	arg=$func_quote_arg_result
773588de56ccSmrg        func_append compile_command " $arg"
773688de56ccSmrg        func_append finalize_command " $arg"
7737e9fcaa8aSmrg        func_append compiler_flags " $arg"
773888de56ccSmrg        continue
773988de56ccSmrg        ;;
7740b4ee4795Smrg
7741862bcd1aSmrg      -Z*)
7742862bcd1aSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7743862bcd1aSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7744862bcd1aSmrg	  compiler_flags="$compiler_flags $arg"
7745862bcd1aSmrg	  func_append compile_command " $arg"
7746862bcd1aSmrg	  func_append finalize_command " $arg"
7747862bcd1aSmrg	  case $arg in
7748862bcd1aSmrg	  -Zlinker | -Zstack)
7749862bcd1aSmrg	    prev=xcompiler
7750862bcd1aSmrg	    ;;
7751862bcd1aSmrg	  esac
7752862bcd1aSmrg	  continue
7753862bcd1aSmrg        else
7754862bcd1aSmrg	  # Otherwise treat like 'Some other compiler flag' below
77557d2c738bSmrg	  func_quote_arg pretty "$arg"
77567d2c738bSmrg	  arg=$func_quote_arg_result
7757862bcd1aSmrg        fi
7758862bcd1aSmrg	;;
7759862bcd1aSmrg
776088de56ccSmrg      # Some other compiler flag.
776188de56ccSmrg      -* | +*)
77627d2c738bSmrg        func_quote_arg pretty "$arg"
77637d2c738bSmrg	arg=$func_quote_arg_result
776488de56ccSmrg	;;
7765b4ee4795Smrg
776688de56ccSmrg      *.$objext)
776788de56ccSmrg	# A standard object.
7768e9fcaa8aSmrg	func_append objs " $arg"
776988de56ccSmrg	;;
7770b4ee4795Smrg
777188de56ccSmrg      *.lo)
777288de56ccSmrg	# A libtool-controlled object.
7773b4ee4795Smrg
777488de56ccSmrg	# Check to see that this really is a libtool object.
777588de56ccSmrg	if func_lalib_unsafe_p "$arg"; then
777688de56ccSmrg	  pic_object=
777788de56ccSmrg	  non_pic_object=
7778b4ee4795Smrg
777988de56ccSmrg	  # Read the .lo file
778088de56ccSmrg	  func_source "$arg"
7781b4ee4795Smrg
778288de56ccSmrg	  if test -z "$pic_object" ||
778388de56ccSmrg	     test -z "$non_pic_object" ||
7784862bcd1aSmrg	     test none = "$pic_object" &&
7785862bcd1aSmrg	     test none = "$non_pic_object"; then
7786862bcd1aSmrg	    func_fatal_error "cannot find name of object for '$arg'"
778788de56ccSmrg	  fi
7788b4ee4795Smrg
778988de56ccSmrg	  # Extract subdirectory from the argument.
779088de56ccSmrg	  func_dirname "$arg" "/" ""
7791862bcd1aSmrg	  xdir=$func_dirname_result
7792b4ee4795Smrg
7793862bcd1aSmrg	  test none = "$pic_object" || {
779488de56ccSmrg	    # Prepend the subdirectory the object is found in.
7795862bcd1aSmrg	    pic_object=$xdir$pic_object
7796b4ee4795Smrg
7797862bcd1aSmrg	    if test dlfiles = "$prev"; then
7798862bcd1aSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7799e9fcaa8aSmrg		func_append dlfiles " $pic_object"
780088de56ccSmrg		prev=
780188de56ccSmrg		continue
780288de56ccSmrg	      else
780388de56ccSmrg		# If libtool objects are unsupported, then we need to preload.
780488de56ccSmrg		prev=dlprefiles
780588de56ccSmrg	      fi
780688de56ccSmrg	    fi
7807b4ee4795Smrg
780888de56ccSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7809862bcd1aSmrg	    if test dlprefiles = "$prev"; then
781088de56ccSmrg	      # Preload the old-style object.
7811e9fcaa8aSmrg	      func_append dlprefiles " $pic_object"
781288de56ccSmrg	      prev=
781388de56ccSmrg	    fi
78141ab64890Smrg
781588de56ccSmrg	    # A PIC object.
781688de56ccSmrg	    func_append libobjs " $pic_object"
7817862bcd1aSmrg	    arg=$pic_object
7818862bcd1aSmrg	  }
78191ab64890Smrg
782088de56ccSmrg	  # Non-PIC object.
7821862bcd1aSmrg	  if test none != "$non_pic_object"; then
782288de56ccSmrg	    # Prepend the subdirectory the object is found in.
7823862bcd1aSmrg	    non_pic_object=$xdir$non_pic_object
78241ab64890Smrg
782588de56ccSmrg	    # A standard non-PIC object
782688de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
7827862bcd1aSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7828862bcd1aSmrg	      arg=$non_pic_object
782988de56ccSmrg	    fi
783088de56ccSmrg	  else
783188de56ccSmrg	    # If the PIC object exists, use it instead.
783288de56ccSmrg	    # $xdir was prepended to $pic_object above.
7833862bcd1aSmrg	    non_pic_object=$pic_object
783488de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
783588de56ccSmrg	  fi
783688de56ccSmrg	else
783788de56ccSmrg	  # Only an error if not doing a dry-run.
783888de56ccSmrg	  if $opt_dry_run; then
783988de56ccSmrg	    # Extract subdirectory from the argument.
784088de56ccSmrg	    func_dirname "$arg" "/" ""
7841862bcd1aSmrg	    xdir=$func_dirname_result
784288de56ccSmrg
784388de56ccSmrg	    func_lo2o "$arg"
784488de56ccSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
784588de56ccSmrg	    non_pic_object=$xdir$func_lo2o_result
784688de56ccSmrg	    func_append libobjs " $pic_object"
784788de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
784888de56ccSmrg	  else
7849862bcd1aSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
785088de56ccSmrg	  fi
785188de56ccSmrg	fi
785288de56ccSmrg	;;
78531ab64890Smrg
785488de56ccSmrg      *.$libext)
785588de56ccSmrg	# An archive.
7856e9fcaa8aSmrg	func_append deplibs " $arg"
7857e9fcaa8aSmrg	func_append old_deplibs " $arg"
785888de56ccSmrg	continue
785988de56ccSmrg	;;
786088de56ccSmrg
786188de56ccSmrg      *.la)
786288de56ccSmrg	# A libtool-controlled library.
786388de56ccSmrg
7864e9fcaa8aSmrg	func_resolve_sysroot "$arg"
7865862bcd1aSmrg	if test dlfiles = "$prev"; then
786688de56ccSmrg	  # This library was specified with -dlopen.
7867e9fcaa8aSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
786888de56ccSmrg	  prev=
7869862bcd1aSmrg	elif test dlprefiles = "$prev"; then
787088de56ccSmrg	  # The library was specified with -dlpreopen.
7871e9fcaa8aSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
787288de56ccSmrg	  prev=
787388de56ccSmrg	else
7874e9fcaa8aSmrg	  func_append deplibs " $func_resolve_sysroot_result"
787588de56ccSmrg	fi
787688de56ccSmrg	continue
787788de56ccSmrg	;;
787888de56ccSmrg
787988de56ccSmrg      # Some other compiler argument.
788088de56ccSmrg      *)
788188de56ccSmrg	# Unknown arguments in both finalize_command and compile_command need
788288de56ccSmrg	# to be aesthetically quoted because they are evaled later.
78837d2c738bSmrg	func_quote_arg pretty "$arg"
78847d2c738bSmrg	arg=$func_quote_arg_result
788588de56ccSmrg	;;
788688de56ccSmrg      esac # arg
788788de56ccSmrg
788888de56ccSmrg      # Now actually substitute the argument into the commands.
788988de56ccSmrg      if test -n "$arg"; then
789007fb9b8fSmrg	if test -n "$rpath_arg"; then
789107fb9b8fSmrg          func_append finalize_rpath " ${arg##*,}"
789207fb9b8fSmrg	  unset rpath_arg
789307fb9b8fSmrg	else
789407fb9b8fSmrg	  case $arg in
789507fb9b8fSmrg          -Wl,-rpath,*)
789607fb9b8fSmrg	    func_append finalize_rpath " ${arg##*,}";;
789707fb9b8fSmrg          -Wl,-rpath)
789807fb9b8fSmrg	    rpath_arg=1;;
789907fb9b8fSmrg          *)
790007fb9b8fSmrg            func_append compile_command " $arg"
790107fb9b8fSmrg	    func_append finalize_command " $arg"
790207fb9b8fSmrg	  esac
790307fb9b8fSmrg        fi
790488de56ccSmrg      fi
790588de56ccSmrg    done # argument parsing loop
790688de56ccSmrg
790788de56ccSmrg    test -n "$prev" && \
7908862bcd1aSmrg      func_fatal_help "the '$prevarg' option requires an argument"
790988de56ccSmrg
7910862bcd1aSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
791188de56ccSmrg      eval arg=\"$export_dynamic_flag_spec\"
791288de56ccSmrg      func_append compile_command " $arg"
791388de56ccSmrg      func_append finalize_command " $arg"
791488de56ccSmrg    fi
791588de56ccSmrg
791688de56ccSmrg    oldlibs=
791788de56ccSmrg    # calculate the name of the file, without its directory
791888de56ccSmrg    func_basename "$output"
7919862bcd1aSmrg    outputname=$func_basename_result
7920862bcd1aSmrg    libobjs_save=$libobjs
792188de56ccSmrg
792288de56ccSmrg    if test -n "$shlibpath_var"; then
792388de56ccSmrg      # get the directories listed in $shlibpath_var
7924862bcd1aSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
792588de56ccSmrg    else
792688de56ccSmrg      shlib_search_path=
792788de56ccSmrg    fi
792888de56ccSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
792988de56ccSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
793088de56ccSmrg
7931862bcd1aSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7932862bcd1aSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7933862bcd1aSmrg
793488de56ccSmrg    func_dirname "$output" "/" ""
7935862bcd1aSmrg    output_objdir=$func_dirname_result$objdir
7936e9fcaa8aSmrg    func_to_tool_file "$output_objdir/"
7937e9fcaa8aSmrg    tool_output_objdir=$func_to_tool_file_result
793888de56ccSmrg    # Create the object directory.
793988de56ccSmrg    func_mkdir_p "$output_objdir"
794088de56ccSmrg
794188de56ccSmrg    # Determine the type of output
794288de56ccSmrg    case $output in
794388de56ccSmrg    "")
794488de56ccSmrg      func_fatal_help "you must specify an output file"
794588de56ccSmrg      ;;
794688de56ccSmrg    *.$libext) linkmode=oldlib ;;
794788de56ccSmrg    *.lo | *.$objext) linkmode=obj ;;
794888de56ccSmrg    *.la) linkmode=lib ;;
794988de56ccSmrg    *) linkmode=prog ;; # Anything else should be a program.
795088de56ccSmrg    esac
795188de56ccSmrg
795288de56ccSmrg    specialdeplibs=
795388de56ccSmrg
795488de56ccSmrg    libs=
795588de56ccSmrg    # Find all interdependent deplibs by searching for libraries
795688de56ccSmrg    # that are linked more than once (e.g. -la -lb -la)
795788de56ccSmrg    for deplib in $deplibs; do
7958862bcd1aSmrg      if $opt_preserve_dup_deps; then
795988de56ccSmrg	case "$libs " in
7960e9fcaa8aSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
796188de56ccSmrg	esac
796288de56ccSmrg      fi
7963e9fcaa8aSmrg      func_append libs " $deplib"
796488de56ccSmrg    done
796588de56ccSmrg
7966862bcd1aSmrg    if test lib = "$linkmode"; then
796788de56ccSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
796888de56ccSmrg
796988de56ccSmrg      # Compute libraries that are listed more than once in $predeps
797088de56ccSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
797188de56ccSmrg      # not to be eliminated).
797288de56ccSmrg      pre_post_deps=
797388de56ccSmrg      if $opt_duplicate_compiler_generated_deps; then
797488de56ccSmrg	for pre_post_dep in $predeps $postdeps; do
797588de56ccSmrg	  case "$pre_post_deps " in
7976e9fcaa8aSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
797788de56ccSmrg	  esac
7978e9fcaa8aSmrg	  func_append pre_post_deps " $pre_post_dep"
797988de56ccSmrg	done
798088de56ccSmrg      fi
798188de56ccSmrg      pre_post_deps=
798288de56ccSmrg    fi
798388de56ccSmrg
798488de56ccSmrg    deplibs=
798588de56ccSmrg    newdependency_libs=
798688de56ccSmrg    newlib_search_path=
798788de56ccSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
798888de56ccSmrg    notinst_deplibs= # not-installed libtool libraries
798988de56ccSmrg    notinst_path= # paths that contain not-installed libtool libraries
799088de56ccSmrg
799188de56ccSmrg    case $linkmode in
799288de56ccSmrg    lib)
799388de56ccSmrg	passes="conv dlpreopen link"
799488de56ccSmrg	for file in $dlfiles $dlprefiles; do
799588de56ccSmrg	  case $file in
799688de56ccSmrg	  *.la) ;;
799788de56ccSmrg	  *)
7998862bcd1aSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
799988de56ccSmrg	    ;;
800088de56ccSmrg	  esac
800188de56ccSmrg	done
800288de56ccSmrg	;;
800388de56ccSmrg    prog)
800488de56ccSmrg	compile_deplibs=
800588de56ccSmrg	finalize_deplibs=
8006862bcd1aSmrg	alldeplibs=false
800788de56ccSmrg	newdlfiles=
800888de56ccSmrg	newdlprefiles=
800988de56ccSmrg	passes="conv scan dlopen dlpreopen link"
801088de56ccSmrg	;;
801188de56ccSmrg    *)  passes="conv"
801288de56ccSmrg	;;
801388de56ccSmrg    esac
801488de56ccSmrg
801588de56ccSmrg    for pass in $passes; do
801688de56ccSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
801788de56ccSmrg      # so that -L comes before libs that need it for instance...
8018862bcd1aSmrg      if test lib,link = "$linkmode,$pass"; then
801988de56ccSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
802088de56ccSmrg	##        order, and fix it there properly
802188de56ccSmrg        tmp_deplibs=
802288de56ccSmrg	for deplib in $deplibs; do
802388de56ccSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
802488de56ccSmrg	done
8025862bcd1aSmrg	deplibs=$tmp_deplibs
802688de56ccSmrg      fi
802788de56ccSmrg
8028862bcd1aSmrg      if test lib,link = "$linkmode,$pass" ||
8029862bcd1aSmrg	 test prog,scan = "$linkmode,$pass"; then
8030862bcd1aSmrg	libs=$deplibs
803188de56ccSmrg	deplibs=
803288de56ccSmrg      fi
8033862bcd1aSmrg      if test prog = "$linkmode"; then
803488de56ccSmrg	case $pass in
8035862bcd1aSmrg	dlopen) libs=$dlfiles ;;
8036862bcd1aSmrg	dlpreopen) libs=$dlprefiles ;;
803703ea5dc6Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
803888de56ccSmrg	esac
803988de56ccSmrg      fi
8040862bcd1aSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
804188de56ccSmrg	# Collect and forward deplibs of preopened libtool libs
804288de56ccSmrg	for lib in $dlprefiles; do
804388de56ccSmrg	  # Ignore non-libtool-libs
804488de56ccSmrg	  dependency_libs=
8045e9fcaa8aSmrg	  func_resolve_sysroot "$lib"
804688de56ccSmrg	  case $lib in
8047e9fcaa8aSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
804888de56ccSmrg	  esac
804988de56ccSmrg
805088de56ccSmrg	  # Collect preopened libtool deplibs, except any this library
805188de56ccSmrg	  # has declared as weak libs
805288de56ccSmrg	  for deplib in $dependency_libs; do
8053e9fcaa8aSmrg	    func_basename "$deplib"
8054e9fcaa8aSmrg            deplib_base=$func_basename_result
805588de56ccSmrg	    case " $weak_libs " in
805688de56ccSmrg	    *" $deplib_base "*) ;;
8057e9fcaa8aSmrg	    *) func_append deplibs " $deplib" ;;
805888de56ccSmrg	    esac
805988de56ccSmrg	  done
806088de56ccSmrg	done
8061862bcd1aSmrg	libs=$dlprefiles
806288de56ccSmrg      fi
8063862bcd1aSmrg      if test dlopen = "$pass"; then
806488de56ccSmrg	# Collect dlpreopened libraries
8065862bcd1aSmrg	save_deplibs=$deplibs
806688de56ccSmrg	deplibs=
806788de56ccSmrg      fi
806888de56ccSmrg
806988de56ccSmrg      for deplib in $libs; do
807088de56ccSmrg	lib=
8071862bcd1aSmrg	found=false
807288de56ccSmrg	case $deplib in
8073eb411b4bSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
807407fb9b8fSmrg        |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
8075862bcd1aSmrg	  if test prog,link = "$linkmode,$pass"; then
807688de56ccSmrg	    compile_deplibs="$deplib $compile_deplibs"
807788de56ccSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
807888de56ccSmrg	  else
8079e9fcaa8aSmrg	    func_append compiler_flags " $deplib"
8080862bcd1aSmrg	    if test lib = "$linkmode"; then
808188de56ccSmrg		case "$new_inherited_linker_flags " in
808288de56ccSmrg		    *" $deplib "*) ;;
8083e9fcaa8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
808488de56ccSmrg		esac
808588de56ccSmrg	    fi
808688de56ccSmrg	  fi
808788de56ccSmrg	  continue
808888de56ccSmrg	  ;;
808988de56ccSmrg	-l*)
8090862bcd1aSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
8091862bcd1aSmrg	    func_warning "'-l' is ignored for archives/objects"
809288de56ccSmrg	    continue
809388de56ccSmrg	  fi
809488de56ccSmrg	  func_stripname '-l' '' "$deplib"
809588de56ccSmrg	  name=$func_stripname_result
8096862bcd1aSmrg	  if test lib = "$linkmode"; then
809788de56ccSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
809888de56ccSmrg	  else
809988de56ccSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
810088de56ccSmrg	  fi
810188de56ccSmrg	  for searchdir in $searchdirs; do
810288de56ccSmrg	    for search_ext in .la $std_shrext .so .a; do
810388de56ccSmrg	      # Search the libtool library
8104862bcd1aSmrg	      lib=$searchdir/lib$name$search_ext
810588de56ccSmrg	      if test -f "$lib"; then
8106862bcd1aSmrg		if test .la = "$search_ext"; then
8107862bcd1aSmrg		  found=:
810888de56ccSmrg		else
8109862bcd1aSmrg		  found=false
811088de56ccSmrg		fi
811188de56ccSmrg		break 2
811288de56ccSmrg	      fi
811388de56ccSmrg	    done
811488de56ccSmrg	  done
8115862bcd1aSmrg	  if $found; then
8116862bcd1aSmrg	    # deplib is a libtool library
811788de56ccSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
811888de56ccSmrg	    # We need to do some special things here, and not later.
8119862bcd1aSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
812088de56ccSmrg	      case " $predeps $postdeps " in
812188de56ccSmrg	      *" $deplib "*)
812288de56ccSmrg		if func_lalib_p "$lib"; then
812388de56ccSmrg		  library_names=
812488de56ccSmrg		  old_library=
812588de56ccSmrg		  func_source "$lib"
812688de56ccSmrg		  for l in $old_library $library_names; do
8127862bcd1aSmrg		    ll=$l
812888de56ccSmrg		  done
8129862bcd1aSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
8130862bcd1aSmrg		    found=false
813188de56ccSmrg		    func_dirname "$lib" "" "."
8132862bcd1aSmrg		    ladir=$func_dirname_result
813388de56ccSmrg		    lib=$ladir/$old_library
8134862bcd1aSmrg		    if test prog,link = "$linkmode,$pass"; then
813588de56ccSmrg		      compile_deplibs="$deplib $compile_deplibs"
813688de56ccSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
813788de56ccSmrg		    else
813888de56ccSmrg		      deplibs="$deplib $deplibs"
8139862bcd1aSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
814088de56ccSmrg		    fi
814188de56ccSmrg		    continue
814288de56ccSmrg		  fi
814388de56ccSmrg		fi
814488de56ccSmrg		;;
814588de56ccSmrg	      *) ;;
814688de56ccSmrg	      esac
814788de56ccSmrg	    fi
8148862bcd1aSmrg	  else
8149862bcd1aSmrg	    # deplib doesn't seem to be a libtool library
8150862bcd1aSmrg	    if test prog,link = "$linkmode,$pass"; then
8151862bcd1aSmrg	      compile_deplibs="$deplib $compile_deplibs"
8152862bcd1aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8153862bcd1aSmrg	    else
8154862bcd1aSmrg	      deplibs="$deplib $deplibs"
8155862bcd1aSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
8156862bcd1aSmrg	    fi
8157862bcd1aSmrg	    continue
815888de56ccSmrg	  fi
815988de56ccSmrg	  ;; # -l
816088de56ccSmrg	*.ltframework)
8161862bcd1aSmrg	  if test prog,link = "$linkmode,$pass"; then
816288de56ccSmrg	    compile_deplibs="$deplib $compile_deplibs"
816388de56ccSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
816488de56ccSmrg	  else
816588de56ccSmrg	    deplibs="$deplib $deplibs"
8166862bcd1aSmrg	    if test lib = "$linkmode"; then
816788de56ccSmrg		case "$new_inherited_linker_flags " in
816888de56ccSmrg		    *" $deplib "*) ;;
8169e9fcaa8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
817088de56ccSmrg		esac
817188de56ccSmrg	    fi
817288de56ccSmrg	  fi
817388de56ccSmrg	  continue
817488de56ccSmrg	  ;;
817588de56ccSmrg	-L*)
817688de56ccSmrg	  case $linkmode in
817788de56ccSmrg	  lib)
817888de56ccSmrg	    deplibs="$deplib $deplibs"
8179862bcd1aSmrg	    test conv = "$pass" && continue
818088de56ccSmrg	    newdependency_libs="$deplib $newdependency_libs"
818188de56ccSmrg	    func_stripname '-L' '' "$deplib"
8182e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8183e9fcaa8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
818488de56ccSmrg	    ;;
818588de56ccSmrg	  prog)
8186862bcd1aSmrg	    if test conv = "$pass"; then
818788de56ccSmrg	      deplibs="$deplib $deplibs"
818888de56ccSmrg	      continue
818988de56ccSmrg	    fi
8190862bcd1aSmrg	    if test scan = "$pass"; then
819188de56ccSmrg	      deplibs="$deplib $deplibs"
819288de56ccSmrg	    else
819388de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
819488de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
819588de56ccSmrg	    fi
819688de56ccSmrg	    func_stripname '-L' '' "$deplib"
8197e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8198e9fcaa8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
819988de56ccSmrg	    ;;
820088de56ccSmrg	  *)
8201862bcd1aSmrg	    func_warning "'-L' is ignored for archives/objects"
820288de56ccSmrg	    ;;
820388de56ccSmrg	  esac # linkmode
820488de56ccSmrg	  continue
820588de56ccSmrg	  ;; # -L
820688de56ccSmrg	-R*)
8207862bcd1aSmrg	  if test link = "$pass"; then
820888de56ccSmrg	    func_stripname '-R' '' "$deplib"
8209e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8210e9fcaa8aSmrg	    dir=$func_resolve_sysroot_result
821188de56ccSmrg	    # Make sure the xrpath contains only unique directories.
821288de56ccSmrg	    case "$xrpath " in
821388de56ccSmrg	    *" $dir "*) ;;
8214e9fcaa8aSmrg	    *) func_append xrpath " $dir" ;;
821588de56ccSmrg	    esac
821688de56ccSmrg	  fi
821788de56ccSmrg	  deplibs="$deplib $deplibs"
821888de56ccSmrg	  continue
821988de56ccSmrg	  ;;
8220e9fcaa8aSmrg	*.la)
8221e9fcaa8aSmrg	  func_resolve_sysroot "$deplib"
8222e9fcaa8aSmrg	  lib=$func_resolve_sysroot_result
8223e9fcaa8aSmrg	  ;;
822488de56ccSmrg	*.$libext)
8225862bcd1aSmrg	  if test conv = "$pass"; then
822688de56ccSmrg	    deplibs="$deplib $deplibs"
822788de56ccSmrg	    continue
822888de56ccSmrg	  fi
822988de56ccSmrg	  case $linkmode in
823088de56ccSmrg	  lib)
823188de56ccSmrg	    # Linking convenience modules into shared libraries is allowed,
823288de56ccSmrg	    # but linking other static libraries is non-portable.
823388de56ccSmrg	    case " $dlpreconveniencelibs " in
823488de56ccSmrg	    *" $deplib "*) ;;
823588de56ccSmrg	    *)
8236862bcd1aSmrg	      valid_a_lib=false
823788de56ccSmrg	      case $deplibs_check_method in
823888de56ccSmrg		match_pattern*)
823988de56ccSmrg		  set dummy $deplibs_check_method; shift
824088de56ccSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8241e9fcaa8aSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
824288de56ccSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8243862bcd1aSmrg		    valid_a_lib=:
824488de56ccSmrg		  fi
824588de56ccSmrg		;;
824688de56ccSmrg		pass_all)
8247862bcd1aSmrg		  valid_a_lib=:
824888de56ccSmrg		;;
824988de56ccSmrg	      esac
8250862bcd1aSmrg	      if $valid_a_lib; then
825107fb9b8fSmrg		func_warning "Linking the shared library $output against the static library $deplib is not portable!"
8252862bcd1aSmrg		deplibs="$deplib $deplibs"
8253862bcd1aSmrg	      else
825407fb9b8fSmrg		func_warning "Trying to link with static lib archive $deplib."
825507fb9b8fSmrg		func_warning "I have the capability to make that library automatically link in when"
825607fb9b8fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
825707fb9b8fSmrg		func_warning "shared version of the library, which you do not appear to have"
825807fb9b8fSmrg		func_warning "because the file extensions .$libext of this argument makes me believe"
825907fb9b8fSmrg		func_warning "that it is just a static archive that I should not use here."
826088de56ccSmrg	      fi
826188de56ccSmrg	      ;;
826288de56ccSmrg	    esac
826388de56ccSmrg	    continue
826488de56ccSmrg	    ;;
826588de56ccSmrg	  prog)
8266862bcd1aSmrg	    if test link != "$pass"; then
826788de56ccSmrg	      deplibs="$deplib $deplibs"
826888de56ccSmrg	    else
826988de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
827088de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
827188de56ccSmrg	    fi
827288de56ccSmrg	    continue
827388de56ccSmrg	    ;;
827488de56ccSmrg	  esac # linkmode
827588de56ccSmrg	  ;; # *.$libext
827688de56ccSmrg	*.lo | *.$objext)
8277862bcd1aSmrg	  if test conv = "$pass"; then
827888de56ccSmrg	    deplibs="$deplib $deplibs"
8279862bcd1aSmrg	  elif test prog = "$linkmode"; then
8280862bcd1aSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
828188de56ccSmrg	      # If there is no dlopen support or we're linking statically,
828288de56ccSmrg	      # we need to preload.
8283e9fcaa8aSmrg	      func_append newdlprefiles " $deplib"
828488de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
828588de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
828688de56ccSmrg	    else
8287e9fcaa8aSmrg	      func_append newdlfiles " $deplib"
828888de56ccSmrg	    fi
828988de56ccSmrg	  fi
829088de56ccSmrg	  continue
829188de56ccSmrg	  ;;
829288de56ccSmrg	%DEPLIBS%)
8293862bcd1aSmrg	  alldeplibs=:
829488de56ccSmrg	  continue
829588de56ccSmrg	  ;;
829688de56ccSmrg	esac # case $deplib
829788de56ccSmrg
8298862bcd1aSmrg	$found || test -f "$lib" \
8299862bcd1aSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
830088de56ccSmrg
830188de56ccSmrg	# Check to see that this really is a libtool archive.
830288de56ccSmrg	func_lalib_unsafe_p "$lib" \
8303862bcd1aSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
830488de56ccSmrg
830588de56ccSmrg	func_dirname "$lib" "" "."
8306862bcd1aSmrg	ladir=$func_dirname_result
830788de56ccSmrg
830888de56ccSmrg	dlname=
830988de56ccSmrg	dlopen=
831088de56ccSmrg	dlpreopen=
831188de56ccSmrg	libdir=
831288de56ccSmrg	library_names=
831388de56ccSmrg	old_library=
831488de56ccSmrg	inherited_linker_flags=
831588de56ccSmrg	# If the library was installed with an old release of libtool,
831688de56ccSmrg	# it will not redefine variables installed, or shouldnotlink
831788de56ccSmrg	installed=yes
831888de56ccSmrg	shouldnotlink=no
831988de56ccSmrg	avoidtemprpath=
832088de56ccSmrg
832188de56ccSmrg
832288de56ccSmrg	# Read the .la file
832388de56ccSmrg	func_source "$lib"
832488de56ccSmrg
832588de56ccSmrg	# Convert "-framework foo" to "foo.ltframework"
832688de56ccSmrg	if test -n "$inherited_linker_flags"; then
8327e9fcaa8aSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
832888de56ccSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
832988de56ccSmrg	    case " $new_inherited_linker_flags " in
833088de56ccSmrg	      *" $tmp_inherited_linker_flag "*) ;;
8331e9fcaa8aSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
833288de56ccSmrg	    esac
833388de56ccSmrg	  done
833488de56ccSmrg	fi
8335e9fcaa8aSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8336862bcd1aSmrg	if test lib,link = "$linkmode,$pass" ||
8337862bcd1aSmrg	   test prog,scan = "$linkmode,$pass" ||
8338862bcd1aSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8339e9fcaa8aSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8340e9fcaa8aSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
834188de56ccSmrg	fi
834288de56ccSmrg
8343862bcd1aSmrg	if test conv = "$pass"; then
834488de56ccSmrg	  # Only check for convenience libraries
834588de56ccSmrg	  deplibs="$lib $deplibs"
834688de56ccSmrg	  if test -z "$libdir"; then
834788de56ccSmrg	    if test -z "$old_library"; then
8348862bcd1aSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
834988de56ccSmrg	    fi
835088de56ccSmrg	    # It is a libtool convenience library, so add in its objects.
8351e9fcaa8aSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8352e9fcaa8aSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8353862bcd1aSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8354862bcd1aSmrg	    func_fatal_error "'$lib' is not a convenience library"
835588de56ccSmrg	  fi
835603ea5dc6Smrg	  tmp_libs=
835703ea5dc6Smrg	  for deplib in $dependency_libs; do
835803ea5dc6Smrg	    deplibs="$deplib $deplibs"
835903ea5dc6Smrg	    if $opt_preserve_dup_deps; then
836003ea5dc6Smrg	      case "$tmp_libs " in
836103ea5dc6Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
836203ea5dc6Smrg	      esac
836303ea5dc6Smrg	    fi
836403ea5dc6Smrg	    func_append tmp_libs " $deplib"
836503ea5dc6Smrg	  done
836688de56ccSmrg	  continue
836788de56ccSmrg	fi # $pass = conv
836888de56ccSmrg
836988de56ccSmrg
837088de56ccSmrg	# Get the name of the library we link against.
837188de56ccSmrg	linklib=
8372e9fcaa8aSmrg	if test -n "$old_library" &&
8373862bcd1aSmrg	   { test yes = "$prefer_static_libs" ||
8374862bcd1aSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8375e9fcaa8aSmrg	  linklib=$old_library
8376e9fcaa8aSmrg	else
8377e9fcaa8aSmrg	  for l in $old_library $library_names; do
8378862bcd1aSmrg	    linklib=$l
8379e9fcaa8aSmrg	  done
8380e9fcaa8aSmrg	fi
838188de56ccSmrg	if test -z "$linklib"; then
8382862bcd1aSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
838388de56ccSmrg	fi
838488de56ccSmrg
838588de56ccSmrg	# This library was specified with -dlopen.
8386862bcd1aSmrg	if test dlopen = "$pass"; then
8387862bcd1aSmrg	  test -z "$libdir" \
8388862bcd1aSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
838988de56ccSmrg	  if test -z "$dlname" ||
8390862bcd1aSmrg	     test yes != "$dlopen_support" ||
8391862bcd1aSmrg	     test no = "$build_libtool_libs"
8392862bcd1aSmrg	  then
839388de56ccSmrg	    # If there is no dlname, no dlopen support or we're linking
839488de56ccSmrg	    # statically, we need to preload.  We also need to preload any
839588de56ccSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
839688de56ccSmrg	    # bomb out in the load deplibs phase.
8397e9fcaa8aSmrg	    func_append dlprefiles " $lib $dependency_libs"
839888de56ccSmrg	  else
8399e9fcaa8aSmrg	    func_append newdlfiles " $lib"
840088de56ccSmrg	  fi
840188de56ccSmrg	  continue
840288de56ccSmrg	fi # $pass = dlopen
840388de56ccSmrg
840488de56ccSmrg	# We need an absolute path.
840588de56ccSmrg	case $ladir in
8406862bcd1aSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
840788de56ccSmrg	*)
840888de56ccSmrg	  abs_ladir=`cd "$ladir" && pwd`
840988de56ccSmrg	  if test -z "$abs_ladir"; then
8410862bcd1aSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
841188de56ccSmrg	    func_warning "passing it literally to the linker, although it might fail"
8412862bcd1aSmrg	    abs_ladir=$ladir
841388de56ccSmrg	  fi
841488de56ccSmrg	  ;;
841588de56ccSmrg	esac
841688de56ccSmrg	func_basename "$lib"
8417862bcd1aSmrg	laname=$func_basename_result
841888de56ccSmrg
841988de56ccSmrg	# Find the relevant object directory and library name.
8420862bcd1aSmrg	if test yes = "$installed"; then
8421e9fcaa8aSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8422862bcd1aSmrg	    func_warning "library '$lib' was moved."
8423862bcd1aSmrg	    dir=$ladir
8424862bcd1aSmrg	    absdir=$abs_ladir
8425862bcd1aSmrg	    libdir=$abs_ladir
842688de56ccSmrg	  else
8427862bcd1aSmrg	    dir=$lt_sysroot$libdir
8428862bcd1aSmrg	    absdir=$lt_sysroot$libdir
842988de56ccSmrg	  fi
8430862bcd1aSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
843188de56ccSmrg	else
843288de56ccSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8433862bcd1aSmrg	    dir=$ladir
8434862bcd1aSmrg	    absdir=$abs_ladir
843588de56ccSmrg	    # Remove this search path later
8436e9fcaa8aSmrg	    func_append notinst_path " $abs_ladir"
843788de56ccSmrg	  else
8438862bcd1aSmrg	    dir=$ladir/$objdir
8439862bcd1aSmrg	    absdir=$abs_ladir/$objdir
844088de56ccSmrg	    # Remove this search path later
8441e9fcaa8aSmrg	    func_append notinst_path " $abs_ladir"
844288de56ccSmrg	  fi
844388de56ccSmrg	fi # $installed = yes
844488de56ccSmrg	func_stripname 'lib' '.la' "$laname"
844588de56ccSmrg	name=$func_stripname_result
844688de56ccSmrg
844788de56ccSmrg	# This library was specified with -dlpreopen.
8448862bcd1aSmrg	if test dlpreopen = "$pass"; then
8449862bcd1aSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8450862bcd1aSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
845188de56ccSmrg	  fi
8452862bcd1aSmrg	  case $host in
8453e9fcaa8aSmrg	    # special handling for platforms with PE-DLLs.
845407fb9b8fSmrg	    *cygwin* | *mingw* | *windows* | *cegcc* )
8455e9fcaa8aSmrg	      # Linker will automatically link against shared library if both
8456e9fcaa8aSmrg	      # static and shared are present.  Therefore, ensure we extract
8457e9fcaa8aSmrg	      # symbols from the import library if a shared library is present
8458e9fcaa8aSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8459e9fcaa8aSmrg	      # this by putting the import library name into $newdlprefiles.
8460e9fcaa8aSmrg	      # We recover the dlopen module name by 'saving' the la file
8461e9fcaa8aSmrg	      # name in a special purpose variable, and (later) extracting the
8462e9fcaa8aSmrg	      # dlname from the la file.
8463e9fcaa8aSmrg	      if test -n "$dlname"; then
8464e9fcaa8aSmrg	        func_tr_sh "$dir/$linklib"
8465e9fcaa8aSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8466e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8467e9fcaa8aSmrg	      else
8468e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8469e9fcaa8aSmrg	        # Keep a list of preopened convenience libraries to check
8470e9fcaa8aSmrg	        # that they are being used correctly in the link pass.
8471e9fcaa8aSmrg	        test -z "$libdir" && \
8472e9fcaa8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8473e9fcaa8aSmrg	      fi
8474e9fcaa8aSmrg	    ;;
8475e9fcaa8aSmrg	    * )
8476e9fcaa8aSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8477e9fcaa8aSmrg	      # are required to link).
8478e9fcaa8aSmrg	      if test -n "$old_library"; then
8479e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8480e9fcaa8aSmrg	        # Keep a list of preopened convenience libraries to check
8481e9fcaa8aSmrg	        # that they are being used correctly in the link pass.
8482e9fcaa8aSmrg	        test -z "$libdir" && \
8483e9fcaa8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8484e9fcaa8aSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8485e9fcaa8aSmrg	      elif test -n "$dlname"; then
8486e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$dlname"
8487e9fcaa8aSmrg	      else
8488e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8489e9fcaa8aSmrg	      fi
8490e9fcaa8aSmrg	    ;;
8491e9fcaa8aSmrg	  esac
849288de56ccSmrg	fi # $pass = dlpreopen
849388de56ccSmrg
849488de56ccSmrg	if test -z "$libdir"; then
849588de56ccSmrg	  # Link the convenience library
8496862bcd1aSmrg	  if test lib = "$linkmode"; then
849788de56ccSmrg	    deplibs="$dir/$old_library $deplibs"
8498862bcd1aSmrg	  elif test prog,link = "$linkmode,$pass"; then
849988de56ccSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
850088de56ccSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
850188de56ccSmrg	  else
850288de56ccSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
850388de56ccSmrg	  fi
850488de56ccSmrg	  continue
850588de56ccSmrg	fi
850688de56ccSmrg
850788de56ccSmrg
8508862bcd1aSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8509e9fcaa8aSmrg	  func_append newlib_search_path " $ladir"
851088de56ccSmrg	  deplibs="$lib $deplibs"
851188de56ccSmrg
8512862bcd1aSmrg	  linkalldeplibs=false
8513862bcd1aSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8514862bcd1aSmrg	     test no = "$build_libtool_libs"; then
8515862bcd1aSmrg	    linkalldeplibs=:
851688de56ccSmrg	  fi
851788de56ccSmrg
851888de56ccSmrg	  tmp_libs=
851988de56ccSmrg	  for deplib in $dependency_libs; do
852088de56ccSmrg	    case $deplib in
852188de56ccSmrg	    -L*) func_stripname '-L' '' "$deplib"
8522e9fcaa8aSmrg	         func_resolve_sysroot "$func_stripname_result"
8523e9fcaa8aSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
852488de56ccSmrg		 ;;
852588de56ccSmrg	    esac
852688de56ccSmrg	    # Need to link against all dependency_libs?
8527862bcd1aSmrg	    if $linkalldeplibs; then
852888de56ccSmrg	      deplibs="$deplib $deplibs"
852988de56ccSmrg	    else
853088de56ccSmrg	      # Need to hardcode shared library paths
853188de56ccSmrg	      # or/and link against static libraries
853288de56ccSmrg	      newdependency_libs="$deplib $newdependency_libs"
853388de56ccSmrg	    fi
8534862bcd1aSmrg	    if $opt_preserve_dup_deps; then
853588de56ccSmrg	      case "$tmp_libs " in
8536e9fcaa8aSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
853788de56ccSmrg	      esac
853888de56ccSmrg	    fi
8539e9fcaa8aSmrg	    func_append tmp_libs " $deplib"
854088de56ccSmrg	  done # for deplib
854188de56ccSmrg	  continue
854288de56ccSmrg	fi # $linkmode = prog...
854388de56ccSmrg
8544862bcd1aSmrg	if test prog,link = "$linkmode,$pass"; then
854588de56ccSmrg	  if test -n "$library_names" &&
8546862bcd1aSmrg	     { { test no = "$prefer_static_libs" ||
8547862bcd1aSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
854888de56ccSmrg	       test -z "$old_library"; }; then
854988de56ccSmrg	    # We need to hardcode the library path
8550862bcd1aSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
855188de56ccSmrg	      # Make sure the rpath contains only unique directories.
8552862bcd1aSmrg	      case $temp_rpath: in
855388de56ccSmrg	      *"$absdir:"*) ;;
855407fb9b8fSmrg              *) case $absdir in
855507fb9b8fSmrg                 "$progdir/"*) func_append temp_rpath "$absdir:" ;;
855607fb9b8fSmrg                 *)            func_append temp_rpath_tail "$absdir:" ;;
855707fb9b8fSmrg                 esac
855888de56ccSmrg	      esac
855988de56ccSmrg	    fi
856088de56ccSmrg
856188de56ccSmrg	    # Hardcode the library path.
856288de56ccSmrg	    # Skip directories that are in the system default run-time
856388de56ccSmrg	    # search path.
856488de56ccSmrg	    case " $sys_lib_dlsearch_path " in
856588de56ccSmrg	    *" $absdir "*) ;;
856688de56ccSmrg	    *)
856707fb9b8fSmrg	      case "$compile_rpath$compile_rpath_tail " in
856888de56ccSmrg	      *" $absdir "*) ;;
856907fb9b8fSmrg	      *) case $absdir in
857007fb9b8fSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
857107fb9b8fSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
857207fb9b8fSmrg		 esac
857388de56ccSmrg	      esac
857488de56ccSmrg	      ;;
857588de56ccSmrg	    esac
857688de56ccSmrg	    case " $sys_lib_dlsearch_path " in
857788de56ccSmrg	    *" $libdir "*) ;;
857888de56ccSmrg	    *)
857988de56ccSmrg	      case "$finalize_rpath " in
858088de56ccSmrg	      *" $libdir "*) ;;
8581e9fcaa8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
858288de56ccSmrg	      esac
858388de56ccSmrg	      ;;
858488de56ccSmrg	    esac
858588de56ccSmrg	  fi # $linkmode,$pass = prog,link...
858688de56ccSmrg
8587862bcd1aSmrg	  if $alldeplibs &&
8588862bcd1aSmrg	     { test pass_all = "$deplibs_check_method" ||
8589862bcd1aSmrg	       { test yes = "$build_libtool_libs" &&
859088de56ccSmrg		 test -n "$library_names"; }; }; then
859188de56ccSmrg	    # We only need to search for static libraries
859288de56ccSmrg	    continue
859388de56ccSmrg	  fi
859488de56ccSmrg	fi
859588de56ccSmrg
859688de56ccSmrg	link_static=no # Whether the deplib will be linked statically
859788de56ccSmrg	use_static_libs=$prefer_static_libs
8598862bcd1aSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
859988de56ccSmrg	  use_static_libs=no
860088de56ccSmrg	fi
860188de56ccSmrg	if test -n "$library_names" &&
8602862bcd1aSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
860307fb9b8fSmrg	  case $host_os in
860407fb9b8fSmrg	  cygwin* | mingw* | windows* | cegcc* | os2*)
860588de56ccSmrg	      # No point in relinking DLLs because paths are not encoded
8606e9fcaa8aSmrg	      func_append notinst_deplibs " $lib"
860788de56ccSmrg	      need_relink=no
860888de56ccSmrg	    ;;
860988de56ccSmrg	  *)
8610862bcd1aSmrg	    if test no = "$installed"; then
8611e9fcaa8aSmrg	      func_append notinst_deplibs " $lib"
861288de56ccSmrg	      need_relink=yes
861388de56ccSmrg	    fi
861488de56ccSmrg	    ;;
861588de56ccSmrg	  esac
861688de56ccSmrg	  # This is a shared library
861788de56ccSmrg
861888de56ccSmrg	  # Warn about portability, can't link against -module's on some
861988de56ccSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8620862bcd1aSmrg	  dlopenmodule=
862188de56ccSmrg	  for dlpremoduletest in $dlprefiles; do
862288de56ccSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8623862bcd1aSmrg	      dlopenmodule=$dlpremoduletest
862488de56ccSmrg	      break
862588de56ccSmrg	    fi
862688de56ccSmrg	  done
8627862bcd1aSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8628e9fcaa8aSmrg	    echo
8629862bcd1aSmrg	    if test prog = "$linkmode"; then
863007fb9b8fSmrg	      func_warning "Linking the executable $output against the loadable module"
863188de56ccSmrg	    else
863207fb9b8fSmrg	      func_warning "Linking the shared library $output against the loadable module"
863388de56ccSmrg	    fi
863407fb9b8fSmrg	    func_warning "$linklib is not portable!"
863588de56ccSmrg	  fi
8636862bcd1aSmrg	  if test lib = "$linkmode" &&
8637862bcd1aSmrg	     test yes = "$hardcode_into_libs"; then
863888de56ccSmrg	    # Hardcode the library path.
863988de56ccSmrg	    # Skip directories that are in the system default run-time
864088de56ccSmrg	    # search path.
864188de56ccSmrg	    case " $sys_lib_dlsearch_path " in
864288de56ccSmrg	    *" $absdir "*) ;;
864388de56ccSmrg	    *)
864407fb9b8fSmrg	      case "$compile_rpath$compile_rpath_tail " in
864588de56ccSmrg	      *" $absdir "*) ;;
864607fb9b8fSmrg	      *) case $absdir in
864707fb9b8fSmrg                 "$progdir/"*) func_append compile_rpath " $absdir" ;;
864807fb9b8fSmrg                 *) func_append compile_rpath_tail " $absdir" ;;
864907fb9b8fSmrg		 esac
865088de56ccSmrg	      esac
865188de56ccSmrg	      ;;
865288de56ccSmrg	    esac
865388de56ccSmrg	    case " $sys_lib_dlsearch_path " in
865488de56ccSmrg	    *" $libdir "*) ;;
865588de56ccSmrg	    *)
865688de56ccSmrg	      case "$finalize_rpath " in
865788de56ccSmrg	      *" $libdir "*) ;;
8658e9fcaa8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
865988de56ccSmrg	      esac
866088de56ccSmrg	      ;;
866188de56ccSmrg	    esac
866288de56ccSmrg	  fi
866388de56ccSmrg
866488de56ccSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
866588de56ccSmrg	    # figure out the soname
866688de56ccSmrg	    set dummy $library_names
866788de56ccSmrg	    shift
8668862bcd1aSmrg	    realname=$1
866988de56ccSmrg	    shift
867088de56ccSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
867188de56ccSmrg	    # use dlname if we got it. it's perfectly good, no?
867288de56ccSmrg	    if test -n "$dlname"; then
8673862bcd1aSmrg	      soname=$dlname
867488de56ccSmrg	    elif test -n "$soname_spec"; then
867588de56ccSmrg	      # bleh windows
867607fb9b8fSmrg	      case $host_os in
867707fb9b8fSmrg	      cygwin* | mingw* | windows* | cegcc* | os2*)
867888de56ccSmrg	        func_arith $current - $age
867988de56ccSmrg		major=$func_arith_result
8680862bcd1aSmrg		versuffix=-$major
868188de56ccSmrg		;;
868288de56ccSmrg	      esac
868388de56ccSmrg	      eval soname=\"$soname_spec\"
868488de56ccSmrg	    else
8685862bcd1aSmrg	      soname=$realname
868688de56ccSmrg	    fi
868788de56ccSmrg
868888de56ccSmrg	    # Make a new name for the extract_expsyms_cmds to use
8689862bcd1aSmrg	    soroot=$soname
869088de56ccSmrg	    func_basename "$soroot"
8691862bcd1aSmrg	    soname=$func_basename_result
869288de56ccSmrg	    func_stripname 'lib' '.dll' "$soname"
869388de56ccSmrg	    newlib=libimp-$func_stripname_result.a
869488de56ccSmrg
869588de56ccSmrg	    # If the library has no export list, then create one now
869688de56ccSmrg	    if test -f "$output_objdir/$soname-def"; then :
869788de56ccSmrg	    else
8698862bcd1aSmrg	      func_verbose "extracting exported symbol list from '$soname'"
869988de56ccSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
870088de56ccSmrg	    fi
870188de56ccSmrg
870288de56ccSmrg	    # Create $newlib
870388de56ccSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8704862bcd1aSmrg	      func_verbose "generating import library for '$soname'"
870588de56ccSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
870688de56ccSmrg	    fi
870788de56ccSmrg	    # make sure the library variables are pointing to the new library
870888de56ccSmrg	    dir=$output_objdir
870988de56ccSmrg	    linklib=$newlib
871088de56ccSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
871188de56ccSmrg
8712862bcd1aSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
871388de56ccSmrg	    add_shlibpath=
871488de56ccSmrg	    add_dir=
871588de56ccSmrg	    add=
871688de56ccSmrg	    lib_linked=yes
871788de56ccSmrg	    case $hardcode_action in
871888de56ccSmrg	    immediate | unsupported)
8719862bcd1aSmrg	      if test no = "$hardcode_direct"; then
8720862bcd1aSmrg		add=$dir/$linklib
872188de56ccSmrg		case $host in
8722862bcd1aSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8723862bcd1aSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
872407fb9b8fSmrg		  *-*-emscripten*) add_dir=-L$dir ;;
872588de56ccSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8726862bcd1aSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
872788de56ccSmrg		  *-*-darwin* )
8728862bcd1aSmrg		    # if the lib is a (non-dlopened) module then we cannot
872988de56ccSmrg		    # link against it, someone is ignoring the earlier warnings
873088de56ccSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8731862bcd1aSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
873288de56ccSmrg		      if test "X$dlopenmodule" != "X$lib"; then
873307fb9b8fSmrg			func_warning "lib $linklib is a module, not a shared library"
8734862bcd1aSmrg			if test -z "$old_library"; then
873507fb9b8fSmrg			  func_warning "And there doesn't seem to be a static archive available"
873607fb9b8fSmrg			  func_warning "The link will probably fail, sorry"
873788de56ccSmrg			else
8738862bcd1aSmrg			  add=$dir/$old_library
873988de56ccSmrg			fi
874088de56ccSmrg		      elif test -n "$old_library"; then
8741862bcd1aSmrg			add=$dir/$old_library
874288de56ccSmrg		      fi
874388de56ccSmrg		    fi
874488de56ccSmrg		esac
8745862bcd1aSmrg	      elif test no = "$hardcode_minus_L"; then
874688de56ccSmrg		case $host in
8747862bcd1aSmrg		*-*-sunos*) add_shlibpath=$dir ;;
874888de56ccSmrg		esac
8749862bcd1aSmrg		add_dir=-L$dir
8750862bcd1aSmrg		add=-l$name
8751862bcd1aSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8752862bcd1aSmrg		add_shlibpath=$dir
8753862bcd1aSmrg		add=-l$name
875488de56ccSmrg	      else
875588de56ccSmrg		lib_linked=no
875688de56ccSmrg	      fi
875788de56ccSmrg	      ;;
875888de56ccSmrg	    relink)
8759862bcd1aSmrg	      if test yes = "$hardcode_direct" &&
8760862bcd1aSmrg	         test no = "$hardcode_direct_absolute"; then
8761862bcd1aSmrg		add=$dir/$linklib
8762862bcd1aSmrg	      elif test yes = "$hardcode_minus_L"; then
8763862bcd1aSmrg		add_dir=-L$absdir
876488de56ccSmrg		# Try looking first in the location we're being installed to.
876588de56ccSmrg		if test -n "$inst_prefix_dir"; then
876688de56ccSmrg		  case $libdir in
876788de56ccSmrg		    [\\/]*)
8768e9fcaa8aSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
876988de56ccSmrg		      ;;
877088de56ccSmrg		  esac
877188de56ccSmrg		fi
8772862bcd1aSmrg		add=-l$name
8773862bcd1aSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8774862bcd1aSmrg		add_shlibpath=$dir
8775862bcd1aSmrg		add=-l$name
877688de56ccSmrg	      else
877788de56ccSmrg		lib_linked=no
877888de56ccSmrg	      fi
877988de56ccSmrg	      ;;
878088de56ccSmrg	    *) lib_linked=no ;;
878188de56ccSmrg	    esac
878288de56ccSmrg
8783862bcd1aSmrg	    if test yes != "$lib_linked"; then
878488de56ccSmrg	      func_fatal_configuration "unsupported hardcode properties"
878588de56ccSmrg	    fi
878688de56ccSmrg
878788de56ccSmrg	    if test -n "$add_shlibpath"; then
878888de56ccSmrg	      case :$compile_shlibpath: in
878988de56ccSmrg	      *":$add_shlibpath:"*) ;;
8790e9fcaa8aSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
879188de56ccSmrg	      esac
879288de56ccSmrg	    fi
8793862bcd1aSmrg	    if test prog = "$linkmode"; then
879488de56ccSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
879588de56ccSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
879688de56ccSmrg	    else
879788de56ccSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
879888de56ccSmrg	      test -n "$add" && deplibs="$add $deplibs"
8799862bcd1aSmrg	      if test yes != "$hardcode_direct" &&
8800862bcd1aSmrg		 test yes != "$hardcode_minus_L" &&
8801862bcd1aSmrg		 test yes = "$hardcode_shlibpath_var"; then
880288de56ccSmrg		case :$finalize_shlibpath: in
880388de56ccSmrg		*":$libdir:"*) ;;
8804e9fcaa8aSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
880588de56ccSmrg		esac
880688de56ccSmrg	      fi
880788de56ccSmrg	    fi
880888de56ccSmrg	  fi
880988de56ccSmrg
8810862bcd1aSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
881188de56ccSmrg	    add_shlibpath=
881288de56ccSmrg	    add_dir=
881388de56ccSmrg	    add=
881488de56ccSmrg	    # Finalize command for both is simple: just hardcode it.
8815862bcd1aSmrg	    if test yes = "$hardcode_direct" &&
8816862bcd1aSmrg	       test no = "$hardcode_direct_absolute"; then
8817862bcd1aSmrg	      add=$libdir/$linklib
8818862bcd1aSmrg	    elif test yes = "$hardcode_minus_L"; then
881907fb9b8fSmrg	      add_dir=-L$lt_sysroot$libdir
8820862bcd1aSmrg	      add=-l$name
8821862bcd1aSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
882288de56ccSmrg	      case :$finalize_shlibpath: in
882388de56ccSmrg	      *":$libdir:"*) ;;
8824e9fcaa8aSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
882588de56ccSmrg	      esac
8826862bcd1aSmrg	      add=-l$name
8827862bcd1aSmrg	    elif test yes = "$hardcode_automatic"; then
882888de56ccSmrg	      if test -n "$inst_prefix_dir" &&
8829862bcd1aSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8830862bcd1aSmrg		add=$inst_prefix_dir$libdir/$linklib
883188de56ccSmrg	      else
8832862bcd1aSmrg		add=$libdir/$linklib
883388de56ccSmrg	      fi
883488de56ccSmrg	    else
883588de56ccSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
883607fb9b8fSmrg	      add_dir=-L$lt_sysroot$libdir
883788de56ccSmrg	      # Try looking first in the location we're being installed to.
883888de56ccSmrg	      if test -n "$inst_prefix_dir"; then
883988de56ccSmrg		case $libdir in
884088de56ccSmrg		  [\\/]*)
8841e9fcaa8aSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
884288de56ccSmrg		    ;;
884388de56ccSmrg		esac
884488de56ccSmrg	      fi
8845862bcd1aSmrg	      add=-l$name
884688de56ccSmrg	    fi
884788de56ccSmrg
8848862bcd1aSmrg	    if test prog = "$linkmode"; then
884988de56ccSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
885088de56ccSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
885188de56ccSmrg	    else
885288de56ccSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
885388de56ccSmrg	      test -n "$add" && deplibs="$add $deplibs"
885488de56ccSmrg	    fi
885588de56ccSmrg	  fi
8856862bcd1aSmrg	elif test prog = "$linkmode"; then
885788de56ccSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
885888de56ccSmrg	  # is not unsupported.  This is valid on all known static and
885988de56ccSmrg	  # shared platforms.
8860862bcd1aSmrg	  if test unsupported != "$hardcode_direct"; then
8861862bcd1aSmrg	    test -n "$old_library" && linklib=$old_library
886288de56ccSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
886388de56ccSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
886488de56ccSmrg	  else
886588de56ccSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
886688de56ccSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
886788de56ccSmrg	  fi
8868862bcd1aSmrg	elif test yes = "$build_libtool_libs"; then
886988de56ccSmrg	  # Not a shared library
8870862bcd1aSmrg	  if test pass_all != "$deplibs_check_method"; then
887188de56ccSmrg	    # We're trying link a shared library against a static one
887288de56ccSmrg	    # but the system doesn't support it.
887388de56ccSmrg
887488de56ccSmrg	    # Just print a warning and add the library to dependency_libs so
887588de56ccSmrg	    # that the program can be linked against the static library.
887607fb9b8fSmrg	    func_warning "This system cannot link to static lib archive $lib."
887707fb9b8fSmrg	    func_warning "I have the capability to make that library automatically link in when"
887807fb9b8fSmrg	    func_warning "you link to this library.  But I can only do this if you have a"
887907fb9b8fSmrg	    func_warning "shared version of the library, which you do not appear to have."
8880862bcd1aSmrg	    if test yes = "$module"; then
888107fb9b8fSmrg	      func_warning "But as you try to build a module library, libtool will still create "
888207fb9b8fSmrg	      func_warning "a static module, that should work as long as the dlopening application"
888307fb9b8fSmrg	      func_warning "is linked with the -dlopen flag to resolve symbols at runtime."
888488de56ccSmrg	      if test -z "$global_symbol_pipe"; then
888507fb9b8fSmrg		func_warning "However, this would only work if libtool was able to extract symbol"
888607fb9b8fSmrg		func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
888707fb9b8fSmrg		func_warning "not find such a program.  So, this module is probably useless."
888807fb9b8fSmrg		func_warning "'nm' from GNU binutils and a full rebuild may help."
888988de56ccSmrg	      fi
8890862bcd1aSmrg	      if test no = "$build_old_libs"; then
889188de56ccSmrg		build_libtool_libs=module
889288de56ccSmrg		build_old_libs=yes
889388de56ccSmrg	      else
889488de56ccSmrg		build_libtool_libs=no
889588de56ccSmrg	      fi
889688de56ccSmrg	    fi
889788de56ccSmrg	  else
889888de56ccSmrg	    deplibs="$dir/$old_library $deplibs"
889988de56ccSmrg	    link_static=yes
890088de56ccSmrg	  fi
890188de56ccSmrg	fi # link shared/static library?
890288de56ccSmrg
8903862bcd1aSmrg	if test lib = "$linkmode"; then
890488de56ccSmrg	  if test -n "$dependency_libs" &&
8905862bcd1aSmrg	     { test yes != "$hardcode_into_libs" ||
8906862bcd1aSmrg	       test yes = "$build_old_libs" ||
8907862bcd1aSmrg	       test yes = "$link_static"; }; then
890888de56ccSmrg	    # Extract -R from dependency_libs
890988de56ccSmrg	    temp_deplibs=
891088de56ccSmrg	    for libdir in $dependency_libs; do
891188de56ccSmrg	      case $libdir in
891288de56ccSmrg	      -R*) func_stripname '-R' '' "$libdir"
891388de56ccSmrg	           temp_xrpath=$func_stripname_result
891488de56ccSmrg		   case " $xrpath " in
891588de56ccSmrg		   *" $temp_xrpath "*) ;;
8916e9fcaa8aSmrg		   *) func_append xrpath " $temp_xrpath";;
891788de56ccSmrg		   esac;;
8918e9fcaa8aSmrg	      *) func_append temp_deplibs " $libdir";;
891988de56ccSmrg	      esac
892088de56ccSmrg	    done
8921862bcd1aSmrg	    dependency_libs=$temp_deplibs
892288de56ccSmrg	  fi
892388de56ccSmrg
8924e9fcaa8aSmrg	  func_append newlib_search_path " $absdir"
892588de56ccSmrg	  # Link against this library
8926862bcd1aSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
892788de56ccSmrg	  # ... and its dependency_libs
892888de56ccSmrg	  tmp_libs=
892988de56ccSmrg	  for deplib in $dependency_libs; do
893088de56ccSmrg	    newdependency_libs="$deplib $newdependency_libs"
8931e9fcaa8aSmrg	    case $deplib in
8932e9fcaa8aSmrg              -L*) func_stripname '-L' '' "$deplib"
8933e9fcaa8aSmrg                   func_resolve_sysroot "$func_stripname_result";;
8934e9fcaa8aSmrg              *) func_resolve_sysroot "$deplib" ;;
8935e9fcaa8aSmrg            esac
8936862bcd1aSmrg	    if $opt_preserve_dup_deps; then
893788de56ccSmrg	      case "$tmp_libs " in
8938e9fcaa8aSmrg	      *" $func_resolve_sysroot_result "*)
8939e9fcaa8aSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
894088de56ccSmrg	      esac
894188de56ccSmrg	    fi
8942e9fcaa8aSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
894388de56ccSmrg	  done
894488de56ccSmrg
8945862bcd1aSmrg	  if test no != "$link_all_deplibs"; then
894688de56ccSmrg	    # Add the search paths of all dependency libraries
894788de56ccSmrg	    for deplib in $dependency_libs; do
894847f86ac1Smrg	      path=
894988de56ccSmrg	      case $deplib in
8950862bcd1aSmrg	      -L*) path=$deplib ;;
895188de56ccSmrg	      *.la)
8952e9fcaa8aSmrg	        func_resolve_sysroot "$deplib"
8953e9fcaa8aSmrg	        deplib=$func_resolve_sysroot_result
895488de56ccSmrg	        func_dirname "$deplib" "" "."
8955e9fcaa8aSmrg		dir=$func_dirname_result
895688de56ccSmrg		# We need an absolute path.
895788de56ccSmrg		case $dir in
8958862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
895988de56ccSmrg		*)
896088de56ccSmrg		  absdir=`cd "$dir" && pwd`
896188de56ccSmrg		  if test -z "$absdir"; then
8962862bcd1aSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8963862bcd1aSmrg		    absdir=$dir
896488de56ccSmrg		  fi
896588de56ccSmrg		  ;;
896688de56ccSmrg		esac
896788de56ccSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
896888de56ccSmrg		case $host in
896988de56ccSmrg		*-*-darwin*)
897088de56ccSmrg		  depdepl=
8971862bcd1aSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8972862bcd1aSmrg		  if test -n "$deplibrary_names"; then
8973862bcd1aSmrg		    for tmp in $deplibrary_names; do
897488de56ccSmrg		      depdepl=$tmp
897588de56ccSmrg		    done
8976862bcd1aSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8977862bcd1aSmrg		      depdepl=$absdir/$objdir/$depdepl
8978862bcd1aSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
897988de56ccSmrg                      if test -z "$darwin_install_name"; then
8980862bcd1aSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
898188de56ccSmrg                      fi
8982862bcd1aSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8983862bcd1aSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
898488de56ccSmrg		      path=
898588de56ccSmrg		    fi
898688de56ccSmrg		  fi
898788de56ccSmrg		  ;;
898888de56ccSmrg		*)
8989862bcd1aSmrg		  path=-L$absdir/$objdir
899088de56ccSmrg		  ;;
899188de56ccSmrg		esac
899288de56ccSmrg		else
8993862bcd1aSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
899488de56ccSmrg		  test -z "$libdir" && \
8995862bcd1aSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
899688de56ccSmrg		  test "$absdir" != "$libdir" && \
8997862bcd1aSmrg		    func_warning "'$deplib' seems to be moved"
899888de56ccSmrg
8999862bcd1aSmrg		  path=-L$absdir
900088de56ccSmrg		fi
900188de56ccSmrg		;;
900288de56ccSmrg	      esac
900388de56ccSmrg	      case " $deplibs " in
900488de56ccSmrg	      *" $path "*) ;;
900588de56ccSmrg	      *) deplibs="$path $deplibs" ;;
900688de56ccSmrg	      esac
900788de56ccSmrg	    done
900888de56ccSmrg	  fi # link_all_deplibs != no
900988de56ccSmrg	fi # linkmode = lib
901088de56ccSmrg      done # for deplib in $libs
901107fb9b8fSmrg
901207fb9b8fSmrg      func_append temp_rpath "$temp_rpath_tail"
901307fb9b8fSmrg      func_append compile_rpath "$compile_rpath_tail"
901407fb9b8fSmrg
9015862bcd1aSmrg      if test link = "$pass"; then
9016862bcd1aSmrg	if test prog = "$linkmode"; then
901788de56ccSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
901888de56ccSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
901988de56ccSmrg	else
9020e9fcaa8aSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
902188de56ccSmrg	fi
902288de56ccSmrg      fi
9023862bcd1aSmrg      dependency_libs=$newdependency_libs
9024862bcd1aSmrg      if test dlpreopen = "$pass"; then
902588de56ccSmrg	# Link the dlpreopened libraries before other libraries
902688de56ccSmrg	for deplib in $save_deplibs; do
902788de56ccSmrg	  deplibs="$deplib $deplibs"
902888de56ccSmrg	done
902988de56ccSmrg      fi
9030862bcd1aSmrg      if test dlopen != "$pass"; then
9031862bcd1aSmrg	test conv = "$pass" || {
903288de56ccSmrg	  # Make sure lib_search_path contains only unique directories.
903388de56ccSmrg	  lib_search_path=
903488de56ccSmrg	  for dir in $newlib_search_path; do
903588de56ccSmrg	    case "$lib_search_path " in
903688de56ccSmrg	    *" $dir "*) ;;
9037e9fcaa8aSmrg	    *) func_append lib_search_path " $dir" ;;
903888de56ccSmrg	    esac
903988de56ccSmrg	  done
904088de56ccSmrg	  newlib_search_path=
9041862bcd1aSmrg	}
904288de56ccSmrg
9043862bcd1aSmrg	if test prog,link = "$linkmode,$pass"; then
904488de56ccSmrg	  vars="compile_deplibs finalize_deplibs"
9045862bcd1aSmrg	else
9046862bcd1aSmrg	  vars=deplibs
904788de56ccSmrg	fi
904888de56ccSmrg	for var in $vars dependency_libs; do
904988de56ccSmrg	  # Add libraries to $var in reverse order
905088de56ccSmrg	  eval tmp_libs=\"\$$var\"
905188de56ccSmrg	  new_libs=
905207fb9b8fSmrg	  # FIXME: Pedantically, this is the right thing to do, so
905307fb9b8fSmrg	  #        that some nasty dependency loop isn't accidentally
905407fb9b8fSmrg	  #        broken: new_libs="$deplib $new_libs"
905588de56ccSmrg	  for deplib in $tmp_libs; do
905607fb9b8fSmrg	    if $opt_preserve_dup_deps; then
905707fb9b8fSmrg	      new_libs="$deplib $new_libs"
905807fb9b8fSmrg	    else
905907fb9b8fSmrg	      # Pragmatically, this seems to cause very few problems in
906007fb9b8fSmrg	      # practice:
906107fb9b8fSmrg	      case $deplib in
906207fb9b8fSmrg	      -L*) new_libs="$deplib $new_libs" ;;
906307fb9b8fSmrg	      -R*) ;;
906488de56ccSmrg	      *)
906507fb9b8fSmrg	        # And here is the reason: when a library appears more
906607fb9b8fSmrg	        # than once as an explicit dependence of a library, or
906707fb9b8fSmrg	        # is implicitly linked in more than once by the
906807fb9b8fSmrg	        # compiler, it is considered special, and multiple
906907fb9b8fSmrg	        # occurrences thereof are not removed.  Compare this
907007fb9b8fSmrg	        # with having the same library being listed as a
907107fb9b8fSmrg	        # dependency of multiple other libraries: in this case,
907207fb9b8fSmrg	        # we know (pedantically, we assume) the library does not
907307fb9b8fSmrg	        # need to be listed more than once, so we keep only the
907407fb9b8fSmrg	        # last copy.  This is not always right, but it is rare
907507fb9b8fSmrg	        # enough that we require users that really mean to play
907607fb9b8fSmrg	        # such unportable linking tricks to link the library
907707fb9b8fSmrg	        # using -Wl,-lname, so that libtool does not consider it
907807fb9b8fSmrg	        # for duplicate removal.  And if not possible for portability
907907fb9b8fSmrg	        # reasons, then --preserve-dup-deps should be used.
908007fb9b8fSmrg	        case " $specialdeplibs " in
908107fb9b8fSmrg	        *" $deplib "*) new_libs="$deplib $new_libs" ;;
908207fb9b8fSmrg	        *)
908307fb9b8fSmrg	          case " $new_libs " in
908407fb9b8fSmrg	          *" $deplib "*) ;;
908507fb9b8fSmrg	          *) new_libs="$deplib $new_libs" ;;
908607fb9b8fSmrg	          esac
908707fb9b8fSmrg	          ;;
908807fb9b8fSmrg	        esac
908907fb9b8fSmrg	        ;;
909088de56ccSmrg	      esac
909107fb9b8fSmrg	    fi
909288de56ccSmrg	  done
909388de56ccSmrg	  tmp_libs=
909488de56ccSmrg	  for deplib in $new_libs; do
909588de56ccSmrg	    case $deplib in
909688de56ccSmrg	    -L*)
909788de56ccSmrg	      case " $tmp_libs " in
909888de56ccSmrg	      *" $deplib "*) ;;
9099e9fcaa8aSmrg	      *) func_append tmp_libs " $deplib" ;;
910088de56ccSmrg	      esac
910188de56ccSmrg	      ;;
9102e9fcaa8aSmrg	    *) func_append tmp_libs " $deplib" ;;
910388de56ccSmrg	    esac
910488de56ccSmrg	  done
910588de56ccSmrg	  eval $var=\"$tmp_libs\"
910688de56ccSmrg	done # for var
910788de56ccSmrg      fi
9108862bcd1aSmrg
9109862bcd1aSmrg      # Add Sun CC postdeps if required:
9110862bcd1aSmrg      test CXX = "$tagname" && {
9111862bcd1aSmrg        case $host_os in
9112862bcd1aSmrg        linux*)
91137d2c738bSmrg          case `$CC -V 2>&1 | $SED 5q` in
9114862bcd1aSmrg          *Sun\ C*) # Sun C++ 5.9
9115862bcd1aSmrg            func_suncc_cstd_abi
9116862bcd1aSmrg
9117862bcd1aSmrg            if test no != "$suncc_use_cstd_abi"; then
9118862bcd1aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
9119862bcd1aSmrg            fi
9120862bcd1aSmrg            ;;
9121862bcd1aSmrg          esac
9122862bcd1aSmrg          ;;
9123862bcd1aSmrg
9124862bcd1aSmrg        solaris*)
9125862bcd1aSmrg          func_cc_basename "$CC"
9126862bcd1aSmrg          case $func_cc_basename_result in
9127862bcd1aSmrg          CC* | sunCC*)
9128862bcd1aSmrg            func_suncc_cstd_abi
9129862bcd1aSmrg
9130862bcd1aSmrg            if test no != "$suncc_use_cstd_abi"; then
9131862bcd1aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
9132862bcd1aSmrg            fi
9133862bcd1aSmrg            ;;
9134862bcd1aSmrg          esac
9135862bcd1aSmrg          ;;
9136862bcd1aSmrg        esac
9137862bcd1aSmrg      }
9138862bcd1aSmrg
913988de56ccSmrg      # Last step: remove runtime libs from dependency_libs
914088de56ccSmrg      # (they stay in deplibs)
914188de56ccSmrg      tmp_libs=
9142862bcd1aSmrg      for i in $dependency_libs; do
914388de56ccSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
914488de56ccSmrg	*" $i "*)
9145862bcd1aSmrg	  i=
914688de56ccSmrg	  ;;
914788de56ccSmrg	esac
9148862bcd1aSmrg	if test -n "$i"; then
9149e9fcaa8aSmrg	  func_append tmp_libs " $i"
915088de56ccSmrg	fi
915188de56ccSmrg      done
915288de56ccSmrg      dependency_libs=$tmp_libs
915388de56ccSmrg    done # for pass
9154862bcd1aSmrg    if test prog = "$linkmode"; then
9155862bcd1aSmrg      dlfiles=$newdlfiles
915688de56ccSmrg    fi
9157862bcd1aSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
9158862bcd1aSmrg      dlprefiles=$newdlprefiles
915988de56ccSmrg    fi
916088de56ccSmrg
916188de56ccSmrg    case $linkmode in
916288de56ccSmrg    oldlib)
9163862bcd1aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
9164862bcd1aSmrg	func_warning "'-dlopen' is ignored for archives"
916588de56ccSmrg      fi
916688de56ccSmrg
916788de56ccSmrg      case " $deplibs" in
916888de56ccSmrg      *\ -l* | *\ -L*)
9169862bcd1aSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
917088de56ccSmrg      esac
917188de56ccSmrg
917288de56ccSmrg      test -n "$rpath" && \
9173862bcd1aSmrg	func_warning "'-rpath' is ignored for archives"
917488de56ccSmrg
917588de56ccSmrg      test -n "$xrpath" && \
9176862bcd1aSmrg	func_warning "'-R' is ignored for archives"
917788de56ccSmrg
917888de56ccSmrg      test -n "$vinfo" && \
9179862bcd1aSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
918088de56ccSmrg
918188de56ccSmrg      test -n "$release" && \
9182862bcd1aSmrg	func_warning "'-release' is ignored for archives"
918388de56ccSmrg
918488de56ccSmrg      test -n "$export_symbols$export_symbols_regex" && \
9185862bcd1aSmrg	func_warning "'-export-symbols' is ignored for archives"
918688de56ccSmrg
918788de56ccSmrg      # Now set the variables for building old libraries.
918888de56ccSmrg      build_libtool_libs=no
9189862bcd1aSmrg      oldlibs=$output
9190e9fcaa8aSmrg      func_append objs "$old_deplibs"
919188de56ccSmrg      ;;
919288de56ccSmrg
919388de56ccSmrg    lib)
9194862bcd1aSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
919588de56ccSmrg      case $outputname in
919688de56ccSmrg      lib*)
919788de56ccSmrg	func_stripname 'lib' '.la' "$outputname"
919888de56ccSmrg	name=$func_stripname_result
919988de56ccSmrg	eval shared_ext=\"$shrext_cmds\"
920088de56ccSmrg	eval libname=\"$libname_spec\"
920188de56ccSmrg	;;
920288de56ccSmrg      *)
9203862bcd1aSmrg	test no = "$module" \
9204862bcd1aSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
920588de56ccSmrg
9206862bcd1aSmrg	if test no != "$need_lib_prefix"; then
920788de56ccSmrg	  # Add the "lib" prefix for modules if required
920888de56ccSmrg	  func_stripname '' '.la' "$outputname"
920988de56ccSmrg	  name=$func_stripname_result
921088de56ccSmrg	  eval shared_ext=\"$shrext_cmds\"
921188de56ccSmrg	  eval libname=\"$libname_spec\"
921288de56ccSmrg	else
921388de56ccSmrg	  func_stripname '' '.la' "$outputname"
921488de56ccSmrg	  libname=$func_stripname_result
921588de56ccSmrg	fi
921688de56ccSmrg	;;
921788de56ccSmrg      esac
921888de56ccSmrg
921988de56ccSmrg      if test -n "$objs"; then
9220862bcd1aSmrg	if test pass_all != "$deplibs_check_method"; then
9221862bcd1aSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
922288de56ccSmrg	else
922307fb9b8fSmrg	  func_warning "Linking the shared library $output against the non-libtool objects $objs is not portable!"
9224e9fcaa8aSmrg	  func_append libobjs " $objs"
922588de56ccSmrg	fi
922688de56ccSmrg      fi
922788de56ccSmrg
9228862bcd1aSmrg      test no = "$dlself" \
9229862bcd1aSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
923088de56ccSmrg
923188de56ccSmrg      set dummy $rpath
923288de56ccSmrg      shift
9233862bcd1aSmrg      test 1 -lt "$#" \
9234862bcd1aSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
923588de56ccSmrg
9236862bcd1aSmrg      install_libdir=$1
923788de56ccSmrg
923888de56ccSmrg      oldlibs=
923988de56ccSmrg      if test -z "$rpath"; then
9240862bcd1aSmrg	if test yes = "$build_libtool_libs"; then
924188de56ccSmrg	  # Building a libtool convenience library.
9242862bcd1aSmrg	  # Some compilers have problems with a '.al' extension so
924388de56ccSmrg	  # convenience libraries should have the same extension an
924488de56ccSmrg	  # archive normally would.
924588de56ccSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
924688de56ccSmrg	  build_libtool_libs=convenience
924788de56ccSmrg	  build_old_libs=yes
924888de56ccSmrg	fi
924988de56ccSmrg
925088de56ccSmrg	test -n "$vinfo" && \
9251862bcd1aSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
925288de56ccSmrg
925388de56ccSmrg	test -n "$release" && \
9254862bcd1aSmrg	  func_warning "'-release' is ignored for convenience libraries"
925588de56ccSmrg      else
925688de56ccSmrg
925788de56ccSmrg	# Parse the version information argument.
9258862bcd1aSmrg	save_ifs=$IFS; IFS=:
925988de56ccSmrg	set dummy $vinfo 0 0 0
926088de56ccSmrg	shift
9261862bcd1aSmrg	IFS=$save_ifs
926288de56ccSmrg
926388de56ccSmrg	test -n "$7" && \
9264862bcd1aSmrg	  func_fatal_help "too many parameters to '-version-info'"
926588de56ccSmrg
926688de56ccSmrg	# convert absolute version numbers to libtool ages
926788de56ccSmrg	# this retains compatibility with .la files and attempts
926888de56ccSmrg	# to make the code below a bit more comprehensible
926988de56ccSmrg
927088de56ccSmrg	case $vinfo_number in
927188de56ccSmrg	yes)
9272862bcd1aSmrg	  number_major=$1
9273862bcd1aSmrg	  number_minor=$2
9274862bcd1aSmrg	  number_revision=$3
927588de56ccSmrg	  #
927688de56ccSmrg	  # There are really only two kinds -- those that
927788de56ccSmrg	  # use the current revision as the major version
927888de56ccSmrg	  # and those that subtract age and use age as
927988de56ccSmrg	  # a minor version.  But, then there is irix
9280862bcd1aSmrg	  # that has an extra 1 added just for fun
928188de56ccSmrg	  #
928288de56ccSmrg	  case $version_type in
9283eb411b4bSmrg	  # correct linux to gnu/linux during the next big refactor
928407fb9b8fSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|qnx|windows|none)
928588de56ccSmrg	    func_arith $number_major + $number_minor
928688de56ccSmrg	    current=$func_arith_result
9287862bcd1aSmrg	    age=$number_minor
9288862bcd1aSmrg	    revision=$number_revision
928988de56ccSmrg	    ;;
929007fb9b8fSmrg	  freebsd-aout|sco|sunos)
9291862bcd1aSmrg	    current=$number_major
9292862bcd1aSmrg	    revision=$number_minor
9293862bcd1aSmrg	    age=0
929488de56ccSmrg	    ;;
929588de56ccSmrg	  irix|nonstopux)
929688de56ccSmrg	    func_arith $number_major + $number_minor
929788de56ccSmrg	    current=$func_arith_result
9298862bcd1aSmrg	    age=$number_minor
9299862bcd1aSmrg	    revision=$number_minor
930088de56ccSmrg	    lt_irix_increment=no
930188de56ccSmrg	    ;;
930207fb9b8fSmrg	  *)
930307fb9b8fSmrg	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
930407fb9b8fSmrg	    ;;
930588de56ccSmrg	  esac
930688de56ccSmrg	  ;;
930788de56ccSmrg	no)
9308862bcd1aSmrg	  current=$1
9309862bcd1aSmrg	  revision=$2
9310862bcd1aSmrg	  age=$3
931188de56ccSmrg	  ;;
931288de56ccSmrg	esac
931388de56ccSmrg
931488de56ccSmrg	# Check that each of the things are valid numbers.
931588de56ccSmrg	case $current in
931688de56ccSmrg	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]) ;;
931788de56ccSmrg	*)
9318862bcd1aSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9319862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
932088de56ccSmrg	  ;;
932188de56ccSmrg	esac
932288de56ccSmrg
932388de56ccSmrg	case $revision in
932488de56ccSmrg	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]) ;;
932588de56ccSmrg	*)
9326862bcd1aSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9327862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
932888de56ccSmrg	  ;;
932988de56ccSmrg	esac
933088de56ccSmrg
933188de56ccSmrg	case $age in
933288de56ccSmrg	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]) ;;
933388de56ccSmrg	*)
9334862bcd1aSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9335862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
933688de56ccSmrg	  ;;
933788de56ccSmrg	esac
933888de56ccSmrg
933988de56ccSmrg	if test "$age" -gt "$current"; then
9340862bcd1aSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9341862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
934288de56ccSmrg	fi
934388de56ccSmrg
934488de56ccSmrg	# Calculate the version variables.
934588de56ccSmrg	major=
934688de56ccSmrg	versuffix=
934788de56ccSmrg	verstring=
934888de56ccSmrg	case $version_type in
934988de56ccSmrg	none) ;;
935088de56ccSmrg
935188de56ccSmrg	darwin)
935288de56ccSmrg	  # Like Linux, but with the current version available in
935388de56ccSmrg	  # verstring for coding it into the library header
935488de56ccSmrg	  func_arith $current - $age
935588de56ccSmrg	  major=.$func_arith_result
9356862bcd1aSmrg	  versuffix=$major.$age.$revision
935788de56ccSmrg	  # Darwin ld doesn't like 0 for these options...
935888de56ccSmrg	  func_arith $current + 1
935988de56ccSmrg	  minor_current=$func_arith_result
9360862bcd1aSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
936188de56ccSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9362862bcd1aSmrg          # On Darwin other compilers
9363862bcd1aSmrg          case $CC in
9364862bcd1aSmrg              nagfor*)
9365862bcd1aSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9366862bcd1aSmrg                  ;;
9367862bcd1aSmrg              *)
9368862bcd1aSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9369862bcd1aSmrg                  ;;
9370862bcd1aSmrg          esac
937188de56ccSmrg	  ;;
937288de56ccSmrg
937388de56ccSmrg	freebsd-aout)
9374862bcd1aSmrg	  major=.$current
9375862bcd1aSmrg	  versuffix=.$current.$revision
937688de56ccSmrg	  ;;
937788de56ccSmrg
93787d2c738bSmrg	freebsd-elf | midnightbsd-elf)
9379862bcd1aSmrg	  func_arith $current - $age
9380862bcd1aSmrg	  major=.$func_arith_result
9381862bcd1aSmrg	  versuffix=$major.$age.$revision
938288de56ccSmrg	  ;;
938388de56ccSmrg
938488de56ccSmrg	irix | nonstopux)
9385862bcd1aSmrg	  if test no = "$lt_irix_increment"; then
938688de56ccSmrg	    func_arith $current - $age
938788de56ccSmrg	  else
938888de56ccSmrg	    func_arith $current - $age + 1
938988de56ccSmrg	  fi
939088de56ccSmrg	  major=$func_arith_result
939188de56ccSmrg
939288de56ccSmrg	  case $version_type in
939388de56ccSmrg	    nonstopux) verstring_prefix=nonstopux ;;
939488de56ccSmrg	    *)         verstring_prefix=sgi ;;
939588de56ccSmrg	  esac
9396862bcd1aSmrg	  verstring=$verstring_prefix$major.$revision
939788de56ccSmrg
939888de56ccSmrg	  # Add in all the interfaces that we are compatible with.
939988de56ccSmrg	  loop=$revision
9400862bcd1aSmrg	  while test 0 -ne "$loop"; do
940188de56ccSmrg	    func_arith $revision - $loop
940288de56ccSmrg	    iface=$func_arith_result
940388de56ccSmrg	    func_arith $loop - 1
940488de56ccSmrg	    loop=$func_arith_result
9405862bcd1aSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
940688de56ccSmrg	  done
940788de56ccSmrg
9408862bcd1aSmrg	  # Before this point, $major must not contain '.'.
940988de56ccSmrg	  major=.$major
9410862bcd1aSmrg	  versuffix=$major.$revision
941188de56ccSmrg	  ;;
941288de56ccSmrg
9413eb411b4bSmrg	linux) # correct to gnu/linux during the next big refactor
941488de56ccSmrg	  func_arith $current - $age
941588de56ccSmrg	  major=.$func_arith_result
9416862bcd1aSmrg	  versuffix=$major.$age.$revision
941788de56ccSmrg	  ;;
941888de56ccSmrg
941988de56ccSmrg	osf)
942088de56ccSmrg	  func_arith $current - $age
942188de56ccSmrg	  major=.$func_arith_result
9422862bcd1aSmrg	  versuffix=.$current.$age.$revision
9423862bcd1aSmrg	  verstring=$current.$age.$revision
942488de56ccSmrg
942588de56ccSmrg	  # Add in all the interfaces that we are compatible with.
942688de56ccSmrg	  loop=$age
9427862bcd1aSmrg	  while test 0 -ne "$loop"; do
942888de56ccSmrg	    func_arith $current - $loop
942988de56ccSmrg	    iface=$func_arith_result
943088de56ccSmrg	    func_arith $loop - 1
943188de56ccSmrg	    loop=$func_arith_result
9432862bcd1aSmrg	    verstring=$verstring:$iface.0
943388de56ccSmrg	  done
943488de56ccSmrg
943588de56ccSmrg	  # Make executables depend on our current version.
9436862bcd1aSmrg	  func_append verstring ":$current.0"
943788de56ccSmrg	  ;;
943888de56ccSmrg
943988de56ccSmrg	qnx)
944007fb9b8fSmrg	  func_arith $current - $age
944107fb9b8fSmrg	  major=.$func_arith_result
944207fb9b8fSmrg	  versuffix=$major.$age.$revision
9443862bcd1aSmrg	  ;;
9444862bcd1aSmrg
9445862bcd1aSmrg	sco)
9446862bcd1aSmrg	  major=.$current
9447862bcd1aSmrg	  versuffix=.$current
944888de56ccSmrg	  ;;
944988de56ccSmrg
945088de56ccSmrg	sunos)
9451862bcd1aSmrg	  major=.$current
9452862bcd1aSmrg	  versuffix=.$current.$revision
945388de56ccSmrg	  ;;
945488de56ccSmrg
945588de56ccSmrg	windows)
945688de56ccSmrg	  # Use '-' rather than '.', since we only want one
9457862bcd1aSmrg	  # extension on DOS 8.3 file systems.
945888de56ccSmrg	  func_arith $current - $age
945988de56ccSmrg	  major=$func_arith_result
9460862bcd1aSmrg	  versuffix=-$major
946188de56ccSmrg	  ;;
946288de56ccSmrg
946388de56ccSmrg	*)
9464862bcd1aSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
946588de56ccSmrg	  ;;
946688de56ccSmrg	esac
946788de56ccSmrg
946888de56ccSmrg	# Clear the version info if we defaulted, and they specified a release.
946988de56ccSmrg	if test -z "$vinfo" && test -n "$release"; then
947088de56ccSmrg	  major=
947188de56ccSmrg	  case $version_type in
947288de56ccSmrg	  darwin)
947388de56ccSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
947488de56ccSmrg	    # problems, so we reset it completely
947588de56ccSmrg	    verstring=
947688de56ccSmrg	    ;;
947788de56ccSmrg	  *)
9478862bcd1aSmrg	    verstring=0.0
947988de56ccSmrg	    ;;
948088de56ccSmrg	  esac
9481862bcd1aSmrg	  if test no = "$need_version"; then
948288de56ccSmrg	    versuffix=
948388de56ccSmrg	  else
9484862bcd1aSmrg	    versuffix=.0.0
948588de56ccSmrg	  fi
948688de56ccSmrg	fi
948788de56ccSmrg
948888de56ccSmrg	# Remove version info from name if versioning should be avoided
9489862bcd1aSmrg	if test yes,no = "$avoid_version,$need_version"; then
949088de56ccSmrg	  major=
949188de56ccSmrg	  versuffix=
9492862bcd1aSmrg	  verstring=
949388de56ccSmrg	fi
949488de56ccSmrg
949588de56ccSmrg	# Check to see if the archive will have undefined symbols.
9496862bcd1aSmrg	if test yes = "$allow_undefined"; then
9497862bcd1aSmrg	  if test unsupported = "$allow_undefined_flag"; then
9498862bcd1aSmrg	    if test yes = "$build_old_libs"; then
9499862bcd1aSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9500862bcd1aSmrg	      build_libtool_libs=no
9501862bcd1aSmrg	    else
9502862bcd1aSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9503862bcd1aSmrg	    fi
950488de56ccSmrg	  fi
950588de56ccSmrg	else
950688de56ccSmrg	  # Don't allow undefined symbols.
9507862bcd1aSmrg	  allow_undefined_flag=$no_undefined_flag
950888de56ccSmrg	fi
950988de56ccSmrg
951088de56ccSmrg      fi
951188de56ccSmrg
9512862bcd1aSmrg      func_generate_dlsyms "$libname" "$libname" :
9513e9fcaa8aSmrg      func_append libobjs " $symfileobj"
9514862bcd1aSmrg      test " " = "$libobjs" && libobjs=
951588de56ccSmrg
9516862bcd1aSmrg      if test relink != "$opt_mode"; then
951788de56ccSmrg	# Remove our outputs, but don't remove object files since they
951888de56ccSmrg	# may have been created when compiling PIC objects.
951988de56ccSmrg	removelist=
952088de56ccSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
952188de56ccSmrg	for p in $tempremovelist; do
952288de56ccSmrg	  case $p in
952388de56ccSmrg	    *.$objext | *.gcno)
952488de56ccSmrg	       ;;
9525862bcd1aSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9526862bcd1aSmrg	       if test -n "$precious_files_regex"; then
952788de56ccSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
952888de56ccSmrg		 then
952988de56ccSmrg		   continue
953088de56ccSmrg		 fi
953188de56ccSmrg	       fi
9532e9fcaa8aSmrg	       func_append removelist " $p"
953388de56ccSmrg	       ;;
953488de56ccSmrg	    *) ;;
953588de56ccSmrg	  esac
953688de56ccSmrg	done
953788de56ccSmrg	test -n "$removelist" && \
953888de56ccSmrg	  func_show_eval "${RM}r \$removelist"
953988de56ccSmrg      fi
954088de56ccSmrg
954188de56ccSmrg      # Now set the variables for building old libraries.
9542862bcd1aSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9543e9fcaa8aSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
954488de56ccSmrg
954588de56ccSmrg	# Transform .lo files to .o files.
9546862bcd1aSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
954788de56ccSmrg      fi
954888de56ccSmrg
954988de56ccSmrg      # Eliminate all temporary directories.
955088de56ccSmrg      #for path in $notinst_path; do
9551e9fcaa8aSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9552e9fcaa8aSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9553e9fcaa8aSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
955488de56ccSmrg      #done
955588de56ccSmrg
955688de56ccSmrg      if test -n "$xrpath"; then
955788de56ccSmrg	# If the user specified any rpath flags, then add them.
955888de56ccSmrg	temp_xrpath=
955988de56ccSmrg	for libdir in $xrpath; do
9560e9fcaa8aSmrg	  func_replace_sysroot "$libdir"
9561e9fcaa8aSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
956288de56ccSmrg	  case "$finalize_rpath " in
956388de56ccSmrg	  *" $libdir "*) ;;
9564e9fcaa8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
956588de56ccSmrg	  esac
956688de56ccSmrg	done
9567862bcd1aSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
956888de56ccSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
956988de56ccSmrg	fi
957088de56ccSmrg      fi
957188de56ccSmrg
957288de56ccSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9573862bcd1aSmrg      old_dlfiles=$dlfiles
957488de56ccSmrg      dlfiles=
957588de56ccSmrg      for lib in $old_dlfiles; do
957688de56ccSmrg	case " $dlprefiles $dlfiles " in
957788de56ccSmrg	*" $lib "*) ;;
9578e9fcaa8aSmrg	*) func_append dlfiles " $lib" ;;
957988de56ccSmrg	esac
958088de56ccSmrg      done
958188de56ccSmrg
958288de56ccSmrg      # Make sure dlprefiles contains only unique files
9583862bcd1aSmrg      old_dlprefiles=$dlprefiles
958488de56ccSmrg      dlprefiles=
958588de56ccSmrg      for lib in $old_dlprefiles; do
958688de56ccSmrg	case "$dlprefiles " in
958788de56ccSmrg	*" $lib "*) ;;
9588e9fcaa8aSmrg	*) func_append dlprefiles " $lib" ;;
958988de56ccSmrg	esac
959088de56ccSmrg      done
959188de56ccSmrg
9592862bcd1aSmrg      if test yes = "$build_libtool_libs"; then
959388de56ccSmrg	if test -n "$rpath"; then
959488de56ccSmrg	  case $host in
959507fb9b8fSmrg	  *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
959688de56ccSmrg	    # these systems don't actually have a c library (as such)!
959788de56ccSmrg	    ;;
959888de56ccSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
959988de56ccSmrg	    # Rhapsody C library is in the System framework
9600e9fcaa8aSmrg	    func_append deplibs " System.ltframework"
960188de56ccSmrg	    ;;
960288de56ccSmrg	  *-*-netbsd*)
960388de56ccSmrg	    # Don't link with libc until the a.out ld.so is fixed.
960488de56ccSmrg	    ;;
96057d2c738bSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
960688de56ccSmrg	    # Do not include libc due to us having libc/libc_r.
960788de56ccSmrg	    ;;
960888de56ccSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
960988de56ccSmrg	    # Causes problems with __ctype
961088de56ccSmrg	    ;;
961188de56ccSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
961288de56ccSmrg	    # Compiler inserts libc in the correct place for threads to work
961388de56ccSmrg	    ;;
961488de56ccSmrg	  *)
961588de56ccSmrg	    # Add libc to deplibs on all other systems if necessary.
9616862bcd1aSmrg	    if test yes = "$build_libtool_need_lc"; then
9617e9fcaa8aSmrg	      func_append deplibs " -lc"
961888de56ccSmrg	    fi
961988de56ccSmrg	    ;;
962088de56ccSmrg	  esac
962188de56ccSmrg	fi
962288de56ccSmrg
962388de56ccSmrg	# Transform deplibs into only deplibs that can be linked in shared.
962488de56ccSmrg	name_save=$name
962588de56ccSmrg	libname_save=$libname
962688de56ccSmrg	release_save=$release
962788de56ccSmrg	versuffix_save=$versuffix
962888de56ccSmrg	major_save=$major
962988de56ccSmrg	# I'm not sure if I'm treating the release correctly.  I think
963088de56ccSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
963188de56ccSmrg	# add it in twice.  Is that correct?
9632862bcd1aSmrg	release=
9633862bcd1aSmrg	versuffix=
9634862bcd1aSmrg	major=
963588de56ccSmrg	newdeplibs=
963688de56ccSmrg	droppeddeps=no
963788de56ccSmrg	case $deplibs_check_method in
963888de56ccSmrg	pass_all)
963988de56ccSmrg	  # Don't check for shared/static.  Everything works.
964088de56ccSmrg	  # This might be a little naive.  We might want to check
964188de56ccSmrg	  # whether the library exists or not.  But this is on
964288de56ccSmrg	  # osf3 & osf4 and I'm not really sure... Just
964388de56ccSmrg	  # implementing what was already the behavior.
964488de56ccSmrg	  newdeplibs=$deplibs
964588de56ccSmrg	  ;;
964688de56ccSmrg	file_magic*)
964788de56ccSmrg	  set dummy $deplibs_check_method; shift
964888de56ccSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
964988de56ccSmrg	  for a_deplib in $deplibs; do
965088de56ccSmrg	    case $a_deplib in
965188de56ccSmrg	    -l*)
965288de56ccSmrg	      func_stripname -l '' "$a_deplib"
965388de56ccSmrg	      name=$func_stripname_result
9654862bcd1aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
965588de56ccSmrg		case " $predeps $postdeps " in
965688de56ccSmrg		*" $a_deplib "*)
9657e9fcaa8aSmrg		  func_append newdeplibs " $a_deplib"
9658862bcd1aSmrg		  a_deplib=
965988de56ccSmrg		  ;;
966088de56ccSmrg		esac
966188de56ccSmrg	      fi
9662862bcd1aSmrg	      if test -n "$a_deplib"; then
966388de56ccSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9664e9fcaa8aSmrg		if test -n "$file_magic_glob"; then
9665e9fcaa8aSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9666e9fcaa8aSmrg		else
9667e9fcaa8aSmrg		  libnameglob=$libname
9668e9fcaa8aSmrg		fi
9669862bcd1aSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
967088de56ccSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9671862bcd1aSmrg		  if test yes = "$want_nocaseglob"; then
9672e9fcaa8aSmrg		    shopt -s nocaseglob
9673e9fcaa8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9674e9fcaa8aSmrg		    $nocaseglob
9675e9fcaa8aSmrg		  else
9676e9fcaa8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9677e9fcaa8aSmrg		  fi
967888de56ccSmrg		  for potent_lib in $potential_libs; do
967988de56ccSmrg		      # Follow soft links.
968088de56ccSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
968188de56ccSmrg			 $GREP " -> " >/dev/null; then
968288de56ccSmrg			continue
968388de56ccSmrg		      fi
968488de56ccSmrg		      # The statement above tries to avoid entering an
968588de56ccSmrg		      # endless loop below, in case of cyclic links.
968688de56ccSmrg		      # We might still enter an endless loop, since a link
968788de56ccSmrg		      # loop can be closed while we follow links,
968888de56ccSmrg		      # but so what?
9689862bcd1aSmrg		      potlib=$potent_lib
969088de56ccSmrg		      while test -h "$potlib" 2>/dev/null; do
9691862bcd1aSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
969288de56ccSmrg			case $potliblink in
9693862bcd1aSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9694862bcd1aSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
969588de56ccSmrg			esac
969688de56ccSmrg		      done
969788de56ccSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
969888de56ccSmrg			 $SED -e 10q |
969988de56ccSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
9700e9fcaa8aSmrg			func_append newdeplibs " $a_deplib"
9701862bcd1aSmrg			a_deplib=
970288de56ccSmrg			break 2
970388de56ccSmrg		      fi
970488de56ccSmrg		  done
970588de56ccSmrg		done
970688de56ccSmrg	      fi
9707862bcd1aSmrg	      if test -n "$a_deplib"; then
970888de56ccSmrg		droppeddeps=yes
970907fb9b8fSmrg		func_warning "Linker path does not have real file for library $a_deplib."
971007fb9b8fSmrg		func_warning "I have the capability to make that library automatically link in when"
971107fb9b8fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
971207fb9b8fSmrg		func_warning "shared version of the library, which you do not appear to have"
971307fb9b8fSmrg		func_warning "because I did check the linker path looking for a file starting"
9714862bcd1aSmrg		if test -z "$potlib"; then
971507fb9b8fSmrg		  func_warning "with $libname but no candidates were found. (...for file magic test)"
971688de56ccSmrg		else
971707fb9b8fSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
971807fb9b8fSmrg		  func_warning "using a file magic. Last file checked: $potlib"
971988de56ccSmrg		fi
972088de56ccSmrg	      fi
972188de56ccSmrg	      ;;
972288de56ccSmrg	    *)
972388de56ccSmrg	      # Add a -L argument.
9724e9fcaa8aSmrg	      func_append newdeplibs " $a_deplib"
972588de56ccSmrg	      ;;
972688de56ccSmrg	    esac
972788de56ccSmrg	  done # Gone through all deplibs.
972888de56ccSmrg	  ;;
972988de56ccSmrg	match_pattern*)
973088de56ccSmrg	  set dummy $deplibs_check_method; shift
973188de56ccSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
973288de56ccSmrg	  for a_deplib in $deplibs; do
973388de56ccSmrg	    case $a_deplib in
973488de56ccSmrg	    -l*)
973588de56ccSmrg	      func_stripname -l '' "$a_deplib"
973688de56ccSmrg	      name=$func_stripname_result
9737862bcd1aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
973888de56ccSmrg		case " $predeps $postdeps " in
973988de56ccSmrg		*" $a_deplib "*)
9740e9fcaa8aSmrg		  func_append newdeplibs " $a_deplib"
9741862bcd1aSmrg		  a_deplib=
974288de56ccSmrg		  ;;
974388de56ccSmrg		esac
974488de56ccSmrg	      fi
9745862bcd1aSmrg	      if test -n "$a_deplib"; then
974688de56ccSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
974788de56ccSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
974888de56ccSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
974988de56ccSmrg		  for potent_lib in $potential_libs; do
9750862bcd1aSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9751e9fcaa8aSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
975288de56ccSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9753e9fcaa8aSmrg		      func_append newdeplibs " $a_deplib"
9754862bcd1aSmrg		      a_deplib=
975588de56ccSmrg		      break 2
975688de56ccSmrg		    fi
975788de56ccSmrg		  done
975888de56ccSmrg		done
975988de56ccSmrg	      fi
9760862bcd1aSmrg	      if test -n "$a_deplib"; then
976188de56ccSmrg		droppeddeps=yes
976207fb9b8fSmrg		func_warning "Linker path does not have real file for library $a_deplib."
976307fb9b8fSmrg		func_warning "I have the capability to make that library automatically link in when"
976407fb9b8fSmrg		func_warning "you link to this library.  But I can only do this if you have a"
976507fb9b8fSmrg		func_warning "shared version of the library, which you do not appear to have"
976607fb9b8fSmrg		func_warning "because I did check the linker path looking for a file starting"
9767862bcd1aSmrg		if test -z "$potlib"; then
976807fb9b8fSmrg		  func_warning "with $libname but no candidates were found. (...for regex pattern test)"
976988de56ccSmrg		else
977007fb9b8fSmrg		  func_warning "with $libname and none of the candidates passed a file format test"
977107fb9b8fSmrg		  func_warning "using a regex pattern. Last file checked: $potlib"
977288de56ccSmrg		fi
977388de56ccSmrg	      fi
977488de56ccSmrg	      ;;
977588de56ccSmrg	    *)
977688de56ccSmrg	      # Add a -L argument.
9777e9fcaa8aSmrg	      func_append newdeplibs " $a_deplib"
977888de56ccSmrg	      ;;
977988de56ccSmrg	    esac
978088de56ccSmrg	  done # Gone through all deplibs.
978188de56ccSmrg	  ;;
978288de56ccSmrg	none | unknown | *)
9783862bcd1aSmrg	  newdeplibs=
9784e9fcaa8aSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9785862bcd1aSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9786862bcd1aSmrg	    for i in $predeps $postdeps; do
978788de56ccSmrg	      # can't use Xsed below, because $i might contain '/'
9788862bcd1aSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
978988de56ccSmrg	    done
979088de56ccSmrg	  fi
9791e9fcaa8aSmrg	  case $tmp_deplibs in
9792e9fcaa8aSmrg	  *[!\	\ ]*)
9793e9fcaa8aSmrg	    echo
9794862bcd1aSmrg	    if test none = "$deplibs_check_method"; then
979507fb9b8fSmrg	      func_warning "Inter-library dependencies are not supported in this platform."
979688de56ccSmrg	    else
979707fb9b8fSmrg	      func_warning "Inter-library dependencies are not known to be supported."
979888de56ccSmrg	    fi
979907fb9b8fSmrg	    func_warning "All declared inter-library dependencies are being dropped."
980088de56ccSmrg	    droppeddeps=yes
9801e9fcaa8aSmrg	    ;;
9802e9fcaa8aSmrg	  esac
980388de56ccSmrg	  ;;
980488de56ccSmrg	esac
980588de56ccSmrg	versuffix=$versuffix_save
980688de56ccSmrg	major=$major_save
980788de56ccSmrg	release=$release_save
980888de56ccSmrg	libname=$libname_save
980988de56ccSmrg	name=$name_save
981088de56ccSmrg
981188de56ccSmrg	case $host in
981288de56ccSmrg	*-*-rhapsody* | *-*-darwin1.[012])
981388de56ccSmrg	  # On Rhapsody replace the C library with the System framework
9814e9fcaa8aSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
981588de56ccSmrg	  ;;
981688de56ccSmrg	esac
981788de56ccSmrg
9818862bcd1aSmrg	if test yes = "$droppeddeps"; then
9819862bcd1aSmrg	  if test yes = "$module"; then
982007fb9b8fSmrg	    func_warning "libtool could not satisfy all declared inter-library"
982107fb9b8fSmrg	    func_warning "dependencies of module $libname.  Therefore, libtool will create"
982207fb9b8fSmrg	    func_warning "a static module, that should work as long as the dlopening"
982307fb9b8fSmrg	    func_warning "application is linked with the -dlopen flag."
982488de56ccSmrg	    if test -z "$global_symbol_pipe"; then
982507fb9b8fSmrg	      func_warning "However, this would only work if libtool was able to extract symbol"
982607fb9b8fSmrg	      func_warning "lists from a program, using 'nm' or equivalent, but libtool could"
982707fb9b8fSmrg	      func_warning "not find such a program.  So, this module is probably useless."
982807fb9b8fSmrg	      func_warning "'nm' from GNU binutils and a full rebuild may help."
982988de56ccSmrg	    fi
9830862bcd1aSmrg	    if test no = "$build_old_libs"; then
9831862bcd1aSmrg	      oldlibs=$output_objdir/$libname.$libext
983288de56ccSmrg	      build_libtool_libs=module
983388de56ccSmrg	      build_old_libs=yes
983488de56ccSmrg	    else
983588de56ccSmrg	      build_libtool_libs=no
983688de56ccSmrg	    fi
983788de56ccSmrg	  else
9838e9fcaa8aSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9839e9fcaa8aSmrg	    echo "*** automatically added whenever a program is linked with this library"
9840e9fcaa8aSmrg	    echo "*** or is declared to -dlopen it."
984188de56ccSmrg
9842862bcd1aSmrg	    if test no = "$allow_undefined"; then
9843e9fcaa8aSmrg	      echo
9844e9fcaa8aSmrg	      echo "*** Since this library must not contain undefined symbols,"
9845e9fcaa8aSmrg	      echo "*** because either the platform does not support them or"
9846e9fcaa8aSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9847e9fcaa8aSmrg	      echo "*** libtool will only create a static version of it."
9848862bcd1aSmrg	      if test no = "$build_old_libs"; then
9849862bcd1aSmrg		oldlibs=$output_objdir/$libname.$libext
985088de56ccSmrg		build_libtool_libs=module
985188de56ccSmrg		build_old_libs=yes
985288de56ccSmrg	      else
985388de56ccSmrg		build_libtool_libs=no
985488de56ccSmrg	      fi
985588de56ccSmrg	    fi
985688de56ccSmrg	  fi
985788de56ccSmrg	fi
985888de56ccSmrg	# Done checking deplibs!
985988de56ccSmrg	deplibs=$newdeplibs
986088de56ccSmrg      fi
986188de56ccSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
986288de56ccSmrg      case $host in
986388de56ccSmrg	*-*-darwin*)
9864e9fcaa8aSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9865e9fcaa8aSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9866e9fcaa8aSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
986788de56ccSmrg	  ;;
986888de56ccSmrg      esac
986988de56ccSmrg
987088de56ccSmrg      # move library search paths that coincide with paths to not yet
987188de56ccSmrg      # installed libraries to the beginning of the library search list
987288de56ccSmrg      new_libs=
987388de56ccSmrg      for path in $notinst_path; do
987488de56ccSmrg	case " $new_libs " in
987588de56ccSmrg	*" -L$path/$objdir "*) ;;
987688de56ccSmrg	*)
987788de56ccSmrg	  case " $deplibs " in
987888de56ccSmrg	  *" -L$path/$objdir "*)
9879e9fcaa8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
988088de56ccSmrg	  esac
988188de56ccSmrg	  ;;
988288de56ccSmrg	esac
988388de56ccSmrg      done
988488de56ccSmrg      for deplib in $deplibs; do
988588de56ccSmrg	case $deplib in
988688de56ccSmrg	-L*)
988788de56ccSmrg	  case " $new_libs " in
988888de56ccSmrg	  *" $deplib "*) ;;
9889e9fcaa8aSmrg	  *) func_append new_libs " $deplib" ;;
989088de56ccSmrg	  esac
989188de56ccSmrg	  ;;
9892e9fcaa8aSmrg	*) func_append new_libs " $deplib" ;;
989388de56ccSmrg	esac
989488de56ccSmrg      done
9895862bcd1aSmrg      deplibs=$new_libs
989688de56ccSmrg
989788de56ccSmrg      # All the library-specific variables (install_libdir is set above).
989888de56ccSmrg      library_names=
989988de56ccSmrg      old_library=
990088de56ccSmrg      dlname=
990188de56ccSmrg
990288de56ccSmrg      # Test again, we may have decided not to build it any more
9903862bcd1aSmrg      if test yes = "$build_libtool_libs"; then
9904862bcd1aSmrg	# Remove $wl instances when linking with ld.
9905eb411b4bSmrg	# FIXME: should test the right _cmds variable.
9906eb411b4bSmrg	case $archive_cmds in
9907eb411b4bSmrg	  *\$LD\ *) wl= ;;
9908eb411b4bSmrg        esac
9909862bcd1aSmrg	if test yes = "$hardcode_into_libs"; then
991088de56ccSmrg	  # Hardcode the library paths
991188de56ccSmrg	  hardcode_libdirs=
991288de56ccSmrg	  dep_rpath=
9913862bcd1aSmrg	  rpath=$finalize_rpath
9914862bcd1aSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
991588de56ccSmrg	  for libdir in $rpath; do
991688de56ccSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
991788de56ccSmrg	      if test -n "$hardcode_libdir_separator"; then
9918e9fcaa8aSmrg		func_replace_sysroot "$libdir"
9919e9fcaa8aSmrg		libdir=$func_replace_sysroot_result
992088de56ccSmrg		if test -z "$hardcode_libdirs"; then
9921862bcd1aSmrg		  hardcode_libdirs=$libdir
992288de56ccSmrg		else
992388de56ccSmrg		  # Just accumulate the unique libdirs.
992488de56ccSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
992588de56ccSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
992688de56ccSmrg		    ;;
992788de56ccSmrg		  *)
9928e9fcaa8aSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
992988de56ccSmrg		    ;;
993088de56ccSmrg		  esac
993188de56ccSmrg		fi
993288de56ccSmrg	      else
993388de56ccSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
9934e9fcaa8aSmrg		func_append dep_rpath " $flag"
993588de56ccSmrg	      fi
993688de56ccSmrg	    elif test -n "$runpath_var"; then
993788de56ccSmrg	      case "$perm_rpath " in
993888de56ccSmrg	      *" $libdir "*) ;;
9939eb411b4bSmrg	      *) func_append perm_rpath " $libdir" ;;
994088de56ccSmrg	      esac
994188de56ccSmrg	    fi
994288de56ccSmrg	  done
994388de56ccSmrg	  # Substitute the hardcoded libdirs into the rpath.
994488de56ccSmrg	  if test -n "$hardcode_libdir_separator" &&
994588de56ccSmrg	     test -n "$hardcode_libdirs"; then
9946862bcd1aSmrg	    libdir=$hardcode_libdirs
9947eb411b4bSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
994888de56ccSmrg	  fi
994988de56ccSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
995088de56ccSmrg	    # We should set the runpath_var.
995188de56ccSmrg	    rpath=
995288de56ccSmrg	    for dir in $perm_rpath; do
9953e9fcaa8aSmrg	      func_append rpath "$dir:"
995488de56ccSmrg	    done
995588de56ccSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
995688de56ccSmrg	  fi
995788de56ccSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
995888de56ccSmrg	fi
99591ab64890Smrg
9960862bcd1aSmrg	shlibpath=$finalize_shlibpath
9961862bcd1aSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
996288de56ccSmrg	if test -n "$shlibpath"; then
996388de56ccSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
996488de56ccSmrg	fi
99651ab64890Smrg
996688de56ccSmrg	# Get the real and link names of the library.
996788de56ccSmrg	eval shared_ext=\"$shrext_cmds\"
996888de56ccSmrg	eval library_names=\"$library_names_spec\"
996988de56ccSmrg	set dummy $library_names
997088de56ccSmrg	shift
9971862bcd1aSmrg	realname=$1
997288de56ccSmrg	shift
99731ab64890Smrg
997488de56ccSmrg	if test -n "$soname_spec"; then
997588de56ccSmrg	  eval soname=\"$soname_spec\"
997688de56ccSmrg	else
9977862bcd1aSmrg	  soname=$realname
997888de56ccSmrg	fi
997988de56ccSmrg	if test -z "$dlname"; then
998088de56ccSmrg	  dlname=$soname
998188de56ccSmrg	fi
99821ab64890Smrg
9983862bcd1aSmrg	lib=$output_objdir/$realname
998488de56ccSmrg	linknames=
998588de56ccSmrg	for link
998688de56ccSmrg	do
9987e9fcaa8aSmrg	  func_append linknames " $link"
998888de56ccSmrg	done
99891ab64890Smrg
999088de56ccSmrg	# Use standard objects if they are pic
9991e9fcaa8aSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
999288de56ccSmrg	test "X$libobjs" = "X " && libobjs=
99931ab64890Smrg
999488de56ccSmrg	delfiles=
999588de56ccSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
999688de56ccSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9997862bcd1aSmrg	  export_symbols=$output_objdir/$libname.uexp
9998e9fcaa8aSmrg	  func_append delfiles " $export_symbols"
999988de56ccSmrg	fi
100001ab64890Smrg
1000188de56ccSmrg	orig_export_symbols=
1000288de56ccSmrg	case $host_os in
1000307fb9b8fSmrg	cygwin* | mingw* | windows* | cegcc*)
1000488de56ccSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
1000588de56ccSmrg	    # exporting using user supplied symfile
10006862bcd1aSmrg	    func_dll_def_p "$export_symbols" || {
1000788de56ccSmrg	      # and it's NOT already a .def file. Must figure out
1000888de56ccSmrg	      # which of the given symbols are data symbols and tag
1000988de56ccSmrg	      # them as such. So, trigger use of export_symbols_cmds.
1001088de56ccSmrg	      # export_symbols gets reassigned inside the "prepare
1001188de56ccSmrg	      # the list of exported symbols" if statement, so the
1001288de56ccSmrg	      # include_expsyms logic still works.
10013862bcd1aSmrg	      orig_export_symbols=$export_symbols
1001488de56ccSmrg	      export_symbols=
1001588de56ccSmrg	      always_export_symbols=yes
10016862bcd1aSmrg	    }
1001788de56ccSmrg	  fi
1001888de56ccSmrg	  ;;
1001988de56ccSmrg	esac
100201ab64890Smrg
1002188de56ccSmrg	# Prepare the list of exported symbols
1002288de56ccSmrg	if test -z "$export_symbols"; then
10023862bcd1aSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
10024862bcd1aSmrg	    func_verbose "generating symbol list for '$libname.la'"
10025862bcd1aSmrg	    export_symbols=$output_objdir/$libname.exp
1002688de56ccSmrg	    $opt_dry_run || $RM $export_symbols
1002788de56ccSmrg	    cmds=$export_symbols_cmds
10028862bcd1aSmrg	    save_ifs=$IFS; IFS='~'
10029e9fcaa8aSmrg	    for cmd1 in $cmds; do
10030862bcd1aSmrg	      IFS=$save_ifs
10031e9fcaa8aSmrg	      # Take the normal branch if the nm_file_list_spec branch
10032e9fcaa8aSmrg	      # doesn't work or if tool conversion is not needed.
10033e9fcaa8aSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
10034e9fcaa8aSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
10035e9fcaa8aSmrg		  try_normal_branch=yes
10036e9fcaa8aSmrg		  eval cmd=\"$cmd1\"
10037e9fcaa8aSmrg		  func_len " $cmd"
10038e9fcaa8aSmrg		  len=$func_len_result
10039e9fcaa8aSmrg		  ;;
10040e9fcaa8aSmrg		*)
10041e9fcaa8aSmrg		  try_normal_branch=no
10042e9fcaa8aSmrg		  ;;
10043e9fcaa8aSmrg	      esac
10044862bcd1aSmrg	      if test yes = "$try_normal_branch" \
10045e9fcaa8aSmrg		 && { test "$len" -lt "$max_cmd_len" \
10046e9fcaa8aSmrg		      || test "$max_cmd_len" -le -1; }
10047e9fcaa8aSmrg	      then
10048e9fcaa8aSmrg		func_show_eval "$cmd" 'exit $?'
10049e9fcaa8aSmrg		skipped_export=false
10050e9fcaa8aSmrg	      elif test -n "$nm_file_list_spec"; then
10051e9fcaa8aSmrg		func_basename "$output"
10052e9fcaa8aSmrg		output_la=$func_basename_result
10053e9fcaa8aSmrg		save_libobjs=$libobjs
10054e9fcaa8aSmrg		save_output=$output
10055862bcd1aSmrg		output=$output_objdir/$output_la.nm
10056e9fcaa8aSmrg		func_to_tool_file "$output"
10057e9fcaa8aSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
10058e9fcaa8aSmrg		func_append delfiles " $output"
10059e9fcaa8aSmrg		func_verbose "creating $NM input file list: $output"
10060e9fcaa8aSmrg		for obj in $save_libobjs; do
10061e9fcaa8aSmrg		  func_to_tool_file "$obj"
10062e9fcaa8aSmrg		  $ECHO "$func_to_tool_file_result"
10063e9fcaa8aSmrg		done > "$output"
10064e9fcaa8aSmrg		eval cmd=\"$cmd1\"
1006588de56ccSmrg		func_show_eval "$cmd" 'exit $?'
10066e9fcaa8aSmrg		output=$save_output
10067e9fcaa8aSmrg		libobjs=$save_libobjs
1006888de56ccSmrg		skipped_export=false
1006988de56ccSmrg	      else
1007088de56ccSmrg		# The command line is too long to execute in one step.
1007188de56ccSmrg		func_verbose "using reloadable object file for export list..."
1007288de56ccSmrg		skipped_export=:
1007388de56ccSmrg		# Break out early, otherwise skipped_export may be
1007488de56ccSmrg		# set to false by a later but shorter cmd.
1007588de56ccSmrg		break
1007688de56ccSmrg	      fi
1007788de56ccSmrg	    done
10078862bcd1aSmrg	    IFS=$save_ifs
10079862bcd1aSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
1008088de56ccSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
1008188de56ccSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
1008288de56ccSmrg	    fi
1008388de56ccSmrg	  fi
100841ab64890Smrg	fi
100851ab64890Smrg
1008688de56ccSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
10087862bcd1aSmrg	  tmp_export_symbols=$export_symbols
10088862bcd1aSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10089e9fcaa8aSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1009088de56ccSmrg	fi
100911ab64890Smrg
10092862bcd1aSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
1009388de56ccSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10094862bcd1aSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1009588de56ccSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10096862bcd1aSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
1009788de56ccSmrg	  # though. Also, the filter scales superlinearly with the number of
1009888de56ccSmrg	  # global variables. join(1) would be nice here, but unfortunately
1009988de56ccSmrg	  # isn't a blessed tool.
1010088de56ccSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10101e9fcaa8aSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1010288de56ccSmrg	  export_symbols=$output_objdir/$libname.def
1010388de56ccSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1010488de56ccSmrg	fi
101051ab64890Smrg
1010688de56ccSmrg	tmp_deplibs=
1010788de56ccSmrg	for test_deplib in $deplibs; do
1010888de56ccSmrg	  case " $convenience " in
1010988de56ccSmrg	  *" $test_deplib "*) ;;
1011088de56ccSmrg	  *)
10111e9fcaa8aSmrg	    func_append tmp_deplibs " $test_deplib"
1011288de56ccSmrg	    ;;
1011388de56ccSmrg	  esac
1011488de56ccSmrg	done
10115862bcd1aSmrg	deplibs=$tmp_deplibs
101161ab64890Smrg
1011788de56ccSmrg	if test -n "$convenience"; then
1011888de56ccSmrg	  if test -n "$whole_archive_flag_spec" &&
10119862bcd1aSmrg	    test yes = "$compiler_needs_object" &&
1012088de56ccSmrg	    test -z "$libobjs"; then
1012188de56ccSmrg	    # extract the archives, so we have objects to list.
1012288de56ccSmrg	    # TODO: could optimize this to just extract one archive.
1012388de56ccSmrg	    whole_archive_flag_spec=
1012488de56ccSmrg	  fi
1012588de56ccSmrg	  if test -n "$whole_archive_flag_spec"; then
1012688de56ccSmrg	    save_libobjs=$libobjs
1012788de56ccSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1012888de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1012988de56ccSmrg	  else
10130862bcd1aSmrg	    gentop=$output_objdir/${outputname}x
10131e9fcaa8aSmrg	    func_append generated " $gentop"
101321ab64890Smrg
1013388de56ccSmrg	    func_extract_archives $gentop $convenience
10134e9fcaa8aSmrg	    func_append libobjs " $func_extract_archives_result"
1013588de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1013688de56ccSmrg	  fi
10137b4ee4795Smrg	fi
101381ab64890Smrg
10139862bcd1aSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
1014088de56ccSmrg	  eval flag=\"$thread_safe_flag_spec\"
10141e9fcaa8aSmrg	  func_append linker_flags " $flag"
10142b4ee4795Smrg	fi
101432e9c7c8cSmrg
1014488de56ccSmrg	# Make a backup of the uninstalled library when relinking
10145862bcd1aSmrg	if test relink = "$opt_mode"; then
1014688de56ccSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
1014788de56ccSmrg	fi
101481ab64890Smrg
1014988de56ccSmrg	# Do each of the archive commands.
10150862bcd1aSmrg	if test yes = "$module" && test -n "$module_cmds"; then
1015188de56ccSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1015288de56ccSmrg	    eval test_cmds=\"$module_expsym_cmds\"
1015388de56ccSmrg	    cmds=$module_expsym_cmds
1015488de56ccSmrg	  else
1015588de56ccSmrg	    eval test_cmds=\"$module_cmds\"
1015688de56ccSmrg	    cmds=$module_cmds
1015788de56ccSmrg	  fi
10158b4ee4795Smrg	else
1015988de56ccSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1016088de56ccSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
1016188de56ccSmrg	    cmds=$archive_expsym_cmds
1016288de56ccSmrg	  else
1016388de56ccSmrg	    eval test_cmds=\"$archive_cmds\"
1016488de56ccSmrg	    cmds=$archive_cmds
1016588de56ccSmrg	  fi
10166b4ee4795Smrg	fi
101671ab64890Smrg
10168862bcd1aSmrg	if test : != "$skipped_export" &&
1016988de56ccSmrg	   func_len " $test_cmds" &&
1017088de56ccSmrg	   len=$func_len_result &&
1017188de56ccSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1017288de56ccSmrg	  :
1017388de56ccSmrg	else
1017488de56ccSmrg	  # The command line is too long to link in one step, link piecewise
1017588de56ccSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
1017688de56ccSmrg	  # script.
101771ab64890Smrg
1017888de56ccSmrg	  # Save the value of $output and $libobjs because we want to
1017988de56ccSmrg	  # use them later.  If we have whole_archive_flag_spec, we
1018088de56ccSmrg	  # want to use save_libobjs as it was before
1018188de56ccSmrg	  # whole_archive_flag_spec was expanded, because we can't
1018288de56ccSmrg	  # assume the linker understands whole_archive_flag_spec.
1018388de56ccSmrg	  # This may have to be revisited, in case too many
1018488de56ccSmrg	  # convenience libraries get linked in and end up exceeding
1018588de56ccSmrg	  # the spec.
1018688de56ccSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
1018788de56ccSmrg	    save_libobjs=$libobjs
1018888de56ccSmrg	  fi
1018988de56ccSmrg	  save_output=$output
10190e9fcaa8aSmrg	  func_basename "$output"
10191e9fcaa8aSmrg	  output_la=$func_basename_result
101921ab64890Smrg
1019388de56ccSmrg	  # Clear the reloadable object creation command queue and
1019488de56ccSmrg	  # initialize k to one.
1019588de56ccSmrg	  test_cmds=
1019688de56ccSmrg	  concat_cmds=
1019788de56ccSmrg	  objlist=
1019888de56ccSmrg	  last_robj=
1019988de56ccSmrg	  k=1
1020088de56ccSmrg
1020107fb9b8fSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10202862bcd1aSmrg	    output=$output_objdir/$output_la.lnk
1020388de56ccSmrg	    func_verbose "creating linker input file list: $output"
1020488de56ccSmrg	    : > $output
1020588de56ccSmrg	    set x $save_libobjs
1020688de56ccSmrg	    shift
1020788de56ccSmrg	    firstobj=
10208862bcd1aSmrg	    if test yes = "$compiler_needs_object"; then
1020988de56ccSmrg	      firstobj="$1 "
1021088de56ccSmrg	      shift
1021188de56ccSmrg	    fi
1021288de56ccSmrg	    for obj
1021388de56ccSmrg	    do
10214e9fcaa8aSmrg	      func_to_tool_file "$obj"
10215e9fcaa8aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
1021688de56ccSmrg	    done
10217e9fcaa8aSmrg	    func_append delfiles " $output"
10218e9fcaa8aSmrg	    func_to_tool_file "$output"
10219e9fcaa8aSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
1022007fb9b8fSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
1022107fb9b8fSmrg	    output=$output_objdir/$output_la.lnkscript
1022207fb9b8fSmrg	    func_verbose "creating GNU ld script: $output"
1022307fb9b8fSmrg	    echo 'INPUT (' > $output
1022407fb9b8fSmrg	    for obj in $save_libobjs
1022507fb9b8fSmrg	    do
1022607fb9b8fSmrg	      func_to_tool_file "$obj"
1022707fb9b8fSmrg	      $ECHO "$func_to_tool_file_result" >> $output
1022807fb9b8fSmrg	    done
1022907fb9b8fSmrg	    echo ')' >> $output
1023007fb9b8fSmrg	    func_append delfiles " $output"
1023107fb9b8fSmrg	    func_to_tool_file "$output"
1023207fb9b8fSmrg	    output=$func_to_tool_file_result
1023388de56ccSmrg	  else
1023488de56ccSmrg	    if test -n "$save_libobjs"; then
1023588de56ccSmrg	      func_verbose "creating reloadable object files..."
10236862bcd1aSmrg	      output=$output_objdir/$output_la-$k.$objext
1023788de56ccSmrg	      eval test_cmds=\"$reload_cmds\"
1023888de56ccSmrg	      func_len " $test_cmds"
1023988de56ccSmrg	      len0=$func_len_result
1024088de56ccSmrg	      len=$len0
1024188de56ccSmrg
1024288de56ccSmrg	      # Loop over the list of objects to be linked.
1024388de56ccSmrg	      for obj in $save_libobjs
1024488de56ccSmrg	      do
1024588de56ccSmrg		func_len " $obj"
1024688de56ccSmrg		func_arith $len + $func_len_result
1024788de56ccSmrg		len=$func_arith_result
10248862bcd1aSmrg		if test -z "$objlist" ||
1024988de56ccSmrg		   test "$len" -lt "$max_cmd_len"; then
1025088de56ccSmrg		  func_append objlist " $obj"
1025188de56ccSmrg		else
1025288de56ccSmrg		  # The command $test_cmds is almost too long, add a
1025388de56ccSmrg		  # command to the queue.
10254862bcd1aSmrg		  if test 1 -eq "$k"; then
1025588de56ccSmrg		    # The first file doesn't have a previous command to add.
10256e9fcaa8aSmrg		    reload_objs=$objlist
10257e9fcaa8aSmrg		    eval concat_cmds=\"$reload_cmds\"
1025888de56ccSmrg		  else
1025988de56ccSmrg		    # All subsequent reloadable object files will link in
1026088de56ccSmrg		    # the last one created.
10261e9fcaa8aSmrg		    reload_objs="$objlist $last_robj"
10262e9fcaa8aSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
1026388de56ccSmrg		  fi
10264862bcd1aSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
1026588de56ccSmrg		  func_arith $k + 1
1026688de56ccSmrg		  k=$func_arith_result
10267862bcd1aSmrg		  output=$output_objdir/$output_la-$k.$objext
10268e9fcaa8aSmrg		  objlist=" $obj"
1026988de56ccSmrg		  func_len " $last_robj"
1027088de56ccSmrg		  func_arith $len0 + $func_len_result
1027188de56ccSmrg		  len=$func_arith_result
1027288de56ccSmrg		fi
1027388de56ccSmrg	      done
1027488de56ccSmrg	      # Handle the remaining objects by creating one last
1027588de56ccSmrg	      # reloadable object file.  All subsequent reloadable object
1027688de56ccSmrg	      # files will link in the last one created.
1027788de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10278e9fcaa8aSmrg	      reload_objs="$objlist $last_robj"
10279862bcd1aSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
1028088de56ccSmrg	      if test -n "$last_robj"; then
10281862bcd1aSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1028288de56ccSmrg	      fi
10283e9fcaa8aSmrg	      func_append delfiles " $output"
102841ab64890Smrg
1028588de56ccSmrg	    else
1028688de56ccSmrg	      output=
1028788de56ccSmrg	    fi
102881ab64890Smrg
10289862bcd1aSmrg	    ${skipped_export-false} && {
10290862bcd1aSmrg	      func_verbose "generating symbol list for '$libname.la'"
10291862bcd1aSmrg	      export_symbols=$output_objdir/$libname.exp
1029288de56ccSmrg	      $opt_dry_run || $RM $export_symbols
1029388de56ccSmrg	      libobjs=$output
1029488de56ccSmrg	      # Append the command to create the export file.
1029588de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1029688de56ccSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
1029788de56ccSmrg	      if test -n "$last_robj"; then
1029888de56ccSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1029988de56ccSmrg	      fi
10300862bcd1aSmrg	    }
103011ab64890Smrg
1030288de56ccSmrg	    test -n "$save_libobjs" &&
1030388de56ccSmrg	      func_verbose "creating a temporary reloadable object file: $output"
103041ab64890Smrg
1030588de56ccSmrg	    # Loop through the commands generated above and execute them.
10306862bcd1aSmrg	    save_ifs=$IFS; IFS='~'
1030788de56ccSmrg	    for cmd in $concat_cmds; do
10308862bcd1aSmrg	      IFS=$save_ifs
10309862bcd1aSmrg	      $opt_quiet || {
103107d2c738bSmrg		  func_quote_arg expand,pretty "$cmd"
103117d2c738bSmrg		  eval "func_echo $func_quote_arg_result"
1031288de56ccSmrg	      }
1031388de56ccSmrg	      $opt_dry_run || eval "$cmd" || {
1031488de56ccSmrg		lt_exit=$?
1031588de56ccSmrg
1031688de56ccSmrg		# Restore the uninstalled library and exit
10317862bcd1aSmrg		if test relink = "$opt_mode"; then
1031888de56ccSmrg		  ( cd "$output_objdir" && \
1031988de56ccSmrg		    $RM "${realname}T" && \
1032088de56ccSmrg		    $MV "${realname}U" "$realname" )
1032188de56ccSmrg		fi
103221ab64890Smrg
1032388de56ccSmrg		exit $lt_exit
1032488de56ccSmrg	      }
1032588de56ccSmrg	    done
10326862bcd1aSmrg	    IFS=$save_ifs
10327b4ee4795Smrg
1032888de56ccSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
1032988de56ccSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
1033088de56ccSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
103311ab64890Smrg	    fi
103321ab64890Smrg	  fi
103331ab64890Smrg
10334862bcd1aSmrg          ${skipped_export-false} && {
1033588de56ccSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10336862bcd1aSmrg	      tmp_export_symbols=$export_symbols
10337862bcd1aSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10338e9fcaa8aSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1033988de56ccSmrg	    fi
103402e9c7c8cSmrg
1034188de56ccSmrg	    if test -n "$orig_export_symbols"; then
1034288de56ccSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10343862bcd1aSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1034488de56ccSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10345862bcd1aSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
1034688de56ccSmrg	      # though. Also, the filter scales superlinearly with the number of
1034788de56ccSmrg	      # global variables. join(1) would be nice here, but unfortunately
1034888de56ccSmrg	      # isn't a blessed tool.
1034988de56ccSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10350e9fcaa8aSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1035188de56ccSmrg	      export_symbols=$output_objdir/$libname.def
1035288de56ccSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1035388de56ccSmrg	    fi
10354862bcd1aSmrg	  }
103551ab64890Smrg
1035688de56ccSmrg	  libobjs=$output
1035788de56ccSmrg	  # Restore the value of output.
1035888de56ccSmrg	  output=$save_output
103591ab64890Smrg
1036088de56ccSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
1036188de56ccSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1036288de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1036388de56ccSmrg	  fi
1036488de56ccSmrg	  # Expand the library linking commands again to reset the
1036588de56ccSmrg	  # value of $libobjs for piecewise linking.
103661ab64890Smrg
1036788de56ccSmrg	  # Do each of the archive commands.
10368862bcd1aSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
1036988de56ccSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1037088de56ccSmrg	      cmds=$module_expsym_cmds
1037188de56ccSmrg	    else
1037288de56ccSmrg	      cmds=$module_cmds
10373b4ee4795Smrg	    fi
10374b4ee4795Smrg	  else
1037588de56ccSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1037688de56ccSmrg	      cmds=$archive_expsym_cmds
1037788de56ccSmrg	    else
1037888de56ccSmrg	      cmds=$archive_cmds
1037988de56ccSmrg	    fi
10380b4ee4795Smrg	  fi
1038188de56ccSmrg	fi
103821ab64890Smrg
1038388de56ccSmrg	if test -n "$delfiles"; then
1038488de56ccSmrg	  # Append the command to remove temporary files to $cmds.
1038588de56ccSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1038688de56ccSmrg	fi
103871ab64890Smrg
1038888de56ccSmrg	# Add any objects from preloaded convenience libraries
1038988de56ccSmrg	if test -n "$dlprefiles"; then
10390862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
10391e9fcaa8aSmrg	  func_append generated " $gentop"
103921ab64890Smrg
1039388de56ccSmrg	  func_extract_archives $gentop $dlprefiles
10394e9fcaa8aSmrg	  func_append libobjs " $func_extract_archives_result"
1039588de56ccSmrg	  test "X$libobjs" = "X " && libobjs=
1039688de56ccSmrg	fi
103971ab64890Smrg
10398862bcd1aSmrg	save_ifs=$IFS; IFS='~'
1039988de56ccSmrg	for cmd in $cmds; do
10400862bcd1aSmrg	  IFS=$sp$nl
1040188de56ccSmrg	  eval cmd=\"$cmd\"
10402862bcd1aSmrg	  IFS=$save_ifs
10403862bcd1aSmrg	  $opt_quiet || {
104047d2c738bSmrg	    func_quote_arg expand,pretty "$cmd"
104057d2c738bSmrg	    eval "func_echo $func_quote_arg_result"
1040688de56ccSmrg	  }
1040788de56ccSmrg	  $opt_dry_run || eval "$cmd" || {
1040888de56ccSmrg	    lt_exit=$?
104092e9c7c8cSmrg
1041088de56ccSmrg	    # Restore the uninstalled library and exit
10411862bcd1aSmrg	    if test relink = "$opt_mode"; then
1041288de56ccSmrg	      ( cd "$output_objdir" && \
1041388de56ccSmrg	        $RM "${realname}T" && \
1041488de56ccSmrg		$MV "${realname}U" "$realname" )
1041588de56ccSmrg	    fi
104162e9c7c8cSmrg
1041788de56ccSmrg	    exit $lt_exit
1041888de56ccSmrg	  }
1041988de56ccSmrg	done
10420862bcd1aSmrg	IFS=$save_ifs
104212e9c7c8cSmrg
1042288de56ccSmrg	# Restore the uninstalled library and exit
10423862bcd1aSmrg	if test relink = "$opt_mode"; then
1042488de56ccSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
104252e9c7c8cSmrg
1042688de56ccSmrg	  if test -n "$convenience"; then
1042788de56ccSmrg	    if test -z "$whole_archive_flag_spec"; then
1042888de56ccSmrg	      func_show_eval '${RM}r "$gentop"'
1042988de56ccSmrg	    fi
1043088de56ccSmrg	  fi
104312e9c7c8cSmrg
1043288de56ccSmrg	  exit $EXIT_SUCCESS
1043388de56ccSmrg	fi
1043488de56ccSmrg
1043588de56ccSmrg	# Create links to the real library.
1043688de56ccSmrg	for linkname in $linknames; do
1043788de56ccSmrg	  if test "$realname" != "$linkname"; then
1043888de56ccSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10439b4ee4795Smrg	  fi
10440b4ee4795Smrg	done
104412e9c7c8cSmrg
1044288de56ccSmrg	# If -module or -export-dynamic was specified, set the dlname.
10443862bcd1aSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1044488de56ccSmrg	  # On all known operating systems, these are identical.
10445862bcd1aSmrg	  dlname=$soname
1044688de56ccSmrg	fi
1044788de56ccSmrg      fi
104481ab64890Smrg      ;;
104491ab64890Smrg
1045088de56ccSmrg    obj)
10451862bcd1aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10452862bcd1aSmrg	func_warning "'-dlopen' is ignored for objects"
1045388de56ccSmrg      fi
10454b4ee4795Smrg
1045588de56ccSmrg      case " $deplibs" in
1045688de56ccSmrg      *\ -l* | *\ -L*)
10457862bcd1aSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
104582e9c7c8cSmrg      esac
104591ab64890Smrg
1046088de56ccSmrg      test -n "$rpath" && \
10461862bcd1aSmrg	func_warning "'-rpath' is ignored for objects"
1046288de56ccSmrg
1046388de56ccSmrg      test -n "$xrpath" && \
10464862bcd1aSmrg	func_warning "'-R' is ignored for objects"
104651ab64890Smrg
1046688de56ccSmrg      test -n "$vinfo" && \
10467862bcd1aSmrg	func_warning "'-version-info' is ignored for objects"
104682e9c7c8cSmrg
1046988de56ccSmrg      test -n "$release" && \
10470862bcd1aSmrg	func_warning "'-release' is ignored for objects"
1047188de56ccSmrg
1047288de56ccSmrg      case $output in
1047388de56ccSmrg      *.lo)
1047488de56ccSmrg	test -n "$objs$old_deplibs" && \
10475862bcd1aSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1047688de56ccSmrg
1047788de56ccSmrg	libobj=$output
1047888de56ccSmrg	func_lo2o "$libobj"
1047988de56ccSmrg	obj=$func_lo2o_result
10480b4ee4795Smrg	;;
10481b4ee4795Smrg      *)
1048288de56ccSmrg	libobj=
10483862bcd1aSmrg	obj=$output
104841ab64890Smrg	;;
104852e9c7c8cSmrg      esac
104861ab64890Smrg
1048788de56ccSmrg      # Delete the old objects.
1048888de56ccSmrg      $opt_dry_run || $RM $obj $libobj
104891ab64890Smrg
1049088de56ccSmrg      # Objects from convenience libraries.  This assumes
1049188de56ccSmrg      # single-version convenience libraries.  Whenever we create
1049288de56ccSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1049388de56ccSmrg      # the extraction.
1049488de56ccSmrg      reload_conv_objs=
1049588de56ccSmrg      gentop=
10496862bcd1aSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10497862bcd1aSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10498862bcd1aSmrg      # into space.
10499862bcd1aSmrg      case $reload_cmds in
10500862bcd1aSmrg        *\$LD[\ \$]*) wl= ;;
10501862bcd1aSmrg      esac
1050288de56ccSmrg      if test -n "$convenience"; then
1050388de56ccSmrg	if test -n "$whole_archive_flag_spec"; then
1050488de56ccSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10505862bcd1aSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10506862bcd1aSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
1050788de56ccSmrg	else
10508862bcd1aSmrg	  gentop=$output_objdir/${obj}x
10509e9fcaa8aSmrg	  func_append generated " $gentop"
10510b4ee4795Smrg
1051188de56ccSmrg	  func_extract_archives $gentop $convenience
1051288de56ccSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
1051388de56ccSmrg	fi
10514b4ee4795Smrg      fi
10515b4ee4795Smrg
10516e9fcaa8aSmrg      # If we're not building shared, we need to use non_pic_objs
10517862bcd1aSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10518e9fcaa8aSmrg
1051988de56ccSmrg      # Create the old-style object.
10520862bcd1aSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10521b4ee4795Smrg
10522862bcd1aSmrg      output=$obj
1052388de56ccSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10524b4ee4795Smrg
1052588de56ccSmrg      # Exit if we aren't doing a library object file.
1052688de56ccSmrg      if test -z "$libobj"; then
1052788de56ccSmrg	if test -n "$gentop"; then
1052888de56ccSmrg	  func_show_eval '${RM}r "$gentop"'
1052988de56ccSmrg	fi
1053088de56ccSmrg
1053188de56ccSmrg	exit $EXIT_SUCCESS
10532b4ee4795Smrg      fi
1053388de56ccSmrg
10534862bcd1aSmrg      test yes = "$build_libtool_libs" || {
1053588de56ccSmrg	if test -n "$gentop"; then
1053688de56ccSmrg	  func_show_eval '${RM}r "$gentop"'
1053788de56ccSmrg	fi
1053888de56ccSmrg
1053988de56ccSmrg	# Create an invalid libtool object if no PIC, so that we don't
1054088de56ccSmrg	# accidentally link it into a program.
1054188de56ccSmrg	# $show "echo timestamp > $libobj"
1054288de56ccSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1054388de56ccSmrg	exit $EXIT_SUCCESS
10544862bcd1aSmrg      }
1054588de56ccSmrg
10546862bcd1aSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1054788de56ccSmrg	# Only do commands if we really have different PIC objects.
1054888de56ccSmrg	reload_objs="$libobjs $reload_conv_objs"
10549862bcd1aSmrg	output=$libobj
1055088de56ccSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
1055188de56ccSmrg      fi
1055288de56ccSmrg
1055388de56ccSmrg      if test -n "$gentop"; then
1055488de56ccSmrg	func_show_eval '${RM}r "$gentop"'
1055588de56ccSmrg      fi
1055688de56ccSmrg
1055788de56ccSmrg      exit $EXIT_SUCCESS
10558b4ee4795Smrg      ;;
105591ab64890Smrg
1056088de56ccSmrg    prog)
1056188de56ccSmrg      case $host in
1056288de56ccSmrg	*cygwin*) func_stripname '' '.exe' "$output"
1056388de56ccSmrg	          output=$func_stripname_result.exe;;
1056488de56ccSmrg      esac
1056588de56ccSmrg      test -n "$vinfo" && \
10566862bcd1aSmrg	func_warning "'-version-info' is ignored for programs"
105671ab64890Smrg
1056888de56ccSmrg      test -n "$release" && \
10569862bcd1aSmrg	func_warning "'-release' is ignored for programs"
105701ab64890Smrg
10571862bcd1aSmrg      $preload \
10572862bcd1aSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10573862bcd1aSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1057488de56ccSmrg
1057588de56ccSmrg      case $host in
1057688de56ccSmrg      *-*-rhapsody* | *-*-darwin1.[012])
1057788de56ccSmrg	# On Rhapsody replace the C library is the System framework
10578e9fcaa8aSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10579e9fcaa8aSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10580b4ee4795Smrg	;;
1058188de56ccSmrg      esac
10582b4ee4795Smrg
1058388de56ccSmrg      case $host in
1058488de56ccSmrg      *-*-darwin*)
1058588de56ccSmrg	# Don't allow lazy linking, it breaks C++ global constructors
1058688de56ccSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10587862bcd1aSmrg	if test CXX = "$tagname"; then
1058888de56ccSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1058988de56ccSmrg	    10.[0123])
10590862bcd1aSmrg	      func_append compile_command " $wl-bind_at_load"
10591862bcd1aSmrg	      func_append finalize_command " $wl-bind_at_load"
1059288de56ccSmrg	    ;;
1059388de56ccSmrg	  esac
10594b4ee4795Smrg	fi
1059588de56ccSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10596e9fcaa8aSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10597e9fcaa8aSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1059888de56ccSmrg	;;
1059988de56ccSmrg      esac
10600b4ee4795Smrg
10601b4ee4795Smrg
1060288de56ccSmrg      # move library search paths that coincide with paths to not yet
1060388de56ccSmrg      # installed libraries to the beginning of the library search list
1060488de56ccSmrg      new_libs=
1060588de56ccSmrg      for path in $notinst_path; do
1060688de56ccSmrg	case " $new_libs " in
1060788de56ccSmrg	*" -L$path/$objdir "*) ;;
1060888de56ccSmrg	*)
1060988de56ccSmrg	  case " $compile_deplibs " in
1061088de56ccSmrg	  *" -L$path/$objdir "*)
10611e9fcaa8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
106122e9c7c8cSmrg	  esac
1061388de56ccSmrg	  ;;
1061488de56ccSmrg	esac
1061588de56ccSmrg      done
1061688de56ccSmrg      for deplib in $compile_deplibs; do
1061788de56ccSmrg	case $deplib in
1061888de56ccSmrg	-L*)
1061988de56ccSmrg	  case " $new_libs " in
1062088de56ccSmrg	  *" $deplib "*) ;;
10621e9fcaa8aSmrg	  *) func_append new_libs " $deplib" ;;
106222e9c7c8cSmrg	  esac
1062388de56ccSmrg	  ;;
10624e9fcaa8aSmrg	*) func_append new_libs " $deplib" ;;
1062588de56ccSmrg	esac
1062688de56ccSmrg      done
10627862bcd1aSmrg      compile_deplibs=$new_libs
106281ab64890Smrg
10629b4ee4795Smrg
10630e9fcaa8aSmrg      func_append compile_command " $compile_deplibs"
10631e9fcaa8aSmrg      func_append finalize_command " $finalize_deplibs"
10632b4ee4795Smrg
1063388de56ccSmrg      if test -n "$rpath$xrpath"; then
1063488de56ccSmrg	# If the user specified any rpath flags, then add them.
1063588de56ccSmrg	for libdir in $rpath $xrpath; do
1063688de56ccSmrg	  # This is the magic to use -rpath.
1063788de56ccSmrg	  case "$finalize_rpath " in
1063888de56ccSmrg	  *" $libdir "*) ;;
10639e9fcaa8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
1064088de56ccSmrg	  esac
1064188de56ccSmrg	done
1064288de56ccSmrg      fi
10643b4ee4795Smrg
1064488de56ccSmrg      # Now hardcode the library paths
1064588de56ccSmrg      rpath=
1064688de56ccSmrg      hardcode_libdirs=
1064788de56ccSmrg      for libdir in $compile_rpath $finalize_rpath; do
1064888de56ccSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1064988de56ccSmrg	  if test -n "$hardcode_libdir_separator"; then
1065088de56ccSmrg	    if test -z "$hardcode_libdirs"; then
10651862bcd1aSmrg	      hardcode_libdirs=$libdir
1065288de56ccSmrg	    else
1065388de56ccSmrg	      # Just accumulate the unique libdirs.
1065488de56ccSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1065588de56ccSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1065688de56ccSmrg		;;
1065788de56ccSmrg	      *)
10658e9fcaa8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1065988de56ccSmrg		;;
1066088de56ccSmrg	      esac
1066188de56ccSmrg	    fi
10662b4ee4795Smrg	  else
1066388de56ccSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10664e9fcaa8aSmrg	    func_append rpath " $flag"
10665b4ee4795Smrg	  fi
1066688de56ccSmrg	elif test -n "$runpath_var"; then
1066788de56ccSmrg	  case "$perm_rpath " in
1066888de56ccSmrg	  *" $libdir "*) ;;
10669e9fcaa8aSmrg	  *) func_append perm_rpath " $libdir" ;;
1067088de56ccSmrg	  esac
1067188de56ccSmrg	fi
1067288de56ccSmrg	case $host in
1067307fb9b8fSmrg	*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*)
10674862bcd1aSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1067588de56ccSmrg	  case :$dllsearchpath: in
1067688de56ccSmrg	  *":$libdir:"*) ;;
1067788de56ccSmrg	  ::) dllsearchpath=$libdir;;
10678e9fcaa8aSmrg	  *) func_append dllsearchpath ":$libdir";;
1067988de56ccSmrg	  esac
1068088de56ccSmrg	  case :$dllsearchpath: in
1068188de56ccSmrg	  *":$testbindir:"*) ;;
1068288de56ccSmrg	  ::) dllsearchpath=$testbindir;;
10683e9fcaa8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
1068488de56ccSmrg	  esac
1068588de56ccSmrg	  ;;
1068688de56ccSmrg	esac
1068788de56ccSmrg      done
1068888de56ccSmrg      # Substitute the hardcoded libdirs into the rpath.
1068988de56ccSmrg      if test -n "$hardcode_libdir_separator" &&
1069088de56ccSmrg	 test -n "$hardcode_libdirs"; then
10691862bcd1aSmrg	libdir=$hardcode_libdirs
1069288de56ccSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1069388de56ccSmrg      fi
10694862bcd1aSmrg      compile_rpath=$rpath
10695b4ee4795Smrg
1069688de56ccSmrg      rpath=
1069788de56ccSmrg      hardcode_libdirs=
1069888de56ccSmrg      for libdir in $finalize_rpath; do
1069988de56ccSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1070088de56ccSmrg	  if test -n "$hardcode_libdir_separator"; then
1070188de56ccSmrg	    if test -z "$hardcode_libdirs"; then
10702862bcd1aSmrg	      hardcode_libdirs=$libdir
1070388de56ccSmrg	    else
1070488de56ccSmrg	      # Just accumulate the unique libdirs.
1070588de56ccSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1070688de56ccSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1070788de56ccSmrg		;;
1070888de56ccSmrg	      *)
10709e9fcaa8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1071088de56ccSmrg		;;
1071188de56ccSmrg	      esac
1071288de56ccSmrg	    fi
107131ab64890Smrg	  else
1071488de56ccSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10715e9fcaa8aSmrg	    func_append rpath " $flag"
107161ab64890Smrg	  fi
1071788de56ccSmrg	elif test -n "$runpath_var"; then
1071888de56ccSmrg	  case "$finalize_perm_rpath " in
1071988de56ccSmrg	  *" $libdir "*) ;;
10720e9fcaa8aSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1072188de56ccSmrg	  esac
107221ab64890Smrg	fi
1072388de56ccSmrg      done
1072488de56ccSmrg      # Substitute the hardcoded libdirs into the rpath.
1072588de56ccSmrg      if test -n "$hardcode_libdir_separator" &&
1072688de56ccSmrg	 test -n "$hardcode_libdirs"; then
10727862bcd1aSmrg	libdir=$hardcode_libdirs
1072888de56ccSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1072988de56ccSmrg      fi
10730862bcd1aSmrg      finalize_rpath=$rpath
107311ab64890Smrg
10732862bcd1aSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1073388de56ccSmrg	# Transform all the library objects into standard objects.
10734e9fcaa8aSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10735e9fcaa8aSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1073688de56ccSmrg      fi
107371ab64890Smrg
10738862bcd1aSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
107391ab64890Smrg
1074088de56ccSmrg      # template prelinking step
1074188de56ccSmrg      if test -n "$prelink_cmds"; then
1074288de56ccSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1074388de56ccSmrg      fi
107441ab64890Smrg
10745862bcd1aSmrg      wrappers_required=:
1074688de56ccSmrg      case $host in
10747e9fcaa8aSmrg      *cegcc* | *mingw32ce*)
10748e9fcaa8aSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10749862bcd1aSmrg        wrappers_required=false
10750e9fcaa8aSmrg        ;;
1075107fb9b8fSmrg      *cygwin* | *mingw* | *windows* )
10752862bcd1aSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
1075388de56ccSmrg        ;;
1075488de56ccSmrg      *)
10755862bcd1aSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10756862bcd1aSmrg          wrappers_required=false
1075788de56ccSmrg        fi
1075888de56ccSmrg        ;;
1075988de56ccSmrg      esac
10760862bcd1aSmrg      $wrappers_required || {
1076188de56ccSmrg	# Replace the output file specification.
10762e9fcaa8aSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10763862bcd1aSmrg	link_command=$compile_command$compile_rpath
107641ab64890Smrg
1076588de56ccSmrg	# We have no uninstalled library dependencies, so finalize right now.
1076688de56ccSmrg	exit_status=0
1076788de56ccSmrg	func_show_eval "$link_command" 'exit_status=$?'
107681ab64890Smrg
10769e9fcaa8aSmrg	if test -n "$postlink_cmds"; then
10770e9fcaa8aSmrg	  func_to_tool_file "$output"
10771e9fcaa8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10772e9fcaa8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10773e9fcaa8aSmrg	fi
10774e9fcaa8aSmrg
1077588de56ccSmrg	# Delete the generated files.
10776862bcd1aSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10777862bcd1aSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
107781ab64890Smrg	fi
107791ab64890Smrg
1078088de56ccSmrg	exit $exit_status
10781862bcd1aSmrg      }
107821ab64890Smrg
1078388de56ccSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1078488de56ccSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1078588de56ccSmrg      fi
1078688de56ccSmrg      if test -n "$finalize_shlibpath"; then
1078788de56ccSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1078888de56ccSmrg      fi
10789b4ee4795Smrg
1079088de56ccSmrg      compile_var=
1079188de56ccSmrg      finalize_var=
1079288de56ccSmrg      if test -n "$runpath_var"; then
1079388de56ccSmrg	if test -n "$perm_rpath"; then
1079488de56ccSmrg	  # We should set the runpath_var.
1079588de56ccSmrg	  rpath=
1079688de56ccSmrg	  for dir in $perm_rpath; do
10797e9fcaa8aSmrg	    func_append rpath "$dir:"
1079888de56ccSmrg	  done
1079988de56ccSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
108001ab64890Smrg	fi
1080188de56ccSmrg	if test -n "$finalize_perm_rpath"; then
1080288de56ccSmrg	  # We should set the runpath_var.
1080388de56ccSmrg	  rpath=
1080488de56ccSmrg	  for dir in $finalize_perm_rpath; do
10805e9fcaa8aSmrg	    func_append rpath "$dir:"
1080688de56ccSmrg	  done
1080788de56ccSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
108081ab64890Smrg	fi
1080988de56ccSmrg      fi
108101ab64890Smrg
10811862bcd1aSmrg      if test yes = "$no_install"; then
1081288de56ccSmrg	# We don't need to create a wrapper script.
10813862bcd1aSmrg	link_command=$compile_var$compile_command$compile_rpath
1081488de56ccSmrg	# Replace the output file specification.
10815e9fcaa8aSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1081688de56ccSmrg	# Delete the old output file.
1081788de56ccSmrg	$opt_dry_run || $RM $output
1081888de56ccSmrg	# Link the executable and exit
1081988de56ccSmrg	func_show_eval "$link_command" 'exit $?'
10820e9fcaa8aSmrg
10821e9fcaa8aSmrg	if test -n "$postlink_cmds"; then
10822e9fcaa8aSmrg	  func_to_tool_file "$output"
10823e9fcaa8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10824e9fcaa8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10825e9fcaa8aSmrg	fi
10826e9fcaa8aSmrg
10827b4ee4795Smrg	exit $EXIT_SUCCESS
1082888de56ccSmrg      fi
108292e9c7c8cSmrg
10830862bcd1aSmrg      case $hardcode_action,$fast_install in
10831862bcd1aSmrg        relink,*)
10832862bcd1aSmrg	  # Fast installation is not supported
10833862bcd1aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10834862bcd1aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1083588de56ccSmrg
10836862bcd1aSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10837862bcd1aSmrg	  func_warning "'$output' will be relinked during installation"
10838862bcd1aSmrg	  ;;
10839862bcd1aSmrg        *,yes)
10840862bcd1aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10841862bcd1aSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10842862bcd1aSmrg          ;;
10843862bcd1aSmrg	*,no)
10844862bcd1aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10845862bcd1aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10846862bcd1aSmrg          ;;
10847862bcd1aSmrg	*,needless)
10848862bcd1aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10849862bcd1aSmrg	  relink_command=
10850862bcd1aSmrg          ;;
10851862bcd1aSmrg      esac
108521ab64890Smrg
1085388de56ccSmrg      # Replace the output file specification.
10854e9fcaa8aSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
108551ab64890Smrg
1085688de56ccSmrg      # Delete the old output files.
1085788de56ccSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
108581ab64890Smrg
1085988de56ccSmrg      func_show_eval "$link_command" 'exit $?'
10860b4ee4795Smrg
10861e9fcaa8aSmrg      if test -n "$postlink_cmds"; then
10862e9fcaa8aSmrg	func_to_tool_file "$output_objdir/$outputname"
10863e9fcaa8aSmrg	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'`
10864e9fcaa8aSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10865e9fcaa8aSmrg      fi
10866e9fcaa8aSmrg
1086788de56ccSmrg      # Now create the wrapper script.
1086888de56ccSmrg      func_verbose "creating $output"
10869b4ee4795Smrg
1087088de56ccSmrg      # Quote the relink command for shipping.
1087188de56ccSmrg      if test -n "$relink_command"; then
1087288de56ccSmrg	# Preserve any variables that may affect compiler behavior
1087388de56ccSmrg	for var in $variables_saved_for_relink; do
1087488de56ccSmrg	  if eval test -z \"\${$var+set}\"; then
1087588de56ccSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1087688de56ccSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1087788de56ccSmrg	    relink_command="$var=; export $var; $relink_command"
108781ab64890Smrg	  else
108797d2c738bSmrg	    func_quote_arg pretty "$var_value"
108807d2c738bSmrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
108811ab64890Smrg	  fi
1088288de56ccSmrg	done
108837d2c738bSmrg	func_quote eval cd "`pwd`"
108847d2c738bSmrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
108857d2c738bSmrg	relink_command=$func_quote_arg_unquoted_result
1088688de56ccSmrg      fi
1088788de56ccSmrg
1088888de56ccSmrg      # Only actually do things if not in dry run mode.
1088988de56ccSmrg      $opt_dry_run || {
1089088de56ccSmrg	# win32 will think the script is a binary if it has
1089188de56ccSmrg	# a .exe suffix, so we strip it off here.
1089288de56ccSmrg	case $output in
1089388de56ccSmrg	  *.exe) func_stripname '' '.exe' "$output"
1089488de56ccSmrg	         output=$func_stripname_result ;;
1089588de56ccSmrg	esac
1089688de56ccSmrg	# test for cygwin because mv fails w/o .exe extensions
1089788de56ccSmrg	case $host in
1089888de56ccSmrg	  *cygwin*)
1089988de56ccSmrg	    exeext=.exe
1090088de56ccSmrg	    func_stripname '' '.exe' "$outputname"
1090188de56ccSmrg	    outputname=$func_stripname_result ;;
1090288de56ccSmrg	  *) exeext= ;;
109031ab64890Smrg	esac
1090488de56ccSmrg	case $host in
1090507fb9b8fSmrg	  *cygwin* | *mingw* | windows* )
1090688de56ccSmrg	    func_dirname_and_basename "$output" "" "."
1090788de56ccSmrg	    output_name=$func_basename_result
1090888de56ccSmrg	    output_path=$func_dirname_result
10909862bcd1aSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10910862bcd1aSmrg	    cwrapper=$output_path/$output_name.exe
1091188de56ccSmrg	    $RM $cwrappersource $cwrapper
1091288de56ccSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1091388de56ccSmrg
1091488de56ccSmrg	    func_emit_cwrapperexe_src > $cwrappersource
1091588de56ccSmrg
1091688de56ccSmrg	    # The wrapper executable is built using the $host compiler,
1091788de56ccSmrg	    # because it contains $host paths and files. If cross-
1091888de56ccSmrg	    # compiling, it, like the target executable, must be
1091988de56ccSmrg	    # executed on the $host or under an emulation environment.
1092088de56ccSmrg	    $opt_dry_run || {
1092188de56ccSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1092288de56ccSmrg	      $STRIP $cwrapper
1092388de56ccSmrg	    }
109241ab64890Smrg
1092588de56ccSmrg	    # Now, create the wrapper script for func_source use:
1092688de56ccSmrg	    func_ltwrapper_scriptname $cwrapper
1092788de56ccSmrg	    $RM $func_ltwrapper_scriptname_result
1092888de56ccSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1092988de56ccSmrg	    $opt_dry_run || {
1093088de56ccSmrg	      # note: this script will not be executed, so do not chmod.
10931862bcd1aSmrg	      if test "x$build" = "x$host"; then
1093288de56ccSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1093388de56ccSmrg	      else
1093488de56ccSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1093588de56ccSmrg	      fi
1093688de56ccSmrg	    }
1093788de56ccSmrg	  ;;
1093888de56ccSmrg	  * )
1093988de56ccSmrg	    $RM $output
1094088de56ccSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
109411ab64890Smrg
1094288de56ccSmrg	    func_emit_wrapper no > $output
1094388de56ccSmrg	    chmod +x $output
1094488de56ccSmrg	  ;;
1094588de56ccSmrg	esac
1094688de56ccSmrg      }
1094788de56ccSmrg      exit $EXIT_SUCCESS
1094888de56ccSmrg      ;;
1094988de56ccSmrg    esac
109501ab64890Smrg
1095188de56ccSmrg    # See if we need to build an old-fashioned archive.
1095288de56ccSmrg    for oldlib in $oldlibs; do
109531ab64890Smrg
10954862bcd1aSmrg      case $build_libtool_libs in
10955862bcd1aSmrg        convenience)
10956862bcd1aSmrg	  oldobjs="$libobjs_save $symfileobj"
10957862bcd1aSmrg	  addlibs=$convenience
1095888de56ccSmrg	  build_libtool_libs=no
10959862bcd1aSmrg	  ;;
10960862bcd1aSmrg	module)
10961862bcd1aSmrg	  oldobjs=$libobjs_save
10962862bcd1aSmrg	  addlibs=$old_convenience
10963862bcd1aSmrg	  build_libtool_libs=no
10964862bcd1aSmrg          ;;
10965862bcd1aSmrg	*)
1096688de56ccSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10967862bcd1aSmrg	  $preload && test -f "$symfileobj" \
10968862bcd1aSmrg	    && func_append oldobjs " $symfileobj"
10969862bcd1aSmrg	  addlibs=$old_convenience
10970862bcd1aSmrg	  ;;
10971862bcd1aSmrg      esac
109721ab64890Smrg
1097388de56ccSmrg      if test -n "$addlibs"; then
10974862bcd1aSmrg	gentop=$output_objdir/${outputname}x
10975e9fcaa8aSmrg	func_append generated " $gentop"
109761ab64890Smrg
1097788de56ccSmrg	func_extract_archives $gentop $addlibs
10978e9fcaa8aSmrg	func_append oldobjs " $func_extract_archives_result"
1097988de56ccSmrg      fi
109801ab64890Smrg
1098188de56ccSmrg      # Do each command in the archive commands.
10982862bcd1aSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1098388de56ccSmrg	cmds=$old_archive_from_new_cmds
1098488de56ccSmrg      else
109851ab64890Smrg
1098688de56ccSmrg	# Add any objects from preloaded convenience libraries
1098788de56ccSmrg	if test -n "$dlprefiles"; then
10988862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
10989e9fcaa8aSmrg	  func_append generated " $gentop"
109901ab64890Smrg
1099188de56ccSmrg	  func_extract_archives $gentop $dlprefiles
10992e9fcaa8aSmrg	  func_append oldobjs " $func_extract_archives_result"
1099388de56ccSmrg	fi
109941ab64890Smrg
1099588de56ccSmrg	# POSIX demands no paths to be encoded in archives.  We have
1099688de56ccSmrg	# to avoid creating archives with duplicate basenames if we
1099788de56ccSmrg	# might have to extract them afterwards, e.g., when creating a
1099888de56ccSmrg	# static archive out of a convenience library, or when linking
1099988de56ccSmrg	# the entirety of a libtool archive into another (currently
1100088de56ccSmrg	# not supported by libtool).
1100188de56ccSmrg	if (for obj in $oldobjs
1100288de56ccSmrg	    do
1100388de56ccSmrg	      func_basename "$obj"
1100488de56ccSmrg	      $ECHO "$func_basename_result"
1100588de56ccSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
1100688de56ccSmrg	  :
1100788de56ccSmrg	else
11008e9fcaa8aSmrg	  echo "copying selected object files to avoid basename conflicts..."
11009862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
11010e9fcaa8aSmrg	  func_append generated " $gentop"
1101188de56ccSmrg	  func_mkdir_p "$gentop"
1101288de56ccSmrg	  save_oldobjs=$oldobjs
1101388de56ccSmrg	  oldobjs=
1101488de56ccSmrg	  counter=1
1101588de56ccSmrg	  for obj in $save_oldobjs
1101688de56ccSmrg	  do
1101788de56ccSmrg	    func_basename "$obj"
11018862bcd1aSmrg	    objbase=$func_basename_result
1101988de56ccSmrg	    case " $oldobjs " in
1102088de56ccSmrg	    " ") oldobjs=$obj ;;
1102188de56ccSmrg	    *[\ /]"$objbase "*)
1102288de56ccSmrg	      while :; do
1102388de56ccSmrg		# Make sure we don't pick an alternate name that also
1102488de56ccSmrg		# overlaps.
1102588de56ccSmrg		newobj=lt$counter-$objbase
1102688de56ccSmrg		func_arith $counter + 1
1102788de56ccSmrg		counter=$func_arith_result
1102888de56ccSmrg		case " $oldobjs " in
1102988de56ccSmrg		*[\ /]"$newobj "*) ;;
1103088de56ccSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1103188de56ccSmrg		esac
1103288de56ccSmrg	      done
1103388de56ccSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
11034e9fcaa8aSmrg	      func_append oldobjs " $gentop/$newobj"
1103588de56ccSmrg	      ;;
11036e9fcaa8aSmrg	    *) func_append oldobjs " $obj" ;;
1103788de56ccSmrg	    esac
110381ab64890Smrg	  done
110392e9c7c8cSmrg	fi
11040eb411b4bSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
11041eb411b4bSmrg	tool_oldlib=$func_to_tool_file_result
1104288de56ccSmrg	eval cmds=\"$old_archive_cmds\"
11043b4ee4795Smrg
1104488de56ccSmrg	func_len " $cmds"
1104588de56ccSmrg	len=$func_len_result
1104688de56ccSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1104788de56ccSmrg	  cmds=$old_archive_cmds
11048e9fcaa8aSmrg	elif test -n "$archiver_list_spec"; then
11049e9fcaa8aSmrg	  func_verbose "using command file archive linking..."
11050e9fcaa8aSmrg	  for obj in $oldobjs
11051e9fcaa8aSmrg	  do
11052e9fcaa8aSmrg	    func_to_tool_file "$obj"
11053e9fcaa8aSmrg	    $ECHO "$func_to_tool_file_result"
11054e9fcaa8aSmrg	  done > $output_objdir/$libname.libcmd
11055e9fcaa8aSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
11056e9fcaa8aSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
11057e9fcaa8aSmrg	  cmds=$old_archive_cmds
1105888de56ccSmrg	else
1105988de56ccSmrg	  # the command line is too long to link in one step, link in parts
1106088de56ccSmrg	  func_verbose "using piecewise archive linking..."
1106188de56ccSmrg	  save_RANLIB=$RANLIB
1106288de56ccSmrg	  RANLIB=:
1106388de56ccSmrg	  objlist=
1106488de56ccSmrg	  concat_cmds=
1106588de56ccSmrg	  save_oldobjs=$oldobjs
1106688de56ccSmrg	  oldobjs=
1106788de56ccSmrg	  # Is there a better way of finding the last object in the list?
1106888de56ccSmrg	  for obj in $save_oldobjs
1106988de56ccSmrg	  do
1107088de56ccSmrg	    last_oldobj=$obj
1107188de56ccSmrg	  done
1107288de56ccSmrg	  eval test_cmds=\"$old_archive_cmds\"
1107388de56ccSmrg	  func_len " $test_cmds"
1107488de56ccSmrg	  len0=$func_len_result
1107588de56ccSmrg	  len=$len0
1107688de56ccSmrg	  for obj in $save_oldobjs
1107788de56ccSmrg	  do
1107888de56ccSmrg	    func_len " $obj"
1107988de56ccSmrg	    func_arith $len + $func_len_result
1108088de56ccSmrg	    len=$func_arith_result
1108188de56ccSmrg	    func_append objlist " $obj"
1108288de56ccSmrg	    if test "$len" -lt "$max_cmd_len"; then
1108388de56ccSmrg	      :
1108488de56ccSmrg	    else
1108588de56ccSmrg	      # the above command should be used before it gets too long
1108688de56ccSmrg	      oldobjs=$objlist
11087862bcd1aSmrg	      if test "$obj" = "$last_oldobj"; then
1108888de56ccSmrg		RANLIB=$save_RANLIB
1108988de56ccSmrg	      fi
1109088de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11091862bcd1aSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1109288de56ccSmrg	      objlist=
1109388de56ccSmrg	      len=$len0
1109488de56ccSmrg	    fi
1109588de56ccSmrg	  done
1109688de56ccSmrg	  RANLIB=$save_RANLIB
1109788de56ccSmrg	  oldobjs=$objlist
11098862bcd1aSmrg	  if test -z "$oldobjs"; then
1109988de56ccSmrg	    eval cmds=\"\$concat_cmds\"
1110088de56ccSmrg	  else
1110188de56ccSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1110288de56ccSmrg	  fi
1110388de56ccSmrg	fi
1110488de56ccSmrg      fi
1110588de56ccSmrg      func_execute_cmds "$cmds" 'exit $?'
111061ab64890Smrg    done
111071ab64890Smrg
1110888de56ccSmrg    test -n "$generated" && \
1110988de56ccSmrg      func_show_eval "${RM}r$generated"
111101ab64890Smrg
1111188de56ccSmrg    # Now create the libtool archive.
1111288de56ccSmrg    case $output in
1111388de56ccSmrg    *.la)
1111488de56ccSmrg      old_library=
11115862bcd1aSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1111688de56ccSmrg      func_verbose "creating $output"
111172e9c7c8cSmrg
1111888de56ccSmrg      # Preserve any variables that may affect compiler behavior
1111988de56ccSmrg      for var in $variables_saved_for_relink; do
1112088de56ccSmrg	if eval test -z \"\${$var+set}\"; then
1112188de56ccSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1112288de56ccSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
1112388de56ccSmrg	  relink_command="$var=; export $var; $relink_command"
11124b4ee4795Smrg	else
111257d2c738bSmrg	  func_quote_arg pretty,unquoted "$var_value"
111267d2c738bSmrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11127b4ee4795Smrg	fi
1112888de56ccSmrg      done
1112988de56ccSmrg      # Quote the link command for shipping.
111307d2c738bSmrg      func_quote eval cd "`pwd`"
111317d2c738bSmrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
111327d2c738bSmrg      func_quote_arg pretty,unquoted "$relink_command"
111337d2c738bSmrg      relink_command=$func_quote_arg_unquoted_result
11134862bcd1aSmrg      if test yes = "$hardcode_automatic"; then
1113588de56ccSmrg	relink_command=
1113688de56ccSmrg      fi
111371ab64890Smrg
1113888de56ccSmrg      # Only create the output if not a dry run.
1113988de56ccSmrg      $opt_dry_run || {
1114088de56ccSmrg	for installed in no yes; do
11141862bcd1aSmrg	  if test yes = "$installed"; then
1114288de56ccSmrg	    if test -z "$install_libdir"; then
1114388de56ccSmrg	      break
1114488de56ccSmrg	    fi
11145862bcd1aSmrg	    output=$output_objdir/${outputname}i
1114688de56ccSmrg	    # Replace all uninstalled libtool libraries with the installed ones
1114788de56ccSmrg	    newdependency_libs=
1114888de56ccSmrg	    for deplib in $dependency_libs; do
1114988de56ccSmrg	      case $deplib in
1115088de56ccSmrg	      *.la)
1115188de56ccSmrg		func_basename "$deplib"
11152862bcd1aSmrg		name=$func_basename_result
11153eb411b4bSmrg		func_resolve_sysroot "$deplib"
11154862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1115588de56ccSmrg		test -z "$libdir" && \
11156862bcd1aSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11157e9fcaa8aSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11158e9fcaa8aSmrg		;;
11159e9fcaa8aSmrg	      -L*)
11160e9fcaa8aSmrg		func_stripname -L '' "$deplib"
11161e9fcaa8aSmrg		func_replace_sysroot "$func_stripname_result"
11162e9fcaa8aSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1116388de56ccSmrg		;;
11164e9fcaa8aSmrg	      -R*)
11165e9fcaa8aSmrg		func_stripname -R '' "$deplib"
11166e9fcaa8aSmrg		func_replace_sysroot "$func_stripname_result"
11167e9fcaa8aSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11168e9fcaa8aSmrg		;;
11169e9fcaa8aSmrg	      *) func_append newdependency_libs " $deplib" ;;
1117088de56ccSmrg	      esac
1117188de56ccSmrg	    done
11172862bcd1aSmrg	    dependency_libs=$newdependency_libs
1117388de56ccSmrg	    newdlfiles=
1117488de56ccSmrg
1117588de56ccSmrg	    for lib in $dlfiles; do
1117688de56ccSmrg	      case $lib in
1117788de56ccSmrg	      *.la)
1117888de56ccSmrg	        func_basename "$lib"
11179862bcd1aSmrg		name=$func_basename_result
11180862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1118188de56ccSmrg		test -z "$libdir" && \
11182862bcd1aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11183e9fcaa8aSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1118488de56ccSmrg		;;
11185e9fcaa8aSmrg	      *) func_append newdlfiles " $lib" ;;
1118688de56ccSmrg	      esac
1118788de56ccSmrg	    done
11188862bcd1aSmrg	    dlfiles=$newdlfiles
1118988de56ccSmrg	    newdlprefiles=
1119088de56ccSmrg	    for lib in $dlprefiles; do
1119188de56ccSmrg	      case $lib in
1119288de56ccSmrg	      *.la)
1119388de56ccSmrg		# Only pass preopened files to the pseudo-archive (for
1119488de56ccSmrg		# eventual linking with the app. that links it) if we
1119588de56ccSmrg		# didn't already link the preopened objects directly into
1119688de56ccSmrg		# the library:
1119788de56ccSmrg		func_basename "$lib"
11198862bcd1aSmrg		name=$func_basename_result
11199862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1120088de56ccSmrg		test -z "$libdir" && \
11201862bcd1aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11202e9fcaa8aSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1120388de56ccSmrg		;;
1120488de56ccSmrg	      esac
1120588de56ccSmrg	    done
11206862bcd1aSmrg	    dlprefiles=$newdlprefiles
1120788de56ccSmrg	  else
1120888de56ccSmrg	    newdlfiles=
1120988de56ccSmrg	    for lib in $dlfiles; do
1121088de56ccSmrg	      case $lib in
11211862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1121288de56ccSmrg		*) abs=`pwd`"/$lib" ;;
1121388de56ccSmrg	      esac
11214e9fcaa8aSmrg	      func_append newdlfiles " $abs"
1121588de56ccSmrg	    done
11216862bcd1aSmrg	    dlfiles=$newdlfiles
1121788de56ccSmrg	    newdlprefiles=
1121888de56ccSmrg	    for lib in $dlprefiles; do
1121988de56ccSmrg	      case $lib in
11220862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1122188de56ccSmrg		*) abs=`pwd`"/$lib" ;;
1122288de56ccSmrg	      esac
11223e9fcaa8aSmrg	      func_append newdlprefiles " $abs"
1122488de56ccSmrg	    done
11225862bcd1aSmrg	    dlprefiles=$newdlprefiles
1122688de56ccSmrg	  fi
1122788de56ccSmrg	  $RM $output
1122888de56ccSmrg	  # place dlname in correct position for cygwin
11229e9fcaa8aSmrg	  # In fact, it would be nice if we could use this code for all target
11230e9fcaa8aSmrg	  # systems that can't hard-code library paths into their executables
11231e9fcaa8aSmrg	  # and that have no shared library path variable independent of PATH,
11232e9fcaa8aSmrg	  # but it turns out we can't easily determine that from inspecting
11233e9fcaa8aSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11234e9fcaa8aSmrg	  # applies here; at the moment, that means platforms that use the PE
11235e9fcaa8aSmrg	  # object format with DLL files.  See the long comment at the top of
11236e9fcaa8aSmrg	  # tests/bindir.at for full details.
1123788de56ccSmrg	  tdlname=$dlname
1123888de56ccSmrg	  case $host,$output,$installed,$module,$dlname in
1123907fb9b8fSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *windows*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11240e9fcaa8aSmrg	      # If a -bindir argument was supplied, place the dll there.
11241862bcd1aSmrg	      if test -n "$bindir"; then
11242e9fcaa8aSmrg		func_relative_path "$install_libdir" "$bindir"
11243862bcd1aSmrg		tdlname=$func_relative_path_result/$dlname
11244e9fcaa8aSmrg	      else
11245e9fcaa8aSmrg		# Otherwise fall back on heuristic.
11246e9fcaa8aSmrg		tdlname=../bin/$dlname
11247e9fcaa8aSmrg	      fi
11248e9fcaa8aSmrg	      ;;
1124988de56ccSmrg	  esac
1125088de56ccSmrg	  $ECHO > $output "\
1125188de56ccSmrg# $outputname - a libtool library file
11252862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1125388de56ccSmrg#
1125488de56ccSmrg# Please DO NOT delete this file!
1125588de56ccSmrg# It is necessary for linking the library.
112561ab64890Smrg
1125788de56ccSmrg# The name that we can dlopen(3).
1125888de56ccSmrgdlname='$tdlname'
112591ab64890Smrg
1126088de56ccSmrg# Names of this library.
1126188de56ccSmrglibrary_names='$library_names'
112621ab64890Smrg
1126388de56ccSmrg# The name of the static archive.
1126488de56ccSmrgold_library='$old_library'
112651ab64890Smrg
11266862bcd1aSmrg# Linker flags that cannot go in dependency_libs.
1126788de56ccSmrginherited_linker_flags='$new_inherited_linker_flags'
112681ab64890Smrg
1126988de56ccSmrg# Libraries that this one depends upon.
1127088de56ccSmrgdependency_libs='$dependency_libs'
112711ab64890Smrg
1127288de56ccSmrg# Names of additional weak libraries provided by this library
1127388de56ccSmrgweak_library_names='$weak_libs'
112741ab64890Smrg
1127588de56ccSmrg# Version information for $libname.
1127688de56ccSmrgcurrent=$current
1127788de56ccSmrgage=$age
1127888de56ccSmrgrevision=$revision
112791ab64890Smrg
1128088de56ccSmrg# Is this an already installed library?
1128188de56ccSmrginstalled=$installed
112821ab64890Smrg
1128388de56ccSmrg# Should we warn about portability when linking against -modules?
1128488de56ccSmrgshouldnotlink=$module
112851ab64890Smrg
1128688de56ccSmrg# Files to dlopen/dlpreopen
1128788de56ccSmrgdlopen='$dlfiles'
1128888de56ccSmrgdlpreopen='$dlprefiles'
112891ab64890Smrg
1129088de56ccSmrg# Directory that this library needs to be installed in:
1129188de56ccSmrglibdir='$install_libdir'"
11292862bcd1aSmrg	  if test no,yes = "$installed,$need_relink"; then
1129388de56ccSmrg	    $ECHO >> $output "\
1129488de56ccSmrgrelink_command=\"$relink_command\""
1129588de56ccSmrg	  fi
1129688de56ccSmrg	done
1129788de56ccSmrg      }
112981ab64890Smrg
1129988de56ccSmrg      # Do a symbolic link so that the libtool archive can be found in
1130088de56ccSmrg      # LD_LIBRARY_PATH before the program is installed.
1130188de56ccSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1130288de56ccSmrg      ;;
1130388de56ccSmrg    esac
1130488de56ccSmrg    exit $EXIT_SUCCESS
1130588de56ccSmrg}
11306b4ee4795Smrg
11307862bcd1aSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11308862bcd1aSmrg  func_mode_link ${1+"$@"}
11309862bcd1aSmrgfi
113101ab64890Smrg
113111ab64890Smrg
1131288de56ccSmrg# func_mode_uninstall arg...
1131388de56ccSmrgfunc_mode_uninstall ()
1131488de56ccSmrg{
11315862bcd1aSmrg    $debug_cmd
11316862bcd1aSmrg
11317862bcd1aSmrg    RM=$nonopt
113181ab64890Smrg    files=
11319862bcd1aSmrg    rmforce=false
113201ab64890Smrg    exit_status=0
113211ab64890Smrg
113221ab64890Smrg    # This variable tells wrapper scripts just to set variables rather
113231ab64890Smrg    # than running their programs.
11324862bcd1aSmrg    libtool_install_magic=$magic
113251ab64890Smrg
113261ab64890Smrg    for arg
113271ab64890Smrg    do
113281ab64890Smrg      case $arg in
11329862bcd1aSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11330e9fcaa8aSmrg      -*) func_append RM " $arg" ;;
11331e9fcaa8aSmrg      *) func_append files " $arg" ;;
113321ab64890Smrg      esac
113331ab64890Smrg    done
113341ab64890Smrg
1133588de56ccSmrg    test -z "$RM" && \
1133688de56ccSmrg      func_fatal_help "you must specify an RM program"
113371ab64890Smrg
113381ab64890Smrg    rmdirs=
113391ab64890Smrg
113401ab64890Smrg    for file in $files; do
1134188de56ccSmrg      func_dirname "$file" "" "."
11342862bcd1aSmrg      dir=$func_dirname_result
11343862bcd1aSmrg      if test . = "$dir"; then
11344862bcd1aSmrg	odir=$objdir
113451ab64890Smrg      else
11346862bcd1aSmrg	odir=$dir/$objdir
113471ab64890Smrg      fi
1134888de56ccSmrg      func_basename "$file"
11349862bcd1aSmrg      name=$func_basename_result
11350862bcd1aSmrg      test uninstall = "$opt_mode" && odir=$dir
113511ab64890Smrg
11352e9fcaa8aSmrg      # Remember odir for removal later, being careful to avoid duplicates
11353862bcd1aSmrg      if test clean = "$opt_mode"; then
113541ab64890Smrg	case " $rmdirs " in
11355e9fcaa8aSmrg	  *" $odir "*) ;;
11356e9fcaa8aSmrg	  *) func_append rmdirs " $odir" ;;
113571ab64890Smrg	esac
113581ab64890Smrg      fi
113591ab64890Smrg
113601ab64890Smrg      # Don't error if the file doesn't exist and rm -f was used.
1136188de56ccSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1136288de56ccSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1136388de56ccSmrg	 test -f "$file"; then
113641ab64890Smrg	:
113651ab64890Smrg      elif test -d "$file"; then
113661ab64890Smrg	exit_status=1
113671ab64890Smrg	continue
11368862bcd1aSmrg      elif $rmforce; then
113691ab64890Smrg	continue
113701ab64890Smrg      fi
113711ab64890Smrg
11372862bcd1aSmrg      rmfiles=$file
113731ab64890Smrg
113741ab64890Smrg      case $name in
113751ab64890Smrg      *.la)
113761ab64890Smrg	# Possibly a libtool archive, so verify it.
1137788de56ccSmrg	if func_lalib_p "$file"; then
1137888de56ccSmrg	  func_source $dir/$name
113791ab64890Smrg
113801ab64890Smrg	  # Delete the libtool libraries and symlinks.
113811ab64890Smrg	  for n in $library_names; do
11382e9fcaa8aSmrg	    func_append rmfiles " $odir/$n"
113831ab64890Smrg	  done
11384e9fcaa8aSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
113851ab64890Smrg
11386862bcd1aSmrg	  case $opt_mode in
113871ab64890Smrg	  clean)
11388e9fcaa8aSmrg	    case " $library_names " in
113891ab64890Smrg	    *" $dlname "*) ;;
11390e9fcaa8aSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
113911ab64890Smrg	    esac
11392e9fcaa8aSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
113931ab64890Smrg	    ;;
113941ab64890Smrg	  uninstall)
113951ab64890Smrg	    if test -n "$library_names"; then
113961ab64890Smrg	      # Do each command in the postuninstall commands.
11397862bcd1aSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113981ab64890Smrg	    fi
113991ab64890Smrg
114001ab64890Smrg	    if test -n "$old_library"; then
114011ab64890Smrg	      # Do each command in the old_postuninstall commands.
11402862bcd1aSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
114031ab64890Smrg	    fi
114041ab64890Smrg	    # FIXME: should reinstall the best remaining shared library.
114051ab64890Smrg	    ;;
114061ab64890Smrg	  esac
114071ab64890Smrg	fi
114081ab64890Smrg	;;
114091ab64890Smrg
114101ab64890Smrg      *.lo)
114111ab64890Smrg	# Possibly a libtool object, so verify it.
1141288de56ccSmrg	if func_lalib_p "$file"; then
114131ab64890Smrg
114141ab64890Smrg	  # Read the .lo file
1141588de56ccSmrg	  func_source $dir/$name
114161ab64890Smrg
114171ab64890Smrg	  # Add PIC object to the list of files to remove.
11418862bcd1aSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11419e9fcaa8aSmrg	    func_append rmfiles " $dir/$pic_object"
114201ab64890Smrg	  fi
114211ab64890Smrg
114221ab64890Smrg	  # Add non-PIC object to the list of files to remove.
11423862bcd1aSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11424e9fcaa8aSmrg	    func_append rmfiles " $dir/$non_pic_object"
114251ab64890Smrg	  fi
114261ab64890Smrg	fi
114271ab64890Smrg	;;
114281ab64890Smrg
114291ab64890Smrg      *)
11430862bcd1aSmrg	if test clean = "$opt_mode"; then
114311ab64890Smrg	  noexename=$name
114321ab64890Smrg	  case $file in
114331ab64890Smrg	  *.exe)
1143488de56ccSmrg	    func_stripname '' '.exe' "$file"
1143588de56ccSmrg	    file=$func_stripname_result
1143688de56ccSmrg	    func_stripname '' '.exe' "$name"
1143788de56ccSmrg	    noexename=$func_stripname_result
114381ab64890Smrg	    # $file with .exe has already been added to rmfiles,
114391ab64890Smrg	    # add $file without .exe
11440e9fcaa8aSmrg	    func_append rmfiles " $file"
114411ab64890Smrg	    ;;
114421ab64890Smrg	  esac
114431ab64890Smrg	  # Do a test to see if this is a libtool program.
1144488de56ccSmrg	  if func_ltwrapper_p "$file"; then
1144588de56ccSmrg	    if func_ltwrapper_executable_p "$file"; then
1144688de56ccSmrg	      func_ltwrapper_scriptname "$file"
1144788de56ccSmrg	      relink_command=
1144888de56ccSmrg	      func_source $func_ltwrapper_scriptname_result
11449e9fcaa8aSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1145088de56ccSmrg	    else
1145188de56ccSmrg	      relink_command=
1145288de56ccSmrg	      func_source $dir/$noexename
1145388de56ccSmrg	    fi
114541ab64890Smrg
114551ab64890Smrg	    # note $name still contains .exe if it was in $file originally
114561ab64890Smrg	    # as does the version of $file that was added into $rmfiles
11457862bcd1aSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11458862bcd1aSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11459e9fcaa8aSmrg	      func_append rmfiles " $odir/lt-$name"
114601ab64890Smrg	    fi
11461862bcd1aSmrg	    if test "X$noexename" != "X$name"; then
11462862bcd1aSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
114631ab64890Smrg	    fi
114641ab64890Smrg	  fi
114651ab64890Smrg	fi
114661ab64890Smrg	;;
114671ab64890Smrg      esac
1146888de56ccSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
114691ab64890Smrg    done
114701ab64890Smrg
11471862bcd1aSmrg    # Try to remove the $objdir's in the directories where we deleted files
114721ab64890Smrg    for dir in $rmdirs; do
114731ab64890Smrg      if test -d "$dir"; then
1147488de56ccSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
114751ab64890Smrg      fi
114761ab64890Smrg    done
114771ab64890Smrg
114781ab64890Smrg    exit $exit_status
1147988de56ccSmrg}
114801ab64890Smrg
11481862bcd1aSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11482862bcd1aSmrg  func_mode_uninstall ${1+"$@"}
11483862bcd1aSmrgfi
114842e9c7c8cSmrg
11485e9fcaa8aSmrgtest -z "$opt_mode" && {
11486862bcd1aSmrg  help=$generic_help
1148788de56ccSmrg  func_fatal_help "you must specify a MODE"
1148888de56ccSmrg}
1148988de56ccSmrg
1149088de56ccSmrgtest -z "$exec_cmd" && \
11491862bcd1aSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
114921ab64890Smrg
114931ab64890Smrgif test -n "$exec_cmd"; then
1149488de56ccSmrg  eval exec "$exec_cmd"
114951ab64890Smrg  exit $EXIT_FAILURE
114961ab64890Smrgfi
114971ab64890Smrg
1149888de56ccSmrgexit $exit_status
114991ab64890Smrg
115001ab64890Smrg
115011ab64890Smrg# The TAGs below are defined such that we never get into a situation
11502862bcd1aSmrg# where we disable both kinds of libraries.  Given conflicting
115031ab64890Smrg# choices, we go for a static library, that is the most portable,
115041ab64890Smrg# since we can't tell whether shared libraries were disabled because
115051ab64890Smrg# the user asked for that or because the platform doesn't support
115061ab64890Smrg# them.  This is particularly important on AIX, because we don't
115071ab64890Smrg# support having both static and shared libraries enabled at the same
115081ab64890Smrg# time on that platform, so we default to a shared-only configuration.
115091ab64890Smrg# If a disable-shared tag is given, we'll fallback to a static-only
115101ab64890Smrg# configuration.  But we'll never go from static-only to shared-only.
115111ab64890Smrg
115121ab64890Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1151388de56ccSmrgbuild_libtool_libs=no
1151488de56ccSmrgbuild_old_libs=yes
115151ab64890Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
115161ab64890Smrg
115171ab64890Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1151888de56ccSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
115191ab64890Smrg# ### END LIBTOOL TAG CONFIG: disable-static
115201ab64890Smrg
115211ab64890Smrg# Local Variables:
115221ab64890Smrg# mode:shell-script
115231ab64890Smrg# sh-indentation:2
115241ab64890Smrg# End:
11525